@friggframework/schemas 2.0.0--canary.702.047d3c4.0 → 2.0.0--canary.701.2571e69.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.
package/README.md CHANGED
@@ -41,32 +41,6 @@ if (result.valid) {
41
41
  }
42
42
  ```
43
43
 
44
- ### Integration classes and defaults (ADR-051)
45
-
46
- Apps list integration classes, which JSON Schema cannot describe.
47
- `validateAppDefinition` validates a view of the definition in which each
48
- class in `integrations`, `adminScripts` and `reports` is replaced by
49
- `{ Definition }`; `frigg validate` checks the classes themselves.
50
-
51
- ```javascript
52
- const { applyAppDefinitionDefaults } = require('@friggframework/schemas');
53
- // or, without loading Ajv:
54
- // require('@friggframework/schemas/app-definition').applyAppDefinitionDefaults
55
-
56
- const definition = applyAppDefinitionDefaults(require('./index').Definition);
57
- definition.user.individualUserRequired; // true (schema default)
58
- ```
59
-
60
- `applyAppDefinitionDefaults` returns a copy with every `default` declared in
61
- the app-definition schema applied (only inside blocks the app sets, plus
62
- blocks that have a default themselves, such as `user`). core's
63
- `loadAppDefinition` and devtools' `createFriggInfrastructure` call it, so a
64
- schema default is the runtime default. A schema default must equal what the
65
- code does when the key is absent; the contract test in
66
- `packages/devtools/infrastructure/app-definition-schema-contract.test.js`
67
- checks this for the infrastructure builders. Keys nothing reads are marked
68
- `"deprecated": true`.
69
-
70
44
  ### Advanced Validation
71
45
 
72
46
  ```javascript
@@ -172,7 +146,9 @@ Defines the structure for Frigg API modules.
172
146
  **Key Properties:**
173
147
  - `moduleName` (required): Module identifier
174
148
  - `getName` (required): Function returning module name
175
- - `requiredAuthMethods` (required): Authentication configuration
149
+ - `requiredAuthMethods` (required): Authentication configuration (includes optional `getAuthorizationRequirements` and `setAuthParams` for API-key modules)
150
+ - `modelName`: Entity/credential model name used by the Module runtime
151
+ - Real Definitions (classes/functions) are accepted by `validateApiModuleDefinition` via a schema view.
176
152
  - `env`: Environment variable configuration
177
153
  - `config`: Module-specific configuration
178
154
 
package/index.js CHANGED
@@ -12,10 +12,6 @@ const path = require('path');
12
12
 
13
13
  // Import middleware
14
14
  const schemaValidationMiddleware = require('./middleware/schema-validation');
15
- const {
16
- applyAppDefinitionDefaults,
17
- toAppDefinitionSchemaView,
18
- } = require('./app-definition');
19
15
  const {
20
16
  toApiModuleDefinitionSchemaView,
21
17
  } = require('./api-module-definition');
@@ -83,13 +79,7 @@ function validate(schemaName, data) {
83
79
  * @returns {object} - Validation result
84
80
  */
85
81
  function validateAppDefinition(appDefinition) {
86
- // Apps list integration classes, which JSON Schema cannot describe:
87
- // validate the serialisable view and return the original definition.
88
- const result = validate(
89
- 'app-definition',
90
- toAppDefinitionSchemaView(appDefinition)
91
- );
92
- return { ...result, data: appDefinition };
82
+ return validate('app-definition', appDefinition);
93
83
  }
94
84
 
95
85
  /**
@@ -104,7 +94,7 @@ function validateIntegrationDefinition(integrationDefinition) {
104
94
  /**
105
95
  * Validate API Module Definition.
106
96
  * Real Definitions carry classes and functions; validate the serialisable
107
- * view and return the original definition (same pattern as validateAppDefinition).
97
+ * view and return the original definition.
108
98
  * @param {object} apiModuleDefinition - API module definition object to validate
109
99
  * @returns {object} - Validation result
110
100
  */
@@ -376,8 +366,6 @@ module.exports = {
376
366
  // Validation functions
377
367
  validate,
378
368
  validateAppDefinition,
379
- applyAppDefinitionDefaults,
380
- toAppDefinitionSchemaView,
381
369
  toApiModuleDefinitionSchemaView,
382
370
  validateIntegrationDefinition,
383
371
  validateApiModuleDefinition,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friggframework/schemas",
3
- "version": "2.0.0--canary.702.047d3c4.0",
3
+ "version": "2.0.0--canary.701.2571e69.0",
4
4
  "description": "Canonical JSON Schema definitions for Frigg Framework",
5
5
  "main": "index.js",
6
6
  "author": "",
@@ -39,9 +39,8 @@
39
39
  "validators/",
40
40
  "mocks/",
41
41
  "middleware/",
42
- "app-definition.js",
43
42
  "api-module-definition.js",
44
43
  "index.js"
45
44
  ],
46
- "gitHead": "047d3c404aa8c9636d6c2c442d28ce5e5fcf6b39"
45
+ "gitHead": "2571e692e406f3d39977c865685639b9e895345f"
47
46
  }
@@ -22,35 +22,22 @@
22
22
  },
23
23
  "label": {
24
24
  "type": "string",
25
- "description": "Human-readable display name for the application. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
25
+ "description": "Human-readable display name for the application",
26
26
  "minLength": 1,
27
27
  "maxLength": 200,
28
- "examples": ["My Frigg Application", "Customer Portal Integrations"],
29
- "deprecated": true
30
- },
31
- "region": {
32
- "type": "string",
33
- "description": "AWS region. The deploy region comes from AWS_REGION (default us-east-1), not from this key. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
34
- "deprecated": true
35
- },
36
- "stage": {
37
- "type": "string",
38
- "description": "Stage name used only to infer the KMS key alias. The deployed stage comes from `--stage`."
28
+ "examples": ["My Frigg Application", "Customer Portal Integrations"]
39
29
  },
