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