washday-sdk 1.6.11 → 1.6.13

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 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) {
@@ -135,6 +136,7 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
135
136
  createOrderEvidence: ordersEndpoints.postModule.createOrderEvidence,
136
137
  getRedeemPointsPreview: ordersEndpoints.postModule.getRedeemPointsPreview,
137
138
  setOrderUncollected: ordersEndpoints.postModule.setOrderUncollected,
139
+ payAndCollect: ordersEndpoints.postModule.payAndCollect,
138
140
  deletePaymentLineById: ordersEndpoints.deleteModule.deletePaymentLineById,
139
141
  getListCustomersApp: ordersEndpoints.getModule.getListCustomersApp,
140
142
  getByIdCustomersApp: ordersEndpoints.getModule.getByIdCustomersApp,
@@ -355,5 +357,9 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
355
357
  getMPAttemptStatus: integrationsEndpoints.getModule.getMPAttemptStatus,
356
358
  updateMPTerminalOperationMode: integrationsEndpoints.postModule.updateMPTerminalOperationMode,
357
359
  });
360
+ this.updates = bindMethods(this, {
361
+ getLatestUpdates: updatesEndpoints.getModule.getLatestUpdates,
362
+ markUpdatesAsSeen: updatesEndpoints.postModule.markUpdatesAsSeen,
363
+ });
358
364
  };
359
365
  export default WashdayClient;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  const GET_SET_ORDER_PAYMENTLINES = (orderId) => `/api/v2/order/${orderId}/paymentLines`;
11
11
  const GET_SET_ORDER = 'api/v2/order';
12
12
  const GET_SET_ORDER_CUSTOMERS_APP = 'api/v2/washdayapp/orders';
13
+ const PAY_AND_COLLECT = (sequence, storeId) => `/api/v2/order/${sequence}/${storeId}/pay-and-collect`;
13
14
  export const createPaymentLine = function (id, data) {
14
15
  return __awaiter(this, void 0, void 0, function* () {
15
16
  try {
@@ -126,3 +127,26 @@ export const setOrderUncollected = function (data) {
126
127
  }
127
128
  });
128
129
  };
130
+ export const payAndCollect = function (params) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ try {
133
+ const config = {
134
+ headers: { Authorization: `Bearer ${this.apiToken}` }
135
+ };
136
+ return yield this.axiosInstance.post(PAY_AND_COLLECT(params.sequence, params.storeId), {
137
+ paymentMethod: params.paymentMethod,
138
+ cashierBoxId: params.cashierBoxId,
139
+ amount: params.amount,
140
+ paymentDate: params.paymentDate,
141
+ collectedDateTime: params.collectedDateTime,
142
+ collectWithAmountDue: params.collectWithAmountDue,
143
+ pinUserId: params.pinUserId,
144
+ attemptId: params.attemptId,
145
+ }, config);
146
+ }
147
+ catch (error) {
148
+ console.error('Error fetching payAndCollect:', error);
149
+ throw error;
150
+ }
151
+ });
152
+ };
@@ -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,2 @@
1
+ export * as getModule from './get';
2
+ export * as postModule from './post';
@@ -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
- if ((discountCodeObj === null || discountCodeObj === void 0 ? void 0 : discountCodeObj.type) === 'percentage') {
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) === 'buyXGetY') {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "1.6.11",
3
+ "version": "1.6.13",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
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
@@ -142,6 +143,7 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
142
143
  createOrderEvidence: ordersEndpoints.postModule.createOrderEvidence,
143
144
  getRedeemPointsPreview: ordersEndpoints.postModule.getRedeemPointsPreview,
144
145
  setOrderUncollected: ordersEndpoints.postModule.setOrderUncollected,
146
+ payAndCollect: ordersEndpoints.postModule.payAndCollect,
145
147
  deletePaymentLineById: ordersEndpoints.deleteModule.deletePaymentLineById,
146
148
  getListCustomersApp: ordersEndpoints.getModule.getListCustomersApp,
147
149
  getByIdCustomersApp: ordersEndpoints.getModule.getByIdCustomersApp,
@@ -362,6 +364,10 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
362
364
  getMPAttemptStatus: integrationsEndpoints.getModule.getMPAttemptStatus,
363
365
  updateMPTerminalOperationMode: integrationsEndpoints.postModule.updateMPTerminalOperationMode,
364
366
  });
