-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetEndOfDayReport.ts
More file actions
76 lines (73 loc) · 3.03 KB
/
Copy pathgetEndOfDayReport.ts
File metadata and controls
76 lines (73 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import {ActionSdk, HerculesFunctionContext, RuntimeErrorException} from "@code0-tech/hercules";
import {getAuthToken} from "../helpers";
import axios from "axios";
import {EndOfDayRequestData, EndOfDayResponseData, EndOfDayResponseDataSchema} from "../types/glsEndOfDayRequest";
export default (sdk: ActionSdk) => {
return sdk.registerFunctionDefinitions(
{
definition: {
runtimeName: "getEndOfDayReport",
documentation: [
{
code: "en-US",
content: "Retrieves all shipments dispatched on a given date. Useful for reconciliation and end-of-day processing."
}
],
displayMessage: [
{
code: "en-US",
content: "Get end of day report"
}
],
name: [
{
code: "en-US",
content: "Get end of day report",
}
],
description: [
{
code: "en-US",
content: "Retrieves all shipments dispatched on a given date. Useful for reconciliation and end-of-day processing.",
}
],
signature: "(data: GLS_END_OF_DAY_REQUEST_DATA): GLS_END_OF_DAY_RESPONSE_DATA",
parameters: [
{
runtimeName: "data",
name: [
{
code: "en-US",
content: "Data",
}
],
description: [
{
code: "en-US",
content: "The end of day report request data.",
}
]
}
],
linkedDataTypes: [
"GLS_END_OF_DAY_REQUEST_DATA",
"GLS_END_OF_DAY_RESPONSE_DATA",
],
},
handler: async (data: EndOfDayRequestData, context: HerculesFunctionContext): Promise<EndOfDayResponseData> => {
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
try {
const result = await axios.post(`${url}/rs/shipments/endofday?date=${data.date}`, {}, {
headers: {
Authorization: `Bearer ${await getAuthToken(context)}`,
"Content-Type": "application/glsVersion1+json"
}
})
return EndOfDayResponseDataSchema.parse(result.data)
} catch (error: any) {
throw new RuntimeErrorException("GET_END_OF_DAY_INFO_FAILED", error.toString())
}
}
},
)
}