-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetEndOfDayReportFunction.ts
More file actions
57 lines (55 loc) · 1.92 KB
/
Copy pathgetEndOfDayReportFunction.ts
File metadata and controls
57 lines (55 loc) · 1.92 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
import axios from "axios";
import {
Description, DisplayIcon,
DisplayMessage,
Documentation,
FunctionContext,
Identifier,
Name,
Parameter,
RuntimeError,
Signature,
} from "@code0-tech/hercules";
import { getAuthToken } from "../helpers.js";
import {
EndOfDayResponseData,
EndOfDayResponseDataSchema,
} from "../data_types/glsEndOfDay.js";
@Identifier("getEndOfDayReport")
@DisplayIcon("codezero:gls")
@Signature("(date: string): GLS_END_OF_DAY_RESPONSE_DATA")
@Name({ code: "en-US", content: "Get end of day report" })
@DisplayMessage({ code: "en-US", content: "Get end of day report" })
@Documentation({
code: "en-US",
content: "Retrieves all shipments dispatched on a given date. Useful for reconciliation and end-of-day processing.",
})
@Description({
code: "en-US",
content: "Retrieves all shipments dispatched on a given date. Useful for reconciliation and end-of-day processing.",
})
@Parameter({
runtimeName: "date",
name: [{ code: "en-US", content: "Date" }],
description: [{ code: "en-US", content: "The dispatch date to retrieve shipments for, in ISO format (YYYY-MM-DD)." }],
})
export class GetEndOfDayReportFunction {
async run(context: FunctionContext, date: string): Promise<EndOfDayResponseData> {
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
try {
const result = await axios.post(
`${url}/rs/shipments/endofday?date=${date}`,
{},
{
headers: {
Authorization: `Bearer ${await getAuthToken(context)}`,
"Content-Type": "application/glsVersion1+json",
},
}
);
return EndOfDayResponseDataSchema.parse(result.data);
} catch (error: any) {
throw new RuntimeError("GET_END_OF_DAY_INFO_FAILED", error.toString());
}
}
}