@payloadcms/figma 0.0.1-alpha.62 → 0.0.1-alpha.63

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.
Files changed (35) hide show
  1. package/dist/auth/crypto-utils.d.ts +11 -0
  2. package/dist/auth/crypto-utils.js +51 -0
  3. package/dist/auth/oauth-flow.js +3 -3
  4. package/dist/auth/project-token.d.ts +17 -6
  5. package/dist/auth/project-token.js +37 -19
  6. package/dist/auth/token-store-migration.d.ts +58 -0
  7. package/dist/auth/token-store-migration.js +156 -0
  8. package/dist/auth/token-store.d.ts +51 -128
  9. package/dist/auth/token-store.js +326 -187
  10. package/dist/auth/types.d.ts +8 -1
  11. package/dist/cli.js +6 -0
  12. package/dist/commands/debug.js +16 -12
  13. package/dist/commands/dump-tokens.d.ts +12 -0
  14. package/dist/commands/dump-tokens.js +69 -0
  15. package/dist/commands/init.js +7 -3
  16. package/dist/commands/list-tokens.js +2 -2
  17. package/dist/commands/login.js +1 -1
  18. package/dist/commands/logout.js +23 -4
  19. package/dist/db-content-api/utilities/auth.js +4 -1
  20. package/dist/oauth/defaults.d.ts +3 -1
  21. package/dist/oauth/defaults.js +6 -5
  22. package/dist/oauth/endpoints/getLoginEndpoint.js +1 -1
  23. package/dist/oauth/index.js +1 -0
  24. package/dist/oauth/types.d.ts +10 -0
  25. package/dist/plugin/auth-preflight.d.ts +8 -0
  26. package/dist/plugin/auth-preflight.js +20 -0
  27. package/dist/plugin/bootstrap-preflight.d.ts +23 -0
  28. package/dist/plugin/bootstrap-preflight.js +45 -0
  29. package/dist/plugin/build-config.js +73 -12
  30. package/dist/plugin/dev-cookie-names.d.ts +14 -0
  31. package/dist/plugin/dev-cookie-names.js +19 -0
  32. package/dist/storage-content-api/client.js +4 -1
  33. package/dist/utils/token-display.d.ts +5 -1
  34. package/dist/utils/token-display.js +47 -26
  35. package/package.json +2 -1
