@smithy/shared-ini-file-loader 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -1,228 +1,189 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- CONFIG_PREFIX_SEPARATOR: () => CONFIG_PREFIX_SEPARATOR,
25
- DEFAULT_PROFILE: () => DEFAULT_PROFILE,
26
- ENV_PROFILE: () => ENV_PROFILE,
27
- SSOToken: () => import_getSSOTokenFromFile2.SSOToken,
28
- externalDataInterceptor: () => externalDataInterceptor,
29
- getProfileName: () => getProfileName,
30
- getSSOTokenFromFile: () => import_getSSOTokenFromFile2.getSSOTokenFromFile,
31
- loadSharedConfigFiles: () => loadSharedConfigFiles,
32
- loadSsoSessionData: () => loadSsoSessionData,
33
- parseKnownFiles: () => parseKnownFiles
34
- });
35
- module.exports = __toCommonJS(index_exports);
36
- __reExport(index_exports, require("././getHomeDir"), module.exports);
1
+ 'use strict';
37
2
 
38
- // src/getProfileName.ts
39
- var ENV_PROFILE = "AWS_PROFILE";
40
- var DEFAULT_PROFILE = "default";
41
- var getProfileName = /* @__PURE__ */ __name((init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE, "getProfileName");
3
+ var getHomeDir = require('./getHomeDir');
4
+ var getSSOTokenFilepath = require('./getSSOTokenFilepath');
5
+ var getSSOTokenFromFile = require('./getSSOTokenFromFile');
6
+ var path = require('path');
7
+ var types = require('@smithy/types');
8
+ var slurpFile = require('./slurpFile');
42
9
 
43
- // src/index.ts
44
- __reExport(index_exports, require("././getSSOTokenFilepath"), module.exports);
45
- var import_getSSOTokenFromFile2 = require("././getSSOTokenFromFile");
10
+ const ENV_PROFILE = "AWS_PROFILE";
11
+ const DEFAULT_PROFILE = "default";
12
+ const getProfileName = (init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE;
46
13
 
47
- // src/loadSharedConfigFiles.ts
48
-
49
-
50
- // src/getConfigData.ts
51
- var import_types = require("@smithy/types");
52
- var getConfigData = /* @__PURE__ */ __name((data) => Object.entries(data).filter(([key]) => {
53
- const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
54
- if (indexOfSeparator === -1) {
55
- return false;
56
- }
57
- return Object.values(import_types.IniSectionType).includes(key.substring(0, indexOfSeparator));
58
- }).reduce(
59
- (acc, [key, value]) => {
14
+ const getConfigData = (data) => Object.entries(data)
15
+ .filter(([key]) => {
16
+ const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
17
+ if (indexOfSeparator === -1) {
18
+ return false;
19
+ }
20
+ return Object.values(types.IniSectionType).includes(key.substring(0, indexOfSeparator));
21
+ })
22
+ .reduce((acc, [key, value]) => {
60
23
  const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
61
- const updatedKey = key.substring(0, indexOfSeparator) === import_types.IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key;
24
+ const updatedKey = key.substring(0, indexOfSeparator) === types.IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key;
62
25
  acc[updatedKey] = value;
63
26
  return acc;
64
- },
65
- {
66
- // Populate default profile, if present.
67
- ...data.default && { default: data.default }
68
- }
69
- ), "getConfigData");
70
-
71
- // src/getConfigFilepath.ts
72
- var import_path = require("path");
73
- var import_getHomeDir = require("././getHomeDir");
74
- var ENV_CONFIG_PATH = "AWS_CONFIG_FILE";
75
- var getConfigFilepath = /* @__PURE__ */ __name(() => process.env[ENV_CONFIG_PATH] || (0, import_path.join)((0, import_getHomeDir.getHomeDir)(), ".aws", "config"), "getConfigFilepath");
76
-
77
- // src/getCredentialsFilepath.ts
78
-
79
- var import_getHomeDir2 = require("././getHomeDir");
80
- var ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
81
- var getCredentialsFilepath = /* @__PURE__ */ __name(() => process.env[ENV_CREDENTIALS_PATH] || (0, import_path.join)((0, import_getHomeDir2.getHomeDir)(), ".aws", "credentials"), "getCredentialsFilepath");
82
-
83
- // src/loadSharedConfigFiles.ts
84
- var import_getHomeDir3 = require("././getHomeDir");
85
-
86
- // src/parseIni.ts
27
+ }, {
28
+ ...(data.default && { default: data.default }),
29
+ });
87
30
 
88
- var prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
89
- var profileNameBlockList = ["__proto__", "profile __proto__"];
90
- var parseIni = /* @__PURE__ */ __name((iniData) => {
91
- const map = {};
92
- let currentSection;
93
- let currentSubSection;
94
- for (const iniLine of iniData.split(/\r?\n/)) {
95
- const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
96
- const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
97
- if (isSection) {
98
- currentSection = void 0;
99
- currentSubSection = void 0;
100
- const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
101
- const matches = prefixKeyRegex.exec(sectionName);
102
- if (matches) {
103
- const [, prefix, , name] = matches;
104
- if (Object.values(import_types.IniSectionType).includes(prefix)) {
105
- currentSection = [prefix, name].join(CONFIG_PREFIX_SEPARATOR);
31
+ const ENV_CONFIG_PATH = "AWS_CONFIG_FILE";
32
+ const getConfigFilepath = () => process.env[ENV_CONFIG_PATH] || path.join(getHomeDir.getHomeDir(), ".aws", "config");
33
+
34
+ const ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
35
+ const getCredentialsFilepath = () => process.env[ENV_CREDENTIALS_PATH] || path.join(getHomeDir.getHomeDir(), ".aws", "credentials");
36
+
37
+ const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
38
+ const profileNameBlockList = ["__proto__", "profile __proto__"];
39
+ const parseIni = (iniData) => {
40
+ const map = {};
41
+ let currentSection;
42
+ let currentSubSection;
43
+ for (const iniLine of iniData.split(/\r?\n/)) {
44
+ const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
45
+ const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
46
+ if (isSection) {
47
+ currentSection = undefined;
48
+ currentSubSection = undefined;
49
+ const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
50
+ const matches = prefixKeyRegex.exec(sectionName);
51
+ if (matches) {
52
+ const [, prefix, , name] = matches;
53
+ if (Object.values(types.IniSectionType).includes(prefix)) {
54
+ currentSection = [prefix, name].join(CONFIG_PREFIX_SEPARATOR);
55
+ }
56
+ }
57
+ else {
58
+ currentSection = sectionName;
59
+ }
60
+ if (profileNameBlockList.includes(sectionName)) {
61
+ throw new Error(`Found invalid profile name "${sectionName}"`);
62
+ }
106
63
  }
107
- } else {
108
- currentSection = sectionName;
109
- }
110
- if (profileNameBlockList.includes(sectionName)) {
111
- throw new Error(`Found invalid profile name "${sectionName}"`);
112
- }
113
- } else if (currentSection) {
114
- const indexOfEqualsSign = trimmedLine.indexOf("=");
115
- if (![0, -1].includes(indexOfEqualsSign)) {
116
- const [name, value] = [
117
- trimmedLine.substring(0, indexOfEqualsSign).trim(),
118
- trimmedLine.substring(indexOfEqualsSign + 1).trim()
119
- ];
120
- if (value === "") {
121
- currentSubSection = name;
122
- } else {
123
- if (currentSubSection && iniLine.trimStart() === iniLine) {
124
- currentSubSection = void 0;
125
- }
126
- map[currentSection] = map[currentSection] || {};
127
- const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name;
128
- map[currentSection][key] = value;
64
+ else if (currentSection) {
65
+ const indexOfEqualsSign = trimmedLine.indexOf("=");
66
+ if (![0, -1].includes(indexOfEqualsSign)) {
67
+ const [name, value] = [
68
+ trimmedLine.substring(0, indexOfEqualsSign).trim(),
69
+ trimmedLine.substring(indexOfEqualsSign + 1).trim(),
70
+ ];
71
+ if (value === "") {
72
+ currentSubSection = name;
73
+ }
74
+ else {
75
+ if (currentSubSection && iniLine.trimStart() === iniLine) {
76
+ currentSubSection = undefined;
77
+ }
78
+ map[currentSection] = map[currentSection] || {};
79
+ const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name;
80
+ map[currentSection][key] = value;
81
+ }
82
+ }
129
83
  }
130
- }
131
84
  }
132
- }
133
- return map;
134
- }, "parseIni");
135
-
136
- // src/loadSharedConfigFiles.ts
137
- var import_slurpFile = require("././slurpFile");
138
- var swallowError = /* @__PURE__ */ __name(() => ({}), "swallowError");
139
- var CONFIG_PREFIX_SEPARATOR = ".";
140
- var loadSharedConfigFiles = /* @__PURE__ */ __name(async (init = {}) => {
141
- const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init;
142
- const homeDir = (0, import_getHomeDir3.getHomeDir)();
143
- const relativeHomeDirPrefix = "~/";
144
- let resolvedFilepath = filepath;
145
- if (filepath.startsWith(relativeHomeDirPrefix)) {
146
- resolvedFilepath = (0, import_path.join)(homeDir, filepath.slice(2));
147
- }
148
- let resolvedConfigFilepath = configFilepath;
149
- if (configFilepath.startsWith(relativeHomeDirPrefix)) {
150
- resolvedConfigFilepath = (0, import_path.join)(homeDir, configFilepath.slice(2));
151
- }
152
- const parsedFiles = await Promise.all([
153
- (0, import_slurpFile.slurpFile)(resolvedConfigFilepath, {
154
- ignoreCache: init.ignoreCache
155
- }).then(parseIni).then(getConfigData).catch(swallowError),
156
- (0, import_slurpFile.slurpFile)(resolvedFilepath, {
157
- ignoreCache: init.ignoreCache
158
- }).then(parseIni).catch(swallowError)
159
- ]);
160
- return {
161
- configFile: parsedFiles[0],
162
- credentialsFile: parsedFiles[1]
163
- };
164
- }, "loadSharedConfigFiles");
165
-
166
- // src/getSsoSessionData.ts
167
-
168
- 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.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1)]: value }), {}), "getSsoSessionData");
85
+ return map;
86
+ };
169
87
 
