@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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _carddb_core from '@carddb/core';
2
- import { Logger, LogLevel, Cache, ResourceType, CardDBConfig, RateLimitInfo, GraphQLErrorInfo, Collection, Publisher, Game, Dataset, Deck, DeckCreateInput, DeckUpdateInput, HydrateDeckEntryInput, HydratedDeckEntry, FilterInput, DatasetRecord, APIKeyInfo } from '@carddb/core';
2
+ import { Logger, LogLevel, Cache, ResourceType, CardDBConfig, RateLimitInfo, GraphQLErrorInfo, Collection, Publisher, Game, Dataset, Deck, DeckVersion, DeckCollaborator, DeckPreviewToken, DeckCreateInput, DeckUpdateInput, DeckPublishInput, DeckCollaboratorRole, DeckPreviewTokenCreateInput, DeckPreviewTokenCreatePayload, HydrateDeckEntryInput, HydratedDeckEntry, FilterInput, DatasetRecord, APIKeyInfo } from '@carddb/core';
3
3
  export * from '@carddb/core';
4
4
 
5
5
  /**
@@ -331,6 +331,10 @@ interface FetchDeckOptions {
331
331
  cache?: boolean;
332
332
  }
333
333
  type FetchDeckByExternalRefOptions = FetchDeckOptions;
334
+ type FetchDeckBySlugOptions = FetchDeckOptions;
335
+ type ListDeckVersionsOptions = ListDecksOptions;
336
+ type ListDeckCollaboratorsOptions = FetchDeckOptions;
337
+ type ListDeckPreviewTokensOptions = FetchDeckOptions;
334
338
  interface HydrateDeckEntriesOptions {
335
339
  /** Publisher slug (uses default if configured) */
336
340
  publisherSlug?: string;
