@onlineapps/service-wrapper 2.0.0 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/service-wrapper",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Thin orchestration layer for microservices - delegates all infrastructure concerns to specialized connectors",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -28,7 +28,7 @@
28
28
  "@onlineapps/conn-infra-mq": "^1.1.0",
29
29
  "@onlineapps/conn-orch-registry": "^1.1.4",
30
30
  "@onlineapps/conn-orch-cookbook": "^2.0.0",
31
- "@onlineapps/conn-orch-orchestrator": "^1.0.0",
31
+ "@onlineapps/conn-orch-orchestrator": "^1.0.1",
32
32
  "@onlineapps/conn-orch-api-mapper": "^1.0.0",
33
33
  "@onlineapps/conn-base-cache": "^1.0.0",
34
34
  "@onlineapps/conn-infra-error-handler": "^1.0.0"
@@ -41,4 +41,4 @@
41
41
  "engines": {
42
42
  "node": ">=14.0.0"
43
43
  }
44
- }
44
+ }
@@ -44,15 +44,17 @@ class ServiceWrapper {
44
44
  * Create a new ServiceWrapper instance
45
45
  * @constructor
46
46
  * @param {Object} options - Configuration options
47
- * @param {Object} options.service - Express application instance
47
+ * @param {Object} [options.service] - Express application instance (for direct calls)
48
+ * @param {string} [options.serviceUrl] - HTTP URL of the service (for HTTP calls)
48
49
  * @param {string} options.serviceName - Name of the service
49
50
  * @param {Object} options.openApiSpec - OpenAPI specification
50
51
  * @param {Object} [options.config={}] - Infrastructure configuration
51
52
  * @param {string} [options.config.rabbitmq] - RabbitMQ connection URL
52
53
  * @param {string} [options.config.redis] - Redis connection string
53
54
  * @param {string} [options.config.registry] - Registry service URL
54
- * @param {number} [options.config.port=3000] - Service port
55
+ * @param {number} [options.config.port=3000] - Service port (deprecated, use serviceUrl)
55
56
  * @param {number} [options.config.prefetch=10] - MQ prefetch count
57
+ * @param {boolean} [options.config.directCall] - Use direct Express calls (default: auto-detect)
56
58
  *
57
59
  * @throws {Error} If required options are missing
58
60
  */
@@ -61,6 +63,7 @@ class ServiceWrapper {
61
63
 
62
64
  // Store configuration
63
65
  this.service = options.service;
66
+ this.serviceUrl = options.serviceUrl;
64
67
  this.serviceName = options.serviceName;
65
68
  this.openApiSpec = options.openApiSpec;
66
69
  this.config = options.config || {};
@@ -83,8 +86,8 @@ class ServiceWrapper {
83
86
  * @throws {Error} If required options are missing
84
87
  */
85
88
  _validateOptions(options) {
86
- if (!options.service) {
87
- throw new Error('Service (Express app) is required');
89
+ if (!options.service && !options.serviceUrl) {
90
+ throw new Error('Either service (Express app) or serviceUrl is required');
88
91
  }
89
92
  if (!options.serviceName) {
90
93
  throw new Error('Service name is required');
@@ -135,14 +138,21 @@ class ServiceWrapper {
135
138
  });
136
139
 
137
140
  // 4. Create the orchestrator with all dependencies
141
+ // Determine if we should use direct calls or HTTP
142
+ const useDirectCall = this.config.directCall !== undefined
143
+ ? this.config.directCall
144
+ : (this.service && !this.serviceUrl); // Auto-detect based on what was provided
145
+
146
+ const serviceUrl = this.serviceUrl || `http://localhost:${this.config.port || 3000}`;
147
+
138
148
  this.orchestrator = OrchestratorConnector.create({
139
149
  mqClient: this.mqClient,
140
150
  registryClient: this.registryClient,
141
151
  apiMapper: ApiMapperConnector.create({
142
152
  openApiSpec: this.openApiSpec,
143
- serviceUrl: `http://localhost:${this.config.port || 3000}`,
153
+ serviceUrl: serviceUrl,
144
154
  service: this.service,
145
- directCall: true,
155
+ directCall: useDirectCall,
146
156
  logger: this.logger
147
157
  }),
148
158
  cookbook: CookbookConnector,
@@ -248,9 +258,10 @@ class ServiceWrapper {
248
258
  * @returns {Promise<void>}
249
259
  */
250
260
  async _registerService() {
261
+ const serviceUrl = this.serviceUrl || `http://localhost:${this.config.port || 3000}`;
251
262
  const serviceInfo = {
252
263
  name: this.serviceName,
253
- url: `http://localhost:${this.config.port || 3000}`,
264
+ url: serviceUrl,
254
265
  openapi: this.openApiSpec,
255
266
  metadata: {
256
267
  version: this.openApiSpec.info?.version || '1.0.0',