washday-sdk 1.6.46 → 1.6.47

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.
@@ -0,0 +1,28 @@
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 GET_SET_CONFIG = "api/config";
11
+ export const getTaxPresets = function (params) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ try {
14
+ const config = Object.assign({ headers: { Authorization: `Bearer ${this.apiToken}` } }, ((params === null || params === void 0 ? void 0 : params.country)
15
+ ? {
16
+ params: {
17
+ country: params.country,
18
+ },
19
+ }
20
+ : {}));
21
+ return yield this.axiosInstance.get(`${GET_SET_CONFIG}/tax-presets`, config);
22
+ }
23
+ catch (error) {
24
+ console.error("Error fetching getTaxPresets:", error);
25
+ throw error;
26
+ }
27
+ });
28
+ };
@@ -0,0 +1 @@
1
+ export * as getModule from "./get";
package/dist/api/index.js CHANGED
@@ -6,6 +6,7 @@ import { getCompanyById, getCompanyOrdersMetrics, getGarmentAttributeCatalogs }
6
6
  import { disableBillingOverage, enableBillingOverage, updateCFDIOrgLogo, updateCompanyTaxInfoCertificates } from "./companies/post";
7
7
  import { updateCompanyById, updateCompanyLogoById, updateCompanySubscriptionBillingInfoById, updateCompanyTaxInfoById, updateGarmentAttributeCatalogsById } from "./companies/put";
8
8
  import { getCountries } from "./countries/get";
9
+ import * as configEndpoints from "./config";
9
10
  import { getAutomaticDiscountById, getAutomaticDiscounts, getAvailableAutomaticDiscounts, getDiscountCodeById, getDiscountCodes, verifyDiscountCode, verifyDiscountCodeCustomersApp } from './discounts/get';
10
11
  import { createAutomaticDiscount, createDiscountCode } from "./discounts/post";
11
12
  import { deleteAutomaticDiscountById, deleteDiscountCodeById, updateAutomaticDiscountById, updateDiscountCodeById } from "./discounts/put";
@@ -216,6 +217,9 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
216
217
  this.countries = bindMethods(this, {
217
218
  getCountries: getCountries,
218
219
  });
