@payloadcms/figma 0.1.0-alpha.10 → 0.1.0-alpha.12
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 +11 -0
- package/dist/api/control-plane.js +26 -0
- package/dist/auth/headless-oauth-flow.js +4 -0
- package/dist/auth/oauth-flow.js +17 -0
- package/dist/auth/refresh.js +12 -12
- package/dist/auth/requested-scopes.d.ts +1 -0
- package/dist/auth/requested-scopes.js +3 -0
- package/dist/auth/token-store.d.ts +16 -0
- package/dist/auth/token-store.js +33 -0
- package/dist/auth/types.d.ts +5 -3
- package/dist/commands/bootstrap.js +3 -0
- package/dist/commands/init.js +71 -1
- package/dist/commands/upgrade.js +65 -1
- package/dist/commands/upload-schema.js +3 -4
- package/dist/config/oauth.js +6 -1
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +0 -3
- package/dist/db-content-api/utilities/data/index.js +6 -0
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +9 -4
- package/dist/plugin/build-config.d.ts +9 -1
- package/dist/plugin/build-config.js +158 -17
- package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +2 -1
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -1
- package/dist/storage-content-api/api-types.d.ts +5 -2
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.d.ts +1 -0
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.js +8 -0
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +12 -0
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +26 -0
- package/dist/storage-content-api/buildMediaRequestHeaders.d.ts +1 -0
- package/dist/storage-content-api/buildMediaRequestHeaders.js +14 -0
- package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +4 -0
- package/dist/storage-content-api/buildMediaResponseHeaders.js +52 -0
- package/dist/storage-content-api/client-uploads/generate.d.ts +7 -3
- package/dist/storage-content-api/client-uploads/generate.js +20 -20
- package/dist/storage-content-api/copyFile.d.ts +16 -0
- package/dist/storage-content-api/copyFile.js +90 -0
- package/dist/storage-content-api/deleteFile.d.ts +8 -0
- package/dist/storage-content-api/deleteFile.js +18 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +3 -3
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +10 -4
- package/dist/storage-content-api/getMediaType.d.ts +1 -0
- package/dist/storage-content-api/getMediaType.js +3 -0
- package/dist/storage-content-api/handleUpload.d.ts +1 -2
- package/dist/storage-content-api/handleUpload.js +13 -157
- package/dist/storage-content-api/hasSupportedContentEncoding.d.ts +1 -0
- package/dist/storage-content-api/hasSupportedContentEncoding.js +6 -0
- package/dist/storage-content-api/index.js +16 -8
- package/dist/storage-content-api/mediaErrorResponse.d.ts +1 -0
- package/dist/storage-content-api/mediaErrorResponse.js +12 -0
- package/dist/storage-content-api/shouldAttachMedia.d.ts +1 -0
- package/dist/storage-content-api/shouldAttachMedia.js +34 -0
- package/dist/storage-content-api/staticHandler.d.ts +2 -1
- package/dist/storage-content-api/staticHandler.js +85 -31
- package/dist/storage-content-api/uploadFileData.d.ts +10 -0
- package/dist/storage-content-api/uploadFileData.js +145 -0
- package/dist/utils/cache-bootstrap.js +1 -0
- package/dist/utils/env-management.d.ts +15 -0
- package/dist/utils/env-management.js +47 -0
- package/dist/utils/load-payload-config.js +1 -6
- package/dist/utils/payload-config-ast.d.ts +5 -0
- package/dist/utils/payload-config-ast.js +73 -4
- package/dist/utils/payload-config-modifier.js +3 -0
- package/dist/utils/payload-secret.d.ts +28 -0
- package/dist/utils/payload-secret.js +34 -0
- package/package.json +15 -13
- package/dist/storage-content-api/handleDelete.d.ts +0 -7
- package/dist/storage-content-api/handleDelete.js +0 -15
- package/dist/storage-content-api/utilities/getSafeFilename.d.ts +0 -11
- package/dist/storage-content-api/utilities/getSafeFilename.js +0 -59
- package/dist/storage-content-api/utilities/index.d.ts +0 -2
- package/dist/storage-content-api/utilities/index.js +0 -2
- package/dist/storage-content-api/utilities/parseUploadReference.d.ts +0 -17
- package/dist/storage-content-api/utilities/parseUploadReference.js +0 -27
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
const PART_SIZE = 64 * 1024 * 1024 // 64MB per part
|
|
3
|
+
;
|
|
4
|
+
const MAX_FILE_SIZE_BEFORE_MULTIPART = 100 * 1024 * 1024 // 100MB
|
|
5
|
+
;
|
|
6
|
+
/** Uploads file bytes to `fileKey`, with a multipart upload for large files. */ export async function uploadFileData({ client, collectionId, fileData, fileKey, fileSize = fileData.length, mimeType }) {
|
|
7
|
+
if (fileSize > MAX_FILE_SIZE_BEFORE_MULTIPART) {
|
|
8
|
+
await uploadMultipart({
|
|
9
|
+
client,
|
|
10
|
+
collectionId,
|
|
11
|
+
fileData,
|
|
12
|
+
fileKey,
|
|
13
|
+
mimeType
|
|
14
|
+
});
|
|
15
|
+
} else {
|
|
16
|
+
await uploadSingleFile({
|
|
17
|
+
client,
|
|
18
|
+
collectionId,
|
|
19
|
+
fileData,
|
|
20
|
+
fileKey,
|
|
21
|
+
mimeType
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function uploadSingleFile({ client, collectionId, fileData, fileKey, mimeType }) {
|
|
26
|
+
const { data, error, response } = await client.POST('/api/v0/uploads/sign', {
|
|
27
|
+
body: {
|
|
28
|
+
collectionId,
|
|
29
|
+
contentType: mimeType,
|
|
30
|
+
expiresIn: 3600,
|
|
31
|
+
filename: fileKey
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (error) {
|
|
35
|
+
throw new APIError(`Failed to get presigned upload URL: ${error.message}`, response.status, {
|
|
36
|
+
code: error.code
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (!data) {
|
|
40
|
+
throw new Error('No response while getting presigned upload URL');
|
|
41
|
+
}
|
|
42
|
+
const uploadResponse = await fetch(data.url, {
|
|
43
|
+
// TS's BodyInit type rejects Buffer<ArrayBufferLike>; wrap as Uint8Array
|
|
44
|
+
// (a valid ArrayBufferView) — byte-identical.
|
|
45
|
+
body: new Uint8Array(fileData),
|
|
46
|
+
headers: {
|
|
47
|
+
'Content-Type': mimeType
|
|
48
|
+
},
|
|
49
|
+
method: 'PUT'
|
|
50
|
+
});
|
|
51
|
+
if (!uploadResponse.ok) {
|
|
52
|
+
throw new Error(`Failed to upload to S3: ${uploadResponse.status} ${uploadResponse.statusText}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function uploadMultipart({ client, collectionId, fileData, fileKey, mimeType }) {
|
|
56
|
+
const { data: initiateData, error: initiateError, response: initiateResponse } = await client.POST('/api/v0/uploads/multipart/initiate', {
|
|
57
|
+
body: {
|
|
58
|
+
collectionId,
|
|
59
|
+
contentType: mimeType,
|
|
60
|
+
filename: fileKey
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (initiateError) {
|
|
64
|
+
throw new APIError(`Failed to initiate multipart upload: ${initiateError.message}`, initiateResponse.status, {
|
|
65
|
+
code: initiateError.code
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (!initiateData) {
|
|
69
|
+
throw new Error('No response while initiating multipart upload');
|
|
70
|
+
}
|
|
71
|
+
const { uploadId } = initiateData;
|
|
72
|
+
try {
|
|
73
|
+
const numParts = Math.ceil(fileData.length / PART_SIZE);
|
|
74
|
+
const partNumbers = Array.from({
|
|
75
|
+
length: numParts
|
|
76
|
+
}, (_, i)=>i + 1);
|
|
77
|
+
const { data: partsData, error: partsError, response: partsResponse } = await client.POST('/api/v0/uploads/multipart/parts', {
|
|
78
|
+
body: {
|
|
79
|
+
collectionId,
|
|
80
|
+
expiresIn: 3600,
|
|
81
|
+
filename: fileKey,
|
|
82
|
+
partNumbers,
|
|
83
|
+
uploadId
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (partsError) {
|
|
87
|
+
throw new APIError(`Failed to get part URLs: ${partsError.message}`, partsResponse.status, {
|
|
88
|
+
code: partsError.code
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (!partsData) {
|
|
92
|
+
throw new Error('No response while getting part URLs');
|
|
93
|
+
}
|
|
94
|
+
const { parts } = partsData;
|
|
95
|
+
if (!parts || !Array.isArray(parts)) {
|
|
96
|
+
throw new Error('Invalid response from part URLs endpoint: parts is not an array');
|
|
97
|
+
}
|
|
98
|
+
const uploadedParts = await Promise.all(parts.map(async ({ partNumber, url })=>{
|
|
99
|
+
const start = (partNumber - 1) * PART_SIZE;
|
|
100
|
+
const end = Math.min(start + PART_SIZE, fileData.length);
|
|
101
|
+
const partData = fileData.slice(start, end);
|
|
102
|
+
const uploadResponse = await fetch(url, {
|
|
103
|
+
body: partData,
|
|
104
|
+
headers: {
|
|
105
|
+
'Content-Type': mimeType
|
|
106
|
+
},
|
|
107
|
+
method: 'PUT'
|
|
108
|
+
});
|
|
109
|
+
const etag = uploadResponse.headers.get('ETag');
|
|
110
|
+
if (!etag) {
|
|
111
|
+
throw new Error(`No ETag returned for part ${partNumber}`);
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
ETag: etag,
|
|
115
|
+
PartNumber: partNumber
|
|
116
|
+
};
|
|
117
|
+
}));
|
|
118
|
+
const { error: completeError, response: completeResponse } = await client.POST('/api/v0/uploads/multipart/complete', {
|
|
119
|
+
body: {
|
|
120
|
+
collectionId,
|
|
121
|
+
filename: fileKey,
|
|
122
|
+
parts: uploadedParts,
|
|
123
|
+
uploadId
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (completeError) {
|
|
127
|
+
throw new APIError(`Failed to complete multipart upload: ${completeError.message}`, completeResponse.status, {
|
|
128
|
+
code: completeError.code
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
try {
|
|
133
|
+
await client.POST('/api/v0/uploads/multipart/abort', {
|
|
134
|
+
body: {
|
|
135
|
+
collectionId,
|
|
136
|
+
filename: fileKey,
|
|
137
|
+
uploadId
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
} catch {
|
|
141
|
+
// Ignore abort errors
|
|
142
|
+
}
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -6,6 +6,7 @@ import * as log from './log.js';
|
|
|
6
6
|
const { oauthCredentials } = bootstrapInfo;
|
|
7
7
|
for (const env of bootstrapInfo.environments){
|
|
8
8
|
tokenStore.setBootstrapData(projectId, env.name, {
|
|
9
|
+
contentApiUrl: env.contentApiUrl,
|
|
9
10
|
contentSystemId: env.contentSystemId,
|
|
10
11
|
oauthClientId: oauthCredentials.oauthClientId,
|
|
11
12
|
oauthClientSecret: oauthCredentials.oauthClientSecret,
|
|
@@ -14,6 +14,8 @@ export declare function getEnvVar(projectPath: string, key: string): Promise<nul
|
|
|
14
14
|
* @returns The value if found, null otherwise
|
|
15
15
|
*/
|
|
16
16
|
export declare function getEnvVarSync(projectPath: string, key: string): null | string;
|
|
17
|
+
/** Read a dotenv-parsed value without populating process.env. */
|
|
18
|
+
export declare function getParsedEnvVarSync(projectPath: string, key: string): null | string;
|
|
17
19
|
/**
|
|
18
20
|
* Add or update an environment variable in .env file
|
|
19
21
|
*
|
|
@@ -22,6 +24,19 @@ export declare function getEnvVarSync(projectPath: string, key: string): null |
|
|
|
22
24
|
* @param value - Environment variable value
|
|
23
25
|
*/
|
|
24
26
|
export declare function addOrUpdateEnvVar(projectPath: string, key: string, value: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Comment out an environment variable in .env file by prepending `# ` to any
|
|
29
|
+
* assignment line for the given key. Preserves the value so the developer can
|
|
30
|
+
* uncomment it later (or move it to another env file). No-op if the key is
|
|
31
|
+
* absent or every occurrence is already commented.
|
|
32
|
+
*
|
|
33
|
+
* @param projectPath - Path to project directory
|
|
34
|
+
* @param key - Environment variable name to disable
|
|
35
|
+
* @param annotation - Optional trailing comment appended to each disabled
|
|
36
|
+
* line, so the developer knows why it was disabled
|
|
37
|
+
* @returns true if at least one line was commented out, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
export declare function commentOutEnvVar(projectPath: string, key: string, annotation?: string): Promise<boolean>;
|
|
25
40
|
/**
|
|
26
41
|
* Remove an environment variable from .env file
|
|
27
42
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parse } from 'dotenv';
|
|
1
2
|
import fs from 'fs/promises';
|
|
2
3
|
import fsSync from 'node:fs';
|
|
3
4
|
import path from 'path';
|
|
@@ -54,6 +55,14 @@ import path from 'path';
|
|
|
54
55
|
return null;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
58
|
+
/** Read a dotenv-parsed value without populating process.env. */ export function getParsedEnvVarSync(projectPath, key) {
|
|
59
|
+
try {
|
|
60
|
+
const contents = fsSync.readFileSync(path.join(projectPath, '.env'), 'utf-8');
|
|
61
|
+
return parse(contents)[key] ?? null;
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
57
66
|
/**
|
|
58
67
|
* Add or update an environment variable in .env file
|
|
59
68
|
*
|
|
@@ -115,6 +124,44 @@ import path from 'path';
|
|
|
115
124
|
throw new Error(`Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
116
125
|
}
|
|
117
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Comment out an environment variable in .env file by prepending `# ` to any
|
|
129
|
+
* assignment line for the given key. Preserves the value so the developer can
|
|
130
|
+
* uncomment it later (or move it to another env file). No-op if the key is
|
|
131
|
+
* absent or every occurrence is already commented.
|
|
132
|
+
*
|
|
133
|
+
* @param projectPath - Path to project directory
|
|
134
|
+
* @param key - Environment variable name to disable
|
|
135
|
+
* @param annotation - Optional trailing comment appended to each disabled
|
|
136
|
+
* line, so the developer knows why it was disabled
|
|
137
|
+
* @returns true if at least one line was commented out, false otherwise
|
|
138
|
+
*/ export async function commentOutEnvVar(projectPath, key, annotation) {
|
|
139
|
+
const envPath = path.join(projectPath, '.env');
|
|
140
|
+
try {
|
|
141
|
+
const contents = await fs.readFile(envPath, 'utf-8');
|
|
142
|
+
const lines = contents.split(/\r?\n/);
|
|
143
|
+
let changed = false;
|
|
144
|
+
const updated = lines.map((line)=>{
|
|
145
|
+
if (!line.includes('=') || line.trim().startsWith('#')) {
|
|
146
|
+
return line;
|
|
147
|
+
}
|
|
148
|
+
const equalsIndex = line.indexOf('=');
|
|
149
|
+
const lineKey = line.substring(0, equalsIndex).trim();
|
|
150
|
+
if (lineKey !== key) {
|
|
151
|
+
return line;
|
|
152
|
+
}
|
|
153
|
+
changed = true;
|
|
154
|
+
const suffix = annotation ? ` # ${annotation}` : '';
|
|
155
|
+
return `# ${line}${suffix}`;
|
|
156
|
+
});
|
|
157
|
+
if (changed) {
|
|
158
|
+
await fs.writeFile(envPath, updated.join('\n'), 'utf-8');
|
|
159
|
+
}
|
|
160
|
+
return changed;
|
|
161
|
+
} catch {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
118
165
|
/**
|
|
119
166
|
* Remove an environment variable from .env file
|
|
120
167
|
*
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import { pathToFileURL } from 'node:url';
|
|
4
3
|
import { findPayloadConfig } from './payload-config-finder.js';
|
|
@@ -16,11 +15,7 @@ import { findPayloadConfig } from './payload-config-finder.js';
|
|
|
16
15
|
const absoluteConfigPath = path.resolve(projectPath, configPath);
|
|
17
16
|
const { loadEnv } = await import('payload/node');
|
|
18
17
|
loadEnv();
|
|
19
|
-
const
|
|
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);
|
|
18
|
+
const tsImport = (await import('tsx/esm/api')).tsImport;
|
|
24
19
|
const parentURL = pathToFileURL(`${projectPath}${path.sep}`).href;
|
|
25
20
|
const imported = await tsImport(absoluteConfigPath, parentURL);
|
|
26
21
|
return await (imported.default ?? imported);
|
|
@@ -34,6 +34,11 @@ export type DetectionResult = {
|
|
|
34
34
|
/** NPM package sharp is imported from (always 'sharp') */
|
|
35
35
|
importSource: string;
|
|
36
36
|
};
|
|
37
|
+
/** Payload v4 Sharp upload transformer (`upload.transformers: [sharpTransformer()]`) if present */
|
|
38
|
+
sharpTransformer?: {
|
|
39
|
+
/** NPM package the transformer is imported from (always '@payloadcms/transformer-sharp') */
|
|
40
|
+
importSource: string;
|
|
41
|
+
};
|
|
37
42
|
};
|
|
38
43
|
/**
|
|
39
44
|
* Detect what changes are needed in the payload config file
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Node, SyntaxKind } from 'ts-morph';
|
|
2
2
|
import * as log from './log.js';
|
|
3
|
+
const SHARP_TRANSFORMER_SOURCE = '@payloadcms/transformer-sharp';
|
|
3
4
|
/**
|
|
4
5
|
* Detect what changes are needed in the payload config file
|
|
5
6
|
*/ export function detectRequiredChanges(sourceFile) {
|
|
@@ -88,7 +89,10 @@ import * as log from './log.js';
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
|
-
// Check for secret property
|
|
92
|
+
// Check for secret property. The platform owns PAYLOAD_SECRET, so the
|
|
93
|
+
// scaffolded `secret: process.env.PAYLOAD_SECRET` line is stripped —
|
|
94
|
+
// `buildFigmaConfig` injects the value at runtime from the env var (in
|
|
95
|
+
// Lambda) or the TokenStore cache (local dev).
|
|
92
96
|
const secretProperty = configArg.getProperty('secret');
|
|
93
97
|
if (secretProperty) {
|
|
94
98
|
result.secretProperty = true;
|
|
@@ -121,6 +125,11 @@ import * as log from './log.js';
|
|
|
121
125
|
importSource: sharpImport?.getModuleSpecifierValue() || 'sharp'
|
|
122
126
|
};
|
|
123
127
|
}
|
|
128
|
+
if (findSharpTransformerCalls(sourceFile, configArg).length > 0) {
|
|
129
|
+
result.sharpTransformer = {
|
|
130
|
+
importSource: SHARP_TRANSFORMER_SOURCE
|
|
131
|
+
};
|
|
132
|
+
}
|
|
124
133
|
// Check for figma property
|
|
125
134
|
const figmaProperty = configArg.getProperty('figma');
|
|
126
135
|
if (figmaProperty) {
|
|
@@ -252,7 +261,7 @@ import * as log from './log.js';
|
|
|
252
261
|
modified = true;
|
|
253
262
|
}
|
|
254
263
|
}
|
|
255
|
-
// 2. Remove secret property
|
|
264
|
+
// 2. Remove secret property (platform-managed)
|
|
256
265
|
if (detection.secretProperty) {
|
|
257
266
|
const secretProperty = configArg.getProperty('secret');
|
|
258
267
|
if (secretProperty) {
|
|
@@ -279,7 +288,27 @@ import * as log from './log.js';
|
|
|
279
288
|
modified = true;
|
|
280
289
|
}
|
|
281
290
|
}
|
|
282
|
-
// 5.
|
|
291
|
+
// 5. Remove sharpTransformer from upload.transformers, then any config it leaves empty
|
|
292
|
+
if (detection.sharpTransformer) {
|
|
293
|
+
const calls = findSharpTransformerCalls(sourceFile, configArg);
|
|
294
|
+
if (calls.length > 0) {
|
|
295
|
+
const transformersArray = calls[0].getParentIfKindOrThrow(SyntaxKind.ArrayLiteralExpression);
|
|
296
|
+
for (const call of calls){
|
|
297
|
+
transformersArray.removeElement(call);
|
|
298
|
+
}
|
|
299
|
+
changes.push('Removed sharpTransformer from upload.transformers');
|
|
300
|
+
const transformersProperty = transformersArray.getParentIfKindOrThrow(SyntaxKind.PropertyAssignment);
|
|
301
|
+
const uploadObject = transformersProperty.getParentIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
|
|
302
|
+
if (transformersArray.getElements().length === 0) {
|
|
303
|
+
transformersProperty.remove();
|
|
304
|
+
}
|
|
305
|
+
if (uploadObject.getProperties().length === 0) {
|
|
306
|
+
uploadObject.getParentIfKindOrThrow(SyntaxKind.PropertyAssignment).remove();
|
|
307
|
+
}
|
|
308
|
+
modified = true;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// 6. Update buildConfig import
|
|
283
312
|
if (detection.needsImportChange) {
|
|
284
313
|
if (payloadImport) {
|
|
285
314
|
if (detection.hasOtherPayloadImports) {
|
|
@@ -328,7 +357,7 @@ import * as log from './log.js';
|
|
|
328
357
|
modified = true;
|
|
329
358
|
}
|
|
330
359
|
}
|
|
331
|
-
//
|
|
360
|
+
// 7. Remove orphaned imports
|
|
332
361
|
// Re-fetch imports after each removal to avoid stale references
|
|
333
362
|
if (detection.dbProperty) {
|
|
334
363
|
const currentImports = sourceFile.getImportDeclarations();
|
|
@@ -357,11 +386,51 @@ import * as log from './log.js';
|
|
|
357
386
|
modified = true;
|
|
358
387
|
}
|
|
359
388
|
}
|
|
389
|
+
if (detection.sharpTransformer) {
|
|
390
|
+
const currentImports = sourceFile.getImportDeclarations();
|
|
391
|
+
const transformerImport = currentImports.find((imp)=>imp.getModuleSpecifierValue() === SHARP_TRANSFORMER_SOURCE);
|
|
392
|
+
if (transformerImport) {
|
|
393
|
+
transformerImport.remove();
|
|
394
|
+
changes.push('Removed sharpTransformer import');
|
|
395
|
+
modified = true;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
360
398
|
return {
|
|
361
399
|
changes,
|
|
362
400
|
modified
|
|
363
401
|
};
|
|
364
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Find `sharpTransformer()` calls in `upload.transformers` of the config object.
|
|
405
|
+
* Returns none when the imported name is used anywhere else, so the import can be
|
|
406
|
+
* removed without breaking other code.
|
|
407
|
+
*/ function findSharpTransformerCalls(sourceFile, configArg) {
|
|
408
|
+
const transformerImport = sourceFile.getImportDeclarations().find((imp)=>imp.getModuleSpecifierValue() === SHARP_TRANSFORMER_SOURCE);
|
|
409
|
+
const specifier = transformerImport?.getNamedImports().find((ni)=>ni.getName() === 'sharpTransformer');
|
|
410
|
+
if (!transformerImport || !specifier) {
|
|
411
|
+
return [];
|
|
412
|
+
}
|
|
413
|
+
const localName = specifier.getAliasNode()?.getText() ?? 'sharpTransformer';
|
|
414
|
+
if (!Node.isObjectLiteralExpression(configArg)) {
|
|
415
|
+
return [];
|
|
416
|
+
}
|
|
417
|
+
const upload = configArg.getProperty('upload');
|
|
418
|
+
const uploadObject = Node.isPropertyAssignment(upload) ? upload.getInitializer() : undefined;
|
|
419
|
+
if (!Node.isObjectLiteralExpression(uploadObject)) {
|
|
420
|
+
return [];
|
|
421
|
+
}
|
|
422
|
+
const transformers = uploadObject.getProperty('transformers');
|
|
423
|
+
const transformersArray = Node.isPropertyAssignment(transformers) ? transformers.getInitializer() : undefined;
|
|
424
|
+
if (!Node.isArrayLiteralExpression(transformersArray)) {
|
|
425
|
+
return [];
|
|
426
|
+
}
|
|
427
|
+
const calls = transformersArray.getElements().filter((element)=>Node.isCallExpression(element) && element.getExpression().getText() === localName);
|
|
428
|
+
const references = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier).filter((id)=>id.getText() === localName && !id.getFirstAncestorByKind(SyntaxKind.ImportDeclaration));
|
|
429
|
+
if (references.length !== calls.length) {
|
|
430
|
+
return [];
|
|
431
|
+
}
|
|
432
|
+
return calls;
|
|
433
|
+
}
|
|
365
434
|
/**
|
|
366
435
|
* Add figma property to buildConfig if it doesn't exist
|
|
367
436
|
* Modifies the AST in memory - caller must call sourceFile.save()
|
|
@@ -104,6 +104,9 @@ import { getOwnVersion } from './version-check.js';
|
|
|
104
104
|
if (detection.sharpProperty) {
|
|
105
105
|
packagesToUninstall.push('sharp');
|
|
106
106
|
}
|
|
107
|
+
if (detection.sharpTransformer) {
|
|
108
|
+
packagesToUninstall.push(detection.sharpTransformer.importSource);
|
|
109
|
+
}
|
|
107
110
|
if (packagesToInstall.length > 0) {
|
|
108
111
|
log.debug(`Installing ${packagesToInstall.length} packages in a single operation: ${packagesToInstall.map((p)=>p.name).join(', ')}`);
|
|
109
112
|
try {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AuthCredential } from '../auth/credentials.js';
|
|
2
|
+
import type { TokenStore } from '../auth/token-store.js';
|
|
3
|
+
import type { ProjectStoreScope } from '../auth/types.js';
|
|
4
|
+
export declare const PAYLOAD_SECRET_ENV_VAR = "PAYLOAD_SECRET";
|
|
5
|
+
interface EnsurePayloadSecretArgs {
|
|
6
|
+
credential: AuthCredential;
|
|
7
|
+
projectInfo: ProjectStoreScope;
|
|
8
|
+
/** Fetch the current platform value even when cached, preserving the cache on failure. */
|
|
9
|
+
refresh?: boolean;
|
|
10
|
+
tenantInstanceId: string;
|
|
11
|
+
tokenStore: TokenStore;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the tenant's PAYLOAD_SECRET and cache it in the encrypted
|
|
15
|
+
* TokenStore. The secret is intentionally NOT written to `.env`: keeping it
|
|
16
|
+
* only in the machine-scoped, AES-256-GCM-encrypted store avoids the
|
|
17
|
+
* plaintext-on-disk / accidental-exfiltration risks of a project-local file.
|
|
18
|
+
* `buildFigmaConfig` reads it back from the TokenStore at dev/build time.
|
|
19
|
+
*
|
|
20
|
+
* The Figma platform owns PAYLOAD_SECRET rotation; this helper never
|
|
21
|
+
* generates or mutates the value — it only fetches whatever the Control
|
|
22
|
+
* Plane currently returns and caches it.
|
|
23
|
+
*
|
|
24
|
+
* Non-fatal on failure: callers should catch and log rather than abort init,
|
|
25
|
+
* so the sinatra endpoint rollout can lag the CLI.
|
|
26
|
+
*/
|
|
27
|
+
export declare function ensurePayloadSecret({ credential, projectInfo, refresh, tenantInstanceId, tokenStore, }: EnsurePayloadSecretArgs): Promise<string>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getEnvironmentVariableByName } from '../api/control-plane.js';
|
|
2
|
+
import * as log from './log.js';
|
|
3
|
+
export const PAYLOAD_SECRET_ENV_VAR = 'PAYLOAD_SECRET';
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the tenant's PAYLOAD_SECRET and cache it in the encrypted
|
|
6
|
+
* TokenStore. The secret is intentionally NOT written to `.env`: keeping it
|
|
7
|
+
* only in the machine-scoped, AES-256-GCM-encrypted store avoids the
|
|
8
|
+
* plaintext-on-disk / accidental-exfiltration risks of a project-local file.
|
|
9
|
+
* `buildFigmaConfig` reads it back from the TokenStore at dev/build time.
|
|
10
|
+
*
|
|
11
|
+
* The Figma platform owns PAYLOAD_SECRET rotation; this helper never
|
|
12
|
+
* generates or mutates the value — it only fetches whatever the Control
|
|
13
|
+
* Plane currently returns and caches it.
|
|
14
|
+
*
|
|
15
|
+
* Non-fatal on failure: callers should catch and log rather than abort init,
|
|
16
|
+
* so the sinatra endpoint rollout can lag the CLI.
|
|
17
|
+
*/ export async function ensurePayloadSecret({ credential, projectInfo, refresh = false, tenantInstanceId, tokenStore }) {
|
|
18
|
+
const cached = tokenStore.getPayloadSecret({
|
|
19
|
+
projectInfo
|
|
20
|
+
});
|
|
21
|
+
if (cached && !refresh) {
|
|
22
|
+
return cached;
|
|
23
|
+
}
|
|
24
|
+
const secret = await getEnvironmentVariableByName(credential, tenantInstanceId, PAYLOAD_SECRET_ENV_VAR);
|
|
25
|
+
if (!secret) {
|
|
26
|
+
throw new Error('Control Plane returned an empty PAYLOAD_SECRET');
|
|
27
|
+
}
|
|
28
|
+
tokenStore.setPayloadSecret({
|
|
29
|
+
projectInfo,
|
|
30
|
+
secret
|
|
31
|
+
});
|
|
32
|
+
log.debug(`Cached PAYLOAD_SECRET for ${projectInfo.projectId}:${projectInfo.environmentName}`);
|
|
33
|
+
return secret;
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/figma",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.12",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"arg": "^5.0.2",
|
|
46
46
|
"conf": "^13.1.0",
|
|
47
47
|
"cross-spawn": "7.0.6",
|
|
48
|
+
"dotenv": "^16.4.5",
|
|
48
49
|
"env-paths": "^3.0.0",
|
|
49
50
|
"figures": "^6.1.0",
|
|
50
51
|
"jose": "6.0.12",
|
|
@@ -58,38 +59,39 @@
|
|
|
58
59
|
"tar": "^7.5.21",
|
|
59
60
|
"terminal-link": "^5.0.0",
|
|
60
61
|
"ts-morph": "^21.0.1",
|
|
62
|
+
"tsx": "4.23.15",
|
|
61
63
|
"uuid": "^10.0.0"
|
|
62
64
|
},
|
|
63
65
|
"devDependencies": {
|
|
64
66
|
"@payloadcms/eslint-config": "3.28.0",
|
|
65
67
|
"@payloadcms/eslint-plugin": "3.28.0",
|
|
66
|
-
"@payloadcms/next": "4.0.0-canary.
|
|
67
|
-
"@payloadcms/plugin-cloud-storage": "4.0.0-canary.
|
|
68
|
-
"@payloadcms/richtext-lexical": "4.0.0-canary.
|
|
69
|
-
"@payloadcms/translations": "4.0.0-canary.
|
|
70
|
-
"@payloadcms/ui": "4.0.0-canary.
|
|
68
|
+
"@payloadcms/next": "4.0.0-canary.39",
|
|
69
|
+
"@payloadcms/plugin-cloud-storage": "4.0.0-canary.39",
|
|
70
|
+
"@payloadcms/richtext-lexical": "4.0.0-canary.39",
|
|
71
|
+
"@payloadcms/translations": "4.0.0-canary.39",
|
|
72
|
+
"@payloadcms/ui": "4.0.0-canary.39",
|
|
71
73
|
"@swc/cli": "0.7.7",
|
|
72
74
|
"@types/archiver": "7.0.0",
|
|
73
75
|
"@types/cross-spawn": "6.0.6",
|
|
74
76
|
"@types/jsonwebtoken": "^9.0.10",
|
|
75
77
|
"@types/node": "^24.0.0",
|
|
78
|
+
"@types/react": "^19",
|
|
76
79
|
"@types/uuid": "^8.3.4",
|
|
77
80
|
"copyfiles": "^2.4.1",
|
|
78
81
|
"eslint": "9.22.0",
|
|
79
82
|
"next": "^16.3.3",
|
|
80
83
|
"openapi-typescript": "^7.13.0",
|
|
81
|
-
"payload": "4.0.0-canary.
|
|
84
|
+
"payload": "4.0.0-canary.39",
|
|
82
85
|
"rimraf": "^6.1.3",
|
|
83
|
-
"tsx": "4.20.6",
|
|
84
86
|
"typescript": "5.7.3",
|
|
85
87
|
"vitest": "4.0.15"
|
|
86
88
|
},
|
|
87
89
|
"peerDependencies": {
|
|
88
|
-
"@payloadcms/plugin-cloud-storage": ">=4.0.0-canary.
|
|
89
|
-
"@payloadcms/richtext-lexical": ">=4.0.0-canary.
|
|
90
|
-
"@payloadcms/translations": ">=4.0.0-canary.
|
|
91
|
-
"@payloadcms/ui": ">=4.0.0-canary.
|
|
92
|
-
"payload": ">=4.0.0-canary.
|
|
90
|
+
"@payloadcms/plugin-cloud-storage": ">=4.0.0-canary.39 <4.0.0-internal",
|
|
91
|
+
"@payloadcms/richtext-lexical": ">=4.0.0-canary.39 <4.0.0-internal",
|
|
92
|
+
"@payloadcms/translations": ">=4.0.0-canary.39 <4.0.0-internal",
|
|
93
|
+
"@payloadcms/ui": ">=4.0.0-canary.39 <4.0.0-internal",
|
|
94
|
+
"payload": ">=4.0.0-canary.39 <4.0.0-internal",
|
|
93
95
|
"react": "^19.0.1 || ^19.1.2 || ^19.2.1"
|
|
94
96
|
},
|
|
95
97
|
"peerDependenciesMeta": {
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
export const getHandleDelete = ({ client })=>{
|
|
3
|
-
return async ({ collection, doc: { prefix = '' }, filename })=>{
|
|
4
|
-
const collectionId = collection.slug;
|
|
5
|
-
const fileKey = path.posix.join(prefix, filename);
|
|
6
|
-
await client.DELETE('/api/v0/uploads/{collectionId}/{filename}', {
|
|
7
|
-
params: {
|
|
8
|
-
path: {
|
|
9
|
-
collectionId,
|
|
10
|
-
filename: fileKey
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { PayloadRequest } from 'payload';
|
|
2
|
-
/**
|
|
3
|
-
* Get a safe filename that doesn't collide with existing documents
|
|
4
|
-
* Similar to Payload's getSafeFileName
|
|
5
|
-
*/
|
|
6
|
-
export declare function getSafeFilename({ collectionSlug, desiredFilename, prefix, req, }: {
|
|
7
|
-
collectionSlug: string;
|
|
8
|
-
desiredFilename: string;
|
|
9
|
-
prefix?: string;
|
|
10
|
-
req: PayloadRequest;
|
|
11
|
-
}): Promise<string>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import sanitize from 'sanitize-filename';
|
|
2
|
-
/**
|
|
3
|
-
* Check if a document with the given filename already exists in the database
|
|
4
|
-
* Matches Payload's docWithFilenameExists
|
|
5
|
-
*/ async function docWithFilenameExists({ collectionSlug, filename, prefix, req }) {
|
|
6
|
-
const where = {
|
|
7
|
-
filename: {
|
|
8
|
-
equals: filename
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
if (prefix) {
|
|
12
|
-
where.prefix = {
|
|
13
|
-
equals: prefix
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
const doc = await req.payload.db.findOne({
|
|
17
|
-
collection: collectionSlug,
|
|
18
|
-
req,
|
|
19
|
-
where
|
|
20
|
-
});
|
|
21
|
-
return !!doc;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Increment filename by adding -1, -2, etc. suffix
|
|
25
|
-
* photo.jpg → photo-1.jpg
|
|
26
|
-
* photo-1.jpg → photo-2.jpg
|
|
27
|
-
* Matches Payload's incrementName
|
|
28
|
-
*/ function incrementFilename(name) {
|
|
29
|
-
const extension = name.split('.').pop();
|
|
30
|
-
const baseFilename = sanitize(name.substring(0, name.lastIndexOf('.')) || name);
|
|
31
|
-
let incrementedName = baseFilename;
|
|
32
|
-
const regex = /(.*)-(\d+)$/;
|
|
33
|
-
const found = baseFilename.match(regex);
|
|
34
|
-
if (found === null) {
|
|
35
|
-
incrementedName += '-1';
|
|
36
|
-
} else {
|
|
37
|
-
const matchedName = found[1];
|
|
38
|
-
const matchedNumber = found[2];
|
|
39
|
-
const incremented = Number(matchedNumber) + 1;
|
|
40
|
-
incrementedName = `${matchedName}-${incremented}`;
|
|
41
|
-
}
|
|
42
|
-
return `${incrementedName}.${extension}`;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Get a safe filename that doesn't collide with existing documents
|
|
46
|
-
* Similar to Payload's getSafeFileName
|
|
47
|
-
*/ export async function getSafeFilename({ collectionSlug, desiredFilename, prefix, req }) {
|
|
48
|
-
let modifiedFilename = desiredFilename;
|
|
49
|
-
// Keep incrementing until we find a filename that doesn't exist
|
|
50
|
-
while(await docWithFilenameExists({
|
|
51
|
-
collectionSlug,
|
|
52
|
-
filename: modifiedFilename,
|
|
53
|
-
prefix,
|
|
54
|
-
req
|
|
55
|
-
})){
|
|
56
|
-
modifiedFilename = incrementFilename(modifiedFilename);
|
|
57
|
-
}
|
|
58
|
-
return modifiedFilename;
|
|
59
|
-
}
|