@payloadcms/figma 1.0.0-beta.2 → 1.0.0-beta.3
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.
|
@@ -9,6 +9,7 @@ import { getGlobalSlug } from './temp-utilities/slug.js';
|
|
|
9
9
|
import { addFallbackSort } from './temp-utilities/sorting.js';
|
|
10
10
|
import { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js';
|
|
11
11
|
import { getClientVersionHeaders } from './utilities/clientVersionHeaders.js';
|
|
12
|
+
import { getCorrelationHeaders } from './utilities/correlationIds.js';
|
|
12
13
|
import { dataToContentAPI, resolveVersionContent } from './utilities/data/index.js';
|
|
13
14
|
import { injectGlobalType } from './utilities/data/injectGlobalType.js';
|
|
14
15
|
import { validateRelationshipIds } from './utilities/data/validateRelationships.js';
|
|
@@ -39,6 +40,7 @@ async function syncCollections() {
|
|
|
39
40
|
let existingIds;
|
|
40
41
|
try {
|
|
41
42
|
const { data: response, error, response: httpResponse } = await this.client.GET('/api/v0/content_systems/{contentSystemId}/collections', {
|
|
43
|
+
headers: getCorrelationHeaders(),
|
|
42
44
|
params: {
|
|
43
45
|
path: {
|
|
44
46
|
contentSystemId: this.contentSystemId
|
|
@@ -104,6 +106,7 @@ async function createCollection(collectionId) {
|
|
|
104
106
|
body: {
|
|
105
107
|
id: collectionId
|
|
106
108
|
},
|
|
109
|
+
headers: getCorrelationHeaders(),
|
|
107
110
|
params: {
|
|
108
111
|
path: {
|
|
109
112
|
contentSystemId: this.contentSystemId
|
|
@@ -121,7 +124,7 @@ async function createCollection(collectionId) {
|
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
|
-
async function findMany({ collection, joins, limit, locale: localeArg, page, pagination: _pagination, sort, where }) {
|
|
127
|
+
async function findMany({ collection, joins, limit, locale: localeArg, page, pagination: _pagination, req, sort, where }) {
|
|
125
128
|
const locale = addFallbackLocale(localeArg, this.payload);
|
|
126
129
|
const localeNormalizedWhere = normalizeLocaleInWhere(where, this.payload, collection, locale);
|
|
127
130
|
const joinClause = convertPayloadJoinsToContentAPI(this.payload, collection, joins);
|
|
@@ -136,7 +139,8 @@ async function findMany({ collection, joins, limit, locale: localeArg, page, pag
|
|
|
136
139
|
schema: this.documentSchema(),
|
|
137
140
|
sort: addFallbackSort(sort, this.payload, collection),
|
|
138
141
|
where: convertPayloadWhereToContentAPI(localeNormalizedWhere, this.payload, collection, false)
|
|
139
|
-
}
|
|
142
|
+
},
|
|
143
|
+
headers: getCorrelationHeaders(req)
|
|
140
144
|
});
|
|
141
145
|
if (error) {
|
|
142
146
|
throw createDocumentContentAPIError(this, 'findMany', error, httpResponse.status, collection);
|
|
@@ -160,6 +164,7 @@ async function find(args) {
|
|
|
160
164
|
locale: args.locale,
|
|
161
165
|
page: args.page ?? 1,
|
|
162
166
|
pagination: args.pagination,
|
|
167
|
+
req: args.req,
|
|
163
168
|
sort: args.sort || collectionConfig?.defaultSort,
|
|
164
169
|
where: args.where
|
|
165
170
|
});
|
|
@@ -181,7 +186,8 @@ async function findVersions(args) {
|
|
|
181
186
|
schema: this.documentSchema(),
|
|
182
187
|
sort: sortWithFallback,
|
|
183
188
|
where: whereClause
|
|
184
|
-
}
|
|
189
|
+
},
|
|
190
|
+
headers: getCorrelationHeaders(args.req)
|
|
185
191
|
});
|
|
186
192
|
if (error) {
|
|
187
193
|
throw createDocumentContentAPIError(this, 'findVersions', error, httpResponse.status, args.collection);
|
|
@@ -198,6 +204,7 @@ async function queryDrafts(args) {
|
|
|
198
204
|
locale: args.locale,
|
|
199
205
|
page: args.page,
|
|
200
206
|
pagination: args.pagination,
|
|
207
|
+
req: args.req,
|
|
201
208
|
sort: args.sort,
|
|
202
209
|
where: {
|
|
203
210
|
...args.where,
|
|
@@ -240,7 +247,8 @@ async function createVersion(args) {
|
|
|
240
247
|
updatedAt: args.updatedAt,
|
|
241
248
|
version: versionContent
|
|
242
249
|
}
|
|
243
|
-
}
|
|
250
|
+
},
|
|
251
|
+
headers: getCorrelationHeaders(args.req)
|
|
244
252
|
});
|
|
245
253
|
if (error) {
|
|
246
254
|
throw createDocumentContentAPIError(this, 'createVersion', error, httpResponse.status, args.collectionSlug);
|
|
@@ -283,7 +291,8 @@ async function updateVersion(args) {
|
|
|
283
291
|
version: versionContent
|
|
284
292
|
},
|
|
285
293
|
where: convertPayloadWhereToContentAPI(where, this.payload, args.collection, true)
|
|
286
|
-
}
|
|
294
|
+
},
|
|
295
|
+
headers: getCorrelationHeaders(args.req)
|
|
287
296
|
});
|
|
288
297
|
if (error) {
|
|
289
298
|
throw createDocumentContentAPIError(this, 'updateVersion', error, httpResponse.status, args.collection);
|
|
@@ -318,7 +327,8 @@ async function deleteVersions(args) {
|
|
|
318
327
|
locale,
|
|
319
328
|
schema: this.documentSchema(),
|
|
320
329
|
where: convertPayloadWhereToContentAPI(args.where, this.payload, collection, true)
|
|
321
|
-
}
|
|
330
|
+
},
|
|
331
|
+
headers: getCorrelationHeaders(args.req)
|
|
322
332
|
});
|
|
323
333
|
if (error) {
|
|
324
334
|
throw createDocumentContentAPIError(this, 'deleteVersions', error, httpResponse.status, collection);
|
|
@@ -331,6 +341,7 @@ async function findOne(args) {
|
|
|
331
341
|
limit: 1,
|
|
332
342
|
locale: args.locale,
|
|
333
343
|
pagination: false,
|
|
344
|
+
req: args.req,
|
|
334
345
|
where: args.where
|
|
335
346
|
});
|
|
336
347
|
return docs[0] ?? null;
|
|
@@ -348,7 +359,8 @@ async function findDistinct(args) {
|
|
|
348
359
|
schema: this.documentSchema(),
|
|
349
360
|
sort: addFallbackSort(args.sort, this.payload, args.collection),
|
|
350
361
|
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
351
|
-
}
|
|
362
|
+
},
|
|
363
|
+
headers: getCorrelationHeaders(args.req)
|
|
352
364
|
});
|
|
353
365
|
if (error) {
|
|
354
366
|
throw createDocumentContentAPIError(this, 'findDistinct', error, httpResponse.status, args.collection);
|
|
@@ -381,7 +393,8 @@ async function updateMany(args) {
|
|
|
381
393
|
schema: this.documentSchema(),
|
|
382
394
|
sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),
|
|
383
395
|
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
384
|
-
}
|
|
396
|
+
},
|
|
397
|
+
headers: getCorrelationHeaders(args.req)
|
|
385
398
|
});
|
|
386
399
|
if (error) {
|
|
387
400
|
throw createDocumentContentAPIError(this, 'updateMany', error, httpResponse.status, args.collection);
|
|
@@ -421,7 +434,8 @@ async function updateOne(args) {
|
|
|
421
434
|
locale,
|
|
422
435
|
schema: this.documentSchema(),
|
|
423
436
|
where: convertPayloadWhereToContentAPI(where, this.payload, args.collection, false)
|
|
424
|
-
}
|
|
437
|
+
},
|
|
438
|
+
headers: getCorrelationHeaders(args.req)
|
|
425
439
|
});
|
|
426
440
|
if (error) {
|
|
427
441
|
throw createDocumentContentAPIError(this, 'updateOne', error, httpResponse.status, args.collection);
|
|
@@ -453,7 +467,8 @@ async function deleteMany(args) {
|
|
|
453
467
|
locale,
|
|
454
468
|
schema: this.documentSchema(),
|
|
455
469
|
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
456
|
-
}
|
|
470
|
+
},
|
|
471
|
+
headers: getCorrelationHeaders(args.req)
|
|
457
472
|
});
|
|
458
473
|
if (error) {
|
|
459
474
|
throw createDocumentContentAPIError(this, 'deleteMany', error, httpResponse.status, args.collection);
|
|
@@ -469,7 +484,8 @@ async function deleteOne(args) {
|
|
|
469
484
|
locale,
|
|
470
485
|
schema: this.documentSchema(),
|
|
471
486
|
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
472
|
-
}
|
|
487
|
+
},
|
|
488
|
+
headers: getCorrelationHeaders(args.req)
|
|
473
489
|
});
|
|
474
490
|
if (error) {
|
|
475
491
|
throw createDocumentContentAPIError(this, 'deleteOne', error, httpResponse.status, args.collection);
|
|
@@ -523,7 +539,8 @@ async function create(args) {
|
|
|
523
539
|
environmentName: this.environmentName,
|
|
524
540
|
locale,
|
|
525
541
|
schema: this.documentSchema()
|
|
526
|
-
}
|
|
542
|
+
},
|
|
543
|
+
headers: getCorrelationHeaders(args.req)
|
|
527
544
|
});
|
|
528
545
|
if (error) {
|
|
529
546
|
redirectInitialAutosaveCreate({
|
|
@@ -551,7 +568,8 @@ async function clearDatabase() {
|
|
|
551
568
|
const response = await fetch(getClearDatabaseUrl(this.url, process.env.FIGMA_CONTENT_API_CUTOVER_STATE), {
|
|
552
569
|
headers: {
|
|
553
570
|
'Content-Type': 'application/json',
|
|
554
|
-
...this.clientVersionHeaders
|
|
571
|
+
...this.clientVersionHeaders,
|
|
572
|
+
...getCorrelationHeaders()
|
|
555
573
|
},
|
|
556
574
|
method: 'POST'
|
|
557
575
|
});
|
|
@@ -618,7 +636,8 @@ async function count(args) {
|
|
|
618
636
|
locale,
|
|
619
637
|
schema: this.documentSchema(),
|
|
620
638
|
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
621
|
-
}
|
|
639
|
+
},
|
|
640
|
+
headers: getCorrelationHeaders(args.req)
|
|
622
641
|
});
|
|
623
642
|
if (error) {
|
|
624
643
|
throw createDocumentContentAPIError(this, 'count', error, httpResponse.status, args.collection);
|
|
@@ -639,7 +658,8 @@ async function countVersions(args) {
|
|
|
639
658
|
locale,
|
|
640
659
|
schema: this.documentSchema(),
|
|
641
660
|
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, true)
|
|
642
|
-
}
|
|
661
|
+
},
|
|
662
|
+
headers: getCorrelationHeaders(args.req)
|
|
643
663
|
});
|
|
644
664
|
if (error) {
|
|
645
665
|
throw createDocumentContentAPIError(this, 'countVersions', error, httpResponse.status, args.collection);
|
|
@@ -696,7 +716,8 @@ async function upsert(args) {
|
|
|
696
716
|
locale,
|
|
697
717
|
schema: this.documentSchema(),
|
|
698
718
|
where: convertPayloadWhereToContentAPI(args.where, this.payload, args.collection, false)
|
|
699
|
-
}
|
|
719
|
+
},
|
|
720
|
+
headers: getCorrelationHeaders(args.req)
|
|
700
721
|
});
|
|
701
722
|
if (error) {
|
|
702
723
|
throw createDocumentContentAPIError(this, 'upsert', error, httpResponse.status, args.collection);
|
|
@@ -756,7 +777,8 @@ async function updateJobs(args) {
|
|
|
756
777
|
schema: this.documentSchema(),
|
|
757
778
|
sort: sortClause,
|
|
758
779
|
where: whereQuery
|
|
759
|
-
}
|
|
780
|
+
},
|
|
781
|
+
headers: getCorrelationHeaders(args.req)
|
|
760
782
|
});
|
|
761
783
|
if (error) {
|
|
762
784
|
throw createDocumentContentAPIError(this, 'updateJobs', error, httpResponse.status, collection);
|
|
@@ -788,6 +810,7 @@ async function createGlobal(args) {
|
|
|
788
810
|
...args.data,
|
|
789
811
|
id: args.slug
|
|
790
812
|
},
|
|
813
|
+
req: args.req,
|
|
791
814
|
where: {
|
|
792
815
|
id: {
|
|
793
816
|
equals: args.slug
|
|
@@ -800,6 +823,7 @@ async function findGlobal(args) {
|
|
|
800
823
|
const doc = await this.findOne({
|
|
801
824
|
collection: getGlobalSlug(args.slug),
|
|
802
825
|
locale: args.locale,
|
|
826
|
+
req: args.req,
|
|
803
827
|
where: args.where ?? {}
|
|
804
828
|
});
|
|
805
829
|
return injectGlobalType(doc, args.slug);
|
|
@@ -808,6 +832,7 @@ async function updateGlobal(args) {
|
|
|
808
832
|
const doc = await this.upsert({
|
|
809
833
|
collection: getGlobalSlug(args.slug),
|
|
810
834
|
data: args.data,
|
|
835
|
+
req: args.req,
|
|
811
836
|
where: {
|
|
812
837
|
id: {
|
|
813
838
|
equals: args.slug
|
|
@@ -824,6 +849,7 @@ function findGlobalVersions(args) {
|
|
|
824
849
|
locale: args.locale,
|
|
825
850
|
page: args.page,
|
|
826
851
|
pagination: args.pagination,
|
|
852
|
+
req: args.req,
|
|
827
853
|
sort: args.sort,
|
|
828
854
|
where: args.where
|
|
829
855
|
});
|
|
@@ -837,6 +863,7 @@ function createGlobalVersion(args) {
|
|
|
837
863
|
createdAt: args.createdAt,
|
|
838
864
|
parent: args.globalSlug,
|
|
839
865
|
publishedLocale: args.publishedLocale,
|
|
866
|
+
req: args.req,
|
|
840
867
|
updatedAt: args.updatedAt,
|
|
841
868
|
versionData: args.versionData
|
|
842
869
|
});
|
|
@@ -848,6 +875,7 @@ function updateGlobalVersion(args) {
|
|
|
848
875
|
id: args.id,
|
|
849
876
|
collection: getGlobalSlug(args.global),
|
|
850
877
|
locale: args.locale,
|
|
878
|
+
req: args.req,
|
|
851
879
|
versionData: args.versionData
|
|
852
880
|
});
|
|
853
881
|
}
|
|
@@ -855,6 +883,7 @@ function updateGlobalVersion(args) {
|
|
|
855
883
|
return this.updateVersion({
|
|
856
884
|
collection: getGlobalSlug(args.global),
|
|
857
885
|
locale: args.locale,
|
|
886
|
+
req: args.req,
|
|
858
887
|
versionData: args.versionData,
|
|
859
888
|
where: args.where
|
|
860
889
|
});
|
|
@@ -863,6 +892,7 @@ function countGlobalVersions(args) {
|
|
|
863
892
|
return this.countVersions({
|
|
864
893
|
collection: getGlobalSlug(args.global),
|
|
865
894
|
locale: args.locale,
|
|
895
|
+
req: args.req,
|
|
866
896
|
where: args.where
|
|
867
897
|
});
|
|
868
898
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
export declare const FIGMA_ROOT_REQ_ID_HEADER = "Figma-Root-Req-ID";
|
|
3
|
+
export declare const FIGMA_PARENT_REQ_ID_HEADER = "Figma-Parent-Req-ID";
|
|
4
|
+
export type CorrelationIds = {
|
|
5
|
+
/** The current operation (this Payload app). */
|
|
6
|
+
leafId: string;
|
|
7
|
+
/** The operation that called this Payload app, or null when there is none. */
|
|
8
|
+
parentId: null | string;
|
|
9
|
+
/** The operation that started the call tree. */
|
|
10
|
+
rootId: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Correlation IDs for a Payload request, stable for the lifetime of that request object.
|
|
14
|
+
* Calls without a request (e.g. collection sync on connect) each start their own call tree.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getCorrelationIds(req?: Partial<PayloadRequest>): CorrelationIds;
|
|
17
|
+
/** Headers that identify this Payload app as the parent of an outgoing Content API request. */
|
|
18
|
+
export declare function getCorrelationHeaders(req?: Partial<PayloadRequest>): Record<string, string>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
export const FIGMA_ROOT_REQ_ID_HEADER = 'Figma-Root-Req-ID';
|
|
3
|
+
export const FIGMA_PARENT_REQ_ID_HEADER = 'Figma-Parent-Req-ID';
|
|
4
|
+
const correlationIdsByRequest = new WeakMap();
|
|
5
|
+
function buildCorrelationIds(headers) {
|
|
6
|
+
const leafId = randomUUID();
|
|
7
|
+
const rootId = headers?.get(FIGMA_ROOT_REQ_ID_HEADER);
|
|
8
|
+
if (!rootId) {
|
|
9
|
+
// Without a root, a parent cannot be placed in a call tree, so this request starts a new one.
|
|
10
|
+
return {
|
|
11
|
+
leafId,
|
|
12
|
+
parentId: null,
|
|
13
|
+
rootId: leafId
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
leafId,
|
|
18
|
+
parentId: headers?.get(FIGMA_PARENT_REQ_ID_HEADER) || null,
|
|
19
|
+
rootId
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Correlation IDs for a Payload request, stable for the lifetime of that request object.
|
|
24
|
+
* Calls without a request (e.g. collection sync on connect) each start their own call tree.
|
|
25
|
+
*/ export function getCorrelationIds(req) {
|
|
26
|
+
if (!req) {
|
|
27
|
+
return buildCorrelationIds(undefined);
|
|
28
|
+
}
|
|
29
|
+
let ids = correlationIdsByRequest.get(req);
|
|
30
|
+
if (!ids) {
|
|
31
|
+
ids = buildCorrelationIds(req.headers);
|
|
32
|
+
correlationIdsByRequest.set(req, ids);
|
|
33
|
+
}
|
|
34
|
+
return ids;
|
|
35
|
+
}
|
|
36
|
+
/** Headers that identify this Payload app as the parent of an outgoing Content API request. */ export function getCorrelationHeaders(req) {
|
|
37
|
+
const { leafId, rootId } = getCorrelationIds(req);
|
|
38
|
+
return {
|
|
39
|
+
[FIGMA_PARENT_REQ_ID_HEADER]: leafId,
|
|
40
|
+
[FIGMA_ROOT_REQ_ID_HEADER]: rootId
|
|
41
|
+
};
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/figma",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@clack/prompts": "^0.11.0",
|
|
41
|
-
"@cloudflare/workers-types": "5.
|
|
41
|
+
"@cloudflare/workers-types": "^5.20261108.1",
|
|
42
42
|
"@figma/rest-api-spec": "^0.34.0",
|
|
43
43
|
"@sindresorhus/slugify": "^3.0.0",
|
|
44
44
|
"archiver": "7.0.1",
|
|
@@ -63,11 +63,11 @@
|
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@payloadcms/eslint-config": "3.28.0",
|
|
65
65
|
"@payloadcms/eslint-plugin": "3.28.0",
|
|
66
|
-
"@payloadcms/next": "4.0.0-beta.
|
|
67
|
-
"@payloadcms/plugin-cloud-storage": "4.0.0-beta.
|
|
68
|
-
"@payloadcms/richtext-lexical": "4.0.0-beta.
|
|
69
|
-
"@payloadcms/translations": "4.0.0-beta.
|
|
70
|
-
"@payloadcms/ui": "4.0.0-beta.
|
|
66
|
+
"@payloadcms/next": "4.0.0-beta.9",
|
|
67
|
+
"@payloadcms/plugin-cloud-storage": "4.0.0-beta.9",
|
|
68
|
+
"@payloadcms/richtext-lexical": "4.0.0-beta.9",
|
|
69
|
+
"@payloadcms/translations": "4.0.0-beta.9",
|
|
70
|
+
"@payloadcms/ui": "4.0.0-beta.9",
|
|
71
71
|
"@swc/cli": "0.7.7",
|
|
72
72
|
"@types/archiver": "7.0.0",
|
|
73
73
|
"@types/cross-spawn": "6.0.6",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"eslint": "9.22.0",
|
|
78
78
|
"next": "^16.4.2",
|
|
79
79
|
"openapi-typescript": "^7.13.0",
|
|
80
|
-
"payload": "4.0.0-beta.
|
|
80
|
+
"payload": "4.0.0-beta.9",
|
|
81
81
|
"react": "^19.3.1",
|
|
82
82
|
"react-dom": "^19.3.1",
|
|
83
83
|
"tsx": "4.20.6",
|
|
@@ -85,11 +85,11 @@
|
|
|
85
85
|
"vitest": "4.0.15"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
|
-
"@payloadcms/plugin-cloud-storage": ">=4.0.0-beta.
|
|
89
|
-
"@payloadcms/richtext-lexical": ">=4.0.0-beta.
|
|
90
|
-
"@payloadcms/translations": ">=4.0.0-beta.
|
|
91
|
-
"@payloadcms/ui": ">=4.0.0-beta.
|
|
92
|
-
"payload": ">=4.0.0-beta.
|
|
88
|
+
"@payloadcms/plugin-cloud-storage": ">=4.0.0-beta.9 <4.0.0-internal",
|
|
89
|
+
"@payloadcms/richtext-lexical": ">=4.0.0-beta.9 <4.0.0-internal",
|
|
90
|
+
"@payloadcms/translations": ">=4.0.0-beta.9 <4.0.0-internal",
|
|
91
|
+
"@payloadcms/ui": ">=4.0.0-beta.9 <4.0.0-internal",
|
|
92
|
+
"payload": ">=4.0.0-beta.9 <4.0.0-internal",
|
|
93
93
|
"react": "^19.3.1"
|
|
94
94
|
},
|
|
95
95
|
"peerDependenciesMeta": {
|