@scaleway/configuration-loader 2.9.0 → 2.10.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/CHANGELOG.md +172 -0
- package/dist/config-loader.d.ts +3 -1
- package/dist/config-loader.js +16 -14
- package/dist/env.d.ts +21 -19
- package/dist/env.js +3 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/path-resolver.d.ts +2 -0
- package/dist/path-resolver.js +7 -5
- package/dist/types.d.ts +54 -52
- package/dist/yml-loader.d.ts +3 -1
- package/dist/yml-loader.js +17 -13
- package/package.json +3 -5
- package/tsconfig.json +3 -0
- package/tsdown.config.ts +9 -0
- package/tsconfig.build.json +0 -12
- package/vite.config.ts +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,177 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- chore(release): publish
|
|
8
|
+
|
|
9
|
+
- test: check homeDir with empty xdg_config_home (#269)
|
|
10
|
+
|
|
11
|
+
- chore(minor-deps): update dependency @scaleway/eslint-config-react to ^3.10.0 (#238)
|
|
12
|
+
|
|
13
|
+
- chore(packages): upgrade deps (#3157)
|
|
14
|
+
|
|
15
|
+
- chore(release): publish
|
|
16
|
+
|
|
17
|
+
- fix(build): export all types (#1261)
|
|
18
|
+
|
|
19
|
+
- chore(deps): update dependency prettier to v3.8.3 (#2907)
|
|
20
|
+
|
|
21
|
+
- fix(oxlint): enable typescript/strict-boolean-expressions as error (#3570)
|
|
22
|
+
|
|
23
|
+
- chore(release): publish
|
|
24
|
+
|
|
25
|
+
- fix(oxlint): enable eslint/curly as error (#3511)
|
|
26
|
+
|
|
27
|
+
- chore(deps): update node.js to >=20.19.1 (#2094)
|
|
28
|
+
|
|
29
|
+
- feat: update to Node18, remove cross-fetch, and run tests on node+jsdom (#386)
|
|
30
|
+
|
|
31
|
+
- feat(configuration-loader): add async config loading and file permission check (#2860)
|
|
32
|
+
|
|
33
|
+
- chore(biome): use biome to format instead of prettier (#1947)
|
|
34
|
+
|
|
35
|
+
- test(vitest): use vitest instead of jest (#1124)
|
|
36
|
+
|
|
37
|
+
- chore(typescript): upgrade version (#2916)
|
|
38
|
+
|
|
39
|
+
- chore(deps): update node.js to >=20.19.6 (#2604)
|
|
40
|
+
|
|
41
|
+
- chore(release): publish
|
|
42
|
+
|
|
43
|
+
- chore: commit generated files for release (#2876)
|
|
44
|
+
|
|
45
|
+
- chore(deps): update pnpm to v10.33.0 (#2905)
|
|
46
|
+
|
|
47
|
+
- chore(client): clean up client usage inside sdk (#1952)
|
|
48
|
+
|
|
49
|
+
- fix(oxlint): enable 12 tiny unicorn rules as error (#3573)
|
|
50
|
+
|
|
51
|
+
- chore(release): publish
|
|
52
|
+
|
|
53
|
+
- chore(deps): update node.js to >=20.19.4 (#2280)
|
|
54
|
+
|
|
55
|
+
- chore(release): publish
|
|
56
|
+
|
|
57
|
+
- chore(release): publish
|
|
58
|
+
|
|
59
|
+
- chore(release): publish
|
|
60
|
+
|
|
61
|
+
- fix(oxlint): enable eslint/require-unicode-regexp as error (#3424)
|
|
62
|
+
|
|
63
|
+
- chore(release): publish
|
|
64
|
+
|
|
65
|
+
- chore(lerna): remove lerna and use pnpm auto release repo pkg (#3174)
|
|
66
|
+
|
|
67
|
+
- fix(oxlint): enable 12 fully-fixed rules as error (#3574) (#3575)
|
|
68
|
+
|
|
69
|
+
- chore(release): publish
|
|
70
|
+
|
|
71
|
+
- chore(release): publish
|
|
72
|
+
|
|
73
|
+
- chore(deps): update dependency typescript to ^4.9.3 (#241)
|
|
74
|
+
|
|
75
|
+
- chore(packages): add licence field, use exports field everywhere (#2147)
|
|
76
|
+
|
|
77
|
+
- chore(release): publish
|
|
78
|
+
|
|
79
|
+
- chore(release): publish
|
|
80
|
+
|
|
81
|
+
- chore(release): publish
|
|
82
|
+
|
|
83
|
+
- fix(oxlint): enable unicorn/import-style as error (#3553)
|
|
84
|
+
|
|
85
|
+
- chore(release): publish
|
|
86
|
+
|
|
87
|
+
- feat: prepare v1 release (#454)
|
|
88
|
+
|
|
89
|
+
- chore: remove linter warnings, and move jsdom to devDep (#1154)
|
|
90
|
+
|
|
91
|
+
- chore(release): publish
|
|
92
|
+
|
|
93
|
+
- chore: fix a few typos (#47)
|
|
94
|
+
|
|
95
|
+
- chore(release): publish
|
|
96
|
+
|
|
97
|
+
- fix(oxlint): enable error-message, only-throw-error, prefer-type-error as error (#3591)
|
|
98
|
+
|
|
99
|
+
- chore(release): publish
|
|
100
|
+
|
|
101
|
+
- feat: migrate to GitHub (#1)
|
|
102
|
+
|
|
103
|
+
- chore(release): publish
|
|
104
|
+
|
|
105
|
+
- chore(minor-deps): update dependency @scaleway/eslint-config-react to ^3.14.1 (#378)
|
|
106
|
+
|
|
107
|
+
- chore(deps): update node.js to >=20.20.2 (#2960)
|
|
108
|
+
|
|
109
|
+
- chore: migrate from ESLint to Biome for linting and formatting (#2551)
|
|
110
|
+
|
|
111
|
+
- chore(deps): update dependency husky to v9 (#1149)
|
|
112
|
+
|
|
113
|
+
- fix: exclude generated config files from biome formatting (#2661)
|
|
114
|
+
|
|
115
|
+
- feat(configuration-loader): list all configurations at once (#336)
|
|
116
|
+
|
|
117
|
+
- chore(release): publish
|
|
118
|
+
|
|
119
|
+
- chore(deps): update dependency @typescript/native-preview to v7.0.0-dev.20260420.1 (#2906)
|
|
120
|
+
|
|
121
|
+
- fix(release): run by commit and github release cli (#3185)
|
|
122
|
+
|
|
123
|
+
- feat: publish packages as ESM only (#2624)
|
|
124
|
+
|
|
125
|
+
- chore(build): from rollup to vite config (#1255)
|
|
126
|
+
|
|
127
|
+
- chore(deps): update dependency vitest to v4 [security] (#2998)
|
|
128
|
+
|
|
129
|
+
- build: adjust package version (#16)
|
|
130
|
+
|
|
131
|
+
- chore(release): publish
|
|
132
|
+
|
|
133
|
+
- chore(release): publish
|
|
134
|
+
|
|
135
|
+
- chore(release): publish
|
|
136
|
+
|
|
137
|
+
- chore: add extension for nodenext (#2265)
|
|
138
|
+
|
|
139
|
+
- fix(oxlint): enable no-shadow, prefer-destructuring, prefer-global-this, set-state-in-effect as error (#3592)
|
|
140
|
+
|
|
141
|
+
- chore(release): publish
|
|
142
|
+
|
|
143
|
+
- feat(sdk-react): add react sdk (#2794)
|
|
144
|
+
|
|
145
|
+
- chore(release): publish
|
|
146
|
+
|
|
147
|
+
- chore(deps): update dependency @types/node to v18.19.130 (#2610)
|
|
148
|
+
|
|
149
|
+
- chore(release): publish
|
|
150
|
+
|
|
151
|
+
- chore(engines): remove node engines (#3336)
|
|
152
|
+
|
|
153
|
+
- chore(release): publish
|
|
154
|
+
|
|
155
|
+
- chore(release): publish
|
|
156
|
+
|
|
157
|
+
- chore(release): publish
|
|
158
|
+
|
|
159
|
+
- fix(oxlint): enable unicorn/text-encoding-identifier-case as error (#3571)
|
|
160
|
+
|
|
161
|
+
- chore(release): publish
|
|
162
|
+
|
|
163
|
+
- chore(release): publish
|
|
164
|
+
|
|
165
|
+
- feat(sdk): unify tools (#2903)
|
|
166
|
+
|
|
167
|
+
- chore(patch-deps): update dependency @types/node to v20.19.43 (#3094)
|
|
168
|
+
|
|
169
|
+
- chore(release): publish
|
|
170
|
+
|
|
171
|
+
- fix(oxlint): enable eslint/prefer-named-capture-group as error (#3590)
|
|
172
|
+
|
|
173
|
+
- chore(release): publish
|
|
174
|
+
|
|
3
175
|
## 2.9.0
|
|
4
176
|
|
|
5
177
|
### Minor Changes
|
package/dist/config-loader.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AllProfilesFromFileParams, Profile, ProfileFromFileParams } from "./types.js";
|
|
2
|
+
//#region src/config-loader.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Loads profile from environment values.
|
|
4
5
|
*
|
|
@@ -61,3 +62,4 @@ export declare const loadAllProfilesFromConfigurationFileAsync: (params?: Readon
|
|
|
61
62
|
* @public
|
|
62
63
|
*/
|
|
63
64
|
export declare const loadProfileFromConfigurationFileAsync: (params?: Readonly<ProfileFromFileParams>) => Promise<Profile>;
|
|
65
|
+
//#endregion
|
package/dist/config-loader.js
CHANGED
|
@@ -2,8 +2,9 @@ import { EnvironmentKey } from "./env.js";
|
|
|
2
2
|
import { resolveConfigurationFilePath } from "./path-resolver.js";
|
|
3
3
|
import { loadConfigurationFromFile, loadConfigurationFromFileAsync } from "./yml-loader.js";
|
|
4
4
|
import { env } from "node:process";
|
|
5
|
+
|
|
5
6
|
//#region src/config-loader.ts
|
|
6
|
-
|
|
7
|
+
const convertFileConfigToSDK = (obj) => ({
|
|
7
8
|
accessKey: obj.access_key,
|
|
8
9
|
apiURL: obj.api_url,
|
|
9
10
|
defaultOrganizationId: obj.default_organization_id,
|
|
@@ -19,14 +20,14 @@ var convertFileConfigToSDK = (obj) => ({
|
|
|
19
20
|
*
|
|
20
21
|
* @public
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
-
accessKey: env[
|
|
24
|
-
apiURL: env[
|
|
25
|
-
defaultOrganizationId: env[
|
|
26
|
-
defaultProjectId: env[
|
|
27
|
-
defaultRegion: env[
|
|
28
|
-
defaultZone: env[
|
|
29
|
-
secretKey: env[
|
|
23
|
+
const loadProfileFromEnvironmentValues = () => ({
|
|
24
|
+
accessKey: env["SCW_ACCESS_KEY"],
|
|
25
|
+
apiURL: env["SCW_API_URL"],
|
|
26
|
+
defaultOrganizationId: env["SCW_DEFAULT_ORGANIZATION_ID"],
|
|
27
|
+
defaultProjectId: env["SCW_DEFAULT_PROJECT_ID"],
|
|
28
|
+
defaultRegion: env["SCW_DEFAULT_REGION"],
|
|
29
|
+
defaultZone: env["SCW_DEFAULT_ZONE"],
|
|
30
|
+
secretKey: env["SCW_SECRET_KEY"]
|
|
30
31
|
});
|
|
31
32
|
/**
|
|
32
33
|
* Loads all the profiles from configuration file.
|
|
@@ -39,7 +40,7 @@ var loadProfileFromEnvironmentValues = () => ({
|
|
|
39
40
|
*
|
|
40
41
|
* @public
|
|
41
42
|
*/
|
|
42
|
-
|
|
43
|
+
const loadAllProfilesFromConfigurationFile = (params) => {
|
|
43
44
|
const filePath = params?.filepath ?? resolveConfigurationFilePath();
|
|
44
45
|
if (typeof filePath !== "string" || filePath.length === 0) throw new Error("Could not find the path to the configuration file.");
|
|
45
46
|
const configs = loadConfigurationFromFile(filePath);
|
|
@@ -59,7 +60,7 @@ var loadAllProfilesFromConfigurationFile = (params) => {
|
|
|
59
60
|
*
|
|
60
61
|
* @public
|
|
61
62
|
*/
|
|
62
|
-
|
|
63
|
+
const loadProfileFromConfigurationFile = (params) => {
|
|
63
64
|
const configs = loadAllProfilesFromConfigurationFile(params);
|
|
64
65
|
const profileName = params?.profileName ?? "default";
|
|
65
66
|
const profileMap = configs[profileName];
|
|
@@ -79,7 +80,7 @@ var loadProfileFromConfigurationFile = (params) => {
|
|
|
79
80
|
*
|
|
80
81
|
* @public
|
|
81
82
|
*/
|
|
82
|
-
|
|
83
|
+
const loadAllProfilesFromConfigurationFileAsync = async (params) => {
|
|
83
84
|
const filePath = params?.filepath ?? resolveConfigurationFilePath();
|
|
84
85
|
if (typeof filePath !== "string" || filePath.length === 0) throw new Error("Could not find the path to the configuration file.");
|
|
85
86
|
const configs = await loadConfigurationFromFileAsync(filePath);
|
|
@@ -101,12 +102,13 @@ var loadAllProfilesFromConfigurationFileAsync = async (params) => {
|
|
|
101
102
|
*
|
|
102
103
|
* @public
|
|
103
104
|
*/
|
|
104
|
-
|
|
105
|
+
const loadProfileFromConfigurationFileAsync = async (params) => {
|
|
105
106
|
const configs = await loadAllProfilesFromConfigurationFileAsync(params);
|
|
106
107
|
const profileName = params?.profileName ?? "default";
|
|
107
108
|
const profileMap = configs[profileName];
|
|
108
109
|
if (typeof profileMap !== "object") throw new TypeError(`Could not find the desired profile '${profileName}' in the configuration file.`);
|
|
109
110
|
return profileMap;
|
|
110
111
|
};
|
|
112
|
+
|
|
111
113
|
//#endregion
|
|
112
|
-
export { loadAllProfilesFromConfigurationFile, loadAllProfilesFromConfigurationFileAsync, loadProfileFromConfigurationFile, loadProfileFromConfigurationFileAsync, loadProfileFromEnvironmentValues };
|
|
114
|
+
export { loadAllProfilesFromConfigurationFile, loadAllProfilesFromConfigurationFileAsync, loadProfileFromConfigurationFile, loadProfileFromConfigurationFileAsync, loadProfileFromEnvironmentValues };
|
package/dist/env.d.ts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
+
//#region src/env.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Environment Key.
|
|
3
4
|
*/
|
|
4
5
|
export declare enum EnvironmentKey {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
/** Path to the Scaleway configuration file */
|
|
7
|
+
ScwConfigPath = "SCW_CONFIG_PATH",
|
|
8
|
+
/** Scaleway access key */
|
|
9
|
+
ScwAccessKey = "SCW_ACCESS_KEY",
|
|
10
|
+
/**
|
|
11
|
+
* Scaleway secret key
|
|
12
|
+
* @remarks #nosec G101
|
|
13
|
+
*/
|
|
14
|
+
ScwSecretKey = "SCW_SECRET_KEY",
|
|
15
|
+
/** Scaleway API URL */
|
|
16
|
+
ScwAPIURL = "SCW_API_URL",
|
|
17
|
+
/** Scaleway default organization ID */
|
|
18
|
+
ScwDefaultOrganizationId = "SCW_DEFAULT_ORGANIZATION_ID",
|
|
19
|
+
/** Scaleway default project ID */
|
|
20
|
+
ScwDefaultProjectId = "SCW_DEFAULT_PROJECT_ID",
|
|
21
|
+
/** Scaleway default region */
|
|
22
|
+
ScwDefaultRegion = "SCW_DEFAULT_REGION",
|
|
23
|
+
/** Scaleway default zone */
|
|
24
|
+
ScwDefaultZone = "SCW_DEFAULT_ZONE"
|
|
24
25
|
}
|
|
26
|
+
//#endregion
|
package/dist/env.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Environment Key.
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
let EnvironmentKey = /* @__PURE__ */ function(EnvironmentKey) {
|
|
6
6
|
/** Path to the Scaleway configuration file */
|
|
7
7
|
EnvironmentKey["ScwConfigPath"] = "SCW_CONFIG_PATH";
|
|
8
8
|
/** Scaleway access key */
|
|
@@ -24,5 +24,6 @@ var EnvironmentKey = /* @__PURE__ */ function(EnvironmentKey) {
|
|
|
24
24
|
EnvironmentKey["ScwDefaultZone"] = "SCW_DEFAULT_ZONE";
|
|
25
25
|
return EnvironmentKey;
|
|
26
26
|
}({});
|
|
27
|
+
|
|
27
28
|
//#endregion
|
|
28
|
-
export { EnvironmentKey };
|
|
29
|
+
export { EnvironmentKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AllProfilesFromFileParams, Profile, ProfileFromFileParams } from "./types.js";
|
|
2
|
+
import { loadAllProfilesFromConfigurationFile, loadAllProfilesFromConfigurationFileAsync, loadProfileFromConfigurationFile, loadProfileFromConfigurationFileAsync, loadProfileFromEnvironmentValues } from "./config-loader.js";
|
|
3
|
+
import { hasSecureFilePermissions } from "./yml-loader.js";
|
|
4
|
+
export { type AllProfilesFromFileParams, type Profile, type ProfileFromFileParams, hasSecureFilePermissions, loadAllProfilesFromConfigurationFile, loadAllProfilesFromConfigurationFileAsync, loadProfileFromConfigurationFile, loadProfileFromConfigurationFileAsync, loadProfileFromEnvironmentValues };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { hasSecureFilePermissions } from "./yml-loader.js";
|
|
2
2
|
import { loadAllProfilesFromConfigurationFile, loadAllProfilesFromConfigurationFileAsync, loadProfileFromConfigurationFile, loadProfileFromConfigurationFileAsync, loadProfileFromEnvironmentValues } from "./config-loader.js";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
export { hasSecureFilePermissions, loadAllProfilesFromConfigurationFile, loadAllProfilesFromConfigurationFileAsync, loadProfileFromConfigurationFile, loadProfileFromConfigurationFileAsync, loadProfileFromEnvironmentValues };
|
package/dist/path-resolver.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/path-resolver.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Gets the Scaleway directory.
|
|
3
4
|
*
|
|
@@ -14,3 +15,4 @@ export declare const getScwConfigurationDirectory: () => string;
|
|
|
14
15
|
* @internal
|
|
15
16
|
*/
|
|
16
17
|
export declare const resolveConfigurationFilePath: () => string;
|
|
18
|
+
//#endregion
|
package/dist/path-resolver.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { EnvironmentKey } from "./env.js";
|
|
2
|
+
import { env } from "node:process";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
|
-
|
|
5
|
+
|
|
5
6
|
//#region src/path-resolver.ts
|
|
6
7
|
/**
|
|
7
8
|
* Gets the Scaleway directory.
|
|
@@ -10,7 +11,7 @@ import { env } from "node:process";
|
|
|
10
11
|
*
|
|
11
12
|
* @internal
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
const getScwConfigurationDirectory = () => {
|
|
14
15
|
const xdgConfigPath = env.XDG_CONFIG_HOME;
|
|
15
16
|
if (typeof xdgConfigPath === "string" && xdgConfigPath.length > 0) return path.join(xdgConfigPath, "scw");
|
|
16
17
|
return path.join(homedir(), ".config", "scw");
|
|
@@ -22,10 +23,11 @@ var getScwConfigurationDirectory = () => {
|
|
|
22
23
|
*
|
|
23
24
|
* @internal
|
|
24
25
|
*/
|
|
25
|
-
|
|
26
|
-
const envFilePath = env[
|
|
26
|
+
const resolveConfigurationFilePath = () => {
|
|
27
|
+
const envFilePath = env["SCW_CONFIG_PATH"];
|
|
27
28
|
if (typeof envFilePath === "string" && envFilePath.length > 0) return envFilePath;
|
|
28
29
|
return path.join(getScwConfigurationDirectory(), "config.yaml");
|
|
29
30
|
};
|
|
31
|
+
|
|
30
32
|
//#endregion
|
|
31
|
-
export { getScwConfigurationDirectory, resolveConfigurationFilePath };
|
|
33
|
+
export { getScwConfigurationDirectory, resolveConfigurationFilePath };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,67 +1,69 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Profile contains information to help instanciating the Scaleway client.
|
|
3
4
|
*
|
|
4
5
|
* @public
|
|
5
6
|
*/
|
|
6
7
|
export type Profile = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
8
|
+
/**
|
|
9
|
+
* You need an access key and a secret key to connect to Scaleway API.
|
|
10
|
+
* Generate your token at the following address: {@link https://console.scaleway.com/project/credentials}
|
|
11
|
+
*/
|
|
12
|
+
accessKey?: string;
|
|
13
|
+
/**
|
|
14
|
+
* APIURL overrides the API URL of the Scaleway API to the given URL.
|
|
15
|
+
* Change that if you want to direct requests to a different endpoint.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue `https://api.scaleway.com`
|
|
18
|
+
*/
|
|
19
|
+
apiURL?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Your organization ID is the identifier of your account inside Scaleway infrastructure.
|
|
22
|
+
*/
|
|
23
|
+
defaultOrganizationId?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Your project ID is the identifier of the project your resources are attached to.
|
|
26
|
+
*/
|
|
27
|
+
defaultProjectId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* A region is represented as a geographical area such as France (Paris) or the Netherlands (Amsterdam).
|
|
30
|
+
* It can contain multiple availability zones.
|
|
31
|
+
*
|
|
32
|
+
* Examples: fr-par, nl-ams.
|
|
33
|
+
*/
|
|
34
|
+
defaultRegion?: string;
|
|
35
|
+
/**
|
|
36
|
+
* A region can be split into many availability zones (AZ).
|
|
37
|
+
* Latency between multiple AZ of the same region are low as they have a common network layer.
|
|
38
|
+
*
|
|
39
|
+
* Examples: fr-par-1, nl-ams-1
|
|
40
|
+
*/
|
|
41
|
+
defaultZone?: string;
|
|
42
|
+
/**
|
|
43
|
+
* The secret key is the value that can be used to authenticate against the API (the value used in X-Auth-Token HTTP-header).
|
|
44
|
+
* The secret key MUST remain secret and not given to anyone or published online.
|
|
45
|
+
*/
|
|
46
|
+
secretKey?: string;
|
|
46
47
|
};
|
|
47
48
|
/** Configuration type. */
|
|
48
49
|
export type ConfigurationType = Record<string, Record<string, string>>;
|
|
49
50
|
/** Parameters to load the all the profiles from the configuration file */
|
|
50
51
|
export type AllProfilesFromFileParams = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The path at which to locate the configuration file.
|
|
54
|
+
*
|
|
55
|
+
* Defaults to the value of the `SCW_CONFIG_PATH` environment variable
|
|
56
|
+
* or `~/.scw/config` otherwise.
|
|
57
|
+
*/
|
|
58
|
+
filepath?: string;
|
|
58
59
|
};
|
|
59
60
|
/** Parameters to load the profile from the configuration file */
|
|
60
61
|
export type ProfileFromFileParams = AllProfilesFromFileParams & {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Name of the profile to load.
|
|
64
|
+
*
|
|
65
|
+
* @defaultValue `default`
|
|
66
|
+
* */
|
|
67
|
+
profileName?: string;
|
|
67
68
|
};
|
|
69
|
+
//#endregion
|
package/dist/yml-loader.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ConfigurationType } from "./types.js";
|
|
2
|
+
//#region src/yml-loader.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Converts YAML to configuration map.
|
|
4
5
|
*
|
|
@@ -49,3 +50,4 @@ export declare const loadConfigurationFromFileAsync: (filePath: string) => Promi
|
|
|
49
50
|
* @public
|
|
50
51
|
*/
|
|
51
52
|
export declare const hasSecureFilePermissions: (filePath: string) => Promise<boolean>;
|
|
53
|
+
//#endregion
|
package/dist/yml-loader.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { readFile, readFileSync, stat } from "node:fs";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
|
+
|
|
3
4
|
//#region src/yml-loader.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const readFileAsync = promisify(readFile);
|
|
6
|
+
const statAsync = promisify(stat);
|
|
7
|
+
const STRIP_COMMENT_REGEX = /(?<prefix>^|\s)[;#]/v;
|
|
8
|
+
const DETECT_SECTION_REGEX = /^\s*(?<section>[\s\S]+?):\s*$/v;
|
|
9
|
+
const DETECT_ITEM_REGEX = /^\s*(?<key>.+?)\s*:\s*(?<value>.+?)\s*$/v;
|
|
9
10
|
/**
|
|
10
11
|
* Converts YAML to configuration map.
|
|
11
12
|
*
|
|
@@ -14,12 +15,12 @@ var DETECT_ITEM_REGEX = new RegExp("^\\s*(?<key>.+?)\\s*:\\s*(?<value>.+?)\\s*$"
|
|
|
14
15
|
*
|
|
15
16
|
* @internal
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
const convertYamlToConfiguration = (input) => {
|
|
18
19
|
let foundProfilesKey = false;
|
|
19
20
|
let currentSection = "default";
|
|
20
21
|
const map = {};
|
|
21
22
|
if (typeof input !== "string") return map;
|
|
22
|
-
input.split(
|
|
23
|
+
input.split(/\r?\n/v).forEach((rawLine) => {
|
|
23
24
|
const [line] = rawLine.split(STRIP_COMMENT_REGEX);
|
|
24
25
|
const newSection = DETECT_SECTION_REGEX.exec(line);
|
|
25
26
|
if (newSection) {
|
|
@@ -48,8 +49,9 @@ var convertYamlToConfiguration = (input) => {
|
|
|
48
49
|
*
|
|
49
50
|
* @internal
|
|
50
51
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
const loadConfigurationFromFile = (filePath) => {
|
|
53
|
+
const fileContent = readFileSync(filePath, "utf8");
|
|
54
|
+
return convertYamlToConfiguration(fileContent);
|
|
53
55
|
};
|
|
54
56
|
/**
|
|
55
57
|
* Loads configuration from a file (asynchronous).
|
|
@@ -65,8 +67,9 @@ var loadConfigurationFromFile = (filePath) => {
|
|
|
65
67
|
*
|
|
66
68
|
* @public
|
|
67
69
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
const loadConfigurationFromFileAsync = async (filePath) => {
|
|
71
|
+
const fileContent = await readFileAsync(filePath, "utf8");
|
|
72
|
+
return convertYamlToConfiguration(fileContent);
|
|
70
73
|
};
|
|
71
74
|
/**
|
|
72
75
|
* Checks whether a configuration file has secure permissions.
|
|
@@ -81,9 +84,10 @@ var loadConfigurationFromFileAsync = async (filePath) => {
|
|
|
81
84
|
*
|
|
82
85
|
* @public
|
|
83
86
|
*/
|
|
84
|
-
|
|
87
|
+
const hasSecureFilePermissions = async (filePath) => {
|
|
85
88
|
if (process.platform === "win32") return true;
|
|
86
89
|
return ((await statAsync(filePath)).mode & 63) === 0;
|
|
87
90
|
};
|
|
91
|
+
|
|
88
92
|
//#endregion
|
|
89
|
-
export { convertYamlToConfiguration, hasSecureFilePermissions, loadConfigurationFromFile, loadConfigurationFromFileAsync };
|
|
93
|
+
export { convertYamlToConfiguration, hasSecureFilePermissions, loadConfigurationFromFile, loadConfigurationFromFileAsync };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleway/configuration-loader",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "Load configuration via file or environment for NodeJS.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -24,9 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"typecheck": "tsc --noEmit",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"copy-test-fixtures": "mkdir -p dist/__tests__/data && cp src/__tests__/data/*.yaml dist/__tests__/data/",
|
|
30
|
-
"build:profile": "npx vite-bundle-visualizer -c ../../vite.config.ts"
|
|
27
|
+
"build": "tsdown --config tsdown.config.ts && pnpm run copy-test-fixtures",
|
|
28
|
+
"copy-test-fixtures": "mkdir -p dist/__tests__/data && cp src/__tests__/data/*.yaml dist/__tests__/data/"
|
|
31
29
|
}
|
|
32
30
|
}
|
package/tsconfig.json
CHANGED
package/tsdown.config.ts
ADDED
package/tsconfig.build.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"noEmit": false,
|
|
5
|
-
"emitDeclarationOnly": true,
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"outDir": "dist",
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"types": ["node"]
|
|
10
|
-
},
|
|
11
|
-
"exclude": ["dist/*", "*.config.ts", "*.setup.ts", "**/__tests__", "**/__mocks__", "src/**/*.test.tsx"]
|
|
12
|
-
}
|
package/vite.config.ts
DELETED