1- //TODO: Why is the request data here wrapped within a object and isn't a direct parameter of 3
2-
31import axios from "axios" ;
42import {
53 Description , DisplayIcon ,
@@ -14,14 +12,13 @@ import {
1412} from "@code0-tech/hercules" ;
1513import { getAuthToken } from "../helpers.js" ;
1614import {
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,61 @@ 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." } ] ,
3956} )
4057export class GetAllowedServicesFunction {
41- async run ( context : FunctionContext , data : AllowedServicesRequestData ) : Promise < AllowedServicesResponseData > {
58+ async run (
59+ context : FunctionContext ,
60+ SourceCountryCode : string ,
61+ SourceZIPCode : string ,
62+ DestinationCountryCode : string ,
63+ DestinationZIPCode : string ,
64+ ContactID ?: string
65+ ) : Promise < AllowedServicesResponseData > {
4266 try {
4367 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" ,
68+ const result = await axios . post (
69+ `${ url } /rs/shipments/allowedservices` ,
70+ {
71+ Source : {
72+ CountryCode : SourceCountryCode ,
73+ ZIPCode : SourceZIPCode ,
74+ } ,
75+ Destination : {
76+ CountryCode : DestinationCountryCode ,
77+ ZIPCode : DestinationZIPCode ,
78+ } ,
79+ ContactID,
4880 } ,
49- } ) ;
81+ {
82+ headers : {
83+ Authorization : `Bearer ${ await getAuthToken ( context ) } ` ,
84+ "Content-Type" : "application/glsVersion1+json" ,
85+ } ,
86+ }
87+ ) ;
5088 return AllowedServicesResponseDataSchema . parse ( result . data ) ;
5189 } catch ( error ) {
5290 if ( typeof error === "string" ) {
0 commit comments