Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@smithy/node-config-provider

Package Overview
Dependencies
Maintainers
3
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/node-config-provider - npm Package Compare versions

Comparing version
4.3.14
to
4.4.0
+5
-62
dist-cjs/index.js

@@ -1,62 +0,5 @@

'use strict';
var propertyProvider = require('@smithy/property-provider');
var sharedIniFileLoader = require('@smithy/shared-ini-file-loader');
function getSelectorName(functionString) {
try {
const constants = new Set(Array.from(functionString.match(/([A-Z_]){3,}/g) ?? []));
constants.delete("CONFIG");
constants.delete("CONFIG_PREFIX_SEPARATOR");
constants.delete("ENV");
return [...constants].join(", ");
}
catch (e) {
return functionString;
}
}
const fromEnv = (envVarSelector, options) => async () => {
try {
const config = envVarSelector(process.env, options);
if (config === undefined) {
throw new Error();
}
return config;
}
catch (e) {
throw new propertyProvider.CredentialsProviderError(e.message || `Not found in ENV: ${getSelectorName(envVarSelector.toString())}`, { logger: options?.logger });
}
};
const fromSharedConfigFiles = (configSelector, { preferredFile = "config", ...init } = {}) => async () => {
const profile = sharedIniFileLoader.getProfileName(init);
const { configFile, credentialsFile } = await sharedIniFileLoader.loadSharedConfigFiles(init);
const profileFromCredentials = credentialsFile[profile] || {};
const profileFromConfig = configFile[profile] || {};
const mergedProfile = preferredFile === "config"
? { ...profileFromCredentials, ...profileFromConfig }
: { ...profileFromConfig, ...profileFromCredentials };
try {
const cfgFile = preferredFile === "config" ? configFile : credentialsFile;
const configValue = configSelector(mergedProfile, cfgFile);
if (configValue === undefined) {
throw new Error();
}
return configValue;
}
catch (e) {
throw new propertyProvider.CredentialsProviderError(e.message || `Not found in config files w/ profile [${profile}]: ${getSelectorName(configSelector.toString())}`, { logger: init.logger });
}
};
const isFunction = (func) => typeof func === "function";
const fromStatic = (defaultValue) => isFunction(defaultValue) ? async () => await defaultValue() : propertyProvider.fromStatic(defaultValue);
const loadConfig = ({ environmentVariableSelector, configFileSelector, default: defaultValue }, configuration = {}) => {
const { signingName, logger } = configuration;
const envOptions = { signingName, logger };
return propertyProvider.memoize(propertyProvider.chain(fromEnv(environmentVariableSelector, envOptions), fromSharedConfigFiles(configFileSelector, configuration), fromStatic(defaultValue)));
};
exports.loadConfig = loadConfig;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadConfig = void 0;
var config_1 = require("@smithy/core/config");
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_1.loadConfig; } });
+1
-1

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

export * from "./configLoader";
export { loadConfig, } from "@smithy/core/config";

@@ -1,4 +0,3 @@

