@seshuk/payload-plugin-openapi 1.0.0-beta.1 → 1.0.0-beta.2

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.
Files changed (148) hide show
  1. package/README.md +8 -4
  2. package/dist/server/spec/buildDocument.js +62 -9
  3. package/dist/server/spec/buildDocument.js.map +1 -1
  4. package/dist/server/spec/components.js.map +1 -1
  5. package/dist/server/spec/entitySchemas.d.ts +5 -6
  6. package/dist/server/spec/entitySchemas.js.map +1 -1
  7. package/dist/server/spec/filters.d.ts +5 -1
  8. package/dist/server/spec/filters.js +21 -10
  9. package/dist/server/spec/filters.js.map +1 -1
  10. package/dist/server/spec/hierarchy.js +9 -4
  11. package/dist/server/spec/hierarchy.js.map +1 -1
  12. package/dist/server/spec/paths/collections.js +111 -7
  13. package/dist/server/spec/paths/collections.js.map +1 -1
  14. package/dist/server/spec/paths/custom.d.ts +4 -2
  15. package/dist/server/spec/paths/custom.js +1 -1
  16. package/dist/server/spec/paths/custom.js.map +1 -1
  17. package/dist/server/spec/paths/system.d.ts +2 -1
  18. package/dist/server/spec/paths/system.js +67 -1
  19. package/dist/server/spec/paths/system.js.map +1 -1
  20. package/dist/server/spec/plugins/ecommerce.d.ts +3 -0
  21. package/dist/server/spec/plugins/ecommerce.js +270 -0
  22. package/dist/server/spec/plugins/ecommerce.js.map +1 -0
  23. package/dist/server/spec/plugins/importExport.d.ts +3 -0
  24. package/dist/server/spec/plugins/importExport.js +202 -0
  25. package/dist/server/spec/plugins/importExport.js.map +1 -0
  26. package/dist/server/spec/plugins/index.d.ts +3 -0
  27. package/dist/server/spec/plugins/index.js +21 -0
  28. package/dist/server/spec/plugins/index.js.map +1 -0
  29. package/dist/server/spec/plugins/mcp.d.ts +3 -0
  30. package/dist/server/spec/plugins/mcp.js +118 -0
  31. package/dist/server/spec/plugins/mcp.js.map +1 -0
  32. package/dist/server/spec/plugins/multiTenant.d.ts +3 -0
  33. package/dist/server/spec/plugins/multiTenant.js +39 -0
  34. package/dist/server/spec/plugins/multiTenant.js.map +1 -0
  35. package/dist/server/spec/plugins/search.d.ts +3 -0
  36. package/dist/server/spec/plugins/search.js +43 -0
  37. package/dist/server/spec/plugins/search.js.map +1 -0
  38. package/dist/server/spec/plugins/seo.d.ts +3 -0
  39. package/dist/server/spec/plugins/seo.js +83 -0
  40. package/dist/server/spec/plugins/seo.js.map +1 -0
  41. package/dist/server/spec/plugins/shared.d.ts +35 -0
  42. package/dist/server/spec/plugins/shared.js +37 -0
  43. package/dist/server/spec/plugins/shared.js.map +1 -0
  44. package/dist/server/spec/plugins/storageR2.d.ts +3 -0
  45. package/dist/server/spec/plugins/storageR2.js +91 -0
  46. package/dist/server/spec/plugins/storageR2.js.map +1 -0
  47. package/dist/server/spec/plugins/stripe.d.ts +10 -0
  48. package/dist/server/spec/plugins/stripe.js +102 -0
  49. package/dist/server/spec/plugins/stripe.js.map +1 -0
  50. package/dist/server/spec/security.d.ts +2 -1
  51. package/dist/server/spec/security.js +5 -2
  52. package/dist/server/spec/security.js.map +1 -1
  53. package/dist/server/spec/tags.d.ts +4 -1
  54. package/dist/server/spec/tags.js +18 -2
  55. package/dist/server/spec/tags.js.map +1 -1
  56. package/dist/server/ui/html.js +2 -2
  57. package/dist/server/ui/html.js.map +1 -1
  58. package/dist/shared/translations/locales/ar.js +74 -0
  59. package/dist/shared/translations/locales/ar.js.map +1 -1
  60. package/dist/shared/translations/locales/az.js +74 -0
  61. package/dist/shared/translations/locales/az.js.map +1 -1
  62. package/dist/shared/translations/locales/bg.js +74 -0
  63. package/dist/shared/translations/locales/bg.js.map +1 -1
  64. package/dist/shared/translations/locales/bnBd.js +74 -0
  65. package/dist/shared/translations/locales/bnBd.js.map +1 -1
  66. package/dist/shared/translations/locales/bnIn.js +74 -0
  67. package/dist/shared/translations/locales/bnIn.js.map +1 -1
  68. package/dist/shared/translations/locales/ca.js +74 -0
  69. package/dist/shared/translations/locales/ca.js.map +1 -1
  70. package/dist/shared/translations/locales/cs.js +74 -0
  71. package/dist/shared/translations/locales/cs.js.map +1 -1
  72. package/dist/shared/translations/locales/da.js +74 -0
  73. package/dist/shared/translations/locales/da.js.map +1 -1
  74. package/dist/shared/translations/locales/de.js +74 -0
  75. package/dist/shared/translations/locales/de.js.map +1 -1
  76. package/dist/shared/translations/locales/en.js +74 -0
  77. package/dist/shared/translations/locales/en.js.map +1 -1
  78. package/dist/shared/translations/locales/es.js +74 -0
  79. package/dist/shared/translations/locales/es.js.map +1 -1
  80. package/dist/shared/translations/locales/et.js +74 -0
  81. package/dist/shared/translations/locales/et.js.map +1 -1
  82. package/dist/shared/translations/locales/fa.js +74 -0
  83. package/dist/shared/translations/locales/fa.js.map +1 -1
  84. package/dist/shared/translations/locales/fr.js +74 -0
  85. package/dist/shared/translations/locales/fr.js.map +1 -1
  86. package/dist/shared/translations/locales/he.js +74 -0
  87. package/dist/shared/translations/locales/he.js.map +1 -1
  88. package/dist/shared/translations/locales/hr.js +74 -0
  89. package/dist/shared/translations/locales/hr.js.map +1 -1
  90. package/dist/shared/translations/locales/hu.js +74 -0
  91. package/dist/shared/translations/locales/hu.js.map +1 -1
  92. package/dist/shared/translations/locales/hy.js +74 -0
  93. package/dist/shared/translations/locales/hy.js.map +1 -1
  94. package/dist/shared/translations/locales/id.js +74 -0
  95. package/dist/shared/translations/locales/id.js.map +1 -1
  96. package/dist/shared/translations/locales/is.js +74 -0
  97. package/dist/shared/translations/locales/is.js.map +1 -1
  98. package/dist/shared/translations/locales/it.js +74 -0
  99. package/dist/shared/translations/locales/it.js.map +1 -1
  100. package/dist/shared/translations/locales/ja.js +74 -0
  101. package/dist/shared/translations/locales/ja.js.map +1 -1
  102. package/dist/shared/translations/locales/ko.js +74 -0
  103. package/dist/shared/translations/locales/ko.js.map +1 -1
  104. package/dist/shared/translations/locales/lt.js +74 -0
  105. package/dist/shared/translations/locales/lt.js.map +1 -1
  106. package/dist/shared/translations/locales/lv.js +74 -0
  107. package/dist/shared/translations/locales/lv.js.map +1 -1
  108. package/dist/shared/translations/locales/my.js +74 -0
  109. package/dist/shared/translations/locales/my.js.map +1 -1
  110. package/dist/shared/translations/locales/nb.js +74 -0
  111. package/dist/shared/translations/locales/nb.js.map +1 -1
  112. package/dist/shared/translations/locales/nl.js +74 -0
  113. package/dist/shared/translations/locales/nl.js.map +1 -1
  114. package/dist/shared/translations/locales/pl.js +74 -0
  115. package/dist/shared/translations/locales/pl.js.map +1 -1
  116. package/dist/shared/translations/locales/pt.js +74 -0
  117. package/dist/shared/translations/locales/pt.js.map +1 -1
  118. package/dist/shared/translations/locales/ro.js +74 -0
  119. package/dist/shared/translations/locales/ro.js.map +1 -1
  120. package/dist/shared/translations/locales/rs.js +74 -0
  121. package/dist/shared/translations/locales/rs.js.map +1 -1
  122. package/dist/shared/translations/locales/rsLatin.js +74 -0
  123. package/dist/shared/translations/locales/rsLatin.js.map +1 -1
  124. package/dist/shared/translations/locales/ru.js +74 -0
  125. package/dist/shared/translations/locales/ru.js.map +1 -1
  126. package/dist/shared/translations/locales/sk.js +74 -0
  127. package/dist/shared/translations/locales/sk.js.map +1 -1
  128. package/dist/shared/translations/locales/sl.js +74 -0
  129. package/dist/shared/translations/locales/sl.js.map +1 -1
  130. package/dist/shared/translations/locales/sv.js +74 -0
  131. package/dist/shared/translations/locales/sv.js.map +1 -1
  132. package/dist/shared/translations/locales/ta.js +74 -0
  133. package/dist/shared/translations/locales/ta.js.map +1 -1
  134. package/dist/shared/translations/locales/th.js +74 -0
  135. package/dist/shared/translations/locales/th.js.map +1 -1
  136. package/dist/shared/translations/locales/tr.js +74 -0
  137. package/dist/shared/translations/locales/tr.js.map +1 -1
  138. package/dist/shared/translations/locales/uk.js +74 -0
  139. package/dist/shared/translations/locales/uk.js.map +1 -1
  140. package/dist/shared/translations/locales/vi.js +74 -0
  141. package/dist/shared/translations/locales/vi.js.map +1 -1
  142. package/dist/shared/translations/locales/zh.js +74 -0
  143. package/dist/shared/translations/locales/zh.js.map +1 -1
  144. package/dist/shared/translations/locales/zhTw.js +74 -0
  145. package/dist/shared/translations/locales/zhTw.js.map +1 -1
  146. package/dist/shared/translations/types.d.ts +74 -0
  147. package/dist/shared/types/index.d.ts +23 -8
  148. package/package.json +23 -15
