@scaleway/configuration-loader 0.1.0-beta.5 → 0.1.0-beta.7
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/CHANGELOG.md +12 -0
- package/dist/config-loader.js +36 -15
- package/dist/index.cjs +38 -16
- package/dist/index.d.ts +18 -3
- package/dist/index.js +1 -1
- package/dist/yml-loader.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.1.0-beta.7 (2023-01-27)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- update to Node18, remove cross-fetch, and run tests on node+jsdom ([#386](https://github.com/scaleway/scaleway-sdk-js/issues/386)) ([4e1fe02](https://github.com/scaleway/scaleway-sdk-js/commit/4e1fe02b54939d2d4008b9c53d56ea2553c796fb))
|
|
11
|
+
|
|
12
|
+
## 0.1.0-beta.6 (2023-01-03)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- **configuration-loader:** list all configurations at once ([#336](https://github.com/scaleway/scaleway-sdk-js/issues/336)) ([f58b62c](https://github.com/scaleway/scaleway-sdk-js/commit/f58b62c050dedf9aa8fae71600c2e718f099173a))
|
|
17
|
+
|
|
6
18
|
## 0.1.0-beta.5 (2022-12-05)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @scaleway/configuration-loader
|
package/dist/config-loader.js
CHANGED
|
@@ -3,6 +3,16 @@ import { EnvironmentKey } from './env.js';
|
|
|
3
3
|
import { resolveConfigurationFilePath } from './path-resolver.js';
|
|
4
4
|
import { loadConfigurationFromFile } from './yml-loader.js';
|
|
5
5
|
|
|
6
|
+
const convertFileConfigToSDK = obj => ({
|
|
7
|
+
accessKey: obj.access_key,
|
|
8
|
+
apiURL: obj.api_url,
|
|
9
|
+
defaultOrganizationId: obj.default_organization_id,
|
|
10
|
+
defaultProjectId: obj.default_project_id,
|
|
11
|
+
defaultRegion: obj.default_region,
|
|
12
|
+
defaultZone: obj.default_zone,
|
|
13
|
+
secretKey: obj.secret_key
|
|
14
|
+
});
|
|
15
|
+
|
|
6
16
|
/**
|
|
7
17
|
* Loads profile from environment values.
|
|
8
18
|
*
|
|
@@ -21,37 +31,48 @@ const loadProfileFromEnvironmentValues = () => ({
|
|
|
21
31
|
});
|
|
22
32
|
|
|
23
33
|
/**
|
|
24
|
-
* Loads
|
|
34
|
+
* Loads all the profiles from configuration file.
|
|
25
35
|
*
|
|
26
36
|
* @param params - The parameters to load the profile
|
|
27
|
-
* @returns The
|
|
37
|
+
* @returns The profiles filled with values found in the configuration profile
|
|
28
38
|
*
|
|
29
39
|
* @throws Error
|
|
30
|
-
* Thrown if the configuration file couldn't be found
|
|
31
|
-
* or if the specified profile can't be found.
|
|
40
|
+
* Thrown if the configuration file couldn't be found.
|
|
32
41
|
*
|
|
33
42
|
* @public
|
|
34
43
|
*/
|
|
35
|
-
const
|
|
44
|
+
const loadAllProfilesFromConfigurationFile = params => {
|
|
36
45
|
const filePath = (params == null ? void 0 : params.filepath) ?? resolveConfigurationFilePath();
|
|
37
46
|
if (typeof filePath !== 'string' || filePath.length === 0) {
|
|
38
47
|
throw new Error('Could not find the path to the configuration file.');
|
|
39
48
|
}
|
|
40
49
|
const configs = loadConfigurationFromFile(filePath);
|
|
50
|
+
return Object.keys(configs).reduce((prev, pKey) => ({
|
|
51
|
+
...prev,
|
|
52
|
+
[pKey]: convertFileConfigToSDK(configs[pKey])
|
|
53
|
+
}), {});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Loads profile from configuration file.
|
|
58
|
+
*
|
|
59
|
+
* @param params - The parameters to load the profile
|
|
60
|
+
* @returns The profile filled with values found in the configuration profile
|
|
61
|
+
*
|
|
62
|
+
* @throws Error
|
|
63
|
+
* Thrown if the configuration file couldn't be found,
|
|
64
|
+
* or if the specified profile can't be found.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
const loadProfileFromConfigurationFile = params => {
|
|
69
|
+
const configs = loadAllProfilesFromConfigurationFile(params);
|
|
41
70
|
const profileName = (params == null ? void 0 : params.profileName) ?? 'default';
|
|
42
71
|
const profileMap = configs[profileName];
|
|
43
72
|
if (typeof profileMap !== 'object') {
|
|
44
73
|
throw new Error(`Could not find the desired profile '${profileName}' in the configuration file.`);
|
|
45
74
|
}
|
|
46
|
-
return
|
|
47
|
-
accessKey: profileMap.access_key,
|
|
48
|
-
apiURL: profileMap.api_url,
|
|
49
|
-
defaultOrganizationId: profileMap.default_organization_id,
|
|
50
|
-
defaultProjectId: profileMap.default_project_id,
|
|
51
|
-
defaultRegion: profileMap.default_region,
|
|
52
|
-
defaultZone: profileMap.default_zone,
|
|
53
|
-
secretKey: profileMap.secret_key
|
|
54
|
-
};
|
|
75
|
+
return profileMap;
|
|
55
76
|
};
|
|
56
77
|
|
|
57
|
-
export { loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
|
|
78
|
+
export { loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
|
package/dist/index.cjs
CHANGED
|
@@ -100,7 +100,7 @@ const convertYamlToConfiguration = input => {
|
|
|
100
100
|
currentSection = undefined;
|
|
101
101
|
if (newSection[1] === 'profiles') {
|
|
102
102
|
foundProfilesKey = true;
|
|
103
|
-
} else if (foundProfilesKey
|
|
103
|
+
} else if (foundProfilesKey) {
|
|
104
104
|
[, currentSection] = newSection;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -136,6 +136,16 @@ const loadConfigurationFromFile = filePath => {
|
|
|
136
136
|
return convertYamlToConfiguration(fileContent);
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
+
const convertFileConfigToSDK = obj => ({
|
|
140
|
+
accessKey: obj.access_key,
|
|
141
|
+
apiURL: obj.api_url,
|
|
142
|
+
defaultOrganizationId: obj.default_organization_id,
|
|
143
|
+
defaultProjectId: obj.default_project_id,
|
|
144
|
+
defaultRegion: obj.default_region,
|
|
145
|
+
defaultZone: obj.default_zone,
|
|
146
|
+
secretKey: obj.secret_key
|
|
147
|
+
});
|
|
148
|
+
|
|
139
149
|
/**
|
|
140
150
|
* Loads profile from environment values.
|
|
141
151
|
*
|
|
@@ -153,6 +163,29 @@ const loadProfileFromEnvironmentValues = () => ({
|
|
|
153
163
|
secretKey: process.env[EnvironmentKey.ScwSecretKey]
|
|
154
164
|
});
|
|
155
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Loads all the profiles from configuration file.
|
|
168
|
+
*
|
|
169
|
+
* @param params - The parameters to load the profile
|
|
170
|
+
* @returns The profiles filled with values found in the configuration profile
|
|
171
|
+
*
|
|
172
|
+
* @throws Error
|
|
173
|
+
* Thrown if the configuration file couldn't be found.
|
|
174
|
+
*
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
const loadAllProfilesFromConfigurationFile = params => {
|
|
178
|
+
const filePath = params?.filepath ?? resolveConfigurationFilePath();
|
|
179
|
+
if (typeof filePath !== 'string' || filePath.length === 0) {
|
|
180
|
+
throw new Error('Could not find the path to the configuration file.');
|
|
181
|
+
}
|
|
182
|
+
const configs = loadConfigurationFromFile(filePath);
|
|
183
|
+
return Object.keys(configs).reduce((prev, pKey) => ({
|
|
184
|
+
...prev,
|
|
185
|
+
[pKey]: convertFileConfigToSDK(configs[pKey])
|
|
186
|
+
}), {});
|
|
187
|
+
};
|
|
188
|
+
|
|
156
189
|
/**
|
|
157
190
|
* Loads profile from configuration file.
|
|
158
191
|
*
|
|
@@ -166,26 +199,15 @@ const loadProfileFromEnvironmentValues = () => ({
|
|
|
166
199
|
* @public
|
|
167
200
|
*/
|
|
168
201
|
const loadProfileFromConfigurationFile = params => {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
throw new Error('Could not find the path to the configuration file.');
|
|
172
|
-
}
|
|
173
|
-
const configs = loadConfigurationFromFile(filePath);
|
|
174
|
-
const profileName = (params == null ? void 0 : params.profileName) ?? 'default';
|
|
202
|
+
const configs = loadAllProfilesFromConfigurationFile(params);
|
|
203
|
+
const profileName = params?.profileName ?? 'default';
|
|
175
204
|
const profileMap = configs[profileName];
|
|
176
205
|
if (typeof profileMap !== 'object') {
|
|
177
206
|
throw new Error(`Could not find the desired profile '${profileName}' in the configuration file.`);
|
|
178
207
|
}
|
|
179
|
-
return
|
|
180
|
-
accessKey: profileMap.access_key,
|
|
181
|
-
apiURL: profileMap.api_url,
|
|
182
|
-
defaultOrganizationId: profileMap.default_organization_id,
|
|
183
|
-
defaultProjectId: profileMap.default_project_id,
|
|
184
|
-
defaultRegion: profileMap.default_region,
|
|
185
|
-
defaultZone: profileMap.default_zone,
|
|
186
|
-
secretKey: profileMap.secret_key
|
|
187
|
-
};
|
|
208
|
+
return profileMap;
|
|
188
209
|
};
|
|
189
210
|
|
|
211
|
+
exports.loadAllProfilesFromConfigurationFile = loadAllProfilesFromConfigurationFile;
|
|
190
212
|
exports.loadProfileFromConfigurationFile = loadProfileFromConfigurationFile;
|
|
191
213
|
exports.loadProfileFromEnvironmentValues = loadProfileFromEnvironmentValues;
|
package/dist/index.d.ts
CHANGED
|
@@ -44,8 +44,8 @@ type Profile = {
|
|
|
44
44
|
*/
|
|
45
45
|
secretKey?: string;
|
|
46
46
|
};
|
|
47
|
-
/** Parameters to load the
|
|
48
|
-
type
|
|
47
|
+
/** Parameters to load the all the profiles from the configuration file */
|
|
48
|
+
type AllProfilesFromFileParams = {
|
|
49
49
|
/**
|
|
50
50
|
* The path at which to locate the configuration file.
|
|
51
51
|
*
|
|
@@ -53,6 +53,9 @@ type ProfileFromFileParams = {
|
|
|
53
53
|
* or `~/.scw/config` otherwise.
|
|
54
54
|
*/
|
|
55
55
|
filepath?: string;
|
|
56
|
+
};
|
|
57
|
+
/** Parameters to load the profile from the configuration file */
|
|
58
|
+
type ProfileFromFileParams = AllProfilesFromFileParams & {
|
|
56
59
|
/**
|
|
57
60
|
* Name of the profile to load.
|
|
58
61
|
*
|
|
@@ -69,6 +72,18 @@ type ProfileFromFileParams = {
|
|
|
69
72
|
* @public
|
|
70
73
|
*/
|
|
71
74
|
declare const loadProfileFromEnvironmentValues: () => Profile;
|
|
75
|
+
/**
|
|
76
|
+
* Loads all the profiles from configuration file.
|
|
77
|
+
*
|
|
78
|
+
* @param params - The parameters to load the profile
|
|
79
|
+
* @returns The profiles filled with values found in the configuration profile
|
|
80
|
+
*
|
|
81
|
+
* @throws Error
|
|
82
|
+
* Thrown if the configuration file couldn't be found.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
declare const loadAllProfilesFromConfigurationFile: (params?: Readonly<AllProfilesFromFileParams>) => Record<string, Profile>;
|
|
72
87
|
/**
|
|
73
88
|
* Loads profile from configuration file.
|
|
74
89
|
*
|
|
@@ -83,4 +98,4 @@ declare const loadProfileFromEnvironmentValues: () => Profile;
|
|
|
83
98
|
*/
|
|
84
99
|
declare const loadProfileFromConfigurationFile: (params?: Readonly<ProfileFromFileParams>) => Profile;
|
|
85
100
|
|
|
86
|
-
export { Profile, ProfileFromFileParams, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
|
|
101
|
+
export { AllProfilesFromFileParams, Profile, ProfileFromFileParams, loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues } from './config-loader.js';
|
|
1
|
+
export { loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues } from './config-loader.js';
|
package/dist/yml-loader.js
CHANGED
|
@@ -28,7 +28,7 @@ const convertYamlToConfiguration = input => {
|
|
|
28
28
|
currentSection = undefined;
|
|
29
29
|
if (newSection[1] === 'profiles') {
|
|
30
30
|
foundProfilesKey = true;
|
|
31
|
-
} else if (foundProfilesKey
|
|
31
|
+
} else if (foundProfilesKey) {
|
|
32
32
|
[, currentSection] = newSection;
|
|
33
33
|
}
|
|
34
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleway/configuration-loader",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Load configuration via file or environment for NodeJS.",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"type": "module",
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@types/node": "^18.11.
|
|
22
|
+
"@types/node": "^18.11.18"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "d58e6175a5b8b8a3727097710b2ebcee012f924b"
|
|
25
25
|
}
|