@payloadcms/figma 0.1.0-alpha.0 → 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/dist/{utils → adapters}/asset-collection.d.ts +17 -3
- package/dist/adapters/asset-collection.js +242 -0
- package/dist/{utils → adapters}/build-lambda-zip.d.ts +8 -7
- package/dist/adapters/build-lambda-zip.js +111 -0
- package/dist/adapters/configureNextjsCache.d.ts +8 -0
- package/dist/adapters/configureNextjsCache.js +55 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +1 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +15 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.d.ts +12 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.js +28 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.d.ts +9 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.js +13 -0
- package/dist/adapters/deploy-output/isFile.d.ts +1 -0
- package/dist/adapters/deploy-output/isFile.js +4 -0
- package/dist/adapters/deploy-output/readJson.d.ts +1 -0
- package/dist/adapters/deploy-output/readJson.js +9 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.d.ts +8 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.js +16 -0
- package/dist/adapters/deploy-output/resolveOutputPath.d.ts +2 -0
- package/dist/adapters/deploy-output/resolveOutputPath.js +9 -0
- package/dist/adapters/deploy-output/resolveWithin.d.ts +1 -0
- package/dist/adapters/deploy-output/resolveWithin.js +12 -0
- package/dist/adapters/fs-utils.d.ts +39 -0
- package/dist/adapters/fs-utils.js +135 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.d.ts +40 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.js +174 -0
- package/dist/adapters/nextjs.d.ts +12 -0
- package/dist/adapters/nextjs.js +67 -0
- package/dist/adapters/nitro.d.ts +8 -0
- package/dist/adapters/nitro.js +193 -0
- package/dist/adapters/secret-files.d.ts +25 -0
- package/dist/adapters/secret-files.js +50 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.js +1 -0
- package/dist/{utils/adapters → adapters}/vite.d.ts +2 -2
- package/dist/adapters/vite.js +33 -0
- package/dist/api/check-project-subdomain-availability.d.ts +12 -0
- package/dist/api/check-project-subdomain-availability.js +32 -0
- package/dist/api/control-plane-error.d.ts +6 -0
- package/dist/api/control-plane-error.js +8 -0
- package/dist/api/control-plane-fetch.d.ts +7 -0
- package/dist/api/control-plane-fetch.js +37 -0
- package/dist/api/control-plane.d.ts +1 -9
- package/dist/api/control-plane.js +2 -48
- package/dist/api/create-project.d.ts +18 -0
- package/dist/api/create-project.js +37 -0
- package/dist/api/list-project-workspaces.d.ts +8 -0
- package/dist/api/list-project-workspaces.js +28 -0
- package/dist/api/project-resource-type.d.ts +1 -0
- package/dist/api/project-resource-type.js +1 -0
- package/dist/auth/headless-oauth-flow.d.ts +23 -0
- package/dist/auth/headless-oauth-flow.js +69 -0
- package/dist/auth/oauth-flow.d.ts +2 -0
- package/dist/auth/oauth-flow.js +13 -8
- package/dist/auth/token-store.d.ts +4 -1
- package/dist/auth/token-store.js +14 -0
- package/dist/auth/types.d.ts +12 -0
- package/dist/cli.d.ts +39 -0
- package/dist/cli.js +71 -36
- package/dist/commands/bootstrap.js +2 -1
- package/dist/commands/build-lambda-zip.js +1 -1
- package/dist/commands/deploy.d.ts +12 -0
- package/dist/commands/deploy.js +63 -25
- package/dist/commands/detect-project-resource-type.d.ts +3 -0
- package/dist/commands/detect-project-resource-type.js +28 -0
- package/dist/commands/init.d.ts +2 -2
- package/dist/commands/init.js +164 -79
- package/dist/commands/login.d.ts +11 -1
- package/dist/commands/login.js +66 -4
- package/dist/commands/prompt-to-create-project/format-project-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-project-subdomain.js +3 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.js +7 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.js +13 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.d.ts +7 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.js +32 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.d.ts +8 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.js +27 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.js +54 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.js +23 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.d.ts +12 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.js +36 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.js +9 -0
- package/dist/commands/prompt-to-create-project.d.ts +24 -0
- package/dist/commands/prompt-to-create-project.js +69 -0
- package/dist/commands/setup-agent.d.ts +12 -0
- package/dist/commands/setup-agent.js +123 -0
- package/dist/commands/write-project-configuration.d.ts +12 -0
- package/dist/commands/write-project-configuration.js +16 -0
- package/dist/db-content-api/generated/content-api-types.d.ts +661 -16
- package/dist/db-content-api/index.d.ts +3 -0
- package/dist/db-content-api/index.js +155 -161
- package/dist/db-content-api/utilities/clientVersionHeaders.d.ts +7 -0
- package/dist/db-content-api/utilities/clientVersionHeaders.js +15 -0
- package/dist/db-content-api/utilities/data/atomicOperations.d.ts +16 -0
- package/dist/db-content-api/utilities/data/atomicOperations.js +48 -0
- package/dist/db-content-api/utilities/data/convertRelationshipIds.d.ts +25 -0
- package/dist/db-content-api/utilities/data/convertRelationshipIds.js +109 -0
- package/dist/db-content-api/utilities/data/index.js +73 -57
- package/dist/db-content-api/utilities/data/injectGlobalType.d.ts +6 -0
- package/dist/db-content-api/utilities/data/injectGlobalType.js +11 -0
- package/dist/db-content-api/utilities/data/isLocaleMap.d.ts +10 -0
- package/dist/db-content-api/utilities/data/isLocaleMap.js +13 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +3 -11
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
- package/dist/db-content-api/utilities/data/resolveFieldLocalization.d.ts +18 -0
- package/dist/db-content-api/utilities/data/resolveFieldLocalization.js +21 -0
- package/dist/db-content-api/utilities/data/validateRelationships.js +19 -12
- package/dist/db-content-api/utilities/isRecord.d.ts +9 -0
- package/dist/db-content-api/utilities/isRecord.js +19 -0
- package/dist/db-content-api/utilities/joins.d.ts +6 -8
- package/dist/db-content-api/utilities/joins.js +13 -22
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.d.ts +10 -0
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.js +95 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.d.ts +9 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.js +112 -0
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.d.ts +21 -4
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +118 -36
- package/dist/db-content-api/utilities/schema/getDocumentSchema.d.ts +3 -0
- package/dist/db-content-api/utilities/schema/getDocumentSchema.js +24 -0
- package/dist/db-content-api/utilities/where.d.ts +3 -17
- package/dist/db-content-api/utilities/where.js +21 -21
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.js +2 -0
- package/dist/exports/views.d.ts +1 -0
- package/dist/exports/views.js +1 -0
- package/dist/imageSizeOptions.d.ts +23 -0
- package/dist/imageSizeOptions.js +26 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/write-agent-config.d.ts +12 -0
- package/dist/lib/write-agent-config.js +52 -0
- package/dist/next/image-loader.d.ts +6 -0
- package/dist/next/image-loader.js +14 -0
- package/dist/oauth/components/LoginButton/index.js +66 -19
- package/dist/oauth/components/LoginButton/index.scss +121 -15
- package/dist/oauth/defaults.js +4 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js +5 -2
- package/dist/oauth/index.js +8 -7
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +1 -1
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +5 -1
- package/dist/plugin/build-config.d.ts +4 -2
- package/dist/plugin/build-config.js +95 -31
- package/dist/plugin/cache-revalidation-hooks.d.ts +6 -0
- package/dist/plugin/cache-revalidation-hooks.js +69 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +8 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.js +66 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.scss +56 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.js +110 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.css +14 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.js +52 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.d.ts +7 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.js +3 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.d.ts +1 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.js +27 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.js +30 -0
- package/dist/plugin/cloud-limits/routes.d.ts +2 -0
- package/dist/plugin/cloud-limits/routes.js +4 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.d.ts +9 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.js +28 -0
- package/dist/plugin/cloud-limits/shared.d.ts +10 -0
- package/dist/plugin/cloud-limits/shared.js +52 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.d.ts +2 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.js +134 -0
- package/dist/plugin/cloud-limits/utilities/toasts.d.ts +4 -0
- package/dist/plugin/cloud-limits/utilities/toasts.js +19 -0
- package/dist/plugin/make-permission-access/make-permission-access.d.ts +8 -0
- package/dist/plugin/make-permission-access/make-permission-access.js +24 -0
- package/dist/plugin/sandbox-upload-fetch.d.ts +32 -0
- package/dist/plugin/sandbox-upload-fetch.js +53 -0
- package/dist/skills/deploy-to-figma/SKILL.md +234 -0
- package/dist/skills/deploy-to-figma/references/cli-reference.md +146 -0
- package/dist/storage-content-api/client-uploads/generate.js +2 -1
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +11 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +27 -0
- package/dist/storage-content-api/index.js +1 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
- package/dist/storage-content-api/staticHandler.js +2 -1
- package/dist/storage-content-api/types.d.ts +4 -1
- package/dist/translations/ar.d.ts +12 -0
- package/dist/translations/ar.js +12 -0
- package/dist/translations/az.d.ts +12 -0
- package/dist/translations/az.js +12 -0
- package/dist/translations/bg.d.ts +12 -0
- package/dist/translations/bg.js +12 -0
- package/dist/translations/bnBd.d.ts +12 -0
- package/dist/translations/bnBd.js +12 -0
- package/dist/translations/bnIn.d.ts +12 -0
- package/dist/translations/bnIn.js +12 -0
- package/dist/translations/ca.d.ts +12 -0
- package/dist/translations/ca.js +12 -0
- package/dist/translations/cs.d.ts +12 -0
- package/dist/translations/cs.js +12 -0
- package/dist/translations/da.d.ts +12 -0
- package/dist/translations/da.js +12 -0
- package/dist/translations/de.d.ts +12 -0
- package/dist/translations/de.js +12 -0
- package/dist/translations/en.d.ts +12 -0
- package/dist/translations/en.js +12 -0
- package/dist/translations/es.d.ts +12 -0
- package/dist/translations/es.js +12 -0
- package/dist/translations/et.d.ts +12 -0
- package/dist/translations/et.js +12 -0
- package/dist/translations/fa.d.ts +12 -0
- package/dist/translations/fa.js +12 -0
- package/dist/translations/fr.d.ts +12 -0
- package/dist/translations/fr.js +12 -0
- package/dist/translations/he.d.ts +12 -0
- package/dist/translations/he.js +12 -0
- package/dist/translations/hr.d.ts +12 -0
- package/dist/translations/hr.js +12 -0
- package/dist/translations/hu.d.ts +12 -0
- package/dist/translations/hu.js +12 -0
- package/dist/translations/hy.d.ts +12 -0
- package/dist/translations/hy.js +12 -0
- package/dist/translations/id.d.ts +12 -0
- package/dist/translations/id.js +12 -0
- package/dist/translations/index.d.ts +533 -0
- package/dist/translations/index.js +90 -0
- package/dist/translations/is.d.ts +12 -0
- package/dist/translations/is.js +12 -0
- package/dist/translations/it.d.ts +12 -0
- package/dist/translations/it.js +12 -0
- package/dist/translations/ja.d.ts +12 -0
- package/dist/translations/ja.js +12 -0
- package/dist/translations/ko.d.ts +12 -0
- package/dist/translations/ko.js +12 -0
- package/dist/translations/lt.d.ts +12 -0
- package/dist/translations/lt.js +12 -0
- package/dist/translations/lv.d.ts +12 -0
- package/dist/translations/lv.js +12 -0
- package/dist/translations/my.d.ts +12 -0
- package/dist/translations/my.js +12 -0
- package/dist/translations/nb.d.ts +12 -0
- package/dist/translations/nb.js +12 -0
- package/dist/translations/nl.d.ts +12 -0
- package/dist/translations/nl.js +12 -0
- package/dist/translations/pl.d.ts +12 -0
- package/dist/translations/pl.js +12 -0
- package/dist/translations/pt.d.ts +12 -0
- package/dist/translations/pt.js +12 -0
- package/dist/translations/ro.d.ts +12 -0
- package/dist/translations/ro.js +12 -0
- package/dist/translations/rs.d.ts +12 -0
- package/dist/translations/rs.js +12 -0
- package/dist/translations/rsLatin.d.ts +12 -0
- package/dist/translations/rsLatin.js +12 -0
- package/dist/translations/ru.d.ts +12 -0
- package/dist/translations/ru.js +12 -0
- package/dist/translations/sk.d.ts +12 -0
- package/dist/translations/sk.js +12 -0
- package/dist/translations/sl.d.ts +12 -0
- package/dist/translations/sl.js +12 -0
- package/dist/translations/sv.d.ts +12 -0
- package/dist/translations/sv.js +12 -0
- package/dist/translations/ta.d.ts +12 -0
- package/dist/translations/ta.js +12 -0
- package/dist/translations/th.d.ts +12 -0
- package/dist/translations/th.js +12 -0
- package/dist/translations/tr.d.ts +12 -0
- package/dist/translations/tr.js +12 -0
- package/dist/translations/uk.d.ts +12 -0
- package/dist/translations/uk.js +12 -0
- package/dist/translations/vi.d.ts +12 -0
- package/dist/translations/vi.js +12 -0
- package/dist/translations/zh.d.ts +12 -0
- package/dist/translations/zh.js +12 -0
- package/dist/translations/zhTw.d.ts +12 -0
- package/dist/translations/zhTw.js +12 -0
- package/dist/types.d.ts +11 -0
- package/dist/utils/assert-never.d.ts +1 -0
- package/dist/utils/assert-never.js +3 -0
- package/dist/utils/build-detection.d.ts +6 -1
- package/dist/utils/build-detection.js +68 -89
- package/dist/utils/deploy-adapter.d.ts +3 -35
- package/dist/utils/deploy-adapter.js +25 -14
- package/dist/utils/lambda-config.js +18 -23
- package/dist/utils/load-payload-config.d.ts +2 -2
- package/dist/utils/messages.js +24 -3
- package/dist/utils/next-image-loader-config.d.ts +2 -0
- package/dist/utils/next-image-loader-config.js +63 -0
- package/dist/utils/next-image-loader-file.d.ts +2 -0
- package/dist/utils/next-image-loader-file.js +11 -0
- package/dist/utils/payload-generate.d.ts +10 -0
- package/dist/utils/payload-generate.js +59 -0
- package/dist/utils/pnpm-builds.d.ts +14 -0
- package/dist/utils/pnpm-builds.js +125 -0
- package/dist/utils/s3-upload.js +4 -1
- package/package.json +31 -7
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +0 -10
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +0 -71
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts +0 -41
- package/dist/db-content-api/utilities/meta/buildMeta.js +0 -39
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +0 -16
- package/dist/db-content-api/utilities/meta/buildPathTypes.js +0 -243
- package/dist/db-content-api/utilities/meta/buildUniquePaths.d.ts +0 -12
- package/dist/db-content-api/utilities/meta/buildUniquePaths.js +0 -60
- package/dist/lib/download-skill.d.ts +0 -12
- package/dist/lib/download-skill.js +0 -77
- package/dist/utils/adapters/nextjs.d.ts +0 -8
- package/dist/utils/adapters/nextjs.js +0 -61
- package/dist/utils/adapters/nitro.d.ts +0 -8
- package/dist/utils/adapters/nitro.js +0 -172
- package/dist/utils/adapters/vite.js +0 -31
- package/dist/utils/asset-collection.js +0 -144
- package/dist/utils/build-lambda-zip.js +0 -90
- package/dist/utils/fs-utils.d.ts +0 -12
- package/dist/utils/fs-utils.js +0 -55
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import createClient from 'openapi-fetch';
|
|
2
|
-
import { APIError, createDatabaseAdapter } from 'payload';
|
|
2
|
+
import { APIError, createDatabaseAdapter, ValidationError } from 'payload';
|
|
3
3
|
import { v4 as uuid } from 'uuid';
|
|
4
4
|
import { FigmaApiError } from '../api/figma-api.js';
|
|
5
5
|
import { CONTENT_SYSTEM_NOT_FOUND_MESSAGE } from '../constants.js';
|
|
6
|
+
import { redirectInitialAutosaveCreate } from '../plugin/cloud-limits/server/redirectInitialAutosaveCreate.js';
|
|
6
7
|
import { getGlobalSlug } from './temp-utilities/slug.js';
|
|
7
8
|
import { addFallbackSort } from './temp-utilities/sorting.js';
|
|
8
9
|
import { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js';
|
|
9
10
|
import { createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js';
|
|
11
|
+
import { getClientVersionHeaders } from './utilities/clientVersionHeaders.js';
|
|
10
12
|
import { dataToContentAPI, resolveVersionContent } from './utilities/data/index.js';
|
|
13
|
+
import { injectGlobalType } from './utilities/data/injectGlobalType.js';
|
|
11
14
|
import { validateRelationshipIds } from './utilities/data/validateRelationships.js';
|
|
12
15
|
import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
|
|
13
16
|
import { addFallbackLocale } from './utilities/locale/index.js';
|
|
14
|
-
import { buildMeta } from './utilities/meta/buildMeta.js';
|
|
15
17
|
import { normalizeLocaleInWhere } from './utilities/meta/normalizeLocaleInWhere.js';
|
|
18
|
+
import { getDocumentSchema } from './utilities/schema/getDocumentSchema.js';
|
|
16
19
|
import { convertPayloadWhereToContentAPI } from './utilities/where.js';
|
|
17
20
|
/**
|
|
18
21
|
* Heads-up logged locally whenever a job is queued. Queued jobs are executed by Figma's deployed runner, so
|
|
@@ -108,7 +111,7 @@ async function createCollection(collectionId) {
|
|
|
108
111
|
}
|
|
109
112
|
});
|
|
110
113
|
if (error) {
|
|
111
|
-
throw
|
|
114
|
+
throw createDocumentContentAPIError(this, 'createCollection', error, httpResponse.status, collectionId);
|
|
112
115
|
}
|
|
113
116
|
this.payload.logger.info(`Created collection: ${collectionId}`);
|
|
114
117
|
} catch (error) {
|
|
@@ -120,26 +123,23 @@ async function createCollection(collectionId) {
|
|
|
120
123
|
}
|
|
121
124
|
async function findMany({ collection, joins, limit, locale: localeArg, page, pagination: _pagination, sort, where }) {
|
|
122
125
|
const locale = addFallbackLocale(localeArg, this.payload);
|
|
123
|
-
const
|
|
124
|
-
const
|
|
126
|
+
const localeNormalizedWhere = normalizeLocaleInWhere(where, this.payload, collection, locale);
|
|
127
|
+
const joinClause = convertPayloadJoinsToContentAPI(this.payload, collection, joins);
|
|
128
|
+
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:find', {
|
|
125
129
|
body: {
|
|
126
130
|
collection,
|
|
127
131
|
contentSystemId: this.contentSystemId,
|
|
128
|
-
join:
|
|
132
|
+
join: joinClause,
|
|
129
133
|
limit,
|
|
130
134
|
locale,
|
|
131
135
|
page: page ?? 1,
|
|
136
|
+
schema: this.documentSchema(),
|
|
132
137
|
sort: addFallbackSort(sort, this.payload, collection),
|
|
133
|
-
where: convertPayloadWhereToContentAPI(
|
|
134
|
-
...buildMeta(this.payload, {
|
|
135
|
-
collection,
|
|
136
|
-
locale,
|
|
137
|
-
where: normalizedWhere
|
|
138
|
-
})
|
|
138
|
+
where: convertPayloadWhereToContentAPI(localeNormalizedWhere, this.payload, collection, false)
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
141
|
if (error) {
|
|
142
|
-
throw
|
|
142
|
+
throw createDocumentContentAPIError(this, 'findMany', error, httpResponse.status, collection);
|
|
143
143
|
}
|
|
144
144
|
if (!response) {
|
|
145
145
|
throw new Error('No response from findMany');
|
|
@@ -167,12 +167,9 @@ async function find(args) {
|
|
|
167
167
|
// TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183
|
|
168
168
|
async function findVersions(args) {
|
|
169
169
|
const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
|
|
170
|
-
const whereClause = convertPayloadWhereToContentAPI(args.where
|
|
171
|
-
parentToDocumentId: true,
|
|
172
|
-
stripVersionPrefix: true
|
|
173
|
-
});
|
|
170
|
+
const whereClause = convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, true);
|
|
174
171
|
const locale = addFallbackLocale(args.locale, this.payload);
|
|
175
|
-
const { data: response, error, response: httpResponse } = await this.client.POST('/api/
|
|
172
|
+
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:find', {
|
|
176
173
|
body: {
|
|
177
174
|
collection: args.collection,
|
|
178
175
|
contentSystemId: this.contentSystemId,
|
|
@@ -181,17 +178,13 @@ async function findVersions(args) {
|
|
|
181
178
|
limit: args.limit,
|
|
182
179
|
locale,
|
|
183
180
|
page: args.page ?? 1,
|
|
181
|
+
schema: this.documentSchema(),
|
|
184
182
|
sort: sortWithFallback,
|
|
185
|
-
where: whereClause
|
|
186
|
-
...buildMeta(this.payload, {
|
|
187
|
-
collection: args.collection,
|
|
188
|
-
locale,
|
|
189
|
-
where: args.where
|
|
190
|
-
})
|
|
183
|
+
where: whereClause
|
|
191
184
|
}
|
|
192
185
|
});
|
|
193
186
|
if (error) {
|
|
194
|
-
throw
|
|
187
|
+
throw createDocumentContentAPIError(this, 'findVersions', error, httpResponse.status, args.collection);
|
|
195
188
|
}
|
|
196
189
|
if (!response) {
|
|
197
190
|
throw new Error('No response from findVersions');
|
|
@@ -229,13 +222,17 @@ async function createVersion(args) {
|
|
|
229
222
|
applyDefaults: true,
|
|
230
223
|
publishedLocale: args.publishedLocale
|
|
231
224
|
});
|
|
225
|
+
// id/globalType aren't v1 schema fields (id rides as versionDoc.parent)
|
|
226
|
+
delete versionContent.id;
|
|
227
|
+
delete versionContent.globalType;
|
|
232
228
|
if (args.autosave) {
|
|
233
229
|
versionContent._payloadAutosave = true;
|
|
234
230
|
}
|
|
235
|
-
const { data: response, error, response: httpResponse } = await this.client.POST('/api/
|
|
231
|
+
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:create', {
|
|
236
232
|
body: {
|
|
237
233
|
collection: args.collectionSlug,
|
|
238
234
|
contentSystemId: this.contentSystemId,
|
|
235
|
+
schema: this.documentSchema(),
|
|
239
236
|
versionDoc: {
|
|
240
237
|
createdAt: args.createdAt,
|
|
241
238
|
latest: true,
|
|
@@ -246,7 +243,7 @@ async function createVersion(args) {
|
|
|
246
243
|
}
|
|
247
244
|
});
|
|
248
245
|
if (error) {
|
|
249
|
-
throw
|
|
246
|
+
throw createDocumentContentAPIError(this, 'createVersion', error, httpResponse.status, args.collectionSlug);
|
|
250
247
|
}
|
|
251
248
|
if (!response) {
|
|
252
249
|
throw new Error('No response from createVersion');
|
|
@@ -269,12 +266,15 @@ async function updateVersion(args) {
|
|
|
269
266
|
const versionContent = dataToContentAPI(this.payload, args.collection, resolvedVersion, {
|
|
270
267
|
publishedLocale
|
|
271
268
|
});
|
|
272
|
-
|
|
269
|
+
delete versionContent.id;
|
|
270
|
+
delete versionContent.globalType;
|
|
271
|
+
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:update', {
|
|
273
272
|
body: {
|
|
274
273
|
collection: args.collection,
|
|
275
274
|
contentSystemId: this.contentSystemId,
|
|
276
275
|
createOnMissing: false,
|
|
277
276
|
locale,
|
|
277
|
+
schema: this.documentSchema(),
|
|
278
278
|
versionDoc: {
|
|
279
279
|
createdAt: versionMeta.createdAt,
|
|
280
280
|
latest: versionMeta.latest,
|
|
@@ -282,18 +282,11 @@ async function updateVersion(args) {
|
|
|
282
282
|
updatedAt: versionMeta.updatedAt,
|
|
283
283
|
version: versionContent
|
|
284
284
|
},
|
|
285
|
-
where: convertPayloadWhereToContentAPI(where,
|
|
286
|
-
stripVersionPrefix: true
|
|
287
|
-
}),
|
|
288
|
-
...buildMeta(this.payload, {
|
|
289
|
-
collection: args.collection,
|
|
290
|
-
locale,
|
|
291
|
-
where
|
|
292
|
-
})
|
|
285
|
+
where: convertPayloadWhereToContentAPI(where, this.payload, args.collection, true)
|
|
293
286
|
}
|
|
294
287
|
});
|
|
295
288
|
if (error) {
|
|
296
|
-
throw
|
|
289
|
+
throw createDocumentContentAPIError(this, 'updateVersion', error, httpResponse.status, args.collection);
|
|
297
290
|
}
|
|
298
291
|
if (!response?.result || !('data' in response.result)) {
|
|
299
292
|
throw new Error('No document data in updateVersion response');
|
|
@@ -310,27 +303,25 @@ async function updateVersion(args) {
|
|
|
310
303
|
});
|
|
311
304
|
}
|
|
312
305
|
async function deleteVersions(args) {
|
|
313
|
-
|
|
314
|
-
|
|
306
|
+
// Globals are addressed by `globalSlug` and map to the `_global-<slug>` collection.
|
|
307
|
+
// Only one of `collection`/`globalSlug` is set.
|
|
308
|
+
const globalSlug = args.globalSlug != null ? getGlobalSlug(args.globalSlug) : undefined;
|
|
309
|
+
const collection = args.collection ?? globalSlug;
|
|
310
|
+
if (collection == null) {
|
|
311
|
+
throw new Error('deleteVersions requires a collection or globalSlug');
|
|
315
312
|
}
|
|
316
313
|
const locale = addFallbackLocale(args.locale, this.payload);
|
|
317
|
-
const { error, response: httpResponse } = await this.client.POST('/api/
|
|
314
|
+
const { error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:delete', {
|
|
318
315
|
body: {
|
|
319
|
-
collection
|
|
316
|
+
collection,
|
|
320
317
|
contentSystemId: this.contentSystemId,
|
|
321
318
|
locale,
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}),
|
|
325
|
-
...buildMeta(this.payload, {
|
|
326
|
-
collection: args.collection,
|
|
327
|
-
locale,
|
|
328
|
-
where: args.where
|
|
329
|
-
})
|
|
319
|
+
schema: this.documentSchema(),
|
|
320
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, collection, true)
|
|
330
321
|
}
|
|
331
322
|
});
|
|
332
323
|
if (error) {
|
|
333
|
-
throw
|
|
324
|
+
throw createDocumentContentAPIError(this, 'deleteVersions', error, httpResponse.status, collection);
|
|
334
325
|
}
|
|
335
326
|
}
|
|
336
327
|
async function findOne(args) {
|
|
@@ -346,7 +337,7 @@ async function findOne(args) {
|
|
|
346
337
|
}
|
|
347
338
|
async function findDistinct(args) {
|
|
348
339
|
const locale = addFallbackLocale(args.locale, this.payload);
|
|
349
|
-
const { data: response, error, response: httpResponse } = await this.client.POST('/api/
|
|
340
|
+
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:findDistinct', {
|
|
350
341
|
body: {
|
|
351
342
|
collection: args.collection,
|
|
352
343
|
contentSystemId: this.contentSystemId,
|
|
@@ -354,17 +345,13 @@ async function findDistinct(args) {
|
|
|
354
345
|
limit: args.limit,
|
|
355
346
|
locale,
|
|
356
347
|
page: args.page ?? 1,
|
|
348
|
+
schema: this.documentSchema(),
|
|
357
349
|
sort: addFallbackSort(args.sort, this.payload, args.collection),
|
|
358
|
-
where: convertPayloadWhereToContentAPI(args.where
|
|
359
|
-
...buildMeta(this.payload, {
|
|
360
|
-
collection: args.collection,
|
|
361
|
-
locale,
|
|
362
|
-
where: args.where
|
|
363
|
-
})
|
|
350
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
364
351
|
}
|
|
365
352
|
});
|
|
366
353
|
if (error) {
|
|
367
|
-
throw
|
|
354
|
+
throw createDocumentContentAPIError(this, 'findDistinct', error, httpResponse.status, args.collection);
|
|
368
355
|
}
|
|
369
356
|
const { data, ...pagination } = response.result;
|
|
370
357
|
return {
|
|
@@ -382,7 +369,7 @@ async function updateMany(args) {
|
|
|
382
369
|
data: args.data,
|
|
383
370
|
payload: this.payload
|
|
384
371
|
});
|
|
385
|
-
const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/
|
|
372
|
+
const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
|
|
386
373
|
body: {
|
|
387
374
|
collection: args.collection,
|
|
388
375
|
contentSystemId: this.contentSystemId,
|
|
@@ -391,18 +378,13 @@ async function updateMany(args) {
|
|
|
391
378
|
environmentName: this.environmentName,
|
|
392
379
|
limit: args.limit,
|
|
393
380
|
locale,
|
|
394
|
-
|
|
381
|
+
schema: this.documentSchema(),
|
|
395
382
|
sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),
|
|
396
|
-
where: convertPayloadWhereToContentAPI(args.where)
|
|
397
|
-
...buildMeta(this.payload, {
|
|
398
|
-
collection: args.collection,
|
|
399
|
-
locale,
|
|
400
|
-
where: args.where
|
|
401
|
-
})
|
|
383
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
402
384
|
}
|
|
403
385
|
});
|
|
404
386
|
if (error) {
|
|
405
|
-
throw
|
|
387
|
+
throw createDocumentContentAPIError(this, 'updateMany', error, httpResponse.status, args.collection);
|
|
406
388
|
}
|
|
407
389
|
if (!contentAPIResponse) {
|
|
408
390
|
throw new Error('No response from updateMany');
|
|
@@ -429,7 +411,7 @@ async function updateOne(args) {
|
|
|
429
411
|
data: args.data,
|
|
430
412
|
payload: this.payload
|
|
431
413
|
});
|
|
432
|
-
const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/
|
|
414
|
+
const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
|
|
433
415
|
body: {
|
|
434
416
|
collection: args.collection,
|
|
435
417
|
contentSystemId: this.contentSystemId,
|
|
@@ -437,17 +419,12 @@ async function updateOne(args) {
|
|
|
437
419
|
doc: dataToContentAPI(this.payload, args.collection, args.data),
|
|
438
420
|
environmentName: this.environmentName,
|
|
439
421
|
locale,
|
|
440
|
-
|
|
441
|
-
where: convertPayloadWhereToContentAPI(where)
|
|
442
|
-
...buildMeta(this.payload, {
|
|
443
|
-
collection: args.collection,
|
|
444
|
-
locale,
|
|
445
|
-
where
|
|
446
|
-
})
|
|
422
|
+
schema: this.documentSchema(),
|
|
423
|
+
where: convertPayloadWhereToContentAPI(where, this.payload, args.collection, false)
|
|
447
424
|
}
|
|
448
425
|
});
|
|
449
426
|
if (error) {
|
|
450
|
-
throw
|
|
427
|
+
throw createDocumentContentAPIError(this, 'updateOne', error, httpResponse.status, args.collection);
|
|
451
428
|
}
|
|
452
429
|
if (!contentAPIResponse) {
|
|
453
430
|
throw new Error('No response from updateOne');
|
|
@@ -468,43 +445,34 @@ async function updateOne(args) {
|
|
|
468
445
|
}
|
|
469
446
|
async function deleteMany(args) {
|
|
470
447
|
const locale = addFallbackLocale(args.req?.locale, this.payload);
|
|
471
|
-
const { error, response: httpResponse } = await this.client.POST('/api/
|
|
448
|
+
const { error, response: httpResponse } = await this.client.POST('/api/v1/documents:delete', {
|
|
472
449
|
body: {
|
|
473
450
|
collection: args.collection,
|
|
474
451
|
contentSystemId: this.contentSystemId,
|
|
475
452
|
environmentName: this.environmentName,
|
|
476
453
|
locale,
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
collection: args.collection,
|
|
480
|
-
locale,
|
|
481
|
-
where: args.where
|
|
482
|
-
})
|
|
454
|
+
schema: this.documentSchema(),
|
|
455
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
483
456
|
}
|
|
484
457
|
});
|
|
485
458
|
if (error) {
|
|
486
|
-
throw
|
|
459
|
+
throw createDocumentContentAPIError(this, 'deleteMany', error, httpResponse.status, args.collection);
|
|
487
460
|
}
|
|
488
461
|
}
|
|
489
462
|
async function deleteOne(args) {
|
|
490
463
|
const locale = addFallbackLocale(args.req?.locale, this.payload);
|
|
491
|
-
const { data: response, error, response: httpResponse } = await this.client.POST('/api/
|
|
464
|
+
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:delete', {
|
|
492
465
|
body: {
|
|
493
466
|
collection: args.collection,
|
|
494
467
|
contentSystemId: this.contentSystemId,
|
|
495
468
|
environmentName: this.environmentName,
|
|
496
469
|
locale,
|
|
497
|
-
|
|
498
|
-
where: convertPayloadWhereToContentAPI(args.where)
|
|
499
|
-
...buildMeta(this.payload, {
|
|
500
|
-
collection: args.collection,
|
|
501
|
-
locale,
|
|
502
|
-
where: args.where
|
|
503
|
-
})
|
|
470
|
+
schema: this.documentSchema(),
|
|
471
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
504
472
|
}
|
|
505
473
|
});
|
|
506
474
|
if (error) {
|
|
507
|
-
throw
|
|
475
|
+
throw createDocumentContentAPIError(this, 'deleteOne', error, httpResponse.status, args.collection);
|
|
508
476
|
}
|
|
509
477
|
if (!response?.result || !('data' in response.result)) {
|
|
510
478
|
throw new Error('No document data in deleteOne response');
|
|
@@ -541,7 +509,7 @@ async function create(args) {
|
|
|
541
509
|
data: args.data,
|
|
542
510
|
payload: this.payload
|
|
543
511
|
});
|
|
544
|
-
const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/
|
|
512
|
+
const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:create', {
|
|
545
513
|
body: {
|
|
546
514
|
collection: args.collection,
|
|
547
515
|
contentSystemId: this.contentSystemId,
|
|
@@ -554,15 +522,17 @@ async function create(args) {
|
|
|
554
522
|
},
|
|
555
523
|
environmentName: this.environmentName,
|
|
556
524
|
locale,
|
|
557
|
-
|
|
558
|
-
collection: args.collection,
|
|
559
|
-
data: args.data,
|
|
560
|
-
locale
|
|
561
|
-
})
|
|
525
|
+
schema: this.documentSchema()
|
|
562
526
|
}
|
|
563
527
|
});
|
|
564
528
|
if (error) {
|
|
565
|
-
|
|
529
|
+
redirectInitialAutosaveCreate({
|
|
530
|
+
collectionSlug: args.collection,
|
|
531
|
+
errorCode: error.code,
|
|
532
|
+
payload: this.payload,
|
|
533
|
+
req: args.req
|
|
534
|
+
});
|
|
535
|
+
throw createDocumentContentAPIError(this, 'create', error, httpResponse.status, args.collection);
|
|
566
536
|
}
|
|
567
537
|
if (!contentAPIResponse) {
|
|
568
538
|
throw new Error('No response from create');
|
|
@@ -580,7 +550,8 @@ async function clearDatabase() {
|
|
|
580
550
|
try {
|
|
581
551
|
const response = await fetch(getClearDatabaseUrl(this.url, process.env.FIGMA_CONTENT_API_CUTOVER_STATE), {
|
|
582
552
|
headers: {
|
|
583
|
-
'Content-Type': 'application/json'
|
|
553
|
+
'Content-Type': 'application/json',
|
|
554
|
+
...this.clientVersionHeaders
|
|
584
555
|
},
|
|
585
556
|
method: 'POST'
|
|
586
557
|
});
|
|
@@ -604,21 +575,17 @@ export function getClearDatabaseUrl(url, cutoverState) {
|
|
|
604
575
|
}
|
|
605
576
|
async function count(args) {
|
|
606
577
|
const locale = addFallbackLocale(args.locale, this.payload);
|
|
607
|
-
const { data: response, error, response: httpResponse } = await this.client.POST('/api/
|
|
578
|
+
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:count', {
|
|
608
579
|
body: {
|
|
609
580
|
collection: args.collection,
|
|
610
581
|
contentSystemId: this.contentSystemId,
|
|
611
582
|
locale,
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
collection: args.collection,
|
|
615
|
-
locale,
|
|
616
|
-
where: args.where
|
|
617
|
-
})
|
|
583
|
+
schema: this.documentSchema(),
|
|
584
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
618
585
|
}
|
|
619
586
|
});
|
|
620
587
|
if (error) {
|
|
621
|
-
throw
|
|
588
|
+
throw createDocumentContentAPIError(this, 'count', error, httpResponse.status, args.collection);
|
|
622
589
|
}
|
|
623
590
|
if (!response) {
|
|
624
591
|
throw new Error('No response from count');
|
|
@@ -629,24 +596,17 @@ async function count(args) {
|
|
|
629
596
|
}
|
|
630
597
|
async function countVersions(args) {
|
|
631
598
|
const locale = addFallbackLocale(args.locale, this.payload);
|
|
632
|
-
const { data: response, error, response: httpResponse } = await this.client.POST('/api/
|
|
599
|
+
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:count', {
|
|
633
600
|
body: {
|
|
634
601
|
collection: args.collection,
|
|
635
602
|
contentSystemId: this.contentSystemId,
|
|
636
603
|
locale,
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
stripVersionPrefix: true
|
|
640
|
-
}),
|
|
641
|
-
...buildMeta(this.payload, {
|
|
642
|
-
collection: args.collection,
|
|
643
|
-
locale,
|
|
644
|
-
where: args.where
|
|
645
|
-
})
|
|
604
|
+
schema: this.documentSchema(),
|
|
605
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, true)
|
|
646
606
|
}
|
|
647
607
|
});
|
|
648
608
|
if (error) {
|
|
649
|
-
throw
|
|
609
|
+
throw createDocumentContentAPIError(this, 'countVersions', error, httpResponse.status, args.collection);
|
|
650
610
|
}
|
|
651
611
|
if (!response) {
|
|
652
612
|
throw new Error('No response from countVersions');
|
|
@@ -655,12 +615,19 @@ async function countVersions(args) {
|
|
|
655
615
|
totalDocs: response.result.count
|
|
656
616
|
};
|
|
657
617
|
}
|
|
618
|
+
// Content API document ids are text. A document id is only ever a string or a number
|
|
619
|
+
// (a custom numeric id), so coerce those to a string and treat anything else as absent.
|
|
620
|
+
function toIdString(value) {
|
|
621
|
+
return typeof value === 'string' || typeof value === 'number' ? String(value) : undefined;
|
|
622
|
+
}
|
|
658
623
|
async function upsert(args) {
|
|
659
|
-
|
|
624
|
+
// The Content API stores every document id as text; a custom numeric id arrives as a
|
|
625
|
+
// number, so coerce it (matching `create`) before it becomes `createOnMissing.id`.
|
|
626
|
+
let documentId = toIdString(args.data.id);
|
|
660
627
|
if (!documentId && args.where && 'id' in args.where) {
|
|
661
628
|
const idClause = args.where.id;
|
|
662
|
-
if (idClause
|
|
663
|
-
documentId = idClause.equals;
|
|
629
|
+
if (idClause) {
|
|
630
|
+
documentId = toIdString(idClause.equals);
|
|
664
631
|
}
|
|
665
632
|
}
|
|
666
633
|
if (!documentId) {
|
|
@@ -672,30 +639,31 @@ async function upsert(args) {
|
|
|
672
639
|
data: args.data,
|
|
673
640
|
payload: this.payload
|
|
674
641
|
});
|
|
675
|
-
|
|
642
|
+
// `createdAt` is create-time metadata, so seed it on `createOnMissing` (used only when no
|
|
643
|
+
// document matches) rather than on `doc`. The server preserves an existing document's
|
|
644
|
+
// `createdAt` on update precisely because `doc` omits it; `updatedAt` is still refreshed on
|
|
645
|
+
// every write via `dataToContentAPI`. Sending `createdAt` on `doc` would overwrite it on
|
|
646
|
+
// every update (e.g. repeated `updateGlobal` calls).
|
|
647
|
+
const createdAt = new Date().toISOString();
|
|
648
|
+
const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
|
|
676
649
|
body: {
|
|
677
650
|
collection: args.collection,
|
|
678
651
|
contentSystemId: this.contentSystemId,
|
|
679
652
|
createOnMissing: {
|
|
680
|
-
id: documentId
|
|
653
|
+
id: documentId,
|
|
654
|
+
createdAt
|
|
681
655
|
},
|
|
682
656
|
doc: dataToContentAPI(this.payload, args.collection, args.data, {
|
|
683
|
-
applyDefaults: true
|
|
684
|
-
createdAt: true
|
|
657
|
+
applyDefaults: true
|
|
685
658
|
}),
|
|
686
659
|
environmentName: this.environmentName,
|
|
687
660
|
locale,
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
collection: args.collection,
|
|
691
|
-
data: args.data,
|
|
692
|
-
locale,
|
|
693
|
-
where: args.where
|
|
694
|
-
})
|
|
661
|
+
schema: this.documentSchema(),
|
|
662
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
695
663
|
}
|
|
696
664
|
});
|
|
697
665
|
if (error) {
|
|
698
|
-
throw
|
|
666
|
+
throw createDocumentContentAPIError(this, 'upsert', error, httpResponse.status, args.collection);
|
|
699
667
|
}
|
|
700
668
|
if (!contentAPIResponse) {
|
|
701
669
|
throw new Error('No response from upsert');
|
|
@@ -715,6 +683,7 @@ async function upsert(args) {
|
|
|
715
683
|
});
|
|
716
684
|
}
|
|
717
685
|
async function updateJobs(args) {
|
|
686
|
+
const collection = 'payload-jobs';
|
|
718
687
|
const { id, limit, returning, sort, where } = args;
|
|
719
688
|
if (id == null && where == null) {
|
|
720
689
|
throw new Error('updateJobs requires either id or a where clause');
|
|
@@ -735,17 +704,12 @@ async function updateJobs(args) {
|
|
|
735
704
|
equals: String(id)
|
|
736
705
|
}
|
|
737
706
|
} : where;
|
|
738
|
-
const docData = dataToContentAPI(this.payload,
|
|
739
|
-
const sortClause = addFallbackSort(sort || '-updatedAt', this.payload,
|
|
740
|
-
const whereQuery = convertPayloadWhereToContentAPI(whereClause);
|
|
741
|
-
const
|
|
742
|
-
collection: 'payload-jobs',
|
|
743
|
-
locale: undefined,
|
|
744
|
-
where: whereClause
|
|
745
|
-
});
|
|
746
|
-
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:update', {
|
|
707
|
+
const docData = dataToContentAPI(this.payload, collection, data);
|
|
708
|
+
const sortClause = addFallbackSort(sort || '-updatedAt', this.payload, collection);
|
|
709
|
+
const whereQuery = convertPayloadWhereToContentAPI(whereClause, this.payload, collection, false);
|
|
710
|
+
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
|
|
747
711
|
body: {
|
|
748
|
-
collection
|
|
712
|
+
collection,
|
|
749
713
|
contentSystemId: this.contentSystemId,
|
|
750
714
|
createOnMissing: false,
|
|
751
715
|
doc: docData,
|
|
@@ -753,14 +717,13 @@ async function updateJobs(args) {
|
|
|
753
717
|
...limit != null && {
|
|
754
718
|
limit
|
|
755
719
|
},
|
|
756
|
-
|
|
720
|
+
schema: this.documentSchema(),
|
|
757
721
|
sort: sortClause,
|
|
758
|
-
where: whereQuery
|
|
759
|
-
...meta
|
|
722
|
+
where: whereQuery
|
|
760
723
|
}
|
|
761
724
|
});
|
|
762
725
|
if (error) {
|
|
763
|
-
throw
|
|
726
|
+
throw createDocumentContentAPIError(this, 'updateJobs', error, httpResponse.status, collection);
|
|
764
727
|
}
|
|
765
728
|
if (!response) {
|
|
766
729
|
throw new Error('No response from updateJobs');
|
|
@@ -772,23 +735,22 @@ async function updateJobs(args) {
|
|
|
772
735
|
return [];
|
|
773
736
|
}
|
|
774
737
|
return response.result.data.map((doc)=>unwrapDocument({
|
|
775
|
-
collectionSlug:
|
|
738
|
+
collectionSlug: collection,
|
|
776
739
|
doc,
|
|
777
740
|
payload: this.payload
|
|
778
741
|
}));
|
|
779
742
|
}
|
|
780
|
-
function createGlobal(args) {
|
|
743
|
+
async function createGlobal(args) {
|
|
781
744
|
// Globals are singletons identified by their slug. Use upsert so concurrent calls
|
|
782
745
|
// (e.g. handleSchedules processing multiple queueables with the same null jobStats)
|
|
783
746
|
// don't fail with "A record with this field already exists". The deep-merge semantics
|
|
784
747
|
// of the update path are safe here: callers that want a fresh create (first run) get
|
|
785
748
|
// an effective create, and callers that race a prior create get a merge instead.
|
|
786
|
-
|
|
749
|
+
const doc = await this.upsert({
|
|
787
750
|
collection: getGlobalSlug(args.slug),
|
|
788
751
|
data: {
|
|
789
752
|
...args.data,
|
|
790
|
-
id: args.slug
|
|
791
|
-
globalType: args.slug
|
|
753
|
+
id: args.slug
|
|
792
754
|
},
|
|
793
755
|
where: {
|
|
794
756
|
id: {
|
|
@@ -796,19 +758,18 @@ function createGlobal(args) {
|
|
|
796
758
|
}
|
|
797
759
|
}
|
|
798
760
|
});
|
|
761
|
+
return injectGlobalType(doc, args.slug);
|
|
799
762
|
}
|
|
800
|
-
function findGlobal(args) {
|
|
801
|
-
|
|
763
|
+
async function findGlobal(args) {
|
|
764
|
+
const doc = await this.findOne({
|
|
802
765
|
collection: getGlobalSlug(args.slug),
|
|
803
766
|
locale: args.locale,
|
|
804
767
|
where: args.where ?? {}
|
|
805
768
|
});
|
|
769
|
+
return injectGlobalType(doc, args.slug);
|
|
806
770
|
}
|
|
807
771
|
async function updateGlobal(args) {
|
|
808
|
-
|
|
809
|
-
// which overwrites the original timestamp on updates. The fix belongs in the Content API:
|
|
810
|
-
// `createOnMissing` should preserve `createdAt` on updates and only set it on creates.
|
|
811
|
-
return this.upsert({
|
|
772
|
+
const doc = await this.upsert({
|
|
812
773
|
collection: getGlobalSlug(args.slug),
|
|
813
774
|
data: args.data,
|
|
814
775
|
where: {
|
|
@@ -817,6 +778,7 @@ async function updateGlobal(args) {
|
|
|
817
778
|
}
|
|
818
779
|
}
|
|
819
780
|
});
|
|
781
|
+
return injectGlobalType(doc, args.slug);
|
|
820
782
|
}
|
|
821
783
|
// TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183
|
|
822
784
|
function findGlobalVersions(args) {
|
|
@@ -868,6 +830,13 @@ function countGlobalVersions(args) {
|
|
|
868
830
|
where: args.where
|
|
869
831
|
});
|
|
870
832
|
}
|
|
833
|
+
function createDocumentContentAPIError(adapter, operation, error, status, collectionSlug) {
|
|
834
|
+
const validationError = maybeCreateUniqueValidationError(error, collectionSlug, adapter);
|
|
835
|
+
if (validationError != null) {
|
|
836
|
+
return validationError;
|
|
837
|
+
}
|
|
838
|
+
return createContentAPIError(operation, error, status);
|
|
839
|
+
}
|
|
871
840
|
function createContentAPIError(operation, error, status) {
|
|
872
841
|
return new APIError(`Content API ${operation} error: ${error.message}`, status, {
|
|
873
842
|
code: error.code,
|
|
@@ -875,12 +844,35 @@ function createContentAPIError(operation, error, status) {
|
|
|
875
844
|
field: error.field
|
|
876
845
|
});
|
|
877
846
|
}
|
|
847
|
+
// A unique-constraint violation from the Content API is Payload's `ValidationError` contract:
|
|
848
|
+
// reconstruct it with the offending field path(s) so callers can map the error back to a field
|
|
849
|
+
// (matching what Payload's other database adapters throw). Falls back to a generic APIError when
|
|
850
|
+
// the collection or offending field is unknown.
|
|
851
|
+
function maybeCreateUniqueValidationError(error, collectionSlug, adapter) {
|
|
852
|
+
if (error.constraint !== 'unique_constraint') {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
const paths = (error.field ?? '').split(',').map((path)=>path.trim()).filter((path)=>path.length > 0);
|
|
856
|
+
if (paths.length === 0) {
|
|
857
|
+
adapter.payload.logger.error(`Unique constraint violation but no offending field.`);
|
|
858
|
+
return null;
|
|
859
|
+
}
|
|
860
|
+
return new ValidationError({
|
|
861
|
+
collection: collectionSlug,
|
|
862
|
+
errors: paths.map((path)=>({
|
|
863
|
+
message: error.message,
|
|
864
|
+
path
|
|
865
|
+
}))
|
|
866
|
+
});
|
|
867
|
+
}
|
|
878
868
|
export const contentAPIAdapter = (opts)=>({
|
|
879
869
|
name: 'content-api',
|
|
880
870
|
defaultIDType: 'text',
|
|
881
871
|
init: ({ payload })=>{
|
|
872
|
+
const clientVersionHeaders = getClientVersionHeaders();
|
|
882
873
|
const client = createClient({
|
|
883
|
-
baseUrl: opts.url
|
|
874
|
+
baseUrl: opts.url,
|
|
875
|
+
headers: clientVersionHeaders
|
|
884
876
|
});
|
|
885
877
|
const middlewareOpts = {
|
|
886
878
|
auth: opts.auth,
|
|
@@ -897,6 +889,7 @@ export const contentAPIAdapter = (opts)=>({
|
|
|
897
889
|
beginTransaction: ()=>Promise.resolve(null),
|
|
898
890
|
clearDatabase: clearDatabase,
|
|
899
891
|
client,
|
|
892
|
+
clientVersionHeaders,
|
|
900
893
|
commitTransaction: async ()=>{},
|
|
901
894
|
connect: connect,
|
|
902
895
|
contentSystemId: opts.contentSystemId,
|
|
@@ -911,6 +904,7 @@ export const contentAPIAdapter = (opts)=>({
|
|
|
911
904
|
deleteMany: deleteMany,
|
|
912
905
|
deleteOne: deleteOne,
|
|
913
906
|
deleteVersions: deleteVersions,
|
|
907
|
+
documentSchema: ()=>getDocumentSchema(payload.config),
|
|
914
908
|
environmentName: opts.environmentName,
|
|
915
909
|
find: find,
|
|
916
910
|
findDistinct: findDistinct,
|