@@ -351,6 +355,14 @@ declare class DecksResource extends BaseResource {
351
355
  * Fetch a hosted deck by CardDB UUID.
352
356
  */
353
357
  fetch(id: string, options?: FetchDeckOptions): Promise<Deck | null>;
358
+ /**
359
+ * Fetch one deck owned by the current account or API application.
360
+ */
361
+ fetchMine(id: string, options?: FetchDeckOptions): Promise<Deck | null>;
362
+ /**
363
+ * Fetch a hosted deck by canonical or historical slug.
364
+ */
365
+ fetchBySlug(publisherSlug: string, gameKey: string, slug: string, options?: FetchDeckBySlugOptions): Promise<Deck | null>;
354
366
  /**
355
367
  * Fetch a hosted deck by external reference for the current API application.
356
368
  */
@@ -359,6 +371,26 @@ declare class DecksResource extends BaseResource {
359
371
  * List decks owned by the current account or API application.
360
372
  */
361
373
  listMine(options?: ListDecksOptions): Promise<Collection<Deck>>;
374
+ /**
375
+ * Fetch one immutable published deck version.
376
+ */
377
+ fetchVersion(id: string, options?: FetchDeckOptions): Promise<DeckVersion | null>;
378
+ /**
379
+ * List immutable published versions for a deck.
380
+ */
381
+ listVersions(deckId: string, options?: ListDeckVersionsOptions): Promise<Collection<DeckVersion>>;
382
+ /**
383
+ * Fetch current draft data using a revocable preview token.
384
+ */
385
+ preview(token: string, options?: FetchDeckOptions): Promise<Deck | null>;
386
+ /**
387
+ * List collaborators for a deck.
388
+ */
389
+ listCollaborators(deckId: string, options?: ListDeckCollaboratorsOptions): Promise<DeckCollaborator[]>;
390
+ /**
391
+ * List draft preview tokens for a deck.
392
+ */
393
+ listPreviewTokens(deckId: string, options?: ListDeckPreviewTokensOptions): Promise<DeckPreviewToken[]>;
362
394
  /**
363
395
  * Create a hosted deck.
364
396
  */
@@ -371,6 +403,26 @@ declare class DecksResource extends BaseResource {
371
403
  * Delete a hosted deck.
372
404
  */
373
405
  delete(id: string): Promise<boolean>;
406
+ /**
407
+ * Publish the current draft as an immutable deck version.
408
+ */
409
+ publish(id: string, input?: DeckPublishInput): Promise<DeckVersion>;
410
+ /**
411
+ * Create or update a deck collaborator.
412
+ */
413
+ upsertCollaborator(deckId: string, accountId: string, role: DeckCollaboratorRole): Promise<DeckCollaborator>;
414
+ /**
415
+ * Remove a deck collaborator.
416
+ */
417
+ removeCollaborator(deckId: string, accountId: string): Promise<boolean>;
418
+ /**
419
+ * Create a revocable draft preview token.
420
+ */
421
+ createPreviewToken(input: DeckPreviewTokenCreateInput): Promise<DeckPreviewTokenCreatePayload>;
422
+ /**
423
+ * Revoke a draft preview token.
424
+ */
425
+ revokePreviewToken(id: string): Promise<boolean>;
374
426
  /**
375
427
  * Hydrate third-party-owned deck entries without storing them in CardDB.
376
428
  */
@@ -777,4 +829,4 @@ declare function readCache<T>(cache: Cache, key: string): Promise<T | null>;
777
829
  */
778
830
  declare function writeCache<T>(cache: Cache, key: string, value: T, ttl: number): Promise<void>;
779
831
 
780
- 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, type FetchDeckByExternalRefOptions, type FetchDeckOptions, GamesResource, type GetDatasetOptions, type GetGameOptions, type GetPublisherOptions, type GetRecordByIdentifierOptions, type GetRecordOptions, type GetRecordsByIdentifierOptions, type GraphQLResponse, type HydrateDeckEntriesOptions, type ListDecksOptions, type ListFormatsOptions, type ListRuleDatasetsOptions, type ListRulesOptions, PublishersResource, RecordsResource, RulesResource, type SearchDatasetsOptions, type SearchGamesOptions, type SearchPublishersOptions, type SearchRecordsOptions, cacheKey, getRateLimitInfo, getSDKVersion, getUserAgent, readCache, writeCache };
832
+ 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, type FetchDeckByExternalRefOptions, type FetchDeckBySlugOptions, type FetchDeckOptions, GamesResource, type GetDatasetOptions, type GetGameOptions, type GetPublisherOptions, type GetRecordByIdentifierOptions, type GetRecordOptions, type GetRecordsByIdentifierOptions, type GraphQLResponse, type HydrateDeckEntriesOptions, type ListDeckCollaboratorsOptions, type ListDeckPreviewTokensOptions, type ListDeckVersionsOptions, type ListDecksOptions, type ListFormatsOptions, type ListRuleDatasetsOptions, type ListRulesOptions, PublishersResource, RecordsResource, RulesResource, type SearchDatasetsOptions, type SearchGamesOptions, type SearchPublishersOptions, type SearchRecordsOptions, cacheKey, getRateLimitInfo, getSDKVersion, getUserAgent, readCache, writeCache };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _carddb_core from '@carddb/core';
2
- import { Logger, LogLevel, Cache, ResourceType, CardDBConfig, RateLimitInfo, GraphQLErrorInfo, Collection, Publisher, Game, Dataset, Deck, DeckCreateInput, DeckUpdateInput, HydrateDeckEntryInput, HydratedDeckEntry, FilterInput, DatasetRecord, APIKeyInfo } from '@carddb/core';
2
+ import { Logger, LogLevel, Cache, ResourceType, CardDBConfig, RateLimitInfo, GraphQLErrorInfo, Collection, Publisher, Game, Dataset, Deck, DeckVersion, DeckCollaborator, DeckPreviewToken, DeckCreateInput, DeckUpdateInput, DeckPublishInput, DeckCollaboratorRole, DeckPreviewTokenCreateInput, DeckPreviewTokenCreatePayload, HydrateDeckEntryInput, HydratedDeckEntry, FilterInput, DatasetRecord, APIKeyInfo } from '@carddb/core';
3
3
  export * from '@carddb/core';
4
4
 
5
5
  /**
@@ -331,6 +331,10 @@ interface FetchDeckOptions {
331
331
  cache?: boolean;
332
332
  }
333
333
  type FetchDeckByExternalRefOptions = FetchDeckOptions;
334
+ type FetchDeckBySlugOptions = FetchDeckOptions;
335
+ type ListDeckVersionsOptions = ListDecksOptions;
336
+ type ListDeckCollaboratorsOptions = FetchDeckOptions;
337
+ type ListDeckPreviewTokensOptions = FetchDeckOptions;
334
338
  interface HydrateDeckEntriesOptions {
335
339
  /** Publisher slug (uses default if configured) */
336
340
  publisherSlug?: string;
@@ -351,6 +355,14 @@ declare class DecksResource extends BaseResource {
351
355
  * Fetch a hosted deck by CardDB UUID.
352
356
  */
353
357
  fetch(id: string, options?: FetchDeckOptions): Promise<Deck | null>;
358
+ /**
359
+ * Fetch one deck owned by the current account or API application.
360
+ */
361
+ fetchMine(id: string, options?: FetchDeckOptions): Promise<Deck | null>;
362
+ /**
363
+ * Fetch a hosted deck by canonical or historical slug.
364
+ */
365
+ fetchBySlug(publisherSlug: string, gameKey: string, slug: string, options?: FetchDeckBySlugOptions): Promise<Deck | null>;
354
366
  /**
355
367
  * Fetch a hosted deck by external reference for the current API application.
356
368
  */
@@ -359,6 +371,26 @@ declare class DecksResource extends BaseResource {
359
371
  * List decks owned by the current account or API application.
360
372
  */
361
373
  listMine(options?: ListDecksOptions): Promise<Collection<Deck>>;
374
+ /**
375
+ * Fetch one immutable published deck version.
376
+ */
377
+ fetchVersion(id: string, options?: FetchDeckOptions): Promise<DeckVersion | null>;
378
+ /**
379
+ * List immutable published versions for a deck.
380
+ */
381
+ listVersions(deckId: string, options?: ListDeckVersionsOptions): Promise<Collection<DeckVersion>>;
382
+ /**
383
+ * Fetch current draft data using a revocable preview token.
384
+ */
385
+ preview(token: string, options?: FetchDeckOptions): Promise<Deck | null>;
386
+ /**
387
+ * List collaborators for a deck.
388
+ */
389
+ listCollaborators(deckId: string, options?: ListDeckCollaboratorsOptions): Promise<DeckCollaborator[]>;
390
+ /**
391
+ * List draft preview tokens for a deck.
392
+ */
393
+ listPreviewTokens(deckId: string, options?: ListDeckPreviewTokensOptions): Promise<DeckPreviewToken[]>;
362
394
  /**
363
395
  * Create a hosted deck.
364
396
  */
@@ -371,6 +403,26 @@ declare class DecksResource extends BaseResource {
371
403
  * Delete a hosted deck.
372
404
  */
373
405
  delete(id: string): Promise<boolean>;
406
+ /**
407
+ * Publish the current draft as an immutable deck version.
408
+ */
409
+ publish(id: string, input?: DeckPublishInput): Promise<DeckVersion>;
410
+ /**
411
+ * Create or update a deck collaborator.
412
+ */
413
+ upsertCollaborator(deckId: string, accountId: string, role: DeckCollaboratorRole): Promise<DeckCollaborator>;
414
+ /**
415
+ * Remove a deck collaborator.
416
+ */
417
+ removeCollaborator(deckId: string, accountId: string): Promise<boolean>;
418
+ /**
419
+ * Create a revocable draft preview token.
420
+ */
421
+ createPreviewToken(input: DeckPreviewTokenCreateInput): Promise<DeckPreviewTokenCreatePayload>;
422
+ /**
423
+ * Revoke a draft preview token.
424
+ */
425
+ revokePreviewToken(id: string): Promise<boolean>;
374
426
  /**
375
427
  * Hydrate third-party-owned deck entries without storing them in CardDB.
376
428
  */
@@ -777,4 +829,4 @@ declare function readCache<T>(cache: Cache, key: string): Promise<T | null>;
777
829
  */
778
830
  declare function writeCache<T>(cache: Cache, key: string, value: T, ttl: number): Promise<void>;
779
831
 
780
- 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, type FetchDeckByExternalRefOptions, type FetchDeckOptions, GamesResource, type GetDatasetOptions, type GetGameOptions, type GetPublisherOptions, type GetRecordByIdentifierOptions, type GetRecordOptions, type GetRecordsByIdentifierOptions, type GraphQLResponse, type HydrateDeckEntriesOptions, type ListDecksOptions, type ListFormatsOptions, type ListRuleDatasetsOptions, type ListRulesOptions, PublishersResource, RecordsResource, RulesResource, type SearchDatasetsOptions, type SearchGamesOptions, type SearchPublishersOptions, type SearchRecordsOptions, cacheKey, getRateLimitInfo, getSDKVersion, getUserAgent, readCache, writeCache };
832
+ 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, type FetchDeckByExternalRefOptions, type FetchDeckBySlugOptions, type FetchDeckOptions, GamesResource, type GetDatasetOptions, type GetGameOptions, type GetPublisherOptions, type GetRecordByIdentifierOptions, type GetRecordOptions, type GetRecordsByIdentifierOptions, type GraphQLResponse, type HydrateDeckEntriesOptions, type ListDeckCollaboratorsOptions, type ListDeckPreviewTokensOptions, type ListDeckVersionsOptions, type ListDecksOptions, type ListFormatsOptions, type ListRuleDatasetsOptions, type ListRulesOptions, PublishersResource, RecordsResource, RulesResource, type SearchDatasetsOptions, type SearchGamesOptions, type SearchPublishersOptions, type SearchRecordsOptions, cacheKey, getRateLimitInfo, getSDKVersion, getUserAgent, readCache, writeCache };
package/dist/index.js CHANGED
@@ -86,9 +86,7 @@ var Configuration = class _Configuration {
86
86
  validatePublisher(publisherSlug) {
87
87
  if (!this.allowedPublishers) return;
88
88
  if (this.allowedPublishers.includes(publisherSlug)) return;
89
- throw new RestrictedError(
90
- `Publisher '${publisherSlug}' is not in the allowed publishers list`
91
- );
89
+ throw new RestrictedError(`Publisher '${publisherSlug}' is not in the allowed publishers list`);
92
90
  }
93
91
  /**
94
92
  * Validate that a game is allowed by the configuration
@@ -98,9 +96,7 @@ var Configuration = class _Configuration {
98
96
  const allowedForPublisher = this.allowedGames[publisherSlug];
99
97
  if (!allowedForPublisher) return;
100
98
  if (allowedForPublisher.includes(gameKey)) return;
101
- throw new RestrictedError(
102
- `Game '${gameKey}' is not allowed for publisher '${publisherSlug}'`
103
- );
99
+ throw new RestrictedError(`Game '${gameKey}' is not allowed for publisher '${publisherSlug}'`);
104
100
  }
105
101
  /**
106
102
  * Validate both publisher and game access
@@ -746,6 +742,28 @@ var DecksResource = class extends BaseResource {
746
742
  return result["fetchDeck"] ?? null;
747
743
  });
748
744
  }
745
+ /**
746
+ * Fetch one deck owned by the current account or API application.
747
+ */
748
+ async fetchMine(id, options = {}) {
749
+ const key = this.cacheKey("decks", "fetchMine", { id });
750
+ return this.withCache(key, "decks", options, async () => {
751
+ const { query } = QueryBuilder.myDeck();
752
+ const result = await this.connection.execute(query, { id });
753
+ return result["myDeck"] ?? null;
754
+ });
755
+ }
756
+ /**
757
+ * Fetch a hosted deck by canonical or historical slug.
758
+ */
759
+ async fetchBySlug(publisherSlug, gameKey, slug, options = {}) {
760
+ const key = this.cacheKey("decks", "fetchBySlug", { publisherSlug, gameKey, slug });
761
+ return this.withCache(key, "decks", options, async () => {
762
+ const { query } = QueryBuilder.fetchDeckBySlug();
763
+ const result = await this.connection.execute(query, { publisherSlug, gameKey, slug });
764
+ return result["fetchDeckBySlug"] ?? null;
765
+ });
766
+ }
749
767
  /**
750
768
  * Fetch a hosted deck by external reference for the current API application.
751
769
  */
@@ -774,6 +792,68 @@ var DecksResource = class extends BaseResource {
774
792
  nextPageLoader: async (cursor) => this.listMine({ ...options, after: cursor })
775
793
  });
776
794
  }
795
+ /**
796
+ * Fetch one immutable published deck version.
797
+ */
798
+ async fetchVersion(id, options = {}) {
799
+ const key = this.cacheKey("decks", "fetchVersion", { id });
800
+ return this.withCache(key, "decks", options, async () => {
801
+ const { query } = QueryBuilder.deckVersion();
802
+ const result = await this.connection.execute(query, { id });
803
+ return result["deckVersion"] ?? null;
804
+ });
805
+ }
806
+ /**
807
+ * List immutable published versions for a deck.
808
+ */
809
+ async listVersions(deckId, options = {}) {
810
+ const { query, variables: pageVariables } = QueryBuilder.deckVersions({
811
+ first: options.first,
812
+ after: options.after
813
+ });
814
+ const variables = { deckId, ...pageVariables };
815
+ const key = this.cacheKey("decks", "listVersions", variables);
816
+ const data = await this.withCache(key, "decks", options, async () => {
817
+ const result = await this.connection.execute(query, variables);
818
+ return result["deckVersions"];
819
+ });
820
+ return new Collection(data, {
821
+ nextPageLoader: async (cursor) => this.listVersions(deckId, { ...options, after: cursor })
822
+ });
823
+ }
824
+ /**
825
+ * Fetch current draft data using a revocable preview token.
826
+ */
827
+ async preview(token, options = {}) {
828
+ const key = this.cacheKey("decks", "preview", { token });
829
+ return this.withCache(key, "decks", options, async () => {
830
+ const { query } = QueryBuilder.deckPreview();
831
+ const result = await this.connection.execute(query, { token });
832
+ return result["deckPreview"] ?? null;
833
+ });
834
+ }
835
+ /**
836
+ * List collaborators for a deck.
837
+ */
838
+ async listCollaborators(deckId, options = {}) {
839
+ const key = this.cacheKey("decks", "listCollaborators", { deckId });
840
+ return this.withCache(key, "decks", options, async () => {
841
+ const { query } = QueryBuilder.deckCollaborators();
842
+ const result = await this.connection.execute(query, { deckId });
843
+ return result["deckCollaborators"];
844
+ });
845
+ }
846
+ /**
847
+ * List draft preview tokens for a deck.
848
+ */
849
+ async listPreviewTokens(deckId, options = {}) {
850
+ const key = this.cacheKey("decks", "listPreviewTokens", { deckId });
851
+ return this.withCache(key, "decks", options, async () => {
852
+ const { query } = QueryBuilder.deckPreviewTokens();
853
+ const result = await this.connection.execute(query, { deckId });
854
+ return result["deckPreviewTokens"];
855
+ });
856
+ }
777
857
  /**
778
858
  * Create a hosted deck.
779
859
  */
@@ -800,6 +880,50 @@ var DecksResource = class extends BaseResource {
800
880
  const result = await this.connection.execute(query, { id });
801
881
  return Boolean(result["deckDelete"]);
802
882
  }
883
+ /**
884
+ * Publish the current draft as an immutable deck version.
885
+ */
886
+ async publish(id, input = {}) {
887
+ const { query } = QueryBuilder.publishDeck();
888
+ const variables = QueryBuilder.deckPublishVariables(id, input);
889
+ const result = await this.connection.execute(query, variables);
890
+ return result["deckPublish"];
891
+ }
892
+ /**
893
+ * Create or update a deck collaborator.
894
+ */
895
+ async upsertCollaborator(deckId, accountId, role) {
896
+ const { query } = QueryBuilder.upsertDeckCollaborator();
897
+ const variables = QueryBuilder.deckCollaboratorVariables(deckId, accountId, role);
898
+ const result = await this.connection.execute(query, variables);
899
+ return result["deckCollaboratorUpsert"];
900
+ }
901
+ /**
902
+ * Remove a deck collaborator.
903
+ */
904
+ async removeCollaborator(deckId, accountId) {
905
+ const { query } = QueryBuilder.removeDeckCollaborator();
906
+ const variables = QueryBuilder.deckCollaboratorVariables(deckId, accountId);
907
+ const result = await this.connection.execute(query, variables);
908
+ return Boolean(result["deckCollaboratorRemove"]);
909
+ }
910
+ /**
911
+ * Create a revocable draft preview token.
912
+ */
913
+ async createPreviewToken(input) {
914
+ const { query } = QueryBuilder.createDeckPreviewToken();
915
+ const variables = QueryBuilder.deckPreviewTokenCreateVariables(input);
916
+ const result = await this.connection.execute(query, variables);
917
+ return result["deckPreviewTokenCreate"];
918
+ }
919
+ /**
920
+ * Revoke a draft preview token.
921
+ */
922
+ async revokePreviewToken(id) {
923
+ const { query } = QueryBuilder.revokeDeckPreviewToken();
924
+ const result = await this.connection.execute(query, { id });
925
+ return Boolean(result["deckPreviewTokenRevoke"]);
926
+ }
803
927
  /**
804
928
  * Hydrate third-party-owned deck entries without storing them in CardDB.
805
929
  */
@@ -825,7 +949,11 @@ var DecksResource = class extends BaseResource {
825
949
  });
826
950
  return result["fetchRecordsByIdentifier"];
827
951
  });
828
- const recordsByIdentifier = recordsByDeckIdentifier(records, identifiers, options.identifierField);
952
+ const recordsByIdentifier = recordsByDeckIdentifier(
953
+ records,
954
+ identifiers,
955
+ options.identifierField
956
+ );
829
957
  return options.entries.map((entry) => ({
830
958
  ...entry,
831
959
  record: recordsByIdentifier.get(entry.identifier) ?? null