@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,82 @@
1
+ import type { Region, Zone } from './locality';
2
+ /**
3
+ * Holds access key and secret key.
4
+ *
5
+ * @public
6
+ */
7
+ export interface AuthenticationSecrets {
8
+ /**
9
+ * You need an access key and a secret key to connect to Scaleway API.
10
+ * Generate your access key at the following address: {@link https://console.scaleway.com/project/credentials}.
11
+ */
12
+ accessKey: string;
13
+ /**
14
+ * The secret key is the value that can be used to authenticate against the API (the value used in X-Auth-Token HTTP-header).
15
+ * The secret key MUST remain secret and not given to anyone or published online.
16
+ * Generate your secret key at the following address: {@link https://console.scaleway.com/project/credentials}.
17
+ */
18
+ secretKey: string;
19
+ }
20
+ /**
21
+ * Holds default values of a Scaleway profile.
22
+ *
23
+ * @public
24
+ */
25
+ export interface ProfileDefaultValues {
26
+ /**
27
+ * APIURL overrides the API URL of the Scaleway API to the given URL.
28
+ * Change that if you want to direct requests to a different endpoint.
29
+ *
30
+ * @defaultValue `https://api.scaleway.com`
31
+ */
32
+ apiURL: string;
33
+ /**
34
+ * Your organization ID is the identifier of your account inside Scaleway infrastructure.
35
+ */
36
+ defaultOrganizationId?: string;
37
+ /**
38
+ * Your project ID is the identifier of the project your resources are attached to.
39
+ */
40
+ defaultProjectId?: string;
41
+ /**
42
+ * A region is represented as a geographical area such as France (Paris) or the Netherlands (Amsterdam).
43
+ * It can contain multiple availability zones.
44
+ *
45
+ * Examples: fr-par, nl-ams.
46
+ */
47
+ defaultRegion?: Region;
48
+ /**
49
+ * A region can be split into many availability zones (AZ).
50
+ * Latency between multiple AZ of the same region are low as they have a common network layer.
51
+ *
52
+ * Examples: fr-par-1, nl-ams-1
53
+ */
54
+ defaultZone?: Zone;
55
+ }
56
+ /**
57
+ * Holds values of a Scaleway profile.
58
+ *
59
+ * @public
60
+ */
61
+ export type Profile = Partial<ProfileDefaultValues & AuthenticationSecrets>;
62
+ /**
63
+ * Verifies that the payload contains both the accessKey and the secretKey.
64
+ *
65
+ * @param obj - The secrets
66
+ * @returns Whether the secrets are not empty.
67
+ *
68
+ * @internal
69
+ */
70
+ export declare const hasAuthenticationSecrets: (obj: Partial<AuthenticationSecrets>) => obj is AuthenticationSecrets;
71
+ /**
72
+ * Asserts the format of secrets.
73
+ *
74
+ * @param obj - The secrets
75
+ * @returns Whether the secrets use a valid format
76
+ *
77
+ * @throws Error
78
+ * Thrown if either the accessKey or the secretKey has en invalid format.
79
+ *
80
+ * @internal
81
+ */
82
+ export declare function assertValidAuthenticationSecrets(obj: Partial<AuthenticationSecrets>): asserts obj is AuthenticationSecrets;
@@ -0,0 +1,23 @@
1
+ import { isAccessKey, isSecretKey } from "../internal/validations/string-validation.js";
2
+ const hasAuthenticationSecrets = (obj) => typeof obj.accessKey === "string" && obj.accessKey !== "" && typeof obj.secretKey === "string" && obj.secretKey !== "";
3
+ 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
+ }
19
+ }
20
+ export {
21
+ assertValidAuthenticationSecrets,
22
+ hasAuthenticationSecrets
23
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const stringValidation = require("../internal/validations/string-validation.cjs");
4
+ const assertValidSettings = (obj) => {
5
+ if (obj.defaultOrganizationId !== void 0) {
6
+ if (typeof obj.defaultOrganizationId !== "string" || obj.defaultOrganizationId.length === 0) {
7
+ throw new Error("Default organization ID cannot be empty");
8
+ }
9
+ if (!stringValidation.isOrganizationId(obj.defaultOrganizationId)) {
10
+ throw new Error(
11
+ `Invalid organization ID format '${obj.defaultOrganizationId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`
12
+ );
13
+ }
14
+ }
15
+ if (obj.defaultProjectId !== void 0) {
16
+ if (typeof obj.defaultProjectId !== "string" || obj.defaultProjectId.length === 0) {
17
+ throw new Error("Default project ID cannot be empty");
18
+ }
19
+ if (!stringValidation.isProjectId(obj.defaultProjectId)) {
20
+ throw new Error(
21
+ `Invalid project ID format '${obj.defaultProjectId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`
22
+ );
23
+ }
24
+ }
25
+ if (obj.defaultRegion && !stringValidation.isRegion(obj.defaultRegion)) {
26
+ throw new Error(`Invalid default region format '${obj.defaultRegion}'`);
27
+ }
28
+ if (obj.defaultZone && !stringValidation.isZone(obj.defaultZone)) {
29
+ throw new Error(`Invalid default zone format '${obj.defaultZone}'`);
30
+ }
31
+ if (obj.apiURL && !stringValidation.isURL(obj.apiURL)) {
32
+ throw new Error(`Invalid URL ${obj.apiURL}`);
33
+ }
34
+ if (obj.apiURL?.endsWith("/")) {
35
+ throw new Error(
36
+ `Invalid URL ${obj.apiURL}: it should not have a trailing slash`
37
+ );
38
+ }
39
+ if (typeof obj.httpClient !== typeof fetch) {
40
+ throw new Error(`Invalid HTTP Client`);
41
+ }
42
+ if (obj.defaultPageSize !== void 0 && (typeof obj.defaultPageSize !== "number" || Number.isNaN(obj.defaultPageSize) || obj.defaultPageSize <= 0)) {
43
+ throw new Error(
44
+ `Invalid defaultPageSize ${obj.defaultPageSize}: it should be a number above 0`
45
+ );
46
+ }
47
+ if (typeof obj.userAgent !== "string") {
48
+ throw new Error(`Invalid User-Agent`);
49
+ }
50
+ };
51
+ exports.assertValidSettings = assertValidSettings;
@@ -0,0 +1,59 @@
1
+ import type { NetworkInterceptors, RequestInterceptor, ResponseInterceptor } from '../internal/interceptors/types';
2
+ import type { Profile } from './client-ini-profile.js';
3
+ /**
4
+ * Holds default values of settings.
5
+ *
6
+ * @public
7
+ */
8
+ export type DefaultValues = Profile & {
9
+ /**
10
+ * The default number of results when requesting a paginated resource.
11
+ */
12
+ defaultPageSize?: number;
13
+ };
14
+ /**
15
+ * Settings hold the values of all client options.
16
+ *
17
+ * @public
18
+ */
19
+ export interface Settings extends DefaultValues {
20
+ /**
21
+ * The default number of results when requesting a paginated resource.
22
+ */
23
+ defaultPageSize?: number;
24
+ /**
25
+ * HTTP Client doing the requests.
26
+ */
27
+ httpClient: typeof fetch;
28
+ /**
29
+ * The Request interceptors.
30
+ *
31
+ * @deprecated Please use `interceptors` instead.
32
+ */
33
+ requestInterceptors?: RequestInterceptor[];
34
+ /**
35
+ * The Response interceptors.
36
+ *
37
+ * @deprecated Please use `interceptors` instead.
38
+ */
39
+ responseInterceptors?: ResponseInterceptor[];
40
+ /**
41
+ * The Network interceptors.
42
+ */
43
+ interceptors: NetworkInterceptors[];
44
+ /**
45
+ * The User-Agent sent with each request.
46
+ *
47
+ * @defaultValue scaleway-sdk-js/version
48
+ */
49
+ userAgent: string;
50
+ }
51
+ /**
52
+ * Validates the content of a {@link Settings} object.
53
+ *
54
+ * @throws Error
55
+ * Thrown if {@link Settings} aren't valid.
56
+ *
57
+ * @internal
58
+ */
59
+ export declare const assertValidSettings: (obj: Readonly<Settings>) => void;
@@ -0,0 +1,51 @@
1
+ import { isOrganizationId, isProjectId, isRegion, isZone, isURL } from "../internal/validations/string-validation.js";
2
+ 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
51
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index = require("../internal/logger/index.cjs");
4
+ const clientIniFactory = require("./client-ini-factory.cjs");
5
+ const clientSettings = require("./client-settings.cjs");
6
+ const constants = require("./constants.cjs");
7
+ const buildFetcher = require("./fetch/build-fetcher.cjs");
8
+ const DEFAULT_SETTINGS = {
9
+ apiURL: "https://api.scaleway.com",
10
+ httpClient: fetch,
11
+ interceptors: [],
12
+ userAgent: constants.userAgent
13
+ };
14
+ const createAdvancedClient = (...configs) => {
15
+ const settings = configs.concat([clientIniFactory.withLegacyInterceptors()]).reduce(
16
+ (currentSettings, config) => config(currentSettings),
17
+ DEFAULT_SETTINGS
18
+ );
19
+ clientSettings.assertValidSettings(settings);
20
+ index.getLogger().info(`init Scaleway SDK version ${constants.version}`);
21
+ return {
22
+ fetch: buildFetcher.buildFetcher(settings, settings.httpClient),
23
+ settings
24
+ };
25
+ };
26
+ const createClient = (settings = {}) => createAdvancedClient(
27
+ clientIniFactory.withProfile(settings),
28
+ clientIniFactory.withAdditionalInterceptors(settings.interceptors ?? [])
29
+ );
30
+ exports.createAdvancedClient = createAdvancedClient;
31
+ exports.createClient = createClient;
@@ -0,0 +1,71 @@
1
+ import type { ClientConfig } from './client-ini-factory.js';
2
+ import type { Settings } from './client-settings.js';
3
+ import type { Fetcher } from './fetch/build-fetcher.js';
4
+ /**
5
+ * Scaleway client.
6
+ */
7
+ export interface Client {
8
+ fetch: Fetcher;
9
+ settings: Settings;
10
+ }
11
+ /**
12
+ * Creates a Scaleway client with advanced options.
13
+ * You can either use existing factories
14
+ * (like `withProfile`, `withUserAgentSuffix`, etc)
15
+ * or write your own using the interface `ClientConfig`.
16
+ *
17
+ * @example
18
+ * Creates a client with factories:
19
+ * ```
20
+ * createAdvancedClient(
21
+ * (obj: Settings) => ({
22
+ * ...obj,
23
+ * defaultPageSize: 100 ,
24
+ * httpClient: myFetchWrapper,
25
+ * }),
26
+ * withUserAgentSuffix('bot-name/1.0'),
27
+ * )
28
+ * ```
29
+ *
30
+ * @throws Error
31
+ * Thrown if the setup fails.
32
+ *
33
+ * @public
34
+ */
35
+ export declare const createAdvancedClient: (...configs: ClientConfig[]) => Client;
36
+ /**
37
+ * Creates a Scaleway client with a profile.
38
+ *
39
+ * @example
40
+ * Creates a client with credentials & default values (see https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/):
41
+ * ```
42
+ * import { createClient } from '@scaleway/sdk'
43
+ *
44
+ * createClient({
45
+ * accessKey: 'SCWXXXXXXXXXXXXXXXXX',
46
+ * secretKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
47
+ * defaultProjectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
48
+ * defaultRegion: 'fr-par',
49
+ * defaultZone: 'fr-par-1',
50
+ * })
51
+ * ```
52
+ *
53
+ * @example
54
+ * Creates a client by loading values from the environment (see https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/)
55
+ * or the config file created by CLI `scw init` (see https://www.scaleway.com/en/cli/):
56
+ * ```
57
+ * import { loadProfileFromConfigurationFile } from '@scaleway/configuration-loader'
58
+ * import { createClient } from '@scaleway/sdk'
59
+ *
60
+ * createClient({
61
+ * ...await loadProfileFromConfigurationFile(),
62
+ * defaultZone: 'fr-par-3',
63
+ * })
64
+ * ```
65
+ *
66
+ * @throws Error
67
+ * Thrown if the setup fails.
68
+ *
69
+ * @public
70
+ */
71
+ export declare const createClient: (settings?: Partial<Settings>) => Client;
@@ -0,0 +1,31 @@
1
+ import { getLogger } from "../internal/logger/index.js";
2
+ import { withAdditionalInterceptors, withProfile, withLegacyInterceptors } from "./client-ini-factory.js";
3
+ import { assertValidSettings } from "./client-settings.js";
4
+ import { userAgent, version } from "./constants.js";
5
+ import { buildFetcher } from "./fetch/build-fetcher.js";
6
+ const DEFAULT_SETTINGS = {
7
+ apiURL: "https://api.scaleway.com",
8
+ httpClient: fetch,
9
+ interceptors: [],
10
+ userAgent
11
+ };
12
+ const createAdvancedClient = (...configs) => {
13
+ const settings = configs.concat([withLegacyInterceptors()]).reduce(
14
+ (currentSettings, config) => config(currentSettings),
15
+ DEFAULT_SETTINGS
16
+ );
17
+ assertValidSettings(settings);
18
+ getLogger().info(`init Scaleway SDK version ${version}`);
19
+ return {
20
+ fetch: buildFetcher(settings, settings.httpClient),
21
+ settings
22
+ };
23
+ };
24
+ const createClient = (settings = {}) => createAdvancedClient(
25
+ withProfile(settings),
26
+ withAdditionalInterceptors(settings.interceptors ?? [])
27
+ );
28
+ export {
29
+ createAdvancedClient,
30
+ createClient
31
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const _package = require("../package.json.cjs");
4
+ const { version } = _package.default;
5
+ const userAgent = `scaleway-sdk-js/${version}`;
6
+ const SESSION_HEADER_KEY = "x-session-token";
7
+ const AUTH_HEADER_KEY = "x-auth-token";
8
+ exports.AUTH_HEADER_KEY = AUTH_HEADER_KEY;
9
+ exports.SESSION_HEADER_KEY = SESSION_HEADER_KEY;
10
+ exports.userAgent = userAgent;
11
+ exports.version = version;
@@ -0,0 +1,4 @@
1
+ export declare const version: string;
2
+ export declare const userAgent: string;
3
+ export declare const SESSION_HEADER_KEY = "x-session-token";
4
+ export declare const AUTH_HEADER_KEY = "x-auth-token";
@@ -0,0 +1,11 @@
1
+ import pkg from "../package.json.js";
2
+ const { version } = pkg;
3
+ const userAgent = `scaleway-sdk-js/${version}`;
4
+ const SESSION_HEADER_KEY = "x-session-token";
5
+ const AUTH_HEADER_KEY = "x-auth-token";
6
+ export {
7
+ AUTH_HEADER_KEY,
8
+ SESSION_HEADER_KEY,
9
+ userAgent,
10
+ version
11
+ };
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const json = require("../helpers/json.cjs");
4
+ const marshalling = require("../helpers/marshalling.cjs");
5
+ const index = require("../vendor/base64/index.cjs");
6
+ const customTypes = require("./custom-types.cjs");
7
+ const unmarshalMoney = (data) => {
8
+ if (!json.isJSONObject(data)) {
9
+ throw new TypeError(
10
+ `Unmarshalling the type 'Money' failed as data isn't a dictionary.`
11
+ );
12
+ }
13
+ return {
14
+ currencyCode: data.currency_code,
15
+ nanos: data.nanos,
16
+ units: data.units
17
+ };
18
+ };
19
+ const unmarshalServiceInfo = (data) => {
20
+ if (!json.isJSONObject(data)) {
21
+ throw new TypeError(
22
+ `Unmarshalling the type 'ServiceInfo' failed as data isn't a dictionary.`
23
+ );
24
+ }
25
+ return {
26
+ description: data.description,
27
+ documentationUrl: data.documentation_url,
28
+ name: data.name,
29
+ version: data.version
30
+ };
31
+ };
32
+ const unmarshalScwFile = (data) => {
33
+ if (!json.isJSONObject(data)) {
34
+ throw new TypeError(
35
+ `Unmarshalling the type 'ScwFile' failed as data isn't a dictionary.`
36
+ );
37
+ }
38
+ return {
39
+ content: data.content,
40
+ contentType: data.content_type,
41
+ name: data.name
42
+ };
43
+ };
44
+ const unmarshalTimeSeriesPoint = (data) => {
45
+ if (!Array.isArray(data)) {
46
+ throw new TypeError(
47
+ `Unmarshalling the type 'TimeSeriesPoint' failed as data isn't an array.`
48
+ );
49
+ }
50
+ return {
51
+ timestamp: marshalling.unmarshalDate(data[0]),
52
+ value: data[1]
53
+ };
54
+ };
55
+ const unmarshalTimeSeries = (data) => {
56
+ if (!json.isJSONObject(data)) {
57
+ throw new TypeError(
58
+ `Unmarshalling the type 'TimeSeries' failed as data isn't a dictionary.`
59
+ );
60
+ }
61
+ return {
62
+ metadata: data.metadata,
63
+ name: data.name,
64
+ points: marshalling.unmarshalArrayOfObject(data.points, unmarshalTimeSeriesPoint)
65
+ };
66
+ };
67
+ const unmarshalDecimal = (data) => {
68
+ if (!(typeof data === "object")) {
69
+ throw new TypeError(
70
+ `Unmarshalling the type 'Decimal' failed as data isn't an object.`
71
+ );
72
+ }
73
+ if (data === null) {
74
+ return null;
75
+ }
76
+ if (!("value" in data)) {
77
+ throw new TypeError(
78
+ `Unmarshalling the type 'Decimal' failed as data object does not have a 'value' key.`
79
+ );
80
+ }
81
+ if (!(typeof data.value === "string")) {
82
+ throw new TypeError(
83
+ `Unmarshalling the type 'Decimal' failed as 'value' is not a string.`
84
+ );
85
+ }
86
+ return new customTypes.Decimal(data.value);
87
+ };
88
+ const marshalScwFile = (obj) => ({
89
+ content: obj.content,
90
+ content_type: obj.contentType,
91
+ name: obj.name
92
+ });
93
+ const marshalBlobToScwFile = async (blob) => ({
94
+ content: index.fromByteArray(new Uint8Array(await blob.arrayBuffer())),
95
+ content_type: blob.type,
96
+ name: "file"
97
+ });
98
+ const marshalMoney = (obj) => ({
99
+ currency_code: obj.currencyCode,
100
+ nanos: obj.nanos,
101
+ units: obj.units
102
+ });
103
+ const marshalTimeSeriesPoint = (obj) => ({
104
+ timestamp: obj.timestamp?.toISOString(),
105
+ value: obj.value
106
+ });
107
+ const marshalTimeSeries = (obj) => ({
108
+ metadata: obj.metadata,
109
+ name: obj.name,
110
+ points: obj.points.map((elt) => marshalTimeSeriesPoint(elt))
111
+ });
112
+ const marshalDecimal = (obj) => ({
113
+ value: obj.toString()
114
+ });
115
+ const unmarshalDates = (obj, keys) => {
116
+ if (Array.isArray(obj)) {
117
+ return obj.map((v) => unmarshalDates(v, keys));
118
+ }
119
+ if (obj && typeof obj === "object") {
120
+ return Object.entries(obj).reduce(
121
+ (acc, [key, value]) => ({
122
+ ...acc,
123
+ [key]: typeof value === "string" && keys.includes(key) ? new Date(value) : unmarshalDates(value, keys)
124
+ }),
125
+ {}
126
+ );
127
+ }
128
+ return obj;
129
+ };
130
+ const unmarshalAnyRes = (obj, ignoreKeys = [], dateKeys) => {
131
+ if (!json.isJSONObject(obj)) {
132
+ throw new TypeError(`Data isn't a dictionary.`);
133
+ }
134
+ return json.camelizeKeys(
135
+ dateKeys && dateKeys.length > 0 ? unmarshalDates(obj, dateKeys) : obj,
136
+ ignoreKeys
137
+ );
138
+ };
139
+ exports.marshalBlobToScwFile = marshalBlobToScwFile;
140
+ exports.marshalDecimal = marshalDecimal;
141
+ exports.marshalMoney = marshalMoney;
142
+ exports.marshalScwFile = marshalScwFile;
143
+ exports.marshalTimeSeries = marshalTimeSeries;
144
+ exports.marshalTimeSeriesPoint = marshalTimeSeriesPoint;
145
+ exports.unmarshalAnyRes = unmarshalAnyRes;
146
+ exports.unmarshalDates = unmarshalDates;
147
+ exports.unmarshalDecimal = unmarshalDecimal;
148
+ exports.unmarshalMoney = unmarshalMoney;
149
+ exports.unmarshalScwFile = unmarshalScwFile;
150
+ exports.unmarshalServiceInfo = unmarshalServiceInfo;
151
+ exports.unmarshalTimeSeries = unmarshalTimeSeries;
152
+ exports.unmarshalTimeSeriesPoint = unmarshalTimeSeriesPoint;
@@ -0,0 +1,104 @@
1
+ import type { Money, ScwFile, ServiceInfo, TimeSeries, TimeSeriesPoint } from './custom-types.js';
2
+ import { Decimal } from './custom-types.js';
3
+ /**
4
+ * Unmarshals {@link Money}
5
+ *
6
+ * @internal
7
+ */
8
+ export declare const unmarshalMoney: (data: unknown) => Money;
9
+ /**
10
+ * Unmarshals {@link ServiceInfo}.
11
+ *
12
+ * @internal
13
+ */
14
+ export declare const unmarshalServiceInfo: (data: unknown) => ServiceInfo;
15
+ /**
16
+ * Unmarshals {@link ScwFile}.
17
+ *
18
+ * @internal
19
+ */
20
+ export declare const unmarshalScwFile: (data: unknown) => ScwFile;
21
+ /**
22
+ * Unmarshals {@link TimeSeriesPoint}
23
+ *
24
+ * @remarks To optimize the size of this message,
25
+ * the JSON is compressed in an array instead of a dictionary.
26
+ * Example: `["2019-08-08T15:00:00Z", 0.2]`.
27
+ *
28
+ * @internal
29
+ */
30
+ export declare const unmarshalTimeSeriesPoint: (data: unknown) => TimeSeriesPoint;
31
+ /**
32
+ * Unmarshals {@link TimeSeries}
33
+ *
34
+ * @internal
35
+ */
36
+ export declare const unmarshalTimeSeries: (data: unknown) => TimeSeries;
37
+ /**
38
+ * Unmarshals {@link Decimal}
39
+ *
40
+ * @internal
41
+ */
42
+ export declare const unmarshalDecimal: (data: unknown) => Decimal | null;
43
+ /**
44
+ * Marshals {@link ScwFile}.
45
+ *
46
+ * @internal
47
+ */
48
+ export declare const marshalScwFile: (obj: ScwFile) => Record<string, unknown>;
49
+ /**
50
+ * Marshals {@link Blob}.
51
+ *
52
+ * @internal
53
+ */
54
+ export declare const marshalBlobToScwFile: (blob: Blob) => Promise<Record<string, unknown>>;
55
+ /**
56
+ * Marshals {@link Money}
57
+ *
58
+ * @internal
59
+ */
60
+ export declare const marshalMoney: (obj: Money) => Record<string, unknown>;
61
+ /**
62
+ * Marshals {@link TimeSeriesPoint}
63
+ *
64
+ * @internal
65
+ */
66
+ export declare const marshalTimeSeriesPoint: (obj: TimeSeriesPoint) => Record<string, unknown>;
67
+ /**
68
+ * Marshals {@link TimeSeries}
69
+ *
70
+ * @internal
71
+ */
72
+ export declare const marshalTimeSeries: (obj: TimeSeries) => Record<string, unknown>;
73
+ /**
74
+ * Marshals {@link Decimal}
75
+ *
76
+ * @internal
77
+ */
78
+ export declare const marshalDecimal: (obj: Decimal) => {
79
+ value: string;
80
+ };
81
+ /**
82
+ * Unmarshals record to convert iso dates from string to Dates.
83
+ *
84
+ * @param obj - The input
85
+ * @param keys - The keys requiring a conversion
86
+ * @returns The updated input
87
+ *
88
+ * @internal
89
+ */
90
+ export declare const unmarshalDates: <T>(obj: unknown, keys: string[]) => T;
91
+ /**
92
+ * Unmarshals input to a record with camilized keys and instanciated Date.
93
+ *
94
+ * @param obj - The input
95
+ * @param ignoreKeys - The keys which should be not be transformed
96
+ * @param dateKeys - The keys which should be transformed to Date
97
+ * @returns The record
98
+ *
99
+ * @throws TypeError
100
+ * Thrown if the input isn't {@link JSONObject}.
101
+ *
102
+ * @internal
103
+ */
104
+ export declare const unmarshalAnyRes: <T>(obj: unknown, ignoreKeys?: string[], dateKeys?: string[]) => T;