@unmeshed/sdk 1.0.13 → 1.0.15
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/index.d.mts +370 -0
- package/{types → dist}/index.d.ts +95 -38
- package/dist/index.js +842 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +797 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -14
- package/apiClient.d.ts +0 -14
- package/apiClient.js +0 -106
- package/apiClient.js.map +0 -1
- package/index.d.ts +0 -21
- package/index.js +0 -29
- package/index.js.map +0 -1
- package/poller/pollerClientImpl.d.ts +0 -2
- package/poller/pollerClientImpl.js +0 -130
- package/poller/pollerClientImpl.js.map +0 -1
- package/process/processClientImpl.d.ts +0 -12
- package/process/processClientImpl.js +0 -202
- package/process/processClientImpl.js.map +0 -1
- package/registration/registrationClientImpl.d.ts +0 -1
- package/registration/registrationClientImpl.js +0 -22
- package/registration/registrationClientImpl.js.map +0 -1
- package/sampleTest.d.ts +0 -1
- package/sampleTest.js +0 -82
- package/sampleTest.js.map +0 -1
- package/types/index.js +0 -81
- package/types/index.js.map +0 -1
- package/utils/unmeshedCommonUtils.d.ts +0 -3
- package/utils/unmeshedCommonUtils.js +0 -18
- package/utils/unmeshedCommonUtils.js.map +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
// src/apis/unmeshedApiClient.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
|
|
4
|
+
// src/utils/unmeshedCommonUtils.ts
|
|
5
|
+
import { createHash } from "crypto";
|
|
6
|
+
var UnmeshedCommonUtils = class {
|
|
7
|
+
static createSecureHash(input) {
|
|
8
|
+
try {
|
|
9
|
+
const hash = createHash("sha256");
|
|
10
|
+
hash.update(input, "utf8");
|
|
11
|
+
return hash.digest("hex");
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw new Error("Error creating hash");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/apis/unmeshedApiClient.ts
|
|
19
|
+
var UnmeshedApiClient = class {
|
|
20
|
+
axiosInstance = null;
|
|
21
|
+
clientId = void 0;
|
|
22
|
+
_config;
|
|
23
|
+
constructor(unmeshedClientConfig) {
|
|
24
|
+
console.log("Initializing Unmeshed ApiClient");
|
|
25
|
+
this._config = createUnmeshedClientConfig(unmeshedClientConfig);
|
|
26
|
+
console.log(this._config);
|
|
27
|
+
this.clientId = this._config.clientId;
|
|
28
|
+
if (!this._config.baseUrl) {
|
|
29
|
+
throw new Error("baseUrl is required");
|
|
30
|
+
}
|
|
31
|
+
const baseURL = this._config.port ? `${this._config.baseUrl}:${this._config.port}` : this._config.baseUrl;
|
|
32
|
+
this.axiosInstance = axios.create({
|
|
33
|
+
baseURL,
|
|
34
|
+
timeout: this._config.timeout,
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
Authorization: `Bearer client.sdk.${this._config.clientId}.${UnmeshedCommonUtils.createSecureHash(
|
|
38
|
+
this._config.authToken
|
|
39
|
+
)}`
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async handleRequest({
|
|
44
|
+
method,
|
|
45
|
+
endpoint,
|
|
46
|
+
params,
|
|
47
|
+
data,
|
|
48
|
+
config
|
|
49
|
+
}) {
|
|
50
|
+
if (!this.axiosInstance) {
|
|
51
|
+
throw new Error("ApiClient must be initialized before making requests");
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const response = await this.axiosInstance.request({
|
|
55
|
+
method,
|
|
56
|
+
url: endpoint,
|
|
57
|
+
params,
|
|
58
|
+
data,
|
|
59
|
+
...config
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
data: response.data,
|
|
63
|
+
status: response.status,
|
|
64
|
+
headers: response.headers
|
|
65
|
+
};
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (axios.isAxiosError(error)) {
|
|
68
|
+
console.error("Request failed:", error.message);
|
|
69
|
+
throw this.handleError(error);
|
|
70
|
+
}
|
|
71
|
+
console.error("Unexpected error:", error.message);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
handleError(error) {
|
|
76
|
+
console.error("Error details:", {
|
|
77
|
+
message: error.message,
|
|
78
|
+
status: error.response?.status,
|
|
79
|
+
data: error.response?.data
|
|
80
|
+
});
|
|
81
|
+
let response = error?.response?.data;
|
|
82
|
+
if (response?.errorMessage) {
|
|
83
|
+
return new Error(`${response.errorMessage} [Status code: ${error.response?.status || ""}]`);
|
|
84
|
+
}
|
|
85
|
+
return new Error(error.message, { cause: error.response?.data || {} });
|
|
86
|
+
}
|
|
87
|
+
async get(endpoint, params, config) {
|
|
88
|
+
return this.handleRequest({
|
|
89
|
+
method: "get",
|
|
90
|
+
endpoint,
|
|
91
|
+
params,
|
|
92
|
+
config
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async post(endpoint, clientRequestConfig) {
|
|
96
|
+
return this.handleRequest({
|
|
97
|
+
method: "post",
|
|
98
|
+
endpoint,
|
|
99
|
+
...clientRequestConfig
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async put(endpoint, clientRequestConfig) {
|
|
103
|
+
return this.handleRequest({
|
|
104
|
+
method: "put",
|
|
105
|
+
endpoint,
|
|
106
|
+
...clientRequestConfig
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async delete(endpoint, clientRequestConfig) {
|
|
110
|
+
return this.handleRequest({
|
|
111
|
+
method: "delete",
|
|
112
|
+
endpoint,
|
|
113
|
+
...clientRequestConfig
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
getClientId() {
|
|
117
|
+
return this.clientId;
|
|
118
|
+
}
|
|
119
|
+
get config() {
|
|
120
|
+
return this._config;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
function createUnmeshedClientConfig(config) {
|
|
124
|
+
return {
|
|
125
|
+
baseUrl: config.baseUrl,
|
|
126
|
+
clientId: config.clientId,
|
|
127
|
+
authToken: config.authToken,
|
|
128
|
+
port: config.port ?? 443,
|
|
129
|
+
timeout: config.timeout ?? 5e3,
|
|
130
|
+
pollInterval: config.pollInterval ?? 100,
|
|
131
|
+
apiWorkerTimeout: config.apiWorkerTimeout ?? 1e4,
|
|
132
|
+
pollTimeout: config.pollTimeout ?? 1e4,
|
|
133
|
+
responsePollInterval: config.responsePollInterval ?? 100,
|
|
134
|
+
responsePollTimeout: config.responsePollTimeout ?? 1e4,
|
|
135
|
+
responseBatchSize: config.responseBatchSize ?? 50
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/types/index.ts
|
|
140
|
+
var ApiCallType = /* @__PURE__ */ ((ApiCallType2) => {
|
|
141
|
+
ApiCallType2["SYNC"] = "SYNC";
|
|
142
|
+
ApiCallType2["ASYNC"] = "ASYNC";
|
|
143
|
+
ApiCallType2["STREAM"] = "STREAM";
|
|
144
|
+
return ApiCallType2;
|
|
145
|
+
})(ApiCallType || {});
|
|
146
|
+
var WebhookSource = /* @__PURE__ */ ((WebhookSource2) => {
|
|
147
|
+
WebhookSource2["MS_TEAMS"] = "MS_TEAMS";
|
|
148
|
+
WebhookSource2["NOT_DEFINED"] = "NOT_DEFINED";
|
|
149
|
+
return WebhookSource2;
|
|
150
|
+
})(WebhookSource || {});
|
|
151
|
+
var SQAuthUserType = /* @__PURE__ */ ((SQAuthUserType2) => {
|
|
152
|
+
SQAuthUserType2["USER"] = "USER";
|
|
153
|
+
SQAuthUserType2["API"] = "API";
|
|
154
|
+
SQAuthUserType2["INTERNAL"] = "INTERNAL";
|
|
155
|
+
return SQAuthUserType2;
|
|
156
|
+
})(SQAuthUserType || {});
|
|
157
|
+
var StepType = /* @__PURE__ */ ((StepType2) => {
|
|
158
|
+
StepType2["WORKER"] = "WORKER";
|
|
159
|
+
StepType2["HTTP"] = "HTTP";
|
|
160
|
+
StepType2["WAIT"] = "WAIT";
|
|
161
|
+
StepType2["FAIL"] = "FAIL";
|
|
162
|
+
StepType2["PYTHON"] = "PYTHON";
|
|
163
|
+
StepType2["JAVASCRIPT"] = "JAVASCRIPT";
|
|
164
|
+
StepType2["JQ"] = "JQ";
|
|
165
|
+
StepType2["MANAGED"] = "MANAGED";
|
|
166
|
+
StepType2["BUILTIN"] = "BUILTIN";
|
|
167
|
+
StepType2["NOOP"] = "NOOP";
|
|
168
|
+
StepType2["PERSISTED_STATE"] = "PERSISTED_STATE";
|
|
169
|
+
StepType2["DEPENDSON"] = "DEPENDSON";
|
|
170
|
+
StepType2["INTEGRATION"] = "INTEGRATION";
|
|
171
|
+
StepType2["EXIT"] = "EXIT";
|
|
172
|
+
StepType2["SUB_PROCESS"] = "SUB_PROCESS";
|
|
173
|
+
StepType2["LIST"] = "LIST";
|
|
174
|
+
StepType2["PARALLEL"] = "PARALLEL";
|
|
175
|
+
StepType2["FOREACH"] = "FOREACH";
|
|
176
|
+
StepType2["SWITCH"] = "SWITCH";
|
|
177
|
+
return StepType2;
|
|
178
|
+
})(StepType || {});
|
|
179
|
+
var StepStatus = /* @__PURE__ */ ((StepStatus2) => {
|
|
180
|
+
StepStatus2["PENDING"] = "PENDING";
|
|
181
|
+
StepStatus2["SCHEDULED"] = "SCHEDULED";
|
|
182
|
+
StepStatus2["RUNNING"] = "RUNNING";
|
|
183
|
+
StepStatus2["PAUSED"] = "PAUSED";
|
|
184
|
+
StepStatus2["COMPLETED"] = "COMPLETED";
|
|
185
|
+
StepStatus2["FAILED"] = "FAILED";
|
|
186
|
+
StepStatus2["TIMED_OUT"] = "TIMED_OUT";
|
|
187
|
+
StepStatus2["SKIPPED"] = "SKIPPED";
|
|
188
|
+
StepStatus2["CANCELLED"] = "CANCELLED";
|
|
189
|
+
return StepStatus2;
|
|
190
|
+
})(StepStatus || {});
|
|
191
|
+
var ProcessStatus = /* @__PURE__ */ ((ProcessStatus2) => {
|
|
192
|
+
ProcessStatus2["RUNNING"] = "RUNNING";
|
|
193
|
+
ProcessStatus2["COMPLETED"] = "COMPLETED";
|
|
194
|
+
ProcessStatus2["FAILED"] = "FAILED";
|
|
195
|
+
ProcessStatus2["TIMED_OUT"] = "TIMED_OUT";
|
|
196
|
+
ProcessStatus2["CANCELLED"] = "CANCELLED";
|
|
197
|
+
ProcessStatus2["TERMINATED"] = "TERMINATED";
|
|
198
|
+
ProcessStatus2["REVIEWED"] = "REVIEWED";
|
|
199
|
+
return ProcessStatus2;
|
|
200
|
+
})(ProcessStatus || {});
|
|
201
|
+
var ProcessTriggerType = /* @__PURE__ */ ((ProcessTriggerType2) => {
|
|
202
|
+
ProcessTriggerType2["MANUAL"] = "MANUAL";
|
|
203
|
+
ProcessTriggerType2["SCHEDULED"] = "SCHEDULED";
|
|
204
|
+
ProcessTriggerType2["API_MAPPING"] = "API_MAPPING";
|
|
205
|
+
ProcessTriggerType2["WEBHOOK"] = "WEBHOOK";
|
|
206
|
+
ProcessTriggerType2["API"] = "API";
|
|
207
|
+
ProcessTriggerType2["SUB_PROCESS"] = "SUB_PROCESS";
|
|
208
|
+
return ProcessTriggerType2;
|
|
209
|
+
})(ProcessTriggerType || {});
|
|
210
|
+
var ProcessType = /* @__PURE__ */ ((ProcessType2) => {
|
|
211
|
+
ProcessType2["STANDARD"] = "STANDARD";
|
|
212
|
+
ProcessType2["DYNAMIC"] = "DYNAMIC";
|
|
213
|
+
ProcessType2["API_ORCHESTRATION"] = "API_ORCHESTRATION";
|
|
214
|
+
ProcessType2["INTERNAL"] = "INTERNAL";
|
|
215
|
+
return ProcessType2;
|
|
216
|
+
})(ProcessType || {});
|
|
217
|
+
|
|
218
|
+
// src/apis/queuedWorker.ts
|
|
219
|
+
var QueuedWorker = class {
|
|
220
|
+
queue;
|
|
221
|
+
pollIntervalMs;
|
|
222
|
+
batchSize;
|
|
223
|
+
workerFn;
|
|
224
|
+
timeoutMs;
|
|
225
|
+
constructor(capacity, pollIntervalMs, batchSize, workerFn, timeoutMs) {
|
|
226
|
+
this.queue = new BlockingQueue(capacity);
|
|
227
|
+
this.pollIntervalMs = pollIntervalMs;
|
|
228
|
+
this.batchSize = batchSize;
|
|
229
|
+
this.workerFn = workerFn;
|
|
230
|
+
this.timeoutMs = timeoutMs;
|
|
231
|
+
console.log(`Configured queued worker with ${pollIntervalMs} ms interval and batch size of ${batchSize} and a timeout of ${timeoutMs} ms`);
|
|
232
|
+
this.start();
|
|
233
|
+
}
|
|
234
|
+
async start() {
|
|
235
|
+
let errorCount = 0;
|
|
236
|
+
while (true) {
|
|
237
|
+
try {
|
|
238
|
+
const batch = await this.queue.takeBatch(this.batchSize);
|
|
239
|
+
if (batch.length > 0) {
|
|
240
|
+
console.log(`Batch work ${batch.length} received`);
|
|
241
|
+
await this.runWithTimeout(this.workerFn(batch), this.timeoutMs);
|
|
242
|
+
}
|
|
243
|
+
} catch (error) {
|
|
244
|
+
errorCount++;
|
|
245
|
+
console.error(`Error processing batch - error count : ${errorCount} - `, error);
|
|
246
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
247
|
+
}
|
|
248
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollIntervalMs));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async runWithTimeout(task, timeoutMs) {
|
|
252
|
+
return new Promise((resolve, reject) => {
|
|
253
|
+
const timeout = setTimeout(() => reject(new Error("Task timed out")), timeoutMs);
|
|
254
|
+
task.then(() => {
|
|
255
|
+
clearTimeout(timeout);
|
|
256
|
+
resolve();
|
|
257
|
+
}).catch((error) => {
|
|
258
|
+
clearTimeout(timeout);
|
|
259
|
+
reject(error);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
async put(item) {
|
|
264
|
+
await this.queue.put(item);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
var BlockingQueue = class {
|
|
268
|
+
queue = [];
|
|
269
|
+
capacity;
|
|
270
|
+
constructor(capacity) {
|
|
271
|
+
if (capacity <= 0) {
|
|
272
|
+
throw new Error("Capacity must be greater than 0");
|
|
273
|
+
}
|
|
274
|
+
this.capacity = capacity;
|
|
275
|
+
}
|
|
276
|
+
async put(item) {
|
|
277
|
+
while (this.queue.length >= this.capacity) {
|
|
278
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
279
|
+
}
|
|
280
|
+
this.queue.push(item);
|
|
281
|
+
}
|
|
282
|
+
async takeBatch(batchSize) {
|
|
283
|
+
while (this.queue.length === 0) {
|
|
284
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
285
|
+
}
|
|
286
|
+
return this.queue.splice(0, batchSize);
|
|
287
|
+
}
|
|
288
|
+
size() {
|
|
289
|
+
return this.queue.length;
|
|
290
|
+
}
|
|
291
|
+
isEmpty() {
|
|
292
|
+
return this.queue.length === 0;
|
|
293
|
+
}
|
|
294
|
+
peek() {
|
|
295
|
+
return this.queue[0];
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/apis/pollerClientImpl.ts
|
|
300
|
+
async function registerPolling(apiClient, data) {
|
|
301
|
+
const attempt = async () => {
|
|
302
|
+
try {
|
|
303
|
+
const response = await apiClient.put("/api/clients/register", {
|
|
304
|
+
data
|
|
305
|
+
});
|
|
306
|
+
console.log("Successfully renewed registration for workers", data);
|
|
307
|
+
return response.data;
|
|
308
|
+
} catch {
|
|
309
|
+
console.error(
|
|
310
|
+
"An error occurred during polling registration. Retrying in 3 seconds..."
|
|
311
|
+
);
|
|
312
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
313
|
+
return attempt();
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
return attempt();
|
|
317
|
+
}
|
|
318
|
+
async function pollWorker(apiClient, data) {
|
|
319
|
+
try {
|
|
320
|
+
const response = await apiClient.post("/api/clients/poll", { data });
|
|
321
|
+
if (response.data && response.data.length > 0) {
|
|
322
|
+
console.log(`Received ${response.data.length} work requests`);
|
|
323
|
+
}
|
|
324
|
+
return response.data;
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error("Error occurred during worker polling", error);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
async function postWorkerResponse(apiClient, workResponses) {
|
|
330
|
+
try {
|
|
331
|
+
if (workResponses.length > 0) {
|
|
332
|
+
const grouped = workResponses.reduce((acc, response2) => {
|
|
333
|
+
if (!acc[response2.status]) {
|
|
334
|
+
acc[response2.status] = [];
|
|
335
|
+
}
|
|
336
|
+
acc[response2.status].push(response2.stepId);
|
|
337
|
+
return acc;
|
|
338
|
+
}, {});
|
|
339
|
+
const resultString = Object.entries(grouped).map(([status, stepIds]) => `${status}: [${stepIds.join(", ")}]`).join(", ");
|
|
340
|
+
console.log(`Posting response of size: ${workResponses.length} including ids: ${resultString}`);
|
|
341
|
+
const response = await apiClient.post("/api/clients/bulkResults", {
|
|
342
|
+
data: workResponses
|
|
343
|
+
});
|
|
344
|
+
return response.data;
|
|
345
|
+
}
|
|
346
|
+
return {};
|
|
347
|
+
} catch (error) {
|
|
348
|
+
console.log("Error:", error);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async function runPollWithTimeout(task, timeoutMs) {
|
|
352
|
+
return new Promise((resolve, reject) => {
|
|
353
|
+
const timeout = setTimeout(() => reject(new Error("Task timed out")), timeoutMs);
|
|
354
|
+
task.then((workRequests) => {
|
|
355
|
+
clearTimeout(timeout);
|
|
356
|
+
resolve(workRequests);
|
|
357
|
+
}).catch((error) => {
|
|
358
|
+
clearTimeout(timeout);
|
|
359
|
+
reject(error);
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
var continuePolling = {
|
|
364
|
+
value: true
|
|
365
|
+
};
|
|
366
|
+
async function pollForWorkers(apiClient, workers) {
|
|
367
|
+
const queuedWorker = new QueuedWorker(
|
|
368
|
+
1e5,
|
|
369
|
+
apiClient.config.responsePollInterval,
|
|
370
|
+
apiClient.config.responseBatchSize,
|
|
371
|
+
async (batchWork) => {
|
|
372
|
+
await postWorkerResponse(apiClient, batchWork);
|
|
373
|
+
},
|
|
374
|
+
apiClient.config.responsePollTimeout
|
|
375
|
+
);
|
|
376
|
+
const registerPollingData = workers.map((worker) => {
|
|
377
|
+
return {
|
|
378
|
+
orgId: 0,
|
|
379
|
+
namespace: worker.namespace,
|
|
380
|
+
stepType: "WORKER",
|
|
381
|
+
name: worker.name
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
await registerPolling(apiClient, registerPollingData);
|
|
385
|
+
const pollWorkerData = workers.map((worker) => {
|
|
386
|
+
return {
|
|
387
|
+
stepQueueNameData: {
|
|
388
|
+
orgId: 0,
|
|
389
|
+
namespace: worker.namespace,
|
|
390
|
+
stepType: "WORKER",
|
|
391
|
+
name: worker.name
|
|
392
|
+
},
|
|
393
|
+
size: worker.maxInProgress
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
let errorCount = 0;
|
|
397
|
+
while (continuePolling.value) {
|
|
398
|
+
try {
|
|
399
|
+
const workRequests = await runPollWithTimeout(pollWorker(apiClient, pollWorkerData), apiClient.config.pollTimeout);
|
|
400
|
+
for (const polledWorker of workRequests) {
|
|
401
|
+
const associatedWorker = workers.find(
|
|
402
|
+
(worker) => worker.name === polledWorker.stepName && worker.namespace === polledWorker.stepNamespace
|
|
403
|
+
);
|
|
404
|
+
let workerResponse = {
|
|
405
|
+
processId: polledWorker.processId,
|
|
406
|
+
stepId: polledWorker.stepId,
|
|
407
|
+
stepExecutionId: polledWorker.stepExecutionId,
|
|
408
|
+
runCount: polledWorker.runCount,
|
|
409
|
+
output: {},
|
|
410
|
+
status: "RUNNING" /* RUNNING */,
|
|
411
|
+
rescheduleAfterSeconds: null,
|
|
412
|
+
startedAt: (/* @__PURE__ */ new Date()).getTime()
|
|
413
|
+
};
|
|
414
|
+
if (!associatedWorker) {
|
|
415
|
+
workerResponse = {
|
|
416
|
+
...workerResponse,
|
|
417
|
+
output: {
|
|
418
|
+
error: `No worker found for ${polledWorker.stepName} ${polledWorker.stepNamespace}`
|
|
419
|
+
},
|
|
420
|
+
status: "TIMED_OUT" /* TIMED_OUT */
|
|
421
|
+
};
|
|
422
|
+
await queuedWorker.put(workerResponse);
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
const TIMEOUT = apiClient.config.apiWorkerTimeout;
|
|
426
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
427
|
+
setTimeout(() => reject(new Error("Timed out")), TIMEOUT);
|
|
428
|
+
});
|
|
429
|
+
try {
|
|
430
|
+
console.log(`Starting work ${polledWorker.processId} : ${polledWorker.stepId} : ${polledWorker.stepName} : ${polledWorker.stepRef}`);
|
|
431
|
+
const result = await Promise.race([
|
|
432
|
+
associatedWorker.worker(polledWorker.inputParam),
|
|
433
|
+
timeoutPromise
|
|
434
|
+
]);
|
|
435
|
+
workerResponse = {
|
|
436
|
+
...workerResponse,
|
|
437
|
+
output: {
|
|
438
|
+
...result,
|
|
439
|
+
__workCompletedAt: (/* @__PURE__ */ new Date()).getTime()
|
|
440
|
+
},
|
|
441
|
+
status: "COMPLETED" /* COMPLETED */
|
|
442
|
+
};
|
|
443
|
+
} catch (error) {
|
|
444
|
+
const err = error;
|
|
445
|
+
if (err.message && err.message === "Timed out") {
|
|
446
|
+
workerResponse = {
|
|
447
|
+
...workerResponse,
|
|
448
|
+
output: {
|
|
449
|
+
error: `${err.message} based on work timeout settings in worker - ${apiClient.config.apiWorkerTimeout} ms`
|
|
450
|
+
},
|
|
451
|
+
status: "TIMED_OUT" /* TIMED_OUT */
|
|
452
|
+
};
|
|
453
|
+
} else {
|
|
454
|
+
workerResponse = {
|
|
455
|
+
...workerResponse,
|
|
456
|
+
output: {
|
|
457
|
+
error: safeStringifyError(err)
|
|
458
|
+
},
|
|
459
|
+
status: "FAILED" /* FAILED */
|
|
460
|
+
};
|
|
461
|
+
console.error("Error:", err.message);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
await queuedWorker.put(workerResponse);
|
|
465
|
+
}
|
|
466
|
+
await new Promise((resolve) => setTimeout(resolve, apiClient.config.pollInterval));
|
|
467
|
+
} catch (error) {
|
|
468
|
+
errorCount++;
|
|
469
|
+
console.error(`Error processing batch - error count : ${errorCount} - `, error);
|
|
470
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function safeStringifyError(error) {
|
|
475
|
+
try {
|
|
476
|
+
if (error instanceof Error) {
|
|
477
|
+
const plainError = {
|
|
478
|
+
name: error.name,
|
|
479
|
+
message: error.message,
|
|
480
|
+
stack: error.stack,
|
|
481
|
+
...error
|
|
482
|
+
// Include enumerable custom properties if they exist
|
|
483
|
+
};
|
|
484
|
+
return JSON.stringify(plainError);
|
|
485
|
+
}
|
|
486
|
+
return JSON.stringify(error);
|
|
487
|
+
} catch (stringifyError) {
|
|
488
|
+
return `Error stringification failed: ${stringifyError.message}`;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
async function startPollingWorkers(apiClient, workers, intervalMs = 5e3) {
|
|
492
|
+
async function pollCycle() {
|
|
493
|
+
try {
|
|
494
|
+
await pollForWorkers(apiClient, workers);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
console.error("Error during worker polling:", error);
|
|
497
|
+
}
|
|
498
|
+
setTimeout(pollCycle, intervalMs);
|
|
499
|
+
}
|
|
500
|
+
await pollCycle();
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// src/apis/processClientImpl.ts
|
|
504
|
+
import { isAxiosError } from "axios";
|
|
505
|
+
var RUN_PROCESS_REQUEST_URL = "api/process/";
|
|
506
|
+
var runProcessSync = async (apiClient, ProcessRequestData2) => {
|
|
507
|
+
try {
|
|
508
|
+
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "runSync", {
|
|
509
|
+
data: ProcessRequestData2,
|
|
510
|
+
params: {
|
|
511
|
+
clientId: apiClient.getClientId()
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
console.log("Response:", response);
|
|
515
|
+
return response.data;
|
|
516
|
+
} catch (error) {
|
|
517
|
+
console.error("Some error occurred running process request : ", error);
|
|
518
|
+
throw error;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
var runProcessAsync = async (apiClient, ProcessRequestData2) => {
|
|
522
|
+
try {
|
|
523
|
+
const response = await apiClient.post(
|
|
524
|
+
RUN_PROCESS_REQUEST_URL + "runAsync",
|
|
525
|
+
{
|
|
526
|
+
data: ProcessRequestData2,
|
|
527
|
+
params: {
|
|
528
|
+
clientId: apiClient.getClientId()
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
);
|
|
532
|
+
console.log("Response:", response);
|
|
533
|
+
return response.data;
|
|
534
|
+
} catch (error) {
|
|
535
|
+
console.error("Some error occurred running process request : ", error);
|
|
536
|
+
throw error;
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
var getProcessData = async (apiClient, processId) => {
|
|
540
|
+
if (processId == null) {
|
|
541
|
+
throw new Error("Process ID cannot be null");
|
|
542
|
+
}
|
|
543
|
+
try {
|
|
544
|
+
const response = await apiClient.get(
|
|
545
|
+
RUN_PROCESS_REQUEST_URL + "context/" + processId
|
|
546
|
+
);
|
|
547
|
+
return response.data;
|
|
548
|
+
} catch (error) {
|
|
549
|
+
console.error("Error occurred while fetching process record: ", error);
|
|
550
|
+
throw error;
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
var getStepData = async (apiClient, stepId) => {
|
|
554
|
+
if (stepId === null || stepId === void 0) {
|
|
555
|
+
throw new Error("Step ID cannot be null or undefined");
|
|
556
|
+
}
|
|
557
|
+
try {
|
|
558
|
+
const response = await apiClient.get(
|
|
559
|
+
RUN_PROCESS_REQUEST_URL + "stepContext/" + stepId
|
|
560
|
+
);
|
|
561
|
+
return response.data;
|
|
562
|
+
} catch (error) {
|
|
563
|
+
console.log("Error occurred while getStepData: ", error);
|
|
564
|
+
throw error;
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
var bulkTerminate = async (apiClient, processIds, reason) => {
|
|
568
|
+
try {
|
|
569
|
+
const response = await apiClient.post(
|
|
570
|
+
RUN_PROCESS_REQUEST_URL + "bulkTerminate",
|
|
571
|
+
{
|
|
572
|
+
params: { reason },
|
|
573
|
+
data: processIds
|
|
574
|
+
}
|
|
575
|
+
);
|
|
576
|
+
return response.data;
|
|
577
|
+
} catch (error) {
|
|
578
|
+
const err = error;
|
|
579
|
+
throw new Error(
|
|
580
|
+
`Error occurred while terminating processes: ${err.message || error}`
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
var bulkResume = async (apiClient, processIds) => {
|
|
585
|
+
try {
|
|
586
|
+
const response = await apiClient.post(
|
|
587
|
+
RUN_PROCESS_REQUEST_URL + "bulkResume",
|
|
588
|
+
{
|
|
589
|
+
data: processIds
|
|
590
|
+
}
|
|
591
|
+
);
|
|
592
|
+
return response.data;
|
|
593
|
+
} catch (error) {
|
|
594
|
+
const err = error;
|
|
595
|
+
throw new Error(
|
|
596
|
+
`Error occurred while resuming processes: ${err.message || error}`
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
var bulkReviewed = async (apiClient, processIds, reason) => {
|
|
601
|
+
try {
|
|
602
|
+
const response = await apiClient.post(
|
|
603
|
+
RUN_PROCESS_REQUEST_URL + "bulkReviewed",
|
|
604
|
+
{
|
|
605
|
+
data: processIds,
|
|
606
|
+
params: { reason }
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
return response.data;
|
|
610
|
+
} catch (error) {
|
|
611
|
+
const err = error;
|
|
612
|
+
throw new Error(
|
|
613
|
+
`Error occurred while marking processes as reviewed: ${err.message || error}`
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
var rerun = async (apiClient, processId, clientId, version) => {
|
|
618
|
+
const params = {
|
|
619
|
+
clientId,
|
|
620
|
+
processId
|
|
621
|
+
};
|
|
622
|
+
if (version !== void 0) {
|
|
623
|
+
params["version"] = version;
|
|
624
|
+
}
|
|
625
|
+
try {
|
|
626
|
+
const response = await apiClient.post(RUN_PROCESS_REQUEST_URL + "rerun", {
|
|
627
|
+
params
|
|
628
|
+
});
|
|
629
|
+
return response.data;
|
|
630
|
+
} catch (error) {
|
|
631
|
+
if (isAxiosError(error)) {
|
|
632
|
+
throw new Error(
|
|
633
|
+
`HTTP request error during rerun process: ${error.response?.status} - ${error.response?.data}`
|
|
634
|
+
);
|
|
635
|
+
} else {
|
|
636
|
+
const err = error;
|
|
637
|
+
throw new Error(
|
|
638
|
+
`Unexpected error during rerun process: ${err.message || err}`
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
var searchProcessExecutions = async (apiClient, params) => {
|
|
644
|
+
const queryParams = new URLSearchParams();
|
|
645
|
+
if (params.startTimeEpoch !== void 0 && params.startTimeEpoch !== 0)
|
|
646
|
+
queryParams.set("startTimeEpoch", params.startTimeEpoch.toString());
|
|
647
|
+
if (params.endTimeEpoch !== void 0 && params.endTimeEpoch !== 0)
|
|
648
|
+
queryParams.set("endTimeEpoch", (params.endTimeEpoch || 0).toString());
|
|
649
|
+
if (params.namespace) queryParams.set("namespace", params.namespace);
|
|
650
|
+
if (params.names && params.names.length)
|
|
651
|
+
queryParams.set("names", params.names.join(","));
|
|
652
|
+
if (params.processIds && params.processIds.length)
|
|
653
|
+
queryParams.set("processIds", params.processIds.join(","));
|
|
654
|
+
if (params.correlationIds && params.correlationIds.length)
|
|
655
|
+
queryParams.set("correlationIds", params.correlationIds.join(","));
|
|
656
|
+
if (params.requestIds && params.requestIds.length)
|
|
657
|
+
queryParams.set("requestIds", params.requestIds.join(","));
|
|
658
|
+
if (params.statuses && params.statuses.length)
|
|
659
|
+
queryParams.set("statuses", params.statuses.join(","));
|
|
660
|
+
if (params.triggerTypes && params.triggerTypes.length)
|
|
661
|
+
queryParams.set("triggerTypes", params.triggerTypes.join(","));
|
|
662
|
+
const updatedParams = Object.fromEntries(new URLSearchParams(queryParams));
|
|
663
|
+
try {
|
|
664
|
+
const response = await apiClient.get(
|
|
665
|
+
RUN_PROCESS_REQUEST_URL + "api/stats/process/search",
|
|
666
|
+
updatedParams
|
|
667
|
+
);
|
|
668
|
+
console.log("Response:", response);
|
|
669
|
+
return response.data;
|
|
670
|
+
} catch (error) {
|
|
671
|
+
console.error("Error occurred while searching process executions: ", error);
|
|
672
|
+
throw error;
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
var invokeApiMappingGet = async (apiClient, endpoint, id, correlationId, apiCallType) => {
|
|
676
|
+
try {
|
|
677
|
+
const response = await apiClient.get(
|
|
678
|
+
RUN_PROCESS_REQUEST_URL + "api/call/" + endpoint,
|
|
679
|
+
{
|
|
680
|
+
id,
|
|
681
|
+
correlationId,
|
|
682
|
+
apiCallType
|
|
683
|
+
}
|
|
684
|
+
);
|
|
685
|
+
console.log("Response:", response);
|
|
686
|
+
return response.data;
|
|
687
|
+
} catch (error) {
|
|
688
|
+
console.error("Error occurred while invoking API Mapping GET: ", error);
|
|
689
|
+
throw error;
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
var invokeApiMappingPost = async (apiClient, endpoint, input, id, correlationId, apiCallType = "ASYNC" /* ASYNC */) => {
|
|
693
|
+
try {
|
|
694
|
+
const response = await apiClient.post(
|
|
695
|
+
RUN_PROCESS_REQUEST_URL + "api/call/" + endpoint,
|
|
696
|
+
{
|
|
697
|
+
data: input,
|
|
698
|
+
params: {
|
|
699
|
+
id,
|
|
700
|
+
correlationId,
|
|
701
|
+
apiCallType
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
);
|
|
705
|
+
return response.data;
|
|
706
|
+
} catch (error) {
|
|
707
|
+
console.error("Error occurred while invoking API Mapping POST: ", error);
|
|
708
|
+
throw error;
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
// src/apis/registrationClientImpl.ts
|
|
713
|
+
var renewRegistration = async (apiClient, params) => {
|
|
714
|
+
try {
|
|
715
|
+
const response = await apiClient.put("/api/clients/register", {
|
|
716
|
+
params: { ...params }
|
|
717
|
+
});
|
|
718
|
+
console.debug("Response from server:", response);
|
|
719
|
+
return response.data;
|
|
720
|
+
} catch (error) {
|
|
721
|
+
console.error("Error occurred during registration renewal:", error);
|
|
722
|
+
throw error;
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
// src/index.ts
|
|
727
|
+
var UnmeshedClient = class {
|
|
728
|
+
client;
|
|
729
|
+
constructor(config) {
|
|
730
|
+
this.client = new UnmeshedApiClient(config);
|
|
731
|
+
}
|
|
732
|
+
startPolling(workers) {
|
|
733
|
+
startPollingWorkers(this.client, workers);
|
|
734
|
+
}
|
|
735
|
+
// Other methods for interacting with Unmeshed API
|
|
736
|
+
runProcessSync(ProcessRequestData2) {
|
|
737
|
+
return runProcessSync(this.client, ProcessRequestData2);
|
|
738
|
+
}
|
|
739
|
+
runProcessAsync(ProcessRequestData2) {
|
|
740
|
+
return runProcessAsync(this.client, ProcessRequestData2);
|
|
741
|
+
}
|
|
742
|
+
getProcessData(processId) {
|
|
743
|
+
return getProcessData(this.client, processId);
|
|
744
|
+
}
|
|
745
|
+
getStepData(stepId) {
|
|
746
|
+
return getStepData(this.client, stepId);
|
|
747
|
+
}
|
|
748
|
+
bulkTerminate(processIds, reason) {
|
|
749
|
+
return bulkTerminate(this.client, processIds, reason);
|
|
750
|
+
}
|
|
751
|
+
bulkResume(processIds) {
|
|
752
|
+
return bulkResume(this.client, processIds);
|
|
753
|
+
}
|
|
754
|
+
bulkReviewed(processIds, reason) {
|
|
755
|
+
return bulkReviewed(this.client, processIds, reason);
|
|
756
|
+
}
|
|
757
|
+
reRun(processId, clientId, version) {
|
|
758
|
+
return rerun(this.client, processId, clientId, version);
|
|
759
|
+
}
|
|
760
|
+
searchProcessExecution(params) {
|
|
761
|
+
return searchProcessExecutions(this.client, params);
|
|
762
|
+
}
|
|
763
|
+
invokeApiMappingGet(apiClient, endpoint, id, correlationId, apiCallType) {
|
|
764
|
+
return invokeApiMappingGet(
|
|
765
|
+
apiClient,
|
|
766
|
+
endpoint,
|
|
767
|
+
id,
|
|
768
|
+
correlationId,
|
|
769
|
+
apiCallType
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
invokeApiMappingPost(endpoint, input, id, correlationId, apiCallType) {
|
|
773
|
+
return invokeApiMappingPost(
|
|
774
|
+
this.client,
|
|
775
|
+
endpoint,
|
|
776
|
+
input,
|
|
777
|
+
id,
|
|
778
|
+
correlationId,
|
|
779
|
+
apiCallType
|
|
780
|
+
);
|
|
781
|
+
}
|
|
782
|
+
reNewRegistration(params) {
|
|
783
|
+
return renewRegistration(this.client, params);
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
export {
|
|
787
|
+
ApiCallType,
|
|
788
|
+
ProcessStatus,
|
|
789
|
+
ProcessTriggerType,
|
|
790
|
+
ProcessType,
|
|
791
|
+
SQAuthUserType,
|
|
792
|
+
StepStatus,
|
|
793
|
+
StepType,
|
|
794
|
+
UnmeshedClient,
|
|
795
|
+
WebhookSource
|
|
796
|
+
};
|
|
797
|
+
//# sourceMappingURL=index.mjs.map
|