@scaleway/sdk-std 1.0.1

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 (154) hide show
  1. package/LICENSE +191 -0
  2. package/dist/index.gen.cjs +1 -0
  3. package/dist/index.gen.d.ts +1 -0
  4. package/dist/index.gen.js +1 -0
  5. package/dist/types.gen.d.ts +2 -0
  6. package/node_modules/@scaleway/sdk-client/README.md +36 -0
  7. package/node_modules/@scaleway/sdk-client/dist/bridge.d.ts +12 -0
  8. package/node_modules/@scaleway/sdk-client/dist/helpers/is-browser.cjs +4 -0
  9. package/node_modules/@scaleway/sdk-client/dist/helpers/is-browser.d.ts +1 -0
  10. package/node_modules/@scaleway/sdk-client/dist/helpers/is-browser.js +4 -0
  11. package/node_modules/@scaleway/sdk-client/dist/helpers/is-response.cjs +4 -0
  12. package/node_modules/@scaleway/sdk-client/dist/helpers/is-response.d.ts +8 -0
  13. package/node_modules/@scaleway/sdk-client/dist/helpers/is-response.js +4 -0
  14. package/node_modules/@scaleway/sdk-client/dist/helpers/json.cjs +47 -0
  15. package/node_modules/@scaleway/sdk-client/dist/helpers/json.d.ts +32 -0
  16. package/node_modules/@scaleway/sdk-client/dist/helpers/json.js +47 -0
  17. package/node_modules/@scaleway/sdk-client/dist/helpers/marshalling.cjs +76 -0
  18. package/node_modules/@scaleway/sdk-client/dist/helpers/marshalling.d.ts +60 -0
  19. package/node_modules/@scaleway/sdk-client/dist/helpers/marshalling.js +76 -0
  20. package/node_modules/@scaleway/sdk-client/dist/index.cjs +56 -0
  21. package/node_modules/@scaleway/sdk-client/dist/index.d.ts +16 -0
  22. package/node_modules/@scaleway/sdk-client/dist/index.js +56 -0
  23. package/node_modules/@scaleway/sdk-client/dist/internal/async/interval-retrier.cjs +53 -0
  24. package/node_modules/@scaleway/sdk-client/dist/internal/async/interval-retrier.d.ts +111 -0
  25. package/node_modules/@scaleway/sdk-client/dist/internal/async/interval-retrier.js +53 -0
  26. package/node_modules/@scaleway/sdk-client/dist/internal/async/sleep.cjs +6 -0
  27. package/node_modules/@scaleway/sdk-client/dist/internal/async/sleep.d.ts +9 -0
  28. package/node_modules/@scaleway/sdk-client/dist/internal/async/sleep.js +6 -0
  29. package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/composer.cjs +25 -0
  30. package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/composer.d.ts +25 -0
  31. package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/composer.js +25 -0
  32. package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/helpers.cjs +12 -0
  33. package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/helpers.d.ts +21 -0
  34. package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/helpers.js +12 -0
  35. package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/types.d.ts +89 -0
  36. package/node_modules/@scaleway/sdk-client/dist/internal/logger/console-logger.cjs +24 -0
  37. package/node_modules/@scaleway/sdk-client/dist/internal/logger/console-logger.d.ts +23 -0
  38. package/node_modules/@scaleway/sdk-client/dist/internal/logger/console-logger.js +24 -0
  39. package/node_modules/@scaleway/sdk-client/dist/internal/logger/index.cjs +12 -0
  40. package/node_modules/@scaleway/sdk-client/dist/internal/logger/index.d.ts +25 -0
  41. package/node_modules/@scaleway/sdk-client/dist/internal/logger/index.js +12 -0
  42. package/node_modules/@scaleway/sdk-client/dist/internal/logger/level-resolver.cjs +13 -0
  43. package/node_modules/@scaleway/sdk-client/dist/internal/logger/level-resolver.d.ts +9 -0
  44. package/node_modules/@scaleway/sdk-client/dist/internal/logger/level-resolver.js +13 -0
  45. package/node_modules/@scaleway/sdk-client/dist/internal/logger/logger.d.ts +13 -0
  46. package/node_modules/@scaleway/sdk-client/dist/internal/validations/string-validation.cjs +30 -0
  47. package/node_modules/@scaleway/sdk-client/dist/internal/validations/string-validation.d.ts +18 -0
  48. package/node_modules/@scaleway/sdk-client/dist/internal/validations/string-validation.js +30 -0
  49. package/node_modules/@scaleway/sdk-client/dist/internals.d.ts +10 -0
  50. package/node_modules/@scaleway/sdk-client/dist/package.json.cjs +8 -0
  51. package/node_modules/@scaleway/sdk-client/dist/package.json.js +8 -0
  52. package/node_modules/@scaleway/sdk-client/dist/scw/api.cjs +8 -0
  53. package/node_modules/@scaleway/sdk-client/dist/scw/api.d.ts +10 -0
  54. package/node_modules/@scaleway/sdk-client/dist/scw/api.js +8 -0
  55. package/node_modules/@scaleway/sdk-client/dist/scw/auth.cjs +25 -0
  56. package/node_modules/@scaleway/sdk-client/dist/scw/auth.d.ts +70 -0
  57. package/node_modules/@scaleway/sdk-client/dist/scw/auth.js +25 -0
  58. package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-factory.cjs +66 -0
  59. package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-factory.d.ts +111 -0
  60. package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-factory.js +66 -0
  61. package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-profile.cjs +23 -0
  62. package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-profile.d.ts +82 -0
  63. package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-profile.js +23 -0
  64. package/node_modules/@scaleway/sdk-client/dist/scw/client-settings.cjs +51 -0
  65. package/node_modules/@scaleway/sdk-client/dist/scw/client-settings.d.ts +59 -0
  66. package/node_modules/@scaleway/sdk-client/dist/scw/client-settings.js +51 -0
  67. package/node_modules/@scaleway/sdk-client/dist/scw/client.cjs +31 -0
  68. package/node_modules/@scaleway/sdk-client/dist/scw/client.d.ts +71 -0
  69. package/node_modules/@scaleway/sdk-client/dist/scw/client.js +31 -0
  70. package/node_modules/@scaleway/sdk-client/dist/scw/constants.cjs +11 -0
  71. package/node_modules/@scaleway/sdk-client/dist/scw/constants.d.ts +4 -0
  72. package/node_modules/@scaleway/sdk-client/dist/scw/constants.js +11 -0
  73. package/node_modules/@scaleway/sdk-client/dist/scw/custom-marshalling.cjs +152 -0
  74. package/node_modules/@scaleway/sdk-client/dist/scw/custom-marshalling.d.ts +104 -0
  75. package/node_modules/@scaleway/sdk-client/dist/scw/custom-marshalling.js +152 -0
  76. package/node_modules/@scaleway/sdk-client/dist/scw/custom-types.cjs +11 -0
  77. package/node_modules/@scaleway/sdk-client/dist/scw/custom-types.d.ts +74 -0
  78. package/node_modules/@scaleway/sdk-client/dist/scw/custom-types.js +11 -0
  79. package/node_modules/@scaleway/sdk-client/dist/scw/errors/error-parser.cjs +76 -0
  80. package/node_modules/@scaleway/sdk-client/dist/scw/errors/error-parser.d.ts +12 -0
  81. package/node_modules/@scaleway/sdk-client/dist/scw/errors/error-parser.js +76 -0
  82. package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/invalid-request-mapper.cjs +36 -0
  83. package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/invalid-request-mapper.d.ts +12 -0
  84. package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/invalid-request-mapper.js +36 -0
  85. package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/unknown-resource-mapper.cjs +23 -0
  86. package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/unknown-resource-mapper.d.ts +11 -0
  87. package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/unknown-resource-mapper.js +23 -0
  88. package/node_modules/@scaleway/sdk-client/dist/scw/errors/scw-error-from-json.d.ts +10 -0
  89. package/node_modules/@scaleway/sdk-client/dist/scw/errors/scw-error.cjs +43 -0
  90. package/node_modules/@scaleway/sdk-client/dist/scw/errors/scw-error.d.ts +25 -0
  91. package/node_modules/@scaleway/sdk-client/dist/scw/errors/scw-error.js +43 -0
  92. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/already-exists-error.cjs +31 -0
  93. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/already-exists-error.d.ts +16 -0
  94. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/already-exists-error.js +31 -0
  95. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/denied-authentication-error.cjs +37 -0
  96. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/denied-authentication-error.d.ts +15 -0
  97. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/denied-authentication-error.js +37 -0
  98. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/index.cjs +28 -0
  99. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/index.d.ts +17 -0
  100. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/index.js +28 -0
  101. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/invalid-arguments-error.cjs +54 -0
  102. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/invalid-arguments-error.d.ts +24 -0
  103. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/invalid-arguments-error.js +54 -0
  104. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/out-of-stock-error.cjs +17 -0
  105. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/out-of-stock-error.d.ts +14 -0
  106. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/out-of-stock-error.js +17 -0
  107. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/permissions-denied-error.cjs +29 -0
  108. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/permissions-denied-error.d.ts +23 -0
  109. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/permissions-denied-error.js +29 -0
  110. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/precondition-failed-error.cjs +32 -0
  111. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/precondition-failed-error.d.ts +15 -0
  112. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/precondition-failed-error.js +32 -0
  113. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/quotas-exceeded-error.cjs +43 -0
  114. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/quotas-exceeded-error.d.ts +34 -0
  115. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/quotas-exceeded-error.js +43 -0
  116. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-expired-error.cjs +31 -0
  117. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-expired-error.d.ts +16 -0
  118. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-expired-error.js +31 -0
  119. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-locked-error.cjs +20 -0
  120. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-locked-error.d.ts +15 -0
  121. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-locked-error.js +20 -0
  122. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-not-found-error.cjs +24 -0
  123. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-not-found-error.d.ts +15 -0
  124. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-not-found-error.js +24 -0
  125. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/too-many-requests-error.cjs +58 -0
  126. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/too-many-requests-error.d.ts +32 -0
  127. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/too-many-requests-error.js +58 -0
  128. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/transient-state-error.cjs +31 -0
  129. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/transient-state-error.d.ts +16 -0
  130. package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/transient-state-error.js +31 -0
  131. package/node_modules/@scaleway/sdk-client/dist/scw/errors/types.cjs +15 -0
  132. package/node_modules/@scaleway/sdk-client/dist/scw/errors/types.d.ts +9 -0
  133. package/node_modules/@scaleway/sdk-client/dist/scw/errors/types.js +15 -0
  134. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/build-fetcher.cjs +60 -0
  135. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/build-fetcher.d.ts +23 -0
  136. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/build-fetcher.js +60 -0
  137. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-dumper.cjs +20 -0
  138. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-dumper.d.ts +18 -0
  139. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-dumper.js +20 -0
  140. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-interceptors.cjs +43 -0
  141. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-interceptors.d.ts +38 -0
  142. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-interceptors.js +43 -0
  143. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/resource-paginator.cjs +36 -0
  144. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/resource-paginator.d.ts +47 -0
  145. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/resource-paginator.js +36 -0
  146. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/response-parser.cjs +55 -0
  147. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/response-parser.d.ts +25 -0
  148. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/response-parser.js +55 -0
  149. package/node_modules/@scaleway/sdk-client/dist/scw/fetch/types.d.ts +16 -0
  150. package/node_modules/@scaleway/sdk-client/dist/scw/locality.d.ts +2 -0
  151. package/node_modules/@scaleway/sdk-client/dist/vendor/base64/index.cjs +46 -0
  152. package/node_modules/@scaleway/sdk-client/dist/vendor/base64/index.js +46 -0
  153. package/node_modules/@scaleway/sdk-client/package.json +36 -0
  154. package/package.json +41 -0
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const consoleLogger = require("./console-logger.cjs");
4
+ let sdkLogger = new consoleLogger.ConsoleLogger("silent");
5
+ const setLogger = (logger) => {
6
+ sdkLogger = logger;
7
+ };
8
+ const enableConsoleLogger = (logLevel = "warn", prefix = "scaleway-sdk-js:") => setLogger(new consoleLogger.ConsoleLogger(logLevel, prefix));
9
+ const getLogger = () => sdkLogger;
10
+ exports.enableConsoleLogger = enableConsoleLogger;
11
+ exports.getLogger = getLogger;
12
+ exports.setLogger = setLogger;
@@ -0,0 +1,25 @@
1
+ import type { LogLevel } from './level-resolver.js';
2
+ import type { Logger } from './logger';
3
+ /**
4
+ * Sets a logger to be used within the SDK.
5
+ *
6
+ * @param logger - The Logger instance
7
+ *
8
+ * @public
9
+ */
10
+ export declare const setLogger: (logger: Readonly<Logger>) => void;
11
+ /**
12
+ * Sets the logger to console logger with given logLevel (log is disabled by default).
13
+ *
14
+ * @param logLevel - The Log level (default to 'warn')
15
+ * @param prefix - A Log message prefix (default to 'scaleway-sdk-js:')
16
+ *
17
+ * @public
18
+ */
19
+ export declare const enableConsoleLogger: (logLevel?: LogLevel, prefix?: string) => void;
20
+ /**
21
+ * Returns the active SDK logger.
22
+ *
23
+ * @internal
24
+ */
25
+ export declare const getLogger: () => Readonly<Logger>;
@@ -0,0 +1,12 @@
1
+ import { ConsoleLogger } from "./console-logger.js";
2
+ let sdkLogger = new ConsoleLogger("silent");
3
+ const setLogger = (logger) => {
4
+ sdkLogger = logger;
5
+ };
6
+ const enableConsoleLogger = (logLevel = "warn", prefix = "scaleway-sdk-js:") => setLogger(new ConsoleLogger(logLevel, prefix));
7
+ const getLogger = () => sdkLogger;
8
+ export {
9
+ enableConsoleLogger,
10
+ getLogger,
11
+ setLogger
12
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ var LevelResolver = /* @__PURE__ */ ((LevelResolver2) => {
4
+ LevelResolver2[LevelResolver2["silent"] = 0] = "silent";
5
+ LevelResolver2[LevelResolver2["error"] = 1] = "error";
6
+ LevelResolver2[LevelResolver2["warn"] = 2] = "warn";
7
+ LevelResolver2[LevelResolver2["info"] = 3] = "info";
8
+ LevelResolver2[LevelResolver2["debug"] = 4] = "debug";
9
+ return LevelResolver2;
10
+ })(LevelResolver || {});
11
+ const shouldLog = (currentLevel, level) => LevelResolver[level] <= currentLevel;
12
+ exports.LevelResolver = LevelResolver;
13
+ exports.shouldLog = shouldLog;
@@ -0,0 +1,9 @@
1
+ export declare enum LevelResolver {
2
+ silent = 0,
3
+ error = 1,
4
+ warn = 2,
5
+ info = 3,
6
+ debug = 4
7
+ }
8
+ export type LogLevel = keyof typeof LevelResolver;
9
+ export declare const shouldLog: (currentLevel: LevelResolver, level: LogLevel) => boolean;
@@ -0,0 +1,13 @@
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 || {});
9
+ const shouldLog = (currentLevel, level) => LevelResolver[level] <= currentLevel;
10
+ export {
11
+ LevelResolver,
12
+ shouldLog
13
+ };
@@ -0,0 +1,13 @@
1
+ import type { LogLevel } from './level-resolver.js';
2
+ /**
3
+ * Logger.
4
+ *
5
+ * @public
6
+ */
7
+ export interface Logger {
8
+ readonly logLevel: LogLevel;
9
+ debug: (message: string) => void;
10
+ info: (message: string) => void;
11
+ warn: (message: string) => void;
12
+ error: (message: string) => void;
13
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const isAccessKeyRegex = /^SCW[A-Z0-9]{17}$/i;
4
+ const isRegionRegex = /^[a-z]{2}-[a-z]{3}$/i;
5
+ 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;
6
+ const isZoneRegex = /^[a-z]{2}-[a-z]{3}-[1-9]$/i;
7
+ const isUUID = (str) => isUUIDRegex.test(str);
8
+ const isAccessKey = (str) => isAccessKeyRegex.test(str);
9
+ const isSecretKey = (str) => isUUID(str);
10
+ const isOrganizationId = (str) => isUUID(str);
11
+ const isProjectId = (str) => isUUID(str);
12
+ const isRegion = (str) => isRegionRegex.test(str);
13
+ const isZone = (str) => isZoneRegex.test(str);
14
+ const isURL = (str) => {
15
+ let url;
16
+ try {
17
+ url = new URL(str);
18
+ } catch {
19
+ return false;
20
+ }
21
+ return url.protocol === "http:" || url.protocol === "https:";
22
+ };
23
+ exports.isAccessKey = isAccessKey;
24
+ exports.isOrganizationId = isOrganizationId;
25
+ exports.isProjectId = isProjectId;
26
+ exports.isRegion = isRegion;
27
+ exports.isSecretKey = isSecretKey;
28
+ exports.isURL = isURL;
29
+ exports.isUUID = isUUID;
30
+ exports.isZone = isZone;
@@ -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 { marshalBlobToScwFile, marshalDecimal, marshalMoney, marshalScwFile, marshalTimeSeries, unmarshalAnyRes, 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,8 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const version = "1.2.1";
4
+ const pkg = {
5
+ version
6
+ };
7
+ exports.default = pkg;
8
+ exports.version = version;
@@ -0,0 +1,8 @@
1
+ const version = "1.2.1";
2
+ const pkg = {
3
+ version
4
+ };
5
+ export {
6
+ pkg as default,
7
+ version
8
+ };
@@ -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,25 @@
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 constants = require("./constants.cjs");
6
+ const authenticateWithSessionToken = (getToken) => helpers.addAsyncHeaderInterceptor(constants.SESSION_HEADER_KEY, getToken);
7
+ const authenticateWithSecrets = (secrets) => {
8
+ clientIniProfile.assertValidAuthenticationSecrets(secrets);
9
+ return helpers.addHeaderInterceptor(constants.AUTH_HEADER_KEY, secrets.secretKey);
10
+ };
11
+ const obfuscateToken = (key) => `${key.substring(0, 5)}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`;
12
+ const obfuscateUUID = (key) => `${key.substring(0, 8)}-xxxx-xxxx-xxxx-xxxxxxxxxxxx`;
13
+ const obfuscateAuthHeadersEntry = ([
14
+ name,
15
+ value
16
+ ]) => {
17
+ if (name === constants.SESSION_HEADER_KEY) return [name, obfuscateToken(value)];
18
+ if (name === constants.AUTH_HEADER_KEY) return [name, obfuscateUUID(value)];
19
+ return [name, value];
20
+ };
21
+ exports.authenticateWithSecrets = authenticateWithSecrets;
22
+ exports.authenticateWithSessionToken = authenticateWithSessionToken;
23
+ exports.obfuscateAuthHeadersEntry = obfuscateAuthHeadersEntry;
24
+ exports.obfuscateToken = obfuscateToken;
25
+ exports.obfuscateUUID = obfuscateUUID;
@@ -0,0 +1,70 @@
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
+ interface AddSessionHeader {
7
+ request: Request;
8
+ getAsyncToken: () => Promise<string | undefined>;
9
+ }
10
+ /**
11
+ * Add an JWT Session Header to a request through an interceptor.
12
+ *
13
+ * @param request - The request to modify
14
+ * @param getJwt - The session value
15
+ * @returns The Request interceptor
16
+ *
17
+ */
18
+ export declare const addSessionHeader: ({ request, getAsyncToken, }: AddSessionHeader) => Promise<Request>;
19
+ /**
20
+ * Authenticates with a session token.
21
+ *
22
+ * @param getToken - The token accessor
23
+ * @returns The request interceptor
24
+ *
25
+ * @deprecated Please use addAsyncHeaderInterceptor instead.
26
+ *
27
+ * @internal
28
+ */
29
+ export declare const authenticateWithSessionToken: (getToken: TokenAccessor) => RequestInterceptor;
30
+ /**
31
+ * Authenticates with a secrets.
32
+ *
33
+ * @param getToken - The secrets
34
+ * @returns The request interceptor
35
+ *
36
+ * @throws Error
37
+ * Thrown if the secrets are invalid.
38
+ *
39
+ * @internal
40
+ */
41
+ export declare const authenticateWithSecrets: (secrets: AuthenticationSecrets) => RequestInterceptor;
42
+ /**
43
+ * Obfuscates a token.
44
+ *
45
+ * @param key - The token
46
+ * @returns The obfuscated token
47
+ *
48
+ * @internal
49
+ */
50
+ export declare const obfuscateToken: (key: string) => string;
51
+ /**
52
+ * Obfuscates an UUID.
53
+ *
54
+ * @param key - The UUID
55
+ * @returns The obfuscated UUID
56
+ *
57
+ * @internal
58
+ */
59
+ export declare const obfuscateUUID: (key: string) => string;
60
+ type HeaderEntry = [string, string];
61
+ /**
62
+ * Obfuscates headers entry.
63
+ *
64
+ * @param array - The header entry
65
+ * @returns The obfuscated entry
66
+ *
67
+ * @internal
68
+ */
69
+ export declare const obfuscateAuthHeadersEntry: ([name, value,]: HeaderEntry) => HeaderEntry;
70
+ export {};
@@ -0,0 +1,25 @@
1
+ import { addAsyncHeaderInterceptor, addHeaderInterceptor } from "../internal/interceptors/helpers.js";
2
+ import { assertValidAuthenticationSecrets } from "./client-ini-profile.js";
3
+ import { SESSION_HEADER_KEY, AUTH_HEADER_KEY } from "./constants.js";
4
+ const authenticateWithSessionToken = (getToken) => addAsyncHeaderInterceptor(SESSION_HEADER_KEY, getToken);
5
+ const authenticateWithSecrets = (secrets) => {
6
+ assertValidAuthenticationSecrets(secrets);
7
+ return addHeaderInterceptor(AUTH_HEADER_KEY, secrets.secretKey);
8
+ };
9
+ const obfuscateToken = (key) => `${key.substring(0, 5)}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`;
10
+ 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
25
+ };
@@ -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;