@carddb/browser 0.2.5 → 0.3.0

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.
@@ -1,4 +1,4 @@
1
- var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardDBError",this.response=r,Error.captureStackTrace&&Error.captureStackTrace(this,re);}},B=class extends y{constructor(e="Invalid or missing API key",t){super(e,t),this.name="AuthenticationError";}},q=class extends y{retryAfter;limit;remaining;resetAt;constructor(e="Rate limit exceeded",t={}){super(e,t.response),this.name="RateLimitError",this.retryAfter=t.retryAfter??null,this.limit=t.limit??null,this.remaining=t.remaining??null,this.resetAt=t.resetAt??null;}},mt=class extends y{constructor(e="Resource not found",t){super(e,t),this.name="NotFoundError";}},_=class extends y{errors;constructor(e="Validation error",t={}){super(e,t.response),this.name="ValidationError",this.errors=t.errors??[];}},b=class extends y{constructor(e,t){super(e,t),this.name="RestrictedError";}},se=class extends y{errors;constructor(e="GraphQL error",t={}){super(e,t.response),this.name="GraphQLError",this.errors=t.errors??[];}},E=class extends y{constructor(e="Connection error",t){super(e,t),this.name="ConnectionError";}},V=class extends E{constructor(e="Request timed out",t){super(e,t),this.name="TimeoutError";}},J=class extends y{status;constructor(e="Server error",t={}){super(e,t.response),this.name="ServerError",this.status=t.status??null;}},gt=class extends y{failures;partialResults;constructor(e="Some links could not be resolved",t={}){super(e,t.response),this.name="LinkResolutionError",this.failures=t.failures??[],this.partialResults=t.partialResults;}getFailuresForField(e){return this.failures.filter(t=>t.field===e)}hasFailuresForField(e){return this.failures.some(t=>t.field===e)}};function kt(e){return {eq:e}}function It(e){return {neq:e}}function $t(e){return {gt:e}}function bt(e){return {gte:e}}function vt(e){return {lt:e}}function Dt(e){return {lte:e}}function wt(e){return {in:e}}function At(e){return {nin:e}}function Et(e){return {contains:e}}function St(e){return {like:e}}function xt(e){return {ilike:e}}function Rt(){return {is_null:true}}function qt(){return {is_null:false}}var be=class ie{conditions=[];orGroups=[];where(t,r){if(typeof t=="string")this.conditions.push({[t]:r});else for(let[s,i]of Object.entries(t))this.conditions.push({[s]:i});return this}any(t){let r=new ie;t(r);let s=r.getConditions();return s.length>0&&this.orGroups.push({$or:s}),this}whereLink(t,r){let s={};for(let[i,n]of Object.entries(r))s[i]=n;return this.conditions.push({[`${t}._link`]:s}),this}whereAny(t,r){let s={};for(let[i,n]of Object.entries(r))s[i]=n;return this.conditions.push({[`${t}._any`]:s}),this}getConditions(){return this.conditions}build(){let t=[...this.conditions,...this.orGroups];return t.length===0?{}:t.length===1?t[0]:{$and:t}}};function C(e){if(e!==void 0){if(typeof e=="function"){let t=new be;e(t);let r=t.build();return Object.keys(r).length>0?r:void 0}return Object.keys(e).length>0?e:void 0}}var S=`
1
+ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardDBError",this.response=r,Error.captureStackTrace&&Error.captureStackTrace(this,re);}},B=class extends y{constructor(e="Invalid or missing API key",t){super(e,t),this.name="AuthenticationError";}},q=class extends y{retryAfter;limit;remaining;resetAt;constructor(e="Rate limit exceeded",t={}){super(e,t.response),this.name="RateLimitError",this.retryAfter=t.retryAfter??null,this.limit=t.limit??null,this.remaining=t.remaining??null,this.resetAt=t.resetAt??null;}},mt=class extends y{constructor(e="Resource not found",t){super(e,t),this.name="NotFoundError";}},V=class extends y{errors;constructor(e="Validation error",t={}){super(e,t.response),this.name="ValidationError",this.errors=t.errors??[];}},b=class extends y{constructor(e,t){super(e,t),this.name="RestrictedError";}},se=class extends y{errors;constructor(e="GraphQL error",t={}){super(e,t.response),this.name="GraphQLError",this.errors=t.errors??[];}},E=class extends y{constructor(e="Connection error",t){super(e,t),this.name="ConnectionError";}},_=class extends E{constructor(e="Request timed out",t){super(e,t),this.name="TimeoutError";}},J=class extends y{status;constructor(e="Server error",t={}){super(e,t.response),this.name="ServerError",this.status=t.status??null;}},gt=class extends y{failures;partialResults;constructor(e="Some links could not be resolved",t={}){super(e,t.response),this.name="LinkResolutionError",this.failures=t.failures??[],this.partialResults=t.partialResults;}getFailuresForField(e){return this.failures.filter(t=>t.field===e)}hasFailuresForField(e){return this.failures.some(t=>t.field===e)}};function kt(e){return {eq:e}}function It(e){return {neq:e}}function $t(e){return {gt:e}}function bt(e){return {gte:e}}function Dt(e){return {lt:e}}function vt(e){return {lte:e}}function wt(e){return {in:e}}function At(e){return {nin:e}}function Et(e){return {contains:e}}function St(e){return {like:e}}function xt(e){return {ilike:e}}function Rt(){return {is_null:true}}function qt(){return {is_null:false}}var be=class ie{conditions=[];orGroups=[];where(t,r){if(typeof t=="string")this.conditions.push({[t]:r});else for(let[s,i]of Object.entries(t))this.conditions.push({[s]:i});return this}any(t){let r=new ie;t(r);let s=r.getConditions();return s.length>0&&this.orGroups.push({$or:s}),this}whereLink(t,r){let s={};for(let[i,n]of Object.entries(r))s[i]=n;return this.conditions.push({[`${t}._link`]:s}),this}whereAny(t,r){let s={};for(let[i,n]of Object.entries(r))s[i]=n;return this.conditions.push({[`${t}._any`]:s}),this}getConditions(){return this.conditions}build(){let t=[...this.conditions,...this.orGroups];return t.length===0?{}:t.length===1?t[0]:{$and:t}}};function C(e){if(e!==void 0){if(typeof e=="function"){let t=new be;e(t);let r=t.build();return Object.keys(r).length>0?r:void 0}return Object.keys(e).length>0?e:void 0}}var S=`
2
2
  id
3
3
  createdAt
4
4
  updatedAt
@@ -11,7 +11,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
11
11
  entityType
12
12
  entityId
13
13
  url
14
- `,ve=`
14
+ `,De=`
15
15
  file {
16
16
  ${S}
17
17
  }
@@ -88,7 +88,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
88
88
  key
89
89
  name
90
90
  }
91
- `,De=4;function ae(e){return `
91
+ `,ve=4;function ae(e){return `
92
92
  key
93
93
  label
94
94
  description
@@ -123,10 +123,10 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
123
123
  nestedFields {
124
124
  ${ae(e-1)}
125
125
  }`:""}
126
- `}var D=`
126
+ `}var v=`
127
127
  schema {
128
128
  fields {
129
- ${ae(De)}
129
+ ${ae(ve)}
130
130
  }
131
131
  filterableFields
132
132
  searchableFields
@@ -214,7 +214,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
214
214
  excludedFromDeckSize
215
215
  legalCardTypes
216
216
  metadata
217
- `,K=`
217
+ `,T=`
218
218
  id
219
219
  datasetId
220
220
  recordId
@@ -303,7 +303,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
303
303
  publishedByApiApplicationId
304
304
  createdAt
305
305
  entries {
306
- ${K}
306
+ ${T}
307
307
  }
308
308
  `,Q=`
309
309
  id
@@ -335,7 +335,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
335
335
  lastUsedAt
336
336
  createdAt
337
337
  updatedAt
338
- `,T=`
338
+ `,K=`
339
339
  id
340
340
  deckId
341
341
  apiApplicationId
@@ -499,7 +499,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
499
499
  ${f}
500
500
  }
501
501
  entries {
502
- ${K}
502
+ ${T}
503
503
  }
504
504
  `,ee=`
505
505
  deck {
@@ -556,16 +556,16 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
556
556
  ${u}
557
557
  }
558
558
  entry {
559
- ${K}
559
+ ${T}
560
560
  }
561
561
  `,de=`
562
562
  deck {
563
563
  ${u}
564
564
  }
565
565
  entries {
566
- ${K}
566
+ ${T}
567
567
  }
568
- `,Ke=de,Te=`
568
+ `,Te=de,Ke=`
569
569
  deck {
570
570
  ${u}
571
571
  }
@@ -651,7 +651,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
651
651
  datasetId
652
652
  dataset {
653
653
  ${p}
654
- ${D}
654
+ ${v}
655
655
  }
656
656
  accountId
657
657
  status
@@ -786,9 +786,9 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
786
786
  sampleRecords
787
787
  availableDatasets {
788
788
  ${p}
789
- ${D}
789
+ ${v}
790
790
  }
791
- `,_e=`
791
+ `,Ve=`
792
792
  datasets {
793
793
  datasetKey
794
794
  datasetName
@@ -808,7 +808,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
808
808
  ${L}
809
809
  }
810
810
  canProceed
811
- `,Ve=`
811
+ `,_e=`
812
812
  datasetKey
813
813
  datasetId
814
814
  datasetName
@@ -819,7 +819,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
819
819
  skippedCount
820
820
  failedCount
821
821
  errorMessage
822
- `,v=`
822
+ `,D=`
823
823
  id
824
824
  publisherId
825
825
  publisher {
@@ -842,7 +842,7 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
842
842
  progress
843
843
  importOrder
844
844
  datasetStatuses {
845
- ${Ve}
845
+ ${_e}
846
846
  }
847
847
  errorMessage
848
848
  startedAt
@@ -984,14 +984,14 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
984
984
  query FetchDataset($id: UUID!) {
985
985
  fetchDataset(id: $id) {
986
986
  ${p}
987
- ${D}
987
+ ${v}
988
988
  }
989
989
  }
990
990
  `}},fetchDatasetByKeys(){return {query:`
991
991
  query FetchDataset($publisherSlug: String!, $gameKey: String!, $datasetKey: String!) {
992
992
  fetchDataset(publisherSlug: $publisherSlug, gameKey: $gameKey, datasetKey: $datasetKey) {
993
993
  ${p}
994
- ${D}
994
+ ${v}
995
995
  }
996
996
  }
997
997
  `}},fetchDatasets(){return {query:`
@@ -1004,14 +1004,14 @@ var y=class re extends Error{response;constructor(t,r){super(t),this.name="CardD
1004
1004
  query Datasets(${s.join(", ")}) {
1005
1005
  datasets(${r.join(", ")}) {
1006
1006
  ${l(`${p}
1007
- ${D}`)}
1007
+ ${v}`)}
1008
1008
  }
1009
1009
  }
1010
1010
  `,variables:t}},dataset(e){let t={},r=[],s=[];return e.id!==void 0&&(s.push("$id: UUID"),r.push("id: $id"),t.id=e.id),e.publisherId!==void 0&&(s.push("$publisherId: UUID"),r.push("publisherId: $publisherId"),t.publisherId=e.publisherId),e.gameId!==void 0&&(s.push("$gameId: UUID"),r.push("gameId: $gameId"),t.gameId=e.gameId),e.datasetKey!==void 0&&(s.push("$datasetKey: String"),r.push("datasetKey: $datasetKey"),t.datasetKey=e.datasetKey),{query:`
1011
1011
  query Dataset(${s.join(", ")}) {
1012
1012
  dataset(${r.join(", ")}) {
1013
1013
  ${p}
1014
- ${D}
1014
+ ${v}
1015
1015
  }
1016
1016
  }
1017
1017
  `,variables:t}},searchRecords(e){let t={publisherSlug:e.publisherSlug,gameKey:e.gameKey,datasetKey:e.datasetKey},r=["publisherSlug: $publisherSlug","gameKey: $gameKey","datasetKey: $datasetKey"],s=["$publisherSlug: String!","$gameKey: String!","$datasetKey: String!"];e.filter!==void 0&&(s.push("$filter: JSON"),r.push("filter: $filter"),t.filter=e.filter),e.search!==void 0&&(s.push("$search: String"),r.push("search: $search"),t.search=e.search),e.orderBy!==void 0&&(s.push("$orderBy: String"),r.push("orderBy: $orderBy"),t.orderBy=e.orderBy),e.resolveLinks!==void 0&&(s.push("$resolveLinks: [String!]"),r.push("resolveLinks: $resolveLinks"),t.resolveLinks=e.resolveLinks),e.first!==void 0&&(s.push("$first: Int"),r.push("first: $first"),t.first=e.first),e.after!==void 0&&(s.push("$after: String"),r.push("after: $after"),t.after=e.after),e.validateSchema!==void 0&&(s.push("$validateSchema: Boolean"),r.push("validateSchema: $validateSchema"),t.validateSchema=e.validateSchema);let i=e.resolveLinks&&e.resolveLinks.length>0,n=k({includePricing:e.includePricing}),c=i?`${n}
@@ -1141,43 +1141,43 @@ ${te}`:n;return {query:`
1141
1141
  `,variables:t}},gameImportPreview(){return {query:`
1142
1142
  query GameImportPreview($input: GameImportPreviewInput!) {
1143
1143
  gameImportPreview(input: $input) {
1144
- ${_e}
1144
+ ${Ve}
1145
1145
  }
1146
1146
  }
1147
1147
  `}},gameImportFromFile(){return {query:`
1148
1148
  mutation GameImportFromFile($input: GameImportFromFileInput!) {
1149
1149
  gameImportFromFile(input: $input) {
1150
- ${v}
1150
+ ${D}
1151
1151
  }
1152
1152
  }
1153
1153
  `}},gameImportFromPayload(){return {query:`
1154
1154
  mutation GameImportFromPayload($input: GameImportFromPayloadInput!) {
1155
1155
  gameImportFromPayload(input: $input) {
1156
- ${v}
1156
+ ${D}
1157
1157
  }
1158
1158
  }
1159
1159
  `}},gameImportFromUrl(){return {query:`
1160
1160
  mutation GameImportFromUrl($input: GameImportFromUrlInput!) {
1161
1161
  gameImportFromUrl(input: $input) {
1162
- ${v}
1162
+ ${D}
1163
1163
  }
1164
1164
  }
1165
1165
  `}},gameImportJob(){return {query:`
1166
1166
  query GameImportJob($id: UUID!) {
1167
1167
  gameImportJob(id: $id) {
1168
- ${v}
1168
+ ${D}
1169
1169
  }
1170
1170
  }
1171
1171
  `}},gameImportJobs(e){let t={gameId:e.gameId},r=["gameId: $gameId"],s=["$gameId: UUID!"];return e.status!==void 0&&(s.push("$status: ImportJobStatus"),r.push("status: $status"),t.status=e.status),e.first!==void 0&&(s.push("$first: Int"),r.push("first: $first"),t.first=e.first),e.after!==void 0&&(s.push("$after: String"),r.push("after: $after"),t.after=e.after),{query:`
1172
1172
  query GameImportJobs(${s.join(", ")}) {
1173
1173
  gameImportJobs(${r.join(", ")}) {
1174
- ${l(v)}
1174
+ ${l(D)}
1175
1175
  }
1176
1176
  }
1177
1177
  `,variables:t}},gameImportJobCancel(){return {query:`
1178
1178
  mutation GameImportJobCancel($id: UUID!) {
1179
1179
  gameImportJobCancel(id: $id) {
1180
- ${v}
1180
+ ${D}
1181
1181
  }
1182
1182
  }
1183
1183
  `}},file(){return {query:`
@@ -1189,7 +1189,7 @@ ${te}`:n;return {query:`
1189
1189
  `}},fileUploadRequest(){return {query:`
1190
1190
  mutation FileUploadRequest($input: FileUploadInput!) {
1191
1191
  fileUploadRequest(input: $input) {
1192
- ${ve}
1192
+ ${De}
1193
1193
  }
1194
1194
  }
1195
1195
  `}},fileUploadConfirm(){return {query:`
@@ -1379,7 +1379,7 @@ ${te}`:n;return {query:`
1379
1379
  `}},deckAccessTokenIssuers(){return {query:`
1380
1380
  query DeckAccessTokenIssuers($deckId: UUID!) {
1381
1381
  deckAccessTokenIssuers(deckId: $deckId) {
1382
- ${T}
1382
+ ${K}
1383
1383
  }
1384
1384
  }
1385
1385
  `}},deckApiApplicationAccesses(){return {query:`
@@ -1479,13 +1479,13 @@ ${te}`:n;return {query:`
1479
1479
  `}},replaceDeckEntries(){return {query:`
1480
1480
  mutation DeckEntriesReplace($deckId: UUID!, $input: DeckEntriesReplaceInput!) {
1481
1481
  deckEntriesReplace(deckId: $deckId, input: $input) {
1482
- ${Ke}
1482
+ ${Te}
1483
1483
  }
1484
1484
  }
1485
1485
  `}},importDeck(){return {query:`
1486
1486
  mutation DeckImport($input: DeckImportInput!) {
1487
1487
  deckImport(input: $input) {
1488
- ${Te}
1488
+ ${Ke}
1489
1489
  }
1490
1490
  }
1491
1491
  `}},createDeckImportFormat(){return {query:`
@@ -1591,7 +1591,7 @@ ${te}`:n;return {query:`
1591
1591
  `}},createDeckAccessTokenIssuer(){return {query:`
