@onlineapps/conn-orch-api-mapper 1.0.33 → 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 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="#loadOpenApiSpec">loadOpenApiSpec(spec)</a> ⇒ <code>Object</code></dt>
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.openApiSpec | <code>Object</code> \| <code>string</code> | | OpenAPI specification object or path |
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
- openApiSpec: require('./openapi.json'),
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.openApiSpec | <code>Object</code> \| <code>string</code> | | OpenAPI specification object or path |
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
- openApiSpec: require('./openapi.json'),
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.openApiSpec | <code>Object</code> \| <code>string</code> | | OpenAPI specification object or path |
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
- openApiSpec: require('./openapi.json'),
151
+ operations: require('./openapi.json'),
152
152
  serviceUrl: 'http://hello-service:3000'
153
153
  });
154
154
  ```
155
- <a name="loadOpenApiSpec"></a>
155
+ <a name="loadOperations"></a>
156
156
 
157
- ## loadOpenApiSpec(spec) ⇒ <code>Object</code>
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 OpenAPI
234
+ // Generate request from operations spec
235
235
  const request = await mapper.fromOpenAPI({
236
- spec: openApiSpec,
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.33",
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.15"
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 OpenAPI specification.
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|string} config.openApiSpec - OpenAPI specification object or path
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} [config.logger] - Logger instance
32
+ * @param {Object} config.logger - Logger instance (required; must expose `warn`)
24
33
  *
25
34
  * @example
26
35
  * const apiMapper = new ApiMapper({
27
- * openApiSpec: require('./openapi.json'),
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.openApiSpec) {
33
- throw new Error('OpenAPI specification is required');
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
- this.openApiSpec = config.openApiSpec;
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
- // Parse OpenAPI to create operation map
50
- this.operations = this._parseOpenApiSpec(this.openApiSpec);
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 OpenAPI specification
55
- * @method loadOpenApiSpec
56
- * @param {Object|string} spec - OpenAPI specification or path
57
- * @returns {Object} Parsed operations map
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
- loadOpenApiSpec(spec) {
60
- this.openApiSpec = spec;
61
- this.operations = this._parseOpenApiSpec(spec);
75
+ loadOperations(spec) {
76
+ this.operationsSpec = spec;
77
+ this.operations = this._parseOperations(spec);
62
78
  return this.operations;
63
79
  }
64
80
 
@@ -545,12 +561,14 @@ class ApiMapper {
545
561
  }
546
562
 
547
563
  /**
548
- * Parse OpenAPI specification or operations.json to extract operations
564
+ * Parse operations specification (operations.json primary, OpenAPI fallback)
565
+ * into a runtime operation map keyed by operationId.
566
+ *
549
567
  * @private
550
- * @param {Object} spec - OpenAPI specification or operations.json format
568
+ * @param {Object} spec - operations.json payload or legacy OpenAPI spec
551
569
  * @returns {Object} Operations map
552
570
  */
553
- _parseOpenApiSpec(spec) {
571
+ _parseOperations(spec) {
554
572
  const operations = {};
555
573
 
556
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
- * Handles OpenAPI parsing, request transformation, and response mapping.
5
+ * @description API mapping connector that maps cookbook operations to HTTP endpoints
6
+ * using the operations.json contract (primary format).
7
7
  *
8
- * @see {@link https://github.com/onlineapps/oa-drive/tree/main/shared/connector/conn-orch-api-mapper|GitHub Repository}
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|string} config.openApiSpec - OpenAPI specification object or path
21
- * @param {string} config.serviceUrl - Base URL of the service
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} [config.logger] - Logger instance
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
- * openApiSpec: require('./openapi.json'),
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) {