@friggframework/devtools 2.0.0--canary.744.7e3ee98.0 → 2.0.0--canary.743.d13a976.0

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.
@@ -33,9 +33,7 @@ class AdminScriptBuilder extends InfrastructureBuilder {
33
33
  appDefinition.reports.length > 0;
34
34
  const hasBuiltinReports =
35
35
  appDefinition.admin?.includeBuiltinReports === true;
36
- const hasBuiltinScripts =
37
- appDefinition.admin?.includeBuiltinScripts === true;
38
- return hasScripts || hasReports || hasBuiltinReports || hasBuiltinScripts;
36
+ return hasScripts || hasReports || hasBuiltinReports;
39
37
  }
40
38
 
41
39
  getDependencies() {
@@ -85,10 +83,6 @@ class AdminScriptBuilder extends InfrastructureBuilder {
85
83
  : [];
86
84
  const hasReports =
87
85
  reports.length > 0 || adminConfig.includeBuiltinReports === true;
88
- // The built-in scripts (registered at runtime by the admin-scripts
89
- // bootstrap) need the same queue, executor and routes as app scripts.
90
- const hasScripts =
91
- adminScripts.length > 0 || adminConfig.includeBuiltinScripts === true;
92
86
 
93
87
  // Only non-JSON report output is stored in S3, so provision the bucket
94
88
  // only for that. Built-in reports emit JSON, so they don't trigger it.
@@ -105,7 +99,7 @@ class AdminScriptBuilder extends InfrastructureBuilder {
105
99
  iamStatements: [],
106
100
  };
107
101
 
108
- if (hasScripts) {
102
+ if (adminScripts.length > 0) {
109
103
  console.log(` Processing ${adminScripts.length} scripts...`);
110
104
  this.createAdminScriptQueue(result, appDefinition);
111
105
  this.createScriptExecutorFunction(appDefinition, result, usePrismaLayer);
@@ -115,9 +109,6 @@ class AdminScriptBuilder extends InfrastructureBuilder {
115
109
  const name = script.Definition?.name || 'unknown';
116
110
  console.log(` ✓ Registered script: ${name}`);
117
111
  });
118
- if (adminConfig.includeBuiltinScripts) {
119
- console.log(' ✓ Built-in scripts enabled');
120
- }
121
112
  }
122
113
 
123
114
  if (hasReports) {
@@ -136,9 +127,12 @@ class AdminScriptBuilder extends InfrastructureBuilder {
136
127
  }
137
128
  }
138
129
 
139
- if (adminConfig.enableScheduling && (hasScripts || hasReports)) {
130
+ if (
131
+ adminConfig.enableScheduling &&
132
+ (adminScripts.length > 0 || hasReports)
133
+ ) {
140
134
  this.createSchedulerResources(appDefinition, result, {
141
- scriptsPresent: hasScripts,
135
+ scriptsPresent: adminScripts.length > 0,
142
136
  hasReports,
143
137
  });
144
138
  }
@@ -44,12 +44,6 @@ describe('AdminScriptBuilder', () => {
44
44
  expect(adminScriptBuilder.shouldExecute(appDefinition)).toBe(true);
45
45
  });
46
46
 
47
- it('should return true when only the built-in scripts are enabled', () => {
48
- expect(
49
- adminScriptBuilder.shouldExecute({ admin: { includeBuiltinScripts: true } })
50
- ).toBe(true);
51
- });
52
-
53
47
  it('should return false when adminScripts is not an array', () => {
54
48
  const appDefinition = {
55
49
  adminScripts: { name: 'test' },
@@ -748,27 +742,6 @@ describe('AdminScriptBuilder', () => {
748
742
  expect(result.functions.reportExecutor).toBeDefined();
749
743
  });
750
744
 
751
- it('creates the script queue, executor and routes when only the built-in scripts are enabled', async () => {
752
- const result = await adminScriptBuilder.build(
753
- { admin: { includeBuiltinScripts: true } },
754
- {}
755
- );
756
-
757
- expect(result.resources.AdminScriptQueue).toBeDefined();
758
- expect(result.functions.adminScriptExecutor).toBeDefined();
759
- expect(result.functions.adminScriptRouter).toBeDefined();
760
- });
761
-
762
- it('provisions scheduling for the built-in scripts', async () => {
763
- const result = await adminScriptBuilder.build(
764
- { admin: { includeBuiltinScripts: true, enableScheduling: true } },
765
- {}
766
- );
767
-
768
- expect(result.resources.AdminScriptQueue).toBeDefined();
769
- expect(JSON.stringify(result.resources)).toMatch(/Schedule/);
770
- });
771
-
772
745
  it('does NOT create ReportQueue or reportExecutor when only adminScripts are present', async () => {
773
746
  const appDefinition = {
774
747
  adminScripts: [{ Definition: { name: 'test-script' } }],
@@ -33,6 +33,11 @@ const {
33
33
  nestedNodeModulesExcludes,
34
34
  } = require('../shared/utilities/nested-node-modules');
35
35
  const { queueArnFromUrl } = require('../shared/utilities/sqs-queue-arn');
36
+ const {
37
+ declaredMaxConcurrency,
38
+ queueWorkerConcurrencySource,
39
+ queueWorkerMaximumConcurrency,
40
+ } = require('./queue-worker-concurrency');
36
41
  const { bundledPrismaEngineExcludes } = require('../shared/lambda-architectures');
37
42
  const {
38
43
  INTEGRATION_QUEUE_MAX_RECEIVE_COUNT,
@@ -436,12 +441,19 @@ class IntegrationBuilder extends InfrastructureBuilder {
436
441
 
437
442
  // Create Queue Worker function
438
443
  const queueWorkerName = `${integrationName}QueueWorker`;
444
+ const queueWorkerReservedConcurrency = 20;
445
+ // ADR-049 section 6, 2a: the integration's queueWorker setting, else
446
+ // the modules' maxConcurrency, caps the whole queue worker.
447
+ const maximumConcurrency = queueWorkerMaximumConcurrency(
448
+ integration,
449
+ queueWorkerReservedConcurrency
450
+ );
439
451
  result.functions[queueWorkerName] = {
440
452
  handler: `node_modules/@friggframework/core/handlers/workers/integration-defined-workers.handlers.${integrationName}.queueWorker`,
441
453
  skipEsbuild: true, // Nested exports in node_modules - skip esbuild bundling
442
454
  package: functionPackageConfig,
443
455
  ...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }), // Queue workers need Prisma for database operations
444
- reservedConcurrency: 20,
456
+ reservedConcurrency: queueWorkerReservedConcurrency,
445
457
  events: [
446
458
  {
447
459
  sqs: {
@@ -453,12 +465,33 @@ class IntegrationBuilder extends InfrastructureBuilder {
453
465
  },
454
466
  batchSize: 1,
455
467
  functionResponseType: 'ReportBatchItemFailures',
468
+ ...(maximumConcurrency !== undefined && {
469
+ maximumConcurrency,
470
+ }),
456
471
  },
457
472
  },
458
473
  ],
459
474
  timeout: 900, // 15 minutes max for queue workers (Lambda maximum)
460
475
  };
461
476
  console.log(` ✓ Queue worker function defined`);
477
+ const concurrencySource = queueWorkerConcurrencySource(integration);
478
+ if (
479
+ maximumConcurrency === undefined &&
480
+ concurrencySource.value !== undefined
481
+ ) {
482
+ console.log(
483
+ ` ⚠ Queue worker maximumConcurrency ${concurrencySource.value} not set: it is not below the reserved concurrency of ${queueWorkerReservedConcurrency}`
484
+ );
485
+ }
486
+ if (maximumConcurrency !== undefined) {
487
+ console.log(
488
+ ` ✓ Queue worker maximumConcurrency ${maximumConcurrency} for the whole queue (${
489
+ concurrencySource.source === 'integration'
490
+ ? 'Definition.queueWorker.maximumConcurrency'
491
+ : `smallest module maxConcurrency ${declaredMaxConcurrency(integration)}; set Definition.queueWorker.maximumConcurrency to change or false to turn off`
492
+ })`
493
+ );
494
+ }
462
495
  }
463
496
 
464
497
  /**
@@ -393,6 +393,92 @@ describe('IntegrationBuilder', () => {
393
393
  expect(result.functions.testQueueWorker.reservedConcurrency).toBe(20);
394
394
  });
395
395
 
396
+ describe('maximumConcurrency from the modules (ADR-049 section 6, 2a)', () => {
397
+ const withModules = (...limits) => ({
398
+ integrations: [
399
+ {
400
+ Definition: {
401
+ name: 'test',
402
+ modules: Object.fromEntries(
403
+ limits.map((maxConcurrency, i) => [
404
+ `m${i}`,
405
+ {
406
+ definition: {
407
+ API: class {
408
+ static rateLimit =
409
+ maxConcurrency === undefined
410
+ ? undefined
411
+ : { maxConcurrency };
412
+ },
413
+ },
414
+ },
415
+ ])
416
+ ),
417
+ },
418
+ },
419
+ ],
420
+ });
421
+ const sqsOf = (result) =>
422
+ result.functions.testQueueWorker.events[0].sqs;
423
+
424
+ it('sets the smallest maxConcurrency of the modules', async () => {
425
+ const result = await integrationBuilder.build(
426
+ withModules(10, 5, undefined),
427
+ {}
428
+ );
429
+ expect(sqsOf(result).maximumConcurrency).toBe(5);
430
+ expect(result.functions.testQueueWorker.reservedConcurrency).toBe(20);
431
+ });
432
+
433
+ it('raises a value under 2 to the SQS minimum of 2', async () => {
434
+ const result = await integrationBuilder.build(withModules(1), {});
435
+ expect(sqsOf(result).maximumConcurrency).toBe(2);
436
+ });
437
+
438
+ it('sets nothing when no module declares maxConcurrency', async () => {
439
+ const result = await integrationBuilder.build(
440
+ withModules(undefined),
441
+ {}
442
+ );
443
+ expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
444
+ });
445
+
446
+ it('sets nothing when the value is not below the reserved concurrency', async () => {
447
+ const result = await integrationBuilder.build(withModules(50), {});
448
+ expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
449
+ });
450
+
451
+ const withSetting = (setting, ...limits) => {
452
+ const app = withModules(...limits);
453
+ app.integrations[0].Definition.queueWorker = {
454
+ maximumConcurrency: setting,
455
+ };
456
+ return app;
457
+ };
458
+
459
+ it('uses Definition.queueWorker.maximumConcurrency over the modules', async () => {
460
+ const result = await integrationBuilder.build(
461
+ withSetting(8, 3),
462
+ {}
463
+ );
464
+ expect(sqsOf(result).maximumConcurrency).toBe(8);
465
+ });
466
+
467
+ it('refuses a Definition.queueWorker.maximumConcurrency that is not an integer or false', async () => {
468
+ await expect(
469
+ integrationBuilder.build(withSetting('8', 3), {})
470
+ ).rejects.toThrow('must be an integer from 2 to 1000, or false');
471
+ });
472
+
473
+ it('sets nothing when Definition.queueWorker.maximumConcurrency is false', async () => {
474
+ const result = await integrationBuilder.build(
475
+ withSetting(false, 3),
476
+ {}
477
+ );
478
+ expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
479
+ });
480
+ });
481
+
396
482
  it('should add queue URL to environment variables', async () => {
397
483
  const appDefinition = {
398
484
  integrations: [
@@ -0,0 +1,85 @@
1
+ /**
2
+ * ADR-049 section 6, pacing 2a: the queue worker's maximum concurrency comes
3
+ * from the `maxConcurrency` that the integration's API modules declare in
4
+ * `static rateLimit`. The module only describes the provider; devtools
5
+ * decides the deployment.
6
+ *
7
+ * `maximumConcurrency` limits the whole queue of the integration, for every
8
+ * tenant, while `maxConcurrency` describes one key of the provider. So the
9
+ * integration decides it: `Definition.queueWorker.maximumConcurrency` sets
10
+ * it (an integer), or turns it off (`false`). When the integration sets
11
+ * nothing, the value is the smallest `maxConcurrency` of its modules.
12
+ * It becomes the SQS event source's `maximumConcurrency`, which AWS bounds to
13
+ * 2..1000, and never more than the worker's reserved concurrency. An SQS
14
+ * event source that hits `maximumConcurrency` leaves the messages in the
15
+ * queue: unlike a lower reserved concurrency, it does not throttle them and
16
+ * does not spend their receives.
17
+ */
18
+
19
+ const SQS_MIN_MAXIMUM_CONCURRENCY = 2;
20
+
21
+ function moduleApiClasses(integration) {
22
+ const modules = integration?.Definition?.modules ?? {};
23
+ return Object.values(modules)
24
+ .map((entry) => (entry?.definition ?? entry)?.API)
25
+ .filter((API) => typeof API === 'function');
26
+ }
27
+
28
+ /** The smallest declared `maxConcurrency`, or undefined. */
29
+ function declaredMaxConcurrency(integration) {
30
+ let smallest;
31
+ for (const API of moduleApiClasses(integration)) {
32
+ let value;
33
+ try {
34
+ value = API.rateLimit?.maxConcurrency;
35
+ } catch {
36
+ value = undefined;
37
+ }
38
+ if (Number.isInteger(value) && value > 0) {
39
+ smallest =
40
+ smallest === undefined ? value : Math.min(smallest, value);
41
+ }
42
+ }
43
+ return smallest;
44
+ }
45
+
46
+ /**
47
+ * Where the value comes from: the integration's own setting, or its modules.
48
+ * Throws for a setting that is neither a positive integer nor `false`.
49
+ * @returns {{ value: number|undefined, source: 'integration'|'modules'|'off'|'none' }}
50
+ */
51
+ function queueWorkerConcurrencySource(integration) {
52
+ const setting = integration?.Definition?.queueWorker?.maximumConcurrency;
53
+ if (setting === false) return { value: undefined, source: 'off' };
54
+ if (Number.isInteger(setting) && setting > 0) {
55
+ return { value: setting, source: 'integration' };
56
+ }
57
+ if (setting !== undefined) {
58
+ throw new Error(
59
+ `Definition.queueWorker.maximumConcurrency of integration "${integration?.Definition?.name}" must be an integer from 2 to 1000, or false`
60
+ );
61
+ }
62
+ const declared = declaredMaxConcurrency(integration);
63
+ return declared === undefined
64
+ ? { value: undefined, source: 'none' }
65
+ : { value: declared, source: 'modules' };
66
+ }
67
+
68
+ /**
69
+ * @returns {number|undefined} the SQS `maximumConcurrency` for the queue
70
+ * worker, or undefined when it is off, nothing declares a value, or the
71
+ * value is not below the reserved concurrency.
72
+ */
73
+ function queueWorkerMaximumConcurrency(integration, reservedConcurrency) {
74
+ const declared = queueWorkerConcurrencySource(integration).value;
75
+ if (declared === undefined) return undefined;
76
+ const value = Math.max(declared, SQS_MIN_MAXIMUM_CONCURRENCY);
77
+ return value < reservedConcurrency ? value : undefined;
78
+ }
79
+
80
+ module.exports = {
81
+ SQS_MIN_MAXIMUM_CONCURRENCY,
82
+ declaredMaxConcurrency,
83
+ queueWorkerConcurrencySource,
84
+ queueWorkerMaximumConcurrency,
85
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/devtools",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.744.7e3ee98.0",
4
+ "version": "2.0.0--canary.743.d13a976.0",
5
5
  "bin": {
6
6
  "frigg": "./frigg-cli/index.js"
7
7
  },
@@ -28,9 +28,9 @@
28
28
  "@babel/eslint-parser": "^7.18.9",
29
29
  "@babel/parser": "^7.25.3",
30
30
  "@babel/traverse": "^7.25.3",
31
- "@friggframework/core": "2.0.0--canary.744.7e3ee98.0",
32
- "@friggframework/schemas": "2.0.0--canary.744.7e3ee98.0",
33
- "@friggframework/test": "2.0.0--canary.744.7e3ee98.0",
31
+ "@friggframework/core": "2.0.0--canary.743.d13a976.0",
32
+ "@friggframework/schemas": "2.0.0--canary.743.d13a976.0",
33
+ "@friggframework/test": "2.0.0--canary.743.d13a976.0",
34
34
  "@hapi/boom": "^10.0.1",
35
35
  "@inquirer/prompts": "^5.3.8",
36
36
  "axios": "^1.18.0",
@@ -58,8 +58,8 @@
58
58
  "validate-npm-package-name": "^5.0.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@friggframework/eslint-config": "2.0.0--canary.744.7e3ee98.0",
62
- "@friggframework/prettier-config": "2.0.0--canary.744.7e3ee98.0",
61
+ "@friggframework/eslint-config": "2.0.0--canary.743.d13a976.0",
62
+ "@friggframework/prettier-config": "2.0.0--canary.743.d13a976.0",
63
63
  "aws-sdk-client-mock": "^4.1.0",
64
64
  "aws-sdk-client-mock-jest": "^4.1.0",
65
65
  "jest": "^30.1.3",
@@ -91,5 +91,5 @@
91
91
  "publishConfig": {
92
92
  "access": "public"
93
93
  },
94
- "gitHead": "7e3ee98f0418c7247a4c166826c0b561eef27741"
94
+ "gitHead": "d13a976018ff2a673f3309523aa7c5a725bb97b6"
95
95
  }