@@ -1,7 +1,8 @@
1
1
  import { createSchemaName, listSchemaName, refTo, schemaName, updateSchemaName } from "../names.js";
2
- import { ERRORS, docAccessOperation, errorResponses, jsonOk, jsonResponse, uploadRequestBody, validateOperation } from "../components.js";
2
+ import { ERRORS, docAccessOperation, errorResponses, jsonBody, jsonOk, jsonResponse, uploadRequestBody, validateOperation } from "../components.js";
3
3
  import { makeT } from "../../../shared/translations/index.js";
4
4
  import { buildListParams, buildParamSchemas, commonReadParams, validateParams, writeParams } from "../params.js";
5
+ import { securedRequirement } from "../security.js";
5
6
  const buildCollectionPaths = ({ collection, ctx, security = {}, access = false }) => {
6
7
  const t = makeT(ctx.i18n);
7
8
  const name = schemaName(collection.slug);
@@ -277,13 +278,20 @@ const buildCollectionPaths = ({ collection, ctx, security = {}, access = false }
277
278
  type: "string",
278
279
  format: "binary"
279
280
  } } } };
281
+ const fileParams = [{
282
+ name: "filename",
283
+ in: "path",
284
+ required: true,
285
+ schema: { type: "string" }
286
+ }];
287
+ if (collection.versions) fileParams.push({
288
+ name: "version",
289
+ in: "query",
290
+ description: t("paramFileVersion"),
291
+ schema: { type: idType }
292
+ });
280
293
  paths[`${base}/file/{filename}`] = {
281
- parameters: [{
282
- name: "filename",
283
- in: "path",
284
- required: true,
285
- schema: { type: "string" }
286
- }],
294
+ parameters: fileParams,
287
295
  get: {
288
296
  tags: [name],
289
297
  operationId: `get${name}File`,
@@ -306,6 +314,102 @@ const buildCollectionPaths = ({ collection, ctx, security = {}, access = false }
306
314
  security: secRead
307
315
  }
308
316
  };
317
+ paths[`${base}/{id}/rename`] = {
318
+ parameters: [{
319
+ name: "id",
320
+ in: "path",
321
+ required: true,
322
+ schema: { type: idType }
323
+ }],
324
+ post: {
325
+ tags: [name],
326
+ operationId: `rename${name}File`,
327
+ requestBody: {
328
+ required: true,
329
+ content: { "application/json": { schema: {
330
+ type: "object",
331
+ properties: {
332
+ filename: { type: "string" },
333
+ draft: { type: "boolean" }
334
+ },
335
+ required: ["filename"]
336
+ } } }
337
+ },
338
+ responses: updateResponse,
339
+ security: secUpdate
340
+ }
341
+ };
342
+ }
343
+ if (collection.slug === "payload-preferences") {
344
+ delete paths[`${base}/count`];
345
+ delete paths[`${base}/validate`];
346
+ delete paths[`${base}/access`];
347
+ const keyParam = [{
348
+ name: "id",
349
+ in: "path",
350
+ required: true,
351
+ description: t("paramPreferenceKey"),
352
+ schema: { type: "string" }
353
+ }];
354
+ const secured = securedRequirement();
355
+ paths[`${base}/{id}`] = {
356
+ ...paths[`${base}/{id}`],
357
+ get: {
358
+ tags: [name],
359
+ operationId: `find${name}ByKey`,
360
+ summary: t("preferenceGet"),
361
+ parameters: keyParam,
362
+ responses: {
363
+ ...jsonOk(t("preferenceGetResult"), { anyOf: [docRef, {
364
+ type: "object",
365
+ properties: {
366
+ message: { type: "string" },
367
+ value: { const: null }
368
+ },
369
+ required: ["message", "value"]
370
+ }] }),
371
+ ...errorResponses(["500"], t)
372
+ },
373
+ security: secured
374
+ },
375
+ post: {
376
+ tags: [name],
377
+ operationId: `upsert${name}ByKey`,
378
+ summary: t("preferenceSet"),
379
+ parameters: keyParam,
380
+ requestBody: {
381
+ ...jsonBody({
382
+ type: "object",
383
+ properties: { value: {} },
384
+ required: ["value"]
385
+ }),
386
+ description: t("preferenceSetBody")
387
+ },
388
+ responses: {
389
+ ...jsonOk(t("preferenceSetResult"), mutationSchema),
390
+ ...errorResponses(["401", "500"], t)
391
+ },
392
+ security: secured
393
+ },
394
+ delete: {
395
+ tags: [name],
396
+ operationId: `delete${name}ByKey`,
397
+ summary: t("preferenceDelete"),
398
+ parameters: keyParam,
399
+ responses: {
400
+ ...jsonOk(t("preferenceDeleteResult"), { allOf: [docRef, {
401
+ type: "object",
402
+ properties: { message: { type: "string" } }
403
+ }] }),
404
+ ...errorResponses([
405
+ "401",
406
+ "404",
407
+ "500"
408
+ ], t)
409
+ },
410
+ security: secured
411
+ }
412
+ };
309
413
  }
310
414
  return paths;
311
415
  };