40
30
  "managementMode": {
41
31
  "type": "string",
42
- "description": "Infrastructure management mode. 'managed': Frigg creates and owns the VPC, database and KMS key it needs (with vpcIsolation 'isolated', per stage). 'existing': use existing resources given by id. 'discover' (also the behaviour when omitted): find existing resources and create what is missing. 'custom' is accepted for compatibility and behaves like 'discover'.",
43
- "enum": ["managed", "discover", "existing", "custom"]
32
+ "description": "Infrastructure management mode: 'managed' lets Frigg manage resources, 'discover' uses existing resources, 'custom' for manual configuration",
33
+ "enum": ["managed", "discover", "custom"],
34
+ "default": "managed"
44
35
  },
45
36
  "vpcIsolation": {
46
37
  "type": "string",
47
- "description": "With managementMode 'managed': 'isolated' gives each stage its own VPC, database and key; 'shared' reuses them across stages. Set it explicitly: when it is omitted the builders do not agree on a default (see ADR-051).",
48
- "enum": ["isolated", "shared"]
49
- },
50
- "usePrismaLambdaLayer": {
51
- "type": "boolean",
52
- "description": "Ship Prisma in a shared Lambda layer. false bundles Prisma into each function instead.",
53
- "default": true
38
+ "description": "VPC isolation strategy: 'isolated' creates separate VPC per stage, 'shared' reuses VPC across stages",
39
+ "enum": ["isolated", "shared"],
40
+ "default": "isolated"
54
41
  },
55
42
  "environment": {
56
43
  "type": "object",
@@ -81,72 +68,93 @@
81
68
  },
82
69
  "integrations": {
83
70
  "type": "array",
84
- "description": "The IntegrationBase subclasses this application exposes. JSON Schema cannot describe a JavaScript class, so validateAppDefinition checks a serialisable view in which each class is replaced by { Definition: <its static Definition> }; `frigg validate` checks each Definition structurally (name, version, modules and their API module definitions).",
71
+ "description": "Array of integration classes to enable in the application",
85
72
  "items": {
86
73
  "type": "object",
87
- "description": "An integration class, seen as { Definition } (see the integrations description)",
88
- "required": ["Definition"],
89
- "properties": {
90
- "Definition": {
91
- "type": "object",
92
- "description": "The integration's static Definition (see integration-definition.schema.json)"
93
- }
94
- }
74
+ "description": "Integration class or configuration object"
95
75
  },
96
76
  "default": []
97
77
  },
78
+ "adminScripts": {
79
+ "type": "array",
80
+ "description": "Admin script classes (extending AdminScriptBase from @friggframework/admin-scripts) served under /admin/scripts",
81
+ "items": {
82
+ "description": "Admin script class"
83
+ },
84
+ "default": []
85
+ },
86
+ "reports": {
87
+ "type": "array",
88
+ "description": "Report classes served by the admin report runner",
89
+ "items": {
90
+ "description": "Report class"
91
+ },
92
+ "default": []
93
+ },
94
+ "admin": {
95
+ "type": "object",
96
+ "description": "Admin script and report runner options",
97
+ "properties": {
98
+ "enableScheduling": {
99
+ "type": "boolean",
100
+ "description": "Provision the EventBridge Scheduler group and role so admin scripts and reports can run on a schedule",
101
+ "default": false
102
+ },
103
+ "includeBuiltinReports": {
104
+ "type": "boolean",
105
+ "description": "Serve the built-in reports alongside the app's own reports",
106
+ "default": false
107
+ }
108
+ },
109
+ "additionalProperties": false
110
+ },
98
111
  "user": {
99
112
  "type": "object",
100
- "description": "User management and authentication. Read by core when it loads the app definition; an omitted block gets the defaults below (ADR-051).",
113
+ "description": "User management and authentication configuration",
101
114
  "properties": {
102
115
  "usePassword": {
103
116
  "type": "boolean",
104
- "description": "Users log in with username and password (POST /user/login). false: users are identified by appUserId (x-frigg-appuserid) instead.",
105
- "default": false
117
+ "description": "Enable password-based authentication for user login",
118
+ "default": true
106
119
  },
107
120
  "password": {
108
121
  "type": "boolean",
109
- "description": "DEPRECATED alias of usePassword: when usePassword is not set, the loader copies this value into it.",
110
- "deprecated": true
122
+ "description": "DEPRECATED: Use 'usePassword' instead. Enable password-based authentication",
123
+ "default": true
111
124
  },
112
125
  "primary": {
113
126
  "type": "string",
114
- "description": "Primary user type. Any value other than 'organization' is treated as 'individual'.",
127
+ "description": "Primary user type for authentication",
115
128
  "enum": ["individual", "organization"],
116
129
  "default": "individual"
117
130
  },
118
131
  "individualUserRequired": {
119
132
  "type": "boolean",
120
- "description": "Require an individual user. POST /user/login logs in individual users only when this is true.",
133
+ "description": "Require individual user for authentication",
121
134
  "default": true
122
135
  },
123
136
  "organizationUserRequired": {
124
137
  "type": "boolean",
125
- "description": "Require an organization user (looked up by appOrgId).",
126
- "default": false
127
- },
128
- "strictUserValidation": {
129
- "type": "boolean",
130
- "description": "With x-frigg headers, reject a user id that does not exist instead of creating and linking it.",
138
+ "description": "Require organization user for authentication",
131
139
  "default": false
132
140
  },
133
141
  "authModes": {
134
142
  "type": "object",
135
- "description": "Authentication modes. When the block is omitted, Frigg tokens and the shared secret are accepted. x-frigg-appUserId and x-frigg-appOrgId headers identify the user with any mode.",
143
+ "description": "Authentication mode configuration - enables multiple authentication strategies. x-frigg-appUserId and x-frigg-appOrgId headers are automatically supported for user identification with any auth mode.",
136
144
  "properties": {
137
145
  "friggToken": {
138
146
  "type": "boolean",
139
- "description": "Accept Frigg bearer tokens from /user/login. Enabled unless false.",
147
+ "description": "Enable Frigg native bearer token authentication (from /user/login)",
140
148
  "default": true
141
149
  },
142
150
  "sharedSecret": {
143
151
  "type": "boolean",
144
- "description": "Accept the x-frigg-api-key header (checked against FRIGG_API_KEY) for backend-to-backend calls. Enabled unless false.",
145
- "default": true
152
+ "description": "Enable shared secret authentication for backend-to-backend communication (requires FRIGG_API_KEY env var and x-frigg-api-key header)",
153
+ "default": false
146
154
  },
147
155
  "adopterJwt": {
148
156
  "type": "boolean",
149
- "description": "Accept JWTs from the adopter's own auth system (requires jwtConfig). Enabled only when true.",
157
+ "description": "Enable custom JWT authentication from adopter's auth system (requires jwtConfig)",
150
158
  "default": false
151
159
  }
152
160
  },
@@ -182,25 +190,22 @@
182
190
  },
183
191
  "fields": {
184
192
  "type": "array",
185
- "description": "Additional user fields. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
186
- "items": {"type": "string"},
187
- "examples": [
188
- ["email", "firstName", "lastName"]
189
- ],
190
- "deprecated": true
193
+ "description": "Additional user fields",
194
+ "items": {
195
+ "type": "string"
196
+ },
197
+ "examples": [["email", "firstName", "lastName"]]
191
198
  },
192
199
  "model": {
193
200
  "type": "object",
194
- "description": "Custom user model class. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
195
- "deprecated": true
201
+ "description": "Custom user model class"
196
202
  }
197
203
  },
198
- "additionalProperties": false,
199
- "default": {}
204
+ "additionalProperties": false
200
205
  },
