@betterstore/sdk 0.5.24 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +15 -472
- package/dist/index.d.ts +15 -472
- package/dist/index.js +36 -180
- package/dist/index.mjs +35 -178
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -31,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
createStoreClient: () => createStoreClient,
|
|
34
|
-
createStoreHelpers: () => createStoreHelpers,
|
|
35
34
|
default: () => createBetterStore
|
|
36
35
|
});
|
|
37
36
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -331,10 +330,10 @@ var Client = class {
|
|
|
331
330
|
async getCheckoutShippingRates(clientSecret, checkoutId) {
|
|
332
331
|
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
333
332
|
const data = await apiClient.get(
|
|
334
|
-
`/checkout
|
|
333
|
+
`/checkout/${checkoutId}/shipping/rates`
|
|
335
334
|
);
|
|
336
|
-
if ("isError" in data && data.isError || !data || !
|
|
337
|
-
return
|
|
335
|
+
if ("isError" in data && data.isError || !data || !("rates" in data)) {
|
|
336
|
+
return {};
|
|
338
337
|
}
|
|
339
338
|
return data;
|
|
340
339
|
}
|
|
@@ -437,36 +436,18 @@ var Collections = class {
|
|
|
437
436
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
438
437
|
}
|
|
439
438
|
async list(params) {
|
|
440
|
-
const
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
`/collections?${queryParams.toString()}`
|
|
446
|
-
);
|
|
447
|
-
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
448
|
-
return [];
|
|
439
|
+
const data = await this.apiClient.post(`/collections`, params);
|
|
440
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError || !("collections" in data)) {
|
|
441
|
+
return {
|
|
442
|
+
collections: []
|
|
443
|
+
};
|
|
449
444
|
}
|
|
450
445
|
return data;
|
|
451
446
|
}
|
|
452
447
|
async retrieve(params) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
);
|
|
457
|
-
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
458
|
-
console.error(
|
|
459
|
-
`Collection with seoHandle ${params.seoHandle} not found`
|
|
460
|
-
);
|
|
461
|
-
return null;
|
|
462
|
-
}
|
|
463
|
-
return data2;
|
|
464
|
-
}
|
|
465
|
-
const data = await this.apiClient.get(
|
|
466
|
-
`/collections/id/${params.id}`
|
|
467
|
-
);
|
|
468
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
469
|
-
console.error(`Collection with id ${params.id} not found`);
|
|
448
|
+
const data = await this.apiClient.post(`/collections/retrieve`, params);
|
|
449
|
+
if ("isError" in data && data.isError || !data || !("id" in data) || !("collection" in data)) {
|
|
450
|
+
console.error(`Collection not found`);
|
|
470
451
|
return null;
|
|
471
452
|
}
|
|
472
453
|
return data;
|
|
@@ -549,34 +530,24 @@ var Discounts = class {
|
|
|
549
530
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
550
531
|
}
|
|
551
532
|
async list(params) {
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
const data = await this.apiClient.get(
|
|
557
|
-
`/discounts?${queryParams.toString()}`
|
|
533
|
+
const data = await this.apiClient.post(
|
|
534
|
+
"/discounts",
|
|
535
|
+
params
|
|
558
536
|
);
|
|
559
|
-
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
560
|
-
return
|
|
537
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError || !("discounts" in data)) {
|
|
538
|
+
return {
|
|
539
|
+
discounts: []
|
|
540
|
+
};
|
|
561
541
|
}
|
|
562
542
|
return data;
|
|
563
543
|
}
|
|
564
544
|
async retrieve(params) {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
);
|
|
569
|
-
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
570
|
-
console.error(`Discount with code ${params.code} not found`);
|
|
571
|
-
return null;
|
|
572
|
-
}
|
|
573
|
-
return data2;
|
|
574
|
-
}
|
|
575
|
-
const data = await this.apiClient.get(
|
|
576
|
-
`/discounts/id/${params.id}`
|
|
545
|
+
const data = await this.apiClient.post(
|
|
546
|
+
`/discounts/retrieve`,
|
|
547
|
+
params
|
|
577
548
|
);
|
|
578
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
579
|
-
console.error(`Discount
|
|
549
|
+
if ("isError" in data && data.isError || !data || !("id" in data) || !("discount" in data)) {
|
|
550
|
+
console.error(`Discount not found`);
|
|
580
551
|
return null;
|
|
581
552
|
}
|
|
582
553
|
return data;
|
|
@@ -584,101 +555,6 @@ var Discounts = class {
|
|
|
584
555
|
};
|
|
585
556
|
var discounts_default = Discounts;
|
|
586
557
|
|
|
587
|
-
// src/helpers/index.ts
|
|
588
|
-
var currencyLocales = {
|
|
589
|
-
CZK: "cs-CZ",
|
|
590
|
-
// Czech Koruna
|
|
591
|
-
USD: "en-US",
|
|
592
|
-
// US Dollar
|
|
593
|
-
EUR: "de-DE",
|
|
594
|
-
// Euro (Germany locale)
|
|
595
|
-
GBP: "en-GB",
|
|
596
|
-
// British Pound
|
|
597
|
-
JPY: "ja-JP",
|
|
598
|
-
// Japanese Yen
|
|
599
|
-
AUD: "en-AU",
|
|
600
|
-
// Australian Dollar
|
|
601
|
-
CAD: "en-CA",
|
|
602
|
-
// Canadian Dollar
|
|
603
|
-
NZD: "en-NZ",
|
|
604
|
-
// New Zealand Dollar
|
|
605
|
-
SEK: "sv-SE",
|
|
606
|
-
// Swedish Krona
|
|
607
|
-
NOK: "nb-NO",
|
|
608
|
-
// Norwegian Krone
|
|
609
|
-
DKK: "da-DK",
|
|
610
|
-
// Danish Krone
|
|
611
|
-
CHF: "de-CH",
|
|
612
|
-
// Swiss Franc (German Switzerland)
|
|
613
|
-
HUF: "hu-HU",
|
|
614
|
-
// Hungarian Forint
|
|
615
|
-
PLN: "pl-PL",
|
|
616
|
-
// Polish Zloty
|
|
617
|
-
BGN: "bg-BG",
|
|
618
|
-
// Bulgarian Lev
|
|
619
|
-
RON: "ro-RO",
|
|
620
|
-
// Romanian Leu
|
|
621
|
-
RUB: "ru-RU",
|
|
622
|
-
// Russian Ruble
|
|
623
|
-
CNY: "zh-CN",
|
|
624
|
-
// Chinese Yuan
|
|
625
|
-
INR: "en-IN",
|
|
626
|
-
// Indian Rupee
|
|
627
|
-
BRL: "pt-BR",
|
|
628
|
-
// Brazilian Real
|
|
629
|
-
MXN: "es-MX",
|
|
630
|
-
// Mexican Peso
|
|
631
|
-
ZAR: "en-ZA",
|
|
632
|
-
// South African Rand
|
|
633
|
-
KRW: "ko-KR",
|
|
634
|
-
// South Korean Won
|
|
635
|
-
MYR: "ms-MY",
|
|
636
|
-
// Malaysian Ringgit
|
|
637
|
-
SGD: "en-SG",
|
|
638
|
-
// Singapore Dollar
|
|
639
|
-
TWD: "zh-TW",
|
|
640
|
-
// Taiwanese Dollar
|
|
641
|
-
THB: "th-TH",
|
|
642
|
-
// Thai Baht
|
|
643
|
-
IDR: "id-ID",
|
|
644
|
-
// Indonesian Rupiah
|
|
645
|
-
AED: "ar-AE",
|
|
646
|
-
// UAE Dirham
|
|
647
|
-
SAR: "ar-SA",
|
|
648
|
-
// Saudi Riyal
|
|
649
|
-
TRY: "tr-TR"
|
|
650
|
-
// Turkish Lira
|
|
651
|
-
};
|
|
652
|
-
var Helpers = class {
|
|
653
|
-
proxy;
|
|
654
|
-
constructor(proxy) {
|
|
655
|
-
this.proxy = proxy;
|
|
656
|
-
}
|
|
657
|
-
formatCurrency(currency) {
|
|
658
|
-
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
659
|
-
const formattedCurrency = new Intl.NumberFormat(locale, {
|
|
660
|
-
style: "currency",
|
|
661
|
-
currency,
|
|
662
|
-
currencyDisplay: "symbol"
|
|
663
|
-
});
|
|
664
|
-
return formattedCurrency.format(0).replace(/[\d.,\s]/g, "").trim();
|
|
665
|
-
}
|
|
666
|
-
formatPrice(priceInCents, currency, exchangeRate) {
|
|
667
|
-
const amount = priceInCents / 100 * (exchangeRate ?? 1);
|
|
668
|
-
const isWhole = amount % 1 === 0;
|
|
669
|
-
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
670
|
-
const formattedPrice = new Intl.NumberFormat(locale, {
|
|
671
|
-
style: "currency",
|
|
672
|
-
currency,
|
|
673
|
-
currencyDisplay: "symbol",
|
|
674
|
-
minimumFractionDigits: isWhole ? 0 : 2,
|
|
675
|
-
maximumFractionDigits: isWhole ? 0 : 2
|
|
676
|
-
}).format(amount);
|
|
677
|
-
return formattedPrice;
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
var helpers_default = Helpers;
|
|
681
|
-
|
|
682
558
|
// src/products/index.ts
|
|
683
559
|
var Products = class {
|
|
684
560
|
apiClient;
|
|
@@ -686,40 +562,24 @@ var Products = class {
|
|
|
686
562
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
687
563
|
}
|
|
688
564
|
async list(params) {
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
const data = await this.apiClient.get(
|
|
694
|
-
`/products?${queryParams.toString()}`
|
|
565
|
+
const data = await this.apiClient.post(
|
|
566
|
+
"/products",
|
|
567
|
+
params
|
|
695
568
|
);
|
|
696
|
-
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
697
|
-
return
|
|
569
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError || !("products" in data)) {
|
|
570
|
+
return {
|
|
571
|
+
products: []
|
|
572
|
+
};
|
|
698
573
|
}
|
|
699
574
|
return data;
|
|
700
575
|
}
|
|
701
576
|
async retrieve(params) {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
707
|
-
console.error(`Product with seoHandle ${params.seoHandle} not found`);
|
|
708
|
-
return null;
|
|
709
|
-
}
|
|
710
|
-
return data;
|
|
711
|
-
}
|
|
712
|
-
if ("id" in params && typeof params?.id === "string") {
|
|
713
|
-
const data = await this.apiClient.get(
|
|
714
|
-
`/products/id/${params.id}`
|
|
715
|
-
);
|
|
716
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
717
|
-
console.error(`Product with id ${params.id} not found`);
|
|
718
|
-
return null;
|
|
719
|
-
}
|
|
720
|
-
return data;
|
|
577
|
+
const data = await this.apiClient.post("/products/retrieve", params);
|
|
578
|
+
if ("isError" in data && data.isError || !data || !("id" in data) || !("product" in data)) {
|
|
579
|
+
console.error(`Product not found`);
|
|
580
|
+
return null;
|
|
721
581
|
}
|
|
722
|
-
return
|
|
582
|
+
return data;
|
|
723
583
|
}
|
|
724
584
|
};
|
|
725
585
|
var products_default = Products;
|
|
@@ -741,11 +601,7 @@ function createBetterStore(config) {
|
|
|
741
601
|
function createStoreClient(config) {
|
|
742
602
|
return new client_default(config?.proxy);
|
|
743
603
|
}
|
|
744
|
-
function createStoreHelpers(config) {
|
|
745
|
-
return new helpers_default(config?.proxy);
|
|
746
|
-
}
|
|
747
604
|
// Annotate the CommonJS export names for ESM import in node:
|
|
748
605
|
0 && (module.exports = {
|
|
749
|
-
createStoreClient
|
|
750
|
-
createStoreHelpers
|
|
606
|
+
createStoreClient
|
|
751
607
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -293,10 +293,10 @@ var Client = class {
|
|
|
293
293
|
async getCheckoutShippingRates(clientSecret, checkoutId) {
|
|
294
294
|
const apiClient = createApiClient(clientSecret, this.proxy);
|
|
295
295
|
const data = await apiClient.get(
|
|
296
|
-
`/checkout
|
|
296
|
+
`/checkout/${checkoutId}/shipping/rates`
|
|
297
297
|
);
|
|
298
|
-
if ("isError" in data && data.isError || !data || !
|
|
299
|
-
return
|
|
298
|
+
if ("isError" in data && data.isError || !data || !("rates" in data)) {
|
|
299
|
+
return {};
|
|
300
300
|
}
|
|
301
301
|
return data;
|
|
302
302
|
}
|
|
@@ -399,36 +399,18 @@ var Collections = class {
|
|
|
399
399
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
400
400
|
}
|
|
401
401
|
async list(params) {
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
`/collections?${queryParams.toString()}`
|
|
408
|
-
);
|
|
409
|
-
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
410
|
-
return [];
|
|
402
|
+
const data = await this.apiClient.post(`/collections`, params);
|
|
403
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError || !("collections" in data)) {
|
|
404
|
+
return {
|
|
405
|
+
collections: []
|
|
406
|
+
};
|
|
411
407
|
}
|
|
412
408
|
return data;
|
|
413
409
|
}
|
|
414
410
|
async retrieve(params) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
);
|
|
419
|
-
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
420
|
-
console.error(
|
|
421
|
-
`Collection with seoHandle ${params.seoHandle} not found`
|
|
422
|
-
);
|
|
423
|
-
return null;
|
|
424
|
-
}
|
|
425
|
-
return data2;
|
|
426
|
-
}
|
|
427
|
-
const data = await this.apiClient.get(
|
|
428
|
-
`/collections/id/${params.id}`
|
|
429
|
-
);
|
|
430
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
431
|
-
console.error(`Collection with id ${params.id} not found`);
|
|
411
|
+
const data = await this.apiClient.post(`/collections/retrieve`, params);
|
|
412
|
+
if ("isError" in data && data.isError || !data || !("id" in data) || !("collection" in data)) {
|
|
413
|
+
console.error(`Collection not found`);
|
|
432
414
|
return null;
|
|
433
415
|
}
|
|
434
416
|
return data;
|
|
@@ -511,34 +493,24 @@ var Discounts = class {
|
|
|
511
493
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
512
494
|
}
|
|
513
495
|
async list(params) {
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
const data = await this.apiClient.get(
|
|
519
|
-
`/discounts?${queryParams.toString()}`
|
|
496
|
+
const data = await this.apiClient.post(
|
|
497
|
+
"/discounts",
|
|
498
|
+
params
|
|
520
499
|
);
|
|
521
|
-
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
522
|
-
return
|
|
500
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError || !("discounts" in data)) {
|
|
501
|
+
return {
|
|
502
|
+
discounts: []
|
|
503
|
+
};
|
|
523
504
|
}
|
|
524
505
|
return data;
|
|
525
506
|
}
|
|
526
507
|
async retrieve(params) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
);
|
|
531
|
-
if ("isError" in data2 && data2.isError || !data2 || !("id" in data2)) {
|
|
532
|
-
console.error(`Discount with code ${params.code} not found`);
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
return data2;
|
|
536
|
-
}
|
|
537
|
-
const data = await this.apiClient.get(
|
|
538
|
-
`/discounts/id/${params.id}`
|
|
508
|
+
const data = await this.apiClient.post(
|
|
509
|
+
`/discounts/retrieve`,
|
|
510
|
+
params
|
|
539
511
|
);
|
|
540
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
541
|
-
console.error(`Discount
|
|
512
|
+
if ("isError" in data && data.isError || !data || !("id" in data) || !("discount" in data)) {
|
|
513
|
+
console.error(`Discount not found`);
|
|
542
514
|
return null;
|
|
543
515
|
}
|
|
544
516
|
return data;
|
|
@@ -546,101 +518,6 @@ var Discounts = class {
|
|
|
546
518
|
};
|
|
547
519
|
var discounts_default = Discounts;
|
|
548
520
|
|
|
549
|
-
// src/helpers/index.ts
|
|
550
|
-
var currencyLocales = {
|
|
551
|
-
CZK: "cs-CZ",
|
|
552
|
-
// Czech Koruna
|
|
553
|
-
USD: "en-US",
|
|
554
|
-
// US Dollar
|
|
555
|
-
EUR: "de-DE",
|
|
556
|
-
// Euro (Germany locale)
|
|
557
|
-
GBP: "en-GB",
|
|
558
|
-
// British Pound
|
|
559
|
-
JPY: "ja-JP",
|
|
560
|
-
// Japanese Yen
|
|
561
|
-
AUD: "en-AU",
|
|
562
|
-
// Australian Dollar
|
|
563
|
-
CAD: "en-CA",
|
|
564
|
-
// Canadian Dollar
|
|
565
|
-
NZD: "en-NZ",
|
|
566
|
-
// New Zealand Dollar
|
|
567
|
-
SEK: "sv-SE",
|
|
568
|
-
// Swedish Krona
|
|
569
|
-
NOK: "nb-NO",
|
|
570
|
-
// Norwegian Krone
|
|
571
|
-
DKK: "da-DK",
|
|
572
|
-
// Danish Krone
|
|
573
|
-
CHF: "de-CH",
|
|
574
|
-
// Swiss Franc (German Switzerland)
|
|
575
|
-
HUF: "hu-HU",
|
|
576
|
-
// Hungarian Forint
|
|
577
|
-
PLN: "pl-PL",
|
|
578
|
-
// Polish Zloty
|
|
579
|
-
BGN: "bg-BG",
|
|
580
|
-
// Bulgarian Lev
|
|
581
|
-
RON: "ro-RO",
|
|
582
|
-
// Romanian Leu
|
|
583
|
-
RUB: "ru-RU",
|
|
584
|
-
// Russian Ruble
|
|
585
|
-
CNY: "zh-CN",
|
|
586
|
-
// Chinese Yuan
|
|
587
|
-
INR: "en-IN",
|
|
588
|
-
// Indian Rupee
|
|
589
|
-
BRL: "pt-BR",
|
|
590
|
-
// Brazilian Real
|
|
591
|
-
MXN: "es-MX",
|
|
592
|
-
// Mexican Peso
|
|
593
|
-
ZAR: "en-ZA",
|
|
594
|
-
// South African Rand
|
|
595
|
-
KRW: "ko-KR",
|
|
596
|
-
// South Korean Won
|
|
597
|
-
MYR: "ms-MY",
|
|
598
|
-
// Malaysian Ringgit
|
|
599
|
-
SGD: "en-SG",
|
|
600
|
-
// Singapore Dollar
|
|
601
|
-
TWD: "zh-TW",
|
|
602
|
-
// Taiwanese Dollar
|
|
603
|
-
THB: "th-TH",
|
|
604
|
-
// Thai Baht
|
|
605
|
-
IDR: "id-ID",
|
|
606
|
-
// Indonesian Rupiah
|
|
607
|
-
AED: "ar-AE",
|
|
608
|
-
// UAE Dirham
|
|
609
|
-
SAR: "ar-SA",
|
|
610
|
-
// Saudi Riyal
|
|
611
|
-
TRY: "tr-TR"
|
|
612
|
-
// Turkish Lira
|
|
613
|
-
};
|
|
614
|
-
var Helpers = class {
|
|
615
|
-
proxy;
|
|
616
|
-
constructor(proxy) {
|
|
617
|
-
this.proxy = proxy;
|
|
618
|
-
}
|
|
619
|
-
formatCurrency(currency) {
|
|
620
|
-
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
621
|
-
const formattedCurrency = new Intl.NumberFormat(locale, {
|
|
622
|
-
style: "currency",
|
|
623
|
-
currency,
|
|
624
|
-
currencyDisplay: "symbol"
|
|
625
|
-
});
|
|
626
|
-
return formattedCurrency.format(0).replace(/[\d.,\s]/g, "").trim();
|
|
627
|
-
}
|
|
628
|
-
formatPrice(priceInCents, currency, exchangeRate) {
|
|
629
|
-
const amount = priceInCents / 100 * (exchangeRate ?? 1);
|
|
630
|
-
const isWhole = amount % 1 === 0;
|
|
631
|
-
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
632
|
-
const formattedPrice = new Intl.NumberFormat(locale, {
|
|
633
|
-
style: "currency",
|
|
634
|
-
currency,
|
|
635
|
-
currencyDisplay: "symbol",
|
|
636
|
-
minimumFractionDigits: isWhole ? 0 : 2,
|
|
637
|
-
maximumFractionDigits: isWhole ? 0 : 2
|
|
638
|
-
}).format(amount);
|
|
639
|
-
return formattedPrice;
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
var helpers_default = Helpers;
|
|
643
|
-
|
|
644
521
|
// src/products/index.ts
|
|
645
522
|
var Products = class {
|
|
646
523
|
apiClient;
|
|
@@ -648,40 +525,24 @@ var Products = class {
|
|
|
648
525
|
this.apiClient = createApiClient(apiKey, proxy);
|
|
649
526
|
}
|
|
650
527
|
async list(params) {
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
const data = await this.apiClient.get(
|
|
656
|
-
`/products?${queryParams.toString()}`
|
|
528
|
+
const data = await this.apiClient.post(
|
|
529
|
+
"/products",
|
|
530
|
+
params
|
|
657
531
|
);
|
|
658
|
-
if (!data || !Array.isArray(data) || "isError" in data && data.isError) {
|
|
659
|
-
return
|
|
532
|
+
if (!data || !Array.isArray(data) || "isError" in data && data.isError || !("products" in data)) {
|
|
533
|
+
return {
|
|
534
|
+
products: []
|
|
535
|
+
};
|
|
660
536
|
}
|
|
661
537
|
return data;
|
|
662
538
|
}
|
|
663
539
|
async retrieve(params) {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
669
|
-
console.error(`Product with seoHandle ${params.seoHandle} not found`);
|
|
670
|
-
return null;
|
|
671
|
-
}
|
|
672
|
-
return data;
|
|
673
|
-
}
|
|
674
|
-
if ("id" in params && typeof params?.id === "string") {
|
|
675
|
-
const data = await this.apiClient.get(
|
|
676
|
-
`/products/id/${params.id}`
|
|
677
|
-
);
|
|
678
|
-
if ("isError" in data && data.isError || !data || !("id" in data)) {
|
|
679
|
-
console.error(`Product with id ${params.id} not found`);
|
|
680
|
-
return null;
|
|
681
|
-
}
|
|
682
|
-
return data;
|
|
540
|
+
const data = await this.apiClient.post("/products/retrieve", params);
|
|
541
|
+
if ("isError" in data && data.isError || !data || !("id" in data) || !("product" in data)) {
|
|
542
|
+
console.error(`Product not found`);
|
|
543
|
+
return null;
|
|
683
544
|
}
|
|
684
|
-
return
|
|
545
|
+
return data;
|
|
685
546
|
}
|
|
686
547
|
};
|
|
687
548
|
var products_default = Products;
|
|
@@ -703,11 +564,7 @@ function createBetterStore(config) {
|
|
|
703
564
|
function createStoreClient(config) {
|
|
704
565
|
return new client_default(config?.proxy);
|
|
705
566
|
}
|
|
706
|
-
function createStoreHelpers(config) {
|
|
707
|
-
return new helpers_default(config?.proxy);
|
|
708
|
-
}
|
|
709
567
|
export {
|
|
710
568
|
createStoreClient,
|
|
711
|
-
createStoreHelpers,
|
|
712
569
|
createBetterStore as default
|
|
713
570
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterstore/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/axios": "^0.14.4",
|
|
14
|
-
"tsup": "^8.4.0",
|
|
15
14
|
"eslint": "^9.29.0",
|
|
15
|
+
"tsup": "^8.4.0",
|
|
16
16
|
"typescript": "5.8.2",
|
|
17
17
|
"@betterstore/eslint-config": "0.0.0",
|
|
18
18
|
"@betterstore/typescript-config": "0.0.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@betterstore/bridge": "^0.0.23",
|
|
21
22
|
"axios": "^1.8.2",
|
|
22
23
|
"zod": "^3.24.2"
|
|
23
24
|
},
|