@betterstore/sdk 0.5.25 → 0.6.1
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 +9 -302
- package/dist/index.d.ts +9 -302
- package/dist/index.js +8 -101
- package/dist/index.mjs +6 -100
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,292 +1,9 @@
|
|
|
1
|
+
import { OTPSignupParams, OTPSignupResponse, OTPLoginParams, OTPLoginResponse, OTPVerifyParams, OTPVerifyResponse, CustomerSession, CheckoutCreateParams, CheckoutSession, CheckoutUpdateParams, GetShippingRatesResponse, CustomerCreateParams, CustomerResponse, CustomerUpdateParams, AutosuggestAddressResult, LookupAddressResult, ListCollectionsParams, ListCollectionsResponse, RetrieveCollectionParams, RetrieveCollectionResponse, CustomerSubscriptionUpdateParams, CustomerSubscription, ListDiscountsParams, ListDiscountsResponse, RetrieveDiscountParams, RetrieveDiscountResponse, ListProductsParams, ListProductsResponse, RetrieveProductParams, RetrieveProductResponse } from '@betterstore/bridge';
|
|
2
|
+
export { Address, AutosuggestAddressResult, CheckoutCreateParams, CheckoutSession, CheckoutUpdateParams, CustomShippingVendorRate, CustomerCreateParams, CustomerResponse, CustomerSession, CustomerSubscription, CustomerSubscriptionUpdateParams, CustomerUpdateParams, GetShippingRatesResponse, ListCollectionsParams, ListCollectionsResponse, ListDiscountsParams, ListDiscountsResponse, ListProductsParams, ListProductsResponse, LookupAddressResult, OTPLoginParams, OTPLoginResponse, OTPSignupParams, OTPSignupResponse, OTPVerifyParams, OTPVerifyResponse, ProductVariant, RetrieveCollectionParams, RetrieveCollectionResponse, RetrieveDiscountParams, RetrieveDiscountResponse, RetrieveProductParams, RetrieveProductResponse, formatCurrency, formatPrice } from '@betterstore/bridge';
|
|
1
3
|
import axios from 'axios';
|
|
2
|
-
import { GetShippingRatesResponse, ListCollectionsParams, ListCollectionsResponse, RetrieveCollectionParams, RetrieveCollectionResponse, ListDiscountsParams, ListDiscountsResponse, RetrieveDiscountParams, RetrieveDiscountResponse, ListProductsParams, ListProductsResponse, RetrieveProductParams, RetrieveProductResponse } from '@betterstore/bridge';
|
|
3
4
|
|
|
4
5
|
declare const createApiClient: (apiKey: string, proxy?: string) => axios.AxiosInstance;
|
|
5
6
|
|
|
6
|
-
interface Discount {
|
|
7
|
-
id: string;
|
|
8
|
-
createdAt: Date;
|
|
9
|
-
updatedAt: Date;
|
|
10
|
-
type: "AMOUNT_OFF_PRODUCTS" | "BUY_X_GET_Y" | "AMOUNT_OFF_ORDER" | "FREE_SHIPPING";
|
|
11
|
-
method: "CODE" | "AUTOMATIC";
|
|
12
|
-
code?: string | null;
|
|
13
|
-
title?: string | null;
|
|
14
|
-
value: number;
|
|
15
|
-
valueType: "PERCENTAGE" | "FIXED_AMOUNT" | "FREE";
|
|
16
|
-
discountScope: "PRODUCTS" | "COLLECTIONS";
|
|
17
|
-
allowedProductIDs: string[];
|
|
18
|
-
allowedCollectionIDs: string[];
|
|
19
|
-
allowedCombinations: ("ORDER" | "PRODUCT" | "SHIPPING")[];
|
|
20
|
-
minimumRequirementsType: "NONE" | "MINIMUM_ORDER_AMOUNT" | "MINIMUM_PRODUCT_QUANTITY";
|
|
21
|
-
minimumRequirementsValue?: number | null;
|
|
22
|
-
requiredProductIDs: string[];
|
|
23
|
-
requiredCollectionIDs: string[];
|
|
24
|
-
minimumRequirementsScope: "PRODUCTS" | "COLLECTIONS";
|
|
25
|
-
maxUses?: number | null;
|
|
26
|
-
maxUsesPerCustomer?: number | null;
|
|
27
|
-
maxAllowedProductQuantity?: number | null;
|
|
28
|
-
uses: number;
|
|
29
|
-
subscriptionDiscountDurationType: "ONE_TIME" | "RECURRING" | "FOREVER";
|
|
30
|
-
subscriptionDiscountDurationValue: number;
|
|
31
|
-
stripeDiscountId?: string | null;
|
|
32
|
-
startsAt: Date;
|
|
33
|
-
expiresAt?: Date | null;
|
|
34
|
-
status: "ACTIVE" | "EXPIRED" | "SCHEDULED";
|
|
35
|
-
organizationId: string;
|
|
36
|
-
}
|
|
37
|
-
interface VariantOption {
|
|
38
|
-
name: string;
|
|
39
|
-
value: string;
|
|
40
|
-
}
|
|
41
|
-
interface ProductVariant {
|
|
42
|
-
title: string;
|
|
43
|
-
description?: string;
|
|
44
|
-
images: string[];
|
|
45
|
-
sku?: string;
|
|
46
|
-
barcode?: string;
|
|
47
|
-
inventoryItem: {
|
|
48
|
-
stockPolicy: "CONTINUE" | "DENY";
|
|
49
|
-
trackInventory: boolean;
|
|
50
|
-
};
|
|
51
|
-
isPhysical: boolean;
|
|
52
|
-
weightInGrams?: number;
|
|
53
|
-
heightInCm?: number;
|
|
54
|
-
widthInCm?: number;
|
|
55
|
-
lengthInCm?: number;
|
|
56
|
-
priceInCents: number;
|
|
57
|
-
billingType: ProductBillingType;
|
|
58
|
-
billingInterval: ProductBillingInterval;
|
|
59
|
-
billingIntervalCount: number;
|
|
60
|
-
metadata?: Record<string, any>;
|
|
61
|
-
variantOptions: VariantOption[];
|
|
62
|
-
}
|
|
63
|
-
interface ProductOption {
|
|
64
|
-
name: string;
|
|
65
|
-
values: string[];
|
|
66
|
-
}
|
|
67
|
-
type ProductStatus = "DRAFT" | "ACTIVE" | "ARCHIVED";
|
|
68
|
-
type ProductBillingInterval = "DAY" | "WEEK" | "MONTH" | "YEAR";
|
|
69
|
-
type ProductBillingType = "ONE_TIME" | "SUBSCRIPTION";
|
|
70
|
-
interface Product {
|
|
71
|
-
id: string;
|
|
72
|
-
createdAt: Date;
|
|
73
|
-
updatedAt: Date;
|
|
74
|
-
title: string;
|
|
75
|
-
description?: string;
|
|
76
|
-
images: string[];
|
|
77
|
-
category: string;
|
|
78
|
-
tags: string[];
|
|
79
|
-
isPhysical: boolean;
|
|
80
|
-
weightInGrams?: number;
|
|
81
|
-
heightInCm?: number;
|
|
82
|
-
widthInCm?: number;
|
|
83
|
-
lengthInCm?: number;
|
|
84
|
-
priceInCents: number;
|
|
85
|
-
billingType: ProductBillingType;
|
|
86
|
-
billingInterval: ProductBillingInterval;
|
|
87
|
-
billingIntervalCount: number;
|
|
88
|
-
sku?: string;
|
|
89
|
-
barcode?: string;
|
|
90
|
-
inventoryItem: {
|
|
91
|
-
stockPolicy: "CONTINUE" | "DENY";
|
|
92
|
-
trackInventory: boolean;
|
|
93
|
-
};
|
|
94
|
-
seoPageTitle?: string;
|
|
95
|
-
seoDescription?: string;
|
|
96
|
-
seoHandle?: string;
|
|
97
|
-
vendor?: string;
|
|
98
|
-
metadata?: Record<string, any>;
|
|
99
|
-
status: ProductStatus;
|
|
100
|
-
options: ProductOption[];
|
|
101
|
-
productVariants: ProductVariant[];
|
|
102
|
-
}
|
|
103
|
-
interface ProductWithoutVariants extends Omit<Product, "productVariants"> {
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
type ProductData = Pick<Product, "title" | "description" | "images" | "category" | "tags" | "sku" | "barcode" | "vendor" | "isPhysical" | "weightInGrams" | "heightInCm" | "widthInCm" | "lengthInCm" | "priceInCents" | "billingType" | "billingInterval" | "billingIntervalCount"> & {
|
|
107
|
-
productId: string;
|
|
108
|
-
selectedVariant: Pick<ProductVariant, "title" | "description" | "sku" | "barcode" | "images" | "isPhysical" | "weightInGrams" | "heightInCm" | "widthInCm" | "lengthInCm" | "priceInCents" | "billingType" | "billingInterval" | "billingIntervalCount" | "variantOptions" | "metadata">;
|
|
109
|
-
};
|
|
110
|
-
interface LineItem {
|
|
111
|
-
quantity: number;
|
|
112
|
-
variantOptions: {
|
|
113
|
-
name: string;
|
|
114
|
-
value: string;
|
|
115
|
-
}[];
|
|
116
|
-
productData: ProductData;
|
|
117
|
-
metadata?: string;
|
|
118
|
-
}
|
|
119
|
-
interface LineItemCreate extends Omit<LineItem, "productData" | "product" | "metadata" | "variantOptions"> {
|
|
120
|
-
variantOptions?: {
|
|
121
|
-
name: string;
|
|
122
|
-
value: string;
|
|
123
|
-
}[];
|
|
124
|
-
productId: string;
|
|
125
|
-
product?: ProductWithoutVariants;
|
|
126
|
-
metadata?: Record<string, any>;
|
|
127
|
-
}
|
|
128
|
-
type Currency = string;
|
|
129
|
-
interface CheckoutCreateParams {
|
|
130
|
-
type: "hosted" | "embed";
|
|
131
|
-
customerId?: string;
|
|
132
|
-
lineItems: LineItemCreate[];
|
|
133
|
-
currency?: Currency;
|
|
134
|
-
discountCodes?: string[];
|
|
135
|
-
}
|
|
136
|
-
interface CheckoutUpdateParams {
|
|
137
|
-
customerId?: string;
|
|
138
|
-
shipments?: CheckoutShipment[];
|
|
139
|
-
}
|
|
140
|
-
type ShipmentData = {
|
|
141
|
-
rateId: string;
|
|
142
|
-
providerId?: string;
|
|
143
|
-
priceInCents: number;
|
|
144
|
-
pickupPointId?: string;
|
|
145
|
-
trackingId?: string;
|
|
146
|
-
trackingUrl?: string;
|
|
147
|
-
};
|
|
148
|
-
type CheckoutShipment = {
|
|
149
|
-
id: string;
|
|
150
|
-
shipmentData?: ShipmentData | null;
|
|
151
|
-
};
|
|
152
|
-
interface CheckoutSession {
|
|
153
|
-
id: string;
|
|
154
|
-
testmode: boolean;
|
|
155
|
-
clientSecret: string;
|
|
156
|
-
customer?: {
|
|
157
|
-
id: string;
|
|
158
|
-
address?: Address;
|
|
159
|
-
email?: string;
|
|
160
|
-
};
|
|
161
|
-
lineItems: LineItem[];
|
|
162
|
-
tax: number | null;
|
|
163
|
-
discountAmount: number | null;
|
|
164
|
-
appliedDiscounts: {
|
|
165
|
-
id: string;
|
|
166
|
-
amount: number;
|
|
167
|
-
allowedLineItems: {
|
|
168
|
-
productId: string;
|
|
169
|
-
quantity: number;
|
|
170
|
-
}[];
|
|
171
|
-
discount: Discount;
|
|
172
|
-
}[];
|
|
173
|
-
currency: string;
|
|
174
|
-
exchangeRate: number | null;
|
|
175
|
-
shipments: CheckoutShipment[];
|
|
176
|
-
status: "IN_PROGRESS" | "PAYMENT_PENDING" | "ABANDONED" | "CANCELED" | "FAILED";
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
type AutosuggestAddressResult = {
|
|
180
|
-
id: string;
|
|
181
|
-
title: string;
|
|
182
|
-
address: {
|
|
183
|
-
label: string;
|
|
184
|
-
};
|
|
185
|
-
position: {
|
|
186
|
-
lat: number;
|
|
187
|
-
lng: number;
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
type LookupAddressResult = {
|
|
191
|
-
id: string;
|
|
192
|
-
title: string;
|
|
193
|
-
address: Pick<Address, "line1" | "city" | "province" | "provinceCode" | "country" | "countryCode" | "zipCode">;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
type Address = {
|
|
197
|
-
name: string;
|
|
198
|
-
phone: string;
|
|
199
|
-
line1: string;
|
|
200
|
-
line2?: string;
|
|
201
|
-
city: string;
|
|
202
|
-
province?: string;
|
|
203
|
-
provinceCode?: string;
|
|
204
|
-
country: string;
|
|
205
|
-
countryCode: string;
|
|
206
|
-
zipCode: string;
|
|
207
|
-
};
|
|
208
|
-
interface CustomerCreateParams {
|
|
209
|
-
firstName?: string;
|
|
210
|
-
lastName?: string;
|
|
211
|
-
email: string;
|
|
212
|
-
phone?: string;
|
|
213
|
-
address?: Address;
|
|
214
|
-
image?: string;
|
|
215
|
-
password?: string;
|
|
216
|
-
metadata?: Record<string, any>;
|
|
217
|
-
tags?: string[];
|
|
218
|
-
notes?: string;
|
|
219
|
-
isSubscribedEmail?: boolean;
|
|
220
|
-
isSubscribedSMS?: boolean;
|
|
221
|
-
}
|
|
222
|
-
interface CustomerUpdateParams extends Omit<CustomerCreateParams, "email"> {
|
|
223
|
-
email?: string;
|
|
224
|
-
}
|
|
225
|
-
interface Customer$1 extends CustomerCreateParams {
|
|
226
|
-
id: string;
|
|
227
|
-
createdAt: string;
|
|
228
|
-
updatedAt: string;
|
|
229
|
-
}
|
|
230
|
-
interface CustomerSubscription {
|
|
231
|
-
cancelAtPeriodEnd: boolean;
|
|
232
|
-
}
|
|
233
|
-
type CustomerSubscriptionUpdateParams = Partial<Pick<CustomerSubscription, "cancelAtPeriodEnd">>;
|
|
234
|
-
|
|
235
|
-
interface CustomerSession {
|
|
236
|
-
customerId: string;
|
|
237
|
-
expiresAt: Date;
|
|
238
|
-
testmode: boolean;
|
|
239
|
-
token: string;
|
|
240
|
-
customer: {
|
|
241
|
-
createdAt: Date;
|
|
242
|
-
updatedAt: Date;
|
|
243
|
-
firstName: string;
|
|
244
|
-
lastName: string;
|
|
245
|
-
email: string;
|
|
246
|
-
phone?: string;
|
|
247
|
-
password?: string;
|
|
248
|
-
image?: string;
|
|
249
|
-
metadata?: string;
|
|
250
|
-
stripeCustomerId: string;
|
|
251
|
-
isSubscribedEmail: boolean;
|
|
252
|
-
isSubscribedSMS: boolean;
|
|
253
|
-
address: Address;
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
interface OTPLoginParams {
|
|
257
|
-
email: string;
|
|
258
|
-
}
|
|
259
|
-
interface OTPSignupParams extends CustomerCreateParams {
|
|
260
|
-
}
|
|
261
|
-
interface OTPVerifyParams {
|
|
262
|
-
email: string;
|
|
263
|
-
otp: string;
|
|
264
|
-
}
|
|
265
|
-
type OTPLoginResponse = {
|
|
266
|
-
success: true;
|
|
267
|
-
token: string;
|
|
268
|
-
} | {
|
|
269
|
-
success: false;
|
|
270
|
-
code: "BAD_REQUEST" | "CUSTOMER_NOT_FOUND";
|
|
271
|
-
error: string;
|
|
272
|
-
};
|
|
273
|
-
type OTPSignupResponse = {
|
|
274
|
-
success: true;
|
|
275
|
-
token: string;
|
|
276
|
-
} | {
|
|
277
|
-
success: false;
|
|
278
|
-
code: "BAD_REQUEST" | "CUSTOMER_ALREADY_EXISTS";
|
|
279
|
-
error: string;
|
|
280
|
-
};
|
|
281
|
-
type OTPVerifyResponse = {
|
|
282
|
-
success: true;
|
|
283
|
-
customerSession: CustomerSession;
|
|
284
|
-
} | {
|
|
285
|
-
success: false;
|
|
286
|
-
code: "BAD_REQUEST";
|
|
287
|
-
error: string;
|
|
288
|
-
};
|
|
289
|
-
|
|
290
7
|
declare class OTP {
|
|
291
8
|
private apiClient;
|
|
292
9
|
constructor(apiClient: ReturnType<typeof createApiClient>);
|
|
@@ -381,15 +98,15 @@ declare class Client {
|
|
|
381
98
|
/**
|
|
382
99
|
* Create a new customer
|
|
383
100
|
*/
|
|
384
|
-
createCustomer(clientSecret: string, params: CustomerCreateParams): Promise<
|
|
101
|
+
createCustomer(clientSecret: string, params: CustomerCreateParams): Promise<CustomerResponse>;
|
|
385
102
|
/**
|
|
386
103
|
* Retrieve a customer by ID or email
|
|
387
104
|
*/
|
|
388
|
-
retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<
|
|
105
|
+
retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<CustomerResponse | null>;
|
|
389
106
|
/**
|
|
390
107
|
* Update a customer
|
|
391
108
|
*/
|
|
392
|
-
updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<
|
|
109
|
+
updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<CustomerResponse | null>;
|
|
393
110
|
/**
|
|
394
111
|
* Get exchange rate for a currency
|
|
395
112
|
*/
|
|
@@ -423,15 +140,15 @@ declare class Customer {
|
|
|
423
140
|
/**
|
|
424
141
|
* Create a new customer
|
|
425
142
|
*/
|
|
426
|
-
create(params: CustomerCreateParams): Promise<
|
|
143
|
+
create(params: CustomerCreateParams): Promise<CustomerResponse>;
|
|
427
144
|
/**
|
|
428
145
|
* Retrieve a customer by ID or email
|
|
429
146
|
*/
|
|
430
|
-
retrieve(idOrEmail: string): Promise<
|
|
147
|
+
retrieve(idOrEmail: string): Promise<CustomerResponse | null>;
|
|
431
148
|
/**
|
|
432
149
|
* Update a customer
|
|
433
150
|
*/
|
|
434
|
-
update(customerId: string, params: CustomerUpdateParams): Promise<
|
|
151
|
+
update(customerId: string, params: CustomerUpdateParams): Promise<CustomerResponse | null>;
|
|
435
152
|
/**
|
|
436
153
|
* Delete a customer
|
|
437
154
|
*/
|
|
@@ -449,13 +166,6 @@ declare class Discounts {
|
|
|
449
166
|
retrieve<T extends RetrieveDiscountParams>(params: T): Promise<RetrieveDiscountResponse | null>;
|
|
450
167
|
}
|
|
451
168
|
|
|
452
|
-
declare class Helpers {
|
|
453
|
-
proxy?: string;
|
|
454
|
-
constructor(proxy?: string);
|
|
455
|
-
formatCurrency(currency: string): string;
|
|
456
|
-
formatPrice(priceInCents: number, currency: string, exchangeRate?: number | null): string;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
169
|
declare class Products {
|
|
460
170
|
private apiClient;
|
|
461
171
|
constructor(apiKey: string, proxy?: string);
|
|
@@ -477,8 +187,5 @@ declare function createBetterStore(config: {
|
|
|
477
187
|
declare function createStoreClient(config?: {
|
|
478
188
|
proxy?: string;
|
|
479
189
|
}): Client;
|
|
480
|
-
declare function createStoreHelpers(config?: {
|
|
481
|
-
proxy?: string;
|
|
482
|
-
}): Helpers;
|
|
483
190
|
|
|
484
|
-
export {
|
|
191
|
+
export { createStoreClient, createBetterStore as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,292 +1,9 @@
|
|
|
1
|
+
import { OTPSignupParams, OTPSignupResponse, OTPLoginParams, OTPLoginResponse, OTPVerifyParams, OTPVerifyResponse, CustomerSession, CheckoutCreateParams, CheckoutSession, CheckoutUpdateParams, GetShippingRatesResponse, CustomerCreateParams, CustomerResponse, CustomerUpdateParams, AutosuggestAddressResult, LookupAddressResult, ListCollectionsParams, ListCollectionsResponse, RetrieveCollectionParams, RetrieveCollectionResponse, CustomerSubscriptionUpdateParams, CustomerSubscription, ListDiscountsParams, ListDiscountsResponse, RetrieveDiscountParams, RetrieveDiscountResponse, ListProductsParams, ListProductsResponse, RetrieveProductParams, RetrieveProductResponse } from '@betterstore/bridge';
|
|
2
|
+
export { Address, AutosuggestAddressResult, CheckoutCreateParams, CheckoutSession, CheckoutUpdateParams, CustomShippingVendorRate, CustomerCreateParams, CustomerResponse, CustomerSession, CustomerSubscription, CustomerSubscriptionUpdateParams, CustomerUpdateParams, GetShippingRatesResponse, ListCollectionsParams, ListCollectionsResponse, ListDiscountsParams, ListDiscountsResponse, ListProductsParams, ListProductsResponse, LookupAddressResult, OTPLoginParams, OTPLoginResponse, OTPSignupParams, OTPSignupResponse, OTPVerifyParams, OTPVerifyResponse, ProductVariant, RetrieveCollectionParams, RetrieveCollectionResponse, RetrieveDiscountParams, RetrieveDiscountResponse, RetrieveProductParams, RetrieveProductResponse, formatCurrency, formatPrice } from '@betterstore/bridge';
|
|
1
3
|
import axios from 'axios';
|
|
2
|
-
import { GetShippingRatesResponse, ListCollectionsParams, ListCollectionsResponse, RetrieveCollectionParams, RetrieveCollectionResponse, ListDiscountsParams, ListDiscountsResponse, RetrieveDiscountParams, RetrieveDiscountResponse, ListProductsParams, ListProductsResponse, RetrieveProductParams, RetrieveProductResponse } from '@betterstore/bridge';
|
|
3
4
|
|
|
4
5
|
declare const createApiClient: (apiKey: string, proxy?: string) => axios.AxiosInstance;
|
|
5
6
|
|
|
6
|
-
interface Discount {
|
|
7
|
-
id: string;
|
|
8
|
-
createdAt: Date;
|
|
9
|
-
updatedAt: Date;
|
|
10
|
-
type: "AMOUNT_OFF_PRODUCTS" | "BUY_X_GET_Y" | "AMOUNT_OFF_ORDER" | "FREE_SHIPPING";
|
|
11
|
-
method: "CODE" | "AUTOMATIC";
|
|
12
|
-
code?: string | null;
|
|
13
|
-
title?: string | null;
|
|
14
|
-
value: number;
|
|
15
|
-
valueType: "PERCENTAGE" | "FIXED_AMOUNT" | "FREE";
|
|
16
|
-
discountScope: "PRODUCTS" | "COLLECTIONS";
|
|
17
|
-
allowedProductIDs: string[];
|
|
18
|
-
allowedCollectionIDs: string[];
|
|
19
|
-
allowedCombinations: ("ORDER" | "PRODUCT" | "SHIPPING")[];
|
|
20
|
-
minimumRequirementsType: "NONE" | "MINIMUM_ORDER_AMOUNT" | "MINIMUM_PRODUCT_QUANTITY";
|
|
21
|
-
minimumRequirementsValue?: number | null;
|
|
22
|
-
requiredProductIDs: string[];
|
|
23
|
-
requiredCollectionIDs: string[];
|
|
24
|
-
minimumRequirementsScope: "PRODUCTS" | "COLLECTIONS";
|
|
25
|
-
maxUses?: number | null;
|
|
26
|
-
maxUsesPerCustomer?: number | null;
|
|
27
|
-
maxAllowedProductQuantity?: number | null;
|
|
28
|
-
uses: number;
|
|
29
|
-
subscriptionDiscountDurationType: "ONE_TIME" | "RECURRING" | "FOREVER";
|
|
30
|
-
subscriptionDiscountDurationValue: number;
|
|
31
|
-
stripeDiscountId?: string | null;
|
|
32
|
-
startsAt: Date;
|
|
33
|
-
expiresAt?: Date | null;
|
|
34
|
-
status: "ACTIVE" | "EXPIRED" | "SCHEDULED";
|
|
35
|
-
organizationId: string;
|
|
36
|
-
}
|
|
37
|
-
interface VariantOption {
|
|
38
|
-
name: string;
|
|
39
|
-
value: string;
|
|
40
|
-
}
|
|
41
|
-
interface ProductVariant {
|
|
42
|
-
title: string;
|
|
43
|
-
description?: string;
|
|
44
|
-
images: string[];
|
|
45
|
-
sku?: string;
|
|
46
|
-
barcode?: string;
|
|
47
|
-
inventoryItem: {
|
|
48
|
-
stockPolicy: "CONTINUE" | "DENY";
|
|
49
|
-
trackInventory: boolean;
|
|
50
|
-
};
|
|
51
|
-
isPhysical: boolean;
|
|
52
|
-
weightInGrams?: number;
|
|
53
|
-
heightInCm?: number;
|
|
54
|
-
widthInCm?: number;
|
|
55
|
-
lengthInCm?: number;
|
|
56
|
-
priceInCents: number;
|
|
57
|
-
billingType: ProductBillingType;
|
|
58
|
-
billingInterval: ProductBillingInterval;
|
|
59
|
-
billingIntervalCount: number;
|
|
60
|
-
metadata?: Record<string, any>;
|
|
61
|
-
variantOptions: VariantOption[];
|
|
62
|
-
}
|
|
63
|
-
interface ProductOption {
|
|
64
|
-
name: string;
|
|
65
|
-
values: string[];
|
|
66
|
-
}
|
|
67
|
-
type ProductStatus = "DRAFT" | "ACTIVE" | "ARCHIVED";
|
|
68
|
-
type ProductBillingInterval = "DAY" | "WEEK" | "MONTH" | "YEAR";
|
|
69
|
-
type ProductBillingType = "ONE_TIME" | "SUBSCRIPTION";
|
|
70
|
-
interface Product {
|
|
71
|
-
id: string;
|
|
72
|
-
createdAt: Date;
|
|
73
|
-
updatedAt: Date;
|
|
74
|
-
title: string;
|
|
75
|
-
description?: string;
|
|
76
|
-
images: string[];
|
|
77
|
-
category: string;
|
|
78
|
-
tags: string[];
|
|
79
|
-
isPhysical: boolean;
|
|
80
|
-
weightInGrams?: number;
|
|
81
|
-
heightInCm?: number;
|
|
82
|
-
widthInCm?: number;
|
|
83
|
-
lengthInCm?: number;
|
|
84
|
-
priceInCents: number;
|
|
85
|
-
billingType: ProductBillingType;
|
|
86
|
-
billingInterval: ProductBillingInterval;
|
|
87
|
-
billingIntervalCount: number;
|
|
88
|
-
sku?: string;
|
|
89
|
-
barcode?: string;
|
|
90
|
-
inventoryItem: {
|
|
91
|
-
stockPolicy: "CONTINUE" | "DENY";
|
|
92
|
-
trackInventory: boolean;
|
|
93
|
-
};
|
|
94
|
-
seoPageTitle?: string;
|
|
95
|
-
seoDescription?: string;
|
|
96
|
-
seoHandle?: string;
|
|
97
|
-
vendor?: string;
|
|
98
|
-
metadata?: Record<string, any>;
|
|
99
|
-
status: ProductStatus;
|
|
100
|
-
options: ProductOption[];
|
|
101
|
-
productVariants: ProductVariant[];
|
|
102
|
-
}
|
|
103
|
-
interface ProductWithoutVariants extends Omit<Product, "productVariants"> {
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
type ProductData = Pick<Product, "title" | "description" | "images" | "category" | "tags" | "sku" | "barcode" | "vendor" | "isPhysical" | "weightInGrams" | "heightInCm" | "widthInCm" | "lengthInCm" | "priceInCents" | "billingType" | "billingInterval" | "billingIntervalCount"> & {
|
|
107
|
-
productId: string;
|
|
108
|
-
selectedVariant: Pick<ProductVariant, "title" | "description" | "sku" | "barcode" | "images" | "isPhysical" | "weightInGrams" | "heightInCm" | "widthInCm" | "lengthInCm" | "priceInCents" | "billingType" | "billingInterval" | "billingIntervalCount" | "variantOptions" | "metadata">;
|
|
109
|
-
};
|
|
110
|
-
interface LineItem {
|
|
111
|
-
quantity: number;
|
|
112
|
-
variantOptions: {
|
|
113
|
-
name: string;
|
|
114
|
-
value: string;
|
|
115
|
-
}[];
|
|
116
|
-
productData: ProductData;
|
|
117
|
-
metadata?: string;
|
|
118
|
-
}
|
|
119
|
-
interface LineItemCreate extends Omit<LineItem, "productData" | "product" | "metadata" | "variantOptions"> {
|
|
120
|
-
variantOptions?: {
|
|
121
|
-
name: string;
|
|
122
|
-
value: string;
|
|
123
|
-
}[];
|
|
124
|
-
productId: string;
|
|
125
|
-
product?: ProductWithoutVariants;
|
|
126
|
-
metadata?: Record<string, any>;
|
|
127
|
-
}
|
|
128
|
-
type Currency = string;
|
|
129
|
-
interface CheckoutCreateParams {
|
|
130
|
-
type: "hosted" | "embed";
|
|
131
|
-
customerId?: string;
|
|
132
|
-
lineItems: LineItemCreate[];
|
|
133
|
-
currency?: Currency;
|
|
134
|
-
discountCodes?: string[];
|
|
135
|
-
}
|
|
136
|
-
interface CheckoutUpdateParams {
|
|
137
|
-
customerId?: string;
|
|
138
|
-
shipments?: CheckoutShipment[];
|
|
139
|
-
}
|
|
140
|
-
type ShipmentData = {
|
|
141
|
-
rateId: string;
|
|
142
|
-
providerId?: string;
|
|
143
|
-
priceInCents: number;
|
|
144
|
-
pickupPointId?: string;
|
|
145
|
-
trackingId?: string;
|
|
146
|
-
trackingUrl?: string;
|
|
147
|
-
};
|
|
148
|
-
type CheckoutShipment = {
|
|
149
|
-
id: string;
|
|
150
|
-
shipmentData?: ShipmentData | null;
|
|
151
|
-
};
|
|
152
|
-
interface CheckoutSession {
|
|
153
|
-
id: string;
|
|
154
|
-
testmode: boolean;
|
|
155
|
-
clientSecret: string;
|
|
156
|
-
customer?: {
|
|
157
|
-
id: string;
|
|
158
|
-
address?: Address;
|
|
159
|
-
email?: string;
|
|
160
|
-
};
|
|
161
|
-
lineItems: LineItem[];
|
|
162
|
-
tax: number | null;
|
|
163
|
-
discountAmount: number | null;
|
|
164
|
-
appliedDiscounts: {
|
|
165
|
-
id: string;
|
|
166
|
-
amount: number;
|
|
167
|
-
allowedLineItems: {
|
|
168
|
-
productId: string;
|
|
169
|
-
quantity: number;
|
|
170
|
-
}[];
|
|
171
|
-
discount: Discount;
|
|
172
|
-
}[];
|
|
173
|
-
currency: string;
|
|
174
|
-
exchangeRate: number | null;
|
|
175
|
-
shipments: CheckoutShipment[];
|
|
176
|
-
status: "IN_PROGRESS" | "PAYMENT_PENDING" | "ABANDONED" | "CANCELED" | "FAILED";
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
type AutosuggestAddressResult = {
|
|
180
|
-
id: string;
|
|
181
|
-
title: string;
|
|
182
|
-
address: {
|
|
183
|
-
label: string;
|
|
184
|
-
};
|
|
185
|
-
position: {
|
|
186
|
-
lat: number;
|
|
187
|
-
lng: number;
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
type LookupAddressResult = {
|
|
191
|
-
id: string;
|
|
192
|
-
title: string;
|
|
193
|
-
address: Pick<Address, "line1" | "city" | "province" | "provinceCode" | "country" | "countryCode" | "zipCode">;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
type Address = {
|
|
197
|
-
name: string;
|
|
198
|
-
phone: string;
|
|
199
|
-
line1: string;
|
|
200
|
-
line2?: string;
|
|
201
|
-
city: string;
|
|
202
|
-
province?: string;
|
|
203
|
-
provinceCode?: string;
|
|
204
|
-
country: string;
|
|
205
|
-
countryCode: string;
|
|
206
|
-
zipCode: string;
|
|
207
|
-
};
|
|
208
|
-
interface CustomerCreateParams {
|
|
209
|
-
firstName?: string;
|
|
210
|
-
lastName?: string;
|
|
211
|
-
email: string;
|
|
212
|
-
phone?: string;
|
|
213
|
-
address?: Address;
|
|
214
|
-
image?: string;
|
|
215
|
-
password?: string;
|
|
216
|
-
metadata?: Record<string, any>;
|
|
217
|
-
tags?: string[];
|
|
218
|
-
notes?: string;
|
|
219
|
-
isSubscribedEmail?: boolean;
|
|
220
|
-
isSubscribedSMS?: boolean;
|
|
221
|
-
}
|
|
222
|
-
interface CustomerUpdateParams extends Omit<CustomerCreateParams, "email"> {
|
|
223
|
-
email?: string;
|
|
224
|
-
}
|
|
225
|
-
interface Customer$1 extends CustomerCreateParams {
|
|
226
|
-
id: string;
|
|
227
|
-
createdAt: string;
|
|
228
|
-
updatedAt: string;
|
|
229
|
-
}
|
|
230
|
-
interface CustomerSubscription {
|
|
231
|
-
cancelAtPeriodEnd: boolean;
|
|
232
|
-
}
|
|
233
|
-
type CustomerSubscriptionUpdateParams = Partial<Pick<CustomerSubscription, "cancelAtPeriodEnd">>;
|
|
234
|
-
|
|
235
|
-
interface CustomerSession {
|
|
236
|
-
customerId: string;
|
|
237
|
-
expiresAt: Date;
|
|
238
|
-
testmode: boolean;
|
|
239
|
-
token: string;
|
|
240
|
-
customer: {
|
|
241
|
-
createdAt: Date;
|
|
242
|
-
updatedAt: Date;
|
|
243
|
-
firstName: string;
|
|
244
|
-
lastName: string;
|
|
245
|
-
email: string;
|
|
246
|
-
phone?: string;
|
|
247
|
-
password?: string;
|
|
248
|
-
image?: string;
|
|
249
|
-
metadata?: string;
|
|
250
|
-
stripeCustomerId: string;
|
|
251
|
-
isSubscribedEmail: boolean;
|
|
252
|
-
isSubscribedSMS: boolean;
|
|
253
|
-
address: Address;
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
interface OTPLoginParams {
|
|
257
|
-
email: string;
|
|
258
|
-
}
|
|
259
|
-
interface OTPSignupParams extends CustomerCreateParams {
|
|
260
|
-
}
|
|
261
|
-
interface OTPVerifyParams {
|
|
262
|
-
email: string;
|
|
263
|
-
otp: string;
|
|
264
|
-
}
|
|
265
|
-
type OTPLoginResponse = {
|
|
266
|
-
success: true;
|
|
267
|
-
token: string;
|
|
268
|
-
} | {
|
|
269
|
-
success: false;
|
|
270
|
-
code: "BAD_REQUEST" | "CUSTOMER_NOT_FOUND";
|
|
271
|
-
error: string;
|
|
272
|
-
};
|
|
273
|
-
type OTPSignupResponse = {
|
|
274
|
-
success: true;
|
|
275
|
-
token: string;
|
|
276
|
-
} | {
|
|
277
|
-
success: false;
|
|
278
|
-
code: "BAD_REQUEST" | "CUSTOMER_ALREADY_EXISTS";
|
|
279
|
-
error: string;
|
|
280
|
-
};
|
|
281
|
-
type OTPVerifyResponse = {
|
|
282
|
-
success: true;
|
|
283
|
-
customerSession: CustomerSession;
|
|
284
|
-
} | {
|
|
285
|
-
success: false;
|
|
286
|
-
code: "BAD_REQUEST";
|
|
287
|
-
error: string;
|
|
288
|
-
};
|
|
289
|
-
|
|
290
7
|
declare class OTP {
|
|
291
8
|
private apiClient;
|
|
292
9
|
constructor(apiClient: ReturnType<typeof createApiClient>);
|
|
@@ -381,15 +98,15 @@ declare class Client {
|
|
|
381
98
|
/**
|
|
382
99
|
* Create a new customer
|
|
383
100
|
*/
|
|
384
|
-
createCustomer(clientSecret: string, params: CustomerCreateParams): Promise<
|
|
101
|
+
createCustomer(clientSecret: string, params: CustomerCreateParams): Promise<CustomerResponse>;
|
|
385
102
|
/**
|
|
386
103
|
* Retrieve a customer by ID or email
|
|
387
104
|
*/
|
|
388
|
-
retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<
|
|
105
|
+
retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<CustomerResponse | null>;
|
|
389
106
|
/**
|
|
390
107
|
* Update a customer
|
|
391
108
|
*/
|
|
392
|
-
updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<
|
|
109
|
+
updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<CustomerResponse | null>;
|
|
393
110
|
/**
|
|
394
111
|
* Get exchange rate for a currency
|
|
395
112
|
*/
|
|
@@ -423,15 +140,15 @@ declare class Customer {
|
|
|
423
140
|
/**
|
|
424
141
|
* Create a new customer
|
|
425
142
|
*/
|
|
426
|
-
create(params: CustomerCreateParams): Promise<
|
|
143
|
+
create(params: CustomerCreateParams): Promise<CustomerResponse>;
|
|
427
144
|
/**
|
|
428
145
|
* Retrieve a customer by ID or email
|
|
429
146
|
*/
|
|
430
|
-
retrieve(idOrEmail: string): Promise<
|
|
147
|
+
retrieve(idOrEmail: string): Promise<CustomerResponse | null>;
|
|
431
148
|
/**
|
|
432
149
|
* Update a customer
|
|
433
150
|
*/
|
|
434
|
-
update(customerId: string, params: CustomerUpdateParams): Promise<
|
|
151
|
+
update(customerId: string, params: CustomerUpdateParams): Promise<CustomerResponse | null>;
|
|
435
152
|
/**
|
|
436
153
|
* Delete a customer
|
|
437
154
|
*/
|
|
@@ -449,13 +166,6 @@ declare class Discounts {
|
|
|
449
166
|
retrieve<T extends RetrieveDiscountParams>(params: T): Promise<RetrieveDiscountResponse | null>;
|
|
450
167
|
}
|
|
451
168
|
|
|
452
|
-
declare class Helpers {
|
|
453
|
-
proxy?: string;
|
|
454
|
-
constructor(proxy?: string);
|
|
455
|
-
formatCurrency(currency: string): string;
|
|
456
|
-
formatPrice(priceInCents: number, currency: string, exchangeRate?: number | null): string;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
169
|
declare class Products {
|
|
460
170
|
private apiClient;
|
|
461
171
|
constructor(apiKey: string, proxy?: string);
|
|
@@ -477,8 +187,5 @@ declare function createBetterStore(config: {
|
|
|
477
187
|
declare function createStoreClient(config?: {
|
|
478
188
|
proxy?: string;
|
|
479
189
|
}): Client;
|
|
480
|
-
declare function createStoreHelpers(config?: {
|
|
481
|
-
proxy?: string;
|
|
482
|
-
}): Helpers;
|
|
483
190
|
|
|
484
|
-
export {
|
|
191
|
+
export { createStoreClient, createBetterStore as default };
|
package/dist/index.js
CHANGED
|
@@ -31,8 +31,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
createStoreClient: () => createStoreClient,
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
default: () => createBetterStore,
|
|
35
|
+
formatCurrency: () => import_bridge.formatCurrency,
|
|
36
|
+
formatPrice: () => import_bridge.formatPrice
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(index_exports);
|
|
38
39
|
|
|
@@ -556,101 +557,6 @@ var Discounts = class {
|
|
|
556
557
|
};
|
|
557
558
|
var discounts_default = Discounts;
|
|
558
559
|
|
|
559
|
-
// src/helpers/index.ts
|
|
560
|
-
var currencyLocales = {
|
|
561
|
-
CZK: "cs-CZ",
|
|
562
|
-
// Czech Koruna
|
|
563
|
-
USD: "en-US",
|
|
564
|
-
// US Dollar
|
|
565
|
-
EUR: "de-DE",
|
|
566
|
-
// Euro (Germany locale)
|
|
567
|
-
GBP: "en-GB",
|
|
568
|
-
// British Pound
|
|
569
|
-
JPY: "ja-JP",
|
|
570
|
-
// Japanese Yen
|
|
571
|
-
AUD: "en-AU",
|
|
572
|
-
// Australian Dollar
|
|
573
|
-
CAD: "en-CA",
|
|
574
|
-
// Canadian Dollar
|
|
575
|
-
NZD: "en-NZ",
|
|
576
|
-
// New Zealand Dollar
|
|
577
|
-
SEK: "sv-SE",
|
|
578
|
-
// Swedish Krona
|
|
579
|
-
NOK: "nb-NO",
|
|
580
|
-
// Norwegian Krone
|
|
581
|
-
DKK: "da-DK",
|
|
582
|
-
// Danish Krone
|
|
583
|
-
CHF: "de-CH",
|
|
584
|
-
// Swiss Franc (German Switzerland)
|
|
585
|
-
HUF: "hu-HU",
|
|
586
|
-
// Hungarian Forint
|
|
587
|
-
PLN: "pl-PL",
|
|
588
|
-
// Polish Zloty
|
|
589
|
-
BGN: "bg-BG",
|
|
590
|
-
// Bulgarian Lev
|
|
591
|
-
RON: "ro-RO",
|
|
592
|
-
// Romanian Leu
|
|
593
|
-
RUB: "ru-RU",
|
|
594
|
-
// Russian Ruble
|
|
595
|
-
CNY: "zh-CN",
|
|
596
|
-
// Chinese Yuan
|
|
597
|
-
INR: "en-IN",
|
|
598
|
-
// Indian Rupee
|
|
599
|
-
BRL: "pt-BR",
|
|
600
|
-
// Brazilian Real
|
|
601
|
-
MXN: "es-MX",
|
|
602
|
-
// Mexican Peso
|
|
603
|
-
ZAR: "en-ZA",
|
|
604
|
-
// South African Rand
|
|
605
|
-
KRW: "ko-KR",
|
|
606
|
-
// South Korean Won
|
|
607
|
-
MYR: "ms-MY",
|
|
608
|
-
// Malaysian Ringgit
|
|
609
|
-
SGD: "en-SG",
|
|
610
|
-
// Singapore Dollar
|
|
611
|
-
TWD: "zh-TW",
|
|
612
|
-
// Taiwanese Dollar
|
|
613
|
-
THB: "th-TH",
|
|
614
|
-
// Thai Baht
|
|
615
|
-
IDR: "id-ID",
|
|
616
|
-
// Indonesian Rupiah
|
|
617
|
-
AED: "ar-AE",
|
|
618
|
-
// UAE Dirham
|
|
619
|
-
SAR: "ar-SA",
|
|
620
|
-
// Saudi Riyal
|
|
621
|
-
TRY: "tr-TR"
|
|
622
|
-
// Turkish Lira
|
|
623
|
-
};
|
|
624
|
-
var Helpers = class {
|
|
625
|
-
proxy;
|
|
626
|
-
constructor(proxy) {
|
|
627
|
-
this.proxy = proxy;
|
|
628
|
-
}
|
|
629
|
-
formatCurrency(currency) {
|
|
630
|
-
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
631
|
-
const formattedCurrency = new Intl.NumberFormat(locale, {
|
|
632
|
-
style: "currency",
|
|
633
|
-
currency,
|
|
634
|
-
currencyDisplay: "symbol"
|
|
635
|
-
});
|
|
636
|
-
return formattedCurrency.format(0).replace(/[\d.,\s]/g, "").trim();
|
|
637
|
-
}
|
|
638
|
-
formatPrice(priceInCents, currency, exchangeRate) {
|
|
639
|
-
const amount = priceInCents / 100 * (exchangeRate ?? 1);
|
|
640
|
-
const isWhole = amount % 1 === 0;
|
|
641
|
-
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
642
|
-
const formattedPrice = new Intl.NumberFormat(locale, {
|
|
643
|
-
style: "currency",
|
|
644
|
-
currency,
|
|
645
|
-
currencyDisplay: "symbol",
|
|
646
|
-
minimumFractionDigits: isWhole ? 0 : 2,
|
|
647
|
-
maximumFractionDigits: isWhole ? 0 : 2
|
|
648
|
-
}).format(amount);
|
|
649
|
-
return formattedPrice;
|
|
650
|
-
}
|
|
651
|
-
};
|
|
652
|
-
var helpers_default = Helpers;
|
|
653
|
-
|
|
654
560
|
// src/products/index.ts
|
|
655
561
|
var Products = class {
|
|
656
562
|
apiClient;
|
|
@@ -680,6 +586,9 @@ var Products = class {
|
|
|
680
586
|
};
|
|
681
587
|
var products_default = Products;
|
|
682
588
|
|
|
589
|
+
// src/types.ts
|
|
590
|
+
var import_bridge = require("@betterstore/bridge");
|
|
591
|
+
|
|
683
592
|
// src/index.ts
|
|
684
593
|
function createBetterStore(config) {
|
|
685
594
|
if (!config.apiKey) {
|
|
@@ -697,11 +606,9 @@ function createBetterStore(config) {
|
|
|
697
606
|
function createStoreClient(config) {
|
|
698
607
|
return new client_default(config?.proxy);
|
|
699
608
|
}
|
|
700
|
-
function createStoreHelpers(config) {
|
|
701
|
-
return new helpers_default(config?.proxy);
|
|
702
|
-
}
|
|
703
609
|
// Annotate the CommonJS export names for ESM import in node:
|
|
704
610
|
0 && (module.exports = {
|
|
705
611
|
createStoreClient,
|
|
706
|
-
|
|
612
|
+
formatCurrency,
|
|
613
|
+
formatPrice
|
|
707
614
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -518,101 +518,6 @@ var Discounts = class {
|
|
|
518
518
|
};
|
|
519
519
|
var discounts_default = Discounts;
|
|
520
520
|
|
|
521
|
-
// src/helpers/index.ts
|
|
522
|
-
var currencyLocales = {
|
|
523
|
-
CZK: "cs-CZ",
|
|
524
|
-
// Czech Koruna
|
|
525
|
-
USD: "en-US",
|
|
526
|
-
// US Dollar
|
|
527
|
-
EUR: "de-DE",
|
|
528
|
-
// Euro (Germany locale)
|
|
529
|
-
GBP: "en-GB",
|
|
530
|
-
// British Pound
|
|
531
|
-
JPY: "ja-JP",
|
|
532
|
-
// Japanese Yen
|
|
533
|
-
AUD: "en-AU",
|
|
534
|
-
// Australian Dollar
|
|
535
|
-
CAD: "en-CA",
|
|
536
|
-
// Canadian Dollar
|
|
537
|
-
NZD: "en-NZ",
|
|
538
|
-
// New Zealand Dollar
|
|
539
|
-
SEK: "sv-SE",
|
|
540
|
-
// Swedish Krona
|
|
541
|
-
NOK: "nb-NO",
|
|
542
|
-
// Norwegian Krone
|
|
543
|
-
DKK: "da-DK",
|
|
544
|
-
// Danish Krone
|
|
545
|
-
CHF: "de-CH",
|
|
546
|
-
// Swiss Franc (German Switzerland)
|
|
547
|
-
HUF: "hu-HU",
|
|
548
|
-
// Hungarian Forint
|
|
549
|
-
PLN: "pl-PL",
|
|
550
|
-
// Polish Zloty
|
|
551
|
-
BGN: "bg-BG",
|
|
552
|
-
// Bulgarian Lev
|
|
553
|
-
RON: "ro-RO",
|
|
554
|
-
// Romanian Leu
|
|
555
|
-
RUB: "ru-RU",
|
|
556
|
-
// Russian Ruble
|
|
557
|
-
CNY: "zh-CN",
|
|
558
|
-
// Chinese Yuan
|
|
559
|
-
INR: "en-IN",
|
|
560
|
-
// Indian Rupee
|
|
561
|
-
BRL: "pt-BR",
|
|
562
|
-
// Brazilian Real
|
|
563
|
-
MXN: "es-MX",
|
|
564
|
-
// Mexican Peso
|
|
565
|
-
ZAR: "en-ZA",
|
|
566
|
-
// South African Rand
|
|
567
|
-
KRW: "ko-KR",
|
|
568
|
-
// South Korean Won
|
|
569
|
-
MYR: "ms-MY",
|
|
570
|
-
// Malaysian Ringgit
|
|
571
|
-
SGD: "en-SG",
|
|
572
|
-
// Singapore Dollar
|
|
573
|
-
TWD: "zh-TW",
|
|
574
|
-
// Taiwanese Dollar
|
|
575
|
-
THB: "th-TH",
|
|
576
|
-
// Thai Baht
|
|
577
|
-
IDR: "id-ID",
|
|
578
|
-
// Indonesian Rupiah
|
|
579
|
-
AED: "ar-AE",
|
|
580
|
-
// UAE Dirham
|
|
581
|
-
SAR: "ar-SA",
|
|
582
|
-
// Saudi Riyal
|
|
583
|
-
TRY: "tr-TR"
|
|
584
|
-
// Turkish Lira
|
|
585
|
-
};
|
|
586
|
-
var Helpers = class {
|
|
587
|
-
proxy;
|
|
588
|
-
constructor(proxy) {
|
|
589
|
-
this.proxy = proxy;
|
|
590
|
-
}
|
|
591
|
-
formatCurrency(currency) {
|
|
592
|
-
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
593
|
-
const formattedCurrency = new Intl.NumberFormat(locale, {
|
|
594
|
-
style: "currency",
|
|
595
|
-
currency,
|
|
596
|
-
currencyDisplay: "symbol"
|
|
597
|
-
});
|
|
598
|
-
return formattedCurrency.format(0).replace(/[\d.,\s]/g, "").trim();
|
|
599
|
-
}
|
|
600
|
-
formatPrice(priceInCents, currency, exchangeRate) {
|
|
601
|
-
const amount = priceInCents / 100 * (exchangeRate ?? 1);
|
|
602
|
-
const isWhole = amount % 1 === 0;
|
|
603
|
-
const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
|
|
604
|
-
const formattedPrice = new Intl.NumberFormat(locale, {
|
|
605
|
-
style: "currency",
|
|
606
|
-
currency,
|
|
607
|
-
currencyDisplay: "symbol",
|
|
608
|
-
minimumFractionDigits: isWhole ? 0 : 2,
|
|
609
|
-
maximumFractionDigits: isWhole ? 0 : 2
|
|
610
|
-
}).format(amount);
|
|
611
|
-
return formattedPrice;
|
|
612
|
-
}
|
|
613
|
-
};
|
|
614
|
-
var helpers_default = Helpers;
|
|
615
|
-
|
|
616
521
|
// src/products/index.ts
|
|
617
522
|
var Products = class {
|
|
618
523
|
apiClient;
|
|
@@ -642,6 +547,9 @@ var Products = class {
|
|
|
642
547
|
};
|
|
643
548
|
var products_default = Products;
|
|
644
549
|
|
|
550
|
+
// src/types.ts
|
|
551
|
+
import { formatCurrency, formatPrice } from "@betterstore/bridge";
|
|
552
|
+
|
|
645
553
|
// src/index.ts
|
|
646
554
|
function createBetterStore(config) {
|
|
647
555
|
if (!config.apiKey) {
|
|
@@ -659,11 +567,9 @@ function createBetterStore(config) {
|
|
|
659
567
|
function createStoreClient(config) {
|
|
660
568
|
return new client_default(config?.proxy);
|
|
661
569
|
}
|
|
662
|
-
function createStoreHelpers(config) {
|
|
663
|
-
return new helpers_default(config?.proxy);
|
|
664
|
-
}
|
|
665
570
|
export {
|
|
666
571
|
createStoreClient,
|
|
667
|
-
|
|
668
|
-
|
|
572
|
+
createBetterStore as default,
|
|
573
|
+
formatCurrency,
|
|
574
|
+
formatPrice
|
|
669
575
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterstore/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@betterstore/typescript-config": "0.0.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@betterstore/bridge": "^0.0.
|
|
21
|
+
"@betterstore/bridge": "^0.0.23",
|
|
22
22
|
"axios": "^1.8.2",
|
|
23
23
|
"zod": "^3.24.2"
|
|
24
24
|
},
|