Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

envsafe

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

envsafe - npm Package Compare versions

Comparing version 1.2.0-0 to 1.2.0-1

51

dist/envsafe.cjs.development.js

@@ -229,6 +229,11 @@ 'use strict';

validator = _ref.validator,
key = _ref.key;
key = _ref.key,
validateKey = _ref.validateKey;
var usingDevDefault = env.NODE_ENV !== 'production';
var raw = (_validator$input = validator.input) !== null && _validator$input !== void 0 ? _validator$input : env[key];
if (validateKey && !validateKey(key)) {
throw new InvalidEnvError("Invalid environment key \"" + key + "\"");
}
if (raw === undefined && usingDevDefault && validator.devDefault !== undefined) {

@@ -262,3 +267,4 @@ raw = validator.devDefault;

_ref2$strict = _ref2.strict,
strict = _ref2$strict === void 0 ? false : _ref2$strict;
strict = _ref2$strict === void 0 ? false : _ref2$strict,
validateKey = _ref2.validateKey;

@@ -275,3 +281,4 @@ var errors = {};

validator: validator,
key: key
key: key,
validateKey: validateKey
});

@@ -379,30 +386,19 @@ output[key] = resolved;

function nextjsWebpackPlugin(_ref) {
var browserEnv = _ref.browserEnv,
webpack = _ref.webpack;
var env = {};
for (var key in browserEnv) {
if (key.startsWith('NEXT_PUBLIC_')) {
env[key] = browserEnv[key];
}
function nextjsWebpackPlugin(validators, webpack, env) {
if (env === void 0) {
env = process.env;
}
return new webpack.DefinePlugin({
'process.browserEnv': JSON.stringify(env)
var cleanEnv = envsafe(validators, {
validateKey: function validateKey(key) {
if (!key.startsWith('NEXT_PUBLIC_')) {
throw new InvalidEnvError("Not prefixed with \"NEXT_PUBLIC_\"");
}
return true;
},
env: env
});
}
function craWebpackPlugin(_ref2) {
var browserEnv = _ref2.browserEnv,
webpack = _ref2.webpack;
var env = {};
for (var key in browserEnv) {
if (key.startsWith('REACT_APP_')) {
env[key] = browserEnv[key];
}
}
return new webpack.DefinePlugin({
'process.browserEnv': JSON.stringify(env)
'process.envsafe': JSON.stringify(cleanEnv)
});

@@ -414,3 +410,2 @@ }

exports.bool = bool;
exports.craWebpackPlugin = craWebpackPlugin;
exports.defaultReporter = defaultReporter;

@@ -417,0 +412,0 @@ exports.defaultReporterText = defaultReporterText;

@@ -1,2 +0,2 @@

"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function i(e,t,r){return(i=o()?Reflect.construct:function(e,t,r){var o=[null];o.push.apply(o,t);var i=new(Function.bind.apply(e,o));return r&&n(i,r.prototype),i}).apply(null,arguments)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return i(e,arguments,r(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,e)})(e)}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}Object.defineProperty(exports,"__esModule",{value:!0});var c=function(e){function r(t){var n;return n=e.call(this,t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(u(TypeError)),a=function(e,t){return new c("Invalid "+e+' input: "'+t+'"')},f=function(e){function r(t){var n;return n=e.call(this,t)||this,Object.setPrototypeOf(s(n),r.prototype),n}return t(r,e),r}(u(ReferenceError)),p=["length","inspect","hasOwnProperty","toJSON","asymmetricMatch","nodeType","$$typeof","constructor","@@__IMMUTABLE_ITERABLE__@@","@@__IMMUTABLE_RECORD__@@","_isMockFunction","then","__esModule"];function l(e,t){var r=Object.freeze?Object.freeze(e):e;return global.Proxy?new Proxy(r,{get:function(e,n){if("string"!=typeof n||p.includes(n))return r[n];if(!r.hasOwnProperty(n)){if(t.hasOwnProperty(n))throw new ReferenceError("[envsafe] Env var "+String(n)+" was accessed but not validated. This var is set in the environment; please add an envsafe validator for it.");throw new ReferenceError('[envsafe] Env var "'+String(n)+'" not found')}return r[n]}}):r}function v(e){for(var t=e.errors,r=[],n=[],o=0,i=Object.keys(t);o<i.length;o++){var u=i[o],s=t[u];s instanceof f?n.push(" "+u+": "+(s.message||"required")):r.push(" "+u+": "+(s.message||"invalid"))}return r.length&&r.unshift("❌ Invalid environment variables:"),n.length&&n.unshift("💨 Missing environment variables:"),["========================================"].concat(r,n,["========================================"]).join("\n")}function d(e){var t,r=v(e);throw console.error(r),"undefined"!=typeof window&&(null===(t=window)||void 0===t?void 0:t.alert)&&window.alert(r),new TypeError(r)}function h(e){var t,r=e.env,n=e.validator,o=null!==(t=n.input)&&void 0!==t?t:r[e.key];if(void 0===o&&"production"!==r.NODE_ENV&&void 0!==n.devDefault&&(o=n.devDefault),void 0===o&&void 0!==n.default&&(o=n.default),void 0===o)throw new f("Missing value");var i=n._parse(o);if(n.choices&&!n.choices.includes(i))throw new c('Value "'+i+'" not in choices ['+n.choices+"]");return i}var y=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function w(t){return function(r){return void 0===r&&(r={}),e({},r,{_parse:t})}}var b=w((function(e){switch(e){case!0:case"true":case"t":case"1":return!0;case!1:case"false":case"f":case"0":return!1;default:throw a("str",e)}})),_=w((function(e){if("string"!=typeof e)throw a("str",e);return e})),O=w((function(e){if(!y.test(e))throw a("email",e);return e})),g=w((function(e){var t=+e;if(Number.isNaN(t))throw a("num",e);return t})),E=w((function(e){var t=+e;if(Number.isNaN(t)||""+t!=""+e||t%1!=0||t<1||t>65535)throw a("port",e);return t})),x=w((function(e){try{return new URL(e),e}catch(t){throw a("url",e)}})),P=w((function(e){try{return"string"!=typeof e?e:JSON.parse(e)}catch(t){throw a("json",e)}}));exports.InvalidEnvError=c,exports.MissingEnvError=f,exports.bool=b,exports.craWebpackPlugin=function(e){var t=e.browserEnv,r=e.webpack,n={};for(var o in t)o.startsWith("REACT_APP_")&&(n[o]=t[o]);return new r.DefinePlugin({"process.browserEnv":JSON.stringify(n)})},exports.defaultReporter=d,exports.defaultReporterText=v,exports.email=O,exports.envsafe=function(e,t){var r=void 0===t?{}:t,n=r.reporter,o=void 0===n?d:n,i=r.env,u=void 0===i?process.env:i,s=r.strict,c=void 0!==s&&s,a={},f={};for(var p in e){var v=e[p];try{var y=h({env:u,validator:v,key:p});f[p]=y}catch(e){a[p]=e}}return Object.keys(a).length&&o({errors:a,output:f,env:u}),c?l(f,u):f},exports.freezeObject=l,exports.invalidEnvError=a,exports.json=P,exports.makeValidator=w,exports.nextjsWebpackPlugin=function(e){var t=e.browserEnv,r=e.webpack,n={};for(var o in t)o.startsWith("NEXT_PUBLIC_")&&(n[o]=t[o]);return new r.DefinePlugin({"process.browserEnv":JSON.stringify(n)})},exports.num=g,exports.port=E,exports.str=_,exports.url=x;
"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function i(e,t,r){return(i=o()?Reflect.construct:function(e,t,r){var o=[null];o.push.apply(o,t);var i=new(Function.bind.apply(e,o));return r&&n(i,r.prototype),i}).apply(null,arguments)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return i(e,arguments,r(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,e)})(e)}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}Object.defineProperty(exports,"__esModule",{value:!0});var c=function(e){function r(t){var n;return n=e.call(this,t)||this,Object.setPrototypeOf(a(n),r.prototype),n}return t(r,e),r}(u(TypeError)),s=function(e,t){return new c("Invalid "+e+' input: "'+t+'"')},f=function(e){function r(t){var n;return n=e.call(this,t)||this,Object.setPrototypeOf(a(n),r.prototype),n}return t(r,e),r}(u(ReferenceError)),p=["length","inspect","hasOwnProperty","toJSON","asymmetricMatch","nodeType","$$typeof","constructor","@@__IMMUTABLE_ITERABLE__@@","@@__IMMUTABLE_RECORD__@@","_isMockFunction","then","__esModule"];function l(e,t){var r=Object.freeze?Object.freeze(e):e;return global.Proxy?new Proxy(r,{get:function(e,n){if("string"!=typeof n||p.includes(n))return r[n];if(!r.hasOwnProperty(n)){if(t.hasOwnProperty(n))throw new ReferenceError("[envsafe] Env var "+String(n)+" was accessed but not validated. This var is set in the environment; please add an envsafe validator for it.");throw new ReferenceError('[envsafe] Env var "'+String(n)+'" not found')}return r[n]}}):r}function v(e){for(var t=e.errors,r=[],n=[],o=0,i=Object.keys(t);o<i.length;o++){var u=i[o],a=t[u];a instanceof f?n.push(" "+u+": "+(a.message||"required")):r.push(" "+u+": "+(a.message||"invalid"))}return r.length&&r.unshift("❌ Invalid environment variables:"),n.length&&n.unshift("💨 Missing environment variables:"),["========================================"].concat(r,n,["========================================"]).join("\n")}function d(e){var t,r=v(e);throw console.error(r),"undefined"!=typeof window&&(null===(t=window)||void 0===t?void 0:t.alert)&&window.alert(r),new TypeError(r)}function h(e){var t,r=e.env,n=e.validator,o=e.key,i=e.validateKey,u="production"!==r.NODE_ENV,a=null!==(t=n.input)&&void 0!==t?t:r[o];if(i&&!i(o))throw new c('Invalid environment key "'+o+'"');if(void 0===a&&u&&void 0!==n.devDefault&&(a=n.devDefault),void 0===a&&void 0!==n.default&&(a=n.default),void 0===a)throw new f("Missing value");var s=n._parse(a);if(n.choices&&!n.choices.includes(s))throw new c('Value "'+s+'" not in choices ['+n.choices+"]");return s}function y(e,t){var r=void 0===t?{}:t,n=r.reporter,o=void 0===n?d:n,i=r.env,u=void 0===i?process.env:i,a=r.strict,c=void 0!==a&&a,s=r.validateKey,f={},p={};for(var v in e){var y=e[v];try{var w=h({env:u,validator:y,key:v,validateKey:s});p[v]=w}catch(e){f[v]=e}}return Object.keys(f).length&&o({errors:f,output:p,env:u}),c?l(p,u):p}var w=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function _(t){return function(r){return void 0===r&&(r={}),e({},r,{_parse:t})}}var O=_((function(e){switch(e){case!0:case"true":case"t":case"1":return!0;case!1:case"false":case"f":case"0":return!1;default:throw s("str",e)}})),b=_((function(e){if("string"!=typeof e)throw s("str",e);return e})),g=_((function(e){if(!w.test(e))throw s("email",e);return e})),x=_((function(e){var t=+e;if(Number.isNaN(t))throw s("num",e);return t})),E=_((function(e){var t=+e;if(Number.isNaN(t)||""+t!=""+e||t%1!=0||t<1||t>65535)throw s("port",e);return t})),j=_((function(e){try{return new URL(e),e}catch(t){throw s("url",e)}})),m=_((function(e){try{return"string"!=typeof e?e:JSON.parse(e)}catch(t){throw s("json",e)}}));exports.InvalidEnvError=c,exports.MissingEnvError=f,exports.bool=O,exports.defaultReporter=d,exports.defaultReporterText=v,exports.email=g,exports.envsafe=y,exports.freezeObject=l,exports.invalidEnvError=s,exports.json=m,exports.makeValidator=_,exports.nextjsWebpackPlugin=function(e,t,r){void 0===r&&(r=process.env);var n=y(e,{validateKey:function(e){if(!e.startsWith("NEXT_PUBLIC_"))throw new c('Not prefixed with "NEXT_PUBLIC_"');return!0},env:r});return new t.DefinePlugin({"process.envsafe":JSON.stringify(n)})},exports.num=x,exports.port=E,exports.str=b,exports.url=j;
//# sourceMappingURL=envsafe.cjs.production.min.js.map
import { EnvsafeOpts, Validators } from './types';
export declare function envsafe<TCleanEnv>(validators: Validators<TCleanEnv>, { reporter, env, strict, }?: EnvsafeOpts<TCleanEnv>): Readonly<TCleanEnv>;
export declare function envsafe<TCleanEnv>(validators: Validators<TCleanEnv>, { reporter, env, strict, validateKey, }?: EnvsafeOpts<TCleanEnv>): Readonly<TCleanEnv>;

@@ -225,6 +225,11 @@ function _extends() {

validator = _ref.validator,
key = _ref.key;
key = _ref.key,
validateKey = _ref.validateKey;
var usingDevDefault = env.NODE_ENV !== 'production';
var raw = (_validator$input = validator.input) !== null && _validator$input !== void 0 ? _validator$input : env[key];
if (validateKey && !validateKey(key)) {
throw new InvalidEnvError("Invalid environment key \"" + key + "\"");
}
if (raw === undefined && usingDevDefault && validator.devDefault !== undefined) {

@@ -258,3 +263,4 @@ raw = validator.devDefault;

_ref2$strict = _ref2.strict,
strict = _ref2$strict === void 0 ? false : _ref2$strict;
strict = _ref2$strict === void 0 ? false : _ref2$strict,
validateKey = _ref2.validateKey;

@@ -271,3 +277,4 @@ var errors = {};

validator: validator,
key: key
key: key,
validateKey: validateKey
});

@@ -375,34 +382,23 @@ output[key] = resolved;

function nextjsWebpackPlugin(_ref) {
var browserEnv = _ref.browserEnv,
webpack = _ref.webpack;
var env = {};
for (var key in browserEnv) {
if (key.startsWith('NEXT_PUBLIC_')) {
env[key] = browserEnv[key];
}
function nextjsWebpackPlugin(validators, webpack, env) {
if (env === void 0) {
env = process.env;
}
return new webpack.DefinePlugin({
'process.browserEnv': JSON.stringify(env)
var cleanEnv = envsafe(validators, {
validateKey: function validateKey(key) {
if (!key.startsWith('NEXT_PUBLIC_')) {
throw new InvalidEnvError("Not prefixed with \"NEXT_PUBLIC_\"");
}
return true;
},
env: env
});
}
function craWebpackPlugin(_ref2) {
var browserEnv = _ref2.browserEnv,
webpack = _ref2.webpack;
var env = {};
for (var key in browserEnv) {
if (key.startsWith('REACT_APP_')) {
env[key] = browserEnv[key];
}
}
return new webpack.DefinePlugin({
'process.browserEnv': JSON.stringify(env)
'process.envsafe': JSON.stringify(cleanEnv)
});
}
export { InvalidEnvError, MissingEnvError, bool, craWebpackPlugin, defaultReporter, defaultReporterText, email, envsafe, freezeObject, invalidEnvError, json, makeValidator, nextjsWebpackPlugin, num, port, str, url };
export { InvalidEnvError, MissingEnvError, bool, defaultReporter, defaultReporterText, email, envsafe, freezeObject, invalidEnvError, json, makeValidator, nextjsWebpackPlugin, num, port, str, url };
//# sourceMappingURL=envsafe.esm.js.map

@@ -0,13 +1,6 @@

/// <reference types="node" />
import { DefinePlugin } from 'webpack';
export declare function nextjsWebpackPlugin<TCleanEnv extends Readonly<Record<string, any>>>({ browserEnv, webpack, }: {
browserEnv: TCleanEnv;
webpack: {
DefinePlugin: typeof DefinePlugin;
};
}): DefinePlugin;
export declare function craWebpackPlugin<TCleanEnv extends Readonly<Record<string, any>>>({ browserEnv, webpack, }: {
browserEnv: TCleanEnv;
webpack: {
DefinePlugin: typeof DefinePlugin;
};
}): DefinePlugin;
import { Validators } from '../types';
export declare function nextjsWebpackPlugin<TCleanEnv>(validators: Validators<TCleanEnv>, webpack: {
DefinePlugin: typeof DefinePlugin;
}, env?: NodeJS.ProcessEnv): DefinePlugin;

@@ -44,2 +44,3 @@ export interface Spec<TValue> {

export declare type ReporterFn<TCleanEnv> = (opts: ReporterOpts<TCleanEnv>) => void;
export declare type KeyValidator = (key: string) => boolean;
export declare type EnvsafeOpts<TCleanEnv> = {

@@ -61,2 +62,6 @@ /**

strict?: boolean;
/**
* Used in webpack plugins to validate that the key is in an allowlist of keys
*/
validateKey?: (key: string) => true;
};

@@ -63,0 +68,0 @@ export declare type Validators<TCleanEnv> = {

{
"version": "1.2.0-0",
"version": "1.2.0-1",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -10,2 +10,3 @@ import { InvalidEnvError, MissingEnvError } from './errors';

Validators,
KeyValidator,
} from './types';

@@ -17,2 +18,3 @@

key,
validateKey,
}: {

@@ -22,2 +24,3 @@ env: Environment;

key: string;
validateKey?: KeyValidator;
}): TValue {

@@ -28,2 +31,6 @@ const usingDevDefault = env.NODE_ENV !== 'production';

if (validateKey && !validateKey(key)) {
throw new InvalidEnvError(`Invalid environment key "${key}"`);
}
if (

@@ -60,2 +67,3 @@ raw === undefined &&

strict = false,
validateKey,
}: EnvsafeOpts<TCleanEnv> = {},

@@ -69,3 +77,3 @@ ): Readonly<TCleanEnv> {

try {
const resolved = getValueOrThrow({ env, validator, key });
const resolved = getValueOrThrow({ env, validator, key, validateKey });
output[key] = resolved;

@@ -72,0 +80,0 @@ } catch (err) {

import { DefinePlugin } from 'webpack';
import { envsafe } from '../envsafe';
import { InvalidEnvError } from '../errors';
import { Validators } from '../types';
export function nextjsWebpackPlugin<
TCleanEnv extends Readonly<Record<string, any>>
>({
browserEnv,
webpack,
}: {
browserEnv: TCleanEnv;
export function nextjsWebpackPlugin<TCleanEnv>(
validators: Validators<TCleanEnv>,
webpack: {
DefinePlugin: typeof DefinePlugin;
};
}) {
const env = {} as TCleanEnv;
for (const key in browserEnv) {
if (key.startsWith('NEXT_PUBLIC_')) {
env[key] = browserEnv[key];
}
}
return new webpack.DefinePlugin({
'process.browserEnv': JSON.stringify(env),
},
env = process.env,
) {
const cleanEnv = envsafe(validators, {
validateKey(key) {
if (!key.startsWith('NEXT_PUBLIC_')) {
throw new InvalidEnvError(`Not prefixed with "NEXT_PUBLIC_"`);
}
return true;
},
env,
});
}
export function craWebpackPlugin<
TCleanEnv extends Readonly<Record<string, any>>
>({
browserEnv,
webpack,
}: {
browserEnv: TCleanEnv;
webpack: {
DefinePlugin: typeof DefinePlugin;
};
}) {
const env = {} as TCleanEnv;
for (const key in browserEnv) {
if (key.startsWith('REACT_APP_')) {
env[key] = browserEnv[key];
}
}
return new webpack.DefinePlugin({
'process.browserEnv': JSON.stringify(env),
'process.envsafe': JSON.stringify(cleanEnv),
});
}

@@ -49,3 +49,3 @@ export interface Spec<TValue> {

export type ReporterFn<TCleanEnv> = (opts: ReporterOpts<TCleanEnv>) => void;
export type KeyValidator = (key: string) => boolean;
export type EnvsafeOpts<TCleanEnv> = {

@@ -67,2 +67,6 @@ /**

strict?: boolean;
/**
* Used in webpack plugins to validate that the key is in an allowlist of keys
*/
validateKey?: (key: string) => true;
};

@@ -69,0 +73,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc