@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 CHANGED
@@ -1,455 +1,8 @@
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';
1
2
  import axios from 'axios';
2
3
 
3
4
  declare const createApiClient: (apiKey: string, proxy?: string) => axios.AxiosInstance;
4
5
 
5
- interface GetShippingRatesResponse {
6
- [shipmentId: string]: ShippingRate[];
7
- }
8
- type ShippingVendorCarrierType = "zasilkovna";
9
- type ProviderId = "zasilkovna";
10
- type ShippingRate = FixedRate | PlatformCarrierRate | CustomShippingVendorRate | PrebuiltRate;
11
- interface FixedRate {
12
- id: string;
13
- type: "FIXED";
14
- name: string;
15
- description?: string;
16
- priceInCents: number;
17
- }
18
- interface BasePlatformCarrierRate {
19
- id: string;
20
- providerId: ProviderId;
21
- type: "PLATFORM_CARRIER";
22
- platformCarrierSlug: string;
23
- priceInCents: number;
24
- }
25
- interface ZasilkovnaPlatformCarrierRate extends BasePlatformCarrierRate {
26
- providerId: "zasilkovna";
27
- platformCarrierSlug: "bs_platform_zasilkovna";
28
- service: "z_box";
29
- clientSecret: string;
30
- }
31
- type PlatformCarrierRate = ZasilkovnaPlatformCarrierRate;
32
- interface BaseCustomShippingVendorRate {
33
- id: string;
34
- providerId: ProviderId;
35
- type: "CUSTOM_SHIPPING_VENDOR";
36
- shippingVendorCarrierType: ShippingVendorCarrierType;
37
- priceInCents: number;
38
- }
39
- interface ZasilkovnaCustomShippingVendorRate extends BaseCustomShippingVendorRate {
40
- providerId: "zasilkovna";
41
- shippingVendorCarrierType: Extract<ShippingVendorCarrierType, "zasilkovna">;
42
- service: "z_box";
43
- clientSecret: string;
44
- }
45
- type CustomShippingVendorRate = ZasilkovnaCustomShippingVendorRate;
46
- type PrebuiltRateType = "PICKUP_IN_STORE" | "LOCAL_DELIVERY";
47
- interface BasePrebuiltRate {
48
- id: string;
49
- type: "PREBUILT";
50
- prebuiltRateType: PrebuiltRateType;
51
- priceInCents: number;
52
- }
53
- interface PrebuildPickupInStoreRate extends BasePrebuiltRate {
54
- prebuiltRateType: Extract<PrebuiltRateType, "PICKUP_IN_STORE">;
55
- expectedPickupDateInHours: number;
56
- }
57
- interface PrebuiltLocalDeliveryRate extends BasePrebuiltRate {
58
- prebuiltRateType: Extract<PrebuiltRateType, "LOCAL_DELIVERY">;
59
- }
60
- type PrebuiltRate = PrebuildPickupInStoreRate | PrebuiltLocalDeliveryRate;
61
-
62
- type ProductData = Pick<Product, "title" | "description" | "images" | "category" | "tags" | "sku" | "barcode" | "vendor" | "isPhysical" | "weightInGrams" | "heightInCm" | "widthInCm" | "lengthInCm" | "priceInCents" | "billingType" | "billingInterval" | "billingIntervalCount"> & {
63
- productId: string;
64
- selectedVariant: Pick<ProductVariant, "title" | "description" | "sku" | "barcode" | "images" | "isPhysical" | "weightInGrams" | "heightInCm" | "widthInCm" | "lengthInCm" | "priceInCents" | "billingType" | "billingInterval" | "billingIntervalCount" | "variantOptions" | "metadata">;
65
- };
66
- interface LineItem {
67
- quantity: number;
68
- variantOptions: {
69
- name: string;
70
- value: string;
71
- }[];
72
- productData: ProductData;
73
- metadata?: string;
74
- }
75
- interface LineItemCreate extends Omit<LineItem, "productData" | "product" | "metadata" | "variantOptions"> {
76
- variantOptions?: {
77
- name: string;
78
- value: string;
79
- }[];
80
- productId: string;
81
- product?: ProductWithoutVariants;
82
- metadata?: Record<string, any>;
83
- }
84
- type Currency = string;
85
- interface CheckoutCreateParams {
86
- type: "hosted" | "embed";
87
- customerId?: string;
88
- lineItems: LineItemCreate[];
89
- currency?: Currency;
90
- discountCodes?: string[];
91
- }
92
- interface CheckoutUpdateParams {
93
- customerId?: string;
94
- shipments?: CheckoutShipment[];
95
- }
96
-
97
- type ShipmentData = {
98
- rateId: string;
99
- providerId?: string;
100
- priceInCents: number;
101
- pickupPointId?: string;
102
- trackingId?: string;
103
- trackingUrl?: string;
104
- };
105
- type CheckoutShipment = {
106
- id: string;
107
- shipmentData?: ShipmentData | null;
108
- };
109
- interface CheckoutSession {
110
- id: string;
111
- testmode: boolean;
112
- clientSecret: string;
113
- customer?: {
114
- id: string;
115
- address?: Address;
116
- email?: string;
117
- };
118
- lineItems: LineItem[];
119
- tax: number | null;
120
- discountAmount: number | null;
121
- appliedDiscounts: {
122
- id: string;
123
- amount: number;
124
- allowedLineItems: {
125
- productId: string;
126
- quantity: number;
127
- }[];
128
- discount: Discount;
129
- }[];
130
- currency: string;
131
- exchangeRate: number | null;
132
- shipments: CheckoutShipment[];
133
- status: "IN_PROGRESS" | "PAYMENT_PENDING" | "ABANDONED" | "CANCELED" | "FAILED";
134
- }
135
-
136
- type AutosuggestAddressResult = {
137
- id: string;
138
- title: string;
139
- address: {
140
- label: string;
141
- };
142
- position: {
143
- lat: number;
144
- lng: number;
145
- };
146
- };
147
- type LookupAddressResult = {
148
- id: string;
149
- title: string;
150
- address: Pick<Address, "line1" | "city" | "province" | "provinceCode" | "country" | "countryCode" | "zipCode">;
151
- };
152
-
153
- type SortOrder = "asc" | "desc";
154
- type GetListParams<A, B> = {
155
- sortBy?: A;
156
- sortOrder?: SortOrder;
157
- query?: B & {
158
- NOT?: B | B[];
159
- OR?: B[];
160
- };
161
- };
162
- type EnumQueryType<T> = {
163
- equals?: T;
164
- in?: T[];
165
- not?: T;
166
- notIn?: T[];
167
- };
168
- type StringArrayQueryType<T = string> = {
169
- equals?: T[];
170
- has?: T;
171
- hasEvery?: T[];
172
- hasSome?: T[];
173
- isEmpty?: boolean;
174
- };
175
- type DateQueryType = {
176
- equals?: Date;
177
- in?: Date[];
178
- not?: Date;
179
- notIn?: Date[];
180
- gt?: Date;
181
- gte?: Date;
182
- lt?: Date;
183
- lte?: Date;
184
- };
185
- type OptionalDateQueryType = DateQueryType & {
186
- isSet: boolean;
187
- };
188
- type ArrayModelQueryType<T> = {
189
- some?: T;
190
- every?: T;
191
- none?: T;
192
- };
193
-
194
- interface VariantOption {
195
- name: string;
196
- value: string;
197
- }
198
- interface ProductVariant {
199
- title: string;
200
- description?: string;
201
- images: string[];
202
- sku?: string;
203
- barcode?: string;
204
- inventoryItem: {
205
- stockPolicy: "CONTINUE" | "DENY";
206
- trackInventory: boolean;
207
- };
208
- isPhysical: boolean;
209
- weightInGrams?: number;
210
- heightInCm?: number;
211
- widthInCm?: number;
212
- lengthInCm?: number;
213
- priceInCents: number;
214
- billingType: ProductBillingType;
215
- billingInterval: ProductBillingInterval;
216
- billingIntervalCount: number;
217
- metadata?: Record<string, any>;
218
- variantOptions: VariantOption[];
219
- }
220
- interface ProductOption {
221
- name: string;
222
- values: string[];
223
- }
224
- type ProductStatus = "DRAFT" | "ACTIVE" | "ARCHIVED";
225
- type ProductBillingInterval = "DAY" | "WEEK" | "MONTH" | "YEAR";
226
- type ProductBillingType = "ONE_TIME" | "SUBSCRIPTION";
227
- interface Product {
228
- id: string;
229
- createdAt: Date;
230
- updatedAt: Date;
231
- title: string;
232
- description?: string;
233
- images: string[];
234
- category: string;
235
- tags: string[];
236
- isPhysical: boolean;
237
- weightInGrams?: number;
238
- heightInCm?: number;
239
- widthInCm?: number;
240
- lengthInCm?: number;
241
- priceInCents: number;
242
- billingType: ProductBillingType;
243
- billingInterval: ProductBillingInterval;
244
- billingIntervalCount: number;
245
- sku?: string;
246
- barcode?: string;
247
- inventoryItem: {
248
- stockPolicy: "CONTINUE" | "DENY";
249
- trackInventory: boolean;
250
- };
251
- seoPageTitle?: string;
252
- seoDescription?: string;
253
- seoHandle?: string;
254
- vendor?: string;
255
- metadata?: Record<string, any>;
256
- status: ProductStatus;
257
- options: ProductOption[];
258
- productVariants: ProductVariant[];
259
- }
260
- interface ProductWithoutVariants extends Omit<Product, "productVariants"> {
261
- }
262
- type ListProductsQuery = {
263
- collectionIDs?: StringArrayQueryType;
264
- collections?: ArrayModelQueryType<{
265
- seoHandle?: StringArrayQueryType;
266
- }>;
267
- tags?: StringArrayQueryType;
268
- createdAt?: DateQueryType;
269
- updatedAt?: DateQueryType;
270
- };
271
- type ListProductsSortBy = "createdAt" | "updatedAt" | "title" | "priceInCents";
272
- type ListProductsParams = GetListParams<ListProductsSortBy, ListProductsQuery>;
273
- type RetrieveProductParams = {
274
- seoHandle: string;
275
- } | {
276
- id: string;
277
- };
278
-
279
- interface Collection {
280
- id: string;
281
- title: string;
282
- description?: string;
283
- images: string[];
284
- tags: string[];
285
- seoPageTitle?: string;
286
- seoDescription?: string;
287
- seoHandle?: string;
288
- }
289
- interface CollectionWithProducts extends Collection {
290
- products: ProductWithoutVariants[];
291
- }
292
- type ListCollectionsQuery = undefined;
293
- type ListCollectionsSortBy = "createdAt" | "updatedAt" | "title";
294
- type ListCollectionsParams = GetListParams<ListCollectionsSortBy, ListCollectionsQuery>;
295
- type RetrieveCollectionParams = {
296
- seoHandle: string;
297
- } | {
298
- id: string;
299
- };
300
-
301
- type Address = {
302
- name: string;
303
- phone: string;
304
- line1: string;
305
- line2?: string;
306
- city: string;
307
- province?: string;
308
- provinceCode?: string;
309
- country: string;
310
- countryCode: string;
311
- zipCode: string;
312
- };
313
- interface CustomerCreateParams {
314
- firstName?: string;
315
- lastName?: string;
316
- email: string;
317
- phone?: string;
318
- address?: Address;
319
- image?: string;
320
- password?: string;
321
- metadata?: Record<string, any>;
322
- tags?: string[];
323
- notes?: string;
324
- isSubscribedEmail?: boolean;
325
- isSubscribedSMS?: boolean;
326
- }
327
- interface CustomerUpdateParams extends Omit<CustomerCreateParams, "email"> {
328
- email?: string;
329
- }
330
- interface Customer$1 extends CustomerCreateParams {
331
- id: string;
332
- createdAt: string;
333
- updatedAt: string;
334
- }
335
- interface CustomerSubscription {
336
- cancelAtPeriodEnd: boolean;
337
- }
338
- type CustomerSubscriptionUpdateParams = Partial<Pick<CustomerSubscription, "cancelAtPeriodEnd">>;
339
-
340
- interface Discount {
341
- id: string;
342
- createdAt: Date;
343
- updatedAt: Date;
344
- type: "AMOUNT_OFF_PRODUCTS" | "BUY_X_GET_Y" | "AMOUNT_OFF_ORDER" | "FREE_SHIPPING";
345
- method: "CODE" | "AUTOMATIC";
346
- code?: string | null;
347
- title?: string | null;
348
- value: number;
349
- valueType: "PERCENTAGE" | "FIXED_AMOUNT" | "FREE";
350
- discountScope: "PRODUCTS" | "COLLECTIONS";
351
- allowedProductIDs: string[];
352
- allowedCollectionIDs: string[];
353
- allowedCombinations: ("ORDER" | "PRODUCT" | "SHIPPING")[];
354
- minimumRequirementsType: "NONE" | "MINIMUM_ORDER_AMOUNT" | "MINIMUM_PRODUCT_QUANTITY";
355
- minimumRequirementsValue?: number | null;
356
- requiredProductIDs: string[];
357
- requiredCollectionIDs: string[];
358
- minimumRequirementsScope: "PRODUCTS" | "COLLECTIONS";
359
- maxUses?: number | null;
360
- maxUsesPerCustomer?: number | null;
361
- maxAllowedProductQuantity?: number | null;
362
- uses: number;
363
- subscriptionDiscountDurationType: "ONE_TIME" | "RECURRING" | "FOREVER";
364
- subscriptionDiscountDurationValue: number;
365
- stripeDiscountId?: string | null;
366
- startsAt: Date;
367
- expiresAt?: Date | null;
368
- status: "ACTIVE" | "EXPIRED" | "SCHEDULED";
369
- organizationId: string;
370
- }
371
- type ListDiscountsQuery = {
372
- type?: EnumQueryType<Discount["type"]>;
373
- valueType?: EnumQueryType<Discount["valueType"]>;
374
- method?: EnumQueryType<Discount["method"]>;
375
- status?: EnumQueryType<Discount["status"]>;
376
- minimumRequirementsType?: EnumQueryType<Discount["minimumRequirementsType"]>;
377
- minimumRequirementsScope?: EnumQueryType<Discount["minimumRequirementsScope"]>;
378
- discountScope?: EnumQueryType<Discount["discountScope"]>;
379
- subscriptionDiscountDurationType?: EnumQueryType<Discount["subscriptionDiscountDurationType"]>;
380
- allowedCombinations?: StringArrayQueryType<Discount["allowedCombinations"]>;
381
- allowedProductIDs?: StringArrayQueryType<Discount["allowedProductIDs"]>;
382
- allowedCollectionIDs?: StringArrayQueryType<Discount["allowedCollectionIDs"]>;
383
- requiredProductIDs?: StringArrayQueryType<Discount["requiredProductIDs"]>;
384
- requiredCollectionIDs?: StringArrayQueryType<Discount["requiredCollectionIDs"]>;
385
- startsAt?: DateQueryType;
386
- expiresAt?: OptionalDateQueryType;
387
- createdAt?: DateQueryType;
388
- updatedAt?: DateQueryType;
389
- };
390
- type ListDiscountsSortBy = "createdAt" | "updatedAt" | "expiresAt" | "startsAt";
391
- type ListDiscountsParams = GetListParams<ListDiscountsSortBy, ListDiscountsQuery>;
392
- type RetrieveDiscountParams = {
393
- id: string;
394
- } | {
395
- code: string;
396
- };
397
-
398
- interface CustomerSession {
399
- customerId: string;
400
- expiresAt: Date;
401
- testmode: boolean;
402
- token: string;
403
- customer: {
404
- createdAt: Date;
405
- updatedAt: Date;
406
- firstName: string;
407
- lastName: string;
408
- email: string;
409
- phone?: string;
410
- password?: string;
411
- image?: string;
412
- metadata?: string;
413
- stripeCustomerId: string;
414
- isSubscribedEmail: boolean;
415
- isSubscribedSMS: boolean;
416
- address: Address;
417
- };
418
- }
419
- interface OTPLoginParams {
420
- email: string;
421
- }
422
- interface OTPSignupParams extends CustomerCreateParams {
423
- }
424
- interface OTPVerifyParams {
425
- email: string;
426
- otp: string;
427
- }
428
- type OTPLoginResponse = {
429
- success: true;
430
- token: string;
431
- } | {
432
- success: false;
433
- code: "BAD_REQUEST" | "CUSTOMER_NOT_FOUND";
434
- error: string;
435
- };
436
- type OTPSignupResponse = {
437
- success: true;
438
- token: string;
439
- } | {
440
- success: false;
441
- code: "BAD_REQUEST" | "CUSTOMER_ALREADY_EXISTS";
442
- error: string;
443
- };
444
- type OTPVerifyResponse = {
445
- success: true;
446
- customerSession: CustomerSession;
447
- } | {
448
- success: false;
449
- code: "BAD_REQUEST";
450
- error: string;
451
- };
452
-
453
6
  declare class OTP {
454
7
  private apiClient;
455
8
  constructor(apiClient: ReturnType<typeof createApiClient>);
@@ -532,7 +85,7 @@ declare class Client {
532
85
  /**
533
86
  * Get shipping rates for a checkout session
534
87
  */
535
- getCheckoutShippingRates(clientSecret: string, checkoutId: string): Promise<ShippingRate[]>;
88
+ getCheckoutShippingRates(clientSecret: string, checkoutId: string): Promise<GetShippingRatesResponse>;
536
89
  /**
537
90
  * Generate payment secret for a checkout session
538
91
  */
@@ -544,15 +97,15 @@ declare class Client {
544
97
  /**
545
98
  * Create a new customer
546
99
  */
547
- createCustomer(clientSecret: string, params: CustomerCreateParams): Promise<Customer$1>;
100
+ createCustomer(clientSecret: string, params: CustomerCreateParams): Promise<CustomerResponse>;
548
101
  /**
549
102
  * Retrieve a customer by ID or email
550
103
  */
551
- retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<Customer$1 | null>;
104
+ retrieveCustomer(clientSecret: string, idOrEmail: string): Promise<CustomerResponse | null>;
552
105
  /**
553
106
  * Update a customer
554
107
  */
555
- updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<Customer$1 | null>;
108
+ updateCustomer(clientSecret: string, customerId: string, params: CustomerUpdateParams): Promise<CustomerResponse | null>;
556
109
  /**
557
110
  * Get exchange rate for a currency
558
111
  */
@@ -576,8 +129,8 @@ declare class Client {
576
129
  declare class Collections {
577
130
  private apiClient;
578
131
  constructor(apiKey: string, proxy?: string);
579
- list(params?: ListCollectionsParams): Promise<Collection[]>;
580
- retrieve(params: RetrieveCollectionParams): Promise<CollectionWithProducts | null>;
132
+ list<T extends ListCollectionsParams>(params?: T): Promise<ListCollectionsResponse<T>>;
133
+ retrieve<T extends RetrieveCollectionParams>(params: T): Promise<RetrieveCollectionResponse<T> | null>;
581
134
  }
582
135
 
583
136
  declare class Customer {
@@ -586,15 +139,15 @@ declare class Customer {
586
139
  /**
587
140
  * Create a new customer
588
141
  */
589
- create(params: CustomerCreateParams): Promise<Customer$1>;
142
+ create(params: CustomerCreateParams): Promise<CustomerResponse>;
590
143
  /**
591
144
  * Retrieve a customer by ID or email
592
145
  */
593
- retrieve(idOrEmail: string): Promise<Customer$1 | null>;
146
+ retrieve(idOrEmail: string): Promise<CustomerResponse | null>;
594
147
  /**
595
148
  * Update a customer
596
149
  */
597
- update(customerId: string, params: CustomerUpdateParams): Promise<Customer$1 | null>;
150
+ update(customerId: string, params: CustomerUpdateParams): Promise<CustomerResponse | null>;
598
151
  /**
599
152
  * Delete a customer
600
153
  */
@@ -608,22 +161,15 @@ declare class Customer {
608
161
  declare class Discounts {
609
162
  private apiClient;
610
163
  constructor(apiKey: string, proxy?: string);
611
- list(params?: ListDiscountsParams): Promise<Discount[]>;
612
- retrieve(params: RetrieveDiscountParams): Promise<Discount | null>;
613
- }
614
-
615
- declare class Helpers {
616
- proxy?: string;
617
- constructor(proxy?: string);
618
- formatCurrency(currency: string): string;
619
- formatPrice(priceInCents: number, currency: string, exchangeRate?: number | null): string;
164
+ list<T extends ListDiscountsParams>(params?: T): Promise<ListDiscountsResponse>;
165
+ retrieve<T extends RetrieveDiscountParams>(params: T): Promise<RetrieveDiscountResponse | null>;
620
166
  }
621
167
 
622
168
  declare class Products {
623
169
  private apiClient;
624
170
  constructor(apiKey: string, proxy?: string);
625
- list(params?: ListProductsParams): Promise<ProductWithoutVariants[]>;
626
- retrieve(params: RetrieveProductParams): Promise<Product | null>;
171
+ list<T extends ListProductsParams>(params?: T): Promise<ListProductsResponse<T>>;
172
+ retrieve<T extends RetrieveProductParams>(params: T): Promise<RetrieveProductResponse<T> | null>;
627
173
  }
628
174
 
629
175
  declare function createBetterStore(config: {
@@ -640,8 +186,5 @@ declare function createBetterStore(config: {
640
186
  declare function createStoreClient(config?: {
641
187
  proxy?: string;
642
188
  }): Client;
643
- declare function createStoreHelpers(config?: {
644
- proxy?: string;
645
- }): Helpers;
646
189
 
647
- export { type Address, type AutosuggestAddressResult, type CheckoutCreateParams, type CheckoutSession, type CheckoutUpdateParams, type Collection, type CollectionWithProducts, type Currency, type Customer$1 as Customer, type CustomerCreateParams, type CustomerSession, type CustomerSubscription, type CustomerSubscriptionUpdateParams, type CustomerUpdateParams, type Discount, type GetShippingRatesResponse, type LineItem, type LineItemCreate, type ListCollectionsParams, type ListCollectionsQuery, type ListCollectionsSortBy, type ListDiscountsParams, type ListDiscountsQuery, type ListDiscountsSortBy, type ListProductsParams, type ListProductsQuery, type ListProductsSortBy, type LookupAddressResult, type OTPLoginParams, type OTPLoginResponse, type OTPSignupParams, type OTPSignupResponse, type OTPVerifyParams, type OTPVerifyResponse, type Product, type ProductBillingInterval, type ProductBillingType, type ProductOption, type ProductStatus, type ProductVariant, type ProductWithoutVariants, type RetrieveCollectionParams, type RetrieveDiscountParams, type RetrieveProductParams, type ShippingRate, type VariantOption, createStoreClient, createStoreHelpers, createBetterStore as default };
190
+ export { createStoreClient, createBetterStore as default };