@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,23 @@
1
+ import { Type } from '@nestjs/common';
2
+ import { IImportStrategy } from './import-strategy.interface';
3
+ import { IProcessStrategy } from './processing-strategy.interface';
4
+ /**
5
+ * Defines the complete import configuration for a single entity type (tableName).
6
+ * This unified profile groups all related strategies and validators.
7
+ */
8
+ export interface ImportEntityProfile {
9
+ /**
10
+ * A unique identifier for this data type (e.g., 'policies', 'users').
11
+ */
12
+ tableName: string;
13
+ /**
14
+ * The class that implements the initial import logic (transform & validate).
15
+ * Must be a class that adheres to the IImportStrategy interface.
16
+ */
17
+ importStrategy: Type<IImportStrategy<any, any>>;
18
+ /**
19
+ * The class that implements the business processing logic (compare & map).
20
+ * Must be a class that adheres to the IProcessStrategy interface.
21
+ */
22
+ processStrategy: Type<IProcessStrategy<any, any>>;
23
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=import-entity-profile.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-entity-profile.interface.js","sourceRoot":"","sources":["../../src/interface/import-entity-profile.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ export interface IImportStrategy<TInput extends object, TAttributesDto extends object> {
2
+ /**
3
+ * Transforms a raw input object (from an API, CSV row, etc.)
4
+ * into a standardized DTO.
5
+ */
6
+ transform(input: TInput): Promise<TAttributesDto>;
7
+ /**
8
+ * Validates the standardized DTO.
9
+ * @throws {Error} or a custom exception if validation fails.
10
+ */
11
+ validate(data: TAttributesDto): Promise<void>;
12
+ }
13
+ /**
14
+ * A base class (framework) that provides partial logic for an Import Strategy.
15
+ * Users can extend this class to save effort.
16
+ */
17
+ export declare abstract class BaseImportStrategy<TInput extends object, TAttributesDto extends object> implements IImportStrategy<TInput, TAttributesDto> {
18
+ transform(input: TInput): Promise<TAttributesDto>;
19
+ validate(data: TAttributesDto): Promise<void>;
20
+ /**
21
+ * Recursively flattens validation errors into a single array of strings.
22
+ * @param errors The array of ValidationError objects.
23
+ * @param parentPath The path of the parent property, used for building nested paths.
24
+ * @returns An array of human-readable error strings.
25
+ */
26
+ private flattenValidationErrors;
27
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseImportStrategy = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const class_validator_1 = require("class-validator");
6
+ /**
7
+ * A base class (framework) that provides partial logic for an Import Strategy.
8
+ * Users can extend this class to save effort.
9
+ */
10
+ class BaseImportStrategy {
11
+ async transform(input) {
12
+ return input;
13
+ }
14
+ async validate(data) {
15
+ const errors = await (0, class_validator_1.validate)(data);
16
+ if (errors.length > 0) {
17
+ const flatMessages = this.flattenValidationErrors(errors);
18
+ throw new common_1.BadRequestException({
19
+ statusCode: 400,
20
+ message: flatMessages,
21
+ error: 'Bad Request',
22
+ });
23
+ }
24
+ }
25
+ /**
26
+ * Recursively flattens validation errors into a single array of strings.
27
+ * @param errors The array of ValidationError objects.
28
+ * @param parentPath The path of the parent property, used for building nested paths.
29
+ * @returns An array of human-readable error strings.
30
+ */
31
+ flattenValidationErrors(errors, parentPath = '') {
32
+ const messages = [];
33
+ for (const error of errors) {
34
+ const currentPath = parentPath
35
+ ? `${parentPath}.${error.property}`
36
+ : error.property;
37
+ // If there are children, recurse to find the nested errors
38
+ if (error.children && error.children.length > 0) {
39
+ messages.push(...this.flattenValidationErrors(error.children, currentPath));
40
+ }
41
+ // Otherwise, we've found the constraint. Format the message.
42
+ else if (error.constraints) {
43
+ // The default message from class-validator often includes the property name.
44
+ // To avoid duplication like "attributes.policyType: policyType must be...",
45
+ // we can simply replace the first word of the message with the full path.
46
+ const firstConstraint = Object.values(error.constraints)[0];
47
+ const message = firstConstraint.replace(error.property, currentPath);
48
+ messages.push(message);
49
+ }
50
+ }
51
+ return messages;
52
+ }
53
+ }
54
+ exports.BaseImportStrategy = BaseImportStrategy;
55
+ //# sourceMappingURL=import-strategy.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-strategy.interface.js","sourceRoot":"","sources":["../../src/interface/import-strategy.interface.ts"],"names":[],"mappings":";;;AAAA,2CAAoD;AACpD,qDAA2D;AAmB3D;;;GAGG;AACH,MAAsB,kBAAkB;IAKtC,KAAK,CAAC,SAAS,CAAC,KAAa;QAC3B,OAAO,KAAkC,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAoB;QACjC,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAQ,EAAC,IAAI,CAAC,CAAA;QACnC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,YAAY,GAAG,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAA;YACzD,MAAM,IAAI,4BAAmB,CAAC;gBAC5B,UAAU,EAAE,GAAG;gBACf,OAAO,EAAE,YAAY;gBACrB,KAAK,EAAE,aAAa;aACrB,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACK,uBAAuB,CAC7B,MAAyB,EACzB,UAAU,GAAG,EAAE;QAEf,MAAM,QAAQ,GAAG,EAAE,CAAA;QACnB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,WAAW,GAAG,UAAU;gBAC5B,CAAC,CAAC,GAAG,UAAU,IAAI,KAAK,CAAC,QAAQ,EAAE;gBACnC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAA;YAElB,2DAA2D;YAC3D,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChD,QAAQ,CAAC,IAAI,CACX,GAAG,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,QAAQ,EAAE,WAAW,CAAC,CAC7D,CAAA;YACH,CAAC;YACD,6DAA6D;iBACxD,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;gBAC3B,6EAA6E;gBAC7E,4EAA4E;gBAC5E,0EAA0E;gBAC1E,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;gBAC3D,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAA;gBACpE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACxB,CAAC;QACH,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AAvDD,gDAuDC"}
@@ -0,0 +1,4 @@
1
+ export * from './csv-mapping-strategy.interface';
2
+ export * from './import-entity-profile.interface';
3
+ export * from './import-strategy.interface';
4
+ export * from './processing-strategy.interface';
@@ -0,0 +1,21 @@
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-mapping-strategy.interface"), exports);
18
+ __exportStar(require("./import-entity-profile.interface"), exports);
19
+ __exportStar(require("./import-strategy.interface"), exports);
20
+ __exportStar(require("./processing-strategy.interface"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAgD;AAChD,oEAAiD;AACjD,8DAA2C;AAC3C,kEAA+C"}
@@ -0,0 +1,57 @@
1
+ import { CommandInputModel, CommandPartialInputModel, CommandService, DataModel } from '@mbc-cqrs-serverless/core';
2
+ import { ComparisonStatus } from '../enum/comparison-status.enum';
3
+ /**
4
+ * Defines the standardized result of a comparison operation.
5
+ * It indicates whether the imported data corresponds to a new, changed, or identical entity.
6
+ * @template TEntity The type of the database entity model, extending DataModel.
7
+ */
8
+ export interface ComparisonResult<TEntity extends DataModel> {
9
+ status: ComparisonStatus;
10
+ /**
11
+ * If the status is 'CHANGED', this property holds the existing entity data
12
+ * retrieved from the database. It is undefined otherwise.
13
+ */
14
+ existingData?: TEntity;
15
+ }
16
+ /**
17
+ * The core strategy interface for processing a single, validated import record.
18
+ * Developers implement this interface to define the business logic for comparing
19
+ * imported data with existing records and mapping it to the final database model.
20
+ *
21
+ * @template TEntity The type of the final database entity model (e.g., ProductModel).
22
+ * @template TAttributesDto The type of the validated attributes DTO (e.g., CreateProductImportAttributesDto).
23
+ */
24
+ export interface IProcessStrategy<TEntity extends DataModel, TAttributesDto extends object> {
25
+ /**
26
+ * Compares the validated import data with data already in the target system
27
+ * to determine if it's a new entity, a changed one, or identical.
28
+ * @param importAttributes The strongly-typed, validated attributes object.
29
+ * @param tenantCode The tenant code for the operation.
30
+ * @returns A promise that resolves with a ComparisonResult object.
31
+ */
32
+ compare(importAttributes: TAttributesDto, tenantCode: string): Promise<ComparisonResult<TEntity>>;
33
+ /**
34
+ * Maps the validated import data into the precise input model required by the CommandService.
35
+ * The implementer is responsible for constructing the correct payload for either a
36
+ * create (`CommandInputModel`) or an update (`CommandPartialInputModel`).
37
+ *
38
+ * @param status The result from the `compare` step ('NOT_EXIST' or 'CHANGED').
39
+ * @param importAttributes The strongly-typed, validated attributes object.
40
+ * @param tenantCode The tenant code for the operation.
41
+ * @param existingData The existing entity data, provided if status is 'CHANGED'.
42
+ * @returns A promise that resolves with the input model for the CommandService.
43
+ */
44
+ map(status: Exclude<ComparisonStatus, ComparisonStatus.EQUAL>, importAttributes: TAttributesDto, tenantCode: string, existingData?: TEntity): Promise<CommandInputModel | CommandPartialInputModel>;
45
+ /**
46
+ * Provides an instance of the command service for the final database write.
47
+ */
48
+ getCommandService(): CommandService;
49
+ }
50
+ /**
51
+ * A base class (framework) for a Process Strategy.
52
+ */
53
+ export declare abstract class BaseProcessStrategy<TEntity extends DataModel, TTransformedDto extends object> implements IProcessStrategy<TEntity, TTransformedDto> {
54
+ abstract compare(transformedData: TTransformedDto, tenantCode: string): Promise<ComparisonResult<TEntity>>;
55
+ abstract map(status: Exclude<ComparisonStatus, ComparisonStatus.EQUAL>, transformedData: TTransformedDto, tenantCode: string, existingData?: TEntity): Promise<CommandInputModel | CommandPartialInputModel>;
56
+ abstract getCommandService(): CommandService;
57
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseProcessStrategy = void 0;
4
+ /**
5
+ * A base class (framework) for a Process Strategy.
6
+ */
7
+ class BaseProcessStrategy {
8
+ }
9
+ exports.BaseProcessStrategy = BaseProcessStrategy;
10
+ //# sourceMappingURL=processing-strategy.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processing-strategy.interface.js","sourceRoot":"","sources":["../../src/interface/processing-strategy.interface.ts"],"names":[],"mappings":";;;AAsEA;;GAEG;AACH,MAAsB,mBAAmB;CAkBxC;AAlBD,kDAkBC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@mbc-cqrs-serverless/import",
3
+ "version": "0.1.74-beta.0",
4
+ "description": "Import module",
5
+ "keywords": [
6
+ "mbc",
7
+ "cqrs",
8
+ "serverless",
9
+ "framework",
10
+ "event-driven",
11
+ "backend",
12
+ "aws",
13
+ "lambda",
14
+ "ecs",
15
+ "fargate",
16
+ "step-functions",
17
+ "sqs",
18
+ "typescript"
19
+ ],
20
+ "main": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "files": [
23
+ "dist",
24
+ "!dist/tsconfig.tsbuildinfo"
25
+ ],
26
+ "scripts": {
27
+ "build": "rm -rf dist && nest build",
28
+ "test": "echo \"Error: no test specified\" && exit 1"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/mbc-net/mbc-cqrs-serverless.git"
33
+ },
34
+ "author": "Murakami Business Consulting, Inc.",
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://github.com/mbc-net/mbc-cqrs-serverless/issues"
38
+ },
39
+ "homepage": "https://mbc-cqrs-serverless.mbc-net.com/",
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@mbc-cqrs-serverless/core": "^0.1.74-beta.0",
45
+ "csv-parser": "^3.2.0"
46
+ },
47
+ "gitHead": "c3befdd5f0b905b0b285acd12e3129c37e3f5f36"
48
+ }