@@ -18,7 +18,10 @@ function createStorageAuthMiddleware(config) {
18
18
  if (auth.mode === 'apiKey') {
19
19
  request.headers.set('X-Api-Key', auth.apiKey);
20
20
  } else if (auth.mode === 'tokenStore') {
21
- const token = await getValidProjectToken(auth.tokenStore, contentSystemId);
21
+ const token = await getValidProjectToken({
22
+ tenantId: contentSystemId,
23
+ tokenStore: auth.tokenStore
24
+ });
22
25
  if (!token) {
23
26
  throw new Error('Authentication required. Run `npx @payloadcms/figma login` to authenticate.');
24
27
  }
@@ -8,7 +8,11 @@ export declare function maskToken(token: string): string;
8
8
  */
9
9
  export declare function formatTimestamp(timestamp: number): string;
10
10
  /**
11
- * Show all stored project tokens
11
+ * Show the project token for the current project + environment scope.
12
+ *
13
+ * Resolves `projectId` and `environmentName` from env vars
14
+ * (`FIGMA_PROJECT_ID`, `FIGMA_ENVIRONMENT_NAME`) — the *user's* project
15
+ * environment, which is independent of the infra env (production/staging).
12
16
  */
13
17
  export declare function showProjectTokens(tokenStore: TokenStore): void;
14
18
  //# sourceMappingURL=token-display.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import * as p from '@clack/prompts';
2
2
  import pc from 'picocolors';
3
+ import { getEnvVarSync } from './env-management.js';
3
4
  import { isDebug } from './is-debug.js';
4
5
  /**
5
6
  * Mask token for display (show first 4 and last 4 characters)
@@ -32,38 +33,58 @@ import { isDebug } from './is-debug.js';
32
33
  return pc.red(`${minutes}m`);
33
34
  }
34
35
  /**
35
- * Show all stored project tokens
36
+ * Show the project token for the current project + environment scope.
37
+ *
38
+ * Resolves `projectId` and `environmentName` from env vars
39
+ * (`FIGMA_PROJECT_ID`, `FIGMA_ENVIRONMENT_NAME`) — the *user's* project
40
+ * environment, which is independent of the infra env (production/staging).
36
41
  */ export function showProjectTokens(tokenStore) {
37
- // Get all tenant IDs that have project tokens
38
- const tenantIds = tokenStore.getAllProjectTokenTenantIds();
39
- if (tenantIds.length === 0) {
40
- p.note(pc.dim('No project tokens stored.'), `Project Tokens`);
42
+ const cwd = process.cwd();
43
+ const projectId = getEnvVarSync(cwd, 'FIGMA_PROJECT_ID');
44
+ const environmentName = getEnvVarSync(cwd, 'FIGMA_ENVIRONMENT_NAME');
45
+ if (!projectId || !environmentName) {
46
+ p.note(pc.dim('Set FIGMA_PROJECT_ID and FIGMA_ENVIRONMENT_NAME in your .env to view project tokens.'), 'Project Tokens');
41
47
  return;
42
48
  }
43
- const projectTokenLines = [];
44
- let displayedCount = 0;
45
- tenantIds.forEach((tenantId)=>{
46
- const projectToken = tokenStore.getProjectToken(tenantId);
47
- if (!projectToken) {
48
- return;
49
- }
50
- const isValid = tokenStore.hasValidProjectToken(tenantId);
51
- const status = isValid ? pc.green('✓ Valid') : pc.red('✗ Expired');
52
- if (displayedCount > 0) {
53
- projectTokenLines.push(''); // Blank line between tokens
54
- }
55
- projectTokenLines.push(`Tenant ID: ${tenantId}`);
56
- projectTokenLines.push(`Status: ${status}`);
57
- projectTokenLines.push(`Token: ${isDebug() ? projectToken.token : maskToken(projectToken.token)}`);
58
- projectTokenLines.push(`Expires: ${formatTimestamp(projectToken.expiresAt)}`);
59
- displayedCount++;
49
+ const header = [
50
+ `Project ID: ${projectId}`,
51
+ `Environment: ${environmentName}`
52
+ ];
53
+ const bootstrapData = tokenStore.getBootstrapData(projectId, environmentName);
54
+ if (!bootstrapData) {
55
+ p.note([
56
+ ...header,
57
+ pc.dim('No bootstrap data. Run `@payloadcms/figma init` to set up.')
58
+ ].join('\n'), 'Project Token');
59
+ return;
60
+ }
61
+ const projectInfo = {
62
+ environmentName,
63
+ projectId
64
+ };
65
+ const projectToken = tokenStore.getProjectToken({
66
+ projectInfo
60
67
  });
61
- // Handle case where all tokens were expired and auto-cleaned
62
- if (displayedCount === 0) {
63
- p.note(pc.dim('No project tokens stored.'), `Project Tokens`);
68
+ if (!projectToken) {
69
+ p.note([
70
+ ...header,
71
+ `Tenant ID: ${bootstrapData.contentSystemId}`,
72
+ pc.dim('No stored token.')
73
+ ].join('\n'), 'Project Token');
64
74
  return;
65
75
  }
66
- p.note(projectTokenLines.join('\n'), `Project Tokens (${displayedCount})`);
76
+ const isValid = tokenStore.hasValidProjectToken({
77
+ projectInfo
78
+ });
79
+ const status = isValid ? pc.green('✓ Valid') : pc.red('✗ Expired');
80
+ const projectTokenLines = [
81
+ ...header,
82
+ `Tenant ID: ${bootstrapData.contentSystemId}`,
83
+ `Status: ${status}`,
84
+ `Token: ${isDebug() ? projectToken.token : maskToken(projectToken.token)}`,
85
+ `Expires: ${formatTimestamp(projectToken.expiresAt)}`
86
+ ];
87
+ p.note(projectTokenLines.join('\n'), 'Project Token');
67
88
  }
68
89
 
69
90
  //# sourceMappingURL=token-display.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/figma",
3
- "version": "0.0.1-alpha.62",
3
+ "version": "0.0.1-alpha.63",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "type": "module",
6
6
  "exports": {
@@ -34,6 +34,7 @@
34
34
  "arg": "^5.0.2",
35
35
  "conf": "^13.1.0",
36
36
  "cross-spawn": "7.0.6",
37
+ "env-paths": "^3.0.0",
37
38
  "figures": "^6.1.0",
38
39
  "jose": "6.0.12",
39
40
  "jsonwebtoken": "9.0.3",