@izara_project/izara-core-library-asynchronous-flow 1.0.39 → 1.0.41
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 +1 -1
- package/src/asyncFlowSharedLib.js +72 -16
- package/src/awaitingMultipleSteps.js +128 -48
- package/src/awaitingStep.js +38 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Sven Mason <thebarbariansven@gmail.com>",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"homepage": "https://bitbucket.org/izara-core-libraries/izara-core-library-asynchronous-flow#readme",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.41",
|
|
7
7
|
"description": "Shared asynchronous flow logic",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "index.js",
|
|
@@ -28,13 +28,57 @@ import { sqs } from '@izara_project/izara-core-library-external-request';
|
|
|
28
28
|
|
|
29
29
|
import { identifierUuid } from '@izara_project/izara-shared-core';
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Helper to safely join a prefix and an ID with a single underscore.
|
|
33
|
+
* Ensures no duplicate underscores between them.
|
|
34
|
+
* @param {string} id
|
|
35
|
+
* @param {string} [prefix='']
|
|
36
|
+
* @returns {string}
|
|
37
|
+
*/
|
|
38
|
+
function _joinPrefixAndId(id, prefix = '') {
|
|
39
|
+
if (!prefix) return id;
|
|
40
|
+
|
|
41
|
+
const cleanPrefix = prefix.endsWith('_') ? prefix.slice(0, -1) : prefix;
|
|
42
|
+
const cleanId = id.startsWith('_') ? id.slice(1) : id;
|
|
43
|
+
|
|
44
|
+
return `${cleanPrefix}_${cleanId}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Create awaitingStepId by concatenating prefix and partitionKey.
|
|
49
|
+
* If prefix ends with an underscore, it's removed before concatenation.
|
|
50
|
+
* If partitionKey starts with an underscore, it's removed before concatenation.
|
|
51
|
+
* This ensures a clean "PREFIX_PARTITIONKEY" format without double underscores.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} partitionKey
|
|
54
|
+
* @param {string} [prefix='']
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
function createAwaitingStepId(partitionKey, prefix = '') {
|
|
58
|
+
return _joinPrefixAndId(partitionKey, prefix);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create pendingStepId by concatenating prefix and identifierId.
|
|
63
|
+
* If prefix ends with an underscore, it's removed before concatenation.
|
|
64
|
+
* If identifierId starts with an underscore, it's removed before concatenation.
|
|
65
|
+
* This ensures a clean "PREFIX_IDENTIFIER" format without double underscores.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} identifierId
|
|
68
|
+
* @param {string} [prefix='']
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
function createPendingStepId(identifierId, prefix = '') {
|
|
72
|
+
return _joinPrefixAndId(identifierId, prefix);
|
|
73
|
+
}
|
|
74
|
+
|
|
31
75
|
/**
|
|
32
76
|
* Create a field name for storing the unique-request id, with optional prefix.
|
|
33
77
|
* @param {string} prefix
|
|
34
78
|
* @param {string} [uniqueRequestIdFieldName='UniqueRequestId']
|
|
35
79
|
* @returns {string}
|
|
36
80
|
*/
|
|
37
|
-
|
|
81
|
+
function createFieldNameUniqueRequestId(
|
|
38
82
|
prefix,
|
|
39
83
|
uniqueRequestIdFieldName = 'UniqueRequestId'
|
|
40
84
|
) {
|
|
@@ -48,11 +92,7 @@ export function createFieldNameUniqueRequestId(
|
|
|
48
92
|
* @param {string} [prefix=""]
|
|
49
93
|
* @returns {string}
|
|
50
94
|
*/
|
|
51
|
-
|
|
52
|
-
partitionKey,
|
|
53
|
-
sortId,
|
|
54
|
-
prefix = ''
|
|
55
|
-
) {
|
|
95
|
+
function createConcatenatedAwaitingStepId(partitionKey, sortId, prefix = '') {
|
|
56
96
|
return prefix + partitionKey + '_' + sortId;
|
|
57
97
|
}
|
|
58
98
|
|
|
@@ -62,7 +102,7 @@ export function createConcatenatedAwaitingStepId(
|
|
|
62
102
|
* @param {string} childId
|
|
63
103
|
* @returns {string}
|
|
64
104
|
*/
|
|
65
|
-
|
|
105
|
+
function createConcatenatedPendingStepId(parentId, childId) {
|
|
66
106
|
return parentId + '_' + childId;
|
|
67
107
|
}
|
|
68
108
|
|
|
@@ -72,8 +112,8 @@ export function createConcatenatedPendingStepId(parentId, childId) {
|
|
|
72
112
|
* @param {string} [prefix=''] - The prefix to prepend to the parent Ids.
|
|
73
113
|
* @returns {string} The parent Flow Id created.
|
|
74
114
|
*/
|
|
75
|
-
|
|
76
|
-
return (
|
|
115
|
+
function createParentFlowId(prefix = '') {
|
|
116
|
+
return _joinPrefixAndId(identifierUuid(), prefix);
|
|
77
117
|
}
|
|
78
118
|
|
|
79
119
|
/**
|
|
@@ -84,7 +124,7 @@ export function createParentFlowId(prefix = '') {
|
|
|
84
124
|
* @returns {string}
|
|
85
125
|
* @throws {NoRetryError} If the stripped value equals the prefix (invalid)
|
|
86
126
|
*/
|
|
87
|
-
|
|
127
|
+
function explodePendingStepId(pendingStepId, prefix = '') {
|
|
88
128
|
if (!pendingStepId) throw new NoRetryError('pendingStepId is required');
|
|
89
129
|
if (!prefix) return pendingStepId;
|
|
90
130
|
|
|
@@ -129,7 +169,7 @@ export function explodePendingStepId(pendingStepId, prefix = '') {
|
|
|
129
169
|
* @returns {Promise<[UniqueRequestStatus, Attrs]>}
|
|
130
170
|
* @throws {NoRetryError} If unable to set uniqueRequestId after 2 tries
|
|
131
171
|
*/
|
|
132
|
-
|
|
172
|
+
async function checkUniqueRequestProcessing(
|
|
133
173
|
_izContext,
|
|
134
174
|
tableName,
|
|
135
175
|
primaryKey,
|
|
@@ -232,7 +272,7 @@ export async function checkUniqueRequestProcessing(
|
|
|
232
272
|
* @param {string} prefix - Field prefix used in cache fields
|
|
233
273
|
* @returns {Promise<[boolean, string|undefined]>}
|
|
234
274
|
*/
|
|
235
|
-
|
|
275
|
+
async function checkTimeCacheComplete(
|
|
236
276
|
_izContext,
|
|
237
277
|
fullMainTableName,
|
|
238
278
|
keyValues,
|
|
@@ -277,7 +317,7 @@ export async function checkTimeCacheComplete(
|
|
|
277
317
|
* @returns {Promise<[boolean, any, string|undefined]>}
|
|
278
318
|
* @throws {NoRetryError} If record cannot be fetched
|
|
279
319
|
*/
|
|
280
|
-
|
|
320
|
+
async function checkAndGetTimeCacheComplete(
|
|
281
321
|
_izContext,
|
|
282
322
|
fullMainTableName,
|
|
283
323
|
keyValues,
|
|
@@ -351,7 +391,7 @@ export async function checkAndGetTimeCacheComplete(
|
|
|
351
391
|
* @param {string} uniqueRequestIdCompleteFieldName
|
|
352
392
|
* @returns {Promise<boolean>}
|
|
353
393
|
*/
|
|
354
|
-
|
|
394
|
+
async function checkCacheUniqueRequestId(
|
|
355
395
|
_izContext,
|
|
356
396
|
fullMainTableName,
|
|
357
397
|
keyValues,
|
|
@@ -381,7 +421,7 @@ export async function checkCacheUniqueRequestId(
|
|
|
381
421
|
* @returns {Attrs|null}
|
|
382
422
|
* @throws {NoRetryError} On invalid field names or malformed startKey
|
|
383
423
|
*/
|
|
384
|
-
|
|
424
|
+
function validateStartKeyParam(
|
|
385
425
|
_izContext,
|
|
386
426
|
startKey,
|
|
387
427
|
partitionKeyFieldName,
|
|
@@ -431,7 +471,7 @@ export function validateStartKeyParam(
|
|
|
431
471
|
* @returns {Promise<void>}
|
|
432
472
|
* @throws {NoRetryError} If `numberInvocation` exceeds internal safety limit
|
|
433
473
|
*/
|
|
434
|
-
|
|
474
|
+
async function validateMultipleInvocations(
|
|
435
475
|
_izContext,
|
|
436
476
|
messageProperty,
|
|
437
477
|
passOnStartKey = {},
|
|
@@ -477,3 +517,19 @@ export async function validateMultipleInvocations(
|
|
|
477
517
|
throw err;
|
|
478
518
|
}
|
|
479
519
|
}
|
|
520
|
+
|
|
521
|
+
export {
|
|
522
|
+
createAwaitingStepId,
|
|
523
|
+
createPendingStepId,
|
|
524
|
+
createFieldNameUniqueRequestId,
|
|
525
|
+
createConcatenatedAwaitingStepId,
|
|
526
|
+
createConcatenatedPendingStepId,
|
|
527
|
+
createParentFlowId,
|
|
528
|
+
explodePendingStepId,
|
|
529
|
+
checkUniqueRequestProcessing,
|
|
530
|
+
checkTimeCacheComplete,
|
|
531
|
+
checkAndGetTimeCacheComplete,
|
|
532
|
+
checkCacheUniqueRequestId,
|
|
533
|
+
validateStartKeyParam,
|
|
534
|
+
validateMultipleInvocations
|
|
535
|
+
};
|
|
@@ -19,7 +19,10 @@ import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
|
19
19
|
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
20
20
|
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
21
21
|
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
createParentFlowId,
|
|
24
|
+
createPendingStepId
|
|
25
|
+
} from './asyncFlowSharedLib.js';
|
|
23
26
|
|
|
24
27
|
function _assertPendingStepId(pendingStepId) {
|
|
25
28
|
if (!pendingStepId) {
|
|
@@ -92,36 +95,45 @@ async function _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId) {
|
|
|
92
95
|
// One awaitingStepId can have multiple pendingStepIds awaiting it.
|
|
93
96
|
// One pendingStepId can have multiple awaitingStepIds awaiting it.
|
|
94
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Create awaiting multiple step records to block a flow until multiple steps complete.
|
|
100
|
+
* @async
|
|
101
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
102
|
+
* @param {string} pendingStepId - The ID of the pending step that is waiting.
|
|
103
|
+
* @param {Array<object>} [records=[]] - Array of step items.
|
|
104
|
+
* @param {string} [records[].awaitingStepId] - Optional ID of the awaiting step. If not provided, a random UUID will be generated.
|
|
105
|
+
* @param {object} [records[].message] - Optional message payload to publish if flowType is provided.
|
|
106
|
+
* @param {object} [records[].flowType] - Optional flowType override for this specific step record.
|
|
107
|
+
* @param {string} records[].flowType.flowTag - Tag identifying the flow.
|
|
108
|
+
* @param {string} records[].flowType.serviceTag - Tag identifying the service.
|
|
109
|
+
* @param {object} [options={}] - Optional configurations.
|
|
110
|
+
* @param {string} [options.prefix=''] - Prefix to prepend to pendingStepId.
|
|
111
|
+
* @param {object} [options.additionalAttributes={}] - Default additional attributes to associate with each pending step record.
|
|
112
|
+
* @param {object|null} [options.flowType=null] - Default flow schema/service metadata if starting external tasks.
|
|
113
|
+
* @param {string} [options.flowType.flowTag] - Tag identifying the default flow.
|
|
114
|
+
* @param {string} [options.flowType.serviceTag] - Tag identifying the default service.
|
|
115
|
+
* @returns {Promise<string|undefined>} The awaitingStepId of the first mapped record.
|
|
116
|
+
*/
|
|
95
117
|
export async function createAwaitingMultipleSteps(
|
|
96
118
|
_izContext,
|
|
97
119
|
pendingStepId,
|
|
98
120
|
records = [],
|
|
99
121
|
options = {}
|
|
100
122
|
) {
|
|
101
|
-
const {
|
|
102
|
-
prefix = '',
|
|
103
|
-
additionalAttributes = {},
|
|
104
|
-
publishConfig = null
|
|
105
|
-
} = options;
|
|
123
|
+
const { prefix = '', additionalAttributes = {}, flowType = null } = options;
|
|
106
124
|
|
|
107
125
|
_izContext.logger.debug('[Lib:AsyncFlow:createAwaitingMultipleSteps] Input', {
|
|
108
126
|
pendingStepId,
|
|
109
127
|
options
|
|
110
128
|
});
|
|
111
129
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
: `${prefix}_`
|
|
116
|
-
: '';
|
|
117
|
-
const finalPendingStepId =
|
|
118
|
-
formattedPrefix && !pendingStepId.startsWith(formattedPrefix)
|
|
119
|
-
? formattedPrefix + pendingStepId
|
|
120
|
-
: pendingStepId;
|
|
130
|
+
const finalPendingStepId = createPendingStepId(pendingStepId, prefix);
|
|
131
|
+
|
|
132
|
+
const hasFlowPublish = flowType || records.some(r => r.flowType);
|
|
121
133
|
|
|
122
134
|
let finalRecords = records;
|
|
123
135
|
|
|
124
|
-
if (finalRecords.length === 0 && !
|
|
136
|
+
if (finalRecords.length === 0 && !hasFlowPublish) {
|
|
125
137
|
finalRecords = [
|
|
126
138
|
{
|
|
127
139
|
awaitingStepId: createParentFlowId(prefix),
|
|
@@ -130,38 +142,47 @@ export async function createAwaitingMultipleSteps(
|
|
|
130
142
|
];
|
|
131
143
|
}
|
|
132
144
|
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (!Array.isArray(messages)) {
|
|
138
|
-
throw new NoRetryError('messages must be an array');
|
|
139
|
-
}
|
|
145
|
+
if (hasFlowPublish) {
|
|
146
|
+
finalRecords = records.map(record => {
|
|
147
|
+
const recordFlowType = record.flowType || flowType;
|
|
140
148
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
finalRecords = messages.map(message => {
|
|
146
|
-
const parentFlowId = createParentFlowId(prefix);
|
|
149
|
+
if (!recordFlowType || !recordFlowType.flowTag || !recordFlowType.serviceTag) {
|
|
150
|
+
throw new NoRetryError('record.flowType must have both flowTag and serviceTag');
|
|
151
|
+
}
|
|
147
152
|
|
|
153
|
+
const awaitingStepId =
|
|
154
|
+
record.awaitingStepId || createParentFlowId(prefix);
|
|
148
155
|
return {
|
|
149
|
-
awaitingStepId
|
|
156
|
+
awaitingStepId,
|
|
150
157
|
additionalAttributes,
|
|
151
158
|
message: {
|
|
152
|
-
...message,
|
|
153
|
-
parentFlowId
|
|
154
|
-
}
|
|
159
|
+
...record.message,
|
|
160
|
+
parentFlowId: awaitingStepId
|
|
161
|
+
},
|
|
162
|
+
topicArn: snsSharedLib.snsTopicArnByFlowSchema(
|
|
163
|
+
_izContext,
|
|
164
|
+
recordFlowType.flowTag,
|
|
165
|
+
recordFlowType.serviceTag
|
|
166
|
+
)
|
|
155
167
|
};
|
|
156
168
|
});
|
|
157
169
|
}
|
|
158
170
|
|
|
159
171
|
await _putAwaitingMultipleStepRecords(
|
|
160
172
|
_izContext,
|
|
161
|
-
finalRecords.map(({ awaitingStepId, additionalAttributes: itemAttrs }) =>
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
173
|
+
finalRecords.map(({ awaitingStepId, additionalAttributes: itemAttrs }) => {
|
|
174
|
+
const hasItemAttrs = itemAttrs && Object.keys(itemAttrs).length > 0;
|
|
175
|
+
const hasOptAttrs =
|
|
176
|
+
additionalAttributes && Object.keys(additionalAttributes).length > 0;
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
awaitingStepId,
|
|
180
|
+
additionalAttributes:
|
|
181
|
+
hasItemAttrs || hasOptAttrs
|
|
182
|
+
? { ...additionalAttributes, ...itemAttrs }
|
|
183
|
+
: undefined
|
|
184
|
+
};
|
|
185
|
+
}),
|
|
165
186
|
finalPendingStepId,
|
|
166
187
|
{
|
|
167
188
|
complete: false,
|
|
@@ -169,19 +190,12 @@ export async function createAwaitingMultipleSteps(
|
|
|
169
190
|
}
|
|
170
191
|
);
|
|
171
192
|
|
|
172
|
-
if (
|
|
173
|
-
const topicArn = snsSharedLib.snsTopicArnByFlowSchema(
|
|
174
|
-
_izContext,
|
|
175
|
-
publishConfig.flowType.flowTag,
|
|
176
|
-
publishConfig.flowType.serviceTag
|
|
177
|
-
);
|
|
178
|
-
|
|
193
|
+
if (hasFlowPublish) {
|
|
179
194
|
await Promise.all(
|
|
180
|
-
finalRecords.map(({ message }) =>
|
|
195
|
+
finalRecords.map(({ message, topicArn }) =>
|
|
181
196
|
sns.publishAsync(_izContext, {
|
|
182
197
|
TopicArn: `${topicArn}_In`,
|
|
183
|
-
Message: JSON.stringify(message)
|
|
184
|
-
MessageAttributes: {}
|
|
198
|
+
Message: JSON.stringify(message)
|
|
185
199
|
})
|
|
186
200
|
)
|
|
187
201
|
);
|
|
@@ -190,6 +204,15 @@ export async function createAwaitingMultipleSteps(
|
|
|
190
204
|
return finalRecords[0]?.awaitingStepId;
|
|
191
205
|
}
|
|
192
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Update an awaiting multiple step record in the Steps table.
|
|
209
|
+
* @async
|
|
210
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
211
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
212
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
213
|
+
* @param {object} data - Attributes to update.
|
|
214
|
+
* @returns {Promise<object>} The updated data with awaitingStepId merged.
|
|
215
|
+
*/
|
|
193
216
|
export async function updateAwaitingMultipleStep(
|
|
194
217
|
_izContext,
|
|
195
218
|
awaitingStepId,
|
|
@@ -216,6 +239,13 @@ export async function updateAwaitingMultipleStep(
|
|
|
216
239
|
return { ...data, awaitingStepId };
|
|
217
240
|
}
|
|
218
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Query and return the first pending step item that matches the given awaitingStepId.
|
|
244
|
+
* @async
|
|
245
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
246
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
247
|
+
* @returns {Promise<object|undefined>} The found item or undefined.
|
|
248
|
+
*/
|
|
219
249
|
export async function findPendingStepAwaitingMultipleSteps(
|
|
220
250
|
_izContext,
|
|
221
251
|
awaitingStepId
|
|
@@ -232,6 +262,13 @@ export async function findPendingStepAwaitingMultipleSteps(
|
|
|
232
262
|
return items[0];
|
|
233
263
|
}
|
|
234
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Query and return all pending step items matching the given awaitingStepId.
|
|
267
|
+
* @async
|
|
268
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
269
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
270
|
+
* @returns {Promise<Array<object>>} List of matching items.
|
|
271
|
+
*/
|
|
235
272
|
export async function findPendingStepsAwaitingMultipleSteps(
|
|
236
273
|
_izContext,
|
|
237
274
|
awaitingStepId
|
|
@@ -239,6 +276,13 @@ export async function findPendingStepsAwaitingMultipleSteps(
|
|
|
239
276
|
return _queryPendingStepsByAwaitingStepId(_izContext, awaitingStepId);
|
|
240
277
|
}
|
|
241
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Retrieve the pendingStepId of the first step matching the given awaitingStepId.
|
|
281
|
+
* @async
|
|
282
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
283
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
284
|
+
* @returns {Promise<string|undefined>} The pendingStepId of the first item found.
|
|
285
|
+
*/
|
|
242
286
|
export async function findPendingStepIdAwaitingMultipleSteps(
|
|
243
287
|
_izContext,
|
|
244
288
|
awaitingStepId
|
|
@@ -250,6 +294,13 @@ export async function findPendingStepIdAwaitingMultipleSteps(
|
|
|
250
294
|
return items[0]?.pendingStepId;
|
|
251
295
|
}
|
|
252
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Query and return all awaiting steps matching the given pendingStepId from byPending index table.
|
|
299
|
+
* @async
|
|
300
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
301
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
302
|
+
* @returns {Promise<Array<object>>} List of matching items.
|
|
303
|
+
*/
|
|
253
304
|
export async function findAwaitingMultipleStepByPending(
|
|
254
305
|
_izContext,
|
|
255
306
|
pendingStepId
|
|
@@ -257,13 +308,26 @@ export async function findAwaitingMultipleStepByPending(
|
|
|
257
308
|
return _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId);
|
|
258
309
|
}
|
|
259
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Check if all awaiting steps for a pendingStepId are completed. If a current awaitingStepId
|
|
313
|
+
* is provided, it updates its status to complete and returns values/errors.
|
|
314
|
+
* @async
|
|
315
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
316
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
317
|
+
* @param {string|null} [currentAwaitingStepId=null] - The ID of the current awaiting step that completed.
|
|
318
|
+
* @param {Array<any>} [errorsFound=[]] - Errors collected from the current step.
|
|
319
|
+
* @param {object} [returnValues={}] - Values returned from the current step.
|
|
320
|
+
* @param {object} [settings={ checkIsAllError: false }] - Execution settings.
|
|
321
|
+
* @param {boolean} [settings.checkIsAllError=false] - Whether to verify if all steps failed.
|
|
322
|
+
* @returns {Promise<object>} Status object containing isComplete, collectedAttributes, collectedErrors, returnValues, additionalAttributes, etc.
|
|
323
|
+
*/
|
|
260
324
|
export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
261
325
|
_izContext,
|
|
262
326
|
pendingStepId,
|
|
263
327
|
currentAwaitingStepId = null,
|
|
264
328
|
errorsFound = [],
|
|
265
329
|
returnValues = {},
|
|
266
|
-
settings = { checkIsAllError:
|
|
330
|
+
settings = { checkIsAllError: false }
|
|
267
331
|
) {
|
|
268
332
|
_izContext.logger.debug(
|
|
269
333
|
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Input parameters',
|
|
@@ -346,6 +410,13 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
346
410
|
};
|
|
347
411
|
}
|
|
348
412
|
|
|
413
|
+
/**
|
|
414
|
+
* Clean up/delete all awaiting multiple steps records associated with the pendingStepId from both tables.
|
|
415
|
+
* @async
|
|
416
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
417
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
418
|
+
* @returns {Promise<boolean>} True if operations completed successfully.
|
|
419
|
+
*/
|
|
349
420
|
export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
350
421
|
_izContext.logger.debug('[Lib:clearAllAwaitingSteps] Input parameters', {
|
|
351
422
|
pendingStepId
|
|
@@ -382,6 +453,15 @@ export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
|
382
453
|
return true;
|
|
383
454
|
}
|
|
384
455
|
|
|
456
|
+
/**
|
|
457
|
+
* Delete a specific awaiting step from Steps table (and optionally from byPending table if no errors found).
|
|
458
|
+
* @async
|
|
459
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
460
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
461
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
462
|
+
* @param {Array<any>} [errorsFound=[]] - List of errors. If empty, the record is removed from byPending too.
|
|
463
|
+
* @returns {Promise<void>}
|
|
464
|
+
*/
|
|
385
465
|
export async function removeAwaitingMultipleStep(
|
|
386
466
|
_izContext,
|
|
387
467
|
awaitingStepId,
|
package/src/awaitingStep.js
CHANGED
|
@@ -47,6 +47,16 @@ async function _findSinglePendingStep(_izContext, awaitingStepId) {
|
|
|
47
47
|
// AwaitingStep flow awaiting one external flow, will continue its flow once one external flow completes.
|
|
48
48
|
// One awaitingStepId can have multiple pendingStepIds awaiting it.
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Create a single awaiting step record to block a flow until a specific external flow step completes.
|
|
52
|
+
* @async
|
|
53
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
54
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
55
|
+
* @param {string} pendingStepId - The ID of the pending step that is waiting.
|
|
56
|
+
* @param {object} [additionalAttributes={}] - Additional attributes to save with the record.
|
|
57
|
+
* @param {object} [callingFlowConfig={}] - Calling flow configuration.
|
|
58
|
+
* @returns {Promise<void>}
|
|
59
|
+
*/
|
|
50
60
|
export async function createAwaitingStep(
|
|
51
61
|
_izContext,
|
|
52
62
|
awaitingStepId,
|
|
@@ -80,10 +90,27 @@ export async function createAwaitingStep(
|
|
|
80
90
|
);
|
|
81
91
|
}
|
|
82
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Query and return the single pending step item that matches the given awaitingStepId.
|
|
95
|
+
* @async
|
|
96
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
97
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
98
|
+
* @returns {Promise<object>} The found pending step record.
|
|
99
|
+
* @throws {NoRetryError} If awaitingStepId is missing or if not exactly one record is found.
|
|
100
|
+
*/
|
|
83
101
|
export async function findPendingStep(_izContext, awaitingStepId) {
|
|
84
102
|
return _findSinglePendingStep(_izContext, awaitingStepId);
|
|
85
103
|
}
|
|
86
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Delete a specific awaiting step record from AwaitingStep table.
|
|
107
|
+
* @async
|
|
108
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
109
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
110
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
111
|
+
* @returns {Promise<void>}
|
|
112
|
+
* @throws {NoRetryError} If awaitingStepId or pendingStepId is missing.
|
|
113
|
+
*/
|
|
87
114
|
export async function removeAwaitingStep(
|
|
88
115
|
_izContext,
|
|
89
116
|
awaitingStepId,
|
|
@@ -105,6 +132,17 @@ export async function removeAwaitingStep(
|
|
|
105
132
|
);
|
|
106
133
|
}
|
|
107
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Delete an awaiting step record from AwaitingStep table, conditional on uniqueRequestId.
|
|
137
|
+
* @async
|
|
138
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
139
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
140
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
141
|
+
* @param {string} checkUniqueRequestId - The uniqueRequestId to check.
|
|
142
|
+
* @param {string} [prefix=''] - Prefix for uniqueRequestId field name.
|
|
143
|
+
* @returns {Promise<void>}
|
|
144
|
+
* @throws {NoRetryError} If required arguments are missing.
|
|
145
|
+
*/
|
|
108
146
|
export async function removeAwaitingStepWithCheckUniqueRequestId(
|
|
109
147
|
_izContext,
|
|
110
148
|
awaitingStepId,
|