@payloadcms/figma 0.0.1-alpha.74 → 0.0.1-alpha.75

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.
@@ -51,6 +51,57 @@ import { getDevCookieNames } from './dev-cookie-names.js';
51
51
  readOnly: true
52
52
  },
53
53
  label: 'Profile Picture'
54
+ },
55
+ // Virtual (never persisted): populated per-request from the session JWT. The
56
+ // afterRead hook surfaces the claim on the requester's OWN user record only —
57
+ // a JWT describes its bearer, so these are meaningful for req.user, not for
58
+ // reads of other users. See defaults.ts (defaultVerify) which attaches the
59
+ // live claim to req.user.
60
+ {
61
+ name: 'userGroups',
62
+ type: 'text',
63
+ access: {
64
+ read: ({ id, req })=>req.user?.id === id
65
+ },
66
+ admin: {
67
+ readOnly: true
68
+ },
69
+ hasMany: true,
70
+ hooks: {
71
+ afterRead: [
72
+ ({ data, req })=>data?.id !== undefined && req.user?.id === data.id ? req.user.userGroups : undefined
73
+ ]
74
+ },
75
+ label: 'User Groups',
76
+ virtual: true
77
+ },
78
+ // KEEP_IN_SYNC(sinatra/controllers/api/api_payload_control_plane.rb) — resolve_make_permission
79
+ {
80
+ name: 'makePermission',
81
+ type: 'select',
82
+ access: {
83
+ read: ({ id, req })=>req.user?.id === id
84
+ },
85
+ admin: {
86
+ readOnly: true
87
+ },
88
+ hooks: {
89
+ afterRead: [
90
+ ({ data, req })=>data?.id !== undefined && req.user?.id === data.id ? req.user.makePermission : undefined
91
+ ]
92
+ },
93
+ label: 'Make Permission',
94
+ options: [
95
+ {
96
+ label: 'View',
97
+ value: 'view'
98
+ },
99
+ {
100
+ label: 'Edit',
101
+ value: 'edit'
102
+ }
103
+ ],
104
+ virtual: true
54
105
  }
55
106
  ];
56
107
  function missingOAuthCredential(name) {
@@ -176,6 +227,7 @@ export async function buildFigmaConfig(config) {
176
227
  const envConfig = getEnvConfig();
177
228
  // Resolve contentSystemId: config first, env var, then local store fallback (dev)
178
229
  let { contentSystemId } = config.figma;
230
+ let environmentId = config.figma.environmentId ?? process.env.FIGMA_EID;
179
231
  contentSystemId ??= process.env.FIGMA_CONTENT_API_CONTENT_SYSTEM_ID;
180
232
  let bootstrapData = null;
181
233
  let bootstrapReason = null;
@@ -202,9 +254,21 @@ export async function buildFigmaConfig(config) {
202
254
  }
203
255
  if (bootstrapData) {
204
256
  contentSystemId = bootstrapData.contentSystemId;
257
+ environmentId ??= bootstrapData.tenantInstanceId;
205
258
  }
206
259
  }
207
260
  }
