Skip to content

Commit 15367bf

Browse files
committed
Add initial configuration files and update README with environment variables
1 parent c7fd889 commit 15367bf

11 files changed

Lines changed: 170 additions & 20 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# centaurus
22
The "central" place for all actions
3+
4+
# ENV
5+
| ENV Variable | Description | Default Value |
6+
|------------------------|------------------------------------------------|---------------------|
7+
| `HERCULES_AUTH_TOKEN` | Authentication token for connecting to Aquila. | `""` (empty string) |
8+
| `HERCULES_AQUILA_URL` | URL of the Aquila server to connect to. | `"localhost:50051"` |
9+
| `HERCULES_ACTION_ID` | Identifier for the action being registered. | `"<action-name>"` |
10+
| `HERCULES_SDK_VERSION` | Version of the Hercules SDK being used. | `"0.0.0"` |

actions/gls-action/.example.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
HERCULES_AUTH_TOKEN=your_hercules_auth_token_here
2+
HERCULES_AQUILA_URL=https://aquila.hercules-ci.com
3+
HERCULES_ACTION_ID=gls-action
4+
HERCULES_SDK_VERSION=0.0.0

actions/gls-action/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
# ENV
2-
| ENV Variable | Description | Default Value |
3-
|------------------------|------------------------------------------------|---------------------|
4-
| `HERCULES_AUTH_TOKEN` | Authentication token for connecting to Aquila. | `""` (empty string) |
5-
| `HERCULES_AQUILA_URL` | URL of the Aquila server to connect to. | `"localhost:50051"` |
6-
| `HERCULES_ACTION_ID` | Identifier for the action being registered. | `"gls-action"` |
7-
| `HERCULES_SDK_VERSION` | Version of the Hercules SDK being used. | `"0.0.0"` |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3.9"
2+
3+
services:
4+
gls-action:
5+
image: node:20
6+
working_dir: /app
7+
volumes:
8+
- .:/app
9+
command: sh -c "npm install && npx tsx src/index.ts"
10+
env_file:
11+
- .env

actions/gls-action/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/gls-action/src/helpers.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ export const getAuthToken = async (context: HerculesFunctionContext) => {
6565
client_secret: context.matchedConfig.findConfig("client_secret") as string,
6666
grant_type: "client_credentials"
6767
}
68+
const url = context.matchedConfig.findConfig("auth_url") as string
69+
6870
if (cachedToken.expiresAt > Date.now()) {
6971
console.log("Using cached access token")
7072
return cachedToken.token
7173
}
7274

7375

