cliodot 1.2.3 → 1.2.4
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 +201 -0
- package/README.md +2 -0
- package/dist/AuthAppClient.d.ts +1 -0
- package/dist/AuthAppClient.d.ts.map +1 -1
- package/dist/AuthAppClient.js +199 -1
- package/dist/CommercialAppClient.d.ts +50 -9
- package/dist/CommercialAppClient.d.ts.map +1 -1
- package/dist/CommercialAppClient.js +576 -1
- package/dist/ConnectorBuilder.js +104 -1
- package/dist/Events.d.ts +2 -0
- package/dist/Events.d.ts.map +1 -1
- package/dist/Events.js +325 -1
- package/dist/Flosync.js +296 -1
- package/dist/FlosyncClient.js +429 -1
- package/dist/FunctionBuilder.js +65 -1
- package/dist/IdentityAppClient.d.ts +1 -0
- package/dist/IdentityAppClient.d.ts.map +1 -1
- package/dist/IdentityAppClient.js +197 -1
- package/dist/MemoryAppClient.d.ts +1 -0
- package/dist/MemoryAppClient.d.ts.map +1 -1
- package/dist/MemoryAppClient.js +149 -1
- package/dist/MemoryClient.js +20 -1
- package/dist/OAuthAppClient.d.ts +1 -0
- package/dist/OAuthAppClient.d.ts.map +1 -1
- package/dist/OAuthAppClient.js +269 -1
- package/dist/ProviderServicesClient.d.ts +24 -0
- package/dist/ProviderServicesClient.d.ts.map +1 -0
- package/dist/ProviderServicesClient.js +158 -0
- package/dist/Surface.d.ts +2 -0
- package/dist/Surface.d.ts.map +1 -1
- package/dist/Surface.js +255 -1
- package/dist/ValidatorBuilder.js +24 -1
- package/dist/Webhooks.js +61 -1
- package/dist/WorkflowBuilder.js +279 -1
- package/dist/__tests__/CommercialAppClient.test.d.ts +2 -0
- package/dist/__tests__/CommercialAppClient.test.d.ts.map +1 -0
- package/dist/__tests__/CommercialAppClient.test.js +217 -0
- package/dist/__tests__/Events.test.js +191 -1
- package/dist/__tests__/IdentityAppClient.test.js +232 -1
- package/dist/__tests__/OAuthAppClient.test.js +300 -1
- package/dist/__tests__/ProviderServicesClient.test.d.ts +2 -0
- package/dist/__tests__/ProviderServicesClient.test.d.ts.map +1 -0
- package/dist/__tests__/ProviderServicesClient.test.js +131 -0
- package/dist/__tests__/Surface.test.js +150 -1
- package/dist/__tests__/errors.test.js +54 -1
- package/dist/__tests__/function.test.js +58 -1
- package/dist/__tests__/helpers.d.ts +5 -0
- package/dist/__tests__/helpers.d.ts.map +1 -0
- package/dist/__tests__/helpers.js +10 -0
- package/dist/__tests__/localhost-lookup.test.d.ts +2 -0
- package/dist/__tests__/localhost-lookup.test.d.ts.map +1 -0
- package/dist/__tests__/localhost-lookup.test.js +26 -0
- package/dist/__tests__/parse-api-error.test.js +26 -1
- package/dist/__tests__/runner.test.js +156 -1
- package/dist/connectors/builtin.js +354 -1
- package/dist/connectors/registry.js +300 -1
- package/dist/decorators/build.js +105 -1
- package/dist/decorators/connector.js +56 -1
- package/dist/decorators/index.js +34 -1
- package/dist/decorators/metadata.js +338 -1
- package/dist/decorators/steps.js +220 -1
- package/dist/decorators/workflow.js +52 -1
- package/dist/errors.js +76 -1
- package/dist/http/__tests__/cliodot-request.environment.test.d.ts +2 -0
- package/dist/http/__tests__/cliodot-request.environment.test.d.ts.map +1 -0
- package/dist/http/__tests__/cliodot-request.environment.test.js +37 -0
- package/dist/http/__tests__/cliodot-result.test.d.ts +2 -0
- package/dist/http/__tests__/cliodot-result.test.d.ts.map +1 -0
- package/dist/http/__tests__/cliodot-result.test.js +57 -0
- package/dist/http/__tests__/events-instance-id.test.d.ts +2 -0
- package/dist/http/__tests__/events-instance-id.test.d.ts.map +1 -0
- package/dist/http/__tests__/events-instance-id.test.js +45 -0
- package/dist/http/cliodot-request.d.ts +35 -0
- package/dist/http/cliodot-request.d.ts.map +1 -0
- package/dist/http/cliodot-request.js +105 -0
- package/dist/http/cliodot-result.d.ts +40 -0
- package/dist/http/cliodot-result.d.ts.map +1 -0
- package/dist/http/cliodot-result.js +139 -0
- package/dist/http/create-client.d.ts +3 -0
- package/dist/http/create-client.d.ts.map +1 -0
- package/dist/http/create-client.js +14 -0
- package/dist/http/events-instance-id.d.ts +11 -0
- package/dist/http/events-instance-id.d.ts.map +1 -0
- package/dist/http/events-instance-id.js +86 -0
- package/dist/http/localhost-lookup.d.ts +12 -0
- package/dist/http/localhost-lookup.d.ts.map +1 -0
- package/dist/http/localhost-lookup.js +67 -0
- package/dist/http/parse-api-error.js +56 -1
- package/dist/http/sanitize-execution-headers.js +79 -1
- package/dist/identity-offline-verify.js +174 -1
- package/dist/identity-token-cache.js +51 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -1
- package/dist/runner/ProcessorEngine.js +1311 -1
- package/dist/runner/connector.executor.js +1786 -1
- package/dist/runner/utilities/math.executor.js +153 -1
- package/dist/runner/utilities/random.executor.js +151 -1
- package/dist/runner/utilities/string.executor.js +825 -1
- package/dist/template.js +127 -1
- package/dist/transformers/StepsToNodesTransformer.js +214 -1
- package/dist/transformers/WorkflowTransformer.js +189 -1
- package/dist/types/auth-app.api.d.ts +2 -0
- package/dist/types/auth-app.api.d.ts.map +1 -1
- package/dist/types/auth-app.api.js +2 -1
- package/dist/types/builtin.js +2 -1
- package/dist/types/client.api.js +2 -1
- package/dist/types/commercial-app.api.d.ts +407 -11
- package/dist/types/commercial-app.api.d.ts.map +1 -1
- package/dist/types/commercial-app.api.js +2 -1
- package/dist/types/connector.js +2 -1
- package/dist/types/context.js +2 -1
- package/dist/types/event-app.api.d.ts +8 -0
- package/dist/types/event-app.api.d.ts.map +1 -1
- package/dist/types/event-app.api.js +2 -1
- package/dist/types/function.js +2 -1
- package/dist/types/identity-app.api.d.ts +2 -0
- package/dist/types/identity-app.api.d.ts.map +1 -1
- package/dist/types/identity-app.api.js +2 -1
- package/dist/types/index.js +23 -1
- package/dist/types/memory-app.api.d.ts +2 -0
- package/dist/types/memory-app.api.d.ts.map +1 -1
- package/dist/types/memory-app.api.js +2 -1
- package/dist/types/oauth-app.api.d.ts +2 -0
- package/dist/types/oauth-app.api.d.ts.map +1 -1
- package/dist/types/oauth-app.api.js +105 -1
- package/dist/types/provider-services.api.d.ts +98 -0
- package/dist/types/provider-services.api.d.ts.map +1 -0
- package/dist/types/provider-services.api.js +2 -0
- package/dist/types/validator.js +2 -1
- package/dist/types/webhook-app.api.js +2 -1
- package/dist/types/workflow.js +33 -1
- package/dist/validators/validators.js +478 -1
- package/dist/variable.js +37 -1
- package/package.json +3 -2
|
@@ -1 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Workflow = Workflow;
|
|
4
|
+
exports.Http = Http;
|
|
5
|
+
exports.Webhook = Webhook;
|
|
6
|
+
exports.Job = Job;
|
|
7
|
+
exports.Schedule = Schedule;
|
|
8
|
+
const workflow_1 = require("../types/workflow");
|
|
9
|
+
const metadata_1 = require("./metadata");
|
|
10
|
+
function Workflow(workflowId, workflowName) {
|
|
11
|
+
return function (ctor) {
|
|
12
|
+
const meta = (0, metadata_1.getOrCreateWorkflowMeta)(ctor);
|
|
13
|
+
if (workflowId)
|
|
14
|
+
meta.workflowId = workflowId;
|
|
15
|
+
if (workflowName)
|
|
16
|
+
meta.workflowName = workflowName;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function Http(method, path) {
|
|
20
|
+
return function (ctor) {
|
|
21
|
+
const meta = (0, metadata_1.getOrCreateWorkflowMeta)(ctor);
|
|
22
|
+
const trigger = {
|
|
23
|
+
type: workflow_1.WorkflowTriggerType.HTTP,
|
|
24
|
+
webhook_url: path,
|
|
25
|
+
webhookMethod: method,
|
|
26
|
+
};
|
|
27
|
+
meta.trigger = trigger;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function Webhook(method, path) {
|
|
31
|
+
return Http(method, path);
|
|
32
|
+
}
|
|
33
|
+
function Job(cron, timezone) {
|
|
34
|
+
return function (ctor) {
|
|
35
|
+
const meta = (0, metadata_1.getOrCreateWorkflowMeta)(ctor);
|
|
36
|
+
meta.trigger = {
|
|
37
|
+
type: workflow_1.WorkflowTriggerType.JOB,
|
|
38
|
+
cron: cron ?? "* * * * *",
|
|
39
|
+
timezone,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function Schedule(cron, timezone) {
|
|
44
|
+
return function (ctor) {
|
|
45
|
+
const meta = (0, metadata_1.getOrCreateWorkflowMeta)(ctor);
|
|
46
|
+
meta.trigger = {
|
|
47
|
+
type: workflow_1.WorkflowTriggerType.SCHEDULE,
|
|
48
|
+
cron,
|
|
49
|
+
timezone,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
package/dist/errors.js
CHANGED
|
@@ -1 +1,76 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CliodotApiError = void 0;
|
|
4
|
+
exports.cliodotApiErrorFromAxios = cliodotApiErrorFromAxios;
|
|
5
|
+
const parse_api_error_1 = require("./http/parse-api-error");
|
|
6
|
+
function coerceErrorMessage(message, fallback) {
|
|
7
|
+
if (typeof message === "string" && message.trim())
|
|
8
|
+
return message.trim();
|
|
9
|
+
if (message && typeof message === "object") {
|
|
10
|
+
const parsed = (0, parse_api_error_1.parseApiErrorMessage)(message);
|
|
11
|
+
if (parsed)
|
|
12
|
+
return parsed;
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(message);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return fallback;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return fallback;
|
|
21
|
+
}
|
|
22
|
+
function isAxiosLikeResponse(value) {
|
|
23
|
+
if (!value || typeof value !== "object")
|
|
24
|
+
return false;
|
|
25
|
+
const candidate = value;
|
|
26
|
+
return ("data" in candidate &&
|
|
27
|
+
("config" in candidate || "request" in candidate || "headers" in candidate));
|
|
28
|
+
}
|
|
29
|
+
function resolveApiBody(options) {
|
|
30
|
+
if (options?.data !== undefined) {
|
|
31
|
+
return options.data;
|
|
32
|
+
}
|
|
33
|
+
if (isAxiosLikeResponse(options?.response)) {
|
|
34
|
+
return options?.response?.data;
|
|
35
|
+
}
|
|
36
|
+
return options?.response;
|
|
37
|
+
}
|
|
38
|
+
class CliodotApiError extends Error {
|
|
39
|
+
constructor(message, options) {
|
|
40
|
+
const data = resolveApiBody(options);
|
|
41
|
+
const resolved = coerceErrorMessage(message, "") ||
|
|
42
|
+
(0, parse_api_error_1.parseApiErrorMessage)(data) ||
|
|
43
|
+
"Request failed";
|
|
44
|
+
super(resolved);
|
|
45
|
+
this.name = "CliodotApiError";
|
|
46
|
+
this.status =
|
|
47
|
+
options?.status ??
|
|
48
|
+
(0, parse_api_error_1.parseApiErrorStatus)(data, isAxiosLikeResponse(options?.response)
|
|
49
|
+
? options?.response?.status
|
|
50
|
+
: undefined);
|
|
51
|
+
this.response = data;
|
|
52
|
+
this.data = data;
|
|
53
|
+
this.code = options?.code ?? (0, parse_api_error_1.parseApiErrorCode)(this.data);
|
|
54
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
55
|
+
}
|
|
56
|
+
toJSON() {
|
|
57
|
+
return {
|
|
58
|
+
name: this.name,
|
|
59
|
+
message: this.message,
|
|
60
|
+
status: this.status,
|
|
61
|
+
code: this.code,
|
|
62
|
+
data: this.data,
|
|
63
|
+
response: this.response,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.CliodotApiError = CliodotApiError;
|
|
68
|
+
function cliodotApiErrorFromAxios(err, fallbackMessage) {
|
|
69
|
+
const data = err?.response?.data;
|
|
70
|
+
const message = (0, parse_api_error_1.parseApiErrorMessage)(data) || err?.message || fallbackMessage;
|
|
71
|
+
return new CliodotApiError(message, {
|
|
72
|
+
status: (0, parse_api_error_1.parseApiErrorStatus)(data, err?.response?.status),
|
|
73
|
+
data,
|
|
74
|
+
code: (0, parse_api_error_1.parseApiErrorCode)(data),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cliodot-request.environment.test.d.ts","sourceRoot":"","sources":["../../../src/http/__tests__/cliodot-request.environment.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cliodot_request_1 = require("../cliodot-request");
|
|
4
|
+
describe("SDK environment headers", () => {
|
|
5
|
+
it("normalizes aliases and ignores invalid values", () => {
|
|
6
|
+
expect((0, cliodot_request_1.normalizeSdkEnvironment)("development")).toBe("dev");
|
|
7
|
+
expect((0, cliodot_request_1.normalizeSdkEnvironment)("production")).toBe("prod");
|
|
8
|
+
expect((0, cliodot_request_1.normalizeSdkEnvironment)("staging")).toBeUndefined();
|
|
9
|
+
});
|
|
10
|
+
it("adds x-environment on bearer auth when pinned", () => {
|
|
11
|
+
const headers = (0, cliodot_request_1.resolveBearerAuthHeaders)({
|
|
12
|
+
appId: "psv_app_1",
|
|
13
|
+
apiKey: "pak_test",
|
|
14
|
+
environment: "prod",
|
|
15
|
+
});
|
|
16
|
+
expect(headers).toMatchObject({
|
|
17
|
+
"x-cliodot-app-id": "psv_app_1",
|
|
18
|
+
Authorization: "Bearer pak_test",
|
|
19
|
+
"x-environment": "prod",
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it("omits x-environment when the client is not pinned", () => {
|
|
23
|
+
const headers = (0, cliodot_request_1.resolveBearerAuthHeaders)({
|
|
24
|
+
appId: "psv_app_1",
|
|
25
|
+
apiKey: "pak_test",
|
|
26
|
+
});
|
|
27
|
+
expect(headers).toMatchObject({
|
|
28
|
+
"x-cliodot-app-id": "psv_app_1",
|
|
29
|
+
Authorization: "Bearer pak_test",
|
|
30
|
+
});
|
|
31
|
+
expect(headers["x-environment"]).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
it("does not add a header for unknown environment values", () => {
|
|
34
|
+
const headers = (0, cliodot_request_1.applyEnvironmentHeader)({}, "staging");
|
|
35
|
+
expect(headers["x-environment"]).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cliodot-result.test.d.ts","sourceRoot":"","sources":["../../../src/http/__tests__/cliodot-result.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cliodot_result_1 = require("../cliodot-result");
|
|
4
|
+
describe("cliodot-result", () => {
|
|
5
|
+
it("cliodotFail builds structured failure", () => {
|
|
6
|
+
const result = (0, cliodot_result_1.cliodotFail)("TEST", "boom", { status: 400 });
|
|
7
|
+
expect(result).toEqual({
|
|
8
|
+
ok: false,
|
|
9
|
+
error: { code: "TEST", message: "boom", status: 400 },
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
it("isCliodotOk / isCliodotFail discriminate", () => {
|
|
13
|
+
expect((0, cliodot_result_1.isCliodotOk)((0, cliodot_result_1.cliodotOk)({ value: 1 }))).toBe(true);
|
|
14
|
+
expect((0, cliodot_result_1.isCliodotFail)((0, cliodot_result_1.cliodotValidationFail)("bad"))).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
it("resolveConfigError returns first invalid check", () => {
|
|
17
|
+
expect((0, cliodot_result_1.resolveConfigError)([
|
|
18
|
+
{ valid: true, message: "ok" },
|
|
19
|
+
{ valid: false, message: "missing baseUrl" },
|
|
20
|
+
])).toEqual({ code: cliodot_result_1.SDK_ERROR.CONFIG, message: "missing baseUrl" });
|
|
21
|
+
});
|
|
22
|
+
it("resolveRequiredString validates non-empty strings", () => {
|
|
23
|
+
expect((0, cliodot_result_1.resolveRequiredString)("", "service")).toEqual({
|
|
24
|
+
ok: false,
|
|
25
|
+
error: { code: cliodot_result_1.SDK_ERROR.VALIDATION, message: "service is required" },
|
|
26
|
+
});
|
|
27
|
+
expect((0, cliodot_result_1.resolveRequiredString)("pay", "service")).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
it("ensureOkTrue wraps bodies without ok", () => {
|
|
30
|
+
expect((0, cliodot_result_1.ensureOkTrue)({ keys: [] })).toEqual({ ok: true, keys: [] });
|
|
31
|
+
expect((0, cliodot_result_1.ensureOkTrue)({ ok: true, keys: [] })).toEqual({ ok: true, keys: [] });
|
|
32
|
+
});
|
|
33
|
+
it("normalizeApiFailure reads nested error objects", () => {
|
|
34
|
+
expect((0, cliodot_result_1.normalizeApiFailure)({ ok: false, error: { code: "X", message: "nope" } }, 502)).toEqual({
|
|
35
|
+
ok: false,
|
|
36
|
+
error: { code: "X", message: "nope", status: 502, details: { ok: false, error: { code: "X", message: "nope" } } },
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it("failureFromCaught maps axios-like errors", () => {
|
|
40
|
+
const err = {
|
|
41
|
+
response: {
|
|
42
|
+
status: 401,
|
|
43
|
+
data: { ok: false, error: { code: "UNAUTHORIZED", message: "bad key" } },
|
|
44
|
+
},
|
|
45
|
+
message: "Request failed with status code 401",
|
|
46
|
+
};
|
|
47
|
+
expect((0, cliodot_result_1.failureFromCaught)(err, "fallback")).toEqual({
|
|
48
|
+
ok: false,
|
|
49
|
+
error: {
|
|
50
|
+
code: "UNAUTHORIZED",
|
|
51
|
+
message: "bad key",
|
|
52
|
+
status: 401,
|
|
53
|
+
details: err.response.data,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events-instance-id.test.d.ts","sourceRoot":"","sources":["../../../src/http/__tests__/events-instance-id.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const crypto_1 = require("crypto");
|
|
4
|
+
const events_instance_id_1 = require("../events-instance-id");
|
|
5
|
+
jest.mock("os", () => ({
|
|
6
|
+
hostname: jest.fn(() => "pc-one"),
|
|
7
|
+
platform: jest.fn(() => "darwin"),
|
|
8
|
+
arch: jest.fn(() => "arm64"),
|
|
9
|
+
userInfo: jest.fn(() => ({ username: "huios" })),
|
|
10
|
+
homedir: jest.fn(() => "/Users/huios"),
|
|
11
|
+
cpus: jest.fn(() => [{ model: "Apple M-series" }]),
|
|
12
|
+
}));
|
|
13
|
+
const os = require("os");
|
|
14
|
+
describe("resolveEventsInstanceId", () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
os.hostname.mockReturnValue("pc-one");
|
|
17
|
+
});
|
|
18
|
+
it("keeps the same id on the same computer", () => {
|
|
19
|
+
const a = (0, events_instance_id_1.resolveEventsInstanceId)({ appId: "evt_app_1" });
|
|
20
|
+
const b = (0, events_instance_id_1.resolveEventsInstanceId)({ appId: "evt_app_1" });
|
|
21
|
+
expect(a).toBe(b);
|
|
22
|
+
expect(a).toHaveLength(64);
|
|
23
|
+
});
|
|
24
|
+
it("changes when the computer hostname changes", () => {
|
|
25
|
+
const first = (0, events_instance_id_1.resolveEventsInstanceId)({ appId: "evt_app_1" });
|
|
26
|
+
os.hostname.mockReturnValue("pc-two");
|
|
27
|
+
const second = (0, events_instance_id_1.resolveEventsInstanceId)({ appId: "evt_app_1" });
|
|
28
|
+
expect(second).not.toBe(first);
|
|
29
|
+
});
|
|
30
|
+
it("accepts a stable override", () => {
|
|
31
|
+
expect((0, events_instance_id_1.resolveEventsInstanceId)({
|
|
32
|
+
appId: "evt_app_1",
|
|
33
|
+
instanceId: "test-instance",
|
|
34
|
+
})).toBe("test-instance");
|
|
35
|
+
});
|
|
36
|
+
it("hashes a short override", () => {
|
|
37
|
+
const hashed = (0, events_instance_id_1.resolveEventsInstanceId)({
|
|
38
|
+
appId: "evt_app_1",
|
|
39
|
+
instanceId: "pc1",
|
|
40
|
+
});
|
|
41
|
+
expect(hashed).toBe((0, crypto_1.createHash)("sha256")
|
|
42
|
+
.update("cliodot-events:evt_app_1:override:pc1")
|
|
43
|
+
.digest("hex"));
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
|
+
import { type CliodotFail, type CliodotMethodResult, type CliodotStructuredError } from "./cliodot-result";
|
|
3
|
+
export type AuthHeadersResult = Record<string, string> | CliodotFail;
|
|
4
|
+
export type SdkEnvironment = "dev" | "prod";
|
|
5
|
+
export declare function normalizeSdkEnvironment(value?: string): SdkEnvironment | undefined;
|
|
6
|
+
export declare function applyEnvironmentHeader(headers: Record<string, string>, environment?: string): Record<string, string>;
|
|
7
|
+
export type ExecuteCliodotRequestOptions<T extends object> = {
|
|
8
|
+
configError?: CliodotStructuredError | null;
|
|
9
|
+
authHeaders: AuthHeadersResult;
|
|
10
|
+
axios: AxiosInstance;
|
|
11
|
+
method: string;
|
|
12
|
+
path: string;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
params?: Record<string, unknown>;
|
|
15
|
+
validateStatus?: (status: number) => boolean;
|
|
16
|
+
transformErrorMessage?: (message: string, code?: string) => string;
|
|
17
|
+
passThrough?: (data: unknown, status: number) => T | CliodotFail | null;
|
|
18
|
+
fallbackMessage?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function executeCliodotRequest<T extends object>(options: ExecuteCliodotRequestOptions<T>): Promise<CliodotMethodResult<T>>;
|
|
21
|
+
export declare function resolveBearerAuthHeaders(input: {
|
|
22
|
+
appId: string;
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
appSecret?: string;
|
|
25
|
+
environment?: string;
|
|
26
|
+
missingMessage?: string;
|
|
27
|
+
}): AuthHeadersResult;
|
|
28
|
+
export declare function resolveS2SAuthHeaders(input: {
|
|
29
|
+
appId: string;
|
|
30
|
+
appApiKey?: string;
|
|
31
|
+
appSecret?: string;
|
|
32
|
+
missingMessage?: string;
|
|
33
|
+
}): AuthHeadersResult;
|
|
34
|
+
export declare function parseFailureFromBody(data: unknown, status?: number): CliodotFail;
|
|
35
|
+
//# sourceMappingURL=cliodot-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cliodot-request.d.ts","sourceRoot":"","sources":["../../src/http/cliodot-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAE5B,MAAM,kBAAkB,CAAC;AAG1B,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC;AAErE,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,CAAC;AAE5C,wBAAgB,uBAAuB,CACrC,KAAK,CAAC,EAAE,MAAM,GACb,cAAc,GAAG,SAAS,CAM5B;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMxB;AAED,MAAM,MAAM,4BAA4B,CAAC,CAAC,SAAS,MAAM,IAAI;IAC3D,WAAW,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC5C,WAAW,EAAE,iBAAiB,CAAC;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7C,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACnE,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC,GAAG,WAAW,GAAG,IAAI,CAAC;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAcF,wBAAsB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EAC1D,OAAO,EAAE,4BAA4B,CAAC,CAAC,CAAC,GACvC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAwCjC;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,iBAAiB,CAkBpB;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,iBAAiB,CAcpB;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,CAIhF"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeSdkEnvironment = normalizeSdkEnvironment;
|
|
4
|
+
exports.applyEnvironmentHeader = applyEnvironmentHeader;
|
|
5
|
+
exports.executeCliodotRequest = executeCliodotRequest;
|
|
6
|
+
exports.resolveBearerAuthHeaders = resolveBearerAuthHeaders;
|
|
7
|
+
exports.resolveS2SAuthHeaders = resolveS2SAuthHeaders;
|
|
8
|
+
exports.parseFailureFromBody = parseFailureFromBody;
|
|
9
|
+
const cliodot_result_1 = require("./cliodot-result");
|
|
10
|
+
const parse_api_error_1 = require("./parse-api-error");
|
|
11
|
+
function normalizeSdkEnvironment(value) {
|
|
12
|
+
if (!value)
|
|
13
|
+
return undefined;
|
|
14
|
+
const normalized = value.trim().toLowerCase();
|
|
15
|
+
if (normalized === "dev" || normalized === "development")
|
|
16
|
+
return "dev";
|
|
17
|
+
if (normalized === "prod" || normalized === "production")
|
|
18
|
+
return "prod";
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
function applyEnvironmentHeader(headers, environment) {
|
|
22
|
+
const normalized = normalizeSdkEnvironment(environment);
|
|
23
|
+
if (normalized) {
|
|
24
|
+
headers["x-environment"] = normalized;
|
|
25
|
+
}
|
|
26
|
+
return headers;
|
|
27
|
+
}
|
|
28
|
+
function cleanParams(params) {
|
|
29
|
+
if (!params)
|
|
30
|
+
return undefined;
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const [key, value] of Object.entries(params)) {
|
|
33
|
+
if (value === undefined || value === null)
|
|
34
|
+
continue;
|
|
35
|
+
out[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return Object.keys(out).length ? out : undefined;
|
|
38
|
+
}
|
|
39
|
+
async function executeCliodotRequest(options) {
|
|
40
|
+
if (options.configError) {
|
|
41
|
+
return (0, cliodot_result_1.cliodotFail)(options.configError.code, options.configError.message);
|
|
42
|
+
}
|
|
43
|
+
if ((0, cliodot_result_1.isCliodotFail)(options.authHeaders)) {
|
|
44
|
+
return options.authHeaders;
|
|
45
|
+
}
|
|
46
|
+
const fallbackMessage = options.fallbackMessage || `Request failed: ${options.method} ${options.path}`;
|
|
47
|
+
try {
|
|
48
|
+
const response = await options.axios({
|
|
49
|
+
method: options.method,
|
|
50
|
+
url: options.path,
|
|
51
|
+
headers: options.authHeaders,
|
|
52
|
+
data: options.body,
|
|
53
|
+
params: cleanParams(options.params),
|
|
54
|
+
...(options.validateStatus ? { validateStatus: options.validateStatus } : {}),
|
|
55
|
+
});
|
|
56
|
+
const data = response.data;
|
|
57
|
+
const status = response.status;
|
|
58
|
+
if (options.passThrough) {
|
|
59
|
+
const passed = options.passThrough(data, status);
|
|
60
|
+
if (passed !== null) {
|
|
61
|
+
return passed;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (status >= 400 || (data && typeof data === "object" && data.ok === false)) {
|
|
65
|
+
return (0, cliodot_result_1.normalizeApiFailure)(data, status, options.transformErrorMessage);
|
|
66
|
+
}
|
|
67
|
+
return (0, cliodot_result_1.ensureOkTrue)(data);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
return (0, cliodot_result_1.failureFromCaught)(err, fallbackMessage, options.transformErrorMessage);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function resolveBearerAuthHeaders(input) {
|
|
74
|
+
const headers = {
|
|
75
|
+
"x-cliodot-app-id": input.appId,
|
|
76
|
+
};
|
|
77
|
+
applyEnvironmentHeader(headers, input.environment);
|
|
78
|
+
if (input.apiKey) {
|
|
79
|
+
headers.Authorization = `Bearer ${input.apiKey}`;
|
|
80
|
+
return headers;
|
|
81
|
+
}
|
|
82
|
+
if (input.appSecret) {
|
|
83
|
+
headers.Authorization = `Bearer ${input.appSecret}`;
|
|
84
|
+
headers["x-cliodot-app-secret"] = input.appSecret;
|
|
85
|
+
return headers;
|
|
86
|
+
}
|
|
87
|
+
return (0, cliodot_result_1.cliodotFail)(cliodot_result_1.SDK_ERROR.AUTH, input.missingMessage || "App credentials required (apiKey/appApiKey or appSecret)");
|
|
88
|
+
}
|
|
89
|
+
function resolveS2SAuthHeaders(input) {
|
|
90
|
+
if (input.appApiKey) {
|
|
91
|
+
return { Authorization: `Bearer ${input.appApiKey}` };
|
|
92
|
+
}
|
|
93
|
+
if (input.appSecret) {
|
|
94
|
+
return {
|
|
95
|
+
"X-Cliodot-App-Id": input.appId,
|
|
96
|
+
"X-Cliodot-App-Secret": input.appSecret,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return (0, cliodot_result_1.cliodotFail)(cliodot_result_1.SDK_ERROR.AUTH, input.missingMessage || "App credentials required (appApiKey or appSecret)");
|
|
100
|
+
}
|
|
101
|
+
function parseFailureFromBody(data, status) {
|
|
102
|
+
const code = (0, parse_api_error_1.parseApiErrorCode)(data) || (status ? `HTTP_${status}` : cliodot_result_1.SDK_ERROR.REQUEST_FAILED);
|
|
103
|
+
const message = (0, parse_api_error_1.parseApiErrorMessage)(data) || "Request failed";
|
|
104
|
+
return (0, cliodot_result_1.cliodotFail)(code, message, { status, details: data });
|
|
105
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type CliodotStructuredError = {
|
|
2
|
+
code: string;
|
|
3
|
+
message: string;
|
|
4
|
+
status?: number;
|
|
5
|
+
details?: unknown;
|
|
6
|
+
};
|
|
7
|
+
export type CliodotFail = {
|
|
8
|
+
ok: false;
|
|
9
|
+
error: CliodotStructuredError;
|
|
10
|
+
};
|
|
11
|
+
export type CliodotOk<T extends object = Record<string, never>> = {
|
|
12
|
+
ok: true;
|
|
13
|
+
} & T;
|
|
14
|
+
export type CliodotMethodResult<T extends object = Record<string, never>> = CliodotOk<T> | CliodotFail;
|
|
15
|
+
export declare const SDK_ERROR: {
|
|
16
|
+
readonly CONFIG: "SDK_CONFIG_INVALID";
|
|
17
|
+
readonly VALIDATION: "SDK_VALIDATION";
|
|
18
|
+
readonly AUTH: "SDK_AUTH_MISSING";
|
|
19
|
+
readonly NETWORK: "NETWORK_ERROR";
|
|
20
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
21
|
+
readonly REQUEST_FAILED: "REQUEST_FAILED";
|
|
22
|
+
};
|
|
23
|
+
export declare function cliodotFail(code: string, message: string, extras?: {
|
|
24
|
+
status?: number;
|
|
25
|
+
details?: unknown;
|
|
26
|
+
}): CliodotFail;
|
|
27
|
+
export declare function cliodotValidationFail(message: string): CliodotFail;
|
|
28
|
+
export declare function cliodotOk<T extends object>(data: T): CliodotOk<T>;
|
|
29
|
+
export declare function isCliodotFail(value: unknown): value is CliodotFail;
|
|
30
|
+
export declare function isCliodotOk<T extends object>(value: CliodotMethodResult<T> | unknown): value is CliodotOk<T>;
|
|
31
|
+
export declare function resolveConfigError(checks: Array<{
|
|
32
|
+
valid: boolean;
|
|
33
|
+
message: string;
|
|
34
|
+
code?: string;
|
|
35
|
+
}>): CliodotStructuredError | null;
|
|
36
|
+
export declare function resolveRequiredString(value: unknown, label: string): CliodotFail | null;
|
|
37
|
+
export declare function ensureOkTrue<T extends object>(data: unknown): CliodotMethodResult<T>;
|
|
38
|
+
export declare function normalizeApiFailure(data: unknown, status?: number, transformMessage?: (message: string, code?: string) => string): CliodotFail;
|
|
39
|
+
export declare function failureFromCaught(err: unknown, fallbackMessage: string, transformMessage?: (message: string, code?: string) => string): CliodotFail;
|
|
40
|
+
//# sourceMappingURL=cliodot-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cliodot-result.d.ts","sourceRoot":"","sources":["../../src/http/cliodot-result.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,sBAAsB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI;IAChE,EAAE,EAAE,IAAI,CAAC;CACV,GAAG,CAAC,CAAC;AAEN,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IACpE,SAAS,CAAC,CAAC,CAAC,GACZ,WAAW,CAAC;AAEhB,eAAO,MAAM,SAAS;;;;;;;CAOZ,CAAC;AAEX,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC9C,WAAW,CAUb;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAElE;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEjE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CASlE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,OAAO,GACtC,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,CAEvB;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAChE,sBAAsB,GAAG,IAAI,CAO/B;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACZ,WAAW,GAAG,IAAI,CAKpB;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC3C,IAAI,EAAE,OAAO,GACZ,mBAAmB,CAAC,CAAC,CAAC,CAYxB;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,EACb,MAAM,CAAC,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,GAC5D,WAAW,CAYb;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,OAAO,EACZ,eAAe,EAAE,MAAM,EACvB,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,GAC5D,WAAW,CAgEb"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDK_ERROR = void 0;
|
|
4
|
+
exports.cliodotFail = cliodotFail;
|
|
5
|
+
exports.cliodotValidationFail = cliodotValidationFail;
|
|
6
|
+
exports.cliodotOk = cliodotOk;
|
|
7
|
+
exports.isCliodotFail = isCliodotFail;
|
|
8
|
+
exports.isCliodotOk = isCliodotOk;
|
|
9
|
+
exports.resolveConfigError = resolveConfigError;
|
|
10
|
+
exports.resolveRequiredString = resolveRequiredString;
|
|
11
|
+
exports.ensureOkTrue = ensureOkTrue;
|
|
12
|
+
exports.normalizeApiFailure = normalizeApiFailure;
|
|
13
|
+
exports.failureFromCaught = failureFromCaught;
|
|
14
|
+
const parse_api_error_1 = require("./parse-api-error");
|
|
15
|
+
exports.SDK_ERROR = {
|
|
16
|
+
CONFIG: "SDK_CONFIG_INVALID",
|
|
17
|
+
VALIDATION: "SDK_VALIDATION",
|
|
18
|
+
AUTH: "SDK_AUTH_MISSING",
|
|
19
|
+
NETWORK: "NETWORK_ERROR",
|
|
20
|
+
UNKNOWN: "UNKNOWN",
|
|
21
|
+
REQUEST_FAILED: "REQUEST_FAILED",
|
|
22
|
+
};
|
|
23
|
+
function cliodotFail(code, message, extras) {
|
|
24
|
+
return {
|
|
25
|
+
ok: false,
|
|
26
|
+
error: {
|
|
27
|
+
code,
|
|
28
|
+
message,
|
|
29
|
+
...(extras?.status !== undefined ? { status: extras.status } : {}),
|
|
30
|
+
...(extras?.details !== undefined ? { details: extras.details } : {}),
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function cliodotValidationFail(message) {
|
|
35
|
+
return cliodotFail(exports.SDK_ERROR.VALIDATION, message);
|
|
36
|
+
}
|
|
37
|
+
function cliodotOk(data) {
|
|
38
|
+
return { ok: true, ...data };
|
|
39
|
+
}
|
|
40
|
+
function isCliodotFail(value) {
|
|
41
|
+
return (!!value &&
|
|
42
|
+
typeof value === "object" &&
|
|
43
|
+
value.ok === false &&
|
|
44
|
+
!!value.error &&
|
|
45
|
+
typeof value.error.code === "string" &&
|
|
46
|
+
typeof value.error.message === "string");
|
|
47
|
+
}
|
|
48
|
+
function isCliodotOk(value) {
|
|
49
|
+
return !!value && typeof value === "object" && value.ok === true;
|
|
50
|
+
}
|
|
51
|
+
function resolveConfigError(checks) {
|
|
52
|
+
const failed = checks.find((check) => !check.valid);
|
|
53
|
+
if (!failed)
|
|
54
|
+
return null;
|
|
55
|
+
return {
|
|
56
|
+
code: failed.code || exports.SDK_ERROR.CONFIG,
|
|
57
|
+
message: failed.message,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function resolveRequiredString(value, label) {
|
|
61
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
62
|
+
return cliodotValidationFail(`${label} is required`);
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
function ensureOkTrue(data) {
|
|
67
|
+
if (!data || typeof data !== "object") {
|
|
68
|
+
return cliodotFail(exports.SDK_ERROR.UNKNOWN, "Invalid response body");
|
|
69
|
+
}
|
|
70
|
+
const body = data;
|
|
71
|
+
if (body.ok === false) {
|
|
72
|
+
return normalizeApiFailure(body);
|
|
73
|
+
}
|
|
74
|
+
if (body.ok === true) {
|
|
75
|
+
return body;
|
|
76
|
+
}
|
|
77
|
+
return cliodotOk(body);
|
|
78
|
+
}
|
|
79
|
+
function normalizeApiFailure(data, status, transformMessage) {
|
|
80
|
+
let code = (0, parse_api_error_1.parseApiErrorCode)(data) || (status ? `HTTP_${status}` : exports.SDK_ERROR.REQUEST_FAILED);
|
|
81
|
+
let message = (0, parse_api_error_1.parseApiErrorMessage)(data) || "Request failed";
|
|
82
|
+
if (transformMessage) {
|
|
83
|
+
message = transformMessage(message, code);
|
|
84
|
+
}
|
|
85
|
+
return cliodotFail(code, message, {
|
|
86
|
+
status,
|
|
87
|
+
details: data,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function failureFromCaught(err, fallbackMessage, transformMessage) {
|
|
91
|
+
if (isCliodotFail(err)) {
|
|
92
|
+
return err;
|
|
93
|
+
}
|
|
94
|
+
const axiosResponse = err &&
|
|
95
|
+
typeof err === "object" &&
|
|
96
|
+
"response" in err
|
|
97
|
+
? err.response
|
|
98
|
+
: undefined;
|
|
99
|
+
if (axiosResponse) {
|
|
100
|
+
const status = axiosResponse.status;
|
|
101
|
+
const data = axiosResponse.data;
|
|
102
|
+
if (data && typeof data === "object" && data.ok === false) {
|
|
103
|
+
return normalizeApiFailure(data, status, transformMessage);
|
|
104
|
+
}
|
|
105
|
+
let message = fallbackMessage;
|
|
106
|
+
if (data && typeof data === "object") {
|
|
107
|
+
const rawMessage = data.message;
|
|
108
|
+
if (typeof rawMessage === "string" && rawMessage.trim()) {
|
|
109
|
+
message = rawMessage.trim();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (typeof err.message === "string" &&
|
|
113
|
+
String(err.message).trim()) {
|
|
114
|
+
message = String(err.message).trim();
|
|
115
|
+
}
|
|
116
|
+
const code = (0, parse_api_error_1.parseApiErrorCode)(data) || (status ? `HTTP_${status}` : exports.SDK_ERROR.NETWORK);
|
|
117
|
+
const finalMessage = transformMessage ? transformMessage(message, code) : message;
|
|
118
|
+
return cliodotFail(code, finalMessage, { status, details: data ?? err });
|
|
119
|
+
}
|
|
120
|
+
if (err && typeof err === "object" && "code" in err && "message" in err) {
|
|
121
|
+
const structured = err;
|
|
122
|
+
const message = transformMessage
|
|
123
|
+
? transformMessage(structured.message, structured.code)
|
|
124
|
+
: structured.message;
|
|
125
|
+
return cliodotFail(structured.code, message, {
|
|
126
|
+
status: structured.status,
|
|
127
|
+
details: structured.details,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const message = (err instanceof Error && err.message.trim()) ||
|
|
131
|
+
(typeof err === "string" && err.trim()) ||
|
|
132
|
+
fallbackMessage;
|
|
133
|
+
const finalMessage = transformMessage ? transformMessage(message) : message;
|
|
134
|
+
const isNetwork = err &&
|
|
135
|
+
typeof err === "object" &&
|
|
136
|
+
("code" in err || "errno" in err) &&
|
|
137
|
+
!axiosResponse;
|
|
138
|
+
return cliodotFail(isNetwork ? exports.SDK_ERROR.NETWORK : exports.SDK_ERROR.UNKNOWN, finalMessage, { details: err });
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-client.d.ts","sourceRoot":"","sources":["../../src/http/create-client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAGlE,wBAAgB,kBAAkB,CAChC,MAAM,GAAE,mBAAwB,GAC/B,aAAa,CAKf"}
|