Skip to content

Commit 66fd9a7

Browse files
authored
Merge pull request #28 from code0-tech/feat/#27
Unwrap GLS paramater functions
2 parents a3aa4fc + ce8ee90 commit 66fd9a7

7 files changed

Lines changed: 218 additions & 71 deletions

File tree

actions/gls-action/src/data_types/glsReprintParcel.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DisplayMessage, Identifier, Name, Schema } from "@code0-tech/hercules";
22
import { z } from "zod";
3+
import { ReturnLabelsSchema } from "./glsPrintingOptions.js";
34

45
export const ReprintParcelRequestDataSchema = z.object({
56
TrackID: z.string().max(8).optional(),
@@ -9,10 +10,7 @@ export const ReprintParcelRequestDataSchema = z.object({
910
PartnerParcelNumber: z.string().max(50).optional(),
1011
CreationDate: z.iso.date(),
1112
PrintingOptions: z.object({
12-
ReturnLabels: z.object({
13-
TemplateSet: z.enum(["NONE", "ZPL_200", "ZPL_300"]),
14-
LabelFormat: z.enum(["PDF", "ZEBRA", "PNG", "PNG_200"]),
15-
}),
13+
ReturnLabels: ReturnLabelsSchema,
1614
}),
1715
});
1816
export type ReprintParcelRequestData = z.infer<typeof ReprintParcelRequestDataSchema>;

actions/gls-action/src/functions/cancelShipmentFunction.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
//TODO: Why is the request data here wrapped within a object and isn't a direct parameter
2-
31
import {
4-
Description, DisplayIcon,
2+
Description,
3+
DisplayIcon,
54
DisplayMessage,
65
Documentation,
76
FunctionContext,
@@ -11,17 +10,14 @@ import {
1110
RuntimeError,
1211
Signature,
1312
} from "@code0-tech/hercules";
14-
import { cancelShipment } from "../helpers.js";
15-
import {
16-
CancelShipmentRequestData,
17-
CancelShipmentResponseData,
18-
} from "../data_types/glsCancelShipment.js";
13+
import {cancelShipment} from "../helpers.js";
14+
import {CancelShipmentResponseData} from "../data_types/glsCancelShipment.js";
1915

2016
@Identifier("cancelShipment")
2117
@DisplayIcon("codezero:gls")
22-
@Signature("(data: GLS_CANCEL_SHIPMENT_REQUEST_DATA): GLS_CANCEL_SHIPMENT_RESPONSE_DATA")
23-
@Name({ code: "en-US", content: "Cancel shipment" })
24-
@DisplayMessage({ code: "en-US", content: "Cancel shipment" })
18+
@Signature("(TrackID: string): GLS_CANCEL_SHIPMENT_RESPONSE_DATA")
19+
@Name({code: "en-US", content: "Cancel shipment"})
20+
@DisplayMessage({code: "en-US", content: "Cancel shipment"})
2521
@Documentation({
2622
code: "en-US",
2723
content: "Cancels an existing shipment by its Track ID. Only possible if the parcel has not yet been scanned.",
@@ -31,14 +27,16 @@ import {
3127
content: "Cancels an existing shipment by its Track ID. Only possible if the parcel has not yet been scanned.",
3228
})
3329
@Parameter({
34-
runtimeName: "data",
35-
name: [{ code: "en-US", content: "Data" }],
36-
description: [{ code: "en-US", content: "The cancel shipment request data." }],
30+
runtimeName: "TrackID",
31+
name: [{code: "en-US", content: "Track ID"}],
32+
description: [{code: "en-US", content: "The Track ID of the shipment to cancel."}],
3733
})
3834
export class CancelShipmentFunction {
39-
async run(context: FunctionContext, data: CancelShipmentRequestData): Promise<CancelShipmentResponseData> {
35+
async run(context: FunctionContext, TrackID: string): Promise<CancelShipmentResponseData> {
4036
try {
41-
return await cancelShipment(data, context);
37+
return await cancelShipment({
38+
TrackID
39+
}, context);
4240
} catch (error) {
4341
if (typeof error === "string") {
4442
throw new RuntimeError("ERROR_CREATING_GLS_SHIPMENT", error);

actions/gls-action/src/functions/getAllowedServicesFunction.ts

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//TODO: Why is the request data here wrapped within a object and isn't a direct parameter of 3
2-
31
import axios from "axios";
42
import {
53
Description, DisplayIcon,
@@ -14,14 +12,13 @@ import {
1412
} from "@code0-tech/hercules";
1513
import { getAuthToken } from "../helpers.js";
1614
import {
17-
AllowedServicesRequestData,
1815
AllowedServicesResponseData,
1916
AllowedServicesResponseDataSchema,
2017
} from "../data_types/glsAllowedServices.js";
2118

2219
@Identifier("getAllowedServices")
2320
@DisplayIcon("codezero:gls")
24-
@Signature("(data: GLS_ALLOWED_SERVICES_REQUEST_DATA): GLS_ALLOWED_SERVICES_RESPONSE_DATA")
21+
@Signature("(SourceCountryCode: string, SourceZIPCode: string, DestinationCountryCode: string, DestinationZIPCode: string, ContactID?: string): GLS_ALLOWED_SERVICES_RESPONSE_DATA")
2522
@Name({ code: "en-US", content: "Get allowed services" })
2623
@DisplayMessage({ code: "en-US", content: "Get allowed services" })
2724
@Documentation({
@@ -33,20 +30,62 @@ import {
3330
content: "Returns the GLS services available for a given origin/destination country and ZIP code combination.",
3431
})
3532
@Parameter({
36-
runtimeName: "data",
37-
name: [{ code: "en-US", content: "Data" }],
38-
description: [{ code: "en-US", content: "The allowed services request data." }],
33+
runtimeName: "SourceCountryCode",
34+
name: [{ code: "en-US", content: "Source country code" }],
35+
description: [{ code: "en-US", content: "The ISO alpha-2 country code of the origin. For example, DE for Germany." }],
36+
})
37+
@Parameter({
38+
runtimeName: "SourceZIPCode",
39+
name: [{ code: "en-US", content: "Source ZIP code" }],
40+
description: [{ code: "en-US", content: "The ZIP code of the origin. Max length is 10 characters." }],
41+
})
42+
@Parameter({
43+
runtimeName: "DestinationCountryCode",
44+
name: [{ code: "en-US", content: "Destination country code" }],
45+
description: [{ code: "en-US", content: "The ISO alpha-2 country code of the destination. For example, FR for France." }],
46+
})
47+
@Parameter({
48+
runtimeName: "DestinationZIPCode",
49+
name: [{ code: "en-US", content: "Destination ZIP code" }],
50+
description: [{ code: "en-US", content: "The ZIP code of the destination. Max length is 10 characters." }],
51+
})
52+
@Parameter({
53+
runtimeName: "ContactID",
54+
name: [{ code: "en-US", content: "Contact ID" }],
55+
description: [{ code: "en-US", content: "The GLS contact ID to use for the request." }],
56+
optional: true,
3957
})
4058
export class GetAllowedServicesFunction {
41-
async run(context: FunctionContext, data: AllowedServicesRequestData): Promise<AllowedServicesResponseData> {
59+
async run(
60+
context: FunctionContext,
61+
SourceCountryCode: string,
62+
SourceZIPCode: string,
63+
DestinationCountryCode: string,
64+
DestinationZIPCode: string,
65+
ContactID?: string
66+
): Promise<AllowedServicesResponseData> {
4267
try {
4368
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
44-
const result = await axios.post(`${url}/rs/shipments/allowedservices`, data, {
45-
headers: {
46-
Authorization: `Bearer ${await getAuthToken(context)}`,
47-
"Content-Type": "application/glsVersion1+json",
69+
const result = await axios.post(
70+
`${url}/rs/shipments/allowedservices`,
71+
{
72+
Source: {
73+
CountryCode: SourceCountryCode,
74+
ZIPCode: SourceZIPCode,
75+
},
76+
Destination: {
77+
CountryCode: DestinationCountryCode,
78+
ZIPCode: DestinationZIPCode,
79+
},
80+
ContactID,
4881
},
49-
});
82+
{
83+
headers: {
84+
Authorization: `Bearer ${await getAuthToken(context)}`,
85+
"Content-Type": "application/glsVersion1+json",
86+
},
87+
}
88+
);
5089
return AllowedServicesResponseDataSchema.parse(result.data);
5190
} catch (error) {
5291
if (typeof error === "string") {

actions/gls-action/src/functions/getEndOfDayReportFunction.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//TODO: Why is the request data here wrapped within a object and isn't a direct parameter
2-
31
import axios from "axios";
42
import {
53
Description, DisplayIcon,
@@ -14,14 +12,13 @@ import {
1412
} from "@code0-tech/hercules";
1513
import { getAuthToken } from "../helpers.js";
1614
import {
17-
EndOfDayRequestData,
1815
EndOfDayResponseData,
1916
EndOfDayResponseDataSchema,
2017
} from "../data_types/glsEndOfDay.js";
2118

2219
@Identifier("getEndOfDayReport")
2320
@DisplayIcon("codezero:gls")
24-
@Signature("(data: GLS_END_OF_DAY_REQUEST_DATA): GLS_END_OF_DAY_RESPONSE_DATA")
21+
@Signature("(date: string): GLS_END_OF_DAY_RESPONSE_DATA")
2522
@Name({ code: "en-US", content: "Get end of day report" })
2623
@DisplayMessage({ code: "en-US", content: "Get end of day report" })
2724
@Documentation({
@@ -33,17 +30,17 @@ import {
3330
content: "Retrieves all shipments dispatched on a given date. Useful for reconciliation and end-of-day processing.",
3431
})
3532
@Parameter({
36-
runtimeName: "data",
37-
name: [{ code: "en-US", content: "Data" }],
38-
description: [{ code: "en-US", content: "The end of day report request data." }],
33+
runtimeName: "date",
34+
name: [{ code: "en-US", content: "Date" }],
35+
description: [{ code: "en-US", content: "The dispatch date to retrieve shipments for, in ISO format (YYYY-MM-DD)." }],
3936
})
4037
export class GetEndOfDayReportFunction {
41-
async run(context: FunctionContext, data: EndOfDayRequestData): Promise<EndOfDayResponseData> {
38+
async run(context: FunctionContext, date: string): Promise<EndOfDayResponseData> {
4239
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
4340

4441
try {
4542
const result = await axios.post(
46-
`${url}/rs/shipments/endofday?date=${data.date}`,
43+
`${url}/rs/shipments/endofday?date=${date}`,
4744
{},
4845
{
4946
headers: {

actions/gls-action/src/functions/reprintParcelFunction.ts

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import {
1414
} from "@code0-tech/hercules";
1515
import { getAuthToken } from "../helpers.js";
1616
import {
17-
ReprintParcelRequestData,
1817
ReprintParcelResponseData,
1918
ReprintParcelResponseDataSchema,
2019
} from "../data_types/glsReprintParcel.js";
20+
import { ReturnLabels } from "../data_types/glsPrintingOptions.js";
2121

2222
@Identifier("reprintParcel")
2323
@DisplayIcon("codezero:gls")
24-
@Signature("(data: GLS_REPRINT_PARCEL_REQUEST_DATA): GLS_REPRINT_PARCEL_RESPONSE_DATA")
24+
@Signature("(CreationDate: string, TemplateSet: \"NONE\"|\"D_200\"|\"PF_4_I\"|\"PF_4_I_200\"|\"PF_4_I_300\"|\"PF_8_D_200\"|\"T_200_BF\"|\"T_300_BF\"|\"ZPL_200\"|\"ZPL_200_TRACKID_EAN_128\"|\"ZPL_200_TRACKID_CODE_39\"|\"ZPL_200_REFNO_EAN_128\"|\"ZPL_200_REFNO_CODE_39\"|\"ZPL_300\"|\"ZPL_300_TRACKID_EAN_128\"|\"ZPL_300_TRACKID_CODE_39\"|\"ZPL_300_REFNO_EAN_128\"|\"ZPL_300_REFNO_CODE_39\", LabelFormat: \"PDF\"|\"ZEBRA\"|\"INTERMEC\"|\"DATAMAX\"|\"TOSHIBA\"|\"PNG\", TrackID?: string, ParcelNumber?: number, ShipmentReference?: string, ShipmentUnitReference?: string, PartnerParcelNumber?: string): GLS_REPRINT_PARCEL_RESPONSE_DATA")
2525
@Name({ code: "en-US", content: "Reprint parcel" })
2626
@DisplayMessage({ code: "en-US", content: "Reprint parcel" })
2727
@Documentation({
@@ -33,21 +33,88 @@ import {
3333
content: "Reprints the label for an existing parcel.\nUse this if the original label is damaged, lost, or needs to be printed in a different format.",
3434
})
3535
@Parameter({
36-
runtimeName: "data",
37-
name: [{ code: "en-US", content: "Data" }],
38-
description: [{ code: "en-US", content: "The reprint parcel request data." }],
36+
runtimeName: "CreationDate",
37+
name: [{ code: "en-US", content: "Creation date" }],
38+
description: [{ code: "en-US", content: "The creation date of the parcel, in ISO format (YYYY-MM-DD)." }],
39+
})
40+
@Parameter({
41+
runtimeName: "TemplateSet",
42+
name: [{ code: "en-US", content: "Template set" }],
43+
description: [{ code: "en-US", content: "The template set to use for the reprinted label." }],
44+
})
45+
@Parameter({
46+
runtimeName: "LabelFormat",
47+
name: [{ code: "en-US", content: "Label format" }],
48+
description: [{ code: "en-US", content: "The format of the reprinted label." }],
49+
})
50+
@Parameter({
51+
runtimeName: "TrackID",
52+
name: [{ code: "en-US", content: "Track ID" }],
53+
description: [{ code: "en-US", content: "The Track ID of the parcel to reprint. Max length is 8 characters." }],
54+
optional: true,
55+
})
56+
@Parameter({
57+
runtimeName: "ParcelNumber",
58+
name: [{ code: "en-US", content: "Parcel number" }],
59+
description: [{ code: "en-US", content: "The parcel number of the parcel to reprint." }],
60+
optional: true,
61+
})
62+
@Parameter({
63+
runtimeName: "ShipmentReference",
64+
name: [{ code: "en-US", content: "Shipment reference" }],
65+
description: [{ code: "en-US", content: "The shipment reference of the parcel to reprint. Max length is 40 characters." }],
66+
optional: true,
67+
})
68+
@Parameter({
69+
runtimeName: "ShipmentUnitReference",
70+
name: [{ code: "en-US", content: "Shipment unit reference" }],
71+
description: [{ code: "en-US", content: "The shipment unit reference of the parcel to reprint. Max length is 40 characters." }],
72+
optional: true,
73+
})
74+
@Parameter({
75+
runtimeName: "PartnerParcelNumber",
76+
name: [{ code: "en-US", content: "Partner parcel number" }],
77+
description: [{ code: "en-US", content: "The partner parcel number of the parcel to reprint. Max length is 50 characters." }],
78+
optional: true,
3979
})
4080
export class ReprintParcelFunction {
41-
async run(context: FunctionContext, data: ReprintParcelRequestData): Promise<ReprintParcelResponseData> {
81+
async run(
82+
context: FunctionContext,
83+
CreationDate: string,
84+
TemplateSet: ReturnLabels["TemplateSet"],
85+
LabelFormat: ReturnLabels["LabelFormat"],
86+
TrackID?: string,
87+
ParcelNumber?: number,
88+
ShipmentReference?: string,
89+
ShipmentUnitReference?: string,
90+
PartnerParcelNumber?: string
91+
): Promise<ReprintParcelResponseData> {
4292
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
4393

4494
try {
45-
const result = await axios.post(`${url}/rs/shipments/reprintparcel`, data, {
46-
headers: {
47-
Authorization: `Bearer ${await getAuthToken(context)}`,
48-
"Content-Type": "application/glsVersion1+json",
95+
const result = await axios.post(
96+
`${url}/rs/shipments/reprintparcel`,
97+
{
98+
TrackID,
99+
ParcelNumber,
100+
ShipmentReference,
101+
ShipmentUnitReference,
102+
PartnerParcelNumber,
103+
CreationDate,
104+
PrintingOptions: {
105+
ReturnLabels: {
106+
TemplateSet,
107+
LabelFormat,
108+
},
109+
},
49110
},
50-
});
111+
{
112+
headers: {
113+
Authorization: `Bearer ${await getAuthToken(context)}`,
114+
"Content-Type": "application/glsVersion1+json",
115+
},
116+
}
117+
);
51118
return ReprintParcelResponseDataSchema.parse(result.data);
52119
} catch (error: any) {
53120
console.log(error);

0 commit comments

Comments
 (0)