-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreprintParcel.ts
More file actions
80 lines (78 loc) · 3.15 KB
/
Copy pathreprintParcel.ts
File metadata and controls
80 lines (78 loc) · 3.15 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
77
78
79
80
import {ActionSdk, HerculesFunctionContext, RuntimeErrorException} from "@code0-tech/hercules";
import {getAuthToken} from "../helpers";
import axios from "axios";
import {
ReprintParcelRequestData,
ReprintParcelResponseData,
ReprintParcelResponseDataSchema
} from "../types/glsReprintParcel";
export default (sdk: ActionSdk) => {
return sdk.registerFunctionDefinitions(
{
definition: {
runtimeName: "reprintParcel",
documentation: [
{
code: "en-US",
content: "Reprints the label for an existing parcel. Use this if the original label is damaged, lost, or needs to be printed in a different format."
}
],
displayMessage: [
{
code: "en-US",
content: "Reprint parcel"
}
],
name: [
{
code: "en-US",
content: "Reprint parcel",
}
],
description: [
{
code: "en-US",
content: "Reprints the label for an existing parcel. Use this if the original label is damaged, lost, or needs to be printed in a different format.",
}
],
signature: "(data: GLS_REPRINT_PARCEL_REQUEST_DATA): GLS_REPRINT_PARCEL_RESPONSE_DATA",
parameters: [
{
runtimeName: "data",
name: [
{
code: "en-US",
content: "Data",
}
],
description: [
{
code: "en-US",
content: "The reprint parcel request data.",
}
]
}
],
linkedDataTypes: [
"GLS_REPRINT_PARCEL_REQUEST_DATA",
"GLS_REPRINT_PARCEL_RESPONSE_DATA",
],
},
handler: async (data: ReprintParcelRequestData, context: HerculesFunctionContext): Promise<ReprintParcelResponseData> => {
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
try {
const result = await axios.post(`${url}/rs/shipments/reprintparcel`, data, {
headers: {
Authorization: `Bearer ${await getAuthToken(context)}`,
"Content-Type": "application/glsVersion1+json"
}
})
return ReprintParcelResponseDataSchema.parse(result.data)
} catch (error: any) {
console.log(error)
throw new RuntimeErrorException("REPRINT_PARCEL_FAILED", error.toString())
}
}
}
)
}