Skip to content

Commit be85eb0

Browse files
committed
Refactor SDK integration to use ActionSdk and update TypeScript definitions
1 parent 22e249a commit be85eb0

85 files changed

Lines changed: 2861 additions & 1484 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

actions/gls-action/package-lock.json

Lines changed: 398 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/gls-action/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "./dist/index.js",
77
"types": "./dist/index.d.ts",
88
"scripts": {
9-
"build": "tsc --build",
10-
"lint": "eslint ."
9+
"build": "vite build",
10+
"lint": "eslint .",
11+
"test": "vitest run"
1112
}
1213
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {vi} from "vitest";
2+
import {SdkMockState} from "../index.test";
3+
import {withSdkMock} from "./withSdkMock";
4+
import {ActionSdk} from "@code0-tech/hercules";
5+
6+
export const withBaseFunctionMock = async (
7+
register: (sdk: ActionSdk) => Promise<void>,
8+
tests: (state: SdkMockState) => void
9+
) => {
10+
await withSdkMock(async (state) => {
11+
const {createSdk} = await import("@code0-tech/hercules")
12+
13+
vi.doMock("../helpers.ts", async (importOriginal) => {
14+
const actual = await importOriginal() as any;
15+
16+
return {
17+
...actual,
18+
loadAllDefinitions: vi.fn(() => {
19+
return Promise.resolve()
20+
})
21+
}
22+
})
23+
24+
const mockSdk = createSdk(
25+
{
26+
actionId: "",
27+
version: "",
28+
aquilaUrl: "",
29+
authToken: ""
30+
}
31+
)
32+
33+
vi.doMock("../index.ts", () => ({
34+
sdk: mockSdk
35+
}));
36+
37+
vi.doMock("axios", () => {
38+
return {
39+
post: vi.fn(),
40+
get: vi.fn(),
41+
put: vi.fn(),
42+
delete: vi.fn(),
43+
};
44+
});
45+
46+
try {
47+
await register(mockSdk)
48+
49+
tests(state);
50+
51+
} catch (error) {
52+
console.error(error)
53+
}
54+
})
55+
}
56+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import {beforeEach, vi} from "vitest";
2+
import {
3+
ActionSdk,
4+
HerculesActionConfigurationDefinition,
5+
HerculesDataType,
6+
HerculesFlowType,
7+
HerculesRegisterFunctionParameter
8+
} from "@code0-tech/hercules";
9+
import {SdkMockState} from "../index.test";
10+
11+
export const withSdkMock = async (tests: (state: SdkMockState) => void) => {
12+
const state = vi.hoisted(() => {
13+
const state: SdkMockState = {
14+
registeredFunctionDefinitions: [] as HerculesRegisterFunctionParameter[],
15+
dataTypes: [] as HerculesDataType[],
16+
flowTypes: [] as HerculesFlowType[],
17+
configDefinitions: [] as HerculesActionConfigurationDefinition[],
18+
};
19+
return state
20+
})
21+
22+
23+
vi.mock("@code0-tech/hercules", async (importOriginal) => {
24+
const actual = await importOriginal() as any
25+
return {
26+
...actual,
27+
createSdk: (config, configDefinitions) => {
28+
state.configDefinitions = configDefinitions || null
29+
30+
const mockedActionSdk: ActionSdk = {
31+
config: config,
32+
registerFunctionDefinitions: (...defs: HerculesRegisterFunctionParameter[]) => {
33+
state.registeredFunctionDefinitions = defs;
34+
return Promise.resolve();
35+
},
36+
37+
registerConfigDefinitions: (...defs: HerculesActionConfigurationDefinition[]) => {
38+
state.configDefinitions = defs;
39+
return Promise.resolve();
40+
},
41+
42+
registerDataTypes: (...types: HerculesDataType[]) => {
43+
state.dataTypes = types;
44+
return Promise.resolve();
45+
},
46+
47+
registerFlowTypes: (...types: HerculesFlowType[]) => {
48+
state.flowTypes = types;
49+
return Promise.resolve();
50+
},
51+
fullyConnected: () => {
52+
return true
53+
},
54+
connect: vi.fn((options) => {
55+
return Promise.resolve([]);
56+
}),
57+
onError: vi.fn(),
58+
dispatchEvent: vi.fn(),
59+
getProjectActionConfigurations: vi.fn()
60+
}
61+
return mockedActionSdk
62+
63+
}
64+
}
65+
66+
})
67+
68+
69+
beforeEach(() => {
70+
state.registeredFunctionDefinitions = null;
71+
state.dataTypes = null;
72+
state.flowTypes = null;
73+
state.configDefinitions = null;
74+
});
75+
76+
tests(state);
77+
}

actions/gls-action/src/definitions/configDefinition/authUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {sdk} from "../../index";
1+
import {ActionSdk} from "@code0-tech/hercules";
22

3-
export function register() {
3+
export function register(sdk: ActionSdk) {
44
return sdk.registerConfigDefinitions(
55
{
66
identifier: "auth_url",

actions/gls-action/src/definitions/configDefinition/clientId.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {sdk} from "../../index";
1+
import {ActionSdk} from "@code0-tech/hercules";
22

3-
export function register() {
3+
export function register(sdk: ActionSdk) {
44
return sdk.registerConfigDefinitions(
55
{
66
identifier: "client_id",

actions/gls-action/src/definitions/configDefinition/clientSecret.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {sdk} from "../../index";
1+
import {ActionSdk} from "@code0-tech/hercules";
22

3-
export function register() {
3+
export function register(sdk: ActionSdk) {
44
return sdk.registerConfigDefinitions(
55
{
66
identifier: "client_secret",

actions/gls-action/src/definitions/configDefinition/contactId.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {sdk} from "../../index";
1+
import {ActionSdk} from "@code0-tech/hercules";
22

3-
export function register() {
3+
export function register(sdk: ActionSdk) {
44
return sdk.registerConfigDefinitions(
55
{
66
identifier: "contact_id",

actions/gls-action/src/definitions/configDefinition/defaultShipper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {sdk} from "../../index";
1+
import {ActionSdk} from "@code0-tech/hercules";
22

3-
export function register() {
3+
export function register(sdk: ActionSdk) {
44
return sdk.registerConfigDefinitions(
55
{
66
identifier: "default_shipper",

actions/gls-action/src/definitions/configDefinition/shipItApiUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {sdk} from "../../index";
1+
import {ActionSdk} from "@code0-tech/hercules";
22

3-
export function register() {
3+
export function register(sdk: ActionSdk) {
44
return sdk.registerConfigDefinitions(
55
{
66
identifier: "ship_it_api_url",

0 commit comments

Comments
 (0)