@carddb/client 0.2.0 → 0.3.0

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.js CHANGED
@@ -612,6 +612,73 @@ var GamesResource = class extends BaseResource {
612
612
  constructor(connection, config) {
613
613
  super(connection, config);
614
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
+ }
615
682
  /**
616
683
  * Search for games
617
684
  *
@@ -687,6 +754,58 @@ var DatasetsResource = class extends BaseResource {
687
754
  constructor(connection, config) {
688
755
  super(connection, config);
689
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
+ }
690
809
  /**
691
810
  * Search for datasets
692
811
  *
@@ -1470,6 +1589,16 @@ var DecksResource = class extends BaseResource {
1470
1589
  const result = await this.connection.execute(query, variables);
1471
1590
  return result["deckAccessTokenExchange"];
1472
1591
  }
1592
+ /**
1593
+ * Exchange the current secret API application credential for an app-owned deck session token.
1594
+ */
1595
+ async exchangeSessionToken(input) {
1596
+ this.config.requireSecretCredential("decks.exchangeSessionToken");
1597
+ const { query } = QueryBuilder.exchangeDeckSessionToken();
1598
+ const variables = QueryBuilder.deckSessionTokenExchangeVariables(input);
1599
+ const result = await this.connection.execute(query, variables);
1600
+ return result["deckSessionTokenExchange"];
1601
+ }
1473
1602
  /**
1474
1603
  * Revoke an exchanged deck access token.
1475
1604
  */
@@ -1532,6 +1661,121 @@ var RecordsResource = class extends BaseResource {
1532
1661
  constructor(connection, config) {
1533
1662
  super(connection, config);
1534
1663
  }
1664
+ /**
1665
+ * List records in a publisher-accessible dataset by dataset ID.
1666
+ */
1667
+ async list(options) {
1668
+ const filter = resolveFilter(options.filter);
1669
+ const { query, variables } = QueryBuilder.listDatasetRecords({
1670
+ datasetId: options.datasetId,
1671
+ filter,
1672
+ orderBy: options.orderBy,
1673
+ first: options.first,
1674
+ after: options.after,
1675
+ last: options.last,
1676
+ before: options.before,
1677
+ validateSchema: options.validateSchema
1678
+ });
1679
+ const key = this.cacheKey("records", "list", variables);
1680
+ const data = await this.withCache(key, "records", options, async () => {
1681
+ const result = await this.connection.execute(query, variables);
1682
+ return result["datasetRecords"];
1683
+ });
1684
+ return new Collection(data, {
1685
+ nextPageLoader: async (cursor) => this.list({ ...options, after: cursor })
1686
+ });
1687
+ }
1688
+ /**
1689
+ * Get a publisher-accessible record by dataset ID and identifier value.
1690
+ */
1691
+ async getByDatasetIdentifier(options) {
1692
+ const key = this.cacheKey("records", "getByDatasetIdentifier", {
1693
+ datasetId: options.datasetId,
1694
+ identifier: options.identifier,
1695
+ includePricing: options.includePricing ?? false
1696
+ });
1697
+ return this.withCache(key, "records", options, async () => {
1698
+ const { query, variables } = QueryBuilder.datasetRecord({
1699
+ datasetId: options.datasetId,
1700
+ identifier: options.identifier,
1701
+ includePricing: options.includePricing
1702
+ });
1703
+ const result = await this.connection.execute(query, variables);
1704
+ return result["datasetRecord"] ?? null;
1705
+ });
1706
+ }
1707
+ /**
1708
+ * Start an import-backed batch upsert, or return a dry-run result. Requires a secret credential.
1709
+ */
1710
+ async upsertBatch(input) {
1711
+ this.config.requireSecretCredential("records.upsertBatch");
1712
+ const { query } = QueryBuilder.upsertDatasetRecords();
1713
+ const result = await this.connection.execute(
1714
+ query,
1715
+ QueryBuilder.datasetRecordsUpsertVariables(input)
1716
+ );
1717
+ return result["datasetRecordsUpsert"];
1718
+ }
1719
+ /**
1720
+ * Create a dry-run or destructive bulk delete/reconciliation job. Requires a secret credential.
1721
+ */
1722
+ async deleteBatch(input) {
1723
+ this.config.requireSecretCredential("records.deleteBatch");
1724
+ const { query } = QueryBuilder.deleteDatasetRecords();
1725
+ const result = await this.connection.execute(
1726
+ query,
1727
+ QueryBuilder.datasetRecordsDeleteVariables(input)
1728
+ );
1729
+ return result["datasetRecordsDelete"];
1730
+ }
1731
+ /**
1732
+ * Get one bulk delete/reconciliation job.
1733
+ */
1734
+ async getDeleteJob(id, options = {}) {
1735
+ const key = this.cacheKey("records", "getDeleteJob", { id });
1736
+ return this.withCache(key, "records", options, async () => {
1737
+ const { query } = QueryBuilder.datasetRecordDeleteJob();
1738
+ const result = await this.connection.execute(query, { id });
1739
+ return result["datasetRecordDeleteJob"] ?? null;
1740
+ });
1741
+ }
1742
+ /**
1743
+ * List bulk delete/reconciliation jobs for a publisher.
1744
+ */
1745
+ async listDeleteJobs(publisherId, options = {}) {
1746
+ const { query, variables } = QueryBuilder.datasetRecordDeleteJobs({
1747
+ publisherId,
1748
+ datasetId: options.datasetId,
1749
+ status: options.status,
1750
+ first: options.first,
1751
+ after: options.after
1752
+ });
1753
+ const key = this.cacheKey("records", "listDeleteJobs", variables);
1754
+ const data = await this.withCache(key, "records", options, async () => {
1755
+ const result = await this.connection.execute(query, variables);
1756
+ return result["datasetRecordDeleteJobs"];
1757
+ });
1758
+ return new Collection(data, {
1759
+ nextPageLoader: async (cursor) => this.listDeleteJobs(publisherId, { ...options, after: cursor })
1760
+ });
1761
+ }
1762
+ /**
1763
+ * Poll a delete job until it reaches a terminal state.
1764
+ */
1765
+ async waitForDeleteJob(id, options = {}) {
1766
+ const intervalMs = options.intervalMs ?? 1e3;
1767
+ const timeoutMs = options.timeoutMs ?? 3e5;
1768
+ const startedAt = Date.now();
1769
+ while (true) {
1770
+ const job = await this.getDeleteJob(id, { cache: false });
1771
+ if (!job) throw new Error(`Delete job '${id}' was not found`);
1772
+ if (job.status === "COMPLETED" || job.status === "FAILED") return job;
1773
+ if (Date.now() - startedAt >= timeoutMs) {
1774
+ throw new Error(`Timed out waiting for delete job '${id}'`);
1775
+ }
1776
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
1777
+ }
1778
+ }
1535
1779
  /**
1536
1780
  * Search for records in a dataset with filtering, search, and pagination
1537
1781
  *
@@ -1813,6 +2057,482 @@ var RulesResource = class extends BaseResource {
1813
2057
  });
1814
2058
  }
1815
2059
  };
2060
+ var ImportFormatsResource = class extends BaseResource {
2061
+ constructor(connection, config) {
2062
+ super(connection, config);
2063
+ }
2064
+ /**
2065
+ * List publisher-managed import formats by publisher or game scope.
2066
+ */
2067
+ async list(options) {
2068
+ const { query, variables } = QueryBuilder.deckImportFormats({
2069
+ publisherId: options.publisherId,
2070
+ gameId: options.gameId,
2071
+ includeArchived: options.includeArchived,
2072
+ first: options.first,
2073
+ after: options.after
2074
+ });
2075
+ const key = this.cacheKey("importFormats", "list", variables);
2076
+ const data = await this.withCache(key, "importFormats", options, async () => {
2077
+ const result = await this.connection.execute(query, variables);
2078
+ return result["deckImportFormats"];
2079
+ });
2080
+ return new Collection(data, {
2081
+ nextPageLoader: async (cursor) => this.list({ ...options, after: cursor })
2082
+ });
2083
+ }
2084
+ /**
2085
+ * Get one import format by UUID.
2086
+ */
2087
+ async get(id, options = {}) {
2088
+ const key = this.cacheKey("importFormats", "get", { id });
2089
+ return this.withCache(key, "importFormats", options, async () => {
2090
+ const { query } = QueryBuilder.deckImportFormat();
2091
+ const result = await this.connection.execute(query, { id });
2092
+ return result["deckImportFormat"] ?? null;
2093
+ });
2094
+ }
2095
+ /**
2096
+ * Get one import format by game ID and stable key.
2097
+ */
2098
+ async getByKey(options) {
2099
+ const key = this.cacheKey("importFormats", "getByKey", {
2100
+ gameId: options.gameId,
2101
+ formatKey: options.key
2102
+ });
2103
+ return this.withCache(key, "importFormats", options, async () => {
2104
+ const { query } = QueryBuilder.deckImportFormat();
2105
+ const result = await this.connection.execute(query, {
2106
+ gameId: options.gameId,
2107
+ key: options.key
2108
+ });
2109
+ return result["deckImportFormat"] ?? null;
2110
+ });
2111
+ }
2112
+ /**
2113
+ * Preview parsing and record resolution for a configured import format.
2114
+ */
2115
+ async test(input) {
2116
+ const { query } = QueryBuilder.deckImportFormatTest();
2117
+ const result = await this.connection.execute(
2118
+ query,
2119
+ QueryBuilder.deckImportFormatTestVariables(input)
2120
+ );
2121
+ return result["deckImportFormatTest"];
2122
+ }
2123
+ /**
2124
+ * Create an import format. Requires a server-side secret credential.
2125
+ */
2126
+ async create(input) {
2127
+ this.config.requireSecretCredential("importFormats.create");
2128
+ const { query } = QueryBuilder.createDeckImportFormat();
2129
+ const result = await this.connection.execute(
2130
+ query,
2131
+ QueryBuilder.deckImportFormatCreateVariables(input)
2132
+ );
2133
+ return result["deckImportFormatCreate"];
2134
+ }
2135
+ /**
2136
+ * Update an import format. Requires a server-side secret credential.
2137
+ */
2138
+ async update(id, input) {
2139
+ this.config.requireSecretCredential("importFormats.update");
2140
+ const { query } = QueryBuilder.updateDeckImportFormat();
2141
+ const result = await this.connection.execute(
2142
+ query,
2143
+ QueryBuilder.deckImportFormatUpdateVariables(id, input)
2144
+ );
2145
+ return result["deckImportFormatUpdate"];
2146
+ }
2147
+ /**
2148
+ * Archive an import format. Requires a server-side secret credential.
2149
+ */
2150
+ async archive(id) {
2151
+ this.config.requireSecretCredential("importFormats.archive");
2152
+ const { query } = QueryBuilder.archiveDeckImportFormat();
2153
+ const result = await this.connection.execute(query, { id });
2154
+ return result["deckImportFormatArchive"];
2155
+ }
2156
+ /**
2157
+ * Restore an archived import format. Requires a server-side secret credential.
2158
+ */
2159
+ async unarchive(id) {
2160
+ this.config.requireSecretCredential("importFormats.unarchive");
2161
+ const { query } = QueryBuilder.unarchiveDeckImportFormat();
2162
+ const result = await this.connection.execute(query, { id });
2163
+ return result["deckImportFormatUnarchive"];
2164
+ }
2165
+ };
2166
+ var ImportsResource = class extends BaseResource {
2167
+ constructor(connection, config) {
2168
+ super(connection, config);
2169
+ }
2170
+ /**
2171
+ * Preview a single-dataset import source without writing records or schema.
2172
+ */
2173
+ async preview(input) {
2174
+ const { query } = QueryBuilder.datasetImportPreview();
2175
+ const result = await this.connection.execute(
2176
+ query,
2177
+ QueryBuilder.datasetImportPreviewVariables(input)
2178
+ );
2179
+ return result["datasetImportPreview"];
2180
+ }
2181
+ /**
2182
+ * Validate a single-dataset import source with dry-run enforced.
2183
+ */
2184
+ async validate(input) {
2185
+ const { query } = QueryBuilder.datasetImportValidate();
2186
+ const result = await this.connection.execute(
2187
+ query,
2188
+ QueryBuilder.datasetImportValidateVariables(input)
2189
+ );
2190
+ return result["datasetImportValidate"];
2191
+ }
2192
+ /**
2193
+ * Start an async single-dataset import from `fileId`, `data`, or `sourceUrl`.
2194
+ */
2195
+ async run(input) {
2196
+ this.config.requireSecretCredential("imports.run");
2197
+ if ("fileId" in input && input.fileId) {
2198
+ const { query: query2 } = QueryBuilder.datasetImportFromFile();
2199
+ const result2 = await this.connection.execute(
2200
+ query2,
2201
+ QueryBuilder.datasetImportFromFileVariables(input)
2202
+ );
2203
+ return result2["datasetImportFromFile"];
2204
+ }
2205
+ if ("sourceUrl" in input && input.sourceUrl) {
2206
+ const { query: query2 } = QueryBuilder.datasetImportFromUrl();
2207
+ const result2 = await this.connection.execute(
2208
+ query2,
2209
+ QueryBuilder.datasetImportFromUrlVariables(input)
2210
+ );
2211
+ return result2["datasetImportFromUrl"];
2212
+ }
2213
+ const { query } = QueryBuilder.datasetImportFromPayload();
2214
+ const result = await this.connection.execute(
2215
+ query,
2216
+ QueryBuilder.datasetImportFromPayloadVariables(input)
2217
+ );
2218
+ return result["datasetImportFromPayload"];
2219
+ }
2220
+ /**
2221
+ * Fetch one single-dataset import job.
2222
+ */
2223
+ async getJob(id, options = {}) {
2224
+ const key = this.cacheKey("imports", "getJob", { id });
2225
+ return this.withCache(key, "imports", options, async () => {
2226
+ const { query } = QueryBuilder.importJob();
2227
+ const result = await this.connection.execute(query, { id });
2228
+ return result["importJob"] ?? null;
2229
+ });
2230
+ }
2231
+ /**
2232
+ * List single-dataset import jobs for a publisher.
2233
+ */
2234
+ async listJobs(publisherId, options = {}) {
2235
+ const { query, variables } = QueryBuilder.importJobs({
2236
+ publisherId,
2237
+ datasetId: options.datasetId,
2238
+ status: options.status,
2239
+ first: options.first,
2240
+ after: options.after
2241
+ });
2242
+ const key = this.cacheKey("imports", "listJobs", variables);
2243
+ const data = await this.withCache(key, "imports", options, async () => {
2244
+ const result = await this.connection.execute(query, variables);
2245
+ return result["importJobs"];
2246
+ });
2247
+ return new Collection(data, {
2248
+ nextPageLoader: async (cursor) => this.listJobs(publisherId, { ...options, after: cursor })
2249
+ });
2250
+ }
2251
+ /**
2252
+ * Cancel a pending or processing single-dataset import job.
2253
+ */
2254
+ async cancelJob(id) {
2255
+ this.config.requireSecretCredential("imports.cancelJob");
2256
+ const { query } = QueryBuilder.importJobCancel();
2257
+ const result = await this.connection.execute(query, { id });
2258
+ return result["importJobCancel"];
2259
+ }
2260
+ /**
2261
+ * List structured logs for one single-dataset import job.
2262
+ */
2263
+ async listJobLogs(importJobId, options = {}) {
2264
+ const { query, variables } = QueryBuilder.importJobLogs({
2265
+ importJobId,
2266
+ level: options.level,
2267
+ datasetKey: options.datasetKey,
2268
+ first: options.first,
2269
+ after: options.after
2270
+ });
2271
+ const key = this.cacheKey("imports", "listJobLogs", variables);
2272
+ const data = await this.withCache(key, "imports", options, async () => {
2273
+ const result = await this.connection.execute(query, variables);
2274
+ const job = result["importJob"];
2275
+ return job?.logs ?? emptyConnection();
2276
+ });
2277
+ return new Collection(data, {
2278
+ nextPageLoader: async (cursor) => this.listJobLogs(importJobId, { ...options, after: cursor })
2279
+ });
2280
+ }
2281
+ /**
2282
+ * Poll a single-dataset import job until completion or failure.
2283
+ */
2284
+ async waitForJob(id, options = {}) {
2285
+ const intervalMs = options.intervalMs ?? 1e3;
2286
+ const timeoutMs = options.timeoutMs ?? 3e5;
2287
+ const startedAt = Date.now();
2288
+ while (true) {
2289
+ const job = await this.getJob(id, { cache: false });
2290
+ if (!job) throw new Error(`Import job '${id}' was not found`);
2291
+ if (job.status === "COMPLETED" || job.status === "FAILED") return job;
2292
+ if (Date.now() - startedAt >= timeoutMs) {
2293
+ throw new Error(`Timed out waiting for import job '${id}'`);
2294
+ }
2295
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
2296
+ }
2297
+ }
2298
+ /**
2299
+ * Preview an advanced game-level import source without writing records or schema.
2300
+ */
2301
+ async previewGame(input) {
2302
+ const { query } = QueryBuilder.gameImportPreview();
2303
+ const result = await this.connection.execute(
2304
+ query,
2305
+ QueryBuilder.gameImportPreviewVariables(input)
2306
+ );
2307
+ return result["gameImportPreview"];
2308
+ }
2309
+ /**
2310
+ * Start an async advanced game-level import from `fileId`, `data`, or `sourceUrl`.
2311
+ */
2312
+ async runGame(input) {
2313
+ this.config.requireSecretCredential("imports.runGame");
2314
+ if ("fileId" in input && input.fileId) {
2315
+ const { query: query2 } = QueryBuilder.gameImportFromFile();
2316
+ const result2 = await this.connection.execute(
2317
+ query2,
2318
+ QueryBuilder.gameImportFromFileVariables(input)
2319
+ );
2320
+ return result2["gameImportFromFile"];
2321
+ }
2322
+ if ("sourceUrl" in input && input.sourceUrl) {
2323
+ const { query: query2 } = QueryBuilder.gameImportFromUrl();
2324
+ const result2 = await this.connection.execute(
2325
+ query2,
2326
+ QueryBuilder.gameImportFromUrlVariables(input)
2327
+ );
2328
+ return result2["gameImportFromUrl"];
2329
+ }
2330
+ const { query } = QueryBuilder.gameImportFromPayload();
2331
+ const result = await this.connection.execute(
2332
+ query,
2333
+ QueryBuilder.gameImportFromPayloadVariables(input)
2334
+ );
2335
+ return result["gameImportFromPayload"];
2336
+ }
2337
+ /**
2338
+ * Fetch one advanced game-level import job.
2339
+ */
2340
+ async getGameJob(id, options = {}) {
2341
+ const key = this.cacheKey("imports", "getGameJob", { id });
2342
+ return this.withCache(key, "imports", options, async () => {
2343
+ const { query } = QueryBuilder.gameImportJob();
2344
+ const result = await this.connection.execute(query, { id });
2345
+ return result["gameImportJob"] ?? null;
2346
+ });
2347
+ }
2348
+ /**
2349
+ * List advanced game-level import jobs.
2350
+ */
2351
+ async listGameJobs(gameId, options = {}) {
2352
+ const { query, variables } = QueryBuilder.gameImportJobs({
2353
+ gameId,
2354
+ status: options.status,
2355
+ first: options.first,
2356
+ after: options.after
2357
+ });
2358
+ const key = this.cacheKey("imports", "listGameJobs", variables);
2359
+ const data = await this.withCache(key, "imports", options, async () => {
2360
+ const result = await this.connection.execute(query, variables);
2361
+ return result["gameImportJobs"];
2362
+ });
2363
+ return new Collection(data, {
2364
+ nextPageLoader: async (cursor) => this.listGameJobs(gameId, { ...options, after: cursor })
2365
+ });
2366
+ }
2367
+ /**
2368
+ * Cancel a pending or processing advanced game-level import job.
2369
+ */
2370
+ async cancelGameJob(id) {
2371
+ this.config.requireSecretCredential("imports.cancelGameJob");
2372
+ const { query } = QueryBuilder.gameImportJobCancel();
2373
+ const result = await this.connection.execute(query, { id });
2374
+ return result["gameImportJobCancel"];
2375
+ }
2376
+ /**
2377
+ * Poll an advanced game-level import job until completion or failure.
2378
+ */
2379
+ async waitForGameJob(id, options = {}) {
2380
+ const intervalMs = options.intervalMs ?? 1e3;
2381
+ const timeoutMs = options.timeoutMs ?? 3e5;
2382
+ const startedAt = Date.now();
2383
+ while (true) {
2384
+ const job = await this.getGameJob(id, { cache: false });
2385
+ if (!job) throw new Error(`Game import job '${id}' was not found`);
2386
+ if (job.status === "COMPLETED" || job.status === "FAILED") return job;
2387
+ if (Date.now() - startedAt >= timeoutMs) {
2388
+ throw new Error(`Timed out waiting for game import job '${id}'`);
2389
+ }
2390
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
2391
+ }
2392
+ }
2393
+ };
2394
+ function emptyConnection() {
2395
+ return {
2396
+ totalCount: 0,
2397
+ pageInfo: {
2398
+ hasNextPage: false,
2399
+ hasPreviousPage: false,
2400
+ startCursor: null,
2401
+ endCursor: null
2402
+ },
2403
+ edges: []
2404
+ };
2405
+ }
2406
+ var ExportsResource = class extends BaseResource {
2407
+ constructor(connection, config) {
2408
+ super(connection, config);
2409
+ }
2410
+ /**
2411
+ * Start an async dataset export. Requires a server-side secret credential.
2412
+ */
2413
+ async run(input) {
2414
+ this.config.requireSecretCredential("exports.run");
2415
+ const { query } = QueryBuilder.datasetExport();
2416
+ const result = await this.connection.execute(query, QueryBuilder.datasetExportVariables(input));
2417
+ return result["datasetExport"];
2418
+ }
2419
+ /** Alias for `run`. */
2420
+ async create(input) {
2421
+ return this.run(input);
2422
+ }
2423
+ /**
2424
+ * Fetch one export job.
2425
+ */
2426
+ async getJob(id, options = {}) {
2427
+ const key = this.cacheKey("exports", "getJob", { id });
2428
+ return this.withCache(key, "exports", options, async () => {
2429
+ const { query } = QueryBuilder.exportJob();
2430
+ const result = await this.connection.execute(query, { id });
2431
+ return result["exportJob"] ?? null;
2432
+ });
2433
+ }
2434
+ /**
2435
+ * List export jobs for a publisher, optionally filtered by game, dataset, or status.
2436
+ */
2437
+ async listJobs(publisherId, options = {}) {
2438
+ const { query, variables } = QueryBuilder.exportJobs({
2439
+ publisherId,
2440
+ gameId: options.gameId,
2441
+ datasetId: options.datasetId,
2442
+ status: options.status,
2443
+ first: options.first,
2444
+ after: options.after
2445
+ });
2446
+ const key = this.cacheKey("exports", "listJobs", variables);
2447
+ const data = await this.withCache(key, "exports", options, async () => {
2448
+ const result = await this.connection.execute(query, variables);
2449
+ return result["exportJobs"];
2450
+ });
2451
+ return new Collection(data, {
2452
+ nextPageLoader: async (cursor) => this.listJobs(publisherId, { ...options, after: cursor })
2453
+ });
2454
+ }
2455
+ /**
2456
+ * Refresh the signed download URL for a completed export job.
2457
+ */
2458
+ async refreshUrl(id) {
2459
+ const { query } = QueryBuilder.exportJobRefreshUrl();
2460
+ const result = await this.connection.execute(query, { id });
2461
+ return result["exportJobRefreshUrl"];
2462
+ }
2463
+ /**
2464
+ * Cancel a pending or processing export job. Requires a server-side secret credential.
2465
+ */
2466
+ async cancel(id) {
2467
+ this.config.requireSecretCredential("exports.cancel");
2468
+ const { query } = QueryBuilder.exportJobCancel();
2469
+ const result = await this.connection.execute(query, { id });
2470
+ return result["exportJobCancel"];
2471
+ }
2472
+ /**
2473
+ * Poll an export job until completion or failure.
2474
+ */
2475
+ async waitForJob(id, options = {}) {
2476
+ const intervalMs = options.intervalMs ?? 1e3;
2477
+ const timeoutMs = options.timeoutMs ?? 3e5;
2478
+ const startedAt = Date.now();
2479
+ while (true) {
2480
+ const job = await this.getJob(id, { cache: false });
2481
+ if (!job) throw new Error(`Export job '${id}' was not found`);
2482
+ if (job.status === "COMPLETED" || job.status === "FAILED") return job;
2483
+ if (Date.now() - startedAt >= timeoutMs) {
2484
+ throw new Error(`Timed out waiting for export job '${id}'`);
2485
+ }
2486
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
2487
+ }
2488
+ }
2489
+ };
2490
+ var FilesResource = class extends BaseResource {
2491
+ constructor(connection, config) {
2492
+ super(connection, config);
2493
+ }
2494
+ /**
2495
+ * Get one file by ID.
2496
+ */
2497
+ async get(id, options = {}) {
2498
+ const key = this.cacheKey("files", "get", { id });
2499
+ return this.withCache(key, "files", options, async () => {
2500
+ const { query } = QueryBuilder.file();
2501
+ const result = await this.connection.execute(query, { id });
2502
+ return result["file"] ?? null;
2503
+ });
2504
+ }
2505
+ /**
2506
+ * Request a presigned URL for direct upload. Requires a server-side secret credential.
2507
+ */
2508
+ async requestUpload(input) {
2509
+ this.config.requireSecretCredential("files.requestUpload");
2510
+ const { query } = QueryBuilder.fileUploadRequest();
2511
+ const result = await this.connection.execute(
2512
+ query,
2513
+ QueryBuilder.fileUploadRequestVariables(input)
2514
+ );
2515
+ return result["fileUploadRequest"];
2516
+ }
2517
+ /**
2518
+ * Confirm that a presigned upload completed.
2519
+ */
2520
+ async confirmUpload(id) {
2521
+ this.config.requireSecretCredential("files.confirmUpload");
2522
+ const { query } = QueryBuilder.fileUploadConfirm();
2523
+ const result = await this.connection.execute(query, { id });
2524
+ return result["fileUploadConfirm"];
2525
+ }
2526
+ /**
2527
+ * Delete a file. Requires a server-side secret credential.
2528
+ */
2529
+ async delete(id) {
2530
+ this.config.requireSecretCredential("files.delete");
2531
+ const { query } = QueryBuilder.fileDelete();
2532
+ const result = await this.connection.execute(query, { id });
2533
+ return Boolean(result["fileDelete"]);
2534
+ }
2535
+ };
1816
2536
 
1817
2537
  // src/client.ts
1818
2538
  var CardDBClient = class _CardDBClient {
@@ -1830,6 +2550,14 @@ var CardDBClient = class _CardDBClient {
1830
2550
  decks;
1831
2551
  /** Rules resource for game rules and deck formats */
1832
2552
  rules;
2553
+ /** Publisher-managed import format resource */
2554
+ importFormats;
2555
+ /** Publisher import job resource */
2556
+ imports;
2557
+ /** Publisher dataset export job resource */
2558
+ exports;
2559
+ /** File upload helper resource */
2560
+ files;
1833
2561
  /**
1834
2562
  * Create a new CardDB client
1835
2563
  *
@@ -1844,6 +2572,10 @@ var CardDBClient = class _CardDBClient {
1844
2572
  this.records = new RecordsResource(this.connection, this.config);
1845
2573
  this.decks = new DecksResource(this.connection, this.config);
1846
2574
  this.rules = new RulesResource(this.connection, this.config);
2575
+ this.importFormats = new ImportFormatsResource(this.connection, this.config);
2576
+ this.imports = new ImportsResource(this.connection, this.config);
2577
+ this.exports = new ExportsResource(this.connection, this.config);
2578
+ this.files = new FilesResource(this.connection, this.config);
1847
2579
  }
1848
2580
  /**
1849
2581
  * Get information about the current API key
@@ -1917,6 +2649,6 @@ var CardDBClient = class _CardDBClient {
1917
2649
  }
1918
2650
  };
1919
2651
 
1920
- 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 };
2652
+ 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 };
1921
2653
  //# sourceMappingURL=index.js.map
1922
2654
  //# sourceMappingURL=index.js.map