anear-js-api 1.3.0 → 1.3.1

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.
@@ -658,7 +658,8 @@ const ActiveEventStatesConfig = {
658
658
  states: {
659
659
  idle: {},
660
660
  waitingForCancelConfirmations: {
661
- entry: ['sendCancelTimeoutToAllAPMs', 'setupPendingCancelConfirmations'],
661
+ // Note: Setup actions are called in the transitions that lead here, not in entry
662
+ // This allows different setup for declarative cancel (TRIGGER_CANCEL_SEQUENCE) vs manual cancel (CANCEL_ALL_PARTICIPANT_TIMEOUTS)
662
663
  on: {
663
664
  TIMER_CANCELED: {
664
665
  actions: ['removeFromPendingCancelConfirmations']
@@ -677,7 +678,7 @@ const ActiveEventStatesConfig = {
677
678
  },
678
679
  always: {
679
680
  guard: 'allCancelConfirmationsReceived',
680
- actions: ['forwardPendingCancelAction', 'clearCancelState'],
681
+ actions: ['forwardPendingCancelActionIfExists', 'clearCancelState'],
681
682
  target: '#waitingForActions.idle'
682
683
  }
683
684
  }
@@ -691,7 +692,12 @@ const ActiveEventStatesConfig = {
691
692
  actions: ['trackParticipantTimeout', 'processParticipantTimeout'],
692
693
  // v5 note: internal transitions are the default (v4 had `internal: true`)
693
694
  },
695
+ CANCEL_ALL_PARTICIPANT_TIMEOUTS: {
696
+ actions: ['setupPendingCancelConfirmationsForManualCancel', 'sendCancelTimeoutToAllAPMs'],
697
+ target: '.waitingForCancelConfirmations'
698
+ },
694
699
  TRIGGER_CANCEL_SEQUENCE: {
700
+ actions: ['sendCancelTimeoutToAllAPMs', 'setupPendingCancelConfirmations'],
695
701
  target: '.waitingForCancelConfirmations'
696
702
  },
697
703
  TIMER_CANCELED: {
@@ -1749,6 +1755,19 @@ const AnearEventMachineFunctions = ({
1749
1755
  suppressParticipantTimeouts: true // Drop PARTICIPANT_TIMEOUT events
1750
1756
  }
1751
1757
  }),
1758
+ setupPendingCancelConfirmationsForManualCancel: assign(({ context }) => {
1759
+ // Get all active participants (for manual cancelAllParticipantTimeouts call)
1760
+ const activeParticipantIds = getActiveParticipantIds(context)
1761
+ const pendingConfirmations = new Set(activeParticipantIds)
1762
+
1763
+ logger.info(`[AEM] Starting manual cancellation sequence (cancelAllParticipantTimeouts). Waiting for ${pendingConfirmations.size} APM confirmations: ${[...pendingConfirmations].join(', ')}`)
1764
+
1765
+ return {
1766
+ pendingCancelConfirmations: pendingConfirmations,
1767
+ pendingCancelAction: null, // No ACTION to forward for manual cancel
1768
+ suppressParticipantTimeouts: true // Drop PARTICIPANT_TIMEOUT events
1769
+ }
1770
+ }),
1752
1771
  removeFromPendingCancelConfirmations: assign(({ context, event }) => {
1753
1772
  const participantId = event.participantId || event.data?.id
1754
1773
  if (!context.pendingCancelConfirmations || !participantId) return {}
@@ -102,6 +102,14 @@ const AppMachineTransition = (anearEvent) => {
102
102
  let timeoutFn
103
103
  let displayEvent
104
104
 
105
+ // Extract cancel from meta level (for function-based eachParticipant or top-level cancel)
106
+ // Supports both "cancel" (developer-friendly) and "cancelActionType" (internal)
107
+ if (meta.cancel && !cancelActionType) {
108
+ cancelActionType = meta.cancel
109
+ } else if (meta.cancelActionType && !cancelActionType) {
110
+ cancelActionType = meta.cancelActionType
111
+ }
112
+
105
113
  // Validate that participants: and participant: are not both defined
106
114
  if (meta.allParticipants && meta.eachParticipant) {
107
115
  logger.error(`[AppMachineTransition] Invalid meta configuration: both 'allParticipants' and 'eachParticipant' are defined. Only one can be used per state.`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anear-js-api",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Javascript Developer API for Anear Apps",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {