Socket
Socket
Sign inDemoInstall

@smithy/shared-ini-file-loader

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/shared-ini-file-loader - npm Package Compare versions

Comparing version 2.2.8 to 2.3.0

23

dist-cjs/getConfigData.js

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfigData = void 0;
const types_1 = require("@smithy/types");
const loadSharedConfigFiles_1 = require("./loadSharedConfigFiles");
const getConfigData = (data) => Object.entries(data)
.filter(([key]) => {
const indexOfSeparator = key.indexOf(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR);
if (indexOfSeparator === -1) {
return false;
}
return Object.values(types_1.IniSectionType).includes(key.substring(0, indexOfSeparator));
})
.reduce((acc, [key, value]) => {
const indexOfSeparator = key.indexOf(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR);
const updatedKey = key.substring(0, indexOfSeparator) === types_1.IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key;
acc[updatedKey] = value;
return acc;
}, {
...(data.default && { default: data.default }),
});
exports.getConfigData = getConfigData;
module.exports = require("./index.js");

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfigFilepath = exports.ENV_CONFIG_PATH = void 0;
const path_1 = require("path");
const getHomeDir_1 = require("./getHomeDir");
exports.ENV_CONFIG_PATH = "AWS_CONFIG_FILE";
const getConfigFilepath = () => process.env[exports.ENV_CONFIG_PATH] || (0, path_1.join)((0, getHomeDir_1.getHomeDir)(), ".aws", "config");
exports.getConfigFilepath = getConfigFilepath;
module.exports = require("./index.js");

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCredentialsFilepath = exports.ENV_CREDENTIALS_PATH = void 0;
const path_1 = require("path");
const getHomeDir_1 = require("./getHomeDir");
exports.ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
const getCredentialsFilepath = () => process.env[exports.ENV_CREDENTIALS_PATH] || (0, path_1.join)((0, getHomeDir_1.getHomeDir)(), ".aws", "credentials");
exports.getCredentialsFilepath = getCredentialsFilepath;
module.exports = require("./index.js");

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProfileName = exports.DEFAULT_PROFILE = exports.ENV_PROFILE = void 0;
exports.ENV_PROFILE = "AWS_PROFILE";
exports.DEFAULT_PROFILE = "default";
const getProfileName = (init) => init.profile || process.env[exports.ENV_PROFILE] || exports.DEFAULT_PROFILE;
exports.getProfileName = getProfileName;
module.exports = require("./index.js");

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSsoSessionData = void 0;
const types_1 = require("@smithy/types");
const loadSharedConfigFiles_1 = require("./loadSharedConfigFiles");
const getSsoSessionData = (data) => Object.entries(data)
.filter(([key]) => key.startsWith(types_1.IniSectionType.SSO_SESSION + loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR))
.reduce((acc, [key, value]) => ({ ...acc, [key.split(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR)[1]]: value }), {});
exports.getSsoSessionData = getSsoSessionData;
module.exports = require("./index.js");

199

dist-cjs/index.js

@@ -1,11 +0,188 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./getHomeDir"), exports);
tslib_1.__exportStar(require("./getProfileName"), exports);
tslib_1.__exportStar(require("./getSSOTokenFilepath"), exports);
tslib_1.__exportStar(require("./getSSOTokenFromFile"), exports);
tslib_1.__exportStar(require("./loadSharedConfigFiles"), exports);
tslib_1.__exportStar(require("./loadSsoSessionData"), exports);
tslib_1.__exportStar(require("./parseKnownFiles"), exports);
tslib_1.__exportStar(require("./types"), 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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
CONFIG_PREFIX_SEPARATOR: () => CONFIG_PREFIX_SEPARATOR,
DEFAULT_PROFILE: () => DEFAULT_PROFILE,
ENV_PROFILE: () => ENV_PROFILE,
getProfileName: () => getProfileName,
loadSharedConfigFiles: () => loadSharedConfigFiles,
loadSsoSessionData: () => loadSsoSessionData,
parseKnownFiles: () => parseKnownFiles
});
module.exports = __toCommonJS(src_exports);
__reExport(src_exports, require("././getHomeDir"), module.exports);
// src/getProfileName.ts
var ENV_PROFILE = "AWS_PROFILE";
var DEFAULT_PROFILE = "default";
var getProfileName = /* @__PURE__ */ __name((init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE, "getProfileName");
// src/index.ts
__reExport(src_exports, require("././getSSOTokenFilepath"), module.exports);
__reExport(src_exports, require("././getSSOTokenFromFile"), module.exports);
// src/getConfigData.ts
var import_types = require("@smithy/types");
var getConfigData = /* @__PURE__ */ __name((data) => Object.entries(data).filter(([key]) => {
const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
if (indexOfSeparator === -1) {
return false;
}
return Object.values(import_types.IniSectionType).includes(key.substring(0, indexOfSeparator));
}).reduce(
(acc, [key, value]) => {
const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
const updatedKey = key.substring(0, indexOfSeparator) === import_types.IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key;
acc[updatedKey] = value;
return acc;
},
{
// Populate default profile, if present.
...data.default && { default: data.default }
}
), "getConfigData");
// src/getConfigFilepath.ts
var import_path = require("path");
var import_getHomeDir = require("././getHomeDir");
var ENV_CONFIG_PATH = "AWS_CONFIG_FILE";
var getConfigFilepath = /* @__PURE__ */ __name(() => process.env[ENV_CONFIG_PATH] || (0, import_path.join)((0, import_getHomeDir.getHomeDir)(), ".aws", "config"), "getConfigFilepath");
// src/getCredentialsFilepath.ts
var import_getHomeDir2 = require("././getHomeDir");
var ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
var getCredentialsFilepath = /* @__PURE__ */ __name(() => process.env[ENV_CREDENTIALS_PATH] || (0, import_path.join)((0, import_getHomeDir2.getHomeDir)(), ".aws", "credentials"), "getCredentialsFilepath");
// src/parseIni.ts
var prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
var profileNameBlockList = ["__proto__", "profile __proto__"];
var parseIni = /* @__PURE__ */ __name((iniData) => {
const map = {};
let currentSection;
let currentSubSection;
for (const iniLine of iniData.split(/\r?\n/)) {
const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
if (isSection) {
currentSection = void 0;
currentSubSection = void 0;
const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
const matches = prefixKeyRegex.exec(sectionName);
if (matches) {
const [, prefix, , name] = matches;
if (Object.values(import_types.IniSectionType).includes(prefix)) {
currentSection = [prefix, name].join(CONFIG_PREFIX_SEPARATOR);
}
} else {
currentSection = sectionName;
}
if (profileNameBlockList.includes(sectionName)) {
throw new Error(`Found invalid profile name "${sectionName}"`);
}
} else if (currentSection) {
const indexOfEqualsSign = trimmedLine.indexOf("=");
if (![0, -1].includes(indexOfEqualsSign)) {
const [name, value] = [
trimmedLine.substring(0, indexOfEqualsSign).trim(),
trimmedLine.substring(indexOfEqualsSign + 1).trim()
];
if (value === "") {
currentSubSection = name;
} else {
if (currentSubSection && iniLine.trimStart() === iniLine) {
currentSubSection = void 0;
}
map[currentSection] = map[currentSection] || {};
const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name;
map[currentSection][key] = value;
}
}
}
}
return map;
}, "parseIni");
// src/loadSharedConfigFiles.ts
var import_slurpFile = require("././slurpFile");
var swallowError = /* @__PURE__ */ __name(() => ({}), "swallowError");
var CONFIG_PREFIX_SEPARATOR = ".";
var loadSharedConfigFiles = /* @__PURE__ */ __name(async (init = {}) => {
const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init;
const parsedFiles = await Promise.all([
(0, import_slurpFile.slurpFile)(configFilepath, {
ignoreCache: init.ignoreCache
}).then(parseIni).then(getConfigData).catch(swallowError),
(0, import_slurpFile.slurpFile)(filepath, {
ignoreCache: init.ignoreCache
}).then(parseIni).catch(swallowError)
]);
return {
configFile: parsedFiles[0],
credentialsFile: parsedFiles[1]
};
}, "loadSharedConfigFiles");
// src/getSsoSessionData.ts
var getSsoSessionData = /* @__PURE__ */ __name((data) => Object.entries(data).filter(([key]) => key.startsWith(import_types.IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR)).reduce((acc, [key, value]) => ({ ...acc, [key.split(CONFIG_PREFIX_SEPARATOR)[1]]: value }), {}), "getSsoSessionData");
// src/loadSsoSessionData.ts
var import_slurpFile2 = require("././slurpFile");
var swallowError2 = /* @__PURE__ */ __name(() => ({}), "swallowError");
var loadSsoSessionData = /* @__PURE__ */ __name(async (init = {}) => (0, import_slurpFile2.slurpFile)(init.configFilepath ?? getConfigFilepath()).then(parseIni).then(getSsoSessionData).catch(swallowError2), "loadSsoSessionData");
// src/mergeConfigFiles.ts
var mergeConfigFiles = /* @__PURE__ */ __name((...files) => {
const merged = {};
for (const file of files) {
for (const [key, values] of Object.entries(file)) {
if (merged[key] !== void 0) {
Object.assign(merged[key], values);
} else {
merged[key] = values;
}
}
}
return merged;
}, "mergeConfigFiles");
// src/parseKnownFiles.ts
var parseKnownFiles = /* @__PURE__ */ __name(async (init) => {
const parsedFiles = await loadSharedConfigFiles(init);
return mergeConfigFiles(parsedFiles.configFile, parsedFiles.credentialsFile);
}, "parseKnownFiles");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CONFIG_PREFIX_SEPARATOR,
DEFAULT_PROFILE,
ENV_PROFILE,
getProfileName,
loadSharedConfigFiles,
loadSsoSessionData,
parseKnownFiles,
...require("././getHomeDir"),
...require("././getSSOTokenFilepath"),
...require("././getSSOTokenFromFile")
});

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadSharedConfigFiles = exports.CONFIG_PREFIX_SEPARATOR = void 0;
const getConfigData_1 = require("./getConfigData");
const getConfigFilepath_1 = require("./getConfigFilepath");
const getCredentialsFilepath_1 = require("./getCredentialsFilepath");
const parseIni_1 = require("./parseIni");
const slurpFile_1 = require("./slurpFile");
const swallowError = () => ({});
exports.CONFIG_PREFIX_SEPARATOR = ".";
const loadSharedConfigFiles = async (init = {}) => {
const { filepath = (0, getCredentialsFilepath_1.getCredentialsFilepath)(), configFilepath = (0, getConfigFilepath_1.getConfigFilepath)() } = init;
const parsedFiles = await Promise.all([
(0, slurpFile_1.slurpFile)(configFilepath, {
ignoreCache: init.ignoreCache,
})
.then(parseIni_1.parseIni)
.then(getConfigData_1.getConfigData)
.catch(swallowError),
(0, slurpFile_1.slurpFile)(filepath, {
ignoreCache: init.ignoreCache,
})
.then(parseIni_1.parseIni)
.catch(swallowError),
]);
return {
configFile: parsedFiles[0],
credentialsFile: parsedFiles[1],
};
};
exports.loadSharedConfigFiles = loadSharedConfigFiles;
module.exports = require("./index.js");

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadSsoSessionData = void 0;
const getConfigFilepath_1 = require("./getConfigFilepath");
const getSsoSessionData_1 = require("./getSsoSessionData");
const parseIni_1 = require("./parseIni");
const slurpFile_1 = require("./slurpFile");
const swallowError = () => ({});
const loadSsoSessionData = async (init = {}) => {
var _a;
return (0, slurpFile_1.slurpFile)((_a = init.configFilepath) !== null && _a !== void 0 ? _a : (0, getConfigFilepath_1.getConfigFilepath)())
.then(parseIni_1.parseIni)
.then(getSsoSessionData_1.getSsoSessionData)
.catch(swallowError);
};
exports.loadSsoSessionData = loadSsoSessionData;
module.exports = require("./index.js");

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeConfigFiles = void 0;
const mergeConfigFiles = (...files) => {
const merged = {};
for (const file of files) {
for (const [key, values] of Object.entries(file)) {
if (merged[key] !== undefined) {
Object.assign(merged[key], values);
}
else {
merged[key] = values;
}
}
}
return merged;
};
exports.mergeConfigFiles = mergeConfigFiles;
module.exports = require("./index.js");

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseIni = void 0;
const types_1 = require("@smithy/types");
const loadSharedConfigFiles_1 = require("./loadSharedConfigFiles");
const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
const profileNameBlockList = ["__proto__", "profile __proto__"];
const parseIni = (iniData) => {
const map = {};
let currentSection;
let currentSubSection;
for (const iniLine of iniData.split(/\r?\n/)) {
const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
if (isSection) {
currentSection = undefined;
currentSubSection = undefined;
const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
const matches = prefixKeyRegex.exec(sectionName);
if (matches) {
const [, prefix, , name] = matches;
if (Object.values(types_1.IniSectionType).includes(prefix)) {
currentSection = [prefix, name].join(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR);
}
}
else {
currentSection = sectionName;
}
if (profileNameBlockList.includes(sectionName)) {
throw new Error(`Found invalid profile name "${sectionName}"`);
}
}
else if (currentSection) {
const indexOfEqualsSign = trimmedLine.indexOf("=");
if (![0, -1].includes(indexOfEqualsSign)) {
const [name, value] = [
trimmedLine.substring(0, indexOfEqualsSign).trim(),
trimmedLine.substring(indexOfEqualsSign + 1).trim(),
];
if (value === "") {
currentSubSection = name;
}
else {
if (currentSubSection && iniLine.trimStart() === iniLine) {
currentSubSection = undefined;
}
map[currentSection] = map[currentSection] || {};
const key = currentSubSection ? [currentSubSection, name].join(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR) : name;
map[currentSection][key] = value;
}
}
}
}
return map;
};
exports.parseIni = parseIni;
module.exports = require("./index.js");

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseKnownFiles = void 0;
const loadSharedConfigFiles_1 = require("./loadSharedConfigFiles");
const mergeConfigFiles_1 = require("./mergeConfigFiles");
const parseKnownFiles = async (init) => {
const parsedFiles = await (0, loadSharedConfigFiles_1.loadSharedConfigFiles)(init);
return (0, mergeConfigFiles_1.mergeConfigFiles)(parsedFiles.configFile, parsedFiles.credentialsFile);
};
exports.parseKnownFiles = parseKnownFiles;
module.exports = require("./index.js");

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
module.exports = require("./index.js");
{
"name": "@smithy/shared-ini-file-loader",
"version": "2.2.8",
"version": "2.3.0",
"dependencies": {
"@smithy/types": "^2.8.0",
"@smithy/types": "^2.9.0",
"tslib": "^2.5.0"

@@ -18,3 +18,3 @@ },

"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 shared-ini-file-loader",
"build:es": "yarn g:tsc -p tsconfig.es.json",

@@ -38,2 +38,12 @@ "build:types": "yarn g:tsc -p tsconfig.types.json",

"types": "./dist-types/index.d.ts",
"browser": {
"./dist-es/getSSOTokenFromFile": false,
"./dist-es/slurpFile": false
},
"react-native": {
"./dist-cjs/getSSOTokenFromFile": false,
"./dist-cjs/slurpFile": false,
"./dist-es/getSSOTokenFromFile": false,
"./dist-es/slurpFile": false
},
"engines": {

@@ -40,0 +50,0 @@ "node": ">=14.0.0"

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc