diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..76c8b43 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,6 @@ +import openapi from './openapiPlugin.js'; +import rapidoc from './rapidocPlugin.js'; +import redoc from './redocPlugin.js'; +import scalar from './scalarPlugin.js'; +import swaggerUI from './swaggerUIPlugin.js'; +export { openapi, swaggerUI, rapidoc, redoc, scalar }; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..0e99f10 --- /dev/null +++ b/dist/index.js @@ -0,0 +1,7 @@ +import openapi from './openapiPlugin.js'; +import rapidoc from './rapidocPlugin.js'; +import redoc from './redocPlugin.js'; +import scalar from './scalarPlugin.js'; +import swaggerUI from './swaggerUIPlugin.js'; +export { openapi, swaggerUI, rapidoc, redoc, scalar }; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000..79c63ed --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,oBAAoB,CAAA;AACxC,OAAO,OAAO,MAAM,oBAAoB,CAAA;AACxC,OAAO,KAAK,MAAM,kBAAkB,CAAA;AACpC,OAAO,MAAM,MAAM,mBAAmB,CAAA;AACtC,OAAO,SAAS,MAAM,sBAAsB,CAAA;AAE5C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA"} \ No newline at end of file diff --git a/dist/openapi/generators.d.ts b/dist/openapi/generators.d.ts new file mode 100644 index 0000000..704914d --- /dev/null +++ b/dist/openapi/generators.d.ts @@ -0,0 +1,5 @@ +import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'; +import type { PayloadRequest } from 'payload'; +import type { SanitizedPluginOptions } from '../types.js'; +export declare const generateV30Spec: (req: Pick, options: SanitizedPluginOptions) => Promise; +export declare const generateV31Spec: (req: Pick, options: SanitizedPluginOptions) => Promise; diff --git a/dist/openapi/generators.js b/dist/openapi/generators.js new file mode 100644 index 0000000..e3acd04 --- /dev/null +++ b/dist/openapi/generators.js @@ -0,0 +1,536 @@ +import _jsonSchemaToOpenapiSchema from '@openapi-contrib/json-schema-to-openapi-schema'; +import { create } from 'mutative'; +import { entityToJSONSchema } from 'payload'; +import { mapValuesAsync, visitObjectNodes } from '../utils/objects.js'; +import { collectionName, componentName, globalName } from './naming.js'; +import { apiKeySecurity, generateSecuritySchemes } from './securitySchemes.js'; +const baseQueryParams = [ + { in: 'query', name: 'depth', schema: { type: 'number' } }, + { in: 'query', name: 'locale', schema: { type: 'string' } }, + { in: 'query', name: 'fallback-locale', schema: { type: 'string' } }, +]; +const createQueryParams = [ + { in: 'query', name: 'depth', schema: { type: 'number' } }, + { in: 'query', name: 'locale', schema: { type: 'string' } }, +]; +async function jsonSchemaToOpenapiSchema(schema) { + return await _jsonSchemaToOpenapiSchema(schema); +} +const adjustRefTargets = (payload, spec) => { + const search = /^#\/definitions\/(.*)/; + visitObjectNodes(spec, (subject, key, value) => { + const isRef = key === '$ref' && typeof value === 'string'; + if (!isRef) { + return; + } + subject[key] = value.replace(search, (_match, name) => { + if (name === 'supportedTimezones') { + return '#/components/schemas/supportedTimezones'; + } + const collection = payload.collections[name]; + if (collection !== undefined) { + name = collectionName(payload.collections[name]).singular; + return `#/components/schemas/${componentName('schemas', name)}`; + } + const global = payload.globals.config.find(({ slug }) => slug === name); + if (global !== undefined) { + return `#/components/schemas/${componentName('schemas', globalName(global))}`; + } + throw new Error(`Unknown reference: ${name}`); + }); + }); +}; +const removeInterfaceNames = (target) => create(target, draft => visitObjectNodes(draft, (subject, key) => { + if (key === 'interfaceName') { + subject[key] = undefined; + } +})); +const composeRef = (type, name, options) => ({ + $ref: `#/components/${type}/${componentName(type, name, options)}`, +}); +const generateSchemaObject = (config, collection) => { + const schema = entityToJSONSchema(config, removeInterfaceNames(collection.config), // the `interfaceName` option causes `entityToJSONSchema` to add a reference to a non-existing schema + new Map(), 'text', undefined); + return { + ...schema, + title: collectionName(collection).singular, + }; +}; +const requestBodySchema = (fields, schema) => ({ + ...schema, + properties: Object.fromEntries(Object.entries(schema.properties ?? {}).map(([fieldName, schema]) => { + const field = fields.find(field => field.name === fieldName); + if (field?.type === 'relationship') { + const target = Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]; + return [fieldName, { type: 'string', description: `ID of the ${target.join('/')}` }]; + } + return [fieldName, schema]; + })), +}); +const generateRequestBodySchema = (config, collection, type) => { + const schema = entityToJSONSchema(config, removeInterfaceNames(collection.config), // the `interfaceName` option causes `entityToJSONSchema` to add a reference to a non-existing schema + new Map(), 'text', undefined); + schema.properties = Object.fromEntries(Object.entries(schema.properties ?? {}).filter(([property]) => !['id', 'createdAt', 'updatedAt'].includes(property))); + schema.required = (schema.required ?? []).filter(property => schema.properties?.[property] !== undefined); + if (type === 'patch') { + schema.required = []; + } + return { + description: collectionName(collection).singular, + content: { + 'application/json': { + schema: requestBodySchema(collection.config.fields, schema), + }, + }, + }; +}; +const generateQueryOperationSchemas = (collection) => { + const { singular } = collectionName(collection); + return { + [componentName('schemas', singular, { suffix: 'QueryOperations' })]: { + title: `${singular} query operations`, + type: 'object', + properties: Object.fromEntries(collection.config.fields.filter(({ type }) => ['number', 'text', 'email', 'date', 'radio', 'checkbox', 'select'].includes(type)).map(field => { + const comparedValueSchema = (() => { + switch (field.type) { + case 'number': + return { type: 'number' }; + case 'text': + return { type: 'string' }; + case 'email': + return { type: 'string', format: 'email' }; + case 'date': + return { type: 'string', format: 'date-time' }; + case 'checkbox': + return { type: 'boolean' }; + case 'radio': + case 'select': + return { + type: 'string', + enum: field.options.map(it => typeof it === 'string' ? it : it.value), + }; + } + })(); + const properties = { + ['equals']: comparedValueSchema, + ['not_equals']: comparedValueSchema, + ['in']: { type: 'string' }, + ['not_in']: { type: 'string' }, + }; + if (field.type === 'text') { + properties['like'] = comparedValueSchema; + } + if (field.type === 'text' || field.type === 'email') { + properties['contains'] = comparedValueSchema; + } + if (field.type === 'number' || field.type === 'date') { + properties['greater_than'] = comparedValueSchema; + properties['greater_than_equal'] = comparedValueSchema; + properties['less_than'] = comparedValueSchema; + properties['less_than_equal'] = comparedValueSchema; + } + return [ + field.name, + { + type: 'object', + properties, + }, + ]; + })), + }, + [componentName('schemas', singular, { suffix: 'QueryOperationsAnd' })]: { + title: `${singular} query conjunction`, + type: 'object', + properties: { + and: { + type: 'array', + items: { + anyOf: [ + composeRef('schemas', singular, { suffix: 'QueryOperations' }), + composeRef('schemas', singular, { suffix: 'QueryOperationsAnd' }), + composeRef('schemas', singular, { suffix: 'QueryOperationsOr' }), + ], + }, + }, + }, + required: ['and'], + }, + [componentName('schemas', singular, { suffix: 'QueryOperationsOr' })]: { + title: `${singular} query disjunction`, + type: 'object', + properties: { + or: { + type: 'array', + items: { + anyOf: [ + composeRef('schemas', singular, { suffix: 'QueryOperations' }), + composeRef('schemas', singular, { suffix: 'QueryOperationsAnd' }), + composeRef('schemas', singular, { suffix: 'QueryOperationsOr' }), + ], + }, + }, + }, + required: ['or'], + }, + }; +}; +const generateCollectionResponses = (collection) => { + const { singular, plural } = collectionName(collection); + return { + [componentName('responses', singular)]: { + description: `${singular} object`, + content: { + 'application/json': { + schema: composeRef('schemas', singular), + }, + }, + }, + [componentName('responses', singular, { prefix: 'New' })]: { + description: `${singular} object`, + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + message: { type: 'string' }, + doc: { + allOf: [ + composeRef('schemas', singular), + { + type: 'object', + properties: { + id: { type: 'string' }, + createdAt: { + type: 'string', + format: 'date-time', + }, + updatedAt: { + type: 'string', + format: 'date-time', + }, + }, + required: ['id', 'createdAt', 'updatedAt'], + }, + ], + }, + }, + required: ['message', 'doc'], + }, + }, + }, + }, + [componentName('responses', singular, { suffix: 'NotFound' })]: { + description: `${singular} not found`, + }, + [componentName('responses', singular, { suffix: 'List' })]: { + description: `List of ${plural}`, + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + docs: { + type: 'array', + items: composeRef('schemas', singular), + }, + totalDocs: { type: 'integer' }, + limit: { type: 'integer' }, + totalPages: { type: 'integer' }, + page: { type: 'integer' }, + pagingCounter: { type: 'integer' }, + hasPrevPage: { type: 'boolean' }, + hasNextPage: { type: 'boolean' }, + prevPage: { type: ['integer', 'null'] }, + nextPage: { type: ['integer', 'null'] }, + }, + required: [ + 'docs', + 'totalDocs', + 'limit', + 'totalPages', + 'page', + 'pagingCounter', + 'hasPrevPage', + 'hasNextPage', + 'prevPage', + 'nextPage', + ], + }, + }, + }, + }, + }; +}; +const isOpenToPublic = async (checker) => { + try { + const result = await checker(new Proxy({}, { + get(target, p, receiver) { + if (p === 'req') { + throw new Error(); + } + return Reflect.get(target, p, receiver); + }, + })); + return result === true; + } + catch { + return false; + } +}; +const generateCollectionOperations = async (collection) => { + const { slug } = collection.config; + const { singular, plural } = collectionName(collection); + const tags = [plural]; + const singleObjectResponses = { + 200: composeRef('responses', singular), + 404: composeRef('responses', singular, { suffix: 'NotFound' }), + }; + return { + [`/api/${slug}`]: { + get: { + operationId: componentName('schemas', plural, { prefix: 'list' }), + summary: `Retrieve a list of ${plural}`, + tags, + parameters: [ + { in: 'query', name: 'page', schema: { type: 'number' } }, + { in: 'query', name: 'limit', schema: { type: 'number' } }, + ...baseQueryParams, + { + in: 'query', + name: 'sort', + schema: { + type: 'string', + enum: collection.config.fields.flatMap(field => { + if (field.type === 'number' || + field.type === 'text' || + field.type === 'email' || + field.type === 'date') { + return [field.name, `-${field.name}`]; + } + return []; + }), + }, + }, + { + in: 'query', + name: 'where', + style: 'deepObject', + schema: { + allOf: [ + { type: 'object' }, + { + anyOf: [ + composeRef('schemas', singular, { suffix: 'QueryOperations' }), + composeRef('schemas', singular, { suffix: 'QueryOperationsAnd' }), + composeRef('schemas', singular, { suffix: 'QueryOperationsOr' }), + ], + }, + ], + }, + }, + ], + responses: { + 200: composeRef('responses', singular, { suffix: 'List' }), + }, + security: (await isOpenToPublic(collection.config.access.read)) ? [] : [apiKeySecurity], + }, + post: { + operationId: componentName('schemas', singular, { prefix: 'create' }), + summary: `Create a new ${singular}`, + tags, + parameters: createQueryParams, + requestBody: composeRef('requestBodies', singular), + responses: { + 201: composeRef('responses', singular, { prefix: 'New' }), + }, + security: (await isOpenToPublic(collection.config.access.create)) ? [] : [apiKeySecurity], + }, + }, + [`/api/${slug}/{id}`]: { + parameters: [ + ...baseQueryParams, + { + in: 'path', + name: 'id', + description: `ID of the ${singular}`, + required: true, + schema: { + type: 'string', + }, + }, + ], + get: { + operationId: componentName('schemas', singular, { + prefix: 'find', + suffix: 'ById', + }), + summary: `Find a ${singular} by ID`, + tags, + responses: singleObjectResponses, + security: (await isOpenToPublic(collection.config.access.read)) ? [] : [apiKeySecurity], + }, + patch: { + operationId: componentName('schemas', singular, { prefix: 'update' }), + summary: `Update a ${singular}`, + tags, + requestBody: composeRef('requestBodies', singular, { suffix: 'Patch' }), + responses: singleObjectResponses, + security: (await isOpenToPublic(collection.config.access.update)) ? [] : [apiKeySecurity], + }, + delete: { + operationId: componentName('schemas', singular, { prefix: 'delete' }), + summary: `Delete a ${singular}`, + tags, + responses: singleObjectResponses, + security: (await isOpenToPublic(collection.config.access.delete)) ? [] : [apiKeySecurity], + }, + }, + }; +}; +const generateGlobalResponse = (global) => { + const name = globalName(global); + return { + description: name, + content: { + 'application/json': { + schema: composeRef('schemas', name, { suffix: 'Read' }), + }, + }, + }; +}; +const generateGlobalRequestBody = (global) => { + const name = globalName(global); + return { + description: name, + content: { + 'application/json': { + schema: composeRef('schemas', name, { suffix: 'Write' }), + }, + }, + }; +}; +const generateGlobalSchemas = (config, global) => { + const schema = entityToJSONSchema(config, removeInterfaceNames(global), new Map(), 'text', undefined); + return { + [componentName('schemas', globalName(global))]: { ...schema, title: globalName(global) }, + [componentName('schemas', globalName(global), { suffix: 'Read' })]: { + title: `${globalName(global)} (if present)`, + oneOf: [schema, { type: 'object', properties: {} }], + }, + [componentName('schemas', globalName(global), { suffix: 'Write' })]: { + ...requestBodySchema(global.fields, schema), + title: `${globalName(global)} (writable fields)`, + }, + }; +}; +const generateGlobalOperations = async (global) => { + const slug = global.slug; + const singular = globalName(global); + const tags = [singular]; + return { + [`/api/globals/${slug}`]: { + get: { + summary: `Get the ${singular}`, + tags, + parameters: [...baseQueryParams], + responses: { 200: composeRef('responses', singular) }, + security: (await isOpenToPublic(global.access.read)) ? [] : [apiKeySecurity], + }, + post: { + summary: `Update the ${singular}`, + tags, + requestBody: composeRef('requestBodies', singular), + responses: { 200: composeRef('responses', singular) }, + security: (await isOpenToPublic(global.access.update)) ? [] : [apiKeySecurity], + }, + }, + }; +}; +const generateComponents = (req) => { + const schemas = { + supportedTimezones: { + type: 'string', + example: 'Europe/Prague', + }, + }; + for (const collection of Object.values(req.payload.collections)) { + const { singular } = collectionName(collection); + schemas[componentName('schemas', singular)] = generateSchemaObject(req.payload.config, collection); + } + for (const collection of Object.values(req.payload.collections)) { + Object.assign(schemas, generateQueryOperationSchemas(collection)); + } + for (const global of req.payload.globals.config) { + Object.assign(schemas, generateGlobalSchemas(req.payload.config, global)); + } + const requestBodies = {}; + for (const collection of Object.values(req.payload.collections)) { + const { singular } = collectionName(collection); + requestBodies[componentName('requestBodies', singular)] = generateRequestBodySchema(req.payload.config, collection, 'post'); + requestBodies[componentName('requestBodies', singular, { suffix: 'Patch' })] = + generateRequestBodySchema(req.payload.config, collection, 'patch'); + } + for (const global of req.payload.globals.config) { + requestBodies[componentName('requestBodies', globalName(global))] = + generateGlobalRequestBody(global); + } + const responses = Object.assign({}, ...Object.values(req.payload.collections).map(generateCollectionResponses), ...req.payload.globals.config.map(global => ({ + [componentName('responses', globalName(global))]: generateGlobalResponse(global), + }))); + return { schemas, requestBodies, responses }; +}; +export const generateV30Spec = async (req, options) => { + const { schemas, requestBodies, responses } = generateComponents(req); + const spec = { + openapi: '3.0.3', + info: options.metadata, + servers: [{ url: `${req.protocol}//${req.headers.get('host')}` }], + paths: Object.assign({}, ...(await Promise.all(Object.values(req.payload.collections).map(generateCollectionOperations))), ...(await Promise.all(req.payload.globals.config.map(generateGlobalOperations)))), + components: { + securitySchemes: generateSecuritySchemes(options.authEndpoint), + schemas: await mapValuesAsync(jsonSchemaToOpenapiSchema, schemas), + requestBodies: await mapValuesAsync(async (requestBody) => ({ + ...requestBody, + content: (await mapValuesAsync(async (contentItem) => ({ + ...contentItem, + schema: contentItem.schema + ? await jsonSchemaToOpenapiSchema(contentItem.schema) + : undefined, + }), requestBody.content)), + }), requestBodies), + responses: await mapValuesAsync(async (response) => { + return { + ...response, + content: response.content !== undefined + ? (await mapValuesAsync(async (contentItem) => ({ + ...contentItem, + schema: contentItem.schema + ? await jsonSchemaToOpenapiSchema(contentItem.schema) + : undefined, + }), response.content)) + : {}, + }; + }, responses), + }, + }; + adjustRefTargets(req.payload, spec); + return spec; +}; +export const generateV31Spec = async (req, options) => { + const { schemas, requestBodies, responses } = generateComponents(req); + const spec = { + openapi: '3.1.0', + info: options.metadata, + servers: [{ url: `${req.protocol}//${req.headers.get('host')}` }], + paths: Object.assign({}, ...(await Promise.all(Object.values(req.payload.collections).map(generateCollectionOperations))), ...(await Promise.all(req.payload.globals.config.map(generateGlobalOperations)))), + components: { + securitySchemes: generateSecuritySchemes(options.authEndpoint), + schemas: schemas, + requestBodies, + responses, + }, + }; + adjustRefTargets(req.payload, spec); + return spec; +}; +//# sourceMappingURL=generators.js.map \ No newline at end of file diff --git a/dist/openapi/generators.js.map b/dist/openapi/generators.js.map new file mode 100644 index 0000000..45011f3 --- /dev/null +++ b/dist/openapi/generators.js.map @@ -0,0 +1 @@ +{"version":3,"file":"generators.js","sourceRoot":"","sources":["../../src/openapi/generators.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,MAAM,gDAAgD,CAAA;AAEvF,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAejC,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE5C,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ACtB,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACjE,KAAK,EAAE,MAAM,CAAC,MAAM,CAClB,EAAE,EACF,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CACnB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,4BAA4B,CAAC,CACzE,CAAC,EACF,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,CAAC,CACjF;QACD,UAAU,EAAE;YACV,eAAe,EAAE,uBAAuB,CAAC,OAAO,CAAC,YAAY,CAAC;YAC9D,OAAO,EAAE,OAAmD;YAC5D,aAAa;YACb,SAAS;SACV;KAC6B,CAAA;IAEhC,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAEnC,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/openapi/naming.d.ts b/dist/openapi/naming.d.ts new file mode 100644 index 0000000..854bd03 --- /dev/null +++ b/dist/openapi/naming.d.ts @@ -0,0 +1,11 @@ +import type { Collection, SanitizedGlobalConfig } from 'payload'; +export declare const collectionName: (collection: Collection) => { + singular: string; + plural: string; +}; +export declare const globalName: (global: SanitizedGlobalConfig) => string; +export type ComponentType = 'schemas' | 'responses' | 'requestBodies'; +export declare const componentName: (type: ComponentType, name: string, { prefix, suffix }?: { + suffix?: string; + prefix?: string; +}) => string; diff --git a/dist/openapi/naming.js b/dist/openapi/naming.js new file mode 100644 index 0000000..b32ffa1 --- /dev/null +++ b/dist/openapi/naming.js @@ -0,0 +1,46 @@ +import { camelize } from '../utils/strings.js'; +export const collectionName = (collection) => { + const labels = collection.config.labels; + if (labels === undefined) { + return { singular: collection.config.slug, plural: collection.config.slug }; + } + const label = (value) => { + if (typeof value === 'string') { + return value; + } + if (typeof value === 'function') { + return collection.config.slug; // TODO actually use the label function + } + return value['en'] ?? collection.config.slug; + }; + return { singular: label(labels.singular), plural: label(labels.plural) }; +}; +export const globalName = (global) => { + if (global.label === undefined) { + return global.slug; + } + if (typeof global.label === 'string') { + return global.label; + } + if (typeof global.label === 'function') { + return global.slug; // TODO actually use the label function + } + return global.label['en']; +}; +export const componentName = (type, name, { prefix, suffix } = {}) => { + name = camelize(name); + if (prefix) { + name = prefix + name; + } + if (suffix) { + name += suffix; + } + if (type === 'responses') { + name += 'Response'; + } + if (type === 'requestBodies') { + name += 'RequestBody'; + } + return name; +}; +//# sourceMappingURL=naming.js.map \ No newline at end of file diff --git a/dist/openapi/naming.js.map b/dist/openapi/naming.js.map new file mode 100644 index 0000000..1588de6 --- /dev/null +++ b/dist/openapi/naming.js.map @@ -0,0 +1 @@ +{"version":3,"file":"naming.js","sourceRoot":"","sources":["../../src/openapi/naming.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,UAAsB,EAAwC,EAAE;IAC7F,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAA;IAEvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IAC7E,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,KAA6B,EAAU,EAAE;QACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAA;QACd,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YAChC,OAAO,UAAU,CAAC,MAA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AA;IACvB,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/openapi/securitySchemes.d.ts b/dist/openapi/securitySchemes.d.ts new file mode 100644 index 0000000..d55ecc4 --- /dev/null +++ b/dist/openapi/securitySchemes.d.ts @@ -0,0 +1,5 @@ +import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'; +export declare const apiKeySecurity: { + ApiKey: never[]; +}; +export declare const generateSecuritySchemes: (tokenUrl: string) => Record; diff --git a/dist/openapi/securitySchemes.js b/dist/openapi/securitySchemes.js new file mode 100644 index 0000000..9b2b796 --- /dev/null +++ b/dist/openapi/securitySchemes.js @@ -0,0 +1,13 @@ +export const apiKeySecurity = { ApiKey: [] }; +export const generateSecuritySchemes = (tokenUrl) => ({ + ApiKey: { + type: 'oauth2', + flows: { + password: { + tokenUrl: `/api/${tokenUrl}`, + scopes: {}, + }, + }, + }, +}); +//# sourceMappingURL=securitySchemes.js.map \ No newline at end of file diff --git a/dist/openapi/securitySchemes.js.map b/dist/openapi/securitySchemes.js.map new file mode 100644 index 0000000..d306b92 --- /dev/null +++ b/dist/openapi/securitySchemes.js.map @@ -0,0 +1 @@ +{"version":3,"file":"securitySchemes.js","sourceRoot":"","sources":["../../src/openapi/securitySchemes.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;AAE5C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,QAAgB,EACmE,EAAE,CAAC,CAAC;IACvF,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE;YACL,QAAQ,EAAE;gBACR,QAAQ,EAAE,QAAQ,QAAQ,EAAE;gBAC5B,MAAM,EAAE,EAAE;aACX;SACF;KACF;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/openapiPlugin.d.ts b/dist/openapiPlugin.d.ts new file mode 100644 index 0000000..b3690cd --- /dev/null +++ b/dist/openapiPlugin.d.ts @@ -0,0 +1,4 @@ +import type { Plugin } from 'payload'; +import type { PluginOptions } from './types.js'; +declare const openapi: ({ specEndpoint, authEndpoint, openapiVersion, metadata, enabled, }: PluginOptions) => Plugin; +export default openapi; diff --git a/dist/openapiPlugin.js b/dist/openapiPlugin.js new file mode 100644 index 0000000..a211111 --- /dev/null +++ b/dist/openapiPlugin.js @@ -0,0 +1,28 @@ +import { createOAuthPasswordFlowHandler, createOpenAPIRequestHandler } from './requestHandlers.js'; +const openapi = ({ specEndpoint = '/openapi.json', authEndpoint = '/openapi-auth', openapiVersion = '3.0', metadata, enabled = true, }) => ({ endpoints = [], ...config }) => { + if (!enabled) { + return { ...config, endpoints }; + } + return { + ...config, + endpoints: [ + ...endpoints, + { + method: 'get', + path: specEndpoint, + handler: createOpenAPIRequestHandler({ + openapiVersion, + metadata, + authEndpoint, + }), + }, + { + method: 'post', + path: authEndpoint, + handler: createOAuthPasswordFlowHandler(), + }, + ], + }; +}; +export default openapi; +//# sourceMappingURL=openapiPlugin.js.map \ No newline at end of file diff --git a/dist/openapiPlugin.js.map b/dist/openapiPlugin.js.map new file mode 100644 index 0000000..7b51102 --- /dev/null +++ b/dist/openapiPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"openapiPlugin.js","sourceRoot":"","sources":["../src/openapiPlugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAA;AAElG,MAAM,OAAO,GACX,CAAC,EACC,YAAY,GAAG,eAAe,EAC9B,YAAY,GAAG,eAAe,EAC9B,cAAc,GAAG,KAAK,EACtB,QAAQ,EACR,OAAO,GAAG,IAAI,GACA,EAAU,EAAE,CAC5B,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE;IAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAA;IACjC,CAAC;IAED,OAAO;QACL,GAAG,MAAM;QACT,SAAS,EAAE;YACT,GAAG,SAAS;YACZ;gBACE,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,2BAA2B,CAAC;oBACnC,cAAc;oBACd,QAAQ;oBACR,YAAY;iBACb,CAAC;aACH;YACD;gBACE,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,8BAA8B,EAAE;aAC1C;SACF;KACF,CAAA;AACH,CAAC,CAAA;AAEH,eAAe,OAAO,CAAA"} \ No newline at end of file diff --git a/dist/rapidocPlugin.d.ts b/dist/rapidocPlugin.d.ts new file mode 100644 index 0000000..a2b6212 --- /dev/null +++ b/dist/rapidocPlugin.d.ts @@ -0,0 +1,7 @@ +import type { Plugin } from "payload"; +declare const rapidoc: ({ specEndpoint, docsUrl, enabled, }: { + specEndpoint?: string; + docsUrl?: string; + enabled?: boolean; +}) => Plugin; +export default rapidoc; diff --git a/dist/rapidocPlugin.js b/dist/rapidocPlugin.js new file mode 100644 index 0000000..a7f49ff --- /dev/null +++ b/dist/rapidocPlugin.js @@ -0,0 +1,34 @@ +const rapidoc = ({ specEndpoint = "/openapi.json", docsUrl = "/docs", enabled = true, }) => ({ endpoints = [], ...config }) => { + if (!enabled) { + return { ...config, endpoints }; + } + return { + ...config, + endpoints: [ + ...endpoints, + { + method: "get", + path: docsUrl, + handler: async (req) => new Response(` + + + + + + + Rapidoc + + + + + + `, { headers: { "content-type": "text/html" } }), + }, + ], + }; +}; +export default rapidoc; +//# sourceMappingURL=rapidocPlugin.js.map \ No newline at end of file diff --git a/dist/rapidocPlugin.js.map b/dist/rapidocPlugin.js.map new file mode 100644 index 0000000..47f0442 --- /dev/null +++ b/dist/rapidocPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rapidocPlugin.js","sourceRoot":"","sources":["../src/rapidocPlugin.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GACX,CAAC,EACC,YAAY,GAAG,eAAe,EAC9B,OAAO,GAAG,OAAO,EACjB,OAAO,GAAG,IAAI,GAKf,EAAU,EAAE,CACb,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE;IAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAC;IAClC,CAAC;IAED,OAAO;QACL,GAAG,MAAM;QACT,SAAS,EAAE;YACT,GAAG,SAAS;YACZ;gBACE,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CACrB,IAAI,QAAQ,CACV;;;;;;;;;;;;;;oCAcsB,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,YAAY;;sBAErE,EACR,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,EAAE,CAC7C;aACJ;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEJ,eAAe,OAAO,CAAC"} \ No newline at end of file diff --git a/dist/redocPlugin.d.ts b/dist/redocPlugin.d.ts new file mode 100644 index 0000000..c340b63 --- /dev/null +++ b/dist/redocPlugin.d.ts @@ -0,0 +1,7 @@ +import type { Plugin } from "payload"; +declare const redoc: ({ specEndpoint, docsUrl, enabled, }: { + specEndpoint?: string; + docsUrl?: string; + enabled?: boolean; +}) => Plugin; +export default redoc; diff --git a/dist/redocPlugin.js b/dist/redocPlugin.js new file mode 100644 index 0000000..3607707 --- /dev/null +++ b/dist/redocPlugin.js @@ -0,0 +1,41 @@ +const redoc = ({ specEndpoint = "/openapi.json", docsUrl = "/docs", enabled = true, }) => ({ endpoints = [], ...config }) => { + if (!enabled) { + return { ...config, endpoints }; + } + return { + ...config, + endpoints: [ + ...endpoints, + { + method: "get", + path: docsUrl, + handler: async (req) => new Response(` + + + + Redoc + + + + + + + + + + + + `, { headers: { "content-type": "text/html" } }), + }, + ], + }; +}; +export default redoc; +//# sourceMappingURL=redocPlugin.js.map \ No newline at end of file diff --git a/dist/redocPlugin.js.map b/dist/redocPlugin.js.map new file mode 100644 index 0000000..98b0e1c --- /dev/null +++ b/dist/redocPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"redocPlugin.js","sourceRoot":"","sources":["../src/redocPlugin.ts"],"names":[],"mappings":"AAEA,MAAM,KAAK,GACT,CAAC,EACC,YAAY,GAAG,eAAe,EAC9B,OAAO,GAAG,OAAO,EACjB,OAAO,GAAG,IAAI,GAKf,EAAU,EAAE,CACb,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE;IAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAC;IAClC,CAAC;IACD,OAAO;QACL,GAAG,MAAM;QACT,SAAS,EAAE;YACT,GAAG,SAAS;YACZ;gBACE,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CACrB,IAAI,QAAQ,CACV;;;;;;;;;;;;;;;;;;;;qCAoBuB,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,YAAY;;;sBAGtE,EACR,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,EAAE,CAC7C;aACJ;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEJ,eAAe,KAAK,CAAC"} \ No newline at end of file diff --git a/dist/requestHandlers.d.ts b/dist/requestHandlers.d.ts new file mode 100644 index 0000000..3b83d39 --- /dev/null +++ b/dist/requestHandlers.d.ts @@ -0,0 +1,4 @@ +import type { PayloadRequest } from 'payload'; +import type { SanitizedPluginOptions } from './types.js'; +export declare const createOpenAPIRequestHandler: (options: SanitizedPluginOptions) => (req: PayloadRequest) => Promise; +export declare const createOAuthPasswordFlowHandler: () => (req: PayloadRequest) => Promise; diff --git a/dist/requestHandlers.js b/dist/requestHandlers.js new file mode 100644 index 0000000..4e4eb96 --- /dev/null +++ b/dist/requestHandlers.js @@ -0,0 +1,36 @@ +import { generateV30Spec, generateV31Spec } from './openapi/generators.js'; +export const createOpenAPIRequestHandler = (options) => async (req) => { + switch (options.openapiVersion) { + case '3.0': + return Response.json(await generateV30Spec(req, options)); + case '3.1': + return Response.json(await generateV31Spec(req, options)); + } + throw new Error('Invalid `openapiVersion`'); +}; +export const createOAuthPasswordFlowHandler = () => async (req) => { + const formData = await req.formData(); + const collection = req.payload.collections[req.payload.config.admin.user]; + const data = collection.config.auth?.loginWithUsername !== false + ? { + email: formData.get('username').toString(), + username: formData.get('username').toString(), + password: formData.get('password').toString(), + } + : { + email: formData.get('username').toString(), + password: formData.get('password').toString(), + }; + const response = await req.payload.login({ + collection: collection.config.slug, + data, + }); + return Response.json({ + access_token: response.token, + token_type: 'JWT', + expires_in: response.exp !== undefined + ? response.exp - Math.floor(new Date().valueOf() / 1000) + : undefined, + }); +}; +//# sourceMappingURL=requestHandlers.js.map \ No newline at end of file diff --git a/dist/requestHandlers.js.map b/dist/requestHandlers.js.map new file mode 100644 index 0000000..4f0a463 --- /dev/null +++ b/dist/requestHandlers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"requestHandlers.js","sourceRoot":"","sources":["../src/requestHandlers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAE1E,MAAM,CAAC,MAAM,2BAA2B,GACtC,CAAC,OAA+B,EAAE,EAAE,CACpC,KAAK,EAAE,GAAmB,EAAqB,EAAE;IAC/C,QAAQ,OAAO,CAAC,cAAc,EAAE,CAAC;QAC/B,KAAK,KAAK;YACR,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,eAAe,CAAC,GAAG,EAAE,OAAO,C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AAE,KAAK;QACjB,UAAU,EACR,QAAQ,CAAC,GAAG,KAAK,SAAS;YACxB,CAAC,CAAC,QAAQ,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;YACxD,CAAC,CAAC,SAAS;KAChB,CAAC,CAAA;AACJ,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/scalarPlugin.d.ts b/dist/scalarPlugin.d.ts new file mode 100644 index 0000000..85a78fc --- /dev/null +++ b/dist/scalarPlugin.d.ts @@ -0,0 +1,7 @@ +import type { Plugin } from "payload"; +declare const scalar: ({ specEndpoint, docsUrl, enabled, }: { + specEndpoint?: string; + docsUrl?: string; + enabled?: boolean; +}) => Plugin; +export default scalar; diff --git a/dist/scalarPlugin.js b/dist/scalarPlugin.js new file mode 100644 index 0000000..4d48816 --- /dev/null +++ b/dist/scalarPlugin.js @@ -0,0 +1,46 @@ +const scalar = ({ specEndpoint = "/openapi.json", docsUrl = "/docs", enabled = true, }) => ({ endpoints = [], ...config }) => { + if (!enabled) { + return { ...config, endpoints }; + } + return { + ...config, + endpoints: [ + ...endpoints, + { + method: "get", + path: docsUrl, + handler: async (req) => { + const fullSpecUrl = `${req.protocol}//${req.headers.get("host")}${specEndpoint}`; + const html = ` + + + + + + API Docs + + + +
+ + `; + return new Response(html, { + headers: { "content-type": "text/html" }, + }); + }, + }, + ], + }; +}; +export default scalar; +//# sourceMappingURL=scalarPlugin.js.map \ No newline at end of file diff --git a/dist/scalarPlugin.js.map b/dist/scalarPlugin.js.map new file mode 100644 index 0000000..e9337b8 --- /dev/null +++ b/dist/scalarPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"scalarPlugin.js","sourceRoot":"","sources":["../src/scalarPlugin.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GACV,CAAC,EACC,YAAY,GAAG,eAAe,EAC9B,OAAO,GAAG,OAAO,EACjB,OAAO,GAAG,IAAI,GAKf,EAAU,EAAE,CACb,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE;IAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAC;IAClC,CAAC;IAED,OAAO;QACL,GAAG,MAAM;QACT,SAAS,EAAE;YACT,GAAG,SAAS;YACZ;gBACE,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;oBACrB,MAAM,WAAW,GAAG,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,YAAY,EAAE,CAAC;oBAEjF,MAAM,IAAI,GAAG;;;;;;;;;;;;;uDAa8B,WAAW;;;;;;;;;sBAS5C,CAAC;oBAEX,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;wBACxB,OAAO,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE;qBACzC,CAAC,CAAC;gBACL,CAAC;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEJ,eAAe,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/swaggerUIPlugin.d.ts b/dist/swaggerUIPlugin.d.ts new file mode 100644 index 0000000..54f3366 --- /dev/null +++ b/dist/swaggerUIPlugin.d.ts @@ -0,0 +1,7 @@ +import type { Plugin } from "payload"; +declare const swaggerUI: ({ specEndpoint, docsUrl, enabled, }: { + specEndpoint?: string; + docsUrl?: string; + enabled?: boolean; +}) => Plugin; +export default swaggerUI; diff --git a/dist/swaggerUIPlugin.js b/dist/swaggerUIPlugin.js new file mode 100644 index 0000000..28bd876 --- /dev/null +++ b/dist/swaggerUIPlugin.js @@ -0,0 +1,43 @@ +const swaggerUI = ({ specEndpoint = "/openapi.json", docsUrl = "/docs", enabled = true, }) => ({ endpoints = [], ...config }) => { + if (!enabled) { + return { ...config, endpoints }; + } + return { + ...config, + endpoints: [ + ...endpoints, + { + method: "get", + path: docsUrl, + handler: async (req) => new Response(` + + + + + + + SwaggerUI + + + +
+ + + + `, { headers: { "content-type": "text/html" } }), + }, + ], + }; +}; +export default swaggerUI; +//# sourceMappingURL=swaggerUIPlugin.js.map \ No newline at end of file diff --git a/dist/swaggerUIPlugin.js.map b/dist/swaggerUIPlugin.js.map new file mode 100644 index 0000000..86f4c96 --- /dev/null +++ b/dist/swaggerUIPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"swaggerUIPlugin.js","sourceRoot":"","sources":["../src/swaggerUIPlugin.ts"],"names":[],"mappings":"AAEA,MAAM,SAAS,GACb,CAAC,EACC,YAAY,GAAG,eAAe,EAC9B,OAAO,GAAG,OAAO,EACjB,OAAO,GAAG,IAAI,GAKf,EAAU,EAAE,CACb,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,MAAM,EAAU,EAAU,EAAE;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAC;IAClC,CAAC;IACD,OAAO;QACL,GAAG,MAAM;QACT,SAAS,EAAE;YACT,GAAG,SAAS;YACZ;gBACE,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CACrB,IAAI,QAAQ,CACV;;;;;;;;;;;;;;;;;;;4BAmBc,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,YAAY;;;;;;sBAM7D,EACR,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,EAAE,CAC7C;aACJ;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEJ,eAAe,SAAS,CAAC"} \ No newline at end of file diff --git a/dist/types.d.ts b/dist/types.d.ts new file mode 100644 index 0000000..652259d --- /dev/null +++ b/dist/types.d.ts @@ -0,0 +1,14 @@ +export type OpenAPIVersion = '3.0' | '3.1'; +export interface OpenAPIMetadata { + title: string; + version: string; + description?: string; +} +export interface PluginOptions { + enabled?: boolean; + openapiVersion?: OpenAPIVersion; + specEndpoint?: string; + authEndpoint?: string; + metadata: OpenAPIMetadata; +} +export type SanitizedPluginOptions = Required>; diff --git a/dist/types.js b/dist/types.js new file mode 100644 index 0000000..718fd38 --- /dev/null +++ b/dist/types.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/types.js.map b/dist/types.js.map new file mode 100644 index 0000000..c768b79 --- /dev/null +++ b/dist/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/utils/objects.d.ts b/dist/utils/objects.d.ts new file mode 100644 index 0000000..819b184 --- /dev/null +++ b/dist/utils/objects.d.ts @@ -0,0 +1,2 @@ +export declare const mapValuesAsync: (mapper: (value: T) => Promise, record: Record) => Promise>; +export declare const visitObjectNodes: (subject: Record | Array, visitor: (subject: Record & Array, key: string | number, value: unknown) => void) => void; diff --git a/dist/utils/objects.js b/dist/utils/objects.js new file mode 100644 index 0000000..172a894 --- /dev/null +++ b/dist/utils/objects.js @@ -0,0 +1,16 @@ +export const mapValuesAsync = async (mapper, record) => Object.fromEntries(await Promise.all(Object.entries(record).map(async ([key, value]) => [key, await mapper(value)]))); +export const visitObjectNodes = (subject, visitor) => { + if (Array.isArray(subject)) { + for (const [index, value] of subject.entries()) { + visitor(subject, index, value); + visitObjectNodes(value, visitor); + } + } + else if (typeof subject === 'object' && subject !== null && subject !== undefined) { + for (const [key, value] of Object.entries(subject)) { + visitor(subject, key, value); + visitObjectNodes(value, visitor); + } + } +}; +//# sourceMappingURL=objects.js.map \ No newline at end of file diff --git a/dist/utils/objects.js.map b/dist/utils/objects.js.map new file mode 100644 index 0000000..fd801d3 --- /dev/null +++ b/dist/utils/objects.js.map @@ -0,0 +1 @@ +{"version":3,"file":"objects.js","sourceRoot":"","sources":["../../src/utils/objects.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,MAAgC,EAChC,MAAyB,EACG,EAAE,CAC9B,MAAM,CAAC,WAAW,CAChB,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAC/E,CACF,CAAA;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,OAAiD,EACjD,OAIS,EACT,EAAE;IACF,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAC/C,OAAO,CAAC,OAAc,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;YACrC,gBAAgB,CAAC,KAAY,EAAE,OAAO,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;SAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACpF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnD,OAAO,CAAC,OAAc,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;YACnC,gBAAgB,CAAC,KAAY,EAAE,OAAO,CAAC,CAAA;QACzC,CAAC;IACH,CAAC;AACH,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/utils/strings.d.ts b/dist/utils/strings.d.ts new file mode 100644 index 0000000..410a279 --- /dev/null +++ b/dist/utils/strings.d.ts @@ -0,0 +1,2 @@ +export declare const upperFirst: (value: string) => string; +export declare const camelize: (value: string) => string; diff --git a/dist/utils/strings.js b/dist/utils/strings.js new file mode 100644 index 0000000..72543e7 --- /dev/null +++ b/dist/utils/strings.js @@ -0,0 +1,3 @@ +export const upperFirst = (value) => value.length > 0 ? value[0].toUpperCase() + value.slice(1) : ''; +export const camelize = (value) => value.split(/\s+/).map(upperFirst).join(''); +//# sourceMappingURL=strings.js.map \ No newline at end of file diff --git a/dist/utils/strings.js.map b/dist/utils/strings.js.map new file mode 100644 index 0000000..0497143 --- /dev/null +++ b/dist/utils/strings.js.map @@ -0,0 +1 @@ +{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CAC1C,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAEjE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA"} \ No newline at end of file diff --git a/src/rapidocPlugin.ts b/src/rapidocPlugin.ts index 81d6314..dd95964 100644 --- a/src/rapidocPlugin.ts +++ b/src/rapidocPlugin.ts @@ -1,18 +1,18 @@ -import type { Plugin } from 'payload' +import type { Plugin } from "payload"; const rapidoc = ({ - specEndpoint = '/openapi.json', - docsUrl = '/docs', + specEndpoint = "/openapi.json", + docsUrl = "/docs", enabled = true, }: { - specEndpoint?: string - docsUrl?: string - enabled?: boolean + specEndpoint?: string; + docsUrl?: string; + enabled?: boolean; }): Plugin => ({ endpoints = [], ...config }) => { if (!enabled) { - return { ...config, endpoints } + return { ...config, endpoints }; } return { @@ -20,9 +20,9 @@ const rapidoc = endpoints: [ ...endpoints, { - method: 'get', + method: "get", path: docsUrl, - handler: async req => + handler: async (req) => new Response( ` @@ -38,14 +38,14 @@ const rapidoc = - + `, - { headers: { 'content-type': 'text/html' } }, + { headers: { "content-type": "text/html" } } ), }, ], - } - } + }; + }; -export default rapidoc +export default rapidoc; diff --git a/src/redocPlugin.ts b/src/redocPlugin.ts index 2d975ae..cd1262e 100644 --- a/src/redocPlugin.ts +++ b/src/redocPlugin.ts @@ -1,27 +1,27 @@ -import type { Plugin } from 'payload' +import type { Plugin } from "payload"; const redoc = ({ - specEndpoint = '/openapi.json', - docsUrl = '/docs', + specEndpoint = "/openapi.json", + docsUrl = "/docs", enabled = true, }: { - specEndpoint?: string - docsUrl?: string - enabled?: boolean + specEndpoint?: string; + docsUrl?: string; + enabled?: boolean; }): Plugin => ({ endpoints = [], ...config }) => { if (!enabled) { - return { ...config, endpoints } + return { ...config, endpoints }; } return { ...config, endpoints: [ ...endpoints, { - method: 'get', + method: "get", path: docsUrl, - handler: async req => + handler: async (req) => new Response( ` @@ -43,15 +43,15 @@ const redoc = - + `, - { headers: { 'content-type': 'text/html' } }, + { headers: { "content-type": "text/html" } } ), }, ], - } - } + }; + }; -export default redoc +export default redoc; diff --git a/src/scalarPlugin.ts b/src/scalarPlugin.ts index c17c2a4..7659870 100644 --- a/src/scalarPlugin.ts +++ b/src/scalarPlugin.ts @@ -1,18 +1,18 @@ -import type { Plugin } from 'payload' +import type { Plugin } from "payload"; const scalar = ({ - specEndpoint = '/openapi.json', - docsUrl = '/docs', + specEndpoint = "/openapi.json", + docsUrl = "/docs", enabled = true, }: { - specEndpoint?: string - docsUrl?: string - enabled?: boolean + specEndpoint?: string; + docsUrl?: string; + enabled?: boolean; }): Plugin => ({ endpoints = [], ...config }) => { if (!enabled) { - return { ...config, endpoints } + return { ...config, endpoints }; } return { @@ -20,10 +20,10 @@ const scalar = endpoints: [ ...endpoints, { - method: 'get', + method: "get", path: docsUrl, - handler: async req => { - const fullSpecUrl = `${req.protocol}//${req.headers.get('host')}/api${specEndpoint}` + handler: async (req) => { + const fullSpecUrl = `${req.protocol}//${req.headers.get("host")}${specEndpoint}`; const html = ` @@ -47,15 +47,15 @@ const scalar =
- ` + `; return new Response(html, { - headers: { 'content-type': 'text/html' }, - }) + headers: { "content-type": "text/html" }, + }); }, }, ], - } - } + }; + }; -export default scalar +export default scalar; diff --git a/src/swaggerUIPlugin.ts b/src/swaggerUIPlugin.ts index c43a79a..25ce296 100644 --- a/src/swaggerUIPlugin.ts +++ b/src/swaggerUIPlugin.ts @@ -1,27 +1,27 @@ -import type { Config, Plugin } from 'payload' +import type { Config, Plugin } from "payload"; const swaggerUI = ({ - specEndpoint = '/openapi.json', - docsUrl = '/docs', + specEndpoint = "/openapi.json", + docsUrl = "/docs", enabled = true, }: { - specEndpoint?: string - docsUrl?: string - enabled?: boolean + specEndpoint?: string; + docsUrl?: string; + enabled?: boolean; }): Plugin => ({ endpoints = [], ...config }: Config): Config => { if (!enabled) { - return { ...config, endpoints } + return { ...config, endpoints }; } return { ...config, endpoints: [ ...endpoints, { - method: 'get', + method: "get", path: docsUrl, - handler: async req => + handler: async (req) => new Response( ` @@ -42,18 +42,18 @@ const swaggerUI = `, - { headers: { 'content-type': 'text/html' } }, + { headers: { "content-type": "text/html" } } ), }, ], - } - } + }; + }; -export default swaggerUI +export default swaggerUI;