201
206
  "auth": {
202
207
  "type": "object",
203
- "description": "Authentication configuration. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
208
+ "description": "Authentication configuration for integrations",
204
209
  "properties": {
205
210
  "jwtSecret": {
206
211
  "type": "string",
@@ -209,16 +214,17 @@
209
214
  "tokenExpiry": {
210
215
  "type": "string",
211
216
  "description": "Token expiration time",
212
- "pattern": "^\\d+[smhd]$"
217
+ "pattern": "^\\d+[smhd]$",
218
+ "default": "24h"
213
219
  },
214
220
  "refreshTokenExpiry": {
215
221
  "type": "string",
216
- "description": "Refresh token expiration time",
217
- "pattern": "^\\d+[smhd]$"
222
+ "description": "Refresh token expiration time",
223
+ "pattern": "^\\d+[smhd]$",
224
+ "default": "7d"
218
225
  }
219
226
  },
220
- "additionalProperties": false,
221
- "deprecated": true
227
+ "additionalProperties": false
222
228
  },
223
229
  "database": {
224
230
  "type": "object",
@@ -226,8 +232,8 @@
226
232
  "properties": {
227
233
  "uri": {
228
234
  "type": "string",
229
- "description": "Database connection URI (should be set via environment variable). Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
230
- "deprecated": true
235
+ "description": "Database connection URI (should be set via environment variable)",
236
+ "format": "uri"
231
237
  },
232
238
  "mongoDB": {
233
239
  "type": "object",
@@ -240,8 +246,7 @@
240
246
  },
241
247
  "uri": {
242
248
  "type": "string",
243
- "description": "MongoDB connection URI. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set. The connection string comes from DATABASE_URL.",
244
- "deprecated": true
249
+ "description": "MongoDB connection URI"
245
250
  }
246
251
  },
247
252
  "additionalProperties": true
@@ -269,16 +274,18 @@
269
274
  "properties": {
270
275
  "enable": {
271
276
  "type": "boolean",
272
- "description": "Use PostgreSQL. true provisions or discovers Aurora (unless management says otherwise). When omitted, Aurora is not provisioned, but migrations and the Prisma layer still include PostgreSQL; set false for a MongoDB/DocumentDB app."
277
+ "description": "Enable PostgreSQL database",
278
+ "default": false
273
279
  },
274
280
  "management": {
275
281
  "type": "string",
276
- "description": "How Frigg gets the Aurora cluster (ignored when managementMode is 'managed' or 'existing'). 'discover' (also when omitted): find one, else create one in the stack. 'managed': create it in the stack. 'use-existing': connect to `endpoint` without creating anything.",
277
- "enum": ["discover", "managed", "use-existing"]
282
+ "description": "How to manage the PostgreSQL database",
283
+ "enum": ["discover", "create-new", "existing"],
284
+ "default": "discover"
278
285
  },
279
286
  "endpoint": {
280
287
  "type": "string",
281
- "description": "Existing database endpoint (required when management='use-existing')",
288
+ "description": "Existing database endpoint (when management='existing')",
282
289
  "examples": ["mydb.cluster-abc123.us-east-1.rds.amazonaws.com"]
283
290
  },
284
291
  "port": {
@@ -296,15 +303,10 @@
296
303
  "description": "Database username",
297
304
  "default": "postgres"
298
305
  },
299
- "engineVersion": {
300
- "type": "string",
301
- "description": "Aurora PostgreSQL engine version for a cluster Frigg creates",
302
- "default": "15.13"
303
- },
304
306
  "selfHeal": {
305
307
  "type": "boolean",
306
- "description": "Automatically fix database configuration issues. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
307
- "deprecated": true
308
+ "description": "Automatically fix database configuration issues",
309
+ "default": true
308
310
  },
309
311
  "publiclyAccessible": {
310
312
  "type": "boolean",
@@ -313,7 +315,7 @@
313
315
  },
314
316
  "autoCreateCredentials": {
315
317
  "type": "boolean",
316
- "description": "Create a Secrets Manager secret and rotate the Aurora password when a discovered cluster has none (management='discover' only)",
318
+ "description": "Automatically create Secrets Manager secret and rotate Aurora password when discovering existing cluster (only applies when management='discover')",
317
319
  "default": false
318
320
  },
319
321
  "minCapacity": {
@@ -328,65 +330,7 @@
328
330
  "description": "Maximum Aurora Serverless capacity units (0.5-128)",
329
331
  "minimum": 0.5,
330
332
  "maximum": 128,
331
- "default": 4
332
- },
333
- "clusterId": {
334
- "type": "string",
335
- "description": "Only discover the Aurora cluster with this identifier"
336
- },
337
- "instanceId": {
338
- "type": "string",
339
- "description": "Only discover the Aurora instance with this identifier"
340
- },
341
- "ownership": {
342
- "type": "object",
343
- "description": "Per-resource ownership. When set, `management` is not translated.",
344
- "properties": {
345
- "cluster": {
346
- "type": "string",
347
- "enum": ["stack", "external", "auto"],
348
- "description": "Aurora cluster. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
349
- },
350
- "instance": {
351
- "type": "string",
352
- "enum": ["stack", "external", "auto"],
353
- "description": "Aurora instance. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
354
- },
355
- "subnetGroup": {
356
- "type": "string",
357
- "enum": ["stack", "external", "auto"],
358
- "description": "DB subnet group. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
359
- },
360
- "secret": {
361
- "type": "string",
362
- "enum": ["stack", "external", "auto"],
363
- "description": "Secrets Manager credentials secret. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
364
- }
365
- },
366
- "additionalProperties": false
367
- },
368
- "external": {
369
- "type": "object",
370
- "description": "Ids of externally owned resources (ownership 'external')",
371
- "properties": {
372
- "clusterIdentifier": {"type": "string"},
373
- "instanceIdentifier": {"type": "string"},
374
- "subnetGroupName": {"type": "string"},
375
- "secretArn": {"type": "string"}
376
- },
377
- "additionalProperties": false
378
- }
379
- },
380
- "additionalProperties": false
381
- },
382
- "dynamodb": {
383
- "type": "object",
384
- "description": "DynamoDB access from inside the VPC",
385
- "properties": {
386
- "enable": {
387
- "type": "boolean",
388
- "description": "Add a DynamoDB VPC endpoint",
389
- "default": false
333
+ "default": 1
390
334
  }
391
335
  },
392
336
  "additionalProperties": false
@@ -400,12 +344,14 @@
400
344
  "properties": {
401
345
  "fieldLevelEncryptionMethod": {
402
346
  "type": "string",
403
- "description": "Field-level encryption key. 'kms': Frigg creates or discovers a KMS key and sets KMS_KEY_ARN. 'aes': the app supplies AES_KEY_ID and AES_KEY (list both in `environment`). Omitted: no key is provisioned and deployed stages store sensitive fields unencrypted (core logs a warning). Stages dev, test and local never encrypt.",
404
- "enum": ["kms", "aes"]
347
+ "description": "Method for field-level encryption",
348
+ "enum": ["kms", "aes"],
349
+ "default": "aes"
405
350
  },
406
351
  "createResourceIfNoneFound": {
407
352
  "type": "boolean",
408
- "description": "With 'kms' outside managementMode 'managed': create a KMS key when discovery finds none. When omitted, KMS_KEY_ARN falls back to the AWS_DISCOVERY_KMS_KEY_ID environment variable."
353
+ "description": "Create KMS key if none found during discovery",
354
+ "default": false
409
355
  },
410
356
  "schema": {
411
357
  "type": "object",
@@ -442,48 +388,6 @@
442
388
  }
443
389
  }
444
390
  ]
445
- },
446
- "ownership": {
447
- "type": "object",
448
- "description": "Per-resource ownership. When set, createResourceIfNoneFound is not translated.",
449
- "properties": {
450
- "key": {
451
- "type": "string",
452
- "enum": ["stack", "external", "auto"],
453
- "description": "KMS key. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
454
- }
455
- },
456
- "additionalProperties": false
457
- },
458
- "kmsKeyAlias": {
459
- "type": "boolean",
460
- "description": "Create an alias for a KMS key Frigg creates",
461
- "default": false
462
- },
463
- "keyAlias": {
464
- "type": "string",
465
- "description": "Only discover the KMS key with this alias",
466
- "pattern": "^alias/",
467
- "examples": ["alias/my-app-key"]
468
- },
469
- "disable": {
470
- "type": "object",
471
- "description": "Opt specific core-encrypted fields out of encryption: { Model: ['field.path'] }. Existing encrypted values still decrypt.",
472
- "patternProperties": {
473
- "^[A-Z][a-zA-Z0-9]*$": {
474
- "type": "array",
475
- "items": {
476
- "type": "string",
477
- "minLength": 1
478
- }
479
- }
480
- },
481
- "additionalProperties": false
482
- },
483
- "enable": {
484
- "type": "boolean",
485
- "description": "Encryption is controlled by fieldLevelEncryptionMethod. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
486
- "deprecated": true
487
391
  }
