@drawbridge/drawbridge-utils 0.0.51 → 0.0.53
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/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- 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/dist/index.cjs
CHANGED
|
@@ -263,12 +263,12 @@ var formatCurrency = ({
|
|
|
263
263
|
const resolvedLocale = locale || (typeof navigator !== "undefined" ? navigator == null ? void 0 : navigator.language : null) || "en-US";
|
|
264
264
|
const options = {
|
|
265
265
|
currency: code2,
|
|
266
|
+
currencyDisplay: "narrowSymbol",
|
|
266
267
|
minimumFractionDigits: digits,
|
|
267
268
|
maximumFractionDigits: digits,
|
|
268
269
|
style: "currency"
|
|
269
270
|
};
|
|
270
271
|
if (display === "parts") {
|
|
271
|
-
options.currencyDisplay = "narrowSymbol";
|
|
272
272
|
const parts = new Intl.NumberFormat(resolvedLocale, options).formatToParts(value);
|
|
273
273
|
const symbol = ((_a = parts.find((p) => p.type === "currency")) == null ? void 0 : _a.value) || "";
|
|
274
274
|
const number = parts.filter((p) => p.type !== "currency" && p.type !== "literal").map((p) => p.value).join("");
|
package/dist/index.d.cts
CHANGED
|
@@ -241,6 +241,7 @@ const formatCurrency = ({
|
|
|
241
241
|
|
|
242
242
|
const options = {
|
|
243
243
|
currency : code,
|
|
244
|
+
currencyDisplay : 'narrowSymbol',
|
|
244
245
|
minimumFractionDigits : digits,
|
|
245
246
|
maximumFractionDigits : digits,
|
|
246
247
|
style : 'currency'
|
|
@@ -248,8 +249,6 @@ const formatCurrency = ({
|
|
|
248
249
|
|
|
249
250
|
if( display === 'parts' ){
|
|
250
251
|
|
|
251
|
-
options.currencyDisplay = 'narrowSymbol';
|
|
252
|
-
|
|
253
252
|
const parts = new Intl.NumberFormat( resolvedLocale, options ).formatToParts( value );
|
|
254
253
|
|
|
255
254
|
const symbol = parts.find( ( p ) => p.type === 'currency' )?.value || '';
|
package/dist/index.d.ts
CHANGED
|
@@ -241,6 +241,7 @@ const formatCurrency = ({
|
|
|
241
241
|
|
|
242
242
|
const options = {
|
|
243
243
|
currency : code,
|
|
244
|
+
currencyDisplay : 'narrowSymbol',
|
|
244
245
|
minimumFractionDigits : digits,
|
|
245
246
|
maximumFractionDigits : digits,
|
|
246
247
|
style : 'currency'
|
|
@@ -248,8 +249,6 @@ const formatCurrency = ({
|
|
|
248
249
|
|
|
249
250
|
if( display === 'parts' ){
|
|
250
251
|
|
|
251
|
-
options.currencyDisplay = 'narrowSymbol';
|
|
252
|
-
|
|
253
252
|
const parts = new Intl.NumberFormat( resolvedLocale, options ).formatToParts( value );
|
|
254
253
|
|
|
255
254
|
const symbol = parts.find( ( p ) => p.type === 'currency' )?.value || '';
|
package/dist/index.js
CHANGED
|
@@ -219,12 +219,12 @@ var formatCurrency = ({
|
|
|
219
219
|
const resolvedLocale = locale || (typeof navigator !== "undefined" ? navigator == null ? void 0 : navigator.language : null) || "en-US";
|
|
220
220
|
const options = {
|
|
221
221
|
currency: code2,
|
|
222
|
+
currencyDisplay: "narrowSymbol",
|
|
222
223
|
minimumFractionDigits: digits,
|
|
223
224
|
maximumFractionDigits: digits,
|
|
224
225
|
style: "currency"
|
|
225
226
|
};
|
|
226
227
|
if (display === "parts") {
|
|
227
|
-
options.currencyDisplay = "narrowSymbol";
|
|
228
228
|
const parts = new Intl.NumberFormat(resolvedLocale, options).formatToParts(value);
|
|
229
229
|
const symbol = ((_a = parts.find((p) => p.type === "currency")) == null ? void 0 : _a.value) || "";
|
|
230
230
|
const number = parts.filter((p) => p.type !== "currency" && p.type !== "literal").map((p) => p.value).join("");
|
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.53"
|
|
134
139
|
}
|