367
+ this.updates = bindMethods(this, {
368
+ getLatestUpdates: updatesEndpoints.getModule.getLatestUpdates,
369
+ markUpdatesAsSeen: updatesEndpoints.postModule.markUpdatesAsSeen,
370
+ });
365
371
  } as any;
366
372
 
367
373
  export default WashdayClient;
@@ -6,6 +6,7 @@ import axiosInstance from "../axiosInstance";
6
6
  const GET_SET_ORDER_PAYMENTLINES = (orderId: string) => `/api/v2/order/${orderId}/paymentLines`;
7
7
  const GET_SET_ORDER = 'api/v2/order';
8
8
  const GET_SET_ORDER_CUSTOMERS_APP = 'api/v2/washdayapp/orders';
9
+ const PAY_AND_COLLECT = (sequence: string, storeId: string) => `/api/v2/order/${sequence}/${storeId}/pay-and-collect`;
9
10
 
10
11
  export const createPaymentLine = async function (this: WashdayClientInstance, id: string, data: {
11
12
  amountPaid: number,
@@ -132,4 +133,40 @@ export const setOrderUncollected = async function (this: WashdayClientInstance,
132
133
  console.error('Error fetching setOrderUncollected:', error);
133
134
  throw error;
134
135
  }
136
+ };
137
+
138
+ export const payAndCollect = async function (this: WashdayClientInstance, params: {
139
+ sequence: string;
140
+ storeId: string;
141
+ paymentMethod: string;
142
+ cashierBoxId?: string;
143
+ amount?: number;
144
+ paymentDate?: string | Date;
145
+ collectedDateTime?: string | Date;
146
+ collectWithAmountDue?: boolean;
147
+ pinUserId?: string;
148
+ attemptId?: string;
149
+ }): Promise<AxiosResponse<any, any>> {
150
+ try {
151
+ const config = {
152
+ headers: { Authorization: `Bearer ${this.apiToken}` }
153
+ };
154
+ return await this.axiosInstance.post(
155
+ PAY_AND_COLLECT(params.sequence, params.storeId),
156
+ {
157
+ paymentMethod: params.paymentMethod,
158
+ cashierBoxId: params.cashierBoxId,
159
+ amount: params.amount,
160
+ paymentDate: params.paymentDate,
161
+ collectedDateTime: params.collectedDateTime,
162
+ collectWithAmountDue: params.collectWithAmountDue,
163
+ pinUserId: params.pinUserId,
164
+ attemptId: params.attemptId,
165
+ },
166
+ config
167
+ );
168
+ } catch (error) {
169
+ console.error('Error fetching payAndCollect:', error);
170
+ throw error;
171
+ }
135
172
  };
@@ -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,3 @@
1
+ export * as getModule from './get';
2
+ export * as postModule from './post';
3
+
@@ -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
+
@@ -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
 
@@ -127,6 +128,7 @@ export interface WashdayClientInstance {
127
128
  createOrderEvidence: typeof ordersEndpoints.postModule.createOrderEvidence,
128
129
  getRedeemPointsPreview: typeof ordersEndpoints.postModule.getRedeemPointsPreview,
129
130
  setOrderUncollected: typeof ordersEndpoints.postModule.setOrderUncollected,
131
+ payAndCollect: typeof ordersEndpoints.postModule.payAndCollect,
130
132
  deletePaymentLineById: typeof ordersEndpoints.deleteModule.deletePaymentLineById;
131
133
  getListCustomersApp: typeof ordersEndpoints.getModule.getListCustomersApp;
132
134
  getByIdCustomersApp: typeof ordersEndpoints.getModule.getByIdCustomersApp;
@@ -345,4 +347,8 @@ export interface WashdayClientInstance {
345
347
  updateMPTerminalOperationMode: typeof integrationsEndpoints.postModule.updateMPTerminalOperationMode;
346
348
  }
347
349
  };
350
+ updates: {
351
+ getLatestUpdates: typeof updatesEndpoints.getModule.getLatestUpdates;
352
+ markUpdatesAsSeen: typeof updatesEndpoints.postModule.markUpdatesAsSeen;
353
+ };
348
354
  }
@@ -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
- if (discountCodeObj?.type === 'percentage') {
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 === 'buyXGetY') {
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
  }