@scaleway/sdk 1.9.0 → 1.10.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/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.
289
+ */
290
+ responseInterceptors?: ResponseInterceptor[];
291
+ /**
292
+ * The Network interceptors.
205
293
  */
206
- responseInterceptors: ResponseInterceptor[];
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;
@@ -26750,7 +26894,7 @@ interface DnsRecord {
26750
26894
  name: string;
26751
26895
  /** Record type. */
26752
26896
  type: DnsRecordType;
26753
- /** Record time to live. */
26897
+ /** Record time-to-live. */
26754
26898
  ttl: number;
26755
26899
  /** Record value. */
26756
26900
  value: string;
@@ -26770,39 +26914,39 @@ interface DnsRecords {
26770
26914
  }
26771
26915
  /** Hosting. */
26772
26916
  interface Hosting {
26773
- /** ID of the hosting. */
26917
+ /** ID of the Web Hosting plan. */
26774
26918
  id: string;
26775
- /** Organization ID of the hosting. */
26919
+ /** ID of the Scaleway Organization the Web Hosting plan belongs to. */
26776
26920
  organizationId: string;
26777
- /** Project ID of the hosting. */
26921
+ /** ID of the Scaleway Project the Web Hosting plan belongs to. */
26778
26922
  projectId: string;
26779
- /** Last update date. */
26923
+ /** Date on which the Web Hosting plan was last updated. */
26780
26924
  updatedAt?: Date;
26781
- /** Creation date. */
26925
+ /** Date on which the Web Hosting plan was created. */
26782
26926
  createdAt?: Date;
26783
- /** The hosting status. */
26927
+ /** Status of the Web Hosting plan. */
26784
26928
  status: HostingStatus;
26785
26929
  /** Hostname of the host platform. */
26786
26930
  platformHostname: string;
26787
26931
  /** Number of the host platform. */
26788
26932
  platformNumber?: number;
26789
- /** ID of the active offer. */
26933
+ /** ID of the active offer for the Web Hosting plan. */
26790
26934
  offerId: string;
26791
- /** Name of the active offer. */
26935
+ /** Name of the active offer for the Web Hosting plan. */
26792
26936
  offerName: string;
26793
- /** Main domain of the hosting. */
26937
+ /** Main domain associated with the Web Hosting plan. */
26794
26938
  domain: string;
26795
- /** Tags of the hosting. */
26939
+ /** List of tags associated with the Web Hosting plan. */
26796
26940
  tags: string[];
26797
- /** Active options of the hosting. */
26941
+ /** Array of any options activated for the Web Hosting plan. */
26798
26942
  options: HostingOption[];
26799
- /** DNS status of the hosting. */
26943
+ /** DNS status of the Web Hosting plan. */
26800
26944
  dnsStatus: HostingDnsStatus;
26801
- /** URL to connect to cPanel Dashboard and to Webmail interface. */
26945
+ /** URL to connect to cPanel dashboard and to Webmail interface. */
26802
26946
  cpanelUrls?: HostingCpanelUrls;
26803
- /** Main hosting cPanel username. */
26947
+ /** Main Web Hosting cPanel username. */
26804
26948
  username: string;
26805
- /** Region of the hosting. */
26949
+ /** Region where the Web Hosting plan is hosted. */
26806
26950
  region: Region;
26807
26951
  }
26808
26952
  interface HostingCpanelUrls {
@@ -26818,14 +26962,14 @@ interface HostingOption {
26818
26962
  }
26819
26963
  /** List hostings response. */
26820
26964
  interface ListHostingsResponse {
26821
- /** Number of returned hostings. */
26965
+ /** Number of Web Hosting plans returned. */
26822
26966
  totalCount: number;
26823
- /** List of hostings. */
26967
+ /** List of Web Hosting plans. */
26824
26968
  hostings: Hosting[];
26825
26969
  }
26826
26970
  /** List offers response. */
26827
26971
  interface ListOffersResponse {
26828
- /** List of returned offers. */
26972
+ /** List of offers. */
26829
26973
  offers: Offer[];
26830
26974
  }
26831
26975
  /** Nameserver. */
@@ -26834,7 +26978,7 @@ interface Nameserver {
26834
26978
  hostname: string;
26835
26979
  /** Status of the nameserver. */
26836
26980
  status: NameserverStatus;
26837
- /** If the nameserver is the default. */
26981
+ /** Defines whether the nameserver is the default one. */
26838
26982
  isDefault: boolean;
26839
26983
  }
26840
26984
  /** Offer. */
@@ -26843,13 +26987,16 @@ interface Offer {
26843
26987
  id: string;
26844
26988
  /** Unique identifier used for billing. */
26845
26989
  billingOperationPath: string;
26846
- /** Offer product. */
26990
+ /** Product constituting this offer. */
26847
26991
  product?: OfferProduct;
26848
- /** Offer price. */
26992
+ /** Price of this offer. */
26849
26993
  price?: Money;
26850
- /** If offer is available for a specific hosting. */
26994
+ /**
26995
+ * If a hosting_id was specified in the call, defines whether this offer is
26996
+ * available for that Web Hosting plan to migrate (update) to.
26997
+ */
26851
26998
  available: boolean;
26852
- /** If not available, return quota warnings. */
26999
+ /** Quota warnings, if the offer is not available for the specified hosting_id. */
26853
27000
  quotaWarnings: OfferQuotaWarning[];
26854
27001
  }
26855
27002
  /** Offer. product. */
@@ -26872,17 +27019,20 @@ type CreateHostingRequest = {
26872
27019
  * config.
26873
27020
  */
26874
27021
  region?: Region;
26875
- /** ID of the selected offer for the hosting. */
27022
+ /** ID of the selected offer for the Web Hosting plan. */
26876
27023
  offerId: string;
26877
- /** Project ID of the hosting. */
27024
+ /** ID of the Scaleway Project in which to create the Web Hosting plan. */
26878
27025
  projectId?: string;
26879
- /** Contact email of the client for the hosting. */
27026
+ /** Contact email for the Web Hosting client. */
26880
27027
  email?: string;
26881
- /** The tags of the hosting. */
27028
+ /** List of tags for the Web Hosting plan. */
26882
27029
  tags?: string[];
26883
- /** The domain name of the hosting. */
27030
+ /**
27031
+ * Domain name to link to the Web Hosting plan. You must already own this
27032
+ * domain name, and have completed the DNS validation process beforehand.
27033
+ */
26884
27034
  domain: string;
26885
- /** IDs of the selected options for the hosting. */
27035
+ /** IDs of any selected additional options for the Web Hosting plan. */
26886
27036
  optionIds?: string[];
26887
27037
  };
26888
27038
  type ListHostingsRequest$1 = {
@@ -26891,24 +27041,42 @@ type ListHostingsRequest$1 = {
26891
27041
  * config.
26892
27042
  */
26893
27043
  region?: Region;
26894
- /** A positive integer to choose the page to return. */
27044
+ /**
27045
+ * Page number to return, from the paginated results (must be a positive
27046
+ * integer).
27047
+ */
26895
27048
  page?: number;
26896
27049
  /**
26897
- * A positive integer lower or equal to 100 to select the number of items to
26898
- * return.
27050
+ * Number of Web Hosting plans to return (must be a positive integer lower or
27051
+ * equal to 100).
26899
27052
  */
26900
27053
  pageSize?: number;
26901
- /** Define the order of the returned hostings. */
27054
+ /** Sort order for Web Hosting plans in the response. */
26902
27055
  orderBy?: ListHostingsRequestOrderBy;
26903
- /** Return hostings with these tags. */
27056
+ /**
27057
+ * Tags to filter for, only Web Hosting plans with matching tags will be
27058
+ * returned.
27059
+ */
26904
27060
  tags?: string[];
26905
- /** Return hostings with these statuses. */
27061
+ /**
27062
+ * Statuses to filter for, only Web Hosting plans with matching statuses will
27063
+ * be returned.
27064
+ */
26906
27065
  statuses?: HostingStatus[];
26907
- /** Return hostings with this domain. */
27066
+ /**
27067
+ * Domain to filter for, only Web Hosting plans associated with this domain
27068
+ * will be returned.
27069
+ */
26908
27070
  domain?: string;
26909
- /** Return hostings from this project ID. */
27071
+ /**
27072
+ * Project ID to filter for, only Web Hosting plans from this Project will be
27073
+ * returned.
27074
+ */
26910
27075
  projectId?: string;
26911
- /** Return hostings from this organization ID. */
27076
+ /**
27077
+ * Organization ID to filter for, only Web Hosting plans from this
27078
+ * Organization will be returned.
27079
+ */
26912
27080
  organizationId?: string;
26913
27081
  };
26914
27082
  type GetHostingRequest = {
@@ -26928,13 +27096,13 @@ type UpdateHostingRequest = {
26928
27096
  region?: Region;
26929
27097
  /** Hosting ID. */
26930
27098
  hostingId: string;
26931
- /** New contact email for the hosting. */
27099
+ /** New contact email for the Web Hosting plan. */
26932
27100
  email?: string;
26933
- /** New tags for the hosting. */
27101
+ /** New tags for the Web Hosting plan. */
26934
27102
  tags?: string[];
26935
- /** New options IDs for the hosting. */
27103
+ /** IDs of the new options for the Web Hosting plan. */
26936
27104
  optionIds?: string[];
26937
- /** New offer ID for the hosting. */
27105
+ /** ID of the new offer for the Web Hosting plan. */
26938
27106
  offerId?: string;
26939
27107
  };
26940
27108
  type DeleteHostingRequest = {
@@ -26961,7 +27129,7 @@ type GetDomainDnsRecordsRequest = {
26961
27129
  * config.
26962
27130
  */
26963
27131
  region?: Region;
26964
- /** Domain associated to the DNS records. */
27132
+ /** Domain associated with the DNS records. */
26965
27133
  domain: string;
26966
27134
  };
26967
27135
  type ListOffersRequest = {
@@ -26970,22 +27138,32 @@ type ListOffersRequest = {
26970
27138
  * config.
26971
27139
  */
26972
27140
  region?: Region;
26973
- /** Define the order of the returned hostings. */
27141
+ /** Sort order of offers in the response. */
26974
27142
  orderBy?: ListOffersRequestOrderBy;
26975
- /** Select only offers, no options. */
27143
+ /**
27144
+ * Defines whether the response should consist of offers only, without
27145
+ * options.
27146
+ */
26976
27147
  withoutOptions: boolean;
26977
- /** Select only options. */
27148
+ /**
27149
+ * Defines whether the response should consist of options only, without
27150
+ * offers.
27151
+ */
26978
27152
  onlyOptions: boolean;
26979
- /** Define a specific hosting id (optional). */
27153
+ /**
27154
+ * ID of a Web Hosting plan, to check compatibility with returned offers (in
27155
+ * case of wanting to update the plan).
27156
+ */
26980
27157
  hostingId?: string;
26981
27158
  };
26982
27159
 
26983
- /** Webhosting API. */
27160
+ /** Web Hosting API. */
26984
27161
  declare class API extends API$q {
26985
27162
  /** Lists the available regions of the API. */
26986
27163
  static readonly LOCALITIES: Region[];
26987
27164
  /**
26988
- * Create a hosting.
27165
+ * Order a Web Hosting plan. Order a Web Hosting plan, specifying the offer
27166
+ * type required via the `offer_id` parameter.
26989
27167
  *
26990
27168
  * @param request - The request {@link CreateHostingRequest}
26991
27169
  * @returns A Promise of Hosting
@@ -26993,7 +27171,9 @@ declare class API extends API$q {
26993
27171
  createHosting: (request: Readonly<CreateHostingRequest>) => Promise<Hosting>;
26994
27172
  protected pageOfListHostings: (request?: Readonly<ListHostingsRequest$1>) => Promise<ListHostingsResponse>;
26995
27173
  /**
26996
- * List all hostings.
27174
+ * List all Web Hosting plans. List all of your existing Web Hosting plans.
27175
+ * Various filters are available to limit the results, including filtering by
27176
+ * domain, status, tag and Project ID.
26997
27177
  *
26998
27178
  * @param request - The request {@link ListHostingsRequest}
26999
27179
  * @returns A Promise of ListHostingsResponse
@@ -27003,7 +27183,8 @@ declare class API extends API$q {
27003
27183
  [Symbol.asyncIterator]: () => AsyncGenerator<Hosting[], void, void>;
27004
27184
  };
27005
27185
  /**
27006
- * Get a hosting. Get the details of a Hosting with the given ID.
27186
+ * Get a Web Hosting plan. Get the details of one of your existing Web Hosting
27187
+ * plans, specified by its `hosting_id`.
27007
27188
  *
27008
27189
  * @param request - The request {@link GetHostingRequest}
27009
27190
  * @returns A Promise of Hosting
@@ -27018,36 +27199,47 @@ declare class API extends API$q {
27018
27199
  */
27019
27200
  waitForHosting: (request: Readonly<GetHostingRequest>, options?: Readonly<WaitForOptions<Hosting>>) => Promise<Hosting>;
27020
27201
  /**
27021
- * Update a hosting.
27202
+ * Update a Web Hosting plan. Update the details of one of your existing Web
27203
+ * Hosting plans, specified by its `hosting_id`. You can update parameters
27204
+ * including the contact email address, tags, options and offer.
27022
27205
  *
27023
27206
  * @param request - The request {@link UpdateHostingRequest}
27024
27207
  * @returns A Promise of Hosting
27025
27208
  */
27026
27209
  updateHosting: (request: Readonly<UpdateHostingRequest>) => Promise<Hosting>;
27027
27210
  /**
27028
- * Delete a hosting. Delete a hosting with the given ID.
27211
+ * Delete a Web Hosting plan. Delete a Web Hosting plan, specified by its
27212
+ * `hosting_id`. Note that deletion is not immediate: it will take place at
27213
+ * the end of the calendar month, after which time your Web Hosting plan and
27214
+ * all its data (files and emails) will be irreversibly lost.
27029
27215
  *
27030
27216
  * @param request - The request {@link DeleteHostingRequest}
27031
27217
  * @returns A Promise of Hosting
27032
27218
  */
27033
27219
  deleteHosting: (request: Readonly<DeleteHostingRequest>) => Promise<Hosting>;
27034
27220
  /**
27035
- * Restore a hosting. Restore a hosting with the given ID.
27221
+ * Restore a Web Hosting plan. When you [delete a Web Hosting
27222
+ * plan](#path-hostings-delete-a-hosting), definitive deletion does not take
27223
+ * place until the end of the calendar month. In the time between initiating
27224
+ * the deletion, and definitive deletion at the end of the month, you can
27225
+ * choose to **restore** the Web Hosting plan, using this endpoint and
27226
+ * specifying its `hosting_id`.
27036
27227
  *
27037
27228
  * @param request - The request {@link RestoreHostingRequest}
27038
27229
  * @returns A Promise of Hosting
27039
27230
  */
27040
27231
  restoreHosting: (request: Readonly<RestoreHostingRequest>) => Promise<Hosting>;
27041
27232
  /**
27042
- * Get the DNS records. The set of DNS record of a specific domain associated
27043
- * to a hosting.
27233
+ * Get DNS records. Get the set of DNS records of a specified domain
27234
+ * associated with a Web Hosting plan.
27044
27235
  *
27045
27236
  * @param request - The request {@link GetDomainDnsRecordsRequest}
27046
27237
  * @returns A Promise of DnsRecords
27047
27238
  */
27048
27239
  getDomainDnsRecords: (request: Readonly<GetDomainDnsRecordsRequest>) => Promise<DnsRecords>;
27049
27240
  /**
27050
- * List all offers.
27241
+ * List all offers. List the different Web Hosting offers, and their options,
27242
+ * available to order from Scaleway.
27051
27243
  *
27052
27244
  * @param request - The request {@link ListOffersRequest}
27053
27245
  * @returns A Promise of ListOffersResponse
@@ -27145,4 +27337,4 @@ declare namespace index {
27145
27337
  };
27146
27338
  }
27147
27339
 
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 };
27340
+ 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);