washday-sdk 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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,33 @@
1
+ import { ICustomer } from "../../interfaces/Customer";
2
+ import { IOrderInfo } from "../../interfaces/Order";
3
+ import axiosInstance from "../axiosInstance";
4
+
5
+ const GET_SET_CUSTOMERS = 'api/customer';
6
+ const REQUEST_PARAMS = {
7
+ token: 'LOGGED_USER_TOKEN',
8
+ };
9
+
10
+ const getRequestToken = (): string => {
11
+ return this.apiToken;
12
+ }
13
+ export const getCustomerById = async function (customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
14
+ try {
15
+ REQUEST_PARAMS.token = getRequestToken();
16
+ const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: REQUEST_PARAMS });
17
+ return response.data;
18
+ } catch (error) {
19
+ console.error('Error fetching customer:', error);
20
+ throw error;
21
+ }
22
+ };
23
+
24
+ export const getCustomerHighlightsById = async function (customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
25
+ try {
26
+ REQUEST_PARAMS.token = getRequestToken();
27
+ const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: REQUEST_PARAMS });
28
+ return response.data;
29
+ } catch (error) {
30
+ console.error('Error fetching customer:', error);
31
+ throw error;
32
+ }
33
+ };
File without changes
@@ -0,0 +1,19 @@
1
+ import { getCustomerById, getCustomerHighlightsById } from "./customers/get";
2
+
3
+ type WashdayClientConstructor = {
4
+ new(apiToken: string): {
5
+ apiToken: string;
6
+ };
7
+ };
8
+
9
+ const WashdayClient: WashdayClientConstructor = function WashdayClient(apiToken: string) {
10
+ this.apiToken = apiToken;
11
+ } as any;
12
+
13
+ WashdayClient.prototype.customers = {
14
+ getCustomerById: getCustomerById,
15
+ getCustomerHighlightsById: getCustomerHighlightsById
16
+ };
17
+
18
+
19
+ export default WashdayClient;
package/src/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as utils from './utils';
2
+ import WashdayClient from './api';
2
3
 
3
4
  export {
4
- utils
5
+ utils,
6
+ WashdayClient
5
7
  }
@@ -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
+ }