better-auth
Version:
The most comprehensive authentication framework for TypeScript.
1 lines • 23.3 kB
Source Map (JSON)
{"version":3,"file":"generator.mjs","names":["schema: FieldSchema","parameters: OpenAPIParameter[]","properties: Record<string, any>","required: string[]","properties: Record<string, FieldSchema>","key","paths: Record<string, Path>","options"],"sources":["../../../src/plugins/open-api/generator.ts"],"sourcesContent":["import type { AuthContext, BetterAuthOptions } from \"@better-auth/core\";\nimport type {\n\tDBFieldAttribute,\n\tDBFieldAttributeConfig,\n\tDBFieldType,\n} from \"@better-auth/core/db\";\nimport type {\n\tEndpoint,\n\tEndpointOptions,\n\tOpenAPIParameter,\n\tOpenAPISchemaType,\n} from \"better-call\";\nimport * as z from \"zod\";\nimport { getEndpoints } from \"../../api\";\nimport { getAuthTables } from \"../../db\";\n\nexport interface Path {\n\tget?:\n\t\t| {\n\t\t\t\ttags?: string[];\n\t\t\t\toperationId?: string;\n\t\t\t\tdescription?: string;\n\t\t\t\tsecurity?: [{ bearerAuth: string[] }];\n\t\t\t\tparameters?: OpenAPIParameter[];\n\t\t\t\tresponses?: {\n\t\t\t\t\t[key in string]: {\n\t\t\t\t\t\tdescription?: string;\n\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\ttype?: OpenAPISchemaType;\n\t\t\t\t\t\t\t\t\tproperties?: Record<string, any>;\n\t\t\t\t\t\t\t\t\trequired?: string[];\n\t\t\t\t\t\t\t\t\t$ref?: string;\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t};\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t }\n\t\t| undefined;\n\tpost?:\n\t\t| {\n\t\t\t\ttags?: string[];\n\t\t\t\toperationId?: string;\n\t\t\t\tdescription?: string;\n\t\t\t\tsecurity?: [{ bearerAuth: string[] }];\n\t\t\t\tparameters?: OpenAPIParameter[];\n\t\t\t\trequestBody?: {\n\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\ttype?: OpenAPISchemaType;\n\t\t\t\t\t\t\t\tproperties?: Record<string, any>;\n\t\t\t\t\t\t\t\trequired?: string[];\n\t\t\t\t\t\t\t\t$ref?: string;\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t};\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t\tresponses?: {\n\t\t\t\t\t[key in string]: {\n\t\t\t\t\t\tdescription?: string;\n\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\ttype?: OpenAPISchemaType;\n\t\t\t\t\t\t\t\t\tproperties?: Record<string, any>;\n\t\t\t\t\t\t\t\t\trequired?: string[];\n\t\t\t\t\t\t\t\t\t$ref?: string;\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t};\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t }\n\t\t| undefined;\n}\n\ntype AllowedType = \"string\" | \"number\" | \"boolean\" | \"array\" | \"object\";\nconst allowedType = new Set([\"string\", \"number\", \"boolean\", \"array\", \"object\"]);\nfunction getTypeFromZodType(zodType: z.ZodType<any>) {\n\tconst type = zodType.type;\n\treturn allowedType.has(type) ? (type as AllowedType) : \"string\";\n}\n\nexport type FieldSchema = {\n\ttype: DBFieldType;\n\tdefault?:\n\t\t| (DBFieldAttributeConfig[\"defaultValue\"] | \"Generated at runtime\")\n\t\t| undefined;\n\treadOnly?: boolean | undefined;\n\tformat?: string;\n};\n\nexport type OpenAPIModelSchema = {\n\ttype: \"object\";\n\tproperties: Record<string, FieldSchema>;\n\trequired?: string[] | undefined;\n};\n\nfunction getFieldSchema(field: DBFieldAttribute) {\n\tconst schema: FieldSchema = {\n\t\ttype: field.type === \"date\" ? \"string\" : field.type,\n\t\t...(field.type === \"date\" && { format: \"date-time\" }),\n\t};\n\n\tif (field.defaultValue !== undefined) {\n\t\tschema.default =\n\t\t\ttypeof field.defaultValue === \"function\"\n\t\t\t\t? \"Generated at runtime\"\n\t\t\t\t: field.defaultValue;\n\t}\n\n\tif (field.input === false) {\n\t\tschema.readOnly = true;\n\t}\n\n\treturn schema;\n}\n\nfunction getParameters(options: EndpointOptions) {\n\tconst parameters: OpenAPIParameter[] = [];\n\tif (options.metadata?.openapi?.parameters) {\n\t\tparameters.push(...options.metadata.openapi.parameters);\n\t\treturn parameters;\n\t}\n\tif (options.query instanceof z.ZodObject) {\n\t\tObject.entries(options.query.shape).forEach(([key, value]) => {\n\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\tparameters.push({\n\t\t\t\t\tname: key,\n\t\t\t\t\tin: \"query\",\n\t\t\t\t\tschema: {\n\t\t\t\t\t\t...processZodType(value as z.ZodType<any>),\n\t\t\t\t\t\t...(\"minLength\" in value && (value as any).minLength\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tminLength: (value as any).minLength as number,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\treturn parameters;\n}\n\nfunction getRequestBody(options: EndpointOptions): any {\n\tif (options.metadata?.openapi?.requestBody) {\n\t\treturn options.metadata.openapi.requestBody;\n\t}\n\tif (!options.body) return undefined;\n\tif (\n\t\toptions.body instanceof z.ZodObject ||\n\t\toptions.body instanceof z.ZodOptional\n\t) {\n\t\t// @ts-expect-error\n\t\tconst shape = options.body.shape;\n\t\tif (!shape) return undefined;\n\t\tconst properties: Record<string, any> = {};\n\t\tconst required: string[] = [];\n\t\tObject.entries(shape).forEach(([key, value]) => {\n\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\tproperties[key] = processZodType(value as z.ZodType<any>);\n\t\t\t\tif (!(value instanceof z.ZodOptional)) {\n\t\t\t\t\trequired.push(key);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn {\n\t\t\trequired:\n\t\t\t\toptions.body instanceof z.ZodOptional\n\t\t\t\t\t? false\n\t\t\t\t\t: options.body\n\t\t\t\t\t\t? true\n\t\t\t\t\t\t: false,\n\t\t\tcontent: {\n\t\t\t\t\"application/json\": {\n\t\t\t\t\tschema: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties,\n\t\t\t\t\t\trequired,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\treturn undefined;\n}\n\nfunction processZodType(zodType: z.ZodType<any>): any {\n\t// optional unwrapping\n\tif (zodType instanceof z.ZodOptional) {\n\t\tconst innerType = (zodType as any)._def.innerType;\n\t\tconst innerSchema = processZodType(innerType);\n\t\tif (innerSchema.type) {\n\t\t\tconst type = Array.isArray(innerSchema.type)\n\t\t\t\t? innerSchema.type\n\t\t\t\t: [innerSchema.type];\n\t\t\treturn {\n\t\t\t\t...innerSchema,\n\t\t\t\ttype: Array.from(new Set([...type, \"null\"])),\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tanyOf: [innerSchema, { type: \"null\" }],\n\t\t};\n\t}\n\t// object unwrapping\n\tif (zodType instanceof z.ZodObject) {\n\t\tconst shape = (zodType as any).shape;\n\t\tif (shape) {\n\t\t\tconst properties: Record<string, any> = {};\n\t\t\tconst required: string[] = [];\n\t\t\tObject.entries(shape).forEach(([key, value]) => {\n\t\t\t\tif (value instanceof z.ZodType) {\n\t\t\t\t\tproperties[key] = processZodType(value as z.ZodType<any>);\n\t\t\t\t\tif (!(value instanceof z.ZodOptional)) {\n\t\t\t\t\t\trequired.push(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn {\n\t\t\t\ttype: \"object\",\n\t\t\t\tproperties,\n\t\t\t\t...(required.length > 0 ? { required } : {}),\n\t\t\t\tdescription: (zodType as any).description,\n\t\t\t};\n\t\t}\n\t}\n\n\t// For primitive types, get the correct type from the unwrapped ZodType\n\tconst baseSchema = {\n\t\ttype: getTypeFromZodType(zodType),\n\t\tdescription: (zodType as any).description,\n\t};\n\n\treturn baseSchema;\n}\n\nfunction getResponse(responses?: Record<string, any> | undefined) {\n\treturn {\n\t\t\"400\": {\n\t\t\tcontent: {\n\t\t\t\t\"application/json\": {\n\t\t\t\t\tschema: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\trequired: [\"message\"],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tdescription:\n\t\t\t\t\"Bad Request. Usually due to missing parameters, or invalid parameters.\",\n\t\t},\n\t\t\"401\": {\n\t\t\tcontent: {\n\t\t\t\t\"application/json\": {\n\t\t\t\t\tschema: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\trequired: [\"message\"],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tdescription: \"Unauthorized. Due to missing or invalid authentication.\",\n\t\t},\n\t\t\"403\": {\n\t\t\tcontent: {\n\t\t\t\t\"application/json\": {\n\t\t\t\t\tschema: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tdescription:\n\t\t\t\t\"Forbidden. You do not have permission to access this resource or to perform this action.\",\n\t\t},\n\t\t\"404\": {\n\t\t\tcontent: {\n\t\t\t\t\"application/json\": {\n\t\t\t\t\tschema: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tdescription: \"Not Found. The requested resource was not found.\",\n\t\t},\n\t\t\"429\": {\n\t\t\tcontent: {\n\t\t\t\t\"application/json\": {\n\t\t\t\t\tschema: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tdescription:\n\t\t\t\t\"Too Many Requests. You have exceeded the rate limit. Try again later.\",\n\t\t},\n\t\t\"500\": {\n\t\t\tcontent: {\n\t\t\t\t\"application/json\": {\n\t\t\t\t\tschema: {\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tdescription:\n\t\t\t\t\"Internal Server Error. This is a problem with the server that you cannot fix.\",\n\t\t},\n\t\t...responses,\n\t} as any;\n}\n\nfunction toOpenApiPath(path: string) {\n\t// /reset-password/:token -> /reset-password/{token}\n\t// replace all : with {}\n\treturn path\n\t\t.split(\"/\")\n\t\t.map((part) => (part.startsWith(\":\") ? `{${part.slice(1)}}` : part))\n\t\t.join(\"/\");\n}\n\nexport async function generator(ctx: AuthContext, options: BetterAuthOptions) {\n\tconst baseEndpoints = getEndpoints(ctx, {\n\t\t...options,\n\t\tplugins: [],\n\t});\n\n\tconst tables = getAuthTables({\n\t\t...options,\n\t\tsession: {\n\t\t\t...options.session,\n\t\t\tstoreSessionInDatabase: true, // Forcing this to true to return the session table schema\n\t\t},\n\t});\n\tconst models = Object.entries(tables).reduce<\n\t\tRecord<string, OpenAPIModelSchema>\n\t>((acc, [key, value]) => {\n\t\tconst modelName = key.charAt(0).toUpperCase() + key.slice(1);\n\t\tconst fields = value.fields;\n\t\tconst required: string[] = [];\n\t\tconst properties: Record<string, FieldSchema> = {\n\t\t\tid: { type: \"string\" },\n\t\t};\n\t\tObject.entries(fields).forEach(([fieldKey, fieldValue]) => {\n\t\t\tif (!fieldValue) return;\n\t\t\tproperties[fieldKey] = getFieldSchema(fieldValue);\n\t\t\tif (fieldValue.required && fieldValue.input !== false) {\n\t\t\t\trequired.push(fieldKey);\n\t\t\t}\n\t\t});\n\n\t\tObject.entries(properties).forEach(([key, prop]) => {\n\t\t\tconst field = value.fields[key];\n\t\t\tif (field && field.type === \"date\" && prop.type === \"string\") {\n\t\t\t\tprop.format = \"date-time\";\n\t\t\t}\n\t\t});\n\t\tacc[modelName] = {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired,\n\t\t};\n\t\treturn acc;\n\t}, {});\n\n\tconst components = {\n\t\tschemas: {\n\t\t\t...models,\n\t\t},\n\t};\n\n\tconst paths: Record<string, Path> = {};\n\n\tObject.entries(baseEndpoints.api).forEach(([_, value]) => {\n\t\tif (!value.path || ctx.options.disabledPaths?.includes(value.path)) return;\n\t\tconst options = value.options as EndpointOptions;\n\t\tif (options.metadata?.SERVER_ONLY) return;\n\t\tconst path = toOpenApiPath(value.path);\n\t\tif (options.method === \"GET\" || options.method === \"DELETE\") {\n\t\t\tpaths[path] = {\n\t\t\t\t...paths[path],\n\t\t\t\t[options.method.toLowerCase()]: {\n\t\t\t\t\ttags: [\"Default\", ...(options.metadata?.openapi?.tags || [])],\n\t\t\t\t\tdescription: options.metadata?.openapi?.description,\n\t\t\t\t\toperationId: options.metadata?.openapi?.operationId,\n\t\t\t\t\tsecurity: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbearerAuth: [],\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tparameters: getParameters(options),\n\t\t\t\t\tresponses: getResponse(options.metadata?.openapi?.responses),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tif (\n\t\t\toptions.method === \"POST\" ||\n\t\t\toptions.method === \"PATCH\" ||\n\t\t\toptions.method === \"PUT\"\n\t\t) {\n\t\t\tconst body = getRequestBody(options);\n\t\t\tpaths[path] = {\n\t\t\t\t...paths[path],\n\t\t\t\t[options.method.toLowerCase()]: {\n\t\t\t\t\ttags: [\"Default\", ...(options.metadata?.openapi?.tags || [])],\n\t\t\t\t\tdescription: options.metadata?.openapi?.description,\n\t\t\t\t\toperationId: options.metadata?.openapi?.operationId,\n\t\t\t\t\tsecurity: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbearerAuth: [],\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tparameters: getParameters(options),\n\t\t\t\t\t...(body\n\t\t\t\t\t\t? { requestBody: body }\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\trequestBody: {\n\t\t\t\t\t\t\t\t\t//set body none\n\t\t\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\t\t\t\t\tproperties: {},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}),\n\t\t\t\t\tresponses: getResponse(options.metadata?.openapi?.responses),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t});\n\n\tfor (const plugin of options.plugins || []) {\n\t\tif (plugin.id === \"open-api\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst pluginEndpoints = getEndpoints(ctx, {\n\t\t\t...options,\n\t\t\tplugins: [plugin],\n\t\t});\n\t\tconst api = Object.keys(pluginEndpoints.api)\n\t\t\t.map((key) => {\n\t\t\t\tif (\n\t\t\t\t\tbaseEndpoints.api[key as keyof typeof baseEndpoints.api] === undefined\n\t\t\t\t) {\n\t\t\t\t\treturn pluginEndpoints.api[key as keyof typeof pluginEndpoints.api];\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t})\n\t\t\t.filter((x) => x !== null) as Endpoint[];\n\t\tObject.entries(api).forEach(([key, value]) => {\n\t\t\tif (!value.path || ctx.options.disabledPaths?.includes(value.path))\n\t\t\t\treturn;\n\t\t\tconst options = value.options as EndpointOptions;\n\t\t\tif (options.metadata?.SERVER_ONLY) return;\n\t\t\tconst path = toOpenApiPath(value.path);\n\t\t\tif (options.method === \"GET\" || options.method === \"DELETE\") {\n\t\t\t\tpaths[path] = {\n\t\t\t\t\t...paths[path],\n\t\t\t\t\t[options.method.toLowerCase()]: {\n\t\t\t\t\t\ttags: options.metadata?.openapi?.tags || [\n\t\t\t\t\t\t\tplugin.id.charAt(0).toUpperCase() + plugin.id.slice(1),\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdescription: options.metadata?.openapi?.description,\n\t\t\t\t\t\toperationId: options.metadata?.openapi?.operationId,\n\t\t\t\t\t\tsecurity: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tbearerAuth: [],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tparameters: getParameters(options),\n\t\t\t\t\t\tresponses: getResponse(options.metadata?.openapi?.responses),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (\n\t\t\t\toptions.method === \"POST\" ||\n\t\t\t\toptions.method === \"PATCH\" ||\n\t\t\t\toptions.method === \"PUT\"\n\t\t\t) {\n\t\t\t\tpaths[path] = {\n\t\t\t\t\t...paths[path],\n\t\t\t\t\t[options.method.toLowerCase()]: {\n\t\t\t\t\t\ttags: options.metadata?.openapi?.tags || [\n\t\t\t\t\t\t\tplugin.id.charAt(0).toUpperCase() + plugin.id.slice(1),\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdescription: options.metadata?.openapi?.description,\n\t\t\t\t\t\toperationId: options.metadata?.openapi?.operationId,\n\t\t\t\t\t\tsecurity: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tbearerAuth: [],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tparameters: getParameters(options),\n\t\t\t\t\t\trequestBody: getRequestBody(options),\n\t\t\t\t\t\tresponses: getResponse(options.metadata?.openapi?.responses),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t});\n\t}\n\n\tconst res = {\n\t\topenapi: \"3.1.1\",\n\t\tinfo: {\n\t\t\ttitle: \"Better Auth\",\n\t\t\tdescription: \"API Reference for your Better Auth Instance\",\n\t\t\tversion: \"1.1.0\",\n\t\t},\n\t\tcomponents: {\n\t\t\t...components,\n\t\t\tsecuritySchemes: {\n\t\t\t\tapiKeyCookie: {\n\t\t\t\t\ttype: \"apiKey\",\n\t\t\t\t\tin: \"cookie\",\n\t\t\t\t\tname: \"apiKeyCookie\",\n\t\t\t\t\tdescription: \"API Key authentication via cookie\",\n\t\t\t\t},\n\t\t\t\tbearerAuth: {\n\t\t\t\t\ttype: \"http\",\n\t\t\t\t\tscheme: \"bearer\",\n\t\t\t\t\tdescription: \"Bearer token authentication\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tsecurity: [\n\t\t\t{\n\t\t\t\tapiKeyCookie: [],\n\t\t\t\tbearerAuth: [],\n\t\t\t},\n\t\t],\n\t\tservers: [\n\t\t\t{\n\t\t\t\turl: ctx.baseURL,\n\t\t\t},\n\t\t],\n\t\ttags: [\n\t\t\t{\n\t\t\t\tname: \"Default\",\n\t\t\t\tdescription:\n\t\t\t\t\t\"Default endpoints that are included with Better Auth by default. These endpoints are not part of any plugin.\",\n\t\t\t},\n\t\t],\n\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