@unmeshed/sdk 1.0.9 → 1.0.11
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/.idea/modules.xml +8 -0
- package/.idea/unmeshed-javascript-sdk.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/p.json +25 -0
- package/package.json +11 -12
- package/src/apiClient.ts +142 -0
- package/src/index.ts +43 -0
- package/src/poller/pollerClientImpl.ts +150 -0
- package/src/process/processClientImpl.ts +267 -0
- package/src/registration/registrationClientImpl.ts +17 -0
- package/src/sampleTest.ts +86 -0
- package/src/types/index.ts +349 -0
- package/src/utils/unmeshedCommonUtils.ts +13 -0
- package/tsconfig.json +29 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/apiClient.d.ts +0 -14
- package/dist/apiClient.js +0 -89
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -22
- package/dist/poller/pollerClientImpl.d.ts +0 -2
- package/dist/poller/pollerClientImpl.js +0 -122
- package/dist/process/processClientImpl.d.ts +0 -12
- package/dist/process/processClientImpl.js +0 -181
- package/dist/registration/registrationClientImpl.d.ts +0 -1
- package/dist/registration/registrationClientImpl.js +0 -17
- package/dist/sample/sampleAPI.d.ts +0 -2
- package/dist/sample/sampleAPI.js +0 -29
- package/dist/sample/server.d.ts +0 -1
- package/dist/sample/server.js +0 -9
- package/dist/src/apiClient.d.ts +0 -14
- package/dist/src/apiClient.js +0 -99
- package/dist/src/index.d.ts +0 -21
- package/dist/src/index.js +0 -22
- package/dist/src/poller/pollerClientImpl.d.ts +0 -2
- package/dist/src/poller/pollerClientImpl.js +0 -126
- package/dist/src/process/processClientImpl.d.ts +0 -12
- package/dist/src/process/processClientImpl.js +0 -187
- package/dist/src/registration/registrationClientImpl.d.ts +0 -1
- package/dist/src/registration/registrationClientImpl.js +0 -17
- package/dist/src/sample/server.d.ts +0 -1
- package/dist/src/sample/server.js +0 -9
- package/dist/src/types/index.d.ts +0 -313
- package/dist/src/types/index.js +0 -77
- package/dist/src/utils/unmeshedCommonUtils.d.ts +0 -3
- package/dist/src/utils/unmeshedCommonUtils.js +0 -13
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/index.d.ts +0 -313
- package/dist/types/index.js +0 -77
- package/dist/types/unmeshedCommonUtils.d.ts +0 -3
- package/dist/types/unmeshedCommonUtils.js +0 -17
- package/dist/utils/unmeshedCommonUtils.d.ts +0 -3
- package/dist/utils/unmeshedCommonUtils.js +0 -13
package/dist/apiClient.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { UnmeshedCommonUtils } from "./utils/unmeshedCommonUtils";
|
|
3
|
-
export class ApiClient {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.axiosInstance = null;
|
|
6
|
-
this.clientId = null;
|
|
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
|
-
const response = await this.axiosInstance.request({
|
|
33
|
-
method,
|
|
34
|
-
url: endpoint,
|
|
35
|
-
params,
|
|
36
|
-
data,
|
|
37
|
-
...config,
|
|
38
|
-
});
|
|
39
|
-
return {
|
|
40
|
-
data: response.data,
|
|
41
|
-
status: response.status,
|
|
42
|
-
headers: response.headers,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error("Request failed:", error.message);
|
|
47
|
-
throw this.handleError(error);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
handleError(error) {
|
|
51
|
-
console.error("Error details:", {
|
|
52
|
-
message: error.message,
|
|
53
|
-
status: error.response?.status,
|
|
54
|
-
data: error.response?.data,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
async get(endpoint, params, config) {
|
|
58
|
-
return this.handleRequest({
|
|
59
|
-
method: "get",
|
|
60
|
-
endpoint: endpoint,
|
|
61
|
-
params: params,
|
|
62
|
-
config: config,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
async post(endpoint, clientRequestConfig) {
|
|
66
|
-
return this.handleRequest({
|
|
67
|
-
method: "post",
|
|
68
|
-
endpoint: endpoint,
|
|
69
|
-
...clientRequestConfig,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
async put(endpoint, clientRequestConfig) {
|
|
73
|
-
return this.handleRequest({
|
|
74
|
-
method: "put",
|
|
75
|
-
endpoint: endpoint,
|
|
76
|
-
...clientRequestConfig,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async delete(endpoint, clientRequestConfig) {
|
|
80
|
-
return this.handleRequest({
|
|
81
|
-
method: "delete",
|
|
82
|
-
endpoint: endpoint,
|
|
83
|
-
...clientRequestConfig,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
getClientId() {
|
|
87
|
-
return this.clientId;
|
|
88
|
-
}
|
|
89
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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<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
|
-
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;
|
package/dist/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { apiClient } from "..";
|
|
2
|
-
import { StepStatus, } from "../types";
|
|
3
|
-
async function registerPolling(data) {
|
|
4
|
-
const attempt = async () => {
|
|
5
|
-
try {
|
|
6
|
-
const response = await apiClient.put("/api/clients/register", {
|
|
7
|
-
data: data,
|
|
8
|
-
});
|
|
9
|
-
console.log("Successfully executed polling registration...");
|
|
10
|
-
return response.data;
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
console.error("An error occurred during polling registration. Retrying in 3 seconds...");
|
|
14
|
-
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
15
|
-
return attempt();
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
return attempt();
|
|
19
|
-
}
|
|
20
|
-
async function pollWorker(data) {
|
|
21
|
-
try {
|
|
22
|
-
const response = await apiClient.post("/api/clients/poll", {
|
|
23
|
-
data: data,
|
|
24
|
-
});
|
|
25
|
-
console.log("Succesfully executed worker polling...");
|
|
26
|
-
return response.data;
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error("Error occurred during worker polling", error);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async function pollWorkerResult(data) {
|
|
33
|
-
try {
|
|
34
|
-
const response = await apiClient.post("/api/clients/bulkResults", {
|
|
35
|
-
data: data,
|
|
36
|
-
});
|
|
37
|
-
console.log("Worker Result returned successfully...");
|
|
38
|
-
return response.data;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.log("Error:", error);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export default async function pollForWorkers(workers) {
|
|
45
|
-
const registerPollingData = workers.map((worker) => {
|
|
46
|
-
return {
|
|
47
|
-
orgId: 0,
|
|
48
|
-
namespace: worker.namespace,
|
|
49
|
-
stepType: "WORKER",
|
|
50
|
-
name: worker.name,
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
await registerPolling(registerPollingData);
|
|
54
|
-
const pollWorkerData = workers.map((worker) => {
|
|
55
|
-
return {
|
|
56
|
-
stepQueueNameData: {
|
|
57
|
-
orgId: 0,
|
|
58
|
-
namespace: worker.namespace,
|
|
59
|
-
stepType: "WORKER",
|
|
60
|
-
name: worker.name,
|
|
61
|
-
},
|
|
62
|
-
size: worker.maxInProgress,
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
const pollResponse = await pollWorker(pollWorkerData);
|
|
66
|
-
const workerResult = await Promise.all(pollResponse.map(async (polledWorker) => {
|
|
67
|
-
const associatedWorker = workers.find((worker) => worker.name === polledWorker.stepName &&
|
|
68
|
-
worker.namespace === polledWorker.stepNamespace);
|
|
69
|
-
let workerResponse = {
|
|
70
|
-
processId: polledWorker.processId,
|
|
71
|
-
stepId: polledWorker.stepId,
|
|
72
|
-
stepExecutionId: polledWorker.stepExecutionId,
|
|
73
|
-
runCount: polledWorker.runCount,
|
|
74
|
-
output: {},
|
|
75
|
-
status: StepStatus.RUNNING,
|
|
76
|
-
rescheduleAfterSeconds: null,
|
|
77
|
-
startedAt: new Date().getTime(),
|
|
78
|
-
};
|
|
79
|
-
const TIMEOUT = 1000;
|
|
80
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
81
|
-
setTimeout(() => reject(new Error("Timed out")), TIMEOUT);
|
|
82
|
-
});
|
|
83
|
-
try {
|
|
84
|
-
const result = await Promise.race([
|
|
85
|
-
associatedWorker.worker(polledWorker.inputParam),
|
|
86
|
-
timeoutPromise,
|
|
87
|
-
]);
|
|
88
|
-
workerResponse = {
|
|
89
|
-
...workerResponse,
|
|
90
|
-
output: {
|
|
91
|
-
...result,
|
|
92
|
-
__workCompletedAt: new Date().getTime(),
|
|
93
|
-
},
|
|
94
|
-
status: StepStatus.COMPLETED,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
if (error.message === "Timed out") {
|
|
99
|
-
workerResponse = {
|
|
100
|
-
...workerResponse,
|
|
101
|
-
output: {
|
|
102
|
-
error: error.message,
|
|
103
|
-
},
|
|
104
|
-
status: StepStatus.TIMED_OUT,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
workerResponse = {
|
|
109
|
-
...workerResponse,
|
|
110
|
-
output: {
|
|
111
|
-
error: error.message,
|
|
112
|
-
},
|
|
113
|
-
status: StepStatus.FAILED,
|
|
114
|
-
};
|
|
115
|
-
console.error("Error:", error.message);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return workerResponse;
|
|
119
|
-
}));
|
|
120
|
-
const workerResultResponse = await pollWorkerResult(workerResult);
|
|
121
|
-
console.log("Worker result : ", workerResultResponse);
|
|
122
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ApiCallType, ProcessSearchRequest, ProcessActionResponseData, ProcessData, ProcessRequestData, StepData } from "../types";
|
|
2
|
-
export declare const runProcessSync: (ProcessRequestData: ProcessRequestData) => Promise<ProcessData>;
|
|
3
|
-
export declare const runProcessAsync: (ProcessRequestData: ProcessRequestData) => Promise<ProcessData>;
|
|
4
|
-
export declare const getProcessData: (processId: number) => Promise<ProcessData>;
|
|
5
|
-
export declare const getStepData: (stepId: number | null) => Promise<StepData>;
|
|
6
|
-
export declare const bulkTerminate: (processIds: number[], reason?: string) => Promise<ProcessActionResponseData>;
|
|
7
|
-
export declare const bulkResume: (processIds: number[]) => Promise<ProcessActionResponseData>;
|
|
8
|
-
export declare const bulkReviewed: (processIds: number[], reason?: string) => Promise<ProcessActionResponseData>;
|
|
9
|
-
export declare const rerun: (processId: number, clientId: string, version?: number) => Promise<ProcessData>;
|
|
10
|
-
export declare const searchProcessExecutions: (params: ProcessSearchRequest) => Promise<any>;
|
|
11
|
-
export declare const invokeApiMappingGet: (endpoint: string, id: string, correlationId: string, apiCallType: ApiCallType) => Promise<any>;
|
|
12
|
-
export declare const invokeApiMappingPost: (endpoint: string, input: Record<string, any>, id: string, correlationId: string, apiCallType?: ApiCallType) => Promise<any>;
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { apiClient } from "..";
|
|
2
|
-
import { ApiCallType, } from "../types";
|
|
3
|
-
const RUN_PROCESS_REQUEST_URL = "api/process/";
|
|
4
|
-
export const runProcessSync = async (ProcessRequestData) => {
|
|
5
|
-
try {
|
|
6
|
-
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "runSync", {
|
|
7
|
-
data: ProcessRequestData,
|
|
8
|
-
params: {
|
|
9
|
-
clientId: apiClient.getClientId(),
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
console.log("Response:", response);
|
|
13
|
-
return response.data;
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
console.error("Some error occurred running process request : ", error);
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
export const runProcessAsync = async (ProcessRequestData) => {
|
|
21
|
-
try {
|
|
22
|
-
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "runAsync", {
|
|
23
|
-
data: ProcessRequestData,
|
|
24
|
-
params: {
|
|
25
|
-
clientId: apiClient.getClientId(),
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
console.log("Response:", response);
|
|
29
|
-
return response.data;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.error("Some error occurred running process request : ", error);
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
export const getProcessData = async (processId) => {
|
|
37
|
-
if (processId == null) {
|
|
38
|
-
throw new Error("Process ID cannot be null");
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const response = await apiClient.get(RUN_PROCESS_REQUEST_URL + "context/" + processId);
|
|
42
|
-
return response.data;
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
console.error("Error occurred while fetching process record: ", error);
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
export const getStepData = async (stepId) => {
|
|
50
|
-
if (stepId === null || stepId === undefined) {
|
|
51
|
-
throw new Error("Step ID cannot be null or undefined");
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
const response = await apiClient.get(RUN_PROCESS_REQUEST_URL + "stepContext/" + stepId);
|
|
55
|
-
return response.data;
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
throw new Error(`Error occurred while fetching step record: ${error.message || error}`);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
export const bulkTerminate = async (processIds, reason) => {
|
|
62
|
-
try {
|
|
63
|
-
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "bulkTerminate", {
|
|
64
|
-
params: { reason },
|
|
65
|
-
data: processIds,
|
|
66
|
-
});
|
|
67
|
-
return response.data;
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
throw new Error(`Error occurred while terminating processes: ${error.message || error}`);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
export const bulkResume = async (processIds) => {
|
|
74
|
-
try {
|
|
75
|
-
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "bulkResume", {
|
|
76
|
-
data: processIds,
|
|
77
|
-
});
|
|
78
|
-
return response.data;
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
throw new Error(`Error occurred while resuming processes: ${error.message || error}`);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
export const bulkReviewed = async (processIds, reason) => {
|
|
85
|
-
try {
|
|
86
|
-
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "bulkReviewed", {
|
|
87
|
-
data: processIds,
|
|
88
|
-
params: { reason },
|
|
89
|
-
});
|
|
90
|
-
return response.data;
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
throw new Error(`Error occurred while marking processes as reviewed: ${error.message || error}`);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
export const rerun = async (processId, clientId, version) => {
|
|
97
|
-
const params = {
|
|
98
|
-
clientId,
|
|
99
|
-
processId,
|
|
100
|
-
};
|
|
101
|
-
if (version !== undefined) {
|
|
102
|
-
params["version"] = version;
|
|
103
|
-
}
|
|
104
|
-
try {
|
|
105
|
-
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "rerun", {
|
|
106
|
-
params,
|
|
107
|
-
});
|
|
108
|
-
return response.data;
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
if (error.isAxiosError) {
|
|
112
|
-
throw new Error(`HTTP request error during rerun process: ${error.response?.status} - ${error.response?.data}`);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
throw new Error(`Unexpected error during rerun process: ${error.message}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
export const searchProcessExecutions = async (params) => {
|
|
120
|
-
const queryParams = new URLSearchParams();
|
|
121
|
-
if (params.startTimeEpoch !== undefined && params.startTimeEpoch !== 0)
|
|
122
|
-
queryParams.set("startTimeEpoch", params.startTimeEpoch.toString());
|
|
123
|
-
if (params.endTimeEpoch !== undefined && params.endTimeEpoch !== 0)
|
|
124
|
-
queryParams.set("endTimeEpoch", params.endTimeEpoch.toString());
|
|
125
|
-
if (params.namespace)
|
|
126
|
-
queryParams.set("namespace", params.namespace);
|
|
127
|
-
if (params.names && params.names.length)
|
|
128
|
-
queryParams.set("names", params.names.join(","));
|
|
129
|
-
if (params.processIds && params.processIds.length)
|
|
130
|
-
queryParams.set("processIds", params.processIds.join(","));
|
|
131
|
-
if (params.correlationIds && params.correlationIds.length)
|
|
132
|
-
queryParams.set("correlationIds", params.correlationIds.join(","));
|
|
133
|
-
if (params.requestIds && params.requestIds.length)
|
|
134
|
-
queryParams.set("requestIds", params.requestIds.join(","));
|
|
135
|
-
if (params.statuses && params.statuses.length)
|
|
136
|
-
queryParams.set("statuses", params.statuses.join(","));
|
|
137
|
-
if (params.triggerTypes && params.triggerTypes.length)
|
|
138
|
-
queryParams.set("triggerTypes", params.triggerTypes.join(","));
|
|
139
|
-
const updatedParams = Object.fromEntries(new URLSearchParams(queryParams));
|
|
140
|
-
try {
|
|
141
|
-
const response = await apiClient.get(RUN_PROCESS_REQUEST_URL + "api/stats/process/search", updatedParams);
|
|
142
|
-
console.log("Response:", response);
|
|
143
|
-
return response.data;
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
console.error("Error occurred while searching process executions: ", error);
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
export const invokeApiMappingGet = async (endpoint, id, correlationId, apiCallType) => {
|
|
151
|
-
try {
|
|
152
|
-
const response = await apiClient.get(RUN_PROCESS_REQUEST_URL + "api/call/" + endpoint, {
|
|
153
|
-
id: id,
|
|
154
|
-
correlationId: correlationId,
|
|
155
|
-
apiCallType,
|
|
156
|
-
});
|
|
157
|
-
console.log("Response:", response);
|
|
158
|
-
return response.data;
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
console.error("Error occurred while invoking API Mapping GET: ", error);
|
|
162
|
-
throw error;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
export const invokeApiMappingPost = async (endpoint, input, id, correlationId, apiCallType = ApiCallType.ASYNC) => {
|
|
166
|
-
try {
|
|
167
|
-
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "api/call/" + endpoint, {
|
|
168
|
-
data: input,
|
|
169
|
-
params: {
|
|
170
|
-
id: id,
|
|
171
|
-
correlationId: correlationId,
|
|
172
|
-
apiCallType,
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
return response.data;
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
console.error("Error occurred while invoking API Mapping POST: ", error);
|
|
179
|
-
throw error;
|
|
180
|
-
}
|
|
181
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const renewRegistration: () => Promise<string>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { apiClient } from "..";
|
|
2
|
-
export const renewRegistration = async () => {
|
|
3
|
-
try {
|
|
4
|
-
const response = await apiClient.put("/api/clients/register", {
|
|
5
|
-
params: {
|
|
6
|
-
friendlyName: "Unmeshed",
|
|
7
|
-
tokenExpiryDate: "",
|
|
8
|
-
},
|
|
9
|
-
});
|
|
10
|
-
console.debug("Response from server:", response);
|
|
11
|
-
return response.data;
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
console.error("Error occurred during registration renewal:", error);
|
|
15
|
-
throw error;
|
|
16
|
-
}
|
|
17
|
-
};
|
package/dist/sample/sampleAPI.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.postApi = exports.getApi = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const getApi = async () => {
|
|
6
|
-
try {
|
|
7
|
-
const response = await __1.apiClient.get("/api/schedules", {
|
|
8
|
-
name: "test_name",
|
|
9
|
-
});
|
|
10
|
-
console.log("Response:", response);
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
console.error("Error occurred:", error);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
exports.getApi = getApi;
|
|
17
|
-
const postApi = async () => {
|
|
18
|
-
try {
|
|
19
|
-
const response = await __1.apiClient.post("/api/test/post", {
|
|
20
|
-
data: { name: "test_name" },
|
|
21
|
-
});
|
|
22
|
-
console.log("Response:", response);
|
|
23
|
-
return response;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
console.error("Error occurred:", error);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
exports.postApi = postApi;
|
package/dist/sample/server.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/sample/server.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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)));
|
package/dist/src/apiClient.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/src/apiClient.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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;
|