488
392
  },
489
393
  "additionalProperties": false
@@ -494,23 +398,24 @@
494
398
  "properties": {
495
399
  "enable": {
496
400
  "type": "boolean",
497
- "description": "Run the Lambda functions in a VPC",
401
+ "description": "Enable VPC for Lambda functions",
498
402
  "default": false
499
403
  },
500
404
  "management": {
501
405
  "type": "string",
502
- "description": "How Frigg gets the VPC. 'discover' (also when omitted): find one (discovery fails if none exists). 'create-new': create VPC, security group and subnets in the stack. 'use-existing': use `vpcId` (and securityGroupIds / subnets.ids when given). Ignored when `ownership` is set.",
503
- "enum": ["discover", "create-new", "use-existing"]
406
+ "description": "How to manage VPC infrastructure",
407
+ "enum": ["discover", "create-new", "existing"],
408
+ "default": "discover"
504
409
  },
505
410
  "vpcId": {
506
411
  "type": "string",
507
- "description": "Existing VPC ID (required when management='use-existing')",
412
+ "description": "Existing VPC ID (when management='existing')",
508
413
  "pattern": "^vpc-[a-z0-9]+$",
509
414
  "examples": ["vpc-abc123"]
510
415
  },
511
416
  "cidrBlock": {
512
417
  "type": "string",
513
- "description": "CIDR block for a VPC Frigg creates",
418
+ "description": "CIDR block for VPC (when management='create-new')",
514
419
  "pattern": "^([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}$",
515
420
  "default": "10.0.0.0/16"
516
421
  },
@@ -521,9 +426,7 @@
521
426
  "type": "string",
522
427
  "pattern": "^sg-[a-z0-9]+$"
523
428
  },
524
- "examples": [
525
- ["sg-abc123", "sg-def456"]
526
- ]
429
+ "examples": [["sg-abc123", "sg-def456"]]
527
430
  },
