@gethydra/sdk 0.1.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/LICENSE +21 -0
- package/README.md +185 -0
- package/dist/index.d.ts +17298 -0
- package/dist/index.js +1693 -0
- package/dist/webhooks.d.ts +31 -0
- package/dist/webhooks.js +20 -0
- package/package.json +52 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1693 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var HydraError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
status;
|
|
5
|
+
field;
|
|
6
|
+
details;
|
|
7
|
+
retryAfter;
|
|
8
|
+
/** Raw response body when the API returns non-JSON (e.g. CDN 502 HTML page) */
|
|
9
|
+
rawBody;
|
|
10
|
+
constructor(body, status, headers, rawBody) {
|
|
11
|
+
super(body.error.message);
|
|
12
|
+
this.name = "HydraError";
|
|
13
|
+
this.code = body.error.code;
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.field = body.error.field;
|
|
16
|
+
this.details = body.error.details;
|
|
17
|
+
this.rawBody = rawBody;
|
|
18
|
+
const retry = headers.get("Retry-After");
|
|
19
|
+
if (retry) this.retryAfter = parseInt(retry, 10);
|
|
20
|
+
}
|
|
21
|
+
get isRetryable() {
|
|
22
|
+
return this.status === 429 || this.status >= 500;
|
|
23
|
+
}
|
|
24
|
+
get isNotFound() {
|
|
25
|
+
return this.status === 404;
|
|
26
|
+
}
|
|
27
|
+
get isValidationError() {
|
|
28
|
+
return this.code === "validation_error";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var HydraConnectionError = class extends HydraError {
|
|
32
|
+
constructor(message) {
|
|
33
|
+
super({ error: { code: "connection_error", message } }, 0, new Headers());
|
|
34
|
+
this.name = "HydraConnectionError";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var HydraAuthenticationError = class extends HydraError {
|
|
38
|
+
constructor(body, headers) {
|
|
39
|
+
super(body, 401, headers);
|
|
40
|
+
this.name = "HydraAuthenticationError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var HydraPermissionError = class extends HydraError {
|
|
44
|
+
constructor(body, headers) {
|
|
45
|
+
super(body, 403, headers);
|
|
46
|
+
this.name = "HydraPermissionError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var HydraNotFoundError = class extends HydraError {
|
|
50
|
+
constructor(body, headers) {
|
|
51
|
+
super(body, 404, headers);
|
|
52
|
+
this.name = "HydraNotFoundError";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var HydraRateLimitError = class extends HydraError {
|
|
56
|
+
constructor(body, headers) {
|
|
57
|
+
super(body, 429, headers);
|
|
58
|
+
this.name = "HydraRateLimitError";
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var HydraValidationError = class extends HydraError {
|
|
62
|
+
constructor(body, headers) {
|
|
63
|
+
super(body, 400, headers);
|
|
64
|
+
this.name = "HydraValidationError";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var HydraIdempotencyError = class extends HydraError {
|
|
68
|
+
constructor(body, headers) {
|
|
69
|
+
super(body, 409, headers);
|
|
70
|
+
this.name = "HydraIdempotencyError";
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/pagination.ts
|
|
75
|
+
async function* paginate(fetchPage, options) {
|
|
76
|
+
let cursor;
|
|
77
|
+
let pages = 0;
|
|
78
|
+
const maxPages = options?.maxPages;
|
|
79
|
+
do {
|
|
80
|
+
const page = await fetchPage(cursor);
|
|
81
|
+
pages++;
|
|
82
|
+
for (const item of page.data) {
|
|
83
|
+
yield item;
|
|
84
|
+
}
|
|
85
|
+
cursor = page.pagination.has_more ? page.pagination.cursor ?? void 0 : void 0;
|
|
86
|
+
} while (cursor && (maxPages === void 0 || pages < maxPages));
|
|
87
|
+
}
|
|
88
|
+
var DEFAULT_TO_ARRAY_LIMIT = 1e4;
|
|
89
|
+
async function toArray(iterator, options) {
|
|
90
|
+
const limit = options?.limit ?? DEFAULT_TO_ARRAY_LIMIT;
|
|
91
|
+
const results = [];
|
|
92
|
+
for await (const item of iterator) {
|
|
93
|
+
results.push(item);
|
|
94
|
+
if (results.length >= limit) break;
|
|
95
|
+
}
|
|
96
|
+
return results;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/resources/products.ts
|
|
100
|
+
var ProductsResource = class {
|
|
101
|
+
constructor(client) {
|
|
102
|
+
this.client = client;
|
|
103
|
+
}
|
|
104
|
+
client;
|
|
105
|
+
async list(params) {
|
|
106
|
+
return this.client.request("GET", "/v1/products", { params });
|
|
107
|
+
}
|
|
108
|
+
iterate(params, options) {
|
|
109
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
110
|
+
}
|
|
111
|
+
async toArray(params, options) {
|
|
112
|
+
return toArray(this.iterate(params, options), options);
|
|
113
|
+
}
|
|
114
|
+
async get(id, params) {
|
|
115
|
+
return this.client.request("GET", `/v1/products/${id}`, { params });
|
|
116
|
+
}
|
|
117
|
+
async create(body, options) {
|
|
118
|
+
return this.client.request("POST", "/v1/products", { body, ...options });
|
|
119
|
+
}
|
|
120
|
+
async update(id, body) {
|
|
121
|
+
return this.client.request("PATCH", `/v1/products/${id}`, { body });
|
|
122
|
+
}
|
|
123
|
+
async delete(id) {
|
|
124
|
+
return this.client.request("DELETE", `/v1/products/${id}`);
|
|
125
|
+
}
|
|
126
|
+
async batchCreate(body, options) {
|
|
127
|
+
return this.client.request("POST", "/v1/products/batch", { body, ...options });
|
|
128
|
+
}
|
|
129
|
+
async duplicate(id, body) {
|
|
130
|
+
return this.client.request("POST", `/v1/products/${id}/duplicate`, { body });
|
|
131
|
+
}
|
|
132
|
+
async getStats(id) {
|
|
133
|
+
return this.client.request("GET", `/v1/products/${id}/stats`);
|
|
134
|
+
}
|
|
135
|
+
// Variant sub-resources (nested under product)
|
|
136
|
+
async listVariants(productId, params) {
|
|
137
|
+
return this.client.request("GET", `/v1/products/${productId}/variants`, { params });
|
|
138
|
+
}
|
|
139
|
+
async createVariant(productId, body, options) {
|
|
140
|
+
return this.client.request("POST", `/v1/products/${productId}/variants`, { body, ...options });
|
|
141
|
+
}
|
|
142
|
+
async generateVariants(productId, body) {
|
|
143
|
+
return this.client.request("POST", `/v1/products/${productId}/variants/generate`, { body });
|
|
144
|
+
}
|
|
145
|
+
// Image sub-resources (nested under product)
|
|
146
|
+
async listImages(productId) {
|
|
147
|
+
return this.client.request("GET", `/v1/products/${productId}/images`);
|
|
148
|
+
}
|
|
149
|
+
async uploadImage(productId, formData) {
|
|
150
|
+
return this.client.upload(`/v1/products/${productId}/images`, formData);
|
|
151
|
+
}
|
|
152
|
+
async attachImages(productId, body) {
|
|
153
|
+
return this.client.request("POST", `/v1/products/${productId}/images/attach`, { body });
|
|
154
|
+
}
|
|
155
|
+
// Metafield sub-resources
|
|
156
|
+
async setMetafield(productId, slug, body) {
|
|
157
|
+
return this.client.request("PUT", `/v1/products/${productId}/metafields/${slug}`, { body });
|
|
158
|
+
}
|
|
159
|
+
async clearMetafield(productId, slug) {
|
|
160
|
+
return this.client.request("DELETE", `/v1/products/${productId}/metafields/${slug}`);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/resources/variants.ts
|
|
165
|
+
var VariantsResource = class {
|
|
166
|
+
constructor(client) {
|
|
167
|
+
this.client = client;
|
|
168
|
+
}
|
|
169
|
+
client;
|
|
170
|
+
async get(id, params) {
|
|
171
|
+
return this.client.request("GET", `/v1/variants/${id}`, { params });
|
|
172
|
+
}
|
|
173
|
+
async update(id, body) {
|
|
174
|
+
return this.client.request("PATCH", `/v1/variants/${id}`, { body });
|
|
175
|
+
}
|
|
176
|
+
async delete(id) {
|
|
177
|
+
return this.client.request("DELETE", `/v1/variants/${id}`);
|
|
178
|
+
}
|
|
179
|
+
// Price keys
|
|
180
|
+
async listPrices(variantId) {
|
|
181
|
+
return this.client.request("GET", `/v1/variants/${variantId}/prices`);
|
|
182
|
+
}
|
|
183
|
+
async upsertPrice(variantId, priceKeySlug, body) {
|
|
184
|
+
return this.client.request("PUT", `/v1/variants/${variantId}/prices/${priceKeySlug}`, { body });
|
|
185
|
+
}
|
|
186
|
+
async deletePrice(variantId, priceKeySlug) {
|
|
187
|
+
return this.client.request("DELETE", `/v1/variants/${variantId}/prices/${priceKeySlug}`);
|
|
188
|
+
}
|
|
189
|
+
// Metafield sub-resources
|
|
190
|
+
async setMetafield(variantId, slug, body) {
|
|
191
|
+
return this.client.request("PUT", `/v1/variants/${variantId}/metafields/${slug}`, { body });
|
|
192
|
+
}
|
|
193
|
+
async clearMetafield(variantId, slug) {
|
|
194
|
+
return this.client.request("DELETE", `/v1/variants/${variantId}/metafields/${slug}`);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/resources/collections.ts
|
|
199
|
+
var CollectionsResource = class {
|
|
200
|
+
constructor(client) {
|
|
201
|
+
this.client = client;
|
|
202
|
+
}
|
|
203
|
+
client;
|
|
204
|
+
async list(params) {
|
|
205
|
+
return this.client.request("GET", "/v1/collections", { params });
|
|
206
|
+
}
|
|
207
|
+
iterate(params, options) {
|
|
208
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
209
|
+
}
|
|
210
|
+
async toArray(params, options) {
|
|
211
|
+
return toArray(this.iterate(params, options), options);
|
|
212
|
+
}
|
|
213
|
+
async get(id, params) {
|
|
214
|
+
return this.client.request("GET", `/v1/collections/${id}`, { params });
|
|
215
|
+
}
|
|
216
|
+
async create(body, options) {
|
|
217
|
+
return this.client.request("POST", "/v1/collections", { body, ...options });
|
|
218
|
+
}
|
|
219
|
+
async update(id, body) {
|
|
220
|
+
return this.client.request("PATCH", `/v1/collections/${id}`, { body });
|
|
221
|
+
}
|
|
222
|
+
async delete(id) {
|
|
223
|
+
return this.client.request("DELETE", `/v1/collections/${id}`);
|
|
224
|
+
}
|
|
225
|
+
async tree() {
|
|
226
|
+
return this.client.request("GET", "/v1/collections/tree");
|
|
227
|
+
}
|
|
228
|
+
async reorder(body) {
|
|
229
|
+
return this.client.request("PATCH", "/v1/collections/reorder", { body });
|
|
230
|
+
}
|
|
231
|
+
async addProducts(collectionId, body) {
|
|
232
|
+
return this.client.request("POST", `/v1/collections/${collectionId}/products`, { body });
|
|
233
|
+
}
|
|
234
|
+
async reorderProducts(collectionId, body) {
|
|
235
|
+
return this.client.request("PATCH", `/v1/collections/${collectionId}/products/reorder`, {
|
|
236
|
+
body
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
async removeProduct(collectionId, productId) {
|
|
240
|
+
return this.client.request("DELETE", `/v1/collections/${collectionId}/products/${productId}`);
|
|
241
|
+
}
|
|
242
|
+
// Metafield sub-resources
|
|
243
|
+
async setMetafield(collectionId, slug, body) {
|
|
244
|
+
return this.client.request("PUT", `/v1/collections/${collectionId}/metafields/${slug}`, {
|
|
245
|
+
body
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
async clearMetafield(collectionId, slug) {
|
|
249
|
+
return this.client.request("DELETE", `/v1/collections/${collectionId}/metafields/${slug}`);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// src/resources/cart.ts
|
|
254
|
+
var CartResource = class {
|
|
255
|
+
constructor(client) {
|
|
256
|
+
this.client = client;
|
|
257
|
+
}
|
|
258
|
+
client;
|
|
259
|
+
async create() {
|
|
260
|
+
return this.client.request("POST", "/v1/cart");
|
|
261
|
+
}
|
|
262
|
+
async get(id, params) {
|
|
263
|
+
return this.client.request("GET", `/v1/cart/${id}`, { params });
|
|
264
|
+
}
|
|
265
|
+
async addItem(cartId, body) {
|
|
266
|
+
return this.client.request("POST", `/v1/cart/${cartId}/items`, { body });
|
|
267
|
+
}
|
|
268
|
+
async updateItem(cartId, itemId, body) {
|
|
269
|
+
return this.client.request("PATCH", `/v1/cart/${cartId}/items/${itemId}`, { body });
|
|
270
|
+
}
|
|
271
|
+
async removeItem(cartId, itemId) {
|
|
272
|
+
return this.client.request("DELETE", `/v1/cart/${cartId}/items/${itemId}`);
|
|
273
|
+
}
|
|
274
|
+
async clear(cartId) {
|
|
275
|
+
return this.client.request("DELETE", `/v1/cart/${cartId}`);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// src/resources/checkout.ts
|
|
280
|
+
var CheckoutResource = class {
|
|
281
|
+
constructor(client) {
|
|
282
|
+
this.client = client;
|
|
283
|
+
}
|
|
284
|
+
client;
|
|
285
|
+
async create(body, options) {
|
|
286
|
+
return this.client.request("POST", "/v1/checkout", { body, ...options });
|
|
287
|
+
}
|
|
288
|
+
async get(id) {
|
|
289
|
+
return this.client.request("GET", `/v1/checkout/${id}`);
|
|
290
|
+
}
|
|
291
|
+
async applyDiscount(checkoutId, body) {
|
|
292
|
+
return this.client.request("POST", `/v1/checkout/${checkoutId}/discount`, { body });
|
|
293
|
+
}
|
|
294
|
+
async removeDiscount(checkoutId) {
|
|
295
|
+
return this.client.request("DELETE", `/v1/checkout/${checkoutId}/discount`);
|
|
296
|
+
}
|
|
297
|
+
async applyCredit(checkoutId, body) {
|
|
298
|
+
return this.client.request("POST", `/v1/checkout/${checkoutId}/credit`, { body });
|
|
299
|
+
}
|
|
300
|
+
async removeCredit(checkoutId) {
|
|
301
|
+
return this.client.request("DELETE", `/v1/checkout/${checkoutId}/credit`);
|
|
302
|
+
}
|
|
303
|
+
async completeWithCredit(checkoutId) {
|
|
304
|
+
return this.client.request("POST", `/v1/checkout/${checkoutId}/complete`);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// src/resources/orders.ts
|
|
309
|
+
var OrdersResource = class {
|
|
310
|
+
constructor(client) {
|
|
311
|
+
this.client = client;
|
|
312
|
+
}
|
|
313
|
+
client;
|
|
314
|
+
async list(params) {
|
|
315
|
+
return this.client.request("GET", "/v1/orders", { params });
|
|
316
|
+
}
|
|
317
|
+
iterate(params, options) {
|
|
318
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
319
|
+
}
|
|
320
|
+
async toArray(params, options) {
|
|
321
|
+
return toArray(this.iterate(params, options), options);
|
|
322
|
+
}
|
|
323
|
+
async get(id, params) {
|
|
324
|
+
return this.client.request("GET", `/v1/orders/${id}`, { params });
|
|
325
|
+
}
|
|
326
|
+
async create(body, options) {
|
|
327
|
+
return this.client.request("POST", "/v1/orders", { body, ...options });
|
|
328
|
+
}
|
|
329
|
+
async update(id, body) {
|
|
330
|
+
return this.client.request("PATCH", `/v1/orders/${id}`, { body });
|
|
331
|
+
}
|
|
332
|
+
async listFulfillmentOrders(orderId) {
|
|
333
|
+
return this.client.request("GET", `/v1/orders/${orderId}/fulfillment-orders`);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Returns the API path for downloading the invoice PDF for an order.
|
|
337
|
+
* The first request to this endpoint assigns a permanent invoice number.
|
|
338
|
+
*/
|
|
339
|
+
invoiceUrl(orderId) {
|
|
340
|
+
return `/v1/orders/${orderId}/invoice`;
|
|
341
|
+
}
|
|
342
|
+
// Metafield sub-resources
|
|
343
|
+
async setMetafield(orderId, slug, body) {
|
|
344
|
+
return this.client.request("PUT", `/v1/orders/${orderId}/metafields/${slug}`, { body });
|
|
345
|
+
}
|
|
346
|
+
async clearMetafield(orderId, slug) {
|
|
347
|
+
return this.client.request("DELETE", `/v1/orders/${orderId}/metafields/${slug}`);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
// src/resources/fulfillments.ts
|
|
352
|
+
var FulfillmentsResource = class {
|
|
353
|
+
constructor(client) {
|
|
354
|
+
this.client = client;
|
|
355
|
+
}
|
|
356
|
+
client;
|
|
357
|
+
/** Create a fulfillment for a fulfillment order */
|
|
358
|
+
async create(fulfillmentOrderId, body, options) {
|
|
359
|
+
return this.client.request(
|
|
360
|
+
"POST",
|
|
361
|
+
`/v1/fulfillment-orders/${fulfillmentOrderId}/fulfillments`,
|
|
362
|
+
{
|
|
363
|
+
body,
|
|
364
|
+
...options
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
async update(id, body) {
|
|
369
|
+
return this.client.request("PATCH", `/v1/fulfillments/${id}`, { body });
|
|
370
|
+
}
|
|
371
|
+
async cancel(id, body) {
|
|
372
|
+
return this.client.request("DELETE", `/v1/fulfillments/${id}`, { body });
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// src/resources/refunds.ts
|
|
377
|
+
var RefundsResource = class {
|
|
378
|
+
constructor(client) {
|
|
379
|
+
this.client = client;
|
|
380
|
+
}
|
|
381
|
+
client;
|
|
382
|
+
async list(params) {
|
|
383
|
+
return this.client.request("GET", "/v1/refunds", { params });
|
|
384
|
+
}
|
|
385
|
+
iterate(params, options) {
|
|
386
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
387
|
+
}
|
|
388
|
+
async toArray(params, options) {
|
|
389
|
+
return toArray(this.iterate(params, options), options);
|
|
390
|
+
}
|
|
391
|
+
async get(id, params) {
|
|
392
|
+
return this.client.request("GET", `/v1/refunds/${id}`, { params });
|
|
393
|
+
}
|
|
394
|
+
async create(orderId, body, options) {
|
|
395
|
+
return this.client.request("POST", `/v1/orders/${orderId}/refunds`, { body, ...options });
|
|
396
|
+
}
|
|
397
|
+
async listByOrder(orderId) {
|
|
398
|
+
return this.client.request("GET", `/v1/orders/${orderId}/refunds`);
|
|
399
|
+
}
|
|
400
|
+
async retry(id) {
|
|
401
|
+
return this.client.request("POST", `/v1/refunds/${id}/retry`);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Returns the API path for downloading the credit note PDF for a refund.
|
|
405
|
+
* The first request to this endpoint assigns a permanent credit note number.
|
|
406
|
+
*/
|
|
407
|
+
creditNoteUrl(id) {
|
|
408
|
+
return `/v1/refunds/${id}/credit-note`;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// src/resources/returns.ts
|
|
413
|
+
var ReturnsResource = class {
|
|
414
|
+
constructor(client) {
|
|
415
|
+
this.client = client;
|
|
416
|
+
}
|
|
417
|
+
client;
|
|
418
|
+
async list(params) {
|
|
419
|
+
return this.client.request("GET", "/v1/returns", { params });
|
|
420
|
+
}
|
|
421
|
+
iterate(params, options) {
|
|
422
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
423
|
+
}
|
|
424
|
+
async toArray(params, options) {
|
|
425
|
+
return toArray(this.iterate(params, options), options);
|
|
426
|
+
}
|
|
427
|
+
async get(id, params) {
|
|
428
|
+
return this.client.request("GET", `/v1/returns/${id}`, { params });
|
|
429
|
+
}
|
|
430
|
+
async create(orderId, body, options) {
|
|
431
|
+
return this.client.request("POST", `/v1/orders/${orderId}/returns`, { body, ...options });
|
|
432
|
+
}
|
|
433
|
+
async listByOrder(orderId) {
|
|
434
|
+
return this.client.request("GET", `/v1/orders/${orderId}/returns`);
|
|
435
|
+
}
|
|
436
|
+
async approve(id, body) {
|
|
437
|
+
return this.client.request("POST", `/v1/returns/${id}/approve`, { body });
|
|
438
|
+
}
|
|
439
|
+
async receive(id, body) {
|
|
440
|
+
return this.client.request("POST", `/v1/returns/${id}/receive`, { body });
|
|
441
|
+
}
|
|
442
|
+
async close(id) {
|
|
443
|
+
return this.client.request("POST", `/v1/returns/${id}/close`);
|
|
444
|
+
}
|
|
445
|
+
async reject(id, body) {
|
|
446
|
+
return this.client.request("POST", `/v1/returns/${id}/reject`, { body });
|
|
447
|
+
}
|
|
448
|
+
async cancel(id) {
|
|
449
|
+
return this.client.request("POST", `/v1/returns/${id}/cancel`);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
// src/resources/draft-orders.ts
|
|
454
|
+
var DraftOrdersResource = class {
|
|
455
|
+
constructor(client) {
|
|
456
|
+
this.client = client;
|
|
457
|
+
}
|
|
458
|
+
client;
|
|
459
|
+
async list(params) {
|
|
460
|
+
return this.client.request("GET", "/v1/draft-orders", { params });
|
|
461
|
+
}
|
|
462
|
+
iterate(params, options) {
|
|
463
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
464
|
+
}
|
|
465
|
+
async toArray(params, options) {
|
|
466
|
+
return toArray(this.iterate(params, options), options);
|
|
467
|
+
}
|
|
468
|
+
async get(id, params) {
|
|
469
|
+
return this.client.request("GET", `/v1/draft-orders/${id}`, { params });
|
|
470
|
+
}
|
|
471
|
+
async create(body, options) {
|
|
472
|
+
return this.client.request("POST", "/v1/draft-orders", { body, ...options });
|
|
473
|
+
}
|
|
474
|
+
async update(id, body) {
|
|
475
|
+
return this.client.request("PATCH", `/v1/draft-orders/${id}`, { body });
|
|
476
|
+
}
|
|
477
|
+
async delete(id) {
|
|
478
|
+
return this.client.request("DELETE", `/v1/draft-orders/${id}`);
|
|
479
|
+
}
|
|
480
|
+
async addItems(draftOrderId, body) {
|
|
481
|
+
return this.client.request("POST", `/v1/draft-orders/${draftOrderId}/items`, { body });
|
|
482
|
+
}
|
|
483
|
+
async updateItem(draftOrderId, itemId, body) {
|
|
484
|
+
return this.client.request("PATCH", `/v1/draft-orders/${draftOrderId}/items/${itemId}`, {
|
|
485
|
+
body
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
async removeItem(draftOrderId, itemId) {
|
|
489
|
+
return this.client.request("DELETE", `/v1/draft-orders/${draftOrderId}/items/${itemId}`);
|
|
490
|
+
}
|
|
491
|
+
async complete(id) {
|
|
492
|
+
return this.client.request("POST", `/v1/draft-orders/${id}/complete`);
|
|
493
|
+
}
|
|
494
|
+
async send(id, body) {
|
|
495
|
+
return this.client.request("POST", `/v1/draft-orders/${id}/send`, {
|
|
496
|
+
body: body ?? void 0
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/resources/customers.ts
|
|
502
|
+
var CustomersResource = class {
|
|
503
|
+
constructor(client) {
|
|
504
|
+
this.client = client;
|
|
505
|
+
}
|
|
506
|
+
client;
|
|
507
|
+
async list(params) {
|
|
508
|
+
return this.client.request("GET", "/v1/customers", { params });
|
|
509
|
+
}
|
|
510
|
+
iterate(params, options) {
|
|
511
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
512
|
+
}
|
|
513
|
+
async toArray(params, options) {
|
|
514
|
+
return toArray(this.iterate(params, options), options);
|
|
515
|
+
}
|
|
516
|
+
async get(id, params) {
|
|
517
|
+
return this.client.request("GET", `/v1/customers/${id}`, { params });
|
|
518
|
+
}
|
|
519
|
+
async create(body, options) {
|
|
520
|
+
return this.client.request("POST", "/v1/customers", { body, ...options });
|
|
521
|
+
}
|
|
522
|
+
async update(id, body) {
|
|
523
|
+
return this.client.request("PATCH", `/v1/customers/${id}`, { body });
|
|
524
|
+
}
|
|
525
|
+
async delete(id) {
|
|
526
|
+
return this.client.request("DELETE", `/v1/customers/${id}`);
|
|
527
|
+
}
|
|
528
|
+
// Address sub-resources
|
|
529
|
+
async listAddresses(customerId) {
|
|
530
|
+
return this.client.request("GET", `/v1/customers/${customerId}/addresses`);
|
|
531
|
+
}
|
|
532
|
+
async createAddress(customerId, body) {
|
|
533
|
+
return this.client.request("POST", `/v1/customers/${customerId}/addresses`, { body });
|
|
534
|
+
}
|
|
535
|
+
// Note sub-resources
|
|
536
|
+
async listNotes(customerId) {
|
|
537
|
+
return this.client.request("GET", `/v1/customers/${customerId}/notes`);
|
|
538
|
+
}
|
|
539
|
+
async createNote(customerId, body) {
|
|
540
|
+
return this.client.request("POST", `/v1/customers/${customerId}/notes`, { body });
|
|
541
|
+
}
|
|
542
|
+
async deleteNote(customerId, noteId) {
|
|
543
|
+
return this.client.request("DELETE", `/v1/customers/${customerId}/notes/${noteId}`);
|
|
544
|
+
}
|
|
545
|
+
// Metafield sub-resources
|
|
546
|
+
async setMetafield(customerId, slug, body) {
|
|
547
|
+
return this.client.request("PUT", `/v1/customers/${customerId}/metafields/${slug}`, { body });
|
|
548
|
+
}
|
|
549
|
+
async clearMetafield(customerId, slug) {
|
|
550
|
+
return this.client.request("DELETE", `/v1/customers/${customerId}/metafields/${slug}`);
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
// src/resources/customer-groups.ts
|
|
555
|
+
var CustomerGroupsResource = class {
|
|
556
|
+
constructor(client) {
|
|
557
|
+
this.client = client;
|
|
558
|
+
}
|
|
559
|
+
client;
|
|
560
|
+
async list(params) {
|
|
561
|
+
return this.client.request("GET", "/v1/customer-groups", { params });
|
|
562
|
+
}
|
|
563
|
+
iterate(params, options) {
|
|
564
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
565
|
+
}
|
|
566
|
+
async toArray(params, options) {
|
|
567
|
+
return toArray(this.iterate(params, options), options);
|
|
568
|
+
}
|
|
569
|
+
async get(id) {
|
|
570
|
+
return this.client.request("GET", `/v1/customer-groups/${id}`);
|
|
571
|
+
}
|
|
572
|
+
async create(body, options) {
|
|
573
|
+
return this.client.request("POST", "/v1/customer-groups", { body, ...options });
|
|
574
|
+
}
|
|
575
|
+
async update(id, body) {
|
|
576
|
+
return this.client.request("PATCH", `/v1/customer-groups/${id}`, { body });
|
|
577
|
+
}
|
|
578
|
+
async delete(id) {
|
|
579
|
+
return this.client.request("DELETE", `/v1/customer-groups/${id}`);
|
|
580
|
+
}
|
|
581
|
+
async addMembers(groupId, body) {
|
|
582
|
+
return this.client.request("POST", `/v1/customer-groups/${groupId}/members`, { body });
|
|
583
|
+
}
|
|
584
|
+
async removeMember(groupId, customerId) {
|
|
585
|
+
return this.client.request("DELETE", `/v1/customer-groups/${groupId}/members/${customerId}`);
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
// src/resources/addresses.ts
|
|
590
|
+
var AddressesResource = class {
|
|
591
|
+
constructor(client) {
|
|
592
|
+
this.client = client;
|
|
593
|
+
}
|
|
594
|
+
client;
|
|
595
|
+
async update(id, body) {
|
|
596
|
+
return this.client.request("PATCH", `/v1/addresses/${id}`, { body });
|
|
597
|
+
}
|
|
598
|
+
async delete(id) {
|
|
599
|
+
return this.client.request("DELETE", `/v1/addresses/${id}`);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
// src/resources/inventory.ts
|
|
604
|
+
var InventoryResource = class {
|
|
605
|
+
constructor(client) {
|
|
606
|
+
this.client = client;
|
|
607
|
+
}
|
|
608
|
+
client;
|
|
609
|
+
async list(params) {
|
|
610
|
+
return this.client.request("GET", "/v1/inventory", { params });
|
|
611
|
+
}
|
|
612
|
+
iterate(params, options) {
|
|
613
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
614
|
+
}
|
|
615
|
+
async toArray(params, options) {
|
|
616
|
+
return toArray(this.iterate(params, options), options);
|
|
617
|
+
}
|
|
618
|
+
async listAdjustments(params) {
|
|
619
|
+
return this.client.request("GET", "/v1/inventory/adjustments", { params });
|
|
620
|
+
}
|
|
621
|
+
iterateAdjustments(params, options) {
|
|
622
|
+
return paginate((cursor) => this.listAdjustments({ ...params, cursor }), options);
|
|
623
|
+
}
|
|
624
|
+
async adjustmentsToArray(params, options) {
|
|
625
|
+
return toArray(this.iterateAdjustments(params, options), options);
|
|
626
|
+
}
|
|
627
|
+
async set(variantId, body) {
|
|
628
|
+
return this.client.request("PATCH", `/v1/inventory/${variantId}`, { body });
|
|
629
|
+
}
|
|
630
|
+
async adjust(variantId, body) {
|
|
631
|
+
return this.client.request("POST", `/v1/inventory/${variantId}/adjust`, { body });
|
|
632
|
+
}
|
|
633
|
+
async listVariantAdjustments(variantId, params) {
|
|
634
|
+
return this.client.request("GET", `/v1/inventory/${variantId}/adjustments`, { params });
|
|
635
|
+
}
|
|
636
|
+
iterateVariantAdjustments(variantId, params, options) {
|
|
637
|
+
return paginate(
|
|
638
|
+
(cursor) => this.listVariantAdjustments(variantId, { ...params, cursor }),
|
|
639
|
+
options
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
async variantAdjustmentsToArray(variantId, params, options) {
|
|
643
|
+
return toArray(this.iterateVariantAdjustments(variantId, params, options), options);
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
// src/resources/shipping.ts
|
|
648
|
+
var ShippingResource = class {
|
|
649
|
+
constructor(client) {
|
|
650
|
+
this.client = client;
|
|
651
|
+
}
|
|
652
|
+
client;
|
|
653
|
+
// Zones
|
|
654
|
+
async listZones(params) {
|
|
655
|
+
return this.client.request("GET", "/v1/shipping/zones", { params });
|
|
656
|
+
}
|
|
657
|
+
iterateZones(params, options) {
|
|
658
|
+
return paginate((cursor) => this.listZones({ ...params, cursor }), options);
|
|
659
|
+
}
|
|
660
|
+
async zonesToArray(params, options) {
|
|
661
|
+
return toArray(this.iterateZones(params, options), options);
|
|
662
|
+
}
|
|
663
|
+
async getZone(id, params) {
|
|
664
|
+
return this.client.request("GET", `/v1/shipping/zones/${id}`, { params });
|
|
665
|
+
}
|
|
666
|
+
async createZone(body, options) {
|
|
667
|
+
return this.client.request("POST", "/v1/shipping/zones", { body, ...options });
|
|
668
|
+
}
|
|
669
|
+
async updateZone(id, body) {
|
|
670
|
+
return this.client.request("PATCH", `/v1/shipping/zones/${id}`, { body });
|
|
671
|
+
}
|
|
672
|
+
async deleteZone(id) {
|
|
673
|
+
return this.client.request("DELETE", `/v1/shipping/zones/${id}`);
|
|
674
|
+
}
|
|
675
|
+
// Rates
|
|
676
|
+
async createRate(zoneId, body, options) {
|
|
677
|
+
return this.client.request("POST", `/v1/shipping/zones/${zoneId}/rates`, { body, ...options });
|
|
678
|
+
}
|
|
679
|
+
async updateRate(id, body) {
|
|
680
|
+
return this.client.request("PATCH", `/v1/shipping/rates/${id}`, { body });
|
|
681
|
+
}
|
|
682
|
+
async deleteRate(id) {
|
|
683
|
+
return this.client.request("DELETE", `/v1/shipping/rates/${id}`);
|
|
684
|
+
}
|
|
685
|
+
/** Get available shipping rates for a destination (public access) */
|
|
686
|
+
async getAvailableRates(body) {
|
|
687
|
+
return this.client.request("POST", "/v1/shipping/rates", { body });
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
// src/resources/promotions.ts
|
|
692
|
+
var PromotionsResource = class {
|
|
693
|
+
constructor(client) {
|
|
694
|
+
this.client = client;
|
|
695
|
+
}
|
|
696
|
+
client;
|
|
697
|
+
async list(params) {
|
|
698
|
+
return this.client.request("GET", "/v1/promotions", { params });
|
|
699
|
+
}
|
|
700
|
+
iterate(params, options) {
|
|
701
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
702
|
+
}
|
|
703
|
+
async toArray(params, options) {
|
|
704
|
+
return toArray(this.iterate(params, options), options);
|
|
705
|
+
}
|
|
706
|
+
async get(id) {
|
|
707
|
+
return this.client.request("GET", `/v1/promotions/${id}`);
|
|
708
|
+
}
|
|
709
|
+
async create(body, options) {
|
|
710
|
+
return this.client.request("POST", "/v1/promotions", { body, ...options });
|
|
711
|
+
}
|
|
712
|
+
async update(id, body) {
|
|
713
|
+
return this.client.request("PATCH", `/v1/promotions/${id}`, { body });
|
|
714
|
+
}
|
|
715
|
+
async delete(id) {
|
|
716
|
+
return this.client.request("DELETE", `/v1/promotions/${id}`);
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
// src/resources/discounts.ts
|
|
721
|
+
var DiscountsResource = class {
|
|
722
|
+
constructor(client) {
|
|
723
|
+
this.client = client;
|
|
724
|
+
}
|
|
725
|
+
client;
|
|
726
|
+
async list(params) {
|
|
727
|
+
return this.client.request("GET", "/v1/discounts", { params });
|
|
728
|
+
}
|
|
729
|
+
iterate(params, options) {
|
|
730
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
731
|
+
}
|
|
732
|
+
async toArray(params, options) {
|
|
733
|
+
return toArray(this.iterate(params, options), options);
|
|
734
|
+
}
|
|
735
|
+
async get(id) {
|
|
736
|
+
return this.client.request("GET", `/v1/discounts/${id}`);
|
|
737
|
+
}
|
|
738
|
+
async create(body, options) {
|
|
739
|
+
return this.client.request("POST", "/v1/discounts", { body, ...options });
|
|
740
|
+
}
|
|
741
|
+
async update(id, body) {
|
|
742
|
+
return this.client.request("PATCH", `/v1/discounts/${id}`, { body });
|
|
743
|
+
}
|
|
744
|
+
async delete(id) {
|
|
745
|
+
return this.client.request("DELETE", `/v1/discounts/${id}`);
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
// src/resources/images.ts
|
|
750
|
+
var ImagesResource = class {
|
|
751
|
+
constructor(client) {
|
|
752
|
+
this.client = client;
|
|
753
|
+
}
|
|
754
|
+
client;
|
|
755
|
+
async list(params) {
|
|
756
|
+
return this.client.request("GET", "/v1/images", { params });
|
|
757
|
+
}
|
|
758
|
+
iterate(params, options) {
|
|
759
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
760
|
+
}
|
|
761
|
+
async toArray(params, options) {
|
|
762
|
+
return toArray(this.iterate(params, options), options);
|
|
763
|
+
}
|
|
764
|
+
/** Upload an image to the store library */
|
|
765
|
+
async upload(formData) {
|
|
766
|
+
return this.client.upload("/v1/images", formData);
|
|
767
|
+
}
|
|
768
|
+
async update(id, body) {
|
|
769
|
+
return this.client.request("PATCH", `/v1/images/${id}`, { body });
|
|
770
|
+
}
|
|
771
|
+
async delete(id) {
|
|
772
|
+
return this.client.request("DELETE", `/v1/images/${id}`);
|
|
773
|
+
}
|
|
774
|
+
async detach(id) {
|
|
775
|
+
return this.client.request("POST", `/v1/images/${id}/detach`);
|
|
776
|
+
}
|
|
777
|
+
async batchDelete(imageIds) {
|
|
778
|
+
return this.client.request("POST", "/v1/images/batch-delete", {
|
|
779
|
+
body: { image_ids: imageIds }
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
async batchDetach(imageIds) {
|
|
783
|
+
return this.client.request("POST", "/v1/images/batch-detach", {
|
|
784
|
+
body: { image_ids: imageIds }
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
async reorder(body) {
|
|
788
|
+
return this.client.request("PATCH", "/v1/images/reorder", { body });
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
// src/resources/webhooks.ts
|
|
793
|
+
var WebhooksResource = class {
|
|
794
|
+
constructor(client) {
|
|
795
|
+
this.client = client;
|
|
796
|
+
}
|
|
797
|
+
client;
|
|
798
|
+
async list(params) {
|
|
799
|
+
return this.client.request("GET", "/v1/webhooks", { params });
|
|
800
|
+
}
|
|
801
|
+
iterate(params, options) {
|
|
802
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
803
|
+
}
|
|
804
|
+
async toArray(params, options) {
|
|
805
|
+
return toArray(this.iterate(params, options), options);
|
|
806
|
+
}
|
|
807
|
+
async get(id) {
|
|
808
|
+
return this.client.request("GET", `/v1/webhooks/${id}`);
|
|
809
|
+
}
|
|
810
|
+
async create(body, options) {
|
|
811
|
+
return this.client.request("POST", "/v1/webhooks", { body, ...options });
|
|
812
|
+
}
|
|
813
|
+
async update(id, body) {
|
|
814
|
+
return this.client.request("PATCH", `/v1/webhooks/${id}`, { body });
|
|
815
|
+
}
|
|
816
|
+
async delete(id) {
|
|
817
|
+
return this.client.request("DELETE", `/v1/webhooks/${id}`);
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
// src/resources/store.ts
|
|
822
|
+
var StoreResource = class {
|
|
823
|
+
constructor(client) {
|
|
824
|
+
this.client = client;
|
|
825
|
+
}
|
|
826
|
+
client;
|
|
827
|
+
async get(params) {
|
|
828
|
+
return this.client.request("GET", "/v1/store", { params });
|
|
829
|
+
}
|
|
830
|
+
async update(body) {
|
|
831
|
+
return this.client.request("PATCH", "/v1/store", { body });
|
|
832
|
+
}
|
|
833
|
+
async getDomainRecord() {
|
|
834
|
+
return this.client.request("GET", "/v1/store/domain/record");
|
|
835
|
+
}
|
|
836
|
+
async verifyDomain() {
|
|
837
|
+
return this.client.request("POST", "/v1/store/domain/verify");
|
|
838
|
+
}
|
|
839
|
+
async publish() {
|
|
840
|
+
return this.client.request("POST", "/v1/store/publish");
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
// src/resources/tags.ts
|
|
845
|
+
var TagsResource = class {
|
|
846
|
+
constructor(client) {
|
|
847
|
+
this.client = client;
|
|
848
|
+
}
|
|
849
|
+
client;
|
|
850
|
+
async list(params) {
|
|
851
|
+
return this.client.request("GET", "/v1/tags", { params });
|
|
852
|
+
}
|
|
853
|
+
iterate(params, options) {
|
|
854
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
855
|
+
}
|
|
856
|
+
async toArray(params, options) {
|
|
857
|
+
return toArray(this.iterate(params, options), options);
|
|
858
|
+
}
|
|
859
|
+
async create(body, options) {
|
|
860
|
+
return this.client.request("POST", "/v1/tags", { body, ...options });
|
|
861
|
+
}
|
|
862
|
+
async update(id, body) {
|
|
863
|
+
return this.client.request("PATCH", `/v1/tags/${id}`, { body });
|
|
864
|
+
}
|
|
865
|
+
async delete(id) {
|
|
866
|
+
return this.client.request("DELETE", `/v1/tags/${id}`);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
// src/resources/redirects.ts
|
|
871
|
+
var RedirectsResource = class {
|
|
872
|
+
constructor(client) {
|
|
873
|
+
this.client = client;
|
|
874
|
+
}
|
|
875
|
+
client;
|
|
876
|
+
async list(params) {
|
|
877
|
+
return this.client.request("GET", "/v1/redirects", { params });
|
|
878
|
+
}
|
|
879
|
+
iterate(params, options) {
|
|
880
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
881
|
+
}
|
|
882
|
+
async toArray(params, options) {
|
|
883
|
+
return toArray(this.iterate(params, options), options);
|
|
884
|
+
}
|
|
885
|
+
async create(body, options) {
|
|
886
|
+
return this.client.request("POST", "/v1/redirects", { body, ...options });
|
|
887
|
+
}
|
|
888
|
+
async lookup(path) {
|
|
889
|
+
return this.client.request("GET", "/v1/redirects/lookup", { params: { path } });
|
|
890
|
+
}
|
|
891
|
+
async delete(id) {
|
|
892
|
+
return this.client.request("DELETE", `/v1/redirects/${id}`);
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
// src/resources/companies.ts
|
|
897
|
+
var CompaniesResource = class {
|
|
898
|
+
constructor(client) {
|
|
899
|
+
this.client = client;
|
|
900
|
+
}
|
|
901
|
+
client;
|
|
902
|
+
async list(params) {
|
|
903
|
+
return this.client.request("GET", "/v1/companies", { params });
|
|
904
|
+
}
|
|
905
|
+
iterate(params, options) {
|
|
906
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
907
|
+
}
|
|
908
|
+
async toArray(params, options) {
|
|
909
|
+
return toArray(this.iterate(params, options), options);
|
|
910
|
+
}
|
|
911
|
+
async get(id, params) {
|
|
912
|
+
return this.client.request("GET", `/v1/companies/${id}`, { params });
|
|
913
|
+
}
|
|
914
|
+
async create(body, options) {
|
|
915
|
+
return this.client.request("POST", "/v1/companies", { body, ...options });
|
|
916
|
+
}
|
|
917
|
+
async update(id, body) {
|
|
918
|
+
return this.client.request("PATCH", `/v1/companies/${id}`, { body });
|
|
919
|
+
}
|
|
920
|
+
async delete(id) {
|
|
921
|
+
return this.client.request("DELETE", `/v1/companies/${id}`);
|
|
922
|
+
}
|
|
923
|
+
// Addresses
|
|
924
|
+
async listAddresses(companyId) {
|
|
925
|
+
return this.client.request("GET", `/v1/companies/${companyId}/addresses`);
|
|
926
|
+
}
|
|
927
|
+
async createAddress(companyId, body) {
|
|
928
|
+
return this.client.request("POST", `/v1/companies/${companyId}/addresses`, { body });
|
|
929
|
+
}
|
|
930
|
+
async updateAddress(companyId, addressId, body) {
|
|
931
|
+
return this.client.request("PATCH", `/v1/companies/${companyId}/addresses/${addressId}`, {
|
|
932
|
+
body
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
async deleteAddress(companyId, addressId) {
|
|
936
|
+
return this.client.request("DELETE", `/v1/companies/${companyId}/addresses/${addressId}`);
|
|
937
|
+
}
|
|
938
|
+
// Contacts
|
|
939
|
+
async listContacts(companyId) {
|
|
940
|
+
return this.client.request("GET", `/v1/companies/${companyId}/contacts`);
|
|
941
|
+
}
|
|
942
|
+
async createContact(companyId, body) {
|
|
943
|
+
return this.client.request("POST", `/v1/companies/${companyId}/contacts`, { body });
|
|
944
|
+
}
|
|
945
|
+
async updateContact(companyId, contactId, body) {
|
|
946
|
+
return this.client.request("PATCH", `/v1/companies/${companyId}/contacts/${contactId}`, {
|
|
947
|
+
body
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
async deleteContact(companyId, contactId) {
|
|
951
|
+
return this.client.request("DELETE", `/v1/companies/${companyId}/contacts/${contactId}`);
|
|
952
|
+
}
|
|
953
|
+
// Notes
|
|
954
|
+
async listNotes(companyId) {
|
|
955
|
+
return this.client.request("GET", `/v1/companies/${companyId}/notes`);
|
|
956
|
+
}
|
|
957
|
+
async createNote(companyId, body) {
|
|
958
|
+
return this.client.request("POST", `/v1/companies/${companyId}/notes`, { body });
|
|
959
|
+
}
|
|
960
|
+
async deleteNote(companyId, noteId) {
|
|
961
|
+
return this.client.request("DELETE", `/v1/companies/${companyId}/notes/${noteId}`);
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
// src/resources/purchase-orders.ts
|
|
966
|
+
var PurchaseOrdersResource = class {
|
|
967
|
+
constructor(client) {
|
|
968
|
+
this.client = client;
|
|
969
|
+
}
|
|
970
|
+
client;
|
|
971
|
+
async list(params) {
|
|
972
|
+
return this.client.request("GET", "/v1/purchase-orders", { params });
|
|
973
|
+
}
|
|
974
|
+
iterate(params, options) {
|
|
975
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
976
|
+
}
|
|
977
|
+
async toArray(params, options) {
|
|
978
|
+
return toArray(this.iterate(params, options), options);
|
|
979
|
+
}
|
|
980
|
+
async get(id, params) {
|
|
981
|
+
return this.client.request("GET", `/v1/purchase-orders/${id}`, { params });
|
|
982
|
+
}
|
|
983
|
+
async create(body, options) {
|
|
984
|
+
return this.client.request("POST", "/v1/purchase-orders", { body, ...options });
|
|
985
|
+
}
|
|
986
|
+
async update(id, body) {
|
|
987
|
+
return this.client.request("PATCH", `/v1/purchase-orders/${id}`, { body });
|
|
988
|
+
}
|
|
989
|
+
async delete(id) {
|
|
990
|
+
return this.client.request("DELETE", `/v1/purchase-orders/${id}`);
|
|
991
|
+
}
|
|
992
|
+
// Item management
|
|
993
|
+
async addItem(purchaseOrderId, body) {
|
|
994
|
+
return this.client.request("POST", `/v1/purchase-orders/${purchaseOrderId}/items`, { body });
|
|
995
|
+
}
|
|
996
|
+
async updateItem(purchaseOrderId, itemId, body) {
|
|
997
|
+
return this.client.request("PATCH", `/v1/purchase-orders/${purchaseOrderId}/items/${itemId}`, {
|
|
998
|
+
body
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
async removeItem(purchaseOrderId, itemId) {
|
|
1002
|
+
return this.client.request("DELETE", `/v1/purchase-orders/${purchaseOrderId}/items/${itemId}`);
|
|
1003
|
+
}
|
|
1004
|
+
// Actions
|
|
1005
|
+
async markOrdered(id) {
|
|
1006
|
+
return this.client.request("POST", `/v1/purchase-orders/${id}/order`);
|
|
1007
|
+
}
|
|
1008
|
+
async receive(id, body) {
|
|
1009
|
+
return this.client.request("POST", `/v1/purchase-orders/${id}/receive`, { body });
|
|
1010
|
+
}
|
|
1011
|
+
async cancel(id) {
|
|
1012
|
+
return this.client.request("POST", `/v1/purchase-orders/${id}/cancel`);
|
|
1013
|
+
}
|
|
1014
|
+
async close(id) {
|
|
1015
|
+
return this.client.request("POST", `/v1/purchase-orders/${id}/close`);
|
|
1016
|
+
}
|
|
1017
|
+
// Metafield sub-resources (on items)
|
|
1018
|
+
async setItemMetafield(purchaseOrderId, itemId, slug, body) {
|
|
1019
|
+
return this.client.request(
|
|
1020
|
+
"PUT",
|
|
1021
|
+
`/v1/purchase-orders/${purchaseOrderId}/items/${itemId}/metafields/${slug}`,
|
|
1022
|
+
{ body }
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
async clearItemMetafield(purchaseOrderId, itemId, slug) {
|
|
1026
|
+
return this.client.request(
|
|
1027
|
+
"DELETE",
|
|
1028
|
+
`/v1/purchase-orders/${purchaseOrderId}/items/${itemId}/metafields/${slug}`
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
// src/resources/fulfillment-orders.ts
|
|
1034
|
+
var FulfillmentOrdersResource = class {
|
|
1035
|
+
constructor(client) {
|
|
1036
|
+
this.client = client;
|
|
1037
|
+
}
|
|
1038
|
+
client;
|
|
1039
|
+
/** List fulfillment orders for an order (use orders.listFulfillmentOrders instead) */
|
|
1040
|
+
async listForOrder(orderId) {
|
|
1041
|
+
return this.client.request("GET", `/v1/orders/${orderId}/fulfillment-orders`);
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1045
|
+
// src/resources/metafields.ts
|
|
1046
|
+
var MetafieldsResource = class {
|
|
1047
|
+
constructor(client) {
|
|
1048
|
+
this.client = client;
|
|
1049
|
+
}
|
|
1050
|
+
client;
|
|
1051
|
+
/** List metafield definitions for the store */
|
|
1052
|
+
async listDefinitions(params) {
|
|
1053
|
+
return this.client.request("GET", "/v1/store/metafields", { params });
|
|
1054
|
+
}
|
|
1055
|
+
async createDefinition(body) {
|
|
1056
|
+
return this.client.request("POST", "/v1/store/metafields", { body });
|
|
1057
|
+
}
|
|
1058
|
+
async updateDefinition(ownerType, slug, body) {
|
|
1059
|
+
return this.client.request("PATCH", `/v1/store/metafields/${ownerType}/${slug}`, { body });
|
|
1060
|
+
}
|
|
1061
|
+
async archiveDefinition(ownerType, slug) {
|
|
1062
|
+
return this.client.request("DELETE", `/v1/store/metafields/${ownerType}/${slug}`);
|
|
1063
|
+
}
|
|
1064
|
+
async reorderDefinitions(ownerType, body) {
|
|
1065
|
+
return this.client.request("PUT", `/v1/store/metafields/${ownerType}/reorder`, { body });
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
// src/resources/tax.ts
|
|
1070
|
+
var TaxResource = class {
|
|
1071
|
+
constructor(client) {
|
|
1072
|
+
this.client = client;
|
|
1073
|
+
}
|
|
1074
|
+
client;
|
|
1075
|
+
// Groups
|
|
1076
|
+
async listGroups(params) {
|
|
1077
|
+
return this.client.request("GET", "/v1/tax/groups", { params });
|
|
1078
|
+
}
|
|
1079
|
+
iterateGroups(params, options) {
|
|
1080
|
+
return paginate((cursor) => this.listGroups({ ...params, cursor }), options);
|
|
1081
|
+
}
|
|
1082
|
+
async groupsToArray(params, options) {
|
|
1083
|
+
return toArray(this.iterateGroups(params, options), options);
|
|
1084
|
+
}
|
|
1085
|
+
async getGroup(id) {
|
|
1086
|
+
return this.client.request("GET", `/v1/tax/groups/${id}`);
|
|
1087
|
+
}
|
|
1088
|
+
async createGroup(body, options) {
|
|
1089
|
+
return this.client.request("POST", "/v1/tax/groups", { body, ...options });
|
|
1090
|
+
}
|
|
1091
|
+
async updateGroup(id, body) {
|
|
1092
|
+
return this.client.request("PATCH", `/v1/tax/groups/${id}`, { body });
|
|
1093
|
+
}
|
|
1094
|
+
async deleteGroup(id) {
|
|
1095
|
+
return this.client.request("DELETE", `/v1/tax/groups/${id}`);
|
|
1096
|
+
}
|
|
1097
|
+
// Rates
|
|
1098
|
+
async listRates(params) {
|
|
1099
|
+
return this.client.request("GET", "/v1/tax/rates", { params });
|
|
1100
|
+
}
|
|
1101
|
+
iterateRates(params, options) {
|
|
1102
|
+
return paginate((cursor) => this.listRates({ ...params, cursor }), options);
|
|
1103
|
+
}
|
|
1104
|
+
async ratesToArray(params, options) {
|
|
1105
|
+
return toArray(this.iterateRates(params, options), options);
|
|
1106
|
+
}
|
|
1107
|
+
async createRate(body, options) {
|
|
1108
|
+
return this.client.request("POST", "/v1/tax/rates", { body, ...options });
|
|
1109
|
+
}
|
|
1110
|
+
async updateRate(id, body) {
|
|
1111
|
+
return this.client.request("PATCH", `/v1/tax/rates/${id}`, { body });
|
|
1112
|
+
}
|
|
1113
|
+
async deleteRate(id) {
|
|
1114
|
+
return this.client.request("DELETE", `/v1/tax/rates/${id}`);
|
|
1115
|
+
}
|
|
1116
|
+
// Exemptions
|
|
1117
|
+
async listExemptions(params) {
|
|
1118
|
+
return this.client.request("GET", "/v1/tax/exemptions", { params });
|
|
1119
|
+
}
|
|
1120
|
+
iterateExemptions(params, options) {
|
|
1121
|
+
return paginate((cursor) => this.listExemptions({ ...params, cursor }), options);
|
|
1122
|
+
}
|
|
1123
|
+
async exemptionsToArray(params, options) {
|
|
1124
|
+
return toArray(this.iterateExemptions(params, options), options);
|
|
1125
|
+
}
|
|
1126
|
+
async createExemption(body, options) {
|
|
1127
|
+
return this.client.request("POST", "/v1/tax/exemptions", { body, ...options });
|
|
1128
|
+
}
|
|
1129
|
+
async deleteExemption(id) {
|
|
1130
|
+
return this.client.request("DELETE", `/v1/tax/exemptions/${id}`);
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
// src/resources/exchange-rates.ts
|
|
1135
|
+
var ExchangeRatesResource = class {
|
|
1136
|
+
constructor(client) {
|
|
1137
|
+
this.client = client;
|
|
1138
|
+
}
|
|
1139
|
+
client;
|
|
1140
|
+
async list(params) {
|
|
1141
|
+
return this.client.request("GET", "/v1/exchange-rates", { params });
|
|
1142
|
+
}
|
|
1143
|
+
async refresh() {
|
|
1144
|
+
return this.client.request("POST", "/v1/exchange-rates/refresh");
|
|
1145
|
+
}
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
// src/resources/navigation.ts
|
|
1149
|
+
var NavigationResource = class {
|
|
1150
|
+
constructor(client) {
|
|
1151
|
+
this.client = client;
|
|
1152
|
+
}
|
|
1153
|
+
client;
|
|
1154
|
+
async list(params) {
|
|
1155
|
+
return this.client.request("GET", "/v1/navigation", { params });
|
|
1156
|
+
}
|
|
1157
|
+
iterate(params, options) {
|
|
1158
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1159
|
+
}
|
|
1160
|
+
async toArray(params, options) {
|
|
1161
|
+
return toArray(this.iterate(params, options), options);
|
|
1162
|
+
}
|
|
1163
|
+
async get(id) {
|
|
1164
|
+
return this.client.request("GET", `/v1/navigation/${id}`);
|
|
1165
|
+
}
|
|
1166
|
+
async create(body, options) {
|
|
1167
|
+
return this.client.request("POST", "/v1/navigation", { body, ...options });
|
|
1168
|
+
}
|
|
1169
|
+
async update(id, body) {
|
|
1170
|
+
return this.client.request("PATCH", `/v1/navigation/${id}`, { body });
|
|
1171
|
+
}
|
|
1172
|
+
async delete(id) {
|
|
1173
|
+
return this.client.request("DELETE", `/v1/navigation/${id}`);
|
|
1174
|
+
}
|
|
1175
|
+
async addItem(menuId, body) {
|
|
1176
|
+
return this.client.request("POST", `/v1/navigation/${menuId}/items`, { body });
|
|
1177
|
+
}
|
|
1178
|
+
async updateItem(menuId, itemId, body) {
|
|
1179
|
+
return this.client.request("PATCH", `/v1/navigation/${menuId}/items/${itemId}`, { body });
|
|
1180
|
+
}
|
|
1181
|
+
async deleteItem(menuId, itemId) {
|
|
1182
|
+
return this.client.request("DELETE", `/v1/navigation/${menuId}/items/${itemId}`);
|
|
1183
|
+
}
|
|
1184
|
+
async reorderItems(menuId, body) {
|
|
1185
|
+
return this.client.request("PATCH", `/v1/navigation/${menuId}/items/reorder`, { body });
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
|
|
1189
|
+
// src/resources/notifications.ts
|
|
1190
|
+
var NotificationsResource = class {
|
|
1191
|
+
constructor(client) {
|
|
1192
|
+
this.client = client;
|
|
1193
|
+
}
|
|
1194
|
+
client;
|
|
1195
|
+
async list(params) {
|
|
1196
|
+
return this.client.request("GET", "/v1/notifications", { params });
|
|
1197
|
+
}
|
|
1198
|
+
iterate(params, options) {
|
|
1199
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1200
|
+
}
|
|
1201
|
+
async toArray(params, options) {
|
|
1202
|
+
return toArray(this.iterate(params, options), options);
|
|
1203
|
+
}
|
|
1204
|
+
async get(id) {
|
|
1205
|
+
return this.client.request("GET", `/v1/notifications/${id}`);
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
// src/resources/checkouts.ts
|
|
1210
|
+
var CheckoutsResource = class {
|
|
1211
|
+
constructor(client) {
|
|
1212
|
+
this.client = client;
|
|
1213
|
+
}
|
|
1214
|
+
client;
|
|
1215
|
+
async list(params) {
|
|
1216
|
+
return this.client.request("GET", "/v1/checkouts", { params });
|
|
1217
|
+
}
|
|
1218
|
+
iterate(params, options) {
|
|
1219
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1220
|
+
}
|
|
1221
|
+
async toArray(params, options) {
|
|
1222
|
+
return toArray(this.iterate(params, options), options);
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
|
|
1226
|
+
// src/resources/analytics.ts
|
|
1227
|
+
var AnalyticsResource = class {
|
|
1228
|
+
constructor(client) {
|
|
1229
|
+
this.client = client;
|
|
1230
|
+
}
|
|
1231
|
+
client;
|
|
1232
|
+
async summary(params) {
|
|
1233
|
+
return this.client.request("GET", "/v1/analytics/summary", { params });
|
|
1234
|
+
}
|
|
1235
|
+
async revenue(params) {
|
|
1236
|
+
return this.client.request("GET", "/v1/analytics/revenue", { params });
|
|
1237
|
+
}
|
|
1238
|
+
async orders(params) {
|
|
1239
|
+
return this.client.request("GET", "/v1/analytics/orders", { params });
|
|
1240
|
+
}
|
|
1241
|
+
async topProducts(params) {
|
|
1242
|
+
return this.client.request("GET", "/v1/analytics/top-products", { params });
|
|
1243
|
+
}
|
|
1244
|
+
async actionItems() {
|
|
1245
|
+
return this.client.request("GET", "/v1/analytics/action-items");
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
|
|
1249
|
+
// src/resources/store-credit.ts
|
|
1250
|
+
var StoreCreditResource = class {
|
|
1251
|
+
constructor(client) {
|
|
1252
|
+
this.client = client;
|
|
1253
|
+
}
|
|
1254
|
+
client;
|
|
1255
|
+
async getBalance(customerId) {
|
|
1256
|
+
return this.client.request("GET", `/v1/customers/${customerId}/credit`);
|
|
1257
|
+
}
|
|
1258
|
+
async issue(customerId, body, options) {
|
|
1259
|
+
return this.client.request("POST", `/v1/customers/${customerId}/credit`, {
|
|
1260
|
+
body,
|
|
1261
|
+
...options
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
async listTransactions(customerId, params) {
|
|
1265
|
+
return this.client.request("GET", `/v1/customers/${customerId}/credit/transactions`, {
|
|
1266
|
+
params
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
iterateTransactions(customerId, params, options) {
|
|
1270
|
+
return paginate(
|
|
1271
|
+
(cursor) => this.listTransactions(customerId, { ...params, cursor }),
|
|
1272
|
+
options
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
async transactionsToArray(customerId, params, options) {
|
|
1276
|
+
return toArray(this.iterateTransactions(customerId, params, options), options);
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
// src/resources/search.ts
|
|
1281
|
+
var SearchResource = class {
|
|
1282
|
+
constructor(client) {
|
|
1283
|
+
this.client = client;
|
|
1284
|
+
}
|
|
1285
|
+
client;
|
|
1286
|
+
async search(params) {
|
|
1287
|
+
return this.client.request("GET", "/v1/search", { params });
|
|
1288
|
+
}
|
|
1289
|
+
async suggest(params) {
|
|
1290
|
+
return this.client.request("GET", "/v1/search/suggest", { params });
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
|
|
1294
|
+
// src/resources/locations.ts
|
|
1295
|
+
var LocationsResource = class {
|
|
1296
|
+
constructor(client) {
|
|
1297
|
+
this.client = client;
|
|
1298
|
+
}
|
|
1299
|
+
client;
|
|
1300
|
+
async list(params) {
|
|
1301
|
+
return this.client.request("GET", "/v1/locations", { params });
|
|
1302
|
+
}
|
|
1303
|
+
iterate(params, options) {
|
|
1304
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1305
|
+
}
|
|
1306
|
+
async toArray(params, options) {
|
|
1307
|
+
return toArray(this.iterate(params, options), options);
|
|
1308
|
+
}
|
|
1309
|
+
async get(id) {
|
|
1310
|
+
return this.client.request("GET", `/v1/locations/${id}`);
|
|
1311
|
+
}
|
|
1312
|
+
async create(body, options) {
|
|
1313
|
+
return this.client.request("POST", "/v1/locations", { body, ...options });
|
|
1314
|
+
}
|
|
1315
|
+
async update(id, body) {
|
|
1316
|
+
return this.client.request("PATCH", `/v1/locations/${id}`, { body });
|
|
1317
|
+
}
|
|
1318
|
+
async delete(id) {
|
|
1319
|
+
return this.client.request("DELETE", `/v1/locations/${id}`);
|
|
1320
|
+
}
|
|
1321
|
+
async setDefault(id) {
|
|
1322
|
+
return this.client.request("POST", `/v1/locations/${id}/default`);
|
|
1323
|
+
}
|
|
1324
|
+
async transfer(id, body) {
|
|
1325
|
+
return this.client.request("POST", `/v1/locations/${id}/transfer`, { body });
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
// src/resources/integrations.ts
|
|
1330
|
+
var IntegrationsResource = class {
|
|
1331
|
+
constructor(client) {
|
|
1332
|
+
this.client = client;
|
|
1333
|
+
}
|
|
1334
|
+
client;
|
|
1335
|
+
async getAccountingStatus() {
|
|
1336
|
+
return this.client.request("GET", "/v1/integrations/accounting/status");
|
|
1337
|
+
}
|
|
1338
|
+
async getAuthorizeUrl() {
|
|
1339
|
+
return this.client.request("GET", "/v1/integrations/accounting/authorize");
|
|
1340
|
+
}
|
|
1341
|
+
async testConnection() {
|
|
1342
|
+
return this.client.request("POST", "/v1/integrations/accounting/test");
|
|
1343
|
+
}
|
|
1344
|
+
async disconnect() {
|
|
1345
|
+
await this.client.request("DELETE", "/v1/integrations/accounting");
|
|
1346
|
+
}
|
|
1347
|
+
async updateSettings(settings) {
|
|
1348
|
+
return this.client.request("PATCH", "/v1/integrations/accounting/settings", {
|
|
1349
|
+
body: settings
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
async syncOrder(orderId) {
|
|
1353
|
+
return this.client.request("POST", `/v1/integrations/accounting/sync/${orderId}`);
|
|
1354
|
+
}
|
|
1355
|
+
async retrySyncOrder(orderId) {
|
|
1356
|
+
return this.client.request("POST", `/v1/integrations/accounting/sync/${orderId}/retry`);
|
|
1357
|
+
}
|
|
1358
|
+
async listSyncLog(params) {
|
|
1359
|
+
return this.client.request("GET", "/v1/integrations/accounting/sync-log", { params });
|
|
1360
|
+
}
|
|
1361
|
+
iterateSyncLog(params, options) {
|
|
1362
|
+
return paginate((cursor) => this.listSyncLog({ ...params, cursor }), options);
|
|
1363
|
+
}
|
|
1364
|
+
async toArraySyncLog(params, options) {
|
|
1365
|
+
return toArray(this.iterateSyncLog(params, options), options);
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
|
|
1369
|
+
// src/client.ts
|
|
1370
|
+
var SDK_VERSION = "0.1.0";
|
|
1371
|
+
var INITIAL_RETRY_DELAY = 0.5;
|
|
1372
|
+
var MAX_RETRY_DELAY = 5;
|
|
1373
|
+
var MAX_RETRY_AFTER = 60;
|
|
1374
|
+
var VALID_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
1375
|
+
"apiKey",
|
|
1376
|
+
"baseUrl",
|
|
1377
|
+
"timeout",
|
|
1378
|
+
"maxNetworkRetries",
|
|
1379
|
+
"appInfo"
|
|
1380
|
+
]);
|
|
1381
|
+
function getRetryDelay(attempt, retryAfter) {
|
|
1382
|
+
let delay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, attempt - 1), MAX_RETRY_DELAY);
|
|
1383
|
+
delay *= 0.5 * (1 + Math.random());
|
|
1384
|
+
delay = Math.max(INITIAL_RETRY_DELAY, delay);
|
|
1385
|
+
if (retryAfter !== void 0 && retryAfter <= MAX_RETRY_AFTER) {
|
|
1386
|
+
delay = Math.max(delay, retryAfter);
|
|
1387
|
+
}
|
|
1388
|
+
return delay * 1e3;
|
|
1389
|
+
}
|
|
1390
|
+
function sleep(ms) {
|
|
1391
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1392
|
+
}
|
|
1393
|
+
var Hydra = class {
|
|
1394
|
+
apiKey;
|
|
1395
|
+
baseUrl;
|
|
1396
|
+
timeout;
|
|
1397
|
+
maxNetworkRetries;
|
|
1398
|
+
appInfo;
|
|
1399
|
+
// P1: Storefront essentials
|
|
1400
|
+
products = new ProductsResource(this);
|
|
1401
|
+
variants = new VariantsResource(this);
|
|
1402
|
+
collections = new CollectionsResource(this);
|
|
1403
|
+
cart = new CartResource(this);
|
|
1404
|
+
checkout = new CheckoutResource(this);
|
|
1405
|
+
checkouts = new CheckoutsResource(this);
|
|
1406
|
+
search = new SearchResource(this);
|
|
1407
|
+
// P2: Order management
|
|
1408
|
+
orders = new OrdersResource(this);
|
|
1409
|
+
fulfillments = new FulfillmentsResource(this);
|
|
1410
|
+
refunds = new RefundsResource(this);
|
|
1411
|
+
returns = new ReturnsResource(this);
|
|
1412
|
+
draftOrders = new DraftOrdersResource(this);
|
|
1413
|
+
// P3: Customers
|
|
1414
|
+
customers = new CustomersResource(this);
|
|
1415
|
+
customerGroups = new CustomerGroupsResource(this);
|
|
1416
|
+
addresses = new AddressesResource(this);
|
|
1417
|
+
storeCredit = new StoreCreditResource(this);
|
|
1418
|
+
// P4: Commerce operations
|
|
1419
|
+
inventory = new InventoryResource(this);
|
|
1420
|
+
shipping = new ShippingResource(this);
|
|
1421
|
+
promotions = new PromotionsResource(this);
|
|
1422
|
+
discounts = new DiscountsResource(this);
|
|
1423
|
+
// P5: Media & integrations
|
|
1424
|
+
images = new ImagesResource(this);
|
|
1425
|
+
webhooks = new WebhooksResource(this);
|
|
1426
|
+
store = new StoreResource(this);
|
|
1427
|
+
tags = new TagsResource(this);
|
|
1428
|
+
redirects = new RedirectsResource(this);
|
|
1429
|
+
// P6: Advanced
|
|
1430
|
+
locations = new LocationsResource(this);
|
|
1431
|
+
companies = new CompaniesResource(this);
|
|
1432
|
+
purchaseOrders = new PurchaseOrdersResource(this);
|
|
1433
|
+
fulfillmentOrders = new FulfillmentOrdersResource(this);
|
|
1434
|
+
metafields = new MetafieldsResource(this);
|
|
1435
|
+
tax = new TaxResource(this);
|
|
1436
|
+
exchangeRates = new ExchangeRatesResource(this);
|
|
1437
|
+
navigation = new NavigationResource(this);
|
|
1438
|
+
notifications = new NotificationsResource(this);
|
|
1439
|
+
analytics = new AnalyticsResource(this);
|
|
1440
|
+
integrations = new IntegrationsResource(this);
|
|
1441
|
+
constructor(config) {
|
|
1442
|
+
for (const key of Object.keys(config)) {
|
|
1443
|
+
if (!VALID_CONFIG_KEYS.has(key)) {
|
|
1444
|
+
throw new Error(
|
|
1445
|
+
`Hydra: unknown config option "${key}". Valid options: ${[...VALID_CONFIG_KEYS].join(", ")}`
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
if (!config.apiKey) {
|
|
1450
|
+
throw new Error("Hydra: apiKey is required");
|
|
1451
|
+
}
|
|
1452
|
+
this.apiKey = config.apiKey;
|
|
1453
|
+
this.baseUrl = config.baseUrl ?? "https://api.hydrajs.dev";
|
|
1454
|
+
this.timeout = config.timeout ?? 8e4;
|
|
1455
|
+
this.maxNetworkRetries = config.maxNetworkRetries ?? 1;
|
|
1456
|
+
this.appInfo = config.appInfo;
|
|
1457
|
+
}
|
|
1458
|
+
async request(method, path, options) {
|
|
1459
|
+
const maxRetries = options?.maxNetworkRetries ?? this.maxNetworkRetries;
|
|
1460
|
+
let idempotencyKey = options?.idempotencyKey;
|
|
1461
|
+
if (method === "POST" && !idempotencyKey && maxRetries > 0) {
|
|
1462
|
+
idempotencyKey = `hydra-retry-${crypto.randomUUID()}`;
|
|
1463
|
+
}
|
|
1464
|
+
let lastError;
|
|
1465
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1466
|
+
try {
|
|
1467
|
+
const res = await this.executeRequest(method, path, {
|
|
1468
|
+
...options,
|
|
1469
|
+
idempotencyKey
|
|
1470
|
+
});
|
|
1471
|
+
if (res.ok) {
|
|
1472
|
+
if (res.status === 204) return void 0;
|
|
1473
|
+
return res.json();
|
|
1474
|
+
}
|
|
1475
|
+
const error = await this.buildError(res);
|
|
1476
|
+
if (!this.shouldRetry(error, attempt, maxRetries)) {
|
|
1477
|
+
throw error;
|
|
1478
|
+
}
|
|
1479
|
+
lastError = error;
|
|
1480
|
+
const retryAfter = error.retryAfter;
|
|
1481
|
+
await sleep(getRetryDelay(attempt + 1, retryAfter));
|
|
1482
|
+
} catch (e) {
|
|
1483
|
+
if (e instanceof HydraError) throw e;
|
|
1484
|
+
if (attempt >= maxRetries) {
|
|
1485
|
+
const message = e instanceof Error ? e.message : "Connection failed";
|
|
1486
|
+
throw new HydraConnectionError(message.includes("abort") ? "Request timed out" : message);
|
|
1487
|
+
}
|
|
1488
|
+
lastError = e instanceof Error ? e : new Error(String(e));
|
|
1489
|
+
await sleep(getRetryDelay(attempt + 1));
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
throw lastError;
|
|
1493
|
+
}
|
|
1494
|
+
/** Multipart upload for file-based endpoints (e.g. images) */
|
|
1495
|
+
async upload(path, formData, options) {
|
|
1496
|
+
const maxRetries = options?.maxNetworkRetries ?? this.maxNetworkRetries;
|
|
1497
|
+
let lastError;
|
|
1498
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1499
|
+
try {
|
|
1500
|
+
const res = await this.executeUpload(path, formData, options);
|
|
1501
|
+
if (res.ok) {
|
|
1502
|
+
return res.json();
|
|
1503
|
+
}
|
|
1504
|
+
const error = await this.buildError(res);
|
|
1505
|
+
if (!this.shouldRetry(error, attempt, maxRetries)) {
|
|
1506
|
+
throw error;
|
|
1507
|
+
}
|
|
1508
|
+
lastError = error;
|
|
1509
|
+
const retryAfter = error.retryAfter;
|
|
1510
|
+
await sleep(getRetryDelay(attempt + 1, retryAfter));
|
|
1511
|
+
} catch (e) {
|
|
1512
|
+
if (e instanceof HydraError) throw e;
|
|
1513
|
+
if (attempt >= maxRetries) {
|
|
1514
|
+
const message = e instanceof Error ? e.message : "Connection failed";
|
|
1515
|
+
throw new HydraConnectionError(message.includes("abort") ? "Request timed out" : message);
|
|
1516
|
+
}
|
|
1517
|
+
lastError = e instanceof Error ? e : new Error(String(e));
|
|
1518
|
+
await sleep(getRetryDelay(attempt + 1));
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
throw lastError;
|
|
1522
|
+
}
|
|
1523
|
+
// ── Private helpers ──
|
|
1524
|
+
executeRequest(method, path, options) {
|
|
1525
|
+
const url = new URL(path, this.baseUrl);
|
|
1526
|
+
if (options?.params) {
|
|
1527
|
+
for (const [key, value] of Object.entries(options.params)) {
|
|
1528
|
+
if (value === void 0 || value === null) continue;
|
|
1529
|
+
if (Array.isArray(value)) {
|
|
1530
|
+
url.searchParams.set(key, value.join(","));
|
|
1531
|
+
} else {
|
|
1532
|
+
url.searchParams.set(key, String(value));
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
const headers = {
|
|
1537
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
1538
|
+
"User-Agent": this.getUserAgent(),
|
|
1539
|
+
...options?.headers
|
|
1540
|
+
};
|
|
1541
|
+
if (options?.body) {
|
|
1542
|
+
headers["Content-Type"] = "application/json";
|
|
1543
|
+
}
|
|
1544
|
+
if (options?.idempotencyKey) {
|
|
1545
|
+
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
1546
|
+
}
|
|
1547
|
+
const { signal, cleanup } = this.buildSignal(options);
|
|
1548
|
+
return fetch(url.toString(), {
|
|
1549
|
+
method,
|
|
1550
|
+
headers,
|
|
1551
|
+
body: options?.body ? JSON.stringify(options.body) : void 0,
|
|
1552
|
+
signal
|
|
1553
|
+
}).finally(cleanup);
|
|
1554
|
+
}
|
|
1555
|
+
executeUpload(path, formData, options) {
|
|
1556
|
+
const url = new URL(path, this.baseUrl);
|
|
1557
|
+
const { signal, cleanup } = this.buildSignal(options);
|
|
1558
|
+
return fetch(url.toString(), {
|
|
1559
|
+
method: "POST",
|
|
1560
|
+
headers: {
|
|
1561
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
1562
|
+
"User-Agent": this.getUserAgent()
|
|
1563
|
+
// No Content-Type — let the runtime set the multipart boundary
|
|
1564
|
+
},
|
|
1565
|
+
body: formData,
|
|
1566
|
+
signal
|
|
1567
|
+
}).finally(cleanup);
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* Build an AbortSignal that fires on timeout OR user-supplied signal,
|
|
1571
|
+
* whichever comes first.
|
|
1572
|
+
*/
|
|
1573
|
+
buildSignal(options) {
|
|
1574
|
+
const timeout = options?.timeout ?? this.timeout;
|
|
1575
|
+
const controller = new AbortController();
|
|
1576
|
+
let timeoutId;
|
|
1577
|
+
if (timeout > 0) {
|
|
1578
|
+
timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
1579
|
+
}
|
|
1580
|
+
if (options?.signal) {
|
|
1581
|
+
if (options.signal.aborted) {
|
|
1582
|
+
controller.abort(options.signal.reason);
|
|
1583
|
+
} else {
|
|
1584
|
+
options.signal.addEventListener("abort", () => controller.abort(options.signal.reason), {
|
|
1585
|
+
once: true
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
return {
|
|
1590
|
+
signal: controller.signal,
|
|
1591
|
+
cleanup: () => {
|
|
1592
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Parse an error response into a typed HydraError subclass.
|
|
1598
|
+
* Non-JSON bodies (CDN 502, proxy HTML) surface the raw text for debuggability.
|
|
1599
|
+
*/
|
|
1600
|
+
async buildError(res) {
|
|
1601
|
+
let body;
|
|
1602
|
+
try {
|
|
1603
|
+
body = await res.json();
|
|
1604
|
+
} catch {
|
|
1605
|
+
const text = await res.text().catch(() => "");
|
|
1606
|
+
return new HydraConnectionError(
|
|
1607
|
+
`Non-JSON error response (HTTP ${res.status}): ${text.slice(0, 200)}`
|
|
1608
|
+
);
|
|
1609
|
+
}
|
|
1610
|
+
switch (res.status) {
|
|
1611
|
+
case 401:
|
|
1612
|
+
return new HydraAuthenticationError(body, res.headers);
|
|
1613
|
+
case 403:
|
|
1614
|
+
return new HydraPermissionError(body, res.headers);
|
|
1615
|
+
case 404:
|
|
1616
|
+
return new HydraNotFoundError(body, res.headers);
|
|
1617
|
+
case 409:
|
|
1618
|
+
return new HydraIdempotencyError(body, res.headers);
|
|
1619
|
+
case 429:
|
|
1620
|
+
return new HydraRateLimitError(body, res.headers);
|
|
1621
|
+
default:
|
|
1622
|
+
if (res.status === 400 && body.error.code === "validation_error") {
|
|
1623
|
+
return new HydraValidationError(body, res.headers);
|
|
1624
|
+
}
|
|
1625
|
+
return new HydraError(body, res.status, res.headers);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* Determine whether a failed request should be retried.
|
|
1630
|
+
* Client errors (400, 401, 403, 404) are never retried — they won't change.
|
|
1631
|
+
*/
|
|
1632
|
+
shouldRetry(error, attempt, maxRetries) {
|
|
1633
|
+
if (attempt >= maxRetries) return false;
|
|
1634
|
+
return error.status === 408 || error.status === 409 || error.status === 429 || error.status >= 500;
|
|
1635
|
+
}
|
|
1636
|
+
getUserAgent() {
|
|
1637
|
+
let ua = `hydra-sdk/${SDK_VERSION}`;
|
|
1638
|
+
if (this.appInfo) {
|
|
1639
|
+
ua += ` ${this.appInfo.name}`;
|
|
1640
|
+
if (this.appInfo.version) ua += `/${this.appInfo.version}`;
|
|
1641
|
+
if (this.appInfo.url) ua += ` (${this.appInfo.url})`;
|
|
1642
|
+
}
|
|
1643
|
+
return ua;
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
export {
|
|
1647
|
+
AddressesResource,
|
|
1648
|
+
AnalyticsResource,
|
|
1649
|
+
CartResource,
|
|
1650
|
+
CheckoutResource,
|
|
1651
|
+
CheckoutsResource,
|
|
1652
|
+
CollectionsResource,
|
|
1653
|
+
CompaniesResource,
|
|
1654
|
+
CustomerGroupsResource,
|
|
1655
|
+
CustomersResource,
|
|
1656
|
+
DiscountsResource,
|
|
1657
|
+
DraftOrdersResource,
|
|
1658
|
+
ExchangeRatesResource,
|
|
1659
|
+
FulfillmentOrdersResource,
|
|
1660
|
+
FulfillmentsResource,
|
|
1661
|
+
Hydra,
|
|
1662
|
+
HydraAuthenticationError,
|
|
1663
|
+
HydraConnectionError,
|
|
1664
|
+
HydraError,
|
|
1665
|
+
HydraIdempotencyError,
|
|
1666
|
+
HydraNotFoundError,
|
|
1667
|
+
HydraPermissionError,
|
|
1668
|
+
HydraRateLimitError,
|
|
1669
|
+
HydraValidationError,
|
|
1670
|
+
ImagesResource,
|
|
1671
|
+
IntegrationsResource,
|
|
1672
|
+
InventoryResource,
|
|
1673
|
+
LocationsResource,
|
|
1674
|
+
MetafieldsResource,
|
|
1675
|
+
NotificationsResource,
|
|
1676
|
+
OrdersResource,
|
|
1677
|
+
ProductsResource,
|
|
1678
|
+
PromotionsResource,
|
|
1679
|
+
PurchaseOrdersResource,
|
|
1680
|
+
RedirectsResource,
|
|
1681
|
+
RefundsResource,
|
|
1682
|
+
ReturnsResource,
|
|
1683
|
+
SearchResource,
|
|
1684
|
+
ShippingResource,
|
|
1685
|
+
StoreCreditResource,
|
|
1686
|
+
StoreResource,
|
|
1687
|
+
TagsResource,
|
|
1688
|
+
TaxResource,
|
|
1689
|
+
VariantsResource,
|
|
1690
|
+
WebhooksResource,
|
|
1691
|
+
paginate,
|
|
1692
|
+
toArray
|
|
1693
|
+
};
|