170
- // src/loadSsoSessionData.ts
171
- var import_slurpFile2 = require("././slurpFile");
172
- var swallowError2 = /* @__PURE__ */ __name(() => ({}), "swallowError");
173
- var loadSsoSessionData = /* @__PURE__ */ __name(async (init = {}) => (0, import_slurpFile2.slurpFile)(init.configFilepath ?? getConfigFilepath()).then(parseIni).then(getSsoSessionData).catch(swallowError2), "loadSsoSessionData");
88
+ const swallowError$1 = () => ({});
89
+ const CONFIG_PREFIX_SEPARATOR = ".";
90
+ const loadSharedConfigFiles = async (init = {}) => {
91
+ const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init;
92
+ const homeDir = getHomeDir.getHomeDir();
93
+ const relativeHomeDirPrefix = "~/";
94
+ let resolvedFilepath = filepath;
95
+ if (filepath.startsWith(relativeHomeDirPrefix)) {
96
+ resolvedFilepath = path.join(homeDir, filepath.slice(2));
97
+ }
98
+ let resolvedConfigFilepath = configFilepath;
99
+ if (configFilepath.startsWith(relativeHomeDirPrefix)) {
100
+ resolvedConfigFilepath = path.join(homeDir, configFilepath.slice(2));
101
+ }
102
+ const parsedFiles = await Promise.all([
103
+ slurpFile.slurpFile(resolvedConfigFilepath, {
104
+ ignoreCache: init.ignoreCache,
105
+ })
106
+ .then(parseIni)
107
+ .then(getConfigData)
108
+ .catch(swallowError$1),
109
+ slurpFile.slurpFile(resolvedFilepath, {
110
+ ignoreCache: init.ignoreCache,
111
+ })
112
+ .then(parseIni)
113
+ .catch(swallowError$1),
114
+ ]);
115
+ return {
116
+ configFile: parsedFiles[0],
117
+ credentialsFile: parsedFiles[1],
118
+ };
119
+ };
174
120
 
