@scaleway/sdk-client 1.1.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 (149) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +36 -0
  3. package/dist/bridge.d.ts +12 -0
  4. package/dist/helpers/is-browser.cjs +4 -0
  5. package/dist/helpers/is-browser.d.ts +1 -0
  6. package/dist/helpers/is-browser.js +4 -0
  7. package/dist/helpers/is-response.cjs +4 -0
  8. package/dist/helpers/is-response.d.ts +8 -0
  9. package/dist/helpers/is-response.js +4 -0
  10. package/dist/helpers/json.cjs +7 -0
  11. package/dist/helpers/json.d.ts +13 -0
  12. package/dist/helpers/json.js +7 -0
  13. package/dist/helpers/marshalling.cjs +76 -0
  14. package/dist/helpers/marshalling.d.ts +60 -0
  15. package/dist/helpers/marshalling.js +76 -0
  16. package/dist/index.cjs +52 -0
  17. package/dist/index.d.ts +15 -0
  18. package/dist/index.js +52 -0
  19. package/dist/internal/async/interval-retrier.cjs +53 -0
  20. package/dist/internal/async/interval-retrier.d.ts +111 -0
  21. package/dist/internal/async/interval-retrier.js +53 -0
  22. package/dist/internal/async/sleep.cjs +6 -0
  23. package/dist/internal/async/sleep.d.ts +9 -0
  24. package/dist/internal/async/sleep.js +6 -0
  25. package/dist/internal/interceptors/composer.cjs +25 -0
  26. package/dist/internal/interceptors/composer.d.ts +25 -0
  27. package/dist/internal/interceptors/composer.js +25 -0
  28. package/dist/internal/interceptors/helpers.cjs +12 -0
  29. package/dist/internal/interceptors/helpers.d.ts +21 -0
  30. package/dist/internal/interceptors/helpers.js +12 -0
  31. package/dist/internal/interceptors/types.d.ts +89 -0
  32. package/dist/internal/logger/console-logger.cjs +24 -0
  33. package/dist/internal/logger/console-logger.d.ts +23 -0
  34. package/dist/internal/logger/console-logger.js +24 -0
  35. package/dist/internal/logger/index.cjs +12 -0
  36. package/dist/internal/logger/index.d.ts +25 -0
  37. package/dist/internal/logger/index.js +12 -0
  38. package/dist/internal/logger/level-resolver.cjs +13 -0
  39. package/dist/internal/logger/level-resolver.d.ts +9 -0
  40. package/dist/internal/logger/level-resolver.js +13 -0
  41. package/dist/internal/logger/logger.d.ts +13 -0
  42. package/dist/internal/validations/string-validation.cjs +30 -0
  43. package/dist/internal/validations/string-validation.d.ts +18 -0
  44. package/dist/internal/validations/string-validation.js +30 -0
  45. package/dist/internals.d.ts +10 -0
  46. package/dist/package.json.cjs +67 -0
  47. package/dist/package.json.js +67 -0
  48. package/dist/scw/api.cjs +8 -0
  49. package/dist/scw/api.d.ts +10 -0
  50. package/dist/scw/api.js +8 -0
  51. package/dist/scw/auth.cjs +26 -0
  52. package/dist/scw/auth.d.ts +57 -0
  53. package/dist/scw/auth.js +26 -0
  54. package/dist/scw/client-ini-factory.cjs +66 -0
  55. package/dist/scw/client-ini-factory.d.ts +111 -0
  56. package/dist/scw/client-ini-factory.js +66 -0
  57. package/dist/scw/client-ini-profile.cjs +23 -0
  58. package/dist/scw/client-ini-profile.d.ts +82 -0
  59. package/dist/scw/client-ini-profile.js +23 -0
  60. package/dist/scw/client-settings.cjs +51 -0
  61. package/dist/scw/client-settings.d.ts +59 -0
  62. package/dist/scw/client-settings.js +51 -0
  63. package/dist/scw/client.cjs +31 -0
  64. package/dist/scw/client.d.ts +71 -0
  65. package/dist/scw/client.js +31 -0
  66. package/dist/scw/constants.cjs +7 -0
  67. package/dist/scw/constants.d.ts +2 -0
  68. package/dist/scw/constants.js +7 -0
  69. package/dist/scw/custom-marshalling.cjs +126 -0
  70. package/dist/scw/custom-marshalling.d.ts +80 -0
  71. package/dist/scw/custom-marshalling.js +126 -0
  72. package/dist/scw/custom-types.cjs +11 -0
  73. package/dist/scw/custom-types.d.ts +74 -0
  74. package/dist/scw/custom-types.js +11 -0
  75. package/dist/scw/errors/error-parser.cjs +76 -0
  76. package/dist/scw/errors/error-parser.d.ts +12 -0
  77. package/dist/scw/errors/error-parser.js +76 -0
  78. package/dist/scw/errors/non-standard/invalid-request-mapper.cjs +36 -0
  79. package/dist/scw/errors/non-standard/invalid-request-mapper.d.ts +12 -0
  80. package/dist/scw/errors/non-standard/invalid-request-mapper.js +36 -0
  81. package/dist/scw/errors/non-standard/unknown-resource-mapper.cjs +23 -0
  82. package/dist/scw/errors/non-standard/unknown-resource-mapper.d.ts +11 -0
  83. package/dist/scw/errors/non-standard/unknown-resource-mapper.js +23 -0
  84. package/dist/scw/errors/scw-error-from-json.d.ts +10 -0
  85. package/dist/scw/errors/scw-error.cjs +43 -0
  86. package/dist/scw/errors/scw-error.d.ts +25 -0
  87. package/dist/scw/errors/scw-error.js +43 -0
  88. package/dist/scw/errors/standard/already-exists-error.cjs +31 -0
  89. package/dist/scw/errors/standard/already-exists-error.d.ts +16 -0
  90. package/dist/scw/errors/standard/already-exists-error.js +31 -0
  91. package/dist/scw/errors/standard/denied-authentication-error.cjs +37 -0
  92. package/dist/scw/errors/standard/denied-authentication-error.d.ts +15 -0
  93. package/dist/scw/errors/standard/denied-authentication-error.js +37 -0
  94. package/dist/scw/errors/standard/index.cjs +28 -0
  95. package/dist/scw/errors/standard/index.d.ts +17 -0
  96. package/dist/scw/errors/standard/index.js +28 -0
  97. package/dist/scw/errors/standard/invalid-arguments-error.cjs +54 -0
  98. package/dist/scw/errors/standard/invalid-arguments-error.d.ts +24 -0
  99. package/dist/scw/errors/standard/invalid-arguments-error.js +54 -0
  100. package/dist/scw/errors/standard/out-of-stock-error.cjs +17 -0
  101. package/dist/scw/errors/standard/out-of-stock-error.d.ts +14 -0
  102. package/dist/scw/errors/standard/out-of-stock-error.js +17 -0
  103. package/dist/scw/errors/standard/permissions-denied-error.cjs +29 -0
  104. package/dist/scw/errors/standard/permissions-denied-error.d.ts +23 -0
  105. package/dist/scw/errors/standard/permissions-denied-error.js +29 -0
  106. package/dist/scw/errors/standard/precondition-failed-error.cjs +32 -0
  107. package/dist/scw/errors/standard/precondition-failed-error.d.ts +15 -0
  108. package/dist/scw/errors/standard/precondition-failed-error.js +32 -0
  109. package/dist/scw/errors/standard/quotas-exceeded-error.cjs +43 -0
  110. package/dist/scw/errors/standard/quotas-exceeded-error.d.ts +34 -0
  111. package/dist/scw/errors/standard/quotas-exceeded-error.js +43 -0
  112. package/dist/scw/errors/standard/resource-expired-error.cjs +31 -0
  113. package/dist/scw/errors/standard/resource-expired-error.d.ts +16 -0
  114. package/dist/scw/errors/standard/resource-expired-error.js +31 -0
  115. package/dist/scw/errors/standard/resource-locked-error.cjs +20 -0
  116. package/dist/scw/errors/standard/resource-locked-error.d.ts +15 -0
  117. package/dist/scw/errors/standard/resource-locked-error.js +20 -0
  118. package/dist/scw/errors/standard/resource-not-found-error.cjs +24 -0
  119. package/dist/scw/errors/standard/resource-not-found-error.d.ts +15 -0
  120. package/dist/scw/errors/standard/resource-not-found-error.js +24 -0
  121. package/dist/scw/errors/standard/too-many-requests-error.cjs +58 -0
  122. package/dist/scw/errors/standard/too-many-requests-error.d.ts +32 -0
  123. package/dist/scw/errors/standard/too-many-requests-error.js +58 -0
  124. package/dist/scw/errors/standard/transient-state-error.cjs +31 -0
  125. package/dist/scw/errors/standard/transient-state-error.d.ts +16 -0
  126. package/dist/scw/errors/standard/transient-state-error.js +31 -0
  127. package/dist/scw/errors/types.cjs +15 -0
  128. package/dist/scw/errors/types.d.ts +9 -0
  129. package/dist/scw/errors/types.js +15 -0
  130. package/dist/scw/fetch/build-fetcher.cjs +60 -0
  131. package/dist/scw/fetch/build-fetcher.d.ts +23 -0
  132. package/dist/scw/fetch/build-fetcher.js +60 -0
  133. package/dist/scw/fetch/http-dumper.cjs +20 -0
  134. package/dist/scw/fetch/http-dumper.d.ts +18 -0
  135. package/dist/scw/fetch/http-dumper.js +20 -0
  136. package/dist/scw/fetch/http-interceptors.cjs +43 -0
  137. package/dist/scw/fetch/http-interceptors.d.ts +38 -0
  138. package/dist/scw/fetch/http-interceptors.js +43 -0
  139. package/dist/scw/fetch/resource-paginator.cjs +36 -0
  140. package/dist/scw/fetch/resource-paginator.d.ts +47 -0
  141. package/dist/scw/fetch/resource-paginator.js +36 -0
  142. package/dist/scw/fetch/response-parser.cjs +55 -0
  143. package/dist/scw/fetch/response-parser.d.ts +25 -0
  144. package/dist/scw/fetch/response-parser.js +55 -0
  145. package/dist/scw/fetch/types.d.ts +16 -0
  146. package/dist/scw/locality.d.ts +2 -0
  147. package/dist/vendor/base64/index.cjs +42 -0
  148. package/dist/vendor/base64/index.js +42 -0
  149. package/package.json +37 -0
