@unmeshed/sdk 1.1.1 → 1.1.2

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 CHANGED
@@ -201,23 +201,23 @@ type ProcessRequestData = {
201
201
  name: string;
202
202
  namespace: string;
203
203
  version: number | null;
204
- requestId: string;
205
- correlationId: string;
206
- input: Record<string, unknown>;
204
+ requestId?: string;
205
+ correlationId?: string;
206
+ input?: Record<string, unknown>;
207
207
  };
208
208
  type ProcessSearchRequest = {
209
209
  startTimeEpoch: number;
210
210
  endTimeEpoch?: number | null;
211
- namespace: string;
212
- processTypes: ProcessType[];
213
- triggerTypes: ProcessTriggerType[];
214
- names: string[];
215
- processIds: number[];
216
- correlationIds: string[];
217
- requestIds: string[];
218
- statuses: ProcessStatus[];
219
- limit: number;
220
- offset: number;
211
+ namespace?: string;
212
+ processTypes?: ProcessType[];
213
+ triggerTypes?: ProcessTriggerType[];
214
+ names?: string[];
215
+ processIds?: number[];
216
+ correlationIds?: string[];
217
+ requestIds?: string[];
218
+ statuses?: ProcessStatus[];
219
+ limit?: number;
220
+ offset?: number;
221
221
  };
