@payloadcms/figma 0.0.1-alpha.2 → 0.0.1-alpha.20

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.
Files changed (72) hide show
  1. package/dist/api/control-plane.d.ts +1 -1
  2. package/dist/api/control-plane.d.ts.map +1 -1
  3. package/dist/api/control-plane.js +12 -7
  4. package/dist/api/control-plane.js.map +1 -1
  5. package/dist/api/figma-api.d.ts.map +1 -1
  6. package/dist/api/figma-api.js +33 -10
  7. package/dist/api/figma-api.js.map +1 -1
  8. package/dist/auth/crypto-utils.d.ts.map +1 -1
  9. package/dist/auth/crypto-utils.js +5 -5
  10. package/dist/auth/crypto-utils.js.map +1 -1
  11. package/dist/auth/oauth-flow.js +3 -3
  12. package/dist/auth/oauth-flow.js.map +1 -1
  13. package/dist/auth/project-token.d.ts.map +1 -1
  14. package/dist/auth/project-token.js +7 -3
  15. package/dist/auth/project-token.js.map +1 -1
  16. package/dist/auth/token-store.d.ts.map +1 -1
  17. package/dist/auth/token-store.js +3 -0
  18. package/dist/auth/token-store.js.map +1 -1
  19. package/dist/cli.js +1 -0
  20. package/dist/cli.js.map +1 -1
  21. package/dist/commands/deploy.d.ts +2 -0
  22. package/dist/commands/deploy.d.ts.map +1 -1
  23. package/dist/commands/deploy.js +11 -6
  24. package/dist/commands/deploy.js.map +1 -1
  25. package/dist/commands/init.d.ts.map +1 -1
  26. package/dist/commands/init.js +14 -76
  27. package/dist/commands/init.js.map +1 -1
  28. package/dist/commands/login.d.ts +8 -1
  29. package/dist/commands/login.d.ts.map +1 -1
  30. package/dist/commands/login.js +10 -4
  31. package/dist/commands/login.js.map +1 -1
  32. package/dist/config/oauth.d.ts.map +1 -1
  33. package/dist/config/oauth.js +3 -3
  34. package/dist/config/oauth.js.map +1 -1
  35. package/dist/db-adapter.d.ts +17 -0
  36. package/dist/db-adapter.d.ts.map +1 -0
  37. package/dist/db-adapter.js +760 -0
  38. package/dist/db-adapter.js.map +1 -0
  39. package/dist/endpoints/health.d.ts +3 -0
  40. package/dist/endpoints/health.d.ts.map +1 -0
  41. package/dist/endpoints/health.js +11 -0
  42. package/dist/endpoints/health.js.map +1 -0
  43. package/dist/exports/client.d.ts +3 -0
  44. package/dist/exports/client.d.ts.map +1 -0
  45. package/dist/exports/client.js +4 -0
  46. package/dist/exports/client.js.map +1 -0
  47. package/dist/oauth/components/LoginButton/index.d.ts.map +1 -1
  48. package/dist/oauth/components/LoginButton/index.js +50 -6
  49. package/dist/oauth/components/LoginButton/index.js.map +1 -1
  50. package/dist/oauth/components/LoginButton/index.scss +50 -3
  51. package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -1
  52. package/dist/oauth/endpoints/getLoginEndpoint.js +1 -1
  53. package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -1
  54. package/dist/oauth/index.d.ts.map +1 -1
  55. package/dist/oauth/index.js +30 -6
  56. package/dist/oauth/index.js.map +1 -1
  57. package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -1
  58. package/dist/oauth/utilities/refreshTokens.js +1 -1
  59. package/dist/oauth/utilities/refreshTokens.js.map +1 -1
  60. package/dist/plugin/build-config.d.ts +3 -5
  61. package/dist/plugin/build-config.d.ts.map +1 -1
  62. package/dist/plugin/build-config.js +28 -14
  63. package/dist/plugin/build-config.js.map +1 -1
  64. package/dist/utils/payload-config-ast.d.ts +1 -1
  65. package/dist/utils/payload-config-ast.d.ts.map +1 -1
  66. package/dist/utils/payload-config-ast.js +7 -7
  67. package/dist/utils/payload-config-ast.js.map +1 -1
  68. package/dist/utils/s3-upload.d.ts +0 -1
  69. package/dist/utils/s3-upload.d.ts.map +1 -1
  70. package/dist/utils/s3-upload.js +10 -3
  71. package/dist/utils/s3-upload.js.map +1 -1
  72. package/package.json +10 -5
