@processmaker/screen-builder 3.8.41 → 3.8.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@processmaker/screen-builder",
3
- "version": "3.8.41",
3
+ "version": "3.8.43",
4
4
  "scripts": {
5
5
  "dev": "VITE_COVERAGE=true vite",
6
6
  "build": "vite build",
@@ -61,7 +61,7 @@
61
61
  "@fortawesome/fontawesome-free": "^5.6.1",
62
62
  "@originjs/vite-plugin-commonjs": "^1.0.3",
63
63
  "@panter/vue-i18next": "^0.15.2",
64
- "@processmaker/vue-form-elements": "0.65.10",
64
+ "@processmaker/vue-form-elements": "0.65.11",
65
65
  "@processmaker/vue-multiselect": "2.3.2",
66
66
  "@storybook/addon-essentials": "^7.6.13",
67
67
  "@storybook/addon-interactions": "^7.6.13",
@@ -125,7 +125,7 @@
125
125
  },
126
126
  "peerDependencies": {
127
127
  "@panter/vue-i18next": "^0.15.0",
128
- "@processmaker/vue-form-elements": "0.65.10",
128
+ "@processmaker/vue-form-elements": "0.65.11",
129
129
  "i18next": "^15.0.8",
130
130
  "vue": "^2.6.12",
131
131
  "vuex": "^3.1.1"
@@ -534,39 +534,47 @@ export default {
534
534
  // If the task has not an origin source it should re redirected top the tasks List as default.
535
535
  return document.referrer || '/tasks';
536
536
  },
537
- loadNextAssignedTask(requestId = null) {
537
+ loadNextAssignedTask(requestId = null, taskId = null) {
538
538
  if (!requestId) {
539
539
  requestId = this.requestId;
540
540
  }
541
541
  if (!this.userId) {
542
- return;
542
+ return false;
543
543
  }
544
544
  const timestamp = !window.Cypress ? `&t=${Date.now()}` : "";
545
- const url = `?user_id=${this.userId}&status=ACTIVE&process_request_id=${requestId}&include_sub_tasks=1${timestamp}`;
545
+ const taskIdFilter = taskId ? `&task_id=${encodeURIComponent(taskId)}` : "";
546
+ const url = `?user_id=${this.userId}&status=ACTIVE&process_request_id=${requestId}&include_sub_tasks=1${taskIdFilter}${timestamp}`;
546
547
  return this.$dataProvider
547
548
  .getTasks(url).then((response) => {
548
549
  this.$emit("load-data-task", response);
549
- if (response.data.data.length > 0) {
550
- let task = response.data.data[0];
551
- if (task.process_request_id !== this.requestId) {
552
- // Next task is in a subprocess, do a hard redirect
550
+ const tasks = response.data.data;
551
+ const task = taskId
552
+ ? tasks.find(({ id }) => String(id) === String(taskId))
553
+ : tasks[0];
554
+ if (task) {
555
+ const requiresWebEntryFallback = this.isWebEntry
556
+ && task.web_entry_available === false;
557
+ if (task.process_request_id !== this.requestId || requiresWebEntryFallback) {
558
+ // Cross-request transitions and non-Web Entry tasks require a hard redirect.
553
559
  if (this.redirecting === task.process_request_id) {
554
- return;
560
+ return true;
555
561
  }
556
562
  this.unsubscribeSocketListeners();
557
563
  this.redirecting = task.process_request_id;
558
- this.$emit('redirect', task.id, true);
559
- return;
564
+ // Screen Builder uses Vue 2, where emitted events have no runtime emits contract.
565
+ this.$emit('redirect', this.isWebEntry ? task : task.id, true); // NOSONAR
566
+ return true;
560
567
  } else {
561
568
  this.emitIfTaskCompleted(requestId);
562
569
  }
563
570
  this.taskId = task.id;
564
571
  this.nodeId = task.element_id;
565
572
  this.loadTask();
566
- } else if (this.parentRequest && ['COMPLETED', 'CLOSED'].includes(this.task.process_request.status)) {
573
+ } else if (!taskId && this.parentRequest && ['COMPLETED', 'CLOSED'].includes(this.task.process_request.status)) {
567
574
  this.$emit('completed', this.getAllowedRequestId());
568
575
  }
569
576
  this.disabled = false;
577
+ return Boolean(task);
570
578
  });
571
579
  },
572
580
  emitIfTaskCompleted(requestId) {
@@ -641,24 +649,27 @@ export default {
641
649
  * @param {Function} apiCall - The API call to be made.
642
650
  * @param {number} retries - The number of retry attempts.
643
651
  * @param {number} delay - The delay between retries in milliseconds.
652
+ * @param {Function} shouldRetry - Determines whether a successful response should be retried.
644
653
  * @returns {Promise} - The response from the API call.
645
654
  */
646
655
  // eslint-disable-next-line consistent-return
647
- async retryApiCall(apiCall, retries = 3, delay = 1000) {
656
+ async retryApiCall(apiCall, retries = 3, delay = 1000, shouldRetry = () => false) {
648
657
  for (let attempt = 0; attempt < retries; attempt++) {
649
658
  try {
650
659
  // eslint-disable-next-line no-await-in-loop
651
660
  const response = await apiCall();
652
- return response;
661
+ if (!shouldRetry(response) || attempt === retries - 1) {
662
+ return response;
663
+ }
653
664
  } catch (error) {
654
665
  if (attempt === retries - 1) {
655
666
  throw error;
656
667
  }
657
- // eslint-disable-next-line no-await-in-loop
658
- await new Promise((resolve) => {
659
- setTimeout(resolve, delay);
660
- });
661
668
  }
669
+ // eslint-disable-next-line no-await-in-loop
670
+ await new Promise((resolve) => {
671
+ setTimeout(resolve, delay);
672
+ });
662
673
  }
663
674
  },
664
675
  /**
@@ -919,6 +930,31 @@ export default {
919
930
  }
920
931
  },
921
932
 
933
+ async handleWebEntryTaskRedirect(data, tokenId) {
934
+ let taskHandled = false;
935
+ try {
936
+ taskHandled = await this.retryApiCall(
937
+ () => this.loadNextAssignedTask(this.requestId, tokenId),
938
+ 3,
939
+ 1000,
940
+ (handled) => handled !== true
941
+ );
942
+ } catch (error) {
943
+ taskHandled = false;
944
+ } finally {
945
+ if (!taskHandled) {
946
+ this.loadingTask = false;
947
+ this.disabled = false;
948
+ }
949
+ }
950
+
951
+ if (!taskHandled) {
952
+ const fallbackUrl = data?.params?.[0]?.payloadUrl
953
+ || (tokenId ? `/tasks/${tokenId}/edit` : `/requests/${this.requestId}`);
954
+ window.location.href = fallbackUrl;
955
+ }
956
+ },
957
+
922
958
  /**
923
959
  * Handles the 'redirectToTask' event by loading the specified task.
924
960
  * Updates the current task ID and reloads the task data.
@@ -947,6 +983,13 @@ export default {
947
983
  window.location.href = await this.getDestinationUrl();
948
984
  return;
949
985
  }
986
+
987
+ // Web Entry needs the complete task to preserve the target request context.
988
+ if (this.isWebEntry) {
989
+ await this.handleWebEntryTaskRedirect(data, tokenId);
990
+ return;
991
+ }
992
+
950
993
  this.nodeId = nodeId;
951
994
  this.taskId = tokenId;
952
995