@betterstore/sdk 0.3.48 → 0.3.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @betterstore/sdk
2
2
 
3
+ ## 0.3.50
4
+
5
+ ### Patch Changes
6
+
7
+ - discounts handeling finished
8
+
9
+ ## 0.3.49
10
+
11
+ ### Patch Changes
12
+
13
+ - collection utility functions
14
+
3
15
  ## 0.3.48
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -102,6 +102,9 @@ interface Collection {
102
102
  seoDescription?: string;
103
103
  seoHandle?: string;
104
104
  }
105
+ interface CollectionWithProducts extends Collection {
106
+ products: ProductWithoutVariants[];
107
+ }
105
108
 
106
109
  type ShippingRate = ZasilkovnaRate;
107
110
  interface BaseRate {
@@ -138,6 +141,7 @@ interface CheckoutCreateParams {
138
141
  customerId?: string;
139
142
  lineItems: LineItemCreate[];
140
143
  currency?: Currency;
144
+ discountCode?: string;
141
145
  }
142
146
  interface CheckoutUpdateParams {
143
147
  customerId?: string;
@@ -150,24 +154,61 @@ interface CheckoutUpdateParams {
150
154
  };
151
155
  }
152
156
 
153
- interface CheckoutSession {
157
+ type ShipmentData = {
158
+ provider: string;
159
+ name?: string;
160
+ service?: string;
161
+ pickupPointId?: string;
162
+ trackingId?: string;
163
+ trackingUrl?: string;
164
+ };
165
+ type Discount = {
154
166
  id: string;
155
167
  createdAt: Date;
156
168
  updatedAt: Date;
157
- clientSecret: string;
158
- lineItems: LineItem[];
159
- total?: number;
160
- subtotal?: number;
161
- tax?: number;
162
- shipping?: number;
163
- currency: string;
164
- exchangeRate: number;
165
- status: "IN_PROGRESS" | "PAYMENT_PENDING" | "ABANDONED" | "CANCELED" | "FAILED";
169
+ type: "AMOUNT_OFF_PRODUCTS" | "BUY_X_GET_Y" | "AMOUNT_OFF_ORDER" | "FREE_SHIPPING";
170
+ method: "CODE" | "AUTOMATIC";
171
+ code?: string | null;
172
+ title?: string | null;
173
+ value: number;
174
+ valueType: "PERCENTAGE" | "FIXED_AMOUNT" | "FREE";
175
+ discountScope: "PRODUCTS" | "COLLECTIONS";
176
+ allowedProductIDs: string[];
177
+ allowedCollectionIDs: string[];
178
+ allowedCombinations: ("ORDER" | "PRODUCT" | "SHIPPING")[];
179
+ minimumRequirementsType: "NONE" | "MINIMUM_ORDER_AMOUNT" | "MINIMUM_PRODUCT_QUANTITY";
180
+ minimumRequirementsValue?: number | null;
181
+ requiredProductIDs: string[];
182
+ requiredCollectionIDs: string[];
183
+ minimumRequirementsScope: "PRODUCTS" | "COLLECTIONS";
184
+ maxUses?: number | null;
185
+ maxUsesPerCustomer?: number | null;
186
+ maxAllowedProductQuantity?: number | null;
187
+ uses: number;
188
+ startsAt: Date;
189
+ expiresAt?: Date | null;
190
+ status: "ACTIVE" | "EXPIRED" | "SCHEDULED";
191
+ organizationId: string;
192
+ };
193
+ interface CheckoutSession {
194
+ id: string;
195
+ testmode: boolean;
166
196
  customer?: {
167
197
  id: string;
168
198
  address?: Address;
169
199
  email?: string;
170
200
  };
201
+ lineItems: LineItem[];
202
+ tax: number | null;
203
+ shipping: number | null;
204
+ discountAmount: number | null;
205
+ appliedDiscounts: {
206
+ discount: Discount;
207
+ }[];
208
+ currency: string;
209
+ exchangeRate: number | null;
210
+ shipmentData: ShipmentData | null;
211
+ status: "IN_PROGRESS" | "PAYMENT_PENDING" | "ABANDONED" | "CANCELED" | "FAILED";
171
212
  }
172
213
  type RecursiveRecord = {
173
214
  [key: string]: any;
@@ -188,6 +229,14 @@ declare class Checkout {
188
229
  * Update a checkout session
189
230
  */
190
231
  update(checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
232
+ /**
233
+ * Update a checkout session
234
+ */
235
+ applyDiscountCode(checkoutId: string, discountCode: string): Promise<CheckoutSession>;
236
+ /**
237
+ * Update a checkout session
238
+ */
239
+ revalidateDiscounts(checkoutId: string): Promise<CheckoutSession>;
191
240
  /**
192
241
  * Get shipping rates for a checkout session
193
242
  */
@@ -212,6 +261,14 @@ declare class Client {
212
261
  * Update a checkout session
213
262
  */
214
263
  updateCheckout(clientSecret: string, checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
264
+ /**
265
+ * Update a checkout session
266
+ */
267
+ applyDiscountCode(clientSecret: string, checkoutId: string, discountCode: string): Promise<CheckoutSession>;
268
+ /**
269
+ * Update a checkout session
270
+ */
271
+ revalidateDiscounts(clientSecret: string, checkoutId: string): Promise<CheckoutSession>;
215
272
  /**
216
273
  * Get shipping rates for a checkout session
217
274
  */
@@ -272,6 +329,8 @@ declare class Products {
272
329
  list(): Promise<ProductWithoutVariants[]>;
273
330
  retrieve(productId: string): Promise<Product | null>;
274
331
  listCollections(): Promise<Collection[]>;
332
+ retrieveCollectionBySeoHandle(collectionSeoHandle: string): Promise<CollectionWithProducts>;
333
+ retrieveCollectionById(collectionId: string): Promise<CollectionWithProducts>;
275
334
  }
276
335
 
277
336
  declare function createBetterStore(config: {
@@ -289,4 +348,4 @@ declare function createStoreHelpers(config?: {
289
348
  proxy?: string;
290
349
  }): Helpers;
291
350
 
292
- export { type Address, type CheckoutCreateParams, type CheckoutSession, type CheckoutUpdateParams, type Collection, type Currency, type Customer$1 as Customer, type CustomerCreateParams, type CustomerUpdateParams, type LineItem, type LineItemCreate, type Product, type ProductOption, ProductStatus, type ProductVariant, type ProductWithoutVariants, type ShippingRate, type VariantOption, createStoreClient, createStoreHelpers, createBetterStore as default };
351
+ export { type Address, type CheckoutCreateParams, type CheckoutSession, type CheckoutUpdateParams, type Collection, type CollectionWithProducts, type Currency, type Customer$1 as Customer, type CustomerCreateParams, type CustomerUpdateParams, type LineItem, type LineItemCreate, type Product, type ProductOption, ProductStatus, type ProductVariant, type ProductWithoutVariants, type ShippingRate, type VariantOption, createStoreClient, createStoreHelpers, createBetterStore as default };
package/dist/index.d.ts CHANGED
@@ -102,6 +102,9 @@ interface Collection {
102
102
  seoDescription?: string;
103
103
  seoHandle?: string;
104
104
  }
105
+ interface CollectionWithProducts extends Collection {
106
+ products: ProductWithoutVariants[];
107
+ }
105
108
 
106
109
  type ShippingRate = ZasilkovnaRate;
107
110
  interface BaseRate {
@@ -138,6 +141,7 @@ interface CheckoutCreateParams {
138
141
  customerId?: string;
139
142
  lineItems: LineItemCreate[];
140
143
  currency?: Currency;
144
+ discountCode?: string;
141
145
  }
142
146
  interface CheckoutUpdateParams {
143
147
  customerId?: string;
@@ -150,24 +154,61 @@ interface CheckoutUpdateParams {
150
154
  };
151
155
  }
152
156
 
153
- interface CheckoutSession {
157
+ type ShipmentData = {
158
+ provider: string;
159
+ name?: string;
160
+ service?: string;
161
+ pickupPointId?: string;
162
+ trackingId?: string;
163
+ trackingUrl?: string;
164
+ };
165
+ type Discount = {
154
166
  id: string;
155
167
  createdAt: Date;
156
168
  updatedAt: Date;
157
- clientSecret: string;
158
- lineItems: LineItem[];
159
- total?: number;
160
- subtotal?: number;
161
- tax?: number;
162
- shipping?: number;
163
- currency: string;
164
- exchangeRate: number;
165
- status: "IN_PROGRESS" | "PAYMENT_PENDING" | "ABANDONED" | "CANCELED" | "FAILED";
169
+ type: "AMOUNT_OFF_PRODUCTS" | "BUY_X_GET_Y" | "AMOUNT_OFF_ORDER" | "FREE_SHIPPING";
170
+ method: "CODE" | "AUTOMATIC";
171
+ code?: string | null;
172
+ title?: string | null;
173
+ value: number;
174
+ valueType: "PERCENTAGE" | "FIXED_AMOUNT" | "FREE";
175
+ discountScope: "PRODUCTS" | "COLLECTIONS";
176
+ allowedProductIDs: string[];
177
+ allowedCollectionIDs: string[];
178
+ allowedCombinations: ("ORDER" | "PRODUCT" | "SHIPPING")[];
179
+ minimumRequirementsType: "NONE" | "MINIMUM_ORDER_AMOUNT" | "MINIMUM_PRODUCT_QUANTITY";
180
+ minimumRequirementsValue?: number | null;
181
+ requiredProductIDs: string[];
182
+ requiredCollectionIDs: string[];
183
+ minimumRequirementsScope: "PRODUCTS" | "COLLECTIONS";
184
+ maxUses?: number | null;
185
+ maxUsesPerCustomer?: number | null;
186
+ maxAllowedProductQuantity?: number | null;
187
+ uses: number;
188
+ startsAt: Date;
189
+ expiresAt?: Date | null;
190
+ status: "ACTIVE" | "EXPIRED" | "SCHEDULED";
191
+ organizationId: string;
192
+ };
193
+ interface CheckoutSession {
194
+ id: string;
195
+ testmode: boolean;
166
196
  customer?: {
167
197
  id: string;
168
198
  address?: Address;
169
199
  email?: string;
170
200
  };
201
+ lineItems: LineItem[];
202
+ tax: number | null;
203
+ shipping: number | null;
204
+ discountAmount: number | null;
205
+ appliedDiscounts: {
206
+ discount: Discount;
207
+ }[];
208
+ currency: string;
209
+ exchangeRate: number | null;
210
+ shipmentData: ShipmentData | null;
211
+ status: "IN_PROGRESS" | "PAYMENT_PENDING" | "ABANDONED" | "CANCELED" | "FAILED";
171
212
  }
172
213
  type RecursiveRecord = {
173
214
  [key: string]: any;
@@ -188,6 +229,14 @@ declare class Checkout {
188
229
  * Update a checkout session
189
230
  */
190
231
  update(checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
232
+ /**
233
+ * Update a checkout session
234
+ */
235
+ applyDiscountCode(checkoutId: string, discountCode: string): Promise<CheckoutSession>;
236
+ /**
237
+ * Update a checkout session
238
+ */
239
+ revalidateDiscounts(checkoutId: string): Promise<CheckoutSession>;
191
240
  /**
192
241
  * Get shipping rates for a checkout session
193
242
  */
@@ -212,6 +261,14 @@ declare class Client {
212
261
  * Update a checkout session
213
262
  */
214
263
  updateCheckout(clientSecret: string, checkoutId: string, params: CheckoutUpdateParams): Promise<CheckoutSession>;
264
+ /**
265
+ * Update a checkout session
266
+ */
267
+ applyDiscountCode(clientSecret: string, checkoutId: string, discountCode: string): Promise<CheckoutSession>;
268
+ /**
269
+ * Update a checkout session
270
+ */
271
+ revalidateDiscounts(clientSecret: string, checkoutId: string): Promise<CheckoutSession>;
215
272
  /**
216
273
  * Get shipping rates for a checkout session
217
274
  */
@@ -272,6 +329,8 @@ declare class Products {
272
329
  list(): Promise<ProductWithoutVariants[]>;
273
330
  retrieve(productId: string): Promise<Product | null>;
274
331
  listCollections(): Promise<Collection[]>;
332
+ retrieveCollectionBySeoHandle(collectionSeoHandle: string): Promise<CollectionWithProducts>;
333
+ retrieveCollectionById(collectionId: string): Promise<CollectionWithProducts>;
275
334
  }
276
335
 
277
336
  declare function createBetterStore(config: {
@@ -289,4 +348,4 @@ declare function createStoreHelpers(config?: {
289
348
  proxy?: string;
290
349
  }): Helpers;
291
350
 
292
- export { type Address, type CheckoutCreateParams, type CheckoutSession, type CheckoutUpdateParams, type Collection, type Currency, type Customer$1 as Customer, type CustomerCreateParams, type CustomerUpdateParams, type LineItem, type LineItemCreate, type Product, type ProductOption, ProductStatus, type ProductVariant, type ProductWithoutVariants, type ShippingRate, type VariantOption, createStoreClient, createStoreHelpers, createBetterStore as default };
351
+ export { type Address, type CheckoutCreateParams, type CheckoutSession, type CheckoutUpdateParams, type Collection, type CollectionWithProducts, type Currency, type Customer$1 as Customer, type CustomerCreateParams, type CustomerUpdateParams, type LineItem, type LineItemCreate, type Product, type ProductOption, ProductStatus, type ProductVariant, type ProductWithoutVariants, type ShippingRate, type VariantOption, createStoreClient, createStoreHelpers, createBetterStore as default };
package/dist/index.js CHANGED
@@ -163,6 +163,29 @@ var Checkout = class {
163
163
  return data;
164
164
  });
165
165
  }
166
+ /**
167
+ * Update a checkout session
168
+ */
169
+ applyDiscountCode(checkoutId, discountCode) {
170
+ return __async(this, null, function* () {
171
+ const data = yield this.apiClient.post(
172
+ `/checkout/${checkoutId}/discount`,
173
+ { code: discountCode }
174
+ );
175
+ return data;
176
+ });
177
+ }
178
+ /**
179
+ * Update a checkout session
180
+ */
181
+ revalidateDiscounts(checkoutId) {
182
+ return __async(this, null, function* () {
183
+ const data = yield this.apiClient.get(
184
+ `/checkout/${checkoutId}/revalidate-discounts`
185
+ );
186
+ return data;
187
+ });
188
+ }
166
189
  /**
167
190
  * Get shipping rates for a checkout session
168
191
  */
@@ -220,6 +243,31 @@ var Client = class {
220
243
  return data;
221
244
  });
222
245
  }
246
+ /**
247
+ * Update a checkout session
248
+ */
249
+ applyDiscountCode(clientSecret, checkoutId, discountCode) {
250
+ return __async(this, null, function* () {
251
+ const apiClient = createApiClient(clientSecret, this.proxy);
252
+ const data = yield apiClient.post(
253
+ `/checkout/${checkoutId}/discount`,
254
+ { code: discountCode }
255
+ );
256
+ return data;
257
+ });
258
+ }
259
+ /**
260
+ * Update a checkout session
261
+ */
262
+ revalidateDiscounts(clientSecret, checkoutId) {
263
+ return __async(this, null, function* () {
264
+ const apiClient = createApiClient(clientSecret, this.proxy);
265
+ const data = yield apiClient.get(
266
+ `/checkout/${checkoutId}/revalidate-discounts`
267
+ );
268
+ return data;
269
+ });
270
+ }
223
271
  /**
224
272
  * Get shipping rates for a checkout session
225
273
  */
@@ -469,6 +517,22 @@ var Products = class {
469
517
  return data;
470
518
  });
471
519
  }
520
+ retrieveCollectionBySeoHandle(collectionSeoHandle) {
521
+ return __async(this, null, function* () {
522
+ const data = yield this.apiClient.get(
523
+ `/collections/${collectionSeoHandle}`
524
+ );
525
+ return data;
526
+ });
527
+ }
528
+ retrieveCollectionById(collectionId) {
529
+ return __async(this, null, function* () {
530
+ const data = yield this.apiClient.get(
531
+ `/collections/id/${collectionId}`
532
+ );
533
+ return data;
534
+ });
535
+ }
472
536
  };
473
537
  var products_default = Products;
474
538
 
package/dist/index.mjs CHANGED
@@ -127,6 +127,29 @@ var Checkout = class {
127
127
  return data;
128
128
  });
129
129
  }
130
+ /**
131
+ * Update a checkout session
132
+ */
133
+ applyDiscountCode(checkoutId, discountCode) {
134
+ return __async(this, null, function* () {
135
+ const data = yield this.apiClient.post(
136
+ `/checkout/${checkoutId}/discount`,
137
+ { code: discountCode }
138
+ );
139
+ return data;
140
+ });
141
+ }
142
+ /**
143
+ * Update a checkout session
144
+ */
145
+ revalidateDiscounts(checkoutId) {
146
+ return __async(this, null, function* () {
147
+ const data = yield this.apiClient.get(
148
+ `/checkout/${checkoutId}/revalidate-discounts`
149
+ );
150
+ return data;
151
+ });
152
+ }
130
153
  /**
131
154
  * Get shipping rates for a checkout session
132
155
  */
@@ -184,6 +207,31 @@ var Client = class {
184
207
  return data;
185
208
  });
186
209
  }
210
+ /**
211
+ * Update a checkout session
212
+ */
213
+ applyDiscountCode(clientSecret, checkoutId, discountCode) {
214
+ return __async(this, null, function* () {
215
+ const apiClient = createApiClient(clientSecret, this.proxy);
216
+ const data = yield apiClient.post(
217
+ `/checkout/${checkoutId}/discount`,
218
+ { code: discountCode }
219
+ );
220
+ return data;
221
+ });
222
+ }
223
+ /**
224
+ * Update a checkout session
225
+ */
226
+ revalidateDiscounts(clientSecret, checkoutId) {
227
+ return __async(this, null, function* () {
228
+ const apiClient = createApiClient(clientSecret, this.proxy);
229
+ const data = yield apiClient.get(
230
+ `/checkout/${checkoutId}/revalidate-discounts`
231
+ );
232
+ return data;
233
+ });
234
+ }
187
235
  /**
188
236
  * Get shipping rates for a checkout session
189
237
  */
@@ -433,6 +481,22 @@ var Products = class {
433
481
  return data;
434
482
  });
435
483
  }
484
+ retrieveCollectionBySeoHandle(collectionSeoHandle) {
485
+ return __async(this, null, function* () {
486
+ const data = yield this.apiClient.get(
487
+ `/collections/${collectionSeoHandle}`
488
+ );
489
+ return data;
490
+ });
491
+ }
492
+ retrieveCollectionById(collectionId) {
493
+ return __async(this, null, function* () {
494
+ const data = yield this.apiClient.get(
495
+ `/collections/id/${collectionId}`
496
+ );
497
+ return data;
498
+ });
499
+ }
436
500
  };
437
501
  var products_default = Products;
438
502
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterstore/sdk",
3
- "version": "0.3.48",
3
+ "version": "0.3.50",
4
4
  "description": "E-commerce for Developers",
5
5
  "private": false,
6
6
  "publishConfig": {