@carddb/core 0.4.2 → 0.4.5

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/index.cjs CHANGED
@@ -303,6 +303,47 @@ function resolveFilter(input) {
303
303
  }
304
304
 
305
305
  // src/query-builder.ts
306
+ var DECK_JSON_OBJECT_KEYS = /* @__PURE__ */ new Set(["metadata", "annotations"]);
307
+ function normalizeDeckJsonInput(input) {
308
+ return normalizeDeckJsonValue(input, "input");
309
+ }
310
+ function normalizeDeckJsonValue(value, path) {
311
+ if (!isRecord(value)) {
312
+ return value;
313
+ }
314
+ const normalized = {};
315
+ for (const [key, child] of Object.entries(value)) {
316
+ const childPath = `${path}.${key}`;
317
+ if (DECK_JSON_OBJECT_KEYS.has(key)) {
318
+ normalized[key] = normalizeJsonObject(child, childPath);
319
+ } else if (key === "entries" && Array.isArray(child)) {
320
+ normalized[key] = child.map(
321
+ (entry, index) => normalizeDeckJsonValue(entry, `${childPath}[${index}]`)
322
+ );
323
+ } else {
324
+ normalized[key] = child;
325
+ }
326
+ }
327
+ return normalized;
328
+ }
329
+ function normalizeJsonObject(value, path) {
330
+ if (value == null || isRecord(value)) {
331
+ return value;
332
+ }
333
+ if (typeof value === "string") {
334
+ try {
335
+ const parsed = JSON.parse(value);
336
+ if (isRecord(parsed)) {
337
+ return parsed;
338
+ }
339
+ } catch {
340
+ }
341
+ }
342
+ throw new ValidationError(`${path} must be a JSON object`);
343
+ }
344
+ function isRecord(value) {
345
+ return typeof value === "object" && value !== null && !Array.isArray(value);
346
+ }
306
347
  var FILE_FIELDS = `
307
348
  id
308
349
  createdAt
@@ -643,36 +684,12 @@ var DECK_COLLABORATOR_FIELDS = `
643
684
  createdAt
644
685
  updatedAt
645
686
  `;
646
- var DECK_PREVIEW_TOKEN_FIELDS = `
687
+ var DECK_TOKEN_ISSUER_FIELDS = `
647
688
  id
648
- deckId
649
- label
650
- expiresAt
651
- revokedAt
652
- lastUsedAt
653
- createdAt
654
- updatedAt
655
- `;
656
- var DECK_EMBED_TOKEN_FIELDS = `
657
- id
658
- deckId
659
- apiApplicationId
660
- label
661
- readMode
662
- allowedOrigins
663
- externalSubject
664
- expiresAt
665
- revokedAt
666
- lastUsedAt
667
- createdAt
668
- updatedAt
669
- `;
670
- var DECK_ACCESS_TOKEN_ISSUER_FIELDS = `
671
- id
672
- deckId
673
689
  apiApplicationId
674
690
  label
675
- readModes
691
+ allowedScopes
692
+ allowedRepresentations
676
693
  maxTokenLifetimeSeconds
677
694
  directSigningAlg
678
695
  directSigningKeyId
@@ -682,13 +699,15 @@ var DECK_ACCESS_TOKEN_ISSUER_FIELDS = `
682
699
  createdAt
683
700
  updatedAt
684
701
  `;
685
- var DECK_ACCESS_TOKEN_FIELDS = `
702
+ var DECK_TOKEN_FIELDS = `
686
703
  id
687
- deckId
688
704
  apiApplicationId
689
705
  issuerId
690
- readMode
706
+ deckId
707
+ gameId
691
708
  externalSubject
709
+ scopes
710
+ representation
692
711
  expiresAt
693
712
  revokedAt
694
713
  lastUsedAt
@@ -2812,8 +2831,8 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
2812
2831
  deckById() {
2813
2832
  return {
2814
2833
  query: `
