@smithy/util-defaults-mode-node
Advanced tools
Comparing version 2.0.32 to 2.1.0
@@ -1,9 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.IMDS_REGION_PATH = exports.DEFAULTS_MODE_OPTIONS = exports.ENV_IMDS_DISABLED = exports.AWS_DEFAULT_REGION_ENV = exports.AWS_REGION_ENV = exports.AWS_EXECUTION_ENV = void 0; | ||
exports.AWS_EXECUTION_ENV = "AWS_EXECUTION_ENV"; | ||
exports.AWS_REGION_ENV = "AWS_REGION"; | ||
exports.AWS_DEFAULT_REGION_ENV = "AWS_DEFAULT_REGION"; | ||
exports.ENV_IMDS_DISABLED = "AWS_EC2_METADATA_DISABLED"; | ||
exports.DEFAULTS_MODE_OPTIONS = ["in-region", "cross-region", "mobile", "standard", "legacy"]; | ||
exports.IMDS_REGION_PATH = "/latest/meta-data/placement/region"; | ||
module.exports = require("./index.js"); |
@@ -1,14 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NODE_DEFAULTS_MODE_CONFIG_OPTIONS = void 0; | ||
const AWS_DEFAULTS_MODE_ENV = "AWS_DEFAULTS_MODE"; | ||
const AWS_DEFAULTS_MODE_CONFIG = "defaults_mode"; | ||
exports.NODE_DEFAULTS_MODE_CONFIG_OPTIONS = { | ||
environmentVariableSelector: (env) => { | ||
return env[AWS_DEFAULTS_MODE_ENV]; | ||
}, | ||
configFileSelector: (profile) => { | ||
return profile[AWS_DEFAULTS_MODE_CONFIG]; | ||
}, | ||
default: "legacy", | ||
}; | ||
module.exports = require("./index.js"); |
@@ -1,4 +0,107 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./resolveDefaultsModeConfig"), exports); | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
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); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
resolveDefaultsModeConfig: () => resolveDefaultsModeConfig | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/resolveDefaultsModeConfig.ts | ||
var import_config_resolver = require("@smithy/config-resolver"); | ||
var import_credential_provider_imds = require("@smithy/credential-provider-imds"); | ||
var import_node_config_provider = require("@smithy/node-config-provider"); | ||
var import_property_provider = require("@smithy/property-provider"); | ||
// src/constants.ts | ||
var AWS_EXECUTION_ENV = "AWS_EXECUTION_ENV"; | ||
var AWS_REGION_ENV = "AWS_REGION"; | ||
var AWS_DEFAULT_REGION_ENV = "AWS_DEFAULT_REGION"; | ||
var ENV_IMDS_DISABLED = "AWS_EC2_METADATA_DISABLED"; | ||
var DEFAULTS_MODE_OPTIONS = ["in-region", "cross-region", "mobile", "standard", "legacy"]; | ||
var IMDS_REGION_PATH = "/latest/meta-data/placement/region"; | ||
// src/defaultsModeConfig.ts | ||
var AWS_DEFAULTS_MODE_ENV = "AWS_DEFAULTS_MODE"; | ||
var AWS_DEFAULTS_MODE_CONFIG = "defaults_mode"; | ||
var NODE_DEFAULTS_MODE_CONFIG_OPTIONS = { | ||
environmentVariableSelector: (env) => { | ||
return env[AWS_DEFAULTS_MODE_ENV]; | ||
}, | ||
configFileSelector: (profile) => { | ||
return profile[AWS_DEFAULTS_MODE_CONFIG]; | ||
}, | ||
default: "legacy" | ||
}; | ||
// src/resolveDefaultsModeConfig.ts | ||
var resolveDefaultsModeConfig = /* @__PURE__ */ __name(({ | ||
region = (0, import_node_config_provider.loadConfig)(import_config_resolver.NODE_REGION_CONFIG_OPTIONS), | ||
defaultsMode = (0, import_node_config_provider.loadConfig)(NODE_DEFAULTS_MODE_CONFIG_OPTIONS) | ||
} = {}) => (0, import_property_provider.memoize)(async () => { | ||
const mode = typeof defaultsMode === "function" ? await defaultsMode() : defaultsMode; | ||
switch (mode == null ? void 0 : mode.toLowerCase()) { | ||
case "auto": | ||
return resolveNodeDefaultsModeAuto(region); | ||
case "in-region": | ||
case "cross-region": | ||
case "mobile": | ||
case "standard": | ||
case "legacy": | ||
return Promise.resolve(mode == null ? void 0 : mode.toLocaleLowerCase()); | ||
case void 0: | ||
return Promise.resolve("legacy"); | ||
default: | ||
throw new Error( | ||
`Invalid parameter for "defaultsMode", expect ${DEFAULTS_MODE_OPTIONS.join(", ")}, got ${mode}` | ||
); | ||
} | ||
}), "resolveDefaultsModeConfig"); | ||
var resolveNodeDefaultsModeAuto = /* @__PURE__ */ __name(async (clientRegion) => { | ||
if (clientRegion) { | ||
const resolvedRegion = typeof clientRegion === "function" ? await clientRegion() : clientRegion; | ||
const inferredRegion = await inferPhysicalRegion(); | ||
if (!inferredRegion) { | ||
return "standard"; | ||
} | ||
if (resolvedRegion === inferredRegion) { | ||
return "in-region"; | ||
} else { | ||
return "cross-region"; | ||
} | ||
} | ||
return "standard"; | ||
}, "resolveNodeDefaultsModeAuto"); | ||
var inferPhysicalRegion = /* @__PURE__ */ __name(async () => { | ||
if (process.env[AWS_EXECUTION_ENV] && (process.env[AWS_REGION_ENV] || process.env[AWS_DEFAULT_REGION_ENV])) { | ||
return process.env[AWS_REGION_ENV] ?? process.env[AWS_DEFAULT_REGION_ENV]; | ||
} | ||
if (!process.env[ENV_IMDS_DISABLED]) { | ||
try { | ||
const endpoint = await (0, import_credential_provider_imds.getInstanceMetadataEndpoint)(); | ||
return (await (0, import_credential_provider_imds.httpRequest)({ ...endpoint, path: IMDS_REGION_PATH })).toString(); | ||
} catch (e) { | ||
} | ||
} | ||
}, "inferPhysicalRegion"); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
resolveDefaultsModeConfig | ||
}); |
@@ -1,57 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveDefaultsModeConfig = void 0; | ||
const config_resolver_1 = require("@smithy/config-resolver"); | ||
const credential_provider_imds_1 = require("@smithy/credential-provider-imds"); | ||
const node_config_provider_1 = require("@smithy/node-config-provider"); | ||
const property_provider_1 = require("@smithy/property-provider"); | ||
const constants_1 = require("./constants"); | ||
const defaultsModeConfig_1 = require("./defaultsModeConfig"); | ||
const resolveDefaultsModeConfig = ({ region = (0, node_config_provider_1.loadConfig)(config_resolver_1.NODE_REGION_CONFIG_OPTIONS), defaultsMode = (0, node_config_provider_1.loadConfig)(defaultsModeConfig_1.NODE_DEFAULTS_MODE_CONFIG_OPTIONS), } = {}) => (0, property_provider_1.memoize)(async () => { | ||
const mode = typeof defaultsMode === "function" ? await defaultsMode() : defaultsMode; | ||
switch (mode === null || mode === void 0 ? void 0 : mode.toLowerCase()) { | ||
case "auto": | ||
return resolveNodeDefaultsModeAuto(region); | ||
case "in-region": | ||
case "cross-region": | ||
case "mobile": | ||
case "standard": | ||
case "legacy": | ||
return Promise.resolve(mode === null || mode === void 0 ? void 0 : mode.toLocaleLowerCase()); | ||
case undefined: | ||
return Promise.resolve("legacy"); | ||
default: | ||
throw new Error(`Invalid parameter for "defaultsMode", expect ${constants_1.DEFAULTS_MODE_OPTIONS.join(", ")}, got ${mode}`); | ||
} | ||
}); | ||
exports.resolveDefaultsModeConfig = resolveDefaultsModeConfig; | ||
const resolveNodeDefaultsModeAuto = async (clientRegion) => { | ||
if (clientRegion) { | ||
const resolvedRegion = typeof clientRegion === "function" ? await clientRegion() : clientRegion; | ||
const inferredRegion = await inferPhysicalRegion(); | ||
if (!inferredRegion) { | ||
return "standard"; | ||
} | ||
if (resolvedRegion === inferredRegion) { | ||
return "in-region"; | ||
} | ||
else { | ||
return "cross-region"; | ||
} | ||
} | ||
return "standard"; | ||
}; | ||
const inferPhysicalRegion = async () => { | ||
var _a; | ||
if (process.env[constants_1.AWS_EXECUTION_ENV] && (process.env[constants_1.AWS_REGION_ENV] || process.env[constants_1.AWS_DEFAULT_REGION_ENV])) { | ||
return (_a = process.env[constants_1.AWS_REGION_ENV]) !== null && _a !== void 0 ? _a : process.env[constants_1.AWS_DEFAULT_REGION_ENV]; | ||
} | ||
if (!process.env[constants_1.ENV_IMDS_DISABLED]) { | ||
try { | ||
const endpoint = await (0, credential_provider_imds_1.getInstanceMetadataEndpoint)(); | ||
return (await (0, credential_provider_imds_1.httpRequest)({ ...endpoint, path: constants_1.IMDS_REGION_PATH })).toString(); | ||
} | ||
catch (e) { | ||
} | ||
} | ||
}; | ||
module.exports = require("./index.js"); |
{ | ||
"name": "@smithy/util-defaults-mode-node", | ||
"version": "2.0.32", | ||
"version": "2.1.0", | ||
"scripts": { | ||
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'", | ||
"build:cjs": "yarn g:tsc -p tsconfig.cjs.json", | ||
"build:cjs": "node ../../scripts/inline util-defaults-mode-node", | ||
"build:es": "yarn g:tsc -p tsconfig.es.json", | ||
@@ -25,8 +25,8 @@ "build:types": "yarn g:tsc -p tsconfig.types.json", | ||
"dependencies": { | ||
"@smithy/config-resolver": "^2.0.23", | ||
"@smithy/credential-provider-imds": "^2.1.5", | ||
"@smithy/node-config-provider": "^2.1.9", | ||
"@smithy/property-provider": "^2.0.17", | ||
"@smithy/smithy-client": "^2.2.1", | ||
"@smithy/types": "^2.8.0", | ||
"@smithy/config-resolver": "^2.1.0", | ||
"@smithy/credential-provider-imds": "^2.2.0", | ||
"@smithy/node-config-provider": "^2.2.0", | ||
"@smithy/property-provider": "^2.1.0", | ||
"@smithy/smithy-client": "^2.3.0", | ||
"@smithy/types": "^2.9.0", | ||
"tslib": "^2.5.0" | ||
@@ -33,0 +33,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
24473
274