@shoppexio/storefront 0.3.0 → 0.3.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/CHANGELOG.md +5 -0
- package/README.md +1 -1
- package/dist/index.cjs +7 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -31,6 +31,7 @@ interface ApiResponse<T> {
|
|
|
31
31
|
status: number;
|
|
32
32
|
data: T;
|
|
33
33
|
error: string | null;
|
|
34
|
+
message?: string | null;
|
|
34
35
|
}
|
|
35
36
|
interface SDKResponse<T> {
|
|
36
37
|
success: boolean;
|
|
@@ -382,6 +383,7 @@ interface CouponValidationOptions {
|
|
|
382
383
|
}
|
|
383
384
|
interface AffiliateValidation {
|
|
384
385
|
valid: boolean;
|
|
386
|
+
program_enabled?: boolean;
|
|
385
387
|
affiliate_code: string | null;
|
|
386
388
|
discount_active: boolean;
|
|
387
389
|
discount_percent: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ interface ApiResponse<T> {
|
|
|
31
31
|
status: number;
|
|
32
32
|
data: T;
|
|
33
33
|
error: string | null;
|
|
34
|
+
message?: string | null;
|
|
34
35
|
}
|
|
35
36
|
interface SDKResponse<T> {
|
|
36
37
|
success: boolean;
|
|
@@ -382,6 +383,7 @@ interface CouponValidationOptions {
|
|
|
382
383
|
}
|
|
383
384
|
interface AffiliateValidation {
|
|
384
385
|
valid: boolean;
|
|
386
|
+
program_enabled?: boolean;
|
|
385
387
|
affiliate_code: string | null;
|
|
386
388
|
discount_active: boolean;
|
|
387
389
|
discount_percent: number;
|
package/dist/index.js
CHANGED
|
@@ -8695,12 +8695,13 @@ function mapApiResponse(apiResponse) {
|
|
|
8695
8695
|
if (apiResponse.status >= 200 && apiResponse.status < 300) {
|
|
8696
8696
|
return {
|
|
8697
8697
|
success: true,
|
|
8698
|
-
data: apiResponse.data
|
|
8698
|
+
data: apiResponse.data,
|
|
8699
|
+
...apiResponse.message ? { message: apiResponse.message } : {}
|
|
8699
8700
|
};
|
|
8700
8701
|
}
|
|
8701
8702
|
return {
|
|
8702
8703
|
success: false,
|
|
8703
|
-
message: apiResponse.error ?? `Request failed with status ${apiResponse.status}`
|
|
8704
|
+
message: apiResponse.error ?? apiResponse.message ?? `Request failed with status ${apiResponse.status}`
|
|
8704
8705
|
};
|
|
8705
8706
|
}
|
|
8706
8707
|
async function get(endpoint, options) {
|
|
@@ -9462,21 +9463,24 @@ async function validateAffiliateCode(code) {
|
|
|
9462
9463
|
return response;
|
|
9463
9464
|
}
|
|
9464
9465
|
if (!response.data?.valid || !response.data.affiliate_code) {
|
|
9466
|
+
const programDisabled = response.data?.program_enabled === false;
|
|
9465
9467
|
return {
|
|
9466
9468
|
success: false,
|
|
9467
9469
|
data: {
|
|
9468
9470
|
valid: false,
|
|
9471
|
+
...response.data?.program_enabled !== void 0 ? { program_enabled: response.data.program_enabled } : {},
|
|
9469
9472
|
affiliate_code: null,
|
|
9470
9473
|
discount_active: false,
|
|
9471
9474
|
discount_percent: 0
|
|
9472
9475
|
},
|
|
9473
|
-
message: "Invalid affiliate code."
|
|
9476
|
+
message: response.message ?? (programDisabled ? "Affiliate program is disabled for this shop." : "Invalid affiliate code.")
|
|
9474
9477
|
};
|
|
9475
9478
|
}
|
|
9476
9479
|
return {
|
|
9477
9480
|
success: true,
|
|
9478
9481
|
data: {
|
|
9479
9482
|
valid: true,
|
|
9483
|
+
...response.data.program_enabled !== void 0 ? { program_enabled: response.data.program_enabled } : {},
|
|
9480
9484
|
affiliate_code: normalizeAffiliateCode(response.data.affiliate_code),
|
|
9481
9485
|
discount_active: Boolean(response.data.discount_active),
|
|
9482
9486
|
discount_percent: Number(response.data.discount_percent ?? 0)
|