1592
1592
  mutation DeckAccessTokenIssuerCreate($input: DeckAccessTokenIssuerCreateInput!) {
1593
1593
  deckAccessTokenIssuerCreate(input: $input) {
1594
- ${T}
1594
+ ${K}
1595
1595
  }
1596
1596
  }
1597
1597
  `}},revokeDeckAccessTokenIssuer(){return {query:`
@@ -1601,7 +1601,7 @@ ${te}`:n;return {query:`
1601
1601
  `}},revokeDeckAccessTokenIssuerSigningKey(){return {query:`
1602
1602
  mutation DeckAccessTokenIssuerSigningKeyRevoke($id: UUID!) {
1603
1603
  deckAccessTokenIssuerSigningKeyRevoke(id: $id) {
1604
- ${T}
1604
+ ${K}
1605
1605
  }
1606
1606
  }
1607
1607
  `}},exchangeDeckAccessToken(){return {query:`
@@ -1613,7 +1613,27 @@ ${te}`:n;return {query:`
1613
1613
  }
1614
1614
  }
1615
1615
  }
1616
- `}},grantDeckApiApplicationAccess(){return {query:`
1616
+ `}},exchangeDeckSessionToken(){return {query:`
1617
+ mutation DeckSessionTokenExchange($input: DeckSessionTokenExchangeInput!) {
1618
+ deckSessionTokenExchange(input: $input) {
1619
+ token
1620
+ sessionToken {
1621
+ id
1622
+ accountId
1623
+ apiApplicationId
1624
+ gameId
1625
+ environment
1626
+ externalSubject
1627
+ scopes
1628
+ expiresAt
1629
+ revokedAt
1630
+ lastUsedAt
1631
+ createdAt
1632
+ updatedAt
1633
+ }
1634
+ }
1635
+ }
1636
+ `}},grantDeckApiApplicationAccess(){return {query:`
1617
1637
  mutation DeckApiApplicationAccessGrant($input: DeckAPIApplicationAccessGrantInput!) {
1618
1638
  deckApiApplicationAccessGrant(input: $input) {
1619
1639
  ${U}
@@ -1627,7 +1647,7 @@ ${te}`:n;return {query:`
1627
1647
  mutation DeckAccessTokenRevoke($id: UUID!) {
1628
1648
  deckAccessTokenRevoke(id: $id)
1629
1649
  }
1630
- `}},deckCreateVariables(e){return {input:e}},deckUpdateVariables(e,t){return {id:e,input:t}},deckEntryAddVariables(e){return {input:e}},deckEntryUpdateVariables(e,t){return {id:e,input:t}},deckEntryRemoveVariables(e,t){return {id:e,expectedDraftRevision:t}},deckEntryReorderVariables(e,t){return {deckId:e,input:t}},deckEntriesReplaceVariables(e,t){return {deckId:e,input:t}},deckImportVariables(e){return {input:e}},deckImportFormatCreateVariables(e){return {input:e}},deckImportFormatUpdateVariables(e,t){return {id:e,input:t}},deckImportFormatTestVariables(e){return {input:e}},deckUpsertByExternalRefVariables(e){return {input:e}},deckClaimVariables(e,t){return {id:e,input:t}},deckTransferOwnershipVariables(e,t){return {id:e,input:t}},deckCopyVariables(e,t){return {id:e,input:t}},deckPublishVariables(e,t){return {id:e,input:t}},deckValidateVariables(e,t){return t===void 0?{id:e}:{id:e,input:t}},deckRemoveInvalidEntriesVariables(e,t){return {id:e,input:t}},deckHydrateEntriesVariables(e){return {input:e}},deckExportVariables(e,t){return {id:e,format:t}},deckVersionDiffVariables(e,t){return {fromVersionId:e,toVersionId:t}},deckCollaboratorVariables(e,t,r){return r===void 0?{deckId:e,accountId:t}:{deckId:e,accountId:t,role:r}},deckPreviewTokenCreateVariables(e){return {input:e}},deckEmbedTokenCreateVariables(e){return {input:e}},deckAccessTokenIssuerCreateVariables(e){return {input:e}},deckAccessTokenExchangeVariables(e){return {input:e}},deckApiApplicationAccessesVariables(e,t){return t===void 0?{deckId:e}:{deckId:e,includeRevoked:t}},myDeckApiApplicationAccessesVariables(e){return e===void 0?{}:{applicationId:e}},deckApiApplicationAccessGrantVariables(e){return {input:e}},deckApiApplicationAccessRevokeVariables(e,t){return {deckId:e,apiApplicationId:t}},gameCreateVariables(e){return {input:e}},gameUpdateVariables(e,t){return {id:e,input:t}},datasetImportPreviewVariables(e){return {input:e}},datasetImportValidateVariables(e){return {input:e}},datasetImportFromFileVariables(e){return {input:e}},datasetImportFromPayloadVariables(e){return {input:e}},datasetImportFromUrlVariables(e){return {input:e}},gameImportPreviewVariables(e){return {input:e}},gameImportFromFileVariables(e){return {input:e}},gameImportFromPayloadVariables(e){return {input:e}},gameImportFromUrlVariables(e){return {input:e}},datasetRecordsUpsertVariables(e){return {input:e}},datasetRecordsDeleteVariables(e){return {input:e}},fileUploadRequestVariables(e){return {input:e}},datasetExportVariables(e){return {input:e}},fetchMe(){return {query:`
1650
+ `}},deckCreateVariables(e){return {input:e}},deckUpdateVariables(e,t){return {id:e,input:t}},deckEntryAddVariables(e){return {input:e}},deckEntryUpdateVariables(e,t){return {id:e,input:t}},deckEntryRemoveVariables(e,t){return {id:e,expectedDraftRevision:t}},deckEntryReorderVariables(e,t){return {deckId:e,input:t}},deckEntriesReplaceVariables(e,t){return {deckId:e,input:t}},deckImportVariables(e){return {input:e}},deckImportFormatCreateVariables(e){return {input:e}},deckImportFormatUpdateVariables(e,t){return {id:e,input:t}},deckImportFormatTestVariables(e){return {input:e}},deckUpsertByExternalRefVariables(e){return {input:e}},deckClaimVariables(e,t){return {id:e,input:t}},deckTransferOwnershipVariables(e,t){return {id:e,input:t}},deckCopyVariables(e,t){return {id:e,input:t}},deckPublishVariables(e,t){return {id:e,input:t}},deckValidateVariables(e,t){return t===void 0?{id:e}:{id:e,input:t}},deckRemoveInvalidEntriesVariables(e,t){return {id:e,input:t}},deckHydrateEntriesVariables(e){return {input:e}},deckExportVariables(e,t){return {id:e,format:t}},deckVersionDiffVariables(e,t){return {fromVersionId:e,toVersionId:t}},deckCollaboratorVariables(e,t,r){return r===void 0?{deckId:e,accountId:t}:{deckId:e,accountId:t,role:r}},deckPreviewTokenCreateVariables(e){return {input:e}},deckEmbedTokenCreateVariables(e){return {input:e}},deckAccessTokenIssuerCreateVariables(e){return {input:e}},deckAccessTokenExchangeVariables(e){return {input:e}},deckSessionTokenExchangeVariables(e){return {input:e}},deckApiApplicationAccessesVariables(e,t){return t===void 0?{deckId:e}:{deckId:e,includeRevoked:t}},myDeckApiApplicationAccessesVariables(e){return e===void 0?{}:{applicationId:e}},deckApiApplicationAccessGrantVariables(e){return {input:e}},deckApiApplicationAccessRevokeVariables(e,t){return {deckId:e,apiApplicationId:t}},gameCreateVariables(e){return {input:e}},gameUpdateVariables(e,t){return {id:e,input:t}},datasetImportPreviewVariables(e){return {input:e}},datasetImportValidateVariables(e){return {input:e}},datasetImportFromFileVariables(e){return {input:e}},datasetImportFromPayloadVariables(e){return {input:e}},datasetImportFromUrlVariables(e){return {input:e}},gameImportPreviewVariables(e){return {input:e}},gameImportFromFileVariables(e){return {input:e}},gameImportFromPayloadVariables(e){return {input:e}},gameImportFromUrlVariables(e){return {input:e}},datasetRecordsUpsertVariables(e){return {input:e}},datasetRecordsDeleteVariables(e){return {input:e}},fileUploadRequestVariables(e){return {input:e}},datasetExportVariables(e){return {input:e}},fetchMe(){return {query:`
1631
1651
  query FetchMe {
1632
1652
  fetchMe {
1633
1653
  application {
@@ -1649,6 +1669,6 @@ ${te}`:n;return {query:`
1649
1669
  }
1650
1670
  }
1651
1671
  }
1652
- `}}},d=class{totalCount;pageInfo;items;nextPageLoader;constructor(e,t={}){this.totalCount=e.totalCount,this.pageInfo=e.pageInfo,this.items=e.edges.map(r=>t.itemTransformer?t.itemTransformer(r.node):r.node),this.nextPageLoader=t.nextPageLoader;}get hasNextPage(){return this.pageInfo.hasNextPage}get hasPreviousPage(){return this.pageInfo.hasPreviousPage}get endCursor(){return this.pageInfo.endCursor}get startCursor(){return this.pageInfo.startCursor}get length(){return this.items.length}get isEmpty(){return this.items.length===0}get first(){return this.items[0]}get last(){return this.items[this.items.length-1]}async nextPage(){if(!this.hasNextPage)return null;if(!this.nextPageLoader)throw new Error("No next page loader configured");return this.endCursor?this.nextPageLoader(this.endCursor):null}async*[Symbol.asyncIterator](){let e=this;for(;e;){for(let t of e.items)yield t;if(!e.hasNextPage)break;e=await e.nextPage();}}async forEach(e){let t=0;for await(let r of this)await e(r,t++);}async map(e){let t=[],r=0;for await(let s of this)t.push(await e(s,r++));return t}async filter(e){let t=[],r=0;for await(let s of this)await e(s,r++)&&t.push(s);return t}async find(e){let t=0;for await(let r of this)if(await e(r,t++))return r}async take(e){let t=[];for await(let r of this){if(t.length>=e)break;t.push(r);}return t}async toArray(){let e=[];for await(let t of this)e.push(t);return e}async*batches(){let e=this;for(;e&&(e.items.length>0&&(yield e.items),!!e.hasNextPage);)e=await e.nextPage();}each(){return this}};var Je="https://carddb.xtda.org/query",Oe=3e4,Ge=1e4,Me=300,Ne=3,je=2,Ye=1e3,He=3e4,Xe=class pe{apiKey;publishableKey;secretKey;accessToken;legacyApiKey;environment;endpoint;timeout;openTimeout;defaultPublisher;defaultGame;allowedPublishers;allowedGames;logger;logLevel;retryOnRateLimit;maxRetries;retryOnNetworkError;maxNetworkRetries;retryBaseDelay;retryMaxDelay;cache;cacheTtl;cacheTtls;constructor(t={}){this.legacyApiKey=t.apiKey,this.publishableKey=t.publishableKey,this.secretKey=t.secretKey,this.accessToken=t.accessToken,this.apiKey=t.apiKey??t.publishableKey??t.secretKey,this.environment=t.environment,this.endpoint=t.endpoint??Je,this.timeout=t.timeout??Oe,this.openTimeout=t.openTimeout??Ge,this.defaultPublisher=t.defaultPublisher,this.defaultGame=t.defaultGame,this.allowedPublishers=t.allowedPublishers,this.allowedGames=t.allowedGames,this.logger=t.logger,this.logLevel=t.logLevel??"info",this.retryOnRateLimit=t.retryOnRateLimit??false,this.maxRetries=t.maxRetries??Ne,this.retryOnNetworkError=t.retryOnNetworkError??true,this.maxNetworkRetries=t.maxNetworkRetries??je,this.retryBaseDelay=t.retryBaseDelay??Ye,this.retryMaxDelay=t.retryMaxDelay??He,this.cache=t.cache,this.cacheTtl=t.cacheTtl??Me,this.cacheTtls=t.cacheTtls??{};}calculateRetryDelay(t){let r=this.retryBaseDelay*Math.pow(2,t),s=Math.min(r,this.retryMaxDelay),i=s*.25*(Math.random()*2-1);return Math.round(s+i)}cacheTtlFor(t){return this.cacheTtls[t]??this.cacheTtl}resolvePublisher(t){return t??this.defaultPublisher}resolveGame(t){return t??this.defaultGame}validatePublisher(t){if(this.allowedPublishers&&!this.allowedPublishers.includes(t))throw new b(`Publisher '${t}' is not in the allowed publishers list`)}validateGame(t,r){if(!this.allowedGames)return;let s=this.allowedGames[t];if(s&&!s.includes(r))throw new b(`Game '${r}' is not allowed for publisher '${t}'`)}validateAccess(t,r){t&&(this.validatePublisher(t),r&&this.validateGame(t,r));}requireSecretCredential(t){if(!(!this.accessToken&&(this.legacyApiKey||this.secretKey&&!this.publishableKey)))throw new b(`${t} requires a server-side secretKey or legacy apiKey credential`)}requestApiKey(){return this.legacyApiKey??this.publishableKey??this.secretKey}configApiKey(){return this.legacyApiKey}shouldLog(t){let r={debug:0,info:1,warn:2,error:3};return r[t]>=r[this.logLevel]}merge(t){return new pe({apiKey:t.apiKey??this.legacyApiKey,publishableKey:t.publishableKey??this.publishableKey,secretKey:t.secretKey??this.secretKey,accessToken:t.accessToken??this.accessToken,environment:t.environment??this.environment,endpoint:t.endpoint??this.endpoint,timeout:t.timeout??this.timeout,openTimeout:t.openTimeout??this.openTimeout,defaultPublisher:t.defaultPublisher??this.defaultPublisher,defaultGame:t.defaultGame??this.defaultGame,allowedPublishers:t.allowedPublishers??this.allowedPublishers,allowedGames:t.allowedGames??this.allowedGames,logger:t.logger??this.logger,logLevel:t.logLevel??this.logLevel,retryOnRateLimit:t.retryOnRateLimit??this.retryOnRateLimit,maxRetries:t.maxRetries??this.maxRetries,retryOnNetworkError:t.retryOnNetworkError??this.retryOnNetworkError,maxNetworkRetries:t.maxNetworkRetries??this.maxNetworkRetries,retryBaseDelay:t.retryBaseDelay??this.retryBaseDelay,retryMaxDelay:t.retryMaxDelay??this.retryMaxDelay,cache:t.cache??this.cache,cacheTtl:t.cacheTtl??this.cacheTtl,cacheTtls:t.cacheTtls??this.cacheTtls})}},me="0.1.0";function We(){if(typeof globalThis<"u"&&"Bun"in globalThis){let e=globalThis.Bun&&typeof globalThis.Bun=="object"&&globalThis.Bun.version;return {name:"bun",version:typeof e=="string"?e:"unknown"}}if(typeof globalThis<"u"&&"Deno"in globalThis){let e=globalThis.Deno&&typeof globalThis.Deno=="object"&&globalThis.Deno.version&&typeof globalThis.Deno.version=="object"&&globalThis.Deno.version.deno;return {name:"deno",version:typeof e=="string"?e:"unknown"}}return typeof process<"u"&&process.versions&&process.versions.node?{name:"node",version:process.versions.node}:typeof navigator<"u"&&navigator.userAgent?Qe(navigator.userAgent):{name:"unknown",version:"unknown"}}function Qe(e){let t=e.match(/Edg\/(\d+(?:\.\d+)*)/);if(t)return {name:"edge",version:t[1]};let r=e.match(/Chrome\/(\d+(?:\.\d+)*)/);if(r&&!e.includes("Edg/"))return {name:"chrome",version:r[1]};let s=e.match(/Firefox\/(\d+(?:\.\d+)*)/);if(s)return {name:"firefox",version:s[1]};let i=e.match(/Version\/(\d+(?:\.\d+)*).*Safari/);return i?{name:"safari",version:i[1]}:{name:"browser",version:"unknown"}}function ze(){let e=We();return `CardDB-SDK/js/${me} (${e.name}/${e.version})`}function Mt(){return me}var ge=null;function Ze(){return ge}var et=class{config;constructor(e){this.config=e;}async execute(e,t={}){let r=this.extractOperationName(e),s=0,i=0;for(;;)try{let n=Date.now();this.logRequest(r,t);let c=await this.fetch(e,t),o=Date.now()-n,h=await this.handleResponse(c);return this.logResponse(r,o),h}catch(n){if(n instanceof q&&this.config.retryOnRateLimit&&s<this.config.maxRetries){s++;let c=n.retryAfter??60;this.logRateLimitRetry(r,s,c),await this.sleep(c*1e3);continue}if(this.isRetryableNetworkError(n)&&this.config.retryOnNetworkError&&i<this.config.maxNetworkRetries){let c=this.config.calculateRetryDelay(i);this.logNetworkRetry(r,i+1,c,n),i++,await this.sleep(c);continue}if(n instanceof J&&this.config.retryOnNetworkError&&i<this.config.maxNetworkRetries){let c=this.config.calculateRetryDelay(i);this.logNetworkRetry(r,i+1,c,n),i++,await this.sleep(c);continue}throw n}}isRetryableNetworkError(e){return e instanceof E||e instanceof V}async fetch(e,t){let r=new AbortController,s=setTimeout(()=>r.abort(),this.config.timeout),i=this.config.requestApiKey();try{return await fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","User-Agent":ze(),...this.config.accessToken?{Authorization:`Bearer ${this.config.accessToken}`}:{},...!this.config.accessToken&&i?{"X-API-Key":i}:{}},body:JSON.stringify({query:e,variables:t}),signal:r.signal})}catch(n){throw n instanceof Error?n.name==="AbortError"?(this.logError("Request timed out"),new V("Request timed out")):(this.logError(`Connection failed: ${n.message}`),new E(`Connection failed: ${n.message}`)):new E("Connection failed")}finally{clearTimeout(s);}}async handleResponse(e){switch(this.extractRateLimitInfo(e),e.status){case 200:return this.handleSuccessResponse(e);case 401:throw new B("Invalid or missing API key");case 429:return this.handleRateLimitResponse(e);default:if(e.status>=400&&e.status<500)return this.handleClientError(e);if(e.status>=500){let t=await this.parseBody(e);throw new J(`Server error (${e.status})`,{status:e.status,response:t})}throw new y(`Unexpected response status: ${e.status}`)}}async handleSuccessResponse(e){let t=await this.parseBody(e);return t.errors&&t.errors.length>0&&this.handleGraphQLErrors(t.errors,t),t.data??{}}handleGraphQLErrors(e,t){let r=e[0],s=r.message||"GraphQL error";switch(r.extensions?.code){case "UNAUTHENTICATED":throw new B(s,t);case "RATE_LIMITED":throw new q(s,{response:t});case "NOT_FOUND":throw new y(s,t);case "VALIDATION_ERROR":case "BAD_USER_INPUT":throw new _(s,{errors:e,response:t});default:throw new se(s,{errors:e,response:t})}}async handleRateLimitResponse(e){let t=parseInt(e.headers.get("Retry-After")??"60",10),r=parseInt(e.headers.get("X-RateLimit-Limit")??"",10)||null,s=parseInt(e.headers.get("X-RateLimit-Remaining")??"",10)||null,i=parseInt(e.headers.get("X-RateLimit-Reset")??"",10)||null,n=i?new Date(i*1e3):null,c=await this.parseBody(e);throw new q("Rate limit exceeded",{retryAfter:t,limit:r,remaining:s,resetAt:n,response:c})}async handleClientError(e){let t=await this.parseBody(e),r=t.errors?.[0]?.message??`Client error (${e.status})`;throw new _(r,{response:t})}async parseBody(e){try{return await e.json()}catch{return {raw:await e.text()}}}extractRateLimitInfo(e){let t=parseInt(e.headers.get("X-RateLimit-Limit")??"",10)||null,r=parseInt(e.headers.get("X-RateLimit-Remaining")??"",10)||null,s=parseInt(e.headers.get("X-RateLimit-Reset")??"",10)||null;ge={limit:t,remaining:r,reset:s};}extractOperationName(e){let t=e.match(/(?:query|mutation)\s+(\w+)/);return t?t[1]:"Unknown"}sleep(e){return new Promise(t=>setTimeout(t,e))}logRequest(e,t){!this.config.logger||!this.config.shouldLog("debug")||this.config.logger.debug(`[CardDB] Executing ${e}`,{variables:t});}logResponse(e,t){!this.config.logger||!this.config.shouldLog("info")||this.config.logger.info(`[CardDB] ${e} completed in ${t}ms`);}logRateLimitRetry(e,t,r){!this.config.logger||!this.config.shouldLog("warn")||this.config.logger.warn(`[CardDB] Rate limited on ${e}, retry ${t}/${this.config.maxRetries} after ${r}s`);}logNetworkRetry(e,t,r,s){if(!this.config.logger||!this.config.shouldLog("warn"))return;let i=s instanceof Error?s.name:"Unknown";this.config.logger.warn(`[CardDB] ${i} on ${e}, retry ${t}/${this.config.maxNetworkRetries} after ${r}ms`);}logError(e){!this.config.logger||!this.config.shouldLog("error")||this.config.logger.error(`[CardDB] ${e}`);}};function tt(e,t,r){let s=Object.entries(r).filter(([,i])=>i!==void 0).sort(([i],[n])=>i.localeCompare(n)).map(([i,n])=>`${i}=${JSON.stringify(n)}`).join("&");return `carddb:${e}:${t}:${s}`}async function rt(e,t){let r=e.get(t);return r}async function st(e,t,r,s){let i=e.set(t,r,s);i instanceof Promise&&await i;}var m=class{connection;config;constructor(e,t){this.connection=e,this.config=t;}resolvePublisher(e){let t=this.config.resolvePublisher(e);if(!t)throw new Error("publisher_slug is required (no default configured)");return t}resolveGame(e){let t=this.config.resolveGame(e);if(!t)throw new Error("game_key is required (no default configured)");return t}validateAccess(e,t){this.config.validateAccess(e,t);}async withCache(e,t,r,s){let i=r.cache??!!this.config.cache,n=this.config.cache;if(!i||!n)return s();let c=await rt(n,e);if(c!==null)return c;let o=await s();if(o!=null){let h=this.config.cacheTtlFor(t);await st(n,e,o,h);}return o}cacheKey(e,t,r){return tt(e,t,r)}},it=class extends m{constructor(e,t){super(e,t);}async search(e={}){let{query:t,variables:r}=a.searchPublishers({search:e.search,first:e.first,after:e.after}),s=this.cacheKey("publishers","search",r),i=await this.withCache(s,"publishers",e,async()=>(await this.connection.execute(t,r)).searchPublishers);return new d(i,{nextPageLoader:async n=>this.search({...e,after:n})})}async get(e,t={}){let r=this.isUUID(e),s=this.cacheKey("publishers","get",{[r?"id":"slug"]:e});return this.withCache(s,"publishers",t,async()=>{if(r){let{query:i}=a.fetchPublisherById();return (await this.connection.execute(i,{id:e})).fetchPublisher??null}else {let{query:i}=a.fetchPublisherBySlug();return (await this.connection.execute(i,{slug:e})).fetchPublisher??null}})}async getMany(e,t={}){if(e.length===0)return [];let r=this.cacheKey("publishers","getMany",{slugs:e});return this.withCache(r,"publishers",t,async()=>{let{query:s}=a.fetchPublishers();return (await this.connection.execute(s,{slugs:e})).fetchPublishers??[]})}isUUID(e){return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e)}},at=class extends m{constructor(e,t){super(e,t);}async list(e,t={}){let{query:r,variables:s}=a.listGames({publisherId:e,first:t.first,after:t.after,includeArchived:t.includeArchived}),i=this.cacheKey("games","list",s),n=await this.withCache(i,"games",t,async()=>(await this.connection.execute(r,s)).games);return new d(n,{nextPageLoader:async c=>this.list(e,{...t,after:c})})}async getByKey(e){let t=this.cacheKey("games","getByKey",{publisherId:e.publisherId,publisherSlug:e.publisherSlug,gameKey:e.gameKey});return this.withCache(t,"games",e,async()=>{let{query:r,variables:s}=a.game(e);return (await this.connection.execute(r,s)).game??null})}async getBySlug(e){let t=this.cacheKey("games","getBySlug",{publisherId:e.publisherId,publisherSlug:e.publisherSlug,gameSlug:e.gameSlug});return this.withCache(t,"games",e,async()=>{let{query:r,variables:s}=a.game(e);return (await this.connection.execute(r,s)).game??null})}async create(e){this.config.requireSecretCredential("games.create");let{query:t}=a.createGame();return (await this.connection.execute(t,a.gameCreateVariables(e))).gameCreate}async update(e,t){this.config.requireSecretCredential("games.update");let{query:r}=a.updateGame();return (await this.connection.execute(r,a.gameUpdateVariables(e,t))).gameUpdate}async search(e={}){let t=this.config.resolvePublisher(e.publisherSlug);t&&this.validateAccess(t);let{query:r,variables:s}=a.searchGames({publisherSlug:t,search:e.search,first:e.first,after:e.after}),i=this.cacheKey("games","search",s),n=await this.withCache(i,"games",e,async()=>(await this.connection.execute(r,s)).searchGames);return new d(n,{nextPageLoader:async c=>this.search({...e,after:c})})}async get(e,t,r){if(typeof t=="string"){let s=e,i=t,n=r??{};this.validateAccess(s,i);let c=this.cacheKey("games","getByKeys",{publisherSlug:s,gameKey:i});return this.withCache(c,"games",n,async()=>{let{query:o}=a.fetchGameByKeys();return (await this.connection.execute(o,{publisherSlug:s,gameKey:i})).fetchGame??null})}else {let s=e,i=t??{},n=this.cacheKey("games","get",{id:s});return this.withCache(n,"games",i,async()=>{let{query:c}=a.fetchGameById();return (await this.connection.execute(c,{id:s})).fetchGame??null})}}async getMany(e,t={}){if(e.length===0)return [];let r=this.cacheKey("games","getMany",{ids:e});return this.withCache(r,"games",t,async()=>{let{query:s}=a.fetchGames();return (await this.connection.execute(s,{ids:e})).fetchGames??[]})}},nt=class extends m{constructor(e,t){super(e,t);}async list(e,t={}){let{query:r,variables:s}=a.listDatasets({publisherId:e,gameId:t.gameId,includeArchived:t.includeArchived,purpose:t.purpose,first:t.first,after:t.after}),i=this.cacheKey("datasets","list",s),n=await this.withCache(i,"datasets",t,async()=>(await this.connection.execute(r,s)).datasets);return new d(n,{nextPageLoader:async c=>this.list(e,{...t,after:c})})}async getByKey(e){let t=this.cacheKey("datasets","getByKey",{publisherId:e.publisherId,gameId:e.gameId,datasetKey:e.datasetKey});return this.withCache(t,"datasets",e,async()=>{let{query:r,variables:s}=a.dataset(e);return (await this.connection.execute(r,s)).dataset??null})}async getSchema(e){return (typeof e=="string"?await this.withCache(this.cacheKey("datasets","getSchema",{id:e}),"datasets",{},async()=>{let{query:r,variables:s}=a.dataset({id:e});return (await this.connection.execute(r,s)).dataset??null}):await this.getByKey(e))?.schema??null}async search(e={}){let t=this.config.resolvePublisher(e.publisherSlug),r=this.config.resolveGame(e.gameKey);t&&this.validateAccess(t,r);let{query:s,variables:i}=a.searchDatasets({publisherSlug:t,gameKey:r,search:e.search,purpose:e.purpose,first:e.first,after:e.after}),n=this.cacheKey("datasets","search",i),c=await this.withCache(n,"datasets",e,async()=>(await this.connection.execute(s,i)).searchDatasets);return new d(c,{nextPageLoader:async o=>this.search({...e,after:o})})}async get(e,t,r,s){if(typeof t=="string"&&typeof r=="string"){let i=e,n=t,c=s??{};this.validateAccess(i,n);let o=this.cacheKey("datasets","getByKeys",{publisherSlug:i,gameKey:n,datasetKey:r});return this.withCache(o,"datasets",c,async()=>{let{query:h}=a.fetchDatasetByKeys();return (await this.connection.execute(h,{publisherSlug:i,gameKey:n,datasetKey:r})).fetchDataset??null})}else {let i=e,n=t??{},c=this.cacheKey("datasets","get",{id:i});return this.withCache(c,"datasets",n,async()=>{let{query:o}=a.fetchDatasetById();return (await this.connection.execute(o,{id:i})).fetchDataset??null})}}async getMany(e,t={}){if(e.length===0)return [];let r=this.cacheKey("datasets","getMany",{ids:e});return this.withCache(r,"datasets",t,async()=>{let{query:s}=a.fetchDatasets();return (await this.connection.execute(s,{ids:e})).fetchDatasets??[]})}},ct=class extends m{constructor(e,t){super(e,t);}async fetch(e,t={}){let r=this.cacheKey("decks","fetch",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.fetchDeckById();return (await this.connection.execute(s,{id:e})).fetchDeck??null})}async get(e,t={}){let r=this.cacheKey("decks","get",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckById();return (await this.connection.execute(s,{id:e})).deck??null})}async fetchMine(e,t={}){let r=this.cacheKey("decks","fetchMine",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.myDeck();return (await this.connection.execute(s,{id:e})).myDeck??null})}async fetchBySlug(e,t,r,s={}){let i=this.cacheKey("decks","fetchBySlug",{publisherSlug:e,gameKey:t,slug:r});return this.withCache(i,"decks",s,async()=>{let{query:n}=a.fetchDeckBySlug();return (await this.connection.execute(n,{publisherSlug:e,gameKey:t,slug:r})).fetchDeckBySlug??null})}async getBySlug(e,t,r,s={}){let i=this.cacheKey("decks","getBySlug",{publisherSlug:e,gameKey:t,slug:r});return this.withCache(i,"decks",s,async()=>{let{query:n}=a.deckBySlug();return (await this.connection.execute(n,{publisherSlug:e,gameKey:t,slug:r})).deckBySlug??null})}async fetchByExternalRef(e,t={}){let r=this.cacheKey("decks","fetchByExternalRef",{externalRef:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.fetchDeckByExternalRef();return (await this.connection.execute(s,{externalRef:e})).fetchDeckByExternalRef??null})}async getByExternalRef(e,t={}){let r=this.cacheKey("decks","getByExternalRef",{externalRef:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckByExternalRef();return (await this.connection.execute(s,{externalRef:e})).deckByExternalRef??null})}async listMine(e={}){let{query:t,variables:r}=a.listMyDecks({first:e.first,after:e.after,includeArchived:e.includeArchived}),s=this.cacheKey("decks","listMine",r),i=await this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).myDecks);return new d(i,{nextPageLoader:async n=>this.listMine({...e,after:n})})}async listViewer(e={}){let{query:t,variables:r}=a.viewerDecks({filter:e.filter,first:e.first,after:e.after}),s=this.cacheKey("decks","listViewer",r),i=await this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).viewerDecks);return new d(i,{nextPageLoader:async n=>this.listViewer({...e,after:n})})}async listApp(e={}){this.config.requireSecretCredential("decks.listApp");let{query:t,variables:r}=a.appDecks({filter:e.filter,first:e.first,after:e.after}),s=this.cacheKey("decks","listApp",r),i=await this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).appDecks);return new d(i,{nextPageLoader:async n=>this.listApp({...e,after:n})})}async listPublic(e={}){let{query:t,variables:r}=a.publicDecks({filter:e.filter,first:e.first,after:e.after}),s=this.cacheKey("decks","listPublic",r),i=await this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).publicDecks);return new d(i,{nextPageLoader:async n=>this.listPublic({...e,after:n})})}async fetchVersion(e,t={}){let r=this.cacheKey("decks","fetchVersion",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckVersion();return (await this.connection.execute(s,{id:e})).deckVersion??null})}async listVersions(e,t={}){let{query:r,variables:s}=a.deckVersions({first:t.first,after:t.after}),i={deckId:e,...s},n=this.cacheKey("decks","listVersions",i),c=await this.withCache(n,"decks",t,async()=>(await this.connection.execute(r,i)).deckVersions);return new d(c,{nextPageLoader:async o=>this.listVersions(e,{...t,after:o})})}async preview(e,t={}){let r=this.cacheKey("decks","preview",{token:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckPreview();return (await this.connection.execute(s,{token:e})).deckPreview??null})}async embed(e,t={}){let r=this.cacheKey("decks","embed",{token:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckEmbed();return (await this.connection.execute(s,{token:e})).deckEmbed??null})}async access(e,t={}){let r=this.cacheKey("decks","access",{token:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckAccess();return (await this.connection.execute(s,{token:e})).deckAccess??null})}async draftDiff(e,t={}){let r=this.cacheKey("decks","draftDiff",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckDraftDiff();return (await this.connection.execute(s,{id:e})).deckDraftDiff})}async versionDiff(e,t,r={}){let s=a.deckVersionDiffVariables(e,t),i=this.cacheKey("decks","versionDiff",s);return this.withCache(i,"decks",r,async()=>{let{query:n}=a.deckVersionDiff();return (await this.connection.execute(n,s)).deckVersionDiff})}async validate(e,t,r={}){let s=a.deckValidateVariables(e,t),i=this.cacheKey("decks","validate",s);return this.withCache(i,"decks",r,async()=>{let{query:n}=a.deckValidate();return (await this.connection.execute(n,s)).deckValidate})}async hydrateDeckEntries(e,t={}){let r=a.deckHydrateEntriesVariables(e),s=this.cacheKey("decks","hydrateDeckEntries",r);return this.withCache(s,"decks",t,async()=>{let{query:i}=a.deckHydrateEntries();return (await this.connection.execute(i,r)).deckHydrateEntries})}async exportDeck(e,t="SIMPLE_TEXT",r={}){let s=a.deckExportVariables(e,t),i=this.cacheKey("decks","exportDeck",s);return this.withCache(i,"decks",r,async()=>{let{query:n}=a.deckExport();return (await this.connection.execute(n,s)).deckExport})}async sectionDefinitions(e={}){let{query:t,variables:r}=a.deckSectionDefinitions({publisherSlug:e.publisherSlug,gameKey:e.gameKey,gameId:e.gameId,rulesetKey:e.rulesetKey,rulesetVersionId:e.rulesetVersionId}),s=this.cacheKey("decks","sectionDefinitions",r);return this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).deckSectionDefinitions)}async listCollaborators(e,t={}){let r=this.cacheKey("decks","listCollaborators",{deckId:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckCollaborators();return (await this.connection.execute(s,{deckId:e})).deckCollaborators})}async listPreviewTokens(e,t={}){let r=this.cacheKey("decks","listPreviewTokens",{deckId:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckPreviewTokens();return (await this.connection.execute(s,{deckId:e})).deckPreviewTokens})}async listEmbedTokens(e,t={}){let r=this.cacheKey("decks","listEmbedTokens",{deckId:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckEmbedTokens();return (await this.connection.execute(s,{deckId:e})).deckEmbedTokens})}async listAccessTokenIssuers(e,t={}){let r=this.cacheKey("decks","listAccessTokenIssuers",{deckId:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckAccessTokenIssuers();return (await this.connection.execute(s,{deckId:e})).deckAccessTokenIssuers})}async listApiApplicationAccesses(e,t={}){let r=a.deckApiApplicationAccessesVariables(e,t.includeRevoked),s=this.cacheKey("decks","listApiApplicationAccesses",r);return this.withCache(s,"decks",t,async()=>{let{query:i}=a.deckApiApplicationAccesses();return (await this.connection.execute(i,r)).deckApiApplicationAccesses})}async listMyApiApplicationAccesses(e={}){let t=a.myDeckApiApplicationAccessesVariables(e.applicationId),r=this.cacheKey("decks","listMyApiApplicationAccesses",t);return this.withCache(r,"decks",e,async()=>{let{query:s}=a.myDeckApiApplicationAccesses();return (await this.connection.execute(s,t)).myDeckApiApplicationAccesses})}async create(e){let{query:t}=a.createDeck(),r=a.deckCreateVariables(e);return (await this.connection.execute(t,r)).deckCreate}async update(e,t){let{query:r}=a.updateDeck(),s=a.deckUpdateVariables(e,t);return (await this.connection.execute(r,s)).deckUpdate}async updateMetadata(e,t){return this.update(e,t)}async upsertByExternalRef(e){this.config.requireSecretCredential("decks.upsertByExternalRef");let{query:t}=a.upsertDeckByExternalRef(),r=a.deckUpsertByExternalRefVariables(e);return (await this.connection.execute(t,r)).deckUpsertByExternalRef}async claim(e,t){let{query:r}=a.claimDeck(),s=a.deckClaimVariables(e,t);return (await this.connection.execute(r,s)).deckClaim}async transferOwnership(e,t){let{query:r}=a.transferDeckOwnership(),s=a.deckTransferOwnershipVariables(e,t);return (await this.connection.execute(r,s)).deckTransferOwnership}async copy(e,t){let{query:r}=a.copyDeck(),s=a.deckCopyVariables(e,t);return (await this.connection.execute(r,s)).deckCopy}async addEntry(e){let{query:t}=a.addDeckEntry(),r=a.deckEntryAddVariables(e);return (await this.connection.execute(t,r)).deckEntryAdd}async updateEntry(e,t){let{query:r}=a.updateDeckEntry(),s=a.deckEntryUpdateVariables(e,t);return (await this.connection.execute(r,s)).deckEntryUpdate}async removeEntry(e,t){let{query:r}=a.removeDeckEntry(),s=a.deckEntryRemoveVariables(e,t);return (await this.connection.execute(r,s)).deckEntryRemove}async reorderEntries(e,t){let{query:r}=a.reorderDeckEntries(),s=a.deckEntryReorderVariables(e,t);return (await this.connection.execute(r,s)).deckEntryReorder}async replaceEntries(e,t){let{query:r}=a.replaceDeckEntries(),s=a.deckEntriesReplaceVariables(e,t);return (await this.connection.execute(r,s)).deckEntriesReplace}async importDeck(e){let{query:t}=a.importDeck(),r=a.deckImportVariables(e);return (await this.connection.execute(t,r)).deckImport}async listImportFormats(e,t={}){let{query:r,variables:s}=a.deckImportFormats({gameId:e,includeArchived:t.includeArchived,first:t.first,after:t.after}),i=this.cacheKey("decks","listImportFormats",s),n=await this.withCache(i,"decks",t,async()=>(await this.connection.execute(r,s)).deckImportFormats);return new d(n,{nextPageLoader:async c=>this.listImportFormats(e,{...t,after:c})})}async fetchImportFormat(e,t={}){let r=this.cacheKey("decks","fetchImportFormat",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckImportFormat();return (await this.connection.execute(s,{id:e})).deckImportFormat??null})}async testImportFormat(e){let{query:t}=a.deckImportFormatTest(),r=a.deckImportFormatTestVariables(e);return (await this.connection.execute(t,r)).deckImportFormatTest}async createImportFormat(e){let{query:t}=a.createDeckImportFormat(),r=a.deckImportFormatCreateVariables(e);return (await this.connection.execute(t,r)).deckImportFormatCreate}async updateImportFormat(e,t){let{query:r}=a.updateDeckImportFormat(),s=a.deckImportFormatUpdateVariables(e,t);return (await this.connection.execute(r,s)).deckImportFormatUpdate}async archiveImportFormat(e){let{query:t}=a.archiveDeckImportFormat();return (await this.connection.execute(t,{id:e})).deckImportFormatArchive}async unarchiveImportFormat(e){let{query:t}=a.unarchiveDeckImportFormat();return (await this.connection.execute(t,{id:e})).deckImportFormatUnarchive}async delete(e){let{query:t}=a.deleteDeck();return !!(await this.connection.execute(t,{id:e})).deckDelete}async archive(e){let{query:t}=a.archiveDeck();return (await this.connection.execute(t,{id:e})).deckArchive}async restore(e){let{query:t}=a.restoreDeck();return (await this.connection.execute(t,{id:e})).deckRestore}async unpublish(e){let{query:t}=a.unpublishDeck();return (await this.connection.execute(t,{id:e})).deckUnpublish}async publish(e,t){let{query:r}=a.publishDeck(),s=a.deckPublishVariables(e,t);return (await this.connection.execute(r,s)).deckPublish}async removeInvalidEntries(e,t){let{query:r}=a.removeInvalidDeckEntries(),s=a.deckRemoveInvalidEntriesVariables(e,t);return (await this.connection.execute(r,s)).deckRemoveInvalidEntries}async upsertCollaborator(e,t,r){let{query:s}=a.upsertDeckCollaborator(),i=a.deckCollaboratorVariables(e,t,r);return (await this.connection.execute(s,i)).deckCollaboratorUpsert}async removeCollaborator(e,t){let{query:r}=a.removeDeckCollaborator(),s=a.deckCollaboratorVariables(e,t);return !!(await this.connection.execute(r,s)).deckCollaboratorRemove}async createPreviewToken(e){let{query:t}=a.createDeckPreviewToken(),r=a.deckPreviewTokenCreateVariables(e);return (await this.connection.execute(t,r)).deckPreviewTokenCreate}async revokePreviewToken(e){let{query:t}=a.revokeDeckPreviewToken();return !!(await this.connection.execute(t,{id:e})).deckPreviewTokenRevoke}async createEmbedToken(e){let{query:t}=a.createDeckEmbedToken(),r=a.deckEmbedTokenCreateVariables(e);return (await this.connection.execute(t,r)).deckEmbedTokenCreate}async revokeEmbedToken(e){let{query:t}=a.revokeDeckEmbedToken();return !!(await this.connection.execute(t,{id:e})).deckEmbedTokenRevoke}async createAccessTokenIssuer(e){let{query:t}=a.createDeckAccessTokenIssuer(),r=a.deckAccessTokenIssuerCreateVariables(e);return (await this.connection.execute(t,r)).deckAccessTokenIssuerCreate}async revokeAccessTokenIssuer(e){let{query:t}=a.revokeDeckAccessTokenIssuer();return !!(await this.connection.execute(t,{id:e})).deckAccessTokenIssuerRevoke}async revokeAccessTokenIssuerSigningKey(e){let{query:t}=a.revokeDeckAccessTokenIssuerSigningKey();return (await this.connection.execute(t,{id:e})).deckAccessTokenIssuerSigningKeyRevoke}async grantApiApplicationAccess(e){let{query:t}=a.grantDeckApiApplicationAccess(),r=a.deckApiApplicationAccessGrantVariables(e);return (await this.connection.execute(t,r)).deckApiApplicationAccessGrant}async revokeApiApplicationAccess(e,t){let{query:r}=a.revokeDeckApiApplicationAccess(),s=a.deckApiApplicationAccessRevokeVariables(e,t);return !!(await this.connection.execute(r,s)).deckApiApplicationAccessRevoke}async exchangeAccessToken(e){this.config.requireSecretCredential("decks.exchangeAccessToken");let{query:t}=a.exchangeDeckAccessToken(),r=a.deckAccessTokenExchangeVariables(e);return (await this.connection.execute(t,r)).deckAccessTokenExchange}async revokeAccessToken(e){this.config.requireSecretCredential("decks.revokeAccessToken");let{query:t}=a.revokeDeckAccessToken();return !!(await this.connection.execute(t,{id:e})).deckAccessTokenRevoke}async hydrateEntries(e){if(e.entries.length===0)return [];let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let s=e.entries.map(o=>o.identifier),i=this.cacheKey("decks","hydrateEntries",{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifiers:s}),n=await this.withCache(i,"decks",e,async()=>{let{query:o}=a.fetchRecordsByIdentifier();return (await this.connection.execute(o,{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifiers:s})).fetchRecordsByIdentifier}),c=ot(n,s,e.identifierField);return e.entries.map(o=>({...o,record:c.get(o.identifier)??null}))}};function ot(e,t,r){let s=new Set(t),i=new Map;for(let n of e){let c=r?n.data[r]:Object.values(n.data).find(h=>s.has(String(h)));if(c==null)continue;let o=String(c);s.has(o)&&(i.set(o,n),s.delete(o));}return i}var ut=class extends m{constructor(e,t){super(e,t);}async list(e){let t=C(e.filter),{query:r,variables:s}=a.listDatasetRecords({datasetId:e.datasetId,filter:t,orderBy:e.orderBy,first:e.first,after:e.after,last:e.last,before:e.before,validateSchema:e.validateSchema}),i=this.cacheKey("records","list",s),n=await this.withCache(i,"records",e,async()=>(await this.connection.execute(r,s)).datasetRecords);return new d(n,{nextPageLoader:async c=>this.list({...e,after:c})})}async getByDatasetIdentifier(e){let t=this.cacheKey("records","getByDatasetIdentifier",{datasetId:e.datasetId,identifier:e.identifier,includePricing:e.includePricing??false});return this.withCache(t,"records",e,async()=>{let{query:r,variables:s}=a.datasetRecord({datasetId:e.datasetId,identifier:e.identifier,includePricing:e.includePricing});return (await this.connection.execute(r,s)).datasetRecord??null})}async upsertBatch(e){this.config.requireSecretCredential("records.upsertBatch");let{query:t}=a.upsertDatasetRecords();return (await this.connection.execute(t,a.datasetRecordsUpsertVariables(e))).datasetRecordsUpsert}async deleteBatch(e){this.config.requireSecretCredential("records.deleteBatch");let{query:t}=a.deleteDatasetRecords();return (await this.connection.execute(t,a.datasetRecordsDeleteVariables(e))).datasetRecordsDelete}async getDeleteJob(e,t={}){let r=this.cacheKey("records","getDeleteJob",{id:e});return this.withCache(r,"records",t,async()=>{let{query:s}=a.datasetRecordDeleteJob();return (await this.connection.execute(s,{id:e})).datasetRecordDeleteJob??null})}async listDeleteJobs(e,t={}){let{query:r,variables:s}=a.datasetRecordDeleteJobs({publisherId:e,datasetId:t.datasetId,status:t.status,first:t.first,after:t.after}),i=this.cacheKey("records","listDeleteJobs",s),n=await this.withCache(i,"records",t,async()=>(await this.connection.execute(r,s)).datasetRecordDeleteJobs);return new d(n,{nextPageLoader:async c=>this.listDeleteJobs(e,{...t,after:c})})}async waitForDeleteJob(e,t={}){let r=t.intervalMs??1e3,s=t.timeoutMs??3e5,i=Date.now();for(;;){let n=await this.getDeleteJob(e,{cache:false});if(!n)throw new Error(`Delete job '${e}' was not found`);if(n.status==="COMPLETED"||n.status==="FAILED")return n;if(Date.now()-i>=s)throw new Error(`Timed out waiting for delete job '${e}'`);await new Promise(c=>setTimeout(c,r));}}async search(e){let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let s=C(e.filter),{query:i,variables:n}=a.searchRecords({publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,filter:s,search:e.search,orderBy:e.orderBy,resolveLinks:e.resolveLinks,first:e.first,after:e.after,validateSchema:e.validateSchema,includePricing:e.includePricing}),c=this.cacheKey("records","search",{...n,includePricing:e.includePricing??false}),o=await this.withCache(c,"records",e,async()=>(await this.connection.execute(i,n)).searchRecords);return new d(o,{nextPageLoader:async h=>this.search({...e,after:h})})}async get(e,t={}){let r=this.cacheKey("records","get",{id:e,includePricing:t.includePricing??false});return this.withCache(r,"records",t,async()=>{let{query:s}=a.fetchRecordById({includePricing:t.includePricing});return (await this.connection.execute(s,{id:e})).fetchRecord??null})}async getByIdentifier(e){let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let s=this.cacheKey("records","getByIdentifier",{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifier:e.identifier,includePricing:e.includePricing??false});return this.withCache(s,"records",e,async()=>{let{query:i}=a.fetchRecordByIdentifier({includePricing:e.includePricing});return (await this.connection.execute(i,{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifier:e.identifier})).fetchRecordByIdentifier??null})}async getManyByIdentifier(e){if(e.identifiers.length===0)return [];let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let s=this.cacheKey("records","getManyByIdentifier",{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifiers:e.identifiers,includePricing:e.includePricing??false});return this.withCache(s,"records",e,async()=>{let{query:i}=a.fetchRecordsByIdentifier({includePricing:e.includePricing});return (await this.connection.execute(i,{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifiers:e.identifiers})).fetchRecordsByIdentifier??[]})}async getMany(e,t={}){if(e.length===0)return [];let r=this.cacheKey("records","getMany",{ids:e,includePricing:t.includePricing??false});return this.withCache(r,"records",t,async()=>{let{query:s}=a.fetchRecords({includePricing:t.includePricing});return (await this.connection.execute(s,{ids:e})).fetchRecords??[]})}},dt=class extends m{constructor(e,t){super(e,t);}async datasets(e={}){let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let{query:s,variables:i}=a.searchDatasets({publisherSlug:t,gameKey:r,search:e.search,purpose:"RULES",first:e.first,after:e.after}),n=this.cacheKey("rules","datasets",i),c=await this.withCache(n,"datasets",e,async()=>(await this.connection.execute(s,i)).searchDatasets);return new d(c,{nextPageLoader:async o=>this.datasets({...e,after:o})})}async list(e={}){return this.searchRuleRecords("rules",e)}async formats(e={}){return this.searchRuleRecords(e.datasetKey??"formats",e)}async searchRuleRecords(e,t){let r=this.resolvePublisher(t.publisherSlug),s=this.resolveGame(t.gameKey),i=t.datasetKey??e;this.validateAccess(r,s);let n=C(t.filter),{query:c,variables:o}=a.searchRecords({publisherSlug:r,gameKey:s,datasetKey:i,filter:n,search:t.search,orderBy:t.orderBy,resolveLinks:t.resolveLinks,first:t.first,after:t.after,validateSchema:t.validateSchema}),h=this.cacheKey("rules","records",o),H=await this.withCache(h,"records",t,async()=>(await this.connection.execute(c,o)).searchRecords);return new d(H,{nextPageLoader:async X=>this.searchRuleRecords(e,{...t,after:X})})}},lt=class extends m{constructor(e,t){super(e,t);}async list(e){let{query:t,variables:r}=a.deckImportFormats({publisherId:e.publisherId,gameId:e.gameId,includeArchived:e.includeArchived,first:e.first,after:e.after}),s=this.cacheKey("importFormats","list",r),i=await this.withCache(s,"importFormats",e,async()=>(await this.connection.execute(t,r)).deckImportFormats);return new d(i,{nextPageLoader:async n=>this.list({...e,after:n})})}async get(e,t={}){let r=this.cacheKey("importFormats","get",{id:e});return this.withCache(r,"importFormats",t,async()=>{let{query:s}=a.deckImportFormat();return (await this.connection.execute(s,{id:e})).deckImportFormat??null})}async getByKey(e){let t=this.cacheKey("importFormats","getByKey",{gameId:e.gameId,formatKey:e.key});return this.withCache(t,"importFormats",e,async()=>{let{query:r}=a.deckImportFormat();return (await this.connection.execute(r,{gameId:e.gameId,key:e.key})).deckImportFormat??null})}async test(e){let{query:t}=a.deckImportFormatTest();return (await this.connection.execute(t,a.deckImportFormatTestVariables(e))).deckImportFormatTest}async create(e){this.config.requireSecretCredential("importFormats.create");let{query:t}=a.createDeckImportFormat();return (await this.connection.execute(t,a.deckImportFormatCreateVariables(e))).deckImportFormatCreate}async update(e,t){this.config.requireSecretCredential("importFormats.update");let{query:r}=a.updateDeckImportFormat();return (await this.connection.execute(r,a.deckImportFormatUpdateVariables(e,t))).deckImportFormatUpdate}async archive(e){this.config.requireSecretCredential("importFormats.archive");let{query:t}=a.archiveDeckImportFormat();return (await this.connection.execute(t,{id:e})).deckImportFormatArchive}async unarchive(e){this.config.requireSecretCredential("importFormats.unarchive");let{query:t}=a.unarchiveDeckImportFormat();return (await this.connection.execute(t,{id:e})).deckImportFormatUnarchive}},ht=class extends m{constructor(e,t){super(e,t);}async preview(e){let{query:t}=a.datasetImportPreview();return (await this.connection.execute(t,a.datasetImportPreviewVariables(e))).datasetImportPreview}async validate(e){let{query:t}=a.datasetImportValidate();return (await this.connection.execute(t,a.datasetImportValidateVariables(e))).datasetImportValidate}async run(e){if(this.config.requireSecretCredential("imports.run"),"fileId"in e&&e.fileId){let{query:s}=a.datasetImportFromFile();return (await this.connection.execute(s,a.datasetImportFromFileVariables(e))).datasetImportFromFile}if("sourceUrl"in e&&e.sourceUrl){let{query:s}=a.datasetImportFromUrl();return (await this.connection.execute(s,a.datasetImportFromUrlVariables(e))).datasetImportFromUrl}let{query:t}=a.datasetImportFromPayload();return (await this.connection.execute(t,a.datasetImportFromPayloadVariables(e))).datasetImportFromPayload}async getJob(e,t={}){let r=this.cacheKey("imports","getJob",{id:e});return this.withCache(r,"imports",t,async()=>{let{query:s}=a.importJob();return (await this.connection.execute(s,{id:e})).importJob??null})}async listJobs(e,t={}){let{query:r,variables:s}=a.importJobs({publisherId:e,datasetId:t.datasetId,status:t.status,first:t.first,after:t.after}),i=this.cacheKey("imports","listJobs",s),n=await this.withCache(i,"imports",t,async()=>(await this.connection.execute(r,s)).importJobs);return new d(n,{nextPageLoader:async c=>this.listJobs(e,{...t,after:c})})}async cancelJob(e){this.config.requireSecretCredential("imports.cancelJob");let{query:t}=a.importJobCancel();return (await this.connection.execute(t,{id:e})).importJobCancel}async listJobLogs(e,t={}){let{query:r,variables:s}=a.importJobLogs({importJobId:e,level:t.level,datasetKey:t.datasetKey,first:t.first,after:t.after}),i=this.cacheKey("imports","listJobLogs",s),n=await this.withCache(i,"imports",t,async()=>(await this.connection.execute(r,s)).importJob?.logs??yt());return new d(n,{nextPageLoader:async c=>this.listJobLogs(e,{...t,after:c})})}async waitForJob(e,t={}){let r=t.intervalMs??1e3,s=t.timeoutMs??3e5,i=Date.now();for(;;){let n=await this.getJob(e,{cache:false});if(!n)throw new Error(`Import job '${e}' was not found`);if(n.status==="COMPLETED"||n.status==="FAILED")return n;if(Date.now()-i>=s)throw new Error(`Timed out waiting for import job '${e}'`);await new Promise(c=>setTimeout(c,r));}}async previewGame(e){let{query:t}=a.gameImportPreview();return (await this.connection.execute(t,a.gameImportPreviewVariables(e))).gameImportPreview}async runGame(e){if(this.config.requireSecretCredential("imports.runGame"),"fileId"in e&&e.fileId){let{query:s}=a.gameImportFromFile();return (await this.connection.execute(s,a.gameImportFromFileVariables(e))).gameImportFromFile}if("sourceUrl"in e&&e.sourceUrl){let{query:s}=a.gameImportFromUrl();return (await this.connection.execute(s,a.gameImportFromUrlVariables(e))).gameImportFromUrl}let{query:t}=a.gameImportFromPayload();return (await this.connection.execute(t,a.gameImportFromPayloadVariables(e))).gameImportFromPayload}async getGameJob(e,t={}){let r=this.cacheKey("imports","getGameJob",{id:e});return this.withCache(r,"imports",t,async()=>{let{query:s}=a.gameImportJob();return (await this.connection.execute(s,{id:e})).gameImportJob??null})}async listGameJobs(e,t={}){let{query:r,variables:s}=a.gameImportJobs({gameId:e,status:t.status,first:t.first,after:t.after}),i=this.cacheKey("imports","listGameJobs",s),n=await this.withCache(i,"imports",t,async()=>(await this.connection.execute(r,s)).gameImportJobs);return new d(n,{nextPageLoader:async c=>this.listGameJobs(e,{...t,after:c})})}async cancelGameJob(e){this.config.requireSecretCredential("imports.cancelGameJob");let{query:t}=a.gameImportJobCancel();return (await this.connection.execute(t,{id:e})).gameImportJobCancel}async waitForGameJob(e,t={}){let r=t.intervalMs??1e3,s=t.timeoutMs??3e5,i=Date.now();for(;;){let n=await this.getGameJob(e,{cache:false});if(!n)throw new Error(`Game import job '${e}' was not found`);if(n.status==="COMPLETED"||n.status==="FAILED")return n;if(Date.now()-i>=s)throw new Error(`Timed out waiting for game import job '${e}'`);await new Promise(c=>setTimeout(c,r));}}};function yt(){return {totalCount:0,pageInfo:{hasNextPage:false,hasPreviousPage:false,startCursor:null,endCursor:null},edges:[]}}var ft=class extends m{constructor(e,t){super(e,t);}async run(e){this.config.requireSecretCredential("exports.run");let{query:t}=a.datasetExport();return (await this.connection.execute(t,a.datasetExportVariables(e))).datasetExport}async create(e){return this.run(e)}async getJob(e,t={}){let r=this.cacheKey("exports","getJob",{id:e});return this.withCache(r,"exports",t,async()=>{let{query:s}=a.exportJob();return (await this.connection.execute(s,{id:e})).exportJob??null})}async listJobs(e,t={}){let{query:r,variables:s}=a.exportJobs({publisherId:e,gameId:t.gameId,datasetId:t.datasetId,status:t.status,first:t.first,after:t.after}),i=this.cacheKey("exports","listJobs",s),n=await this.withCache(i,"exports",t,async()=>(await this.connection.execute(r,s)).exportJobs);return new d(n,{nextPageLoader:async c=>this.listJobs(e,{...t,after:c})})}async refreshUrl(e){let{query:t}=a.exportJobRefreshUrl();return (await this.connection.execute(t,{id:e})).exportJobRefreshUrl}async cancel(e){this.config.requireSecretCredential("exports.cancel");let{query:t}=a.exportJobCancel();return (await this.connection.execute(t,{id:e})).exportJobCancel}async waitForJob(e,t={}){let r=t.intervalMs??1e3,s=t.timeoutMs??3e5,i=Date.now();for(;;){let n=await this.getJob(e,{cache:false});if(!n)throw new Error(`Export job '${e}' was not found`);if(n.status==="COMPLETED"||n.status==="FAILED")return n;if(Date.now()-i>=s)throw new Error(`Timed out waiting for export job '${e}'`);await new Promise(c=>setTimeout(c,r));}}},pt=class extends m{constructor(e,t){super(e,t);}async get(e,t={}){let r=this.cacheKey("files","get",{id:e});return this.withCache(r,"files",t,async()=>{let{query:s}=a.file();return (await this.connection.execute(s,{id:e})).file??null})}async requestUpload(e){this.config.requireSecretCredential("files.requestUpload");let{query:t}=a.fileUploadRequest();return (await this.connection.execute(t,a.fileUploadRequestVariables(e))).fileUploadRequest}async confirmUpload(e){this.config.requireSecretCredential("files.confirmUpload");let{query:t}=a.fileUploadConfirm();return (await this.connection.execute(t,{id:e})).fileUploadConfirm}async delete(e){this.config.requireSecretCredential("files.delete");let{query:t}=a.fileDelete();return !!(await this.connection.execute(t,{id:e})).fileDelete}},ke=class Ie{config;connection;publishers;games;datasets;records;decks;rules;importFormats;imports;exports;files;constructor(t={}){this.config=new Xe(t),this.connection=new et(this.config),this.publishers=new it(this.connection,this.config),this.games=new at(this.connection,this.config),this.datasets=new nt(this.connection,this.config),this.records=new ut(this.connection,this.config),this.decks=new ct(this.connection,this.config),this.rules=new dt(this.connection,this.config),this.importFormats=new lt(this.connection,this.config),this.imports=new ht(this.connection,this.config),this.exports=new ft(this.connection,this.config),this.files=new pt(this.connection,this.config);}async me(){let{query:t}=a.fetchMe();return (await this.connection.execute(t)).fetchMe??null}getRateLimitInfo(){return Ze()}withConfig(t){let r=this.config.merge(t);return new Ie({apiKey:r.configApiKey(),publishableKey:r.publishableKey,secretKey:r.secretKey,accessToken:r.accessToken,environment:r.environment,endpoint:r.endpoint,timeout:r.timeout,openTimeout:r.openTimeout,defaultPublisher:r.defaultPublisher,defaultGame:r.defaultGame,allowedPublishers:r.allowedPublishers,allowedGames:r.allowedGames,logger:r.logger,logLevel:r.logLevel,retryOnRateLimit:r.retryOnRateLimit,maxRetries:r.maxRetries,retryOnNetworkError:r.retryOnNetworkError,maxNetworkRetries:r.maxNetworkRetries,retryBaseDelay:r.retryBaseDelay,retryMaxDelay:r.retryMaxDelay,cache:r.cache,cacheTtl:r.cacheTtl,cacheTtls:r.cacheTtls})}};var Y=class{storage;prefix;constructor(t={}){let r=t.storage??"localStorage";this.storage=r==="sessionStorage"?globalThis.sessionStorage:globalThis.localStorage,this.prefix=t.prefix??"carddb:";}get(t){try{let r=this.storage.getItem(this.prefix+t);if(!r)return null;let s=JSON.parse(r);return s.expiresAt!==null&&Date.now()>s.expiresAt?(this.storage.removeItem(this.prefix+t),null):s.value}catch{return this.storage.removeItem(this.prefix+t),null}}set(t,r,s){try{let i={value:r,expiresAt:s!==void 0?Date.now()+s*1e3:null};this.storage.setItem(this.prefix+t,JSON.stringify(i));}catch(i){console.warn("[CardDB] Failed to write to cache:",i);}}delete(t){this.storage.removeItem(this.prefix+t);}clear(){let t=[];for(let r=0;r<this.storage.length;r++){let s=this.storage.key(r);s&&s.startsWith(this.prefix)&&t.push(s);}for(let r of t)this.storage.removeItem(r);}has(t){return this.get(t)!==null}get size(){let t=0;for(let r=0;r<this.storage.length;r++){let s=this.storage.key(r);s&&s.startsWith(this.prefix)&&t++;}return t}cleanup(){let t=Date.now(),r=[];for(let s=0;s<this.storage.length;s++){let i=this.storage.key(s);if(i&&i.startsWith(this.prefix))try{let n=this.storage.getItem(i);if(n){let c=JSON.parse(n);c.expiresAt!==null&&t>c.expiresAt&&r.push(i);}}catch{r.push(i);}}for(let s of r)this.storage.removeItem(s);}};var $e=class extends ke{constructor(t={}){if("apiKey"in t&&t.apiKey!==void 0)throw new b("apiKey is not accepted in browsers; use publishableKey or accessToken");if("secretKey"in t&&t.secretKey!==void 0)throw new b("secretKey is server-only; use publishableKey or accessToken in browsers");super(t);}};
1653
- export{B as AuthenticationError,m as BaseResource,Y as BrowserCache,$e as CardDBClient,y as CardDBError,d as Collection,Xe as Configuration,et as Connection,E as ConnectionError,Me as DEFAULT_CACHE_TTL,Je as DEFAULT_ENDPOINT,je as DEFAULT_MAX_NETWORK_RETRIES,Ne as DEFAULT_MAX_RETRIES,Ge as DEFAULT_OPEN_TIMEOUT,Ye as DEFAULT_RETRY_BASE_DELAY,He as DEFAULT_RETRY_MAX_DELAY,Oe as DEFAULT_TIMEOUT,nt as DatasetsResource,ct as DecksResource,ft as ExportsResource,pt as FilesResource,be as FilterBuilder,at as GamesResource,se as GraphQLError,lt as ImportFormatsResource,ht as ImportsResource,gt as LinkResolutionError,mt as NotFoundError,it as PublishersResource,a as QueryBuilder,q as RateLimitError,ut as RecordsResource,b as RestrictedError,dt as RulesResource,J as ServerError,V as TimeoutError,_ as ValidationError,tt as cacheKey,Et as contains,kt as eq,Ze as getRateLimitInfo,Mt as getSDKVersion,ze as getUserAgent,$t as gt,bt as gte,xt as ilike,qt as isNotNull,Rt as isNull,St as like,vt as lt,Dt as lte,It as neq,At as notWithin,rt as readCache,C as resolveFilter,wt as within,st as writeCache};//# sourceMappingURL=index.js.map
1672
+ `}}},d=class{totalCount;pageInfo;items;nextPageLoader;constructor(e,t={}){this.totalCount=e.totalCount,this.pageInfo=e.pageInfo,this.items=e.edges.map(r=>t.itemTransformer?t.itemTransformer(r.node):r.node),this.nextPageLoader=t.nextPageLoader;}get hasNextPage(){return this.pageInfo.hasNextPage}get hasPreviousPage(){return this.pageInfo.hasPreviousPage}get endCursor(){return this.pageInfo.endCursor}get startCursor(){return this.pageInfo.startCursor}get length(){return this.items.length}get isEmpty(){return this.items.length===0}get first(){return this.items[0]}get last(){return this.items[this.items.length-1]}async nextPage(){if(!this.hasNextPage)return null;if(!this.nextPageLoader)throw new Error("No next page loader configured");return this.endCursor?this.nextPageLoader(this.endCursor):null}async*[Symbol.asyncIterator](){let e=this;for(;e;){for(let t of e.items)yield t;if(!e.hasNextPage)break;e=await e.nextPage();}}async forEach(e){let t=0;for await(let r of this)await e(r,t++);}async map(e){let t=[],r=0;for await(let s of this)t.push(await e(s,r++));return t}async filter(e){let t=[],r=0;for await(let s of this)await e(s,r++)&&t.push(s);return t}async find(e){let t=0;for await(let r of this)if(await e(r,t++))return r}async take(e){let t=[];for await(let r of this){if(t.length>=e)break;t.push(r);}return t}async toArray(){let e=[];for await(let t of this)e.push(t);return e}async*batches(){let e=this;for(;e&&(e.items.length>0&&(yield e.items),!!e.hasNextPage);)e=await e.nextPage();}each(){return this}};var Je="https://carddb.xtda.org/query",Oe=3e4,Ge=1e4,Me=300,Ne=3,je=2,Ye=1e3,He=3e4,Xe=class pe{apiKey;publishableKey;secretKey;accessToken;legacyApiKey;environment;endpoint;timeout;openTimeout;defaultPublisher;defaultGame;allowedPublishers;allowedGames;logger;logLevel;retryOnRateLimit;maxRetries;retryOnNetworkError;maxNetworkRetries;retryBaseDelay;retryMaxDelay;cache;cacheTtl;cacheTtls;constructor(t={}){this.legacyApiKey=t.apiKey,this.publishableKey=t.publishableKey,this.secretKey=t.secretKey,this.accessToken=t.accessToken,this.apiKey=t.apiKey??t.publishableKey??t.secretKey,this.environment=t.environment,this.endpoint=t.endpoint??Je,this.timeout=t.timeout??Oe,this.openTimeout=t.openTimeout??Ge,this.defaultPublisher=t.defaultPublisher,this.defaultGame=t.defaultGame,this.allowedPublishers=t.allowedPublishers,this.allowedGames=t.allowedGames,this.logger=t.logger,this.logLevel=t.logLevel??"info",this.retryOnRateLimit=t.retryOnRateLimit??false,this.maxRetries=t.maxRetries??Ne,this.retryOnNetworkError=t.retryOnNetworkError??true,this.maxNetworkRetries=t.maxNetworkRetries??je,this.retryBaseDelay=t.retryBaseDelay??Ye,this.retryMaxDelay=t.retryMaxDelay??He,this.cache=t.cache,this.cacheTtl=t.cacheTtl??Me,this.cacheTtls=t.cacheTtls??{};}calculateRetryDelay(t){let r=this.retryBaseDelay*Math.pow(2,t),s=Math.min(r,this.retryMaxDelay),i=s*.25*(Math.random()*2-1);return Math.round(s+i)}cacheTtlFor(t){return this.cacheTtls[t]??this.cacheTtl}resolvePublisher(t){return t??this.defaultPublisher}resolveGame(t){return t??this.defaultGame}validatePublisher(t){if(this.allowedPublishers&&!this.allowedPublishers.includes(t))throw new b(`Publisher '${t}' is not in the allowed publishers list`)}validateGame(t,r){if(!this.allowedGames)return;let s=this.allowedGames[t];if(s&&!s.includes(r))throw new b(`Game '${r}' is not allowed for publisher '${t}'`)}validateAccess(t,r){t&&(this.validatePublisher(t),r&&this.validateGame(t,r));}requireSecretCredential(t){if(!(!this.accessToken&&(this.legacyApiKey||this.secretKey&&!this.publishableKey)))throw new b(`${t} requires a server-side secretKey or legacy apiKey credential`)}requestApiKey(){return this.legacyApiKey??this.publishableKey??this.secretKey}configApiKey(){return this.legacyApiKey}shouldLog(t){let r={debug:0,info:1,warn:2,error:3};return r[t]>=r[this.logLevel]}merge(t){return new pe({apiKey:t.apiKey??this.legacyApiKey,publishableKey:t.publishableKey??this.publishableKey,secretKey:t.secretKey??this.secretKey,accessToken:t.accessToken??this.accessToken,environment:t.environment??this.environment,endpoint:t.endpoint??this.endpoint,timeout:t.timeout??this.timeout,openTimeout:t.openTimeout??this.openTimeout,defaultPublisher:t.defaultPublisher??this.defaultPublisher,defaultGame:t.defaultGame??this.defaultGame,allowedPublishers:t.allowedPublishers??this.allowedPublishers,allowedGames:t.allowedGames??this.allowedGames,logger:t.logger??this.logger,logLevel:t.logLevel??this.logLevel,retryOnRateLimit:t.retryOnRateLimit??this.retryOnRateLimit,maxRetries:t.maxRetries??this.maxRetries,retryOnNetworkError:t.retryOnNetworkError??this.retryOnNetworkError,maxNetworkRetries:t.maxNetworkRetries??this.maxNetworkRetries,retryBaseDelay:t.retryBaseDelay??this.retryBaseDelay,retryMaxDelay:t.retryMaxDelay??this.retryMaxDelay,cache:t.cache??this.cache,cacheTtl:t.cacheTtl??this.cacheTtl,cacheTtls:t.cacheTtls??this.cacheTtls})}},me="0.1.0";function We(){if(typeof globalThis<"u"&&"Bun"in globalThis){let e=globalThis.Bun&&typeof globalThis.Bun=="object"&&globalThis.Bun.version;return {name:"bun",version:typeof e=="string"?e:"unknown"}}if(typeof globalThis<"u"&&"Deno"in globalThis){let e=globalThis.Deno&&typeof globalThis.Deno=="object"&&globalThis.Deno.version&&typeof globalThis.Deno.version=="object"&&globalThis.Deno.version.deno;return {name:"deno",version:typeof e=="string"?e:"unknown"}}return typeof process<"u"&&process.versions&&process.versions.node?{name:"node",version:process.versions.node}:typeof navigator<"u"&&navigator.userAgent?Qe(navigator.userAgent):{name:"unknown",version:"unknown"}}function Qe(e){let t=e.match(/Edg\/(\d+(?:\.\d+)*)/);if(t)return {name:"edge",version:t[1]};let r=e.match(/Chrome\/(\d+(?:\.\d+)*)/);if(r&&!e.includes("Edg/"))return {name:"chrome",version:r[1]};let s=e.match(/Firefox\/(\d+(?:\.\d+)*)/);if(s)return {name:"firefox",version:s[1]};let i=e.match(/Version\/(\d+(?:\.\d+)*).*Safari/);return i?{name:"safari",version:i[1]}:{name:"browser",version:"unknown"}}function ze(){let e=We();return `CardDB-SDK/js/${me} (${e.name}/${e.version})`}function Mt(){return me}var ge=null;function Ze(){return ge}var et=class{config;constructor(e){this.config=e;}async execute(e,t={}){let r=this.extractOperationName(e),s=0,i=0;for(;;)try{let n=Date.now();this.logRequest(r,t);let c=await this.fetch(e,t),o=Date.now()-n,h=await this.handleResponse(c);return this.logResponse(r,o),h}catch(n){if(n instanceof q&&this.config.retryOnRateLimit&&s<this.config.maxRetries){s++;let c=n.retryAfter??60;this.logRateLimitRetry(r,s,c),await this.sleep(c*1e3);continue}if(this.isRetryableNetworkError(n)&&this.config.retryOnNetworkError&&i<this.config.maxNetworkRetries){let c=this.config.calculateRetryDelay(i);this.logNetworkRetry(r,i+1,c,n),i++,await this.sleep(c);continue}if(n instanceof J&&this.config.retryOnNetworkError&&i<this.config.maxNetworkRetries){let c=this.config.calculateRetryDelay(i);this.logNetworkRetry(r,i+1,c,n),i++,await this.sleep(c);continue}throw n}}isRetryableNetworkError(e){return e instanceof E||e instanceof _}async fetch(e,t){let r=new AbortController,s=setTimeout(()=>r.abort(),this.config.timeout),i=this.config.requestApiKey();try{return await fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","User-Agent":ze(),...this.config.accessToken?{Authorization:`Bearer ${this.config.accessToken}`}:{},...!this.config.accessToken&&i?{"X-API-Key":i}:{}},body:JSON.stringify({query:e,variables:t}),signal:r.signal})}catch(n){throw n instanceof Error?n.name==="AbortError"?(this.logError("Request timed out"),new _("Request timed out")):(this.logError(`Connection failed: ${n.message}`),new E(`Connection failed: ${n.message}`)):new E("Connection failed")}finally{clearTimeout(s);}}async handleResponse(e){switch(this.extractRateLimitInfo(e),e.status){case 200:return this.handleSuccessResponse(e);case 401:throw new B("Invalid or missing API key");case 429:return this.handleRateLimitResponse(e);default:if(e.status>=400&&e.status<500)return this.handleClientError(e);if(e.status>=500){let t=await this.parseBody(e);throw new J(`Server error (${e.status})`,{status:e.status,response:t})}throw new y(`Unexpected response status: ${e.status}`)}}async handleSuccessResponse(e){let t=await this.parseBody(e);return t.errors&&t.errors.length>0&&this.handleGraphQLErrors(t.errors,t),t.data??{}}handleGraphQLErrors(e,t){let r=e[0],s=r.message||"GraphQL error";switch(r.extensions?.code){case "UNAUTHENTICATED":throw new B(s,t);case "RATE_LIMITED":throw new q(s,{response:t});case "NOT_FOUND":throw new y(s,t);case "VALIDATION_ERROR":case "BAD_USER_INPUT":throw new V(s,{errors:e,response:t});default:throw new se(s,{errors:e,response:t})}}async handleRateLimitResponse(e){let t=parseInt(e.headers.get("Retry-After")??"60",10),r=parseInt(e.headers.get("X-RateLimit-Limit")??"",10)||null,s=parseInt(e.headers.get("X-RateLimit-Remaining")??"",10)||null,i=parseInt(e.headers.get("X-RateLimit-Reset")??"",10)||null,n=i?new Date(i*1e3):null,c=await this.parseBody(e);throw new q("Rate limit exceeded",{retryAfter:t,limit:r,remaining:s,resetAt:n,response:c})}async handleClientError(e){let t=await this.parseBody(e),r=t.errors?.[0]?.message??`Client error (${e.status})`;throw new V(r,{response:t})}async parseBody(e){try{return await e.json()}catch{return {raw:await e.text()}}}extractRateLimitInfo(e){let t=parseInt(e.headers.get("X-RateLimit-Limit")??"",10)||null,r=parseInt(e.headers.get("X-RateLimit-Remaining")??"",10)||null,s=parseInt(e.headers.get("X-RateLimit-Reset")??"",10)||null;ge={limit:t,remaining:r,reset:s};}extractOperationName(e){let t=e.match(/(?:query|mutation)\s+(\w+)/);return t?t[1]:"Unknown"}sleep(e){return new Promise(t=>setTimeout(t,e))}logRequest(e,t){!this.config.logger||!this.config.shouldLog("debug")||this.config.logger.debug(`[CardDB] Executing ${e}`,{variables:t});}logResponse(e,t){!this.config.logger||!this.config.shouldLog("info")||this.config.logger.info(`[CardDB] ${e} completed in ${t}ms`);}logRateLimitRetry(e,t,r){!this.config.logger||!this.config.shouldLog("warn")||this.config.logger.warn(`[CardDB] Rate limited on ${e}, retry ${t}/${this.config.maxRetries} after ${r}s`);}logNetworkRetry(e,t,r,s){if(!this.config.logger||!this.config.shouldLog("warn"))return;let i=s instanceof Error?s.name:"Unknown";this.config.logger.warn(`[CardDB] ${i} on ${e}, retry ${t}/${this.config.maxNetworkRetries} after ${r}ms`);}logError(e){!this.config.logger||!this.config.shouldLog("error")||this.config.logger.error(`[CardDB] ${e}`);}};function tt(e,t,r){let s=Object.entries(r).filter(([,i])=>i!==void 0).sort(([i],[n])=>i.localeCompare(n)).map(([i,n])=>`${i}=${JSON.stringify(n)}`).join("&");return `carddb:${e}:${t}:${s}`}async function rt(e,t){let r=e.get(t);return r}async function st(e,t,r,s){let i=e.set(t,r,s);i instanceof Promise&&await i;}var m=class{connection;config;constructor(e,t){this.connection=e,this.config=t;}resolvePublisher(e){let t=this.config.resolvePublisher(e);if(!t)throw new Error("publisher_slug is required (no default configured)");return t}resolveGame(e){let t=this.config.resolveGame(e);if(!t)throw new Error("game_key is required (no default configured)");return t}validateAccess(e,t){this.config.validateAccess(e,t);}async withCache(e,t,r,s){let i=r.cache??!!this.config.cache,n=this.config.cache;if(!i||!n)return s();let c=await rt(n,e);if(c!==null)return c;let o=await s();if(o!=null){let h=this.config.cacheTtlFor(t);await st(n,e,o,h);}return o}cacheKey(e,t,r){return tt(e,t,r)}},it=class extends m{constructor(e,t){super(e,t);}async search(e={}){let{query:t,variables:r}=a.searchPublishers({search:e.search,first:e.first,after:e.after}),s=this.cacheKey("publishers","search",r),i=await this.withCache(s,"publishers",e,async()=>(await this.connection.execute(t,r)).searchPublishers);return new d(i,{nextPageLoader:async n=>this.search({...e,after:n})})}async get(e,t={}){let r=this.isUUID(e),s=this.cacheKey("publishers","get",{[r?"id":"slug"]:e});return this.withCache(s,"publishers",t,async()=>{if(r){let{query:i}=a.fetchPublisherById();return (await this.connection.execute(i,{id:e})).fetchPublisher??null}else {let{query:i}=a.fetchPublisherBySlug();return (await this.connection.execute(i,{slug:e})).fetchPublisher??null}})}async getMany(e,t={}){if(e.length===0)return [];let r=this.cacheKey("publishers","getMany",{slugs:e});return this.withCache(r,"publishers",t,async()=>{let{query:s}=a.fetchPublishers();return (await this.connection.execute(s,{slugs:e})).fetchPublishers??[]})}isUUID(e){return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e)}},at=class extends m{constructor(e,t){super(e,t);}async list(e,t={}){let{query:r,variables:s}=a.listGames({publisherId:e,first:t.first,after:t.after,includeArchived:t.includeArchived}),i=this.cacheKey("games","list",s),n=await this.withCache(i,"games",t,async()=>(await this.connection.execute(r,s)).games);return new d(n,{nextPageLoader:async c=>this.list(e,{...t,after:c})})}async getByKey(e){let t=this.cacheKey("games","getByKey",{publisherId:e.publisherId,publisherSlug:e.publisherSlug,gameKey:e.gameKey});return this.withCache(t,"games",e,async()=>{let{query:r,variables:s}=a.game(e);return (await this.connection.execute(r,s)).game??null})}async getBySlug(e){let t=this.cacheKey("games","getBySlug",{publisherId:e.publisherId,publisherSlug:e.publisherSlug,gameSlug:e.gameSlug});return this.withCache(t,"games",e,async()=>{let{query:r,variables:s}=a.game(e);return (await this.connection.execute(r,s)).game??null})}async create(e){this.config.requireSecretCredential("games.create");let{query:t}=a.createGame();return (await this.connection.execute(t,a.gameCreateVariables(e))).gameCreate}async update(e,t){this.config.requireSecretCredential("games.update");let{query:r}=a.updateGame();return (await this.connection.execute(r,a.gameUpdateVariables(e,t))).gameUpdate}async search(e={}){let t=this.config.resolvePublisher(e.publisherSlug);t&&this.validateAccess(t);let{query:r,variables:s}=a.searchGames({publisherSlug:t,search:e.search,first:e.first,after:e.after}),i=this.cacheKey("games","search",s),n=await this.withCache(i,"games",e,async()=>(await this.connection.execute(r,s)).searchGames);return new d(n,{nextPageLoader:async c=>this.search({...e,after:c})})}async get(e,t,r){if(typeof t=="string"){let s=e,i=t,n=r??{};this.validateAccess(s,i);let c=this.cacheKey("games","getByKeys",{publisherSlug:s,gameKey:i});return this.withCache(c,"games",n,async()=>{let{query:o}=a.fetchGameByKeys();return (await this.connection.execute(o,{publisherSlug:s,gameKey:i})).fetchGame??null})}else {let s=e,i=t??{},n=this.cacheKey("games","get",{id:s});return this.withCache(n,"games",i,async()=>{let{query:c}=a.fetchGameById();return (await this.connection.execute(c,{id:s})).fetchGame??null})}}async getMany(e,t={}){if(e.length===0)return [];let r=this.cacheKey("games","getMany",{ids:e});return this.withCache(r,"games",t,async()=>{let{query:s}=a.fetchGames();return (await this.connection.execute(s,{ids:e})).fetchGames??[]})}},nt=class extends m{constructor(e,t){super(e,t);}async list(e,t={}){let{query:r,variables:s}=a.listDatasets({publisherId:e,gameId:t.gameId,includeArchived:t.includeArchived,purpose:t.purpose,first:t.first,after:t.after}),i=this.cacheKey("datasets","list",s),n=await this.withCache(i,"datasets",t,async()=>(await this.connection.execute(r,s)).datasets);return new d(n,{nextPageLoader:async c=>this.list(e,{...t,after:c})})}async getByKey(e){let t=this.cacheKey("datasets","getByKey",{publisherId:e.publisherId,gameId:e.gameId,datasetKey:e.datasetKey});return this.withCache(t,"datasets",e,async()=>{let{query:r,variables:s}=a.dataset(e);return (await this.connection.execute(r,s)).dataset??null})}async getSchema(e){return (typeof e=="string"?await this.withCache(this.cacheKey("datasets","getSchema",{id:e}),"datasets",{},async()=>{let{query:r,variables:s}=a.dataset({id:e});return (await this.connection.execute(r,s)).dataset??null}):await this.getByKey(e))?.schema??null}async search(e={}){let t=this.config.resolvePublisher(e.publisherSlug),r=this.config.resolveGame(e.gameKey);t&&this.validateAccess(t,r);let{query:s,variables:i}=a.searchDatasets({publisherSlug:t,gameKey:r,search:e.search,purpose:e.purpose,first:e.first,after:e.after}),n=this.cacheKey("datasets","search",i),c=await this.withCache(n,"datasets",e,async()=>(await this.connection.execute(s,i)).searchDatasets);return new d(c,{nextPageLoader:async o=>this.search({...e,after:o})})}async get(e,t,r,s){if(typeof t=="string"&&typeof r=="string"){let i=e,n=t,c=s??{};this.validateAccess(i,n);let o=this.cacheKey("datasets","getByKeys",{publisherSlug:i,gameKey:n,datasetKey:r});return this.withCache(o,"datasets",c,async()=>{let{query:h}=a.fetchDatasetByKeys();return (await this.connection.execute(h,{publisherSlug:i,gameKey:n,datasetKey:r})).fetchDataset??null})}else {let i=e,n=t??{},c=this.cacheKey("datasets","get",{id:i});return this.withCache(c,"datasets",n,async()=>{let{query:o}=a.fetchDatasetById();return (await this.connection.execute(o,{id:i})).fetchDataset??null})}}async getMany(e,t={}){if(e.length===0)return [];let r=this.cacheKey("datasets","getMany",{ids:e});return this.withCache(r,"datasets",t,async()=>{let{query:s}=a.fetchDatasets();return (await this.connection.execute(s,{ids:e})).fetchDatasets??[]})}},ct=class extends m{constructor(e,t){super(e,t);}async fetch(e,t={}){let r=this.cacheKey("decks","fetch",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.fetchDeckById();return (await this.connection.execute(s,{id:e})).fetchDeck??null})}async get(e,t={}){let r=this.cacheKey("decks","get",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckById();return (await this.connection.execute(s,{id:e})).deck??null})}async fetchMine(e,t={}){let r=this.cacheKey("decks","fetchMine",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.myDeck();return (await this.connection.execute(s,{id:e})).myDeck??null})}async fetchBySlug(e,t,r,s={}){let i=this.cacheKey("decks","fetchBySlug",{publisherSlug:e,gameKey:t,slug:r});return this.withCache(i,"decks",s,async()=>{let{query:n}=a.fetchDeckBySlug();return (await this.connection.execute(n,{publisherSlug:e,gameKey:t,slug:r})).fetchDeckBySlug??null})}async getBySlug(e,t,r,s={}){let i=this.cacheKey("decks","getBySlug",{publisherSlug:e,gameKey:t,slug:r});return this.withCache(i,"decks",s,async()=>{let{query:n}=a.deckBySlug();return (await this.connection.execute(n,{publisherSlug:e,gameKey:t,slug:r})).deckBySlug??null})}async fetchByExternalRef(e,t={}){let r=this.cacheKey("decks","fetchByExternalRef",{externalRef:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.fetchDeckByExternalRef();return (await this.connection.execute(s,{externalRef:e})).fetchDeckByExternalRef??null})}async getByExternalRef(e,t={}){let r=this.cacheKey("decks","getByExternalRef",{externalRef:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckByExternalRef();return (await this.connection.execute(s,{externalRef:e})).deckByExternalRef??null})}async listMine(e={}){let{query:t,variables:r}=a.listMyDecks({first:e.first,after:e.after,includeArchived:e.includeArchived}),s=this.cacheKey("decks","listMine",r),i=await this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).myDecks);return new d(i,{nextPageLoader:async n=>this.listMine({...e,after:n})})}async listViewer(e={}){let{query:t,variables:r}=a.viewerDecks({filter:e.filter,first:e.first,after:e.after}),s=this.cacheKey("decks","listViewer",r),i=await this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).viewerDecks);return new d(i,{nextPageLoader:async n=>this.listViewer({...e,after:n})})}async listApp(e={}){this.config.requireSecretCredential("decks.listApp");let{query:t,variables:r}=a.appDecks({filter:e.filter,first:e.first,after:e.after}),s=this.cacheKey("decks","listApp",r),i=await this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).appDecks);return new d(i,{nextPageLoader:async n=>this.listApp({...e,after:n})})}async listPublic(e={}){let{query:t,variables:r}=a.publicDecks({filter:e.filter,first:e.first,after:e.after}),s=this.cacheKey("decks","listPublic",r),i=await this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).publicDecks);return new d(i,{nextPageLoader:async n=>this.listPublic({...e,after:n})})}async fetchVersion(e,t={}){let r=this.cacheKey("decks","fetchVersion",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckVersion();return (await this.connection.execute(s,{id:e})).deckVersion??null})}async listVersions(e,t={}){let{query:r,variables:s}=a.deckVersions({first:t.first,after:t.after}),i={deckId:e,...s},n=this.cacheKey("decks","listVersions",i),c=await this.withCache(n,"decks",t,async()=>(await this.connection.execute(r,i)).deckVersions);return new d(c,{nextPageLoader:async o=>this.listVersions(e,{...t,after:o})})}async preview(e,t={}){let r=this.cacheKey("decks","preview",{token:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckPreview();return (await this.connection.execute(s,{token:e})).deckPreview??null})}async embed(e,t={}){let r=this.cacheKey("decks","embed",{token:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckEmbed();return (await this.connection.execute(s,{token:e})).deckEmbed??null})}async access(e,t={}){let r=this.cacheKey("decks","access",{token:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckAccess();return (await this.connection.execute(s,{token:e})).deckAccess??null})}async draftDiff(e,t={}){let r=this.cacheKey("decks","draftDiff",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckDraftDiff();return (await this.connection.execute(s,{id:e})).deckDraftDiff})}async versionDiff(e,t,r={}){let s=a.deckVersionDiffVariables(e,t),i=this.cacheKey("decks","versionDiff",s);return this.withCache(i,"decks",r,async()=>{let{query:n}=a.deckVersionDiff();return (await this.connection.execute(n,s)).deckVersionDiff})}async validate(e,t,r={}){let s=a.deckValidateVariables(e,t),i=this.cacheKey("decks","validate",s);return this.withCache(i,"decks",r,async()=>{let{query:n}=a.deckValidate();return (await this.connection.execute(n,s)).deckValidate})}async hydrateDeckEntries(e,t={}){let r=a.deckHydrateEntriesVariables(e),s=this.cacheKey("decks","hydrateDeckEntries",r);return this.withCache(s,"decks",t,async()=>{let{query:i}=a.deckHydrateEntries();return (await this.connection.execute(i,r)).deckHydrateEntries})}async exportDeck(e,t="SIMPLE_TEXT",r={}){let s=a.deckExportVariables(e,t),i=this.cacheKey("decks","exportDeck",s);return this.withCache(i,"decks",r,async()=>{let{query:n}=a.deckExport();return (await this.connection.execute(n,s)).deckExport})}async sectionDefinitions(e={}){let{query:t,variables:r}=a.deckSectionDefinitions({publisherSlug:e.publisherSlug,gameKey:e.gameKey,gameId:e.gameId,rulesetKey:e.rulesetKey,rulesetVersionId:e.rulesetVersionId}),s=this.cacheKey("decks","sectionDefinitions",r);return this.withCache(s,"decks",e,async()=>(await this.connection.execute(t,r)).deckSectionDefinitions)}async listCollaborators(e,t={}){let r=this.cacheKey("decks","listCollaborators",{deckId:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckCollaborators();return (await this.connection.execute(s,{deckId:e})).deckCollaborators})}async listPreviewTokens(e,t={}){let r=this.cacheKey("decks","listPreviewTokens",{deckId:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckPreviewTokens();return (await this.connection.execute(s,{deckId:e})).deckPreviewTokens})}async listEmbedTokens(e,t={}){let r=this.cacheKey("decks","listEmbedTokens",{deckId:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckEmbedTokens();return (await this.connection.execute(s,{deckId:e})).deckEmbedTokens})}async listAccessTokenIssuers(e,t={}){let r=this.cacheKey("decks","listAccessTokenIssuers",{deckId:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckAccessTokenIssuers();return (await this.connection.execute(s,{deckId:e})).deckAccessTokenIssuers})}async listApiApplicationAccesses(e,t={}){let r=a.deckApiApplicationAccessesVariables(e,t.includeRevoked),s=this.cacheKey("decks","listApiApplicationAccesses",r);return this.withCache(s,"decks",t,async()=>{let{query:i}=a.deckApiApplicationAccesses();return (await this.connection.execute(i,r)).deckApiApplicationAccesses})}async listMyApiApplicationAccesses(e={}){let t=a.myDeckApiApplicationAccessesVariables(e.applicationId),r=this.cacheKey("decks","listMyApiApplicationAccesses",t);return this.withCache(r,"decks",e,async()=>{let{query:s}=a.myDeckApiApplicationAccesses();return (await this.connection.execute(s,t)).myDeckApiApplicationAccesses})}async create(e){let{query:t}=a.createDeck(),r=a.deckCreateVariables(e);return (await this.connection.execute(t,r)).deckCreate}async update(e,t){let{query:r}=a.updateDeck(),s=a.deckUpdateVariables(e,t);return (await this.connection.execute(r,s)).deckUpdate}async updateMetadata(e,t){return this.update(e,t)}async upsertByExternalRef(e){this.config.requireSecretCredential("decks.upsertByExternalRef");let{query:t}=a.upsertDeckByExternalRef(),r=a.deckUpsertByExternalRefVariables(e);return (await this.connection.execute(t,r)).deckUpsertByExternalRef}async claim(e,t){let{query:r}=a.claimDeck(),s=a.deckClaimVariables(e,t);return (await this.connection.execute(r,s)).deckClaim}async transferOwnership(e,t){let{query:r}=a.transferDeckOwnership(),s=a.deckTransferOwnershipVariables(e,t);return (await this.connection.execute(r,s)).deckTransferOwnership}async copy(e,t){let{query:r}=a.copyDeck(),s=a.deckCopyVariables(e,t);return (await this.connection.execute(r,s)).deckCopy}async addEntry(e){let{query:t}=a.addDeckEntry(),r=a.deckEntryAddVariables(e);return (await this.connection.execute(t,r)).deckEntryAdd}async updateEntry(e,t){let{query:r}=a.updateDeckEntry(),s=a.deckEntryUpdateVariables(e,t);return (await this.connection.execute(r,s)).deckEntryUpdate}async removeEntry(e,t){let{query:r}=a.removeDeckEntry(),s=a.deckEntryRemoveVariables(e,t);return (await this.connection.execute(r,s)).deckEntryRemove}async reorderEntries(e,t){let{query:r}=a.reorderDeckEntries(),s=a.deckEntryReorderVariables(e,t);return (await this.connection.execute(r,s)).deckEntryReorder}async replaceEntries(e,t){let{query:r}=a.replaceDeckEntries(),s=a.deckEntriesReplaceVariables(e,t);return (await this.connection.execute(r,s)).deckEntriesReplace}async importDeck(e){let{query:t}=a.importDeck(),r=a.deckImportVariables(e);return (await this.connection.execute(t,r)).deckImport}async listImportFormats(e,t={}){let{query:r,variables:s}=a.deckImportFormats({gameId:e,includeArchived:t.includeArchived,first:t.first,after:t.after}),i=this.cacheKey("decks","listImportFormats",s),n=await this.withCache(i,"decks",t,async()=>(await this.connection.execute(r,s)).deckImportFormats);return new d(n,{nextPageLoader:async c=>this.listImportFormats(e,{...t,after:c})})}async fetchImportFormat(e,t={}){let r=this.cacheKey("decks","fetchImportFormat",{id:e});return this.withCache(r,"decks",t,async()=>{let{query:s}=a.deckImportFormat();return (await this.connection.execute(s,{id:e})).deckImportFormat??null})}async testImportFormat(e){let{query:t}=a.deckImportFormatTest(),r=a.deckImportFormatTestVariables(e);return (await this.connection.execute(t,r)).deckImportFormatTest}async createImportFormat(e){let{query:t}=a.createDeckImportFormat(),r=a.deckImportFormatCreateVariables(e);return (await this.connection.execute(t,r)).deckImportFormatCreate}async updateImportFormat(e,t){let{query:r}=a.updateDeckImportFormat(),s=a.deckImportFormatUpdateVariables(e,t);return (await this.connection.execute(r,s)).deckImportFormatUpdate}async archiveImportFormat(e){let{query:t}=a.archiveDeckImportFormat();return (await this.connection.execute(t,{id:e})).deckImportFormatArchive}async unarchiveImportFormat(e){let{query:t}=a.unarchiveDeckImportFormat();return (await this.connection.execute(t,{id:e})).deckImportFormatUnarchive}async delete(e){let{query:t}=a.deleteDeck();return !!(await this.connection.execute(t,{id:e})).deckDelete}async archive(e){let{query:t}=a.archiveDeck();return (await this.connection.execute(t,{id:e})).deckArchive}async restore(e){let{query:t}=a.restoreDeck();return (await this.connection.execute(t,{id:e})).deckRestore}async unpublish(e){let{query:t}=a.unpublishDeck();return (await this.connection.execute(t,{id:e})).deckUnpublish}async publish(e,t){let{query:r}=a.publishDeck(),s=a.deckPublishVariables(e,t);return (await this.connection.execute(r,s)).deckPublish}async removeInvalidEntries(e,t){let{query:r}=a.removeInvalidDeckEntries(),s=a.deckRemoveInvalidEntriesVariables(e,t);return (await this.connection.execute(r,s)).deckRemoveInvalidEntries}async upsertCollaborator(e,t,r){let{query:s}=a.upsertDeckCollaborator(),i=a.deckCollaboratorVariables(e,t,r);return (await this.connection.execute(s,i)).deckCollaboratorUpsert}async removeCollaborator(e,t){let{query:r}=a.removeDeckCollaborator(),s=a.deckCollaboratorVariables(e,t);return !!(await this.connection.execute(r,s)).deckCollaboratorRemove}async createPreviewToken(e){let{query:t}=a.createDeckPreviewToken(),r=a.deckPreviewTokenCreateVariables(e);return (await this.connection.execute(t,r)).deckPreviewTokenCreate}async revokePreviewToken(e){let{query:t}=a.revokeDeckPreviewToken();return !!(await this.connection.execute(t,{id:e})).deckPreviewTokenRevoke}async createEmbedToken(e){let{query:t}=a.createDeckEmbedToken(),r=a.deckEmbedTokenCreateVariables(e);return (await this.connection.execute(t,r)).deckEmbedTokenCreate}async revokeEmbedToken(e){let{query:t}=a.revokeDeckEmbedToken();return !!(await this.connection.execute(t,{id:e})).deckEmbedTokenRevoke}async createAccessTokenIssuer(e){let{query:t}=a.createDeckAccessTokenIssuer(),r=a.deckAccessTokenIssuerCreateVariables(e);return (await this.connection.execute(t,r)).deckAccessTokenIssuerCreate}async revokeAccessTokenIssuer(e){let{query:t}=a.revokeDeckAccessTokenIssuer();return !!(await this.connection.execute(t,{id:e})).deckAccessTokenIssuerRevoke}async revokeAccessTokenIssuerSigningKey(e){let{query:t}=a.revokeDeckAccessTokenIssuerSigningKey();return (await this.connection.execute(t,{id:e})).deckAccessTokenIssuerSigningKeyRevoke}async grantApiApplicationAccess(e){let{query:t}=a.grantDeckApiApplicationAccess(),r=a.deckApiApplicationAccessGrantVariables(e);return (await this.connection.execute(t,r)).deckApiApplicationAccessGrant}async revokeApiApplicationAccess(e,t){let{query:r}=a.revokeDeckApiApplicationAccess(),s=a.deckApiApplicationAccessRevokeVariables(e,t);return !!(await this.connection.execute(r,s)).deckApiApplicationAccessRevoke}async exchangeAccessToken(e){this.config.requireSecretCredential("decks.exchangeAccessToken");let{query:t}=a.exchangeDeckAccessToken(),r=a.deckAccessTokenExchangeVariables(e);return (await this.connection.execute(t,r)).deckAccessTokenExchange}async exchangeSessionToken(e){this.config.requireSecretCredential("decks.exchangeSessionToken");let{query:t}=a.exchangeDeckSessionToken(),r=a.deckSessionTokenExchangeVariables(e);return (await this.connection.execute(t,r)).deckSessionTokenExchange}async revokeAccessToken(e){this.config.requireSecretCredential("decks.revokeAccessToken");let{query:t}=a.revokeDeckAccessToken();return !!(await this.connection.execute(t,{id:e})).deckAccessTokenRevoke}async hydrateEntries(e){if(e.entries.length===0)return [];let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let s=e.entries.map(o=>o.identifier),i=this.cacheKey("decks","hydrateEntries",{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifiers:s}),n=await this.withCache(i,"decks",e,async()=>{let{query:o}=a.fetchRecordsByIdentifier();return (await this.connection.execute(o,{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifiers:s})).fetchRecordsByIdentifier}),c=ot(n,s,e.identifierField);return e.entries.map(o=>({...o,record:c.get(o.identifier)??null}))}};function ot(e,t,r){let s=new Set(t),i=new Map;for(let n of e){let c=r?n.data[r]:Object.values(n.data).find(h=>s.has(String(h)));if(c==null)continue;let o=String(c);s.has(o)&&(i.set(o,n),s.delete(o));}return i}var ut=class extends m{constructor(e,t){super(e,t);}async list(e){let t=C(e.filter),{query:r,variables:s}=a.listDatasetRecords({datasetId:e.datasetId,filter:t,orderBy:e.orderBy,first:e.first,after:e.after,last:e.last,before:e.before,validateSchema:e.validateSchema}),i=this.cacheKey("records","list",s),n=await this.withCache(i,"records",e,async()=>(await this.connection.execute(r,s)).datasetRecords);return new d(n,{nextPageLoader:async c=>this.list({...e,after:c})})}async getByDatasetIdentifier(e){let t=this.cacheKey("records","getByDatasetIdentifier",{datasetId:e.datasetId,identifier:e.identifier,includePricing:e.includePricing??false});return this.withCache(t,"records",e,async()=>{let{query:r,variables:s}=a.datasetRecord({datasetId:e.datasetId,identifier:e.identifier,includePricing:e.includePricing});return (await this.connection.execute(r,s)).datasetRecord??null})}async upsertBatch(e){this.config.requireSecretCredential("records.upsertBatch");let{query:t}=a.upsertDatasetRecords();return (await this.connection.execute(t,a.datasetRecordsUpsertVariables(e))).datasetRecordsUpsert}async deleteBatch(e){this.config.requireSecretCredential("records.deleteBatch");let{query:t}=a.deleteDatasetRecords();return (await this.connection.execute(t,a.datasetRecordsDeleteVariables(e))).datasetRecordsDelete}async getDeleteJob(e,t={}){let r=this.cacheKey("records","getDeleteJob",{id:e});return this.withCache(r,"records",t,async()=>{let{query:s}=a.datasetRecordDeleteJob();return (await this.connection.execute(s,{id:e})).datasetRecordDeleteJob??null})}async listDeleteJobs(e,t={}){let{query:r,variables:s}=a.datasetRecordDeleteJobs({publisherId:e,datasetId:t.datasetId,status:t.status,first:t.first,after:t.after}),i=this.cacheKey("records","listDeleteJobs",s),n=await this.withCache(i,"records",t,async()=>(await this.connection.execute(r,s)).datasetRecordDeleteJobs);return new d(n,{nextPageLoader:async c=>this.listDeleteJobs(e,{...t,after:c})})}async waitForDeleteJob(e,t={}){let r=t.intervalMs??1e3,s=t.timeoutMs??3e5,i=Date.now();for(;;){let n=await this.getDeleteJob(e,{cache:false});if(!n)throw new Error(`Delete job '${e}' was not found`);if(n.status==="COMPLETED"||n.status==="FAILED")return n;if(Date.now()-i>=s)throw new Error(`Timed out waiting for delete job '${e}'`);await new Promise(c=>setTimeout(c,r));}}async search(e){let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let s=C(e.filter),{query:i,variables:n}=a.searchRecords({publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,filter:s,search:e.search,orderBy:e.orderBy,resolveLinks:e.resolveLinks,first:e.first,after:e.after,validateSchema:e.validateSchema,includePricing:e.includePricing}),c=this.cacheKey("records","search",{...n,includePricing:e.includePricing??false}),o=await this.withCache(c,"records",e,async()=>(await this.connection.execute(i,n)).searchRecords);return new d(o,{nextPageLoader:async h=>this.search({...e,after:h})})}async get(e,t={}){let r=this.cacheKey("records","get",{id:e,includePricing:t.includePricing??false});return this.withCache(r,"records",t,async()=>{let{query:s}=a.fetchRecordById({includePricing:t.includePricing});return (await this.connection.execute(s,{id:e})).fetchRecord??null})}async getByIdentifier(e){let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let s=this.cacheKey("records","getByIdentifier",{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifier:e.identifier,includePricing:e.includePricing??false});return this.withCache(s,"records",e,async()=>{let{query:i}=a.fetchRecordByIdentifier({includePricing:e.includePricing});return (await this.connection.execute(i,{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifier:e.identifier})).fetchRecordByIdentifier??null})}async getManyByIdentifier(e){if(e.identifiers.length===0)return [];let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let s=this.cacheKey("records","getManyByIdentifier",{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifiers:e.identifiers,includePricing:e.includePricing??false});return this.withCache(s,"records",e,async()=>{let{query:i}=a.fetchRecordsByIdentifier({includePricing:e.includePricing});return (await this.connection.execute(i,{publisherSlug:t,gameKey:r,datasetKey:e.datasetKey,identifiers:e.identifiers})).fetchRecordsByIdentifier??[]})}async getMany(e,t={}){if(e.length===0)return [];let r=this.cacheKey("records","getMany",{ids:e,includePricing:t.includePricing??false});return this.withCache(r,"records",t,async()=>{let{query:s}=a.fetchRecords({includePricing:t.includePricing});return (await this.connection.execute(s,{ids:e})).fetchRecords??[]})}},dt=class extends m{constructor(e,t){super(e,t);}async datasets(e={}){let t=this.resolvePublisher(e.publisherSlug),r=this.resolveGame(e.gameKey);this.validateAccess(t,r);let{query:s,variables:i}=a.searchDatasets({publisherSlug:t,gameKey:r,search:e.search,purpose:"RULES",first:e.first,after:e.after}),n=this.cacheKey("rules","datasets",i),c=await this.withCache(n,"datasets",e,async()=>(await this.connection.execute(s,i)).searchDatasets);return new d(c,{nextPageLoader:async o=>this.datasets({...e,after:o})})}async list(e={}){return this.searchRuleRecords("rules",e)}async formats(e={}){return this.searchRuleRecords(e.datasetKey??"formats",e)}async searchRuleRecords(e,t){let r=this.resolvePublisher(t.publisherSlug),s=this.resolveGame(t.gameKey),i=t.datasetKey??e;this.validateAccess(r,s);let n=C(t.filter),{query:c,variables:o}=a.searchRecords({publisherSlug:r,gameKey:s,datasetKey:i,filter:n,search:t.search,orderBy:t.orderBy,resolveLinks:t.resolveLinks,first:t.first,after:t.after,validateSchema:t.validateSchema}),h=this.cacheKey("rules","records",o),H=await this.withCache(h,"records",t,async()=>(await this.connection.execute(c,o)).searchRecords);return new d(H,{nextPageLoader:async X=>this.searchRuleRecords(e,{...t,after:X})})}},lt=class extends m{constructor(e,t){super(e,t);}async list(e){let{query:t,variables:r}=a.deckImportFormats({publisherId:e.publisherId,gameId:e.gameId,includeArchived:e.includeArchived,first:e.first,after:e.after}),s=this.cacheKey("importFormats","list",r),i=await this.withCache(s,"importFormats",e,async()=>(await this.connection.execute(t,r)).deckImportFormats);return new d(i,{nextPageLoader:async n=>this.list({...e,after:n})})}async get(e,t={}){let r=this.cacheKey("importFormats","get",{id:e});return this.withCache(r,"importFormats",t,async()=>{let{query:s}=a.deckImportFormat();return (await this.connection.execute(s,{id:e})).deckImportFormat??null})}async getByKey(e){let t=this.cacheKey("importFormats","getByKey",{gameId:e.gameId,formatKey:e.key});return this.withCache(t,"importFormats",e,async()=>{let{query:r}=a.deckImportFormat();return (await this.connection.execute(r,{gameId:e.gameId,key:e.key})).deckImportFormat??null})}async test(e){let{query:t}=a.deckImportFormatTest();return (await this.connection.execute(t,a.deckImportFormatTestVariables(e))).deckImportFormatTest}async create(e){this.config.requireSecretCredential("importFormats.create");let{query:t}=a.createDeckImportFormat();return (await this.connection.execute(t,a.deckImportFormatCreateVariables(e))).deckImportFormatCreate}async update(e,t){this.config.requireSecretCredential("importFormats.update");let{query:r}=a.updateDeckImportFormat();return (await this.connection.execute(r,a.deckImportFormatUpdateVariables(e,t))).deckImportFormatUpdate}async archive(e){this.config.requireSecretCredential("importFormats.archive");let{query:t}=a.archiveDeckImportFormat();return (await this.connection.execute(t,{id:e})).deckImportFormatArchive}async unarchive(e){this.config.requireSecretCredential("importFormats.unarchive");let{query:t}=a.unarchiveDeckImportFormat();return (await this.connection.execute(t,{id:e})).deckImportFormatUnarchive}},ht=class extends m{constructor(e,t){super(e,t);}async preview(e){let{query:t}=a.datasetImportPreview();return (await this.connection.execute(t,a.datasetImportPreviewVariables(e))).datasetImportPreview}async validate(e){let{query:t}=a.datasetImportValidate();return (await this.connection.execute(t,a.datasetImportValidateVariables(e))).datasetImportValidate}async run(e){if(this.config.requireSecretCredential("imports.run"),"fileId"in e&&e.fileId){let{query:s}=a.datasetImportFromFile();return (await this.connection.execute(s,a.datasetImportFromFileVariables(e))).datasetImportFromFile}if("sourceUrl"in e&&e.sourceUrl){let{query:s}=a.datasetImportFromUrl();return (await this.connection.execute(s,a.datasetImportFromUrlVariables(e))).datasetImportFromUrl}let{query:t}=a.datasetImportFromPayload();return (await this.connection.execute(t,a.datasetImportFromPayloadVariables(e))).datasetImportFromPayload}async getJob(e,t={}){let r=this.cacheKey("imports","getJob",{id:e});return this.withCache(r,"imports",t,async()=>{let{query:s}=a.importJob();return (await this.connection.execute(s,{id:e})).importJob??null})}async listJobs(e,t={}){let{query:r,variables:s}=a.importJobs({publisherId:e,datasetId:t.datasetId,status:t.status,first:t.first,after:t.after}),i=this.cacheKey("imports","listJobs",s),n=await this.withCache(i,"imports",t,async()=>(await this.connection.execute(r,s)).importJobs);return new d(n,{nextPageLoader:async c=>this.listJobs(e,{...t,after:c})})}async cancelJob(e){this.config.requireSecretCredential("imports.cancelJob");let{query:t}=a.importJobCancel();return (await this.connection.execute(t,{id:e})).importJobCancel}async listJobLogs(e,t={}){let{query:r,variables:s}=a.importJobLogs({importJobId:e,level:t.level,datasetKey:t.datasetKey,first:t.first,after:t.after}),i=this.cacheKey("imports","listJobLogs",s),n=await this.withCache(i,"imports",t,async()=>(await this.connection.execute(r,s)).importJob?.logs??yt());return new d(n,{nextPageLoader:async c=>this.listJobLogs(e,{...t,after:c})})}async waitForJob(e,t={}){let r=t.intervalMs??1e3,s=t.timeoutMs??3e5,i=Date.now();for(;;){let n=await this.getJob(e,{cache:false});if(!n)throw new Error(`Import job '${e}' was not found`);if(n.status==="COMPLETED"||n.status==="FAILED")return n;if(Date.now()-i>=s)throw new Error(`Timed out waiting for import job '${e}'`);await new Promise(c=>setTimeout(c,r));}}async previewGame(e){let{query:t}=a.gameImportPreview();return (await this.connection.execute(t,a.gameImportPreviewVariables(e))).gameImportPreview}async runGame(e){if(this.config.requireSecretCredential("imports.runGame"),"fileId"in e&&e.fileId){let{query:s}=a.gameImportFromFile();return (await this.connection.execute(s,a.gameImportFromFileVariables(e))).gameImportFromFile}if("sourceUrl"in e&&e.sourceUrl){let{query:s}=a.gameImportFromUrl();return (await this.connection.execute(s,a.gameImportFromUrlVariables(e))).gameImportFromUrl}let{query:t}=a.gameImportFromPayload();return (await this.connection.execute(t,a.gameImportFromPayloadVariables(e))).gameImportFromPayload}async getGameJob(e,t={}){let r=this.cacheKey("imports","getGameJob",{id:e});return this.withCache(r,"imports",t,async()=>{let{query:s}=a.gameImportJob();return (await this.connection.execute(s,{id:e})).gameImportJob??null})}async listGameJobs(e,t={}){let{query:r,variables:s}=a.gameImportJobs({gameId:e,status:t.status,first:t.first,after:t.after}),i=this.cacheKey("imports","listGameJobs",s),n=await this.withCache(i,"imports",t,async()=>(await this.connection.execute(r,s)).gameImportJobs);return new d(n,{nextPageLoader:async c=>this.listGameJobs(e,{...t,after:c})})}async cancelGameJob(e){this.config.requireSecretCredential("imports.cancelGameJob");let{query:t}=a.gameImportJobCancel();return (await this.connection.execute(t,{id:e})).gameImportJobCancel}async waitForGameJob(e,t={}){let r=t.intervalMs??1e3,s=t.timeoutMs??3e5,i=Date.now();for(;;){let n=await this.getGameJob(e,{cache:false});if(!n)throw new Error(`Game import job '${e}' was not found`);if(n.status==="COMPLETED"||n.status==="FAILED")return n;if(Date.now()-i>=s)throw new Error(`Timed out waiting for game import job '${e}'`);await new Promise(c=>setTimeout(c,r));}}};function yt(){return {totalCount:0,pageInfo:{hasNextPage:false,hasPreviousPage:false,startCursor:null,endCursor:null},edges:[]}}var ft=class extends m{constructor(e,t){super(e,t);}async run(e){this.config.requireSecretCredential("exports.run");let{query:t}=a.datasetExport();return (await this.connection.execute(t,a.datasetExportVariables(e))).datasetExport}async create(e){return this.run(e)}async getJob(e,t={}){let r=this.cacheKey("exports","getJob",{id:e});return this.withCache(r,"exports",t,async()=>{let{query:s}=a.exportJob();return (await this.connection.execute(s,{id:e})).exportJob??null})}async listJobs(e,t={}){let{query:r,variables:s}=a.exportJobs({publisherId:e,gameId:t.gameId,datasetId:t.datasetId,status:t.status,first:t.first,after:t.after}),i=this.cacheKey("exports","listJobs",s),n=await this.withCache(i,"exports",t,async()=>(await this.connection.execute(r,s)).exportJobs);return new d(n,{nextPageLoader:async c=>this.listJobs(e,{...t,after:c})})}async refreshUrl(e){let{query:t}=a.exportJobRefreshUrl();return (await this.connection.execute(t,{id:e})).exportJobRefreshUrl}async cancel(e){this.config.requireSecretCredential("exports.cancel");let{query:t}=a.exportJobCancel();return (await this.connection.execute(t,{id:e})).exportJobCancel}async waitForJob(e,t={}){let r=t.intervalMs??1e3,s=t.timeoutMs??3e5,i=Date.now();for(;;){let n=await this.getJob(e,{cache:false});if(!n)throw new Error(`Export job '${e}' was not found`);if(n.status==="COMPLETED"||n.status==="FAILED")return n;if(Date.now()-i>=s)throw new Error(`Timed out waiting for export job '${e}'`);await new Promise(c=>setTimeout(c,r));}}},pt=class extends m{constructor(e,t){super(e,t);}async get(e,t={}){let r=this.cacheKey("files","get",{id:e});return this.withCache(r,"files",t,async()=>{let{query:s}=a.file();return (await this.connection.execute(s,{id:e})).file??null})}async requestUpload(e){this.config.requireSecretCredential("files.requestUpload");let{query:t}=a.fileUploadRequest();return (await this.connection.execute(t,a.fileUploadRequestVariables(e))).fileUploadRequest}async confirmUpload(e){this.config.requireSecretCredential("files.confirmUpload");let{query:t}=a.fileUploadConfirm();return (await this.connection.execute(t,{id:e})).fileUploadConfirm}async delete(e){this.config.requireSecretCredential("files.delete");let{query:t}=a.fileDelete();return !!(await this.connection.execute(t,{id:e})).fileDelete}},ke=class Ie{config;connection;publishers;games;datasets;records;decks;rules;importFormats;imports;exports;files;constructor(t={}){this.config=new Xe(t),this.connection=new et(this.config),this.publishers=new it(this.connection,this.config),this.games=new at(this.connection,this.config),this.datasets=new nt(this.connection,this.config),this.records=new ut(this.connection,this.config),this.decks=new ct(this.connection,this.config),this.rules=new dt(this.connection,this.config),this.importFormats=new lt(this.connection,this.config),this.imports=new ht(this.connection,this.config),this.exports=new ft(this.connection,this.config),this.files=new pt(this.connection,this.config);}async me(){let{query:t}=a.fetchMe();return (await this.connection.execute(t)).fetchMe??null}getRateLimitInfo(){return Ze()}withConfig(t){let r=this.config.merge(t);return new Ie({apiKey:r.configApiKey(),publishableKey:r.publishableKey,secretKey:r.secretKey,accessToken:r.accessToken,environment:r.environment,endpoint:r.endpoint,timeout:r.timeout,openTimeout:r.openTimeout,defaultPublisher:r.defaultPublisher,defaultGame:r.defaultGame,allowedPublishers:r.allowedPublishers,allowedGames:r.allowedGames,logger:r.logger,logLevel:r.logLevel,retryOnRateLimit:r.retryOnRateLimit,maxRetries:r.maxRetries,retryOnNetworkError:r.retryOnNetworkError,maxNetworkRetries:r.maxNetworkRetries,retryBaseDelay:r.retryBaseDelay,retryMaxDelay:r.retryMaxDelay,cache:r.cache,cacheTtl:r.cacheTtl,cacheTtls:r.cacheTtls})}};var Y=class{storage;prefix;constructor(t={}){let r=t.storage??"localStorage";this.storage=r==="sessionStorage"?globalThis.sessionStorage:globalThis.localStorage,this.prefix=t.prefix??"carddb:";}get(t){try{let r=this.storage.getItem(this.prefix+t);if(!r)return null;let s=JSON.parse(r);return s.expiresAt!==null&&Date.now()>s.expiresAt?(this.storage.removeItem(this.prefix+t),null):s.value}catch{return this.storage.removeItem(this.prefix+t),null}}set(t,r,s){try{let i={value:r,expiresAt:s!==void 0?Date.now()+s*1e3:null};this.storage.setItem(this.prefix+t,JSON.stringify(i));}catch(i){console.warn("[CardDB] Failed to write to cache:",i);}}delete(t){this.storage.removeItem(this.prefix+t);}clear(){let t=[];for(let r=0;r<this.storage.length;r++){let s=this.storage.key(r);s&&s.startsWith(this.prefix)&&t.push(s);}for(let r of t)this.storage.removeItem(r);}has(t){return this.get(t)!==null}get size(){let t=0;for(let r=0;r<this.storage.length;r++){let s=this.storage.key(r);s&&s.startsWith(this.prefix)&&t++;}return t}cleanup(){let t=Date.now(),r=[];for(let s=0;s<this.storage.length;s++){let i=this.storage.key(s);if(i&&i.startsWith(this.prefix))try{let n=this.storage.getItem(i);if(n){let c=JSON.parse(n);c.expiresAt!==null&&t>c.expiresAt&&r.push(i);}}catch{r.push(i);}}for(let s of r)this.storage.removeItem(s);}};var $e=class extends ke{constructor(t={}){if("apiKey"in t&&t.apiKey!==void 0)throw new b("apiKey is not accepted in browsers; use publishableKey or accessToken");if("secretKey"in t&&t.secretKey!==void 0)throw new b("secretKey is server-only; use publishableKey or accessToken in browsers");super(t);}};
1673
+ export{B as AuthenticationError,m as BaseResource,Y as BrowserCache,$e as CardDBClient,y as CardDBError,d as Collection,Xe as Configuration,et as Connection,E as ConnectionError,Me as DEFAULT_CACHE_TTL,Je as DEFAULT_ENDPOINT,je as DEFAULT_MAX_NETWORK_RETRIES,Ne as DEFAULT_MAX_RETRIES,Ge as DEFAULT_OPEN_TIMEOUT,Ye as DEFAULT_RETRY_BASE_DELAY,He as DEFAULT_RETRY_MAX_DELAY,Oe as DEFAULT_TIMEOUT,nt as DatasetsResource,ct as DecksResource,ft as ExportsResource,pt as FilesResource,be as FilterBuilder,at as GamesResource,se as GraphQLError,lt as ImportFormatsResource,ht as ImportsResource,gt as LinkResolutionError,mt as NotFoundError,it as PublishersResource,a as QueryBuilder,q as RateLimitError,ut as RecordsResource,b as RestrictedError,dt as RulesResource,J as ServerError,_ as TimeoutError,V as ValidationError,tt as cacheKey,Et as contains,kt as eq,Ze as getRateLimitInfo,Mt as getSDKVersion,ze as getUserAgent,$t as gt,bt as gte,xt as ilike,qt as isNotNull,Rt as isNull,St as like,Dt as lt,vt as lte,It as neq,At as notWithin,rt as readCache,C as resolveFilter,wt as within,st as writeCache};//# sourceMappingURL=index.js.map
1654
1674
  //# sourceMappingURL=index.js.map