@@ -1 +1 @@
1
- {"version":3,"file":"collections.js","names":[],"sources":["../../../../src/server/spec/paths/collections.ts"],"sourcesContent":["import type {\n PathsObject,\n ReferenceObject,\n RequestBodyObject,\n ResponsesObject,\n SchemaObject,\n} from '@scalar/openapi-types/3.2'\nimport type { SanitizedCollectionConfig } from 'payload'\n\nimport {\n ERRORS,\n docAccessOperation,\n errorResponses,\n jsonOk,\n jsonResponse,\n uploadRequestBody,\n validateOperation,\n} from '@/server/spec/components.js'\nimport { createSchemaName, listSchemaName, refTo, schemaName, updateSchemaName } from '@/server/spec/names.js'\nimport {\n buildListParams,\n buildParamSchemas,\n commonReadParams,\n type ReadParamRefs,\n validateParams,\n writeParams,\n type WriteOperation,\n} from '@/server/spec/params.js'\nimport type { EntitySecurity } from '@/server/spec/security.js'\nimport { makeT } from '@/shared/translations/index.js'\nimport type { BuildContext } from '@/shared/types/index.js'\n\nexport const buildCollectionPaths = ({\n collection,\n ctx,\n security = {},\n access = false,\n}: {\n collection: SanitizedCollectionConfig\n ctx: BuildContext\n security?: EntitySecurity\n access?: boolean\n}): PathsObject => {\n const t = makeT(ctx.i18n)\n const name = schemaName(collection.slug)\n const base = `${ctx.apiRoute}/${collection.slug}`\n const docRef: ReferenceObject = { $ref: refTo(name) }\n const listRef: ReferenceObject = { $ref: refTo(listSchemaName(name)) }\n const createRef: ReferenceObject = { $ref: refTo(createSchemaName(name)) }\n const updateRef: ReferenceObject = { $ref: refTo(updateSchemaName(name)) }\n const idType = ctx.defaultIDType === 'number' ? 'integer' : 'string'\n const { read: secRead, create: secCreate, update: secUpdate, delete: secDelete, validate: secValidate } = security\n\n const allowBulk = collection.disableBulkEdit !== true\n const allowDuplicate = collection.disableDuplicate !== true\n\n const paramSchemas = buildParamSchemas({ fields: collection.fields, ctx })\n const refs: ReadParamRefs = {\n select: true,\n populate: Boolean(paramSchemas.populate),\n joins: Boolean(paramSchemas.joins),\n }\n\n const isUpload = Boolean(collection.upload)\n const fileRequiredOnCreate =\n typeof collection.upload === 'object' ? collection.upload.filesRequiredOnCreate !== false : true\n\n const requestBody = (ref: ReferenceObject, fileRequired: boolean): RequestBodyObject =>\n isUpload\n ? uploadRequestBody({ bodyRef: ref, fileRequired, t })\n : { content: { 'application/json': { schema: ref } } }\n\n const mutationSchema: SchemaObject = {\n type: 'object',\n properties: { message: { type: 'string' }, doc: docRef },\n }\n\n const listResponse: ResponsesObject = {\n ...jsonOk(t('collectionList'), listRef),\n ...errorResponses(ERRORS.list, t),\n }\n const findByIdResponse: ResponsesObject = {\n ...jsonOk(t('collectionDoc'), docRef),\n ...errorResponses(ERRORS.read, t),\n }\n const createResponse: ResponsesObject = {\n '201': jsonResponse(t('collectionCreated'), mutationSchema),\n ...errorResponses(ERRORS.create, t),\n }\n const updateResponse: ResponsesObject = {\n ...jsonOk(t('collectionUpdated'), mutationSchema),\n ...errorResponses(ERRORS.update, t),\n }\n const deleteResponse: ResponsesObject = {\n ...jsonOk(t('collectionDeleted'), mutationSchema),\n ...errorResponses(ERRORS.delete, t),\n }\n\n const bulkSchema: SchemaObject = {\n type: 'object',\n properties: {\n message: { type: 'string' },\n docs: { type: 'array', items: docRef },\n errors: {\n type: 'array',\n items: {\n type: 'object',\n properties: { message: { type: 'string' }, id: { type: idType } },\n },\n },\n },\n }\n const bulkUpdateResponse: ResponsesObject = {\n ...jsonOk(t('collectionBulkUpdate'), bulkSchema),\n ...errorResponses(ERRORS.update, t),\n }\n const bulkDeleteResponse: ResponsesObject = {\n ...jsonOk(t('collectionBulkDelete'), bulkSchema),\n ...errorResponses(ERRORS.delete, t),\n }\n const countResponse: ResponsesObject = {\n ...jsonOk(t('collectionCount'), { type: 'object', properties: { totalDocs: { type: 'integer' } } }),\n ...errorResponses(ERRORS.list, t),\n }\n\n const listParams = buildListParams({ base: name, fields: collection.fields, ctx, refs })\n const bulkParams = listParams.filter((p) => p.name === 'where')\n const bulkUpdateParams = listParams.filter((p) => ['limit', 'sort', 'where'].includes(p.name))\n const write = (operation: WriteOperation) => writeParams({ base: name, entity: collection, ctx, refs, operation })\n const deleteParams = write('delete')\n\n const bulkOps = allowBulk\n ? {\n patch: {\n tags: [name],\n operationId: `update${name}`,\n parameters: [...bulkUpdateParams, ...write('update')],\n requestBody: requestBody(updateRef, false),\n responses: bulkUpdateResponse,\n security: secUpdate,\n },\n delete: {\n tags: [name],\n operationId: `delete${name}`,\n parameters: [...bulkParams, ...deleteParams],\n responses: bulkDeleteResponse,\n security: secDelete,\n },\n }\n : {}\n\n const paths: PathsObject = {\n [base]: {\n get: {\n tags: [name],\n operationId: `find${name}`,\n parameters: buildListParams({ base: name, fields: collection.fields, ctx, refs }),\n responses: listResponse,\n security: secRead,\n },\n post: {\n tags: [name],\n operationId: `create${name}`,\n parameters: write('create'),\n requestBody: requestBody(createRef, fileRequiredOnCreate),\n responses: createResponse,\n security: secCreate,\n },\n ...bulkOps,\n },\n [`${base}/count`]: {\n get: {\n tags: [name],\n operationId: `count${name}`,\n parameters: bulkParams,\n responses: countResponse,\n security: secRead,\n },\n },\n [`${base}/validate`]: {\n post: validateOperation({\n tag: name,\n operationId: `validate${name}`,\n parameters: validateParams(ctx),\n requestBody: { ...requestBody(createRef, false), required: true },\n errors: ERRORS.create,\n security: secValidate,\n t,\n }),\n },\n [`${base}/{id}`]: {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n get: {\n tags: [name],\n operationId: `find${name}ById`,\n parameters: commonReadParams({ base: name, ctx, refs }),\n responses: findByIdResponse,\n security: secRead,\n },\n patch: {\n tags: [name],\n operationId: `update${name}ById`,\n parameters: write('updateByID'),\n requestBody: requestBody(updateRef, false),\n responses: updateResponse,\n security: secUpdate,\n },\n delete: {\n tags: [name],\n operationId: `delete${name}ById`,\n parameters: deleteParams,\n responses: deleteResponse,\n security: secDelete,\n },\n },\n }\n\n paths[`${base}/{id}/validate`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: validateOperation({\n tag: name,\n operationId: `validate${name}ById`,\n parameters: validateParams(ctx),\n requestBody: requestBody(updateRef, false),\n errors: ERRORS.update,\n security: secValidate,\n t,\n }),\n }\n\n if (allowDuplicate) {\n paths[`${base}/{id}/duplicate`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: {\n tags: [name],\n operationId: `duplicate${name}`,\n parameters: write('duplicate'),\n responses: { ...jsonOk(t('collectionDuplicated'), mutationSchema), ...errorResponses(ERRORS.create, t) },\n security: secCreate,\n },\n }\n }\n\n if (access) {\n const auth = collection.auth\n const operations = [\n 'create',\n 'read',\n 'update',\n 'delete',\n 'validate',\n ...(auth && auth.maxLoginAttempts ? ['unlock'] : []),\n ...(collection.versions ? ['readVersions'] : []),\n ]\n const accessOp = (operationId: string, errors: typeof ERRORS.read) =>\n docAccessOperation({ tag: name, operationId, operations, bodyRef: updateRef, errors, t })\n paths[`${base}/access`] = { post: accessOp(`access${name}`, ['500']) }\n paths[`${base}/access/{id}`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: accessOp(`access${name}ById`, ['404', '500']),\n }\n }\n\n if (isUpload) {\n const file = { content: { '*/*': { schema: { type: 'string', format: 'binary' } } } } as const\n paths[`${base}/file/{filename}`] = {\n parameters: [{ name: 'filename', in: 'path', required: true, schema: { type: 'string' } }],\n get: {\n tags: [name],\n operationId: `get${name}File`,\n responses: {\n '200': { description: t('fileServe'), ...file },\n '206': { description: t('filePartial'), ...file },\n ...errorResponses(['400', '403', '404', '500'], t),\n },\n security: secRead,\n },\n }\n }\n\n return paths\n}\n"],"mappings":";;;;AAgCA,MAAa,wBAAwB,EACnC,YACA,KACA,WAAW,CAAC,GACZ,SAAS,YAMQ;CACjB,MAAM,IAAI,MAAM,IAAI,IAAI;CACxB,MAAM,OAAO,W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,MAAM,YAAY,aAAqB,WACrC,mBAAmB;GAAE,KAAK;GAAM;GAAa;GAAY,SAAS;GAAW;GAAQ;EAAE,CAAC;EAC1F,MAAM,GAAG,KAAK,YAAY,EAAE,MAAM,SAAS,SAAS,QAAQ,CAAC,KAAK,CAAC,EAAE;EACrE,MAAM,GAAG,KAAK,iBAAiB;GAC7B,YAAY,CAAC;IAAE,MAAM;IAAM,IAAI;IAAQ,UAAU;IAAM,QAAQ,EAAE,MAAM,OAAO;GAAE,CAAC;GACjF,MAAM,SAAS,SAAS,KAAK,OAAO,CAAC,OAAO,KAAK,CAAC;EACpD;CACF;CAEA,IAAI,UAAU;EACZ,MAAM,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ;GAAE,MAAM;GAAU,QAAQ;EAAS,EAAE,EAAE,EAAE;EACpF,MAAM,GAAG,KAAK,qBAAqB;GACjC,YAAY,CAAC;IAAE,MAAM;IAAY,IAAI;IAAQ,UAAU;IAAM,QAAQ,EAAE,MAAM,SAAS;GAAE,CAAC;GACzF,KAAK;IACH,MAAM,CAAC,IAAI;IACX,aAAa,MAAM,KAAK;IACxB,WAAW;KACT,OAAO;MAAE,aAAa,EAAE,WAAW;MAAG,GAAG;KAAK;KAC9C,OAAO;MAAE,aAAa,EAAE,aAAa;MAAG,GAAG;KAAK;KAChD,GAAG,eAAe;MAAC;MAAO;MAAO;MAAO;KAAK,GAAG,CAAC;IACnD;IACA,UAAU;GACZ;EACF;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"collections.js","names":[],"sources":["../../../../src/server/spec/paths/collections.ts"],"sourcesContent":["import type {\n ParameterObject,\n PathsObject,\n ReferenceObject,\n RequestBodyObject,\n ResponsesObject,\n SchemaObject,\n} from '@scalar/openapi-types/3.2'\nimport type { SanitizedCollectionConfig } from 'payload'\n\nimport {\n ERRORS,\n docAccessOperation,\n errorResponses,\n jsonBody,\n jsonOk,\n jsonResponse,\n uploadRequestBody,\n validateOperation,\n} from '@/server/spec/components.js'\nimport { createSchemaName, listSchemaName, refTo, schemaName, updateSchemaName } from '@/server/spec/names.js'\nimport {\n buildListParams,\n buildParamSchemas,\n commonReadParams,\n type ReadParamRefs,\n validateParams,\n writeParams,\n type WriteOperation,\n} from '@/server/spec/params.js'\nimport { type EntitySecurity, securedRequirement } from '@/server/spec/security.js'\nimport { makeT } from '@/shared/translations/index.js'\nimport type { BuildContext } from '@/shared/types/index.js'\n\nexport const buildCollectionPaths = ({\n collection,\n ctx,\n security = {},\n access = false,\n}: {\n collection: SanitizedCollectionConfig\n ctx: BuildContext\n security?: EntitySecurity\n access?: boolean\n}): PathsObject => {\n const t = makeT(ctx.i18n)\n const name = schemaName(collection.slug)\n const base = `${ctx.apiRoute}/${collection.slug}`\n const docRef: ReferenceObject = { $ref: refTo(name) }\n const listRef: ReferenceObject = { $ref: refTo(listSchemaName(name)) }\n const createRef: ReferenceObject = { $ref: refTo(createSchemaName(name)) }\n const updateRef: ReferenceObject = { $ref: refTo(updateSchemaName(name)) }\n const idType = ctx.defaultIDType === 'number' ? 'integer' : 'string'\n const { read: secRead, create: secCreate, update: secUpdate, delete: secDelete, validate: secValidate } = security\n\n const allowBulk = collection.disableBulkEdit !== true\n const allowDuplicate = collection.disableDuplicate !== true\n\n const paramSchemas = buildParamSchemas({ fields: collection.fields, ctx })\n const refs: ReadParamRefs = {\n select: true,\n populate: Boolean(paramSchemas.populate),\n joins: Boolean(paramSchemas.joins),\n }\n\n const isUpload = Boolean(collection.upload)\n const fileRequiredOnCreate =\n typeof collection.upload === 'object' ? collection.upload.filesRequiredOnCreate !== false : true\n\n const requestBody = (ref: ReferenceObject, fileRequired: boolean): RequestBodyObject =>\n isUpload\n ? uploadRequestBody({ bodyRef: ref, fileRequired, t })\n : { content: { 'application/json': { schema: ref } } }\n\n const mutationSchema: SchemaObject = {\n type: 'object',\n properties: { message: { type: 'string' }, doc: docRef },\n }\n\n const listResponse: ResponsesObject = {\n ...jsonOk(t('collectionList'), listRef),\n ...errorResponses(ERRORS.list, t),\n }\n const findByIdResponse: ResponsesObject = {\n ...jsonOk(t('collectionDoc'), docRef),\n ...errorResponses(ERRORS.read, t),\n }\n const createResponse: ResponsesObject = {\n '201': jsonResponse(t('collectionCreated'), mutationSchema),\n ...errorResponses(ERRORS.create, t),\n }\n const updateResponse: ResponsesObject = {\n ...jsonOk(t('collectionUpdated'), mutationSchema),\n ...errorResponses(ERRORS.update, t),\n }\n const deleteResponse: ResponsesObject = {\n ...jsonOk(t('collectionDeleted'), mutationSchema),\n ...errorResponses(ERRORS.delete, t),\n }\n\n const bulkSchema: SchemaObject = {\n type: 'object',\n properties: {\n message: { type: 'string' },\n docs: { type: 'array', items: docRef },\n errors: {\n type: 'array',\n items: {\n type: 'object',\n properties: { message: { type: 'string' }, id: { type: idType } },\n },\n },\n },\n }\n const bulkUpdateResponse: ResponsesObject = {\n ...jsonOk(t('collectionBulkUpdate'), bulkSchema),\n ...errorResponses(ERRORS.update, t),\n }\n const bulkDeleteResponse: ResponsesObject = {\n ...jsonOk(t('collectionBulkDelete'), bulkSchema),\n ...errorResponses(ERRORS.delete, t),\n }\n const countResponse: ResponsesObject = {\n ...jsonOk(t('collectionCount'), { type: 'object', properties: { totalDocs: { type: 'integer' } } }),\n ...errorResponses(ERRORS.list, t),\n }\n\n const listParams = buildListParams({ base: name, fields: collection.fields, ctx, refs })\n const bulkParams = listParams.filter((p) => p.name === 'where')\n const bulkUpdateParams = listParams.filter((p) => ['limit', 'sort', 'where'].includes(p.name))\n const write = (operation: WriteOperation) => writeParams({ base: name, entity: collection, ctx, refs, operation })\n const deleteParams = write('delete')\n\n const bulkOps = allowBulk\n ? {\n patch: {\n tags: [name],\n operationId: `update${name}`,\n parameters: [...bulkUpdateParams, ...write('update')],\n requestBody: requestBody(updateRef, false),\n responses: bulkUpdateResponse,\n security: secUpdate,\n },\n delete: {\n tags: [name],\n operationId: `delete${name}`,\n parameters: [...bulkParams, ...deleteParams],\n responses: bulkDeleteResponse,\n security: secDelete,\n },\n }\n : {}\n\n const paths: PathsObject = {\n [base]: {\n get: {\n tags: [name],\n operationId: `find${name}`,\n parameters: buildListParams({ base: name, fields: collection.fields, ctx, refs }),\n responses: listResponse,\n security: secRead,\n },\n post: {\n tags: [name],\n operationId: `create${name}`,\n parameters: write('create'),\n requestBody: requestBody(createRef, fileRequiredOnCreate),\n responses: createResponse,\n security: secCreate,\n },\n ...bulkOps,\n },\n [`${base}/count`]: {\n get: {\n tags: [name],\n operationId: `count${name}`,\n parameters: bulkParams,\n responses: countResponse,\n security: secRead,\n },\n },\n [`${base}/validate`]: {\n post: validateOperation({\n tag: name,\n operationId: `validate${name}`,\n parameters: validateParams(ctx),\n requestBody: { ...requestBody(createRef, false), required: true },\n errors: ERRORS.create,\n security: secValidate,\n t,\n }),\n },\n [`${base}/{id}`]: {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n get: {\n tags: [name],\n operationId: `find${name}ById`,\n parameters: commonReadParams({ base: name, ctx, refs }),\n responses: findByIdResponse,\n security: secRead,\n },\n patch: {\n tags: [name],\n operationId: `update${name}ById`,\n parameters: write('updateByID'),\n requestBody: requestBody(updateRef, false),\n responses: updateResponse,\n security: secUpdate,\n },\n delete: {\n tags: [name],\n operationId: `delete${name}ById`,\n parameters: deleteParams,\n responses: deleteResponse,\n security: secDelete,\n },\n },\n }\n\n paths[`${base}/{id}/validate`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: validateOperation({\n tag: name,\n operationId: `validate${name}ById`,\n parameters: validateParams(ctx),\n requestBody: requestBody(updateRef, false),\n errors: ERRORS.update,\n security: secValidate,\n t,\n }),\n }\n\n if (allowDuplicate) {\n paths[`${base}/{id}/duplicate`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: {\n tags: [name],\n operationId: `duplicate${name}`,\n parameters: write('duplicate'),\n responses: { ...jsonOk(t('collectionDuplicated'), mutationSchema), ...errorResponses(ERRORS.create, t) },\n security: secCreate,\n },\n }\n }\n\n if (access) {\n const auth = collection.auth\n const operations = [\n 'create',\n 'read',\n 'update',\n 'delete',\n 'validate',\n ...(auth && auth.maxLoginAttempts ? ['unlock'] : []),\n ...(collection.versions ? ['readVersions'] : []),\n ]\n const accessOp = (operationId: string, errors: typeof ERRORS.read) =>\n docAccessOperation({ tag: name, operationId, operations, bodyRef: updateRef, errors, t })\n paths[`${base}/access`] = { post: accessOp(`access${name}`, ['500']) }\n paths[`${base}/access/{id}`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: accessOp(`access${name}ById`, ['404', '500']),\n }\n }\n\n if (isUpload) {\n const file = { content: { '*/*': { schema: { type: 'string', format: 'binary' } } } } as const\n const fileParams: ParameterObject[] = [{ name: 'filename', in: 'path', required: true, schema: { type: 'string' } }]\n if (collection.versions) {\n fileParams.push({ name: 'version', in: 'query', description: t('paramFileVersion'), schema: { type: idType } })\n }\n paths[`${base}/file/{filename}`] = {\n parameters: fileParams,\n get: {\n tags: [name],\n operationId: `get${name}File`,\n responses: {\n '200': { description: t('fileServe'), ...file },\n '206': { description: t('filePartial'), ...file },\n ...errorResponses(['400', '403', '404', '500'], t),\n },\n security: secRead,\n },\n }\n paths[`${base}/{id}/rename`] = {\n parameters: [{ name: 'id', in: 'path', required: true, schema: { type: idType } }],\n post: {\n tags: [name],\n operationId: `rename${name}File`,\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n properties: { filename: { type: 'string' }, draft: { type: 'boolean' } },\n required: ['filename'],\n },\n },\n },\n },\n responses: updateResponse,\n security: secUpdate,\n },\n }\n }\n\n if (collection.slug === 'payload-preferences') {\n delete paths[`${base}/count`]\n delete paths[`${base}/validate`]\n delete paths[`${base}/access`]\n const keyParam: ParameterObject[] = [\n { name: 'id', in: 'path', required: true, description: t('paramPreferenceKey'), schema: { type: 'string' } },\n ]\n const secured = securedRequirement()\n paths[`${base}/{id}`] = {\n ...paths[`${base}/{id}`],\n get: {\n tags: [name],\n operationId: `find${name}ByKey`,\n summary: t('preferenceGet'),\n parameters: keyParam,\n responses: {\n ...jsonOk(t('preferenceGetResult'), {\n anyOf: [\n docRef,\n {\n type: 'object',\n properties: { message: { type: 'string' }, value: { const: null } },\n required: ['message', 'value'],\n },\n ],\n }),\n ...errorResponses(['500'], t),\n },\n security: secured,\n },\n post: {\n tags: [name],\n operationId: `upsert${name}ByKey`,\n summary: t('preferenceSet'),\n parameters: keyParam,\n requestBody: {\n ...jsonBody({ type: 'object', properties: { value: {} }, required: ['value'] }),\n description: t('preferenceSetBody'),\n },\n responses: { ...jsonOk(t('preferenceSetResult'), mutationSchema), ...errorResponses(['401', '500'], t) },\n security: secured,\n },\n delete: {\n tags: [name],\n operationId: `delete${name}ByKey`,\n summary: t('preferenceDelete'),\n parameters: keyParam,\n responses: {\n ...jsonOk(t('preferenceDeleteResult'), {\n allOf: [docRef, { type: 'object', properties: { message: { type: 'string' } } }],\n }),\n ...errorResponses(['401', '404', '500'], t),\n },\n security: secured,\n },\n }\n }\n\n return paths\n}\n"],"mappings":";;;;;AAkCA,MAAa,wBAAwB,EACnC,YACA,KACA,WAAW,CAAC,GACZ,SAAS,YAMQ;CACjB,MAAM,IAAI,MAAM,IAAI,IAAI;CACxB,MAAM,OAAO,WAAW,WAAW,IAAI;CACvC,MAAM,OAAO,GAAG,IAAI,SAAS,GAAG,WAAW;CAC3C,MAAM,SAA0B,EAAE,MAAM,MAAM,IAAI,EAAE;CACpD,MAAM,UAA2B,EAAE,MAAM,MAAM,eAAe,IAAI,CAAC,EAAE;CACrE,MAAM,YAA6B,EAAE,MAAM,MAAM,iBAAiB,IAAI,CAAC,EAAE;CACzE,MAAM,YAA6B,EAAE,MAAM,MAAM,iBAAiB,IAAI,CAAC,EAAE;CACzE,MAAM,SAAS,IAAI,kBAAkB,WAAW,YAAY;CAC5D,MAAM,EAAE,MAAM,SAAS,QAAQ,WAAW,QAAQ,WAAW,QAAQ,WAAW,UAAU,gBAAg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EACF;CACF;CAEA,OAAO;AACT"}
@@ -1,6 +1,8 @@
1
1
  import { BuildContext } from "../../../shared/types/index.js";