@@ -0,0 +1,18 @@
1
+ /** Returns true if the given string has a valid UUID format. */
2
+ export declare const isUUID: (str: string) => boolean;
3
+ /** Returns true if the given string has a valid Scaleway access key format. */
4
+ export declare const isAccessKey: (str: string) => boolean;
5
+ /** Returns true if the given string has a valid Scaleway secret key format. */
6
+ export declare const isSecretKey: (str: string) => boolean;
7
+ /** Returns true if the given string has a valid Scaleway organization ID format. */
8
+ export declare const isOrganizationId: (str: string) => boolean;
9
+ /** Returns true if the given string has a valid Scaleway project ID format. */
10
+ export declare const isProjectId: (str: string) => boolean;
11
+ /** Returns true if the given string has a valid region format. */
12
+ export declare const isRegion: (str: string) => boolean;
13
+ /** Returns true if the given string has a valid zone format. */
14
+ export declare const isZone: (str: string) => boolean;
15
+ /** Returns true if the given string has a valid URL format and starts by `http(s):`. */
16
+ export declare const isURL: (str: string) => boolean;
17
+ /** Returns true if the given string has an email format. */
18
+ export declare const isEmail: (str: string) => boolean;
@@ -0,0 +1,30 @@
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;
5
+ const isUUID = (str) => isUUIDRegex.test(str);
6
+ const isAccessKey = (str) => isAccessKeyRegex.test(str);
7
+ const isSecretKey = (str) => isUUID(str);
8
+ const isOrganizationId = (str) => isUUID(str);
9
+ const isProjectId = (str) => isUUID(str);
10
+ const isRegion = (str) => isRegionRegex.test(str);
11
+ const isZone = (str) => isZoneRegex.test(str);
12
+ 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
30
+ };
@@ -0,0 +1,10 @@
1
+ export { isJSONObject } from './helpers/json.js';
2
+ export { createExponentialBackoffStrategy, tryAtIntervals, waitForResource, } from './internal/async/interval-retrier.js';
3
+ export { addAsyncHeaderInterceptor } from './internal/interceptors/helpers.js';
4
+ export { API } from './scw/api.js';
5
+ export { authenticateWithSessionToken } from './scw/auth.js';
6
+ export type { DefaultValues } from './scw/client-settings.js';
7
+ export { marshalDecimal, marshalScwFile, marshalMoney, marshalTimeSeries, marshalBlobToScwFile, unmarshalDecimal, unmarshalMoney, unmarshalScwFile, unmarshalServiceInfo, unmarshalTimeSeries, unmarshalTimeSeriesPoint, } from './scw/custom-marshalling.js';
8
+ export type { ServiceInfo } from './scw/custom-types.js';
9
+ export { resolveOneOf, unmarshalDate, unmarshalArrayOfObject, unmarshalMapOfObject, urlParams, validatePathParam, } from './helpers/marshalling.js';
10
+ export { enrichForPagination } from './scw/fetch/resource-paginator.js';
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const name = "@scaleway/sdk-client";
4
+ const version = "1.0.0";
5
+ const license = "Apache-2.0";
6
+ const description = "Scaleway SDK Client";
7
+ const keywords = [
8
+ "scaleway",
9
+ "cloud",
10
+ "sdk",
11
+ "client"
12
+ ];
13
+ const main = "dist/index.cjs";
14
+ const module$1 = "dist/index.js";
15
+ const types = "dist/index.d.ts";
16
+ const scripts = {
17
+ typecheck: "tsc --noEmit",
18
+ "type:generate": "tsc --declaration -p tsconfig.build.json",
19
+ build: "vite build --config ../../vite.config.ts && pnpm run type:generate && tsc-alias -p tsconfig.build.json",
20
+ "build:profile": "npx vite-bundle-visualizer -c ../../vite.config.ts"
21
+ };
22
+ const files = [
23
+ "dist"
24
+ ];
25
+ const publishConfig = {
26
+ access: "public"
27
+ };
28
+ const repository = {
29
+ type: "git",
30
+ url: "https://github.com/scaleway/scaleway-sdk-js",
31
+ directory: "packages/client"
32
+ };
33
+ const engines = {
34
+ node: ">=18.0"
35
+ };
36
+ const type = "module";
37
+ const pkg = {
38
+ name,
39
+ version,
40
+ license,
41
+ description,
42
+ keywords,
43
+ main,
44
+ module: module$1,
45
+ types,
46
+ scripts,
47
+ files,
48
+ publishConfig,
49
+ repository,
50
+ engines,
51
+ type
52
+ };
53
+ exports.default = pkg;
54
+ exports.description = description;
55
+ exports.engines = engines;
56
+ exports.files = files;
57
+ exports.keywords = keywords;
58
+ exports.license = license;
59
+ exports.main = main;
60
+ exports.module = module$1;
61
+ exports.name = name;
62
+ exports.publishConfig = publishConfig;
63
+ exports.repository = repository;
64
+ exports.scripts = scripts;
65
+ exports.type = type;
66
+ exports.types = types;
67
+ exports.version = version;
@@ -0,0 +1,67 @@
1
+ const name = "@scaleway/sdk-client";
2
+ const version = "1.0.0";
3
+ const license = "Apache-2.0";
4
+ const description = "Scaleway SDK Client";
5
+ const keywords = [
6
+ "scaleway",
7
+ "cloud",
8
+ "sdk",
9
+ "client"
10
+ ];
11
+ const main = "dist/index.cjs";
12
+ const module = "dist/index.js";
13
+ const types = "dist/index.d.ts";
14
+ const scripts = {
15
+ typecheck: "tsc --noEmit",
16
+ "type:generate": "tsc --declaration -p tsconfig.build.json",
17
+ build: "vite build --config ../../vite.config.ts && pnpm run type:generate && tsc-alias -p tsconfig.build.json",
18
+ "build:profile": "npx vite-bundle-visualizer -c ../../vite.config.ts"
19
+ };
20
+ const files = [
21
+ "dist"
22
+ ];
23
+ const publishConfig = {
24
+ access: "public"
25
+ };
26
+ const repository = {
27
+ type: "git",
28
+ url: "https://github.com/scaleway/scaleway-sdk-js",
29
+ directory: "packages/client"
30
+ };
31
+ const engines = {
32
+ node: ">=18.0"
33
+ };
34
+ const type = "module";
35
+ const pkg = {
36
+ name,
37
+ version,
38
+ license,
39
+ description,
40
+ keywords,
41
+ main,
42
+ module,
43
+ types,
44
+ scripts,
45
+ files,
46
+ publishConfig,
47
+ repository,
48
+ engines,
49
+ type
50
+ };
51
+ export {
52
+ pkg as default,
53
+ description,
54
+ engines,
55
+ files,
56
+ keywords,
57
+ license,
58
+ main,
59
+ module,
60
+ name,
61
+ publishConfig,
62
+ repository,
63
+ scripts,
64
+ type,
65
+ types,
66
+ version
67
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ class API {
4
+ constructor(client) {
5
+ this.client = client;
6
+ }
7
+ }
8
+ exports.API = API;
@@ -0,0 +1,10 @@
1
+ import type { Client } from './client.js';
2
+ /**
3
+ * Abstract class to instantiate API from a {@link Client}.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare abstract class API {
8
+ protected client: Client;
9
+ constructor(client: Client);
10
+ }
@@ -0,0 +1,8 @@
1
+ class API {
2
+ constructor(client) {
3
+ this.client = client;
4
+ }
5
+ }
6
+ export {
7
+ API
8
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const helpers = require("../internal/interceptors/helpers.cjs");
4
+ const clientIniProfile = require("./client-ini-profile.cjs");
5
+ const SESSION_HEADER_KEY = "x-session-token";
6
+ const AUTH_HEADER_KEY = "x-auth-token";
7
+ const authenticateWithSessionToken = (getToken) => helpers.addAsyncHeaderInterceptor(SESSION_HEADER_KEY, getToken);
8
+ const authenticateWithSecrets = (secrets) => {
9
+ clientIniProfile.assertValidAuthenticationSecrets(secrets);
10
+ return helpers.addHeaderInterceptor(AUTH_HEADER_KEY, secrets.secretKey);
11
+ };
12
+ const obfuscateToken = (key) => `${key.substring(0, 5)}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`;
13
+ const obfuscateUUID = (key) => `${key.substring(0, 8)}-xxxx-xxxx-xxxx-xxxxxxxxxxxx`;
14
+ const obfuscateAuthHeadersEntry = ([
15
+ name,
16
+ value
17
+ ]) => {
18
+ if (name === SESSION_HEADER_KEY) return [name, obfuscateToken(value)];
19
+ if (name === AUTH_HEADER_KEY) return [name, obfuscateUUID(value)];
20
+ return [name, value];
21
+ };
22
+ exports.authenticateWithSecrets = authenticateWithSecrets;
23
+ exports.authenticateWithSessionToken = authenticateWithSessionToken;
24
+ exports.obfuscateAuthHeadersEntry = obfuscateAuthHeadersEntry;
25
+ exports.obfuscateToken = obfuscateToken;
26
+ exports.obfuscateUUID = obfuscateUUID;
@@ -0,0 +1,57 @@
1
+ import type { RequestInterceptor } from '../internal/interceptors/types';
2
+ import type { AuthenticationSecrets } from './client-ini-profile.js';
3
+ interface TokenAccessor {
4
+ (): Promise<string | undefined>;
5
+ }
6
+ /**
7
+ * Authenticates with a session token.
8
+ *
9
+ * @param getToken - The token accessor
10
+ * @returns The request interceptor
11
+ *
12
+ * @deprecated Please use addAsyncHeaderInterceptor instead.
13
+ *
14
+ * @internal
15
+ */
16
+ export declare const authenticateWithSessionToken: (getToken: TokenAccessor) => RequestInterceptor;
17
+ /**
18
+ * Authenticates with a secrets.
19
+ *
20
+ * @param getToken - The secrets
21
+ * @returns The request interceptor
22
+ *
23
+ * @throws Error
24
+ * Thrown if the secrets are invalid.
25
+ *
26
+ * @internal
27
+ */
28
+ export declare const authenticateWithSecrets: (secrets: AuthenticationSecrets) => RequestInterceptor;
29
+ /**
30
+ * Obfuscates a token.
31
+ *
32
+ * @param key - The token
33
+ * @returns The obfuscated token
34
+ *
35
+ * @internal
36
+ */
37
+ export declare const obfuscateToken: (key: string) => string;
38
+ /**
39
+ * Obfuscates an UUID.
40
+ *
41
+ * @param key - The UUID
42
+ * @returns The obfuscated UUID
43
+ *
44
+ * @internal
45
+ */
46
+ export declare const obfuscateUUID: (key: string) => string;
47
+ type HeaderEntry = [string, string];
48
+ /**
49
+ * Obfuscates headers entry.
50
+ *
51
+ * @param array - The header entry
52
+ * @returns The obfuscated entry
53
+ *
54
+ * @internal
55
+ */
56
+ export declare const obfuscateAuthHeadersEntry: ([name, value,]: HeaderEntry) => HeaderEntry;
57
+ export {};
@@ -0,0 +1,26 @@
1
+ import { addAsyncHeaderInterceptor, addHeaderInterceptor } from "../internal/interceptors/helpers.js";
2
+ import { assertValidAuthenticationSecrets } from "./client-ini-profile.js";
3
+ const SESSION_HEADER_KEY = "x-session-token";
4
+ const AUTH_HEADER_KEY = "x-auth-token";
5
+ const authenticateWithSessionToken = (getToken) => addAsyncHeaderInterceptor(SESSION_HEADER_KEY, getToken);
6
+ const authenticateWithSecrets = (secrets) => {
7
+ assertValidAuthenticationSecrets(secrets);
8
+ return addHeaderInterceptor(AUTH_HEADER_KEY, secrets.secretKey);
9
+ };
10
+ const obfuscateToken = (key) => `${key.substring(0, 5)}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`;
11
+ const obfuscateUUID = (key) => `${key.substring(0, 8)}-xxxx-xxxx-xxxx-xxxxxxxxxxxx`;
12
+ const obfuscateAuthHeadersEntry = ([
13
+ name,
14
+ value
15
+ ]) => {
16
+ if (name === SESSION_HEADER_KEY) return [name, obfuscateToken(value)];
17
+ if (name === AUTH_HEADER_KEY) return [name, obfuscateUUID(value)];
18
+ return [name, value];
19
+ };
20
+ export {
21
+ authenticateWithSecrets,
22
+ authenticateWithSessionToken,
23
+ obfuscateAuthHeadersEntry,
24
+ obfuscateToken,
25
+ obfuscateUUID
26
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const auth = require("./auth.cjs");
4
+ const clientIniProfile = require("./client-ini-profile.cjs");
5
+ const withProfile = (profile) => (settings) => {
6
+ const newSettings = { ...settings };
7
+ if (profile.apiURL) {
8
+ newSettings.apiURL = profile.apiURL;
9
+ }
10
+ if (profile.defaultOrganizationId) {
11
+ newSettings.defaultOrganizationId = profile.defaultOrganizationId;
12
+ }
13
+ if (profile.defaultProjectId) {
14
+ newSettings.defaultProjectId = profile.defaultProjectId;
15
+ }
16
+ if (profile.defaultRegion) {
17
+ newSettings.defaultRegion = profile.defaultRegion;
18
+ }
19
+ if (profile.defaultZone) {
20
+ newSettings.defaultZone = profile.defaultZone;
21
+ }
22
+ if (clientIniProfile.hasAuthenticationSecrets(profile)) {
23
+ newSettings.interceptors = [
24
+ {
25
+ request: auth.authenticateWithSecrets(profile)
26
+ },
27
+ ...newSettings.interceptors
28
+ ];
29
+ }
30
+ return newSettings;
31
+ };
32
+ const withHTTPClient = (httpClient) => (settings) => ({ ...settings, httpClient });
33
+ const withDefaultPageSize = (defaultPageSize) => (settings) => ({ ...settings, defaultPageSize });
34
+ const withUserAgent = (userAgent) => (settings) => ({ ...settings, userAgent });
35
+ const withUserAgentSuffix = (userAgent) => (settings) => ({
36
+ ...settings,
37
+ userAgent: settings.userAgent ? `${settings.userAgent} ${userAgent}` : userAgent
38
+ });
39
+ const withAdditionalInterceptors = (interceptors) => (settings) => ({
40
+ ...settings,
41
+ interceptors: settings.interceptors.concat(interceptors)
42
+ });
43
+ const withLegacyInterceptors = () => (settings) => {
44
+ if (!settings.requestInterceptors && !settings.responseInterceptors) {
45
+ return settings;
46
+ }
47
+ const allInterceptors = settings.interceptors.concat(
48
+ (settings.requestInterceptors ?? []).map((obj) => ({
49
+ request: obj
50
+ })),
51
+ (settings.responseInterceptors ?? []).map((obj) => ({
52
+ response: obj
53
+ }))
54
+ );
55
+ return {
56
+ ...settings,
57
+ interceptors: allInterceptors
58
+ };
59
+ };
60
+ exports.withAdditionalInterceptors = withAdditionalInterceptors;
61
+ exports.withDefaultPageSize = withDefaultPageSize;
62
+ exports.withHTTPClient = withHTTPClient;
63
+ exports.withLegacyInterceptors = withLegacyInterceptors;
64
+ exports.withProfile = withProfile;
65
+ exports.withUserAgent = withUserAgent;
66
+ exports.withUserAgentSuffix = withUserAgentSuffix;
@@ -0,0 +1,111 @@
1
+ import type { NetworkInterceptors } from '../index.js';
2
+ import type { Profile } from './client-ini-profile.js';
3
+ import type { Settings } from './client-settings.js';
4
+ /**
5
+ * A factory to build {@link Settings}.
6
+ *
7
+ * @public
8
+ */
9
+ export type ClientConfig = (obj: Settings) => Settings;
10
+ /**
11
+ * Instantiates the SDK from a configuration {@link Profile}.
12
+ *
13
+ * @param profile - The profile
14
+ * @returns A factory {@link ClientConfig}
15
+ *
16
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
17
+ *
18
+ * @public
19
+ */
20
+ export declare const withProfile: (profile: Readonly<Profile>) => (settings: Readonly<Settings>) => Settings;
21
+ /**
22
+ * Instantiates the SDK with a different HTTP client.
23
+ *
24
+ * @param httpClient - A fetch compatible HTTP client
25
+ * @returns A factory {@link ClientConfig}
26
+ *
27
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
28
+ *
29
+ * @public
30
+ */
31
+ export declare const withHTTPClient: (httpClient: typeof fetch) => (settings: Readonly<Settings>) => Settings;
32
+ /**
33
+ * Instantiates the SDK with a default page size.
34
+ *
35
+ * @param defaultPageSize - The default page size
36
+ * @returns A factory {@link ClientConfig}
37
+ *
38
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
39
+ *
40
+ * @public
41
+ */
42
+ export declare const withDefaultPageSize: (defaultPageSize: number) => ClientConfig;
43
+ /**
44
+ * Instantiates the SDK with a different default user agent.
45
+ *
46
+ * @param userAgent - The default user agent
47
+ * @returns A factory {@link ClientConfig}
48
+ *
49
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
50
+ *
51
+ * @public
52
+ */
53
+ export declare const withUserAgent: (userAgent: string) => (settings: Readonly<Settings>) => Settings;
54
+ /**
55
+ * Instantiates the SDK with an additional user agent.
56
+ *
57
+ * @param userAgent - The suffix to append to default user agent
58
+ * @returns A factory {@link ClientConfig}
59
+ *
60
+ * @remarks This method should be used in conjunction with the initializer `createAdvancedClient`.
61
+ *
62
+ * @public
63
+ */
64
+ export declare const withUserAgentSuffix: (userAgent: string) => (settings: Readonly<Settings>) => Settings;
65
+ /**
66
+ * Instantiates the SDK with additional interceptors.
67
+ *
68
+ * @param interceptors - The additional {@link NetworkInterceptors} interceptors
69
+ * @returns A factory {@link ClientConfig}
70
+ *
71
+ * @remarks
72
+ * It doesn't override the existing interceptors, but instead push more to the list.
73
+ * This method should be used in conjunction with the initializer `createAdvancedClient`.
74
+ *
75
+ * @example
76
+ * ```
77
+ * withAdditionalInterceptors([
78
+ * {
79
+ * request: ({ request }) => {
80
+ * console.log(`Do something with ${JSON.stringify(request)}`)
81
+ * return request
82
+ * },
83
+ * response: ({ response }) => {
84
+ * console.log(`Do something with ${JSON.stringify(response)}`)
85
+ * return response
86
+ * },
87
+ * responseError: async ({
88
+ * request,
89
+ * error,
90
+ * }: {
91
+ * request: Request
92
+ * error: unknown
93
+ * }) => {
94
+ * console.log(
95
+ * `Do something with ${JSON.stringify(request)} and ${JSON.stringify(
96
+ * error,
97
+ * )}`,
98
+ * )
99
+ * throw error // or return Promise.resolve(someData)
100
+ * },
101
+ * },
102
+ * ])
103
+ * ```
104
+ *
105
+ * @public
106
+ */
107
+ export declare const withAdditionalInterceptors: (interceptors: NetworkInterceptors[]) => (settings: Readonly<Settings>) => Settings;
108
+ /**
109
+ * Instantiates the SDK with legacy interceptors.
110
+ */
111
+ export declare const withLegacyInterceptors: () => (settings: Readonly<Settings>) => Settings;
@@ -0,0 +1,66 @@
1
+ import { authenticateWithSecrets } from "./auth.js";
2
+ import { hasAuthenticationSecrets } from "./client-ini-profile.js";
3
+ 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;
29
+ };
30
+ const withHTTPClient = (httpClient) => (settings) => ({ ...settings, httpClient });
31
+ const withDefaultPageSize = (defaultPageSize) => (settings) => ({ ...settings, defaultPageSize });
32
+ const withUserAgent = (userAgent) => (settings) => ({ ...settings, userAgent });
33
+ const withUserAgentSuffix = (userAgent) => (settings) => ({
34
+ ...settings,
35
+ userAgent: settings.userAgent ? `${settings.userAgent} ${userAgent}` : userAgent
36
+ });
37
+ const withAdditionalInterceptors = (interceptors) => (settings) => ({
38
+ ...settings,
39
+ interceptors: settings.interceptors.concat(interceptors)
40
+ });
41
+ 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
66
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const stringValidation = require("../internal/validations/string-validation.cjs");
4
+ const hasAuthenticationSecrets = (obj) => typeof obj.accessKey === "string" && obj.accessKey !== "" && typeof obj.secretKey === "string" && obj.secretKey !== "";
5
+ function assertValidAuthenticationSecrets(obj) {
6
+ if (!(obj.accessKey && obj.secretKey)) {
7
+ throw new Error(
8
+ `Invalid secrets, accessKey & secretKey must be defined. See https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/`
9
+ );
10
+ }
11
+ if (!stringValidation.isAccessKey(obj.accessKey)) {
12
+ throw new Error(
13
+ `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/`
14
+ );
15
+ }
16
+ if (!stringValidation.isSecretKey(obj.secretKey)) {
17
+ throw new Error(
18
+ `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
+ );
20
+ }
21
+ }
22
+ exports.assertValidAuthenticationSecrets = assertValidAuthenticationSecrets;
23
+ exports.hasAuthenticationSecrets = hasAuthenticationSecrets;