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