@unmeshed/sdk 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apiClient.js +7 -12
- package/dist/index.d.ts +8 -8
- package/dist/index.js +20 -23
- package/dist/poller/pollerClientImpl.js +10 -13
- package/dist/process/processClientImpl.js +27 -42
- package/dist/registration/registrationClientImpl.js +3 -7
- package/dist/sample/server.d.ts +1 -0
- package/dist/sample/server.js +9 -0
- package/dist/src/apiClient.d.ts +14 -0
- package/dist/src/apiClient.js +99 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.js +22 -0
- package/dist/src/poller/pollerClientImpl.d.ts +2 -0
- package/dist/src/poller/pollerClientImpl.js +126 -0
- package/dist/src/process/processClientImpl.d.ts +12 -0
- package/dist/src/process/processClientImpl.js +187 -0
- package/dist/src/registration/registrationClientImpl.d.ts +1 -0
- package/dist/src/registration/registrationClientImpl.js +17 -0
- package/dist/src/sample/server.d.ts +1 -0
- package/dist/src/sample/server.js +9 -0
- package/dist/src/types/index.d.ts +313 -0
- package/dist/src/types/index.js +77 -0
- package/dist/src/utils/unmeshedCommonUtils.d.ts +3 -0
- package/dist/src/utils/unmeshedCommonUtils.js +13 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.js +16 -19
- package/dist/utils/unmeshedCommonUtils.js +3 -7
- package/package.json +2 -1
- package/dist/sample/sampleServer.d.ts +0 -1
- package/dist/sample/sampleServer.js +0 -76
- package/dist/sample/workers/ArithmeticWorker.d.ts +0 -5
- package/dist/sample/workers/ArithmeticWorker.js +0 -23
- package/dist/sample/workers/DelayedWorker.d.ts +0 -1
- package/dist/sample/workers/DelayedWorker.js +0 -11
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -62
package/dist/apiClient.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
|
-
const unmeshedCommonUtils_1 = require("./utils/unmeshedCommonUtils");
|
|
6
|
-
class ApiClient {
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { UnmeshedCommonUtils } from "./utils/unmeshedCommonUtils";
|
|
3
|
+
export class ApiClient {
|
|
7
4
|
constructor() {
|
|
8
5
|
this.axiosInstance = null;
|
|
9
6
|
this.clientId = null;
|
|
@@ -15,12 +12,12 @@ class ApiClient {
|
|
|
15
12
|
throw new Error("baseUrl is required");
|
|
16
13
|
}
|
|
17
14
|
const baseURL = port ? `${baseUrl}:${port}` : baseUrl;
|
|
18
|
-
this.axiosInstance =
|
|
15
|
+
this.axiosInstance = axios.create({
|
|
19
16
|
baseURL,
|
|
20
17
|
timeout,
|
|
21
18
|
headers: {
|
|
22
19
|
"Content-Type": "application/json",
|
|
23
|
-
Authorization: `Bearer client.sdk.${clientId}.${
|
|
20
|
+
Authorization: `Bearer client.sdk.${clientId}.${UnmeshedCommonUtils.createSecureHash(authToken)}`,
|
|
24
21
|
},
|
|
25
22
|
});
|
|
26
23
|
}
|
|
@@ -51,11 +48,10 @@ class ApiClient {
|
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
handleError(error) {
|
|
54
|
-
var _a, _b;
|
|
55
51
|
console.error("Error details:", {
|
|
56
52
|
message: error.message,
|
|
57
|
-
status:
|
|
58
|
-
data:
|
|
53
|
+
status: error.response?.status,
|
|
54
|
+
data: error.response?.data,
|
|
59
55
|
});
|
|
60
56
|
}
|
|
61
57
|
async get(endpoint, params, config) {
|
|
@@ -91,4 +87,3 @@ class ApiClient {
|
|
|
91
87
|
return this.clientId;
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
|
-
exports.ApiClient = ApiClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,14 +4,14 @@ import { ApiCallType, ApiClientConfig, ProcessRequestData, ProcessSearchRequest
|
|
|
4
4
|
export declare const apiClient: ApiClient;
|
|
5
5
|
declare const UnmeshedClient: {
|
|
6
6
|
initialize: (config: ApiClientConfig) => void;
|
|
7
|
-
runProcessSync: (ProcessRequestData: ProcessRequestData) => Promise<
|
|
8
|
-
runProcessAsync: (ProcessRequestData: ProcessRequestData) => Promise<
|
|
9
|
-
getProcessData: (processId: number) => Promise<
|
|
10
|
-
getStepData: (stepId: number | null) => Promise<
|
|
11
|
-
bulkTerminate: (processIds: number[], reason?: string) => Promise<
|
|
12
|
-
bulkResume: (processIds: number[]) => Promise<
|
|
13
|
-
bulkReviewed: (processIds: number[], reason?: string) => Promise<
|
|
14
|
-
rerun: (processId: number, clientId: string, version?: number) => Promise<
|
|
7
|
+
runProcessSync: (ProcessRequestData: ProcessRequestData) => Promise<ApiCallType>;
|
|
8
|
+
runProcessAsync: (ProcessRequestData: ProcessRequestData) => Promise<ApiCallType>;
|
|
9
|
+
getProcessData: (processId: number) => Promise<ApiCallType>;
|
|
10
|
+
getStepData: (stepId: number | null) => Promise<ApiCallType>;
|
|
11
|
+
bulkTerminate: (processIds: number[], reason?: string) => Promise<ApiCallType>;
|
|
12
|
+
bulkResume: (processIds: number[]) => Promise<ApiCallType>;
|
|
13
|
+
bulkReviewed: (processIds: number[], reason?: string) => Promise<ApiCallType>;
|
|
14
|
+
rerun: (processId: number, clientId: string, version?: number) => Promise<ApiCallType>;
|
|
15
15
|
searchProcessExecutions: (params: ProcessSearchRequest) => Promise<any>;
|
|
16
16
|
invokeApiMappingGet: (endpoint: string, id: string, correlationId: string, apiCallType: ApiCallType) => Promise<any>;
|
|
17
17
|
invokeApiMappingPost: (endpoint: string, input: Record<string, any>, id: string, correlationId: string, apiCallType?: ApiCallType) => Promise<any>;
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const processClientImpl_1 = require("./process/processClientImpl");
|
|
7
|
-
const registrationClientImpl_1 = require("./registration/registrationClientImpl");
|
|
8
|
-
exports.apiClient = new apiClient_1.ApiClient();
|
|
1
|
+
import { ApiClient } from "./apiClient";
|
|
2
|
+
import pollForWorkers from "./poller/pollerClientImpl";
|
|
3
|
+
import { bulkResume, bulkReviewed, bulkTerminate, getProcessData, getStepData, invokeApiMappingGet, invokeApiMappingPost, rerun, runProcessAsync, runProcessSync, searchProcessExecutions, } from "./process/processClientImpl";
|
|
4
|
+
import { renewRegistration } from "./registration/registrationClientImpl";
|
|
5
|
+
export const apiClient = new ApiClient();
|
|
9
6
|
const UnmeshedClient = {
|
|
10
|
-
initialize: (config) =>
|
|
11
|
-
runProcessSync
|
|
12
|
-
runProcessAsync
|
|
13
|
-
getProcessData
|
|
14
|
-
getStepData
|
|
15
|
-
bulkTerminate
|
|
16
|
-
bulkResume
|
|
17
|
-
bulkReviewed
|
|
18
|
-
rerun
|
|
19
|
-
searchProcessExecutions
|
|
20
|
-
invokeApiMappingGet
|
|
21
|
-
invokeApiMappingPost
|
|
22
|
-
renewRegistration
|
|
23
|
-
pollForWorkers
|
|
7
|
+
initialize: (config) => apiClient.initialize(config),
|
|
8
|
+
runProcessSync,
|
|
9
|
+
runProcessAsync,
|
|
10
|
+
getProcessData,
|
|
11
|
+
getStepData,
|
|
12
|
+
bulkTerminate,
|
|
13
|
+
bulkResume,
|
|
14
|
+
bulkReviewed,
|
|
15
|
+
rerun,
|
|
16
|
+
searchProcessExecutions,
|
|
17
|
+
invokeApiMappingGet,
|
|
18
|
+
invokeApiMappingPost,
|
|
19
|
+
renewRegistration,
|
|
20
|
+
pollForWorkers,
|
|
24
21
|
};
|
|
25
|
-
|
|
22
|
+
export default UnmeshedClient;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.default = pollForWorkers;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const types_1 = require("../types");
|
|
1
|
+
import { apiClient } from "..";
|
|
2
|
+
import { StepStatus, } from "../types";
|
|
6
3
|
async function registerPolling(data) {
|
|
7
4
|
const attempt = async () => {
|
|
8
5
|
try {
|
|
9
|
-
const response = await
|
|
6
|
+
const response = await apiClient.put("/api/clients/register", {
|
|
10
7
|
data: data,
|
|
11
8
|
});
|
|
12
9
|
console.log("Successfully executed polling registration...");
|
|
@@ -22,7 +19,7 @@ async function registerPolling(data) {
|
|
|
22
19
|
}
|
|
23
20
|
async function pollWorker(data) {
|
|
24
21
|
try {
|
|
25
|
-
const response = await
|
|
22
|
+
const response = await apiClient.post("/api/clients/poll", {
|
|
26
23
|
data: data,
|
|
27
24
|
});
|
|
28
25
|
console.log("Succesfully executed worker polling...");
|
|
@@ -34,7 +31,7 @@ async function pollWorker(data) {
|
|
|
34
31
|
}
|
|
35
32
|
async function pollWorkerResult(data) {
|
|
36
33
|
try {
|
|
37
|
-
const response = await
|
|
34
|
+
const response = await apiClient.post("/api/clients/bulkResults", {
|
|
38
35
|
data: data,
|
|
39
36
|
});
|
|
40
37
|
console.log("Worker Result returned successfully...");
|
|
@@ -44,7 +41,7 @@ async function pollWorkerResult(data) {
|
|
|
44
41
|
console.log("Error:", error);
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
|
-
async function pollForWorkers(workers) {
|
|
44
|
+
export default async function pollForWorkers(workers) {
|
|
48
45
|
const registerPollingData = workers.map((worker) => {
|
|
49
46
|
return {
|
|
50
47
|
orgId: 0,
|
|
@@ -75,7 +72,7 @@ async function pollForWorkers(workers) {
|
|
|
75
72
|
stepExecutionId: polledWorker.stepExecutionId,
|
|
76
73
|
runCount: polledWorker.runCount,
|
|
77
74
|
output: {},
|
|
78
|
-
status:
|
|
75
|
+
status: StepStatus.RUNNING,
|
|
79
76
|
rescheduleAfterSeconds: null,
|
|
80
77
|
startedAt: new Date().getTime(),
|
|
81
78
|
};
|
|
@@ -94,7 +91,7 @@ async function pollForWorkers(workers) {
|
|
|
94
91
|
...result,
|
|
95
92
|
__workCompletedAt: new Date().getTime(),
|
|
96
93
|
},
|
|
97
|
-
status:
|
|
94
|
+
status: StepStatus.COMPLETED,
|
|
98
95
|
};
|
|
99
96
|
}
|
|
100
97
|
catch (error) {
|
|
@@ -104,7 +101,7 @@ async function pollForWorkers(workers) {
|
|
|
104
101
|
output: {
|
|
105
102
|
error: error.message,
|
|
106
103
|
},
|
|
107
|
-
status:
|
|
104
|
+
status: StepStatus.TIMED_OUT,
|
|
108
105
|
};
|
|
109
106
|
}
|
|
110
107
|
else {
|
|
@@ -113,7 +110,7 @@ async function pollForWorkers(workers) {
|
|
|
113
110
|
output: {
|
|
114
111
|
error: error.message,
|
|
115
112
|
},
|
|
116
|
-
status:
|
|
113
|
+
status: StepStatus.FAILED,
|
|
117
114
|
};
|
|
118
115
|
console.error("Error:", error.message);
|
|
119
116
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.invokeApiMappingPost = exports.invokeApiMappingGet = exports.searchProcessExecutions = exports.rerun = exports.bulkReviewed = exports.bulkResume = exports.bulkTerminate = exports.getStepData = exports.getProcessData = exports.runProcessAsync = exports.runProcessSync = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const types_1 = require("../types");
|
|
1
|
+
import { apiClient } from "..";
|
|
2
|
+
import { ApiCallType, } from "../types";
|
|
6
3
|
const RUN_PROCESS_REQUEST_URL = "api/process/";
|
|
7
|
-
const runProcessSync = async (ProcessRequestData) => {
|
|
4
|
+
export const runProcessSync = async (ProcessRequestData) => {
|
|
8
5
|
try {
|
|
9
|
-
const response = await
|
|
6
|
+
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "runSync", {
|
|
10
7
|
data: ProcessRequestData,
|
|
11
8
|
params: {
|
|
12
|
-
clientId:
|
|
9
|
+
clientId: apiClient.getClientId(),
|
|
13
10
|
},
|
|
14
11
|
});
|
|
15
12
|
console.log("Response:", response);
|
|
@@ -20,13 +17,12 @@ const runProcessSync = async (ProcessRequestData) => {
|
|
|
20
17
|
throw error;
|
|
21
18
|
}
|
|
22
19
|
};
|
|
23
|
-
|
|
24
|
-
const runProcessAsync = async (ProcessRequestData) => {
|
|
20
|
+
export const runProcessAsync = async (ProcessRequestData) => {
|
|
25
21
|
try {
|
|
26
|
-
const response = await
|
|
22
|
+
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "runAsync", {
|
|
27
23
|
data: ProcessRequestData,
|
|
28
24
|
params: {
|
|
29
|
-
clientId:
|
|
25
|
+
clientId: apiClient.getClientId(),
|
|
30
26
|
},
|
|
31
27
|
});
|
|
32
28
|
console.log("Response:", response);
|
|
@@ -37,13 +33,12 @@ const runProcessAsync = async (ProcessRequestData) => {
|
|
|
37
33
|
throw error;
|
|
38
34
|
}
|
|
39
35
|
};
|
|
40
|
-
|
|
41
|
-
const getProcessData = async (processId) => {
|
|
36
|
+
export const getProcessData = async (processId) => {
|
|
42
37
|
if (processId == null) {
|
|
43
38
|
throw new Error("Process ID cannot be null");
|
|
44
39
|
}
|
|
45
40
|
try {
|
|
46
|
-
const response = await
|
|
41
|
+
const response = await apiClient.get(RUN_PROCESS_REQUEST_URL + "context/" + processId);
|
|
47
42
|
return response.data;
|
|
48
43
|
}
|
|
49
44
|
catch (error) {
|
|
@@ -51,23 +46,21 @@ const getProcessData = async (processId) => {
|
|
|
51
46
|
throw error;
|
|
52
47
|
}
|
|
53
48
|
};
|
|
54
|
-
|
|
55
|
-
const getStepData = async (stepId) => {
|
|
49
|
+
export const getStepData = async (stepId) => {
|
|
56
50
|
if (stepId === null || stepId === undefined) {
|
|
57
51
|
throw new Error("Step ID cannot be null or undefined");
|
|
58
52
|
}
|
|
59
53
|
try {
|
|
60
|
-
const response = await
|
|
54
|
+
const response = await apiClient.get(RUN_PROCESS_REQUEST_URL + "stepContext/" + stepId);
|
|
61
55
|
return response.data;
|
|
62
56
|
}
|
|
63
57
|
catch (error) {
|
|
64
58
|
throw new Error(`Error occurred while fetching step record: ${error.message || error}`);
|
|
65
59
|
}
|
|
66
60
|
};
|
|
67
|
-
|
|
68
|
-
const bulkTerminate = async (processIds, reason) => {
|
|
61
|
+
export const bulkTerminate = async (processIds, reason) => {
|
|
69
62
|
try {
|
|
70
|
-
const response = await
|
|
63
|
+
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "bulkTerminate", {
|
|
71
64
|
params: { reason },
|
|
72
65
|
data: processIds,
|
|
73
66
|
});
|
|
@@ -77,10 +70,9 @@ const bulkTerminate = async (processIds, reason) => {
|
|
|
77
70
|
throw new Error(`Error occurred while terminating processes: ${error.message || error}`);
|
|
78
71
|
}
|
|
79
72
|
};
|
|
80
|
-
|
|
81
|
-
const bulkResume = async (processIds) => {
|
|
73
|
+
export const bulkResume = async (processIds) => {
|
|
82
74
|
try {
|
|
83
|
-
const response = await
|
|
75
|
+
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "bulkResume", {
|
|
84
76
|
data: processIds,
|
|
85
77
|
});
|
|
86
78
|
return response.data;
|
|
@@ -89,10 +81,9 @@ const bulkResume = async (processIds) => {
|
|
|
89
81
|
throw new Error(`Error occurred while resuming processes: ${error.message || error}`);
|
|
90
82
|
}
|
|
91
83
|
};
|
|
92
|
-
|
|
93
|
-
const bulkReviewed = async (processIds, reason) => {
|
|
84
|
+
export const bulkReviewed = async (processIds, reason) => {
|
|
94
85
|
try {
|
|
95
|
-
const response = await
|
|
86
|
+
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "bulkReviewed", {
|
|
96
87
|
data: processIds,
|
|
97
88
|
params: { reason },
|
|
98
89
|
});
|
|
@@ -102,9 +93,7 @@ const bulkReviewed = async (processIds, reason) => {
|
|
|
102
93
|
throw new Error(`Error occurred while marking processes as reviewed: ${error.message || error}`);
|
|
103
94
|
}
|
|
104
95
|
};
|
|
105
|
-
|
|
106
|
-
const rerun = async (processId, clientId, version) => {
|
|
107
|
-
var _a, _b;
|
|
96
|
+
export const rerun = async (processId, clientId, version) => {
|
|
108
97
|
const params = {
|
|
109
98
|
clientId,
|
|
110
99
|
processId,
|
|
@@ -113,22 +102,21 @@ const rerun = async (processId, clientId, version) => {
|
|
|
113
102
|
params["version"] = version;
|
|
114
103
|
}
|
|
115
104
|
try {
|
|
116
|
-
const response = await
|
|
105
|
+
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "rerun", {
|
|
117
106
|
params,
|
|
118
107
|
});
|
|
119
108
|
return response.data;
|
|
120
109
|
}
|
|
121
110
|
catch (error) {
|
|
122
111
|
if (error.isAxiosError) {
|
|
123
|
-
throw new Error(`HTTP request error during rerun process: ${
|
|
112
|
+
throw new Error(`HTTP request error during rerun process: ${error.response?.status} - ${error.response?.data}`);
|
|
124
113
|
}
|
|
125
114
|
else {
|
|
126
115
|
throw new Error(`Unexpected error during rerun process: ${error.message}`);
|
|
127
116
|
}
|
|
128
117
|
}
|
|
129
118
|
};
|
|
130
|
-
|
|
131
|
-
const searchProcessExecutions = async (params) => {
|
|
119
|
+
export const searchProcessExecutions = async (params) => {
|
|
132
120
|
const queryParams = new URLSearchParams();
|
|
133
121
|
if (params.startTimeEpoch !== undefined && params.startTimeEpoch !== 0)
|
|
134
122
|
queryParams.set("startTimeEpoch", params.startTimeEpoch.toString());
|
|
@@ -150,7 +138,7 @@ const searchProcessExecutions = async (params) => {
|
|
|
150
138
|
queryParams.set("triggerTypes", params.triggerTypes.join(","));
|
|
151
139
|
const updatedParams = Object.fromEntries(new URLSearchParams(queryParams));
|
|
152
140
|
try {
|
|
153
|
-
const response = await
|
|
141
|
+
const response = await apiClient.get(RUN_PROCESS_REQUEST_URL + "api/stats/process/search", updatedParams);
|
|
154
142
|
console.log("Response:", response);
|
|
155
143
|
return response.data;
|
|
156
144
|
}
|
|
@@ -159,10 +147,9 @@ const searchProcessExecutions = async (params) => {
|
|
|
159
147
|
throw error;
|
|
160
148
|
}
|
|
161
149
|
};
|
|
162
|
-
|
|
163
|
-
const invokeApiMappingGet = async (endpoint, id, correlationId, apiCallType) => {
|
|
150
|
+
export const invokeApiMappingGet = async (endpoint, id, correlationId, apiCallType) => {
|
|
164
151
|
try {
|
|
165
|
-
const response = await
|
|
152
|
+
const response = await apiClient.get(RUN_PROCESS_REQUEST_URL + "api/call/" + endpoint, {
|
|
166
153
|
id: id,
|
|
167
154
|
correlationId: correlationId,
|
|
168
155
|
apiCallType,
|
|
@@ -175,10 +162,9 @@ const invokeApiMappingGet = async (endpoint, id, correlationId, apiCallType) =>
|
|
|
175
162
|
throw error;
|
|
176
163
|
}
|
|
177
164
|
};
|
|
178
|
-
|
|
179
|
-
const invokeApiMappingPost = async (endpoint, input, id, correlationId, apiCallType = types_1.ApiCallType.ASYNC) => {
|
|
165
|
+
export const invokeApiMappingPost = async (endpoint, input, id, correlationId, apiCallType = ApiCallType.ASYNC) => {
|
|
180
166
|
try {
|
|
181
|
-
const response = await
|
|
167
|
+
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "api/call/" + endpoint, {
|
|
182
168
|
data: input,
|
|
183
169
|
params: {
|
|
184
170
|
id: id,
|
|
@@ -193,4 +179,3 @@ const invokeApiMappingPost = async (endpoint, input, id, correlationId, apiCallT
|
|
|
193
179
|
throw error;
|
|
194
180
|
}
|
|
195
181
|
};
|
|
196
|
-
exports.invokeApiMappingPost = invokeApiMappingPost;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.renewRegistration = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const renewRegistration = async () => {
|
|
1
|
+
import { apiClient } from "..";
|
|
2
|
+
export const renewRegistration = async () => {
|
|
6
3
|
try {
|
|
7
|
-
const response = await
|
|
4
|
+
const response = await apiClient.put("/api/clients/register", {
|
|
8
5
|
params: {
|
|
9
6
|
friendlyName: "Unmeshed",
|
|
10
7
|
tokenExpiryDate: "",
|
|
@@ -18,4 +15,3 @@ const renewRegistration = async () => {
|
|
|
18
15
|
throw error;
|
|
19
16
|
}
|
|
20
17
|
};
|
|
21
|
-
exports.renewRegistration = renewRegistration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { initialize } from "../index";
|
|
2
|
+
import { getProcessData } from "../process/processClientImpl";
|
|
3
|
+
initialize({
|
|
4
|
+
baseUrl: "https://perfdemo.unmeshed.com",
|
|
5
|
+
clientId: "e1208b04-e308-4976-b236-074a82b0ecbb",
|
|
6
|
+
authToken: "8R06KsNUqBN4b67jcN0W",
|
|
7
|
+
port: "443",
|
|
8
|
+
});
|
|
9
|
+
getProcessData(27100448).then(result => console.log(JSON.stringify(result, null, 2)));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApiClientConfig, ApiResponse, ClientRequestConfig, QueryParams, RequestConfig } from "./types";
|
|
2
|
+
export declare class ApiClient {
|
|
3
|
+
private axiosInstance;
|
|
4
|
+
private clientId;
|
|
5
|
+
initialize(config: ApiClientConfig): void;
|
|
6
|
+
private validateInstance;
|
|
7
|
+
private handleRequest;
|
|
8
|
+
private handleError;
|
|
9
|
+
get<T = any>(endpoint: string, params?: QueryParams, config?: RequestConfig): Promise<ApiResponse<T>>;
|
|
10
|
+
post<T = any>(endpoint: string, clientRequestConfig: ClientRequestConfig): Promise<ApiResponse<T>>;
|
|
11
|
+
put<T = any>(endpoint: string, clientRequestConfig: ClientRequestConfig): Promise<ApiResponse<T>>;
|
|
12
|
+
delete<T = any>(endpoint: string, clientRequestConfig: ClientRequestConfig): Promise<ApiResponse<T>>;
|
|
13
|
+
getClientId(): string | undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { UnmeshedCommonUtils } from "./utils/unmeshedCommonUtils";
|
|
3
|
+
export class ApiClient {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.axiosInstance = null;
|
|
6
|
+
this.clientId = undefined;
|
|
7
|
+
}
|
|
8
|
+
initialize(config) {
|
|
9
|
+
const { clientId, authToken, baseUrl, port, timeout = 10000 } = config;
|
|
10
|
+
this.clientId = clientId;
|
|
11
|
+
if (!baseUrl) {
|
|
12
|
+
throw new Error("baseUrl is required");
|
|
13
|
+
}
|
|
14
|
+
const baseURL = port ? `${baseUrl}:${port}` : baseUrl;
|
|
15
|
+
this.axiosInstance = axios.create({
|
|
16
|
+
baseURL,
|
|
17
|
+
timeout,
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
Authorization: `Bearer client.sdk.${clientId}.${UnmeshedCommonUtils.createSecureHash(authToken)}`,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
validateInstance() {
|
|
25
|
+
if (!this.axiosInstance) {
|
|
26
|
+
throw new Error("ApiClient must be initialized before making requests");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async handleRequest({ method, endpoint, params, data, config, }) {
|
|
30
|
+
this.validateInstance();
|
|
31
|
+
try {
|
|
32
|
+
// Assert that axiosInstance exists before using it
|
|
33
|
+
if (!this.axiosInstance) {
|
|
34
|
+
throw new Error("Axios instance is not initialized");
|
|
35
|
+
}
|
|
36
|
+
const response = await this.axiosInstance.request({
|
|
37
|
+
method,
|
|
38
|
+
url: endpoint,
|
|
39
|
+
params,
|
|
40
|
+
data,
|
|
41
|
+
...config,
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
data: response.data,
|
|
45
|
+
status: response.status,
|
|
46
|
+
headers: response.headers,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (axios.isAxiosError(error)) {
|
|
51
|
+
console.error("Request failed:", error.message);
|
|
52
|
+
throw this.handleError(error);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
console.error("Unexpected error:", error.message);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
handleError(error) {
|
|
61
|
+
console.error("Error details:", {
|
|
62
|
+
message: error.message,
|
|
63
|
+
status: error.response?.status,
|
|
64
|
+
data: error.response?.data,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async get(endpoint, params, config) {
|
|
68
|
+
return this.handleRequest({
|
|
69
|
+
method: "get",
|
|
70
|
+
endpoint: endpoint,
|
|
71
|
+
params: params,
|
|
72
|
+
config: config,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async post(endpoint, clientRequestConfig) {
|
|
76
|
+
return this.handleRequest({
|
|
77
|
+
method: "post",
|
|
78
|
+
endpoint: endpoint,
|
|
79
|
+
...clientRequestConfig,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async put(endpoint, clientRequestConfig) {
|
|
83
|
+
return this.handleRequest({
|
|
84
|
+
method: "put",
|
|
85
|
+
endpoint: endpoint,
|
|
86
|
+
...clientRequestConfig,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async delete(endpoint, clientRequestConfig) {
|
|
90
|
+
return this.handleRequest({
|
|
91
|
+
method: "delete",
|
|
92
|
+
endpoint: endpoint,
|
|
93
|
+
...clientRequestConfig,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getClientId() {
|
|
97
|
+
return this.clientId;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ApiClient } from "./apiClient";
|
|
2
|
+
import pollForWorkers from "./poller/pollerClientImpl";
|
|
3
|
+
import { ApiCallType, ApiClientConfig, ProcessRequestData, ProcessSearchRequest } from "./types";
|
|
4
|
+
export declare const apiClient: ApiClient;
|
|
5
|
+
declare const UnmeshedClient: {
|
|
6
|
+
initialize: (config: ApiClientConfig) => void;
|
|
7
|
+
runProcessSync: (ProcessRequestData: ProcessRequestData) => Promise<import("./types").ProcessData>;
|
|
8
|
+
runProcessAsync: (ProcessRequestData: ProcessRequestData) => Promise<import("./types").ProcessData>;
|
|
9
|
+
getProcessData: (processId: number) => Promise<import("./types").ProcessData>;
|
|
10
|
+
getStepData: (stepId: number | null) => Promise<import("./types").StepData>;
|
|
11
|
+
bulkTerminate: (processIds: number[], reason?: string) => Promise<import("./types").ProcessActionResponseData>;
|
|
12
|
+
bulkResume: (processIds: number[]) => Promise<import("./types").ProcessActionResponseData>;
|
|
13
|
+
bulkReviewed: (processIds: number[], reason?: string) => Promise<import("./types").ProcessActionResponseData>;
|
|
14
|
+
rerun: (processId: number, clientId: string, version?: number) => Promise<import("./types").ProcessData>;
|
|
15
|
+
searchProcessExecutions: (params: ProcessSearchRequest) => Promise<any>;
|
|
16
|
+
invokeApiMappingGet: (endpoint: string, id: string, correlationId: string, apiCallType: ApiCallType) => Promise<any>;
|
|
17
|
+
invokeApiMappingPost: (endpoint: string, input: Record<string, any>, id: string, correlationId: string, apiCallType?: ApiCallType) => Promise<any>;
|
|
18
|
+
renewRegistration: () => Promise<string>;
|
|
19
|
+
pollForWorkers: typeof pollForWorkers;
|
|
20
|
+
};
|
|
21
|
+
export default UnmeshedClient;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ApiClient } from "./apiClient";
|
|
2
|
+
import pollForWorkers from "./poller/pollerClientImpl";
|
|
3
|
+
import { bulkResume, bulkReviewed, bulkTerminate, getProcessData, getStepData, invokeApiMappingGet, invokeApiMappingPost, rerun, runProcessAsync, runProcessSync, searchProcessExecutions, } from "./process/processClientImpl";
|
|
4
|
+
import { renewRegistration } from "./registration/registrationClientImpl";
|
|
5
|
+
export const apiClient = new ApiClient();
|
|
6
|
+
const UnmeshedClient = {
|
|
7
|
+
initialize: (config) => apiClient.initialize(config),
|
|
8
|
+
runProcessSync,
|
|
9
|
+
runProcessAsync,
|
|
10
|
+
getProcessData,
|
|
11
|
+
getStepData,
|
|
12
|
+
bulkTerminate,
|
|
13
|
+
bulkResume,
|
|
14
|
+
bulkReviewed,
|
|
15
|
+
rerun,
|
|
16
|
+
searchProcessExecutions,
|
|
17
|
+
invokeApiMappingGet,
|
|
18
|
+
invokeApiMappingPost,
|
|
19
|
+
renewRegistration,
|
|
20
|
+
pollForWorkers,
|
|
21
|
+
};
|
|
22
|
+
export default UnmeshedClient;
|