@mbc-cqrs-serverless/import 0.1.74-beta.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 (93) hide show
  1. package/LICENSE.txt +7 -0
  2. package/README.md +55 -0
  3. package/dist/constant/index.d.ts +1 -0
  4. package/dist/constant/index.js +5 -0
  5. package/dist/constant/index.js.map +1 -0
  6. package/dist/dto/create-csv-import.dto.d.ts +8 -0
  7. package/dist/dto/create-csv-import.dto.js +43 -0
  8. package/dist/dto/create-csv-import.dto.js.map +1 -0
  9. package/dist/dto/create-import.dto.d.ts +6 -0
  10. package/dist/dto/create-import.dto.js +34 -0
  11. package/dist/dto/create-import.dto.js.map +1 -0
  12. package/dist/dto/csv-import-row.interface.d.ts +7 -0
  13. package/dist/dto/csv-import-row.interface.js +4 -0
  14. package/dist/dto/csv-import-row.interface.js.map +1 -0
  15. package/dist/dto/index.d.ts +3 -0
  16. package/dist/dto/index.js +20 -0
  17. package/dist/dto/index.js.map +1 -0
  18. package/dist/entity/import-entity-list.d.ts +6 -0
  19. package/dist/entity/import-entity-list.js +12 -0
  20. package/dist/entity/import-entity-list.js.map +1 -0
  21. package/dist/entity/import-entity.d.ts +20 -0
  22. package/dist/entity/import-entity.js +24 -0
  23. package/dist/entity/import-entity.js.map +1 -0
  24. package/dist/entity/index.d.ts +2 -0
  25. package/dist/entity/index.js +19 -0
  26. package/dist/entity/index.js.map +1 -0
  27. package/dist/enum/comparison-status.enum.d.ts +8 -0
  28. package/dist/enum/comparison-status.enum.js +13 -0
  29. package/dist/enum/comparison-status.enum.js.map +1 -0
  30. package/dist/enum/import-status.enum.d.ts +7 -0
  31. package/dist/enum/import-status.enum.js +12 -0
  32. package/dist/enum/import-status.enum.js.map +1 -0
  33. package/dist/enum/index.d.ts +3 -0
  34. package/dist/enum/index.js +20 -0
  35. package/dist/enum/index.js.map +1 -0
  36. package/dist/enum/processing-mode.enum.d.ts +4 -0
  37. package/dist/enum/processing-mode.enum.js +9 -0
  38. package/dist/enum/processing-mode.enum.js.map +1 -0
  39. package/dist/event/csv-import.queue.event.handler.d.ts +15 -0
  40. package/dist/event/csv-import.queue.event.handler.js +75 -0
  41. package/dist/event/csv-import.queue.event.handler.js.map +1 -0
  42. package/dist/event/csv-import.sfn.event.d.ts +9 -0
  43. package/dist/event/csv-import.sfn.event.handler.d.ts +17 -0
  44. package/dist/event/csv-import.sfn.event.handler.js +151 -0
  45. package/dist/event/csv-import.sfn.event.handler.js.map +1 -0
  46. package/dist/event/csv-import.sfn.event.js +42 -0
  47. package/dist/event/csv-import.sfn.event.js.map +1 -0
  48. package/dist/event/import.event.d.ts +22 -0
  49. package/dist/event/import.event.handler.d.ts +10 -0
  50. package/dist/event/import.event.handler.js +38 -0
  51. package/dist/event/import.event.handler.js.map +1 -0
  52. package/dist/event/import.event.js +34 -0
  53. package/dist/event/import.event.js.map +1 -0
  54. package/dist/event/import.queue.event.d.ts +18 -0
  55. package/dist/event/import.queue.event.handler.d.ts +26 -0
  56. package/dist/event/import.queue.event.handler.js +121 -0
  57. package/dist/event/import.queue.event.handler.js.map +1 -0
  58. package/dist/event/import.queue.event.js +20 -0
  59. package/dist/event/import.queue.event.js.map +1 -0
  60. package/dist/event/index.d.ts +7 -0
  61. package/dist/event/index.js +24 -0
  62. package/dist/event/index.js.map +1 -0
  63. package/dist/import.controller.d.ts +22 -0
  64. package/dist/import.controller.js +99 -0
  65. package/dist/import.controller.js.map +1 -0
  66. package/dist/import.module-definition.d.ts +31 -0
  67. package/dist/import.module-definition.js +20 -0
  68. package/dist/import.module-definition.js.map +1 -0
  69. package/dist/import.module.d.ts +11 -0
  70. package/dist/import.module.js +69 -0
  71. package/dist/import.module.js.map +1 -0
  72. package/dist/import.service.d.ts +59 -0
  73. package/dist/import.service.js +250 -0
  74. package/dist/import.service.js.map +1 -0
  75. package/dist/index.d.ts +10 -0
  76. package/dist/index.js +27 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/interface/csv-mapping-strategy.interface.d.ts +14 -0
  79. package/dist/interface/csv-mapping-strategy.interface.js +3 -0
  80. package/dist/interface/csv-mapping-strategy.interface.js.map +1 -0
  81. package/dist/interface/import-entity-profile.interface.d.ts +23 -0
  82. package/dist/interface/import-entity-profile.interface.js +3 -0
  83. package/dist/interface/import-entity-profile.interface.js.map +1 -0
  84. package/dist/interface/import-strategy.interface.d.ts +27 -0
  85. package/dist/interface/import-strategy.interface.js +55 -0
  86. package/dist/interface/import-strategy.interface.js.map +1 -0
  87. package/dist/interface/index.d.ts +4 -0
  88. package/dist/interface/index.js +21 -0
  89. package/dist/interface/index.js.map +1 -0
  90. package/dist/interface/processing-strategy.interface.d.ts +57 -0
  91. package/dist/interface/processing-strategy.interface.js +10 -0
  92. package/dist/interface/processing-strategy.interface.js.map +1 -0
  93. package/package.json +48 -0
