aws-service-stack 0.15.215 → 0.16.218
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.
- package/dist/_examples/controller/supplier/{supplier-controller.d.ts → supplier-controller-api.d.ts} +3 -3
- package/dist/_examples/controller/supplier/{supplier-controller.js → supplier-controller-api.js} +8 -8
- package/dist/_examples/controller/supplier/supplier-controller-api.js.map +1 -0
- package/dist/_examples/controller/supplier/supplier-controller-stream.d.ts +12 -0
- package/dist/_examples/controller/supplier/supplier-controller-stream.js +67 -0
- package/dist/_examples/controller/supplier/supplier-controller-stream.js.map +1 -0
- package/dist/_examples/controller/supplier/supplier-crud.d.ts +1 -1
- package/dist/_examples/controller/supplier/supplier-crud.js +1 -1
- package/dist/_examples/controller/supplier/supplier-crud.js.map +1 -1
- package/dist/_examples/controller/supplier/supplier-streamer.d.ts +1 -1
- package/dist/_examples/controller/supplier/supplier-streamer.js +3 -2
- package/dist/_examples/controller/supplier/supplier-streamer.js.map +1 -1
- package/dist/_examples/service/supplier/{supplier-service.d.ts → supplier-service-crud.d.ts} +4 -3
- package/dist/_examples/service/supplier/{supplier-service.interface.d.ts → supplier-service-crud.interface.d.ts} +3 -2
- package/dist/_examples/service/supplier/supplier-service-crud.interface.js +3 -0
- package/dist/_examples/service/supplier/supplier-service-crud.interface.js.map +1 -0
- package/dist/_examples/service/supplier/{supplier-service.js → supplier-service-crud.js} +11 -11
- package/dist/_examples/service/supplier/supplier-service-crud.js.map +1 -0
- package/dist/_examples/service/supplier/supplier-service-stream.d.ts +13 -0
- package/dist/_examples/service/supplier/supplier-service-stream.interface.d.ts +5 -0
- package/dist/_examples/service/supplier/supplier-service-stream.interface.js +4 -0
- package/dist/_examples/service/supplier/supplier-service-stream.interface.js.map +1 -0
- package/dist/_examples/service/supplier/supplier-service-stream.js +72 -0
- package/dist/_examples/service/supplier/supplier-service-stream.js.map +1 -0
- package/dist/controller/base-controller.js +3 -2
- package/dist/controller/base-controller.js.map +1 -1
- package/dist/controller/controller-stream.d.ts +16 -0
- package/dist/controller/controller-stream.js +59 -0
- package/dist/controller/controller-stream.js.map +1 -0
- package/dist/service/stream.service.d.ts +17 -0
- package/dist/service/stream.service.interface.d.ts +14 -0
- package/dist/{_examples/service/supplier/supplier-service.interface.js → service/stream.service.interface.js} +1 -1
- package/dist/service/stream.service.interface.js.map +1 -0
- package/dist/service/stream.service.js +76 -0
- package/dist/service/stream.service.js.map +1 -0
- package/dist/utils/file-handler.d.ts +0 -7
- package/dist/utils/file-handler.js +1 -71
- package/dist/utils/file-handler.js.map +1 -1
- package/package.json +2 -4
- package/dist/_examples/controller/supplier/supplier-controller.js.map +0 -1
- package/dist/_examples/service/supplier/supplier-service.interface.js.map +0 -1
- package/dist/_examples/service/supplier/supplier-service.js.map +0 -1
package/dist/_examples/controller/supplier/{supplier-controller.d.ts → supplier-controller-api.d.ts}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { APIGatewayProxyEvent } from "aws-lambda";
|
|
2
|
-
import { SupplierService } from "../../service/supplier/supplier-service.interface";
|
|
3
|
-
import "../../service/supplier/supplier-service";
|
|
2
|
+
import { SupplierService } from "../../service/supplier/supplier-service-crud.interface";
|
|
3
|
+
import "../../service/supplier/supplier-service-crud";
|
|
4
4
|
import { ControllerApi } from "../../../controller/controller-api";
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class SupplierControllerApi extends ControllerApi<SupplierService> {
|
|
6
6
|
constructor();
|
|
7
7
|
protected processCrudRequest(event: APIGatewayProxyEvent): Promise<any>;
|
|
8
8
|
}
|
package/dist/_examples/controller/supplier/{supplier-controller.js → supplier-controller-api.js}
RENAMED
|
@@ -51,12 +51,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
51
51
|
});
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.
|
|
54
|
+
exports.SupplierControllerApi = void 0;
|
|
55
55
|
const typedi_1 = __importStar(require("typedi"));
|
|
56
56
|
const supplier_config_1 = require("./supplier-config");
|
|
57
|
-
require("../../service/supplier/supplier-service");
|
|
57
|
+
require("../../service/supplier/supplier-service-crud");
|
|
58
58
|
const controller_api_1 = require("../../../controller/controller-api");
|
|
59
|
-
let
|
|
59
|
+
let SupplierControllerApi = class SupplierControllerApi extends controller_api_1.ControllerApi {
|
|
60
60
|
constructor() {
|
|
61
61
|
const service = typedi_1.default.get("SupplierService");
|
|
62
62
|
super(service, supplier_config_1.CONFIG_SUPPLIER.toObject());
|
|
@@ -84,9 +84,9 @@ let SupplierController = class SupplierController extends controller_api_1.Contr
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
-
exports.
|
|
88
|
-
exports.
|
|
89
|
-
(0, typedi_1.Service)("
|
|
87
|
+
exports.SupplierControllerApi = SupplierControllerApi;
|
|
88
|
+
exports.SupplierControllerApi = SupplierControllerApi = __decorate([
|
|
89
|
+
(0, typedi_1.Service)("SupplierControllerApi"),
|
|
90
90
|
__metadata("design:paramtypes", [])
|
|
91
|
-
],
|
|
92
|
-
//# sourceMappingURL=supplier-controller.js.map
|
|
91
|
+
], SupplierControllerApi);
|
|
92
|
+
//# sourceMappingURL=supplier-controller-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplier-controller-api.js","sourceRoot":"","sources":["../../../../src/_examples/controller/supplier/supplier-controller-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,uDAA0D;AAG1D,wDAAsD;AACtD,uEAAmE;AAG5D,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,8BAA8B;IACvE;QACE,MAAM,OAAO,GAAoB,gBAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAClE,KAAK,CAAC,OAAO,EAAE,iCAAe,CAAC,QAAQ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typedi\";\n\nimport { APIGatewayProxyEvent } from \"aws-lambda\";\nimport { CONFIG_SUPPLIER, path } from \"./supplier-config\";\n\nimport { SupplierService } from \"../../service/supplier/supplier-service-crud.interface\";\nimport \"../../service/supplier/supplier-service-crud\";\nimport { ControllerApi } from \"../../../controller/controller-api\";\n\n@Service(\"SupplierControllerApi\")\nexport class SupplierControllerApi extends ControllerApi<SupplierService> {\n constructor() {\n const service: SupplierService = Container.get(\"SupplierService\");\n super(service, CONFIG_SUPPLIER.toObject());\n }\n\n protected async processCrudRequest(event: APIGatewayProxyEvent): Promise<any> {\n log.debug(`_example processCrudRequest: ${JSON.stringify(event, null, 2)}`);\n\n if (this.resourcePath === `GET ${path}/list-non-level-one`) {\n return await this.service.ListNonLevelOne(this.request.filterAndSort);\n }\n if (this.resourcePath === `GET ${path}/find-all`) {\n this.service.setConfig(CONFIG_SUPPLIER.toObject());\n try {\n // return await this.service.findAll();\n return await this.service.search(this.request.filterAndSort);\n } catch (err) {\n log.error(JSON.stringify(err, null, 2));\n }\n }\n\n if (this.resourcePath === `PUT ${path}/convert-to-cognito` && this.isAdmin) {\n const { username, email } = this.request.body;\n log.debug(`_example convert to cognito user: ${username}, email: ${email}`);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ControllerStream } from "../../../controller/controller-stream";
|
|
2
|
+
import { ActionDynamoDB } from "../../../model/index.js";
|
|
3
|
+
import { SupplierServiceStream } from "../../service/supplier/supplier-service-stream.interface";
|
|
4
|
+
import "../../service/supplier/supplier-service-stream";
|
|
5
|
+
export declare class SupplierControllerStream extends ControllerStream<SupplierServiceStream> {
|
|
6
|
+
constructor();
|
|
7
|
+
processStreamEventPre(oldItem: SupplierServiceStream, newItem: SupplierServiceStream, event: ActionDynamoDB, tableName: string): Promise<{
|
|
8
|
+
oldItem: SupplierServiceStream;
|
|
9
|
+
newItem: SupplierServiceStream;
|
|
10
|
+
}>;
|
|
11
|
+
processStreamEventPost(oldItem: SupplierServiceStream, newItem: SupplierServiceStream, event: ActionDynamoDB, tableName: string): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.SupplierControllerStream = void 0;
|
|
46
|
+
const typedi_1 = __importStar(require("typedi"));
|
|
47
|
+
const supplier_config_1 = require("./supplier-config");
|
|
48
|
+
const controller_stream_1 = require("../../../controller/controller-stream");
|
|
49
|
+
require("../../service/supplier/supplier-service-stream");
|
|
50
|
+
let SupplierControllerStream = class SupplierControllerStream extends controller_stream_1.ControllerStream {
|
|
51
|
+
constructor() {
|
|
52
|
+
const service = typedi_1.default.get("SupplierServiceStream");
|
|
53
|
+
super(service, supplier_config_1.CONFIG_SUPPLIER.toObject());
|
|
54
|
+
}
|
|
55
|
+
processStreamEventPre(oldItem, newItem, event, tableName) {
|
|
56
|
+
throw new Error("Method not implemented.");
|
|
57
|
+
}
|
|
58
|
+
processStreamEventPost(oldItem, newItem, event, tableName) {
|
|
59
|
+
throw new Error("Method not implemented.");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.SupplierControllerStream = SupplierControllerStream;
|
|
63
|
+
exports.SupplierControllerStream = SupplierControllerStream = __decorate([
|
|
64
|
+
(0, typedi_1.Service)("SupplierControllerStream"),
|
|
65
|
+
__metadata("design:paramtypes", [])
|
|
66
|
+
], SupplierControllerStream);
|
|
67
|
+
//# sourceMappingURL=supplier-controller-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplier-controller-stream.js","sourceRoot":"","sources":["../../../../src/_examples/controller/supplier/supplier-controller-stream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,uDAAoD;AACpD,6EAAyE;AAIzE,0DAAwD;AAGjD,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,oCAAuC;IACnF;QACE,MAAM,OAAO,GAA0B,gBAAS,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QAC9E,KAAK,CAAC,OAAO,EAAE,iCAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,qBAAqB,CACnB,OAA8B,EAC9B,OAA8B,EAC9B,KAAqB,EACrB,SAAiB;QAEjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,sBAAsB,CACpB,OAA8B,EAC9B,OAA8B,EAC9B,KAAqB,EACrB,SAAiB;QAEjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AAvBY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,EAAC,0BAA0B,CAAC;;GACvB,wBAAwB,CAuBpC","sourcesContent":["import Container, { Service } from \"typedi\";\nimport { CONFIG_SUPPLIER } from \"./supplier-config\";\nimport { ControllerStream } from \"../../../controller/controller-stream\";\nimport { ActionDynamoDB } from \"@chinggis/types\";\n\nimport { SupplierServiceStream } from \"../../service/supplier/supplier-service-stream.interface\";\nimport \"../../service/supplier/supplier-service-stream\";\n\n@Service(\"SupplierControllerStream\")\nexport class SupplierControllerStream extends ControllerStream<SupplierServiceStream> {\n constructor() {\n const service: SupplierServiceStream = Container.get(\"SupplierServiceStream\");\n super(service, CONFIG_SUPPLIER.toObject());\n }\n\n processStreamEventPre(\n oldItem: SupplierServiceStream,\n newItem: SupplierServiceStream,\n event: ActionDynamoDB,\n tableName: string,\n ): Promise<{ oldItem: SupplierServiceStream; newItem: SupplierServiceStream }> {\n throw new Error(\"Method not implemented.\");\n }\n\n processStreamEventPost(\n oldItem: SupplierServiceStream,\n newItem: SupplierServiceStream,\n event: ActionDynamoDB,\n tableName: string,\n ): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n}\n"]}
|
|
@@ -51,7 +51,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
51
51
|
exports.handler = void 0;
|
|
52
52
|
require("reflect-metadata");
|
|
53
53
|
const typedi_1 = __importStar(require("typedi"));
|
|
54
|
-
require("./supplier-controller");
|
|
54
|
+
require("./supplier-controller-api");
|
|
55
55
|
const handler = (event) => typedi_1.default.get(HelperCDI).process(event);
|
|
56
56
|
exports.handler = handler;
|
|
57
57
|
let HelperCDI = class HelperCDI {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supplier-crud.js","sourceRoot":"","sources":["../../../../src/_examples/controller/supplier/supplier-crud.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA0B;AAC1B,iDAA4C;AAI5C,
|
|
1
|
+
{"version":3,"file":"supplier-crud.js","sourceRoot":"","sources":["../../../../src/_examples/controller/supplier/supplier-crud.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA0B;AAC1B,iDAA4C;AAI5C,qCAAmC;AAE5B,MAAM,OAAO,GAAG,CAAC,KAA2B,EAAE,EAAE,CAAC,gBAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAAnF,QAAA,OAAO,WAA4E;AAGhG,IAAM,SAAS,GAAf,MAAM,SAAS;IAAf;QACmB,eAAU,GAA0B,gBAAS,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAQ3F,CAAC;IANO,OAAO,CAAC,KAA2B;;YACvC,GAAG,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;YAC5E,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC1C,GAAG,CAAC,KAAK,CAAC,kEAAkE,CAAC,CAAC;YAC9E,OAAO,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACnD,CAAC;KAAA;CACF,CAAA;AATK,SAAS;IADd,IAAA,gBAAO,GAAE;GACJ,SAAS,CASd","sourcesContent":["import \"reflect-metadata\";\nimport Container, { Service } from \"typedi\";\nimport { APIGatewayProxyEvent } from \"aws-lambda\";\n\nimport { SupplierControllerApi } from \"./supplier-controller-api\";\nimport \"./supplier-controller-api\";\n\nexport const handler = (event: APIGatewayProxyEvent) => Container.get(HelperCDI).process(event);\n\n@Service()\nclass HelperCDI {\n private readonly controller: SupplierControllerApi = Container.get(\"SupplierController\");\n\n async process(event: APIGatewayProxyEvent) {\n log.debug(\"_example event start----------------------------------------\\n\");\n log.debug(JSON.stringify(event, null, 2));\n log.debug(\"_example event end ----------------------------------------\\n\\n\");\n return this.controller.resolveCrudRequest(event);\n }\n}\n"]}
|
|
@@ -51,12 +51,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
51
51
|
exports.handler = void 0;
|
|
52
52
|
require("reflect-metadata");
|
|
53
53
|
const typedi_1 = __importStar(require("typedi"));
|
|
54
|
-
|
|
54
|
+
// Controller
|
|
55
|
+
require("./supplier-controller-api");
|
|
55
56
|
const handler = (event) => typedi_1.default.get(HelperCDI).process(event);
|
|
56
57
|
exports.handler = handler;
|
|
57
58
|
let HelperCDI = class HelperCDI {
|
|
58
59
|
constructor() {
|
|
59
|
-
this.controller = typedi_1.default.get("
|
|
60
|
+
this.controller = typedi_1.default.get("SupplierControllerStream");
|
|
60
61
|
}
|
|
61
62
|
process(event) {
|
|
62
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supplier-streamer.js","sourceRoot":"","sources":["../../../../src/_examples/controller/supplier/supplier-streamer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA0B;AAC1B,iDAA4C;
|
|
1
|
+
{"version":3,"file":"supplier-streamer.js","sourceRoot":"","sources":["../../../../src/_examples/controller/supplier/supplier-streamer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA0B;AAC1B,iDAA4C;AAG5C,aAAa;AACb,qCAAmC;AAG5B,MAAM,OAAO,GAAG,CAAC,KAA0B,EAAE,EAAE,CAAC,gBAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAAlF,QAAA,OAAO,WAA2E;AAG/F,IAAM,SAAS,GAAf,MAAM,SAAS;IAAf;QACmB,eAAU,GAA6B,gBAAS,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAKpG,CAAC;IAHO,OAAO,CAAC,KAA0B;;YACtC,0DAA0D;QAC5D,CAAC;KAAA;CACF,CAAA;AANK,SAAS;IADd,IAAA,gBAAO,GAAE;GACJ,SAAS,CAMd","sourcesContent":["import \"reflect-metadata\";\nimport Container, { Service } from \"typedi\";\nimport { DynamoDBStreamEvent } from \"aws-lambda\";\n\n// Controller\nimport \"./supplier-controller-api\";\nimport { SupplierControllerStream } from \"./supplier-controller-stream\";\n\nexport const handler = (event: DynamoDBStreamEvent) => Container.get(HelperCDI).process(event);\n\n@Service()\nclass HelperCDI {\n private readonly controller: SupplierControllerStream = Container.get(\"SupplierControllerStream\");\n\n async process(event: DynamoDBStreamEvent) {\n // return await this.controller.resolveStreamEvent(event);\n }\n}\n"]}
|
package/dist/_examples/service/supplier/{supplier-service.d.ts → supplier-service-crud.d.ts}
RENAMED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { SupplierService } from "./supplier-service.interface";
|
|
1
|
+
import { SupplierService } from "./supplier-service-crud.interface";
|
|
2
2
|
import { SupplierRepoDB } from "../../repositories/supplier/supplier-repo-db.interface";
|
|
3
3
|
import "../../repositories/supplier/supplier-repo-db";
|
|
4
4
|
import { SupplierRepoES } from "../../repositories/supplier/supplier-repo-es.interface";
|
|
5
5
|
import "../../repositories/supplier/supplier-repo-es";
|
|
6
|
-
import { ActionDynamoDB,
|
|
6
|
+
import { ActionDynamoDB, Filter, List } from "../../../index.js";
|
|
7
7
|
import { SAccount } from "../../model-shared/suppler.model";
|
|
8
|
-
|
|
8
|
+
import { CrudServiceImpl } from "../../../service/crud.service";
|
|
9
|
+
export declare class SupplierCrudServiceImpl extends CrudServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES> implements SupplierService {
|
|
9
10
|
constructor();
|
|
10
11
|
convertToCognitoUser(username: string, email: string): Promise<void>;
|
|
11
12
|
ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Filter, List } from "../../../index.js";
|
|
2
2
|
import { SAccount } from "../../model-shared/suppler.model";
|
|
3
|
-
|
|
3
|
+
import { CrudService } from "../../../service/crud.service.interface";
|
|
4
|
+
export interface SupplierService extends CrudService<SAccount> {
|
|
4
5
|
ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>>;
|
|
5
6
|
convertToCognitoUser(username: string, email: string): Promise<void>;
|
|
6
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplier-service-crud.interface.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-crud.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { Filter, List } from \"@chinggis/core\";\nimport { SAccount } from \"../../model-shared/suppler.model\";\nimport { CrudService } from \"../../../service/crud.service.interface\";\n\nexport interface SupplierService extends CrudService<SAccount> {\n ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>>;\n\n convertToCognitoUser(username: string, email: string): Promise<void>;\n}\n"]}
|
|
@@ -51,14 +51,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
51
51
|
});
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.
|
|
54
|
+
exports.SupplierCrudServiceImpl = void 0;
|
|
55
55
|
const typedi_1 = __importStar(require("typedi"));
|
|
56
56
|
require("../../repositories/supplier/supplier-repo-db");
|
|
57
57
|
require("../../repositories/supplier/supplier-repo-es");
|
|
58
58
|
const core_1 = require("../../../index.js");
|
|
59
|
-
const exception_handler_1 = require("../../../exception/exception-handler");
|
|
60
59
|
const supplier_config_1 = require("../../controller/supplier/supplier-config");
|
|
61
|
-
|
|
60
|
+
const crud_service_1 = require("../../../service/crud.service");
|
|
61
|
+
let SupplierCrudServiceImpl = class SupplierCrudServiceImpl extends crud_service_1.CrudServiceImpl {
|
|
62
62
|
// @Inject("EcomOrderService") private readonly ecomOrderService: EcomOrderService;
|
|
63
63
|
// @Inject("ROrderService") private readonly rOrderService: ROrderService;
|
|
64
64
|
//
|
|
@@ -71,11 +71,11 @@ let SupplierServiceImpl = class SupplierServiceImpl extends core_1.BaseServiceIm
|
|
|
71
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
72
|
const supplier = yield this.findById("system", username);
|
|
73
73
|
if (!supplier)
|
|
74
|
-
return this.throwError(
|
|
74
|
+
return this.throwError(core_1.HTTP.BAD_REQUEST.code, "supplier not found!");
|
|
75
75
|
if ((supplier === null || supplier === void 0 ? void 0 : supplier.loginStatus) === "pending")
|
|
76
|
-
return this.throwError(
|
|
76
|
+
return this.throwError(core_1.HTTP.BAD_REQUEST.code, "already pending user!");
|
|
77
77
|
if ((supplier === null || supplier === void 0 ? void 0 : supplier.loginStatus) === "confirmed")
|
|
78
|
-
return this.throwError(
|
|
78
|
+
return this.throwError(core_1.HTTP.BAD_REQUEST.code, "already confirmed user!");
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
ListNonLevelOne(filterAndSort) {
|
|
@@ -151,9 +151,9 @@ let SupplierServiceImpl = class SupplierServiceImpl extends core_1.BaseServiceIm
|
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
|
-
exports.
|
|
155
|
-
exports.
|
|
156
|
-
(0, typedi_1.Service)("
|
|
154
|
+
exports.SupplierCrudServiceImpl = SupplierCrudServiceImpl;
|
|
155
|
+
exports.SupplierCrudServiceImpl = SupplierCrudServiceImpl = __decorate([
|
|
156
|
+
(0, typedi_1.Service)("SupplierCrudService"),
|
|
157
157
|
__metadata("design:paramtypes", [])
|
|
158
|
-
],
|
|
159
|
-
//# sourceMappingURL=supplier-service.js.map
|
|
158
|
+
], SupplierCrudServiceImpl);
|
|
159
|
+
//# sourceMappingURL=supplier-service-crud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplier-service-crud.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-crud.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAK5C,wDAAsD;AAGtD,wDAAsD;AACtD,yCAAqF;AAErF,+EAAgF;AAChF,gEAAgE;AAGzD,IAAM,uBAAuB,GAA7B,MAAM,uBACX,SAAQ,8BAAyD;IAGjE,mFAAmF;IACnF,0EAA0E;IAE1E,EAAE;IACF;QACE,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,KAAK,CAAC,MAAM,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AAE,IAAI;yBACvB;qBACF;iBACF,CAAC,CAAC;YACL,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEhD,OAAO;gBACL,KAAK,EAAE,MAAM;gBACb,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;KAAA;IAEK,cAAc,CAAC,OAAiB,EAAE,OAAiB,EAAE,MAAsB,EAAE,SAAiB;;YAClG,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;KAAA;CACF,CAAA;AAlGY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,gBAAO,EAAC,qBAAqB,CAAC;;GAClB,uBAAuB,CAkGnC","sourcesContent":["import Container, { Service } from \"typedi\";\n\nimport { SupplierService } from \"./supplier-service-crud.interface\";\n\nimport { SupplierRepoDB } from \"../../repositories/supplier/supplier-repo-db.interface\";\nimport \"../../repositories/supplier/supplier-repo-db\";\n\nimport { SupplierRepoES } from \"../../repositories/supplier/supplier-repo-es.interface\";\nimport \"../../repositories/supplier/supplier-repo-es\";\nimport { ActionDynamoDB, Filter, HTTP, List, toCaseSensitive } from \"@chinggis/core\";\nimport { SAccount } from \"../../model-shared/suppler.model\";\nimport { openSearch_supplier } from \"../../controller/supplier/supplier-config\";\nimport { CrudServiceImpl } from \"../../../service/crud.service\";\n\n@Service(\"SupplierCrudService\")\nexport class SupplierCrudServiceImpl\n extends CrudServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES>\n implements SupplierService\n{\n // @Inject(\"EcomOrderService\") private readonly ecomOrderService: EcomOrderService;\n // @Inject(\"ROrderService\") private readonly rOrderService: ROrderService;\n\n //\n constructor() {\n const repoDB: SupplierRepoDB = Container.get(\"SupplierRepoDB\");\n const repoES: SupplierRepoES = Container.get(\"SupplierRepoES\");\n super(repoDB, repoES);\n }\n\n async convertToCognitoUser(username: string, email: string): Promise<void> {\n const supplier = await this.findById(\"system\", username);\n\n if (!supplier) return this.throwError(HTTP.BAD_REQUEST.code, \"supplier not found!\");\n if (supplier?.loginStatus === \"pending\") return this.throwError(HTTP.BAD_REQUEST.code, \"already pending user!\");\n if (supplier?.loginStatus === \"confirmed\") return this.throwError(HTTP.BAD_REQUEST.code, \"already confirmed user!\");\n }\n\n async ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>> {\n if (filterAndSort.page > 0) filterAndSort.page = filterAndSort.page - 1;\n const filter = {\n index: openSearch_supplier.index,\n body: {\n query: {\n bool: {\n must_not: [\n {\n term: {\n accountType: \"level1\",\n },\n },\n ],\n should: [],\n minimum_should_match: 1,\n },\n },\n from: filterAndSort.page * filterAndSort.size,\n size: filterAndSort.size,\n },\n };\n\n if (filterAndSort.page && filterAndSort.size) {\n filter.body.from = filterAndSort.page * filterAndSort.size;\n }\n\n if (filterAndSort.size) {\n filter.body.size = filterAndSort.size;\n }\n\n if (!filterAndSort.searchKeyword) {\n const result = await this.repoES.search(filter, true);\n return {\n items: result,\n lastKey: null,\n };\n }\n\n let searchKeyword = filterAndSort.searchKeyword.trim();\n\n const searchFields = [\"username\", \"firstName\", \"lastName\", \"phoneList\", \"bankAccountNumber\", \"bankName\"];\n searchKeyword = toCaseSensitive(searchKeyword);\n searchFields.forEach((field) => {\n filter.body.query.bool.should.push({\n regexp: {\n [field]: {\n value: `.*${searchKeyword}.*`,\n case_insensitive: true,\n },\n },\n });\n });\n\n if (searchKeyword.includes(\"@\")) {\n filter.body.query.bool.should.push({\n wildcard: {\n \"email.keyword\": {\n value: `*${searchKeyword}*`,\n case_insensitive: true,\n },\n },\n });\n }\n\n const result = await this.repoES.search(filter);\n\n return {\n items: result,\n lastKey: null,\n };\n }\n\n async processChanges(itemOld: SAccount, itemNew: SAccount, action: ActionDynamoDB, tableName: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SupplierRepoDB } from "../../repositories/supplier/supplier-repo-db.interface";
|
|
2
|
+
import "../../repositories/supplier/supplier-repo-db";
|
|
3
|
+
import { SupplierRepoES } from "../../repositories/supplier/supplier-repo-es.interface";
|
|
4
|
+
import "../../repositories/supplier/supplier-repo-es";
|
|
5
|
+
import { SAccount } from "../../model-shared/suppler.model";
|
|
6
|
+
import { SupplierServiceStream } from "./supplier-service-stream.interface";
|
|
7
|
+
import { StreamServiceImpl } from "../../../service/stream.service";
|
|
8
|
+
export declare class SupplierServiceStreamImpl extends StreamServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES> implements SupplierServiceStream {
|
|
9
|
+
constructor();
|
|
10
|
+
processDeletion(oldItem: SAccount, newItem: SAccount, tableName?: string): Promise<any>;
|
|
11
|
+
processInsertion(newItem: SAccount, tableName: string): Promise<any>;
|
|
12
|
+
processModification(itemOld: SAccount, itemNew: SAccount, tableName?: string): Promise<any>;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplier-service-stream.interface.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-stream.interface.ts"],"names":[],"mappings":";;AAEA,2CAAyC","sourcesContent":["import { SAccount } from \"../../model-shared/suppler.model\";\nimport { StreamService } from \"../../../service/stream.service.interface\";\nimport \"../../../service/stream.service\";\n\nexport interface SupplierServiceStream extends StreamService<SAccount> {}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.SupplierServiceStreamImpl = void 0;
|
|
46
|
+
const typedi_1 = __importStar(require("typedi"));
|
|
47
|
+
require("../../repositories/supplier/supplier-repo-db");
|
|
48
|
+
require("../../repositories/supplier/supplier-repo-es");
|
|
49
|
+
const stream_service_1 = require("../../../service/stream.service");
|
|
50
|
+
let SupplierServiceStreamImpl = class SupplierServiceStreamImpl extends stream_service_1.StreamServiceImpl {
|
|
51
|
+
//
|
|
52
|
+
constructor() {
|
|
53
|
+
const repoDB = typedi_1.default.get("SupplierRepoDB");
|
|
54
|
+
const repoES = typedi_1.default.get("SupplierRepoES");
|
|
55
|
+
super(repoDB, repoES);
|
|
56
|
+
}
|
|
57
|
+
processDeletion(oldItem, newItem, tableName) {
|
|
58
|
+
throw new Error("Method not implemented.");
|
|
59
|
+
}
|
|
60
|
+
processInsertion(newItem, tableName) {
|
|
61
|
+
throw new Error("Method not implemented.");
|
|
62
|
+
}
|
|
63
|
+
processModification(itemOld, itemNew, tableName) {
|
|
64
|
+
throw new Error("Method not implemented.");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.SupplierServiceStreamImpl = SupplierServiceStreamImpl;
|
|
68
|
+
exports.SupplierServiceStreamImpl = SupplierServiceStreamImpl = __decorate([
|
|
69
|
+
(0, typedi_1.Service)("SupplierStreamService"),
|
|
70
|
+
__metadata("design:paramtypes", [])
|
|
71
|
+
], SupplierServiceStreamImpl);
|
|
72
|
+
//# sourceMappingURL=supplier-service-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplier-service-stream.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-stream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,wDAAsD;AAGtD,wDAAsD;AAGtD,oEAAoE;AAG7D,IAAM,yBAAyB,GAA/B,MAAM,yBACX,SAAQ,kCAA2D;IAGnE,EAAE;IACF;QACE,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,eAAe,CAAC,OAAiB,EAAE,OAAiB,EAAE,SAAkB;QACtE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,gBAAgB,CAAC,OAAiB,EAAE,SAAiB;QACnD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,mBAAmB,CAAC,OAAiB,EAAE,OAAiB,EAAE,SAAkB;QAC1E,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AApBY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,gBAAO,EAAC,uBAAuB,CAAC;;GACpB,yBAAyB,CAoBrC","sourcesContent":["import Container, { Service } from \"typedi\";\n\nimport { SupplierRepoDB } from \"../../repositories/supplier/supplier-repo-db.interface\";\nimport \"../../repositories/supplier/supplier-repo-db\";\n\nimport { SupplierRepoES } from \"../../repositories/supplier/supplier-repo-es.interface\";\nimport \"../../repositories/supplier/supplier-repo-es\";\nimport { SAccount } from \"../../model-shared/suppler.model\";\nimport { SupplierServiceStream } from \"./supplier-service-stream.interface\";\nimport { StreamServiceImpl } from \"../../../service/stream.service\";\n\n@Service(\"SupplierStreamService\")\nexport class SupplierServiceStreamImpl\n extends StreamServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES>\n implements SupplierServiceStream\n{\n //\n constructor() {\n const repoDB: SupplierRepoDB = Container.get(\"SupplierRepoDB\");\n const repoES: SupplierRepoES = Container.get(\"SupplierRepoES\");\n super(repoDB, repoES);\n }\n\n processDeletion(oldItem: SAccount, newItem: SAccount, tableName?: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n processInsertion(newItem: SAccount, tableName: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n processModification(itemOld: SAccount, itemNew: SAccount, tableName?: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n}\n"]}
|
|
@@ -306,6 +306,7 @@ class BaseController {
|
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
parserUserData(claims) {
|
|
309
|
+
var _a, _b;
|
|
309
310
|
if (this.profileId)
|
|
310
311
|
return;
|
|
311
312
|
// request user data
|
|
@@ -317,8 +318,8 @@ class BaseController {
|
|
|
317
318
|
const groups = (0, string_util_1.normalizeLower)((0, string_util_1.toArray)(this.groups));
|
|
318
319
|
this.isAdmin = groups.some((g) => adminGroups.has(g));
|
|
319
320
|
if (this.isAdmin) {
|
|
320
|
-
this.profileId = this.request.body
|
|
321
|
-
|
|
321
|
+
this.profileId = ((_a = this.request.body) === null || _a === void 0 ? void 0 : _a.ownerId) || "";
|
|
322
|
+
(_b = this.request.body) === null || _b === void 0 ? true : delete _b.ownerId;
|
|
322
323
|
this.requestType = index_1.RequestType.ADMIN;
|
|
323
324
|
}
|
|
324
325
|
else if (this.profileId || this.userId)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-controller.js","sourceRoot":"","sources":["../../src/controller/base-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAkBkB;AAalB,4CAA2D;AAE3D,sDAAgF;AAEhF;;GAEG;AACH,MAAsB,cAAc;IAqBlC,YAAsB,WAAc,EAAE,MAAoB;QAPhD,WAAM,GAAa,EAAE,CAAC;QAQ9B,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAE3B,qCAAqC;QACrC,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,8CAA8C;QAC9C,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC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C,UAAU,CAAC,IAAI,EAAE,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtC,MAAM,cAAc,GAAG,CAAA,MAAA,OAAO,CAAC,aAAa,CAAC,0CAAE,WAAW,EAAE,KAAI,EAAE,CAAC;QACnE,IAAI,cAAc,EAAE,CAAC;YACnB,QAAQ,cAAc,EAAE,CAAC;gBACvB,KAAK,OAAO;oBACV,IAAI,CAAC,WAAW,GAAG,mBAAW,CAAC,KAAK,CAAC;oBACrC,MAAM;gBACR,KAAK,MAAM;oBACT,IAAI,CAAC,WAAW,GAAG,mBAAW,CAAC,IAAI,CAAC;oBACpC,MAAM;gBACR,KAAK,OAAO;oBACV,IAAI,CAAC,WAAW,GAAG,mBAAW,CAAC,KAAK,CAAC;oBACrC,MAAM;gBACR,KAAK,QAAQ;oBACX,IAAI,CAAC,WAAW,GAAG,mBAAW,CAAC,MAAM,CAAC;oBACtC,MAAM;YACV,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAjbD,wCAibC","sourcesContent":["import {\n Access,\n APIResponse,\n BaseService,\n createApiResponse,\n EndpointPolicy,\n findMatchedPolicy,\n formatErrors,\n getTableName,\n HttpMethod,\n HttpRequest,\n parseEventToAction,\n parseHttpRequest,\n parseImage,\n removeFields,\n RequestType,\n ResponseFields,\n validateWithSchema,\n} from \"../index\";\nimport {\n APIGatewayProxyEvent,\n APIGatewayProxyWebsocketEventV2,\n CreateAuthChallengeTriggerEvent,\n DefineAuthChallengeTriggerEvent,\n DynamoDBStreamEvent,\n PostConfirmationTriggerEvent,\n PreSignUpTriggerEvent,\n ScheduledEvent,\n SQSEvent,\n VerifyAuthChallengeResponseTriggerEvent,\n} from \"aws-lambda\";\nimport { errorHandlerHttp, ErrorHttp } from \"../exception\";\nimport { EntityConfig } from \"@chinggis/types\";\nimport { normalizeLower, toArray, trimSpecialChar } from \"../utils/string.util\";\n\n/**\n * @deprecated Use `ControllerApi, ControllerSocket, ControllerStream` instead.\n */\nexport abstract class BaseController<T extends BaseService<any, any>> {\n protected resourcePath: string;\n protected userId: string;\n protected isAdmin: boolean;\n protected request: HttpRequest;\n protected readonly service: T;\n protected adminGroupNames: string[];\n protected requestBody: any;\n protected triggerEvent: any;\n protected eventAttr: any;\n protected event: APIGatewayProxyEvent;\n protected resource: string;\n protected entityId: string;\n protected methode: HttpMethod;\n protected groups: string[] = [];\n protected username: string;\n protected profileId: string;\n protected requestType: RequestType;\n protected config: EntityConfig;\n protected path: string;\n\n protected constructor(baseService: T, config: EntityConfig) {\n this.service = baseService;\n\n // Store config for use in subclasses\n if (!config) return;\n\n this.config = config;\n // Set adminGroupName from config if available\n if (config.ADMIN_GROUP_NAME) {\n this.adminGroupNames = config.ADMIN_GROUP_NAME;\n }\n\n this.service.setConfig(config);\n }\n\n async resolveCrudRequest(event: APIGatewayProxyEvent): Promise<APIResponse> {\n try {\n this.bootstrapRequest(event);\n\n const policy: EndpointPolicy | undefined = findMatchedPolicy(\n this.methode,\n this.path,\n this.config.ENDPOINT_POLICY,\n );\n\n this.checkPermission(policy?.access);\n this.validateRequest(policy?.validator);\n this.setUserFilter();\n\n const response: any = await this.handleCrudByMethod(event);\n\n if (!policy?.response) {\n return createApiResponse(200, response);\n }\n\n const filteredResponse = this.filterResponse(response, policy.response);\n\n return createApiResponse(200, filteredResponse);\n } catch (err) {\n const error = errorHandlerHttp(err);\n log.error(error);\n return createApiResponse(error.statusCode, error.content);\n }\n }\n\n async resolveSQSEvent(sqsEvent: SQSEvent): Promise<void> {\n try {\n await this.processSQSEvent(sqsEvent);\n } catch (error) {\n console.error(\"Error handling SQS event:\", error);\n }\n }\n\n async resolveStreamEvent(event: DynamoDBStreamEvent): Promise<void> {\n try {\n for (const record of event.Records) {\n const oldItem = parseImage(record.dynamodb.OldImage) as T;\n const newItem = parseImage(record.dynamodb.NewImage) as T;\n\n await this.service.processChanges(\n oldItem,\n newItem,\n parseEventToAction(record.eventName),\n getTableName(record.eventSourceARN),\n );\n }\n await this.processStreamEvent(event);\n } catch (error) {\n console.error(\"Error handling request event:\", error);\n }\n }\n\n async resolveScheduledEvent(event: ScheduledEvent): Promise<void> {\n try {\n await this.processScheduledEvent(event);\n } catch (error) {\n console.error(\"Error handling request event:\", error);\n }\n }\n\n async resolveWebSocketEvent(event: APIGatewayProxyWebsocketEventV2): Promise<void> {\n try {\n return await this.processWebSocketEvent(event);\n } catch (error) {\n console.error(\"Error handling request event:\", error);\n }\n }\n\n async resolveTriggerEvent(\n event:\n | CreateAuthChallengeTriggerEvent\n | DefineAuthChallengeTriggerEvent\n | VerifyAuthChallengeResponseTriggerEvent\n | PostConfirmationTriggerEvent\n | PreSignUpTriggerEvent,\n ): Promise<void> {\n try {\n this.triggerEvent = event;\n this.eventAttr = this.triggerEvent.userAttributes;\n return await this.processTriggerEvent(event);\n } catch (error) {\n console.error(\"Error handling request event:\", error);\n }\n }\n\n setConfig(config: EntityConfig): void {\n this.config = config;\n }\n\n protected async handleList(): Promise<any> {\n if (this.methode === \"GET\" && trimSpecialChar(this.path) === trimSpecialChar(this.config.BASE_PATH)) {\n return await this.service.find(this.request.filterAndSort || {});\n }\n\n if (this.methode === \"GET\" && trimSpecialChar(this.path) === trimSpecialChar(this.config.BASE_PATH) + \"/search\") {\n return await this.service.search(this.request.filterAndSort || {});\n }\n\n if (this.methode === \"GET\" && trimSpecialChar(this.path) === trimSpecialChar(this.config.BASE_PATH) + \"/scan\") {\n return await this.service.scan(this.request.filterAndSort || {});\n }\n }\n\n protected async handleUpdate(): Promise<any> {\n if (!this.entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot PATCH resource without id field\");\n\n const entity = this.parseEntity();\n\n if (Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"No fields to update\");\n }\n\n // id change is forbidden\n if (\"id\" in entity) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot modify the id field\");\n }\n\n entity.id = this.entityId;\n return this.service.update(entity, this.profileId);\n }\n\n protected async handleDelete(): Promise<boolean> {\n if (!this.entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot delete resource without id field\");\n\n return this.service.remove(this.entityId, this.profileId);\n }\n\n protected async handleFetch(): Promise<any> {\n if (!this.entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot fetch resource without id field\");\n\n const result = await this.service.findById(this.entityId, this.profileId);\n\n if (result) return result;\n\n throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `Resource with ID ${this.entityId} not found`);\n }\n\n protected async handleReplace() {\n if (!this.entityId) throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot PUT resource without id field\");\n\n const entity = this.parseEntity();\n\n if (!Object.keys(entity).length) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"No entity provided for PUT update\");\n }\n\n if (!this.entityId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot PUT resource without id field\");\n }\n\n entity.id = this.entityId;\n\n return this.service.update(entity, this.profileId);\n }\n\n protected async handlePostCreate() {\n const entity = this.parseEntity();\n if (!Object.keys(entity).length) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"No entity payload provided\");\n }\n\n if (!this.isAdmin) entity.profileId = this.profileId;\n else if (!entity.profileId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"No profileId provided\");\n }\n\n return await this.service.save(entity, this.profileId);\n }\n\n protected abstract processCrudRequest(event: APIGatewayProxyEvent): Promise<any>;\n\n /**\n * service дээр processChanges methode ажилсны дараа хийгдэх үйлдлүүд байна\n * @param event - DynamoDBStreamEvent\n * @returns Promise<void>\n * */\n protected abstract processStreamEvent(event: DynamoDBStreamEvent): Promise<void>;\n\n protected abstract processScheduledEvent(event: ScheduledEvent): Promise<void>;\n\n protected abstract processWebSocketEvent(event: APIGatewayProxyWebsocketEventV2): Promise<void>;\n\n protected processTriggerEvent?(\n event:\n | CreateAuthChallengeTriggerEvent\n | DefineAuthChallengeTriggerEvent\n | VerifyAuthChallengeResponseTriggerEvent\n | PostConfirmationTriggerEvent\n | PreSignUpTriggerEvent,\n ): Promise<void> {\n throw new Error(`Method not implemented. event: ${JSON.stringify(event, null, 2)}`);\n }\n\n protected abstract processSQSEvent(sqsEvent: SQSEvent): Promise<any>;\n\n protected isListRequest(): boolean {\n const basePath = trimSpecialChar(this.config.BASE_PATH);\n\n const allowedPaths = [basePath, `${basePath}/search`, `${basePath}/scan`];\n\n const isMethodGet = this.methode === \"GET\";\n const isAllowedPath = allowedPaths.includes(trimSpecialChar(this.path));\n\n return isMethodGet && isAllowedPath;\n }\n\n protected isUpdateRequest(): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodPatch = this.methode === \"PATCH\";\n const isExpectedPath = trimSpecialChar(this.path) === expectedPath;\n\n return isMethodPatch && isExpectedPath;\n }\n\n protected isDeleteRequest(): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodDelete = this.methode === \"DELETE\";\n const isExpectedPath = trimSpecialChar(this.path) === expectedPath;\n\n return isMethodDelete && isExpectedPath;\n }\n\n protected isFetchRequest(): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = this.methode === \"GET\";\n const isExpectedPath = trimSpecialChar(this.path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n private async handleCrudByMethod(event: APIGatewayProxyEvent): Promise<any> {\n if (this.isUpdateRequest()) return this.handleUpdate();\n if (this.isDeleteRequest()) return this.handleDelete();\n if (this.isFetchRequest()) return this.handleFetch();\n if (this.methode === \"PUT\") return this.handleReplace();\n if (this.methode === \"POST\") return this.handlePostCreate();\n if (this.isListRequest()) return this.handleList();\n return this.processCrudRequest(event); // Custom Endpoints\n }\n\n private filterResponse(response: any, responsePolicy: ResponseFields): any {\n if (Array.isArray(response)) {\n return removeFields(response, responsePolicy.include, responsePolicy.exclude);\n }\n\n if (response?.items && Array.isArray(response.items)) {\n response.items = removeFields(response.items, responsePolicy.include, responsePolicy.exclude);\n return response;\n }\n\n return removeFields([response], responsePolicy.include, responsePolicy.exclude)[0];\n }\n\n /**\n * Map RequestType to Access for permission checking\n */\n private getUserAccessLevel(): Access {\n switch (this.requestType) {\n case RequestType.ADMIN:\n return Access.ADMIN;\n case RequestType.USER:\n return Access.USER;\n case RequestType.GUEST:\n return Access.PUBLIC;\n case RequestType.SYSTEM:\n return Access.SYSTEM;\n default:\n return Access.PUBLIC;\n }\n }\n\n /** Check if the user has permission for the current operation */\n private checkPermission(allowedAccess: Access[]) {\n const currentAccessLevel = this.getUserAccessLevel();\n\n // This means USER can access OWNER-level permissions, but the service will verify actual ownership\n const hasPermission =\n allowedAccess.includes(currentAccessLevel) ||\n (this.requestType === RequestType.USER && allowedAccess.includes(Access.OWNER));\n\n if (hasPermission) return;\n\n throw new ErrorHttp(\n { code: 403, error: \"PermissionDenied\" },\n `Access denied. Required: ${allowedAccess.join(\", \")}, Current: ${currentAccessLevel}`,\n );\n }\n\n private setUserFilter() {\n if (this.isAdmin && !this.profileId) return;\n const ownerIdFieldName = this.config.OWNER_ID_FIELD_NAME || \"ownerId\";\n this.request.filterAndSort[ownerIdFieldName] = this.profileId;\n }\n\n private bootstrapRequest(event: APIGatewayProxyEvent) {\n log.info(\"event: \" + JSON.stringify(event, null, 2));\n\n this.event = event;\n this.resource = event.resource || undefined;\n\n this.methode = event.httpMethod as HttpMethod;\n this.path = event?.requestContext?.resourcePath;\n this.resourcePath = `${this.methode} ${this.path}`;\n\n this.request = parseHttpRequest(event);\n this.requestBody = this.request.body;\n this.entityId = event.pathParameters?.id || undefined;\n\n this.parseEnvData();\n this.parserUserData(event.requestContext?.authorizer?.claims);\n }\n\n private parseEntity(): Record<string, unknown> {\n if (!this.requestBody) return {};\n return typeof this.requestBody === \"string\" ? JSON.parse(this.requestBody) : this.requestBody;\n }\n\n private validateRequest(schema: any) {\n if (!schema) return;\n\n try {\n validateWithSchema(schema, this.requestBody);\n } catch (error) {\n const formattedErrors = formatErrors(error);\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, formattedErrors);\n }\n }\n\n private parserUserData(claims: any) {\n if (this.profileId) return;\n\n // request user data\n this.groups = toArray(claims?.[\"cognito:groups\"]);\n this.username = claims?.[\"cognito:username\"] || \"\";\n this.userId = claims?.sub || \"\";\n this.profileId = claims?.[\"custom:profileId\"] || this.username;\n\n const adminGroups = new Set(normalizeLower(toArray(this.adminGroupNames)));\n const groups = normalizeLower(toArray(this.groups));\n this.isAdmin = groups.some((g) => adminGroups.has(g));\n\n if (this.isAdmin) {\n this.profileId = this.request.body[\"ownerId\"] || \"\";\n delete this.request.body[\"ownerId\"];\n this.requestType = RequestType.ADMIN;\n } else if (this.profileId || this.userId) this.requestType = RequestType.USER;\n else this.requestType = RequestType.GUEST;\n\n log.info(\"groups: \" + JSON.stringify(this.groups, null, 2));\n log.info(`claims:${JSON.stringify(claims, null, 2)}`);\n log.info(\n `groups:${this.groups}, isAdmin:${this.isAdmin}, userId:${this.userId}, profileId:${this.profileId}, username:${this.username}, requestType:${this.requestType}`,\n );\n }\n\n /** DEV **/\n private parseEnvData() {\n if (process.env.ENV?.toLowerCase()?.trim() !== \"dev\") return;\n\n log.debug(\"dev mode detected. Use custom header to initialize user data\");\n\n const headers = this.request.headers;\n\n this.profileId = \"\";\n if (this.requestBody?.ownerId) {\n this.profileId = this.requestBody.ownerId;\n delete this.requestBody.ownerId;\n }\n this.groups = toArray(headers[\"groups\"]);\n this.username = headers[\"username\"] || \"\";\n this.userId = headers[\"userId\"] || \"\";\n const requestTypeStr = headers[\"requestType\"]?.toUpperCase() || \"\";\n if (requestTypeStr) {\n switch (requestTypeStr) {\n case \"ADMIN\":\n this.requestType = RequestType.ADMIN;\n break;\n case \"USER\":\n this.requestType = RequestType.USER;\n break;\n case \"GUEST\":\n this.requestType = RequestType.GUEST;\n break;\n case \"SYSTEM\":\n this.requestType = RequestType.SYSTEM;\n break;\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base-controller.js","sourceRoot":"","sources":["../../src/controller/base-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAkBkB;AAalB,4CAA2D;AAE3D,sDAAgF;AAEhF;;GAEG;AACH,MAAsB,cAAc;IAqBlC,YAAsB,WAAc,EAAE,MAAoB;QAPhD,WAAM,GAAa,EAAE,CAAC;QAQ9B,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAE3B,qCAAqC;QACrC,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,8CAA8C;QAC9C,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC5B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,gBAAgB,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAEK,kBAAkB,CAAC,KAA2B;;YAClD,IAAI,CAAC;gBACH,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;gBAE7B,MAAM,MAAM,GAA+B,IAAA,yBAAiB,EAC1D,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,MAAM,CAAC,eAAe,CAC5B,CAAC;gBAEF,IAAI,CAAC,eAAe,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,CAAC,CAAC;gBACrC,IAAI,CAAC,eAAe,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,CAAC,CAAC;gBACxC,IAAI,CAAC,aAAa,EAAE,CAAC;gBAErB,MAAM,QAAQ,GAAQ,MAAM,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;gBAE3D,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,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n EndpointPolicy,\n findMatchedPolicy,\n formatErrors,\n getTableName,\n HttpMethod,\n HttpRequest,\n parseEventToAction,\n parseHttpRequest,\n parseImage,\n removeFields,\n RequestType,\n ResponseFields,\n validateWithSchema,\n} from \"../index\";\nimport {\n APIGatewayProxyEvent,\n APIGatewayProxyWebsocketEventV2,\n CreateAuthChallengeTriggerEvent,\n DefineAuthChallengeTriggerEvent,\n DynamoDBStreamEvent,\n PostConfirmationTriggerEvent,\n PreSignUpTriggerEvent,\n ScheduledEvent,\n SQSEvent,\n VerifyAuthChallengeResponseTriggerEvent,\n} from \"aws-lambda\";\nimport { errorHandlerHttp, ErrorHttp } from \"../exception\";\nimport { EntityConfig } from \"@chinggis/types\";\nimport { normalizeLower, toArray, trimSpecialChar } from \"../utils/string.util\";\n\n/**\n * @deprecated Use `ControllerApi, ControllerSocket, ControllerStream` instead.\n */\nexport abstract class BaseController<T extends BaseService<any, any>> {\n protected resourcePath: string;\n protected userId: string;\n protected isAdmin: boolean;\n protected request: HttpRequest;\n protected readonly service: T;\n protected adminGroupNames: string[];\n protected requestBody: any;\n protected triggerEvent: any;\n protected eventAttr: any;\n protected event: APIGatewayProxyEvent;\n protected resource: string;\n protected entityId: string;\n protected methode: HttpMethod;\n protected groups: string[] = [];\n protected username: string;\n protected profileId: string;\n protected requestType: RequestType;\n protected config: EntityConfig;\n protected path: string;\n\n protected constructor(baseService: T, config: EntityConfig) {\n this.service = baseService;\n\n // Store config for use in subclasses\n if (!config) return;\n\n this.config = config;\n // Set adminGroupName from config if available\n if (config.ADMIN_GROUP_NAME) {\n this.adminGroupNames = config.ADMIN_GROUP_NAME;\n }\n\n this.service.setConfig(config);\n }\n\n async resolveCrudRequest(event: APIGatewayProxyEvent): Promise<APIResponse> {\n try {\n this.bootstrapRequest(event);\n\n const policy: EndpointPolicy | undefined = findMatchedPolicy(\n this.methode,\n this.path,\n this.config.ENDPOINT_POLICY,\n );\n\n this.checkPermission(policy?.access);\n this.validateRequest(policy?.validator);\n this.setUserFilter();\n\n const response: any = await this.handleCrudByMethod(event);\n\n if (!policy?.response) {\n return createApiResponse(200, response);\n }\n\n const filteredResponse = this.filterResponse(response, policy.response);\n\n return createApiResponse(200, filteredResponse);\n } catch (err) {\n const error = errorHandlerHttp(err);\n log.error(error);\n return createApiResponse(error.statusCode, error.content);\n }\n }\n\n async resolveSQSEvent(sqsEvent: SQSEvent): Promise<void> {\n try {\n await this.processSQSEvent(sqsEvent);\n } catch (error) {\n console.error(\"Error handling SQS event:\", error);\n }\n }\n\n async resolveStreamEvent(event: DynamoDBStreamEvent): Promise<void> {\n try {\n for (const record of event.Records) {\n const oldItem = parseImage(record.dynamodb.OldImage) as T;\n const newItem = parseImage(record.dynamodb.NewImage) as T;\n\n await this.service.processChanges(\n oldItem,\n newItem,\n parseEventToAction(record.eventName),\n getTableName(record.eventSourceARN),\n );\n }\n await this.processStreamEvent(event);\n } catch (error) {\n console.error(\"Error handling request event:\", error);\n }\n }\n\n async resolveScheduledEvent(event: ScheduledEvent): Promise<void> {\n try {\n await this.processScheduledEvent(event);\n } catch (error) {\n console.error(\"Error handling request event:\", error);\n }\n }\n\n async resolveWebSocketEvent(event: APIGatewayProxyWebsocketEventV2): Promise<void> {\n try {\n return await this.processWebSocketEvent(event);\n } catch (error) {\n console.error(\"Error handling request event:\", error);\n }\n }\n\n async resolveTriggerEvent(\n event:\n | CreateAuthChallengeTriggerEvent\n | DefineAuthChallengeTriggerEvent\n | VerifyAuthChallengeResponseTriggerEvent\n | PostConfirmationTriggerEvent\n | PreSignUpTriggerEvent,\n ): Promise<void> {\n try {\n this.triggerEvent = event;\n this.eventAttr = this.triggerEvent.userAttributes;\n return await this.processTriggerEvent(event);\n } catch (error) {\n console.error(\"Error handling request event:\", error);\n }\n }\n\n setConfig(config: EntityConfig): void {\n this.config = config;\n }\n\n protected async handleList(): Promise<any> {\n if (this.methode === \"GET\" && trimSpecialChar(this.path) === trimSpecialChar(this.config.BASE_PATH)) {\n return await this.service.find(this.request.filterAndSort || {});\n }\n\n if (this.methode === \"GET\" && trimSpecialChar(this.path) === trimSpecialChar(this.config.BASE_PATH) + \"/search\") {\n return await this.service.search(this.request.filterAndSort || {});\n }\n\n if (this.methode === \"GET\" && trimSpecialChar(this.path) === trimSpecialChar(this.config.BASE_PATH) + \"/scan\") {\n return await this.service.scan(this.request.filterAndSort || {});\n }\n }\n\n protected async handleUpdate(): Promise<any> {\n if (!this.entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot PATCH resource without id field\");\n\n const entity = this.parseEntity();\n\n if (Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"No fields to update\");\n }\n\n // id change is forbidden\n if (\"id\" in entity) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot modify the id field\");\n }\n\n entity.id = this.entityId;\n return this.service.update(entity, this.profileId);\n }\n\n protected async handleDelete(): Promise<boolean> {\n if (!this.entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot delete resource without id field\");\n\n return this.service.remove(this.entityId, this.profileId);\n }\n\n protected async handleFetch(): Promise<any> {\n if (!this.entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot fetch resource without id field\");\n\n const result = await this.service.findById(this.entityId, this.profileId);\n\n if (result) return result;\n\n throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `Resource with ID ${this.entityId} not found`);\n }\n\n protected async handleReplace() {\n if (!this.entityId) throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot PUT resource without id field\");\n\n const entity = this.parseEntity();\n\n if (!Object.keys(entity).length) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"No entity provided for PUT update\");\n }\n\n if (!this.entityId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"Cannot PUT resource without id field\");\n }\n\n entity.id = this.entityId;\n\n return this.service.update(entity, this.profileId);\n }\n\n protected async handlePostCreate() {\n const entity = this.parseEntity();\n if (!Object.keys(entity).length) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"No entity payload provided\");\n }\n\n if (!this.isAdmin) entity.profileId = this.profileId;\n else if (!entity.profileId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"No profileId provided\");\n }\n\n return await this.service.save(entity, this.profileId);\n }\n\n protected abstract processCrudRequest(event: APIGatewayProxyEvent): Promise<any>;\n\n /**\n * service дээр processChanges methode ажилсны дараа хийгдэх үйлдлүүд байна\n * @param event - DynamoDBStreamEvent\n * @returns Promise<void>\n * */\n protected abstract processStreamEvent(event: DynamoDBStreamEvent): Promise<void>;\n\n protected abstract processScheduledEvent(event: ScheduledEvent): Promise<void>;\n\n protected abstract processWebSocketEvent(event: APIGatewayProxyWebsocketEventV2): Promise<void>;\n\n protected processTriggerEvent?(\n event:\n | CreateAuthChallengeTriggerEvent\n | DefineAuthChallengeTriggerEvent\n | VerifyAuthChallengeResponseTriggerEvent\n | PostConfirmationTriggerEvent\n | PreSignUpTriggerEvent,\n ): Promise<void> {\n throw new Error(`Method not implemented. event: ${JSON.stringify(event, null, 2)}`);\n }\n\n protected abstract processSQSEvent(sqsEvent: SQSEvent): Promise<any>;\n\n protected isListRequest(): boolean {\n const basePath = trimSpecialChar(this.config.BASE_PATH);\n\n const allowedPaths = [basePath, `${basePath}/search`, `${basePath}/scan`];\n\n const isMethodGet = this.methode === \"GET\";\n const isAllowedPath = allowedPaths.includes(trimSpecialChar(this.path));\n\n return isMethodGet && isAllowedPath;\n }\n\n protected isUpdateRequest(): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodPatch = this.methode === \"PATCH\";\n const isExpectedPath = trimSpecialChar(this.path) === expectedPath;\n\n return isMethodPatch && isExpectedPath;\n }\n\n protected isDeleteRequest(): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodDelete = this.methode === \"DELETE\";\n const isExpectedPath = trimSpecialChar(this.path) === expectedPath;\n\n return isMethodDelete && isExpectedPath;\n }\n\n protected isFetchRequest(): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = this.methode === \"GET\";\n const isExpectedPath = trimSpecialChar(this.path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n private async handleCrudByMethod(event: APIGatewayProxyEvent): Promise<any> {\n if (this.isUpdateRequest()) return this.handleUpdate();\n if (this.isDeleteRequest()) return this.handleDelete();\n if (this.isFetchRequest()) return this.handleFetch();\n if (this.methode === \"PUT\") return this.handleReplace();\n if (this.methode === \"POST\") return this.handlePostCreate();\n if (this.isListRequest()) return this.handleList();\n return this.processCrudRequest(event); // Custom Endpoints\n }\n\n private filterResponse(response: any, responsePolicy: ResponseFields): any {\n if (Array.isArray(response)) {\n return removeFields(response, responsePolicy.include, responsePolicy.exclude);\n }\n\n if (response?.items && Array.isArray(response.items)) {\n response.items = removeFields(response.items, responsePolicy.include, responsePolicy.exclude);\n return response;\n }\n\n return removeFields([response], responsePolicy.include, responsePolicy.exclude)[0];\n }\n\n /**\n * Map RequestType to Access for permission checking\n */\n private getUserAccessLevel(): Access {\n switch (this.requestType) {\n case RequestType.ADMIN:\n return Access.ADMIN;\n case RequestType.USER:\n return Access.USER;\n case RequestType.GUEST:\n return Access.PUBLIC;\n case RequestType.SYSTEM:\n return Access.SYSTEM;\n default:\n return Access.PUBLIC;\n }\n }\n\n /** Check if the user has permission for the current operation */\n private checkPermission(allowedAccess: Access[]) {\n const currentAccessLevel = this.getUserAccessLevel();\n\n // This means USER can access OWNER-level permissions, but the service will verify actual ownership\n const hasPermission =\n allowedAccess.includes(currentAccessLevel) ||\n (this.requestType === RequestType.USER && allowedAccess.includes(Access.OWNER));\n\n if (hasPermission) return;\n\n throw new ErrorHttp(\n { code: 403, error: \"PermissionDenied\" },\n `Access denied. Required: ${allowedAccess.join(\", \")}, Current: ${currentAccessLevel}`,\n );\n }\n\n private setUserFilter() {\n if (this.isAdmin && !this.profileId) return;\n const ownerIdFieldName = this.config.OWNER_ID_FIELD_NAME || \"ownerId\";\n this.request.filterAndSort[ownerIdFieldName] = this.profileId;\n }\n\n private bootstrapRequest(event: APIGatewayProxyEvent) {\n log.info(\"event: \" + JSON.stringify(event, null, 2));\n\n this.event = event;\n this.resource = event.resource || undefined;\n\n this.methode = event.httpMethod as HttpMethod;\n this.path = event?.requestContext?.resourcePath;\n this.resourcePath = `${this.methode} ${this.path}`;\n\n this.request = parseHttpRequest(event);\n this.requestBody = this.request.body;\n this.entityId = event.pathParameters?.id || undefined;\n\n this.parseEnvData();\n this.parserUserData(event.requestContext?.authorizer?.claims);\n }\n\n private parseEntity(): Record<string, unknown> {\n if (!this.requestBody) return {};\n return typeof this.requestBody === \"string\" ? JSON.parse(this.requestBody) : this.requestBody;\n }\n\n private validateRequest(schema: any) {\n if (!schema) return;\n\n try {\n validateWithSchema(schema, this.requestBody);\n } catch (error) {\n const formattedErrors = formatErrors(error);\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, formattedErrors);\n }\n }\n\n private parserUserData(claims: any) {\n if (this.profileId) return;\n\n // request user data\n this.groups = toArray(claims?.[\"cognito:groups\"]);\n this.username = claims?.[\"cognito:username\"] || \"\";\n this.userId = claims?.sub || \"\";\n this.profileId = claims?.[\"custom:profileId\"] || this.username;\n\n const adminGroups = new Set(normalizeLower(toArray(this.adminGroupNames)));\n const groups = normalizeLower(toArray(this.groups));\n this.isAdmin = groups.some((g) => adminGroups.has(g));\n\n if (this.isAdmin) {\n this.profileId = this.request.body?.ownerId || \"\";\n delete this.request.body?.ownerId;\n this.requestType = RequestType.ADMIN;\n } else if (this.profileId || this.userId) this.requestType = RequestType.USER;\n else this.requestType = RequestType.GUEST;\n\n log.info(\"groups: \" + JSON.stringify(this.groups, null, 2));\n log.info(`claims:${JSON.stringify(claims, null, 2)}`);\n log.info(\n `groups:${this.groups}, isAdmin:${this.isAdmin}, userId:${this.userId}, profileId:${this.profileId}, username:${this.username}, requestType:${this.requestType}`,\n );\n }\n\n /** DEV **/\n private parseEnvData() {\n if (process.env.ENV?.toLowerCase()?.trim() !== \"dev\") return;\n\n log.debug(\"dev mode detected. Use custom header to initialize user data\");\n\n const headers = this.request.headers;\n\n this.profileId = \"\";\n if (this.requestBody?.ownerId) {\n this.profileId = this.requestBody.ownerId;\n delete this.requestBody.ownerId;\n }\n this.groups = toArray(headers[\"groups\"]);\n this.username = headers[\"username\"] || \"\";\n this.userId = headers[\"userId\"] || \"\";\n const requestTypeStr = headers[\"requestType\"]?.toUpperCase() || \"\";\n if (requestTypeStr) {\n switch (requestTypeStr) {\n case \"ADMIN\":\n this.requestType = RequestType.ADMIN;\n break;\n case \"USER\":\n this.requestType = RequestType.USER;\n break;\n case \"GUEST\":\n this.requestType = RequestType.GUEST;\n break;\n case \"SYSTEM\":\n this.requestType = RequestType.SYSTEM;\n break;\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ActionDynamoDB } from "../index";
|
|
2
|
+
import { DynamoDBStreamEvent } from "aws-lambda";
|
|
3
|
+
import { EntityConfig } from "../model/index.js";
|
|
4
|
+
import { StreamService } from "../service/stream.service.interface";
|
|
5
|
+
export declare abstract class ControllerStream<T extends StreamService<any>> {
|
|
6
|
+
protected readonly service: T;
|
|
7
|
+
protected config: EntityConfig;
|
|
8
|
+
protected constructor(baseService: T, config: EntityConfig);
|
|
9
|
+
resolveStreamEvent(event: DynamoDBStreamEvent): Promise<void>;
|
|
10
|
+
abstract processStreamEventPre(oldItem: T, newItem: T, event: ActionDynamoDB, tableName: string): Promise<{
|
|
11
|
+
oldItem: T;
|
|
12
|
+
newItem: T;
|
|
13
|
+
}>;
|
|
14
|
+
abstract processStreamEventPost(oldItem: T, newItem: T, event: ActionDynamoDB, tableName: string): Promise<void>;
|
|
15
|
+
private processEventRecord;
|
|
16
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ControllerStream = void 0;
|
|
13
|
+
const index_1 = require("../index");
|
|
14
|
+
class ControllerStream {
|
|
15
|
+
constructor(baseService, config) {
|
|
16
|
+
this.service = baseService;
|
|
17
|
+
// Store config for use in subclasses
|
|
18
|
+
if (!config)
|
|
19
|
+
return;
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.service.setConfig(config);
|
|
22
|
+
}
|
|
23
|
+
resolveStreamEvent(event) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
for (const record of event.Records) {
|
|
26
|
+
try {
|
|
27
|
+
yield this.processEventRecord(record);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
log.error("[CORE] Error handling request event:", error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
processEventRecord(record) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const oldItem = (0, index_1.parseImage)(record.dynamodb.OldImage);
|
|
38
|
+
const newItem = (0, index_1.parseImage)(record.dynamodb.NewImage);
|
|
39
|
+
const event = (0, index_1.parseEventToAction)(record.eventName);
|
|
40
|
+
const tableName = (0, index_1.getTableName)(record.eventSourceARN);
|
|
41
|
+
yield this.processStreamEventPre(oldItem, newItem, event, tableName);
|
|
42
|
+
if (event === index_1.ActionDynamoDB.INSERT) {
|
|
43
|
+
yield this.service.processInsertion(newItem, tableName);
|
|
44
|
+
}
|
|
45
|
+
else if (event === index_1.ActionDynamoDB.MODIFY) {
|
|
46
|
+
yield this.service.processModification(oldItem, newItem, tableName);
|
|
47
|
+
}
|
|
48
|
+
else if (event === index_1.ActionDynamoDB.REMOVE) {
|
|
49
|
+
yield this.service.processDeletion(oldItem, newItem, tableName);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error(`[CORE] Unsupported event type: ${event}`);
|
|
53
|
+
}
|
|
54
|
+
yield this.processStreamEventPost(oldItem, newItem, event, tableName);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.ControllerStream = ControllerStream;
|
|
59
|
+
//# sourceMappingURL=controller-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller-stream.js","sourceRoot":"","sources":["../../src/controller/controller-stream.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAwF;AAKxF,MAAsB,gBAAgB;IAKpC,YAAsB,WAAc,EAAE,MAAoB;QACxD,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAE3B,qCAAqC;QACrC,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAEK,kBAAkB,CAAC,KAA0B;;YACjD,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;gBACnC,IAAI,CAAC;oBACH,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;gBACxC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,GAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAA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, parseImage } from \"../index\";\nimport { DynamoDBRecord, DynamoDBStreamEvent } from \"aws-lambda\";\nimport { EntityConfig } from \"@chinggis/types\";\nimport { StreamService } from \"../service/stream.service.interface\";\n\nexport abstract class ControllerStream<T extends StreamService<any>> {\n protected readonly service: T;\n\n protected config: EntityConfig;\n\n protected constructor(baseService: T, config: EntityConfig) {\n this.service = baseService;\n\n // Store config for use in subclasses\n if (!config) return;\n\n this.config = config;\n\n this.service.setConfig(config);\n }\n\n async resolveStreamEvent(event: DynamoDBStreamEvent): Promise<void> {\n for (const record of event.Records) {\n try {\n await this.processEventRecord(record);\n } catch (error) {\n log.error(\"[CORE] Error handling request event:\", error);\n }\n }\n }\n\n abstract processStreamEventPre(\n oldItem: T,\n newItem: T,\n event: ActionDynamoDB,\n tableName: string,\n ): Promise<{ oldItem: T; newItem: T }>;\n\n abstract processStreamEventPost(oldItem: T, newItem: T, event: ActionDynamoDB, tableName: string): Promise<void>;\n\n private async processEventRecord(record: DynamoDBRecord): Promise<any> {\n const oldItem = parseImage(record.dynamodb.OldImage) as T;\n const newItem = parseImage(record.dynamodb.NewImage) as T;\n const event = parseEventToAction(record.eventName);\n const tableName = getTableName(record.eventSourceARN);\n\n await this.processStreamEventPre(oldItem, newItem, event, tableName);\n\n if (event === ActionDynamoDB.INSERT) {\n await this.service.processInsertion(newItem, tableName);\n } else if (event === ActionDynamoDB.MODIFY) {\n await this.service.processModification(oldItem, newItem, tableName);\n } else if (event === ActionDynamoDB.REMOVE) {\n await this.service.processDeletion(oldItem, newItem, tableName);\n } else {\n throw new Error(`[CORE] Unsupported event type: ${event}`);\n }\n\n await this.processStreamEventPost(oldItem, newItem, event, tableName);\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseEntity, BaseRepoDB, BaseRepoES, DynamoIndexMap } from "../index";
|
|
2
|
+
import { EntityConfig } from "../model/index.js";
|
|
3
|
+
import { StreamService } from "./stream.service.interface";
|
|
4
|
+
import "./stream.service";
|
|
5
|
+
export declare abstract class StreamServiceImpl<T extends BaseEntity, D extends BaseRepoDB<T>, S extends BaseRepoES<T>> implements StreamService<T> {
|
|
6
|
+
protected repoDB: D;
|
|
7
|
+
protected repoES: S;
|
|
8
|
+
protected config: EntityConfig;
|
|
9
|
+
protected constructor(repoDB: D, repoES: S);
|
|
10
|
+
getTableName(): string;
|
|
11
|
+
setTable(tableName: string, dynamoIndexMap: DynamoIndexMap): boolean;
|
|
12
|
+
getIndexMapDB(): DynamoIndexMap;
|
|
13
|
+
setConfig(config: EntityConfig): void;
|
|
14
|
+
abstract processModification(itemOld: T, itemNew: T, tableName: string): Promise<any>;
|
|
15
|
+
abstract processDeletion(oldItem: T, newItem: T, tableName?: string): Promise<any>;
|
|
16
|
+
abstract processInsertion(newItem: T, tableName: string): Promise<any>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseEntity, DynamoIndexMap } from "../index";
|
|
2
|
+
import { EntityConfig } from "../model/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Defines a generic base service interface for working with entities in both
|
|
5
|
+
* DynamoDB and OpenSearch.
|
|
6
|
+
*/
|
|
7
|
+
export interface StreamService<T extends BaseEntity> {
|
|
8
|
+
setConfig(config: EntityConfig): void;
|
|
9
|
+
getTableName(): string;
|
|
10
|
+
setTable(tableName: string, dynamoIndexMap: DynamoIndexMap): boolean;
|
|
11
|
+
processDeletion(oldItem: T, newItem: T, tableName?: string): Promise<any>;
|
|
12
|
+
processInsertion(newItem: T, tableName: string): Promise<any>;
|
|
13
|
+
processModification(itemOld: T, itemNew: T, tableName?: string): Promise<any>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.service.interface.js","sourceRoot":"","sources":["../../src/service/stream.service.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseEntity, DynamoIndexMap } from \"../index\";\nimport { EntityConfig } from \"@chinggis/types\";\n\n/**\n * Defines a generic base service interface for working with entities in both\n * DynamoDB and OpenSearch.\n */\nexport interface StreamService<T extends BaseEntity> {\n setConfig(config: EntityConfig): void;\n\n getTableName(): string;\n\n setTable(tableName: string, dynamoIndexMap: DynamoIndexMap): boolean;\n\n processDeletion(oldItem: T, newItem: T, tableName?: string): Promise<any>;\n\n processInsertion(newItem: T, tableName: string): Promise<any>;\n\n processModification(itemOld: T, itemNew: T, tableName?: string): Promise<any>;\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.StreamServiceImpl = void 0;
|
|
37
|
+
const index_1 = require("../index");
|
|
38
|
+
require("./stream.service");
|
|
39
|
+
const console = __importStar(require("node:console"));
|
|
40
|
+
class StreamServiceImpl {
|
|
41
|
+
constructor(repoDB, repoES) {
|
|
42
|
+
if (repoDB != null && !(repoDB instanceof index_1.BaseRepoDBImpl))
|
|
43
|
+
console.error("[CORE] repoDB is not an instance of BaseRepoDBImpl");
|
|
44
|
+
if (repoES != null && !(repoES instanceof index_1.BaseRepoESImpl))
|
|
45
|
+
console.error("[CORE] repoES is not an instance of BaseRepoESImpl");
|
|
46
|
+
if (repoDB == null && repoES == null)
|
|
47
|
+
console.error("[CORE] repo initialization is required");
|
|
48
|
+
this.repoDB = repoDB;
|
|
49
|
+
this.repoES = repoES;
|
|
50
|
+
}
|
|
51
|
+
getTableName() {
|
|
52
|
+
return this.repoDB.getTableName();
|
|
53
|
+
}
|
|
54
|
+
setTable(tableName, dynamoIndexMap) {
|
|
55
|
+
this.repoDB.setTable(tableName);
|
|
56
|
+
this.repoDB.setIndexMap(dynamoIndexMap);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
getIndexMapDB() {
|
|
60
|
+
return this.repoDB.getIndexMap();
|
|
61
|
+
}
|
|
62
|
+
setConfig(config) {
|
|
63
|
+
this.config = config;
|
|
64
|
+
this.setTable(config.DYNAMO_DB.NAME, config.DYNAMO_DB.MAP);
|
|
65
|
+
if (this.repoDB) {
|
|
66
|
+
this.repoDB.setIndexMap(config.DYNAMO_DB.MAP);
|
|
67
|
+
this.repoDB.setTable(config.DYNAMO_DB.NAME);
|
|
68
|
+
}
|
|
69
|
+
if (this.repoES) {
|
|
70
|
+
this.repoES.setEndpoint(config.OPEN_SEARCH.DOMAIN);
|
|
71
|
+
this.repoES.setIndexName(config.OPEN_SEARCH.INDEX);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.StreamServiceImpl = StreamServiceImpl;
|
|
76
|
+
//# sourceMappingURL=stream.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.service.js","sourceRoot":"","sources":["../../src/service/stream.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAA8G;AAI9G,4BAA0B;AAC1B,sDAAwC;AAExC,MAAsB,iBAAiB;IAOrC,YAAsB,MAAS,EAAE,MAAS;QACxC,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,YAAY,sBAAc,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAEtE,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,YAAY,sBAAc,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAEtE,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI;YAAE,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAE9F,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IACpC,CAAC;IAED,QAAQ,CAAC,SAAiB,EAAE,cAA8B;QACxD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IAED,SAAS,CAAC,MAAoB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAE3D,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACnD,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;CAMF;AAtDD,8CAsDC","sourcesContent":["import { BaseEntity, BaseRepoDB, BaseRepoDBImpl, BaseRepoES, BaseRepoESImpl, DynamoIndexMap } from \"../index\";\n\nimport { EntityConfig } from \"@chinggis/types\";\nimport { StreamService } from \"./stream.service.interface\";\nimport \"./stream.service\";\nimport * as console from \"node:console\";\n\nexport abstract class StreamServiceImpl<T extends BaseEntity, D extends BaseRepoDB<T>, S extends BaseRepoES<T>>\n implements StreamService<T>\n{\n protected repoDB: D;\n protected repoES: S;\n protected config: EntityConfig;\n\n protected constructor(repoDB: D, repoES: S) {\n if (repoDB != null && !(repoDB instanceof BaseRepoDBImpl))\n console.error(\"[CORE] repoDB is not an instance of BaseRepoDBImpl\");\n\n if (repoES != null && !(repoES instanceof BaseRepoESImpl))\n console.error(\"[CORE] repoES is not an instance of BaseRepoESImpl\");\n\n if (repoDB == null && repoES == null) console.error(\"[CORE] repo initialization is required\");\n\n this.repoDB = repoDB;\n this.repoES = repoES;\n }\n\n getTableName(): string {\n return this.repoDB.getTableName();\n }\n\n setTable(tableName: string, dynamoIndexMap: DynamoIndexMap): boolean {\n this.repoDB.setTable(tableName);\n this.repoDB.setIndexMap(dynamoIndexMap);\n return true;\n }\n\n getIndexMapDB(): DynamoIndexMap {\n return this.repoDB.getIndexMap();\n }\n\n setConfig(config: EntityConfig) {\n this.config = config;\n\n this.setTable(config.DYNAMO_DB.NAME, config.DYNAMO_DB.MAP);\n\n if (this.repoDB) {\n this.repoDB.setIndexMap(config.DYNAMO_DB.MAP);\n this.repoDB.setTable(config.DYNAMO_DB.NAME);\n }\n\n if (this.repoES) {\n this.repoES.setEndpoint(config.OPEN_SEARCH.DOMAIN);\n this.repoES.setIndexName(config.OPEN_SEARCH.INDEX);\n }\n }\n abstract processModification(itemOld: T, itemNew: T, tableName: string): Promise<any>;\n\n abstract processDeletion(oldItem: T, newItem: T, tableName?: string): Promise<any>;\n\n abstract processInsertion(newItem: T, tableName: string): Promise<any>;\n}\n"]}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
export declare const readFileLinesAsList: (filePath: string) => Promise<string[]>;
|
|
2
2
|
export declare const writeFileLines: (filePath: string, lines: string[]) => void;
|
|
3
|
-
export declare const createFile: <T>(filePath: string, content: Iterable<T>) => void;
|
|
4
3
|
export declare const createTextFile: <T>(filePath: string, content: Iterable<T>) => void;
|
|
5
4
|
export declare const appendNewLineToFile: (filePath: string, items: string[]) => void;
|
|
6
5
|
export declare const createCsvFile: <T>(filePath: string, content: Iterable<T>) => void;
|
|
7
|
-
/**
|
|
8
|
-
* Creates an Excel file from a list of objects
|
|
9
|
-
* @param filePath Path to save the Excel file
|
|
10
|
-
* @param content Iterable list of objects (generic)
|
|
11
|
-
*/
|
|
12
|
-
export declare const createExcelFile: <T>(filePath: string, content: Iterable<T>) => void;
|
|
13
6
|
export declare function readJSONFile(fileName: string): object;
|
|
14
7
|
export declare function readExcel(filePath: string): Array<Array<string>>;
|
|
@@ -49,13 +49,12 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
49
49
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
50
50
|
};
|
|
51
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
-
exports.
|
|
52
|
+
exports.createCsvFile = exports.appendNewLineToFile = exports.createTextFile = exports.writeFileLines = exports.readFileLinesAsList = void 0;
|
|
53
53
|
exports.readJSONFile = readJSONFile;
|
|
54
54
|
exports.readExcel = readExcel;
|
|
55
55
|
const fs = __importStar(require("fs"));
|
|
56
56
|
const path = __importStar(require("path"));
|
|
57
57
|
const readline = __importStar(require("readline"));
|
|
58
|
-
const XLSX = __importStar(require("xlsx"));
|
|
59
58
|
// Function to read a file and return its lines as a list
|
|
60
59
|
const readFileLinesAsList = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
60
|
var _a, e_1, _b, _c;
|
|
@@ -97,19 +96,6 @@ const writeFileLines = (filePath, lines) => {
|
|
|
97
96
|
});
|
|
98
97
|
};
|
|
99
98
|
exports.writeFileLines = writeFileLines;
|
|
100
|
-
// General file creation logic
|
|
101
|
-
const createFile = (filePath, content) => {
|
|
102
|
-
if (filePath.endsWith(".xlsx")) {
|
|
103
|
-
(0, exports.createExcelFile)(filePath, content);
|
|
104
|
-
}
|
|
105
|
-
else if (filePath.endsWith(".csv")) {
|
|
106
|
-
(0, exports.createCsvFile)(filePath, content);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
(0, exports.createTextFile)(filePath, content);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
exports.createFile = createFile;
|
|
113
99
|
// Function to create a text file
|
|
114
100
|
const createTextFile = (filePath, content) => {
|
|
115
101
|
try {
|
|
@@ -149,62 +135,6 @@ const createCsvFile = (filePath, content) => {
|
|
|
149
135
|
console.log(`CSV file has been created at ${filePath}`);
|
|
150
136
|
};
|
|
151
137
|
exports.createCsvFile = createCsvFile;
|
|
152
|
-
/**
|
|
153
|
-
* Creates an Excel file from a list of objects
|
|
154
|
-
* @param filePath Path to save the Excel file
|
|
155
|
-
* @param content Iterable list of objects (generic)
|
|
156
|
-
*/
|
|
157
|
-
const createExcelFile = (filePath, content) => {
|
|
158
|
-
try {
|
|
159
|
-
const data = Array.from(content).map((item) => {
|
|
160
|
-
return Object.fromEntries(Object.entries(item).map(([key, value]) => [
|
|
161
|
-
key,
|
|
162
|
-
Array.isArray(value) ? value.join(", ") : (value !== null && value !== void 0 ? value : ""),
|
|
163
|
-
]));
|
|
164
|
-
});
|
|
165
|
-
if (data.length === 0) {
|
|
166
|
-
console.log("No data to write");
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
const absolutePath = path.resolve(filePath);
|
|
170
|
-
let workbook;
|
|
171
|
-
let worksheet;
|
|
172
|
-
if (fs.existsSync(absolutePath)) {
|
|
173
|
-
// Read the existing workbook
|
|
174
|
-
const fileContents = fs.readFileSync(absolutePath);
|
|
175
|
-
workbook = XLSX.read(fileContents, { type: "buffer" });
|
|
176
|
-
// Get the existing sheet data
|
|
177
|
-
if (workbook.Sheets["Sheet1"]) {
|
|
178
|
-
const existingData = XLSX.utils.sheet_to_json(workbook.Sheets["Sheet1"]);
|
|
179
|
-
// Merge existing data with new data
|
|
180
|
-
const updatedData = existingData.concat(data);
|
|
181
|
-
// Remove the old sheet
|
|
182
|
-
delete workbook.Sheets["Sheet1"];
|
|
183
|
-
workbook.SheetNames = workbook.SheetNames.filter((name) => name !== "Sheet1");
|
|
184
|
-
// Create a new sheet with updated data
|
|
185
|
-
worksheet = XLSX.utils.json_to_sheet(updatedData);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
// If the sheet doesn't exist, just create a new one
|
|
189
|
-
worksheet = XLSX.utils.json_to_sheet(data);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
// Create a new workbook and sheet
|
|
194
|
-
workbook = XLSX.utils.book_new();
|
|
195
|
-
worksheet = XLSX.utils.json_to_sheet(data);
|
|
196
|
-
}
|
|
197
|
-
// Add the new/updated worksheet
|
|
198
|
-
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
|
|
199
|
-
// Write the updated workbook to file
|
|
200
|
-
XLSX.writeFile(workbook, absolutePath);
|
|
201
|
-
console.log(`Excel file successfully created/updated at: ${absolutePath}`);
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
console.error(`Error creating/updating Excel file at ${filePath}:`, error);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
exports.createExcelFile = createExcelFile;
|
|
208
138
|
function readJSONFile(fileName) {
|
|
209
139
|
const filePath = path.join(__dirname, fileName); // Kombiniere __dirname mit Dateinamen
|
|
210
140
|
const fileContent = fs.readFileSync(filePath, "utf-8"); // Lese Datei synchron
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-handler.js","sourceRoot":"","sources":["../../src/utils/file-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,oCAIC;AAED,8BAEC;AAlKD,uCAAyB;AACzB,2CAA6B;AAC7B,mDAAqC;AACrC,2CAA6B;AAE7B,yDAAyD;AAClD,MAAM,mBAAmB,GAAG,CAAO,QAAgB,EAAqB,EAAE;;IAC/E,MAAM,KAAK,GAAa,EAAE,CAAC,CAAC,sBAAsB;IAElD,8BAA8B;IAC9B,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;QAClC,KAAK,EAAE,UAAU;QACjB,SAAS,EAAE,QAAQ,EAAE,uCAAuC;KAC7D,CAAC,CAAC;;QAEH,oBAAoB;QACpB,KAAyB,eAAA,OAAA,cAAA,EAAE,CA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AE,SAAS,EAAE,QAAQ,CAAC,CAAC;QAE5D,qCAAqC;QACrC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAEvC,OAAO,CAAC,GAAG,CAAC,+CAA+C,YAAY,EAAE,CAAC,CAAC;IAC7E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,yCAAyC,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC,CAAC;AA1DW,QAAA,eAAe,mBA0D1B;AAEF,SAAgB,YAAY,CAAC,QAAgB;IAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,sCAAsC;IACvF,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,sBAAsB;IAC9E,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,oBAAoB;AACtD,CAAC;AAED,SAAgB,SAAS,CAAC,QAAgB;IACxC,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import * as fs from \"fs\";\nimport * as path from \"path\";\nimport * as readline from \"readline\";\nimport * as XLSX from \"xlsx\";\n\n// Function to read a file and return its lines as a list\nexport const readFileLinesAsList = async (filePath: string): Promise<string[]> => {\n const lines: string[] = []; // List to store lines\n\n // Create a Readline interface\n const fileStream = fs.createReadStream(filePath);\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity, // Handles different line-ending styles\n });\n\n // Process each line\n for await (const line of rl) {\n lines.push(line); // Add the current line to the list\n }\n\n return lines;\n};\n\n// Function to write lines to a file\nexport const writeFileLines = (filePath: string, lines: string[]): void => {\n fs.writeFile(filePath, lines.join(\"\\n\"), \"utf8\", (err) => {\n if (err) {\n console.error(\"Error writing to the file:\", err);\n } else {\n console.log(`Successfully written: ${lines.length} lines to ${filePath}`);\n }\n });\n};\n\n// General file creation logic\nexport const createFile = <T>(filePath: string, content: Iterable<T>): void => {\n if (filePath.endsWith(\".xlsx\")) {\n createExcelFile(filePath, content);\n } else if (filePath.endsWith(\".csv\")) {\n createCsvFile(filePath, content);\n } else {\n createTextFile(filePath, content);\n }\n};\n\n// Function to create a text file\nexport const createTextFile = <T>(filePath: string, content: Iterable<T>): void => {\n try {\n // Resolve the absolute path\n const absolutePath = path.resolve(filePath);\n\n // Convert Set to Array if necessary, then join elements with a newline\n const data = Array.isArray(content) ? content.join(\"\\n\") : Array.from(content).join(\"\\n\");\n\n // Write data to the resolved absolute path\n fs.writeFileSync(absolutePath, data, \"utf-8\");\n\n console.log(`Text file successfully created at: ${absolutePath}`);\n } catch (error) {\n console.error(`Error writing to file at ${filePath}:`, error);\n }\n};\n\n// Function to append a new line to a file\nexport const appendNewLineToFile = (filePath: string, items: string[]): void => {\n fs.appendFile(filePath, `${items.toString()}\\n`, \"utf8\", (err) => {\n if (err) {\n console.error(\"Error appending to the file:\", err);\n } else {\n console.log(`Successfully appended: ${items.length} items to ${filePath}`);\n }\n });\n};\n\nexport const createCsvFile = <T>(filePath: string, content: Iterable<T>): void => {\n const data = Array.from(content); // Convert Iterable to Array\n if (data.length === 0) {\n console.log(\"No data to write\");\n return;\n }\n\n const csvContent = data.join(\"\\n\");\n\n fs.writeFileSync(filePath, csvContent, \"utf8\");\n console.log(`CSV file has been created at ${filePath}`);\n};\n\n/**\n * Creates an Excel file from a list of objects\n * @param filePath Path to save the Excel file\n * @param content Iterable list of objects (generic)\n */\n\nexport const createExcelFile = <T>(filePath: string, content: Iterable<T>): void => {\n try {\n const data = Array.from(content).map((item) => {\n return Object.fromEntries(\n Object.entries(item as Record<string, any>).map(([key, value]) => [\n key,\n Array.isArray(value) ? value.join(\", \") : (value ?? \"\"),\n ]),\n );\n });\n\n if (data.length === 0) {\n console.log(\"No data to write\");\n return;\n }\n\n const absolutePath = path.resolve(filePath);\n let workbook;\n let worksheet;\n\n if (fs.existsSync(absolutePath)) {\n // Read the existing workbook\n const fileContents = fs.readFileSync(absolutePath);\n workbook = XLSX.read(fileContents, { type: \"buffer\" });\n\n // Get the existing sheet data\n if (workbook.Sheets[\"Sheet1\"]) {\n const existingData = XLSX.utils.sheet_to_json(workbook.Sheets[\"Sheet1\"]);\n\n // Merge existing data with new data\n const updatedData = existingData.concat(data);\n\n // Remove the old sheet\n delete workbook.Sheets[\"Sheet1\"];\n workbook.SheetNames = workbook.SheetNames.filter((name) => name !== \"Sheet1\");\n\n // Create a new sheet with updated data\n worksheet = XLSX.utils.json_to_sheet(updatedData);\n } else {\n // If the sheet doesn't exist, just create a new one\n worksheet = XLSX.utils.json_to_sheet(data);\n }\n } else {\n // Create a new workbook and sheet\n workbook = XLSX.utils.book_new();\n worksheet = XLSX.utils.json_to_sheet(data);\n }\n\n // Add the new/updated worksheet\n XLSX.utils.book_append_sheet(workbook, worksheet, \"Sheet1\");\n\n // Write the updated workbook to file\n XLSX.writeFile(workbook, absolutePath);\n\n console.log(`Excel file successfully created/updated at: ${absolutePath}`);\n } catch (error) {\n console.error(`Error creating/updating Excel file at ${filePath}:`, error);\n }\n};\n\nexport function readJSONFile(fileName: string): object {\n const filePath = path.join(__dirname, fileName); // Kombiniere __dirname mit Dateinamen\n const fileContent = fs.readFileSync(filePath, \"utf-8\"); // Lese Datei synchron\n return JSON.parse(fileContent); // Parse JSON-Inhalt\n}\n\nexport function readExcel(filePath: string): Array<Array<string>> {\n return [];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"file-handler.js","sourceRoot":"","sources":["../../src/utils/file-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,oCAIC;AAED,8BAEC;AApFD,uCAAyB;AACzB,2CAA6B;AAC7B,mDAAqC;AAErC,yDAAyD;AAClD,MAAM,mBAAmB,GAAG,CAAO,QAAgB,EAAqB,EAAE;;IAC/E,MAAM,KAAK,GAA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,kBAAkB,CAAC,CAAC;QAChC,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEnC,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,gCAAgC,QAAQ,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC;AAXW,QAAA,aAAa,iBAWxB;AAEF,SAAgB,YAAY,CAAC,QAAgB;IAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,sCAAsC;IACvF,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,sBAAsB;IAC9E,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,oBAAoB;AACtD,CAAC;AAED,SAAgB,SAAS,CAAC,QAAgB;IACxC,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import * as fs from \"fs\";\nimport * as path from \"path\";\nimport * as readline from \"readline\";\n\n// Function to read a file and return its lines as a list\nexport const readFileLinesAsList = async (filePath: string): Promise<string[]> => {\n const lines: string[] = []; // List to store lines\n\n // Create a Readline interface\n const fileStream = fs.createReadStream(filePath);\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity, // Handles different line-ending styles\n });\n\n // Process each line\n for await (const line of rl) {\n lines.push(line); // Add the current line to the list\n }\n\n return lines;\n};\n\n// Function to write lines to a file\nexport const writeFileLines = (filePath: string, lines: string[]): void => {\n fs.writeFile(filePath, lines.join(\"\\n\"), \"utf8\", (err) => {\n if (err) {\n console.error(\"Error writing to the file:\", err);\n } else {\n console.log(`Successfully written: ${lines.length} lines to ${filePath}`);\n }\n });\n};\n\n// Function to create a text file\nexport const createTextFile = <T>(filePath: string, content: Iterable<T>): void => {\n try {\n // Resolve the absolute path\n const absolutePath = path.resolve(filePath);\n\n // Convert Set to Array if necessary, then join elements with a newline\n const data = Array.isArray(content) ? content.join(\"\\n\") : Array.from(content).join(\"\\n\");\n\n // Write data to the resolved absolute path\n fs.writeFileSync(absolutePath, data, \"utf-8\");\n\n console.log(`Text file successfully created at: ${absolutePath}`);\n } catch (error) {\n console.error(`Error writing to file at ${filePath}:`, error);\n }\n};\n\n// Function to append a new line to a file\nexport const appendNewLineToFile = (filePath: string, items: string[]): void => {\n fs.appendFile(filePath, `${items.toString()}\\n`, \"utf8\", (err) => {\n if (err) {\n console.error(\"Error appending to the file:\", err);\n } else {\n console.log(`Successfully appended: ${items.length} items to ${filePath}`);\n }\n });\n};\n\nexport const createCsvFile = <T>(filePath: string, content: Iterable<T>): void => {\n const data = Array.from(content); // Convert Iterable to Array\n if (data.length === 0) {\n console.log(\"No data to write\");\n return;\n }\n\n const csvContent = data.join(\"\\n\");\n\n fs.writeFileSync(filePath, csvContent, \"utf8\");\n console.log(`CSV file has been created at ${filePath}`);\n};\n\nexport function readJSONFile(fileName: string): object {\n const filePath = path.join(__dirname, fileName); // Kombiniere __dirname mit Dateinamen\n const fileContent = fs.readFileSync(filePath, \"utf-8\"); // Lese Datei synchron\n return JSON.parse(fileContent); // Parse JSON-Inhalt\n}\n\nexport function readExcel(filePath: string): Array<Array<string>> {\n return [];\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aws-service-stack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.218",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "chinggis.systems",
|
|
@@ -58,7 +58,6 @@
|
|
|
58
58
|
"@aws-sdk/util-dynamodb": "^3.907.0",
|
|
59
59
|
"@opensearch-project/opensearch": "^3.5.1",
|
|
60
60
|
"aws-lambda": "^1.0.7",
|
|
61
|
-
"aws-sdk": "^2.1692.0",
|
|
62
61
|
"axios": "^1.12.2",
|
|
63
62
|
"dayjs": "^1.11.10",
|
|
64
63
|
"elastic-builder": "^3.4.0",
|
|
@@ -89,7 +88,6 @@
|
|
|
89
88
|
"ts-node": "^10.9.2",
|
|
90
89
|
"tsc-alias": "^1.8.11",
|
|
91
90
|
"typescript": "^5.8.3",
|
|
92
|
-
"typescript-transform-paths": "^3.5.3"
|
|
93
|
-
"xlsx": "^0.18.5"
|
|
91
|
+
"typescript-transform-paths": "^3.5.3"
|
|
94
92
|
}
|
|
95
93
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"supplier-controller.js","sourceRoot":"","sources":["../../../../src/_examples/controller/supplier/supplier-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,uDAA0D;AAG1D,mDAAiD;AACjD,uEAAmE;AAG5D,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,8BAA8B;IACpE;QACE,MAAM,OAAO,GAAoB,gBAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAClE,KAAK,CAAC,OAAO,EAAE,iCAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7C,CAAC;IAEe,kBAAkB,CAAC,KAA2B;;YAC5D,GAAG,CAAC,KAAK,CAAC,gCAAgC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YAE5E,IAAI,IAAI,CAAC,YAAY,KAAK,OAAO,sBAAI,qBAAqB,EAAE,CAAC;gBAC3D,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YACxE,CAAC;YACD,IAAI,IAAI,CAAC,YAAY,KAAK,OAAO,sBAAI,WAAW,EAAE,CAAC;gBACjD,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,iCAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;gBACnD,IAAI,CAAC;oBACH,8CAA8C;oBAC9C,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;gBAC/D,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC1C,CAAC;YACH,CAAC;YAED,IAAI,IAAI,CAAC,YAAY,KAAK,OAAO,sBAAI,qBAAqB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBAC3E,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBAC9C,GAAG,CAAC,KAAK,CAAC,qCAAqC,QAAQ,YAAY,KAAK,EAAE,CAAC,CAAC;YAC9E,CAAC;QACH,CAAC;KAAA;CACF,CAAA;AA3BY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,gBAAO,EAAC,oBAAoB,CAAC;;GACjB,kBAAkB,CA2B9B","sourcesContent":["import Container, { Service } from \"typedi\";\n\nimport { APIGatewayProxyEvent } from \"aws-lambda\";\nimport { CONFIG_SUPPLIER, path } from \"./supplier-config\";\n\nimport { SupplierService } from \"../../service/supplier/supplier-service.interface\";\nimport \"../../service/supplier/supplier-service\";\nimport { ControllerApi } from \"../../../controller/controller-api\";\n\n@Service(\"SupplierController\")\nexport class SupplierController extends ControllerApi<SupplierService> {\n constructor() {\n const service: SupplierService = Container.get(\"SupplierService\");\n super(service, CONFIG_SUPPLIER.toObject());\n }\n\n protected async processCrudRequest(event: APIGatewayProxyEvent): Promise<any> {\n log.debug(`_example processCrudRequest: ${JSON.stringify(event, null, 2)}`);\n\n if (this.resourcePath === `GET ${path}/list-non-level-one`) {\n return await this.service.ListNonLevelOne(this.request.filterAndSort);\n }\n if (this.resourcePath === `GET ${path}/find-all`) {\n this.service.setConfig(CONFIG_SUPPLIER.toObject());\n try {\n // return await this.service.findAll();\n return await this.service.search(this.request.filterAndSort);\n } catch (err) {\n log.error(JSON.stringify(err, null, 2));\n }\n }\n\n if (this.resourcePath === `PUT ${path}/convert-to-cognito` && this.isAdmin) {\n const { username, email } = this.request.body;\n log.debug(`_example convert to cognito user: ${username}, email: ${email}`);\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"supplier-service.interface.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseService, Filter, List } from \"@chinggis/core\";\nimport { SAccount } from \"../../model-shared/suppler.model\";\n\nexport interface SupplierService extends BaseService<SAccount> {\n ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>>;\n\n convertToCognitoUser(username: string, email: string): Promise<void>;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"supplier-service.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAK5C,wDAAsD;AAGtD,wDAAsD;AACtD,yCAAgG;AAEhG,4EAA4D;AAC5D,+EAAgF;AAGzE,IAAM,mBAAmB,GAAzB,MAAM,mBACX,SAAQ,sBAAyD;IAGjE,mFAAmF;IACnF,0EAA0E;IAE1E,EAAE;IACF;QACE,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC;IAEK,oBAAoB,CAAC,QAAgB,EAAE,KAAa;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AG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEhD,OAAO;gBACL,KAAK,EAAE,MAAM;gBACb,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;KAAA;IAEK,cAAc,CAAC,OAAiB,EAAE,OAAiB,EAAE,MAAsB,EAAE,SAAiB;;YAClG,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;KAAA;CACF,CAAA;AAlGY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,gBAAO,EAAC,iBAAiB,CAAC;;GACd,mBAAmB,CAkG/B","sourcesContent":["import Container, { Service } from \"typedi\";\n\nimport { SupplierService } from \"./supplier-service.interface\";\n\nimport { SupplierRepoDB } from \"../../repositories/supplier/supplier-repo-db.interface\";\nimport \"../../repositories/supplier/supplier-repo-db\";\n\nimport { SupplierRepoES } from \"../../repositories/supplier/supplier-repo-es.interface\";\nimport \"../../repositories/supplier/supplier-repo-es\";\nimport { ActionDynamoDB, BaseServiceImpl, Filter, List, toCaseSensitive } from \"@chinggis/core\";\nimport { SAccount } from \"../../model-shared/suppler.model\";\nimport { HTTP } from \"../../../exception/exception-handler\";\nimport { openSearch_supplier } from \"../../controller/supplier/supplier-config\";\n\n@Service(\"SupplierService\")\nexport class SupplierServiceImpl\n extends BaseServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES>\n implements SupplierService\n{\n // @Inject(\"EcomOrderService\") private readonly ecomOrderService: EcomOrderService;\n // @Inject(\"ROrderService\") private readonly rOrderService: ROrderService;\n\n //\n constructor() {\n const repoDB: SupplierRepoDB = Container.get(\"SupplierRepoDB\");\n const repoES: SupplierRepoES = Container.get(\"SupplierRepoES\");\n super(repoDB, repoES);\n }\n\n async convertToCognitoUser(username: string, email: string): Promise<void> {\n const supplier = await this.findById(\"system\", username);\n\n if (!supplier) return this.throwError(HTTP.BAD_REQUEST.code, \"supplier not found!\");\n if (supplier?.loginStatus === \"pending\") return this.throwError(HTTP.BAD_REQUEST.code, \"already pending user!\");\n if (supplier?.loginStatus === \"confirmed\") return this.throwError(HTTP.BAD_REQUEST.code, \"already confirmed user!\");\n }\n\n async ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>> {\n if (filterAndSort.page > 0) filterAndSort.page = filterAndSort.page - 1;\n const filter = {\n index: openSearch_supplier.index,\n body: {\n query: {\n bool: {\n must_not: [\n {\n term: {\n accountType: \"level1\",\n },\n },\n ],\n should: [],\n minimum_should_match: 1,\n },\n },\n from: filterAndSort.page * filterAndSort.size,\n size: filterAndSort.size,\n },\n };\n\n if (filterAndSort.page && filterAndSort.size) {\n filter.body.from = filterAndSort.page * filterAndSort.size;\n }\n\n if (filterAndSort.size) {\n filter.body.size = filterAndSort.size;\n }\n\n if (!filterAndSort.searchKeyword) {\n const result = await this.repoES.search(filter, true);\n return {\n items: result,\n lastKey: null,\n };\n }\n\n let searchKeyword = filterAndSort.searchKeyword.trim();\n\n const searchFields = [\"username\", \"firstName\", \"lastName\", \"phoneList\", \"bankAccountNumber\", \"bankName\"];\n searchKeyword = toCaseSensitive(searchKeyword);\n searchFields.forEach((field) => {\n filter.body.query.bool.should.push({\n regexp: {\n [field]: {\n value: `.*${searchKeyword}.*`,\n case_insensitive: true,\n },\n },\n });\n });\n\n if (searchKeyword.includes(\"@\")) {\n filter.body.query.bool.should.push({\n wildcard: {\n \"email.keyword\": {\n value: `*${searchKeyword}*`,\n case_insensitive: true,\n },\n },\n });\n }\n\n const result = await this.repoES.search(filter);\n\n return {\n items: result,\n lastKey: null,\n };\n }\n\n async processChanges(itemOld: SAccount, itemNew: SAccount, action: ActionDynamoDB, tableName: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n}\n"]}
|