@scaleway/configuration-loader 0.1.0-beta.4 → 0.1.0-beta.6

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 CHANGED
@@ -3,6 +3,16 @@
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.6 (2023-01-03)
7
+
8
+ ### Features
9
+
10
+ - **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))
11
+
12
+ ## 0.1.0-beta.5 (2022-12-05)
13
+
14
+ **Note:** Version bump only for package @scaleway/configuration-loader
15
+
6
16
  ## 0.1.0-beta.4 (2022-11-23)
7
17
 
8
18
  **Note:** Version bump only for package @scaleway/configuration-loader
@@ -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 profile from configuration file.
34
+ * Loads all the profiles from configuration file.
25
35
  *
26
36
  * @param params - The parameters to load the profile
27
- * @returns The profile filled with values found in the configuration profile
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 loadProfileFromConfigurationFile = params => {
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
@@ -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
  *
@@ -154,38 +164,50 @@ const loadProfileFromEnvironmentValues = () => ({
154
164
  });
155
165
 
156
166
  /**
157
- * Loads profile from configuration file.
167
+ * Loads all the profiles from configuration file.
158
168
  *
159
169
  * @param params - The parameters to load the profile
160
- * @returns The profile filled with values found in the configuration profile
170
+ * @returns The profiles filled with values found in the configuration profile
161
171
  *
162
172
  * @throws Error
163
- * Thrown if the configuration file couldn't be found,
164
- * or if the specified profile can't be found.
173
+ * Thrown if the configuration file couldn't be found.
165
174
  *
166
175
  * @public
167
176
  */
168
- const loadProfileFromConfigurationFile = params => {
177
+ const loadAllProfilesFromConfigurationFile = params => {
169
178
  const filePath = (params == null ? void 0 : params.filepath) ?? resolveConfigurationFilePath();
170
179
  if (typeof filePath !== 'string' || filePath.length === 0) {
171
180
  throw new Error('Could not find the path to the configuration file.');
172
181
  }
173
182
  const configs = loadConfigurationFromFile(filePath);
183
+ return Object.keys(configs).reduce((prev, pKey) => ({
184
+ ...prev,
185
+ [pKey]: convertFileConfigToSDK(configs[pKey])
186
+ }), {});
187
+ };
188
+
189
+ /**
190
+ * Loads profile from configuration file.
191
+ *
192
+ * @param params - The parameters to load the profile
193
+ * @returns The profile filled with values found in the configuration profile
194
+ *
195
+ * @throws Error
196
+ * Thrown if the configuration file couldn't be found,
197
+ * or if the specified profile can't be found.
198
+ *
199
+ * @public
200
+ */
201
+ const loadProfileFromConfigurationFile = params => {
202
+ const configs = loadAllProfilesFromConfigurationFile(params);
174
203
  const profileName = (params == null ? void 0 : 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
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @public
5
5
  */
6
- declare type Profile = {
6
+ type Profile = {
7
7
  /**
8
8
  * You need an access key and a secret key to connect to Scaleway API.
9
9
  * Generate your token at the following address: {@link https://console.scaleway.com/project/credentials}
@@ -44,8 +44,8 @@ declare type Profile = {
44
44
  */
45
45
  secretKey?: string;
46
46
  };
47
- /** Parameters to load the profile from the configuration file */
48
- declare type ProfileFromFileParams = {
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 @@ declare 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 @@ declare 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleway/configuration-loader",
3
- "version": "0.1.0-beta.4",
3
+ "version": "0.1.0-beta.6",
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": "^17.0.45"
22
+ "@types/node": "^18.11.10"
23
23
  },
24
- "gitHead": "5484de96723e18038b6a8781ebb941a1f270f49a"
24
+ "gitHead": "0aca532d8c1f7954def5216262ca6c6adb5aa590"
25
25
  }