@carddb/client 0.1.5 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +1352 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +658 -3
- package/dist/index.d.ts +658 -3
- package/dist/index.js +1349 -68
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -13,6 +13,11 @@ var DEFAULT_RETRY_BASE_DELAY = 1e3;
|
|
|
13
13
|
var DEFAULT_RETRY_MAX_DELAY = 3e4;
|
|
14
14
|
var Configuration = class _Configuration {
|
|
15
15
|
apiKey;
|
|
16
|
+
publishableKey;
|
|
17
|
+
secretKey;
|
|
18
|
+
accessToken;
|
|
19
|
+
legacyApiKey;
|
|
20
|
+
environment;
|
|
16
21
|
endpoint;
|
|
17
22
|
timeout;
|
|
18
23
|
openTimeout;
|
|
@@ -32,7 +37,12 @@ var Configuration = class _Configuration {
|
|
|
32
37
|
cacheTtl;
|
|
33
38
|
cacheTtls;
|
|
34
39
|
constructor(config = {}) {
|
|
35
|
-
this.
|
|
40
|
+
this.legacyApiKey = config.apiKey;
|
|
41
|
+
this.publishableKey = config.publishableKey;
|
|
42
|
+
this.secretKey = config.secretKey;
|
|
43
|
+
this.accessToken = config.accessToken;
|
|
44
|
+
this.apiKey = config.apiKey ?? config.publishableKey ?? config.secretKey;
|
|
45
|
+
this.environment = config.environment;
|
|
36
46
|
this.endpoint = config.endpoint ?? DEFAULT_ENDPOINT;
|
|
37
47
|
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
38
48
|
this.openTimeout = config.openTimeout ?? DEFAULT_OPEN_TIMEOUT;
|
|
@@ -110,6 +120,27 @@ var Configuration = class _Configuration {
|
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Secret-key-only helpers are for server runtimes and trusted backend workflows.
|
|
125
|
+
*/
|
|
126
|
+
requireSecretCredential(operation) {
|
|
127
|
+
if (!this.accessToken && (this.legacyApiKey || this.secretKey && !this.publishableKey)) return;
|
|
128
|
+
throw new core.RestrictedError(
|
|
129
|
+
`${operation} requires a server-side secretKey or legacy apiKey credential`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* API key sent on requests when no OAuth bearer token is configured.
|
|
134
|
+
*/
|
|
135
|
+
requestApiKey() {
|
|
136
|
+
return this.legacyApiKey ?? this.publishableKey ?? this.secretKey;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Explicit legacy apiKey supplied by the caller, excluding publishable/secret aliases.
|
|
140
|
+
*/
|
|
141
|
+
configApiKey() {
|
|
142
|
+
return this.legacyApiKey;
|
|
143
|
+
}
|
|
113
144
|
/**
|
|
114
145
|
* Check if a log level should be logged
|
|
115
146
|
*/
|
|
@@ -127,7 +158,11 @@ var Configuration = class _Configuration {
|
|
|
127
158
|
*/
|
|
128
159
|
merge(overrides) {
|
|
129
160
|
return new _Configuration({
|
|
130
|
-
apiKey: overrides.apiKey ?? this.
|
|
161
|
+
apiKey: overrides.apiKey ?? this.legacyApiKey,
|
|
162
|
+
publishableKey: overrides.publishableKey ?? this.publishableKey,
|
|
163
|
+
secretKey: overrides.secretKey ?? this.secretKey,
|
|
164
|
+
accessToken: overrides.accessToken ?? this.accessToken,
|
|
165
|
+
environment: overrides.environment ?? this.environment,
|
|
131
166
|
endpoint: overrides.endpoint ?? this.endpoint,
|
|
132
167
|
timeout: overrides.timeout ?? this.timeout,
|
|
133
168
|
openTimeout: overrides.openTimeout ?? this.openTimeout,
|
|
@@ -272,6 +307,7 @@ var Connection = class {
|
|
|
272
307
|
async fetch(query, variables) {
|
|
273
308
|
const controller = new AbortController();
|
|
274
309
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
310
|
+
const apiKey = this.config.requestApiKey();
|
|
275
311
|
try {
|
|
276
312
|
const response = await fetch(this.config.endpoint, {
|
|
277
313
|
method: "POST",
|
|
@@ -279,7 +315,8 @@ var Connection = class {
|
|
|
279
315
|
"Content-Type": "application/json",
|
|
280
316
|
Accept: "application/json",
|
|
281
317
|
"User-Agent": getUserAgent(),
|
|
282
|
-
...this.config.
|
|
318
|
+
...this.config.accessToken ? { Authorization: `Bearer ${this.config.accessToken}` } : {},
|
|
319
|
+
...!this.config.accessToken && apiKey ? { "X-API-Key": apiKey } : {}
|
|
283
320
|
},
|
|
284
321
|
body: JSON.stringify({ query, variables }),
|
|
285
322
|
signal: controller.signal
|
|
@@ -576,6 +613,73 @@ var GamesResource = class extends BaseResource {
|
|
|
576
613
|
constructor(connection, config) {
|
|
577
614
|
super(connection, config);
|
|
578
615
|
}
|
|
616
|
+
/**
|
|
617
|
+
* List games for a publisher-management context.
|
|
618
|
+
*/
|
|
619
|
+
async list(publisherId, options = {}) {
|
|
620
|
+
const { query, variables } = core.QueryBuilder.listGames({
|
|
621
|
+
publisherId,
|
|
622
|
+
first: options.first,
|
|
623
|
+
after: options.after,
|
|
624
|
+
includeArchived: options.includeArchived
|
|
625
|
+
});
|
|
626
|
+
const key = this.cacheKey("games", "list", variables);
|
|
627
|
+
const data = await this.withCache(key, "games", options, async () => {
|
|
628
|
+
const result = await this.connection.execute(query, variables);
|
|
629
|
+
return result["games"];
|
|
630
|
+
});
|
|
631
|
+
return new core.Collection(data, {
|
|
632
|
+
nextPageLoader: async (cursor) => this.list(publisherId, { ...options, after: cursor })
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Get a publisher-managed game by stable key.
|
|
637
|
+
*/
|
|
638
|
+
async getByKey(options) {
|
|
639
|
+
const key = this.cacheKey("games", "getByKey", {
|
|
640
|
+
publisherId: options.publisherId,
|
|
641
|
+
publisherSlug: options.publisherSlug,
|
|
642
|
+
gameKey: options.gameKey
|
|
643
|
+
});
|
|
644
|
+
return this.withCache(key, "games", options, async () => {
|
|
645
|
+
const { query, variables } = core.QueryBuilder.game(options);
|
|
646
|
+
const result = await this.connection.execute(query, variables);
|
|
647
|
+
return result["game"] ?? null;
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Get a publisher-managed game by slug.
|
|
652
|
+
*/
|
|
653
|
+
async getBySlug(options) {
|
|
654
|
+
const key = this.cacheKey("games", "getBySlug", {
|
|
655
|
+
publisherId: options.publisherId,
|
|
656
|
+
publisherSlug: options.publisherSlug,
|
|
657
|
+
gameSlug: options.gameSlug
|
|
658
|
+
});
|
|
659
|
+
return this.withCache(key, "games", options, async () => {
|
|
660
|
+
const { query, variables } = core.QueryBuilder.game(options);
|
|
661
|
+
const result = await this.connection.execute(query, variables);
|
|
662
|
+
return result["game"] ?? null;
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Create a publisher-managed game. Requires a server-side secret credential.
|
|
667
|
+
*/
|
|
668
|
+
async create(input) {
|
|
669
|
+
this.config.requireSecretCredential("games.create");
|
|
670
|
+
const { query } = core.QueryBuilder.createGame();
|
|
671
|
+
const result = await this.connection.execute(query, core.QueryBuilder.gameCreateVariables(input));
|
|
672
|
+
return result["gameCreate"];
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Update a publisher-managed game. Requires a server-side secret credential.
|
|
676
|
+
*/
|
|
677
|
+
async update(id, input) {
|
|
678
|
+
this.config.requireSecretCredential("games.update");
|
|
679
|
+
const { query } = core.QueryBuilder.updateGame();
|
|
680
|
+
const result = await this.connection.execute(query, core.QueryBuilder.gameUpdateVariables(id, input));
|
|
681
|
+
return result["gameUpdate"];
|
|
682
|
+
}
|
|
579
683
|
/**
|
|
580
684
|
* Search for games
|
|
581
685
|
*
|
|
@@ -651,6 +755,58 @@ var DatasetsResource = class extends BaseResource {
|
|
|
651
755
|
constructor(connection, config) {
|
|
652
756
|
super(connection, config);
|
|
653
757
|
}
|
|
758
|
+
/**
|
|
759
|
+
* List datasets for a publisher-management context.
|
|
760
|
+
*/
|
|
761
|
+
async list(publisherId, options = {}) {
|
|
762
|
+
const { query, variables } = core.QueryBuilder.listDatasets({
|
|
763
|
+
publisherId,
|
|
764
|
+
gameId: options.gameId,
|
|
765
|
+
includeArchived: options.includeArchived,
|
|
766
|
+
purpose: options.purpose,
|
|
767
|
+
first: options.first,
|
|
768
|
+
after: options.after
|
|
769
|
+
});
|
|
770
|
+
const key = this.cacheKey("datasets", "list", variables);
|
|
771
|
+
const data = await this.withCache(key, "datasets", options, async () => {
|
|
772
|
+
const result = await this.connection.execute(query, variables);
|
|
773
|
+
return result["datasets"];
|
|
774
|
+
});
|
|
775
|
+
return new core.Collection(data, {
|
|
776
|
+
nextPageLoader: async (cursor) => this.list(publisherId, { ...options, after: cursor })
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Get a dataset by game ID and stable dataset key.
|
|
781
|
+
*/
|
|
782
|
+
async getByKey(options) {
|
|
783
|
+
const key = this.cacheKey("datasets", "getByKey", {
|
|
784
|
+
publisherId: options.publisherId,
|
|
785
|
+
gameId: options.gameId,
|
|
786
|
+
datasetKey: options.datasetKey
|
|
787
|
+
});
|
|
788
|
+
return this.withCache(key, "datasets", options, async () => {
|
|
789
|
+
const { query, variables } = core.QueryBuilder.dataset(options);
|
|
790
|
+
const result = await this.connection.execute(query, variables);
|
|
791
|
+
return result["dataset"] ?? null;
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Fetch only the schema portion for a dataset.
|
|
796
|
+
*/
|
|
797
|
+
async getSchema(idOrOptions) {
|
|
798
|
+
const dataset = typeof idOrOptions === "string" ? await this.withCache(
|
|
799
|
+
this.cacheKey("datasets", "getSchema", { id: idOrOptions }),
|
|
800
|
+
"datasets",
|
|
801
|
+
{},
|
|
802
|
+
async () => {
|
|
803
|
+
const { query, variables } = core.QueryBuilder.dataset({ id: idOrOptions });
|
|
804
|
+
const result = await this.connection.execute(query, variables);
|
|
805
|
+
return result["dataset"] ?? null;
|
|
806
|
+
}
|
|
807
|
+
) : await this.getByKey(idOrOptions);
|
|
808
|
+
return dataset?.schema ?? null;
|
|
809
|
+
}
|
|
654
810
|
/**
|
|
655
811
|
* Search for datasets
|
|
656
812
|
*
|
|
@@ -743,6 +899,17 @@ var DecksResource = class extends BaseResource {
|
|
|
743
899
|
return result["fetchDeck"] ?? null;
|
|
744
900
|
});
|
|
745
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
* Fetch a deck by UUID using the ownership-aware `deck` API.
|
|
904
|
+
*/
|
|
905
|
+
async get(id, options = {}) {
|
|
906
|
+
const key = this.cacheKey("decks", "get", { id });
|
|
907
|
+
return this.withCache(key, "decks", options, async () => {
|
|
908
|
+
const { query } = core.QueryBuilder.deckById();
|
|
909
|
+
const result = await this.connection.execute(query, { id });
|
|
910
|
+
return result["deck"] ?? null;
|
|
911
|
+
});
|
|
912
|
+
}
|
|
746
913
|
/**
|
|
747
914
|
* Fetch one deck owned by the current account or API application.
|
|
748
915
|
*/
|
|
@@ -765,6 +932,17 @@ var DecksResource = class extends BaseResource {
|
|
|
765
932
|
return result["fetchDeckBySlug"] ?? null;
|
|
766
933
|
});
|
|
767
934
|
}
|
|
935
|
+
/**
|
|
936
|
+
* Fetch by slug using the ownership-aware `deckBySlug` API.
|
|
937
|
+
*/
|
|
938
|
+
async getBySlug(publisherSlug, gameKey, slug, options = {}) {
|
|
939
|
+
const key = this.cacheKey("decks", "getBySlug", { publisherSlug, gameKey, slug });
|
|
940
|
+
return this.withCache(key, "decks", options, async () => {
|
|
941
|
+
const { query } = core.QueryBuilder.deckBySlug();
|
|
942
|
+
const result = await this.connection.execute(query, { publisherSlug, gameKey, slug });
|
|
943
|
+
return result["deckBySlug"] ?? null;
|
|
944
|
+
});
|
|
945
|
+
}
|
|
768
946
|
/**
|
|
769
947
|
* Fetch a hosted deck by external reference for the current API application.
|
|
770
948
|
*/
|
|
@@ -776,13 +954,25 @@ var DecksResource = class extends BaseResource {
|
|
|
776
954
|
return result["fetchDeckByExternalRef"] ?? null;
|
|
777
955
|
});
|
|
778
956
|
}
|
|
957
|
+
/**
|
|
958
|
+
* Fetch by external reference using the ownership-aware `deckByExternalRef` API.
|
|
959
|
+
*/
|
|
960
|
+
async getByExternalRef(externalRef, options = {}) {
|
|
961
|
+
const key = this.cacheKey("decks", "getByExternalRef", { externalRef });
|
|
962
|
+
return this.withCache(key, "decks", options, async () => {
|
|
963
|
+
const { query } = core.QueryBuilder.deckByExternalRef();
|
|
964
|
+
const result = await this.connection.execute(query, { externalRef });
|
|
965
|
+
return result["deckByExternalRef"] ?? null;
|
|
966
|
+
});
|
|
967
|
+
}
|
|
779
968
|
/**
|
|
780
969
|
* List decks owned by the current account or API application.
|
|
781
970
|
*/
|
|
782
971
|
async listMine(options = {}) {
|
|
783
972
|
const { query, variables } = core.QueryBuilder.listMyDecks({
|
|
784
973
|
first: options.first,
|
|
785
|
-
after: options.after
|
|
974
|
+
after: options.after,
|
|
975
|
+
includeArchived: options.includeArchived
|
|
786
976
|
});
|
|
787
977
|
const key = this.cacheKey("decks", "listMine", variables);
|
|
788
978
|
const data = await this.withCache(key, "decks", options, async () => {
|
|
@@ -793,6 +983,61 @@ var DecksResource = class extends BaseResource {
|
|
|
793
983
|
nextPageLoader: async (cursor) => this.listMine({ ...options, after: cursor })
|
|
794
984
|
});
|
|
795
985
|
}
|
|
986
|
+
/**
|
|
987
|
+
* List decks owned by the current account or OAuth grant.
|
|
988
|
+
*/
|
|
989
|
+
async listViewer(options = {}) {
|
|
990
|
+
const { query, variables } = core.QueryBuilder.viewerDecks({
|
|
991
|
+
filter: options.filter,
|
|
992
|
+
first: options.first,
|
|
993
|
+
after: options.after
|
|
994
|
+
});
|
|
995
|
+
const key = this.cacheKey("decks", "listViewer", variables);
|
|
996
|
+
const data = await this.withCache(key, "decks", options, async () => {
|
|
997
|
+
const result = await this.connection.execute(query, variables);
|
|
998
|
+
return result["viewerDecks"];
|
|
999
|
+
});
|
|
1000
|
+
return new core.Collection(data, {
|
|
1001
|
+
nextPageLoader: async (cursor) => this.listViewer({ ...options, after: cursor })
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* List app-owned decks for the current secret-key API application.
|
|
1006
|
+
*/
|
|
1007
|
+
async listApp(options = {}) {
|
|
1008
|
+
this.config.requireSecretCredential("decks.listApp");
|
|
1009
|
+
const { query, variables } = core.QueryBuilder.appDecks({
|
|
1010
|
+
filter: options.filter,
|
|
1011
|
+
first: options.first,
|
|
1012
|
+
after: options.after
|
|
1013
|
+
});
|
|
1014
|
+
const key = this.cacheKey("decks", "listApp", variables);
|
|
1015
|
+
const data = await this.withCache(key, "decks", options, async () => {
|
|
1016
|
+
const result = await this.connection.execute(query, variables);
|
|
1017
|
+
return result["appDecks"];
|
|
1018
|
+
});
|
|
1019
|
+
return new core.Collection(data, {
|
|
1020
|
+
nextPageLoader: async (cursor) => this.listApp({ ...options, after: cursor })
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* List published live decks eligible for public discovery.
|
|
1025
|
+
*/
|
|
1026
|
+
async listPublic(options = {}) {
|
|
1027
|
+
const { query, variables } = core.QueryBuilder.publicDecks({
|
|
1028
|
+
filter: options.filter,
|
|
1029
|
+
first: options.first,
|
|
1030
|
+
after: options.after
|
|
1031
|
+
});
|
|
1032
|
+
const key = this.cacheKey("decks", "listPublic", variables);
|
|
1033
|
+
const data = await this.withCache(key, "decks", options, async () => {
|
|
1034
|
+
const result = await this.connection.execute(query, variables);
|
|
1035
|
+
return result["publicDecks"];
|
|
1036
|
+
});
|
|
1037
|
+
return new core.Collection(data, {
|
|
1038
|
+
nextPageLoader: async (cursor) => this.listPublic({ ...options, after: cursor })
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
796
1041
|
/**
|
|
797
1042
|
* Fetch one immutable published deck version.
|
|
798
1043
|
*/
|
|
@@ -833,6 +1078,104 @@ var DecksResource = class extends BaseResource {
|
|
|
833
1078
|
return result["deckPreview"] ?? null;
|
|
834
1079
|
});
|
|
835
1080
|
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Fetch published embed data using a revocable embed token.
|
|
1083
|
+
*/
|
|
1084
|
+
async embed(token, options = {}) {
|
|
1085
|
+
const key = this.cacheKey("decks", "embed", { token });
|
|
1086
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1087
|
+
const { query } = core.QueryBuilder.deckEmbed();
|
|
1088
|
+
const result = await this.connection.execute(query, { token });
|
|
1089
|
+
return result["deckEmbed"] ?? null;
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Fetch token-authorized published data using an exchanged access token.
|
|
1094
|
+
*/
|
|
1095
|
+
async access(token, options = {}) {
|
|
1096
|
+
const key = this.cacheKey("decks", "access", { token });
|
|
1097
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1098
|
+
const { query } = core.QueryBuilder.deckAccess();
|
|
1099
|
+
const result = await this.connection.execute(query, { token });
|
|
1100
|
+
return result["deckAccess"] ?? null;
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Compare the current draft against the latest published version.
|
|
1105
|
+
*/
|
|
1106
|
+
async draftDiff(id, options = {}) {
|
|
1107
|
+
const key = this.cacheKey("decks", "draftDiff", { id });
|
|
1108
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1109
|
+
const { query } = core.QueryBuilder.deckDraftDiff();
|
|
1110
|
+
const result = await this.connection.execute(query, { id });
|
|
1111
|
+
return result["deckDraftDiff"];
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Compare any two readable immutable deck versions from the same deck.
|
|
1116
|
+
*/
|
|
1117
|
+
async versionDiff(fromVersionId, toVersionId, options = {}) {
|
|
1118
|
+
const variables = core.QueryBuilder.deckVersionDiffVariables(fromVersionId, toVersionId);
|
|
1119
|
+
const key = this.cacheKey("decks", "versionDiff", variables);
|
|
1120
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1121
|
+
const { query } = core.QueryBuilder.deckVersionDiff();
|
|
1122
|
+
const result = await this.connection.execute(query, variables);
|
|
1123
|
+
return result["deckVersionDiff"];
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Validate a draft against current or explicitly requested immutable rules/data.
|
|
1128
|
+
*/
|
|
1129
|
+
async validate(id, input, options = {}) {
|
|
1130
|
+
const variables = core.QueryBuilder.deckValidateVariables(id, input);
|
|
1131
|
+
const key = this.cacheKey("decks", "validate", variables);
|
|
1132
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1133
|
+
const { query } = core.QueryBuilder.deckValidate();
|
|
1134
|
+
const result = await this.connection.execute(query, variables);
|
|
1135
|
+
return result["deckValidate"];
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Hydrate unpersisted deck entries against a stored deck's game without mutating the deck.
|
|
1140
|
+
*/
|
|
1141
|
+
async hydrateDeckEntries(input, options = {}) {
|
|
1142
|
+
const variables = core.QueryBuilder.deckHydrateEntriesVariables(input);
|
|
1143
|
+
const key = this.cacheKey("decks", "hydrateDeckEntries", variables);
|
|
1144
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1145
|
+
const { query } = core.QueryBuilder.deckHydrateEntries();
|
|
1146
|
+
const result = await this.connection.execute(query, variables);
|
|
1147
|
+
return result["deckHydrateEntries"];
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Export a readable deck representation in a deterministic text format.
|
|
1152
|
+
*/
|
|
1153
|
+
async exportDeck(id, format = "SIMPLE_TEXT", options = {}) {
|
|
1154
|
+
const variables = core.QueryBuilder.deckExportVariables(id, format);
|
|
1155
|
+
const key = this.cacheKey("decks", "exportDeck", variables);
|
|
1156
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1157
|
+
const { query } = core.QueryBuilder.deckExport();
|
|
1158
|
+
const result = await this.connection.execute(query, variables);
|
|
1159
|
+
return result["deckExport"];
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Resolve current or historical ruleset section definitions.
|
|
1164
|
+
*/
|
|
1165
|
+
async sectionDefinitions(options = {}) {
|
|
1166
|
+
const { query, variables } = core.QueryBuilder.deckSectionDefinitions({
|
|
1167
|
+
publisherSlug: options.publisherSlug,
|
|
1168
|
+
gameKey: options.gameKey,
|
|
1169
|
+
gameId: options.gameId,
|
|
1170
|
+
rulesetKey: options.rulesetKey,
|
|
1171
|
+
rulesetVersionId: options.rulesetVersionId
|
|
1172
|
+
});
|
|
1173
|
+
const key = this.cacheKey("decks", "sectionDefinitions", variables);
|
|
1174
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1175
|
+
const result = await this.connection.execute(query, variables);
|
|
1176
|
+
return result["deckSectionDefinitions"];
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
836
1179
|
/**
|
|
837
1180
|
* List collaborators for a deck.
|
|
838
1181
|
*/
|
|
@@ -855,6 +1198,55 @@ var DecksResource = class extends BaseResource {
|
|
|
855
1198
|
return result["deckPreviewTokens"];
|
|
856
1199
|
});
|
|
857
1200
|
}
|
|
1201
|
+
/**
|
|
1202
|
+
* List published embed tokens for a deck.
|
|
1203
|
+
*/
|
|
1204
|
+
async listEmbedTokens(deckId, options = {}) {
|
|
1205
|
+
const key = this.cacheKey("decks", "listEmbedTokens", { deckId });
|
|
1206
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1207
|
+
const { query } = core.QueryBuilder.deckEmbedTokens();
|
|
1208
|
+
const result = await this.connection.execute(query, { deckId });
|
|
1209
|
+
return result["deckEmbedTokens"];
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
/**
|
|
1213
|
+
* List trusted access token issuers for a deck.
|
|
1214
|
+
*/
|
|
1215
|
+
async listAccessTokenIssuers(deckId, options = {}) {
|
|
1216
|
+
const key = this.cacheKey("decks", "listAccessTokenIssuers", { deckId });
|
|
1217
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1218
|
+
const { query } = core.QueryBuilder.deckAccessTokenIssuers();
|
|
1219
|
+
const result = await this.connection.execute(query, { deckId });
|
|
1220
|
+
return result["deckAccessTokenIssuers"];
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* List API applications with explicit access to one owned deck.
|
|
1225
|
+
*/
|
|
1226
|
+
async listApiApplicationAccesses(deckId, options = {}) {
|
|
1227
|
+
const variables = core.QueryBuilder.deckApiApplicationAccessesVariables(
|
|
1228
|
+
deckId,
|
|
1229
|
+
options.includeRevoked
|
|
1230
|
+
);
|
|
1231
|
+
const key = this.cacheKey("decks", "listApiApplicationAccesses", variables);
|
|
1232
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1233
|
+
const { query } = core.QueryBuilder.deckApiApplicationAccesses();
|
|
1234
|
+
const result = await this.connection.execute(query, variables);
|
|
1235
|
+
return result["deckApiApplicationAccesses"];
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* List selected-deck grants for the current account.
|
|
1240
|
+
*/
|
|
1241
|
+
async listMyApiApplicationAccesses(options = {}) {
|
|
1242
|
+
const variables = core.QueryBuilder.myDeckApiApplicationAccessesVariables(options.applicationId);
|
|
1243
|
+
const key = this.cacheKey("decks", "listMyApiApplicationAccesses", variables);
|
|
1244
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1245
|
+
const { query } = core.QueryBuilder.myDeckApiApplicationAccesses();
|
|
1246
|
+
const result = await this.connection.execute(query, variables);
|
|
1247
|
+
return result["myDeckApiApplicationAccesses"];
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
858
1250
|
/**
|
|
859
1251
|
* Create a hosted deck.
|
|
860
1252
|
*/
|
|
@@ -874,91 +1266,373 @@ var DecksResource = class extends BaseResource {
|
|
|
874
1266
|
return result["deckUpdate"];
|
|
875
1267
|
}
|
|
876
1268
|
/**
|
|
877
|
-
*
|
|
1269
|
+
* Update deck-level metadata without mutating entries.
|
|
878
1270
|
*/
|
|
879
|
-
async
|
|
880
|
-
|
|
881
|
-
const result = await this.connection.execute(query, { id });
|
|
882
|
-
return Boolean(result["deckDelete"]);
|
|
1271
|
+
async updateMetadata(id, input) {
|
|
1272
|
+
return this.update(id, input);
|
|
883
1273
|
}
|
|
884
1274
|
/**
|
|
885
|
-
*
|
|
1275
|
+
* Create or replace a draft by API-application external reference.
|
|
886
1276
|
*/
|
|
887
|
-
async
|
|
888
|
-
|
|
889
|
-
const
|
|
1277
|
+
async upsertByExternalRef(input) {
|
|
1278
|
+
this.config.requireSecretCredential("decks.upsertByExternalRef");
|
|
1279
|
+
const { query } = core.QueryBuilder.upsertDeckByExternalRef();
|
|
1280
|
+
const variables = core.QueryBuilder.deckUpsertByExternalRefVariables(input);
|
|
890
1281
|
const result = await this.connection.execute(query, variables);
|
|
891
|
-
return result["
|
|
1282
|
+
return result["deckUpsertByExternalRef"];
|
|
892
1283
|
}
|
|
893
1284
|
/**
|
|
894
|
-
*
|
|
1285
|
+
* Claim an app-owned deck into the consenting OAuth user's account.
|
|
895
1286
|
*/
|
|
896
|
-
async
|
|
897
|
-
const { query } = core.QueryBuilder.
|
|
898
|
-
const variables = core.QueryBuilder.
|
|
1287
|
+
async claim(id, input) {
|
|
1288
|
+
const { query } = core.QueryBuilder.claimDeck();
|
|
1289
|
+
const variables = core.QueryBuilder.deckClaimVariables(id, input);
|
|
899
1290
|
const result = await this.connection.execute(query, variables);
|
|
900
|
-
return result["
|
|
1291
|
+
return result["deckClaim"];
|
|
901
1292
|
}
|
|
902
1293
|
/**
|
|
903
|
-
*
|
|
1294
|
+
* Transfer a deck to another account.
|
|
904
1295
|
*/
|
|
905
|
-
async
|
|
906
|
-
const { query } = core.QueryBuilder.
|
|
907
|
-
const variables = core.QueryBuilder.
|
|
1296
|
+
async transferOwnership(id, input) {
|
|
1297
|
+
const { query } = core.QueryBuilder.transferDeckOwnership();
|
|
1298
|
+
const variables = core.QueryBuilder.deckTransferOwnershipVariables(id, input);
|
|
908
1299
|
const result = await this.connection.execute(query, variables);
|
|
909
|
-
return
|
|
1300
|
+
return result["deckTransferOwnership"];
|
|
910
1301
|
}
|
|
911
1302
|
/**
|
|
912
|
-
*
|
|
1303
|
+
* Copy a deck into the current principal's ownership namespace.
|
|
913
1304
|
*/
|
|
914
|
-
async
|
|
915
|
-
const { query } = core.QueryBuilder.
|
|
916
|
-
const variables = core.QueryBuilder.
|
|
1305
|
+
async copy(id, input) {
|
|
1306
|
+
const { query } = core.QueryBuilder.copyDeck();
|
|
1307
|
+
const variables = core.QueryBuilder.deckCopyVariables(id, input);
|
|
917
1308
|
const result = await this.connection.execute(query, variables);
|
|
918
|
-
return result["
|
|
1309
|
+
return result["deckCopy"];
|
|
919
1310
|
}
|
|
920
1311
|
/**
|
|
921
|
-
*
|
|
1312
|
+
* Add one entry to a deck draft.
|
|
922
1313
|
*/
|
|
923
|
-
async
|
|
924
|
-
const { query } = core.QueryBuilder.
|
|
925
|
-
const
|
|
926
|
-
|
|
1314
|
+
async addEntry(input) {
|
|
1315
|
+
const { query } = core.QueryBuilder.addDeckEntry();
|
|
1316
|
+
const variables = core.QueryBuilder.deckEntryAddVariables(input);
|
|
1317
|
+
const result = await this.connection.execute(query, variables);
|
|
1318
|
+
return result["deckEntryAdd"];
|
|
927
1319
|
}
|
|
928
1320
|
/**
|
|
929
|
-
*
|
|
1321
|
+
* Update one stable deck entry.
|
|
930
1322
|
*/
|
|
931
|
-
async
|
|
932
|
-
|
|
933
|
-
const
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
const
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1323
|
+
async updateEntry(id, input) {
|
|
1324
|
+
const { query } = core.QueryBuilder.updateDeckEntry();
|
|
1325
|
+
const variables = core.QueryBuilder.deckEntryUpdateVariables(id, input);
|
|
1326
|
+
const result = await this.connection.execute(query, variables);
|
|
1327
|
+
return result["deckEntryUpdate"];
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* Remove one stable deck entry.
|
|
1331
|
+
*/
|
|
1332
|
+
async removeEntry(id, expectedDraftRevision) {
|
|
1333
|
+
const { query } = core.QueryBuilder.removeDeckEntry();
|
|
1334
|
+
const variables = core.QueryBuilder.deckEntryRemoveVariables(id, expectedDraftRevision);
|
|
1335
|
+
const result = await this.connection.execute(query, variables);
|
|
1336
|
+
return result["deckEntryRemove"];
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Reorder deck entries within or across sections.
|
|
1340
|
+
*/
|
|
1341
|
+
async reorderEntries(deckId, input) {
|
|
1342
|
+
const { query } = core.QueryBuilder.reorderDeckEntries();
|
|
1343
|
+
const variables = core.QueryBuilder.deckEntryReorderVariables(deckId, input);
|
|
1344
|
+
const result = await this.connection.execute(query, variables);
|
|
1345
|
+
return result["deckEntryReorder"];
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Explicitly replace all deck entries for import or repair flows.
|
|
1349
|
+
*/
|
|
1350
|
+
async replaceEntries(deckId, input) {
|
|
1351
|
+
const { query } = core.QueryBuilder.replaceDeckEntries();
|
|
1352
|
+
const variables = core.QueryBuilder.deckEntriesReplaceVariables(deckId, input);
|
|
1353
|
+
const result = await this.connection.execute(query, variables);
|
|
1354
|
+
return result["deckEntriesReplace"];
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Import a decklist into an existing deck or dry-run resolution.
|
|
1358
|
+
*/
|
|
1359
|
+
async importDeck(input) {
|
|
1360
|
+
const { query } = core.QueryBuilder.importDeck();
|
|
1361
|
+
const variables = core.QueryBuilder.deckImportVariables(input);
|
|
1362
|
+
const result = await this.connection.execute(query, variables);
|
|
1363
|
+
return result["deckImport"];
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* List publisher-managed configured import formats for a game.
|
|
1367
|
+
*/
|
|
1368
|
+
async listImportFormats(gameId, options = {}) {
|
|
1369
|
+
const { query, variables } = core.QueryBuilder.deckImportFormats({
|
|
1370
|
+
gameId,
|
|
1371
|
+
includeArchived: options.includeArchived,
|
|
1372
|
+
first: options.first,
|
|
1373
|
+
after: options.after
|
|
1374
|
+
});
|
|
1375
|
+
const key = this.cacheKey("decks", "listImportFormats", variables);
|
|
1376
|
+
const data = await this.withCache(key, "decks", options, async () => {
|
|
1377
|
+
const result = await this.connection.execute(query, variables);
|
|
1378
|
+
return result["deckImportFormats"];
|
|
1379
|
+
});
|
|
1380
|
+
return new core.Collection(data, {
|
|
1381
|
+
nextPageLoader: async (cursor) => this.listImportFormats(gameId, { ...options, after: cursor })
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Fetch one configured import format by UUID.
|
|
1386
|
+
*/
|
|
1387
|
+
async fetchImportFormat(id, options = {}) {
|
|
1388
|
+
const key = this.cacheKey("decks", "fetchImportFormat", { id });
|
|
1389
|
+
return this.withCache(key, "decks", options, async () => {
|
|
1390
|
+
const { query } = core.QueryBuilder.deckImportFormat();
|
|
1391
|
+
const result = await this.connection.execute(query, { id });
|
|
1392
|
+
return result["deckImportFormat"] ?? null;
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Preview configured import-format parsing and record resolution.
|
|
1397
|
+
*/
|
|
1398
|
+
async testImportFormat(input) {
|
|
1399
|
+
const { query } = core.QueryBuilder.deckImportFormatTest();
|
|
1400
|
+
const variables = core.QueryBuilder.deckImportFormatTestVariables(input);
|
|
1401
|
+
const result = await this.connection.execute(query, variables);
|
|
1402
|
+
return result["deckImportFormatTest"];
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Create a publisher-managed configured import format.
|
|
1406
|
+
*/
|
|
1407
|
+
async createImportFormat(input) {
|
|
1408
|
+
const { query } = core.QueryBuilder.createDeckImportFormat();
|
|
1409
|
+
const variables = core.QueryBuilder.deckImportFormatCreateVariables(input);
|
|
1410
|
+
const result = await this.connection.execute(query, variables);
|
|
1411
|
+
return result["deckImportFormatCreate"];
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* Update a publisher-managed configured import format.
|
|
1415
|
+
*/
|
|
1416
|
+
async updateImportFormat(id, input) {
|
|
1417
|
+
const { query } = core.QueryBuilder.updateDeckImportFormat();
|
|
1418
|
+
const variables = core.QueryBuilder.deckImportFormatUpdateVariables(id, input);
|
|
1419
|
+
const result = await this.connection.execute(query, variables);
|
|
1420
|
+
return result["deckImportFormatUpdate"];
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* Archive a configured import format.
|
|
1424
|
+
*/
|
|
1425
|
+
async archiveImportFormat(id) {
|
|
1426
|
+
const { query } = core.QueryBuilder.archiveDeckImportFormat();
|
|
1427
|
+
const result = await this.connection.execute(query, { id });
|
|
1428
|
+
return result["deckImportFormatArchive"];
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Restore an archived configured import format.
|
|
1432
|
+
*/
|
|
1433
|
+
async unarchiveImportFormat(id) {
|
|
1434
|
+
const { query } = core.QueryBuilder.unarchiveDeckImportFormat();
|
|
1435
|
+
const result = await this.connection.execute(query, { id });
|
|
1436
|
+
return result["deckImportFormatUnarchive"];
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Delete a hosted deck.
|
|
1440
|
+
*/
|
|
1441
|
+
async delete(id) {
|
|
1442
|
+
const { query } = core.QueryBuilder.deleteDeck();
|
|
1443
|
+
const result = await this.connection.execute(query, { id });
|
|
1444
|
+
return Boolean(result["deckDelete"]);
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Recoverably hide a deck from normal owner and public lists.
|
|
1448
|
+
*/
|
|
1449
|
+
async archive(id) {
|
|
1450
|
+
const { query } = core.QueryBuilder.archiveDeck();
|
|
1451
|
+
const result = await this.connection.execute(query, { id });
|
|
1452
|
+
return result["deckArchive"];
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Restore an archived deck to draft or published state.
|
|
1456
|
+
*/
|
|
1457
|
+
async restore(id) {
|
|
1458
|
+
const { query } = core.QueryBuilder.restoreDeck();
|
|
1459
|
+
const result = await this.connection.execute(query, { id });
|
|
1460
|
+
return result["deckRestore"];
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Remove the current public published pointer while keeping version history.
|
|
1464
|
+
*/
|
|
1465
|
+
async unpublish(id) {
|
|
1466
|
+
const { query } = core.QueryBuilder.unpublishDeck();
|
|
1467
|
+
const result = await this.connection.execute(query, { id });
|
|
1468
|
+
return result["deckUnpublish"];
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Publish the current draft as an immutable deck version.
|
|
1472
|
+
*/
|
|
1473
|
+
async publish(id, input) {
|
|
1474
|
+
const { query } = core.QueryBuilder.publishDeck();
|
|
1475
|
+
const variables = core.QueryBuilder.deckPublishVariables(id, input);
|
|
1476
|
+
const result = await this.connection.execute(query, variables);
|
|
1477
|
+
return result["deckPublish"];
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Remove draft entries that fail card-reference validation.
|
|
1481
|
+
*/
|
|
1482
|
+
async removeInvalidEntries(id, input) {
|
|
1483
|
+
const { query } = core.QueryBuilder.removeInvalidDeckEntries();
|
|
1484
|
+
const variables = core.QueryBuilder.deckRemoveInvalidEntriesVariables(id, input);
|
|
1485
|
+
const result = await this.connection.execute(query, variables);
|
|
1486
|
+
return result["deckRemoveInvalidEntries"];
|
|
1487
|
+
}
|
|
1488
|
+
/**
|
|
1489
|
+
* Create or update a deck collaborator.
|
|
1490
|
+
*/
|
|
1491
|
+
async upsertCollaborator(deckId, accountId, role) {
|
|
1492
|
+
const { query } = core.QueryBuilder.upsertDeckCollaborator();
|
|
1493
|
+
const variables = core.QueryBuilder.deckCollaboratorVariables(deckId, accountId, role);
|
|
1494
|
+
const result = await this.connection.execute(query, variables);
|
|
1495
|
+
return result["deckCollaboratorUpsert"];
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Remove a deck collaborator.
|
|
1499
|
+
*/
|
|
1500
|
+
async removeCollaborator(deckId, accountId) {
|
|
1501
|
+
const { query } = core.QueryBuilder.removeDeckCollaborator();
|
|
1502
|
+
const variables = core.QueryBuilder.deckCollaboratorVariables(deckId, accountId);
|
|
1503
|
+
const result = await this.connection.execute(query, variables);
|
|
1504
|
+
return Boolean(result["deckCollaboratorRemove"]);
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Create a revocable draft preview token.
|
|
1508
|
+
*/
|
|
1509
|
+
async createPreviewToken(input) {
|
|
1510
|
+
const { query } = core.QueryBuilder.createDeckPreviewToken();
|
|
1511
|
+
const variables = core.QueryBuilder.deckPreviewTokenCreateVariables(input);
|
|
1512
|
+
const result = await this.connection.execute(query, variables);
|
|
1513
|
+
return result["deckPreviewTokenCreate"];
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Revoke a draft preview token.
|
|
1517
|
+
*/
|
|
1518
|
+
async revokePreviewToken(id) {
|
|
1519
|
+
const { query } = core.QueryBuilder.revokeDeckPreviewToken();
|
|
1520
|
+
const result = await this.connection.execute(query, { id });
|
|
1521
|
+
return Boolean(result["deckPreviewTokenRevoke"]);
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Create a revocable published embed token.
|
|
1525
|
+
*/
|
|
1526
|
+
async createEmbedToken(input) {
|
|
1527
|
+
const { query } = core.QueryBuilder.createDeckEmbedToken();
|
|
1528
|
+
const variables = core.QueryBuilder.deckEmbedTokenCreateVariables(input);
|
|
1529
|
+
const result = await this.connection.execute(query, variables);
|
|
1530
|
+
return result["deckEmbedTokenCreate"];
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* Revoke a published embed token.
|
|
1534
|
+
*/
|
|
1535
|
+
async revokeEmbedToken(id) {
|
|
1536
|
+
const { query } = core.QueryBuilder.revokeDeckEmbedToken();
|
|
1537
|
+
const result = await this.connection.execute(query, { id });
|
|
1538
|
+
return Boolean(result["deckEmbedTokenRevoke"]);
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Trust the current API application to exchange short-lived deck access tokens.
|
|
1542
|
+
*/
|
|
1543
|
+
async createAccessTokenIssuer(input) {
|
|
1544
|
+
const { query } = core.QueryBuilder.createDeckAccessTokenIssuer();
|
|
1545
|
+
const variables = core.QueryBuilder.deckAccessTokenIssuerCreateVariables(input);
|
|
1546
|
+
const result = await this.connection.execute(query, variables);
|
|
1547
|
+
return result["deckAccessTokenIssuerCreate"];
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Revoke a trusted deck access token issuer.
|
|
1551
|
+
*/
|
|
1552
|
+
async revokeAccessTokenIssuer(id) {
|
|
1553
|
+
const { query } = core.QueryBuilder.revokeDeckAccessTokenIssuer();
|
|
1554
|
+
const result = await this.connection.execute(query, { id });
|
|
1555
|
+
return Boolean(result["deckAccessTokenIssuerRevoke"]);
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Revoke only the direct signing key for a trusted deck access token issuer.
|
|
1559
|
+
*/
|
|
1560
|
+
async revokeAccessTokenIssuerSigningKey(id) {
|
|
1561
|
+
const { query } = core.QueryBuilder.revokeDeckAccessTokenIssuerSigningKey();
|
|
1562
|
+
const result = await this.connection.execute(query, { id });
|
|
1563
|
+
return result["deckAccessTokenIssuerSigningKeyRevoke"];
|
|
1564
|
+
}
|
|
1565
|
+
/**
|
|
1566
|
+
* Grant or update one OAuth app's selected-deck access.
|
|
1567
|
+
*/
|
|
1568
|
+
async grantApiApplicationAccess(input) {
|
|
1569
|
+
const { query } = core.QueryBuilder.grantDeckApiApplicationAccess();
|
|
1570
|
+
const variables = core.QueryBuilder.deckApiApplicationAccessGrantVariables(input);
|
|
1571
|
+
const result = await this.connection.execute(query, variables);
|
|
1572
|
+
return result["deckApiApplicationAccessGrant"];
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Revoke one OAuth app's selected-deck access.
|
|
1576
|
+
*/
|
|
1577
|
+
async revokeApiApplicationAccess(deckId, apiApplicationId) {
|
|
1578
|
+
const { query } = core.QueryBuilder.revokeDeckApiApplicationAccess();
|
|
1579
|
+
const variables = core.QueryBuilder.deckApiApplicationAccessRevokeVariables(deckId, apiApplicationId);
|
|
1580
|
+
const result = await this.connection.execute(query, variables);
|
|
1581
|
+
return Boolean(result["deckApiApplicationAccessRevoke"]);
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* Exchange the current trusted API application credential for a deck access token.
|
|
1585
|
+
*/
|
|
1586
|
+
async exchangeAccessToken(input) {
|
|
1587
|
+
this.config.requireSecretCredential("decks.exchangeAccessToken");
|
|
1588
|
+
const { query } = core.QueryBuilder.exchangeDeckAccessToken();
|
|
1589
|
+
const variables = core.QueryBuilder.deckAccessTokenExchangeVariables(input);
|
|
1590
|
+
const result = await this.connection.execute(query, variables);
|
|
1591
|
+
return result["deckAccessTokenExchange"];
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* Revoke an exchanged deck access token.
|
|
1595
|
+
*/
|
|
1596
|
+
async revokeAccessToken(id) {
|
|
1597
|
+
this.config.requireSecretCredential("decks.revokeAccessToken");
|
|
1598
|
+
const { query } = core.QueryBuilder.revokeDeckAccessToken();
|
|
1599
|
+
const result = await this.connection.execute(query, { id });
|
|
1600
|
+
return Boolean(result["deckAccessTokenRevoke"]);
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Hydrate third-party-owned deck entries without storing them in CardDB.
|
|
1604
|
+
*/
|
|
1605
|
+
async hydrateEntries(options) {
|
|
1606
|
+
if (options.entries.length === 0) return [];
|
|
1607
|
+
const publisherSlug = this.resolvePublisher(options.publisherSlug);
|
|
1608
|
+
const gameKey = this.resolveGame(options.gameKey);
|
|
1609
|
+
this.validateAccess(publisherSlug, gameKey);
|
|
1610
|
+
const identifiers = options.entries.map((entry) => entry.identifier);
|
|
1611
|
+
const key = this.cacheKey("decks", "hydrateEntries", {
|
|
1612
|
+
publisherSlug,
|
|
1613
|
+
gameKey,
|
|
1614
|
+
datasetKey: options.datasetKey,
|
|
1615
|
+
identifiers
|
|
1616
|
+
});
|
|
1617
|
+
const records = await this.withCache(key, "decks", options, async () => {
|
|
1618
|
+
const { query } = core.QueryBuilder.fetchRecordsByIdentifier();
|
|
1619
|
+
const result = await this.connection.execute(query, {
|
|
1620
|
+
publisherSlug,
|
|
1621
|
+
gameKey,
|
|
1622
|
+
datasetKey: options.datasetKey,
|
|
1623
|
+
identifiers
|
|
1624
|
+
});
|
|
1625
|
+
return result["fetchRecordsByIdentifier"];
|
|
1626
|
+
});
|
|
1627
|
+
const recordsByIdentifier = recordsByDeckIdentifier(
|
|
1628
|
+
records,
|
|
1629
|
+
identifiers,
|
|
1630
|
+
options.identifierField
|
|
1631
|
+
);
|
|
1632
|
+
return options.entries.map((entry) => ({
|
|
1633
|
+
...entry,
|
|
1634
|
+
record: recordsByIdentifier.get(entry.identifier) ?? null
|
|
1635
|
+
}));
|
|
962
1636
|
}
|
|
963
1637
|
};
|
|
964
1638
|
function recordsByDeckIdentifier(records, identifiers, identifierField) {
|
|
@@ -978,6 +1652,121 @@ var RecordsResource = class extends BaseResource {
|
|
|
978
1652
|
constructor(connection, config) {
|
|
979
1653
|
super(connection, config);
|
|
980
1654
|
}
|
|
1655
|
+
/**
|
|
1656
|
+
* List records in a publisher-accessible dataset by dataset ID.
|
|
1657
|
+
*/
|
|
1658
|
+
async list(options) {
|
|
1659
|
+
const filter = core.resolveFilter(options.filter);
|
|
1660
|
+
const { query, variables } = core.QueryBuilder.listDatasetRecords({
|
|
1661
|
+
datasetId: options.datasetId,
|
|
1662
|
+
filter,
|
|
1663
|
+
orderBy: options.orderBy,
|
|
1664
|
+
first: options.first,
|
|
1665
|
+
after: options.after,
|
|
1666
|
+
last: options.last,
|
|
1667
|
+
before: options.before,
|
|
1668
|
+
validateSchema: options.validateSchema
|
|
1669
|
+
});
|
|
1670
|
+
const key = this.cacheKey("records", "list", variables);
|
|
1671
|
+
const data = await this.withCache(key, "records", options, async () => {
|
|
1672
|
+
const result = await this.connection.execute(query, variables);
|
|
1673
|
+
return result["datasetRecords"];
|
|
1674
|
+
});
|
|
1675
|
+
return new core.Collection(data, {
|
|
1676
|
+
nextPageLoader: async (cursor) => this.list({ ...options, after: cursor })
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
/**
|
|
1680
|
+
* Get a publisher-accessible record by dataset ID and identifier value.
|
|
1681
|
+
*/
|
|
1682
|
+
async getByDatasetIdentifier(options) {
|
|
1683
|
+
const key = this.cacheKey("records", "getByDatasetIdentifier", {
|
|
1684
|
+
datasetId: options.datasetId,
|
|
1685
|
+
identifier: options.identifier,
|
|
1686
|
+
includePricing: options.includePricing ?? false
|
|
1687
|
+
});
|
|
1688
|
+
return this.withCache(key, "records", options, async () => {
|
|
1689
|
+
const { query, variables } = core.QueryBuilder.datasetRecord({
|
|
1690
|
+
datasetId: options.datasetId,
|
|
1691
|
+
identifier: options.identifier,
|
|
1692
|
+
includePricing: options.includePricing
|
|
1693
|
+
});
|
|
1694
|
+
const result = await this.connection.execute(query, variables);
|
|
1695
|
+
return result["datasetRecord"] ?? null;
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
/**
|
|
1699
|
+
* Start an import-backed batch upsert, or return a dry-run result. Requires a secret credential.
|
|
1700
|
+
*/
|
|
1701
|
+
async upsertBatch(input) {
|
|
1702
|
+
this.config.requireSecretCredential("records.upsertBatch");
|
|
1703
|
+
const { query } = core.QueryBuilder.upsertDatasetRecords();
|
|
1704
|
+
const result = await this.connection.execute(
|
|
1705
|
+
query,
|
|
1706
|
+
core.QueryBuilder.datasetRecordsUpsertVariables(input)
|
|
1707
|
+
);
|
|
1708
|
+
return result["datasetRecordsUpsert"];
|
|
1709
|
+
}
|
|
1710
|
+
/**
|
|
1711
|
+
* Create a dry-run or destructive bulk delete/reconciliation job. Requires a secret credential.
|
|
1712
|
+
*/
|
|
1713
|
+
async deleteBatch(input) {
|
|
1714
|
+
this.config.requireSecretCredential("records.deleteBatch");
|
|
1715
|
+
const { query } = core.QueryBuilder.deleteDatasetRecords();
|
|
1716
|
+
const result = await this.connection.execute(
|
|
1717
|
+
query,
|
|
1718
|
+
core.QueryBuilder.datasetRecordsDeleteVariables(input)
|
|
1719
|
+
);
|
|
1720
|
+
return result["datasetRecordsDelete"];
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Get one bulk delete/reconciliation job.
|
|
1724
|
+
*/
|
|
1725
|
+
async getDeleteJob(id, options = {}) {
|
|
1726
|
+
const key = this.cacheKey("records", "getDeleteJob", { id });
|
|
1727
|
+
return this.withCache(key, "records", options, async () => {
|
|
1728
|
+
const { query } = core.QueryBuilder.datasetRecordDeleteJob();
|
|
1729
|
+
const result = await this.connection.execute(query, { id });
|
|
1730
|
+
return result["datasetRecordDeleteJob"] ?? null;
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* List bulk delete/reconciliation jobs for a publisher.
|
|
1735
|
+
*/
|
|
1736
|
+
async listDeleteJobs(publisherId, options = {}) {
|
|
1737
|
+
const { query, variables } = core.QueryBuilder.datasetRecordDeleteJobs({
|
|
1738
|
+
publisherId,
|
|
1739
|
+
datasetId: options.datasetId,
|
|
1740
|
+
status: options.status,
|
|
1741
|
+
first: options.first,
|
|
1742
|
+
after: options.after
|
|
1743
|
+
});
|
|
1744
|
+
const key = this.cacheKey("records", "listDeleteJobs", variables);
|
|
1745
|
+
const data = await this.withCache(key, "records", options, async () => {
|
|
1746
|
+
const result = await this.connection.execute(query, variables);
|
|
1747
|
+
return result["datasetRecordDeleteJobs"];
|
|
1748
|
+
});
|
|
1749
|
+
return new core.Collection(data, {
|
|
1750
|
+
nextPageLoader: async (cursor) => this.listDeleteJobs(publisherId, { ...options, after: cursor })
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Poll a delete job until it reaches a terminal state.
|
|
1755
|
+
*/
|
|
1756
|
+
async waitForDeleteJob(id, options = {}) {
|
|
1757
|
+
const intervalMs = options.intervalMs ?? 1e3;
|
|
1758
|
+
const timeoutMs = options.timeoutMs ?? 3e5;
|
|
1759
|
+
const startedAt = Date.now();
|
|
1760
|
+
while (true) {
|
|
1761
|
+
const job = await this.getDeleteJob(id, { cache: false });
|
|
1762
|
+
if (!job) throw new Error(`Delete job '${id}' was not found`);
|
|
1763
|
+
if (job.status === "COMPLETED" || job.status === "FAILED") return job;
|
|
1764
|
+
if (Date.now() - startedAt >= timeoutMs) {
|
|
1765
|
+
throw new Error(`Timed out waiting for delete job '${id}'`);
|
|
1766
|
+
}
|
|
1767
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
981
1770
|
/**
|
|
982
1771
|
* Search for records in a dataset with filtering, search, and pagination
|
|
983
1772
|
*
|
|
@@ -1259,6 +2048,482 @@ var RulesResource = class extends BaseResource {
|
|
|
1259
2048
|
});
|
|
1260
2049
|
}
|
|
1261
2050
|
};
|
|
2051
|
+
var ImportFormatsResource = class extends BaseResource {
|
|
2052
|
+
constructor(connection, config) {
|
|
2053
|
+
super(connection, config);
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* List publisher-managed import formats by publisher or game scope.
|
|
2057
|
+
*/
|
|
2058
|
+
async list(options) {
|
|
2059
|
+
const { query, variables } = core.QueryBuilder.deckImportFormats({
|
|
2060
|
+
publisherId: options.publisherId,
|
|
2061
|
+
gameId: options.gameId,
|
|
2062
|
+
includeArchived: options.includeArchived,
|
|
2063
|
+
first: options.first,
|
|
2064
|
+
after: options.after
|
|
2065
|
+
});
|
|
2066
|
+
const key = this.cacheKey("importFormats", "list", variables);
|
|
2067
|
+
const data = await this.withCache(key, "importFormats", options, async () => {
|
|
2068
|
+
const result = await this.connection.execute(query, variables);
|
|
2069
|
+
return result["deckImportFormats"];
|
|
2070
|
+
});
|
|
2071
|
+
return new core.Collection(data, {
|
|
2072
|
+
nextPageLoader: async (cursor) => this.list({ ...options, after: cursor })
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Get one import format by UUID.
|
|
2077
|
+
*/
|
|
2078
|
+
async get(id, options = {}) {
|
|
2079
|
+
const key = this.cacheKey("importFormats", "get", { id });
|
|
2080
|
+
return this.withCache(key, "importFormats", options, async () => {
|
|
2081
|
+
const { query } = core.QueryBuilder.deckImportFormat();
|
|
2082
|
+
const result = await this.connection.execute(query, { id });
|
|
2083
|
+
return result["deckImportFormat"] ?? null;
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
/**
|
|
2087
|
+
* Get one import format by game ID and stable key.
|
|
2088
|
+
*/
|
|
2089
|
+
async getByKey(options) {
|
|
2090
|
+
const key = this.cacheKey("importFormats", "getByKey", {
|
|
2091
|
+
gameId: options.gameId,
|
|
2092
|
+
formatKey: options.key
|
|
2093
|
+
});
|
|
2094
|
+
return this.withCache(key, "importFormats", options, async () => {
|
|
2095
|
+
const { query } = core.QueryBuilder.deckImportFormat();
|
|
2096
|
+
const result = await this.connection.execute(query, {
|
|
2097
|
+
gameId: options.gameId,
|
|
2098
|
+
key: options.key
|
|
2099
|
+
});
|
|
2100
|
+
return result["deckImportFormat"] ?? null;
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Preview parsing and record resolution for a configured import format.
|
|
2105
|
+
*/
|
|
2106
|
+
async test(input) {
|
|
2107
|
+
const { query } = core.QueryBuilder.deckImportFormatTest();
|
|
2108
|
+
const result = await this.connection.execute(
|
|
2109
|
+
query,
|
|
2110
|
+
core.QueryBuilder.deckImportFormatTestVariables(input)
|
|
2111
|
+
);
|
|
2112
|
+
return result["deckImportFormatTest"];
|
|
2113
|
+
}
|
|
2114
|
+
/**
|
|
2115
|
+
* Create an import format. Requires a server-side secret credential.
|
|
2116
|
+
*/
|
|
2117
|
+
async create(input) {
|
|
2118
|
+
this.config.requireSecretCredential("importFormats.create");
|
|
2119
|
+
const { query } = core.QueryBuilder.createDeckImportFormat();
|
|
2120
|
+
const result = await this.connection.execute(
|
|
2121
|
+
query,
|
|
2122
|
+
core.QueryBuilder.deckImportFormatCreateVariables(input)
|
|
2123
|
+
);
|
|
2124
|
+
return result["deckImportFormatCreate"];
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* Update an import format. Requires a server-side secret credential.
|
|
2128
|
+
*/
|
|
2129
|
+
async update(id, input) {
|
|
2130
|
+
this.config.requireSecretCredential("importFormats.update");
|
|
2131
|
+
const { query } = core.QueryBuilder.updateDeckImportFormat();
|
|
2132
|
+
const result = await this.connection.execute(
|
|
2133
|
+
query,
|
|
2134
|
+
core.QueryBuilder.deckImportFormatUpdateVariables(id, input)
|
|
2135
|
+
);
|
|
2136
|
+
return result["deckImportFormatUpdate"];
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Archive an import format. Requires a server-side secret credential.
|
|
2140
|
+
*/
|
|
2141
|
+
async archive(id) {
|
|
2142
|
+
this.config.requireSecretCredential("importFormats.archive");
|
|
2143
|
+
const { query } = core.QueryBuilder.archiveDeckImportFormat();
|
|
2144
|
+
const result = await this.connection.execute(query, { id });
|
|
2145
|
+
return result["deckImportFormatArchive"];
|
|
2146
|
+
}
|
|
2147
|
+
/**
|
|
2148
|
+
* Restore an archived import format. Requires a server-side secret credential.
|
|
2149
|
+
*/
|
|
2150
|
+
async unarchive(id) {
|
|
2151
|
+
this.config.requireSecretCredential("importFormats.unarchive");
|
|
2152
|
+
const { query } = core.QueryBuilder.unarchiveDeckImportFormat();
|
|
2153
|
+
const result = await this.connection.execute(query, { id });
|
|
2154
|
+
return result["deckImportFormatUnarchive"];
|
|
2155
|
+
}
|
|
2156
|
+
};
|
|
2157
|
+
var ImportsResource = class extends BaseResource {
|
|
2158
|
+
constructor(connection, config) {
|
|
2159
|
+
super(connection, config);
|
|
2160
|
+
}
|
|
2161
|
+
/**
|
|
2162
|
+
* Preview a single-dataset import source without writing records or schema.
|
|
2163
|
+
*/
|
|
2164
|
+
async preview(input) {
|
|
2165
|
+
const { query } = core.QueryBuilder.datasetImportPreview();
|
|
2166
|
+
const result = await this.connection.execute(
|
|
2167
|
+
query,
|
|
2168
|
+
core.QueryBuilder.datasetImportPreviewVariables(input)
|
|
2169
|
+
);
|
|
2170
|
+
return result["datasetImportPreview"];
|
|
2171
|
+
}
|
|
2172
|
+
/**
|
|
2173
|
+
* Validate a single-dataset import source with dry-run enforced.
|
|
2174
|
+
*/
|
|
2175
|
+
async validate(input) {
|
|
2176
|
+
const { query } = core.QueryBuilder.datasetImportValidate();
|
|
2177
|
+
const result = await this.connection.execute(
|
|
2178
|
+
query,
|
|
2179
|
+
core.QueryBuilder.datasetImportValidateVariables(input)
|
|
2180
|
+
);
|
|
2181
|
+
return result["datasetImportValidate"];
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Start an async single-dataset import from `fileId`, `data`, or `sourceUrl`.
|
|
2185
|
+
*/
|
|
2186
|
+
async run(input) {
|
|
2187
|
+
this.config.requireSecretCredential("imports.run");
|
|
2188
|
+
if ("fileId" in input && input.fileId) {
|
|
2189
|
+
const { query: query2 } = core.QueryBuilder.datasetImportFromFile();
|
|
2190
|
+
const result2 = await this.connection.execute(
|
|
2191
|
+
query2,
|
|
2192
|
+
core.QueryBuilder.datasetImportFromFileVariables(input)
|
|
2193
|
+
);
|
|
2194
|
+
return result2["datasetImportFromFile"];
|
|
2195
|
+
}
|
|
2196
|
+
if ("sourceUrl" in input && input.sourceUrl) {
|
|
2197
|
+
const { query: query2 } = core.QueryBuilder.datasetImportFromUrl();
|
|
2198
|
+
const result2 = await this.connection.execute(
|
|
2199
|
+
query2,
|
|
2200
|
+
core.QueryBuilder.datasetImportFromUrlVariables(input)
|
|
2201
|
+
);
|
|
2202
|
+
return result2["datasetImportFromUrl"];
|
|
2203
|
+
}
|
|
2204
|
+
const { query } = core.QueryBuilder.datasetImportFromPayload();
|
|
2205
|
+
const result = await this.connection.execute(
|
|
2206
|
+
query,
|
|
2207
|
+
core.QueryBuilder.datasetImportFromPayloadVariables(input)
|
|
2208
|
+
);
|
|
2209
|
+
return result["datasetImportFromPayload"];
|
|
2210
|
+
}
|
|
2211
|
+
/**
|
|
2212
|
+
* Fetch one single-dataset import job.
|
|
2213
|
+
*/
|
|
2214
|
+
async getJob(id, options = {}) {
|
|
2215
|
+
const key = this.cacheKey("imports", "getJob", { id });
|
|
2216
|
+
return this.withCache(key, "imports", options, async () => {
|
|
2217
|
+
const { query } = core.QueryBuilder.importJob();
|
|
2218
|
+
const result = await this.connection.execute(query, { id });
|
|
2219
|
+
return result["importJob"] ?? null;
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* List single-dataset import jobs for a publisher.
|
|
2224
|
+
*/
|
|
2225
|
+
async listJobs(publisherId, options = {}) {
|
|
2226
|
+
const { query, variables } = core.QueryBuilder.importJobs({
|
|
2227
|
+
publisherId,
|
|
2228
|
+
datasetId: options.datasetId,
|
|
2229
|
+
status: options.status,
|
|
2230
|
+
first: options.first,
|
|
2231
|
+
after: options.after
|
|
2232
|
+
});
|
|
2233
|
+
const key = this.cacheKey("imports", "listJobs", variables);
|
|
2234
|
+
const data = await this.withCache(key, "imports", options, async () => {
|
|
2235
|
+
const result = await this.connection.execute(query, variables);
|
|
2236
|
+
return result["importJobs"];
|
|
2237
|
+
});
|
|
2238
|
+
return new core.Collection(data, {
|
|
2239
|
+
nextPageLoader: async (cursor) => this.listJobs(publisherId, { ...options, after: cursor })
|
|
2240
|
+
});
|
|
2241
|
+
}
|
|
2242
|
+
/**
|
|
2243
|
+
* Cancel a pending or processing single-dataset import job.
|
|
2244
|
+
*/
|
|
2245
|
+
async cancelJob(id) {
|
|
2246
|
+
this.config.requireSecretCredential("imports.cancelJob");
|
|
2247
|
+
const { query } = core.QueryBuilder.importJobCancel();
|
|
2248
|
+
const result = await this.connection.execute(query, { id });
|
|
2249
|
+
return result["importJobCancel"];
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* List structured logs for one single-dataset import job.
|
|
2253
|
+
*/
|
|
2254
|
+
async listJobLogs(importJobId, options = {}) {
|
|
2255
|
+
const { query, variables } = core.QueryBuilder.importJobLogs({
|
|
2256
|
+
importJobId,
|
|
2257
|
+
level: options.level,
|
|
2258
|
+
datasetKey: options.datasetKey,
|
|
2259
|
+
first: options.first,
|
|
2260
|
+
after: options.after
|
|
2261
|
+
});
|
|
2262
|
+
const key = this.cacheKey("imports", "listJobLogs", variables);
|
|
2263
|
+
const data = await this.withCache(key, "imports", options, async () => {
|
|
2264
|
+
const result = await this.connection.execute(query, variables);
|
|
2265
|
+
const job = result["importJob"];
|
|
2266
|
+
return job?.logs ?? emptyConnection();
|
|
2267
|
+
});
|
|
2268
|
+
return new core.Collection(data, {
|
|
2269
|
+
nextPageLoader: async (cursor) => this.listJobLogs(importJobId, { ...options, after: cursor })
|
|
2270
|
+
});
|
|
2271
|
+
}
|
|
2272
|
+
/**
|
|
2273
|
+
* Poll a single-dataset import job until completion or failure.
|
|
2274
|
+
*/
|
|
2275
|
+
async waitForJob(id, options = {}) {
|
|
2276
|
+
const intervalMs = options.intervalMs ?? 1e3;
|
|
2277
|
+
const timeoutMs = options.timeoutMs ?? 3e5;
|
|
2278
|
+
const startedAt = Date.now();
|
|
2279
|
+
while (true) {
|
|
2280
|
+
const job = await this.getJob(id, { cache: false });
|
|
2281
|
+
if (!job) throw new Error(`Import job '${id}' was not found`);
|
|
2282
|
+
if (job.status === "COMPLETED" || job.status === "FAILED") return job;
|
|
2283
|
+
if (Date.now() - startedAt >= timeoutMs) {
|
|
2284
|
+
throw new Error(`Timed out waiting for import job '${id}'`);
|
|
2285
|
+
}
|
|
2286
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
/**
|
|
2290
|
+
* Preview an advanced game-level import source without writing records or schema.
|
|
2291
|
+
*/
|
|
2292
|
+
async previewGame(input) {
|
|
2293
|
+
const { query } = core.QueryBuilder.gameImportPreview();
|
|
2294
|
+
const result = await this.connection.execute(
|
|
2295
|
+
query,
|
|
2296
|
+
core.QueryBuilder.gameImportPreviewVariables(input)
|
|
2297
|
+
);
|
|
2298
|
+
return result["gameImportPreview"];
|
|
2299
|
+
}
|
|
2300
|
+
/**
|
|
2301
|
+
* Start an async advanced game-level import from `fileId`, `data`, or `sourceUrl`.
|
|
2302
|
+
*/
|
|
2303
|
+
async runGame(input) {
|
|
2304
|
+
this.config.requireSecretCredential("imports.runGame");
|
|
2305
|
+
if ("fileId" in input && input.fileId) {
|
|
2306
|
+
const { query: query2 } = core.QueryBuilder.gameImportFromFile();
|
|
2307
|
+
const result2 = await this.connection.execute(
|
|
2308
|
+
query2,
|
|
2309
|
+
core.QueryBuilder.gameImportFromFileVariables(input)
|
|
2310
|
+
);
|
|
2311
|
+
return result2["gameImportFromFile"];
|
|
2312
|
+
}
|
|
2313
|
+
if ("sourceUrl" in input && input.sourceUrl) {
|
|
2314
|
+
const { query: query2 } = core.QueryBuilder.gameImportFromUrl();
|
|
2315
|
+
const result2 = await this.connection.execute(
|
|
2316
|
+
query2,
|
|
2317
|
+
core.QueryBuilder.gameImportFromUrlVariables(input)
|
|
2318
|
+
);
|
|
2319
|
+
return result2["gameImportFromUrl"];
|
|
2320
|
+
}
|
|
2321
|
+
const { query } = core.QueryBuilder.gameImportFromPayload();
|
|
2322
|
+
const result = await this.connection.execute(
|
|
2323
|
+
query,
|
|
2324
|
+
core.QueryBuilder.gameImportFromPayloadVariables(input)
|
|
2325
|
+
);
|
|
2326
|
+
return result["gameImportFromPayload"];
|
|
2327
|
+
}
|
|
2328
|
+
/**
|
|
2329
|
+
* Fetch one advanced game-level import job.
|
|
2330
|
+
*/
|
|
2331
|
+
async getGameJob(id, options = {}) {
|
|
2332
|
+
const key = this.cacheKey("imports", "getGameJob", { id });
|
|
2333
|
+
return this.withCache(key, "imports", options, async () => {
|
|
2334
|
+
const { query } = core.QueryBuilder.gameImportJob();
|
|
2335
|
+
const result = await this.connection.execute(query, { id });
|
|
2336
|
+
return result["gameImportJob"] ?? null;
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2339
|
+
/**
|
|
2340
|
+
* List advanced game-level import jobs.
|
|
2341
|
+
*/
|
|
2342
|
+
async listGameJobs(gameId, options = {}) {
|
|
2343
|
+
const { query, variables } = core.QueryBuilder.gameImportJobs({
|
|
2344
|
+
gameId,
|
|
2345
|
+
status: options.status,
|
|
2346
|
+
first: options.first,
|
|
2347
|
+
after: options.after
|
|
2348
|
+
});
|
|
2349
|
+
const key = this.cacheKey("imports", "listGameJobs", variables);
|
|
2350
|
+
const data = await this.withCache(key, "imports", options, async () => {
|
|
2351
|
+
const result = await this.connection.execute(query, variables);
|
|
2352
|
+
return result["gameImportJobs"];
|
|
2353
|
+
});
|
|
2354
|
+
return new core.Collection(data, {
|
|
2355
|
+
nextPageLoader: async (cursor) => this.listGameJobs(gameId, { ...options, after: cursor })
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Cancel a pending or processing advanced game-level import job.
|
|
2360
|
+
*/
|
|
2361
|
+
async cancelGameJob(id) {
|
|
2362
|
+
this.config.requireSecretCredential("imports.cancelGameJob");
|
|
2363
|
+
const { query } = core.QueryBuilder.gameImportJobCancel();
|
|
2364
|
+
const result = await this.connection.execute(query, { id });
|
|
2365
|
+
return result["gameImportJobCancel"];
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Poll an advanced game-level import job until completion or failure.
|
|
2369
|
+
*/
|
|
2370
|
+
async waitForGameJob(id, options = {}) {
|
|
2371
|
+
const intervalMs = options.intervalMs ?? 1e3;
|
|
2372
|
+
const timeoutMs = options.timeoutMs ?? 3e5;
|
|
2373
|
+
const startedAt = Date.now();
|
|
2374
|
+
while (true) {
|
|
2375
|
+
const job = await this.getGameJob(id, { cache: false });
|
|
2376
|
+
if (!job) throw new Error(`Game import job '${id}' was not found`);
|
|
2377
|
+
if (job.status === "COMPLETED" || job.status === "FAILED") return job;
|
|
2378
|
+
if (Date.now() - startedAt >= timeoutMs) {
|
|
2379
|
+
throw new Error(`Timed out waiting for game import job '${id}'`);
|
|
2380
|
+
}
|
|
2381
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
};
|
|
2385
|
+
function emptyConnection() {
|
|
2386
|
+
return {
|
|
2387
|
+
totalCount: 0,
|
|
2388
|
+
pageInfo: {
|
|
2389
|
+
hasNextPage: false,
|
|
2390
|
+
hasPreviousPage: false,
|
|
2391
|
+
startCursor: null,
|
|
2392
|
+
endCursor: null
|
|
2393
|
+
},
|
|
2394
|
+
edges: []
|
|
2395
|
+
};
|
|
2396
|
+
}
|
|
2397
|
+
var ExportsResource = class extends BaseResource {
|
|
2398
|
+
constructor(connection, config) {
|
|
2399
|
+
super(connection, config);
|
|
2400
|
+
}
|
|
2401
|
+
/**
|
|
2402
|
+
* Start an async dataset export. Requires a server-side secret credential.
|
|
2403
|
+
*/
|
|
2404
|
+
async run(input) {
|
|
2405
|
+
this.config.requireSecretCredential("exports.run");
|
|
2406
|
+
const { query } = core.QueryBuilder.datasetExport();
|
|
2407
|
+
const result = await this.connection.execute(query, core.QueryBuilder.datasetExportVariables(input));
|
|
2408
|
+
return result["datasetExport"];
|
|
2409
|
+
}
|
|
2410
|
+
/** Alias for `run`. */
|
|
2411
|
+
async create(input) {
|
|
2412
|
+
return this.run(input);
|
|
2413
|
+
}
|
|
2414
|
+
/**
|
|
2415
|
+
* Fetch one export job.
|
|
2416
|
+
*/
|
|
2417
|
+
async getJob(id, options = {}) {
|
|
2418
|
+
const key = this.cacheKey("exports", "getJob", { id });
|
|
2419
|
+
return this.withCache(key, "exports", options, async () => {
|
|
2420
|
+
const { query } = core.QueryBuilder.exportJob();
|
|
2421
|
+
const result = await this.connection.execute(query, { id });
|
|
2422
|
+
return result["exportJob"] ?? null;
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* List export jobs for a publisher, optionally filtered by game, dataset, or status.
|
|
2427
|
+
*/
|
|
2428
|
+
async listJobs(publisherId, options = {}) {
|
|
2429
|
+
const { query, variables } = core.QueryBuilder.exportJobs({
|
|
2430
|
+
publisherId,
|
|
2431
|
+
gameId: options.gameId,
|
|
2432
|
+
datasetId: options.datasetId,
|
|
2433
|
+
status: options.status,
|
|
2434
|
+
first: options.first,
|
|
2435
|
+
after: options.after
|
|
2436
|
+
});
|
|
2437
|
+
const key = this.cacheKey("exports", "listJobs", variables);
|
|
2438
|
+
const data = await this.withCache(key, "exports", options, async () => {
|
|
2439
|
+
const result = await this.connection.execute(query, variables);
|
|
2440
|
+
return result["exportJobs"];
|
|
2441
|
+
});
|
|
2442
|
+
return new core.Collection(data, {
|
|
2443
|
+
nextPageLoader: async (cursor) => this.listJobs(publisherId, { ...options, after: cursor })
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
/**
|
|
2447
|
+
* Refresh the signed download URL for a completed export job.
|
|
2448
|
+
*/
|
|
2449
|
+
async refreshUrl(id) {
|
|
2450
|
+
const { query } = core.QueryBuilder.exportJobRefreshUrl();
|
|
2451
|
+
const result = await this.connection.execute(query, { id });
|
|
2452
|
+
return result["exportJobRefreshUrl"];
|
|
2453
|
+
}
|
|
2454
|
+
/**
|
|
2455
|
+
* Cancel a pending or processing export job. Requires a server-side secret credential.
|
|
2456
|
+
*/
|
|
2457
|
+
async cancel(id) {
|
|
2458
|
+
this.config.requireSecretCredential("exports.cancel");
|
|
2459
|
+
const { query } = core.QueryBuilder.exportJobCancel();
|
|
2460
|
+
const result = await this.connection.execute(query, { id });
|
|
2461
|
+
return result["exportJobCancel"];
|
|
2462
|
+
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Poll an export job until completion or failure.
|
|
2465
|
+
*/
|
|
2466
|
+
async waitForJob(id, options = {}) {
|
|
2467
|
+
const intervalMs = options.intervalMs ?? 1e3;
|
|
2468
|
+
const timeoutMs = options.timeoutMs ?? 3e5;
|
|
2469
|
+
const startedAt = Date.now();
|
|
2470
|
+
while (true) {
|
|
2471
|
+
const job = await this.getJob(id, { cache: false });
|
|
2472
|
+
if (!job) throw new Error(`Export job '${id}' was not found`);
|
|
2473
|
+
if (job.status === "COMPLETED" || job.status === "FAILED") return job;
|
|
2474
|
+
if (Date.now() - startedAt >= timeoutMs) {
|
|
2475
|
+
throw new Error(`Timed out waiting for export job '${id}'`);
|
|
2476
|
+
}
|
|
2477
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
};
|
|
2481
|
+
var FilesResource = class extends BaseResource {
|
|
2482
|
+
constructor(connection, config) {
|
|
2483
|
+
super(connection, config);
|
|
2484
|
+
}
|
|
2485
|
+
/**
|
|
2486
|
+
* Get one file by ID.
|
|
2487
|
+
*/
|
|
2488
|
+
async get(id, options = {}) {
|
|
2489
|
+
const key = this.cacheKey("files", "get", { id });
|
|
2490
|
+
return this.withCache(key, "files", options, async () => {
|
|
2491
|
+
const { query } = core.QueryBuilder.file();
|
|
2492
|
+
const result = await this.connection.execute(query, { id });
|
|
2493
|
+
return result["file"] ?? null;
|
|
2494
|
+
});
|
|
2495
|
+
}
|
|
2496
|
+
/**
|
|
2497
|
+
* Request a presigned URL for direct upload. Requires a server-side secret credential.
|
|
2498
|
+
*/
|
|
2499
|
+
async requestUpload(input) {
|
|
2500
|
+
this.config.requireSecretCredential("files.requestUpload");
|
|
2501
|
+
const { query } = core.QueryBuilder.fileUploadRequest();
|
|
2502
|
+
const result = await this.connection.execute(
|
|
2503
|
+
query,
|
|
2504
|
+
core.QueryBuilder.fileUploadRequestVariables(input)
|
|
2505
|
+
);
|
|
2506
|
+
return result["fileUploadRequest"];
|
|
2507
|
+
}
|
|
2508
|
+
/**
|
|
2509
|
+
* Confirm that a presigned upload completed.
|
|
2510
|
+
*/
|
|
2511
|
+
async confirmUpload(id) {
|
|
2512
|
+
this.config.requireSecretCredential("files.confirmUpload");
|
|
2513
|
+
const { query } = core.QueryBuilder.fileUploadConfirm();
|
|
2514
|
+
const result = await this.connection.execute(query, { id });
|
|
2515
|
+
return result["fileUploadConfirm"];
|
|
2516
|
+
}
|
|
2517
|
+
/**
|
|
2518
|
+
* Delete a file. Requires a server-side secret credential.
|
|
2519
|
+
*/
|
|
2520
|
+
async delete(id) {
|
|
2521
|
+
this.config.requireSecretCredential("files.delete");
|
|
2522
|
+
const { query } = core.QueryBuilder.fileDelete();
|
|
2523
|
+
const result = await this.connection.execute(query, { id });
|
|
2524
|
+
return Boolean(result["fileDelete"]);
|
|
2525
|
+
}
|
|
2526
|
+
};
|
|
1262
2527
|
|
|
1263
2528
|
// src/client.ts
|
|
1264
2529
|
var CardDBClient = class _CardDBClient {
|
|
@@ -1276,6 +2541,14 @@ var CardDBClient = class _CardDBClient {
|
|
|
1276
2541
|
decks;
|
|
1277
2542
|
/** Rules resource for game rules and deck formats */
|
|
1278
2543
|
rules;
|
|
2544
|
+
/** Publisher-managed import format resource */
|
|
2545
|
+
importFormats;
|
|
2546
|
+
/** Publisher import job resource */
|
|
2547
|
+
imports;
|
|
2548
|
+
/** Publisher dataset export job resource */
|
|
2549
|
+
exports;
|
|
2550
|
+
/** File upload helper resource */
|
|
2551
|
+
files;
|
|
1279
2552
|
/**
|
|
1280
2553
|
* Create a new CardDB client
|
|
1281
2554
|
*
|
|
@@ -1290,6 +2563,10 @@ var CardDBClient = class _CardDBClient {
|
|
|
1290
2563
|
this.records = new RecordsResource(this.connection, this.config);
|
|
1291
2564
|
this.decks = new DecksResource(this.connection, this.config);
|
|
1292
2565
|
this.rules = new RulesResource(this.connection, this.config);
|
|
2566
|
+
this.importFormats = new ImportFormatsResource(this.connection, this.config);
|
|
2567
|
+
this.imports = new ImportsResource(this.connection, this.config);
|
|
2568
|
+
this.exports = new ExportsResource(this.connection, this.config);
|
|
2569
|
+
this.files = new FilesResource(this.connection, this.config);
|
|
1293
2570
|
}
|
|
1294
2571
|
/**
|
|
1295
2572
|
* Get information about the current API key
|
|
@@ -1336,7 +2613,11 @@ var CardDBClient = class _CardDBClient {
|
|
|
1336
2613
|
withConfig(overrides) {
|
|
1337
2614
|
const mergedConfig = this.config.merge(overrides);
|
|
1338
2615
|
return new _CardDBClient({
|
|
1339
|
-
apiKey: mergedConfig.
|
|
2616
|
+
apiKey: mergedConfig.configApiKey(),
|
|
2617
|
+
publishableKey: mergedConfig.publishableKey,
|
|
2618
|
+
secretKey: mergedConfig.secretKey,
|
|
2619
|
+
accessToken: mergedConfig.accessToken,
|
|
2620
|
+
environment: mergedConfig.environment,
|
|
1340
2621
|
endpoint: mergedConfig.endpoint,
|
|
1341
2622
|
timeout: mergedConfig.timeout,
|
|
1342
2623
|
openTimeout: mergedConfig.openTimeout,
|
|
@@ -1373,7 +2654,11 @@ exports.DEFAULT_RETRY_MAX_DELAY = DEFAULT_RETRY_MAX_DELAY;
|
|
|
1373
2654
|
exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
|
|
1374
2655
|
exports.DatasetsResource = DatasetsResource;
|
|
1375
2656
|
exports.DecksResource = DecksResource;
|
|
2657
|
+
exports.ExportsResource = ExportsResource;
|
|
2658
|
+
exports.FilesResource = FilesResource;
|
|
1376
2659
|
exports.GamesResource = GamesResource;
|
|
2660
|
+
exports.ImportFormatsResource = ImportFormatsResource;
|
|
2661
|
+
exports.ImportsResource = ImportsResource;
|
|
1377
2662
|
exports.PublishersResource = PublishersResource;
|
|
1378
2663
|
exports.RecordsResource = RecordsResource;
|
|
1379
2664
|
exports.RulesResource = RulesResource;
|