@betterstore/sdk 0.3.107 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -26,26 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var __async = (__this, __arguments, generator) => {
30
- return new Promise((resolve, reject) => {
31
- var fulfilled = (value) => {
32
- try {
33
- step(generator.next(value));
34
- } catch (e) {
35
- reject(e);
36
- }
37
- };
38
- var rejected = (value) => {
39
- try {
40
- step(generator.throw(value));
41
- } catch (e) {
42
- reject(e);
43
- }
44
- };
45
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
- step((generator = generator.apply(__this, __arguments)).next());
47
- });
48
- };
49
29
 
50
30
  // src/index.ts
51
31
  var index_exports = {};
@@ -61,7 +41,7 @@ var import_axios = __toESM(require("axios"));
61
41
  var API_BASE_URL = "https://api.betterstore.io/v1";
62
42
  var createApiClient = (apiKey, proxy) => {
63
43
  const client = import_axios.default.create({
64
- baseURL: proxy != null ? proxy : API_BASE_URL,
44
+ baseURL: proxy ?? API_BASE_URL,
65
45
  headers: {
66
46
  "Content-Type": "application/json",
67
47
  Authorization: `Bearer ${apiKey}`,
@@ -73,7 +53,6 @@ var createApiClient = (apiKey, proxy) => {
73
53
  client.interceptors.response.use(
74
54
  (response) => response.data,
75
55
  (error) => {
76
- var _a, _b;
77
56
  const apiError = {
78
57
  isError: true,
79
58
  status: 500,
@@ -81,8 +60,8 @@ var createApiClient = (apiKey, proxy) => {
81
60
  };
82
61
  if (error.response) {
83
62
  apiError.status = error.response.status;
84
- apiError.message = ((_a = error.response.data) == null ? void 0 : _a.error) || "Server error occurred";
85
- apiError.code = (_b = error.response.data) == null ? void 0 : _b.code;
63
+ apiError.message = error.response.data?.error || "Server error occurred";
64
+ apiError.code = error.response.data?.code;
86
65
  apiError.details = error.response.data;
87
66
  } else if (error.request) {
88
67
  apiError.status = 503;
@@ -107,523 +86,469 @@ var createApiClient = (apiKey, proxy) => {
107
86
 
108
87
  // src/auth/providers/otp.ts
109
88
  var OTP = class {
89
+ apiClient;
110
90
  constructor(apiClient) {
111
91
  this.apiClient = apiClient;
112
92
  }
113
- signup(params) {
114
- return __async(this, null, function* () {
115
- const data = yield this.apiClient.post(
116
- "/auth/otp/signup",
117
- params
118
- );
119
- return data;
120
- });
121
- }
122
- login(params) {
123
- return __async(this, null, function* () {
124
- const data = yield this.apiClient.post(
125
- "/auth/otp/login",
126
- params
127
- );
128
- return data;
129
- });
130
- }
131
- verify(params) {
132
- return __async(this, null, function* () {
133
- const data = yield this.apiClient.post(
134
- "/auth/otp/verify",
135
- params
136
- );
137
- return data;
138
- });
93
+ async signup(params) {
94
+ const data = await this.apiClient.post(
95
+ "/auth/otp/signup",
96
+ params
97
+ );
98
+ return data;
99
+ }
100
+ async login(params) {
101
+ const data = await this.apiClient.post(
102
+ "/auth/otp/login",
103
+ params
104
+ );
105
+ return data;
106
+ }
107
+ async verify(params) {
108
+ const data = await this.apiClient.post(
109
+ "/auth/otp/verify",
110
+ params
111
+ );
112
+ return data;
139
113
  }
140
114
  };
141
115
 
142
116
  // src/auth/index.ts
143
117
  var Auth = class {
118
+ apiClient;
119
+ otp;
144
120
  constructor(apiKey, proxy) {
145
121
  this.apiClient = createApiClient(apiKey, proxy);
146
122
  this.otp = new OTP(this.apiClient);
147
123
  }
148
- retrieveSession(id) {
149
- return __async(this, null, function* () {
150
- const data = yield this.apiClient.get(
151
- `/auth/session/${id}`
152
- );
153
- if ("isError" in data && data.isError || !data || !("token" in data)) {
154
- console.error(`Customer session with id ${id} not found`);
155
- return null;
156
- }
157
- return data;
158
- });
124
+ async retrieveSession(id) {
125
+ const data = await this.apiClient.get(
126
+ `/auth/session/${id}`
127
+ );
128
+ if ("isError" in data && data.isError || !data || !("token" in data)) {
129
+ console.error(`Customer session with id ${id} not found`);
130
+ return null;
131
+ }
132
+ return data;
159
133
  }
160
134
  };
161
135
  var auth_default = Auth;
162
136
 
163
137
  // src/checkout/index.ts
164
138
  var Checkout = class {
139
+ apiClient;
165
140
  constructor(apiKey, proxy) {
166
141
  this.apiClient = createApiClient(apiKey, proxy);
167
142
  }
168
143
  /**
169
144
  * Create a new checkout session
170
145
  */
171
- create(params) {
172
- return __async(this, null, function* () {
173
- const data = yield this.apiClient.post(
174
- "/checkout",
175
- params
176
- );
177
- if ("isError" in data && data.isError || !data || !("id" in data)) {
178
- throw new Error("Failed to create checkout session");
179
- }
180
- return data;
181
- });
146
+ async create(params) {
147
+ const data = await this.apiClient.post(
148
+ "/checkout",
149
+ params
150
+ );
151
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
152
+ throw new Error("Failed to create checkout session");
153
+ }
154
+ return data;
182
155
  }
183
156
  /**
184
157
  * Retrieve a checkout session by ID
185
158
  */
186
- retrieve(checkoutId) {
187
- return __async(this, null, function* () {
188
- const data = yield this.apiClient.get(
189
- `/checkout/${checkoutId}`
190
- );
191
- if ("isError" in data && data.isError || !data || !("id" in data)) {
192
- console.error(`Checkout session with id ${checkoutId} not found`);
193
- return null;
194
- }
195
- return data;
196
- });
159
+ async retrieve(checkoutId) {
160
+ const data = await this.apiClient.get(
161
+ `/checkout/${checkoutId}`
162
+ );
163
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
164
+ console.error(`Checkout session with id ${checkoutId} not found`);
165
+ return null;
166
+ }
167
+ return data;
197
168
  }
198
169
  /**
199
170
  * Update a checkout session
200
171
  */
201
- update(checkoutId, params) {
202
- return __async(this, null, function* () {
203
- const data = yield this.apiClient.put(
204
- `/checkout/${checkoutId}`,
205
- params
206
- );
207
- if ("isError" in data && data.isError || !data || !("id" in data)) {
208
- console.error(`Checkout session with id ${checkoutId} not found`);
209
- return null;
210
- }
211
- return data;
212
- });
172
+ async update(checkoutId, params) {
173
+ const data = await this.apiClient.put(
174
+ `/checkout/${checkoutId}`,
175
+ params
176
+ );
177
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
178
+ console.error(`Checkout session with id ${checkoutId} not found`);
179
+ return null;
180
+ }
181
+ return data;
213
182
  }
214
183
  /**
215
184
  * Apply a discount code to a checkout session
216
185
  */
217
- applyDiscountCode(checkoutId, discountCode) {
218
- return __async(this, null, function* () {
219
- const data = yield this.apiClient.post(
220
- `/checkout/${checkoutId}/discounts/apply`,
221
- { code: discountCode }
222
- );
223
- if ("isError" in data && data.isError || !data || !("id" in data)) {
224
- throw new Error("Failed to apply discount code");
225
- }
226
- return data;
227
- });
186
+ async applyDiscountCode(checkoutId, discountCode) {
187
+ const data = await this.apiClient.post(
188
+ `/checkout/${checkoutId}/discounts/apply`,
189
+ { code: discountCode }
190
+ );
191
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
192
+ throw new Error("Failed to apply discount code");
193
+ }
194
+ return data;
228
195
  }
229
196
  /**
230
197
  * Remove a discount from a checkout session
231
198
  */
232
- removeDiscount(checkoutId, discountId) {
233
- return __async(this, null, function* () {
234
- const data = yield this.apiClient.delete(
235
- `/checkout/${checkoutId}/discounts/${discountId}`
236
- );
237
- if ("isError" in data && data.isError || !data || !("id" in data)) {
238
- console.error(`Checkout session with id ${checkoutId} not found`);
239
- return null;
240
- }
241
- return data;
242
- });
199
+ async removeDiscount(checkoutId, discountId) {
200
+ const data = await this.apiClient.delete(
201
+ `/checkout/${checkoutId}/discounts/${discountId}`
202
+ );
203
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
204
+ console.error(`Checkout session with id ${checkoutId} not found`);
205
+ return null;
206
+ }
207
+ return data;
243
208
  }
244
209
  /**
245
210
  * Revalidate a checkout session
246
211
  */
247
- revalidateDiscounts(checkoutId) {
248
- return __async(this, null, function* () {
249
- const data = yield this.apiClient.get(
250
- `/checkout/${checkoutId}/discounts/revalidate`
251
- );
252
- if ("isError" in data && data.isError || !data || !("id" in data)) {
253
- console.error(`Checkout session with id ${checkoutId} not found`);
254
- return null;
255
- }
256
- return data;
257
- });
212
+ async revalidateDiscounts(checkoutId) {
213
+ const data = await this.apiClient.get(
214
+ `/checkout/${checkoutId}/discounts/revalidate`
215
+ );
216
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
217
+ console.error(`Checkout session with id ${checkoutId} not found`);
218
+ return null;
219
+ }
220
+ return data;
258
221
  }
259
222
  /**
260
223
  * Get shipping rates for a checkout session
261
224
  */
262
- getShippingRates(checkoutId) {
263
- return __async(this, null, function* () {
264
- const data = yield this.apiClient.get(
265
- `/checkout/shipping/${checkoutId}`
266
- );
267
- if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
268
- return [];
269
- }
270
- return data;
271
- });
225
+ async getShippingRates(checkoutId) {
226
+ const data = await this.apiClient.get(
227
+ `/checkout/shipping/${checkoutId}`
228
+ );
229
+ if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
230
+ return [];
231
+ }
232
+ return data;
272
233
  }
273
234
  /**
274
235
  * Generate payment secret for a checkout session
275
236
  */
276
- generatePaymentSecret(checkoutId) {
277
- return __async(this, null, function* () {
278
- const data = yield this.apiClient.post(`
237
+ async generatePaymentSecret(checkoutId) {
238
+ const data = await this.apiClient.post(`
279
239
  /checkout/payment/${checkoutId}`);
280
- if ("isError" in data && data.isError || !data || !("paymentSecret" in data)) {
281
- throw new Error("Failed to generate payment secret");
282
- }
283
- return {
284
- paymentSecret: data.paymentSecret,
285
- publicKey: data.publicKey,
286
- checkoutSession: data.checkoutSession
287
- };
288
- });
240
+ if ("isError" in data && data.isError || !data || !("paymentSecret" in data)) {
241
+ throw new Error("Failed to generate payment secret");
242
+ }
243
+ return {
244
+ paymentSecret: data.paymentSecret,
245
+ publicKey: data.publicKey,
246
+ checkoutSession: data.checkoutSession
247
+ };
289
248
  }
290
249
  };
291
250
  var checkout_default = Checkout;
292
251
 
293
252
  // src/client/index.ts
294
253
  var Client = class {
254
+ proxy;
295
255
  constructor(proxy) {
296
256
  this.proxy = proxy;
297
257
  }
298
258
  /**
299
259
  * Retrieve a checkout session by ID
300
260
  */
301
- retrieveCheckout(clientSecret, checkoutId) {
302
- return __async(this, null, function* () {
303
- const apiClient = createApiClient(clientSecret, this.proxy);
304
- const data = yield apiClient.get(
305
- `/checkout/${checkoutId}`
306
- );
307
- if ("isError" in data && data.isError || !data || !("id" in data)) {
308
- console.error(`Checkout session with id ${checkoutId} not found`);
309
- return null;
310
- }
311
- return data;
312
- });
261
+ async retrieveCheckout(clientSecret, checkoutId) {
262
+ const apiClient = createApiClient(clientSecret, this.proxy);
263
+ const data = await apiClient.get(
264
+ `/checkout/${checkoutId}`
265
+ );
266
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
267
+ console.error(`Checkout session with id ${checkoutId} not found`);
268
+ return null;
269
+ }
270
+ return data;
313
271
  }
314
272
  /**
315
273
  * Update a checkout session
316
274
  */
317
- updateCheckout(clientSecret, checkoutId, params) {
318
- return __async(this, null, function* () {
319
- const apiClient = createApiClient(clientSecret, this.proxy);
320
- const data = yield apiClient.put(
321
- `/checkout/${checkoutId}`,
322
- params
323
- );
324
- if ("isError" in data && data.isError || !data || !("id" in data)) {
325
- console.error(`Checkout session with id ${checkoutId} not found`);
326
- return null;
327
- }
328
- return data;
329
- });
275
+ async updateCheckout(clientSecret, checkoutId, params) {
276
+ const apiClient = createApiClient(clientSecret, this.proxy);
277
+ const data = await apiClient.put(
278
+ `/checkout/${checkoutId}`,
279
+ params
280
+ );
281
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
282
+ console.error(`Checkout session with id ${checkoutId} not found`);
283
+ return null;
284
+ }
285
+ return data;
330
286
  }
331
287
  /**
332
288
  * Apply a discount code to a checkout session
333
289
  */
334
- applyDiscountCode(clientSecret, checkoutId, discountCode) {
335
- return __async(this, null, function* () {
336
- const apiClient = createApiClient(clientSecret, this.proxy);
337
- const data = yield apiClient.post(
338
- `/checkout/${checkoutId}/discounts/apply`,
339
- { code: discountCode }
340
- );
341
- if ("isError" in data && data.isError || !data || !("id" in data)) {
342
- throw new Error("Failed to apply discount code");
343
- }
344
- return data;
345
- });
290
+ async applyDiscountCode(clientSecret, checkoutId, discountCode) {
291
+ const apiClient = createApiClient(clientSecret, this.proxy);
292
+ const data = await apiClient.post(
293
+ `/checkout/${checkoutId}/discounts/apply`,
294
+ { code: discountCode }
295
+ );
296
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
297
+ throw new Error("Failed to apply discount code");
298
+ }
299
+ return data;
346
300
  }
347
301
  /**
348
302
  * Remove a discount code from a checkout session
349
303
  */
350
- removeDiscount(clientSecret, checkoutId, discountId) {
351
- return __async(this, null, function* () {
352
- const apiClient = createApiClient(clientSecret, this.proxy);
353
- const data = yield apiClient.delete(
354
- `/checkout/${checkoutId}/discounts/${discountId}`
355
- );
356
- if ("isError" in data && data.isError || !data || !("id" in data)) {
357
- throw new Error("Failed to remove discount code");
358
- }
359
- return data;
360
- });
304
+ async removeDiscount(clientSecret, checkoutId, discountId) {
305
+ const apiClient = createApiClient(clientSecret, this.proxy);
306
+ const data = await apiClient.delete(
307
+ `/checkout/${checkoutId}/discounts/${discountId}`
308
+ );
309
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
310
+ throw new Error("Failed to remove discount code");
311
+ }
312
+ return data;
361
313
  }
362
314
  /**
363
315
  * Revalidate a checkout session
364
316
  */
365
- revalidateDiscounts(clientSecret, checkoutId) {
366
- return __async(this, null, function* () {
367
- const apiClient = createApiClient(clientSecret, this.proxy);
368
- const data = yield apiClient.get(
369
- `/checkout/${checkoutId}/discounts/revalidate`
370
- );
371
- if ("isError" in data && data.isError || !data || !("id" in data)) {
372
- console.error(`Checkout session with id ${checkoutId} not found`);
373
- return null;
374
- }
375
- return data;
376
- });
317
+ async revalidateDiscounts(clientSecret, checkoutId) {
318
+ const apiClient = createApiClient(clientSecret, this.proxy);
319
+ const data = await apiClient.get(
320
+ `/checkout/${checkoutId}/discounts/revalidate`
321
+ );
322
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
323
+ console.error(`Checkout session with id ${checkoutId} not found`);
324
+ return null;
325
+ }
326
+ return data;
377
327
  }
378
328
  /**
379
329
  * Get shipping rates for a checkout session
380
330
  */
381
- getCheckoutShippingRates(clientSecret, checkoutId) {
382
- return __async(this, null, function* () {
383
- const apiClient = createApiClient(clientSecret, this.proxy);
384
- const data = yield apiClient.get(
385
- `/checkout/shipping/${checkoutId}`
386
- );
387
- if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
388
- return [];
389
- }
390
- return data;
391
- });
331
+ async getCheckoutShippingRates(clientSecret, checkoutId) {
332
+ const apiClient = createApiClient(clientSecret, this.proxy);
333
+ const data = await apiClient.get(
334
+ `/checkout/shipping/${checkoutId}`
335
+ );
336
+ if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
337
+ return [];
338
+ }
339
+ return data;
392
340
  }
393
341
  /**
394
342
  * Generate payment secret for a checkout session
395
343
  */
396
- generateCheckoutPaymentSecret(clientSecret, checkoutId) {
397
- return __async(this, null, function* () {
398
- const apiClient = createApiClient(clientSecret, this.proxy);
399
- const data = yield apiClient.post(`/checkout/payment/${checkoutId}`);
400
- if ("isError" in data && data.isError || !data || !("paymentSecret" in data)) {
401
- throw new Error("Failed to generate payment secret");
402
- }
403
- return {
404
- paymentSecret: data.paymentSecret,
405
- publicKey: data.publicKey,
406
- checkoutSession: data.checkoutSession
407
- };
408
- });
344
+ async generateCheckoutPaymentSecret(clientSecret, checkoutId) {
345
+ const apiClient = createApiClient(clientSecret, this.proxy);
346
+ const data = await apiClient.post(`/checkout/payment/${checkoutId}`);
347
+ if ("isError" in data && data.isError || !data || !("paymentSecret" in data)) {
348
+ throw new Error("Failed to generate payment secret");
349
+ }
350
+ return {
351
+ paymentSecret: data.paymentSecret,
352
+ publicKey: data.publicKey,
353
+ checkoutSession: data.checkoutSession
354
+ };
409
355
  }
410
356
  /**
411
357
  * Create a new customer
412
358
  */
413
- createCustomer(clientSecret, params) {
414
- return __async(this, null, function* () {
415
- const apiClient = createApiClient(clientSecret, this.proxy);
416
- const data = yield apiClient.post(
417
- "/customer",
418
- params
419
- );
420
- if ("isError" in data && data.isError || !data || !("id" in data)) {
421
- throw new Error("Failed to create customer");
422
- }
423
- return data;
424
- });
359
+ async createCustomer(clientSecret, params) {
360
+ const apiClient = createApiClient(clientSecret, this.proxy);
361
+ const data = await apiClient.post(
362
+ "/customer",
363
+ params
364
+ );
365
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
366
+ throw new Error("Failed to create customer");
367
+ }
368
+ return data;
425
369
  }
426
370
  /**
427
371
  * Retrieve a customer by ID or email
428
372
  */
429
- retrieveCustomer(clientSecret, idOrEmail) {
430
- return __async(this, null, function* () {
431
- const apiClient = createApiClient(clientSecret, this.proxy);
432
- const data = yield apiClient.get(
433
- `/customer/${idOrEmail}`
434
- );
435
- if ("isError" in data && data.isError || !data || !("id" in data)) {
436
- console.error(`Customer with id or email ${idOrEmail} not found`);
437
- return null;
438
- }
439
- return data;
440
- });
373
+ async retrieveCustomer(clientSecret, idOrEmail) {
374
+ const apiClient = createApiClient(clientSecret, this.proxy);
375
+ const data = await apiClient.get(
376
+ `/customer/${idOrEmail}`
377
+ );
378
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
379
+ console.error(`Customer with id or email ${idOrEmail} not found`);
380
+ return null;
381
+ }
382
+ return data;
441
383
  }
442
384
  /**
443
385
  * Update a customer
444
386
  */
445
- updateCustomer(clientSecret, customerId, params) {
446
- return __async(this, null, function* () {
447
- const apiClient = createApiClient(clientSecret, this.proxy);
448
- const data = yield apiClient.put(
449
- `/customer/${customerId}`,
450
- params
451
- );
452
- if ("isError" in data && data.isError || !data || !("id" in data)) {
453
- console.error(`Customer with id ${customerId} not found`);
454
- return null;
455
- }
456
- return data;
457
- });
387
+ async updateCustomer(clientSecret, customerId, params) {
388
+ const apiClient = createApiClient(clientSecret, this.proxy);
389
+ const data = await apiClient.put(
390
+ `/customer/${customerId}`,
391
+ params
392
+ );
393
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
394
+ console.error(`Customer with id ${customerId} not found`);
395
+ return null;
396
+ }
397
+ return data;
458
398
  }
459
399
  };
460
400
  var client_default = Client;
461
401
 
462
402
  // src/collections/index.ts
463
403
  var Collections = class {
404
+ apiClient;
464
405
  constructor(apiKey, proxy) {
465
406
  this.apiClient = createApiClient(apiKey, proxy);
466
407
  }
467
- list(params) {
468
- return __async(this, null, function* () {
469
- const queryParams = new URLSearchParams();
470
- if (params) {
471
- queryParams.set("params", JSON.stringify(params));
472
- }
473
- const data = yield this.apiClient.get(
474
- `/collections?${queryParams.toString()}`
475
- );
476
- if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
477
- return [];
478
- }
479
- return data;
480
- });
408
+ async list(params) {
409
+ const queryParams = new URLSearchParams();
410
+ if (params) {
411
+ queryParams.set("params", JSON.stringify(params));
412
+ }
413
+ const data = await this.apiClient.get(
414
+ `/collections?${queryParams.toString()}`
415
+ );
416
+ if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
417
+ return [];
418
+ }
419
+ return data;
481
420
  }
482
- retrieve(params) {
483
- return __async(this, null, function* () {
484
- if ("seoHandle" in params) {
485
- const data2 = yield this.apiClient.get(
486
- `/collections/${params.seoHandle}`
487
- );
488
- if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
489
- console.error(
490
- `Collection with seoHandle ${params.seoHandle} not found`
491
- );
492
- return null;
493
- }
494
- return data2;
495
- }
496
- const data = yield this.apiClient.get(
497
- `/collections/id/${params.id}`
421
+ async retrieve(params) {
422
+ if ("seoHandle" in params) {
423
+ const data2 = await this.apiClient.get(
424
+ `/collections/${params.seoHandle}`
498
425
  );
499
- if ("isError" in data && data.isError || !data || !("id" in data)) {
500
- console.error(`Collection with id ${params.id} not found`);
426
+ if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
427
+ console.error(
428
+ `Collection with seoHandle ${params.seoHandle} not found`
429
+ );
501
430
  return null;
502
431
  }
503
- return data;
504
- });
432
+ return data2;
433
+ }
434
+ const data = await this.apiClient.get(
435
+ `/collections/id/${params.id}`
436
+ );
437
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
438
+ console.error(`Collection with id ${params.id} not found`);
439
+ return null;
440
+ }
441
+ return data;
505
442
  }
506
443
  };
507
444
  var collections_default = Collections;
508
445
 
509
446
  // src/customer/index.ts
510
447
  var Customer = class {
448
+ apiClient;
511
449
  constructor(apiKey, proxy) {
512
450
  this.apiClient = createApiClient(apiKey, proxy);
513
451
  }
514
452
  /**
515
453
  * Create a new customer
516
454
  */
517
- create(params) {
518
- return __async(this, null, function* () {
519
- const data = yield this.apiClient.post(
520
- "/customer",
521
- params
522
- );
523
- if ("isError" in data && data.isError || !data || !("id" in data)) {
524
- throw new Error("Failed to create customer");
525
- }
526
- return data;
527
- });
455
+ async create(params) {
456
+ const data = await this.apiClient.post(
457
+ "/customer",
458
+ params
459
+ );
460
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
461
+ throw new Error("Failed to create customer");
462
+ }
463
+ return data;
528
464
  }
529
465
  /**
530
466
  * Retrieve a customer by ID or email
531
467
  */
532
- retrieve(idOrEmail) {
533
- return __async(this, null, function* () {
534
- const data = yield this.apiClient.get(
535
- `/customer/${idOrEmail}`
536
- );
537
- if ("isError" in data && data.isError || !data || !("id" in data)) {
538
- console.error(`Customer with id or email ${idOrEmail} not found`);
539
- return null;
540
- }
541
- return data;
542
- });
468
+ async retrieve(idOrEmail) {
469
+ const data = await this.apiClient.get(
470
+ `/customer/${idOrEmail}`
471
+ );
472
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
473
+ console.error(`Customer with id or email ${idOrEmail} not found`);
474
+ return null;
475
+ }
476
+ return data;
543
477
  }
544
478
  /**
545
479
  * Update a customer
546
480
  */
547
- update(customerId, params) {
548
- return __async(this, null, function* () {
549
- const data = yield this.apiClient.put(
550
- `/customer/${customerId}`,
551
- params
552
- );
553
- if ("isError" in data && data.isError || !data || !("id" in data)) {
554
- console.error(`Customer with id ${customerId} not found`);
555
- return null;
556
- }
557
- return data;
558
- });
481
+ async update(customerId, params) {
482
+ const data = await this.apiClient.put(
483
+ `/customer/${customerId}`,
484
+ params
485
+ );
486
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
487
+ console.error(`Customer with id ${customerId} not found`);
488
+ return null;
489
+ }
490
+ return data;
559
491
  }
560
492
  /**
561
493
  * Delete a customer
562
494
  */
563
- delete(customerId) {
564
- return __async(this, null, function* () {
565
- yield this.apiClient.delete(`/customer/${customerId}`);
566
- });
495
+ async delete(customerId) {
496
+ await this.apiClient.delete(`/customer/${customerId}`);
567
497
  }
568
498
  /**
569
499
  * Update a customer subscription
570
500
  */
571
- updateCustomerSubscription(stripeSubscriptionId, params) {
572
- return __async(this, null, function* () {
573
- const data = yield this.apiClient.put(
574
- `/customer/subscription/${stripeSubscriptionId}`,
575
- params
576
- );
577
- if ("isError" in data && data.isError || !data || !("id" in data)) {
578
- return null;
579
- }
580
- return data;
581
- });
501
+ async updateCustomerSubscription(stripeSubscriptionId, params) {
502
+ const data = await this.apiClient.put(
503
+ `/customer/subscription/${stripeSubscriptionId}`,
504
+ params
505
+ );
506
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
507
+ return null;
508
+ }
509
+ return data;
582
510
  }
583
511
  };
584
512
  var customer_default = Customer;
585
513
 
586
514
  // src/discounts/index.ts
587
515
  var Discounts = class {
516
+ apiClient;
588
517
  constructor(apiKey, proxy) {
589
518
  this.apiClient = createApiClient(apiKey, proxy);
590
519
  }
591
- list(params) {
592
- return __async(this, null, function* () {
593
- const queryParams = new URLSearchParams();
594
- if (params) {
595
- queryParams.set("params", JSON.stringify(params));
596
- }
597
- const data = yield this.apiClient.get(
598
- `/discounts?${queryParams.toString()}`
599
- );
600
- if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
601
- return [];
602
- }
603
- return data;
604
- });
520
+ async list(params) {
521
+ const queryParams = new URLSearchParams();
522
+ if (params) {
523
+ queryParams.set("params", JSON.stringify(params));
524
+ }
525
+ const data = await this.apiClient.get(
526
+ `/discounts?${queryParams.toString()}`
527
+ );
528
+ if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
529
+ return [];
530
+ }
531
+ return data;
605
532
  }
606
- retrieve(params) {
607
- return __async(this, null, function* () {
608
- if ("code" in params) {
609
- const data2 = yield this.apiClient.get(
610
- `/discounts/code/${params.code}`
611
- );
612
- if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
613
- console.error(`Discount with code ${params.code} not found`);
614
- return null;
615
- }
616
- return data2;
617
- }
618
- const data = yield this.apiClient.get(
619
- `/discounts/id/${params.id}`
533
+ async retrieve(params) {
534
+ if ("code" in params) {
535
+ const data2 = await this.apiClient.get(
536
+ `/discounts/code/${params.code}`
620
537
  );
621
- if ("isError" in data && data.isError || !data || !("id" in data)) {
622
- console.error(`Discount with id ${params.id} not found`);
538
+ if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
539
+ console.error(`Discount with code ${params.code} not found`);
623
540
  return null;
624
541
  }
625
- return data;
626
- });
542
+ return data2;
543
+ }
544
+ const data = await this.apiClient.get(
545
+ `/discounts/id/${params.id}`
546
+ );
547
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
548
+ console.error(`Discount with id ${params.id} not found`);
549
+ return null;
550
+ }
551
+ return data;
627
552
  }
628
553
  };
629
554
  var discounts_default = Discounts;
@@ -694,12 +619,12 @@ var currencyLocales = {
694
619
  // Turkish Lira
695
620
  };
696
621
  var Helpers = class {
622
+ proxy;
697
623
  constructor(proxy) {
698
624
  this.proxy = proxy;
699
625
  }
700
626
  formatCurrency(currency) {
701
- var _a;
702
- const locale = (_a = currencyLocales[currency.toUpperCase()]) != null ? _a : void 0;
627
+ const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
703
628
  const formattedCurrency = new Intl.NumberFormat(locale, {
704
629
  style: "currency",
705
630
  currency,
@@ -708,10 +633,9 @@ var Helpers = class {
708
633
  return formattedCurrency.format(0).replace(/[\d.,\s]/g, "").trim();
709
634
  }
710
635
  formatPrice(priceInCents, currency, exchangeRate) {
711
- var _a;
712
- const amount = priceInCents / 100 * (exchangeRate != null ? exchangeRate : 1);
636
+ const amount = priceInCents / 100 * (exchangeRate ?? 1);
713
637
  const isWhole = amount % 1 === 0;
714
- const locale = (_a = currencyLocales[currency.toUpperCase()]) != null ? _a : void 0;
638
+ const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
715
639
  const formattedPrice = new Intl.NumberFormat(locale, {
716
640
  style: "currency",
717
641
  currency,
@@ -721,64 +645,59 @@ var Helpers = class {
721
645
  }).format(amount);
722
646
  return formattedPrice;
723
647
  }
724
- getExchangeRate(baseCurrency, targetCurrency) {
725
- return __async(this, null, function* () {
726
- const apiClient = createApiClient("", this.proxy);
727
- const { data } = yield apiClient.get(`/helpers/rates/${baseCurrency}`);
728
- const rate = data.rates[targetCurrency];
729
- if (!rate) {
730
- throw new Error("Could not get exchange rate for target currency");
731
- }
732
- return rate;
733
- });
648
+ async getExchangeRate(baseCurrency, targetCurrency) {
649
+ const apiClient = createApiClient("", this.proxy);
650
+ const { data } = await apiClient.get(`/helpers/rates/${baseCurrency}`);
651
+ const rate = data.rates[targetCurrency];
652
+ if (!rate) {
653
+ throw new Error("Could not get exchange rate for target currency");
654
+ }
655
+ return rate;
734
656
  }
735
657
  };
736
658
  var helpers_default = Helpers;
737
659
 
738
660
  // src/products/index.ts
739
661
  var Products = class {
662
+ apiClient;
740
663
  constructor(apiKey, proxy) {
741
664
  this.apiClient = createApiClient(apiKey, proxy);
742
665
  }
743
- list(params) {
744
- return __async(this, null, function* () {
745
- const queryParams = new URLSearchParams();
746
- if (params) {
747
- queryParams.set("params", JSON.stringify(params));
748
- }
749
- const data = yield this.apiClient.get(
750
- `/products?${queryParams.toString()}`
666
+ async list(params) {
667
+ const queryParams = new URLSearchParams();
668
+ if (params) {
669
+ queryParams.set("params", JSON.stringify(params));
670
+ }
671
+ const data = await this.apiClient.get(
672
+ `/products?${queryParams.toString()}`
673
+ );
674
+ if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
675
+ return [];
676
+ }
677
+ return data;
678
+ }
679
+ async retrieve(params) {
680
+ if ("seoHandle" in params && typeof params?.seoHandle === "string") {
681
+ const data = await this.apiClient.get(
682
+ `/products/${params.seoHandle}`
751
683
  );
752
- if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
753
- return [];
684
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
685
+ console.error(`Product with seoHandle ${params.seoHandle} not found`);
686
+ return null;
754
687
  }
755
688
  return data;
756
- });
757
- }
758
- retrieve(params) {
759
- return __async(this, null, function* () {
760
- if ("seoHandle" in params && typeof (params == null ? void 0 : params.seoHandle) === "string") {
761
- const data = yield this.apiClient.get(
762
- `/products/${params.seoHandle}`
763
- );
764
- if ("isError" in data && data.isError || !data || !("id" in data)) {
765
- console.error(`Product with seoHandle ${params.seoHandle} not found`);
766
- return null;
767
- }
768
- return data;
769
- }
770
- if ("id" in params && typeof (params == null ? void 0 : params.id) === "string") {
771
- const data = yield this.apiClient.get(
772
- `/products/id/${params.id}`
773
- );
774
- if ("isError" in data && data.isError || !data || !("id" in data)) {
775
- console.error(`Product with id ${params.id} not found`);
776
- return null;
777
- }
778
- return data;
689
+ }
690
+ if ("id" in params && typeof params?.id === "string") {
691
+ const data = await this.apiClient.get(
692
+ `/products/id/${params.id}`
693
+ );
694
+ if ("isError" in data && data.isError || !data || !("id" in data)) {
695
+ console.error(`Product with id ${params.id} not found`);
696
+ return null;
779
697
  }
780
- return null;
781
- });
698
+ return data;
699
+ }
700
+ return null;
782
701
  }
783
702
  };
784
703
  var products_default = Products;
@@ -798,10 +717,10 @@ function createBetterStore(config) {
798
717
  };
799
718
  }
800
719
  function createStoreClient(config) {
801
- return new client_default(config == null ? void 0 : config.proxy);
720
+ return new client_default(config?.proxy);
802
721
  }
803
722
  function createStoreHelpers(config) {
804
- return new helpers_default(config == null ? void 0 : config.proxy);
723
+ return new helpers_default(config?.proxy);
805
724
  }
806
725
  // Annotate the CommonJS export names for ESM import in node:
807
726
  0 && (module.exports = {