@onlineapps/content-resolver 1.1.5 → 1.1.8

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,10 +1,10 @@
1
1
  {
2
2
  "name": "@onlineapps/content-resolver",
3
- "version": "1.1.5",
3
+ "version": "1.1.8",
4
4
  "description": "Automatic conversion between text content and storage references with Content Descriptor pattern",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
- "test": "jest"
7
+ "test": "jest --passWithNoTests"
8
8
  },
9
9
  "keywords": [
10
10
  "content",
@@ -16,9 +16,11 @@
16
16
  "author": "OnlineApps",
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
- "@onlineapps/conn-base-storage": "^1.0.0"
19
+ "@onlineapps/conn-base-storage": "1.0.4",
20
+ "@onlineapps/runtime-config": "1.0.2"
20
21
  },
21
22
  "peerDependencies": {
22
23
  "@onlineapps/conn-base-storage": "^1.0.0"
23
- }
24
+ },
25
+ "devDependencies": {}
24
26
  }
package/src/config.js ADDED
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Runtime configuration schema for @onlineapps/content-resolver.
5
+ *
6
+ * Uses @onlineapps/runtime-config for unified priority:
7
+ * 1. Explicit config (passed to constructor)
8
+ * 2. Environment variable
9
+ * 3. Module-owned defaults (from ./defaults.js)
10
+ *
11
+ * IMPORTANT: MinIO topology is FAIL-FAST (no defaults).
12
+ */
13
+
14
+ const { createRuntimeConfig } = require('@onlineapps/runtime-config');
15
+ const DEFAULTS = require('./defaults');
16
+
17
+ const runtimeCfg = createRuntimeConfig({
18
+ defaults: DEFAULTS,
19
+ schema: {
20
+ threshold: { env: 'CONTENT_RESOLVER_THRESHOLD', defaultKey: 'thresholdBytes', type: 'number' },
21
+
22
+ // MinIO topology (FAIL-FAST)
23
+ endPoint: { env: 'MINIO_ENDPOINT', required: true },
24
+ port: { env: 'MINIO_PORT', required: true, type: 'number' },
25
+ accessKey: { env: 'MINIO_ACCESS_KEY', required: true },
26
+ secretKey: { env: 'MINIO_SECRET_KEY', required: true },
27
+ useSSL: { env: 'MINIO_USE_SSL', defaultKey: 'useSSL', type: 'boolean' },
28
+
29
+ defaultBucket: { env: 'MINIO_DEFAULT_BUCKET', defaultKey: 'defaultBucket' },
30
+ }
31
+ });
32
+
33
+ module.exports = runtimeCfg;
34
+
35
+
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Module-owned defaults for @onlineapps/content-resolver.
5
+ *
6
+ * NOTE: Infrastructure topology (MinIO endpoint/credentials) has NO defaults.
7
+ */
8
+
9
+ module.exports = {
10
+ thresholdBytes: 16 * 1024,
11
+ defaultBucket: 'workflow',
12
+ useSSL: false,
13
+ };
14
+
15
+
package/src/index.js CHANGED
@@ -11,9 +11,7 @@
11
11
 
12
12
  const StorageConnector = require('@onlineapps/conn-base-storage');
13
13
  const crypto = require('crypto');
14
-
15
- // Default threshold: 16KB (16384 bytes)
16
- const DEFAULT_THRESHOLD = 16 * 1024;
14
+ const runtimeCfg = require('./config');
17
15
 
18
16
  // Reference patterns
19
17
  const MINIO_REF_PATTERN = /^minio:\/\/([^/]+)\/(.+)$/;
@@ -88,7 +86,7 @@ function parseReference(ref) {
88
86
  const internalMatch = ref.match(INTERNAL_REF_PATTERN);
89
87
  if (internalMatch) {
90
88
  // Internal references use default bucket
91
- return { bucket: 'workflow', path: internalMatch[1] };
89
+ return { bucket: runtimeCfg.get('defaultBucket'), path: internalMatch[1] };
92
90
  }
93
91
 
94
92
  return null;
@@ -106,20 +104,26 @@ class ContentResolver {
106
104
  * @param {Object} [options.logger] - Logger instance
107
105
  */
108
106
  constructor(options = {}) {
109
- this.threshold = options.threshold || DEFAULT_THRESHOLD;
107
+ const resolved = runtimeCfg.resolve(options);
108
+ this.threshold = resolved.threshold;
110
109
  this.logger = options.logger || console;
111
110
 
112
- // Storage can be passed as instance or config
111
+ // Storage can be passed as instance or config (no fallbacks - fail-fast)
113
112
  if (options.storage instanceof StorageConnector) {
114
113
  this.storage = options.storage;
114
+ } else if (options.storage) {
115
+ // Config passed explicitly
116
+ this.storageConfig = options.storage;
117
+ this.storage = null;
115
118
  } else {
116
- this.storageConfig = options.storage || {
117
- endPoint: process.env.MINIO_HOST || 'api_shared_storage',
118
- port: parseInt(process.env.MINIO_PORT || '9000'),
119
- useSSL: false,
120
- accessKey: process.env.MINIO_ACCESS_KEY || 'minioadmin',
121
- secretKey: process.env.MINIO_SECRET_KEY || 'minioadmin',
122
- defaultBucket: 'workflow'
119
+ // Must have runtime config (resolved from env) if no explicit storage config passed
120
+ this.storageConfig = {
121
+ endPoint: resolved.endPoint,
122
+ port: resolved.port,
123
+ useSSL: resolved.useSSL,
124
+ accessKey: resolved.accessKey,
125
+ secretKey: resolved.secretKey,
126
+ defaultBucket: resolved.defaultBucket
123
127
  };
124
128
  this.storage = null;
125
129
  }