222
222
  type StepSize = {
223
223
  stepQueueNameData: StepQueueNameData;
@@ -303,11 +303,11 @@ interface ApiError extends Error {
303
303
  interface QueryParams {
304
304
  [key: string]: string | number | boolean | undefined;
305
305
  }
306
- interface RequestConfig extends Omit<AxiosRequestConfig, "baseURL" | "url" | "method"> {
306
+ interface RequestConfig extends Omit<AxiosRequestConfig, 'baseURL' | 'url' | 'method'> {
307
307
  headers?: Record<string, string>;
308
308
  }
309
309
  interface HandleRequestConfig {
310
- method: "get" | "post" | "put" | "delete";
310
+ method: 'get' | 'post' | 'put' | 'delete';
311
311
  endpoint: string;
312
312
  params?: QueryParams;
313
313
  data?: Record<string, unknown>;
package/dist/index.d.ts CHANGED
@@ -201,23 +201,23 @@ type ProcessRequestData = {
201
201
  name: string;
202
202
  namespace: string;
203
203
  version: number | null;
204
- requestId: string;
205
- correlationId: string;
206
- input: Record<string, unknown>;
204
+ requestId?: string;
205
+ correlationId?: string;
206
+ input?: Record<string, unknown>;
207
207
  };
208
208
  type ProcessSearchRequest = {
209
209
  startTimeEpoch: number;
210
210
  endTimeEpoch?: number | null;
211
- namespace: string;
212
- processTypes: ProcessType[];
213
- triggerTypes: ProcessTriggerType[];
214
- names: string[];
215
- processIds: number[];
216
- correlationIds: string[];
217
- requestIds: string[];
218
- statuses: ProcessStatus[];
219
- limit: number;
220
- offset: number;
211
+ namespace?: string;
212
+ processTypes?: ProcessType[];
213
+ triggerTypes?: ProcessTriggerType[];
214
+ names?: string[];
215
+ processIds?: number[];
216
+ correlationIds?: string[];
217
+ requestIds?: string[];
218
+ statuses?: ProcessStatus[];
219
+ limit?: number;
220
+ offset?: number;
221
221
  };
222
222
  type StepSize = {
223
223
  stepQueueNameData: StepQueueNameData;
@@ -303,11 +303,11 @@ interface ApiError extends Error {
303
303
  interface QueryParams {
304
304
  [key: string]: string | number | boolean | undefined;
305
305
  }
306
- interface RequestConfig extends Omit<AxiosRequestConfig, "baseURL" | "url" | "method"> {
306
+ interface RequestConfig extends Omit<AxiosRequestConfig, 'baseURL' | 'url' | 'method'> {
307
307
  headers?: Record<string, string>;
308
308
  }
309
309
  interface HandleRequestConfig {
310
- method: "get" | "post" | "put" | "delete";
310
+ method: 'get' | 'post' | 'put' | 'delete';
311
311
  endpoint: string;
312
312
  params?: QueryParams;
313
313
  data?: Record<string, unknown>;
package/dist/index.js CHANGED
@@ -272,7 +272,9 @@ var QueuedWorker = class {
272
272
  this.batchSize = batchSize;
273
273
  this.workerFn = workerFn;
274
274
  this.timeoutMs = timeoutMs;
275
- console.log(`Configured queued worker with ${pollIntervalMs} ms interval and batch size of ${batchSize} and a timeout of ${timeoutMs} ms`);
275
+ console.log(
276
+ `Configured queued worker with ${pollIntervalMs} ms interval and batch size of ${batchSize} and a timeout of ${timeoutMs} ms`
277
+ );
276
278
  this.start();
277
279
  }
278
280
  async start() {
@@ -350,9 +352,7 @@ async function registerPolling(apiClient, data) {
350
352
  console.log("Successfully renewed registration for workers", data);
351
353
  return response.data;
352
354
  } catch {
353
- console.error(
354
- "An error occurred during polling registration. Retrying in 3 seconds..."
355
- );
355
+ console.error("An error occurred during polling registration. Retrying in 3 seconds...");
356
356
  await new Promise((resolve) => setTimeout(resolve, 3e3));
357
357
  return attempt();
358
358
  }
@@ -368,18 +368,22 @@ async function pollWorker(apiClient, data) {
368
368
  return response.data;
369
369
  } catch (error) {
370
370
  console.error("Error occurred during worker polling", error);
371
+ return [];
371
372
  }
372
373
  }
373
374
  async function postWorkerResponse(apiClient, workResponses) {
374
375
  try {
375
376
  if (workResponses.length > 0) {
376
- const grouped = workResponses.reduce((acc, response2) => {
377
- if (!acc[response2.status]) {
378
- acc[response2.status] = [];
379
- }
380
- acc[response2.status].push(response2.stepId);
381
- return acc;
382
- }, {});
377
+ const grouped = workResponses.reduce(
378
+ (acc, response2) => {
379
+ if (!acc[response2.status]) {
380
+ acc[response2.status] = [];
381
+ }
382
+ acc[response2.status].push(response2.stepId);
383
+ return acc;
384
+ },
385
+ {}
386
+ );
383
387
  const resultString = Object.entries(grouped).map(([status, stepIds]) => `${status}: [${stepIds.join(", ")}]`).join(", ");
384
388
  console.log(`Posting response of size: ${workResponses.length} including ids: ${resultString}`);
385
389
  const response = await apiClient.post(`/api/clients/bulkResults`, {
@@ -440,7 +444,10 @@ async function pollForWorkers(apiClient, workers) {
440
444
  let errorCount = 0;
441
445
  while (continuePolling.value) {
442
446
  try {
443
- const workRequests = await runPollWithTimeout(pollWorker(apiClient, pollWorkerData), apiClient.config.pollTimeout);
447
+ const workRequests = await runPollWithTimeout(
448
+ pollWorker(apiClient, pollWorkerData),
449
+ apiClient.config.pollTimeout
450
+ );
444
451
  for (const polledWorker of workRequests) {
445
452
  const associatedWorker = workers.find(
446
453
  (worker) => worker.name === polledWorker.stepName && worker.namespace === polledWorker.stepNamespace
@@ -471,11 +478,10 @@ async function pollForWorkers(apiClient, workers) {
471
478
  setTimeout(() => reject(new Error("Timed out")), TIMEOUT);
472
479
  });
473
480
  try {
474
- console.log(`Starting work ${polledWorker.processId} : ${polledWorker.stepId} : ${polledWorker.stepName} : ${polledWorker.stepRef}`);
475
- const result = await Promise.race([
476
- associatedWorker.worker(polledWorker.inputParam),
477
- timeoutPromise
478
- ]);
481
+ console.log(
482
+ `Starting work ${polledWorker.processId} : ${polledWorker.stepId} : ${polledWorker.stepName} : ${polledWorker.stepRef}`
483
+ );
484
+ const result = await Promise.race([associatedWorker.worker(polledWorker.inputParam), timeoutPromise]);
479
485
  workerResponse = {
480
486
  ...workerResponse,
481
487
  output: {
@@ -519,17 +525,19 @@ function safeStringifyError(error) {
519
525
  try {
520
526
  if (error instanceof Error) {
521
527
  const plainError = {
528
+ ...error,
522
529
  name: error.name,
523
530
  message: error.message,
524
- stack: error.stack,
525
- ...error
526
- // Include enumerable custom properties if they exist
531
+ stack: error.stack
527
532
  };
528
533
  return JSON.stringify(plainError);
529
534
  }
530
535
  return JSON.stringify(error);
531
536
  } catch (stringifyError) {
532
- return `Error stringification failed: ${stringifyError.message}`;
537
+ if (stringifyError instanceof Error) {
538
+ return `Error stringification failed: ${stringifyError.message}`;
539
+ }
540
+ return "Error stringification failed: An unknown error occurred during stringification.";
533
541
  }
534
542
  }
535
543
  async function startPollingWorkers(apiClient, workers, intervalMs = 5e3) {
@@ -564,15 +572,12 @@ var runProcessSync = async (apiClient, ProcessRequestData2) => {
564
572
  };
565
573
  var runProcessAsync = async (apiClient, ProcessRequestData2) => {
566
574
  try {
567
- const response = await apiClient.post(
568
- `${PROCESS_PREFIX}/runAsync`,
569
- {
570
- data: ProcessRequestData2,
571
- params: {
572
- clientId: apiClient.getClientId()
573
- }
575
+ const response = await apiClient.post(`${PROCESS_PREFIX}/runAsync`, {
576
+ data: ProcessRequestData2,
577
+ params: {
578
+ clientId: apiClient.getClientId()
574
579
  }
575
- );
580
+ });
576
581
  console.log("Response:", response);
577
582
  return response.data;
578
583
  } catch (error) {
@@ -585,10 +590,7 @@ var getProcessData = async (apiClient, processId, includeSteps = false) => {
585
590
  throw new Error("Process ID cannot be null");
586
591
  }
587
592
  try {
588
- const response = await apiClient.get(
589
- `${PROCESS_PREFIX}/context/${processId}`,
590
- { includeSteps }
591
- );
593
+ const response = await apiClient.get(`${PROCESS_PREFIX}/context/${processId}`, { includeSteps });
592
594
  return response.data;
593
595
  } catch (error) {
594
596
  console.error("Error occurred while fetching process record: ", error);
@@ -600,9 +602,7 @@ var getStepData = async (apiClient, stepId) => {
600
602
  throw new Error("Step ID cannot be null or undefined");
601
603
  }
602
604
  try {
603
- const response = await apiClient.get(
604
- `${PROCESS_PREFIX}/stepContext/${stepId}`
605
- );
605
+ const response = await apiClient.get(`${PROCESS_PREFIX}/stepContext/${stepId}`);
606
606
  return response.data;
607
607
  } catch (error) {
608
608
  console.log("Error occurred while getStepData: ", error);
@@ -611,52 +611,37 @@ var getStepData = async (apiClient, stepId) => {
611
611
  };
612
612
  var bulkTerminate = async (apiClient, processIds, reason) => {
613
613
  try {
614
- const response = await apiClient.post(
615
- `${PROCESS_PREFIX}/bulkTerminate`,
616
- {
617
- params: { reason },
618
- data: processIds
619
- }
620
- );
614
+ const response = await apiClient.post(`${PROCESS_PREFIX}/bulkTerminate`, {
615
+ params: { reason },
616
+ data: processIds
617
+ });
621
618
  return response.data;
622
619
  } catch (error) {
623
620
  const err = error;
624
- throw new Error(
625
- `Error occurred while terminating processes: ${err.message || error}`
626
- );
621
+ throw new Error(`Error occurred while terminating processes: ${err.message || error}`);
627
622
  }
628
623
  };
629
624
  var bulkResume = async (apiClient, processIds) => {
630
625
  try {
631
- const response = await apiClient.post(
632
- `${PROCESS_PREFIX}/bulkResume`,
633
- {
634
- data: processIds
635
- }
636
- );
626
+ const response = await apiClient.post(`${PROCESS_PREFIX}/bulkResume`, {
627
+ data: processIds
628
+ });
637
629
  return response.data;
638
630
  } catch (error) {
639
631
  const err = error;
640
- throw new Error(
641
- `Error occurred while resuming processes: ${err.message || error}`
642
- );
632
+ throw new Error(`Error occurred while resuming processes: ${err.message || error}`);
643
633
  }
644
634
  };
645
635
  var bulkReviewed = async (apiClient, processIds, reason) => {
646
636
  try {
647
- const response = await apiClient.post(
648
- `${PROCESS_PREFIX}/bulkReviewed`,
649
- {
650
- data: processIds,
651
- params: { reason }
652
- }
653
- );
637
+ const response = await apiClient.post(`${PROCESS_PREFIX}/bulkReviewed`, {
638
+ data: processIds,
639
+ params: { reason }
640
+ });
654
641
  return response.data;
655
642
  } catch (error) {
656
643
  const err = error;
657
- throw new Error(
658
- `Error occurred while marking processes as reviewed: ${err.message || error}`
659
- );
644
+ throw new Error(`Error occurred while marking processes as reviewed: ${err.message || error}`);
660
645
  }
661
646
  };
662
647
  var rerun = async (apiClient, processId, version) => {
@@ -673,14 +658,10 @@ var rerun = async (apiClient, processId, version) => {
673
658
  return response.data;
674
659
  } catch (error) {
675
660
  if ((0, import_axios2.isAxiosError)(error)) {
676
- throw new Error(
677
- `HTTP request error during rerun process: ${error.response?.status} - ${error.response?.data}`
678
- );
661
+ throw new Error(`HTTP request error during rerun process: ${error.response?.status} - ${error.response?.data}`);
679
662
  } else {
680
663
  const err = error;
681
- throw new Error(
682
- `Unexpected error during rerun process: ${err.message || err}`
683
- );
664
+ throw new Error(`Unexpected error during rerun process: ${err.message || err}`);
684
665
  }
685
666
  }
686
667
  };
@@ -691,24 +672,16 @@ var searchProcessExecutions = async (apiClient, params) => {
691
672
  if (params.endTimeEpoch !== void 0 && params.endTimeEpoch !== 0)
692
673
  queryParams.set("endTimeEpoch", (params.endTimeEpoch || 0).toString());
693
674
  if (params.namespace) queryParams.set("namespace", params.namespace);
694
- if (params.names && params.names.length)
695
- queryParams.set("names", params.names.join(","));
696
- if (params.processIds && params.processIds.length)
697
- queryParams.set("processIds", params.processIds.join(","));
675
+ if (params.names && params.names.length) queryParams.set("names", params.names.join(","));
676
+ if (params.processIds && params.processIds.length) queryParams.set("processIds", params.processIds.join(","));
698
677
  if (params.correlationIds && params.correlationIds.length)
699
678
  queryParams.set("correlationIds", params.correlationIds.join(","));
700
- if (params.requestIds && params.requestIds.length)
701
- queryParams.set("requestIds", params.requestIds.join(","));
702
- if (params.statuses && params.statuses.length)
703
- queryParams.set("statuses", params.statuses.join(","));
704
- if (params.triggerTypes && params.triggerTypes.length)
705
- queryParams.set("triggerTypes", params.triggerTypes.join(","));
679
+ if (params.requestIds && params.requestIds.length) queryParams.set("requestIds", params.requestIds.join(","));
680
+ if (params.statuses && params.statuses.length) queryParams.set("statuses", params.statuses.join(","));
681
+ if (params.triggerTypes && params.triggerTypes.length) queryParams.set("triggerTypes", params.triggerTypes.join(","));
706
682
  const updatedParams = Object.fromEntries(new URLSearchParams(queryParams));
707
683
  try {
708
- const response = await apiClient.get(
709
- `${PROCESS_PREFIX}/api/stats/process/search`,
710
- updatedParams
711
- );
684
+ const response = await apiClient.get(`api/stats/process/search`, updatedParams);
712
685
  console.log("Response:", response);
713
686
  return response.data;
714
687
  } catch (error) {
@@ -718,14 +691,11 @@ var searchProcessExecutions = async (apiClient, params) => {
718
691
  };
719
692
  var invokeApiMappingGet = async (apiClient, endpoint, id, correlationId, apiCallType) => {
720
693
  try {
721
- const response = await apiClient.get(
722
- `${PROCESS_PREFIX}/api/call/${endpoint}`,
723
- {
724
- id,
725
- correlationId,
726
- apiCallType
727
- }
728
- );
694
+ const response = await apiClient.get(`${PROCESS_PREFIX}/api/call/${endpoint}`, {
695
+ id,
696
+ correlationId,
697
+ apiCallType
698
+ });
729
699
  console.log("Response:", response);
730
700
  return response.data;
731
701
  } catch (error) {
@@ -735,17 +705,14 @@ var invokeApiMappingGet = async (apiClient, endpoint, id, correlationId, apiCall
735
705
  };
736
706
  var invokeApiMappingPost = async (apiClient, endpoint, input, id, correlationId, apiCallType = "ASYNC" /* ASYNC */) => {
737
707
  try {
738
- const response = await apiClient.post(
739
- `${PROCESS_PREFIX}/api/call/${endpoint}`,
740
- {
741
- data: input,
742
- params: {
743
- id,
744
- correlationId,
745
- apiCallType
746
- }
708
+ const response = await apiClient.post(`${PROCESS_PREFIX}/api/call/${endpoint}`, {
709
+ data: input,
710
+ params: {
711
+ id,
712
+ correlationId,
713
+ apiCallType
747
714
  }
748
- );
715
+ });
749
716
  return response.data;
750
717
  } catch (error) {
751
718
  console.error("Error occurred while invoking API Mapping POST: ", error);
@@ -804,23 +771,10 @@ var UnmeshedClient = class {
804
771
  return searchProcessExecutions(this.client, params);
805
772
  }
806
773
  invokeApiMappingGet(apiClient, endpoint, id, correlationId, apiCallType) {
807
- return invokeApiMappingGet(
808
- apiClient,
809
- endpoint,
810
- id,
811
- correlationId,
812
- apiCallType
813
- );
774
+ return invokeApiMappingGet(apiClient, endpoint, id, correlationId, apiCallType);
814
775
  }
815
776
  invokeApiMappingPost(endpoint, input, id, correlationId, apiCallType) {
816
- return invokeApiMappingPost(
817
- this.client,
818
- endpoint,
819
- input,
820
- id,
821
- correlationId,
822
- apiCallType
823
- );
777
+ return invokeApiMappingPost(this.client, endpoint, input, id, correlationId, apiCallType);
824
778
  }
825
779
  reNewRegistration(params) {
826
780
  return renewRegistration(this.client, params);