washday-sdk 1.6.34 → 1.6.36
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/api/index.js +5 -0
- package/dist/api/intercom/index.js +1 -0
- package/dist/api/intercom/post.js +36 -0
- package/dist/api/order/post.js +15 -0
- package/package.json +1 -1
- package/src/api/index.ts +5 -0
- package/src/api/intercom/index.ts +1 -0
- package/src/api/intercom/post.ts +33 -0
- package/src/api/order/post.ts +23 -2
- package/src/interfaces/Api.ts +5 -0
- package/src/interfaces/Order.ts +18 -1
- package/test/orders.recordFailedServiceAttempt.test.ts +41 -0
package/dist/api/index.js
CHANGED
|
@@ -45,6 +45,7 @@ import { validateUserPin } from "./users/post";
|
|
|
45
45
|
import { getAxiosInstance } from "./axiosInstance";
|
|
46
46
|
import * as integrationsEndpoints from './integrations';
|
|
47
47
|
import * as updatesEndpoints from './updates';
|
|
48
|
+
import * as intercomEndpoints from './intercom';
|
|
48
49
|
function bindMethods(instance, methods) {
|
|
49
50
|
const boundMethods = {};
|
|
50
51
|
for (const key in methods) {
|
|
@@ -141,6 +142,7 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
|
|
|
141
142
|
setOrderUncollected: ordersEndpoints.postModule.setOrderUncollected,
|
|
142
143
|
payAndCollect: ordersEndpoints.postModule.payAndCollect,
|
|
143
144
|
sendOrderUncollectedCustomerNotification: ordersEndpoints.postModule.sendOrderUncollectedCustomerNotification,
|
|
145
|
+
recordFailedServiceAttempt: ordersEndpoints.postModule.recordFailedServiceAttempt,
|
|
144
146
|
deletePaymentLineById: ordersEndpoints.deleteModule.deletePaymentLineById,
|
|
145
147
|
getListCustomersApp: ordersEndpoints.getModule.getListCustomersApp,
|
|
146
148
|
getByIdCustomersApp: ordersEndpoints.getModule.getByIdCustomersApp,
|
|
@@ -375,5 +377,8 @@ const WashdayClient = function WashdayClient(apiToken, env = 'PROD', clientId, c
|
|
|
375
377
|
getLatestUpdates: updatesEndpoints.getModule.getLatestUpdates,
|
|
376
378
|
markUpdatesAsSeen: updatesEndpoints.postModule.markUpdatesAsSeen,
|
|
377
379
|
});
|
|
380
|
+
this.intercom = bindMethods(this, {
|
|
381
|
+
getMessengerToken: intercomEndpoints.postModule.getMessengerToken,
|
|
382
|
+
});
|
|
378
383
|
};
|
|
379
384
|
export default WashdayClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as postModule from './post';
|
|
@@ -0,0 +1,36 @@
|
|
|
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 INTERCOM_BASE = "api/intercom";
|
|
11
|
+
/**
|
|
12
|
+
* Fetches a fresh Intercom Identity Verification token for the authenticated user.
|
|
13
|
+
*
|
|
14
|
+
* Use this when:
|
|
15
|
+
* - Initializing Intercom Messenger after restoring a session from storage
|
|
16
|
+
* - The token returned at login has expired (check expiresAt before calling)
|
|
17
|
+
*
|
|
18
|
+
* Pass `intercomJwt` if you already have a token — the backend will reuse it
|
|
19
|
+
* if it still has more than 1 hour of life remaining, avoiding unnecessary resets.
|
|
20
|
+
*
|
|
21
|
+
* Requires: authenticated session (apiToken must be set on the client).
|
|
22
|
+
*/
|
|
23
|
+
export const getMessengerToken = function (params) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
try {
|
|
26
|
+
const config = {
|
|
27
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
28
|
+
};
|
|
29
|
+
return yield this.axiosInstance.post(`${INTERCOM_BASE}/messenger-token`, params !== null && params !== void 0 ? params : {}, config);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error('Error fetching intercom messenger token:', error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
package/dist/api/order/post.js
CHANGED
|
@@ -12,6 +12,7 @@ const GET_SET_ORDER = 'api/v2/order';
|
|
|
12
12
|
const GET_SET_ORDER_CUSTOMERS_APP = 'api/v2/washdayapp/orders';
|
|
13
13
|
const PAY_AND_COLLECT = (sequence, storeId) => `/api/v2/order/${sequence}/${storeId}/pay-and-collect`;
|
|
14
14
|
const SEND_UNCOLLECTED_CUSTOMER_NOTIFICATION = (orderId) => `/api/v2/order/${orderId}/send-uncollected-customer-notification`;
|
|
15
|
+
const FAIL_SERVICE_ATTEMPT = (orderId) => `${GET_SET_ORDER}/${orderId}/service-attempts/fail`;
|
|
15
16
|
export const createPaymentLine = function (id, data) {
|
|
16
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
18
|
try {
|
|
@@ -165,3 +166,17 @@ export const sendOrderUncollectedCustomerNotification = function (orderId) {
|
|
|
165
166
|
}
|
|
166
167
|
});
|
|
167
168
|
};
|
|
169
|
+
export const recordFailedServiceAttempt = function (orderId, data) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
try {
|
|
172
|
+
const config = {
|
|
173
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
174
|
+
};
|
|
175
|
+
return yield this.axiosInstance.post(FAIL_SERVICE_ATTEMPT(orderId), data, config);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
console.error('Error fetching recordFailedServiceAttempt:', error);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
};
|
package/package.json
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -47,6 +47,7 @@ import { validateUserPin } from "./users/post";
|
|
|
47
47
|
import { getAxiosInstance } from "./axiosInstance";
|
|
48
48
|
import * as integrationsEndpoints from './integrations';
|
|
49
49
|
import * as updatesEndpoints from './updates';
|
|
50
|
+
import * as intercomEndpoints from './intercom';
|
|
50
51
|
|
|
51
52
|
type WashdayClientConstructor = {
|
|
52
53
|
new(apiToken: string, env?: string, clientId?: string, clientSecret?: string): WashdayClientInstance
|
|
@@ -148,6 +149,7 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
|
|
|
148
149
|
setOrderUncollected: ordersEndpoints.postModule.setOrderUncollected,
|
|
149
150
|
payAndCollect: ordersEndpoints.postModule.payAndCollect,
|
|
150
151
|
sendOrderUncollectedCustomerNotification: ordersEndpoints.postModule.sendOrderUncollectedCustomerNotification,
|
|
152
|
+
recordFailedServiceAttempt: ordersEndpoints.postModule.recordFailedServiceAttempt,
|
|
151
153
|
deletePaymentLineById: ordersEndpoints.deleteModule.deletePaymentLineById,
|
|
152
154
|
getListCustomersApp: ordersEndpoints.getModule.getListCustomersApp,
|
|
153
155
|
getByIdCustomersApp: ordersEndpoints.getModule.getByIdCustomersApp,
|
|
@@ -382,6 +384,9 @@ const WashdayClient: WashdayClientConstructor = function WashdayClient(this: Was
|
|
|
382
384
|
getLatestUpdates: updatesEndpoints.getModule.getLatestUpdates,
|
|
383
385
|
markUpdatesAsSeen: updatesEndpoints.postModule.markUpdatesAsSeen,
|
|
384
386
|
});
|
|
387
|
+
this.intercom = bindMethods(this, {
|
|
388
|
+
getMessengerToken: intercomEndpoints.postModule.getMessengerToken,
|
|
389
|
+
});
|
|
385
390
|
} as any;
|
|
386
391
|
|
|
387
392
|
export default WashdayClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as postModule from './post';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
|
|
3
|
+
const INTERCOM_BASE = "api/intercom";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetches a fresh Intercom Identity Verification token for the authenticated user.
|
|
7
|
+
*
|
|
8
|
+
* Use this when:
|
|
9
|
+
* - Initializing Intercom Messenger after restoring a session from storage
|
|
10
|
+
* - The token returned at login has expired (check expiresAt before calling)
|
|
11
|
+
*
|
|
12
|
+
* Pass `intercomJwt` if you already have a token — the backend will reuse it
|
|
13
|
+
* if it still has more than 1 hour of life remaining, avoiding unnecessary resets.
|
|
14
|
+
*
|
|
15
|
+
* Requires: authenticated session (apiToken must be set on the client).
|
|
16
|
+
*/
|
|
17
|
+
export const getMessengerToken = async function (
|
|
18
|
+
this: WashdayClientInstance,
|
|
19
|
+
params?: {
|
|
20
|
+
intercomJwt?: string;
|
|
21
|
+
platform?: string;
|
|
22
|
+
}
|
|
23
|
+
): Promise<any> {
|
|
24
|
+
try {
|
|
25
|
+
const config = {
|
|
26
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
27
|
+
};
|
|
28
|
+
return await this.axiosInstance.post(`${INTERCOM_BASE}/messenger-token`, params ?? {}, config);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('Error fetching intercom messenger token:', error);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
};
|
package/src/api/order/post.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { AxiosResponse } from "axios";
|
|
2
2
|
import { PaymentMethodsEnum } from "../../enum";
|
|
3
3
|
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
4
|
-
import { OrderDto } from "../../interfaces/Order";
|
|
4
|
+
import { IFailedServiceAttemptPayload, OrderDto } from "../../interfaces/Order";
|
|
5
5
|
import axiosInstance from "../axiosInstance";
|
|
6
6
|
const GET_SET_ORDER_PAYMENTLINES = (orderId: string) => `/api/v2/order/${orderId}/paymentLines`;
|
|
7
7
|
const GET_SET_ORDER = 'api/v2/order';
|
|
8
8
|
const GET_SET_ORDER_CUSTOMERS_APP = 'api/v2/washdayapp/orders';
|
|
9
9
|
const PAY_AND_COLLECT = (sequence: string, storeId: string) => `/api/v2/order/${sequence}/${storeId}/pay-and-collect`;
|
|
10
10
|
const SEND_UNCOLLECTED_CUSTOMER_NOTIFICATION = (orderId: string) => `/api/v2/order/${orderId}/send-uncollected-customer-notification`;
|
|
11
|
+
const FAIL_SERVICE_ATTEMPT = (orderId: string) => `${GET_SET_ORDER}/${orderId}/service-attempts/fail`;
|
|
11
12
|
|
|
12
13
|
export const createPaymentLine = async function (this: WashdayClientInstance, id: string, data: {
|
|
13
14
|
amountPaid: number,
|
|
@@ -186,4 +187,24 @@ export const sendOrderUncollectedCustomerNotification = async function (this: Wa
|
|
|
186
187
|
console.error('Error fetching sendOrderUncollectedCustomerNotification:', error);
|
|
187
188
|
throw error;
|
|
188
189
|
}
|
|
189
|
-
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const recordFailedServiceAttempt = async function (
|
|
193
|
+
this: WashdayClientInstance,
|
|
194
|
+
orderId: string,
|
|
195
|
+
data: IFailedServiceAttemptPayload
|
|
196
|
+
): Promise<AxiosResponse<any, any>> {
|
|
197
|
+
try {
|
|
198
|
+
const config = {
|
|
199
|
+
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
200
|
+
};
|
|
201
|
+
return await this.axiosInstance.post(
|
|
202
|
+
FAIL_SERVICE_ATTEMPT(orderId),
|
|
203
|
+
data,
|
|
204
|
+
config
|
|
205
|
+
);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error('Error fetching recordFailedServiceAttempt:', error);
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
};
|
package/src/interfaces/Api.ts
CHANGED
|
@@ -43,6 +43,7 @@ import * as outsourcedOrdersEndpoints from '../api/outsourcedOrders';
|
|
|
43
43
|
import * as publicsEndpoints from '../api/publics';
|
|
44
44
|
import * as integrationsEndpoints from '../api/integrations';
|
|
45
45
|
import * as updatesEndpoints from '../api/updates';
|
|
46
|
+
import * as intercomEndpoints from '../api/intercom';
|
|
46
47
|
import { validateUserPin } from "../api/users/post";
|
|
47
48
|
import { AxiosInstance } from "axios";
|
|
48
49
|
|
|
@@ -133,6 +134,7 @@ export interface WashdayClientInstance {
|
|
|
133
134
|
setOrderUncollected: typeof ordersEndpoints.postModule.setOrderUncollected,
|
|
134
135
|
payAndCollect: typeof ordersEndpoints.postModule.payAndCollect,
|
|
135
136
|
sendOrderUncollectedCustomerNotification: typeof ordersEndpoints.postModule.sendOrderUncollectedCustomerNotification,
|
|
137
|
+
recordFailedServiceAttempt: typeof ordersEndpoints.postModule.recordFailedServiceAttempt,
|
|
136
138
|
deletePaymentLineById: typeof ordersEndpoints.deleteModule.deletePaymentLineById;
|
|
137
139
|
getListCustomersApp: typeof ordersEndpoints.getModule.getListCustomersApp;
|
|
138
140
|
getByIdCustomersApp: typeof ordersEndpoints.getModule.getByIdCustomersApp;
|
|
@@ -365,4 +367,7 @@ export interface WashdayClientInstance {
|
|
|
365
367
|
getLatestUpdates: typeof updatesEndpoints.getModule.getLatestUpdates;
|
|
366
368
|
markUpdatesAsSeen: typeof updatesEndpoints.postModule.markUpdatesAsSeen;
|
|
367
369
|
};
|
|
370
|
+
intercom: {
|
|
371
|
+
getMessengerToken: typeof intercomEndpoints.postModule.getMessengerToken;
|
|
372
|
+
};
|
|
368
373
|
}
|
package/src/interfaces/Order.ts
CHANGED
|
@@ -15,6 +15,23 @@ interface IPickupInfo {
|
|
|
15
15
|
toTime: string
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
export type ServiceAttemptType = "pickup" | "delivery";
|
|
19
|
+
export type ServiceAttemptReason =
|
|
20
|
+
| "customer_not_home"
|
|
21
|
+
| "no_answer"
|
|
22
|
+
| "wrong_address"
|
|
23
|
+
| "access_issue"
|
|
24
|
+
| "customer_rejected"
|
|
25
|
+
| "driver_issue"
|
|
26
|
+
| "other";
|
|
27
|
+
|
|
28
|
+
export interface IFailedServiceAttemptPayload {
|
|
29
|
+
type: ServiceAttemptType;
|
|
30
|
+
reason: ServiceAttemptReason;
|
|
31
|
+
notes?: string;
|
|
32
|
+
images?: string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
18
35
|
export interface IOrderPaymentLines {
|
|
19
36
|
_id?: any,
|
|
20
37
|
amountPaid: number,
|
|
@@ -130,4 +147,4 @@ export interface OrderDto {
|
|
|
130
147
|
discountCode: string | null,
|
|
131
148
|
createdDate?: Date | null,
|
|
132
149
|
updatedDate?: Date | null
|
|
133
|
-
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { recordFailedServiceAttempt } from "../src/api/order/post";
|
|
2
|
+
|
|
3
|
+
describe("recordFailedServiceAttempt", () => {
|
|
4
|
+
it("calls the failed service attempt endpoint for the selected order", async () => {
|
|
5
|
+
const post = jest.fn().mockResolvedValue({
|
|
6
|
+
data: {
|
|
7
|
+
data: {
|
|
8
|
+
message: "Service attempt recorded successfully",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
const client = {
|
|
13
|
+
apiToken: "token-123",
|
|
14
|
+
axiosInstance: { post },
|
|
15
|
+
} as any;
|
|
16
|
+
|
|
17
|
+
const payload = {
|
|
18
|
+
type: "pickup" as const,
|
|
19
|
+
reason: "customer_not_home" as const,
|
|
20
|
+
notes: "Nobody answered",
|
|
21
|
+
images: ["https://example.com/photo.jpg"],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const result = await recordFailedServiceAttempt.call(client, "order-1", payload);
|
|
25
|
+
|
|
26
|
+
expect(post).toHaveBeenCalledWith(
|
|
27
|
+
"api/v2/order/order-1/service-attempts/fail",
|
|
28
|
+
payload,
|
|
29
|
+
{
|
|
30
|
+
headers: { Authorization: "Bearer token-123" },
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
expect(result).toEqual({
|
|
34
|
+
data: {
|
|
35
|
+
data: {
|
|
36
|
+
message: "Service attempt recorded successfully",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|