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