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

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.
@@ -28,6 +28,10 @@ export interface CreateTenantOptions {
28
28
  * Options for creating a new deployment
29
29
  */
30
30
  export interface CreateDeploymentOptions {
31
+ /** Framework adapter name (e.g., "vite", "nextjs"). Forwarded to Gatekeeper. */
32
+ adapter?: string;
33
+ /** SPA fallback path (e.g., "/index.html"). Vite-only. */
34
+ fallback?: string;
31
35
  /** Pages keyed by route, each with its associated asset keys */
32
36
  pages: Record<string, {
33
37
  assets: string[];
@@ -184,14 +184,21 @@ import * as log from '../utils/log.js';
184
184
  assets: pageData.assets
185
185
  };
186
186
  }
187
+ const body = {
188
+ pages,
189
+ static_assets: options.staticAssets
190
+ };
191
+ if (options.adapter) {
192
+ body.adapter = options.adapter;
193
+ }
194
+ if (options.fallback) {
195
+ body.fallback = options.fallback;
196
+ }
187
197
  // REAL API IMPLEMENTATION
188
198
  const response = await controlPlaneFetch({
189
199
  context: 'create deployment',
190
200
  options: {
191
- body: JSON.stringify({
192
- pages,
193
- static_assets: options.staticAssets
194
- }),
201
+ body: JSON.stringify(body),
195
202
  headers: {
196
203
  ...getAuthHeaders(credential),
197
204
  'Content-Type': 'application/json'
package/dist/cli.js CHANGED
@@ -68,9 +68,11 @@ class Main {
68
68
  setInfraEnvironment('production');
69
69
  } else if (infraEnvArg === 'staging') {
70
70
  setInfraEnvironment('staging');
71
+ } else if (infraEnvArg === 'devbox') {
72
+ setInfraEnvironment('devbox');
71
73
  } else {
72
74
  // eslint-disable-next-line no-console
73
- console.error(`Invalid --infra-env value: ${this.args['--infra-env']}. Use 'production' or 'staging'.`);
75
+ console.error(`Invalid --infra-env value: ${this.args['--infra-env']}. Use 'production', 'staging', or 'devbox'.`);
74
76
  process.exit(1);
75
77
  }
76
78
  }
@@ -241,6 +241,8 @@ import { loginCommand } from './login.js';
241
241
  };
242
242
  }
243
243
  const createResponse = await createDeployment(credential, tenantInstanceId, {
244
+ adapter: adapter.name,
245
+ fallback: adapter.fallback,
244
246
  pages: pagesPayload,
245
247
  staticAssets: assets.uploadKeys
246
248
  });
@@ -67,7 +67,7 @@ import { cacheAllEnvironments } from '../utils/cache-bootstrap.js';
67
67
  *
68
68
  * @param options - Command options
69
69
  */ export async function initCommand(options) {
70
- // Check for outdated version (non-blocking)
70
+ // Check for mismatched version (non-blocking)
71
71
  const currentVersion = await getOwnVersion();
72
72
  await checkForUpdates(currentVersion);
73
73
  // Check authentication
@@ -1,8 +1,16 @@
1
1
  import type { OAuthConfig } from '../auth/types.js';
2
2
  export declare const DEFAULT_CALLBACK_PORT = 34462;
3
3
  /**
4
- * Get OAuth configuration for current environment
5
- * Uses getEnvConfig() to determine staging vs production
4
+ * Get OAuth configuration for current environment.
5
+ *
6
+ * Honors env overrides:
7
+ * FIGMA_API_BASE_URL → tokenUrl, refreshUrl
8
+ * FIGMA_WEB_BASE_URL → authorizationUrl (appends /oauth)
9
+ * FIGMA_CLIENT_ID → clientId
10
+ * FIGMA_REDIRECT_URI → redirectUri
11
+ *
12
+ * When FIGMA_INFRA_ENV=devbox, FIGMA_API_BASE_URL and FIGMA_WEB_BASE_URL are
13
+ * required (ENV_CONFIG.devbox has empty URL defaults to fail-closed).
6
14
  */
7
15
  export declare function getOAuthConfig(): OAuthConfig;
8
16
  export declare const TOKEN_EXPIRY_BUFFER_SECONDS = 300;
@@ -1,10 +1,24 @@
1
- import { getEnvConfig } from '../constants.js';
1
+ import { getEnvConfig, getInfraEnvironment } from '../constants.js';
2
2
  export const DEFAULT_CALLBACK_PORT = 34462;
3
3
  /**
4
- * Get OAuth configuration for current environment
5
- * Uses getEnvConfig() to determine staging vs production
4
+ * Get OAuth configuration for current environment.
5
+ *
6
+ * Honors env overrides:
7
+ * FIGMA_API_BASE_URL → tokenUrl, refreshUrl
8
+ * FIGMA_WEB_BASE_URL → authorizationUrl (appends /oauth)
9
+ * FIGMA_CLIENT_ID → clientId
10
+ * FIGMA_REDIRECT_URI → redirectUri
11
+ *
12
+ * When FIGMA_INFRA_ENV=devbox, FIGMA_API_BASE_URL and FIGMA_WEB_BASE_URL are
13
+ * required (ENV_CONFIG.devbox has empty URL defaults to fail-closed).
6
14
  */ export function getOAuthConfig() {
7
- const { apiBaseUrl, authorizationUrl, clientId } = getEnvConfig();
15
+ const { apiBaseUrl: defaultApi, authorizationUrl: defaultAuth, clientId } = getEnvConfig();
16
+ const apiBaseUrl = process.env.FIGMA_API_BASE_URL || defaultApi;
17
+ const webBase = process.env.FIGMA_WEB_BASE_URL;
18
+ const authorizationUrl = webBase ? `${webBase}/oauth` : defaultAuth;
19
+ if (getInfraEnvironment() === 'devbox' && (!apiBaseUrl || !authorizationUrl)) {
20
+ throw new Error('FIGMA_API_BASE_URL and FIGMA_WEB_BASE_URL must be set when FIGMA_INFRA_ENV=devbox');
21
+ }
8
22
  return {
9
23
  authorizationUrl,
10
24
  clientId: process.env.FIGMA_CLIENT_ID || clientId,
@@ -1,7 +1,9 @@
1
1
  /**
2
- * Figma infrastructure environment (production or staging)
2
+ * Figma infrastructure environment (production, staging, or devbox).
3
+ * devbox is a local-dev mode that requires FIGMA_API_BASE_URL and
4
+ * FIGMA_WEB_BASE_URL env overrides to point at a Coder devbox.
3
5
  */
4
- export type Environment = 'production' | 'staging';
6
+ export type Environment = 'devbox' | 'production' | 'staging';
5
7
  type EnvironmentConfig = {
6
8
  /** Figma API base URL. Override: FIGMA_API_BASE_URL */
7
9
  apiBaseUrl: string;
package/dist/constants.js CHANGED
@@ -18,6 +18,17 @@ import { getEnvVarSync } from './utils/env-management.js';
18
18
  contentApiUrl: 'https://us-east-1.cms-tenants-001-staging.figmacontentstaging.com',
19
19
  identityMetadata: 'https://staging.figma.com/.well-known/openid-configuration',
20
20
  jwksUri: 'https://static.figmacontentstaging.com/.well_known/jwks.json'
21
+ },
22
+ // Empty URLs are intentional: devbox mode requires FIGMA_API_BASE_URL and
23
+ // FIGMA_WEB_BASE_URL to be set, validated at getOAuthConfig() time.
24
+ // clientId defaults to the dev seed value in sinatra/db/seeds.rb.
25
+ devbox: {
26
+ apiBaseUrl: '',
27
+ authorizationUrl: '',
28
+ clientId: 'rNZBcf3xBDmI76mQ9603su',
29
+ contentApiUrl: '',
30
+ identityMetadata: '',
31
+ jwksUri: ''
21
32
  }
22
33
  };
23
34
  /**
@@ -58,9 +69,13 @@ export function getInfraEnvironment() {
58
69
  return envOverride;
59
70
  }
60
71
  // Check process.env first (case-insensitive)
61
- if (process.env.FIGMA_INFRA_ENV?.toLowerCase() === 'staging') {
72
+ const processEnv = process.env.FIGMA_INFRA_ENV?.toLowerCase();
73
+ if (processEnv === 'staging') {
62
74
  return 'staging';
63
75
  }
76
+ if (processEnv === 'devbox') {
77
+ return 'devbox';
78
+ }
64
79
  // Fall back to .env file in cwd (check both new and old env var names)
65
80
  const envFileValue = getEnvVarSync(process.cwd(), 'FIGMA_INFRA_ENV') ?? getEnvVarSync(process.cwd(), 'FIGMA_ENV');
66
81
  if (envFileValue) {
@@ -68,6 +83,9 @@ export function getInfraEnvironment() {
68
83
  if (env === 'staging') {
69
84
  return 'staging';
70
85
  }
86
+ if (env === 'devbox') {
87
+ return 'devbox';
88
+ }
71
89
  if (env !== 'production') {
72
90
  // eslint-disable-next-line no-console
73
91
  console.warn(`Warning: Invalid FIGMA_INFRA_ENV value "${envFileValue}" in .env file. Using production.`);
@@ -8,6 +8,7 @@ import { addFallbackSort } from './temp-utilities/sorting.js';
8
8
  import { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js';
9
9
  import { createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js';
10
10
  import { dataToContentAPI, resolveVersionContent } from './utilities/data/index.js';
11
+ import { validateRelationshipIds } from './utilities/data/validateRelationships.js';
11
12
  import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
12
13
  import { addFallbackLocale } from './utilities/locale/index.js';
13
14
  import { buildMeta } from './utilities/meta/buildMeta.js';
@@ -353,6 +354,11 @@ async function findDistinct(args) {
353
354
  }
354
355
  async function updateMany(args) {
355
356
  const locale = addFallbackLocale(args.locale, this.payload);
357
+ validateRelationshipIds({
358
+ collectionSlug: args.collection,
359
+ data: args.data,
360
+ payload: this.payload
361
+ });
356
362
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
357
363
  body: {
358
364
  collection: args.collection,
@@ -394,6 +400,11 @@ async function updateOne(args) {
394
400
  equals: args.id
395
401
  }
396
402
  };
403
+ validateRelationshipIds({
404
+ collectionSlug: args.collection,
405
+ data: args.data,
406
+ payload: this.payload
407
+ });
397
408
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
398
409
  body: {
399
410
  collection: args.collection,
@@ -498,6 +509,11 @@ async function create(args) {
498
509
  id = uuid();
499
510
  }
500
511
  const locale = addFallbackLocale(args.locale, this.payload);
512
+ validateRelationshipIds({
513
+ collectionSlug: args.collection,
514
+ data: args.data,
515
+ payload: this.payload
516
+ });
501
517
  const { data: response, error } = await this.client.POST('/api/v0/documents:create', {
502
518
  body: {
503
519
  collection: args.collection,
@@ -611,6 +627,11 @@ async function upsert(args) {
611
627
  documentId = uuid();
612
628
  }
613
629
  const locale = addFallbackLocale(args.locale, this.payload);
630
+ validateRelationshipIds({
631
+ collectionSlug: args.collection,
632
+ data: args.data,
633
+ payload: this.payload
634
+ });
614
635
  const { data: response, error } = await this.client.POST('/api/v0/documents:update', {
615
636
  body: {
616
637
  collection: args.collection,
@@ -0,0 +1,7 @@
1
+ import type { Payload } from 'payload';
2
+ export declare function validateRelationshipIds({ collectionSlug, data, payload, }: {
3
+ collectionSlug: string;
4
+ data: Record<string, unknown>;
5
+ payload: Payload;
6
+ }): void;
7
+ //# sourceMappingURL=validateRelationships.d.ts.map
@@ -0,0 +1,102 @@
1
+ import { traverseFields } from 'payload';
2
+ const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3
+ function collectRelationshipValues({ data, fields }) {
4
+ const relationships = [];
5
+ const callback = ({ field, ref })=>{
6
+ if (!('name' in field) || !field.name) {
7
+ return;
8
+ }
9
+ if (field.type !== 'relationship' && field.type !== 'upload') {
10
+ return;
11
+ }
12
+ if (!ref || typeof ref !== 'object') {
13
+ return;
14
+ }
15
+ const rawValue = ref[field.name];
16
+ if (rawValue == null || rawValue === '') {
17
+ return;
18
+ }
19
+ // For localized fields, the value is a locale map (e.g. { en: "uuid", fr: "uuid" }).
20
+ // Iterate locale values instead of treating the map as an ID.
21
+ if ('localized' in field && field.localized) {
22
+ if (typeof rawValue === 'object' && !Array.isArray(rawValue)) {
23
+ for (const localeValue of Object.values(rawValue)){
24
+ if (localeValue != null && localeValue !== '') {
25
+ parseRelationshipValues(localeValue, field.relationTo, relationships);
26
+ }
27
+ }
28
+ }
29
+ return;
30
+ }
31
+ parseRelationshipValues(rawValue, field.relationTo, relationships);
32
+ };
33
+ traverseFields({
34
+ callback,
35
+ fields,
36
+ fillEmpty: false,
37
+ ref: data
38
+ });
39
+ return relationships;
40
+ }
41
+ function parseRelationshipValues(value, relationTo, relationships) {
42
+ if (Array.isArray(relationTo)) {
43
+ // Polymorphic (single or hasMany): value is { relationTo, value } or array of them
44
+ const values = Array.isArray(value) ? value : [
45
+ value
46
+ ];
47
+ for (const v of values){
48
+ if (v && typeof v === 'object' && 'relationTo' in v && 'value' in v) {
49
+ const obj = v;
50
+ if (obj.value != null && obj.value !== '') {
51
+ relationships.push({
52
+ collection: obj.relationTo,
53
+ value: obj.value
54
+ });
55
+ }
56
+ }
57
+ }
58
+ } else {
59
+ // Non-polymorphic (single or hasMany): value is a bare ID or array of IDs
60
+ const values = Array.isArray(value) ? value : [
61
+ value
62
+ ];
63
+ for (const v of values){
64
+ if (v != null && v !== '') {
65
+ relationships.push({
66
+ collection: relationTo,
67
+ value: v
68
+ });
69
+ }
70
+ }
71
+ }
72
+ }
73
+ function isValidId(value, customIDType) {
74
+ if (customIDType === 'number') {
75
+ const num = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : NaN;
76
+ return Number.isFinite(num);
77
+ }
78
+ if (customIDType === 'text') {
79
+ return typeof value === 'string' && value.length > 0;
80
+ }
81
+ return typeof value === 'string' && UUID_REGEX.test(value);
82
+ }
83
+ export function validateRelationshipIds({ collectionSlug, data, payload }) {
84
+ const isGlobal = collectionSlug.startsWith('_global-');
85
+ const actualSlug = isGlobal ? collectionSlug.substring(8) : collectionSlug;
86
+ const config = isGlobal ? payload.config.globals?.find((g)=>g.slug === actualSlug) : payload.config.collections.find((c)=>c.slug === actualSlug);
87
+ if (!config?.fields) {
88
+ return;
89
+ }
90
+ const relationships = collectRelationshipValues({
91
+ data,
92
+ fields: config.fields
93
+ });
94
+ for (const { collection, value } of relationships){
95
+ const customIDType = payload.collections?.[collection]?.customIDType;
96
+ if (!isValidId(value, customIDType)) {
97
+ throw new Error(`Invalid relationship ID "${String(value)}" for collection "${collection}". Expected ${customIDType === 'number' ? 'a number' : customIDType === 'text' ? 'a non-empty string' : 'a valid UUID'}.`);
98
+ }
99
+ }
100
+ }
101
+
102
+ //# sourceMappingURL=validateRelationships.js.map
@@ -23,24 +23,7 @@ export const getHandler = ({ client, collection })=>{
23
23
  status: 500
24
24
  });
25
25
  }
26
- // Fetch file bytes from S3 (required for Payload's image processing)
27
- const fileResponse = await fetch(data.url);
28
- if (!fileResponse.ok) {
29
- req.payload.logger.error(`S3 fetch failed: ${fileResponse.status} ${fileResponse.statusText}`);
30
- return new Response('Failed to fetch file from storage', {
31
- status: 502
32
- });
33
- }
34
- const contentType = fileResponse.headers.get('content-type') || 'application/octet-stream';
35
- const contentLength = fileResponse.headers.get('content-length');
36
- return new Response(fileResponse.body, {
37
- headers: {
38
- 'Content-Type': contentType,
39
- ...contentLength && {
40
- 'Content-Length': contentLength
41
- }
42
- }
43
- });
26
+ return Response.redirect(data.url, 302);
44
27
  } catch (err) {
45
28
  req.payload.logger.error({
46
29
  err,
@@ -4,8 +4,10 @@
4
4
  * Cross-platform replacement for build_for_lambda.sh:
5
5
  * 1. Copies .next/static to .next/standalone/.next/static
6
6
  * 2. Copies run.sh to .next/standalone/run.sh
7
- * 3. Copies public/ to .next/standalone/public/ (if exists)
8
- * 4. Creates lambda.zip from .next/standalone/
7
+ * 3. Creates lambda.zip from .next/standalone/
8
+ *
9
+ * Note: public/ is NOT included in the zip — those files are uploaded
10
+ * as static assets and served via CDN, not from the Lambda function.
9
11
  *
10
12
  * @param projectPath - Path to project root
11
13
  * @throws Error if standalone directory missing or zip creation fails
@@ -8,15 +8,16 @@ import path from 'path';
8
8
  * Cross-platform replacement for build_for_lambda.sh:
9
9
  * 1. Copies .next/static to .next/standalone/.next/static
10
10
  * 2. Copies run.sh to .next/standalone/run.sh
11
- * 3. Copies public/ to .next/standalone/public/ (if exists)
12
- * 4. Creates lambda.zip from .next/standalone/
11
+ * 3. Creates lambda.zip from .next/standalone/
12
+ *
13
+ * Note: public/ is NOT included in the zip — those files are uploaded
14
+ * as static assets and served via CDN, not from the Lambda function.
13
15
  *
14
16
  * @param projectPath - Path to project root
15
17
  * @throws Error if standalone directory missing or zip creation fails
16
18
  */ export async function buildLambdaZip(projectPath) {
17
19
  const standalonePath = path.join(projectPath, '.next', 'standalone');
18
20
  const staticPath = path.join(projectPath, '.next', 'static');
19
- const publicPath = path.join(projectPath, 'public');
20
21
  const runShPath = path.join(projectPath, 'run.sh');
21
22
  const zipPath = path.join(projectPath, 'lambda.zip');
22
23
  if (!await isDirectory(standalonePath)) {
@@ -31,10 +32,6 @@ import path from 'path';
31
32
  } catch {
32
33
  // run.sh may not exist in all setups
33
34
  }
34
- if (await isDirectory(publicPath)) {
35
- const destPublic = path.join(standalonePath, 'public');
36
- await copyDirectory(publicPath, destPublic);
37
- }
38
35
  await createZip(standalonePath, zipPath);
39
36
  }
40
37
  async function isDirectory(dirPath) {
@@ -59,7 +59,7 @@ export function helpMessage() {
59
59
 
60
60
  ${pc.bold('GLOBAL OPTIONS')}
61
61
 
62
- ${pc.dim('--infra-env <env>')} Target infrastructure (production or staging)
62
+ ${pc.dim('--infra-env <env>')} Target infrastructure (production, staging, or devbox)
63
63
 
64
64
  ${pc.bold('DOCUMENTATION')}
65
65
 
@@ -21,7 +21,7 @@ export async function checkForUpdates(currentVersion) {
21
21
  if (!latestVersion || latestVersion === currentVersion) {
22
22
  return;
23
23
  }
24
- p.log.warn(pc.yellow(`@payloadcms/figma ${currentVersion} is outdated. Latest: ${latestVersion}`));
24
+ p.log.warn(pc.yellow(`@payloadcms/figma ${currentVersion} differs from latest. Latest: ${latestVersion}`));
25
25
  p.log.message(pc.dim(` Run: npx @payloadcms/figma@${latestVersion} init --id <your-id>`));
26
26
  } catch {
27
27
  // Silent catch - network errors, timeouts, parse errors should not interrupt CLI
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/figma",
3
- "version": "0.0.1-alpha.61",
3
+ "version": "0.0.1-alpha.62",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "type": "module",
6
6
  "exports": {