175
- // src/mergeConfigFiles.ts
176
- var mergeConfigFiles = /* @__PURE__ */ __name((...files) => {
177
- const merged = {};
178
- for (const file of files) {
179
- for (const [key, values] of Object.entries(file)) {
180
- if (merged[key] !== void 0) {
181
- Object.assign(merged[key], values);
182
- } else {
183
- merged[key] = values;
184
- }
121
+ const getSsoSessionData = (data) => Object.entries(data)
122
+ .filter(([key]) => key.startsWith(types.IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR))
123
+ .reduce((acc, [key, value]) => ({ ...acc, [key.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1)]: value }), {});
124
+
125
+ const swallowError = () => ({});
126
+ const loadSsoSessionData = async (init = {}) => slurpFile.slurpFile(init.configFilepath ?? getConfigFilepath())
127
+ .then(parseIni)
128
+ .then(getSsoSessionData)
129
+ .catch(swallowError);
130
+
131
+ const mergeConfigFiles = (...files) => {
132
+ const merged = {};
133
+ for (const file of files) {
134
+ for (const [key, values] of Object.entries(file)) {
135
+ if (merged[key] !== undefined) {
136
+ Object.assign(merged[key], values);
137
+ }
138
+ else {
139
+ merged[key] = values;
140
+ }
141
+ }
185
142
  }
186
- }
187
- return merged;
188
- }, "mergeConfigFiles");
143
+ return merged;
144
+ };
189
145
 
