@scaleway/sdk 0.1.0-beta.8 → 1.0.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.
- package/README.md +1 -1
- package/dist/api/account/index.js +2 -2
- package/dist/api/account/v2/api.gen.js +5 -18
- package/dist/api/account/v2/index.gen.js +3 -0
- package/dist/api/account/v2/marshalling.gen.js +0 -2
- package/dist/api/account/v2alpha1/api.gen.js +3 -13
- package/dist/api/account/v2alpha1/marshalling.gen.js +0 -5
- package/dist/api/applesilicon/index.js +2 -2
- package/dist/api/applesilicon/v1alpha1/api.gen.js +7 -27
- package/dist/api/applesilicon/v1alpha1/index.gen.js +4 -0
- package/dist/api/applesilicon/v1alpha1/marshalling.gen.js +1 -14
- package/dist/api/baremetal/v1/api.gen.js +47 -49
- package/dist/api/baremetal/v1/api.utils.js +2 -10
- package/dist/api/baremetal/v1/content.gen.js +6 -3
- package/dist/api/baremetal/v1/index.js +4 -1
- package/dist/api/baremetal/v1/marshalling.gen.js +44 -45
- package/dist/api/baremetal/v1/validation-rules.gen.js +109 -0
- package/dist/api/container/index.js +2 -2
- package/dist/api/container/v1beta1/api.gen.js +5 -51
- package/dist/api/container/v1beta1/content.gen.js +4 -4
- package/dist/api/container/v1beta1/{index.js → index.gen.js} +3 -1
- package/dist/api/container/v1beta1/marshalling.gen.js +12 -26
- package/dist/api/domain/index.js +2 -2
- package/dist/api/domain/v2beta1/api.gen.js +55 -85
- package/dist/api/domain/v2beta1/content.gen.js +22 -1
- package/dist/api/domain/v2beta1/index.gen.js +4 -0
- package/dist/api/domain/v2beta1/marshalling.gen.js +47 -165
- package/dist/api/flexibleip/index.js +2 -2
- package/dist/api/flexibleip/v1alpha1/api.gen.js +5 -22
- package/dist/api/flexibleip/v1alpha1/content.gen.js +1 -1
- package/dist/api/flexibleip/v1alpha1/index.gen.js +6 -0
- package/dist/api/flexibleip/v1alpha1/marshalling.gen.js +0 -7
- package/dist/api/flexibleip/v1alpha1/validation-rules.gen.js +14 -0
- package/dist/api/function/index.js +2 -2
- package/dist/api/function/v1beta1/api.gen.js +54 -57
- package/dist/api/function/v1beta1/content.gen.js +8 -5
- package/dist/api/function/v1beta1/index.gen.js +4 -0
- package/dist/api/function/v1beta1/marshalling.gen.js +125 -33
- package/dist/api/iam/index.js +2 -2
- package/dist/api/iam/v1alpha1/api.gen.js +15 -62
- package/dist/api/iam/v1alpha1/index.gen.js +5 -0
- package/dist/api/iam/v1alpha1/marshalling.gen.js +7 -29
- package/dist/api/iam/v1alpha1/validation-rules.gen.js +184 -0
- package/dist/api/instance/v1/api.gen.js +38 -118
- package/dist/api/instance/v1/api.utils.js +59 -51
- package/dist/api/instance/v1/content.gen.js +7 -7
- package/dist/api/instance/v1/marshalling.gen.js +46 -168
- package/dist/api/instance/v1/marshalling.utils.js +63 -0
- package/dist/api/iot/index.js +2 -2
- package/dist/api/iot/v1/api.gen.js +5 -56
- package/dist/api/iot/v1/index.gen.js +4 -0
- package/dist/api/iot/v1/marshalling.gen.js +2 -51
- package/dist/api/k8s/index.js +2 -2
- package/dist/api/k8s/v1/api.gen.js +17 -43
- package/dist/api/k8s/v1/content.gen.js +2 -2
- package/dist/api/k8s/v1/index.gen.js +6 -0
- package/dist/api/k8s/v1/marshalling.gen.js +18 -36
- package/dist/api/k8s/v1/validation-rules.gen.js +92 -0
- package/dist/api/lb/v1/api.gen.js +8 -163
- package/dist/api/lb/v1/api.utils.js +3 -9
- package/dist/api/lb/v1/content.gen.js +3 -3
- package/dist/api/lb/v1/marshalling.gen.js +74 -101
- package/dist/api/marketplace/index.js +4 -2
- package/dist/api/marketplace/v1/api.gen.js +3 -13
- package/dist/api/marketplace/v1/index.gen.js +3 -0
- package/dist/api/marketplace/v1/marshalling.gen.js +0 -13
- package/dist/api/marketplace/v2/api.gen.js +85 -0
- package/dist/api/marketplace/v2/index.gen.js +3 -0
- package/dist/api/marketplace/v2/marshalling.gen.js +92 -0
- package/dist/api/mnq/index.js +2 -2
- package/dist/api/mnq/v1alpha1/api.gen.js +7 -25
- package/dist/api/mnq/v1alpha1/index.gen.js +3 -0
- package/dist/api/mnq/v1alpha1/marshalling.gen.js +7 -46
- package/dist/api/rdb/index.js +2 -2
- package/dist/api/rdb/v1/api.gen.js +15 -89
- package/dist/api/rdb/v1/content.gen.js +10 -4
- package/dist/api/rdb/v1/index.gen.js +4 -0
- package/dist/api/rdb/v1/marshalling.gen.js +25 -81
- package/dist/api/redis/index.js +2 -2
- package/dist/api/redis/{v1alpha1 → v1}/api.gen.js +45 -77
- package/dist/api/redis/{v1alpha1 → v1}/content.gen.js +1 -1
- package/dist/api/redis/v1/index.gen.js +4 -0
- package/dist/api/redis/{v1alpha1 → v1}/marshalling.gen.js +42 -59
- package/dist/api/registry/index.js +2 -2
- package/dist/api/registry/v1/api.gen.js +5 -29
- package/dist/api/registry/v1/content.gen.js +2 -2
- package/dist/api/registry/v1/{index.js → index.gen.js} +3 -1
- package/dist/api/registry/v1/marshalling.gen.js +2 -8
- package/dist/api/secret/index.js +2 -0
- package/dist/api/secret/v1alpha1/api.gen.js +135 -0
- package/dist/api/secret/v1alpha1/index.gen.js +3 -0
- package/dist/api/secret/v1alpha1/marshalling.gen.js +82 -0
- package/dist/api/tem/index.js +2 -0
- package/dist/api/tem/v1alpha1/api.gen.js +109 -0
- package/dist/api/tem/v1alpha1/content.gen.js +10 -0
- package/dist/api/tem/v1alpha1/index.gen.js +4 -0
- package/dist/api/tem/v1alpha1/marshalling.gen.js +132 -0
- package/dist/api/test/index.js +2 -2
- package/dist/api/test/v1/api.gen.js +6 -20
- package/dist/api/test/v1/index.gen.js +4 -0
- package/dist/api/test/v1/marshalling.gen.js +2 -5
- package/dist/api/vpc/index.js +2 -2
- package/dist/api/vpc/v1/api.gen.js +6 -17
- package/dist/api/vpc/v1/index.gen.js +3 -0
- package/dist/api/vpc/v1/marshalling.gen.js +1 -3
- package/dist/api/vpcgw/index.js +2 -2
- package/dist/api/vpcgw/v1/api.gen.js +5 -64
- package/dist/api/vpcgw/v1/content.gen.js +2 -2
- package/dist/api/vpcgw/v1/{index.js → index.gen.js} +3 -1
- package/dist/api/vpcgw/v1/marshalling.gen.js +3 -24
- package/dist/helpers/json.js +1 -2
- package/dist/helpers/marshalling.js +7 -20
- package/dist/index.cjs +3870 -2948
- package/dist/index.d.ts +7218 -4335
- package/dist/index.js +10 -6
- package/dist/internal/async/interval-retrier.js +10 -16
- package/dist/internal/interceptors/interceptor.js +3 -1
- package/dist/internal/interceptors/request.js +1 -3
- package/dist/internal/logger/console-logger.js +3 -5
- package/dist/internal/logger/index.js +3 -5
- package/dist/internal/logger/level-resolver.js +0 -3
- package/dist/internal/validations/string-validation.js +8 -10
- package/dist/node_modules/.pnpm/@scaleway_random-name@4.0.1/node_modules/@scaleway/random-name/dist/index.js +13 -0
- package/dist/scw/api.js +3 -4
- package/dist/scw/auth.js +3 -5
- package/dist/scw/client-ini-factory.js +32 -15
- package/dist/scw/client-ini-profile.js +10 -4
- package/dist/scw/client-settings.js +32 -15
- package/dist/scw/client.js +5 -6
- package/dist/scw/constants.js +1 -1
- package/dist/scw/custom-marshalling.js +8 -14
- package/dist/scw/errors/error-parser.js +2 -21
- package/dist/scw/errors/non-standard/invalid-request-mapper.js +17 -15
- package/dist/scw/errors/non-standard/unknown-resource-mapper.js +7 -6
- package/dist/scw/errors/scw-error.js +20 -20
- package/dist/scw/errors/standard/already-exists-error.js +3 -4
- package/dist/scw/errors/standard/denied-authentication-error.js +4 -11
- package/dist/scw/errors/standard/invalid-arguments-error.js +1 -10
- package/dist/scw/errors/standard/out-of-stock-error.js +0 -3
- package/dist/scw/errors/standard/permissions-denied-error.js +1 -4
- package/dist/scw/errors/standard/precondition-failed-error.js +4 -8
- package/dist/scw/errors/standard/quotas-exceeded-error.js +14 -14
- package/dist/scw/errors/standard/resource-expired-error.js +3 -4
- package/dist/scw/errors/standard/resource-locked-error.js +3 -4
- package/dist/scw/errors/standard/resource-not-found-error.js +3 -4
- package/dist/scw/errors/standard/too-many-requests-error.js +3 -16
- package/dist/scw/errors/standard/transient-state-error.js +3 -4
- package/dist/scw/errors/types.js +0 -3
- package/dist/scw/fetch/build-fetcher.js +1 -9
- package/dist/scw/fetch/http-dumper.js +4 -7
- package/dist/scw/fetch/http-interceptors.js +9 -12
- package/dist/scw/fetch/resource-paginator.js +18 -16
- package/dist/scw/fetch/response-parser.js +17 -23
- package/node_modules/@scaleway/random-name/CHANGELOG.md +42 -63
- package/node_modules/@scaleway/random-name/dist/index.js +5 -246
- package/node_modules/@scaleway/random-name/package.json +6 -5
- package/package.json +4 -5
- package/dist/api/account/v2/index.js +0 -1
- package/dist/api/applesilicon/v1alpha1/index.js +0 -2
- package/dist/api/domain/v2beta1/index.js +0 -2
- package/dist/api/flexibleip/v1alpha1/index.js +0 -2
- package/dist/api/function/v1beta1/index.js +0 -2
- package/dist/api/iam/v1alpha1/index.js +0 -1
- package/dist/api/iot/v1/index.js +0 -2
- package/dist/api/k8s/v1/index.js +0 -2
- package/dist/api/marketplace/v1/index.js +0 -1
- package/dist/api/mnq/v1alpha1/index.js +0 -1
- package/dist/api/rdb/v1/index.js +0 -2
- package/dist/api/redis/v1alpha1/index.js +0 -2
- package/dist/api/test/v1/index.js +0 -1
- package/dist/api/vpc/v1/index.js +0 -1
- package/dist/node_modules/.pnpm/@scaleway_random-name@3.0.2/node_modules/@scaleway/random-name/dist/index.js +0 -254
- package/node_modules/@scaleway/random-name/dist/index.browser.js +0 -256
package/dist/index.js
CHANGED
|
@@ -44,9 +44,13 @@ import * as index$g from './api/redis/index.js';
|
|
|
44
44
|
export { index$g as Redis };
|
|
45
45
|
import * as index$h from './api/registry/index.js';
|
|
46
46
|
export { index$h as Registry };
|
|
47
|
-
import * as index$i from './api/
|
|
48
|
-
export { index$i as
|
|
49
|
-
import * as index$j from './api/
|
|
50
|
-
export { index$j as
|
|
51
|
-
import * as index$k from './api/
|
|
52
|
-
export { index$k as
|
|
47
|
+
import * as index$i from './api/secret/index.js';
|
|
48
|
+
export { index$i as Secret };
|
|
49
|
+
import * as index$j from './api/test/index.js';
|
|
50
|
+
export { index$j as Test };
|
|
51
|
+
import * as index$k from './api/tem/index.js';
|
|
52
|
+
export { index$k as TransactionalEmail };
|
|
53
|
+
import * as index$l from './api/vpc/index.js';
|
|
54
|
+
export { index$l as VPC };
|
|
55
|
+
import * as index$m from './api/vpcgw/index.js';
|
|
56
|
+
export { index$m as VPCGW };
|
|
@@ -3,6 +3,7 @@ import { sleep } from './sleep.js';
|
|
|
3
3
|
const DEFAULT_TIMEOUT_SECONDS = 300;
|
|
4
4
|
const DEFAULT_MIN_DELAY_SECONDS = 1;
|
|
5
5
|
const DEFAULT_MAX_DELAY_SECONDS = 30;
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Creates an exponential backoff interval strategy.
|
|
8
9
|
*
|
|
@@ -12,27 +13,24 @@ const DEFAULT_MAX_DELAY_SECONDS = 30;
|
|
|
12
13
|
*
|
|
13
14
|
* @internal
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
16
|
function* createExponentialBackoffStrategy(minDelay, maxDelay) {
|
|
17
17
|
if (minDelay < 1 || maxDelay < 1 || minDelay > maxDelay) {
|
|
18
18
|
throw new Error('Waiter: minDelay must be >= 1 and maxDelay must be >= minDelay');
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
let attempt = 1;
|
|
22
21
|
const ceiling = Math.log(maxDelay / minDelay) / Math.log(2) + 1;
|
|
23
|
-
|
|
24
22
|
const randomInRange = (min, max) => min + Math.random() * (max - min);
|
|
25
|
-
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
26
24
|
while (true) {
|
|
27
25
|
if (attempt > ceiling) {
|
|
28
26
|
yield maxDelay;
|
|
29
27
|
} else {
|
|
30
28
|
yield randomInRange(minDelay, minDelay * 2 ** (attempt - 1));
|
|
31
29
|
}
|
|
32
|
-
|
|
33
30
|
attempt += 1;
|
|
34
31
|
}
|
|
35
32
|
}
|
|
33
|
+
|
|
36
34
|
/**
|
|
37
35
|
* Tries a specific logic several times until it succeeds, timeouts, or throws an exception.
|
|
38
36
|
*
|
|
@@ -44,31 +42,28 @@ function* createExponentialBackoffStrategy(minDelay, maxDelay) {
|
|
|
44
42
|
*
|
|
45
43
|
* @internal
|
|
46
44
|
*/
|
|
47
|
-
|
|
48
45
|
const tryAtIntervals = async function (retry, strategy, timeout) {
|
|
49
46
|
if (timeout === void 0) {
|
|
50
47
|
timeout = DEFAULT_TIMEOUT_SECONDS;
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
const timeoutTimestamp = Date.now() + timeout * 1000;
|
|
54
50
|
let retryCount = 0;
|
|
55
|
-
|
|
56
51
|
while (Date.now() <= timeoutTimestamp) {
|
|
57
|
-
const delay = strategy.next(retryCount += 1).value * 1000;
|
|
58
|
-
|
|
59
|
-
if (timeoutTimestamp <= Date.now() + delay) break;
|
|
60
|
-
|
|
61
|
-
await sleep(delay);
|
|
62
|
-
|
|
52
|
+
const delay = strategy.next(retryCount += 1).value * 1000;
|
|
53
|
+
// Break if timeout has been reached
|
|
54
|
+
if (timeoutTimestamp <= Date.now() + delay) break;
|
|
55
|
+
// Wait before the next retry
|
|
56
|
+
await sleep(delay);
|
|
57
|
+
// Retry
|
|
63
58
|
const {
|
|
64
59
|
value,
|
|
65
60
|
done
|
|
66
61
|
} = await retry();
|
|
67
62
|
if (done) return value;
|
|
68
63
|
}
|
|
69
|
-
|
|
70
64
|
throw new Error(`Timeout after ${timeout}s`);
|
|
71
65
|
};
|
|
66
|
+
|
|
72
67
|
/**
|
|
73
68
|
* Represents the condition to stop waiting for a resource.
|
|
74
69
|
*
|
|
@@ -92,7 +87,6 @@ const waitForResource = function (stop, fetcher, request, options, strategy) {
|
|
|
92
87
|
if (strategy === void 0) {
|
|
93
88
|
strategy = createExponentialBackoffStrategy((options == null ? void 0 : options.minDelay) ?? DEFAULT_MIN_DELAY_SECONDS, (options == null ? void 0 : options.maxDelay) ?? DEFAULT_MAX_DELAY_SECONDS);
|
|
94
89
|
}
|
|
95
|
-
|
|
96
90
|
return tryAtIntervals(async () => {
|
|
97
91
|
const value = await fetcher(request);
|
|
98
92
|
return {
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
const composeInterceptors = interceptors => async instance => interceptors.reduce(async (asyncResult, interceptor) => interceptor(await asyncResult), Promise
|
|
9
|
+
const composeInterceptors = interceptors => async instance => interceptors.reduce(async (asyncResult, interceptor) => interceptor(await asyncResult), new Promise(resolve => {
|
|
10
|
+
resolve(instance);
|
|
11
|
+
}));
|
|
10
12
|
|
|
11
13
|
export { composeInterceptors };
|
|
@@ -11,13 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
const addHeaderInterceptor = (key, value) => request => {
|
|
13
13
|
const clone = request.clone();
|
|
14
|
-
|
|
15
14
|
if (value !== undefined) {
|
|
16
15
|
clone.headers.append(key, value);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
return clone;
|
|
20
18
|
};
|
|
19
|
+
|
|
21
20
|
/**
|
|
22
21
|
* Adds asynchronously an header to a request through an interceptor.
|
|
23
22
|
*
|
|
@@ -27,7 +26,6 @@ const addHeaderInterceptor = (key, value) => request => {
|
|
|
27
26
|
*
|
|
28
27
|
* @internal
|
|
29
28
|
*/
|
|
30
|
-
|
|
31
29
|
const addAsyncHeaderInterceptor = (key, getter) => async request => addHeaderInterceptor(key, await getter())(request);
|
|
32
30
|
|
|
33
31
|
export { addAsyncHeaderInterceptor, addHeaderInterceptor };
|
|
@@ -14,11 +14,9 @@ class ConsoleLogger {
|
|
|
14
14
|
if (prefix === void 0) {
|
|
15
15
|
prefix = '';
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
if (output === void 0) {
|
|
19
18
|
output = console;
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
this.logLevel = logLevel;
|
|
23
21
|
this.prefix = prefix;
|
|
24
22
|
this.output = output;
|
|
@@ -29,13 +27,13 @@ class ConsoleLogger {
|
|
|
29
27
|
this.warn = this.makeMethod('warn');
|
|
30
28
|
this.level = LevelResolver[this.logLevel];
|
|
31
29
|
}
|
|
32
|
-
|
|
33
30
|
makeMethod(method) {
|
|
34
31
|
return message => {
|
|
35
|
-
if (shouldLog(this.level, method))
|
|
32
|
+
if (shouldLog(this.level, method)) {
|
|
33
|
+
this.output[method](this.prefix ? `${this.prefix} ${message}` : message);
|
|
34
|
+
}
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
export { ConsoleLogger };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ConsoleLogger } from './console-logger.js';
|
|
2
2
|
|
|
3
3
|
let sdkLogger = /*#__PURE__*/new ConsoleLogger('silent');
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Sets a logger to be used within the SDK.
|
|
6
7
|
*
|
|
@@ -8,10 +9,10 @@ let sdkLogger = /*#__PURE__*/new ConsoleLogger('silent');
|
|
|
8
9
|
*
|
|
9
10
|
* @public
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
12
|
const setLogger = logger => {
|
|
13
13
|
sdkLogger = logger;
|
|
14
14
|
};
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* Sets the logger to console logger with given logLevel (log is disabled by default).
|
|
17
18
|
*
|
|
@@ -20,24 +21,21 @@ const setLogger = logger => {
|
|
|
20
21
|
*
|
|
21
22
|
* @public
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
24
|
const enableConsoleLogger = function (logLevel, prefix) {
|
|
25
25
|
if (logLevel === void 0) {
|
|
26
26
|
logLevel = 'warn';
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
if (prefix === void 0) {
|
|
30
29
|
prefix = 'scaleway-sdk-js:';
|
|
31
30
|
}
|
|
32
|
-
|
|
33
31
|
return setLogger(new ConsoleLogger(logLevel, prefix));
|
|
34
32
|
};
|
|
33
|
+
|
|
35
34
|
/**
|
|
36
35
|
* Returns the active SDK logger.
|
|
37
36
|
*
|
|
38
37
|
* @internal
|
|
39
38
|
*/
|
|
40
|
-
|
|
41
39
|
const getLogger = () => sdkLogger;
|
|
42
40
|
|
|
43
41
|
export { enableConsoleLogger, getLogger, setLogger };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line eslint-comments/disable-enable-pair
|
|
2
|
-
|
|
3
2
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
4
3
|
let LevelResolver;
|
|
5
|
-
|
|
6
4
|
(function (LevelResolver) {
|
|
7
5
|
LevelResolver[LevelResolver["silent"] = 0] = "silent";
|
|
8
6
|
LevelResolver[LevelResolver["error"] = 1] = "error";
|
|
@@ -10,7 +8,6 @@ let LevelResolver;
|
|
|
10
8
|
LevelResolver[LevelResolver["info"] = 3] = "info";
|
|
11
9
|
LevelResolver[LevelResolver["debug"] = 4] = "debug";
|
|
12
10
|
})(LevelResolver || (LevelResolver = {}));
|
|
13
|
-
|
|
14
11
|
const shouldLog = (currentLevel, level) => LevelResolver[level] <= currentLevel;
|
|
15
12
|
|
|
16
13
|
export { LevelResolver, shouldLog };
|
|
@@ -2,38 +2,36 @@ const isAccessKeyRegex = /^SCW[A-Z0-9]{17}$/i;
|
|
|
2
2
|
const isRegionRegex = /^[a-z]{2}-[a-z]{3}$/i;
|
|
3
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
4
|
const isZoneRegex = /^[a-z]{2}-[a-z]{3}-[1-9]$/i;
|
|
5
|
-
/** Returns true if the given string has a valid UUID format. */
|
|
6
5
|
|
|
6
|
+
/** Returns true if the given string has a valid UUID format. */
|
|
7
7
|
const isUUID = str => isUUIDRegex.test(str);
|
|
8
|
-
/** Returns true if the given string has a valid Scaleway access key format. */
|
|
9
8
|
|
|
9
|
+
/** Returns true if the given string has a valid Scaleway access key format. */
|
|
10
10
|
const isAccessKey = str => isAccessKeyRegex.test(str);
|
|
11
|
-
/** Returns true if the given string has a valid Scaleway secret key format. */
|
|
12
11
|
|
|
12
|
+
/** Returns true if the given string has a valid Scaleway secret key format. */
|
|
13
13
|
const isSecretKey = str => isUUID(str);
|
|
14
|
-
/** Returns true if the given string has a valid Scaleway organization ID format. */
|
|
15
14
|
|
|
15
|
+
/** Returns true if the given string has a valid Scaleway organization ID format. */
|
|
16
16
|
const isOrganizationId = str => isUUID(str);
|
|
17
|
-
/** Returns true if the given string has a valid Scaleway project ID format. */
|
|
18
17
|
|
|
18
|
+
/** Returns true if the given string has a valid Scaleway project ID format. */
|
|
19
19
|
const isProjectId = str => isUUID(str);
|
|
20
|
-
/** Returns true if the given string has a valid region format. */
|
|
21
20
|
|
|
21
|
+
/** Returns true if the given string has a valid region format. */
|
|
22
22
|
const isRegion = str => isRegionRegex.test(str);
|
|
23
|
-
/** Returns true if the given string has a valid zone format. */
|
|
24
23
|
|
|
24
|
+
/** Returns true if the given string has a valid zone format. */
|
|
25
25
|
const isZone = str => isZoneRegex.test(str);
|
|
26
|
-
/** Returns true if the given string has a valid URL format and starts by `http(s):`. */
|
|
27
26
|
|
|
27
|
+
/** Returns true if the given string has a valid URL format and starts by `http(s):`. */
|
|
28
28
|
const isURL = str => {
|
|
29
29
|
let url;
|
|
30
|
-
|
|
31
30
|
try {
|
|
32
31
|
url = new URL(str);
|
|
33
32
|
} catch {
|
|
34
33
|
return false;
|
|
35
34
|
}
|
|
36
|
-
|
|
37
35
|
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
38
36
|
};
|
|
39
37
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const ADJECTIVES = ['admiring', 'adoring', 'affectionate', 'agitated', 'amazing', 'angry', 'awesome', 'beautiful', 'blissful', 'bold', 'boring', 'brave', 'busy', 'charming', 'clever', 'cool', 'compassionate', 'competent', 'condescending', 'confident', 'cranky', 'crazy', 'dazzling', 'determined', 'distracted', 'dreamy', 'eager', 'ecstatic', 'elastic', 'elated', 'elegant', 'eloquent', 'epic', 'exciting', 'fervent', 'festive', 'flamboyant', 'focused', 'friendly', 'frosty', 'funny', 'gallant', 'gifted', 'goofy', 'gracious', 'great', 'happy', 'hardcore', 'heuristic', 'hopeful', 'hungry', 'infallible', 'inspiring', 'interesting', 'intelligent', 'jolly', 'jovial', 'keen', 'kind', 'laughing', 'loving', 'lucid', 'magical', 'mystifying', 'modest', 'musing', 'naughty', 'nervous', 'nice', 'nifty', 'nostalgic', 'objective', 'optimistic', 'peaceful', 'pedantic', 'pensive', 'practical', 'priceless', 'quirky', 'quizzical', 'recursing', 'relaxed', 'reverent', 'romantic', 'sad', 'serene', 'sharp', 'silly', 'sleepy', 'stoic', 'strange', 'stupefied', 'suspicious', 'sweet', 'tender', 'thirsty', 'trusting', 'unruffled', 'upbeat', 'vibrant', 'vigilant', 'vigorous', 'wizardly', 'wonderful', 'xenodochial', 'youthful', 'zealous', 'zen'];
|
|
2
|
+
const NAMES = ['albattani', 'allen', 'almeida', 'antonelli', 'agnesi', 'archimedes', 'ardinghelli', 'aryabhata', 'austin', 'babbage', 'banach', 'banzai', 'bardeen', 'bartik', 'bassi', 'beaver', 'bell', 'benz', 'bhabha', 'bhaskara', 'black', 'blackburn', 'blackwell', 'bohr', 'booth', 'borg', 'bose', 'bouman', 'boyd', 'brahmagupta', 'brattain', 'brown', 'buck', 'burnell', 'cannon', 'carson', 'cartwright', 'carver', 'cerf', 'chandrasekhar', 'chaplygin', 'chatelet', 'chatterjee', 'chebyshev', 'cohen', 'chaum', 'clarke', 'colden', 'cori', 'cray', 'curran', 'curie', 'darwin', 'davinci', 'dewdney', 'dhawan', 'diffie', 'dijkstra', 'dirac', 'driscoll', 'dubinsky', 'easley', 'edison', 'einstein', 'elbakyan', 'elgamal', 'elion', 'ellis', 'engelbart', 'euclid', 'euler', 'faraday', 'feistel', 'fermat', 'fermi', 'feynman', 'franklin', 'gagarin', 'galileo', 'galois', 'ganguly', 'gates', 'gauss', 'germain', 'goldberg', 'goldstine', 'goldwasser', 'golick', 'goodall', 'gould', 'greider', 'grothendieck', 'haibt', 'hamilton', 'haslett', 'hawking', 'hellman', 'heisenberg', 'hermann', 'herschel', 'hertz', 'heyrovsky', 'hodgkin', 'hofstadter', 'hoover', 'hopper', 'hugle', 'hypatia', 'ishizaka', 'jackson', 'jang', 'jemison', 'jennings', 'jepsen', 'johnson', 'joliot', 'jones', 'kalam', 'kapitsa', 'kare', 'keldysh', 'keller', 'kepler', 'khayyam', 'khorana', 'kilby', 'kirch', 'knuth', 'kowalevski', 'lalande', 'lamarr', 'lamport', 'leakey', 'leavitt', 'lederberg', 'lehmann', 'lewin', 'lichterman', 'liskov', 'lovelace', 'lumiere', 'mahavira', 'margulis', 'matsumoto', 'maxwell', 'mayer', 'mccarthy', 'mcclintock', 'mclaren', 'mclean', 'mcnulty', 'mendel', 'mendeleev', 'meitner', 'meninsky', 'merkle', 'mestorf', 'mirzakhani', 'montalcini', 'moore', 'morse', 'murdock', 'moser', 'napier', 'nash', 'neumann', 'newton', 'nightingale', 'nobel', 'noether', 'northcutt', 'noyce', 'panini', 'pare', 'pascal', 'pasteur', 'payne', 'perlman', 'pike', 'poincare', 'poitras', 'proskuriakova', 'ptolemy', 'raman', 'ramanujan', 'ride', 'ritchie', 'rhodes', 'robinson', 'roentgen', 'rosalind', 'rubin', 'saha', 'sammet', 'sanderson', 'satoshi', 'shamir', 'shannon', 'shaw', 'shirley', 'shockley', 'shtern', 'sinoussi', 'snyder', 'solomon', 'spence', 'stonebraker', 'sutherland', 'swanson', 'swartz', 'swirles', 'taussig', 'tereshkova', 'tesla', 'tharp', 'thompson', 'torvalds', 'tu', 'turing', 'varahamihira', 'vaughan', 'visvesvaraya', 'volhard', 'villani', 'wescoff', 'wilbur', 'wiles', 'williams', 'williamson', 'wilson', 'wing', 'wozniak', 'wright', 'wu', 'yalow', 'yonath', 'zhukovsky'];
|
|
3
|
+
const randomName = function () {
|
|
4
|
+
let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
5
|
+
let separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '-';
|
|
6
|
+
const name = `${ADJECTIVES[Math.floor(Math.random() * ADJECTIVES.length)] ?? ''}${separator}${NAMES[Math.floor(Math.random() * NAMES.length)] ?? ''}`;
|
|
7
|
+
if (name === `boring${separator}wozniak`) {
|
|
8
|
+
return randomName(prefix, separator);
|
|
9
|
+
}
|
|
10
|
+
return prefix.length > 0 ? `${prefix}${separator}${name}` : name;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { randomName as default };
|
package/dist/scw/api.js
CHANGED
package/dist/scw/auth.js
CHANGED
|
@@ -3,7 +3,6 @@ import { assertValidAuthenticationSecrets } from './client-ini-profile.js';
|
|
|
3
3
|
|
|
4
4
|
const SESSION_HEADER_KEY = 'x-session-token';
|
|
5
5
|
const AUTH_HEADER_KEY = 'x-auth-token';
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Authenticates with a session token.
|
|
9
8
|
*
|
|
@@ -13,6 +12,7 @@ const AUTH_HEADER_KEY = 'x-auth-token';
|
|
|
13
12
|
* @internal
|
|
14
13
|
*/
|
|
15
14
|
const authenticateWithSessionToken = getToken => addAsyncHeaderInterceptor(SESSION_HEADER_KEY, getToken);
|
|
15
|
+
|
|
16
16
|
/**
|
|
17
17
|
* Authenticates with a secrets.
|
|
18
18
|
*
|
|
@@ -24,11 +24,11 @@ const authenticateWithSessionToken = getToken => addAsyncHeaderInterceptor(SESSI
|
|
|
24
24
|
*
|
|
25
25
|
* @internal
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
27
|
const authenticateWithSecrets = secrets => {
|
|
29
28
|
assertValidAuthenticationSecrets(secrets);
|
|
30
29
|
return addHeaderInterceptor(AUTH_HEADER_KEY, secrets.secretKey);
|
|
31
30
|
};
|
|
31
|
+
|
|
32
32
|
/**
|
|
33
33
|
* Obfuscates a token.
|
|
34
34
|
*
|
|
@@ -37,8 +37,8 @@ const authenticateWithSecrets = secrets => {
|
|
|
37
37
|
*
|
|
38
38
|
* @internal
|
|
39
39
|
*/
|
|
40
|
-
|
|
41
40
|
const obfuscateToken = key => `${key.substring(0, 5)}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`;
|
|
41
|
+
|
|
42
42
|
/**
|
|
43
43
|
* Obfuscates an UUID.
|
|
44
44
|
*
|
|
@@ -47,9 +47,7 @@ const obfuscateToken = key => `${key.substring(0, 5)}xxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
47
47
|
*
|
|
48
48
|
* @internal
|
|
49
49
|
*/
|
|
50
|
-
|
|
51
50
|
const obfuscateUUID = key => `${key.substring(0, 8)}-xxxx-xxxx-xxxx-xxxxxxxxxxxx`;
|
|
52
|
-
|
|
53
51
|
/**
|
|
54
52
|
* Obfuscates headers entry.
|
|
55
53
|
*
|
|
@@ -12,16 +12,30 @@ import { hasAuthenticationSecrets } from './client-ini-profile.js';
|
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
14
|
const withProfile = profile => settings => {
|
|
15
|
-
const newSettings = {
|
|
15
|
+
const newSettings = {
|
|
16
|
+
...settings
|
|
16
17
|
};
|
|
17
|
-
if (profile.apiURL)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (profile.
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
if (profile.apiURL) {
|
|
19
|
+
newSettings.apiURL = profile.apiURL;
|
|
20
|
+
}
|
|
21
|
+
if (profile.defaultOrganizationId) {
|
|
22
|
+
newSettings.defaultOrganizationId = profile.defaultOrganizationId;
|
|
23
|
+
}
|
|
24
|
+
if (profile.defaultProjectId) {
|
|
25
|
+
newSettings.defaultProjectId = profile.defaultProjectId;
|
|
26
|
+
}
|
|
27
|
+
if (profile.defaultRegion) {
|
|
28
|
+
newSettings.defaultRegion = profile.defaultRegion;
|
|
29
|
+
}
|
|
30
|
+
if (profile.defaultZone) {
|
|
31
|
+
newSettings.defaultZone = profile.defaultZone;
|
|
32
|
+
}
|
|
33
|
+
if (hasAuthenticationSecrets(profile)) {
|
|
34
|
+
newSettings.requestInterceptors = [authenticateWithSecrets(profile), ...settings.requestInterceptors];
|
|
35
|
+
}
|
|
23
36
|
return newSettings;
|
|
24
37
|
};
|
|
38
|
+
|
|
25
39
|
/**
|
|
26
40
|
* Instantiates the SDK with a different HTTP client.
|
|
27
41
|
*
|
|
@@ -32,10 +46,11 @@ const withProfile = profile => settings => {
|
|
|
32
46
|
*
|
|
33
47
|
* @public
|
|
34
48
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
const withHTTPClient = httpClient => settings => ({
|
|
50
|
+
...settings,
|
|
37
51
|
httpClient
|
|
38
52
|
});
|
|
53
|
+
|
|
39
54
|
/**
|
|
40
55
|
* Instantiates the SDK with a default page size.
|
|
41
56
|
*
|
|
@@ -46,10 +61,11 @@ const withHTTPClient = httpClient => settings => ({ ...settings,
|
|
|
46
61
|
*
|
|
47
62
|
* @public
|
|
48
63
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
const withDefaultPageSize = defaultPageSize => settings => ({
|
|
65
|
+
...settings,
|
|
51
66
|
defaultPageSize
|
|
52
67
|
});
|
|
68
|
+
|
|
53
69
|
/**
|
|
54
70
|
* Instantiates the SDK with a different default user agent.
|
|
55
71
|
*
|
|
@@ -60,10 +76,11 @@ const withDefaultPageSize = defaultPageSize => settings => ({ ...settings,
|
|
|
60
76
|
*
|
|
61
77
|
* @public
|
|
62
78
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
79
|
+
const withUserAgent = userAgent => settings => ({
|
|
80
|
+
...settings,
|
|
65
81
|
userAgent
|
|
66
82
|
});
|
|
83
|
+
|
|
67
84
|
/**
|
|
68
85
|
* Instantiates the SDK with an additional user agent.
|
|
69
86
|
*
|
|
@@ -74,8 +91,8 @@ const withUserAgent = userAgent => settings => ({ ...settings,
|
|
|
74
91
|
*
|
|
75
92
|
* @public
|
|
76
93
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
const withUserAgentSuffix = userAgent => settings => ({
|
|
95
|
+
...settings,
|
|
79
96
|
userAgent: settings.userAgent ? `${settings.userAgent} ${userAgent}` : userAgent
|
|
80
97
|
});
|
|
81
98
|
|
|
@@ -9,6 +9,7 @@ import { isAccessKey, isSecretKey } from '../internal/validations/string-validat
|
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
const hasAuthenticationSecrets = obj => typeof obj.accessKey === 'string' && obj.accessKey !== '' && typeof obj.secretKey === 'string' && obj.secretKey !== '';
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Asserts the format of secrets.
|
|
14
15
|
*
|
|
@@ -20,11 +21,16 @@ const hasAuthenticationSecrets = obj => typeof obj.accessKey === 'string' && obj
|
|
|
20
21
|
*
|
|
21
22
|
* @internal
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
24
|
function assertValidAuthenticationSecrets(obj) {
|
|
25
|
-
if (!(obj.accessKey && obj.secretKey))
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (!(obj.accessKey && obj.secretKey)) {
|
|
26
|
+
throw new Error(`Invalid secrets, accessKey & secretKey must be defined. See https://www.scaleway.com/en/docs/console/my-project/how-to/generate-api-key/`);
|
|
27
|
+
}
|
|
28
|
+
if (!isAccessKey(obj.accessKey)) {
|
|
29
|
+
throw new Error(`Invalid access key format '${obj.accessKey}', expected SCWXXXXXXXXXXXXXXXXX format. See https://www.scaleway.com/en/docs/console/my-project/how-to/generate-api-key/`);
|
|
30
|
+
}
|
|
31
|
+
if (!isSecretKey(obj.secretKey)) {
|
|
32
|
+
throw new Error(`Invalid secret key format '${obj.secretKey}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. See https://www.scaleway.com/en/docs/console/my-project/how-to/generate-api-key/`);
|
|
33
|
+
}
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
export { assertValidAuthenticationSecrets, hasAuthenticationSecrets };
|
|
@@ -14,36 +14,53 @@ const assertValidSettings = obj => {
|
|
|
14
14
|
if (typeof obj.defaultOrganizationId !== 'string' || obj.defaultOrganizationId.length === 0) {
|
|
15
15
|
throw new Error('Default organization ID cannot be empty');
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
if (isOrganizationId(obj.defaultOrganizationId) !== true) {
|
|
17
|
+
if (!isOrganizationId(obj.defaultOrganizationId)) {
|
|
19
18
|
throw new Error(`Invalid organization ID format '${obj.defaultOrganizationId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`);
|
|
20
19
|
}
|
|
21
|
-
}
|
|
22
|
-
|
|
20
|
+
}
|
|
23
21
|
|
|
22
|
+
// Default Project ID.
|
|
24
23
|
if (obj.defaultProjectId !== undefined) {
|
|
25
24
|
if (typeof obj.defaultProjectId !== 'string' || obj.defaultProjectId.length === 0) {
|
|
26
25
|
throw new Error('Default project ID cannot be empty');
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
if (isProjectId(obj.defaultProjectId) !== true) {
|
|
27
|
+
if (!isProjectId(obj.defaultProjectId)) {
|
|
30
28
|
throw new Error(`Invalid project ID format '${obj.defaultProjectId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`);
|
|
31
29
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
30
|
+
}
|
|
34
31
|
|
|
35
|
-
|
|
32
|
+
// Default Region.
|
|
33
|
+
if (obj.defaultRegion && !isRegion(obj.defaultRegion)) {
|
|
34
|
+
throw new Error(`Invalid default region format '${obj.defaultRegion}'`);
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
// Default Zone.
|
|
38
|
+
if (obj.defaultZone && !isZone(obj.defaultZone)) {
|
|
39
|
+
throw new Error(`Invalid default zone format '${obj.defaultZone}'`);
|
|
40
|
+
}
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
if (obj.apiURL
|
|
42
|
+
// API URL.
|
|
43
|
+
if (!isURL(obj.apiURL)) {
|
|
44
|
+
throw new Error(`Invalid URL ${obj.apiURL}`);
|
|
45
|
+
}
|
|
46
|
+
if (obj.apiURL.endsWith('/')) {
|
|
47
|
+
throw new Error(`Invalid URL ${obj.apiURL}: it should not have a trailing slash`);
|
|
48
|
+
}
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
// HTTP Client.
|
|
51
|
+
if (typeof obj.httpClient !== typeof fetch) {
|
|
52
|
+
throw new Error(`Invalid HTTP Client`);
|
|
53
|
+
}
|
|
43
54
|
|
|
44
|
-
|
|
55
|
+
// Default Page Size.
|
|
56
|
+
if (obj.defaultPageSize !== undefined && (typeof obj.defaultPageSize !== 'number' || Number.isNaN(obj.defaultPageSize) || obj.defaultPageSize <= 0)) {
|
|
57
|
+
throw new Error(`Invalid defaultPageSize ${obj.defaultPageSize}: it should be a number above 0`);
|
|
58
|
+
}
|
|
45
59
|
|
|
46
|
-
|
|
60
|
+
// User Agent.
|
|
61
|
+
if (typeof obj.userAgent !== 'string') {
|
|
62
|
+
throw new Error(`Invalid User-Agent`);
|
|
63
|
+
}
|
|
47
64
|
};
|
|
48
65
|
|
|
49
66
|
export { assertValidSettings };
|
package/dist/scw/client.js
CHANGED
|
@@ -12,6 +12,7 @@ const DEFAULT_SETTINGS = {
|
|
|
12
12
|
responseInterceptors: [],
|
|
13
13
|
userAgent
|
|
14
14
|
};
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* Scaleway client.
|
|
17
18
|
*/
|
|
@@ -44,20 +45,20 @@ const createAdvancedClient = function () {
|
|
|
44
45
|
for (var _len = arguments.length, configs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
45
46
|
configs[_key] = arguments[_key];
|
|
46
47
|
}
|
|
47
|
-
|
|
48
48
|
const settings = configs.reduce((currentSettings, config) => config(currentSettings), DEFAULT_SETTINGS);
|
|
49
49
|
assertValidSettings(settings);
|
|
50
50
|
getLogger().info(`init Scaleway SDK version ${version}`);
|
|
51
51
|
return {
|
|
52
|
-
fetch: buildFetcher(settings,
|
|
52
|
+
fetch: buildFetcher(settings, settings.httpClient),
|
|
53
53
|
settings
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
|
+
|
|
56
57
|
/**
|
|
57
58
|
* Creates a Scaleway client with a profile.
|
|
58
59
|
*
|
|
59
60
|
* @example
|
|
60
|
-
* Creates a client with credentials & default values (see https://www.scaleway.com/docs/console/my-project/how-to/generate-api-key):
|
|
61
|
+
* Creates a client with credentials & default values (see https://www.scaleway.com/en/docs/console/my-project/how-to/generate-api-key/):
|
|
61
62
|
* ```
|
|
62
63
|
* import { createClient } from '@scaleway/sdk'
|
|
63
64
|
*
|
|
@@ -72,7 +73,7 @@ const createAdvancedClient = function () {
|
|
|
72
73
|
*
|
|
73
74
|
* @example
|
|
74
75
|
* Creates a client by loading values from the environment (see https://www.scaleway.com/en/docs/console/my-project/how-to/generate-api-key/#how-to-use-your-api-key)
|
|
75
|
-
* or the config file created by CLI `scw init` (see https://www.scaleway.com/cli):
|
|
76
|
+
* or the config file created by CLI `scw init` (see https://www.scaleway.com/en/cli/):
|
|
76
77
|
* ```
|
|
77
78
|
* import { loadProfileFromConfigurationFile } from '@scaleway/configuration-loader'
|
|
78
79
|
* import { createClient } from '@scaleway/sdk'
|
|
@@ -88,12 +89,10 @@ const createAdvancedClient = function () {
|
|
|
88
89
|
*
|
|
89
90
|
* @public
|
|
90
91
|
*/
|
|
91
|
-
|
|
92
92
|
const createClient = function (profile) {
|
|
93
93
|
if (profile === void 0) {
|
|
94
94
|
profile = {};
|
|
95
95
|
}
|
|
96
|
-
|
|
97
96
|
return createAdvancedClient(withProfile(profile));
|
|
98
97
|
};
|
|
99
98
|
|
package/dist/scw/constants.js
CHANGED