@izara_project/izara-core-library-asynchronous-flow 1.0.38 → 1.0.40
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 +3 -13
- package/src/asyncFlowSharedLib.js +36 -55
- package/src/awaitingMultipleSteps.js +120 -37
- package/src/awaitingStep.js +39 -19
package/package.json
CHANGED
|
@@ -3,34 +3,25 @@
|
|
|
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.40",
|
|
7
7
|
"description": "Shared asynchronous flow logic",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": "./index.js"
|
|
12
12
|
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"test": "jest"
|
|
15
|
-
},
|
|
16
13
|
"repository": {
|
|
17
14
|
"type": "git",
|
|
18
15
|
"url": "git+ssh://git@bitbucket.org/izara-core-libraries/izara-core-library-asynchronous-flow.git"
|
|
19
16
|
},
|
|
20
|
-
"jest": {
|
|
21
|
-
"testEnvironment": "node"
|
|
22
|
-
},
|
|
23
17
|
"devDependencies": {
|
|
24
|
-
"@aws-sdk/client-s3": "^3.1077.0",
|
|
25
18
|
"@izara_project/izara-core-library-core": "^1.0.32",
|
|
26
19
|
"@izara_project/izara-core-library-dynamodb": "^1.0.20",
|
|
27
20
|
"@izara_project/izara-core-library-external-request": "^1.0.30",
|
|
28
21
|
"@izara_project/izara-core-library-logger": "^1.0.9",
|
|
29
22
|
"@izara_project/izara-core-library-sns": "^1.0.8",
|
|
30
23
|
"@izara_project/izara-core-library-sqs": "^1.0.7",
|
|
31
|
-
"@izara_project/izara-shared-core": "^1.0.13"
|
|
32
|
-
"jest": "^30.4.2",
|
|
33
|
-
"ws": "^8.21.0"
|
|
24
|
+
"@izara_project/izara-shared-core": "^1.0.13"
|
|
34
25
|
},
|
|
35
26
|
"peerDependencies": {
|
|
36
27
|
"@izara_project/izara-core-library-core": "^1.0.32",
|
|
@@ -40,6 +31,5 @@
|
|
|
40
31
|
"@izara_project/izara-core-library-sns": "^1.0.8",
|
|
41
32
|
"@izara_project/izara-core-library-sqs": "^1.0.7",
|
|
42
33
|
"@izara_project/izara-shared-core": "^1.0.12"
|
|
43
|
-
}
|
|
44
|
-
"peerDependenciesMeta": {}
|
|
34
|
+
}
|
|
45
35
|
}
|
|
@@ -28,13 +28,20 @@ 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
|
+
function createAwaitingStepId(partitionKey, prefix = '') {
|
|
32
|
+
return prefix + partitionKey;
|
|
33
|
+
}
|
|
34
|
+
function createPendingStepId(identifierId, prefix = '') {
|
|
35
|
+
return prefix + identifierId;
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
/**
|
|
32
39
|
* Create a field name for storing the unique-request id, with optional prefix.
|
|
33
40
|
* @param {string} prefix
|
|
34
41
|
* @param {string} [uniqueRequestIdFieldName='UniqueRequestId']
|
|
35
42
|
* @returns {string}
|
|
36
43
|
*/
|
|
37
|
-
|
|
44
|
+
function createFieldNameUniqueRequestId(
|
|
38
45
|
prefix,
|
|
39
46
|
uniqueRequestIdFieldName = 'UniqueRequestId'
|
|
40
47
|
) {
|
|
@@ -48,11 +55,7 @@ export function createFieldNameUniqueRequestId(
|
|
|
48
55
|
* @param {string} [prefix=""]
|
|
49
56
|
* @returns {string}
|
|
50
57
|
*/
|
|
51
|
-
|
|
52
|
-
partitionKey,
|
|
53
|
-
sortId,
|
|
54
|
-
prefix = ''
|
|
55
|
-
) {
|
|
58
|
+
function createConcatenatedAwaitingStepId(partitionKey, sortId, prefix = '') {
|
|
56
59
|
return prefix + partitionKey + '_' + sortId;
|
|
57
60
|
}
|
|
58
61
|
|
|
@@ -62,37 +65,17 @@ export function createConcatenatedAwaitingStepId(
|
|
|
62
65
|
* @param {string} childId
|
|
63
66
|
* @returns {string}
|
|
64
67
|
*/
|
|
65
|
-
|
|
68
|
+
function createConcatenatedPendingStepId(parentId, childId) {
|
|
66
69
|
return parentId + '_' + childId;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
/**
|
|
70
|
-
* Create a simple awaitingStepId (prefix + partitionKey).
|
|
71
|
-
* @param {string} partitionKey
|
|
72
|
-
* @param {string} [prefix=""]
|
|
73
|
-
* @returns {string}
|
|
74
|
-
*/
|
|
75
|
-
export function createAwaitingStepId(partitionKey, prefix = '') {
|
|
76
|
-
return prefix + partitionKey;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Create a simple pendingStepId (prefix + identifierId).
|
|
81
|
-
* @param {string} identifierId
|
|
82
|
-
* @param {string} [prefix=""]
|
|
83
|
-
* @returns {string}
|
|
84
|
-
*/
|
|
85
|
-
export function createPendingStepId(identifierId, prefix = '') {
|
|
86
|
-
return prefix + identifierId;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
72
|
/**
|
|
90
73
|
* Create parent Flow Id.
|
|
91
74
|
* @async
|
|
92
75
|
* @param {string} [prefix=''] - The prefix to prepend to the parent Ids.
|
|
93
76
|
* @returns {string} The parent Flow Id created.
|
|
94
77
|
*/
|
|
95
|
-
|
|
78
|
+
function createParentFlowId(prefix = '') {
|
|
96
79
|
return (prefix ? `${prefix}_` : '') + identifierUuid();
|
|
97
80
|
}
|
|
98
81
|
|
|
@@ -104,7 +87,7 @@ export function createParentFlowId(prefix = '') {
|
|
|
104
87
|
* @returns {string}
|
|
105
88
|
* @throws {NoRetryError} If the stripped value equals the prefix (invalid)
|
|
106
89
|
*/
|
|
107
|
-
|
|
90
|
+
function explodePendingStepId(pendingStepId, prefix = '') {
|
|
108
91
|
if (!pendingStepId) throw new NoRetryError('pendingStepId is required');
|
|
109
92
|
if (!prefix) return pendingStepId;
|
|
110
93
|
|
|
@@ -117,24 +100,6 @@ export function explodePendingStepId(pendingStepId, prefix = '') {
|
|
|
117
100
|
}
|
|
118
101
|
|
|
119
102
|
// copy from izara-core-library-trigger-cache
|
|
120
|
-
/**
|
|
121
|
-
* Build the field name that stores "cache complete" marker.
|
|
122
|
-
* @param {string} [prefix='cache']
|
|
123
|
-
* @returns {string}
|
|
124
|
-
*/
|
|
125
|
-
export function createFieldNameCacheComplete(prefix = 'cache') {
|
|
126
|
-
return prefix + 'CacheComplete';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Build the field name that stores a cache "status".
|
|
131
|
-
* @param {string} [prefix='cache']
|
|
132
|
-
* @returns {string}
|
|
133
|
-
*/
|
|
134
|
-
export function createFieldNameStatus(prefix = 'cache') {
|
|
135
|
-
return prefix + 'Status';
|
|
136
|
-
}
|
|
137
|
-
|
|
138
103
|
/**
|
|
139
104
|
* Checks if record has uniqueRequestId set, if not set to this requests uniqueRequestId and continue to process
|
|
140
105
|
* if already set check if matches this request uniqueRequestId, if yes continue to process, if not then stop processing
|
|
@@ -167,7 +132,7 @@ export function createFieldNameStatus(prefix = 'cache') {
|
|
|
167
132
|
* @returns {Promise<[UniqueRequestStatus, Attrs]>}
|
|
168
133
|
* @throws {NoRetryError} If unable to set uniqueRequestId after 2 tries
|
|
169
134
|
*/
|
|
170
|
-
|
|
135
|
+
async function checkUniqueRequestProcessing(
|
|
171
136
|
_izContext,
|
|
172
137
|
tableName,
|
|
173
138
|
primaryKey,
|
|
@@ -270,7 +235,7 @@ export async function checkUniqueRequestProcessing(
|
|
|
270
235
|
* @param {string} prefix - Field prefix used in cache fields
|
|
271
236
|
* @returns {Promise<[boolean, string|undefined]>}
|
|
272
237
|
*/
|
|
273
|
-
|
|
238
|
+
async function checkTimeCacheComplete(
|
|
274
239
|
_izContext,
|
|
275
240
|
fullMainTableName,
|
|
276
241
|
keyValues,
|
|
@@ -315,7 +280,7 @@ export async function checkTimeCacheComplete(
|
|
|
315
280
|
* @returns {Promise<[boolean, any, string|undefined]>}
|
|
316
281
|
* @throws {NoRetryError} If record cannot be fetched
|
|
317
282
|
*/
|
|
318
|
-
|
|
283
|
+
async function checkAndGetTimeCacheComplete(
|
|
319
284
|
_izContext,
|
|
320
285
|
fullMainTableName,
|
|
321
286
|
keyValues,
|
|
@@ -333,8 +298,8 @@ export async function checkAndGetTimeCacheComplete(
|
|
|
333
298
|
);
|
|
334
299
|
|
|
335
300
|
const uniqueRequestIdFieldName = createFieldNameUniqueRequestId('cache');
|
|
336
|
-
const cacheCompleteFieldName =
|
|
337
|
-
const statusFieldName =
|
|
301
|
+
const cacheCompleteFieldName = prefix + 'CacheComplete';
|
|
302
|
+
const statusFieldName = prefix + 'Status';
|
|
338
303
|
|
|
339
304
|
let getTimeCacheComplete = await dynamodbSharedLib.getItem(
|
|
340
305
|
_izContext,
|
|
@@ -389,7 +354,7 @@ export async function checkAndGetTimeCacheComplete(
|
|
|
389
354
|
* @param {string} uniqueRequestIdCompleteFieldName
|
|
390
355
|
* @returns {Promise<boolean>}
|
|
391
356
|
*/
|
|
392
|
-
|
|
357
|
+
async function checkCacheUniqueRequestId(
|
|
393
358
|
_izContext,
|
|
394
359
|
fullMainTableName,
|
|
395
360
|
keyValues,
|
|
@@ -419,7 +384,7 @@ export async function checkCacheUniqueRequestId(
|
|
|
419
384
|
* @returns {Attrs|null}
|
|
420
385
|
* @throws {NoRetryError} On invalid field names or malformed startKey
|
|
421
386
|
*/
|
|
422
|
-
|
|
387
|
+
function validateStartKeyParam(
|
|
423
388
|
_izContext,
|
|
424
389
|
startKey,
|
|
425
390
|
partitionKeyFieldName,
|
|
@@ -469,7 +434,7 @@ export function validateStartKeyParam(
|
|
|
469
434
|
* @returns {Promise<void>}
|
|
470
435
|
* @throws {NoRetryError} If `numberInvocation` exceeds internal safety limit
|
|
471
436
|
*/
|
|
472
|
-
|
|
437
|
+
async function validateMultipleInvocations(
|
|
473
438
|
_izContext,
|
|
474
439
|
messageProperty,
|
|
475
440
|
passOnStartKey = {},
|
|
@@ -515,3 +480,19 @@ export async function validateMultipleInvocations(
|
|
|
515
480
|
throw err;
|
|
516
481
|
}
|
|
517
482
|
}
|
|
483
|
+
|
|
484
|
+
export {
|
|
485
|
+
createAwaitingStepId,
|
|
486
|
+
createPendingStepId,
|
|
487
|
+
createFieldNameUniqueRequestId,
|
|
488
|
+
createConcatenatedAwaitingStepId,
|
|
489
|
+
createConcatenatedPendingStepId,
|
|
490
|
+
createParentFlowId,
|
|
491
|
+
explodePendingStepId,
|
|
492
|
+
checkUniqueRequestProcessing,
|
|
493
|
+
checkTimeCacheComplete,
|
|
494
|
+
checkAndGetTimeCacheComplete,
|
|
495
|
+
checkCacheUniqueRequestId,
|
|
496
|
+
validateStartKeyParam,
|
|
497
|
+
validateMultipleInvocations
|
|
498
|
+
};
|
|
@@ -92,6 +92,22 @@ async function _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId) {
|
|
|
92
92
|
// One awaitingStepId can have multiple pendingStepIds awaiting it.
|
|
93
93
|
// One pendingStepId can have multiple awaitingStepIds awaiting it.
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Create awaiting multiple step records to block a flow until multiple steps complete.
|
|
97
|
+
* @async
|
|
98
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
99
|
+
* @param {string} pendingStepId - The ID of the pending step that is waiting.
|
|
100
|
+
* @param {Array<object>} [records=[]] - Array of step items containing awaitingStepId and optional attributes.
|
|
101
|
+
* @param {object} [options={}] - Optional configurations.
|
|
102
|
+
* @param {string} [options.prefix=''] - Prefix to prepend to pendingStepId.
|
|
103
|
+
* @param {object} [options.additionalAttributes={}] - Additional attributes to associate with each pending step record.
|
|
104
|
+
* @param {object} [options.publishConfig=null] - SQS/SNS publish configuration if starting external tasks.
|
|
105
|
+
* @param {Array<object>} options.publishConfig.messages - Messages to publish.
|
|
106
|
+
* @param {object} options.publishConfig.flowType - Flow schema/service metadata.
|
|
107
|
+
* @param {string} options.publishConfig.flowType.flowTag - Tag identifying the flow.
|
|
108
|
+
* @param {string} options.publishConfig.flowType.serviceTag - Tag identifying the service.
|
|
109
|
+
* @returns {Promise<string|undefined>} The awaitingStepId of the first mapped record.
|
|
110
|
+
*/
|
|
95
111
|
export async function createAwaitingMultipleSteps(
|
|
96
112
|
_izContext,
|
|
97
113
|
pendingStepId,
|
|
@@ -109,7 +125,11 @@ export async function createAwaitingMultipleSteps(
|
|
|
109
125
|
options
|
|
110
126
|
});
|
|
111
127
|
|
|
112
|
-
const formattedPrefix = prefix
|
|
128
|
+
const formattedPrefix = prefix
|
|
129
|
+
? prefix.endsWith('_')
|
|
130
|
+
? prefix
|
|
131
|
+
: `${prefix}_`
|
|
132
|
+
: '';
|
|
113
133
|
const finalPendingStepId =
|
|
114
134
|
formattedPrefix && !pendingStepId.startsWith(formattedPrefix)
|
|
115
135
|
? formattedPrefix + pendingStepId
|
|
@@ -154,10 +174,19 @@ export async function createAwaitingMultipleSteps(
|
|
|
154
174
|
|
|
155
175
|
await _putAwaitingMultipleStepRecords(
|
|
156
176
|
_izContext,
|
|
157
|
-
finalRecords.map(({ awaitingStepId, additionalAttributes: itemAttrs }) =>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
177
|
+
finalRecords.map(({ awaitingStepId, additionalAttributes: itemAttrs }) => {
|
|
178
|
+
const hasItemAttrs = itemAttrs && Object.keys(itemAttrs).length > 0;
|
|
179
|
+
const hasOptAttrs =
|
|
180
|
+
additionalAttributes && Object.keys(additionalAttributes).length > 0;
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
awaitingStepId,
|
|
184
|
+
additionalAttributes:
|
|
185
|
+
hasItemAttrs || hasOptAttrs
|
|
186
|
+
? { ...additionalAttributes, ...itemAttrs }
|
|
187
|
+
: undefined
|
|
188
|
+
};
|
|
189
|
+
}),
|
|
161
190
|
finalPendingStepId,
|
|
162
191
|
{
|
|
163
192
|
complete: false,
|
|
@@ -186,44 +215,48 @@ export async function createAwaitingMultipleSteps(
|
|
|
186
215
|
return finalRecords[0]?.awaitingStepId;
|
|
187
216
|
}
|
|
188
217
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
218
|
+
/**
|
|
219
|
+
* Update an awaiting multiple step record in the Steps table.
|
|
220
|
+
* @async
|
|
221
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
222
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
223
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
224
|
+
* @param {object} data - Attributes to update.
|
|
225
|
+
* @returns {Promise<object>} The updated data with awaitingStepId merged.
|
|
226
|
+
*/
|
|
227
|
+
export async function updateAwaitingMultipleStep(
|
|
198
228
|
_izContext,
|
|
229
|
+
awaitingStepId,
|
|
199
230
|
pendingStepId,
|
|
200
|
-
|
|
201
|
-
additionalAttributes = {}
|
|
231
|
+
data
|
|
202
232
|
) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
233
|
+
const tableSteps = dynamodbSharedLib.tableName(
|
|
234
|
+
_izContext,
|
|
235
|
+
'AwaitingMultipleSteps'
|
|
236
|
+
);
|
|
208
237
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
additionalAttributes,
|
|
220
|
-
publishConfig: {
|
|
221
|
-
messages,
|
|
222
|
-
flowType
|
|
223
|
-
}
|
|
238
|
+
await dynamodbSharedLib.updateItem(
|
|
239
|
+
_izContext,
|
|
240
|
+
tableSteps,
|
|
241
|
+
{ awaitingStepId, pendingStepId },
|
|
242
|
+
data
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
_izContext.logger.debug('[Lib:updateAwaitingMultipleStep] Output', {
|
|
246
|
+
awaitingStepId,
|
|
247
|
+
data
|
|
224
248
|
});
|
|
249
|
+
|
|
250
|
+
return { ...data, awaitingStepId };
|
|
225
251
|
}
|
|
226
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Query and return the first pending step item that matches the given awaitingStepId.
|
|
255
|
+
* @async
|
|
256
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
257
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
258
|
+
* @returns {Promise<object|undefined>} The found item or undefined.
|
|
259
|
+
*/
|
|
227
260
|
export async function findPendingStepAwaitingMultipleSteps(
|
|
228
261
|
_izContext,
|
|
229
262
|
awaitingStepId
|
|
@@ -240,6 +273,13 @@ export async function findPendingStepAwaitingMultipleSteps(
|
|
|
240
273
|
return items[0];
|
|
241
274
|
}
|
|
242
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Query and return all pending step items matching the given awaitingStepId.
|
|
278
|
+
* @async
|
|
279
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
280
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
281
|
+
* @returns {Promise<Array<object>>} List of matching items.
|
|
282
|
+
*/
|
|
243
283
|
export async function findPendingStepsAwaitingMultipleSteps(
|
|
244
284
|
_izContext,
|
|
245
285
|
awaitingStepId
|
|
@@ -247,6 +287,13 @@ export async function findPendingStepsAwaitingMultipleSteps(
|
|
|
247
287
|
return _queryPendingStepsByAwaitingStepId(_izContext, awaitingStepId);
|
|
248
288
|
}
|
|
249
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Retrieve the pendingStepId of the first step matching the given awaitingStepId.
|
|
292
|
+
* @async
|
|
293
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
294
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
295
|
+
* @returns {Promise<string|undefined>} The pendingStepId of the first item found.
|
|
296
|
+
*/
|
|
250
297
|
export async function findPendingStepIdAwaitingMultipleSteps(
|
|
251
298
|
_izContext,
|
|
252
299
|
awaitingStepId
|
|
@@ -258,6 +305,13 @@ export async function findPendingStepIdAwaitingMultipleSteps(
|
|
|
258
305
|
return items[0]?.pendingStepId;
|
|
259
306
|
}
|
|
260
307
|
|
|
308
|
+
/**
|
|
309
|
+
* Query and return all awaiting steps matching the given pendingStepId from byPending index table.
|
|
310
|
+
* @async
|
|
311
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
312
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
313
|
+
* @returns {Promise<Array<object>>} List of matching items.
|
|
314
|
+
*/
|
|
261
315
|
export async function findAwaitingMultipleStepByPending(
|
|
262
316
|
_izContext,
|
|
263
317
|
pendingStepId
|
|
@@ -265,13 +319,26 @@ export async function findAwaitingMultipleStepByPending(
|
|
|
265
319
|
return _queryAwaitingStepsByPendingStepId(_izContext, pendingStepId);
|
|
266
320
|
}
|
|
267
321
|
|
|
322
|
+
/**
|
|
323
|
+
* Check if all awaiting steps for a pendingStepId are completed. If a current awaitingStepId
|
|
324
|
+
* is provided, it updates its status to complete and returns values/errors.
|
|
325
|
+
* @async
|
|
326
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
327
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
328
|
+
* @param {string|null} [currentAwaitingStepId=null] - The ID of the current awaiting step that completed.
|
|
329
|
+
* @param {Array<any>} [errorsFound=[]] - Errors collected from the current step.
|
|
330
|
+
* @param {object} [returnValues={}] - Values returned from the current step.
|
|
331
|
+
* @param {object} [settings={ checkIsAllError: false }] - Execution settings.
|
|
332
|
+
* @param {boolean} [settings.checkIsAllError=false] - Whether to verify if all steps failed.
|
|
333
|
+
* @returns {Promise<object>} Status object containing isComplete, collectedAttributes, collectedErrors, returnValues, additionalAttributes, etc.
|
|
334
|
+
*/
|
|
268
335
|
export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
269
336
|
_izContext,
|
|
270
337
|
pendingStepId,
|
|
271
338
|
currentAwaitingStepId = null,
|
|
272
339
|
errorsFound = [],
|
|
273
340
|
returnValues = {},
|
|
274
|
-
settings = { checkIsAllError:
|
|
341
|
+
settings = { checkIsAllError: false }
|
|
275
342
|
) {
|
|
276
343
|
_izContext.logger.debug(
|
|
277
344
|
'[Lib:checkAllAwaitingStepsFinishedWithReturnParams] Input parameters',
|
|
@@ -354,6 +421,13 @@ export async function checkAllAwaitingStepsFinishedWithReturnParams(
|
|
|
354
421
|
};
|
|
355
422
|
}
|
|
356
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Clean up/delete all awaiting multiple steps records associated with the pendingStepId from both tables.
|
|
426
|
+
* @async
|
|
427
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
428
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
429
|
+
* @returns {Promise<boolean>} True if operations completed successfully.
|
|
430
|
+
*/
|
|
357
431
|
export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
358
432
|
_izContext.logger.debug('[Lib:clearAllAwaitingSteps] Input parameters', {
|
|
359
433
|
pendingStepId
|
|
@@ -390,6 +464,15 @@ export async function clearAllAwaitingSteps(_izContext, pendingStepId) {
|
|
|
390
464
|
return true;
|
|
391
465
|
}
|
|
392
466
|
|
|
467
|
+
/**
|
|
468
|
+
* Delete a specific awaiting step from Steps table (and optionally from byPending table if no errors found).
|
|
469
|
+
* @async
|
|
470
|
+
* @param {IzContext} _izContext - The Izara context.
|
|
471
|
+
* @param {string} awaitingStepId - The ID of the awaiting step.
|
|
472
|
+
* @param {string} pendingStepId - The ID of the pending step.
|
|
473
|
+
* @param {Array<any>} [errorsFound=[]] - List of errors. If empty, the record is removed from byPending too.
|
|
474
|
+
* @returns {Promise<void>}
|
|
475
|
+
*/
|
|
393
476
|
export async function removeAwaitingMultipleStep(
|
|
394
477
|
_izContext,
|
|
395
478
|
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,28 +90,27 @@ export async function createAwaitingStep(
|
|
|
80
90
|
);
|
|
81
91
|
}
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
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
|
+
*/
|
|
91
101
|
export async function findPendingStep(_izContext, awaitingStepId) {
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export async function findPendingStepAwaitingStepWithCallingFlow(
|
|
96
|
-
_izContext,
|
|
97
|
-
awaitingStepId
|
|
98
|
-
) {
|
|
99
|
-
const awaitingStep = await findPendingStep(_izContext, awaitingStepId);
|
|
100
|
-
const { callingFlowConfig = null, ...restAwaitingStep } = awaitingStep;
|
|
101
|
-
|
|
102
|
-
return [restAwaitingStep, callingFlowConfig];
|
|
102
|
+
return _findSinglePendingStep(_izContext, awaitingStepId);
|
|
103
103
|
}
|
|
104
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
|
+
*/
|
|
105
114
|
export async function removeAwaitingStep(
|
|
106
115
|
_izContext,
|
|
107
116
|
awaitingStepId,
|
|
@@ -123,6 +132,17 @@ export async function removeAwaitingStep(
|
|
|
123
132
|
);
|
|
124
133
|
}
|
|
125
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
|
+
*/
|
|
126
146
|
export async function removeAwaitingStepWithCheckUniqueRequestId(
|
|
127
147
|
_izContext,
|
|
128
148
|
awaitingStepId,
|