arkos 1.6.5-beta → 1.6.6-beta
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/cjs/exports/index.js +3 -1
- package/dist/cjs/exports/index.js.map +1 -1
- package/dist/cjs/modules/email/email.service.js +13 -7
- package/dist/cjs/modules/email/email.service.js.map +1 -1
- package/dist/cjs/modules/error-handler/error-handler.controller.js +4 -3
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +9 -2
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/cjs/modules/swagger/swagger.router.js +40 -9
- package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/openapi-schema-converter.js +4 -2
- package/dist/cjs/modules/swagger/utils/helpers/openapi-schema-converter.js.map +1 -1
- package/dist/cjs/types/arkos.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/new-arkos-config.js.map +1 -1
- package/dist/cjs/types/upload.js +3 -0
- package/dist/cjs/types/upload.js.map +1 -0
- package/dist/cjs/utils/arkos-router/arkos-router-openapi-manager.js +3 -9
- package/dist/cjs/utils/arkos-router/arkos-router-openapi-manager.js.map +1 -1
- package/dist/cjs/utils/arkos-router/index.js +15 -3
- package/dist/cjs/utils/arkos-router/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/types/index.js.map +1 -1
- package/dist/cjs/utils/arkos-router/utils/helpers/upload-manager.js +5 -0
- package/dist/cjs/utils/arkos-router/utils/helpers/upload-manager.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js +53 -17
- package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/zod-schema-generator.js +18 -18
- package/dist/cjs/utils/cli/utils/template-generator/templates/zod-schema-generator.js.map +1 -1
- package/dist/cjs/utils/features/api.features.js.map +1 -1
- package/dist/cjs/utils/helpers/arkos-config.helpers.js.map +1 -1
- package/dist/esm/exports/index.js +2 -1
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/modules/email/email.service.js +13 -7
- package/dist/esm/modules/email/email.service.js.map +1 -1
- package/dist/esm/modules/error-handler/error-handler.controller.js +4 -3
- package/dist/esm/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.router.js +9 -2
- package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/esm/modules/swagger/swagger.router.js +7 -9
- package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/openapi-schema-converter.js +4 -2
- package/dist/esm/modules/swagger/utils/helpers/openapi-schema-converter.js.map +1 -1
- package/dist/esm/types/arkos.js.map +1 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/new-arkos-config.js.map +1 -1
- package/dist/esm/types/upload.js +2 -0
- package/dist/esm/types/upload.js.map +1 -0
- package/dist/esm/utils/arkos-router/arkos-router-openapi-manager.js +3 -9
- package/dist/esm/utils/arkos-router/arkos-router-openapi-manager.js.map +1 -1
- package/dist/esm/utils/arkos-router/index.js +15 -3
- package/dist/esm/utils/arkos-router/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/types/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/utils/helpers/upload-manager.js +5 -0
- package/dist/esm/utils/arkos-router/utils/helpers/upload-manager.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js +53 -17
- package/dist/esm/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/zod-schema-generator.js +18 -18
- package/dist/esm/utils/cli/utils/template-generator/templates/zod-schema-generator.js.map +1 -1
- package/dist/esm/utils/features/api.features.js.map +1 -1
- package/dist/esm/utils/helpers/arkos-config.helpers.js.map +1 -1
- package/dist/types/exports/index.d.ts +3 -1
- package/dist/types/types/arkos.d.ts +1 -1
- package/dist/types/types/index.d.ts +5 -5
- package/dist/types/types/new-arkos-config.d.ts +1 -1
- package/dist/types/types/upload.d.ts +10 -0
- package/dist/types/utils/arkos-router/types/index.d.ts +15 -14
- package/dist/types/utils/arkos-router/utils/helpers/upload-manager.d.ts +1 -0
- package/dist/types/utils/cli/utils/template-generator/templates/class-validator-dto-generator.d.ts +7 -0
- package/dist/types/utils/features/api.features.d.ts +1 -2
- package/dist/types/utils/helpers/arkos-config.helpers.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-schema-generator.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/zod-schema-generator.ts"],"names":[],"mappings":";;;;;;AAAA,mGAAyE;AAEzE,+DAAsE;AAEtE,mFAA0E;AAE1E,MAAa,kBAAkB;IACrB,oBAAoB,CAAC,OAAwB;QACnD,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAC9B,IAAI,CAAC,SAAS;YACZ,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,MAAM,KAAK,GAAG,8BAAkB,CAAC,MAAM,CAAC,IAAI,CAC1C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAC/D,CAAC;QACF,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,KAAK,CAAC,SAAS,SAAS,CAAC,MAAM,6BAA6B,CAAC,CAAC;QAC1E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oBAAoB,CAAC,OAAwB;QAC3C,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAC9B,MAAM,KAAK,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AAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAC3D,YAAY,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,WAAW,GACf,SAAS,CAAC,IAAI,GAAG,CAAC;YAChB,CAAC,CAAC,YAAY,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,6BAA6B;YAC3E,CAAC,CAAC,EAAE,CAAC;QAET,MAAM,UAAU,GAAG,YAAY;YAC7B,CAAC,CAAC,sEAAsE;YACxE,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO;EACT,WAAW;;EAEX,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC;;;gCAGM,UAAU;CACzC,CAAC;IACA,CAAC;IAED,4BAA4B,CAAC,CAAkB;QAC7C,MAAM,GAAG,GAAG,IAAA,iCAAoB,GAAE,CAAC;QACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;QAElC,MAAM,UAAU,GAAG,YAAY;YAC7B,CAAC,CAAC,kFAAkF;YACpF,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO;;;;;;;sCAO2B,UAAU;CAC/C,CAAC;IACA,CAAC;CACF;AApsBD,gDAosBC;AAED,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAEpD,kBAAe,kBAAkB,CAAC","sourcesContent":["import prismaSchemaParser from \"../../../../prisma/prisma-schema-parser\";\nimport { PrismaField } from \"../../../../prisma/types\";\nimport { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\nimport { getArkosConfig } from \"../../../../helpers/arkos-config.helpers\";\n\nexport class ZodSchemaGenerator {\n private ensureCorrectOptions(options: TemplateOptions) {\n const { modelName } = options;\n if (!modelName)\n throw new Error(\"Module name is required for schema template\");\n const model = prismaSchemaParser.models.find(\n (m) => m.name.toLowerCase() === modelName.pascal.toLowerCase()\n );\n if (!model)\n throw new Error(`Model ${modelName.pascal} not found in Prisma schema`);\n return model;\n }\n\n generateCreateSchema(options: TemplateOptions): string {\n const { modelName } = options;\n const model = this.ensureCorrectOptions(options);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const restrictedFields = [\n \"id\",\n \"createdAt\",\n \"updatedAt\",\n \"deletedAt\",\n \"created_at\",\n \"updated_at\",\n \"deleted_at\",\n ];\n const isUserModule = modelName!.kebab === \"user\";\n const enumsUsed = new Set<string>();\n\n let schemaFields: string[] = [];\n\n for (const field of model.fields) {\n const isForeignKey = model.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n\n if (field.isCompositeType) {\n const compositeType = prismaSchemaParser.compositeTypes.find(\n (t) => t.name === field.type\n )!;\n const fields = compositeType.fields\n .map(\n (f) =>\n ` ${f.name}: ${this.mapPrismaTypeToZod(f.type)}${f.isOptional ? \".optional()\" : \"\"}`\n )\n .join(\",\\n\");\n const zodObj = `z.object({\\n${fields}\\n })`;\n const isOptional = field.isOptional || field.defaultValue !== undefined;\n schemaFields.push(\n ` ${field.name}: ${field.isArray ? `z.array(${zodObj})` : zodObj}${isOptional ? \".optional()\" : \"\"}`\n );\n continue;\n }\n\n if (field.isRelation) {\n if (field.isArray) continue;\n\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n let zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n if (\n refFieldType?.type?.toLowerCase?.() === \"string\" ||\n !refFieldType?.type\n )\n zodType = zodType + \".min(1)\";\n const isOptional =\n field.isOptional || field.defaultValue !== undefined;\n schemaFields.push(\n ` ${field.name}: z.object({ ${refField}: ${zodType} })${isOptional ? \".optional()\" : \"\"}`\n );\n }\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) enumsUsed.add(field.type);\n\n const zodSchema = this.generateZodField(field, isUserModule, false);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type Create${modelName!.pascal}SchemaType = z.infer<typeof Create${modelName!.pascal}Schema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst Create${modelName!.pascal}Schema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default Create${modelName!.pascal}Schema;${typeExport}\n`;\n }\n\n generateUpdateSchema(options: TemplateOptions): string {\n const { modelName } = options;\n const model = this.ensureCorrectOptions(options);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const restrictedFields = [\"id\", \"createdAt\", \"updatedAt\", \"deletedAt\"];\n const isUserModule = modelName!.kebab === \"user\";\n const enumsUsed = new Set<string>();\n\n let schemaFields: string[] = [];\n\n for (const field of model.fields) {\n const isForeignKey = model.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n\n if (field.isCompositeType) {\n const compositeType = prismaSchemaParser.compositeTypes.find(\n (t) => t.name === field.type\n )!;\n const fields = compositeType.fields\n .map(\n (f) =>\n ` ${f.name}: ${this.mapPrismaTypeToZod(f.type)}${f.isOptional ? \".optional()\" : \"\"}`\n )\n .join(\",\\n\");\n const zodObj = `z.object({\\n${fields}\\n })`;\n schemaFields.push(\n ` ${field.name}: ${field.isArray ? `z.array(${zodObj})` : zodObj}.optional()`\n );\n continue;\n }\n\n if (field.isRelation) {\n if (field.isArray) continue;\n\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n let zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n if (\n refFieldType?.type?.toLowerCase?.() === \"string\" ||\n !refFieldType?.type\n )\n zodType = zodType + \".min(1)\";\n\n schemaFields.push(\n ` ${field.name}: z.object({ ${refField}: ${zodType} }).optional()`\n );\n }\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n }\n\n const zodSchema = this.generateZodField(field, isUserModule, true);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type Update${modelName!.pascal}SchemaType = z.infer<typeof Update${modelName!.pascal}Schema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst Update${modelName!.pascal}Schema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default Update${modelName!.pascal}Schema;${typeExport}\n`;\n }\n\n generateBaseSchema(options: TemplateOptions): string {\n const { modelName } = options;\n const model = this.ensureCorrectOptions(options);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const isUserModule = modelName!.kebab === \"user\";\n const enumsUsed = new Set<string>();\n\n let schemaFields: string[] = [];\n\n for (const field of model.fields) {\n if (isUserModule && field.name === \"password\") {\n continue;\n }\n\n if (field.isRelation) {\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n }\n\n const zodSchema = this.generateZodField(field, isUserModule, false);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type ${modelName!.pascal}SchemaType = z.infer<typeof ${modelName!.pascal}Schema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst ${modelName!.pascal}Schema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default ${modelName!.pascal}Schema;${typeExport}\n`;\n }\n\n generateQuerySchema(options: TemplateOptions): string {\n const { modelName } = options;\n const model = this.ensureCorrectOptions(options);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const isUserModule = modelName!.kebab === \"user\";\n const enumsUsed = new Set<string>();\n const filterSchemasNeeded = new Set<string>();\n const restrictedFields = [\"id\"];\n const timestampFields = [\n \"createdAt\",\n \"updatedAt\",\n \"deletedAt\",\n \"created_at\",\n \"updated_at\",\n \"deleted_at\",\n ];\n\n let schemaFields: string[] = [];\n let timestampSchemaFields: string[] = [];\n\n schemaFields.push(` page: z.coerce.number().optional()`);\n schemaFields.push(` limit: z.coerce.number().max(100).optional()`);\n schemaFields.push(` sort: z.string().optional()`);\n schemaFields.push(` fields: z.string().optional()`);\n\n for (const field of model.fields) {\n if (isUserModule && field.name === \"password\") continue;\n if (restrictedFields.includes(field.name)) continue;\n\n const isForeignKey = model.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (isForeignKey) continue;\n\n if (field.isRelation) {\n if (field.isArray) continue;\n\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n const zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n\n const fieldDef = ` ${field.name}: z.object({ ${refField}: ${zodType}.optional() }).optional()`;\n\n if (timestampFields.includes(field.name)) {\n timestampSchemaFields.push(fieldDef);\n } else {\n schemaFields.push(fieldDef);\n }\n }\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n const fieldDef = ` ${field.name}: z.nativeEnum(${field.type}).optional()`;\n\n if (timestampFields.includes(field.name)) {\n timestampSchemaFields.push(fieldDef);\n } else {\n schemaFields.push(fieldDef);\n }\n continue;\n }\n\n if (field.type === \"Boolean\") {\n const fieldDef = ` ${field.name}: z.boolean().optional()`;\n\n if (timestampFields.includes(field.name)) {\n timestampSchemaFields.push(fieldDef);\n } else {\n schemaFields.push(fieldDef);\n }\n continue;\n }\n\n const filterSchemaName = this.getFilterSchemaForField(field, enumsUsed);\n if (filterSchemaName) {\n filterSchemasNeeded.add(filterSchemaName);\n const fieldDef = ` ${field.name}: ${filterSchemaName}.optional()`;\n\n if (timestampFields.includes(field.name)) {\n timestampSchemaFields.push(fieldDef);\n } else {\n schemaFields.push(fieldDef);\n }\n }\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const filterSchemas = this.generateFilterSchemas(\n filterSchemasNeeded,\n enumsUsed\n );\n\n const filterSchemasSection = filterSchemas ? `\\n${filterSchemas}\\n` : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type Query${modelName!.pascal}SchemaType = z.infer<typeof Query${modelName!.pascal}Schema>;`\n : \"\";\n\n const allFields = [...schemaFields, ...timestampSchemaFields];\n\n return `import { z } from \"zod\";\n${enumImports}${filterSchemasSection}\nconst Query${modelName!.pascal}Schema = z.object({\n${allFields.join(\",\\n\")}\n});\n\nexport default Query${modelName!.pascal}Schema;${typeExport}\n`;\n }\n\n private getFilterSchemaForField(\n field: PrismaField,\n enumsUsed: Set<string>\n ): string | null {\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n return `${field.type}FilterSchema`;\n }\n\n switch (field.type) {\n case \"String\":\n return \"StringFilterSchema\";\n case \"Int\":\n case \"Float\":\n case \"Decimal\":\n case \"BigInt\":\n return \"NumberFilterSchema\";\n case \"DateTime\":\n return \"DateTimeFilterSchema\";\n default:\n return null;\n }\n }\n\n private generateFilterSchemas(\n filterSchemasNeeded: Set<string>,\n _: Set<string>\n ): string {\n const schemas: string[] = [];\n\n if (filterSchemasNeeded.has(\"StringFilterSchema\")) {\n schemas.push(`const StringFilterSchema = z.object({\n icontains: z.string().optional()\n});`);\n }\n\n if (filterSchemasNeeded.has(\"NumberFilterSchema\")) {\n schemas.push(`const NumberFilterSchema = z.object({\n equals: z.coerce.number().optional(),\n gte: z.coerce.number().optional(),\n lte: z.coerce.number().optional()\n});`);\n }\n\n if (filterSchemasNeeded.has(\"DateTimeFilterSchema\")) {\n schemas.push(`const DateTimeFilterSchema = z.object({\n equals: z.string().optional(),\n gte: z.string().optional(),\n lte: z.string().optional()\n});`);\n }\n\n return schemas.join(\"\\n\\n\");\n }\n\n private generateZodField(\n field: PrismaField,\n isUserModule: boolean,\n forceOptional: boolean\n ): string {\n let zodType = this.mapPrismaTypeToZod(field.type);\n\n if (field.isArray)\n zodType = `z.array(${zodType}${field.type === \"String\" ? \".min(1)\" : \"\"})`;\n\n if (prismaSchemaParser.isEnum(field.type))\n zodType = field.isArray\n ? `z.array(z.nativeEnum(${field.type}))`\n : `z.nativeEnum(${field.type})`;\n\n if (isUserModule) {\n if (field.name === \"email\") {\n zodType = `z.string().email()`;\n } else if (field.name === \"password\") {\n zodType = `z.string().min(8).regex(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\\\d)/, \"Password must contain at least one uppercase letter, one lowercase letter, and one number\")`;\n }\n }\n\n const isOptional =\n forceOptional || field.isOptional || field.defaultValue !== undefined;\n if (isOptional) zodType += \".optional()\";\n\n return zodType;\n }\n\n private mapPrismaTypeToZod(prismaType: string): string {\n switch (prismaType) {\n case \"String\":\n return \"z.string()\";\n case \"Int\":\n case \"Float\":\n case \"Decimal\":\n return \"z.number()\";\n case \"Boolean\":\n return \"z.boolean()\";\n case \"DateTime\":\n return \"z.date().or(z.string()).refine((val) => val instanceof Date || !isNaN(Date.parse(val)), 'Invalid date')\";\n case \"Json\":\n return \"z.any()\";\n case \"Bytes\":\n return \"z.instanceof(Buffer)\";\n case \"BigInt\":\n return \"z.bigint()\";\n default:\n if (\n prismaSchemaParser.compositeTypes.some((t) => t.name === prismaType)\n ) {\n const compositeType = prismaSchemaParser.compositeTypes.find(\n (t) => t.name === prismaType\n )!;\n const fields = compositeType.fields\n .map(\n (f) =>\n `${f.name}: ${this.mapPrismaTypeToZod(f.type)}${f.isOptional ? \".optional()\" : \"\"}`\n )\n .join(\", \");\n return `z.object({ ${fields} })`;\n }\n return \"z.any()\";\n }\n }\n\n generateLoginSchema(_: TemplateOptions): string {\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const allowedUsernames = getArkosConfig()?.authentication?.login\n ?.allowedUsernames || [\"username\"];\n\n const usernameFields = allowedUsernames.map((field: string) => {\n const displayName = field.includes(\".\") ? field.split(\".\").pop()! : field;\n const zodType =\n displayName === \"email\" ? \"z.string().email()\" : \"z.string().min(1)\";\n return ` ${displayName}: ${zodType}.optional()`;\n });\n\n const anyOfComment =\n allowedUsernames.length > 1\n ? `\\n// At least one of: ${allowedUsernames.map((f: string) => (f.includes(\".\") ? f.split(\".\").pop() : f)).join(\", \")} is required`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type LoginSchemaType = z.infer<typeof LoginSchema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${anyOfComment}\nconst LoginSchema = z.object({\n${usernameFields.join(\",\\n\")},\n password: z.string().min(8)\n});\n\nexport default LoginSchema;${typeExport}\n`;\n }\n\n generateSignupSchema(_: TemplateOptions): string {\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n const userModel = prismaSchemaParser.models.find(\n (m) => m.name.toLowerCase() === \"user\"\n );\n if (!userModel) throw new Error(\"User model not found in Prisma schema\");\n\n const restrictedFields = [\n \"id\",\n \"createdAt\",\n \"updatedAt\",\n \"deletedAt\",\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"lastLoginAt\",\n ];\n\n const enumsUsed = new Set<string>();\n const schemaFields: string[] = [];\n\n for (const field of userModel.fields) {\n const isForeignKey = userModel.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n if (field.isRelation) {\n if (field.isArray) continue;\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n let zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n if (\n refFieldType?.type?.toLowerCase?.() === \"string\" ||\n !refFieldType?.type\n )\n zodType = zodType + \".min(1)\";\n const isOptional =\n field.isOptional || field.defaultValue !== undefined;\n schemaFields.push(\n ` ${field.name}: z.object({ ${refField}: ${zodType} })${isOptional ? \".optional()\" : \"\"}`\n );\n }\n continue;\n }\n if (prismaSchemaParser.isEnum(field.type)) enumsUsed.add(field.type);\n const zodSchema =\n field.name === \"password\"\n ? `z.string().min(8).regex(/[a-z]/, \"Must contain lowercase\").regex(/[A-Z]/, \"Must contain uppercase\").regex(/[0-9]/, \"Must contain number\")`\n : this.generateZodField(field, true, false);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type SignupSchemaType = z.infer<typeof SignupSchema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst SignupSchema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default SignupSchema;${typeExport}\n`;\n }\n\n generateUpdateMeSchema(_: TemplateOptions): string {\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n const userModel = prismaSchemaParser.models.find(\n (m) => m.name.toLowerCase() === \"user\"\n );\n if (!userModel) throw new Error(\"User model not found in Prisma schema\");\n\n const restrictedFields = [\n \"id\",\n \"createdAt\",\n \"updatedAt\",\n \"deletedAt\",\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"lastLoginAt\",\n \"password\",\n ];\n\n const enumsUsed = new Set<string>();\n const schemaFields: string[] = [];\n\n for (const field of userModel.fields) {\n const isForeignKey = userModel.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n if (field.isRelation) {\n if (field.isArray) continue;\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n let zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n if (\n refFieldType?.type?.toLowerCase?.() === \"string\" ||\n !refFieldType?.type\n )\n zodType = zodType + \".min(1)\";\n schemaFields.push(\n ` ${field.name}: z.object({ ${refField}: ${zodType} }).optional()`\n );\n }\n continue;\n }\n if (prismaSchemaParser.isEnum(field.type)) enumsUsed.add(field.type);\n const zodSchema = this.generateZodField(field, true, true);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type UpdateMeSchemaType = z.infer<typeof UpdateMeSchema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst UpdateMeSchema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default UpdateMeSchema;${typeExport}\n`;\n }\n\n generateUpdatePasswordSchema(_: TemplateOptions): string {\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type UpdatePasswordSchemaType = z.infer<typeof UpdatePasswordSchema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n\nconst UpdatePasswordSchema = z.object({\n currentPassword: z.string().min(1),\n newPassword: z.string().min(8).regex(/[a-z]/, \"Must contain lowercase\").regex(/[A-Z]/, \"Must contain uppercase\").regex(/[0-9]/, \"Must contain number\")\n});\n\nexport default UpdatePasswordSchema;${typeExport}\n`;\n }\n}\n\nconst zodSchemaGenerator = new ZodSchemaGenerator();\n\nexport default zodSchemaGenerator;\n"]}
|
|
1
|
+
{"version":3,"file":"zod-schema-generator.js","sourceRoot":"","sources":["../../../../../../../src/utils/cli/utils/template-generator/templates/zod-schema-generator.ts"],"names":[],"mappings":";;;;;;AAAA,mGAAyE;AAEzE,+DAAsE;AAEtE,mFAA0E;AAE1E,MAAa,kBAAkB;IACrB,oBAAoB,CAAC,OAAwB;QACnD,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAC9B,IAAI,CAAC,SAAS;YACZ,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,MAAM,KAAK,GAAG,8BAAkB,CAAC,MAAM,CAAC,IAAI,CAC1C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAC/D,CAAC;QACF,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,KAAK,CAAC,SAAS,SAAS,CAAC,MAAM,6BAA6B,CAAC,CAAC;QAC1E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oBAAoB,CAAC,OAAwB;QAC3C,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEjD,MAAM,GAAG,GAAG,IAAA,iCAAoB,GAAE,CAAC;QACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;QAClC,MAAM,gBAAgB,GAAG;YACvB,IAAI;YACJ,WAAW;YACX,WAAW;YACX,WAAW;YACX,YAAY;YACZ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AAG,CAAC;YAChB,CAAC,CAAC,YAAY,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,6BAA6B;YAC3E,CAAC,CAAC,EAAE,CAAC;QAET,MAAM,UAAU,GAAG,YAAY;YAC7B,CAAC,CAAC,sEAAsE;YACxE,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO;EACT,WAAW;;EAEX,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC;;;gCAGM,UAAU;CACzC,CAAC;IACA,CAAC;IAED,4BAA4B,CAAC,CAAkB;QAC7C,MAAM,GAAG,GAAG,IAAA,iCAAoB,GAAE,CAAC;QACnC,MAAM,YAAY,GAAG,GAAG,KAAK,IAAI,CAAC;QAElC,MAAM,UAAU,GAAG,YAAY;YAC7B,CAAC,CAAC,kFAAkF;YACpF,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO;;;;;;;sCAO2B,UAAU;CAC/C,CAAC;IACA,CAAC;CACF;AApsBD,gDAosBC;AAED,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAEpD,kBAAe,kBAAkB,CAAC","sourcesContent":["import prismaSchemaParser from \"../../../../prisma/prisma-schema-parser\";\nimport { PrismaField } from \"../../../../prisma/types\";\nimport { getUserFileExtension } from \"../../../../helpers/fs.helpers\";\nimport { TemplateOptions } from \"../../template-generators\";\nimport { getArkosConfig } from \"../../../../helpers/arkos-config.helpers\";\n\nexport class ZodSchemaGenerator {\n private ensureCorrectOptions(options: TemplateOptions) {\n const { modelName } = options;\n if (!modelName)\n throw new Error(\"Module name is required for schema template\");\n const model = prismaSchemaParser.models.find(\n (m) => m.name.toLowerCase() === modelName.pascal.toLowerCase()\n );\n if (!model)\n throw new Error(`Model ${modelName.pascal} not found in Prisma schema`);\n return model;\n }\n\n generateCreateSchema(options: TemplateOptions): string {\n const { modelName } = options;\n const model = this.ensureCorrectOptions(options);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const restrictedFields = [\n \"id\",\n \"createdAt\",\n \"updatedAt\",\n \"deletedAt\",\n \"created_at\",\n \"updated_at\",\n \"deleted_at\",\n ];\n const isUserModule = modelName!.kebab === \"user\";\n const enumsUsed = new Set<string>();\n\n let schemaFields: string[] = [];\n\n for (const field of model.fields) {\n const isForeignKey = model.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n\n if (field.isCompositeType) {\n const compositeType = prismaSchemaParser.compositeTypes.find(\n (t) => t.name === field.type\n )!;\n const fields = compositeType.fields\n .map(\n (f) =>\n ` ${f.name}: ${this.mapPrismaTypeToZod(f.type)}${f.isOptional ? \".optional()\" : \"\"}`\n )\n .join(\",\\n\");\n const zodObj = `z.object({\\n${fields}\\n })`;\n const isOptional = field.isOptional || field.defaultValue !== undefined;\n schemaFields.push(\n ` ${field.name}: ${field.isArray ? `z.array(${zodObj})` : zodObj}${isOptional ? \".optional()\" : \"\"}`\n );\n continue;\n }\n\n if (field.isRelation) {\n if (field.isArray) continue;\n\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n let zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n if (\n refFieldType?.type?.toLowerCase?.() === \"string\" ||\n !refFieldType?.type\n )\n zodType = zodType + \".min(1)\";\n const isOptional =\n field.isOptional || field.defaultValue !== undefined;\n schemaFields.push(\n ` ${field.name}: z.object({ ${refField}: ${zodType} })${isOptional ? \".optional()\" : \"\"}`\n );\n }\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) enumsUsed.add(field.type);\n\n const zodSchema = this.generateZodField(field, isUserModule, false);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type Create${modelName!.pascal}Schema = z.infer<typeof Create${modelName!.pascal}Schema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst Create${modelName!.pascal}Schema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default Create${modelName!.pascal}Schema;${typeExport}\n`;\n }\n\n generateUpdateSchema(options: TemplateOptions): string {\n const { modelName } = options;\n const model = this.ensureCorrectOptions(options);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const restrictedFields = [\"id\", \"createdAt\", \"updatedAt\", \"deletedAt\"];\n const isUserModule = modelName!.kebab === \"user\";\n const enumsUsed = new Set<string>();\n\n let schemaFields: string[] = [];\n\n for (const field of model.fields) {\n const isForeignKey = model.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n\n if (field.isCompositeType) {\n const compositeType = prismaSchemaParser.compositeTypes.find(\n (t) => t.name === field.type\n )!;\n const fields = compositeType.fields\n .map(\n (f) =>\n ` ${f.name}: ${this.mapPrismaTypeToZod(f.type)}${f.isOptional ? \".optional()\" : \"\"}`\n )\n .join(\",\\n\");\n const zodObj = `z.object({\\n${fields}\\n })`;\n schemaFields.push(\n ` ${field.name}: ${field.isArray ? `z.array(${zodObj})` : zodObj}.optional()`\n );\n continue;\n }\n\n if (field.isRelation) {\n if (field.isArray) continue;\n\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n let zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n if (\n refFieldType?.type?.toLowerCase?.() === \"string\" ||\n !refFieldType?.type\n )\n zodType = zodType + \".min(1)\";\n\n schemaFields.push(\n ` ${field.name}: z.object({ ${refField}: ${zodType} }).optional()`\n );\n }\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n }\n\n const zodSchema = this.generateZodField(field, isUserModule, true);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type Update${modelName!.pascal}Schema = z.infer<typeof Update${modelName!.pascal}Schema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst Update${modelName!.pascal}Schema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default Update${modelName!.pascal}Schema;${typeExport}\n`;\n }\n\n generateBaseSchema(options: TemplateOptions): string {\n const { modelName } = options;\n const model = this.ensureCorrectOptions(options);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const isUserModule = modelName!.kebab === \"user\";\n const enumsUsed = new Set<string>();\n\n let schemaFields: string[] = [];\n\n for (const field of model.fields) {\n if (isUserModule && field.name === \"password\") {\n continue;\n }\n\n if (field.isRelation) {\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n }\n\n const zodSchema = this.generateZodField(field, isUserModule, false);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type ${modelName!.pascal}Schema = z.infer<typeof ${modelName!.pascal}Schema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst ${modelName!.pascal}Schema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default ${modelName!.pascal}Schema;${typeExport}\n`;\n }\n\n generateQuerySchema(options: TemplateOptions): string {\n const { modelName } = options;\n const model = this.ensureCorrectOptions(options);\n\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const isUserModule = modelName!.kebab === \"user\";\n const enumsUsed = new Set<string>();\n const filterSchemasNeeded = new Set<string>();\n const restrictedFields = [\"id\"];\n const timestampFields = [\n \"createdAt\",\n \"updatedAt\",\n \"deletedAt\",\n \"created_at\",\n \"updated_at\",\n \"deleted_at\",\n ];\n\n let schemaFields: string[] = [];\n let timestampSchemaFields: string[] = [];\n\n schemaFields.push(` page: z.coerce.number().optional()`);\n schemaFields.push(` limit: z.coerce.number().max(100).optional()`);\n schemaFields.push(` sort: z.coerce.string().optional()`);\n schemaFields.push(` fields: z.coerce.string().optional()`);\n\n for (const field of model.fields) {\n if (isUserModule && field.name === \"password\") continue;\n if (restrictedFields.includes(field.name)) continue;\n\n const isForeignKey = model.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (isForeignKey) continue;\n\n if (field.isRelation) {\n if (field.isArray) continue;\n\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n const zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n\n const fieldDef = ` ${field.name}: z.object({ ${refField}: ${zodType}.optional() }).optional()`;\n\n if (timestampFields.includes(field.name)) {\n timestampSchemaFields.push(fieldDef);\n } else {\n schemaFields.push(fieldDef);\n }\n }\n continue;\n }\n\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n const fieldDef = ` ${field.name}: z.nativeEnum(${field.type}).optional()`;\n\n if (timestampFields.includes(field.name)) {\n timestampSchemaFields.push(fieldDef);\n } else {\n schemaFields.push(fieldDef);\n }\n continue;\n }\n\n if (field.type === \"Boolean\") {\n const fieldDef = ` ${field.name}: z.coerce.boolean().optional()`;\n\n if (timestampFields.includes(field.name)) {\n timestampSchemaFields.push(fieldDef);\n } else {\n schemaFields.push(fieldDef);\n }\n continue;\n }\n\n const filterSchemaName = this.getFilterSchemaForField(field, enumsUsed);\n if (filterSchemaName) {\n filterSchemasNeeded.add(filterSchemaName);\n const fieldDef = ` ${field.name}: ${filterSchemaName}.optional()`;\n\n if (timestampFields.includes(field.name)) {\n timestampSchemaFields.push(fieldDef);\n } else {\n schemaFields.push(fieldDef);\n }\n }\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const filterSchemas = this.generateFilterSchemas(\n filterSchemasNeeded,\n enumsUsed\n );\n\n const filterSchemasSection = filterSchemas ? `\\n${filterSchemas}\\n` : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type Query${modelName!.pascal}Schema = z.infer<typeof Query${modelName!.pascal}Schema>;`\n : \"\";\n\n const allFields = [...schemaFields, ...timestampSchemaFields];\n\n return `import { z } from \"zod\";\n${enumImports}${filterSchemasSection}\nconst Query${modelName!.pascal}Schema = z.object({\n${allFields.join(\",\\n\")}\n});\n\nexport default Query${modelName!.pascal}Schema;${typeExport}\n`;\n }\n\n private getFilterSchemaForField(\n field: PrismaField,\n enumsUsed: Set<string>\n ): string | null {\n if (prismaSchemaParser.isEnum(field.type)) {\n enumsUsed.add(field.type);\n return `${field.type}FilterSchema`;\n }\n\n switch (field.type) {\n case \"String\":\n return \"StringFilterSchema\";\n case \"Int\":\n case \"Float\":\n case \"Decimal\":\n case \"BigInt\":\n return \"NumberFilterSchema\";\n case \"DateTime\":\n return \"DateTimeFilterSchema\";\n default:\n return null;\n }\n }\n\n private generateFilterSchemas(\n filterSchemasNeeded: Set<string>,\n _: Set<string>\n ): string {\n const schemas: string[] = [];\n\n if (filterSchemasNeeded.has(\"StringFilterSchema\")) {\n schemas.push(`const StringFilterSchema = z.object({\n icontains: z.coerce.string().optional()\n});`);\n }\n\n if (filterSchemasNeeded.has(\"NumberFilterSchema\")) {\n schemas.push(`const NumberFilterSchema = z.object({\n equals: z.coerce.number().optional(),\n gte: z.coerce.number().optional(),\n lte: z.coerce.number().optional()\n});`);\n }\n\n if (filterSchemasNeeded.has(\"DateTimeFilterSchema\")) {\n schemas.push(`const DateTimeFilterSchema = z.object({\n equals: z.coerce.string().optional(),\n gte: z.coerce.string().optional(),\n lte: z.coerce.string().optional()\n});`);\n }\n\n return schemas.join(\"\\n\\n\");\n }\n\n private generateZodField(\n field: PrismaField,\n isUserModule: boolean,\n forceOptional: boolean\n ): string {\n let zodType = this.mapPrismaTypeToZod(field.type);\n\n if (field.isArray)\n zodType = `z.array(${zodType}${field.type === \"String\" ? \".min(1)\" : \"\"})`;\n\n if (prismaSchemaParser.isEnum(field.type))\n zodType = field.isArray\n ? `z.array(z.nativeEnum(${field.type}))`\n : `z.nativeEnum(${field.type})`;\n\n if (isUserModule) {\n if (field.name === \"email\") {\n zodType = `z.coerce.string().email()`;\n } else if (field.name === \"password\") {\n zodType = `z.coerce.string().min(8).regex(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\\\d)/, \"Password must contain at least one uppercase letter, one lowercase letter, and one number\")`;\n }\n }\n\n const isOptional =\n forceOptional || field.isOptional || field.defaultValue !== undefined;\n if (isOptional) zodType += \".optional()\";\n\n return zodType;\n }\n\n private mapPrismaTypeToZod(prismaType: string): string {\n switch (prismaType) {\n case \"String\":\n return \"z.coerce.string()\";\n case \"Int\":\n case \"Float\":\n case \"Decimal\":\n return \"z.coerce.number()\";\n case \"Boolean\":\n return \"z.coerce.boolean()\";\n case \"DateTime\":\n return \"z.coerce.date().or(z.coerce.string()).refine((val) => val instanceof Date || !isNaN(Date.parse(val)), 'Invalid date')\";\n case \"Json\":\n return \"z.any()\";\n case \"Bytes\":\n return \"z.instanceof(Buffer)\";\n case \"BigInt\":\n return \"z.coerce.bigint()\";\n default:\n if (\n prismaSchemaParser.compositeTypes.some((t) => t.name === prismaType)\n ) {\n const compositeType = prismaSchemaParser.compositeTypes.find(\n (t) => t.name === prismaType\n )!;\n const fields = compositeType.fields\n .map(\n (f) =>\n `${f.name}: ${this.mapPrismaTypeToZod(f.type)}${f.isOptional ? \".optional()\" : \"\"}`\n )\n .join(\", \");\n return `z.object({ ${fields} })`;\n }\n return \"z.any()\";\n }\n }\n\n generateLoginSchema(_: TemplateOptions): string {\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n const allowedUsernames = getArkosConfig()?.authentication?.login\n ?.allowedUsernames || [\"username\"];\n\n const usernameFields = allowedUsernames.map((field: string) => {\n const displayName = field.includes(\".\") ? field.split(\".\").pop()! : field;\n const zodType =\n displayName === \"email\" ? \"z.string().email()\" : \"z.string().min(1)\";\n return ` ${displayName}: ${zodType}.optional()`;\n });\n\n const anyOfComment =\n allowedUsernames.length > 1\n ? `\\n// At least one of: ${allowedUsernames.map((f: string) => (f.includes(\".\") ? f.split(\".\").pop() : f)).join(\", \")} is required`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type LoginSchemaType = z.infer<typeof LoginSchema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${anyOfComment}\nconst LoginSchema = z.object({\n${usernameFields.join(\",\\n\")},\n password: z.string().min(8)\n});\n\nexport default LoginSchema;${typeExport}\n`;\n }\n\n generateSignupSchema(_: TemplateOptions): string {\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n const userModel = prismaSchemaParser.models.find(\n (m) => m.name.toLowerCase() === \"user\"\n );\n if (!userModel) throw new Error(\"User model not found in Prisma schema\");\n\n const restrictedFields = [\n \"id\",\n \"createdAt\",\n \"updatedAt\",\n \"deletedAt\",\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"lastLoginAt\",\n ];\n\n const enumsUsed = new Set<string>();\n const schemaFields: string[] = [];\n\n for (const field of userModel.fields) {\n const isForeignKey = userModel.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n if (field.isRelation) {\n if (field.isArray) continue;\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n let zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n if (\n refFieldType?.type?.toLowerCase?.() === \"string\" ||\n !refFieldType?.type\n )\n zodType = zodType + \".min(1)\";\n const isOptional =\n field.isOptional || field.defaultValue !== undefined;\n schemaFields.push(\n ` ${field.name}: z.object({ ${refField}: ${zodType} })${isOptional ? \".optional()\" : \"\"}`\n );\n }\n continue;\n }\n if (prismaSchemaParser.isEnum(field.type)) enumsUsed.add(field.type);\n const zodSchema =\n field.name === \"password\"\n ? `z.string().min(8).regex(/[a-z]/, \"Must contain lowercase\").regex(/[A-Z]/, \"Must contain uppercase\").regex(/[0-9]/, \"Must contain number\")`\n : this.generateZodField(field, true, false);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type SignupSchemaType = z.infer<typeof SignupSchema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst SignupSchema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default SignupSchema;${typeExport}\n`;\n }\n\n generateUpdateMeSchema(_: TemplateOptions): string {\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n const userModel = prismaSchemaParser.models.find(\n (m) => m.name.toLowerCase() === \"user\"\n );\n if (!userModel) throw new Error(\"User model not found in Prisma schema\");\n\n const restrictedFields = [\n \"id\",\n \"createdAt\",\n \"updatedAt\",\n \"deletedAt\",\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"lastLoginAt\",\n \"password\",\n ];\n\n const enumsUsed = new Set<string>();\n const schemaFields: string[] = [];\n\n for (const field of userModel.fields) {\n const isForeignKey = userModel.fields.some(\n (f) => f.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n if (field.isRelation) {\n if (field.isArray) continue;\n const referencedModel = prismaSchemaParser.models.find(\n (m) => m.name === field.type\n );\n if (referencedModel) {\n const refField = field.foreignReferenceField || \"id\";\n const refFieldType = referencedModel.fields.find(\n (f) => f.name === refField\n );\n let zodType = this.mapPrismaTypeToZod(refFieldType?.type!);\n if (\n refFieldType?.type?.toLowerCase?.() === \"string\" ||\n !refFieldType?.type\n )\n zodType = zodType + \".min(1)\";\n schemaFields.push(\n ` ${field.name}: z.object({ ${refField}: ${zodType} }).optional()`\n );\n }\n continue;\n }\n if (prismaSchemaParser.isEnum(field.type)) enumsUsed.add(field.type);\n const zodSchema = this.generateZodField(field, true, true);\n schemaFields.push(` ${field.name}: ${zodSchema}`);\n }\n\n const enumImports =\n enumsUsed.size > 0\n ? `import { ${Array.from(enumsUsed).join(\", \")} } from \"@prisma/client\";\\n`\n : \"\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type UpdateMeSchemaType = z.infer<typeof UpdateMeSchema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n${enumImports}\nconst UpdateMeSchema = z.object({\n${schemaFields.join(\",\\n\")}\n});\n\nexport default UpdateMeSchema;${typeExport}\n`;\n }\n\n generateUpdatePasswordSchema(_: TemplateOptions): string {\n const ext = getUserFileExtension();\n const isTypeScript = ext === \"ts\";\n\n const typeExport = isTypeScript\n ? `\\n\\nexport type UpdatePasswordSchemaType = z.infer<typeof UpdatePasswordSchema>;`\n : \"\";\n\n return `import { z } from \"zod\";\n\nconst UpdatePasswordSchema = z.object({\n currentPassword: z.string().min(1),\n newPassword: z.string().min(8).regex(/[a-z]/, \"Must contain lowercase\").regex(/[A-Z]/, \"Must contain uppercase\").regex(/[0-9]/, \"Must contain number\")\n});\n\nexport default UpdatePasswordSchema;${typeExport}\n`;\n }\n}\n\nconst zodSchemaGenerator = new ZodSchemaGenerator();\n\nexport default zodSchemaGenerator;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.features.js","sourceRoot":"","sources":["../../../../src/utils/features/api.features.ts"],"names":[],"mappings":";;;;;AACA,mFAAoD;AACpD,0EAAgF;AAChF,4FAAmE;AACnE,8DAA8D;AAE9D,+FAAsE;AAItE,MAAqB,WAAW;IA0B9B,YAAY,GAAa,EAAE,SAAqB;QAtBhD,YAAO,GAAwB,EAAE,CAAC;QAClC,0BAAqB,GAAQ,EAAE,CAAC;QAEhC,mBAAc,GAAG;YACf,MAAM;YACN,SAAS;YACT,MAAM;YACN,OAAO;YACP,QAAQ;YACR,WAAW;YACX,cAAc;YACd,QAAQ;YACR,SAAS;YACT,YAAY;YACZ,OAAO;YACP,oBAAoB;YACpB,eAAe;YACf,QAAQ;YACR,SAAS;YACT,MAAM;SACP,CAAC;QAGA,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;YACrD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;YAEf,IAAI,aAAa,GAAG,EAAE,CAAC;YACvB,IAAI,CAAC;gBACH,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAiB,CAAC,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,mBAAQ,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;YACnE,CAAC;YAED,IAAI,CAAC,YAAY,GAAG,IAAA,0BAAS,EAC3B,IAAA,oDAA6B,EAAC,WAAW,CAAC,EAC1C,IAAA,oDAA6B,EAAC,aAAa,CAAC,CAC7C,CAAC;YAEF,0BAAe,CAAC,yBAAyB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,SAAS;YAAE,IAAI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C,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;QAErE,IAAI,IAAI,CAAC,YAAY,EAAE,SAAS,IAAI,IAAI,CAAC,YAAY,EAAE,YAAY,EAAE,CAAC;YACpE,MAAM,IAAI,mBAAQ,CAChB,2DAA2D,EAC3D,GAAG,CACJ,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE;YAC9B,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,KAAK;gBAAE,OAAO,EAAE,CAAC;YAEjD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;YACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;YAC1D,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;YAEhC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC,EAAE,CAAC;QAEL,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,iBAAiB;SACrB,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA1RD,8BA0RC","sourcesContent":["import { Request } from \"express\";\nimport deepmerge from \"../helpers/deepmerge.helper\";\nimport { parseQueryParamsWithModifiers } from \"../helpers/api.features.helpers\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { getPrismaInstance } from \"../helpers/prisma.helpers\";\nimport { ArkosRequest } from \"../../types\";\nimport debuggerService from \"../../modules/debugger/debugger.service\";\n\ntype ModelName = string;\n\nexport default class APIFeatures {\n req?: ArkosRequest;\n searchParams: any;\n searchParamsWithModifiers: any;\n filters: Record<string, any> = {};\n reqFiltersSearchParam: any = {};\n modelName?: ModelName;\n excludedFields = [\n \"page\",\n \"filters\",\n \"sort\",\n \"limit\",\n \"fields\",\n \"addFields\",\n \"removeFields\",\n \"search\",\n \"include\",\n \"filterMode\",\n \"where\",\n \"prismaQueryOptions\",\n \"ignoredFields\",\n \"select\",\n \"orderBy\",\n \"omit\",\n ];\n\n constructor(req?: Request, modelName?: ModelName) {\n if (req) {\n const { filters = \"{}\", ...restOfQuery } = req.query;\n this.req = req;\n\n let parsedFilters = {};\n try {\n parsedFilters = JSON.parse(filters as string);\n } catch (error) {\n throw new AppError(\"Invalid req.query.filters JSON format\", 400);\n }\n\n this.searchParams = deepmerge(\n parseQueryParamsWithModifiers(restOfQuery),\n parseQueryParamsWithModifiers(parsedFilters)\n );\n\n debuggerService.handleTransformedQueryLog(this.searchParams);\n }\n\n if (modelName) this.modelName = modelName;\n this.filters = { ...this.filters };\n }\n\n filter() {\n if (!this.req)\n throw new Error(\n \"Trying to use APIFeatures.filter() without passing request on class constructor or APIFeatures.setup() method.\"\n );\n\n const searchableFields: Record<string, any>[] = [];\n const queryObj = { ...this.searchParams };\n\n this.excludedFields.forEach((el) => delete queryObj[el]);\n\n const topLevelOR = queryObj.OR;\n const topLevelAND = queryObj.AND;\n delete queryObj.OR;\n delete queryObj.AND;\n\n const whereObj = { ...this.req.params, ...queryObj };\n const whereLogicalOperatorFilters = Object.keys(whereObj).map((key) => ({\n [key]: whereObj[key],\n }));\n\n let whereOptions: any = {};\n\n if (whereLogicalOperatorFilters.length > 0) {\n whereOptions = {\n [(this.req.query?.filterMode as string) ?? \"OR\"]:\n whereLogicalOperatorFilters,\n };\n }\n\n if (topLevelOR) {\n if (whereOptions.OR) {\n whereOptions.OR = [...whereOptions.OR, ...topLevelOR];\n } else {\n whereOptions.OR = topLevelOR;\n }\n }\n\n if (topLevelAND) {\n if (whereOptions.AND) {\n whereOptions.AND = [...whereOptions.AND, ...topLevelAND];\n } else {\n whereOptions.AND = topLevelAND;\n }\n }\n\n if (!!this.searchParams.search) {\n const prisma = getPrismaInstance();\n\n if (!this.modelName)\n throw new Error(\"Model name is required for search functionality\");\n\n if (!prisma[this.modelName] || !prisma[this.modelName].fields)\n throw new Error(`Model '${this.modelName}' not found or has no fields`);\n\n Object.keys((prisma as any)[this.modelName].fields).forEach((key) => {\n const field = ((prisma as any)[this.modelName!].fields as any)[key];\n if (\n field?.typeName === \"String\" &&\n key !== \"id\" &&\n key !== \"password\" &&\n !field.isList &&\n !key?.includes?.(\"Id\") &&\n !key?.includes?.(\"ID\")\n ) {\n searchableFields.push({\n [`${key}`]: {\n contains: this.searchParams.search,\n mode: \"insensitive\",\n },\n });\n }\n });\n\n if (searchableFields.length > 0) {\n whereOptions = deepmerge(\n {\n OR: searchableFields,\n },\n whereOptions\n );\n }\n }\n\n const firstMerge = deepmerge(\n {\n where: whereOptions,\n },\n this.req.prismaQueryOptions || {}\n );\n\n this.filters = deepmerge(firstMerge, this.filters);\n this.searchParams = deepmerge(\n this.searchParams || {},\n this.req.prismaQueryOptions || {}\n );\n\n return this;\n }\n\n sort() {\n const reqOrderBy = this.req?.query.orderBy;\n\n const normalizeOrderBy = (orderBy: any): object[] => {\n if (!orderBy) return [];\n if (Array.isArray(orderBy)) return orderBy;\n if (typeof orderBy === \"object\") return [orderBy];\n return [];\n };\n\n if (this.searchParams.sort) {\n const sortBy = this.searchParams.sort.split(\",\").map((field: string) => ({\n [field.startsWith(\"-\") ? field.substring(1) : field]: field.startsWith(\n \"-\"\n )\n ? \"desc\"\n : \"asc\",\n }));\n\n const reqOrderByArray = normalizeOrderBy(reqOrderBy);\n\n const result = reqOrderByArray.length\n ? [...sortBy, ...reqOrderByArray]\n : sortBy;\n\n this.filters = deepmerge(this.filters, { orderBy: result });\n } else {\n this.filters.orderBy = reqOrderBy;\n }\n\n return this;\n }\n\n limitFields() {\n let finalSelect: Record<string, any> = {};\n let finalInclude: Record<string, any> = {};\n let finalOmit: Record<string, any> = {};\n\n if (this.searchParams?.fields) {\n const fields = this.searchParams.fields.split(\",\");\n\n const regularFields = fields.filter(\n (field: string) => !field.startsWith(\"+\") && !field.startsWith(\"-\")\n );\n const includeFields = fields\n .filter((field: string) => field.startsWith(\"+\"))\n .map((field: string) => field.substring(1));\n const excludeFields = fields\n .filter((field: string) => field.startsWith(\"-\"))\n .map((field: string) => field.substring(1));\n\n if (regularFields.length > 0) {\n finalSelect = regularFields.reduce(\n (acc: Record<string, any>, field: string) => {\n acc[field] = true;\n return acc;\n },\n {} as Record<string, any>\n );\n }\n\n includeFields.forEach((field: string) => {\n finalInclude[field] = true;\n });\n\n excludeFields.forEach((field: string) => {\n finalOmit[field] = true;\n });\n }\n\n if (this.searchParams.include || this.filters.include)\n finalInclude = deepmerge(\n finalInclude,\n deepmerge(this.filters?.include || {}, this.searchParams?.include || {})\n );\n\n if (this.searchParams.select || this.filters.include)\n finalSelect = deepmerge(\n finalSelect,\n deepmerge(this.filters?.select || {}, this.searchParams?.select || {})\n );\n\n if (this.searchParams.omit || this.filters.omit)\n finalOmit = deepmerge(\n finalOmit,\n deepmerge(this.filters?.omit || {}, this.searchParams?.omit || {})\n );\n\n if (\n Object.keys(finalSelect).length > 0 &&\n Object.keys(finalInclude).length > 0\n ) {\n finalSelect = deepmerge(finalSelect, finalInclude);\n finalInclude = {};\n delete this.filters.include;\n delete this.searchParams.include;\n }\n\n if (Object.keys(finalSelect).length > 0) this.filters.select = finalSelect;\n\n if (Object.keys(finalInclude).length > 0)\n this.filters.include = finalInclude;\n\n if (Object.keys(finalOmit).length > 0) this.filters.omit = finalOmit;\n\n if (this.searchParams?.addFields || this.searchParams?.removeFields) {\n throw new AppError(\n \"The addFields and removeFields parameters are deprecated.\",\n 400\n );\n }\n\n return this;\n }\n\n paginate(): APIFeatures {\n const paginationOptions = (() => {\n if (this.searchParams.limit === \"all\") return {};\n\n const page = parseInt(this.searchParams.page, 10) || 1;\n const limit = parseInt(this.searchParams.limit, 10) || 30;\n const skip = (page - 1) * limit;\n\n return { skip, take: limit };\n })();\n\n this.filters = {\n ...this.filters,\n ...paginationOptions,\n };\n return this;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.features.js","sourceRoot":"","sources":["../../../../src/utils/features/api.features.ts"],"names":[],"mappings":";;;;;AAAA,mFAAoD;AACpD,0EAAgF;AAChF,4FAAmE;AACnE,8DAA8D;AAE9D,+FAAsE;AAItE,MAAqB,WAAW;IA0B9B,YAAY,GAAkB,EAAE,SAAqB;QAtBrD,YAAO,GAAwB,EAAE,CAAC;QAClC,0BAAqB,GAAQ,EAAE,CAAC;QAEhC,mBAAc,GAAG;YACf,MAAM;YACN,SAAS;YACT,MAAM;YACN,OAAO;YACP,QAAQ;YACR,WAAW;YACX,cAAc;YACd,QAAQ;YACR,SAAS;YACT,YAAY;YACZ,OAAO;YACP,oBAAoB;YACpB,eAAe;YACf,QAAQ;YACR,SAAS;YACT,MAAM;SACP,CAAC;QAGA,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;YACrD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;YAEf,IAAI,aAAa,GAAG,EAAE,CAAC;YACvB,IAAI,CAAC;gBACH,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAiB,CAAC,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,mBAAQ,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;YACnE,CAAC;YAED,IAAI,CAAC,YAAY,GAAG,IAAA,0BAAS,EAC3B,IAAA,oDAA6B,EAAC,WAAW,CAAC,EAC1C,IAAA,oDAA6B,EAAC,aAAa,CAAC,CAC7C,CAAC;YAEF,0BAAe,CAAC,yBAAyB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,SAAS;YAA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AS,CAAC,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;QAErE,IAAI,IAAI,CAAC,YAAY,EAAE,SAAS,IAAI,IAAI,CAAC,YAAY,EAAE,YAAY,EAAE,CAAC;YACpE,MAAM,IAAI,mBAAQ,CAChB,2DAA2D,EAC3D,GAAG,CACJ,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE;YAC9B,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,KAAK;gBAAE,OAAO,EAAE,CAAC;YAEjD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;YACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;YAC1D,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;YAEhC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC,CAAC,EAAE,CAAC;QAEL,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,iBAAiB;SACrB,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA1RD,8BA0RC","sourcesContent":["import deepmerge from \"../helpers/deepmerge.helper\";\nimport { parseQueryParamsWithModifiers } from \"../helpers/api.features.helpers\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { getPrismaInstance } from \"../helpers/prisma.helpers\";\nimport { ArkosRequest } from \"../../types\";\nimport debuggerService from \"../../modules/debugger/debugger.service\";\n\ntype ModelName = string;\n\nexport default class APIFeatures {\n req?: ArkosRequest;\n searchParams: any;\n searchParamsWithModifiers: any;\n filters: Record<string, any> = {};\n reqFiltersSearchParam: any = {};\n modelName?: ModelName;\n excludedFields = [\n \"page\",\n \"filters\",\n \"sort\",\n \"limit\",\n \"fields\",\n \"addFields\",\n \"removeFields\",\n \"search\",\n \"include\",\n \"filterMode\",\n \"where\",\n \"prismaQueryOptions\",\n \"ignoredFields\",\n \"select\",\n \"orderBy\",\n \"omit\",\n ];\n\n constructor(req?: ArkosRequest, modelName?: ModelName) {\n if (req) {\n const { filters = \"{}\", ...restOfQuery } = req.query;\n this.req = req;\n\n let parsedFilters = {};\n try {\n parsedFilters = JSON.parse(filters as string);\n } catch (error) {\n throw new AppError(\"Invalid req.query.filters JSON format\", 400);\n }\n\n this.searchParams = deepmerge(\n parseQueryParamsWithModifiers(restOfQuery),\n parseQueryParamsWithModifiers(parsedFilters)\n );\n\n debuggerService.handleTransformedQueryLog(this.searchParams);\n }\n\n if (modelName) this.modelName = modelName;\n this.filters = { ...this.filters };\n }\n\n filter() {\n if (!this.req)\n throw new Error(\n \"Trying to use APIFeatures.filter() without passing request on class constructor or APIFeatures.setup() method.\"\n );\n\n const searchableFields: Record<string, any>[] = [];\n const queryObj = { ...this.searchParams };\n\n this.excludedFields.forEach((el) => delete queryObj[el]);\n\n const topLevelOR = queryObj.OR;\n const topLevelAND = queryObj.AND;\n delete queryObj.OR;\n delete queryObj.AND;\n\n const whereObj = { ...this.req.params, ...queryObj };\n const whereLogicalOperatorFilters = Object.keys(whereObj).map((key) => ({\n [key]: whereObj[key],\n }));\n\n let whereOptions: any = {};\n\n if (whereLogicalOperatorFilters.length > 0) {\n whereOptions = {\n [(this.req.query?.filterMode as string) ?? \"OR\"]:\n whereLogicalOperatorFilters,\n };\n }\n\n if (topLevelOR) {\n if (whereOptions.OR) {\n whereOptions.OR = [...whereOptions.OR, ...topLevelOR];\n } else {\n whereOptions.OR = topLevelOR;\n }\n }\n\n if (topLevelAND) {\n if (whereOptions.AND) {\n whereOptions.AND = [...whereOptions.AND, ...topLevelAND];\n } else {\n whereOptions.AND = topLevelAND;\n }\n }\n\n if (!!this.searchParams.search) {\n const prisma = getPrismaInstance();\n\n if (!this.modelName)\n throw new Error(\"Model name is required for search functionality\");\n\n if (!prisma[this.modelName] || !prisma[this.modelName].fields)\n throw new Error(`Model '${this.modelName}' not found or has no fields`);\n\n Object.keys((prisma as any)[this.modelName].fields).forEach((key) => {\n const field = ((prisma as any)[this.modelName!].fields as any)[key];\n if (\n field?.typeName === \"String\" &&\n key !== \"id\" &&\n key !== \"password\" &&\n !field.isList &&\n !key?.includes?.(\"Id\") &&\n !key?.includes?.(\"ID\")\n ) {\n searchableFields.push({\n [`${key}`]: {\n contains: this.searchParams.search,\n mode: \"insensitive\",\n },\n });\n }\n });\n\n if (searchableFields.length > 0) {\n whereOptions = deepmerge(\n {\n OR: searchableFields,\n },\n whereOptions\n );\n }\n }\n\n const firstMerge = deepmerge(\n {\n where: whereOptions,\n },\n this.req.prismaQueryOptions || {}\n );\n\n this.filters = deepmerge(firstMerge, this.filters);\n this.searchParams = deepmerge(\n this.searchParams || {},\n this.req.prismaQueryOptions || {}\n );\n\n return this;\n }\n\n sort() {\n const reqOrderBy = this.req?.query.orderBy;\n\n const normalizeOrderBy = (orderBy: any): object[] => {\n if (!orderBy) return [];\n if (Array.isArray(orderBy)) return orderBy;\n if (typeof orderBy === \"object\") return [orderBy];\n return [];\n };\n\n if (this.searchParams.sort) {\n const sortBy = this.searchParams.sort.split(\",\").map((field: string) => ({\n [field.startsWith(\"-\") ? field.substring(1) : field]: field.startsWith(\n \"-\"\n )\n ? \"desc\"\n : \"asc\",\n }));\n\n const reqOrderByArray = normalizeOrderBy(reqOrderBy);\n\n const result = reqOrderByArray.length\n ? [...sortBy, ...reqOrderByArray]\n : sortBy;\n\n this.filters = deepmerge(this.filters, { orderBy: result });\n } else {\n this.filters.orderBy = reqOrderBy;\n }\n\n return this;\n }\n\n limitFields() {\n let finalSelect: Record<string, any> = {};\n let finalInclude: Record<string, any> = {};\n let finalOmit: Record<string, any> = {};\n\n if (this.searchParams?.fields) {\n const fields = this.searchParams.fields.split(\",\");\n\n const regularFields = fields.filter(\n (field: string) => !field.startsWith(\"+\") && !field.startsWith(\"-\")\n );\n const includeFields = fields\n .filter((field: string) => field.startsWith(\"+\"))\n .map((field: string) => field.substring(1));\n const excludeFields = fields\n .filter((field: string) => field.startsWith(\"-\"))\n .map((field: string) => field.substring(1));\n\n if (regularFields.length > 0) {\n finalSelect = regularFields.reduce(\n (acc: Record<string, any>, field: string) => {\n acc[field] = true;\n return acc;\n },\n {} as Record<string, any>\n );\n }\n\n includeFields.forEach((field: string) => {\n finalInclude[field] = true;\n });\n\n excludeFields.forEach((field: string) => {\n finalOmit[field] = true;\n });\n }\n\n if (this.searchParams.include || this.filters.include)\n finalInclude = deepmerge(\n finalInclude,\n deepmerge(this.filters?.include || {}, this.searchParams?.include || {})\n );\n\n if (this.searchParams.select || this.filters.include)\n finalSelect = deepmerge(\n finalSelect,\n deepmerge(this.filters?.select || {}, this.searchParams?.select || {})\n );\n\n if (this.searchParams.omit || this.filters.omit)\n finalOmit = deepmerge(\n finalOmit,\n deepmerge(this.filters?.omit || {}, this.searchParams?.omit || {})\n );\n\n if (\n Object.keys(finalSelect).length > 0 &&\n Object.keys(finalInclude).length > 0\n ) {\n finalSelect = deepmerge(finalSelect, finalInclude);\n finalInclude = {};\n delete this.filters.include;\n delete this.searchParams.include;\n }\n\n if (Object.keys(finalSelect).length > 0) this.filters.select = finalSelect;\n\n if (Object.keys(finalInclude).length > 0)\n this.filters.include = finalInclude;\n\n if (Object.keys(finalOmit).length > 0) this.filters.omit = finalOmit;\n\n if (this.searchParams?.addFields || this.searchParams?.removeFields) {\n throw new AppError(\n \"The addFields and removeFields parameters are deprecated.\",\n 400\n );\n }\n\n return this;\n }\n\n paginate(): APIFeatures {\n const paginationOptions = (() => {\n if (this.searchParams.limit === \"all\") return {};\n\n const page = parseInt(this.searchParams.page, 10) || 1;\n const limit = parseInt(this.searchParams.limit, 10) || 30;\n const skip = (page - 1) * limit;\n\n return { skip, take: limit };\n })();\n\n this.filters = {\n ...this.filters,\n ...paginationOptions,\n };\n return this;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arkos-config.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/arkos-config.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,sDAIC;AAED,0DAIC;AAOD,wCA0BC;
|
|
1
|
+
{"version":3,"file":"arkos-config.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/arkos-config.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,sDAIC;AAED,0DAIC;AAOD,wCA0BC;AAOD,oCAEC;AAED,kDAuBC;AAlGD,oDAAiE;AACjE,mDAA2B;AAC3B,8DAAqC;AACrC,wDAA0C;AAC1C,qDAAqD;AACrD,CAAC,wCAAwC,CAAC,CAAC;AAE3C,IAAI,kBAAkB,GAAQ,EAAE,CAAC;AAEjC,IAAI,CAAC;IACH,kBAAkB,GAAG,0BAA0B,CAAC;AAClD,CAAC;AAAC,OAAO,GAAQ,EAAE,CAAC;IAClB,IAAI,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,oBAAoB,CAAC;QAC1D,cAAI,CAAC,IAAI,CACP,+CAA+C,SAAS,CAAC,oBAAoB,EAAE,gBAAgB,EAC/F;YACE,SAAS,EAAE,IAAI;SAChB,CACF,CAAC;AACN,CAAC;AAED,SAAgB,qBAAqB;IACnC,MAAM,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAAC;IAE5C,OAAO,cAAc,EAAE,IAAI,CAAC;AAC9B,CAAC;AAED,SAAgB,uBAAuB;IACrC,MAAM,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAAC;IAE5C,OAAO,cAAc,EAAE,IAAI,IAAI,cAAc,EAAE,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ACN,CAAC","sourcesContent":["import { defineConfig, UserArkosConfig } from \"../define-config\";\nimport sheu from \"../sheu\";\nimport ExitError from \"./exit-error\";\nimport * as fsHelpers from \"./fs.helpers\";\nimport { getPrismaInstance } from \"./prisma.helpers\";\n(\"ReplaceWithNeededImportsForArkosConfig\"); // This will be filled by post build script\n\nlet definedArkosConfig: any = {};\n\ntry {\n definedArkosConfig = \"ReplaceWithDynamicImport\"; // This will be filled by post build script\n} catch (err: any) {\n if (err.message.toLowerCase().includes(\"cannot find module\"))\n sheu.warn(\n `Using default configs, because arkos.config.${fsHelpers.getUserFileExtension()} was not found`,\n {\n timestamp: true,\n }\n );\n}\n\nexport function isUsingAuthentication() {\n const { authentication } = getArkosConfig();\n\n return authentication?.mode;\n}\n\nexport function isAuthenticationEnabled() {\n const { authentication } = getArkosConfig();\n\n return authentication?.mode && authentication?.enabled !== false;\n}\n\n/**\n * Gives access to the underlying current configurations being used by **Arkos** by default and also loaded through `arkos.config.{ts|js}`\n *\n * @returns {ArkosConfig}\n */\nexport function getArkosConfig(): UserArkosConfig {\n const config =\n typeof definedArkosConfig === \"string\"\n ? { __loader: \"defineConfig\" }\n : (definedArkosConfig as any)?.default || { __loader: \"defineConfig\" };\n const configFile = `arkos.config.${fsHelpers.getUserFileExtension()}`;\n\n if (\n (config as any).__loader !== \"defineConfig\" &&\n typeof jest == \"undefined\" &&\n typeof definedArkosConfig === \"object\"\n ) {\n sheu.error(\n `From v1.6 config under ${configFile} must be wrapped in \\`defineConfig()\\` function from \\`arkos/config\\`. You can do the following under your ${configFile}:\n\nimport { defineConfig } from \"arkos/config\"\n\nconst config = defineConfig({ ... })\n\nexport default config\n`\n );\n process.exit(1);\n }\n\n return defineConfig(config) as any;\n}\n\n/**\n * Returns true if application is being run through `arkos start` after `arkos build`\n *\n * @since 1.5.16-beta\n */\nexport function isProduction() {\n return process.env.ARKOS_BUILD === \"true\";\n}\n\nexport function validateArkosConfig() {\n const config = getArkosConfig();\n const authenticationEnabled = isAuthenticationEnabled();\n\n if (!config?.source?.entryPoint)\n throw ExitError(\n `Invalid value for 'arkosConfig.source.entryPoint', please pass a valid path from the current working directory`\n );\n\n if (\n authenticationEnabled &&\n isProduction() &&\n !process.env.JWT_SECRET &&\n !config.authentication?.jwt?.secret\n )\n throw ExitError(\n `Missing jwt secret in production, see https://www.arkosjs.com/docs/core-concepts/authentication/setup#configuration`\n );\n\n if (authenticationEnabled && !getPrismaInstance())\n throw ExitError(\n `Arkos' authentication system relies on prisma instance, please disabled your authentication or see https://www.arkosjs.com/docs/core-concepts/prisma-orm/setup to setup a prisma instance`\n );\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import ArkosRouter from "../utils/arkos-router/index.js";
|
|
|
4
4
|
import { loadEnvironmentVariables } from "../utils/dotenv.helpers.js";
|
|
5
5
|
import { ArkosPolicy } from "../components/arkos-policy/index.js";
|
|
6
6
|
import { arkos } from "../app.js";
|
|
7
|
-
|
|
7
|
+
import { isProduction } from "../utils/helpers/arkos-config.helpers.js";
|
|
8
|
+
export { BaseController, loadEnvironmentVariables, getArkosConfig, ArkosRouter, ArkosPolicy, isProduction, };
|
|
8
9
|
export default arkos;
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exports/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAUhD,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAML,cAAc,EAId,wBAAwB,EACxB,cAAc,EACd,WAAW,EAEX,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exports/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAUhD,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAErE,OAAO,EAML,cAAc,EAId,wBAAwB,EACxB,cAAc,EACd,WAAW,EAEX,WAAW,EAGX,YAAY,GACb,CAAC;AAOF,eAAe,KAAK,CAAC","sourcesContent":["import { RouterConfig, RouteHook } from \"../types/router-config\";\nimport { BaseController } from \"./../modules/base/base.controller\";\nimport { getArkosConfig } from \"../server\";\nimport ArkosRouter from \"../utils/arkos-router\";\nimport { IArkosRouter } from \"../utils/arkos-router/types\";\nimport { ArkosRouteConfig } from \"../utils/arkos-router/types\";\nimport {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../types\";\nimport { ArkosConfig } from \"../types/new-arkos-config\";\nimport { loadEnvironmentVariables } from \"../utils/dotenv.helpers\";\nimport { ArkosPolicy } from \"../components/arkos-policy\";\nimport { IArkosPolicy } from \"../components/arkos-policy/types\";\nimport { arkos } from \"../app\";\nimport { ArkosFile } from \"../types/upload\";\nimport { isProduction } from \"../utils/helpers/arkos-config.helpers\";\n\nexport {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n IArkosRouter,\n BaseController,\n ArkosConfig,\n RouterConfig,\n RouteHook,\n loadEnvironmentVariables,\n getArkosConfig,\n ArkosRouter,\n ArkosRouteConfig,\n ArkosPolicy,\n IArkosPolicy,\n ArkosFile,\n isProduction,\n};\n\n/**\n * Main entry point for the Arkos module.\n *\n * @module arkos\n */\nexport default arkos;\n"]}
|
|
@@ -26,9 +26,9 @@ export class EmailService {
|
|
|
26
26
|
const user = emailConfigs?.auth?.user || process.env.EMAIL_USER;
|
|
27
27
|
const pass = emailConfigs?.auth?.pass || process.env.EMAIL_PASSWORD;
|
|
28
28
|
const name = emailConfigs?.name || process.env.EMAIL_NAME;
|
|
29
|
-
if (!host
|
|
29
|
+
if (!host) {
|
|
30
30
|
throw new AppError("You are trying to use emailService without setting email configurations. " +
|
|
31
|
-
"Please configure either arkosConfig.email or environment variables (EMAIL_HOST
|
|
31
|
+
"Please configure either arkosConfig.email or environment variables (EMAIL_HOST)", 500, {
|
|
32
32
|
docs: "Read more about emailService at https://www.arkosjs.com/docs/guides/email-service",
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -37,10 +37,12 @@ export class EmailService {
|
|
|
37
37
|
host,
|
|
38
38
|
port: port || 465,
|
|
39
39
|
secure: secure !== undefined ? secure : true,
|
|
40
|
-
auth:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
auth: user && pass
|
|
41
|
+
? {
|
|
42
|
+
user,
|
|
43
|
+
pass,
|
|
44
|
+
}
|
|
45
|
+
: undefined,
|
|
44
46
|
name,
|
|
45
47
|
};
|
|
46
48
|
}
|
|
@@ -68,7 +70,11 @@ export class EmailService {
|
|
|
68
70
|
}
|
|
69
71
|
const info = await transporter.sendMail({
|
|
70
72
|
...options,
|
|
71
|
-
from: fromAddress
|
|
73
|
+
from: fromAddress
|
|
74
|
+
? config.name
|
|
75
|
+
? `${config.name}<${fromAddress}>`
|
|
76
|
+
: fromAddress
|
|
77
|
+
: undefined,
|
|
72
78
|
text: options?.text ||
|
|
73
79
|
(typeof options.html === "string" && options.html
|
|
74
80
|
? convert(options.html)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.service.js","sourceRoot":"","sources":["../../../../src/modules/email/email.service.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IAAI,CAAC;IAC1B,CAAC;IAOM,MAAM,CAAC,MAAM,CAAC,MAA6B;QAChD,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;CACF;AAED,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;AAExC,eAAe,YAAY,CAAC","sourcesContent":["import nodemailer, { SendMailOptions, Transporter } from \"nodemailer\";\nimport { convert } from \"html-to-text\";\nimport { getArkosConfig } from \"../../server\";\nimport AppError from \"../error-handler/utils/app-error\";\n\n/**\n * Defines the options for sending an email.\n */\nexport type EmailOptions = {\n subject: string;\n} & SendMailOptions;\n\n/**\n * Defines the authentication options for SMTP.\n */\nexport type SMTPAuthOptions = {\n user: string;\n pass: string;\n};\n\n/**\n * Defines the connection options for SMTP server.\n */\nexport type SMTPConnectionOptions = {\n host?: string;\n port?: number;\n secure?: boolean;\n auth?: SMTPAuthOptions;\n name?: string;\n};\n\n/**\n * A service class to handle email-related tasks, including sending emails.\n *\n * See the api reference [www.arkosjs.com/docs/reference/the-email-service-class](https://www.arkosjs.com/docs/reference/the-email-service-class)\n */\nexport class EmailService {\n transporter: Transporter | null = null;\n private customConfig: SMTPConnectionOptions | null = null;\n\n /**\n * Creates an instance of the EmailService class.\n *\n * @param {SMTPConnectionOptions} [config] - Optional custom SMTP configuration.\n * If provided, these settings will be used instead of the Arkos config.\n */\n constructor(config?: SMTPConnectionOptions) {\n if (config) {\n this.customConfig = config;\n }\n }\n\n /**\n * Gets the email configuration from multiple sources with priority:\n * 1. Constructor customConfig\n * 2. ArkosConfig\n * 3. Environment variables\n * @returns Configuration object with host, port, and auth details\n * @throws AppError if required email configuration is not set\n */\n private getEmailConfig(): SMTPConnectionOptions {\n if (this.customConfig) {\n return this.customConfig;\n }\n\n const { email: emailConfigs } = getArkosConfig();\n const host = emailConfigs?.host || process.env.EMAIL_HOST;\n const port =\n emailConfigs?.port ||\n (process.env.EMAIL_PORT ? parseInt(process.env.EMAIL_PORT) : undefined);\n const secure =\n emailConfigs?.secure !== undefined\n ? emailConfigs.secure\n : process.env.EMAIL_SECURE\n ? process.env.EMAIL_SECURE === \"true\"\n : undefined;\n const user = emailConfigs?.auth?.user || process.env.EMAIL_USER;\n const pass = emailConfigs?.auth?.pass || process.env.EMAIL_PASSWORD;\n const name = emailConfigs?.name || process.env.EMAIL_NAME;\n\n if (!host || !user || !pass) {\n throw new AppError(\n \"You are trying to use emailService without setting email configurations. \" +\n \"Please configure either arkosConfig.email or environment variables (EMAIL_HOST, EMAIL_USER, EMAIL_PASSWORD)\",\n 500,\n {\n docs: \"Read more about emailService at https://www.arkosjs.com/docs/guides/email-service\",\n }\n );\n }\n\n return {\n ...emailConfigs,\n host,\n port: port || 465,\n secure: secure !== undefined ? secure : true,\n auth: {\n user,\n pass,\n },\n name,\n };\n }\n\n /**\n * Gets or creates a transporter using the email configuration\n * @param customConfig Optional override connection settings (takes full priority if provided)\n * @returns A configured nodemailer transporter\n */\n private getTransporter(customConfig?: SMTPConnectionOptions): Transporter {\n if (customConfig) {\n const { name, ...config } = customConfig;\n return nodemailer.createTransport(config);\n }\n\n if (!this.transporter) {\n const { name, ...config } = this.getEmailConfig() || {};\n this.transporter = nodemailer.createTransport(config);\n }\n return this.transporter;\n }\n\n /**\n * Sends an email with the provided options.\n * Can use either the default configuration or custom connection options.\n *\n * @param {EmailOptions} options - The options for the email to be sent.\n * @param {SMTPConnectionOptions} [connectionOptions] - Optional custom connection settings.\n * @param {boolean} [skipVerification=false] - Whether to skip connection verification.\n * @returns {Promise<{ success: boolean; messageId?: string } & Record<string, any>>} Result with message ID on success.\n */\n public async send(\n options: EmailOptions & SendMailOptions,\n connectionOptions?: SMTPConnectionOptions,\n skipVerification: boolean = true\n ): Promise<{ success: boolean; messageId?: string } & Record<string, any>> {\n const config = this.getEmailConfig();\n const transporter = connectionOptions\n ? this.getTransporter(connectionOptions)\n : this.getTransporter();\n\n const fromAddress =\n options.from || connectionOptions?.auth?.user || config.auth?.user;\n\n if (connectionOptions || !skipVerification) {\n const isConnected = await this.verifyConnection(transporter);\n if (!isConnected) throw new Error(\"Failed to connect to email server\");\n }\n\n const info = await transporter.sendMail({\n ...options,\n from: fromAddress,\n text:\n options?.text ||\n (typeof options.html === \"string\" && options.html\n ? convert(options.html as string)\n : undefined),\n });\n\n return { success: true, ...info };\n }\n\n /**\n * Verifies the connection to the email server.\n * @param {Transporter} [transporterToVerify] - Optional transporter to verify.\n * @returns {Promise<boolean>} A promise that resolves to true if connection is valid.\n */\n public async verifyConnection(\n transporterToVerify?: Transporter\n ): Promise<boolean> {\n try {\n const transporter = transporterToVerify || this.getTransporter();\n await transporter.verify();\n return true;\n } catch (error) {\n console.error(\"Email Server Connection Failed\", error);\n return false;\n }\n }\n\n /**\n * Updates the custom configuration for this email service instance.\n * @param {SMTPConnectionOptions} config - The new connection options.\n */\n public updateConfig(config: SMTPConnectionOptions): void {\n this.customConfig = config;\n this.transporter = null; // Reset transporter so it will be recreated with new config\n }\n\n /**\n * Creates a new instance of EmailService with custom configuration.\n * @param {SMTPConnectionOptions} config - The connection options for the new instance.\n * @returns {EmailService} A new EmailService instance.\n */\n public static create(config: SMTPConnectionOptions): EmailService {\n return new EmailService(config);\n }\n}\n\nconst emailService = new EmailService();\n\nexport default emailService;\n"]}
|
|
1
|
+
{"version":3,"file":"email.service.js","sourceRoot":"","sources":["../../../../src/modules/email/email.service.ts"],"names":[],"mappings":"AAAA,OAAO,UAA4C,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,QAAQ,MAAM,kCAAkC,CAAC;AAiCxD,MAAM,OAAO,YAAY;IAUvB,YAAY,MAA8B;QAT1C,gBAAW,GAAuB,IAAI,CAAC;QAC/B,iBAAY,GAAiC,IAAI,CAAC;QASxD,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;Q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er, { SendMailOptions, Transporter } from \"nodemailer\";\nimport { convert } from \"html-to-text\";\nimport { getArkosConfig } from \"../../server\";\nimport AppError from \"../error-handler/utils/app-error\";\n\n/**\n * Defines the options for sending an email.\n */\nexport type EmailOptions = {\n subject: string;\n} & SendMailOptions;\n\n/**\n * Defines the authentication options for SMTP.\n */\nexport type SMTPAuthOptions = {\n user: string;\n pass: string;\n};\n\n/**\n * Defines the connection options for SMTP server.\n */\nexport type SMTPConnectionOptions = {\n host?: string;\n port?: number;\n secure?: boolean;\n auth?: SMTPAuthOptions;\n name?: string;\n};\n\n/**\n * A service class to handle email-related tasks, including sending emails.\n *\n * See the api reference [www.arkosjs.com/docs/reference/the-email-service-class](https://www.arkosjs.com/docs/reference/the-email-service-class)\n */\nexport class EmailService {\n transporter: Transporter | null = null;\n private customConfig: SMTPConnectionOptions | null = null;\n\n /**\n * Creates an instance of the EmailService class.\n *\n * @param {SMTPConnectionOptions} [config] - Optional custom SMTP configuration.\n * If provided, these settings will be used instead of the Arkos config.\n */\n constructor(config?: SMTPConnectionOptions) {\n if (config) {\n this.customConfig = config;\n }\n }\n\n /**\n * Gets the email configuration from multiple sources with priority:\n * 1. Constructor customConfig\n * 2. ArkosConfig\n * 3. Environment variables\n * @returns Configuration object with host, port, and auth details\n * @throws AppError if required email configuration is not set\n */\n private getEmailConfig(): SMTPConnectionOptions {\n if (this.customConfig) {\n return this.customConfig;\n }\n\n const { email: emailConfigs } = getArkosConfig();\n const host = emailConfigs?.host || process.env.EMAIL_HOST;\n const port =\n emailConfigs?.port ||\n (process.env.EMAIL_PORT ? parseInt(process.env.EMAIL_PORT) : undefined);\n const secure =\n emailConfigs?.secure !== undefined\n ? emailConfigs.secure\n : process.env.EMAIL_SECURE\n ? process.env.EMAIL_SECURE === \"true\"\n : undefined;\n const user = emailConfigs?.auth?.user || process.env.EMAIL_USER;\n const pass = emailConfigs?.auth?.pass || process.env.EMAIL_PASSWORD;\n const name = emailConfigs?.name || process.env.EMAIL_NAME;\n\n if (!host) {\n throw new AppError(\n \"You are trying to use emailService without setting email configurations. \" +\n \"Please configure either arkosConfig.email or environment variables (EMAIL_HOST)\",\n 500,\n {\n docs: \"Read more about emailService at https://www.arkosjs.com/docs/guides/email-service\",\n }\n );\n }\n\n return {\n ...emailConfigs,\n host,\n port: port || 465,\n secure: secure !== undefined ? secure : true,\n auth:\n user && pass\n ? {\n user,\n pass,\n }\n : undefined,\n name,\n };\n }\n\n /**\n * Gets or creates a transporter using the email configuration\n * @param customConfig Optional override connection settings (takes full priority if provided)\n * @returns A configured nodemailer transporter\n */\n private getTransporter(customConfig?: SMTPConnectionOptions): Transporter {\n if (customConfig) {\n const { name, ...config } = customConfig;\n return nodemailer.createTransport(config);\n }\n\n if (!this.transporter) {\n const { name, ...config } = this.getEmailConfig() || {};\n this.transporter = nodemailer.createTransport(config);\n }\n return this.transporter;\n }\n\n /**\n * Sends an email with the provided options.\n * Can use either the default configuration or custom connection options.\n *\n * @param {EmailOptions} options - The options for the email to be sent.\n * @param {SMTPConnectionOptions} [connectionOptions] - Optional custom connection settings.\n * @param {boolean} [skipVerification=false] - Whether to skip connection verification.\n * @returns {Promise<{ success: boolean; messageId?: string } & Record<string, any>>} Result with message ID on success.\n */\n public async send(\n options: EmailOptions & SendMailOptions,\n connectionOptions?: SMTPConnectionOptions,\n skipVerification: boolean = true\n ): Promise<{ success: boolean; messageId?: string } & Record<string, any>> {\n const config = this.getEmailConfig();\n const transporter = connectionOptions\n ? this.getTransporter(connectionOptions)\n : this.getTransporter();\n\n const fromAddress =\n options.from || connectionOptions?.auth?.user || config.auth?.user;\n\n if (connectionOptions || !skipVerification) {\n const isConnected = await this.verifyConnection(transporter);\n if (!isConnected) throw new Error(\"Failed to connect to email server\");\n }\n\n const info = await transporter.sendMail({\n ...options,\n from: fromAddress\n ? config.name\n ? `${config.name}<${fromAddress}>`\n : fromAddress\n : undefined,\n text:\n options?.text ||\n (typeof options.html === \"string\" && options.html\n ? convert(options.html as string)\n : undefined),\n });\n\n return { success: true, ...info };\n }\n\n /**\n * Verifies the connection to the email server.\n * @param {Transporter} [transporterToVerify] - Optional transporter to verify.\n * @returns {Promise<boolean>} A promise that resolves to true if connection is valid.\n */\n public async verifyConnection(\n transporterToVerify?: Transporter\n ): Promise<boolean> {\n try {\n const transporter = transporterToVerify || this.getTransporter();\n await transporter.verify();\n return true;\n } catch (error) {\n console.error(\"Email Server Connection Failed\", error);\n return false;\n }\n }\n\n /**\n * Updates the custom configuration for this email service instance.\n * @param {SMTPConnectionOptions} config - The new connection options.\n */\n public updateConfig(config: SMTPConnectionOptions): void {\n this.customConfig = config;\n this.transporter = null; // Reset transporter so it will be recreated with new config\n }\n\n /**\n * Creates a new instance of EmailService with custom configuration.\n * @param {SMTPConnectionOptions} config - The connection options for the new instance.\n * @returns {EmailService} A new EmailService instance.\n */\n public static create(config: SMTPConnectionOptions): EmailService {\n return new EmailService(config);\n }\n}\n\nconst emailService = new EmailService();\n\nexport default emailService;\n"]}
|
|
@@ -3,8 +3,8 @@ import { getAppServer } from "../../app.js";
|
|
|
3
3
|
import multerErrorHandler from "./utils/multer-error-handler.js";
|
|
4
4
|
export default function errorHandler(err, req, res, _) {
|
|
5
5
|
console.error("[\x1b[31mError\x1b[0m]:", err);
|
|
6
|
-
err.statusCode = err.statusCode
|
|
7
|
-
err.status = err.status
|
|
6
|
+
err.statusCode = err.isOperational ? err.statusCode : 500;
|
|
7
|
+
err.status = err.isOperational ? err.status : "error";
|
|
8
8
|
let error = {
|
|
9
9
|
...err,
|
|
10
10
|
message: err.message,
|
|
@@ -107,7 +107,8 @@ function sendProductionError(err, _, res) {
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
process.on("SIGTERM", () => {
|
|
110
|
-
if (process.env.ARKOS_BUILD !== "true"
|
|
110
|
+
if (process.env.ARKOS_BUILD !== "true" ||
|
|
111
|
+
process.env.__SKIP_LISTEN === "true") {
|
|
111
112
|
process.exit();
|
|
112
113
|
}
|
|
113
114
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,qBAAqB,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,kBAAkB,MAAM,8BAA8B,CAAC;AAkB9D,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,CAAe;IAEf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;IAEnC,IAAI,KAAK,GAAQ;QACf,GAAG,GAAG;QACN,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,SAAS;KAC/B,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM;QAAE,OAAO,KAAK,EAAE,KAAK,CAAC;IAE5D,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,mBAAmB;YACtB,KAAK,GAAG,qBAAqB,CAAC,cAAc,EAAE,CAAC;YAC/C,MAAM;QACR,KAAK,mBAAmB;YACtB,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,CAAC;YACjD,MAAM;QACR,KAAK,6BAA6B;YAChC,KAAK,GAAG,qBAAqB,CAAC,iCAAiC,CAAC,GAAG,CAAC,CAAC;YACrE,MAAM;QACR,KAAK,iCAAiC;YACpC,KAAK,GAAG,qBAAqB,CAAC,qCAAqC,CAAC,GAAG,CAAC,CAAC;YACzE,MAAM;QACR,KAAK,aAAa;YAChB,KAAK,GAAG,kBAAkB,CAAC,MAAM,CAAC,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ACpB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,SAAS;SAC5B,CAAC,CAAC;;QAEH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,gDAAgD;YACzD,IAAI,EAAE,qBAAqB;YAC3B,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;AACP,CAAC;AAWD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC;QACvC,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAC3E,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;QAE9B,IAAI,MAAM,EAAE,KAAK;YACf,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;gBAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;gBACvC,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,CAAC,CAAC,CAAC;;YAEH,UAAU,CAAC,GAAG,EAAE;gBACd,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC,EAAE,CAAC,CAAC,CAAC;IACV,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { getAppServer } from \"../../app\";\nimport multerErrorHandler from \"./utils/multer-error-handler\";\nimport { MulterError } from \"multer\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} _ - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n _: NextFunction\n): void {\n console.error(\"[\\x1b[31mError\\x1b[0m]:\", err);\n\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n let error: any = {\n ...err,\n message: err.message,\n stack: err?.stack || undefined,\n };\n\n if (process.env.ARKOS_BUILD === \"true\") delete error?.stack;\n\n switch (err.name) {\n case \"JsonWebTokenError\":\n error = errorControllerHelper.handleJWTError();\n break;\n case \"TokenExpiredError\":\n error = errorControllerHelper.handleJWTExpired();\n break;\n case \"PrismaClientValidationError\":\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n break;\n case \"PrismaClientInitializationError\":\n error = errorControllerHelper.handlePrismaClientInitializationError(err);\n break;\n case \"MulterError\":\n error = multerErrorHandler.handle(err as unknown as MulterError);\n break;\n }\n\n switch (err.code) {\n case \"P1000\":\n error = errorControllerHelper.handleAuthenticationError(err);\n break;\n case \"P1001\":\n error = errorControllerHelper.handleServerNotReachableError(err);\n break;\n case \"P1002\":\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n break;\n case \"P1003\":\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n break;\n case \"P2000\":\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n break;\n case \"P2001\":\n error = errorControllerHelper.handleRecordNotFoundError(err);\n break;\n case \"P2002\":\n error = errorControllerHelper.handleUniqueConstraintError(err);\n break;\n case \"P2003\":\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n break;\n case \"P2004\":\n error = errorControllerHelper.handleConstraintFailedError(err);\n break;\n case \"P2025\":\n error = errorControllerHelper.handleNonExistingRecord(err);\n break;\n case \"P3000\":\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n break;\n case \"P3001\":\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n break;\n case \"P3002\":\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n break;\n case \"P3003\":\n error = errorControllerHelper.handleVersionMismatchError(err);\n break;\n }\n\n const { message, ...rest } = error;\n if (process.env.ARKOS_BUILD !== \"true\")\n return sendDevelopmentError(\n {\n message: error.message,\n ...rest,\n stack: err.stack,\n originalError: err,\n },\n req,\n res\n );\n\n sendProductionError({ message, ...rest }, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} _ - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(err: any, _: Request, res: Response): void {\n res.status(err.statusCode).json({\n ...err,\n message: err.message?.split?.(\"\\n\")[err.message?.split?.(\"\\n\").length - 1],\n stack: err?.originalError?.stack?.split?.(\"\\n\"),\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} _ - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, _: Request, res: Response): void {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"Unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Internal server error, please try again later.\",\n code: \"InternalServerError\",\n meta: {},\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (process.env.ARKOS_BUILD !== \"true\") {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n const server = getAppServer();\n\n if (server?.close)\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n else\n setTimeout(() => {\n process.exit(1);\n }, 0);\n }\n});\n"]}
|
|
1
|
+
{"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,qBAAqB,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,kBAAkB,MAAM,8BAA8B,CAAC;AAkB9D,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,CAAe;IAEf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;IAC1D,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAEtD,IAAI,KAAK,GAAQ;QACf,GAAG,GAAG;QACN,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,SAAS;KAC/B,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM;QAAE,OAAO,KAAK,EAAE,KAAK,CAAC;IAE5D,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,mBAAmB;YACtB,KAAK,GAAG,qBAAqB,CAAC,cAAc,EAAE,CAAC;YAC/C,MAAM;QACR,KAAK,mBAAmB;YACtB,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,CAAC;YACjD,MAAM;QACR,KAAK,6BAA6B;YAChC,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./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { getAppServer } from \"../../app\";\nimport multerErrorHandler from \"./utils/multer-error-handler\";\nimport { MulterError } from \"multer\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} _ - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n _: NextFunction\n): void {\n console.error(\"[\\x1b[31mError\\x1b[0m]:\", err);\n\n err.statusCode = err.isOperational ? err.statusCode : 500;\n err.status = err.isOperational ? err.status : \"error\";\n\n let error: any = {\n ...err,\n message: err.message,\n stack: err?.stack || undefined,\n };\n\n if (process.env.ARKOS_BUILD === \"true\") delete error?.stack;\n\n switch (err.name) {\n case \"JsonWebTokenError\":\n error = errorControllerHelper.handleJWTError();\n break;\n case \"TokenExpiredError\":\n error = errorControllerHelper.handleJWTExpired();\n break;\n case \"PrismaClientValidationError\":\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n break;\n case \"PrismaClientInitializationError\":\n error = errorControllerHelper.handlePrismaClientInitializationError(err);\n break;\n case \"MulterError\":\n error = multerErrorHandler.handle(err as unknown as MulterError);\n break;\n }\n\n switch (err.code) {\n case \"P1000\":\n error = errorControllerHelper.handleAuthenticationError(err);\n break;\n case \"P1001\":\n error = errorControllerHelper.handleServerNotReachableError(err);\n break;\n case \"P1002\":\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n break;\n case \"P1003\":\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n break;\n case \"P2000\":\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n break;\n case \"P2001\":\n error = errorControllerHelper.handleRecordNotFoundError(err);\n break;\n case \"P2002\":\n error = errorControllerHelper.handleUniqueConstraintError(err);\n break;\n case \"P2003\":\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n break;\n case \"P2004\":\n error = errorControllerHelper.handleConstraintFailedError(err);\n break;\n case \"P2025\":\n error = errorControllerHelper.handleNonExistingRecord(err);\n break;\n case \"P3000\":\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n break;\n case \"P3001\":\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n break;\n case \"P3002\":\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n break;\n case \"P3003\":\n error = errorControllerHelper.handleVersionMismatchError(err);\n break;\n }\n\n const { message, ...rest } = error;\n if (process.env.ARKOS_BUILD !== \"true\")\n return sendDevelopmentError(\n {\n message: error.message,\n ...rest,\n stack: err.stack,\n originalError: err,\n },\n req,\n res\n );\n\n sendProductionError({ message, ...rest }, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} _ - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(err: any, _: Request, res: Response): void {\n res.status(err.statusCode).json({\n ...err,\n message: err.message?.split?.(\"\\n\")[err.message?.split?.(\"\\n\").length - 1],\n stack: err?.originalError?.stack?.split?.(\"\\n\"),\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} _ - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, _: Request, res: Response): void {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"Unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Internal server error, please try again later.\",\n code: \"InternalServerError\",\n meta: {},\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.ARKOS_BUILD !== \"true\" ||\n process.env.__SKIP_LISTEN === \"true\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n const server = getAppServer();\n\n if (server?.close)\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n else\n setTimeout(() => {\n process.exit(1);\n }, 0);\n }\n});\n"]}
|
|
@@ -12,6 +12,7 @@ import { getUserFileExtension } from "../../utils/helpers/fs.helpers.js";
|
|
|
12
12
|
import path from "path";
|
|
13
13
|
import ArkosRouter from "../../utils/arkos-router/index.js";
|
|
14
14
|
import fileUploadJsonSchemaGenerator from "./utils/file-upload-json-schema-generator.js";
|
|
15
|
+
import AppError from "../error-handler/utils/app-error.js";
|
|
15
16
|
export function getFileUploadRouter(arkosConfig) {
|
|
16
17
|
const router = ArkosRouter();
|
|
17
18
|
const { fileUpload } = arkosConfig;
|
|
@@ -68,10 +69,16 @@ export function getFileUploadRouter(arkosConfig) {
|
|
|
68
69
|
etag: true,
|
|
69
70
|
lastModified: true,
|
|
70
71
|
dotfiles: "ignore",
|
|
71
|
-
fallthrough:
|
|
72
|
+
fallthrough: false,
|
|
72
73
|
index: false,
|
|
73
74
|
cacheControl: true,
|
|
74
|
-
}, fileUpload?.expressStatic || {})),
|
|
75
|
+
}, fileUpload?.expressStatic || {})), (err, req, _res, next) => {
|
|
76
|
+
if (err.code === "ENOENT") {
|
|
77
|
+
const filepath = req.path.replace(`/api/${arkosConfig.fileUpload?.baseRoute}`.replace("//", "/"), "");
|
|
78
|
+
throw new AppError(`File ${filepath} was not found`, 404, "FileNotFound", { filepath });
|
|
79
|
+
}
|
|
80
|
+
next(err);
|
|
81
|
+
}, ...processMiddleware(interceptors?.onFindFileError, { type: "error" }));
|
|
75
82
|
}
|
|
76
83
|
if (!isEndpointDisabled(routerConfig, "uploadFile")) {
|
|
77
84
|
router.post(createRouteConfig(arkosConfig, "uploadFile", baseRoutePrefix, `:fileType`, routerConfig, "file-upload", authConfigs), ...processMiddleware(interceptors?.beforeUploadFile), fileUploadController.uploadFile, ...processMiddleware(interceptors?.afterUploadFile), sendResponse, ...processMiddleware(interceptors?.onUploadFileError, { type: "error" }));
|