Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ jobs:
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build
- run: npm run lint
- run: npm run test
399 changes: 398 additions & 1 deletion actions/gls-action/package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions actions/gls-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc --build",
"lint": "eslint ."
"build": "vite build",
"lint": "eslint .",
"test": "vitest run",
"start": "node dist/index.js"
}
}
56 changes: 56 additions & 0 deletions actions/gls-action/src/__tests__/withBaseFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {vi} from "vitest";
import {SdkMockState} from "../index.test";
import {withSdkMock} from "./withSdkMock";
import {ActionSdk} from "@code0-tech/hercules";

export const withBaseFunctionMock = async (
register: (sdk: ActionSdk) => Promise<void>,
tests: (state: SdkMockState) => void
) => {
await withSdkMock(async (state) => {
const {createSdk} = await import("@code0-tech/hercules")

vi.doMock("../helpers.ts", async (importOriginal) => {
const actual = await importOriginal() as any;

return {
...actual,
loadAllDefinitions: vi.fn(() => {
return Promise.resolve()
})
}
})

const mockSdk = createSdk(
{
actionId: "",
version: "",
aquilaUrl: "",
authToken: ""
}
)

vi.doMock("../index.ts", () => ({
sdk: mockSdk
}));

vi.doMock("axios", () => {
return {
post: vi.fn(),
get: vi.fn(),
put: vi.fn(),
delete: vi.fn(),
};
});

try {
await register(mockSdk)

tests(state);

} catch (error) {
console.error(error)
}
})
}

77 changes: 77 additions & 0 deletions actions/gls-action/src/__tests__/withSdkMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {beforeEach, vi} from "vitest";
import {
ActionSdk,
HerculesActionConfigurationDefinition,
HerculesDataType,
HerculesFlowType,
HerculesRegisterFunctionParameter
} from "@code0-tech/hercules";
import {SdkMockState} from "../index.test";

export const withSdkMock = async (tests: (state: SdkMockState) => void) => {
const state = vi.hoisted(() => {
const state: SdkMockState = {
registeredFunctionDefinitions: [] as HerculesRegisterFunctionParameter[],
dataTypes: [] as HerculesDataType[],
flowTypes: [] as HerculesFlowType[],
configDefinitions: [] as HerculesActionConfigurationDefinition[],
};
return state
})


vi.mock("@code0-tech/hercules", async (importOriginal) => {
const actual = await importOriginal() as any
return {
...actual,
createSdk: (config, configDefinitions) => {
state.configDefinitions = configDefinitions || null

const mockedActionSdk: ActionSdk = {
config: config,
registerFunctionDefinitions: (...defs: HerculesRegisterFunctionParameter[]) => {
state.registeredFunctionDefinitions = defs;
return Promise.resolve();
},

registerConfigDefinitions: (...defs: HerculesActionConfigurationDefinition[]) => {
state.configDefinitions = defs;
return Promise.resolve();
},

registerDataTypes: (...types: HerculesDataType[]) => {
state.dataTypes = types;
return Promise.resolve();
},

registerFlowTypes: (...types: HerculesFlowType[]) => {
state.flowTypes = types;
return Promise.resolve();
},
fullyConnected: () => {
return true
},
connect: vi.fn(() => {
return Promise.resolve([]);
}),
onError: vi.fn(),
dispatchEvent: vi.fn(),
getProjectActionConfigurations: vi.fn()
}
return mockedActionSdk

}
}

})


beforeEach(() => {
state.registeredFunctionDefinitions = null;
state.dataTypes = null;
state.flowTypes = null;
state.configDefinitions = null;
});

tests(state);
}
24 changes: 24 additions & 0 deletions actions/gls-action/src/definitions/configDefinition/authUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {ActionSdk} from "@code0-tech/hercules";

export function register(sdk: ActionSdk) {
return sdk.registerConfigDefinitions(
{
identifier: "auth_url",
type: "TEXT",
defaultValue: "https://api.gls-group.net/oauth2/v2/token",
name: [
{
code: "en-US",
content: "The Auth API url"
}
],
description: [
{
code: "en-US",
content: "The url of the Auth api ending in /token."
}
],
linkedDataTypes: ["STRING"],
},
)
}
23 changes: 23 additions & 0 deletions actions/gls-action/src/definitions/configDefinition/clientId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {ActionSdk} from "@code0-tech/hercules";

export function register(sdk: ActionSdk) {
return sdk.registerConfigDefinitions(
{
identifier: "client_id",
type: "TEXT",
name: [
{
code: "en-US",
content: "Client ID"
}
],
description: [
{
code: "en-US",
content: "The client id to authenticate with the GLS API"
}
],
linkedDataTypes: ["TEXT"],
},
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {ActionSdk} from "@code0-tech/hercules";

export function register(sdk: ActionSdk) {
return sdk.registerConfigDefinitions(
{
identifier: "client_secret",
type: "TEXT",
name: [
{
code: "en-US",
content: "Client secret"
}
],
description: [
{
code: "en-US",
content: "The client secret to authenticate with the GLS API"
}
],
linkedDataTypes: ["TEXT"],
},
)
}
24 changes: 24 additions & 0 deletions actions/gls-action/src/definitions/configDefinition/contactId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {ActionSdk} from "@code0-tech/hercules";

export function register(sdk: ActionSdk) {
return sdk.registerConfigDefinitions(
{
identifier: "contact_id",
type: "TEXT",
name: [
{
code: "en-US",
content: "Contact ID"
}
],
description: [
{
code: "en-US",
content: "The contact id identifying the GLS account to use for the API requests. This contact must be linked to a GLS contract with API access."
}
],
defaultValue: "",
linkedDataTypes: ["TEXT"],
},
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {ActionSdk} from "@code0-tech/hercules";

export function register(sdk: ActionSdk) {
return sdk.registerConfigDefinitions(
{
identifier: "default_shipper",
type: "GLS_SHIPPER",
name: [
{
code: "en-US",
content: "Shipper"
}
],
description: [
{
code: "en-US",
content: "The shipper information to use for the shipments. This will be used if the shipper information is not provided in the shipment data."
}
],
linkedDataTypes: ["GLS_SHIPPER"]
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {ActionSdk} from "@code0-tech/hercules";

export function register(sdk: ActionSdk) {
return sdk.registerConfigDefinitions(
{
identifier: "ship_it_api_url",
type: "TEXT",
defaultValue: " https://api.gls-group.net/shipit-farm/v1/backend/rs",
name: [
{
code: "en-US",
content: "The ShipIt API url"
}
],
description: [
{
code: "en-US",
content: "The url of the GLS ShipIt API."
}
],
linkedDataTypes: ["TEXT"],
},
)
}
42 changes: 42 additions & 0 deletions actions/gls-action/src/definitions/datatypes/glsAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {ActionSdk} from "@code0-tech/hercules";
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),
})
export type AddressSchema = z.infer<typeof AddressSchema>


export function register(sdk: ActionSdk) {
return sdk.registerDataTypes(
{
identifier: "GLS_ADDRESS",
type: singleZodSchemaToTypescriptDef("GLS_ADDRESS", AddressSchema),
name: [
{
code: "en-US",
content: "Address"
}
],
displayMessage: [
{
code: "en-US",
content: "Address"
}
]
},
)
}
Loading