@onlineapps/content-resolver 1.1.6 → 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 +6 -4
- package/src/config.js +35 -0
- package/src/defaults.js +15 -0
- package/src/index.js +11 -24
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/content-resolver",
|
|
3
|
-
"version": "1.1.
|
|
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": "
|
|
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
|
+
|
package/src/defaults.js
ADDED
|
@@ -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: '
|
|
89
|
+
return { bucket: runtimeCfg.get('defaultBucket'), path: internalMatch[1] };
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
return null;
|
|
@@ -106,7 +104,8 @@ class ContentResolver {
|
|
|
106
104
|
* @param {Object} [options.logger] - Logger instance
|
|
107
105
|
*/
|
|
108
106
|
constructor(options = {}) {
|
|
109
|
-
|
|
107
|
+
const resolved = runtimeCfg.resolve(options);
|
|
108
|
+
this.threshold = resolved.threshold;
|
|
110
109
|
this.logger = options.logger || console;
|
|
111
110
|
|
|
112
111
|
// Storage can be passed as instance or config (no fallbacks - fail-fast)
|
|
@@ -117,26 +116,14 @@ class ContentResolver {
|
|
|
117
116
|
this.storageConfig = options.storage;
|
|
118
117
|
this.storage = null;
|
|
119
118
|
} else {
|
|
120
|
-
// Must have env
|
|
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
|
-
}
|
|
119
|
+
// Must have runtime config (resolved from env) if no explicit storage config passed
|
|
133
120
|
this.storageConfig = {
|
|
134
|
-
endPoint:
|
|
135
|
-
port:
|
|
136
|
-
useSSL:
|
|
137
|
-
accessKey:
|
|
138
|
-
secretKey:
|
|
139
|
-
defaultBucket:
|
|
121
|
+
endPoint: resolved.endPoint,
|
|
122
|
+
port: resolved.port,
|
|
123
|
+
useSSL: resolved.useSSL,
|
|
124
|
+
accessKey: resolved.accessKey,
|
|
125
|
+
secretKey: resolved.secretKey,
|
|
126
|
+
defaultBucket: resolved.defaultBucket
|
|
140
127
|
};
|
|
141
128
|
this.storage = null;
|
|
142
129
|
}
|