@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.
package/dist/index.d.ts CHANGED
@@ -57,6 +57,96 @@ type ResourceFetcher<T, R> = (request: R) => Promise<T>;
57
57
  */
58
58
  declare const waitForResource: <R, T>(stop: WaitForStopCondition<T>, fetcher: ResourceFetcher<T, R>, request: R, options?: WaitForOptions<T> | undefined, strategy?: IntervalStrategy) => Promise<Awaited<T>>;
59
59
 
60
+ /**
61
+ * Defines the interceptor for a `Request`.
62
+ * This allows you to intercept requests before starting.
63
+ *
64
+ * @example
65
+ * Adds a custom header to a request:
66
+ * ```
67
+ * const addCustomHeaderInterceptor
68
+ * ({ key, value }: { key: string; value: string }): RequestInterceptor =>
69
+ * ({ request }) => {
70
+ * const clone = request.clone()
71
+ * clone.headers.set(key, value)
72
+ *
73
+ * return clone
74
+ * }
75
+ * ```
76
+ *
77
+ * @public
78
+ */
79
+ interface RequestInterceptor {
80
+ ({ request }: {
81
+ request: Readonly<Request>;
82
+ }): Request | Promise<Request>;
83
+ }
84
+ /**
85
+ * Defines the interceptor for a `Response`.
86
+ * This allows you to intercept responses before unmarshalling.
87
+ *
88
+ * @example
89
+ * Adds a delay before sending the response:
90
+ * ```
91
+ * const addDelayInterceptor: ResponseInterceptor = ({ response }) =>
92
+ * new Promise(resolve => {
93
+ * setTimeout(() => resolve(response), 1000)
94
+ * })
95
+ * ```
96
+ *
97
+ * @public
98
+ */
99
+ interface ResponseInterceptor {
100
+ ({ response }: {
101
+ response: Readonly<Response>;
102
+ }): Response | Promise<Response>;
103
+ }
104
+ /**
105
+ * Defines the interceptor for a `Response` error.
106
+ * This allows you to intercept a response error before exiting the whole process.
107
+ * You can either rethrow an error, and resolve with a different response.
108
+ *
109
+ * @remarks
110
+ * You must return either:
111
+ * 1. An error (`throw error` or `Promise.reject(error)`)
112
+ * 2. Data (directly, or via a Promise)
113
+ *
114
+ * @example
115
+ * Reports error to tracking service:
116
+ * ```
117
+ * const reportErrorToTrackingService: ResponseErrorInterceptor = async ({
118
+ * request,
119
+ * error,
120
+ * }: {
121
+ * request: Request
122
+ * error: unknown
123
+ * }) => {
124
+ * await sendErrorToErrorService(request, error)
125
+ * throw error
126
+ * }
127
+ * ```
128
+ *
129
+ * @public
130
+ */
131
+ interface ResponseErrorInterceptor {
132
+ ({ request, error }: {
133
+ request: Request;
134
+ error: unknown;
135
+ }): unknown | Promise<unknown>;
136
+ }
137
+ /**
138
+ * Defines the network interceptors.
139
+ * Please check the documentation of {@link RequestInterceptor},
140
+ * {@link ResponseInterceptor} and {@link ResponseErrorInterceptor} for examples.
141
+ *
142
+ * @public
143
+ */
144
+ type NetworkInterceptors = {
145
+ request?: RequestInterceptor;
146
+ response?: ResponseInterceptor;
147
+ responseError?: ResponseErrorInterceptor;
148
+ };
149
+
60
150
  declare enum LevelResolver {
61
151
  silent = 0,
62
152
  error = 1,
@@ -161,16 +251,6 @@ interface ProfileDefaultValues {
161
251
  */
162
252
  type Profile = Partial<ProfileDefaultValues & AuthenticationSecrets>;
163
253
 
164
- interface Interceptor<T> {
165
- (instance: Readonly<T>): T | Promise<T>;
166
- }
167
-
168
- /** Request Interceptor. */
169
- type RequestInterceptor = Interceptor<Request>;
170
-
171
- /** Response Interceptor. */
172
- type ResponseInterceptor = Interceptor<Response>;
173
-
174
254
  /**
175
255
  * Holds default values of settings.
176
256
  *
@@ -198,12 +278,20 @@ interface Settings extends DefaultValues {
198
278
  httpClient: typeof fetch;
199
279
  /**
200
280
  * The Request interceptors.
281
+ *
282
+ * @deprecated Please use `interceptors` instead.
201
283
  */
202
- requestInterceptors: RequestInterceptor[];
284
+ requestInterceptors?: RequestInterceptor[];
203
285
  /**
204
286
  * The Response interceptors.
287
+ *
288
+ * @deprecated Please use `interceptors` instead.
205
289
  */
206
- responseInterceptors: ResponseInterceptor[];
290
+ responseInterceptors?: ResponseInterceptor[];
291
+ /**
292
+ * The Network interceptors.
293
+ */
294
+ interceptors: NetworkInterceptors[];
207
295
  /**
208
296
  * The User-Agent sent with each request.
209
297
  *
@@ -273,6 +361,49 @@ declare const withUserAgent: (userAgent: string) => (settings: Readonly<Settings
273
361
  * @public
274
362
  */
275
363
  declare const withUserAgentSuffix: (userAgent: string) => (settings: Readonly<Settings>) => Settings;
364
+ /**
365
+ * Instantiates the SDK with additional interceptors.
366
+ *
367
+ * @param interceptors - The additional {@link NetworkInterceptors} interceptors
368
+ * @returns A factory {@link ClientConfig}
369
+ *
370
+ * @remarks
371
+ * It doesn't override the existing interceptors, but instead push more to the list.
372
+ * This method should be used in conjunction with the initializer `createAdvancedClient`.
373
+ *
374
+ * @example
375
+ * ```
376
+ * withAdditionalInterceptors([
377
+ * {
378
+ * request: ({ request }) => {
379
+ * console.log(`Do something with ${JSON.stringify(request)}`)
380
+ * return request
381
+ * },
382
+ * response: ({ response }) => {
383
+ * console.log(`Do something with ${JSON.stringify(response)}`)
384
+ * return response
385
+ * },
386
+ * responseError: async ({
387
+ * request,
388
+ * error,
389
+ * }: {
390
+ * request: Request
391
+ * error: unknown
392
+ * }) => {
393
+ * console.log(
394
+ * `Do something with ${JSON.stringify(request)} and ${JSON.stringify(
395
+ * error,
396
+ * )}`,
397
+ * )
398
+ * throw error // or return Promise.resolve(someData)
399
+ * },
400
+ * },
401
+ * ])
402
+ * ```
403
+ *
404
+ * @public
405
+ */
406
+ declare const withAdditionalInterceptors: (interceptors: NetworkInterceptors[]) => (settings: Readonly<Settings>) => Settings;
276
407
 
277
408
  /** Scaleway Request. */
278
409
  type ScwRequest = {
@@ -743,6 +874,17 @@ declare namespace index$t {
743
874
  };
744
875
  }
745
876
 
877
+ /**
878
+ * Adds asynchronously an header to a request through an interceptor.
879
+ *
880
+ * @param key - The header key
881
+ * @param value - The header value as a Promise
882
+ * @returns The Request interceptor
883
+ *
884
+ * @internal
885
+ */
886
+ declare const addAsyncHeaderInterceptor: (key: string, getter: () => Promise<string | undefined>) => RequestInterceptor;
887
+
746
888
  /**
747
889
  * Abstract class to instantiate API from a {@link Client}.
748
890
  *
@@ -762,6 +904,8 @@ interface TokenAccessor {
762
904
  * @param getToken - The token accessor
763
905
  * @returns The request interceptor
764
906
  *
907
+ * @deprecated Please use addAsyncHeaderInterceptor instead.
908
+ *
765
909
  * @internal
766
910
  */
767
911
  declare const authenticateWithSessionToken: (getToken: TokenAccessor) => RequestInterceptor;
@@ -14411,10 +14555,7 @@ type CreateClusterRequest$2 = {
14411
14555
  * could be set.
14412
14556
  */
14413
14557
  projectId?: string;
14414
- /**
14415
- * Type of the cluster. Type of the cluster (possible values are kapsule,
14416
- * multicloud).
14417
- */
14558
+ /** Type of the cluster (possible values are kapsule, multicloud). */
14418
14559
  type: string;
14419
14560
  /** Name of the cluster. */
14420
14561
  name?: string;
@@ -14561,8 +14702,8 @@ type SetClusterTypeRequest = {
14561
14702
  /** ID of the cluster to migrate from one type to another. */
14562
14703
  clusterId: string;
14563
14704
  /**
14564
- * Type of the cluster. Type of the cluster. Note that some migrations are not
14565
- * possible (please refer to product documentation).
14705
+ * Type of the cluster. Note that some migrations are not possible (please
14706
+ * refer to product documentation).
14566
14707
  */
14567
14708
  type: string;
14568
14709
  };
@@ -26750,7 +26891,7 @@ interface DnsRecord {
26750
26891
  name: string;
26751
26892
  /** Record type. */
26752
26893
  type: DnsRecordType;
26753
- /** Record time to live. */
26894
+ /** Record time-to-live. */
26754
26895
  ttl: number;
26755
26896
  /** Record value. */
26756
26897
  value: string;
@@ -26770,39 +26911,39 @@ interface DnsRecords {
26770
26911
  }
26771
26912
  /** Hosting. */
26772
26913
  interface Hosting {
26773
- /** ID of the hosting. */
26914
+ /** ID of the Web Hosting plan. */
26774
26915
  id: string;
26775
- /** Organization ID of the hosting. */
26916
+ /** ID of the Scaleway Organization the Web Hosting plan belongs to. */
26776
26917
  organizationId: string;
26777
- /** Project ID of the hosting. */
26918
+ /** ID of the Scaleway Project the Web Hosting plan belongs to. */
26778
26919
  projectId: string;
26779
- /** Last update date. */
26920
+ /** Date on which the Web Hosting plan was last updated. */
26780
26921
  updatedAt?: Date;
26781
- /** Creation date. */
26922
+ /** Date on which the Web Hosting plan was created. */
26782
26923
  createdAt?: Date;
26783
- /** The hosting status. */
26924
+ /** Status of the Web Hosting plan. */
26784
26925
  status: HostingStatus;
26785
26926
  /** Hostname of the host platform. */
26786
26927
  platformHostname: string;
26787
26928
  /** Number of the host platform. */
26788
26929
  platformNumber?: number;
26789
- /** ID of the active offer. */
26930
+ /** ID of the active offer for the Web Hosting plan. */
26790
26931
  offerId: string;
26791
- /** Name of the active offer. */
26932
+ /** Name of the active offer for the Web Hosting plan. */
26792
26933
  offerName: string;
26793
- /** Main domain of the hosting. */
26934
+ /** Main domain associated with the Web Hosting plan. */
26794
26935
  domain: string;
26795
- /** Tags of the hosting. */
26936
+ /** List of tags associated with the Web Hosting plan. */
26796
26937
  tags: string[];
26797
- /** Active options of the hosting. */
26938
+ /** Array of any options activated for the Web Hosting plan. */
26798
26939
  options: HostingOption[];
26799
- /** DNS status of the hosting. */
26940
+ /** DNS status of the Web Hosting plan. */
26800
26941
  dnsStatus: HostingDnsStatus;
26801
- /** URL to connect to cPanel Dashboard and to Webmail interface. */
26942
+ /** URL to connect to cPanel dashboard and to Webmail interface. */
26802
26943
  cpanelUrls?: HostingCpanelUrls;
26803
- /** Main hosting cPanel username. */
26944
+ /** Main Web Hosting cPanel username. */
26804
26945
  username: string;
26805
- /** Region of the hosting. */
26946
+ /** Region where the Web Hosting plan is hosted. */
26806
26947
  region: Region;
26807
26948
  }
26808
26949
  interface HostingCpanelUrls {
@@ -26818,14 +26959,14 @@ interface HostingOption {
26818
26959
  }
26819
26960
  /** List hostings response. */
26820
26961
  interface ListHostingsResponse {
26821
- /** Number of returned hostings. */
26962
+ /** Number of Web Hosting plans returned. */
26822
26963
  totalCount: number;
26823
- /** List of hostings. */
26964
+ /** List of Web Hosting plans. */
26824
26965
  hostings: Hosting[];
26825
26966
  }
26826
26967
  /** List offers response. */
26827
26968
  interface ListOffersResponse {
26828
- /** List of returned offers. */
26969
+ /** List of offers. */
26829
26970
  offers: Offer[];
26830
26971
  }
26831
26972
  /** Nameserver. */
@@ -26834,7 +26975,7 @@ interface Nameserver {
26834
26975
  hostname: string;
26835
26976
  /** Status of the nameserver. */
26836
26977
  status: NameserverStatus;
26837
- /** If the nameserver is the default. */
26978
+ /** Defines whether the nameserver is the default one. */
26838
26979
  isDefault: boolean;
26839
26980
  }
26840
26981
  /** Offer. */
@@ -26843,13 +26984,16 @@ interface Offer {
26843
26984
  id: string;
26844
26985
  /** Unique identifier used for billing. */
26845
26986
  billingOperationPath: string;
26846
- /** Offer product. */
26987
+ /** Product constituting this offer. */
26847
26988
  product?: OfferProduct;
26848
- /** Offer price. */
26989
+ /** Price of this offer. */
26849
26990
  price?: Money;
26850
- /** If offer is available for a specific hosting. */
26991
+ /**
26992
+ * If a hosting_id was specified in the call, defines whether this offer is
26993
+ * available for that Web Hosting plan to migrate (update) to.
26994
+ */
26851
26995
  available: boolean;
26852
- /** If not available, return quota warnings. */
26996
+ /** Quota warnings, if the offer is not available for the specified hosting_id. */
26853
26997
  quotaWarnings: OfferQuotaWarning[];
26854
26998
  }
26855
26999
  /** Offer. product. */
@@ -26872,17 +27016,20 @@ type CreateHostingRequest = {
26872
27016
  * config.
26873
27017
  */
26874
27018
  region?: Region;
26875
- /** ID of the selected offer for the hosting. */
27019
+ /** ID of the selected offer for the Web Hosting plan. */
26876
27020
  offerId: string;
26877
- /** Project ID of the hosting. */
27021
+ /** ID of the Scaleway Project in which to create the Web Hosting plan. */
26878
27022
  projectId?: string;
26879
- /** Contact email of the client for the hosting. */
27023
+ /** Contact email for the Web Hosting client. */
26880
27024
  email?: string;
26881
- /** The tags of the hosting. */
27025
+ /** List of tags for the Web Hosting plan. */
26882
27026
  tags?: string[];
26883
- /** The domain name of the hosting. */
27027
+ /**
27028
+ * Domain name to link to the Web Hosting plan. You must already own this
27029
+ * domain name, and have completed the DNS validation process beforehand.
27030
+ */
26884
27031
  domain: string;
26885
- /** IDs of the selected options for the hosting. */
27032
+ /** IDs of any selected additional options for the Web Hosting plan. */
26886
27033
  optionIds?: string[];
26887
27034
  };
26888
27035
  type ListHostingsRequest$1 = {
@@ -26891,24 +27038,42 @@ type ListHostingsRequest$1 = {
26891
27038
  * config.
26892
27039
  */
26893
27040
  region?: Region;
26894
- /** A positive integer to choose the page to return. */
27041
+ /**
27042
+ * Page number to return, from the paginated results (must be a positive
27043
+ * integer).
27044
+ */
26895
27045
  page?: number;
26896
27046
  /**
26897
- * A positive integer lower or equal to 100 to select the number of items to
26898
- * return.
27047
+ * Number of Web Hosting plans to return (must be a positive integer lower or
27048
+ * equal to 100).
26899
27049
  */
26900
27050
  pageSize?: number;
26901
- /** Define the order of the returned hostings. */
27051
+ /** Sort order for Web Hosting plans in the response. */
26902
27052
  orderBy?: ListHostingsRequestOrderBy;
26903
- /** Return hostings with these tags. */
27053
+ /**
27054
+ * Tags to filter for, only Web Hosting plans with matching tags will be
27055
+ * returned.
27056
+ */
26904
27057
  tags?: string[];
26905
- /** Return hostings with these statuses. */
27058
+ /**
27059
+ * Statuses to filter for, only Web Hosting plans with matching statuses will
27060
+ * be returned.
27061
+ */
26906
27062
  statuses?: HostingStatus[];
26907
- /** Return hostings with this domain. */
27063
+ /**
27064
+ * Domain to filter for, only Web Hosting plans associated with this domain
27065
+ * will be returned.
27066
+ */
26908
27067
  domain?: string;
26909
- /** Return hostings from this project ID. */
27068
+ /**
27069
+ * Project ID to filter for, only Web Hosting plans from this Project will be
27070
+ * returned.
27071
+ */
26910
27072
  projectId?: string;
26911
- /** Return hostings from this organization ID. */
27073
+ /**
27074
+ * Organization ID to filter for, only Web Hosting plans from this
27075
+ * Organization will be returned.
27076
+ */
26912
27077
  organizationId?: string;
26913
27078
  };
26914
27079
  type GetHostingRequest = {
@@ -26928,13 +27093,13 @@ type UpdateHostingRequest = {
26928
27093
  region?: Region;
26929
27094
  /** Hosting ID. */
26930
27095
  hostingId: string;
26931
- /** New contact email for the hosting. */
27096
+ /** New contact email for the Web Hosting plan. */
26932
27097
  email?: string;
26933
- /** New tags for the hosting. */
27098
+ /** New tags for the Web Hosting plan. */
26934
27099
  tags?: string[];
26935
- /** New options IDs for the hosting. */
27100
+ /** IDs of the new options for the Web Hosting plan. */
26936
27101
  optionIds?: string[];
26937
- /** New offer ID for the hosting. */
27102
+ /** ID of the new offer for the Web Hosting plan. */
26938
27103
  offerId?: string;
26939
27104
  };
26940
27105
  type DeleteHostingRequest = {
@@ -26961,7 +27126,7 @@ type GetDomainDnsRecordsRequest = {
26961
27126
  * config.
26962
27127
  */
26963
27128
  region?: Region;
26964
- /** Domain associated to the DNS records. */
27129
+ /** Domain associated with the DNS records. */
26965
27130
  domain: string;
26966
27131
  };
26967
27132
  type ListOffersRequest = {
@@ -26970,22 +27135,32 @@ type ListOffersRequest = {
26970
27135
  * config.
26971
27136
  */
26972
27137
  region?: Region;
26973
- /** Define the order of the returned hostings. */
27138
+ /** Sort order of offers in the response. */
26974
27139
  orderBy?: ListOffersRequestOrderBy;
26975
- /** Select only offers, no options. */
27140
+ /**
27141
+ * Defines whether the response should consist of offers only, without
27142
+ * options.
27143
+ */
26976
27144
  withoutOptions: boolean;
26977
- /** Select only options. */
27145
+ /**
27146
+ * Defines whether the response should consist of options only, without
27147
+ * offers.
27148
+ */
26978
27149
  onlyOptions: boolean;
26979
- /** Define a specific hosting id (optional). */
27150
+ /**
27151
+ * ID of a Web Hosting plan, to check compatibility with returned offers (in
27152
+ * case of wanting to update the plan).
27153
+ */
26980
27154
  hostingId?: string;
26981
27155
  };
26982
27156
 
26983
- /** Webhosting API. */
27157
+ /** Web Hosting API. */
26984
27158
  declare class API extends API$q {
26985
27159
  /** Lists the available regions of the API. */
26986
27160
  static readonly LOCALITIES: Region[];
26987
27161
  /**
26988
- * Create a hosting.
27162
+ * Order a Web Hosting plan. Order a Web Hosting plan, specifying the offer
27163
+ * type required via the `offer_id` parameter.
26989
27164
  *
26990
27165
  * @param request - The request {@link CreateHostingRequest}
26991
27166
  * @returns A Promise of Hosting
@@ -26993,7 +27168,9 @@ declare class API extends API$q {
26993
27168
  createHosting: (request: Readonly<CreateHostingRequest>) => Promise<Hosting>;
26994
27169
  protected pageOfListHostings: (request?: Readonly<ListHostingsRequest$1>) => Promise<ListHostingsResponse>;
26995
27170
  /**
26996
- * List all hostings.
27171
+ * List all Web Hosting plans. List all of your existing Web Hosting plans.
27172
+ * Various filters are available to limit the results, including filtering by
27173
+ * domain, status, tag and Project ID.
26997
27174
  *
26998
27175
  * @param request - The request {@link ListHostingsRequest}
26999
27176
  * @returns A Promise of ListHostingsResponse
@@ -27003,7 +27180,8 @@ declare class API extends API$q {
27003
27180
  [Symbol.asyncIterator]: () => AsyncGenerator<Hosting[], void, void>;
27004
27181
  };
27005
27182
  /**
27006
- * Get a hosting. Get the details of a Hosting with the given ID.
27183
+ * Get a Web Hosting plan. Get the details of one of your existing Web Hosting
27184
+ * plans, specified by its `hosting_id`.
27007
27185
  *
27008
27186
  * @param request - The request {@link GetHostingRequest}
27009
27187
  * @returns A Promise of Hosting
@@ -27018,36 +27196,47 @@ declare class API extends API$q {
27018
27196
  */
27019
27197
  waitForHosting: (request: Readonly<GetHostingRequest>, options?: Readonly<WaitForOptions<Hosting>>) => Promise<Hosting>;
27020
27198
  /**
27021
- * Update a hosting.
27199
+ * Update a Web Hosting plan. Update the details of one of your existing Web
27200
+ * Hosting plans, specified by its `hosting_id`. You can update parameters
27201
+ * including the contact email address, tags, options and offer.
27022
27202
  *
27023
27203
  * @param request - The request {@link UpdateHostingRequest}
27024
27204
  * @returns A Promise of Hosting
27025
27205
  */
27026
27206
  updateHosting: (request: Readonly<UpdateHostingRequest>) => Promise<Hosting>;
27027
27207
  /**
27028
- * Delete a hosting. Delete a hosting with the given ID.
27208
+ * Delete a Web Hosting plan. Delete a Web Hosting plan, specified by its
27209
+ * `hosting_id`. Note that deletion is not immediate: it will take place at
27210
+ * the end of the calendar month, after which time your Web Hosting plan and
27211
+ * all its data (files and emails) will be irreversibly lost.
27029
27212
  *
27030
27213
  * @param request - The request {@link DeleteHostingRequest}
27031
27214
  * @returns A Promise of Hosting
27032
27215
  */
27033
27216
  deleteHosting: (request: Readonly<DeleteHostingRequest>) => Promise<Hosting>;
27034
27217
  /**
27035
- * Restore a hosting. Restore a hosting with the given ID.
27218
+ * Restore a Web Hosting plan. When you [delete a Web Hosting
27219
+ * plan](#path-hostings-delete-a-hosting), definitive deletion does not take
27220
+ * place until the end of the calendar month. In the time between initiating
27221
+ * the deletion, and definitive deletion at the end of the month, you can
27222
+ * choose to **restore** the Web Hosting plan, using this endpoint and
27223
+ * specifying its `hosting_id`.
27036
27224
  *
27037
27225
  * @param request - The request {@link RestoreHostingRequest}
27038
27226
  * @returns A Promise of Hosting
27039
27227
  */
27040
27228
  restoreHosting: (request: Readonly<RestoreHostingRequest>) => Promise<Hosting>;
27041
27229
  /**
27042
- * Get the DNS records. The set of DNS record of a specific domain associated
27043
- * to a hosting.
27230
+ * Get DNS records. Get the set of DNS records of a specified domain
27231
+ * associated with a Web Hosting plan.
27044
27232
  *
27045
27233
  * @param request - The request {@link GetDomainDnsRecordsRequest}
27046
27234
  * @returns A Promise of DnsRecords
27047
27235
  */
27048
27236
  getDomainDnsRecords: (request: Readonly<GetDomainDnsRecordsRequest>) => Promise<DnsRecords>;
27049
27237
  /**
27050
- * List all offers.
27238
+ * List all offers. List the different Web Hosting offers, and their options,
27239
+ * available to order from Scaleway.
27051
27240
  *
27052
27241
  * @param request - The request {@link ListOffersRequest}
27053
27242
  * @returns A Promise of ListOffersResponse
@@ -27145,4 +27334,4 @@ declare namespace index {
27145
27334
  };
27146
27335
  }
27147
27336
 
27148
- export { API$q as API, index$s as Account, index$r as AppleSilicon, index$p as BareMetal, index$o as Billing, Client, ClientConfig, index$n as Cockpit, index$m as Container, DefaultValues, index$l as Domain, index$t as Errors, index$k as FlexibleIP, index$j as Function, index$i as IAM, index$f as IOT, index$g as Instance, index$d as K8S, index$b as LB, Logger, index$9 as MNQ, index$a as Marketplace, Money, Profile, index$8 as RDB, index$7 as Redis, Region, index$6 as Registry, RequestInterceptor, ResponseInterceptor, ScwFile, index$5 as Secret, ServiceInfo, Settings, index$4 as Test, TimeSeries, index$3 as TransactionalEmail, index$2 as VPC, index$1 as VPCGW, WaitForOptions, WaitForStopCondition, index as Webhosting, Zone, authenticateWithSessionToken, createAdvancedClient, createClient, enableConsoleLogger, enrichForPagination, isJSONObject, marshalMoney, marshalScwFile, marshalTimeSeries, resolveOneOf, setLogger, unmarshalArrayOfObject, unmarshalDate, unmarshalMapOfObject, unmarshalMoney, unmarshalScwFile, unmarshalServiceInfo, unmarshalTimeSeries, unmarshalTimeSeriesPoint, urlParams, validatePathParam, waitForResource, withDefaultPageSize, withHTTPClient, withProfile, withUserAgent, withUserAgentSuffix };
27337
+ export { API$q as API, index$s as Account, index$r as AppleSilicon, index$p as BareMetal, index$o as Billing, Client, ClientConfig, index$n as Cockpit, index$m as Container, DefaultValues, index$l as Domain, index$t as Errors, index$k as FlexibleIP, index$j as Function, index$i as IAM, index$f as IOT, index$g as Instance, index$d as K8S, index$b as LB, Logger, index$9 as MNQ, index$a as Marketplace, Money, NetworkInterceptors, Profile, index$8 as RDB, index$7 as Redis, Region, index$6 as Registry, RequestInterceptor, ResponseErrorInterceptor, ResponseInterceptor, ScwFile, index$5 as Secret, ServiceInfo, Settings, index$4 as Test, TimeSeries, index$3 as TransactionalEmail, index$2 as VPC, index$1 as VPCGW, WaitForOptions, WaitForStopCondition, index as Webhosting, Zone, addAsyncHeaderInterceptor, authenticateWithSessionToken, createAdvancedClient, createClient, enableConsoleLogger, enrichForPagination, isJSONObject, marshalMoney, marshalScwFile, marshalTimeSeries, resolveOneOf, setLogger, unmarshalArrayOfObject, unmarshalDate, unmarshalMapOfObject, unmarshalMoney, unmarshalScwFile, unmarshalServiceInfo, unmarshalTimeSeries, unmarshalTimeSeriesPoint, urlParams, validatePathParam, waitForResource, withAdditionalInterceptors, withDefaultPageSize, withHTTPClient, withProfile, withUserAgent, withUserAgentSuffix };
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  export { enableConsoleLogger, setLogger } from './internal/logger/index.js';
2
2
  export { createAdvancedClient, createClient } from './scw/client.js';
3
- export { withDefaultPageSize, withHTTPClient, withProfile, withUserAgent, withUserAgentSuffix } from './scw/client-ini-factory.js';
3
+ export { withAdditionalInterceptors, withDefaultPageSize, withHTTPClient, withProfile, withUserAgent, withUserAgentSuffix } from './scw/client-ini-factory.js';
4
4
  import * as index from './scw/errors/standard/index.js';
5
5
  export { index as Errors };
6
6
  export { isJSONObject } from './helpers/json.js';
7
7
  export { waitForResource } from './internal/async/interval-retrier.js';
8
+ export { addAsyncHeaderInterceptor } from './internal/interceptors/helpers.js';
8
9
  export { API } from './scw/api.js';
9
10
  export { authenticateWithSessionToken } from './scw/auth.js';
10
11
  export { marshalMoney, marshalScwFile, marshalTimeSeries, unmarshalMoney, unmarshalScwFile, unmarshalServiceInfo, unmarshalTimeSeries, unmarshalTimeSeriesPoint } from './scw/custom-marshalling.js';
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Composes request interceptors.
3
+ *
4
+ * @param interceptors - A list of request interceptors
5
+ * @returns An async composed interceptor
6
+ *
7
+ * @internal
8
+ */
9
+ const composeRequestInterceptors = interceptors => async request => interceptors.reduce(async (asyncResult, interceptor) => interceptor({
10
+ request: await asyncResult
11
+ }), Promise.resolve(request));
12
+
13
+ /**
14
+ * Composes response interceptors.
15
+ *
16
+ * @param interceptors - A list of response interceptors
17
+ * @returns An async composed interceptor
18
+ *
19
+ * @internal
20
+ */
21
+ const composeResponseInterceptors = interceptors => async response => interceptors.reduce(async (asyncResult, interceptor) => interceptor({
22
+ response: await asyncResult
23
+ }), Promise.resolve(response));
24
+
25
+ /**
26
+ * Compose response error interceptors.
27
+ *
28
+ * @internal
29
+ */
30
+ const composeResponseErrorInterceptors = interceptors => async (request, error) => {
31
+ let prevError = error;
32
+ for (const interceptor of interceptors) {
33
+ try {
34
+ const res = await interceptor({
35
+ request,
36
+ error: prevError
37
+ });
38
+ return res;
39
+ } catch (err) {
40
+ prevError = err;
41
+ }
42
+ }
43
+ throw prevError;
44
+ };
45
+
46
+ export { composeRequestInterceptors, composeResponseErrorInterceptors, composeResponseInterceptors };
@@ -1,5 +1,3 @@
1
- /** Request Interceptor. */
2
-
3
1
  /**
4
2
  * Adds an header to a request through an interceptor.
5
3
  *
@@ -9,7 +7,10 @@
9
7
  *
10
8
  * @internal
11
9
  */
12
- const addHeaderInterceptor = (key, value) => request => {
10
+ const addHeaderInterceptor = (key, value) => _ref => {
11
+ let {
12
+ request
13
+ } = _ref;
13
14
  const clone = request.clone();
14
15
  if (value !== undefined) {
15
16
  clone.headers.append(key, value);
package/dist/scw/auth.js CHANGED
@@ -1,4 +1,4 @@
1
- import { addAsyncHeaderInterceptor, addHeaderInterceptor } from '../internal/interceptors/request.js';
1
+ import { addAsyncHeaderInterceptor, addHeaderInterceptor } from '../internal/interceptors/helpers.js';
2
2
  import { assertValidAuthenticationSecrets } from './client-ini-profile.js';
3
3
 
4
4
  const SESSION_HEADER_KEY = 'x-session-token';
@@ -9,6 +9,8 @@ const AUTH_HEADER_KEY = 'x-auth-token';
9
9
  * @param getToken - The token accessor
10
10
  * @returns The request interceptor
11
11
  *
12
+ * @deprecated Please use addAsyncHeaderInterceptor instead.
13
+ *
12
14
  * @internal
13
15
  */
14
16
  const authenticateWithSessionToken = getToken => addAsyncHeaderInterceptor(SESSION_HEADER_KEY, getToken);