commerce-kit 0.0.40 → 0.1.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/README.md +112 -44
- package/dist/currencies.d.ts +1 -1
- package/dist/index.d.ts +423 -39
- package/dist/index.js +240 -3
- package/dist/internal.d.ts +11 -75
- package/dist/internal.js +1 -1
- package/package.json +92 -89
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { CartMetadata, MappedCart } from './internal.js';
|
|
2
|
-
export { MappedProduct, MappedShippingRate } from './internal.js';
|
|
3
1
|
import Stripe from 'stripe';
|
|
4
2
|
import { z, TypeOf } from 'zod';
|
|
3
|
+
import { CartMetadata, MappedCart } from './internal.js';
|
|
4
|
+
export { MappedProduct, MappedShippingRate } from './internal.js';
|
|
5
|
+
export { formatMoney } from './currencies.js';
|
|
5
6
|
|
|
6
|
-
type Cart = NonNullable<Awaited<ReturnType<typeof cartGet>>>;
|
|
7
|
-
type Order = NonNullable<Awaited<ReturnType<typeof orderGet>>>;
|
|
7
|
+
type Cart$1 = NonNullable<Awaited<ReturnType<typeof cartGet>>>;
|
|
8
|
+
type Order$1 = NonNullable<Awaited<ReturnType<typeof orderGet>>>;
|
|
8
9
|
declare function cartAdd({ productId, cartId }: {
|
|
9
10
|
productId: string;
|
|
10
11
|
cartId?: string;
|
|
@@ -42,9 +43,9 @@ declare function cartGet(cartId: string): Promise<{
|
|
|
42
43
|
customer: Stripe.Customer | null;
|
|
43
44
|
payment_method: Stripe.PaymentMethod | null;
|
|
44
45
|
taxBreakdown: {
|
|
46
|
+
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
45
47
|
taxPercentage: string;
|
|
46
48
|
taxAmount: number;
|
|
47
|
-
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
48
49
|
}[];
|
|
49
50
|
id: string;
|
|
50
51
|
object: "payment_intent";
|
|
@@ -63,7 +64,7 @@ declare function cartGet(cartId: string): Promise<{
|
|
|
63
64
|
created: number;
|
|
64
65
|
currency: string;
|
|
65
66
|
description: string | null;
|
|
66
|
-
|
|
67
|
+
excluded_payment_method_types: Array<Stripe.PaymentIntent.ExcludedPaymentMethodType> | null;
|
|
67
68
|
last_payment_error: Stripe.PaymentIntent.LastPaymentError | null;
|
|
68
69
|
latest_charge: string | Stripe.Charge | null;
|
|
69
70
|
livemode: boolean;
|
|
@@ -72,6 +73,7 @@ declare function cartGet(cartId: string): Promise<{
|
|
|
72
73
|
payment_method_configuration_details: Stripe.PaymentIntent.PaymentMethodConfigurationDetails | null;
|
|
73
74
|
payment_method_options: Stripe.PaymentIntent.PaymentMethodOptions | null;
|
|
74
75
|
payment_method_types: Array<string>;
|
|
76
|
+
presentment_details?: Stripe.PaymentIntent.PresentmentDetails;
|
|
75
77
|
processing: Stripe.PaymentIntent.Processing | null;
|
|
76
78
|
receipt_email: string | null;
|
|
77
79
|
review: string | Stripe.Review | null;
|
|
@@ -123,8 +125,8 @@ declare function cartCreate({ productId }?: {
|
|
|
123
125
|
productId?: string;
|
|
124
126
|
cartId?: string;
|
|
125
127
|
}): Promise<Stripe.Response<Stripe.PaymentIntent>>;
|
|
126
|
-
declare function cartAddOptimistic({ cart, add
|
|
127
|
-
cart?: Cart | null;
|
|
128
|
+
declare function cartAddOptimistic({ cart, add }: {
|
|
129
|
+
cart?: Cart$1 | null;
|
|
128
130
|
add: string | undefined;
|
|
129
131
|
}): Promise<{
|
|
130
132
|
cart: {
|
|
@@ -154,9 +156,9 @@ declare function cartAddOptimistic({ cart, add, }: {
|
|
|
154
156
|
customer?: Stripe.Customer | null | undefined;
|
|
155
157
|
payment_method?: Stripe.PaymentMethod | null | undefined;
|
|
156
158
|
taxBreakdown?: {
|
|
159
|
+
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
157
160
|
taxPercentage: string;
|
|
158
161
|
taxAmount: number;
|
|
159
|
-
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
160
162
|
}[] | undefined;
|
|
161
163
|
id?: string | undefined;
|
|
162
164
|
object?: "payment_intent" | undefined;
|
|
@@ -174,7 +176,7 @@ declare function cartAddOptimistic({ cart, add, }: {
|
|
|
174
176
|
created?: number | undefined;
|
|
175
177
|
currency?: string | undefined;
|
|
176
178
|
description?: string | null | undefined;
|
|
177
|
-
|
|
179
|
+
excluded_payment_method_types?: Stripe.PaymentIntent.ExcludedPaymentMethodType[] | null | undefined;
|
|
178
180
|
last_payment_error?: Stripe.PaymentIntent.LastPaymentError | null | undefined;
|
|
179
181
|
latest_charge?: string | Stripe.Charge | null | undefined;
|
|
180
182
|
livemode?: boolean | undefined;
|
|
@@ -183,6 +185,7 @@ declare function cartAddOptimistic({ cart, add, }: {
|
|
|
183
185
|
payment_method_configuration_details?: Stripe.PaymentIntent.PaymentMethodConfigurationDetails | null | undefined;
|
|
184
186
|
payment_method_options?: Stripe.PaymentIntent.PaymentMethodOptions | null | undefined;
|
|
185
187
|
payment_method_types?: string[] | undefined;
|
|
188
|
+
presentment_details?: Stripe.PaymentIntent.PresentmentDetails;
|
|
186
189
|
processing?: Stripe.PaymentIntent.Processing | null | undefined;
|
|
187
190
|
receipt_email?: string | null | undefined;
|
|
188
191
|
review?: string | Stripe.Review | null | undefined;
|
|
@@ -372,9 +375,9 @@ declare function orderGet(orderId: string): Promise<{
|
|
|
372
375
|
payment_method: Stripe.PaymentMethod | null;
|
|
373
376
|
latest_charge: Stripe.Charge | null;
|
|
374
377
|
taxBreakdown: {
|
|
378
|
+
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
375
379
|
taxPercentage: string;
|
|
376
380
|
taxAmount: number;
|
|
377
|
-
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
378
381
|
}[];
|
|
379
382
|
metadata: {
|
|
380
383
|
shippingRateId?: string | undefined;
|
|
@@ -416,7 +419,7 @@ declare function orderGet(orderId: string): Promise<{
|
|
|
416
419
|
currency: string;
|
|
417
420
|
customer: string | Stripe.Customer | Stripe.DeletedCustomer | null;
|
|
418
421
|
description: string | null;
|
|
419
|
-
|
|
422
|
+
excluded_payment_method_types: Array<Stripe.PaymentIntent.ExcludedPaymentMethodType> | null;
|
|
420
423
|
last_payment_error: Stripe.PaymentIntent.LastPaymentError | null;
|
|
421
424
|
livemode: boolean;
|
|
422
425
|
next_action: Stripe.PaymentIntent.NextAction | null;
|
|
@@ -424,6 +427,7 @@ declare function orderGet(orderId: string): Promise<{
|
|
|
424
427
|
payment_method_configuration_details: Stripe.PaymentIntent.PaymentMethodConfigurationDetails | null;
|
|
425
428
|
payment_method_options: Stripe.PaymentIntent.PaymentMethodOptions | null;
|
|
426
429
|
payment_method_types: Array<string>;
|
|
430
|
+
presentment_details?: Stripe.PaymentIntent.PresentmentDetails;
|
|
427
431
|
processing: Stripe.PaymentIntent.Processing | null;
|
|
428
432
|
receipt_email: string | null;
|
|
429
433
|
review: string | Stripe.Review | null;
|
|
@@ -533,9 +537,9 @@ declare const getCartWithProductsById: (cartId: string) => Promise<{
|
|
|
533
537
|
customer: Stripe.Customer | null;
|
|
534
538
|
payment_method: Stripe.PaymentMethod | null;
|
|
535
539
|
taxBreakdown: {
|
|
540
|
+
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
536
541
|
taxPercentage: string;
|
|
537
542
|
taxAmount: number;
|
|
538
|
-
taxType: Stripe.Tax.Calculation.TaxBreakdown.TaxRateDetails.TaxType | (string & {});
|
|
539
543
|
}[];
|
|
540
544
|
id: string;
|
|
541
545
|
object: "payment_intent";
|
|
@@ -554,7 +558,7 @@ declare const getCartWithProductsById: (cartId: string) => Promise<{
|
|
|
554
558
|
created: number;
|
|
555
559
|
currency: string;
|
|
556
560
|
description: string | null;
|
|
557
|
-
|
|
561
|
+
excluded_payment_method_types: Array<Stripe.PaymentIntent.ExcludedPaymentMethodType> | null;
|
|
558
562
|
last_payment_error: Stripe.PaymentIntent.LastPaymentError | null;
|
|
559
563
|
latest_charge: string | Stripe.Charge | null;
|
|
560
564
|
livemode: boolean;
|
|
@@ -563,6 +567,7 @@ declare const getCartWithProductsById: (cartId: string) => Promise<{
|
|
|
563
567
|
payment_method_configuration_details: Stripe.PaymentIntent.PaymentMethodConfigurationDetails | null;
|
|
564
568
|
payment_method_options: Stripe.PaymentIntent.PaymentMethodOptions | null;
|
|
565
569
|
payment_method_types: Array<string>;
|
|
570
|
+
presentment_details?: Stripe.PaymentIntent.PresentmentDetails;
|
|
566
571
|
processing: Stripe.PaymentIntent.Processing | null;
|
|
567
572
|
receipt_email: string | null;
|
|
568
573
|
review: string | Stripe.Review | null;
|
|
@@ -648,29 +653,7 @@ declare const getAddressSchema: (tr: {
|
|
|
648
653
|
phone: z.ZodDefault<z.ZodNullable<z.ZodOptional<z.ZodString>>>;
|
|
649
654
|
taxId: z.ZodDefault<z.ZodNullable<z.ZodOptional<z.ZodString>>>;
|
|
650
655
|
email: z.ZodDefault<z.ZodNullable<z.ZodOptional<z.ZodString>>>;
|
|
651
|
-
},
|
|
652
|
-
name: string;
|
|
653
|
-
taxId: string | null;
|
|
654
|
-
city: string;
|
|
655
|
-
country: string;
|
|
656
|
-
line1: string;
|
|
657
|
-
line2: string | null;
|
|
658
|
-
postalCode: string;
|
|
659
|
-
state: string | null;
|
|
660
|
-
phone: string | null;
|
|
661
|
-
email: string | null;
|
|
662
|
-
}, {
|
|
663
|
-
name: string;
|
|
664
|
-
city: string;
|
|
665
|
-
country: string;
|
|
666
|
-
line1: string;
|
|
667
|
-
postalCode: string;
|
|
668
|
-
taxId?: string | null | undefined;
|
|
669
|
-
line2?: string | null | undefined;
|
|
670
|
-
state?: string | null | undefined;
|
|
671
|
-
phone?: string | null | undefined;
|
|
672
|
-
email?: string | null | undefined;
|
|
673
|
-
}>;
|
|
656
|
+
}, z.core.$strip>;
|
|
674
657
|
type AddressSchema = TypeOf<ReturnType<typeof getAddressSchema>>;
|
|
675
658
|
/**
|
|
676
659
|
* @internal
|
|
@@ -763,7 +746,7 @@ declare function productReviewBrowse(params: {
|
|
|
763
746
|
first?: number;
|
|
764
747
|
last?: number;
|
|
765
748
|
offset?: number;
|
|
766
|
-
filter?:
|
|
749
|
+
filter?: Record<string, never>;
|
|
767
750
|
}): Promise<Review[] | null>;
|
|
768
751
|
declare function productReviewAdd(params: {
|
|
769
752
|
productId: string;
|
|
@@ -779,6 +762,369 @@ declare const contextGet: () => Promise<{
|
|
|
779
762
|
publishableKey: string | undefined;
|
|
780
763
|
}>;
|
|
781
764
|
|
|
765
|
+
interface BaseProvider {
|
|
766
|
+
productBrowse(params: ProductBrowseParams): Promise<ProductBrowseResult>;
|
|
767
|
+
productGet(params: ProductGetParams): Promise<Product | null>;
|
|
768
|
+
productSearch?(params: ProductSearchParams): Promise<ProductSearchResult>;
|
|
769
|
+
cartAdd(params: CartAddParams): Promise<{
|
|
770
|
+
cartId: string;
|
|
771
|
+
}>;
|
|
772
|
+
cartUpdate(params: CartUpdateParams): Promise<{
|
|
773
|
+
cartId: string;
|
|
774
|
+
}>;
|
|
775
|
+
cartClear(params: CartClearParams): Promise<{
|
|
776
|
+
cartId: string;
|
|
777
|
+
}>;
|
|
778
|
+
cartGet(params: CartGetParams): Promise<Cart | null>;
|
|
779
|
+
orderGet?(params: OrderGetParams): Promise<Order | null>;
|
|
780
|
+
orderList?(params: OrderListParams): Promise<OrderListResult>;
|
|
781
|
+
}
|
|
782
|
+
interface StripeProviderConfig {
|
|
783
|
+
secretKey?: string;
|
|
784
|
+
tagPrefix?: string;
|
|
785
|
+
}
|
|
786
|
+
interface YnsProviderConfig {
|
|
787
|
+
endpoint: string;
|
|
788
|
+
token: string;
|
|
789
|
+
}
|
|
790
|
+
interface CommerceConfig {
|
|
791
|
+
provider: "stripe" | "yns";
|
|
792
|
+
stripe?: StripeProviderConfig;
|
|
793
|
+
yns?: YnsProviderConfig;
|
|
794
|
+
}
|
|
795
|
+
interface Product {
|
|
796
|
+
id: string;
|
|
797
|
+
name: string;
|
|
798
|
+
slug?: string;
|
|
799
|
+
summary?: string;
|
|
800
|
+
images: string[];
|
|
801
|
+
active: boolean;
|
|
802
|
+
price: number;
|
|
803
|
+
currency: string;
|
|
804
|
+
stock?: number;
|
|
805
|
+
}
|
|
806
|
+
interface Cart {
|
|
807
|
+
id: string;
|
|
808
|
+
customerId?: string;
|
|
809
|
+
items: CartItem[];
|
|
810
|
+
total: number;
|
|
811
|
+
currency: string;
|
|
812
|
+
createdAt: string;
|
|
813
|
+
updatedAt: string;
|
|
814
|
+
}
|
|
815
|
+
interface CartItem {
|
|
816
|
+
id: string;
|
|
817
|
+
productId: string;
|
|
818
|
+
variantId?: string;
|
|
819
|
+
quantity: number;
|
|
820
|
+
price: number;
|
|
821
|
+
}
|
|
822
|
+
interface Order {
|
|
823
|
+
id: string;
|
|
824
|
+
customerId?: string;
|
|
825
|
+
items: CartItem[];
|
|
826
|
+
total: number;
|
|
827
|
+
currency: string;
|
|
828
|
+
status: string;
|
|
829
|
+
createdAt: string;
|
|
830
|
+
updatedAt: string;
|
|
831
|
+
}
|
|
832
|
+
interface ProductBrowseParams {
|
|
833
|
+
first?: number;
|
|
834
|
+
offset?: number;
|
|
835
|
+
category?: string;
|
|
836
|
+
query?: string;
|
|
837
|
+
active?: boolean;
|
|
838
|
+
orderBy?: string;
|
|
839
|
+
orderDirection?: "asc" | "desc";
|
|
840
|
+
fields?: string[];
|
|
841
|
+
_provider?: "stripe" | "yns";
|
|
842
|
+
}
|
|
843
|
+
interface ProductGetParams {
|
|
844
|
+
slug?: string;
|
|
845
|
+
id?: string;
|
|
846
|
+
fields?: string[];
|
|
847
|
+
_provider?: "stripe" | "yns";
|
|
848
|
+
}
|
|
849
|
+
interface ProductSearchParams {
|
|
850
|
+
query: string;
|
|
851
|
+
limit?: number;
|
|
852
|
+
fields?: string[];
|
|
853
|
+
_provider?: "stripe" | "yns";
|
|
854
|
+
}
|
|
855
|
+
interface CartAddParams {
|
|
856
|
+
variantId: string;
|
|
857
|
+
cartId?: string;
|
|
858
|
+
quantity?: number;
|
|
859
|
+
subscriptionId?: string;
|
|
860
|
+
_provider?: "stripe" | "yns";
|
|
861
|
+
}
|
|
862
|
+
interface CartUpdateParams {
|
|
863
|
+
cartId: string;
|
|
864
|
+
variantId: string;
|
|
865
|
+
quantity: number;
|
|
866
|
+
_provider?: "stripe" | "yns";
|
|
867
|
+
}
|
|
868
|
+
interface CartClearParams {
|
|
869
|
+
cartId: string;
|
|
870
|
+
_provider?: "stripe" | "yns";
|
|
871
|
+
}
|
|
872
|
+
interface CartGetParams {
|
|
873
|
+
cartId: string;
|
|
874
|
+
_provider?: "stripe" | "yns";
|
|
875
|
+
}
|
|
876
|
+
interface OrderGetParams {
|
|
877
|
+
orderId: string;
|
|
878
|
+
_provider?: "stripe" | "yns";
|
|
879
|
+
}
|
|
880
|
+
interface OrderListParams {
|
|
881
|
+
customerId?: string;
|
|
882
|
+
limit?: number;
|
|
883
|
+
offset?: number;
|
|
884
|
+
_provider?: "stripe" | "yns";
|
|
885
|
+
}
|
|
886
|
+
interface ProductBrowseResult {
|
|
887
|
+
data: Product[];
|
|
888
|
+
meta: {
|
|
889
|
+
count: number;
|
|
890
|
+
offset: number;
|
|
891
|
+
limit: number;
|
|
892
|
+
hasMore: boolean;
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
interface ProductSearchResult {
|
|
896
|
+
data: Product[];
|
|
897
|
+
total: number;
|
|
898
|
+
}
|
|
899
|
+
interface OrderListResult {
|
|
900
|
+
data: Order[];
|
|
901
|
+
meta: {
|
|
902
|
+
count: number;
|
|
903
|
+
offset: number;
|
|
904
|
+
limit: number;
|
|
905
|
+
hasMore: boolean;
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Configure the Commerce SDK with provider settings
|
|
911
|
+
*/
|
|
912
|
+
declare function configure(config: CommerceConfig): void;
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Cart resource operations
|
|
916
|
+
*/
|
|
917
|
+
declare const cart: {
|
|
918
|
+
/**
|
|
919
|
+
* Add item to cart
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* ```typescript
|
|
923
|
+
* import { cart } from "commerce-kit";
|
|
924
|
+
*
|
|
925
|
+
* // Add to existing cart
|
|
926
|
+
* const result = await cart.add({
|
|
927
|
+
* variantId: "variant_123",
|
|
928
|
+
* cartId: "cart_abc",
|
|
929
|
+
* quantity: 2
|
|
930
|
+
* });
|
|
931
|
+
*
|
|
932
|
+
* // Create new cart if no cartId provided
|
|
933
|
+
* const newCart = await cart.add({
|
|
934
|
+
* variantId: "variant_456"
|
|
935
|
+
* });
|
|
936
|
+
*
|
|
937
|
+
* // Override provider
|
|
938
|
+
* const stripeCart = await cart.add({
|
|
939
|
+
* variantId: "price_123",
|
|
940
|
+
* cartId: "pi_456",
|
|
941
|
+
* _provider: "stripe"
|
|
942
|
+
* });
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
add(params: CartAddParams): Promise<{
|
|
946
|
+
cartId: string;
|
|
947
|
+
}>;
|
|
948
|
+
/**
|
|
949
|
+
* Update item quantity in cart
|
|
950
|
+
*
|
|
951
|
+
* @example
|
|
952
|
+
* ```typescript
|
|
953
|
+
* import { cart } from "commerce-kit";
|
|
954
|
+
*
|
|
955
|
+
* // Update quantity
|
|
956
|
+
* const result = await cart.update({
|
|
957
|
+
* cartId: "cart_123",
|
|
958
|
+
* variantId: "variant_456",
|
|
959
|
+
* quantity: 3
|
|
960
|
+
* });
|
|
961
|
+
*
|
|
962
|
+
* // Set quantity to 0 to remove item
|
|
963
|
+
* const removed = await cart.update({
|
|
964
|
+
* cartId: "cart_123",
|
|
965
|
+
* variantId: "variant_456",
|
|
966
|
+
* quantity: 0
|
|
967
|
+
* });
|
|
968
|
+
* ```
|
|
969
|
+
*/
|
|
970
|
+
update(params: CartUpdateParams): Promise<{
|
|
971
|
+
cartId: string;
|
|
972
|
+
}>;
|
|
973
|
+
/**
|
|
974
|
+
* Clear all items from cart
|
|
975
|
+
*
|
|
976
|
+
* @example
|
|
977
|
+
* ```typescript
|
|
978
|
+
* import { cart } from "commerce-kit";
|
|
979
|
+
*
|
|
980
|
+
* const result = await cart.clear({
|
|
981
|
+
* cartId: "cart_123"
|
|
982
|
+
* });
|
|
983
|
+
* ```
|
|
984
|
+
*/
|
|
985
|
+
clear(params: CartClearParams): Promise<{
|
|
986
|
+
cartId: string;
|
|
987
|
+
}>;
|
|
988
|
+
/**
|
|
989
|
+
* Get cart details with all items
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* ```typescript
|
|
993
|
+
* import { cart } from "commerce-kit";
|
|
994
|
+
*
|
|
995
|
+
* const cartData = await cart.get({
|
|
996
|
+
* cartId: "cart_123"
|
|
997
|
+
* });
|
|
998
|
+
*
|
|
999
|
+
* if (cartData) {
|
|
1000
|
+
* console.log(`Cart has ${cartData.items.length} items`);
|
|
1001
|
+
* console.log(`Total: ${cartData.total} ${cartData.currency}`);
|
|
1002
|
+
* }
|
|
1003
|
+
* ```
|
|
1004
|
+
*/
|
|
1005
|
+
get(params: CartGetParams): Promise<Cart | null>;
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* Order resource operations
|
|
1010
|
+
*/
|
|
1011
|
+
declare const order: {
|
|
1012
|
+
/**
|
|
1013
|
+
* Get a single order by ID
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* ```typescript
|
|
1017
|
+
* import { order } from "commerce-kit";
|
|
1018
|
+
*
|
|
1019
|
+
* const orderData = await order.get({
|
|
1020
|
+
* orderId: "order_123"
|
|
1021
|
+
* });
|
|
1022
|
+
*
|
|
1023
|
+
* if (orderData) {
|
|
1024
|
+
* console.log(`Order status: ${orderData.status}`);
|
|
1025
|
+
* console.log(`Order total: ${orderData.total} ${orderData.currency}`);
|
|
1026
|
+
* }
|
|
1027
|
+
* ```
|
|
1028
|
+
*/
|
|
1029
|
+
get(params: OrderGetParams): Promise<Order | null>;
|
|
1030
|
+
/**
|
|
1031
|
+
* List orders with optional filtering and pagination
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* import { order } from "commerce-kit";
|
|
1036
|
+
*
|
|
1037
|
+
* // List all orders
|
|
1038
|
+
* const orders = await order.list({
|
|
1039
|
+
* limit: 20,
|
|
1040
|
+
* offset: 0
|
|
1041
|
+
* });
|
|
1042
|
+
*
|
|
1043
|
+
* // List orders for specific customer
|
|
1044
|
+
* const customerOrders = await order.list({
|
|
1045
|
+
* customerId: "customer_123",
|
|
1046
|
+
* limit: 10
|
|
1047
|
+
* });
|
|
1048
|
+
*
|
|
1049
|
+
* console.log(`Found ${orders.meta.count} orders`);
|
|
1050
|
+
* ```
|
|
1051
|
+
*/
|
|
1052
|
+
list(params?: OrderListParams): Promise<OrderListResult>;
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Product resource operations
|
|
1057
|
+
*/
|
|
1058
|
+
declare const product: {
|
|
1059
|
+
/**
|
|
1060
|
+
* Browse/list products with optional filtering and pagination
|
|
1061
|
+
*
|
|
1062
|
+
* @example
|
|
1063
|
+
* ```typescript
|
|
1064
|
+
* import { product } from "commerce-kit";
|
|
1065
|
+
*
|
|
1066
|
+
* const products = await product.browse({
|
|
1067
|
+
* first: 10,
|
|
1068
|
+
* category: "electronics"
|
|
1069
|
+
* });
|
|
1070
|
+
*
|
|
1071
|
+
* // With GraphQL field selection (YNS only)
|
|
1072
|
+
* const productsWithFields = await product.browse({
|
|
1073
|
+
* first: 5,
|
|
1074
|
+
* fields: ["id", "name", "price", "images"]
|
|
1075
|
+
* });
|
|
1076
|
+
*
|
|
1077
|
+
* // Override provider for specific call
|
|
1078
|
+
* const stripeProducts = await product.browse({
|
|
1079
|
+
* first: 10,
|
|
1080
|
+
* _provider: "stripe"
|
|
1081
|
+
* });
|
|
1082
|
+
* ```
|
|
1083
|
+
*/
|
|
1084
|
+
browse(params?: ProductBrowseParams): Promise<ProductBrowseResult>;
|
|
1085
|
+
/**
|
|
1086
|
+
* Get a single product by slug or ID
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* ```typescript
|
|
1090
|
+
* import { product } from "commerce-kit";
|
|
1091
|
+
*
|
|
1092
|
+
* const productData = await product.get({ slug: "awesome-product" });
|
|
1093
|
+
*
|
|
1094
|
+
* // With GraphQL field selection (YNS only)
|
|
1095
|
+
* const productWithFields = await product.get({
|
|
1096
|
+
* slug: "awesome-product",
|
|
1097
|
+
* fields: ["id", "name", "price", "category.name"]
|
|
1098
|
+
* });
|
|
1099
|
+
*
|
|
1100
|
+
* // Get by ID instead of slug
|
|
1101
|
+
* const productById = await product.get({ id: "prod_123" });
|
|
1102
|
+
* ```
|
|
1103
|
+
*/
|
|
1104
|
+
get(params: ProductGetParams): Promise<Product | null>;
|
|
1105
|
+
/**
|
|
1106
|
+
* Search products by query string
|
|
1107
|
+
*
|
|
1108
|
+
* @example
|
|
1109
|
+
* ```typescript
|
|
1110
|
+
* import { product } from "commerce-kit";
|
|
1111
|
+
*
|
|
1112
|
+
* const searchResults = await product.search({
|
|
1113
|
+
* query: "laptop computer",
|
|
1114
|
+
* limit: 20
|
|
1115
|
+
* });
|
|
1116
|
+
*
|
|
1117
|
+
* // With field selection
|
|
1118
|
+
* const searchWithFields = await product.search({
|
|
1119
|
+
* query: "smartphone",
|
|
1120
|
+
* fields: ["id", "name", "price"],
|
|
1121
|
+
* limit: 10
|
|
1122
|
+
* });
|
|
1123
|
+
* ```
|
|
1124
|
+
*/
|
|
1125
|
+
search(params: ProductSearchParams): Promise<ProductSearchResult>;
|
|
1126
|
+
};
|
|
1127
|
+
|
|
782
1128
|
declare const provider: ({ tags, revalidate, cache, tagPrefix, secretKey, }: {
|
|
783
1129
|
tags?: NextFetchRequestConfig["tags"];
|
|
784
1130
|
revalidate?: NextFetchRequestConfig["revalidate"];
|
|
@@ -787,4 +1133,42 @@ declare const provider: ({ tags, revalidate, cache, tagPrefix, secretKey, }: {
|
|
|
787
1133
|
secretKey: string | undefined;
|
|
788
1134
|
}) => Stripe;
|
|
789
1135
|
|
|
790
|
-
|
|
1136
|
+
/**
|
|
1137
|
+
* Create a scoped Commerce instance with a specific provider
|
|
1138
|
+
*
|
|
1139
|
+
* @example
|
|
1140
|
+
* ```typescript
|
|
1141
|
+
* import { withProvider } from "commerce-kit";
|
|
1142
|
+
*
|
|
1143
|
+
* const ynsCommerce = withProvider("yns");
|
|
1144
|
+
* const stripeCommerce = withProvider("stripe");
|
|
1145
|
+
*
|
|
1146
|
+
* const ynsProducts = await ynsCommerce.product.browse({ first: 10 });
|
|
1147
|
+
* const stripeProducts = await stripeCommerce.product.browse({ first: 10 });
|
|
1148
|
+
* ```
|
|
1149
|
+
*/
|
|
1150
|
+
declare function withProvider(provider: "stripe" | "yns"): {
|
|
1151
|
+
product: {
|
|
1152
|
+
browse(params: any): Promise<ProductBrowseResult>;
|
|
1153
|
+
get(params: any): Promise<Product | null>;
|
|
1154
|
+
search(params: any): Promise<ProductSearchResult>;
|
|
1155
|
+
};
|
|
1156
|
+
cart: {
|
|
1157
|
+
add(params: any): Promise<{
|
|
1158
|
+
cartId: string;
|
|
1159
|
+
}>;
|
|
1160
|
+
update(params: any): Promise<{
|
|
1161
|
+
cartId: string;
|
|
1162
|
+
}>;
|
|
1163
|
+
clear(params: any): Promise<{
|
|
1164
|
+
cartId: string;
|
|
1165
|
+
}>;
|
|
1166
|
+
get(params: any): Promise<Cart | null>;
|
|
1167
|
+
};
|
|
1168
|
+
order: {
|
|
1169
|
+
get(params: any): Promise<Order | null>;
|
|
1170
|
+
list(params?: any): Promise<OrderListResult>;
|
|
1171
|
+
};
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
export { type AddressSchema, type BaseProvider, type Cart$1 as Cart, type CartAddParams, type CartClearParams, type CartGetParams, type CartUpdateParams, type Cart as CommerceCart, type CartItem as CommerceCartItem, type CommerceConfig, type Order as CommerceOrder, MappedCart, type Order$1 as Order, type Product, type ProductBrowseParams, type ProductGetParams, type ProductsFromMetadata, accountGet, calculateCartTotalNet, calculateCartTotalNetWithoutShipping, calculateCartTotalPossiblyWithTax, cart, cartAdd, cartAddOptimistic, cartChangeQuantity, cartCount, cartCreate, cartGet, cartSaveBillingAddress, cartSaveEmail, cartSaveShipping, cartSaveTax, cartSetQuantity, cartUpdateQuantity, categoryBrowse, configure, contextGet, fileGet, getAddressSchema, getCartWithProductsById, getProductsFromCart, getProductsFromMetadata, order, orderGet, product, productBrowse, productGet, productGetById, productReviewAdd, productReviewBrowse, provider, shippingBrowse, shippingGet, taxDefaultGet, updatePaymentIntent, withProvider };
|