220
+ this.config = bindMethods(this, {
221
+ getTaxPresets: configEndpoints.getModule.getTaxPresets,
222
+ });
219
223
  this.supplies = bindMethods(this, {
220
224
  getSupplies: getSupplies,
221
225
  getSupplyById: getSupplyById,
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as utils from './utils';
2
2
  import WashdayClient from './api';
3
3
  export * from './interfaces/Company';
4
+ export * from './interfaces/Config';
4
5
  export * from './interfaces/Cfdi';
5
6
  export { WashdayClient, utils };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "1.6.46",
3
+ "version": "1.6.47",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -0,0 +1,26 @@
1
+ import { WashdayClientInstance } from "../../interfaces/Api";
2
+
3
+ const GET_SET_CONFIG = "api/config";
4
+
5
+ export const getTaxPresets = async function (
6
+ this: WashdayClientInstance,
7
+ params?: { country?: string }
8
+ ): Promise<any> {
9
+ try {
10
+ const config = {
11
+ headers: { Authorization: `Bearer ${this.apiToken}` },
12
+ ...(params?.country
13
+ ? {
14
+ params: {
15
+ country: params.country,
16
+ },
17
+ }
18
+ : {}),
19
+ };
20
+
21
+ return await this.axiosInstance.get(`${GET_SET_CONFIG}/tax-presets`, config);
22
+ } catch (error) {
23
+ console.error("Error fetching getTaxPresets:", error);
24
+ throw error;
25
+ }
26
+ };
@@ -0,0 +1 @@
1
+ export * as getModule from "./get";
package/src/api/index.ts CHANGED
@@ -7,6 +7,7 @@ import { getCompanyById, getCompanyOrdersMetrics, getGarmentAttributeCatalogs }
7
7
  import { disableBillingOverage, enableBillingOverage, updateCFDIOrgLogo, updateCompanyTaxInfoCertificates } from "./companies/post";
8
8
  import { updateCompanyById, updateCompanyLogoById, updateCompanySubscriptionBillingInfoById, updateCompanyTaxInfoById, updateGarmentAttributeCatalogsById } from "./companies/put";
9
9
  import { getCountries } from "./countries/get";
10
+ import * as configEndpoints from "./config";
10
11
  import { getAutomaticDiscountById, getAutomaticDiscounts, getAvailableAutomaticDiscounts, getDiscountCodeById, getDiscountCodes, verifyDiscountCode, verifyDiscountCodeCustomersApp } from './discounts/get';
11
12
  import { createAutomaticDiscount, createDiscountCode } from "./discounts/post";
12
13
  import { deleteAutomaticDiscountById, deleteDiscountCodeById, updateAutomaticDiscountById, updateDiscountCodeById } from "./discounts/put";
@@ -223,6 +224,9 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
223
224
  this.countries = bindMethods(this, {
224
225
  getCountries: getCountries,
225
226
  });
227
+ this.config = bindMethods(this, {
228
+ getTaxPresets: configEndpoints.getModule.getTaxPresets,
229
+ });
226
230
  this.supplies = bindMethods(this, {
227
231
  getSupplies: getSupplies,
228
232
  getSupplyById: getSupplyById,
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as utils from './utils';
2
2
  import WashdayClient from './api';
3
3
  export * from './interfaces/Company';
4
+ export * from './interfaces/Config';
4
5
  export * from './interfaces/Cfdi';
5
6
 
6
7
  export { WashdayClient, utils };
@@ -6,6 +6,7 @@ import { getCompanyById, getCompanyOrdersMetrics, getGarmentAttributeCatalogs }
6
6
  import { disableBillingOverage, enableBillingOverage, updateCFDIOrgLogo, updateCompanyTaxInfoCertificates } from "../api/companies/post";
7
7
  import { updateCompanyById, updateCompanyLogoById, updateCompanySubscriptionBillingInfoById, updateCompanyTaxInfoById, updateGarmentAttributeCatalogsById } from "../api/companies/put";
8
8
  import { getCountries } from "../api/countries/get";
9
+ import * as configEndpoints from "../api/config";
9
10
  import { getAutomaticDiscountById, getAutomaticDiscounts, getAvailableAutomaticDiscounts, getDiscountCodeById, getDiscountCodes, verifyDiscountCode, verifyDiscountCodeCustomersApp } from '../api/discounts/get';
10
11
  import { createAutomaticDiscount, createDiscountCode } from "../api/discounts/post";
11
12
  import { deleteAutomaticDiscountById, deleteDiscountCodeById, updateAutomaticDiscountById, updateDiscountCodeById } from "../api/discounts/put";
@@ -208,6 +209,9 @@ export interface WashdayClientInstance {
208
209
  countries: {
209
210
  getCountries: typeof getCountries;
210
211
  };
212
+ config: {
213
+ getTaxPresets: typeof configEndpoints.getModule.getTaxPresets;
214
+ };
211
215
  supplies: {
212
216
  getSupplies: typeof getSupplies;
213
217
  getSupplyById: typeof getSupplyById;
@@ -0,0 +1,14 @@
1
+ export type TaxPreset = {
2
+ country: string;
3
+ code: string;
4
+ label: string;
5
+ defaultRate: number;
6
+ description?: string;
7
+ isDefault?: boolean;
8
+ advanced?: boolean;
9
+ };
10
+
11
+ export type GetTaxPresetsResponse = {
12
+ country: string;
13
+ items: TaxPreset[];
14
+ };
@@ -0,0 +1,91 @@
1
+ import WashdayClient from "../src/api";
2
+ import { getTaxPresets } from "../src/api/config/get";
3
+
4
+ describe("getTaxPresets", () => {
5
+ it("calls the tax preset endpoint with MX", async () => {
6
+ const get = jest.fn().mockResolvedValue({
7
+ data: {
8
+ data: {
9
+ country: "MX",
10
+ items: [{ code: "IVA" }],
11
+ },
12
+ },
13
+ });
14
+ const client = {
15
+ apiToken: "token-1",
16
+ axiosInstance: { get },
17
+ } as any;
18
+
19
+ const result = await getTaxPresets.call(client, { country: "MX" });
20
+
21
+ expect(get).toHaveBeenCalledWith("api/config/tax-presets", {
22
+ headers: { Authorization: "Bearer token-1" },
23
+ params: { country: "MX" },
24
+ });
25
+ expect(result.data.data.country).toBe("MX");
26
+ });
27
+
28
+ it("calls the tax preset endpoint with PE", async () => {
29
+ const get = jest.fn().mockResolvedValue({
30
+ data: {
31
+ data: {
32
+ country: "PE",
33
+ items: [{ code: "IGV", defaultRate: 18 }],
34
+ },
35
+ },
36
+ });
37
+ const client = {
38
+ apiToken: "token-2",
39
+ axiosInstance: { get },
40
+ } as any;
41
+
42
+ const result = await getTaxPresets.call(client, { country: "PE" });
43
+
44
+ expect(get).toHaveBeenCalledWith("api/config/tax-presets", {
45
+ headers: { Authorization: "Bearer token-2" },
46
+ params: { country: "PE" },
47
+ });
48
+ expect(result.data.data.items[0].code).toBe("IGV");
49
+ });
50
+
51
+ it("calls the tax preset endpoint without params when country is missing", async () => {
52
+ const get = jest.fn().mockResolvedValue({
53
+ data: {
54
+ data: {
55
+ country: "MX",
56
+ items: [],
57
+ },
58
+ },
59
+ });
60
+ const client = {
61
+ apiToken: "token-3",
62
+ axiosInstance: { get },
63
+ } as any;
64
+
65
+ const result = await getTaxPresets.call(client);
66
+
67
+ expect(get).toHaveBeenCalledWith("api/config/tax-presets", {
68
+ headers: { Authorization: "Bearer token-3" },
69
+ });
70
+ expect(result.data.data.items).toEqual([]);
71
+ });
72
+
73
+ it("binds the config namespace on WashdayClient", async () => {
74
+ const client = new (WashdayClient as any)("token-4", "DEV");
75
+ client.axiosInstance.get = jest.fn().mockResolvedValue({
76
+ data: {
77
+ data: {
78
+ country: "MX",
79
+ items: [{ code: "IVA" }],
80
+ },
81
+ },
82
+ });
83
+
84
+ await client.config.getTaxPresets({ country: "MX" });
85
+
86
+ expect(client.axiosInstance.get).toHaveBeenCalledWith("api/config/tax-presets", {
87
+ headers: { Authorization: "Bearer token-4" },
88
+ params: { country: "MX" },
89
+ });
90
+ });
91
+ });