528
431
  "subnets": {
529
432
  "type": "object",
@@ -531,20 +434,19 @@
531
434
  "properties": {
532
435
  "management": {
533
436
  "type": "string",
534
- "description": "'create': create the subnets in the stack. 'use-existing': use `ids` (at least 2). 'discover', 'create-new' and 'existing' are accepted for compatibility but have no effect (`frigg validate` warns).",
535
- "enum": ["create", "use-existing", "discover", "create-new", "existing"]
437
+ "description": "How to manage subnets",
438
+ "enum": ["discover", "create-new", "existing"],
439
+ "default": "discover"
536
440
  },
537
441
  "ids": {
538
442
  "type": "array",
539
- "description": "Existing subnet IDs (management='use-existing')",
443
+ "description": "Existing subnet IDs",
540
444
  "items": {
541
445
  "type": "string",
542
446
  "pattern": "^subnet-[a-z0-9]+$"
543
447
  },
544
448
  "minItems": 2,
545
- "examples": [
546
- ["subnet-abc123", "subnet-def456"]
547
- ]
449
+ "examples": [["subnet-abc123", "subnet-def456"]]
548
450
  }
549
451
  },
550
452
  "additionalProperties": false
@@ -555,12 +457,13 @@
555
457
  "properties": {
556
458
  "management": {
557
459
  "type": "string",
558
- "description": "'createAndManage': reuse a well-placed NAT gateway or create one. 'discover', 'create-new' and 'existing' are accepted for compatibility but have no effect (`frigg validate` warns). Set `id` to use an existing NAT gateway.",
559
- "enum": ["createAndManage", "discover", "create-new", "existing"]
460
+ "description": "How to manage NAT Gateway",
461
+ "enum": ["discover", "create-new", "existing"],
462
+ "default": "discover"
560
463
  },
561
464
  "id": {
562
465
  "type": "string",
563
- "description": "Existing NAT Gateway ID (makes the NAT gateway external)",
466
+ "description": "Existing NAT Gateway ID",
564
467
  "pattern": "^nat-[a-z0-9]+$",
565
468
  "examples": ["nat-abc123"]
566
469
  }
@@ -569,112 +472,13 @@
569
472
  },
570
473
  "enableVPCEndpoints": {
571
474
  "type": "boolean",
572
- "description": "Create VPC endpoints for AWS services (S3, DynamoDB, KMS, Secrets Manager). Enabled unless false.",
475
+ "description": "Create VPC endpoints for AWS services (S3, DynamoDB, KMS, Secrets Manager)",
573
476
  "default": true
574
477
  },
575
478
  "selfHeal": {
576
479
  "type": "boolean",
577
- "description": "Repair VPC configuration issues (route table associations) during discovery. When omitted, self-healing of stack-owned subnets is on."
578
- },
579
- "shareAcrossStages": {
580
- "type": "boolean",
581
- "description": "Legacy: true reuses (auto) the VPC and subnets across stages; false creates a VPC, subnets and NAT gateway per stage. Ignored when `ownership` is set."
582
- },
583
- "ownership": {
584
- "type": "object",
585
- "description": "Per-resource ownership. When set, management, subnets, natGateway, shareAcrossStages, enableVPCEndpoints and selfHeal are not translated; use `config` instead.",
586
- "properties": {
587
- "vpc": {
588
- "type": "string",
589
- "enum": ["stack", "external", "auto"],
590
- "description": "VPC. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
591
- },
592
- "securityGroup": {
593
- "type": "string",
594
- "enum": ["stack", "external", "auto"],
595
- "description": "Lambda security group. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
596
- },
597
- "subnets": {
598
- "type": "string",
599
- "enum": ["stack", "external", "auto"],
600
- "description": "Private subnets. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
601
- },
602
- "natGateway": {
603
- "type": "string",
604
- "enum": ["stack", "external", "auto"],
605
- "description": "NAT gateway. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
606
- },
607
- "vpcEndpoints": {
608
- "type": "string",
609
- "enum": ["stack", "external", "auto"],
610
- "description": "VPC endpoints. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
611
- }
612
- },
613
- "additionalProperties": false
614
- },
615
- "external": {
616
- "type": "object",
617
- "description": "Ids of externally owned resources (ownership 'external'); discovered ids are used when omitted",
618
- "properties": {
619
- "vpcId": {
620
- "type": "string",
621
- "pattern": "^vpc-[a-z0-9]+$"
622
- },
623
- "securityGroupIds": {
624
- "type": "array",
625
- "items": {
626
- "type": "string",
627
- "pattern": "^sg-[a-z0-9]+$"
628
- }
629
- },
630
- "subnetIds": {
631
- "type": "array",
632
- "items": {
633
- "type": "string",
634
- "pattern": "^subnet-[a-z0-9]+$"
635
- }
636
- },
637
- "natGatewayId": {
638
- "type": "string",
639
- "pattern": "^nat-[a-z0-9]+$"
640
- },
641
- "vpcEndpointIds": {
642
- "type": "object",
643
- "description": "Endpoint ids by type (s3, dynamodb, kms, secretsManager, sqs)",
644
- "additionalProperties": {"type": "string"}
645
- }
646
- },
647
- "additionalProperties": false
648
- },
649
- "config": {
650
- "type": "object",
651
- "description": "Settings for the ownership-based VPC configuration",
652
- "properties": {
653
- "cidrBlock": {
654
- "type": "string",
655
- "description": "CIDR block for a VPC Frigg creates (wins over vpc.cidrBlock)",
656
- "pattern": "^([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}$"
657
- },
658
- "selfHeal": {
659
- "type": "boolean",
660
- "description": "Recreate missing stack-owned subnets. Enabled unless false."
661
- },
662
- "natGateway": {
663
- "type": "object",
664
- "properties": {
665
- "enable": {
666
- "type": "boolean",
667
- "description": "Resolve a NAT gateway. Enabled unless false."
668
- }
669
- },
670
- "additionalProperties": false
671
- },
672
- "enableVpcEndpoints": {
673
- "type": "boolean",
674
- "description": "Create VPC endpoints. Enabled unless false."
675
- }
676
- },
677
- "additionalProperties": false
480
+ "description": "Automatically fix VPC configuration issues",
481
+ "default": false
678
482
  }
679
483
  },
680
484
  "additionalProperties": false
@@ -719,7 +523,9 @@
719
523
  "enum": ["standard", "advanced"],
720
524
  "default": "standard"
721
525
  },
722
- "description": {"type": "string"}
526
+ "description": {
527
+ "type": "string"
528
+ }
723
529
  }
724
530
  }
725
531
  },
@@ -730,15 +536,15 @@
730
536
  },
