@carddb/client 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +135 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -2
- package/dist/index.d.ts +54 -2
- package/dist/index.js +135 -7
- package/dist/index.js.map +1 -1
- package/package.json +12 -4
package/dist/index.cjs
CHANGED
|
@@ -87,9 +87,7 @@ var Configuration = class _Configuration {
|
|
|
87
87
|
validatePublisher(publisherSlug) {
|
|
88
88
|
if (!this.allowedPublishers) return;
|
|
89
89
|
if (this.allowedPublishers.includes(publisherSlug)) return;
|
|
90
|
-
throw new core.RestrictedError(
|
|
91
|
-
`Publisher '${publisherSlug}' is not in the allowed publishers list`
|
|
92
|
-
);
|
|
90
|
+
throw new core.RestrictedError(`Publisher '${publisherSlug}' is not in the allowed publishers list`);
|
|
93
91
|
}
|
|
94
92
|
/**
|
|
95
93
|
* Validate that a game is allowed by the configuration
|
|
@@ -99,9 +97,7 @@ var Configuration = class _Configuration {
|
|
|
99
97
|
const allowedForPublisher = this.allowedGames[publisherSlug];
|
|
100
98
|
if (!allowedForPublisher) return;
|
|
101
99
|
if (allowedForPublisher.includes(gameKey)) return;
|
|
102
|
-
throw new core.RestrictedError(
|
|
103
|
-
`Game '${gameKey}' is not allowed for publisher '${publisherSlug}'`
|
|
104
|
-
);
|
|
100
|
+
throw new core.RestrictedError(`Game '${gameKey}' is not allowed for publisher '${publisherSlug}'`);
|
|
105
101
|
}
|
|
106
102
|
/**
|
|
107
103
|
* Validate both publisher and game access
|
|
@@ -747,6 +743,28 @@ var DecksResource = class extends BaseResource {
|
|
|
747
743
|
return result["fetchDeck"] ?? null;
|
|
748
744
|
});
|
|
749
745
|
}
|
|
746
|
+
/**
|
|
747
|
+
* Fetch one deck owned by the current account or API application.
|
|
748
|
+
*/
|
|
749
|
+
async fetchMine(id, options = {}) {
|
|
750
|
+
const key = this.cacheKey("decks", "fetchMine", { id });
|
|
751
|
+
return this.withCache(key, "decks", options, async () => {
|
|
752
|
+
const { query } = core.QueryBuilder.myDeck();
|
|
753
|
+
const result = await this.connection.execute(query, { id });
|
|
754
|
+
return result["myDeck"] ?? null;
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Fetch a hosted deck by canonical or historical slug.
|
|
759
|
+
*/
|
|
760
|
+
async fetchBySlug(publisherSlug, gameKey, slug, options = {}) {
|
|
761
|
+
const key = this.cacheKey("decks", "fetchBySlug", { publisherSlug, gameKey, slug });
|
|
762
|
+
return this.withCache(key, "decks", options, async () => {
|
|
763
|
+
const { query } = core.QueryBuilder.fetchDeckBySlug();
|
|
764
|
+
const result = await this.connection.execute(query, { publisherSlug, gameKey, slug });
|
|
765
|
+
return result["fetchDeckBySlug"] ?? null;
|
|
766
|
+
});
|
|
767
|
+
}
|
|
750
768
|
/**
|
|
751
769
|
* Fetch a hosted deck by external reference for the current API application.
|
|
752
770
|
*/
|
|
@@ -775,6 +793,68 @@ var DecksResource = class extends BaseResource {
|
|
|
775
793
|
nextPageLoader: async (cursor) => this.listMine({ ...options, after: cursor })
|
|
776
794
|
});
|
|
777
795
|
}
|
|
796
|
+
/**
|
|
797
|
+
* Fetch one immutable published deck version.
|
|
798
|
+
*/
|
|
799
|
+
async fetchVersion(id, options = {}) {
|
|
800
|
+
const key = this.cacheKey("decks", "fetchVersion", { id });
|
|
801
|
+
return this.withCache(key, "decks", options, async () => {
|
|
802
|
+
const { query } = core.QueryBuilder.deckVersion();
|
|
803
|
+
const result = await this.connection.execute(query, { id });
|
|
804
|
+
return result["deckVersion"] ?? null;
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* List immutable published versions for a deck.
|
|
809
|
+
*/
|
|
810
|
+
async listVersions(deckId, options = {}) {
|
|
811
|
+
const { query, variables: pageVariables } = core.QueryBuilder.deckVersions({
|
|
812
|
+
first: options.first,
|
|
813
|
+
after: options.after
|
|
814
|
+
});
|
|
815
|
+
const variables = { deckId, ...pageVariables };
|
|
816
|
+
const key = this.cacheKey("decks", "listVersions", variables);
|
|
817
|
+
const data = await this.withCache(key, "decks", options, async () => {
|
|
818
|
+
const result = await this.connection.execute(query, variables);
|
|
819
|
+
return result["deckVersions"];
|
|
820
|
+
});
|
|
821
|
+
return new core.Collection(data, {
|
|
822
|
+
nextPageLoader: async (cursor) => this.listVersions(deckId, { ...options, after: cursor })
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Fetch current draft data using a revocable preview token.
|
|
827
|
+
*/
|
|
828
|
+
async preview(token, options = {}) {
|
|
829
|
+
const key = this.cacheKey("decks", "preview", { token });
|
|
830
|
+
return this.withCache(key, "decks", options, async () => {
|
|
831
|
+
const { query } = core.QueryBuilder.deckPreview();
|
|
832
|
+
const result = await this.connection.execute(query, { token });
|
|
833
|
+
return result["deckPreview"] ?? null;
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* List collaborators for a deck.
|
|
838
|
+
*/
|
|
839
|
+
async listCollaborators(deckId, options = {}) {
|
|
840
|
+
const key = this.cacheKey("decks", "listCollaborators", { deckId });
|
|
841
|
+
return this.withCache(key, "decks", options, async () => {
|
|
842
|
+
const { query } = core.QueryBuilder.deckCollaborators();
|
|
843
|
+
const result = await this.connection.execute(query, { deckId });
|
|
844
|
+
return result["deckCollaborators"];
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* List draft preview tokens for a deck.
|
|
849
|
+
*/
|
|
850
|
+
async listPreviewTokens(deckId, options = {}) {
|
|
851
|
+
const key = this.cacheKey("decks", "listPreviewTokens", { deckId });
|
|
852
|
+
return this.withCache(key, "decks", options, async () => {
|
|
853
|
+
const { query } = core.QueryBuilder.deckPreviewTokens();
|
|
854
|
+
const result = await this.connection.execute(query, { deckId });
|
|
855
|
+
return result["deckPreviewTokens"];
|
|
856
|
+
});
|
|
857
|
+
}
|
|
778
858
|
/**
|
|
779
859
|
* Create a hosted deck.
|
|
780
860
|
*/
|
|
@@ -801,6 +881,50 @@ var DecksResource = class extends BaseResource {
|
|
|
801
881
|
const result = await this.connection.execute(query, { id });
|
|
802
882
|
return Boolean(result["deckDelete"]);
|
|
803
883
|
}
|
|
884
|
+
/**
|
|
885
|
+
* Publish the current draft as an immutable deck version.
|
|
886
|
+
*/
|
|
887
|
+
async publish(id, input = {}) {
|
|
888
|
+
const { query } = core.QueryBuilder.publishDeck();
|
|
889
|
+
const variables = core.QueryBuilder.deckPublishVariables(id, input);
|
|
890
|
+
const result = await this.connection.execute(query, variables);
|
|
891
|
+
return result["deckPublish"];
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Create or update a deck collaborator.
|
|
895
|
+
*/
|
|
896
|
+
async upsertCollaborator(deckId, accountId, role) {
|
|
897
|
+
const { query } = core.QueryBuilder.upsertDeckCollaborator();
|
|
898
|
+
const variables = core.QueryBuilder.deckCollaboratorVariables(deckId, accountId, role);
|
|
899
|
+
const result = await this.connection.execute(query, variables);
|
|
900
|
+
return result["deckCollaboratorUpsert"];
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Remove a deck collaborator.
|
|
904
|
+
*/
|
|
905
|
+
async removeCollaborator(deckId, accountId) {
|
|
906
|
+
const { query } = core.QueryBuilder.removeDeckCollaborator();
|
|
907
|
+
const variables = core.QueryBuilder.deckCollaboratorVariables(deckId, accountId);
|
|
908
|
+
const result = await this.connection.execute(query, variables);
|
|
909
|
+
return Boolean(result["deckCollaboratorRemove"]);
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Create a revocable draft preview token.
|
|
913
|
+
*/
|
|
914
|
+
async createPreviewToken(input) {
|
|
915
|
+
const { query } = core.QueryBuilder.createDeckPreviewToken();
|
|
916
|
+
const variables = core.QueryBuilder.deckPreviewTokenCreateVariables(input);
|
|
917
|
+
const result = await this.connection.execute(query, variables);
|
|
918
|
+
return result["deckPreviewTokenCreate"];
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Revoke a draft preview token.
|
|
922
|
+
*/
|
|
923
|
+
async revokePreviewToken(id) {
|
|
924
|
+
const { query } = core.QueryBuilder.revokeDeckPreviewToken();
|
|
925
|
+
const result = await this.connection.execute(query, { id });
|
|
926
|
+
return Boolean(result["deckPreviewTokenRevoke"]);
|
|
927
|
+
}
|
|
804
928
|
/**
|
|
805
929
|
* Hydrate third-party-owned deck entries without storing them in CardDB.
|
|
806
930
|
*/
|
|
@@ -826,7 +950,11 @@ var DecksResource = class extends BaseResource {
|
|
|
826
950
|
});
|
|
827
951
|
return result["fetchRecordsByIdentifier"];
|
|
828
952
|
});
|
|
829
|
-
const recordsByIdentifier = recordsByDeckIdentifier(
|
|
953
|
+
const recordsByIdentifier = recordsByDeckIdentifier(
|
|
954
|
+
records,
|
|
955
|
+
identifiers,
|
|
956
|
+
options.identifierField
|
|
957
|
+
);
|
|
830
958
|
return options.entries.map((entry) => ({
|
|
831
959
|
...entry,
|
|
832
960
|
record: recordsByIdentifier.get(entry.identifier) ?? null
|