aws-service-stack 0.17.261 → 0.17.267
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/profile/profile.controller.d.ts +1 -1
- package/dist/_examples/controller/profile/profile.controller.js +1 -1
- package/dist/_examples/controller/profile/profile.controller.js.map +1 -1
- package/dist/_examples/controller/rorder/order-config.d.ts +6 -0
- package/dist/_examples/controller/rorder/order-config.js +50 -0
- package/dist/_examples/controller/rorder/order-config.js.map +1 -0
- package/dist/_examples/controller/rorder/order-controller.d.ts +9 -0
- package/dist/_examples/controller/rorder/order-controller.js +66 -0
- package/dist/_examples/controller/rorder/order-controller.js.map +1 -0
- package/dist/_examples/controller/rorder/order-crud.d.ts +4 -0
- package/dist/_examples/controller/rorder/order-crud.js +57 -0
- package/dist/_examples/controller/rorder/order-crud.js.map +1 -0
- package/dist/_examples/repositories/rorder/rorder-db.repo.d.ts +5 -0
- package/dist/_examples/repositories/rorder/rorder-db.repo.interface.d.ts +4 -0
- package/dist/_examples/repositories/rorder/rorder-db.repo.interface.js +3 -0
- package/dist/_examples/repositories/rorder/rorder-db.repo.interface.js.map +1 -0
- package/dist/_examples/repositories/rorder/rorder-db.repo.js +18 -0
- package/dist/_examples/repositories/rorder/rorder-db.repo.js.map +1 -0
- package/dist/_examples/repositories/rorder/rorder-es.repo.d.ts +7 -0
- package/dist/_examples/repositories/rorder/rorder-es.repo.interface.d.ts +5 -0
- package/dist/_examples/repositories/rorder/rorder-es.repo.interface.js +3 -0
- package/dist/_examples/repositories/rorder/rorder-es.repo.interface.js.map +1 -0
- package/dist/_examples/repositories/rorder/rorder-es.repo.js +22 -0
- package/dist/_examples/repositories/rorder/rorder-es.repo.js.map +1 -0
- package/dist/_examples/service/profile-service.d.ts +2 -4
- package/dist/_examples/service/profile-service.interface.d.ts +2 -2
- package/dist/_examples/service/profile-service.interface.js.map +1 -1
- package/dist/_examples/service/profile-service.js +2 -5
- package/dist/_examples/service/profile-service.js.map +1 -1
- package/dist/_examples/service/rorder/rorder-service.d.ts +11 -0
- package/dist/_examples/service/rorder/rorder-service.interface.d.ts +9 -0
- package/dist/_examples/service/rorder/rorder-service.interface.js +3 -0
- package/dist/_examples/service/rorder/rorder-service.interface.js.map +1 -0
- package/dist/_examples/service/rorder/rorder-service.js +65 -0
- package/dist/_examples/service/rorder/rorder-service.js.map +1 -0
- package/dist/controller/controller-api.js +2 -2
- package/dist/controller/controller-api.js.map +1 -1
- package/dist/model/base.config.d.ts +3 -2
- package/dist/model/base.config.js +5 -3
- package/dist/model/base.config.js.map +1 -1
- package/dist/model/base.model.d.ts +1 -1
- package/dist/model/base.model.js.map +1 -1
- package/dist/model/dynamodb.model.d.ts +2 -0
- package/dist/model/dynamodb.model.js +2 -0
- package/dist/model/dynamodb.model.js.map +1 -1
- package/dist/service/crud.service.d.ts +3 -1
- package/dist/service/crud.service.interface.d.ts +4 -1
- package/dist/service/crud.service.interface.js.map +1 -1
- package/dist/service/crud.service.js +31 -7
- package/dist/service/crud.service.js.map +1 -1
- package/dist/utils/http/http.util.js +6 -2
- package/dist/utils/http/http.util.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-api.js","sourceRoot":"","sources":["../../src/controller/controller-api.ts"],"names":[],"mappings":";;;AAAA,oCAiBkB;AAElB,4CAA2D;AAE3D,sDAAuD;AAGvD,MAAsB,aAAa;IACd,OAAO,CAAI;IACpB,MAAM,CAAe;IACrB,eAAe,CAAW;IAEpC,YAAsB,WAAc,EAAE,MAAoB;QACxD,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAE3B,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC5B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,gBAAgB,CAAC;QACjD,CAAC;QAED,IAAI,CA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,IAAI,qBAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,eAAe,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF;AA9TD,sCA8TC","sourcesContent":["import {\n Access,\n APIResponse,\n BaseEntity,\n createApiResponse,\n EndpointPolicy,\n Filter,\n findMatchedPolicy,\n formatErrors,\n HttpMethod,\n HttpRequest,\n List,\n parseHttpRequest,\n removeFields,\n RequestType,\n ResponseFields,\n validateWithSchema,\n} from \"../index\";\nimport { APIGatewayProxyEvent } from \"aws-lambda\";\nimport { errorHandlerHttp, ErrorHttp } from \"../exception\";\nimport { CognitoUser, EntityConfig } from \"@chinggis/types\";\nimport { trimSpecialChar } from \"../utils/string.util\";\nimport { CrudService } from \"../service\";\n\nexport abstract class ControllerApi<R extends BaseEntity, T extends CrudService<R>> {\n protected readonly service: T;\n protected config: EntityConfig;\n protected adminGroupNames: string[];\n\n protected constructor(baseService: T, config: EntityConfig) {\n this.service = baseService;\n\n if (!config) return;\n\n this.config = config;\n\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 let req = parseHttpRequest(event, this.adminGroupNames);\n\n const policy: EndpointPolicy | undefined = findMatchedPolicy(\n req.methode,\n event?.requestContext?.resourcePath,\n this.config.ENDPOINT_POLICY,\n );\n\n this.checkPermission(policy?.access, req.requestType);\n this.validateRequest(policy?.validator, req.body);\n\n log.debug(\"groups: \" + JSON.stringify(req.groups, null, 2));\n log.debug(`claims:${JSON.stringify(req.identity, null, 2)}`);\n log.debug(\n `groups:${req.groups}, isAdmin:${req.isAdmin}, userId:${req.userId}, profileId:${req.profileId}, username:${req.username}, requestType:${req.requestType}`,\n );\n\n if (!req.isAdmin && req.profileId) {\n const ownerIdFieldName = this.config.OWNER_ID_FIELD_NAME || \"ownerId\";\n req.filter[ownerIdFieldName] = req.profileId;\n }\n\n req = await this.processCrudRequestPre(req);\n\n let response: any = await this.handleCrudByMethod(req);\n\n if (response) response = await this.processCrudRequestPost(req, response);\n else response = await this.processCrudRequest(req); // Custom Endpoints\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 error.content.message = \"[CORE] \" + error.content.message;\n return createApiResponse(error.statusCode, error.content);\n }\n }\n\n setConfig(config: EntityConfig): void {\n this.config = config;\n }\n\n async processCrudRequestPre(req: HttpRequest): Promise<HttpRequest> {\n return req;\n }\n\n async processCrudRequestPost(request: HttpRequest, response: R | List<R>): Promise<R | List<R>> {\n return response;\n }\n\n protected async handleList(methode: HttpMethod, path: string, filter: Filter): Promise<any> {\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH)) {\n return await this.service.find(filter || {});\n }\n\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH) + \"/search\") {\n return await this.service.search(filter || {});\n }\n\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH) + \"/scan\") {\n return await this.service.scan(filter || {});\n }\n }\n\n protected async handleUpdate(entityId: string, requestBody: any, profileId?: string): Promise<R> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PATCH resource without id field\");\n\n const entity = this.parseEntity(requestBody);\n\n if (Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No fields to update\");\n }\n\n // id change is forbidden\n if (\"id\" in entity) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot modify the id field\");\n }\n\n entity.id = entityId;\n return this.service.update(entity as R, profileId);\n }\n\n protected async handleDelete(entityId: string, profileId?: string): Promise<boolean> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot delete resource without id field\");\n\n return this.service.remove(entityId, profileId);\n }\n\n protected async handleFetch(entityId: string, profileId?: string): Promise<R> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot fetch resource without id field\");\n\n const result = await this.service.findById(entityId, profileId);\n\n if (result) return result;\n\n throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `[CORE] Resource with ID ${entityId} not found`);\n }\n\n protected async handleReplace(entityId: string, entity: any, profileId?: string) {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PUT resource without id field\");\n\n if (!Object.keys(entity).length) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"[CORE] No entity provided for PUT update\");\n }\n\n if (!entityId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PUT resource without id field\");\n }\n\n entity.id = entityId;\n\n return this.service.update(entity, profileId);\n }\n\n protected async handlePostCreate(entity: R, isAdmin: boolean, cognitoUser: CognitoUser) {\n if (!entity || Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No entity payload provided\");\n }\n\n if (!entity.ownerId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No ownerId provided\");\n }\n\n // Initialize IDs\n const { ownerId, parentId: inputParentId } = entity;\n let profileId = ownerId;\n let parentId: string;\n\n // Determine parentId and profileId\n if (isAdmin && inputParentId) {\n parentId = inputParentId;\n } else if (cognitoUser.isParent) {\n console.log(\"is parent becomming true\");\n\n parentId = cognitoUser.profile;\n } else {\n console.log(\"is parent not becomming true\");\n console.log(\"the value of isParent: \", cognitoUser.isParent, typeof cognitoUser.isParent);\n\n parentId = cognitoUser.parentId;\n profileId = cognitoUser.profile;\n }\n\n // Remove fields that shouldn't be saved directly\n delete entity.parentId;\n delete entity.ownerId;\n\n // Save entity\n return this.service.save(entity, profileId, parentId);\n }\n\n protected abstract processCrudRequest(event: HttpRequest): Promise<any>;\n\n protected isListRequest(methode: HttpMethod, path: string): boolean {\n const basePath = trimSpecialChar(this.config.BASE_PATH);\n\n const allowedPaths = [basePath, `${basePath}/search`, `${basePath}/scan`];\n\n const isMethodGet = methode === \"GET\";\n const isAllowedPath = allowedPaths.includes(trimSpecialChar(path));\n\n return isMethodGet && isAllowedPath;\n }\n\n protected isUpdateRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodPatch = methode === \"PATCH\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodPatch && isExpectedPath;\n }\n\n protected isDeleteRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodDelete = methode === \"DELETE\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodDelete && isExpectedPath;\n }\n\n protected isFetchRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = methode === \"GET\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n protected isPostRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}`;\n const isMethodGet = methode === \"POST\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n protected isPutRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = methode === \"PUT\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n private async handleCrudByMethod(req: HttpRequest): Promise<any> {\n const path = req.event?.requestContext?.resourcePath;\n\n const entity = this.parseEntity(req.body);\n\n if (this.isUpdateRequest(req.methode, path)) return this.handleUpdate(req.entityId, entity, req.profileId);\n if (this.isDeleteRequest(req.methode, path)) return this.handleDelete(req.entityId, req.profileId);\n if (this.isFetchRequest(req.methode, path)) return this.handleFetch(req.entityId, req.profileId);\n if (this.isPutRequest(req.methode, path)) return this.handleReplace(req.entityId, entity, req.profileId);\n if (this.isPostRequest(req.methode, path)) return this.handlePostCreate(entity, req.isAdmin, req.identity);\n if (this.isListRequest(req.methode, path)) return this.handleList(req.methode, path, req.filter);\n\n return null;\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 /** Map RequestType to Access for permission checking */\n private getUserAccessLevel(requestType: RequestType): Access {\n switch (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[], requestType: RequestType) {\n const currentAccessLevel = this.getUserAccessLevel(requestType);\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 (requestType === RequestType.USER && allowedAccess.includes(Access.OWNER));\n\n if (hasPermission) return;\n\n throw new ErrorHttp(\n { code: 403, error: \"PermissionDenied\" },\n `[CORE] Access denied. Required: ${allowedAccess.join(\", \")}, Current: ${currentAccessLevel}`,\n );\n }\n\n private setUserFilter(request: any, isAdmin: boolean, profileId: string) {\n if (isAdmin && !profileId) return;\n const ownerIdFieldName = this.config.OWNER_ID_FIELD_NAME || \"ownerId\";\n request.filterAndSort[ownerIdFieldName] = profileId;\n return request.filterAndSort;\n }\n\n private parseEntity(requestBody: any): R {\n if (!requestBody) return {} as R;\n return typeof requestBody === \"string\" ? JSON.parse(requestBody) : requestBody;\n }\n\n private validateRequest(schema: any, requestBody: any) {\n if (!schema) return;\n\n try {\n validateWithSchema(schema, requestBody);\n } catch (error) {\n const formattedErrors = formatErrors(error);\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, formattedErrors);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"controller-api.js","sourceRoot":"","sources":["../../src/controller/controller-api.ts"],"names":[],"mappings":";;;AAAA,oCAiBkB;AAElB,4CAA2D;AAE3D,sDAAuD;AAGvD,MAAsB,aAAa;IACd,OAAO,CAAI;IACpB,MAAM,CAAe;IACrB,eAAe,CAAW;IAEpC,YAAsB,WAAc,EAAE,MAAoB;QACxD,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAE3B,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,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;IAED,KAAK,CAAC,kBAAkB,CAAC,KAA2B;QAClD,IAAI,CAAC;YACH,IAAI,GAAG,GAAG,IAAA,wBAAgB,EAAC,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;YAExD,MAAM,MAAM,GAA+B,IAAA,yBAAiB,EAC1D,GAAG,CAAC,OAAO,EACX,KAAK,EAAE,cAAc,EAAE,YAAY,EACnC,IAAI,CAAC,MAAM,CAAC,eAAe,CAC5B,CAAC;YAEF,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;YACtD,IAAI,CAA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AC9F,CAAC;IACJ,CAAC;IAEO,aAAa,CAAC,OAAY,EAAE,OAAgB,EAAE,SAAiB;QACrE,IAAI,OAAO,IAAI,CAAC,SAAS;YAAE,OAAO;QAClC,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,mBAAmB,IAAI,SAAS,CAAC;QACtE,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC;QACpD,OAAO,OAAO,CAAC,aAAa,CAAC;IAC/B,CAAC;IAEO,WAAW,CAAC,WAAgB;QAClC,IAAI,CAAC,WAAW;YAAE,OAAO,EAAO,CAAC;QACjC,OAAO,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;IACjF,CAAC;IAEO,eAAe,CAAC,MAAW,EAAE,WAAgB;QACnD,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,IAAI,CAAC;YACH,IAAA,0BAAkB,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,eAAe,GAAG,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC;YAC5C,MAAM,IAAI,qBAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,eAAe,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF;AA9TD,sCA8TC","sourcesContent":["import {\n Access,\n APIResponse,\n BaseEntity,\n createApiResponse,\n EndpointPolicy,\n Filter,\n findMatchedPolicy,\n formatErrors,\n HttpMethod,\n HttpRequest,\n List,\n parseHttpRequest,\n removeFields,\n RequestType,\n ResponseFields,\n validateWithSchema,\n} from \"../index\";\nimport { APIGatewayProxyEvent } from \"aws-lambda\";\nimport { errorHandlerHttp, ErrorHttp } from \"../exception\";\nimport { CognitoUser, EntityConfig } from \"@chinggis/types\";\nimport { trimSpecialChar } from \"../utils/string.util\";\nimport { CrudService } from \"../service\";\n\nexport abstract class ControllerApi<R extends BaseEntity, T extends CrudService<R>> {\n protected readonly service: T;\n protected config: EntityConfig;\n protected adminGroupNames: string[];\n\n protected constructor(baseService: T, config: EntityConfig) {\n this.service = baseService;\n\n if (!config) return;\n\n this.config = config;\n\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 let req = parseHttpRequest(event, this.adminGroupNames);\n\n const policy: EndpointPolicy | undefined = findMatchedPolicy(\n req.methode,\n event?.requestContext?.resourcePath,\n this.config.ENDPOINT_POLICY,\n );\n\n this.checkPermission(policy?.access, req.requestType);\n this.validateRequest(policy?.validator, req.body);\n\n log.debug(\"groups: \" + JSON.stringify(req.groups, null, 2));\n log.debug(`claims:${JSON.stringify(req.identity, null, 2)}`);\n log.debug(\n `groups:${req.groups}, isAdmin:${req.isAdmin}, userId:${req.userId}, profileId:${req.profileId}, username:${req.username}, requestType:${req.requestType}`,\n );\n\n if (!req.isAdmin && req.profileId) {\n const ownerIdFieldName = this.config.OWNER_ID_FIELD_NAME || \"ownerId\";\n req.filter[ownerIdFieldName] = req.profileId;\n }\n\n req = await this.processCrudRequestPre(req);\n\n let response: any = await this.handleCrudByMethod(req);\n\n if (response) response = await this.processCrudRequestPost(req, response);\n else response = await this.processCrudRequest(req); // Custom Endpoints\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 error.content.message = \"[CORE] \" + error.content.message;\n return createApiResponse(error.statusCode, error.content);\n }\n }\n\n setConfig(config: EntityConfig): void {\n this.config = config;\n }\n\n async processCrudRequestPre(req: HttpRequest): Promise<HttpRequest> {\n return req;\n }\n\n async processCrudRequestPost(request: HttpRequest, response: R | List<R>): Promise<R | List<R>> {\n return response;\n }\n\n protected async handleList(methode: HttpMethod, path: string, filter: Filter): Promise<any> {\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH)) {\n return await this.service.find(filter || {});\n }\n\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH) + \"/search\") {\n return await this.service.search(filter || {});\n }\n\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH) + \"/scan\") {\n return await this.service.scan(filter || {});\n }\n }\n\n protected async handleUpdate(entityId: string, requestBody: any, profileId?: string): Promise<R> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PATCH resource without id field\");\n\n const entity = this.parseEntity(requestBody);\n\n if (Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No fields to update\");\n }\n\n // id change is forbidden\n if (\"id\" in entity) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot modify the id field\");\n }\n\n entity.id = entityId;\n return this.service.update(entity as R, profileId);\n }\n\n protected async handleDelete(entityId: string, profileId?: string): Promise<boolean> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot delete resource without id field\");\n\n return this.service.remove(entityId, profileId);\n }\n\n protected async handleFetch(entityId: string, profileId?: string): Promise<R> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot fetch resource without id field\");\n\n const result = await this.service.findById(entityId, profileId);\n\n if (result) return result;\n\n throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `[CORE] Resource with ID ${entityId} not found`);\n }\n\n protected async handleReplace(entityId: string, entity: any, profileId?: string) {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PUT resource without id field\");\n\n if (!Object.keys(entity).length) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"[CORE] No entity provided for PUT update\");\n }\n\n if (!entityId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PUT resource without id field\");\n }\n\n entity.id = entityId;\n\n return this.service.update(entity, profileId);\n }\n\n protected async handlePostCreate(entity: R, isAdmin: boolean, cognitoUser: CognitoUser) {\n if (!entity || Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No entity payload provided\");\n }\n\n if (!entity.ownerId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No ownerId provided\");\n }\n\n // Initialize IDs\n const { ownerId, ownerParentId: inputParentId } = entity;\n let profileId = ownerId;\n let parentId: string;\n\n // Determine parentId and profileId\n if (isAdmin && inputParentId) {\n parentId = inputParentId;\n } else if (cognitoUser.isParent) {\n console.log(\"is parent becomming true\");\n\n parentId = cognitoUser.profile;\n } else {\n console.log(\"is parent not becomming true\");\n console.log(\"the value of isParent: \", cognitoUser.isParent, typeof cognitoUser.isParent);\n\n parentId = cognitoUser.parentId;\n profileId = cognitoUser.profile;\n }\n\n // Remove fields that shouldn't be saved directly\n delete entity.ownerParentId;\n delete entity.ownerId;\n\n // Save entity\n return this.service.save(entity, profileId, parentId);\n }\n\n protected abstract processCrudRequest(event: HttpRequest): Promise<any>;\n\n protected isListRequest(methode: HttpMethod, path: string): boolean {\n const basePath = trimSpecialChar(this.config.BASE_PATH);\n\n const allowedPaths = [basePath, `${basePath}/search`, `${basePath}/scan`];\n\n const isMethodGet = methode === \"GET\";\n const isAllowedPath = allowedPaths.includes(trimSpecialChar(path));\n\n return isMethodGet && isAllowedPath;\n }\n\n protected isUpdateRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodPatch = methode === \"PATCH\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodPatch && isExpectedPath;\n }\n\n protected isDeleteRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodDelete = methode === \"DELETE\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodDelete && isExpectedPath;\n }\n\n protected isFetchRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = methode === \"GET\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n protected isPostRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}`;\n const isMethodGet = methode === \"POST\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n protected isPutRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = methode === \"PUT\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n private async handleCrudByMethod(req: HttpRequest): Promise<any> {\n const path = req.event?.requestContext?.resourcePath;\n\n const entity = this.parseEntity(req.body);\n\n if (this.isUpdateRequest(req.methode, path)) return this.handleUpdate(req.entityId, entity, req.profileId);\n if (this.isDeleteRequest(req.methode, path)) return this.handleDelete(req.entityId, req.profileId);\n if (this.isFetchRequest(req.methode, path)) return this.handleFetch(req.entityId, req.profileId);\n if (this.isPutRequest(req.methode, path)) return this.handleReplace(req.entityId, entity, req.profileId);\n if (this.isPostRequest(req.methode, path)) return this.handlePostCreate(entity, req.isAdmin, req.identity);\n if (this.isListRequest(req.methode, path)) return this.handleList(req.methode, path, req.filter);\n\n return null;\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 /** Map RequestType to Access for permission checking */\n private getUserAccessLevel(requestType: RequestType): Access {\n switch (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[], requestType: RequestType) {\n const currentAccessLevel = this.getUserAccessLevel(requestType);\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 (requestType === RequestType.USER && allowedAccess.includes(Access.OWNER));\n\n if (hasPermission) return;\n\n throw new ErrorHttp(\n { code: 403, error: \"PermissionDenied\" },\n `[CORE] Access denied. Required: ${allowedAccess.join(\", \")}, Current: ${currentAccessLevel}`,\n );\n }\n\n private setUserFilter(request: any, isAdmin: boolean, profileId: string) {\n if (isAdmin && !profileId) return;\n const ownerIdFieldName = this.config.OWNER_ID_FIELD_NAME || \"ownerId\";\n request.filterAndSort[ownerIdFieldName] = profileId;\n return request.filterAndSort;\n }\n\n private parseEntity(requestBody: any): R {\n if (!requestBody) return {} as R;\n return typeof requestBody === \"string\" ? JSON.parse(requestBody) : requestBody;\n }\n\n private validateRequest(schema: any, requestBody: any) {\n if (!schema) return;\n\n try {\n validateWithSchema(schema, requestBody);\n } catch (error) {\n const formattedErrors = formatErrors(error);\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, formattedErrors);\n }\n }\n}\n"]}
|
|
@@ -2,9 +2,10 @@ import { DynamoIndexMap, EndpointPolicy } from "../index.js";
|
|
|
2
2
|
/** Generic DynamoDB Configuration */
|
|
3
3
|
export declare class DynamoDBConfig {
|
|
4
4
|
NAME: string;
|
|
5
|
+
PARENT_FIELD_NAME?: string;
|
|
5
6
|
OWNER_FIELD_NAME: string;
|
|
6
7
|
MAP: DynamoIndexMap;
|
|
7
|
-
constructor(tableName: string, ownerFieldName: string, indexMap: DynamoIndexMap);
|
|
8
|
+
constructor(tableName: string, ownerFieldName: string, indexMap: DynamoIndexMap, parentFieldName?: string);
|
|
8
9
|
}
|
|
9
10
|
/** Generic OpenSearch Configuration */
|
|
10
11
|
export declare class OpenSearchConfig {
|
|
@@ -33,7 +34,7 @@ export declare class EntityConfigImpl implements EntityConfig {
|
|
|
33
34
|
OWNER_ID_FIELD_NAME: string;
|
|
34
35
|
constructor(basePath: string, adminGroupName?: string[]);
|
|
35
36
|
/** Set DynamoDB configuration */
|
|
36
|
-
setDynamoDB(tableName: string, ownerFieldName: string, indexMap: DynamoIndexMap): this;
|
|
37
|
+
setDynamoDB(tableName: string, ownerFieldName: string, indexMap: DynamoIndexMap, parentId?: string): this;
|
|
37
38
|
/** Set OpenSearch configuration */
|
|
38
39
|
setOpenSearch(domain: string, index: string): this;
|
|
39
40
|
/** Set path-based policies */
|
|
@@ -4,10 +4,12 @@ exports.EntityConfigImpl = exports.OpenSearchConfig = exports.DynamoDBConfig = v
|
|
|
4
4
|
/** Generic DynamoDB Configuration */
|
|
5
5
|
class DynamoDBConfig {
|
|
6
6
|
NAME; // DynamoDB table name
|
|
7
|
+
PARENT_FIELD_NAME;
|
|
7
8
|
OWNER_FIELD_NAME; // DynamoDB index map for queries
|
|
8
9
|
MAP;
|
|
9
|
-
constructor(tableName, ownerFieldName, indexMap) {
|
|
10
|
+
constructor(tableName, ownerFieldName, indexMap, parentFieldName) {
|
|
10
11
|
this.NAME = tableName;
|
|
12
|
+
this.PARENT_FIELD_NAME = parentFieldName;
|
|
11
13
|
this.OWNER_FIELD_NAME = ownerFieldName;
|
|
12
14
|
this.MAP = indexMap;
|
|
13
15
|
}
|
|
@@ -38,8 +40,8 @@ class EntityConfigImpl {
|
|
|
38
40
|
this.ENDPOINT_POLICY = [];
|
|
39
41
|
}
|
|
40
42
|
/** Set DynamoDB configuration */
|
|
41
|
-
setDynamoDB(tableName, ownerFieldName, indexMap) {
|
|
42
|
-
this.DYNAMO_DB = new DynamoDBConfig(tableName, ownerFieldName, indexMap);
|
|
43
|
+
setDynamoDB(tableName, ownerFieldName, indexMap, parentId) {
|
|
44
|
+
this.DYNAMO_DB = new DynamoDBConfig(tableName, ownerFieldName, indexMap, parentId);
|
|
43
45
|
return this;
|
|
44
46
|
}
|
|
45
47
|
/** Set OpenSearch configuration */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.config.js","sourceRoot":"","sources":["../../src/model/base.config.ts"],"names":[],"mappings":";;;AAEA,qCAAqC;AACrC,MAAa,cAAc;IACzB,IAAI,CAAS,CAAC,sBAAsB;IACpC,gBAAgB,CAAS,CAAC,iCAAiC;IAC3D,GAAG,CAAiB;IAEpB,YAAY,SAAiB,EAAE,cAAsB,EAAE,QAAwB;
|
|
1
|
+
{"version":3,"file":"base.config.js","sourceRoot":"","sources":["../../src/model/base.config.ts"],"names":[],"mappings":";;;AAEA,qCAAqC;AACrC,MAAa,cAAc;IACzB,IAAI,CAAS,CAAC,sBAAsB;IACpC,iBAAiB,CAAU;IAC3B,gBAAgB,CAAS,CAAC,iCAAiC;IAC3D,GAAG,CAAiB;IAEpB,YAAY,SAAiB,EAAE,cAAsB,EAAE,QAAwB,EAAE,eAAwB;QACvG,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,iBAAiB,GAAG,eAAe,CAAC;QACzC,IAAI,CAAC,gBAAgB,GAAG,cAAc,CAAC;QACvC,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC;IACtB,CAAC;CACF;AAZD,wCAYC;AAED,uCAAuC;AACvC,MAAa,gBAAgB;IAC3B,MAAM,CAAS;IACf,KAAK,CAAS;IAEd,YAAY,MAAc,EAAE,SAAiB;QAC3C,IAAI,CAAC,MAAM,GAAG,M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,EAAE,IAAI,CAAC,gBAAgB;YACvC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;SAC9C,CAAC;IACJ,CAAC;CACF;AA9CD,4CA8CC","sourcesContent":["import { DynamoIndexMap, EndpointPolicy } from \"@chinggis/core\";\n\n/** Generic DynamoDB Configuration */\nexport class DynamoDBConfig {\n NAME: string; // DynamoDB table name\n PARENT_FIELD_NAME?: string;\n OWNER_FIELD_NAME: string; // DynamoDB index map for queries\n MAP: DynamoIndexMap;\n\n constructor(tableName: string, ownerFieldName: string, indexMap: DynamoIndexMap, parentFieldName?: string) {\n this.NAME = tableName;\n this.PARENT_FIELD_NAME = parentFieldName;\n this.OWNER_FIELD_NAME = ownerFieldName;\n this.MAP = indexMap;\n }\n}\n\n/** Generic OpenSearch Configuration */\nexport class OpenSearchConfig {\n DOMAIN: string;\n INDEX: string;\n\n constructor(domain: string, indexName: string) {\n this.DOMAIN = domain;\n this.INDEX = indexName;\n }\n}\n\n/** Configuration interface for type safety */\nexport interface EntityConfig {\n BASE_PATH: string;\n DYNAMO_DB: DynamoDBConfig;\n OPEN_SEARCH: OpenSearchConfig;\n ENDPOINT_POLICY: EndpointPolicy[];\n ADMIN_GROUP_NAME: string[];\n PARENT_ID_FIELD_NAME?: string;\n OWNER_ID_FIELD_NAME?: string;\n}\n\n/** Generic Entity Configuration Class **/\nexport class EntityConfigImpl implements EntityConfig {\n BASE_PATH: string; //Entity name for logging and debugging\n DYNAMO_DB: DynamoDBConfig; // DynamoDB configuration\n OPEN_SEARCH: OpenSearchConfig; // OpenSearch configuration\n ENDPOINT_POLICY: EndpointPolicy[]; // Path-based permission configuration\n ADMIN_GROUP_NAME: string[]; // Admin group name for Cognito\n\n PARENT_ID_FIELD_NAME?: string;\n OWNER_ID_FIELD_NAME: string;\n\n constructor(basePath: string, adminGroupName?: string[]) {\n this.BASE_PATH = basePath;\n this.ADMIN_GROUP_NAME = adminGroupName || [\"admin\"];\n this.ENDPOINT_POLICY = [];\n }\n\n /** Set DynamoDB configuration */\n setDynamoDB(tableName: string, ownerFieldName: string, indexMap: DynamoIndexMap, parentId?: string): this {\n this.DYNAMO_DB = new DynamoDBConfig(tableName, ownerFieldName, indexMap, parentId);\n return this;\n }\n\n /** Set OpenSearch configuration */\n setOpenSearch(domain: string, index: string): this {\n this.OPEN_SEARCH = new OpenSearchConfig(domain, index);\n return this;\n }\n\n /** Set path-based policies */\n setPolicies(policies: EndpointPolicy[]): this {\n this.ENDPOINT_POLICY = policies;\n return this;\n }\n\n /** Get configuration as a plain object (for BaseController compatibility) */\n toObject(): EntityConfig {\n return {\n BASE_PATH: this.BASE_PATH,\n DYNAMO_DB: this.DYNAMO_DB,\n OPEN_SEARCH: this.OPEN_SEARCH,\n ENDPOINT_POLICY: this.ENDPOINT_POLICY,\n ADMIN_GROUP_NAME: this.ADMIN_GROUP_NAME,\n PARENT_ID_FIELD_NAME: this.PARENT_ID_FIELD_NAME,\n OWNER_ID_FIELD_NAME: this.OWNER_ID_FIELD_NAME,\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.model.js","sourceRoot":"","sources":["../../src/model/base.model.ts"],"names":[],"mappings":"","sourcesContent":["import { RequestType } from \"./validation.model\";\nimport { Action } from \"./http.model\";\n\nexport interface BaseEntity {\n id?: string;\n createdAt?: string;\n updatedAt?: string;\n createdBy?: string | any;\n updatedBy?: string | any;\n ownerId?: string;\n
|
|
1
|
+
{"version":3,"file":"base.model.js","sourceRoot":"","sources":["../../src/model/base.model.ts"],"names":[],"mappings":"","sourcesContent":["import { RequestType } from \"./validation.model\";\nimport { Action } from \"./http.model\";\n\nexport interface BaseEntity {\n id?: string;\n createdAt?: string;\n updatedAt?: string;\n createdBy?: string | any;\n updatedBy?: string | any;\n ownerId?: string;\n ownerParentId?: string;\n permission?: Map<string, Permission[]>;\n}\n\nexport interface Permission {\n role: RequestType;\n actions: Action[];\n}\n\nexport interface Attachment {\n thumbnail: string;\n original: string;\n}\n\nexport interface List<T> {\n items: Array<T>;\n lastKey?: string;\n}\n"]}
|
|
@@ -33,5 +33,7 @@ export declare class DynamoIndexMap extends Map<string, {
|
|
|
33
33
|
listFields?: string[];
|
|
34
34
|
mapFields?: string[];
|
|
35
35
|
booleanFields?: string[];
|
|
36
|
+
ownerFieldNameParent?: string;
|
|
37
|
+
ownerFieldName: string;
|
|
36
38
|
setFields(partitionKey?: string, numberFields?: string[], arrayFields?: string[], booleanFields?: string[], mapFields?: string[]): DynamoIndexMap;
|
|
37
39
|
}
|
|
@@ -14,6 +14,8 @@ class DynamoIndexMap extends Map {
|
|
|
14
14
|
listFields;
|
|
15
15
|
mapFields;
|
|
16
16
|
booleanFields;
|
|
17
|
+
ownerFieldNameParent;
|
|
18
|
+
ownerFieldName;
|
|
17
19
|
setFields(partitionKey, numberFields, arrayFields, booleanFields, mapFields) {
|
|
18
20
|
this.partitionKey = partitionKey;
|
|
19
21
|
this.numberFields = numberFields;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamodb.model.js","sourceRoot":"","sources":["../../src/model/dynamodb.model.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,mCAAiB,CAAA;IACjB,mCAAiB,CAAA;AACnB,CAAC,EAJW,cAAc,8BAAd,cAAc,QAIzB;AAqBD,gFAAgF;AAChF,MAAa,cAAe,SAAQ,GAQnC;IACC,YAAY,GAAW,IAAI,CAAC;IAC5B,YAAY,CAAY;IACxB,UAAU,CAAY;IACtB,SAAS,CAAY;IACrB,aAAa,CAAY;
|
|
1
|
+
{"version":3,"file":"dynamodb.model.js","sourceRoot":"","sources":["../../src/model/dynamodb.model.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,mCAAiB,CAAA;IACjB,mCAAiB,CAAA;AACnB,CAAC,EAJW,cAAc,8BAAd,cAAc,QAIzB;AAqBD,gFAAgF;AAChF,MAAa,cAAe,SAAQ,GAQnC;IACC,YAAY,GAAW,IAAI,CAAC;IAC5B,YAAY,CAAY;IACxB,UAAU,CAAY;IACtB,SAAS,CAAY;IACrB,aAAa,CAAY;IACzB,oBAAoB,CAAU;IAC9B,cAAc,CAAS;IAEvB,SAAS,CACP,YAAqB,EACrB,YAAuB,EACvB,WAAsB,EACtB,aAAwB,EACxB,SAAoB;QAEpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA/BD,wCA+BC","sourcesContent":["export enum ActionDynamoDB {\n INSERT = \"INSERT\",\n MODIFY = \"MODIFY\",\n REMOVE = \"REMOVE\",\n}\n\nexport interface DynamoDbFilter {\n keyConditionExpression?: string;\n filterExpression?: string;\n expressionAttributeNames?: { [key: string]: string };\n expressionAttributeValues?: { [key: string]: any };\n scanIndexForward?: boolean; // false for descending order, true for ascending order\n size?: number;\n startAt?: string;\n getAllItems?: boolean;\n}\n\n/*\n * @deprecated use List\n * **/\nexport interface DynamoDbListResponse<T> {\n items: Array<T>;\n lastKey?: string;\n}\n\n/** map key is indexName, field: indexField, rField: related field names list */\nexport class DynamoIndexMap extends Map<\n string,\n {\n field: string;\n rFields: string[];\n sortKeyField?: string;\n fieldSeparator?: string;\n }\n> {\n partitionKey: string = \"id\";\n numberFields?: string[];\n listFields?: string[];\n mapFields?: string[];\n booleanFields?: string[];\n ownerFieldNameParent?: string;\n ownerFieldName: string;\n\n setFields(\n partitionKey?: string,\n numberFields?: string[],\n arrayFields?: string[],\n booleanFields?: string[],\n mapFields?: string[],\n ): DynamoIndexMap {\n this.partitionKey = partitionKey;\n this.numberFields = numberFields;\n this.listFields = arrayFields;\n this.booleanFields = booleanFields;\n this.mapFields = mapFields;\n return this;\n }\n}\n"]}
|
|
@@ -14,7 +14,7 @@ export declare abstract class CrudServiceImpl<T extends BaseEntity, D extends Ba
|
|
|
14
14
|
search(filter: Filter): Promise<T[]>;
|
|
15
15
|
searchFieldNotExist(fieldName: string, from: number, size: number): Promise<Partial<T>[]>;
|
|
16
16
|
save(entity: Partial<T>, ownerId: string, parentId?: string, createdByUserId?: string): Promise<T>;
|
|
17
|
-
saveAll(entities: Partial<T>[], ownerId: string, createdByUserId?: string, isTransactional?: boolean): Promise<Partial<T>[]>;
|
|
17
|
+
saveAll(entities: Partial<T>[], ownerId: string, parentId?: string, createdByUserId?: string, isTransactional?: boolean): Promise<Partial<T>[]>;
|
|
18
18
|
update(entity: T, requestUserId?: string): Promise<T>;
|
|
19
19
|
updateAll(entities: Partial<T>[], fields: string[], requestUserId?: string, isTransactional?: boolean): Promise<boolean>;
|
|
20
20
|
remove(entityId: string, ownerId?: string): Promise<boolean>;
|
|
@@ -24,6 +24,7 @@ export declare abstract class CrudServiceImpl<T extends BaseEntity, D extends Ba
|
|
|
24
24
|
setOpensearch(indexName: string, opensearchEndpoint: string): boolean;
|
|
25
25
|
getIndexES(): string;
|
|
26
26
|
getIndexMapDB(): DynamoIndexMap;
|
|
27
|
+
setIndexMapDB(indexMap: DynamoIndexMap): boolean;
|
|
27
28
|
findAll(): Promise<T[]>;
|
|
28
29
|
findAllMatch(filter: Filter): Promise<T[]>;
|
|
29
30
|
findAllByIndex(indexName: string, indexValue: any): Promise<T[]>;
|
|
@@ -50,4 +51,5 @@ export declare abstract class CrudServiceImpl<T extends BaseEntity, D extends Ba
|
|
|
50
51
|
*/
|
|
51
52
|
private checkIsIndexedField;
|
|
52
53
|
private fetchAll;
|
|
54
|
+
private parseOwnerFields;
|
|
53
55
|
}
|
|
@@ -11,6 +11,7 @@ export interface CrudService<T extends BaseEntity> {
|
|
|
11
11
|
* Creates a new entity for the given user.
|
|
12
12
|
* @param ownerId - The ID of the user who owns the entity.
|
|
13
13
|
* @param entity - The entity to be created.
|
|
14
|
+
* @param parentId
|
|
14
15
|
* @param createdByUserId - The created userId.
|
|
15
16
|
* @returns The created entity.
|
|
16
17
|
*/
|
|
@@ -19,11 +20,12 @@ export interface CrudService<T extends BaseEntity> {
|
|
|
19
20
|
* Creates multiple new entities for the given user.
|
|
20
21
|
* @param ownerId - The ID of the user who owns the entities.
|
|
21
22
|
* @param entity - An array of entities to be created.
|
|
23
|
+
* @param parentId
|
|
22
24
|
* @param createdByUserId - The created userId.
|
|
23
25
|
* @param isTransactional - Whether to perform the operation in a transaction.
|
|
24
26
|
* @returns An array of created entities.
|
|
25
27
|
*/
|
|
26
|
-
saveAll(entity: Partial<T>[], ownerId: string, createdByUserId?: string, isTransactional?: boolean): Promise<Partial<T>[]>;
|
|
28
|
+
saveAll(entity: Partial<T>[], ownerId: string, parentId?: string, createdByUserId?: string, isTransactional?: boolean): Promise<Partial<T>[]>;
|
|
27
29
|
/**
|
|
28
30
|
* Applies partial updates to an entity for the given user.
|
|
29
31
|
* Only the specified fields will be updated.
|
|
@@ -114,6 +116,7 @@ export interface CrudService<T extends BaseEntity> {
|
|
|
114
116
|
setOpensearch(indexName: string, opensearchEndpoint: string): boolean;
|
|
115
117
|
getIndexES(): string;
|
|
116
118
|
getIndexMapDB(): DynamoIndexMap;
|
|
119
|
+
setIndexMapDB(indexMap: DynamoIndexMap): boolean;
|
|
117
120
|
incrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T>;
|
|
118
121
|
decrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T>;
|
|
119
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud.service.interface.js","sourceRoot":"","sources":["../../src/service/crud.service.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseEntity, DynamoIndexMap, Filter, List } 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 CrudService<T extends BaseEntity> {\n setConfig(config: EntityConfig): void;\n\n getTableName(): string;\n /**\n * Creates a new entity for the given user.\n * @param ownerId - The ID of the user who owns the entity.\n * @param entity - The entity to be created.\n * @param createdByUserId - The created userId.\n * @returns The created entity.\n */\n save(entity: Partial<T>, ownerId: string, parentId?: string, createdByUserId?: string): Promise<T>;\n\n /**\n * Creates multiple new entities for the given user.\n * @param ownerId - The ID of the user who owns the entities.\n * @param entity - An array of entities to be created.\n * @param createdByUserId - The created userId.\n * @param isTransactional - Whether to perform the operation in a transaction.\n * @returns An array of created entities.\n */\n saveAll(\n entity: Partial<T>[],\n ownerId: string,\n createdByUserId?: string,\n isTransactional?: boolean,\n ): Promise<Partial<T>[]>;\n\n /**\n * Applies partial updates to an entity for the given user.\n * Only the specified fields will be updated.\n * @param requestUserId - The ID of the user who owns the entity. If not exist means admin\n * @param entity - The entity with updated fields.\n * @returns The updated entity.\n */\n update(entity: T, requestUserId?: string): Promise<T>;\n\n /**\n * Applies partial updates to multiple entities for the given user.\n * Only the specified fields will be updated for each entity.\n * @param requestUserId - The ID of the user who owns the entities. If not exist means admin\n * @param entity - An array of entities with updated fields.\n * @param fields - The list of field names to update in each entity.\n * @param isTransactional - Whether to perform the operation in a transaction.\n * @returns True if all entities were successfully updated.\n */\n updateAll(entity: T[], fields: string[], requestUserId?: string, isTransactional?: boolean): Promise<boolean>;\n\n /**\n * Deletes an entity by ID for the given user.\n * @param ownerId - The ID of the user who owns the entity.\n * @param entityId - The ID of the entity to delete.\n * @returns True if the entity was successfully deleted.\n */\n remove(entityId: string, ownerId?: string): Promise<boolean>;\n\n /**\n * Deletes multiple entities by their IDs for the given user.\n * @param ownerId - The ID of the user who owns the entities.\n * @param entityIds - An array of entity IDs to delete.\n * @returns True if all entities were successfully deleted.\n */\n removeAll(entityIds: string[], ownerId?: string): Promise<boolean>;\n\n /**\n * Retrieves an entity by its ID for the given user.\n * @param ownerId - The ID of the user who owns the entity.\n * @param entityId - The ID of the entity to retrieve.\n * @returns The requested entity.\n */\n findById(entityId: string, ownerId?: string): Promise<T>;\n\n /**\n * Retrieves multiple entities by their IDs for the given user.\n * @param ownerId - The ID of the user who owns the entities.\n * @param entityIds - An array of entity IDs to retrieve.\n * @returns An array of found entities.\n */\n findByIds(entityIds: string[], ownerId?: string): Promise<T[]>;\n\n /**\n * Retrieves a paginated and filtered list of entities from DynamoDB.\n *\n * @param filter - Filtering and sorting options.\n * @returns A promise resolving to a paginated list of entities.\n */\n find(filter: Filter): Promise<List<Partial<T>>>;\n\n /**\n * Scans the table with non-index filters. Expensive; avoid it for hot paths.\n */\n scan(filter: Filter): Promise<List<Partial<T>>>;\n\n findQuery(queryParams: string): Promise<List<Partial<T>>>;\n\n searchQuery(queryParams: string): Promise<Partial<T>[]>;\n\n findAll(): Promise<T[]>;\n\n findAllMatch(filter: Filter): Promise<T[]>;\n\n findAllByIndex(indexName: string, indexValue: any): Promise<T[]>;\n\n findByField(fieldName: string, fieldValue: any): Promise<List<T>>;\n\n findFirst(fieldName: string, fieldValue: string | boolean | number | Date): Promise<T>;\n\n throwError(code: number, message: string, errorContent?: any): void;\n\n throwErrorHttp(error: { message: string; code: number }, message: string, errorContent?: any): void;\n\n throwErrorDatabase(tableName: string, command: any, errorContent?: any): void;\n\n throwErrorValidation(entityName: string, validation: Map<string, any>, errorContent?: any): void;\n\n // throwError(httpStatus: number, message: string): void;\n /**\n * Retrieves a filtered and sorted list of entities from OpenSearch.\n *\n * @param filter - Filtering and sorting options.\n * @returns A promise resolving to the list of matching entities.\n */\n search(filter: Filter): Promise<T[]>;\n\n searchFieldNotExist(fieldName: string, from: number, size: number): Promise<Partial<T>[]>;\n\n /**\n * Changes the owner of an entity.\n * @param ownerId - The new owner's ID.\n * @param entityId - The ID of the entity to transfer.\n * @returns The updated entity with the new owner.\n */\n changeOwner(entityId: string, ownerId: string): Promise<T>;\n\n setTable(tableName: string, dynamoIndexMap: DynamoIndexMap): boolean;\n\n setOpensearch(indexName: string, opensearchEndpoint: string): boolean;\n\n getIndexES(): string;\n\n getIndexMapDB(): DynamoIndexMap;\n\n incrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T>;\n\n decrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"crud.service.interface.js","sourceRoot":"","sources":["../../src/service/crud.service.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { BaseEntity, DynamoIndexMap, Filter, List } 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 CrudService<T extends BaseEntity> {\n setConfig(config: EntityConfig): void;\n\n getTableName(): string;\n /**\n * Creates a new entity for the given user.\n * @param ownerId - The ID of the user who owns the entity.\n * @param entity - The entity to be created.\n * @param parentId\n * @param createdByUserId - The created userId.\n * @returns The created entity.\n */\n save(entity: Partial<T>, ownerId: string, parentId?: string, createdByUserId?: string): Promise<T>;\n\n /**\n * Creates multiple new entities for the given user.\n * @param ownerId - The ID of the user who owns the entities.\n * @param entity - An array of entities to be created.\n * @param parentId\n * @param createdByUserId - The created userId.\n * @param isTransactional - Whether to perform the operation in a transaction.\n * @returns An array of created entities.\n */\n saveAll(\n entity: Partial<T>[],\n ownerId: string,\n parentId?: string,\n createdByUserId?: string,\n isTransactional?: boolean,\n ): Promise<Partial<T>[]>;\n\n /**\n * Applies partial updates to an entity for the given user.\n * Only the specified fields will be updated.\n * @param requestUserId - The ID of the user who owns the entity. If not exist means admin\n * @param entity - The entity with updated fields.\n * @returns The updated entity.\n */\n update(entity: T, requestUserId?: string): Promise<T>;\n\n /**\n * Applies partial updates to multiple entities for the given user.\n * Only the specified fields will be updated for each entity.\n * @param requestUserId - The ID of the user who owns the entities. If not exist means admin\n * @param entity - An array of entities with updated fields.\n * @param fields - The list of field names to update in each entity.\n * @param isTransactional - Whether to perform the operation in a transaction.\n * @returns True if all entities were successfully updated.\n */\n updateAll(entity: T[], fields: string[], requestUserId?: string, isTransactional?: boolean): Promise<boolean>;\n\n /**\n * Deletes an entity by ID for the given user.\n * @param ownerId - The ID of the user who owns the entity.\n * @param entityId - The ID of the entity to delete.\n * @returns True if the entity was successfully deleted.\n */\n remove(entityId: string, ownerId?: string): Promise<boolean>;\n\n /**\n * Deletes multiple entities by their IDs for the given user.\n * @param ownerId - The ID of the user who owns the entities.\n * @param entityIds - An array of entity IDs to delete.\n * @returns True if all entities were successfully deleted.\n */\n removeAll(entityIds: string[], ownerId?: string): Promise<boolean>;\n\n /**\n * Retrieves an entity by its ID for the given user.\n * @param ownerId - The ID of the user who owns the entity.\n * @param entityId - The ID of the entity to retrieve.\n * @returns The requested entity.\n */\n findById(entityId: string, ownerId?: string): Promise<T>;\n\n /**\n * Retrieves multiple entities by their IDs for the given user.\n * @param ownerId - The ID of the user who owns the entities.\n * @param entityIds - An array of entity IDs to retrieve.\n * @returns An array of found entities.\n */\n findByIds(entityIds: string[], ownerId?: string): Promise<T[]>;\n\n /**\n * Retrieves a paginated and filtered list of entities from DynamoDB.\n *\n * @param filter - Filtering and sorting options.\n * @returns A promise resolving to a paginated list of entities.\n */\n find(filter: Filter): Promise<List<Partial<T>>>;\n\n /**\n * Scans the table with non-index filters. Expensive; avoid it for hot paths.\n */\n scan(filter: Filter): Promise<List<Partial<T>>>;\n\n findQuery(queryParams: string): Promise<List<Partial<T>>>;\n\n searchQuery(queryParams: string): Promise<Partial<T>[]>;\n\n findAll(): Promise<T[]>;\n\n findAllMatch(filter: Filter): Promise<T[]>;\n\n findAllByIndex(indexName: string, indexValue: any): Promise<T[]>;\n\n findByField(fieldName: string, fieldValue: any): Promise<List<T>>;\n\n findFirst(fieldName: string, fieldValue: string | boolean | number | Date): Promise<T>;\n\n throwError(code: number, message: string, errorContent?: any): void;\n\n throwErrorHttp(error: { message: string; code: number }, message: string, errorContent?: any): void;\n\n throwErrorDatabase(tableName: string, command: any, errorContent?: any): void;\n\n throwErrorValidation(entityName: string, validation: Map<string, any>, errorContent?: any): void;\n\n // throwError(httpStatus: number, message: string): void;\n /**\n * Retrieves a filtered and sorted list of entities from OpenSearch.\n *\n * @param filter - Filtering and sorting options.\n * @returns A promise resolving to the list of matching entities.\n */\n search(filter: Filter): Promise<T[]>;\n\n searchFieldNotExist(fieldName: string, from: number, size: number): Promise<Partial<T>[]>;\n\n /**\n * Changes the owner of an entity.\n * @param ownerId - The new owner's ID.\n * @param entityId - The ID of the entity to transfer.\n * @returns The updated entity with the new owner.\n */\n changeOwner(entityId: string, ownerId: string): Promise<T>;\n\n setTable(tableName: string, dynamoIndexMap: DynamoIndexMap): boolean;\n\n setOpensearch(indexName: string, opensearchEndpoint: string): boolean;\n\n getIndexES(): string;\n\n getIndexMapDB(): DynamoIndexMap;\n\n setIndexMapDB(indexMap: DynamoIndexMap): boolean;\n\n incrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T>;\n\n decrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T>;\n}\n"]}
|
|
@@ -26,7 +26,8 @@ class CrudServiceImpl {
|
|
|
26
26
|
return await this.find(filter);
|
|
27
27
|
}
|
|
28
28
|
async searchQuery(queryParams) {
|
|
29
|
-
|
|
29
|
+
let filter = (0, index_1.parseIndexFilter)(queryParams);
|
|
30
|
+
filter = this.parseOwnerFields(filter, this.config);
|
|
30
31
|
this.checkIsIndexedField(filter);
|
|
31
32
|
return await this.search(filter);
|
|
32
33
|
}
|
|
@@ -37,7 +38,8 @@ class CrudServiceImpl {
|
|
|
37
38
|
return await this.repoDB.decrementValueByField(entityId, fieldName, value);
|
|
38
39
|
}
|
|
39
40
|
async search(filter) {
|
|
40
|
-
|
|
41
|
+
const parsedFilter = this.parseOwnerFields(filter, this.config);
|
|
42
|
+
return (await this.repoES.find(parsedFilter)).items;
|
|
41
43
|
}
|
|
42
44
|
async searchFieldNotExist(fieldName, from, size) {
|
|
43
45
|
return await this.repoES.fieldNotExists(fieldName, from, size);
|
|
@@ -52,10 +54,12 @@ class CrudServiceImpl {
|
|
|
52
54
|
entity[this.config.PARENT_ID_FIELD_NAME] = parentId;
|
|
53
55
|
return await this.repoDB.save(entity);
|
|
54
56
|
}
|
|
55
|
-
async saveAll(entities, ownerId, createdByUserId, isTransactional) {
|
|
57
|
+
async saveAll(entities, ownerId, parentId, createdByUserId, isTransactional) {
|
|
56
58
|
const entitiesUpdated = [];
|
|
57
59
|
for (const item of entities) {
|
|
58
60
|
const entity = (0, index_1.addDatesAndId)(item);
|
|
61
|
+
if (parentId)
|
|
62
|
+
entity[this.config.PARENT_ID_FIELD_NAME] = parentId;
|
|
59
63
|
entity[this.config.OWNER_ID_FIELD_NAME] = ownerId;
|
|
60
64
|
entity.createdBy = createdByUserId || ownerId;
|
|
61
65
|
entitiesUpdated.push(entity);
|
|
@@ -65,7 +69,8 @@ class CrudServiceImpl {
|
|
|
65
69
|
async update(entity, requestUserId) {
|
|
66
70
|
if (requestUserId) {
|
|
67
71
|
const item = await this.repoDB.findById(entity.id);
|
|
68
|
-
if (item[this.config.OWNER_ID_FIELD_NAME] !== requestUserId
|
|
72
|
+
if (item[this.config.OWNER_ID_FIELD_NAME] !== requestUserId ||
|
|
73
|
+
item[this.config.PARENT_ID_FIELD_NAME] !== requestUserId)
|
|
69
74
|
throw new exception_1.ErrorHttp({ code: 403, error: "PermissionDenied" }, `No permission to resource: ${entity.id}`);
|
|
70
75
|
entity.updatedBy = requestUserId;
|
|
71
76
|
}
|
|
@@ -112,6 +117,10 @@ class CrudServiceImpl {
|
|
|
112
117
|
getIndexMapDB() {
|
|
113
118
|
return this.repoDB.getIndexMap();
|
|
114
119
|
}
|
|
120
|
+
setIndexMapDB(indexMap) {
|
|
121
|
+
this.repoDB.setIndexMap(indexMap);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
115
124
|
async findAll() {
|
|
116
125
|
const result = [];
|
|
117
126
|
const filter = (0, index_1.parseIndexFilter)("size=250");
|
|
@@ -149,8 +158,9 @@ class CrudServiceImpl {
|
|
|
149
158
|
}
|
|
150
159
|
async find(filter) {
|
|
151
160
|
// Validate that all field names in the filter exist in the index map
|
|
152
|
-
this.
|
|
153
|
-
|
|
161
|
+
let parsedFilter = this.parseOwnerFields(filter, this.config);
|
|
162
|
+
this.checkIsIndexedField(parsedFilter);
|
|
163
|
+
parsedFilter = (0, index_1.parseIndexFilter)(filter, this.getIndexMapDB());
|
|
154
164
|
return await this.repoDB.find(parsedFilter);
|
|
155
165
|
}
|
|
156
166
|
async findById(entityId, profileId) {
|
|
@@ -172,7 +182,6 @@ class CrudServiceImpl {
|
|
|
172
182
|
entity[this.config.OWNER_ID_FIELD_NAME] == profileId) {
|
|
173
183
|
ownEntities.push(entity);
|
|
174
184
|
}
|
|
175
|
-
continue;
|
|
176
185
|
}
|
|
177
186
|
return ownEntities;
|
|
178
187
|
}
|
|
@@ -196,6 +205,7 @@ class CrudServiceImpl {
|
|
|
196
205
|
setConfig(config) {
|
|
197
206
|
this.config = config;
|
|
198
207
|
this.setTable(config.DYNAMO_DB.NAME, config.DYNAMO_DB.MAP);
|
|
208
|
+
this.getIndexMapDB();
|
|
199
209
|
if (this.repoDB) {
|
|
200
210
|
this.repoDB.setIndexMap(config.DYNAMO_DB.MAP);
|
|
201
211
|
this.repoDB.setTable(config.DYNAMO_DB.NAME);
|
|
@@ -269,6 +279,20 @@ class CrudServiceImpl {
|
|
|
269
279
|
} while (filter.lastKey);
|
|
270
280
|
return result;
|
|
271
281
|
}
|
|
282
|
+
parseOwnerFields(filter, entityConfig) {
|
|
283
|
+
const parsedFilter = filter;
|
|
284
|
+
if (parsedFilter.ownerParentId && entityConfig.PARENT_ID_FIELD_NAME) {
|
|
285
|
+
parsedFilter[entityConfig.PARENT_ID_FIELD_NAME] = parsedFilter.ownerParentId;
|
|
286
|
+
if (entityConfig.PARENT_ID_FIELD_NAME !== parsedFilter.ownerParentId)
|
|
287
|
+
delete parsedFilter.ownerParentId;
|
|
288
|
+
}
|
|
289
|
+
if (parsedFilter.profileId && entityConfig.OWNER_ID_FIELD_NAME) {
|
|
290
|
+
parsedFilter[entityConfig.OWNER_ID_FIELD_NAME] = parsedFilter.profileId;
|
|
291
|
+
if (entityConfig.OWNER_ID_FIELD_NAME !== parsedFilter.owderId)
|
|
292
|
+
delete parsedFilter.profileId;
|
|
293
|
+
}
|
|
294
|
+
return parsedFilter;
|
|
295
|
+
}
|
|
272
296
|
}
|
|
273
297
|
exports.CrudServiceImpl = CrudServiceImpl;
|
|
274
298
|
//# sourceMappingURL=crud.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud.service.js","sourceRoot":"","sources":["../../src/service/crud.service.ts"],"names":[],"mappings":";;;AAAA,oCAYkB;AAClB,4CAAoF;AAKpF,MAAsB,eAAe;IAGzB,MAAM,CAAI;IACV,MAAM,CAAI;IACV,MAAM,CAAe;IAE/B,YAAsB,MAAS,EAAE,MAAS;QACxC,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,YAAY,sBAAc,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAE/D,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,YAAY,sBAAc,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAE/D,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI;YAAE,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAEvF,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,KAAK,CAAC,SAAS,CAAC,WAAmB;QACjC,MAAM,MAAM,GAAG,IAAA,wBAAgB,EAAC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,kCAAkC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC9G,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,MAAc;QACnC,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,GAAG,CAAC;YACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAChD,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC/B,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QACpC,CAAC,QAAQ,MAAM,CAAC,OAAO,EAAE;QAEzB,OAAO,MAAa,CAAC;IACvB,CAAC;CACF;AA5VD,0CA4VC","sourcesContent":["import {\n addDates,\n addDatesAndId,\n BaseEntity,\n BaseRepoDB,\n BaseRepoDBImpl,\n BaseRepoES,\n BaseRepoESImpl,\n DynamoIndexMap,\n Filter,\n List,\n parseIndexFilter,\n} from \"../index\";\nimport { ErrorBase, ErrorDynamoDB, ErrorHttp, ErrorValidation } from \"../exception\";\n\nimport { EntityConfig } from \"@chinggis/types\";\nimport { CrudService } from \"./crud.service.interface\";\n\nexport abstract class CrudServiceImpl<T extends BaseEntity, D extends BaseRepoDB<T>, S extends BaseRepoES<T>>\n implements CrudService<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(\"repoDB is not an instance of BaseRepoDBImpl\");\n\n if (repoES != null && !(repoES instanceof BaseRepoESImpl))\n console.error(\"repoES is not an instance of BaseRepoESImpl\");\n\n if (repoDB == null && repoES == null) console.error(\"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 async findQuery(queryParams: string): Promise<List<Partial<T>>> {\n const filter = parseIndexFilter(queryParams, this.getIndexMapDB());\n this.checkIsIndexedField(filter);\n return await this.find(filter);\n }\n\n async searchQuery(queryParams: string): Promise<Partial<T>[]> {\n const filter = parseIndexFilter(queryParams);\n this.checkIsIndexedField(filter);\n return await this.search(filter);\n }\n\n async incrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T> {\n return await this.repoDB.incrementValueByField(entityId, fieldName, value);\n }\n\n async decrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T> {\n return await this.repoDB.decrementValueByField(entityId, fieldName, value);\n }\n\n async search(filter: Filter): Promise<T[]> {\n return (await this.repoES.find(filter)).items as T[];\n }\n\n async searchFieldNotExist(fieldName: string, from: number, size: number): Promise<Partial<T>[]> {\n return await this.repoES.fieldNotExists(fieldName, from, size);\n }\n\n async save(entity: Partial<T>, ownerId: string, parentId?: string, createdByUserId?: string): Promise<T> {\n addDatesAndId(entity);\n\n if (ownerId) {\n entity[this.config.OWNER_ID_FIELD_NAME] = ownerId;\n entity.createdBy = createdByUserId || ownerId;\n }\n if (parentId) entity[this.config.PARENT_ID_FIELD_NAME] = parentId;\n\n return await this.repoDB.save(entity);\n }\n\n async saveAll(\n entities: Partial<T>[],\n ownerId: string,\n createdByUserId?: string,\n isTransactional?: boolean,\n ): Promise<Partial<T>[]> {\n const entitiesUpdated = [];\n\n for (const item of entities) {\n const entity = addDatesAndId(item);\n entity[this.config.OWNER_ID_FIELD_NAME] = ownerId;\n entity.createdBy = createdByUserId || ownerId;\n\n entitiesUpdated.push(entity);\n }\n\n return await this.repoDB.saveMany(entitiesUpdated, isTransactional);\n }\n\n async update(entity: T, requestUserId?: string): Promise<T> {\n if (requestUserId) {\n const item = await this.repoDB.findById(entity.id);\n if (item[this.config.OWNER_ID_FIELD_NAME] !== requestUserId)\n throw new ErrorHttp({ code: 403, error: \"PermissionDenied\" }, `No permission to resource: ${entity.id}`);\n entity.updatedBy = requestUserId;\n }\n entity = addDates(entity) as T;\n\n // if (!hasPermission(entity, userId, Permission.UPDATE)) throw new Error(\"Unauthorized access\");\n return await this.repoDB.update(entity);\n }\n\n async updateAll(\n entities: Partial<T>[],\n fields: string[],\n requestUserId?: string,\n isTransactional?: boolean,\n ): Promise<boolean> {\n if (requestUserId) log.warn(\"this methode is under development, cannot check ownership by updateAll\");\n\n return await this.repoDB.updateMany(entities, fields, isTransactional);\n }\n\n async remove(entityId: string, ownerId?: string): Promise<boolean> {\n const entity = await this.repoDB.findById(entityId);\n if (!entity) throw new Error(\"Entity not found\");\n\n if (ownerId && entity[this.config.OWNER_ID_FIELD_NAME] !== ownerId) return null;\n\n return await this.repoDB.delete(entityId);\n }\n\n async removeAll(entityIds: string[], ownerId?: string): Promise<boolean> {\n if (ownerId) log.warn(\"this methode is under development, cannot check ownership by removeAll\");\n return await this.repoDB.deleteMany(entityIds);\n }\n\n async changeOwner(entityId: string, ownerId: string): Promise<T> {\n const entity = await this.repoDB.findById(entityId);\n entity[this.config.OWNER_ID_FIELD_NAME] = ownerId;\n return this.repoDB.update(entity);\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 setOpensearch(indexName: string, opensearchEndpoint: string): boolean {\n this.repoES.setIndexName(indexName);\n this.repoES.setEndpoint(opensearchEndpoint);\n return true;\n }\n\n getIndexES(): string {\n return this.repoES.getIndexName();\n }\n\n getIndexMapDB(): DynamoIndexMap {\n return this.repoDB.getIndexMap();\n }\n\n async findAll(): Promise<T[]> {\n const result: T[] = [];\n\n const filter = parseIndexFilter(\"size=250\");\n\n do {\n const response = await this.repoDB.find(filter);\n result.push(...(response.items as T[]));\n filter.lastKey = response.lastKey;\n } while (filter.lastKey);\n\n return result;\n }\n\n async findAllMatch(filter: Filter): Promise<T[]> {\n this.checkIsIndexedField(filter);\n return await this.fetchAll(filter);\n }\n\n async findAllByIndex(indexName: string, indexValue: any): Promise<T[]> {\n // Create a filter object for validation\n const filter = { indexName: indexName, indexValue: indexValue };\n this.checkIsIndexedField(filter);\n\n const parsedFilter = parseIndexFilter(filter, this.getIndexMapDB());\n return this.fetchAll(parsedFilter);\n }\n\n async findByField(fieldName: string, fieldValue: any): Promise<List<T>> {\n // Create a filter object for validation\n const filter = { [fieldName]: fieldValue, size: 100 };\n this.checkIsIndexedField(filter);\n const parsedFilter = parseIndexFilter(fieldName + \"=\" + fieldValue + \"&size=100\", this.getIndexMapDB());\n return (await this.find(parsedFilter)) as List<T>;\n }\n\n async findFirst(fieldName: string, fieldValue: string | boolean | number | Date): Promise<T> {\n // Validate that the field name exists in the index map\n const filter = { [fieldName]: fieldValue };\n this.checkIsIndexedField(filter);\n\n const result = await this.findByField(fieldName, fieldValue);\n return result.items.length > 0 ? result.items[0] : null;\n }\n\n async find(filter: Filter): Promise<List<Partial<T>>> {\n // Validate that all field names in the filter exist in the index map\n this.checkIsIndexedField(filter);\n\n const parsedFilter = parseIndexFilter(filter, this.getIndexMapDB());\n return await this.repoDB.find(parsedFilter);\n }\n\n async findById(entityId: string, profileId?: string): Promise<T> {\n const entity = await this.repoDB.findById(entityId);\n\n if (entity[this.config.PARENT_ID_FIELD_NAME] == profileId || entity[this.config.OWNER_ID_FIELD_NAME] == profileId) {\n return entity;\n }\n\n return null;\n }\n\n async findByIds(entityIds: string[], profileId?: string): Promise<T[]> {\n if (entityIds.length > 25) throw new ErrorDynamoDB(this.getTableName(), \"findByIds\", \"Too many entities\");\n\n const entities = await this.repoDB.findByIds(entityIds);\n if (!profileId) return entities;\n const ownEntities = [];\n for (const entity of entities) {\n if (\n entity[this.config.PARENT_ID_FIELD_NAME] == profileId ||\n entity[this.config.OWNER_ID_FIELD_NAME] == profileId\n ) {\n ownEntities.push(entity);\n }\n\n continue;\n }\n return ownEntities;\n }\n\n async scan(filter: Filter): Promise<List<Partial<T>>> {\n this.checkIsIndexedField(filter);\n const parsedFilter = parseIndexFilter(filter, this.getIndexMapDB());\n return await this.repoDB.scan(parsedFilter);\n }\n\n throwErrorHttp(error: { message: string; code: number }, message?: string, errorContent?: any): void {\n throw new ErrorHttp({ code: error.code, error: error.message }, message, errorContent);\n }\n\n throwErrorDatabase(tableName: string, command: any, errorContent?: any): void {\n throw new ErrorDynamoDB(tableName, command, errorContent);\n }\n\n throwErrorValidation(entityName: string, validation: Map<string, any>, errorContent?: any): void {\n throw new ErrorValidation(entityName, validation, errorContent);\n }\n\n throwError(code: number, message: string, errorContent?: any): void {\n throw new ErrorBase(code, message, errorContent);\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\n /**\n * Validates that all field names in the filter exist in the index map.\n * Throws a Bad Request error if any field is not found in the available indexes.\n *\n * @param filter - The filter object containing field names to validate\n * @throws ErrorHttp with status 400 if validation fails\n */\n private checkIsIndexedField(filter: Filter): void {\n if (!filter || typeof filter !== \"object\") {\n return; // Skip validation for invalid filters\n }\n\n const indexMap = this.getIndexMapDB();\n if (!indexMap || indexMap.size === 0) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"No indexes configured for this table\");\n }\n\n // Get all valid field names from all indexes\n const validFields = new Set<string>();\n\n // Add a partition key\n if (indexMap.partitionKey) {\n validFields.add(indexMap.partitionKey);\n }\n\n // Add fields from all indexes\n for (const [indexName, indexConfig] of indexMap.entries()) {\n if (indexConfig.field) {\n validFields.add(indexConfig.field);\n }\n if (indexConfig.rFields) {\n indexConfig.rFields.forEach((field) => validFields.add(field));\n }\n if (indexConfig.sortKeyField) {\n validFields.add(indexConfig.sortKeyField);\n }\n }\n\n // Check each field in the filter\n const invalidFields: string[] = [];\n for (const fieldName of Object.keys(filter)) {\n // Skip special filter properties that are not field names\n if (\n [\"indexName\", \"indexValue\", \"size\", \"lastKey\", \"fieldsInclude\", \"fieldsExclude\", \"rangeFilters\"].includes(\n fieldName,\n )\n ) {\n continue;\n }\n\n // Skip range filter fields (ageMin, ageMax, etc.)\n const rangeSuffixes = [\"Min\", \"Max\", \"From\", \"To\", \"Start\", \"End\"];\n const isRangeField = rangeSuffixes.some((suffix) => fieldName.endsWith(suffix));\n if (isRangeField) {\n continue;\n }\n\n if (!validFields.has(fieldName)) {\n invalidFields.push(fieldName);\n }\n }\n\n if (invalidFields.length > 0) {\n const availableFields = Array.from(validFields).sort();\n throw new ErrorHttp(\n { code: 400, error: \"Bad Request\" },\n `Invalid field names in filter: ${invalidFields.join(\", \")}. Available fields: ${availableFields.join(\", \")}`,\n );\n }\n }\n\n private async fetchAll(filter: Filter): Promise<T[]> {\n const result: Partial<T>[] = [];\n do {\n const response = await this.repoDB.find(filter);\n result.push(...response.items);\n filter.lastKey = response.lastKey;\n } while (filter.lastKey);\n\n return result as T[];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"crud.service.js","sourceRoot":"","sources":["../../src/service/crud.service.ts"],"names":[],"mappings":";;;AAAA,oCAYkB;AAClB,4CAAoF;AAKpF,MAAsB,eAAe;IAGzB,MAAM,CAAI;IACV,MAAM,CAAI;IACV,MAAM,CAAe;IAE/B,YAAsB,MAAS,EAAE,MAAS;QACxC,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,YAAY,sBAAc,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAE/D,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,YAAY,sBAAc,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAE/D,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI;YAA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,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC/B,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QACpC,CAAC,QAAQ,MAAM,CAAC,OAAO,EAAE;QAEzB,OAAO,MAAa,CAAC;IACvB,CAAC;IAEO,gBAAgB,CAAC,MAAc,EAAE,YAA0B;QACjE,MAAM,YAAY,GAAG,MAAM,CAAC;QAC5B,IAAI,YAAY,CAAC,aAAa,IAAI,YAAY,CAAC,oBAAoB,EAAE,CAAC;YACpE,YAAY,CAAC,YAAY,CAAC,oBAAoB,CAAC,GAAG,YAAY,CAAC,aAAa,CAAC;YAC7E,IAAI,YAAY,CAAC,oBAAoB,KAAK,YAAY,CAAC,aAAa;gBAAE,OAAO,YAAY,CAAC,aAAa,CAAC;QAC1G,CAAC;QAED,IAAI,YAAY,CAAC,SAAS,IAAI,YAAY,CAAC,mBAAmB,EAAE,CAAC;YAC/D,YAAY,CAAC,YAAY,CAAC,mBAAmB,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC;YACxE,IAAI,YAAY,CAAC,mBAAmB,KAAK,YAAY,CAAC,OAAO;gBAAE,OAAO,YAAY,CAAC,SAAS,CAAC;QAC/F,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AA3XD,0CA2XC","sourcesContent":["import {\n addDates,\n addDatesAndId,\n BaseEntity,\n BaseRepoDB,\n BaseRepoDBImpl,\n BaseRepoES,\n BaseRepoESImpl,\n DynamoIndexMap,\n Filter,\n List,\n parseIndexFilter,\n} from \"../index\";\nimport { ErrorBase, ErrorDynamoDB, ErrorHttp, ErrorValidation } from \"../exception\";\n\nimport { EntityConfig } from \"@chinggis/types\";\nimport { CrudService } from \"./crud.service.interface\";\n\nexport abstract class CrudServiceImpl<T extends BaseEntity, D extends BaseRepoDB<T>, S extends BaseRepoES<T>>\n implements CrudService<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(\"repoDB is not an instance of BaseRepoDBImpl\");\n\n if (repoES != null && !(repoES instanceof BaseRepoESImpl))\n console.error(\"repoES is not an instance of BaseRepoESImpl\");\n\n if (repoDB == null && repoES == null) console.error(\"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 async findQuery(queryParams: string): Promise<List<Partial<T>>> {\n const filter = parseIndexFilter(queryParams, this.getIndexMapDB());\n this.checkIsIndexedField(filter);\n return await this.find(filter);\n }\n\n async searchQuery(queryParams: string): Promise<Partial<T>[]> {\n let filter = parseIndexFilter(queryParams);\n filter = this.parseOwnerFields(filter, this.config);\n this.checkIsIndexedField(filter);\n return await this.search(filter);\n }\n\n async incrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T> {\n return await this.repoDB.incrementValueByField(entityId, fieldName, value);\n }\n\n async decrementValueByField(entityId: string, fieldName: string, value?: number): Promise<T> {\n return await this.repoDB.decrementValueByField(entityId, fieldName, value);\n }\n\n async search(filter: Filter): Promise<T[]> {\n const parsedFilter = this.parseOwnerFields(filter, this.config);\n return (await this.repoES.find(parsedFilter)).items as T[];\n }\n\n async searchFieldNotExist(fieldName: string, from: number, size: number): Promise<Partial<T>[]> {\n return await this.repoES.fieldNotExists(fieldName, from, size);\n }\n\n async save(entity: Partial<T>, ownerId: string, parentId?: string, createdByUserId?: string): Promise<T> {\n addDatesAndId(entity);\n\n if (ownerId) {\n entity[this.config.OWNER_ID_FIELD_NAME] = ownerId;\n entity.createdBy = createdByUserId || ownerId;\n }\n if (parentId) entity[this.config.PARENT_ID_FIELD_NAME] = parentId;\n\n return await this.repoDB.save(entity);\n }\n\n async saveAll(\n entities: Partial<T>[],\n ownerId: string,\n parentId?: string,\n createdByUserId?: string,\n isTransactional?: boolean,\n ): Promise<Partial<T>[]> {\n const entitiesUpdated = [];\n\n for (const item of entities) {\n const entity = addDatesAndId(item);\n\n if (parentId) entity[this.config.PARENT_ID_FIELD_NAME] = parentId;\n\n entity[this.config.OWNER_ID_FIELD_NAME] = ownerId;\n entity.createdBy = createdByUserId || ownerId;\n\n entitiesUpdated.push(entity);\n }\n\n return await this.repoDB.saveMany(entitiesUpdated, isTransactional);\n }\n\n async update(entity: T, requestUserId?: string): Promise<T> {\n if (requestUserId) {\n const item = await this.repoDB.findById(entity.id);\n if (\n item[this.config.OWNER_ID_FIELD_NAME] !== requestUserId ||\n item[this.config.PARENT_ID_FIELD_NAME] !== requestUserId\n )\n throw new ErrorHttp({ code: 403, error: \"PermissionDenied\" }, `No permission to resource: ${entity.id}`);\n entity.updatedBy = requestUserId;\n }\n entity = addDates(entity) as T;\n\n // if (!hasPermission(entity, userId, Permission.UPDATE)) throw new Error(\"Unauthorized access\");\n return await this.repoDB.update(entity);\n }\n\n async updateAll(\n entities: Partial<T>[],\n fields: string[],\n requestUserId?: string,\n isTransactional?: boolean,\n ): Promise<boolean> {\n if (requestUserId) log.warn(\"this methode is under development, cannot check ownership by updateAll\");\n\n return await this.repoDB.updateMany(entities, fields, isTransactional);\n }\n\n async remove(entityId: string, ownerId?: string): Promise<boolean> {\n const entity = await this.repoDB.findById(entityId);\n if (!entity) throw new Error(\"Entity not found\");\n\n if (ownerId && entity[this.config.OWNER_ID_FIELD_NAME] !== ownerId) return null;\n\n return await this.repoDB.delete(entityId);\n }\n\n async removeAll(entityIds: string[], ownerId?: string): Promise<boolean> {\n if (ownerId) log.warn(\"this methode is under development, cannot check ownership by removeAll\");\n return await this.repoDB.deleteMany(entityIds);\n }\n\n async changeOwner(entityId: string, ownerId: string): Promise<T> {\n const entity = await this.repoDB.findById(entityId);\n entity[this.config.OWNER_ID_FIELD_NAME] = ownerId;\n return this.repoDB.update(entity);\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 setOpensearch(indexName: string, opensearchEndpoint: string): boolean {\n this.repoES.setIndexName(indexName);\n this.repoES.setEndpoint(opensearchEndpoint);\n return true;\n }\n\n getIndexES(): string {\n return this.repoES.getIndexName();\n }\n\n getIndexMapDB(): DynamoIndexMap {\n return this.repoDB.getIndexMap();\n }\n\n setIndexMapDB(indexMap: DynamoIndexMap): boolean {\n this.repoDB.setIndexMap(indexMap);\n return true;\n }\n\n async findAll(): Promise<T[]> {\n const result: T[] = [];\n\n const filter = parseIndexFilter(\"size=250\");\n\n do {\n const response = await this.repoDB.find(filter);\n result.push(...(response.items as T[]));\n filter.lastKey = response.lastKey;\n } while (filter.lastKey);\n\n return result;\n }\n\n async findAllMatch(filter: Filter): Promise<T[]> {\n this.checkIsIndexedField(filter);\n return await this.fetchAll(filter);\n }\n\n async findAllByIndex(indexName: string, indexValue: any): Promise<T[]> {\n // Create a filter object for validation\n const filter = { indexName: indexName, indexValue: indexValue };\n this.checkIsIndexedField(filter);\n\n const parsedFilter = parseIndexFilter(filter, this.getIndexMapDB());\n return this.fetchAll(parsedFilter);\n }\n\n async findByField(fieldName: string, fieldValue: any): Promise<List<T>> {\n // Create a filter object for validation\n const filter = { [fieldName]: fieldValue, size: 100 };\n this.checkIsIndexedField(filter);\n const parsedFilter = parseIndexFilter(fieldName + \"=\" + fieldValue + \"&size=100\", this.getIndexMapDB());\n return (await this.find(parsedFilter)) as List<T>;\n }\n\n async findFirst(fieldName: string, fieldValue: string | boolean | number | Date): Promise<T> {\n // Validate that the field name exists in the index map\n const filter = { [fieldName]: fieldValue };\n this.checkIsIndexedField(filter);\n\n const result = await this.findByField(fieldName, fieldValue);\n return result.items.length > 0 ? result.items[0] : null;\n }\n\n async find(filter: Filter): Promise<List<Partial<T>>> {\n // Validate that all field names in the filter exist in the index map\n let parsedFilter = this.parseOwnerFields(filter, this.config);\n\n this.checkIsIndexedField(parsedFilter);\n\n parsedFilter = parseIndexFilter(filter, this.getIndexMapDB());\n return await this.repoDB.find(parsedFilter);\n }\n\n async findById(entityId: string, profileId?: string): Promise<T> {\n const entity = await this.repoDB.findById(entityId);\n\n if (entity[this.config.PARENT_ID_FIELD_NAME] == profileId || entity[this.config.OWNER_ID_FIELD_NAME] == profileId) {\n return entity;\n }\n\n return null;\n }\n\n async findByIds(entityIds: string[], profileId?: string): Promise<T[]> {\n if (entityIds.length > 25) throw new ErrorDynamoDB(this.getTableName(), \"findByIds\", \"Too many entities\");\n\n const entities = await this.repoDB.findByIds(entityIds);\n if (!profileId) return entities;\n const ownEntities = [];\n for (const entity of entities) {\n if (\n entity[this.config.PARENT_ID_FIELD_NAME] == profileId ||\n entity[this.config.OWNER_ID_FIELD_NAME] == profileId\n ) {\n ownEntities.push(entity);\n }\n }\n return ownEntities;\n }\n\n async scan(filter: Filter): Promise<List<Partial<T>>> {\n this.checkIsIndexedField(filter);\n const parsedFilter = parseIndexFilter(filter, this.getIndexMapDB());\n return await this.repoDB.scan(parsedFilter);\n }\n\n throwErrorHttp(error: { message: string; code: number }, message?: string, errorContent?: any): void {\n throw new ErrorHttp({ code: error.code, error: error.message }, message, errorContent);\n }\n\n throwErrorDatabase(tableName: string, command: any, errorContent?: any): void {\n throw new ErrorDynamoDB(tableName, command, errorContent);\n }\n\n throwErrorValidation(entityName: string, validation: Map<string, any>, errorContent?: any): void {\n throw new ErrorValidation(entityName, validation, errorContent);\n }\n\n throwError(code: number, message: string, errorContent?: any): void {\n throw new ErrorBase(code, message, errorContent);\n }\n\n setConfig(config: EntityConfig) {\n this.config = config;\n\n this.setTable(config.DYNAMO_DB.NAME, config.DYNAMO_DB.MAP);\n\n this.getIndexMapDB();\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\n /**\n * Validates that all field names in the filter exist in the index map.\n * Throws a Bad Request error if any field is not found in the available indexes.\n *\n * @param filter - The filter object containing field names to validate\n * @throws ErrorHttp with status 400 if validation fails\n */\n private checkIsIndexedField(filter: Filter): void {\n if (!filter || typeof filter !== \"object\") {\n return; // Skip validation for invalid filters\n }\n\n const indexMap = this.getIndexMapDB();\n if (!indexMap || indexMap.size === 0) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"No indexes configured for this table\");\n }\n\n // Get all valid field names from all indexes\n const validFields = new Set<string>();\n\n // Add a partition key\n if (indexMap.partitionKey) {\n validFields.add(indexMap.partitionKey);\n }\n\n // Add fields from all indexes\n for (const [indexName, indexConfig] of indexMap.entries()) {\n if (indexConfig.field) {\n validFields.add(indexConfig.field);\n }\n if (indexConfig.rFields) {\n indexConfig.rFields.forEach((field) => validFields.add(field));\n }\n if (indexConfig.sortKeyField) {\n validFields.add(indexConfig.sortKeyField);\n }\n }\n\n // Check each field in the filter\n const invalidFields: string[] = [];\n for (const fieldName of Object.keys(filter)) {\n // Skip special filter properties that are not field names\n if (\n [\"indexName\", \"indexValue\", \"size\", \"lastKey\", \"fieldsInclude\", \"fieldsExclude\", \"rangeFilters\"].includes(\n fieldName,\n )\n ) {\n continue;\n }\n\n // Skip range filter fields (ageMin, ageMax, etc.)\n const rangeSuffixes = [\"Min\", \"Max\", \"From\", \"To\", \"Start\", \"End\"];\n const isRangeField = rangeSuffixes.some((suffix) => fieldName.endsWith(suffix));\n if (isRangeField) {\n continue;\n }\n\n if (!validFields.has(fieldName)) {\n invalidFields.push(fieldName);\n }\n }\n\n if (invalidFields.length > 0) {\n const availableFields = Array.from(validFields).sort();\n throw new ErrorHttp(\n { code: 400, error: \"Bad Request\" },\n `Invalid field names in filter: ${invalidFields.join(\", \")}. Available fields: ${availableFields.join(\", \")}`,\n );\n }\n }\n\n private async fetchAll(filter: Filter): Promise<T[]> {\n const result: Partial<T>[] = [];\n do {\n const response = await this.repoDB.find(filter);\n result.push(...response.items);\n filter.lastKey = response.lastKey;\n } while (filter.lastKey);\n\n return result as T[];\n }\n\n private parseOwnerFields(filter: Filter, entityConfig: EntityConfig) {\n const parsedFilter = filter;\n if (parsedFilter.ownerParentId && entityConfig.PARENT_ID_FIELD_NAME) {\n parsedFilter[entityConfig.PARENT_ID_FIELD_NAME] = parsedFilter.ownerParentId;\n if (entityConfig.PARENT_ID_FIELD_NAME !== parsedFilter.ownerParentId) delete parsedFilter.ownerParentId;\n }\n\n if (parsedFilter.profileId && entityConfig.OWNER_ID_FIELD_NAME) {\n parsedFilter[entityConfig.OWNER_ID_FIELD_NAME] = parsedFilter.profileId;\n if (entityConfig.OWNER_ID_FIELD_NAME !== parsedFilter.owderId) delete parsedFilter.profileId;\n }\n\n return parsedFilter;\n }\n}\n"]}
|
|
@@ -30,6 +30,7 @@ const parseHttpRequest = (event, adminGroupNames) => {
|
|
|
30
30
|
const isParent = identity?.["custom:isParent"] === "1";
|
|
31
31
|
const userId = identity?.sub || "";
|
|
32
32
|
let profileId = identity?.profile || username;
|
|
33
|
+
const parentId = identity?.["custom:parentId"];
|
|
33
34
|
const adminGroups = new Set((0, string_util_1.normalizeLower)((0, string_util_1.toArray)(adminGroupNames)));
|
|
34
35
|
const groups = (0, string_util_1.normalizeLower)((0, string_util_1.toArray)(groupsCognito));
|
|
35
36
|
const isAdmin = groups.some((g) => adminGroups.has(g));
|
|
@@ -56,6 +57,7 @@ const parseHttpRequest = (event, adminGroupNames) => {
|
|
|
56
57
|
? {
|
|
57
58
|
...identity,
|
|
58
59
|
isParent,
|
|
60
|
+
parentId,
|
|
59
61
|
Authorization: event?.headers?.Authorization,
|
|
60
62
|
identityId: event && "x-cognito-identity-id" in event.headers ? event.headers["x-cognito-identity-id"] : undefined,
|
|
61
63
|
}
|
|
@@ -71,9 +73,11 @@ const parseHttpRequest = (event, adminGroupNames) => {
|
|
|
71
73
|
headers: { ...event?.headers },
|
|
72
74
|
};
|
|
73
75
|
if (isParent)
|
|
74
|
-
parsedParams.filter["
|
|
75
|
-
else
|
|
76
|
+
parsedParams.filter["ownerParentId"] = profileId;
|
|
77
|
+
else {
|
|
76
78
|
parsedParams.filter["profileId"] = profileId;
|
|
79
|
+
parsedParams.filter["ownerParentId"] = parentId;
|
|
80
|
+
}
|
|
77
81
|
if (event?.body)
|
|
78
82
|
parsedParams.body = typeof event.body === "string" ? JSON.parse(event.body) : event.body;
|
|
79
83
|
return parsedParams;
|