@friggframework/schemas 2.0.0--canary.700.80ec1cc.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 +3 -1
- package/api-module-definition.js +93 -0
- package/index.js +13 -3
- package/package.json +3 -2
- package/schemas/api-module-definition.schema.json +23 -0
package/README.md
CHANGED
|
@@ -146,7 +146,9 @@ Defines the structure for Frigg API modules.
|
|
|
146
146
|
**Key Properties:**
|
|
147
147
|
- `moduleName` (required): Module identifier
|
|
148
148
|
- `getName` (required): Function returning module name
|
|
149
|
-
- `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.
|
|
150
152
|
- `env`: Environment variable configuration
|
|
151
153
|
- `config`: Module-specific configuration
|
|
152
154
|
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API module definition helpers shared by validators and the frigg CLI.
|
|
3
|
+
* Real Definitions carry classes and functions that JSON Schema cannot
|
|
4
|
+
* describe; validators check the serialisable view produced here.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function isPlainObject(value) {
|
|
8
|
+
if (value === null || typeof value !== 'object') return false;
|
|
9
|
+
const proto = Object.getPrototypeOf(value);
|
|
10
|
+
return proto === Object.prototype || proto === null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Schema descriptor for a JavaScript function (see api-module-definition
|
|
15
|
+
* schema: `{ type: "function", async?: boolean }`).
|
|
16
|
+
*
|
|
17
|
+
* @param {Function} fn
|
|
18
|
+
* @returns {{ type: 'function', async?: boolean }}
|
|
19
|
+
*/
|
|
20
|
+
function toFunctionDescriptor(fn) {
|
|
21
|
+
const descriptor = { type: 'function' };
|
|
22
|
+
if (fn && fn.constructor && fn.constructor.name === 'AsyncFunction') {
|
|
23
|
+
descriptor.async = true;
|
|
24
|
+
}
|
|
25
|
+
return descriptor;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* JSON Schema cannot describe a JavaScript class or function. Validators
|
|
30
|
+
* therefore check this serialisable view: the API class becomes an empty
|
|
31
|
+
* object, functions become `{ type: "function" }` descriptors, and
|
|
32
|
+
* `undefined` env values are dropped (unset `process.env.*` entries).
|
|
33
|
+
*
|
|
34
|
+
* @param {object} definition the `Definition` exported by an API module
|
|
35
|
+
* @returns {object} a view suitable for the api-module-definition schema
|
|
36
|
+
*/
|
|
37
|
+
function toApiModuleDefinitionSchemaView(definition) {
|
|
38
|
+
if (!isPlainObject(definition)) return definition;
|
|
39
|
+
|
|
40
|
+
const view = { ...definition };
|
|
41
|
+
|
|
42
|
+
if (typeof view.API === 'function') {
|
|
43
|
+
view.API = {};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof view.getName === 'function') {
|
|
47
|
+
view.getName = toFunctionDescriptor(view.getName);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (isPlainObject(view.requiredAuthMethods)) {
|
|
51
|
+
const methods = { ...view.requiredAuthMethods };
|
|
52
|
+
for (const [key, value] of Object.entries(methods)) {
|
|
53
|
+
if (typeof value === 'function') {
|
|
54
|
+
methods[key] = toFunctionDescriptor(value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
view.requiredAuthMethods = methods;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (isPlainObject(view.env)) {
|
|
61
|
+
const env = {};
|
|
62
|
+
for (const [key, value] of Object.entries(view.env)) {
|
|
63
|
+
if (value !== undefined) env[key] = value;
|
|
64
|
+
}
|
|
65
|
+
view.env = env;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (isPlainObject(view.manager)) {
|
|
69
|
+
const manager = { ...view.manager };
|
|
70
|
+
for (const key of ['Entity', 'Credential']) {
|
|
71
|
+
if (typeof manager[key] === 'function') {
|
|
72
|
+
manager[key] = {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (isPlainObject(manager.methods)) {
|
|
76
|
+
const methods = { ...manager.methods };
|
|
77
|
+
for (const [key, value] of Object.entries(methods)) {
|
|
78
|
+
if (typeof value === 'function') {
|
|
79
|
+
methods[key] = {};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
manager.methods = methods;
|
|
83
|
+
}
|
|
84
|
+
view.manager = manager;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return view;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
toApiModuleDefinitionSchemaView,
|
|
92
|
+
toFunctionDescriptor,
|
|
93
|
+
};
|
package/index.js
CHANGED
|
@@ -12,6 +12,9 @@ const path = require('path');
|
|
|
12
12
|
|
|
13
13
|
// Import middleware
|
|
14
14
|
const schemaValidationMiddleware = require('./middleware/schema-validation');
|
|
15
|
+
const {
|
|
16
|
+
toApiModuleDefinitionSchemaView,
|
|
17
|
+
} = require('./api-module-definition');
|
|
15
18
|
|
|
16
19
|
// Initialize AJV with formats
|
|
17
20
|
const ajv = new Ajv({
|
|
@@ -89,12 +92,18 @@ function validateIntegrationDefinition(integrationDefinition) {
|
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
/**
|
|
92
|
-
* Validate API Module Definition
|
|
93
|
-
*
|
|
95
|
+
* Validate API Module Definition.
|
|
96
|
+
* Real Definitions carry classes and functions; validate the serialisable
|
|
97
|
+
* view and return the original definition.
|
|
98
|
+
* @param {object} apiModuleDefinition - API module definition object to validate
|
|
94
99
|
* @returns {object} - Validation result
|
|
95
100
|
*/
|
|
96
101
|
function validateApiModuleDefinition(apiModuleDefinition) {
|
|
97
|
-
|
|
102
|
+
const result = validate(
|
|
103
|
+
'api-module-definition',
|
|
104
|
+
toApiModuleDefinitionSchemaView(apiModuleDefinition)
|
|
105
|
+
);
|
|
106
|
+
return { ...result, data: apiModuleDefinition };
|
|
98
107
|
}
|
|
99
108
|
|
|
100
109
|
/**
|
|
@@ -357,6 +366,7 @@ module.exports = {
|
|
|
357
366
|
// Validation functions
|
|
358
367
|
validate,
|
|
359
368
|
validateAppDefinition,
|
|
369
|
+
toApiModuleDefinitionSchemaView,
|
|
360
370
|
validateIntegrationDefinition,
|
|
361
371
|
validateApiModuleDefinition,
|
|
362
372
|
validateServerlessConfig,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/schemas",
|
|
3
|
-
"version": "2.0.0--canary.
|
|
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,7 +39,8 @@
|
|
|
39
39
|
"validators/",
|
|
40
40
|
"mocks/",
|
|
41
41
|
"middleware/",
|
|
42
|
+
"api-module-definition.js",
|
|
42
43
|
"index.js"
|
|
43
44
|
],
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "2571e692e406f3d39977c865685639b9e895345f"
|
|
45
46
|
}
|
|
@@ -27,6 +27,13 @@
|
|
|
27
27
|
"minLength": 1,
|
|
28
28
|
"maxLength": 100
|
|
29
29
|
},
|
|
30
|
+
"modelName": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"description": "Entity/credential model name used by the Module runtime (e.g. 'Fathom'). Distinct from moduleName, which is the package identifier.",
|
|
33
|
+
"pattern": "^[a-zA-Z][a-zA-Z0-9_]*$",
|
|
34
|
+
"minLength": 1,
|
|
35
|
+
"maxLength": 100
|
|
36
|
+
},
|
|
30
37
|
"requiredAuthMethods": {
|
|
31
38
|
"type": "object",
|
|
32
39
|
"description": "Required authentication methods and configuration",
|
|
@@ -90,6 +97,22 @@
|
|
|
90
97
|
"type": {"type": "string", "enum": ["function"]},
|
|
91
98
|
"async": {"type": "boolean", "default": true}
|
|
92
99
|
}
|
|
100
|
+
},
|
|
101
|
+
"getAuthorizationRequirements": {
|
|
102
|
+
"type": "object",
|
|
103
|
+
"description": "Method that returns the authorization requirements (type, jsonSchema/uiSchema) for non-OAuth flows such as API key",
|
|
104
|
+
"properties": {
|
|
105
|
+
"type": {"type": "string", "enum": ["function"]},
|
|
106
|
+
"async": {"type": "boolean", "default": true}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"setAuthParams": {
|
|
110
|
+
"type": "object",
|
|
111
|
+
"description": "Method that applies authorization parameters (e.g. API key) to the API instance",
|
|
112
|
+
"properties": {
|
|
113
|
+
"type": {"type": "string", "enum": ["function"]},
|
|
114
|
+
"async": {"type": "boolean", "default": true}
|
|
115
|
+
}
|
|
93
116
|
}
|
|
94
117
|
},
|
|
95
118
|
"additionalProperties": false
|