From 1a9b8285cd2129712b4fb216bcdff931cfe0882a Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Sun, 29 Mar 2026 21:47:43 +0200 Subject: [PATCH 1/4] First progress in generating docs --- actions/gls-action/package.json | 3 +- actions/gls-action/scripts/generateTypes.ts | 132 ++++ actions/gls-action/src/types/glsAddress.ts | 69 +- .../src/types/glsEndOfDayRequest.ts | 11 +- actions/gls-action/src/types/glsShipment.ts | 4 +- .../src/types/glsShipmentService.ts | 33 - actions/gls-action/vite.config.ts | 1 + docs/Actions/GLS/types.md | 434 ------------- docs/Actions/GLS/types.mdx | 603 ++++++++++++++++++ package-lock.json | 18 +- package.json | 3 +- tsconfig.base.json | 4 +- 12 files changed, 816 insertions(+), 499 deletions(-) create mode 100644 actions/gls-action/scripts/generateTypes.ts delete mode 100644 docs/Actions/GLS/types.md create mode 100644 docs/Actions/GLS/types.mdx diff --git a/actions/gls-action/package.json b/actions/gls-action/package.json index 1e8868d..106637b 100644 --- a/actions/gls-action/package.json +++ b/actions/gls-action/package.json @@ -9,6 +9,7 @@ "build": "vite build", "lint": "eslint .", "test": "vitest run", - "start": "node dist/main.js" + "start": "node dist/main.js", + "docs:generate": "npm run build && node dist/generateTypes.js > ../../docs/Actions/GLS/types.mdx" } } diff --git a/actions/gls-action/scripts/generateTypes.ts b/actions/gls-action/scripts/generateTypes.ts new file mode 100644 index 0000000..aea98d1 --- /dev/null +++ b/actions/gls-action/scripts/generateTypes.ts @@ -0,0 +1,132 @@ +import {loadAllDefinitions} from "../src/helpers"; +import { + HerculesActionConfigurationDefinition, + HerculesDataType, HerculesFlowType, HerculesRegisterFunctionParameter, +} from "@code0-tech/hercules"; + + +const state = { + dataTypes: [] as HerculesDataType[], + actionConfigurationDefinitions: [] as HerculesActionConfigurationDefinition[], + runtimeFunctions: [] as HerculesRegisterFunctionParameter[], + flowTypes: [] as HerculesFlowType[] +} + + +async function run() { + await loadAllDefinitions({ + onError: handler => { + }, + connect: options => Promise.resolve([]), + dispatchEvent: (event, payload) => Promise.resolve(), + getProjectActionConfigurations: () => [], + config: { + authToken: "", + aquilaUrl: "", + version: "", + actionId: "" + }, + fullyConnected: () => false, + registerDataTypes: (...dataTypes) => { + state.dataTypes = [ + ...dataTypes, + ...state.dataTypes + ] + return Promise.resolve() + }, + registerConfigDefinitions: (...actionConfigurations) => { + state.actionConfigurationDefinitions = [ + ...actionConfigurations, + ...state.actionConfigurationDefinitions + ] + return Promise.resolve() + }, + registerFunctionDefinitions: (...functionDefinitions) => { + state.runtimeFunctions = [ + ...functionDefinitions, + ...state.runtimeFunctions + ] + return Promise.resolve() + }, + registerFlowTypes: (...flowTypes) => { + return Promise.resolve() + } + + }) +} + +run().then(async () => { + let typeContent = `--- +title: Datatypes +description: All data types registered by the GLS Action — field references and descriptions. +--- + +# GLS Action Types + +The GLS Action registers the following data types with the Hercules platform. These types are used as inputs and outputs +of the GLS functions and can be referenced in your flows. + +--- + ` + + state.dataTypes.forEach(value => { + value.type = `export type ${value.identifier} = ${value.type}` + .replace(/ \| undefined/g, "") + .replace(/\/\*\*/g, "/**\n") + .replace(/\*\//g, "\n**/") + .replace( + /(\w+)(\?)?:\s*(GLS_\w+);/g, + (match, name, optionalMark, gls) => { + if (optionalMark) { + return `/** + Optional. + @fumadocsHref #type-table-temp.ts-${gls} +**/ +${name}: ${gls}`; + } + + return `/** + @fumadocsHref #type-table-temp.ts-${gls} +**/ +${name}: ${gls}`; + } + ); + + let array = false + if (value.type.endsWith("[];")) { + value.type = value.type.slice(0, -3) + ";" + array = true + } + + typeContent += ` +# ${value.identifier}${array ? " (array)" : ""} + + + +` + }) + typeContent = typeContent.replace(" | undefined", "") + + console.log(typeContent) +}) + + + + + + + + + + + + + + + + + diff --git a/actions/gls-action/src/types/glsAddress.ts b/actions/gls-action/src/types/glsAddress.ts index c75eb2c..4d76bc6 100644 --- a/actions/gls-action/src/types/glsAddress.ts +++ b/actions/gls-action/src/types/glsAddress.ts @@ -3,19 +3,62 @@ import z from "zod" import {singleZodSchemaToTypescriptDef} from "../helpers"; export const AddressSchema = z.object({ - Name1: z.string().max(40), - Name2: z.string().max(40).optional(), - Name3: z.string().max(40).optional(), - CountryCode: z.string().max(2), - Province: z.string().max(40).optional(), - City: z.string().max(40), - Street: z.string().min(4), - StreetNumber: z.string().max(40).optional(), - ContactPerson: z.string().max(40).min(6).optional(), - FixedLinePhonenumber: z.string().max(35).min(4).optional(), - MobilePhonenumber: z.string().max(35).min(4).optional(), - eMail: z.string().max(80).optional(), - ZIPCode: z.string().max(10), + Name1: z.string().max(40).describe(` + Primary name line (person or company). + Max 40 characters. + `), + Name2: z.string().max(40).optional().describe(` + Optional second name line (e.g., department or additional identifier). + Max 40 characters. + `), Name3: z.string().max(40).optional().describe(` + Optional third name line for extended address details. + Max 40 characters. + `), + CountryCode: z.string().max(2).describe(` + Two-letter ISO country code (e.g., DE, US). + `), + Province: z.string().max(40).optional().describe(` + State, province, or region. + Optional field. + Max 40 characters. + `), + City: z.string().max(40).describe(` + City or locality name. + Max 40 characters. + `), + Street: z.string().min(4).describe(` + Street name. + Minimum 4 characters required. + `), + StreetNumber: z.string().max(40).optional().describe(` + House or building number. + Optional field. + Max 40 characters. + `), + ContactPerson: z.string().max(40).min(6).optional().describe(` + Full name of a contact person. + Optional field. + Must be between 6 and 40 characters. + `), + FixedLinePhonenumber: z.string().max(35).min(4).optional().describe(` + Landline phone number. + Optional field. + Must be between 4 and 35 characters. + `), + MobilePhonenumber: z.string().max(35).min(4).optional().describe(` + Mobile phone number. + Optional field. + Must be between 4 and 35 characters. + `), + eMail: z.string().max(80).optional().describe(` + Email address. + Optional field. + Max 80 characters. + `), + ZIPCode: z.string().max(10).describe(` + Postal or ZIP code. + Max 10 characters. + `), }) export type AddressSchema = z.infer diff --git a/actions/gls-action/src/types/glsEndOfDayRequest.ts b/actions/gls-action/src/types/glsEndOfDayRequest.ts index 50f4964..81b62bb 100644 --- a/actions/gls-action/src/types/glsEndOfDayRequest.ts +++ b/actions/gls-action/src/types/glsEndOfDayRequest.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {singleZodSchemaToTypescriptDef} from "../helpers"; +import {singleZodSchemaToTypescriptDef, zodSchemaToTypescriptDefs} from "../helpers"; import z from "zod"; import {AddressSchema} from "./glsAddress"; @@ -50,10 +50,13 @@ export default (sdk: ActionSdk) => { }, { identifier: "GLS_END_OF_DAY_RESPONSE_DATA", - type: singleZodSchemaToTypescriptDef( + type: zodSchemaToTypescriptDefs( "GLS_END_OF_DAY_RESPONSE_DATA", - EndOfDayResponseDataSchema - ), + EndOfDayResponseDataSchema, + { + GLS_ADDRESS: AddressSchema + } + ).get("GLS_END_OF_DAY_RESPONSE_DATA")!, name: [ { code: "en-US", diff --git a/actions/gls-action/src/types/glsShipment.ts b/actions/gls-action/src/types/glsShipment.ts index 1e328f2..2bae894 100644 --- a/actions/gls-action/src/types/glsShipment.ts +++ b/actions/gls-action/src/types/glsShipment.ts @@ -17,7 +17,7 @@ export const ShipmentSchema = z.object({ Consignee: ConsigneeSchema, Shipper: ShipperSchema.optional(), Carrier: z.enum(["ROYALMAIL"]).optional(), - ShipmentUnit: ShipmentUnitSchema, + ShipmentUnit: z.lazy(() => ShipmentUnitSchema), Service: z.lazy(() => ShipmentServiceSchema), Return: z.object({ Address: AddressSchema @@ -30,7 +30,7 @@ export const InternalShipmentSchma = ShipmentSchema.extend({ Middleware: z.string().max(40), Shipper: InternalShipperSchema, Service: z.lazy(() => InternalShipmentServiceSchema), - ShipmentUnit: InternalShipmentUnitSchema + ShipmentUnit: z.lazy(() => InternalShipmentUnitSchema) }) export default (sdk: ActionSdk) => { diff --git a/actions/gls-action/src/types/glsShipmentService.ts b/actions/gls-action/src/types/glsShipmentService.ts index 5f85514..c65ccf1 100644 --- a/actions/gls-action/src/types/glsShipmentService.ts +++ b/actions/gls-action/src/types/glsShipmentService.ts @@ -1,8 +1,5 @@ import z from "zod"; import {AddressSchema} from "./glsAddress"; -import {zodSchemaToTypescriptDefs} from "../helpers"; -import {ShipmentSchema} from "./glsShipment"; -import {ActionSdk} from "@code0-tech/hercules"; export const ShipmentServiceSchema = z.array(z.object({ @@ -185,33 +182,3 @@ export const InternalShipmentServiceSchema = z.array(z.object({ serviceName: z.string().default("service_Saturday"), }).optional(), })).optional() - -export default (sdk: ActionSdk) => { - return sdk.registerDataTypes( - { - identifier: "GLS_SHIPMENT_SERVICE", - type: zodSchemaToTypescriptDefs( - "XXX", - ShipmentSchema, - { - GLS_SHIPMENT_SERVICE: ShipmentServiceSchema, - } - ).get("GLS_SHIPMENT_SERVICE")!, // Hacky way because shipment service is defined as an array - name: [ - { - code: "en-US", - content: "Shipment Service" - } - ], - displayMessage: [ - { - code: "en-US", - content: "Shipment Service" - } - ], - linkedDataTypes: [ - "GLS_ADDRESS" - ] - }, - ) -} diff --git a/actions/gls-action/vite.config.ts b/actions/gls-action/vite.config.ts index f584efa..f258811 100644 --- a/actions/gls-action/vite.config.ts +++ b/actions/gls-action/vite.config.ts @@ -10,6 +10,7 @@ export default defineConfig({ rollupOptions: { input: { main: resolve(__dirname, 'src/index.ts'), + generateTypes: resolve(__dirname, 'scripts/generateTypes.ts') }, external: [ 'fs', diff --git a/docs/Actions/GLS/types.md b/docs/Actions/GLS/types.md deleted file mode 100644 index fd3af33..0000000 --- a/docs/Actions/GLS/types.md +++ /dev/null @@ -1,434 +0,0 @@ ---- -title: Datatypes -description: All data types registered by the GLS Action — field references and descriptions. ---- - -# GLS Action Types - -The GLS Action registers the following data types with the Hercules platform. These types are used as inputs and outputs -of the GLS functions and can be referenced in your flows. - ---- - -## `GLS_ADDRESS` - -Represents a physical address used for consignee, shipper, and return addresses. - -**Used by:** `GLS_CONSIGNEE`, `GLS_SHIPPER`, `GLS_SHIPMENT_SERVICE` (Exchange, DeliveryAtWork, etc.) - -| Field | Type | Required | Constraints | Description | -|------------------------|--------|----------|---------------|--------------------------------------------| -| `Name1` | string | **Yes** | max 40 | Primary name (person or company) | -| `Name2` | string | No | max 40 | Additional name line (e.g. department) | -| `Name3` | string | No | max 40 | Additional name line (e.g. c/o) | -| `CountryCode` | string | **Yes** | max 2 | ISO alpha-2 country code (e.g. `DE`, `FR`) | -| `Province` | string | No | max 40 | State or province | -| `City` | string | **Yes** | max 40 | City name | -| `Street` | string | **Yes** | min 4 | Street name | -| `StreetNumber` | string | No | max 40 | House/building number | -| `ContactPerson` | string | No | min 6, max 40 | Contact person name | -| `FixedLinePhonenumber` | string | No | min 4, max 35 | Landline phone number | -| `MobilePhonenumber` | string | No | min 4, max 35 | Mobile phone number | -| `eMail` | string | No | max 80 | Email address | -| `ZIPCode` | string | **Yes** | max 10 | Postal/ZIP code | - ---- - -## `GLS_CONSIGNEE` - -Represents the recipient of a shipment. - -**Used by:** `GLS_SHIPMENT` - -**Linked types:** `GLS_ADDRESS` - -| Field | Type | Required | Constraints | Description | -|---------------|-----------------------------|----------|-------------|-------------------------------------| -| `ConsigneeID` | string | No | max 40 | Your internal customer/consignee ID | -| `CostCenter` | string | No | max 80 | Cost center for billing | -| `Category` | `"BUSINESS"` \| `"PRIVATE"` | No | — | Type of recipient | -| `AddressSchema` | GLS_ADDRESS | **Yes** | — | Physical delivery address | - ---- - -## `GLS_SHIPPER` - -Represents the sender of a shipment. - -**Used by:** `GLS_SHIPMENT`, action configuration - -**Linked types:** `GLS_ADDRESS` - -| Field | Type | Required | Description | -|-----------------------------|-------------|----------|-------------------------------------------| -| `AddressSchema` | GLS_ADDRESS | No | Primary shipper address | -| `AlternativeShipperAddress` | GLS_ADDRESS | No | Alternative address to print on the label | - -> **Note:** When used in the configuration (`shipper`), the action automatically includes the `ContactID` from the -`contact_id` configuration value. - ---- - -## `GLS_UNIT_SERVICE` - -An optional array of value-added services applied to an individual shipment unit (parcel). - -**Used by:** `GLS_SHIPMENT_UNIT` - -Each element is an object with one or more of the following optional fields: - -| Service field | Description | -|---------------------|----------------------------------------------------------------------------------| -| `Cash` | Cash on delivery — `Reason` (max 160), `Amount` (min 1), `Currency` (3 chars) | -| `AddonLiability` | Additional liability insurance — `Amount`, `Currency`, `ParcelContent` (max 255) | -| `HazardousGoods` | Hazardous goods declaration — array of `{ Weight, GLSHazNo (max 8) }` | -| `ExWorks` | Ex-works shipping terms | -| `LimitedQuantities` | Limited quantities of dangerous goods — optional `Weight` | - ---- - -## `GLS_SHIPMENT_UNIT` - -Represents a single parcel within a shipment. A shipment may contain multiple units. - -**Used by:** `GLS_SHIPMENT`, `GLS_SHIPMENT_WITHOUT_SERVICES` - -**Linked types:** `GLS_UNIT_SERVICE` - -| Field | Type | Required | Constraints | Description | -|-------------------------|------------------|----------|-------------|---------------------------------| -| `Weight` | number | **Yes** | 0.10–99 kg | Weight of the parcel | -| `ShipmentUnitReference` | string | No | max 40 | Your internal parcel reference | -| `PartnerParcelNumber` | string | No | max 50 | Partner-assigned number | -| `Note1` | string | No | max 50 | Label note line 1 | -| `Note2` | string | No | max 50 | Label note line 2 | -| `Service` | GLS_UNIT_SERVICE | No | — | Unit-level value-added services | - ---- - -## `GLS_SHIPMENT_SERVICE` - -An optional array of shipment-level services. Shipment creation functions automatically populate this based on which -function you call. - -**Used by:** `GLS_SHIPMENT` - -Each element is an object with one of the following service fields: - -| Service | Parameters | Description | -|------------------------|------------------------------------------------------------------------------------------|------------------------------------| -| `ShopDelivery` | `ParcelShopID` (max 50) | Delivery to a GLS Parcel Shop | -| `ShopReturn` | `NumberOfLabels`, `ReturnQR?` | Return from a Parcel Shop | -| `Exchange` | `AddressSchema` (GLS_ADDRESS), `ExpectedWeight?` | Exchange delivery and pickup | -| `DeliveryAtWork` | `RecipientName`, `Building`, `Floor`, `Room?`, `Phonenumber?`, `AlternateRecipientName?` | Workplace delivery | -| `Deposit` | `PlaceOfDeposit` (max 121) | Deposit without signature | -| `IdentPin` | `PIN` (max 4), `Birthdate?` | PIN-based identity check | -| `Ident` | `Birthdate`, `Firstname`, `Lastname`, `Nationality` (max 2) | Full identity check | -| `PickAndShip` | `PickupDate` | GLS picks up from consignee | -| `FlexDeliveryService` | — | Recipient can redirect delivery | -| `SignatureService` | — | Signature required on delivery | -| `Guaranteed24Service` | — | 24-hour guaranteed delivery | -| `AddresseeOnlyService` | — | Delivery to named addressee only | -| `TyreService` | — | Tyre/wheel delivery service | -| `EOB` | — | End of Business (next working day) | -| `SaturdayService` | — | Saturday delivery | -| `Saturday1000Service` | — | Saturday by 10:00 | -| `Saturday1200Service` | — | Saturday by 12:00 | - ---- - -## `GLS_SHIPMENT` - -The complete shipment object including all services. - -**Used by:** `GLS_VALIDATE_SHIPMENT_REQUEST_DATA` - -**Linked types:** `GLS_CONSIGNEE`, `GLS_SHIPPER`, `GLS_SHIPMENT_UNIT`, `GLS_SHIPMENT_SERVICE`, `GLS_ADDRESS` - -| Field | Type | Required | Description | -|-----------------------------|---------------------------|----------|--------------------------------------------------| -| `Product` | `"PARCEL"` \| `"EXPRESS"` | **Yes** | Shipment product type | -| `ConsigneeSchema` | GLS_CONSIGNEE | **Yes** | Recipient details | -| `ShipperSchema` | GLS_SHIPPER | **Yes** | Sender details | -| `ShipmentUnit` | GLS_SHIPMENT_UNIT[] | **Yes** | Array of parcels (min 1) | -| `Service` | GLS_SHIPMENT_SERVICE | No | Shipment-level services | -| `ShipmentReference` | string (max 40) | No | Your internal shipment reference | -| `ShipmentDate` | date | No | Shipment date (defaults to today) | -| `IncotermCode` | integer (max 99) | No | International commerce terms code | -| `Identifier` | string (max 40) | No | Additional identifier | -| `ExpressAltDeliveryAllowed` | boolean | No | Allow alternative delivery for express shipments | -| `Carrier` | `"ROYALMAIL"` | No | Override carrier (UK only) | -| `Return.AddressSchema` | GLS_ADDRESS | No | AddressSchema for return shipments | - ---- - -## `GLS_SHIPMENT_WITHOUT_SERVICES` - -The shipment object without the `Service` field. Used as input to all shipment creation functions — the service is added -automatically based on which function you call. - -**Linked types:** `GLS_SHIPMENT` - -Same fields as `GLS_SHIPMENT` except `Service` is omitted. - ---- - -## `GLS_PRINTING_OPTIONS` - -Configures how shipping labels are generated. - -| Field | Type | Required | Description | -|---------------------------------|--------|----------|----------------------------------------------------------------------------------------------------------| -| `ReturnLabels.TemplateSet` | enum | **Yes** | Label template to use | -| `ReturnLabels.LabelFormat` | enum | **Yes** | Output file format | -| `useDefault` | string | No | If set to `"Default"`, uses the default printing options configured in GLS instead of the specified ones | -| `DefinePrinter.LabelPrinter` | string | No | Specify the printer name, only backend printers are valid | -| `DefinePrinter.DocumentPrinter` | string | no | Specify the document printer name, only backend printers are valid | - -**Template sets:** `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` - -**Label formats:** `PDF`, `ZEBRA`, `INTERMEC`, `DATAMAX`, `TOSHIBA`, `PNG` - ---- - -## `GLS_RETURN_OPTIONS` - -Controls whether the GLS API includes print data and routing info in the response. - -| Field | Type | Default | Description | -|---------------------|---------|---------|------------------------------------------| -| `ReturnPrintData` | boolean | `true` | Include base64-encoded label in response | -| `ReturnRoutingInfo` | boolean | `true` | Include routing information in response | - -> Set both to `false` if you only need the `TrackID` and don't need the label data immediately. - ---- - -## `GLS_CUSTOM_CONTENT` - -Customizes what appears on the printed shipping label. - -| Field | Type | Required | Description | -|----------------------|--------------------------------------------|----------|--------------------------------------| -| `CustomerLogo` | string | **Yes** | Base64-encoded logo image | -| `BarcodeContentType` | `"TRACK_ID"` \| `"GLS_SHIPMENT_REFERENCE"` | **Yes** | What to encode in the custom barcode | -| `Barcode` | string | No | Custom barcode value | -| `BarcodeType` | `"EAN_128"` \| `"CODE_39"` | No | Barcode symbology | -| `HideShipperAddress` | boolean | No | Hide shipper address on label | - ---- - -## `GLS_CREATE_PARCELS_RESPONSE` - -The response returned by all shipment creation functions. - -| Field | Type | Description | -|--------------------------------------------------------------|------------------|------------------------------------------| -| `CreatedShipment.ShipmentReference` | string[] | Your shipment references | -| `CreatedShipment.ParcelData[].TrackID` | string (8 chars) | GLS tracking ID — use to track or cancel | -| `CreatedShipment.ParcelData[].ParcelNumber` | string | GLS parcel number | -| `CreatedShipment.ParcelData[].Barcodes.Primary2D` | string | 2D barcode data | -| `CreatedShipment.ParcelData[].Barcodes.Secondary2D` | string | Secondary 2D barcode | -| `CreatedShipment.ParcelData[].Barcodes.Primary1D` | string | 1D barcode data | -| `CreatedShipment.ParcelData[].Barcodes.Primary1DPrint` | boolean | Whether to print 1D barcode | -| `CreatedShipment.ParcelData[].RoutingInfo.Tour` | string | Delivery tour identifier | -| `CreatedShipment.ParcelData[].RoutingInfo.FinalLocationCode` | string | Final delivery depot | -| `CreatedShipment.ParcelData[].RoutingInfo.HubLocation` | string | Hub location code | -| `CreatedShipment.ParcelData[].RoutingInfo.LastRoutingDate` | date | Last valid routing date | -| `CreatedShipment.PrintData[].Data` | string | Base64-encoded label | -| `CreatedShipment.PrintData[].LabelFormat` | enum | Format of the label | -| `CreatedShipment.CustomerID` | string | GLS customer identifier | -| `CreatedShipment.PickupLocation` | string | Depot where parcel will be picked up | -| `CreatedShipment.GDPR` | string[] | GDPR-related references | - ---- - -## `GLS_CANCEL_SHIPMENT_REQUEST_DATA` - -Input for the `cancelShipment` function. - -| Field | Type | Required | Description | -|-----------|--------|----------|-------------------------------------------| -| `TrackID` | string | **Yes** | GLS tracking ID of the shipment to cancel | - ---- - -## `GLS_CANCEL_SHIPMENT_RESPONSE_DATA` - -Response from the `cancelShipment` function. - -| Field | Type | Description | -|-----------|-----------------------------------------------------------------------|------------------------------------| -| `TrackID` | string | The tracking ID that was cancelled | -| `result` | `"CANCELLED"` \| `"CANCELLATION_PENDING"` \| `"SCANNED"` \| `"ERROR"` | Result of the cancellation | - ---- - -## `GLS_ALLOWED_SERVICES_REQUEST_DATA` - -Input for the `getAllowedServices` function. - -| Field | Type | Required | Description | -|---------------------------|-----------------|----------|-----------------------------------| -| `Source.CountryCode` | string (max 2) | **Yes** | Origin country code | -| `Source.ZIPCode` | string (max 10) | **Yes** | Origin ZIP/postal code | -| `Destination.CountryCode` | string (max 2) | **Yes** | Destination country code | -| `Destination.ZIPCode` | string (max 10) | **Yes** | Destination ZIP/postal code | -| `ContactID` | string | No | GLS contact ID (overrides config) | - ---- - -## `GLS_ALLOWED_SERVICES_RESPONSE_DATA` - -Response from the `getAllowedServices` function. - -| Field | Type | Description | -|---------------------------------|--------|------------------------------------------------------| -| `AllowedServices[]` | array | List of services or products available for the route | -| `AllowedServices[].ServiceName` | string | Name of an available service | -| `AllowedServices[].ProductName` | string | Name of an available product | - -Each element contains either `ServiceName` or `ProductName`, not both. - ---- - -## `GLS_END_OF_DAY_REQUEST_DATA` - -Input for the `getEndOfDayReport` function. - -| Field | Type | Required | Description | -|--------|-----------------|----------|-----------------------------------------------------------------| -| `date` | ISO date string | **Yes** | The date for which to retrieve the report (e.g. `"2025-01-15"`) | - ---- - -## `GLS_END_OF_DAY_RESPONSE_DATA` - -Response from the `getEndOfDayReport` function. - -| Field | Type | Description | -|-------------------------------------------------|---------------------------|----------------------------------| -| `Shipments[].ShippingDate` | ISO date | Date the shipment was dispatched | -| `Shipments[].Product` | `"PARCEL"` \| `"EXPRESS"` | Product type | -| `Shipments[].ConsigneeSchema.AddressSchema` | GLS_ADDRESS | Recipient address | -| `Shipments[].ShipperSchema.ContactID` | string | GLS contact ID of shipper | -| `Shipments[].ShipperSchema.AlternativeShipperAddress` | GLS_ADDRESS | Alternative shipper address | -| `Shipments[].ShipmentUnit[].TrackID` | string | Tracking ID | -| `Shipments[].ShipmentUnit[].Weight` | string | Parcel weight | -| `Shipments[].ShipmentUnit[].ParcelNumber` | string | GLS parcel number | - ---- - -## `GLS_UPDATE_PARCEL_WEIGHT_REQUEST_DATA` - -Input for the `updateParcelWeight` function. Provide at least one identifier (`TrackID`, `ParcelNumber`, -`ShipmentReference`, `ShipmentUnitReference`, or `PartnerParcelNumber`). - -| Field | Type | Required | Constraints | Description | -|-------------------------|--------|----------|------------------|----------------------------| -| `TrackID` | string | No | max 8 | GLS tracking ID | -| `ParcelNumber` | number | No | max 999999999999 | GLS parcel number | -| `ShipmentReference` | string | No | max 40 | Your shipment reference | -| `ShipmentUnitReference` | string | No | max 40 | Your parcel unit reference | -| `PartnerParcelNumber` | string | No | max 50 | Partner parcel number | -| `Weight` | number | **Yes** | min 0.10 | New weight in kilograms | - ---- - -## `GLS_UPDATE_PARCEL_WEIGHT_RESPONSE_DATA` - -Response from the `updateParcelWeight` function. - -| Field | Type | Description | -|-----------------|--------|--------------------------------| -| `UpdatedWeight` | string | Confirmed updated weight value | - ---- - -## `GLS_REPRINT_PARCEL_REQUEST_DATA` - -Input for the `reprintParcel` function. Provide at least one identifier. - -| Field | Type | Required | Constraints | Description | -|--------------------------------------------|-----------------|----------|----------------------------------|---------------------------------| -| `TrackID` | string | No | max 8 | GLS tracking ID | -| `ParcelNumber` | number | No | max 999999999999 | GLS parcel number | -| `ShipmentReference` | string | No | max 40 | Your shipment reference | -| `ShipmentUnitReference` | string | No | max 40 | Your parcel unit reference | -| `PartnerParcelNumber` | string | No | max 50 | Partner parcel number | -| `CreationDate` | ISO date string | **Yes** | — | Original shipment creation date | -| `PrintingOptions.ReturnLabels.TemplateSet` | enum | **Yes** | `NONE`, `ZPL_200`, `ZPL_300` | Label template | -| `PrintingOptions.ReturnLabels.LabelFormat` | enum | **Yes** | `PDF`, `ZEBRA`, `PNG`, `PNG_200` | Output format | - ---- - -## `GLS_REPRINT_PARCEL_RESPONSE_DATA` - -Response from the `reprintParcel` function. Same structure as `GLS_CREATE_PARCELS_RESPONSE` without the -`ShipmentReference` and `GDPR` fields. - -| Field | Type | Description | -|------------------------------------------------------|----------|----------------------------------| -| `CreatedShipment.ParcelData[].TrackID` | string | Tracking ID | -| `CreatedShipment.ParcelData[].ShipmentUnitReference` | string[] | Unit references | -| `CreatedShipment.ParcelData[].ParcelNumber` | string | Parcel number | -| `CreatedShipment.ParcelData[].Barcodes` | object | Barcode data | -| `CreatedShipment.ParcelData[].RoutingInfo` | object | Routing details | -| `CreatedShipment.PrintData[].Data` | string | Base64-encoded label | -| `CreatedShipment.PrintData[].LabelFormat` | enum | `PDF`, `ZEBRA`, `PNG`, `PNG_200` | -| `CreatedShipment.CustomerID` | string | GLS customer identifier | -| `CreatedShipment.PickupLocation` | string | Depot pickup location | -| `CreatedShipment.GDPR` | string[] | GDPR references | - ---- - -## `GLS_VALIDATE_SHIPMENT_REQUEST_DATA` - -Input for the `validateShipment` function. - -| Field | Type | Required | Description | -|------------|--------------|----------|-----------------------------------| -| `Shipment` | GLS_SHIPMENT | **Yes** | The complete shipment to validate | - ---- - -## `GLS_VALIDATE_SHIPMENT_RESPONSE_DATA` - -Response from the `validateShipment` function. - -| Field | Type | Description | -|----------------------------------------|----------|--------------------------------------------------| -| `success` | boolean | Whether the shipment passed all validation rules | -| `validationResult.Issues[]` | array | List of validation issues (empty if valid) | -| `validationResult.Issues[].Rule` | string | Name of the failed validation rule | -| `validationResult.Issues[].Location` | string | Path in the data where the issue was found | -| `validationResult.Issues[].Parameters` | string[] | Additional details about the issue | - ---- - -## Type dependency diagram - -``` -GLS_SHIPMENT_WITHOUT_SERVICES - ├── ConsigneeSchema: GLS_CONSIGNEE - │ └── AddressSchema: GLS_ADDRESS - ├── ShipperSchema: GLS_SHIPPER - │ ├── AddressSchema: GLS_ADDRESS - │ └── AlternativeShipperAddress: GLS_ADDRESS - └── ShipmentUnit[]: GLS_SHIPMENT_UNIT - └── Service: GLS_UNIT_SERVICE - -GLS_PRINTING_OPTIONS - └── ReturnLabels: { TemplateSet, LabelFormat } - -GLS_CUSTOM_CONTENT - └── { CustomerLogo, BarcodeContentType, Barcode, BarcodeType, HideShipperAddress } - -GLS_RETURN_OPTIONS - └── { ReturnPrintData, ReturnRoutingInfo } - -─── Shipment function ────────────────────────────────────────────── -[GLS_SHIPMENT_WITHOUT_SERVICES + GLS_PRINTING_OPTIONS + ...] → GLS_CREATE_PARCELS_RESPONSE -``` diff --git a/docs/Actions/GLS/types.mdx b/docs/Actions/GLS/types.mdx new file mode 100644 index 0000000..7110669 --- /dev/null +++ b/docs/Actions/GLS/types.mdx @@ -0,0 +1,603 @@ +--- +title: Datatypes +description: All data types registered by the GLS Action — field references and descriptions. +--- + +# GLS Action Types + +The GLS Action registers the following data types with the Hercules platform. These types are used as inputs and outputs +of the GLS functions and can be referenced in your flows. + +--- + +# GLS_VALIDATE_SHIPMENT_REQUEST_DATA + + + + +# GLS_VALIDATE_SHIPMENT_RESPONSE_DATA + + + + +# GLS_UPDATE_PARCEL_WEIGHT_REQUEST_DATA + + + + +# GLS_UPDATE_PARCEL_WEIGHT_RESPONSE_DATA + + + + +# GLS_UNIT_SERVICE (array) + + + + +# GLS_SHIPPER + + + + +# GLS_SHIPMENT_UNIT (array) + + + + +# GLS_SHIPMENT + + + + +# GLS_SHIPMENT_WITHOUT_SERVICES + + + + +# GLS_RETURN_OPTIONS + + + + +# GLS_REPRINT_PARCEL_REQUEST_DATA + + + + +# GLS_REPRINT_PARCEL_RESPONSE_DATA + + + + +# GLS_PRINTING_OPTIONS + + + + +# GLS_END_OF_DAY_REQUEST_DATA + + + + +# GLS_END_OF_DAY_RESPONSE_DATA + + + + +# GLS_CUSTOM_CONTENT + + + + +# GLS_CREATE_PARCELS_RESPONSE + + + + +# GLS_CONSIGNEE + + + + +# GLS_CANCEL_SHIPMENT_REQUEST_DATA + + + + +# GLS_CANCEL_SHIPMENT_RESPONSE_DATA + + + + +# GLS_ALLOWED_SERVICES_REQUEST_DATA + + + + +# GLS_ALLOWED_SERVICES_RESPONSE_DATA + + + + +# GLS_ADDRESS + + + + diff --git a/package-lock.json b/package-lock.json index f45fe06..b5fc11f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "actions/*" ], "dependencies": { - "@code0-tech/hercules": "file:code0-tech-hercules-0.0.0.tgz", + "@code0-tech/hercules": "^0.0.2", "axios": "^1.13.6", "vite": "^7.3.1", "zod": "^4.3.6", @@ -41,12 +41,12 @@ "link": true }, "node_modules/@code0-tech/hercules": { - "version": "0.0.0", - "resolved": "file:code0-tech-hercules-0.0.0.tgz", - "integrity": "sha512-MwoauVdEnfA7IvODjPt2aPbQe8m0xmFAq+smn/sIId/yeJ1ldmoJjhtDFeXpYgS6fLZQ09lgpXrTYmZAiyRPsQ==", + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/@code0-tech/hercules/-/hercules-0.0.2.tgz", + "integrity": "sha512-oG0N8zRNX8WJmYORhbNnAj75HXi6pzL+xclO3vOxHQiOBjb4hjqnRYIBtCTuR9xAJSXeOEqPu5rgK2hHKTsdzA==", "license": "ISC", "dependencies": { - "@code0-tech/tucana": "file:code0-tech-tucana-0.0.0.tgz", + "@code0-tech/tucana": "^0.0.65", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-backend": "^2.11.1", "@protobuf-ts/grpc-transport": "^2.11.1", @@ -54,10 +54,10 @@ "@protobuf-ts/runtime-rpc": "^2.11.1" } }, - "node_modules/@code0-tech/hercules/node_modules/@code0-tech/tucana": { - "version": "0.0.0", - "resolved": "file:code0-tech-tucana-0.0.0.tgz", - "integrity": "sha512-ZXpWELHdEYyeJaGue9Lq2t0sqnR4F77fxwsAaim0Q7gkilsCCzIFYPy4t3cRhfhKtw3iSknDOGrtFqvAaH6D5w==", + "node_modules/@code0-tech/tucana": { + "version": "0.0.65", + "resolved": "https://registry.npmjs.org/@code0-tech/tucana/-/tucana-0.0.65.tgz", + "integrity": "sha512-XTNAZ+iqTEf1yLU0uqNc2+ICg6tRF0w41C6da9DePoV4qDa2aRmZwA4jJyr/1i+hohZVKRrhkY7Qaf/blsyx0g==", "license": "Apache-2.0" }, "node_modules/@esbuild/aix-ppc64": { diff --git a/package.json b/package.json index 03cbe81..bed8ff4 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "packageManager": "npm@11.12.1", "scripts": { "build": "npm run build --workspaces --if-present", + "docs:generate": "npm run docs:generate --workspaces --if-present", "start": "turbo run start", "test": "vitest run", "test:watch": "vitest", @@ -25,7 +26,7 @@ "vitest": "^4.0.0" }, "dependencies": { - "@code0-tech/hercules": "file:code0-tech-hercules-0.0.0.tgz", + "@code0-tech/hercules": "^0.0.2", "axios": "^1.13.6", "vite": "^7.3.1", "zod": "^4.3.6", diff --git a/tsconfig.base.json b/tsconfig.base.json index fbfad07..8a0c8f5 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -3,8 +3,8 @@ "esModuleInterop": true, "module": "es2022", "moduleResolution": "bundler", - "target": "es2020", - "lib": ["es2020", "dom"], + "target": "es2021", + "lib": ["es2022", "es2021", "dom"], "strict": false, "skipLibCheck": true, "types": ["vite/client"] From 0e6d193c63c71748f93b2a0ee39726ca2badb22b Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Sun, 29 Mar 2026 21:49:58 +0200 Subject: [PATCH 2/4] Fix linter --- actions/gls-action/scripts/generateTypes.ts | 10 +++++++--- actions/gls-action/src/index.ts | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/actions/gls-action/scripts/generateTypes.ts b/actions/gls-action/scripts/generateTypes.ts index aea98d1..d1c6422 100644 --- a/actions/gls-action/scripts/generateTypes.ts +++ b/actions/gls-action/scripts/generateTypes.ts @@ -15,10 +15,10 @@ const state = { async function run() { await loadAllDefinitions({ - onError: handler => { + onError: () => { }, - connect: options => Promise.resolve([]), - dispatchEvent: (event, payload) => Promise.resolve(), + connect: () => Promise.resolve([]), + dispatchEvent: () => Promise.resolve(), getProjectActionConfigurations: () => [], config: { authToken: "", @@ -49,6 +49,10 @@ async function run() { return Promise.resolve() }, registerFlowTypes: (...flowTypes) => { + state.flowTypes = [ + ...state.flowTypes, + ...flowTypes + ] return Promise.resolve() } diff --git a/actions/gls-action/src/index.ts b/actions/gls-action/src/index.ts index f7bae4b..ad330bf 100644 --- a/actions/gls-action/src/index.ts +++ b/actions/gls-action/src/index.ts @@ -18,6 +18,7 @@ async function main() { console.error(error) } } + main().catch(err => { console.error(err) process.exit(1) From c86f9d0544519ec39b7c5636fef369405152dcef Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Sun, 29 Mar 2026 21:53:06 +0200 Subject: [PATCH 3/4] Fix typo --- README.md | 2 +- docs/Actions/GLS/configs.md | 2 +- docs/Actions/GLS/functions.md | 12 ++++++------ docs/Actions/GLS/overview.md | 2 +- docs/index.mdx | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d17526d..4cf5dca 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Full documentation is located in the [`docs/`](docs/) folder: - [GLS Action Overview](docs/Actions/GLS/overview.md) - [GLS Configuration](docs/Actions/GLS/configs.md) - [GLS Functions](docs/Actions/GLS/functions.md) -- [GLS Types](docs/Actions/GLS/types.md) +- [GLS Types](docs/Actions/GLS/types.mdx) - [GLS Events](docs/Actions/GLS/events.md) - [Common Use Cases](docs/Actions/GLS/use-cases.md) - [Troubleshooting & Community Support](docs/Actions/GLS/troubleshooting.md) diff --git a/docs/Actions/GLS/configs.md b/docs/Actions/GLS/configs.md index 20d3de5..fa374e1 100644 --- a/docs/Actions/GLS/configs.md +++ b/docs/Actions/GLS/configs.md @@ -107,4 +107,4 @@ The value must be a valid `GLS_SHIPPER` object: } ``` -See [Types — GLS_SHIPPER](types.md#GLS_SHIPPER) for the full field reference. +See [Types — GLS_SHIPPER](types.mdx#GLS_SHIPPER) for the full field reference. diff --git a/docs/Actions/GLS/functions.md b/docs/Actions/GLS/functions.md index 7633a68..c5ffdde 100644 --- a/docs/Actions/GLS/functions.md +++ b/docs/Actions/GLS/functions.md @@ -56,7 +56,7 @@ createAddress( | `MobilePhonenumber` | string (min 4, max 35) | No | Mobile phone number | | `eMail` | string (max 80) | No | Email address | -**Returns:** [`GLS_ADDRESS`](types.md#GLS_ADDRESS) +**Returns:** [`GLS_ADDRESS`](types.mdx#GLS_ADDRESS) --- @@ -83,7 +83,7 @@ createConsignee( | `AddressSchema` | GLS_ADDRESS | **Yes** | The delivery address for this consignee | | `Category` | `"BUSINESS"` \| `"PRIVATE"` | **Yes** | Whether the consignee is a business or private recipient | -**Returns:** [`GLS_CONSIGNEE`](types.md#GLS_CONSIGNEE) +**Returns:** [`GLS_CONSIGNEE`](types.mdx#GLS_CONSIGNEE) --- @@ -114,7 +114,7 @@ createShipmentUnit( | `note2` | string (max 50) | No | Additional note printed on the label (line 2) | | `shipmentUnitService` | GLS_UNIT_SERVICE | No | Unit-level services (Cash, AddonLiability, HazardousGoods, etc.) | -**Returns:** [`GLS_SHIPMENT_UNIT`](types.md#GLS_SHIPMENT_UNIT) +**Returns:** [`GLS_SHIPMENT_UNIT`](types.mdx#GLS_SHIPMENT_UNIT-array) --- @@ -140,7 +140,7 @@ createPrintingOptions(returnLabels: RETURN_LABELS): GLS_PRINTING_OPTIONS | `TemplateSet` | `NONE`, `D_200`, `PF_4_I`, `ZPL_200`, `ZPL_300`, ... | Label template set | | `LabelFormat` | `PDF`, `ZEBRA`, `INTERMEC`, `DATAMAX`, `TOSHIBA`, `PNG` | Output format | -**Returns:** [`GLS_PRINTING_OPTIONS`](types.md#GLS_PRINTING_OPTIONS) +**Returns:** [`GLS_PRINTING_OPTIONS`](types.mdx#GLS_PRINTING_OPTIONS) --- @@ -169,7 +169,7 @@ createCustomContent( | `barcodeType` | `"EAN_128"` \| `"CODE_39"` | No | Barcode symbology | | `barcode` | string | No | Custom barcode value | -**Returns:** [`GLS_CUSTOM_CONTENT`](types.md#GLS_CUSTOM_CONTENT) +**Returns:** [`GLS_CUSTOM_CONTENT`](types.mdx#GLS_CUSTOM_CONTENT) --- @@ -536,7 +536,7 @@ validateShipment └── validationResult.Issues[] ``` -See [Types — GLS_VALIDATE_SHIPMENT_REQUEST_DATA](types.md#GLS_VALIDATE_SHIPMENT_REQUEST_DATA) for the input format. +See [Types — GLS_VALIDATE_SHIPMENT_REQUEST_DATA](types.mdx#GLS_VALIDATE_SHIPMENT_REQUEST_DATA) for the input format. --- diff --git a/docs/Actions/GLS/overview.md b/docs/Actions/GLS/overview.md index 3913cc9..61f2350 100644 --- a/docs/Actions/GLS/overview.md +++ b/docs/Actions/GLS/overview.md @@ -91,7 +91,7 @@ GLS_CREATE_PARCELS_RESPONSE ← tracking IDs, barcode data, print data, routing - [Quick Start](quick-start.md) — Create your first shipment in a few steps - [Configuration](configs.md) — Full list of configuration options and how to get credentials - [Functions](functions.md) — All available functions with parameter details -- [Types](types.md) — All data types used in the GLS Action +- [Types](types.mdx) — All data types used in the GLS Action - [Events](events.md) — Events emitted by the GLS Action - [Common Use Cases](use-cases.md) — Example flows for real-world scenarios - [Troubleshooting](troubleshooting.md) — FAQ and community support diff --git a/docs/index.mdx b/docs/index.mdx index 272254b..31e854a 100644 --- a/docs/index.mdx +++ b/docs/index.mdx @@ -37,7 +37,7 @@ Before using any action from Centaurus, make sure you have: - [GLS Action Overview](Actions/GLS/overview.md) — Get started with the GLS shipping integration - [GLS Configuration](Actions/GLS/configs.md) — API keys and configuration options - [GLS Functions](Actions/GLS/functions.md) — All available functions and their parameters -- [GLS Types](Actions/GLS/types.md) — Data types used across the GLS action +- [GLS Types](Actions/GLS/types.mdx) — Data types used across the GLS action - [GLS Events](Actions/GLS/events.md) — Events emitted by the GLS action - [Common Use Cases](Actions/GLS/use-cases.md) — Example workflows using the GLS action - [Troubleshooting](Actions/GLS/troubleshooting.md) — FAQ and community support \ No newline at end of file From 51a4902a531ff30ca20212c7824a6945d2656885 Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Mon, 30 Mar 2026 22:48:42 +0200 Subject: [PATCH 4/4] New method of generative types??? --- actions/gls-action/package.json | 3 + actions/gls-action/scripts/generateTypes.ts | 162 +- actions/gls-action/src/types/glsAddress.ts | 44 +- .../gls-action/src/types/glsUnitService.ts | 2 +- docs/Actions/GLS/functions.md | 2 +- docs/Actions/GLS/types.mdx | 1965 ++++++++++++----- package-lock.json | 41 +- tsconfig.base.json | 2 +- 8 files changed, 1580 insertions(+), 641 deletions(-) diff --git a/actions/gls-action/package.json b/actions/gls-action/package.json index 106637b..5768b95 100644 --- a/actions/gls-action/package.json +++ b/actions/gls-action/package.json @@ -11,5 +11,8 @@ "test": "vitest run", "start": "node dist/main.js", "docs:generate": "npm run build && node dist/generateTypes.js > ../../docs/Actions/GLS/types.mdx" + }, + "dependencies": { + "ts-morph": "^27.0.2" } } diff --git a/actions/gls-action/scripts/generateTypes.ts b/actions/gls-action/scripts/generateTypes.ts index d1c6422..b307b8e 100644 --- a/actions/gls-action/scripts/generateTypes.ts +++ b/actions/gls-action/scripts/generateTypes.ts @@ -3,6 +3,7 @@ import { HerculesActionConfigurationDefinition, HerculesDataType, HerculesFlowType, HerculesRegisterFunctionParameter, } from "@code0-tech/hercules"; +import {Project, SymbolFlags, Type} from "ts-morph"; const state = { @@ -60,10 +61,11 @@ async function run() { } run().then(async () => { - let typeContent = `--- + console.log(`--- title: Datatypes description: All data types registered by the GLS Action — field references and descriptions. --- +import {TypeTable} from "fumadocs-ui/components/type-table"; # GLS Action Types @@ -71,66 +73,150 @@ The GLS Action registers the following data types with the Hercules platform. Th of the GLS functions and can be referenced in your flows. --- - ` - + `) state.dataTypes.forEach(value => { value.type = `export type ${value.identifier} = ${value.type}` .replace(/ \| undefined/g, "") - .replace(/\/\*\*/g, "/**\n") - .replace(/\*\//g, "\n**/") - .replace( - /(\w+)(\?)?:\s*(GLS_\w+);/g, - (match, name, optionalMark, gls) => { - if (optionalMark) { - return `/** - Optional. - @fumadocsHref #type-table-temp.ts-${gls} -**/ -${name}: ${gls}`; + + + function breakDown( + typeName: string, + code: string + ): Record { + const map: Record = {}; + + const project = new Project({useInMemoryFileSystem: true}); + const sourceFile = project.createSourceFile("example.ts", code); + + const typeAlias = sourceFile.getTypeAliasOrThrow(typeName); + let rootType = typeAlias.getType(); + + if (rootType.isArray()) { + rootType = rootType.getArrayElementTypeOrThrow(); + } + + function buildType(type: Type, currentName: string): string { + const props = type.getProperties(); + + const lines: string[] = []; + + props.forEach(symbol => { + const name = symbol.getName(); + const decl = symbol.getDeclarations()[0]; + if (!decl) return; + + + let propType = symbol.getTypeAtLocation(decl); + + // unwrap arrays + let isArray = false; + if (propType.isArray()) { + propType = propType.getArrayElementTypeOrThrow(); + isArray = true; } - return `/** - @fumadocsHref #type-table-temp.ts-${gls} -**/ -${name}: ${gls}`; - } - ); + let typeText: string; - let array = false - if (value.type.endsWith("[];")) { - value.type = value.type.slice(0, -3) + ";" - array = true - } + if (propType.getText().startsWith("{")) { + const newName = `${currentName}$${name}`; - typeContent += ` -# ${value.identifier}${array ? " (array)" : ""} - - + // recurse first + const nestedType = buildType(propType, newName); -` - }) - typeContent = typeContent.replace(" | undefined", "") + map[newName] = `export type ${newName} = ${nestedType};`; + + typeText = isArray ? `${newName}[]` : newName; + } else { + typeText = propType.getText(decl); + } + + // JSDoc + const jsDocs = (decl as any).getJsDocs?.() + ?.map(d => d.getText()) + .join("\n"); + + const docPrefix = jsDocs ? `${jsDocs}\n` : ""; - console.log(typeContent) -}) + lines.push( + `${docPrefix}${name}${symbol.hasFlags(SymbolFlags.Optional) ? "?" : ""}: ${typeText};` + ); + }); + return `{\n${lines.map(l => " " + l).join("\n")}\n}`; + } + const finalType = buildType(rootType, typeName); + map[typeName] = `export type ${typeName} = ${finalType};`; + + return map; + } + const broke = breakDown(value.identifier, value.type) + const entries = Object.entries(broke).reverse(); + for (const [key, val] of entries) { + let typeString = ` + ` + const project = new Project({useInMemoryFileSystem: true}); + const sourceFile = project.createSourceFile("example.ts", val); + const typeAlias = sourceFile.getTypeAliasOrThrow(key); + let type = typeAlias.getType() + const array = typeAlias.getType().isArray() + if (array) { + type = type.getArrayElementTypeOrThrow() + } + type.getProperties().forEach(property => { + const name = property.getName(); + const currType = property.getTypeAtLocation(typeAlias); + const currTypeText = currType.getText(); + const docs = { + description: "No description set", + deprecated: false, + default: undefined, + link: undefined + } + property.getJsDocTags().forEach(info => { + info.getText().forEach(part => { + docs[info.getName()] = part.text.trim() + }) + }) + if (currTypeText.startsWith("GLS_")) { + docs.link = currTypeText.toLowerCase() + .replace(/-/g, "_") + .replace(/\$/g, "") + .replace("[]", "") + } + typeString += `${name}: { + description: '${docs.description}', + deprecated: ${docs.deprecated}, + required: ${!property.isOptional()}, ${docs.link ? `\ntypeDescriptionLink: '#${docs.link}',` : ""} + type: '${currTypeText}', ${docs.default ? `\ndefault: ${docs.default}` : ""} + }, + ` + + }) + + const table = `` + console.log(`# ${key}`) + console.log(table) + } + // console.log(` +// # ${value.identifier} ${array ? "[]" : ""} +// `) +// console.log(table) + }) +}) \ No newline at end of file diff --git a/actions/gls-action/src/types/glsAddress.ts b/actions/gls-action/src/types/glsAddress.ts index 4d76bc6..05f5a86 100644 --- a/actions/gls-action/src/types/glsAddress.ts +++ b/actions/gls-action/src/types/glsAddress.ts @@ -4,60 +4,42 @@ import {singleZodSchemaToTypescriptDef} from "../helpers"; export const AddressSchema = z.object({ Name1: z.string().max(40).describe(` - Primary name line (person or company). - Max 40 characters. + @description Primary name line (person or company). Max 40 characters. `), Name2: z.string().max(40).optional().describe(` - Optional second name line (e.g., department or additional identifier). - Max 40 characters. + @description Optional second name line (e.g., department or additional identifier). Max 40 characters. `), Name3: z.string().max(40).optional().describe(` - Optional third name line for extended address details. - Max 40 characters. + @description Optional third name line for extended address details. Max 40 characters. `), CountryCode: z.string().max(2).describe(` - Two-letter ISO country code (e.g., DE, US). + @description Two-letter ISO country code (e.g., DE, US). `), Province: z.string().max(40).optional().describe(` - State, province, or region. - Optional field. - Max 40 characters. + @description State, province, or region. Optional field. Max 40 characters. `), City: z.string().max(40).describe(` - City or locality name. - Max 40 characters. + @description City or locality name. Max 40 characters. `), Street: z.string().min(4).describe(` - Street name. - Minimum 4 characters required. + @description Street name. Minimum 4 characters required. `), StreetNumber: z.string().max(40).optional().describe(` - House or building number. - Optional field. - Max 40 characters. + @description House or building number. Optional field. Max 40 characters. `), ContactPerson: z.string().max(40).min(6).optional().describe(` - Full name of a contact person. - Optional field. - Must be between 6 and 40 characters. + @description Full name of a contact person. Optional field. Must be between 6 and 40 characters. `), FixedLinePhonenumber: z.string().max(35).min(4).optional().describe(` - Landline phone number. - Optional field. - Must be between 4 and 35 characters. + @description Landline phone number. Optional field. Must be between 4 and 35 characters. `), MobilePhonenumber: z.string().max(35).min(4).optional().describe(` - Mobile phone number. - Optional field. - Must be between 4 and 35 characters. + @description Mobile phone number. Optional field. Must be between 4 and 35 characters. `), eMail: z.string().max(80).optional().describe(` - Email address. - Optional field. - Max 80 characters. + @description Email address. Optional field. Max 80 characters. `), ZIPCode: z.string().max(10).describe(` - Postal or ZIP code. - Max 10 characters. + @description Postal or ZIP code. Max 10 characters. `), }) export type AddressSchema = z.infer diff --git a/actions/gls-action/src/types/glsUnitService.ts b/actions/gls-action/src/types/glsUnitService.ts index 8976cde..050fe26 100644 --- a/actions/gls-action/src/types/glsUnitService.ts +++ b/actions/gls-action/src/types/glsUnitService.ts @@ -5,7 +5,7 @@ import {ActionSdk} from "@code0-tech/hercules"; export const UnitServiceSchema = z.array(z.object({ Cash: z.object({ - Reason: z.string().max(160), + Reason: z.string().max(160).describe("@description Test"), Amount: z.number().min(1), Currency: z.string().max(3).min(3) }).optional(), diff --git a/docs/Actions/GLS/functions.md b/docs/Actions/GLS/functions.md index c5ffdde..fdb68ee 100644 --- a/docs/Actions/GLS/functions.md +++ b/docs/Actions/GLS/functions.md @@ -114,7 +114,7 @@ createShipmentUnit( | `note2` | string (max 50) | No | Additional note printed on the label (line 2) | | `shipmentUnitService` | GLS_UNIT_SERVICE | No | Unit-level services (Cash, AddonLiability, HazardousGoods, etc.) | -**Returns:** [`GLS_SHIPMENT_UNIT`](types.mdx#GLS_SHIPMENT_UNIT-array) +**Returns:** [`GLS_SHIPMENT_UNIT`](types.mdx#gls_shipment_unit) --- diff --git a/docs/Actions/GLS/types.mdx b/docs/Actions/GLS/types.mdx index 7110669..04ac827 100644 --- a/docs/Actions/GLS/types.mdx +++ b/docs/Actions/GLS/types.mdx @@ -2,6 +2,7 @@ title: Datatypes description: All data types registered by the GLS Action — field references and descriptions. --- +import {TypeTable} from "fumadocs-ui/components/type-table"; # GLS Action Types @@ -11,593 +12,1427 @@ of the GLS functions and can be referenced in your flows. --- # GLS_VALIDATE_SHIPMENT_REQUEST_DATA - - - - + # GLS_VALIDATE_SHIPMENT_RESPONSE_DATA - - - - + +# GLS_VALIDATE_SHIPMENT_RESPONSE_DATA$validationResult + +# GLS_VALIDATE_SHIPMENT_RESPONSE_DATA$validationResult$Issues + # GLS_UPDATE_PARCEL_WEIGHT_REQUEST_DATA - - - - + # GLS_UPDATE_PARCEL_WEIGHT_RESPONSE_DATA - - - - -# GLS_UNIT_SERVICE (array) - - - - + +# GLS_UNIT_SERVICE + +# GLS_UNIT_SERVICE$LimitedQuantities + +# GLS_UNIT_SERVICE$ExWorks + +# GLS_UNIT_SERVICE$HazardousGoods + +# GLS_UNIT_SERVICE$HazardousGoods$HarzardousGood + +# GLS_UNIT_SERVICE$AddonLiability + +# GLS_UNIT_SERVICE$Cash + # GLS_SHIPPER - - - - -# GLS_SHIPMENT_UNIT (array) - - +# GLS_SHIPMENT_UNIT + +# GLS_SHIPMENT_UNIT$Service + +# GLS_SHIPMENT_UNIT$Service$LimitedQuantities + +# GLS_SHIPMENT_UNIT$Service$ExWorks + +# GLS_SHIPMENT_UNIT$Service$HazardousGoods + - - + description: 'No description set', + deprecated: false, + required: true, +typeDescriptionLink: '#gls_shipment_unitservicehazardousgoodsharzardousgood', + type: 'GLS_SHIPMENT_UNIT$Service$HazardousGoods$HarzardousGood[]', + }, + }} +/> +# GLS_SHIPMENT_UNIT$Service$HazardousGoods$HarzardousGood + +# GLS_SHIPMENT_UNIT$Service$AddonLiability + +# GLS_SHIPMENT_UNIT$Service$Cash + # GLS_SHIPMENT - - - - + +# GLS_SHIPMENT$Return + # GLS_SHIPMENT_WITHOUT_SERVICES - - - - + +# GLS_SHIPMENT_WITHOUT_SERVICES$Return + # GLS_RETURN_OPTIONS - - - - + # GLS_REPRINT_PARCEL_REQUEST_DATA - - - - + +# GLS_REPRINT_PARCEL_REQUEST_DATA$PrintingOptions + +# GLS_REPRINT_PARCEL_REQUEST_DATA$PrintingOptions$ReturnLabels + # GLS_REPRINT_PARCEL_RESPONSE_DATA - - +# GLS_REPRINT_PARCEL_RESPONSE_DATA$CreatedShipment + +# GLS_REPRINT_PARCEL_RESPONSE_DATA$CreatedShipment$PrintData + +# GLS_REPRINT_PARCEL_RESPONSE_DATA$CreatedShipment$ParcelData + - - + description: 'No description set', + deprecated: false, + required: true, +typeDescriptionLink: '#gls_reprint_parcel_response_datacreatedshipmentparceldataroutinginfo', + type: 'GLS_REPRINT_PARCEL_RESPONSE_DATA$CreatedShipment$ParcelData$RoutingInfo', + }, + }} +/> +# GLS_REPRINT_PARCEL_RESPONSE_DATA$CreatedShipment$ParcelData$RoutingInfo + +# GLS_REPRINT_PARCEL_RESPONSE_DATA$CreatedShipment$ParcelData$Barcodes + # GLS_PRINTING_OPTIONS - - - - + +# GLS_PRINTING_OPTIONS$DefinePrinter + +# GLS_PRINTING_OPTIONS$ReturnLabels + # GLS_END_OF_DAY_REQUEST_DATA - - - - + # GLS_END_OF_DAY_RESPONSE_DATA - - - - + +# GLS_END_OF_DAY_RESPONSE_DATA$Shipments + +# GLS_END_OF_DAY_RESPONSE_DATA$Shipments$ShipmentUnit + +# GLS_END_OF_DAY_RESPONSE_DATA$Shipments$Shipper + +# GLS_END_OF_DAY_RESPONSE_DATA$Shipments$Consignee + # GLS_CUSTOM_CONTENT - - - - + # GLS_CREATE_PARCELS_RESPONSE - - +# GLS_CREATE_PARCELS_RESPONSE$CreatedShipment + +# GLS_CREATE_PARCELS_RESPONSE$CreatedShipment$PrintData + +# GLS_CREATE_PARCELS_RESPONSE$CreatedShipment$ParcelData + - - + description: 'No description set', + deprecated: false, + required: true, +typeDescriptionLink: '#gls_create_parcels_responsecreatedshipmentparceldataroutinginfo', + type: 'GLS_CREATE_PARCELS_RESPONSE$CreatedShipment$ParcelData$RoutingInfo', + }, + }} +/> +# GLS_CREATE_PARCELS_RESPONSE$CreatedShipment$ParcelData$RoutingInfo + +# GLS_CREATE_PARCELS_RESPONSE$CreatedShipment$ParcelData$Barcodes + # GLS_CONSIGNEE - - - - + # GLS_CANCEL_SHIPMENT_REQUEST_DATA - - - - + # GLS_CANCEL_SHIPMENT_RESPONSE_DATA - - - - + # GLS_ALLOWED_SERVICES_REQUEST_DATA - - - - + +# GLS_ALLOWED_SERVICES_REQUEST_DATA$Destination + +# GLS_ALLOWED_SERVICES_REQUEST_DATA$Source + # GLS_ALLOWED_SERVICES_RESPONSE_DATA - - - - + +# GLS_ALLOWED_SERVICES_RESPONSE_DATA$AllowedServices + # GLS_ADDRESS - - - - + diff --git a/package-lock.json b/package-lock.json index b5fc11f..765c3b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,10 @@ }, "actions/gls-action": { "name": "@code0-tech/gls-action", - "version": "0.0.0" + "version": "0.0.0", + "dependencies": { + "ts-morph": "^27.0.2" + } }, "actions/notion-action": { "name": "@code0-tech/notion-action", @@ -1141,6 +1144,17 @@ "dev": true, "license": "MIT" }, + "node_modules/@ts-morph/common": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.28.1.tgz", + "integrity": "sha512-W74iWf7ILp1ZKNYXY5qbddNaml7e9Sedv5lvU1V8lftlitkc9Pq1A+jlH23ltDgWYeZFFEqGCD1Ies9hqu3O+g==", + "license": "MIT", + "dependencies": { + "minimatch": "^10.0.1", + "path-browserify": "^1.0.1", + "tinyglobby": "^0.2.14" + } + }, "node_modules/@turbo/darwin-64": { "version": "2.8.21", "resolved": "https://registry.npmjs.org/@turbo/darwin-64/-/darwin-64-2.8.21.tgz", @@ -1708,7 +1722,6 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", - "dev": true, "license": "MIT", "engines": { "node": "18 || 20 || >=22" @@ -1718,7 +1731,6 @@ "version": "5.0.5", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.5.tgz", "integrity": "sha512-VZznLgtwhn+Mact9tfiwx64fA9erHH/MCXEUfB/0bX/6Fz6ny5EGTXYltMocqg4xFAQZtnO3DHWWXi8RiuN7cQ==", - "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^4.0.2" @@ -1764,6 +1776,12 @@ "node": ">=12" } }, + "node_modules/code-block-writer": { + "version": "13.0.3", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-13.0.3.tgz", + "integrity": "sha512-Oofo0pq3IKnsFtuHqSF7TqBfr71aeyZDVJ0HpmqB7FBM2qEigL0iPONSCZSO9pE9dZTAxANe5XHG9Uy0YMv8cg==", + "license": "MIT" + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -2597,7 +2615,6 @@ "version": "10.2.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.4.tgz", "integrity": "sha512-oRjTw/97aTBN0RHbYCdtF1MQfvusSIBQM0IZEgzl6426+8jSC0nF1a/GmnVLpfB9yyr6g6FTqWqiZVbxrtaCIg==", - "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "brace-expansion": "^5.0.2" @@ -2702,6 +2719,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "license": "MIT" + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -3026,6 +3049,16 @@ "typescript": ">=4.8.4" } }, + "node_modules/ts-morph": { + "version": "27.0.2", + "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-27.0.2.tgz", + "integrity": "sha512-fhUhgeljcrdZ+9DZND1De1029PrE+cMkIP7ooqkLRTrRLTqcki2AstsyJm0vRNbTbVCNJ0idGlbBrfqc7/nA8w==", + "license": "MIT", + "dependencies": { + "@ts-morph/common": "~0.28.1", + "code-block-writer": "^13.0.3" + } + }, "node_modules/turbo": { "version": "2.8.21", "resolved": "https://registry.npmjs.org/turbo/-/turbo-2.8.21.tgz", diff --git a/tsconfig.base.json b/tsconfig.base.json index 8a0c8f5..3363612 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -7,7 +7,7 @@ "lib": ["es2022", "es2021", "dom"], "strict": false, "skipLibCheck": true, - "types": ["vite/client"] + "types": ["vite/client"], }, "include": ["src/**/*"], "exclude": ["node_modules", "dist", "***/test/**", "**/*.test.ts"]