washday-sdk 1.0.2 → 1.1.0

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.
Files changed (254) hide show
  1. package/README.md +126 -0
  2. package/babel.config.js +8 -0
  3. package/dist/api/attendance/delete.js +2 -0
  4. package/dist/api/attendance/get.js +83 -0
  5. package/dist/api/attendance/index.js +4 -0
  6. package/dist/api/attendance/post.js +39 -0
  7. package/dist/api/attendance/put.js +25 -0
  8. package/dist/api/auth/index.js +3 -0
  9. package/dist/api/auth/post.js +170 -0
  10. package/dist/api/axiosInstance.js +15 -11
  11. package/dist/api/cashierbox/delete.js +40 -0
  12. package/dist/api/cashierbox/get.js +63 -0
  13. package/dist/api/cashierbox/post.js +42 -0
  14. package/dist/api/cashierbox/put.js +42 -0
  15. package/dist/api/cashups/delete.js +25 -0
  16. package/dist/api/cashups/get.js +60 -0
  17. package/dist/api/cashups/index.js +4 -0
  18. package/dist/api/cashups/post.js +25 -0
  19. package/dist/api/cashups/put.js +52 -0
  20. package/dist/api/cfdi/delete.js +25 -0
  21. package/dist/api/cfdi/get.js +126 -0
  22. package/dist/api/cfdi/index.js +4 -0
  23. package/dist/api/cfdi/post.js +41 -0
  24. package/dist/api/cfdi/put.js +52 -0
  25. package/dist/api/companies/get.js +29 -0
  26. package/dist/api/companies/post.js +41 -0
  27. package/dist/api/companies/put.js +57 -0
  28. package/dist/api/countries/get.js +29 -0
  29. package/dist/api/countries/post.js +1 -0
  30. package/dist/api/countries/put.js +1 -0
  31. package/dist/api/csv/get.js +325 -0
  32. package/dist/api/csv/index.js +1 -0
  33. package/dist/api/customers/delete.js +40 -0
  34. package/dist/api/customers/get.js +75 -20
  35. package/dist/api/customers/index.js +4 -1
  36. package/dist/api/customers/post.js +41 -0
  37. package/dist/api/customers/put.js +52 -0
  38. package/dist/api/discounts/get.js +120 -0
  39. package/dist/api/discounts/post.js +40 -0
  40. package/dist/api/discounts/put.js +68 -0
  41. package/dist/api/index.js +316 -8
  42. package/dist/api/inventory/delete.js +26 -0
  43. package/dist/api/inventory/get.js +62 -0
  44. package/dist/api/inventory/index.js +4 -0
  45. package/dist/api/inventory/post.js +26 -0
  46. package/dist/api/inventory/put.js +41 -0
  47. package/dist/api/order/delete.js +40 -0
  48. package/dist/api/order/get.js +181 -0
  49. package/dist/api/order/index.js +4 -0
  50. package/dist/api/order/post.js +115 -0
  51. package/dist/api/order/put.js +202 -0
  52. package/dist/api/outsourcedOrders/delete.js +25 -0
  53. package/dist/api/outsourcedOrders/get.js +62 -0
  54. package/dist/api/outsourcedOrders/index.js +4 -0
  55. package/dist/api/outsourcedOrders/post.js +25 -0
  56. package/dist/api/outsourcedOrders/put.js +25 -0
  57. package/dist/api/partners/delete.js +25 -0
  58. package/dist/api/partners/get.js +40 -0
  59. package/dist/api/partners/index.js +4 -0
  60. package/dist/api/partners/post.js +25 -0
  61. package/dist/api/partners/put.js +25 -0
  62. package/dist/api/pdf/get.js +43 -0
  63. package/dist/api/pdf/index.js +1 -0
  64. package/dist/api/products/delete.js +40 -0
  65. package/dist/api/products/get.js +25 -0
  66. package/dist/api/products/index.js +4 -0
  67. package/dist/api/products/post.js +60 -0
  68. package/dist/api/products/put.js +40 -0
  69. package/dist/api/publics/get.js +26 -0
  70. package/dist/api/publics/index.js +1 -0
  71. package/dist/api/reports/get.js +303 -0
  72. package/dist/api/reports/index.js +1 -0
  73. package/dist/api/reviews/delete.js +15 -0
  74. package/dist/api/reviews/get.js +41 -0
  75. package/dist/api/reviews/index.js +4 -0
  76. package/dist/api/reviews/post.js +20 -0
  77. package/dist/api/reviews/put.js +52 -0
  78. package/dist/api/routes/delete.js +25 -0
  79. package/dist/api/routes/get.js +95 -0
  80. package/dist/api/routes/index.js +4 -0
  81. package/dist/api/routes/post.js +67 -0
  82. package/dist/api/routes/put.js +54 -0
  83. package/dist/api/sections/delete.js +25 -0
  84. package/dist/api/sections/get.js +71 -0
  85. package/dist/api/sections/index.js +4 -0
  86. package/dist/api/sections/post.js +26 -0
  87. package/dist/api/sections/put.js +25 -0
  88. package/dist/api/staff/delete.js +26 -0
  89. package/dist/api/staff/get.js +40 -0
  90. package/dist/api/staff/post.js +26 -0
  91. package/dist/api/staff/put.js +26 -0
  92. package/dist/api/stores/get.js +110 -0
  93. package/dist/api/stores/post.js +61 -0
  94. package/dist/api/stores/put.js +44 -0
  95. package/dist/api/stripe/get.js +1 -0
  96. package/dist/api/stripe/post.js +71 -0
  97. package/dist/api/stripe/put.js +1 -0
  98. package/dist/api/supplies/delete.js +26 -0
  99. package/dist/api/supplies/get.js +62 -0
  100. package/dist/api/supplies/post.js +26 -0
  101. package/dist/api/supplies/put.js +41 -0
  102. package/dist/api/users/delete.js +26 -0
  103. package/dist/api/users/post.js +25 -0
  104. package/dist/api/users/put.js +29 -0
  105. package/dist/enum/index.js +12 -7
  106. package/dist/index.js +3 -33
  107. package/dist/interfaces/Api.js +1 -3
  108. package/dist/interfaces/Apple.js +16 -0
  109. package/dist/interfaces/Attendance.js +1 -0
  110. package/dist/interfaces/Customer.js +1 -2
  111. package/dist/interfaces/Order.js +1 -2
  112. package/dist/interfaces/Permission.js +1 -2
  113. package/dist/interfaces/Product.js +1 -2
  114. package/dist/interfaces/Section.js +1 -2
  115. package/dist/interfaces/Store.js +1 -2
  116. package/dist/interfaces/StoreImage.js +1 -2
  117. package/dist/interfaces/User.js +1 -2
  118. package/dist/utils/apiUtils.js +9 -0
  119. package/dist/utils/index.js +2 -17
  120. package/dist/utils/orders/calculateOrderTotal.js +30 -21
  121. package/dist/utils/orders/calculateTotalTaxesIncluded.js +55 -29
  122. package/dist/utils/orders/calculateTotalTaxesOverPrice.js +56 -45
  123. package/dist/utils/orders/helpers.js +126 -17
  124. package/dist/utils/orders/index.js +3 -5
  125. package/dist/utils/receipt/generateReceiptHTML.js +157 -0
  126. package/dist/utils/util.js +63 -0
  127. package/docs/README.md +66 -0
  128. package/docs/examples/common-use-cases.md +487 -0
  129. package/docs/getting-started.md +237 -0
  130. package/docs/modules/attendance.md +404 -0
  131. package/jest.config.js +0 -0
  132. package/package.json +12 -4
  133. package/src/api/attendance/delete.ts +1 -0
  134. package/src/api/attendance/get.ts +81 -0
  135. package/src/api/attendance/index.ts +4 -0
  136. package/src/api/attendance/post.ts +37 -0
  137. package/src/api/attendance/put.ts +20 -0
  138. package/src/api/auth/index.ts +3 -0
  139. package/src/api/auth/post.ts +198 -0
  140. package/src/api/axiosInstance.ts +13 -3
  141. package/src/api/cashierbox/delete.ts +28 -0
  142. package/src/api/cashierbox/get.ts +53 -0
  143. package/src/api/cashierbox/post.ts +39 -0
  144. package/src/api/cashierbox/put.ts +32 -0
  145. package/src/api/cashups/delete.ts +15 -0
  146. package/src/api/cashups/get.ts +52 -0
  147. package/src/api/cashups/index.ts +4 -0
  148. package/src/api/cashups/post.ts +23 -0
  149. package/src/api/cashups/put.ts +53 -0
  150. package/src/api/cfdi/delete.ts +21 -0
  151. package/src/api/cfdi/get.ts +119 -0
  152. package/src/api/cfdi/index.ts +4 -0
  153. package/src/api/cfdi/post.ts +60 -0
  154. package/src/api/cfdi/put.ts +53 -0
  155. package/src/api/companies/get.ts +23 -0
  156. package/src/api/companies/post.ts +29 -0
  157. package/src/api/companies/put.ts +43 -0
  158. package/src/api/countries/get.ts +23 -0
  159. package/src/api/countries/post.ts +0 -0
  160. package/src/api/countries/put.ts +0 -0
  161. package/src/api/csv/get.ts +354 -0
  162. package/src/api/csv/index.ts +1 -0
  163. package/src/api/customers/delete.ts +29 -0
  164. package/src/api/customers/get.ts +80 -8
  165. package/src/api/customers/index.ts +4 -0
  166. package/src/api/customers/post.ts +48 -0
  167. package/src/api/customers/put.ts +68 -0
  168. package/src/api/discounts/get.ts +100 -0
  169. package/src/api/discounts/post.ts +35 -0
  170. package/src/api/discounts/put.ts +66 -0
  171. package/src/api/index.ts +318 -11
  172. package/src/api/inventory/delete.ts +16 -0
  173. package/src/api/inventory/get.ts +53 -0
  174. package/src/api/inventory/index.ts +4 -0
  175. package/src/api/inventory/post.ts +22 -0
  176. package/src/api/inventory/put.ts +35 -0
  177. package/src/api/order/delete.ts +29 -0
  178. package/src/api/order/get.ts +207 -0
  179. package/src/api/order/index.ts +4 -0
  180. package/src/api/order/post.ts +118 -0
  181. package/src/api/order/put.ts +224 -0
  182. package/src/api/outsourcedOrders/delete.ts +15 -0
  183. package/src/api/outsourcedOrders/get.ts +54 -0
  184. package/src/api/outsourcedOrders/index.ts +4 -0
  185. package/src/api/outsourcedOrders/post.ts +24 -0
  186. package/src/api/outsourcedOrders/put.ts +21 -0
  187. package/src/api/partners/delete.ts +15 -0
  188. package/src/api/partners/get.ts +28 -0
  189. package/src/api/partners/index.ts +4 -0
  190. package/src/api/partners/post.ts +21 -0
  191. package/src/api/partners/put.ts +21 -0
  192. package/src/api/pdf/get.ts +43 -0
  193. package/src/api/pdf/index.ts +1 -0
  194. package/src/api/products/delete.ts +28 -0
  195. package/src/api/products/get.ts +16 -0
  196. package/src/api/products/index.ts +4 -0
  197. package/src/api/products/post.ts +73 -0
  198. package/src/api/products/put.ts +49 -0
  199. package/src/api/publics/get.ts +16 -0
  200. package/src/api/publics/index.ts +1 -0
  201. package/src/api/reports/get.ts +329 -0
  202. package/src/api/reports/index.ts +1 -0
  203. package/src/api/reviews/delete.ts +15 -0
  204. package/src/api/reviews/get.ts +31 -0
  205. package/src/api/reviews/index.ts +4 -0
  206. package/src/api/reviews/post.ts +20 -0
  207. package/src/api/reviews/put.ts +53 -0
  208. package/src/api/routes/delete.ts +15 -0
  209. package/src/api/routes/get.ts +86 -0
  210. package/src/api/routes/index.ts +4 -0
  211. package/src/api/routes/post.ts +60 -0
  212. package/src/api/routes/put.ts +44 -0
  213. package/src/api/sections/delete.ts +15 -0
  214. package/src/api/sections/get.ts +67 -0
  215. package/src/api/sections/index.ts +4 -0
  216. package/src/api/sections/post.ts +22 -0
  217. package/src/api/sections/put.ts +23 -0
  218. package/src/api/staff/delete.ts +16 -0
  219. package/src/api/staff/get.ts +29 -0
  220. package/src/api/staff/post.ts +17 -0
  221. package/src/api/staff/put.ts +17 -0
  222. package/src/api/stores/get.ts +93 -0
  223. package/src/api/stores/post.ts +49 -0
  224. package/src/api/stores/put.ts +35 -0
  225. package/src/api/stripe/get.ts +0 -0
  226. package/src/api/stripe/post.ts +59 -0
  227. package/src/api/stripe/put.ts +0 -0
  228. package/src/api/supplies/delete.ts +16 -0
  229. package/src/api/supplies/get.ts +53 -0
  230. package/src/api/supplies/post.ts +26 -0
  231. package/src/api/supplies/put.ts +33 -0
  232. package/src/api/users/delete.ts +16 -0
  233. package/src/api/users/post.ts +18 -0
  234. package/src/api/users/put.ts +36 -0
  235. package/src/enum/index.ts +9 -1
  236. package/src/index.ts +1 -4
  237. package/src/interfaces/Api.ts +307 -2
  238. package/src/interfaces/Apple.ts +74 -0
  239. package/src/interfaces/Attendance.ts +45 -0
  240. package/src/interfaces/Customer.ts +15 -11
  241. package/src/interfaces/Order.ts +38 -1
  242. package/src/interfaces/Product.ts +1 -0
  243. package/src/interfaces/Store.ts +41 -0
  244. package/src/utils/apiUtils.ts +11 -0
  245. package/src/utils/index.ts +6 -1
  246. package/src/utils/orders/calculateOrderTotal.test.js +930 -0
  247. package/src/utils/orders/calculateOrderTotal.ts +60 -15
  248. package/src/utils/orders/calculateTotalTaxesIncluded.ts +57 -25
  249. package/src/utils/orders/calculateTotalTaxesOverPrice.ts +57 -41
  250. package/src/utils/orders/helpers.ts +195 -47
  251. package/src/utils/orders/index.ts +3 -1
  252. package/src/utils/receipt/generateReceiptHTML.ts +163 -0
  253. package/src/utils/util.ts +65 -0
  254. package/tsconfig.json +13 -9
