Skip to content

Commit 1a9b828

Browse files
committed
First progress in generating docs
1 parent fecb5de commit 1a9b828

12 files changed

Lines changed: 816 additions & 499 deletions

File tree

actions/gls-action/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build": "vite build",
1010
"lint": "eslint .",
1111
"test": "vitest run",
12-
"start": "node dist/main.js"
12+
"start": "node dist/main.js",
13+
"docs:generate": "npm run build && node dist/generateTypes.js > ../../docs/Actions/GLS/types.mdx"
1314
}
1415
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import {loadAllDefinitions} from "../src/helpers";
2+
import {
3+
HerculesActionConfigurationDefinition,
4+
HerculesDataType, HerculesFlowType, HerculesRegisterFunctionParameter,
5+
} from "@code0-tech/hercules";
6+
7+
8+
const state = {
9+
dataTypes: [] as HerculesDataType[],
10+
actionConfigurationDefinitions: [] as HerculesActionConfigurationDefinition[],
11+
runtimeFunctions: [] as HerculesRegisterFunctionParameter[],
12+
flowTypes: [] as HerculesFlowType[]
13+
}
14+
15+
16+
async function run() {
17+
await loadAllDefinitions({
18+
onError: handler => {
19+
},
20+
connect: options => Promise.resolve([]),
21+
dispatchEvent: (event, payload) => Promise.resolve(),
22+
getProjectActionConfigurations: () => [],
23+
config: {
24+
authToken: "",
25+
aquilaUrl: "",
26+
version: "",
27+
actionId: ""
28+
},
29+
fullyConnected: () => false,
30+
registerDataTypes: (...dataTypes) => {
31+
state.dataTypes = [
32+
...dataTypes,
33+
...state.dataTypes
34+
]
35+
return Promise.resolve()
36+
},
37+
registerConfigDefinitions: (...actionConfigurations) => {
38+
state.actionConfigurationDefinitions = [
39+
...actionConfigurations,
40+
...state.actionConfigurationDefinitions
41+
]
42+
return Promise.resolve()
43+
},
44+
registerFunctionDefinitions: (...functionDefinitions) => {
45+
state.runtimeFunctions = [
46+
...functionDefinitions,
47+
...state.runtimeFunctions
48+
]
49+
return Promise.resolve()
50+
},
51+
registerFlowTypes: (...flowTypes) => {
52+
return Promise.resolve()
53+
}
54+
55+
})
56+
}
57+
58+
run().then(async () => {
59+
let typeContent = `---
60+
title: Datatypes
61+
description: All data types registered by the GLS Action — field references and descriptions.
62+
---
63+
64+
# GLS Action Types
65+
66+
The GLS Action registers the following data types with the Hercules platform. These types are used as inputs and outputs
67+
of the GLS functions and can be referenced in your flows.
68+
69+
---
70+
`
71+
72+
state.dataTypes.forEach(value => {
73+
value.type = `export type ${value.identifier} = ${value.type}`
74+
.replace(/ \| undefined/g, "")
75+
.replace(/\/\*\*/g, "/**\n")
76+
.replace(/\*\//g, "\n**/")
77+
.replace(
78+
/(\w+)(\?)?:\s*(GLS_\w+);/g,
79+
(match, name, optionalMark, gls) => {
80+
if (optionalMark) {
81+
return `/**
82+
Optional.
83+
@fumadocsHref #type-table-temp.ts-${gls}
84+
**/
85+
${name}: ${gls}`;
86+
}
87+
88+
return `/**
89+
@fumadocsHref #type-table-temp.ts-${gls}
90+
**/
91+
${name}: ${gls}`;
92+
}
93+
);
94+
95+
let array = false
96+
if (value.type.endsWith("[];")) {
97+
value.type = value.type.slice(0, -3) + ";"
98+
array = true
99+
}
100+
101+
typeContent += `
102+
# ${value.identifier}${array ? " (array)" : ""}
103+
104+
<AutoTypeTable type={\`
105+
106+
${value.type}
107+
108+
\`} name="${value.identifier}"/>
109+
110+
`
111+
})
112+
typeContent = typeContent.replace(" | undefined", "")
113+
114+
console.log(typeContent)
115+
})
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+
130+
131+
132+

actions/gls-action/src/types/glsAddress.ts

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,62 @@ import z from "zod"
33
import {singleZodSchemaToTypescriptDef} from "../helpers";
44

55
export const AddressSchema = z.object({
6-
Name1: z.string().max(40),
7-
Name2: z.string().max(40).optional(),
8-
Name3: z.string().max(40).optional(),
9-
CountryCode: z.string().max(2),
10-
Province: z.string().max(40).optional(),
11-
City: z.string().max(40),
12-
Street: z.string().min(4),
13-
StreetNumber: z.string().max(40).optional(),
14-
ContactPerson: z.string().max(40).min(6).optional(),
15-
FixedLinePhonenumber: z.string().max(35).min(4).optional(),
16-
MobilePhonenumber: z.string().max(35).min(4).optional(),
17-
eMail: z.string().max(80).optional(),
18-
ZIPCode: z.string().max(10),
6+
Name1: z.string().max(40).describe(`
7+
Primary name line (person or company).
8+
Max 40 characters.
9+
`),
10+
Name2: z.string().max(40).optional().describe(`
11+
Optional second name line (e.g., department or additional identifier).
12+
Max 40 characters.
13+
`), Name3: z.string().max(40).optional().describe(`
14+
Optional third name line for extended address details.
15+
Max 40 characters.
16+
`),
17+
CountryCode: z.string().max(2).describe(`
18+
Two-letter ISO country code (e.g., DE, US).
19+
`),
20+
Province: z.string().max(40).optional().describe(`
21+
State, province, or region.
22+
Optional field.
23+
Max 40 characters.
24+
`),
25+
City: z.string().max(40).describe(`
26+
City or locality name.
27+
Max 40 characters.
28+
`),
29+
Street: z.string().min(4).describe(`
30+
Street name.
31+
Minimum 4 characters required.
32+
`),
33+
StreetNumber: z.string().max(40).optional().describe(`
34+
House or building number.
35+
Optional field.
36+
Max 40 characters.
37+
`),
38+
ContactPerson: z.string().max(40).min(6).optional().describe(`
39+
Full name of a contact person.
40+
Optional field.
41+
Must be between 6 and 40 characters.
42+
`),
43+
FixedLinePhonenumber: z.string().max(35).min(4).optional().describe(`
44+
Landline phone number.
45+
Optional field.
46+
Must be between 4 and 35 characters.
47+
`),
48+
MobilePhonenumber: z.string().max(35).min(4).optional().describe(`
49+
Mobile phone number.
50+
Optional field.
51+
Must be between 4 and 35 characters.
52+
`),
53+
eMail: z.string().max(80).optional().describe(`
54+
Email address.
55+
Optional field.
56+
Max 80 characters.
57+
`),
58+
ZIPCode: z.string().max(10).describe(`
59+
Postal or ZIP code.
60+
Max 10 characters.
61+
`),
1962
})
2063
export type AddressSchema = z.infer<typeof AddressSchema>
2164

actions/gls-action/src/types/glsEndOfDayRequest.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {ActionSdk} from "@code0-tech/hercules";
2-
import {singleZodSchemaToTypescriptDef} from "../helpers";
2+
import {singleZodSchemaToTypescriptDef, zodSchemaToTypescriptDefs} from "../helpers";
33
import z from "zod";
44
import {AddressSchema} from "./glsAddress";
55

@@ -50,10 +50,13 @@ export default (sdk: ActionSdk) => {
5050
},
5151
{
5252
identifier: "GLS_END_OF_DAY_RESPONSE_DATA",
53-
type: singleZodSchemaToTypescriptDef(
53+
type: zodSchemaToTypescriptDefs(
5454
"GLS_END_OF_DAY_RESPONSE_DATA",
55-
EndOfDayResponseDataSchema
56-
),
55+
EndOfDayResponseDataSchema,
56+
{
57+
GLS_ADDRESS: AddressSchema
58+
}
59+
).get("GLS_END_OF_DAY_RESPONSE_DATA")!,
5760
name: [
5861
{
5962
code: "en-US",

actions/gls-action/src/types/glsShipment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const ShipmentSchema = z.object({
1717
Consignee: ConsigneeSchema,
1818
Shipper: ShipperSchema.optional(),
1919
Carrier: z.enum(["ROYALMAIL"]).optional(),
20-
ShipmentUnit: ShipmentUnitSchema,
20+
ShipmentUnit: z.lazy(() => ShipmentUnitSchema),
2121
Service: z.lazy(() => ShipmentServiceSchema),
2222
Return: z.object({
2323
Address: AddressSchema
@@ -30,7 +30,7 @@ export const InternalShipmentSchma = ShipmentSchema.extend({
3030
Middleware: z.string().max(40),
3131
Shipper: InternalShipperSchema,
3232
Service: z.lazy(() => InternalShipmentServiceSchema),
33-
ShipmentUnit: InternalShipmentUnitSchema
33+
ShipmentUnit: z.lazy(() => InternalShipmentUnitSchema)
3434
})
3535

3636
export default (sdk: ActionSdk) => {

actions/gls-action/src/types/glsShipmentService.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import z from "zod";
22
import {AddressSchema} from "./glsAddress";
3-
import {zodSchemaToTypescriptDefs} from "../helpers";
4-
import {ShipmentSchema} from "./glsShipment";
5-
import {ActionSdk} from "@code0-tech/hercules";
63

74

85
export const ShipmentServiceSchema = z.array(z.object({
@@ -185,33 +182,3 @@ export const InternalShipmentServiceSchema = z.array(z.object({
185182
serviceName: z.string().default("service_Saturday"),
186183
}).optional(),
187184
})).optional()
188-
189-
export default (sdk: ActionSdk) => {
190-
return sdk.registerDataTypes(
191-
{
192-
identifier: "GLS_SHIPMENT_SERVICE",
193-
type: zodSchemaToTypescriptDefs(
194-
"XXX",
195-
ShipmentSchema,
196-
{
197-
GLS_SHIPMENT_SERVICE: ShipmentServiceSchema,
198-
}
199-
).get("GLS_SHIPMENT_SERVICE")!, // Hacky way because shipment service is defined as an array
200-
name: [
201-
{
202-
code: "en-US",
203-
content: "Shipment Service"
204-
}
205-
],
206-
displayMessage: [
207-
{
208-
code: "en-US",
209-
content: "Shipment Service"
210-
}
211-
],
212-
linkedDataTypes: [
213-
"GLS_ADDRESS"
214-
]
215-
},
216-
)
217-
}

actions/gls-action/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig({
1010
rollupOptions: {
1111
input: {
1212
main: resolve(__dirname, 'src/index.ts'),
13+
generateTypes: resolve(__dirname, 'scripts/generateTypes.ts')
1314
},
1415
external: [
1516
'fs',

0 commit comments

Comments
 (0)