@betterstore/sdk 0.6.3 → 0.6.4
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 +40 -7
- package/dist/index.d.ts +40 -7
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
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
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';
|
|
3
3
|
import axios from 'axios';
|
|
4
|
+
import * as _betterstore_bridge_generated_prisma_client from '@betterstore/bridge/generated/prisma/client';
|
|
4
5
|
|
|
5
6
|
declare const createApiClient: (apiKey: string, proxy?: string) => axios.AxiosInstance;
|
|
6
7
|
|
|
@@ -132,12 +133,13 @@ type FormatResponseForSDK<T extends object> = keyof T extends [
|
|
|
132
133
|
string,
|
|
133
134
|
...string[]
|
|
134
135
|
] ? T : T[keyof T];
|
|
136
|
+
type FormatParamsForSDK<GenericType, ConstraintType> = GenericType & Record<Exclude<keyof GenericType, keyof ConstraintType>, never>;
|
|
135
137
|
|
|
136
138
|
declare class Collections {
|
|
137
139
|
private apiClient;
|
|
138
140
|
constructor(apiKey: string, proxy?: string);
|
|
139
|
-
list<T extends ListCollectionsParams>(params?: T): Promise<FormatResponseForSDK<ListCollectionsResponse<T>>>;
|
|
140
|
-
retrieve<T extends RetrieveCollectionParams>(params: T): Promise<FormatResponseForSDK<RetrieveCollectionResponse<T>> | null>;
|
|
141
|
+
list<T extends ListCollectionsParams>(params?: FormatParamsForSDK<T, ListCollectionsParams>): Promise<FormatResponseForSDK<ListCollectionsResponse<T>>>;
|
|
142
|
+
retrieve<T extends RetrieveCollectionParams>(params: FormatParamsForSDK<T, RetrieveCollectionParams>): Promise<FormatResponseForSDK<RetrieveCollectionResponse<T>> | null>;
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
declare class Customer {
|
|
@@ -168,15 +170,15 @@ declare class Customer {
|
|
|
168
170
|
declare class Discounts {
|
|
169
171
|
private apiClient;
|
|
170
172
|
constructor(apiKey: string, proxy?: string);
|
|
171
|
-
list<T extends ListDiscountsParams>(params?: T): Promise<FormatResponseForSDK<ListDiscountsResponse>>;
|
|
172
|
-
retrieve<T extends RetrieveDiscountParams>(params: T): Promise<FormatResponseForSDK<RetrieveDiscountResponse> | null>;
|
|
173
|
+
list<T extends ListDiscountsParams>(params?: FormatParamsForSDK<T, ListDiscountsParams>): Promise<FormatResponseForSDK<ListDiscountsResponse>>;
|
|
174
|
+
retrieve<T extends RetrieveDiscountParams>(params: FormatParamsForSDK<T, RetrieveDiscountParams>): Promise<FormatResponseForSDK<RetrieveDiscountResponse> | null>;
|
|
173
175
|
}
|
|
174
176
|
|
|
175
177
|
declare class Products {
|
|
176
178
|
private apiClient;
|
|
177
179
|
constructor(apiKey: string, proxy?: string);
|
|
178
|
-
list<T extends ListProductsParams>(params?: T): Promise<FormatResponseForSDK<ListProductsResponse<T>>>;
|
|
179
|
-
retrieve<T extends RetrieveProductParams>(params: T): Promise<FormatResponseForSDK<RetrieveProductResponse<T>> | null>;
|
|
180
|
+
list<T extends ListProductsParams>(params?: FormatParamsForSDK<T, ListProductsParams>): Promise<FormatResponseForSDK<ListProductsResponse<T>>>;
|
|
181
|
+
retrieve<T extends RetrieveProductParams>(params: FormatParamsForSDK<T, RetrieveProductParams>): Promise<FormatResponseForSDK<RetrieveProductResponse<T>> | null>;
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
type Discount = NonNullable<RetrieveDiscountResponse["discount"]>;
|
|
@@ -185,8 +187,39 @@ declare function findAutomaticProductDiscount({ productId, priceInCents, discoun
|
|
|
185
187
|
priceInCents: number;
|
|
186
188
|
discounts: Discount[];
|
|
187
189
|
}): {
|
|
190
|
+
discount: {
|
|
191
|
+
method: _betterstore_bridge_generated_prisma_client.$Enums.DiscountMethod;
|
|
192
|
+
testmode: boolean;
|
|
193
|
+
id: string;
|
|
194
|
+
createdAt: Date;
|
|
195
|
+
updatedAt: Date;
|
|
196
|
+
expiresAt: Date | null;
|
|
197
|
+
status: _betterstore_bridge_generated_prisma_client.$Enums.DiscountStatus;
|
|
198
|
+
code: string | null;
|
|
199
|
+
title: string | null;
|
|
200
|
+
type: _betterstore_bridge_generated_prisma_client.$Enums.DiscountType;
|
|
201
|
+
value: number;
|
|
202
|
+
valueType: _betterstore_bridge_generated_prisma_client.$Enums.DiscountValueType;
|
|
203
|
+
discountScope: _betterstore_bridge_generated_prisma_client.$Enums.ProductDiscountScope;
|
|
204
|
+
allowedProductIDs: string[];
|
|
205
|
+
allowedCollectionIDs: string[];
|
|
206
|
+
allowedCombinations: _betterstore_bridge_generated_prisma_client.$Enums.DiscountScope[];
|
|
207
|
+
minimumRequirementsType: _betterstore_bridge_generated_prisma_client.$Enums.MinimumRequirementsType;
|
|
208
|
+
minimumRequirementsValue: number | null;
|
|
209
|
+
requiredProductIDs: string[];
|
|
210
|
+
requiredCollectionIDs: string[];
|
|
211
|
+
minimumRequirementsScope: _betterstore_bridge_generated_prisma_client.$Enums.ProductDiscountScope;
|
|
212
|
+
maxUses: number | null;
|
|
213
|
+
maxUsesPerCustomer: number | null;
|
|
214
|
+
maxAllowedProductQuantity: number | null;
|
|
215
|
+
uses: number;
|
|
216
|
+
subscriptionDiscountDurationType: _betterstore_bridge_generated_prisma_client.$Enums.SubscriptionDiscountDurationType;
|
|
217
|
+
subscriptionDiscountDurationValue: number;
|
|
218
|
+
stripeDiscountId: string | null;
|
|
219
|
+
startsAt: Date;
|
|
220
|
+
} | undefined;
|
|
188
221
|
finalPrice: number;
|
|
189
|
-
discountAmount: number
|
|
222
|
+
discountAmount: number;
|
|
190
223
|
originalPrice: number;
|
|
191
224
|
isFree: boolean;
|
|
192
225
|
isDiscounted: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
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
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';
|
|
3
3
|
import axios from 'axios';
|
|
4
|
+
import * as _betterstore_bridge_generated_prisma_client from '@betterstore/bridge/generated/prisma/client';
|
|
4
5
|
|
|
5
6
|
declare const createApiClient: (apiKey: string, proxy?: string) => axios.AxiosInstance;
|
|
6
7
|
|
|
@@ -132,12 +133,13 @@ type FormatResponseForSDK<T extends object> = keyof T extends [
|
|
|
132
133
|
string,
|
|
133
134
|
...string[]
|
|
134
135
|
] ? T : T[keyof T];
|
|
136
|
+
type FormatParamsForSDK<GenericType, ConstraintType> = GenericType & Record<Exclude<keyof GenericType, keyof ConstraintType>, never>;
|
|
135
137
|
|
|
136
138
|
declare class Collections {
|
|
137
139
|
private apiClient;
|
|
138
140
|
constructor(apiKey: string, proxy?: string);
|
|
139
|
-
list<T extends ListCollectionsParams>(params?: T): Promise<FormatResponseForSDK<ListCollectionsResponse<T>>>;
|
|
140
|
-
retrieve<T extends RetrieveCollectionParams>(params: T): Promise<FormatResponseForSDK<RetrieveCollectionResponse<T>> | null>;
|
|
141
|
+
list<T extends ListCollectionsParams>(params?: FormatParamsForSDK<T, ListCollectionsParams>): Promise<FormatResponseForSDK<ListCollectionsResponse<T>>>;
|
|
142
|
+
retrieve<T extends RetrieveCollectionParams>(params: FormatParamsForSDK<T, RetrieveCollectionParams>): Promise<FormatResponseForSDK<RetrieveCollectionResponse<T>> | null>;
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
declare class Customer {
|
|
@@ -168,15 +170,15 @@ declare class Customer {
|
|
|
168
170
|
declare class Discounts {
|
|
169
171
|
private apiClient;
|
|
170
172
|
constructor(apiKey: string, proxy?: string);
|
|
171
|
-
list<T extends ListDiscountsParams>(params?: T): Promise<FormatResponseForSDK<ListDiscountsResponse>>;
|
|
172
|
-
retrieve<T extends RetrieveDiscountParams>(params: T): Promise<FormatResponseForSDK<RetrieveDiscountResponse> | null>;
|
|
173
|
+
list<T extends ListDiscountsParams>(params?: FormatParamsForSDK<T, ListDiscountsParams>): Promise<FormatResponseForSDK<ListDiscountsResponse>>;
|
|
174
|
+
retrieve<T extends RetrieveDiscountParams>(params: FormatParamsForSDK<T, RetrieveDiscountParams>): Promise<FormatResponseForSDK<RetrieveDiscountResponse> | null>;
|
|
173
175
|
}
|
|
174
176
|
|
|
175
177
|
declare class Products {
|
|
176
178
|
private apiClient;
|
|
177
179
|
constructor(apiKey: string, proxy?: string);
|
|
178
|
-
list<T extends ListProductsParams>(params?: T): Promise<FormatResponseForSDK<ListProductsResponse<T>>>;
|
|
179
|
-
retrieve<T extends RetrieveProductParams>(params: T): Promise<FormatResponseForSDK<RetrieveProductResponse<T>> | null>;
|
|
180
|
+
list<T extends ListProductsParams>(params?: FormatParamsForSDK<T, ListProductsParams>): Promise<FormatResponseForSDK<ListProductsResponse<T>>>;
|
|
181
|
+
retrieve<T extends RetrieveProductParams>(params: FormatParamsForSDK<T, RetrieveProductParams>): Promise<FormatResponseForSDK<RetrieveProductResponse<T>> | null>;
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
type Discount = NonNullable<RetrieveDiscountResponse["discount"]>;
|
|
@@ -185,8 +187,39 @@ declare function findAutomaticProductDiscount({ productId, priceInCents, discoun
|
|
|
185
187
|
priceInCents: number;
|
|
186
188
|
discounts: Discount[];
|
|
187
189
|
}): {
|
|
190
|
+
discount: {
|
|
191
|
+
method: _betterstore_bridge_generated_prisma_client.$Enums.DiscountMethod;
|
|
192
|
+
testmode: boolean;
|
|
193
|
+
id: string;
|
|
194
|
+
createdAt: Date;
|
|
195
|
+
updatedAt: Date;
|
|
196
|
+
expiresAt: Date | null;
|
|
197
|
+
status: _betterstore_bridge_generated_prisma_client.$Enums.DiscountStatus;
|
|
198
|
+
code: string | null;
|
|
199
|
+
title: string | null;
|
|
200
|
+
type: _betterstore_bridge_generated_prisma_client.$Enums.DiscountType;
|
|
201
|
+
value: number;
|
|
202
|
+
valueType: _betterstore_bridge_generated_prisma_client.$Enums.DiscountValueType;
|
|
203
|
+
discountScope: _betterstore_bridge_generated_prisma_client.$Enums.ProductDiscountScope;
|
|
204
|
+
allowedProductIDs: string[];
|
|
205
|
+
allowedCollectionIDs: string[];
|
|
206
|
+
allowedCombinations: _betterstore_bridge_generated_prisma_client.$Enums.DiscountScope[];
|
|
207
|
+
minimumRequirementsType: _betterstore_bridge_generated_prisma_client.$Enums.MinimumRequirementsType;
|
|
208
|
+
minimumRequirementsValue: number | null;
|
|
209
|
+
requiredProductIDs: string[];
|
|
210
|
+
requiredCollectionIDs: string[];
|
|
211
|
+
minimumRequirementsScope: _betterstore_bridge_generated_prisma_client.$Enums.ProductDiscountScope;
|
|
212
|
+
maxUses: number | null;
|
|
213
|
+
maxUsesPerCustomer: number | null;
|
|
214
|
+
maxAllowedProductQuantity: number | null;
|
|
215
|
+
uses: number;
|
|
216
|
+
subscriptionDiscountDurationType: _betterstore_bridge_generated_prisma_client.$Enums.SubscriptionDiscountDurationType;
|
|
217
|
+
subscriptionDiscountDurationValue: number;
|
|
218
|
+
stripeDiscountId: string | null;
|
|
219
|
+
startsAt: Date;
|
|
220
|
+
} | undefined;
|
|
188
221
|
finalPrice: number;
|
|
189
|
-
discountAmount: number
|
|
222
|
+
discountAmount: number;
|
|
190
223
|
originalPrice: number;
|
|
191
224
|
isFree: boolean;
|
|
192
225
|
isDiscounted: boolean;
|
package/dist/index.js
CHANGED
|
@@ -612,7 +612,7 @@ function calculateDiscountAmount(originalPrice, discount) {
|
|
|
612
612
|
const isDiscounted = discountValueInCents === 0;
|
|
613
613
|
return {
|
|
614
614
|
finalPrice,
|
|
615
|
-
discountAmount: discountValueInCents,
|
|
615
|
+
discountAmount: discountValueInCents ?? 0,
|
|
616
616
|
originalPrice,
|
|
617
617
|
isFree: isFreeDiscount,
|
|
618
618
|
isDiscounted
|
|
@@ -625,7 +625,7 @@ function findAutomaticProductDiscount({
|
|
|
625
625
|
}) {
|
|
626
626
|
const discount = getHighestDiscount(productId, priceInCents, discounts);
|
|
627
627
|
const result = calculateDiscountAmount(priceInCents, discount);
|
|
628
|
-
return result;
|
|
628
|
+
return { ...result, discount };
|
|
629
629
|
}
|
|
630
630
|
|
|
631
631
|
// src/index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -572,7 +572,7 @@ function calculateDiscountAmount(originalPrice, discount) {
|
|
|
572
572
|
const isDiscounted = discountValueInCents === 0;
|
|
573
573
|
return {
|
|
574
574
|
finalPrice,
|
|
575
|
-
discountAmount: discountValueInCents,
|
|
575
|
+
discountAmount: discountValueInCents ?? 0,
|
|
576
576
|
originalPrice,
|
|
577
577
|
isFree: isFreeDiscount,
|
|
578
578
|
isDiscounted
|
|
@@ -585,7 +585,7 @@ function findAutomaticProductDiscount({
|
|
|
585
585
|
}) {
|
|
586
586
|
const discount = getHighestDiscount(productId, priceInCents, discounts);
|
|
587
587
|
const result = calculateDiscountAmount(priceInCents, discount);
|
|
588
|
-
return result;
|
|
588
|
+
return { ...result, discount };
|
|
589
589
|
}
|
|
590
590
|
|
|
591
591
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterstore/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
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.24",
|
|
22
22
|
"axios": "^1.8.2",
|
|
23
23
|
"zod": "^3.24.2"
|
|
24
24
|
},
|