@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,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 { withLegacyInterceptors, withAdditionalInterceptors, withProfile } from "./client-ini-factory.js";
3
+ import { assertValidSettings } from "./client-settings.js";
4
+ import { version, userAgent } 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,7 @@
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
+ exports.userAgent = userAgent;
7
+ exports.version = version;
@@ -0,0 +1,2 @@
1
+ export declare const version: string;
2
+ export declare const userAgent: string;
@@ -0,0 +1,7 @@
1
+ import pkg from "../package.json.js";
2
+ const { version } = pkg;
3
+ const userAgent = `scaleway-sdk-js/${version}`;
4
+ export {
5
+ userAgent,
6
+ version
7
+ };
@@ -0,0 +1,126 @@
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
+ exports.marshalBlobToScwFile = marshalBlobToScwFile;
116
+ exports.marshalDecimal = marshalDecimal;
117
+ exports.marshalMoney = marshalMoney;
118
+ exports.marshalScwFile = marshalScwFile;
119
+ exports.marshalTimeSeries = marshalTimeSeries;
120
+ exports.marshalTimeSeriesPoint = marshalTimeSeriesPoint;
121
+ exports.unmarshalDecimal = unmarshalDecimal;
122
+ exports.unmarshalMoney = unmarshalMoney;
123
+ exports.unmarshalScwFile = unmarshalScwFile;
124
+ exports.unmarshalServiceInfo = unmarshalServiceInfo;
125
+ exports.unmarshalTimeSeries = unmarshalTimeSeries;
126
+ exports.unmarshalTimeSeriesPoint = unmarshalTimeSeriesPoint;
@@ -0,0 +1,80 @@
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
+ };