731
537
  "secretsManager": {
732
538
  "type": "object",
733
- "description": "AWS Secrets Manager configuration. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
539
+ "description": "AWS Secrets Manager configuration",
734
540
  "properties": {
735
541
  "enable": {
736
542
  "type": "boolean",
737
- "description": "Enable AWS Secrets Manager for secure credential storage"
543
+ "description": "Enable AWS Secrets Manager for secure credential storage",
544
+ "default": false
738
545
  }
739
546
  },
740
- "additionalProperties": false,
741
- "deprecated": true
547
+ "additionalProperties": false
742
548
  },
743
549
  "lambda": {
744
550
  "type": "object",
@@ -748,11 +554,6 @@
748
554
  "type": "boolean",
749
555
  "description": "Scope framework-generated environment variables (queue URLs, migration/scheduler vars) to the functions that consume them instead of broadcasting to every function. Reduces per-function env size against the Lambda 4KB limit",
750
556
  "default": false
751
- },
752
- "keepNestedNodeModules": {
753
- "type": "boolean",
754
- "description": "Keep nested node_modules in function packages (nested Frigg, AWS SDK and Prisma packages are still excluded)",
755
- "default": false
756
557
  }
757
558
  },
758
559
  "additionalProperties": false
@@ -768,15 +569,15 @@
768
569
  },
769
570
  "routeSelectionExpression": {
770
571
  "type": "string",
771
- "description": "Route selection expression for WebSocket. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
772
- "deprecated": true
572
+ "description": "Route selection expression for WebSocket",
573
+ "default": "$request.body.action"
773
574
  }
774
575
  },
775
576
  "additionalProperties": false
776
577
  },
777
578
  "security": {
778
579
  "type": "object",
779
- "description": "Security settings for the application. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
580
+ "description": "Security settings for the application",
780
581
  "properties": {
781
582
  "cors": {
782
583
  "type": "object",
@@ -785,17 +586,16 @@
785
586
  "origin": {
786
587
  "oneOf": [
787
588
  {"type": "string"},
788
- {
789
- "type": "array",
790
- "items": {"type": "string"}
791
- },
589
+ {"type": "array", "items": {"type": "string"}},
792
590
  {"type": "boolean"}
793
591
  ],
794
- "description": "Allowed origins for CORS requests"
592
+ "description": "Allowed origins for CORS requests",
593
+ "default": "http://localhost:3000"
795
594
  },
796
595
  "credentials": {
797
596
  "type": "boolean",
798
- "description": "Allow credentials in CORS requests"
597
+ "description": "Allow credentials in CORS requests",
598
+ "default": true
799
599
  },
800
600
  "methods": {
801
601
  "type": "array",
@@ -820,23 +620,24 @@
820
620
  "windowMs": {
821
621
  "type": "integer",
822
622
  "description": "Time window in milliseconds",
823
- "minimum": 1000
623
+ "minimum": 1000,
624
+ "default": 900000
824
625
  },
825
626
  "max": {
826
- "type": "integer",
627
+ "type": "integer",
827
628
  "description": "Maximum requests per window",
828
- "minimum": 1
629
+ "minimum": 1,
630
+ "default": 100
829
631
  }
830
632
  },
831
633
  "additionalProperties": false
832
634
  }
833
635
  },
834
- "additionalProperties": false,
835
- "deprecated": true
636
+ "additionalProperties": false
836
637
  },
