@friggframework/schemas 2.0.0-next.30

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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Left Hook Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,377 @@
1
+ # @friggframework/schemas
2
+
3
+ Canonical JSON Schema definitions for the Frigg Framework, providing formal validation and documentation for all core configuration objects.
4
+
5
+ ## Overview
6
+
7
+ This package contains the official, versioned schemas for:
8
+
9
+ - **App Definition**: Configuration for Frigg applications
10
+ - **Integration Definition**: Configuration for Frigg integrations
11
+ - **API Module Definition**: Configuration for Frigg API modules
12
+ - **Serverless Configuration**: AWS deployment configuration
13
+ - **Environment Configuration**: Environment variable management
14
+ - **Core Models**: User, Entity, and Credential data models
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @friggframework/schemas
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Basic Validation
25
+
26
+ ```javascript
27
+ const { validateAppDefinition } = require('@friggframework/schemas');
28
+
29
+ const appDefinition = {
30
+ integrations: [],
31
+ user: { password: true },
32
+ encryption: { useDefaultKMSForFieldLevelEncryption: true }
33
+ };
34
+
35
+ const result = validateAppDefinition(appDefinition);
36
+
37
+ if (result.valid) {
38
+ console.log('✅ App definition is valid');
39
+ } else {
40
+ console.error('❌ Validation errors:', result.errors);
41
+ }
42
+ ```
43
+
44
+ ### Advanced Validation
45
+
46
+ ```javascript
47
+ const { validate, formatErrors } = require('@friggframework/schemas');
48
+
49
+ // Validate any schema by name
50
+ const result = validate('integration-definition', integrationData);
51
+
52
+ if (!result.valid) {
53
+ console.error('Validation failed:');
54
+ console.error(formatErrors(result.errors));
55
+ }
56
+ ```
57
+
58
+ ### Schema Introspection
59
+
60
+ ```javascript
61
+ const { getSchemas, getSchema } = require('@friggframework/schemas');
62
+
63
+ // Get all available schemas
64
+ const allSchemas = getSchemas();
65
+ console.log('Available schemas:', Object.keys(allSchemas));
66
+
67
+ // Get a specific schema
68
+ const appSchema = getSchema('app-definition');
69
+ console.log('App definition schema:', appSchema);
70
+ ```
71
+
72
+ ## Available Schemas
73
+
74
+ ### App Definition Schema
75
+
76
+ Defines the structure for Frigg application configuration.
77
+
78
+ **Key Properties:**
79
+ - `integrations` (required): Array of integration classes
80
+ - `user`: User management configuration
81
+ - `security`: CORS, rate limiting, and security settings
82
+ - `encryption`: KMS and encryption settings
83
+ - `logging`: Logging configuration
84
+ - `custom`: Application-specific settings
85
+
86
+ **Example:**
87
+ ```javascript
88
+ const appDefinition = {
89
+ integrations: [HubSpotIntegration],
90
+ user: { password: true },
91
+ encryption: { useDefaultKMSForFieldLevelEncryption: true },
92
+ vpc: { enable: true },
93
+ security: {
94
+ cors: {
95
+ origin: "http://localhost:3000",
96
+ credentials: true
97
+ }
98
+ },
99
+ logging: { level: "info" },
100
+ custom: {
101
+ appName: "My Frigg App",
102
+ version: "1.0.0",
103
+ environment: "development"
104
+ }
105
+ };
106
+ ```
107
+
108
+ ### Integration Definition Schema
109
+
110
+ Defines the structure for Frigg integrations.
111
+
112
+ **Key Properties:**
113
+ - `name` (required): Integration identifier
114
+ - `version` (required): Semantic version
115
+ - `options`: Configuration options and display properties
116
+ - `capabilities`: Authentication, webhooks, sync capabilities
117
+ - `requirements`: Environment variables and dependencies
118
+
119
+ **Example:**
120
+ ```javascript
121
+ const integrationDefinition = {
122
+ name: "hubspot",
123
+ version: "2.0.0",
124
+ options: {
125
+ type: "api",
126
+ hasUserConfig: true,
127
+ display: {
128
+ name: "HubSpot CRM",
129
+ description: "Integrate with HubSpot for CRM functionality",
130
+ category: "CRM",
131
+ tags: ["crm", "marketing"]
132
+ }
133
+ },
134
+ capabilities: {
135
+ auth: ["oauth2"],
136
+ webhooks: true,
137
+ sync: { bidirectional: true, incremental: true }
138
+ }
139
+ };
140
+ ```
141
+
142
+ ### API Module Definition Schema
143
+
144
+ Defines the structure for Frigg API modules.
145
+
146
+ **Key Properties:**
147
+ - `moduleName` (required): Module identifier
148
+ - `getName` (required): Function returning module name
149
+ - `requiredAuthMethods` (required): Authentication configuration
150
+ - `env`: Environment variable configuration
151
+ - `config`: Module-specific configuration
152
+
153
+ **Example:**
154
+ ```javascript
155
+ const apiModuleDefinition = {
156
+ moduleName: "hubspot",
157
+ getName: function() { return "hubspot"; },
158
+ requiredAuthMethods: {
159
+ getToken: async function(api, params) { /* implementation */ },
160
+ apiPropertiesToPersist: {
161
+ credential: ["access_token", "refresh_token"],
162
+ entity: ["external_id", "portal_id"]
163
+ },
164
+ getCredentialDetails: async function(api) { /* implementation */ },
165
+ testAuthRequest: async function() { /* implementation */ }
166
+ },
167
+ env: {
168
+ client_id: process.env.HUBSPOT_CLIENT_ID,
169
+ client_secret: process.env.HUBSPOT_CLIENT_SECRET
170
+ }
171
+ };
172
+ ```
173
+
174
+ ### Serverless Configuration Schema
175
+
176
+ Defines the structure for Serverless Framework configuration used in AWS deployments.
177
+
178
+ **Key Properties:**
179
+ - `service` (required): Service name for the deployment
180
+ - `provider` (required): Cloud provider configuration (AWS, runtime, region, etc.)
181
+ - `functions`: Lambda function definitions with handlers and events
182
+ - `resources`: CloudFormation resource definitions
183
+ - `plugins`: Serverless Framework plugins
184
+
185
+ **Example:**
186
+ ```javascript
187
+ const serverlessConfig = {
188
+ frameworkVersion: ">=3.17.0",
189
+ service: "frigg-backend",
190
+ provider: {
191
+ name: "aws",
192
+ runtime: "nodejs20.x",
193
+ timeout: 30,
194
+ region: "us-east-1"
195
+ },
196
+ functions: {
197
+ api: {
198
+ handler: "./src/api.handler",
199
+ events: [{
200
+ http: {
201
+ path: "/api/{proxy+}",
202
+ method: "ANY",
203
+ cors: true
204
+ }
205
+ }]
206
+ }
207
+ }
208
+ };
209
+ ```
210
+
211
+ ### Environment Configuration Schema
212
+
213
+ Defines the structure for environment variable management and validation.
214
+
215
+ **Key Properties:**
216
+ - `environments`: Environment-specific configurations (development, staging, production)
217
+ - `global`: Global settings for masking, encryption, and audit logging
218
+ - `templates`: Reusable templates for different integration types
219
+
220
+ **Example:**
221
+ ```javascript
222
+ const environmentConfig = {
223
+ environments: {
224
+ development: {
225
+ variables: {
226
+ DATABASE_URL: {
227
+ value: "mongodb://localhost:27017/frigg-dev",
228
+ required: true,
229
+ sensitive: true,
230
+ description: "MongoDB connection string"
231
+ }
232
+ },
233
+ integrations: {
234
+ hubspot: {
235
+ required: ["HUBSPOT_CLIENT_ID", "HUBSPOT_CLIENT_SECRET"],
236
+ prefix: "HUBSPOT"
237
+ }
238
+ }
239
+ }
240
+ },
241
+ global: {
242
+ encryptionKeys: {
243
+ kmsKeyId: "12345678-1234-1234-1234-123456789abc",
244
+ algorithm: "AES-256-GCM"
245
+ }
246
+ }
247
+ };
248
+ ```
249
+
250
+ ### Core Models Schema
251
+
252
+ Defines the structure for core Frigg data models including User, Entity, and Credential.
253
+
254
+ **Key Properties:**
255
+ - `user`: User model with authentication, preferences, and permissions
256
+ - `credential`: Authentication credential storage with encryption
257
+ - `entity`: Data entity configuration with sync settings
258
+
259
+ **Example:**
260
+ ```javascript
261
+ const coreModels = {
262
+ user: {
263
+ _id: "507f1f77bcf86cd799439011",
264
+ email: "user@example.com",
265
+ role: "user",
266
+ permissions: ["integrations:read", "integrations:write"],
267
+ preferences: {
268
+ theme: "dark",
269
+ notifications: { email: true }
270
+ }
271
+ },
272
+ credential: {
273
+ _id: "507f1f77bcf86cd799439012",
274
+ userId: "507f1f77bcf86cd799439011",
275
+ subType: "hubspot",
276
+ auth_is_valid: true,
277
+ authData: {
278
+ access_token: "encrypted_token",
279
+ token_type: "Bearer"
280
+ }
281
+ },
282
+ entity: {
283
+ _id: "507f1f77bcf86cd799439013",
284
+ credentialId: "507f1f77bcf86cd799439012",
285
+ userId: "507f1f77bcf86cd799439011",
286
+ subType: "contact",
287
+ name: "HubSpot Contacts",
288
+ status: "active"
289
+ }
290
+ };
291
+ ```
292
+
293
+ ## API Reference
294
+
295
+ ### Validation Functions
296
+
297
+ #### `validate(schemaName, data)`
298
+ Validates data against a named schema.
299
+
300
+ **Parameters:**
301
+ - `schemaName` (string): Name of schema ('app-definition', 'integration-definition', 'api-module-definition', 'serverless-config', 'environment-config', 'core-models')
302
+ - `data` (object): Data to validate
303
+
304
+ **Returns:** `{ valid: boolean, errors: array|null, data: object }`
305
+
306
+ #### `validateAppDefinition(appDefinition)`
307
+ Validates an app definition object.
308
+
309
+ #### `validateIntegrationDefinition(integrationDefinition)`
310
+ Validates an integration definition object.
311
+
312
+ #### `validateApiModuleDefinition(apiModuleDefinition)`
313
+ Validates an API module definition object.
314
+
315
+ #### `validateServerlessConfig(serverlessConfig)`
316
+ Validates a Serverless Framework configuration object.
317
+
318
+ #### `validateEnvironmentConfig(environmentConfig)`
319
+ Validates an environment configuration object.
320
+
321
+ #### `validateCoreModels(coreModels)`
322
+ Validates core data models (User, Entity, Credential).
323
+
324
+ ### Schema Access Functions
325
+
326
+ #### `getSchemas()`
327
+ Returns all available schemas as an object.
328
+
329
+ #### `getSchema(schemaName)`
330
+ Returns a specific schema by name.
331
+
332
+ ### Utility Functions
333
+
334
+ #### `formatErrors(errors)`
335
+ Formats AJV validation errors for human-readable output.
336
+
337
+ ## Development
338
+
339
+ ### Running Schema Validation
340
+
341
+ ```bash
342
+ npm run validate
343
+ ```
344
+
345
+ This validates all schemas against the JSON Schema meta-schema and tests all examples.
346
+
347
+ ### Testing
348
+
349
+ ```bash
350
+ npm test
351
+ ```
352
+
353
+ ## Schema Versioning
354
+
355
+ Schemas follow semantic versioning. Breaking changes to schemas will result in major version bumps.
356
+
357
+ Current schema versions:
358
+ - App Definition: Draft-07 (JSON Schema)
359
+ - Integration Definition: Draft-07 (JSON Schema)
360
+ - API Module Definition: Draft-07 (JSON Schema)
361
+ - Serverless Configuration: Draft-07 (JSON Schema)
362
+ - Environment Configuration: Draft-07 (JSON Schema)
363
+ - Core Models: Draft-07 (JSON Schema)
364
+
365
+ ## Contributing
366
+
367
+ When updating schemas:
368
+
369
+ 1. Update the schema file in `schemas/`
370
+ 2. Update examples in the schema
371
+ 3. Run `npm run validate` to ensure validity
372
+ 4. Update this README if needed
373
+ 5. Update version if breaking changes
374
+
375
+ ## License
376
+
377
+ MIT - see LICENSE file for details.
package/index.js ADDED
@@ -0,0 +1,173 @@
1
+ /**
2
+ * @friggframework/schemas - Canonical JSON Schema definitions for Frigg Framework
3
+ *
4
+ * This package provides formal JSON Schema definitions for all core Frigg configuration
5
+ * objects, along with runtime validation utilities.
6
+ */
7
+
8
+ const Ajv = require('ajv');
9
+ const addFormats = require('ajv-formats');
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ // Initialize AJV with formats
14
+ const ajv = new Ajv({
15
+ allErrors: true,
16
+ verbose: true,
17
+ strict: false
18
+ });
19
+ addFormats(ajv);
20
+
21
+ // Load all schemas
22
+ const schemas = {};
23
+ const schemaDir = path.join(__dirname, 'schemas');
24
+
25
+ // Load schema files
26
+ const schemaFiles = [
27
+ 'app-definition.schema.json',
28
+ 'integration-definition.schema.json',
29
+ 'api-module-definition.schema.json',
30
+ 'serverless-config.schema.json',
31
+ 'environment-config.schema.json',
32
+ 'core-models.schema.json'
33
+ ];
34
+
35
+ schemaFiles.forEach(file => {
36
+ const schemaPath = path.join(schemaDir, file);
37
+ const schemaContent = JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
38
+ const schemaName = file.replace('.schema.json', '');
39
+
40
+ schemas[schemaName] = schemaContent;
41
+ ajv.addSchema(schemaContent, schemaName);
42
+ });
43
+
44
+ /**
45
+ * Validate an object against a schema
46
+ * @param {string} schemaName - Name of the schema to validate against
47
+ * @param {object} data - Data to validate
48
+ * @returns {object} - Validation result with { valid: boolean, errors?: array }
49
+ */
50
+ function validate(schemaName, data) {
51
+ const validator = ajv.getSchema(schemaName);
52
+
53
+ if (!validator) {
54
+ throw new Error(`Schema '${schemaName}' not found. Available schemas: ${Object.keys(schemas).join(', ')}`);
55
+ }
56
+
57
+ const valid = validator(data);
58
+
59
+ return {
60
+ valid,
61
+ errors: valid ? null : validator.errors,
62
+ data
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Validate App Definition
68
+ * @param {object} appDefinition - App definition object to validate
69
+ * @returns {object} - Validation result
70
+ */
71
+ function validateAppDefinition(appDefinition) {
72
+ return validate('app-definition', appDefinition);
73
+ }
74
+
75
+ /**
76
+ * Validate Integration Definition
77
+ * @param {object} integrationDefinition - Integration definition object to validate
78
+ * @returns {object} - Validation result
79
+ */
80
+ function validateIntegrationDefinition(integrationDefinition) {
81
+ return validate('integration-definition', integrationDefinition);
82
+ }
83
+
84
+ /**
85
+ * Validate API Module Definition
86
+ * @param {object} apiModuleDefinition - API module definition object to validate
87
+ * @returns {object} - Validation result
88
+ */
89
+ function validateApiModuleDefinition(apiModuleDefinition) {
90
+ return validate('api-module-definition', apiModuleDefinition);
91
+ }
92
+
93
+ /**
94
+ * Validate Serverless Configuration
95
+ * @param {object} serverlessConfig - Serverless configuration object to validate
96
+ * @returns {object} - Validation result
97
+ */
98
+ function validateServerlessConfig(serverlessConfig) {
99
+ return validate('serverless-config', serverlessConfig);
100
+ }
101
+
102
+ /**
103
+ * Validate Environment Configuration
104
+ * @param {object} environmentConfig - Environment configuration object to validate
105
+ * @returns {object} - Validation result
106
+ */
107
+ function validateEnvironmentConfig(environmentConfig) {
108
+ return validate('environment-config', environmentConfig);
109
+ }
110
+
111
+ /**
112
+ * Validate Core Models
113
+ * @param {object} coreModels - Core models object to validate
114
+ * @returns {object} - Validation result
115
+ */
116
+ function validateCoreModels(coreModels) {
117
+ return validate('core-models', coreModels);
118
+ }
119
+
120
+ /**
121
+ * Get all available schemas
122
+ * @returns {object} - Object containing all loaded schemas
123
+ */
124
+ function getSchemas() {
125
+ return { ...schemas };
126
+ }
127
+
128
+ /**
129
+ * Get a specific schema by name
130
+ * @param {string} schemaName - Name of the schema to retrieve
131
+ * @returns {object} - Schema object
132
+ */
133
+ function getSchema(schemaName) {
134
+ if (!schemas[schemaName]) {
135
+ throw new Error(`Schema '${schemaName}' not found. Available schemas: ${Object.keys(schemas).join(', ')}`);
136
+ }
137
+ return schemas[schemaName];
138
+ }
139
+
140
+ /**
141
+ * Format validation errors for human-readable output
142
+ * @param {array} errors - AJV validation errors
143
+ * @returns {string} - Formatted error message
144
+ */
145
+ function formatErrors(errors) {
146
+ if (!errors || errors.length === 0) {
147
+ return 'No errors';
148
+ }
149
+
150
+ return errors.map(error => {
151
+ const instancePath = error.instancePath || 'root';
152
+ const message = error.message;
153
+ const allowedValues = error.params?.allowedValues ?
154
+ ` (allowed: ${error.params.allowedValues.join(', ')})` : '';
155
+
156
+ return `${instancePath}: ${message}${allowedValues}`;
157
+ }).join('\n');
158
+ }
159
+
160
+ module.exports = {
161
+ validate,
162
+ validateAppDefinition,
163
+ validateIntegrationDefinition,
164
+ validateApiModuleDefinition,
165
+ validateServerlessConfig,
166
+ validateEnvironmentConfig,
167
+ validateCoreModels,
168
+ getSchemas,
169
+ getSchema,
170
+ formatErrors,
171
+ schemas,
172
+ ajv
173
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@friggframework/schemas",
3
+ "version": "2.0.0-next.30",
4
+ "description": "Canonical JSON Schema definitions for Frigg Framework",
5
+ "main": "index.js",
6
+ "author": "",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/friggframework/frigg.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/friggframework/frigg/issues"
14
+ },
15
+ "homepage": "https://github.com/friggframework/frigg#readme",
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "scripts": {
20
+ "test": "jest",
21
+ "validate": "node scripts/validate-schemas.js",
22
+ "build": "node scripts/build-schemas.js"
23
+ },
24
+ "keywords": [
25
+ "frigg",
26
+ "schemas",
27
+ "validation",
28
+ "json-schema"
29
+ ],
30
+ "dependencies": {
31
+ "ajv": "^8.12.0",
32
+ "ajv-formats": "^2.1.1"
33
+ },
34
+ "devDependencies": {
35
+ "jest": "^29.7.0"
36
+ },
37
+ "files": [
38
+ "schemas/",
39
+ "validators/",
40
+ "index.js"
41
+ ],
42
+ "gitHead": "d7ae62b34be71a239fa25255f81cde87da576a95"
43
+ }