@onlineapps/conn-orch-api-mapper 1.0.32 → 1.0.34
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 +9 -9
- package/README.md +2 -2
- package/package.json +2 -2
- package/src/ApiMapper.js +42 -23
- package/src/index.js +11 -8
package/API.md
CHANGED
|
@@ -19,7 +19,7 @@ Handles OpenAPI parsing, request transformation, and response mapping.</p>
|
|
|
19
19
|
## Functions
|
|
20
20
|
|
|
21
21
|
<dl>
|
|
22
|
-
<dt><a href="#
|
|
22
|
+
<dt><a href="#loadOperations">loadOperations(spec)</a> ⇒ <code>Object</code></dt>
|
|
23
23
|
<dd><p>Load OpenAPI specification</p>
|
|
24
24
|
</dd>
|
|
25
25
|
<dt><a href="#mapOperationToEndpoint">mapOperationToEndpoint(operationName)</a> ⇒ <code>Object</code></dt>
|
|
@@ -57,7 +57,7 @@ Create API mapper instance
|
|
|
57
57
|
| Param | Type | Default | Description |
|
|
58
58
|
| --- | --- | --- | --- |
|
|
59
59
|
| config | <code>Object</code> | | Configuration options |
|
|
60
|
-
| config.
|
|
60
|
+
| config.operations | <code>Object</code> \| <code>string</code> | | Operations spec (operations.json contract; legacy OpenAPI accepted as fallback) |
|
|
61
61
|
| config.serviceUrl | <code>string</code> | | Base URL of the service |
|
|
62
62
|
| [config.service] | <code>Object</code> | | Express app instance for direct calls |
|
|
63
63
|
| [config.directCall] | <code>boolean</code> | <code>false</code> | Use direct Express calls instead of HTTP |
|
|
@@ -66,7 +66,7 @@ Create API mapper instance
|
|
|
66
66
|
**Example**
|
|
67
67
|
```js
|
|
68
68
|
const apiMapper = create({
|
|
69
|
-
|
|
69
|
+
operations: require('./openapi.json'),
|
|
70
70
|
serviceUrl: 'http://127.0.0.1:3000'
|
|
71
71
|
});
|
|
72
72
|
```
|
|
@@ -97,7 +97,7 @@ Create a new ApiMapper instance
|
|
|
97
97
|
| Param | Type | Default | Description |
|
|
98
98
|
| --- | --- | --- | --- |
|
|
99
99
|
| config | <code>Object</code> | | Configuration object |
|
|
100
|
-
| config.
|
|
100
|
+
| config.operations | <code>Object</code> \| <code>string</code> | | Operations spec (operations.json contract; legacy OpenAPI accepted as fallback) |
|
|
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 |
|
|
@@ -107,7 +107,7 @@ Create a new ApiMapper instance
|
|
|
107
107
|
**Example**
|
|
108
108
|
```js
|
|
109
109
|
const apiMapper = new ApiMapper({
|
|
110
|
-
|
|
110
|
+
operations: require('./openapi.json'),
|
|
111
111
|
serviceUrl: 'http://hello-service:3000'
|
|
112
112
|
});
|
|
113
113
|
```
|
|
@@ -138,7 +138,7 @@ Create a new ApiMapper instance
|
|
|
138
138
|
| Param | Type | Default | Description |
|
|
139
139
|
| --- | --- | --- | --- |
|
|
140
140
|
| config | <code>Object</code> | | Configuration object |
|
|
141
|
-
| config.
|
|
141
|
+
| config.operations | <code>Object</code> \| <code>string</code> | | Operations spec (operations.json contract; legacy OpenAPI accepted as fallback) |
|
|
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 |
|
|
@@ -148,13 +148,13 @@ Create a new ApiMapper instance
|
|
|
148
148
|
**Example**
|
|
149
149
|
```js
|
|
150
150
|
const apiMapper = new ApiMapper({
|
|
151
|
-
|
|
151
|
+
operations: require('./openapi.json'),
|
|
152
152
|
serviceUrl: 'http://hello-service:3000'
|
|
153
153
|
});
|
|
154
154
|
```
|
|
155
|
-
<a name="
|
|
155
|
+
<a name="loadOperations"></a>
|
|
156
156
|
|
|
157
|
-
##
|
|
157
|
+
## loadOperations(spec) ⇒ <code>Object</code>
|
|
158
158
|
Load OpenAPI specification
|
|
159
159
|
|
|
160
160
|
**Kind**: global function
|
package/README.md
CHANGED
|
@@ -231,9 +231,9 @@ const valid = await mapper.validateOperation({
|
|
|
231
231
|
params: { name: 'World' }
|
|
232
232
|
});
|
|
233
233
|
|
|
234
|
-
// Generate request from
|
|
234
|
+
// Generate request from operations spec
|
|
235
235
|
const request = await mapper.fromOpenAPI({
|
|
236
|
-
spec:
|
|
236
|
+
spec: operationsSpec,
|
|
237
237
|
operationId: 'greetUser',
|
|
238
238
|
params: { name: 'World' }
|
|
239
239
|
});
|
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.34",
|
|
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.16"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"jest": "^29.5.0",
|
package/src/ApiMapper.js
CHANGED
|
@@ -5,39 +5,54 @@ const ContentAccessor = require('@onlineapps/content-resolver');
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @class ApiMapper
|
|
8
|
-
* @description Maps cookbook operations to HTTP API endpoints using
|
|
8
|
+
* @description Maps cookbook operations to HTTP API endpoints using the
|
|
9
|
+
* operations.json contract (see operations-registry-contract.md §3). A legacy
|
|
10
|
+
* OpenAPI `paths` payload is still accepted as a fallback during migration.
|
|
11
|
+
*
|
|
9
12
|
* Handles request building, variable resolution, and response transformation.
|
|
10
13
|
*
|
|
11
14
|
* This is the core logic moved from service-wrapper's ApiCaller to make
|
|
12
15
|
* service-wrapper a true thin orchestration layer.
|
|
16
|
+
*
|
|
17
|
+
* @see api/docs/standards/operations-registry-contract.md §3 Operation schema
|
|
13
18
|
*/
|
|
14
19
|
class ApiMapper {
|
|
15
20
|
/**
|
|
16
|
-
* Create a new ApiMapper instance
|
|
21
|
+
* Create a new ApiMapper instance.
|
|
22
|
+
*
|
|
17
23
|
* @constructor
|
|
18
24
|
* @param {Object} config - Configuration object
|
|
19
|
-
* @param {Object
|
|
25
|
+
* @param {Object} config.operations - Operations specification. Primary format:
|
|
26
|
+
* `{ operations: { <operationId>: { method, endpoint, input, output, ... } } }`
|
|
27
|
+
* (see operations-registry-contract.md §3). Legacy OpenAPI `{ paths }`
|
|
28
|
+
* payloads are still accepted as a fallback.
|
|
20
29
|
* @param {string} config.serviceUrl - Base URL of the service (required; no topology defaults)
|
|
21
30
|
* @param {Object} [config.service] - Express app instance for direct calls
|
|
22
31
|
* @param {boolean} [config.directCall=false] - Use direct Express calls instead of HTTP
|
|
23
|
-
* @param {Object}
|
|
32
|
+
* @param {Object} config.logger - Logger instance (required; must expose `warn`)
|
|
24
33
|
*
|
|
25
34
|
* @example
|
|
26
35
|
* const apiMapper = new ApiMapper({
|
|
27
|
-
*
|
|
28
|
-
* serviceUrl: 'http://hello-service:3000'
|
|
36
|
+
* operations: require('./config/service/operations.json'),
|
|
37
|
+
* serviceUrl: 'http://hello-service:3000',
|
|
38
|
+
* logger
|
|
29
39
|
* });
|
|
30
40
|
*/
|
|
31
41
|
constructor(config) {
|
|
32
|
-
if (!config.
|
|
33
|
-
throw new Error('
|
|
42
|
+
if (!config.operations) {
|
|
43
|
+
throw new Error('[ApiMapper] operations specification is required (see operations-registry-contract.md §3)');
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
if (typeof config.serviceUrl !== 'string' || config.serviceUrl.trim().length === 0) {
|
|
37
47
|
throw new Error('[ApiMapper] Missing configuration - serviceUrl is required (no defaults)');
|
|
38
48
|
}
|
|
39
49
|
|
|
40
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Raw operations specification as provided by the caller. For operations.json
|
|
52
|
+
* payloads this is `{ operations: { ... } }`; for legacy OpenAPI it is
|
|
53
|
+
* `{ paths: { ... } }`.
|
|
54
|
+
*/
|
|
55
|
+
this.operationsSpec = config.operations;
|
|
41
56
|
this.serviceUrl = config.serviceUrl;
|
|
42
57
|
this.service = config.service;
|
|
43
58
|
this.directCall = config.directCall === true;
|
|
@@ -46,19 +61,20 @@ class ApiMapper {
|
|
|
46
61
|
}
|
|
47
62
|
this.logger = config.logger;
|
|
48
63
|
|
|
49
|
-
//
|
|
50
|
-
this.operations = this.
|
|
64
|
+
// Parsed operation map: <operationId> → endpoint/HTTP details used at runtime.
|
|
65
|
+
this.operations = this._parseOperations(this.operationsSpec);
|
|
51
66
|
}
|
|
52
67
|
|
|
53
68
|
/**
|
|
54
|
-
* Load
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
57
|
-
* @
|
|
69
|
+
* Load (or reload) the operations specification.
|
|
70
|
+
*
|
|
71
|
+
* @method loadOperations
|
|
72
|
+
* @param {Object} spec - Operations specification (see constructor)
|
|
73
|
+
* @returns {Object} Parsed operation map
|
|
58
74
|
*/
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
this.operations = this.
|
|
75
|
+
loadOperations(spec) {
|
|
76
|
+
this.operationsSpec = spec;
|
|
77
|
+
this.operations = this._parseOperations(spec);
|
|
62
78
|
return this.operations;
|
|
63
79
|
}
|
|
64
80
|
|
|
@@ -201,7 +217,8 @@ class ApiMapper {
|
|
|
201
217
|
const getContentResolver = () => {
|
|
202
218
|
if (!contentResolver) {
|
|
203
219
|
contentResolver = new ContentAccessor({
|
|
204
|
-
context: { workflow_id: workflowId, step_id: stepId }
|
|
220
|
+
context: { workflow_id: workflowId, step_id: stepId },
|
|
221
|
+
logger: this.logger
|
|
205
222
|
});
|
|
206
223
|
}
|
|
207
224
|
return contentResolver;
|
|
@@ -462,7 +479,7 @@ class ApiMapper {
|
|
|
462
479
|
let resolver = null;
|
|
463
480
|
const getResolver = () => {
|
|
464
481
|
if (!resolver) {
|
|
465
|
-
resolver = new ContentAccessor();
|
|
482
|
+
resolver = new ContentAccessor({ logger: this.logger });
|
|
466
483
|
}
|
|
467
484
|
return resolver;
|
|
468
485
|
};
|
|
@@ -544,12 +561,14 @@ class ApiMapper {
|
|
|
544
561
|
}
|
|
545
562
|
|
|
546
563
|
/**
|
|
547
|
-
* Parse
|
|
564
|
+
* Parse operations specification (operations.json primary, OpenAPI fallback)
|
|
565
|
+
* into a runtime operation map keyed by operationId.
|
|
566
|
+
*
|
|
548
567
|
* @private
|
|
549
|
-
* @param {Object} spec -
|
|
568
|
+
* @param {Object} spec - operations.json payload or legacy OpenAPI spec
|
|
550
569
|
* @returns {Object} Operations map
|
|
551
570
|
*/
|
|
552
|
-
|
|
571
|
+
_parseOperations(spec) {
|
|
553
572
|
const operations = {};
|
|
554
573
|
|
|
555
574
|
if (!spec || typeof spec !== 'object') {
|
package/src/index.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @module @onlineapps/conn-orch-api-mapper
|
|
5
|
-
* @description API mapping connector that maps cookbook operations to HTTP endpoints
|
|
6
|
-
*
|
|
5
|
+
* @description API mapping connector that maps cookbook operations to HTTP endpoints
|
|
6
|
+
* using the operations.json contract (primary format).
|
|
7
7
|
*
|
|
8
|
-
* @see
|
|
8
|
+
* @see /api/docs/architecture/operations-registry-contract.md §3 (operations.json)
|
|
9
|
+
* @see /api/shared/connector/conn-orch-api-mapper/README.md
|
|
9
10
|
* @author OA Drive Team
|
|
10
11
|
* @license MIT
|
|
11
12
|
* @since 1.0.0
|
|
@@ -17,17 +18,19 @@ const ApiMapper = require('./ApiMapper');
|
|
|
17
18
|
* Create API mapper instance
|
|
18
19
|
* @function create
|
|
19
20
|
* @param {Object} config - Configuration options
|
|
20
|
-
* @param {Object
|
|
21
|
-
*
|
|
21
|
+
* @param {Object} config.operations - Operations specification (operations.json contract).
|
|
22
|
+
* Legacy OpenAPI `{ paths }` payload still accepted as a fallback.
|
|
23
|
+
* @param {string} config.serviceUrl - Base URL of the service (required)
|
|
22
24
|
* @param {Object} [config.service] - Express app instance for direct calls
|
|
23
25
|
* @param {boolean} [config.directCall=false] - Use direct Express calls instead of HTTP
|
|
24
|
-
* @param {Object}
|
|
26
|
+
* @param {Object} config.logger - Logger instance (required)
|
|
25
27
|
* @returns {ApiMapper} New API mapper instance
|
|
26
28
|
*
|
|
27
29
|
* @example
|
|
28
30
|
* const apiMapper = create({
|
|
29
|
-
*
|
|
30
|
-
* serviceUrl: 'http://127.0.0.1:3000'
|
|
31
|
+
* operations: require('./config/service/operations.json'),
|
|
32
|
+
* serviceUrl: 'http://127.0.0.1:3000',
|
|
33
|
+
* logger: myLogger
|
|
31
34
|
* });
|
|
32
35
|
*/
|
|
33
36
|
function create(config) {
|