package/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2024 Murakami Business Consulting, Inc. https://www.mbc-net.com/
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ ![MBC CQRS serverless framework](https://mbc-cqrs-serverless.mbc-net.com/img/mbc-cqrs-serverless.png)
2
+
3
+
4
+ # MBC CQRS serverless framework Import package
5
+
6
+ A flexible and extensible module for handling data import within the `@mbc-cqrs-serverless` framework.
7
+
8
+ ## Core Features
9
+
10
+ - **Unified Architectural Design**: Facilitates the processing of data from REST API endpoints and CSV files through a singular, consistent set of core business logic.
11
+
12
+ - **Strategy Pattern Implementation**: Enables comprehensive customization of validation, transformation, and processing logic for each data entity via NestJS providers.
13
+
14
+ - **Asynchronous, Event-Driven Processing**: Guarantees maximum scalability and resilience by processing all tasks asynchronously through a pipeline of DynamoDB Streams, SNS, and SQS.
15
+
16
+ - **Biphasic Processing Model**: Establishes a distinct separation of concerns between the initial data ingestion and validation phase and the subsequent business logic execution.
17
+
18
+ - **Dual CSV Processing Modes**: Offers the flexibility to select between `DIRECT` processing for smaller files and a resilient `STEP_FUNCTION` workflow for large-scale, mission-critical import operations.
19
+
20
+ ## Installation
21
+
22
+ ```sh
23
+ npm install @mbc-cqrs-serverless/import
24
+ ```
25
+ ## Architecture Overview
26
+
27
+ The module operates on a powerful two-phase architecture, ensuring a clean separation of concerns.
28
+
29
+ 1. The Import Phase (Ingestion)
30
+
31
+ This phase is responsible for getting data into the system. It's handled by a class that implements the `IImportStrategy` interface.
32
+
33
+ `transform(input)`: Takes a raw input object (from a JSON body or a CSV row) and transforms it into a standardized, validated DTO.
34
+
35
+ `validate(dto)`: Validates the transformed DTO.
36
+
37
+ The result of this phase is a record in a temporary DynamoDB table with a CREATED status.
38
+
39
+ 2. The Process Phase (Business Logic)
40
+
41
+ Once a record is in the temporary table, an event is triggered, and this phase begins. It's handled by a class that implements the `IProcessStrategy` interface.
42
+
43
+ `compare(dto)`: Compares the data from the temporary table with data in the final destination table to determine if it's a new record (`NOT_EXIST`), a changed one (`CHANGED`), or identical (`EQUAL`).
44
+
45
+ `map(status, dto)`: Based on the comparison, it constructs the final payload for a create or update command.
46
+
47
+ `getCommandService()`: Provides the correct `CommandService` to execute the final write operation.
48
+
49
+ After this phase, the record in the temporary table is updated to `COMPLETED` or `FAILED`, and the result is stored for auditing.
50
+
51
+ ## License
52
+
53
+ Copyright © 2024, Murakami Business Consulting, Inc. https://www.mbc-net.com/
54
+
55
+ This project and sub projects are under the MIT License.
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_IMPORT_ACTION_QUEUE = "import-action-queue";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_IMPORT_ACTION_QUEUE = void 0;
4
+ exports.DEFAULT_IMPORT_ACTION_QUEUE = 'import-action-queue';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,2BAA2B,GAAG,qBAAqB,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { ProcessingMode } from '../enum';
2
+ export declare class CreateCsvImportDto {
3
+ processingMode: ProcessingMode;
4
+ bucket: string;
5
+ key: string;
6
+ tableName: string;
7
+ tenantCode: string;
8
+ }
@@ -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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CreateCsvImportDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ const enum_1 = require("../enum");
15
+ class CreateCsvImportDto {
16
+ }
17
+ exports.CreateCsvImportDto = CreateCsvImportDto;
18
+ __decorate([
19
+ (0, class_validator_1.IsNotEmpty)(),
20
+ (0, class_validator_1.IsEnum)(enum_1.ProcessingMode),
21
+ __metadata("design:type", String)
22
+ ], CreateCsvImportDto.prototype, "processingMode", void 0);
23
+ __decorate([
24
+ (0, class_validator_1.IsString)(),
25
+ (0, class_validator_1.IsNotEmpty)(),
26
+ __metadata("design:type", String)
27
+ ], CreateCsvImportDto.prototype, "bucket", void 0);
28
+ __decorate([
29
+ (0, class_validator_1.IsString)(),
30
+ (0, class_validator_1.IsNotEmpty)(),
31
+ __metadata("design:type", String)
32
+ ], CreateCsvImportDto.prototype, "key", void 0);
33
+ __decorate([
34
+ (0, class_validator_1.IsString)(),
35
+ (0, class_validator_1.IsNotEmpty)(),
36
+ __metadata("design:type", String)
37
+ ], CreateCsvImportDto.prototype, "tableName", void 0);
38
+ __decorate([
39
+ (0, class_validator_1.IsString)(),
40
+ (0, class_validator_1.IsNotEmpty)(),
41
+ __metadata("design:type", String)
42
+ ], CreateCsvImportDto.prototype, "tenantCode", void 0);
43
+ //# sourceMappingURL=create-csv-import.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-csv-import.dto.js","sourceRoot":"","sources":["../../src/dto/create-csv-import.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA8D;AAE9D,kCAAwC;AAExC,MAAa,kBAAkB;CAoB9B;AApBD,gDAoBC;AAjBC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,qBAAc,CAAC;;0DACO;AAI9B;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;kDACC;AAId;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;+CACF;AAIX;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;qDACI;AAIjB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;sDACK"}
@@ -0,0 +1,6 @@
1
+ export declare class CreateImportDto {
2
+ tableName: string;
3
+ tenantCode: string;
4
+ name?: string;
5
+ attributes: Record<string, any>;
6
+ }
@@ -0,0 +1,34 @@
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.CreateImportDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ class CreateImportDto {
15
+ }
16
+ exports.CreateImportDto = CreateImportDto;
17
+ __decorate([
18
+ (0, class_validator_1.IsString)(),
19
+ __metadata("design:type", String)
20
+ ], CreateImportDto.prototype, "tableName", void 0);
21
+ __decorate([
22
+ (0, class_validator_1.IsString)(),
23
+ __metadata("design:type", String)
24
+ ], CreateImportDto.prototype, "tenantCode", void 0);
25
+ __decorate([
26
+ (0, class_validator_1.IsString)(),
27
+ (0, class_validator_1.IsOptional)(),
28
+ __metadata("design:type", String)
29
+ ], CreateImportDto.prototype, "name", void 0);
30
+ __decorate([
31
+ (0, class_validator_1.IsObject)(),
32
+ __metadata("design:type", Object)
33
+ ], CreateImportDto.prototype, "attributes", void 0);
34
+ //# sourceMappingURL=create-import.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-import.dto.js","sourceRoot":"","sources":["../../src/dto/create-import.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAgE;AAEhE,MAAa,eAAe;CAa3B;AAbD,0CAaC;AAXC;IADC,IAAA,0BAAQ,GAAE;;kDACM;AAGjB;IADC,IAAA,0BAAQ,GAAE;;mDACO;AAIlB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;6CACA;AAGb;IADC,IAAA,0BAAQ,GAAE;;mDACoB"}
@@ -0,0 +1,7 @@
1
+ import { CreateCsvImportDto } from './create-csv-import.dto';
2
+ export interface ICsvRowImport<T = any> {
3
+ BatchInput: {
4
+ Attributes: CreateCsvImportDto;
5
+ };
6
+ Items: T[];
7
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // import { CsvImportType } from '../constants/csv-import.enum'
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=csv-import-row.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv-import-row.interface.js","sourceRoot":"","sources":["../../src/dto/csv-import-row.interface.ts"],"names":[],"mappings":";AAAA,+DAA+D"}
@@ -0,0 +1,3 @@
1
+ export * from './create-csv-import.dto';
2
+ export * from './create-import.dto';
3
+ export * from './csv-import-row.interface';
@@ -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("./create-csv-import.dto"), exports);
18
+ __exportStar(require("./create-import.dto"), exports);
19
+ __exportStar(require("./csv-import-row.interface"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAuC;AACvC,sDAAmC;AACnC,6DAA0C"}
@@ -0,0 +1,6 @@
1
+ import { DataListEntity } from '@mbc-cqrs-serverless/core';
2
+ import { ImportEntity } from './import-entity';
3
+ export declare class ImportListEntity extends DataListEntity {
4
+ items: ImportEntity[];
5
+ constructor(partial: Partial<ImportListEntity>);
6
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportListEntity = void 0;
4
+ const core_1 = require("@mbc-cqrs-serverless/core");
5
+ class ImportListEntity extends core_1.DataListEntity {
6
+ constructor(partial) {
7
+ super(partial);
8
+ Object.assign(this, partial);
9
+ }
10
+ }
11
+ exports.ImportListEntity = ImportListEntity;
12
+ //# sourceMappingURL=import-entity-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-entity-list.js","sourceRoot":"","sources":["../../src/entity/import-entity-list.ts"],"names":[],"mappings":";;;AAAA,oDAA0D;AAI1D,MAAa,gBAAiB,SAAQ,qBAAc;IAGlD,YAAY,OAAkC;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAA;QAEd,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC9B,CAAC;CACF;AARD,4CAQC"}
@@ -0,0 +1,20 @@
1
+ import { CommandEntity } from '@mbc-cqrs-serverless/core';
2
+ import { ImportStatusEnum } from '../enum/import-status.enum';
3
+ /**
4
+ * Import data structure
5
+ * - pk: {IMPORT|CSV_IMPORT}#tenantCode
6
+ * - sk: tableName#uuid
7
+ * - code: tableName#uuid
8
+ * - name: name || tableName
9
+ * - tenant_code: tenantCode
10
+ * - type: CSV_MASTER_JOB | tableName
11
+ * - status: ImportStatusEnum
12
+ * - attributes: ImportEntity attributes
13
+ * - result: ImportEntity result
14
+ */
15
+ export declare class ImportEntity extends CommandEntity {
16
+ status?: ImportStatusEnum;
17
+ attributes: Record<string, any>;
18
+ result?: Record<string, any>;
19
+ constructor(partial: Partial<ImportEntity>);
20
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportEntity = void 0;
4
+ const core_1 = require("@mbc-cqrs-serverless/core");
5
+ /**
6
+ * Import data structure
7
+ * - pk: {IMPORT|CSV_IMPORT}#tenantCode
8
+ * - sk: tableName#uuid
9
+ * - code: tableName#uuid
10
+ * - name: name || tableName
11
+ * - tenant_code: tenantCode
12
+ * - type: CSV_MASTER_JOB | tableName
13
+ * - status: ImportStatusEnum
14
+ * - attributes: ImportEntity attributes
15
+ * - result: ImportEntity result
16
+ */
17
+ class ImportEntity extends core_1.CommandEntity {
18
+ constructor(partial) {
19
+ super();
20
+ Object.assign(this, partial);
21
+ }
22
+ }
23
+ exports.ImportEntity = ImportEntity;
24
+ //# sourceMappingURL=import-entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-entity.js","sourceRoot":"","sources":["../../src/entity/import-entity.ts"],"names":[],"mappings":";;;AAAA,oDAAyD;AAIzD;;;;;;;;;;;GAWG;AACH,MAAa,YAAa,SAAQ,oBAAa;IAK7C,YAAY,OAA8B;QACxC,KAAK,EAAE,CAAA;QACP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC9B,CAAC;CACF;AATD,oCASC"}
@@ -0,0 +1,2 @@
1
+ export * from './import-entity';
2
+ export * from './import-entity-list';
@@ -0,0 +1,19 @@
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("./import-entity"), exports);
18
+ __exportStar(require("./import-entity-list"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,uDAAoC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Defines the possible outcomes of an import comparison.
3
+ */
4
+ export declare enum ComparisonStatus {
5
+ EQUAL = "EQUAL",
6
+ NOT_EXIST = "NOT_EXIST",
7
+ CHANGED = "CHANGED"
8
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComparisonStatus = void 0;
4
+ /**
5
+ * Defines the possible outcomes of an import comparison.
6
+ */
7
+ var ComparisonStatus;
8
+ (function (ComparisonStatus) {
9
+ ComparisonStatus["EQUAL"] = "EQUAL";
10
+ ComparisonStatus["NOT_EXIST"] = "NOT_EXIST";
11
+ ComparisonStatus["CHANGED"] = "CHANGED";
12
+ })(ComparisonStatus || (exports.ComparisonStatus = ComparisonStatus = {}));
13
+ //# sourceMappingURL=comparison-status.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparison-status.enum.js","sourceRoot":"","sources":["../../src/enum/comparison-status.enum.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,mCAAe,CAAA;IACf,2CAAuB,CAAA;IACvB,uCAAmB,CAAA;AACrB,CAAC,EAJW,gBAAgB,gCAAhB,gBAAgB,QAI3B"}
@@ -0,0 +1,7 @@
1
+ export declare enum ImportStatusEnum {
2
+ CREATED = "CREATED",
3
+ QUEUED = "QUEUED",
4
+ PROCESSING = "PROCESSING",
5
+ COMPLETED = "COMPLETED",
6
+ FAILED = "FAILED"
7
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportStatusEnum = void 0;
4
+ var ImportStatusEnum;
5
+ (function (ImportStatusEnum) {
6
+ ImportStatusEnum["CREATED"] = "CREATED";
7
+ ImportStatusEnum["QUEUED"] = "QUEUED";
8
+ ImportStatusEnum["PROCESSING"] = "PROCESSING";
9
+ ImportStatusEnum["COMPLETED"] = "COMPLETED";
10
+ ImportStatusEnum["FAILED"] = "FAILED";
11
+ })(ImportStatusEnum || (exports.ImportStatusEnum = ImportStatusEnum = {}));
12
+ //# sourceMappingURL=import-status.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-status.enum.js","sourceRoot":"","sources":["../../src/enum/import-status.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,uCAAmB,CAAA;IACnB,qCAAiB,CAAA;IACjB,6CAAyB,CAAA;IACzB,2CAAuB,CAAA;IACvB,qCAAiB,CAAA;AACnB,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B"}
@@ -0,0 +1,3 @@
1
+ export * from './comparison-status.enum';
2
+ export * from './import-status.enum';
3
+ export * from './processing-mode.enum';
@@ -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("./comparison-status.enum"), exports);
18
+ __exportStar(require("./import-status.enum"), exports);
19
+ __exportStar(require("./processing-mode.enum"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/enum/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAwC;AACxC,uDAAoC;AACpC,yDAAsC"}
@@ -0,0 +1,4 @@
1
+ export declare enum ProcessingMode {
2
+ DIRECT = "DIRECT",
3
+ STEP_FUNCTION = "STEP_FUNCTION"
4
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProcessingMode = void 0;
4
+ var ProcessingMode;
5
+ (function (ProcessingMode) {
6
+ ProcessingMode["DIRECT"] = "DIRECT";
7
+ ProcessingMode["STEP_FUNCTION"] = "STEP_FUNCTION";
8
+ })(ProcessingMode || (exports.ProcessingMode = ProcessingMode = {}));
9
+ //# sourceMappingURL=processing-mode.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processing-mode.enum.js","sourceRoot":"","sources":["../../src/enum/processing-mode.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,iDAA+B,CAAA;AACjC,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB"}
@@ -0,0 +1,15 @@
1
+ import { IEventHandler, StepFunctionService } from '@mbc-cqrs-serverless/core';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import { ImportService } from '../import.service';
4
+ import { IImportStrategy } from '../interface';
5
+ import { ImportQueueEvent } from './import.queue.event';
6
+ export declare class CsvImportQueueEventHandler implements IEventHandler<ImportQueueEvent> {
7
+ private readonly configService;
8
+ private readonly sfnService;
9
+ private readonly importService;
10
+ private readonly importStrategyMap;
11
+ private readonly logger;
12
+ private readonly csvImportArn;
13
+ constructor(configService: ConfigService, sfnService: StepFunctionService, importService: ImportService, importStrategyMap: Map<string, IImportStrategy<any, any>>);
14
+ execute(event: ImportQueueEvent): Promise<any>;
15
+ }
@@ -0,0 +1,75 @@
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 CsvImportQueueEventHandler_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.CsvImportQueueEventHandler = void 0;
17
+ // event/csv-job.event.handler.ts (Refactored)
18
+ const core_1 = require("@mbc-cqrs-serverless/core");
19
+ const common_1 = require("@nestjs/common");
20
+ const config_1 = require("@nestjs/config");
21
+ const import_status_enum_1 = require("../enum/import-status.enum");
22
+ const import_module_definition_1 = require("../import.module-definition");
23
+ const import_service_1 = require("../import.service");
24
+ const import_queue_event_1 = require("./import.queue.event");
25
+ let CsvImportQueueEventHandler = CsvImportQueueEventHandler_1 = class CsvImportQueueEventHandler {
26
+ constructor(configService, sfnService, importService, importStrategyMap) {
27
+ this.configService = configService;
28
+ this.sfnService = sfnService;
29
+ this.importService = importService;
30
+ this.importStrategyMap = importStrategyMap;
31
+ this.logger = new common_1.Logger(CsvImportQueueEventHandler_1.name);
32
+ this.csvImportArn = this.configService.get('SFN_IMPORT_CSV_ARN');
33
+ }
34
+ async execute(event) {
35
+ const importEntity = event.importEvent.importEntity;
36
+ // This handler ONLY acts on master jobs and ignores all other event types.
37
+ if (importEntity.type !== 'CSV_MASTER_JOB') {
38
+ return;
39
+ }
40
+ const importKey = event.importEvent.importKey;
41
+ const { key, tableName, tenantCode } = importEntity.attributes;
42
+ this.logger.log(`Received master CSV job from queue: ${importEntity.id} for file ${key}`);
43
+ try {
44
+ await this.importService.updateStatus(importKey, import_status_enum_1.ImportStatusEnum.PROCESSING);
45
+ // 1. Find the custom CSV mapper for the target table.
46
+ const mapper = this.importStrategyMap.get(tableName);
47
+ if (!mapper) {
48
+ throw new Error(`No CSV mapping strategy found for table: ${tableName}`);
49
+ }
50
+ await this.sfnService.startExecution(this.csvImportArn, importEntity.attributes, `${tenantCode}-${tableName}-${Date.now()}`);
51
+ this.logger.log(`Started Step Function execution for master job ${importEntity.id}`);
52
+ // The master job's status will now be updated by the Step Function itself upon completion/failure.
53
+ }
54
+ catch (error) {
55
+ this.logger.error(`Failed to start Step Function for master job ${importEntity.id}`, error);
56
+ // If starting the SFN fails, update the master job to FAILED status.
57
+ await this.importService.updateStatus(importKey, import_status_enum_1.ImportStatusEnum.FAILED, {
58
+ error: {
59
+ message: `Failed to start Step Function: ${error.message}`,
60
+ },
61
+ });
62
+ throw error;
63
+ }
64
+ }
65
+ };
66
+ exports.CsvImportQueueEventHandler = CsvImportQueueEventHandler;
67
+ exports.CsvImportQueueEventHandler = CsvImportQueueEventHandler = CsvImportQueueEventHandler_1 = __decorate([
68
+ (0, core_1.EventHandler)(import_queue_event_1.ImportQueueEvent),
69
+ __param(3, (0, common_1.Inject)(import_module_definition_1.IMPORT_STRATEGY_MAP)),
70
+ __metadata("design:paramtypes", [config_1.ConfigService,
71
+ core_1.StepFunctionService,
72
+ import_service_1.ImportService,
73
+ Map])
74
+ ], CsvImportQueueEventHandler);
75
+ //# sourceMappingURL=csv-import.queue.event.handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv-import.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/csv-import.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA8C;AAC9C,oDAIkC;AAClC,2CAA+C;AAC/C,2CAA8C;AAG9C,mEAA6D;AAC7D,0EAAiE;AACjE,sDAAiD;AAEjD,6DAAuD;AAGhD,IAAM,0BAA0B,kCAAhC,MAAM,0BAA0B;IAMrC,YACmB,aAA4B,EAC5B,UAA+B,EAC/B,aAA4B,EAE7C,iBAA0E;QAJzD,kBAAa,GAAb,aAAa,CAAe;QAC5B,eAAU,GAAV,UAAU,CAAqB;QAC/B,kBAAa,GAAb,aAAa,CAAe;QAE5B,sBAAiB,GAAjB,iBAAiB,CAAwC;QAR3D,WAAM,GAAG,IAAI,eAAM,CAAC,4BAA0B,CAAC,IAAI,CAAC,CAAA;QAUnE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,oBAAoB,CAAC,CAAA;IAC1E,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAuB;QACnC,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,YAAY,CAAA;QAEnD,2EAA2E;QAC3E,IAAI,YAAY,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAC3C,OAAM;QACR,CAAC;QAED,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,SAAS,CAAA;QAC7C,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,GAClC,YAAY,CAAC,UAAgC,CAAA;QAC/C,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,uCAAuC,YAAY,CAAC,EAAE,aAAa,GAAG,EAAE,CACzE,CAAA;QAED,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CACnC,SAAS,EACT,qCAAgB,CAAC,UAAU,CAC5B,CAAA;YAED,sDAAsD;YACtD,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YACpD,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,4CAA4C,SAAS,EAAE,CAAC,CAAA;YAC1E,CAAC;YAED,MAAM,IAAI,CAAC,UAAU,CAAC,cAAc,CAClC,IAAI,CAAC,YAAY,EACjB,YAAY,CAAC,UAAU,EACvB,GAAG,UAAU,IAAI,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAC3C,CAAA;YAED,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,kDAAkD,YAAY,CAAC,EAAE,EAAE,CACpE,CAAA;YACD,mGAAmG;QACrG,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,gDAAgD,YAAY,CAAC,EAAE,EAAE,EACjE,KAAK,CACN,CAAA;YACD,qEAAqE;YACrE,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CACnC,SAAS,EACT,qCAAgB,CAAC,MAAM,EACvB;gBACE,KAAK,EAAE;oBACL,OAAO,EAAE,kCAAmC,KAAe,CAAC,OAAO,EAAE;iBACtE;aACF,CACF,CAAA;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF,CAAA;AAvEY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,mBAAY,EAAC,qCAAgB,CAAC;IAW1B,WAAA,IAAA,eAAM,EAAC,8CAAmB,CAAC,CAAA;qCAHI,sBAAa;QAChB,0BAAmB;QAChB,8BAAa;QAET,GAAG;GAX9B,0BAA0B,CAuEtC"}
@@ -0,0 +1,9 @@
1
+ import { IEvent, StepFunctionsContext } from '@mbc-cqrs-serverless/core';
2
+ import { CreateCsvImportDto } from '../dto/create-csv-import.dto';
3
+ import { ICsvRowImport } from '../dto/csv-import-row.interface';
4
+ export declare class CsvImportSfnEvent implements IEvent {
5
+ source: string;
6
+ context: StepFunctionsContext;
7
+ input: CreateCsvImportDto | ICsvRowImport;
8
+ constructor(event?: Partial<CsvImportSfnEvent>);
9
+ }
@@ -0,0 +1,17 @@
1
+ import { IEventHandler, S3Service } from '@mbc-cqrs-serverless/core';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import { ImportService } from '../import.service';
4
+ import { IImportStrategy } from '../interface';
5
+ import { CsvImportSfnEvent } from './csv-import.sfn.event';
6
+ export declare class CsvImportSfnEventHandler implements IEventHandler<CsvImportSfnEvent> {
7
+ private readonly importService;
8
+ private readonly importStrategyMap;
9
+ private readonly configService;
10
+ private readonly s3Service;
11
+ private readonly logger;
12
+ private readonly alarmTopicArn;
13
+ constructor(importService: ImportService, importStrategyMap: Map<string, IImportStrategy<any, any>>, configService: ConfigService, s3Service: S3Service);
14
+ execute(event: CsvImportSfnEvent): Promise<any>;
15
+ handleStepState(event: CsvImportSfnEvent): Promise<any>;
16
+ private loadCsv;
17
+ }