@payloadcms/figma 0.1.0-alpha.1 → 0.1.0-alpha.11
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 +10 -9
- package/dist/api/control-plane.js +27 -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 +20 -1
- package/dist/auth/token-store.js +47 -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 +235 -80
- 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/upgrade.js +65 -1
- 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 +6 -2
- package/dist/db-content-api/index.d.ts +1 -1
- package/dist/db-content-api/index.js +121 -72
- package/dist/db-content-api/utilities/data/index.js +8 -2
- 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/removeVirtualFields.d.ts +3 -11
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
- 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.js +5 -1
- 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.js +9 -4
- 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 +2 -6
- package/dist/db-content-api/utilities/where.js +20 -9
- 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 +13 -3
- package/dist/plugin/build-config.js +181 -36
- 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 +9 -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 +3 -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/api-types.d.ts +3 -0
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.d.ts +1 -0
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.js +8 -0
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +12 -0
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +26 -0
- package/dist/storage-content-api/buildMediaRequestHeaders.d.ts +1 -0
- package/dist/storage-content-api/buildMediaRequestHeaders.js +14 -0
- package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +4 -0
- package/dist/storage-content-api/buildMediaResponseHeaders.js +52 -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 +33 -0
- package/dist/storage-content-api/getMediaType.d.ts +1 -0
- package/dist/storage-content-api/getMediaType.js +3 -0
- package/dist/storage-content-api/hasSupportedContentEncoding.d.ts +1 -0
- package/dist/storage-content-api/hasSupportedContentEncoding.js +6 -0
- package/dist/storage-content-api/index.js +1 -0
- package/dist/storage-content-api/mediaErrorResponse.d.ts +1 -0
- package/dist/storage-content-api/mediaErrorResponse.js +12 -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/shouldAttachMedia.d.ts +1 -0
- package/dist/storage-content-api/shouldAttachMedia.js +34 -0
- package/dist/storage-content-api/staticHandler.js +93 -25
- 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/env-management.d.ts +15 -0
- package/dist/utils/env-management.js +47 -0
- package/dist/utils/lambda-config.js +18 -23
- 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-config-ast.js +5 -2
- package/dist/utils/payload-generate.d.ts +10 -0
- package/dist/utils/payload-generate.js +59 -0
- package/dist/utils/payload-secret.d.ts +28 -0
- package/dist/utils/payload-secret.js +34 -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 +33 -7
- 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
package/dist/commands/upgrade.js
CHANGED
|
@@ -8,12 +8,13 @@ import { getBootstrapInfo, getCmsResourceId } from '../api/control-plane.js';
|
|
|
8
8
|
import { getValidCredential } from '../auth/oauth-flow.js';
|
|
9
9
|
import { getTokenStore } from '../auth/token-store.js';
|
|
10
10
|
import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
|
|
11
|
-
import { addOrUpdateEnvVar, getEnvVar, removeEnvVar } from '../utils/env-management.js';
|
|
11
|
+
import { addOrUpdateEnvVar, commentOutEnvVar, getEnvVar, removeEnvVar } from '../utils/env-management.js';
|
|
12
12
|
import { formatFile } from '../utils/formatter.js';
|
|
13
13
|
import { getPackageManager } from '../utils/package-manager.js';
|
|
14
14
|
import { removeFigmaContentSystemId } from '../utils/payload-config-ast.js';
|
|
15
15
|
import { findPayloadConfig } from '../utils/payload-config-finder.js';
|
|
16
16
|
import { checkPackageInstalled, installPackage } from '../utils/payload-package-check.js';
|
|
17
|
+
import { ensurePayloadSecret } from '../utils/payload-secret.js';
|
|
17
18
|
import { getOwnVersion } from '../utils/version-check.js';
|
|
18
19
|
export async function upgradeCommand(options = {}) {
|
|
19
20
|
const cwd = process.cwd();
|
|
@@ -45,6 +46,11 @@ export async function upgradeCommand(options = {}) {
|
|
|
45
46
|
isDryRun,
|
|
46
47
|
warnings
|
|
47
48
|
});
|
|
49
|
+
await migrateCommentOutPayloadSecret({
|
|
50
|
+
changes,
|
|
51
|
+
cwd,
|
|
52
|
+
isDryRun
|
|
53
|
+
});
|
|
48
54
|
await migrateConfigAst({
|
|
49
55
|
changes,
|
|
50
56
|
cwd,
|
|
@@ -221,6 +227,64 @@ async function migrateRemoveDeprecatedEnvVars({ changes, cwd, isDryRun, warnings
|
|
|
221
227
|
p.log.warning(`Deprecated env var removal failed: ${msg}`);
|
|
222
228
|
}
|
|
223
229
|
}
|
|
230
|
+
async function migrateCommentOutPayloadSecret({ changes, cwd, isDryRun }) {
|
|
231
|
+
try {
|
|
232
|
+
// Only touch active (uncommented) assignments — commentOutEnvVar already
|
|
233
|
+
// no-ops on commented lines, but checking here avoids the dry-run message
|
|
234
|
+
// when there's nothing left to do.
|
|
235
|
+
const existing = await getEnvVar(cwd, 'PAYLOAD_SECRET');
|
|
236
|
+
if (existing === null) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (isDryRun) {
|
|
240
|
+
p.log.message(`${pc.dim('○')} Would comment out PAYLOAD_SECRET in .env after caching the platform secret`);
|
|
241
|
+
changes.push('Comment out PAYLOAD_SECRET in .env');
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const projectId = await getEnvVar(cwd, 'FIGMA_PROJECT_ID');
|
|
245
|
+
const environmentName = await getEnvVar(cwd, 'FIGMA_ENVIRONMENT_NAME');
|
|
246
|
+
if (!projectId || !environmentName) {
|
|
247
|
+
p.log.warning('Keeping PAYLOAD_SECRET in .env: initialize the project before migrating its secret.');
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const store = getTokenStore();
|
|
251
|
+
const credential = await getValidCredential(store);
|
|
252
|
+
if (!credential) {
|
|
253
|
+
p.log.warning('Keeping PAYLOAD_SECRET in .env: run `npx @payloadcms/figma login` and retry upgrade.');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
let bootstrapData = store.getBootstrapData(projectId, environmentName);
|
|
257
|
+
if (!bootstrapData) {
|
|
258
|
+
const bootstrapInfo = await getBootstrapInfo(credential, projectId);
|
|
259
|
+
cacheAllEnvironments(store, projectId, bootstrapInfo);
|
|
260
|
+
bootstrapData = store.getBootstrapData(projectId, environmentName);
|
|
261
|
+
}
|
|
262
|
+
if (!bootstrapData?.tenantInstanceId) {
|
|
263
|
+
p.log.warning('Keeping PAYLOAD_SECRET in .env: the project environment could not be resolved.');
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
await ensurePayloadSecret({
|
|
267
|
+
credential,
|
|
268
|
+
projectInfo: {
|
|
269
|
+
environmentName,
|
|
270
|
+
projectId
|
|
271
|
+
},
|
|
272
|
+
refresh: true,
|
|
273
|
+
tenantInstanceId: bootstrapData.tenantInstanceId,
|
|
274
|
+
tokenStore: store
|
|
275
|
+
});
|
|
276
|
+
const changed = await commentOutEnvVar(cwd, 'PAYLOAD_SECRET', 'disabled by @payloadcms/figma: platform owns PAYLOAD_SECRET');
|
|
277
|
+
if (!changed) {
|
|
278
|
+
p.log.warning('Could not comment out PAYLOAD_SECRET in .env; the platform secret is cached. Retry upgrade.');
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
p.log.message(`${pc.green('●')} Env: Commented out PAYLOAD_SECRET (Figma platform owns this value; ` + `a local copy would silently diverge from the deployed secret)`);
|
|
282
|
+
changes.push('Commented out PAYLOAD_SECRET in .env');
|
|
283
|
+
} catch (error) {
|
|
284
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
285
|
+
p.log.warning(`PAYLOAD_SECRET migration failed; keeping the existing .env value: ${msg}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
224
288
|
async function migrateConfigAst({ changes, cwd, isDryRun }) {
|
|
225
289
|
try {
|
|
226
290
|
const configPath = await findPayloadConfig(cwd);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BootstrapInfo } from '../api/control-plane.js';
|
|
2
|
+
import type { TokenStore } from '../auth/token-store.js';
|
|
3
|
+
interface WriteProjectConfigurationArgs {
|
|
4
|
+
bootstrapInfo: BootstrapInfo | null;
|
|
5
|
+
environmentName: string;
|
|
6
|
+
projectDir: string;
|
|
7
|
+
projectId: string;
|
|
8
|
+
shouldWriteEnvironmentVariables?: boolean;
|
|
9
|
+
tokenStore: TokenStore;
|
|
10
|
+
}
|
|
11
|
+
export declare function writeProjectConfiguration({ bootstrapInfo, environmentName, projectDir, projectId, shouldWriteEnvironmentVariables, tokenStore, }: WriteProjectConfigurationArgs): Promise<void>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getInfraEnvironment } from '../constants.js';
|
|
2
|
+
import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
|
|
3
|
+
import { addOrUpdateEnvVar } from '../utils/env-management.js';
|
|
4
|
+
export async function writeProjectConfiguration({ bootstrapInfo, environmentName, projectDir, projectId, shouldWriteEnvironmentVariables = true, tokenStore }) {
|
|
5
|
+
if (shouldWriteEnvironmentVariables) {
|
|
6
|
+
await addOrUpdateEnvVar(projectDir, 'FIGMA_PROJECT_ID', projectId);
|
|
7
|
+
await addOrUpdateEnvVar(projectDir, 'FIGMA_ENVIRONMENT_NAME', environmentName);
|
|
8
|
+
const infraEnvironment = getInfraEnvironment();
|
|
9
|
+
if (infraEnvironment !== 'production') {
|
|
10
|
+
await addOrUpdateEnvVar(projectDir, 'FIGMA_INFRA_ENV', infraEnvironment);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (bootstrapInfo) {
|
|
14
|
+
cacheAllEnvironments(tokenStore, projectId, bootstrapInfo);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -8062,12 +8062,16 @@ export type components = {
|
|
|
8062
8062
|
/** @example document.pdf */
|
|
8063
8063
|
filename: string;
|
|
8064
8064
|
/**
|
|
8065
|
-
* @default
|
|
8066
|
-
* @example
|
|
8065
|
+
* @default 300
|
|
8066
|
+
* @example 300
|
|
8067
8067
|
*/
|
|
8068
8068
|
expiresIn: number;
|
|
8069
8069
|
/** @example media */
|
|
8070
8070
|
collectionId: string;
|
|
8071
|
+
responseHeaders?: {
|
|
8072
|
+
/** @example public, max-age=3600 */
|
|
8073
|
+
cacheControl: string;
|
|
8074
|
+
};
|
|
8071
8075
|
};
|
|
8072
8076
|
InitiateMultipartUploadResponse: {
|
|
8073
8077
|
/** @example abc123xyz789 */
|
|
@@ -29,7 +29,7 @@ export type ContentAPIAdapter = {
|
|
|
29
29
|
client: ReturnType<typeof createClient<paths>>;
|
|
30
30
|
clientVersionHeaders: Record<string, string>;
|
|
31
31
|
contentSystemId: string;
|
|
32
|
-
documentSchema: DocumentSchemaWire;
|
|
32
|
+
documentSchema: () => DocumentSchemaWire;
|
|
33
33
|
environmentName?: string;
|
|
34
34
|
idType: 'uuid';
|
|
35
35
|
notifyLocalJobQueue: boolean;
|
|
@@ -1,19 +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';
|
|
10
11
|
import { getClientVersionHeaders } from './utilities/clientVersionHeaders.js';
|
|
11
12
|
import { dataToContentAPI, resolveVersionContent } from './utilities/data/index.js';
|
|
13
|
+
import { injectGlobalType } from './utilities/data/injectGlobalType.js';
|
|
12
14
|
import { validateRelationshipIds } from './utilities/data/validateRelationships.js';
|
|
13
15
|
import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
|
|
14
16
|
import { addFallbackLocale } from './utilities/locale/index.js';
|
|
15
17
|
import { normalizeLocaleInWhere } from './utilities/meta/normalizeLocaleInWhere.js';
|
|
16
|
-
import {
|
|
18
|
+
import { getDocumentSchema } from './utilities/schema/getDocumentSchema.js';
|
|
17
19
|
import { convertPayloadWhereToContentAPI } from './utilities/where.js';
|
|
18
20
|
/**
|
|
19
21
|
* Heads-up logged locally whenever a job is queued. Queued jobs are executed by Figma's deployed runner, so
|
|
@@ -109,7 +111,7 @@ async function createCollection(collectionId) {
|
|
|
109
111
|
}
|
|
110
112
|
});
|
|
111
113
|
if (error) {
|
|
112
|
-
throw
|
|
114
|
+
throw createDocumentContentAPIError(this, 'createCollection', error, httpResponse.status, collectionId);
|
|
113
115
|
}
|
|
114
116
|
this.payload.logger.info(`Created collection: ${collectionId}`);
|
|
115
117
|
} catch (error) {
|
|
@@ -121,7 +123,7 @@ async function createCollection(collectionId) {
|
|
|
121
123
|
}
|
|
122
124
|
async function findMany({ collection, joins, limit, locale: localeArg, page, pagination: _pagination, sort, where }) {
|
|
123
125
|
const locale = addFallbackLocale(localeArg, this.payload);
|
|
124
|
-
const
|
|
126
|
+
const localeNormalizedWhere = normalizeLocaleInWhere(where, this.payload, collection, locale);
|
|
125
127
|
const joinClause = convertPayloadJoinsToContentAPI(this.payload, collection, joins);
|
|
126
128
|
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:find', {
|
|
127
129
|
body: {
|
|
@@ -131,13 +133,13 @@ async function findMany({ collection, joins, limit, locale: localeArg, page, pag
|
|
|
131
133
|
limit,
|
|
132
134
|
locale,
|
|
133
135
|
page: page ?? 1,
|
|
134
|
-
schema: this.documentSchema,
|
|
136
|
+
schema: this.documentSchema(),
|
|
135
137
|
sort: addFallbackSort(sort, this.payload, collection),
|
|
136
|
-
where: convertPayloadWhereToContentAPI(
|
|
138
|
+
where: convertPayloadWhereToContentAPI(localeNormalizedWhere, this.payload, collection, false)
|
|
137
139
|
}
|
|
138
140
|
});
|
|
139
141
|
if (error) {
|
|
140
|
-
throw
|
|
142
|
+
throw createDocumentContentAPIError(this, 'findMany', error, httpResponse.status, collection);
|
|
141
143
|
}
|
|
142
144
|
if (!response) {
|
|
143
145
|
throw new Error('No response from findMany');
|
|
@@ -165,7 +167,7 @@ async function find(args) {
|
|
|
165
167
|
// TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183
|
|
166
168
|
async function findVersions(args) {
|
|
167
169
|
const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
|
|
168
|
-
const whereClause = convertPayloadWhereToContentAPI(args.where
|
|
170
|
+
const whereClause = convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, true);
|
|
169
171
|
const locale = addFallbackLocale(args.locale, this.payload);
|
|
170
172
|
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:find', {
|
|
171
173
|
body: {
|
|
@@ -176,13 +178,13 @@ async function findVersions(args) {
|
|
|
176
178
|
limit: args.limit,
|
|
177
179
|
locale,
|
|
178
180
|
page: args.page ?? 1,
|
|
179
|
-
schema: this.documentSchema,
|
|
181
|
+
schema: this.documentSchema(),
|
|
180
182
|
sort: sortWithFallback,
|
|
181
183
|
where: whereClause
|
|
182
184
|
}
|
|
183
185
|
});
|
|
184
186
|
if (error) {
|
|
185
|
-
throw
|
|
187
|
+
throw createDocumentContentAPIError(this, 'findVersions', error, httpResponse.status, args.collection);
|
|
186
188
|
}
|
|
187
189
|
if (!response) {
|
|
188
190
|
throw new Error('No response from findVersions');
|
|
@@ -230,7 +232,7 @@ async function createVersion(args) {
|
|
|
230
232
|
body: {
|
|
231
233
|
collection: args.collectionSlug,
|
|
232
234
|
contentSystemId: this.contentSystemId,
|
|
233
|
-
schema: this.documentSchema,
|
|
235
|
+
schema: this.documentSchema(),
|
|
234
236
|
versionDoc: {
|
|
235
237
|
createdAt: args.createdAt,
|
|
236
238
|
latest: true,
|
|
@@ -241,7 +243,7 @@ async function createVersion(args) {
|
|
|
241
243
|
}
|
|
242
244
|
});
|
|
243
245
|
if (error) {
|
|
244
|
-
throw
|
|
246
|
+
throw createDocumentContentAPIError(this, 'createVersion', error, httpResponse.status, args.collectionSlug);
|
|
245
247
|
}
|
|
246
248
|
if (!response) {
|
|
247
249
|
throw new Error('No response from createVersion');
|
|
@@ -272,7 +274,7 @@ async function updateVersion(args) {
|
|
|
272
274
|
contentSystemId: this.contentSystemId,
|
|
273
275
|
createOnMissing: false,
|
|
274
276
|
locale,
|
|
275
|
-
schema: this.documentSchema,
|
|
277
|
+
schema: this.documentSchema(),
|
|
276
278
|
versionDoc: {
|
|
277
279
|
createdAt: versionMeta.createdAt,
|
|
278
280
|
latest: versionMeta.latest,
|
|
@@ -280,11 +282,11 @@ async function updateVersion(args) {
|
|
|
280
282
|
updatedAt: versionMeta.updatedAt,
|
|
281
283
|
version: versionContent
|
|
282
284
|
},
|
|
283
|
-
where: convertPayloadWhereToContentAPI(where)
|
|
285
|
+
where: convertPayloadWhereToContentAPI(where, this.payload, args.collection, true)
|
|
284
286
|
}
|
|
285
287
|
});
|
|
286
288
|
if (error) {
|
|
287
|
-
throw
|
|
289
|
+
throw createDocumentContentAPIError(this, 'updateVersion', error, httpResponse.status, args.collection);
|
|
288
290
|
}
|
|
289
291
|
if (!response?.result || !('data' in response.result)) {
|
|
290
292
|
throw new Error('No document data in updateVersion response');
|
|
@@ -301,21 +303,25 @@ async function updateVersion(args) {
|
|
|
301
303
|
});
|
|
302
304
|
}
|
|
303
305
|
async function deleteVersions(args) {
|
|
304
|
-
|
|
305
|
-
|
|
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');
|
|
306
312
|
}
|
|
307
313
|
const locale = addFallbackLocale(args.locale, this.payload);
|
|
308
314
|
const { error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:delete', {
|
|
309
315
|
body: {
|
|
310
|
-
collection
|
|
316
|
+
collection,
|
|
311
317
|
contentSystemId: this.contentSystemId,
|
|
312
318
|
locale,
|
|
313
|
-
schema: this.documentSchema,
|
|
314
|
-
where: convertPayloadWhereToContentAPI(args.where)
|
|
319
|
+
schema: this.documentSchema(),
|
|
320
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, collection, true)
|
|
315
321
|
}
|
|
316
322
|
});
|
|
317
323
|
if (error) {
|
|
318
|
-
throw
|
|
324
|
+
throw createDocumentContentAPIError(this, 'deleteVersions', error, httpResponse.status, collection);
|
|
319
325
|
}
|
|
320
326
|
}
|
|
321
327
|
async function findOne(args) {
|
|
@@ -339,13 +345,13 @@ async function findDistinct(args) {
|
|
|
339
345
|
limit: args.limit,
|
|
340
346
|
locale,
|
|
341
347
|
page: args.page ?? 1,
|
|
342
|
-
schema: this.documentSchema,
|
|
348
|
+
schema: this.documentSchema(),
|
|
343
349
|
sort: addFallbackSort(args.sort, this.payload, args.collection),
|
|
344
|
-
where: convertPayloadWhereToContentAPI(args.where
|
|
350
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
345
351
|
}
|
|
346
352
|
});
|
|
347
353
|
if (error) {
|
|
348
|
-
throw
|
|
354
|
+
throw createDocumentContentAPIError(this, 'findDistinct', error, httpResponse.status, args.collection);
|
|
349
355
|
}
|
|
350
356
|
const { data, ...pagination } = response.result;
|
|
351
357
|
return {
|
|
@@ -372,13 +378,13 @@ async function updateMany(args) {
|
|
|
372
378
|
environmentName: this.environmentName,
|
|
373
379
|
limit: args.limit,
|
|
374
380
|
locale,
|
|
375
|
-
schema: this.documentSchema,
|
|
381
|
+
schema: this.documentSchema(),
|
|
376
382
|
sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),
|
|
377
|
-
where: convertPayloadWhereToContentAPI(args.where)
|
|
383
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
378
384
|
}
|
|
379
385
|
});
|
|
380
386
|
if (error) {
|
|
381
|
-
throw
|
|
387
|
+
throw createDocumentContentAPIError(this, 'updateMany', error, httpResponse.status, args.collection);
|
|
382
388
|
}
|
|
383
389
|
if (!contentAPIResponse) {
|
|
384
390
|
throw new Error('No response from updateMany');
|
|
@@ -413,12 +419,12 @@ async function updateOne(args) {
|
|
|
413
419
|
doc: dataToContentAPI(this.payload, args.collection, args.data),
|
|
414
420
|
environmentName: this.environmentName,
|
|
415
421
|
locale,
|
|
416
|
-
schema: this.documentSchema,
|
|
417
|
-
where: convertPayloadWhereToContentAPI(where)
|
|
422
|
+
schema: this.documentSchema(),
|
|
423
|
+
where: convertPayloadWhereToContentAPI(where, this.payload, args.collection, false)
|
|
418
424
|
}
|
|
419
425
|
});
|
|
420
426
|
if (error) {
|
|
421
|
-
throw
|
|
427
|
+
throw createDocumentContentAPIError(this, 'updateOne', error, httpResponse.status, args.collection);
|
|
422
428
|
}
|
|
423
429
|
if (!contentAPIResponse) {
|
|
424
430
|
throw new Error('No response from updateOne');
|
|
@@ -445,12 +451,12 @@ async function deleteMany(args) {
|
|
|
445
451
|
contentSystemId: this.contentSystemId,
|
|
446
452
|
environmentName: this.environmentName,
|
|
447
453
|
locale,
|
|
448
|
-
schema: this.documentSchema,
|
|
449
|
-
where: convertPayloadWhereToContentAPI(args.where)
|
|
454
|
+
schema: this.documentSchema(),
|
|
455
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
450
456
|
}
|
|
451
457
|
});
|
|
452
458
|
if (error) {
|
|
453
|
-
throw
|
|
459
|
+
throw createDocumentContentAPIError(this, 'deleteMany', error, httpResponse.status, args.collection);
|
|
454
460
|
}
|
|
455
461
|
}
|
|
456
462
|
async function deleteOne(args) {
|
|
@@ -461,12 +467,12 @@ async function deleteOne(args) {
|
|
|
461
467
|
contentSystemId: this.contentSystemId,
|
|
462
468
|
environmentName: this.environmentName,
|
|
463
469
|
locale,
|
|
464
|
-
schema: this.documentSchema,
|
|
465
|
-
where: convertPayloadWhereToContentAPI(args.where)
|
|
470
|
+
schema: this.documentSchema(),
|
|
471
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
466
472
|
}
|
|
467
473
|
});
|
|
468
474
|
if (error) {
|
|
469
|
-
throw
|
|
475
|
+
throw createDocumentContentAPIError(this, 'deleteOne', error, httpResponse.status, args.collection);
|
|
470
476
|
}
|
|
471
477
|
if (!response?.result || !('data' in response.result)) {
|
|
472
478
|
throw new Error('No document data in deleteOne response');
|
|
@@ -516,11 +522,17 @@ async function create(args) {
|
|
|
516
522
|
},
|
|
517
523
|
environmentName: this.environmentName,
|
|
518
524
|
locale,
|
|
519
|
-
schema: this.documentSchema
|
|
525
|
+
schema: this.documentSchema()
|
|
520
526
|
}
|
|
521
527
|
});
|
|
522
528
|
if (error) {
|
|
523
|
-
|
|
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);
|
|
524
536
|
}
|
|
525
537
|
if (!contentAPIResponse) {
|
|
526
538
|
throw new Error('No response from create');
|
|
@@ -568,12 +580,12 @@ async function count(args) {
|
|
|
568
580
|
collection: args.collection,
|
|
569
581
|
contentSystemId: this.contentSystemId,
|
|
570
582
|
locale,
|
|
571
|
-
schema: this.documentSchema,
|
|
572
|
-
where: convertPayloadWhereToContentAPI(args.where)
|
|
583
|
+
schema: this.documentSchema(),
|
|
584
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
573
585
|
}
|
|
574
586
|
});
|
|
575
587
|
if (error) {
|
|
576
|
-
throw
|
|
588
|
+
throw createDocumentContentAPIError(this, 'count', error, httpResponse.status, args.collection);
|
|
577
589
|
}
|
|
578
590
|
if (!response) {
|
|
579
591
|
throw new Error('No response from count');
|
|
@@ -589,12 +601,12 @@ async function countVersions(args) {
|
|
|
589
601
|
collection: args.collection,
|
|
590
602
|
contentSystemId: this.contentSystemId,
|
|
591
603
|
locale,
|
|
592
|
-
schema: this.documentSchema,
|
|
593
|
-
where: convertPayloadWhereToContentAPI(args.where)
|
|
604
|
+
schema: this.documentSchema(),
|
|
605
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, true)
|
|
594
606
|
}
|
|
595
607
|
});
|
|
596
608
|
if (error) {
|
|
597
|
-
throw
|
|
609
|
+
throw createDocumentContentAPIError(this, 'countVersions', error, httpResponse.status, args.collection);
|
|
598
610
|
}
|
|
599
611
|
if (!response) {
|
|
600
612
|
throw new Error('No response from countVersions');
|
|
@@ -603,12 +615,19 @@ async function countVersions(args) {
|
|
|
603
615
|
totalDocs: response.result.count
|
|
604
616
|
};
|
|
605
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
|
+
}
|
|
606
623
|
async function upsert(args) {
|
|
607
|
-
|
|
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);
|
|
608
627
|
if (!documentId && args.where && 'id' in args.where) {
|
|
609
628
|
const idClause = args.where.id;
|
|
610
|
-
if (idClause
|
|
611
|
-
documentId = idClause.equals;
|
|
629
|
+
if (idClause) {
|
|
630
|
+
documentId = toIdString(idClause.equals);
|
|
612
631
|
}
|
|
613
632
|
}
|
|
614
633
|
if (!documentId) {
|
|
@@ -620,25 +639,31 @@ async function upsert(args) {
|
|
|
620
639
|
data: args.data,
|
|
621
640
|
payload: this.payload
|
|
622
641
|
});
|
|
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();
|
|
623
648
|
const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
|
|
624
649
|
body: {
|
|
625
650
|
collection: args.collection,
|
|
626
651
|
contentSystemId: this.contentSystemId,
|
|
627
652
|
createOnMissing: {
|
|
628
|
-
id: documentId
|
|
653
|
+
id: documentId,
|
|
654
|
+
createdAt
|
|
629
655
|
},
|
|
630
656
|
doc: dataToContentAPI(this.payload, args.collection, args.data, {
|
|
631
|
-
applyDefaults: true
|
|
632
|
-
createdAt: true
|
|
657
|
+
applyDefaults: true
|
|
633
658
|
}),
|
|
634
659
|
environmentName: this.environmentName,
|
|
635
660
|
locale,
|
|
636
|
-
schema: this.documentSchema,
|
|
637
|
-
where: convertPayloadWhereToContentAPI(args.where)
|
|
661
|
+
schema: this.documentSchema(),
|
|
662
|
+
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
638
663
|
}
|
|
639
664
|
});
|
|
640
665
|
if (error) {
|
|
641
|
-
throw
|
|
666
|
+
throw createDocumentContentAPIError(this, 'upsert', error, httpResponse.status, args.collection);
|
|
642
667
|
}
|
|
643
668
|
if (!contentAPIResponse) {
|
|
644
669
|
throw new Error('No response from upsert');
|
|
@@ -658,6 +683,7 @@ async function upsert(args) {
|
|
|
658
683
|
});
|
|
659
684
|
}
|
|
660
685
|
async function updateJobs(args) {
|
|
686
|
+
const collection = 'payload-jobs';
|
|
661
687
|
const { id, limit, returning, sort, where } = args;
|
|
662
688
|
if (id == null && where == null) {
|
|
663
689
|
throw new Error('updateJobs requires either id or a where clause');
|
|
@@ -678,12 +704,12 @@ async function updateJobs(args) {
|
|
|
678
704
|
equals: String(id)
|
|
679
705
|
}
|
|
680
706
|
} : where;
|
|
681
|
-
const docData = dataToContentAPI(this.payload,
|
|
682
|
-
const sortClause = addFallbackSort(sort || '-updatedAt', this.payload,
|
|
683
|
-
const whereQuery = convertPayloadWhereToContentAPI(whereClause);
|
|
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);
|
|
684
710
|
const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
|
|
685
711
|
body: {
|
|
686
|
-
collection
|
|
712
|
+
collection,
|
|
687
713
|
contentSystemId: this.contentSystemId,
|
|
688
714
|
createOnMissing: false,
|
|
689
715
|
doc: docData,
|
|
@@ -691,13 +717,13 @@ async function updateJobs(args) {
|
|
|
691
717
|
...limit != null && {
|
|
692
718
|
limit
|
|
693
719
|
},
|
|
694
|
-
schema: this.documentSchema,
|
|
720
|
+
schema: this.documentSchema(),
|
|
695
721
|
sort: sortClause,
|
|
696
722
|
where: whereQuery
|
|
697
723
|
}
|
|
698
724
|
});
|
|
699
725
|
if (error) {
|
|
700
|
-
throw
|
|
726
|
+
throw createDocumentContentAPIError(this, 'updateJobs', error, httpResponse.status, collection);
|
|
701
727
|
}
|
|
702
728
|
if (!response) {
|
|
703
729
|
throw new Error('No response from updateJobs');
|
|
@@ -709,18 +735,18 @@ async function updateJobs(args) {
|
|
|
709
735
|
return [];
|
|
710
736
|
}
|
|
711
737
|
return response.result.data.map((doc)=>unwrapDocument({
|
|
712
|
-
collectionSlug:
|
|
738
|
+
collectionSlug: collection,
|
|
713
739
|
doc,
|
|
714
740
|
payload: this.payload
|
|
715
741
|
}));
|
|
716
742
|
}
|
|
717
|
-
function createGlobal(args) {
|
|
743
|
+
async function createGlobal(args) {
|
|
718
744
|
// Globals are singletons identified by their slug. Use upsert so concurrent calls
|
|
719
745
|
// (e.g. handleSchedules processing multiple queueables with the same null jobStats)
|
|
720
746
|
// don't fail with "A record with this field already exists". The deep-merge semantics
|
|
721
747
|
// of the update path are safe here: callers that want a fresh create (first run) get
|
|
722
748
|
// an effective create, and callers that race a prior create get a merge instead.
|
|
723
|
-
|
|
749
|
+
const doc = await this.upsert({
|
|
724
750
|
collection: getGlobalSlug(args.slug),
|
|
725
751
|
data: {
|
|
726
752
|
...args.data,
|
|
@@ -732,6 +758,7 @@ function createGlobal(args) {
|
|
|
732
758
|
}
|
|
733
759
|
}
|
|
734
760
|
});
|
|
761
|
+
return injectGlobalType(doc, args.slug);
|
|
735
762
|
}
|
|
736
763
|
async function findGlobal(args) {
|
|
737
764
|
const doc = await this.findOne({
|
|
@@ -739,17 +766,10 @@ async function findGlobal(args) {
|
|
|
739
766
|
locale: args.locale,
|
|
740
767
|
where: args.where ?? {}
|
|
741
768
|
});
|
|
742
|
-
|
|
743
|
-
;
|
|
744
|
-
doc.globalType = args.slug;
|
|
745
|
-
}
|
|
746
|
-
return doc;
|
|
769
|
+
return injectGlobalType(doc, args.slug);
|
|
747
770
|
}
|
|
748
771
|
async function updateGlobal(args) {
|
|
749
|
-
|
|
750
|
-
// which overwrites the original timestamp on updates. The fix belongs in the Content API:
|
|
751
|
-
// `createOnMissing` should preserve `createdAt` on updates and only set it on creates.
|
|
752
|
-
return this.upsert({
|
|
772
|
+
const doc = await this.upsert({
|
|
753
773
|
collection: getGlobalSlug(args.slug),
|
|
754
774
|
data: args.data,
|
|
755
775
|
where: {
|
|
@@ -758,6 +778,7 @@ async function updateGlobal(args) {
|
|
|
758
778
|
}
|
|
759
779
|
}
|
|
760
780
|
});
|
|
781
|
+
return injectGlobalType(doc, args.slug);
|
|
761
782
|
}
|
|
762
783
|
// TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183
|
|
763
784
|
function findGlobalVersions(args) {
|
|
@@ -809,6 +830,13 @@ function countGlobalVersions(args) {
|
|
|
809
830
|
where: args.where
|
|
810
831
|
});
|
|
811
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
|
+
}
|
|
812
840
|
function createContentAPIError(operation, error, status) {
|
|
813
841
|
return new APIError(`Content API ${operation} error: ${error.message}`, status, {
|
|
814
842
|
code: error.code,
|
|
@@ -816,6 +844,27 @@ function createContentAPIError(operation, error, status) {
|
|
|
816
844
|
field: error.field
|
|
817
845
|
});
|
|
818
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
|
+
}
|
|
819
868
|
export const contentAPIAdapter = (opts)=>({
|
|
820
869
|
name: 'content-api',
|
|
821
870
|
defaultIDType: 'text',
|
|
@@ -855,7 +904,7 @@ export const contentAPIAdapter = (opts)=>({
|
|
|
855
904
|
deleteMany: deleteMany,
|
|
856
905
|
deleteOne: deleteOne,
|
|
857
906
|
deleteVersions: deleteVersions,
|
|
858
|
-
documentSchema:
|
|
907
|
+
documentSchema: ()=>getDocumentSchema(payload.config),
|
|
859
908
|
environmentName: opts.environmentName,
|
|
860
909
|
find: find,
|
|
861
910
|
findDistinct: findDistinct,
|