@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
|
@@ -1,26 +1,202 @@
|
|
|
1
|
+
import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
|
|
2
|
+
import { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
1
3
|
import { lexicalEditor } from '@payloadcms/richtext-lexical';
|
|
2
4
|
import { buildConfig as payloadBuildConfig } from 'payload';
|
|
5
|
+
import { getBootstrapInfo } from '../api/control-plane.js';
|
|
6
|
+
import { getValidAccessToken } from '../auth/oauth-flow.js';
|
|
7
|
+
import { getTokenStore } from '../auth/token-store.js';
|
|
8
|
+
import { getEnvConfig } from '../constants.js';
|
|
9
|
+
import { contentAPIAdapter } from '../db-content-api/index.js';
|
|
10
|
+
import { health } from '../endpoints/health.js';
|
|
11
|
+
import { schema } from '../endpoints/schema.js';
|
|
3
12
|
import { oAuth2Plugin } from '../oauth/index.js';
|
|
4
|
-
import {
|
|
13
|
+
import { createStorageClient } from '../storage-content-api/client.js';
|
|
14
|
+
import { getGenerateSignedURLHandler } from '../storage-content-api/client-uploads/generateSignedURL.js';
|
|
15
|
+
import { contentApiStorageAdapter } from '../storage-content-api/index.js';
|
|
16
|
+
import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
|
|
17
|
+
import * as log from '../utils/log.js';
|
|
5
18
|
/**
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
* Fields added to users collection for Figma profile info
|
|
20
|
+
*/ const figmaUserFields = [
|
|
21
|
+
{
|
|
22
|
+
name: 'figmaHandle',
|
|
23
|
+
type: 'text',
|
|
24
|
+
admin: {
|
|
25
|
+
readOnly: true
|
|
26
|
+
},
|
|
27
|
+
label: 'Name'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'figmaImageUrl',
|
|
31
|
+
type: 'text',
|
|
32
|
+
admin: {
|
|
33
|
+
components: {
|
|
34
|
+
Cell: '@payloadcms/figma/client#FigmaAvatarCell'
|
|
35
|
+
},
|
|
36
|
+
disableBulkEdit: true,
|
|
37
|
+
hidden: true,
|
|
38
|
+
readOnly: true
|
|
39
|
+
},
|
|
40
|
+
label: 'Profile Picture'
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
function missingOAuthCredential(name) {
|
|
44
|
+
log.warning(`${name} could not be resolved. OAuth login will not work until this is configured. ` + 'Run `npx @payloadcms/figma init` to set up your project.');
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fetch bootstrap data from the API and cache all environments locally.
|
|
49
|
+
* Returns the requested environment's data, or null if resolution fails.
|
|
50
|
+
*/ async function resolveAndCacheBootstrap(store, projectId, environmentName) {
|
|
51
|
+
try {
|
|
52
|
+
const accessToken = await getValidAccessToken(store);
|
|
53
|
+
if (!accessToken) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const bootstrapInfo = await getBootstrapInfo(accessToken, projectId);
|
|
57
|
+
cacheAllEnvironments(store, projectId, bootstrapInfo);
|
|
58
|
+
return store.getBootstrapData(projectId, environmentName);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
log.warning(`Failed to resolve bootstrap data: ${error instanceof Error ? error.message : 'Unknown error'}. ` + 'Try running `npx @payloadcms/figma login` to refresh authentication.');
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export async function buildFigmaConfig(config) {
|
|
65
|
+
const envConfig = getEnvConfig();
|
|
66
|
+
// Resolve contentSystemId: config first, then local store fallback (dev)
|
|
67
|
+
let { contentSystemId } = config.figma;
|
|
68
|
+
let bootstrapData = null;
|
|
69
|
+
if (!contentSystemId) {
|
|
70
|
+
const projectId = process.env.FIGMA_PROJECT_ID;
|
|
71
|
+
const environmentName = process.env.FIGMA_ENVIRONMENT_NAME;
|
|
72
|
+
if (projectId && environmentName) {
|
|
73
|
+
const store = getTokenStore();
|
|
74
|
+
bootstrapData = store.getBootstrapData(projectId, environmentName);
|
|
75
|
+
// Runtime fallback: fetch from API if not cached (e.g. environment switch without re-init)
|
|
76
|
+
if (!bootstrapData) {
|
|
77
|
+
bootstrapData = await resolveAndCacheBootstrap(store, projectId, environmentName);
|
|
78
|
+
}
|
|
79
|
+
if (bootstrapData) {
|
|
80
|
+
contentSystemId = bootstrapData.contentSystemId;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!contentSystemId) {
|
|
85
|
+
throw new Error('Content System ID could not be resolved. ' + 'Run `npx @payloadcms/figma init` to set up your project.');
|
|
86
|
+
}
|
|
87
|
+
const url = process.env.FIGMA_CONTENT_API_URL || envConfig.contentApiUrl;
|
|
88
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
89
|
+
// Determine database adapter based on environment
|
|
90
|
+
let db;
|
|
91
|
+
if (config.figma.useContentSystem === false) {
|
|
92
|
+
db = config.db;
|
|
93
|
+
} else if (process.env.FIGMA_CONTENT_API_ACCESS_KEY) {
|
|
94
|
+
db = contentAPIAdapter({
|
|
95
|
+
auth: {
|
|
96
|
+
apiKey: process.env.FIGMA_CONTENT_API_ACCESS_KEY,
|
|
97
|
+
mode: 'apiKey'
|
|
98
|
+
},
|
|
99
|
+
contentSystemId,
|
|
100
|
+
url
|
|
101
|
+
});
|
|
102
|
+
} else if (process.env.FIGMA_DEV_JWT === 'true') {
|
|
103
|
+
db = contentAPIAdapter({
|
|
104
|
+
auth: {
|
|
105
|
+
mode: 'devJwt'
|
|
106
|
+
},
|
|
107
|
+
contentSystemId,
|
|
108
|
+
url
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
db = contentAPIAdapter({
|
|
112
|
+
auth: {
|
|
113
|
+
mode: 'tokenStore',
|
|
114
|
+
tokenStore: getTokenStore()
|
|
115
|
+
},
|
|
116
|
+
contentSystemId,
|
|
117
|
+
url
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Build storage plugin if there are upload collections and storage is not disabled
|
|
121
|
+
const uploadCollections = (config.collections || []).filter((c)=>c.upload);
|
|
122
|
+
let storagePlugin;
|
|
123
|
+
if (uploadCollections.length > 0 && config.figma.storage !== false) {
|
|
124
|
+
const storageConfig = process.env.FIGMA_CONTENT_API_ACCESS_KEY ? {
|
|
125
|
+
baseUrl: url,
|
|
126
|
+
contentApiKey: process.env.FIGMA_CONTENT_API_ACCESS_KEY
|
|
127
|
+
} : process.env.FIGMA_DEV_JWT === 'true' ? {
|
|
128
|
+
auth: {
|
|
129
|
+
mode: 'devJwt'
|
|
130
|
+
},
|
|
131
|
+
baseUrl: url,
|
|
132
|
+
contentSystemId
|
|
133
|
+
} : {
|
|
134
|
+
auth: {
|
|
135
|
+
mode: 'tokenStore',
|
|
136
|
+
tokenStore: getTokenStore()
|
|
137
|
+
},
|
|
138
|
+
baseUrl: url,
|
|
139
|
+
contentSystemId
|
|
140
|
+
};
|
|
141
|
+
const adapter = contentApiStorageAdapter(storageConfig);
|
|
142
|
+
const storageClient = createStorageClient(storageConfig);
|
|
143
|
+
const collectionsMap = uploadCollections.reduce((acc, c)=>{
|
|
144
|
+
acc[c.slug] = {
|
|
145
|
+
adapter,
|
|
146
|
+
disableLocalStorage: true
|
|
147
|
+
};
|
|
148
|
+
return acc;
|
|
149
|
+
}, {});
|
|
150
|
+
initClientUploads({
|
|
151
|
+
clientHandler: '@payloadcms/figma/client#ContentApiClientUploadHandler',
|
|
152
|
+
collections: collectionsMap,
|
|
153
|
+
config: config,
|
|
154
|
+
enabled: true,
|
|
155
|
+
serverHandler: getGenerateSignedURLHandler({
|
|
156
|
+
client: storageClient
|
|
157
|
+
}),
|
|
158
|
+
serverHandlerPath: '/content-api-storage-signed-url'
|
|
159
|
+
});
|
|
160
|
+
storagePlugin = cloudStoragePlugin({
|
|
161
|
+
collections: collectionsMap
|
|
162
|
+
});
|
|
163
|
+
}
|
|
15
164
|
// Build complete config with Figma platform defaults
|
|
16
165
|
const configWithFigmaDefaults = {
|
|
17
166
|
...config,
|
|
18
|
-
|
|
167
|
+
admin: {
|
|
168
|
+
// Auto-refresh tokens before expiry to prevent unexpected logouts.
|
|
169
|
+
autoRefresh: true,
|
|
170
|
+
avatar: {
|
|
171
|
+
Component: '@payloadcms/figma/client#FigmaAvatar'
|
|
172
|
+
},
|
|
173
|
+
...config.admin
|
|
174
|
+
},
|
|
175
|
+
custom: {
|
|
176
|
+
figma: {
|
|
177
|
+
...config.figma,
|
|
178
|
+
contentSystemId
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
db,
|
|
19
182
|
editor: config.editor ?? lexicalEditor(),
|
|
183
|
+
endpoints: [
|
|
184
|
+
...config.endpoints ?? [],
|
|
185
|
+
health,
|
|
186
|
+
schema
|
|
187
|
+
],
|
|
188
|
+
...isProduction && !config.logger ? {
|
|
189
|
+
logger: {
|
|
190
|
+
options: {}
|
|
191
|
+
}
|
|
192
|
+
} : {},
|
|
20
193
|
secret: 'MY_SECRET',
|
|
21
194
|
// Add oauth to plugins if not already present
|
|
22
195
|
plugins: [
|
|
23
196
|
...config.plugins ?? [],
|
|
197
|
+
...storagePlugin ? [
|
|
198
|
+
storagePlugin
|
|
199
|
+
] : [],
|
|
24
200
|
oAuth2Plugin({
|
|
25
201
|
collections: [
|
|
26
202
|
{
|
|
@@ -30,9 +206,9 @@ import { figmaContentSystem } from './adapter.js';
|
|
|
30
206
|
response_mode: 'query',
|
|
31
207
|
response_type: 'code'
|
|
32
208
|
},
|
|
33
|
-
clientID: process.env.FIGMA_OAUTH_CLIENT_ID,
|
|
34
|
-
clientSecret: process.env.FIGMA_OAUTH_CLIENT_SECRET,
|
|
35
|
-
identityMetadata:
|
|
209
|
+
clientID: process.env.FIGMA_OAUTH_CLIENT_ID ?? bootstrapData?.oauthClientId ?? missingOAuthCredential('FIGMA_OAUTH_CLIENT_ID'),
|
|
210
|
+
clientSecret: process.env.FIGMA_OAUTH_CLIENT_SECRET ?? bootstrapData?.oauthClientSecret,
|
|
211
|
+
identityMetadata: envConfig.identityMetadata,
|
|
36
212
|
scope: [
|
|
37
213
|
'current_user:read'
|
|
38
214
|
],
|
|
@@ -40,12 +216,27 @@ import { figmaContentSystem } from './adapter.js';
|
|
|
40
216
|
usernameField: 'email'
|
|
41
217
|
}
|
|
42
218
|
],
|
|
43
|
-
debug:
|
|
44
|
-
disabled: false
|
|
45
|
-
redirectServerURL: 'http://localhost:3000'
|
|
219
|
+
debug: !!process.env.DEBUG,
|
|
220
|
+
disabled: false
|
|
46
221
|
})
|
|
47
222
|
]
|
|
48
223
|
};
|
|
224
|
+
// Inject figma fields into users collection
|
|
225
|
+
const collections = configWithFigmaDefaults.collections?.map((col)=>{
|
|
226
|
+
if (col.slug === 'users') {
|
|
227
|
+
return {
|
|
228
|
+
...col,
|
|
229
|
+
fields: [
|
|
230
|
+
...col.fields || [],
|
|
231
|
+
...figmaUserFields
|
|
232
|
+
]
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return col;
|
|
236
|
+
});
|
|
237
|
+
if (collections) {
|
|
238
|
+
configWithFigmaDefaults.collections = collections;
|
|
239
|
+
}
|
|
49
240
|
// Delegate to Payload's buildConfig
|
|
50
241
|
return await payloadBuildConfig(configWithFigmaDefaults);
|
|
51
242
|
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upload API types extracted from Content API OpenAPI spec.
|
|
3
|
+
* These are kept separate to avoid breaking changes when the main spec is regenerated.
|
|
4
|
+
*/
|
|
5
|
+
export type UploadPaths = {
|
|
6
|
+
'/api/v0/uploads/{collectionId}/{filename}': {
|
|
7
|
+
delete: {
|
|
8
|
+
parameters: {
|
|
9
|
+
path: {
|
|
10
|
+
collectionId: string;
|
|
11
|
+
filename: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
responses: {
|
|
15
|
+
200: {
|
|
16
|
+
content: {
|
|
17
|
+
'application/json': {
|
|
18
|
+
success: true;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
'/api/v0/uploads/download/sign': {
|
|
26
|
+
post: {
|
|
27
|
+
requestBody: {
|
|
28
|
+
content: {
|
|
29
|
+
'application/json': {
|
|
30
|
+
collectionId: string;
|
|
31
|
+
expiresIn: number;
|
|
32
|
+
filename: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
responses: {
|
|
37
|
+
200: {
|
|
38
|
+
content: {
|
|
39
|
+
'application/json': {
|
|
40
|
+
url: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
'/api/v0/uploads/multipart/abort': {
|
|
48
|
+
post: {
|
|
49
|
+
requestBody: {
|
|
50
|
+
content: {
|
|
51
|
+
'application/json': {
|
|
52
|
+
collectionId: string;
|
|
53
|
+
filename: string;
|
|
54
|
+
uploadId: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
responses: {
|
|
59
|
+
200: {
|
|
60
|
+
content: {
|
|
61
|
+
'application/json': {
|
|
62
|
+
success: true;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
'/api/v0/uploads/multipart/complete': {
|
|
70
|
+
post: {
|
|
71
|
+
requestBody: {
|
|
72
|
+
content: {
|
|
73
|
+
'application/json': {
|
|
74
|
+
collectionId: string;
|
|
75
|
+
filename: string;
|
|
76
|
+
parts: Array<{
|
|
77
|
+
ETag: string;
|
|
78
|
+
PartNumber: number;
|
|
79
|
+
}>;
|
|
80
|
+
uploadId: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
responses: {
|
|
85
|
+
200: {
|
|
86
|
+
content: {
|
|
87
|
+
'application/json': {
|
|
88
|
+
success: true;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
'/api/v0/uploads/multipart/initiate': {
|
|
96
|
+
post: {
|
|
97
|
+
requestBody: {
|
|
98
|
+
content: {
|
|
99
|
+
'application/json': {
|
|
100
|
+
collectionId: string;
|
|
101
|
+
contentType: string;
|
|
102
|
+
filename: string;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
responses: {
|
|
107
|
+
200: {
|
|
108
|
+
content: {
|
|
109
|
+
'application/json': {
|
|
110
|
+
uploadId: string;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
'/api/v0/uploads/multipart/parts': {
|
|
118
|
+
post: {
|
|
119
|
+
requestBody: {
|
|
120
|
+
content: {
|
|
121
|
+
'application/json': {
|
|
122
|
+
collectionId: string;
|
|
123
|
+
expiresIn: number;
|
|
124
|
+
filename: string;
|
|
125
|
+
partNumbers: number[];
|
|
126
|
+
uploadId: string;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
responses: {
|
|
131
|
+
200: {
|
|
132
|
+
content: {
|
|
133
|
+
'application/json': {
|
|
134
|
+
parts: Array<{
|
|
135
|
+
partNumber: number;
|
|
136
|
+
url: string;
|
|
137
|
+
}>;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
'/api/v0/uploads/sign': {
|
|
145
|
+
post: {
|
|
146
|
+
requestBody: {
|
|
147
|
+
content: {
|
|
148
|
+
'application/json': {
|
|
149
|
+
collectionId: string;
|
|
150
|
+
contentType?: string;
|
|
151
|
+
expiresIn: number;
|
|
152
|
+
filename: string;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
responses: {
|
|
157
|
+
200: {
|
|
158
|
+
content: {
|
|
159
|
+
'application/json': {
|
|
160
|
+
url: string;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=api-types.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const ContentApiClientUploadHandler: ({ children, collectionSlug, enabled, extra, prefix, serverHandlerPath, }: {
|
|
2
|
+
children: import("react").ReactNode;
|
|
3
|
+
collectionSlug: import("payload").UploadCollectionSlug;
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
extra: Record<string, unknown>;
|
|
6
|
+
prefix?: string;
|
|
7
|
+
serverHandlerPath: `/${string}`;
|
|
8
|
+
}) => import("react").JSX.Element;
|
|
9
|
+
//# sourceMappingURL=ClientUploadHandler.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client';
|
|
3
|
+
export const ContentApiClientUploadHandler = createClientUploadHandler({
|
|
4
|
+
handler: async ({ apiRoute, collectionSlug, file, prefix, serverHandlerPath, serverURL })=>{
|
|
5
|
+
// Build endpoint URL: serverURL + apiRoute + serverHandlerPath
|
|
6
|
+
const endpointRoute = `${serverURL}${apiRoute}${serverHandlerPath}`;
|
|
7
|
+
const response = await fetch(endpointRoute, {
|
|
8
|
+
body: JSON.stringify({
|
|
9
|
+
collectionSlug,
|
|
10
|
+
filename: file.name,
|
|
11
|
+
mimeType: file.type
|
|
12
|
+
}),
|
|
13
|
+
credentials: 'include',
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json'
|
|
16
|
+
},
|
|
17
|
+
method: 'POST'
|
|
18
|
+
});
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
throw new Error(`Failed to get presigned URL: ${response.status} ${response.statusText}`);
|
|
21
|
+
}
|
|
22
|
+
const { filename: safeFilename, url } = await response.json();
|
|
23
|
+
const uploadFilename = safeFilename || file.name;
|
|
24
|
+
const uploadResponse = await fetch(url, {
|
|
25
|
+
body: file,
|
|
26
|
+
headers: {
|
|
27
|
+
'Content-Type': file.type
|
|
28
|
+
},
|
|
29
|
+
method: 'PUT'
|
|
30
|
+
});
|
|
31
|
+
if (!uploadResponse.ok) {
|
|
32
|
+
throw new Error(`Failed to upload to S3: ${uploadResponse.status} ${uploadResponse.statusText}`);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
clientUploaded: true,
|
|
36
|
+
filename: uploadFilename,
|
|
37
|
+
prefix
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=ClientUploadHandler.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PayloadHandler } from 'payload';
|
|
2
|
+
import type { StorageClient } from '../client.js';
|
|
3
|
+
type ClientUploadsAccess = (args: {
|
|
4
|
+
collectionSlug: string;
|
|
5
|
+
req: Parameters<PayloadHandler>[0];
|
|
6
|
+
}) => boolean | Promise<boolean>;
|
|
7
|
+
type Args = {
|
|
8
|
+
access?: ClientUploadsAccess;
|
|
9
|
+
client: StorageClient;
|
|
10
|
+
};
|
|
11
|
+
export declare const getGenerateSignedURLHandler: ({ access, client, }: Args) => PayloadHandler;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=generateSignedURL.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { APIError, Forbidden } from 'payload';
|
|
2
|
+
import { getSafeFilename } from '../utilities/index.js';
|
|
3
|
+
const defaultAccess = ({ req })=>!!req.user;
|
|
4
|
+
export const getGenerateSignedURLHandler = ({ access = defaultAccess, client })=>{
|
|
5
|
+
return async (req)=>{
|
|
6
|
+
if (!req.json) {
|
|
7
|
+
throw new APIError('Content-Type expected to be application/json', 400);
|
|
8
|
+
}
|
|
9
|
+
const { collectionSlug, filename, mimeType } = await req.json();
|
|
10
|
+
if (!await access({
|
|
11
|
+
collectionSlug,
|
|
12
|
+
req
|
|
13
|
+
})) {
|
|
14
|
+
throw new Forbidden();
|
|
15
|
+
}
|
|
16
|
+
const safeFilename = await getSafeFilename({
|
|
17
|
+
collectionSlug,
|
|
18
|
+
desiredFilename: filename,
|
|
19
|
+
req
|
|
20
|
+
});
|
|
21
|
+
const { data, error } = await client.POST('/api/v0/uploads/sign', {
|
|
22
|
+
body: {
|
|
23
|
+
collectionId: collectionSlug,
|
|
24
|
+
contentType: mimeType,
|
|
25
|
+
expiresIn: 3600,
|
|
26
|
+
filename: safeFilename
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
if (error || !data) {
|
|
30
|
+
throw new APIError(`Failed to get presigned upload URL: ${JSON.stringify(error)}`);
|
|
31
|
+
}
|
|
32
|
+
return Response.json({
|
|
33
|
+
filename: safeFilename,
|
|
34
|
+
url: data.url
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=generateSignedURL.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import createClient from 'openapi-fetch';
|
|
2
|
+
import type { UploadPaths } from './api-types.js';
|
|
3
|
+
import type { StorageClientConfig } from './types.js';
|
|
4
|
+
export type StorageClient = ReturnType<typeof createClient<UploadPaths>>;
|
|
5
|
+
export declare function createStorageClient(config: StorageClientConfig): StorageClient;
|
|
6
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import createClient from 'openapi-fetch';
|
|
2
|
+
import { getValidProjectToken } from '../auth/project-token.js';
|
|
3
|
+
import { fetchDevJwt } from '../db-content-api/utilities/auth.js';
|
|
4
|
+
export function createStorageClient(config) {
|
|
5
|
+
const client = createClient({
|
|
6
|
+
baseUrl: config.baseUrl
|
|
7
|
+
});
|
|
8
|
+
client.use(createStorageAuthMiddleware(config));
|
|
9
|
+
return client;
|
|
10
|
+
}
|
|
11
|
+
function createStorageAuthMiddleware(config) {
|
|
12
|
+
return {
|
|
13
|
+
async onRequest ({ request }) {
|
|
14
|
+
if ('contentApiKey' in config) {
|
|
15
|
+
request.headers.set('X-Api-Key', config.contentApiKey);
|
|
16
|
+
} else {
|
|
17
|
+
const { auth, contentSystemId } = config;
|
|
18
|
+
if (auth.mode === 'apiKey') {
|
|
19
|
+
request.headers.set('X-Api-Key', auth.apiKey);
|
|
20
|
+
} else if (auth.mode === 'tokenStore') {
|
|
21
|
+
const token = await getValidProjectToken(auth.tokenStore, contentSystemId);
|
|
22
|
+
if (!token) {
|
|
23
|
+
throw new Error('Authentication required. Run `npx @payloadcms/figma login` to authenticate.');
|
|
24
|
+
}
|
|
25
|
+
request.headers.set('Authorization', `Bearer ${token}`);
|
|
26
|
+
} else {
|
|
27
|
+
const token = await fetchDevJwt(config.baseUrl, contentSystemId);
|
|
28
|
+
request.headers.set('Authorization', `Bearer ${token}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return request;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
export const getGenerateURL = ({ baseUrl })=>({ collection, filename, prefix = '' })=>{
|
|
3
|
+
const collectionId = collection.slug;
|
|
4
|
+
const fileKey = path.posix.join(prefix, filename);
|
|
5
|
+
return `${baseUrl}/api/v0/uploads/download/${collectionId}/${encodeURIComponent(fileKey)}`;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=generateURL.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
import type { StorageClient } from './client.js';
|
|
3
|
+
type Args = {
|
|
4
|
+
client: StorageClient;
|
|
5
|
+
};
|
|
6
|
+
export declare const getHandleDelete: ({ client }: Args) => HandleDelete;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=handleDelete.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
export const getHandleDelete = ({ client })=>{
|
|
3
|
+
return async ({ collection, doc: { prefix = '' }, filename })=>{
|
|
4
|
+
const collectionId = collection.slug;
|
|
5
|
+
const fileKey = path.posix.join(prefix, filename);
|
|
6
|
+
await client.DELETE('/api/v0/uploads/{collectionId}/{filename}', {
|
|
7
|
+
params: {
|
|
8
|
+
path: {
|
|
9
|
+
collectionId,
|
|
10
|
+
filename: fileKey
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=handleDelete.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
import type { CollectionConfig } from 'payload';
|
|
3
|
+
import type { StorageClient } from './client.js';
|
|
4
|
+
type Args = {
|
|
5
|
+
client: StorageClient;
|
|
6
|
+
collection: CollectionConfig;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const getHandleUpload: ({ client, collection, prefix }: Args) => HandleUpload;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=handleUpload.d.ts.map
|