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,197 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IdentityAppClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
const parse_api_error_1 = require("./http/parse-api-error");
|
|
10
|
+
const cliodot_request_1 = require("./http/cliodot-request");
|
|
11
|
+
function trimBaseUrl(url) {
|
|
12
|
+
return url.trim().replace(/\/+$/, "");
|
|
13
|
+
}
|
|
14
|
+
function resolveInternalProviderId(name) {
|
|
15
|
+
const trimmed = name.trim();
|
|
16
|
+
if (!trimmed) {
|
|
17
|
+
throw new errors_1.CliodotApiError("provider requires a non-empty Identity App id");
|
|
18
|
+
}
|
|
19
|
+
if (trimmed.startsWith("ext:") || trimmed.startsWith("ext_")) {
|
|
20
|
+
throw new errors_1.CliodotApiError("provider() resolves internal Identity Apps only; use extProvider() for external profiles");
|
|
21
|
+
}
|
|
22
|
+
return trimmed;
|
|
23
|
+
}
|
|
24
|
+
function resolveExternalProviderId(name) {
|
|
25
|
+
const trimmed = name.trim();
|
|
26
|
+
if (!trimmed) {
|
|
27
|
+
throw new errors_1.CliodotApiError("extProvider requires a non-empty profile slug or id");
|
|
28
|
+
}
|
|
29
|
+
if (trimmed.startsWith("ext:") || trimmed.startsWith("ext_")) {
|
|
30
|
+
return trimmed;
|
|
31
|
+
}
|
|
32
|
+
return `ext:${trimmed}`;
|
|
33
|
+
}
|
|
34
|
+
class IdentityAppClient {
|
|
35
|
+
constructor(config) {
|
|
36
|
+
if (!config.baseUrl?.trim()) {
|
|
37
|
+
throw new errors_1.CliodotApiError("IdentityAppClient requires baseUrl");
|
|
38
|
+
}
|
|
39
|
+
if (!config.appId?.trim()) {
|
|
40
|
+
throw new errors_1.CliodotApiError("IdentityAppClient requires appId");
|
|
41
|
+
}
|
|
42
|
+
this.baseUrl = trimBaseUrl(config.baseUrl);
|
|
43
|
+
this.appId = config.appId.trim();
|
|
44
|
+
this.apiKey =
|
|
45
|
+
config.apiKey?.trim() || config.appApiKey?.trim() || undefined;
|
|
46
|
+
this.appSecret = config.appSecret?.trim() || undefined;
|
|
47
|
+
this.environment = config.environment;
|
|
48
|
+
this.debug = config.debug ?? false;
|
|
49
|
+
this.axios = axios_1.default.create({
|
|
50
|
+
baseURL: `${this.baseUrl}/identity`,
|
|
51
|
+
timeout: config.timeoutMs ?? 30000,
|
|
52
|
+
headers: { "Content-Type": "application/json" },
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
me() {
|
|
56
|
+
return this.request("GET", "/v1/me");
|
|
57
|
+
}
|
|
58
|
+
authenticate(input) {
|
|
59
|
+
if (!input?.target_app_id?.trim()) {
|
|
60
|
+
throw new errors_1.CliodotApiError("authenticate requires target_app_id");
|
|
61
|
+
}
|
|
62
|
+
const body = {
|
|
63
|
+
target_app_id: input.target_app_id.trim(),
|
|
64
|
+
};
|
|
65
|
+
if (input.scopes !== undefined) {
|
|
66
|
+
body.scopes = input.scopes;
|
|
67
|
+
}
|
|
68
|
+
return this.request("POST", "/v1/authenticate", body);
|
|
69
|
+
}
|
|
70
|
+
verify(input) {
|
|
71
|
+
if (!input?.access_token?.trim()) {
|
|
72
|
+
throw new errors_1.CliodotApiError("verify requires access_token");
|
|
73
|
+
}
|
|
74
|
+
const body = {
|
|
75
|
+
access_token: input.access_token.trim(),
|
|
76
|
+
};
|
|
77
|
+
if (input.required_scopes !== undefined) {
|
|
78
|
+
body.required_scopes = input.required_scopes;
|
|
79
|
+
}
|
|
80
|
+
const target = input.target_app_id?.trim();
|
|
81
|
+
if (target) {
|
|
82
|
+
return this.request("POST", `/v1/apps/${encodeURIComponent(target)}/verify`, body);
|
|
83
|
+
}
|
|
84
|
+
return this.request("POST", "/v1/verify", body);
|
|
85
|
+
}
|
|
86
|
+
refresh(input) {
|
|
87
|
+
if (!input?.refresh_token?.trim()) {
|
|
88
|
+
throw new errors_1.CliodotApiError("refresh requires refresh_token");
|
|
89
|
+
}
|
|
90
|
+
return this.request("POST", "/v1/token/refresh", {
|
|
91
|
+
refresh_token: input.refresh_token.trim(),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
revoke(input) {
|
|
95
|
+
const access = input?.access_token?.trim();
|
|
96
|
+
const refresh = input?.refresh_token?.trim();
|
|
97
|
+
if (!access && !refresh) {
|
|
98
|
+
throw new errors_1.CliodotApiError("revoke requires access_token or refresh_token");
|
|
99
|
+
}
|
|
100
|
+
const body = {};
|
|
101
|
+
if (access)
|
|
102
|
+
body.access_token = access;
|
|
103
|
+
if (refresh)
|
|
104
|
+
body.refresh_token = refresh;
|
|
105
|
+
return this.request("POST", "/v1/token/revoke", body);
|
|
106
|
+
}
|
|
107
|
+
async getJwks(appId) {
|
|
108
|
+
if (!appId?.trim()) {
|
|
109
|
+
throw new errors_1.CliodotApiError("getJwks requires appId");
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const { data } = await this.axios({
|
|
113
|
+
method: "GET",
|
|
114
|
+
url: `/v1/apps/${encodeURIComponent(appId.trim())}/jwks.json`,
|
|
115
|
+
});
|
|
116
|
+
if (data?.ok === false) {
|
|
117
|
+
throw new errors_1.CliodotApiError((0, parse_api_error_1.parseApiErrorMessage)(data) || "JWKS request failed", {
|
|
118
|
+
data,
|
|
119
|
+
code: (0, parse_api_error_1.parseApiErrorCode)(data),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return data;
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
if (err instanceof errors_1.CliodotApiError)
|
|
126
|
+
throw err;
|
|
127
|
+
throw (0, errors_1.cliodotApiErrorFromAxios)(err, `Request failed: GET jwks`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
provider(name) {
|
|
131
|
+
const target_app_id = resolveInternalProviderId(name);
|
|
132
|
+
return this.buildProviderHandle(target_app_id);
|
|
133
|
+
}
|
|
134
|
+
extProvider(name) {
|
|
135
|
+
const target_app_id = resolveExternalProviderId(name);
|
|
136
|
+
return this.buildProviderHandle(target_app_id);
|
|
137
|
+
}
|
|
138
|
+
buildProviderHandle(target_app_id) {
|
|
139
|
+
return {
|
|
140
|
+
target_app_id,
|
|
141
|
+
authenticate: (scopes) => {
|
|
142
|
+
const input = { target_app_id };
|
|
143
|
+
if (scopes !== undefined)
|
|
144
|
+
input.scopes = scopes;
|
|
145
|
+
return this.authenticate(input);
|
|
146
|
+
},
|
|
147
|
+
verify: (accessToken, required_scopes) => {
|
|
148
|
+
const input = {
|
|
149
|
+
access_token: accessToken,
|
|
150
|
+
target_app_id,
|
|
151
|
+
};
|
|
152
|
+
if (required_scopes !== undefined) {
|
|
153
|
+
input.required_scopes = required_scopes;
|
|
154
|
+
}
|
|
155
|
+
return this.verify(input);
|
|
156
|
+
},
|
|
157
|
+
refresh: (refreshToken) => this.refresh({ refresh_token: refreshToken }),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
buildAuthHeaders() {
|
|
161
|
+
const headers = (0, cliodot_request_1.applyEnvironmentHeader)({
|
|
162
|
+
"x-cliodot-app-id": this.appId,
|
|
163
|
+
}, this.environment);
|
|
164
|
+
if (this.apiKey) {
|
|
165
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
166
|
+
return headers;
|
|
167
|
+
}
|
|
168
|
+
if (this.appSecret) {
|
|
169
|
+
headers["x-cliodot-app-secret"] = this.appSecret;
|
|
170
|
+
return headers;
|
|
171
|
+
}
|
|
172
|
+
throw new errors_1.CliodotApiError("Identity app credentials required (apiKey/appApiKey or appSecret)");
|
|
173
|
+
}
|
|
174
|
+
async request(method, path, body) {
|
|
175
|
+
try {
|
|
176
|
+
const { data } = await this.axios({
|
|
177
|
+
method,
|
|
178
|
+
url: path,
|
|
179
|
+
headers: this.buildAuthHeaders(),
|
|
180
|
+
data: body,
|
|
181
|
+
});
|
|
182
|
+
if (data?.ok === false) {
|
|
183
|
+
throw new errors_1.CliodotApiError((0, parse_api_error_1.parseApiErrorMessage)(data) || "Identity request failed", {
|
|
184
|
+
data,
|
|
185
|
+
code: (0, parse_api_error_1.parseApiErrorCode)(data),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return data;
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
if (err instanceof errors_1.CliodotApiError)
|
|
192
|
+
throw err;
|
|
193
|
+
throw (0, errors_1.cliodotApiErrorFromAxios)(err, `Request failed: ${method} ${path}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.IdentityAppClient = IdentityAppClient;
|
|
@@ -4,6 +4,7 @@ export declare class MemoryAppClient implements MemoryAppClientApi {
|
|
|
4
4
|
private readonly appId;
|
|
5
5
|
private readonly apiKey?;
|
|
6
6
|
private readonly appSecret?;
|
|
7
|
+
private readonly environment?;
|
|
7
8
|
private readonly axios;
|
|
8
9
|
readonly debug: boolean;
|
|
9
10
|
constructor(config: MemoryAppClientConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryAppClient.d.ts","sourceRoot":"","sources":["../src/MemoryAppClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MemoryAppClient.d.ts","sourceRoot":"","sources":["../src/MemoryAppClient.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAMhC,qBAAa,eAAgB,YAAW,kBAAkB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,SAAgB,KAAK,EAAE,OAAO,CAAC;gBAEnB,MAAM,EAAE,qBAAqB;IAqBzC,KAAK,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAa5D,SAAS,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAaxE,GAAG,CACD,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,MAAM,EAAE,YAAY,CAAA;KAAE,CAAC;IAU9C,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAiB9D,MAAM,CACJ,KAAK,EAAE,iBAAiB,GACvB,OAAO,CAAC;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;KAAE,CAAC;IAWtE,IAAI,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAezD,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAI/D,OAAO,CAAC,gBAAgB;YAoBV,OAAO;CAgCtB"}
|
package/dist/MemoryAppClient.js
CHANGED
|
@@ -1 +1,149 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MemoryAppClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
const parse_api_error_1 = require("./http/parse-api-error");
|
|
10
|
+
const cliodot_request_1 = require("./http/cliodot-request");
|
|
11
|
+
function trimBaseUrl(url) {
|
|
12
|
+
return url.trim().replace(/\/+$/, "");
|
|
13
|
+
}
|
|
14
|
+
class MemoryAppClient {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
if (!config.baseUrl?.trim()) {
|
|
17
|
+
throw new errors_1.CliodotApiError("MemoryAppClient requires baseUrl");
|
|
18
|
+
}
|
|
19
|
+
if (!config.appId?.trim()) {
|
|
20
|
+
throw new errors_1.CliodotApiError("MemoryAppClient requires appId");
|
|
21
|
+
}
|
|
22
|
+
this.baseUrl = trimBaseUrl(config.baseUrl);
|
|
23
|
+
this.appId = config.appId.trim();
|
|
24
|
+
this.apiKey =
|
|
25
|
+
config.apiKey?.trim() || config.appApiKey?.trim() || undefined;
|
|
26
|
+
this.appSecret = config.appSecret?.trim() || undefined;
|
|
27
|
+
this.environment = config.environment;
|
|
28
|
+
this.debug = config.debug ?? false;
|
|
29
|
+
this.axios = axios_1.default.create({
|
|
30
|
+
baseURL: `${this.baseUrl}/memory`,
|
|
31
|
+
timeout: 60000,
|
|
32
|
+
headers: { "Content-Type": "application/json" },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
store(input) {
|
|
36
|
+
if (!input?.collection?.trim()) {
|
|
37
|
+
throw new errors_1.CliodotApiError("collection is required");
|
|
38
|
+
}
|
|
39
|
+
if (input.content === undefined) {
|
|
40
|
+
throw new errors_1.CliodotApiError("content is required");
|
|
41
|
+
}
|
|
42
|
+
return this.request("POST", "/v1/store", {
|
|
43
|
+
...input,
|
|
44
|
+
collection: input.collection.trim(),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
storeMany(input) {
|
|
48
|
+
if (!input?.collection?.trim()) {
|
|
49
|
+
throw new errors_1.CliodotApiError("collection is required");
|
|
50
|
+
}
|
|
51
|
+
if (!Array.isArray(input.items) || input.items.length === 0) {
|
|
52
|
+
throw new errors_1.CliodotApiError("items is required");
|
|
53
|
+
}
|
|
54
|
+
return this.request("POST", "/v1/store-many", {
|
|
55
|
+
collection: input.collection.trim(),
|
|
56
|
+
items: input.items,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
get(input) {
|
|
60
|
+
if (!input?.collection?.trim() || !input?.id?.trim()) {
|
|
61
|
+
throw new errors_1.CliodotApiError("collection and id are required");
|
|
62
|
+
}
|
|
63
|
+
return this.request("POST", "/v1/get", {
|
|
64
|
+
collection: input.collection.trim(),
|
|
65
|
+
id: input.id.trim(),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
update(input) {
|
|
69
|
+
if (!input?.collection?.trim() || !input?.id?.trim()) {
|
|
70
|
+
throw new errors_1.CliodotApiError("collection and id are required");
|
|
71
|
+
}
|
|
72
|
+
return this.request("POST", "/v1/update", {
|
|
73
|
+
collection: input.collection.trim(),
|
|
74
|
+
id: input.id.trim(),
|
|
75
|
+
content: input.content,
|
|
76
|
+
type: input.type,
|
|
77
|
+
title: input.title,
|
|
78
|
+
metadata: input.metadata,
|
|
79
|
+
tags: input.tags,
|
|
80
|
+
source: input.source,
|
|
81
|
+
async: input.async,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
delete(input) {
|
|
85
|
+
if (!input?.collection?.trim() || !input?.id?.trim()) {
|
|
86
|
+
throw new errors_1.CliodotApiError("collection and id are required");
|
|
87
|
+
}
|
|
88
|
+
return this.request("POST", "/v1/delete", {
|
|
89
|
+
collection: input.collection.trim(),
|
|
90
|
+
id: input.id.trim(),
|
|
91
|
+
mode: input.mode || "soft",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
find(input) {
|
|
95
|
+
if (!input?.collection?.trim()) {
|
|
96
|
+
throw new errors_1.CliodotApiError("collection is required");
|
|
97
|
+
}
|
|
98
|
+
return this.request("POST", "/v1/find", {
|
|
99
|
+
collection: input.collection.trim(),
|
|
100
|
+
filter: input.filter,
|
|
101
|
+
type: input.type,
|
|
102
|
+
tags: input.tags,
|
|
103
|
+
metadata: input.metadata,
|
|
104
|
+
limit: input.limit,
|
|
105
|
+
offset: input.offset,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
search(input) {
|
|
109
|
+
return this.request("POST", "/v1/search", input);
|
|
110
|
+
}
|
|
111
|
+
buildAuthHeaders() {
|
|
112
|
+
const headers = (0, cliodot_request_1.applyEnvironmentHeader)({
|
|
113
|
+
"x-cliodot-app-id": this.appId,
|
|
114
|
+
}, this.environment);
|
|
115
|
+
if (this.apiKey) {
|
|
116
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
117
|
+
return headers;
|
|
118
|
+
}
|
|
119
|
+
if (this.appSecret) {
|
|
120
|
+
headers["x-cliodot-app-secret"] = this.appSecret;
|
|
121
|
+
return headers;
|
|
122
|
+
}
|
|
123
|
+
throw new errors_1.CliodotApiError("MemoryAppClient credentials required (apiKey/appApiKey or appSecret)");
|
|
124
|
+
}
|
|
125
|
+
async request(method, path, body) {
|
|
126
|
+
try {
|
|
127
|
+
const { data } = await this.axios({
|
|
128
|
+
method,
|
|
129
|
+
url: path,
|
|
130
|
+
headers: this.buildAuthHeaders(),
|
|
131
|
+
data: body,
|
|
132
|
+
});
|
|
133
|
+
if (data?.ok === false) {
|
|
134
|
+
throw new errors_1.CliodotApiError((0, parse_api_error_1.parseApiErrorMessage)(data) || "Memory request failed", {
|
|
135
|
+
data,
|
|
136
|
+
code: (0, parse_api_error_1.parseApiErrorCode)(data),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return data;
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
if (err instanceof errors_1.CliodotApiError) {
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
throw (0, errors_1.cliodotApiErrorFromAxios)(err, `Request failed: ${method} ${path}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.MemoryAppClient = MemoryAppClient;
|
package/dist/MemoryClient.js
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryClient = void 0;
|
|
4
|
+
const MemoryAppClient_1 = require("./MemoryAppClient");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
class MemoryClient extends MemoryAppClient_1.MemoryAppClient {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super(config);
|
|
9
|
+
}
|
|
10
|
+
search(input) {
|
|
11
|
+
return super.search(input);
|
|
12
|
+
}
|
|
13
|
+
searchCross(input) {
|
|
14
|
+
if (!input?.apps?.length && !input?.group?.trim()) {
|
|
15
|
+
throw new errors_1.CliodotApiError("apps[] or group is required");
|
|
16
|
+
}
|
|
17
|
+
return this.search(input);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.MemoryClient = MemoryClient;
|
package/dist/OAuthAppClient.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OAuthAppClient.d.ts","sourceRoot":"","sources":["../src/OAuthAppClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OAuthAppClient.d.ts","sourceRoot":"","sources":["../src/OAuthAppClient.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EAOf,mBAAmB,EAEnB,kBAAkB,EAClB,qBAAqB,EAKtB,MAAM,uBAAuB,CAAC;AAwF/B,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,SAAgB,KAAK,EAAE,OAAO,CAAC;gBAEnB,MAAM,EAAE,oBAAoB;IAoBxC,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,eAAe;YAmBT,OAAO;IA+CrB,QAAQ,CAAC,OAAO,EAAE,eAAe,CAqE/B;IAEI,QAAQ,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAUzE,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAoDvC;CACH"}
|