@@ -0,0 +1,62 @@
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 axiosInstance from "../axiosInstance";
11
+ const GET_SET_SUPPLY = (storeId) => `api/store/${storeId}/supply`;
12
+ export const getSupplies = function (storeId, queryParams) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ try {
15
+ const config = {
16
+ headers: { Authorization: `Bearer ${this.apiToken}` }
17
+ };
18
+ const response = yield axiosInstance.get(`${GET_SET_SUPPLY(storeId)}?${queryParams}`, config);
19
+ return response;
20
+ }
21
+ catch (error) {
22
+ console.error('Error fetching getSupplies:', error);
23
+ throw error;
24
+ }
25
+ });
26
+ };
27
+ export const getSupplyById = function (storeId, id) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ try {
30
+ const config = {
31
+ headers: { Authorization: `Bearer ${this.apiToken}` }
32
+ };
33
+ return yield axiosInstance.get(`${GET_SET_SUPPLY(storeId)}/${id}`, config);
34
+ }
35
+ catch (error) {
36
+ console.error('Error fetching getStoreSupplyById:', error);
37
+ throw error;
38
+ }
39
+ });
40
+ };
41
+ export const getSupplyHistory = function (storeId, id, params) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ try {
44
+ const config = {
45
+ headers: { Authorization: `Bearer ${this.apiToken}` }
46
+ };
47
+ let queryParams = '';
48
+ if (params === null || params === void 0 ? void 0 : params.hasOwnProperty('pageNum')) {
49
+ queryParams += `pageNum=${params === null || params === void 0 ? void 0 : params.pageNum}`;
50
+ }
51
+ if (params === null || params === void 0 ? void 0 : params.hasOwnProperty('limit')) {
52
+ queryParams += `&limit=${params === null || params === void 0 ? void 0 : params.limit}`;
53
+ }
54
+ const response = yield axiosInstance.get(`${GET_SET_SUPPLY(storeId)}/${id}/history?${queryParams}`, config);
55
+ return response;
56
+ }
57
+ catch (error) {
58
+ console.error('Error fetching getCashierBoxMovementsHistory:', error);
59
+ throw error;
60
+ }
61
+ });
62
+ };
@@ -0,0 +1,26 @@
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 axiosInstance from "../axiosInstance";
11
+ const GET_SET_SUPPLY = (storeId) => `api/store/${storeId}/supply`;
12
+ export const createSupply = function (storeId, data) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ try {
15
+ const config = {
16
+ headers: { Authorization: `Bearer ${this.apiToken}` }
17
+ };
18
+ const response = yield axiosInstance.post(`${GET_SET_SUPPLY(storeId)}`, data, config);
19
+ return response;
20
+ }
21
+ catch (error) {
22
+ console.error('Error fetching createSupply:', error);
23
+ throw error;
24
+ }
25
+ });
26
+ };
@@ -0,0 +1,41 @@
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 axiosInstance from "../axiosInstance";
11
+ const GET_SET_SUPPLY = (storeId) => `api/store/${storeId}/supply`;
12
+ export const updateSupplyById = function (storeId, id, data) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ try {
15
+ const config = {
16
+ headers: { Authorization: `Bearer ${this.apiToken}` }
17
+ };
18
+ const response = yield axiosInstance.put(`${GET_SET_SUPPLY(storeId)}/${id}`, data, config);
19
+ return response;
20
+ }
21
+ catch (error) {
22
+ console.error('Error fetching getStoreById:', error);
23
+ throw error;
24
+ }
25
+ });
26
+ };
27
+ export const addSupplyStock = function (storeId, id, data) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ try {
30
+ const config = {
31
+ headers: { Authorization: `Bearer ${this.apiToken}` }
32
+ };
33
+ const response = yield axiosInstance.put(`${GET_SET_SUPPLY(storeId)}/${id}/addStock`, data, config);
34
+ return response;
35
+ }
36
+ catch (error) {
37
+ console.error('Error fetching addSupplyStock:', error);
38
+ throw error;
39
+ }
40
+ });
41
+ };
@@ -0,0 +1,26 @@
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 axiosInstance from "../axiosInstance";
11
+ const GET_SET_USER = 'api/user';
12
+ export const deleteUserById = function (id) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ try {
15
+ const config = {
16
+ headers: { Authorization: `Bearer ${this.apiToken}` }
17
+ };
18
+ const response = yield axiosInstance.delete(`${GET_SET_USER}/${id}`, config);
19
+ return response;
20
+ }
21
+ catch (error) {
22
+ console.error('Error fetching deleteUserById:', error);
23
+ throw error;
24
+ }
25
+ });
26
+ };
@@ -0,0 +1,25 @@
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 axiosInstance from "../axiosInstance";
11
+ const GET_SET_USER = 'api/users';
12
+ export const validateUserPin = function (data) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ try {
15
+ const config = {
16
+ headers: { Authorization: `Bearer ${this.apiToken}` }
17
+ };
18
+ return yield axiosInstance.post(`${GET_SET_USER}/validate-pin`, data, config);
19
+ }
20
+ catch (error) {
21
+ console.error('Error fetching validateUserPin:', error);
22
+ throw error;
23
+ }
24
+ });
25
+ };
@@ -0,0 +1,29 @@
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 axiosInstance from "../axiosInstance";
11
+ const GET_SET_USER = 'api/user';
12
+ const REQUEST_PARAMS = {
13
+ token: 'LOGGED_USER_TOKEN',
14
+ };
15
+ export const updateUserById = function (userId, data) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ try {
18
+ const config = {
19
+ headers: { Authorization: `Bearer ${this.apiToken}` }
20
+ };
21
+ const response = yield axiosInstance.put(`${GET_SET_USER}/${userId}`, data, config);
22
+ return response.data || {};
23
+ }
24
+ catch (error) {
25
+ console.error('Error fetching updateUserById:', error);
26
+ throw error;
27
+ }
28
+ });
29
+ };
@@ -1,15 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BuyAndGetConditionsTypes = exports.DiscountCodeTypes = void 0;
4
- var DiscountCodeTypes;
1
+ export var DiscountCodeTypes;
5
2
  (function (DiscountCodeTypes) {
6
3
  DiscountCodeTypes["PERCENTAGE"] = "percentage";
7
4
  DiscountCodeTypes["NUMBER"] = "number";
8
5
  DiscountCodeTypes["FREE_DELIVERY"] = "freeDelivery";
9
6
  DiscountCodeTypes["BUY_X_GET_Y"] = "buyXGetY";
10
- })(DiscountCodeTypes || (exports.DiscountCodeTypes = DiscountCodeTypes = {}));
11
- var BuyAndGetConditionsTypes;
7
+ DiscountCodeTypes["FREE_ITEM"] = "freeItem";
8
+ })(DiscountCodeTypes || (DiscountCodeTypes = {}));
9
+ export var BuyAndGetConditionsTypes;
12
10
  (function (BuyAndGetConditionsTypes) {
13
11
  BuyAndGetConditionsTypes["PERCENTAGE"] = "percentage";
14
12
  BuyAndGetConditionsTypes["FREE"] = "free";
15
- })(BuyAndGetConditionsTypes || (exports.BuyAndGetConditionsTypes = BuyAndGetConditionsTypes = {}));
13
+ })(BuyAndGetConditionsTypes || (BuyAndGetConditionsTypes = {}));
14
+ export var PaymentMethodsEnum;
15
+ (function (PaymentMethodsEnum) {
16
+ PaymentMethodsEnum["Cash"] = "cash";
17
+ PaymentMethodsEnum["Card"] = "card";
18
+ PaymentMethodsEnum["Delivery"] = "delivery";
19
+ PaymentMethodsEnum["Transfer"] = "transfer";
20
+ })(PaymentMethodsEnum || (PaymentMethodsEnum = {}));
package/dist/index.js CHANGED
@@ -1,33 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.WashdayClient = exports.utils = void 0;
30
- const utils = __importStar(require("./utils"));
31
- exports.utils = utils;
32
- const api_1 = __importDefault(require("./api"));
33
- exports.WashdayClient = api_1.default;
1
+ import * as utils from './utils';
2
+ import WashdayClient from './api';
3
+ export { WashdayClient, utils };
@@ -1,3 +1 @@
1
- export type WashdayClientInstance = {
2
- apiToken: string;
3
- };
1
+ export {};
@@ -0,0 +1,16 @@
1
+ var AppleAuthenticationUserDetectionStatus;
2
+ (function (AppleAuthenticationUserDetectionStatus) {
3
+ /**
4
+ * The system does not support this determination and there is no data.
5
+ */
6
+ AppleAuthenticationUserDetectionStatus[AppleAuthenticationUserDetectionStatus["UNSUPPORTED"] = 0] = "UNSUPPORTED";
7
+ /**
8
+ * The system has not determined whether the user might be a real person.
9
+ */
10
+ AppleAuthenticationUserDetectionStatus[AppleAuthenticationUserDetectionStatus["UNKNOWN"] = 1] = "UNKNOWN";
11
+ /**
12
+ * The user appears to be a real person.
13
+ */
14
+ AppleAuthenticationUserDetectionStatus[AppleAuthenticationUserDetectionStatus["LIKELY_REAL"] = 2] = "LIKELY_REAL";
15
+ })(AppleAuthenticationUserDetectionStatus || (AppleAuthenticationUserDetectionStatus = {}));
16
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export const generateQueryParamsStr = (availableQueryParamsList = [], receivedParamsObj = {}) => {
2
+ let queryParams = [];
3
+ for (let availableParam of availableQueryParamsList) {
4
+ if (receivedParamsObj.hasOwnProperty(availableParam)) {
5
+ queryParams.push(`${availableParam}=${receivedParamsObj[availableParam]}`);
6
+ }
7
+ }
8
+ return queryParams.join('&');
9
+ };
@@ -1,17 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./orders"), exports);
1
+ export { applyDiscountToProducts, calculateOrderTotal } from './orders';
2
+ export { getFormattedAddress } from './util';
@@ -1,33 +1,42 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateOrderTotal = void 0;
4
- const enum_1 = require("../../enum");
5
- const calculateTotalTaxesIncluded_1 = require("./calculateTotalTaxesIncluded");
6
- const calculateTotalTaxesOverPrice_1 = require("./calculateTotalTaxesOverPrice");
7
- const helpers_1 = require("./helpers");
8
- const calculateOrderTotal = (order, selectedCustomer, storeSettings, hasShippingCost, storeDiscounts = [], discountCodeObj) => {
1
+ import { DiscountCodeTypes } from "../../enum";
2
+ import { calculateTotalTaxesIncluded } from "./calculateTotalTaxesIncluded";
3
+ import { calculateTotalTaxesOverPrice } from "./calculateTotalTaxesOverPrice";
4
+ import { getCreditApplied, getProductLineTotals, getShippingCost } from "./helpers";
5
+ export const calculateOrderTotal = (order, selectedCustomer, storeSettings, hasShippingCost, storeDiscounts = [], discountCodeObj, redeemPointsDiscount = 0 // 💡 NUEVO parámetro
6
+ ) => {
9
7
  var _a;
10
8
  try {
11
9
  const appliedOrderDiscounts = {};
12
- const productTableCalculator = (storeSettings === null || storeSettings === void 0 ? void 0 : storeSettings.taxesType) === 'over_price' ? calculateTotalTaxesOverPrice_1.calculateTotalTaxesOverPrice : calculateTotalTaxesIncluded_1.calculateTotalTaxesIncluded;
10
+ const productTableCalculator = (storeSettings === null || storeSettings === void 0 ? void 0 : storeSettings.taxesType) === 'over_price'
11
+ ? calculateTotalTaxesOverPrice
12
+ : calculateTotalTaxesIncluded;
13
13
  const productTableImports = productTableCalculator(order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj);
14
- // PRODUCT LINE TOTALS
15
- const { totalQuantity, totalImportWithDiscount, totalImportWithoutDiscount, totalImporTaxes, totalDiscountAmount } = (0, helpers_1.getProductLineTotals)(productTableImports);
16
- // DISCOUNT TOTAL AND SHIPPING SERVICE COST
14
+ // === PRODUCT LINE TOTALS ===
15
+ const { totalQuantity, totalImportWithDiscount, totalImportWithoutDiscount, totalImporTaxes, totalDiscountAmount, totalSubtotalAmount } = getProductLineTotals(productTableImports);
16
+ // === DISCOUNT CODE (monetario tipo NUMBER que se aplica una sola vez) ===
17
17
  let discountCodeAmount = 0;
18
- let shippingCost = (0, helpers_1.getShippingCost)(discountCodeObj, hasShippingCost, storeSettings);
19
- if (discountCodeObj && discountCodeObj.type === enum_1.DiscountCodeTypes.NUMBER && discountCodeObj.applyOnceOnOrder) {
20
- const includesProducts = discountCodeObj.applyToAllProducts || order.products.some((curr) => discountCodeObj.products.includes(curr._id));
18
+ if (discountCodeObj &&
19
+ discountCodeObj.type === DiscountCodeTypes.NUMBER &&
20
+ discountCodeObj.applyOnceOnOrder) {
21
+ const includesProducts = discountCodeObj.applyToAllProducts ||
22
+ order.products.some((curr) => discountCodeObj.products.includes(curr._id));
21
23
  discountCodeAmount = includesProducts ? discountCodeObj.value : 0;
22
24
  }
23
- // ORDER TOTAL CALCULATION AND CREDIT APPLIED
24
- let orderTotalWithOutCredit = +(totalImportWithDiscount + totalImporTaxes + shippingCost - discountCodeAmount).toFixed(2);
25
- let creditApplied = (0, helpers_1.getCreditApplied)(selectedCustomer, orderTotalWithOutCredit);
26
- let orderTotal = +(orderTotalWithOutCredit - creditApplied).toFixed(2);
27
- return Object.assign(Object.assign({}, order), { totalQuantity, customerDiscount: order.discountCode ? 0 : (_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount, productTotal: totalImportWithDiscount, taxesTotal: totalImporTaxes, total: orderTotal, creditApplied, productTotalWithoutDiscount: totalImportWithoutDiscount, totalDiscountAmount: totalDiscountAmount + discountCodeAmount, shippingServiceTotal: shippingCost, appliedOrderDiscounts });
25
+ // === SHIPPING COST ===
26
+ const shippingCost = getShippingCost(discountCodeObj, hasShippingCost, storeSettings);
27
+ // === TOTAL ANTES DE CRÉDITOS/PUNTOS ===
28
+ const orderTotalWithOutCredit = +(totalImportWithDiscount +
29
+ shippingCost -
30
+ discountCodeAmount).toFixed(2);
31
+ // === APLICAR CRÉDITO Y PUNTOS REDIMIDOS ===
32
+ const creditApplied = getCreditApplied(selectedCustomer, orderTotalWithOutCredit);
33
+ const orderTotal = +(orderTotalWithOutCredit -
34
+ creditApplied -
35
+ redeemPointsDiscount).toFixed(2);
36
+ // === RETURN FINAL OBJECT ===
37
+ return Object.assign(Object.assign({}, order), { totalQuantity, customerDiscount: order.discountCode ? 0 : (_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount, productTotal: totalImportWithDiscount, taxesTotal: totalImporTaxes, total: orderTotal, creditApplied, redeemPointsApplied: redeemPointsDiscount, productTotalWithoutDiscount: totalImportWithoutDiscount, totalDiscountAmount: totalDiscountAmount + discountCodeAmount, shippingServiceTotal: shippingCost, appliedOrderDiscounts, subtotal: totalSubtotalAmount });
28
38
  }
29
39
  catch (error) {
30
40
  throw error;
31
41
  }
32
42
  };
33
- exports.calculateOrderTotal = calculateOrderTotal;
@@ -1,24 +1,35 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateTotalTaxesIncluded = void 0;
4
- const helpers_1 = require("./helpers");
5
- const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj) => {
1
+ import { DiscountCodeTypes } from "../../enum";
2
+ import { getProductTaxesPercentage } from "./helpers";
3
+ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj) => {
6
4
  const productTableImports = [...order.products, ...order.buyAndGetProducts].map((current) => {
7
5
  var _a, _b;
6
+ const qty = current.qty || 0;
7
+ const taxPercentage = getProductTaxesPercentage(current, storeSettings);
8
+ const taxFactor = 1 + taxPercentage / 100;
9
+ // Convertir extraAmount de bruto a neto
10
+ const extraAmountGross = current.extraAmount || 0;
11
+ const extraAmountNet = extraAmountGross / taxFactor;
12
+ // Precio bruto del producto (sin extraAmount)
13
+ const productGrossPrice = order.express ? current.expressPrice : current.price;
14
+ // Convertir precio bruto a neto
15
+ const unitNetPrice = productGrossPrice / taxFactor;
16
+ // Determinar el porcentaje de descuento (si aplica)
8
17
  let discPercentageInteger = 0;
9
18
  let productPercentageDiscount = 0;
10
19
  let customerDiscount = 0;
11
- let qty = current.qty || 0;
12
- const extraAmountPerUnit = current.extraAmount / qty;
13
- const prodPrice = (order.express ? current.expressPrice : current.price) + extraAmountPerUnit;
14
20
  if (!order.discountCode) {
15
- const discountsToApply = storeDiscounts.filter((discount) => discount.products.includes(current._id) && discount.isActive);
21
+ const discountsToApply = storeDiscounts.filter((discount) => discount.isActive && discount.products.some((p) => {
22
+ if (typeof p === 'string') {
23
+ return p === current._id;
24
+ }
25
+ else if (typeof p === 'object') {
26
+ return p._id === current._id;
27
+ }
28
+ return false;
29
+ }));
16
30
  customerDiscount = ((_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount) || 0;
17
31
  productPercentageDiscount = discountsToApply.reduce((prev, next) => {
18
- if (next.type === 'percentage') {
19
- return prev + next.value;
20
- }
21
- return prev;
32
+ return next.type === 'percentage' ? prev + next.value : prev;
22
33
  }, 0);
23
34
  discPercentageInteger = +((productPercentageDiscount + customerDiscount) / 100).toFixed(2);
24
35
  discountsToApply.forEach((discount) => (appliedOrderDiscounts[discount._id] = discount));
@@ -38,28 +49,43 @@ const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettings, sto
38
49
  if (discountType === 'percentage' && current.isBuyAndGetProduct) {
39
50
  discPercentageInteger = +(discountValue / 100).toFixed(2);
40
51
  }
52
+ if (discountType === 'free' && current.isBuyAndGetProduct) {
53
+ discPercentageInteger = 1;
54
+ }
55
+ }
56
+ else if (discountCodeObj.type === DiscountCodeTypes.FREE_ITEM && (current.isFreeItem)) {
57
+ discPercentageInteger = 1;
41
58
  }
42
59
  }
43
- const taxPercentage = (0, helpers_1.getProductTaxesPercentage)(current, storeSettings);
44
- const taxPercentageInteger = taxPercentage / 100;
45
- const unitPrice = prodPrice / (1 + taxPercentageInteger);
46
- const discountAmountPerUnit = discPercentageInteger
47
- ? unitPrice * discPercentageInteger
48
- : (current.discountAmount || 0) / (1 + taxPercentageInteger);
49
- const prodPriceWithDiscountPerUnit = unitPrice - discountAmountPerUnit;
50
- const taxesAmountPerUnit = prodPriceWithDiscountPerUnit * taxPercentageInteger;
51
- const totalTaxesApplied = +(taxesAmountPerUnit * qty).toFixed(2);
52
- const lineDiscount = qty * discountAmountPerUnit;
53
- const prodLinePriceWithDiscount = +(qty * prodPriceWithDiscountPerUnit).toFixed(2);
60
+ // === NUEVO: Aplicar descuento sobre el precio total ajustado (producto base + extra prorrateado) ===
61
+ // Si hay cantidad, repartir el extra neto entre cada unidad
62
+ const unitExtraNet = qty > 0 ? extraAmountNet / qty : 0;
63
+ // Precio neto ajustado: precio base + extra (por unidad)
64
+ const adjustedUnitNetPrice = unitNetPrice + unitExtraNet;
65
+ // Calcular el descuento sobre el precio ajustado
66
+ const discountAmountPerUnit = discPercentageInteger ? adjustedUnitNetPrice * discPercentageInteger : 0;
67
+ // Precio neto con descuento aplicado por unidad
68
+ const discountedUnitNetPrice = adjustedUnitNetPrice - discountAmountPerUnit;
69
+ // === Totales de la línea ===
70
+ // Total neto sin descuento: precio base total + extra (ya prorrateado en el total)
71
+ const productNetTotalWithoutDiscount = (unitNetPrice * qty) + extraAmountNet;
72
+ // Total neto con descuento: se aplica el descuento sobre el precio ajustado por unidad
73
+ const productNetTotalWithDiscount = discountedUnitNetPrice * qty;
74
+ // Reaplicar IVA a ambos totales
75
+ const productLineImportTotal = +(productNetTotalWithoutDiscount * taxFactor).toFixed(2);
76
+ const productLineTotalWithDiscount = +(productNetTotalWithDiscount * taxFactor).toFixed(2);
77
+ // Calcular el total de impuestos como la diferencia entre bruto y neto con descuento
78
+ const totalTaxesApplied = +(productLineTotalWithDiscount - productNetTotalWithDiscount).toFixed(2);
79
+ const lineDiscount = +(discountAmountPerUnit * qty).toFixed(2);
54
80
  return {
55
81
  product: current,
56
- qty: qty,
57
- productLineImportTotal: unitPrice * qty,
58
- productLineTotalWithDiscount: prodLinePriceWithDiscount,
82
+ qty,
83
+ productLineImportTotal, // Total bruto sin descuento (incluye extra y IVA)
84
+ productLineTotalWithDiscount, // Total bruto con descuento aplicado sobre el precio ajustado
59
85
  productLineTaxesTotal: totalTaxesApplied,
60
- lineDiscountAmount: lineDiscount
86
+ lineDiscountAmount: lineDiscount,
87
+ productLineSubtotal: productNetTotalWithoutDiscount // Subtotal neto (sin IVA)
61
88
  };
62
89
  });
63
90
  return productTableImports;
64
91
  };
65
- exports.calculateTotalTaxesIncluded = calculateTotalTaxesIncluded;