prime-sdk 1.0.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.
Files changed (70) hide show
  1. package/.eslintrc.js +25 -0
  2. package/.prettierrc +4 -0
  3. package/README.md +63 -0
  4. package/dist/app.module.d.ts +2 -0
  5. package/dist/app.module.js +32 -0
  6. package/dist/app.module.js.map +1 -0
  7. package/dist/app.service.d.ts +9 -0
  8. package/dist/app.service.js +39 -0
  9. package/dist/app.service.js.map +1 -0
  10. package/dist/external/aws/sqs/sqs.provider.d.ts +12 -0
  11. package/dist/external/aws/sqs/sqs.provider.js +31 -0
  12. package/dist/external/aws/sqs/sqs.provider.js.map +1 -0
  13. package/dist/external/aws/sqs/sqs.service.d.ts +17 -0
  14. package/dist/external/aws/sqs/sqs.service.js +53 -0
  15. package/dist/external/aws/sqs/sqs.service.js.map +1 -0
  16. package/dist/external/aws/sqs.provider.d.ts +12 -0
  17. package/dist/external/aws/sqs.provider.js +31 -0
  18. package/dist/external/aws/sqs.provider.js.map +1 -0
  19. package/dist/external/aws/sqs.service.d.ts +17 -0
  20. package/dist/external/aws/sqs.service.js +53 -0
  21. package/dist/external/aws/sqs.service.js.map +1 -0
  22. package/dist/index.d.ts +4 -0
  23. package/dist/index.js +10 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/lib/events/events.d.ts +2 -0
  26. package/dist/lib/events/events.js +17 -0
  27. package/dist/lib/events/events.js.map +1 -0
  28. package/dist/lib/queue/interfaces/consumer.interface.d.ts +6 -0
  29. package/dist/lib/queue/interfaces/consumer.interface.js +5 -0
  30. package/dist/lib/queue/interfaces/consumer.interface.js.map +1 -0
  31. package/dist/lib/queue/interfaces/queue.interface.d.ts +11 -0
  32. package/dist/lib/queue/interfaces/queue.interface.js +5 -0
  33. package/dist/lib/queue/interfaces/queue.interface.js.map +1 -0
  34. package/dist/lib/queue/queue.d.ts +16 -0
  35. package/dist/lib/queue/queue.js +77 -0
  36. package/dist/lib/queue/queue.js.map +1 -0
  37. package/dist/lib/queue/queue.module.d.ts +5 -0
  38. package/dist/lib/queue/queue.module.js +30 -0
  39. package/dist/lib/queue/queue.module.js.map +1 -0
  40. package/dist/lib/queue/types/queue.type.d.ts +7 -0
  41. package/dist/lib/queue/types/queue.type.js +3 -0
  42. package/dist/lib/queue/types/queue.type.js.map +1 -0
  43. package/dist/lib/storage/storage.d.ts +2 -0
  44. package/dist/lib/storage/storage.js +17 -0
  45. package/dist/lib/storage/storage.js.map +1 -0
  46. package/dist/main.d.ts +1 -0
  47. package/dist/main.js +10 -0
  48. package/dist/main.js.map +1 -0
  49. package/dist/tsconfig.build.tsbuildinfo +1 -0
  50. package/nest-cli.json +8 -0
  51. package/package.json +73 -0
  52. package/queue-publish.bash +4 -0
  53. package/queue.bash +7 -0
  54. package/src/app.module.ts +19 -0
  55. package/src/app.service.ts +26 -0
  56. package/src/external/aws/sqs/sqs.provider.ts +39 -0
  57. package/src/external/aws/sqs/sqs.service.ts +50 -0
  58. package/src/index.ts +5 -0
  59. package/src/lib/events/events.ts +4 -0
  60. package/src/lib/queue/interfaces/consumer.interface.ts +8 -0
  61. package/src/lib/queue/interfaces/queue.interface.ts +9 -0
  62. package/src/lib/queue/queue.module.ts +17 -0
  63. package/src/lib/queue/queue.ts +80 -0
  64. package/src/lib/queue/types/queue.type.ts +8 -0
  65. package/src/lib/storage/storage.ts +4 -0
  66. package/src/main.ts +8 -0
  67. package/test/app.e2e-spec.ts +24 -0
  68. package/test/jest-e2e.json +9 -0
  69. package/tsconfig.build.json +4 -0
  70. package/tsconfig.json +21 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,25 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ project: 'tsconfig.json',
