@scaleway/sdk-client 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.
Files changed (53) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +11 -0
  2. package/dist/helpers/is-browser.js +1 -3
  3. package/dist/helpers/is-response.js +8 -3
  4. package/dist/helpers/json.js +47 -40
  5. package/dist/helpers/marshalling.js +88 -59
  6. package/dist/index.js +6 -47
  7. package/dist/internal/async/interval-retrier.js +64 -49
  8. package/dist/internal/async/sleep.js +10 -4
  9. package/dist/internal/interceptors/composer.js +34 -23
  10. package/dist/internal/interceptors/helpers.js +22 -9
  11. package/dist/internal/logger/console-logger.js +27 -22
  12. package/dist/internal/logger/index.js +23 -7
  13. package/dist/internal/logger/level-resolver.js +9 -12
  14. package/dist/internal/validations/string-validation.js +20 -21
  15. package/dist/internals.js +8 -0
  16. package/dist/package.js +32 -0
  17. package/dist/scw/api.js +10 -7
  18. package/dist/scw/auth.js +60 -17
  19. package/dist/scw/client-ini-factory.js +127 -57
  20. package/dist/scw/client-ini-profile.js +23 -19
  21. package/dist/scw/client-settings.js +25 -49
  22. package/dist/scw/client.js +76 -25
  23. package/dist/scw/constants.js +3 -8
  24. package/dist/scw/custom-marshalling.js +147 -121
  25. package/dist/scw/custom-types.js +11 -10
  26. package/dist/scw/errors/error-parser.js +83 -61
  27. package/dist/scw/errors/non-standard/invalid-request-mapper.js +20 -29
  28. package/dist/scw/errors/non-standard/unknown-resource-mapper.js +9 -16
  29. package/dist/scw/errors/scw-error.js +42 -39
  30. package/dist/scw/errors/standard/already-exists-error.js +20 -29
  31. package/dist/scw/errors/standard/denied-authentication-error.js +43 -34
  32. package/dist/scw/errors/standard/index.js +20 -18
  33. package/dist/scw/errors/standard/invalid-arguments-error.js +51 -50
  34. package/dist/scw/errors/standard/out-of-stock-error.js +18 -15
  35. package/dist/scw/errors/standard/permissions-denied-error.js +30 -26
  36. package/dist/scw/errors/standard/precondition-failed-error.js +32 -29
  37. package/dist/scw/errors/standard/quotas-exceeded-error.js +43 -38
  38. package/dist/scw/errors/standard/resource-expired-error.js +20 -29
  39. package/dist/scw/errors/standard/resource-locked-error.js +19 -18
  40. package/dist/scw/errors/standard/resource-not-found-error.js +19 -22
  41. package/dist/scw/errors/standard/too-many-requests-error.js +41 -54
  42. package/dist/scw/errors/standard/transient-state-error.js +20 -29
  43. package/dist/scw/errors/types.js +12 -12
  44. package/dist/scw/fetch/build-fetcher.js +49 -54
  45. package/dist/scw/fetch/http-dumper.js +50 -16
  46. package/dist/scw/fetch/http-interceptors.d.ts +1 -3
  47. package/dist/scw/fetch/http-interceptors.js +52 -34
  48. package/dist/scw/fetch/resource-paginator.js +52 -28
  49. package/dist/scw/fetch/response-parser.js +48 -49
  50. package/dist/scw/locality.js +12 -14
  51. package/dist/vendor/base64/index.js +31 -39
  52. package/package.json +1 -1
  53. package/dist/package.json.js +0 -8
@@ -1,12 +1,28 @@
1
1
  import { ConsoleLogger } from "./console-logger.js";
2
- let sdkLogger = new ConsoleLogger("silent");
2
+ var sdkLogger = new ConsoleLogger("silent");
3
+ /**
4
+ * Sets a logger to be used within the SDK.
5
+ *
6
+ * @param logger - The Logger instance
7
+ *
8
+ * @public
9
+ */
3
10
  const setLogger = (logger) => {
4
- sdkLogger = logger;
11
+ sdkLogger = logger;
5
12
  };