export * from "./configLoader";
export { EnvOptions, GetterFromEnv } from "./fromEnv";
export { GetterFromConfig, SharedConfigInit } from "./fromSharedConfigFiles";
export { FromStaticConfig } from "./fromStatic";
/** @deprecated Use @smithy/core/config instead. */
export { loadConfig, type LocalConfigOptions, type LoadedConfigSelectors, type NodeSharedConfigInit as SharedConfigInit, } from "@smithy/core/config";
export type { EnvOptions, GetterFromEnv } from "@smithy/core/config";
{
"name": "@smithy/node-config-provider",
"version": "4.3.14",
"version": "4.4.0",
"description": "Load config default values from ini config files and environmental variable",
"scripts": {
"build": "concurrently 'yarn:build:types' 'yarn:build:es:cjs'",
"build:es:cjs": "yarn g:tsc -p tsconfig.es.json && node ../../scripts/inline node-config-provider",
"build:types": "yarn g:tsc -p tsconfig.types.json",
"build:types:downlevel": "premove dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
"clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
"format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"stage-release": "premove .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
"test": "yarn g:vitest run",
"test:watch": "yarn g:vitest watch"
"build": "yarn g:tsc -p tsconfig.cjs.json && yarn g:tsc -p tsconfig.es.json && yarn g:tsc -p tsconfig.types.json",
"clean": "rm -rf dist-cjs dist-es dist-types",
"stage-release": "rm -rf .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz"
},

@@ -28,24 +21,8 @@ "author": {

"dependencies": {
"@smithy/property-provider": "^4.2.14",
"@smithy/shared-ini-file-loader": "^4.4.9",
"@smithy/types": "^4.14.1",
"@smithy/core": "^3.24.0",
"tslib": "^2.6.2"
},
"devDependencies": {
"@types/node": "^18.11.9",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
"premove": "4.0.0",
"typedoc": "0.23.23"
},
"engines": {
"node": ">=18.0.0"
},
"typesVersions": {
"<4.5": {
"dist-types/*": [
"dist-types/ts3.4/*"
]
}
},
"files": [

@@ -52,0 +29,0 @@ "dist-*/**"

import { chain, memoize } from "@smithy/property-provider";
import { fromEnv } from "./fromEnv";
import { fromSharedConfigFiles } from "./fromSharedConfigFiles";
import { fromStatic } from "./fromStatic";
export const loadConfig = ({ environmentVariableSelector, configFileSelector, default: defaultValue }, configuration = {}) => {
const { signingName, logger } = configuration;
const envOptions = { signingName, logger };
return memoize(chain(fromEnv(environmentVariableSelector, envOptions), fromSharedConfigFiles(configFileSelector, configuration), fromStatic(defaultValue)));
};
import { CredentialsProviderError } from "@smithy/property-provider";
import { getSelectorName } from "./getSelectorName";
export const fromEnv = (envVarSelector, options) => async () => {
try {
const config = envVarSelector(process.env, options);
if (config === undefined) {
throw new Error();
}
return config;
}
catch (e) {
throw new CredentialsProviderError(e.message || `Not found in ENV: ${getSelectorName(envVarSelector.toString())}`, { logger: options?.logger });
}
};
import { CredentialsProviderError } from "@smithy/property-provider";
import { getProfileName, loadSharedConfigFiles } from "@smithy/shared-ini-file-loader";
import { getSelectorName } from "./getSelectorName";
export const fromSharedConfigFiles = (configSelector, { preferredFile = "config", ...init } = {}) => async () => {
const profile = getProfileName(init);
const { configFile, credentialsFile } = await loadSharedConfigFiles(init);
const profileFromCredentials = credentialsFile[profile] || {};
const profileFromConfig = configFile[profile] || {};
const mergedProfile = preferredFile === "config"
? { ...profileFromCredentials, ...profileFromConfig }
: { ...profileFromConfig, ...profileFromCredentials };
try {
const cfgFile = preferredFile === "config" ? configFile : credentialsFile;
const configValue = configSelector(mergedProfile, cfgFile);
if (configValue === undefined) {
throw new Error();
}
return configValue;
}
catch (e) {
throw new CredentialsProviderError(e.message || `Not found in config files w/ profile [${profile}]: ${getSelectorName(configSelector.toString())}`, { logger: init.logger });
}
};
import { fromStatic as convertToProvider } from "@smithy/property-provider";
const isFunction = (func) => typeof func === "function";
export const fromStatic = (defaultValue) => isFunction(defaultValue) ? async () => await defaultValue() : convertToProvider(defaultValue);
export function getSelectorName(functionString) {
try {
const constants = new Set(Array.from(functionString.match(/([A-Z_]){3,}/g) ?? []));
constants.delete("CONFIG");
constants.delete("CONFIG_PREFIX_SEPARATOR");
constants.delete("ENV");
return [...constants].join(", ");
}
catch (e) {
return functionString;
}
}
import type { Provider } from "@smithy/types";
import type { EnvOptions, GetterFromEnv } from "./fromEnv";
import type { GetterFromConfig, SharedConfigInit } from "./fromSharedConfigFiles";
import type { FromStaticConfig } from "./fromStatic";
/**
* @internal
*/
export type LocalConfigOptions = SharedConfigInit & EnvOptions;
/**
* @internal
*/
export interface LoadedConfigSelectors<T> {
/**
* A getter function getting the config values from all the environment
* variables.
*/
environmentVariableSelector: GetterFromEnv<T>;
/**
* A getter function getting config values associated with the inferred
* profile from shared INI files
*/
configFileSelector: GetterFromConfig<T>;
/**
* Default value or getter
*/
default: FromStaticConfig<T>;
}
/**
* @internal
*/
export declare const loadConfig: <T = string>({ environmentVariableSelector, configFileSelector, default: defaultValue }: LoadedConfigSelectors<T>, configuration?: LocalConfigOptions) => Provider<T>;
import type { Logger, Provider } from "@smithy/types";
/**
* @internal
*/
export interface EnvOptions {
/**
* The SigV4 service signing name.
*/
signingName?: string;
/**
* For credential resolution trace logging.
*/
logger?: Logger;
}
export type GetterFromEnv<T> = (env: Record<string, string | undefined>, options?: EnvOptions) => T | undefined;
/**
* Get config value given the environment variable name or getter from
* environment variable.
*/
export declare const fromEnv: <T = string>(envVarSelector: GetterFromEnv<T>, options?: EnvOptions) => Provider<T>;
import type { SourceProfileInit } from "@smithy/shared-ini-file-loader";
import type { ParsedIniData, Profile, Provider } from "@smithy/types";
/**
* @internal
*/
export interface SharedConfigInit extends SourceProfileInit {
/**
* The preferred shared ini file to load the config. "config" option refers to
* the shared config file(defaults to `~/.aws/config`). "credentials" option
* refers to the shared credentials file(defaults to `~/.aws/credentials`)
*/
preferredFile?: "config" | "credentials";
}
/**
* @internal
*/
export type GetterFromConfig<T> = (profile: Profile, configFile?: ParsedIniData) => T | undefined;
/**
* Get config value from the shared config files with inferred profile name.
* @internal
*/
export declare const fromSharedConfigFiles: <T = string>(configSelector: GetterFromConfig<T>, { preferredFile, ...init }?: SharedConfigInit) => Provider<T>;
import type { Provider } from "@smithy/types";
/**
* @internal
*/
export type FromStaticConfig<T> = T | (() => T) | Provider<T>;
/**
* @internal
*/
export declare const fromStatic: <T>(defaultValue: FromStaticConfig<T>) => Provider<T>;
/**
* Attempts to extract the name of the variable that the functional selector is looking for.
* Improves readability over the raw Function.toString() value.
* @internal
* @param functionString - function's string representation.
*
* @returns constant value used within the function.
*/
export declare function getSelectorName(functionString: string): string;
# @smithy/node-config-provider
[![NPM version](https://img.shields.io/npm/v/@smithy/node-config-provider/latest.svg)](https://www.npmjs.com/package/@smithy/node-config-provider)
[![NPM downloads](https://img.shields.io/npm/dm/@smithy/node-config-provider.svg)](https://www.npmjs.com/package/@smithy/node-config-provider)
### :warning: Internal API :warning:
> This is an internal package.
> That means this is used as a dependency for other, public packages, but
> should not be taken directly as a dependency in your application's `package.json`.
> If you are updating the version of this package, for example to bring in a
> bug-fix, you should do so by updating your application lockfile with
> e.g. `npm up @scope/package` or equivalent command in another
> package manager, rather than taking a direct dependency.
---