washday-sdk 1.0.0 → 1.0.2
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/axiosInstance.js +42 -0
- package/dist/api/customers/get.js +51 -0
- package/dist/api/customers/index.js +1 -0
- package/dist/api/index.js +11 -0
- package/dist/index.js +6 -1
- package/dist/interfaces/Api.js +3 -0
- package/package.json +1 -1
- package/src/api/axiosInstance.ts +45 -0
- package/src/api/customers/get.ts +32 -0
- package/src/api/customers/index.ts +0 -0
- package/src/api/index.ts +20 -0
- package/src/index.ts +3 -1
- package/src/interfaces/Api.ts +3 -0
- package/src/interfaces/Order.ts +12 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
// Define the type for the Axios instance
|
|
8
|
+
let axiosInstance = null;
|
|
9
|
+
const BASE_URL = 'https://washday-backend.herokuapp.com/';
|
|
10
|
+
// Function to create or return the singleton instance
|
|
11
|
+
const getAxiosInstance = () => {
|
|
12
|
+
if (!axiosInstance) {
|
|
13
|
+
axiosInstance = axios_1.default.create({
|
|
14
|
+
baseURL: BASE_URL,
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
// Add any default headers here
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
// Add interceptor to set token and other options for every request
|
|
21
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
22
|
+
const { token, contentType = 'application/json', responseType = 'json', contentDisposition } = config.params || {};
|
|
23
|
+
if (token) {
|
|
24
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
25
|
+
}
|
|
26
|
+
if (contentType) {
|
|
27
|
+
config.headers['Content-Type'] = contentType;
|
|
28
|
+
}
|
|
29
|
+
if (responseType) {
|
|
30
|
+
config.responseType = responseType;
|
|
31
|
+
}
|
|
32
|
+
if (contentDisposition) {
|
|
33
|
+
config.headers['Content-Disposition'] = contentDisposition;
|
|
34
|
+
}
|
|
35
|
+
return config;
|
|
36
|
+
}, (error) => {
|
|
37
|
+
return Promise.reject(error);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return axiosInstance;
|
|
41
|
+
};
|
|
42
|
+
exports.default = getAxiosInstance();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getCustomerHighlightsById = exports.getCustomerById = void 0;
|
|
16
|
+
const axiosInstance_1 = __importDefault(require("../axiosInstance"));
|
|
17
|
+
const GET_SET_CUSTOMERS = 'api/customer';
|
|
18
|
+
const REQUEST_PARAMS = {
|
|
19
|
+
token: 'LOGGED_USER_TOKEN',
|
|
20
|
+
};
|
|
21
|
+
const getRequestToken = () => {
|
|
22
|
+
return this.apiToken;
|
|
23
|
+
};
|
|
24
|
+
const getCustomerById = function (customerId) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
REQUEST_PARAMS.token = getRequestToken();
|
|
28
|
+
const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: REQUEST_PARAMS });
|
|
29
|
+
return response.data;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error('Error fetching customer:', error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
exports.getCustomerById = getCustomerById;
|
|
38
|
+
const getCustomerHighlightsById = function (customerId) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
try {
|
|
41
|
+
REQUEST_PARAMS.token = getRequestToken();
|
|
42
|
+
const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: REQUEST_PARAMS });
|
|
43
|
+
return response.data;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error('Error fetching customer:', error);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
exports.getCustomerHighlightsById = getCustomerHighlightsById;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const get_1 = require("./customers/get");
|
|
4
|
+
const WashdayClient = function WashdayClient(apiToken) {
|
|
5
|
+
this.apiToken = apiToken;
|
|
6
|
+
};
|
|
7
|
+
WashdayClient.prototype.customers = {
|
|
8
|
+
getCustomerById: get_1.getCustomerById,
|
|
9
|
+
getCustomerHighlightsById: get_1.getCustomerHighlightsById
|
|
10
|
+
};
|
|
11
|
+
exports.default = WashdayClient;
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.utils = void 0;
|
|
29
|
+
exports.WashdayClient = exports.utils = void 0;
|
|
27
30
|
const utils = __importStar(require("./utils"));
|
|
28
31
|
exports.utils = utils;
|
|
32
|
+
const api_1 = __importDefault(require("./api"));
|
|
33
|
+
exports.WashdayClient = api_1.default;
|
package/package.json
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
|
|
3
|
+
// Define the type for the Axios instance
|
|
4
|
+
let axiosInstance: AxiosInstance | null = null;
|
|
5
|
+
|
|
6
|
+
const BASE_URL: string = 'https://washday-backend.herokuapp.com/';
|
|
7
|
+
|
|
8
|
+
// Function to create or return the singleton instance
|
|
9
|
+
const getAxiosInstance = (): AxiosInstance => {
|
|
10
|
+
if (!axiosInstance) {
|
|
11
|
+
axiosInstance = axios.create({
|
|
12
|
+
baseURL: BASE_URL,
|
|
13
|
+
headers: {
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
// Add any default headers here
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Add interceptor to set token and other options for every request
|
|
20
|
+
axiosInstance.interceptors.request.use(
|
|
21
|
+
(config) => {
|
|
22
|
+
const { token, contentType = 'application/json', responseType = 'json', contentDisposition } = config.params || {};
|
|
23
|
+
if (token) {
|
|
24
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
25
|
+
}
|
|
26
|
+
if (contentType) {
|
|
27
|
+
config.headers['Content-Type'] = contentType;
|
|
28
|
+
}
|
|
29
|
+
if (responseType) {
|
|
30
|
+
config.responseType = responseType;
|
|
31
|
+
}
|
|
32
|
+
if (contentDisposition) {
|
|
33
|
+
config.headers['Content-Disposition'] = contentDisposition;
|
|
34
|
+
}
|
|
35
|
+
return config;
|
|
36
|
+
},
|
|
37
|
+
(error) => {
|
|
38
|
+
return Promise.reject(error);
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return axiosInstance;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default getAxiosInstance();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
import { ICustomer } from "../../interfaces/Customer";
|
|
3
|
+
import { IOrderInfo } from "../../interfaces/Order";
|
|
4
|
+
import axiosInstance from "../axiosInstance";
|
|
5
|
+
|
|
6
|
+
const GET_SET_CUSTOMERS = 'api/customer';
|
|
7
|
+
const REQUEST_PARAMS = {
|
|
8
|
+
token: 'LOGGED_USER_TOKEN',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export const getCustomerById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
|
|
13
|
+
try {
|
|
14
|
+
REQUEST_PARAMS.token = this.apiToken;
|
|
15
|
+
const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: REQUEST_PARAMS });
|
|
16
|
+
return response.data;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error('Error fetching customer:', error);
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getCustomerHighlightsById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
|
|
24
|
+
try {
|
|
25
|
+
REQUEST_PARAMS.token = this.apiToken;
|
|
26
|
+
const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: REQUEST_PARAMS });
|
|
27
|
+
return response.data;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('Error fetching customer:', error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
File without changes
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../interfaces/Api";
|
|
2
|
+
import { getCustomerById, getCustomerHighlightsById } from "./customers/get";
|
|
3
|
+
|
|
4
|
+
type WashdayClientConstructor = {
|
|
5
|
+
new(apiToken: string): {
|
|
6
|
+
apiToken: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const WashdayClient: WashdayClientConstructor = function WashdayClient(this: WashdayClientInstance, apiToken: string) {
|
|
11
|
+
this.apiToken = apiToken;
|
|
12
|
+
} as any;
|
|
13
|
+
|
|
14
|
+
WashdayClient.prototype.customers = {
|
|
15
|
+
getCustomerById: getCustomerById,
|
|
16
|
+
getCustomerHighlightsById: getCustomerHighlightsById
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export default WashdayClient;
|
package/src/index.ts
CHANGED
package/src/interfaces/Order.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ICustomer } from "./Customer";
|
|
2
|
-
import { IOrderProduct } from "./Product";
|
|
2
|
+
import { IOrderProduct, IProduct } from "./Product";
|
|
3
3
|
import { ICashierBox, IStore, ITaxConfig } from "./Store";
|
|
4
4
|
import { IUser } from "./User";
|
|
5
5
|
|
|
@@ -83,3 +83,14 @@ export interface IOrder {
|
|
|
83
83
|
paymentLines: Array<IOrderPaymentLines> | Array<string> | any,
|
|
84
84
|
facturapiInvoiceID?: string | null,
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export interface IOrderInfo {
|
|
89
|
+
topProducts: IProduct[];
|
|
90
|
+
sales: number;
|
|
91
|
+
totalOrderQuantities: number;
|
|
92
|
+
paidFromCredit: number;
|
|
93
|
+
paid: number;
|
|
94
|
+
unpaid: number;
|
|
95
|
+
lastOrderDate: Date;
|
|
96
|
+
}
|