@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,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const json = require("../../../helpers/json.cjs");
|
|
4
|
+
const scwError = require("../scw-error.cjs");
|
|
5
|
+
const buildMessage = (list) => `quota(s) exceeded: ${list.map((details) => {
|
|
6
|
+
const message = `Quotas reached: You have reached the maximum number of ${details.resource} authorized by your Organization. Access the quotas page from your Organization dashboard to manage quotas.`;
|
|
7
|
+
return details.scope ? `${message} for ${details.scope.kind} '${details.scope.id}'` : message;
|
|
8
|
+
}).join("; ")}`;
|
|
9
|
+
const buildScope = (detail) => {
|
|
10
|
+
if (typeof detail.organization_id === "string" && detail.organization_id.length) {
|
|
11
|
+
return { id: detail.organization_id, kind: "organization" };
|
|
12
|
+
}
|
|
13
|
+
if (typeof detail.project_id === "string" && detail.project_id.length) {
|
|
14
|
+
return { id: detail.project_id, kind: "project" };
|
|
15
|
+
}
|
|
16
|
+
return void 0;
|
|
17
|
+
};
|
|
18
|
+
class QuotasExceededError extends scwError.ScalewayError {
|
|
19
|
+
constructor(status, body, list) {
|
|
20
|
+
super(status, body, buildMessage(list));
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.body = body;
|
|
23
|
+
this.list = list;
|
|
24
|
+
this.name = "QuotasExceededError";
|
|
25
|
+
}
|
|
26
|
+
static fromJSON(status, obj) {
|
|
27
|
+
if (!Array.isArray(obj.details)) return null;
|
|
28
|
+
return new QuotasExceededError(
|
|
29
|
+
status,
|
|
30
|
+
obj,
|
|
31
|
+
obj.details.reduce(
|
|
32
|
+
(list, detail) => json.isJSONObject(detail) && typeof detail.resource === "string" && typeof detail.quota === "number" && typeof detail.current === "number" ? list.concat({
|
|
33
|
+
current: detail.current,
|
|
34
|
+
quota: detail.quota,
|
|
35
|
+
resource: detail.resource,
|
|
36
|
+
scope: buildScope(detail)
|
|
37
|
+
}) : list,
|
|
38
|
+
[]
|
|
39
|
+
)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.QuotasExceededError = QuotasExceededError;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JSONObject } from '../../../helpers/json.js';
|
|
2
|
+
import { ScalewayError } from '../scw-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* Scope of an {@link QuotasExceededErrorDetails} error.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface QuotasExceededErrorScope {
|
|
9
|
+
kind: 'organization' | 'project';
|
|
10
|
+
id: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Details of an {@link QuotasExceededError} error.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface QuotasExceededErrorDetails {
|
|
18
|
+
readonly resource: string;
|
|
19
|
+
readonly quota: number;
|
|
20
|
+
readonly current: number;
|
|
21
|
+
readonly scope?: QuotasExceededErrorScope;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* QuotasExceeded error happens when one or many resource exceed quotas during the creation of a resource.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare class QuotasExceededError extends ScalewayError {
|
|
29
|
+
readonly status: number;
|
|
30
|
+
readonly body: JSONObject;
|
|
31
|
+
readonly list: QuotasExceededErrorDetails[];
|
|
32
|
+
constructor(status: number, body: JSONObject, list: QuotasExceededErrorDetails[]);
|
|
33
|
+
static fromJSON(status: number, obj: Readonly<JSONObject>): QuotasExceededError | null;
|
|
34
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isJSONObject } from "../../../helpers/json.js";
|
|
2
|
+
import { ScalewayError } from "../scw-error.js";
|
|
3
|
+
const buildMessage = (list) => `quota(s) exceeded: ${list.map((details) => {
|
|
4
|
+
const message = `Quotas reached: You have reached the maximum number of ${details.resource} authorized by your Organization. Access the quotas page from your Organization dashboard to manage quotas.`;
|
|
5
|
+
return details.scope ? `${message} for ${details.scope.kind} '${details.scope.id}'` : message;
|
|
6
|
+
}).join("; ")}`;
|
|
7
|
+
const buildScope = (detail) => {
|
|
8
|
+
if (typeof detail.organization_id === "string" && detail.organization_id.length) {
|
|
9
|
+
return { id: detail.organization_id, kind: "organization" };
|
|
10
|
+
}
|
|
11
|
+
if (typeof detail.project_id === "string" && detail.project_id.length) {
|
|
12
|
+
return { id: detail.project_id, kind: "project" };
|
|
13
|
+
}
|
|
14
|
+
return void 0;
|
|
15
|
+
};
|
|
16
|
+
class QuotasExceededError extends ScalewayError {
|
|
17
|
+
constructor(status, body, list) {
|
|
18
|
+
super(status, body, buildMessage(list));
|
|
19
|
+
this.status = status;
|
|
20
|
+
this.body = body;
|
|
21
|
+
this.list = list;
|
|
22
|
+
this.name = "QuotasExceededError";
|
|
23
|
+
}
|
|
24
|
+
static fromJSON(status, obj) {
|
|
25
|
+
if (!Array.isArray(obj.details)) return null;
|
|
26
|
+
return new QuotasExceededError(
|
|
27
|
+
status,
|
|
28
|
+
obj,
|
|
29
|
+
obj.details.reduce(
|
|
30
|
+
(list, detail) => isJSONObject(detail) && typeof detail.resource === "string" && typeof detail.quota === "number" && typeof detail.current === "number" ? list.concat({
|
|
31
|
+
current: detail.current,
|
|
32
|
+
quota: detail.quota,
|
|
33
|
+
resource: detail.resource,
|
|
34
|
+
scope: buildScope(detail)
|
|
35
|
+
}) : list,
|
|
36
|
+
[]
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
QuotasExceededError
|
|
43
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const scwError = require("../scw-error.cjs");
|
|
4
|
+
class ResourceExpiredError extends scwError.ScalewayError {
|
|
5
|
+
constructor(status, body, resource, resourceId, expiredSince) {
|
|
6
|
+
super(
|
|
7
|
+
status,
|
|
8
|
+
body,
|
|
9
|
+
`resource ${resource} with ID ${resourceId} expired since ${expiredSince.toISOString()}`
|
|
10
|
+
);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.body = body;
|
|
13
|
+
this.resource = resource;
|
|
14
|
+
this.resourceId = resourceId;
|
|
15
|
+
this.expiredSince = expiredSince;
|
|
16
|
+
this.name = "ResourceExpiredError";
|
|
17
|
+
}
|
|
18
|
+
static fromJSON(status, obj) {
|
|
19
|
+
if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string" || typeof obj.expired_since !== "string") {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return new ResourceExpiredError(
|
|
23
|
+
status,
|
|
24
|
+
obj,
|
|
25
|
+
obj.resource,
|
|
26
|
+
obj.resource_id,
|
|
27
|
+
new Date(obj.expired_since)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ResourceExpiredError = ResourceExpiredError;
|
package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-expired-error.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JSONObject } from '../../../helpers/json.js';
|
|
2
|
+
import { ScalewayError } from '../scw-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* ResourceExpired error happens when trying to access a resource that has expired.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class ResourceExpiredError extends ScalewayError {
|
|
9
|
+
readonly status: number;
|
|
10
|
+
readonly body: JSONObject;
|
|
11
|
+
readonly resource: string;
|
|
12
|
+
readonly resourceId: string;
|
|
13
|
+
readonly expiredSince: Date;
|
|
14
|
+
constructor(status: number, body: JSONObject, resource: string, resourceId: string, expiredSince: Date);
|
|
15
|
+
static fromJSON(status: number, obj: Readonly<JSONObject>): ResourceExpiredError | null;
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ScalewayError } from "../scw-error.js";
|
|
2
|
+
class ResourceExpiredError extends ScalewayError {
|
|
3
|
+
constructor(status, body, resource, resourceId, expiredSince) {
|
|
4
|
+
super(
|
|
5
|
+
status,
|
|
6
|
+
body,
|
|
7
|
+
`resource ${resource} with ID ${resourceId} expired since ${expiredSince.toISOString()}`
|
|
8
|
+
);
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.body = body;
|
|
11
|
+
this.resource = resource;
|
|
12
|
+
this.resourceId = resourceId;
|
|
13
|
+
this.expiredSince = expiredSince;
|
|
14
|
+
this.name = "ResourceExpiredError";
|
|
15
|
+
}
|
|
16
|
+
static fromJSON(status, obj) {
|
|
17
|
+
if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string" || typeof obj.expired_since !== "string") {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return new ResourceExpiredError(
|
|
21
|
+
status,
|
|
22
|
+
obj,
|
|
23
|
+
obj.resource,
|
|
24
|
+
obj.resource_id,
|
|
25
|
+
new Date(obj.expired_since)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
ResourceExpiredError
|
|
31
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const scwError = require("../scw-error.cjs");
|
|
4
|
+
class ResourceLockedError extends scwError.ScalewayError {
|
|
5
|
+
constructor(status, body, resource, resourceId) {
|
|
6
|
+
super(status, body, `resource ${resource} with ID ${resourceId} is locked`);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.body = body;
|
|
9
|
+
this.resource = resource;
|
|
10
|
+
this.resourceId = resourceId;
|
|
11
|
+
this.name = "ResourceLockedError";
|
|
12
|
+
}
|
|
13
|
+
static fromJSON(status, obj) {
|
|
14
|
+
if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string") {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return new ResourceLockedError(status, obj, obj.resource, obj.resource_id);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ResourceLockedError = ResourceLockedError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { JSONObject } from '../../../helpers/json.js';
|
|
2
|
+
import { ScalewayError } from '../scw-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* ResourceLocked error happens when a resource is locked by trust and safety.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class ResourceLockedError extends ScalewayError {
|
|
9
|
+
readonly status: number;
|
|
10
|
+
readonly body: JSONObject;
|
|
11
|
+
readonly resource: string;
|
|
12
|
+
readonly resourceId: string;
|
|
13
|
+
constructor(status: number, body: JSONObject, resource: string, resourceId: string);
|
|
14
|
+
static fromJSON(status: number, obj: Readonly<JSONObject>): ResourceLockedError | null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ScalewayError } from "../scw-error.js";
|
|
2
|
+
class ResourceLockedError extends ScalewayError {
|
|
3
|
+
constructor(status, body, resource, resourceId) {
|
|
4
|
+
super(status, body, `resource ${resource} with ID ${resourceId} is locked`);
|
|
5
|
+
this.status = status;
|
|
6
|
+
this.body = body;
|
|
7
|
+
this.resource = resource;
|
|
8
|
+
this.resourceId = resourceId;
|
|
9
|
+
this.name = "ResourceLockedError";
|
|
10
|
+
}
|
|
11
|
+
static fromJSON(status, obj) {
|
|
12
|
+
if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string") {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return new ResourceLockedError(status, obj, obj.resource, obj.resource_id);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
ResourceLockedError
|
|
20
|
+
};
|
package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-not-found-error.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const scwError = require("../scw-error.cjs");
|
|
4
|
+
class ResourceNotFoundError extends scwError.ScalewayError {
|
|
5
|
+
constructor(status, body, resource, resourceId) {
|
|
6
|
+
super(
|
|
7
|
+
status,
|
|
8
|
+
body,
|
|
9
|
+
`resource ${resource} with ID ${resourceId} is not found`
|
|
10
|
+
);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.body = body;
|
|
13
|
+
this.resource = resource;
|
|
14
|
+
this.resourceId = resourceId;
|
|
15
|
+
this.name = "ResourceNotFoundError";
|
|
16
|
+
}
|
|
17
|
+
static fromJSON(status, obj) {
|
|
18
|
+
if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string") {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return new ResourceNotFoundError(status, obj, obj.resource, obj.resource_id);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ResourceNotFoundError = ResourceNotFoundError;
|
package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-not-found-error.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { JSONObject } from '../../../helpers/json.js';
|
|
2
|
+
import { ScalewayError } from '../scw-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* ResourceNotFound error happens when getting a resource that does not exist anymore.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class ResourceNotFoundError extends ScalewayError {
|
|
9
|
+
readonly status: number;
|
|
10
|
+
readonly body: JSONObject;
|
|
11
|
+
readonly resource: string;
|
|
12
|
+
readonly resourceId: string;
|
|
13
|
+
constructor(status: number, body: JSONObject, resource: string, resourceId: string);
|
|
14
|
+
static fromJSON(status: number, obj: Readonly<JSONObject>): ResourceNotFoundError | null;
|
|
15
|
+
}
|
package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/resource-not-found-error.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ScalewayError } from "../scw-error.js";
|
|
2
|
+
class ResourceNotFoundError extends ScalewayError {
|
|
3
|
+
constructor(status, body, resource, resourceId) {
|
|
4
|
+
super(
|
|
5
|
+
status,
|
|
6
|
+
body,
|
|
7
|
+
`resource ${resource} with ID ${resourceId} is not found`
|
|
8
|
+
);
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.body = body;
|
|
11
|
+
this.resource = resource;
|
|
12
|
+
this.resourceId = resourceId;
|
|
13
|
+
this.name = "ResourceNotFoundError";
|
|
14
|
+
}
|
|
15
|
+
static fromJSON(status, obj) {
|
|
16
|
+
if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string") {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return new ResourceNotFoundError(status, obj, obj.resource, obj.resource_id);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
ResourceNotFoundError
|
|
24
|
+
};
|
package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/too-many-requests-error.cjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const json = require("../../../helpers/json.cjs");
|
|
4
|
+
const scwError = require("../scw-error.cjs");
|
|
5
|
+
const buildMessage = (helpMessage, limit, resetSeconds, resetAt) => {
|
|
6
|
+
const details = [];
|
|
7
|
+
if (limit) {
|
|
8
|
+
if (limit.windowSeconds) {
|
|
9
|
+
details.push(`quota is ${limit.quota} for ${limit.windowSeconds}s`);
|
|
10
|
+
} else {
|
|
11
|
+
details.push(`quota is ${limit.quota}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (resetSeconds) {
|
|
15
|
+
details.push(`resets in ${resetSeconds}s`);
|
|
16
|
+
} else if (resetAt) {
|
|
17
|
+
details.push(`resets at ${resetAt.toISOString()}`);
|
|
18
|
+
}
|
|
19
|
+
let output = `too many requests`;
|
|
20
|
+
if (details.length > 0) {
|
|
21
|
+
output += ` (${details.join(", ")})`;
|
|
22
|
+
}
|
|
23
|
+
if (helpMessage.length > 0) {
|
|
24
|
+
output += `: ${helpMessage}`;
|
|
25
|
+
}
|
|
26
|
+
return output;
|
|
27
|
+
};
|
|
28
|
+
class TooManyRequestsError extends scwError.ScalewayError {
|
|
29
|
+
constructor(status, body, helpMessage, limit, resetSeconds, resetAt) {
|
|
30
|
+
super(status, body, buildMessage(helpMessage, limit, resetSeconds, resetAt));
|
|
31
|
+
this.status = status;
|
|
32
|
+
this.body = body;
|
|
33
|
+
this.helpMessage = helpMessage;
|
|
34
|
+
this.limit = limit;
|
|
35
|
+
this.resetSeconds = resetSeconds;
|
|
36
|
+
this.resetAt = resetAt;
|
|
37
|
+
this.name = "TooManyRequestsError";
|
|
38
|
+
}
|
|
39
|
+
static fromJSON(status, obj) {
|
|
40
|
+
if (typeof obj.help_message !== "string") return null;
|
|
41
|
+
let limit;
|
|
42
|
+
if (json.isJSONObject(obj.limit) && typeof obj.limit.quota === "number") {
|
|
43
|
+
limit = {
|
|
44
|
+
quota: obj.limit.quota,
|
|
45
|
+
windowSeconds: typeof obj.limit.window_seconds === "number" ? obj.limit.window_seconds : void 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return new TooManyRequestsError(
|
|
49
|
+
status,
|
|
50
|
+
obj,
|
|
51
|
+
obj.help_message,
|
|
52
|
+
limit,
|
|
53
|
+
typeof obj.reset_seconds === "number" ? obj.reset_seconds : void 0,
|
|
54
|
+
typeof obj.reset_at === "string" ? new Date(obj.reset_at) : void 0
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.TooManyRequestsError = TooManyRequestsError;
|
package/node_modules/@scaleway/sdk-client/dist/scw/errors/standard/too-many-requests-error.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { JSONObject } from '../../../helpers/json.js';
|
|
2
|
+
import { ScalewayError } from '../scw-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* Quota policy of {@link TooManyRequestsError}.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface TooManyRequestsQuotaPolicy {
|
|
9
|
+
quota: number;
|
|
10
|
+
windowSeconds?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* TooManyRequestsError error happens when fetching too many times a resource.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export declare class TooManyRequestsError extends ScalewayError {
|
|
18
|
+
readonly status: number;
|
|
19
|
+
readonly body: JSONObject;
|
|
20
|
+
readonly helpMessage: string;
|
|
21
|
+
readonly limit?: TooManyRequestsQuotaPolicy | undefined;
|
|
22
|
+
/** The number of seconds until the quota resets */
|
|
23
|
+
readonly resetSeconds?: number | undefined;
|
|
24
|
+
/** The timestamp when the quota resets */
|
|
25
|
+
readonly resetAt?: Date | undefined;
|
|
26
|
+
constructor(status: number, body: JSONObject, helpMessage: string, limit?: TooManyRequestsQuotaPolicy | undefined,
|
|
27
|
+
/** The number of seconds until the quota resets */
|
|
28
|
+
resetSeconds?: number | undefined,
|
|
29
|
+
/** The timestamp when the quota resets */
|
|
30
|
+
resetAt?: Date | undefined);
|
|
31
|
+
static fromJSON(status: number, obj: Readonly<JSONObject>): TooManyRequestsError | null;
|
|
32
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isJSONObject } from "../../../helpers/json.js";
|
|
2
|
+
import { ScalewayError } from "../scw-error.js";
|
|
3
|
+
const buildMessage = (helpMessage, limit, resetSeconds, resetAt) => {
|
|
4
|
+
const details = [];
|
|
5
|
+
if (limit) {
|
|
6
|
+
if (limit.windowSeconds) {
|
|
7
|
+
details.push(`quota is ${limit.quota} for ${limit.windowSeconds}s`);
|
|
8
|
+
} else {
|
|
9
|
+
details.push(`quota is ${limit.quota}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (resetSeconds) {
|
|
13
|
+
details.push(`resets in ${resetSeconds}s`);
|
|
14
|
+
} else if (resetAt) {
|
|
15
|
+
details.push(`resets at ${resetAt.toISOString()}`);
|
|
16
|
+
}
|
|
17
|
+
let output = `too many requests`;
|
|
18
|
+
if (details.length > 0) {
|
|
19
|
+
output += ` (${details.join(", ")})`;
|
|
20
|
+
}
|
|
21
|
+
if (helpMessage.length > 0) {
|
|
22
|
+
output += `: ${helpMessage}`;
|
|
23
|
+
}
|
|
24
|
+
return output;
|
|
25
|
+
};
|
|
26
|
+
class TooManyRequestsError extends ScalewayError {
|
|
27
|
+
constructor(status, body, helpMessage, limit, resetSeconds, resetAt) {
|
|
28
|
+
super(status, body, buildMessage(helpMessage, limit, resetSeconds, resetAt));
|
|
29
|
+
this.status = status;
|
|
30
|
+
this.body = body;
|
|
31
|
+
this.helpMessage = helpMessage;
|
|
32
|
+
this.limit = limit;
|
|
33
|
+
this.resetSeconds = resetSeconds;
|
|
34
|
+
this.resetAt = resetAt;
|
|
35
|
+
this.name = "TooManyRequestsError";
|
|
36
|
+
}
|
|
37
|
+
static fromJSON(status, obj) {
|
|
38
|
+
if (typeof obj.help_message !== "string") return null;
|
|
39
|
+
let limit;
|
|
40
|
+
if (isJSONObject(obj.limit) && typeof obj.limit.quota === "number") {
|
|
41
|
+
limit = {
|
|
42
|
+
quota: obj.limit.quota,
|
|
43
|
+
windowSeconds: typeof obj.limit.window_seconds === "number" ? obj.limit.window_seconds : void 0
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return new TooManyRequestsError(
|
|
47
|
+
status,
|
|
48
|
+
obj,
|
|
49
|
+
obj.help_message,
|
|
50
|
+
limit,
|
|
51
|
+
typeof obj.reset_seconds === "number" ? obj.reset_seconds : void 0,
|
|
52
|
+
typeof obj.reset_at === "string" ? new Date(obj.reset_at) : void 0
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
TooManyRequestsError
|
|
58
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const scwError = require("../scw-error.cjs");
|
|
4
|
+
class TransientStateError extends scwError.ScalewayError {
|
|
5
|
+
constructor(status, body, resource, resourceId, currentState) {
|
|
6
|
+
super(
|
|
7
|
+
status,
|
|
8
|
+
body,
|
|
9
|
+
`resource ${resource} with ID ${resourceId} is in a transient state: ${currentState}`
|
|
10
|
+
);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.body = body;
|
|
13
|
+
this.resource = resource;
|
|
14
|
+
this.resourceId = resourceId;
|
|
15
|
+
this.currentState = currentState;
|
|
16
|
+
this.name = "TransientStateError";
|
|
17
|
+
}
|
|
18
|
+
static fromJSON(status, obj) {
|
|
19
|
+
if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string" || typeof obj.current_state !== "string") {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return new TransientStateError(
|
|
23
|
+
status,
|
|
24
|
+
obj,
|
|
25
|
+
obj.resource,
|
|
26
|
+
obj.resource_id,
|
|
27
|
+
obj.current_state
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.TransientStateError = TransientStateError;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JSONObject } from '../../../helpers/json.js';
|
|
2
|
+
import { ScalewayError } from '../scw-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* TransientState error happens when trying to perform an action on a resource in a transient state.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class TransientStateError extends ScalewayError {
|
|
9
|
+
readonly status: number;
|
|
10
|
+
readonly body: JSONObject;
|
|
11
|
+
readonly resource: string;
|
|
12
|
+
readonly resourceId: string;
|
|
13
|
+
readonly currentState: string;
|
|
14
|
+
constructor(status: number, body: JSONObject, resource: string, resourceId: string, currentState: string);
|
|
15
|
+
static fromJSON(status: number, obj: Readonly<JSONObject>): ScalewayError | null;
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ScalewayError } from "../scw-error.js";
|
|
2
|
+
class TransientStateError extends ScalewayError {
|
|
3
|
+
constructor(status, body, resource, resourceId, currentState) {
|
|
4
|
+
super(
|
|
5
|
+
status,
|
|
6
|
+
body,
|
|
7
|
+
`resource ${resource} with ID ${resourceId} is in a transient state: ${currentState}`
|
|
8
|
+
);
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.body = body;
|
|
11
|
+
this.resource = resource;
|
|
12
|
+
this.resourceId = resourceId;
|
|
13
|
+
this.currentState = currentState;
|
|
14
|
+
this.name = "TransientStateError";
|
|
15
|
+
}
|
|
16
|
+
static fromJSON(status, obj) {
|
|
17
|
+
if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string" || typeof obj.current_state !== "string") {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return new TransientStateError(
|
|
21
|
+
status,
|
|
22
|
+
obj,
|
|
23
|
+
obj.resource,
|
|
24
|
+
obj.resource_id,
|
|
25
|
+
obj.current_state
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
TransientStateError
|
|
31
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const json = require("../../helpers/json.cjs");
|
|
4
|
+
const isRecordOfStringArray = (obj) => {
|
|
5
|
+
if (!json.isJSONObject(obj)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
for (const elt of Object.values(obj)) {
|
|
9
|
+
if (!Array.isArray(elt) || Object.values(elt).find((x) => typeof x !== "string") !== void 0) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
};
|
|
15
|
+
exports.isRecordOfStringArray = isRecordOfStringArray;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifies the object is a record of string to string[].
|
|
3
|
+
*
|
|
4
|
+
* @param obj - The object
|
|
5
|
+
* @returns Whether the object is of the expected type
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare const isRecordOfStringArray: (obj: Readonly<unknown>) => obj is Record<string, string[]>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isJSONObject } from "../../helpers/json.js";
|
|
2
|
+
const isRecordOfStringArray = (obj) => {
|
|
3
|
+
if (!isJSONObject(obj)) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
for (const elt of Object.values(obj)) {
|
|
7
|
+
if (!Array.isArray(elt) || Object.values(elt).find((x) => typeof x !== "string") !== void 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
isRecordOfStringArray
|
|
15
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const isBrowser = require("../../helpers/is-browser.cjs");
|
|
4
|
+
const composer = require("../../internal/interceptors/composer.cjs");
|
|
5
|
+
const auth = require("../auth.cjs");
|
|
6
|
+
const httpInterceptors = require("./http-interceptors.cjs");
|
|
7
|
+
const responseParser = require("./response-parser.cjs");
|
|
8
|
+
const buildRequest = (request, settings) => {
|
|
9
|
+
let { path } = request;
|
|
10
|
+
if (request.urlParams instanceof URLSearchParams) {
|
|
11
|
+
path = path.concat(`?${request.urlParams.toString()}`);
|
|
12
|
+
}
|
|
13
|
+
return new Request(`${settings.apiURL}${path}`, {
|
|
14
|
+
body: request.body,
|
|
15
|
+
headers: {
|
|
16
|
+
Accept: "application/json",
|
|
17
|
+
.../* istanbul ignore next */
|
|
18
|
+
!isBrowser.isBrowser() ? { "User-Agent": settings.userAgent } : {},
|
|
19
|
+
...request.headers
|
|
20
|
+
},
|
|
21
|
+
method: request.method
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const asIs = (response) => response;
|
|
25
|
+
const buildFetcher = (settings, httpClient) => {
|
|
26
|
+
let requestNumber = 0;
|
|
27
|
+
const prepareRequest = (requestId) => composer.composeRequestInterceptors([
|
|
28
|
+
...settings.interceptors.map((obj) => obj.request).filter((obj) => obj),
|
|
29
|
+
httpInterceptors.logRequest(requestId, httpInterceptors.obfuscateInterceptor(auth.obfuscateAuthHeadersEntry))
|
|
30
|
+
]);
|
|
31
|
+
const prepareResponse = (requestId) => composer.composeResponseInterceptors([
|
|
32
|
+
...settings.interceptors.map((obj) => obj.response).filter((obj) => obj),
|
|
33
|
+
httpInterceptors.logResponse(requestId)
|
|
34
|
+
]);
|
|
35
|
+
const prepareResponseErrors = () => composer.composeResponseErrorInterceptors(
|
|
36
|
+
settings.interceptors.map((obj) => obj.responseError).filter((obj) => obj)
|
|
37
|
+
);
|
|
38
|
+
return async (request, unwrapper = asIs) => {
|
|
39
|
+
const requestId = `${requestNumber += 1}`;
|
|
40
|
+
const reqInterceptors = prepareRequest(requestId);
|
|
41
|
+
const finalRequest = await reqInterceptors(buildRequest(request, settings));
|
|
42
|
+
try {
|
|
43
|
+
const response = await httpClient(finalRequest);
|
|
44
|
+
const resInterceptors = prepareResponse(requestId);
|
|
45
|
+
const finalResponse = await resInterceptors(response);
|
|
46
|
+
const resUnmarshaller = responseParser.responseParser(
|
|
47
|
+
unwrapper,
|
|
48
|
+
request.responseType ?? "json"
|
|
49
|
+
);
|
|
50
|
+
const unmarshaledResponse = await resUnmarshaller(finalResponse);
|
|
51
|
+
return unmarshaledResponse;
|
|
52
|
+
} catch (err) {
|
|
53
|
+
const resErrorInterceptors = prepareResponseErrors();
|
|
54
|
+
const handledError = await resErrorInterceptors(finalRequest, err);
|
|
55
|
+
return unwrapper(handledError);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
exports.buildFetcher = buildFetcher;
|
|
60
|
+
exports.buildRequest = buildRequest;
|