arkos 1.4.1-canary.7 → 1.4.2-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/modules/auth/auth.service.js +5 -3
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +27 -9
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js +28 -11
- package/dist/cjs/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +3 -0
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -1
- package/dist/cjs/server.js +6 -2
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/utils/arkos-router/index.js +5 -0
- package/dist/cjs/utils/arkos-router/index.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +0 -7
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js.map +1 -1
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +19 -4
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/esm/modules/auth/auth.service.js +5 -3
- package/dist/esm/modules/auth/auth.service.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +27 -9
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js +28 -11
- package/dist/esm/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js +3 -0
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -1
- package/dist/esm/server.js +6 -2
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/utils/arkos-router/index.js +5 -0
- package/dist/esm/utils/arkos-router/index.js.map +1 -1
- package/dist/esm/utils/cli/dev.js +0 -7
- package/dist/esm/utils/cli/dev.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js.map +1 -1
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js +19 -4
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/package.json +1 -1
|
@@ -217,6 +217,9 @@ class PrismaJsonSchemaGenerator {
|
|
|
217
217
|
const selectFields = options?.select;
|
|
218
218
|
const omittedFields = options?.omit;
|
|
219
219
|
const includeRelations = options?.include;
|
|
220
|
+
if (selectFields && includeRelations) {
|
|
221
|
+
throw new Error(`Found both 'select' and 'include' in ${model.name} query options. Please use one of them.`);
|
|
222
|
+
}
|
|
220
223
|
for (const field of model.fields) {
|
|
221
224
|
if (field.name === "password")
|
|
222
225
|
continue;
|
|
@@ -225,10 +228,14 @@ class PrismaJsonSchemaGenerator {
|
|
|
225
228
|
if (selectFields && !selectFields[field.name])
|
|
226
229
|
continue;
|
|
227
230
|
if (this.isModelRelation(field.type)) {
|
|
228
|
-
if (includeRelations?.[field.name]
|
|
231
|
+
if (includeRelations?.[field.name] ||
|
|
232
|
+
selectFields?.[field.name] ||
|
|
233
|
+
omittedFields?.[field.name] === false) {
|
|
229
234
|
const relationModel = this.schema.models.find((m) => m.name === field.type);
|
|
230
235
|
if (relationModel) {
|
|
231
|
-
const relationSchema = this.generateNestedRelationSchema(relationModel, includeRelations[field.name]
|
|
236
|
+
const relationSchema = this.generateNestedRelationSchema(relationModel, includeRelations?.[field.name] ||
|
|
237
|
+
selectFields?.[field.name] ||
|
|
238
|
+
omittedFields?.[field.name]);
|
|
232
239
|
properties[field.name] = field.isArray
|
|
233
240
|
? { type: "array", items: relationSchema }
|
|
234
241
|
: relationSchema;
|
|
@@ -252,6 +259,10 @@ class PrismaJsonSchemaGenerator {
|
|
|
252
259
|
const required = [];
|
|
253
260
|
const selectFields = includeOptions?.select;
|
|
254
261
|
const nestedIncludes = includeOptions?.include;
|
|
262
|
+
const ommittedFields = includeOptions?.omit;
|
|
263
|
+
if (selectFields && nestedIncludes) {
|
|
264
|
+
throw new Error(`Found both 'select' and 'include' in nested ${model.name} query options. Please use one of them.`);
|
|
265
|
+
}
|
|
255
266
|
for (const field of model.fields) {
|
|
256
267
|
if (field.name.toLowerCase().includes("password")) {
|
|
257
268
|
continue;
|
|
@@ -260,10 +271,14 @@ class PrismaJsonSchemaGenerator {
|
|
|
260
271
|
continue;
|
|
261
272
|
}
|
|
262
273
|
if (this.isModelRelation(field.type)) {
|
|
263
|
-
if (nestedIncludes?.[field.name]
|
|
274
|
+
if (nestedIncludes?.[field.name] ||
|
|
275
|
+
selectFields?.[field.name] ||
|
|
276
|
+
ommittedFields?.[field.name] === false) {
|
|
264
277
|
const relationModel = this.schema.models.find((m) => m.name === field.type);
|
|
265
278
|
if (relationModel) {
|
|
266
|
-
const nestedSchema = this.generateNestedRelationSchema(relationModel, nestedIncludes[field.name]
|
|
279
|
+
const nestedSchema = this.generateNestedRelationSchema(relationModel, nestedIncludes?.[field.name] ||
|
|
280
|
+
selectFields?.[field.name] ||
|
|
281
|
+
ommittedFields?.[field.name]);
|
|
267
282
|
properties[field.name] = field.isArray
|
|
268
283
|
? { type: "array", items: nestedSchema }
|
|
269
284
|
: nestedSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma-json-schema-generator.js","sourceRoot":"","sources":["../../../../src/utils/prisma/prisma-json-schema-generator.ts"],"names":[],"mappings":";;;;;;AAEA,mFAAoD;AACpD,sDAG2B;AA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C,IAAI,CAAC,CAAC;YACrE,IAAI,OAAO,EAAE,CAAC;gBACZ,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;YACjC,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,yBAAyB,CAAC,UAAkB;QAClD,MAAM,OAAO,GAA8B;YACzC,MAAM,EAAE,QAAQ;YAChB,GAAG,EAAE,QAAQ;YACb,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,SAAS;YAClB,QAAQ,EAAE,QAAQ;YAClB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,QAAQ;SAChB,CAAC;QAEF,IAAI,OAAO,CAAC,UAAU,CAAC;YAAE,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;QAEpD,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;YAAE,OAAO,QAAQ,CAAC;QAE7C,IAAI,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC;YAAE,OAAO,QAAQ,CAAC;QAEtD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,MAAM,CAAC,QAAgB;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;IAC5D,CAAC;CACF;AA/uBD,8DA+uBC;AAED,MAAM,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;AAElE,kBAAe,yBAAyB,CAAC","sourcesContent":["import { ArkosConfig, RouterConfig } from \"../../exports\";\nimport { AuthPrismaQueryOptions, PrismaQueryOptions } from \"../../types\";\nimport deepmerge from \"../helpers/deepmerge.helper\";\nimport {\n getModuleComponents,\n ValidationFileMappingKey,\n} from \"../dynamic-loader\";\nimport prismaSchemaParser from \"./prisma-schema-parser\";\nimport {\n PrismaModel,\n PrismaField,\n JsonSchema,\n JsonSchemaProperty,\n} from \"./types\";\nimport { localValidatorFileExists } from \"../../modules/swagger/utils/helpers/swagger.router.helpers\";\n\nexport interface SchemaGenerationConfig {\n modelName: string;\n arkosConfig: ArkosConfig;\n schemasToGenerate?: ValidationFileMappingKey[];\n}\n\nexport interface GeneratedSchemas {\n [key: string]: JsonSchema;\n}\n\n/**\n * Enhanced JSON Schema generator that creates schemas based on Prisma models and query options\n */\nexport class PrismaJsonSchemaGenerator {\n schema = prismaSchemaParser.parse();\n\n /**\n * Main method to generate all schemas for a model\n */\n generateModelSchemas(config: SchemaGenerationConfig): GeneratedSchemas {\n const {\n modelName,\n arkosConfig,\n schemasToGenerate = [\n \"model\",\n \"login\",\n \"signup\",\n \"getMe\",\n \"updateMe\",\n \"updatePassword\",\n \"create\",\n \"createOne\",\n \"createMany\",\n \"update\",\n \"updateOne\",\n \"updateMany\",\n \"query\",\n \"findOne\",\n \"findMany\",\n ],\n } = config;\n\n const moduleComponents = getModuleComponents(modelName);\n const routerConfig = moduleComponents?.router?.config || {};\n const prismaQueryOptions = moduleComponents?.prismaQueryOptions || {};\n const authModuleModel = [\"auth\", \"me\", \"password\", \"signup\", \"login\"];\n const isAuthModule = authModuleModel.includes(modelName.toLowerCase());\n\n if (arkosConfig?.swagger?.strict && arkosConfig.swagger.mode !== \"prisma\")\n return {};\n\n if (routerConfig?.disable === true) return {};\n\n const model = this.schema.models.find(\n (m) => m.name.toLowerCase() === modelName.toLowerCase()\n );\n if (!model && !isAuthModule) return {};\n\n const schemas: { [key: string]: JsonSchema } = {};\n\n if (isAuthModule) {\n this.generateAuthSchemas(\n this.schema.models.find((m) => m.name.toLowerCase() === \"user\")!,\n schemas,\n arkosConfig,\n schemasToGenerate,\n prismaQueryOptions as AuthPrismaQueryOptions<any>\n );\n } else {\n if (model)\n this.generateCrudSchemas(\n model,\n schemas,\n arkosConfig,\n schemasToGenerate,\n prismaQueryOptions as PrismaQueryOptions<any>,\n routerConfig\n );\n }\n\n return { ...schemas };\n }\n\n /**\n * Generate auth-specific schemas\n */\n private generateAuthSchemas(\n model: PrismaModel,\n schemas: { [key: string]: JsonSchema },\n arkosConfig: ArkosConfig,\n schemasToGenerate: ValidationFileMappingKey[],\n queryOptions?: AuthPrismaQueryOptions<any>,\n routerConfig?: RouterConfig\n ) {\n const modelName = \"Auth\";\n\n // if no auth activated forget those json schemas\n if (!arkosConfig?.authentication) return schemas;\n\n // Login schema (input)\n if (\n schemasToGenerate.includes(\"login\") &&\n !this.isEndpointDisabled(\"login\", routerConfig) &&\n !localValidatorFileExists(\"login\", modelName, arkosConfig)\n ) {\n schemas[`LoginSchema`] = this.generateLoginSchema(arkosConfig);\n }\n\n // Signup schema (input)\n if (\n schemasToGenerate.includes(\"signup\") &&\n !this.isEndpointDisabled(\"signup\", routerConfig) &&\n !localValidatorFileExists(\"signup\", modelName, arkosConfig)\n ) {\n schemas[`SignupSchema`] = this.generateSignupSchema(\n model,\n queryOptions?.signup\n );\n }\n\n // UpdateMe schema (input)\n if (\n schemasToGenerate.includes(\"updateMe\") &&\n !this.isEndpointDisabled(\"updateMe\", routerConfig) &&\n !localValidatorFileExists(\"updateMe\", modelName, arkosConfig)\n ) {\n schemas[`UpdateMeSchema`] = this.generateUpdateMeSchema(\n model,\n queryOptions?.updateMe\n );\n }\n\n // UpdatePassword schema (input)\n if (\n schemasToGenerate.includes(\"updatePassword\") &&\n !this.isEndpointDisabled(\"updatePassword\", routerConfig) &&\n !localValidatorFileExists(\"updatePassword\", modelName, arkosConfig)\n ) {\n schemas[`UpdatePasswordSchema`] = this.generateUpdatePasswordSchema(\n model,\n queryOptions?.updatePassword\n );\n }\n\n if (\n schemasToGenerate.includes(\"getMe\") &&\n !this.isEndpointDisabled(\"getMe\", routerConfig) &&\n !localValidatorFileExists(\"getMe\", modelName, arkosConfig)\n ) {\n schemas[`GetMeSchema`] = this.generateResponseSchema(\n model,\n queryOptions?.getMe || {},\n \"findOne\"\n );\n }\n }\n\n /**\n * Generate standard CRUD schemas\n */\n private generateCrudSchemas(\n model: PrismaModel,\n schemas: { [key: string]: JsonSchema },\n arkosConfig: ArkosConfig,\n schemasToGenerate: ValidationFileMappingKey[],\n queryOptions?: PrismaQueryOptions<any>,\n routerConfig?: RouterConfig<any>\n ) {\n const modelName = model.name;\n\n const ensureBaseSchemaReference = (\n operation: string,\n modelName: string\n ) => {\n const suffix =\n arkosConfig.validation?.resolver === \"zod\" ? \"Schema\" : \"Dto\";\n\n const singleOpName = operation === \"Create\" ? \"createOne\" : \"updateOne\";\n const hasLocalValidator = localValidatorFileExists(\n singleOpName,\n modelName,\n arkosConfig\n );\n\n if (hasLocalValidator) return `${operation}${modelName}${suffix}`;\n else {\n const modelSchemaKey = `${operation}${modelName}ModelSchema`;\n\n if (!schemas[modelSchemaKey]) {\n if (operation === \"Create\") {\n schemas[modelSchemaKey] = this.generateCreateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"createOne\")\n );\n } else if (operation === \"Update\") {\n schemas[modelSchemaKey] = this.generateUpdateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"updateOne\")\n );\n }\n }\n\n return modelSchemaKey;\n }\n };\n\n if (\n schemasToGenerate.includes(\"createOne\") &&\n !this.isEndpointDisabled(\"createOne\", routerConfig) &&\n !localValidatorFileExists(\"createOne\", modelName, arkosConfig)\n ) {\n schemas[`Create${modelName}ModelSchema`] = this.generateCreateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"createOne\")\n );\n }\n\n if (\n schemasToGenerate.includes(\"createMany\") &&\n !this.isEndpointDisabled(\"createMany\", routerConfig) &&\n !localValidatorFileExists(\"createMany\", modelName, arkosConfig)\n ) {\n const baseSchemaKey = ensureBaseSchemaReference(\"Create\", modelName);\n schemas[`CreateMany${modelName}ModelSchema`] = {\n type: \"array\",\n items: { $ref: `#/components/schemas/${baseSchemaKey}` },\n };\n }\n\n if (\n schemasToGenerate.includes(\"updateOne\") &&\n !this.isEndpointDisabled(\"updateOne\", routerConfig) &&\n !localValidatorFileExists(\"updateOne\", modelName, arkosConfig)\n ) {\n schemas[`Update${modelName}ModelSchema`] = this.generateUpdateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"updateOne\")\n );\n }\n\n if (\n schemasToGenerate.includes(\"updateMany\") &&\n !this.isEndpointDisabled(\"updateMany\", routerConfig) &&\n !localValidatorFileExists(\"updateMany\", modelName, arkosConfig)\n ) {\n schemas[`UpdateMany${modelName}ModelSchema`] = this.generateUpdateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"updateOne\")\n );\n }\n if (\n schemasToGenerate.includes(\"findOne\") &&\n !this.isEndpointDisabled(\"findOne\", routerConfig) &&\n !localValidatorFileExists(\"findOne\", modelName, arkosConfig)\n ) {\n schemas[`FindOne${modelName}ModelSchema`] = this.generateResponseSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"findOne\"),\n \"findOne\"\n );\n }\n\n if (\n schemasToGenerate.includes(\"findMany\") &&\n !this.isEndpointDisabled(\"findMany\", routerConfig) &&\n !localValidatorFileExists(\"findMany\", modelName, arkosConfig)\n ) {\n schemas[`FindMany${modelName}ModelSchema`] = {\n type: \"array\",\n items: this.generateResponseSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"findMany\"),\n \"findMany\"\n ),\n };\n }\n }\n\n /**\n * Generate create schema (excludes ID, includes relation IDs only)\n */\n private generateCreateSchema(\n model: PrismaModel,\n _: Record<string, any>\n ): JsonSchema {\n const properties: { [key: string]: JsonSchemaProperty } = {};\n const required: string[] = [];\n const restrictedFields = [\"createdAt\", \"updatedAt\", \"deletedAt\", \"id\"];\n\n if (model.name.toLowerCase() === \"auth\")\n restrictedFields.push(\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"lastLoginAt\"\n );\n\n for (const field of model.fields) {\n const isForeignKey = model.fields.some(\n (_field) => _field.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n\n if (this.isModelRelation(field.type)) {\n if (!field.isArray) {\n const referencedModel = prismaSchemaParser.models.find(\n (_model) => _model.name === field.type\n )!;\n\n properties[field.name] = {\n type: \"object\",\n properties: {\n [field.foreignReferenceField || \"id\"]: {\n type: this.mapPrismaTypeToJsonSchema(\n referencedModel?.fields.find(\n (_field) => _field.name === field.foreignReferenceField\n )?.type || \"String\"\n ),\n },\n },\n };\n\n if (!field.isOptional && field.defaultValue === undefined)\n required.push(field.name);\n }\n continue;\n }\n\n const property = this.convertFieldToJsonSchema(field);\n properties[field.name] = property;\n\n // Field is required if not optional, no default, and not array\n if (\n !field.isOptional &&\n field.defaultValue === undefined &&\n !field.isArray\n ) {\n required.push(field.name);\n }\n }\n\n return {\n type: \"object\",\n properties,\n required,\n };\n }\n\n /**\n * Generate update schema (all fields optional, includes relation IDs only)\n */\n private generateUpdateSchema(\n model: PrismaModel,\n _: Record<string, any>\n ): JsonSchema {\n const properties: { [key: string]: JsonSchemaProperty } = {};\n const autoFillFields = [\"createdAt\", \"updatedAt\", \"deletedAt\", \"id\"];\n\n for (const field of model.fields) {\n const isForeignKey = model.fields.some(\n (_field) => _field.foreignKeyField === field.name\n );\n if (field.isId || autoFillFields.includes(field.name) || isForeignKey)\n continue;\n\n if (this.isModelRelation(field.type)) {\n if (!field.isArray) {\n const referencedModel = prismaSchemaParser.models.find(\n (_model) => _model.name === field.type\n )!;\n\n properties[field.name] = {\n type: \"object\",\n properties: {\n [field.foreignReferenceField || \"id\"]: {\n type: this.mapPrismaTypeToJsonSchema(\n referencedModel?.fields.find(\n (_field) => _field.name === field.foreignReferenceField\n )?.type || \"String\"\n ),\n },\n },\n };\n }\n\n continue;\n }\n\n const property = this.convertFieldToJsonSchema(field);\n properties[field.name] = property;\n }\n\n return {\n type: \"object\",\n properties,\n required: [], // All fields are optional in update\n };\n }\n\n /**\n * Generate response schema (includes nested relations based on query options)\n */\n private generateResponseSchema(\n model: PrismaModel,\n options: Record<string, any>,\n _: \"findOne\" | \"findMany\"\n ): JsonSchema {\n const properties: { [key: string]: JsonSchemaProperty } = {};\n const required: string[] = [];\n\n // Get select and include options\n const selectFields = options?.select;\n const omittedFields = options?.omit;\n const includeRelations = options?.include;\n\n for (const field of model.fields) {\n // Skip password fields\n if (field.name === \"password\") continue;\n\n // Skip ommited fields\n if (omittedFields && omittedFields[field.name]) continue;\n\n // If select is specified, only include selected fields\n if (selectFields && !selectFields[field.name]) continue;\n\n // Handle relations\n if (this.isModelRelation(field.type)) {\n // Include relation if specified in include option\n if (includeRelations?.[field.name]) {\n const relationModel = this.schema.models.find(\n (m) => m.name === field.type\n );\n\n if (relationModel) {\n const relationSchema = this.generateNestedRelationSchema(\n relationModel,\n includeRelations[field.name]\n );\n properties[field.name] = field.isArray\n ? { type: \"array\", items: relationSchema }\n : relationSchema;\n }\n }\n continue;\n }\n\n const property = this.convertFieldToJsonSchema(field);\n properties[field.name] = property;\n\n // Field is required if not optional (for response schemas, we include all by default)\n if (!field.isOptional) required.push(field.name);\n }\n\n return {\n type: \"object\",\n properties,\n required,\n };\n }\n\n /**\n * Generate nested relation schema\n */\n private generateNestedRelationSchema(\n model: PrismaModel,\n includeOptions: any\n ): JsonSchemaProperty {\n const properties: { [key: string]: JsonSchemaProperty } = {};\n const required: string[] = [];\n\n // Handle nested select\n const selectFields = includeOptions?.select;\n const nestedIncludes = includeOptions?.include;\n\n for (const field of model.fields) {\n // Skip password fields\n if (field.name.toLowerCase().includes(\"password\")) {\n continue;\n }\n\n if (selectFields && !selectFields[field.name]) {\n continue;\n }\n\n if (this.isModelRelation(field.type)) {\n if (nestedIncludes?.[field.name]) {\n const relationModel = this.schema.models.find(\n (m) => m.name === field.type\n );\n if (relationModel) {\n const nestedSchema = this.generateNestedRelationSchema(\n relationModel,\n nestedIncludes[field.name]\n );\n properties[field.name] = field.isArray\n ? { type: \"array\", items: nestedSchema }\n : nestedSchema;\n }\n }\n continue;\n }\n\n const property = this.convertFieldToJsonSchema(field);\n properties[field.name] = property;\n\n if (!field.isOptional) {\n required.push(field.name);\n }\n }\n\n return {\n type: \"object\",\n properties,\n required,\n };\n }\n\n /**\n * Auth-specific schema generators\n */\n private generateLoginSchema(arkosConfig?: ArkosConfig): JsonSchema {\n const userNameFields =\n arkosConfig?.authentication?.login?.allowedUsernames || [];\n\n // Helper function to get display name for nested fields\n const getDisplayName = (field: string) => {\n if (field.includes(\".\")) return field.split(\".\").pop() || field; // Get the part after the last dot\n return field;\n };\n\n // Base schema with password (always required)\n const baseSchema: JsonSchemaProperty = {\n type: \"object\",\n properties: {\n password: {\n type: \"string\",\n minLength: 8,\n },\n },\n required: [\"password\"],\n };\n\n // Add all username fields to properties\n userNameFields.forEach((field) => {\n const displayName = getDisplayName(field);\n baseSchema.properties![displayName] = {\n type: \"string\",\n format: \"string\",\n description: `Username field: ${field}`, // Optional: show original field path\n };\n });\n\n // At least one username field must be provided along with password\n if (userNameFields.length > 0) {\n const usernameDisplayNames = userNameFields.map(getDisplayName);\n\n return {\n ...baseSchema,\n anyOf: usernameDisplayNames.map(() => ({\n required: [...baseSchema.required!],\n })),\n };\n }\n\n return baseSchema;\n }\n private generateSignupSchema(\n model: PrismaModel,\n options?: Record<string, any>\n ): JsonSchema {\n // Similar to create but might have specific required fields\n const singupSchema = this.generateCreateSchema(model, options || {});\n\n const restrictedFields = [\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"lastLoginAt\",\n ];\n restrictedFields.forEach((field) => {\n delete singupSchema?.properties?.[field];\n });\n\n return singupSchema;\n }\n\n private generateUpdateMeSchema(\n model: PrismaModel,\n options?: Record<string, any>\n ): JsonSchema {\n // Similar to update but might exclude certain fields like role, etc.\n const updateSchema = this.generateUpdateSchema(model, options || {});\n\n // Remove sensitive fields that users shouldn't update themselves\n const restrictedFields = [\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"password\",\n \"lastLoginAt\",\n ];\n restrictedFields.forEach((field) => {\n delete updateSchema?.properties?.[field];\n });\n\n return updateSchema;\n }\n\n private generateUpdatePasswordSchema(\n _: PrismaModel,\n _1?: Record<string, any>\n ): JsonSchema {\n return {\n type: \"object\",\n properties: {\n currentPassword: { type: \"string\" },\n newPassword: { type: \"string\", minLength: 8 },\n },\n required: [\"currentPassword\", \"newPassword\"],\n };\n }\n\n /**\n * Utility methods\n */\n private resolvePrismaQueryOptions(\n prismaQueryOptions?: PrismaQueryOptions<any> | AuthPrismaQueryOptions<any>,\n action?: ValidationFileMappingKey\n ): Record<string, any> {\n if (!prismaQueryOptions || !action) {\n return {};\n }\n\n const options = prismaQueryOptions as any;\n const actionOptions = options[action] || {};\n\n // Start with deprecated queryOptions (for backward compatibility)\n let mergedOptions = options.queryOptions || {};\n\n // Apply global options (replaces queryOptions)\n if (options.global)\n mergedOptions = deepmerge(mergedOptions, options.global);\n\n // Apply general operation options based on action type\n const generalOptions = this.getGeneralOptionsForAction(options, action);\n if (generalOptions)\n mergedOptions = deepmerge(mergedOptions, generalOptions);\n\n // Finally apply specific action options (highest priority)\n if (actionOptions) mergedOptions = deepmerge(mergedOptions, actionOptions);\n\n return mergedOptions;\n }\n\n /**\n * Helps in remmaping those prisma query options that combines many operations for example find, save...\n */\n private getGeneralOptionsForAction(\n options: any,\n action: ValidationFileMappingKey\n ): Record<string, any> | null {\n const actionMap: { [key: string]: string[] } = {\n find: [\"findOne\", \"findMany\"],\n create: [\"createOne\", \"createMany\"],\n update: [\"updateOne\", \"updateMany\"],\n delete: [\"deleteOne\", \"deleteMany\"],\n save: [\"createOne\", \"createMany\", \"updateOne\", \"updateMany\"],\n saveOne: [\"createOne\", \"updateOne\"],\n saveMany: [\"createMany\", \"updateMany\"],\n };\n\n for (const [optionKey, actions] of Object.entries(actionMap)) {\n if (actions.includes(action) && options[optionKey]) {\n return options[optionKey];\n }\n }\n\n return null;\n }\n\n private isEndpointDisabled(\n endpoint: string,\n routerConfig?: RouterConfig<any>\n ): boolean {\n if (!routerConfig?.disable) return false;\n\n if (typeof routerConfig.disable === \"boolean\") {\n return routerConfig.disable;\n }\n\n return (\n routerConfig.disable[endpoint as keyof typeof routerConfig.disable] ||\n false\n );\n }\n\n private isModelRelation(typeName: string): boolean {\n return this.schema.models.some((m) => m.name === typeName);\n }\n\n private convertFieldToJsonSchema(field: PrismaField): JsonSchemaProperty {\n // Reuse the existing method from the original generator\n const baseType = this.mapPrismaTypeToJsonSchema(field.type);\n const property: JsonSchemaProperty = { type: baseType };\n\n if (field.isArray) {\n property.type = \"array\";\n property.items = { type: this.mapPrismaTypeToJsonSchema(field.type) };\n }\n\n if (field.defaultValue !== undefined) {\n property.default = field.defaultValue;\n }\n\n if (field.type === \"DateTime\") {\n property.format = \"date-time\";\n }\n\n if (this.isEnum(field.type)) {\n const enumDef = this.schema.enums.find((e) => e.name === field.type);\n if (enumDef) {\n property.enum = enumDef.values;\n }\n }\n\n return property;\n }\n\n private mapPrismaTypeToJsonSchema(prismaType: string): string {\n const typeMap: { [key: string]: string } = {\n String: \"string\",\n Int: \"number\",\n Float: \"number\",\n Boolean: \"boolean\",\n DateTime: \"string\",\n Json: \"object\",\n Bytes: \"string\",\n };\n\n if (typeMap[prismaType]) return typeMap[prismaType];\n\n if (this.isEnum(prismaType)) return \"string\";\n\n if (this.isModelRelation(prismaType)) return \"object\";\n\n return \"string\";\n }\n\n private isEnum(typeName: string): boolean {\n return this.schema.enums.some((e) => e.name === typeName);\n }\n}\n\nconst prismaJsonSchemaGenerator = new PrismaJsonSchemaGenerator();\n\nexport default prismaJsonSchemaGenerator;\n"]}
|
|
1
|
+
{"version":3,"file":"prisma-json-schema-generator.js","sourceRoot":"","sources":["../../../../src/utils/prisma/prisma-json-schema-generator.ts"],"names":[],"mappings":";;;;;;AAEA,mFAAoD;AACpD,sDAG2B;AAC3B,kFAAwD;AAOxD,uGAAsG;AAetG,MAAa,yBAAyB;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E,OAAO,QAAQ,CAAC;QAE7C,IAAI,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC;YAAE,OAAO,QAAQ,CAAC;QAEtD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,MAAM,CAAC,QAAgB;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;IAC5D,CAAC;CACF;AAxwBD,8DAwwBC;AAED,MAAM,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;AAElE,kBAAe,yBAAyB,CAAC","sourcesContent":["import { ArkosConfig, RouterConfig } from \"../../exports\";\nimport { AuthPrismaQueryOptions, PrismaQueryOptions } from \"../../types\";\nimport deepmerge from \"../helpers/deepmerge.helper\";\nimport {\n getModuleComponents,\n ValidationFileMappingKey,\n} from \"../dynamic-loader\";\nimport prismaSchemaParser from \"./prisma-schema-parser\";\nimport {\n PrismaModel,\n PrismaField,\n JsonSchema,\n JsonSchemaProperty,\n} from \"./types\";\nimport { localValidatorFileExists } from \"../../modules/swagger/utils/helpers/swagger.router.helpers\";\n\nexport interface SchemaGenerationConfig {\n modelName: string;\n arkosConfig: ArkosConfig;\n schemasToGenerate?: ValidationFileMappingKey[];\n}\n\nexport interface GeneratedSchemas {\n [key: string]: JsonSchema;\n}\n\n/**\n * Enhanced JSON Schema generator that creates schemas based on Prisma models and query options\n */\nexport class PrismaJsonSchemaGenerator {\n schema = prismaSchemaParser.parse();\n\n /**\n * Main method to generate all schemas for a model\n */\n generateModelSchemas(config: SchemaGenerationConfig): GeneratedSchemas {\n const {\n modelName,\n arkosConfig,\n schemasToGenerate = [\n \"model\",\n \"login\",\n \"signup\",\n \"getMe\",\n \"updateMe\",\n \"updatePassword\",\n \"create\",\n \"createOne\",\n \"createMany\",\n \"update\",\n \"updateOne\",\n \"updateMany\",\n \"query\",\n \"findOne\",\n \"findMany\",\n ],\n } = config;\n\n const moduleComponents = getModuleComponents(modelName);\n const routerConfig = moduleComponents?.router?.config || {};\n const prismaQueryOptions = moduleComponents?.prismaQueryOptions || {};\n const authModuleModel = [\"auth\", \"me\", \"password\", \"signup\", \"login\"];\n const isAuthModule = authModuleModel.includes(modelName.toLowerCase());\n\n if (arkosConfig?.swagger?.strict && arkosConfig.swagger.mode !== \"prisma\")\n return {};\n\n if (routerConfig?.disable === true) return {};\n\n const model = this.schema.models.find(\n (m) => m.name.toLowerCase() === modelName.toLowerCase()\n );\n if (!model && !isAuthModule) return {};\n\n const schemas: { [key: string]: JsonSchema } = {};\n\n if (isAuthModule) {\n this.generateAuthSchemas(\n this.schema.models.find((m) => m.name.toLowerCase() === \"user\")!,\n schemas,\n arkosConfig,\n schemasToGenerate,\n prismaQueryOptions as AuthPrismaQueryOptions<any>\n );\n } else {\n if (model)\n this.generateCrudSchemas(\n model,\n schemas,\n arkosConfig,\n schemasToGenerate,\n prismaQueryOptions as PrismaQueryOptions<any>,\n routerConfig\n );\n }\n\n return { ...schemas };\n }\n\n /**\n * Generate auth-specific schemas\n */\n private generateAuthSchemas(\n model: PrismaModel,\n schemas: { [key: string]: JsonSchema },\n arkosConfig: ArkosConfig,\n schemasToGenerate: ValidationFileMappingKey[],\n queryOptions?: AuthPrismaQueryOptions<any>,\n routerConfig?: RouterConfig\n ) {\n const modelName = \"Auth\";\n\n // if no auth activated forget those json schemas\n if (!arkosConfig?.authentication) return schemas;\n\n // Login schema (input)\n if (\n schemasToGenerate.includes(\"login\") &&\n !this.isEndpointDisabled(\"login\", routerConfig) &&\n !localValidatorFileExists(\"login\", modelName, arkosConfig)\n ) {\n schemas[`LoginSchema`] = this.generateLoginSchema(arkosConfig);\n }\n\n // Signup schema (input)\n if (\n schemasToGenerate.includes(\"signup\") &&\n !this.isEndpointDisabled(\"signup\", routerConfig) &&\n !localValidatorFileExists(\"signup\", modelName, arkosConfig)\n ) {\n schemas[`SignupSchema`] = this.generateSignupSchema(\n model,\n queryOptions?.signup\n );\n }\n\n // UpdateMe schema (input)\n if (\n schemasToGenerate.includes(\"updateMe\") &&\n !this.isEndpointDisabled(\"updateMe\", routerConfig) &&\n !localValidatorFileExists(\"updateMe\", modelName, arkosConfig)\n ) {\n schemas[`UpdateMeSchema`] = this.generateUpdateMeSchema(\n model,\n queryOptions?.updateMe\n );\n }\n\n // UpdatePassword schema (input)\n if (\n schemasToGenerate.includes(\"updatePassword\") &&\n !this.isEndpointDisabled(\"updatePassword\", routerConfig) &&\n !localValidatorFileExists(\"updatePassword\", modelName, arkosConfig)\n ) {\n schemas[`UpdatePasswordSchema`] = this.generateUpdatePasswordSchema(\n model,\n queryOptions?.updatePassword\n );\n }\n\n if (\n schemasToGenerate.includes(\"getMe\") &&\n !this.isEndpointDisabled(\"getMe\", routerConfig) &&\n !localValidatorFileExists(\"getMe\", modelName, arkosConfig)\n ) {\n schemas[`GetMeSchema`] = this.generateResponseSchema(\n model,\n queryOptions?.getMe || {},\n \"findOne\"\n );\n }\n }\n\n /**\n * Generate standard CRUD schemas\n */\n private generateCrudSchemas(\n model: PrismaModel,\n schemas: { [key: string]: JsonSchema },\n arkosConfig: ArkosConfig,\n schemasToGenerate: ValidationFileMappingKey[],\n queryOptions?: PrismaQueryOptions<any>,\n routerConfig?: RouterConfig<any>\n ) {\n const modelName = model.name;\n\n const ensureBaseSchemaReference = (\n operation: string,\n modelName: string\n ) => {\n const suffix =\n arkosConfig.validation?.resolver === \"zod\" ? \"Schema\" : \"Dto\";\n\n const singleOpName = operation === \"Create\" ? \"createOne\" : \"updateOne\";\n const hasLocalValidator = localValidatorFileExists(\n singleOpName,\n modelName,\n arkosConfig\n );\n\n if (hasLocalValidator) return `${operation}${modelName}${suffix}`;\n else {\n const modelSchemaKey = `${operation}${modelName}ModelSchema`;\n\n if (!schemas[modelSchemaKey]) {\n if (operation === \"Create\") {\n schemas[modelSchemaKey] = this.generateCreateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"createOne\")\n );\n } else if (operation === \"Update\") {\n schemas[modelSchemaKey] = this.generateUpdateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"updateOne\")\n );\n }\n }\n\n return modelSchemaKey;\n }\n };\n\n if (\n schemasToGenerate.includes(\"createOne\") &&\n !this.isEndpointDisabled(\"createOne\", routerConfig) &&\n !localValidatorFileExists(\"createOne\", modelName, arkosConfig)\n ) {\n schemas[`Create${modelName}ModelSchema`] = this.generateCreateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"createOne\")\n );\n }\n\n if (\n schemasToGenerate.includes(\"createMany\") &&\n !this.isEndpointDisabled(\"createMany\", routerConfig) &&\n !localValidatorFileExists(\"createMany\", modelName, arkosConfig)\n ) {\n const baseSchemaKey = ensureBaseSchemaReference(\"Create\", modelName);\n schemas[`CreateMany${modelName}ModelSchema`] = {\n type: \"array\",\n items: { $ref: `#/components/schemas/${baseSchemaKey}` },\n };\n }\n\n if (\n schemasToGenerate.includes(\"updateOne\") &&\n !this.isEndpointDisabled(\"updateOne\", routerConfig) &&\n !localValidatorFileExists(\"updateOne\", modelName, arkosConfig)\n ) {\n schemas[`Update${modelName}ModelSchema`] = this.generateUpdateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"updateOne\")\n );\n }\n\n if (\n schemasToGenerate.includes(\"updateMany\") &&\n !this.isEndpointDisabled(\"updateMany\", routerConfig) &&\n !localValidatorFileExists(\"updateMany\", modelName, arkosConfig)\n ) {\n schemas[`UpdateMany${modelName}ModelSchema`] = this.generateUpdateSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"updateOne\")\n );\n }\n if (\n schemasToGenerate.includes(\"findOne\") &&\n !this.isEndpointDisabled(\"findOne\", routerConfig) &&\n !localValidatorFileExists(\"findOne\", modelName, arkosConfig)\n ) {\n schemas[`FindOne${modelName}ModelSchema`] = this.generateResponseSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"findOne\"),\n \"findOne\"\n );\n }\n\n if (\n schemasToGenerate.includes(\"findMany\") &&\n !this.isEndpointDisabled(\"findMany\", routerConfig) &&\n !localValidatorFileExists(\"findMany\", modelName, arkosConfig)\n ) {\n schemas[`FindMany${modelName}ModelSchema`] = {\n type: \"array\",\n items: this.generateResponseSchema(\n model,\n this.resolvePrismaQueryOptions(queryOptions, \"findMany\"),\n \"findMany\"\n ),\n };\n }\n }\n\n /**\n * Generate create schema (excludes ID, includes relation IDs only)\n */\n private generateCreateSchema(\n model: PrismaModel,\n _: Record<string, any>\n ): JsonSchema {\n const properties: { [key: string]: JsonSchemaProperty } = {};\n const required: string[] = [];\n const restrictedFields = [\"createdAt\", \"updatedAt\", \"deletedAt\", \"id\"];\n\n if (model.name.toLowerCase() === \"auth\")\n restrictedFields.push(\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"lastLoginAt\"\n );\n\n for (const field of model.fields) {\n const isForeignKey = model.fields.some(\n (_field) => _field.foreignKeyField === field.name\n );\n if (field.isId || restrictedFields.includes(field.name) || isForeignKey)\n continue;\n\n if (this.isModelRelation(field.type)) {\n if (!field.isArray) {\n const referencedModel = prismaSchemaParser.models.find(\n (_model) => _model.name === field.type\n )!;\n\n properties[field.name] = {\n type: \"object\",\n properties: {\n [field.foreignReferenceField || \"id\"]: {\n type: this.mapPrismaTypeToJsonSchema(\n referencedModel?.fields.find(\n (_field) => _field.name === field.foreignReferenceField\n )?.type || \"String\"\n ),\n },\n },\n };\n\n if (!field.isOptional && field.defaultValue === undefined)\n required.push(field.name);\n }\n continue;\n }\n\n const property = this.convertFieldToJsonSchema(field);\n properties[field.name] = property;\n\n // Field is required if not optional, no default, and not array\n if (\n !field.isOptional &&\n field.defaultValue === undefined &&\n !field.isArray\n ) {\n required.push(field.name);\n }\n }\n\n return {\n type: \"object\",\n properties,\n required,\n };\n }\n\n /**\n * Generate update schema (all fields optional, includes relation IDs only)\n */\n private generateUpdateSchema(\n model: PrismaModel,\n _: Record<string, any>\n ): JsonSchema {\n const properties: { [key: string]: JsonSchemaProperty } = {};\n const autoFillFields = [\"createdAt\", \"updatedAt\", \"deletedAt\", \"id\"];\n\n for (const field of model.fields) {\n const isForeignKey = model.fields.some(\n (_field) => _field.foreignKeyField === field.name\n );\n if (field.isId || autoFillFields.includes(field.name) || isForeignKey)\n continue;\n\n if (this.isModelRelation(field.type)) {\n if (!field.isArray) {\n const referencedModel = prismaSchemaParser.models.find(\n (_model) => _model.name === field.type\n )!;\n\n properties[field.name] = {\n type: \"object\",\n properties: {\n [field.foreignReferenceField || \"id\"]: {\n type: this.mapPrismaTypeToJsonSchema(\n referencedModel?.fields.find(\n (_field) => _field.name === field.foreignReferenceField\n )?.type || \"String\"\n ),\n },\n },\n };\n }\n\n continue;\n }\n\n const property = this.convertFieldToJsonSchema(field);\n properties[field.name] = property;\n }\n\n return {\n type: \"object\",\n properties,\n required: [], // All fields are optional in update\n };\n }\n\n /**\n * Generate response schema (includes nested relations based on query options)\n */\n private generateResponseSchema(\n model: PrismaModel,\n options: Record<string, any>,\n _: \"findOne\" | \"findMany\"\n ): JsonSchema {\n const properties: { [key: string]: JsonSchemaProperty } = {};\n const required: string[] = [];\n\n // Get select and include options\n const selectFields = options?.select;\n const omittedFields = options?.omit;\n const includeRelations = options?.include;\n\n if (selectFields && includeRelations) {\n throw new Error(\n `Found both 'select' and 'include' in ${model.name} query options. Please use one of them.`\n );\n }\n\n for (const field of model.fields) {\n // Skip password fields\n if (field.name === \"password\") continue;\n\n // Skip ommited fields\n if (omittedFields && omittedFields[field.name]) continue;\n\n // If select is specified, only include selected fields\n if (selectFields && !selectFields[field.name]) continue;\n\n // Handle relations\n if (this.isModelRelation(field.type)) {\n // Include relation if specified in include option\n if (\n includeRelations?.[field.name] ||\n selectFields?.[field.name] ||\n omittedFields?.[field.name] === false\n ) {\n const relationModel = this.schema.models.find(\n (m) => m.name === field.type\n );\n\n if (relationModel) {\n const relationSchema = this.generateNestedRelationSchema(\n relationModel,\n includeRelations?.[field.name] ||\n selectFields?.[field.name] ||\n omittedFields?.[field.name]\n );\n properties[field.name] = field.isArray\n ? { type: \"array\", items: relationSchema }\n : relationSchema;\n }\n }\n continue;\n }\n\n const property = this.convertFieldToJsonSchema(field);\n properties[field.name] = property;\n\n // Field is required if not optional (for response schemas, we include all by default)\n if (!field.isOptional) required.push(field.name);\n }\n\n return {\n type: \"object\",\n properties,\n required,\n };\n }\n\n /**\n * Generate nested relation schema\n */\n private generateNestedRelationSchema(\n model: PrismaModel,\n includeOptions: any\n ): JsonSchemaProperty {\n const properties: { [key: string]: JsonSchemaProperty } = {};\n const required: string[] = [];\n\n // Handle nested select\n const selectFields = includeOptions?.select;\n const nestedIncludes = includeOptions?.include;\n const ommittedFields = includeOptions?.omit;\n\n if (selectFields && nestedIncludes) {\n throw new Error(\n `Found both 'select' and 'include' in nested ${model.name} query options. Please use one of them.`\n );\n }\n\n for (const field of model.fields) {\n // Skip password fields\n if (field.name.toLowerCase().includes(\"password\")) {\n continue;\n }\n\n if (selectFields && !selectFields[field.name]) {\n continue;\n }\n\n if (this.isModelRelation(field.type)) {\n if (\n nestedIncludes?.[field.name] ||\n selectFields?.[field.name] ||\n ommittedFields?.[field.name] === false\n ) {\n const relationModel = this.schema.models.find(\n (m) => m.name === field.type\n );\n if (relationModel) {\n const nestedSchema = this.generateNestedRelationSchema(\n relationModel,\n nestedIncludes?.[field.name] ||\n selectFields?.[field.name] ||\n ommittedFields?.[field.name]\n );\n properties[field.name] = field.isArray\n ? { type: \"array\", items: nestedSchema }\n : nestedSchema;\n }\n }\n continue;\n }\n\n const property = this.convertFieldToJsonSchema(field);\n properties[field.name] = property;\n\n if (!field.isOptional) {\n required.push(field.name);\n }\n }\n\n return {\n type: \"object\",\n properties,\n required,\n };\n }\n\n /**\n * Auth-specific schema generators\n */\n private generateLoginSchema(arkosConfig?: ArkosConfig): JsonSchema {\n const userNameFields =\n arkosConfig?.authentication?.login?.allowedUsernames || [];\n\n // Helper function to get display name for nested fields\n const getDisplayName = (field: string) => {\n if (field.includes(\".\")) return field.split(\".\").pop() || field; // Get the part after the last dot\n return field;\n };\n\n // Base schema with password (always required)\n const baseSchema: JsonSchemaProperty = {\n type: \"object\",\n properties: {\n password: {\n type: \"string\",\n minLength: 8,\n },\n },\n required: [\"password\"],\n };\n\n // Add all username fields to properties\n userNameFields.forEach((field) => {\n const displayName = getDisplayName(field);\n baseSchema.properties![displayName] = {\n type: \"string\",\n format: \"string\",\n description: `Username field: ${field}`, // Optional: show original field path\n };\n });\n\n // At least one username field must be provided along with password\n if (userNameFields.length > 0) {\n const usernameDisplayNames = userNameFields.map(getDisplayName);\n\n return {\n ...baseSchema,\n anyOf: usernameDisplayNames.map(() => ({\n required: [...baseSchema.required!],\n })),\n };\n }\n\n return baseSchema;\n }\n private generateSignupSchema(\n model: PrismaModel,\n options?: Record<string, any>\n ): JsonSchema {\n // Similar to create but might have specific required fields\n const singupSchema = this.generateCreateSchema(model, options || {});\n\n const restrictedFields = [\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"lastLoginAt\",\n ];\n restrictedFields.forEach((field) => {\n delete singupSchema?.properties?.[field];\n });\n\n return singupSchema;\n }\n\n private generateUpdateMeSchema(\n model: PrismaModel,\n options?: Record<string, any>\n ): JsonSchema {\n // Similar to update but might exclude certain fields like role, etc.\n const updateSchema = this.generateUpdateSchema(model, options || {});\n\n // Remove sensitive fields that users shouldn't update themselves\n const restrictedFields = [\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"password\",\n \"lastLoginAt\",\n ];\n restrictedFields.forEach((field) => {\n delete updateSchema?.properties?.[field];\n });\n\n return updateSchema;\n }\n\n private generateUpdatePasswordSchema(\n _: PrismaModel,\n _1?: Record<string, any>\n ): JsonSchema {\n return {\n type: \"object\",\n properties: {\n currentPassword: { type: \"string\" },\n newPassword: { type: \"string\", minLength: 8 },\n },\n required: [\"currentPassword\", \"newPassword\"],\n };\n }\n\n /**\n * Utility methods\n */\n private resolvePrismaQueryOptions(\n prismaQueryOptions?: PrismaQueryOptions<any> | AuthPrismaQueryOptions<any>,\n action?: ValidationFileMappingKey\n ): Record<string, any> {\n if (!prismaQueryOptions || !action) {\n return {};\n }\n\n const options = prismaQueryOptions as any;\n const actionOptions = options[action] || {};\n\n // Start with deprecated queryOptions (for backward compatibility)\n let mergedOptions = options.queryOptions || {};\n\n // Apply global options (replaces queryOptions)\n if (options.global)\n mergedOptions = deepmerge(mergedOptions, options.global);\n\n // Apply general operation options based on action type\n const generalOptions = this.getGeneralOptionsForAction(options, action);\n if (generalOptions)\n mergedOptions = deepmerge(mergedOptions, generalOptions);\n\n // Finally apply specific action options (highest priority)\n if (actionOptions) mergedOptions = deepmerge(mergedOptions, actionOptions);\n\n return mergedOptions;\n }\n\n /**\n * Helps in remmaping those prisma query options that combines many operations for example find, save...\n */\n private getGeneralOptionsForAction(\n options: any,\n action: ValidationFileMappingKey\n ): Record<string, any> | null {\n const actionMap: { [key: string]: string[] } = {\n find: [\"findOne\", \"findMany\"],\n create: [\"createOne\", \"createMany\"],\n update: [\"updateOne\", \"updateMany\"],\n delete: [\"deleteOne\", \"deleteMany\"],\n save: [\"createOne\", \"createMany\", \"updateOne\", \"updateMany\"],\n saveOne: [\"createOne\", \"updateOne\"],\n saveMany: [\"createMany\", \"updateMany\"],\n };\n\n for (const [optionKey, actions] of Object.entries(actionMap)) {\n if (actions.includes(action) && options[optionKey]) {\n return options[optionKey];\n }\n }\n\n return null;\n }\n\n private isEndpointDisabled(\n endpoint: string,\n routerConfig?: RouterConfig<any>\n ): boolean {\n if (!routerConfig?.disable) return false;\n\n if (typeof routerConfig.disable === \"boolean\") {\n return routerConfig.disable;\n }\n\n return (\n routerConfig.disable[endpoint as keyof typeof routerConfig.disable] ||\n false\n );\n }\n\n private isModelRelation(typeName: string): boolean {\n return this.schema.models.some((m) => m.name === typeName);\n }\n\n private convertFieldToJsonSchema(field: PrismaField): JsonSchemaProperty {\n // Reuse the existing method from the original generator\n const baseType = this.mapPrismaTypeToJsonSchema(field.type);\n const property: JsonSchemaProperty = { type: baseType };\n\n if (field.isArray) {\n property.type = \"array\";\n property.items = { type: this.mapPrismaTypeToJsonSchema(field.type) };\n }\n\n if (field.defaultValue !== undefined) {\n property.default = field.defaultValue;\n }\n\n if (field.type === \"DateTime\") {\n property.format = \"date-time\";\n }\n\n if (this.isEnum(field.type)) {\n const enumDef = this.schema.enums.find((e) => e.name === field.type);\n if (enumDef) {\n property.enum = enumDef.values;\n }\n }\n\n return property;\n }\n\n private mapPrismaTypeToJsonSchema(prismaType: string): string {\n const typeMap: { [key: string]: string } = {\n String: \"string\",\n Int: \"number\",\n Float: \"number\",\n Boolean: \"boolean\",\n DateTime: \"string\",\n Json: \"object\",\n Bytes: \"string\",\n };\n\n if (typeMap[prismaType]) return typeMap[prismaType];\n\n if (this.isEnum(prismaType)) return \"string\";\n\n if (this.isModelRelation(prismaType)) return \"object\";\n\n return \"string\";\n }\n\n private isEnum(typeName: string): boolean {\n return this.schema.enums.some((e) => e.name === typeName);\n }\n}\n\nconst prismaJsonSchemaGenerator = new PrismaJsonSchemaGenerator();\n\nexport default prismaJsonSchemaGenerator;\n"]}
|
|
@@ -174,10 +174,12 @@ export class AuthService {
|
|
|
174
174
|
const prisma = getPrismaInstance();
|
|
175
175
|
let token;
|
|
176
176
|
if (req?.headers?.authorization &&
|
|
177
|
-
req?.headers?.authorization.startsWith("Bearer")
|
|
177
|
+
req?.headers?.authorization.startsWith("Bearer") &&
|
|
178
|
+
req?.headers?.authorization.split?.(" ")?.[1])
|
|
178
179
|
token = req?.headers?.authorization.split(" ")[1];
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
if (!token &&
|
|
181
|
+
req?.cookies?.arkos_access_token !== "no-token" &&
|
|
182
|
+
req.cookies) {
|
|
181
183
|
token = req?.cookies?.arkos_access_token;
|
|
182
184
|
}
|
|
183
185
|
if (!token)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.service.ts"],"names":[],"mappings":"AAAA,OAAO,GAAoB,MAAM,cAAc,CAAC;AAChD,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,UAAU,MAAM,oCAAoC,CAAC;AAC5D,OAAO,QAAQ,MAAM,kCAAkC,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAavE,OAAO,EAAc,IAAI,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,iBAAiB,MAAM,sCAAsC,CAAC;AACrE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,0CAA0C,CAAC;AAKlD,MAAM,OAAO,WAAW;IAAxB;QAIE,uBAAkB,GAAgC,EAAE,CAAC;QA8arD,iBAAY,GAAG,UAAU,CACvB,KAAK,EAAE,GAAiB,EAAE,CAAgB,EAAE,IAAuB,EAAE,EAAE;YACrE,IAAI,uBAAuB,EAAE;gBAC3B,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAS,CAAC;YAC5D,IAAI,EAAE,CAAC;QACT,CAAC,CACF,CAAC;IAsFJ,CAAC;IAhgBC,YAAY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AAE,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC1E,CAAC;iBAAM,IAAI,OAAO,EAAE,cAAc,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACtD,IAAI,CAAC,aAAa,IAAI,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;oBAC5D,aAAa,GAAG,mBAAmB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,WAAW;wBACnE,EAAE,aAAa,CAAC;gBAEpB,OAAO,CACL,CAAC,CAAC,aAAa;oBACf,IAAI,CAAC,wBAAwB,CAAC,IAAW,EAAE,MAAM,EAAE,aAAa,CAAC,CAClE,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;IACJ,CAAC;CACF;AAKD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,eAAe,WAAW,CAAC","sourcesContent":["import jwt, { SignOptions } from \"jsonwebtoken\";\nimport bcrypt from \"bcryptjs\";\nimport { User } from \"../../types\";\nimport catchAsync from \"../error-handler/utils/catch-async\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { callNext } from \"../base/base.middlewares\";\nimport { getArkosConfig } from \"../../server\";\nimport arkosEnv from \"../../utils/arkos-env\";\nimport { getPrismaInstance } from \"../../utils/helpers/prisma.helpers\";\nimport {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../../types\";\nimport {\n AuthJwtPayload,\n AccessAction,\n AccessControlConfig,\n AuthenticationControlConfig,\n} from \"../../types/auth\";\nimport { MsDuration, toMs } from \"./utils/helpers/auth.controller.helpers\";\nimport { appModules, getModuleComponents } from \"../../utils/dynamic-loader\";\nimport { kebabCase } from \"../../exports/utils\";\nimport {\n invaliAuthTokenError,\n loginRequiredError,\n} from \"./utils/auth-error-objects\";\nimport authActionService from \"./utils/services/auth-action.service\";\nimport {\n isAuthenticationEnabled,\n isUsingAuthentication,\n} from \"../../utils/helpers/arkos-config.helpers\";\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nexport class AuthService {\n /**\n * Object containing a combination of actions per resource, tracked by each set of calls of `authService.handleAccessControl`, this can be accessed through the `authService` object or through the endpoint\n */\n actionsPerResource: Record<string, Set<string>> = {};\n\n /**\n * Signs a JWT token for the user.\n *\n * @param {number | string} id - The unique identifier of the user to generate the token for.\n * @param {string | number} [expiresIn] - The expiration time for the token. Defaults to environment variable `JWT_EXPIRES_IN`.\n * @param {string} [secret] - The secret key used to sign the token. Defaults to environment variable `JWT_SECRET`.\n * @returns {string} The signed JWT token.\n */\n signJwtToken(\n id: number | string,\n expiresIn?: MsDuration | number,\n secret?: string\n ): string {\n const { authentication: configs } = getArkosConfig();\n\n if (\n process.env.ARKOS_BUILD === \"true\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret on production!\",\n 500,\n \"MissingJWTOnProduction\"\n );\n\n secret =\n secret ||\n configs?.jwt?.secret ||\n process.env.JWT_SECRET ||\n arkosEnv.JWT_SECRET;\n\n expiresIn = (expiresIn ||\n configs?.jwt?.expiresIn ||\n process.env.JWT_EXPIRES_IN ||\n arkosEnv.JWT_EXPIRES_IN) as keyof SignOptions[\"expiresIn\"];\n\n return jwt.sign({ id }, secret, {\n expiresIn: expiresIn as MsDuration,\n });\n }\n\n /**\n * Retrieves cookie configuration options for JWT authentication.\n *\n * Merges configuration from multiple sources in order of precedence:\n * 1. Arkos configuration file\n * 2. Environment variables\n * 3. Request properties (for secure flag)\n * 4. Default fallback values\n *\n * @param req - ArkosRequest object used to determine if the connection is secure\n * @returns Cookie options object with expires, httpOnly, secure, and sameSite properties\n *\n * @example\n * ```typescript\n * const cookieOptions = authService.getJwtCookieOptions(req);\n * res.cookie('jwt', token, cookieOptions);\n * ```\n */\n getJwtCookieOptions(req: ArkosRequest) {\n const arkosConfig = getArkosConfig();\n const authConfigs = arkosConfig?.authentication;\n\n if (!req)\n throw new Error(\"Missing req object in order get jwt cookie options\");\n\n const sameSite =\n authConfigs?.jwt?.cookie?.sameSite ||\n (process.env.JWT_COOKIE_SAME_SITE as\n | \"none\"\n | \"lax\"\n | \"strict\"\n | undefined) ||\n \"lax\";\n\n return {\n expires: new Date(\n Date.now() +\n Number(\n toMs(\n authConfigs?.jwt?.expiresIn ||\n (process.env.JWT_EXPIRES_IN as MsDuration) ||\n (arkosEnv.JWT_EXPIRES_IN as MsDuration)\n )\n )\n ),\n httpOnly:\n authConfigs?.jwt?.cookie?.httpOnly ??\n (process.env.JWT_COOKIE_HTTP_ONLY !== undefined\n ? process.env.JWT_COOKIE_HTTP_ONLY === \"true\"\n : undefined) ??\n true,\n secure:\n authConfigs?.jwt?.cookie?.secure ??\n (process.env.JWT_COOKIE_SECURE === \"true\" ||\n req.secure ||\n req.headers[\"x-forwarded-proto\"] === \"https\" ||\n sameSite === \"none\"),\n sameSite,\n };\n }\n\n /**\n * Is used by default internally by Arkos under `BaseService` class to check if the password is already hashed.\n *\n * This was just added to prevent unwanted errors when someone just forgets that the `BaseService` class will automatically hash the password field using `authService.hashPassword` by default.\n *\n * So now before `BaseService` hashes it will test it.\n *\n *\n * @param password The password to be tested if is hashed\n * @returns\n */\n isPasswordHashed(password: string) {\n return !Number.isNaN(bcrypt.getRounds(password) * 1);\n }\n\n /**\n * Compares a candidate password with the stored user password to check if they match.\n *\n * @param {string} candidatePassword - The password provided by the user during login.\n * @param {string} userPassword - The password stored in the database.\n * @returns {Promise<boolean>} Returns true if the passwords match, otherwise false.\n */\n async isCorrectPassword(\n candidatePassword: string,\n userPassword: string\n ): Promise<boolean> {\n return await bcrypt.compare(candidatePassword, userPassword);\n }\n\n /**\n * Hashes a plain text password using bcrypt.\n *\n * @param {string} password - The password to be hashed.\n * @returns {Promise<string>} Returns the hashed password.\n */\n async hashPassword(password: string): Promise<string> {\n return await bcrypt.hash(password, 12);\n }\n\n /**\n * Checks if a password is strong, requiring uppercase, lowercase, and numeric characters as the default.\n *\n * **NB**: You must pay attention when using custom validation with zod or class-validator, try to use the same regex always.\n *\n * **Note**: You can define it when calling arkos.init()\n * ```ts\n * arkos.init({\n * authentication: {\n * passwordValidation:{ regex: /your-desired-regex/, message: 'password must contain...'}\n * }\n * })\n * ```\n *\n * @param {string} password - The password to check.\n * @returns {boolean} Returns true if the password meets the strength criteria, otherwise false.\n */\n public isPasswordStrong(password: string): boolean {\n const initAuthConfigs = getArkosConfig()?.authentication;\n\n const strongPasswordRegex =\n initAuthConfigs?.passwordValidation?.regex ||\n /^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).+$/;\n return strongPasswordRegex.test(password);\n }\n\n /**\n * Checks if a user has changed their password after the JWT was issued.\n *\n * @param {User} user - The user object containing the passwordChangedAt field.\n * @param {number} JWTTimestamp - The timestamp when the JWT was issued.\n * @returns {boolean} Returns true if the user changed their password after the JWT was issued, otherwise false.\n */\n userChangedPasswordAfter(user: User, JWTTimestamp: number): boolean {\n if (user.passwordChangedAt) {\n const convertedTimestamp = parseInt(\n String(user.passwordChangedAt.getTime() / 1000),\n 10\n );\n\n return JWTTimestamp < convertedTimestamp;\n }\n return false;\n }\n\n /**\n * Verifies the authenticity of a JWT token.\n *\n * @param {string} token - The JWT token to verify.\n * @param {string} [secret] - The secret key used to verify the token. Defaults to environment variable `JWT_SECRET`.\n * @returns {Promise<AuthJwtPayload>} Returns the decoded JWT payload if the token is valid.\n * @throws {Error} Throws an error if the token is invalid or expired.\n */\n async verifyJwtToken(\n token: string,\n secret?: string\n ): Promise<AuthJwtPayload> {\n const { authentication: configs } = getArkosConfig();\n\n if (\n process.env.ARKOS_BUILD === \"true\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret in production\",\n 500,\n \"MissingJWTSecretInProduction\"\n );\n\n secret =\n secret ||\n configs?.jwt?.secret ||\n process.env.JWT_SECRET ||\n arkosEnv.JWT_SECRET;\n\n return new Promise((resolve, reject) => {\n jwt.verify(token, secret, (err, decoded) => {\n if (err) reject(err);\n else resolve(decoded as AuthJwtPayload);\n });\n });\n }\n\n /**\n * Checks if a user has permission for a specific action using static access control rules.\n * Validates user roles against predefined access control configuration.\n *\n * @param user - The user object containing role or roles field\n * @param action - The action being performed\n * @param accessControl - Access control configuration (array of roles or object with action-role mappings)\n * @returns True if user has permission, false otherwise\n * @throws Error if user doesn't have role/roles field\n */\n protected checkStaticAccessControl(\n user: User,\n action: string,\n accessControl: AccessControlConfig\n ) {\n if (!user?.role && !user.roles)\n throw Error(\n \"Validation Error: In order to use static authentication user needs at least role field or roles for multiple roles.\"\n );\n\n let authorizedRoles: string[] = [];\n\n if (Array.isArray(accessControl)) authorizedRoles = accessControl;\n else if (accessControl[action])\n authorizedRoles = Array.isArray(accessControl[action])\n ? accessControl[action]\n : accessControl[action].roles || [];\n\n const userRoles = Array.isArray(user?.roles) ? user.roles : [user.role];\n\n return !!userRoles.some((role: string) => authorizedRoles.includes(role));\n }\n\n /**\n * Checks if a user has permission for a specific action and resource using dynamic access control.\n * Queries the database to verify user's role permissions.\n *\n * @param userId - The unique identifier of the user\n * @param action - The action being performed\n * @param resource - The resource being accessed\n * @returns Promise resolving to true if user has permission, false otherwise\n */\n protected async checkDynamicAccessControl(\n userId: string,\n action: string,\n resource: string\n ) {\n const prisma = getPrismaInstance();\n return !!(await prisma.userRole.findFirst({\n where: {\n userId,\n role: {\n permissions: {\n some: {\n resource,\n action,\n },\n },\n },\n },\n select: { id: true },\n }));\n }\n\n /**\n * Middleware function to handle access control based on user roles and permissions.\n *\n * @param {AccessAction} action - The action being performed (e.g., create, update, delete, view).\n * @param {string} resource - The resource name that the action is being performed on (e.g., \"User\", \"Post\").\n * @param {AccessControlConfig} accessControl - The access control configuration.\n * @returns {ArkosRequestHandler} The middleware function that checks if the user has permission to perform the action.\n */\n handleAccessControl(\n action: AccessAction,\n resource: string,\n accessControl?: AccessControlConfig\n ): ArkosRequestHandler {\n if (\n !accessControl &&\n appModules.some(\n (appModule) => kebabCase(appModule) === kebabCase(resource)\n )\n )\n accessControl = getModuleComponents(resource)?.authConfigs?.accessControl;\n\n authActionService.add(action, resource, accessControl);\n\n return catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n if (req.user) {\n const user = req.user as User;\n const configs = getArkosConfig();\n\n if (user.isSuperUser) {\n next();\n return;\n }\n\n const notEnoughPermissionsError = new AppError(\n \"You do not have permission to perfom this action\",\n 403,\n {},\n \"NotEnoughPermissions\"\n );\n\n if (configs?.authentication?.mode === \"dynamic\") {\n const hasPermission = await this.checkDynamicAccessControl(\n user.id,\n action,\n resource\n );\n\n if (!hasPermission) return next(notEnoughPermissionsError);\n } else if (configs?.authentication?.mode === \"static\") {\n if (!accessControl) return next(notEnoughPermissionsError);\n\n const hasPermission = this.checkStaticAccessControl(\n user,\n action,\n accessControl\n );\n\n if (!hasPermission) return next(notEnoughPermissionsError);\n }\n }\n\n next();\n }\n );\n }\n\n /**\n * Processes the cookies or authoriation token and returns the user.\n * @param req\n * @returns {Promise<User | null>} - if authentication is turned off in arkosConfig it returns null\n * @throws {AppError} Throws an error if the token is invalid or the user is not logged in.\n */\n async getAuthenticatedUser(req: ArkosRequest): Promise<User | null> {\n if (!isAuthenticationEnabled())\n throw Error(\n \"ValidationError: Trying to call getAuthenticatedUser without setting up authentication\"\n );\n\n const prisma = getPrismaInstance();\n\n let token: string | undefined;\n\n if (\n req?.headers?.authorization &&\n req?.headers?.authorization.startsWith(\"Bearer\")\n ) {\n token = req?.headers?.authorization.split(\" \")[1];\n } else if (req?.cookies?.arkos_access_token !== \"no-token\" && req.cookies) {\n token = req?.cookies?.arkos_access_token;\n }\n\n if (!token) throw loginRequiredError;\n\n let decoded: AuthJwtPayload | undefined;\n\n try {\n decoded = await this.verifyJwtToken(token);\n } catch (err) {\n throw invaliAuthTokenError;\n }\n\n if (!decoded?.id) throw invaliAuthTokenError;\n const user: any | null = await (prisma as any).user.findUnique({\n where: { id: String(decoded.id) },\n });\n\n if (!user)\n throw new AppError(\n \"The user belonging to this token does no longer exists\",\n 401,\n {},\n \"UserNoLongerExists\"\n );\n\n if (\n this.userChangedPasswordAfter(user, decoded.iat!) &&\n !req.path?.includes?.(\"logout\")\n )\n throw new AppError(\n \"User recently changed password! Please log in again.\",\n 401,\n {},\n \"PasswordChanged\"\n );\n\n req.accessToken = token;\n return user;\n }\n\n /**\n * Middleware function to authenticate the user based on the JWT token.\n *\n * @param {ArkosRequest} req - The request object.\n * @param {ArkosResponse} res - The response object.\n * @param {ArkosNextFunction} next - The next middleware function to be called.\n * @returns {void}\n */\n authenticate = catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n if (isAuthenticationEnabled())\n req.user = (await this.getAuthenticatedUser(req)) as User;\n next();\n }\n );\n\n /**\n * Handles authentication control by checking the `authenticationControl` configuration in the `authConfigs`.\n *\n * @param {ControllerActions} action - The action being performed (e.g., create, update, delete, view).\n * @param {AuthenticationControlConfig} authenticationControl - The authentication configuration object.\n * @returns {ArkosRequestHandler} The middleware function that checks if authentication is required.\n */\n handleAuthenticationControl(\n action: AccessAction,\n authenticationControl?: AuthenticationControlConfig | undefined\n ): ArkosRequestHandler {\n if (authenticationControl && typeof authenticationControl === \"object\") {\n if (authenticationControl[action] === false) return callNext;\n else if (authenticationControl[action] === true) return this.authenticate;\n } else return this.authenticate;\n\n return this.authenticate;\n }\n\n /**\n * Creates a permission checker function for a specific action and resource.\n *\n * PS: This method should be called during application initialization to build permission validators.\n *\n * @see {@link https://www.arkosjs.com/docs/advanced-guide/fine-grained-access-control}\n *\n * @param action - The action to check permission for (e.g., 'View', 'Create', 'Delete')\n * @param resource - The resource being accessed, must be in kebabCase (e.g., 'user', 'cart-item', 'order')\n * @param accessControl - Access control rules (required for static authentication mode), and it is automatically loaded for known modules such as all prisma models, auth and file-upload.\n * @returns A function that takes a user object and returns a boolean indicating permission status\n *\n * @example\n * ```typescript\n * const hasViewProductPermission = await authService.permission('View', 'product');\n *\n * // Later in handler:\n * const canAccess = await hasViewProductPermission(user);\n * if (canAccess) {\n * // User has permission\n * }\n * ```\n */\n permission(\n action: string,\n resource: string,\n accessControl?: AccessControlConfig\n ) {\n // Check if called during request handling (deep call stack indicates handler execution)\n const stack = new Error().stack;\n\n if (stack?.includes(\"node_modules/express/lib/router/index.js\"))\n throw new Error(\n \"authService.permission() should be called during application initialization level.\"\n );\n\n authActionService.add(action, resource, accessControl);\n\n return async (user: Record<string, any> | undefined): Promise<boolean> => {\n // getArkosConfig must not be called the same time as arkos.init()\n const configs = getArkosConfig();\n\n if (!isUsingAuthentication())\n throw Error(\n \"Validation Error: Trying to use authService.permission without setting up authentication.\"\n );\n\n if (!user) throw loginRequiredError;\n if (user.isSuperUser) return true;\n\n if (configs?.authentication?.mode === \"dynamic\") {\n return await this.checkDynamicAccessControl(user?.id, action, resource);\n } else if (configs?.authentication?.mode === \"static\") {\n if (!accessControl && appModules.includes(kebabCase(resource)))\n accessControl = getModuleComponents(kebabCase(resource))?.authConfigs\n ?.accessControl;\n\n return (\n !!accessControl &&\n this.checkStaticAccessControl(user as any, action, accessControl)\n );\n }\n return false;\n };\n }\n}\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nconst authService = new AuthService();\n\nexport default authService;\n"]}
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.service.ts"],"names":[],"mappings":"AAAA,OAAO,GAAoB,MAAM,cAAc,CAAC;AAChD,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,UAAU,MAAM,oCAAoC,CAAC;AAC5D,OAAO,QAAQ,MAAM,kCAAkC,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,QAAQ,MAAM,uBAAuB,CAAC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AW,EAAE,MAAM,EAAE,aAAa,CAAC,CAClE,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;IACJ,CAAC;CACF;AAKD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,eAAe,WAAW,CAAC","sourcesContent":["import jwt, { SignOptions } from \"jsonwebtoken\";\nimport bcrypt from \"bcryptjs\";\nimport { User } from \"../../types\";\nimport catchAsync from \"../error-handler/utils/catch-async\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { callNext } from \"../base/base.middlewares\";\nimport { getArkosConfig } from \"../../server\";\nimport arkosEnv from \"../../utils/arkos-env\";\nimport { getPrismaInstance } from \"../../utils/helpers/prisma.helpers\";\nimport {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../../types\";\nimport {\n AuthJwtPayload,\n AccessAction,\n AccessControlConfig,\n AuthenticationControlConfig,\n} from \"../../types/auth\";\nimport { MsDuration, toMs } from \"./utils/helpers/auth.controller.helpers\";\nimport { appModules, getModuleComponents } from \"../../utils/dynamic-loader\";\nimport { kebabCase } from \"../../exports/utils\";\nimport {\n invaliAuthTokenError,\n loginRequiredError,\n} from \"./utils/auth-error-objects\";\nimport authActionService from \"./utils/services/auth-action.service\";\nimport {\n isAuthenticationEnabled,\n isUsingAuthentication,\n} from \"../../utils/helpers/arkos-config.helpers\";\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nexport class AuthService {\n /**\n * Object containing a combination of actions per resource, tracked by each set of calls of `authService.handleAccessControl`, this can be accessed through the `authService` object or through the endpoint\n */\n actionsPerResource: Record<string, Set<string>> = {};\n\n /**\n * Signs a JWT token for the user.\n *\n * @param {number | string} id - The unique identifier of the user to generate the token for.\n * @param {string | number} [expiresIn] - The expiration time for the token. Defaults to environment variable `JWT_EXPIRES_IN`.\n * @param {string} [secret] - The secret key used to sign the token. Defaults to environment variable `JWT_SECRET`.\n * @returns {string} The signed JWT token.\n */\n signJwtToken(\n id: number | string,\n expiresIn?: MsDuration | number,\n secret?: string\n ): string {\n const { authentication: configs } = getArkosConfig();\n\n if (\n process.env.ARKOS_BUILD === \"true\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret on production!\",\n 500,\n \"MissingJWTOnProduction\"\n );\n\n secret =\n secret ||\n configs?.jwt?.secret ||\n process.env.JWT_SECRET ||\n arkosEnv.JWT_SECRET;\n\n expiresIn = (expiresIn ||\n configs?.jwt?.expiresIn ||\n process.env.JWT_EXPIRES_IN ||\n arkosEnv.JWT_EXPIRES_IN) as keyof SignOptions[\"expiresIn\"];\n\n return jwt.sign({ id }, secret, {\n expiresIn: expiresIn as MsDuration,\n });\n }\n\n /**\n * Retrieves cookie configuration options for JWT authentication.\n *\n * Merges configuration from multiple sources in order of precedence:\n * 1. Arkos configuration file\n * 2. Environment variables\n * 3. Request properties (for secure flag)\n * 4. Default fallback values\n *\n * @param req - ArkosRequest object used to determine if the connection is secure\n * @returns Cookie options object with expires, httpOnly, secure, and sameSite properties\n *\n * @example\n * ```typescript\n * const cookieOptions = authService.getJwtCookieOptions(req);\n * res.cookie('jwt', token, cookieOptions);\n * ```\n */\n getJwtCookieOptions(req: ArkosRequest) {\n const arkosConfig = getArkosConfig();\n const authConfigs = arkosConfig?.authentication;\n\n if (!req)\n throw new Error(\"Missing req object in order get jwt cookie options\");\n\n const sameSite =\n authConfigs?.jwt?.cookie?.sameSite ||\n (process.env.JWT_COOKIE_SAME_SITE as\n | \"none\"\n | \"lax\"\n | \"strict\"\n | undefined) ||\n \"lax\";\n\n return {\n expires: new Date(\n Date.now() +\n Number(\n toMs(\n authConfigs?.jwt?.expiresIn ||\n (process.env.JWT_EXPIRES_IN as MsDuration) ||\n (arkosEnv.JWT_EXPIRES_IN as MsDuration)\n )\n )\n ),\n httpOnly:\n authConfigs?.jwt?.cookie?.httpOnly ??\n (process.env.JWT_COOKIE_HTTP_ONLY !== undefined\n ? process.env.JWT_COOKIE_HTTP_ONLY === \"true\"\n : undefined) ??\n true,\n secure:\n authConfigs?.jwt?.cookie?.secure ??\n (process.env.JWT_COOKIE_SECURE === \"true\" ||\n req.secure ||\n req.headers[\"x-forwarded-proto\"] === \"https\" ||\n sameSite === \"none\"),\n sameSite,\n };\n }\n\n /**\n * Is used by default internally by Arkos under `BaseService` class to check if the password is already hashed.\n *\n * This was just added to prevent unwanted errors when someone just forgets that the `BaseService` class will automatically hash the password field using `authService.hashPassword` by default.\n *\n * So now before `BaseService` hashes it will test it.\n *\n *\n * @param password The password to be tested if is hashed\n * @returns\n */\n isPasswordHashed(password: string) {\n return !Number.isNaN(bcrypt.getRounds(password) * 1);\n }\n\n /**\n * Compares a candidate password with the stored user password to check if they match.\n *\n * @param {string} candidatePassword - The password provided by the user during login.\n * @param {string} userPassword - The password stored in the database.\n * @returns {Promise<boolean>} Returns true if the passwords match, otherwise false.\n */\n async isCorrectPassword(\n candidatePassword: string,\n userPassword: string\n ): Promise<boolean> {\n return await bcrypt.compare(candidatePassword, userPassword);\n }\n\n /**\n * Hashes a plain text password using bcrypt.\n *\n * @param {string} password - The password to be hashed.\n * @returns {Promise<string>} Returns the hashed password.\n */\n async hashPassword(password: string): Promise<string> {\n return await bcrypt.hash(password, 12);\n }\n\n /**\n * Checks if a password is strong, requiring uppercase, lowercase, and numeric characters as the default.\n *\n * **NB**: You must pay attention when using custom validation with zod or class-validator, try to use the same regex always.\n *\n * **Note**: You can define it when calling arkos.init()\n * ```ts\n * arkos.init({\n * authentication: {\n * passwordValidation:{ regex: /your-desired-regex/, message: 'password must contain...'}\n * }\n * })\n * ```\n *\n * @param {string} password - The password to check.\n * @returns {boolean} Returns true if the password meets the strength criteria, otherwise false.\n */\n public isPasswordStrong(password: string): boolean {\n const initAuthConfigs = getArkosConfig()?.authentication;\n\n const strongPasswordRegex =\n initAuthConfigs?.passwordValidation?.regex ||\n /^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).+$/;\n return strongPasswordRegex.test(password);\n }\n\n /**\n * Checks if a user has changed their password after the JWT was issued.\n *\n * @param {User} user - The user object containing the passwordChangedAt field.\n * @param {number} JWTTimestamp - The timestamp when the JWT was issued.\n * @returns {boolean} Returns true if the user changed their password after the JWT was issued, otherwise false.\n */\n userChangedPasswordAfter(user: User, JWTTimestamp: number): boolean {\n if (user.passwordChangedAt) {\n const convertedTimestamp = parseInt(\n String(user.passwordChangedAt.getTime() / 1000),\n 10\n );\n\n return JWTTimestamp < convertedTimestamp;\n }\n return false;\n }\n\n /**\n * Verifies the authenticity of a JWT token.\n *\n * @param {string} token - The JWT token to verify.\n * @param {string} [secret] - The secret key used to verify the token. Defaults to environment variable `JWT_SECRET`.\n * @returns {Promise<AuthJwtPayload>} Returns the decoded JWT payload if the token is valid.\n * @throws {Error} Throws an error if the token is invalid or expired.\n */\n async verifyJwtToken(\n token: string,\n secret?: string\n ): Promise<AuthJwtPayload> {\n const { authentication: configs } = getArkosConfig();\n\n if (\n process.env.ARKOS_BUILD === \"true\" &&\n !process.env.JWT_SECRET &&\n !configs?.jwt?.secret\n )\n throw new AppError(\n \"Missing JWT secret in production\",\n 500,\n \"MissingJWTSecretInProduction\"\n );\n\n secret =\n secret ||\n configs?.jwt?.secret ||\n process.env.JWT_SECRET ||\n arkosEnv.JWT_SECRET;\n\n return new Promise((resolve, reject) => {\n jwt.verify(token, secret, (err, decoded) => {\n if (err) reject(err);\n else resolve(decoded as AuthJwtPayload);\n });\n });\n }\n\n /**\n * Checks if a user has permission for a specific action using static access control rules.\n * Validates user roles against predefined access control configuration.\n *\n * @param user - The user object containing role or roles field\n * @param action - The action being performed\n * @param accessControl - Access control configuration (array of roles or object with action-role mappings)\n * @returns True if user has permission, false otherwise\n * @throws Error if user doesn't have role/roles field\n */\n protected checkStaticAccessControl(\n user: User,\n action: string,\n accessControl: AccessControlConfig\n ) {\n if (!user?.role && !user.roles)\n throw Error(\n \"Validation Error: In order to use static authentication user needs at least role field or roles for multiple roles.\"\n );\n\n let authorizedRoles: string[] = [];\n\n if (Array.isArray(accessControl)) authorizedRoles = accessControl;\n else if (accessControl[action])\n authorizedRoles = Array.isArray(accessControl[action])\n ? accessControl[action]\n : accessControl[action].roles || [];\n\n const userRoles = Array.isArray(user?.roles) ? user.roles : [user.role];\n\n return !!userRoles.some((role: string) => authorizedRoles.includes(role));\n }\n\n /**\n * Checks if a user has permission for a specific action and resource using dynamic access control.\n * Queries the database to verify user's role permissions.\n *\n * @param userId - The unique identifier of the user\n * @param action - The action being performed\n * @param resource - The resource being accessed\n * @returns Promise resolving to true if user has permission, false otherwise\n */\n protected async checkDynamicAccessControl(\n userId: string,\n action: string,\n resource: string\n ) {\n const prisma = getPrismaInstance();\n return !!(await prisma.userRole.findFirst({\n where: {\n userId,\n role: {\n permissions: {\n some: {\n resource,\n action,\n },\n },\n },\n },\n select: { id: true },\n }));\n }\n\n /**\n * Middleware function to handle access control based on user roles and permissions.\n *\n * @param {AccessAction} action - The action being performed (e.g., create, update, delete, view).\n * @param {string} resource - The resource name that the action is being performed on (e.g., \"User\", \"Post\").\n * @param {AccessControlConfig} accessControl - The access control configuration.\n * @returns {ArkosRequestHandler} The middleware function that checks if the user has permission to perform the action.\n */\n handleAccessControl(\n action: AccessAction,\n resource: string,\n accessControl?: AccessControlConfig\n ): ArkosRequestHandler {\n if (\n !accessControl &&\n appModules.some(\n (appModule) => kebabCase(appModule) === kebabCase(resource)\n )\n )\n accessControl = getModuleComponents(resource)?.authConfigs?.accessControl;\n\n authActionService.add(action, resource, accessControl);\n\n return catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n if (req.user) {\n const user = req.user as User;\n const configs = getArkosConfig();\n\n if (user.isSuperUser) {\n next();\n return;\n }\n\n const notEnoughPermissionsError = new AppError(\n \"You do not have permission to perfom this action\",\n 403,\n {},\n \"NotEnoughPermissions\"\n );\n\n if (configs?.authentication?.mode === \"dynamic\") {\n const hasPermission = await this.checkDynamicAccessControl(\n user.id,\n action,\n resource\n );\n\n if (!hasPermission) return next(notEnoughPermissionsError);\n } else if (configs?.authentication?.mode === \"static\") {\n if (!accessControl) return next(notEnoughPermissionsError);\n\n const hasPermission = this.checkStaticAccessControl(\n user,\n action,\n accessControl\n );\n\n if (!hasPermission) return next(notEnoughPermissionsError);\n }\n }\n\n next();\n }\n );\n }\n\n /**\n * Processes the cookies or authoriation token and returns the user.\n * @param req\n * @returns {Promise<User | null>} - if authentication is turned off in arkosConfig it returns null\n * @throws {AppError} Throws an error if the token is invalid or the user is not logged in.\n */\n async getAuthenticatedUser(req: ArkosRequest): Promise<User | null> {\n if (!isAuthenticationEnabled())\n throw Error(\n \"ValidationError: Trying to call getAuthenticatedUser without setting up authentication\"\n );\n\n const prisma = getPrismaInstance();\n\n let token: string | undefined;\n\n if (\n req?.headers?.authorization &&\n req?.headers?.authorization.startsWith(\"Bearer\") &&\n req?.headers?.authorization.split?.(\" \")?.[1]\n )\n token = req?.headers?.authorization.split(\" \")[1];\n\n if (\n !token &&\n req?.cookies?.arkos_access_token !== \"no-token\" &&\n req.cookies\n ) {\n token = req?.cookies?.arkos_access_token;\n }\n\n if (!token) throw loginRequiredError;\n\n let decoded: AuthJwtPayload | undefined;\n\n try {\n decoded = await this.verifyJwtToken(token);\n } catch (err) {\n throw invaliAuthTokenError;\n }\n\n if (!decoded?.id) throw invaliAuthTokenError;\n const user: any | null = await (prisma as any).user.findUnique({\n where: { id: String(decoded.id) },\n });\n\n if (!user)\n throw new AppError(\n \"The user belonging to this token does no longer exists\",\n 401,\n {},\n \"UserNoLongerExists\"\n );\n\n if (\n this.userChangedPasswordAfter(user, decoded.iat!) &&\n !req.path?.includes?.(\"logout\")\n )\n throw new AppError(\n \"User recently changed password! Please log in again.\",\n 401,\n {},\n \"PasswordChanged\"\n );\n\n req.accessToken = token;\n return user;\n }\n\n /**\n * Middleware function to authenticate the user based on the JWT token.\n *\n * @param {ArkosRequest} req - The request object.\n * @param {ArkosResponse} res - The response object.\n * @param {ArkosNextFunction} next - The next middleware function to be called.\n * @returns {void}\n */\n authenticate = catchAsync(\n async (req: ArkosRequest, _: ArkosResponse, next: ArkosNextFunction) => {\n if (isAuthenticationEnabled())\n req.user = (await this.getAuthenticatedUser(req)) as User;\n next();\n }\n );\n\n /**\n * Handles authentication control by checking the `authenticationControl` configuration in the `authConfigs`.\n *\n * @param {ControllerActions} action - The action being performed (e.g., create, update, delete, view).\n * @param {AuthenticationControlConfig} authenticationControl - The authentication configuration object.\n * @returns {ArkosRequestHandler} The middleware function that checks if authentication is required.\n */\n handleAuthenticationControl(\n action: AccessAction,\n authenticationControl?: AuthenticationControlConfig | undefined\n ): ArkosRequestHandler {\n if (authenticationControl && typeof authenticationControl === \"object\") {\n if (authenticationControl[action] === false) return callNext;\n else if (authenticationControl[action] === true) return this.authenticate;\n } else return this.authenticate;\n\n return this.authenticate;\n }\n\n /**\n * Creates a permission checker function for a specific action and resource.\n *\n * PS: This method should be called during application initialization to build permission validators.\n *\n * @see {@link https://www.arkosjs.com/docs/advanced-guide/fine-grained-access-control}\n *\n * @param action - The action to check permission for (e.g., 'View', 'Create', 'Delete')\n * @param resource - The resource being accessed, must be in kebabCase (e.g., 'user', 'cart-item', 'order')\n * @param accessControl - Access control rules (required for static authentication mode), and it is automatically loaded for known modules such as all prisma models, auth and file-upload.\n * @returns A function that takes a user object and returns a boolean indicating permission status\n *\n * @example\n * ```typescript\n * const hasViewProductPermission = await authService.permission('View', 'product');\n *\n * // Later in handler:\n * const canAccess = await hasViewProductPermission(user);\n * if (canAccess) {\n * // User has permission\n * }\n * ```\n */\n permission(\n action: string,\n resource: string,\n accessControl?: AccessControlConfig\n ) {\n // Check if called during request handling (deep call stack indicates handler execution)\n const stack = new Error().stack;\n\n if (stack?.includes(\"node_modules/express/lib/router/index.js\"))\n throw new Error(\n \"authService.permission() should be called during application initialization level.\"\n );\n\n authActionService.add(action, resource, accessControl);\n\n return async (user: Record<string, any> | undefined): Promise<boolean> => {\n // getArkosConfig must not be called the same time as arkos.init()\n const configs = getArkosConfig();\n\n if (!isUsingAuthentication())\n throw Error(\n \"Validation Error: Trying to use authService.permission without setting up authentication.\"\n );\n\n if (!user) throw loginRequiredError;\n if (user.isSuperUser) return true;\n\n if (configs?.authentication?.mode === \"dynamic\") {\n return await this.checkDynamicAccessControl(user?.id, action, resource);\n } else if (configs?.authentication?.mode === \"static\") {\n if (!accessControl && appModules.includes(kebabCase(resource)))\n accessControl = getModuleComponents(kebabCase(resource))?.authConfigs\n ?.accessControl;\n\n return (\n !!accessControl &&\n this.checkStaticAccessControl(user as any, action, accessControl)\n );\n }\n return false;\n };\n }\n}\n\n/**\n * Handles various authentication-related tasks such as JWT signing, password hashing, and verifying user credentials.\n */\nconst authService = new AuthService();\n\nexport default authService;\n"]}
|
|
@@ -39,7 +39,9 @@ export default function getAuthenticationJsonSchemaPaths(arkosConfig, existingPa
|
|
|
39
39
|
: currentPath?.summary,
|
|
40
40
|
description: currentPath?.description ||
|
|
41
41
|
"Authenticates a user and returns an access token",
|
|
42
|
-
operationId: currentPath?.operationId
|
|
42
|
+
operationId: currentPath?.operationId?.includes(pathname)
|
|
43
|
+
? "login"
|
|
44
|
+
: currentPath?.operationId,
|
|
43
45
|
requestBody: currentPath?.requestBody || {
|
|
44
46
|
description: "User credentials",
|
|
45
47
|
required: true,
|
|
@@ -90,7 +92,9 @@ export default function getAuthenticationJsonSchemaPaths(arkosConfig, existingPa
|
|
|
90
92
|
? "Logout from the system"
|
|
91
93
|
: currentPath?.summary,
|
|
92
94
|
description: currentPath?.description || "Invalidates the current user's JWT token",
|
|
93
|
-
operationId: currentPath?.operationId
|
|
95
|
+
operationId: currentPath?.operationId?.includes(pathname)
|
|
96
|
+
? "logout"
|
|
97
|
+
: currentPath?.operationId,
|
|
94
98
|
security: [{ BearerAuth: [] }],
|
|
95
99
|
responses: {
|
|
96
100
|
...(currentPath?.responses || {}),
|
|
@@ -117,7 +121,9 @@ export default function getAuthenticationJsonSchemaPaths(arkosConfig, existingPa
|
|
|
117
121
|
? "Register a new user"
|
|
118
122
|
: currentPath?.summary,
|
|
119
123
|
description: currentPath?.description || "Creates a new user account",
|
|
120
|
-
operationId: currentPath?.operationId
|
|
124
|
+
operationId: currentPath?.operationId?.includes(pathname)
|
|
125
|
+
? "signup"
|
|
126
|
+
: currentPath?.operationId,
|
|
121
127
|
requestBody: currentPath?.requestBody || {
|
|
122
128
|
description: "User registration data",
|
|
123
129
|
required: true,
|
|
@@ -164,7 +170,9 @@ export default function getAuthenticationJsonSchemaPaths(arkosConfig, existingPa
|
|
|
164
170
|
: currentPath?.summary,
|
|
165
171
|
description: currentPath?.description ||
|
|
166
172
|
"Changes the password for the authenticated user",
|
|
167
|
-
operationId: currentPath?.operationId
|
|
173
|
+
operationId: currentPath?.operationId?.includes(pathname)
|
|
174
|
+
? "updatePassword"
|
|
175
|
+
: currentPath?.operationId,
|
|
168
176
|
security: [{ BearerAuth: [] }],
|
|
169
177
|
requestBody: currentPath?.requestBody || {
|
|
170
178
|
description: "Current and new password",
|
|
@@ -222,7 +230,9 @@ export default function getAuthenticationJsonSchemaPaths(arkosConfig, existingPa
|
|
|
222
230
|
: currentPath?.summary,
|
|
223
231
|
description: currentPath?.description ||
|
|
224
232
|
"Retrieves information about the currently authenticated user",
|
|
225
|
-
operationId: currentPath?.operationId
|
|
233
|
+
operationId: currentPath?.operationId?.includes(pathname)
|
|
234
|
+
? "getMe"
|
|
235
|
+
: currentPath?.operationId,
|
|
226
236
|
security: [{ BearerAuth: [] }],
|
|
227
237
|
responses: {
|
|
228
238
|
...(currentPath?.responses || {}),
|
|
@@ -257,7 +267,9 @@ export default function getAuthenticationJsonSchemaPaths(arkosConfig, existingPa
|
|
|
257
267
|
: currentPath?.summary,
|
|
258
268
|
description: currentPath?.description ||
|
|
259
269
|
"Updates information for the currently authenticated user",
|
|
260
|
-
operationId: currentPath?.operationId
|
|
270
|
+
operationId: currentPath?.operationId?.includes(pathname)
|
|
271
|
+
? "updateMe"
|
|
272
|
+
: currentPath?.operationId,
|
|
261
273
|
security: [{ BearerAuth: [] }],
|
|
262
274
|
requestBody: currentPath?.requestBody || {
|
|
263
275
|
description: "User data to update",
|
|
@@ -304,7 +316,9 @@ export default function getAuthenticationJsonSchemaPaths(arkosConfig, existingPa
|
|
|
304
316
|
: currentPath?.summary,
|
|
305
317
|
description: currentPath?.description ||
|
|
306
318
|
"Marks the current user's account as deleted",
|
|
307
|
-
operationId: currentPath?.operationId
|
|
319
|
+
operationId: currentPath?.operationId?.includes(pathname)
|
|
320
|
+
? "deleteMe"
|
|
321
|
+
: currentPath?.operationId,
|
|
308
322
|
security: [{ BearerAuth: [] }],
|
|
309
323
|
responses: {
|
|
310
324
|
...(currentPath?.responses || {}),
|
|
@@ -343,7 +357,9 @@ export default function getAuthenticationJsonSchemaPaths(arkosConfig, existingPa
|
|
|
343
357
|
: currentPath?.summary,
|
|
344
358
|
description: currentPath?.description ||
|
|
345
359
|
"Retrieves a list of all available authentication actions and permissions",
|
|
346
|
-
operationId: currentPath?.operationId
|
|
360
|
+
operationId: currentPath?.operationId?.includes(pathname)
|
|
361
|
+
? "findManyAuthAction"
|
|
362
|
+
: currentPath?.operationId,
|
|
347
363
|
security: [{ BearerAuth: [] }],
|
|
348
364
|
responses: {
|
|
349
365
|
...(currentPath?.responses || {}),
|
|
@@ -410,7 +426,9 @@ export default function getAuthenticationJsonSchemaPaths(arkosConfig, existingPa
|
|
|
410
426
|
: currentPath?.summary,
|
|
411
427
|
description: currentPath?.description ||
|
|
412
428
|
"Retrieves all authentication actions for a specific resource",
|
|
413
|
-
operationId: currentPath?.operationId
|
|
429
|
+
operationId: currentPath?.operationId?.includes(pathname)
|
|
430
|
+
? "findOneAuthAction"
|
|
431
|
+
: currentPath?.operationId,
|
|
414
432
|
security: [{ BearerAuth: [] }],
|
|
415
433
|
parameters: mergedParameters,
|
|
416
434
|
responses: {
|