washday-sdk 1.6.46 → 1.6.48
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/auth/get.js +22 -0
- package/dist/api/auth/index.js +1 -0
- package/dist/api/config/get.js +28 -0
- package/dist/api/config/index.js +1 -0
- package/dist/api/index.js +5 -0
- package/dist/index.js +2 -0
- package/dist/interfaces/Auth.js +1 -0
- package/dist/interfaces/Config.js +1 -0
- package/package.json +1 -1
- package/src/api/auth/get.ts +18 -0
- package/src/api/auth/index.ts +1 -0
- package/src/api/config/get.ts +26 -0
- package/src/api/config/index.ts +1 -0
- package/src/api/index.ts +5 -0
- package/src/index.ts +2 -0
- package/src/interfaces/Api.ts +5 -0
- package/src/interfaces/Auth.ts +9 -0
- package/src/interfaces/Config.ts +14 -0
- package/test/auth.signupCountrySuggestionBinding.test.ts +44 -0
- package/test/config.getTaxPresets.test.ts +91 -0
|
@@ -0,0 +1,22 @@
|
|
|
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 REGULAR_USER_AUTH = "api/auth";
|
|
11
|
+
export const getSignupCountrySuggestion = function () {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
try {
|
|
14
|
+
const config = {};
|
|
15
|
+
return yield this.axiosInstance.get(`${REGULAR_USER_AUTH}/signup-country-suggestion`, config);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error("Error fetching getSignupCountrySuggestion:", error);
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
};
|
package/dist/api/auth/index.js
CHANGED
|
@@ -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";
|
|
@@ -123,6 +124,7 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
|
|
|
123
124
|
customersAppForgotPassword: authEndpoints.postModule.customersAppForgotPassword,
|
|
124
125
|
customersAppChangePassword: authEndpoints.postModule.customersAppChangePassword,
|
|
125
126
|
companySignUp: authEndpoints.postModule.companySignUp,
|
|
127
|
+
getSignupCountrySuggestion: authEndpoints.getModule.getSignupCountrySuggestion,
|
|
126
128
|
});
|
|
127
129
|
this.orders = bindMethods(this, {
|
|
128
130
|
getList: ordersEndpoints.getModule.getList,
|
|
@@ -216,6 +218,9 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
|
|
|
216
218
|
this.countries = bindMethods(this, {
|
|
217
219
|
getCountries: getCountries,
|
|
218
220
|
});
|
|
221
|
+
this.config = bindMethods(this, {
|
|
222
|
+
getTaxPresets: configEndpoints.getModule.getTaxPresets,
|
|
223
|
+
});
|
|
219
224
|
this.supplies = bindMethods(this, {
|
|
220
225
|
getSupplies: getSupplies,
|
|
221
226
|
getSupplyById: getSupplyById,
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
|
|
3
|
+
const REGULAR_USER_AUTH = "api/auth";
|
|
4
|
+
|
|
5
|
+
export const getSignupCountrySuggestion = async function (
|
|
6
|
+
this: WashdayClientInstance,
|
|
7
|
+
): Promise<any> {
|
|
8
|
+
try {
|
|
9
|
+
const config = {};
|
|
10
|
+
return await this.axiosInstance.get(
|
|
11
|
+
`${REGULAR_USER_AUTH}/signup-country-suggestion`,
|
|
12
|
+
config,
|
|
13
|
+
);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error("Error fetching getSignupCountrySuggestion:", error);
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
};
|
package/src/api/auth/index.ts
CHANGED
|
@@ -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";
|
|
@@ -130,6 +131,7 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
|
|
|
130
131
|
customersAppForgotPassword: authEndpoints.postModule.customersAppForgotPassword,
|
|
131
132
|
customersAppChangePassword: authEndpoints.postModule.customersAppChangePassword,
|
|
132
133
|
companySignUp: authEndpoints.postModule.companySignUp,
|
|
134
|
+
getSignupCountrySuggestion: authEndpoints.getModule.getSignupCountrySuggestion,
|
|
133
135
|
});
|
|
134
136
|
this.orders = bindMethods(this, {
|
|
135
137
|
getList: ordersEndpoints.getModule.getList,
|
|
@@ -223,6 +225,9 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
|
|
|
223
225
|
this.countries = bindMethods(this, {
|
|
224
226
|
getCountries: getCountries,
|
|
225
227
|
});
|
|
228
|
+
this.config = bindMethods(this, {
|
|
229
|
+
getTaxPresets: configEndpoints.getModule.getTaxPresets,
|
|
230
|
+
});
|
|
226
231
|
this.supplies = bindMethods(this, {
|
|
227
232
|
getSupplies: getSupplies,
|
|
228
233
|
getSupplyById: getSupplyById,
|
package/src/index.ts
CHANGED
package/src/interfaces/Api.ts
CHANGED
|
@@ -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";
|
|
@@ -88,6 +89,7 @@ export interface WashdayClientInstance {
|
|
|
88
89
|
customersAppForgotPassword: typeof authEndpoints.postModule.customersAppForgotPassword;
|
|
89
90
|
customersAppChangePassword: typeof authEndpoints.postModule.customersAppChangePassword;
|
|
90
91
|
companySignUp: typeof authEndpoints.postModule.companySignUp;
|
|
92
|
+
getSignupCountrySuggestion: typeof authEndpoints.getModule.getSignupCountrySuggestion;
|
|
91
93
|
}
|
|
92
94
|
review: {
|
|
93
95
|
getList: typeof reviewsEndpoints.getModule.getList;
|
|
@@ -208,6 +210,9 @@ export interface WashdayClientInstance {
|
|
|
208
210
|
countries: {
|
|
209
211
|
getCountries: typeof getCountries;
|
|
210
212
|
};
|
|
213
|
+
config: {
|
|
214
|
+
getTaxPresets: typeof configEndpoints.getModule.getTaxPresets;
|
|
215
|
+
};
|
|
211
216
|
supplies: {
|
|
212
217
|
getSupplies: typeof getSupplies;
|
|
213
218
|
getSupplyById: typeof getSupplyById;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type SignupCountryIso = "MX" | "PE";
|
|
2
|
+
export type SignupCountrySuggestionSource = "ip" | "fallback" | "unknown";
|
|
3
|
+
export type SignupCountrySuggestionConfidence = "medium" | "low";
|
|
4
|
+
|
|
5
|
+
export interface SignupCountrySuggestion {
|
|
6
|
+
countryIso: SignupCountryIso;
|
|
7
|
+
source: SignupCountrySuggestionSource;
|
|
8
|
+
confidence: SignupCountrySuggestionConfidence;
|
|
9
|
+
}
|
|
@@ -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,44 @@
|
|
|
1
|
+
const mockGet = jest.fn().mockResolvedValue({
|
|
2
|
+
data: {
|
|
3
|
+
data: {
|
|
4
|
+
countryIso: "PE",
|
|
5
|
+
source: "ip",
|
|
6
|
+
confidence: "medium",
|
|
7
|
+
},
|
|
8
|
+
errors: null,
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
jest.mock("../src/api/axiosInstance", () => ({
|
|
13
|
+
__esModule: true,
|
|
14
|
+
getAxiosInstance: jest.fn(() => ({
|
|
15
|
+
get: mockGet,
|
|
16
|
+
interceptors: {
|
|
17
|
+
request: {
|
|
18
|
+
use: jest.fn(),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
})),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
import WashdayClient from "../src/api";
|
|
25
|
+
|
|
26
|
+
describe("WashdayClient signup country suggestion binding", () => {
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
jest.clearAllMocks();
|
|
29
|
+
mockGet.mockClear();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("binds auth.getSignupCountrySuggestion to the public GET endpoint", async () => {
|
|
33
|
+
const client = new (WashdayClient as any)("token-that-should-not-be-used");
|
|
34
|
+
|
|
35
|
+
const result = await client.auth.getSignupCountrySuggestion();
|
|
36
|
+
|
|
37
|
+
expect(mockGet).toHaveBeenCalledWith(
|
|
38
|
+
"api/auth/signup-country-suggestion",
|
|
39
|
+
{}
|
|
40
|
+
);
|
|
41
|
+
expect(result.data.data.countryIso).toBe("PE");
|
|
42
|
+
expect(result.data.errors).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -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
|
+
});
|