2815
- query Deck($id: UUID!) {
2816
- deck(id: $id) {
2834
+ query Deck($id: UUID!, $readState: DeckReadState!, $version: DeckPublishedVersionSelector) {
2835
+ deck(id: $id, readState: $readState, version: $version) {
2817
2836
  ${DECK_FIELDS}
2818
2837
  }
2819
2838
  }
@@ -2867,8 +2886,8 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
2867
2886
  deckByExternalRef() {
2868
2887
  return {
2869
2888
  query: `
2870
- query DeckByExternalRef($externalRef: String!) {
2871
- deckByExternalRef(externalRef: $externalRef) {
2889
+ query DeckByExternalRef($externalRef: String!, $readState: DeckReadState!, $version: DeckPublishedVersionSelector) {
2890
+ deckByExternalRef(externalRef: $externalRef, readState: $readState, version: $version) {
2872
2891
  ${DECK_FIELDS}
2873
2892
  }
2874
2893
  }
@@ -2911,39 +2930,6 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
2911
2930
  variables
2912
2931
  };
2913
2932
  },
2914
- deckPreview() {
2915
- return {
2916
- query: `
2917
- query DeckPreview($token: String!) {
2918
- deckPreview(token: $token) {
2919
- ${DECK_FIELDS}
2920
- }
2921
- }
2922
- `
2923
- };
2924
- },
2925
- deckEmbed() {
2926
- return {
2927
- query: `
2928
- query DeckEmbed($token: String!) {
2929
- deckEmbed(token: $token) {
2930
- ${DECK_FIELDS}
2931
- }
2932
- }
2933
- `
2934
- };
2935
- },
2936
- deckAccess() {
2937
- return {
2938
- query: `
2939
- query DeckAccess($token: String!) {
2940
- deckAccess(token: $token) {
2941
- ${DECK_FIELDS}
2942
- }
2943
- }
2944
- `
2945
- };
2946
- },
2947
2933
  deckDraftDiff() {
2948
2934
  return {
2949
2935
  query: `
@@ -3052,28 +3038,6 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
3052
3038
  `
3053
3039
  };
3054
3040
  },
3055
- deckEmbedTokens() {
3056
- return {
3057
- query: `
3058
- query DeckEmbedTokens($deckId: UUID!) {
3059
- deckEmbedTokens(deckId: $deckId) {
3060
- ${DECK_EMBED_TOKEN_FIELDS}
3061
- }
3062
- }
3063
- `
3064
- };
3065
- },
3066
- deckAccessTokenIssuers() {
3067
- return {
3068
- query: `
3069
- query DeckAccessTokenIssuers($deckId: UUID!) {
3070
- deckAccessTokenIssuers(deckId: $deckId) {
3071
- ${DECK_ACCESS_TOKEN_ISSUER_FIELDS}
3072
- }
3073
- }
3074
- `
3075
- };
3076
- },
3077
3041
  deckApiApplicationAccesses() {
3078
3042
  return {
3079
3043
  query: `
@@ -3160,17 +3124,6 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
3160
3124
  `
3161
3125
  };
3162
3126
  },
3163
- deckPreviewTokens() {
3164
- return {
3165
- query: `
3166
- query DeckPreviewTokens($deckId: UUID!) {
3167
- deckPreviewTokens(deckId: $deckId) {
3168
- ${DECK_PREVIEW_TOKEN_FIELDS}
3169
- }
3170
- }
3171
- `
3172
- };
3173
- },
3174
3127
  createDeck() {
3175
3128
  return {
3176
3129
  query: `
@@ -3435,120 +3388,58 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
3435
3388
  `
3436
3389
  };
3437
3390
  },
3438
- createDeckPreviewToken() {
3439
- return {
3440
- query: `
3441
- mutation DeckPreviewTokenCreate($input: DeckPreviewTokenCreateInput!) {
3442
- deckPreviewTokenCreate(input: $input) {
3443
- token
3444
- previewToken {
3445
- ${DECK_PREVIEW_TOKEN_FIELDS}
3446
- }
3447
- }
3448
- }
3449
- `
3450
- };
3451
- },
3452
- revokeDeckPreviewToken() {
3453
- return {
3454
- query: `
3455
- mutation DeckPreviewTokenRevoke($id: UUID!) {
3456
- deckPreviewTokenRevoke(id: $id)
3457
- }
3458
- `
3459
- };
3460
- },
3461
- createDeckEmbedToken() {
3462
- return {
3463
- query: `
3464
- mutation DeckEmbedTokenCreate($input: DeckEmbedTokenCreateInput!) {
3465
- deckEmbedTokenCreate(input: $input) {
3466
- token
3467
- embedToken {
3468
- ${DECK_EMBED_TOKEN_FIELDS}
3469
- }
3470
- }
3471
- }
3472
- `
3473
- };
3474
- },
3475
- revokeDeckEmbedToken() {
3391
+ createDeckTokenIssuer() {
3476
3392
  return {
3477
3393
  query: `
3478
- mutation DeckEmbedTokenRevoke($id: UUID!) {
3479
- deckEmbedTokenRevoke(id: $id)
3480
- }
3481
- `
3482
- };
3483
- },
3484
- createDeckAccessTokenIssuer() {
3485
- return {
3486
- query: `
3487
- mutation DeckAccessTokenIssuerCreate($input: DeckAccessTokenIssuerCreateInput!) {
3488
- deckAccessTokenIssuerCreate(input: $input) {
3489
- ${DECK_ACCESS_TOKEN_ISSUER_FIELDS}
3394
+ mutation DeckTokenIssuerCreate($input: DeckTokenIssuerCreateInput!) {
3395
+ deckTokenIssuerCreate(input: $input) {
3396
+ ${DECK_TOKEN_ISSUER_FIELDS}
3490
3397
  }
3491
3398
  }
3492
3399
  `
3493
3400
  };
3494
3401
  },
3495
- revokeDeckAccessTokenIssuer() {
3402
+ revokeDeckTokenIssuer() {
3496
3403
  return {
3497
3404
  query: `
3498
- mutation DeckAccessTokenIssuerRevoke($id: UUID!) {
3499
- deckAccessTokenIssuerRevoke(id: $id)
3405
+ mutation DeckTokenIssuerRevoke($id: UUID!) {
3406
+ deckTokenIssuerRevoke(id: $id)
3500
3407
  }
3501
3408
  `
3502
3409
  };
3503
3410
  },
3504
- revokeDeckAccessTokenIssuerSigningKey() {
3411
+ revokeDeckTokenIssuerSigningKey() {
3505
3412
  return {
3506
3413
  query: `
3507
- mutation DeckAccessTokenIssuerSigningKeyRevoke($id: UUID!) {
3508
- deckAccessTokenIssuerSigningKeyRevoke(id: $id) {
3509
- ${DECK_ACCESS_TOKEN_ISSUER_FIELDS}
3414
+ mutation DeckTokenIssuerSigningKeyRevoke($id: UUID!) {
3415
+ deckTokenIssuerSigningKeyRevoke(id: $id) {
3416
+ ${DECK_TOKEN_ISSUER_FIELDS}
3510
3417
  }
3511
3418
  }
3512
3419
  `
3513
3420
  };
3514
3421
  },
3515
- exchangeDeckAccessToken() {
3422
+ exchangeDeckToken() {
3516
3423
  return {
3517
3424
  query: `
3518
- mutation DeckAccessTokenExchange($input: DeckAccessTokenExchangeInput!) {
3519
- deckAccessTokenExchange(input: $input) {
3425
+ mutation DeckTokenExchange($input: DeckTokenExchangeInput!) {
3426
+ deckTokenExchange(input: $input) {
3520
3427
  token
3521
- accessToken {
3522
- ${DECK_ACCESS_TOKEN_FIELDS}
3428
+ deckToken {
3429
+ ${DECK_TOKEN_FIELDS}
3523
3430
  }
3524
3431
  }
3525
3432
  }
3526
3433
  `
3527
3434
  };
3528
3435
  },
3529
- exchangeDeckSessionToken() {
3436
+ revokeDeckToken() {
3530
3437
  return {
3531
3438
  query: `
3532
- mutation DeckSessionTokenExchange($input: DeckSessionTokenExchangeInput!) {
3533
- deckSessionTokenExchange(input: $input) {
3534
- token
3535
- sessionToken {
3536
- id
3537
- accountId
3538
- apiApplicationId
3539
- gameId
3540
- environment
3541
- externalSubject
3542
- scopes
3543
- expiresAt
3544
- revokedAt
3545
- lastUsedAt
3546
- createdAt
3547
- updatedAt
3548
- }
3549
- }
3550
- }
3551
- `
3439
+ mutation DeckTokenRevoke($id: UUID!) {
3440
+ deckTokenRevoke(id: $id)
3441
+ }
3442
+ `
3552
3443
  };
3553
3444
  },
3554
3445
  grantDeckApiApplicationAccess() {
@@ -3571,26 +3462,17 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
3571
3462
  `
3572
3463
  };
3573
3464
  },
3574
- revokeDeckAccessToken() {
3575
- return {
3576
- query: `
3577
- mutation DeckAccessTokenRevoke($id: UUID!) {
3578
- deckAccessTokenRevoke(id: $id)
3579
- }
3580
- `
3581
- };
3582
- },
3583
3465
  deckCreateVariables(input) {
3584
- return { input };
3466
+ return { input: normalizeDeckJsonInput(input) };
3585
3467
  },
3586
3468
  deckUpdateVariables(id, input) {
3587
- return { id, input };
3469
+ return { id, input: normalizeDeckJsonInput(input) };
3588
3470
  },
3589
3471
  deckEntryAddVariables(input) {
3590
- return { input };
3472
+ return { input: normalizeDeckJsonInput(input) };
3591
3473
  },
3592
3474
  deckEntryUpdateVariables(id, input) {
3593
- return { id, input };
3475
+ return { id, input: normalizeDeckJsonInput(input) };
3594
3476
  },
3595
3477
  deckEntryRemoveVariables(id, expectedDraftRevision) {
3596
3478
  return { id, expectedDraftRevision };
@@ -3599,7 +3481,7 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
3599
3481
  return { deckId, input };
3600
3482
  },
3601
3483
  deckEntriesReplaceVariables(deckId, input) {
3602
- return { deckId, input };
3484
+ return { deckId, input: normalizeDeckJsonInput(input) };
3603
3485
  },
3604
3486
  deckImportVariables(input) {
3605
3487
  return { input };
@@ -3614,7 +3496,13 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
3614
3496
  return { input };
3615
3497
  },
3616
3498
  deckUpsertByExternalRefVariables(input) {
3617
- return { input };
3499
+ return { input: normalizeDeckJsonInput(input) };
3500
+ },
3501
+ deckReadVariables(id, readState, version) {
3502
+ return { id, readState, version };
3503
+ },
3504
+ deckExternalRefReadVariables(externalRef, readState, version) {
3505
+ return { externalRef, readState, version };
3618
3506
  },
3619
3507
  deckClaimVariables(id, input) {
3620
3508
  return { id, input };
@@ -3635,7 +3523,7 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
3635
3523
  return { id, input };
3636
3524
  },
3637
3525
  deckHydrateEntriesVariables(input) {
3638
- return { input };
3526
+ return { input: normalizeDeckJsonInput(input) };
3639
3527
  },
3640
3528
  deckExportVariables(id, format) {
3641
3529
  return { id, format };
@@ -3646,19 +3534,10 @@ ${RESOLVED_LINKS_FIELDS}` : selectedRecordFields;
3646
3534
  deckCollaboratorVariables(deckId, accountId, role) {
3647
3535
  return role === void 0 ? { deckId, accountId } : { deckId, accountId, role };
3648
3536
  },
3649
- deckPreviewTokenCreateVariables(input) {
3650
- return { input };
3651
- },
3652
- deckEmbedTokenCreateVariables(input) {
3653
- return { input };
3654
- },
3655
- deckAccessTokenIssuerCreateVariables(input) {
3656
- return { input };
3657
- },
3658
- deckAccessTokenExchangeVariables(input) {
3537
+ deckTokenIssuerCreateVariables(input) {
3659
3538
  return { input };
3660
3539
  },
3661
- deckSessionTokenExchangeVariables(input) {
3540
+ deckTokenExchangeVariables(input) {
3662
3541
  return { input };
3663
3542
  },
3664
3543
  deckApiApplicationAccessesVariables(deckId, includeRevoked) {