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