@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
@@ -0,0 +1,151 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ var CsvImportSfnEventHandler_1;
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.CsvImportSfnEventHandler = void 0;
20
+ const client_s3_1 = require("@aws-sdk/client-s3");
21
+ const core_1 = require("@mbc-cqrs-serverless/core");
22
+ const common_1 = require("@nestjs/common");
23
+ const config_1 = require("@nestjs/config");
24
+ const csv_parser_1 = __importDefault(require("csv-parser"));
25
+ const stream_1 = require("stream");
26
+ const import_module_definition_1 = require("../import.module-definition");
27
+ const import_service_1 = require("../import.service");
28
+ const csv_import_sfn_event_1 = require("./csv-import.sfn.event");
29
+ let CsvImportSfnEventHandler = CsvImportSfnEventHandler_1 = class CsvImportSfnEventHandler {
30
+ constructor(importService, importStrategyMap, configService, s3Service) {
31
+ this.importService = importService;
32
+ this.importStrategyMap = importStrategyMap;
33
+ this.configService = configService;
34
+ this.s3Service = s3Service;
35
+ this.logger = new common_1.Logger(CsvImportSfnEventHandler_1.name);
36
+ this.alarmTopicArn = this.configService.get('SNS_ALARM_TOPIC_ARN');
37
+ }
38
+ async execute(event) {
39
+ this.logger.log('🚀 ~ CsvImporaaatSfnEventHandler ~ execute ~ event:', event);
40
+ try {
41
+ return await this.handleStepState(event);
42
+ }
43
+ catch (error) {
44
+ // await this.sendAlarm(event, error) // TODO:
45
+ this.logger.error('import step execution failed', error);
46
+ throw error;
47
+ }
48
+ }
49
+ async handleStepState(event) {
50
+ this.logger.debug('Processing event:::', JSON.stringify(event, null, 2));
51
+ if (event.context.State.Name === 'csv_loader') {
52
+ return await this.loadCsv(event.input);
53
+ }
54
+ const input = event.input;
55
+ const items = input.Items;
56
+ const attributes = input.BatchInput.Attributes;
57
+ const createImportDtos = [];
58
+ const strategy = this.importStrategyMap.get(attributes.tableName);
59
+ if (!strategy) {
60
+ throw new Error(`No import strategy found for table: ${attributes.tableName}`);
61
+ }
62
+ for (const [index, item] of items.entries()) {
63
+ try {
64
+ const transformedData = await strategy.transform(item);
65
+ await strategy.validate(transformedData);
66
+ const createImport = {
67
+ tableName: attributes.tableName,
68
+ tenantCode: attributes.tenantCode,
69
+ attributes: transformedData,
70
+ };
71
+ createImportDtos.push(createImport);
72
+ }
73
+ catch (error) {
74
+ this.logger.warn(`Row ${index + 1} failed mapping.`, { item, error });
75
+ throw error;
76
+ }
77
+ }
78
+ const invokeContext = (0, core_1.extractInvokeContext)();
79
+ const options = {
80
+ invokeContext,
81
+ };
82
+ if (createImportDtos.length > 0) {
83
+ const importPromises = createImportDtos.map((dto) => this.importService.createImport(dto, options));
84
+ await Promise.all(importPromises);
85
+ }
86
+ }
87
+ async loadCsv(input, limit = 10) {
88
+ // 1. Fetch the S3 object stream
89
+ const { Body: s3Stream } = await this.s3Service.client.send(new client_s3_1.GetObjectCommand({
90
+ Bucket: input.bucket,
91
+ Key: input.key,
92
+ }));
93
+ if (!(s3Stream instanceof stream_1.Readable)) {
94
+ // This handles cases where the Body might not be a stream (e.g., error or empty object)
95
+ throw new Error('Failed to get a readable stream from S3 object.');
96
+ }
97
+ // 2. Wrap the stream processing in a Promise for async/await compatibility
98
+ return new Promise((resolve, reject) => {
99
+ const items = [];
100
+ const parser = (0, csv_parser_1.default)({
101
+ mapHeaders: ({ header }) => header.trim(),
102
+ mapValues: ({ value }) => value.trim(),
103
+ });
104
+ const streamPipeline = s3Stream.pipe(parser);
105
+ streamPipeline
106
+ .on('data', (row) => {
107
+ // Only push items until the limit is reached
108
+ if (items.length < limit) {
109
+ items.push(row);
110
+ }
111
+ else {
112
+ // 3. Efficiently destroy the stream once the limit is met.
113
+ // This stops reading the file from S3 and parsing, saving resources.
114
+ streamPipeline.destroy();
115
+ this.logger.debug(`Limit of ${limit} rows reached. Destroying stream.`);
116
+ resolve({
117
+ BatchInput: {
118
+ Attributes: input,
119
+ },
120
+ Items: items,
121
+ });
122
+ }
123
+ })
124
+ .on('end', () => {
125
+ // This 'end' event will only be reached if the file has fewer rows than the limit.
126
+ this.logger.debug(`CSV parsing finished. Found ${items.length} rows.`);
127
+ resolve({
128
+ BatchInput: {
129
+ Attributes: input,
130
+ },
131
+ Items: items,
132
+ });
133
+ })
134
+ .on('error', (error) => {
135
+ // Handle any errors during streaming or parsing
136
+ this.logger.error('Error parsing CSV stream:', error);
137
+ reject(error);
138
+ });
139
+ });
140
+ }
141
+ };
142
+ exports.CsvImportSfnEventHandler = CsvImportSfnEventHandler;
143
+ exports.CsvImportSfnEventHandler = CsvImportSfnEventHandler = CsvImportSfnEventHandler_1 = __decorate([
144
+ (0, core_1.EventHandler)(csv_import_sfn_event_1.CsvImportSfnEvent),
145
+ __param(1, (0, common_1.Inject)(import_module_definition_1.IMPORT_STRATEGY_MAP)),
146
+ __metadata("design:paramtypes", [import_service_1.ImportService,
147
+ Map,
148
+ config_1.ConfigService,
149
+ core_1.S3Service])
150
+ ], CsvImportSfnEventHandler);
151
+ //# sourceMappingURL=csv-import.sfn.event.handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv-import.sfn.event.handler.js","sourceRoot":"","sources":["../../src/event/csv-import.sfn.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,kDAAqD;AACrD,oDAMkC;AAClC,2CAA+C;AAC/C,2CAA8C;AAC9C,4DAA4B;AAC5B,mCAAiC;AAKjC,0EAAiE;AACjE,sDAAiD;AAEjD,iEAA0D;AAGnD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAMnC,YACmB,aAA4B,EAE7C,iBAA0E,EACzD,aAA4B,EAC5B,SAAoB;QAJpB,kBAAa,GAAb,aAAa,CAAe;QAE5B,sBAAiB,GAAjB,iBAAiB,CAAwC;QACzD,kBAAa,GAAb,aAAa,CAAe;QAC5B,cAAS,GAAT,SAAS,CAAW;QARtB,WAAM,GAAW,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAA;QAUzE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,qBAAqB,CAAC,CAAA;IAC5E,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAwB;QACpC,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,qDAAqD,EACrD,KAAK,CACN,CAAA;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,EAAE,EAAE;gBAC5B,gDAAgD;gBAChD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAA;gBACrD,MAAM,CAAC,KAAK,CAAC,CAAA;YACf,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AA5IY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAY,EAAC,wCAAiB,CAAC;IAS3B,WAAA,IAAA,eAAM,EAAC,8CAAmB,CAAC,CAAA;qCADI,8BAAa;QAET,GAAG;QACP,sBAAa;QACjB,gBAAS;GAX5B,wBAAwB,CA4IpC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CsvImportSfnEvent = void 0;
4
+ class CsvImportSfnEvent {
5
+ constructor(event) {
6
+ Object.assign(this, event);
7
+ this.source = event.context.Execution.Id;
8
+ }
9
+ }
10
+ exports.CsvImportSfnEvent = CsvImportSfnEvent;
11
+ // {
12
+ // "input": {
13
+ // "bucket": "local-bucket",
14
+ // "key": "csv/test.csv",
15
+ // "tableName": "policy",
16
+ // "tenantCode": "buildshiru"
17
+ // },
18
+ // "context": {
19
+ // "Execution": {
20
+ // "Id": "arn:aws:states:ap-northeast-1:101010101010:execution:csv-import:user-1705417891631",
21
+ // "Input": {
22
+ // "bucket": "local-bucket",
23
+ // "key": "csv/test.csv",
24
+ // "tableName": "policy",
25
+ // "tenantCode": "buildshiru"
26
+ // },
27
+ // "Name": "user-1705417891631",
28
+ // "RoleArn": "arn:aws:iam::101010101010:role/DummyRole",
29
+ // "StartTime": "2024-01-16T15:11:31.665Z"
30
+ // },
31
+ // "State": {
32
+ // "EnteredTime": "2024-01-16T15:11:31.666Z",
33
+ // "Name": "csv_loader",
34
+ // "RetryCount": 0
35
+ // },
36
+ // "StateMachine": {
37
+ // "Id": "arn:aws:states:ap-northeast-1:101010101010:stateMachine:csv-import",
38
+ // "Name": "csv-import"
39
+ // }
40
+ // }
41
+ // }
42
+ //# sourceMappingURL=csv-import.sfn.event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv-import.sfn.event.js","sourceRoot":"","sources":["../../src/event/csv-import.sfn.event.ts"],"names":[],"mappings":";;;AAKA,MAAa,iBAAiB;IAK5B,YAAY,KAAkC;QAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAA;IAC1C,CAAC;CACF;AATD,8CASC;AAED,IAAI;AACJ,eAAe;AACf,gCAAgC;AAChC,6BAA6B;AAC7B,6BAA6B;AAC7B,iCAAiC;AACjC,OAAO;AACP,iBAAiB;AACjB,qBAAqB;AACrB,oGAAoG;AACpG,mBAAmB;AACnB,oCAAoC;AACpC,iCAAiC;AACjC,iCAAiC;AACjC,qCAAqC;AACrC,WAAW;AACX,sCAAsC;AACtC,+DAA+D;AAC/D,gDAAgD;AAChD,SAAS;AACT,iBAAiB;AACjB,mDAAmD;AACnD,8BAA8B;AAC9B,wBAAwB;AACxB,SAAS;AACT,wBAAwB;AACxB,oFAAoF;AACpF,6BAA6B;AAC7B,QAAQ;AACR,MAAM;AACN,IAAI"}
@@ -0,0 +1,22 @@
1
+ import { DetailKey, IEvent } from '@mbc-cqrs-serverless/core';
2
+ import { DynamoDBRecord, StreamRecord } from 'aws-lambda';
3
+ import { ImportEntity } from '../entity/import-entity';
4
+ export declare const IMPORT_EVENT_ACTION = "import-execute";
5
+ export declare class ImportEvent implements IEvent, DynamoDBRecord {
6
+ source: string;
7
+ awsRegion?: string | undefined;
8
+ dynamodb?: StreamRecord | undefined;
9
+ eventID?: string | undefined;
10
+ eventName?: 'INSERT' | 'MODIFY' | 'REMOVE' | undefined;
11
+ eventSource?: string | undefined;
12
+ eventSourceARN?: string | undefined;
13
+ eventVersion?: string | undefined;
14
+ userIdentity?: any;
15
+ private _importKey;
16
+ private _importEntity?;
17
+ constructor(event?: Partial<ImportEvent>);
18
+ get tableName(): string;
19
+ fromDynamoDBRecord(record: DynamoDBRecord): ImportEvent;
20
+ get importEntity(): ImportEntity;
21
+ get importKey(): DetailKey;
22
+ }
@@ -0,0 +1,10 @@
1
+ import { IEventHandler, SnsService } from '@mbc-cqrs-serverless/core';
2
+ import { ImportService } from '../import.service';
3
+ import { ImportEvent } from './import.event';
4
+ export declare class ImportEventHandler implements IEventHandler<ImportEvent> {
5
+ private readonly snsService;
6
+ private readonly importService;
7
+ private readonly logger;
8
+ constructor(snsService: SnsService, importService: ImportService);
9
+ execute(event: ImportEvent): Promise<any>;
10
+ }
@@ -0,0 +1,38 @@
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 ImportEventHandler_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.ImportEventHandler = void 0;
14
+ const core_1 = require("@mbc-cqrs-serverless/core");
15
+ const common_1 = require("@nestjs/common");
16
+ const import_status_enum_1 = require("../enum/import-status.enum");
17
+ const import_service_1 = require("../import.service");
18
+ const import_event_1 = require("./import.event");
19
+ let ImportEventHandler = ImportEventHandler_1 = class ImportEventHandler {
20
+ constructor(snsService, importService) {
21
+ this.snsService = snsService;
22
+ this.importService = importService;
23
+ this.logger = new common_1.Logger(ImportEventHandler_1.name);
24
+ }
25
+ async execute(event) {
26
+ this.logger.debug('import event executing::', event);
27
+ // publish event to sns
28
+ await this.snsService.publish({ action: import_event_1.IMPORT_EVENT_ACTION, ...event });
29
+ return await this.importService.updateStatus(event.importKey, import_status_enum_1.ImportStatusEnum.QUEUED);
30
+ }
31
+ };
32
+ exports.ImportEventHandler = ImportEventHandler;
33
+ exports.ImportEventHandler = ImportEventHandler = ImportEventHandler_1 = __decorate([
34
+ (0, core_1.EventHandler)(import_event_1.ImportEvent),
35
+ __metadata("design:paramtypes", [core_1.SnsService,
36
+ import_service_1.ImportService])
37
+ ], ImportEventHandler);
38
+ //# sourceMappingURL=import.event.handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import.event.handler.js","sourceRoot":"","sources":["../../src/event/import.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oDAIkC;AAClC,2CAAuC;AAEvC,mEAA6D;AAC7D,sDAAiD;AACjD,iDAAiE;AAG1D,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAG7B,YACmB,UAAsB,EACtB,aAA4B;QAD5B,eAAU,GAAV,UAAU,CAAY;QACtB,kBAAa,GAAb,aAAa,CAAe;QAJ9B,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAA;IAK1D,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,KAAkB;QAC9B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAA;QACpD,uBAAuB;QACvB,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,kCAAmB,EAAE,GAAG,KAAK,EAAE,CAAC,CAAA;QAExE,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAC1C,KAAK,CAAC,SAAS,EACf,qCAAgB,CAAC,MAAM,CACxB,CAAA;IACH,CAAC;CACF,CAAA;AAlBY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAY,EAAC,0BAAW,CAAC;qCAKO,iBAAU;QACP,8BAAa;GALpC,kBAAkB,CAkB9B"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportEvent = exports.IMPORT_EVENT_ACTION = void 0;
4
+ const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
5
+ const core_1 = require("@mbc-cqrs-serverless/core");
6
+ exports.IMPORT_EVENT_ACTION = 'import-execute';
7
+ class ImportEvent {
8
+ constructor(event) {
9
+ Object.assign(this, event);
10
+ }
11
+ get tableName() {
12
+ return (0, core_1.getResourceNameFromArn)(this.source);
13
+ }
14
+ fromDynamoDBRecord(record) {
15
+ Object.assign(this, record, {
16
+ source: record.eventSourceARN,
17
+ });
18
+ return this;
19
+ }
20
+ get importEntity() {
21
+ if (!this._importEntity) {
22
+ this._importEntity = (0, util_dynamodb_1.unmarshall)(this.dynamodb?.NewImage);
23
+ }
24
+ return this._importEntity;
25
+ }
26
+ get importKey() {
27
+ if (!this._importKey) {
28
+ this._importKey = (0, util_dynamodb_1.unmarshall)(this.dynamodb?.Keys);
29
+ }
30
+ return this._importKey;
31
+ }
32
+ }
33
+ exports.ImportEvent = ImportEvent;
34
+ //# sourceMappingURL=import.event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import.event.js","sourceRoot":"","sources":["../../src/event/import.event.ts"],"names":[],"mappings":";;;AACA,0DAAmD;AACnD,oDAIkC;AAKrB,QAAA,mBAAmB,GAAG,gBAAgB,CAAA;AAEnD,MAAa,WAAW;IActB,YAAY,KAA4B;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAC5B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAA,6BAAsB,EAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,kBAAkB,CAAC,MAAsB;QACvC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE;YAC1B,MAAM,EAAE,MAAM,CAAC,cAAc;SAC9B,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,YAAY;QACd,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,IAAI,CAAC,aAAa,GAAG,IAAA,0BAAU,EAC7B,IAAI,CAAC,QAAQ,EAAE,QAA6C,CAC7C,CAAA;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;IAED,IAAI,SAAS;QACX,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,GAAG,IAAA,0BAAU,EAC1B,IAAI,CAAC,QAAQ,EAAE,IAAyC,CAC5C,CAAA;QAChB,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;CACF;AAhDD,kCAgDC"}
@@ -0,0 +1,18 @@
1
+ import { IEvent } from '@mbc-cqrs-serverless/core';
2
+ import { SQSMessageAttributes, SQSRecord, SQSRecordAttributes } from 'aws-lambda';
3
+ import { ImportEvent } from './import.event';
4
+ export declare class ImportQueueEvent implements IEvent, SQSRecord {
5
+ source: string;
6
+ messageId: string;
7
+ receiptHandle: string;
8
+ body: string;
9
+ attributes: SQSRecordAttributes;
10
+ messageAttributes: SQSMessageAttributes;
11
+ md5OfBody: string;
12
+ eventSource: string;
13
+ eventSourceARN: string;
14
+ awsRegion: string;
15
+ private _importEvent?;
16
+ fromSqsRecord(record: SQSRecord): ImportQueueEvent;
17
+ get importEvent(): ImportEvent;
18
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file import.queue.event.handler.ts
3
+ * @description This handler is the core worker for processing individual import records.
4
+ * It listens for messages from the main SQS queue, finds the correct processing
5
+ * strategy for the record's table type, and executes them sequentially.
6
+ */
7
+ import { IEventHandler } from '@mbc-cqrs-serverless/core';
8
+ import { ImportService } from '../import.service';
9
+ import { IProcessStrategy } from '../interface/processing-strategy.interface';
10
+ import { ImportQueueEvent } from './import.queue.event';
11
+ export declare class ImportQueueEventHandler implements IEventHandler<ImportQueueEvent> {
12
+ private readonly importService;
13
+ private readonly strategyMap;
14
+ private readonly logger;
15
+ constructor(importService: ImportService, strategyMap: Map<string, IProcessStrategy<any, any>>);
16
+ execute(event: ImportQueueEvent): Promise<any>;
17
+ /**
18
+ * Orchestrates the processing of a single import record.
19
+ */
20
+ handleImport(event: ImportQueueEvent): Promise<any>;
21
+ /**
22
+ * Executes the full lifecycle (compare, map, save) for a single strategy.
23
+ * @returns The result of the create/update operation or a status message.
24
+ */
25
+ private executeStrategy;
26
+ }
@@ -0,0 +1,121 @@
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 ImportQueueEventHandler_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.ImportQueueEventHandler = void 0;
17
+ /**
18
+ * @file import.queue.event.handler.ts
19
+ * @description This handler is the core worker for processing individual import records.
20
+ * It listens for messages from the main SQS queue, finds the correct processing
21
+ * strategy for the record's table type, and executes them sequentially.
22
+ */
23
+ const core_1 = require("@mbc-cqrs-serverless/core");
24
+ const common_1 = require("@nestjs/common");
25
+ const comparison_status_enum_1 = require("../enum/comparison-status.enum");
26
+ const import_status_enum_1 = require("../enum/import-status.enum");
27
+ const import_module_definition_1 = require("../import.module-definition");
28
+ const import_service_1 = require("../import.service");
29
+ const import_queue_event_1 = require("./import.queue.event");
30
+ let ImportQueueEventHandler = ImportQueueEventHandler_1 = class ImportQueueEventHandler {
31
+ constructor(importService, strategyMap) {
32
+ this.importService = importService;
33
+ this.strategyMap = strategyMap;
34
+ this.logger = new common_1.Logger(ImportQueueEventHandler_1.name);
35
+ }
36
+ async execute(event) {
37
+ const importEntity = event.importEvent.importEntity;
38
+ // This handler processes individual records, so it must ignore the master CSV jobs.
39
+ // Master jobs are handled exclusively by the CsvImportQueueEventHandler.
40
+ if (importEntity.type === 'CSV_MASTER_JOB') {
41
+ this.logger.debug(`Skipping CSV_MASTER_JOB in main queue handler: ${importEntity.id}`);
42
+ return;
43
+ }
44
+ await this.handleImport(event);
45
+ }
46
+ /**
47
+ * Orchestrates the processing of a single import record.
48
+ */
49
+ async handleImport(event) {
50
+ const importKey = event.importEvent.importKey;
51
+ const { attributes, tenantCode, type: tableName, } = event.importEvent.importEntity;
52
+ this.logger.debug(`Processing import job ${importKey.pk}#${importKey.sk} for table: ${tableName}`);
53
+ // 1. Find the correct strategies for this import's table type
54
+ const strategy = this.strategyMap.get(tableName);
55
+ if (!strategy) {
56
+ const error = new Error(`No import strategies registered for table: ${tableName}`);
57
+ this.logger.error(error);
58
+ await this.importService.updateStatus(importKey, import_status_enum_1.ImportStatusEnum.FAILED, { error: error.stack });
59
+ return;
60
+ }
61
+ try {
62
+ // 2. Set status to PROCESSING
63
+ await this.importService.updateStatus(importKey, import_status_enum_1.ImportStatusEnum.PROCESSING);
64
+ // 3. Execute all registered strategies in sequence for this record
65
+ const result = await this.executeStrategy(strategy, attributes, tenantCode);
66
+ // 4. Finalize the import status as COMPLETED
67
+ await this.importService.updateStatus(importKey, import_status_enum_1.ImportStatusEnum.COMPLETED, { result });
68
+ this.logger.log(`Successfully completed import job: ${importKey.pk}#${importKey.sk}`);
69
+ }
70
+ catch (error) {
71
+ // 5. Handle any errors during processing
72
+ this.logger.error(`Failed to process import job: ${importKey.pk}#${importKey.sk}`, error);
73
+ await Promise.all([
74
+ this.importService.updateStatus(importKey, import_status_enum_1.ImportStatusEnum.FAILED, {
75
+ error: {
76
+ message: error.message,
77
+ stack: error.stack,
78
+ },
79
+ }),
80
+ this.importService.publishAlarm(event, error.stack),
81
+ ]);
82
+ throw error;
83
+ }
84
+ }
85
+ /**
86
+ * Executes the full lifecycle (compare, map, save) for a single strategy.
87
+ * @returns The result of the create/update operation or a status message.
88
+ */
89
+ async executeStrategy(strategy, attributes, tenantCode) {
90
+ // 1. Determine if there are changes
91
+ const compareResult = await strategy.compare(attributes, tenantCode);
92
+ if (compareResult.status === comparison_status_enum_1.ComparisonStatus.EQUAL) {
93
+ return { status: 'EQUAL', message: 'No changes detected.' };
94
+ }
95
+ // 2. Map the attributes to the correct CommandService input model
96
+ // The strategy now handles the logic of building the payload.
97
+ const mappedData = await strategy.map(compareResult.status, attributes, tenantCode, compareResult.existingData);
98
+ const commandService = strategy.getCommandService();
99
+ let finalResult;
100
+ // 3. Execute the appropriate command
101
+ const invokeContext = (0, core_1.extractInvokeContext)();
102
+ const options = {
103
+ invokeContext,
104
+ };
105
+ if (compareResult.status === comparison_status_enum_1.ComparisonStatus.NOT_EXIST) {
106
+ finalResult = await commandService.publishAsync(mappedData, options);
107
+ }
108
+ else {
109
+ finalResult = await commandService.publishPartialUpdateAsync(mappedData, options);
110
+ }
111
+ return finalResult;
112
+ }
113
+ };
114
+ exports.ImportQueueEventHandler = ImportQueueEventHandler;
115
+ exports.ImportQueueEventHandler = ImportQueueEventHandler = ImportQueueEventHandler_1 = __decorate([
116
+ (0, core_1.EventHandler)(import_queue_event_1.ImportQueueEvent),
117
+ __param(1, (0, common_1.Inject)(import_module_definition_1.PROCESS_STRATEGY_MAP)),
118
+ __metadata("design:paramtypes", [import_service_1.ImportService,
119
+ Map])
120
+ ], ImportQueueEventHandler);
121
+ //# sourceMappingURL=import.queue.event.handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/import.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,oDAOkC;AAClC,2CAA+C;AAE/C,2EAAiE;AACjE,mEAA6D;AAC7D,0EAAkE;AAClE,sDAAiD;AAEjD,6DAAuD;AAGhD,IAAM,uBAAuB,+BAA7B,MAAM,uBAAuB;IAKlC,YACmB,aAA4B,EAE7C,WAAqE;QAFpD,kBAAa,GAAb,aAAa,CAAe;QAE5B,gBAAW,GAAX,WAAW,CAAyC;QALtD,WAAM,GAAG,IAAI,eAAM,CAAC,yBAAuB,CAAC,IAAI,CAAC,CAAA;IAM/D,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,KAAuB;QACnC,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,YAAY,CAAA;QAEnD,oFAAoF;QACpF,yEAAyE;QACzE,IAAI,YAAY,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAC3C,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,kDAAkD,YAAY,CAAC,EAAE,EAAE,CACpE,CAAA;YACD,OAAM;QACR,CAAC;QAED,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,KAAuB;QACxC,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,SAAS,CAAA;QAC7C,MAAM,EACJ,UAAU,EACV,UAAU,EACV,IAAI,EAAE,SAAS,GAChB,GAAG,KAAK,CAAC,WAAW,CAAC,YAAY,CAAA;QAClC,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,yBAAyB,SAAS,CAAC,EAAE,IAAI,SAAS,CAAC,EAAE,eAAe,SAAS,EAAE,CAChF,CAAA;QAED,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,uBAAuB;IADnC,IAAA,mBAAY,EAAC,qCAAgB,CAAC;IAQ1B,WAAA,IAAA,eAAM,EAAC,+CAAoB,CAAC,CAAA;qCADG,8BAAa;QAEf,GAAG;GARxB,uBAAuB,CAgJnC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportQueueEvent = void 0;
4
+ const import_event_1 = require("./import.event");
5
+ class ImportQueueEvent {
6
+ fromSqsRecord(record) {
7
+ Object.assign(this, record, {
8
+ source: record.eventSourceARN,
9
+ });
10
+ return this;
11
+ }
12
+ get importEvent() {
13
+ if (!this._importEvent) {
14
+ this._importEvent = new import_event_1.ImportEvent(JSON.parse(this.body));
15
+ }
16
+ return this._importEvent;
17
+ }
18
+ }
19
+ exports.ImportQueueEvent = ImportQueueEvent;
20
+ //# sourceMappingURL=import.queue.event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import.queue.event.js","sourceRoot":"","sources":["../../src/event/import.queue.event.ts"],"names":[],"mappings":";;;AAOA,iDAA4C;AAE5C,MAAa,gBAAgB;IAc3B,aAAa,CAAC,MAAiB;QAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE;YAC1B,MAAM,EAAE,MAAM,CAAC,cAAc;SAC9B,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,WAAW;QACb,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,IAAI,CAAC,YAAY,GAAG,IAAI,0BAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QAC5D,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;CACF;AA5BD,4CA4BC"}
@@ -0,0 +1,7 @@
1
+ export * from './csv-import.queue.event.handler';
2
+ export * from './csv-import.sfn.event';
3
+ export * from './csv-import.sfn.event.handler';
4
+ export * from './import.event';
5
+ export * from './import.event.handler';
6
+ export * from './import.queue.event';
7
+ export * from './import.queue.event.handler';
@@ -0,0 +1,24 @@
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("./csv-import.queue.event.handler"), exports);
18
+ __exportStar(require("./csv-import.sfn.event"), exports);
19
+ __exportStar(require("./csv-import.sfn.event.handler"), exports);
20
+ __exportStar(require("./import.event"), exports);
21
+ __exportStar(require("./import.event.handler"), exports);
22
+ __exportStar(require("./import.queue.event"), exports);
23
+ __exportStar(require("./import.queue.event.handler"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAgD;AAChD,yDAAsC;AACtC,iEAA8C;AAC9C,iDAA8B;AAC9B,yDAAsC;AACtC,uDAAoC;AACpC,+DAA4C"}
@@ -0,0 +1,22 @@
1
+ import { IInvoke } from '@mbc-cqrs-serverless/core';
2
+ import { CreateCsvImportDto } from './dto/create-csv-import.dto';
3
+ import { CreateImportDto } from './dto/create-import.dto';
4
+ import { ImportService } from './import.service';
5
+ export declare class ImportController {
6
+ private readonly importService;
7
+ private readonly logger;
8
+ constructor(importService: ImportService);
9
+ /**
10
+ * Endpoint for importing a single data record.
11
+ * This is typically used for real-time or low-volume data synchronization.
12
+ * The actual processing is asynchronous; this endpoint only validates the input
13
+ * and queues the import task.
14
+ */
15
+ createImport(invokeContext: IInvoke, createImportDto: CreateImportDto): Promise<import("./entity").ImportEntity>;
16
+ /**
17
+ * Endpoint for initiating a CSV file import.
18
+ * This endpoint accepts the location of a CSV file in S3 and allows the client
19
+ * to specify the processing strategy ('DIRECT' for small files, 'STEP_FUNCTION' for large files).
20
+ */
21
+ createCsvImport(invokeContext: IInvoke, createCsvImportDto: CreateCsvImportDto): Promise<import("./entity").ImportEntity | import("./entity").ImportEntity[]>;
22
+ }