@scaleway/configuration-loader 2.1.0 → 2.2.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/.turbo/turbo-build.log +10 -9
- package/CHANGELOG.md +6 -0
- package/biome.jsonc +13 -0
- package/dist/config-loader.js +58 -40
- package/dist/env.js +26 -14
- package/dist/index.js +1 -5
- package/dist/path-resolver.js +23 -16
- package/dist/yml-loader.js +44 -36
- package/package.json +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
> @scaleway/configuration-loader@2.1.0 build /home/runner/work/scaleway-sdk-js/scaleway-sdk-js/packages/configuration-loader
|
|
3
3
|
> vite build --config ../../vite.config.ts && pnpm run type:generate
|
|
4
4
|
|
|
5
|
-
[36mvite
|
|
6
|
-
|
|
7
|
-
[32m✓[39m 5 modules transformed.
|
|
5
|
+
[36mvite v8.0.0-beta.16 [32mbuilding ssr environment for production...[36m[39m
|
|
6
|
+
[2K
|
|
8
7
|
rendering chunks...
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
computing gzip size...
|
|
9
|
+
dist/index.js 0.26 kB │ gzip: 0.12 kB
|
|
10
|
+
dist/path-resolver.js 0.89 kB │ gzip: 0.38 kB
|
|
11
|
+
dist/env.js 0.90 kB │ gzip: 0.38 kB
|
|
12
|
+
dist/yml-loader.js 1.40 kB │ gzip: 0.64 kB
|
|
13
|
+
dist/config-loader.js 2.56 kB │ gzip: 0.81 kB
|
|
14
|
+
|
|
15
|
+
[32m✓ built in 28ms[39m
|
|
15
16
|
|
|
16
17
|
> @scaleway/configuration-loader@2.1.0 type:generate /home/runner/work/scaleway-sdk-js/scaleway-sdk-js/packages/configuration-loader
|
|
17
18
|
> tsc --declaration -p tsconfig.build.json
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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
|
+
# 2.2.0 (2026-03-05)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **sdk-react:** add react sdk ([#2794](https://github.com/scaleway/scaleway-sdk-js/issues/2794)) ([7dfbf6b](https://github.com/scaleway/scaleway-sdk-js/commit/7dfbf6b4d4eae5f95cd05ff7433e30c522619475))
|
|
11
|
+
|
|
6
12
|
# 2.1.0 (2025-12-19)
|
|
7
13
|
|
|
8
14
|
### Bug Fixes
|
package/biome.jsonc
ADDED
package/dist/config-loader.js
CHANGED
|
@@ -1,50 +1,68 @@
|
|
|
1
|
-
import { env } from "node:process";
|
|
2
1
|
import { EnvironmentKey } from "./env.js";
|
|
3
2
|
import { resolveConfigurationFilePath } from "./path-resolver.js";
|
|
4
3
|
import { loadConfigurationFromFile } from "./yml-loader.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import { env } from "node:process";
|
|
5
|
+
var convertFileConfigToSDK = (obj) => ({
|
|
6
|
+
accessKey: obj.access_key,
|
|
7
|
+
apiURL: obj.api_url,
|
|
8
|
+
defaultOrganizationId: obj.default_organization_id,
|
|
9
|
+
defaultProjectId: obj.default_project_id,
|
|
10
|
+
defaultRegion: obj.default_region,
|
|
11
|
+
defaultZone: obj.default_zone,
|
|
12
|
+
secretKey: obj.secret_key
|
|
13
13
|
});
|
|
14
|
+
/**
|
|
15
|
+
* Loads profile from environment values.
|
|
16
|
+
*
|
|
17
|
+
* @returns The profile filled with values found in the environment
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
14
21
|
const loadProfileFromEnvironmentValues = () => ({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
accessKey: env[EnvironmentKey.ScwAccessKey],
|
|
23
|
+
apiURL: env[EnvironmentKey.ScwAPIURL],
|
|
24
|
+
defaultOrganizationId: env[EnvironmentKey.ScwDefaultOrganizationId],
|
|
25
|
+
defaultProjectId: env[EnvironmentKey.ScwDefaultProjectId],
|
|
26
|
+
defaultRegion: env[EnvironmentKey.ScwDefaultRegion],
|
|
27
|
+
defaultZone: env[EnvironmentKey.ScwDefaultZone],
|
|
28
|
+
secretKey: env[EnvironmentKey.ScwSecretKey]
|
|
22
29
|
});
|
|
30
|
+
/**
|
|
31
|
+
* Loads all the profiles from configuration file.
|
|
32
|
+
*
|
|
33
|
+
* @param params - The parameters to load the profile
|
|
34
|
+
* @returns The profiles filled with values found in the configuration profile
|
|
35
|
+
*
|
|
36
|
+
* @throws Error
|
|
37
|
+
* Thrown if the configuration file couldn't be found.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
23
41
|
const loadAllProfilesFromConfigurationFile = (params) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (const pKey of Object.keys(configs)) {
|
|
31
|
-
result[pKey] = convertFileConfigToSDK(configs[pKey]);
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
42
|
+
const filePath = params?.filepath ?? resolveConfigurationFilePath();
|
|
43
|
+
if (typeof filePath !== "string" || filePath.length === 0) throw new Error("Could not find the path to the configuration file.");
|
|
44
|
+
const configs = loadConfigurationFromFile(filePath);
|
|
45
|
+
const result = {};
|
|
46
|
+
for (const pKey of Object.keys(configs)) result[pKey] = convertFileConfigToSDK(configs[pKey]);
|
|
47
|
+
return result;
|
|
34
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Loads profile from configuration file.
|
|
51
|
+
*
|
|
52
|
+
* @param params - The parameters to load the profile
|
|
53
|
+
* @returns The profile filled with values found in the configuration profile
|
|
54
|
+
*
|
|
55
|
+
* @throws Error
|
|
56
|
+
* Thrown if the configuration file couldn't be found,
|
|
57
|
+
* or if the specified profile can't be found.
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
35
61
|
const loadProfileFromConfigurationFile = (params) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
`Could not find the desired profile '${profileName}' in the configuration file.`
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
return profileMap;
|
|
45
|
-
};
|
|
46
|
-
export {
|
|
47
|
-
loadAllProfilesFromConfigurationFile,
|
|
48
|
-
loadProfileFromConfigurationFile,
|
|
49
|
-
loadProfileFromEnvironmentValues
|
|
62
|
+
const configs = loadAllProfilesFromConfigurationFile(params);
|
|
63
|
+
const profileName = params?.profileName ?? "default";
|
|
64
|
+
const profileMap = configs[profileName];
|
|
65
|
+
if (typeof profileMap !== "object") throw new Error(`Could not find the desired profile '${profileName}' in the configuration file.`);
|
|
66
|
+
return profileMap;
|
|
50
67
|
};
|
|
68
|
+
export { loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
|
package/dist/env.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Environment Key.
|
|
3
|
+
*/
|
|
4
|
+
let EnvironmentKey = /* @__PURE__ */ function(EnvironmentKey) {
|
|
5
|
+
/** Path to the Scaleway configuration file */
|
|
6
|
+
EnvironmentKey["ScwConfigPath"] = "SCW_CONFIG_PATH";
|
|
7
|
+
/** Scaleway access key */
|
|
8
|
+
EnvironmentKey["ScwAccessKey"] = "SCW_ACCESS_KEY";
|
|
9
|
+
/**
|
|
10
|
+
* Scaleway secret key
|
|
11
|
+
* @remarks #nosec G101
|
|
12
|
+
*/
|
|
13
|
+
EnvironmentKey["ScwSecretKey"] = "SCW_SECRET_KEY";
|
|
14
|
+
/** Scaleway API URL */
|
|
15
|
+
EnvironmentKey["ScwAPIURL"] = "SCW_API_URL";
|
|
16
|
+
/** Scaleway default organization ID */
|
|
17
|
+
EnvironmentKey["ScwDefaultOrganizationId"] = "SCW_DEFAULT_ORGANIZATION_ID";
|
|
18
|
+
/** Scaleway default project ID */
|
|
19
|
+
EnvironmentKey["ScwDefaultProjectId"] = "SCW_DEFAULT_PROJECT_ID";
|
|
20
|
+
/** Scaleway default region */
|
|
21
|
+
EnvironmentKey["ScwDefaultRegion"] = "SCW_DEFAULT_REGION";
|
|
22
|
+
/** Scaleway default zone */
|
|
23
|
+
EnvironmentKey["ScwDefaultZone"] = "SCW_DEFAULT_ZONE";
|
|
24
|
+
return EnvironmentKey;
|
|
25
|
+
}({});
|
|
26
|
+
export { EnvironmentKey };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
1
|
import { loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues } from "./config-loader.js";
|
|
2
|
-
export {
|
|
3
|
-
loadAllProfilesFromConfigurationFile,
|
|
4
|
-
loadProfileFromConfigurationFile,
|
|
5
|
-
loadProfileFromEnvironmentValues
|
|
6
|
-
};
|
|
2
|
+
export { loadAllProfilesFromConfigurationFile, loadProfileFromConfigurationFile, loadProfileFromEnvironmentValues };
|
package/dist/path-resolver.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
+
import { EnvironmentKey } from "./env.js";
|
|
2
|
+
import { env } from "node:process";
|
|
1
3
|
import { homedir } from "node:os";
|
|
2
4
|
import * as path from "node:path";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Gets the Scaleway directory.
|
|
7
|
+
*
|
|
8
|
+
* @returns The path to the Scaleway diretory
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
5
12
|
const getScwConfigurationDirectory = () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return path.join(homedir(), ".config", "scw");
|
|
13
|
+
const xdgConfigPath = env.XDG_CONFIG_HOME;
|
|
14
|
+
if (typeof xdgConfigPath === "string" && xdgConfigPath.length > 0) return path.join(xdgConfigPath, "scw");
|
|
15
|
+
return path.join(homedir(), ".config", "scw");
|
|
11
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Gets the configuration file path.
|
|
19
|
+
*
|
|
20
|
+
* @returns The path to the configuration file
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
12
24
|
const resolveConfigurationFilePath = () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return path.join(getScwConfigurationDirectory(), "config.yaml");
|
|
18
|
-
};
|
|
19
|
-
export {
|
|
20
|
-
getScwConfigurationDirectory,
|
|
21
|
-
resolveConfigurationFilePath
|
|
25
|
+
const envFilePath = env[EnvironmentKey.ScwConfigPath];
|
|
26
|
+
if (typeof envFilePath === "string" && envFilePath.length > 0) return envFilePath;
|
|
27
|
+
return path.join(getScwConfigurationDirectory(), "config.yaml");
|
|
22
28
|
};
|
|
29
|
+
export { resolveConfigurationFilePath };
|
package/dist/yml-loader.js
CHANGED
|
@@ -1,41 +1,49 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var STRIP_COMMENT_REGEX = /(^|\s)[;#]/;
|
|
3
|
+
var DETECT_SECTION_REGEX = /^\s*([\s\S]+?):\s*$/;
|
|
4
|
+
var DETECT_ITEM_REGEX = /^\s*(.+?)\s*:\s*(.+?)\s*$/;
|
|
5
|
+
/**
|
|
6
|
+
* Converts YAML to configuration map.
|
|
7
|
+
*
|
|
8
|
+
* @param input - YAML string
|
|
9
|
+
* @returns The configuration map
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
5
13
|
const convertYamlToConfiguration = (input) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
map[currentSection] = {};
|
|
27
|
-
}
|
|
28
|
-
[, , map[currentSection][item[1]]] = item;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return map;
|
|
14
|
+
let foundProfilesKey = false;
|
|
15
|
+
let currentSection = "default";
|
|
16
|
+
const map = {};
|
|
17
|
+
if (typeof input !== "string") return map;
|
|
18
|
+
input.split(/\r?\n/).forEach((rawLine) => {
|
|
19
|
+
const line = rawLine.split(STRIP_COMMENT_REGEX)[0];
|
|
20
|
+
const newSection = DETECT_SECTION_REGEX.exec(line);
|
|
21
|
+
if (newSection) {
|
|
22
|
+
currentSection = void 0;
|
|
23
|
+
if (newSection[1] === "profiles") foundProfilesKey = true;
|
|
24
|
+
else if (foundProfilesKey) [, currentSection] = newSection;
|
|
25
|
+
} else if (currentSection) {
|
|
26
|
+
const item = DETECT_ITEM_REGEX.exec(line);
|
|
27
|
+
if (item) {
|
|
28
|
+
if (typeof map[currentSection] !== "object") map[currentSection] = {};
|
|
29
|
+
[, , map[currentSection][item[1]]] = item;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return map;
|
|
33
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Loads configuration from a file.
|
|
37
|
+
*
|
|
38
|
+
* @param filePath - Path to the configuration file
|
|
39
|
+
* @returns The configuration
|
|
40
|
+
*
|
|
41
|
+
* @throws Error
|
|
42
|
+
* Thrown if the file doesn't exist.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
34
46
|
const loadConfigurationFromFile = (filePath) => {
|
|
35
|
-
|
|
36
|
-
return convertYamlToConfiguration(fileContent);
|
|
37
|
-
};
|
|
38
|
-
export {
|
|
39
|
-
convertYamlToConfiguration,
|
|
40
|
-
loadConfigurationFromFile
|
|
47
|
+
return convertYamlToConfiguration(readFileSync(filePath, "utf-8"));
|
|
41
48
|
};
|
|
49
|
+
export { loadConfigurationFromFile };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleway/configuration-loader",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Load configuration via file or environment for NodeJS.",
|
|
6
6
|
"publishConfig": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/node": "
|
|
25
|
+
"@types/node": "20.19.35"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"typecheck": "tsc --noEmit",
|