washday-sdk 0.0.8 → 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/dist/index.js CHANGED
@@ -22,12 +22,7 @@ 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
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.utils = exports.WashdayClient = void 0;
26
+ exports.utils = void 0;
30
27
  const utils = __importStar(require("./utils"));
31
28
  exports.utils = utils;
32
- const api_1 = __importDefault(require("./api"));
33
- exports.WashdayClient = api_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "0.0.8",
3
+ "version": "1.0.1",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,4 +1,3 @@
1
- import { WashdayClientInstance } from "../../interfaces/Api";
2
1
  import { ICustomer } from "../../interfaces/Customer";
3
2
  import { IOrderInfo } from "../../interfaces/Order";
4
3
  import axiosInstance from "../axiosInstance";
@@ -8,11 +7,13 @@ const REQUEST_PARAMS = {
8
7
  token: 'LOGGED_USER_TOKEN',
9
8
  };
10
9
 
11
-
12
- export const getCustomerById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
10
+ const getRequestToken = (): string => {
11
+ return this.apiToken;
12
+ }
13
+ export const getCustomerById = async function (customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
13
14
  try {
14
- REQUEST_PARAMS.token = this.apiToken;
15
- const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: { ...REQUEST_PARAMS } });
15
+ REQUEST_PARAMS.token = getRequestToken();
16
+ const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: REQUEST_PARAMS });
16
17
  return response.data;
17
18
  } catch (error) {
18
19
  console.error('Error fetching customer:', error);
@@ -20,10 +21,10 @@ export const getCustomerById = async function (this: WashdayClientInstance, cust
20
21
  }
21
22
  };
22
23
 
23
- export const getCustomerHighlightsById = async function (this: WashdayClientInstance, customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
24
+ export const getCustomerHighlightsById = async function (customerId: string): Promise<{ customer: ICustomer, orderInfo: IOrderInfo }> {
24
25
  try {
25
- REQUEST_PARAMS.token = this.apiToken;
26
- const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: { ...REQUEST_PARAMS } });
26
+ REQUEST_PARAMS.token = getRequestToken();
27
+ const response = await axiosInstance.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: REQUEST_PARAMS });
27
28
  return response.data;
28
29
  } catch (error) {
29
30
  console.error('Error fetching customer:', error);
package/src/api/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { WashdayClientInstance } from "../interfaces/Api";
2
1
  import { getCustomerById, getCustomerHighlightsById } from "./customers/get";
3
2
 
4
3
  type WashdayClientConstructor = {
@@ -7,9 +6,8 @@ type WashdayClientConstructor = {
7
6
  };
8
7
  };
9
8
 
10
- const WashdayClient: WashdayClientConstructor = function WashdayClient(this: WashdayClientInstance, apiToken: string) {
9
+ const WashdayClient: WashdayClientConstructor = function WashdayClient(apiToken: string) {
11
10
  this.apiToken = apiToken;
12
- WashdayClient.prototype.customers.apiToken = apiToken;
13
11
  } as any;
14
12
 
15
13
  WashdayClient.prototype.customers = {
package/src/index.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import * as utils from './utils';
2
2
  import WashdayClient from './api';
3
3
 
4
- export { WashdayClient, utils };
4
+ export {
5
+ utils,
6
+ WashdayClient
7
+ }
@@ -1,42 +0,0 @@
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();
@@ -1,48 +0,0 @@
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 getCustomerById = function (customerId) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- try {
24
- REQUEST_PARAMS.token = this.apiToken;
25
- const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}`, { params: Object.assign({}, REQUEST_PARAMS) });
26
- return response.data;
27
- }
28
- catch (error) {
29
- console.error('Error fetching customer:', error);
30
- throw error;
31
- }
32
- });
33
- };
34
- exports.getCustomerById = getCustomerById;
35
- const getCustomerHighlightsById = function (customerId) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- try {
38
- REQUEST_PARAMS.token = this.apiToken;
39
- const response = yield axiosInstance_1.default.get(`${GET_SET_CUSTOMERS}/${customerId}/highlights`, { params: Object.assign({}, REQUEST_PARAMS) });
40
- return response.data;
41
- }
42
- catch (error) {
43
- console.error('Error fetching customer:', error);
44
- throw error;
45
- }
46
- });
47
- };
48
- exports.getCustomerHighlightsById = getCustomerHighlightsById;
@@ -1 +0,0 @@
1
- "use strict";
package/dist/api/index.js DELETED
@@ -1,12 +0,0 @@
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
- WashdayClient.prototype.customers.apiToken = apiToken;
7
- };
8
- WashdayClient.prototype.customers = {
9
- getCustomerById: get_1.getCustomerById,
10
- getCustomerHighlightsById: get_1.getCustomerHighlightsById
11
- };
12
- exports.default = WashdayClient;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export type WashdayClientInstance = {
2
- apiToken: string;
3
- };