washday-sdk 1.6.54 → 1.6.55

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 @@
1
+ export * as postModule from "./post";
@@ -0,0 +1,56 @@
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 GOOGLE_MAPS_PROXY = "api/v2/google-maps";
11
+ const CUSTOMERS_APP_GOOGLE_MAPS_PROXY = "api/v2/washdayapp/google-maps";
12
+ function authConfig() {
13
+ return {
14
+ headers: { Authorization: `Bearer ${this.apiToken}` },
15
+ };
16
+ }
17
+ export const autocompleteCustomersApp = function (payload) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ return yield this.axiosInstance.post(`${CUSTOMERS_APP_GOOGLE_MAPS_PROXY}/autocomplete`, payload, authConfig.call(this));
20
+ });
21
+ };
22
+ export const placeDetailsCustomersApp = function (payload) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ return yield this.axiosInstance.post(`${CUSTOMERS_APP_GOOGLE_MAPS_PROXY}/place-details`, payload, authConfig.call(this));
25
+ });
26
+ };
27
+ export const geocodeCustomersApp = function (payload) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ return yield this.axiosInstance.post(`${CUSTOMERS_APP_GOOGLE_MAPS_PROXY}/geocode`, payload, authConfig.call(this));
30
+ });
31
+ };
32
+ export const reverseGeocodeCustomersApp = function (payload) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return yield this.axiosInstance.post(`${CUSTOMERS_APP_GOOGLE_MAPS_PROXY}/reverse-geocode`, payload, authConfig.call(this));
35
+ });
36
+ };
37
+ export const autocomplete = function (payload) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return yield this.axiosInstance.post(`${GOOGLE_MAPS_PROXY}/autocomplete`, payload, authConfig.call(this));
40
+ });
41
+ };
42
+ export const placeDetails = function (payload) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ return yield this.axiosInstance.post(`${GOOGLE_MAPS_PROXY}/place-details`, payload, authConfig.call(this));
45
+ });
46
+ };
47
+ export const geocode = function (payload) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return yield this.axiosInstance.post(`${GOOGLE_MAPS_PROXY}/geocode`, payload, authConfig.call(this));
50
+ });
51
+ };
52
+ export const reverseGeocode = function (payload) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ return yield this.axiosInstance.post(`${GOOGLE_MAPS_PROXY}/reverse-geocode`, payload, authConfig.call(this));
55
+ });
56
+ };
package/dist/api/index.js CHANGED
@@ -47,6 +47,7 @@ import { getAxiosInstance } from "./axiosInstance";
47
47
  import * as integrationsEndpoints from './integrations';
48
48
  import * as updatesEndpoints from './updates';
49
49
  import * as intercomEndpoints from './intercom';
