@carddb/client 0.1.2 → 0.1.3

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
@@ -746,6 +746,28 @@ var DecksResource = class extends BaseResource {
746
746
  return result["fetchDeck"] ?? null;
747
747
  });
748
748
  }
749
+ /**
750
+ * Fetch one deck owned by the current account or API application.
751
+ */
752
+ async fetchMine(id, options = {}) {
753
+ const key = this.cacheKey("decks", "fetchMine", { id });
754
+ return this.withCache(key, "decks", options, async () => {
755
+ const { query } = QueryBuilder.myDeck();
756
+ const result = await this.connection.execute(query, { id });
757
+ return result["myDeck"] ?? null;
758
+ });
759
+ }
760
+ /**
761
+ * Fetch a hosted deck by canonical or historical slug.
762
+ */
763
+ async fetchBySlug(publisherSlug, gameKey, slug, options = {}) {
764
+ const key = this.cacheKey("decks", "fetchBySlug", { publisherSlug, gameKey, slug });
765
+ return this.withCache(key, "decks", options, async () => {
766
+ const { query } = QueryBuilder.fetchDeckBySlug();
767
+ const result = await this.connection.execute(query, { publisherSlug, gameKey, slug });
768
+ return result["fetchDeckBySlug"] ?? null;
769
+ });
770
+ }
749
771
  /**
750
772
  * Fetch a hosted deck by external reference for the current API application.
751
773
  */
@@ -774,6 +796,68 @@ var DecksResource = class extends BaseResource {
774
796
  nextPageLoader: async (cursor) => this.listMine({ ...options, after: cursor })
775
797
  });
776
798
  }
799
+ /**
800
+ * Fetch one immutable published deck version.
801
+ */
802
+ async fetchVersion(id, options = {}) {
803
+ const key = this.cacheKey("decks", "fetchVersion", { id });
804
+ return this.withCache(key, "decks", options, async () => {
805
+ const { query } = QueryBuilder.deckVersion();
806
+ const result = await this.connection.execute(query, { id });
807
+ return result["deckVersion"] ?? null;
808
+ });
809
+ }
810
+ /**
811
+ * List immutable published versions for a deck.
812
+ */
813
+ async listVersions(deckId, options = {}) {
814
+ const { query, variables: pageVariables } = QueryBuilder.deckVersions({
815
+ first: options.first,
816
+ after: options.after
817
+ });
818
+ const variables = { deckId, ...pageVariables };
819
+ const key = this.cacheKey("decks", "listVersions", variables);
820
+ const data = await this.withCache(key, "decks", options, async () => {
821
+ const result = await this.connection.execute(query, variables);
822
+ return result["deckVersions"];
823
+ });
824
+ return new Collection(data, {
825
+ nextPageLoader: async (cursor) => this.listVersions(deckId, { ...options, after: cursor })
826
+ });
827
+ }
828
+ /**
829
+ * Fetch current draft data using a revocable preview token.
830
+ */
831
+ async preview(token, options = {}) {
832
+ const key = this.cacheKey("decks", "preview", { token });
833
+ return this.withCache(key, "decks", options, async () => {
834
+ const { query } = QueryBuilder.deckPreview();
835
+ const result = await this.connection.execute(query, { token });
836
+ return result["deckPreview"] ?? null;
837
+ });
838
+ }
839
+ /**
840
+ * List collaborators for a deck.
841
+ */
842
+ async listCollaborators(deckId, options = {}) {
843
+ const key = this.cacheKey("decks", "listCollaborators", { deckId });
844
+ return this.withCache(key, "decks", options, async () => {
845
+ const { query } = QueryBuilder.deckCollaborators();
846
+ const result = await this.connection.execute(query, { deckId });
847
+ return result["deckCollaborators"];
848
+ });
849
+ }
850
+ /**
851
+ * List draft preview tokens for a deck.
852
+ */
853
+ async listPreviewTokens(deckId, options = {}) {
854
+ const key = this.cacheKey("decks", "listPreviewTokens", { deckId });
855
+ return this.withCache(key, "decks", options, async () => {
856
+ const { query } = QueryBuilder.deckPreviewTokens();
857
+ const result = await this.connection.execute(query, { deckId });
858
+ return result["deckPreviewTokens"];
859
+ });
860
+ }
777
861
  /**
778
862
  * Create a hosted deck.
779
863
  */
@@ -800,6 +884,50 @@ var DecksResource = class extends BaseResource {
800
884
  const result = await this.connection.execute(query, { id });
801
885
  return Boolean(result["deckDelete"]);
802
886
  }
887
+ /**
888
+ * Publish the current draft as an immutable deck version.
889
+ */
890
+ async publish(id, input = {}) {
891
+ const { query } = QueryBuilder.publishDeck();
892
+ const variables = QueryBuilder.deckPublishVariables(id, input);
893
+ const result = await this.connection.execute(query, variables);
894
+ return result["deckPublish"];
895
+ }
896
+ /**
897
+ * Create or update a deck collaborator.
898
+ */
899
+ async upsertCollaborator(deckId, accountId, role) {
900
+ const { query } = QueryBuilder.upsertDeckCollaborator();
901
+ const variables = QueryBuilder.deckCollaboratorVariables(deckId, accountId, role);
902
+ const result = await this.connection.execute(query, variables);
903
+ return result["deckCollaboratorUpsert"];
904
+ }
905
+ /**
906
+ * Remove a deck collaborator.
907
+ */
908
+ async removeCollaborator(deckId, accountId) {
909
+ const { query } = QueryBuilder.removeDeckCollaborator();
910
+ const variables = QueryBuilder.deckCollaboratorVariables(deckId, accountId);
911
+ const result = await this.connection.execute(query, variables);
912
+ return Boolean(result["deckCollaboratorRemove"]);
913
+ }
914
+ /**
915
+ * Create a revocable draft preview token.
916
+ */
917
+ async createPreviewToken(input) {
918
+ const { query } = QueryBuilder.createDeckPreviewToken();
919
+ const variables = QueryBuilder.deckPreviewTokenCreateVariables(input);
920
+ const result = await this.connection.execute(query, variables);
921
+ return result["deckPreviewTokenCreate"];
922
+ }
923
+ /**
924
+ * Revoke a draft preview token.
925
+ */
926
+ async revokePreviewToken(id) {
927
+ const { query } = QueryBuilder.revokeDeckPreviewToken();
928
+ const result = await this.connection.execute(query, { id });
929
+ return Boolean(result["deckPreviewTokenRevoke"]);
930
+ }
803
931
  /**
804
932
  * Hydrate third-party-owned deck entries without storing them in CardDB.
805
933
  */
@@ -825,7 +953,11 @@ var DecksResource = class extends BaseResource {
825
953
  });
826
954
  return result["fetchRecordsByIdentifier"];
827
955
  });
828
- const recordsByIdentifier = recordsByDeckIdentifier(records, identifiers, options.identifierField);
956
+ const recordsByIdentifier = recordsByDeckIdentifier(
957
+ records,
958
+ identifiers,
959
+ options.identifierField
960
+ );
829
961
  return options.entries.map((entry) => ({
830
962
  ...entry,
831
963
  record: recordsByIdentifier.get(entry.identifier) ?? null