@scaleway/sdk-std 1.0.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/LICENSE +191 -0
- package/dist/index.gen.cjs +1 -0
- package/dist/index.gen.d.ts +1 -0
- package/dist/index.gen.js +1 -0
- package/dist/types.gen.d.ts +2 -0
- package/node_modules/@scaleway/sdk-client/README.md +36 -0
- package/node_modules/@scaleway/sdk-client/dist/bridge.d.ts +12 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/is-browser.cjs +4 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/is-browser.d.ts +1 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/is-browser.js +4 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/is-response.cjs +4 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/is-response.d.ts +8 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/is-response.js +4 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/json.cjs +47 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/json.d.ts +32 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/json.js +47 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/marshalling.cjs +76 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/marshalling.d.ts +60 -0
- package/node_modules/@scaleway/sdk-client/dist/helpers/marshalling.js +76 -0
- package/node_modules/@scaleway/sdk-client/dist/index.cjs +56 -0
- package/node_modules/@scaleway/sdk-client/dist/index.d.ts +16 -0
- package/node_modules/@scaleway/sdk-client/dist/index.js +56 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/async/interval-retrier.cjs +53 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/async/interval-retrier.d.ts +111 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/async/interval-retrier.js +53 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/async/sleep.cjs +6 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/async/sleep.d.ts +9 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/async/sleep.js +6 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/composer.cjs +25 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/composer.d.ts +25 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/composer.js +25 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/helpers.cjs +12 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/helpers.d.ts +21 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/helpers.js +12 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/interceptors/types.d.ts +89 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/console-logger.cjs +24 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/console-logger.d.ts +23 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/console-logger.js +24 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/index.cjs +12 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/index.d.ts +25 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/index.js +12 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/level-resolver.cjs +13 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/level-resolver.d.ts +9 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/level-resolver.js +13 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/logger/logger.d.ts +13 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/validations/string-validation.cjs +30 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/validations/string-validation.d.ts +18 -0
- package/node_modules/@scaleway/sdk-client/dist/internal/validations/string-validation.js +30 -0
- package/node_modules/@scaleway/sdk-client/dist/internals.d.ts +10 -0
- package/node_modules/@scaleway/sdk-client/dist/package.json.cjs +8 -0
- package/node_modules/@scaleway/sdk-client/dist/package.json.js +8 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/api.cjs +8 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/api.d.ts +10 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/api.js +8 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/auth.cjs +25 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/auth.d.ts +70 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/auth.js +25 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-factory.cjs +66 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-factory.d.ts +111 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-factory.js +66 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-profile.cjs +23 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-profile.d.ts +82 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client-ini-profile.js +23 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client-settings.cjs +51 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client-settings.d.ts +59 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client-settings.js +51 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client.cjs +31 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client.d.ts +71 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/client.js +31 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/constants.cjs +11 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/constants.d.ts +4 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/constants.js +11 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/custom-marshalling.cjs +152 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/custom-marshalling.d.ts +104 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/custom-marshalling.js +152 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/custom-types.cjs +11 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/custom-types.d.ts +74 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/custom-types.js +11 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/error-parser.cjs +76 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/error-parser.d.ts +12 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/error-parser.js +76 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/invalid-request-mapper.cjs +36 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/invalid-request-mapper.d.ts +12 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/invalid-request-mapper.js +36 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/unknown-resource-mapper.cjs +23 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/unknown-resource-mapper.d.ts +11 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/non-standard/unknown-resource-mapper.js +23 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/scw-error-from-json.d.ts +10 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/scw-error.cjs +43 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/scw-error.d.ts +25 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/scw-error.js +43 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/already-exists-error.cjs +31 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/already-exists-error.d.ts +16 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/already-exists-error.js +31 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/denied-authentication-error.cjs +37 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/denied-authentication-error.d.ts +15 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/denied-authentication-error.js +37 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/index.cjs +28 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/index.d.ts +17 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/index.js +28 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/invalid-arguments-error.cjs +54 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/invalid-arguments-error.d.ts +24 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/invalid-arguments-error.js +54 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/out-of-stock-error.cjs +17 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/out-of-stock-error.d.ts +14 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/out-of-stock-error.js +17 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/permissions-denied-error.cjs +29 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/permissions-denied-error.d.ts +23 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/permissions-denied-error.js +29 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/precondition-failed-error.cjs +32 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/precondition-failed-error.d.ts +15 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/precondition-failed-error.js +32 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/quotas-exceeded-error.cjs +43 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/quotas-exceeded-error.d.ts +34 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/quotas-exceeded-error.js +43 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-expired-error.cjs +31 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-expired-error.d.ts +16 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-expired-error.js +31 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-locked-error.cjs +20 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-locked-error.d.ts +15 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-locked-error.js +20 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-not-found-error.cjs +24 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-not-found-error.d.ts +15 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-not-found-error.js +24 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/too-many-requests-error.cjs +58 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/too-many-requests-error.d.ts +32 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/too-many-requests-error.js +58 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/transient-state-error.cjs +31 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/transient-state-error.d.ts +16 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/transient-state-error.js +31 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/types.cjs +15 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/types.d.ts +9 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/errors/types.js +15 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/build-fetcher.cjs +60 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/build-fetcher.d.ts +23 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/build-fetcher.js +60 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-dumper.cjs +20 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-dumper.d.ts +18 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-dumper.js +20 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-interceptors.cjs +43 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-interceptors.d.ts +38 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/http-interceptors.js +43 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/resource-paginator.cjs +36 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/resource-paginator.d.ts +47 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/resource-paginator.js +36 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/response-parser.cjs +55 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/response-parser.d.ts +25 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/response-parser.js +55 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/fetch/types.d.ts +16 -0
- package/node_modules/@scaleway/sdk-client/dist/scw/locality.d.ts +2 -0
- package/node_modules/@scaleway/sdk-client/dist/vendor/base64/index.cjs +46 -0
- package/node_modules/@scaleway/sdk-client/dist/vendor/base64/index.js +46 -0
- package/node_modules/@scaleway/sdk-client/package.json +36 -0
- package/package.json +41 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const index = require("./internal/logger/index.cjs");
|
|
4
|
+
const client = require("./scw/client.cjs");
|
|
5
|
+
const constants = require("./scw/constants.cjs");
|
|
6
|
+
const clientIniFactory = require("./scw/client-ini-factory.cjs");
|
|
7
|
+
const customTypes = require("./scw/custom-types.cjs");
|
|
8
|
+
const index$1 = require("./scw/errors/standard/index.cjs");
|
|
9
|
+
const json = require("./helpers/json.cjs");
|
|
10
|
+
const intervalRetrier = require("./internal/async/interval-retrier.cjs");
|
|
11
|
+
const helpers = require("./internal/interceptors/helpers.cjs");
|
|
12
|
+
const api = require("./scw/api.cjs");
|
|
13
|
+
const auth = require("./scw/auth.cjs");
|
|
14
|
+
const customMarshalling = require("./scw/custom-marshalling.cjs");
|
|
15
|
+
const marshalling = require("./helpers/marshalling.cjs");
|
|
16
|
+
const resourcePaginator = require("./scw/fetch/resource-paginator.cjs");
|
|
17
|
+
exports.enableConsoleLogger = index.enableConsoleLogger;
|
|
18
|
+
exports.setLogger = index.setLogger;
|
|
19
|
+
exports.createAdvancedClient = client.createAdvancedClient;
|
|
20
|
+
exports.createClient = client.createClient;
|
|
21
|
+
exports.AUTH_HEADER_KEY = constants.AUTH_HEADER_KEY;
|
|
22
|
+
exports.SESSION_HEADER_KEY = constants.SESSION_HEADER_KEY;
|
|
23
|
+
exports.withAdditionalInterceptors = clientIniFactory.withAdditionalInterceptors;
|
|
24
|
+
exports.withDefaultPageSize = clientIniFactory.withDefaultPageSize;
|
|
25
|
+
exports.withHTTPClient = clientIniFactory.withHTTPClient;
|
|
26
|
+
exports.withProfile = clientIniFactory.withProfile;
|
|
27
|
+
exports.withUserAgent = clientIniFactory.withUserAgent;
|
|
28
|
+
exports.withUserAgentSuffix = clientIniFactory.withUserAgentSuffix;
|
|
29
|
+
exports.Decimal = customTypes.Decimal;
|
|
30
|
+
exports.Errors = index$1;
|
|
31
|
+
exports.isJSONObject = json.isJSONObject;
|
|
32
|
+
exports.createExponentialBackoffStrategy = intervalRetrier.createExponentialBackoffStrategy;
|
|
33
|
+
exports.tryAtIntervals = intervalRetrier.tryAtIntervals;
|
|
34
|
+
exports.waitForResource = intervalRetrier.waitForResource;
|
|
35
|
+
exports.addAsyncHeaderInterceptor = helpers.addAsyncHeaderInterceptor;
|
|
36
|
+
exports.API = api.API;
|
|
37
|
+
exports.authenticateWithSessionToken = auth.authenticateWithSessionToken;
|
|
38
|
+
exports.marshalBlobToScwFile = customMarshalling.marshalBlobToScwFile;
|
|
39
|
+
exports.marshalDecimal = customMarshalling.marshalDecimal;
|
|
40
|
+
exports.marshalMoney = customMarshalling.marshalMoney;
|
|
41
|
+
exports.marshalScwFile = customMarshalling.marshalScwFile;
|
|
42
|
+
exports.marshalTimeSeries = customMarshalling.marshalTimeSeries;
|
|
43
|
+
exports.unmarshalAnyRes = customMarshalling.unmarshalAnyRes;
|
|
44
|
+
exports.unmarshalDecimal = customMarshalling.unmarshalDecimal;
|
|
45
|
+
exports.unmarshalMoney = customMarshalling.unmarshalMoney;
|
|
46
|
+
exports.unmarshalScwFile = customMarshalling.unmarshalScwFile;
|
|
47
|
+
exports.unmarshalServiceInfo = customMarshalling.unmarshalServiceInfo;
|
|
48
|
+
exports.unmarshalTimeSeries = customMarshalling.unmarshalTimeSeries;
|
|
49
|
+
exports.unmarshalTimeSeriesPoint = customMarshalling.unmarshalTimeSeriesPoint;
|
|
50
|
+
exports.resolveOneOf = marshalling.resolveOneOf;
|
|
51
|
+
exports.unmarshalArrayOfObject = marshalling.unmarshalArrayOfObject;
|
|
52
|
+
exports.unmarshalDate = marshalling.unmarshalDate;
|
|
53
|
+
exports.unmarshalMapOfObject = marshalling.unmarshalMapOfObject;
|
|
54
|
+
exports.urlParams = marshalling.urlParams;
|
|
55
|
+
exports.validatePathParam = marshalling.validatePathParam;
|
|
56
|
+
exports.enrichForPagination = resourcePaginator.enrichForPagination;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type { WaitForOptions, WaitForStopCondition, } from './internal/async/interval-retrier.js';
|
|
2
|
+
export type { NetworkInterceptors, RequestInterceptor, ResponseInterceptor, ResponseErrorInterceptor, } from './internal/interceptors/types';
|
|
3
|
+
export { enableConsoleLogger, setLogger } from './internal/logger/index.js';
|
|
4
|
+
export type { Logger } from './internal/logger/logger';
|
|
5
|
+
export { createClient, createAdvancedClient } from './scw/client.js';
|
|
6
|
+
export { AUTH_HEADER_KEY, SESSION_HEADER_KEY } from './scw/constants.js';
|
|
7
|
+
export type { Client } from './scw/client.js';
|
|
8
|
+
export type { Profile } from './scw/client-ini-profile.js';
|
|
9
|
+
export type { Settings } from './scw/client-settings.js';
|
|
10
|
+
export { withAdditionalInterceptors, withDefaultPageSize, withHTTPClient, withProfile, withUserAgent, withUserAgentSuffix, } from './scw/client-ini-factory.js';
|
|
11
|
+
export type { ClientConfig } from './scw/client-ini-factory.js';
|
|
12
|
+
export { Decimal } from './scw/custom-types.js';
|
|
13
|
+
export type { Money, ScwFile, TimeSeries } from './scw/custom-types.js';
|
|
14
|
+
export * as Errors from './scw/errors/standard/index.js';
|
|
15
|
+
export type { Region, Zone } from './scw/locality';
|
|
16
|
+
export * from './internals';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { enableConsoleLogger, setLogger } from "./internal/logger/index.js";
|
|
2
|
+
import { createAdvancedClient, createClient } from "./scw/client.js";
|
|
3
|
+
import { AUTH_HEADER_KEY, SESSION_HEADER_KEY } from "./scw/constants.js";
|
|
4
|
+
import { withAdditionalInterceptors, withDefaultPageSize, withHTTPClient, withProfile, withUserAgent, withUserAgentSuffix } from "./scw/client-ini-factory.js";
|
|
5
|
+
import { Decimal } from "./scw/custom-types.js";
|
|
6
|
+
import * as index from "./scw/errors/standard/index.js";
|
|
7
|
+
import { isJSONObject } from "./helpers/json.js";
|
|
8
|
+
import { createExponentialBackoffStrategy, tryAtIntervals, waitForResource } from "./internal/async/interval-retrier.js";
|
|
9
|
+
import { addAsyncHeaderInterceptor } from "./internal/interceptors/helpers.js";
|
|
10
|
+
import { API } from "./scw/api.js";
|
|
11
|
+
import { authenticateWithSessionToken } from "./scw/auth.js";
|
|
12
|
+
import { marshalBlobToScwFile, marshalDecimal, marshalMoney, marshalScwFile, marshalTimeSeries, unmarshalAnyRes, unmarshalDecimal, unmarshalMoney, unmarshalScwFile, unmarshalServiceInfo, unmarshalTimeSeries, unmarshalTimeSeriesPoint } from "./scw/custom-marshalling.js";
|
|
13
|
+
import { resolveOneOf, unmarshalArrayOfObject, unmarshalDate, unmarshalMapOfObject, urlParams, validatePathParam } from "./helpers/marshalling.js";
|
|
14
|
+
import { enrichForPagination } from "./scw/fetch/resource-paginator.js";
|
|
15
|
+
export {
|
|
16
|
+
API,
|
|
17
|
+
AUTH_HEADER_KEY,
|
|
18
|
+
Decimal,
|
|
19
|
+
index as Errors,
|
|
20
|
+
SESSION_HEADER_KEY,
|
|
21
|
+
addAsyncHeaderInterceptor,
|
|
22
|
+
authenticateWithSessionToken,
|
|
23
|
+
createAdvancedClient,
|
|
24
|
+
createClient,
|
|
25
|
+
createExponentialBackoffStrategy,
|
|
26
|
+
enableConsoleLogger,
|
|
27
|
+
enrichForPagination,
|
|
28
|
+
isJSONObject,
|
|
29
|
+
marshalBlobToScwFile,
|
|
30
|
+
marshalDecimal,
|
|
31
|
+
marshalMoney,
|
|
32
|
+
marshalScwFile,
|
|
33
|
+
marshalTimeSeries,
|
|
34
|
+
resolveOneOf,
|
|
35
|
+
setLogger,
|
|
36
|
+
tryAtIntervals,
|
|
37
|
+
unmarshalAnyRes,
|
|
38
|
+
unmarshalArrayOfObject,
|
|
39
|
+
unmarshalDate,
|
|
40
|
+
unmarshalDecimal,
|
|
41
|
+
unmarshalMapOfObject,
|
|
42
|
+
unmarshalMoney,
|
|
43
|
+
unmarshalScwFile,
|
|
44
|
+
unmarshalServiceInfo,
|
|
45
|
+
unmarshalTimeSeries,
|
|
46
|
+
unmarshalTimeSeriesPoint,
|
|
47
|
+
urlParams,
|
|
48
|
+
validatePathParam,
|
|
49
|
+
waitForResource,
|
|
50
|
+
withAdditionalInterceptors,
|
|
51
|
+
withDefaultPageSize,
|
|
52
|
+
withHTTPClient,
|
|
53
|
+
withProfile,
|
|
54
|
+
withUserAgent,
|
|
55
|
+
withUserAgentSuffix
|
|
56
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const sleep = require("./sleep.cjs");
|
|
4
|
+
const DEFAULT_TIMEOUT_SECONDS = 300;
|
|
5
|
+
const DEFAULT_MIN_DELAY_SECONDS = 1;
|
|
6
|
+
const DEFAULT_MAX_DELAY_SECONDS = 30;
|
|
7
|
+
function* createExponentialBackoffStrategy(minDelay, maxDelay) {
|
|
8
|
+
if (minDelay < 1 || maxDelay < 1 || minDelay > maxDelay) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"Waiter: minDelay must be >= 1 and maxDelay must be >= minDelay"
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
let attempt = 1;
|
|
14
|
+
const ceiling = Math.log(maxDelay / minDelay) / Math.log(2) + 1;
|
|
15
|
+
const randomInRange = (min, max) => min + Math.random() * (max - min);
|
|
16
|
+
while (true) {
|
|
17
|
+
if (attempt > ceiling) {
|
|
18
|
+
yield maxDelay;
|
|
19
|
+
} else {
|
|
20
|
+
yield randomInRange(minDelay, minDelay * 2 ** (attempt - 1));
|
|
21
|
+
}
|
|
22
|
+
attempt += 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const tryAtIntervals = async (retry, strategy, timeout = DEFAULT_TIMEOUT_SECONDS) => {
|
|
26
|
+
const timeoutTimestamp = Date.now() + timeout * 1e3;
|
|
27
|
+
let retryCount = 0;
|
|
28
|
+
while (Date.now() <= timeoutTimestamp) {
|
|
29
|
+
const delay = strategy.next(retryCount += 1).value * 1e3;
|
|
30
|
+
if (timeoutTimestamp <= Date.now() + delay) break;
|
|
31
|
+
await sleep.sleep(delay);
|
|
32
|
+
const { value, done } = await retry();
|
|
33
|
+
if (done) return value;
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`Timeout after ${timeout}s`);
|
|
36
|
+
};
|
|
37
|
+
const waitForResource = (stop, fetcher, request, options, strategy = createExponentialBackoffStrategy(
|
|
38
|
+
options?.minDelay ?? DEFAULT_MIN_DELAY_SECONDS,
|
|
39
|
+
options?.maxDelay ?? DEFAULT_MAX_DELAY_SECONDS
|
|
40
|
+
)) => tryAtIntervals(
|
|
41
|
+
async () => {
|
|
42
|
+
const value = await fetcher(request);
|
|
43
|
+
return {
|
|
44
|
+
done: await stop(value),
|
|
45
|
+
value
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
strategy,
|
|
49
|
+
options?.timeout
|
|
50
|
+
);
|
|
51
|
+
exports.createExponentialBackoffStrategy = createExponentialBackoffStrategy;
|
|
52
|
+
exports.tryAtIntervals = tryAtIntervals;
|
|
53
|
+
exports.waitForResource = waitForResource;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to retry logic between each interval.
|
|
3
|
+
*
|
|
4
|
+
* @returns The result and if it's done
|
|
5
|
+
*
|
|
6
|
+
* @throws An exception might be thrown by the logic being run
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
type Retry<T> = () => Promise<IteratorResult<T, T>>;
|
|
11
|
+
/**
|
|
12
|
+
* Generated interval strategy iterator.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
type IntervalStrategy = Generator<number, number, number>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a fixed interval strategy.
|
|
19
|
+
* It returns the same interval value whatever the retry count.
|
|
20
|
+
*
|
|
21
|
+
* @param interval - The time interval (in seconds) to wait between each run
|
|
22
|
+
* @returns A fixed interval generator
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export declare function createFixedIntervalStrategy(interval: number): IntervalStrategy;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a fibonacci interval strategy.
|
|
29
|
+
*
|
|
30
|
+
* @param base - The base interval (in seconds) that will be multiplicated with the fibonacci number
|
|
31
|
+
* @param factor - The factor so the fibonacci suite will go slower or faster
|
|
32
|
+
* @returns A fibonnacci generator
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export declare function createFibonacciIntervalStrategy(base?: number, factor?: number): IntervalStrategy;
|
|
37
|
+
/**
|
|
38
|
+
* Creates an exponential backoff interval strategy.
|
|
39
|
+
*
|
|
40
|
+
* @param minDelay - The minimum delay before the next try in seconds
|
|
41
|
+
* @param maxDelay - The maximum delay before the next try in seconds
|
|
42
|
+
* @returns An exponential backoff generator
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export declare function createExponentialBackoffStrategy(minDelay: number, maxDelay: number): IntervalStrategy;
|
|
47
|
+
/**
|
|
48
|
+
* Tries a specific logic several times until it succeeds, timeouts, or throws an exception.
|
|
49
|
+
*
|
|
50
|
+
* @param retry - The function to retry logic between each interval
|
|
51
|
+
* @param strategy - A generated interval strategy iterator
|
|
52
|
+
* @param timeout - The maximum time elapsed before timeout error
|
|
53
|
+
*
|
|
54
|
+
* @throws An timeout exception or error thrown by the logic being run
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export declare const tryAtIntervals: <T>(retry: Retry<T>, strategy: IntervalStrategy, timeout?: number) => Promise<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Represents the condition to stop waiting for a resource.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export type WaitForStopCondition<T> = (obj: T) => Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* The options to wait until a resource is ready.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export interface WaitForOptions<T> {
|
|
71
|
+
/**
|
|
72
|
+
* Timeout in seconds.
|
|
73
|
+
*
|
|
74
|
+
* @defaultValue 300 seconds (5 minutes).
|
|
75
|
+
*/
|
|
76
|
+
timeout?: number;
|
|
77
|
+
/**
|
|
78
|
+
* The minimum delay before the next try in seconds.
|
|
79
|
+
*
|
|
80
|
+
* @defaultValue 1 second.
|
|
81
|
+
*/
|
|
82
|
+
minDelay?: number;
|
|
83
|
+
/**
|
|
84
|
+
* The maximum delay before the next try in seconds.
|
|
85
|
+
*
|
|
86
|
+
* @defaultValue 30 seconds.
|
|
87
|
+
*/
|
|
88
|
+
maxDelay?: number;
|
|
89
|
+
/**
|
|
90
|
+
* The condition to stop trying.
|
|
91
|
+
*
|
|
92
|
+
* @defaultValue Waits for non-transient value.
|
|
93
|
+
*/
|
|
94
|
+
stop?: WaitForStopCondition<T>;
|
|
95
|
+
}
|
|
96
|
+
type ResourceFetcher<T, R> = (request: R) => Promise<T>;
|
|
97
|
+
/**
|
|
98
|
+
* Fetches resource several times until an expected condition is reached, timeouts, or throws an exception.
|
|
99
|
+
*
|
|
100
|
+
* @param stop - The condition to stop waiting
|
|
101
|
+
* @param fetcher - The method to retrieve resource
|
|
102
|
+
* @param request - The resource request options
|
|
103
|
+
* @param options - The retry strategy options
|
|
104
|
+
* @param strategy - An optional custom strategy
|
|
105
|
+
*
|
|
106
|
+
* @returns A promise of resource
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
export declare const waitForResource: <R, T>(stop: WaitForStopCondition<T>, fetcher: ResourceFetcher<T, R>, request: R, options?: WaitForOptions<T>, strategy?: IntervalStrategy) => Promise<Awaited<T>>;
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { sleep } from "./sleep.js";
|
|
2
|
+
const DEFAULT_TIMEOUT_SECONDS = 300;
|
|
3
|
+
const DEFAULT_MIN_DELAY_SECONDS = 1;
|
|
4
|
+
const DEFAULT_MAX_DELAY_SECONDS = 30;
|
|
5
|
+
function* createExponentialBackoffStrategy(minDelay, maxDelay) {
|
|
6
|
+
if (minDelay < 1 || maxDelay < 1 || minDelay > maxDelay) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"Waiter: minDelay must be >= 1 and maxDelay must be >= minDelay"
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
let attempt = 1;
|
|
12
|
+
const ceiling = Math.log(maxDelay / minDelay) / Math.log(2) + 1;
|
|
13
|
+
const randomInRange = (min, max) => min + Math.random() * (max - min);
|
|
14
|
+
while (true) {
|
|
15
|
+
if (attempt > ceiling) {
|
|
16
|
+
yield maxDelay;
|
|
17
|
+
} else {
|
|
18
|
+
yield randomInRange(minDelay, minDelay * 2 ** (attempt - 1));
|
|
19
|
+
}
|
|
20
|
+
attempt += 1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const tryAtIntervals = async (retry, strategy, timeout = DEFAULT_TIMEOUT_SECONDS) => {
|
|
24
|
+
const timeoutTimestamp = Date.now() + timeout * 1e3;
|
|
25
|
+
let retryCount = 0;
|
|
26
|
+
while (Date.now() <= timeoutTimestamp) {
|
|
27
|
+
const delay = strategy.next(retryCount += 1).value * 1e3;
|
|
28
|
+
if (timeoutTimestamp <= Date.now() + delay) break;
|
|
29
|
+
await sleep(delay);
|
|
30
|
+
const { value, done } = await retry();
|
|
31
|
+
if (done) return value;
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`Timeout after ${timeout}s`);
|
|
34
|
+
};
|
|
35
|
+
const waitForResource = (stop, fetcher, request, options, strategy = createExponentialBackoffStrategy(
|
|
36
|
+
options?.minDelay ?? DEFAULT_MIN_DELAY_SECONDS,
|
|
37
|
+
options?.maxDelay ?? DEFAULT_MAX_DELAY_SECONDS
|
|
38
|
+
)) => tryAtIntervals(
|
|
39
|
+
async () => {
|
|
40
|
+
const value = await fetcher(request);
|
|
41
|
+
return {
|
|
42
|
+
done: await stop(value),
|
|
43
|
+
value
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
strategy,
|
|
47
|
+
options?.timeout
|
|
48
|
+
);
|
|
49
|
+
export {
|
|
50
|
+
createExponentialBackoffStrategy,
|
|
51
|
+
tryAtIntervals,
|
|
52
|
+
waitForResource
|
|
53
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const composeRequestInterceptors = (interceptors) => async (request) => interceptors.reduce(
|
|
4
|
+
async (asyncResult, interceptor) => interceptor({ request: await asyncResult }),
|
|
5
|
+
Promise.resolve(request)
|
|
6
|
+
);
|
|
7
|
+
const composeResponseInterceptors = (interceptors) => async (response) => interceptors.reduce(
|
|
8
|
+
async (asyncResult, interceptor) => interceptor({ response: await asyncResult }),
|
|
9
|
+
Promise.resolve(response)
|
|
10
|
+
);
|
|
11
|
+
const composeResponseErrorInterceptors = (interceptors) => async (request, error) => {
|
|
12
|
+
let prevError = error;
|
|
13
|
+
for (const interceptor of interceptors) {
|
|
14
|
+
try {
|
|
15
|
+
const res = await interceptor({ request, error: prevError });
|
|
16
|
+
return res;
|
|
17
|
+
} catch (err) {
|
|
18
|
+
prevError = err;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
throw prevError;
|
|
22
|
+
};
|
|
23
|
+
exports.composeRequestInterceptors = composeRequestInterceptors;
|
|
24
|
+
exports.composeResponseErrorInterceptors = composeResponseErrorInterceptors;
|
|
25
|
+
exports.composeResponseInterceptors = composeResponseInterceptors;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RequestInterceptor, ResponseErrorInterceptor, ResponseInterceptor } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Composes request interceptors.
|
|
4
|
+
*
|
|
5
|
+
* @param interceptors - A list of request interceptors
|
|
6
|
+
* @returns An async composed interceptor
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const composeRequestInterceptors: (interceptors: RequestInterceptor[]) => (request: Request) => Promise<Request>;
|
|
11
|
+
/**
|
|
12
|
+
* Composes response interceptors.
|
|
13
|
+
*
|
|
14
|
+
* @param interceptors - A list of response interceptors
|
|
15
|
+
* @returns An async composed interceptor
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare const composeResponseInterceptors: (interceptors: ResponseInterceptor[]) => (response: Response) => Promise<Response>;
|
|
20
|
+
/**
|
|
21
|
+
* Compose response error interceptors.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare const composeResponseErrorInterceptors: (interceptors: ResponseErrorInterceptor[]) => (request: Request, error: unknown) => Promise<unknown>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const composeRequestInterceptors = (interceptors) => async (request) => interceptors.reduce(
|
|
2
|
+
async (asyncResult, interceptor) => interceptor({ request: await asyncResult }),
|
|
3
|
+
Promise.resolve(request)
|
|
4
|
+
);
|
|
5
|
+
const composeResponseInterceptors = (interceptors) => async (response) => interceptors.reduce(
|
|
6
|
+
async (asyncResult, interceptor) => interceptor({ response: await asyncResult }),
|
|
7
|
+
Promise.resolve(response)
|
|
8
|
+
);
|
|
9
|
+
const composeResponseErrorInterceptors = (interceptors) => async (request, error) => {
|
|
10
|
+
let prevError = error;
|
|
11
|
+
for (const interceptor of interceptors) {
|
|
12
|
+
try {
|
|
13
|
+
const res = await interceptor({ request, error: prevError });
|
|
14
|
+
return res;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
prevError = err;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
throw prevError;
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
composeRequestInterceptors,
|
|
23
|
+
composeResponseErrorInterceptors,
|
|
24
|
+
composeResponseInterceptors
|
|
25
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const addHeaderInterceptor = (key, value) => ({ request }) => {
|
|
4
|
+
const clone = request.clone();
|
|
5
|
+
if (value !== void 0) {
|
|
6
|
+
clone.headers.append(key, value);
|
|
7
|
+
}
|
|
8
|
+
return clone;
|
|
9
|
+
};
|
|
10
|
+
const addAsyncHeaderInterceptor = (key, getter) => async (request) => addHeaderInterceptor(key, await getter())(request);
|
|
11
|
+
exports.addAsyncHeaderInterceptor = addAsyncHeaderInterceptor;
|
|
12
|
+
exports.addHeaderInterceptor = addHeaderInterceptor;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RequestInterceptor } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Adds an header to a request through an interceptor.
|
|
4
|
+
*
|
|
5
|
+
* @param key - The header key
|
|
6
|
+
* @param value - The header value
|
|
7
|
+
* @returns The Request interceptor
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const addHeaderInterceptor: (key: string, value?: string) => RequestInterceptor;
|
|
12
|
+
/**
|
|
13
|
+
* Adds asynchronously an header to a request through an interceptor.
|
|
14
|
+
*
|
|
15
|
+
* @param key - The header key
|
|
16
|
+
* @param value - The header value as a Promise
|
|
17
|
+
* @returns The Request interceptor
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export declare const addAsyncHeaderInterceptor: (key: string, getter: () => Promise<string | undefined>) => RequestInterceptor;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const addHeaderInterceptor = (key, value) => ({ request }) => {
|
|
2
|
+
const clone = request.clone();
|
|
3
|
+
if (value !== void 0) {
|
|
4
|
+
clone.headers.append(key, value);
|
|
5
|
+
}
|
|
6
|
+
return clone;
|
|
7
|
+
};
|
|
8
|
+
const addAsyncHeaderInterceptor = (key, getter) => async (request) => addHeaderInterceptor(key, await getter())(request);
|
|
9
|
+
export {
|
|
10
|
+
addAsyncHeaderInterceptor,
|
|
11
|
+
addHeaderInterceptor
|
|
12
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the interceptor for a `Request`.
|
|
3
|
+
* This allows you to intercept requests before starting.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* Adds a custom header to a request:
|
|
7
|
+
* ```
|
|
8
|
+
* const addCustomHeaderInterceptor
|
|
9
|
+
* ({ key, value }: { key: string; value: string }): RequestInterceptor =>
|
|
10
|
+
* ({ request }) => {
|
|
11
|
+
* const clone = request.clone()
|
|
12
|
+
* clone.headers.set(key, value)
|
|
13
|
+
*
|
|
14
|
+
* return clone
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export interface RequestInterceptor {
|
|
21
|
+
({ request }: {
|
|
22
|
+
request: Readonly<Request>;
|
|
23
|
+
}): Request | Promise<Request>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Defines the interceptor for a `Response`.
|
|
27
|
+
* This allows you to intercept responses before unmarshalling.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* Adds a delay before sending the response:
|
|
31
|
+
* ```
|
|
32
|
+
* const addDelayInterceptor: ResponseInterceptor = ({ response }) =>
|
|
33
|
+
* new Promise(resolve => {
|
|
34
|
+
* setTimeout(() => resolve(response), 1000)
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export interface ResponseInterceptor {
|
|
41
|
+
({ response }: {
|
|
42
|
+
response: Readonly<Response>;
|
|
43
|
+
}): Response | Promise<Response>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Defines the interceptor for a `Response` error.
|
|
47
|
+
* This allows you to intercept a response error before exiting the whole process.
|
|
48
|
+
* You can either rethrow an error, and resolve with a different response.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* You must return either:
|
|
52
|
+
* 1. An error (`throw error` or `Promise.reject(error)`)
|
|
53
|
+
* 2. Data (directly, or via a Promise)
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* Reports error to tracking service:
|
|
57
|
+
* ```
|
|
58
|
+
* const reportErrorToTrackingService: ResponseErrorInterceptor = async ({
|
|
59
|
+
* request,
|
|
60
|
+
* error,
|
|
61
|
+
* }: {
|
|
62
|
+
* request: Request
|
|
63
|
+
* error: unknown
|
|
64
|
+
* }) => {
|
|
65
|
+
* await sendErrorToErrorService(request, error)
|
|
66
|
+
* throw error
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
export interface ResponseErrorInterceptor {
|
|
73
|
+
({ request, error }: {
|
|
74
|
+
request: Request;
|
|
75
|
+
error: unknown;
|
|
76
|
+
}): unknown;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Defines the network interceptors.
|
|
80
|
+
* Please check the documentation of {@link RequestInterceptor},
|
|
81
|
+
* {@link ResponseInterceptor} and {@link ResponseErrorInterceptor} for examples.
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
export interface NetworkInterceptors {
|
|
86
|
+
request?: RequestInterceptor;
|
|
87
|
+
response?: ResponseInterceptor;
|
|
88
|
+
responseError?: ResponseErrorInterceptor;
|
|
89
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const levelResolver = require("./level-resolver.cjs");
|
|
4
|
+
class ConsoleLogger {
|
|
5
|
+
constructor(logLevel, prefix = "", output = console) {
|
|
6
|
+
this.logLevel = logLevel;
|
|
7
|
+
this.prefix = prefix;
|
|
8
|
+
this.output = output;
|
|
9
|
+
this.level = levelResolver.LevelResolver[this.logLevel];
|
|
10
|
+
}
|
|
11
|
+
level;
|
|
12
|
+
makeMethod(method) {
|
|
13
|
+
return (message) => {
|
|
14
|
+
if (levelResolver.shouldLog(this.level, method)) {
|
|
15
|
+
this.output[method](this.prefix ? `${this.prefix} ${message}` : message);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
debug = this.makeMethod("debug");
|
|
20
|
+
error = this.makeMethod("error");
|
|
21
|
+
info = this.makeMethod("info");
|
|
22
|
+
warn = this.makeMethod("warn");
|
|
23
|
+
}
|
|
24
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LogLevel } from './level-resolver.js';
|
|
2
|
+
import type { Logger } from './logger';
|
|
3
|
+
/**
|
|
4
|
+
* A Logger using console output.
|
|
5
|
+
*
|
|
6
|
+
* @param logLevel - The logger level name
|
|
7
|
+
* @param prefix - An optional logger message prefix
|
|
8
|
+
* @param output - The output to print logs, using by default the global console object
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare class ConsoleLogger implements Logger {
|
|
13
|
+
readonly logLevel: LogLevel;
|
|
14
|
+
private readonly prefix;
|
|
15
|
+
private output;
|
|
16
|
+
private level;
|
|
17
|
+
constructor(logLevel: LogLevel, prefix?: string, output?: typeof console);
|
|
18
|
+
private makeMethod;
|
|
19
|
+
debug: (message: string) => void;
|
|
20
|
+
error: (message: string) => void;
|
|
21
|
+
info: (message: string) => void;
|
|
22
|
+
warn: (message: string) => void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LevelResolver, shouldLog } from "./level-resolver.js";
|
|
2
|
+
class ConsoleLogger {
|
|
3
|
+
constructor(logLevel, prefix = "", output = console) {
|
|
4
|
+
this.logLevel = logLevel;
|
|
5
|
+
this.prefix = prefix;
|
|
6
|
+
this.output = output;
|
|
7
|
+
this.level = LevelResolver[this.logLevel];
|
|
8
|
+
}
|
|
9
|
+
level;
|
|
10
|
+
makeMethod(method) {
|
|
11
|
+
return (message) => {
|
|
12
|
+
if (shouldLog(this.level, method)) {
|
|
13
|
+
this.output[method](this.prefix ? `${this.prefix} ${message}` : message);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
debug = this.makeMethod("debug");
|
|
18
|
+
error = this.makeMethod("error");
|
|
19
|
+
info = this.makeMethod("info");
|
|
20
|
+
warn = this.makeMethod("warn");
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
ConsoleLogger
|
|
24
|
+
};
|