@scaleway/sdk 1.9.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,14 +10,15 @@ const jsonContentHeaders = {
10
10
  'Content-Type': 'application/json; charset=utf-8'
11
11
  };
12
12
 
13
- /** Webhosting API. */
13
+ /** Web Hosting API. */
14
14
  class API extends API$1 {
15
15
  constructor() {
16
16
  var _this;
17
17
  super(...arguments);
18
18
  _this = this;
19
19
  /**
20
- * Create a hosting.
20
+ * Order a Web Hosting plan. Order a Web Hosting plan, specifying the offer
21
+ * type required via the `offer_id` parameter.
21
22
  *
22
23
  * @param request - The request {@link CreateHostingRequest}
23
24
  * @returns A Promise of Hosting
@@ -39,7 +40,9 @@ class API extends API$1 {
39
40
  }, unmarshalListHostingsResponse);
40
41
  };
41
42
  /**
42
- * List all hostings.
43
+ * List all Web Hosting plans. List all of your existing Web Hosting plans.
44
+ * Various filters are available to limit the results, including filtering by
45
+ * domain, status, tag and Project ID.
43
46
  *
44
47
  * @param request - The request {@link ListHostingsRequest}
45
48
  * @returns A Promise of ListHostingsResponse
@@ -51,7 +54,8 @@ class API extends API$1 {
51
54
  return enrichForPagination('hostings', _this.pageOfListHostings, request);
52
55
  };
53
56
  /**
54
- * Get a hosting. Get the details of a Hosting with the given ID.
57
+ * Get a Web Hosting plan. Get the details of one of your existing Web Hosting
58
+ * plans, specified by its `hosting_id`.
55
59
  *
56
60
  * @param request - The request {@link GetHostingRequest}
57
61
  * @returns A Promise of Hosting
@@ -69,7 +73,9 @@ class API extends API$1 {
69
73
  */
70
74
  this.waitForHosting = (request, options) => waitForResource(options?.stop ?? (res => Promise.resolve(!HOSTING_TRANSIENT_STATUSES.includes(res.status))), this.getHosting, request, options);
71
75
  /**
72
- * Update a hosting.
76
+ * Update a Web Hosting plan. Update the details of one of your existing Web
77
+ * Hosting plans, specified by its `hosting_id`. You can update parameters
78
+ * including the contact email address, tags, options and offer.
73
79
  *
74
80
  * @param request - The request {@link UpdateHostingRequest}
75
81
  * @returns A Promise of Hosting
@@ -81,7 +87,10 @@ class API extends API$1 {
81
87
  path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}`
82
88
  }, unmarshalHosting);
83
89
  /**
84
- * Delete a hosting. Delete a hosting with the given ID.
90
+ * Delete a Web Hosting plan. Delete a Web Hosting plan, specified by its
91
+ * `hosting_id`. Note that deletion is not immediate: it will take place at
92
+ * the end of the calendar month, after which time your Web Hosting plan and
93
+ * all its data (files and emails) will be irreversibly lost.
85
94
  *
86
95
  * @param request - The request {@link DeleteHostingRequest}
87
96
  * @returns A Promise of Hosting
@@ -91,7 +100,12 @@ class API extends API$1 {
91
100
  path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}`
92
101
  }, unmarshalHosting);
93
102
  /**
94
- * Restore a hosting. Restore a hosting with the given ID.
103
+ * Restore a Web Hosting plan. When you [delete a Web Hosting
104
+ * plan](#path-hostings-delete-a-hosting), definitive deletion does not take
105
+ * place until the end of the calendar month. In the time between initiating
106
+ * the deletion, and definitive deletion at the end of the month, you can
107
+ * choose to **restore** the Web Hosting plan, using this endpoint and
108
+ * specifying its `hosting_id`.
95
109
  *
96
110
  * @param request - The request {@link RestoreHostingRequest}
97
111
  * @returns A Promise of Hosting
@@ -103,8 +117,8 @@ class API extends API$1 {
103
117
  path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/restore`
104
118
  }, unmarshalHosting);
105
119
  /**
106
- * Get the DNS records. The set of DNS record of a specific domain associated
107
- * to a hosting.
120
+ * Get DNS records. Get the set of DNS records of a specified domain
121
+ * associated with a Web Hosting plan.
108
122
  *
109
123
  * @param request - The request {@link GetDomainDnsRecordsRequest}
110
124
  * @returns A Promise of DnsRecords
@@ -114,7 +128,8 @@ class API extends API$1 {
114
128
  path: `/webhosting/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/domains/${validatePathParam('domain', request.domain)}/dns-records`
115
129
  }, unmarshalDnsRecords);
116
130
  /**
117
- * List all offers.
131
+ * List all offers. List the different Web Hosting offers, and their options,
132
+ * available to order from Scaleway.
118
133
  *
119
134
  * @param request - The request {@link ListOffersRequest}
120
135
  * @returns A Promise of ListOffersResponse
package/dist/index.cjs CHANGED
@@ -71,8 +71,6 @@ const enableConsoleLogger = (logLevel = 'warn', prefix = 'scaleway-sdk-js:') =>
71
71
  */
72
72
  const getLogger = () => sdkLogger;
73
73
 
74
- /** Request Interceptor. */
75
-
76
74
  /**
77
75
  * Adds an header to a request through an interceptor.
78
76
  *
@@ -82,7 +80,9 @@ const getLogger = () => sdkLogger;
82
80
  *
83
81
  * @internal
84
82
  */
85
- const addHeaderInterceptor = (key, value) => request => {
83
+ const addHeaderInterceptor = (key, value) => ({
84
+ request
85
+ }) => {
86
86
  const clone = request.clone();
87
87
  if (value !== undefined) {
88
88
  clone.headers.append(key, value);
@@ -197,6 +197,8 @@ const AUTH_HEADER_KEY = 'x-auth-token';
197
197
  * @param getToken - The token accessor
198
198
  * @returns The request interceptor
199
199
  *
200
+ * @deprecated Please use addAsyncHeaderInterceptor instead.
201
+ *
200
202
  * @internal
201
203
  */
202
204
  const authenticateWithSessionToken = getToken => addAsyncHeaderInterceptor(SESSION_HEADER_KEY, getToken);
@@ -286,7 +288,9 @@ const withProfile = profile => settings => {
286
288
  newSettings.defaultZone = profile.defaultZone;
287
289
  }
288
290
  if (hasAuthenticationSecrets(profile)) {
289
- newSettings.requestInterceptors = [authenticateWithSecrets(profile), ...settings.requestInterceptors];
291
+ newSettings.interceptors = [{
292
+ request: authenticateWithSecrets(profile)
293
+ }, ...newSettings.interceptors];
290
294
  }
291
295
  return newSettings;
292
296
  };
@@ -351,6 +355,73 @@ const withUserAgentSuffix = userAgent => settings => ({
351
355
  userAgent: settings.userAgent ? `${settings.userAgent} ${userAgent}` : userAgent
352
356
  });
353
357
 
358
+ /**
359
+ * Instantiates the SDK with additional interceptors.
360
+ *
361
+ * @param interceptors - The additional {@link NetworkInterceptors} interceptors
362
+ * @returns A factory {@link ClientConfig}
363
+ *
364
+ * @remarks
365
+ * It doesn't override the existing interceptors, but instead push more to the list.
366
+ * This method should be used in conjunction with the initializer `createAdvancedClient`.
367
+ *
368
+ * @example
369
+ * ```
370
+ * withAdditionalInterceptors([
371
+ * {
372
+ * request: ({ request }) => {
373
+ * console.log(`Do something with ${JSON.stringify(request)}`)
374
+ * return request
375
+ * },
376
+ * response: ({ response }) => {
377
+ * console.log(`Do something with ${JSON.stringify(response)}`)
378
+ * return response
379
+ * },
380
+ * responseError: async ({
381
+ * request,
382
+ * error,
383
+ * }: {
384
+ * request: Request
385
+ * error: unknown
386
+ * }) => {
387
+ * console.log(
388
+ * `Do something with ${JSON.stringify(request)} and ${JSON.stringify(
389
+ * error,
390
+ * )}`,
391
+ * )
392
+ * throw error // or return Promise.resolve(someData)
393
+ * },
394
+ * },
395
+ * ])
396
+ * ```
397
+ *
398
+ * @public
399
+ */
400
+ const withAdditionalInterceptors = interceptors => settings => ({
401
+ ...settings,
402
+ interceptors: settings.interceptors.concat(interceptors)
403
+ });
404
+
405
+ /**
406
+ * Instantiates the SDK with legacy interceptors.
407
+ */
408
+ /* eslint-disable deprecation/deprecation */
409
+ const withLegacyInterceptors = () => settings => {
410
+ if (!settings.requestInterceptors && !settings.responseInterceptors) {
411
+ return settings;
412
+ }
413
+ const allInterceptors = settings.interceptors.concat((settings.requestInterceptors ?? []).map(obj => ({
414
+ request: obj
415
+ })), (settings.responseInterceptors ?? []).map(obj => ({
416
+ response: obj
417
+ })));
418
+ return {
419
+ ...settings,
420
+ interceptors: allInterceptors
421
+ };
422
+ };
423
+ /* eslint-enable deprecation/deprecation */
424
+
354
425
  /**
355
426
  * Holds default values of settings.
356
427
  *
@@ -426,22 +497,55 @@ const assertValidSettings = obj => {
426
497
  }
427
498
  };
428
499
 
429
- const version = 'v1.8.0';
500
+ const version = 'v1.10.0';
430
501
  const userAgent = `scaleway-sdk-js/${version}`;
431
502
 
432
503
  const isBrowser = () => typeof window !== 'undefined' && typeof window.document !== 'undefined';
433
504
 
434
505
  /**
435
- * Composes interceptors.
506
+ * Composes request interceptors.
436
507
  *
437
- * @param interceptors - A list of interceptors (that modify an object instance)
508
+ * @param interceptors - A list of request interceptors
438
509
  * @returns An async composed interceptor
439
510
  *
440
511
  * @internal
441
512
  */
442
- const composeInterceptors = interceptors => async instance => interceptors.reduce(async (asyncResult, interceptor) => interceptor(await asyncResult), new Promise(resolve => {
443
- resolve(instance);
444
- }));
513
+ const composeRequestInterceptors = interceptors => async request => interceptors.reduce(async (asyncResult, interceptor) => interceptor({
514
+ request: await asyncResult
515
+ }), Promise.resolve(request));
516
+
517
+ /**
518
+ * Composes response interceptors.
519
+ *
520
+ * @param interceptors - A list of response interceptors
521
+ * @returns An async composed interceptor
522
+ *
523
+ * @internal
524
+ */
525
+ const composeResponseInterceptors = interceptors => async response => interceptors.reduce(async (asyncResult, interceptor) => interceptor({
526
+ response: await asyncResult
527
+ }), Promise.resolve(response));
528
+
529
+ /**
530
+ * Compose response error interceptors.
531
+ *
532
+ * @internal
533
+ */
534
+ const composeResponseErrorInterceptors = interceptors => async (request, error) => {
535
+ let prevError = error;
536
+ for (const interceptor of interceptors) {
537
+ try {
538
+ const res = await interceptor({
539
+ request,
540
+ error: prevError
541
+ });
542
+ return res;
543
+ } catch (err) {
544
+ prevError = err;
545
+ }
546
+ }
547
+ throw prevError;
548
+ };
445
549
 
446
550
  /**
447
551
  * Converts a string to PascalCase.
@@ -526,8 +630,12 @@ class ObfuscatedRequest extends Request {
526
630
  *
527
631
  * @internal
528
632
  */
529
- const obfuscateInterceptor = obfuscate => request => new ObfuscatedRequest(request, obfuscate);
530
- const identity = instance => instance;
633
+ const obfuscateInterceptor = obfuscate => ({
634
+ request
635
+ }) => new ObfuscatedRequest(request, obfuscate);
636
+ const identity = ({
637
+ request
638
+ }) => request;
531
639
 
532
640
  /**
533
641
  * Creates an interceptor to log the requests.
@@ -538,10 +646,14 @@ const identity = instance => instance;
538
646
  *
539
647
  * @internal
540
648
  */
541
- const logRequest = (identifier, obfuscate = identity) => async request => {
649
+ const logRequest = (identifier, obfuscate = identity) => async ({
650
+ request
651
+ }) => {
542
652
  if (shouldLog(LevelResolver[getLogger().logLevel], 'debug')) {
543
653
  getLogger().debug(`--------------- Scaleway SDK REQUEST ${identifier} ---------------
544
- ${await dumpRequest(await obfuscate(request))}
654
+ ${await dumpRequest(await obfuscate({
655
+ request
656
+ }))}
545
657
  ---------------------------------------------------------`);
546
658
  }
547
659
  return request;
@@ -555,7 +667,9 @@ ${await dumpRequest(await obfuscate(request))}
555
667
  *
556
668
  * @internal
557
669
  */
558
- const logResponse = identifier => async response => {
670
+ const logResponse = identifier => async ({
671
+ response
672
+ }) => {
559
673
  if (shouldLog(LevelResolver[getLogger().logLevel], 'debug')) {
560
674
  getLogger().debug(`--------------- Scaleway SDK RESPONSE ${identifier} ---------------
561
675
  ${await dumpResponse(response)}
@@ -1358,11 +1472,25 @@ const asIs = response => response;
1358
1472
  */
1359
1473
  const buildFetcher = (settings, httpClient) => {
1360
1474
  let requestNumber = 0;
1361
- const prepareRequest = requestId => composeInterceptors([...settings.requestInterceptors, logRequest(requestId, obfuscateInterceptor(obfuscateAuthHeadersEntry))]);
1362
- const prepareResponse = requestId => composeInterceptors([...settings.responseInterceptors, logResponse(requestId)]);
1475
+ const prepareRequest = requestId => composeRequestInterceptors([...settings.interceptors.map(obj => obj.request).filter(obj => obj), logRequest(requestId, obfuscateInterceptor(obfuscateAuthHeadersEntry))]);
1476
+ const prepareResponse = requestId => composeResponseInterceptors([...settings.interceptors.map(obj => obj.response).filter(obj => obj), logResponse(requestId)]);
1477
+ const prepareResponseErrors = () => composeResponseErrorInterceptors(settings.interceptors.map(obj => obj.responseError).filter(obj => obj));
1363
1478
  return async (request, unwrapper = asIs) => {
1364
1479
  const requestId = `${requestNumber += 1}`;
1365
- return Promise.resolve(buildRequest(request, settings)).then(prepareRequest(requestId)).then(httpClient).then(prepareResponse(requestId)).then(responseParser(unwrapper, request.responseType ?? 'json'));
1480
+ const reqInterceptors = prepareRequest(requestId);
1481
+ const finalRequest = await reqInterceptors(buildRequest(request, settings));
1482
+ try {
1483
+ const response = await httpClient(finalRequest);
1484
+ const resInterceptors = prepareResponse(requestId);
1485
+ const finalResponse = await resInterceptors(response);
1486
+ const resUnmarshaller = responseParser(unwrapper, request.responseType ?? 'json');
1487
+ const unmarshaledResponse = await resUnmarshaller(finalResponse);
1488
+ return unmarshaledResponse;
1489
+ } catch (err) {
1490
+ const resErrorInterceptors = prepareResponseErrors();
1491
+ const handledError = await resErrorInterceptors(finalRequest, err);
1492
+ return unwrapper(handledError);
1493
+ }
1366
1494
  };
1367
1495
  };
1368
1496
 
@@ -1370,8 +1498,7 @@ const buildFetcher = (settings, httpClient) => {
1370
1498
  const DEFAULT_SETTINGS = {
1371
1499
  apiURL: 'https://api.scaleway.com',
1372
1500
  httpClient: fetch,
1373
- requestInterceptors: [],
1374
- responseInterceptors: [],
1501
+ interceptors: [],
1375
1502
  userAgent
1376
1503
  };
1377
1504
 
@@ -1404,7 +1531,7 @@ const DEFAULT_SETTINGS = {
1404
1531
  * @public
1405
1532
  */
1406
1533
  const createAdvancedClient = (...configs) => {
1407
- const settings = configs.reduce((currentSettings, config) => config(currentSettings), DEFAULT_SETTINGS);
1534
+ const settings = configs.concat([withLegacyInterceptors()]).reduce((currentSettings, config) => config(currentSettings), DEFAULT_SETTINGS);
1408
1535
  assertValidSettings(settings);
1409
1536
  getLogger().info(`init Scaleway SDK version ${version}`);
1410
1537
  return {
@@ -21325,13 +21452,14 @@ const jsonContentHeaders = {
21325
21452
  'Content-Type': 'application/json; charset=utf-8'
21326
21453
  };
21327
21454
 
21328
- /** Webhosting API. */
21455
+ /** Web Hosting API. */
21329
21456
  class API extends API$q {
21330
21457
  /** Lists the available regions of the API. */
21331
21458
  static LOCALITIES = ['fr-par'];
21332
21459
 
21333
21460
  /**
21334
- * Create a hosting.
21461
+ * Order a Web Hosting plan. Order a Web Hosting plan, specifying the offer
21462
+ * type required via the `offer_id` parameter.
21335
21463
  *
21336
21464
  * @param request - The request {@link CreateHostingRequest}
21337
21465
  * @returns A Promise of Hosting
@@ -21349,7 +21477,9 @@ class API extends API$q {
21349
21477
  }, unmarshalListHostingsResponse);
21350
21478
 
21351
21479
  /**
21352
- * List all hostings.
21480
+ * List all Web Hosting plans. List all of your existing Web Hosting plans.
21481
+ * Various filters are available to limit the results, including filtering by
21482
+ * domain, status, tag and Project ID.
21353
21483
  *
21354
21484
  * @param request - The request {@link ListHostingsRequest}
21355
21485
  * @returns A Promise of ListHostingsResponse
@@ -21357,7 +21487,8 @@ class API extends API$q {
21357
21487
  listHostings = (request = {}) => enrichForPagination('hostings', this.pageOfListHostings, request);
21358
21488
 
21359
21489
  /**
21360
- * Get a hosting. Get the details of a Hosting with the given ID.
21490
+ * Get a Web Hosting plan. Get the details of one of your existing Web Hosting
21491
+ * plans, specified by its `hosting_id`.
21361
21492
  *
21362
21493
  * @param request - The request {@link GetHostingRequest}
21363
21494
  * @returns A Promise of Hosting
@@ -21377,7 +21508,9 @@ class API extends API$q {
21377
21508
  waitForHosting = (request, options) => waitForResource(options?.stop ?? (res => Promise.resolve(!HOSTING_TRANSIENT_STATUSES.includes(res.status))), this.getHosting, request, options);
21378
21509
 
21379
21510
  /**
21380
- * Update a hosting.
21511
+ * Update a Web Hosting plan. Update the details of one of your existing Web
21512
+ * Hosting plans, specified by its `hosting_id`. You can update parameters
21513
+ * including the contact email address, tags, options and offer.
21381
21514
  *
21382
21515
  * @param request - The request {@link UpdateHostingRequest}
21383
21516
  * @returns A Promise of Hosting
@@ -21390,7 +21523,10 @@ class API extends API$q {
21390
21523
  }, unmarshalHosting);
21391
21524
 
21392
21525
  /**
21393
- * Delete a hosting. Delete a hosting with the given ID.
21526
+ * Delete a Web Hosting plan. Delete a Web Hosting plan, specified by its
21527
+ * `hosting_id`. Note that deletion is not immediate: it will take place at
21528
+ * the end of the calendar month, after which time your Web Hosting plan and
21529
+ * all its data (files and emails) will be irreversibly lost.
21394
21530
  *
21395
21531
  * @param request - The request {@link DeleteHostingRequest}
21396
21532
  * @returns A Promise of Hosting
@@ -21401,7 +21537,12 @@ class API extends API$q {
21401
21537
  }, unmarshalHosting);
21402
21538
 
21403
21539
  /**
21404
- * Restore a hosting. Restore a hosting with the given ID.
21540
+ * Restore a Web Hosting plan. When you [delete a Web Hosting
21541
+ * plan](#path-hostings-delete-a-hosting), definitive deletion does not take
21542
+ * place until the end of the calendar month. In the time between initiating
21543
+ * the deletion, and definitive deletion at the end of the month, you can
21544
+ * choose to **restore** the Web Hosting plan, using this endpoint and
21545
+ * specifying its `hosting_id`.
21405
21546
  *
21406
21547
  * @param request - The request {@link RestoreHostingRequest}
21407
21548
  * @returns A Promise of Hosting
@@ -21414,8 +21555,8 @@ class API extends API$q {
21414
21555
  }, unmarshalHosting);
21415
21556
 
21416
21557
  /**
21417
- * Get the DNS records. The set of DNS record of a specific domain associated
21418
- * to a hosting.
21558
+ * Get DNS records. Get the set of DNS records of a specified domain
21559
+ * associated with a Web Hosting plan.
21419
21560
  *
21420
21561
  * @param request - The request {@link GetDomainDnsRecordsRequest}
21421
21562
  * @returns A Promise of DnsRecords
@@ -21426,7 +21567,8 @@ class API extends API$q {
21426
21567
  }, unmarshalDnsRecords);
21427
21568
 
21428
21569
  /**
21429
- * List all offers.
21570
+ * List all offers. List the different Web Hosting offers, and their options,
21571
+ * available to order from Scaleway.
21430
21572
  *
21431
21573
  * @param request - The request {@link ListOffersRequest}
21432
21574
  * @returns A Promise of ListOffersResponse
@@ -21497,6 +21639,7 @@ exports.TransactionalEmail = index$3;
21497
21639
  exports.VPC = index$2;
21498
21640
  exports.VPCGW = index$1;
21499
21641
  exports.Webhosting = index;
21642
+ exports.addAsyncHeaderInterceptor = addAsyncHeaderInterceptor;
21500
21643
  exports.authenticateWithSessionToken = authenticateWithSessionToken;
21501
21644
  exports.createAdvancedClient = createAdvancedClient;
21502
21645
  exports.createClient = createClient;
@@ -21519,6 +21662,7 @@ exports.unmarshalTimeSeriesPoint = unmarshalTimeSeriesPoint;
21519
21662
  exports.urlParams = urlParams;
21520
21663
  exports.validatePathParam = validatePathParam;
21521
21664
  exports.waitForResource = waitForResource;
21665
+ exports.withAdditionalInterceptors = withAdditionalInterceptors;
21522
21666
  exports.withDefaultPageSize = withDefaultPageSize;
21523
21667
  exports.withHTTPClient = withHTTPClient;
21524
21668
  exports.withProfile = withProfile;