@scaleway/sdk-client 1.3.3 → 2.1.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.
Files changed (65) hide show
  1. package/dist/helpers/json.js +6 -7
  2. package/dist/helpers/marshalling.d.ts +0 -8
  3. package/dist/helpers/marshalling.js +18 -22
  4. package/dist/internal/async/interval-retrier.js +2 -1
  5. package/dist/internal/interceptors/types.d.ts +7 -0
  6. package/dist/package.json.js +1 -1
  7. package/dist/scw/auth.d.ts +7 -0
  8. package/dist/scw/custom-marshalling.js +5 -7
  9. package/dist/scw/errors/error-parser.js +4 -4
  10. package/dist/scw/errors/non-standard/invalid-request-mapper.d.ts +1 -3
  11. package/dist/scw/errors/non-standard/invalid-request-mapper.js +27 -29
  12. package/dist/scw/errors/non-standard/unknown-resource-mapper.d.ts +1 -3
  13. package/dist/scw/errors/non-standard/unknown-resource-mapper.js +15 -17
  14. package/dist/scw/fetch/build-fetcher.js +2 -1
  15. package/dist/scw/fetch/http-interceptors.d.ts +7 -0
  16. package/dist/vendor/base64/index.js +16 -11
  17. package/package.json +2 -4
  18. package/dist/helpers/is-browser.cjs +0 -4
  19. package/dist/helpers/is-response.cjs +0 -4
  20. package/dist/helpers/json.cjs +0 -47
  21. package/dist/helpers/marshalling.cjs +0 -76
  22. package/dist/index.cjs +0 -58
  23. package/dist/internal/async/interval-retrier.cjs +0 -53
  24. package/dist/internal/async/sleep.cjs +0 -6
  25. package/dist/internal/interceptors/composer.cjs +0 -25
  26. package/dist/internal/interceptors/helpers.cjs +0 -12
  27. package/dist/internal/logger/console-logger.cjs +0 -24
  28. package/dist/internal/logger/index.cjs +0 -12
  29. package/dist/internal/logger/level-resolver.cjs +0 -13
  30. package/dist/internal/validations/string-validation.cjs +0 -30
  31. package/dist/package.json.cjs +0 -8
  32. package/dist/scw/api.cjs +0 -8
  33. package/dist/scw/auth.cjs +0 -25
  34. package/dist/scw/client-ini-factory.cjs +0 -66
  35. package/dist/scw/client-ini-profile.cjs +0 -23
  36. package/dist/scw/client-settings.cjs +0 -51
  37. package/dist/scw/client.cjs +0 -31
  38. package/dist/scw/constants.cjs +0 -11
  39. package/dist/scw/custom-marshalling.cjs +0 -152
  40. package/dist/scw/custom-types.cjs +0 -11
  41. package/dist/scw/errors/error-parser.cjs +0 -76
  42. package/dist/scw/errors/non-standard/invalid-request-mapper.cjs +0 -36
  43. package/dist/scw/errors/non-standard/unknown-resource-mapper.cjs +0 -23
  44. package/dist/scw/errors/scw-error.cjs +0 -43
  45. package/dist/scw/errors/standard/already-exists-error.cjs +0 -31
  46. package/dist/scw/errors/standard/denied-authentication-error.cjs +0 -37
  47. package/dist/scw/errors/standard/index.cjs +0 -28
  48. package/dist/scw/errors/standard/invalid-arguments-error.cjs +0 -54
  49. package/dist/scw/errors/standard/out-of-stock-error.cjs +0 -17
  50. package/dist/scw/errors/standard/permissions-denied-error.cjs +0 -29
  51. package/dist/scw/errors/standard/precondition-failed-error.cjs +0 -32
  52. package/dist/scw/errors/standard/quotas-exceeded-error.cjs +0 -43
  53. package/dist/scw/errors/standard/resource-expired-error.cjs +0 -31
  54. package/dist/scw/errors/standard/resource-locked-error.cjs +0 -20
  55. package/dist/scw/errors/standard/resource-not-found-error.cjs +0 -24
  56. package/dist/scw/errors/standard/too-many-requests-error.cjs +0 -58
  57. package/dist/scw/errors/standard/transient-state-error.cjs +0 -31
  58. package/dist/scw/errors/types.cjs +0 -15
  59. package/dist/scw/fetch/build-fetcher.cjs +0 -60
  60. package/dist/scw/fetch/http-dumper.cjs +0 -20
  61. package/dist/scw/fetch/http-interceptors.cjs +0 -43
  62. package/dist/scw/fetch/resource-paginator.cjs +0 -36
  63. package/dist/scw/fetch/response-parser.cjs +0 -55
  64. package/dist/scw/locality.cjs +0 -16
  65. package/dist/vendor/base64/index.cjs +0 -46
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const json = require("../../helpers/json.cjs");
4
- const types = require("./types.cjs");
5
- const buildDefaultMessage = (status, body) => {
6
- const message = [`http error ${status}`];
7
- if (typeof body === "string") {
8
- message.push(body);
9
- } else if (json.isJSONObject(body)) {
10
- if (typeof body.resource === "string") {
11
- message.push(`resource ${body.resource}`);
12
- }
13
- if (typeof body.message === "string") {
14
- message.push(body.message);
15
- }
16
- if (body.fields && types.isRecordOfStringArray(body.fields)) {
17
- message.push(
18
- Object.entries(body.fields).map(([name, list]) => `${name} (${list.join(", ")})`).join(", ")
19
- );
20
- }
21
- }
22
- return message.join(": ");
23
- };
24
- class ScalewayError extends Error {
25
- constructor(status, body, message = buildDefaultMessage(status, body)) {
26
- super(message);
27
- this.status = status;
28
- this.body = body;
29
- this.message = message;
30
- this.name = "ScalewayError";
31
- this.rawMessage = typeof body === "object" && typeof body.message === "string" ? body.message : void 0;
32
- Object.setPrototypeOf(this, new.target.prototype);
33
- }
34
- /** The message originating from the payload. */
35
- rawMessage;
36
- static fromJSON(status, obj) {
37
- return new ScalewayError(status, obj);
38
- }
39
- toString() {
40
- return `${this.name}: ${this.message}`;
41
- }
42
- }
43
- exports.ScalewayError = ScalewayError;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const scwError = require("../scw-error.cjs");
4
- class AlreadyExistsError extends scwError.ScalewayError {
5
- constructor(status, body, resource, resourceId, helpMessage) {
6
- super(
7
- status,
8
- body,
9
- `resource ${resource} with ID ${resourceId} already exists: ${helpMessage}`
10
- );
11
- this.status = status;
12
- this.body = body;
13
- this.resource = resource;
14
- this.resourceId = resourceId;
15
- this.helpMessage = helpMessage;
16
- this.name = "AlreadyExistsError";
17
- }
18
- static fromJSON(status, obj) {
19
- if (typeof obj.resource !== "string" || typeof obj.resource_id !== "string" || typeof obj.help_message !== "string") {
20
- return null;
21
- }
22
- return new AlreadyExistsError(
23
- status,
24
- obj,
25
- obj.resource,
26
- obj.resource_id,
27
- obj.help_message
28
- );
29
- }
30
- }
31
- exports.AlreadyExistsError = AlreadyExistsError;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const scwError = require("../scw-error.cjs");
4
- const buildMessage = (method, reason) => {
5
- let reasonDesc;
6
- switch (reason) {
7
- case "invalid_argument":
8
- reasonDesc = `invalid ${method} format or empty value`;
9
- break;
10
- case "not_found":
11
- reasonDesc = `${method} does not exist`;
12
- break;
13
- case "expired":
14
- reasonDesc = `${method} is expired`;
15
- break;
16
- default:
17
- reasonDesc = `unknown reason for ${method}`;
18
- }
19
- return `denied authentication: ${reasonDesc}`;
20
- };
21
- class DeniedAuthenticationError extends scwError.ScalewayError {
22
- constructor(status, body, method, reason) {
23
- super(status, body, buildMessage(method, reason));
24
- this.status = status;
25
- this.body = body;
26
- this.method = method;
27
- this.reason = reason;
28
- this.name = "DeniedAuthenticationError";
29
- }
30
- static fromJSON(status, obj) {
31
- if (typeof obj.method !== "string" || typeof obj.reason !== "string") {
32
- return null;
33
- }
34
- return new DeniedAuthenticationError(status, obj, obj.method, obj.reason);
35
- }
36
- }
37
- exports.DeniedAuthenticationError = DeniedAuthenticationError;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const scwError = require("../scw-error.cjs");
4
- const alreadyExistsError = require("./already-exists-error.cjs");
5
- const deniedAuthenticationError = require("./denied-authentication-error.cjs");
6
- const invalidArgumentsError = require("./invalid-arguments-error.cjs");
7
- const outOfStockError = require("./out-of-stock-error.cjs");
8
- const permissionsDeniedError = require("./permissions-denied-error.cjs");
9
- const preconditionFailedError = require("./precondition-failed-error.cjs");
10
- const quotasExceededError = require("./quotas-exceeded-error.cjs");
11
- const resourceExpiredError = require("./resource-expired-error.cjs");
12
- const resourceLockedError = require("./resource-locked-error.cjs");
13
- const resourceNotFoundError = require("./resource-not-found-error.cjs");
14
- const tooManyRequestsError = require("./too-many-requests-error.cjs");
15
- const transientStateError = require("./transient-state-error.cjs");
16
- exports.ScalewayError = scwError.ScalewayError;
17
- exports.AlreadyExistsError = alreadyExistsError.AlreadyExistsError;
18
- exports.DeniedAuthenticationError = deniedAuthenticationError.DeniedAuthenticationError;
19
- exports.InvalidArgumentsError = invalidArgumentsError.InvalidArgumentsError;
20
- exports.OutOfStockError = outOfStockError.OutOfStockError;
21
- exports.PermissionsDeniedError = permissionsDeniedError.PermissionsDeniedError;
22
- exports.PreconditionFailedError = preconditionFailedError.PreconditionFailedError;
23
- exports.QuotasExceededError = quotasExceededError.QuotasExceededError;
24
- exports.ResourceExpiredError = resourceExpiredError.ResourceExpiredError;
25
- exports.ResourceLockedError = resourceLockedError.ResourceLockedError;
26
- exports.ResourceNotFoundError = resourceNotFoundError.ResourceNotFoundError;
27
- exports.TooManyRequestsError = tooManyRequestsError.TooManyRequestsError;
28
- exports.TransientStateError = transientStateError.TransientStateError;
@@ -1,54 +0,0 @@
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) => {
6
- const invalidArgs = list.reduce((acc, details) => {
7
- let readableReason = "";
8
- switch (details.reason) {
9
- case "required":
10
- readableReason = `is required`;
11
- break;
12
- case "format":
13
- readableReason = `is wrongly formatted`;
14
- break;
15
- case "constraint":
16
- readableReason = `does not respect constraint`;
17
- break;
18
- default:
19
- readableReason = `is invalid for unexpected reason`;
20
- break;
21
- }
22
- if (details.helpMessage && details.helpMessage.length > 0) {
23
- readableReason = readableReason.concat(`, `, details.helpMessage);
24
- }
25
- acc.push(`${details.argumentName} ${readableReason}`);
26
- return acc;
27
- }, []);
28
- return `invalid argument(s): ${invalidArgs.join("; ")}`;
29
- };
30
- class InvalidArgumentsError extends scwError.ScalewayError {
31
- constructor(status, body, details) {
32
- super(status, body, buildMessage(details));
33
- this.status = status;
34
- this.body = body;
35
- this.details = details;
36
- this.name = "InvalidArgumentsError";
37
- }
38
- static fromJSON(status, obj) {
39
- if (!Array.isArray(obj.details)) return null;
40
- return new InvalidArgumentsError(
41
- status,
42
- obj,
43
- obj.details.reduce(
44
- (list, detail) => json.isJSONObject(detail) && typeof detail.argument_name === "string" && typeof detail.reason === "string" ? list.concat({
45
- argumentName: detail.argument_name,
46
- helpMessage: typeof detail.help_message === "string" ? detail.help_message : void 0,
47
- reason: detail.reason
48
- }) : list,
49
- []
50
- )
51
- );
52
- }
53
- }
54
- exports.InvalidArgumentsError = InvalidArgumentsError;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const scwError = require("../scw-error.cjs");
4
- class OutOfStockError extends scwError.ScalewayError {
5
- constructor(status, body, resource) {
6
- super(status, body, `resource ${resource} is out of stock`);
7
- this.status = status;
8
- this.body = body;
9
- this.resource = resource;
10
- this.name = "OutOfStockError";
11
- }
12
- static fromJSON(status, obj) {
13
- if (typeof obj.resource !== "string") return null;
14
- return new OutOfStockError(status, obj, obj.resource);
15
- }
16
- }
17
- exports.OutOfStockError = OutOfStockError;
@@ -1,29 +0,0 @@
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) => `insufficient permissions: ${list.map(({ action, resource }) => `${action} ${resource}`).join("; ")}`;
6
- class PermissionsDeniedError extends scwError.ScalewayError {
7
- constructor(status, body, list) {
8
- super(status, body, buildMessage(list));
9
- this.status = status;
10
- this.body = body;
11
- this.list = list;
12
- this.name = "PermissionsDeniedError";
13
- }
14
- static fromJSON(status, obj) {
15
- if (!Array.isArray(obj.details)) return null;
16
- return new PermissionsDeniedError(
17
- status,
18
- obj,
19
- obj.details.reduce(
20
- (list, detail) => json.isJSONObject(detail) && typeof detail.resource === "string" && typeof detail.action === "string" ? list.concat({
21
- action: detail.action,
22
- resource: detail.resource
23
- }) : list,
24
- []
25
- )
26
- );
27
- }
28
- }
29
- exports.PermissionsDeniedError = PermissionsDeniedError;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const scwError = require("../scw-error.cjs");
4
- const buildMessage = (precondition, helpMessage) => {
5
- let message = `precondition failed: ${precondition}`;
6
- if (typeof helpMessage === "string" && helpMessage.length > 0) {
7
- message = message.concat(", ", helpMessage);
8
- }
9
- return message;
10
- };
11
- class PreconditionFailedError extends scwError.ScalewayError {
12
- constructor(status, body, precondition, helpMessage) {
13
- super(status, body, buildMessage(precondition, helpMessage));
14
- this.status = status;
15
- this.body = body;
16
- this.precondition = precondition;
17
- this.helpMessage = helpMessage;
18
- this.name = "PreconditionFailedError";
19
- }
20
- static fromJSON(status, obj) {
21
- if (typeof obj.precondition !== "string" || typeof obj.help_message !== "string") {
22
- return null;
23
- }
24
- return new PreconditionFailedError(
25
- status,
26
- obj,
27
- obj.precondition,
28
- obj.help_message
29
- );
30
- }
31
- }
32
- exports.PreconditionFailedError = PreconditionFailedError;
@@ -1,43 +0,0 @@
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;
@@ -1,31 +0,0 @@
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;
@@ -1,20 +0,0 @@
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;
@@ -1,24 +0,0 @@
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;
@@ -1,58 +0,0 @@
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;
@@ -1,31 +0,0 @@
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;
@@ -1,15 +0,0 @@
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;
@@ -1,60 +0,0 @@
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;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const toPascalCase = (str) => str.replace(
4
- /\w+/g,
5
- (word) => `${word[0].toUpperCase()}${word.slice(1).toLowerCase()}`
6
- );
7
- const serializeHeadersEntry = ([name, value]) => `${toPascalCase(name)}: ${value}`;
8
- const serializeHeaders = (headers) => Array.from(headers.entries(), serializeHeadersEntry);
9
- const dumpRequest = async (request) => [
10
- `${request.method.toUpperCase()}: ${request.url}`,
11
- ...serializeHeaders(request.headers),
12
- await request.clone().text()
13
- ].join("\r\n");
14
- const dumpResponse = async (response) => [
15
- `HTTP ${response.status} ${response.ok ? "OK" : "NOK"}`,
16
- ...serializeHeaders(response.headers),
17
- await response.clone().text()
18
- ].join("\r\n");
19
- exports.dumpRequest = dumpRequest;
20
- exports.dumpResponse = dumpResponse;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("../../internal/logger/index.cjs");
4
- const levelResolver = require("../../internal/logger/level-resolver.cjs");
5
- const httpDumper = require("./http-dumper.cjs");
6
- class ObfuscatedRequest extends Request {
7
- constructor(request, obfuscate) {
8
- super(request);
9
- this.request = request;
10
- this.obfuscate = obfuscate;
11
- }
12
- get headers() {
13
- return new Headers(Array.from(this.request.headers, this.obfuscate));
14
- }
15
- clone() {
16
- return new ObfuscatedRequest(this.request, this.obfuscate);
17
- }
18
- }
19
- const obfuscateInterceptor = (obfuscate) => ({ request }) => new ObfuscatedRequest(request, obfuscate);
20
- const identity = ({ request }) => request;
21
- const logRequest = (identifier, obfuscate = identity) => async ({ request }) => {
22
- if (levelResolver.shouldLog(levelResolver.LevelResolver[index.getLogger().logLevel], "debug")) {
23
- index.getLogger().debug(
24
- `--------------- Scaleway SDK REQUEST ${identifier} ---------------
25
- ${await httpDumper.dumpRequest(await obfuscate({ request }))}
26
- ---------------------------------------------------------`
27
- );
28
- }
29
- return request;
30
- };
31
- const logResponse = (identifier) => async ({ response }) => {
32
- if (levelResolver.shouldLog(levelResolver.LevelResolver[index.getLogger().logLevel], "debug")) {
33
- index.getLogger().debug(
34
- `--------------- Scaleway SDK RESPONSE ${identifier} ---------------
35
- ${await httpDumper.dumpResponse(response)}
36
- ---------------------------------------------------------`
37
- );
38
- }
39
- return response;
40
- };
41
- exports.logRequest = logRequest;
42
- exports.logResponse = logResponse;
43
- exports.obfuscateInterceptor = obfuscateInterceptor;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const extract = (key) => (result) => result[key];
4
- function* pages(key, fetcher, request, firstPage) {
5
- if (!Array.isArray(firstPage[key])) {
6
- throw new Error(`Property ${key} is not a list in paginated result`);
7
- }
8
- const getList = extract(key);
9
- let page = request.page || 1;
10
- if (page === 1) {
11
- yield Promise.resolve(getList(firstPage));
12
- page += 1;
13
- }
14
- const { length } = firstPage[key];
15
- if (!length) return;
16
- const { totalCount } = firstPage;
17
- while (page <= Math.floor((totalCount + length - 1) / length)) {
18
- yield fetcher({ ...request, page }).then(getList);
19
- page += 1;
20
- }
21
- }
22
- async function* fetchPaginated(key, fetcher, request, initial = fetcher(request)) {
23
- yield* pages(key, fetcher, request, await initial);
24
- }
25
- const fetchAll = async (key, fetcher, request, initial = fetcher(request)) => (await Promise.all(Array.from(pages(key, fetcher, request, await initial)))).flat();
26
- const enrichForPagination = (key, fetcher, request) => {
27
- const firstPage = fetcher(request);
28
- return Object.assign(firstPage, {
29
- all: () => fetchAll(key, fetcher, request, firstPage),
30
- [Symbol.asyncIterator]: () => fetchPaginated(key, fetcher, request, firstPage)
31
- });
32
- };
33
- exports.enrichForPagination = enrichForPagination;
34
- exports.extract = extract;
35
- exports.fetchAll = fetchAll;
36
- exports.fetchPaginated = fetchPaginated;