@onefivecommerce/sdk 0.0.0-stage → 0.10.1
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 +184 -2
- package/dist/index.d.ts +24851 -0
- package/dist/index.js +2636 -0
- package/dist/webhooks.d.ts +31 -0
- package/dist/webhooks.js +20 -0
- package/package.json +50 -5
package/dist/index.js
ADDED
|
@@ -0,0 +1,2636 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var OneFiveError = 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 = "OneFiveError";
|
|
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 OneFiveConnectionError = class extends OneFiveError {
|
|
32
|
+
constructor(message) {
|
|
33
|
+
super({ error: { code: "connection_error", message } }, 0, new Headers());
|
|
34
|
+
this.name = "OneFiveConnectionError";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var OneFiveAuthenticationError = class extends OneFiveError {
|
|
38
|
+
constructor(body, headers) {
|
|
39
|
+
super(body, 401, headers);
|
|
40
|
+
this.name = "OneFiveAuthenticationError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var OneFivePermissionError = class extends OneFiveError {
|
|
44
|
+
constructor(body, headers) {
|
|
45
|
+
super(body, 403, headers);
|
|
46
|
+
this.name = "OneFivePermissionError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var OneFiveNotFoundError = class extends OneFiveError {
|
|
50
|
+
constructor(body, headers) {
|
|
51
|
+
super(body, 404, headers);
|
|
52
|
+
this.name = "OneFiveNotFoundError";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var OneFiveRateLimitError = class extends OneFiveError {
|
|
56
|
+
constructor(body, headers) {
|
|
57
|
+
super(body, 429, headers);
|
|
58
|
+
this.name = "OneFiveRateLimitError";
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var OneFiveValidationError = class extends OneFiveError {
|
|
62
|
+
constructor(body, headers) {
|
|
63
|
+
super(body, 400, headers);
|
|
64
|
+
this.name = "OneFiveValidationError";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var OneFiveIdempotencyError = class extends OneFiveError {
|
|
68
|
+
constructor(body, headers) {
|
|
69
|
+
super(body, 409, headers);
|
|
70
|
+
this.name = "OneFiveIdempotencyError";
|
|
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
|
+
// Linked product sub-resources
|
|
163
|
+
async listLinks(productId) {
|
|
164
|
+
return this.client.request("GET", `/v1/products/${productId}/links`);
|
|
165
|
+
}
|
|
166
|
+
async createLink(productId, body, options) {
|
|
167
|
+
return this.client.request("POST", `/v1/products/${productId}/links`, { body, ...options });
|
|
168
|
+
}
|
|
169
|
+
async deleteLink(productId, targetProductId) {
|
|
170
|
+
return this.client.request("DELETE", `/v1/products/${productId}/links/${targetProductId}`);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/resources/variants.ts
|
|
175
|
+
var VariantsResource = class {
|
|
176
|
+
constructor(client) {
|
|
177
|
+
this.client = client;
|
|
178
|
+
}
|
|
179
|
+
client;
|
|
180
|
+
async get(id, params) {
|
|
181
|
+
return this.client.request("GET", `/v1/variants/${id}`, { params });
|
|
182
|
+
}
|
|
183
|
+
async update(id, body) {
|
|
184
|
+
return this.client.request("PATCH", `/v1/variants/${id}`, { body });
|
|
185
|
+
}
|
|
186
|
+
async delete(id) {
|
|
187
|
+
return this.client.request("DELETE", `/v1/variants/${id}`);
|
|
188
|
+
}
|
|
189
|
+
// Price keys
|
|
190
|
+
async listPrices(variantId) {
|
|
191
|
+
return this.client.request("GET", `/v1/variants/${variantId}/prices`);
|
|
192
|
+
}
|
|
193
|
+
async upsertPrice(variantId, priceKeySlug, body) {
|
|
194
|
+
return this.client.request("PUT", `/v1/variants/${variantId}/prices/${priceKeySlug}`, { body });
|
|
195
|
+
}
|
|
196
|
+
async deletePrice(variantId, priceKeySlug) {
|
|
197
|
+
return this.client.request("DELETE", `/v1/variants/${variantId}/prices/${priceKeySlug}`);
|
|
198
|
+
}
|
|
199
|
+
// Metafield sub-resources
|
|
200
|
+
async setMetafield(variantId, slug, body) {
|
|
201
|
+
return this.client.request("PUT", `/v1/variants/${variantId}/metafields/${slug}`, { body });
|
|
202
|
+
}
|
|
203
|
+
async clearMetafield(variantId, slug) {
|
|
204
|
+
return this.client.request("DELETE", `/v1/variants/${variantId}/metafields/${slug}`);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// src/resources/collections.ts
|
|
209
|
+
var CollectionsResource = class {
|
|
210
|
+
constructor(client) {
|
|
211
|
+
this.client = client;
|
|
212
|
+
}
|
|
213
|
+
client;
|
|
214
|
+
async list(params) {
|
|
215
|
+
return this.client.request("GET", "/v1/collections", { params });
|
|
216
|
+
}
|
|
217
|
+
iterate(params, options) {
|
|
218
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
219
|
+
}
|
|
220
|
+
async toArray(params, options) {
|
|
221
|
+
return toArray(this.iterate(params, options), options);
|
|
222
|
+
}
|
|
223
|
+
async get(id, params) {
|
|
224
|
+
return this.client.request("GET", `/v1/collections/${id}`, { params });
|
|
225
|
+
}
|
|
226
|
+
async create(body, options) {
|
|
227
|
+
return this.client.request("POST", "/v1/collections", { body, ...options });
|
|
228
|
+
}
|
|
229
|
+
async update(id, body) {
|
|
230
|
+
return this.client.request("PATCH", `/v1/collections/${id}`, { body });
|
|
231
|
+
}
|
|
232
|
+
async delete(id) {
|
|
233
|
+
return this.client.request("DELETE", `/v1/collections/${id}`);
|
|
234
|
+
}
|
|
235
|
+
async tree() {
|
|
236
|
+
return this.client.request("GET", "/v1/collections/tree");
|
|
237
|
+
}
|
|
238
|
+
async reorder(body) {
|
|
239
|
+
return this.client.request("PATCH", "/v1/collections/reorder", { body });
|
|
240
|
+
}
|
|
241
|
+
async addProducts(collectionId, body) {
|
|
242
|
+
return this.client.request("POST", `/v1/collections/${collectionId}/products`, { body });
|
|
243
|
+
}
|
|
244
|
+
async reorderProducts(collectionId, body) {
|
|
245
|
+
return this.client.request("PATCH", `/v1/collections/${collectionId}/products/reorder`, {
|
|
246
|
+
body
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
async removeProduct(collectionId, productId) {
|
|
250
|
+
return this.client.request("DELETE", `/v1/collections/${collectionId}/products/${productId}`);
|
|
251
|
+
}
|
|
252
|
+
// Metafield sub-resources
|
|
253
|
+
async setMetafield(collectionId, slug, body) {
|
|
254
|
+
return this.client.request("PUT", `/v1/collections/${collectionId}/metafields/${slug}`, {
|
|
255
|
+
body
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
async clearMetafield(collectionId, slug) {
|
|
259
|
+
return this.client.request("DELETE", `/v1/collections/${collectionId}/metafields/${slug}`);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// src/resources/cart.ts
|
|
264
|
+
var CartResource = class {
|
|
265
|
+
constructor(client) {
|
|
266
|
+
this.client = client;
|
|
267
|
+
}
|
|
268
|
+
client;
|
|
269
|
+
async create() {
|
|
270
|
+
return this.client.request("POST", "/v1/cart");
|
|
271
|
+
}
|
|
272
|
+
async get(id, params) {
|
|
273
|
+
return this.client.request("GET", `/v1/cart/${id}`, { params });
|
|
274
|
+
}
|
|
275
|
+
async addItem(cartId, body) {
|
|
276
|
+
return this.client.request("POST", `/v1/cart/${cartId}/items`, { body });
|
|
277
|
+
}
|
|
278
|
+
async updateItem(cartId, itemId, body) {
|
|
279
|
+
return this.client.request("PATCH", `/v1/cart/${cartId}/items/${itemId}`, { body });
|
|
280
|
+
}
|
|
281
|
+
async removeItem(cartId, itemId) {
|
|
282
|
+
return this.client.request("DELETE", `/v1/cart/${cartId}/items/${itemId}`);
|
|
283
|
+
}
|
|
284
|
+
async clear(cartId) {
|
|
285
|
+
return this.client.request("DELETE", `/v1/cart/${cartId}`);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// src/resources/checkout.ts
|
|
290
|
+
var CheckoutResource = class {
|
|
291
|
+
constructor(client) {
|
|
292
|
+
this.client = client;
|
|
293
|
+
}
|
|
294
|
+
client;
|
|
295
|
+
async create(body, options) {
|
|
296
|
+
return this.client.request("POST", "/v1/checkout", { body, ...options });
|
|
297
|
+
}
|
|
298
|
+
async get(id) {
|
|
299
|
+
return this.client.request("GET", `/v1/checkout/${id}`);
|
|
300
|
+
}
|
|
301
|
+
async applyDiscount(checkoutId, body) {
|
|
302
|
+
return this.client.request("POST", `/v1/checkout/${checkoutId}/discount`, { body });
|
|
303
|
+
}
|
|
304
|
+
async removeDiscount(checkoutId) {
|
|
305
|
+
return this.client.request("DELETE", `/v1/checkout/${checkoutId}/discount`);
|
|
306
|
+
}
|
|
307
|
+
async applyCredit(checkoutId, body) {
|
|
308
|
+
return this.client.request("POST", `/v1/checkout/${checkoutId}/credit`, { body });
|
|
309
|
+
}
|
|
310
|
+
async removeCredit(checkoutId) {
|
|
311
|
+
return this.client.request("DELETE", `/v1/checkout/${checkoutId}/credit`);
|
|
312
|
+
}
|
|
313
|
+
async completeWithCredit(checkoutId) {
|
|
314
|
+
return this.client.request("POST", `/v1/checkout/${checkoutId}/complete`);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Confirm a BYO checkout as paid. Only works for stores in BYO payment mode.
|
|
318
|
+
* Creates the order with financial_status 'paid'.
|
|
319
|
+
*/
|
|
320
|
+
async confirm(checkoutId, body, options) {
|
|
321
|
+
return this.client.request("POST", `/v1/checkout/${checkoutId}/confirm`, {
|
|
322
|
+
body: body ?? {},
|
|
323
|
+
...options
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/resources/orders.ts
|
|
329
|
+
var OrdersResource = class {
|
|
330
|
+
constructor(client) {
|
|
331
|
+
this.client = client;
|
|
332
|
+
}
|
|
333
|
+
client;
|
|
334
|
+
async list(params) {
|
|
335
|
+
return this.client.request("GET", "/v1/orders", { params });
|
|
336
|
+
}
|
|
337
|
+
iterate(params, options) {
|
|
338
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
339
|
+
}
|
|
340
|
+
async toArray(params, options) {
|
|
341
|
+
return toArray(this.iterate(params, options), options);
|
|
342
|
+
}
|
|
343
|
+
async get(id, params) {
|
|
344
|
+
return this.client.request("GET", `/v1/orders/${id}`, { params });
|
|
345
|
+
}
|
|
346
|
+
async create(body, options) {
|
|
347
|
+
return this.client.request("POST", "/v1/orders", { body, ...options });
|
|
348
|
+
}
|
|
349
|
+
async update(id, body) {
|
|
350
|
+
return this.client.request("PATCH", `/v1/orders/${id}`, { body });
|
|
351
|
+
}
|
|
352
|
+
async listFulfillmentOrders(orderId) {
|
|
353
|
+
return this.client.request("GET", `/v1/orders/${orderId}/fulfillment-orders`);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Returns the API path for downloading the invoice PDF for an order.
|
|
357
|
+
* The first request to this endpoint assigns a permanent invoice number.
|
|
358
|
+
*/
|
|
359
|
+
invoiceUrl(orderId) {
|
|
360
|
+
return `/v1/orders/${orderId}/invoice`;
|
|
361
|
+
}
|
|
362
|
+
// Metafield sub-resources
|
|
363
|
+
async setMetafield(orderId, slug, body) {
|
|
364
|
+
return this.client.request("PUT", `/v1/orders/${orderId}/metafields/${slug}`, { body });
|
|
365
|
+
}
|
|
366
|
+
async clearMetafield(orderId, slug) {
|
|
367
|
+
return this.client.request("DELETE", `/v1/orders/${orderId}/metafields/${slug}`);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// src/resources/fulfillments.ts
|
|
372
|
+
var FulfillmentsResource = class {
|
|
373
|
+
constructor(client) {
|
|
374
|
+
this.client = client;
|
|
375
|
+
}
|
|
376
|
+
client;
|
|
377
|
+
/** Create a fulfillment for a fulfillment order */
|
|
378
|
+
async create(fulfillmentOrderId, body, options) {
|
|
379
|
+
return this.client.request(
|
|
380
|
+
"POST",
|
|
381
|
+
`/v1/fulfillment-orders/${fulfillmentOrderId}/fulfillments`,
|
|
382
|
+
{
|
|
383
|
+
body,
|
|
384
|
+
...options
|
|
385
|
+
}
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
async update(id, body) {
|
|
389
|
+
return this.client.request("PATCH", `/v1/fulfillments/${id}`, { body });
|
|
390
|
+
}
|
|
391
|
+
async cancel(id, body) {
|
|
392
|
+
return this.client.request("DELETE", `/v1/fulfillments/${id}`, { body });
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// src/resources/refunds.ts
|
|
397
|
+
var RefundsResource = class {
|
|
398
|
+
constructor(client) {
|
|
399
|
+
this.client = client;
|
|
400
|
+
}
|
|
401
|
+
client;
|
|
402
|
+
async list(params) {
|
|
403
|
+
return this.client.request("GET", "/v1/refunds", { params });
|
|
404
|
+
}
|
|
405
|
+
iterate(params, options) {
|
|
406
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
407
|
+
}
|
|
408
|
+
async toArray(params, options) {
|
|
409
|
+
return toArray(this.iterate(params, options), options);
|
|
410
|
+
}
|
|
411
|
+
async get(id, params) {
|
|
412
|
+
return this.client.request("GET", `/v1/refunds/${id}`, { params });
|
|
413
|
+
}
|
|
414
|
+
async create(orderId, body, options) {
|
|
415
|
+
return this.client.request("POST", `/v1/orders/${orderId}/refunds`, { body, ...options });
|
|
416
|
+
}
|
|
417
|
+
async listByOrder(orderId) {
|
|
418
|
+
return this.client.request("GET", `/v1/orders/${orderId}/refunds`);
|
|
419
|
+
}
|
|
420
|
+
async retry(id) {
|
|
421
|
+
return this.client.request("POST", `/v1/refunds/${id}/retry`);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Returns the API path for downloading the credit note PDF for a refund.
|
|
425
|
+
* The first request to this endpoint assigns a permanent credit note number.
|
|
426
|
+
*/
|
|
427
|
+
creditNoteUrl(id) {
|
|
428
|
+
return `/v1/refunds/${id}/credit-note`;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
// src/resources/returns.ts
|
|
433
|
+
var ReturnsResource = class {
|
|
434
|
+
constructor(client) {
|
|
435
|
+
this.client = client;
|
|
436
|
+
}
|
|
437
|
+
client;
|
|
438
|
+
async list(params) {
|
|
439
|
+
return this.client.request("GET", "/v1/returns", { params });
|
|
440
|
+
}
|
|
441
|
+
iterate(params, options) {
|
|
442
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
443
|
+
}
|
|
444
|
+
async toArray(params, options) {
|
|
445
|
+
return toArray(this.iterate(params, options), options);
|
|
446
|
+
}
|
|
447
|
+
async get(id, params) {
|
|
448
|
+
return this.client.request("GET", `/v1/returns/${id}`, { params });
|
|
449
|
+
}
|
|
450
|
+
async create(orderId, body, options) {
|
|
451
|
+
return this.client.request("POST", `/v1/orders/${orderId}/returns`, { body, ...options });
|
|
452
|
+
}
|
|
453
|
+
async listByOrder(orderId) {
|
|
454
|
+
return this.client.request("GET", `/v1/orders/${orderId}/returns`);
|
|
455
|
+
}
|
|
456
|
+
async approve(id, body) {
|
|
457
|
+
return this.client.request("POST", `/v1/returns/${id}/approve`, { body });
|
|
458
|
+
}
|
|
459
|
+
async receive(id, body) {
|
|
460
|
+
return this.client.request("POST", `/v1/returns/${id}/receive`, { body });
|
|
461
|
+
}
|
|
462
|
+
async close(id) {
|
|
463
|
+
return this.client.request("POST", `/v1/returns/${id}/close`);
|
|
464
|
+
}
|
|
465
|
+
async reject(id, body) {
|
|
466
|
+
return this.client.request("POST", `/v1/returns/${id}/reject`, { body });
|
|
467
|
+
}
|
|
468
|
+
async cancel(id) {
|
|
469
|
+
return this.client.request("POST", `/v1/returns/${id}/cancel`);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
// src/resources/draft-orders.ts
|
|
474
|
+
var DraftOrdersResource = class {
|
|
475
|
+
constructor(client) {
|
|
476
|
+
this.client = client;
|
|
477
|
+
}
|
|
478
|
+
client;
|
|
479
|
+
async list(params) {
|
|
480
|
+
return this.client.request("GET", "/v1/draft-orders", { params });
|
|
481
|
+
}
|
|
482
|
+
iterate(params, options) {
|
|
483
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
484
|
+
}
|
|
485
|
+
async toArray(params, options) {
|
|
486
|
+
return toArray(this.iterate(params, options), options);
|
|
487
|
+
}
|
|
488
|
+
async get(id, params) {
|
|
489
|
+
return this.client.request("GET", `/v1/draft-orders/${id}`, { params });
|
|
490
|
+
}
|
|
491
|
+
async create(body, options) {
|
|
492
|
+
return this.client.request("POST", "/v1/draft-orders", { body, ...options });
|
|
493
|
+
}
|
|
494
|
+
async update(id, body) {
|
|
495
|
+
return this.client.request("PATCH", `/v1/draft-orders/${id}`, { body });
|
|
496
|
+
}
|
|
497
|
+
async delete(id) {
|
|
498
|
+
return this.client.request("DELETE", `/v1/draft-orders/${id}`);
|
|
499
|
+
}
|
|
500
|
+
async addItems(draftOrderId, body) {
|
|
501
|
+
return this.client.request("POST", `/v1/draft-orders/${draftOrderId}/items`, { body });
|
|
502
|
+
}
|
|
503
|
+
async updateItem(draftOrderId, itemId, body) {
|
|
504
|
+
return this.client.request("PATCH", `/v1/draft-orders/${draftOrderId}/items/${itemId}`, {
|
|
505
|
+
body
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
async removeItem(draftOrderId, itemId) {
|
|
509
|
+
return this.client.request("DELETE", `/v1/draft-orders/${draftOrderId}/items/${itemId}`);
|
|
510
|
+
}
|
|
511
|
+
async complete(id) {
|
|
512
|
+
return this.client.request("POST", `/v1/draft-orders/${id}/complete`);
|
|
513
|
+
}
|
|
514
|
+
async send(id, body) {
|
|
515
|
+
return this.client.request("POST", `/v1/draft-orders/${id}/send`, {
|
|
516
|
+
body: body ?? void 0
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
// src/resources/customers.ts
|
|
522
|
+
var CustomersResource = class {
|
|
523
|
+
constructor(client) {
|
|
524
|
+
this.client = client;
|
|
525
|
+
}
|
|
526
|
+
client;
|
|
527
|
+
async list(params) {
|
|
528
|
+
return this.client.request("GET", "/v1/customers", { params });
|
|
529
|
+
}
|
|
530
|
+
iterate(params, options) {
|
|
531
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
532
|
+
}
|
|
533
|
+
async toArray(params, options) {
|
|
534
|
+
return toArray(this.iterate(params, options), options);
|
|
535
|
+
}
|
|
536
|
+
async get(id, params) {
|
|
537
|
+
return this.client.request("GET", `/v1/customers/${id}`, { params });
|
|
538
|
+
}
|
|
539
|
+
async create(body, options) {
|
|
540
|
+
return this.client.request("POST", "/v1/customers", { body, ...options });
|
|
541
|
+
}
|
|
542
|
+
async update(id, body) {
|
|
543
|
+
return this.client.request("PATCH", `/v1/customers/${id}`, { body });
|
|
544
|
+
}
|
|
545
|
+
async delete(id) {
|
|
546
|
+
return this.client.request("DELETE", `/v1/customers/${id}`);
|
|
547
|
+
}
|
|
548
|
+
// Address sub-resources
|
|
549
|
+
async listAddresses(customerId) {
|
|
550
|
+
return this.client.request("GET", `/v1/customers/${customerId}/addresses`);
|
|
551
|
+
}
|
|
552
|
+
async createAddress(customerId, body) {
|
|
553
|
+
return this.client.request("POST", `/v1/customers/${customerId}/addresses`, { body });
|
|
554
|
+
}
|
|
555
|
+
// Note sub-resources
|
|
556
|
+
async listNotes(customerId) {
|
|
557
|
+
return this.client.request("GET", `/v1/customers/${customerId}/notes`);
|
|
558
|
+
}
|
|
559
|
+
async createNote(customerId, body) {
|
|
560
|
+
return this.client.request("POST", `/v1/customers/${customerId}/notes`, { body });
|
|
561
|
+
}
|
|
562
|
+
async deleteNote(customerId, noteId) {
|
|
563
|
+
return this.client.request("DELETE", `/v1/customers/${customerId}/notes/${noteId}`);
|
|
564
|
+
}
|
|
565
|
+
// Metafield sub-resources
|
|
566
|
+
async setMetafield(customerId, slug, body) {
|
|
567
|
+
return this.client.request("PUT", `/v1/customers/${customerId}/metafields/${slug}`, { body });
|
|
568
|
+
}
|
|
569
|
+
async clearMetafield(customerId, slug) {
|
|
570
|
+
return this.client.request("DELETE", `/v1/customers/${customerId}/metafields/${slug}`);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
// src/resources/customer-groups.ts
|
|
575
|
+
var CustomerGroupsResource = class {
|
|
576
|
+
constructor(client) {
|
|
577
|
+
this.client = client;
|
|
578
|
+
}
|
|
579
|
+
client;
|
|
580
|
+
async list(params) {
|
|
581
|
+
return this.client.request("GET", "/v1/customer-groups", { params });
|
|
582
|
+
}
|
|
583
|
+
iterate(params, options) {
|
|
584
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
585
|
+
}
|
|
586
|
+
async toArray(params, options) {
|
|
587
|
+
return toArray(this.iterate(params, options), options);
|
|
588
|
+
}
|
|
589
|
+
async get(id) {
|
|
590
|
+
return this.client.request("GET", `/v1/customer-groups/${id}`);
|
|
591
|
+
}
|
|
592
|
+
async create(body, options) {
|
|
593
|
+
return this.client.request("POST", "/v1/customer-groups", { body, ...options });
|
|
594
|
+
}
|
|
595
|
+
async update(id, body) {
|
|
596
|
+
return this.client.request("PATCH", `/v1/customer-groups/${id}`, { body });
|
|
597
|
+
}
|
|
598
|
+
async delete(id) {
|
|
599
|
+
return this.client.request("DELETE", `/v1/customer-groups/${id}`);
|
|
600
|
+
}
|
|
601
|
+
async addMembers(groupId, body) {
|
|
602
|
+
return this.client.request("POST", `/v1/customer-groups/${groupId}/members`, { body });
|
|
603
|
+
}
|
|
604
|
+
async removeMember(groupId, customerId) {
|
|
605
|
+
return this.client.request("DELETE", `/v1/customer-groups/${groupId}/members/${customerId}`);
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// src/resources/customer-photos.ts
|
|
610
|
+
var CustomerPhotosResource = class {
|
|
611
|
+
constructor(client) {
|
|
612
|
+
this.client = client;
|
|
613
|
+
}
|
|
614
|
+
client;
|
|
615
|
+
/**
|
|
616
|
+
* List customer photos (secret key only).
|
|
617
|
+
* Filter by product, status, etc.
|
|
618
|
+
*/
|
|
619
|
+
async list(params) {
|
|
620
|
+
return this.client.request("GET", "/v1/customer-photos", { params });
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Iterate through all customer photos with automatic pagination.
|
|
624
|
+
*/
|
|
625
|
+
iterate(params, options) {
|
|
626
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Fetch all customer photos as an array (use with caution on large datasets).
|
|
630
|
+
*/
|
|
631
|
+
async toArray(params, options) {
|
|
632
|
+
return toArray(this.iterate(params, options), options);
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Upload a customer photo (publishable or secret key).
|
|
636
|
+
* Accepts FormData with: image, product_id, credit, link_url, link_text, alt_text, customer_email.
|
|
637
|
+
*/
|
|
638
|
+
async upload(formData) {
|
|
639
|
+
return this.client.upload("/v1/customer-photos", formData);
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Get a single customer photo by ID (secret key only).
|
|
643
|
+
*/
|
|
644
|
+
async get(id) {
|
|
645
|
+
return this.client.request("GET", `/v1/customer-photos/${id}`);
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Update customer photo metadata (secret key only).
|
|
649
|
+
* Fields: credit, link_url, link_text, alt_text, show_in_gallery.
|
|
650
|
+
*/
|
|
651
|
+
async update(id, body) {
|
|
652
|
+
return this.client.request("PATCH", `/v1/customer-photos/${id}`, { body });
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Approve a customer photo (secret key only).
|
|
656
|
+
* Sets status to 'approved' and makes it visible on storefront.
|
|
657
|
+
*/
|
|
658
|
+
async approve(id) {
|
|
659
|
+
return this.client.request("POST", `/v1/customer-photos/${id}/approve`);
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Reject a customer photo (secret key only).
|
|
663
|
+
* Sets status to 'rejected'. Optionally include rejection notes.
|
|
664
|
+
*/
|
|
665
|
+
async reject(id, body) {
|
|
666
|
+
return this.client.request("POST", `/v1/customer-photos/${id}/reject`, { body });
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Delete a customer photo (soft delete, secret key only).
|
|
670
|
+
*/
|
|
671
|
+
async delete(id) {
|
|
672
|
+
return this.client.request("DELETE", `/v1/customer-photos/${id}`);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Replace the image file on an existing customer photo (secret key only).
|
|
676
|
+
* Preserves all metadata, approval status, and moderation history.
|
|
677
|
+
*/
|
|
678
|
+
async replaceImage(id, formData) {
|
|
679
|
+
return this.client.upload(`/v1/customer-photos/${id}/replace-image`, formData);
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Get approved customer photos for a product (storefront-safe, publishable key works).
|
|
683
|
+
* Returns up to 24 approved photos for display on product pages.
|
|
684
|
+
*/
|
|
685
|
+
async getForProduct(productId) {
|
|
686
|
+
return this.client.request("GET", `/v1/products/${productId}/customer-photos`);
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
// src/resources/addresses.ts
|
|
691
|
+
var AddressesResource = class {
|
|
692
|
+
constructor(client) {
|
|
693
|
+
this.client = client;
|
|
694
|
+
}
|
|
695
|
+
client;
|
|
696
|
+
async update(id, body) {
|
|
697
|
+
return this.client.request("PATCH", `/v1/addresses/${id}`, { body });
|
|
698
|
+
}
|
|
699
|
+
async delete(id) {
|
|
700
|
+
return this.client.request("DELETE", `/v1/addresses/${id}`);
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
// src/resources/inventory.ts
|
|
705
|
+
var InventoryResource = class {
|
|
706
|
+
constructor(client) {
|
|
707
|
+
this.client = client;
|
|
708
|
+
}
|
|
709
|
+
client;
|
|
710
|
+
async list(params) {
|
|
711
|
+
return this.client.request("GET", "/v1/inventory", { params });
|
|
712
|
+
}
|
|
713
|
+
iterate(params, options) {
|
|
714
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
715
|
+
}
|
|
716
|
+
async toArray(params, options) {
|
|
717
|
+
return toArray(this.iterate(params, options), options);
|
|
718
|
+
}
|
|
719
|
+
async listAdjustments(params) {
|
|
720
|
+
return this.client.request("GET", "/v1/inventory/adjustments", { params });
|
|
721
|
+
}
|
|
722
|
+
iterateAdjustments(params, options) {
|
|
723
|
+
return paginate((cursor) => this.listAdjustments({ ...params, cursor }), options);
|
|
724
|
+
}
|
|
725
|
+
async adjustmentsToArray(params, options) {
|
|
726
|
+
return toArray(this.iterateAdjustments(params, options), options);
|
|
727
|
+
}
|
|
728
|
+
async set(variantId, body) {
|
|
729
|
+
return this.client.request("PATCH", `/v1/inventory/${variantId}`, { body });
|
|
730
|
+
}
|
|
731
|
+
async adjust(variantId, body) {
|
|
732
|
+
return this.client.request("POST", `/v1/inventory/${variantId}/adjust`, { body });
|
|
733
|
+
}
|
|
734
|
+
async listVariantAdjustments(variantId, params) {
|
|
735
|
+
return this.client.request("GET", `/v1/inventory/${variantId}/adjustments`, { params });
|
|
736
|
+
}
|
|
737
|
+
iterateVariantAdjustments(variantId, params, options) {
|
|
738
|
+
return paginate(
|
|
739
|
+
(cursor) => this.listVariantAdjustments(variantId, { ...params, cursor }),
|
|
740
|
+
options
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
async variantAdjustmentsToArray(variantId, params, options) {
|
|
744
|
+
return toArray(this.iterateVariantAdjustments(variantId, params, options), options);
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
// src/resources/shipping.ts
|
|
749
|
+
var ShippingResource = class {
|
|
750
|
+
constructor(client) {
|
|
751
|
+
this.client = client;
|
|
752
|
+
}
|
|
753
|
+
client;
|
|
754
|
+
// Zones
|
|
755
|
+
async listZones(params) {
|
|
756
|
+
return this.client.request("GET", "/v1/shipping/zones", { params });
|
|
757
|
+
}
|
|
758
|
+
iterateZones(params, options) {
|
|
759
|
+
return paginate((cursor) => this.listZones({ ...params, cursor }), options);
|
|
760
|
+
}
|
|
761
|
+
async zonesToArray(params, options) {
|
|
762
|
+
return toArray(this.iterateZones(params, options), options);
|
|
763
|
+
}
|
|
764
|
+
async getZone(id, params) {
|
|
765
|
+
return this.client.request("GET", `/v1/shipping/zones/${id}`, { params });
|
|
766
|
+
}
|
|
767
|
+
async createZone(body, options) {
|
|
768
|
+
return this.client.request("POST", "/v1/shipping/zones", { body, ...options });
|
|
769
|
+
}
|
|
770
|
+
async updateZone(id, body) {
|
|
771
|
+
return this.client.request("PATCH", `/v1/shipping/zones/${id}`, { body });
|
|
772
|
+
}
|
|
773
|
+
async deleteZone(id) {
|
|
774
|
+
return this.client.request("DELETE", `/v1/shipping/zones/${id}`);
|
|
775
|
+
}
|
|
776
|
+
// Rates
|
|
777
|
+
async createRate(zoneId, body, options) {
|
|
778
|
+
return this.client.request("POST", `/v1/shipping/zones/${zoneId}/rates`, { body, ...options });
|
|
779
|
+
}
|
|
780
|
+
async updateRate(id, body) {
|
|
781
|
+
return this.client.request("PATCH", `/v1/shipping/rates/${id}`, { body });
|
|
782
|
+
}
|
|
783
|
+
async deleteRate(id) {
|
|
784
|
+
return this.client.request("DELETE", `/v1/shipping/rates/${id}`);
|
|
785
|
+
}
|
|
786
|
+
/** Get available shipping rates for a destination (public access) */
|
|
787
|
+
async getAvailableRates(body) {
|
|
788
|
+
return this.client.request("POST", "/v1/shipping/rates", { body });
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
// src/resources/promotions.ts
|
|
793
|
+
var PromotionsResource = class {
|
|
794
|
+
constructor(client) {
|
|
795
|
+
this.client = client;
|
|
796
|
+
}
|
|
797
|
+
client;
|
|
798
|
+
async list(params) {
|
|
799
|
+
return this.client.request("GET", "/v1/promotions", { 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/promotions/${id}`);
|
|
809
|
+
}
|
|
810
|
+
async create(body, options) {
|
|
811
|
+
return this.client.request("POST", "/v1/promotions", { body, ...options });
|
|
812
|
+
}
|
|
813
|
+
async update(id, body) {
|
|
814
|
+
return this.client.request("PATCH", `/v1/promotions/${id}`, { body });
|
|
815
|
+
}
|
|
816
|
+
async delete(id) {
|
|
817
|
+
return this.client.request("DELETE", `/v1/promotions/${id}`);
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
// src/resources/discounts.ts
|
|
822
|
+
var DiscountsResource = class {
|
|
823
|
+
constructor(client) {
|
|
824
|
+
this.client = client;
|
|
825
|
+
}
|
|
826
|
+
client;
|
|
827
|
+
async list(params) {
|
|
828
|
+
return this.client.request("GET", "/v1/discounts", { params });
|
|
829
|
+
}
|
|
830
|
+
iterate(params, options) {
|
|
831
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
832
|
+
}
|
|
833
|
+
async toArray(params, options) {
|
|
834
|
+
return toArray(this.iterate(params, options), options);
|
|
835
|
+
}
|
|
836
|
+
async get(id) {
|
|
837
|
+
return this.client.request("GET", `/v1/discounts/${id}`);
|
|
838
|
+
}
|
|
839
|
+
async create(body, options) {
|
|
840
|
+
return this.client.request("POST", "/v1/discounts", { body, ...options });
|
|
841
|
+
}
|
|
842
|
+
async update(id, body) {
|
|
843
|
+
return this.client.request("PATCH", `/v1/discounts/${id}`, { body });
|
|
844
|
+
}
|
|
845
|
+
async delete(id) {
|
|
846
|
+
return this.client.request("DELETE", `/v1/discounts/${id}`);
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
// src/resources/images.ts
|
|
851
|
+
var ImagesResource = class {
|
|
852
|
+
constructor(client) {
|
|
853
|
+
this.client = client;
|
|
854
|
+
}
|
|
855
|
+
client;
|
|
856
|
+
async list(params) {
|
|
857
|
+
return this.client.request("GET", "/v1/images", { params });
|
|
858
|
+
}
|
|
859
|
+
iterate(params, options) {
|
|
860
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
861
|
+
}
|
|
862
|
+
async toArray(params, options) {
|
|
863
|
+
return toArray(this.iterate(params, options), options);
|
|
864
|
+
}
|
|
865
|
+
/** Upload an image to the store library */
|
|
866
|
+
async upload(formData) {
|
|
867
|
+
return this.client.upload("/v1/images", formData);
|
|
868
|
+
}
|
|
869
|
+
async update(id, body) {
|
|
870
|
+
return this.client.request("PATCH", `/v1/images/${id}`, { body });
|
|
871
|
+
}
|
|
872
|
+
async delete(id) {
|
|
873
|
+
return this.client.request("DELETE", `/v1/images/${id}`);
|
|
874
|
+
}
|
|
875
|
+
async detach(id) {
|
|
876
|
+
return this.client.request("POST", `/v1/images/${id}/detach`);
|
|
877
|
+
}
|
|
878
|
+
async batchDelete(imageIds) {
|
|
879
|
+
return this.client.request("POST", "/v1/images/batch-delete", {
|
|
880
|
+
body: { image_ids: imageIds }
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
async batchDetach(imageIds) {
|
|
884
|
+
return this.client.request("POST", "/v1/images/batch-detach", {
|
|
885
|
+
body: { image_ids: imageIds }
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
async reorder(body) {
|
|
889
|
+
return this.client.request("PATCH", "/v1/images/reorder", { body });
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
// src/resources/webhooks.ts
|
|
894
|
+
var WebhooksResource = class {
|
|
895
|
+
constructor(client) {
|
|
896
|
+
this.client = client;
|
|
897
|
+
}
|
|
898
|
+
client;
|
|
899
|
+
async list(params) {
|
|
900
|
+
return this.client.request("GET", "/v1/webhooks", { params });
|
|
901
|
+
}
|
|
902
|
+
iterate(params, options) {
|
|
903
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
904
|
+
}
|
|
905
|
+
async toArray(params, options) {
|
|
906
|
+
return toArray(this.iterate(params, options), options);
|
|
907
|
+
}
|
|
908
|
+
async get(id) {
|
|
909
|
+
return this.client.request("GET", `/v1/webhooks/${id}`);
|
|
910
|
+
}
|
|
911
|
+
async create(body, options) {
|
|
912
|
+
return this.client.request("POST", "/v1/webhooks", { body, ...options });
|
|
913
|
+
}
|
|
914
|
+
async update(id, body) {
|
|
915
|
+
return this.client.request("PATCH", `/v1/webhooks/${id}`, { body });
|
|
916
|
+
}
|
|
917
|
+
async delete(id) {
|
|
918
|
+
return this.client.request("DELETE", `/v1/webhooks/${id}`);
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
// src/resources/store.ts
|
|
923
|
+
var StoreResource = class {
|
|
924
|
+
constructor(client) {
|
|
925
|
+
this.client = client;
|
|
926
|
+
}
|
|
927
|
+
client;
|
|
928
|
+
async get(params) {
|
|
929
|
+
return this.client.request("GET", "/v1/store", { params });
|
|
930
|
+
}
|
|
931
|
+
async update(body) {
|
|
932
|
+
return this.client.request("PATCH", "/v1/store", { body });
|
|
933
|
+
}
|
|
934
|
+
async getDomainRecord() {
|
|
935
|
+
return this.client.request("GET", "/v1/store/domain/record");
|
|
936
|
+
}
|
|
937
|
+
async verifyDomain() {
|
|
938
|
+
return this.client.request("POST", "/v1/store/domain/verify");
|
|
939
|
+
}
|
|
940
|
+
async publish() {
|
|
941
|
+
return this.client.request("POST", "/v1/store/publish");
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
// src/resources/tags.ts
|
|
946
|
+
var TagsResource = class {
|
|
947
|
+
constructor(client) {
|
|
948
|
+
this.client = client;
|
|
949
|
+
}
|
|
950
|
+
client;
|
|
951
|
+
async list(params) {
|
|
952
|
+
return this.client.request("GET", "/v1/tags", { params });
|
|
953
|
+
}
|
|
954
|
+
iterate(params, options) {
|
|
955
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
956
|
+
}
|
|
957
|
+
async toArray(params, options) {
|
|
958
|
+
return toArray(this.iterate(params, options), options);
|
|
959
|
+
}
|
|
960
|
+
async create(body, options) {
|
|
961
|
+
return this.client.request("POST", "/v1/tags", { body, ...options });
|
|
962
|
+
}
|
|
963
|
+
async update(id, body) {
|
|
964
|
+
return this.client.request("PATCH", `/v1/tags/${id}`, { body });
|
|
965
|
+
}
|
|
966
|
+
async delete(id) {
|
|
967
|
+
return this.client.request("DELETE", `/v1/tags/${id}`);
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
|
|
971
|
+
// src/resources/redirects.ts
|
|
972
|
+
var RedirectsResource = class {
|
|
973
|
+
constructor(client) {
|
|
974
|
+
this.client = client;
|
|
975
|
+
}
|
|
976
|
+
client;
|
|
977
|
+
async list(params) {
|
|
978
|
+
return this.client.request("GET", "/v1/redirects", { params });
|
|
979
|
+
}
|
|
980
|
+
iterate(params, options) {
|
|
981
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
982
|
+
}
|
|
983
|
+
async toArray(params, options) {
|
|
984
|
+
return toArray(this.iterate(params, options), options);
|
|
985
|
+
}
|
|
986
|
+
async create(body, options) {
|
|
987
|
+
return this.client.request("POST", "/v1/redirects", { body, ...options });
|
|
988
|
+
}
|
|
989
|
+
async lookup(path) {
|
|
990
|
+
return this.client.request("GET", "/v1/redirects/lookup", { params: { path } });
|
|
991
|
+
}
|
|
992
|
+
async delete(id) {
|
|
993
|
+
return this.client.request("DELETE", `/v1/redirects/${id}`);
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
// src/resources/companies.ts
|
|
998
|
+
var CompaniesResource = class {
|
|
999
|
+
constructor(client) {
|
|
1000
|
+
this.client = client;
|
|
1001
|
+
}
|
|
1002
|
+
client;
|
|
1003
|
+
async list(params) {
|
|
1004
|
+
return this.client.request("GET", "/v1/companies", { params });
|
|
1005
|
+
}
|
|
1006
|
+
iterate(params, options) {
|
|
1007
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1008
|
+
}
|
|
1009
|
+
async toArray(params, options) {
|
|
1010
|
+
return toArray(this.iterate(params, options), options);
|
|
1011
|
+
}
|
|
1012
|
+
async get(id, params) {
|
|
1013
|
+
return this.client.request("GET", `/v1/companies/${id}`, { params });
|
|
1014
|
+
}
|
|
1015
|
+
async create(body, options) {
|
|
1016
|
+
return this.client.request("POST", "/v1/companies", { body, ...options });
|
|
1017
|
+
}
|
|
1018
|
+
async update(id, body) {
|
|
1019
|
+
return this.client.request("PATCH", `/v1/companies/${id}`, { body });
|
|
1020
|
+
}
|
|
1021
|
+
async delete(id) {
|
|
1022
|
+
return this.client.request("DELETE", `/v1/companies/${id}`);
|
|
1023
|
+
}
|
|
1024
|
+
// Addresses
|
|
1025
|
+
async listAddresses(companyId) {
|
|
1026
|
+
return this.client.request("GET", `/v1/companies/${companyId}/addresses`);
|
|
1027
|
+
}
|
|
1028
|
+
async createAddress(companyId, body) {
|
|
1029
|
+
return this.client.request("POST", `/v1/companies/${companyId}/addresses`, { body });
|
|
1030
|
+
}
|
|
1031
|
+
async updateAddress(companyId, addressId, body) {
|
|
1032
|
+
return this.client.request("PATCH", `/v1/companies/${companyId}/addresses/${addressId}`, {
|
|
1033
|
+
body
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
async deleteAddress(companyId, addressId) {
|
|
1037
|
+
return this.client.request("DELETE", `/v1/companies/${companyId}/addresses/${addressId}`);
|
|
1038
|
+
}
|
|
1039
|
+
// Contacts
|
|
1040
|
+
async listContacts(companyId) {
|
|
1041
|
+
return this.client.request("GET", `/v1/companies/${companyId}/contacts`);
|
|
1042
|
+
}
|
|
1043
|
+
async createContact(companyId, body) {
|
|
1044
|
+
return this.client.request("POST", `/v1/companies/${companyId}/contacts`, { body });
|
|
1045
|
+
}
|
|
1046
|
+
async updateContact(companyId, contactId, body) {
|
|
1047
|
+
return this.client.request("PATCH", `/v1/companies/${companyId}/contacts/${contactId}`, {
|
|
1048
|
+
body
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
async deleteContact(companyId, contactId) {
|
|
1052
|
+
return this.client.request("DELETE", `/v1/companies/${companyId}/contacts/${contactId}`);
|
|
1053
|
+
}
|
|
1054
|
+
// Notes
|
|
1055
|
+
async listNotes(companyId) {
|
|
1056
|
+
return this.client.request("GET", `/v1/companies/${companyId}/notes`);
|
|
1057
|
+
}
|
|
1058
|
+
async createNote(companyId, body) {
|
|
1059
|
+
return this.client.request("POST", `/v1/companies/${companyId}/notes`, { body });
|
|
1060
|
+
}
|
|
1061
|
+
async deleteNote(companyId, noteId) {
|
|
1062
|
+
return this.client.request("DELETE", `/v1/companies/${companyId}/notes/${noteId}`);
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
// src/resources/purchase-orders.ts
|
|
1067
|
+
var PurchaseOrdersResource = class {
|
|
1068
|
+
constructor(client) {
|
|
1069
|
+
this.client = client;
|
|
1070
|
+
}
|
|
1071
|
+
client;
|
|
1072
|
+
async list(params) {
|
|
1073
|
+
return this.client.request("GET", "/v1/purchase-orders", { params });
|
|
1074
|
+
}
|
|
1075
|
+
iterate(params, options) {
|
|
1076
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1077
|
+
}
|
|
1078
|
+
async toArray(params, options) {
|
|
1079
|
+
return toArray(this.iterate(params, options), options);
|
|
1080
|
+
}
|
|
1081
|
+
async get(id, params) {
|
|
1082
|
+
return this.client.request("GET", `/v1/purchase-orders/${id}`, { params });
|
|
1083
|
+
}
|
|
1084
|
+
async create(body, options) {
|
|
1085
|
+
return this.client.request("POST", "/v1/purchase-orders", { body, ...options });
|
|
1086
|
+
}
|
|
1087
|
+
async update(id, body) {
|
|
1088
|
+
return this.client.request("PATCH", `/v1/purchase-orders/${id}`, { body });
|
|
1089
|
+
}
|
|
1090
|
+
async delete(id) {
|
|
1091
|
+
return this.client.request("DELETE", `/v1/purchase-orders/${id}`);
|
|
1092
|
+
}
|
|
1093
|
+
// Item management
|
|
1094
|
+
async addItem(purchaseOrderId, body) {
|
|
1095
|
+
return this.client.request("POST", `/v1/purchase-orders/${purchaseOrderId}/items`, { body });
|
|
1096
|
+
}
|
|
1097
|
+
async updateItem(purchaseOrderId, itemId, body) {
|
|
1098
|
+
return this.client.request("PATCH", `/v1/purchase-orders/${purchaseOrderId}/items/${itemId}`, {
|
|
1099
|
+
body
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
async removeItem(purchaseOrderId, itemId) {
|
|
1103
|
+
return this.client.request("DELETE", `/v1/purchase-orders/${purchaseOrderId}/items/${itemId}`);
|
|
1104
|
+
}
|
|
1105
|
+
// Actions
|
|
1106
|
+
async markOrdered(id) {
|
|
1107
|
+
return this.client.request("POST", `/v1/purchase-orders/${id}/order`);
|
|
1108
|
+
}
|
|
1109
|
+
async receive(id, body) {
|
|
1110
|
+
return this.client.request("POST", `/v1/purchase-orders/${id}/receive`, { body });
|
|
1111
|
+
}
|
|
1112
|
+
async cancel(id) {
|
|
1113
|
+
return this.client.request("POST", `/v1/purchase-orders/${id}/cancel`);
|
|
1114
|
+
}
|
|
1115
|
+
async close(id) {
|
|
1116
|
+
return this.client.request("POST", `/v1/purchase-orders/${id}/close`);
|
|
1117
|
+
}
|
|
1118
|
+
// Metafield sub-resources (on items)
|
|
1119
|
+
async setItemMetafield(purchaseOrderId, itemId, slug, body) {
|
|
1120
|
+
return this.client.request(
|
|
1121
|
+
"PUT",
|
|
1122
|
+
`/v1/purchase-orders/${purchaseOrderId}/items/${itemId}/metafields/${slug}`,
|
|
1123
|
+
{ body }
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
async clearItemMetafield(purchaseOrderId, itemId, slug) {
|
|
1127
|
+
return this.client.request(
|
|
1128
|
+
"DELETE",
|
|
1129
|
+
`/v1/purchase-orders/${purchaseOrderId}/items/${itemId}/metafields/${slug}`
|
|
1130
|
+
);
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
// src/resources/fulfillment-orders.ts
|
|
1135
|
+
var FulfillmentOrdersResource = class {
|
|
1136
|
+
constructor(client) {
|
|
1137
|
+
this.client = client;
|
|
1138
|
+
}
|
|
1139
|
+
client;
|
|
1140
|
+
/** List fulfillment orders for an order (use orders.listFulfillmentOrders instead) */
|
|
1141
|
+
async listForOrder(orderId) {
|
|
1142
|
+
return this.client.request("GET", `/v1/orders/${orderId}/fulfillment-orders`);
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
// src/resources/metafields.ts
|
|
1147
|
+
var MetafieldsResource = class {
|
|
1148
|
+
constructor(client) {
|
|
1149
|
+
this.client = client;
|
|
1150
|
+
}
|
|
1151
|
+
client;
|
|
1152
|
+
/** List metafield definitions for the store */
|
|
1153
|
+
async listDefinitions(params) {
|
|
1154
|
+
return this.client.request("GET", "/v1/store/metafields", { params });
|
|
1155
|
+
}
|
|
1156
|
+
async createDefinition(body) {
|
|
1157
|
+
return this.client.request("POST", "/v1/store/metafields", { body });
|
|
1158
|
+
}
|
|
1159
|
+
async updateDefinition(ownerType, slug, body) {
|
|
1160
|
+
return this.client.request("PATCH", `/v1/store/metafields/${ownerType}/${slug}`, { body });
|
|
1161
|
+
}
|
|
1162
|
+
async archiveDefinition(ownerType, slug) {
|
|
1163
|
+
return this.client.request("DELETE", `/v1/store/metafields/${ownerType}/${slug}`);
|
|
1164
|
+
}
|
|
1165
|
+
async reorderDefinitions(ownerType, body) {
|
|
1166
|
+
return this.client.request("PUT", `/v1/store/metafields/${ownerType}/reorder`, { body });
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
// src/resources/tax.ts
|
|
1171
|
+
var TaxResource = class {
|
|
1172
|
+
constructor(client) {
|
|
1173
|
+
this.client = client;
|
|
1174
|
+
}
|
|
1175
|
+
client;
|
|
1176
|
+
// Groups
|
|
1177
|
+
async listGroups(params) {
|
|
1178
|
+
return this.client.request("GET", "/v1/tax/groups", { params });
|
|
1179
|
+
}
|
|
1180
|
+
iterateGroups(params, options) {
|
|
1181
|
+
return paginate((cursor) => this.listGroups({ ...params, cursor }), options);
|
|
1182
|
+
}
|
|
1183
|
+
async groupsToArray(params, options) {
|
|
1184
|
+
return toArray(this.iterateGroups(params, options), options);
|
|
1185
|
+
}
|
|
1186
|
+
async getGroup(id) {
|
|
1187
|
+
return this.client.request("GET", `/v1/tax/groups/${id}`);
|
|
1188
|
+
}
|
|
1189
|
+
async createGroup(body, options) {
|
|
1190
|
+
return this.client.request("POST", "/v1/tax/groups", { body, ...options });
|
|
1191
|
+
}
|
|
1192
|
+
async updateGroup(id, body) {
|
|
1193
|
+
return this.client.request("PATCH", `/v1/tax/groups/${id}`, { body });
|
|
1194
|
+
}
|
|
1195
|
+
async deleteGroup(id) {
|
|
1196
|
+
return this.client.request("DELETE", `/v1/tax/groups/${id}`);
|
|
1197
|
+
}
|
|
1198
|
+
// Rates
|
|
1199
|
+
async listRates(params) {
|
|
1200
|
+
return this.client.request("GET", "/v1/tax/rates", { params });
|
|
1201
|
+
}
|
|
1202
|
+
iterateRates(params, options) {
|
|
1203
|
+
return paginate((cursor) => this.listRates({ ...params, cursor }), options);
|
|
1204
|
+
}
|
|
1205
|
+
async ratesToArray(params, options) {
|
|
1206
|
+
return toArray(this.iterateRates(params, options), options);
|
|
1207
|
+
}
|
|
1208
|
+
async createRate(body, options) {
|
|
1209
|
+
return this.client.request("POST", "/v1/tax/rates", { body, ...options });
|
|
1210
|
+
}
|
|
1211
|
+
async updateRate(id, body) {
|
|
1212
|
+
return this.client.request("PATCH", `/v1/tax/rates/${id}`, { body });
|
|
1213
|
+
}
|
|
1214
|
+
async deleteRate(id) {
|
|
1215
|
+
return this.client.request("DELETE", `/v1/tax/rates/${id}`);
|
|
1216
|
+
}
|
|
1217
|
+
// Exemptions
|
|
1218
|
+
async listExemptions(params) {
|
|
1219
|
+
return this.client.request("GET", "/v1/tax/exemptions", { params });
|
|
1220
|
+
}
|
|
1221
|
+
iterateExemptions(params, options) {
|
|
1222
|
+
return paginate((cursor) => this.listExemptions({ ...params, cursor }), options);
|
|
1223
|
+
}
|
|
1224
|
+
async exemptionsToArray(params, options) {
|
|
1225
|
+
return toArray(this.iterateExemptions(params, options), options);
|
|
1226
|
+
}
|
|
1227
|
+
async createExemption(body, options) {
|
|
1228
|
+
return this.client.request("POST", "/v1/tax/exemptions", { body, ...options });
|
|
1229
|
+
}
|
|
1230
|
+
async deleteExemption(id) {
|
|
1231
|
+
return this.client.request("DELETE", `/v1/tax/exemptions/${id}`);
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
// src/resources/exchange-rates.ts
|
|
1236
|
+
var ExchangeRatesResource = class {
|
|
1237
|
+
constructor(client) {
|
|
1238
|
+
this.client = client;
|
|
1239
|
+
}
|
|
1240
|
+
client;
|
|
1241
|
+
async list(params) {
|
|
1242
|
+
return this.client.request("GET", "/v1/exchange-rates", { params });
|
|
1243
|
+
}
|
|
1244
|
+
async refresh() {
|
|
1245
|
+
return this.client.request("POST", "/v1/exchange-rates/refresh");
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
|
|
1249
|
+
// src/resources/filter-attributes.ts
|
|
1250
|
+
var FilterAttributesResource = class {
|
|
1251
|
+
constructor(client) {
|
|
1252
|
+
this.client = client;
|
|
1253
|
+
}
|
|
1254
|
+
client;
|
|
1255
|
+
async list(params) {
|
|
1256
|
+
return this.client.request("GET", "/v1/filter-attributes", { params });
|
|
1257
|
+
}
|
|
1258
|
+
iterate(params, options) {
|
|
1259
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1260
|
+
}
|
|
1261
|
+
async toArray(params, options) {
|
|
1262
|
+
return toArray(this.iterate(params, options), options);
|
|
1263
|
+
}
|
|
1264
|
+
async get(id) {
|
|
1265
|
+
return this.client.request("GET", `/v1/filter-attributes/${id}`);
|
|
1266
|
+
}
|
|
1267
|
+
async create(body, options) {
|
|
1268
|
+
return this.client.request("POST", "/v1/filter-attributes", { body, ...options });
|
|
1269
|
+
}
|
|
1270
|
+
async update(id, body) {
|
|
1271
|
+
return this.client.request("PATCH", `/v1/filter-attributes/${id}`, { body });
|
|
1272
|
+
}
|
|
1273
|
+
async delete(id) {
|
|
1274
|
+
return this.client.request("DELETE", `/v1/filter-attributes/${id}`);
|
|
1275
|
+
}
|
|
1276
|
+
async reorder(body) {
|
|
1277
|
+
return this.client.request("PUT", "/v1/filter-attributes/reorder", { body });
|
|
1278
|
+
}
|
|
1279
|
+
async discover() {
|
|
1280
|
+
return this.client.request("GET", "/v1/filter-attributes/discover");
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
|
|
1284
|
+
// src/resources/navigation.ts
|
|
1285
|
+
var NavigationResource = class {
|
|
1286
|
+
constructor(client) {
|
|
1287
|
+
this.client = client;
|
|
1288
|
+
}
|
|
1289
|
+
client;
|
|
1290
|
+
async list(params) {
|
|
1291
|
+
return this.client.request("GET", "/v1/navigation", { params });
|
|
1292
|
+
}
|
|
1293
|
+
iterate(params, options) {
|
|
1294
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1295
|
+
}
|
|
1296
|
+
async toArray(params, options) {
|
|
1297
|
+
return toArray(this.iterate(params, options), options);
|
|
1298
|
+
}
|
|
1299
|
+
async get(id) {
|
|
1300
|
+
return this.client.request("GET", `/v1/navigation/${id}`);
|
|
1301
|
+
}
|
|
1302
|
+
async create(body, options) {
|
|
1303
|
+
return this.client.request("POST", "/v1/navigation", { body, ...options });
|
|
1304
|
+
}
|
|
1305
|
+
async update(id, body) {
|
|
1306
|
+
return this.client.request("PATCH", `/v1/navigation/${id}`, { body });
|
|
1307
|
+
}
|
|
1308
|
+
async delete(id) {
|
|
1309
|
+
return this.client.request("DELETE", `/v1/navigation/${id}`);
|
|
1310
|
+
}
|
|
1311
|
+
async addItem(menuId, body) {
|
|
1312
|
+
return this.client.request("POST", `/v1/navigation/${menuId}/items`, { body });
|
|
1313
|
+
}
|
|
1314
|
+
async updateItem(menuId, itemId, body) {
|
|
1315
|
+
return this.client.request("PATCH", `/v1/navigation/${menuId}/items/${itemId}`, { body });
|
|
1316
|
+
}
|
|
1317
|
+
async deleteItem(menuId, itemId) {
|
|
1318
|
+
return this.client.request("DELETE", `/v1/navigation/${menuId}/items/${itemId}`);
|
|
1319
|
+
}
|
|
1320
|
+
async reorderItems(menuId, body) {
|
|
1321
|
+
return this.client.request("PATCH", `/v1/navigation/${menuId}/items/reorder`, { body });
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1325
|
+
// src/resources/notifications.ts
|
|
1326
|
+
var NotificationsResource = class {
|
|
1327
|
+
constructor(client) {
|
|
1328
|
+
this.client = client;
|
|
1329
|
+
}
|
|
1330
|
+
client;
|
|
1331
|
+
async list(params) {
|
|
1332
|
+
return this.client.request("GET", "/v1/notifications", { params });
|
|
1333
|
+
}
|
|
1334
|
+
iterate(params, options) {
|
|
1335
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1336
|
+
}
|
|
1337
|
+
async toArray(params, options) {
|
|
1338
|
+
return toArray(this.iterate(params, options), options);
|
|
1339
|
+
}
|
|
1340
|
+
async get(id) {
|
|
1341
|
+
return this.client.request("GET", `/v1/notifications/${id}`);
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1345
|
+
// src/resources/checkouts.ts
|
|
1346
|
+
var CheckoutsResource = class {
|
|
1347
|
+
constructor(client) {
|
|
1348
|
+
this.client = client;
|
|
1349
|
+
}
|
|
1350
|
+
client;
|
|
1351
|
+
async list(params) {
|
|
1352
|
+
return this.client.request("GET", "/v1/checkouts", { params });
|
|
1353
|
+
}
|
|
1354
|
+
iterate(params, options) {
|
|
1355
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1356
|
+
}
|
|
1357
|
+
async toArray(params, options) {
|
|
1358
|
+
return toArray(this.iterate(params, options), options);
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
// src/resources/analytics.ts
|
|
1363
|
+
var AnalyticsResource = class {
|
|
1364
|
+
constructor(client) {
|
|
1365
|
+
this.client = client;
|
|
1366
|
+
}
|
|
1367
|
+
client;
|
|
1368
|
+
async summary(params) {
|
|
1369
|
+
return this.client.request("GET", "/v1/analytics/summary", { params });
|
|
1370
|
+
}
|
|
1371
|
+
async revenue(params) {
|
|
1372
|
+
return this.client.request("GET", "/v1/analytics/revenue", { params });
|
|
1373
|
+
}
|
|
1374
|
+
async orders(params) {
|
|
1375
|
+
return this.client.request("GET", "/v1/analytics/orders", { params });
|
|
1376
|
+
}
|
|
1377
|
+
async topProducts(params) {
|
|
1378
|
+
return this.client.request("GET", "/v1/analytics/top-products", { params });
|
|
1379
|
+
}
|
|
1380
|
+
async actionItems() {
|
|
1381
|
+
return this.client.request("GET", "/v1/analytics/action-items");
|
|
1382
|
+
}
|
|
1383
|
+
async posDashboard(params) {
|
|
1384
|
+
return this.client.request("GET", "/v1/pos/analytics/dashboard", { params });
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
|
|
1388
|
+
// src/resources/store-credit.ts
|
|
1389
|
+
var StoreCreditResource = class {
|
|
1390
|
+
constructor(client) {
|
|
1391
|
+
this.client = client;
|
|
1392
|
+
}
|
|
1393
|
+
client;
|
|
1394
|
+
async getBalance(customerId) {
|
|
1395
|
+
return this.client.request("GET", `/v1/customers/${customerId}/credit`);
|
|
1396
|
+
}
|
|
1397
|
+
async getLoyalty(customerId) {
|
|
1398
|
+
return this.client.request("GET", `/v1/customers/${customerId}/loyalty`);
|
|
1399
|
+
}
|
|
1400
|
+
async issue(customerId, body, options) {
|
|
1401
|
+
return this.client.request("POST", `/v1/customers/${customerId}/credit`, {
|
|
1402
|
+
body,
|
|
1403
|
+
...options
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
async listTransactions(customerId, params) {
|
|
1407
|
+
return this.client.request("GET", `/v1/customers/${customerId}/credit/transactions`, {
|
|
1408
|
+
params
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
iterateTransactions(customerId, params, options) {
|
|
1412
|
+
return paginate(
|
|
1413
|
+
(cursor) => this.listTransactions(customerId, { ...params, cursor }),
|
|
1414
|
+
options
|
|
1415
|
+
);
|
|
1416
|
+
}
|
|
1417
|
+
async transactionsToArray(customerId, params, options) {
|
|
1418
|
+
return toArray(this.iterateTransactions(customerId, params, options), options);
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
// src/resources/search.ts
|
|
1423
|
+
var SearchResource = class {
|
|
1424
|
+
constructor(client) {
|
|
1425
|
+
this.client = client;
|
|
1426
|
+
}
|
|
1427
|
+
client;
|
|
1428
|
+
async search(params) {
|
|
1429
|
+
return this.client.request("GET", "/v1/search", { params });
|
|
1430
|
+
}
|
|
1431
|
+
async suggest(params) {
|
|
1432
|
+
return this.client.request("GET", "/v1/search/suggest", { params });
|
|
1433
|
+
}
|
|
1434
|
+
async bootstrap() {
|
|
1435
|
+
return this.client.request("POST", "/v1/search/bootstrap");
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1439
|
+
// src/resources/channels.ts
|
|
1440
|
+
var ChannelsResource = class {
|
|
1441
|
+
constructor(client) {
|
|
1442
|
+
this.client = client;
|
|
1443
|
+
}
|
|
1444
|
+
client;
|
|
1445
|
+
async list(params) {
|
|
1446
|
+
return this.client.request("GET", "/v1/channels", { params });
|
|
1447
|
+
}
|
|
1448
|
+
iterate(params, options) {
|
|
1449
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1450
|
+
}
|
|
1451
|
+
async toArray(params, options) {
|
|
1452
|
+
return toArray(this.iterate(params, options), options);
|
|
1453
|
+
}
|
|
1454
|
+
async get(slug, params) {
|
|
1455
|
+
return this.client.request("GET", `/v1/channels/${slug}`, { params });
|
|
1456
|
+
}
|
|
1457
|
+
async create(body, options) {
|
|
1458
|
+
return this.client.request("POST", "/v1/channels", { body, ...options });
|
|
1459
|
+
}
|
|
1460
|
+
async update(slug, body) {
|
|
1461
|
+
return this.client.request("PATCH", `/v1/channels/${slug}`, { body });
|
|
1462
|
+
}
|
|
1463
|
+
async archive(slug) {
|
|
1464
|
+
return this.client.request("DELETE", `/v1/channels/${slug}`);
|
|
1465
|
+
}
|
|
1466
|
+
async setDefault(slug) {
|
|
1467
|
+
return this.client.request("PUT", `/v1/channels/${slug}/default`, { body: {} });
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
// src/resources/locations.ts
|
|
1472
|
+
var LocationsResource = class {
|
|
1473
|
+
constructor(client) {
|
|
1474
|
+
this.client = client;
|
|
1475
|
+
}
|
|
1476
|
+
client;
|
|
1477
|
+
async list(params) {
|
|
1478
|
+
return this.client.request("GET", "/v1/locations", { params });
|
|
1479
|
+
}
|
|
1480
|
+
iterate(params, options) {
|
|
1481
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1482
|
+
}
|
|
1483
|
+
async toArray(params, options) {
|
|
1484
|
+
return toArray(this.iterate(params, options), options);
|
|
1485
|
+
}
|
|
1486
|
+
async get(id) {
|
|
1487
|
+
return this.client.request("GET", `/v1/locations/${id}`);
|
|
1488
|
+
}
|
|
1489
|
+
async create(body, options) {
|
|
1490
|
+
return this.client.request("POST", "/v1/locations", { body, ...options });
|
|
1491
|
+
}
|
|
1492
|
+
async update(id, body) {
|
|
1493
|
+
return this.client.request("PATCH", `/v1/locations/${id}`, { body });
|
|
1494
|
+
}
|
|
1495
|
+
async delete(id) {
|
|
1496
|
+
return this.client.request("DELETE", `/v1/locations/${id}`);
|
|
1497
|
+
}
|
|
1498
|
+
async setDefault(id) {
|
|
1499
|
+
return this.client.request("POST", `/v1/locations/${id}/default`);
|
|
1500
|
+
}
|
|
1501
|
+
async transfer(id, body) {
|
|
1502
|
+
return this.client.request("POST", `/v1/locations/${id}/transfer`, { body });
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
|
|
1506
|
+
// src/resources/integrations.ts
|
|
1507
|
+
var IntegrationsResource = class {
|
|
1508
|
+
constructor(client) {
|
|
1509
|
+
this.client = client;
|
|
1510
|
+
}
|
|
1511
|
+
client;
|
|
1512
|
+
async getAccountingStatus() {
|
|
1513
|
+
return this.client.request("GET", "/v1/integrations/accounting/status");
|
|
1514
|
+
}
|
|
1515
|
+
async getAuthorizeUrl() {
|
|
1516
|
+
return this.client.request("GET", "/v1/integrations/accounting/authorize");
|
|
1517
|
+
}
|
|
1518
|
+
async testConnection() {
|
|
1519
|
+
return this.client.request("POST", "/v1/integrations/accounting/test");
|
|
1520
|
+
}
|
|
1521
|
+
async disconnect() {
|
|
1522
|
+
await this.client.request("DELETE", "/v1/integrations/accounting");
|
|
1523
|
+
}
|
|
1524
|
+
async updateSettings(settings) {
|
|
1525
|
+
return this.client.request("PATCH", "/v1/integrations/accounting/settings", {
|
|
1526
|
+
body: settings
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
async syncOrder(orderId) {
|
|
1530
|
+
return this.client.request("POST", `/v1/integrations/accounting/sync/${orderId}`);
|
|
1531
|
+
}
|
|
1532
|
+
async retrySyncOrder(orderId) {
|
|
1533
|
+
return this.client.request("POST", `/v1/integrations/accounting/sync/${orderId}/retry`);
|
|
1534
|
+
}
|
|
1535
|
+
async listSyncLog(params) {
|
|
1536
|
+
return this.client.request("GET", "/v1/integrations/accounting/sync-log", { params });
|
|
1537
|
+
}
|
|
1538
|
+
iterateSyncLog(params, options) {
|
|
1539
|
+
return paginate((cursor) => this.listSyncLog({ ...params, cursor }), options);
|
|
1540
|
+
}
|
|
1541
|
+
async toArraySyncLog(params, options) {
|
|
1542
|
+
return toArray(this.iterateSyncLog(params, options), options);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
// src/resources/posts.ts
|
|
1547
|
+
var PostsResource = class {
|
|
1548
|
+
constructor(client) {
|
|
1549
|
+
this.client = client;
|
|
1550
|
+
}
|
|
1551
|
+
client;
|
|
1552
|
+
async list(params) {
|
|
1553
|
+
return this.client.request("GET", "/v1/posts", { params });
|
|
1554
|
+
}
|
|
1555
|
+
iterate(params, options) {
|
|
1556
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1557
|
+
}
|
|
1558
|
+
async toArray(params, options) {
|
|
1559
|
+
return toArray(this.iterate(params, options), options);
|
|
1560
|
+
}
|
|
1561
|
+
async get(id, params) {
|
|
1562
|
+
return this.client.request("GET", `/v1/posts/${id}`, { params });
|
|
1563
|
+
}
|
|
1564
|
+
async create(body, options) {
|
|
1565
|
+
return this.client.request("POST", "/v1/posts", { body, ...options });
|
|
1566
|
+
}
|
|
1567
|
+
async update(id, body) {
|
|
1568
|
+
return this.client.request("PATCH", `/v1/posts/${id}`, { body });
|
|
1569
|
+
}
|
|
1570
|
+
async delete(id) {
|
|
1571
|
+
return this.client.request("DELETE", `/v1/posts/${id}`);
|
|
1572
|
+
}
|
|
1573
|
+
async addCategories(postId, body) {
|
|
1574
|
+
return this.client.request("POST", `/v1/posts/${postId}/categories`, { body });
|
|
1575
|
+
}
|
|
1576
|
+
async removeCategory(postId, categoryId) {
|
|
1577
|
+
return this.client.request(
|
|
1578
|
+
"DELETE",
|
|
1579
|
+
`/v1/posts/${postId}/categories/${categoryId}`
|
|
1580
|
+
);
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
|
|
1584
|
+
// src/resources/content-categories.ts
|
|
1585
|
+
var ContentCategoriesResource = class {
|
|
1586
|
+
constructor(client) {
|
|
1587
|
+
this.client = client;
|
|
1588
|
+
}
|
|
1589
|
+
client;
|
|
1590
|
+
async list(params) {
|
|
1591
|
+
return this.client.request("GET", "/v1/content-categories", { params });
|
|
1592
|
+
}
|
|
1593
|
+
iterate(params, options) {
|
|
1594
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1595
|
+
}
|
|
1596
|
+
async toArray(params, options) {
|
|
1597
|
+
return toArray(this.iterate(params, options), options);
|
|
1598
|
+
}
|
|
1599
|
+
async get(id) {
|
|
1600
|
+
return this.client.request("GET", `/v1/content-categories/${id}`);
|
|
1601
|
+
}
|
|
1602
|
+
async create(body, options) {
|
|
1603
|
+
return this.client.request("POST", "/v1/content-categories", { body, ...options });
|
|
1604
|
+
}
|
|
1605
|
+
async update(id, body) {
|
|
1606
|
+
return this.client.request("PATCH", `/v1/content-categories/${id}`, { body });
|
|
1607
|
+
}
|
|
1608
|
+
async delete(id) {
|
|
1609
|
+
return this.client.request("DELETE", `/v1/content-categories/${id}`);
|
|
1610
|
+
}
|
|
1611
|
+
// ── Post sub-resources ──
|
|
1612
|
+
async listPosts(categoryId, params) {
|
|
1613
|
+
return this.client.request("GET", `/v1/content-categories/${categoryId}/posts`, { params });
|
|
1614
|
+
}
|
|
1615
|
+
async addPosts(categoryId, body) {
|
|
1616
|
+
return this.client.request("POST", `/v1/content-categories/${categoryId}/posts`, { body });
|
|
1617
|
+
}
|
|
1618
|
+
async removePost(categoryId, postId) {
|
|
1619
|
+
return this.client.request(
|
|
1620
|
+
"DELETE",
|
|
1621
|
+
`/v1/content-categories/${categoryId}/posts/${postId}`
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
async reorderPosts(categoryId, body) {
|
|
1625
|
+
return this.client.request(
|
|
1626
|
+
"PATCH",
|
|
1627
|
+
`/v1/content-categories/${categoryId}/posts/reorder`,
|
|
1628
|
+
{ body }
|
|
1629
|
+
);
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1633
|
+
// src/resources/membership-plans.ts
|
|
1634
|
+
var MembershipPlansResource = class {
|
|
1635
|
+
constructor(client) {
|
|
1636
|
+
this.client = client;
|
|
1637
|
+
}
|
|
1638
|
+
client;
|
|
1639
|
+
async list(params) {
|
|
1640
|
+
return this.client.request("GET", "/v1/membership-plans", { params });
|
|
1641
|
+
}
|
|
1642
|
+
iterate(params, options) {
|
|
1643
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1644
|
+
}
|
|
1645
|
+
async toArray(params, options) {
|
|
1646
|
+
return toArray(this.iterate(params, options), options);
|
|
1647
|
+
}
|
|
1648
|
+
async get(id) {
|
|
1649
|
+
return this.client.request("GET", `/v1/membership-plans/${id}`);
|
|
1650
|
+
}
|
|
1651
|
+
async create(body, options) {
|
|
1652
|
+
return this.client.request("POST", "/v1/membership-plans", { body, ...options });
|
|
1653
|
+
}
|
|
1654
|
+
async update(id, body) {
|
|
1655
|
+
return this.client.request("PATCH", `/v1/membership-plans/${id}`, { body });
|
|
1656
|
+
}
|
|
1657
|
+
async delete(id) {
|
|
1658
|
+
return this.client.request("DELETE", `/v1/membership-plans/${id}`);
|
|
1659
|
+
}
|
|
1660
|
+
async listSubscriptions(params) {
|
|
1661
|
+
return this.client.request("GET", "/v1/membership-plans/subscriptions", { params });
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
|
|
1665
|
+
// src/resources/bookings.ts
|
|
1666
|
+
var BookingsResource = class {
|
|
1667
|
+
constructor(client) {
|
|
1668
|
+
this.client = client;
|
|
1669
|
+
}
|
|
1670
|
+
client;
|
|
1671
|
+
// ── Bookable locations ──
|
|
1672
|
+
async listLocations() {
|
|
1673
|
+
return this.client.request("GET", "/v1/bookings/locations");
|
|
1674
|
+
}
|
|
1675
|
+
// ── Availability ──
|
|
1676
|
+
async getAvailability(params) {
|
|
1677
|
+
return this.client.request("GET", "/v1/bookings/availability", { params });
|
|
1678
|
+
}
|
|
1679
|
+
// ── Appointments ──
|
|
1680
|
+
async createAppointment(body, options) {
|
|
1681
|
+
return this.client.request("POST", "/v1/bookings/appointments", {
|
|
1682
|
+
body,
|
|
1683
|
+
...options
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
async confirmAppointment(id) {
|
|
1687
|
+
return this.client.request("POST", `/v1/bookings/appointments/${id}/confirm`);
|
|
1688
|
+
}
|
|
1689
|
+
async listAppointments(params) {
|
|
1690
|
+
return this.client.request("GET", "/v1/bookings/appointments", { params });
|
|
1691
|
+
}
|
|
1692
|
+
iterateAppointments(params, options) {
|
|
1693
|
+
return paginate(
|
|
1694
|
+
(cursor) => this.listAppointments({ ...params, cursor }),
|
|
1695
|
+
options
|
|
1696
|
+
);
|
|
1697
|
+
}
|
|
1698
|
+
async toArrayAppointments(params, options) {
|
|
1699
|
+
return toArray(this.iterateAppointments(params, options), options);
|
|
1700
|
+
}
|
|
1701
|
+
/** List the authenticated customer's own appointments. Requires customer JWT. */
|
|
1702
|
+
async myAppointments(params) {
|
|
1703
|
+
return this.client.request("GET", "/v1/bookings/my-appointments", { params });
|
|
1704
|
+
}
|
|
1705
|
+
/** Cancel the customer's own appointment. Must be 24h+ before scheduled time. Requires customer JWT. */
|
|
1706
|
+
async cancelMyAppointment(id) {
|
|
1707
|
+
return this.client.request("POST", `/v1/bookings/my-appointments/${id}/cancel`);
|
|
1708
|
+
}
|
|
1709
|
+
/** Reschedule the customer's own appointment. Must be 4h+ before current time. Requires customer JWT. */
|
|
1710
|
+
async rescheduleMyAppointment(id, body) {
|
|
1711
|
+
return this.client.request("POST", `/v1/bookings/my-appointments/${id}/reschedule`, { body });
|
|
1712
|
+
}
|
|
1713
|
+
async getAppointment(id) {
|
|
1714
|
+
return this.client.request("GET", `/v1/bookings/appointments/${id}`);
|
|
1715
|
+
}
|
|
1716
|
+
async updateAppointment(id, body) {
|
|
1717
|
+
return this.client.request("PATCH", `/v1/bookings/appointments/${id}`, {
|
|
1718
|
+
body
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
/** Reschedule an appointment to a new date/time. Requires a secret key. */
|
|
1722
|
+
async rescheduleAppointment(id, body) {
|
|
1723
|
+
return this.client.request("POST", `/v1/bookings/appointments/${id}/reschedule`, { body });
|
|
1724
|
+
}
|
|
1725
|
+
// ── Availability overrides ──
|
|
1726
|
+
async createOverride(body, options) {
|
|
1727
|
+
return this.client.request("POST", "/v1/bookings/overrides", {
|
|
1728
|
+
body,
|
|
1729
|
+
...options
|
|
1730
|
+
});
|
|
1731
|
+
}
|
|
1732
|
+
async listOverrides(params) {
|
|
1733
|
+
return this.client.request("GET", "/v1/bookings/overrides", { params });
|
|
1734
|
+
}
|
|
1735
|
+
async deleteOverride(id) {
|
|
1736
|
+
return this.client.request("DELETE", `/v1/bookings/overrides/${id}`);
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
|
|
1740
|
+
// src/resources/lookbooks.ts
|
|
1741
|
+
var LookbooksResource = class {
|
|
1742
|
+
constructor(client) {
|
|
1743
|
+
this.client = client;
|
|
1744
|
+
}
|
|
1745
|
+
client;
|
|
1746
|
+
async list(params) {
|
|
1747
|
+
return this.client.request("GET", "/v1/lookbooks", { params });
|
|
1748
|
+
}
|
|
1749
|
+
iterate(params, options) {
|
|
1750
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1751
|
+
}
|
|
1752
|
+
async toArray(params, options) {
|
|
1753
|
+
return toArray(this.iterate(params, options), options);
|
|
1754
|
+
}
|
|
1755
|
+
async get(id, params) {
|
|
1756
|
+
return this.client.request("GET", `/v1/lookbooks/${id}`, { params });
|
|
1757
|
+
}
|
|
1758
|
+
async create(body, options) {
|
|
1759
|
+
return this.client.request("POST", "/v1/lookbooks", { body, ...options });
|
|
1760
|
+
}
|
|
1761
|
+
async update(id, body) {
|
|
1762
|
+
return this.client.request("PATCH", `/v1/lookbooks/${id}`, { body });
|
|
1763
|
+
}
|
|
1764
|
+
async delete(id) {
|
|
1765
|
+
return this.client.request("DELETE", `/v1/lookbooks/${id}`);
|
|
1766
|
+
}
|
|
1767
|
+
/** Upload or replace the primary (BW) image for a lookbook. */
|
|
1768
|
+
async uploadImage(id, formData) {
|
|
1769
|
+
return this.client.upload(`/v1/lookbooks/${id}/image`, formData);
|
|
1770
|
+
}
|
|
1771
|
+
/** Upload or replace the color (hover) image for a lookbook. */
|
|
1772
|
+
async uploadColorImage(id, formData) {
|
|
1773
|
+
return this.client.upload(`/v1/lookbooks/${id}/image-color`, formData);
|
|
1774
|
+
}
|
|
1775
|
+
/** List all lookbook tags for this store, ordered by position then slug. */
|
|
1776
|
+
async listTags() {
|
|
1777
|
+
return this.client.request("GET", "/v1/lookbooks/tags");
|
|
1778
|
+
}
|
|
1779
|
+
};
|
|
1780
|
+
|
|
1781
|
+
// src/resources/gift-cards.ts
|
|
1782
|
+
var GiftCardsResource = class {
|
|
1783
|
+
constructor(client) {
|
|
1784
|
+
this.client = client;
|
|
1785
|
+
}
|
|
1786
|
+
client;
|
|
1787
|
+
async list(params) {
|
|
1788
|
+
return this.client.request("GET", "/v1/gift-cards", { params });
|
|
1789
|
+
}
|
|
1790
|
+
iterate(params, options) {
|
|
1791
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1792
|
+
}
|
|
1793
|
+
async toArray(params, options) {
|
|
1794
|
+
return toArray(this.iterate(params, options), options);
|
|
1795
|
+
}
|
|
1796
|
+
async get(id) {
|
|
1797
|
+
return this.client.request("GET", `/v1/gift-cards/${id}`);
|
|
1798
|
+
}
|
|
1799
|
+
async create(body, options) {
|
|
1800
|
+
return this.client.request("POST", "/v1/gift-cards", { body, ...options });
|
|
1801
|
+
}
|
|
1802
|
+
async update(id, body) {
|
|
1803
|
+
return this.client.request("PUT", `/v1/gift-cards/${id}`, { body });
|
|
1804
|
+
}
|
|
1805
|
+
async deactivate(id) {
|
|
1806
|
+
return this.client.request("POST", `/v1/gift-cards/${id}/deactivate`);
|
|
1807
|
+
}
|
|
1808
|
+
async listTransactions(id, params) {
|
|
1809
|
+
return this.client.request("GET", `/v1/gift-cards/${id}/transactions`, { params });
|
|
1810
|
+
}
|
|
1811
|
+
iterateTransactions(id, params, options) {
|
|
1812
|
+
return paginate(
|
|
1813
|
+
(cursor) => this.listTransactions(id, { ...params, cursor }),
|
|
1814
|
+
options
|
|
1815
|
+
);
|
|
1816
|
+
}
|
|
1817
|
+
async transactionsToArray(id, params, options) {
|
|
1818
|
+
return toArray(this.iterateTransactions(id, params, options), options);
|
|
1819
|
+
}
|
|
1820
|
+
async credit(id, body, options) {
|
|
1821
|
+
return this.client.request("POST", `/v1/gift-cards/${id}/credit`, { body, ...options });
|
|
1822
|
+
}
|
|
1823
|
+
async debit(id, body, options) {
|
|
1824
|
+
return this.client.request("POST", `/v1/gift-cards/${id}/debit`, { body, ...options });
|
|
1825
|
+
}
|
|
1826
|
+
/** Convert a gift card's remaining balance into store credit on a customer account. */
|
|
1827
|
+
async convert(id, body) {
|
|
1828
|
+
return this.client.request("POST", `/v1/gift-cards/${id}/convert`, { body });
|
|
1829
|
+
}
|
|
1830
|
+
/** Look up a gift card by code (publishable key OK). */
|
|
1831
|
+
async lookup(code) {
|
|
1832
|
+
return this.client.request("GET", "/v1/gift-cards/lookup", { params: { code } });
|
|
1833
|
+
}
|
|
1834
|
+
};
|
|
1835
|
+
|
|
1836
|
+
// src/resources/forms.ts
|
|
1837
|
+
var FormsResource = class {
|
|
1838
|
+
constructor(client) {
|
|
1839
|
+
this.client = client;
|
|
1840
|
+
}
|
|
1841
|
+
client;
|
|
1842
|
+
// ── Form definitions ──
|
|
1843
|
+
/** List all form definitions (including archived). Secret key required. */
|
|
1844
|
+
async list() {
|
|
1845
|
+
return this.client.request("GET", "/v1/store/forms");
|
|
1846
|
+
}
|
|
1847
|
+
/** Get a single form definition by slug. Secret key required. */
|
|
1848
|
+
async get(slug) {
|
|
1849
|
+
return this.client.request("GET", `/v1/store/forms/${slug}`);
|
|
1850
|
+
}
|
|
1851
|
+
/** Create a new form definition. Secret key required. */
|
|
1852
|
+
async create(body, options) {
|
|
1853
|
+
return this.client.request("POST", "/v1/store/forms", { body, ...options });
|
|
1854
|
+
}
|
|
1855
|
+
/** Update a form definition (title, slug, settings, archived). Secret key required. */
|
|
1856
|
+
async update(slug, body) {
|
|
1857
|
+
return this.client.request("PATCH", `/v1/store/forms/${slug}`, { body });
|
|
1858
|
+
}
|
|
1859
|
+
/** Get a form's active fields and settings for public rendering. Publishable key accepted. */
|
|
1860
|
+
async getPublic(slug) {
|
|
1861
|
+
return this.client.request("GET", `/v1/store/forms/${slug}/public`);
|
|
1862
|
+
}
|
|
1863
|
+
// ── Fields within a form ──
|
|
1864
|
+
/** Add a field to a form. Secret key required. */
|
|
1865
|
+
async createField(formSlug, body, options) {
|
|
1866
|
+
return this.client.request("POST", `/v1/store/forms/${formSlug}/fields`, { body, ...options });
|
|
1867
|
+
}
|
|
1868
|
+
/** Update a field within a form. Secret key required. */
|
|
1869
|
+
async updateField(formSlug, fieldSlug, body) {
|
|
1870
|
+
return this.client.request("PATCH", `/v1/store/forms/${formSlug}/fields/${fieldSlug}`, { body });
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1874
|
+
// src/resources/form-submissions.ts
|
|
1875
|
+
var FormSubmissionsResource = class {
|
|
1876
|
+
constructor(client) {
|
|
1877
|
+
this.client = client;
|
|
1878
|
+
}
|
|
1879
|
+
client;
|
|
1880
|
+
/** Submit form data. Publishable key accepted. */
|
|
1881
|
+
async create(body, options) {
|
|
1882
|
+
return this.client.request("POST", "/v1/form-submissions", { body, ...options });
|
|
1883
|
+
}
|
|
1884
|
+
/** List form submissions with optional form slug filter. Secret key required. */
|
|
1885
|
+
async list(params) {
|
|
1886
|
+
return this.client.request("GET", "/v1/form-submissions", { params });
|
|
1887
|
+
}
|
|
1888
|
+
iterate(params, options) {
|
|
1889
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
1890
|
+
}
|
|
1891
|
+
async toArray(params, options) {
|
|
1892
|
+
return toArray(this.iterate(params, options), options);
|
|
1893
|
+
}
|
|
1894
|
+
/** Get a single form submission by ID. Secret key required. */
|
|
1895
|
+
async get(id) {
|
|
1896
|
+
return this.client.request("GET", `/v1/form-submissions/${id}`);
|
|
1897
|
+
}
|
|
1898
|
+
};
|
|
1899
|
+
|
|
1900
|
+
// src/resources/auth.ts
|
|
1901
|
+
var AuthResource = class {
|
|
1902
|
+
constructor(client) {
|
|
1903
|
+
this.client = client;
|
|
1904
|
+
}
|
|
1905
|
+
client;
|
|
1906
|
+
/**
|
|
1907
|
+
* Register a new customer account.
|
|
1908
|
+
* Returns tokens if the store does not require email verification,
|
|
1909
|
+
* or a message prompting verification if it does.
|
|
1910
|
+
*/
|
|
1911
|
+
async register(body) {
|
|
1912
|
+
return this.client.request("POST", "/v1/auth/register", { body });
|
|
1913
|
+
}
|
|
1914
|
+
/** Log in with email and password. Returns access + refresh tokens. */
|
|
1915
|
+
async login(body) {
|
|
1916
|
+
return this.client.request("POST", "/v1/auth/login", { body });
|
|
1917
|
+
}
|
|
1918
|
+
/** Exchange a refresh token for new access + refresh tokens (single-use rotation). */
|
|
1919
|
+
async refreshToken(refreshToken) {
|
|
1920
|
+
return this.client.request("POST", "/v1/auth/token", {
|
|
1921
|
+
body: { refresh_token: refreshToken }
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
/** Invalidate a refresh token. Idempotent — succeeds even if already invalidated. */
|
|
1925
|
+
async logout(refreshToken) {
|
|
1926
|
+
return this.client.request("POST", "/v1/auth/logout", {
|
|
1927
|
+
body: { refresh_token: refreshToken }
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
/** Request a password reset email. Always returns a generic message (prevents enumeration). */
|
|
1931
|
+
async forgotPassword(email) {
|
|
1932
|
+
return this.client.request("POST", "/v1/auth/forgot-password", {
|
|
1933
|
+
body: { email }
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
/** Reset password using a token from the reset email. Invalidates all sessions. */
|
|
1937
|
+
async resetPassword(token, password) {
|
|
1938
|
+
return this.client.request("POST", "/v1/auth/reset-password", {
|
|
1939
|
+
body: { token, password }
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
/** Verify a customer's email using the token from the verification email. */
|
|
1943
|
+
async verifyEmail(token) {
|
|
1944
|
+
return this.client.request("POST", "/v1/auth/verify-email", {
|
|
1945
|
+
body: { token }
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
/** Resend the email verification link. Always returns a generic message (prevents enumeration). */
|
|
1949
|
+
async resendVerification(email) {
|
|
1950
|
+
return this.client.request("POST", "/v1/auth/resend-verification", {
|
|
1951
|
+
body: { email }
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
};
|
|
1955
|
+
|
|
1956
|
+
// src/resources/me.ts
|
|
1957
|
+
var MeResource = class {
|
|
1958
|
+
constructor(client) {
|
|
1959
|
+
this.client = client;
|
|
1960
|
+
}
|
|
1961
|
+
client;
|
|
1962
|
+
opts(accessToken, extra) {
|
|
1963
|
+
const token = accessToken ?? this.client.customerToken;
|
|
1964
|
+
if (!token) {
|
|
1965
|
+
throw new Error(
|
|
1966
|
+
"Customer access token required. Pass accessToken or call onefive.setCustomerToken()."
|
|
1967
|
+
);
|
|
1968
|
+
}
|
|
1969
|
+
return {
|
|
1970
|
+
...extra,
|
|
1971
|
+
headers: {
|
|
1972
|
+
Authorization: `Bearer ${token}`,
|
|
1973
|
+
...extra?.headers
|
|
1974
|
+
}
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
/** Get the authenticated customer's profile. */
|
|
1978
|
+
async getProfile(accessToken) {
|
|
1979
|
+
return this.client.request("GET", "/v1/me", this.opts(accessToken));
|
|
1980
|
+
}
|
|
1981
|
+
/** Update profile fields (first_name, last_name, phone, dob, locale). */
|
|
1982
|
+
async updateProfile(body, accessToken) {
|
|
1983
|
+
return this.client.request("PATCH", "/v1/me", this.opts(accessToken, { body }));
|
|
1984
|
+
}
|
|
1985
|
+
/** Change password. Invalidates all sessions and returns new tokens. */
|
|
1986
|
+
async changePassword(body, accessToken) {
|
|
1987
|
+
return this.client.request("POST", "/v1/me/password", this.opts(accessToken, { body }));
|
|
1988
|
+
}
|
|
1989
|
+
/** List the customer's order history. */
|
|
1990
|
+
async listOrders(params, accessToken) {
|
|
1991
|
+
return this.client.request("GET", "/v1/me/orders", this.opts(accessToken, {
|
|
1992
|
+
params
|
|
1993
|
+
}));
|
|
1994
|
+
}
|
|
1995
|
+
/** List the customer's addresses. */
|
|
1996
|
+
async listAddresses(accessToken) {
|
|
1997
|
+
return this.client.request("GET", "/v1/me/addresses", this.opts(accessToken));
|
|
1998
|
+
}
|
|
1999
|
+
/** Create a new address. */
|
|
2000
|
+
async createAddress(body, accessToken) {
|
|
2001
|
+
return this.client.request("POST", "/v1/me/addresses", this.opts(accessToken, { body }));
|
|
2002
|
+
}
|
|
2003
|
+
/** Update an existing address. */
|
|
2004
|
+
async updateAddress(id, body, accessToken) {
|
|
2005
|
+
return this.client.request(
|
|
2006
|
+
"PATCH",
|
|
2007
|
+
`/v1/me/addresses/${id}`,
|
|
2008
|
+
this.opts(accessToken, { body })
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
/** Delete an address. */
|
|
2012
|
+
async deleteAddress(id, accessToken) {
|
|
2013
|
+
return this.client.request("DELETE", `/v1/me/addresses/${id}`, this.opts(accessToken));
|
|
2014
|
+
}
|
|
2015
|
+
/** Get store credit balance breakdown. */
|
|
2016
|
+
async getCredit(accessToken) {
|
|
2017
|
+
return this.client.request("GET", "/v1/me/credit", this.opts(accessToken));
|
|
2018
|
+
}
|
|
2019
|
+
/** List store credit transactions. */
|
|
2020
|
+
async listCreditTransactions(params, accessToken) {
|
|
2021
|
+
return this.client.request(
|
|
2022
|
+
"GET",
|
|
2023
|
+
"/v1/me/credit/transactions",
|
|
2024
|
+
this.opts(accessToken, { params })
|
|
2025
|
+
);
|
|
2026
|
+
}
|
|
2027
|
+
/** Get loyalty programme summary. */
|
|
2028
|
+
async getLoyalty(accessToken) {
|
|
2029
|
+
return this.client.request("GET", "/v1/me/loyalty", this.opts(accessToken));
|
|
2030
|
+
}
|
|
2031
|
+
/** List the customer's returns. */
|
|
2032
|
+
async listReturns(accessToken) {
|
|
2033
|
+
return this.client.request("GET", "/v1/me/returns", this.opts(accessToken));
|
|
2034
|
+
}
|
|
2035
|
+
/** Get active membership. */
|
|
2036
|
+
async getMembership(accessToken) {
|
|
2037
|
+
return this.client.request("GET", "/v1/me/membership", this.opts(accessToken));
|
|
2038
|
+
}
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
// src/resources/directory.ts
|
|
2042
|
+
var DirectoryResource = class {
|
|
2043
|
+
constructor(client) {
|
|
2044
|
+
this.client = client;
|
|
2045
|
+
}
|
|
2046
|
+
client;
|
|
2047
|
+
/** List directory listings with optional filters and pagination. */
|
|
2048
|
+
async list(params) {
|
|
2049
|
+
return this.client.request("GET", "/v1/directory", { params });
|
|
2050
|
+
}
|
|
2051
|
+
/** Async iterator over all directory listings, fetching pages lazily. */
|
|
2052
|
+
iterate(params, options) {
|
|
2053
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
2054
|
+
}
|
|
2055
|
+
/** Collect all directory listings into an array. */
|
|
2056
|
+
async toArray(params, options) {
|
|
2057
|
+
return toArray(this.iterate(params, options), options);
|
|
2058
|
+
}
|
|
2059
|
+
/** Get a single directory listing by ID. */
|
|
2060
|
+
async get(id) {
|
|
2061
|
+
return this.client.request("GET", `/v1/directory/${id}`);
|
|
2062
|
+
}
|
|
2063
|
+
/** Create a new directory listing. Requires a secret key. */
|
|
2064
|
+
async create(body, options) {
|
|
2065
|
+
return this.client.request("POST", "/v1/directory", { body, ...options });
|
|
2066
|
+
}
|
|
2067
|
+
/** Update a directory listing. Requires a secret key. */
|
|
2068
|
+
async update(id, body) {
|
|
2069
|
+
return this.client.request("PATCH", `/v1/directory/${id}`, { body });
|
|
2070
|
+
}
|
|
2071
|
+
/** Delete a directory listing. Requires a secret key. */
|
|
2072
|
+
async delete(id) {
|
|
2073
|
+
return this.client.request("DELETE", `/v1/directory/${id}`);
|
|
2074
|
+
}
|
|
2075
|
+
/** Submit a claim request for a directory listing. */
|
|
2076
|
+
async claim(id, body, options) {
|
|
2077
|
+
return this.client.request("POST", `/v1/directory/${id}/claim`, { body, ...options });
|
|
2078
|
+
}
|
|
2079
|
+
/** Get the public category taxonomy. */
|
|
2080
|
+
async getCategories() {
|
|
2081
|
+
return this.client.request("GET", "/v1/directory/categories");
|
|
2082
|
+
}
|
|
2083
|
+
/** Get the active tier definitions. */
|
|
2084
|
+
async getTiers() {
|
|
2085
|
+
return this.client.request("GET", "/v1/directory/tiers");
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
|
|
2089
|
+
// src/resources/directory-categories.ts
|
|
2090
|
+
var DirectoryCategoriesResource = class {
|
|
2091
|
+
constructor(client) {
|
|
2092
|
+
this.client = client;
|
|
2093
|
+
}
|
|
2094
|
+
client;
|
|
2095
|
+
/** List all directory categories. Requires a secret key. */
|
|
2096
|
+
async list() {
|
|
2097
|
+
return this.client.request("GET", "/v1/store/directory-categories");
|
|
2098
|
+
}
|
|
2099
|
+
/** Get a single directory category by slug. Requires a secret key. */
|
|
2100
|
+
async get(slug) {
|
|
2101
|
+
return this.client.request("GET", `/v1/store/directory-categories/${slug}`);
|
|
2102
|
+
}
|
|
2103
|
+
/** Create a new directory category. Requires a secret key. */
|
|
2104
|
+
async create(body, options) {
|
|
2105
|
+
return this.client.request("POST", "/v1/store/directory-categories", { body, ...options });
|
|
2106
|
+
}
|
|
2107
|
+
/** Update a directory category. Requires a secret key. */
|
|
2108
|
+
async update(slug, body) {
|
|
2109
|
+
return this.client.request("PATCH", `/v1/store/directory-categories/${slug}`, { body });
|
|
2110
|
+
}
|
|
2111
|
+
/** Delete a directory category. Children are re-parented. Requires a secret key. */
|
|
2112
|
+
async delete(slug) {
|
|
2113
|
+
return this.client.request("DELETE", `/v1/store/directory-categories/${slug}`);
|
|
2114
|
+
}
|
|
2115
|
+
/** Bulk reorder categories (parent assignments and positions). Requires a secret key. */
|
|
2116
|
+
async reorder(body) {
|
|
2117
|
+
return this.client.request("POST", "/v1/store/directory-categories/reorder", { body });
|
|
2118
|
+
}
|
|
2119
|
+
/** Get directory-wide settings. Requires a secret key. */
|
|
2120
|
+
async getSettings() {
|
|
2121
|
+
return this.client.request("GET", "/v1/store/directory-categories/settings");
|
|
2122
|
+
}
|
|
2123
|
+
/** Update directory-wide settings. Requires a secret key. */
|
|
2124
|
+
async updateSettings(body) {
|
|
2125
|
+
return this.client.request("PATCH", "/v1/store/directory-categories/settings", { body });
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
|
|
2129
|
+
// src/resources/directory-tiers.ts
|
|
2130
|
+
var DirectoryTiersResource = class {
|
|
2131
|
+
constructor(client) {
|
|
2132
|
+
this.client = client;
|
|
2133
|
+
}
|
|
2134
|
+
client;
|
|
2135
|
+
/** List all directory tiers. Requires a secret key. */
|
|
2136
|
+
async list() {
|
|
2137
|
+
return this.client.request("GET", "/v1/store/directory-tiers");
|
|
2138
|
+
}
|
|
2139
|
+
/** Get a single directory tier by slug. Requires a secret key. */
|
|
2140
|
+
async get(slug) {
|
|
2141
|
+
return this.client.request("GET", `/v1/store/directory-tiers/${slug}`);
|
|
2142
|
+
}
|
|
2143
|
+
/** Create a new directory tier. Requires a secret key. */
|
|
2144
|
+
async create(body, options) {
|
|
2145
|
+
return this.client.request("POST", "/v1/store/directory-tiers", { body, ...options });
|
|
2146
|
+
}
|
|
2147
|
+
/** Update a directory tier. Requires a secret key. */
|
|
2148
|
+
async update(slug, body) {
|
|
2149
|
+
return this.client.request("PATCH", `/v1/store/directory-tiers/${slug}`, { body });
|
|
2150
|
+
}
|
|
2151
|
+
/** Delete a directory tier. Requires a secret key. */
|
|
2152
|
+
async delete(slug) {
|
|
2153
|
+
return this.client.request("DELETE", `/v1/store/directory-tiers/${slug}`);
|
|
2154
|
+
}
|
|
2155
|
+
/** Bulk reorder tiers. Requires a secret key. */
|
|
2156
|
+
async reorder(body) {
|
|
2157
|
+
return this.client.request("POST", "/v1/store/directory-tiers/reorder", { body });
|
|
2158
|
+
}
|
|
2159
|
+
};
|
|
2160
|
+
|
|
2161
|
+
// src/resources/geo.ts
|
|
2162
|
+
var GeoResource = class {
|
|
2163
|
+
constructor(client) {
|
|
2164
|
+
this.client = client;
|
|
2165
|
+
}
|
|
2166
|
+
client;
|
|
2167
|
+
/** List all supported countries with region counts. */
|
|
2168
|
+
async countries() {
|
|
2169
|
+
return this.client.request("GET", "/v1/geo/countries");
|
|
2170
|
+
}
|
|
2171
|
+
/** Get a single country by ISO 3166-1 alpha-2 code. */
|
|
2172
|
+
async country(code) {
|
|
2173
|
+
return this.client.request("GET", `/v1/geo/countries/${code}`);
|
|
2174
|
+
}
|
|
2175
|
+
/** List regions, optionally filtered by country, parent subdivision, or type. */
|
|
2176
|
+
async regions(params) {
|
|
2177
|
+
return this.client.request("GET", "/v1/geo/regions", {
|
|
2178
|
+
params
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
/** Get a single region by slug. */
|
|
2182
|
+
async region(slug) {
|
|
2183
|
+
return this.client.request("GET", `/v1/geo/regions/${slug}`);
|
|
2184
|
+
}
|
|
2185
|
+
/** List postcode outcodes (districts), filtered by area, country, or prefix. At least one filter required. */
|
|
2186
|
+
async outcodes(params) {
|
|
2187
|
+
return this.client.request("GET", "/v1/geo/outcodes", {
|
|
2188
|
+
params
|
|
2189
|
+
});
|
|
2190
|
+
}
|
|
2191
|
+
/** Get a single outcode by code (e.g. 'S40', 'LE1'). */
|
|
2192
|
+
async outcode(code) {
|
|
2193
|
+
return this.client.request("GET", `/v1/geo/outcodes/${code}`);
|
|
2194
|
+
}
|
|
2195
|
+
/** Lookup a full UK postcode (e.g. 'S40 1AB'). Returns coordinates, county, district, region. */
|
|
2196
|
+
async postcode(code) {
|
|
2197
|
+
return this.client.request("GET", `/v1/geo/postcodes/${code.replace(/\s+/g, "")}`);
|
|
2198
|
+
}
|
|
2199
|
+
/** List cities/towns, filtered by region slug, country code, or name prefix. At least one filter required. */
|
|
2200
|
+
async cities(params) {
|
|
2201
|
+
return this.client.request("GET", "/v1/geo/cities", {
|
|
2202
|
+
params
|
|
2203
|
+
});
|
|
2204
|
+
}
|
|
2205
|
+
/** Get a single city/town by slug. */
|
|
2206
|
+
async city(slug) {
|
|
2207
|
+
return this.client.request("GET", `/v1/geo/cities/${slug}`);
|
|
2208
|
+
}
|
|
2209
|
+
};
|
|
2210
|
+
|
|
2211
|
+
// src/resources/deploy-hooks.ts
|
|
2212
|
+
var DeployHooksResource = class {
|
|
2213
|
+
constructor(client) {
|
|
2214
|
+
this.client = client;
|
|
2215
|
+
}
|
|
2216
|
+
client;
|
|
2217
|
+
async list(params) {
|
|
2218
|
+
return this.client.request("GET", "/v1/store/deploy-hooks", {
|
|
2219
|
+
params
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
iterate(params, options) {
|
|
2223
|
+
return paginate((cursor) => this.list({ ...params, cursor }), options);
|
|
2224
|
+
}
|
|
2225
|
+
async toArray(params, options) {
|
|
2226
|
+
return toArray(this.iterate(params, options), options);
|
|
2227
|
+
}
|
|
2228
|
+
async get(id) {
|
|
2229
|
+
return this.client.request("GET", `/v1/store/deploy-hooks/${id}`);
|
|
2230
|
+
}
|
|
2231
|
+
async create(body, options) {
|
|
2232
|
+
return this.client.request("POST", "/v1/store/deploy-hooks", { body, ...options });
|
|
2233
|
+
}
|
|
2234
|
+
async update(id, body) {
|
|
2235
|
+
return this.client.request("PATCH", `/v1/store/deploy-hooks/${id}`, { body });
|
|
2236
|
+
}
|
|
2237
|
+
async delete(id) {
|
|
2238
|
+
return this.client.request("DELETE", `/v1/store/deploy-hooks/${id}`);
|
|
2239
|
+
}
|
|
2240
|
+
async test(id) {
|
|
2241
|
+
return this.client.request("POST", `/v1/store/deploy-hooks/${id}/test`);
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2245
|
+
// src/client.ts
|
|
2246
|
+
var SDK_VERSION = "0.1.0";
|
|
2247
|
+
var INITIAL_RETRY_DELAY = 0.5;
|
|
2248
|
+
var MAX_RETRY_DELAY = 5;
|
|
2249
|
+
var MAX_RETRY_AFTER = 60;
|
|
2250
|
+
var VALID_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
2251
|
+
"apiKey",
|
|
2252
|
+
"baseUrl",
|
|
2253
|
+
"timeout",
|
|
2254
|
+
"maxNetworkRetries",
|
|
2255
|
+
"appInfo"
|
|
2256
|
+
]);
|
|
2257
|
+
function getRetryDelay(attempt, retryAfter) {
|
|
2258
|
+
let delay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, attempt - 1), MAX_RETRY_DELAY);
|
|
2259
|
+
delay *= 0.5 * (1 + Math.random());
|
|
2260
|
+
delay = Math.max(INITIAL_RETRY_DELAY, delay);
|
|
2261
|
+
if (retryAfter !== void 0 && retryAfter <= MAX_RETRY_AFTER) {
|
|
2262
|
+
delay = Math.max(delay, retryAfter);
|
|
2263
|
+
}
|
|
2264
|
+
return delay * 1e3;
|
|
2265
|
+
}
|
|
2266
|
+
function sleep(ms) {
|
|
2267
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2268
|
+
}
|
|
2269
|
+
var OneFive = class {
|
|
2270
|
+
apiKey;
|
|
2271
|
+
baseUrl;
|
|
2272
|
+
timeout;
|
|
2273
|
+
maxNetworkRetries;
|
|
2274
|
+
appInfo;
|
|
2275
|
+
_customerToken = null;
|
|
2276
|
+
/** Current customer access token, or null if not set. */
|
|
2277
|
+
get customerToken() {
|
|
2278
|
+
return this._customerToken;
|
|
2279
|
+
}
|
|
2280
|
+
/** Set a customer access token (JWT). Subsequent requests include `Authorization: Bearer {token}`. */
|
|
2281
|
+
setCustomerToken(token) {
|
|
2282
|
+
this._customerToken = token;
|
|
2283
|
+
}
|
|
2284
|
+
/** Clear the customer access token. */
|
|
2285
|
+
clearCustomerToken() {
|
|
2286
|
+
this._customerToken = null;
|
|
2287
|
+
}
|
|
2288
|
+
// P1: Storefront essentials
|
|
2289
|
+
products = new ProductsResource(this);
|
|
2290
|
+
variants = new VariantsResource(this);
|
|
2291
|
+
collections = new CollectionsResource(this);
|
|
2292
|
+
cart = new CartResource(this);
|
|
2293
|
+
checkout = new CheckoutResource(this);
|
|
2294
|
+
checkouts = new CheckoutsResource(this);
|
|
2295
|
+
search = new SearchResource(this);
|
|
2296
|
+
// P2: Order management
|
|
2297
|
+
orders = new OrdersResource(this);
|
|
2298
|
+
fulfillments = new FulfillmentsResource(this);
|
|
2299
|
+
refunds = new RefundsResource(this);
|
|
2300
|
+
returns = new ReturnsResource(this);
|
|
2301
|
+
draftOrders = new DraftOrdersResource(this);
|
|
2302
|
+
// P3: Customers
|
|
2303
|
+
customers = new CustomersResource(this);
|
|
2304
|
+
customerGroups = new CustomerGroupsResource(this);
|
|
2305
|
+
customerPhotos = new CustomerPhotosResource(this);
|
|
2306
|
+
addresses = new AddressesResource(this);
|
|
2307
|
+
storeCredit = new StoreCreditResource(this);
|
|
2308
|
+
// P4: Commerce operations
|
|
2309
|
+
inventory = new InventoryResource(this);
|
|
2310
|
+
shipping = new ShippingResource(this);
|
|
2311
|
+
promotions = new PromotionsResource(this);
|
|
2312
|
+
discounts = new DiscountsResource(this);
|
|
2313
|
+
// P5: Media & integrations
|
|
2314
|
+
images = new ImagesResource(this);
|
|
2315
|
+
webhooks = new WebhooksResource(this);
|
|
2316
|
+
store = new StoreResource(this);
|
|
2317
|
+
tags = new TagsResource(this);
|
|
2318
|
+
redirects = new RedirectsResource(this);
|
|
2319
|
+
// P6: Advanced
|
|
2320
|
+
channels = new ChannelsResource(this);
|
|
2321
|
+
locations = new LocationsResource(this);
|
|
2322
|
+
companies = new CompaniesResource(this);
|
|
2323
|
+
purchaseOrders = new PurchaseOrdersResource(this);
|
|
2324
|
+
fulfillmentOrders = new FulfillmentOrdersResource(this);
|
|
2325
|
+
metafields = new MetafieldsResource(this);
|
|
2326
|
+
tax = new TaxResource(this);
|
|
2327
|
+
exchangeRates = new ExchangeRatesResource(this);
|
|
2328
|
+
filterAttributes = new FilterAttributesResource(this);
|
|
2329
|
+
navigation = new NavigationResource(this);
|
|
2330
|
+
notifications = new NotificationsResource(this);
|
|
2331
|
+
analytics = new AnalyticsResource(this);
|
|
2332
|
+
integrations = new IntegrationsResource(this);
|
|
2333
|
+
// P7: Content
|
|
2334
|
+
posts = new PostsResource(this);
|
|
2335
|
+
contentCategories = new ContentCategoriesResource(this);
|
|
2336
|
+
// P8: Subscriptions
|
|
2337
|
+
membershipPlans = new MembershipPlansResource(this);
|
|
2338
|
+
// P9: Bookings
|
|
2339
|
+
bookings = new BookingsResource(this);
|
|
2340
|
+
// P10: Lookbooks
|
|
2341
|
+
lookbooks = new LookbooksResource(this);
|
|
2342
|
+
// P11: Gift Cards
|
|
2343
|
+
giftCards = new GiftCardsResource(this);
|
|
2344
|
+
// P12: Customer Auth
|
|
2345
|
+
auth = new AuthResource(this);
|
|
2346
|
+
me = new MeResource(this);
|
|
2347
|
+
// P13: Forms
|
|
2348
|
+
forms = new FormsResource(this);
|
|
2349
|
+
formSubmissions = new FormSubmissionsResource(this);
|
|
2350
|
+
// P14: Directory
|
|
2351
|
+
directory = new DirectoryResource(this);
|
|
2352
|
+
directoryCategories = new DirectoryCategoriesResource(this);
|
|
2353
|
+
directoryTiers = new DirectoryTiersResource(this);
|
|
2354
|
+
// P15: Geo Reference Data
|
|
2355
|
+
geo = new GeoResource(this);
|
|
2356
|
+
// P16: Deploy Hooks
|
|
2357
|
+
deployHooks = new DeployHooksResource(this);
|
|
2358
|
+
constructor(config) {
|
|
2359
|
+
for (const key of Object.keys(config)) {
|
|
2360
|
+
if (!VALID_CONFIG_KEYS.has(key)) {
|
|
2361
|
+
throw new Error(
|
|
2362
|
+
`OneFive: unknown config option "${key}". Valid options: ${[...VALID_CONFIG_KEYS].join(", ")}`
|
|
2363
|
+
);
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
if (!config.apiKey) {
|
|
2367
|
+
throw new Error("OneFive: apiKey is required");
|
|
2368
|
+
}
|
|
2369
|
+
this.apiKey = config.apiKey;
|
|
2370
|
+
this.baseUrl = config.baseUrl ?? "https://api.onefive.dev";
|
|
2371
|
+
this.timeout = config.timeout ?? 8e4;
|
|
2372
|
+
this.maxNetworkRetries = config.maxNetworkRetries ?? 1;
|
|
2373
|
+
this.appInfo = config.appInfo;
|
|
2374
|
+
}
|
|
2375
|
+
async request(method, path, options) {
|
|
2376
|
+
const maxRetries = options?.maxNetworkRetries ?? this.maxNetworkRetries;
|
|
2377
|
+
let idempotencyKey = options?.idempotencyKey;
|
|
2378
|
+
if (method === "POST" && !idempotencyKey && maxRetries > 0) {
|
|
2379
|
+
idempotencyKey = `onefive-retry-${crypto.randomUUID()}`;
|
|
2380
|
+
}
|
|
2381
|
+
let lastError;
|
|
2382
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
2383
|
+
try {
|
|
2384
|
+
const res = await this.executeRequest(method, path, {
|
|
2385
|
+
...options,
|
|
2386
|
+
idempotencyKey
|
|
2387
|
+
});
|
|
2388
|
+
if (res.ok) {
|
|
2389
|
+
if (res.status === 204) return void 0;
|
|
2390
|
+
return res.json();
|
|
2391
|
+
}
|
|
2392
|
+
const error = await this.buildError(res);
|
|
2393
|
+
if (!this.shouldRetry(error, attempt, maxRetries)) {
|
|
2394
|
+
throw error;
|
|
2395
|
+
}
|
|
2396
|
+
lastError = error;
|
|
2397
|
+
const retryAfter = error.retryAfter;
|
|
2398
|
+
await sleep(getRetryDelay(attempt + 1, retryAfter));
|
|
2399
|
+
} catch (e) {
|
|
2400
|
+
if (e instanceof OneFiveError) throw e;
|
|
2401
|
+
if (attempt >= maxRetries) {
|
|
2402
|
+
const message = e instanceof Error ? e.message : "Connection failed";
|
|
2403
|
+
throw new OneFiveConnectionError(message.includes("abort") ? "Request timed out" : message);
|
|
2404
|
+
}
|
|
2405
|
+
lastError = e instanceof Error ? e : new Error(String(e));
|
|
2406
|
+
await sleep(getRetryDelay(attempt + 1));
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
throw lastError;
|
|
2410
|
+
}
|
|
2411
|
+
/** Multipart upload for file-based endpoints (e.g. images) */
|
|
2412
|
+
async upload(path, formData, options) {
|
|
2413
|
+
const maxRetries = options?.maxNetworkRetries ?? this.maxNetworkRetries;
|
|
2414
|
+
let lastError;
|
|
2415
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
2416
|
+
try {
|
|
2417
|
+
const res = await this.executeUpload(path, formData, options);
|
|
2418
|
+
if (res.ok) {
|
|
2419
|
+
return res.json();
|
|
2420
|
+
}
|
|
2421
|
+
const error = await this.buildError(res);
|
|
2422
|
+
if (!this.shouldRetry(error, attempt, maxRetries)) {
|
|
2423
|
+
throw error;
|
|
2424
|
+
}
|
|
2425
|
+
lastError = error;
|
|
2426
|
+
const retryAfter = error.retryAfter;
|
|
2427
|
+
await sleep(getRetryDelay(attempt + 1, retryAfter));
|
|
2428
|
+
} catch (e) {
|
|
2429
|
+
if (e instanceof OneFiveError) throw e;
|
|
2430
|
+
if (attempt >= maxRetries) {
|
|
2431
|
+
const message = e instanceof Error ? e.message : "Connection failed";
|
|
2432
|
+
throw new OneFiveConnectionError(message.includes("abort") ? "Request timed out" : message);
|
|
2433
|
+
}
|
|
2434
|
+
lastError = e instanceof Error ? e : new Error(String(e));
|
|
2435
|
+
await sleep(getRetryDelay(attempt + 1));
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
throw lastError;
|
|
2439
|
+
}
|
|
2440
|
+
// ── Private helpers ──
|
|
2441
|
+
executeRequest(method, path, options) {
|
|
2442
|
+
const url = new URL(path, this.baseUrl);
|
|
2443
|
+
if (options?.params) {
|
|
2444
|
+
for (const [key, value] of Object.entries(options.params)) {
|
|
2445
|
+
if (value === void 0 || value === null) continue;
|
|
2446
|
+
if (Array.isArray(value)) {
|
|
2447
|
+
url.searchParams.set(key, value.join(","));
|
|
2448
|
+
} else {
|
|
2449
|
+
url.searchParams.set(key, String(value));
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
const headers = {
|
|
2454
|
+
"X-API-Key": this.apiKey,
|
|
2455
|
+
"User-Agent": this.getUserAgent()
|
|
2456
|
+
};
|
|
2457
|
+
if (this._customerToken) {
|
|
2458
|
+
headers["Authorization"] = `Bearer ${this._customerToken}`;
|
|
2459
|
+
}
|
|
2460
|
+
if (options?.headers) {
|
|
2461
|
+
Object.assign(headers, options.headers);
|
|
2462
|
+
}
|
|
2463
|
+
if (options?.body) {
|
|
2464
|
+
headers["Content-Type"] = "application/json";
|
|
2465
|
+
}
|
|
2466
|
+
if (options?.idempotencyKey) {
|
|
2467
|
+
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
2468
|
+
}
|
|
2469
|
+
const { signal, cleanup } = this.buildSignal(options);
|
|
2470
|
+
return fetch(url.toString(), {
|
|
2471
|
+
method,
|
|
2472
|
+
headers,
|
|
2473
|
+
body: options?.body ? JSON.stringify(options.body) : void 0,
|
|
2474
|
+
signal
|
|
2475
|
+
}).finally(cleanup);
|
|
2476
|
+
}
|
|
2477
|
+
executeUpload(path, formData, options) {
|
|
2478
|
+
const url = new URL(path, this.baseUrl);
|
|
2479
|
+
const { signal, cleanup } = this.buildSignal(options);
|
|
2480
|
+
const headers = {
|
|
2481
|
+
"X-API-Key": this.apiKey,
|
|
2482
|
+
"User-Agent": this.getUserAgent()
|
|
2483
|
+
// No Content-Type — let the runtime set the multipart boundary
|
|
2484
|
+
};
|
|
2485
|
+
if (this._customerToken) {
|
|
2486
|
+
headers["Authorization"] = `Bearer ${this._customerToken}`;
|
|
2487
|
+
}
|
|
2488
|
+
return fetch(url.toString(), {
|
|
2489
|
+
method: "POST",
|
|
2490
|
+
headers,
|
|
2491
|
+
body: formData,
|
|
2492
|
+
signal
|
|
2493
|
+
}).finally(cleanup);
|
|
2494
|
+
}
|
|
2495
|
+
/**
|
|
2496
|
+
* Build an AbortSignal that fires on timeout OR user-supplied signal,
|
|
2497
|
+
* whichever comes first.
|
|
2498
|
+
*/
|
|
2499
|
+
buildSignal(options) {
|
|
2500
|
+
const timeout = options?.timeout ?? this.timeout;
|
|
2501
|
+
const controller = new AbortController();
|
|
2502
|
+
let timeoutId;
|
|
2503
|
+
if (timeout > 0) {
|
|
2504
|
+
timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
2505
|
+
}
|
|
2506
|
+
if (options?.signal) {
|
|
2507
|
+
if (options.signal.aborted) {
|
|
2508
|
+
controller.abort(options.signal.reason);
|
|
2509
|
+
} else {
|
|
2510
|
+
options.signal.addEventListener("abort", () => controller.abort(options.signal.reason), {
|
|
2511
|
+
once: true
|
|
2512
|
+
});
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
return {
|
|
2516
|
+
signal: controller.signal,
|
|
2517
|
+
cleanup: () => {
|
|
2518
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
2519
|
+
}
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
/**
|
|
2523
|
+
* Parse an error response into a typed OneFiveError subclass.
|
|
2524
|
+
* Non-JSON bodies (CDN 502, proxy HTML) surface the raw text for debuggability.
|
|
2525
|
+
*/
|
|
2526
|
+
async buildError(res) {
|
|
2527
|
+
let body;
|
|
2528
|
+
try {
|
|
2529
|
+
body = await res.json();
|
|
2530
|
+
} catch {
|
|
2531
|
+
const text = await res.text().catch(() => "");
|
|
2532
|
+
return new OneFiveConnectionError(
|
|
2533
|
+
`Non-JSON error response (HTTP ${res.status}): ${text.slice(0, 200)}`
|
|
2534
|
+
);
|
|
2535
|
+
}
|
|
2536
|
+
switch (res.status) {
|
|
2537
|
+
case 401:
|
|
2538
|
+
return new OneFiveAuthenticationError(body, res.headers);
|
|
2539
|
+
case 403:
|
|
2540
|
+
return new OneFivePermissionError(body, res.headers);
|
|
2541
|
+
case 404:
|
|
2542
|
+
return new OneFiveNotFoundError(body, res.headers);
|
|
2543
|
+
case 409:
|
|
2544
|
+
return new OneFiveIdempotencyError(body, res.headers);
|
|
2545
|
+
case 429:
|
|
2546
|
+
return new OneFiveRateLimitError(body, res.headers);
|
|
2547
|
+
default:
|
|
2548
|
+
if (res.status === 400 && body.error.code === "validation_error") {
|
|
2549
|
+
return new OneFiveValidationError(body, res.headers);
|
|
2550
|
+
}
|
|
2551
|
+
return new OneFiveError(body, res.status, res.headers);
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
/**
|
|
2555
|
+
* Determine whether a failed request should be retried.
|
|
2556
|
+
* Client errors (400, 401, 403, 404) are never retried — they won't change.
|
|
2557
|
+
*/
|
|
2558
|
+
shouldRetry(error, attempt, maxRetries) {
|
|
2559
|
+
if (attempt >= maxRetries) return false;
|
|
2560
|
+
return error.status === 408 || error.status === 409 || error.status === 429 || error.status >= 500;
|
|
2561
|
+
}
|
|
2562
|
+
getUserAgent() {
|
|
2563
|
+
let ua = `onefive-sdk/${SDK_VERSION}`;
|
|
2564
|
+
if (this.appInfo) {
|
|
2565
|
+
ua += ` ${this.appInfo.name}`;
|
|
2566
|
+
if (this.appInfo.version) ua += `/${this.appInfo.version}`;
|
|
2567
|
+
if (this.appInfo.url) ua += ` (${this.appInfo.url})`;
|
|
2568
|
+
}
|
|
2569
|
+
return ua;
|
|
2570
|
+
}
|
|
2571
|
+
};
|
|
2572
|
+
export {
|
|
2573
|
+
AddressesResource,
|
|
2574
|
+
AnalyticsResource,
|
|
2575
|
+
AuthResource,
|
|
2576
|
+
BookingsResource,
|
|
2577
|
+
CartResource,
|
|
2578
|
+
ChannelsResource,
|
|
2579
|
+
CheckoutResource,
|
|
2580
|
+
CheckoutsResource,
|
|
2581
|
+
CollectionsResource,
|
|
2582
|
+
CompaniesResource,
|
|
2583
|
+
ContentCategoriesResource,
|
|
2584
|
+
CustomerGroupsResource,
|
|
2585
|
+
CustomerPhotosResource,
|
|
2586
|
+
CustomersResource,
|
|
2587
|
+
DeployHooksResource,
|
|
2588
|
+
DirectoryCategoriesResource,
|
|
2589
|
+
DirectoryResource,
|
|
2590
|
+
DirectoryTiersResource,
|
|
2591
|
+
DiscountsResource,
|
|
2592
|
+
DraftOrdersResource,
|
|
2593
|
+
ExchangeRatesResource,
|
|
2594
|
+
FormSubmissionsResource,
|
|
2595
|
+
FormsResource,
|
|
2596
|
+
FulfillmentOrdersResource,
|
|
2597
|
+
FulfillmentsResource,
|
|
2598
|
+
GeoResource,
|
|
2599
|
+
GiftCardsResource,
|
|
2600
|
+
ImagesResource,
|
|
2601
|
+
IntegrationsResource,
|
|
2602
|
+
InventoryResource,
|
|
2603
|
+
LocationsResource,
|
|
2604
|
+
LookbooksResource,
|
|
2605
|
+
MeResource,
|
|
2606
|
+
MembershipPlansResource,
|
|
2607
|
+
MetafieldsResource,
|
|
2608
|
+
NotificationsResource,
|
|
2609
|
+
OneFive,
|
|
2610
|
+
OneFiveAuthenticationError,
|
|
2611
|
+
OneFiveConnectionError,
|
|
2612
|
+
OneFiveError,
|
|
2613
|
+
OneFiveIdempotencyError,
|
|
2614
|
+
OneFiveNotFoundError,
|
|
2615
|
+
OneFivePermissionError,
|
|
2616
|
+
OneFiveRateLimitError,
|
|
2617
|
+
OneFiveValidationError,
|
|
2618
|
+
OrdersResource,
|
|
2619
|
+
PostsResource,
|
|
2620
|
+
ProductsResource,
|
|
2621
|
+
PromotionsResource,
|
|
2622
|
+
PurchaseOrdersResource,
|
|
2623
|
+
RedirectsResource,
|
|
2624
|
+
RefundsResource,
|
|
2625
|
+
ReturnsResource,
|
|
2626
|
+
SearchResource,
|
|
2627
|
+
ShippingResource,
|
|
2628
|
+
StoreCreditResource,
|
|
2629
|
+
StoreResource,
|
|
2630
|
+
TagsResource,
|
|
2631
|
+
TaxResource,
|
|
2632
|
+
VariantsResource,
|
|
2633
|
+
WebhooksResource,
|
|
2634
|
+
paginate,
|
|
2635
|
+
toArray
|
|
2636
|
+
};
|