74-
const authValue = await axios.post("https://api-sandbox.gls-group.net/oauth2/v2/token", AuthenticationRequestDataSchema.parse(data), {
76+
const authValue = await axios.post(url, AuthenticationRequestDataSchema.parse(data), {
7577
headers: {
7678
"Content-Type": "application/x-www-form-urlencoded"
7779
}
@@ -87,7 +89,7 @@ export const getAuthToken = async (context: HerculesFunctionContext) => {
8789
}
8890

8991
export const validateShipment = async (data: ValidateShipmentRequestData, context: HerculesFunctionContext): Promise<ValidateShipmentResponseData> => {
90-
const url = context?.matchedConfig.findConfig("api_url") as string;
92+
const url = context?.matchedConfig.findConfig("ship_it_api_url") as string;
9193
const contactID = context?.matchedConfig.findConfig("contact_id") as string || ""
9294

9395
try {
@@ -104,7 +106,7 @@ export const validateShipment = async (data: ValidateShipmentRequestData, contex
104106

105107
}
106108
export const reprintParcel = async (data: ReprintParcelRequestData, context: HerculesFunctionContext): Promise<ReprintParcelResponseData> => {
107-
const url = context.matchedConfig.findConfig("api_url") as string;
109+
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
108110

109111
try {
110112
const result = await axios.post(`${url}/rs/shipments/reprintparcel`, data, {
@@ -121,7 +123,7 @@ export const reprintParcel = async (data: ReprintParcelRequestData, context: Her
121123
}
122124

123125
export const updateParcelWeight = async (data: UpdateParcelWeightRequestData, context: HerculesFunctionContext): Promise<UpdateParcelWeightResponseData> => {
124-
const url = context.matchedConfig.findConfig("api_url") as string;
126+
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
125127

126128
try {
127129
const result = await axios.post(`${url}/rs/shipments/updateparcelweight`, data, {
@@ -139,7 +141,7 @@ export const updateParcelWeight = async (data: UpdateParcelWeightRequestData, co
139141
}
140142

141143
export const getEndOfDayInfo = async (data: EndOfDayRequestData, context: HerculesFunctionContext): Promise<EndOfDayResponseData> => {
142-
const url = context.matchedConfig.findConfig("api_url") as string;
144+
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
143145

144146
try {
145147
const result = await axios.post(`${url}/rs/shipments/endofday?date=${data.date}`, {}, {
@@ -156,7 +158,7 @@ export const getEndOfDayInfo = async (data: EndOfDayRequestData, context: Hercul
156158
}
157159

158160
export const getAllowedServices = async (data: AllowedServicesRequestData, context: HerculesFunctionContext): Promise<AllowedServicesResponseData> => {
159-
const url = context.matchedConfig.findConfig("api_url") as string;
161+
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
160162

161163
try {
162164
const result = await axios.post(`${url}/rs/shipments/allowedservices`, data, {
@@ -184,7 +186,7 @@ export const getAllowedServices = async (data: AllowedServicesRequestData, conte
184186
}
185187

186188
export const cancelShipment = async (data: CancelShipmentRequestData, context: HerculesFunctionContext): Promise<CancelShipmentResponseData> => {
187-
const url = context.matchedConfig.findConfig("api_url") as string;
189+
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
188190

189191

190192
try {
@@ -208,7 +210,7 @@ export const cancelShipment = async (data: CancelShipmentRequestData, context: H
208210

209211
const postShipments = async (data: ShipmentRequestData, context: HerculesFunctionContext): Promise<CreateParcelsResponse> => {
210212
const contactID = context.matchedConfig.findConfig("contact_id") as string;
211-
const url = context.matchedConfig.findConfig("api_url") as string;
213+
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
212214

213215
const parsedData: InternalShipmentRequestData = transformShipmentRequestDataToInternalFormat(ShipmentRequestDataSchema.parse(data), context, contactID);
214216

actions/gls-action/src/index.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
createSdk,
2+
createSdk, HerculesActionProjectConfiguration,
33
HerculesFunctionContext,
44
HerculesRuntimeFunctionDefinition,
55
RuntimeErrorException
@@ -2395,18 +2395,37 @@ sdk.registerConfigDefinitions(
23952395
linkedDataTypes: ["STRING"],
23962396
},
23972397
{
2398-
identifier: "api_url",
2398+
identifier: "ship_it_api_url",
23992399
type: "STRING",
2400+
defaultValue: " https://api.gls-group.net/shipit-farm/v1/backend/rs",
24002401
name: [
24012402
{
24022403
code: "en-US",
2403-
content: "API url"
2404+
content: "The ShipIt API url"
24042405
}
24052406
],
24062407
description: [
24072408
{
24082409
code: "en-US",
2409-
content: "The url of the GLS API."
2410+
content: "The url of the GLS ShipIt API."
2411+
}
2412+
],
2413+
linkedDataTypes: ["STRING"],
2414+
},
2415+
{
2416+
identifier: "auth_url",
2417+
type: "STRING",
2418+
defaultValue: "https://api.gls-group.net/oauth2/v2/token",
2419+
name: [
2420+
{
2421+
code: "en-US",
2422+
content: "The Auth API url"
2423+
}
2424+
],
2425+
description: [
2426+
{
2427+
code: "en-US",
2428+
content: "The url of the Auth api ending in /token."
24102429
}
24112430
],
24122431
linkedDataTypes: ["STRING"],
@@ -2431,4 +2450,22 @@ sdk.registerConfigDefinitions(
24312450
).catch(reason => {
24322451
console.error("Failed to register config definitions:", reason)
24332452
process.exit(1)
2434-
})
2453+
})
2454+
2455+
connectToSdk();
2456+
2457+
function connectToSdk() {
2458+
sdk.connect().then((_: HerculesActionProjectConfiguration[]) => {
2459+
console.log("SDK connected successfully");
2460+
}).catch((_error) => {
2461+
console.error("Error connecting SDK:");
2462+
})
2463+
2464+
sdk.onError((error) => {
2465+
console.error("SDK Error occurred:", error.message);
2466+
console.log("Attempting to reconnect in 5s...");
2467+
setTimeout(() => {
2468+
connectToSdk();
2469+
}, 5000)
2470+
})
2471+
}

docs/Actions/GLS/configs.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Action Configuration
3+
---
4+
5+
The GLS action provides following configurations:
6+
7+
| Config Name | Description | Type | Required |
8+
|-----------------|------------------------------------------------------------------|-------------|----------|
9+
| contact_id | The contact id used in some requests | string | No |
10+
| client_id | The client id used for auth purposes | string | Yes |
11+
| client_secret | The client secret used for auth purposes | string | Yes |
12+
| ship_it_api_url | Gls provides multiple ship it urls, provide yours | string | No |
13+
| auth_url | Gls provides multiple auth urls, provide yours ending in /token | string | No |
14+
| shipper | And default shipper which is replaced in the request if provided | GLS_SHIPPER | No |
15+
16+
17+
For you to receive that credentials you need to follow this guide: https://dev-portal.gls-group.net/get-started#sign-in
18+
19+
You can receive the client id and secret under "My Apps" after creating one.
20+
21+
The Contact id needs to be retrieved from GLS support, so you need to contact them and ask for it.

docs/Guides/installation.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Installation guide for actions
3+
---
4+
5+
# Cloud edition
6+
7+
# Selfhosted
8+
9+
To install the Action on your self-hosted instance, follow these steps:
10+
11+
## Clone the repository:
12+
```bash
13+
git clone https://github.com/code0-tech/centaurus.git
14+
```
15+
16+
#
17+
18+
## Navigate to the action directory:
19+
```bash
20+
cd centaurus/actions/<action-name>
21+
```
22+
23+
#
24+
25+
## Create .env file and set the required environment variables:
26+
27+
Possible ENV variables:
28+
29+
| ENV Variable | Description | Default Value |
30+
|------------------------|------------------------------------------------|---------------------|
31+
| `HERCULES_AUTH_TOKEN` | Authentication token for connecting to Aquila. | `""` (empty string) |
32+
| `HERCULES_AQUILA_URL` | URL of the Aquila server to connect to. | `"localhost:50051"` |
33+
| `HERCULES_ACTION_ID` | Identifier for the action being registered. | `"<action-name>"` |
34+
| `HERCULES_SDK_VERSION` | Version of the Hercules SDK being used. | `"0.0.0"` |
35+
36+
Example (.env):
37+
```
38+
HERCULES_AUTH_TOKEN=your_auth_token
39+
...
40+
```
41+
42+
#
43+
44+
## Install it via docker:
45+
```bash
46+
docker compose up -d
47+
```
48+

docs/index.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Welcome to the Documentation for Centaurus
3+
description: Find out how Centaurus works
4+
template: splash
5+
---
6+
7+
## What is Centaurus?
8+
9+
Centaurus is a repository with a collection of actions provided by code0.

0 commit comments

Comments
 (0)