washday-sdk 1.6.10 → 1.6.12
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/api/index.js +5 -0
- package/dist/api/stores/get.js +1 -1
- package/dist/api/stores/put.js +1 -1
- package/dist/api/updates/get.js +32 -0
- package/dist/api/updates/index.js +2 -0
- package/dist/api/updates/post.js +24 -0
- package/dist/utils/orders/calculateTotalTaxesIncluded.js +6 -2
- package/package.json +1 -1
- package/src/api/index.ts +5 -0
- package/src/api/stores/get.ts +1 -1
- package/src/api/stores/put.ts +1 -1
- package/src/api/updates/get.ts +25 -0
- package/src/api/updates/index.ts +3 -0
- package/src/api/updates/post.ts +16 -0
- package/src/interfaces/Api.ts +5 -0
- package/src/utils/orders/calculateTotalTaxesIncluded.ts +6 -2
package/dist/api/index.js
CHANGED
|
@@ -43,6 +43,7 @@ import * as publicsEndpoints from './publics';
|
|
|
43
43
|
import { validateUserPin } from "./users/post";
|
|
44
44
|
import { getAxiosInstance } from "./axiosInstance";
|
|
45
45
|
import * as integrationsEndpoints from './integrations';
|
|
46
|
+
import * as updatesEndpoints from './updates';
|
|
46
47
|
function bindMethods(instance, methods) {
|
|
47
48
|
const boundMethods = {};
|
|
48
49
|
for (const key in methods) {
|
|
@@ -355,5 +356,9 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
|
|
|
355
356
|
getMPAttemptStatus: integrationsEndpoints.getModule.getMPAttemptStatus,
|
|
356
357
|
updateMPTerminalOperationMode: integrationsEndpoints.postModule.updateMPTerminalOperationMode,
|
|
357
358
|
});
|
|
359
|
+
this.updates = bindMethods(this, {
|
|
360
|
+
getLatestUpdates: updatesEndpoints.getModule.getLatestUpdates,
|
|
361
|
+
markUpdatesAsSeen: updatesEndpoints.postModule.markUpdatesAsSeen,
|
|
362
|
+
});
|
|
358
363
|
};
|
|
359
364
|
export default WashdayClient;
|
package/dist/api/stores/get.js
CHANGED
|
@@ -128,7 +128,7 @@ export const getPaymentFees = function (storeId) {
|
|
|
128
128
|
const config = {
|
|
129
129
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
130
130
|
};
|
|
131
|
-
return yield this.axiosInstance.get(`${
|
|
131
|
+
return yield this.axiosInstance.get(`${GET_SET_STORES_V2}/${storeId}/payment-fees`, config)
|
|
132
132
|
.then(response => { var _a; return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.data) || {}; });
|
|
133
133
|
}
|
|
134
134
|
catch (error) {
|
package/dist/api/stores/put.js
CHANGED
|
@@ -62,7 +62,7 @@ export const updatePaymentFees = function (storeId, data) {
|
|
|
62
62
|
const config = {
|
|
63
63
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
64
64
|
};
|
|
65
|
-
return yield this.axiosInstance.put(`${
|
|
65
|
+
return yield this.axiosInstance.put(`${GET_SET_STORES_V2}/${storeId}/payment-fees`, data, config);
|
|
66
66
|
}
|
|
67
67
|
catch (error) {
|
|
68
68
|
console.error('Error fetching updatePaymentFees:', error);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { generateQueryParamsStr } from "../../utils/apiUtils";
|
|
11
|
+
const GET_LATEST_UPDATES = 'api/updates/latest';
|
|
12
|
+
export const getLatestUpdates = function (params, options) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
try {
|
|
15
|
+
const config = {
|
|
16
|
+
headers: { Authorization: `Bearer ${this.apiToken}` },
|
|
17
|
+
signal: (options === null || options === void 0 ? void 0 : options.signal) || (params === null || params === void 0 ? void 0 : params.signal) || undefined
|
|
18
|
+
};
|
|
19
|
+
const queryParams = generateQueryParamsStr(['limit'], params || {});
|
|
20
|
+
const url = queryParams ? `${GET_LATEST_UPDATES}?${queryParams}` : GET_LATEST_UPDATES;
|
|
21
|
+
return yield this.axiosInstance.get(url, config);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error instanceof Error && (error.name === 'AbortError' || error.name === 'CanceledError')) {
|
|
25
|
+
console.log('Request was cancelled');
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
console.error('Washday SDK - Error fetching latest updates:', error);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const MARK_UPDATES_SEEN = 'api/updates/mark-seen';
|
|
11
|
+
export const markUpdatesAsSeen = function () {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
try {
|
|
14
|
+
const config = {
|
|
15
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
16
|
+
};
|
|
17
|
+
return yield this.axiosInstance.post(MARK_UPDATES_SEEN, {}, config);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error('Washday SDK - Error marking updates as seen:', error);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
@@ -17,6 +17,7 @@ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettin
|
|
|
17
17
|
let discPercentageInteger = 0;
|
|
18
18
|
let productPercentageDiscount = 0;
|
|
19
19
|
let customerDiscount = 0;
|
|
20
|
+
// ORDER DOES NOT HAVE A DISCOUNT CODE
|
|
20
21
|
if (!order.discountCode) {
|
|
21
22
|
const discountsToApply = storeDiscounts.filter((discount) => discount.isActive && discount.products.some((p) => {
|
|
22
23
|
if (typeof p === 'string') {
|
|
@@ -35,7 +36,9 @@ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettin
|
|
|
35
36
|
discountsToApply.forEach((discount) => (appliedOrderDiscounts[discount._id] = discount));
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
|
-
|
|
39
|
+
// ORDER HAS A DISCOUNT CODE
|
|
40
|
+
// PERCENTAGE DISCOUNT CODE
|
|
41
|
+
if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) === DiscountCodeTypes.PERCENTAGE) {
|
|
39
42
|
discPercentageInteger = +(discountCodeObj.value / 100).toFixed(2);
|
|
40
43
|
if (!discountCodeObj.applyToAllProducts) {
|
|
41
44
|
discPercentageInteger = ((_b = discountCodeObj.products) === null || _b === void 0 ? void 0 : _b.includes(current._id))
|
|
@@ -43,7 +46,7 @@ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettin
|
|
|
43
46
|
: 0;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) ===
|
|
49
|
+
if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) === DiscountCodeTypes.BUY_X_GET_Y) {
|
|
47
50
|
const discountType = discountCodeObj.buyAndGetConditions[0].getDiscountType;
|
|
48
51
|
const discountValue = discountCodeObj.buyAndGetConditions[0].discountValue;
|
|
49
52
|
if (discountType === 'percentage' && current.isBuyAndGetProduct) {
|
|
@@ -52,6 +55,7 @@ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettin
|
|
|
52
55
|
if (discountType === 'free' && current.isBuyAndGetProduct) {
|
|
53
56
|
discPercentageInteger = 1;
|
|
54
57
|
}
|
|
58
|
+
// FREE ITEM DISCOUNT CODE
|
|
55
59
|
}
|
|
56
60
|
else if (discountCodeObj.type === DiscountCodeTypes.FREE_ITEM && (current.isFreeItem)) {
|
|
57
61
|
discPercentageInteger = 1;
|
package/package.json
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -45,6 +45,7 @@ import * as publicsEndpoints from './publics';
|
|
|
45
45
|
import { validateUserPin } from "./users/post";
|
|
46
46
|
import { getAxiosInstance } from "./axiosInstance";
|
|
47
47
|
import * as integrationsEndpoints from './integrations';
|
|
48
|
+
import * as updatesEndpoints from './updates';
|
|
48
49
|
|
|
49
50
|
type WashdayClientConstructor = {
|
|
50
51
|
new(apiToken: string, env?: string, clientId?: string, clientSecret?: string): WashdayClientInstance
|
|
@@ -362,6 +363,10 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
|
|
|
362
363
|
getMPAttemptStatus: integrationsEndpoints.getModule.getMPAttemptStatus,
|
|
363
364
|
updateMPTerminalOperationMode: integrationsEndpoints.postModule.updateMPTerminalOperationMode,
|
|
364
365
|
});
|
|
366
|
+
this.updates = bindMethods(this, {
|
|
367
|
+
getLatestUpdates: updatesEndpoints.getModule.getLatestUpdates,
|
|
368
|
+
markUpdatesAsSeen: updatesEndpoints.postModule.markUpdatesAsSeen,
|
|
369
|
+
});
|
|
365
370
|
} as any;
|
|
366
371
|
|
|
367
372
|
export default WashdayClient;
|
package/src/api/stores/get.ts
CHANGED
|
@@ -111,7 +111,7 @@ export const getPaymentFees = async function (this: WashdayClientInstance, store
|
|
|
111
111
|
const config = {
|
|
112
112
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
113
113
|
};
|
|
114
|
-
return await this.axiosInstance.get(`${
|
|
114
|
+
return await this.axiosInstance.get(`${GET_SET_STORES_V2}/${storeId}/payment-fees`, config)
|
|
115
115
|
.then(response => response.data?.data || {});
|
|
116
116
|
} catch (error) {
|
|
117
117
|
console.error('Error fetching getPaymentFees:', error);
|
package/src/api/stores/put.ts
CHANGED
|
@@ -54,7 +54,7 @@ export const updatePaymentFees = async function (this: WashdayClientInstance, st
|
|
|
54
54
|
const config = {
|
|
55
55
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
56
56
|
};
|
|
57
|
-
return await this.axiosInstance.put(`${
|
|
57
|
+
return await this.axiosInstance.put(`${GET_SET_STORES_V2}/${storeId}/payment-fees`, data, config);
|
|
58
58
|
} catch (error) {
|
|
59
59
|
console.error('Error fetching updatePaymentFees:', error);
|
|
60
60
|
throw error;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GenericAbortSignal } from "axios";
|
|
2
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
3
|
+
import { generateQueryParamsStr } from "../../utils/apiUtils";
|
|
4
|
+
|
|
5
|
+
const GET_LATEST_UPDATES = 'api/updates/latest';
|
|
6
|
+
|
|
7
|
+
export const getLatestUpdates = async function (this: WashdayClientInstance, params?: { limit?: number | string, signal?: GenericAbortSignal }, options?: { signal?: GenericAbortSignal }): Promise<any> {
|
|
8
|
+
try {
|
|
9
|
+
const config = {
|
|
10
|
+
headers: { Authorization: `Bearer ${this.apiToken}` },
|
|
11
|
+
signal: options?.signal || params?.signal || undefined
|
|
12
|
+
};
|
|
13
|
+
const queryParams = generateQueryParamsStr(['limit'], params || {});
|
|
14
|
+
const url = queryParams ? `${GET_LATEST_UPDATES}?${queryParams}` : GET_LATEST_UPDATES;
|
|
15
|
+
return await this.axiosInstance.get(url, config);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error instanceof Error && (error.name === 'AbortError' || error.name === 'CanceledError')) {
|
|
18
|
+
console.log('Request was cancelled');
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
console.error('Washday SDK - Error fetching latest updates:', error);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
|
|
3
|
+
const MARK_UPDATES_SEEN = 'api/updates/mark-seen';
|
|
4
|
+
|
|
5
|
+
export const markUpdatesAsSeen = async function (this: WashdayClientInstance): Promise<any> {
|
|
6
|
+
try {
|
|
7
|
+
const config = {
|
|
8
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
9
|
+
};
|
|
10
|
+
return await this.axiosInstance.post(MARK_UPDATES_SEEN, {}, config);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error('Washday SDK - Error marking updates as seen:', error);
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
package/src/interfaces/Api.ts
CHANGED
|
@@ -41,6 +41,7 @@ import * as partnersEndpoints from '../api/partners';
|
|
|
41
41
|
import * as outsourcedOrdersEndpoints from '../api/outsourcedOrders';
|
|
42
42
|
import * as publicsEndpoints from '../api/publics';
|
|
43
43
|
import * as integrationsEndpoints from '../api/integrations';
|
|
44
|
+
import * as updatesEndpoints from '../api/updates';
|
|
44
45
|
import { validateUserPin } from "../api/users/post";
|
|
45
46
|
import { AxiosInstance } from "axios";
|
|
46
47
|
|
|
@@ -345,4 +346,8 @@ export interface WashdayClientInstance {
|
|
|
345
346
|
updateMPTerminalOperationMode: typeof integrationsEndpoints.postModule.updateMPTerminalOperationMode;
|
|
346
347
|
}
|
|
347
348
|
};
|
|
349
|
+
updates: {
|
|
350
|
+
getLatestUpdates: typeof updatesEndpoints.getModule.getLatestUpdates;
|
|
351
|
+
markUpdatesAsSeen: typeof updatesEndpoints.postModule.markUpdatesAsSeen;
|
|
352
|
+
};
|
|
348
353
|
}
|
|
@@ -28,6 +28,7 @@ export const calculateTotalTaxesIncluded = (
|
|
|
28
28
|
let discPercentageInteger = 0;
|
|
29
29
|
let productPercentageDiscount = 0;
|
|
30
30
|
let customerDiscount = 0;
|
|
31
|
+
// ORDER DOES NOT HAVE A DISCOUNT CODE
|
|
31
32
|
if (!order.discountCode) {
|
|
32
33
|
const discountsToApply = storeDiscounts.filter(
|
|
33
34
|
(discount: any) => discount.isActive && discount.products.some((p: any) => {
|
|
@@ -46,7 +47,9 @@ export const calculateTotalTaxesIncluded = (
|
|
|
46
47
|
discPercentageInteger = +((productPercentageDiscount + customerDiscount) / 100).toFixed(2);
|
|
47
48
|
discountsToApply.forEach((discount) => (appliedOrderDiscounts[discount._id] = discount));
|
|
48
49
|
} else {
|
|
49
|
-
|
|
50
|
+
// ORDER HAS A DISCOUNT CODE
|
|
51
|
+
// PERCENTAGE DISCOUNT CODE
|
|
52
|
+
if (discountCodeObj?.type === DiscountCodeTypes.PERCENTAGE) {
|
|
50
53
|
discPercentageInteger = +(discountCodeObj.value / 100).toFixed(2);
|
|
51
54
|
if (!discountCodeObj.applyToAllProducts) {
|
|
52
55
|
discPercentageInteger = discountCodeObj.products?.includes(current._id)
|
|
@@ -54,7 +57,7 @@ export const calculateTotalTaxesIncluded = (
|
|
|
54
57
|
: 0;
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
|
-
if (discountCodeObj?.type ===
|
|
60
|
+
if (discountCodeObj?.type === DiscountCodeTypes.BUY_X_GET_Y) {
|
|
58
61
|
const discountType = discountCodeObj.buyAndGetConditions[0].getDiscountType;
|
|
59
62
|
const discountValue = discountCodeObj.buyAndGetConditions[0].discountValue;
|
|
60
63
|
if (discountType === 'percentage' && current.isBuyAndGetProduct) {
|
|
@@ -63,6 +66,7 @@ export const calculateTotalTaxesIncluded = (
|
|
|
63
66
|
if (discountType === 'free' && current.isBuyAndGetProduct) {
|
|
64
67
|
discPercentageInteger = 1;
|
|
65
68
|
}
|
|
69
|
+
// FREE ITEM DISCOUNT CODE
|
|
66
70
|
} else if (discountCodeObj.type === DiscountCodeTypes.FREE_ITEM && ((current as any).isFreeItem)) {
|
|
67
71
|
discPercentageInteger = 1;
|
|
68
72
|
}
|