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