@onlineapps/conn-orch-api-mapper 1.0.26 → 1.0.28
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/API.md +3 -3
- package/package.json +2 -2
- package/src/ApiMapper.js +30 -3
- package/src/index.js +1 -1
package/API.md
CHANGED
|
@@ -67,7 +67,7 @@ Create API mapper instance
|
|
|
67
67
|
```js
|
|
68
68
|
const apiMapper = create({
|
|
69
69
|
openApiSpec: require('./openapi.json'),
|
|
70
|
-
serviceUrl: 'http://
|
|
70
|
+
serviceUrl: 'http://127.0.0.1:3000'
|
|
71
71
|
});
|
|
72
72
|
```
|
|
73
73
|
<a name="ApiMapper"></a>
|
|
@@ -98,7 +98,7 @@ Create a new ApiMapper instance
|
|
|
98
98
|
| --- | --- | --- | --- |
|
|
99
99
|
| config | <code>Object</code> | | Configuration object |
|
|
100
100
|
| config.openApiSpec | <code>Object</code> \| <code>string</code> | | OpenAPI specification object or path |
|
|
101
|
-
|
|
|
101
|
+
| config.serviceUrl | <code>string</code> | | Base URL of the service (required; no defaults) |
|
|
102
102
|
| [config.service] | <code>Object</code> | | Express app instance for direct calls |
|
|
103
103
|
| [config.directCall] | <code>boolean</code> | <code>false</code> | Use direct Express calls instead of HTTP |
|
|
104
104
|
| [config.logger] | <code>Object</code> | | Logger instance |
|
|
@@ -139,7 +139,7 @@ Create a new ApiMapper instance
|
|
|
139
139
|
| --- | --- | --- | --- |
|
|
140
140
|
| config | <code>Object</code> | | Configuration object |
|
|
141
141
|
| config.openApiSpec | <code>Object</code> \| <code>string</code> | | OpenAPI specification object or path |
|
|
142
|
-
|
|
|
142
|
+
| config.serviceUrl | <code>string</code> | | Base URL of the service (required; no defaults) |
|
|
143
143
|
| [config.service] | <code>Object</code> | | Express app instance for direct calls |
|
|
144
144
|
| [config.directCall] | <code>boolean</code> | <code>false</code> | Use direct Express calls instead of HTTP |
|
|
145
145
|
| [config.logger] | <code>Object</code> | | Logger instance |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/conn-orch-api-mapper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
4
4
|
"description": "API mapping connector for OA Drive - maps cookbook operations to HTTP endpoints",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"axios": "^1.4.0",
|
|
24
|
-
"@onlineapps/content-resolver": "1.1.
|
|
24
|
+
"@onlineapps/content-resolver": "1.1.15"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"jest": "^29.5.0",
|
package/src/ApiMapper.js
CHANGED
|
@@ -17,11 +17,10 @@ class ApiMapper {
|
|
|
17
17
|
* @constructor
|
|
18
18
|
* @param {Object} config - Configuration object
|
|
19
19
|
* @param {Object|string} config.openApiSpec - OpenAPI specification object or path
|
|
20
|
-
* @param {string}
|
|
20
|
+
* @param {string} config.serviceUrl - Base URL of the service (required; no topology defaults)
|
|
21
21
|
* @param {Object} [config.service] - Express app instance for direct calls
|
|
22
22
|
* @param {boolean} [config.directCall=false] - Use direct Express calls instead of HTTP
|
|
23
23
|
* @param {Object} [config.logger] - Logger instance
|
|
24
|
-
* @param {number} [config.port=3000] - Service port for direct calls
|
|
25
24
|
*
|
|
26
25
|
* @example
|
|
27
26
|
* const apiMapper = new ApiMapper({
|
|
@@ -34,8 +33,12 @@ class ApiMapper {
|
|
|
34
33
|
throw new Error('OpenAPI specification is required');
|
|
35
34
|
}
|
|
36
35
|
|
|
36
|
+
if (typeof config.serviceUrl !== 'string' || config.serviceUrl.trim().length === 0) {
|
|
37
|
+
throw new Error('[ApiMapper] Missing configuration - serviceUrl is required (no defaults)');
|
|
38
|
+
}
|
|
39
|
+
|
|
37
40
|
this.openApiSpec = config.openApiSpec;
|
|
38
|
-
this.serviceUrl = config.serviceUrl
|
|
41
|
+
this.serviceUrl = config.serviceUrl;
|
|
39
42
|
this.service = config.service; // Express app for direct calls
|
|
40
43
|
this.directCall = config.directCall === true;
|
|
41
44
|
this.logger = config.logger || console;
|
|
@@ -557,6 +560,9 @@ class ApiMapper {
|
|
|
557
560
|
operations[operationId] = {
|
|
558
561
|
method: (operation.method || 'POST').toUpperCase(),
|
|
559
562
|
path: operation.endpoint || `/${operationId}`,
|
|
563
|
+
// Static headers from operations.json (e.g. x-validation-request).
|
|
564
|
+
// NOTE: account-id is controlled by workflow context (_system.account_id) and must not be overridden here.
|
|
565
|
+
headers: operation.headers || null,
|
|
560
566
|
// Store original operations.json input schema for type-driven descriptor handling
|
|
561
567
|
input: operation.input || null,
|
|
562
568
|
parameters: operation.input ? this._convertOperationsJsonInputToOpenApi(operation.input) : [],
|
|
@@ -693,6 +699,27 @@ class ApiMapper {
|
|
|
693
699
|
data: null
|
|
694
700
|
};
|
|
695
701
|
|
|
702
|
+
// operations.json static headers (if present)
|
|
703
|
+
if (operation && operation.headers && typeof operation.headers === 'object') {
|
|
704
|
+
Object.entries(operation.headers).forEach(([k, v]) => {
|
|
705
|
+
if (!k) return;
|
|
706
|
+
// Never allow operation-level config to override tenant header
|
|
707
|
+
if (String(k).toLowerCase() === 'account-id') return;
|
|
708
|
+
|
|
709
|
+
// Optional: allow ${context.path} variable resolution (no env side-effects here).
|
|
710
|
+
if (typeof v === 'string' && v.startsWith('${') && v.endsWith('}')) {
|
|
711
|
+
const path = v.slice(2, -1);
|
|
712
|
+
const resolved = this._getValueFromPath(context, path);
|
|
713
|
+
if (resolved !== undefined) {
|
|
714
|
+
request.headers[k] = resolved;
|
|
715
|
+
}
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
request.headers[k] = v;
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
|
|
696
723
|
// Process path parameters
|
|
697
724
|
operation.parameters.forEach(param => {
|
|
698
725
|
const value = input[param.name];
|
package/src/index.js
CHANGED