@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.
Files changed (36) hide show
  1. package/dist/apiClient.js +7 -12
  2. package/dist/index.d.ts +8 -8
  3. package/dist/index.js +20 -23
  4. package/dist/poller/pollerClientImpl.js +10 -13
  5. package/dist/process/processClientImpl.js +27 -42
  6. package/dist/registration/registrationClientImpl.js +3 -7
  7. package/dist/sample/server.d.ts +1 -0
  8. package/dist/sample/server.js +9 -0
  9. package/dist/src/apiClient.d.ts +14 -0
  10. package/dist/src/apiClient.js +99 -0
  11. package/dist/src/index.d.ts +21 -0
  12. package/dist/src/index.js +22 -0
  13. package/dist/src/poller/pollerClientImpl.d.ts +2 -0
  14. package/dist/src/poller/pollerClientImpl.js +126 -0
  15. package/dist/src/process/processClientImpl.d.ts +12 -0
  16. package/dist/src/process/processClientImpl.js +187 -0
  17. package/dist/src/registration/registrationClientImpl.d.ts +1 -0
  18. package/dist/src/registration/registrationClientImpl.js +17 -0
  19. package/dist/src/sample/server.d.ts +1 -0
  20. package/dist/src/sample/server.js +9 -0
  21. package/dist/src/types/index.d.ts +313 -0
  22. package/dist/src/types/index.js +77 -0
  23. package/dist/src/utils/unmeshedCommonUtils.d.ts +3 -0
  24. package/dist/src/utils/unmeshedCommonUtils.js +13 -0
  25. package/dist/tsconfig.tsbuildinfo +1 -0
  26. package/dist/types/index.js +16 -19
  27. package/dist/utils/unmeshedCommonUtils.js +3 -7
  28. package/package.json +2 -1
  29. package/dist/sample/sampleServer.d.ts +0 -1
  30. package/dist/sample/sampleServer.js +0 -76
  31. package/dist/sample/workers/ArithmeticWorker.d.ts +0 -5
  32. package/dist/sample/workers/ArithmeticWorker.js +0 -23
  33. package/dist/sample/workers/DelayedWorker.d.ts +0 -1
  34. package/dist/sample/workers/DelayedWorker.js +0 -11
  35. package/dist/server.d.ts +0 -1
  36. package/dist/server.js +0 -62
package/dist/apiClient.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiClient = void 0;
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 = axios_1.default.create({
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}.${unmeshedCommonUtils_1.UnmeshedCommonUtils.createSecureHash(authToken)}`,
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: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
58
- data: (_b = error.response) === null || _b === void 0 ? void 0 : _b.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<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>;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.apiClient = void 0;
4
- const apiClient_1 = require("./apiClient");
5
- const pollerClientImpl_1 = require("./poller/pollerClientImpl");
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) => exports.apiClient.initialize(config),
11
- runProcessSync: processClientImpl_1.runProcessSync,
12
- runProcessAsync: processClientImpl_1.runProcessAsync,
13
- getProcessData: processClientImpl_1.getProcessData,
14
- getStepData: processClientImpl_1.getStepData,
15
- bulkTerminate: processClientImpl_1.bulkTerminate,
16
- bulkResume: processClientImpl_1.bulkResume,
17
- bulkReviewed: processClientImpl_1.bulkReviewed,
18
- rerun: processClientImpl_1.rerun,
19
- searchProcessExecutions: processClientImpl_1.searchProcessExecutions,
20
- invokeApiMappingGet: processClientImpl_1.invokeApiMappingGet,
21
- invokeApiMappingPost: processClientImpl_1.invokeApiMappingPost,
22
- renewRegistration: registrationClientImpl_1.renewRegistration,
23
- pollForWorkers: pollerClientImpl_1.default,
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
- exports.default = UnmeshedClient;
22
+ export default UnmeshedClient;
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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 __1.apiClient.put("/api/clients/register", {
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 __1.apiClient.post("/api/clients/poll", {
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 __1.apiClient.post("/api/clients/bulkResults", {
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: types_1.StepStatus.RUNNING,
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: types_1.StepStatus.COMPLETED,
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: types_1.StepStatus.TIMED_OUT,
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: types_1.StepStatus.FAILED,
113
+ status: StepStatus.FAILED,
117
114
  };
118
115
  console.error("Error:", error.message);
119
116
  }
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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 __1.apiClient.post(RUN_PROCESS_REQUEST_URL + "runSync", {
6
+ const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "runSync", {
10
7
  data: ProcessRequestData,
11
8
  params: {
12
- clientId: __1.apiClient.getClientId(),
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
- exports.runProcessSync = runProcessSync;
24
- const runProcessAsync = async (ProcessRequestData) => {
20
+ export const runProcessAsync = async (ProcessRequestData) => {
25
21
  try {
26
- const response = await __1.apiClient.post(RUN_PROCESS_REQUEST_URL + "runAsync", {
22
+ const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "runAsync", {
27
23
  data: ProcessRequestData,
28
24
  params: {
29
- clientId: __1.apiClient.getClientId(),
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
- exports.runProcessAsync = runProcessAsync;
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 __1.apiClient.get(RUN_PROCESS_REQUEST_URL + "context/" + processId);
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
- exports.getProcessData = getProcessData;
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 __1.apiClient.get(RUN_PROCESS_REQUEST_URL + "stepContext/" + stepId);
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
- exports.getStepData = getStepData;
68
- const bulkTerminate = async (processIds, reason) => {
61
+ export const bulkTerminate = async (processIds, reason) => {
69
62
  try {
70
- const response = await __1.apiClient.post(RUN_PROCESS_REQUEST_URL + "bulkTerminate", {
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
- exports.bulkTerminate = bulkTerminate;
81
- const bulkResume = async (processIds) => {
73
+ export const bulkResume = async (processIds) => {
82
74
  try {
83
- const response = await __1.apiClient.post(RUN_PROCESS_REQUEST_URL + "bulkResume", {
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
- exports.bulkResume = bulkResume;
93
- const bulkReviewed = async (processIds, reason) => {
84
+ export const bulkReviewed = async (processIds, reason) => {
94
85
  try {
95
- const response = await __1.apiClient.post(RUN_PROCESS_REQUEST_URL + "bulkReviewed", {
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
- exports.bulkReviewed = bulkReviewed;
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 __1.apiClient.post(RUN_PROCESS_REQUEST_URL + "rerun", {
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: ${(_a = error.response) === null || _a === void 0 ? void 0 : _a.status} - ${(_b = error.response) === null || _b === void 0 ? void 0 : _b.data}`);
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
- exports.rerun = rerun;
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 __1.apiClient.get(RUN_PROCESS_REQUEST_URL + "api/stats/process/search", updatedParams);
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
- exports.searchProcessExecutions = searchProcessExecutions;
163
- const invokeApiMappingGet = async (endpoint, id, correlationId, apiCallType) => {
150
+ export const invokeApiMappingGet = async (endpoint, id, correlationId, apiCallType) => {
164
151
  try {
165
- const response = await __1.apiClient.get(RUN_PROCESS_REQUEST_URL + "api/call/" + endpoint, {
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
- exports.invokeApiMappingGet = invokeApiMappingGet;
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 __1.apiClient.post(RUN_PROCESS_REQUEST_URL + "api/call/" + endpoint, {
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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 __1.apiClient.put("/api/clients/register", {
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;
@@ -0,0 +1,2 @@
1
+ import { UnmeshedWorkerConfig } from "../types";
2
+ export default function pollForWorkers(workers: UnmeshedWorkerConfig[]): Promise<void>;