@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
|
@@ -44,8 +44,8 @@ export interface CreateDeploymentResponse {
|
|
|
44
44
|
export interface CreateDeploymentApiResponse {
|
|
45
45
|
error: boolean;
|
|
46
46
|
meta: {
|
|
47
|
-
code_upload_url: string;
|
|
48
47
|
deployment_id: string;
|
|
48
|
+
lambda_zip_upload_url: string;
|
|
49
49
|
static_asset_upload_urls: Record<string, string>;
|
|
50
50
|
};
|
|
51
51
|
status: number;
|
|
@@ -65,6 +65,8 @@ export interface PerformDeploymentResponse {
|
|
|
65
65
|
deploymentId: string;
|
|
66
66
|
/** Status message */
|
|
67
67
|
message: string;
|
|
68
|
+
/** List of tenant domains */
|
|
69
|
+
tenantDomains: string[];
|
|
68
70
|
}
|
|
69
71
|
export interface PerformDeploymentApiResponse {
|
|
70
72
|
error: boolean;
|
|
@@ -72,6 +74,7 @@ export interface PerformDeploymentApiResponse {
|
|
|
72
74
|
deployment_id: string;
|
|
73
75
|
message: string;
|
|
74
76
|
status: string;
|
|
77
|
+
tenant_domains: string[];
|
|
75
78
|
};
|
|
76
79
|
status: number;
|
|
77
80
|
}
|
|
@@ -121,4 +124,31 @@ export declare function createDeployment(accessToken: string, tenantId: string,
|
|
|
121
124
|
* @returns Deployment status and message
|
|
122
125
|
*/
|
|
123
126
|
export declare function performDeployment(accessToken: string, tenantId: string, options: PerformDeploymentOptions): Promise<PerformDeploymentResponse>;
|
|
127
|
+
/**
|
|
128
|
+
* A single environment returned by the bootstrap endpoint
|
|
129
|
+
*/
|
|
130
|
+
export type BootstrapEnvironment = {
|
|
131
|
+
contentSystemId: string;
|
|
132
|
+
name: string;
|
|
133
|
+
tenantInstanceId: string;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Response from the bootstrap endpoint (camelCased)
|
|
137
|
+
*/
|
|
138
|
+
export type BootstrapInfo = {
|
|
139
|
+
environments: BootstrapEnvironment[];
|
|
140
|
+
oauthCredentials: {
|
|
141
|
+
oauthClientId: string;
|
|
142
|
+
oauthClientSecret: string;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Get bootstrap info for a CMS resource
|
|
147
|
+
* Maps to: GET /v1/cms/:cmsResourceId/bootstrap
|
|
148
|
+
*
|
|
149
|
+
* @param accessToken - OAuth access token
|
|
150
|
+
* @param cmsResourceId - CMS Resource ID (project ID)
|
|
151
|
+
* @param environmentName - Optional environment name filter
|
|
152
|
+
*/
|
|
153
|
+
export declare function getBootstrapInfo(accessToken: string, cmsResourceId: string, environmentName?: string): Promise<BootstrapInfo>;
|
|
124
154
|
//# sourceMappingURL=control-plane.d.ts.map
|
|
@@ -2,18 +2,12 @@
|
|
|
2
2
|
* Control Plane API Client
|
|
3
3
|
*
|
|
4
4
|
* TODO: Replace with real API calls when Control Plane is available
|
|
5
|
-
*/ import {
|
|
5
|
+
*/ import { getEnvConfig } from '../constants.js';
|
|
6
6
|
import * as log from '../utils/log.js';
|
|
7
|
-
/**
|
|
8
|
-
* Control Plane API base URLs
|
|
9
|
-
*/ const CONTROL_PLANE_API_URLS = {
|
|
10
|
-
production: 'https://api.figma.com',
|
|
11
|
-
staging: 'https://api.staging.figma.com'
|
|
12
|
-
};
|
|
13
7
|
/**
|
|
14
8
|
* Get the Control Plane API base URL based on environment
|
|
15
9
|
*/ function getControlPlaneBaseUrl() {
|
|
16
|
-
return process.env.FIGMA_API_BASE_URL ||
|
|
10
|
+
return process.env.FIGMA_API_BASE_URL || getEnvConfig().apiBaseUrl;
|
|
17
11
|
}
|
|
18
12
|
/**
|
|
19
13
|
* Error thrown when Control Plane API calls fail
|
|
@@ -32,9 +26,7 @@ import * as log from '../utils/log.js';
|
|
|
32
26
|
* @param accessToken - OAuth access token
|
|
33
27
|
* @returns Array of tenant instances
|
|
34
28
|
*/ export async function listTenants(accessToken) {
|
|
35
|
-
|
|
36
|
-
// Default to true until real API is available
|
|
37
|
-
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE !== 'false';
|
|
29
|
+
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE === 'true';
|
|
38
30
|
if (shouldMock) {
|
|
39
31
|
// MOCK IMPLEMENTATION: Return sample tenants for testing
|
|
40
32
|
log.debug('Using mock Control Plane API for listTenants (FIGMA_MOCK_CONTROL_PLANE != "false")');
|
|
@@ -58,14 +50,15 @@ import * as log from '../utils/log.js';
|
|
|
58
50
|
];
|
|
59
51
|
}
|
|
60
52
|
// REAL API IMPLEMENTATION
|
|
61
|
-
const response = await
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
const response = await controlPlaneFetch({
|
|
54
|
+
context: 'list tenants',
|
|
55
|
+
options: {
|
|
56
|
+
headers: {
|
|
57
|
+
Authorization: `Bearer ${accessToken}`
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
url: `${getControlPlaneBaseUrl()}/v1/tenant`
|
|
65
61
|
});
|
|
66
|
-
if (!response.ok) {
|
|
67
|
-
throw new ControlPlaneError(`Failed to list tenants: ${response.status} ${response.statusText}`, response.status);
|
|
68
|
-
}
|
|
69
62
|
return response.json();
|
|
70
63
|
}
|
|
71
64
|
/**
|
|
@@ -77,7 +70,7 @@ import * as log from '../utils/log.js';
|
|
|
77
70
|
* @returns Newly created tenant
|
|
78
71
|
*/ export async function createTenant(accessToken, options) {
|
|
79
72
|
// Check if control plane API should be mocked
|
|
80
|
-
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE
|
|
73
|
+
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE === 'true';
|
|
81
74
|
if (shouldMock) {
|
|
82
75
|
// MOCK IMPLEMENTATION: Generate mock tenant for testing
|
|
83
76
|
log.debug('Using mock Control Plane API for createTenant (FIGMA_MOCK_CONTROL_PLANE != "false")');
|
|
@@ -94,19 +87,20 @@ import * as log from '../utils/log.js';
|
|
|
94
87
|
};
|
|
95
88
|
}
|
|
96
89
|
// REAL API IMPLEMENTATION
|
|
97
|
-
const response = await
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
90
|
+
const response = await controlPlaneFetch({
|
|
91
|
+
context: 'create tenant',
|
|
92
|
+
options: {
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
name: options.name
|
|
95
|
+
}),
|
|
96
|
+
headers: {
|
|
97
|
+
Authorization: `Bearer ${accessToken}`,
|
|
98
|
+
'Content-Type': 'application/json'
|
|
99
|
+
},
|
|
100
|
+
method: 'POST'
|
|
104
101
|
},
|
|
105
|
-
|
|
102
|
+
url: `${getControlPlaneBaseUrl()}/v1/tenant`
|
|
106
103
|
});
|
|
107
|
-
if (!response.ok) {
|
|
108
|
-
throw new ControlPlaneError(`Failed to create tenant: ${response.status} ${response.statusText}`, response.status);
|
|
109
|
-
}
|
|
110
104
|
return response.json();
|
|
111
105
|
}
|
|
112
106
|
/**
|
|
@@ -118,7 +112,7 @@ import * as log from '../utils/log.js';
|
|
|
118
112
|
* @returns Tenant details
|
|
119
113
|
*/ export async function getTenantDetails(accessToken, tenantId) {
|
|
120
114
|
// Check if control plane API should be mocked
|
|
121
|
-
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE
|
|
115
|
+
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE === 'true';
|
|
122
116
|
if (shouldMock) {
|
|
123
117
|
// MOCK IMPLEMENTATION: Return mock tenant details for testing
|
|
124
118
|
log.debug('Using mock Control Plane API for getTenantDetails (FIGMA_MOCK_CONTROL_PLANE != "false")');
|
|
@@ -132,14 +126,15 @@ import * as log from '../utils/log.js';
|
|
|
132
126
|
};
|
|
133
127
|
}
|
|
134
128
|
// REAL API IMPLEMENTATION
|
|
135
|
-
const response = await
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
const response = await controlPlaneFetch({
|
|
130
|
+
context: 'get tenant details',
|
|
131
|
+
options: {
|
|
132
|
+
headers: {
|
|
133
|
+
Authorization: `Bearer ${accessToken}`
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
url: `${getControlPlaneBaseUrl()}/v1/tenant/${tenantId}`
|
|
139
137
|
});
|
|
140
|
-
if (!response.ok) {
|
|
141
|
-
throw new ControlPlaneError(`Failed to get tenant details: ${response.status} ${response.statusText}`, response.status);
|
|
142
|
-
}
|
|
143
138
|
return response.json();
|
|
144
139
|
}
|
|
145
140
|
/**
|
|
@@ -152,10 +147,10 @@ import * as log from '../utils/log.js';
|
|
|
152
147
|
* @returns Deployment ID and upload URLs
|
|
153
148
|
*/ export async function createDeployment(accessToken, tenantId, options) {
|
|
154
149
|
// Check if control plane API should be mocked
|
|
155
|
-
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE
|
|
150
|
+
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE === 'true';
|
|
156
151
|
if (shouldMock) {
|
|
157
152
|
// MOCK IMPLEMENTATION: Generate mock deployment and signed URLs
|
|
158
|
-
log.debug('Using mock Control Plane API for createDeployment (FIGMA_MOCK_CONTROL_PLANE
|
|
153
|
+
log.debug('Using mock Control Plane API for createDeployment (FIGMA_MOCK_CONTROL_PLANE === "true")');
|
|
159
154
|
const deploymentId = `deploy_${Math.random().toString(36).substring(2, 11)}`;
|
|
160
155
|
const mockBucket = 'figma-cms-deployments-mock';
|
|
161
156
|
const mockRegion = 'us-west-2';
|
|
@@ -174,24 +169,27 @@ import * as log from '../utils/log.js';
|
|
|
174
169
|
staticAssetUploadUrls
|
|
175
170
|
};
|
|
176
171
|
}
|
|
172
|
+
const url = `${getControlPlaneBaseUrl()}/v1/cms/tenant/${tenantId}/deploy/create`;
|
|
173
|
+
log.debug(`Calling createDeployment API at ${url}`);
|
|
177
174
|
// REAL API IMPLEMENTATION
|
|
178
|
-
const response = await
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
175
|
+
const response = await controlPlaneFetch({
|
|
176
|
+
context: 'create deployment',
|
|
177
|
+
options: {
|
|
178
|
+
body: JSON.stringify({
|
|
179
|
+
static_assets: options.staticAssets
|
|
180
|
+
}),
|
|
181
|
+
headers: {
|
|
182
|
+
Authorization: `Bearer ${accessToken}`,
|
|
183
|
+
'Content-Type': 'application/json'
|
|
184
|
+
},
|
|
185
|
+
method: 'POST'
|
|
185
186
|
},
|
|
186
|
-
|
|
187
|
+
url
|
|
187
188
|
});
|
|
188
|
-
if (!response.ok) {
|
|
189
|
-
throw new ControlPlaneError(`Failed to create deployment: ${response.status} ${response.statusText}`, response.status);
|
|
190
|
-
}
|
|
191
189
|
const data = await response.json();
|
|
192
190
|
// Map API response format to our interface
|
|
193
191
|
return {
|
|
194
|
-
codeUploadUrl: data.meta.
|
|
192
|
+
codeUploadUrl: data.meta.lambda_zip_upload_url,
|
|
195
193
|
deploymentId: data.meta.deployment_id,
|
|
196
194
|
staticAssetUploadUrls: data.meta.static_asset_upload_urls
|
|
197
195
|
};
|
|
@@ -205,36 +203,108 @@ import * as log from '../utils/log.js';
|
|
|
205
203
|
* @param options - Deployment perform options
|
|
206
204
|
* @returns Deployment status and message
|
|
207
205
|
*/ export async function performDeployment(accessToken, tenantId, options) {
|
|
208
|
-
|
|
209
|
-
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE !== 'false';
|
|
206
|
+
const shouldMock = process.env.FIGMA_MOCK_CONTROL_PLANE === 'true';
|
|
210
207
|
if (shouldMock) {
|
|
211
208
|
// MOCK IMPLEMENTATION: Return mock deployment status
|
|
212
209
|
log.debug('Using mock Control Plane API for performDeployment (FIGMA_MOCK_CONTROL_PLANE != "false")');
|
|
213
210
|
return {
|
|
214
211
|
deploymentId: options.deploymentId,
|
|
215
|
-
message: 'Deployment initiated successfully'
|
|
212
|
+
message: 'Deployment initiated successfully',
|
|
213
|
+
tenantDomains: [
|
|
214
|
+
'example.figmasource.site'
|
|
215
|
+
]
|
|
216
216
|
};
|
|
217
217
|
}
|
|
218
|
+
const url = `${getControlPlaneBaseUrl()}/v1/cms/tenant/${tenantId}/deploy/perform`;
|
|
219
|
+
log.debug(`Calling performDeployment API at ${url}`);
|
|
218
220
|
// REAL API IMPLEMENTATION
|
|
219
|
-
const response = await
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
221
|
+
const response = await controlPlaneFetch({
|
|
222
|
+
context: 'perform deployment',
|
|
223
|
+
options: {
|
|
224
|
+
body: JSON.stringify({
|
|
225
|
+
deployment_id: options.deploymentId
|
|
226
|
+
}),
|
|
227
|
+
headers: {
|
|
228
|
+
Authorization: `Bearer ${accessToken}`,
|
|
229
|
+
'Content-Type': 'application/json'
|
|
230
|
+
},
|
|
231
|
+
method: 'POST'
|
|
226
232
|
},
|
|
227
|
-
|
|
233
|
+
url
|
|
228
234
|
});
|
|
229
|
-
if (!response.ok) {
|
|
230
|
-
throw new ControlPlaneError(`Failed to perform deployment: ${response.status} ${response.statusText}`, response.status);
|
|
231
|
-
}
|
|
232
235
|
const data = await response.json();
|
|
233
236
|
// Map API response to our interface
|
|
234
237
|
return {
|
|
235
238
|
deploymentId: data.meta.deployment_id,
|
|
236
|
-
message: data.meta.message || 'Deployment initiated'
|
|
239
|
+
message: data.meta.message || 'Deployment initiated',
|
|
240
|
+
tenantDomains: data.meta.tenant_domains
|
|
237
241
|
};
|
|
238
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Get bootstrap info for a CMS resource
|
|
245
|
+
* Maps to: GET /v1/cms/:cmsResourceId/bootstrap
|
|
246
|
+
*
|
|
247
|
+
* @param accessToken - OAuth access token
|
|
248
|
+
* @param cmsResourceId - CMS Resource ID (project ID)
|
|
249
|
+
* @param environmentName - Optional environment name filter
|
|
250
|
+
*/ export async function getBootstrapInfo(accessToken, cmsResourceId, environmentName) {
|
|
251
|
+
const baseUrl = getControlPlaneBaseUrl();
|
|
252
|
+
let url = `${baseUrl}/v1/cms/${cmsResourceId}/bootstrap`;
|
|
253
|
+
if (environmentName) {
|
|
254
|
+
url += `?environment_name=${encodeURIComponent(environmentName)}`;
|
|
255
|
+
}
|
|
256
|
+
log.debug(`Calling getBootstrapInfo API at ${url}`);
|
|
257
|
+
const response = await controlPlaneFetch({
|
|
258
|
+
context: 'get bootstrap info',
|
|
259
|
+
options: {
|
|
260
|
+
headers: {
|
|
261
|
+
Authorization: `Bearer ${accessToken}`
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
url
|
|
265
|
+
});
|
|
266
|
+
const data = await response.json();
|
|
267
|
+
return {
|
|
268
|
+
environments: data.meta.environments.map((env)=>({
|
|
269
|
+
name: env.name,
|
|
270
|
+
contentSystemId: env.content_system_id,
|
|
271
|
+
tenantInstanceId: env.tenant_instance_id
|
|
272
|
+
})),
|
|
273
|
+
oauthCredentials: {
|
|
274
|
+
oauthClientId: data.meta.oauth_credentials.oauth_client_id,
|
|
275
|
+
oauthClientSecret: data.meta.oauth_credentials.oauth_client_secret
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const MAX_RETRIES = 3;
|
|
280
|
+
const INITIAL_RETRY_DELAY = 1000;
|
|
281
|
+
function sleep(ms) {
|
|
282
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
283
|
+
}
|
|
284
|
+
async function controlPlaneFetch(params) {
|
|
285
|
+
const { context, options, url } = params;
|
|
286
|
+
let lastError;
|
|
287
|
+
for(let attempt = 0; attempt < MAX_RETRIES; attempt++){
|
|
288
|
+
try {
|
|
289
|
+
const response = await fetch(url, options);
|
|
290
|
+
if (response.ok) {
|
|
291
|
+
return response;
|
|
292
|
+
}
|
|
293
|
+
if (response.status < 500) {
|
|
294
|
+
throw new ControlPlaneError(`Failed to ${context}: ${response.status} ${response.statusText}`, response.status);
|
|
295
|
+
}
|
|
296
|
+
lastError = new ControlPlaneError(`Failed to ${context}: ${response.status} ${response.statusText}`, response.status);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
if (error instanceof ControlPlaneError) {
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
lastError = error instanceof Error ? error : new Error('Unknown error');
|
|
302
|
+
}
|
|
303
|
+
if (attempt < MAX_RETRIES - 1) {
|
|
304
|
+
await sleep(INITIAL_RETRY_DELAY * Math.pow(2, attempt));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
throw new ControlPlaneError(`Network error while ${context}: ${lastError?.message || 'Unknown error'}`, undefined, lastError);
|
|
308
|
+
}
|
|
239
309
|
|
|
240
310
|
//# sourceMappingURL=control-plane.js.map
|
package/dist/api/figma-api.d.ts
CHANGED
|
@@ -5,6 +5,15 @@
|
|
|
5
5
|
* Handles project token generation and other CMS-related API calls
|
|
6
6
|
*/
|
|
7
7
|
import type { ProjectToken } from '../auth/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* User info from Figma API /v1/me endpoint
|
|
10
|
+
*/
|
|
11
|
+
export type FigmaUserInfo = {
|
|
12
|
+
email: string;
|
|
13
|
+
handle: string;
|
|
14
|
+
id: string;
|
|
15
|
+
img_url: string;
|
|
16
|
+
};
|
|
8
17
|
/**
|
|
9
18
|
* Error thrown when Figma API calls fail
|
|
10
19
|
*/
|
|
@@ -28,4 +37,15 @@ export declare class FigmaApiError extends Error {
|
|
|
28
37
|
* @throws {FigmaApiError} If the API call fails
|
|
29
38
|
*/
|
|
30
39
|
export declare function getProjectToken(accessToken: string, tenantId: string): Promise<ProjectToken>;
|
|
40
|
+
/**
|
|
41
|
+
* Get user info from Figma API
|
|
42
|
+
*
|
|
43
|
+
* Endpoint: GET https://api.figma.com/v1/me
|
|
44
|
+
* Requires OAuth access_token (not project token)
|
|
45
|
+
*
|
|
46
|
+
* @param accessToken - OAuth access token for authentication
|
|
47
|
+
* @returns FigmaUserInfo with user profile data
|
|
48
|
+
* @throws {FigmaApiError} If the API call fails
|
|
49
|
+
*/
|
|
50
|
+
export declare function getUserInfo(accessToken: string): Promise<FigmaUserInfo>;
|
|
31
51
|
//# sourceMappingURL=figma-api.d.ts.map
|
package/dist/api/figma-api.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Client for Figma REST API (Pixie) endpoints
|
|
5
5
|
* Handles project token generation and other CMS-related API calls
|
|
6
|
-
*/ import
|
|
6
|
+
*/ import { getEnvConfig } from '../constants.js';
|
|
7
|
+
import * as log from '../utils/log.js';
|
|
7
8
|
/**
|
|
8
9
|
* Error thrown when Figma API calls fail
|
|
9
10
|
*/ export class FigmaApiError extends Error {
|
|
@@ -14,19 +15,6 @@
|
|
|
14
15
|
this.name = 'FigmaApiError';
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Base URLs for Figma API
|
|
19
|
-
*/ const API_BASE_URLS = {
|
|
20
|
-
prod: 'https://api.figma.com',
|
|
21
|
-
staging: 'https://api.staging.figma.com'
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Get the Figma API base URL based on environment
|
|
25
|
-
* TODO: Use this once real API endpoints are available
|
|
26
|
-
*/ function _getApiBaseUrl() {
|
|
27
|
-
// For now, default to staging to match OAuth config
|
|
28
|
-
return process.env.FIGMA_API_BASE_URL || API_BASE_URLS.staging;
|
|
29
|
-
}
|
|
30
18
|
/**
|
|
31
19
|
* Get a project token (JWT) for a specific tenant/CMS
|
|
32
20
|
*
|
|
@@ -41,13 +29,41 @@
|
|
|
41
29
|
* @returns ProjectToken with JWT and expiry information
|
|
42
30
|
* @throws {FigmaApiError} If the API call fails
|
|
43
31
|
*/ export async function getProjectToken(accessToken, tenantId) {
|
|
44
|
-
// Check
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
// Priority 1: Check for direct token value from environment
|
|
33
|
+
const envTokenValue = process.env.FIGMA_MOCK_PROJECT_TOKEN_VALUE;
|
|
34
|
+
if (envTokenValue) {
|
|
35
|
+
log.debug('Using direct project token from FIGMA_MOCK_PROJECT_TOKEN_VALUE');
|
|
36
|
+
try {
|
|
37
|
+
// Parse JWT payload to extract claims
|
|
38
|
+
const parts = envTokenValue.split('.');
|
|
39
|
+
if (parts.length !== 3) {
|
|
40
|
+
throw new Error('Invalid JWT format: must have 3 parts (header.payload.signature)');
|
|
41
|
+
}
|
|
42
|
+
const payload = parts[1];
|
|
43
|
+
const base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
|
|
44
|
+
const paddedBase64 = base64.padEnd(base64.length + (4 - base64.length % 4) % 4, '=');
|
|
45
|
+
const decodedPayload = JSON.parse(Buffer.from(paddedBase64, 'base64').toString('utf-8'));
|
|
46
|
+
if (!decodedPayload.exp || typeof decodedPayload.exp !== 'number') {
|
|
47
|
+
throw new Error('JWT payload missing exp claim');
|
|
48
|
+
}
|
|
49
|
+
// Extract tenant ID from aud claim (use parameter as fallback)
|
|
50
|
+
const extractedTenantId = decodedPayload.aud || tenantId;
|
|
51
|
+
return {
|
|
52
|
+
expiresAt: decodedPayload.exp * 1000,
|
|
53
|
+
tenantId: extractedTenantId,
|
|
54
|
+
token: envTokenValue
|
|
55
|
+
};
|
|
56
|
+
} catch (error) {
|
|
57
|
+
throw new FigmaApiError(`Invalid JWT token in FIGMA_MOCK_PROJECT_TOKEN_VALUE: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined, error instanceof Error ? error : undefined);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Priority 2: Check if project token API should be mocked
|
|
61
|
+
// Default to false (use real API)
|
|
62
|
+
const shouldMock = process.env.FIGMA_MOCK_PROJECT_TOKEN === 'true';
|
|
47
63
|
try {
|
|
48
64
|
if (shouldMock) {
|
|
49
65
|
// MOCK IMPLEMENTATION: Generate a mock JWT token for testing
|
|
50
|
-
log.debug('Using mock project token API for getProjectToken (FIGMA_MOCK_PROJECT_TOKEN
|
|
66
|
+
log.debug('Using mock project token API for getProjectToken (FIGMA_MOCK_PROJECT_TOKEN = "true")');
|
|
51
67
|
const mockToken = createMockJWT(tenantId, 25) // 25 minutes expiry
|
|
52
68
|
;
|
|
53
69
|
// Mock response data
|
|
@@ -68,7 +84,7 @@
|
|
|
68
84
|
};
|
|
69
85
|
}
|
|
70
86
|
// REAL API IMPLEMENTATION
|
|
71
|
-
const baseUrl =
|
|
87
|
+
const baseUrl = process.env.FIGMA_API_BASE_URL || getEnvConfig().apiBaseUrl;
|
|
72
88
|
const url = `${baseUrl}/v1/cms/${tenantId}/token/`;
|
|
73
89
|
const response = await fetch(url, {
|
|
74
90
|
headers: {
|
|
@@ -81,12 +97,19 @@
|
|
|
81
97
|
let errorMessage = `Failed to get project token: ${response.status} ${response.statusText}`;
|
|
82
98
|
try {
|
|
83
99
|
const errorBody = await response.json();
|
|
84
|
-
|
|
85
|
-
|
|
100
|
+
// Only use string error messages (API may return { error: true })
|
|
101
|
+
if (typeof errorBody.message === 'string') {
|
|
102
|
+
errorMessage = errorBody.message;
|
|
103
|
+
} else if (typeof errorBody.error === 'string') {
|
|
104
|
+
errorMessage = errorBody.error;
|
|
86
105
|
}
|
|
87
106
|
} catch {
|
|
88
107
|
// Ignore JSON parse errors for error body
|
|
89
108
|
}
|
|
109
|
+
// Provide actionable error for common cases
|
|
110
|
+
if (response.status === 404) {
|
|
111
|
+
errorMessage = `Content System ID "${tenantId}" not found. Ensure FIGMA_CONTENT_API_CONTENT_SYSTEM_ID is set to a valid content system ID in your .env file.`;
|
|
112
|
+
}
|
|
90
113
|
throw new FigmaApiError(errorMessage, response.status);
|
|
91
114
|
}
|
|
92
115
|
const data = await response.json();
|
|
@@ -165,5 +188,38 @@
|
|
|
165
188
|
throw new FigmaApiError(`Failed to parse JWT expiry: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined, error instanceof Error ? error : undefined);
|
|
166
189
|
}
|
|
167
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Get user info from Figma API
|
|
193
|
+
*
|
|
194
|
+
* Endpoint: GET https://api.figma.com/v1/me
|
|
195
|
+
* Requires OAuth access_token (not project token)
|
|
196
|
+
*
|
|
197
|
+
* @param accessToken - OAuth access token for authentication
|
|
198
|
+
* @returns FigmaUserInfo with user profile data
|
|
199
|
+
* @throws {FigmaApiError} If the API call fails
|
|
200
|
+
*/ export async function getUserInfo(accessToken) {
|
|
201
|
+
const baseUrl = process.env.FIGMA_API_BASE_URL || getEnvConfig().apiBaseUrl;
|
|
202
|
+
const url = `${baseUrl}/v1/me`;
|
|
203
|
+
try {
|
|
204
|
+
const response = await fetch(url, {
|
|
205
|
+
headers: {
|
|
206
|
+
Authorization: `Bearer ${accessToken}`
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
if (!response.ok) {
|
|
210
|
+
throw new FigmaApiError(`Failed to get user info: ${response.status} ${response.statusText}`, response.status);
|
|
211
|
+
}
|
|
212
|
+
const data = await response.json();
|
|
213
|
+
if (!data.id || !data.email || typeof data.handle !== 'string') {
|
|
214
|
+
throw new FigmaApiError('Invalid user info response: missing required fields');
|
|
215
|
+
}
|
|
216
|
+
return data;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (error instanceof FigmaApiError) {
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
throw new FigmaApiError(`Failed to get user info: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined, error instanceof Error ? error : undefined);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
168
224
|
|
|
169
225
|
//# sourceMappingURL=figma-api.js.map
|
|
@@ -2,6 +2,7 @@ import { readFileSync } from 'fs';
|
|
|
2
2
|
import { createServer } from 'http';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
+
import { DEFAULT_CALLBACK_PORT } from '../config/oauth.js';
|
|
5
6
|
const filename = fileURLToPath(import.meta.url);
|
|
6
7
|
const dirname = path.dirname(filename);
|
|
7
8
|
/**
|
|
@@ -27,7 +28,7 @@ const dirname = path.dirname(filename);
|
|
|
27
28
|
server = null;
|
|
28
29
|
timeoutMs;
|
|
29
30
|
constructor(options = {}){
|
|
30
|
-
this.preferredPort = options.port ||
|
|
31
|
+
this.preferredPort = options.port || DEFAULT_CALLBACK_PORT;
|
|
31
32
|
this.timeoutMs = options.timeoutMs || 120000; // 2 minutes default
|
|
32
33
|
this.server = createServer();
|
|
33
34
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import Conf from 'conf';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import os from 'os';
|
|
4
|
-
// Configuration store for cryptographic salt
|
|
5
|
-
const cryptoConf = new Conf({
|
|
6
|
-
configName: 'payloadcms-figma-crypto',
|
|
7
|
-
projectName: 'payloadcms-figma'
|
|
8
|
-
});
|
|
9
4
|
/**
|
|
10
5
|
* Get or generate a random salt for key derivation
|
|
11
6
|
*
|
|
@@ -15,6 +10,11 @@ const cryptoConf = new Conf({
|
|
|
15
10
|
*
|
|
16
11
|
* @returns 32-byte hex string (64 characters)
|
|
17
12
|
*/ function getOrCreateSalt() {
|
|
13
|
+
// Configuration store for cryptographic salt
|
|
14
|
+
const cryptoConf = new Conf({
|
|
15
|
+
configName: 'payloadcms-figma-crypto',
|
|
16
|
+
projectName: 'payloadcms-figma'
|
|
17
|
+
});
|
|
18
18
|
let salt = cryptoConf.get('salt');
|
|
19
19
|
if (!salt) {
|
|
20
20
|
// Generate cryptographically secure random salt (32 bytes = 256 bits)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Environment } from '../constants.js';
|
|
1
2
|
import type { JWTPayload } from './types.js';
|
|
2
3
|
/**
|
|
3
4
|
* JWT validation error with specific error codes
|
|
@@ -27,7 +28,7 @@ export declare class JWTValidationError extends Error {
|
|
|
27
28
|
* @returns Promise resolving to validated JWT payload
|
|
28
29
|
* @throws {JWTValidationError} If validation fails
|
|
29
30
|
*/
|
|
30
|
-
export declare function validateProjectToken(token: string, environment:
|
|
31
|
+
export declare function validateProjectToken(token: string, environment: Environment): Promise<JWTPayload>;
|
|
31
32
|
/**
|
|
32
33
|
* Clear JWKS cache (useful for testing or forcing refresh)
|
|
33
34
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRemoteJWKSet, jwtVerify } from 'jose';
|
|
2
2
|
import { JWKSMultipleMatchingKeys, JWKSNoMatchingKey, JWSInvalid, JWSSignatureVerificationFailed, JWTExpired } from 'jose/errors';
|
|
3
|
-
import {
|
|
3
|
+
import { ENV_CONFIG } from '../constants.js';
|
|
4
4
|
/**
|
|
5
5
|
* JWT validation error with specific error codes
|
|
6
6
|
*/ export class JWTValidationError extends Error {
|
|
@@ -28,7 +28,7 @@ import { getJWKSUri } from '../constants.js';
|
|
|
28
28
|
* @param environment - Figma environment ('production' or 'staging')
|
|
29
29
|
* @returns JWKS resolver function
|
|
30
30
|
*/ function getJWKSResolver(environment) {
|
|
31
|
-
const jwksUri =
|
|
31
|
+
const jwksUri = ENV_CONFIG[environment].jwksUri;
|
|
32
32
|
if (!jwksResolvers.has(jwksUri)) {
|
|
33
33
|
jwksResolvers.set(jwksUri, createRemoteJWKSet(new URL(jwksUri), {
|
|
34
34
|
cacheMaxAge: 24 * 60 * 60 * 1000,
|
|
@@ -13,7 +13,7 @@ export declare class OAuthFlowError extends Error {
|
|
|
13
13
|
export interface OAuthFlowOptions {
|
|
14
14
|
/** OAuth2 client ID (defaults to config) */
|
|
15
15
|
clientId?: string;
|
|
16
|
-
/** Callback server port (defaults to
|
|
16
|
+
/** Callback server port (defaults to DEFAULT_CALLBACK_PORT) */
|
|
17
17
|
port?: number;
|
|
18
18
|
/** Redirect URI (defaults to config) */
|
|
19
19
|
redirectUri?: string;
|