@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
|
@@ -6,24 +6,22 @@ const unmarshalMoney = data => {
|
|
|
6
6
|
if (!isJSONObject(data)) {
|
|
7
7
|
throw new TypeError(`Unmarshalling the type 'Money' failed as data isn't a dictionary.`);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
9
|
return {
|
|
11
10
|
currencyCode: data.currency_code,
|
|
12
11
|
nanos: data.nanos,
|
|
13
12
|
units: data.units
|
|
14
13
|
};
|
|
15
14
|
};
|
|
15
|
+
|
|
16
16
|
/**
|
|
17
17
|
* Unmarshals {@link ServiceInfo}.
|
|
18
18
|
*
|
|
19
19
|
* @internal
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
21
|
const unmarshalServiceInfo = data => {
|
|
23
22
|
if (!isJSONObject(data)) {
|
|
24
23
|
throw new TypeError(`Unmarshalling the type 'ServiceInfo' failed as data isn't a dictionary.`);
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
return {
|
|
28
26
|
description: data.description,
|
|
29
27
|
documentationUrl: data.documentation_url,
|
|
@@ -31,23 +29,23 @@ const unmarshalServiceInfo = data => {
|
|
|
31
29
|
version: data.version
|
|
32
30
|
};
|
|
33
31
|
};
|
|
32
|
+
|
|
34
33
|
/**
|
|
35
34
|
* Unmarshals {@link ScwFile}.
|
|
36
35
|
*
|
|
37
36
|
* @internal
|
|
38
37
|
*/
|
|
39
|
-
|
|
40
38
|
const unmarshalScwFile = data => {
|
|
41
39
|
if (!isJSONObject(data)) {
|
|
42
40
|
throw new TypeError(`Unmarshalling the type 'ScwFile' failed as data isn't a dictionary.`);
|
|
43
41
|
}
|
|
44
|
-
|
|
45
42
|
return {
|
|
46
43
|
content: data.content,
|
|
47
44
|
contentType: data.content_type,
|
|
48
45
|
name: data.name
|
|
49
46
|
};
|
|
50
47
|
};
|
|
48
|
+
|
|
51
49
|
/**
|
|
52
50
|
* Unmarshals {@link TimeSeriesPoint}
|
|
53
51
|
*
|
|
@@ -57,76 +55,72 @@ const unmarshalScwFile = data => {
|
|
|
57
55
|
*
|
|
58
56
|
* @internal
|
|
59
57
|
*/
|
|
60
|
-
|
|
61
58
|
const unmarshalTimeSeriesPoint = data => {
|
|
62
59
|
if (!Array.isArray(data)) {
|
|
63
60
|
throw new TypeError(`Unmarshalling the type 'TimeSeriesPoint' failed as data isn't an array.`);
|
|
64
61
|
}
|
|
65
|
-
|
|
66
62
|
return {
|
|
67
63
|
timestamp: unmarshalDate(data[0]),
|
|
68
64
|
value: data[1]
|
|
69
65
|
};
|
|
70
66
|
};
|
|
67
|
+
|
|
71
68
|
/**
|
|
72
69
|
* Unmarshals {@link TimeSeries}
|
|
73
70
|
*
|
|
74
71
|
* @internal
|
|
75
72
|
*/
|
|
76
|
-
|
|
77
73
|
const unmarshalTimeSeries = data => {
|
|
78
74
|
if (!isJSONObject(data)) {
|
|
79
75
|
throw new TypeError(`Unmarshalling the type 'TimeSeries' failed as data isn't a dictionary.`);
|
|
80
76
|
}
|
|
81
|
-
|
|
82
77
|
return {
|
|
83
78
|
metadata: data.metadata,
|
|
84
79
|
name: data.name,
|
|
85
80
|
points: unmarshalArrayOfObject(data.points, unmarshalTimeSeriesPoint)
|
|
86
81
|
};
|
|
87
82
|
};
|
|
83
|
+
|
|
88
84
|
/**
|
|
89
85
|
* Marshals {@link ScwFile}.
|
|
90
86
|
*
|
|
91
87
|
* @internal
|
|
92
88
|
*/
|
|
93
|
-
|
|
94
89
|
const marshalScwFile = obj => ({
|
|
95
90
|
content: obj.content,
|
|
96
91
|
content_type: obj.contentType,
|
|
97
92
|
name: obj.name
|
|
98
93
|
});
|
|
94
|
+
|
|
99
95
|
/**
|
|
100
96
|
* Marshals {@link Money}
|
|
101
97
|
*
|
|
102
98
|
* @internal
|
|
103
99
|
*/
|
|
104
|
-
|
|
105
100
|
const marshalMoney = obj => ({
|
|
106
101
|
currency_code: obj.currencyCode,
|
|
107
102
|
nanos: obj.nanos,
|
|
108
103
|
units: obj.units
|
|
109
104
|
});
|
|
105
|
+
|
|
110
106
|
/**
|
|
111
107
|
* Marshals {@link TimeSeriesPoint}
|
|
112
108
|
*
|
|
113
109
|
* @internal
|
|
114
110
|
*/
|
|
115
|
-
|
|
116
111
|
const marshalTimeSeriesPoint = obj => {
|
|
117
112
|
var _obj$timestamp;
|
|
118
|
-
|
|
119
113
|
return {
|
|
120
114
|
timestamp: (_obj$timestamp = obj.timestamp) == null ? void 0 : _obj$timestamp.toISOString(),
|
|
121
115
|
value: obj.value
|
|
122
116
|
};
|
|
123
117
|
};
|
|
118
|
+
|
|
124
119
|
/**
|
|
125
120
|
* Marshals {@link TimeSeries}
|
|
126
121
|
*
|
|
127
122
|
* @internal
|
|
128
123
|
*/
|
|
129
|
-
|
|
130
124
|
const marshalTimeSeries = obj => ({
|
|
131
125
|
metadata: obj.metadata,
|
|
132
126
|
name: obj.name,
|
|
@@ -24,65 +24,51 @@ import { TransientStateError } from './standard/transient-state-error.js';
|
|
|
24
24
|
*
|
|
25
25
|
* @internal
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
27
|
const unmarshalStandardError = (type, status, body) => {
|
|
29
28
|
let error;
|
|
30
|
-
|
|
31
29
|
switch (type) {
|
|
32
30
|
case 'denied_authentication':
|
|
33
31
|
error = DeniedAuthenticationError;
|
|
34
32
|
break;
|
|
35
|
-
|
|
36
33
|
case 'invalid_arguments':
|
|
37
34
|
error = InvalidArgumentsError;
|
|
38
35
|
break;
|
|
39
|
-
|
|
40
36
|
case 'out_of_stock':
|
|
41
37
|
error = OutOfStockError;
|
|
42
38
|
break;
|
|
43
|
-
|
|
44
39
|
case 'permissions_denied':
|
|
45
40
|
error = PermissionsDeniedError;
|
|
46
41
|
break;
|
|
47
|
-
|
|
48
42
|
case 'precondition_failed':
|
|
49
43
|
error = PreconditionFailedError;
|
|
50
44
|
break;
|
|
51
|
-
|
|
52
45
|
case 'quotas_exceeded':
|
|
53
46
|
error = QuotasExceededError;
|
|
54
47
|
break;
|
|
55
|
-
|
|
56
48
|
case 'expired':
|
|
57
49
|
error = ResourceExpiredError;
|
|
58
50
|
break;
|
|
59
|
-
|
|
60
51
|
case 'not_found':
|
|
61
52
|
error = ResourceNotFoundError;
|
|
62
53
|
break;
|
|
63
|
-
|
|
64
54
|
case 'locked':
|
|
65
55
|
error = ResourceLockedError;
|
|
66
56
|
break;
|
|
67
|
-
|
|
68
57
|
case 'transient_state':
|
|
69
58
|
error = TransientStateError;
|
|
70
59
|
break;
|
|
71
|
-
|
|
72
60
|
case 'already_exists':
|
|
73
61
|
error = AlreadyExistsError;
|
|
74
62
|
break;
|
|
75
|
-
|
|
76
63
|
case 'too_many_requests':
|
|
77
64
|
error = TooManyRequestsError;
|
|
78
65
|
break;
|
|
79
|
-
|
|
80
66
|
default:
|
|
81
67
|
return null;
|
|
82
68
|
}
|
|
83
|
-
|
|
84
69
|
return error.fromJSON(status, body);
|
|
85
70
|
};
|
|
71
|
+
|
|
86
72
|
/**
|
|
87
73
|
* Unmarshals a non-standard error from raw body.
|
|
88
74
|
*
|
|
@@ -93,20 +79,17 @@ const unmarshalStandardError = (type, status, body) => {
|
|
|
93
79
|
*
|
|
94
80
|
* @internal
|
|
95
81
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
82
|
const unmarshalNonStandardError = (type, status, body) => {
|
|
99
83
|
switch (type) {
|
|
100
84
|
case 'unknown_resource':
|
|
101
85
|
return UnknownResourceMapper.fromJSON(status, body);
|
|
102
|
-
|
|
103
86
|
case 'invalid_request_error':
|
|
104
87
|
return InvalidRequestMapper.fromJSON(status, body);
|
|
105
|
-
|
|
106
88
|
default:
|
|
107
89
|
return null;
|
|
108
90
|
}
|
|
109
91
|
};
|
|
92
|
+
|
|
110
93
|
/**
|
|
111
94
|
* Parses Scaleway error from raw body.
|
|
112
95
|
*
|
|
@@ -116,8 +99,6 @@ const unmarshalNonStandardError = (type, status, body) => {
|
|
|
116
99
|
*
|
|
117
100
|
* @internal
|
|
118
101
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
102
|
const parseScalewayError = (status, body) => {
|
|
122
103
|
const parsableError = typeof body.type === 'string' && (unmarshalStandardError(body.type, status, body) ?? unmarshalNonStandardError(body.type, status, body));
|
|
123
104
|
return parsableError || new ScalewayError(status, body);
|
|
@@ -8,27 +8,29 @@ import { isRecordOfStringArray } from '../types.js';
|
|
|
8
8
|
*
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
11
|
class InvalidRequestMapper {
|
|
13
12
|
static fromJSON(status, obj) {
|
|
14
|
-
if (typeof obj.message === 'string' && obj.message.toLowerCase().includes('quota exceeded for this resource'))
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (typeof obj.message === 'string' && obj.message.toLowerCase().includes('quota exceeded for this resource')) {
|
|
14
|
+
return new QuotasExceededError(status, obj, [{
|
|
15
|
+
current: 0,
|
|
16
|
+
quota: 0,
|
|
17
|
+
resource: typeof obj.resource === 'string' ? obj.resource : ''
|
|
18
|
+
}]);
|
|
19
|
+
}
|
|
19
20
|
const fields = obj.fields && isRecordOfStringArray(obj.fields) ? obj.fields : {};
|
|
20
21
|
const fieldsMessages = Object.entries(fields);
|
|
21
|
-
if (fieldsMessages.length)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
if (fieldsMessages.length) {
|
|
23
|
+
return new InvalidArgumentsError(status, obj, fieldsMessages.map(_ref => {
|
|
24
|
+
let [argumentName, messages] = _ref;
|
|
25
|
+
return messages.map(helpMessage => ({
|
|
26
|
+
argumentName,
|
|
27
|
+
helpMessage,
|
|
28
|
+
reason: 'constraint'
|
|
29
|
+
}));
|
|
30
|
+
}).flat());
|
|
31
|
+
}
|
|
29
32
|
return new ScalewayError(status, obj);
|
|
30
33
|
}
|
|
31
|
-
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export { InvalidRequestMapper };
|
|
@@ -7,20 +7,21 @@ import { ResourceNotFoundError } from '../standard/resource-not-found-error.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
class UnknownResourceMapper {
|
|
12
11
|
static fromJSON(status, obj) {
|
|
13
12
|
// Split the message
|
|
14
13
|
// Note: some errors uses ' and not "
|
|
15
14
|
// Examples: `"111..." not found` or `Security Group '111...' not found`
|
|
16
15
|
const messageParts = typeof obj.message === 'string' ? obj.message.split(/"|'/) : [];
|
|
17
|
-
if (messageParts.length === 3 && isUUID(messageParts[1]))
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
if (messageParts.length === 3 && isUUID(messageParts[1])) {
|
|
17
|
+
return new ResourceNotFoundError(status, obj,
|
|
18
|
+
// transform `Security group ` to `security_group`
|
|
19
|
+
// `.replaceAll()` may be too recent to use yet.
|
|
20
|
+
// that's why we're using `.split(' ').join('_')` for now.
|
|
21
|
+
messageParts[0].trim().toLowerCase().split(' ').join('_'), messageParts[1]);
|
|
22
|
+
}
|
|
21
23
|
return new ScalewayError(status, obj);
|
|
22
24
|
}
|
|
23
|
-
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export { UnknownResourceMapper };
|
|
@@ -10,45 +10,43 @@ import { isRecordOfStringArray } from './types.js';
|
|
|
10
10
|
*
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
13
|
const buildDefaultMessage = (status, body) => {
|
|
15
14
|
const message = [`http error ${status}`];
|
|
16
|
-
|
|
17
15
|
if (typeof body === 'string') {
|
|
18
16
|
message.push(body);
|
|
19
17
|
} else if (isJSONObject(body)) {
|
|
20
|
-
if (typeof body.resource === 'string')
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
18
|
+
if (typeof body.resource === 'string') {
|
|
19
|
+
message.push(`resource ${body.resource}`);
|
|
20
|
+
}
|
|
21
|
+
if (typeof body.message === 'string') {
|
|
22
|
+
message.push(body.message);
|
|
23
|
+
}
|
|
24
|
+
if (body.fields && isRecordOfStringArray(body.fields)) {
|
|
25
|
+
message.push(Object.entries(body.fields).map(_ref => {
|
|
26
|
+
let [name, list] = _ref;
|
|
27
|
+
return `${name} (${list.join(', ')})`;
|
|
28
|
+
}).join(', '));
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
|
-
|
|
28
31
|
return message.join(': ');
|
|
29
32
|
};
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* Scaleway error.
|
|
32
36
|
*
|
|
33
37
|
* @public
|
|
34
38
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
39
|
class ScalewayError extends Error {
|
|
38
40
|
/** The message originating from the payload. */
|
|
39
|
-
|
|
40
|
-
/** The response status. */
|
|
41
|
-
status,
|
|
42
|
-
/** The
|
|
43
|
-
body,
|
|
44
|
-
/** The augmented message. */
|
|
41
|
+
|
|
42
|
+
constructor( /** The response status. */
|
|
43
|
+
status, /** The response payload. */
|
|
44
|
+
body, /** The augmented message. */
|
|
45
45
|
message) {
|
|
46
46
|
if (message === void 0) {
|
|
47
47
|
message = buildDefaultMessage(status, body);
|
|
48
48
|
}
|
|
49
|
-
|
|
50
49
|
super(message); // 'Error' breaks prototype chain here
|
|
51
|
-
|
|
52
50
|
this.status = status;
|
|
53
51
|
this.body = body;
|
|
54
52
|
this.message = message;
|
|
@@ -61,7 +59,9 @@ class ScalewayError extends Error {
|
|
|
61
59
|
static fromJSON(status, obj) {
|
|
62
60
|
return new ScalewayError(status, obj);
|
|
63
61
|
}
|
|
64
|
-
|
|
62
|
+
toString() {
|
|
63
|
+
return `${this.name}: ${this.message}`;
|
|
64
|
+
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export { ScalewayError };
|
|
@@ -5,7 +5,6 @@ import { ScalewayError } from '../scw-error.js';
|
|
|
5
5
|
*
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
class AlreadyExistsError extends ScalewayError {
|
|
10
9
|
constructor(status, body, resource, resourceId, helpMessage) {
|
|
11
10
|
super(status, body, `resource ${resource} with ID ${resourceId} already exists: ${helpMessage}`);
|
|
@@ -16,12 +15,12 @@ class AlreadyExistsError extends ScalewayError {
|
|
|
16
15
|
this.helpMessage = helpMessage;
|
|
17
16
|
this.name = 'AlreadyExistsError';
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
static fromJSON(status, obj) {
|
|
21
|
-
if (typeof obj.resource !== 'string' || typeof obj.resource_id !== 'string' || typeof obj.help_message !== 'string')
|
|
19
|
+
if (typeof obj.resource !== 'string' || typeof obj.resource_id !== 'string' || typeof obj.help_message !== 'string') {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
22
|
return new AlreadyExistsError(status, obj, obj.resource, obj.resource_id, obj.help_message);
|
|
23
23
|
}
|
|
24
|
-
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export { AlreadyExistsError };
|
|
@@ -9,36 +9,29 @@ import { ScalewayError } from '../scw-error.js';
|
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
12
|
const buildMessage = (method, reason) => {
|
|
14
13
|
let reasonDesc;
|
|
15
|
-
|
|
16
14
|
switch (reason) {
|
|
17
15
|
case 'invalid_argument':
|
|
18
16
|
reasonDesc = `invalid ${method} format or empty value`;
|
|
19
17
|
break;
|
|
20
|
-
|
|
21
18
|
case 'not_found':
|
|
22
19
|
reasonDesc = `${method} does not exist`;
|
|
23
20
|
break;
|
|
24
|
-
|
|
25
21
|
case 'expired':
|
|
26
22
|
reasonDesc = `${method} is expired`;
|
|
27
23
|
break;
|
|
28
|
-
|
|
29
24
|
default:
|
|
30
25
|
reasonDesc = `unknown reason for ${method}`;
|
|
31
26
|
}
|
|
32
|
-
|
|
33
27
|
return `denied authentication: ${reasonDesc}`;
|
|
34
28
|
};
|
|
29
|
+
|
|
35
30
|
/**
|
|
36
31
|
* DeniedAuthentication error is used by the API Gateway auth service to deny a request.
|
|
37
32
|
*
|
|
38
33
|
* @public
|
|
39
34
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
35
|
class DeniedAuthenticationError extends ScalewayError {
|
|
43
36
|
constructor(status, body, method, reason) {
|
|
44
37
|
super(status, body, buildMessage(method, reason));
|
|
@@ -48,12 +41,12 @@ class DeniedAuthenticationError extends ScalewayError {
|
|
|
48
41
|
this.reason = reason;
|
|
49
42
|
this.name = 'DeniedAuthenticationError';
|
|
50
43
|
}
|
|
51
|
-
|
|
52
44
|
static fromJSON(status, obj) {
|
|
53
|
-
if (typeof obj.method !== 'string' || typeof obj.reason !== 'string')
|
|
45
|
+
if (typeof obj.method !== 'string' || typeof obj.reason !== 'string') {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
54
48
|
return new DeniedAuthenticationError(status, obj, obj.method, obj.reason);
|
|
55
49
|
}
|
|
56
|
-
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
export { DeniedAuthenticationError };
|
|
@@ -18,41 +18,34 @@ import { ScalewayError } from '../scw-error.js';
|
|
|
18
18
|
const buildMessage = list => {
|
|
19
19
|
const invalidArgs = list.reduce((acc, details) => {
|
|
20
20
|
let readableReason = '';
|
|
21
|
-
|
|
22
21
|
switch (details.reason) {
|
|
23
22
|
case 'required':
|
|
24
23
|
readableReason = `is required`;
|
|
25
24
|
break;
|
|
26
|
-
|
|
27
25
|
case 'format':
|
|
28
26
|
readableReason = `is wrongly formatted`;
|
|
29
27
|
break;
|
|
30
|
-
|
|
31
28
|
case 'constraint':
|
|
32
29
|
readableReason = `does not respect constraint`;
|
|
33
30
|
break;
|
|
34
|
-
|
|
35
31
|
default:
|
|
36
32
|
readableReason = `is invalid for unexpected reason`;
|
|
37
33
|
break;
|
|
38
34
|
}
|
|
39
|
-
|
|
40
35
|
if (details.helpMessage && details.helpMessage.length > 0) {
|
|
41
36
|
readableReason = readableReason.concat(`, `, details.helpMessage);
|
|
42
37
|
}
|
|
43
|
-
|
|
44
38
|
acc.push(`${details.argumentName} ${readableReason}`);
|
|
45
39
|
return acc;
|
|
46
40
|
}, []);
|
|
47
41
|
return `invalid argument(s): ${invalidArgs.join('; ')}`;
|
|
48
42
|
};
|
|
43
|
+
|
|
49
44
|
/**
|
|
50
45
|
* InvalidArguments error happens when one or many fields are invalid in the request message.
|
|
51
46
|
*
|
|
52
47
|
* @public
|
|
53
48
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
49
|
class InvalidArgumentsError extends ScalewayError {
|
|
57
50
|
constructor(status, body, details) {
|
|
58
51
|
super(status, body, buildMessage(details));
|
|
@@ -61,7 +54,6 @@ class InvalidArgumentsError extends ScalewayError {
|
|
|
61
54
|
this.details = details;
|
|
62
55
|
this.name = 'InvalidArgumentsError';
|
|
63
56
|
}
|
|
64
|
-
|
|
65
57
|
static fromJSON(status, obj) {
|
|
66
58
|
if (!Array.isArray(obj.details)) return null;
|
|
67
59
|
return new InvalidArgumentsError(status, obj, obj.details.reduce((list, detail) => isJSONObject(detail) && typeof detail.argument_name === 'string' && typeof detail.reason === 'string' ? list.concat({
|
|
@@ -70,7 +62,6 @@ class InvalidArgumentsError extends ScalewayError {
|
|
|
70
62
|
reason: detail.reason
|
|
71
63
|
}) : list, []));
|
|
72
64
|
}
|
|
73
|
-
|
|
74
65
|
}
|
|
75
66
|
|
|
76
67
|
export { InvalidArgumentsError };
|
|
@@ -5,7 +5,6 @@ import { ScalewayError } from '../scw-error.js';
|
|
|
5
5
|
*
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
class OutOfStockError extends ScalewayError {
|
|
10
9
|
constructor(status, body, resource) {
|
|
11
10
|
super(status, body, `resource ${resource} is out of stock`);
|
|
@@ -14,12 +13,10 @@ class OutOfStockError extends ScalewayError {
|
|
|
14
13
|
this.resource = resource;
|
|
15
14
|
this.name = 'OutOfStockError';
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
static fromJSON(status, obj) {
|
|
19
17
|
if (typeof obj.resource !== 'string') return null;
|
|
20
18
|
return new OutOfStockError(status, obj, obj.resource);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
export { OutOfStockError };
|
|
@@ -22,13 +22,12 @@ const buildMessage = list => `insufficient permissions: ${list.map(_ref => {
|
|
|
22
22
|
} = _ref;
|
|
23
23
|
return `${action} ${resource}`;
|
|
24
24
|
}).join('; ')}`;
|
|
25
|
+
|
|
25
26
|
/**
|
|
26
27
|
* PermissionsDenied error happens when one or many permissions are not accorded to the user making the request.
|
|
27
28
|
*
|
|
28
29
|
* @public
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
31
|
class PermissionsDeniedError extends ScalewayError {
|
|
33
32
|
constructor(status, body, list) {
|
|
34
33
|
super(status, body, buildMessage(list));
|
|
@@ -37,7 +36,6 @@ class PermissionsDeniedError extends ScalewayError {
|
|
|
37
36
|
this.list = list;
|
|
38
37
|
this.name = 'PermissionsDeniedError';
|
|
39
38
|
}
|
|
40
|
-
|
|
41
39
|
static fromJSON(status, obj) {
|
|
42
40
|
if (!Array.isArray(obj.details)) return null;
|
|
43
41
|
return new PermissionsDeniedError(status, obj, obj.details.reduce((list, detail) => isJSONObject(detail) && typeof detail.resource === 'string' && typeof detail.action === 'string' ? list.concat({
|
|
@@ -45,7 +43,6 @@ class PermissionsDeniedError extends ScalewayError {
|
|
|
45
43
|
resource: detail.resource
|
|
46
44
|
}) : list, []));
|
|
47
45
|
}
|
|
48
|
-
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
export { PermissionsDeniedError };
|
|
@@ -9,23 +9,19 @@ import { ScalewayError } from '../scw-error.js';
|
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
12
|
const buildMessage = (precondition, helpMessage) => {
|
|
14
13
|
let message = `precondition failed: ${precondition}`;
|
|
15
|
-
|
|
16
14
|
if (typeof helpMessage === 'string' && helpMessage.length > 0) {
|
|
17
15
|
message = message.concat(', ', helpMessage);
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
return message;
|
|
21
18
|
};
|
|
19
|
+
|
|
22
20
|
/**
|
|
23
21
|
* PreconditionFailed error is used when a precondition is not respected.
|
|
24
22
|
*
|
|
25
23
|
* @public
|
|
26
24
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
25
|
class PreconditionFailedError extends ScalewayError {
|
|
30
26
|
constructor(status, body, precondition, helpMessage) {
|
|
31
27
|
super(status, body, buildMessage(precondition, helpMessage));
|
|
@@ -35,12 +31,12 @@ class PreconditionFailedError extends ScalewayError {
|
|
|
35
31
|
this.helpMessage = helpMessage;
|
|
36
32
|
this.name = 'PreconditionFailedError';
|
|
37
33
|
}
|
|
38
|
-
|
|
39
34
|
static fromJSON(status, obj) {
|
|
40
|
-
if (typeof obj.precondition !== 'string' || typeof obj.help_message !== 'string')
|
|
35
|
+
if (typeof obj.precondition !== 'string' || typeof obj.help_message !== 'string') {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
41
38
|
return new PreconditionFailedError(status, obj, obj.precondition, obj.help_message);
|
|
42
39
|
}
|
|
43
|
-
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
export { PreconditionFailedError };
|
|
@@ -15,29 +15,31 @@ import { ScalewayError } from '../scw-error.js';
|
|
|
15
15
|
*
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
|
-
const buildMessage = list => `quota
|
|
18
|
+
const buildMessage = list => `quota(s) exceeded: ${list.map(details => {
|
|
19
19
|
const message = `${details.resource} has reached its quota (${details.current}/${details.quota})`;
|
|
20
20
|
return details.scope ? `${message} for ${details.scope.kind} '${details.scope.id}'` : message;
|
|
21
21
|
}).join('; ')}`;
|
|
22
|
-
|
|
23
22
|
const buildScope = detail => {
|
|
24
|
-
if (typeof detail.organization_id === 'string' && detail.organization_id.length)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
if (typeof detail.organization_id === 'string' && detail.organization_id.length) {
|
|
24
|
+
return {
|
|
25
|
+
id: detail.organization_id,
|
|
26
|
+
kind: 'organization'
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (typeof detail.project_id === 'string' && detail.project_id.length) {
|
|
30
|
+
return {
|
|
31
|
+
id: detail.project_id,
|
|
32
|
+
kind: 'project'
|
|
33
|
+
};
|
|
34
|
+
}
|
|
32
35
|
return undefined;
|
|
33
36
|
};
|
|
37
|
+
|
|
34
38
|
/**
|
|
35
39
|
* QuotasExceeded error happens when one or many resource exceed quotas during the creation of a resource.
|
|
36
40
|
*
|
|
37
41
|
* @public
|
|
38
42
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
43
|
class QuotasExceededError extends ScalewayError {
|
|
42
44
|
constructor(status, body, list) {
|
|
43
45
|
super(status, body, buildMessage(list));
|
|
@@ -46,7 +48,6 @@ class QuotasExceededError extends ScalewayError {
|
|
|
46
48
|
this.list = list;
|
|
47
49
|
this.name = 'QuotasExceededError';
|
|
48
50
|
}
|
|
49
|
-
|
|
50
51
|
static fromJSON(status, obj) {
|
|
51
52
|
if (!Array.isArray(obj.details)) return null;
|
|
52
53
|
return new QuotasExceededError(status, obj, obj.details.reduce((list, detail) => isJSONObject(detail) && typeof detail.resource === 'string' && typeof detail.quota === 'number' && typeof detail.current === 'number' ? list.concat({
|
|
@@ -56,7 +57,6 @@ class QuotasExceededError extends ScalewayError {
|
|
|
56
57
|
scope: buildScope(detail)
|
|
57
58
|
}) : list, []));
|
|
58
59
|
}
|
|
59
|
-
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export { QuotasExceededError };
|