@@ -0,0 +1,760 @@
1
+ import { randomUUID } from 'crypto';
2
+ import { createDatabaseAdapter } from 'payload';
3
+ const slugIsGlobal = (slug)=>slug.startsWith('_global-');
4
+ const getGlobalSlug = (slug)=>`_global-${slug}`;
5
+ // Transform Payload Where format to Content API WhereClause format
6
+ function transformWhereClause(where) {
7
+ if (!where) {
8
+ return undefined;
9
+ }
10
+ // Handle and/or logical operators
11
+ if (where.and) {
12
+ return {
13
+ and: where.and.map(transformWhereClause).filter(Boolean)
14
+ };
15
+ }
16
+ if (where.or) {
17
+ return {
18
+ or: where.or.map(transformWhereClause).filter(Boolean)
19
+ };
20
+ }
21
+ // Transform field conditions
22
+ const transformedClauses = [];
23
+ for (const [field, condition] of Object.entries(where)){
24
+ if (field === 'and' || field === 'or') {
25
+ continue;
26
+ }
27
+ if (Array.isArray(condition)) {
28
+ // Handle nested and/or arrays
29
+ transformedClauses.push({
30
+ [field]: condition.map(transformWhereClause).filter(Boolean)
31
+ });
32
+ } else if (typeof condition === 'object' && condition !== null) {
33
+ // Handle field operators like { equals: 'value' }, { greater_than: 10 }
34
+ for (const [operator, value] of Object.entries(condition)){
35
+ transformedClauses.push({
36
+ operator: operator,
37
+ path: field,
38
+ value
39
+ });
40
+ }
41
+ } else {
42
+ // Handle direct field values like { status: 'published' }
43
+ transformedClauses.push({
44
+ operator: 'equals',
45
+ path: field,
46
+ value: condition
47
+ });
48
+ }
49
+ }
50
+ if (transformedClauses.length === 1) {
51
+ return transformedClauses[0];
52
+ } else if (transformedClauses.length > 1) {
53
+ return {
54
+ and: transformedClauses
55
+ };
56
+ }
57
+ return undefined;
58
+ }
59
+ const formatDocument = (doc)=>{
60
+ if (!doc) {
61
+ return null;
62
+ }
63
+ const { id, data, ...meta } = doc;
64
+ return {
65
+ id,
66
+ _meta: meta,
67
+ ...data
68
+ };
69
+ };
70
+ async function init() {
71
+ console.log('🔍 [DB_CONTENT_API] init() called');
72
+ console.log('🔍 [DB_CONTENT_API] this:', this);
73
+ console.log('🔍 [DB_CONTENT_API] payload collections:', this.payload.config.collections.map((c)=>c.slug));
74
+ // Create collections in content API
75
+ for (const collection of this.payload.config.collections){
76
+ try {
77
+ console.log(`🔧 [DB_CONTENT_API] Creating collection: ${collection.slug}`);
78
+ const response = await this.request('/api/v0/collections', {
79
+ contentSystemId: this.contentSystemId,
80
+ key: collection.slug
81
+ });
82
+ if (response.error) {
83
+ console.error(`[DB_CONTENT_API] create collection ${collection.slug} failure`, response.error);
84
+ } else {
85
+ console.log(`✅ [DB_CONTENT_API] Created collection: ${collection.slug}`);
86
+ }
87
+ } catch (error) {
88
+ console.warn(`⚠️ [DB_CONTENT_API] Failed to create collection ${collection.slug}:`, error);
89
+ }
90
+ }
91
+ // Create globals as collections (with _global- prefix)
92
+ for (const global of this.payload.config.globals){
93
+ try {
94
+ const globalKey = getGlobalSlug(global.slug);
95
+ console.log(`🔧 [DB_CONTENT_API] Creating global collection: ${globalKey}`);
96
+ const response = await this.request('/api/v0/collections', {
97
+ contentSystemId: this.contentSystemId,
98
+ key: globalKey
99
+ });
100
+ if (response.error) {
101
+ console.error(`[DB_CONTENT_API] create global collection ${globalKey} failure`, response.error);
102
+ } else {
103
+ console.log(`✅ [DB_CONTENT_API] Created global collection: ${globalKey}`);
104
+ }
105
+ } catch (error) {
106
+ console.warn(`⚠️ [DB_CONTENT_API] Failed to create global collection ${global.slug}:`, error);
107
+ }
108
+ }
109
+ console.log('🔍 [DB_CONTENT_API] payload globals:', this.payload.config.globals.map((g)=>g.slug));
110
+ }
111
+ const find = async function find({ collection, limit, page = 1, req, sort, where, ...args }) {
112
+ console.log('🔍 [DB_CONTENT_API] find() called with:', collection, JSON.stringify(transformWhereClause(where), null, 2), {
113
+ limit,
114
+ page,
115
+ sort,
116
+ ...args
117
+ });
118
+ try {
119
+ const response = await this.request('/api/v0/documents:find', {
120
+ collectionKey: collection,
121
+ contentSystemId: this.contentSystemId,
122
+ limit,
123
+ offset: (page - 1) * (limit || 10),
124
+ sort: sort ? [
125
+ sort
126
+ ].flat().map((s)=>({
127
+ direction: Object.values(s)[0] === -1 ? 'dsc' : 'asc',
128
+ path: Object.keys(s)[0]
129
+ })) : undefined,
130
+ where: transformWhereClause(where)
131
+ });
132
+ if (response.error) {
133
+ console.error('[DB_CONTENT_API] find() failure', response.error?.message || response.error);
134
+ }
135
+ const docs = response.result?.data || [];
136
+ const pagination = response.result?.pagination;
137
+ const totalDocs = pagination?.total || docs.length;
138
+ const actualLimit = limit || 10;
139
+ const totalPages = Math.ceil(totalDocs / actualLimit);
140
+ const hasNextPage = page < totalPages;
141
+ const result = {
142
+ docs: docs.map(formatDocument),
143
+ hasNextPage,
144
+ hasPrevPage: page > 1,
145
+ limit: actualLimit,
146
+ nextPage: hasNextPage ? page + 1 : null,
147
+ page,
148
+ pagingCounter: 1,
149
+ prevPage: page > 1 ? page - 1 : null,
150
+ totalDocs,
151
+ totalPages
152
+ };
153
+ console.log('[DB_CONTENT_API] find() result:', result);
154
+ return result;
155
+ } catch (error) {
156
+ console.error(`❌ [DB_CONTENT_API] Error in find():`, error);
157
+ const docs = [];
158
+ const hasNextPage = false;
159
+ const totalPages = 1;
160
+ return {
161
+ docs,
162
+ hasNextPage,
163
+ hasPrevPage: page > 1,
164
+ limit: limit || docs.length,
165
+ nextPage: hasNextPage ? page + 1 : null,
166
+ page,
167
+ pagingCounter: 1,
168
+ prevPage: page > 1 ? page - 1 : null,
169
+ totalDocs: docs.length,
170
+ totalPages
171
+ };
172
+ }
173
+ };
174
+ const findVersions = async function findVersions({ collection, limit, page = 1, req, where, ...args }) {
175
+ console.log('🔍 [DB_CONTENT_API] findVersions() called with:', {
176
+ collection,
177
+ limit,
178
+ page,
179
+ where,
180
+ ...args
181
+ });
182
+ const docs = [];
183
+ const hasNextPage = false;
184
+ const result = {
185
+ docs,
186
+ hasNextPage,
187
+ hasPrevPage: page > 1,
188
+ limit: limit || docs.length,
189
+ nextPage: hasNextPage ? page + 1 : null,
190
+ page,
191
+ pagingCounter: 1,
192
+ prevPage: page > 1 ? page - 1 : null,
193
+ totalDocs: docs.length,
194
+ totalPages: limit && docs.length ? Math.ceil(docs.length / limit) : 1
195
+ };
196
+ console.log('[DB_CONTENT_API] findVersions() result:', result);
197
+ return result;
198
+ };
199
+ const queryDrafts = async function queryDrafts({ collection, limit, page = 1, req, where, ...args }) {
200
+ console.log('🔍 [DB_CONTENT_API] queryDrafts() called with:', {
201
+ collection,
202
+ limit,
203
+ page,
204
+ where,
205
+ ...args
206
+ });
207
+ const docs = [];
208
+ const hasNextPage = false;
209
+ const result = {
210
+ docs,
211
+ hasNextPage,
212
+ hasPrevPage: page > 1,
213
+ limit: limit || docs.length,
214
+ nextPage: hasNextPage ? page + 1 : null,
215
+ page,
216
+ pagingCounter: 1,
217
+ prevPage: page > 1 ? page - 1 : null,
218
+ totalDocs: docs.length,
219
+ totalPages: limit && docs.length ? Math.ceil(docs.length / limit) : 1
220
+ };
221
+ console.log('[DB_CONTENT_API] queryDrafts() result:', result);
222
+ return result;
223
+ };
224
+ const createVersion = async function createVersion({ collectionSlug, req, versionData, ...args }) {
225
+ console.log('🔍 [DB_CONTENT_API] createVersion() called with:', {
226
+ collectionSlug,
227
+ versionData,
228
+ ...args
229
+ });
230
+ const result = {};
231
+ console.log('[DB_CONTENT_API] createVersion() result:', result);
232
+ return result;
233
+ };
234
+ const updateVersion = async function updateVersion({ id, collection, req, versionData, where, ...args }) {
235
+ console.log('🔍 [DB_CONTENT_API] updateVersion() called with:', {
236
+ id,
237
+ collection,
238
+ versionData,
239
+ ...args
240
+ });
241
+ const result = {};
242
+ console.log('[DB_CONTENT_API] updateVersion() result:', result);
243
+ return result;
244
+ };
245
+ const deleteVersions = async function deleteVersions({ collection, req, where, ...args }) {
246
+ console.log('🔍 [DB_CONTENT_API] deleteVersions() called with:', {
247
+ collection,
248
+ where,
249
+ ...args
250
+ });
251
+ const versionsToDelete = [];
252
+ const versionCollection = 'versions';
253
+ console.log(`🗑️ [DB_CONTENT_API] Deleted ${versionsToDelete.length} versions from ${versionCollection}`);
254
+ // return versionsToDelete.length
255
+ };
256
+ const findOne = async function findOne({ collection, req, where, ...args }) {
257
+ console.log('🔍 [DB_CONTENT_API] findOne() called with:', collection, JSON.stringify(transformWhereClause(where), null, 2), args, req?.body);
258
+ try {
259
+ const response = await this.request('/api/v0/documents:find', {
260
+ collectionKey: collection,
261
+ contentSystemId: this.contentSystemId,
262
+ limit: 1,
263
+ offset: 0,
264
+ where: transformWhereClause(where)
265
+ });
266
+ if (response.error) {
267
+ console.error('[DB_CONTENT_API] findOne() failure', response.error?.message || response.error);
268
+ }
269
+ const docs = response.result?.data || [];
270
+ const result = docs.length > 0 ? docs[0] : null;
271
+ console.log('[DB_CONTENT_API] findOne() result:', result);
272
+ return formatDocument(result);
273
+ } catch (error) {
274
+ console.error(`❌ [DB_CONTENT_API] Error in findOne():`, error);
275
+ return null;
276
+ }
277
+ };
278
+ const updateMany = async function updateMany({ collection, data, req, where, ...args }) {
279
+ console.log('🔍 [DB_CONTENT_API] updateMany() called with:', {
280
+ collection,
281
+ data,
282
+ where,
283
+ ...args
284
+ });
285
+ try {
286
+ const response = await this.request('/api/v0/documents:update', {
287
+ collectionKey: collection,
288
+ contentSystemId: this.contentSystemId,
289
+ createOnMissing: false,
290
+ data,
291
+ where: transformWhereClause(where)
292
+ });
293
+ if (response.error) {
294
+ console.error('[DB_CONTENT_API] updateMany() failure', response.error?.message || response.error);
295
+ }
296
+ // Return array of updated documents if available, otherwise return placeholder
297
+ const result = response.result?.data || [];
298
+ console.log('[DB_CONTENT_API] updateMany() result:', result);
299
+ return result;
300
+ } catch (error) {
301
+ console.error(`❌ [DB_CONTENT_API] Error in updateMany():`, error);
302
+ return [];
303
+ }
304
+ };
305
+ const updateOne = async function updateOne({ id, collection, data, req, where = {}, ...args }) {
306
+ console.log('🔍 [DB_CONTENT_API] updateOne() called with:', {
307
+ id,
308
+ collection,
309
+ data,
310
+ where,
311
+ ...args
312
+ });
313
+ try {
314
+ const whereClause = id ? {
315
+ operator: 'equals',
316
+ path: 'id',
317
+ value: id
318
+ } : transformWhereClause(where);
319
+ const response = await this.request('/api/v0/documents:update', {
320
+ collectionKey: collection,
321
+ contentSystemId: this.contentSystemId,
322
+ createOnMissing: false,
323
+ data,
324
+ returning: {
325
+ exclude: []
326
+ },
327
+ where: whereClause
328
+ });
329
+ if (response.error) {
330
+ console.error('[DB_CONTENT_API] updateOne() failure', response.error?.message || response.error);
331
+ }
332
+ const result = response.result?.data || {
333
+ id,
334
+ ...data
335
+ };
336
+ console.log('[DB_CONTENT_API] updateOne() result:', result);
337
+ return result;
338
+ } catch (error) {
339
+ console.error(`❌ [DB_CONTENT_API] Error in updateOne():`, error);
340
+ return {
341
+ id,
342
+ ...data
343
+ };
344
+ }
345
+ };
346
+ const deleteMany = async function deleteMany({ collection, req, where, ...args }) {
347
+ console.log('🔍 [DB_CONTENT_API] deleteMany() called with:', {
348
+ collection,
349
+ where,
350
+ ...args
351
+ });
352
+ try {
353
+ const response = await this.request('/api/v0/documents:delete', {
354
+ collectionKey: collection,
355
+ contentSystemId: this.contentSystemId,
356
+ returning: false,
357
+ where: transformWhereClause(where)
358
+ });
359
+ if (response.error) {
360
+ console.error('[DB_CONTENT_API] deleteMany() failure', response.error?.message || response.error);
361
+ }
362
+ const deletedCount = response.result?.count || 0;
363
+ console.log(`🗑️ [DB_CONTENT_API] Deleted ${deletedCount} documents from ${collection}`);
364
+ } catch (error) {
365
+ console.error(`❌ [DB_CONTENT_API] Error in deleteMany():`, error);
366
+ }
367
+ };
368
+ const deleteOne = async function deleteOne({ collection, req, where, ...args }) {
369
+ console.log('🔍 [DB_CONTENT_API] deleteOne() called with:', {
370
+ collection,
371
+ where,
372
+ ...args
373
+ });
374
+ try {
375
+ const response = await this.request('/api/v0/documents:delete', {
376
+ collectionKey: collection,
377
+ contentSystemId: this.contentSystemId,
378
+ returning: {
379
+ exclude: []
380
+ },
381
+ where: transformWhereClause(where)
382
+ });
383
+ if (response.error) {
384
+ console.error('[DB_CONTENT_API] deleteOne() failure', response.error?.message || response.error);
385
+ }
386
+ const deletedDocs = response.result?.data || [];
387
+ const docId = deletedDocs.length > 0 ? deletedDocs[0].id : 'unknown';
388
+ const result = deletedDocs.length > 0 ? deletedDocs[0] : {};
389
+ console.log(`🗑️ [DB_CONTENT_API] Deleted document ${docId} from ${collection}`);
390
+ console.log('[DB_CONTENT_API] deleteOne() result:', result);
391
+ return result;
392
+ } catch (error) {
393
+ console.error(`❌ [DB_CONTENT_API] Error in deleteOne():`, error);
394
+ return {};
395
+ }
396
+ };
397
+ const create = async function create({ collection, data, req, ...args }) {
398
+ console.log('🔍 [DB_CONTENT_API] create() called with:', {
399
+ collection,
400
+ data,
401
+ ...args
402
+ });
403
+ try {
404
+ const randomKey = randomUUID();
405
+ const response = await this.request('/api/v0/documents:create', {
406
+ collectionKey: collection,
407
+ contentSystemId: this.contentSystemId,
408
+ data,
409
+ key: data.key || data.id || `doc-${randomKey}`
410
+ });
411
+ if (response.error) {
412
+ console.error('[DB_CONTENT_API] create() failure', response.error?.message || response.error);
413
+ }
414
+ const result = response.result?.data || response.result || {
415
+ id: `doc-${randomKey}`,
416
+ ...data
417
+ };
418
+ console.log('[DB_CONTENT_API] create() result:', result);
419
+ return result;
420
+ } catch (error) {
421
+ console.error(`❌ [DB_CONTENT_API] Error in create():`, error);
422
+ return {
423
+ id: `doc-${randomUUID()}`,
424
+ ...data
425
+ };
426
+ }
427
+ };
428
+ const count = async function count({ collection, req, where = {}, ...args }) {
429
+ console.log('🔍 [DB_CONTENT_API] count() called with:', {
430
+ collection,
431
+ where,
432
+ ...args
433
+ });
434
+ try {
435
+ const response = await this.request('/api/v0/documents:count', {
436
+ collectionKey: collection,
437
+ contentSystemId: this.contentSystemId,
438
+ where: transformWhereClause(where)
439
+ });
440
+ if (response.error) {
441
+ console.error('[DB_CONTENT_API] count() failure', response.error?.message || response.error);
442
+ }
443
+ const result = {
444
+ totalDocs: response.result?.count || 0
445
+ };
446
+ console.log('[DB_CONTENT_API] count() result:', result);
447
+ return result;
448
+ } catch (error) {
449
+ console.error(`❌ [DB_CONTENT_API] Error in count():`, error);
450
+ return {
451
+ totalDocs: 0
452
+ };
453
+ }
454
+ };
455
+ const countVersions = async function countVersions({ collection, req, where, ...args }) {
456
+ console.log('🔍 [DB_CONTENT_API] countVersions() called with:', {
457
+ collection,
458
+ where,
459
+ ...args
460
+ });
461
+ const result = {
462
+ totalDocs: 0
463
+ };
464
+ console.log('[DB_CONTENT_API] countVersions() result:', result);
465
+ return result;
466
+ };
467
+ const upsert = async function upsert({ collection, data, req, where, ...args }) {
468
+ console.log('🔍 [DB_CONTENT_API] upsert() called with:', {
469
+ collection,
470
+ data,
471
+ where,
472
+ ...args
473
+ });
474
+ try {
475
+ // Try to update first
476
+ const updateResponse = await this.request('/api/v0/documents:update', {
477
+ collectionKey: collection,
478
+ contentSystemId: this.contentSystemId,
479
+ createOnMissing: {
480
+ documentKey: `upsert-${Date.now()}`
481
+ },
482
+ data,
483
+ returning: {
484
+ exclude: []
485
+ },
486
+ where: transformWhereClause(where)
487
+ });
488
+ if (!updateResponse.success) {
489
+ console.log('[DB_CONTENT_API] upsert() failure', updateResponse.error);
490
+ }
491
+ const result = updateResponse.result?.data || {
492
+ ...data
493
+ };
494
+ console.log('[DB_CONTENT_API] upsert() result:', result);
495
+ return result;
496
+ } catch (error) {
497
+ console.error(`❌ [DB_CONTENT_API] Error in upsert():`, error);
498
+ return {
499
+ ...data
500
+ };
501
+ }
502
+ };
503
+ const createGlobal = async function createGlobal({ slug, data, req, ...args }) {
504
+ console.log('🔍 [DB_CONTENT_API] createGlobal() called with:', {
505
+ slug,
506
+ data,
507
+ ...args
508
+ });
509
+ try {
510
+ const globalKey = getGlobalSlug(slug);
511
+ const response = await this.request('/api/v0/documents:create', {
512
+ collectionKey: globalKey,
513
+ contentSystemId: this.contentSystemId,
514
+ data,
515
+ key: `global-${slug}`
516
+ });
517
+ if (response.error) {
518
+ console.error('[DB_CONTENT_API] createGlobal() failure', response.error?.message || response.error);
519
+ }
520
+ const result = response.result?.data || response.result || {
521
+ id: `global-${slug}`,
522
+ ...data
523
+ };
524
+ console.log('[DB_CONTENT_API] createGlobal() result:', result);
525
+ return result;
526
+ } catch (error) {
527
+ console.error(`❌ [DB_CONTENT_API] Error in createGlobal():`, error);
528
+ return {
529
+ id: `global-${slug}`,
530
+ ...data
531
+ };
532
+ }
533
+ };
534
+ const findGlobal = async function findGlobal({ slug, req, ...args }) {
535
+ console.log('🔍 [DB_CONTENT_API] findGlobal() called with:', {
536
+ slug,
537
+ ...args
538
+ });
539
+ try {
540
+ const globalKey = getGlobalSlug(slug);
541
+ const response = await this.request('/api/v0/documents:find', {
542
+ collectionKey: globalKey,
543
+ contentSystemId: this.contentSystemId,
544
+ limit: 1,
545
+ offset: 0
546
+ });
547
+ if (response.error) {
548
+ console.error('[DB_CONTENT_API] findGlobal() failure', response.error?.message || response.error);
549
+ }
550
+ const docs = response.result?.data || [];
551
+ const result = docs.length > 0 ? docs[0] : null;
552
+ console.log('[DB_CONTENT_API] findGlobal() result:', result);
553
+ return formatDocument(result);
554
+ } catch (error) {
555
+ console.error(`❌ [DB_CONTENT_API] Error in findGlobal():`, error);
556
+ return null;
557
+ }
558
+ };
559
+ const findDistinct = async function findDistinct({ collection, field, limit, page = 1, req, where, ...args }) {
560
+ console.log('🔍 [DB_CONTENT_API] findDistinct() called with:', {
561
+ collection,
562
+ field,
563
+ limit,
564
+ page,
565
+ where,
566
+ ...args
567
+ });
568
+ const distinctValues = [];
569
+ const paginatedValues = [];
570
+ const endIndex = 0;
571
+ const totalDocs = 0;
572
+ console.log(`📊 [DB_CONTENT_API] findDistinct result: ${distinctValues.length} distinct values for ${field}`);
573
+ return {
574
+ hasNextPage: limit ? endIndex < totalDocs : false,
575
+ hasPrevPage: page > 1,
576
+ limit: limit || totalDocs,
577
+ nextPage: limit && endIndex < totalDocs ? page + 1 : null,
578
+ page,
579
+ pagingCounter: 1,
580
+ prevPage: page > 1 ? page - 1 : null,
581
+ totalDocs,
582
+ totalPages: limit ? Math.ceil(totalDocs / limit) : 1,
583
+ values: paginatedValues
584
+ };
585
+ };
586
+ const updateGlobal = async function updateGlobal({ slug, data, req, ...args }) {
587
+ console.log('🔍 [DB_CONTENT_API] updateGlobal() called with:', {
588
+ slug,
589
+ data,
590
+ ...args
591
+ });
592
+ try {
593
+ const globalKey = getGlobalSlug(slug);
594
+ const response = await this.request('/api/v0/documents:update', {
595
+ collectionKey: globalKey,
596
+ contentSystemId: this.contentSystemId,
597
+ createOnMissing: {
598
+ documentKey: `global-${slug}`
599
+ },
600
+ data,
601
+ returning: {
602
+ exclude: []
603
+ },
604
+ where: {
605
+ operator: 'equals',
606
+ path: 'key',
607
+ value: `global-${slug}`
608
+ }
609
+ });
610
+ if (response.error) {
611
+ console.error('[DB_CONTENT_API] updateGlobal() failure', response.error?.message || response.error);
612
+ }
613
+ const result = response.result?.data || {
614
+ id: `global-${slug}`,
615
+ ...data
616
+ };
617
+ console.log('[DB_CONTENT_API] updateGlobal() result:', result);
618
+ return result;
619
+ } catch (error) {
620
+ console.error(`❌ [DB_CONTENT_API] Error in updateGlobal():`, error);
621
+ return {
622
+ id: `global-${slug}`,
623
+ ...data
624
+ };
625
+ }
626
+ };
627
+ const findGlobalVersions = async function findGlobalVersions({ limit, page = 1, req, where, ...args }) {
628
+ console.log('🔍 [DB_CONTENT_API] findGlobalVersions() called with:', {
629
+ limit,
630
+ page,
631
+ where,
632
+ ...args
633
+ });
634
+ const docs = [];
635
+ const hasNextPage = false;
636
+ const result = {
637
+ docs,
638
+ hasNextPage,
639
+ hasPrevPage: page > 1,
640
+ limit: limit || docs.length,
641
+ nextPage: hasNextPage ? page + 1 : null,
642
+ page,
643
+ pagingCounter: 1,
644
+ prevPage: page > 1 ? page - 1 : null,
645
+ totalDocs: docs.length,
646
+ totalPages: limit && docs.length ? Math.ceil(docs.length / limit) : 1
647
+ };
648
+ console.log('[DB_CONTENT_API] findGlobalVersions() result:', result);
649
+ return result;
650
+ };
651
+ const createGlobalVersion = async function createGlobalVersion({ req, versionData, ...args }) {
652
+ console.log('🔍 [DB_CONTENT_API] createGlobalVersion() called with:', {
653
+ versionData,
654
+ ...args
655
+ });
656
+ const result = {};
657
+ console.log('[DB_CONTENT_API] createGlobalVersion() result:', result);
658
+ return result;
659
+ };
660
+ const updateGlobalVersion = async function updateGlobalVersion({ id, req, versionData, ...args }) {
661
+ console.log('🔍 [DB_CONTENT_API] updateGlobalVersion() called with:', {
662
+ id,
663
+ versionData,
664
+ ...args
665
+ });
666
+ const result = {};
667
+ console.log('[DB_CONTENT_API] updateGlobalVersion() result:', result);
668
+ return result;
669
+ };
670
+ const countGlobalVersions = async function countGlobalVersions({ req, where, ...args }) {
671
+ console.log('🔍 [DB_CONTENT_API] countGlobalVersions() called with:', {
672
+ where,
673
+ ...args
674
+ });
675
+ const totalDocs = 0;
676
+ const globalVersionsSlug = 'global-versions';
677
+ console.log(`📊 [DB_CONTENT_API] countGlobalVersions result: ${totalDocs} versions in ${globalVersionsSlug}`);
678
+ const result = {
679
+ totalDocs
680
+ };
681
+ console.log('[DB_CONTENT_API] countGlobalVersions() result:', result);
682
+ return result;
683
+ };
684
+ const request = async function(path, body = {}) {
685
+ console.log('🔍 [DB_CONTENT_API] request() called with:', {
686
+ body,
687
+ path
688
+ });
689
+ const res = await fetch(`${this.contentApiUrl}${path}`, {
690
+ body: JSON.stringify({
691
+ contentSystemId: this.contentSystemId,
692
+ ...body
693
+ }),
694
+ headers: {
695
+ 'Content-Type': 'application/json',
696
+ ...this.contentApiKey ? {
697
+ 'X-Api-Key': this.contentApiKey
698
+ } : {
699
+ Authorization: `Bearer ${this.projectToken}`
700
+ }
701
+ },
702
+ method: 'POST'
703
+ });
704
+ return res.json();
705
+ };
706
+ const beginTransaction = async function(options) {
707
+ console.log('🔍 [DB_CONTENT_API] beginTransaction() called', options);
708
+ return null;
709
+ };
710
+ const commitTransaction = async function(id) {
711
+ console.log('🔍 [DB_CONTENT_API] commitTransaction() called', id);
712
+ };
713
+ export const contentAPIAdapter = (opts)=>{
714
+ return {
715
+ name: 'content_api',
716
+ defaultIDType: 'text',
717
+ init: ({ payload })=>{
718
+ return createDatabaseAdapter({
719
+ name: 'content_api',
720
+ beginTransaction,
721
+ commitTransaction,
722
+ contentApiKey: opts.contentApiKey,
723
+ contentApiUrl: opts.contentApiUrl,
724
+ contentSystemId: opts.contentSystemId,
725
+ count,
726
+ countGlobalVersions,
727
+ countVersions,
728
+ create,
729
+ createGlobal,
730
+ createGlobalVersion,
731
+ createVersion,
732
+ defaultIDType: 'text',
733
+ deleteMany,
734
+ deleteOne,
735
+ deleteVersions,
736
+ find,
737
+ findDistinct,
738
+ findGlobal,
739
+ findGlobalVersions,
740
+ findOne,
741
+ findVersions,
742
+ init,
743
+ packageName: '@payloadcms/db-content-api',
744
+ payload,
745
+ projectToken: opts.projectToken,
746
+ queryDrafts,
747
+ request,
748
+ rollbackTransaction: async ()=>{},
749
+ updateGlobal,
750
+ updateGlobalVersion,
751
+ updateMany,
752
+ updateOne,
753
+ updateVersion,
754
+ upsert
755
+ });
756
+ }
757
+ };
758
+ };
759
+
760
+ //# sourceMappingURL=db-adapter.js.map