@carddb/client 0.2.0 → 0.2.5

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