fase(16): integrations module
This commit is contained in:
22
dist/modules/integrations/domain/entities/Integration.js
vendored
Normal file
22
dist/modules/integrations/domain/entities/Integration.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Integration = void 0;
|
||||
const Entity_1 = require("../../../../shared/domain/Entity");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
class Integration extends Entity_1.Entity {
|
||||
static create(props, id) {
|
||||
return new Integration({ ...props, enabled: true, createdAt: new Date() }, id ?? UniqueId_1.UniqueId.create());
|
||||
}
|
||||
static reconstitute(props, id) {
|
||||
return new Integration(props, id);
|
||||
}
|
||||
get name() { return this.props.name; }
|
||||
get type() { return this.props.type; }
|
||||
get enabled() { return this.props.enabled; }
|
||||
get config() { return this.props.config; }
|
||||
get createdAt() { return this.props.createdAt; }
|
||||
enable() { this.props.enabled = true; }
|
||||
disable() { this.props.enabled = false; }
|
||||
updateConfig(config) { this.props.config = config; }
|
||||
}
|
||||
exports.Integration = Integration;
|
||||
27
dist/modules/integrations/domain/entities/WebhookEndpoint.js
vendored
Normal file
27
dist/modules/integrations/domain/entities/WebhookEndpoint.js
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WebhookEndpoint = void 0;
|
||||
const Entity_1 = require("../../../../shared/domain/Entity");
|
||||
const UniqueId_1 = require("../../../../shared/domain/UniqueId");
|
||||
const WebhookSecret_1 = require("../value-objects/WebhookSecret");
|
||||
class WebhookEndpoint extends Entity_1.Entity {
|
||||
static create(props, id) {
|
||||
return new WebhookEndpoint({ ...props, secret: WebhookSecret_1.WebhookSecret.generate(), enabled: true, createdAt: new Date() }, id ?? UniqueId_1.UniqueId.create());
|
||||
}
|
||||
static reconstitute(props, id) {
|
||||
return new WebhookEndpoint(props, id);
|
||||
}
|
||||
get url() { return this.props.url; }
|
||||
get secret() { return this.props.secret; }
|
||||
get enabled() { return this.props.enabled; }
|
||||
get createdAt() { return this.props.createdAt; }
|
||||
get lastDeliveredAt() { return this.props.lastDeliveredAt; }
|
||||
get lastStatus() { return this.props.lastStatus; }
|
||||
recordDelivery(statusCode) {
|
||||
this.props.lastDeliveredAt = new Date();
|
||||
this.props.lastStatus = statusCode;
|
||||
}
|
||||
enable() { this.props.enabled = true; }
|
||||
disable() { this.props.enabled = false; }
|
||||
}
|
||||
exports.WebhookEndpoint = WebhookEndpoint;
|
||||
2
dist/modules/integrations/domain/ports/IIntegrationProvider.js
vendored
Normal file
2
dist/modules/integrations/domain/ports/IIntegrationProvider.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
dist/modules/integrations/domain/ports/IIntegrationRepository.js
vendored
Normal file
2
dist/modules/integrations/domain/ports/IIntegrationRepository.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
dist/modules/integrations/domain/ports/IWebhookEndpointRepository.js
vendored
Normal file
2
dist/modules/integrations/domain/ports/IWebhookEndpointRepository.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
18
dist/modules/integrations/domain/value-objects/IntegrationType.js
vendored
Normal file
18
dist/modules/integrations/domain/value-objects/IntegrationType.js
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IntegrationType = void 0;
|
||||
const ValueObject_1 = require("../../../../shared/domain/ValueObject");
|
||||
class IntegrationType extends ValueObject_1.ValueObject {
|
||||
get value() { return this.props.value; }
|
||||
static fromString(s) {
|
||||
if (s === 'jira' || s === 'slack' || s === 'github' || s === 'webhook') {
|
||||
return new IntegrationType({ value: s });
|
||||
}
|
||||
throw new Error(`Invalid integration type: ${s}`);
|
||||
}
|
||||
static jira() { return new IntegrationType({ value: 'jira' }); }
|
||||
static slack() { return new IntegrationType({ value: 'slack' }); }
|
||||
static github() { return new IntegrationType({ value: 'github' }); }
|
||||
static webhook() { return new IntegrationType({ value: 'webhook' }); }
|
||||
}
|
||||
exports.IntegrationType = IntegrationType;
|
||||
21
dist/modules/integrations/domain/value-objects/WebhookSecret.js
vendored
Normal file
21
dist/modules/integrations/domain/value-objects/WebhookSecret.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WebhookSecret = void 0;
|
||||
const ValueObject_1 = require("../../../../shared/domain/ValueObject");
|
||||
const crypto_1 = require("crypto");
|
||||
class WebhookSecret extends ValueObject_1.ValueObject {
|
||||
get value() { return this.props.value; }
|
||||
static generate() {
|
||||
const secret = (0, crypto_1.randomBytes)(32).toString('hex');
|
||||
return new WebhookSecret({ value: secret });
|
||||
}
|
||||
static fromString(s) {
|
||||
if (!s || s.length < 16)
|
||||
throw new Error('Webhook secret must be at least 16 characters');
|
||||
return new WebhookSecret({ value: s });
|
||||
}
|
||||
sign(payload) {
|
||||
return (0, crypto_1.createHmac)('sha256', this.props.value).update(payload).digest('hex');
|
||||
}
|
||||
}
|
||||
exports.WebhookSecret = WebhookSecret;
|
||||
Reference in New Issue
Block a user