@payloadcms/figma 0.0.1-alpha.5 → 0.0.1-alpha.51
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 +61 -10
- 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 +29 -15
- 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
package/dist/commands/init.js
CHANGED
|
@@ -2,30 +2,39 @@ import * as p from '@clack/prompts';
|
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import pc from 'picocolors';
|
|
5
|
-
import { ControlPlaneError,
|
|
5
|
+
import { ControlPlaneError, getBootstrapInfo } from '../api/control-plane.js';
|
|
6
6
|
import { FigmaApiError } from '../api/figma-api.js';
|
|
7
7
|
import { getValidAccessToken } from '../auth/oauth-flow.js';
|
|
8
8
|
import { getValidProjectToken, ProjectTokenError } from '../auth/project-token.js';
|
|
9
|
-
import {
|
|
9
|
+
import { getTokenStore } from '../auth/token-store.js';
|
|
10
|
+
import { CONTENT_SYSTEM_NOT_FOUND_MESSAGE, getInfraEnvironment } from '../constants.js';
|
|
11
|
+
import { ensureGitignore } from '../utils/config.js';
|
|
12
|
+
import { addOrUpdateEnvVar } from '../utils/env-management.js';
|
|
10
13
|
import { isDebug } from '../utils/is-debug.js';
|
|
14
|
+
import { applyLambdaModifications } from '../utils/lambda-config.js';
|
|
11
15
|
import * as log from '../utils/log.js';
|
|
16
|
+
import { detectPackageManagerFromEnvironment, getRunCommand, resolvePackageManager } from '../utils/package-manager.js';
|
|
12
17
|
import { displayManualInstructions, ensurePayloadFigmaConfig } from '../utils/payload-config-modifier.js';
|
|
18
|
+
import { runScript } from '../utils/payload-package-check.js';
|
|
13
19
|
import { detectPayloadProject, hasRequiredDependencies, initializeGitRepo, installDependencies, isInProjectDirectory, scaffoldProject, validatePayloadVersion } from '../utils/project.js';
|
|
20
|
+
import { resolveEnvironment } from '../utils/resolve-environment.js';
|
|
21
|
+
import { checkForUpdates, getOwnVersion } from '../utils/version-check.js';
|
|
14
22
|
import { loginCommand } from './login.js';
|
|
23
|
+
import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
|
|
15
24
|
/**
|
|
16
|
-
* Generate and store project token for a
|
|
25
|
+
* Generate and store project token for a content system
|
|
17
26
|
* Non-blocking - will show warning but not exit on failure
|
|
18
27
|
* Only shows feedback if DEBUG mode is enabled, otherwise runs silently
|
|
19
28
|
*
|
|
20
29
|
* @param tokenStore - Token store instance
|
|
21
|
-
* @param
|
|
30
|
+
* @param contentSystemId - Content System ID to generate token for
|
|
22
31
|
* @param spinner - Clack spinner instance for status updates (only used in debug mode)
|
|
23
|
-
*/ async function generateProjectTokenWithFeedback(tokenStore,
|
|
32
|
+
*/ async function generateProjectTokenWithFeedback(tokenStore, contentSystemId, spinner) {
|
|
24
33
|
if (isDebug()) {
|
|
25
34
|
spinner.start('Generating project token...');
|
|
26
35
|
}
|
|
27
36
|
try {
|
|
28
|
-
const projectToken = await getValidProjectToken(tokenStore,
|
|
37
|
+
const projectToken = await getValidProjectToken(tokenStore, contentSystemId);
|
|
29
38
|
if (isDebug()) {
|
|
30
39
|
if (projectToken) {
|
|
31
40
|
spinner.stop(pc.green('✓ Project token generated'));
|
|
@@ -58,48 +67,35 @@ import { loginCommand } from './login.js';
|
|
|
58
67
|
*
|
|
59
68
|
* @param options - Command options
|
|
60
69
|
*/ export async function initCommand(options) {
|
|
70
|
+
// Check for outdated version (non-blocking)
|
|
71
|
+
const currentVersion = await getOwnVersion();
|
|
72
|
+
await checkForUpdates(currentVersion);
|
|
61
73
|
// Check authentication
|
|
62
|
-
const tokenStore =
|
|
74
|
+
const tokenStore = getTokenStore();
|
|
63
75
|
const s = p.spinner();
|
|
64
|
-
let accessToken;
|
|
65
76
|
if (options.skipAuth) {
|
|
66
77
|
// Skip authentication for testing/development
|
|
67
78
|
p.log.warn(pc.yellow('Skipping authentication (--skip-auth mode)'));
|
|
68
|
-
accessToken = 'mock-access-token';
|
|
69
79
|
} else {
|
|
70
80
|
try {
|
|
71
81
|
// Check for valid cached tokens first (no API call needed)
|
|
72
|
-
if (tokenStore.hasValidTokens()) {
|
|
73
|
-
// Use cached token silently - no spinner needed
|
|
74
|
-
accessToken = tokenStore.getAccessToken();
|
|
75
|
-
} else {
|
|
82
|
+
if (!tokenStore.hasValidTokens()) {
|
|
76
83
|
// Need to refresh or authenticate - show spinner for API call
|
|
77
84
|
s.start('Checking authentication...');
|
|
78
85
|
const token = await getValidAccessToken(tokenStore);
|
|
79
86
|
if (!token) {
|
|
80
|
-
s.stop(
|
|
81
|
-
p.log.info('Authentication required to continue');
|
|
82
|
-
// Prompt user to authenticate now
|
|
83
|
-
const shouldAuth = await p.confirm({
|
|
84
|
-
initialValue: true,
|
|
85
|
-
message: 'Would you like to authenticate now?'
|
|
86
|
-
});
|
|
87
|
-
if (p.isCancel(shouldAuth) || !shouldAuth) {
|
|
88
|
-
p.cancel('Operation cancelled');
|
|
89
|
-
process.exit(0);
|
|
90
|
-
}
|
|
87
|
+
s.stop('Authentication required to continue');
|
|
91
88
|
// Run login command
|
|
92
|
-
await loginCommand(
|
|
89
|
+
await loginCommand({
|
|
90
|
+
showNextSteps: false
|
|
91
|
+
});
|
|
93
92
|
// Get token after auth
|
|
94
93
|
const newToken = await getValidAccessToken(tokenStore);
|
|
95
94
|
if (!newToken) {
|
|
96
95
|
p.log.error('Authentication failed');
|
|
97
96
|
process.exit(1);
|
|
98
97
|
}
|
|
99
|
-
accessToken = newToken;
|
|
100
|
-
p.log.success(pc.green('✓ Authenticated'));
|
|
101
98
|
} else {
|
|
102
|
-
accessToken = token;
|
|
103
99
|
s.stop(pc.green('✓ Authenticated'));
|
|
104
100
|
}
|
|
105
101
|
}
|
|
@@ -113,53 +109,39 @@ import { loginCommand } from './login.js';
|
|
|
113
109
|
// Note: We no longer check for figma.config.json here
|
|
114
110
|
// Instead, the AST detection will check if figma object already exists in payload.config.ts
|
|
115
111
|
// and skip modification if it does (unless --force is used)
|
|
116
|
-
// Step 3: Get CMS ID
|
|
112
|
+
// Step 3: Get CMS Resource ID (required argument)
|
|
117
113
|
log.debug('Configuring Project...');
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
114
|
+
if (!options.id) {
|
|
115
|
+
p.log.error('CMS Resource ID is required. Use --id <cms-resource-id>');
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
const cmsResourceId = options.id;
|
|
119
|
+
// Fetch bootstrap info (oauth creds + environments)
|
|
120
|
+
let bootstrapInfo = null;
|
|
121
|
+
let resolvedEnv = null;
|
|
122
|
+
let oauthClientId = null;
|
|
123
|
+
let oauthClientSecret = null;
|
|
124
|
+
if (!options.skipAuth) {
|
|
125
|
+
const accessToken = await getValidAccessToken(tokenStore);
|
|
126
|
+
if (accessToken) {
|
|
127
|
+
try {
|
|
128
|
+
bootstrapInfo = await getBootstrapInfo(accessToken, cmsResourceId);
|
|
129
|
+
const envName = options.env ?? process.env.FIGMA_ENVIRONMENT_NAME ?? undefined;
|
|
130
|
+
resolvedEnv = resolveEnvironment({
|
|
131
|
+
environmentName: envName,
|
|
132
|
+
environments: bootstrapInfo.environments
|
|
133
|
+
});
|
|
134
|
+
oauthClientId = bootstrapInfo.oauthCredentials.oauthClientId;
|
|
135
|
+
oauthClientSecret = bootstrapInfo.oauthCredentials.oauthClientSecret;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
log.debug(`Control Plane Error: ${error.statusCode} - ${error.message}`);
|
|
138
|
+
if (error instanceof ControlPlaneError && (error.statusCode === 404 || error.statusCode === 410)) {
|
|
139
|
+
p.log.error(pc.red(CONTENT_SYSTEM_NOT_FOUND_MESSAGE));
|
|
140
|
+
process.exit(1);
|
|
131
141
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
p.
|
|
135
|
-
process.exit(0);
|
|
136
|
-
}
|
|
137
|
-
tenantId = input;
|
|
138
|
-
}
|
|
139
|
-
// Try to fetch tenant details
|
|
140
|
-
try {
|
|
141
|
-
log.debug('Using mock Control Plane API (no real network calls)');
|
|
142
|
-
selectedTenant = await getTenantDetails(accessToken, tenantId);
|
|
143
|
-
log.debug(`Using: ${selectedTenant.domain}`);
|
|
144
|
-
} catch (error) {
|
|
145
|
-
p.log.error(pc.red('✗ Failed to fetch CMS details'));
|
|
146
|
-
// Check if permission error (403)
|
|
147
|
-
if (error instanceof ControlPlaneError && error.statusCode === 403) {
|
|
148
|
-
p.log.error('You do not have permission to access the provided CMS ID. Please try again.');
|
|
149
|
-
} else if (error instanceof ControlPlaneError && error.statusCode === 404) {
|
|
150
|
-
p.log.error('Tenant ID not found. Verify the ID is correct.');
|
|
151
|
-
} else {
|
|
152
|
-
p.log.error(error instanceof Error ? error.message : 'Unknown error');
|
|
153
|
-
}
|
|
154
|
-
// Clear tenantId to prompt again
|
|
155
|
-
tenantId = undefined;
|
|
156
|
-
// Ask if they want to retry
|
|
157
|
-
const shouldRetry = await p.confirm({
|
|
158
|
-
initialValue: true,
|
|
159
|
-
message: 'Would you like to try a different CMS ID?'
|
|
160
|
-
});
|
|
161
|
-
if (p.isCancel(shouldRetry) || !shouldRetry) {
|
|
162
|
-
p.cancel('Operation cancelled');
|
|
142
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
143
|
+
p.log.error(pc.red(`✗ Unable to fetch project info for "${cmsResourceId}"`));
|
|
144
|
+
p.log.error(pc.dim(`Details: ${message}`));
|
|
163
145
|
process.exit(1);
|
|
164
146
|
}
|
|
165
147
|
}
|
|
@@ -171,6 +153,7 @@ import { loginCommand } from './login.js';
|
|
|
171
153
|
log.debug('Project directory detected');
|
|
172
154
|
// Detect Payload
|
|
173
155
|
const projectInfo = await detectPayloadProject();
|
|
156
|
+
const packageManager = await resolvePackageManager(process.cwd());
|
|
174
157
|
if (projectInfo.hasPayload) {
|
|
175
158
|
// Validate existing Payload version
|
|
176
159
|
if (projectInfo.payloadVersion && !validatePayloadVersion(projectInfo.payloadVersion)) {
|
|
@@ -190,19 +173,17 @@ import { loginCommand } from './login.js';
|
|
|
190
173
|
});
|
|
191
174
|
if (!p.isCancel(shouldInstall) && shouldInstall) {
|
|
192
175
|
s.start('Installing dependencies...');
|
|
193
|
-
await installDependencies(process.cwd(),
|
|
176
|
+
await installDependencies(process.cwd(), packageManager);
|
|
194
177
|
s.stop(pc.green('✓ Dependencies installed'));
|
|
195
178
|
}
|
|
196
179
|
}
|
|
197
180
|
s.start('Checking Payload configuration...');
|
|
198
|
-
const modResult = await ensurePayloadFigmaConfig(process.cwd(),
|
|
199
|
-
|
|
200
|
-
tenantId: selectedTenant.id,
|
|
201
|
-
useContentSystem: !options.noContentSystem
|
|
181
|
+
const modResult = await ensurePayloadFigmaConfig(process.cwd(), packageManager, {
|
|
182
|
+
contentSystemId: resolvedEnv?.contentSystemId ?? cmsResourceId
|
|
202
183
|
});
|
|
203
184
|
if (!modResult.success) {
|
|
204
185
|
s.stop(pc.red('✗ Configuration check failed'));
|
|
205
|
-
displayManualInstructions(modResult.error || 'Unknown error');
|
|
186
|
+
displayManualInstructions(modResult.error || 'Unknown error', packageManager);
|
|
206
187
|
process.exit(1);
|
|
207
188
|
}
|
|
208
189
|
if (modResult.modified) {
|
|
@@ -219,6 +200,23 @@ import { loginCommand } from './login.js';
|
|
|
219
200
|
p.log.warn(pc.yellow(`⚠ ${warning}`));
|
|
220
201
|
});
|
|
221
202
|
}
|
|
203
|
+
// Write environment variables to .env file
|
|
204
|
+
try {
|
|
205
|
+
await addOrUpdateEnvVar(process.cwd(), 'FIGMA_PROJECT_ID', cmsResourceId);
|
|
206
|
+
await addOrUpdateEnvVar(process.cwd(), 'FIGMA_ENVIRONMENT_NAME', resolvedEnv?.name ?? 'production');
|
|
207
|
+
log.debug('Added FIGMA_PROJECT_ID and FIGMA_ENVIRONMENT_NAME to .env file');
|
|
208
|
+
const infraEnv = getInfraEnvironment();
|
|
209
|
+
if (infraEnv !== 'production') {
|
|
210
|
+
await addOrUpdateEnvVar(process.cwd(), 'FIGMA_INFRA_ENV', infraEnv);
|
|
211
|
+
log.debug(`Added FIGMA_INFRA_ENV=${infraEnv} to .env file`);
|
|
212
|
+
}
|
|
213
|
+
// Cache all environments in local encrypted store
|
|
214
|
+
if (bootstrapInfo && oauthClientId && oauthClientSecret) {
|
|
215
|
+
cacheAllEnvironments(tokenStore, cmsResourceId, bootstrapInfo);
|
|
216
|
+
}
|
|
217
|
+
} catch (error) {
|
|
218
|
+
p.log.warn(pc.yellow(`⚠ Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
219
|
+
}
|
|
222
220
|
} else {
|
|
223
221
|
// Has package.json but no Payload - offer to add Payload
|
|
224
222
|
p.log.warn(pc.yellow('⚠ No Payload detected in this project'));
|
|
@@ -239,16 +237,24 @@ import { loginCommand } from './login.js';
|
|
|
239
237
|
p.note('Create a new project or manually add Payload dependencies', 'Action Required');
|
|
240
238
|
process.exit(1);
|
|
241
239
|
}
|
|
240
|
+
// Generate import map to prevent errors on first dev run
|
|
241
|
+
await runScript(process.cwd(), 'generate:importmap', packageManager);
|
|
242
|
+
// Apply Lambda modifications (run.sh, standalone output, lambda:buildzip script)
|
|
243
|
+
await applyLambdaModifications(process.cwd(), packageManager);
|
|
244
|
+
// Ensure .gitignore has required entries
|
|
245
|
+
await ensureGitignore(process.cwd(), [
|
|
246
|
+
'.env',
|
|
247
|
+
'.env.local',
|
|
248
|
+
'lambda.zip'
|
|
249
|
+
]);
|
|
242
250
|
// Generate project token (unless skipping auth)
|
|
243
|
-
if (!options.skipAuth) {
|
|
244
|
-
await generateProjectTokenWithFeedback(tokenStore,
|
|
251
|
+
if (!options.skipAuth && resolvedEnv) {
|
|
252
|
+
await generateProjectTokenWithFeedback(tokenStore, resolvedEnv.contentSystemId, s);
|
|
245
253
|
}
|
|
246
254
|
// Success message for existing project
|
|
247
255
|
p.outro(pc.green('✓ Project initialized successfully!'));
|
|
248
256
|
const nextSteps = [
|
|
249
|
-
|
|
250
|
-
'Start development server: `pnpm dev`',
|
|
251
|
-
`Access your CMS at: ${pc.cyan(`https://${selectedTenant.domain}`)}`
|
|
257
|
+
`Start development server: \`${getRunCommand(packageManager)} dev\``
|
|
252
258
|
].filter(Boolean);
|
|
253
259
|
p.note(nextSteps.join('\n'), 'Next Steps');
|
|
254
260
|
} else {
|
|
@@ -275,6 +281,7 @@ import { loginCommand } from './login.js';
|
|
|
275
281
|
const fullPath = path.resolve(process.cwd(), projectPath);
|
|
276
282
|
// Get project name from path or prompt
|
|
277
283
|
const projectName = options.name || path.basename(fullPath);
|
|
284
|
+
const packageManager = detectPackageManagerFromEnvironment();
|
|
278
285
|
// Create directory
|
|
279
286
|
try {
|
|
280
287
|
await fs.mkdir(fullPath, {
|
|
@@ -287,10 +294,10 @@ import { loginCommand } from './login.js';
|
|
|
287
294
|
// Scaffold project
|
|
288
295
|
s.start('Downloading template from GitHub...');
|
|
289
296
|
try {
|
|
290
|
-
await scaffoldProject(fullPath, projectName);
|
|
297
|
+
await scaffoldProject(fullPath, projectName, packageManager);
|
|
291
298
|
s.stop(pc.green('✓ Template downloaded'));
|
|
292
299
|
s.start('Installing dependencies...');
|
|
293
|
-
await installDependencies(fullPath,
|
|
300
|
+
await installDependencies(fullPath, packageManager);
|
|
294
301
|
s.stop(pc.green('✓ Dependencies installed'));
|
|
295
302
|
} catch (error) {
|
|
296
303
|
s.stop(pc.red('✗ Failed'));
|
|
@@ -299,14 +306,12 @@ import { loginCommand } from './login.js';
|
|
|
299
306
|
}
|
|
300
307
|
// Modify Payload configuration
|
|
301
308
|
s.start('Checking Payload configuration...');
|
|
302
|
-
const modResult = await ensurePayloadFigmaConfig(fullPath,
|
|
303
|
-
|
|
304
|
-
tenantId: selectedTenant.id,
|
|
305
|
-
useContentSystem: !options.noContentSystem
|
|
309
|
+
const modResult = await ensurePayloadFigmaConfig(fullPath, packageManager, {
|
|
310
|
+
contentSystemId: resolvedEnv?.contentSystemId ?? cmsResourceId
|
|
306
311
|
});
|
|
307
312
|
if (!modResult.success) {
|
|
308
313
|
s.stop(pc.red('✗ Configuration check failed'));
|
|
309
|
-
displayManualInstructions(modResult.error || 'Unknown error');
|
|
314
|
+
displayManualInstructions(modResult.error || 'Unknown error', packageManager);
|
|
310
315
|
process.exit(1);
|
|
311
316
|
}
|
|
312
317
|
if (modResult.modified) {
|
|
@@ -323,9 +328,28 @@ import { loginCommand } from './login.js';
|
|
|
323
328
|
p.log.warn(pc.yellow(`⚠ ${warning}`));
|
|
324
329
|
});
|
|
325
330
|
}
|
|
331
|
+
// Write environment variables to .env file
|
|
332
|
+
try {
|
|
333
|
+
await addOrUpdateEnvVar(fullPath, 'FIGMA_PROJECT_ID', cmsResourceId);
|
|
334
|
+
await addOrUpdateEnvVar(fullPath, 'FIGMA_ENVIRONMENT_NAME', resolvedEnv?.name ?? 'production');
|
|
335
|
+
log.debug('Added FIGMA_PROJECT_ID and FIGMA_ENVIRONMENT_NAME to .env file');
|
|
336
|
+
const infraEnv = getInfraEnvironment();
|
|
337
|
+
if (infraEnv !== 'production') {
|
|
338
|
+
await addOrUpdateEnvVar(fullPath, 'FIGMA_INFRA_ENV', infraEnv);
|
|
339
|
+
log.debug(`Added FIGMA_INFRA_ENV=${infraEnv} to .env file`);
|
|
340
|
+
}
|
|
341
|
+
// Cache all environments in local encrypted store
|
|
342
|
+
if (bootstrapInfo && oauthClientId && oauthClientSecret) {
|
|
343
|
+
cacheAllEnvironments(tokenStore, cmsResourceId, bootstrapInfo);
|
|
344
|
+
}
|
|
345
|
+
} catch (error) {
|
|
346
|
+
p.log.warn(pc.yellow(`⚠ Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
347
|
+
}
|
|
348
|
+
// Generate import map to prevent errors on first dev run
|
|
349
|
+
await runScript(fullPath, 'generate:importmap', packageManager);
|
|
326
350
|
// Generate project token (unless skipping auth)
|
|
327
|
-
if (!options.skipAuth) {
|
|
328
|
-
await generateProjectTokenWithFeedback(tokenStore,
|
|
351
|
+
if (!options.skipAuth && resolvedEnv) {
|
|
352
|
+
await generateProjectTokenWithFeedback(tokenStore, resolvedEnv.contentSystemId, s);
|
|
329
353
|
}
|
|
330
354
|
// Initialize git repository (after all files including lock file are ready)
|
|
331
355
|
initializeGitRepo(fullPath);
|
|
@@ -337,7 +361,7 @@ import { loginCommand } from './login.js';
|
|
|
337
361
|
if (relativePath && relativePath !== '.') {
|
|
338
362
|
nextSteps.push(`cd ${relativePath}`);
|
|
339
363
|
}
|
|
340
|
-
nextSteps.push(
|
|
364
|
+
nextSteps.push(`${getRunCommand(packageManager)} dev or follow directions in README.md`, '', 'Documentation:', '- Getting Started: https://payloadcms.com/docs/getting-started/what-is-payload', '- Configuration: https://payloadcms.com/docs/configuration/overview');
|
|
341
365
|
p.note(nextSteps.join('\n'), 'Next Steps');
|
|
342
366
|
p.outro(pc.green('✓ Done'));
|
|
343
367
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Options for list-tokens command
|
|
3
3
|
*/
|
|
4
4
|
export interface ListTokensCommandOptions {
|
|
5
|
+
/** Show all environments */
|
|
6
|
+
all?: boolean;
|
|
5
7
|
/** Enable debug mode */
|
|
6
8
|
debug?: boolean;
|
|
7
9
|
}
|
|
@@ -9,8 +11,6 @@ export interface ListTokensCommandOptions {
|
|
|
9
11
|
* Handle the `@payloadcms/figma list-tokens` command
|
|
10
12
|
*
|
|
11
13
|
* Displays stored token information including OAuth and project tokens.
|
|
12
|
-
*
|
|
13
|
-
* @param _options - Command options (unused)
|
|
14
14
|
*/
|
|
15
|
-
export declare function listTokensCommand(
|
|
15
|
+
export declare function listTokensCommand(options?: ListTokensCommandOptions): void;
|
|
16
16
|
//# sourceMappingURL=list-tokens.d.ts.map
|
|
@@ -1,25 +1,40 @@
|
|
|
1
1
|
import * as p from '@clack/prompts';
|
|
2
2
|
import pc from 'picocolors';
|
|
3
|
-
import {
|
|
3
|
+
import { getTokenStore } from '../auth/token-store.js';
|
|
4
|
+
import { getInfraEnvironment } from '../constants.js';
|
|
5
|
+
import { formatEnvSuffix } from '../utils/format-env-suffix.js';
|
|
4
6
|
import { isDebug } from '../utils/is-debug.js';
|
|
5
7
|
import { formatTimestamp, maskToken, showProjectTokens } from '../utils/token-display.js';
|
|
8
|
+
const ALL_ENVIRONMENTS = [
|
|
9
|
+
'production',
|
|
10
|
+
'staging'
|
|
11
|
+
];
|
|
6
12
|
/**
|
|
7
13
|
* Handle the `@payloadcms/figma list-tokens` command
|
|
8
14
|
*
|
|
9
15
|
* Displays stored token information including OAuth and project tokens.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
*/ export function listTokensCommand(options = {}) {
|
|
17
|
+
if (options.all) {
|
|
18
|
+
// Show detailed info for all environments
|
|
19
|
+
for (const env of ALL_ENVIRONMENTS){
|
|
20
|
+
showTokenDetails(env);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
// Show detailed info for current environment only
|
|
24
|
+
showTokenDetails(getInfraEnvironment());
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function showTokenDetails(env) {
|
|
28
|
+
const tokenStore = getTokenStore(env);
|
|
14
29
|
const tokens = tokenStore.getTokens();
|
|
15
30
|
if (!tokens) {
|
|
16
|
-
p.log.warn(pc.yellow(
|
|
31
|
+
p.log.warn(pc.yellow(`No tokens found${formatEnvSuffix(env, ' for ')}. Not authenticated.`));
|
|
17
32
|
p.note(`Run ${pc.cyan('@payloadcms/figma login')} to authenticate`, 'Tip');
|
|
18
33
|
return;
|
|
19
34
|
}
|
|
20
35
|
const isValid = tokenStore.hasValidTokens();
|
|
21
36
|
const status = isValid ? pc.green('✓ Valid') : pc.red('✗ Expired');
|
|
22
|
-
p.log.step(pc.bold('
|
|
37
|
+
p.log.step(pc.bold(`Token Status${formatEnvSuffix(env, ' (', ')')}`));
|
|
23
38
|
// Build OAuth token info display
|
|
24
39
|
const lines = [
|
|
25
40
|
`Status: ${status}`,
|
package/dist/commands/login.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
type LoginArgs = {
|
|
2
|
+
/** Set this to show next steps after login
|
|
3
|
+
* @default true
|
|
4
|
+
*/
|
|
5
|
+
showNextSteps: boolean;
|
|
6
|
+
};
|
|
1
7
|
/**
|
|
2
8
|
* Handle the `@payloadcms/figma login` command
|
|
3
9
|
*
|
|
4
10
|
* Authenticates the user with Figma OAuth2 and stores tokens locally.
|
|
5
11
|
* If valid tokens already exist, shows an error message.
|
|
6
12
|
*/
|
|
7
|
-
export declare function loginCommand(): Promise<void>;
|
|
13
|
+
export declare function loginCommand(args?: LoginArgs): Promise<void>;
|
|
14
|
+
export {};
|
|
8
15
|
//# sourceMappingURL=login.d.ts.map
|
package/dist/commands/login.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import * as p from '@clack/prompts';
|
|
2
2
|
import pc from 'picocolors';
|
|
3
|
+
import { CallbackError } from '../auth/callback-server.js';
|
|
3
4
|
import { executeOAuthFlow, getValidAccessToken, OAuthFlowError } from '../auth/oauth-flow.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { getTokenStore } from '../auth/token-store.js';
|
|
6
|
+
import { getOAuthConfig } from '../config/oauth.js';
|
|
7
|
+
import { getInfraEnvironment } from '../constants.js';
|
|
8
|
+
import { formatEnvSuffix } from '../utils/format-env-suffix.js';
|
|
6
9
|
import * as log from '../utils/log.js';
|
|
7
10
|
/**
|
|
8
11
|
* Handle the `@payloadcms/figma login` command
|
|
9
12
|
*
|
|
10
13
|
* Authenticates the user with Figma OAuth2 and stores tokens locally.
|
|
11
14
|
* If valid tokens already exist, shows an error message.
|
|
12
|
-
*/ export async function loginCommand() {
|
|
13
|
-
const
|
|
15
|
+
*/ export async function loginCommand(args) {
|
|
16
|
+
const { showNextSteps } = args || {
|
|
17
|
+
showNextSteps: false
|
|
18
|
+
};
|
|
19
|
+
const env = getInfraEnvironment();
|
|
20
|
+
const tokenStore = getTokenStore(env);
|
|
14
21
|
// Check for existing valid tokens
|
|
15
22
|
try {
|
|
16
23
|
const existingToken = await getValidAccessToken(tokenStore);
|
|
17
24
|
if (existingToken) {
|
|
18
25
|
const tokens = tokenStore.getTokens();
|
|
19
|
-
p.log.warn(pc.yellow(
|
|
26
|
+
p.log.warn(pc.yellow(`Already logged in${formatEnvSuffix(env)}`));
|
|
20
27
|
if (tokens?.userId) {
|
|
21
28
|
log.info(`User ID: ${tokens.userId}`);
|
|
22
29
|
}
|
|
@@ -30,28 +37,39 @@ import * as log from '../utils/log.js';
|
|
|
30
37
|
}
|
|
31
38
|
// Start OAuth flow
|
|
32
39
|
await handleAuthentication({
|
|
40
|
+
showNextSteps,
|
|
33
41
|
tokenStore
|
|
34
42
|
});
|
|
35
43
|
}
|
|
36
44
|
/**
|
|
37
45
|
* Handle authentication flow
|
|
38
|
-
*/ async function handleAuthentication({ tokenStore }) {
|
|
46
|
+
*/ async function handleAuthentication({ showNextSteps, tokenStore }) {
|
|
39
47
|
try {
|
|
40
48
|
// Execute OAuth flow
|
|
49
|
+
const oauthConfig = getOAuthConfig();
|
|
41
50
|
const result = await executeOAuthFlow(tokenStore, {
|
|
42
|
-
clientId:
|
|
43
|
-
redirectUri:
|
|
44
|
-
scopes:
|
|
51
|
+
clientId: oauthConfig.clientId,
|
|
52
|
+
redirectUri: oauthConfig.redirectUri,
|
|
53
|
+
scopes: oauthConfig.scopes
|
|
45
54
|
});
|
|
46
|
-
|
|
55
|
+
const env = getInfraEnvironment();
|
|
56
|
+
p.log.success(pc.green(`✓ Logged in${formatEnvSuffix(env)}`));
|
|
47
57
|
if (result.userId) {
|
|
48
58
|
log.debug(`User ID: ${result.userId}`);
|
|
49
59
|
}
|
|
50
60
|
log.debug(`Token storage: ${pc.dim(tokenStore.getStoragePath())}`);
|
|
51
|
-
// Show next steps
|
|
52
|
-
|
|
61
|
+
// Show next steps unless disabled
|
|
62
|
+
if (showNextSteps !== false) {
|
|
63
|
+
p.note(` ${pc.cyan('@payloadcms/figma init')} Create a new CMS instance`, 'Next Steps');
|
|
64
|
+
}
|
|
53
65
|
} catch (error) {
|
|
54
66
|
if (error instanceof OAuthFlowError) {
|
|
67
|
+
const isTimeout = error.cause instanceof CallbackError && error.cause.code === 'timeout';
|
|
68
|
+
if (isTimeout) {
|
|
69
|
+
p.log.error(pc.red('✗ Authentication timed out.'));
|
|
70
|
+
p.note(`Run ${pc.cyan('@payloadcms/figma login')} to try again.`, 'Tip');
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
55
73
|
log.error(error.message);
|
|
56
74
|
if (error.cause) {
|
|
57
75
|
log.debug(`Cause: ${error.cause.message}`);
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
* Options for logout command
|
|
3
3
|
*/
|
|
4
4
|
export interface LogoutCommandOptions {
|
|
5
|
+
/** Logout from all environments */
|
|
6
|
+
all?: boolean;
|
|
5
7
|
/** Enable debug mode */
|
|
6
8
|
debug?: boolean;
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
9
11
|
* Handle the `@payloadcms/figma logout` command
|
|
10
12
|
*
|
|
11
|
-
* Clears
|
|
12
|
-
*
|
|
13
|
-
* @param _options - Command options (unused)
|
|
13
|
+
* Clears stored tokens (OAuth and project tokens) after confirmation.
|
|
14
|
+
* By default clears only current environment. Use --all for all environments.
|
|
14
15
|
*/
|
|
15
|
-
export declare function logoutCommand(
|
|
16
|
+
export declare function logoutCommand(options?: LogoutCommandOptions): Promise<void>;
|
|
16
17
|
//# sourceMappingURL=logout.d.ts.map
|
package/dist/commands/logout.js
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
import * as p from '@clack/prompts';
|
|
2
2
|
import pc from 'picocolors';
|
|
3
|
-
import {
|
|
3
|
+
import { getTokenStore } from '../auth/token-store.js';
|
|
4
|
+
import { getInfraEnvironment } from '../constants.js';
|
|
5
|
+
import { formatEnvSuffix } from '../utils/format-env-suffix.js';
|
|
4
6
|
import * as log from '../utils/log.js';
|
|
7
|
+
const ALL_ENVIRONMENTS = [
|
|
8
|
+
'production',
|
|
9
|
+
'staging'
|
|
10
|
+
];
|
|
5
11
|
/**
|
|
6
12
|
* Handle the `@payloadcms/figma logout` command
|
|
7
13
|
*
|
|
8
|
-
* Clears
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
* Clears stored tokens (OAuth and project tokens) after confirmation.
|
|
15
|
+
* By default clears only current environment. Use --all for all environments.
|
|
16
|
+
*/ export async function logoutCommand(options = {}) {
|
|
17
|
+
const currentEnv = getInfraEnvironment();
|
|
18
|
+
if (options.all) {
|
|
19
|
+
await logoutAllEnvironments();
|
|
20
|
+
} else {
|
|
21
|
+
await logoutSingleEnvironment(currentEnv);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function logoutSingleEnvironment(env) {
|
|
25
|
+
const tokenStore = getTokenStore(env);
|
|
13
26
|
const hasTokens = tokenStore.getTokens() !== null;
|
|
14
27
|
if (!hasTokens) {
|
|
15
|
-
p.log.warn(pc.yellow(
|
|
28
|
+
p.log.warn(pc.yellow(`No tokens found${formatEnvSuffix(env, ' for ')}. Already logged out.`));
|
|
16
29
|
return;
|
|
17
30
|
}
|
|
18
|
-
// Confirm logout
|
|
19
31
|
const confirmed = await p.confirm({
|
|
20
32
|
initialValue: false,
|
|
21
|
-
message:
|
|
33
|
+
message: `This will clear all OAuth and project tokens${formatEnvSuffix(env, ' for ')}. Continue?`
|
|
22
34
|
});
|
|
23
35
|
if (p.isCancel(confirmed) || !confirmed) {
|
|
24
36
|
p.log.info('Logout cancelled');
|
|
@@ -27,12 +39,43 @@ import * as log from '../utils/log.js';
|
|
|
27
39
|
const s = p.spinner();
|
|
28
40
|
s.start('Clearing tokens...');
|
|
29
41
|
try {
|
|
30
|
-
// Clear OAuth tokens
|
|
31
42
|
tokenStore.clearTokens();
|
|
32
|
-
// Clear all project tokens
|
|
33
43
|
tokenStore.clearAllProjectTokens();
|
|
34
|
-
s.stop(pc.green(
|
|
35
|
-
|
|
44
|
+
s.stop(pc.green(`✓ Logged out${formatEnvSuffix(env, ' from ')}`));
|
|
45
|
+
} catch (error) {
|
|
46
|
+
s.stop(pc.red('✗ Failed to clear tokens'));
|
|
47
|
+
log.error(error instanceof Error ? error.message : 'Unknown error');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function logoutAllEnvironments() {
|
|
52
|
+
// Check which environments have tokens
|
|
53
|
+
const envsWithTokens = ALL_ENVIRONMENTS.filter((env)=>{
|
|
54
|
+
const store = getTokenStore(env);
|
|
55
|
+
return store.getTokens() !== null;
|
|
56
|
+
});
|
|
57
|
+
if (envsWithTokens.length === 0) {
|
|
58
|
+
p.log.warn(pc.yellow('No tokens found in any environment. Already logged out.'));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const envList = envsWithTokens.join(' and ');
|
|
62
|
+
const confirmed = await p.confirm({
|
|
63
|
+
initialValue: false,
|
|
64
|
+
message: `This will clear all OAuth and project tokens for ${envList}. Continue?`
|
|
65
|
+
});
|
|
66
|
+
if (p.isCancel(confirmed) || !confirmed) {
|
|
67
|
+
p.log.info('Logout cancelled');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const s = p.spinner();
|
|
71
|
+
s.start('Clearing tokens...');
|
|
72
|
+
try {
|
|
73
|
+
for (const env of envsWithTokens){
|
|
74
|
+
const store = getTokenStore(env);
|
|
75
|
+
store.clearTokens();
|
|
76
|
+
store.clearAllProjectTokens();
|
|
77
|
+
}
|
|
78
|
+
s.stop(pc.green('✓ Logged out from all environments'));
|
|
36
79
|
} catch (error) {
|
|
37
80
|
s.stop(pc.red('✗ Failed to clear tokens'));
|
|
38
81
|
log.error(error instanceof Error ? error.message : 'Unknown error');
|