@scaleway/sdk 0.0.2-alpha.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/LICENSE +191 -0
- package/README.md +28 -0
- package/dist/api/function/manual/FunctionAPI.js +436 -0
- package/dist/api/function/manual/WaitForFunctionAPI.js +27 -0
- package/dist/api/function/manual/types.js +1 -0
- package/dist/api/registry/manual/RegistryAPI.js +260 -0
- package/dist/api/registry/manual/WaitForRegistryAPI.js +27 -0
- package/dist/api/registry/manual/types.js +1 -0
- package/dist/helpers/API.js +12 -0
- package/dist/helpers/camelize.js +36 -0
- package/dist/helpers/forRegions.js +15 -0
- package/dist/helpers/is-browser.js +3 -0
- package/dist/helpers/json.js +6 -0
- package/dist/index.cjs +9449 -0
- package/dist/index.d.ts +1126 -0
- package/dist/index.js +13 -0
- package/dist/internal/async/interval-retrier.js +89 -0
- package/dist/internal/async/sleep.js +13 -0
- package/dist/internal/auth.js +68 -0
- package/dist/internal/interceptors/interceptor.js +11 -0
- package/dist/internal/interceptors/request.js +29 -0
- package/dist/internal/logger/console-logger.js +31 -0
- package/dist/internal/logger/index.js +38 -0
- package/dist/internal/logger/level-resolver.js +16 -0
- package/dist/internal/tools/string-validation.js +39 -0
- package/dist/internals.js +4 -0
- package/dist/node_modules/@scaleway/random-name/dist/index.js +254 -0
- package/dist/scw/client-ini-factory.js +24 -0
- package/dist/scw/client-ini-profile.js +30 -0
- package/dist/scw/client-settings.js +49 -0
- package/dist/scw/client.js +96 -0
- package/dist/scw/constants.js +4 -0
- package/dist/scw/errors/error-parser.js +121 -0
- package/dist/scw/errors/non-standard/invalid-request-mapper.js +34 -0
- package/dist/scw/errors/non-standard/unknown-resource-mapper.js +26 -0
- package/dist/scw/errors/scw-error.js +64 -0
- package/dist/scw/errors/standard/already-exists-error.js +26 -0
- package/dist/scw/errors/standard/denied-authentication-error.js +58 -0
- package/dist/scw/errors/standard/index.js +12 -0
- package/dist/scw/errors/standard/invalid-arguments-error.js +75 -0
- package/dist/scw/errors/standard/out-of-stock-error.js +24 -0
- package/dist/scw/errors/standard/permissions-denied-error.js +50 -0
- package/dist/scw/errors/standard/precondition-failed-error.js +62 -0
- package/dist/scw/errors/standard/quotas-exceeded-error.js +61 -0
- package/dist/scw/errors/standard/resource-expired-error.js +26 -0
- package/dist/scw/errors/standard/resource-locked-error.js +25 -0
- package/dist/scw/errors/standard/resource-not-found-error.js +25 -0
- package/dist/scw/errors/standard/transient-state-error.js +26 -0
- package/dist/scw/errors/types.js +26 -0
- package/dist/scw/fetch/build-fetcher.js +66 -0
- package/dist/scw/fetch/http-dumper.js +57 -0
- package/dist/scw/fetch/http-interceptors.js +80 -0
- package/dist/scw/fetch/resource-paginator.js +41 -0
- package/dist/scw/fetch/response-parser.js +46 -0
- package/dist/scw/marshalling.js +103 -0
- package/package.json +27 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import randomName from '../../../node_modules/@scaleway/random-name/dist/index.js';
|
|
2
|
+
import { fetchPaginated, fetchAll } from '../../../scw/fetch/resource-paginator.js';
|
|
3
|
+
import { assertNotEmptyParam, resolveOneOf, urlParams, unmarshalAnyRes } from '../../../scw/marshalling.js';
|
|
4
|
+
import { WaitForRegistryAPI } from './WaitForRegistryAPI.js';
|
|
5
|
+
|
|
6
|
+
const IMAGE_DATE_KEYS = ['created_at', 'updated_at'];
|
|
7
|
+
|
|
8
|
+
const unmarshalImage = data => unmarshalAnyRes(data, [], IMAGE_DATE_KEYS);
|
|
9
|
+
|
|
10
|
+
const NAMESPACE_DATE_KEYS = IMAGE_DATE_KEYS;
|
|
11
|
+
|
|
12
|
+
const unmarshalNamespace = data => unmarshalAnyRes(data, [], NAMESPACE_DATE_KEYS);
|
|
13
|
+
|
|
14
|
+
const TAG_DATE_KEYS = IMAGE_DATE_KEYS;
|
|
15
|
+
|
|
16
|
+
const unmarshalTag = data => unmarshalAnyRes(data, [], TAG_DATE_KEYS);
|
|
17
|
+
|
|
18
|
+
const jsonContentHeaders = {
|
|
19
|
+
'Content-Type': 'application/json; charset=utf-8'
|
|
20
|
+
};
|
|
21
|
+
class RegistryAPI extends WaitForRegistryAPI {
|
|
22
|
+
constructor() {
|
|
23
|
+
var _this;
|
|
24
|
+
|
|
25
|
+
super(...arguments);
|
|
26
|
+
_this = this;
|
|
27
|
+
|
|
28
|
+
this.createNamespace = _ref => {
|
|
29
|
+
let {
|
|
30
|
+
region = this.client.settings.defaultRegion,
|
|
31
|
+
...req
|
|
32
|
+
} = _ref;
|
|
33
|
+
assertNotEmptyParam('region', region);
|
|
34
|
+
const origin = resolveOneOf([{
|
|
35
|
+
default: this.client.settings.defaultProjectId,
|
|
36
|
+
param: 'project_id',
|
|
37
|
+
value: req.projectId
|
|
38
|
+
}, {
|
|
39
|
+
default: this.client.settings.defaultOrganizationId,
|
|
40
|
+
param: 'organization_id',
|
|
41
|
+
value: req.organizationId
|
|
42
|
+
}]);
|
|
43
|
+
return this.client.fetch({
|
|
44
|
+
body: JSON.stringify({
|
|
45
|
+
description: req.description,
|
|
46
|
+
is_public: req.isPublic,
|
|
47
|
+
name: req.name || randomName('ns'),
|
|
48
|
+
[origin.param]: origin.value
|
|
49
|
+
}),
|
|
50
|
+
headers: jsonContentHeaders,
|
|
51
|
+
method: 'POST',
|
|
52
|
+
path: `/registry/v1/regions/${region}/namespaces`
|
|
53
|
+
}, unmarshalNamespace);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
this.updateNamespace = _ref2 => {
|
|
57
|
+
let {
|
|
58
|
+
region = this.client.settings.defaultRegion,
|
|
59
|
+
...req
|
|
60
|
+
} = _ref2;
|
|
61
|
+
assertNotEmptyParam('region', region);
|
|
62
|
+
assertNotEmptyParam('namespaceId', req.namespaceId);
|
|
63
|
+
return this.client.fetch({
|
|
64
|
+
body: JSON.stringify({
|
|
65
|
+
description: req.description,
|
|
66
|
+
is_public: req.isPublic
|
|
67
|
+
}),
|
|
68
|
+
headers: jsonContentHeaders,
|
|
69
|
+
method: 'PATCH',
|
|
70
|
+
path: `/registry/v1/regions/${region}/namespaces/${req.namespaceId}`
|
|
71
|
+
}, unmarshalNamespace);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
this.getNamespace = _ref3 => {
|
|
75
|
+
let {
|
|
76
|
+
region = this.client.settings.defaultRegion,
|
|
77
|
+
...req
|
|
78
|
+
} = _ref3;
|
|
79
|
+
assertNotEmptyParam('region', region);
|
|
80
|
+
assertNotEmptyParam('namespaceId', req.namespaceId);
|
|
81
|
+
return this.client.fetch({
|
|
82
|
+
method: 'GET',
|
|
83
|
+
path: `/registry/v1/regions/${region}/namespaces/${req.namespaceId}`
|
|
84
|
+
}, unmarshalNamespace);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
this.listNamespaces = function (_temp) {
|
|
88
|
+
let {
|
|
89
|
+
orderBy = 'created_at_asc',
|
|
90
|
+
organizationId = _this.client.settings.defaultOrganizationId,
|
|
91
|
+
pageSize = _this.client.settings.defaultPageSize,
|
|
92
|
+
projectId = _this.client.settings.defaultProjectId,
|
|
93
|
+
region = _this.client.settings.defaultRegion,
|
|
94
|
+
...req
|
|
95
|
+
} = _temp === void 0 ? {} : _temp;
|
|
96
|
+
assertNotEmptyParam('region', region);
|
|
97
|
+
return _this.client.fetch({
|
|
98
|
+
method: 'GET',
|
|
99
|
+
path: `/registry/v1/regions/${region}/namespaces`,
|
|
100
|
+
urlParams: urlParams(['name', req.name], ['order_by', orderBy], ['organization_id', organizationId], ['page', req.page], ['page_size', pageSize], ['project_id', projectId])
|
|
101
|
+
}, data => unmarshalAnyRes(data, [], NAMESPACE_DATE_KEYS));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
this.paginateNamespaces = function (request) {
|
|
105
|
+
if (request === void 0) {
|
|
106
|
+
request = {};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return fetchPaginated('namespaces', _this.listNamespaces, request);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
this.listAllNamespaces = function (request) {
|
|
113
|
+
if (request === void 0) {
|
|
114
|
+
request = {};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return fetchAll('namespaces', _this.listNamespaces, request);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
this.deleteNamespace = _ref4 => {
|
|
121
|
+
let {
|
|
122
|
+
region = this.client.settings.defaultRegion,
|
|
123
|
+
...req
|
|
124
|
+
} = _ref4;
|
|
125
|
+
assertNotEmptyParam('region', region);
|
|
126
|
+
assertNotEmptyParam('namespaceId', req.namespaceId);
|
|
127
|
+
return this.client.fetch({
|
|
128
|
+
method: 'DELETE',
|
|
129
|
+
path: `/registry/v1/regions/${region}/namespaces/${req.namespaceId}`
|
|
130
|
+
}, unmarshalNamespace);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
this.updateImage = _ref5 => {
|
|
134
|
+
let {
|
|
135
|
+
region = this.client.settings.defaultRegion,
|
|
136
|
+
...req
|
|
137
|
+
} = _ref5;
|
|
138
|
+
assertNotEmptyParam('region', region);
|
|
139
|
+
assertNotEmptyParam('imageId', req.imageId);
|
|
140
|
+
return this.client.fetch({
|
|
141
|
+
body: JSON.stringify({
|
|
142
|
+
visibility: req.visibility.toString()
|
|
143
|
+
}),
|
|
144
|
+
headers: jsonContentHeaders,
|
|
145
|
+
method: 'PATCH',
|
|
146
|
+
path: `/registry/v1/regions/${region}/images/${req.imageId}`
|
|
147
|
+
}, unmarshalImage);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
this.getImage = _ref6 => {
|
|
151
|
+
let {
|
|
152
|
+
region = this.client.settings.defaultRegion,
|
|
153
|
+
...req
|
|
154
|
+
} = _ref6;
|
|
155
|
+
assertNotEmptyParam('region', region);
|
|
156
|
+
assertNotEmptyParam('imageId', req.imageId);
|
|
157
|
+
return this.client.fetch({
|
|
158
|
+
method: 'GET',
|
|
159
|
+
path: `/registry/v1/regions/${region}/images/${req.imageId}`
|
|
160
|
+
}, unmarshalImage);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
this.listImages = function (_temp2) {
|
|
164
|
+
let {
|
|
165
|
+
orderBy = 'created_at_asc',
|
|
166
|
+
organizationId = _this.client.settings.defaultOrganizationId,
|
|
167
|
+
pageSize = _this.client.settings.defaultPageSize,
|
|
168
|
+
projectId = _this.client.settings.defaultProjectId,
|
|
169
|
+
region = _this.client.settings.defaultRegion,
|
|
170
|
+
...req
|
|
171
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
172
|
+
assertNotEmptyParam('region', region);
|
|
173
|
+
return _this.client.fetch({
|
|
174
|
+
method: 'GET',
|
|
175
|
+
path: `/registry/v1/regions/${region}/images`,
|
|
176
|
+
urlParams: urlParams(['name', req.name], ['namespace_id', req.namespaceId], ['order_by', orderBy], ['organization_id', organizationId], ['page', req.page], ['page_size', pageSize], ['project_id', projectId])
|
|
177
|
+
}, data => unmarshalAnyRes(data, [], IMAGE_DATE_KEYS));
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
this.paginateImages = function (request) {
|
|
181
|
+
if (request === void 0) {
|
|
182
|
+
request = {};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return fetchPaginated('images', _this.listImages, request);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
this.listAllImages = function (request) {
|
|
189
|
+
if (request === void 0) {
|
|
190
|
+
request = {};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return fetchAll('images', _this.listImages, request);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
this.deleteImage = _ref7 => {
|
|
197
|
+
let {
|
|
198
|
+
region = this.client.settings.defaultRegion,
|
|
199
|
+
...req
|
|
200
|
+
} = _ref7;
|
|
201
|
+
assertNotEmptyParam('region', region);
|
|
202
|
+
assertNotEmptyParam('imageId', req.imageId);
|
|
203
|
+
return this.client.fetch({
|
|
204
|
+
method: 'DELETE',
|
|
205
|
+
path: `/registry/v1/regions/${region}/images/${req.imageId}`
|
|
206
|
+
}, unmarshalImage);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
this.getTag = _ref8 => {
|
|
210
|
+
let {
|
|
211
|
+
region = this.client.settings.defaultRegion,
|
|
212
|
+
...req
|
|
213
|
+
} = _ref8;
|
|
214
|
+
assertNotEmptyParam('region', region);
|
|
215
|
+
assertNotEmptyParam('tagId', req.tagId);
|
|
216
|
+
return this.client.fetch({
|
|
217
|
+
method: 'GET',
|
|
218
|
+
path: `/registry/v1/regions/${region}/tags/${req.tagId}`
|
|
219
|
+
}, unmarshalTag);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
this.listTags = _ref9 => {
|
|
223
|
+
let {
|
|
224
|
+
region = this.client.settings.defaultRegion,
|
|
225
|
+
orderBy = 'created_at_asc',
|
|
226
|
+
pageSize = this.client.settings.defaultPageSize,
|
|
227
|
+
...request
|
|
228
|
+
} = _ref9;
|
|
229
|
+
assertNotEmptyParam('region', region);
|
|
230
|
+
assertNotEmptyParam('imageId', request.imageId);
|
|
231
|
+
return this.client.fetch({
|
|
232
|
+
method: 'GET',
|
|
233
|
+
path: `/registry/v1/regions/${region}/images/${request.imageId}/tags`,
|
|
234
|
+
urlParams: urlParams(['page', request.page], ['page_size', pageSize], ['order_by', orderBy], ['name', request.name])
|
|
235
|
+
}, data => unmarshalAnyRes(data, [], TAG_DATE_KEYS));
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
this.paginateTags = request => fetchPaginated('tags', this.listTags, request);
|
|
239
|
+
|
|
240
|
+
this.listAllTags = request => fetchAll('tags', this.listTags, request);
|
|
241
|
+
|
|
242
|
+
this.deleteTag = _ref10 => {
|
|
243
|
+
let {
|
|
244
|
+
region = this.client.settings.defaultRegion,
|
|
245
|
+
...req
|
|
246
|
+
} = _ref10;
|
|
247
|
+
assertNotEmptyParam('region', region);
|
|
248
|
+
assertNotEmptyParam('tagId', req.tagId);
|
|
249
|
+
return this.client.fetch({
|
|
250
|
+
headers: jsonContentHeaders,
|
|
251
|
+
method: 'DELETE',
|
|
252
|
+
path: `/registry/v1/regions/${region}/tags/${req.tagId}`,
|
|
253
|
+
urlParams: urlParams(['force', req.force])
|
|
254
|
+
}, unmarshalTag);
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { RegistryAPI };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { waitForStatus } from '../../../internal/async/interval-retrier.js';
|
|
2
|
+
import { API } from '../../../helpers/API.js';
|
|
3
|
+
|
|
4
|
+
const NAMESPACE_RETRY_INTERVAL_MS = 15 * 1000;
|
|
5
|
+
const TERMINAL_NAMESPACE_STATUS = ['ready', 'locked', 'error', 'unknown'];
|
|
6
|
+
const TERMINAL_IMAGE_STATUS = TERMINAL_NAMESPACE_STATUS;
|
|
7
|
+
const TERMINAL_TAG_STATUS = TERMINAL_NAMESPACE_STATUS;
|
|
8
|
+
class WaitForRegistryAPI extends API {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.getNamespace = void 0;
|
|
12
|
+
this.getImage = void 0;
|
|
13
|
+
this.getTag = void 0;
|
|
14
|
+
|
|
15
|
+
this.waitForNamespace = (request, options) => waitForStatus(TERMINAL_NAMESPACE_STATUS, this.getNamespace, request, {
|
|
16
|
+
retryInterval: NAMESPACE_RETRY_INTERVAL_MS,
|
|
17
|
+
...options
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
this.waitForImage = (request, options) => waitForStatus(TERMINAL_IMAGE_STATUS, this.getImage, request, options);
|
|
21
|
+
|
|
22
|
+
this.waitForTag = (request, options) => waitForStatus(TERMINAL_TAG_STATUS, this.getTag, request, options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { WaitForRegistryAPI };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camelizes a string.
|
|
3
|
+
*
|
|
4
|
+
* @param str - The string to camelize
|
|
5
|
+
* @returns The camelized string
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
const camelize = str => str.toLowerCase().replace(/[-_\s.]+([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
10
|
+
/**
|
|
11
|
+
* Camelizes keys of an object (deeply).
|
|
12
|
+
*
|
|
13
|
+
* @param obj - The object
|
|
14
|
+
* @param ignoreKeys - The keys to ignore
|
|
15
|
+
* @returns The object with camelized keys
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const camelizeKeys = function (obj, ignoreKeys) {
|
|
22
|
+
if (ignoreKeys === void 0) {
|
|
23
|
+
ignoreKeys = [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (Array.isArray(obj)) return obj.map(v => camelizeKeys(v, ignoreKeys));
|
|
27
|
+
if (obj && typeof obj === 'object' && !(obj instanceof Date)) return Object.entries(obj).reduce((acc, _ref) => {
|
|
28
|
+
let [key, value] = _ref;
|
|
29
|
+
return { ...acc,
|
|
30
|
+
[camelize(key)]: ignoreKeys.includes(key) ? value : camelizeKeys(value, ignoreKeys)
|
|
31
|
+
};
|
|
32
|
+
}, {});
|
|
33
|
+
return obj;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { camelize, camelizeKeys };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes a request for several regions at once.
|
|
3
|
+
*
|
|
4
|
+
* @param regions - The regions
|
|
5
|
+
* @param fetcher - The fetcher
|
|
6
|
+
* @param request - The request
|
|
7
|
+
* @returns The resolved promise
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
const forRegions = async (regions, fetcher, request) => (await Promise.all(regions.map(region => fetcher({ ...request,
|
|
12
|
+
region
|
|
13
|
+
})))).flat();
|
|
14
|
+
|
|
15
|
+
export { forRegions };
|