13
+ /**
14
+ * Sets the logger to console logger with given logLevel (log is disabled by default).
15
+ *
16
+ * @param logLevel - The Log level (default to 'warn')
17
+ * @param prefix - A Log message prefix (default to 'scaleway-sdk-js:')
18
+ *
19
+ * @public
20
+ */
6
21
  const enableConsoleLogger = (logLevel = "warn", prefix = "scaleway-sdk-js:") => setLogger(new ConsoleLogger(logLevel, prefix));
22
+ /**
23
+ * Returns the active SDK logger.
24
+ *
25
+ * @internal
26
+ */
7
27
  const getLogger = () => sdkLogger;
8
- export {
9
- enableConsoleLogger,
10
- getLogger,
11
- setLogger
12
- };
28
+ export { enableConsoleLogger, getLogger, setLogger };
@@ -1,13 +1,10 @@
1
- var LevelResolver = /* @__PURE__ */ ((LevelResolver2) => {
2
- LevelResolver2[LevelResolver2["silent"] = 0] = "silent";
3
- LevelResolver2[LevelResolver2["error"] = 1] = "error";
4
- LevelResolver2[LevelResolver2["warn"] = 2] = "warn";
5
- LevelResolver2[LevelResolver2["info"] = 3] = "info";
6
- LevelResolver2[LevelResolver2["debug"] = 4] = "debug";
7
- return LevelResolver2;
8
- })(LevelResolver || {});
1
+ let LevelResolver = /* @__PURE__ */ function(LevelResolver) {
2
+ LevelResolver[LevelResolver["silent"] = 0] = "silent";
3
+ LevelResolver[LevelResolver["error"] = 1] = "error";
4
+ LevelResolver[LevelResolver["warn"] = 2] = "warn";
5
+ LevelResolver[LevelResolver["info"] = 3] = "info";
6
+ LevelResolver[LevelResolver["debug"] = 4] = "debug";
7
+ return LevelResolver;
8
+ }({});
9
9
  const shouldLog = (currentLevel, level) => LevelResolver[level] <= currentLevel;
10
- export {
11
- LevelResolver,
12
- shouldLog
13
- };
10
+ export { LevelResolver, shouldLog };
@@ -1,30 +1,29 @@
1
- const isAccessKeyRegex = /^SCW[A-Z0-9]{17}$/i;
2
- const isRegionRegex = /^[a-z]{2}-[a-z]{3}$/i;
3
- const isUUIDRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i;
4
- const isZoneRegex = /^[a-z]{2}-[a-z]{3}-[1-9]$/i;
1
+ var isAccessKeyRegex = /^SCW[A-Z0-9]{17}$/i;
2
+ var isRegionRegex = /^[a-z]{2}-[a-z]{3}$/i;
3
+ var isUUIDRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i;
4
+ var isZoneRegex = /^[a-z]{2}-[a-z]{3}-[1-9]$/i;
5
+ /** Returns true if the given string has a valid UUID format. */
5
6
  const isUUID = (str) => isUUIDRegex.test(str);
7
+ /** Returns true if the given string has a valid Scaleway access key format. */
6
8
  const isAccessKey = (str) => isAccessKeyRegex.test(str);
9
+ /** Returns true if the given string has a valid Scaleway secret key format. */
7
10
  const isSecretKey = (str) => isUUID(str);
11
+ /** Returns true if the given string has a valid Scaleway organization ID format. */
8
12
  const isOrganizationId = (str) => isUUID(str);
13
+ /** Returns true if the given string has a valid Scaleway project ID format. */
9
14
  const isProjectId = (str) => isUUID(str);
15
+ /** Returns true if the given string has a valid region format. */
10
16
  const isRegion = (str) => isRegionRegex.test(str);
17
+ /** Returns true if the given string has a valid zone format. */
11
18
  const isZone = (str) => isZoneRegex.test(str);
19
+ /** Returns true if the given string has a valid URL format and starts by `http(s):`. */
12
20
  const isURL = (str) => {
13
- let url;
14
- try {
15
- url = new URL(str);
16
- } catch {
17
- return false;
18
- }
19
- return url.protocol === "http:" || url.protocol === "https:";
20
- };
21
- export {
22
- isAccessKey,
23
- isOrganizationId,
24
- isProjectId,
25
- isRegion,
26
- isSecretKey,
27
- isURL,
28
- isUUID,
29
- isZone
21
+ let url;
22
+ try {
23
+ url = new URL(str);
24
+ } catch {
25
+ return false;
26
+ }
27
+ return url.protocol === "http:" || url.protocol === "https:";
30
28
  };
