@onlineapps/content-resolver 1.1.6 → 1.1.10

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.6",
3
+ "version": "1.1.10",
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,11 @@
11
11
 
12
12
  const StorageConnector = require('@onlineapps/conn-base-storage');
13
13
  const crypto = require('crypto');
14
+ const DEFAULTS = require('./defaults');
15
+ const runtimeCfg = require('./config');
14
16
 
15
- // Default threshold: 16KB (16384 bytes)
16
- const DEFAULT_THRESHOLD = 16 * 1024;
17
+ // Backward-compatible constant export (module-owned default, not ENV override)
18
+ const DEFAULT_THRESHOLD = DEFAULTS.threshold;
17
19
 
18
20
  // Reference patterns
19
21
  const MINIO_REF_PATTERN = /^minio:\/\/([^/]+)\/(.+)$/;
@@ -88,7 +90,7 @@ function parseReference(ref) {
88
90
  const internalMatch = ref.match(INTERNAL_REF_PATTERN);
89
91
  if (internalMatch) {
90
92
  // Internal references use default bucket
91
- return { bucket: 'workflow', path: internalMatch[1] };
93
+ return { bucket: runtimeCfg.get('defaultBucket'), path: internalMatch[1] };
92
94
  }
93
95
 
94
96
  return null;
@@ -106,7 +108,8 @@ class ContentResolver {
106
108
  * @param {Object} [options.logger] - Logger instance
107
109
  */
108
110
  constructor(options = {}) {
109
- this.threshold = options.threshold || DEFAULT_THRESHOLD;
111
+ const resolved = runtimeCfg.resolve(options);
112
+ this.threshold = resolved.threshold;
110
113
  this.logger = options.logger || console;
111
114
 
112
115
  // Storage can be passed as instance or config (no fallbacks - fail-fast)
@@ -117,26 +120,14 @@ class ContentResolver {
117
120
  this.storageConfig = options.storage;
118
121
  this.storage = null;
119
122
  } else {
120
- // Must have env variables if no config passed
121
- if (!process.env.MINIO_HOST) {
122
- throw new Error('[ContentResolver] Missing required: MINIO_HOST env or options.storage');
123
- }
124
- if (!process.env.MINIO_PORT) {
125
- throw new Error('[ContentResolver] Missing required: MINIO_PORT env or options.storage');
126
- }
127
- if (!process.env.MINIO_ACCESS_KEY) {
128
- throw new Error('[ContentResolver] Missing required: MINIO_ACCESS_KEY env or options.storage');
129
- }
130
- if (!process.env.MINIO_SECRET_KEY) {
131
- throw new Error('[ContentResolver] Missing required: MINIO_SECRET_KEY env or options.storage');
132
- }
123
+ // Must have runtime config (resolved from env) if no explicit storage config passed
133
124
  this.storageConfig = {
134
- endPoint: process.env.MINIO_HOST,
135
- port: parseInt(process.env.MINIO_PORT),
136
- useSSL: false,
137
- accessKey: process.env.MINIO_ACCESS_KEY,
138
- secretKey: process.env.MINIO_SECRET_KEY,
139
- defaultBucket: 'workflow'
125
+ endPoint: resolved.endPoint,
126
+ port: resolved.port,
127
+ useSSL: resolved.useSSL,
128
+ accessKey: resolved.accessKey,
129
+ secretKey: resolved.secretKey,
130
+ defaultBucket: resolved.defaultBucket
140
131
  };
141
132
  this.storage = null;
142
133
  }