@payloadcms/figma 0.1.0-alpha.1 → 0.1.0-internal.e071575

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.
@@ -18,6 +18,7 @@ import * as log from '../utils/log.js';
18
18
  import { logMissingCliAuth } from './auth-preflight.js';
19
19
  import { logMissingContentSystemId } from './bootstrap-preflight.js';
20
20
  import { getDevCookieNames } from './dev-cookie-names.js';
21
+ import { createSandboxUploadFetchPlugin } from './sandbox-upload-fetch.js';
21
22
  /**
22
23
  * Worker-trusted marker injected by Figma's sites-worker after it validates the
23
24
  * X-Figma-Job-Queues-Auth-Bypass secret on a Payload jobs endpoint. The default
@@ -392,7 +393,10 @@ export async function buildFigmaConfig(config) {
392
393
  debug: !!process.env.DEBUG,
393
394
  disabled: false
394
395
  }),
395
- scheduleExtractPlugin()
396
+ scheduleExtractPlugin(),
397
+ // Not folded into createStoragePlugin: that one is skipped when
398
+ // figma.storage is false, which would break remote uploads for those apps.
399
+ createSandboxUploadFetchPlugin()
396
400
  ]
397
401
  };
398
402
  // Inject figma fields into users collection
@@ -0,0 +1,30 @@
1
+ import type { Config } from 'payload';
2
+ /**
3
+ * True inside the Make sandbox. agentplat injects `FIGMA=1` into every sandbox
4
+ * process; it is absent locally and in the deployed Lambda. `FIGMA=true` is
5
+ * accepted because the Make app template's `vite.config.ts` treats both as
6
+ * sandbox markers.
7
+ *
8
+ * KEEP_IN_SYNC(services/agentplat/scriptrun/script_runner.go): EnvFigma
9
+ */
10
+ export declare function isMakeSandbox(): boolean;
11
+ /**
12
+ * Lets upload collections fetch remote files inside the Make sandbox, where DNS
13
+ * maps external hostnames to unique-local IPv6 addresses (`fc00::/7`) and
14
+ * `safeFetch` rejects every resolved range that is not `unicast`. Outside the
15
+ * sandbox this is a no-op.
16
+ *
17
+ * `skipSafeFetch` is forced rather than defaulted with `??`, because
18
+ * `@payloadcms/plugin-cloud-storage` recomputes it on every upload collection
19
+ * and a nullish default would never fire. An app's own setting loses here.
20
+ *
21
+ * `externalFileHeaderFilter` is deliberately left unset: it replaces Payload's
22
+ * cookie logic wholesale, including the branch that forwards cookies for
23
+ * relative URLs.
24
+ *
25
+ * Accepted risks, all bounded by the auth gate on the upload routes and the
26
+ * sandbox's network limits: `getExternalFile` re-validates its three redirect
27
+ * hops only against `pasteURL.allowList`; any session can make the server GET
28
+ * an arbitrary URL and read the body; request cookies reach the fetch target.
29
+ */
30
+ export declare function createSandboxUploadFetchPlugin(): (config: Config) => Config;
@@ -0,0 +1,59 @@
1
+ import * as log from '../utils/log.js';
2
+ /**
3
+ * True inside the Make sandbox. agentplat injects `FIGMA=1` into every sandbox
4
+ * process; it is absent locally and in the deployed Lambda. `FIGMA=true` is
5
+ * accepted because the Make app template's `vite.config.ts` treats both as
6
+ * sandbox markers.
7
+ *
8
+ * KEEP_IN_SYNC(services/agentplat/scriptrun/script_runner.go): EnvFigma
9
+ */ export function isMakeSandbox() {
10
+ return process.env.FIGMA === '1' || process.env.FIGMA === 'true';
11
+ }
12
+ /**
13
+ * Lets upload collections fetch remote files inside the Make sandbox, where DNS
14
+ * maps external hostnames to unique-local IPv6 addresses (`fc00::/7`) and
15
+ * `safeFetch` rejects every resolved range that is not `unicast`. Outside the
16
+ * sandbox this is a no-op.
17
+ *
18
+ * `skipSafeFetch` is forced rather than defaulted with `??`, because
19
+ * `@payloadcms/plugin-cloud-storage` recomputes it on every upload collection
20
+ * and a nullish default would never fire. An app's own setting loses here.
21
+ *
22
+ * `externalFileHeaderFilter` is deliberately left unset: it replaces Payload's
23
+ * cookie logic wholesale, including the branch that forwards cookies for
24
+ * relative URLs.
25
+ *
26
+ * Accepted risks, all bounded by the auth gate on the upload routes and the
27
+ * sandbox's network limits: `getExternalFile` re-validates its three redirect
28
+ * hops only against `pasteURL.allowList`; any session can make the server GET
29
+ * an arbitrary URL and read the body; request cookies reach the fetch target.
30
+ */ export function createSandboxUploadFetchPlugin() {
31
+ return (config)=>{
32
+ if (!isMakeSandbox()) {
33
+ return config;
34
+ }
35
+ const modifiedSlugs = [];
36
+ const collections = (config.collections ?? []).map((collection)=>{
37
+ if (!collection.upload) {
38
+ return collection;
39
+ }
40
+ modifiedSlugs.push(collection.slug);
41
+ const upload = collection.upload === true ? {} : collection.upload;
42
+ return {
43
+ ...collection,
44
+ upload: {
45
+ ...upload,
46
+ skipSafeFetch: true
47
+ }
48
+ };
49
+ });
50
+ if (modifiedSlugs.length === 0) {
51
+ return config;
52
+ }
53
+ log.debug(`Make sandbox detected: upload collections skip safeFetch (${modifiedSlugs.join(', ')})`);
54
+ return {
55
+ ...config,
56
+ collections
57
+ };
58
+ };
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/figma",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-internal.e071575",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "type": "module",
6
6
  "exports": {
@@ -97,6 +97,7 @@
97
97
  "generate:types": "tsx scripts/generate-types.ts",
98
98
  "lint": "eslint .",
99
99
  "lint:fix": "eslint . --fix",
100
+ "payload:cli": "tsx scripts/payload-cli.ts",
100
101
  "start": "pnpm build && node ./bin/cli.js",
101
102
  "test": "TEST_UNIT=true vitest run",
102
103
  "test:int": "TEST_INT=true vitest run --config vitest.config.int.ts",