🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@arcjet/env

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcjet/env - npm Package Compare versions

Comparing version
1.7.0
to
1.8.0-rc.0
+85
dist/index.d.ts
//#region src/index.d.ts
/**
* Environment.
*/
type Env = {
[key: string]: unknown;
/**
* Base URL of Arcjet API.
*/
ARCJET_BASE_URL?: string | undefined;
/**
* Environment of Arcjet SDK.
*/
ARCJET_ENV?: string | undefined;
/**
* Log level of Arcjet SDK.
*/
ARCJET_LOG_LEVEL?: string | undefined;
/**
* Firebase configuration variable.
*/
FIREBASE_CONFIG?: string | undefined;
/**
* Name of Fly.io app.
*/
FLY_APP_NAME?: string | undefined;
/**
* Vite mode.
*/
MODE?: string | undefined;
/**
* Environment of Node.js.
*/
NODE_ENV?: string | undefined;
/**
* Render environment variable.
*/
RENDER?: string | undefined;
/**
* Vercel environment variable.
*/
VERCEL?: string | undefined;
};
/**
* Platform name.
*/
type Platform = "firebase" | "fly-io" | "render" | "vercel";
/**
* Detect the platform.
*
* @param environment
* Environment.
* @returns
* Name of platform if found.
*/
declare function platform(environment: Env): Platform | undefined;
/**
* Check if the environment is development.
*
* @param environment
* Environment.
* @returns
* Whether the environment is development.
*/
declare function isDevelopment(environment: Env): boolean;
/**
* Get the log level.
*
* @param environment
* Environment.
* @returns
* Log level.
*/
declare function logLevel(environment: Env): "debug" | "info" | "warn" | "error";
/**
* Get the base URL of an Arcjet API.
*
* @param environment
* Environment.
* @returns
* Base URL of Arcjet API.
*/
declare function baseUrl(environment: Env): string;
//#endregion
export { Env, Platform, baseUrl, isDevelopment, logLevel, platform };
//#region src/index.ts
/**
* Detect the platform.
*
* @param environment
* Environment.
* @returns
* Name of platform if found.
*/
function platform(environment) {
if (typeof environment["FIREBASE_CONFIG"] === "string" && environment["FIREBASE_CONFIG"] !== "") return "firebase";
if (typeof environment["FLY_APP_NAME"] === "string" && environment["FLY_APP_NAME"] !== "") return "fly-io";
if (typeof environment["VERCEL"] === "string" && environment["VERCEL"] === "1") return "vercel";
if (typeof environment["RENDER"] === "string" && environment["RENDER"] === "true") return "render";
}
/**
* Check if the environment is development.
*
* @param environment
* Environment.
* @returns
* Whether the environment is development.
*/
function isDevelopment(environment) {
return environment.NODE_ENV === "development" || environment.MODE === "development" || environment.ARCJET_ENV === "development";
}
/**
* Get the log level.
*
* @param environment
* Environment.
* @returns
* Log level.
*/
function logLevel(environment) {
const level = environment["ARCJET_LOG_LEVEL"];
switch (level) {
case "debug":
case "info":
case "warn":
case "error": return level;
default: return "warn";
}
}
const baseUrlAllowed = [
"https://decide.arcjet.com",
"https://decide.arcjettest.com",
"https://fly.decide.arcjet.com",
"https://fly.decide.arcjettest.com",
"https://decide.arcjet.com/",
"https://decide.arcjettest.com/",
"https://fly.decide.arcjet.com/",
"https://fly.decide.arcjettest.com/"
];
/**
* Get the base URL of an Arcjet API.
*
* @param environment
* Environment.
* @returns
* Base URL of Arcjet API.
*/
function baseUrl(environment) {
if (typeof environment["ARCJET_BASE_URL"] === "string") {
if (baseUrlAllowed.includes(environment["ARCJET_BASE_URL"])) return environment["ARCJET_BASE_URL"];
try {
if (new URL(environment["ARCJET_BASE_URL"]).hostname.endsWith(".orb.local")) return environment["ARCJET_BASE_URL"];
} catch {}
}
if (platform(environment) === "fly-io") return "https://fly.decide.arcjet.com";
return "https://decide.arcjet.com";
}
//#endregion
export { baseUrl, isDevelopment, logLevel, platform };
+32
-29
{
"name": "@arcjet/env",
"version": "1.7.0",
"version": "1.8.0-rc.0",
"description": "Arcjet environment detection",

@@ -8,12 +8,6 @@ "keywords": [

"environment",
"utility",
"util"
"util",
"utility"
],
"license": "Apache-2.0",
"homepage": "https://arcjet.com",
"repository": {
"type": "git",
"url": "git+https://github.com/arcjet/arcjet-js.git",
"directory": "env"
},
"bugs": {

@@ -23,2 +17,3 @@ "url": "https://github.com/arcjet/arcjet-js/issues",

},
"license": "Apache-2.0",
"author": {

@@ -29,31 +24,39 @@ "name": "Arcjet",

},
"engines": {
"node": ">=22.21.0 <23 || >=24.5.0"
"repository": {
"type": "git",
"url": "git+https://github.com/arcjet/arcjet-js.git",
"directory": "env"
},
"type": "module",
"main": "./index.js",
"types": "./index.d.ts",
"files": [
"index.d.ts",
"index.js"
"dist"
],
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"publishConfig": {
"access": "public",
"tag": "latest"
},
"scripts": {
"build": "rollup --config rollup.config.js",
"lint": "eslint .",
"test-api": "node --test -- test/*.test.js",
"test-coverage": "node --experimental-test-coverage --test -- test/*.test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
"build": "tsdown",
"typecheck": "tsgo --noEmit",
"test-api": "node --test -- test/*.test.ts",
"test-coverage": "node --experimental-test-coverage --test -- test/*.test.ts",
"test": "npm run build && npm run test-coverage"
},
"dependencies": {},
"devDependencies": {
"@arcjet/eslint-config": "1.7.0",
"@arcjet/rollup-config": "1.7.0",
"@rollup/wasm-node": "4.62.2",
"eslint": "9.39.4",
"typescript": "5.9.3"
"tsdown": "0.22.3",
"typescript": "6.0.3"
},
"publishConfig": {
"access": "public",
"tag": "latest"
"engines": {
"node": ">=22.21.0 <23 || >=24.5.0"
}
}
/**
* Environment.
*/
export type Env = {
[key: string]: unknown;
/**
* Base URL of Arcjet API.
*/
ARCJET_BASE_URL?: string | undefined;
/**
* Environment of Arcjet SDK.
*/
ARCJET_ENV?: string | undefined;
/**
* Log level of Arcjet SDK.
*/
ARCJET_LOG_LEVEL?: string | undefined;
/**
* Firebase configuration variable.
*/
FIREBASE_CONFIG?: string | undefined;
/**
* Name of Fly.io app.
*/
FLY_APP_NAME?: string | undefined;
/**
* Vite mode.
*/
MODE?: string | undefined;
/**
* Environment of Node.js.
*/
NODE_ENV?: string | undefined;
/**
* Render environment variable.
*/
RENDER?: string | undefined;
/**
* Vercel environment variable.
*/
VERCEL?: string | undefined;
};
/**
* Platform name.
*/
export type Platform = "firebase" | "fly-io" | "render" | "vercel";
/**
* Detect the platform.
*
* @param environment
* Environment.
* @returns
* Name of platform if found.
*/
export declare function platform(environment: Env): Platform | undefined;
/**
* Check if the environment is development.
*
* @param environment
* Environment.
* @returns
* Whether the environment is development.
*/
export declare function isDevelopment(environment: Env): boolean;
/**
* Get the log level.
*
* @param environment
* Environment.
* @returns
* Log level.
*/
export declare function logLevel(environment: Env): "debug" | "info" | "warn" | "error";
/**
* Get the base URL of an Arcjet API.
*
* @param environment
* Environment.
* @returns
* Base URL of Arcjet API.
*/
export declare function baseUrl(environment: Env): string;
/**
* Detect the platform.
*
* @param environment
* Environment.
* @returns
* Name of platform if found.
*/
function platform(environment) {
if (typeof environment["FIREBASE_CONFIG"] === "string" &&
environment["FIREBASE_CONFIG"] !== "") {
return "firebase";
}
if (typeof environment["FLY_APP_NAME"] === "string" &&
environment["FLY_APP_NAME"] !== "") {
return "fly-io";
}
if (typeof environment["VERCEL"] === "string" &&
environment["VERCEL"] === "1") {
return "vercel";
}
// https://render.com/docs/environment-variables
if (typeof environment["RENDER"] === "string" &&
environment["RENDER"] === "true") {
return "render";
}
}
/**
* Check if the environment is development.
*
* @param environment
* Environment.
* @returns
* Whether the environment is development.
*/
function isDevelopment(environment) {
return (environment.NODE_ENV === "development" ||
environment.MODE === "development" ||
environment.ARCJET_ENV === "development");
}
/**
* Get the log level.
*
* @param environment
* Environment.
* @returns
* Log level.
*/
function logLevel(environment) {
const level = environment["ARCJET_LOG_LEVEL"];
switch (level) {
case "debug":
case "info":
case "warn":
case "error":
return level;
default:
// Default to warn if not set
return "warn";
}
}
const baseUrlAllowed = [
"https://decide.arcjet.com",
"https://decide.arcjettest.com",
"https://fly.decide.arcjet.com",
"https://fly.decide.arcjettest.com",
// Allow trailing slashes
"https://decide.arcjet.com/",
"https://decide.arcjettest.com/",
"https://fly.decide.arcjet.com/",
"https://fly.decide.arcjettest.com/",
];
/**
* Get the base URL of an Arcjet API.
*
* @param environment
* Environment.
* @returns
* Base URL of Arcjet API.
*/
function baseUrl(environment) {
// Use ARCJET_BASE_URL if it is set and belongs to our allowlist or has a
// hostname ending in .orb.local; otherwise use the hardcoded default.
if (typeof environment["ARCJET_BASE_URL"] === "string") {
if (baseUrlAllowed.includes(environment["ARCJET_BASE_URL"])) {
return environment["ARCJET_BASE_URL"];
}
try {
const hostname = new URL(environment["ARCJET_BASE_URL"]).hostname;
if (hostname.endsWith(".orb.local")) {
return environment["ARCJET_BASE_URL"];
}
}
catch {
// Invalid URL, fall through to default.
}
}
// If we're running on fly.io, use the Arcjet Decide Service hosted on fly
// Ref: https://fly.io/docs/machines/runtime-environment/#environment-variables
if (platform(environment) === "fly-io") {
return "https://fly.decide.arcjet.com";
}
return "https://decide.arcjet.com";
}
export { baseUrl, isDevelopment, logLevel, platform };