190
- // src/parseKnownFiles.ts
191
- var parseKnownFiles = /* @__PURE__ */ __name(async (init) => {
192
- const parsedFiles = await loadSharedConfigFiles(init);
193
- return mergeConfigFiles(parsedFiles.configFile, parsedFiles.credentialsFile);
194
- }, "parseKnownFiles");
146
+ const parseKnownFiles = async (init) => {
147
+ const parsedFiles = await loadSharedConfigFiles(init);
148
+ return mergeConfigFiles(parsedFiles.configFile, parsedFiles.credentialsFile);
149
+ };
195
150
 
196
- // src/externalDataInterceptor.ts
197
- var import_getSSOTokenFromFile = require("././getSSOTokenFromFile");
198
- var import_slurpFile3 = require("././slurpFile");
199
- var externalDataInterceptor = {
200
- getFileRecord() {
201
- return import_slurpFile3.fileIntercept;
202
- },
203
- interceptFile(path, contents) {
204
- import_slurpFile3.fileIntercept[path] = Promise.resolve(contents);
205
- },
206
- getTokenRecord() {
207
- return import_getSSOTokenFromFile.tokenIntercept;
208
- },
209
- interceptToken(id, contents) {
210
- import_getSSOTokenFromFile.tokenIntercept[id] = contents;
211
- }
151
+ const externalDataInterceptor = {
152
+ getFileRecord() {
153
+ return slurpFile.fileIntercept;
154
+ },
155
+ interceptFile(path, contents) {
156
+ slurpFile.fileIntercept[path] = Promise.resolve(contents);
157
+ },
158
+ getTokenRecord() {
159
+ return getSSOTokenFromFile.tokenIntercept;
160
+ },
161
+ interceptToken(id, contents) {
162
+ getSSOTokenFromFile.tokenIntercept[id] = contents;
163
+ },
212
164
  };
213
- // Annotate the CommonJS export names for ESM import in node:
214
165
 
215
- 0 && (module.exports = {
216
- getSSOTokenFromFile,
217
- externalDataInterceptor,
218
- getHomeDir,
219
- ENV_PROFILE,
220
- DEFAULT_PROFILE,
221
- getProfileName,
222
- getSSOTokenFilepath,
223
- CONFIG_PREFIX_SEPARATOR,
224
- loadSharedConfigFiles,
225
- loadSsoSessionData,
226
- parseKnownFiles
166
+ Object.defineProperty(exports, "getSSOTokenFromFile", {
167
+ enumerable: true,
168
+ get: function () { return getSSOTokenFromFile.getSSOTokenFromFile; }
169
+ });
170
+ exports.CONFIG_PREFIX_SEPARATOR = CONFIG_PREFIX_SEPARATOR;
171
+ exports.DEFAULT_PROFILE = DEFAULT_PROFILE;
172
+ exports.ENV_PROFILE = ENV_PROFILE;
173
+ exports.externalDataInterceptor = externalDataInterceptor;
174
+ exports.getProfileName = getProfileName;
175
+ exports.loadSharedConfigFiles = loadSharedConfigFiles;
176
+ exports.loadSsoSessionData = loadSsoSessionData;
177
+ exports.parseKnownFiles = parseKnownFiles;
178
+ Object.keys(getHomeDir).forEach(function (k) {
179
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
180
+ enumerable: true,
181
+ get: function () { return getHomeDir[k]; }
182
+ });
183
+ });
184
+ Object.keys(getSSOTokenFilepath).forEach(function (k) {
185
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
186
+ enumerable: true,
187
+ get: function () { return getSSOTokenFilepath[k]; }
188
+ });
227
189
  });
228
-
@@ -9,7 +9,7 @@ const slurpFile = (path, options) => {
9
9
  if (exports.fileIntercept[path] !== undefined) {
10
10
  return exports.fileIntercept[path];
11
11
  }
12
- if (!exports.filePromisesHash[path] || (options === null || options === void 0 ? void 0 : options.ignoreCache)) {
12
+ if (!exports.filePromisesHash[path] || options?.ignoreCache) {
13
13
  exports.filePromisesHash[path] = readFile(path, "utf8");
14
14
  }
15
15
  return exports.filePromisesHash[path];
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@smithy/shared-ini-file-loader",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "dependencies": {
5
- "@smithy/types": "^4.5.0",
5
+ "@smithy/types": "^4.6.0",
6
6
  "tslib": "^2.6.2"
7
7
  },
8
8
  "devDependencies": {
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");
package/dist-cjs/types.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./index.js");