Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@clipboard-health/config
Advanced tools
Type-safe static configuration management: a pure function to resolve, validate against a Zod schema, and freeze configuration values.
Type-safe static configuration management: a pure function to resolve, validate against a Zod schema, and freeze configuration values.
Configuration values resolve in order from highest precedence to lowest:
{ myApi: { port: 3000 } }
configuration resolves to MY_API_PORT
.Supported configuration value types:
To override arrays with environment variables, use stringified JSON arrays, e.g. ["a","b"]
.
IMPORTANT: To avoid runtime errors:
z.coerce
Zod types for those you plan to override.
Note that z.coerce.boolean()
coerces any truthy value to true
. To restrict to "true" | "false"
, use the booleanString
schema from @clipboard-health/contract-core
.ReadonlyDeep<SchemaT>
, but the library returns a
Readonly<SchemaT>
because the former prevents clients from passing configuration values to
functions that don't explicitly accept readonly
types.npm install @clipboard-health/config
import { ok } from "node:assert/strict";
import { createConfig } from "@clipboard-health/config";
import { z } from "zod";
const allowed = ["local", "development", "production"] as const;
type Allowed = (typeof allowed)[number];
function createEnvironmentConfig(current: Allowed) {
return createConfig({
config: {
baseUrl: {
defaultValue: "http://localhost:3000",
description: "Base URL for API requests",
overrides: {
development: "https://dev.example.com",
production: "https://api.example.com",
},
},
database: {
port: {
defaultValue: 5432,
description: "Database port",
},
},
},
environment: { allowed, current },
schema: z.object({
baseUrl: z.string().url(),
database: z.object({
// Use `z.coerce` to override with environment variables.
port: z.coerce.number().min(1024).max(65_535),
}),
}),
});
}
{
// Uses default values.
const config = createEnvironmentConfig("local");
ok(config.baseUrl === "http://localhost:3000");
ok(config.database.port === 5432);
}
{
// Uses baseUrl environment override.
const config = createEnvironmentConfig("development");
ok(config.baseUrl === "https://dev.example.com");
ok(config.database.port === 5432);
}
// Uses environment variable overrides.
const original = { ...process.env };
try {
process.env["BASE_URL"] = "https://staging.example.com";
process.env["DATABASE_PORT"] = "54320";
const config = createEnvironmentConfig("local");
ok(config.baseUrl === "https://staging.example.com");
ok(config.database.port === 54_320);
} finally {
process.env = { ...original };
}
See package.json
scripts
for a list of commands.
FAQs
Type-safe static configuration management: a pure function to resolve, validate against a Zod schema, and freeze configuration values.
The npm package @clipboard-health/config receives a total of 147 weekly downloads. As such, @clipboard-health/config popularity was classified as not popular.
We found that @clipboard-health/config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.