5
+ tsconfigRootDir: __dirname,
6
+ sourceType: 'module',
7
+ },
8
+ plugins: ['@typescript-eslint/eslint-plugin'],
9
+ extends: [
10
+ 'plugin:@typescript-eslint/recommended',
11
+ 'plugin:prettier/recommended',
12
+ ],
13
+ root: true,
14
+ env: {
15
+ node: true,
16
+ jest: true,
17
+ },
18
+ ignorePatterns: ['.eslintrc.js'],
19
+ rules: {
20
+ '@typescript-eslint/interface-name-prefix': 'off',
21
+ '@typescript-eslint/explicit-function-return-type': 'off',
22
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
23
+ '@typescript-eslint/no-explicit-any': 'off',
24
+ },
25
+ };
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all"
4
+ }
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ ## Instalando pacote
2
+
3
+ ```bash
4
+ yarn add prime-sdk
5
+ ```
6
+
7
+ ### SQS
8
+
9
+ Instale no modulo da aplicação
10
+ ```bash
11
+ import { Module } from '@nestjs/common';
12
+ import { AppService } from './app.service';
13
+ import { QueueModule } from './lib/queue/queue.module';
14
+
15
+ @Module({
16
+ imports: [
17
+ QueueModule.forRoot({
18
+ credentials: {
19
+ accessKeyId: '000000000',
20
+ secretAccessKey: '000000000',
21
+ },
22
+ endpoint: 'http://localhost:4566/',
23
+ region: 'us-east-1',
24
+ }),
25
+ ],
26
+ providers: [AppService],
27
+ exports: [],
28
+ })
29
+ export class AppModule {}
30
+
31
+ ```
32
+
33
+ Adicione a trigger no local que desejar
34
+ ```bash
35
+
36
+ import { Injectable } from '@nestjs/common';
37
+ import { IConsumer } from './lib/queue/interfaces/consumer.interface';
38
+ import { Message } from '@aws-sdk/client-sqs';
39
+ import { Queue } from './lib/queue/queue';
40
+
41
+ @Injectable()
42
+ export class AppService implements IConsumer {
43
+ constructor(private readonly queueHandler: Queue) {
44
+ this.queueHandler.handler({
45
+ QueueUrl: `${'teste'}`,
46
+ context: this,
47
+ bulk: 1,
48
+ waitTimeSeconds: 20,
49
+ });
50
+ }
51
+
52
+ handleMessage(message: Message | Message[]): Promise<void> {
53
+ console.log(message);
54
+ return;
55
+ }
56
+
57
+ handleError(error: unknown): Promise<void> {
58
+ console.log(error);
59
+ return;
60
+ }
61
+ }
62
+
63
+ ```
@@ -0,0 +1,2 @@
1
+ export declare class AppModule {
2
+ }
@@ -0,0 +1,32 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AppModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const app_service_1 = require("./app.service");
12
+ const queue_module_1 = require("./lib/queue/queue.module");
13
+ let AppModule = class AppModule {
14
+ };
15
+ exports.AppModule = AppModule;
16
+ exports.AppModule = AppModule = __decorate([
17
+ (0, common_1.Module)({
18
+ imports: [
19
+ queue_module_1.QueueModule.forRoot({
20
+ credentials: {
21
+ accessKeyId: '000000000',
22
+ secretAccessKey: '000000000',
23
+ },
24
+ endpoint: 'http://localhost:4566/',
25
+ region: 'us-east-1',
26
+ }),
27
+ ],
28
+ providers: [app_service_1.AppService],
29
+ exports: [],
30
+ })
31
+ ], AppModule);
32
+ //# sourceMappingURL=app.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,+CAA2C;AAC3C,2DAAuD;AAgBhD,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IAdrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,0BAAW,CAAC,OAAO,CAAC;gBAClB,WAAW,EAAE;oBACX,WAAW,EAAE,WAAW;oBACxB,eAAe,EAAE,WAAW;iBAC7B;gBACD,QAAQ,EAAE,wBAAwB;gBAClC,MAAM,EAAE,WAAW;aACpB,CAAC;SACH;QACD,SAAS,EAAE,CAAC,wBAAU,CAAC;QACvB,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,SAAS,CAAG"}
@@ -0,0 +1,9 @@
1
+ import { IConsumer } from './lib/queue/interfaces/consumer.interface';
2
+ import { Message } from '@aws-sdk/client-sqs';
3
+ import { Queue } from './lib/queue/queue';
4
+ export declare class AppService implements IConsumer {
5
+ private readonly queueHandler;
6
+ constructor(queueHandler: Queue);
7
+ handleMessage(message: Message | Message[]): Promise<void>;
8
+ handleError(error: unknown): Promise<void>;
9
+ }
@@ -0,0 +1,39 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AppService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const queue_1 = require("./lib/queue/queue");
15
+ let AppService = class AppService {
16
+ constructor(queueHandler) {
17
+ this.queueHandler = queueHandler;
18
+ this.queueHandler.handler({
19
+ QueueUrl: `${'teste'}`,
20
+ context: this,
21
+ bulk: 1,
22
+ waitTimeSeconds: 20,
23
+ });
24
+ }
25
+ handleMessage(message) {
26
+ console.log(message);
27
+ return;
28
+ }
29
+ handleError(error) {
30
+ console.log(error);
31
+ return;
32
+ }
33
+ };
34
+ exports.AppService = AppService;
35
+ exports.AppService = AppService = __decorate([
36
+ (0, common_1.Injectable)(),
37
+ __metadata("design:paramtypes", [queue_1.Queue])
38
+ ], AppService);
39
+ //# sourceMappingURL=app.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.service.js","sourceRoot":"","sources":["../src/app.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAG5C,6CAA0C;AAGnC,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,YAA6B,YAAmB;QAAnB,iBAAY,GAAZ,YAAY,CAAO;QAC9C,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;YACxB,QAAQ,EAAE,GAAG,OAAO,EAAE;YACtB,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,CAAC;YACP,eAAe,EAAE,EAAE;SACpB,CAAC,CAAC;IACL,CAAC;IAED,aAAa,CAAC,OAA4B;QACxC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IAED,WAAW,CAAC,KAAc;QACxB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,OAAO;IACT,CAAC;CACF,CAAA;AAnBY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;qCAEgC,aAAK;GADrC,UAAU,CAmBtB"}
@@ -0,0 +1,12 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ export type SqsSetup = {
3
+ region: string;
4
+ endpoint: string;
5
+ credentials: {
6
+ accessKeyId: string;
7
+ secretAccessKey: string;
8
+ };
9
+ };
10
+ export declare class SqsModule {
11
+ static forRoot(params: SqsSetup): DynamicModule;
12
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqsModule = void 0;
4
+ const client_sqs_1 = require("@aws-sdk/client-sqs");
5
+ const SqsProvider = (params) => {
6
+ return {
7
+ provide: 'CONNECTION_SQS',
8
+ useFactory: () => {
9
+ return new client_sqs_1.SQSClient({
10
+ region: params.region,
11
+ endpoint: params.endpoint,
12
+ credentials: {
13
+ accessKeyId: params.credentials.accessKeyId,
14
+ secretAccessKey: params.credentials.secretAccessKey,
15
+ },
16
+ });
17
+ },
18
+ };
19
+ };
20
+ class SqsModule {
21
+ static forRoot(params) {
22
+ const sqsProvider = SqsProvider(params);
23
+ return {
24
+ module: SqsModule,
25
+ providers: [sqsProvider],
26
+ exports: [sqsProvider],
27
+ };
28
+ }
29
+ }
30
+ exports.SqsModule = SqsModule;
31
+ //# sourceMappingURL=sqs.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqs.provider.js","sourceRoot":"","sources":["../../../../src/external/aws/sqs/sqs.provider.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAYhD,MAAM,WAAW,GAAG,CAAC,MAAgB,EAAE,EAAE;IACvC,OAAO;QACL,OAAO,EAAE,gBAAgB;QACzB,UAAU,EAAE,GAAG,EAAE;YACf,OAAO,IAAI,sBAAS,CAAC;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,WAAW,EAAE;oBACX,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,WAAW;oBAC3C,eAAe,EAAE,MAAM,CAAC,WAAW,CAAC,eAAe;iBACpD;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAa,SAAS;IACpB,MAAM,CAAC,OAAO,CAAC,MAAgB;QAC7B,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAExC,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,CAAC,WAAW,CAAC;YACxB,OAAO,EAAE,CAAC,WAAW,CAAC;SACvB,CAAC;IACJ,CAAC;CACF;AAVD,8BAUC"}
@@ -0,0 +1,17 @@
1
+ import { DeleteMessageCommand, ReceiveMessageCommand, ReceiveMessageResult, SQSClient } from '@aws-sdk/client-sqs';
2
+ import { IQueue } from 'src/lib/queue/interfaces/queue.interface';
3
+ export declare class Sqs implements IQueue {
4
+ private readonly client;
5
+ private queueUrl;
6
+ private bulk;
7
+ private waitTimeSeconds;
8
+ constructor(client: SQSClient);
9
+ setup({ waitTimeSeconds, bulk, queueUrl }: {
10
+ waitTimeSeconds: any;
11
+ bulk: any;
12
+ queueUrl: any;
13
+ }): void;
14
+ sendCommand(command: ReceiveMessageCommand | DeleteMessageCommand): Promise<unknown>;
15
+ receiveMessages(): Promise<ReceiveMessageResult>;
16
+ deleteMessage(receiptHandle: any): Promise<unknown>;
17
+ }
@@ -0,0 +1,53 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Sqs = void 0;
16
+ const client_sqs_1 = require("@aws-sdk/client-sqs");
17
+ const common_1 = require("@nestjs/common");
18
+ let Sqs = class Sqs {
19
+ constructor(client) {
20
+ this.client = client;
21
+ }
22
+ setup({ waitTimeSeconds, bulk, queueUrl }) {
23
+ this.waitTimeSeconds = waitTimeSeconds;
24
+ this.bulk = bulk;
25
+ this.queueUrl = queueUrl;
26
+ }
27
+ async sendCommand(command) {
28
+ return this.client.send(command);
29
+ }
30
+ async receiveMessages() {
31
+ const input = {
32
+ QueueUrl: this.queueUrl,
33
+ MaxNumberOfMessages: this.bulk,
34
+ WaitTimeSeconds: this.waitTimeSeconds,
35
+ };
36
+ const command = new client_sqs_1.ReceiveMessageCommand(input);
37
+ return (await this.sendCommand(command));
38
+ }
39
+ async deleteMessage(receiptHandle) {
40
+ const deleteCommand = new client_sqs_1.DeleteMessageCommand({
41
+ QueueUrl: this.queueUrl,
42
+ ReceiptHandle: receiptHandle,
43
+ });
44
+ return await this.sendCommand(deleteCommand);
45
+ }
46
+ };
47
+ exports.Sqs = Sqs;
48
+ exports.Sqs = Sqs = __decorate([
49
+ (0, common_1.Injectable)(),
50
+ __param(0, (0, common_1.Inject)('CONNECTION_SQS')),
51
+ __metadata("design:paramtypes", [client_sqs_1.SQSClient])
52
+ ], Sqs);
53
+ //# sourceMappingURL=sqs.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqs.service.js","sourceRoot":"","sources":["../../../../src/external/aws/sqs/sqs.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAK6B;AAC7B,2CAAoD;AAI7C,IAAM,GAAG,GAAT,MAAM,GAAG;IAKd,YAAuD,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAAG,CAAC;IAE5E,KAAK,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE;QACvC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,WAAW,CACf,OAAqD;QAErD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,KAAK,GAAG;YACZ,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,mBAAmB,EAAE,IAAI,CAAC,IAAI;YAC9B,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,kCAAqB,CAAC,KAAK,CAAC,CAAC;QAEjD,OAAO,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAyB,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,aAAa;QAC/B,MAAM,aAAa,GAAG,IAAI,iCAAoB,CAAC;YAC7C,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,aAAa,EAAE,aAAa;SAC7B,CAAC,CAAC;QAEH,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC/C,CAAC;CACF,CAAA;AAvCY,kBAAG;cAAH,GAAG;IADf,IAAA,mBAAU,GAAE;IAME,WAAA,IAAA,eAAM,EAAC,gBAAgB,CAAC,CAAA;qCAA0B,sBAAS;GAL7D,GAAG,CAuCf"}
@@ -0,0 +1,12 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ export type SqsSetup = {
3
+ region: string;
4
+ endpoint: string;
5
+ credentials: {
6
+ accessKeyId: string;
7
+ secretAccessKey: string;
8
+ };
9
+ };
10
+ export declare class SqsModule {
11
+ static forRoot(params: SqsSetup): DynamicModule;
12
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqsModule = void 0;
4
+ const client_sqs_1 = require("@aws-sdk/client-sqs");
5
+ const SqsProvider = (params) => {
6
+ return {
7
+ provide: 'CONNECTION_SQS',
8
+ useFactory: () => {
9
+ return new client_sqs_1.SQSClient({
10
+ region: params.region,
11
+ endpoint: params.endpoint,
12
+ credentials: {
13
+ accessKeyId: params.credentials.accessKeyId,
14
+ secretAccessKey: params.credentials.secretAccessKey,
15
+ },
16
+ });
17
+ },
18
+ };
19
+ };
20
+ class SqsModule {
21
+ static forRoot(params) {
22
+ const sqsProvider = SqsProvider(params);
23
+ return {
24
+ module: SqsModule,
25
+ providers: [sqsProvider],
26
+ exports: [sqsProvider],
27
+ };
28
+ }
29
+ }
30
+ exports.SqsModule = SqsModule;
31
+ //# sourceMappingURL=sqs.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqs.provider.js","sourceRoot":"","sources":["../../../src/external/aws/sqs.provider.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAYhD,MAAM,WAAW,GAAG,CAAC,MAAgB,EAAE,EAAE;IACvC,OAAO;QACL,OAAO,EAAE,gBAAgB;QACzB,UAAU,EAAE,GAAG,EAAE;YACf,OAAO,IAAI,sBAAS,CAAC;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,WAAW,EAAE;oBACX,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,WAAW;oBAC3C,eAAe,EAAE,MAAM,CAAC,WAAW,CAAC,eAAe;iBACpD;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAa,SAAS;IACpB,MAAM,CAAC,OAAO,CAAC,MAAgB;QAC7B,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAExC,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,CAAC,WAAW,CAAC;YACxB,OAAO,EAAE,CAAC,WAAW,CAAC;SACvB,CAAC;IACJ,CAAC;CACF;AAVD,8BAUC"}
@@ -0,0 +1,17 @@
1
+ import { DeleteMessageCommand, ReceiveMessageCommand, ReceiveMessageResult, SQSClient } from '@aws-sdk/client-sqs';
2
+ import { IQueue } from 'src/lib/queue/interfaces/queue.interface';
3
+ export declare class Sqs implements IQueue {
4
+ private readonly client;
5
+ private queueUrl;
6
+ private bulk;
7
+ private waitTimeSeconds;
8
+ constructor(client: SQSClient);
9
+ setup({ waitTimeSeconds, bulk, queueUrl }: {
10
+ waitTimeSeconds: any;
11
+ bulk: any;
12
+ queueUrl: any;
13
+ }): void;
14
+ sendCommand(command: ReceiveMessageCommand | DeleteMessageCommand): Promise<unknown>;
15
+ receiveMessages(): Promise<ReceiveMessageResult>;
16
+ deleteMessage(receiptHandle: any): Promise<unknown>;
17
+ }
@@ -0,0 +1,53 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Sqs = void 0;
16
+ const client_sqs_1 = require("@aws-sdk/client-sqs");
17
+ const common_1 = require("@nestjs/common");
18
+ let Sqs = class Sqs {
19
+ constructor(client) {
20
+ this.client = client;
21
+ }
22
+ setup({ waitTimeSeconds, bulk, queueUrl }) {
23
+ this.waitTimeSeconds = waitTimeSeconds;
24
+ this.bulk = bulk;
25
+ this.queueUrl = queueUrl;
26
+ }
27
+ async sendCommand(command) {
28
+ return this.client.send(command);
29
+ }
30
+ async receiveMessages() {
31
+ const input = {
32
+ QueueUrl: this.queueUrl,
33
+ MaxNumberOfMessages: this.bulk,
34
+ WaitTimeSeconds: this.waitTimeSeconds,
35
+ };
36
+ const command = new client_sqs_1.ReceiveMessageCommand(input);
37
+ return (await this.sendCommand(command));
38
+ }
39
+ async deleteMessage(receiptHandle) {
40
+ const deleteCommand = new client_sqs_1.DeleteMessageCommand({
41
+ QueueUrl: this.queueUrl,
42
+ ReceiptHandle: receiptHandle,
43
+ });
44
+ return await this.sendCommand(deleteCommand);
45
+ }
46
+ };
47
+ exports.Sqs = Sqs;
48
+ exports.Sqs = Sqs = __decorate([
49
+ (0, common_1.Injectable)(),
50
+ __param(0, (0, common_1.Inject)('CONNECTION_SQS')),
51
+ __metadata("design:paramtypes", [client_sqs_1.SQSClient])
52
+ ], Sqs);
53
+ //# sourceMappingURL=sqs.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqs.service.js","sourceRoot":"","sources":["../../../src/external/aws/sqs.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAK6B;AAC7B,2CAAoD;AAI7C,IAAM,GAAG,GAAT,MAAM,GAAG;IAKd,YAAuD,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAAG,CAAC;IAE5E,KAAK,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE;QACvC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,WAAW,CACf,OAAqD;QAErD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,KAAK,GAAG;YACZ,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,mBAAmB,EAAE,IAAI,CAAC,IAAI;YAC9B,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,kCAAqB,CAAC,KAAK,CAAC,CAAC;QAEjD,OAAO,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAyB,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,aAAa;QAC/B,MAAM,aAAa,GAAG,IAAI,iCAAoB,CAAC;YAC7C,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,aAAa,EAAE,aAAa;SAC7B,CAAC,CAAC;QAEH,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC/C,CAAC;CACF,CAAA;AAvCY,kBAAG;cAAH,GAAG;IADf,IAAA,mBAAU,GAAE;IAME,WAAA,IAAA,eAAM,EAAC,gBAAgB,CAAC,CAAA;qCAA0B,sBAAS;GAL7D,GAAG,CAuCf"}
@@ -0,0 +1,4 @@
1
+ import { QueueModule } from './lib/queue/queue.module';
2
+ import { Queue } from './lib/queue/queue';
3
+ import { IConsumer } from './lib/queue/interfaces/consumer.interface';
4
+ export { QueueModule, Queue, IConsumer };
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IConsumer = exports.Queue = exports.QueueModule = void 0;
4
+ const queue_module_1 = require("./lib/queue/queue.module");
5
+ Object.defineProperty(exports, "QueueModule", { enumerable: true, get: function () { return queue_module_1.QueueModule; } });
6
+ const queue_1 = require("./lib/queue/queue");
7
+ Object.defineProperty(exports, "Queue", { enumerable: true, get: function () { return queue_1.Queue; } });
8
+ const consumer_interface_1 = require("./lib/queue/interfaces/consumer.interface");
9
+ Object.defineProperty(exports, "IConsumer", { enumerable: true, get: function () { return consumer_interface_1.IConsumer; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AAI9C,4FAJA,0BAAW,OAIA;AAHpB,6CAA0C;AAGpB,sFAHb,aAAK,OAGa;AAF3B,kFAAsE;AAEzC,0FAFpB,8BAAS,OAEoB"}
@@ -0,0 +1,2 @@
1
+ export declare class Events {
2
+ }
@@ -0,0 +1,17 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Events = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ let Events = class Events {
12
+ };
13
+ exports.Events = Events;
14
+ exports.Events = Events = __decorate([
15
+ (0, common_1.Injectable)()
16
+ ], Events);
17
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/lib/events/events.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAGrC,IAAM,MAAM,GAAZ,MAAM,MAAM;CAAG,CAAA;AAAT,wBAAM;iBAAN,MAAM;IADlB,IAAA,mBAAU,GAAE;GACA,MAAM,CAAG"}
@@ -0,0 +1,6 @@
1
+ import { Message } from '@aws-sdk/client-sqs';
2
+ export interface IConsumer {
3
+ handleMessage(message: Array<Message> | Message): Promise<void>;
4
+ handleError(error: unknown): Promise<void>;
5
+ }
6
+ export declare const IConsumer: unique symbol;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IConsumer = void 0;
4
+ exports.IConsumer = Symbol('IConsumer');
5
+ //# sourceMappingURL=consumer.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumer.interface.js","sourceRoot":"","sources":["../../../../src/lib/queue/interfaces/consumer.interface.ts"],"names":[],"mappings":";;;AAOa,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Message, ReceiveMessageResult } from '@aws-sdk/client-sqs';
2
+ export interface IQueue {
3
+ deleteMessage(message: Array<Message> | Message): Promise<unknown>;
4
+ receiveMessages(): Promise<ReceiveMessageResult>;
5
+ setup({ waitTimeSeconds, bulk, queueUrl }: {
6
+ waitTimeSeconds: any;
7
+ bulk: any;
8
+ queueUrl: any;
9
+ }): void;
10
+ }
11
+ export declare const IQueue: unique symbol;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IQueue = void 0;
4
+ exports.IQueue = Symbol('IQueue');
5
+ //# sourceMappingURL=queue.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.interface.js","sourceRoot":"","sources":["../../../../src/lib/queue/interfaces/queue.interface.ts"],"names":[],"mappings":";;;AAQa,QAAA,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { QueueConfig } from './types/queue.type';
2
+ import { IQueue } from './interfaces/queue.interface';
3
+ import { ReceiveMessageResult } from '@aws-sdk/client-sqs';
4
+ export declare class Queue {
5
+ private readonly broker;
6
+ private queueUrl;
7
+ private bulk;
8
+ private context;
9
+ private inWork;
10
+ private waitTimeSeconds;
11
+ constructor(broker: IQueue);
12
+ handler({ QueueUrl, context, bulk, waitTimeSeconds, }: QueueConfig): Promise<void>;
13
+ run(): Promise<void>;
14
+ receiveMessages(): Promise<ReceiveMessageResult>;
15
+ deleteMessage(receiptHandle: any): Promise<unknown>;
16
+ }
@@ -0,0 +1,77 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Queue = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const queue_interface_1 = require("./interfaces/queue.interface");
18
+ let Queue = class Queue {
19
+ constructor(broker) {
20
+ this.broker = broker;
21
+ this.queueUrl = null;
22
+ this.bulk = 1;
23
+ this.context = null;
24
+ this.inWork = false;
25
+ this.waitTimeSeconds = 20;
26
+ }
27
+ async handler({ QueueUrl = null, context = null, bulk = 1, waitTimeSeconds = 20, }) {
28
+ this.queueUrl = QueueUrl;
29
+ this.bulk = bulk;
30
+ this.context = context;
31
+ this.waitTimeSeconds = waitTimeSeconds;
32
+ this.broker.setup({
33
+ waitTimeSeconds: this.waitTimeSeconds,
34
+ bulk: this.bulk,
35
+ queueUrl: this.queueUrl,
36
+ });
37
+ while (!this.inWork) {
38
+ await this.run();
39
+ }
40
+ }
41
+ async run() {
42
+ this.inWork = true;
43
+ const response = await this.receiveMessages();
44
+ try {
45
+ if (this.bulk === 1) {
46
+ const message = response.Messages?.[0] || null;
47
+ if (message) {
48
+ await this.context.handleMessage(message);
49
+ await this.deleteMessage(message.ReceiptHandle);
50
+ }
51
+ this.inWork = false;
52
+ return;
53
+ }
54
+ await this.context.handleMessage(response.Messages);
55
+ response.Messages.forEach(async (message) => {
56
+ await this.deleteMessage(message.ReceiptHandle);
57
+ });
58
+ }
59
+ catch (error) {
60
+ await this.context.handleError(error);
61
+ }
62
+ this.inWork = false;
63
+ }
64
+ async receiveMessages() {
65
+ return await this.broker.receiveMessages();
66
+ }
67
+ async deleteMessage(receiptHandle) {
68
+ return await this.broker.deleteMessage(receiptHandle);
69
+ }
70
+ };
71
+ exports.Queue = Queue;
72
+ exports.Queue = Queue = __decorate([
73
+ (0, common_1.Injectable)(),
74
+ __param(0, (0, common_1.Inject)(queue_interface_1.IQueue)),
75
+ __metadata("design:paramtypes", [Object])
76
+ ], Queue);
77
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/lib/queue/queue.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAGpD,kEAAsD;AAI/C,IAAM,KAAK,GAAX,MAAM,KAAK;IAWhB,YAA4B,MAA+B;QAAd,WAAM,GAAN,MAAM,CAAQ;QAVnD,aAAQ,GAAW,IAAI,CAAC;QAExB,SAAI,GAAW,CAAC,CAAC;QAEjB,YAAO,GAAc,IAAI,CAAC;QAE1B,WAAM,GAAY,KAAK,CAAC;QAExB,oBAAe,GAAW,EAAE,CAAC;IAEyB,CAAC;IAE/D,KAAK,CAAC,OAAO,CAAC,EACZ,QAAQ,GAAG,IAAI,EACf,OAAO,GAAG,IAAI,EACd,IAAI,GAAG,CAAC,EACR,eAAe,GAAG,EAAE,GACR;QACZ,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QAEvC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YAChB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG;QACP,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAE9C,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBACpB,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;gBAE/C,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;oBAE1C,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;gBAClD,CAAC;gBAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;gBAEpB,OAAO;YACT,CAAC;YAED,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAEpD,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,OAAgB,EAAE,EAAE;gBACnD,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,aAAa;QAC/B,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC;CACF,CAAA;AAxEY,sBAAK;gBAAL,KAAK;IADjB,IAAA,mBAAU,GAAE;IAYE,WAAA,IAAA,eAAM,EAAC,wBAAM,CAAC,CAAA;;GAXhB,KAAK,CAwEjB"}
@@ -0,0 +1,5 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { SqsSetup } from '../../external/aws/sqs/sqs.provider';
3
+ export declare class QueueModule {
4
+ static forRoot(params: SqsSetup): DynamicModule;
5
+ }