@drawbridge/drawbridge-utils 0.0.51 → 0.0.52
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/dist/env.cjs +41 -0
- package/dist/env.d.cts +41 -0
- package/dist/env.d.ts +41 -0
- package/dist/env.js +17 -0
- package/package.json +6 -1
package/dist/env.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// lib/env.js
|
|
20
|
+
var env_exports = {};
|
|
21
|
+
__export(env_exports, {
|
|
22
|
+
assertEnv: () => assertEnv
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(env_exports);
|
|
25
|
+
var assertEnv = (required = [], { env = process.env, exit = true } = {}) => {
|
|
26
|
+
const missing = (required || []).filter((key) => {
|
|
27
|
+
const value = env[key];
|
|
28
|
+
return value === void 0 || value === null || String(value).trim() === "";
|
|
29
|
+
});
|
|
30
|
+
if (missing.length === 0) return;
|
|
31
|
+
const message = "Missing required environment variable" + (missing.length > 1 ? "s" : "") + ": " + missing.join(", ");
|
|
32
|
+
console.error("[boot] " + message);
|
|
33
|
+
if (exit) {
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
throw new Error(message);
|
|
37
|
+
};
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
assertEnv
|
|
41
|
+
});
|
package/dist/env.d.cts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Boot-time required-environment-variable validation. A service calls
|
|
2
|
+
// assertEnv(required) as the first thing in index.js so a missing must-have
|
|
3
|
+
// config fails loudly at startup instead of silently degrading at first use
|
|
4
|
+
// (e.g. a missing OAUTH_TOKEN_HMAC_KEY surfacing only as failed socket auth).
|
|
5
|
+
//
|
|
6
|
+
// const { assertEnv } = require( '@drawbridge/drawbridge-utils/env' );
|
|
7
|
+
// assertEnv([ 'MONGODB_URI', 'REDIS_URL', 'OAUTH_TOKEN_HMAC_KEY' ]);
|
|
8
|
+
//
|
|
9
|
+
// Reports EVERY missing var in one message (not just the first) and exits the
|
|
10
|
+
// process with code 1. A var counts as missing when unset, null, or an
|
|
11
|
+
// empty/whitespace-only string. Pass { exit : false } to throw instead of
|
|
12
|
+
// exiting (used in tests); pass { env } to validate against a supplied map.
|
|
13
|
+
const assertEnv = ( required = [], { env = process.env, exit = true } = {} ) => {
|
|
14
|
+
|
|
15
|
+
const missing = ( required || [] ).filter( ( key ) => {
|
|
16
|
+
|
|
17
|
+
const value = env[ key ];
|
|
18
|
+
|
|
19
|
+
return value === undefined || value === null || String( value ).trim() === '';
|
|
20
|
+
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if( missing.length === 0 ) return;
|
|
24
|
+
|
|
25
|
+
const message = 'Missing required environment variable'
|
|
26
|
+
+ ( missing.length > 1 ? 's' : '' )
|
|
27
|
+
+ ': ' + missing.join( ', ' );
|
|
28
|
+
|
|
29
|
+
console.error( '[boot] ' + message );
|
|
30
|
+
|
|
31
|
+
if( exit ){
|
|
32
|
+
|
|
33
|
+
process.exit( 1 );
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
throw new Error( message );
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { assertEnv };
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Boot-time required-environment-variable validation. A service calls
|
|
2
|
+
// assertEnv(required) as the first thing in index.js so a missing must-have
|
|
3
|
+
// config fails loudly at startup instead of silently degrading at first use
|
|
4
|
+
// (e.g. a missing OAUTH_TOKEN_HMAC_KEY surfacing only as failed socket auth).
|
|
5
|
+
//
|
|
6
|
+
// const { assertEnv } = require( '@drawbridge/drawbridge-utils/env' );
|
|
7
|
+
// assertEnv([ 'MONGODB_URI', 'REDIS_URL', 'OAUTH_TOKEN_HMAC_KEY' ]);
|
|
8
|
+
//
|
|
9
|
+
// Reports EVERY missing var in one message (not just the first) and exits the
|
|
10
|
+
// process with code 1. A var counts as missing when unset, null, or an
|
|
11
|
+
// empty/whitespace-only string. Pass { exit : false } to throw instead of
|
|
12
|
+
// exiting (used in tests); pass { env } to validate against a supplied map.
|
|
13
|
+
const assertEnv = ( required = [], { env = process.env, exit = true } = {} ) => {
|
|
14
|
+
|
|
15
|
+
const missing = ( required || [] ).filter( ( key ) => {
|
|
16
|
+
|
|
17
|
+
const value = env[ key ];
|
|
18
|
+
|
|
19
|
+
return value === undefined || value === null || String( value ).trim() === '';
|
|
20
|
+
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if( missing.length === 0 ) return;
|
|
24
|
+
|
|
25
|
+
const message = 'Missing required environment variable'
|
|
26
|
+
+ ( missing.length > 1 ? 's' : '' )
|
|
27
|
+
+ ': ' + missing.join( ', ' );
|
|
28
|
+
|
|
29
|
+
console.error( '[boot] ' + message );
|
|
30
|
+
|
|
31
|
+
if( exit ){
|
|
32
|
+
|
|
33
|
+
process.exit( 1 );
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
throw new Error( message );
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { assertEnv };
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// lib/env.js
|
|
2
|
+
var assertEnv = (required = [], { env = process.env, exit = true } = {}) => {
|
|
3
|
+
const missing = (required || []).filter((key) => {
|
|
4
|
+
const value = env[key];
|
|
5
|
+
return value === void 0 || value === null || String(value).trim() === "";
|
|
6
|
+
});
|
|
7
|
+
if (missing.length === 0) return;
|
|
8
|
+
const message = "Missing required environment variable" + (missing.length > 1 ? "s" : "") + ": " + missing.join(", ");
|
|
9
|
+
console.error("[boot] " + message);
|
|
10
|
+
if (exit) {
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
throw new Error(message);
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
assertEnv
|
|
17
|
+
};
|
package/package.json
CHANGED
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
"import": "./dist/encrypt.js",
|
|
40
40
|
"require": "./dist/encrypt.cjs"
|
|
41
41
|
},
|
|
42
|
+
"./env": {
|
|
43
|
+
"types": "./dist/env.d.ts",
|
|
44
|
+
"import": "./dist/env.js",
|
|
45
|
+
"require": "./dist/env.cjs"
|
|
46
|
+
},
|
|
42
47
|
"./axios": {
|
|
43
48
|
"types": "./dist/axios.d.ts",
|
|
44
49
|
"import": "./dist/axios.js",
|
|
@@ -130,5 +135,5 @@
|
|
|
130
135
|
"build": "tsup && npm publish"
|
|
131
136
|
},
|
|
132
137
|
"types": "dist/index.d.ts",
|
|
133
|
-
"version": "0.0.
|
|
138
|
+
"version": "0.0.52"
|
|
134
139
|
}
|