@izara_project/izara-core-generate-service-code 1.0.47 → 1.0.48

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": "@izara_project/izara-core-generate-service-code",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
4
4
  "description": "Code for locally generating per service files",
5
5
  "homepage": "https://bitbucket.org/izara-core-support-services/izara-core-support-services-generate-service-code#readme",
6
6
  "repository": {
@@ -20,7 +20,8 @@ import fs from 'fs';
20
20
  import yaml from 'yaml';
21
21
  import libs from '#libs/Libs.js';
22
22
  import utils from '#libs/Utils.js';
23
- const { firstLetterUpperCase: upperCase, firstLetterLowerCase: lowerCase } = utils;
23
+ const { firstLetterUpperCase: upperCase, firstLetterLowerCase: lowerCase } =
24
+ utils;
24
25
  import consts from '#libs/Consts.js';
25
26
  const { SOURCE_PATH, HANDLER, RESOURCE_CLASSES, SNS_RESOURCE } = consts;
26
27
 
@@ -54,7 +55,6 @@ const {
54
55
  // import handlerSendPlugIn from './afterFirstFlowStep/sendPlugIn/handler/handler.js';
55
56
  // import mainFunctionSendPlugIn from './afterFirstFlowStep/sendPlugIn/mainFunction/main.js';
56
57
 
57
-
58
58
  /**
59
59
  * Generates code from templates based on object schemas
60
60
  * @param {Object} _izContext
@@ -69,7 +69,7 @@ async function generatePlunIg(
69
69
  rootServicePath,
70
70
  appPath,
71
71
  allObjSchemas,
72
- allLocalFlowSchemas,
72
+ allLocalFlowSchemas
73
73
  ) {
74
74
  const allCreateSourceParams = [];
75
75
 
@@ -79,18 +79,22 @@ async function generatePlunIg(
79
79
  ? allObjSchemas.length
80
80
  : 0;
81
81
 
82
-
83
82
  console.info(`[plugIn] start totalSchemas=${totalSchemas}`);
84
83
  if (totalSchemas === 0) return [];
85
84
 
86
- const configPath = path.join(rootServicePath, 'config/serverless.config.yml');
85
+ const configPath = path.join(
86
+ rootServicePath,
87
+ 'config/serverless.config.yml'
88
+ );
87
89
  const serverlessConfig = fs.readFileSync(configPath, 'utf8');
88
90
  const config = yaml.parse(serverlessConfig);
89
91
  const serviceTag = config.main_config.iz_serviceTag;
90
92
 
91
93
  for (const flowSchema of allLocalFlowSchemas) {
92
- for (const [flowStepName, flowStepConfig] of Object.entries(flowSchema.flowSteps)) {
93
- if (flowStepName === "In" || flowStepName === "Out") continue;
94
+ for (const [flowStepName, flowStepConfig] of Object.entries(
95
+ flowSchema.flowSteps
96
+ )) {
97
+ if (flowStepName === 'In' || flowStepName === 'Out') continue;
94
98
 
95
99
  const flowTag = flowSchema.flowTag;
96
100
  const roleName = upperCase(flowTag);
@@ -104,7 +108,7 @@ async function generatePlunIg(
104
108
  resourceApis,
105
109
  hookTagSetting: `${flowSchema.flowTag}FunctionSetting`,
106
110
  functionName: upperCase(flowSchema.flowTag) + upperCase(flowStepName),
107
- roleName,
111
+ roleName
108
112
  };
109
113
 
110
114
  resolveHandlerConfig(
@@ -123,21 +127,25 @@ async function generatePlunIg(
123
127
  upperCase(flowSchema.flowTag),
124
128
  upperCase(flowStepName),
125
129
  'source/',
126
- `${upperCase(flowTag)}${upperCase(flowStepName)}_${upperCase(data.handlerType)}`,
130
+ `${upperCase(flowTag)}${upperCase(flowStepName)}_${upperCase(data.handlerType)}`
127
131
  ),
128
- functionNameConfig: upperCase(flowSchema.flowTag) +
132
+ functionNameConfig:
133
+ upperCase(flowSchema.flowTag) +
129
134
  upperCase(flowStepName) +
130
135
  upperCase(data.handlerType),
131
136
  event: resourceNames(
132
137
  RESOURCE_CLASSES.sqs,
138
+ upperCase(flowSchema.flowTag) +
139
+ upperCase(flowStepName) +
140
+ upperCase(data.handlerType)
141
+ ),
142
+ queueName:
133
143
  upperCase(flowSchema.flowTag) +
134
144
  upperCase(flowStepName) +
135
- upperCase(data.handlerType)),
136
- queueName: upperCase(flowSchema.flowTag) + upperCase(flowStepName) + upperCase(data.handlerType),
145
+ upperCase(data.handlerType),
137
146
  topicName: upperCase(flowSchema.flowTag) + upperCase(flowStepName)
138
147
  });
139
148
 
140
-
141
149
  // ── branch into the three helpers ──────────────────────────────────
142
150
  if (flowStepConfig.plugInHooks?.length) {
143
151
  for (let i = 0; i < flowStepConfig.plugInHooks.length; i++) {
@@ -169,29 +177,26 @@ async function generatePlunIg(
169
177
  allCreateSourceParams.push(...noHookResults);
170
178
  }
171
179
 
172
- if (flowStepConfig.hasOwnProperty("settings")) {
173
- data["handleLogic"] = flowStepConfig.settings.handleLogic;
174
- data["childFlow"] = flowStepConfig.settings.flowType;
180
+ if (flowStepConfig.hasOwnProperty('settings')) {
181
+ data['handleLogic'] = flowStepConfig.settings.handleLogic;
182
+ data['childFlow'] = flowStepConfig.settings.flowType;
175
183
  data.event = resourceNames(
176
184
  RESOURCE_CLASSES.sqs,
177
185
  upperCase(flowSchema.flowTag) +
178
- upperCase(flowStepName) +
179
- upperCase(data.handleLogic) +
180
- upperCase(data.handlerType)
181
- )
186
+ upperCase(flowStepName) +
187
+ upperCase(data.handleLogic) +
188
+ upperCase(data.handlerType)
189
+ );
182
190
  const generateLambdaFlowStepByConfig = buildFlowStepResourceByConfig(
183
191
  _izContext,
184
192
  data,
185
193
  appPath
186
194
  );
187
195
  allCreateSourceParams.push(...generateLambdaFlowStepByConfig);
188
-
189
196
  }
190
-
191
197
  }
192
198
  }
193
199
 
194
-
195
200
  const uniqueSortedTargetFiles = Array.from(
196
201
  new Set(
197
202
  allCreateSourceParams
@@ -220,24 +225,22 @@ async function generatePlunIg(
220
225
 
221
226
  export default generatePlunIg;
222
227
 
223
-
224
- async function buildNoPluginHookResources(_izContext, data, flowStepConfig, appPath) {
228
+ async function buildNoPluginHookResources(
229
+ _izContext,
230
+ data,
231
+ flowStepConfig,
232
+ appPath
233
+ ) {
225
234
  const results = [];
226
235
 
227
- const yamlRes = await yamlFlowStep(
228
- _izContext,
229
- data,
230
- appPath);
231
- const handlerRes = await handlerFlowStep(
232
- _izContext,
233
- data,
234
- appPath);
235
-
236
- if (data.handlerType === HANDLER.hdrSqs || data.handlerType === HANDLER.hdrDsq) {
237
- const sqsRes = await sqsFlowStep(
238
- _izContext,
239
- data,
240
- appPath);
236
+ const yamlRes = await yamlFlowStep(_izContext, data, appPath);
237
+ const handlerRes = await handlerFlowStep(_izContext, data, appPath);
238
+
239
+ if (
240
+ data.handlerType === HANDLER.hdrSqs ||
241
+ data.handlerType === HANDLER.hdrDsq
242
+ ) {
243
+ const sqsRes = await sqsFlowStep(_izContext, data, appPath);
241
244
  results.push(sqsRes);
242
245
  }
243
246
 
@@ -257,51 +260,52 @@ async function buildNoPluginHookResources(_izContext, data, flowStepConfig, appP
257
260
  appPath
258
261
  );
259
262
 
260
- results.push(mainRes,
263
+ results.push(
264
+ mainRes,
261
265
  // snsOutRes,
262
266
  yamlRes,
263
- handlerRes);
267
+ handlerRes
268
+ );
264
269
 
265
270
  return results;
266
271
  }
267
272
 
268
- async function buildFirstPluginHookResources(_izContext, data, flowStepConfig, appPath) {
273
+ async function buildFirstPluginHookResources(
274
+ _izContext,
275
+ data,
276
+ flowStepConfig,
277
+ appPath
278
+ ) {
269
279
  const results = [];
270
280
 
271
- const yamlRes = await yamlFlowStep(
272
- _izContext,
273
- data,
274
- appPath);
281
+ const yamlRes = await yamlFlowStep(_izContext, data, appPath);
275
282
 
276
- const handlerRes = await handlerFlowStep(
277
- _izContext,
278
- data,
279
- appPath);
283
+ const handlerRes = await handlerFlowStep(_izContext, data, appPath);
280
284
 
281
285
  results.push(yamlRes, handlerRes);
282
286
 
283
- if (data.handlerType === HANDLER.hdrSqs ||
284
- data.handlerType === HANDLER.hdrDsq) {
285
- const sqsRes = await sqsFlowStep(
286
- _izContext,
287
- data,
288
- appPath);
287
+ if (
288
+ data.handlerType === HANDLER.hdrSqs ||
289
+ data.handlerType === HANDLER.hdrDsq
290
+ ) {
291
+ const sqsRes = await sqsFlowStep(_izContext, data, appPath);
289
292
  results.push(sqsRes);
290
293
  }
291
294
 
292
- const snsOutRes = await snsOut(
293
- _izContext,
294
- data,
295
- appPath);
295
+ const snsOutRes = await snsOut(_izContext, data, appPath);
296
296
  results.push(snsOutRes);
297
297
 
298
298
  // Original: only the first plugInHook (index 0) creates the main function
299
299
  const firstHook = flowStepConfig.plugInHooks[0];
300
- const [objSchema] = await getLocalOrS3ObjectSchema(
300
+ const [objSchema, error] = await getLocalOrS3ObjectSchema(
301
301
  _izContext,
302
302
  firstHook.objType,
303
303
  path.join(appPath, './src/schemas')
304
304
  );
305
+ if (error) {
306
+ console.error('[plugIn] error:', error);
307
+ throw new NoRetryError(error);
308
+ }
305
309
 
306
310
  let mainData = { ...data, havePlugIn: false };
307
311
 
@@ -329,27 +333,29 @@ async function buildFirstPluginHookResources(_izContext, data, flowStepConfig, a
329
333
  }
330
334
  }
331
335
 
332
- const mainRes = await mainFunctionFlowStep(
333
- _izContext,
334
- mainData,
335
- appPath);
336
+ const mainRes = await mainFunctionFlowStep(_izContext, mainData, appPath);
336
337
 
337
338
  results.push(mainRes);
338
339
 
339
340
  return results;
340
341
  }
341
342
 
342
- async function buildRecievePluginHookResource(_izContext, data, appPath, allObjSchemas) {
343
+ async function buildRecievePluginHookResource(
344
+ _izContext,
345
+ data,
346
+ appPath,
347
+ allObjSchemas
348
+ ) {
343
349
  const results = [];
344
350
 
345
351
  for (const objSchema of allObjSchemas) {
346
- if (!objSchema.hasOwnProperty("recievePlugInHookTag")) continue;
352
+ if (!objSchema.hasOwnProperty('recievePlugInHookTag')) continue;
347
353
 
348
354
  for (const recieveConfig of Object.values(objSchema.recievePlugInHookTag)) {
349
355
  const localData = { ...data };
350
356
 
351
357
  if (recieveConfig.hasOwnProperty('flowType')) {
352
- localData.recieveType = "async";
358
+ localData.recieveType = 'async';
353
359
  localData.flowType = recieveConfig.flowType;
354
360
  } else {
355
361
  localData.recieveType = 'sync';
@@ -358,21 +364,20 @@ async function buildRecievePluginHookResource(_izContext, data, appPath, allObjS
358
364
  const yamlRecieveRes = await yamlRecievePlugIn(
359
365
  _izContext,
360
366
  localData,
361
- appPath);
367
+ appPath
368
+ );
362
369
  const handlerRecieveRes = await handlerRecievePlugIn(
363
370
  _izContext,
364
371
  localData,
365
- appPath);
372
+ appPath
373
+ );
366
374
  const mainRecieveRes = await mainFunctionRecievePlugIn(
367
375
  _izContext,
368
376
  localData,
369
- appPath);
370
-
371
- results.push(
372
- ...yamlRecieveRes,
373
- ...handlerRecieveRes,
374
- mainRecieveRes
377
+ appPath
375
378
  );
379
+
380
+ results.push(...yamlRecieveRes, ...handlerRecieveRes, mainRecieveRes);
376
381
  }
377
382
  }
378
383
 
@@ -380,95 +385,100 @@ async function buildRecievePluginHookResource(_izContext, data, appPath, allObjS
380
385
  }
381
386
 
382
387
  // Extracted from the original if/else chain — mutates data, additionalResourcePermission, resourceApis in place
383
- function resolveHandlerConfig(data, flowStepConfig, additionalResourcePermission, resourceApis, serviceTag, fallbackEvent = []) {
388
+ function resolveHandlerConfig(
389
+ data,
390
+ flowStepConfig,
391
+ additionalResourcePermission,
392
+ resourceApis,
393
+ serviceTag,
394
+ fallbackEvent = []
395
+ ) {
384
396
  const { flowTag, flowStepName } = data;
385
397
  let handler;
386
398
  const events = flowStepConfig.event || fallbackEvent || [];
387
399
 
388
- if (events.includes("ownTopic")) {
400
+ if (events.includes('ownTopic')) {
389
401
  data.eventFlow = 'ownTopic';
390
402
  handler = HANDLER.hdrSqs;
391
403
  additionalResourcePermission.push(
392
- createSnsResource([upperCase(flowTag) +
393
- upperCase(flowStepName) + "_In"]),
404
+ createSnsResource([upperCase(flowTag) + upperCase(flowStepName) + '_In']),
394
405
  createSqsResource([
406
+ upperCase(flowTag) + upperCase(flowStepName) + upperCase(handler),
395
407
  upperCase(flowTag) +
396
- upperCase(flowStepName) +
397
- upperCase(handler),
398
- upperCase(flowTag) +
399
- upperCase(flowStepName) +
400
- upperCase(handler) + "DLQ",
408
+ upperCase(flowStepName) +
409
+ upperCase(handler) +
410
+ 'DLQ'
401
411
  ])
402
412
  );
403
- } else if (events.includes("extTopic")) {
413
+ } else if (events.includes('extTopic')) {
404
414
  data.eventFlow = 'extTopic';
405
415
  handler = HANDLER.hdrSqs;
406
416
  additionalResourcePermission.push(
407
417
  createSqsResource([
418
+ upperCase(flowTag) + upperCase(flowStepName) + upperCase(handler),
408
419
  upperCase(flowTag) +
409
- upperCase(flowStepName) +
410
- upperCase(handler),
411
- upperCase(flowTag) +
412
- upperCase(flowStepName) +
413
- upperCase(handler) + "DLQ",
420
+ upperCase(flowStepName) +
421
+ upperCase(handler) +
422
+ 'DLQ'
414
423
  ])
415
424
  );
416
- } else if (events.includes("lambdaSyncInv")) {
425
+ } else if (events.includes('lambdaSyncInv')) {
417
426
  handler = HANDLER.hdrInv;
418
- } else if (events.includes("lambdaSyncApi")) {
427
+ } else if (events.includes('lambdaSyncApi')) {
419
428
  handler = HANDLER.hdrApi;
420
429
  resourceApis.push({
421
430
  path: `${serviceTag}/${lowerCase(flowTag)}${lowerCase(flowStepName)}`,
422
431
  pathWithUser: `${serviceTag}/${lowerCase(flowTag)}${lowerCase(flowStepName)}/{targetUserId}`,
423
432
  method: 'post',
424
433
  hookTagApp: `${upperCase(flowStepName)}${upperCase(handler)}AppLevelAuthorizer`,
425
- hookTagUser: `${upperCase(flowStepName)}${upperCase(handler)}UserLevelAuthorizer`,
434
+ hookTagUser: `${upperCase(flowStepName)}${upperCase(handler)}UserLevelAuthorizer`
426
435
  });
427
- } else if (events.includes("queue")) {
436
+ } else if (events.includes('queue')) {
428
437
  handler = HANDLER.hdrDsq;
429
438
  additionalResourcePermission.push(
430
439
  createSqsResource([
440
+ upperCase(flowTag) + upperCase(flowStepName) + upperCase(handler),
431
441
  upperCase(flowTag) +
432
- upperCase(flowStepName) +
433
- upperCase(handler),
434
- upperCase(flowTag) +
435
- upperCase(flowStepName) +
436
- upperCase(handler) +
437
- "DSQ",
442
+ upperCase(flowStepName) +
443
+ upperCase(handler) +
444
+ 'DSQ'
438
445
  ])
439
446
  );
440
447
  }
441
448
 
442
- if (flowStepConfig.hasOwnProperty("settings")) {
443
- if (flowStepConfig.settings.hasOwnProperty("handleLogic")) {
449
+ if (flowStepConfig.hasOwnProperty('settings')) {
450
+ if (flowStepConfig.settings.hasOwnProperty('handleLogic')) {
444
451
  const handleLogic = flowStepConfig.settings.handleLogic;
445
452
  const childFlow = flowStepConfig.settings.flowType;
446
453
  if (handleLogic === 'awaitingMultipleSteps') {
447
454
  handler = HANDLER.hdrSqs;
448
- additionalResourcePermission.push(awaitingMultipleStepsRole())
449
- additionalResourcePermission.push(createSqsResource(
450
- [
455
+ additionalResourcePermission.push(awaitingMultipleStepsRole());
456
+ additionalResourcePermission.push(
457
+ createSqsResource([
451
458
  upperCase(flowTag) +
452
- upperCase(flowStepName) +
453
- upperCase(flowStepConfig.settings.handleLogic) +
454
- upperCase(HANDLER.hdrSqs),
459
+ upperCase(flowStepName) +
460
+ upperCase(flowStepConfig.settings.handleLogic) +
461
+ upperCase(HANDLER.hdrSqs),
455
462
  upperCase(flowTag) +
456
- upperCase(flowStepName) +
457
- upperCase(flowStepConfig.settings.handleLogic) +
458
- upperCase(HANDLER.hdrSqs) + "DLQ"
459
- ]
460
- ))
463
+ upperCase(flowStepName) +
464
+ upperCase(flowStepConfig.settings.handleLogic) +
465
+ upperCase(HANDLER.hdrSqs) +
466
+ 'DLQ'
467
+ ])
468
+ );
461
469
  } else if (handleLogic === 'paginated') {
462
470
  handler = HANDLER.hdrSqs;
463
- additionalResourcePermission.push(createSqsResource(
464
- [
471
+ additionalResourcePermission.push(
472
+ createSqsResource([
465
473
  upperCase(flowTag) +
466
- upperCase(flowStepName) +
467
- upperCase(HANDLER.hdrDsq),
474
+ upperCase(flowStepName) +
475
+ upperCase(HANDLER.hdrDsq),
468
476
  upperCase(flowTag) +
469
- upperCase(flowStepName) +
470
- upperCase(HANDLER.hdrDsq) + "DLQ"
471
- ]))
477
+ upperCase(flowStepName) +
478
+ upperCase(HANDLER.hdrDsq) +
479
+ 'DLQ'
480
+ ])
481
+ );
472
482
  }
473
483
  }
474
484
  }
@@ -479,50 +489,31 @@ function buildFlowStepResourceByConfig(_izContext, data, appPath) {
479
489
  const results = [];
480
490
 
481
491
  if (data.handleLogic === 'awaitingMultipleSteps') {
482
- data.handlerType = HANDLER.hdrSqs
492
+ data.handlerType = HANDLER.hdrSqs;
483
493
  } else if (data.handleLogic === 'paginated') {
484
- data.handlerType = HANDLER.hdrDsq
494
+ data.handlerType = HANDLER.hdrDsq;
485
495
  }
486
496
 
487
- data["functionName"] = upperCase(data.flowTag) +
497
+ data['functionName'] =
498
+ upperCase(data.flowTag) +
488
499
  upperCase(data.flowStepName) +
489
- upperCase(data.handleLogic)
500
+ upperCase(data.handleLogic);
490
501
 
491
- data["functionNameConfig"] = upperCase(data.flowTag) +
502
+ data['functionNameConfig'] =
503
+ upperCase(data.flowTag) +
492
504
  upperCase(data.flowStepName) +
493
505
  upperCase(data.handleLogic) +
494
- upperCase(data.handlerType)
506
+ upperCase(data.handlerType);
495
507
 
496
- const handler = handlerFlowConfig(
497
- _izContext,
498
- data,
499
- appPath
500
- );
508
+ const handler = handlerFlowConfig(_izContext, data, appPath);
501
509
 
502
- const mainFunction = mainFunctionFlowConfig(
503
- _izContext,
504
- data,
505
- appPath
506
- );
510
+ const mainFunction = mainFunctionFlowConfig(_izContext, data, appPath);
507
511
 
508
- const sqs = sqsFlowConfig(
509
- _izContext,
510
- data,
511
- appPath
512
- );
512
+ const sqs = sqsFlowConfig(_izContext, data, appPath);
513
513
 
514
- const yaml = yamlFlowConfig(
515
- _izContext,
516
- data,
517
- appPath
518
- );
514
+ const yaml = yamlFlowConfig(_izContext, data, appPath);
519
515
 
520
- results.push(
521
- handler,
522
- mainFunction,
523
- sqs,
524
- yaml
525
- );
516
+ results.push(handler, mainFunction, sqs, yaml);
526
517
 
527
518
  return results;
528
- }
519
+ }