@apipass/event-notification 0.0.12-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ import { AWSEventNotificationOptions } from "./event-notification-options";
2
+ import { EventNotificationService } from "./event-notification-service";
3
+ export declare class AWSEventNotificationService implements EventNotificationService {
4
+ private readonly logger;
5
+ private region;
6
+ private accountId;
7
+ private environment;
8
+ constructor(options: AWSEventNotificationOptions);
9
+ notifyEvent(eventName: string, content?: string): void;
10
+ static getTopicArn(eventName: string, region: string, accountId: string, environment: string): string;
11
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var AWSEventNotificationService_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.AWSEventNotificationService = void 0;
17
+ const sns = require("@aws-sdk/client-sns");
18
+ const common_1 = require("@nestjs/common");
19
+ const event_notification_constants_1 = require("./event-notification-constants");
20
+ const event_notification_options_1 = require("./event-notification-options");
21
+ let AWSEventNotificationService = AWSEventNotificationService_1 = class AWSEventNotificationService {
22
+ constructor(options) {
23
+ this.logger = new common_1.Logger(AWSEventNotificationService_1.name);
24
+ this.region = options.region;
25
+ this.accountId = options.accountId;
26
+ this.environment = options.environment;
27
+ }
28
+ notifyEvent(eventName, content) {
29
+ const TopicArn = AWSEventNotificationService_1.getTopicArn(eventName, this.region, this.accountId, this.environment);
30
+ new sns.SNSClient({ region: this.region }).send(new sns.PublishCommand({ TopicArn: TopicArn, Message: content }));
31
+ this.logger.warn(`Message send to topic: ${TopicArn}`);
32
+ }
33
+ static getTopicArn(eventName, region, accountId, environment) {
34
+ return `arn:aws:sns:${region}:${accountId}:${eventName}-${environment}`;
35
+ }
36
+ };
37
+ AWSEventNotificationService = AWSEventNotificationService_1 = __decorate([
38
+ (0, common_1.Injectable)(),
39
+ __param(0, (0, common_1.Inject)(event_notification_constants_1.EVENT_NOTIFICATION_OPTION)),
40
+ __metadata("design:paramtypes", [event_notification_options_1.AWSEventNotificationOptions])
41
+ ], AWSEventNotificationService);
42
+ exports.AWSEventNotificationService = AWSEventNotificationService;
43
+ //# sourceMappingURL=aws-event-notification.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-event-notification.service.js","sourceRoot":"","sources":["../src/aws-event-notification.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA2C;AAC3C,2CAA4D;AAC5D,iFAA2E;AAC3E,6EAA2E;AAIpE,IAAM,2BAA2B,mCAAjC,MAAM,2BAA2B;IAOpC,YAA+C,OAAoC;QANlE,WAAM,GAAG,IAAI,eAAM,CAAC,6BAA2B,CAAC,IAAI,CAAC,CAAC;QAOnE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAC3C,CAAC;IAED,WAAW,CAAC,SAAiB,EAAE,OAAgB;QAC3C,MAAM,QAAQ,GAAG,6BAA2B,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QAClH,IAAI,GAAG,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,cAAc,CAAC,EAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAC,CAAC,CAAC,CAAA;QAC/G,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,SAAiB,EAAE,MAAc,EAAE,SAAiB,EAAE,WAAmB;QACxF,OAAO,eAAe,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,WAAW,EAAE,CAAA;IAC3E,CAAC;CAEJ,CAAA;AAvBY,2BAA2B;IADvC,IAAA,mBAAU,GAAE;IAQI,WAAA,IAAA,eAAM,EAAC,wDAAyB,CAAC,CAAA;qCAAU,wDAA2B;GAP1E,2BAA2B,CAuBvC;AAvBY,kEAA2B"}
@@ -0,0 +1,2 @@
1
+ export declare const EVENT_NOTIFICATION_SERVICE = "EventNotificationService";
2
+ export declare const EVENT_NOTIFICATION_OPTION = "EventNotificationOptions";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVENT_NOTIFICATION_OPTION = exports.EVENT_NOTIFICATION_SERVICE = void 0;
4
+ exports.EVENT_NOTIFICATION_SERVICE = 'EventNotificationService';
5
+ exports.EVENT_NOTIFICATION_OPTION = 'EventNotificationOptions';
6
+ //# sourceMappingURL=event-notification-constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-notification-constants.js","sourceRoot":"","sources":["../src/event-notification-constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,0BAA0B,GAAG,0BAA0B,CAAC;AACxD,QAAA,yBAAyB,GAAG,0BAA0B,CAAC"}
@@ -0,0 +1,15 @@
1
+ export declare type EventNotificationOptions = AWSEventNotificationOptions;
2
+ export declare enum EventNotificationType {
3
+ AWS = "AWS"
4
+ }
5
+ export declare class AWSEventNotificationOptions {
6
+ accountId: string;
7
+ region: string;
8
+ environment: string;
9
+ type?: string;
10
+ }
11
+ export interface EventNotificationAsyncOptions {
12
+ type: string;
13
+ useFactory: any;
14
+ inject: any[];
15
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AWSEventNotificationOptions = exports.EventNotificationType = void 0;
4
+ var EventNotificationType;
5
+ (function (EventNotificationType) {
6
+ EventNotificationType["AWS"] = "AWS";
7
+ })(EventNotificationType = exports.EventNotificationType || (exports.EventNotificationType = {}));
8
+ class AWSEventNotificationOptions {
9
+ }
10
+ exports.AWSEventNotificationOptions = AWSEventNotificationOptions;
11
+ //# sourceMappingURL=event-notification-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-notification-options.js","sourceRoot":"","sources":["../src/event-notification-options.ts"],"names":[],"mappings":";;;AAEA,IAAY,qBAEX;AAFD,WAAY,qBAAqB;IAC7B,oCAAW,CAAA;AACf,CAAC,EAFW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAEhC;AAED,MAAa,2BAA2B;CAKvC;AALD,kEAKC"}
@@ -0,0 +1,6 @@
1
+ export declare class EventNotificationServiceFactory {
2
+ static createInstance(type: string): any;
3
+ }
4
+ export interface EventNotificationService {
5
+ notifyEvent(eventName: string, message?: string): any;
6
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventNotificationServiceFactory = void 0;
4
+ const aws_event_notification_service_1 = require("./aws-event-notification.service");
5
+ const event_notification_options_1 = require("./event-notification-options");
6
+ class EventNotificationServiceFactory {
7
+ static createInstance(type) {
8
+ switch (type) {
9
+ case event_notification_options_1.EventNotificationType.AWS: return aws_event_notification_service_1.AWSEventNotificationService;
10
+ default: throw new Error('Event Notification type not found');
11
+ }
12
+ }
13
+ }
14
+ exports.EventNotificationServiceFactory = EventNotificationServiceFactory;
15
+ //# sourceMappingURL=event-notification-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-notification-service.js","sourceRoot":"","sources":["../src/event-notification-service.ts"],"names":[],"mappings":";;;AACA,qFAA+E;AAC/E,6EAAqE;AAErE,MAAa,+BAA+B;IACxC,MAAM,CAAC,cAAc,CAAC,IAAY;QAC9B,QAAQ,IAAI,EAAE;YACV,KAAK,kDAAqB,CAAC,GAAG,CAAC,CAAC,OAAO,4DAA2B,CAAA;YAClE,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;SAChE;IACL,CAAC;CACJ;AAPD,0EAOC"}
@@ -0,0 +1,6 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ import { EventNotificationAsyncOptions, EventNotificationOptions } from "./event-notification-options";
3
+ export declare class EventNotificationModule {
4
+ static forRoot(options: EventNotificationOptions): DynamicModule;
5
+ static forRootAsync(asyncOptions: EventNotificationAsyncOptions): DynamicModule;
6
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var EventNotificationModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.EventNotificationModule = void 0;
11
+ const config_1 = require("@nestjs/config");
12
+ const common_1 = require("@nestjs/common");
13
+ const event_notification_constants_1 = require("./event-notification-constants");
14
+ const event_notification_service_1 = require("./event-notification-service");
15
+ let EventNotificationModule = EventNotificationModule_1 = class EventNotificationModule {
16
+ static forRoot(options) {
17
+ const serviceProvider = {
18
+ provide: event_notification_constants_1.EVENT_NOTIFICATION_SERVICE,
19
+ useClass: event_notification_service_1.EventNotificationServiceFactory.createInstance(options.type),
20
+ };
21
+ return {
22
+ module: EventNotificationModule_1,
23
+ global: true,
24
+ imports: [config_1.ConfigModule],
25
+ providers: [serviceProvider, {
26
+ provide: event_notification_constants_1.EVENT_NOTIFICATION_OPTION,
27
+ useValue: options
28
+ }
29
+ ],
30
+ exports: [serviceProvider]
31
+ };
32
+ }
33
+ static forRootAsync(asyncOptions) {
34
+ const serviceProvider = {
35
+ provide: event_notification_constants_1.EVENT_NOTIFICATION_SERVICE,
36
+ useClass: event_notification_service_1.EventNotificationServiceFactory.createInstance(asyncOptions.type),
37
+ };
38
+ return {
39
+ module: EventNotificationModule_1,
40
+ providers: [
41
+ serviceProvider,
42
+ {
43
+ provide: event_notification_constants_1.EVENT_NOTIFICATION_OPTION,
44
+ useFactory: asyncOptions.useFactory,
45
+ inject: asyncOptions.inject
46
+ }
47
+ ],
48
+ exports: [
49
+ serviceProvider
50
+ ]
51
+ };
52
+ }
53
+ };
54
+ EventNotificationModule = EventNotificationModule_1 = __decorate([
55
+ (0, common_1.Global)(),
56
+ (0, common_1.Module)({})
57
+ ], EventNotificationModule);
58
+ exports.EventNotificationModule = EventNotificationModule;
59
+ //# sourceMappingURL=event-notification.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-notification.module.js","sourceRoot":"","sources":["../src/event-notification.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA8C;AAC9C,2CAAyE;AACzE,iFAAuG;AAEvG,6EAA+E;AAIxE,IAAM,uBAAuB,+BAA7B,MAAM,uBAAuB;IAEhC,MAAM,CAAC,OAAO,CAAC,OAAiC;QAE5C,MAAM,eAAe,GAAa;YAC9B,OAAO,EAAE,yDAA0B;YACnC,QAAQ,EAAE,4DAA+B,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC;SACzE,CAAA;QAED,OAAO;YACH,MAAM,EAAE,yBAAuB;YAC/B,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,CAAC,qBAAY,CAAC;YACvB,SAAS,EAAE,CAAE,eAAe,EAAG;oBAC3B,OAAO,EAAE,wDAAyB;oBAClC,QAAQ,EAAE,OAAO;iBACpB;aACA;YACD,OAAO,EAAE,CAAE,eAAe,CAAE;SAC/B,CAAA;IACL,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,YAA2C;QAE3D,MAAM,eAAe,GAAa;YAC9B,OAAO,EAAE,yDAA0B;YACnC,QAAQ,EAAE,4DAA+B,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC;SAC9E,CAAA;QAED,OAAO;YACH,MAAM,EAAE,yBAAuB;YAC/B,SAAS,EAAE;gBACP,eAAe;gBACf;oBACI,OAAO,EAAE,wDAAyB;oBAClC,UAAU,EAAE,YAAY,CAAC,UAAU;oBACnC,MAAM,EAAE,YAAY,CAAC,MAAM;iBAC9B;aACJ;YACD,OAAO,EAAE;gBACL,eAAe;aAClB;SACJ,CAAC;IAEN,CAAC;CAEJ,CAAA;AA9CY,uBAAuB;IAFnC,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,uBAAuB,CA8CnC;AA9CY,0DAAuB"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './event-notification.module';
2
+ export * from './event-notification-service';
3
+ export * from './event-notification-options';
package/lib/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./event-notification.module"), exports);
18
+ __exportStar(require("./event-notification-service"), exports);
19
+ __exportStar(require("./event-notification-options"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,+DAA6C;AAC7C,+DAA6C"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@apipass/event-notification",
3
+ "version": "0.0.12-alpha.0",
4
+ "description": "> TODO: description",
5
+ "author": "Nathan Lemos <nathan@apipass.com.br>",
6
+ "license": "ISC",
7
+ "main": "lib/event-notification.js",
8
+ "typings": "lib/event-notification.d.ts",
9
+ "directories": {
10
+ "lib": "lib",
11
+ "test": "__tests__"
12
+ },
13
+ "dependencies": {
14
+ "@aws-sdk/client-sns": "3.171.0"
15
+ },
16
+ "devDependencies": {
17
+ "@nestjs/common": "9.0.11",
18
+ "@nestjs/config": "2.2.0"
19
+ },
20
+ "files": [
21
+ "lib"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "tsc": "tsc",
28
+ "test": "node ./__tests__/@apipass/event-notification.test.js"
29
+ },
30
+ "gitHead": "292a42ca30dc724645b1ee29165abec4baa3aee8"
31
+ }