Socket
Socket
Sign inDemoInstall

@availity/env-var

Package Overview
Dependencies
0
Maintainers
17
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-alpha.23 to 2.0.0

.eslintrc.yml

215

CHANGELOG.md

@@ -1,8 +0,33 @@

# Change Log
# Changelog
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
## [1.9.2](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.1...@availity/env-var@1.9.2) (2019-10-29)
# [2.0.0](https://github.com/Availity/sdk-js/compare/@availity/env-var@1.11.3...@availity/env-var@2.0.0) (2022-04-28)
* feat(env-var)!: update types ([d747314](https://github.com/Availity/sdk-js/commit/d747314b481c41a1c5da11613df9d0ad9ae6988d))
* build!: switch from lerna to nx and compile to esm with tsup ([c586085](https://github.com/Availity/sdk-js/commit/c5860856ca96b743a0653d335ea00f0889132f7f))
### BREAKING CHANGES
* Drop IE support
* Drop Internet Explorer support
## [1.11.4-alpha.0](https://github.com/Availity/sdk-js/compare/@availity/env-var@1.11.3...@availity/env-var@1.11.4-alpha.0) (2022-04-18)
* build!: switch from lerna to nx and compile to esm with tsup ([c586085](https://github.com/Availity/sdk-js/commit/c5860856ca96b743a0653d335ea00f0889132f7f))
### BREAKING CHANGES
* Drop Internet Explorer support
## 1.11.3 (2021-12-21)
**Note:** Version bump only for package @availity/env-var

@@ -14,3 +39,3 @@

## [1.9.1](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.0...@availity/env-var@1.9.1) (2019-04-17)
## 1.11.2 (2021-10-22)

@@ -23,8 +48,16 @@ **Note:** Version bump only for package @availity/env-var

# [1.9.0](https://github.com/availity/sdk-js/compare/@availity/env-var@1.7.1...@availity/env-var@1.9.0) (2019-03-18)
## 1.11.1 (2021-05-17)
**Note:** Version bump only for package @availity/env-var
# 1.11.0 (2020-06-03)
### Features
* **env-var:** added extra param for setting default env var ([2f97472](https://github.com/availity/sdk-js/commit/2f97472))
* **env-var:** add sandbox support to cloud environment ([8ada30c](https://github.com/availity/sdk-js/commit/8ada30cabe64eb95cc37f3b3e0d68444585c0373))

@@ -35,3 +68,3 @@

# [1.8.0](https://github.com/availity/sdk-js/compare/@availity/env-var@1.7.1...@availity/env-var@1.8.0) (2019-03-04)
# 1.10.0 (2020-05-20)

@@ -41,3 +74,3 @@

* **env-var:** added extra param for setting default env var ([2f97472](https://github.com/availity/sdk-js/commit/2f97472))
* **env-var:** add env support for cloud urls ([2534563](https://github.com/availity/sdk-js/commit/2534563e7ced303d6095101733e5d64a22210ef6))

@@ -48,3 +81,3 @@

## [1.7.1](https://github.com/availity/sdk-js/compare/@availity/env-var@1.7.0...@availity/env-var@1.7.1) (2019-02-12)
## 1.9.20 (2020-05-01)

@@ -57,20 +90,172 @@ **Note:** Version bump only for package @availity/env-var

# 1.7.0 (2019-02-12)
## 1.9.19 (2020-04-30)
**Note:** Version bump only for package @availity/env-var
## 1.6.2 (2018-04-24)
## 1.9.18 (2020-04-22)
**Note:** Version bump only for package @availity/env-var
## 1.9.17 (2020-04-08)
**Note:** Version bump only for package @availity/env-var
## 1.9.16 (2020-04-06)
**Note:** Version bump only for package @availity/env-var
## 1.9.15 (2020-04-06)
**Note:** Version bump only for package @availity/env-var
## [1.9.14](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.11...@availity/env-var@1.9.14) (2020-02-13)
**Note:** Version bump only for package @availity/env-var
## [1.9.13](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.12...@availity/env-var@1.9.13) (2020-02-13)
**Note:** Version bump only for package @availity/env-var
## [1.9.12](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.10...@availity/env-var@1.9.12) (2020-02-13)
**Note:** Version bump only for package @availity/env-var
## [1.9.11](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.9...@availity/env-var@1.9.11) (2020-02-13)
### Bug Fixes
* **env-var:** default value not environment ([076540b](https://github.com/availity/sdk-js/commit/076540b))
* update babel and jest configs, rename tests ([c80e194](https://github.com/availity/sdk-js/commit/c80e1947f0c3cb28c3c7db842c82f381622d72e7))
# 1.6.0 (2018-04-20)
## [1.9.10](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.9...@availity/env-var@1.9.10) (2020-02-13)
### Bug Fixes
* update babel and jest configs, rename tests ([c80e194](https://github.com/availity/sdk-js/commit/c80e1947f0c3cb28c3c7db842c82f381622d72e7))
## [1.9.9](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.6...@availity/env-var@1.9.9) (2020-02-13)
**Note:** Version bump only for package @availity/env-var
## [1.9.8](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.7...@availity/env-var@1.9.8) (2020-02-13)
**Note:** Version bump only for package @availity/env-var
## [1.9.7](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.6...@availity/env-var@1.9.7) (2020-02-13)
**Note:** Version bump only for package @availity/env-var
## [1.9.6](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.5...@availity/env-var@1.9.6) (2020-02-09)
**Note:** Version bump only for package @availity/env-var
## [1.9.5](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.4...@availity/env-var@1.9.5) (2020-01-23)
**Note:** Version bump only for package @availity/env-var
## [1.9.4](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.3...@availity/env-var@1.9.4) (2020-01-03)
**Note:** Version bump only for package @availity/env-var
## [1.9.3](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.2...@availity/env-var@1.9.3) (2020-01-03)
**Note:** Version bump only for package @availity/env-var
## [1.9.2](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.1...@availity/env-var@1.9.2) (2019-10-29)
**Note:** Version bump only for package @availity/env-var
## [1.9.1](https://github.com/availity/sdk-js/compare/@availity/env-var@1.9.0...@availity/env-var@1.9.1) (2019-04-17)
**Note:** Version bump only for package @availity/env-var
# [1.9.0](https://github.com/availity/sdk-js/compare/@availity/env-var@1.7.1...@availity/env-var@1.9.0) (2019-03-18)
### Features
* **env-var:** add env-vars package ([a5a2409](https://github.com/availity/sdk-js/commit/a5a2409))
- **env-var:** added extra param for setting default env var ([2f97472](https://github.com/availity/sdk-js/commit/2f97472))
# [1.8.0](https://github.com/availity/sdk-js/compare/@availity/env-var@1.7.1...@availity/env-var@1.8.0) (2019-03-04)
### Features
- **env-var:** added extra param for setting default env var ([2f97472](https://github.com/availity/sdk-js/commit/2f97472))
## [1.7.1](https://github.com/availity/sdk-js/compare/@availity/env-var@1.7.0...@availity/env-var@1.7.1) (2019-02-12)
**Note:** Version bump only for package @availity/env-var
# 1.7.0 (2019-02-12)
## 1.6.2 (2018-04-24)
### Bug Fixes
- **env-var:** default value not environment ([076540b](https://github.com/availity/sdk-js/commit/076540b))
# 1.6.0 (2018-04-20)
### Features
- **env-var:** add env-vars package ([a5a2409](https://github.com/availity/sdk-js/commit/a5a2409))

@@ -0,8 +1,141 @@

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./env-var.cjs.production.min.js')
} else {
module.exports = require('./env-var.cjs.development.js')
// src/index.js
var src_exports = {};
__export(src_exports, {
default: () => src_default,
getCurrentEnv: () => getCurrentEnv,
getLocation: () => getLocation,
getSpecificEnv: () => getSpecificEnv,
setEnvironments: () => setEnvironments,
setSpecificEnvironments: () => setSpecificEnvironments
});
module.exports = __toCommonJS(src_exports);
var getCloudEnv = (options) => {
const { subdomain, pathname } = options;
if (!(subdomain && pathname))
return null;
const subMatch = subdomain.match(/.*?\.(?:aw|az|gc)([nps])$/);
if (!subMatch)
return null;
const pathMatch = pathname.match(/^\/[a-z]{3}\/([\da-z]{3})\/.*/);
if (!pathMatch)
return null;
const isProdPath = pathMatch[1] === "prd";
switch (subMatch[1]) {
case "p":
return isProdPath ? pathMatch[1] : null;
case "n":
case "s":
return isProdPath ? null : pathMatch[1];
default:
return null;
}
};
var environments = {
local: ["127.0.0.1", "localhost"],
test: [/^t(?:(?:\d\d)|(?:est))-apps$/, (options) => /^t(?:(?:\d\d)|(?:st))$/.test(getCloudEnv(options))],
qa: [/^q(?:(?:\d\d)|(?:ap?))-apps$/, (options) => /^(stg|q(?:(?:\d\d)|(?:ua)|(?:ap)))$/.test(getCloudEnv(options))],
prod: [/^apps$/, (options) => getCloudEnv(options) === "prd"]
};
var specificEnvironments = [
{
regex: /^(?:(.*)-)?apps$/,
fn: (options) => options.match[1] || "prod"
},
{
regex: /.*?\.(?:aw|az|gc)([nps])$/,
fn: getCloudEnv
}
];
function setEnvironments(envs, override) {
if (override) {
environments = envs;
} else {
Object.assign(environments, envs);
}
}
function setSpecificEnvironments(envs, override) {
if (override) {
specificEnvironments = envs;
} else {
Object.assign(specificEnvironments, envs);
}
}
function getLocation(href) {
const anchor = document.createElement("a");
anchor.href = href;
return anchor;
}
function getLocationComponents(windowOverride) {
const { hostname, pathname } = windowOverride === null || typeof windowOverride === "string" ? getLocation(windowOverride) : windowOverride.location;
const subdomain = hostname.split(".availity")[0];
return {
subdomain,
pathname
};
}
function getCurrentEnv(windowOverride = window) {
const { subdomain, pathname } = getLocationComponents(windowOverride);
return Object.keys(environments).reduce((prev, env) => {
if (prev)
return prev;
let envTests = environments[env];
if (!Array.isArray(envTests)) {
envTests = [envTests];
}
return envTests.some((testObj) => {
switch (Object.prototype.toString.call(testObj)) {
case "[object String]":
return testObj === subdomain;
case "[object RegExp]":
return testObj.test(subdomain);
case "[object Function]":
return testObj({ subdomain, pathname });
default:
return false;
}
}) && env;
}, "");
}
function getSpecificEnv(windowOverride = window) {
const { subdomain, pathname } = getLocationComponents(windowOverride);
return specificEnvironments.reduce((prev, env) => {
if (prev)
return prev;
const { regex, fn } = env;
const match = subdomain.match(regex);
return match ? fn({ match, subdomain, pathname }) : null;
}, null) || "local";
}
function src_default(varObj, windowOverride, defaultVar) {
const env = getCurrentEnv(windowOverride);
if (typeof varObj[env] !== "undefined") {
return varObj[env];
}
return defaultVar || varObj.local;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getCurrentEnv,
getLocation,
getSpecificEnv,
setEnvironments,
setSpecificEnvironments
});

43

package.json
{
"name": "@availity/env-var",
"version": "2.0.0-alpha.23+8e4e32a",
"version": "2.0.0",
"description": "Availity-specific way to determine variables based on the current environment the code is running in",
"main": "lib/index.js",
"module": "src/index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/availity/sdk-js.git"
},
"keywords": [

@@ -17,14 +10,34 @@ "availity",

],
"homepage": "https://availity.github.io/sdk-js/resources/env-var",
"bugs": {
"url": "https://github.com/availity/sdk-js/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/availity/sdk-js.git",
"directory": "packages/env-var"
},
"license": "MIT",
"contributors": [
"Evan Sharp <evan.sharp@availity.com> (https://github.com/TheSharpieOne)"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/availity/sdk-js/issues"
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsup src/index.js --format esm,cjs --dts",
"dev": "tsup src/index.js --format esm,cjs --watch --dts",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"clean": "rm -rf node_modules && rm -rf dist",
"bundlesize": "bundlesize",
"publish": "yarn npm publish --tolerate-republish --access public"
},
"homepage": "https://github.com/availity/sdk-js",
"devDependencies": {
"tsup": "^5.10.1",
"typescript": "^4.5.3"
},
"publishConfig": {
"access": "public"
},
"gitHead": "8e4e32a30771beef013cc5d28e2994b1a209fac0"
}
}
}

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

# env-var
# @availity/env-var

@@ -6,9 +6,21 @@ > Get run-time environment variables for immutable builds

[![Version](https://img.shields.io/npm/v/@availity/env-var.svg?style=for-the-badge)](https://www.npmjs.com/package/@availity/env-var)
[![NPM Downloads](https://img.shields.io/npm/dt/@availity/env-var.svg?style=for-the-badge)](https://www.npmjs.com/package/@availity/env-var)
[![Dependecy Status](https://img.shields.io/librariesio/release/npm/@availity/env-var?style=for-the-badge)](https://github.com/Availity/sdk-js/blob/master/packages/env-var/package.json)
## Install
### NPM
```bash
npm install @availity/env-var --save
npm install @availity/env-var
```
## [Documentation](https://availity.github.io/sdk-js/features/env-var)
### Yarn
```bash
yarn add @availity/env-var
```
## Documentation
Check out more documentation at [availity.github.io](https://availity.github.io/sdk-js/resources/env-var)

@@ -0,7 +1,48 @@

// Cloud domains are in the format <team>.<cloud provider><zone>.availity.com
// where <cloud provider> is a two character abbreviation for the cloud provider
// and zone is a one character abbreviation for prod, non-prod,or sandbox.
// Cloud URIs are in the format /<namespace>/<environment>/...
// where <namespace> is a three character abbreviation, e.g., cdn or api
// and <environment> is a three character abbreviation, e.g., prd or t01
const getCloudEnv = (options) => {
const { subdomain, pathname } = options;
if (!(subdomain && pathname)) return null;
const subMatch = subdomain.match(/.*?\.(?:aw|az|gc)([nps])$/);
if (!subMatch) return null;
const pathMatch = pathname.match(/^\/[a-z]{3}\/([\da-z]{3})\/.*/);
if (!pathMatch) return null;
// ??p domains must be prod, ??n and ??s domains can't be prod
const isProdPath = pathMatch[1] === 'prd';
switch (subMatch[1]) {
case 'p':
return isProdPath ? pathMatch[1] : null;
case 'n':
case 's':
return isProdPath ? null : pathMatch[1];
default:
return null;
}
};
let environments = {
local: ['127.0.0.1', 'localhost'],
test: [/^t(?:(?:\d\d)|(?:est))-apps$/],
qa: [/^q(?:(?:\d\d)|(?:ap?))-apps$/],
prod: [/^apps$/],
test: [/^t(?:(?:\d\d)|(?:est))-apps$/, (options) => /^t(?:(?:\d\d)|(?:st))$/.test(getCloudEnv(options))],
qa: [/^q(?:(?:\d\d)|(?:ap?))-apps$/, (options) => /^(stg|q(?:(?:\d\d)|(?:ua)|(?:ap)))$/.test(getCloudEnv(options))],
prod: [/^apps$/, (options) => getCloudEnv(options) === 'prd'],
};
let specificEnvironments = [
{
regex: /^(?:(.*)-)?apps$/,
fn: (options) => options.match[1] || 'prod',
},
{
regex: /.*?\.(?:aw|az|gc)([nps])$/,
fn: getCloudEnv,
},
];
export function setEnvironments(envs, override) {

@@ -14,2 +55,11 @@ if (override) {

}
export function setSpecificEnvironments(envs, override) {
if (override) {
specificEnvironments = envs;
} else {
Object.assign(specificEnvironments, envs);
}
}
export function getLocation(href) {

@@ -21,4 +71,4 @@ const anchor = document.createElement('a');

export function getCurrentEnv(windowOverride = window) {
const { hostname } =
function getLocationComponents(windowOverride) {
const { hostname, pathname } =
windowOverride === null || typeof windowOverride === 'string'

@@ -28,3 +78,11 @@ ? getLocation(windowOverride)

const subdomain = hostname.split('.availity')[0];
return {
subdomain,
pathname,
};
}
export function getCurrentEnv(windowOverride = window) {
const { subdomain, pathname } = getLocationComponents(windowOverride);
return Object.keys(environments).reduce((prev, env) => {

@@ -38,11 +96,10 @@ if (prev) return prev;

return (
envTests.some(test => {
switch (Object.prototype.toString.call(test)) {
envTests.some((testObj) => {
switch (Object.prototype.toString.call(testObj)) {
case '[object String]':
return test === subdomain;
return testObj === subdomain;
case '[object RegExp]':
return test.test(subdomain);
return testObj.test(subdomain);
case '[object Function]':
// eslint-disable-next-line jest/no-disabled-tests
return test();
return testObj({ subdomain, pathname });
default:

@@ -56,3 +113,18 @@ return false;

export default function(varObj, windowOverride, defaultVar) {
// Returns the specific environment, e.g. t01, not test
export function getSpecificEnv(windowOverride = window) {
const { subdomain, pathname } = getLocationComponents(windowOverride);
return (
specificEnvironments.reduce((prev, env) => {
if (prev) return prev;
const { regex, fn } = env;
const match = subdomain.match(regex);
return match ? fn({ match, subdomain, pathname }) : null;
}, null) || 'local'
);
}
// eslint-disable-next-line func-names
export default function (varObj, windowOverride, defaultVar) {
const env = getCurrentEnv(windowOverride);

@@ -59,0 +131,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc