@payloadcms/figma 0.1.0-internal.10c3b07 → 0.1.0-internal.fbdc0d3
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/LICENSE.md +1 -1
- package/dist/{utils → adapters}/asset-collection.d.ts +10 -4
- package/dist/{utils → adapters}/asset-collection.js +58 -17
- package/dist/{utils → adapters}/build-lambda-zip.d.ts +4 -2
- package/dist/adapters/build-lambda-zip.js +111 -0
- package/dist/adapters/configureNextjsCache.d.ts +8 -0
- package/dist/adapters/configureNextjsCache.js +55 -0
- package/dist/{utils → adapters}/deploy-output/resolveOutputPath.d.ts +1 -1
- package/dist/adapters/fs-utils.d.ts +39 -0
- package/dist/adapters/fs-utils.js +135 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.d.ts +40 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.js +174 -0
- package/dist/adapters/nextjs.d.ts +12 -0
- package/dist/adapters/nextjs.js +67 -0
- package/dist/{utils/adapters → adapters}/nitro.d.ts +2 -2
- package/dist/{utils/adapters → adapters}/nitro.js +54 -29
- package/dist/adapters/secret-files.d.ts +25 -0
- package/dist/adapters/secret-files.js +50 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.js +1 -0
- package/dist/{utils/adapters → adapters}/vite.d.ts +1 -1
- package/dist/{utils/adapters → adapters}/vite.js +4 -3
- 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/build-lambda-zip.js +1 -1
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/init.js +72 -2
- 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/generated/content-api-types.d.ts +6 -2
- package/dist/db-content-api/utilities/auth.d.ts +1 -4
- package/dist/db-content-api/utilities/auth.js +1 -1
- package/dist/db-content-api/utilities/data/index.js +8 -2
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +3 -11
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +9 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/next/image-loader.d.ts +6 -0
- package/dist/next/image-loader.js +14 -0
- package/dist/oauth/components/LoginButton/index.js +66 -19
- package/dist/oauth/components/LoginButton/index.scss +121 -15
- package/dist/oauth/defaults.js +4 -1
- package/dist/plugin/build-config.d.ts +13 -3
- package/dist/plugin/build-config.js +198 -59
- package/dist/plugin/cache-revalidation-hooks.d.ts +6 -0
- package/dist/plugin/cache-revalidation-hooks.js +69 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +2 -1
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -1
- package/dist/plugin/make-permission-access/make-permission-access.d.ts +8 -0
- package/dist/plugin/make-permission-access/make-permission-access.js +24 -0
- package/dist/storage-content-api/api-types.d.ts +5 -2
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.d.ts +1 -1
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.js +3 -1
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +8 -6
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +17 -12
- 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 +3 -3
- package/dist/storage-content-api/buildMediaResponseHeaders.js +25 -18
- package/dist/storage-content-api/client-uploads/generate.d.ts +7 -3
- package/dist/storage-content-api/client-uploads/generate.js +22 -21
- package/dist/storage-content-api/client.d.ts +0 -2
- package/dist/storage-content-api/client.js +2 -2
- 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 +11 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +33 -0
- 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 -1
- package/dist/storage-content-api/hasSupportedContentEncoding.js +4 -2
- package/dist/storage-content-api/index.js +17 -8
- package/dist/storage-content-api/mediaErrorResponse.d.ts +1 -1
- package/dist/storage-content-api/mediaErrorResponse.js +2 -2
- package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
- package/dist/storage-content-api/shouldAttachMedia.d.ts +1 -0
- package/dist/storage-content-api/{getInlineContentType.js → shouldAttachMedia.js} +8 -7
- package/dist/storage-content-api/staticHandler.d.ts +2 -1
- package/dist/storage-content-api/staticHandler.js +47 -53
- package/dist/storage-content-api/types.d.ts +4 -1
- package/dist/storage-content-api/uploadFileData.d.ts +10 -0
- package/dist/storage-content-api/uploadFileData.js +145 -0
- package/dist/utils/build-detection.js +3 -3
- package/dist/utils/cache-bootstrap.js +1 -0
- package/dist/utils/deploy-adapter.d.ts +2 -34
- package/dist/utils/deploy-adapter.js +16 -9
- package/dist/utils/env-management.d.ts +15 -0
- package/dist/utils/env-management.js +47 -0
- package/dist/utils/lambda-config.js +14 -9
- package/dist/utils/load-payload-config.js +1 -6
- package/dist/utils/next-image-loader-config.d.ts +2 -0
- package/dist/utils/next-image-loader-config.js +63 -0
- package/dist/utils/next-image-loader-file.d.ts +2 -0
- package/dist/utils/next-image-loader-file.js +11 -0
- 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 +22 -10
- package/dist/storage-content-api/getInlineContentType.d.ts +0 -1
- 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
- package/dist/utils/adapters/nextjs.d.ts +0 -8
- package/dist/utils/adapters/nextjs.js +0 -64
- package/dist/utils/build-lambda-zip.js +0 -73
- package/dist/utils/fs-utils.d.ts +0 -12
- package/dist/utils/fs-utils.js +0 -55
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNitroOutput.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNitroOutput.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/isFile.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/isFile.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/readJson.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/readJson.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveNitroOutputLayout.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveNitroOutputLayout.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveOutputPath.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveWithin.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveWithin.js +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Node, SyntaxKind } from 'ts-morph';
|
|
2
|
+
import { FIGMA_IMAGE_LOADER_PATH } from './next-image-loader-file.js';
|
|
3
|
+
export function addFigmaImageLoaderConfig(configObject) {
|
|
4
|
+
const imagesProperty = configObject.getProperty('images');
|
|
5
|
+
if (!imagesProperty) {
|
|
6
|
+
configObject.addPropertyAssignment({
|
|
7
|
+
name: 'images',
|
|
8
|
+
initializer: `{
|
|
9
|
+
loader: 'custom',
|
|
10
|
+
loaderFile: '${FIGMA_IMAGE_LOADER_PATH}',
|
|
11
|
+
}`
|
|
12
|
+
});
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let imagesValue;
|
|
16
|
+
if (Node.isPropertyAssignment(imagesProperty)) {
|
|
17
|
+
imagesValue = imagesProperty.getInitializer();
|
|
18
|
+
} else if (Node.isShorthandPropertyAssignment(imagesProperty)) {
|
|
19
|
+
imagesValue = imagesProperty.getNameNode();
|
|
20
|
+
}
|
|
21
|
+
const imagesObject = resolveLocalObjectLiteral(imagesValue);
|
|
22
|
+
if (!imagesObject) {
|
|
23
|
+
throw new Error('Figma could not add the image loader because it could not inspect the `images` configuration. ' + 'Define `images` as an object in this Next.js config file and rerun ' + '`npx @payloadcms/figma init`.');
|
|
24
|
+
}
|
|
25
|
+
const loaderProperty = imagesObject.getProperty('loader');
|
|
26
|
+
const loaderFileProperty = imagesObject.getProperty('loaderFile');
|
|
27
|
+
if (loaderProperty || loaderFileProperty) {
|
|
28
|
+
const isFigmaLoader = getStringPropertyValue(loaderProperty) === 'custom' && getStringPropertyValue(loaderFileProperty) === FIGMA_IMAGE_LOADER_PATH;
|
|
29
|
+
if (!isFigmaLoader) {
|
|
30
|
+
throw new Error('A custom Next.js image loader is already configured, so Figma left it unchanged. ' + 'Remove the existing images.loader and images.loaderFile settings and rerun ' + '`npx @payloadcms/figma init`.');
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
imagesObject.addPropertyAssignment({
|
|
35
|
+
name: 'loader',
|
|
36
|
+
initializer: "'custom'"
|
|
37
|
+
});
|
|
38
|
+
imagesObject.addPropertyAssignment({
|
|
39
|
+
name: 'loaderFile',
|
|
40
|
+
initializer: `'${FIGMA_IMAGE_LOADER_PATH}'`
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function resolveLocalObjectLiteral(node) {
|
|
44
|
+
if (Node.isObjectLiteralExpression(node)) {
|
|
45
|
+
return node;
|
|
46
|
+
}
|
|
47
|
+
if (!Node.isIdentifier(node)) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const sourceFile = node.getSourceFile();
|
|
51
|
+
for (const definition of node.getDefinitionNodes()){
|
|
52
|
+
if (Node.isVariableDeclaration(definition) && definition.getSourceFile() === sourceFile) {
|
|
53
|
+
return definition.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
function getStringPropertyValue(property) {
|
|
59
|
+
if (!property || !Node.isPropertyAssignment(property)) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return property.getInitializerIfKind(SyntaxKind.StringLiteral)?.getLiteralValue();
|
|
63
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export const FIGMA_IMAGE_LOADER_PATH = './figma-image-loader.ts';
|
|
4
|
+
const FIGMA_IMAGE_LOADER_CONTENT = `'use client'
|
|
5
|
+
|
|
6
|
+
// Generated by @payloadcms/figma. Do not edit.
|
|
7
|
+
export { figmaNextImageLoader as default } from '@payloadcms/figma/next-image-loader'
|
|
8
|
+
`;
|
|
9
|
+
export async function writeFigmaImageLoaderFile(projectPath) {
|
|
10
|
+
await fs.writeFile(path.join(projectPath, FIGMA_IMAGE_LOADER_PATH), FIGMA_IMAGE_LOADER_CONTENT);
|
|
11
|
+
}
|
|
@@ -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-internal.
|
|
3
|
+
"version": "0.1.0-internal.fbdc0d3",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"types": "./dist/exports/client.d.ts",
|
|
15
15
|
"default": "./dist/exports/client.js"
|
|
16
16
|
},
|
|
17
|
+
"./next-image-loader": {
|
|
18
|
+
"import": "./dist/next/image-loader.js",
|
|
19
|
+
"types": "./dist/next/image-loader.d.ts",
|
|
20
|
+
"default": "./dist/next/image-loader.js"
|
|
21
|
+
},
|
|
17
22
|
"./views": {
|
|
18
23
|
"import": "./dist/exports/views.js",
|
|
19
24
|
"types": "./dist/exports/views.d.ts",
|
|
@@ -40,6 +45,7 @@
|
|
|
40
45
|
"arg": "^5.0.2",
|
|
41
46
|
"conf": "^13.1.0",
|
|
42
47
|
"cross-spawn": "7.0.6",
|
|
48
|
+
"dotenv": "^16.4.5",
|
|
43
49
|
"env-paths": "^3.0.0",
|
|
44
50
|
"figures": "^6.1.0",
|
|
45
51
|
"jose": "6.0.12",
|
|
@@ -50,36 +56,42 @@
|
|
|
50
56
|
"qs-esm": "^8.0.1",
|
|
51
57
|
"sanitize-filename": "^1.6.4",
|
|
52
58
|
"skills": "1.4.4",
|
|
53
|
-
"tar": "^7.5.
|
|
59
|
+
"tar": "^7.5.21",
|
|
54
60
|
"terminal-link": "^5.0.0",
|
|
55
61
|
"ts-morph": "^21.0.1",
|
|
62
|
+
"tsx": "4.23.15",
|
|
56
63
|
"uuid": "^10.0.0"
|
|
57
64
|
},
|
|
58
65
|
"devDependencies": {
|
|
59
66
|
"@payloadcms/eslint-config": "3.28.0",
|
|
60
67
|
"@payloadcms/eslint-plugin": "3.28.0",
|
|
61
|
-
"@payloadcms/next": "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",
|
|
62
73
|
"@swc/cli": "0.7.7",
|
|
63
74
|
"@types/archiver": "7.0.0",
|
|
64
75
|
"@types/cross-spawn": "6.0.6",
|
|
65
76
|
"@types/jsonwebtoken": "^9.0.10",
|
|
66
77
|
"@types/node": "^24.0.0",
|
|
78
|
+
"@types/react": "^19",
|
|
67
79
|
"@types/uuid": "^8.3.4",
|
|
68
80
|
"copyfiles": "^2.4.1",
|
|
69
81
|
"eslint": "9.22.0",
|
|
70
|
-
"next": "^16.
|
|
82
|
+
"next": "^16.3.3",
|
|
71
83
|
"openapi-typescript": "^7.13.0",
|
|
84
|
+
"payload": "4.0.0-canary.39",
|
|
72
85
|
"rimraf": "^6.1.3",
|
|
73
|
-
"tsx": "4.20.6",
|
|
74
86
|
"typescript": "5.7.3",
|
|
75
87
|
"vitest": "4.0.15"
|
|
76
88
|
},
|
|
77
89
|
"peerDependencies": {
|
|
78
|
-
"@payloadcms/plugin-cloud-storage": ">=4.0.0-canary.
|
|
79
|
-
"@payloadcms/richtext-lexical": ">=4.0.0-canary.
|
|
80
|
-
"@payloadcms/translations": ">=4.0.0-canary.
|
|
81
|
-
"@payloadcms/ui": ">=4.0.0-canary.
|
|
82
|
-
"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",
|
|
83
95
|
"react": "^19.0.1 || ^19.1.2 || ^19.2.1"
|
|
84
96
|
},
|
|
85
97
|
"peerDependenciesMeta": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getInlineContentType: (value: null | string | undefined) => string | null;
|
|
@@ -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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shape of the `uploadReference` this adapter attaches to client-uploaded files
|
|
3
|
-
* (via the `generate` upload-instructions handler). Payload exposes it as
|
|
4
|
-
* `unknown`, so it must be narrowed at runtime before use.
|
|
5
|
-
*/
|
|
6
|
-
export type ContentApiUploadReference = {
|
|
7
|
-
clientUploaded?: boolean;
|
|
8
|
-
filename?: string;
|
|
9
|
-
mimeType?: string;
|
|
10
|
-
prefix?: string;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Safely narrows an `unknown` uploadReference into the adapter's known shape,
|
|
14
|
-
* keeping only properties present with the expected type. Returns an empty
|
|
15
|
-
* object for any non-object input.
|
|
16
|
-
*/
|
|
17
|
-
export declare const parseUploadReference: (reference: unknown) => ContentApiUploadReference;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shape of the `uploadReference` this adapter attaches to client-uploaded files
|
|
3
|
-
* (via the `generate` upload-instructions handler). Payload exposes it as
|
|
4
|
-
* `unknown`, so it must be narrowed at runtime before use.
|
|
5
|
-
*/ /**
|
|
6
|
-
* Safely narrows an `unknown` uploadReference into the adapter's known shape,
|
|
7
|
-
* keeping only properties present with the expected type. Returns an empty
|
|
8
|
-
* object for any non-object input.
|
|
9
|
-
*/ export const parseUploadReference = (reference)=>{
|
|
10
|
-
if (!reference || typeof reference !== 'object') {
|
|
11
|
-
return {};
|
|
12
|
-
}
|
|
13
|
-
const result = {};
|
|
14
|
-
if ('clientUploaded' in reference && typeof reference.clientUploaded === 'boolean') {
|
|
15
|
-
result.clientUploaded = reference.clientUploaded;
|
|
16
|
-
}
|
|
17
|
-
if ('filename' in reference && typeof reference.filename === 'string') {
|
|
18
|
-
result.filename = reference.filename;
|
|
19
|
-
}
|
|
20
|
-
if ('mimeType' in reference && typeof reference.mimeType === 'string') {
|
|
21
|
-
result.mimeType = reference.mimeType;
|
|
22
|
-
}
|
|
23
|
-
if ('prefix' in reference && typeof reference.prefix === 'string') {
|
|
24
|
-
result.prefix = reference.prefix;
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AssetCollection, DeployAdapter, LambdaBundle, PageCollection } from '../deploy-adapter.js';
|
|
2
|
-
export declare class NextjsAdapter implements DeployAdapter {
|
|
3
|
-
name: "nextjs";
|
|
4
|
-
collectAssets(projectPath: string, output?: string): Promise<AssetCollection>;
|
|
5
|
-
collectPages(projectPath: string, output?: string): Promise<PageCollection>;
|
|
6
|
-
prepareLambdaBundle(projectPath: string, output?: string): Promise<LambdaBundle>;
|
|
7
|
-
}
|
|
8
|
-
export declare const nextjsAdapter: NextjsAdapter;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { collectSSGAssets, collectStaticAssets, collectStaticMetadataAssets } from '../asset-collection.js';
|
|
4
|
-
import { buildLambdaZip } from '../build-lambda-zip.js';
|
|
5
|
-
import { resolveOutputPath } from '../deploy-output/resolveOutputPath.js';
|
|
6
|
-
import { collectFilesRecursive } from '../fs-utils.js';
|
|
7
|
-
export class NextjsAdapter {
|
|
8
|
-
name = 'nextjs';
|
|
9
|
-
async collectAssets(projectPath, output) {
|
|
10
|
-
// Bundle assets: .next/static/ → _next/static/
|
|
11
|
-
const staticAssets = await collectStaticAssets(projectPath, output);
|
|
12
|
-
const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
|
|
13
|
-
// Public assets: public/ directory
|
|
14
|
-
const publicDir = path.join(projectPath, 'public');
|
|
15
|
-
let publicAssets = [];
|
|
16
|
-
try {
|
|
17
|
-
await fs.stat(publicDir);
|
|
18
|
-
publicAssets = await collectFilesRecursive(publicDir, publicDir);
|
|
19
|
-
} catch {
|
|
20
|
-
// No public directory
|
|
21
|
-
}
|
|
22
|
-
const metadataAssets = await collectStaticMetadataAssets(projectPath, output);
|
|
23
|
-
const pathMap = {};
|
|
24
|
-
for (const key of staticAssets){
|
|
25
|
-
pathMap[key] = path.relative(projectPath, path.join(outputPath, key.replace(/^_next\//, '')));
|
|
26
|
-
}
|
|
27
|
-
for (const key of publicAssets){
|
|
28
|
-
pathMap[key] = path.join('public', key);
|
|
29
|
-
}
|
|
30
|
-
for (const key of metadataAssets.keys){
|
|
31
|
-
pathMap[key] = metadataAssets.pathMap[key];
|
|
32
|
-
}
|
|
33
|
-
const uploadKeys = Object.keys(pathMap);
|
|
34
|
-
return {
|
|
35
|
-
pathMap,
|
|
36
|
-
routes: uploadKeys.map((key)=>`/${key}`),
|
|
37
|
-
uploadKeys
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
async collectPages(projectPath, output) {
|
|
41
|
-
const ssg = await collectSSGAssets(projectPath, output);
|
|
42
|
-
// Build route → asset keys mapping and extract unique routes
|
|
43
|
-
const routeAssetMap = {};
|
|
44
|
-
for (const key of ssg.keys){
|
|
45
|
-
// Strip extension to get the base, then derive the route
|
|
46
|
-
const base = key.replace(/\.(?:html|rsc|meta)$/, '');
|
|
47
|
-
const route = base === 'index' ? '/' : `/${base}`;
|
|
48
|
-
if (!routeAssetMap[route]) {
|
|
49
|
-
routeAssetMap[route] = [];
|
|
50
|
-
}
|
|
51
|
-
routeAssetMap[route].push(key);
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
pathMap: ssg.pathMap,
|
|
55
|
-
routeAssetMap,
|
|
56
|
-
routes: Object.keys(routeAssetMap),
|
|
57
|
-
uploadKeys: ssg.keys
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
async prepareLambdaBundle(projectPath, output) {
|
|
61
|
-
return buildLambdaZip(projectPath, output);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export const nextjsAdapter = new NextjsAdapter();
|