261
+ if (!environmentId) {
262
+ const projectId = process.env.FIGMA_PROJECT_ID ?? getEnvVarSync(process.cwd(), 'FIGMA_PROJECT_ID');
263
+ const environmentName = process.env.FIGMA_ENVIRONMENT_NAME ?? getEnvVarSync(process.cwd(), 'FIGMA_ENVIRONMENT_NAME');
264
+ if (projectId && environmentName) {
265
+ bootstrapData ??= getTokenStore().getBootstrapData(projectId, environmentName);
266
+ environmentId = bootstrapData?.tenantInstanceId;
267
+ }
268
+ }
269
+ if (!environmentId) {
270
+ throw new Error('Environment ID could not be resolved. Set FIGMA_EID or initialize the project.');
271
+ }
208
272
  if (!contentSystemId) {
209
273
  logMissingContentSystemId(bootstrapReason ?? {
210
274
  kind: 'no-config'
@@ -273,7 +337,8 @@ export async function buildFigmaConfig(config) {
273
337
  custom: {
274
338
  figma: {
275
339
  ...config.figma,
276
- contentSystemId
340
+ contentSystemId,
341
+ environmentId
277
342
  }
278
343
  },
279
344
  db,
@@ -0,0 +1,9 @@
1
+ import type { Config } from 'payload';
2
+ /**
3
+ * Load a project's Payload config without initializing Payload or connecting to its database.
4
+ *
5
+ * Payload's CLI uses tsx to evaluate TypeScript config files. Resolve that same loader from the
6
+ * project's Payload installation so this also works with strict package-manager layouts where
7
+ * tsx is not a direct dependency of @payloadcms/figma.
8
+ */
9
+ export declare function loadPayloadConfig(projectPath: string): Promise<Config>;
@@ -0,0 +1,27 @@
1
+ import { createRequire } from 'node:module';
2
+ import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { findPayloadConfig } from './payload-config-finder.js';
5
+ /**
6
+ * Load a project's Payload config without initializing Payload or connecting to its database.
7
+ *
8
+ * Payload's CLI uses tsx to evaluate TypeScript config files. Resolve that same loader from the
9
+ * project's Payload installation so this also works with strict package-manager layouts where
10
+ * tsx is not a direct dependency of @payloadcms/figma.
11
+ */ export async function loadPayloadConfig(projectPath) {
12
+ const configPath = await findPayloadConfig(projectPath);
13
+ if (!configPath) {
14
+ throw new Error('Payload config not found.');
15
+ }
16
+ const absoluteConfigPath = path.resolve(projectPath, configPath);
17
+ const { loadEnv } = await import('payload/node');
18
+ loadEnv();
19
+ const requireFromProject = createRequire(path.join(projectPath, 'package.json'));
20
+ const payloadEntryPath = requireFromProject.resolve('payload');
21
+ const requireFromPayload = createRequire(payloadEntryPath);
22
+ const tsxApiPath = requireFromPayload.resolve('tsx/esm/api');
23
+ const { tsImport } = await import(pathToFileURL(tsxApiPath).href);
24
+ const parentURL = pathToFileURL(`${projectPath}${path.sep}`).href;
25
+ const imported = await tsImport(absoluteConfigPath, parentURL);
26
+ return await (imported.default ?? imported);
27
+ }
@@ -19,6 +19,7 @@ export function helpMessage() {
19
19
  ${pc.cyan('env')} Switch active environment
20
20
  ${pc.cyan('deploy')} Deploy your project to Figma
21
21
  ${pc.cyan('upgrade')} Run upgrade migrations
22
+ ${pc.cyan('upload-schema')} Upload collection schema to the Content API
22
23
  ${pc.cyan('build-lambda-zip')} Build Lambda deployment zip
23
24
 
24
25
  ${pc.bold('OPTIONS')}
@@ -68,6 +69,12 @@ export function helpMessage() {
68
69
  ${pc.cyan('@payloadcms/figma upgrade')} Run all upgrade migrations
69
70
  ${pc.dim('--dry-run')} Preview changes without applying
70
71
 
72
+ ${pc.bold('UPLOAD SCHEMA COMMAND')}
73
+
74
+ ${pc.cyan('@payloadcms/figma upload-schema')} Upload collection schema for the active environment
75
+ ${pc.dim('--id <project-id>')} Override FIGMA_PROJECT_ID
76
+ ${pc.dim('--env <environment>')} Override FIGMA_ENVIRONMENT_NAME
77
+
71
78
  ${pc.bold('GLOBAL OPTIONS')}
72
79
 
73
80
  ${pc.dim('--infra-env <env>')} Target infrastructure (production, staging, or devbox)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/figma",
3
- "version": "0.0.1-alpha.74",
3
+ "version": "0.0.1-alpha.75",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "type": "module",
6
6
  "exports": {