@payloadcms/figma 0.1.0-alpha.11 → 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 +2 -0
- package/dist/api/control-plane.js +1 -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/types.d.ts +5 -3
- package/dist/commands/bootstrap.js +3 -0
- 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/plugin/build-config.js +76 -16
- package/dist/storage-content-api/api-types.d.ts +2 -2
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +1 -1
- 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/handleUpload.d.ts +1 -2
- package/dist/storage-content-api/handleUpload.js +13 -157
- package/dist/storage-content-api/index.js +16 -8
- package/dist/storage-content-api/staticHandler.d.ts +2 -1
- package/dist/storage-content-api/staticHandler.js +14 -27
- 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/load-payload-config.js +1 -6
- package/dist/utils/payload-config-ast.d.ts +5 -0
- package/dist/utils/payload-config-ast.js +68 -2
- package/dist/utils/payload-config-modifier.js +3 -0
- package/package.json +13 -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
|
@@ -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) {
|
|
@@ -124,6 +125,11 @@ import * as log from './log.js';
|
|
|
124
125
|
importSource: sharpImport?.getModuleSpecifierValue() || 'sharp'
|
|
125
126
|
};
|
|
126
127
|
}
|
|
128
|
+
if (findSharpTransformerCalls(sourceFile, configArg).length > 0) {
|
|
129
|
+
result.sharpTransformer = {
|
|
130
|
+
importSource: SHARP_TRANSFORMER_SOURCE
|
|
131
|
+
};
|
|
132
|
+
}
|
|
127
133
|
// Check for figma property
|
|
128
134
|
const figmaProperty = configArg.getProperty('figma');
|
|
129
135
|
if (figmaProperty) {
|
|
@@ -282,7 +288,27 @@ import * as log from './log.js';
|
|
|
282
288
|
modified = true;
|
|
283
289
|
}
|
|
284
290
|
}
|
|
285
|
-
// 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
|
|
286
312
|
if (detection.needsImportChange) {
|
|
287
313
|
if (payloadImport) {
|
|
288
314
|
if (detection.hasOtherPayloadImports) {
|
|
@@ -331,7 +357,7 @@ import * as log from './log.js';
|
|
|
331
357
|
modified = true;
|
|
332
358
|
}
|
|
333
359
|
}
|
|
334
|
-
//
|
|
360
|
+
// 7. Remove orphaned imports
|
|
335
361
|
// Re-fetch imports after each removal to avoid stale references
|
|
336
362
|
if (detection.dbProperty) {
|
|
337
363
|
const currentImports = sourceFile.getImportDeclarations();
|
|
@@ -360,11 +386,51 @@ import * as log from './log.js';
|
|
|
360
386
|
modified = true;
|
|
361
387
|
}
|
|
362
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
|
+
}
|
|
363
398
|
return {
|
|
364
399
|
changes,
|
|
365
400
|
modified
|
|
366
401
|
};
|
|
367
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
|
+
}
|
|
368
434
|
/**
|
|
369
435
|
* Add figma property to buildConfig if it doesn't exist
|
|
370
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 {
|
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": {
|
|
@@ -59,16 +59,17 @@
|
|
|
59
59
|
"tar": "^7.5.21",
|
|
60
60
|
"terminal-link": "^5.0.0",
|
|
61
61
|
"ts-morph": "^21.0.1",
|
|
62
|
+
"tsx": "4.23.15",
|
|
62
63
|
"uuid": "^10.0.0"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"@payloadcms/eslint-config": "3.28.0",
|
|
66
67
|
"@payloadcms/eslint-plugin": "3.28.0",
|
|
67
|
-
"@payloadcms/next": "4.0.0-canary.
|
|
68
|
-
"@payloadcms/plugin-cloud-storage": "4.0.0-canary.
|
|
69
|
-
"@payloadcms/richtext-lexical": "4.0.0-canary.
|
|
70
|
-
"@payloadcms/translations": "4.0.0-canary.
|
|
71
|
-
"@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",
|
|
72
73
|
"@swc/cli": "0.7.7",
|
|
73
74
|
"@types/archiver": "7.0.0",
|
|
74
75
|
"@types/cross-spawn": "6.0.6",
|
|
@@ -80,18 +81,17 @@
|
|
|
80
81
|
"eslint": "9.22.0",
|
|
81
82
|
"next": "^16.3.3",
|
|
82
83
|
"openapi-typescript": "^7.13.0",
|
|
83
|
-
"payload": "4.0.0-canary.
|
|
84
|
+
"payload": "4.0.0-canary.39",
|
|
84
85
|
"rimraf": "^6.1.3",
|
|
85
|
-
"tsx": "4.20.6",
|
|
86
86
|
"typescript": "5.7.3",
|
|
87
87
|
"vitest": "4.0.15"
|
|
88
88
|
},
|
|
89
89
|
"peerDependencies": {
|
|
90
|
-
"@payloadcms/plugin-cloud-storage": ">=4.0.0-canary.
|
|
91
|
-
"@payloadcms/richtext-lexical": ">=4.0.0-canary.
|
|
92
|
-
"@payloadcms/translations": ">=4.0.0-canary.
|
|
93
|
-
"@payloadcms/ui": ">=4.0.0-canary.
|
|
94
|
-
"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",
|
|
95
95
|
"react": "^19.0.1 || ^19.1.2 || ^19.2.1"
|
|
96
96
|
},
|
|
97
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
|
-
}
|
|
@@ -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
|
-
};
|