washday-sdk 1.6.53 → 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.
@@ -1,4 +1,5 @@
1
1
  export * as deleteModule from './delete';
2
2
  export * as getModule from './get';
3
+ export * as patchModule from './patch';
3
4
  export * as postModule from './post';
4
5
  export * as putModule from './put';
@@ -0,0 +1,18 @@
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 GET_SET_CUSTOMERS_APP = "api/v2/washdayapp/customers";
11
+ export const updateAddressCustomersApp = function (payload) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ const config = {
14
+ headers: { Authorization: `Bearer ${this.apiToken}` },
15
+ };
16
+ return yield this.axiosInstance.patch(`${GET_SET_CUSTOMERS_APP}/me/address`, payload, config);
17
+ });
18
+ };
@@ -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) {
@@ -176,6 +177,7 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
176
177
  deleteById: customersEndpoints.deleteModule.deleteById,
177
178
  deleteByIdCustomersApp: customersEndpoints.deleteModule.deleteByIdCustomersApp,
178
179
  updateByIdCustomersApp: customersEndpoints.putModule.updateByIdCustomersApp,
180
+ updateAddressCustomersApp: customersEndpoints.patchModule.updateAddressCustomersApp,
179
181
  });
180
182
  this.stores = bindMethods(this, {
181
183
  getStores: getStores,
@@ -222,6 +224,16 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
222
224
  this.config = bindMethods(this, {
223
225
  getTaxPresets: configEndpoints.getModule.getTaxPresets,
224
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
+ });
225
237
  this.supplies = bindMethods(this, {
226
238
  getSupplies: getSupplies,
227
239
  getSupplyById: getSupplyById,
package/dist/index.js CHANGED
@@ -4,4 +4,6 @@ export * from './interfaces/Company';
4
4
  export * from './interfaces/Config';
5
5
  export * from './interfaces/Cfdi';
6
6
  export * from './interfaces/Auth';
7
+ export * from './interfaces/Customer';
8
+ export * from './interfaces/GoogleMaps';
7
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.53",
3
+ "version": "1.6.55",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -1,4 +1,5 @@
1
1
  export * as deleteModule from './delete';
2
2
  export * as getModule from './get';
3
+ export * as patchModule from './patch';
3
4
  export * as postModule from './post';
4
5
  export * as putModule from './put';
@@ -0,0 +1,21 @@
1
+ import { WashdayClientInstance } from "../../interfaces/Api";
2
+ import {
3
+ UpdateCustomersAppCustomerAddressPayload,
4
+ UpdateCustomersAppCustomerAddressResponse,
5
+ } from "../../interfaces/Customer";
6
+
7
+ const GET_SET_CUSTOMERS_APP = "api/v2/washdayapp/customers";
8
+
9
+ export const updateAddressCustomersApp = async function (
10
+ this: WashdayClientInstance,
11
+ payload: UpdateCustomersAppCustomerAddressPayload
12
+ ): Promise<UpdateCustomersAppCustomerAddressResponse> {
13
+ const config = {
14
+ headers: { Authorization: `Bearer ${this.apiToken}` },
15
+ };
16
+ return await this.axiosInstance.patch(
17
+ `${GET_SET_CUSTOMERS_APP}/me/address`,
18
+ payload,
19
+ config
20
+ );
21
+ };
@@ -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
@@ -183,6 +184,7 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
183
184
  deleteById: customersEndpoints.deleteModule.deleteById,
184
185
  deleteByIdCustomersApp: customersEndpoints.deleteModule.deleteByIdCustomersApp,
185
186
  updateByIdCustomersApp: customersEndpoints.putModule.updateByIdCustomersApp,
187
+ updateAddressCustomersApp: customersEndpoints.patchModule.updateAddressCustomersApp,
186
188
  });
187
189
  this.stores = bindMethods(this, {
188
190
  getStores: getStores,
@@ -229,6 +231,16 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
229
231
  this.config = bindMethods(this, {
230
232
  getTaxPresets: configEndpoints.getModule.getTaxPresets,
231
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
+ });
232
244
  this.supplies = bindMethods(this, {
233
245
  getSupplies: getSupplies,
234
246
  getSupplyById: getSupplyById,
package/src/index.ts CHANGED
@@ -4,5 +4,7 @@ export * from './interfaces/Company';
4
4
  export * from './interfaces/Config';
5
5
  export * from './interfaces/Cfdi';
6
6
  export * from './interfaces/Auth';
7
+ export * from './interfaces/Customer';
8
+ export * from './interfaces/GoogleMaps';
7
9
 
8
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
 
@@ -168,6 +169,7 @@ export interface WashdayClientInstance {
168
169
  deleteById: typeof customersEndpoints.deleteModule.deleteById;
169
170
  deleteByIdCustomersApp: typeof customersEndpoints.deleteModule.deleteByIdCustomersApp;
170
171
  updateByIdCustomersApp: typeof customersEndpoints.putModule.updateByIdCustomersApp;
172
+ updateAddressCustomersApp: typeof customersEndpoints.patchModule.updateAddressCustomersApp;
171
173
  };
172
174
  stores: {
173
175
  getStores: typeof getStores;
@@ -214,6 +216,16 @@ export interface WashdayClientInstance {
214
216
  config: {
215
217
  getTaxPresets: typeof configEndpoints.getModule.getTaxPresets;
216
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
+ };
217
229
  supplies: {
218
230
  getSupplies: typeof getSupplies;
219
231
  getSupplyById: typeof getSupplyById;
@@ -18,17 +18,40 @@ interface IPaymentMethod {
18
18
  export interface IAddress {
19
19
  formattedAddress?: string; // A field to store the full address as a single string
20
20
  street?: string;
21
+ number?: string;
21
22
  neighborhood?: string;
22
23
  postalCode?: string;
23
24
  city?: string;
24
25
  state?: string;
25
26
  country?: string;
27
+ mapLocation?: IMapLocation;
28
+ // TODO: Legacy field. Use address.mapLocation instead.
29
+ // Kept temporarily for backward compatibility while old documents and active clients are migrated.
26
30
  coordinates?: {
27
31
  lat: number;
28
32
  lng: number;
29
33
  };
30
34
  }
31
35
 
36
+ export type MapLocationSource = "manual" | "places" | "geocoded" | "imported";
37
+
38
+ export interface IMapLocation {
39
+ type: "Point";
40
+ coordinates: [number, number];
41
+ source?: MapLocationSource;
42
+ formattedAddress?: string;
43
+ placeId?: string;
44
+ updatedAt?: string | Date;
45
+ }
46
+
47
+ export interface UpdateCustomersAppCustomerAddressPayload {
48
+ address: IAddress;
49
+ }
50
+
51
+ export interface UpdateCustomersAppCustomerAddressResponse {
52
+ customer: ICustomer;
53
+ }
54
+
32
55
  export interface ICustomer {
33
56
  name: string,
34
57
  phone: string,
@@ -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,77 @@
1
+ import WashdayClient from "../src/api";
2
+ import { updateAddressCustomersApp } from "../src/api/customers/patch";
3
+ import { UpdateCustomersAppCustomerAddressPayload } from "../src/interfaces/Customer";
4
+
5
+ const payload: UpdateCustomersAppCustomerAddressPayload = {
6
+ address: {
7
+ formattedAddress: "Calle 1, Merida",
8
+ street: "Calle 1",
9
+ number: "123",
10
+ neighborhood: "Centro",
11
+ city: "Merida",
12
+ state: "Yucatan",
13
+ postalCode: "97000",
14
+ country: "Mexico",
15
+ mapLocation: {
16
+ type: "Point",
17
+ coordinates: [-89.62, 20.97],
18
+ source: "places",
19
+ formattedAddress: "Calle 1, Merida",
20
+ placeId: "place-123",
21
+ updatedAt: "2026-05-18T12:00:00.000Z",
22
+ },
23
+ },
24
+ };
25
+
26
+ describe("updateAddressCustomersApp", () => {
27
+ it("calls the authenticated Customers App address endpoint", async () => {
28
+ const patch = jest.fn().mockResolvedValue({
29
+ data: {
30
+ data: {
31
+ customer: {
32
+ _id: "customer-1",
33
+ address: payload.address,
34
+ },
35
+ },
36
+ },
37
+ });
38
+ const client = {
39
+ apiToken: "customer-token",
40
+ axiosInstance: { patch },
41
+ } as any;
42
+
43
+ await updateAddressCustomersApp.call(client, payload);
44
+
45
+ expect(patch).toHaveBeenCalledWith(
46
+ "api/v2/washdayapp/customers/me/address",
47
+ payload,
48
+ {
49
+ headers: { Authorization: "Bearer customer-token" },
50
+ }
51
+ );
52
+ });
53
+
54
+ it("exposes updateAddressCustomersApp through wdClient.customers", async () => {
55
+ const client = new (WashdayClient as any)("customer-token", "DEV");
56
+ client.axiosInstance.patch = jest.fn().mockResolvedValue({
57
+ data: {
58
+ data: {
59
+ customer: {
60
+ _id: "customer-1",
61
+ address: payload.address,
62
+ },
63
+ },
64
+ },
65
+ });
66
+
67
+ await client.customers.updateAddressCustomersApp(payload);
68
+
69
+ expect(client.axiosInstance.patch).toHaveBeenCalledWith(
70
+ "api/v2/washdayapp/customers/me/address",
71
+ payload,
72
+ {
73
+ headers: { Authorization: "Bearer customer-token" },
74
+ }
75
+ );
76
+ });
77
+ });
@@ -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
+ });