@betterstore/sdk 0.3.97 → 0.3.98
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/CHANGELOG.md +6 -0
- package/dist/index.d.mts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.js +125 -26
- package/dist/index.mjs +125 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as axios from 'axios';
|
|
2
2
|
|
|
3
|
-
declare const createApiClient: (apiKey: string, proxy?: string
|
|
3
|
+
declare const createApiClient: (apiKey: string, proxy?: string) => axios.AxiosInstance;
|
|
4
4
|
|
|
5
5
|
type ShippingRate = ZasilkovnaRate;
|
|
6
6
|
interface BaseRate {
|
|
@@ -401,11 +401,11 @@ declare class Checkout {
|
|
|
401
401
|
/**
|
|
402
402
|
* Retrieve a checkout session by ID
|
|
403
403
|
*/
|
|
404
|
-
retrieve(checkoutId: string): Promise<CheckoutSession>;
|
|
404
|
+
retrieve(checkoutId: string): Promise<CheckoutSession | null>;
|
|
405
405
|
/**
|
|
406
406
|
* Update a checkout session
|
|
407
407
|
*/
|
|
408
|
-
update(checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
|
|
408
|
+
update(checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession | null>;
|
|
409
409
|
/**
|
|
410
410
|
* Apply a discount code to a checkout session
|
|
411
411
|
*/
|
|
@@ -413,11 +413,11 @@ declare class Checkout {
|
|
|
413
413
|
/**
|
|
414
414
|
* Remove a discount from a checkout session
|
|
415
415
|
*/
|
|
416
|
-
removeDiscount(checkoutId: string, discountId: string): Promise<CheckoutSession>;
|
|
416
|
+
removeDiscount(checkoutId: string, discountId: string): Promise<CheckoutSession | null>;
|
|
417
417
|
/**
|
|
418
418
|
* Revalidate a checkout session
|
|
419
419
|
*/
|
|
420
|
-
revalidateDiscounts(checkoutId: string): Promise<CheckoutSession>;
|
|
420
|
+
revalidateDiscounts(checkoutId: string): Promise<CheckoutSession | null>;
|
|
421
421
|
/**
|
|
422
422
|
* Get shipping rates for a checkout session
|
|
423
423
|
*/
|
|
@@ -438,11 +438,11 @@ declare class Client {
|
|
|
438
438
|
/**
|
|
439
439
|
* Retrieve a checkout session by ID
|
|
440
440
|
*/
|
|
441
|
-
retrieveCheckout(clientSecret: string, checkoutId: string): Promise<CheckoutSession>;
|
|
441
|
+
retrieveCheckout(clientSecret: string, checkoutId: string): Promise<CheckoutSession | null>;
|
|
442
442
|
/**
|
|
443
443
|
* Update a checkout session
|
|
444
444
|
*/
|
|
445
|
-
updateCheckout(clientSecret: string, checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
|
|
445
|
+
updateCheckout(clientSecret: string, checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession | null>;
|
|
446
446
|
/**
|
|
447
447
|
* Apply a discount code to a checkout session
|
|
448
448
|
*/
|
|
@@ -454,7 +454,7 @@ declare class Client {
|
|
|
454
454
|
/**
|
|
455
455
|
* Revalidate a checkout session
|
|
456
456
|
*/
|
|
457
|
-
revalidateDiscounts(clientSecret: string, checkoutId: string): Promise<CheckoutSession>;
|
|
457
|
+
revalidateDiscounts(clientSecret: string, checkoutId: string): Promise<CheckoutSession | null>;
|
|
458
458
|
/**
|
|
459
459
|
* Get shipping rates for a checkout session
|
|
460
460
|
*/
|
|
@@ -474,11 +474,11 @@ declare class Client {
|
|
|
474
474
|
/**
|
|
475
475
|
* Retrieve a customer by ID or email
|
|
476
476
|
*/
|
|
477
|
-
retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<Customer$1>;
|
|
477
|
+
retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<Customer$1 | null>;
|
|
478
478
|
/**
|
|
479
479
|
* Update a customer
|
|
480
480
|
*/
|
|
481
|
-
updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<Customer$1>;
|
|
481
|
+
updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<Customer$1 | null>;
|
|
482
482
|
}
|
|
483
483
|
|
|
484
484
|
declare class Collections {
|
|
@@ -498,19 +498,19 @@ declare class Customer {
|
|
|
498
498
|
/**
|
|
499
499
|
* Retrieve a customer by ID or email
|
|
500
500
|
*/
|
|
501
|
-
retrieve(idOrEmail: string): Promise<Customer$1>;
|
|
501
|
+
retrieve(idOrEmail: string): Promise<Customer$1 | null>;
|
|
502
502
|
/**
|
|
503
503
|
* Update a customer
|
|
504
504
|
*/
|
|
505
|
-
update(customerId: string, params: CustomerUpdateParams): Promise<Customer$1>;
|
|
505
|
+
update(customerId: string, params: CustomerUpdateParams): Promise<Customer$1 | null>;
|
|
506
506
|
/**
|
|
507
507
|
* Delete a customer
|
|
508
508
|
*/
|
|
509
509
|
delete(customerId: string): Promise<void>;
|
|
510
510
|
/**
|
|
511
|
-
*
|
|
511
|
+
* Update a customer subscription
|
|
512
512
|
*/
|
|
513
|
-
updateCustomerSubscription(stripeSubscriptionId: string, params: CustomerSubscriptionUpdateParams): Promise<CustomerSubscription>;
|
|
513
|
+
updateCustomerSubscription(stripeSubscriptionId: string, params: CustomerSubscriptionUpdateParams): Promise<CustomerSubscription | null>;
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
declare class Discounts {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as axios from 'axios';
|
|
2
2
|
|
|
3
|
-
declare const createApiClient: (apiKey: string, proxy?: string
|
|
3
|
+
declare const createApiClient: (apiKey: string, proxy?: string) => axios.AxiosInstance;
|
|
4
4
|
|
|
5
5
|
type ShippingRate = ZasilkovnaRate;
|
|
6
6
|
interface BaseRate {
|
|
@@ -401,11 +401,11 @@ declare class Checkout {
|
|
|
401
401
|
/**
|
|
402
402
|
* Retrieve a checkout session by ID
|
|
403
403
|
*/
|
|
404
|
-
retrieve(checkoutId: string): Promise<CheckoutSession>;
|
|
404
|
+
retrieve(checkoutId: string): Promise<CheckoutSession | null>;
|
|
405
405
|
/**
|
|
406
406
|
* Update a checkout session
|
|
407
407
|
*/
|
|
408
|
-
update(checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
|
|
408
|
+
update(checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession | null>;
|
|
409
409
|
/**
|
|
410
410
|
* Apply a discount code to a checkout session
|
|
411
411
|
*/
|
|
@@ -413,11 +413,11 @@ declare class Checkout {
|
|
|
413
413
|
/**
|
|
414
414
|
* Remove a discount from a checkout session
|
|
415
415
|
*/
|
|
416
|
-
removeDiscount(checkoutId: string, discountId: string): Promise<CheckoutSession>;
|
|
416
|
+
removeDiscount(checkoutId: string, discountId: string): Promise<CheckoutSession | null>;
|
|
417
417
|
/**
|
|
418
418
|
* Revalidate a checkout session
|
|
419
419
|
*/
|
|
420
|
-
revalidateDiscounts(checkoutId: string): Promise<CheckoutSession>;
|
|
420
|
+
revalidateDiscounts(checkoutId: string): Promise<CheckoutSession | null>;
|
|
421
421
|
/**
|
|
422
422
|
* Get shipping rates for a checkout session
|
|
423
423
|
*/
|
|
@@ -438,11 +438,11 @@ declare class Client {
|
|
|
438
438
|
/**
|
|
439
439
|
* Retrieve a checkout session by ID
|
|
440
440
|
*/
|
|
441
|
-
retrieveCheckout(clientSecret: string, checkoutId: string): Promise<CheckoutSession>;
|
|
441
|
+
retrieveCheckout(clientSecret: string, checkoutId: string): Promise<CheckoutSession | null>;
|
|
442
442
|
/**
|
|
443
443
|
* Update a checkout session
|
|
444
444
|
*/
|
|
445
|
-
updateCheckout(clientSecret: string, checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
|
|
445
|
+
updateCheckout(clientSecret: string, checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession | null>;
|
|
446
446
|
/**
|
|
447
447
|
* Apply a discount code to a checkout session
|
|
448
448
|
*/
|
|
@@ -454,7 +454,7 @@ declare class Client {
|
|
|
454
454
|
/**
|
|
455
455
|
* Revalidate a checkout session
|
|
456
456
|
*/
|
|
457
|
-
revalidateDiscounts(clientSecret: string, checkoutId: string): Promise<CheckoutSession>;
|
|
457
|
+
revalidateDiscounts(clientSecret: string, checkoutId: string): Promise<CheckoutSession | null>;
|
|
458
458
|
/**
|
|
459
459
|
* Get shipping rates for a checkout session
|
|
460
460
|
*/
|
|
@@ -474,11 +474,11 @@ declare class Client {
|
|
|
474
474
|
/**
|
|
475
475
|
* Retrieve a customer by ID or email
|
|
476
476
|
*/
|
|
477
|
-
retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<Customer$1>;
|
|
477
|
+
retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<Customer$1 | null>;
|
|
478
478
|
/**
|
|
479
479
|
* Update a customer
|
|
480
480
|
*/
|
|
481
|
-
updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<Customer$1>;
|
|
481
|
+
updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<Customer$1 | null>;
|
|
482
482
|
}
|
|
483
483
|
|
|
484
484
|
declare class Collections {
|
|
@@ -498,19 +498,19 @@ declare class Customer {
|
|
|
498
498
|
/**
|
|
499
499
|
* Retrieve a customer by ID or email
|
|
500
500
|
*/
|
|
501
|
-
retrieve(idOrEmail: string): Promise<Customer$1>;
|
|
501
|
+
retrieve(idOrEmail: string): Promise<Customer$1 | null>;
|
|
502
502
|
/**
|
|
503
503
|
* Update a customer
|
|
504
504
|
*/
|
|
505
|
-
update(customerId: string, params: CustomerUpdateParams): Promise<Customer$1>;
|
|
505
|
+
update(customerId: string, params: CustomerUpdateParams): Promise<Customer$1 | null>;
|
|
506
506
|
/**
|
|
507
507
|
* Delete a customer
|
|
508
508
|
*/
|
|
509
509
|
delete(customerId: string): Promise<void>;
|
|
510
510
|
/**
|
|
511
|
-
*
|
|
511
|
+
* Update a customer subscription
|
|
512
512
|
*/
|
|
513
|
-
updateCustomerSubscription(stripeSubscriptionId: string, params: CustomerSubscriptionUpdateParams): Promise<CustomerSubscription>;
|
|
513
|
+
updateCustomerSubscription(stripeSubscriptionId: string, params: CustomerSubscriptionUpdateParams): Promise<CustomerSubscription | null>;
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
declare class Discounts {
|
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
59
59
|
// src/utils/axios.ts
|
|
60
60
|
var import_axios = __toESM(require("axios"));
|
|
61
61
|
var API_BASE_URL = "https://api.betterstore.io/v1";
|
|
62
|
-
var createApiClient = (apiKey, proxy
|
|
62
|
+
var createApiClient = (apiKey, proxy) => {
|
|
63
63
|
const client = import_axios.default.create({
|
|
64
64
|
baseURL: proxy != null ? proxy : API_BASE_URL,
|
|
65
65
|
headers: {
|
|
@@ -75,6 +75,7 @@ var createApiClient = (apiKey, proxy, returnError) => {
|
|
|
75
75
|
(error) => {
|
|
76
76
|
var _a, _b;
|
|
77
77
|
const apiError = {
|
|
78
|
+
isError: true,
|
|
78
79
|
status: 500,
|
|
79
80
|
message: "An unexpected error occurred"
|
|
80
81
|
};
|
|
@@ -94,10 +95,11 @@ var createApiClient = (apiKey, proxy, returnError) => {
|
|
|
94
95
|
apiError.code = "REQUEST_SETUP_ERROR";
|
|
95
96
|
apiError.details = error;
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
console.error(apiError);
|
|
99
|
+
if (apiError.code === "REQUEST_SETUP_ERROR" || apiError.code === "SERVICE_UNAVAILABLE") {
|
|
100
|
+
throw apiError;
|
|
99
101
|
}
|
|
100
|
-
|
|
102
|
+
return apiError;
|
|
101
103
|
}
|
|
102
104
|
);
|
|
103
105
|
return client;
|
|
@@ -140,7 +142,7 @@ var OTP = class {
|
|
|
140
142
|
// src/auth/index.ts
|
|
141
143
|
var Auth = class {
|
|
142
144
|
constructor(apiKey, proxy) {
|
|
143
|
-
this.apiClient = createApiClient(apiKey, proxy
|
|
145
|
+
this.apiClient = createApiClient(apiKey, proxy);
|
|
144
146
|
this.otp = new OTP(this.apiClient);
|
|
145
147
|
}
|
|
146
148
|
retrieveSession(id) {
|
|
@@ -148,6 +150,10 @@ var Auth = class {
|
|
|
148
150
|
const data = yield this.apiClient.get(
|
|
149
151
|
`/auth/session/${id}`
|
|
150
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
|
+
}
|
|
151
157
|
return data;
|
|
152
158
|
});
|
|
153
159
|
}
|
|
@@ -168,6 +174,9 @@ var Checkout = class {
|
|
|
168
174
|
"/checkout",
|
|
169
175
|
params
|
|
170
176
|
);
|
|
177
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
178
|
+
throw new Error("Failed to create checkout session");
|
|
179
|
+
}
|
|
171
180
|
return data;
|
|
172
181
|
});
|
|
173
182
|
}
|
|
@@ -179,6 +188,10 @@ var Checkout = class {
|
|
|
179
188
|
const data = yield this.apiClient.get(
|
|
180
189
|
`/checkout/${checkoutId}`
|
|
181
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
|
+
}
|
|
182
195
|
return data;
|
|
183
196
|
});
|
|
184
197
|
}
|
|
@@ -191,6 +204,10 @@ var Checkout = class {
|
|
|
191
204
|
`/checkout/${checkoutId}`,
|
|
192
205
|
params
|
|
193
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
|
+
}
|
|
194
211
|
return data;
|
|
195
212
|
});
|
|
196
213
|
}
|
|
@@ -203,6 +220,9 @@ var Checkout = class {
|
|
|
203
220
|
`/checkout/${checkoutId}/discounts/apply`,
|
|
204
221
|
{ code: discountCode }
|
|
205
222
|
);
|
|
223
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
224
|
+
throw new Error("Failed to apply discount code");
|
|
225
|
+
}
|
|
206
226
|
return data;
|
|
207
227
|
});
|
|
208
228
|
}
|
|
@@ -214,6 +234,10 @@ var Checkout = class {
|
|
|
214
234
|
const data = yield this.apiClient.delete(
|
|
215
235
|
`/checkout/${checkoutId}/discounts/${discountId}`
|
|
216
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
|
+
}
|
|
217
241
|
return data;
|
|
218
242
|
});
|
|
219
243
|
}
|
|
@@ -225,6 +249,10 @@ var Checkout = class {
|
|
|
225
249
|
const data = yield this.apiClient.get(
|
|
226
250
|
`/checkout/${checkoutId}/discounts/revalidate`
|
|
227
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
|
+
}
|
|
228
256
|
return data;
|
|
229
257
|
});
|
|
230
258
|
}
|
|
@@ -236,6 +264,9 @@ var Checkout = class {
|
|
|
236
264
|
const data = yield this.apiClient.get(
|
|
237
265
|
`/checkout/shipping/${checkoutId}`
|
|
238
266
|
);
|
|
267
|
+
if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
239
270
|
return data;
|
|
240
271
|
});
|
|
241
272
|
}
|
|
@@ -246,6 +277,9 @@ var Checkout = class {
|
|
|
246
277
|
return __async(this, null, function* () {
|
|
247
278
|
const data = yield this.apiClient.post(`
|
|
248
279
|
/checkout/payment/${checkoutId}`);
|
|
280
|
+
if ("isError" in data && data.isError || !data || !("paymentSecret" in data)) {
|
|
281
|
+
throw new Error("Failed to generate payment secret");
|
|
282
|
+
}
|
|
249
283
|
return {
|
|
250
284
|
paymentSecret: data.paymentSecret,
|
|
251
285
|
publicKey: data.publicKey,
|
|
@@ -270,6 +304,10 @@ var Client = class {
|
|
|
270
304
|
const data = yield apiClient.get(
|
|
271
305
|
`/checkout/${checkoutId}`
|
|
272
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
|
+
}
|
|
273
311
|
return data;
|
|
274
312
|
});
|
|
275
313
|
}
|
|
@@ -283,6 +321,10 @@ var Client = class {
|
|
|
283
321
|
`/checkout/${checkoutId}`,
|
|
284
322
|
params
|
|
285
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
|
+
}
|
|
286
328
|
return data;
|
|
287
329
|
});
|
|
288
330
|
}
|
|
@@ -296,6 +338,9 @@ var Client = class {
|
|
|
296
338
|
`/checkout/${checkoutId}/discounts/apply`,
|
|
297
339
|
{ code: discountCode }
|
|
298
340
|
);
|
|
341
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
342
|
+
throw new Error("Failed to apply discount code");
|
|
343
|
+
}
|
|
299
344
|
return data;
|
|
300
345
|
});
|
|
301
346
|
}
|
|
@@ -308,6 +353,9 @@ var Client = class {
|
|
|
308
353
|
const data = yield apiClient.delete(
|
|
309
354
|
`/checkout/${checkoutId}/discounts/${discountId}`
|
|
310
355
|
);
|
|
356
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
357
|
+
throw new Error("Failed to remove discount code");
|
|
358
|
+
}
|
|
311
359
|
return data;
|
|
312
360
|
});
|
|
313
361
|
}
|
|
@@ -320,6 +368,10 @@ var Client = class {
|
|
|
320
368
|
const data = yield apiClient.get(
|
|
321
369
|
`/checkout/${checkoutId}/discounts/revalidate`
|
|
322
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
|
+
}
|
|
323
375
|
return data;
|
|
324
376
|
});
|
|
325
377
|
}
|
|
@@ -332,6 +384,9 @@ var Client = class {
|
|
|
332
384
|
const data = yield apiClient.get(
|
|
333
385
|
`/checkout/shipping/${checkoutId}`
|
|
334
386
|
);
|
|
387
|
+
if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
|
|
388
|
+
return [];
|
|
389
|
+
}
|
|
335
390
|
return data;
|
|
336
391
|
});
|
|
337
392
|
}
|
|
@@ -342,6 +397,9 @@ var Client = class {
|
|
|
342
397
|
return __async(this, null, function* () {
|
|
343
398
|
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
344
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
|
+
}
|
|
345
403
|
return {
|
|
346
404
|
paymentSecret: data.paymentSecret,
|
|
347
405
|
publicKey: data.publicKey,
|
|
@@ -355,7 +413,13 @@ var Client = class {
|
|
|
355
413
|
createCustomer(clientSecret, params) {
|
|
356
414
|
return __async(this, null, function* () {
|
|
357
415
|
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
358
|
-
const data = yield apiClient.post(
|
|
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
|
+
}
|
|
359
423
|
return data;
|
|
360
424
|
});
|
|
361
425
|
}
|
|
@@ -365,9 +429,12 @@ var Client = class {
|
|
|
365
429
|
retrieveCustomer(clientSecret, idOrEmail) {
|
|
366
430
|
return __async(this, null, function* () {
|
|
367
431
|
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
368
|
-
const data = yield apiClient.get(
|
|
369
|
-
|
|
370
|
-
|
|
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;
|
|
371
438
|
}
|
|
372
439
|
return data;
|
|
373
440
|
});
|
|
@@ -382,6 +449,10 @@ var Client = class {
|
|
|
382
449
|
`/customer/${customerId}`,
|
|
383
450
|
params
|
|
384
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
|
+
}
|
|
385
456
|
return data;
|
|
386
457
|
});
|
|
387
458
|
}
|
|
@@ -402,6 +473,9 @@ var Collections = class {
|
|
|
402
473
|
const data = yield this.apiClient.get(
|
|
403
474
|
`/collections?${queryParams.toString()}`
|
|
404
475
|
);
|
|
476
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
477
|
+
return [];
|
|
478
|
+
}
|
|
405
479
|
return data;
|
|
406
480
|
});
|
|
407
481
|
}
|
|
@@ -411,7 +485,7 @@ var Collections = class {
|
|
|
411
485
|
const data2 = yield this.apiClient.get(
|
|
412
486
|
`/collections/${params.seoHandle}`
|
|
413
487
|
);
|
|
414
|
-
if (!data2) {
|
|
488
|
+
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
415
489
|
console.error(
|
|
416
490
|
`Collection with seoHandle ${params.seoHandle} not found`
|
|
417
491
|
);
|
|
@@ -422,7 +496,7 @@ var Collections = class {
|
|
|
422
496
|
const data = yield this.apiClient.get(
|
|
423
497
|
`/collections/id/${params.id}`
|
|
424
498
|
);
|
|
425
|
-
if (!data) {
|
|
499
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
426
500
|
console.error(`Collection with id ${params.id} not found`);
|
|
427
501
|
return null;
|
|
428
502
|
}
|
|
@@ -442,7 +516,13 @@ var Customer = class {
|
|
|
442
516
|
*/
|
|
443
517
|
create(params) {
|
|
444
518
|
return __async(this, null, function* () {
|
|
445
|
-
const data = yield this.apiClient.post(
|
|
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
|
+
}
|
|
446
526
|
return data;
|
|
447
527
|
});
|
|
448
528
|
}
|
|
@@ -454,8 +534,9 @@ var Customer = class {
|
|
|
454
534
|
const data = yield this.apiClient.get(
|
|
455
535
|
`/customer/${idOrEmail}`
|
|
456
536
|
);
|
|
457
|
-
if (!data) {
|
|
458
|
-
|
|
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;
|
|
459
540
|
}
|
|
460
541
|
return data;
|
|
461
542
|
});
|
|
@@ -469,6 +550,10 @@ var Customer = class {
|
|
|
469
550
|
`/customer/${customerId}`,
|
|
470
551
|
params
|
|
471
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
|
+
}
|
|
472
557
|
return data;
|
|
473
558
|
});
|
|
474
559
|
}
|
|
@@ -481,7 +566,7 @@ var Customer = class {
|
|
|
481
566
|
});
|
|
482
567
|
}
|
|
483
568
|
/**
|
|
484
|
-
*
|
|
569
|
+
* Update a customer subscription
|
|
485
570
|
*/
|
|
486
571
|
updateCustomerSubscription(stripeSubscriptionId, params) {
|
|
487
572
|
return __async(this, null, function* () {
|
|
@@ -489,6 +574,9 @@ var Customer = class {
|
|
|
489
574
|
`/customer/subscription/${stripeSubscriptionId}`,
|
|
490
575
|
params
|
|
491
576
|
);
|
|
577
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
492
580
|
return data;
|
|
493
581
|
});
|
|
494
582
|
}
|
|
@@ -509,6 +597,9 @@ var Discounts = class {
|
|
|
509
597
|
const data = yield this.apiClient.get(
|
|
510
598
|
`/discounts?${queryParams.toString()}`
|
|
511
599
|
);
|
|
600
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
601
|
+
return [];
|
|
602
|
+
}
|
|
512
603
|
return data;
|
|
513
604
|
});
|
|
514
605
|
}
|
|
@@ -518,7 +609,7 @@ var Discounts = class {
|
|
|
518
609
|
const data2 = yield this.apiClient.get(
|
|
519
610
|
`/discounts/code/${params.code}`
|
|
520
611
|
);
|
|
521
|
-
if (!data2) {
|
|
612
|
+
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
522
613
|
console.error(`Discount with code ${params.code} not found`);
|
|
523
614
|
return null;
|
|
524
615
|
}
|
|
@@ -527,7 +618,7 @@ var Discounts = class {
|
|
|
527
618
|
const data = yield this.apiClient.get(
|
|
528
619
|
`/discounts/id/${params.id}`
|
|
529
620
|
);
|
|
530
|
-
if (!data) {
|
|
621
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
531
622
|
console.error(`Discount with id ${params.id} not found`);
|
|
532
623
|
return null;
|
|
533
624
|
}
|
|
@@ -658,27 +749,35 @@ var Products = class {
|
|
|
658
749
|
const data = yield this.apiClient.get(
|
|
659
750
|
`/products?${queryParams.toString()}`
|
|
660
751
|
);
|
|
752
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
753
|
+
return [];
|
|
754
|
+
}
|
|
661
755
|
return data;
|
|
662
756
|
});
|
|
663
757
|
}
|
|
664
758
|
retrieve(params) {
|
|
665
759
|
return __async(this, null, function* () {
|
|
666
|
-
if ("seoHandle" in params) {
|
|
667
|
-
const
|
|
760
|
+
if ("seoHandle" in params && typeof (params == null ? void 0 : params.seoHandle) === "string") {
|
|
761
|
+
const data = yield this.apiClient.get(
|
|
668
762
|
`/products/${params.seoHandle}`
|
|
669
763
|
);
|
|
670
|
-
if (!
|
|
764
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
671
765
|
console.error(`Product with seoHandle ${params.seoHandle} not found`);
|
|
672
766
|
return null;
|
|
673
767
|
}
|
|
674
|
-
return
|
|
768
|
+
return data;
|
|
675
769
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
770
|
+
if ("id" in params && typeof (params == null ? void 0 : params.id) === "string") {
|
|
771
|
+
const data = yield this.apiClient.get(
|
|
772
|
+
`/products/${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;
|
|
680
779
|
}
|
|
681
|
-
return
|
|
780
|
+
return null;
|
|
682
781
|
});
|
|
683
782
|
}
|
|
684
783
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -22,7 +22,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
22
22
|
// src/utils/axios.ts
|
|
23
23
|
import axios from "axios";
|
|
24
24
|
var API_BASE_URL = "https://api.betterstore.io/v1";
|
|
25
|
-
var createApiClient = (apiKey, proxy
|
|
25
|
+
var createApiClient = (apiKey, proxy) => {
|
|
26
26
|
const client = axios.create({
|
|
27
27
|
baseURL: proxy != null ? proxy : API_BASE_URL,
|
|
28
28
|
headers: {
|
|
@@ -38,6 +38,7 @@ var createApiClient = (apiKey, proxy, returnError) => {
|
|
|
38
38
|
(error) => {
|
|
39
39
|
var _a, _b;
|
|
40
40
|
const apiError = {
|
|
41
|
+
isError: true,
|
|
41
42
|
status: 500,
|
|
42
43
|
message: "An unexpected error occurred"
|
|
43
44
|
};
|
|
@@ -57,10 +58,11 @@ var createApiClient = (apiKey, proxy, returnError) => {
|
|
|
57
58
|
apiError.code = "REQUEST_SETUP_ERROR";
|
|
58
59
|
apiError.details = error;
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
console.error(apiError);
|
|
62
|
+
if (apiError.code === "REQUEST_SETUP_ERROR" || apiError.code === "SERVICE_UNAVAILABLE") {
|
|
63
|
+
throw apiError;
|
|
62
64
|
}
|
|
63
|
-
|
|
65
|
+
return apiError;
|
|
64
66
|
}
|
|
65
67
|
);
|
|
66
68
|
return client;
|
|
@@ -103,7 +105,7 @@ var OTP = class {
|
|
|
103
105
|
// src/auth/index.ts
|
|
104
106
|
var Auth = class {
|
|
105
107
|
constructor(apiKey, proxy) {
|
|
106
|
-
this.apiClient = createApiClient(apiKey, proxy
|
|
108
|
+
this.apiClient = createApiClient(apiKey, proxy);
|
|
107
109
|
this.otp = new OTP(this.apiClient);
|
|
108
110
|
}
|
|
109
111
|
retrieveSession(id) {
|
|
@@ -111,6 +113,10 @@ var Auth = class {
|
|
|
111
113
|
const data = yield this.apiClient.get(
|
|
112
114
|
`/auth/session/${id}`
|
|
113
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
|
+
}
|
|
114
120
|
return data;
|
|
115
121
|
});
|
|
116
122
|
}
|
|
@@ -131,6 +137,9 @@ var Checkout = class {
|
|
|
131
137
|
"/checkout",
|
|
132
138
|
params
|
|
133
139
|
);
|
|
140
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
141
|
+
throw new Error("Failed to create checkout session");
|
|
142
|
+
}
|
|
134
143
|
return data;
|
|
135
144
|
});
|
|
136
145
|
}
|
|
@@ -142,6 +151,10 @@ var Checkout = class {
|
|
|
142
151
|
const data = yield this.apiClient.get(
|
|
143
152
|
`/checkout/${checkoutId}`
|
|
144
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
|
+
}
|
|
145
158
|
return data;
|
|
146
159
|
});
|
|
147
160
|
}
|
|
@@ -154,6 +167,10 @@ var Checkout = class {
|
|
|
154
167
|
`/checkout/${checkoutId}`,
|
|
155
168
|
params
|
|
156
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
|
+
}
|
|
157
174
|
return data;
|
|
158
175
|
});
|
|
159
176
|
}
|
|
@@ -166,6 +183,9 @@ var Checkout = class {
|
|
|
166
183
|
`/checkout/${checkoutId}/discounts/apply`,
|
|
167
184
|
{ code: discountCode }
|
|
168
185
|
);
|
|
186
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
187
|
+
throw new Error("Failed to apply discount code");
|
|
188
|
+
}
|
|
169
189
|
return data;
|
|
170
190
|
});
|
|
171
191
|
}
|
|
@@ -177,6 +197,10 @@ var Checkout = class {
|
|
|
177
197
|
const data = yield this.apiClient.delete(
|
|
178
198
|
`/checkout/${checkoutId}/discounts/${discountId}`
|
|
179
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
|
+
}
|
|
180
204
|
return data;
|
|
181
205
|
});
|
|
182
206
|
}
|
|
@@ -188,6 +212,10 @@ var Checkout = class {
|
|
|
188
212
|
const data = yield this.apiClient.get(
|
|
189
213
|
`/checkout/${checkoutId}/discounts/revalidate`
|
|
190
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
|
+
}
|
|
191
219
|
return data;
|
|
192
220
|
});
|
|
193
221
|
}
|
|
@@ -199,6 +227,9 @@ var Checkout = class {
|
|
|
199
227
|
const data = yield this.apiClient.get(
|
|
200
228
|
`/checkout/shipping/${checkoutId}`
|
|
201
229
|
);
|
|
230
|
+
if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
202
233
|
return data;
|
|
203
234
|
});
|
|
204
235
|
}
|
|
@@ -209,6 +240,9 @@ var Checkout = class {
|
|
|
209
240
|
return __async(this, null, function* () {
|
|
210
241
|
const data = yield this.apiClient.post(`
|
|
211
242
|
/checkout/payment/${checkoutId}`);
|
|
243
|
+
if ("isError" in data && data.isError || !data || !("paymentSecret" in data)) {
|
|
244
|
+
throw new Error("Failed to generate payment secret");
|
|
245
|
+
}
|
|
212
246
|
return {
|
|
213
247
|
paymentSecret: data.paymentSecret,
|
|
214
248
|
publicKey: data.publicKey,
|
|
@@ -233,6 +267,10 @@ var Client = class {
|
|
|
233
267
|
const data = yield apiClient.get(
|
|
234
268
|
`/checkout/${checkoutId}`
|
|
235
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
|
+
}
|
|
236
274
|
return data;
|
|
237
275
|
});
|
|
238
276
|
}
|
|
@@ -246,6 +284,10 @@ var Client = class {
|
|
|
246
284
|
`/checkout/${checkoutId}`,
|
|
247
285
|
params
|
|
248
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
|
+
}
|
|
249
291
|
return data;
|
|
250
292
|
});
|
|
251
293
|
}
|
|
@@ -259,6 +301,9 @@ var Client = class {
|
|
|
259
301
|
`/checkout/${checkoutId}/discounts/apply`,
|
|
260
302
|
{ code: discountCode }
|
|
261
303
|
);
|
|
304
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
305
|
+
throw new Error("Failed to apply discount code");
|
|
306
|
+
}
|
|
262
307
|
return data;
|
|
263
308
|
});
|
|
264
309
|
}
|
|
@@ -271,6 +316,9 @@ var Client = class {
|
|
|
271
316
|
const data = yield apiClient.delete(
|
|
272
317
|
`/checkout/${checkoutId}/discounts/${discountId}`
|
|
273
318
|
);
|
|
319
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
320
|
+
throw new Error("Failed to remove discount code");
|
|
321
|
+
}
|
|
274
322
|
return data;
|
|
275
323
|
});
|
|
276
324
|
}
|
|
@@ -283,6 +331,10 @@ var Client = class {
|
|
|
283
331
|
const data = yield apiClient.get(
|
|
284
332
|
`/checkout/${checkoutId}/discounts/revalidate`
|
|
285
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
|
+
}
|
|
286
338
|
return data;
|
|
287
339
|
});
|
|
288
340
|
}
|
|
@@ -295,6 +347,9 @@ var Client = class {
|
|
|
295
347
|
const data = yield apiClient.get(
|
|
296
348
|
`/checkout/shipping/${checkoutId}`
|
|
297
349
|
);
|
|
350
|
+
if ("isError" in data && data.isError || !data || !Array.isArray(data)) {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
298
353
|
return data;
|
|
299
354
|
});
|
|
300
355
|
}
|
|
@@ -305,6 +360,9 @@ var Client = class {
|
|
|
305
360
|
return __async(this, null, function* () {
|
|
306
361
|
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
307
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
|
+
}
|
|
308
366
|
return {
|
|
309
367
|
paymentSecret: data.paymentSecret,
|
|
310
368
|
publicKey: data.publicKey,
|
|
@@ -318,7 +376,13 @@ var Client = class {
|
|
|
318
376
|
createCustomer(clientSecret, params) {
|
|
319
377
|
return __async(this, null, function* () {
|
|
320
378
|
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
321
|
-
const data = yield apiClient.post(
|
|
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
|
+
}
|
|
322
386
|
return data;
|
|
323
387
|
});
|
|
324
388
|
}
|
|
@@ -328,9 +392,12 @@ var Client = class {
|
|
|
328
392
|
retrieveCustomer(clientSecret, idOrEmail) {
|
|
329
393
|
return __async(this, null, function* () {
|
|
330
394
|
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
331
|
-
const data = yield apiClient.get(
|
|
332
|
-
|
|
333
|
-
|
|
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;
|
|
334
401
|
}
|
|
335
402
|
return data;
|
|
336
403
|
});
|
|
@@ -345,6 +412,10 @@ var Client = class {
|
|
|
345
412
|
`/customer/${customerId}`,
|
|
346
413
|
params
|
|
347
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
|
+
}
|
|
348
419
|
return data;
|
|
349
420
|
});
|
|
350
421
|
}
|
|
@@ -365,6 +436,9 @@ var Collections = class {
|
|
|
365
436
|
const data = yield this.apiClient.get(
|
|
366
437
|
`/collections?${queryParams.toString()}`
|
|
367
438
|
);
|
|
439
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
440
|
+
return [];
|
|
441
|
+
}
|
|
368
442
|
return data;
|
|
369
443
|
});
|
|
370
444
|
}
|
|
@@ -374,7 +448,7 @@ var Collections = class {
|
|
|
374
448
|
const data2 = yield this.apiClient.get(
|
|
375
449
|
`/collections/${params.seoHandle}`
|
|
376
450
|
);
|
|
377
|
-
if (!data2) {
|
|
451
|
+
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
378
452
|
console.error(
|
|
379
453
|
`Collection with seoHandle ${params.seoHandle} not found`
|
|
380
454
|
);
|
|
@@ -385,7 +459,7 @@ var Collections = class {
|
|
|
385
459
|
const data = yield this.apiClient.get(
|
|
386
460
|
`/collections/id/${params.id}`
|
|
387
461
|
);
|
|
388
|
-
if (!data) {
|
|
462
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
389
463
|
console.error(`Collection with id ${params.id} not found`);
|
|
390
464
|
return null;
|
|
391
465
|
}
|
|
@@ -405,7 +479,13 @@ var Customer = class {
|
|
|
405
479
|
*/
|
|
406
480
|
create(params) {
|
|
407
481
|
return __async(this, null, function* () {
|
|
408
|
-
const data = yield this.apiClient.post(
|
|
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
|
+
}
|
|
409
489
|
return data;
|
|
410
490
|
});
|
|
411
491
|
}
|
|
@@ -417,8 +497,9 @@ var Customer = class {
|
|
|
417
497
|
const data = yield this.apiClient.get(
|
|
418
498
|
`/customer/${idOrEmail}`
|
|
419
499
|
);
|
|
420
|
-
if (!data) {
|
|
421
|
-
|
|
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;
|
|
422
503
|
}
|
|
423
504
|
return data;
|
|
424
505
|
});
|
|
@@ -432,6 +513,10 @@ var Customer = class {
|
|
|
432
513
|
`/customer/${customerId}`,
|
|
433
514
|
params
|
|
434
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
|
+
}
|
|
435
520
|
return data;
|
|
436
521
|
});
|
|
437
522
|
}
|
|
@@ -444,7 +529,7 @@ var Customer = class {
|
|
|
444
529
|
});
|
|
445
530
|
}
|
|
446
531
|
/**
|
|
447
|
-
*
|
|
532
|
+
* Update a customer subscription
|
|
448
533
|
*/
|
|
449
534
|
updateCustomerSubscription(stripeSubscriptionId, params) {
|
|
450
535
|
return __async(this, null, function* () {
|
|
@@ -452,6 +537,9 @@ var Customer = class {
|
|
|
452
537
|
`/customer/subscription/${stripeSubscriptionId}`,
|
|
453
538
|
params
|
|
454
539
|
);
|
|
540
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
455
543
|
return data;
|
|
456
544
|
});
|
|
457
545
|
}
|
|
@@ -472,6 +560,9 @@ var Discounts = class {
|
|
|
472
560
|
const data = yield this.apiClient.get(
|
|
473
561
|
`/discounts?${queryParams.toString()}`
|
|
474
562
|
);
|
|
563
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
564
|
+
return [];
|
|
565
|
+
}
|
|
475
566
|
return data;
|
|
476
567
|
});
|
|
477
568
|
}
|
|
@@ -481,7 +572,7 @@ var Discounts = class {
|
|
|
481
572
|
const data2 = yield this.apiClient.get(
|
|
482
573
|
`/discounts/code/${params.code}`
|
|
483
574
|
);
|
|
484
|
-
if (!data2) {
|
|
575
|
+
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
485
576
|
console.error(`Discount with code ${params.code} not found`);
|
|
486
577
|
return null;
|
|
487
578
|
}
|
|
@@ -490,7 +581,7 @@ var Discounts = class {
|
|
|
490
581
|
const data = yield this.apiClient.get(
|
|
491
582
|
`/discounts/id/${params.id}`
|
|
492
583
|
);
|
|
493
|
-
if (!data) {
|
|
584
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
494
585
|
console.error(`Discount with id ${params.id} not found`);
|
|
495
586
|
return null;
|
|
496
587
|
}
|
|
@@ -621,27 +712,35 @@ var Products = class {
|
|
|
621
712
|
const data = yield this.apiClient.get(
|
|
622
713
|
`/products?${queryParams.toString()}`
|
|
623
714
|
);
|
|
715
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
716
|
+
return [];
|
|
717
|
+
}
|
|
624
718
|
return data;
|
|
625
719
|
});
|
|
626
720
|
}
|
|
627
721
|
retrieve(params) {
|
|
628
722
|
return __async(this, null, function* () {
|
|
629
|
-
if ("seoHandle" in params) {
|
|
630
|
-
const
|
|
723
|
+
if ("seoHandle" in params && typeof (params == null ? void 0 : params.seoHandle) === "string") {
|
|
724
|
+
const data = yield this.apiClient.get(
|
|
631
725
|
`/products/${params.seoHandle}`
|
|
632
726
|
);
|
|
633
|
-
if (!
|
|
727
|
+
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
634
728
|
console.error(`Product with seoHandle ${params.seoHandle} not found`);
|
|
635
729
|
return null;
|
|
636
730
|
}
|
|
637
|
-
return
|
|
731
|
+
return data;
|
|
638
732
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
733
|
+
if ("id" in params && typeof (params == null ? void 0 : params.id) === "string") {
|
|
734
|
+
const data = yield this.apiClient.get(
|
|
735
|
+
`/products/${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;
|
|
643
742
|
}
|
|
644
|
-
return
|
|
743
|
+
return null;
|
|
645
744
|
});
|
|
646
745
|
}
|
|
647
746
|
};
|