@payloadcms/figma 0.1.0-internal.10c3b07 → 0.1.0-internal.fbdc0d3
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 +10 -4
- package/dist/{utils → adapters}/asset-collection.js +58 -17
- package/dist/{utils → adapters}/build-lambda-zip.d.ts +4 -2
- 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/{utils → adapters}/deploy-output/resolveOutputPath.d.ts +1 -1
- 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/{utils/adapters → adapters}/nitro.d.ts +2 -2
- package/dist/{utils/adapters → adapters}/nitro.js +54 -29
- 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 +1 -1
- package/dist/{utils/adapters → adapters}/vite.js +4 -3
- package/dist/api/control-plane.d.ts +11 -0
- package/dist/api/control-plane.js +26 -0
- package/dist/auth/headless-oauth-flow.js +4 -0
- package/dist/auth/oauth-flow.js +17 -0
- package/dist/auth/refresh.js +12 -12
- package/dist/auth/requested-scopes.d.ts +1 -0
- package/dist/auth/requested-scopes.js +3 -0
- package/dist/auth/token-store.d.ts +16 -0
- package/dist/auth/token-store.js +33 -0
- package/dist/auth/types.d.ts +5 -3
- package/dist/commands/bootstrap.js +3 -0
- package/dist/commands/build-lambda-zip.js +1 -1
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/init.js +72 -2
- package/dist/commands/upgrade.js +65 -1
- package/dist/commands/upload-schema.js +3 -4
- package/dist/config/oauth.js +6 -1
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +0 -3
- package/dist/db-content-api/generated/content-api-types.d.ts +6 -2
- package/dist/db-content-api/utilities/auth.d.ts +1 -4
- package/dist/db-content-api/utilities/auth.js +1 -1
- package/dist/db-content-api/utilities/data/index.js +8 -2
- 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/schema/buildDocumentSchema.js +9 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -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/plugin/build-config.d.ts +13 -3
- package/dist/plugin/build-config.js +198 -59
- 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 +2 -1
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -1
- 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/storage-content-api/api-types.d.ts +5 -2
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.d.ts +1 -1
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.js +3 -1
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +8 -6
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +17 -12
- 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 +3 -3
- package/dist/storage-content-api/buildMediaResponseHeaders.js +25 -18
- package/dist/storage-content-api/client-uploads/generate.d.ts +7 -3
- package/dist/storage-content-api/client-uploads/generate.js +22 -21
- package/dist/storage-content-api/client.d.ts +0 -2
- package/dist/storage-content-api/client.js +2 -2
- package/dist/storage-content-api/copyFile.d.ts +16 -0
- package/dist/storage-content-api/copyFile.js +90 -0
- package/dist/storage-content-api/deleteFile.d.ts +8 -0
- package/dist/storage-content-api/deleteFile.js +18 -0
- 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/handleUpload.d.ts +1 -2
- package/dist/storage-content-api/handleUpload.js +13 -157
- package/dist/storage-content-api/hasSupportedContentEncoding.d.ts +1 -1
- package/dist/storage-content-api/hasSupportedContentEncoding.js +4 -2
- package/dist/storage-content-api/index.js +17 -8
- package/dist/storage-content-api/mediaErrorResponse.d.ts +1 -1
- package/dist/storage-content-api/mediaErrorResponse.js +2 -2
- 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/{getInlineContentType.js → shouldAttachMedia.js} +8 -7
- package/dist/storage-content-api/staticHandler.d.ts +2 -1
- package/dist/storage-content-api/staticHandler.js +47 -53
- package/dist/storage-content-api/types.d.ts +4 -1
- package/dist/storage-content-api/uploadFileData.d.ts +10 -0
- package/dist/storage-content-api/uploadFileData.js +145 -0
- package/dist/utils/build-detection.js +3 -3
- package/dist/utils/cache-bootstrap.js +1 -0
- package/dist/utils/deploy-adapter.d.ts +2 -34
- package/dist/utils/deploy-adapter.js +16 -9
- package/dist/utils/env-management.d.ts +15 -0
- package/dist/utils/env-management.js +47 -0
- package/dist/utils/lambda-config.js +14 -9
- package/dist/utils/load-payload-config.js +1 -6
- 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.d.ts +5 -0
- package/dist/utils/payload-config-ast.js +73 -4
- package/dist/utils/payload-config-modifier.js +3 -0
- package/dist/utils/payload-secret.d.ts +28 -0
- package/dist/utils/payload-secret.js +34 -0
- package/package.json +22 -10
- package/dist/storage-content-api/getInlineContentType.d.ts +0 -1
- package/dist/storage-content-api/handleDelete.d.ts +0 -7
- package/dist/storage-content-api/handleDelete.js +0 -15
- package/dist/storage-content-api/utilities/getSafeFilename.d.ts +0 -11
- package/dist/storage-content-api/utilities/getSafeFilename.js +0 -59
- package/dist/storage-content-api/utilities/index.d.ts +0 -2
- package/dist/storage-content-api/utilities/index.js +0 -2
- package/dist/storage-content-api/utilities/parseUploadReference.d.ts +0 -17
- package/dist/storage-content-api/utilities/parseUploadReference.js +0 -27
- package/dist/utils/adapters/nextjs.d.ts +0 -8
- package/dist/utils/adapters/nextjs.js +0 -64
- package/dist/utils/build-lambda-zip.js +0 -73
- package/dist/utils/fs-utils.d.ts +0 -12
- package/dist/utils/fs-utils.js +0 -55
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNitroOutput.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNitroOutput.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/isFile.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/isFile.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/readJson.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/readJson.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveNitroOutputLayout.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveNitroOutputLayout.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveOutputPath.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveWithin.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveWithin.js +0 -0
package/dist/auth/oauth-flow.js
CHANGED
|
@@ -7,6 +7,7 @@ import { CallbackError, CallbackServer } from './callback-server.js';
|
|
|
7
7
|
import { parsePastedCode, validatePastedCode } from './paste-code.js';
|
|
8
8
|
import { generatePKCEPair } from './pkce.js';
|
|
9
9
|
import { exchangeCodeForTokens, refreshAccessToken, TokenRefreshError } from './refresh.js';
|
|
10
|
+
import { hasRequestedScopes } from './requested-scopes.js';
|
|
10
11
|
/**
|
|
11
12
|
* Error during OAuth flow
|
|
12
13
|
*/ export class OAuthFlowError extends Error {
|
|
@@ -130,6 +131,9 @@ import { exchangeCodeForTokens, refreshAccessToken, TokenRefreshError } from './
|
|
|
130
131
|
} catch (error) {
|
|
131
132
|
throw new OAuthFlowError('Failed to exchange authorization code for tokens', error instanceof Error ? error : undefined);
|
|
132
133
|
}
|
|
134
|
+
if (!hasRequestedScopes(tokens.scopes, scopes)) {
|
|
135
|
+
throw new OAuthFlowError('Authorization did not grant all requested Cloud scopes');
|
|
136
|
+
}
|
|
133
137
|
// Store tokens
|
|
134
138
|
try {
|
|
135
139
|
tokenStore.setTokens(tokens);
|
|
@@ -162,6 +166,13 @@ import { exchangeCodeForTokens, refreshAccessToken, TokenRefreshError } from './
|
|
|
162
166
|
* @returns Promise resolving to AuthCredential (wrapped access token) or null if no valid tokens
|
|
163
167
|
* @throws OAuthFlowError if refresh fails
|
|
164
168
|
*/ export async function getValidOAuthAccessToken(tokenStore) {
|
|
169
|
+
const cached = tokenStore.getOauthInfo();
|
|
170
|
+
const requiredScopes = getOAuthConfig().scopes;
|
|
171
|
+
// Older cached grants lack scope metadata or the Cloud capabilities. Refreshing
|
|
172
|
+
// them cannot add consent, so start a new authorization flow instead.
|
|
173
|
+
if (cached && !hasRequestedScopes(cached.scopes, requiredScopes)) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
165
176
|
// Check if we have valid tokens
|
|
166
177
|
if (tokenStore.hasValidOauthToken()) {
|
|
167
178
|
const token = tokenStore.getCurrentOauthToken();
|
|
@@ -179,6 +190,9 @@ import { exchangeCodeForTokens, refreshAccessToken, TokenRefreshError } from './
|
|
|
179
190
|
try {
|
|
180
191
|
const tokens = await refreshAccessToken(refreshToken);
|
|
181
192
|
tokenStore.setTokens(tokens);
|
|
193
|
+
if (!hasRequestedScopes(tokens.scopes, requiredScopes)) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
182
196
|
return {
|
|
183
197
|
type: 'oauth',
|
|
184
198
|
token: tokens.accessToken
|
|
@@ -190,6 +204,9 @@ import { exchangeCodeForTokens, refreshAccessToken, TokenRefreshError } from './
|
|
|
190
204
|
try {
|
|
191
205
|
const tokens = await refreshAccessToken(refreshToken);
|
|
192
206
|
tokenStore.setTokens(tokens);
|
|
207
|
+
if (!hasRequestedScopes(tokens.scopes, requiredScopes)) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
193
210
|
return {
|
|
194
211
|
type: 'oauth',
|
|
195
212
|
token: tokens.accessToken
|
package/dist/auth/refresh.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/* eslint-disable perfectionist/sort-objects */ import { getOAuthConfig } from '../config/oauth.js';
|
|
2
2
|
import * as log from '../utils/log.js';
|
|
3
|
+
function parseGrantedScopes(scope) {
|
|
4
|
+
return scope?.split(/[\s,]+/).filter(Boolean);
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* Error thrown when token refresh fails
|
|
5
8
|
*/ export class TokenRefreshError extends Error {
|
|
@@ -50,15 +53,17 @@ import * as log from '../utils/log.js';
|
|
|
50
53
|
}
|
|
51
54
|
const data = await response.json();
|
|
52
55
|
// Validate response contains required fields
|
|
53
|
-
if (!data.access_token || !data.
|
|
56
|
+
if (!data.access_token || !data.expires_in) {
|
|
54
57
|
throw new TokenRefreshError('Invalid token response: missing required fields');
|
|
55
58
|
}
|
|
56
59
|
// Convert response to our internal token format
|
|
57
60
|
const expiresAt = Date.now() + data.expires_in * 1000;
|
|
58
61
|
return {
|
|
59
62
|
accessToken: data.access_token,
|
|
60
|
-
refreshToken: data.refresh_token,
|
|
63
|
+
refreshToken: data.refresh_token ?? refreshToken,
|
|
61
64
|
expiresAt,
|
|
65
|
+
scopes: parseGrantedScopes(data.scope),
|
|
66
|
+
tokenType: data.token_type,
|
|
62
67
|
userId: data.user_id_string
|
|
63
68
|
};
|
|
64
69
|
} catch (error) {
|
|
@@ -99,12 +104,7 @@ import * as log from '../utils/log.js';
|
|
|
99
104
|
const headers = {
|
|
100
105
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
101
106
|
};
|
|
102
|
-
|
|
103
|
-
log.debug(`Token exchange request: ${JSON.stringify({
|
|
104
|
-
url: oauthConfig.tokenUrl,
|
|
105
|
-
headers,
|
|
106
|
-
body: params.toString()
|
|
107
|
-
})}`);
|
|
107
|
+
log.debug(`Token exchange request to ${oauthConfig.tokenUrl}`);
|
|
108
108
|
const response = await fetch(oauthConfig.tokenUrl, {
|
|
109
109
|
method: 'POST',
|
|
110
110
|
headers,
|
|
@@ -117,17 +117,15 @@ import * as log from '../utils/log.js';
|
|
|
117
117
|
})}`);
|
|
118
118
|
if (!response.ok) {
|
|
119
119
|
const errorText = await response.text();
|
|
120
|
-
log.debug(`
|
|
120
|
+
log.debug(`Token exchange rejected with status ${response.status}`);
|
|
121
121
|
throw new TokenRefreshError(`Token exchange failed: ${response.statusText}. ${errorText}`, response.status);
|
|
122
122
|
}
|
|
123
123
|
const data = await response.json();
|
|
124
124
|
log.debug(`Token response: ${JSON.stringify({
|
|
125
|
-
access_token: data.access_token,
|
|
126
125
|
token_type: data.token_type,
|
|
127
126
|
expires_in: data.expires_in,
|
|
128
127
|
scope: data.scope,
|
|
129
|
-
user_id_string: data.user_id_string
|
|
130
|
-
refresh_token: data.refresh_token?.substring(0, 10) + '...'
|
|
128
|
+
user_id_string: data.user_id_string
|
|
131
129
|
})}`);
|
|
132
130
|
// Validate response contains required fields
|
|
133
131
|
if (!data.access_token || !data.refresh_token || !data.expires_in) {
|
|
@@ -139,6 +137,8 @@ import * as log from '../utils/log.js';
|
|
|
139
137
|
accessToken: data.access_token,
|
|
140
138
|
refreshToken: data.refresh_token,
|
|
141
139
|
expiresAt,
|
|
140
|
+
scopes: parseGrantedScopes(data.scope),
|
|
141
|
+
tokenType: data.token_type,
|
|
142
142
|
userId: data.user_id_string
|
|
143
143
|
};
|
|
144
144
|
} catch (error) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hasRequestedScopes(granted: readonly string[] | undefined, required: readonly string[]): boolean;
|
|
@@ -64,6 +64,22 @@ export declare class TokenStore {
|
|
|
64
64
|
getBootstrapData(projectId: string, environmentName: string): BootstrapData | null;
|
|
65
65
|
setBootstrapData(projectId: string, environmentName: string, data: BootstrapData): void;
|
|
66
66
|
clearBootstrapData(projectId: string, environmentName: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* PAYLOAD_SECRET is fetched from the Control Plane during `init` and
|
|
69
|
+
* cached here per (projectId, environmentName). buildFigmaConfig reads
|
|
70
|
+
* it at local dev startup when process.env.PAYLOAD_SECRET is unset.
|
|
71
|
+
* Platform-injected in Lambda, so this path is never hit there.
|
|
72
|
+
*/
|
|
73
|
+
getPayloadSecret({ projectInfo }?: {
|
|
74
|
+
projectInfo?: ProjectStoreScope;
|
|
75
|
+
}): null | string;
|
|
76
|
+
setPayloadSecret({ projectInfo, secret, }: {
|
|
77
|
+
projectInfo?: ProjectStoreScope;
|
|
78
|
+
secret: string;
|
|
79
|
+
}): void;
|
|
80
|
+
clearPayloadSecret({ projectInfo }?: {
|
|
81
|
+
projectInfo?: ProjectStoreScope;
|
|
82
|
+
}): void;
|
|
67
83
|
private buildOAuthConfigName;
|
|
68
84
|
private buildOAuthStoreCwd;
|
|
69
85
|
private buildProjectStoreConfigName;
|
package/dist/auth/token-store.js
CHANGED
|
@@ -354,6 +354,39 @@ const PROJECT_STORE_SCHEMA_VERSION = 1;
|
|
|
354
354
|
});
|
|
355
355
|
config.delete('bootstrapData');
|
|
356
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* PAYLOAD_SECRET is fetched from the Control Plane during `init` and
|
|
359
|
+
* cached here per (projectId, environmentName). buildFigmaConfig reads
|
|
360
|
+
* it at local dev startup when process.env.PAYLOAD_SECRET is unset.
|
|
361
|
+
* Platform-injected in Lambda, so this path is never hit there.
|
|
362
|
+
*/ getPayloadSecret({ projectInfo } = {}) {
|
|
363
|
+
const resolvedProjectInfo = projectInfo ?? this.getProjectInfoFromEnv();
|
|
364
|
+
if (!resolvedProjectInfo) {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
const config = this.getProjectStore(resolvedProjectInfo);
|
|
368
|
+
return this.safeGet({
|
|
369
|
+
config,
|
|
370
|
+
key: 'payloadSecret'
|
|
371
|
+
}) ?? null;
|
|
372
|
+
}
|
|
373
|
+
setPayloadSecret({ projectInfo, secret }) {
|
|
374
|
+
const resolvedProjectInfo = projectInfo ?? this.getProjectInfoFromEnv();
|
|
375
|
+
if (!resolvedProjectInfo) {
|
|
376
|
+
throw new Error('Cannot set payload secret: FIGMA_PROJECT_ID and FIGMA_ENVIRONMENT_NAME must be set');
|
|
377
|
+
}
|
|
378
|
+
const config = this.getProjectStore(resolvedProjectInfo);
|
|
379
|
+
config.set('_schemaVersion', PROJECT_STORE_SCHEMA_VERSION);
|
|
380
|
+
config.set('payloadSecret', secret);
|
|
381
|
+
}
|
|
382
|
+
clearPayloadSecret({ projectInfo } = {}) {
|
|
383
|
+
const resolvedProjectInfo = projectInfo ?? this.getProjectInfoFromEnv();
|
|
384
|
+
if (!resolvedProjectInfo) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const config = this.getProjectStore(resolvedProjectInfo);
|
|
388
|
+
config.delete('payloadSecret');
|
|
389
|
+
}
|
|
357
390
|
buildOAuthConfigName() {
|
|
358
391
|
// For test isolation: if using a custom config name, use it as-is with -oauth suffix
|
|
359
392
|
// Otherwise use the standard naming that includes environment
|
package/dist/auth/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Environment } from '../constants.js';
|
|
|
5
5
|
* Standard OAuth2 scopes for user-level permissions
|
|
6
6
|
* @see https://www.figma.com/developers/api#oauth2
|
|
7
7
|
*/
|
|
8
|
-
export type FigmaOAuthScope = 'current_user:read' | 'file_comments:read' | 'file_comments:write' | 'file_content:read' | 'file_dev_resources:read' | 'file_dev_resources:write' | 'file_metadata:read' | 'file_variables:read' | 'file_variables:write' | 'file_versions:read' | 'files:read' | 'library_analytics:read' | 'library_assets:read' | 'library_content:read' | 'projects:read' | 'team_library_content:read' | 'webhooks:read' | 'webhooks:write';
|
|
8
|
+
export type FigmaOAuthScope = 'cloud:content:read_write' | 'cloud:create' | 'cloud:deploy' | 'cloud:read' | 'cloud:secrets:read' | 'current_user:read' | 'file_comments:read' | 'file_comments:write' | 'file_content:read' | 'file_dev_resources:read' | 'file_dev_resources:write' | 'file_metadata:read' | 'file_variables:read' | 'file_variables:write' | 'file_versions:read' | 'files:read' | 'library_analytics:read' | 'library_assets:read' | 'library_content:read' | 'projects:read' | 'team_library_content:read' | 'webhooks:read' | 'webhooks:write';
|
|
9
9
|
/**
|
|
10
10
|
* Organization-level OAuth2 scopes
|
|
11
11
|
* Requires organization admin permissions
|
|
@@ -53,8 +53,8 @@ export interface FigmaTokenResponse {
|
|
|
53
53
|
access_token: string;
|
|
54
54
|
/** Token expiration time in seconds */
|
|
55
55
|
expires_in: number;
|
|
56
|
-
/** OAuth2 refresh token */
|
|
57
|
-
refresh_token
|
|
56
|
+
/** OAuth2 refresh token; omitted when refreshing an existing grant */
|
|
57
|
+
refresh_token?: string;
|
|
58
58
|
/** Space-separated list of granted scopes */
|
|
59
59
|
scope?: string;
|
|
60
60
|
/** Token type (typically "Bearer") */
|
|
@@ -189,6 +189,8 @@ export type FigmaUser = User;
|
|
|
189
189
|
* Keyed by projectId:environmentName
|
|
190
190
|
*/
|
|
191
191
|
export type BootstrapData = {
|
|
192
|
+
/** Regional Content API base URL. Absent in entries cached before bootstrap returned it. */
|
|
193
|
+
contentApiUrl?: string;
|
|
192
194
|
contentSystemId: string;
|
|
193
195
|
oauthClientId: string;
|
|
194
196
|
oauthClientSecret: string;
|
|
@@ -84,6 +84,9 @@ import { maskToken } from '../utils/token-display.js';
|
|
|
84
84
|
];
|
|
85
85
|
for (const env of info.environments){
|
|
86
86
|
lines.push(` ${pc.bold(env.name)}`, ` Tenant ID (contentSystemId): ${env.contentSystemId}`, ` Tenant Instance ID: ${env.tenantInstanceId}`);
|
|
87
|
+
if (env.contentApiUrl) {
|
|
88
|
+
lines.push(` Content API URL: ${env.contentApiUrl}`);
|
|
89
|
+
}
|
|
87
90
|
}
|
|
88
91
|
p.note(lines.join('\n'), 'Bootstrap Info');
|
|
89
92
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as p from '@clack/prompts';
|
|
2
2
|
import pc from 'picocolors';
|
|
3
|
-
import { buildLambdaZip } from '../
|
|
3
|
+
import { buildLambdaZip } from '../adapters/build-lambda-zip.js';
|
|
4
4
|
/**
|
|
5
5
|
* Build Lambda deployment zip from current directory
|
|
6
6
|
*/ export async function buildLambdaZipCommand() {
|
package/dist/commands/deploy.js
CHANGED
|
@@ -2,14 +2,14 @@ import * as p from '@clack/prompts';
|
|
|
2
2
|
import spawn from 'cross-spawn';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import pc from 'picocolors';
|
|
5
|
+
import { getFileSize } from '../adapters/asset-collection.js';
|
|
6
|
+
import { LAMBDA_MAX_UNZIPPED_BYTES } from '../adapters/build-lambda-zip.js';
|
|
5
7
|
import { createDeployment, getBootstrapInfo, performDeployment } from '../api/control-plane.js';
|
|
6
8
|
import { ControlPlaneError } from '../api/control-plane-error.js';
|
|
7
9
|
import { tryGetCredential } from '../auth/oauth-flow.js';
|
|
8
10
|
import { getTokenStore } from '../auth/token-store.js';
|
|
9
11
|
import { getInfraEnvironment, getProjectNotFoundMessage } from '../constants.js';
|
|
10
|
-
import { getFileSize } from '../utils/asset-collection.js';
|
|
11
12
|
import { detectBuild, getBuildCommand } from '../utils/build-detection.js';
|
|
12
|
-
import { LAMBDA_MAX_UNZIPPED_BYTES } from '../utils/build-lambda-zip.js';
|
|
13
13
|
import { detectAdapter } from '../utils/deploy-adapter.js';
|
|
14
14
|
import { getEnvVar } from '../utils/env-management.js';
|
|
15
15
|
import * as log from '../utils/log.js';
|
package/dist/commands/init.js
CHANGED
|
@@ -11,7 +11,7 @@ import { getTokenStore } from '../auth/token-store.js';
|
|
|
11
11
|
import { getInfraEnvironment, getProjectNotFoundMessage } from '../constants.js';
|
|
12
12
|
import { writeAgentConfigFiles } from '../lib/write-agent-config.js';
|
|
13
13
|
import { ensureGitignore } from '../utils/config.js';
|
|
14
|
-
import { addOrUpdateEnvVar } from '../utils/env-management.js';
|
|
14
|
+
import { addOrUpdateEnvVar, commentOutEnvVar, removeEnvVar } from '../utils/env-management.js';
|
|
15
15
|
import { isDebug } from '../utils/is-debug.js';
|
|
16
16
|
import { applyLambdaModifications } from '../utils/lambda-config.js';
|
|
17
17
|
import * as log from '../utils/log.js';
|
|
@@ -29,6 +29,52 @@ import { writeProjectConfiguration } from './write-project-configuration.js';
|
|
|
29
29
|
import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
|
|
30
30
|
import { DEFAULT_TEMPLATE_SOURCE } from '../utils/download-template.js';
|
|
31
31
|
import { parseTemplateSpec, TemplateSpecParseError } from '../utils/parse-template-spec.js';
|
|
32
|
+
import { ensurePayloadSecret } from '../utils/payload-secret.js';
|
|
33
|
+
async function removePayloadSecretFromEnv(projectDir) {
|
|
34
|
+
// New-project flow: the scaffold owns .env, so any PAYLOAD_SECRET carried
|
|
35
|
+
// over from a template is not a value the developer set. Remove it
|
|
36
|
+
// outright to keep the scaffolded file clean.
|
|
37
|
+
const removed = await removeEnvVar(projectDir, 'PAYLOAD_SECRET');
|
|
38
|
+
if (!removed) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
p.log.warn(pc.yellow('⚠ Removed PAYLOAD_SECRET from .env. The Figma platform owns this value; a local ' + 'copy would silently diverge from the deployed secret and cause encrypted data ' + '(API keys, auth tokens) to fail decryption in production.'));
|
|
42
|
+
}
|
|
43
|
+
async function commentOutPayloadSecretInEnv(projectDir) {
|
|
44
|
+
// Existing-project flow: the developer's .env may hold a PAYLOAD_SECRET
|
|
45
|
+
// they need for another system or environment. Comment out rather than
|
|
46
|
+
// delete so the value survives and they can uncomment / relocate it.
|
|
47
|
+
const changed = await commentOutEnvVar(projectDir, 'PAYLOAD_SECRET', 'disabled by @payloadcms/figma: platform owns PAYLOAD_SECRET');
|
|
48
|
+
if (!changed) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
p.log.warn(pc.yellow('⚠ Commented out PAYLOAD_SECRET in .env. The Figma platform owns this value; a ' + 'local copy would silently diverge from the deployed secret and cause encrypted ' + 'data (API keys, auth tokens) to fail decryption in production.'));
|
|
52
|
+
}
|
|
53
|
+
async function maybeEnsurePayloadSecret(args) {
|
|
54
|
+
if (!args.credential || !args.resolvedEnv) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await ensurePayloadSecret({
|
|
59
|
+
credential: args.credential,
|
|
60
|
+
projectInfo: {
|
|
61
|
+
environmentName: args.resolvedEnv.name,
|
|
62
|
+
projectId: args.cmsResourceId
|
|
63
|
+
},
|
|
64
|
+
tenantInstanceId: args.resolvedEnv.tenantInstanceId,
|
|
65
|
+
tokenStore: args.tokenStore,
|
|
66
|
+
// Re-init is the explicit recovery path after platform secret rotation.
|
|
67
|
+
refresh: true
|
|
68
|
+
});
|
|
69
|
+
log.debug('PAYLOAD_SECRET cached in TokenStore');
|
|
70
|
+
return true;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
// Preserve the existing cache and .env fallback until a refresh succeeds.
|
|
73
|
+
const message = err instanceof Error ? err.message : 'Unknown error';
|
|
74
|
+
p.log.warn(pc.yellow(`⚠ Could not fetch PAYLOAD_SECRET (${message}). Existing secrets were preserved. Re-run init to retry.`));
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
32
78
|
async function maybeWriteAgentConfigFiles(args) {
|
|
33
79
|
if (args.noAgent) {
|
|
34
80
|
return;
|
|
@@ -299,6 +345,12 @@ async function maybeWriteAgentConfigFiles(args) {
|
|
|
299
345
|
p.log.error(error instanceof Error ? error.message : 'Failed to configure project');
|
|
300
346
|
process.exit(1);
|
|
301
347
|
}
|
|
348
|
+
await maybeEnsurePayloadSecret({
|
|
349
|
+
cmsResourceId,
|
|
350
|
+
credential,
|
|
351
|
+
resolvedEnv,
|
|
352
|
+
tokenStore
|
|
353
|
+
});
|
|
302
354
|
p.outro(pc.green('✓ Vite project initialized successfully!'));
|
|
303
355
|
return;
|
|
304
356
|
}
|
|
@@ -374,6 +426,15 @@ async function maybeWriteAgentConfigFiles(args) {
|
|
|
374
426
|
} catch (error) {
|
|
375
427
|
p.log.warn(pc.yellow(`⚠ Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
376
428
|
}
|
|
429
|
+
const secretCached = await maybeEnsurePayloadSecret({
|
|
430
|
+
cmsResourceId,
|
|
431
|
+
credential,
|
|
432
|
+
resolvedEnv,
|
|
433
|
+
tokenStore
|
|
434
|
+
});
|
|
435
|
+
if (secretCached) {
|
|
436
|
+
await commentOutPayloadSecretInEnv(process.cwd());
|
|
437
|
+
}
|
|
377
438
|
} else {
|
|
378
439
|
p.log.warn(pc.yellow('⚠ Payload was not detected in this project'));
|
|
379
440
|
p.note('Run this command in a directory without an existing project or in an existing Payload project.', 'Action Required');
|
|
@@ -391,7 +452,7 @@ async function maybeWriteAgentConfigFiles(args) {
|
|
|
391
452
|
log.error(error instanceof Error ? error.message : 'Unknown error');
|
|
392
453
|
process.exit(1);
|
|
393
454
|
}
|
|
394
|
-
// Apply Lambda modifications (run.sh,
|
|
455
|
+
// Apply Lambda modifications (run.sh, Next.js config, lambda:buildzip script)
|
|
395
456
|
await applyLambdaModifications(process.cwd(), packageManager);
|
|
396
457
|
// Ensure .gitignore has required entries
|
|
397
458
|
await ensureGitignore(process.cwd(), [
|
|
@@ -466,6 +527,15 @@ async function maybeWriteAgentConfigFiles(args) {
|
|
|
466
527
|
} catch (error) {
|
|
467
528
|
p.log.warn(pc.yellow(`⚠ Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
468
529
|
}
|
|
530
|
+
const secretCached = await maybeEnsurePayloadSecret({
|
|
531
|
+
cmsResourceId,
|
|
532
|
+
credential,
|
|
533
|
+
resolvedEnv,
|
|
534
|
+
tokenStore
|
|
535
|
+
});
|
|
536
|
+
if (secretCached) {
|
|
537
|
+
await removePayloadSecretFromEnv(fullPath);
|
|
538
|
+
}
|
|
469
539
|
// npm leaves node_modules in a transient state after a sequence of
|
|
470
540
|
// add/remove calls; a final install reconciles it so the project is
|
|
471
541
|
// immediately buildable.
|
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);
|
|
@@ -4,7 +4,6 @@ import { getBootstrapInfo } from '../api/control-plane.js';
|
|
|
4
4
|
import { tryGetCredential } from '../auth/oauth-flow.js';
|
|
5
5
|
import { getValidProjectToken } from '../auth/project-token.js';
|
|
6
6
|
import { getTokenStore } from '../auth/token-store.js';
|
|
7
|
-
import { getEnvConfig } from '../constants.js';
|
|
8
7
|
import { buildDocumentSchema } from '../db-content-api/utilities/schema/buildDocumentSchema.js';
|
|
9
8
|
import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
|
|
10
9
|
import { getEnvVar } from '../utils/env-management.js';
|
|
@@ -58,10 +57,10 @@ import { loginCommand } from './login.js';
|
|
|
58
57
|
if (!apiKey && !projectToken) {
|
|
59
58
|
throw new Error('Could not get a project token. Run `@payloadcms/figma login` and retry.');
|
|
60
59
|
}
|
|
61
|
-
//
|
|
62
|
-
const contentApiUrl = process.env.FIGMA_CONTENT_API_URL ||
|
|
60
|
+
// The bootstrap environment carries its regional Content API URL.
|
|
61
|
+
const contentApiUrl = process.env.FIGMA_CONTENT_API_URL || environment.contentApiUrl;
|
|
63
62
|
if (!contentApiUrl) {
|
|
64
|
-
throw new Error(
|
|
63
|
+
throw new Error(`No Content API URL returned for environment "${environment.name}".`);
|
|
65
64
|
}
|
|
66
65
|
const response = await fetch(`${contentApiUrl}/api/v0/content_systems/${encodeURIComponent(environment.contentSystemId)}/jsonb_to_index_migration_schema`, {
|
|
67
66
|
body: JSON.stringify({
|
package/dist/config/oauth.js
CHANGED
|
@@ -28,7 +28,12 @@ export const DEFAULT_CALLBACK_PORT = DEFAULT_CALLBACK_PORTS[0];
|
|
|
28
28
|
redirectUri: process.env.FIGMA_REDIRECT_URI || `http://localhost:${DEFAULT_CALLBACK_PORT}/callback`,
|
|
29
29
|
refreshUrl: `${apiBaseUrl}/v1/oauth/refresh`,
|
|
30
30
|
scopes: [
|
|
31
|
-
'current_user:read'
|
|
31
|
+
'current_user:read',
|
|
32
|
+
'cloud:read',
|
|
33
|
+
'cloud:create',
|
|
34
|
+
'cloud:secrets:read',
|
|
35
|
+
'cloud:content:read_write',
|
|
36
|
+
'cloud:deploy'
|
|
32
37
|
],
|
|
33
38
|
tokenUrl: `${apiBaseUrl}/v1/oauth/token`
|
|
34
39
|
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -11,8 +11,6 @@ type EnvironmentConfig = {
|
|
|
11
11
|
authorizationUrl: string;
|
|
12
12
|
/** OAuth client ID. Override: FIGMA_CLIENT_ID or FIGMA_OAUTH_CLIENT_ID */
|
|
13
13
|
clientId: string;
|
|
14
|
-
/** Content API base URL. Override: FIGMA_CONTENT_API_URL */
|
|
15
|
-
contentApiUrl: string;
|
|
16
14
|
/** OIDC discovery endpoint */
|
|
17
15
|
identityMetadata: string;
|
|
18
16
|
/** JSON Web Key Set URL for token validation */
|
package/dist/constants.js
CHANGED
|
@@ -7,7 +7,6 @@ import { getEnvVarSync } from './utils/env-management.js';
|
|
|
7
7
|
apiBaseUrl: 'https://api.figma.com',
|
|
8
8
|
authorizationUrl: 'https://www.figma.com/oauth',
|
|
9
9
|
clientId: 'lelKVTAzOekFnirnlAMbuD',
|
|
10
|
-
contentApiUrl: 'https://us-east-1.cms-tenants-001-production.figmacontent.com',
|
|
11
10
|
identityMetadata: 'https://www.figma.com/.well-known/openid-configuration',
|
|
12
11
|
jwksUri: 'https://static.figmacontent.com/.well_known/jwks.json'
|
|
13
12
|
},
|
|
@@ -15,7 +14,6 @@ import { getEnvVarSync } from './utils/env-management.js';
|
|
|
15
14
|
apiBaseUrl: 'https://api.staging.figma.com',
|
|
16
15
|
authorizationUrl: 'https://staging.figma.com/oauth',
|
|
17
16
|
clientId: 'wqAToBAp4UI9AZ5M6wTfT9',
|
|
18
|
-
contentApiUrl: 'https://us-east-1.cms-tenants-001-staging.figmacontentstaging.com',
|
|
19
17
|
identityMetadata: 'https://staging.figma.com/.well-known/openid-configuration',
|
|
20
18
|
jwksUri: 'https://static.figmacontentstaging.com/.well_known/jwks.json'
|
|
21
19
|
},
|
|
@@ -26,7 +24,6 @@ import { getEnvVarSync } from './utils/env-management.js';
|
|
|
26
24
|
apiBaseUrl: '',
|
|
27
25
|
authorizationUrl: '',
|
|
28
26
|
clientId: 'rNZBcf3xBDmI76mQ9603su',
|
|
29
|
-
contentApiUrl: '',
|
|
30
27
|
identityMetadata: '',
|
|
31
28
|
jwksUri: ''
|
|
32
29
|
}
|
|
@@ -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 */
|
|
@@ -12,10 +12,7 @@ type TokenStoreAuth = {
|
|
|
12
12
|
type DevJwtAuth = {
|
|
13
13
|
mode: 'devJwt';
|
|
14
14
|
};
|
|
15
|
-
type
|
|
16
|
-
mode: 'egressProxy';
|
|
17
|
-
};
|
|
18
|
-
export type AuthMode = ApiKeyAuth | DevJwtAuth | EgressProxyAuth | TokenStoreAuth;
|
|
15
|
+
export type AuthMode = ApiKeyAuth | DevJwtAuth | TokenStoreAuth;
|
|
19
16
|
export declare function fetchDevJwt(url: string, contentSystemId: string): Promise<string>;
|
|
20
17
|
export declare function createAuthMiddleware(opts: {
|
|
21
18
|
auth: AuthMode;
|
|
@@ -33,7 +33,7 @@ export function createAuthMiddleware(opts) {
|
|
|
33
33
|
throw new Error('Authentication required. Run `npx @payloadcms/figma login` to authenticate.');
|
|
34
34
|
}
|
|
35
35
|
request.headers.set('Authorization', `Bearer ${token}`);
|
|
36
|
-
} else
|
|
36
|
+
} else {
|
|
37
37
|
let token = devJwtCache.get(opts.contentSystemId);
|
|
38
38
|
if (!token) {
|
|
39
39
|
token = await fetchDevJwt(opts.url, opts.contentSystemId);
|
|
@@ -112,7 +112,7 @@ import { transformToLocalizeStatus } from './transformPublishedLocale.js';
|
|
|
112
112
|
'id'
|
|
113
113
|
]
|
|
114
114
|
});
|
|
115
|
-
removeVirtualFields(transformed, collectionConfig.fields);
|
|
115
|
+
removeVirtualFields(transformed, collectionConfig.fields, payload.config);
|
|
116
116
|
// Convert numeric ID to string for Content API
|
|
117
117
|
const customIDType = payload.collections?.[collectionSlug]?.customIDType;
|
|
118
118
|
if (customIDType === 'number') {
|
|
@@ -208,6 +208,12 @@ export function dataFromContentAPI(payload, collectionSlug, data, locale) {
|
|
|
208
208
|
};
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
211
|
+
// Document reads may omit an empty has-many select, while version writes store it as [].
|
|
212
|
+
// Return the same shape to Payload from both paths.
|
|
213
|
+
if (field.type === 'select' && field.hasMany && !isLocalized && value == null) {
|
|
214
|
+
current[fieldName] = [];
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
211
217
|
// Content API may omit fields; Payload expects null for optional fields.
|
|
212
218
|
// In all-locales mode, localized fields use {} so afterRead can safely iterate locale keys.
|
|
213
219
|
if (value === undefined) {
|
|
@@ -295,7 +301,7 @@ export function dataFromContentAPI(payload, collectionSlug, data, locale) {
|
|
|
295
301
|
]
|
|
296
302
|
});
|
|
297
303
|
// Remove virtual fields - must happen AFTER stripFields
|
|
298
|
-
removeVirtualFields(transformed, collectionConfig.fields);
|
|
304
|
+
removeVirtualFields(transformed, collectionConfig.fields, payload.config);
|
|
299
305
|
// Handle auth-specific fields that aren't in the field schema
|
|
300
306
|
// When these fields are null in DB, Content API omits them from response (undefined)
|
|
301
307
|
// But Payload expects them to be null, not undefined
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
* Virtual fields should never be persisted in the database.
|
|
5
|
-
*
|
|
6
|
-
* @todo It might be a good idea to combine `stripFields` with `stripFields`
|
|
7
|
-
* in a new utility that receives a callback with conditions. I didn't do
|
|
8
|
-
* it now because `stripFields` was copied from db-mongo and I'd like to
|
|
9
|
-
* find a way to unify everything.
|
|
10
|
-
*/
|
|
11
|
-
export declare function removeVirtualFields(data: Record<string, unknown>, fieldConfigs: CollectionConfig['fields']): void;
|
|
1
|
+
import type { Field, SanitizedConfig } from 'payload';
|
|
2
|
+
/** Remove pure virtual fields from document data at every schema depth. */
|
|
3
|
+
export declare function removeVirtualFields(data: Record<string, unknown>, fields: Field[], config: SanitizedConfig): void;
|