29
+ export { isAccessKey, isOrganizationId, isProjectId, isRegion, isSecretKey, isURL, isUUID, isZone };
@@ -0,0 +1,8 @@
1
+ import "./helpers/json.js";
2
+ import "./helpers/marshalling.js";
3
+ import "./internal/async/interval-retrier.js";
4
+ import "./internal/interceptors/helpers.js";
5
+ import "./scw/api.js";
6
+ import "./scw/auth.js";
7
+ import "./scw/custom-marshalling.js";
8
+ import "./scw/fetch/resource-paginator.js";
@@ -0,0 +1,32 @@
1
+ var package_default = {
2
+ name: "@scaleway/sdk-client",
3
+ version: "2.1.0",
4
+ license: "Apache-2.0",
5
+ description: "Scaleway SDK Client",
6
+ keywords: [
7
+ "scaleway",
8
+ "cloud",
9
+ "sdk",
10
+ "client"
11
+ ],
12
+ scripts: {
13
+ "typecheck": "tsc --noEmit",
14
+ "type:generate": "tsc --declaration -p tsconfig.build.json",
15
+ "build": "vite build --config ../../vite.config.ts && pnpm run type:generate && tsc-alias -p tsconfig.build.json",
16
+ "build:profile": "npx vite-bundle-visualizer -c ../../vite.config.ts"
17
+ },
18
+ files: ["dist"],
19
+ publishConfig: { "access": "public" },
20
+ repository: {
21
+ "type": "git",
22
+ "url": "git+https://github.com/scaleway/scaleway-sdk-js",
23
+ "directory": "packages/client"
24
+ },
25
+ engines: { "node": ">=20.19.6" },
26
+ type: "module",
27
+ exports: { ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ } }
31
+ };
32
+ export { package_default as default };
package/dist/scw/api.js CHANGED
@@ -1,8 +1,11 @@
1
- class API {
2
- constructor(client) {
3
- this.client = client;
4
- }
5
- }
6
- export {
7
- API
1
+ /**
2
+ * Abstract class to instantiate API from a {@link Client}.
3
+ *
4
+ * @internal
5
+ */
6
+ var API = class {
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
8
10
  };
11
+ export { API };
package/dist/scw/auth.js CHANGED
@@ -1,25 +1,68 @@
1
1
  import { addAsyncHeaderInterceptor, addHeaderInterceptor } from "../internal/interceptors/helpers.js";
2
2
  import { assertValidAuthenticationSecrets } from "./client-ini-profile.js";
3
- import { SESSION_HEADER_KEY, AUTH_HEADER_KEY } from "./constants.js";
3
+ import { AUTH_HEADER_KEY, SESSION_HEADER_KEY } from "./constants.js";
4
+ /**
5
+ * Authentication utilities for Scaleway SDK.
6
+ *
7
+ * Note: This file uses interface call signatures instead of shorthand function types
8
+ * to maintain clear, documented public API signatures that are more readable in IDE
9
+ * tooltips and generated documentation.
10
+ */
11
+ /**
12
+ * Authenticates with a session token.
13
+ *
14
+ * @param getToken - The token accessor
15
+ * @returns The request interceptor
16
+ *
17
+ * @deprecated Please use addAsyncHeaderInterceptor instead.
18
+ *
19
+ * @internal
20
+ */
4
21
  const authenticateWithSessionToken = (getToken) => addAsyncHeaderInterceptor(SESSION_HEADER_KEY, getToken);
22
+ /**
23
+ * Authenticates with a secrets.
24
+ *
25
+ * @param getToken - The secrets
26
+ * @returns The request interceptor
27
+ *
28
+ * @throws Error
29
+ * Thrown if the secrets are invalid.
30
+ *
31
+ * @internal
32
+ */
5
33
  const authenticateWithSecrets = (secrets) => {
6
- assertValidAuthenticationSecrets(secrets);
7
- return addHeaderInterceptor(AUTH_HEADER_KEY, secrets.secretKey);
34
+ assertValidAuthenticationSecrets(secrets);
35
+ return addHeaderInterceptor(AUTH_HEADER_KEY, secrets.secretKey);
8
36
  };
37
+ /**
38
+ * Obfuscates a token.
39
+ *
40
+ * @param key - The token
41
+ * @returns The obfuscated token
42
+ *
43
+ * @internal
44
+ */
9
45
  const obfuscateToken = (key) => `${key.substring(0, 5)}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`;
46
+ /**
47
+ * Obfuscates an UUID.
48
+ *
49
+ * @param key - The UUID
50
+ * @returns The obfuscated UUID
51
+ *
52
+ * @internal
53
+ */
10
54
  const obfuscateUUID = (key) => `${key.substring(0, 8)}-xxxx-xxxx-xxxx-xxxxxxxxxxxx`;
11
- const obfuscateAuthHeadersEntry = ([
12
- name,
13
- value
14
- ]) => {
15
- if (name === SESSION_HEADER_KEY) return [name, obfuscateToken(value)];
16
- if (name === AUTH_HEADER_KEY) return [name, obfuscateUUID(value)];
17
- return [name, value];
18
- };
19
- export {
20
- authenticateWithSecrets,
21
- authenticateWithSessionToken,
22
- obfuscateAuthHeadersEntry,
23
- obfuscateToken,
24
- obfuscateUUID
55
+ /**
56
+ * Obfuscates headers entry.
57
+ *
58
+ * @param array - The header entry
59
+ * @returns The obfuscated entry
60
+ *
61
+ * @internal
62
+ */
63
+ const obfuscateAuthHeadersEntry = ([name, value]) => {
64
+ if (name === "x-session-token") return [name, obfuscateToken(value)];
65
+ if (name === "x-auth-token") return [name, obfuscateUUID(value)];
66
+ return [name, value];
25
67
  };
68
+ export { authenticateWithSecrets, authenticateWithSessionToken, obfuscateAuthHeadersEntry };
@@ -1,66 +1,136 @@
1
- import { authenticateWithSecrets } from "./auth.js";
2
1
  import { hasAuthenticationSecrets } from "./client-ini-profile.js";
2
+ import { authenticateWithSecrets } from "./auth.js";
3
+ /**
4
+ * Instantiates the SDK from a configuration {@link Profile}.
5
+ *
6
+ * @param profile - The profile
7
+ * @returns A factory {@link ClientConfig}
8
+ *
9
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
10
+ *
11
+ * @public
12
+ */
3
13
  const withProfile = (profile) => (settings) => {
4
- const newSettings = { ...settings };
5
- if (profile.apiURL) {
6
- newSettings.apiURL = profile.apiURL;
7
- }
8
- if (profile.defaultOrganizationId) {
9
- newSettings.defaultOrganizationId = profile.defaultOrganizationId;
10
- }
11
- if (profile.defaultProjectId) {
12
- newSettings.defaultProjectId = profile.defaultProjectId;
13
- }
14
- if (profile.defaultRegion) {
15
- newSettings.defaultRegion = profile.defaultRegion;
16
- }
17
- if (profile.defaultZone) {
18
- newSettings.defaultZone = profile.defaultZone;
19
- }
20
- if (hasAuthenticationSecrets(profile)) {
21
- newSettings.interceptors = [
22
- {
23
- request: authenticateWithSecrets(profile)
24
- },
25
- ...newSettings.interceptors
26
- ];
27
- }
28
- return newSettings;
14
+ const newSettings = { ...settings };
15
+ if (profile.apiURL) newSettings.apiURL = profile.apiURL;
16
+ if (profile.defaultOrganizationId) newSettings.defaultOrganizationId = profile.defaultOrganizationId;
17
+ if (profile.defaultProjectId) newSettings.defaultProjectId = profile.defaultProjectId;
18
+ if (profile.defaultRegion) newSettings.defaultRegion = profile.defaultRegion;
19
+ if (profile.defaultZone) newSettings.defaultZone = profile.defaultZone;
20
+ if (hasAuthenticationSecrets(profile)) newSettings.interceptors = [{ request: authenticateWithSecrets(profile) }, ...newSettings.interceptors];
21
+ return newSettings;
29
22
  };
30
- const withHTTPClient = (httpClient) => (settings) => ({ ...settings, httpClient });
31
- const withDefaultPageSize = (defaultPageSize) => (settings) => ({ ...settings, defaultPageSize });
32
- const withUserAgent = (userAgent) => (settings) => ({ ...settings, userAgent });
23
+ /**
24
+ * Instantiates the SDK with a different HTTP client.
25
+ *
26
+ * @param httpClient - A fetch compatible HTTP client
27
+ * @returns A factory {@link ClientConfig}
28
+ *
29
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
30
+ *
31
+ * @public
32
+ */
33
+ const withHTTPClient = (httpClient) => (settings) => ({
34
+ ...settings,
35
+ httpClient
36
+ });
37
+ /**
38
+ * Instantiates the SDK with a default page size.
39
+ *
40
+ * @param defaultPageSize - The default page size
41
+ * @returns A factory {@link ClientConfig}
42
+ *
43
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
44
+ *
45
+ * @public
46
+ */
47
+ const withDefaultPageSize = (defaultPageSize) => (settings) => ({
48
+ ...settings,
49
+ defaultPageSize
50
+ });
51
+ /**
52
+ * Instantiates the SDK with a different default user agent.
53
+ *
54
+ * @param userAgent - The default user agent
55
+ * @returns A factory {@link ClientConfig}
56
+ *
57
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
58
+ *
59
+ * @public
60
+ */
61
+ const withUserAgent = (userAgent) => (settings) => ({
62
+ ...settings,
63
+ userAgent
64
+ });
65
+ /**
66
+ * Instantiates the SDK with an additional user agent.
67
+ *
68
+ * @param userAgent - The suffix to append to default user agent
69
+ * @returns A factory {@link ClientConfig}
70
+ *
71
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
72
+ *
73
+ * @public
74
+ */
33
75
  const withUserAgentSuffix = (userAgent) => (settings) => ({
34
- ...settings,
35
- userAgent: settings.userAgent ? `${settings.userAgent} ${userAgent}` : userAgent
76
+ ...settings,
77
+ userAgent: settings.userAgent ? `${settings.userAgent} ${userAgent}` : userAgent
36
78
  });
79
+ /**
80
+ * Instantiates the SDK with additional interceptors.
81
+ *
82
+ * @param interceptors - The additional {@link NetworkInterceptors} interceptors
83
+ * @returns A factory {@link ClientConfig}
84
+ *
85
+ * @remarks
86
+ * It doesn't override the existing interceptors, but instead push more to the list.
87
+ * This method should be used in conjunction with the initializer `createAdvancedClient`.
88
+ *
89
+ * @example
90
+ * ```
91
+ * withAdditionalInterceptors([
92
+ * {
93
+ * request: ({ request }) => {
94
+ * console.log(`Do something with ${JSON.stringify(request)}`)
95
+ * return request
96
+ * },
97
+ * response: ({ response }) => {
98
+ * console.log(`Do something with ${JSON.stringify(response)}`)
99
+ * return response
100
+ * },
101
+ * responseError: async ({
102
+ * request,
103
+ * error,
104
+ * }: {
105
+ * request: Request
106
+ * error: unknown
107
+ * }) => {
108
+ * console.log(
109
+ * `Do something with ${JSON.stringify(request)} and ${JSON.stringify(
110
+ * error,
111
+ * )}`,
112
+ * )
113
+ * throw error // or return Promise.resolve(someData)
114
+ * },
115
+ * },
116
+ * ])
117
+ * ```
118
+ *
119
+ * @public
120
+ */
37
121
  const withAdditionalInterceptors = (interceptors) => (settings) => ({
38
- ...settings,
39
- interceptors: settings.interceptors.concat(interceptors)
122
+ ...settings,
123
+ interceptors: settings.interceptors.concat(interceptors)
40
124
  });
125
+ /**
126
+ * Instantiates the SDK with legacy interceptors.
127
+ */
41
128
  const withLegacyInterceptors = () => (settings) => {
42
- if (!settings.requestInterceptors && !settings.responseInterceptors) {
43
- return settings;
44
- }
45
- const allInterceptors = settings.interceptors.concat(
46
- (settings.requestInterceptors ?? []).map((obj) => ({
47
- request: obj
48
- })),
49
- (settings.responseInterceptors ?? []).map((obj) => ({
50
- response: obj
51
- }))
52
- );
53
- return {
54
- ...settings,
55
- interceptors: allInterceptors
56
- };
57
- };
58
- export {
59
- withAdditionalInterceptors,
60
- withDefaultPageSize,
61
- withHTTPClient,
62
- withLegacyInterceptors,
63
- withProfile,
64
- withUserAgent,
65
- withUserAgentSuffix
129
+ if (!settings.requestInterceptors && !settings.responseInterceptors) return settings;
130
+ const allInterceptors = settings.interceptors.concat((settings.requestInterceptors ?? []).map((obj) => ({ request: obj })), (settings.responseInterceptors ?? []).map((obj) => ({ response: obj })));
131
+ return {
132
+ ...settings,
133
+ interceptors: allInterceptors
134
+ };
66
135
  };
136
+ export { withAdditionalInterceptors, withDefaultPageSize, withHTTPClient, withLegacyInterceptors, withProfile, withUserAgent, withUserAgentSuffix };
@@ -1,23 +1,27 @@
1
1
  import { isAccessKey, isSecretKey } from "../internal/validations/string-validation.js";
2
+ /**
3
+ * Verifies that the payload contains both the accessKey and the secretKey.
4
+ *
5
+ * @param obj - The secrets
6
+ * @returns Whether the secrets are not empty.
7
+ *
8
+ * @internal
9
+ */
2
10
  const hasAuthenticationSecrets = (obj) => typeof obj.accessKey === "string" && obj.accessKey !== "" && typeof obj.secretKey === "string" && obj.secretKey !== "";
11
+ /**
12
+ * Asserts the format of secrets.
13
+ *
14
+ * @param obj - The secrets
15
+ * @returns Whether the secrets use a valid format
16
+ *
17
+ * @throws Error
18
+ * Thrown if either the accessKey or the secretKey has en invalid format.
19
+ *
20
+ * @internal
21
+ */
3
22
  function assertValidAuthenticationSecrets(obj) {
4
- if (!(obj.accessKey && obj.secretKey)) {
5
- throw new Error(
6
- `Invalid secrets, accessKey & secretKey must be defined. See https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/`
7
- );
8
- }
9
- if (!isAccessKey(obj.accessKey)) {
10
- throw new Error(
11
- `Invalid access key format '${obj.accessKey}', expected SCWXXXXXXXXXXXXXXXXX format. See https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/`
12
- );
13
- }
14
- if (!isSecretKey(obj.secretKey)) {
15
- throw new Error(
16
- `Invalid secret key format '${obj.secretKey}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. See https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/`
17
- );
18
- }
23
+ if (!(obj.accessKey && obj.secretKey)) throw new Error(`Invalid secrets, accessKey & secretKey must be defined. See https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/`);
24
+ if (!isAccessKey(obj.accessKey)) throw new Error(`Invalid access key format '${obj.accessKey}', expected SCWXXXXXXXXXXXXXXXXX format. See https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/`);
25
+ if (!isSecretKey(obj.secretKey)) throw new Error(`Invalid secret key format '${obj.secretKey}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. See https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/`);
19
26
  }
20
- export {
21
- assertValidAuthenticationSecrets,
22
- hasAuthenticationSecrets
23
- };
27
+ export { assertValidAuthenticationSecrets, hasAuthenticationSecrets };
@@ -1,51 +1,27 @@
1
- import { isOrganizationId, isProjectId, isRegion, isZone, isURL } from "../internal/validations/string-validation.js";
1
+ import { isOrganizationId, isProjectId, isRegion, isURL, isZone } from "../internal/validations/string-validation.js";
2
+ /**
3
+ * Validates the content of a {@link Settings} object.
4
+ *
5
+ * @throws Error
6
+ * Thrown if {@link Settings} aren't valid.
7
+ *
8
+ * @internal
9
+ */
2
10
  const assertValidSettings = (obj) => {
3
- if (obj.defaultOrganizationId !== void 0) {
4
- if (typeof obj.defaultOrganizationId !== "string" || obj.defaultOrganizationId.length === 0) {
5
- throw new Error("Default organization ID cannot be empty");
6
- }
7
- if (!isOrganizationId(obj.defaultOrganizationId)) {
8
- throw new Error(
9
- `Invalid organization ID format '${obj.defaultOrganizationId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`
10
- );
11
- }
12
- }
13
- if (obj.defaultProjectId !== void 0) {
14
- if (typeof obj.defaultProjectId !== "string" || obj.defaultProjectId.length === 0) {
15
- throw new Error("Default project ID cannot be empty");
16
- }
17
- if (!isProjectId(obj.defaultProjectId)) {
18
- throw new Error(
19
- `Invalid project ID format '${obj.defaultProjectId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`
20
- );
21
- }
22
- }
23
- if (obj.defaultRegion && !isRegion(obj.defaultRegion)) {
24
- throw new Error(`Invalid default region format '${obj.defaultRegion}'`);
25
- }
26
- if (obj.defaultZone && !isZone(obj.defaultZone)) {
27
- throw new Error(`Invalid default zone format '${obj.defaultZone}'`);
28
- }
29
- if (obj.apiURL && !isURL(obj.apiURL)) {
30
- throw new Error(`Invalid URL ${obj.apiURL}`);
31
- }
32
- if (obj.apiURL?.endsWith("/")) {
33
- throw new Error(
34
- `Invalid URL ${obj.apiURL}: it should not have a trailing slash`
35
- );
36
- }
37
- if (typeof obj.httpClient !== typeof fetch) {
38
- throw new Error(`Invalid HTTP Client`);
39
- }
40
- if (obj.defaultPageSize !== void 0 && (typeof obj.defaultPageSize !== "number" || Number.isNaN(obj.defaultPageSize) || obj.defaultPageSize <= 0)) {
41
- throw new Error(
42
- `Invalid defaultPageSize ${obj.defaultPageSize}: it should be a number above 0`
43
- );
44
- }
45
- if (typeof obj.userAgent !== "string") {
46
- throw new Error(`Invalid User-Agent`);
47
- }
48
- };
49
- export {
50
- assertValidSettings
11
+ if (obj.defaultOrganizationId !== void 0) {
12
+ if (typeof obj.defaultOrganizationId !== "string" || obj.defaultOrganizationId.length === 0) throw new Error("Default organization ID cannot be empty");
13
+ if (!isOrganizationId(obj.defaultOrganizationId)) throw new Error(`Invalid organization ID format '${obj.defaultOrganizationId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`);
14
+ }
15
+ if (obj.defaultProjectId !== void 0) {
16
+ if (typeof obj.defaultProjectId !== "string" || obj.defaultProjectId.length === 0) throw new Error("Default project ID cannot be empty");
17
+ if (!isProjectId(obj.defaultProjectId)) throw new Error(`Invalid project ID format '${obj.defaultProjectId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`);
18
+ }
19
+ if (obj.defaultRegion && !isRegion(obj.defaultRegion)) throw new Error(`Invalid default region format '${obj.defaultRegion}'`);
20
+ if (obj.defaultZone && !isZone(obj.defaultZone)) throw new Error(`Invalid default zone format '${obj.defaultZone}'`);
21
+ if (obj.apiURL && !isURL(obj.apiURL)) throw new Error(`Invalid URL ${obj.apiURL}`);
22
+ if (obj.apiURL?.endsWith("/")) throw new Error(`Invalid URL ${obj.apiURL}: it should not have a trailing slash`);
23
+ if (typeof obj.httpClient !== typeof fetch) throw new Error(`Invalid HTTP Client`);
24
+ if (obj.defaultPageSize !== void 0 && (typeof obj.defaultPageSize !== "number" || Number.isNaN(obj.defaultPageSize) || obj.defaultPageSize <= 0)) throw new Error(`Invalid defaultPageSize ${obj.defaultPageSize}: it should be a number above 0`);
25
+ if (typeof obj.userAgent !== "string") throw new Error(`Invalid User-Agent`);
51
26
  };
27
+ export { assertValidSettings };