2
- import { SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from "payload";
3
- import { PathsObject } from "@scalar/openapi-types/3.2";
2
+ import { Endpoint, SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from "payload";
3
+ import { OperationObject, PathsObject } from "@scalar/openapi-types/3.2";
4
+ export declare const getOpenapiMeta: (endpoint: Endpoint) => OperationObject | undefined;
5
+ export declare const normalizePath: (prefix: string, path: string) => string;
4
6
  export declare const buildCustomEndpointPaths: ({ config, collections, globals, ctx }: {
5
7
  config: SanitizedConfig;
6
8
  collections: SanitizedCollectionConfig[];
@@ -37,6 +37,6 @@ const buildCustomEndpointPaths = ({ config, collections, globals, ctx }) => {
37
37
  });
38
38
  return out;
39
39
  };
40
- export { buildCustomEndpointPaths };
40
+ export { buildCustomEndpointPaths, getOpenapiMeta, normalizePath };
41
41
 
42
42
  //# sourceMappingURL=custom.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","names":[],"sources":["../../../../src/server/spec/paths/custom.ts"],"sourcesContent":["import type { OperationObject, PathsObject } from '@scalar/openapi-types/3.2'\nimport type { Endpoint, SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from 'payload'\n\nimport type { BuildContext } from '@/shared/types/index.js'\n\nconst getOpenapiMeta = (endpoint: Endpoint): OperationObject | undefined => {\n const meta = endpoint.custom?.openapi\n return meta && typeof meta === 'object' ? (meta as OperationObject) : undefined\n}\n\nconst normalizePath = (prefix: string, path: string): string => {\n const joined = `${prefix}${path.startsWith('/') ? path : `/${path}`}`\n return joined.replace(/:([A-Za-z0-9_]+)/g, '{$1}')\n}\n\nconst collect = ({\n endpoints,\n prefix,\n out,\n}: {\n endpoints: Endpoint[] | false | undefined\n prefix: string\n out: PathsObject\n}): void => {\n if (!endpoints) return\n for (const endpoint of endpoints) {\n const meta = getOpenapiMeta(endpoint)\n if (!meta) continue\n const path = normalizePath(prefix, endpoint.path)\n const method = endpoint.method.toLowerCase()\n out[path] = { ...out[path], [method]: { ...meta } }\n }\n}\n\nexport const buildCustomEndpointPaths = ({\n config,\n collections,\n globals,\n ctx,\n}: {\n config: SanitizedConfig\n collections: SanitizedCollectionConfig[]\n globals: SanitizedGlobalConfig[]\n ctx: BuildContext\n}): PathsObject => {\n const out: PathsObject = {}\n collect({ endpoints: config.endpoints, prefix: ctx.apiRoute, out })\n for (const collection of collections) {\n collect({ endpoints: collection.endpoints, prefix: `${ctx.apiRoute}/${collection.slug}`, out })\n }\n for (const global of globals) {\n collect({ endpoints: global.endpoints, prefix: `${ctx.apiRoute}/globals/${global.slug}`, out })\n }\n return out\n}\n"],"mappings":"AAKA,MAAM,kBAAkB,aAAoD;CAC1E,MAAM,OAAO,SAAS,QAAQ;CAC9B,OAAO,QAAQ,OAAO,SAAS,WAAY,OAA2B,KAAA;AACxE;AAEA,MAAM,iBAAiB,QAAgB,SAAyB;CAE9D,OAAO,GADW,SAAS,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,SAC/C,QAAQ,qBAAqB,MAAM;AACnD;AAEA,MAAM,WAAW,EACf,WACA,QACA,UAKU;CACV,IAAI,CAAC,WAAW;CAChB,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,OAAO,eAAe,QAAQ;EACpC,IAAI,CAAC,MAAM;EACX,MAAM,OAAO,cAAc,QAAQ,SAAS,IAAI;EAChD,MAAM,SAAS,SAAS,OAAO,YAAY;EAC3C,IAAI,QAAQ;GAAE,GAAG,IAAI;IAAQ,SAAS,EAAE,GAAG,KAAK;EAAE;CACpD;AACF;AAEA,MAAa,4BAA4B,EACvC,QACA,aACA,SACA,UAMiB;CACjB,MAAM,MAAmB,CAAC;CAC1B,QAAQ;EAAE,WAAW,OAAO;EAAW,QAAQ,IAAI;EAAU;CAAI,CAAC;CAClE,KAAK,MAAM,cAAc,aACvB,QAAQ;EAAE,WAAW,WAAW;EAAW,QAAQ,GAAG,IAAI,SAAS,GAAG,WAAW;EAAQ;CAAI,CAAC;CAEhG,KAAK,MAAM,UAAU,SACnB,QAAQ;EAAE,WAAW,OAAO;EAAW,QAAQ,GAAG,IAAI,SAAS,WAAW,OAAO;EAAQ;CAAI,CAAC;CAEhG,OAAO;AACT"}
1
+ {"version":3,"file":"custom.js","names":[],"sources":["../../../../src/server/spec/paths/custom.ts"],"sourcesContent":["import type { OperationObject, PathsObject } from '@scalar/openapi-types/3.2'\nimport type { Endpoint, SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from 'payload'\n\nimport type { BuildContext } from '@/shared/types/index.js'\n\nexport const getOpenapiMeta = (endpoint: Endpoint): OperationObject | undefined => {\n const meta = endpoint.custom?.openapi\n return meta && typeof meta === 'object' ? (meta as OperationObject) : undefined\n}\n\nexport const normalizePath = (prefix: string, path: string): string => {\n const joined = `${prefix}${path.startsWith('/') ? path : `/${path}`}`\n return joined.replace(/:([A-Za-z0-9_]+)/g, '{$1}')\n}\n\nconst collect = ({\n endpoints,\n prefix,\n out,\n}: {\n endpoints: Endpoint[] | false | undefined\n prefix: string\n out: PathsObject\n}): void => {\n if (!endpoints) return\n for (const endpoint of endpoints) {\n const meta = getOpenapiMeta(endpoint)\n if (!meta) continue\n const path = normalizePath(prefix, endpoint.path)\n const method = endpoint.method.toLowerCase()\n out[path] = { ...out[path], [method]: { ...meta } }\n }\n}\n\nexport const buildCustomEndpointPaths = ({\n config,\n collections,\n globals,\n ctx,\n}: {\n config: SanitizedConfig\n collections: SanitizedCollectionConfig[]\n globals: SanitizedGlobalConfig[]\n ctx: BuildContext\n}): PathsObject => {\n const out: PathsObject = {}\n collect({ endpoints: config.endpoints, prefix: ctx.apiRoute, out })\n for (const collection of collections) {\n collect({ endpoints: collection.endpoints, prefix: `${ctx.apiRoute}/${collection.slug}`, out })\n }\n for (const global of globals) {\n collect({ endpoints: global.endpoints, prefix: `${ctx.apiRoute}/globals/${global.slug}`, out })\n }\n return out\n}\n"],"mappings":"AAKA,MAAa,kBAAkB,aAAoD;CACjF,MAAM,OAAO,SAAS,QAAQ;CAC9B,OAAO,QAAQ,OAAO,SAAS,WAAY,OAA2B,KAAA;AACxE;AAEA,MAAa,iBAAiB,QAAgB,SAAyB;CAErE,OAAO,GADW,SAAS,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,SAC/C,QAAQ,qBAAqB,MAAM;AACnD;AAEA,MAAM,WAAW,EACf,WACA,QACA,UAKU;CACV,IAAI,CAAC,WAAW;CAChB,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,OAAO,eAAe,QAAQ;EACpC,IAAI,CAAC,MAAM;EACX,MAAM,OAAO,cAAc,QAAQ,SAAS,IAAI;EAChD,MAAM,SAAS,SAAS,OAAO,YAAY;EAC3C,IAAI,QAAQ;GAAE,GAAG,IAAI;IAAQ,SAAS,EAAE,GAAG,KAAK;EAAE;CACpD;AACF;AAEA,MAAa,4BAA4B,EACvC,QACA,aACA,SACA,UAMiB;CACjB,MAAM,MAAmB,CAAC;CAC1B,QAAQ;EAAE,WAAW,OAAO;EAAW,QAAQ,IAAI;EAAU;CAAI,CAAC;CAClE,KAAK,MAAM,cAAc,aACvB,QAAQ;EAAE,WAAW,WAAW;EAAW,QAAQ,GAAG,IAAI,SAAS,GAAG,WAAW;EAAQ;CAAI,CAAC;CAEhG,KAAK,MAAM,UAAU,SACnB,QAAQ;EAAE,WAAW,OAAO;EAAW,QAAQ,GAAG,IAAI,SAAS,WAAW,OAAO;EAAQ;CAAI,CAAC;CAEhG,OAAO;AACT"}
@@ -1,8 +1,9 @@
1
1
  import { BuildContext } from "../../../shared/types/index.js";
2
2
  import { PathsObject } from "@scalar/openapi-types/3.2";
3
- export declare const buildSystemPaths: ({ ctx, access, uploadSlugs }: {
3
+ export declare const buildSystemPaths: ({ ctx, access, uploadSlugs, reorderSlugs }: {
4
4
  ctx: BuildContext;
5
5
  access: boolean;
6
6
  uploadSlugs: string[];
7
+ reorderSlugs?: string[];
7
8
  }) => PathsObject;
8
9
  //# sourceMappingURL=system.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { SECURITY_SCHEME_NAME, errorResponses, jsonBody, jsonResponse } from "../components.js";
2
2
  import { makeT } from "../../../shared/translations/index.js";
3
- const buildSystemPaths = ({ ctx, access, uploadSlugs }) => {
3
+ const buildSystemPaths = ({ ctx, access, uploadSlugs, reorderSlugs = [] }) => {
4
4
  const t = makeT(ctx.i18n);
5
5
  const paths = {};
6
6
  if (access) paths[`${ctx.apiRoute}/access`] = { get: {
@@ -130,6 +130,72 @@ const buildSystemPaths = ({ ctx, access, uploadSlugs }) => {
130
130
  }
131
131
  };
132
132
  }
133
+ if (reorderSlugs.length > 0) {
134
+ const idType = ctx.defaultIDType === "number" ? "integer" : "string";
135
+ paths[`${ctx.apiRoute}/reorder`] = { post: {
136
+ tags: ["Reorder"],
137
+ operationId: "reorder",
138
+ summary: t("reorder"),
139
+ requestBody: {
140
+ ...jsonBody({
141
+ type: "object",
142
+ properties: {
143
+ collectionSlug: {
144
+ type: "string",
145
+ enum: reorderSlugs
146
+ },
147
+ docsToMove: {
148
+ type: "array",
149
+ minItems: 1,
150
+ items: { type: idType }
151
+ },
152
+ newKeyWillBe: {
153
+ type: "string",
154
+ enum: ["greater", "less"]
155
+ },
156
+ orderableFieldName: { type: "string" },
157
+ target: {
158
+ type: "object",
159
+ properties: {
160
+ id: { type: idType },
161
+ key: { type: "string" }
162
+ },
163
+ required: ["id"]
164
+ }
165
+ },
166
+ required: [
167
+ "collectionSlug",
168
+ "docsToMove",
169
+ "newKeyWillBe",
170
+ "orderableFieldName",
171
+ "target"
172
+ ]
173
+ }),
174
+ description: t("reorderBody")
175
+ },
176
+ responses: {
177
+ "200": jsonResponse(t("reorderResult"), {
178
+ type: "object",
179
+ properties: {
180
+ success: { type: "boolean" },
181
+ orderValues: {
182
+ type: "array",
183
+ items: { type: "string" }
184
+ },
185
+ message: { type: "string" }
186
+ },
187
+ required: ["success"]
188
+ }),
189
+ "400": jsonResponse(t("errorReorder400"), {
190
+ type: "object",
191
+ properties: { error: { type: "string" } },
192
+ required: ["error"]
193
+ }),
194
+ ...errorResponses(["403", "500"], t)
195
+ },
196
+ security: [{ [SECURITY_SCHEME_NAME]: [] }]
197
+ } };
198
+ }
133
199
  return paths;
134
200
  };
135
201
  export { buildSystemPaths };
@@ -1 +1 @@
1
- {"version":3,"file":"system.js","names":[],"sources":["../../../../src/server/spec/paths/system.ts"],"sourcesContent":["import type { PathsObject, ResponsesObject } from '@scalar/openapi-types/3.2'\n\nimport { SECURITY_SCHEME_NAME, errorResponses, jsonBody, jsonResponse } from '@/server/spec/components.js'\nimport { makeT } from '@/shared/translations/index.js'\nimport type { BuildContext } from '@/shared/types/index.js'\n\nexport const buildSystemPaths = ({\n ctx,\n access,\n uploadSlugs,\n}: {\n ctx: BuildContext\n access: boolean\n uploadSlugs: string[]\n}): PathsObject => {\n const t = makeT(ctx.i18n)\n const paths: PathsObject = {}\n\n if (access) {\n paths[`${ctx.apiRoute}/access`] = {\n get: {\n tags: ['Access'],\n operationId: 'access',\n responses: {\n '200': jsonResponse(t('authAccess'), { type: 'object', additionalProperties: true }),\n ...errorResponses(['500'], t),\n },\n },\n }\n }\n\n if (uploadSlugs.length > 0) {\n const staged: ResponsesObject = {\n '204': { description: t('uploadStageResult') },\n ...errorResponses(['400', '500'], t),\n }\n\n paths[`${ctx.apiRoute}/upload-instructions`] = {\n post: {\n tags: ['Uploads'],\n operationId: 'getUploadInstructions',\n summary: t('uploadInstructionsSummary'),\n requestBody: jsonBody({\n type: 'object',\n additionalProperties: false,\n properties: {\n collectionSlug: { type: 'string', enum: uploadSlugs },\n docPrefix: { type: 'string' },\n filename: { type: 'string' },\n filesize: { type: 'integer', minimum: 0 },\n mimeType: { type: 'string' },\n },\n required: ['collectionSlug', 'filename', 'filesize', 'mimeType'],\n }),\n responses: {\n '200': jsonResponse(t('uploadInstructionsResult'), {\n type: 'object',\n properties: {\n type: { type: 'string', enum: ['http', 'dispatch'] },\n file: {\n type: 'object',\n properties: {\n filename: { type: 'string' },\n mimeType: { type: 'string' },\n size: { type: 'integer' },\n uploadReference: { type: 'object', additionalProperties: true },\n },\n required: ['filename', 'mimeType', 'size', 'uploadReference'],\n },\n request: {\n type: 'object',\n properties: {\n method: { type: 'string', enum: ['POST', 'PUT'] },\n url: { type: 'string' },\n headers: { type: 'object', additionalProperties: { type: 'string' } },\n },\n required: ['method', 'url'],\n },\n name: { type: 'string' },\n data: {},\n },\n required: ['type', 'file'],\n }),\n ...errorResponses(['400', '403', '500'], t),\n },\n security: [{ [SECURITY_SCHEME_NAME]: [] }],\n },\n }\n paths[`${ctx.apiRoute}/upload-instructions/{uploadId}`] = {\n parameters: [{ name: 'uploadId', in: 'path', required: true, schema: { type: 'string' } }],\n put: {\n tags: ['Uploads'],\n operationId: 'uploadStagedFile',\n summary: t('uploadStagePutSummary'),\n requestBody: {\n required: true,\n content: { '*/*': { schema: { type: 'string', format: 'binary' } } },\n },\n responses: staged,\n security: [{ [SECURITY_SCHEME_NAME]: [] }],\n },\n delete: {\n tags: ['Uploads'],\n operationId: 'deleteStagedFile',\n summary: t('uploadStageDeleteSummary'),\n responses: staged,\n security: [{ [SECURITY_SCHEME_NAME]: [] }],\n },\n }\n }\n\n return paths\n}\n"],"mappings":";;AAMA,MAAa,oBAAoB,EAC/B,KACA,QACA,kBAKiB;CACjB,MAAM,IAAI,MAAM,IAAI,IAAI;CACxB,MAAM,QAAqB,CAAC;CAE5B,IAAI,QACF,MAAM,GAAG,IAAI,SAAS,YAAY,EAChC,KAAK;EACH,MAAM,CAAC,QAAQ;EACf,aAAa;EACb,WAAW;GACT,OAAO,aAAa,EAAE,YAAY,GAAG;IAAE,MAAM;IAAU,sBAAsB;GAAK,CAAC;GACnF,GAAG,eAAe,CAAC,KAAK,GAAG,CAAC;EAC9B;CACF,EACF;CAGF,IAAI,YAAY,SAAS,GAAG;EAC1B,MAAM,SAA0B;GAC9B,OA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AAC;GAC5C;GACA,UAAU,CAAC,GAAG,uBAAuB,CAAC,EAAE,CAAC;EAC3C,EACF;EACA,MAAM,GAAG,IAAI,SAAS,oCAAoC;GACxD,YAAY,CAAC;IAAE,MAAM;IAAY,IAAI;IAAQ,UAAU;IAAM,QAAQ,EAAE,MAAM,SAAS;GAAE,CAAC;GACzF,KAAK;IACH,MAAM,CAAC,SAAS;IAChB,aAAa;IACb,SAAS,EAAE,uBAAuB;IAClC,aAAa;KACX,UAAU;KACV,SAAS,EAAE,OAAO,EAAE,QAAQ;MAAE,MAAM;MAAU,QAAQ;KAAS,EAAE,EAAE;IACrE;IACA,WAAW;IACX,UAAU,CAAC,GAAG,uBAAuB,CAAC,EAAE,CAAC;GAC3C;GACA,QAAQ;IACN,MAAM,CAAC,SAAS;IAChB,aAAa;IACb,SAAS,EAAE,0BAA0B;IACrC,WAAW;IACX,UAAU,CAAC,GAAG,uBAAuB,CAAC,EAAE,CAAC;GAC3C;EACF;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"system.js","names":[],"sources":["../../../../src/server/spec/paths/system.ts"],"sourcesContent":["import type { PathsObject, ResponsesObject } from '@scalar/openapi-types/3.2'\n\nimport { SECURITY_SCHEME_NAME, errorResponses, jsonBody, jsonResponse } from '@/server/spec/components.js'\nimport { makeT } from '@/shared/translations/index.js'\nimport type { BuildContext } from '@/shared/types/index.js'\n\nexport const buildSystemPaths = ({\n ctx,\n access,\n uploadSlugs,\n reorderSlugs = [],\n}: {\n ctx: BuildContext\n access: boolean\n uploadSlugs: string[]\n reorderSlugs?: string[]\n}): PathsObject => {\n const t = makeT(ctx.i18n)\n const paths: PathsObject = {}\n\n if (access) {\n paths[`${ctx.apiRoute}/access`] = {\n get: {\n tags: ['Access'],\n operationId: 'access',\n responses: {\n '200': jsonResponse(t('authAccess'), { type: 'object', additionalProperties: true }),\n ...errorResponses(['500'], t),\n },\n },\n }\n }\n\n if (uploadSlugs.length > 0) {\n const staged: ResponsesObject = {\n '204': { description: t('uploadStageResult') },\n ...errorResponses(['400', '500'], t),\n }\n\n paths[`${ctx.apiRoute}/upload-instructions`] = {\n post: {\n tags: ['Uploads'],\n operationId: 'getUploadInstructions',\n summary: t('uploadInstructionsSummary'),\n requestBody: jsonBody({\n type: 'object',\n additionalProperties: false,\n properties: {\n collectionSlug: { type: 'string', enum: uploadSlugs },\n docPrefix: { type: 'string' },\n filename: { type: 'string' },\n filesize: { type: 'integer', minimum: 0 },\n mimeType: { type: 'string' },\n },\n required: ['collectionSlug', 'filename', 'filesize', 'mimeType'],\n }),\n responses: {\n '200': jsonResponse(t('uploadInstructionsResult'), {\n type: 'object',\n properties: {\n type: { type: 'string', enum: ['http', 'dispatch'] },\n file: {\n type: 'object',\n properties: {\n filename: { type: 'string' },\n mimeType: { type: 'string' },\n size: { type: 'integer' },\n uploadReference: { type: 'object', additionalProperties: true },\n },\n required: ['filename', 'mimeType', 'size', 'uploadReference'],\n },\n request: {\n type: 'object',\n properties: {\n method: { type: 'string', enum: ['POST', 'PUT'] },\n url: { type: 'string' },\n headers: { type: 'object', additionalProperties: { type: 'string' } },\n },\n required: ['method', 'url'],\n },\n name: { type: 'string' },\n data: {},\n },\n required: ['type', 'file'],\n }),\n ...errorResponses(['400', '403', '500'], t),\n },\n security: [{ [SECURITY_SCHEME_NAME]: [] }],\n },\n }\n paths[`${ctx.apiRoute}/upload-instructions/{uploadId}`] = {\n parameters: [{ name: 'uploadId', in: 'path', required: true, schema: { type: 'string' } }],\n put: {\n tags: ['Uploads'],\n operationId: 'uploadStagedFile',\n summary: t('uploadStagePutSummary'),\n requestBody: {\n required: true,\n content: { '*/*': { schema: { type: 'string', format: 'binary' } } },\n },\n responses: staged,\n security: [{ [SECURITY_SCHEME_NAME]: [] }],\n },\n delete: {\n tags: ['Uploads'],\n operationId: 'deleteStagedFile',\n summary: t('uploadStageDeleteSummary'),\n responses: staged,\n security: [{ [SECURITY_SCHEME_NAME]: [] }],\n },\n }\n }\n\n if (reorderSlugs.length > 0) {\n const idType = ctx.defaultIDType === 'number' ? 'integer' : 'string'\n paths[`${ctx.apiRoute}/reorder`] = {\n post: {\n tags: ['Reorder'],\n operationId: 'reorder',\n summary: t('reorder'),\n requestBody: {\n ...jsonBody({\n type: 'object',\n properties: {\n collectionSlug: { type: 'string', enum: reorderSlugs },\n docsToMove: { type: 'array', minItems: 1, items: { type: idType } },\n newKeyWillBe: { type: 'string', enum: ['greater', 'less'] },\n orderableFieldName: { type: 'string' },\n target: {\n type: 'object',\n properties: { id: { type: idType }, key: { type: 'string' } },\n required: ['id'],\n },\n },\n required: ['collectionSlug', 'docsToMove', 'newKeyWillBe', 'orderableFieldName', 'target'],\n }),\n description: t('reorderBody'),\n },\n responses: {\n '200': jsonResponse(t('reorderResult'), {\n type: 'object',\n properties: {\n success: { type: 'boolean' },\n orderValues: { type: 'array', items: { type: 'string' } },\n message: { type: 'string' },\n },\n required: ['success'],\n }),\n '400': jsonResponse(t('errorReorder400'), {\n type: 'object',\n properties: { error: { type: 'string' } },\n required: ['error'],\n }),\n ...errorResponses(['403', '500'], t),\n },\n security: [{ [SECURITY_SCHEME_NAME]: [] }],\n },\n }\n }\n\n return paths\n}\n"],"mappings":";;AAMA,MAAa,oBAAoB,EAC/B,KACA,QACA,aACA,eAAe,CAAC,QAMC;CACjB,MAAM,IAAI,MAAM,IAAI,IAAI;CACxB,MAAM,QAAqB,CAAC;CAE5B,IAAI,QACF,MAAM,GAAG,IAAI,SAAS,YAAY,EAChC,KAAK;EACH,MAAM,CAAC,QAAQ;EACf,aAAa;EACb,WAAW;GACT,OAAO,aAAa,EAAE,YAAY,GAAG;IAAE,MAAM;IAAU,sBAAsB;GAAK,CAAC;GACnF,GAAG,eAAe,CAAC,KAAK,GAAG,CAAC;EAC9B;CACF,EACF;CAGF,IAAI,YAAY,SAAS,GAAG;EAC1B,MAAM,SAA0B;GAC9B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE;GAC7C,GAAG,eAAe,CAAC,OAAO,KA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AO,aAAa,EAAE,eAAe,GAAG;KACtC,MAAM;KACN,YAAY;MACV,SAAS,EAAE,MAAM,UAAU;MAC3B,aAAa;OAAE,MAAM;OAAS,OAAO,EAAE,MAAM,SAAS;MAAE;MACxD,SAAS,EAAE,MAAM,SAAS;KAC5B;KACA,UAAU,CAAC,SAAS;IACtB,CAAC;IACD,OAAO,aAAa,EAAE,iBAAiB,GAAG;KACxC,MAAM;KACN,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE;KACxC,UAAU,CAAC,OAAO;IACpB,CAAC;IACD,GAAG,eAAe,CAAC,OAAO,KAAK,GAAG,CAAC;GACrC;GACA,UAAU,CAAC,GAAG,uBAAuB,CAAC,EAAE,CAAC;EAC3C,EACF;CACF;CAEA,OAAO;AACT"}
@@ -0,0 +1,3 @@
1
+ import { OfficialPlugin } from "./shared.js";
2
+ export declare const ecommerce: OfficialPlugin;
3
+ //# sourceMappingURL=ecommerce.d.ts.map
@@ -0,0 +1,270 @@
1
+ import { upperFirst } from "../../../shared/utils.js";
2
+ import { refTo, schemaName } from "../names.js";
3
+ import { ERROR_SCHEMA_NAME, errorResponses, jsonBody, jsonResponse } from "../components.js";
4
+ import { securedRequirement } from "../security.js";
5
+ import { collectionGroups, idSchema, messageErrors, mountEndpoints } from "./shared.js";
6
+ import { stripeWebhookOperation } from "./stripe.js";
7
+ const TAG = "Ecommerce";
8
+ const PAYMENT_PATH = /^\/payments\/([^/]+)\/(initiate|confirm-order)$/;
9
+ const CART_OPERATIONS = {
10
+ "/:id/add-item": {
11
+ operationId: "addItem",
12
+ summary: "ecommerceAddItem"
13
+ },
14
+ "/:id/remove-item": {
15
+ operationId: "removeItem",
16
+ summary: "ecommerceRemoveItem"
17
+ },
18
+ "/:id/update-item": {
19
+ operationId: "updateItem",
20
+ summary: "ecommerceUpdateItem"
21
+ },
22
+ "/:id/clear": {
23
+ operationId: "clear",
24
+ summary: "ecommerceClearCart"
25
+ },
26
+ "/:id/merge": {
27
+ operationId: "merge",
28
+ summary: "ecommerceMergeCart"
29
+ }
30
+ };
31
+ const ecommerce = {
32
+ slug: "@payloadcms/plugin-ecommerce",
33
+ tag: TAG,
34
+ build: ({ config, collections, ctx, schemas, t }) => {
35
+ const id = idSchema(ctx);
36
+ const secret = { type: "string" };
37
+ const failure = {
38
+ type: "object",
39
+ properties: {
40
+ message: { type: "string" },
41
+ success: {
42
+ type: "boolean",
43
+ enum: [false]
44
+ }
45
+ },
46
+ required: ["message", "success"]
47
+ };
48
+ const cartBodies = {
49
+ "/:id/add-item": {
50
+ type: "object",
51
+ properties: {
52
+ item: {
53
+ type: "object",
54
+ additionalProperties: true,
55
+ properties: {
56
+ product: id,
57
+ variant: id
58
+ },
59
+ required: ["product"]
60
+ },
61
+ quantity: {
62
+ type: "number",
63
+ default: 1
64
+ },
65
+ secret
66
+ },
67
+ required: ["item"]
68
+ },
69
+ "/:id/remove-item": {
70
+ type: "object",
71
+ properties: {
72
+ itemID: { type: "string" },
73
+ secret
74
+ },
75
+ required: ["itemID"]
76
+ },
77
+ "/:id/update-item": {
78
+ type: "object",
79
+ properties: {
80
+ itemID: { type: "string" },
81
+ quantity: {
82
+ description: t("ecommerceQuantity"),
83
+ oneOf: [{ type: "number" }, {
84
+ type: "object",
85
+ properties: { $inc: { type: "number" } },
86
+ required: ["$inc"]
87
+ }]
88
+ },
89
+ removeOnZero: {
90
+ type: "boolean",
91
+ default: true
92
+ },
93
+ secret
94
+ },
95
+ required: ["itemID", "quantity"]
96
+ },
97
+ "/:id/clear": {
98
+ type: "object",
99
+ properties: { secret }
100
+ },
101
+ "/:id/merge": {
102
+ type: "object",
103
+ properties: {
104
+ sourceCartID: id,
105
+ sourceSecret: { type: "string" }
106
+ },
107
+ required: ["sourceCartID", "sourceSecret"]
108
+ }
109
+ };
110
+ const cartGroups = collectionGroups(collections.filter((c) => (c.endpoints || []).some((endpoint) => endpoint.method === "post" && endpoint.path === "/:id/add-item")), ctx, ({ method, path }, collection) => {
111
+ const meta = CART_OPERATIONS[path];
112
+ if (!meta || method !== "post") return void 0;
113
+ const name = schemaName(collection.slug);
114
+ const merge = path === "/:id/merge";
115
+ const cart = schemas[name] ? { $ref: refTo(name) } : {
116
+ type: "object",
117
+ additionalProperties: true
118
+ };
119
+ const param = {
120
+ name: "id",
121
+ in: "path",
122
+ required: true,
123
+ schema: id
124
+ };
125
+ return {
126
+ tags: [TAG],
127
+ operationId: `${meta.operationId}${name}`,
128
+ summary: t(meta.summary),
129
+ description: merge ? void 0 : t("ecommerceCartAccess"),
130
+ parameters: [param],
131
+ requestBody: {
132
+ ...jsonBody(cartBodies[path]),
133
+ required: path !== "/:id/clear"
134
+ },
135
+ responses: {
136
+ "200": jsonResponse(t("ecommerceCartResult"), {
137
+ type: "object",
138
+ properties: {
139
+ cart,
140
+ message: { type: "string" },
141
+ success: {
142
+ type: "boolean",
143
+ enum: [true]
144
+ }
145
+ },
146
+ required: [
147
+ "cart",
148
+ "message",
149
+ "success"
150
+ ]
151
+ }),
152
+ ...messageErrors(merge ? ["400", "401"] : ["400"], t, failure),
153
+ ...errorResponses(["403"], t),
154
+ "404": jsonResponse(t("errorPluginEcommerce404"), { oneOf: [{
155
+ type: "object",
156
+ properties: {
157
+ cart: { type: ["object", "null"] },
158
+ ...failure.properties
159
+ },
160
+ required: [
161
+ "cart",
162
+ "message",
163
+ "success"
164
+ ]
165
+ }, { $ref: refTo(ERROR_SCHEMA_NAME) }] })
166
+ },
167
+ ...merge ? { security: securedRequirement() } : {}
168
+ };
169
+ });
170
+ const address = {
171
+ type: "object",
172
+ additionalProperties: true
173
+ };
174
+ const paymentBody = (extra) => ({
175
+ ...jsonBody({
176
+ type: "object",
177
+ additionalProperties: true,
178
+ properties: {
179
+ cartID: id,
180
+ secret,
181
+ customerEmail: {
182
+ type: "string",
183
+ format: "email"
184
+ },
185
+ billingAddress: address,
186
+ shippingAddress: address,
187
+ ...extra
188
+ },
189
+ ...Object.keys(extra).length > 0 ? { required: Object.keys(extra) } : {}
190
+ }),
191
+ description: t("ecommercePaymentBody")
192
+ });
193
+ const usedIds = /* @__PURE__ */ new Set();
194
+ const uniqueId = (base) => {
195
+ let operationId = base;
196
+ for (let n = 2; usedIds.has(operationId); n++) operationId = `${base}${n}`;
197
+ usedIds.add(operationId);
198
+ return operationId;
199
+ };
200
+ return [{ paths: mountEndpoints(config.endpoints, ctx.apiRoute, ({ method, path }) => {
201
+ if (method !== "post") return void 0;
202
+ if (path === "/payments/stripe/webhooks") return stripeWebhookOperation({
203
+ tag: TAG,
204
+ operationId: "ecommerceStripeWebhooks",
205
+ t
206
+ });
207
+ const match = PAYMENT_PATH.exec(path);
208
+ if (!match) return void 0;
209
+ const [, methodName = "", step] = match;
210
+ const stripe = methodName === "stripe";
211
+ const suffix = upperFirst(methodName.replace(/[^A-Za-z0-9]+(.)?/g, (_, c = "") => c.toUpperCase()));
212
+ if (step === "initiate") return {
213
+ tags: [TAG],
214
+ operationId: uniqueId(`initiatePayment${suffix}`),
215
+ summary: t("ecommerceInitiatePayment", { method: methodName }),
216
+ requestBody: paymentBody({}),
217
+ responses: {
218
+ "200": jsonResponse(t("ecommerceInitiateResult"), {
219
+ type: "object",
220
+ additionalProperties: true,
221
+ properties: {
222
+ message: { type: "string" },
223
+ ...stripe ? {
224
+ clientSecret: { type: "string" },
225
+ paymentIntentID: { type: "string" }
226
+ } : {}
227
+ },
228
+ required: ["message"]
229
+ }),
230
+ ...messageErrors([
231
+ "400",
232
+ "404",
233
+ "500"
234
+ ], t)
235
+ }
236
+ };
237
+ return {
238
+ tags: [TAG],
239
+ operationId: uniqueId(`confirmOrder${suffix}`),
240
+ summary: t("ecommerceConfirmOrder", { method: methodName }),
241
+ requestBody: paymentBody(stripe ? { paymentIntentID: { type: "string" } } : {}),
242
+ responses: {
243
+ "200": jsonResponse(t("ecommerceConfirmResult"), {
244
+ type: "object",
245
+ additionalProperties: true,
246
+ properties: {
247
+ message: { type: "string" },
248
+ orderID: id,
249
+ transactionID: id,
250
+ ...stripe ? { accessToken: { type: "string" } } : {}
251
+ },
252
+ required: [
253
+ "message",
254
+ "orderID",
255
+ "transactionID"
256
+ ]
257
+ }),
258
+ ...messageErrors([
259
+ "400",
260
+ "404",
261
+ "500"
262
+ ], t)
263
+ }
264
+ };
265
+ }) }, ...cartGroups];
266
+ }
267
+ };
268
+ export { ecommerce };
269
+
270
+ //# sourceMappingURL=ecommerce.js.map