837
638
  "webhooks": {
838
639
  "type": "object",
839
- "description": "Webhook handling configuration. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set. Webhooks are declared per integration (Definition.webhooks).",
640
+ "description": "Webhook handling configuration",
840
641
  "properties": {
841
642
  "secret": {
842
643
  "type": "string",
@@ -845,11 +646,11 @@
845
646
  "prefix": {
846
647
  "type": "string",
847
648
  "description": "Webhook endpoint prefix",
848
- "pattern": "^/[a-zA-Z0-9/_-]*$"
649
+ "pattern": "^/[a-zA-Z0-9/_-]*$",
650
+ "default": "/webhooks"
849
651
  }
850
652
  },
851
- "additionalProperties": false,
852
- "deprecated": true
653
+ "additionalProperties": false
853
654
  },
854
655
  "logging": {
855
656
  "type": "object",
@@ -857,8 +658,9 @@
857
658
  "properties": {
858
659
  "level": {
859
660
  "type": "string",
860
- "description": "Minimum log level, in lower or upper case. Sets FRIGG_LOG_LEVEL (when not info) and the Lambda application log level. When omitted, core logs at info and no Lambda log level is set.",
861
- "enum": ["trace", "debug", "info", "warn", "error", "fatal", "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"]
661
+ "description": "Minimum log level, in lower or upper case. Sets FRIGG_LOG_LEVEL (when not info) and the Lambda application log level.",
662
+ "enum": ["trace", "debug", "info", "warn", "error", "fatal", "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"],
663
+ "default": "info"
862
664
  },
863
665
  "retentionInDays": {
864
666
  "type": "integer",
@@ -867,225 +669,46 @@
867
669
  },
868
670
  "format": {
869
671
  "type": "string",
870
- "description": "Log format. Records are always JSON lines; this key is informational and has no default.",
871
- "enum": ["json"]
872
- }
873
- },
874
- "additionalProperties": false
875
- },
876
- "scheduler": {
877
- "type": "object",
878
- "description": "EventBridge Scheduler resources for one-time jobs. Also enabled automatically when an integration declares webhooks.",
879
- "properties": {
880
- "enable": {
881
- "type": "boolean",
882
- "description": "Provision the scheduler role and dead-letter queue",
883
- "default": false
884
- }
885
- },
886
- "additionalProperties": false
887
- },
888
- "aws": {
889
- "type": "object",
890
- "description": "AWS options for the build",
891
- "properties": {
892
- "discovery": {
893
- "type": "object",
894
- "description": "AWS resource discovery during build/deploy",
895
- "properties": {
896
- "enabled": {
897
- "type": "boolean",
898
- "description": "Force discovery on or off. When omitted, discovery runs when a feature needs it (VPC, KMS, SSM, PostgreSQL) and FRIGG_SKIP_AWS_DISCOVERY is not set."
899
- },
900
- "failOnError": {
901
- "type": "boolean",
902
- "description": "Fail the build when discovery fails",
903
- "default": false
904
- }
905
- },
906
- "additionalProperties": false
907
- }
908
- },
909
- "additionalProperties": false
910
- },
911
- "migration": {
912
- "type": "object",
913
- "description": "Database migration resources",
914
- "properties": {
915
- "ownership": {
916
- "type": "object",
917
- "properties": {
918
- "bucket": {
919
- "type": "string",
920
- "enum": ["stack", "external", "auto"],
921
- "description": "Migration S3 bucket. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
922
- },
923
- "queue": {
924
- "type": "string",
925
- "enum": ["stack", "external", "auto"],
926
- "description": "Migration SQS queue. Who owns the resource: 'stack' (this stack creates it), 'external' (use the id in `external`), 'auto' (reuse what discovery finds, else create)"
927
- }
928
- },
929
- "additionalProperties": false
930
- }
931
- },
932
- "additionalProperties": false
933
- },
934
- "telemetry": {
935
- "type": "object",
936
- "description": "Telemetry and usage tracking (ADR-011). An invalid block disables telemetry at runtime instead of failing.",
937
- "properties": {
938
- "exporter": {
939
- "type": "object",
940
- "description": "Where traces and metrics go. When omitted: 'console' for STAGE=local, else 'none'.",
941
- "properties": {
942
- "type": {
943
- "type": "string",
944
- "enum": ["none", "noop", "console", "otlp", "honeycomb", "datadog"]
945
- },
946
- "endpoint": {
947
- "type": "string",
948
- "description": "OTLP endpoint (honeycomb defaults to https://api.honeycomb.io)"
949
- },
950
- "headers": {
951
- "type": "object",
952
- "additionalProperties": {"type": "string"}
953
- },
954
- "apiKey": {
955
- "type": "string",
956
- "description": "Honeycomb API key (sent as x-honeycomb-team)"
957
- },
958
- "traceExporter": {
959
- "description": "A pre-built OTel trace exporter instance (advanced)"
960
- },
961
- "metricExporter": {
962
- "description": "A pre-built OTel metric exporter instance (advanced)"
963
- }
964
- },
965
- "additionalProperties": false
966
- },
967
- "sampleRatio": {
968
- "type": "number",
969
- "description": "Fraction of traces exported",
970
- "minimum": 0,
971
- "maximum": 1,
972
- "default": 1
973
- },
974
- "northStar": {
975
- "type": "object",
976
- "description": "The usage counter that measures each integration type's value: { default: { name }, byType: { <type>: { name } } }",
977
- "properties": {
978
- "default": {
979
- "type": "object",
980
- "required": ["name"],
981
- "properties": {
982
- "name": {"type": "string"}
983
- }
984
- },
985
- "byType": {
986
- "type": "object",
987
- "additionalProperties": {
988
- "type": "object",
989
- "required": ["name"],
990
- "properties": {
991
- "name": {"type": "string"}
992
- }
993
- }
994
- }
995
- },
996
- "additionalProperties": false
997
- },
998
- "subscribers": {
999
- "type": "array",
1000
- "description": "Telemetry event subscribers: functions or { handler } objects",
1001
- "items": {
1002
- "description": "A function or { handler }"
1003
- }
1004
- }
1005
- },
1006
- "additionalProperties": false
1007
- },
1008
- "admin": {
1009
- "type": "object",
1010
- "description": "Admin Script Runner options (ADR-005, ADR-010)",
1011
- "properties": {
1012
- "includeBuiltinReports": {
1013
- "type": "boolean",
1014
- "description": "Register Frigg's built-in reports",
1015
- "default": false
1016
- },
1017
- "enableScheduling": {
1018
- "type": "boolean",
1019
- "description": "Provision scheduling for admin scripts"
1020
- }
1021
- },
1022
- "additionalProperties": false
1023
- },
1024
- "adminScripts": {
1025
- "type": "array",
1026
- "description": "Admin script classes (each with a static Definition). Validators see each class as { Definition }.",
1027
- "items": {
1028
- "type": "object",
1029
- "required": ["Definition"],
1030
- "properties": {
1031
- "Definition": {"type": "object"}
1032
- }
1033
- },
1034
- "default": []
1035
- },
1036
- "reports": {
1037
- "type": "array",
1038
- "description": "Report classes (each with a static Definition). Validators see each class as { Definition }.",
1039
- "items": {
1040
- "type": "object",
1041
- "required": ["Definition"],
1042
- "properties": {
1043
- "Definition": {"type": "object"}
1044
- }
1045
- },
1046
- "default": []
1047
- },
1048
- "deployment": {
1049
- "type": "object",
1050
- "description": "`frigg deploy` options",
1051
- "properties": {
1052
- "skipPostDeploymentHealthCheck": {
1053
- "type": "boolean",
1054
- "description": "Skip `frigg doctor` after a deploy",
1055
- "default": false
672
+ "description": "Log format. Records are always JSON lines.",
673
+ "enum": ["json"],
674
+ "default": "json"
1056
675
  }
1057
676
  },
1058
677
  "additionalProperties": false
1059
678
  },
1060
679
  "custom": {
1061
680
  "type": "object",
1062
- "description": "Custom application-specific configuration. Not read by the Frigg runtime: it has no effect. Kept so existing definitions stay valid; `frigg validate` warns when it is set.",
681
+ "description": "Custom application-specific configuration",
1063
682
  "properties": {
1064
683
  "appName": {
1065
684
  "type": "string",
1066
- "description": "Application display name"
685
+ "description": "Application display name",
686
+ "default": "My Frigg Application"
1067
687
  },
1068
688
  "version": {
1069
689
  "type": "string",
1070
690
  "description": "Application version",
1071
- "pattern": "^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.-]+)?$"
691
+ "pattern": "^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.-]+)?$",
692
+ "default": "1.0.0"
1072
693
  },
1073
694
  "environment": {
1074
695
  "type": "string",
1075
696
  "description": "Deployment environment/stage",
1076
- "enum": ["development", "staging", "production", "test"]
697
+ "enum": ["development", "staging", "production", "test"],
698
+ "default": "development"
1077
699
  },
1078
700
  "features": {
1079
701
  "type": "object",
1080
702
  "description": "Feature flags and toggles",
1081
703
  "patternProperties": {
1082
- "^[a-zA-Z][a-zA-Z0-9_]*$": {"type": "boolean"}
704
+ "^[a-zA-Z][a-zA-Z0-9_]*$": {
705
+ "type": "boolean"
706
+ }
1083
707
  },
1084
708
  "additionalProperties": false
1085
709
  }
1086
710
  },
1087
- "additionalProperties": true,
1088
- "deprecated": true
711
+ "additionalProperties": true
1089
712
  }
1090
713
  },
