@payloadcms/figma 0.0.1-alpha.5 → 0.0.1-alpha.50
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/dist/api/control-plane.d.ts +31 -1
- package/dist/api/control-plane.js +137 -67
- package/dist/api/figma-api.d.ts +20 -0
- package/dist/api/figma-api.js +77 -21
- package/dist/auth/callback-server.js +2 -1
- package/dist/auth/crypto-utils.js +5 -5
- package/dist/auth/jwt-validator.d.ts +2 -1
- package/dist/auth/jwt-validator.js +2 -2
- package/dist/auth/oauth-flow.d.ts +1 -1
- package/dist/auth/oauth-flow.js +15 -11
- package/dist/auth/project-token.js +11 -6
- package/dist/auth/refresh.d.ts +2 -1
- package/dist/auth/refresh.js +25 -12
- package/dist/auth/token-store.d.ts +40 -1
- package/dist/auth/token-store.js +65 -5
- package/dist/auth/types.d.ts +17 -4
- package/dist/cli.js +54 -6
- package/dist/commands/build-lambda-zip.d.ts +5 -0
- package/dist/commands/build-lambda-zip.js +19 -0
- package/dist/commands/debug.d.ts +8 -0
- package/dist/commands/debug.js +161 -0
- package/dist/commands/deploy.d.ts +6 -0
- package/dist/commands/deploy.js +94 -126
- package/dist/commands/env.d.ts +13 -0
- package/dist/commands/env.js +88 -0
- package/dist/commands/init.d.ts +3 -5
- package/dist/commands/init.js +118 -94
- package/dist/commands/list-tokens.d.ts +3 -3
- package/dist/commands/list-tokens.js +22 -7
- package/dist/commands/login.d.ts +8 -1
- package/dist/commands/login.js +30 -12
- package/dist/commands/logout.d.ts +5 -4
- package/dist/commands/logout.js +56 -13
- package/dist/config/oauth.d.ts +4 -14
- package/dist/config/oauth.js +18 -40
- package/dist/constants.d.ts +36 -19
- package/dist/constants.js +58 -20
- package/dist/db-content-api/README.md +98 -0
- package/dist/db-content-api/generated/content-api-types.d.ts +3746 -0
- package/dist/db-content-api/generated/content-api-types.js +7 -0
- package/dist/db-content-api/index.d.ts +20 -0
- package/dist/db-content-api/index.js +702 -0
- package/dist/db-content-api/temp-utilities/slug.d.ts +2 -0
- package/dist/db-content-api/temp-utilities/slug.js +3 -0
- package/dist/db-content-api/temp-utilities/sorting.d.ts +3 -0
- package/dist/db-content-api/temp-utilities/sorting.js +32 -0
- package/dist/db-content-api/temp-utilities/types.d.ts +22 -0
- package/dist/db-content-api/temp-utilities/types.js +15 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts +34 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.js +53 -0
- package/dist/db-content-api/utilities/auth.d.ts +30 -0
- package/dist/db-content-api/utilities/auth.js +81 -0
- package/dist/db-content-api/utilities/data/applyDefaults.d.ts +7 -0
- package/dist/db-content-api/utilities/data/applyDefaults.js +59 -0
- package/dist/db-content-api/utilities/data/castFieldValue.d.ts +11 -0
- package/dist/db-content-api/utilities/data/castFieldValue.js +69 -0
- package/dist/db-content-api/utilities/data/index.d.ts +42 -0
- package/dist/db-content-api/utilities/data/index.js +211 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +12 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +54 -0
- package/dist/db-content-api/utilities/data/stripFields.d.ts +48 -0
- package/dist/db-content-api/utilities/data/stripFields.js +195 -0
- package/dist/db-content-api/utilities/data/transformPublishedLocale.d.ts +23 -0
- package/dist/db-content-api/utilities/data/transformPublishedLocale.js +42 -0
- package/dist/db-content-api/utilities/joins.d.ts +55 -0
- package/dist/db-content-api/utilities/joins.js +136 -0
- package/dist/db-content-api/utilities/locale/index.d.ts +10 -0
- package/dist/db-content-api/utilities/locale/index.js +21 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +11 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +66 -0
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts +37 -0
- package/dist/db-content-api/utilities/meta/buildMeta.js +33 -0
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +13 -0
- package/dist/db-content-api/utilities/meta/buildPathTypes.js +181 -0
- package/dist/db-content-api/utilities/where.d.ts +20 -0
- package/dist/db-content-api/utilities/where.js +127 -0
- package/dist/endpoints/health.d.ts +3 -0
- package/dist/endpoints/health.js +11 -0
- package/dist/endpoints/schema.d.ts +3 -0
- package/dist/endpoints/schema.js +29 -0
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.js +3 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/oauth/components/FigmaAvatar/index.d.ts +4 -0
- package/dist/oauth/components/FigmaAvatar/index.js +27 -0
- package/dist/oauth/components/FigmaAvatar/index.scss +12 -0
- package/dist/oauth/components/FigmaAvatarCell/index.d.ts +5 -0
- package/dist/oauth/components/FigmaAvatarCell/index.js +25 -0
- package/dist/oauth/components/FigmaAvatarCell/index.scss +5 -0
- package/dist/oauth/components/FigmaAvatarPlaceholder/index.d.ts +9 -0
- package/dist/oauth/components/FigmaAvatarPlaceholder/index.js +37 -0
- package/dist/oauth/components/FigmaAvatarPlaceholder/index.scss +28 -0
- package/dist/oauth/components/LoginButton/index.js +50 -6
- package/dist/oauth/components/LoginButton/index.scss +50 -3
- package/dist/oauth/components/LogoutButton/index.js +5 -4
- package/dist/oauth/defaults.js +67 -10
- package/dist/oauth/endpoints/getLoginEndpoint.js +69 -24
- package/dist/oauth/endpoints/getLogoutEndpoint.js +7 -4
- package/dist/oauth/index.js +40 -5
- package/dist/oauth/strategy/index.d.ts +0 -2
- package/dist/oauth/strategy/index.js +40 -17
- package/dist/oauth/types.d.ts +6 -6
- package/dist/oauth/utilities/isDuplicateKeyError.d.ts +7 -0
- package/dist/oauth/utilities/isDuplicateKeyError.js +14 -0
- package/dist/oauth/utilities/refreshTokens.js +3 -3
- package/dist/plugin/build-config.d.ts +21 -14
- package/dist/plugin/build-config.js +208 -17
- package/dist/storage-content-api/api-types.d.ts +168 -0
- package/dist/storage-content-api/api-types.js +6 -0
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts +9 -0
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.js +42 -0
- package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts +13 -0
- package/dist/storage-content-api/client-uploads/generateSignedURL.js +39 -0
- package/dist/storage-content-api/client.d.ts +6 -0
- package/dist/storage-content-api/client.js +36 -0
- package/dist/storage-content-api/generateURL.d.ts +7 -0
- package/dist/storage-content-api/generateURL.js +8 -0
- package/dist/storage-content-api/handleDelete.d.ts +8 -0
- package/dist/storage-content-api/handleDelete.js +17 -0
- package/dist/storage-content-api/handleUpload.d.ts +11 -0
- package/dist/storage-content-api/handleUpload.js +144 -0
- package/dist/storage-content-api/index.d.ts +5 -0
- package/dist/storage-content-api/index.js +31 -0
- package/dist/storage-content-api/staticHandler.d.ts +10 -0
- package/dist/storage-content-api/staticHandler.js +56 -0
- package/dist/storage-content-api/types.d.ts +10 -0
- package/dist/storage-content-api/types.js +3 -0
- package/dist/storage-content-api/utilities/getSafeFilename.d.ts +12 -0
- package/dist/storage-content-api/utilities/getSafeFilename.js +61 -0
- package/dist/storage-content-api/utilities/index.d.ts +2 -0
- package/dist/storage-content-api/utilities/index.js +3 -0
- package/dist/templates/.env.example +5 -0
- package/dist/templates/README.md +19 -0
- package/dist/types/config.d.ts +2 -1
- package/dist/types/config.js +0 -2
- package/dist/types.d.ts +3 -1
- package/dist/utils/asset-collection.d.ts +3 -6
- package/dist/utils/asset-collection.js +10 -34
- package/dist/utils/build-lambda-zip.d.ts +14 -0
- package/dist/utils/build-lambda-zip.js +81 -0
- package/dist/utils/cache-bootstrap.d.ts +8 -0
- package/dist/utils/cache-bootstrap.js +18 -0
- package/dist/utils/config.js +1 -1
- package/dist/utils/env-management.d.ts +16 -7
- package/dist/utils/env-management.js +85 -64
- package/dist/utils/format-env-suffix.d.ts +12 -0
- package/dist/utils/format-env-suffix.js +13 -0
- package/dist/utils/formatter.js +3 -5
- package/dist/utils/lambda-config.d.ts +3 -1
- package/dist/utils/lambda-config.js +38 -32
- package/dist/utils/messages.d.ts +1 -1
- package/dist/utils/messages.js +22 -8
- package/dist/utils/package-manager.d.ts +24 -0
- package/dist/utils/package-manager.js +53 -0
- package/dist/utils/payload-config-ast.d.ts +22 -3
- package/dist/utils/payload-config-ast.js +96 -31
- package/dist/utils/payload-config-finder.d.ts +2 -2
- package/dist/utils/payload-config-finder.js +48 -9
- package/dist/utils/payload-config-modifier.d.ts +1 -1
- package/dist/utils/payload-config-modifier.js +58 -9
- package/dist/utils/payload-package-check.d.ts +12 -1
- package/dist/utils/payload-package-check.js +63 -5
- package/dist/utils/project.d.ts +3 -2
- package/dist/utils/project.js +15 -7
- package/dist/utils/resolve-environment.d.ts +14 -0
- package/dist/utils/resolve-environment.js +28 -0
- package/dist/utils/s3-upload.d.ts +0 -1
- package/dist/utils/s3-upload.js +10 -3
- package/dist/utils/token-display.js +11 -5
- package/dist/utils/typescript-validator.js +4 -6
- package/dist/utils/version-check.d.ts +3 -0
- package/dist/utils/version-check.js +38 -0
- package/package.json +29 -10
- package/dist/api/control-plane.d.ts.map +0 -1
- package/dist/api/control-plane.js.map +0 -1
- package/dist/api/figma-api.d.ts.map +0 -1
- package/dist/api/figma-api.js.map +0 -1
- package/dist/auth/browser.d.ts.map +0 -1
- package/dist/auth/browser.js.map +0 -1
- package/dist/auth/callback-server.d.ts.map +0 -1
- package/dist/auth/callback-server.js.map +0 -1
- package/dist/auth/crypto-utils.d.ts.map +0 -1
- package/dist/auth/crypto-utils.js.map +0 -1
- package/dist/auth/jwt-validator.d.ts.map +0 -1
- package/dist/auth/jwt-validator.js.map +0 -1
- package/dist/auth/oauth-flow.d.ts.map +0 -1
- package/dist/auth/oauth-flow.js.map +0 -1
- package/dist/auth/pkce.d.ts.map +0 -1
- package/dist/auth/pkce.js.map +0 -1
- package/dist/auth/project-token.d.ts.map +0 -1
- package/dist/auth/project-token.js.map +0 -1
- package/dist/auth/refresh.d.ts.map +0 -1
- package/dist/auth/refresh.js.map +0 -1
- package/dist/auth/token-store.d.ts.map +0 -1
- package/dist/auth/token-store.js.map +0 -1
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/deploy.js.map +0 -1
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/list-tokens.d.ts.map +0 -1
- package/dist/commands/list-tokens.js.map +0 -1
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/logout.d.ts.map +0 -1
- package/dist/commands/logout.js.map +0 -1
- package/dist/config/oauth.d.ts.map +0 -1
- package/dist/config/oauth.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/exports/client.d.ts.map +0 -1
- package/dist/exports/client.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/oauth/components/LoginButton/index.d.ts.map +0 -1
- package/dist/oauth/components/LoginButton/index.js.map +0 -1
- package/dist/oauth/components/LogoutButton/index.d.ts.map +0 -1
- package/dist/oauth/components/LogoutButton/index.js.map +0 -1
- package/dist/oauth/defaults.d.ts.map +0 -1
- package/dist/oauth/defaults.js.map +0 -1
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +0 -1
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getLogoutEndpoint.js.map +0 -1
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getMetaEndpoint.js.map +0 -1
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +0 -1
- package/dist/oauth/exports/client.d.ts.map +0 -1
- package/dist/oauth/exports/client.js.map +0 -1
- package/dist/oauth/hooks/afterLogout.d.ts.map +0 -1
- package/dist/oauth/hooks/afterLogout.js.map +0 -1
- package/dist/oauth/hooks/me.d.ts.map +0 -1
- package/dist/oauth/hooks/me.js.map +0 -1
- package/dist/oauth/hooks/refresh.d.ts.map +0 -1
- package/dist/oauth/hooks/refresh.js.map +0 -1
- package/dist/oauth/index.d.ts.map +0 -1
- package/dist/oauth/index.js.map +0 -1
- package/dist/oauth/strategy/index.d.ts.map +0 -1
- package/dist/oauth/strategy/index.js.map +0 -1
- package/dist/oauth/types.d.ts.map +0 -1
- package/dist/oauth/types.js.map +0 -1
- package/dist/oauth/utilities/clearCookie.d.ts.map +0 -1
- package/dist/oauth/utilities/clearCookie.js.map +0 -1
- package/dist/oauth/utilities/createCookieOptions.d.ts.map +0 -1
- package/dist/oauth/utilities/createCookieOptions.js.map +0 -1
- package/dist/oauth/utilities/createDebugLogger.d.ts.map +0 -1
- package/dist/oauth/utilities/createDebugLogger.js.map +0 -1
- package/dist/oauth/utilities/extractOrigin.d.ts.map +0 -1
- package/dist/oauth/utilities/extractOrigin.js.map +0 -1
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +0 -1
- package/dist/oauth/utilities/getAdminCollectionSlug.js.map +0 -1
- package/dist/oauth/utilities/getAdminPath.d.ts +0 -8
- package/dist/oauth/utilities/getAdminPath.d.ts.map +0 -1
- package/dist/oauth/utilities/getAdminPath.js +0 -9
- package/dist/oauth/utilities/getAdminPath.js.map +0 -1
- package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +0 -1
- package/dist/oauth/utilities/getAuthorizeURL.js.map +0 -1
- package/dist/oauth/utilities/getCookieExpiration.d.ts.map +0 -1
- package/dist/oauth/utilities/getCookieExpiration.js.map +0 -1
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +0 -1
- package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +0 -1
- package/dist/oauth/utilities/getTokenExp.d.ts.map +0 -1
- package/dist/oauth/utilities/getTokenExp.js.map +0 -1
- package/dist/oauth/utilities/getUsernameField.d.ts.map +0 -1
- package/dist/oauth/utilities/getUsernameField.js.map +0 -1
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +0 -1
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +0 -1
- package/dist/oauth/utilities/mergeHeaders.d.ts.map +0 -1
- package/dist/oauth/utilities/mergeHeaders.js.map +0 -1
- package/dist/oauth/utilities/refreshTokens.d.ts.map +0 -1
- package/dist/oauth/utilities/refreshTokens.js.map +0 -1
- package/dist/plugin/adapter.d.ts.map +0 -1
- package/dist/plugin/adapter.js.map +0 -1
- package/dist/plugin/build-config.d.ts.map +0 -1
- package/dist/plugin/build-config.js.map +0 -1
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/config.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/asset-collection.d.ts.map +0 -1
- package/dist/utils/asset-collection.js.map +0 -1
- package/dist/utils/build-detection.d.ts.map +0 -1
- package/dist/utils/build-detection.js.map +0 -1
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/download-template.d.ts.map +0 -1
- package/dist/utils/download-template.js.map +0 -1
- package/dist/utils/env-management.d.ts.map +0 -1
- package/dist/utils/env-management.js.map +0 -1
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js.map +0 -1
- package/dist/utils/formatter.d.ts.map +0 -1
- package/dist/utils/formatter.js.map +0 -1
- package/dist/utils/git.d.ts.map +0 -1
- package/dist/utils/git.js.map +0 -1
- package/dist/utils/is-debug.d.ts.map +0 -1
- package/dist/utils/is-debug.js.map +0 -1
- package/dist/utils/lambda-config.d.ts.map +0 -1
- package/dist/utils/lambda-config.js.map +0 -1
- package/dist/utils/log.d.ts.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/messages.d.ts.map +0 -1
- package/dist/utils/messages.js.map +0 -1
- package/dist/utils/package-manager.d.ts.map +0 -1
- package/dist/utils/package-manager.js.map +0 -1
- package/dist/utils/payload-config-ast.d.ts.map +0 -1
- package/dist/utils/payload-config-ast.js.map +0 -1
- package/dist/utils/payload-config-finder.d.ts.map +0 -1
- package/dist/utils/payload-config-finder.js.map +0 -1
- package/dist/utils/payload-config-modifier.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.js.map +0 -1
- package/dist/utils/payload-package-check.d.ts.map +0 -1
- package/dist/utils/payload-package-check.js.map +0 -1
- package/dist/utils/project.d.ts.map +0 -1
- package/dist/utils/project.js.map +0 -1
- package/dist/utils/s3-upload.d.ts.map +0 -1
- package/dist/utils/s3-upload.js.map +0 -1
- package/dist/utils/token-display.d.ts.map +0 -1
- package/dist/utils/token-display.js.map +0 -1
- package/dist/utils/typescript-validator.d.ts.map +0 -1
- package/dist/utils/typescript-validator.js.map +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Add fallback sort to ensure consistent ordering when sorting by non-unique fields
|
|
2
|
+
// Matches MongoDB adapter behavior
|
|
3
|
+
// TO-DECIDE: Should this live here or in content-api?
|
|
4
|
+
export function addFallbackSort(sort, payload, collectionSlug) {
|
|
5
|
+
const collectionConfig = payload.config.collections.find((c)=>c.slug === collectionSlug);
|
|
6
|
+
if (!sort || !collectionConfig) {
|
|
7
|
+
return sort;
|
|
8
|
+
}
|
|
9
|
+
const sortArray = Array.isArray(sort) ? sort : [
|
|
10
|
+
sort
|
|
11
|
+
];
|
|
12
|
+
// Determine fallback sort field
|
|
13
|
+
let fallbackSort = '-id';
|
|
14
|
+
if (collectionConfig.timestamps !== false) {
|
|
15
|
+
fallbackSort = '-createdAt';
|
|
16
|
+
}
|
|
17
|
+
// Check if fallback sort is already included
|
|
18
|
+
const hasFallback = sortArray.some((item)=>item === fallbackSort || item === fallbackSort.replace('-', ''));
|
|
19
|
+
if (hasFallback) {
|
|
20
|
+
return sort;
|
|
21
|
+
}
|
|
22
|
+
// Check if all sort fields are unique (then no fallback needed)
|
|
23
|
+
// For simplicity, we'll always add fallback - checking uniqueness requires field traversal
|
|
24
|
+
// which would be expensive. This matches the conservative approach.
|
|
25
|
+
// Add fallback sort - always return array to preserve multiple sort fields
|
|
26
|
+
return [
|
|
27
|
+
...sortArray,
|
|
28
|
+
fallbackSort
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=sorting.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PathType can be either a simple string type or an object with additional metadata.
|
|
3
|
+
*
|
|
4
|
+
* Simple types: "array" - for array fields, blocks, or hasMany relationships/selects
|
|
5
|
+
*
|
|
6
|
+
* Relationship types include collection info needed for Content API to perform JOINs:
|
|
7
|
+
* - type: "relationship" for stored references, "join" for virtual reverse lookups
|
|
8
|
+
* - collection: target collection slug (or array for polymorphic)
|
|
9
|
+
* - hasMany: whether it stores multiple references
|
|
10
|
+
*
|
|
11
|
+
* TODO: This type is defined here temporarily so Content API can test the integration.
|
|
12
|
+
* Once Content API implements support for this, the type should be generated from openapi.json.
|
|
13
|
+
*/
|
|
14
|
+
export type PathTypeValue = 'array' | {
|
|
15
|
+
collection: string | string[];
|
|
16
|
+
hasMany?: boolean;
|
|
17
|
+
/** For join fields, the field path in the related collection that points back */
|
|
18
|
+
on?: string;
|
|
19
|
+
type: 'join' | 'relationship';
|
|
20
|
+
};
|
|
21
|
+
export type PathTypesRecord = Record<string, PathTypeValue>;
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PathType can be either a simple string type or an object with additional metadata.
|
|
3
|
+
*
|
|
4
|
+
* Simple types: "array" - for array fields, blocks, or hasMany relationships/selects
|
|
5
|
+
*
|
|
6
|
+
* Relationship types include collection info needed for Content API to perform JOINs:
|
|
7
|
+
* - type: "relationship" for stored references, "join" for virtual reverse lookups
|
|
8
|
+
* - collection: target collection slug (or array for polymorphic)
|
|
9
|
+
* - hasMany: whether it stores multiple references
|
|
10
|
+
*
|
|
11
|
+
* TODO: This type is defined here temporarily so Content API can test the integration.
|
|
12
|
+
* Once Content API implements support for this, the type should be generated from openapi.json.
|
|
13
|
+
*/ export { };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
|
+
import type { components } from '../generated/content-api-types.js';
|
|
3
|
+
type DocumentResponse = {
|
|
4
|
+
id: string;
|
|
5
|
+
} & components['schemas']['Document'];
|
|
6
|
+
type DocumentVersionResponse = {
|
|
7
|
+
id: string;
|
|
8
|
+
} & components['schemas']['DocumentVersion'];
|
|
9
|
+
export declare function unwrapDocument(payload: Payload, doc: DocumentResponse | DocumentVersionResponse, collectionSlug?: string): Record<string, unknown>;
|
|
10
|
+
export declare const unwrapFindResponse: (payload: Payload, response: components["schemas"]["FindDocumentsResponse"]["result"] | components["schemas"]["FindDocumentVersionsResponse"]["result"], collection: string) => {
|
|
11
|
+
totalDocs: number;
|
|
12
|
+
limit: number;
|
|
13
|
+
page: number;
|
|
14
|
+
totalPages: number;
|
|
15
|
+
pagingCounter: number;
|
|
16
|
+
hasPrevPage: boolean;
|
|
17
|
+
hasNextPage: boolean;
|
|
18
|
+
prevPage: number | null;
|
|
19
|
+
nextPage: number | null;
|
|
20
|
+
docs: Record<string, unknown>[];
|
|
21
|
+
} | {
|
|
22
|
+
totalDocs: number;
|
|
23
|
+
limit: number;
|
|
24
|
+
page: number;
|
|
25
|
+
totalPages: number;
|
|
26
|
+
pagingCounter: number;
|
|
27
|
+
hasPrevPage: boolean;
|
|
28
|
+
hasNextPage: boolean;
|
|
29
|
+
prevPage: number | null;
|
|
30
|
+
nextPage: number | null;
|
|
31
|
+
docs: Record<string, unknown>[];
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=unwrapDocument.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { dataFromContentAPI } from '../utilities/data/index.js';
|
|
2
|
+
// Helper to unwrap Content API document format to Payload format
|
|
3
|
+
// Content API returns:
|
|
4
|
+
// - For documents: { id, contentSystemId, collection, doc: { ...fields, createdAt, updatedAt } }
|
|
5
|
+
// - For versions: { id, contentSystemId, collection, versionDoc: { id, createdAt, updatedAt, latest, parent, version: {...fields} } }
|
|
6
|
+
// Payload expects:
|
|
7
|
+
// - For documents: { id, ...fields, createdAt, updatedAt }
|
|
8
|
+
// - For versions: { id, parent, latest, version: { ...fields }, createdAt, updatedAt }
|
|
9
|
+
export function unwrapDocument(payload, doc, collectionSlug) {
|
|
10
|
+
if (!doc) {
|
|
11
|
+
return doc;
|
|
12
|
+
}
|
|
13
|
+
// Check if this is a DocumentVersion (has versionDoc field)
|
|
14
|
+
const isVersion = 'versionDoc' in doc;
|
|
15
|
+
if (isVersion) {
|
|
16
|
+
// For versions, Payload expects nested structure with 'version' field
|
|
17
|
+
const { versionDoc } = doc;
|
|
18
|
+
const baseDoc = {
|
|
19
|
+
...versionDoc
|
|
20
|
+
};
|
|
21
|
+
// Transform data from Content API format to Payload format
|
|
22
|
+
if (collectionSlug) {
|
|
23
|
+
// Only transform the nested 'version' field
|
|
24
|
+
baseDoc.version = dataFromContentAPI(payload, collectionSlug, baseDoc.version);
|
|
25
|
+
// Also convert version ID if collection uses numeric custom ID
|
|
26
|
+
const customIDType = payload.collections?.[collectionSlug]?.customIDType;
|
|
27
|
+
if (customIDType === 'number') {
|
|
28
|
+
baseDoc.id = Number(baseDoc.id);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return baseDoc;
|
|
32
|
+
}
|
|
33
|
+
// For regular documents, spread doc data at root level
|
|
34
|
+
const { id, doc: docData } = doc;
|
|
35
|
+
const baseDoc = {
|
|
36
|
+
...docData,
|
|
37
|
+
id
|
|
38
|
+
};
|
|
39
|
+
// Transform data from Content API format to Payload format
|
|
40
|
+
if (collectionSlug) {
|
|
41
|
+
return dataFromContentAPI(payload, collectionSlug, baseDoc);
|
|
42
|
+
}
|
|
43
|
+
return baseDoc;
|
|
44
|
+
}
|
|
45
|
+
export const unwrapFindResponse = (payload, response, collection)=>{
|
|
46
|
+
const { data, ...paginationFields } = response;
|
|
47
|
+
return {
|
|
48
|
+
docs: data.map((doc)=>unwrapDocument(payload, doc, collection)),
|
|
49
|
+
...paginationFields
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=unwrapDocument.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Middleware } from 'openapi-fetch';
|
|
2
|
+
import type { Payload } from 'payload';
|
|
3
|
+
import type { TokenStore } from '../../auth/token-store.js';
|
|
4
|
+
type ApiKeyAuth = {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
mode: 'apiKey';
|
|
7
|
+
};
|
|
8
|
+
type TokenStoreAuth = {
|
|
9
|
+
mode: 'tokenStore';
|
|
10
|
+
tokenStore: TokenStore;
|
|
11
|
+
};
|
|
12
|
+
type DevJwtAuth = {
|
|
13
|
+
mode: 'devJwt';
|
|
14
|
+
};
|
|
15
|
+
export type AuthMode = ApiKeyAuth | DevJwtAuth | TokenStoreAuth;
|
|
16
|
+
export declare function fetchDevJwt(url: string, contentSystemId: string): Promise<string>;
|
|
17
|
+
export declare function createAuthMiddleware(opts: {
|
|
18
|
+
auth: AuthMode;
|
|
19
|
+
contentSystemId: string;
|
|
20
|
+
logger: Payload['logger'];
|
|
21
|
+
url: string;
|
|
22
|
+
}): Middleware;
|
|
23
|
+
export declare function createErrorMiddleware(opts: {
|
|
24
|
+
auth: AuthMode;
|
|
25
|
+
contentSystemId: string;
|
|
26
|
+
logger: Payload['logger'];
|
|
27
|
+
url: string;
|
|
28
|
+
}): Middleware;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { getValidProjectToken } from '../../auth/project-token.js';
|
|
2
|
+
// Module-level cache for dev JWT tokens
|
|
3
|
+
const devJwtCache = new Map();
|
|
4
|
+
export async function fetchDevJwt(url, contentSystemId) {
|
|
5
|
+
const usesSuperUser = !contentSystemId || contentSystemId === 'test-system' || contentSystemId === '*';
|
|
6
|
+
const contentSystemIdForJWT = usesSuperUser ? '*' : contentSystemId;
|
|
7
|
+
const response = await fetch(`${url}/dev/jwt`, {
|
|
8
|
+
body: JSON.stringify({
|
|
9
|
+
content_system_id: contentSystemIdForJWT
|
|
10
|
+
}),
|
|
11
|
+
headers: {
|
|
12
|
+
'Content-Type': 'application/json'
|
|
13
|
+
},
|
|
14
|
+
method: 'POST'
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error(`Failed to get dev JWT: ${response.status} ${response.statusText}`);
|
|
18
|
+
}
|
|
19
|
+
const { token } = await response.json();
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
22
|
+
export function createAuthMiddleware(opts) {
|
|
23
|
+
return {
|
|
24
|
+
async onRequest ({ request }) {
|
|
25
|
+
if (opts.auth.mode === 'apiKey') {
|
|
26
|
+
request.headers.set('X-Api-Key', opts.auth.apiKey);
|
|
27
|
+
} else if (opts.auth.mode === 'tokenStore') {
|
|
28
|
+
const token = await getValidProjectToken(opts.auth.tokenStore, opts.contentSystemId);
|
|
29
|
+
if (!token) {
|
|
30
|
+
throw new Error('Authentication required. Run `npx @payloadcms/figma login` to authenticate.');
|
|
31
|
+
}
|
|
32
|
+
request.headers.set('Authorization', `Bearer ${token}`);
|
|
33
|
+
} else {
|
|
34
|
+
let token = devJwtCache.get(opts.contentSystemId);
|
|
35
|
+
if (!token) {
|
|
36
|
+
token = await fetchDevJwt(opts.url, opts.contentSystemId);
|
|
37
|
+
devJwtCache.set(opts.contentSystemId, token);
|
|
38
|
+
opts.logger.info(`Dev JWT acquired for content system: ${opts.contentSystemId}`);
|
|
39
|
+
}
|
|
40
|
+
request.headers.set('Authorization', `Bearer ${token}`);
|
|
41
|
+
}
|
|
42
|
+
return request;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function createErrorMiddleware(opts) {
|
|
47
|
+
return {
|
|
48
|
+
async onResponse ({ request, response }) {
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
// Handle 401 retry for dev JWT
|
|
51
|
+
if (response.status === 401 && opts.auth.mode === 'devJwt') {
|
|
52
|
+
const retryCount = parseInt(request.headers.get('X-Retry-Count') || '0', 10);
|
|
53
|
+
if (retryCount < 1) {
|
|
54
|
+
opts.logger.info('Dev JWT expired, refreshing...');
|
|
55
|
+
devJwtCache.delete(opts.contentSystemId);
|
|
56
|
+
const newToken = await fetchDevJwt(opts.url, opts.contentSystemId);
|
|
57
|
+
devJwtCache.set(opts.contentSystemId, newToken);
|
|
58
|
+
// duplex: 'half' is required for Node.js fetch with streaming body
|
|
59
|
+
const newRequest = new Request(request.url, {
|
|
60
|
+
body: request.body,
|
|
61
|
+
duplex: 'half',
|
|
62
|
+
headers: new Headers(request.headers),
|
|
63
|
+
method: request.method
|
|
64
|
+
});
|
|
65
|
+
newRequest.headers.set('X-Retry-Count', '1');
|
|
66
|
+
newRequest.headers.set('Authorization', `Bearer ${newToken}`);
|
|
67
|
+
return fetch(newRequest);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const text = await response.clone().text();
|
|
71
|
+
opts.logger.error({
|
|
72
|
+
msg: `HTTP ${response.status} from ${request.url}`,
|
|
73
|
+
response: text
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return response;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Field } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively apply static default values to data
|
|
4
|
+
* This handles defaults for nested structures (arrays, groups) which traverseFields doesn't handle
|
|
5
|
+
*/
|
|
6
|
+
export declare function applyDefaults(data: Record<string, unknown>, fields: Field[]): void;
|
|
7
|
+
//# sourceMappingURL=applyDefaults.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively apply static default values to data
|
|
3
|
+
* This handles defaults for nested structures (arrays, groups) which traverseFields doesn't handle
|
|
4
|
+
*/ export function applyDefaults(data, fields) {
|
|
5
|
+
for (const field of fields){
|
|
6
|
+
// Only process fields that affect data (have a name)
|
|
7
|
+
if (!('name' in field) || !field.name) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const value = data[field.name];
|
|
11
|
+
// Check if field has a default value (only for FieldAffectingData types)
|
|
12
|
+
const defaultValue = 'defaultValue' in field ? field.defaultValue : undefined;
|
|
13
|
+
const hasDefault = defaultValue !== undefined;
|
|
14
|
+
const isFunction = typeof defaultValue === 'function';
|
|
15
|
+
// Skip function defaults - they need req/user context
|
|
16
|
+
if (hasDefault && isFunction) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
// Apply default if value is undefined
|
|
20
|
+
if (hasDefault && value === undefined) {
|
|
21
|
+
let appliedDefault = typeof defaultValue === 'object' ? JSON.parse(JSON.stringify(defaultValue)) : defaultValue;
|
|
22
|
+
// Special handling for point fields: convert array [lng, lat] to GeoJSON format
|
|
23
|
+
if (field.type === 'point' && Array.isArray(appliedDefault) && appliedDefault.length === 2) {
|
|
24
|
+
appliedDefault = {
|
|
25
|
+
type: 'Point',
|
|
26
|
+
coordinates: appliedDefault
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
data[field.name] = appliedDefault;
|
|
30
|
+
}
|
|
31
|
+
// Recursively process nested structures
|
|
32
|
+
const currentValue = data[field.name];
|
|
33
|
+
if (field.type === 'array' && Array.isArray(currentValue) && 'fields' in field) {
|
|
34
|
+
// Apply defaults to each array element
|
|
35
|
+
for (const element of currentValue){
|
|
36
|
+
if (element && typeof element === 'object') {
|
|
37
|
+
applyDefaults(element, field.fields);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} else if (field.type === 'group' && currentValue && typeof currentValue === 'object') {
|
|
41
|
+
// Apply defaults to group fields
|
|
42
|
+
if ('fields' in field) {
|
|
43
|
+
applyDefaults(currentValue, field.fields);
|
|
44
|
+
}
|
|
45
|
+
} else if (field.type === 'blocks' && Array.isArray(currentValue) && 'blocks' in field) {
|
|
46
|
+
// Apply defaults to each block
|
|
47
|
+
for (const element of currentValue){
|
|
48
|
+
if (element && typeof element === 'object' && 'blockType' in element) {
|
|
49
|
+
const block = field.blocks.find((b)=>b.slug === element.blockType);
|
|
50
|
+
if (block?.fields) {
|
|
51
|
+
applyDefaults(element, block.fields);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=applyDefaults.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Field, TabAsField } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Cast field values to the appropriate type for Content API storage.
|
|
4
|
+
*
|
|
5
|
+
* This function implements type coercion similar to Mongoose (used by MongoDB adapter)
|
|
6
|
+
* to ensure data consistency. When users ignore TypeScript types and pass incorrect types,
|
|
7
|
+
* we automatically convert them to the expected type.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare function castFieldValue(field: Field | TabAsField, value: unknown): unknown;
|
|
11
|
+
//# sourceMappingURL=castFieldValue.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cast field values to the appropriate type for Content API storage.
|
|
3
|
+
*
|
|
4
|
+
* This function implements type coercion similar to Mongoose (used by MongoDB adapter)
|
|
5
|
+
* to ensure data consistency. When users ignore TypeScript types and pass incorrect types,
|
|
6
|
+
* we automatically convert them to the expected type.
|
|
7
|
+
*
|
|
8
|
+
*/ export function castFieldValue(field, value) {
|
|
9
|
+
if (value === null || value === undefined) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
if (field.type === 'number') {
|
|
13
|
+
// Handle hasMany: true - array of numbers
|
|
14
|
+
if ('hasMany' in field && field.hasMany && Array.isArray(value)) {
|
|
15
|
+
return value.map((item)=>{
|
|
16
|
+
if (typeof item === 'number') {
|
|
17
|
+
return item;
|
|
18
|
+
}
|
|
19
|
+
if (typeof item === 'string' || typeof item === 'boolean') {
|
|
20
|
+
return Number(item);
|
|
21
|
+
}
|
|
22
|
+
return item // Pass through other types (will likely fail validation)
|
|
23
|
+
;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
// Handle single number
|
|
27
|
+
if (typeof value !== 'number') {
|
|
28
|
+
if (typeof value === 'string' || typeof value === 'boolean') {
|
|
29
|
+
return Number(value);
|
|
30
|
+
}
|
|
31
|
+
// For objects/arrays (when not hasMany), return as-is (will likely fail validation later)
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (field.type === 'checkbox' && typeof value !== 'boolean') {
|
|
36
|
+
if (typeof value === 'string') {
|
|
37
|
+
if (value.toLowerCase() === 'true' || value === '1') {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (value.toLowerCase() === 'false' || value === '0' || value === '') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Boolean(value);
|
|
45
|
+
}
|
|
46
|
+
// Matches Mongoose behavior: stores dates as ISO strings
|
|
47
|
+
if (field.type === 'date' && typeof value !== 'string') {
|
|
48
|
+
if (value instanceof Date) {
|
|
49
|
+
return value.toISOString();
|
|
50
|
+
}
|
|
51
|
+
if (typeof value === 'number') {
|
|
52
|
+
return new Date(value).toISOString();
|
|
53
|
+
}
|
|
54
|
+
// For other types, return as-is (will likely fail validation)
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
// Text-like fields: convert non-strings to JSON strings
|
|
58
|
+
// This handles text, textarea, email, and code fields
|
|
59
|
+
// EXCEPTIONS:
|
|
60
|
+
// - Localized fields are stored as objects like {"en": "value", "es": "valor"}
|
|
61
|
+
// - hasMany fields are stored as arrays like ["value1", "value2"]
|
|
62
|
+
if ((field.type === 'text' || field.type === 'textarea' || field.type === 'email' || field.type === 'code') && typeof value !== 'string' && !('localized' in field && field.localized) && !('hasMany' in field && field.hasMany && Array.isArray(value))) {
|
|
63
|
+
return JSON.stringify(value);
|
|
64
|
+
}
|
|
65
|
+
// No casting needed for other types or already correct types
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=castFieldValue.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
|
+
import type { components } from '../../generated/content-api-types.js';
|
|
3
|
+
type DataWithOperations = components['schemas']['DataWithOperations'];
|
|
4
|
+
interface DataToContentAPIOptions {
|
|
5
|
+
/** Apply static defaults for undefined fields */
|
|
6
|
+
applyDefaults?: boolean;
|
|
7
|
+
/** Add createdAt timestamp */
|
|
8
|
+
createdAt?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Transform publishedLocale to localizeStatus format.
|
|
11
|
+
* When provided, converts `_status: 'published'` + `publishedLocale: 'en'`
|
|
12
|
+
* to `_status: { en: 'published' }` format.
|
|
13
|
+
*/
|
|
14
|
+
publishedLocale?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Transform data before sending to Content API (WRITE operations)
|
|
18
|
+
*
|
|
19
|
+
* Conversions applied:
|
|
20
|
+
* - Default values: Apply static defaults for undefined fields (when applyDefaults=true)
|
|
21
|
+
* - Type casting: Convert values to match field types (e.g., number -> string for text fields)
|
|
22
|
+
* - RichText fields: Objects -> JSON strings
|
|
23
|
+
* - Virtual fields: Remove fields with `virtual: true` (pure virtual fields should never be saved)
|
|
24
|
+
* - Timestamps: Add updatedAt (always), and createdAt (when createdAt=true)
|
|
25
|
+
* - publishedLocale: Transform to localizeStatus format (when publishedLocale is provided)
|
|
26
|
+
*
|
|
27
|
+
* Note: Date fields are automatically converted to ISO strings by JSON.stringify()
|
|
28
|
+
*/
|
|
29
|
+
export declare function dataToContentAPI(payload: Payload, collectionSlug: string, data: unknown, options?: DataToContentAPIOptions): DataWithOperations;
|
|
30
|
+
/**
|
|
31
|
+
* Transform data received from Content API (READ operations)
|
|
32
|
+
*
|
|
33
|
+
* Conversions applied:
|
|
34
|
+
* - RichText fields: JSON strings -> Objects
|
|
35
|
+
* - Virtual fields: Remove fields with `virtual: true` (should not be in DB but Content API backend may add them)
|
|
36
|
+
*
|
|
37
|
+
* Note: Date fields come as ISO strings from Content API and stay as strings
|
|
38
|
+
* (matching MongoDB and other adapters' behavior)
|
|
39
|
+
*/
|
|
40
|
+
export declare function dataFromContentAPI(payload: Payload, collectionSlug: string, data: unknown): unknown;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|