50
+ import * as googleMapsEndpoints from './googleMaps';
50
51
  function bindMethods(instance, methods) {
51
52
  const boundMethods = {};
52
53
  for (const key in methods) {
@@ -223,6 +224,16 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
223
224
  this.config = bindMethods(this, {
224
225
  getTaxPresets: configEndpoints.getModule.getTaxPresets,
225
226
  });
227
+ this.googleMaps = bindMethods(this, {
228
+ autocompleteCustomersApp: googleMapsEndpoints.postModule.autocompleteCustomersApp,
229
+ placeDetailsCustomersApp: googleMapsEndpoints.postModule.placeDetailsCustomersApp,
230
+ geocodeCustomersApp: googleMapsEndpoints.postModule.geocodeCustomersApp,
231
+ reverseGeocodeCustomersApp: googleMapsEndpoints.postModule.reverseGeocodeCustomersApp,
232
+ autocomplete: googleMapsEndpoints.postModule.autocomplete,
233
+ placeDetails: googleMapsEndpoints.postModule.placeDetails,
234
+ geocode: googleMapsEndpoints.postModule.geocode,
235
+ reverseGeocode: googleMapsEndpoints.postModule.reverseGeocode,
236
+ });
226
237
  this.supplies = bindMethods(this, {
227
238
  getSupplies: getSupplies,
228
239
  getSupplyById: getSupplyById,
package/dist/index.js CHANGED
@@ -5,4 +5,5 @@ export * from './interfaces/Config';
5
5
  export * from './interfaces/Cfdi';
6
6
  export * from './interfaces/Auth';
7
7
  export * from './interfaces/Customer';
8
+ export * from './interfaces/GoogleMaps';
8
9
  export { WashdayClient, utils };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "1.6.54",
3
+ "version": "1.6.55",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -0,0 +1 @@
1
+ export * as postModule from "./post";
@@ -0,0 +1,108 @@
1
+ import { WashdayClientInstance } from "../../interfaces/Api";
2
+ import {
3
+ GoogleMapsAutocompletePayload,
4
+ GoogleMapsAutocompleteResponse,
5
+ GoogleMapsGeocodePayload,
6
+ GoogleMapsGeocodeResponse,
7
+ GoogleMapsPlaceDetailsPayload,
8
+ GoogleMapsPlaceDetailsResponse,
9
+ GoogleMapsReverseGeocodePayload,
10
+ GoogleMapsReverseGeocodeResponse,
11
+ } from "../../interfaces/GoogleMaps";
12
+
13
+ const GOOGLE_MAPS_PROXY = "api/v2/google-maps";
14
+ const CUSTOMERS_APP_GOOGLE_MAPS_PROXY = "api/v2/washdayapp/google-maps";
15
+
16
+ function authConfig(this: WashdayClientInstance) {
17
+ return {
18
+ headers: { Authorization: `Bearer ${this.apiToken}` },
19
+ };
20
+ }
21
+
22
+ export const autocompleteCustomersApp = async function (
23
+ this: WashdayClientInstance,
24
+ payload: GoogleMapsAutocompletePayload
25
+ ): Promise<GoogleMapsAutocompleteResponse> {
26
+ return await this.axiosInstance.post(
27
+ `${CUSTOMERS_APP_GOOGLE_MAPS_PROXY}/autocomplete`,
28
+ payload,
29
+ authConfig.call(this)
30
+ );
31
+ };
32
+
33
+ export const placeDetailsCustomersApp = async function (
34
+ this: WashdayClientInstance,
35
+ payload: GoogleMapsPlaceDetailsPayload
36
+ ): Promise<GoogleMapsPlaceDetailsResponse> {
37
+ return await this.axiosInstance.post(
38
+ `${CUSTOMERS_APP_GOOGLE_MAPS_PROXY}/place-details`,
39
+ payload,
40
+ authConfig.call(this)
41
+ );
42
+ };
43
+
44
+ export const geocodeCustomersApp = async function (
45
+ this: WashdayClientInstance,
46
+ payload: GoogleMapsGeocodePayload
47
+ ): Promise<GoogleMapsGeocodeResponse> {
48
+ return await this.axiosInstance.post(
49
+ `${CUSTOMERS_APP_GOOGLE_MAPS_PROXY}/geocode`,
50
+ payload,
51
+ authConfig.call(this)
52
+ );
53
+ };
54
+
55
+ export const reverseGeocodeCustomersApp = async function (
56
+ this: WashdayClientInstance,
57
+ payload: GoogleMapsReverseGeocodePayload
58
+ ): Promise<GoogleMapsReverseGeocodeResponse> {
59
+ return await this.axiosInstance.post(
60
+ `${CUSTOMERS_APP_GOOGLE_MAPS_PROXY}/reverse-geocode`,
61
+ payload,
62
+ authConfig.call(this)
63
+ );
64
+ };
65
+
66
+ export const autocomplete = async function (
67
+ this: WashdayClientInstance,
68
+ payload: GoogleMapsAutocompletePayload
69
+ ): Promise<GoogleMapsAutocompleteResponse> {
70
+ return await this.axiosInstance.post(
71
+ `${GOOGLE_MAPS_PROXY}/autocomplete`,
72
+ payload,
73
+ authConfig.call(this)
74
+ );
75
+ };
76
+
77
+ export const placeDetails = async function (
78
+ this: WashdayClientInstance,
79
+ payload: GoogleMapsPlaceDetailsPayload
80
+ ): Promise<GoogleMapsPlaceDetailsResponse> {
81
+ return await this.axiosInstance.post(
82
+ `${GOOGLE_MAPS_PROXY}/place-details`,
83
+ payload,
84
+ authConfig.call(this)
85
+ );
86
+ };
87
+
88
+ export const geocode = async function (
89
+ this: WashdayClientInstance,
90
+ payload: GoogleMapsGeocodePayload
91
+ ): Promise<GoogleMapsGeocodeResponse> {
92
+ return await this.axiosInstance.post(
93
+ `${GOOGLE_MAPS_PROXY}/geocode`,
94
+ payload,
95
+ authConfig.call(this)
96
+ );
97
+ };
98
+
99
+ export const reverseGeocode = async function (
100
+ this: WashdayClientInstance,
101
+ payload: GoogleMapsReverseGeocodePayload
102
+ ): Promise<GoogleMapsReverseGeocodeResponse> {
103
+ return await this.axiosInstance.post(
104
+ `${GOOGLE_MAPS_PROXY}/reverse-geocode`,
105
+ payload,
106
+ authConfig.call(this)
107
+ );
108
+ };
package/src/api/index.ts CHANGED
@@ -49,6 +49,7 @@ import { getAxiosInstance } from "./axiosInstance";
49
49
  import * as integrationsEndpoints from './integrations';
50
50
  import * as updatesEndpoints from './updates';
51
51
  import * as intercomEndpoints from './intercom';
52
+ import * as googleMapsEndpoints from './googleMaps';
52
53
 
53
54
  type WashdayClientConstructor = {
54
55
  new(apiToken: string, env?: string, clientId?: string, clientSecret?: string): WashdayClientInstance
@@ -230,6 +231,16 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
230
231
  this.config = bindMethods(this, {
231
232
  getTaxPresets: configEndpoints.getModule.getTaxPresets,
232
233
  });
234
+ this.googleMaps = bindMethods(this, {
235
+ autocompleteCustomersApp: googleMapsEndpoints.postModule.autocompleteCustomersApp,
236
+ placeDetailsCustomersApp: googleMapsEndpoints.postModule.placeDetailsCustomersApp,
237
+ geocodeCustomersApp: googleMapsEndpoints.postModule.geocodeCustomersApp,
238
+ reverseGeocodeCustomersApp: googleMapsEndpoints.postModule.reverseGeocodeCustomersApp,
239
+ autocomplete: googleMapsEndpoints.postModule.autocomplete,
240
+ placeDetails: googleMapsEndpoints.postModule.placeDetails,
241
+ geocode: googleMapsEndpoints.postModule.geocode,
242
+ reverseGeocode: googleMapsEndpoints.postModule.reverseGeocode,
243
+ });
233
244
  this.supplies = bindMethods(this, {
234
245
  getSupplies: getSupplies,
235
246
  getSupplyById: getSupplyById,
package/src/index.ts CHANGED
@@ -5,5 +5,6 @@ export * from './interfaces/Config';
5
5
  export * from './interfaces/Cfdi';
6
6
  export * from './interfaces/Auth';
7
7
  export * from './interfaces/Customer';
8
+ export * from './interfaces/GoogleMaps';
8
9
 
9
10
  export { WashdayClient, utils };
@@ -45,6 +45,7 @@ import * as publicsEndpoints from '../api/publics';
45
45
  import * as integrationsEndpoints from '../api/integrations';
46
46
  import * as updatesEndpoints from '../api/updates';
47
47
  import * as intercomEndpoints from '../api/intercom';
48
+ import * as googleMapsEndpoints from '../api/googleMaps';
48
49
  import { validateUserPin } from "../api/users/post";
49
50
  import { AxiosInstance } from "axios";
50
51
 
@@ -215,6 +216,16 @@ export interface WashdayClientInstance {
215
216
  config: {
216
217
  getTaxPresets: typeof configEndpoints.getModule.getTaxPresets;
217
218
  };
219
+ googleMaps: {
220
+ autocompleteCustomersApp: typeof googleMapsEndpoints.postModule.autocompleteCustomersApp;
221
+ placeDetailsCustomersApp: typeof googleMapsEndpoints.postModule.placeDetailsCustomersApp;
222
+ geocodeCustomersApp: typeof googleMapsEndpoints.postModule.geocodeCustomersApp;
223
+ reverseGeocodeCustomersApp: typeof googleMapsEndpoints.postModule.reverseGeocodeCustomersApp;
224
+ autocomplete: typeof googleMapsEndpoints.postModule.autocomplete;
225
+ placeDetails: typeof googleMapsEndpoints.postModule.placeDetails;
226
+ geocode: typeof googleMapsEndpoints.postModule.geocode;
227
+ reverseGeocode: typeof googleMapsEndpoints.postModule.reverseGeocode;
228
+ };
218
229
  supplies: {
219
230
  getSupplies: typeof getSupplies;
220
231
  getSupplyById: typeof getSupplyById;
@@ -0,0 +1,97 @@
1
+ export interface GoogleMapsLatLng {
2
+ lat: number;
3
+ lng: number;
4
+ }
5
+
6
+ export interface GoogleMapsLocationBias {
7
+ circle: {
8
+ center: {
9
+ latitude: number;
10
+ longitude: number;
11
+ };
12
+ radius: number;
13
+ };
14
+ }
15
+
16
+ export interface GoogleMapsAutocompletePayload {
17
+ input: string;
18
+ sessionToken: string;
19
+ storeId?: string;
20
+ locationBias?: GoogleMapsLocationBias;
21
+ regionCode?: string;
22
+ }
23
+
24
+ export interface GoogleMapsPlaceDetailsPayload {
25
+ placeId?: string;
26
+ placeResourceName?: string;
27
+ sessionToken: string;
28
+ storeId?: string;
29
+ }
30
+
31
+ export interface GoogleMapsGeocodePayload {
32
+ address: string;
33
+ storeId?: string;
34
+ regionCode?: string;
35
+ }
36
+
37
+ export interface GoogleMapsReverseGeocodePayload {
38
+ latLng: GoogleMapsLatLng;
39
+ storeId?: string;
40
+ }
41
+
42
+ export interface GoogleMapsParsedAddressComponents {
43
+ street?: string;
44
+ number?: string;
45
+ neighborhood?: string;
46
+ postalCode?: string;
47
+ city?: string;
48
+ state?: string;
49
+ country?: string;
50
+ }
51
+
52
+ export interface GoogleMapsAutocompleteSuggestion {
53
+ placeId: string;
54
+ placeResourceName: string;
55
+ text: string;
56
+ }
57
+
58
+ export interface GoogleMapsPlaceDetailsResult {
59
+ placeId: string;
60
+ placeResourceName: string;
61
+ formattedAddress?: string;
62
+ latLng: GoogleMapsLatLng;
63
+ address: GoogleMapsParsedAddressComponents;
64
+ }
65
+
66
+ export interface GoogleMapsGeocodeResult {
67
+ placeId?: string;
68
+ formattedAddress?: string;
69
+ latLng: GoogleMapsLatLng;
70
+ address: GoogleMapsParsedAddressComponents;
71
+ }
72
+
73
+ export interface GoogleMapsAutocompleteResponse {
74
+ data: {
75
+ suggestions: GoogleMapsAutocompleteSuggestion[];
76
+ };
77
+ errors?: string[];
78
+ }
79
+
80
+ export interface GoogleMapsPlaceDetailsResponse {
81
+ data: GoogleMapsPlaceDetailsResult;
82
+ errors?: string[];
83
+ }
84
+
85
+ export interface GoogleMapsGeocodeResponse {
86
+ data: {
87
+ result: GoogleMapsGeocodeResult | null;
88
+ };
89
+ errors?: string[];
90
+ }
91
+
92
+ export interface GoogleMapsReverseGeocodeResponse {
93
+ data: {
94
+ result: GoogleMapsGeocodeResult | null;
95
+ };
96
+ errors?: string[];
97
+ }
@@ -0,0 +1,154 @@
1
+ import WashdayClient from "../src/api";
2
+ import {
3
+ autocomplete,
4
+ autocompleteCustomersApp,
5
+ geocode,
6
+ geocodeCustomersApp,
7
+ placeDetails,
8
+ placeDetailsCustomersApp,
9
+ reverseGeocode,
10
+ reverseGeocodeCustomersApp,
11
+ } from "../src/api/googleMaps/post";
12
+ import {
13
+ GoogleMapsAutocompletePayload,
14
+ GoogleMapsGeocodePayload,
15
+ GoogleMapsPlaceDetailsPayload,
16
+ GoogleMapsReverseGeocodePayload,
17
+ } from "../src/interfaces/GoogleMaps";
18
+
19
+ const autocompletePayload: GoogleMapsAutocompletePayload = {
20
+ input: "Calle 60",
21
+ sessionToken: "session-123",
22
+ storeId: "store-123",
23
+ regionCode: "MX",
24
+ locationBias: {
25
+ circle: {
26
+ center: { latitude: 20.97, longitude: -89.62 },
27
+ radius: 12000,
28
+ },
29
+ },
30
+ };
31
+
32
+ const placeDetailsPayload: GoogleMapsPlaceDetailsPayload = {
33
+ placeResourceName: "places/abc",
34
+ sessionToken: "session-123",
35
+ storeId: "store-123",
36
+ };
37
+
38
+ const geocodePayload: GoogleMapsGeocodePayload = {
39
+ address: "Calle 60, Merida",
40
+ storeId: "store-123",
41
+ regionCode: "MX",
42
+ };
43
+
44
+ const reverseGeocodePayload: GoogleMapsReverseGeocodePayload = {
45
+ latLng: { lat: 20.97, lng: -89.62 },
46
+ storeId: "store-123",
47
+ };
48
+
49
+ function createClient() {
50
+ return {
51
+ apiToken: "token-123",
52
+ axiosInstance: {
53
+ post: jest.fn().mockResolvedValue({ data: { data: {} } }),
54
+ },
55
+ } as any;
56
+ }
57
+
58
+ describe("google maps proxy endpoints", () => {
59
+ it("calls Customers App Google Maps proxy endpoints with customer token", async () => {
60
+ const client = createClient();
61
+
62
+ await autocompleteCustomersApp.call(client, autocompletePayload);
63
+ await placeDetailsCustomersApp.call(client, placeDetailsPayload);
64
+ await geocodeCustomersApp.call(client, geocodePayload);
65
+ await reverseGeocodeCustomersApp.call(client, reverseGeocodePayload);
66
+
67
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
68
+ 1,
69
+ "api/v2/washdayapp/google-maps/autocomplete",
70
+ autocompletePayload,
71
+ { headers: { Authorization: "Bearer token-123" } }
72
+ );
73
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
74
+ 2,
75
+ "api/v2/washdayapp/google-maps/place-details",
76
+ placeDetailsPayload,
77
+ { headers: { Authorization: "Bearer token-123" } }
78
+ );
79
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
80
+ 3,
81
+ "api/v2/washdayapp/google-maps/geocode",
82
+ geocodePayload,
83
+ { headers: { Authorization: "Bearer token-123" } }
84
+ );
85
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
86
+ 4,
87
+ "api/v2/washdayapp/google-maps/reverse-geocode",
88
+ reverseGeocodePayload,
89
+ { headers: { Authorization: "Bearer token-123" } }
90
+ );
91
+ });
92
+
93
+ it("calls internal user Google Maps proxy endpoints with user token", async () => {
94
+ const client = createClient();
95
+
96
+ await autocomplete.call(client, autocompletePayload);
97
+ await placeDetails.call(client, placeDetailsPayload);
98
+ await geocode.call(client, geocodePayload);
99
+ await reverseGeocode.call(client, reverseGeocodePayload);
100
+
101
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
102
+ 1,
103
+ "api/v2/google-maps/autocomplete",
104
+ autocompletePayload,
105
+ { headers: { Authorization: "Bearer token-123" } }
106
+ );
107
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
108
+ 2,
109
+ "api/v2/google-maps/place-details",
110
+ placeDetailsPayload,
111
+ { headers: { Authorization: "Bearer token-123" } }
112
+ );
113
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
114
+ 3,
115
+ "api/v2/google-maps/geocode",
116
+ geocodePayload,
117
+ { headers: { Authorization: "Bearer token-123" } }
118
+ );
119
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
120
+ 4,
121
+ "api/v2/google-maps/reverse-geocode",
122
+ reverseGeocodePayload,
123
+ { headers: { Authorization: "Bearer token-123" } }
124
+ );
125
+ });
126
+
127
+ it("exposes Google Maps proxy methods through wdClient.googleMaps", async () => {
128
+ const client = new (WashdayClient as any)("token-123", "DEV");
129
+ client.axiosInstance.post = jest.fn().mockResolvedValue({ data: { data: {} } });
130
+
131
+ await client.googleMaps.autocompleteCustomersApp(autocompletePayload);
132
+ await client.googleMaps.placeDetailsCustomersApp(placeDetailsPayload);
133
+ await client.googleMaps.geocodeCustomersApp(geocodePayload);
134
+ await client.googleMaps.reverseGeocodeCustomersApp(reverseGeocodePayload);
135
+ await client.googleMaps.autocomplete(autocompletePayload);
136
+ await client.googleMaps.placeDetails(placeDetailsPayload);
137
+ await client.googleMaps.geocode(geocodePayload);
138
+ await client.googleMaps.reverseGeocode(reverseGeocodePayload);
139
+
140
+ expect(client.axiosInstance.post).toHaveBeenCalledTimes(8);
141
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
142
+ 1,
143
+ "api/v2/washdayapp/google-maps/autocomplete",
144
+ autocompletePayload,
145
+ { headers: { Authorization: "Bearer token-123" } }
146
+ );
147
+ expect(client.axiosInstance.post).toHaveBeenNthCalledWith(
148
+ 8,
149
+ "api/v2/google-maps/reverse-geocode",
150
+ reverseGeocodePayload,
151
+ { headers: { Authorization: "Bearer token-123" } }
152
+ );
153
+ });
154
+ });