1091
714
  "additionalProperties": false,
@@ -1099,15 +722,12 @@
1099
722
  },
1100
723
  "integrations": [],
1101
724
  "user": {
1102
- "usePassword": true,
1103
- "primary": "individual",
1104
- "individualUserRequired": true,
1105
- "organizationUserRequired": false
725
+ "password": true
1106
726
  },
1107
727
  "database": {
1108
728
  "postgres": {
1109
729
  "enable": true,
1110
- "management": "managed"
730
+ "management": "create-new"
1111
731
  }
1112
732
  },
1113
733
  "encryption": {
@@ -1120,8 +740,18 @@
1120
740
  "cidrBlock": "10.0.0.0/16",
1121
741
  "enableVPCEndpoints": true
1122
742
  },
1123
- "ssm": {"enable": true},
1124
- "websockets": {"enable": true},
743
+ "ssm": {
744
+ "enable": true
745
+ },
746
+ "websockets": {
747
+ "enable": true
748
+ },
749
+ "security": {
750
+ "cors": {
751
+ "origin": "http://localhost:3000",
752
+ "credentials": true
753
+ }
754
+ },
1125
755
  "logging": {
1126
756
  "level": "info",
1127
757
  "retentionInDays": 30
package/app-definition.js DELETED
@@ -1,113 +0,0 @@
1
- /**
2
- * App definition helpers shared by the runtime (core) and the tooling
3
- * (devtools, frigg CLI). See ADR-051.
4
- *
5
- * This file loads only the JSON schema, not Ajv, so the runtime can apply
6
- * the schema defaults at cold start without compiling a validator.
7
- */
8
-
9
- const appDefinitionSchema = require('./schemas/app-definition.schema.json');
10
-
11
- function isPlainObject(value) {
12
- if (value === null || typeof value !== 'object') return false;
13
- const proto = Object.getPrototypeOf(value);
14
- return proto === Object.prototype || proto === null;
15
- }
16
-
17
- function cloneDefault(value) {
18
- // Schema defaults are JSON values: a JSON round trip copies them fully.
19
- return value === undefined ? value : JSON.parse(JSON.stringify(value));
20
- }
21
-
22
- /**
23
- * Copy plain objects and arrays, keep everything else (classes, functions,
24
- * instances) by reference.
25
- */
26
- function clonePlain(value) {
27
- if (Array.isArray(value)) return value.map(clonePlain);
28
- if (isPlainObject(value)) {
29
- const copy = {};
30
- for (const [key, inner] of Object.entries(value)) {
31
- copy[key] = clonePlain(inner);
32
- }
33
- return copy;
34
- }
35
- return value;
36
- }
37
-
38
- function applyDefaultsInPlace(schema, data) {
39
- if (!schema || !isPlainObject(data)) return;
40
- const properties = schema.properties || {};
41
- for (const [key, propertySchema] of Object.entries(properties)) {
42
- if (data[key] === undefined && propertySchema.default !== undefined) {
43
- data[key] = cloneDefault(propertySchema.default);
44
- }
45
- if (isPlainObject(data[key]) && propertySchema.properties) {
46
- applyDefaultsInPlace(propertySchema, data[key]);
47
- }
48
- }
49
- }
50
-
51
- /**
52
- * Return a copy of the app definition with every `default` that the
53
- * app-definition schema declares applied, the way Ajv `useDefaults` does:
54
- * only for properties of objects that exist (a block the app leaves out is
55
- * not created unless the block itself has a default, as `user` does). It
56
- * also copies the deprecated `user.password` into `user.usePassword` when
57
- * only the old spelling is set. Classes and other non-plain values are kept by reference.
58
- * The input is not mutated, and the function is idempotent.
59
- *
60
- * This is the only place schema defaults are applied. core's
61
- * loadAppDefinition and devtools' createFriggInfrastructure both call it,
62
- * so a default in the schema is a default at runtime.
63
- *
64
- * @param {object} definition the `Definition` exported by the backend
65
- * @returns {object} the definition with defaults applied
66
- */
67
- function applyAppDefinitionDefaults(definition) {
68
- if (!isPlainObject(definition)) return definition;
69
- const copy = clonePlain(definition);
70
- // user.password is the deprecated spelling of user.usePassword.
71
- if (
72
- isPlainObject(copy.user) &&
73
- copy.user.usePassword === undefined &&
74
- typeof copy.user.password === 'boolean'
75
- ) {
76
- copy.user.usePassword = copy.user.password;
77
- }
78
- applyDefaultsInPlace(appDefinitionSchema, copy);
79
- return copy;
80
- }
81
-
82
- // Keys whose entries are classes with a static Definition.
83
- const CLASS_LIST_KEYS = ['integrations', 'adminScripts', 'reports'];
84
-
85
- /**
86
- * JSON Schema cannot describe a JavaScript class, and apps list integration
87
- * (and admin script, and report) classes. Validators therefore check this serialisable view, in which each
88
- * class is replaced by `{ Definition }` (its static Definition). The schema
89
- * describes that view; `frigg validate` checks the Definition itself.
90
- *
91
- * @param {object} definition the `Definition` exported by the backend
92
- * @returns {object} a shallow copy with the class lists mapped to views
93
- */
94
- function toAppDefinitionSchemaView(definition) {
95
- if (!isPlainObject(definition)) return definition;
96
- const view = { ...definition };
97
- for (const key of CLASS_LIST_KEYS) {
98
- if (Array.isArray(definition[key])) {
99
- view[key] = definition[key].map((entry) =>
100
- typeof entry === 'function'
101
- ? { Definition: entry.Definition }
102
- : entry
103
- );
104
- }
105
- }
106
- return view;
107
- }
108
-
109
- module.exports = {
110
- applyAppDefinitionDefaults,
111
- toAppDefinitionSchemaView,
112
- appDefinitionSchema,
113
- };