@kadoa/node-sdk 0.13.0 → 0.14.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/dist/browser/index.global.js +13 -13
- package/dist/browser/index.global.js.map +1 -1
- package/dist/index.d.mts +935 -835
- package/dist/index.d.ts +935 -835
- package/dist/index.js +1254 -1514
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1238 -1513
- package/dist/index.mjs.map +1 -1
- package/package.json +68 -65
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import globalAxios5, { isAxiosError, AxiosError } from 'axios';
|
|
2
|
-
import { v4 } from 'uuid';
|
|
3
|
-
import { URL, URLSearchParams } from 'url';
|
|
4
2
|
import createDebug from 'debug';
|
|
5
3
|
import { upperFirst, camelCase, merge } from 'es-toolkit';
|
|
6
|
-
import {
|
|
4
|
+
import { URL, URLSearchParams } from 'url';
|
|
7
5
|
import assert from 'assert';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { v4 } from 'uuid';
|
|
8
8
|
|
|
9
9
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
10
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -13,7 +13,120 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
13
13
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
// src/
|
|
16
|
+
// src/domains/extraction/extraction.acl.ts
|
|
17
|
+
var FetchDataOptions = class {
|
|
18
|
+
};
|
|
19
|
+
var SchemaFieldDataType = {
|
|
20
|
+
Text: "TEXT",
|
|
21
|
+
Number: "NUMBER",
|
|
22
|
+
Date: "DATE",
|
|
23
|
+
Url: "URL",
|
|
24
|
+
Email: "EMAIL",
|
|
25
|
+
Image: "IMAGE",
|
|
26
|
+
Video: "VIDEO",
|
|
27
|
+
Phone: "PHONE",
|
|
28
|
+
Boolean: "BOOLEAN",
|
|
29
|
+
Location: "LOCATION",
|
|
30
|
+
Array: "ARRAY",
|
|
31
|
+
Object: "OBJECT"
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/runtime/pagination/paginator.ts
|
|
35
|
+
var PagedIterator = class {
|
|
36
|
+
constructor(fetchPage) {
|
|
37
|
+
this.fetchPage = fetchPage;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Fetch all items across all pages
|
|
41
|
+
* @param options Base options (page will be overridden)
|
|
42
|
+
* @returns Array of all items
|
|
43
|
+
*/
|
|
44
|
+
async fetchAll(options = {}) {
|
|
45
|
+
const allItems = [];
|
|
46
|
+
let currentPage = 1;
|
|
47
|
+
let hasMore = true;
|
|
48
|
+
while (hasMore) {
|
|
49
|
+
const result = await this.fetchPage({ ...options, page: currentPage });
|
|
50
|
+
allItems.push(...result.data);
|
|
51
|
+
const pagination = result.pagination;
|
|
52
|
+
hasMore = pagination.page !== void 0 && pagination.totalPages !== void 0 && pagination.page < pagination.totalPages;
|
|
53
|
+
currentPage++;
|
|
54
|
+
}
|
|
55
|
+
return allItems;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create an async iterator for pages
|
|
59
|
+
* @param options Base options (page will be overridden)
|
|
60
|
+
* @returns Async generator that yields pages
|
|
61
|
+
*/
|
|
62
|
+
async *pages(options = {}) {
|
|
63
|
+
let currentPage = 1;
|
|
64
|
+
let hasMore = true;
|
|
65
|
+
while (hasMore) {
|
|
66
|
+
const result = await this.fetchPage({ ...options, page: currentPage });
|
|
67
|
+
yield result;
|
|
68
|
+
const pagination = result.pagination;
|
|
69
|
+
hasMore = pagination.page !== void 0 && pagination.totalPages !== void 0 && pagination.page < pagination.totalPages;
|
|
70
|
+
currentPage++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create an async iterator for individual items
|
|
75
|
+
* @param options Base options (page will be overridden)
|
|
76
|
+
* @returns Async generator that yields items
|
|
77
|
+
*/
|
|
78
|
+
async *items(options = {}) {
|
|
79
|
+
for await (const page of this.pages(options)) {
|
|
80
|
+
for (const item of page.data) {
|
|
81
|
+
yield item;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/domains/extraction/services/data-fetcher.service.ts
|
|
88
|
+
var DataFetcherService = class {
|
|
89
|
+
constructor(workflowsApi) {
|
|
90
|
+
this.workflowsApi = workflowsApi;
|
|
91
|
+
this.defaultLimit = 100;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Fetch a page of workflow data
|
|
95
|
+
*/
|
|
96
|
+
async fetchData(options) {
|
|
97
|
+
const response = await this.workflowsApi.v4WorkflowsWorkflowIdDataGet({
|
|
98
|
+
...options,
|
|
99
|
+
page: options.page ?? 1,
|
|
100
|
+
limit: options.limit ?? this.defaultLimit
|
|
101
|
+
});
|
|
102
|
+
const result = response.data;
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Fetch all pages of workflow data
|
|
107
|
+
*/
|
|
108
|
+
async fetchAllData(options) {
|
|
109
|
+
const iterator = new PagedIterator(
|
|
110
|
+
(pageOptions) => this.fetchData({ ...options, ...pageOptions })
|
|
111
|
+
);
|
|
112
|
+
return iterator.fetchAll({ limit: options.limit ?? this.defaultLimit });
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create an async iterator for paginated data fetching
|
|
116
|
+
*/
|
|
117
|
+
async *fetchDataPages(options) {
|
|
118
|
+
const iterator = new PagedIterator(
|
|
119
|
+
(pageOptions) => this.fetchData({ ...options, ...pageOptions })
|
|
120
|
+
);
|
|
121
|
+
for await (const page of iterator.pages({
|
|
122
|
+
limit: options.limit ?? this.defaultLimit
|
|
123
|
+
})) {
|
|
124
|
+
yield page;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// src/runtime/exceptions/base.exception.ts
|
|
17
130
|
var KadoaErrorCode = {
|
|
18
131
|
AUTH_ERROR: "AUTH_ERROR",
|
|
19
132
|
VALIDATION_ERROR: "VALIDATION_ERROR",
|
|
@@ -196,6 +309,128 @@ var KadoaHttpException = class _KadoaHttpException extends KadoaSdkException {
|
|
|
196
309
|
return "UNKNOWN";
|
|
197
310
|
}
|
|
198
311
|
};
|
|
312
|
+
var createLogger = (namespace) => createDebug(`kadoa:${namespace}`);
|
|
313
|
+
var logger = {
|
|
314
|
+
client: createLogger("client"),
|
|
315
|
+
wss: createLogger("wss"),
|
|
316
|
+
extraction: createLogger("extraction"),
|
|
317
|
+
http: createLogger("http"),
|
|
318
|
+
workflow: createLogger("workflow"),
|
|
319
|
+
crawl: createLogger("crawl"),
|
|
320
|
+
notifications: createLogger("notifications"),
|
|
321
|
+
schemas: createLogger("schemas"),
|
|
322
|
+
validation: createLogger("validation")
|
|
323
|
+
};
|
|
324
|
+
var _SchemaBuilder = class _SchemaBuilder {
|
|
325
|
+
constructor() {
|
|
326
|
+
this.fields = [];
|
|
327
|
+
}
|
|
328
|
+
entity(entityName) {
|
|
329
|
+
this.entityName = entityName;
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Add a structured field to the schema
|
|
334
|
+
* @param name - Field name (alphanumeric only)
|
|
335
|
+
* @param description - Field description
|
|
336
|
+
* @param dataType - Data type (STRING, NUMBER, BOOLEAN, etc.)
|
|
337
|
+
* @param options - Optional field configuration
|
|
338
|
+
*/
|
|
339
|
+
field(name, description, dataType, options) {
|
|
340
|
+
this.validateFieldName(name);
|
|
341
|
+
const requiresExample = _SchemaBuilder.TYPES_REQUIRING_EXAMPLE.includes(dataType);
|
|
342
|
+
if (requiresExample && !options?.example) {
|
|
343
|
+
throw new KadoaSdkException(
|
|
344
|
+
`Field "${name}" with type ${dataType} requires an example`,
|
|
345
|
+
{ code: "VALIDATION_ERROR", details: { name, dataType } }
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
this.fields.push({
|
|
349
|
+
name,
|
|
350
|
+
description,
|
|
351
|
+
dataType,
|
|
352
|
+
fieldType: "SCHEMA",
|
|
353
|
+
example: options?.example,
|
|
354
|
+
isKey: options?.isKey
|
|
355
|
+
});
|
|
356
|
+
return this;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Add a classification field to categorize content
|
|
360
|
+
* @param name - Field name (alphanumeric only)
|
|
361
|
+
* @param description - Field description
|
|
362
|
+
* @param categories - Array of category definitions
|
|
363
|
+
*/
|
|
364
|
+
classify(name, description, categories) {
|
|
365
|
+
this.validateFieldName(name);
|
|
366
|
+
this.fields.push({
|
|
367
|
+
name,
|
|
368
|
+
description,
|
|
369
|
+
fieldType: "CLASSIFICATION",
|
|
370
|
+
categories
|
|
371
|
+
});
|
|
372
|
+
return this;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Add raw page content to extract
|
|
376
|
+
* @param name - Raw content format(s): "html", "markdown", or "url"
|
|
377
|
+
*/
|
|
378
|
+
raw(name) {
|
|
379
|
+
const names = Array.isArray(name) ? name : [name];
|
|
380
|
+
for (const name2 of names) {
|
|
381
|
+
const fieldName = `raw${upperFirst(camelCase(name2))}`;
|
|
382
|
+
if (this.fields.some((field) => field.name === fieldName)) {
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
this.fields.push({
|
|
386
|
+
name: fieldName,
|
|
387
|
+
description: `Raw page content in ${name2.toUpperCase()} format`,
|
|
388
|
+
fieldType: "METADATA",
|
|
389
|
+
metadataKey: name2
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
return this;
|
|
393
|
+
}
|
|
394
|
+
build() {
|
|
395
|
+
if (!this.entityName) {
|
|
396
|
+
throw new KadoaSdkException("Entity name is required", {
|
|
397
|
+
code: "VALIDATION_ERROR",
|
|
398
|
+
details: { entityName: this.entityName }
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
entityName: this.entityName,
|
|
403
|
+
fields: this.fields
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
validateFieldName(name) {
|
|
407
|
+
if (!_SchemaBuilder.FIELD_NAME_PATTERN.test(name)) {
|
|
408
|
+
throw new KadoaSdkException(
|
|
409
|
+
`Field name "${name}" must be alphanumeric only (no underscores or special characters)`,
|
|
410
|
+
{
|
|
411
|
+
code: "VALIDATION_ERROR",
|
|
412
|
+
details: { name, pattern: "^[A-Za-z0-9]+$" }
|
|
413
|
+
}
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
const lowerName = name.toLowerCase();
|
|
417
|
+
if (this.fields.some((f) => f.name.toLowerCase() === lowerName)) {
|
|
418
|
+
throw new KadoaSdkException(`Duplicate field name: "${name}"`, {
|
|
419
|
+
code: "VALIDATION_ERROR",
|
|
420
|
+
details: { name }
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
_SchemaBuilder.FIELD_NAME_PATTERN = /^[A-Za-z0-9]+$/;
|
|
426
|
+
_SchemaBuilder.TYPES_REQUIRING_EXAMPLE = [
|
|
427
|
+
"STRING",
|
|
428
|
+
"IMAGE",
|
|
429
|
+
"LINK",
|
|
430
|
+
"OBJECT",
|
|
431
|
+
"ARRAY"
|
|
432
|
+
];
|
|
433
|
+
var SchemaBuilder = _SchemaBuilder;
|
|
199
434
|
var BASE_PATH = "https://api.kadoa.com".replace(/\/+$/, "");
|
|
200
435
|
var BaseAPI = class {
|
|
201
436
|
constructor(configuration, basePath = BASE_PATH, axios2 = globalAxios5) {
|
|
@@ -2608,7 +2843,7 @@ var WorkflowsApiAxiosParamCreator = function(configuration) {
|
|
|
2608
2843
|
/**
|
|
2609
2844
|
* Retrieves a list of workflows with pagination and search capabilities
|
|
2610
2845
|
* @summary Get a list of workflows
|
|
2611
|
-
* @param {string} [search] Search term to filter workflows by name or
|
|
2846
|
+
* @param {string} [search] Search term to filter workflows by name, URL, or workflow ID
|
|
2612
2847
|
* @param {number} [skip] Number of items to skip
|
|
2613
2848
|
* @param {number} [limit] Maximum number of items to return
|
|
2614
2849
|
* @param {V4WorkflowsGetStateEnum} [state] Filter workflows by state
|
|
@@ -3442,7 +3677,7 @@ var WorkflowsApiFp = function(configuration) {
|
|
|
3442
3677
|
/**
|
|
3443
3678
|
* Retrieves a list of workflows with pagination and search capabilities
|
|
3444
3679
|
* @summary Get a list of workflows
|
|
3445
|
-
* @param {string} [search] Search term to filter workflows by name or
|
|
3680
|
+
* @param {string} [search] Search term to filter workflows by name, URL, or workflow ID
|
|
3446
3681
|
* @param {number} [skip] Number of items to skip
|
|
3447
3682
|
* @param {number} [limit] Maximum number of items to return
|
|
3448
3683
|
* @param {V4WorkflowsGetStateEnum} [state] Filter workflows by state
|
|
@@ -4050,809 +4285,277 @@ var Configuration = class {
|
|
|
4050
4285
|
}
|
|
4051
4286
|
};
|
|
4052
4287
|
|
|
4053
|
-
// src/
|
|
4054
|
-
var
|
|
4055
|
-
var
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
// src/internal/runtime/config/constants.ts
|
|
4059
|
-
var PUBLIC_API_URI = process.env.KADOA_PUBLIC_API_URI ?? "https://api.kadoa.com";
|
|
4060
|
-
var WSS_API_URI = process.env.KADOA_WSS_API_URI ?? "wss://realtime.kadoa.com";
|
|
4061
|
-
var REALTIME_API_URI = process.env.KADOA_REALTIME_API_URI ?? "https://realtime.kadoa.com";
|
|
4062
|
-
var createLogger = (namespace) => createDebug(`kadoa:${namespace}`);
|
|
4063
|
-
var logger = {
|
|
4064
|
-
client: createLogger("client"),
|
|
4065
|
-
wss: createLogger("wss"),
|
|
4066
|
-
extraction: createLogger("extraction"),
|
|
4067
|
-
http: createLogger("http"),
|
|
4068
|
-
workflow: createLogger("workflow"),
|
|
4069
|
-
crawl: createLogger("crawl"),
|
|
4070
|
-
notifications: createLogger("notifications"),
|
|
4071
|
-
schemas: createLogger("schemas"),
|
|
4072
|
-
validation: createLogger("validation")
|
|
4073
|
-
};
|
|
4074
|
-
|
|
4075
|
-
// src/internal/domains/realtime/realtime.ts
|
|
4076
|
-
var debug = logger.wss;
|
|
4077
|
-
if (typeof WebSocket === "undefined") {
|
|
4078
|
-
global.WebSocket = __require("ws");
|
|
4079
|
-
}
|
|
4080
|
-
var Realtime = class {
|
|
4081
|
-
constructor(config) {
|
|
4082
|
-
this.lastHeartbeat = Date.now();
|
|
4083
|
-
this.isConnecting = false;
|
|
4084
|
-
this.eventListeners = /* @__PURE__ */ new Set();
|
|
4085
|
-
this.connectionListeners = /* @__PURE__ */ new Set();
|
|
4086
|
-
this.errorListeners = /* @__PURE__ */ new Set();
|
|
4087
|
-
if (!config.teamApiKey.startsWith("tk-")) {
|
|
4088
|
-
throw new KadoaSdkException(
|
|
4089
|
-
"Realtime connection requires a team API key (starting with 'tk-'). Provided key does not appear to be a team API key.",
|
|
4090
|
-
{
|
|
4091
|
-
code: "AUTH_ERROR",
|
|
4092
|
-
details: { providedKeyPrefix: config.teamApiKey.substring(0, 3) }
|
|
4093
|
-
}
|
|
4094
|
-
);
|
|
4095
|
-
}
|
|
4096
|
-
this.teamApiKey = config.teamApiKey;
|
|
4097
|
-
this.heartbeatInterval = config.heartbeatInterval || 1e4;
|
|
4098
|
-
this.reconnectDelay = config.reconnectDelay || 5e3;
|
|
4099
|
-
this.missedHeartbeatsLimit = config.missedHeartbeatsLimit || 3e4;
|
|
4100
|
-
}
|
|
4101
|
-
async connect() {
|
|
4102
|
-
if (this.isConnecting) return;
|
|
4103
|
-
this.isConnecting = true;
|
|
4104
|
-
try {
|
|
4105
|
-
const response = await fetch(`${PUBLIC_API_URI}/v4/oauth2/token`, {
|
|
4106
|
-
method: "POST",
|
|
4107
|
-
headers: {
|
|
4108
|
-
"Content-Type": "application/json",
|
|
4109
|
-
"x-api-key": `${this.teamApiKey}`,
|
|
4110
|
-
"x-sdk-version": SDK_VERSION
|
|
4111
|
-
}
|
|
4112
|
-
});
|
|
4113
|
-
const { access_token, team_id } = await response.json();
|
|
4114
|
-
this.socket = new WebSocket(
|
|
4115
|
-
`${WSS_API_URI}?access_token=${access_token}`
|
|
4116
|
-
);
|
|
4117
|
-
this.socket.onopen = () => {
|
|
4118
|
-
this.isConnecting = false;
|
|
4119
|
-
this.lastHeartbeat = Date.now();
|
|
4120
|
-
if (this.socket?.readyState === WebSocket.OPEN) {
|
|
4121
|
-
this.socket.send(
|
|
4122
|
-
JSON.stringify({
|
|
4123
|
-
action: "subscribe",
|
|
4124
|
-
channel: team_id
|
|
4125
|
-
})
|
|
4126
|
-
);
|
|
4127
|
-
debug("Connected to WebSocket");
|
|
4128
|
-
this.notifyConnectionListeners(true);
|
|
4129
|
-
}
|
|
4130
|
-
this.startHeartbeatCheck();
|
|
4131
|
-
};
|
|
4132
|
-
this.socket.onmessage = (event) => {
|
|
4133
|
-
try {
|
|
4134
|
-
const data = JSON.parse(event.data);
|
|
4135
|
-
if (data.type === "heartbeat") {
|
|
4136
|
-
this.handleHeartbeat();
|
|
4137
|
-
} else {
|
|
4138
|
-
if (data?.id) {
|
|
4139
|
-
fetch(`${REALTIME_API_URI}/api/v1/events/ack`, {
|
|
4140
|
-
method: "POST",
|
|
4141
|
-
headers: { "Content-Type": "application/json" },
|
|
4142
|
-
body: JSON.stringify({ id: data.id })
|
|
4143
|
-
});
|
|
4144
|
-
}
|
|
4145
|
-
this.notifyEventListeners(data);
|
|
4146
|
-
}
|
|
4147
|
-
} catch (err) {
|
|
4148
|
-
debug("Failed to parse incoming message: %O", err);
|
|
4149
|
-
}
|
|
4150
|
-
};
|
|
4151
|
-
this.socket.onclose = () => {
|
|
4152
|
-
debug("WebSocket disconnected. Attempting to reconnect...");
|
|
4153
|
-
this.isConnecting = false;
|
|
4154
|
-
this.stopHeartbeatCheck();
|
|
4155
|
-
this.notifyConnectionListeners(false, "Connection closed");
|
|
4156
|
-
setTimeout(() => this.connect(), this.reconnectDelay);
|
|
4157
|
-
};
|
|
4158
|
-
this.socket.onerror = (error) => {
|
|
4159
|
-
debug("WebSocket error: %O", error);
|
|
4160
|
-
this.isConnecting = false;
|
|
4161
|
-
this.notifyErrorListeners(error);
|
|
4162
|
-
};
|
|
4163
|
-
} catch (err) {
|
|
4164
|
-
debug("Failed to connect: %O", err);
|
|
4165
|
-
this.isConnecting = false;
|
|
4166
|
-
setTimeout(() => this.connect(), this.reconnectDelay);
|
|
4167
|
-
}
|
|
4168
|
-
}
|
|
4169
|
-
handleHeartbeat() {
|
|
4170
|
-
debug("Heartbeat received");
|
|
4171
|
-
this.lastHeartbeat = Date.now();
|
|
4172
|
-
}
|
|
4173
|
-
notifyEventListeners(event) {
|
|
4174
|
-
this.eventListeners.forEach((listener) => {
|
|
4175
|
-
try {
|
|
4176
|
-
listener(event);
|
|
4177
|
-
} catch (error) {
|
|
4178
|
-
debug("Error in event listener: %O", error);
|
|
4179
|
-
}
|
|
4180
|
-
});
|
|
4181
|
-
}
|
|
4182
|
-
notifyConnectionListeners(connected, reason) {
|
|
4183
|
-
this.connectionListeners.forEach((listener) => {
|
|
4184
|
-
try {
|
|
4185
|
-
listener(connected, reason);
|
|
4186
|
-
} catch (error) {
|
|
4187
|
-
debug("Error in connection listener: %O", error);
|
|
4188
|
-
}
|
|
4189
|
-
});
|
|
4190
|
-
}
|
|
4191
|
-
notifyErrorListeners(error) {
|
|
4192
|
-
this.errorListeners.forEach((listener) => {
|
|
4193
|
-
try {
|
|
4194
|
-
listener(error);
|
|
4195
|
-
} catch (error2) {
|
|
4196
|
-
debug("Error in error listener: %O", error2);
|
|
4197
|
-
}
|
|
4198
|
-
});
|
|
4199
|
-
}
|
|
4200
|
-
startHeartbeatCheck() {
|
|
4201
|
-
this.missedHeartbeatCheckTimer = setInterval(() => {
|
|
4202
|
-
if (Date.now() - this.lastHeartbeat > this.missedHeartbeatsLimit) {
|
|
4203
|
-
debug("No heartbeat received in 30 seconds! Closing connection.");
|
|
4204
|
-
this.socket?.close();
|
|
4205
|
-
}
|
|
4206
|
-
}, this.heartbeatInterval);
|
|
4207
|
-
}
|
|
4208
|
-
stopHeartbeatCheck() {
|
|
4209
|
-
if (this.missedHeartbeatCheckTimer) {
|
|
4210
|
-
clearInterval(this.missedHeartbeatCheckTimer);
|
|
4211
|
-
}
|
|
4212
|
-
}
|
|
4213
|
-
/**
|
|
4214
|
-
* Subscribe to realtime events
|
|
4215
|
-
* @param listener Function to handle incoming events
|
|
4216
|
-
* @returns Function to unsubscribe
|
|
4217
|
-
*/
|
|
4218
|
-
onEvent(listener) {
|
|
4219
|
-
this.eventListeners.add(listener);
|
|
4220
|
-
return () => {
|
|
4221
|
-
this.eventListeners.delete(listener);
|
|
4222
|
-
};
|
|
4288
|
+
// src/domains/schemas/schemas.service.ts
|
|
4289
|
+
var debug = logger.schemas;
|
|
4290
|
+
var SchemasService = class {
|
|
4291
|
+
constructor(client) {
|
|
4292
|
+
this.schemasApi = new SchemasApi(client.configuration);
|
|
4223
4293
|
}
|
|
4224
4294
|
/**
|
|
4225
|
-
*
|
|
4226
|
-
* @param listener Function to handle connection state changes
|
|
4227
|
-
* @returns Function to unsubscribe
|
|
4295
|
+
* Create a schema builder with fluent API and inline create support.
|
|
4228
4296
|
*/
|
|
4229
|
-
|
|
4230
|
-
this
|
|
4231
|
-
return
|
|
4232
|
-
|
|
4233
|
-
|
|
4297
|
+
builder(entityName) {
|
|
4298
|
+
const service = this;
|
|
4299
|
+
return new class extends SchemaBuilder {
|
|
4300
|
+
constructor() {
|
|
4301
|
+
super();
|
|
4302
|
+
this.entity(entityName);
|
|
4303
|
+
}
|
|
4304
|
+
async create(name) {
|
|
4305
|
+
const built = this.build();
|
|
4306
|
+
return service.createSchema({
|
|
4307
|
+
name: name || built.entityName,
|
|
4308
|
+
entity: built.entityName,
|
|
4309
|
+
fields: built.fields
|
|
4310
|
+
});
|
|
4311
|
+
}
|
|
4312
|
+
}();
|
|
4234
4313
|
}
|
|
4235
4314
|
/**
|
|
4236
|
-
*
|
|
4237
|
-
* @param listener Function to handle errors
|
|
4238
|
-
* @returns Function to unsubscribe
|
|
4315
|
+
* Get a schema by ID
|
|
4239
4316
|
*/
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
};
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4317
|
+
async getSchema(schemaId) {
|
|
4318
|
+
debug("Fetching schema with ID: %s", schemaId);
|
|
4319
|
+
const response = await this.schemasApi.v4SchemasSchemaIdGet({
|
|
4320
|
+
schemaId
|
|
4321
|
+
});
|
|
4322
|
+
const schemaData = response.data.data;
|
|
4323
|
+
if (!schemaData) {
|
|
4324
|
+
throw new KadoaSdkException(
|
|
4325
|
+
`${ERROR_MESSAGES.SCHEMA_NOT_FOUND}: ${schemaId}`,
|
|
4326
|
+
{
|
|
4327
|
+
code: KadoaErrorCode.NOT_FOUND,
|
|
4328
|
+
details: { schemaId }
|
|
4329
|
+
}
|
|
4330
|
+
);
|
|
4251
4331
|
}
|
|
4252
|
-
|
|
4253
|
-
this.connectionListeners.clear();
|
|
4254
|
-
this.errorListeners.clear();
|
|
4255
|
-
}
|
|
4256
|
-
isConnected() {
|
|
4257
|
-
return this.socket?.readyState === WebSocket.OPEN;
|
|
4258
|
-
}
|
|
4259
|
-
};
|
|
4260
|
-
|
|
4261
|
-
// src/modules/extraction.module.ts
|
|
4262
|
-
var ExtractionModule = class {
|
|
4263
|
-
constructor(extractionService, dataFetcherService, channelsService, settingsService, workflowsCoreService) {
|
|
4264
|
-
this.extractionService = extractionService;
|
|
4265
|
-
this.dataFetcherService = dataFetcherService;
|
|
4266
|
-
this.channelsService = channelsService;
|
|
4267
|
-
this.settingsService = settingsService;
|
|
4268
|
-
this.workflowsCoreService = workflowsCoreService;
|
|
4332
|
+
return schemaData;
|
|
4269
4333
|
}
|
|
4270
4334
|
/**
|
|
4271
|
-
*
|
|
4272
|
-
*
|
|
4273
|
-
* @param options Extraction configuration options including optional notification settings
|
|
4274
|
-
* @returns ExtractionResult containing workflow ID, workflow details, and first page of extracted data
|
|
4275
|
-
*
|
|
4276
|
-
* @example Simple extraction with AI detection
|
|
4277
|
-
* ```typescript
|
|
4278
|
-
* const result = await client.extraction.run({
|
|
4279
|
-
* urls: ['https://example.com'],
|
|
4280
|
-
* name: 'My Extraction'
|
|
4281
|
-
* });
|
|
4282
|
-
* ```
|
|
4283
|
-
*
|
|
4284
|
-
* @example With notifications
|
|
4285
|
-
* ```typescript
|
|
4286
|
-
* const result = await client.extraction.run({
|
|
4287
|
-
* urls: ['https://example.com'],
|
|
4288
|
-
* name: 'My Extraction',
|
|
4289
|
-
* notifications: {
|
|
4290
|
-
* events: ['workflow_completed', 'workflow_failed'],
|
|
4291
|
-
* channels: {
|
|
4292
|
-
* email: true,
|
|
4293
|
-
* slack: { channelId: 'slack-channel-id' }
|
|
4294
|
-
* }
|
|
4295
|
-
* }
|
|
4296
|
-
* });
|
|
4297
|
-
* ```
|
|
4298
|
-
*
|
|
4299
|
-
* @see {@link KadoaClient.extract} For more flexible extraction configuration using the builder API
|
|
4335
|
+
* List all schemas
|
|
4300
4336
|
*/
|
|
4301
|
-
async
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
mode: "run"
|
|
4305
|
-
});
|
|
4337
|
+
async listSchemas() {
|
|
4338
|
+
const response = await this.schemasApi.v4SchemasGet();
|
|
4339
|
+
return response.data.data;
|
|
4306
4340
|
}
|
|
4307
4341
|
/**
|
|
4308
|
-
*
|
|
4309
|
-
*
|
|
4310
|
-
* @param options Extraction configuration options including optional notification settings
|
|
4311
|
-
* @returns SubmitExtractionResult containing workflow ID
|
|
4312
|
-
*
|
|
4313
|
-
* @example
|
|
4314
|
-
* ```typescript
|
|
4315
|
-
* const result = await client.extraction.submit({
|
|
4316
|
-
* urls: ['https://example.com'],
|
|
4317
|
-
* name: 'My Extraction',
|
|
4318
|
-
* notifications: {
|
|
4319
|
-
* events: 'all',
|
|
4320
|
-
* channels: {
|
|
4321
|
-
* email: true
|
|
4322
|
-
* }
|
|
4323
|
-
* }
|
|
4324
|
-
* });
|
|
4325
|
-
* ```
|
|
4326
|
-
*
|
|
4327
|
-
* @see {@link KadoaClient.extract} For more flexible extraction configuration using the builder API
|
|
4342
|
+
* Create a new schema
|
|
4328
4343
|
*/
|
|
4329
|
-
async
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4344
|
+
async createSchema(body) {
|
|
4345
|
+
debug("Creating schema with name: %s", body.name);
|
|
4346
|
+
const response = await this.schemasApi.v4SchemasPost({
|
|
4347
|
+
createSchemaBody: body
|
|
4333
4348
|
});
|
|
4349
|
+
const schemaId = response.data.schemaId;
|
|
4350
|
+
if (!schemaId) {
|
|
4351
|
+
throw new KadoaSdkException(ERROR_MESSAGES.SCHEMA_CREATE_FAILED, {
|
|
4352
|
+
code: KadoaErrorCode.INTERNAL_ERROR
|
|
4353
|
+
});
|
|
4354
|
+
}
|
|
4355
|
+
return this.getSchema(schemaId);
|
|
4334
4356
|
}
|
|
4335
4357
|
/**
|
|
4336
|
-
*
|
|
4358
|
+
* Update an existing schema
|
|
4337
4359
|
*/
|
|
4338
|
-
async
|
|
4339
|
-
|
|
4360
|
+
async updateSchema(schemaId, body) {
|
|
4361
|
+
debug("Updating schema with ID: %s", schemaId);
|
|
4362
|
+
await this.schemasApi.v4SchemasSchemaIdPut({
|
|
4363
|
+
schemaId,
|
|
4364
|
+
updateSchemaBody: body
|
|
4365
|
+
});
|
|
4366
|
+
return this.getSchema(schemaId);
|
|
4340
4367
|
}
|
|
4341
4368
|
/**
|
|
4342
|
-
*
|
|
4369
|
+
* Delete a schema
|
|
4343
4370
|
*/
|
|
4344
|
-
async
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
);
|
|
4349
|
-
return this.workflowsCoreService.waitForJobCompletion(
|
|
4350
|
-
workflowId,
|
|
4351
|
-
result.jobId
|
|
4352
|
-
);
|
|
4371
|
+
async deleteSchema(schemaId) {
|
|
4372
|
+
debug("Deleting schema with ID: %s", schemaId);
|
|
4373
|
+
await this.schemasApi.v4SchemasSchemaIdDelete({
|
|
4374
|
+
schemaId
|
|
4375
|
+
});
|
|
4353
4376
|
}
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
* // Fetch first page
|
|
4363
|
-
* const firstPage = await client.extraction.fetchData({
|
|
4364
|
-
* workflowId: 'workflow-id',
|
|
4365
|
-
* page: 1,
|
|
4366
|
-
* limit: 100
|
|
4367
|
-
* });
|
|
4368
|
-
*
|
|
4369
|
-
* // Iterate through all pages
|
|
4370
|
-
* for await (const page of client.extraction.fetchDataPages({ workflowId: 'workflow-id' })) {
|
|
4371
|
-
* console.log(`Processing ${page.data.length} records`);
|
|
4372
|
-
* }
|
|
4373
|
-
* ```
|
|
4374
|
-
*/
|
|
4375
|
-
async fetchData(options) {
|
|
4376
|
-
return this.dataFetcherService.fetchData(options);
|
|
4377
|
+
};
|
|
4378
|
+
|
|
4379
|
+
// src/domains/extraction/services/entity-resolver.service.ts
|
|
4380
|
+
var ENTITY_API_ENDPOINT = "/v4/entity";
|
|
4381
|
+
var EntityResolverService = class {
|
|
4382
|
+
constructor(client) {
|
|
4383
|
+
this.client = client;
|
|
4384
|
+
this.schemasService = new SchemasService(client);
|
|
4377
4385
|
}
|
|
4378
4386
|
/**
|
|
4379
|
-
*
|
|
4380
|
-
*
|
|
4381
|
-
* @param options Options for fetching data
|
|
4382
|
-
* @returns All workflow data combined from all pages
|
|
4387
|
+
* Resolves entity and fields from the provided entity configuration
|
|
4383
4388
|
*
|
|
4384
|
-
* @
|
|
4385
|
-
*
|
|
4386
|
-
*
|
|
4387
|
-
* workflowId: 'workflow-id'
|
|
4388
|
-
* });
|
|
4389
|
-
* ```
|
|
4389
|
+
* @param entityConfig The entity configuration to resolve
|
|
4390
|
+
* @param options Additional options for AI detection
|
|
4391
|
+
* @returns Resolved entity with fields
|
|
4390
4392
|
*/
|
|
4391
|
-
async
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4393
|
+
async resolveEntity(entityConfig, options) {
|
|
4394
|
+
if (entityConfig === "ai-detection") {
|
|
4395
|
+
if (!options?.link) {
|
|
4396
|
+
throw new KadoaSdkException(ERROR_MESSAGES.LINK_REQUIRED, {
|
|
4397
|
+
code: "VALIDATION_ERROR",
|
|
4398
|
+
details: { entityConfig, options }
|
|
4399
|
+
});
|
|
4400
|
+
}
|
|
4401
|
+
const entityPrediction = await this.fetchEntityFields({
|
|
4402
|
+
link: options.link,
|
|
4403
|
+
location: options.location,
|
|
4404
|
+
navigationMode: options.navigationMode
|
|
4405
|
+
});
|
|
4406
|
+
return {
|
|
4407
|
+
entity: entityPrediction.entity,
|
|
4408
|
+
fields: entityPrediction.fields
|
|
4409
|
+
};
|
|
4410
|
+
} else if (entityConfig) {
|
|
4411
|
+
if ("schemaId" in entityConfig) {
|
|
4412
|
+
const schema = await this.schemasService.getSchema(
|
|
4413
|
+
entityConfig.schemaId
|
|
4414
|
+
);
|
|
4415
|
+
return {
|
|
4416
|
+
entity: schema.entity ?? "",
|
|
4417
|
+
fields: schema.schema
|
|
4418
|
+
};
|
|
4419
|
+
} else if ("name" in entityConfig && "fields" in entityConfig) {
|
|
4420
|
+
return {
|
|
4421
|
+
entity: entityConfig.name,
|
|
4422
|
+
fields: entityConfig.fields
|
|
4423
|
+
};
|
|
4424
|
+
}
|
|
4425
|
+
}
|
|
4426
|
+
throw new KadoaSdkException(ERROR_MESSAGES.ENTITY_INVARIANT_VIOLATION, {
|
|
4427
|
+
details: {
|
|
4428
|
+
entity: entityConfig
|
|
4429
|
+
}
|
|
4430
|
+
});
|
|
4423
4431
|
}
|
|
4424
4432
|
/**
|
|
4425
|
-
*
|
|
4426
|
-
*
|
|
4427
|
-
*
|
|
4428
|
-
* @returns Array of notification settings
|
|
4433
|
+
* Fetches entity fields dynamically from the /v4/entity endpoint.
|
|
4434
|
+
* This is a workaround implementation using native fetch since the endpoint
|
|
4435
|
+
* is not yet included in the OpenAPI specification.
|
|
4429
4436
|
*
|
|
4430
|
-
* @
|
|
4431
|
-
*
|
|
4432
|
-
* const settings = await client.extraction.getNotificationSettings('workflow-id');
|
|
4433
|
-
* ```
|
|
4437
|
+
* @param options Request options including the link to analyze
|
|
4438
|
+
* @returns EntityPrediction containing the detected entity type and fields
|
|
4434
4439
|
*/
|
|
4435
|
-
async
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
this.channelSetupService = channelSetupService;
|
|
4446
|
-
}
|
|
4447
|
-
async setupForWorkflow(requestData) {
|
|
4448
|
-
const existingSettings = await this.settingsService.listSettings({
|
|
4449
|
-
workflowId: requestData.workflowId
|
|
4440
|
+
async fetchEntityFields(options) {
|
|
4441
|
+
this.validateEntityOptions(options);
|
|
4442
|
+
const url = `${this.client.baseUrl}${ENTITY_API_ENDPOINT}`;
|
|
4443
|
+
const requestBody = options;
|
|
4444
|
+
const response = await this.client.axiosInstance.post(url, requestBody, {
|
|
4445
|
+
headers: {
|
|
4446
|
+
"Content-Type": "application/json",
|
|
4447
|
+
Accept: "application/json",
|
|
4448
|
+
"x-api-key": this.client.apiKey
|
|
4449
|
+
}
|
|
4450
4450
|
});
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4451
|
+
const data = response.data;
|
|
4452
|
+
if (!data.success || !data.entityPrediction || data.entityPrediction.length === 0) {
|
|
4453
|
+
throw new KadoaSdkException(ERROR_MESSAGES.NO_PREDICTIONS, {
|
|
4454
|
+
code: "NOT_FOUND",
|
|
4454
4455
|
details: {
|
|
4455
|
-
|
|
4456
|
+
success: data.success,
|
|
4457
|
+
hasPredictions: !!data.entityPrediction,
|
|
4458
|
+
predictionCount: data.entityPrediction?.length || 0,
|
|
4459
|
+
link: options.link
|
|
4456
4460
|
}
|
|
4457
4461
|
});
|
|
4458
4462
|
}
|
|
4459
|
-
return
|
|
4460
|
-
workflowId: requestData.workflowId,
|
|
4461
|
-
events: requestData.events,
|
|
4462
|
-
channels: requestData.channels
|
|
4463
|
-
});
|
|
4463
|
+
return data.entityPrediction[0];
|
|
4464
4464
|
}
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4465
|
+
/**
|
|
4466
|
+
* Validates entity request options
|
|
4467
|
+
*/
|
|
4468
|
+
validateEntityOptions(options) {
|
|
4469
|
+
if (!options.link) {
|
|
4470
|
+
throw new KadoaSdkException(ERROR_MESSAGES.LINK_REQUIRED, {
|
|
4471
|
+
code: "VALIDATION_ERROR",
|
|
4472
|
+
details: { options }
|
|
4470
4473
|
});
|
|
4471
4474
|
}
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4475
|
+
}
|
|
4476
|
+
};
|
|
4477
|
+
var debug2 = logger.extraction;
|
|
4478
|
+
var SUCCESSFUL_RUN_STATES = /* @__PURE__ */ new Set(["FINISHED", "SUCCESS"]);
|
|
4479
|
+
var DEFAULT_OPTIONS = {
|
|
4480
|
+
mode: "run",
|
|
4481
|
+
pollingInterval: 5e3,
|
|
4482
|
+
maxWaitTime: 3e5,
|
|
4483
|
+
navigationMode: "single-page",
|
|
4484
|
+
location: { type: "auto" },
|
|
4485
|
+
name: "Untitled Workflow",
|
|
4486
|
+
bypassPreview: true,
|
|
4487
|
+
autoStart: true
|
|
4488
|
+
};
|
|
4489
|
+
var ExtractionService = class {
|
|
4490
|
+
constructor(workflowsCoreService, dataFetcherService, entityResolverService, notificationSetupService, notificationChannelsService, notificationSettingsService) {
|
|
4491
|
+
this.workflowsCoreService = workflowsCoreService;
|
|
4492
|
+
this.dataFetcherService = dataFetcherService;
|
|
4493
|
+
this.entityResolverService = entityResolverService;
|
|
4494
|
+
this.notificationSetupService = notificationSetupService;
|
|
4495
|
+
this.notificationChannelsService = notificationChannelsService;
|
|
4496
|
+
this.notificationSettingsService = notificationSettingsService;
|
|
4476
4497
|
}
|
|
4477
4498
|
/**
|
|
4478
|
-
*
|
|
4499
|
+
* Run an extraction workflow and wait for completion.
|
|
4479
4500
|
*/
|
|
4480
|
-
|
|
4481
|
-
return this.
|
|
4501
|
+
async run(options) {
|
|
4502
|
+
return await this.executeExtraction({ ...options, mode: "run" });
|
|
4482
4503
|
}
|
|
4483
4504
|
/**
|
|
4484
|
-
*
|
|
4505
|
+
* Submit an extraction workflow for asynchronous processing.
|
|
4485
4506
|
*/
|
|
4486
|
-
|
|
4487
|
-
return this.
|
|
4488
|
-
}
|
|
4489
|
-
};
|
|
4490
|
-
var _SchemaBuilder = class _SchemaBuilder {
|
|
4491
|
-
constructor() {
|
|
4492
|
-
this.fields = [];
|
|
4493
|
-
}
|
|
4494
|
-
entity(entityName) {
|
|
4495
|
-
this.entityName = entityName;
|
|
4496
|
-
return this;
|
|
4507
|
+
async submit(options) {
|
|
4508
|
+
return await this.executeExtraction({ ...options, mode: "submit" });
|
|
4497
4509
|
}
|
|
4498
4510
|
/**
|
|
4499
|
-
*
|
|
4500
|
-
* @param name - Field name (alphanumeric only)
|
|
4501
|
-
* @param description - Field description
|
|
4502
|
-
* @param dataType - Data type (STRING, NUMBER, BOOLEAN, etc.)
|
|
4503
|
-
* @param options - Optional field configuration
|
|
4511
|
+
* Trigger a workflow run without waiting for completion.
|
|
4504
4512
|
*/
|
|
4505
|
-
|
|
4506
|
-
this.
|
|
4507
|
-
const requiresExample = _SchemaBuilder.TYPES_REQUIRING_EXAMPLE.includes(dataType);
|
|
4508
|
-
if (requiresExample && !options?.example) {
|
|
4509
|
-
throw new KadoaSdkException(
|
|
4510
|
-
`Field "${name}" with type ${dataType} requires an example`,
|
|
4511
|
-
{ code: "VALIDATION_ERROR", details: { name, dataType } }
|
|
4512
|
-
);
|
|
4513
|
-
}
|
|
4514
|
-
this.fields.push({
|
|
4515
|
-
name,
|
|
4516
|
-
description,
|
|
4517
|
-
dataType,
|
|
4518
|
-
fieldType: "SCHEMA",
|
|
4519
|
-
example: options?.example,
|
|
4520
|
-
isKey: options?.isKey
|
|
4521
|
-
});
|
|
4522
|
-
return this;
|
|
4513
|
+
async runJob(workflowId, input) {
|
|
4514
|
+
return await this.workflowsCoreService.runWorkflow(workflowId, input);
|
|
4523
4515
|
}
|
|
4524
4516
|
/**
|
|
4525
|
-
*
|
|
4526
|
-
* @param name - Field name (alphanumeric only)
|
|
4527
|
-
* @param description - Field description
|
|
4528
|
-
* @param categories - Array of category definitions
|
|
4517
|
+
* Trigger a workflow run and wait for the job to complete.
|
|
4529
4518
|
*/
|
|
4530
|
-
|
|
4531
|
-
this.
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4519
|
+
async runJobAndWait(workflowId, input) {
|
|
4520
|
+
const result = await this.workflowsCoreService.runWorkflow(
|
|
4521
|
+
workflowId,
|
|
4522
|
+
input
|
|
4523
|
+
);
|
|
4524
|
+
return await this.workflowsCoreService.waitForJobCompletion(
|
|
4525
|
+
workflowId,
|
|
4526
|
+
result.jobId || ""
|
|
4527
|
+
);
|
|
4539
4528
|
}
|
|
4540
4529
|
/**
|
|
4541
|
-
*
|
|
4542
|
-
* @param name - Raw content format(s): "html", "markdown", or "url"
|
|
4530
|
+
* Fetch a single page of extraction data.
|
|
4543
4531
|
*/
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
for (const name2 of names) {
|
|
4547
|
-
const fieldName = `raw${upperFirst(camelCase(name2))}`;
|
|
4548
|
-
if (this.fields.some((field) => field.name === fieldName)) {
|
|
4549
|
-
continue;
|
|
4550
|
-
}
|
|
4551
|
-
this.fields.push({
|
|
4552
|
-
name: fieldName,
|
|
4553
|
-
description: `Raw page content in ${name2.toUpperCase()} format`,
|
|
4554
|
-
fieldType: "METADATA",
|
|
4555
|
-
metadataKey: name2
|
|
4556
|
-
});
|
|
4557
|
-
}
|
|
4558
|
-
return this;
|
|
4559
|
-
}
|
|
4560
|
-
build() {
|
|
4561
|
-
if (!this.entityName) {
|
|
4562
|
-
throw new KadoaSdkException("Entity name is required", {
|
|
4563
|
-
code: "VALIDATION_ERROR",
|
|
4564
|
-
details: { entityName: this.entityName }
|
|
4565
|
-
});
|
|
4566
|
-
}
|
|
4567
|
-
return {
|
|
4568
|
-
entityName: this.entityName,
|
|
4569
|
-
fields: this.fields
|
|
4570
|
-
};
|
|
4571
|
-
}
|
|
4572
|
-
validateFieldName(name) {
|
|
4573
|
-
if (!_SchemaBuilder.FIELD_NAME_PATTERN.test(name)) {
|
|
4574
|
-
throw new KadoaSdkException(
|
|
4575
|
-
`Field name "${name}" must be alphanumeric only (no underscores or special characters)`,
|
|
4576
|
-
{
|
|
4577
|
-
code: "VALIDATION_ERROR",
|
|
4578
|
-
details: { name, pattern: "^[A-Za-z0-9]+$" }
|
|
4579
|
-
}
|
|
4580
|
-
);
|
|
4581
|
-
}
|
|
4582
|
-
const lowerName = name.toLowerCase();
|
|
4583
|
-
if (this.fields.some((f) => f.name.toLowerCase() === lowerName)) {
|
|
4584
|
-
throw new KadoaSdkException(`Duplicate field name: "${name}"`, {
|
|
4585
|
-
code: "VALIDATION_ERROR",
|
|
4586
|
-
details: { name }
|
|
4587
|
-
});
|
|
4588
|
-
}
|
|
4589
|
-
}
|
|
4590
|
-
};
|
|
4591
|
-
_SchemaBuilder.FIELD_NAME_PATTERN = /^[A-Za-z0-9]+$/;
|
|
4592
|
-
_SchemaBuilder.TYPES_REQUIRING_EXAMPLE = [
|
|
4593
|
-
"STRING",
|
|
4594
|
-
"IMAGE",
|
|
4595
|
-
"LINK",
|
|
4596
|
-
"OBJECT",
|
|
4597
|
-
"ARRAY"
|
|
4598
|
-
];
|
|
4599
|
-
var SchemaBuilder = _SchemaBuilder;
|
|
4600
|
-
|
|
4601
|
-
// src/modules/schemas.module.ts
|
|
4602
|
-
var SchemaBuilderWithCreate = class extends SchemaBuilder {
|
|
4603
|
-
constructor(entityName, service) {
|
|
4604
|
-
super();
|
|
4605
|
-
this.service = service;
|
|
4606
|
-
this.entity(entityName);
|
|
4532
|
+
async fetchData(options) {
|
|
4533
|
+
return await this.dataFetcherService.fetchData(options);
|
|
4607
4534
|
}
|
|
4608
4535
|
/**
|
|
4609
|
-
*
|
|
4610
|
-
* @param name - Optional schema name (defaults to entity name)
|
|
4611
|
-
* @returns Promise resolving to the created schema
|
|
4536
|
+
* Fetch all extraction data across all pages.
|
|
4612
4537
|
*/
|
|
4613
|
-
async
|
|
4614
|
-
|
|
4615
|
-
return this.service.createSchema({
|
|
4616
|
-
name: name || built.entityName,
|
|
4617
|
-
entity: built.entityName,
|
|
4618
|
-
fields: built.fields
|
|
4619
|
-
});
|
|
4620
|
-
}
|
|
4621
|
-
};
|
|
4622
|
-
var SchemasModule = class {
|
|
4623
|
-
constructor(service) {
|
|
4624
|
-
this.service = service;
|
|
4538
|
+
async fetchAllData(options) {
|
|
4539
|
+
return await this.dataFetcherService.fetchAllData(options);
|
|
4625
4540
|
}
|
|
4626
4541
|
/**
|
|
4627
|
-
*
|
|
4628
|
-
* @param entityName - The name of the entity this schema represents
|
|
4629
|
-
* @returns A new SchemaBuilder instance with the entity name already set
|
|
4630
|
-
* @example Build then create
|
|
4631
|
-
* ```typescript
|
|
4632
|
-
* const schema = kadoa.schema.builder("Product")
|
|
4633
|
-
* .field("title", "Product name", "STRING", { example: "iPhone 15" })
|
|
4634
|
-
* .field("price", "Product price", "NUMBER")
|
|
4635
|
-
* .build();
|
|
4636
|
-
*
|
|
4637
|
-
* await kadoa.schema.create(schema);
|
|
4638
|
-
* ```
|
|
4639
|
-
*
|
|
4640
|
-
* @example Fluent chain with create
|
|
4641
|
-
* ```typescript
|
|
4642
|
-
* const schema = await kadoa.schema.builder("Product")
|
|
4643
|
-
* .field("title", "Product name", "STRING", { example: "iPhone 15" })
|
|
4644
|
-
* .field("price", "Product price", "NUMBER")
|
|
4645
|
-
* .create("Product Schema");
|
|
4646
|
-
* ```
|
|
4647
|
-
*/
|
|
4648
|
-
builder(entityName) {
|
|
4649
|
-
return new SchemaBuilderWithCreate(entityName, this.service);
|
|
4650
|
-
}
|
|
4651
|
-
/**
|
|
4652
|
-
* Get a schema by ID
|
|
4653
|
-
*/
|
|
4654
|
-
async get(schemaId) {
|
|
4655
|
-
return this.service.getSchema(schemaId);
|
|
4656
|
-
}
|
|
4657
|
-
/**
|
|
4658
|
-
* List all schemas
|
|
4659
|
-
*/
|
|
4660
|
-
async list() {
|
|
4661
|
-
return this.service.listSchemas();
|
|
4662
|
-
}
|
|
4663
|
-
/**
|
|
4664
|
-
* Create a new schema from a body
|
|
4665
|
-
*/
|
|
4666
|
-
async create(body) {
|
|
4667
|
-
return this.service.createSchema(body);
|
|
4668
|
-
}
|
|
4669
|
-
/**
|
|
4670
|
-
* Update an existing schema
|
|
4671
|
-
*/
|
|
4672
|
-
async update(schemaId, body) {
|
|
4673
|
-
return this.service.updateSchema(schemaId, body);
|
|
4674
|
-
}
|
|
4675
|
-
/**
|
|
4676
|
-
* Delete a schema
|
|
4677
|
-
*/
|
|
4678
|
-
async delete(schemaId) {
|
|
4679
|
-
return this.service.deleteSchema(schemaId);
|
|
4680
|
-
}
|
|
4681
|
-
};
|
|
4682
|
-
|
|
4683
|
-
// src/modules/user.module.ts
|
|
4684
|
-
var UserModule = class {
|
|
4685
|
-
constructor(userService) {
|
|
4686
|
-
this.userService = userService;
|
|
4687
|
-
}
|
|
4688
|
-
/**
|
|
4689
|
-
* Get the underlying UserService instance
|
|
4690
|
-
* @returns UserService instance
|
|
4691
|
-
*/
|
|
4692
|
-
get service() {
|
|
4693
|
-
return this.userService;
|
|
4694
|
-
}
|
|
4695
|
-
/**
|
|
4696
|
-
* Get current user details
|
|
4697
|
-
* @returns KadoaUser details
|
|
4698
|
-
*/
|
|
4699
|
-
async getCurrentUser() {
|
|
4700
|
-
return this.userService.getCurrentUser();
|
|
4701
|
-
}
|
|
4702
|
-
};
|
|
4703
|
-
|
|
4704
|
-
// src/modules/validation.module.ts
|
|
4705
|
-
var ValidationModule = class {
|
|
4706
|
-
constructor(coreService, rulesService) {
|
|
4707
|
-
this.coreService = coreService;
|
|
4708
|
-
this.rulesService = rulesService;
|
|
4709
|
-
}
|
|
4710
|
-
listRules(options) {
|
|
4711
|
-
return this.rulesService.listRules(options);
|
|
4712
|
-
}
|
|
4713
|
-
getRuleByName(name) {
|
|
4714
|
-
return this.rulesService.getRuleByName(name);
|
|
4715
|
-
}
|
|
4716
|
-
createRule(data) {
|
|
4717
|
-
return this.rulesService.createRule(data);
|
|
4718
|
-
}
|
|
4719
|
-
generateRule(data) {
|
|
4720
|
-
return this.rulesService.generateRule(data);
|
|
4721
|
-
}
|
|
4722
|
-
generateRules(data) {
|
|
4723
|
-
return this.rulesService.generateRules(data);
|
|
4724
|
-
}
|
|
4725
|
-
bulkApproveRules(data) {
|
|
4726
|
-
return this.rulesService.bulkApproveRules(data);
|
|
4727
|
-
}
|
|
4728
|
-
bulkDeleteRules(data) {
|
|
4729
|
-
return this.rulesService.bulkDeleteRules(data);
|
|
4730
|
-
}
|
|
4731
|
-
deleteAllRules(data) {
|
|
4732
|
-
return this.rulesService.deleteAllRules(data);
|
|
4733
|
-
}
|
|
4734
|
-
listWorkflowValidations(workflowId, jobId) {
|
|
4735
|
-
return this.coreService.listWorkflowValidations({ workflowId, jobId });
|
|
4736
|
-
}
|
|
4737
|
-
scheduleValidation(workflowId, jobId) {
|
|
4738
|
-
return this.coreService.scheduleValidation(workflowId, jobId);
|
|
4739
|
-
}
|
|
4740
|
-
waitUntilCompleted(validationId, options) {
|
|
4741
|
-
return this.coreService.waitUntilCompleted(validationId, options);
|
|
4742
|
-
}
|
|
4743
|
-
getValidationDetails(validationId) {
|
|
4744
|
-
return this.coreService.getValidationDetails(validationId);
|
|
4745
|
-
}
|
|
4746
|
-
getLatestValidation(workflowId, jobId) {
|
|
4747
|
-
return this.coreService.getLatestValidation(workflowId, jobId);
|
|
4748
|
-
}
|
|
4749
|
-
getValidationAnomalies(validationId) {
|
|
4750
|
-
return this.coreService.getValidationAnomalies(validationId);
|
|
4751
|
-
}
|
|
4752
|
-
getValidationAnomaliesByRule(validationId, ruleName) {
|
|
4753
|
-
return this.coreService.getValidationAnomaliesByRule(
|
|
4754
|
-
validationId,
|
|
4755
|
-
ruleName
|
|
4756
|
-
);
|
|
4757
|
-
}
|
|
4758
|
-
toggleValidationEnabled(workflowId) {
|
|
4759
|
-
return this.coreService.toggleValidationEnabled(workflowId);
|
|
4760
|
-
}
|
|
4761
|
-
};
|
|
4762
|
-
|
|
4763
|
-
// src/modules/workflows.module.ts
|
|
4764
|
-
var WorkflowsModule = class {
|
|
4765
|
-
constructor(core) {
|
|
4766
|
-
this.core = core;
|
|
4767
|
-
}
|
|
4768
|
-
async get(workflowId) {
|
|
4769
|
-
return this.core.get(workflowId);
|
|
4770
|
-
}
|
|
4771
|
-
async list(filters) {
|
|
4772
|
-
return this.core.list(filters);
|
|
4773
|
-
}
|
|
4774
|
-
async getByName(name) {
|
|
4775
|
-
return this.core.getByName(name);
|
|
4776
|
-
}
|
|
4777
|
-
async create(input) {
|
|
4778
|
-
return this.core.create(input);
|
|
4779
|
-
}
|
|
4780
|
-
async cancel(workflowId) {
|
|
4781
|
-
return this.core.cancel(workflowId);
|
|
4782
|
-
}
|
|
4783
|
-
async approve(workflowId) {
|
|
4784
|
-
return this.core.resume(workflowId);
|
|
4785
|
-
}
|
|
4786
|
-
async resume(workflowId) {
|
|
4787
|
-
return this.core.resume(workflowId);
|
|
4788
|
-
}
|
|
4789
|
-
async wait(workflowId, options) {
|
|
4790
|
-
return this.core.wait(workflowId, options);
|
|
4791
|
-
}
|
|
4792
|
-
/**
|
|
4793
|
-
* Get job status directly without polling workflow details
|
|
4542
|
+
* Iterate through extraction data pages.
|
|
4794
4543
|
*/
|
|
4795
|
-
|
|
4796
|
-
return this.
|
|
4544
|
+
fetchDataPages(options) {
|
|
4545
|
+
return this.dataFetcherService.fetchDataPages(options);
|
|
4797
4546
|
}
|
|
4798
4547
|
/**
|
|
4799
|
-
*
|
|
4548
|
+
* List notification channels for a workflow.
|
|
4800
4549
|
*/
|
|
4801
|
-
async
|
|
4802
|
-
return this.
|
|
4803
|
-
}
|
|
4804
|
-
};
|
|
4805
|
-
|
|
4806
|
-
// src/internal/domains/user/user.service.ts
|
|
4807
|
-
var UserService = class {
|
|
4808
|
-
constructor(client) {
|
|
4809
|
-
this.client = client;
|
|
4550
|
+
async getNotificationChannels(workflowId) {
|
|
4551
|
+
return await this.notificationChannelsService.listChannels({ workflowId });
|
|
4810
4552
|
}
|
|
4811
4553
|
/**
|
|
4812
|
-
*
|
|
4813
|
-
* @returns User details
|
|
4554
|
+
* List notification settings for a workflow.
|
|
4814
4555
|
*/
|
|
4815
|
-
async
|
|
4816
|
-
|
|
4817
|
-
baseURL: this.client.baseUrl,
|
|
4818
|
-
headers: {
|
|
4819
|
-
"x-api-key": this.client.apiKey,
|
|
4820
|
-
"Content-Type": "application/json"
|
|
4821
|
-
}
|
|
4822
|
-
});
|
|
4823
|
-
const userData = response.data;
|
|
4824
|
-
if (!userData || !userData.userId) {
|
|
4825
|
-
throw new KadoaSdkException("Invalid user data received");
|
|
4826
|
-
}
|
|
4827
|
-
return {
|
|
4828
|
-
userId: userData.userId,
|
|
4829
|
-
email: userData.email,
|
|
4830
|
-
featureFlags: userData.featureFlags || []
|
|
4831
|
-
};
|
|
4832
|
-
}
|
|
4833
|
-
};
|
|
4834
|
-
var debug2 = logger.extraction;
|
|
4835
|
-
var SUCCESSFUL_RUN_STATES = /* @__PURE__ */ new Set(["FINISHED", "SUCCESS"]);
|
|
4836
|
-
var DEFAULT_OPTIONS = {
|
|
4837
|
-
mode: "run",
|
|
4838
|
-
pollingInterval: 5e3,
|
|
4839
|
-
maxWaitTime: 3e5,
|
|
4840
|
-
navigationMode: "single-page",
|
|
4841
|
-
location: { type: "auto" },
|
|
4842
|
-
name: "Untitled Workflow",
|
|
4843
|
-
bypassPreview: true,
|
|
4844
|
-
autoStart: true
|
|
4845
|
-
};
|
|
4846
|
-
var ExtractionService = class {
|
|
4847
|
-
constructor(workflowsCoreService, dataFetcherService, entityResolverService, notificationSetupService) {
|
|
4848
|
-
this.workflowsCoreService = workflowsCoreService;
|
|
4849
|
-
this.dataFetcherService = dataFetcherService;
|
|
4850
|
-
this.entityResolverService = entityResolverService;
|
|
4851
|
-
this.notificationSetupService = notificationSetupService;
|
|
4556
|
+
async getNotificationSettings(workflowId) {
|
|
4557
|
+
return await this.notificationSettingsService.listSettings({ workflowId });
|
|
4852
4558
|
}
|
|
4853
|
-
/**
|
|
4854
|
-
* execute extraction workflow
|
|
4855
|
-
*/
|
|
4856
4559
|
async executeExtraction(options) {
|
|
4857
4560
|
this.validateOptions(options);
|
|
4858
4561
|
const config = merge(
|
|
@@ -4975,96 +4678,270 @@ var ExtractionService = class {
|
|
|
4975
4678
|
return runState ? SUCCESSFUL_RUN_STATES.has(runState.toUpperCase()) : false;
|
|
4976
4679
|
}
|
|
4977
4680
|
};
|
|
4978
|
-
var
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
recipients: z.array(z.email()).min(1, "Recipients are required for email channel"),
|
|
4986
|
-
from: z.email().refine(
|
|
4987
|
-
(email) => email.endsWith("@kadoa.com"),
|
|
4988
|
-
"From email address must end with @kadoa.com"
|
|
4989
|
-
).optional()
|
|
4990
|
-
});
|
|
4991
|
-
var _NotificationChannelsService = class _NotificationChannelsService {
|
|
4992
|
-
constructor(notificationsApi, userService) {
|
|
4993
|
-
this.api = notificationsApi;
|
|
4994
|
-
this.userService = userService;
|
|
4681
|
+
var debug3 = logger.extraction;
|
|
4682
|
+
var ExtractionBuilderService = class {
|
|
4683
|
+
constructor(workflowsCoreService, entityResolverService, dataFetcherService, notificationSetupService) {
|
|
4684
|
+
this.workflowsCoreService = workflowsCoreService;
|
|
4685
|
+
this.entityResolverService = entityResolverService;
|
|
4686
|
+
this.dataFetcherService = dataFetcherService;
|
|
4687
|
+
this.notificationSetupService = notificationSetupService;
|
|
4995
4688
|
}
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
if (!data) {
|
|
5000
|
-
throw KadoaHttpException.wrap(response, {
|
|
5001
|
-
message: "Failed to list channels"
|
|
5002
|
-
});
|
|
5003
|
-
}
|
|
5004
|
-
return data;
|
|
4689
|
+
get options() {
|
|
4690
|
+
assert(this._options, "Options are not set");
|
|
4691
|
+
return this._options;
|
|
5005
4692
|
}
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
* This is useful for finding workspace-level channels like WebSocket channels
|
|
5009
|
-
* that might not be associated with a specific workflow
|
|
5010
|
-
*/
|
|
5011
|
-
async listAllChannels(workflowId) {
|
|
5012
|
-
if (!workflowId) {
|
|
5013
|
-
return this.listChannels({});
|
|
5014
|
-
}
|
|
5015
|
-
const [workflowChannels, workspaceChannels] = await Promise.all([
|
|
5016
|
-
this.listChannels({ workflowId }),
|
|
5017
|
-
this.listChannels({})
|
|
5018
|
-
]);
|
|
5019
|
-
const allChannels = [...workflowChannels];
|
|
5020
|
-
workspaceChannels.forEach((channel) => {
|
|
5021
|
-
if (!allChannels.find((c) => c.id === channel.id)) {
|
|
5022
|
-
allChannels.push(channel);
|
|
5023
|
-
}
|
|
5024
|
-
});
|
|
5025
|
-
return allChannels;
|
|
4693
|
+
get notificationOptions() {
|
|
4694
|
+
return this._notificationOptions;
|
|
5026
4695
|
}
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
channelId
|
|
5030
|
-
});
|
|
5031
|
-
if (response.status !== 200) {
|
|
5032
|
-
throw KadoaHttpException.wrap(response, {
|
|
5033
|
-
message: "Failed to delete channel"
|
|
5034
|
-
});
|
|
5035
|
-
}
|
|
4696
|
+
get monitoringOptions() {
|
|
4697
|
+
return this._monitoringOptions;
|
|
5036
4698
|
}
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
4699
|
+
get workflowId() {
|
|
4700
|
+
assert(this._workflowId, "Workflow ID is not set");
|
|
4701
|
+
return this._workflowId;
|
|
4702
|
+
}
|
|
4703
|
+
get jobId() {
|
|
4704
|
+
assert(this._jobId, "Job ID is not set");
|
|
4705
|
+
return this._jobId;
|
|
4706
|
+
}
|
|
4707
|
+
extract({
|
|
4708
|
+
urls,
|
|
4709
|
+
name,
|
|
4710
|
+
description,
|
|
4711
|
+
navigationMode,
|
|
4712
|
+
extraction
|
|
4713
|
+
}) {
|
|
4714
|
+
let entity = "ai-detection";
|
|
4715
|
+
if (extraction) {
|
|
4716
|
+
const result = extraction(new SchemaBuilder());
|
|
4717
|
+
if ("schemaId" in result) {
|
|
4718
|
+
entity = { schemaId: result.schemaId };
|
|
4719
|
+
} else {
|
|
4720
|
+
const builtSchema = result.build();
|
|
4721
|
+
entity = { name: builtSchema.entityName, fields: builtSchema.fields };
|
|
5054
4722
|
}
|
|
5055
|
-
return data;
|
|
5056
4723
|
}
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
4724
|
+
this._options = {
|
|
4725
|
+
urls,
|
|
4726
|
+
name,
|
|
4727
|
+
description,
|
|
4728
|
+
navigationMode: navigationMode || "single-page",
|
|
4729
|
+
entity,
|
|
4730
|
+
bypassPreview: false
|
|
4731
|
+
};
|
|
4732
|
+
return this;
|
|
5060
4733
|
}
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
4734
|
+
withNotifications(options) {
|
|
4735
|
+
this._notificationOptions = options;
|
|
4736
|
+
return this;
|
|
4737
|
+
}
|
|
4738
|
+
withMonitoring(options) {
|
|
4739
|
+
this._monitoringOptions = options;
|
|
4740
|
+
return this;
|
|
4741
|
+
}
|
|
4742
|
+
bypassPreview() {
|
|
4743
|
+
assert(this._options, "Options are not set");
|
|
4744
|
+
this._options.bypassPreview = true;
|
|
4745
|
+
return this;
|
|
4746
|
+
}
|
|
4747
|
+
setInterval(options) {
|
|
4748
|
+
assert(this._options, "Options are not set");
|
|
4749
|
+
if ("interval" in options) {
|
|
4750
|
+
this._options.interval = options.interval;
|
|
4751
|
+
} else {
|
|
4752
|
+
this._options.interval = "CUSTOM";
|
|
4753
|
+
this._options.schedules = options.schedules;
|
|
4754
|
+
}
|
|
4755
|
+
return this;
|
|
4756
|
+
}
|
|
4757
|
+
setLocation(options) {
|
|
4758
|
+
assert(this._options, "Options are not set");
|
|
4759
|
+
this._options.location = options;
|
|
4760
|
+
return this;
|
|
4761
|
+
}
|
|
4762
|
+
async create() {
|
|
4763
|
+
assert(this._options, "Options are not set");
|
|
4764
|
+
const { urls, name, description, navigationMode, entity } = this.options;
|
|
4765
|
+
const resolvedEntity = typeof entity === "object" && "schemaId" in entity ? void 0 : await this.entityResolverService.resolveEntity(entity, {
|
|
4766
|
+
link: urls[0],
|
|
4767
|
+
location: this._options.location,
|
|
4768
|
+
navigationMode
|
|
4769
|
+
});
|
|
4770
|
+
if (!resolvedEntity) {
|
|
4771
|
+
throw new KadoaSdkException(ERROR_MESSAGES.ENTITY_FETCH_FAILED, {
|
|
4772
|
+
code: "VALIDATION_ERROR",
|
|
4773
|
+
details: { entity }
|
|
4774
|
+
});
|
|
4775
|
+
}
|
|
4776
|
+
const workflow = await this.workflowsCoreService.create({
|
|
4777
|
+
urls,
|
|
4778
|
+
name,
|
|
4779
|
+
description,
|
|
4780
|
+
navigationMode,
|
|
4781
|
+
monitoring: this._monitoringOptions,
|
|
4782
|
+
schemaId: typeof entity === "object" && "schemaId" in entity ? entity.schemaId : void 0,
|
|
4783
|
+
entity: resolvedEntity.entity,
|
|
4784
|
+
fields: resolvedEntity.fields,
|
|
4785
|
+
autoStart: false,
|
|
4786
|
+
interval: this._options.interval,
|
|
4787
|
+
schedules: this._options.schedules
|
|
4788
|
+
});
|
|
4789
|
+
if (this._notificationOptions) {
|
|
4790
|
+
await this.notificationSetupService.setup({
|
|
4791
|
+
...this._notificationOptions,
|
|
4792
|
+
workflowId: workflow.id
|
|
4793
|
+
});
|
|
4794
|
+
}
|
|
4795
|
+
this._workflowId = workflow.id;
|
|
4796
|
+
return this;
|
|
4797
|
+
}
|
|
4798
|
+
async run(options) {
|
|
4799
|
+
assert(this._options, "Options are not set");
|
|
4800
|
+
assert(this._workflowId, "Workflow ID is not set");
|
|
4801
|
+
const startedJob = await this.workflowsCoreService.runWorkflow(
|
|
4802
|
+
this._workflowId,
|
|
4803
|
+
{ variables: options?.variables, limit: options?.limit }
|
|
4804
|
+
);
|
|
4805
|
+
assert(startedJob.jobId, "Job ID is not set");
|
|
4806
|
+
debug3("Job started: %O", startedJob);
|
|
4807
|
+
this._jobId = startedJob.jobId;
|
|
4808
|
+
const finishedJob = await this.workflowsCoreService.waitForJobCompletion(
|
|
4809
|
+
this._workflowId,
|
|
4810
|
+
startedJob.jobId
|
|
4811
|
+
);
|
|
4812
|
+
debug3("Job finished: %O", finishedJob);
|
|
4813
|
+
return this;
|
|
4814
|
+
}
|
|
4815
|
+
async submit(options) {
|
|
4816
|
+
assert(this._options, "Options are not set");
|
|
4817
|
+
assert(this._workflowId, "Workflow ID is not set");
|
|
4818
|
+
const submittedJob = await this.workflowsCoreService.runWorkflow(
|
|
4819
|
+
this._workflowId,
|
|
4820
|
+
{ variables: options?.variables, limit: options?.limit }
|
|
4821
|
+
);
|
|
4822
|
+
assert(submittedJob.jobId, "Job ID is not set");
|
|
4823
|
+
debug3("Job submitted: %O", submittedJob);
|
|
4824
|
+
this._jobId = submittedJob.jobId;
|
|
4825
|
+
return {
|
|
4826
|
+
workflowId: this._workflowId,
|
|
4827
|
+
jobId: this._jobId
|
|
4828
|
+
};
|
|
4829
|
+
}
|
|
4830
|
+
async fetchData(options) {
|
|
4831
|
+
assert(this._workflowId, "Workflow ID is not set");
|
|
4832
|
+
assert(this._jobId, "Job ID is not set");
|
|
4833
|
+
return this.dataFetcherService.fetchData({
|
|
4834
|
+
workflowId: this._workflowId,
|
|
4835
|
+
runId: this._jobId,
|
|
4836
|
+
page: options.page ?? 1,
|
|
4837
|
+
limit: options.limit ?? 100,
|
|
4838
|
+
...options
|
|
4839
|
+
});
|
|
4840
|
+
}
|
|
4841
|
+
async fetchAllData(options) {
|
|
4842
|
+
assert(this._jobId, "Job ID is not set");
|
|
4843
|
+
assert(this._workflowId, "Workflow ID is not set");
|
|
4844
|
+
return this.dataFetcherService.fetchAllData({
|
|
4845
|
+
workflowId: this._workflowId,
|
|
4846
|
+
runId: this._jobId,
|
|
4847
|
+
...options
|
|
4848
|
+
});
|
|
4849
|
+
}
|
|
4850
|
+
};
|
|
4851
|
+
|
|
4852
|
+
// src/domains/notifications/notifications.acl.ts
|
|
4853
|
+
var NotificationChannelType = {
|
|
4854
|
+
EMAIL: "EMAIL",
|
|
4855
|
+
SLACK: "SLACK",
|
|
4856
|
+
WEBHOOK: "WEBHOOK",
|
|
4857
|
+
WEBSOCKET: "WEBSOCKET"
|
|
4858
|
+
};
|
|
4859
|
+
|
|
4860
|
+
// src/domains/notifications/notification-channels.service.ts
|
|
4861
|
+
var emailChannelConfigSchema = z.object({
|
|
4862
|
+
recipients: z.array(z.email()).min(1, "Recipients are required for email channel"),
|
|
4863
|
+
from: z.email().refine(
|
|
4864
|
+
(email) => email.endsWith("@kadoa.com"),
|
|
4865
|
+
"From email address must end with @kadoa.com"
|
|
4866
|
+
).optional()
|
|
4867
|
+
});
|
|
4868
|
+
var _NotificationChannelsService = class _NotificationChannelsService {
|
|
4869
|
+
constructor(notificationsApi, userService) {
|
|
4870
|
+
this.api = notificationsApi;
|
|
4871
|
+
this.userService = userService;
|
|
4872
|
+
}
|
|
4873
|
+
async listChannels(filters) {
|
|
4874
|
+
const response = await this.api.v5NotificationsChannelsGet(filters);
|
|
4875
|
+
const data = response.data.data?.channels;
|
|
4876
|
+
if (!data) {
|
|
4877
|
+
throw KadoaHttpException.wrap(response, {
|
|
4878
|
+
message: "Failed to list channels"
|
|
4879
|
+
});
|
|
4880
|
+
}
|
|
4881
|
+
return data;
|
|
4882
|
+
}
|
|
4883
|
+
/**
|
|
4884
|
+
* List all channels (both workflow-specific and workspace-level)
|
|
4885
|
+
* This is useful for finding workspace-level channels like WebSocket channels
|
|
4886
|
+
* that might not be associated with a specific workflow
|
|
4887
|
+
*/
|
|
4888
|
+
async listAllChannels(workflowId) {
|
|
4889
|
+
if (!workflowId) {
|
|
4890
|
+
return this.listChannels({});
|
|
4891
|
+
}
|
|
4892
|
+
const [workflowChannels, workspaceChannels] = await Promise.all([
|
|
4893
|
+
this.listChannels({ workflowId }),
|
|
4894
|
+
this.listChannels({})
|
|
4895
|
+
]);
|
|
4896
|
+
const allChannels = [...workflowChannels];
|
|
4897
|
+
workspaceChannels.forEach((channel) => {
|
|
4898
|
+
if (!allChannels.find((c) => c.id === channel.id)) {
|
|
4899
|
+
allChannels.push(channel);
|
|
4900
|
+
}
|
|
4901
|
+
});
|
|
4902
|
+
return allChannels;
|
|
4903
|
+
}
|
|
4904
|
+
async deleteChannel(channelId) {
|
|
4905
|
+
const response = await this.api.v5NotificationsChannelsChannelIdDelete({
|
|
4906
|
+
channelId
|
|
4907
|
+
});
|
|
4908
|
+
if (response.status !== 200) {
|
|
4909
|
+
throw KadoaHttpException.wrap(response, {
|
|
4910
|
+
message: "Failed to delete channel"
|
|
4911
|
+
});
|
|
4912
|
+
}
|
|
4913
|
+
}
|
|
4914
|
+
async createChannel(type, config) {
|
|
4915
|
+
const payload = await this.buildPayload(
|
|
4916
|
+
merge(config || {}, {
|
|
4917
|
+
name: _NotificationChannelsService.DEFAULT_CHANNEL_NAME,
|
|
4918
|
+
channelType: type,
|
|
4919
|
+
config: {}
|
|
4920
|
+
})
|
|
4921
|
+
);
|
|
4922
|
+
const response = await this.api.v5NotificationsChannelsPost({
|
|
4923
|
+
v5NotificationsChannelsPostRequest: payload
|
|
4924
|
+
});
|
|
4925
|
+
if (response.status === 201) {
|
|
4926
|
+
const data = response.data.data?.channel;
|
|
4927
|
+
if (!data) {
|
|
4928
|
+
throw KadoaHttpException.wrap(response, {
|
|
4929
|
+
message: "Failed to create default channels"
|
|
4930
|
+
});
|
|
4931
|
+
}
|
|
4932
|
+
return data;
|
|
4933
|
+
}
|
|
4934
|
+
throw KadoaHttpException.wrap(response, {
|
|
4935
|
+
message: "Failed to create default channels"
|
|
4936
|
+
});
|
|
4937
|
+
}
|
|
4938
|
+
async buildPayload(request) {
|
|
4939
|
+
let config;
|
|
4940
|
+
switch (request.channelType) {
|
|
4941
|
+
case NotificationChannelType.EMAIL:
|
|
4942
|
+
config = await this.buildEmailChannelConfig(
|
|
4943
|
+
request.config
|
|
4944
|
+
);
|
|
5068
4945
|
break;
|
|
5069
4946
|
case NotificationChannelType.SLACK:
|
|
5070
4947
|
config = await this.buildSlackChannelConfig(
|
|
@@ -5125,7 +5002,7 @@ var _NotificationChannelsService = class _NotificationChannelsService {
|
|
|
5125
5002
|
_NotificationChannelsService.DEFAULT_CHANNEL_NAME = "default";
|
|
5126
5003
|
var NotificationChannelsService = _NotificationChannelsService;
|
|
5127
5004
|
|
|
5128
|
-
// src/
|
|
5005
|
+
// src/domains/notifications/notification-settings.service.ts
|
|
5129
5006
|
var NotificationSettingsService = class {
|
|
5130
5007
|
constructor(notificationsApi) {
|
|
5131
5008
|
this.api = notificationsApi;
|
|
@@ -5160,410 +5037,56 @@ var NotificationSettingsService = class {
|
|
|
5160
5037
|
settingsId
|
|
5161
5038
|
});
|
|
5162
5039
|
if (response.status !== 200) {
|
|
5163
|
-
throw KadoaHttpException.wrap(response, {
|
|
5164
|
-
message: "Failed to delete notification settings"
|
|
5165
|
-
});
|
|
5166
|
-
}
|
|
5167
|
-
}
|
|
5168
|
-
};
|
|
5169
|
-
|
|
5170
|
-
// src/internal/runtime/pagination/paginator.ts
|
|
5171
|
-
var PagedIterator = class {
|
|
5172
|
-
constructor(fetchPage) {
|
|
5173
|
-
this.fetchPage = fetchPage;
|
|
5174
|
-
}
|
|
5175
|
-
/**
|
|
5176
|
-
* Fetch all items across all pages
|
|
5177
|
-
* @param options Base options (page will be overridden)
|
|
5178
|
-
* @returns Array of all items
|
|
5179
|
-
*/
|
|
5180
|
-
async fetchAll(options = {}) {
|
|
5181
|
-
const allItems = [];
|
|
5182
|
-
let currentPage = 1;
|
|
5183
|
-
let hasMore = true;
|
|
5184
|
-
while (hasMore) {
|
|
5185
|
-
const result = await this.fetchPage({ ...options, page: currentPage });
|
|
5186
|
-
allItems.push(...result.data);
|
|
5187
|
-
const pagination = result.pagination;
|
|
5188
|
-
hasMore = pagination.page !== void 0 && pagination.totalPages !== void 0 && pagination.page < pagination.totalPages;
|
|
5189
|
-
currentPage++;
|
|
5190
|
-
}
|
|
5191
|
-
return allItems;
|
|
5192
|
-
}
|
|
5193
|
-
/**
|
|
5194
|
-
* Create an async iterator for pages
|
|
5195
|
-
* @param options Base options (page will be overridden)
|
|
5196
|
-
* @returns Async generator that yields pages
|
|
5197
|
-
*/
|
|
5198
|
-
async *pages(options = {}) {
|
|
5199
|
-
let currentPage = 1;
|
|
5200
|
-
let hasMore = true;
|
|
5201
|
-
while (hasMore) {
|
|
5202
|
-
const result = await this.fetchPage({ ...options, page: currentPage });
|
|
5203
|
-
yield result;
|
|
5204
|
-
const pagination = result.pagination;
|
|
5205
|
-
hasMore = pagination.page !== void 0 && pagination.totalPages !== void 0 && pagination.page < pagination.totalPages;
|
|
5206
|
-
currentPage++;
|
|
5207
|
-
}
|
|
5208
|
-
}
|
|
5209
|
-
/**
|
|
5210
|
-
* Create an async iterator for individual items
|
|
5211
|
-
* @param options Base options (page will be overridden)
|
|
5212
|
-
* @returns Async generator that yields items
|
|
5213
|
-
*/
|
|
5214
|
-
async *items(options = {}) {
|
|
5215
|
-
for await (const page of this.pages(options)) {
|
|
5216
|
-
for (const item of page.data) {
|
|
5217
|
-
yield item;
|
|
5218
|
-
}
|
|
5219
|
-
}
|
|
5220
|
-
}
|
|
5221
|
-
};
|
|
5222
|
-
|
|
5223
|
-
// src/internal/domains/extraction/services/data-fetcher.service.ts
|
|
5224
|
-
var DataFetcherService = class {
|
|
5225
|
-
constructor(workflowsApi) {
|
|
5226
|
-
this.workflowsApi = workflowsApi;
|
|
5227
|
-
this.defaultLimit = 100;
|
|
5228
|
-
}
|
|
5229
|
-
/**
|
|
5230
|
-
* Fetch a page of workflow data
|
|
5231
|
-
*/
|
|
5232
|
-
async fetchData(options) {
|
|
5233
|
-
const response = await this.workflowsApi.v4WorkflowsWorkflowIdDataGet({
|
|
5234
|
-
...options,
|
|
5235
|
-
page: options.page ?? 1,
|
|
5236
|
-
limit: options.limit ?? this.defaultLimit
|
|
5237
|
-
});
|
|
5238
|
-
const result = response.data;
|
|
5239
|
-
return result;
|
|
5240
|
-
}
|
|
5241
|
-
/**
|
|
5242
|
-
* Fetch all pages of workflow data
|
|
5243
|
-
*/
|
|
5244
|
-
async fetchAllData(options) {
|
|
5245
|
-
const iterator = new PagedIterator(
|
|
5246
|
-
(pageOptions) => this.fetchData({ ...options, ...pageOptions })
|
|
5247
|
-
);
|
|
5248
|
-
return iterator.fetchAll({ limit: options.limit ?? this.defaultLimit });
|
|
5249
|
-
}
|
|
5250
|
-
/**
|
|
5251
|
-
* Create an async iterator for paginated data fetching
|
|
5252
|
-
*/
|
|
5253
|
-
async *fetchDataPages(options) {
|
|
5254
|
-
const iterator = new PagedIterator(
|
|
5255
|
-
(pageOptions) => this.fetchData({ ...options, ...pageOptions })
|
|
5256
|
-
);
|
|
5257
|
-
for await (const page of iterator.pages({
|
|
5258
|
-
limit: options.limit ?? this.defaultLimit
|
|
5259
|
-
})) {
|
|
5260
|
-
yield page;
|
|
5261
|
-
}
|
|
5262
|
-
}
|
|
5263
|
-
};
|
|
5264
|
-
|
|
5265
|
-
// src/internal/runtime/utils/polling.ts
|
|
5266
|
-
var DEFAULT_POLLING_OPTIONS = {
|
|
5267
|
-
pollIntervalMs: 1e3,
|
|
5268
|
-
timeoutMs: 5 * 60 * 1e3
|
|
5269
|
-
};
|
|
5270
|
-
var POLLING_ERROR_CODES = {
|
|
5271
|
-
ABORTED: "ABORTED",
|
|
5272
|
-
TIMEOUT: "TIMEOUT"
|
|
5273
|
-
};
|
|
5274
|
-
async function pollUntil(pollFn, isComplete, options = {}) {
|
|
5275
|
-
const internalOptions = {
|
|
5276
|
-
...DEFAULT_POLLING_OPTIONS,
|
|
5277
|
-
...options
|
|
5278
|
-
};
|
|
5279
|
-
const pollInterval = Math.max(250, internalOptions.pollIntervalMs);
|
|
5280
|
-
const timeoutMs = internalOptions.timeoutMs;
|
|
5281
|
-
const start = Date.now();
|
|
5282
|
-
let attempts = 0;
|
|
5283
|
-
while (Date.now() - start < timeoutMs) {
|
|
5284
|
-
if (internalOptions.abortSignal?.aborted) {
|
|
5285
|
-
throw new KadoaSdkException("Polling operation was aborted", {
|
|
5286
|
-
code: POLLING_ERROR_CODES.ABORTED
|
|
5287
|
-
});
|
|
5288
|
-
}
|
|
5289
|
-
attempts++;
|
|
5290
|
-
const current = await pollFn();
|
|
5291
|
-
if (isComplete(current)) {
|
|
5292
|
-
return {
|
|
5293
|
-
result: current,
|
|
5294
|
-
attempts,
|
|
5295
|
-
duration: Date.now() - start
|
|
5296
|
-
};
|
|
5297
|
-
}
|
|
5298
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
5299
|
-
}
|
|
5300
|
-
throw new KadoaSdkException(
|
|
5301
|
-
`Polling operation timed out after ${timeoutMs}ms`,
|
|
5302
|
-
{
|
|
5303
|
-
code: POLLING_ERROR_CODES.TIMEOUT,
|
|
5304
|
-
details: {
|
|
5305
|
-
timeoutMs,
|
|
5306
|
-
attempts,
|
|
5307
|
-
duration: Date.now() - start
|
|
5308
|
-
}
|
|
5309
|
-
}
|
|
5310
|
-
);
|
|
5311
|
-
}
|
|
5312
|
-
|
|
5313
|
-
// src/internal/domains/workflows/types.ts
|
|
5314
|
-
var TERMINAL_JOB_STATES = /* @__PURE__ */ new Set([
|
|
5315
|
-
"FINISHED",
|
|
5316
|
-
"FAILED",
|
|
5317
|
-
"NOT_SUPPORTED",
|
|
5318
|
-
"FAILED_INSUFFICIENT_FUNDS"
|
|
5319
|
-
]);
|
|
5320
|
-
|
|
5321
|
-
// src/internal/domains/workflows/workflows-core.service.ts
|
|
5322
|
-
var TERMINAL_RUN_STATES = /* @__PURE__ */ new Set([
|
|
5323
|
-
"FINISHED",
|
|
5324
|
-
"SUCCESS",
|
|
5325
|
-
"FAILED",
|
|
5326
|
-
"ERROR",
|
|
5327
|
-
"STOPPED",
|
|
5328
|
-
"CANCELLED"
|
|
5329
|
-
]);
|
|
5330
|
-
var debug3 = logger.workflow;
|
|
5331
|
-
var WorkflowsCoreService = class {
|
|
5332
|
-
constructor(workflowsApi) {
|
|
5333
|
-
this.workflowsApi = workflowsApi;
|
|
5334
|
-
}
|
|
5335
|
-
async create(input) {
|
|
5336
|
-
const request = {
|
|
5337
|
-
urls: input.urls,
|
|
5338
|
-
name: input.name,
|
|
5339
|
-
schemaId: input.schemaId,
|
|
5340
|
-
description: input.description,
|
|
5341
|
-
navigationMode: input.navigationMode,
|
|
5342
|
-
entity: input.entity,
|
|
5343
|
-
fields: input.fields,
|
|
5344
|
-
bypassPreview: input.bypassPreview ?? true,
|
|
5345
|
-
tags: input.tags,
|
|
5346
|
-
interval: input.interval,
|
|
5347
|
-
monitoring: input.monitoring,
|
|
5348
|
-
location: input.location,
|
|
5349
|
-
autoStart: input.autoStart,
|
|
5350
|
-
schedules: input.schedules
|
|
5351
|
-
};
|
|
5352
|
-
const response = await this.workflowsApi.v4WorkflowsPost({
|
|
5353
|
-
createWorkflowBody: request
|
|
5354
|
-
});
|
|
5355
|
-
const workflowId = response.data?.workflowId;
|
|
5356
|
-
if (!workflowId) {
|
|
5357
|
-
throw new KadoaSdkException(ERROR_MESSAGES.NO_WORKFLOW_ID, {
|
|
5358
|
-
code: "INTERNAL_ERROR",
|
|
5359
|
-
details: {
|
|
5360
|
-
response: response.data
|
|
5361
|
-
}
|
|
5362
|
-
});
|
|
5363
|
-
}
|
|
5364
|
-
return { id: workflowId };
|
|
5365
|
-
}
|
|
5366
|
-
async get(id) {
|
|
5367
|
-
const response = await this.workflowsApi.v4WorkflowsWorkflowIdGet({
|
|
5368
|
-
workflowId: id
|
|
5369
|
-
});
|
|
5370
|
-
return response.data;
|
|
5371
|
-
}
|
|
5372
|
-
async list(filters) {
|
|
5373
|
-
const response = await this.workflowsApi.v4WorkflowsGet(filters);
|
|
5374
|
-
return response.data?.workflows ?? [];
|
|
5375
|
-
}
|
|
5376
|
-
async getByName(name) {
|
|
5377
|
-
const response = await this.workflowsApi.v4WorkflowsGet({
|
|
5378
|
-
search: name
|
|
5379
|
-
});
|
|
5380
|
-
return response.data?.workflows?.[0];
|
|
5381
|
-
}
|
|
5382
|
-
async cancel(id) {
|
|
5383
|
-
await this.workflowsApi.v4WorkflowsWorkflowIdDelete({
|
|
5384
|
-
workflowId: id
|
|
5385
|
-
});
|
|
5386
|
-
}
|
|
5387
|
-
async resume(id) {
|
|
5388
|
-
await this.workflowsApi.v4WorkflowsWorkflowIdResumePut({
|
|
5389
|
-
workflowId: id
|
|
5390
|
-
});
|
|
5391
|
-
}
|
|
5392
|
-
/**
|
|
5393
|
-
* Wait for a workflow to reach the target state or a terminal state if no target state is provided
|
|
5394
|
-
*/
|
|
5395
|
-
async wait(id, options) {
|
|
5396
|
-
let last;
|
|
5397
|
-
const result = await pollUntil(
|
|
5398
|
-
async () => {
|
|
5399
|
-
const current = await this.get(id);
|
|
5400
|
-
if (last?.state !== current.state || last?.runState !== current.runState) {
|
|
5401
|
-
debug3(
|
|
5402
|
-
"workflow %s state: [workflowState: %s, jobState: %s]",
|
|
5403
|
-
id,
|
|
5404
|
-
current.state,
|
|
5405
|
-
current.runState
|
|
5406
|
-
);
|
|
5407
|
-
}
|
|
5408
|
-
last = current;
|
|
5409
|
-
return current;
|
|
5410
|
-
},
|
|
5411
|
-
(current) => {
|
|
5412
|
-
if (options?.targetState && current.state === options.targetState) {
|
|
5413
|
-
return true;
|
|
5414
|
-
}
|
|
5415
|
-
if (current.runState && TERMINAL_RUN_STATES.has(current.runState.toUpperCase()) && current.state !== "QUEUED") {
|
|
5416
|
-
return true;
|
|
5417
|
-
}
|
|
5418
|
-
return false;
|
|
5419
|
-
},
|
|
5420
|
-
options
|
|
5421
|
-
);
|
|
5422
|
-
return result.result;
|
|
5423
|
-
}
|
|
5424
|
-
/**
|
|
5425
|
-
* Run a workflow with variables and optional limit
|
|
5426
|
-
*/
|
|
5427
|
-
async runWorkflow(workflowId, input) {
|
|
5428
|
-
const response = await this.workflowsApi.v4WorkflowsWorkflowIdRunPut({
|
|
5429
|
-
workflowId,
|
|
5430
|
-
v4WorkflowsWorkflowIdRunPutRequest: {
|
|
5431
|
-
variables: input.variables,
|
|
5432
|
-
limit: input.limit
|
|
5433
|
-
}
|
|
5434
|
-
});
|
|
5435
|
-
const jobId = response.data?.jobId;
|
|
5436
|
-
if (!jobId) {
|
|
5437
|
-
throw new KadoaSdkException(ERROR_MESSAGES.NO_WORKFLOW_ID, {
|
|
5438
|
-
code: "INTERNAL_ERROR",
|
|
5439
|
-
details: {
|
|
5440
|
-
response: response.data
|
|
5441
|
-
}
|
|
5442
|
-
});
|
|
5443
|
-
}
|
|
5444
|
-
return {
|
|
5445
|
-
jobId,
|
|
5446
|
-
message: response.data?.message,
|
|
5447
|
-
status: response.data?.status
|
|
5448
|
-
};
|
|
5449
|
-
}
|
|
5450
|
-
/**
|
|
5451
|
-
* Get job status directly without polling workflow details
|
|
5452
|
-
*/
|
|
5453
|
-
async getJobStatus(workflowId, jobId) {
|
|
5454
|
-
const response = await this.workflowsApi.v4WorkflowsWorkflowIdJobsJobIdGet({
|
|
5455
|
-
workflowId,
|
|
5456
|
-
jobId
|
|
5457
|
-
});
|
|
5458
|
-
return response.data;
|
|
5459
|
-
}
|
|
5460
|
-
/**
|
|
5461
|
-
* Wait for a job to reach the target state or a terminal state
|
|
5462
|
-
*/
|
|
5463
|
-
async waitForJobCompletion(workflowId, jobId, options) {
|
|
5464
|
-
let last;
|
|
5465
|
-
const result = await pollUntil(
|
|
5466
|
-
async () => {
|
|
5467
|
-
const current = await this.getJobStatus(workflowId, jobId);
|
|
5468
|
-
if (last?.state !== current.state) {
|
|
5469
|
-
debug3("job %s state: %s", jobId, current.state);
|
|
5470
|
-
}
|
|
5471
|
-
last = current;
|
|
5472
|
-
return current;
|
|
5473
|
-
},
|
|
5474
|
-
(current) => {
|
|
5475
|
-
if (options?.targetStatus && current.state === options.targetStatus) {
|
|
5476
|
-
return true;
|
|
5477
|
-
}
|
|
5478
|
-
if (current.state && TERMINAL_JOB_STATES.has(current.state)) {
|
|
5479
|
-
return true;
|
|
5480
|
-
}
|
|
5481
|
-
return false;
|
|
5482
|
-
},
|
|
5483
|
-
options
|
|
5484
|
-
);
|
|
5485
|
-
return result.result;
|
|
5486
|
-
}
|
|
5487
|
-
};
|
|
5488
|
-
|
|
5489
|
-
// src/internal/domains/schemas/schemas.service.ts
|
|
5490
|
-
var debug4 = logger.schemas;
|
|
5491
|
-
var SchemasService = class {
|
|
5492
|
-
constructor(client) {
|
|
5493
|
-
this.schemasApi = new SchemasApi(client.configuration);
|
|
5494
|
-
}
|
|
5495
|
-
/**
|
|
5496
|
-
* Get a schema by ID
|
|
5497
|
-
*/
|
|
5498
|
-
async getSchema(schemaId) {
|
|
5499
|
-
debug4("Fetching schema with ID: %s", schemaId);
|
|
5500
|
-
const response = await this.schemasApi.v4SchemasSchemaIdGet({
|
|
5501
|
-
schemaId
|
|
5502
|
-
});
|
|
5503
|
-
const schemaData = response.data.data;
|
|
5504
|
-
if (!schemaData) {
|
|
5505
|
-
throw new KadoaSdkException(
|
|
5506
|
-
`${ERROR_MESSAGES.SCHEMA_NOT_FOUND}: ${schemaId}`,
|
|
5507
|
-
{
|
|
5508
|
-
code: KadoaErrorCode.NOT_FOUND,
|
|
5509
|
-
details: { schemaId }
|
|
5510
|
-
}
|
|
5511
|
-
);
|
|
5040
|
+
throw KadoaHttpException.wrap(response, {
|
|
5041
|
+
message: "Failed to delete notification settings"
|
|
5042
|
+
});
|
|
5512
5043
|
}
|
|
5513
|
-
return schemaData;
|
|
5514
5044
|
}
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5045
|
+
};
|
|
5046
|
+
|
|
5047
|
+
// src/domains/notifications/notification-setup.service.ts
|
|
5048
|
+
var debug4 = logger.notifications;
|
|
5049
|
+
var NotificationSetupService = class {
|
|
5050
|
+
constructor(channelsService, settingsService) {
|
|
5051
|
+
this.channelsService = channelsService;
|
|
5052
|
+
this.settingsService = settingsService;
|
|
5521
5053
|
}
|
|
5522
5054
|
/**
|
|
5523
|
-
*
|
|
5055
|
+
* Setup notification settings for a specific workflow ensuring no duplicates exist.
|
|
5524
5056
|
*/
|
|
5525
|
-
async
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
createSchemaBody: body
|
|
5057
|
+
async setupForWorkflow(requestData) {
|
|
5058
|
+
const existingSettings = await this.settingsService.listSettings({
|
|
5059
|
+
workflowId: requestData.workflowId
|
|
5529
5060
|
});
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5061
|
+
if (existingSettings.length > 0) {
|
|
5062
|
+
throw new KadoaSdkException("Settings already exist", {
|
|
5063
|
+
code: KadoaErrorCode.BAD_REQUEST,
|
|
5064
|
+
details: {
|
|
5065
|
+
workflowId: requestData.workflowId
|
|
5066
|
+
}
|
|
5534
5067
|
});
|
|
5535
5068
|
}
|
|
5536
|
-
return this.
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
*/
|
|
5541
|
-
async updateSchema(schemaId, body) {
|
|
5542
|
-
debug4("Updating schema with ID: %s", schemaId);
|
|
5543
|
-
await this.schemasApi.v4SchemasSchemaIdPut({
|
|
5544
|
-
schemaId,
|
|
5545
|
-
updateSchemaBody: body
|
|
5069
|
+
return this.setup({
|
|
5070
|
+
workflowId: requestData.workflowId,
|
|
5071
|
+
events: requestData.events,
|
|
5072
|
+
channels: requestData.channels
|
|
5546
5073
|
});
|
|
5547
|
-
return this.getSchema(schemaId);
|
|
5548
5074
|
}
|
|
5549
5075
|
/**
|
|
5550
|
-
*
|
|
5076
|
+
* Setup notification settings at the workspace level ensuring no duplicates exist.
|
|
5551
5077
|
*/
|
|
5552
|
-
async
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5078
|
+
async setupForWorkspace(requestData) {
|
|
5079
|
+
const existingSettings = await this.settingsService.listSettings({});
|
|
5080
|
+
if (existingSettings.length > 0) {
|
|
5081
|
+
throw new KadoaSdkException("Workspace settings already exist", {
|
|
5082
|
+
code: KadoaErrorCode.BAD_REQUEST
|
|
5083
|
+
});
|
|
5084
|
+
}
|
|
5085
|
+
return this.setup({
|
|
5086
|
+
events: requestData.events,
|
|
5087
|
+
channels: requestData.channels
|
|
5556
5088
|
});
|
|
5557
5089
|
}
|
|
5558
|
-
};
|
|
5559
|
-
|
|
5560
|
-
// src/internal/domains/notifications/notification-setup.service.ts
|
|
5561
|
-
var debug5 = logger.notifications;
|
|
5562
|
-
var NotificationSetupService = class {
|
|
5563
|
-
constructor(channelsService, settingsService) {
|
|
5564
|
-
this.channelsService = channelsService;
|
|
5565
|
-
this.settingsService = settingsService;
|
|
5566
|
-
}
|
|
5567
5090
|
/**
|
|
5568
5091
|
* Complete workflow notification setup including channels and settings
|
|
5569
5092
|
*
|
|
@@ -5571,10 +5094,10 @@ var NotificationSetupService = class {
|
|
|
5571
5094
|
* @returns Array of created notification settings
|
|
5572
5095
|
*/
|
|
5573
5096
|
async setup(requestData) {
|
|
5574
|
-
requestData.workflowId ?
|
|
5097
|
+
requestData.workflowId ? debug4(
|
|
5575
5098
|
"Setting up notifications for workflow %s",
|
|
5576
5099
|
requestData.workflowId
|
|
5577
|
-
) :
|
|
5100
|
+
) : debug4("Setting up notifications for workspace");
|
|
5578
5101
|
const channels = await this.setupChannels({
|
|
5579
5102
|
workflowId: requestData.workflowId,
|
|
5580
5103
|
channels: requestData.channels || {}
|
|
@@ -5582,7 +5105,7 @@ var NotificationSetupService = class {
|
|
|
5582
5105
|
const events = requestData.events || "all";
|
|
5583
5106
|
const eventTypes = events === "all" ? await this.settingsService.listAllEvents() : events;
|
|
5584
5107
|
const channelIds = channels.map((channel) => channel.id).filter(Boolean);
|
|
5585
|
-
|
|
5108
|
+
debug4(
|
|
5586
5109
|
"Creating notification settings for workflow %s: %O",
|
|
5587
5110
|
requestData.workflowId,
|
|
5588
5111
|
{
|
|
@@ -5601,7 +5124,7 @@ var NotificationSetupService = class {
|
|
|
5601
5124
|
});
|
|
5602
5125
|
})
|
|
5603
5126
|
);
|
|
5604
|
-
|
|
5127
|
+
debug4(
|
|
5605
5128
|
requestData.workflowId ? "Successfully setup notifications for workflow %s" : "Successfully setup notifications for workspace",
|
|
5606
5129
|
requestData.workflowId
|
|
5607
5130
|
);
|
|
@@ -5683,7 +5206,7 @@ var NotificationSetupService = class {
|
|
|
5683
5206
|
(channel2) => channel2.channelType === channelType && channel2.name === NotificationChannelsService.DEFAULT_CHANNEL_NAME
|
|
5684
5207
|
);
|
|
5685
5208
|
if (existingChannel) {
|
|
5686
|
-
|
|
5209
|
+
debug4("Using existing default channel: %O", {
|
|
5687
5210
|
workflowId,
|
|
5688
5211
|
channelType,
|
|
5689
5212
|
channelId: existingChannel.id
|
|
@@ -5691,7 +5214,7 @@ var NotificationSetupService = class {
|
|
|
5691
5214
|
return existingChannel;
|
|
5692
5215
|
}
|
|
5693
5216
|
const channel = await this.channelsService.createChannel(channelType);
|
|
5694
|
-
|
|
5217
|
+
debug4("Created default channel %O", {
|
|
5695
5218
|
workflowId,
|
|
5696
5219
|
channelType,
|
|
5697
5220
|
channel
|
|
@@ -5716,7 +5239,7 @@ var NotificationSetupService = class {
|
|
|
5716
5239
|
(channel2) => channel2.channelType === channelType && (channel2.name || NotificationChannelsService.DEFAULT_CHANNEL_NAME) === channelName
|
|
5717
5240
|
);
|
|
5718
5241
|
if (existingChannel) {
|
|
5719
|
-
|
|
5242
|
+
debug4("Using existing channel: %O", {
|
|
5720
5243
|
workflowId,
|
|
5721
5244
|
channelType,
|
|
5722
5245
|
channelName,
|
|
@@ -5728,7 +5251,7 @@ var NotificationSetupService = class {
|
|
|
5728
5251
|
name: channelName,
|
|
5729
5252
|
config
|
|
5730
5253
|
});
|
|
5731
|
-
|
|
5254
|
+
debug4("Created channel with custom config %O", {
|
|
5732
5255
|
workflowId,
|
|
5733
5256
|
channelType,
|
|
5734
5257
|
channelName,
|
|
@@ -5741,7 +5264,280 @@ var NotificationSetupService = class {
|
|
|
5741
5264
|
}
|
|
5742
5265
|
};
|
|
5743
5266
|
|
|
5744
|
-
// src/
|
|
5267
|
+
// src/runtime/config/constants.ts
|
|
5268
|
+
var PUBLIC_API_URI = process.env.KADOA_PUBLIC_API_URI ?? "https://api.kadoa.com";
|
|
5269
|
+
var WSS_API_URI = process.env.KADOA_WSS_API_URI ?? "wss://realtime.kadoa.com";
|
|
5270
|
+
var REALTIME_API_URI = process.env.KADOA_REALTIME_API_URI ?? "https://realtime.kadoa.com";
|
|
5271
|
+
|
|
5272
|
+
// src/version.ts
|
|
5273
|
+
var SDK_VERSION = "0.14.1";
|
|
5274
|
+
var SDK_NAME = "kadoa-node-sdk";
|
|
5275
|
+
var SDK_LANGUAGE = "node";
|
|
5276
|
+
|
|
5277
|
+
// src/domains/realtime/realtime.ts
|
|
5278
|
+
var debug5 = logger.wss;
|
|
5279
|
+
if (typeof WebSocket === "undefined") {
|
|
5280
|
+
global.WebSocket = __require("ws");
|
|
5281
|
+
}
|
|
5282
|
+
var Realtime = class {
|
|
5283
|
+
constructor(config) {
|
|
5284
|
+
this.lastHeartbeat = Date.now();
|
|
5285
|
+
this.isConnecting = false;
|
|
5286
|
+
this.eventListeners = /* @__PURE__ */ new Set();
|
|
5287
|
+
this.connectionListeners = /* @__PURE__ */ new Set();
|
|
5288
|
+
this.errorListeners = /* @__PURE__ */ new Set();
|
|
5289
|
+
if (!config.teamApiKey.startsWith("tk-")) {
|
|
5290
|
+
throw new KadoaSdkException(
|
|
5291
|
+
"Realtime connection requires a team API key (starting with 'tk-'). Provided key does not appear to be a team API key.",
|
|
5292
|
+
{
|
|
5293
|
+
code: "AUTH_ERROR",
|
|
5294
|
+
details: { providedKeyPrefix: config.teamApiKey.substring(0, 3) }
|
|
5295
|
+
}
|
|
5296
|
+
);
|
|
5297
|
+
}
|
|
5298
|
+
this.teamApiKey = config.teamApiKey;
|
|
5299
|
+
this.heartbeatInterval = config.heartbeatInterval || 1e4;
|
|
5300
|
+
this.reconnectDelay = config.reconnectDelay || 5e3;
|
|
5301
|
+
this.missedHeartbeatsLimit = config.missedHeartbeatsLimit || 3e4;
|
|
5302
|
+
}
|
|
5303
|
+
async connect() {
|
|
5304
|
+
if (this.isConnecting) return;
|
|
5305
|
+
this.isConnecting = true;
|
|
5306
|
+
try {
|
|
5307
|
+
const response = await fetch(`${PUBLIC_API_URI}/v4/oauth2/token`, {
|
|
5308
|
+
method: "POST",
|
|
5309
|
+
headers: {
|
|
5310
|
+
"Content-Type": "application/json",
|
|
5311
|
+
"x-api-key": `${this.teamApiKey}`,
|
|
5312
|
+
"x-sdk-version": SDK_VERSION
|
|
5313
|
+
}
|
|
5314
|
+
});
|
|
5315
|
+
const { access_token, team_id } = await response.json();
|
|
5316
|
+
this.socket = new WebSocket(
|
|
5317
|
+
`${WSS_API_URI}?access_token=${access_token}`
|
|
5318
|
+
);
|
|
5319
|
+
this.socket.onopen = () => {
|
|
5320
|
+
this.isConnecting = false;
|
|
5321
|
+
this.lastHeartbeat = Date.now();
|
|
5322
|
+
if (this.socket?.readyState === WebSocket.OPEN) {
|
|
5323
|
+
this.socket.send(
|
|
5324
|
+
JSON.stringify({
|
|
5325
|
+
action: "subscribe",
|
|
5326
|
+
channel: team_id
|
|
5327
|
+
})
|
|
5328
|
+
);
|
|
5329
|
+
debug5("Connected to WebSocket");
|
|
5330
|
+
this.notifyConnectionListeners(true);
|
|
5331
|
+
}
|
|
5332
|
+
this.startHeartbeatCheck();
|
|
5333
|
+
};
|
|
5334
|
+
this.socket.onmessage = (event) => {
|
|
5335
|
+
try {
|
|
5336
|
+
const data = JSON.parse(event.data);
|
|
5337
|
+
if (data.type === "heartbeat") {
|
|
5338
|
+
this.handleHeartbeat();
|
|
5339
|
+
} else {
|
|
5340
|
+
if (data?.id) {
|
|
5341
|
+
fetch(`${REALTIME_API_URI}/api/v1/events/ack`, {
|
|
5342
|
+
method: "POST",
|
|
5343
|
+
headers: { "Content-Type": "application/json" },
|
|
5344
|
+
body: JSON.stringify({ id: data.id })
|
|
5345
|
+
});
|
|
5346
|
+
}
|
|
5347
|
+
this.notifyEventListeners(data);
|
|
5348
|
+
}
|
|
5349
|
+
} catch (err) {
|
|
5350
|
+
debug5("Failed to parse incoming message: %O", err);
|
|
5351
|
+
}
|
|
5352
|
+
};
|
|
5353
|
+
this.socket.onclose = () => {
|
|
5354
|
+
debug5("WebSocket disconnected. Attempting to reconnect...");
|
|
5355
|
+
this.isConnecting = false;
|
|
5356
|
+
this.stopHeartbeatCheck();
|
|
5357
|
+
this.notifyConnectionListeners(false, "Connection closed");
|
|
5358
|
+
setTimeout(() => this.connect(), this.reconnectDelay);
|
|
5359
|
+
};
|
|
5360
|
+
this.socket.onerror = (error) => {
|
|
5361
|
+
debug5("WebSocket error: %O", error);
|
|
5362
|
+
this.isConnecting = false;
|
|
5363
|
+
this.notifyErrorListeners(error);
|
|
5364
|
+
};
|
|
5365
|
+
} catch (err) {
|
|
5366
|
+
debug5("Failed to connect: %O", err);
|
|
5367
|
+
this.isConnecting = false;
|
|
5368
|
+
setTimeout(() => this.connect(), this.reconnectDelay);
|
|
5369
|
+
}
|
|
5370
|
+
}
|
|
5371
|
+
handleHeartbeat() {
|
|
5372
|
+
debug5("Heartbeat received");
|
|
5373
|
+
this.lastHeartbeat = Date.now();
|
|
5374
|
+
}
|
|
5375
|
+
notifyEventListeners(event) {
|
|
5376
|
+
this.eventListeners.forEach((listener) => {
|
|
5377
|
+
try {
|
|
5378
|
+
listener(event);
|
|
5379
|
+
} catch (error) {
|
|
5380
|
+
debug5("Error in event listener: %O", error);
|
|
5381
|
+
}
|
|
5382
|
+
});
|
|
5383
|
+
}
|
|
5384
|
+
notifyConnectionListeners(connected, reason) {
|
|
5385
|
+
this.connectionListeners.forEach((listener) => {
|
|
5386
|
+
try {
|
|
5387
|
+
listener(connected, reason);
|
|
5388
|
+
} catch (error) {
|
|
5389
|
+
debug5("Error in connection listener: %O", error);
|
|
5390
|
+
}
|
|
5391
|
+
});
|
|
5392
|
+
}
|
|
5393
|
+
notifyErrorListeners(error) {
|
|
5394
|
+
this.errorListeners.forEach((listener) => {
|
|
5395
|
+
try {
|
|
5396
|
+
listener(error);
|
|
5397
|
+
} catch (error2) {
|
|
5398
|
+
debug5("Error in error listener: %O", error2);
|
|
5399
|
+
}
|
|
5400
|
+
});
|
|
5401
|
+
}
|
|
5402
|
+
startHeartbeatCheck() {
|
|
5403
|
+
this.missedHeartbeatCheckTimer = setInterval(() => {
|
|
5404
|
+
if (Date.now() - this.lastHeartbeat > this.missedHeartbeatsLimit) {
|
|
5405
|
+
debug5("No heartbeat received in 30 seconds! Closing connection.");
|
|
5406
|
+
this.socket?.close();
|
|
5407
|
+
}
|
|
5408
|
+
}, this.heartbeatInterval);
|
|
5409
|
+
}
|
|
5410
|
+
stopHeartbeatCheck() {
|
|
5411
|
+
if (this.missedHeartbeatCheckTimer) {
|
|
5412
|
+
clearInterval(this.missedHeartbeatCheckTimer);
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5415
|
+
/**
|
|
5416
|
+
* Subscribe to realtime events
|
|
5417
|
+
* @param listener Function to handle incoming events
|
|
5418
|
+
* @returns Function to unsubscribe
|
|
5419
|
+
*/
|
|
5420
|
+
onEvent(listener) {
|
|
5421
|
+
this.eventListeners.add(listener);
|
|
5422
|
+
return () => {
|
|
5423
|
+
this.eventListeners.delete(listener);
|
|
5424
|
+
};
|
|
5425
|
+
}
|
|
5426
|
+
/**
|
|
5427
|
+
* Subscribe to connection state changes
|
|
5428
|
+
* @param listener Function to handle connection state changes
|
|
5429
|
+
* @returns Function to unsubscribe
|
|
5430
|
+
*/
|
|
5431
|
+
onConnection(listener) {
|
|
5432
|
+
this.connectionListeners.add(listener);
|
|
5433
|
+
return () => {
|
|
5434
|
+
this.connectionListeners.delete(listener);
|
|
5435
|
+
};
|
|
5436
|
+
}
|
|
5437
|
+
/**
|
|
5438
|
+
* Subscribe to errors
|
|
5439
|
+
* @param listener Function to handle errors
|
|
5440
|
+
* @returns Function to unsubscribe
|
|
5441
|
+
*/
|
|
5442
|
+
onError(listener) {
|
|
5443
|
+
this.errorListeners.add(listener);
|
|
5444
|
+
return () => {
|
|
5445
|
+
this.errorListeners.delete(listener);
|
|
5446
|
+
};
|
|
5447
|
+
}
|
|
5448
|
+
close() {
|
|
5449
|
+
if (this.socket) {
|
|
5450
|
+
this.stopHeartbeatCheck();
|
|
5451
|
+
this.socket.close();
|
|
5452
|
+
this.socket = void 0;
|
|
5453
|
+
}
|
|
5454
|
+
this.eventListeners.clear();
|
|
5455
|
+
this.connectionListeners.clear();
|
|
5456
|
+
this.errorListeners.clear();
|
|
5457
|
+
}
|
|
5458
|
+
isConnected() {
|
|
5459
|
+
return this.socket?.readyState === WebSocket.OPEN;
|
|
5460
|
+
}
|
|
5461
|
+
};
|
|
5462
|
+
|
|
5463
|
+
// src/domains/user/user.service.ts
|
|
5464
|
+
var UserService = class {
|
|
5465
|
+
constructor(client) {
|
|
5466
|
+
this.client = client;
|
|
5467
|
+
}
|
|
5468
|
+
/**
|
|
5469
|
+
* Get current user details
|
|
5470
|
+
* @returns User details
|
|
5471
|
+
*/
|
|
5472
|
+
async getCurrentUser() {
|
|
5473
|
+
const response = await this.client.axiosInstance.get("/v5/user", {
|
|
5474
|
+
baseURL: this.client.baseUrl,
|
|
5475
|
+
headers: {
|
|
5476
|
+
"x-api-key": this.client.apiKey,
|
|
5477
|
+
"Content-Type": "application/json"
|
|
5478
|
+
}
|
|
5479
|
+
});
|
|
5480
|
+
const userData = response.data;
|
|
5481
|
+
if (!userData || !userData.userId) {
|
|
5482
|
+
throw new KadoaSdkException("Invalid user data received");
|
|
5483
|
+
}
|
|
5484
|
+
return {
|
|
5485
|
+
userId: userData.userId,
|
|
5486
|
+
email: userData.email,
|
|
5487
|
+
featureFlags: userData.featureFlags || []
|
|
5488
|
+
};
|
|
5489
|
+
}
|
|
5490
|
+
};
|
|
5491
|
+
|
|
5492
|
+
// src/runtime/utils/polling.ts
|
|
5493
|
+
var DEFAULT_POLLING_OPTIONS = {
|
|
5494
|
+
pollIntervalMs: 1e3,
|
|
5495
|
+
timeoutMs: 5 * 60 * 1e3
|
|
5496
|
+
};
|
|
5497
|
+
var POLLING_ERROR_CODES = {
|
|
5498
|
+
ABORTED: "ABORTED",
|
|
5499
|
+
TIMEOUT: "TIMEOUT"
|
|
5500
|
+
};
|
|
5501
|
+
async function pollUntil(pollFn, isComplete, options = {}) {
|
|
5502
|
+
const internalOptions = {
|
|
5503
|
+
...DEFAULT_POLLING_OPTIONS,
|
|
5504
|
+
...options
|
|
5505
|
+
};
|
|
5506
|
+
const pollInterval = Math.max(250, internalOptions.pollIntervalMs);
|
|
5507
|
+
const timeoutMs = internalOptions.timeoutMs;
|
|
5508
|
+
const start = Date.now();
|
|
5509
|
+
let attempts = 0;
|
|
5510
|
+
while (Date.now() - start < timeoutMs) {
|
|
5511
|
+
if (internalOptions.abortSignal?.aborted) {
|
|
5512
|
+
throw new KadoaSdkException("Polling operation was aborted", {
|
|
5513
|
+
code: POLLING_ERROR_CODES.ABORTED
|
|
5514
|
+
});
|
|
5515
|
+
}
|
|
5516
|
+
attempts++;
|
|
5517
|
+
const current = await pollFn();
|
|
5518
|
+
if (isComplete(current)) {
|
|
5519
|
+
return {
|
|
5520
|
+
result: current,
|
|
5521
|
+
attempts,
|
|
5522
|
+
duration: Date.now() - start
|
|
5523
|
+
};
|
|
5524
|
+
}
|
|
5525
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
5526
|
+
}
|
|
5527
|
+
throw new KadoaSdkException(
|
|
5528
|
+
`Polling operation timed out after ${timeoutMs}ms`,
|
|
5529
|
+
{
|
|
5530
|
+
code: POLLING_ERROR_CODES.TIMEOUT,
|
|
5531
|
+
details: {
|
|
5532
|
+
timeoutMs,
|
|
5533
|
+
attempts,
|
|
5534
|
+
duration: Date.now() - start
|
|
5535
|
+
}
|
|
5536
|
+
}
|
|
5537
|
+
);
|
|
5538
|
+
}
|
|
5539
|
+
|
|
5540
|
+
// src/domains/validation/validation-core.service.ts
|
|
5745
5541
|
var ValidationCoreService = class {
|
|
5746
5542
|
constructor(client) {
|
|
5747
5543
|
this.validationApi = new DataValidationApi(
|
|
@@ -5815,7 +5611,7 @@ var ValidationCoreService = class {
|
|
|
5815
5611
|
}
|
|
5816
5612
|
);
|
|
5817
5613
|
}
|
|
5818
|
-
if (response.status !== 200 || response.data
|
|
5614
|
+
if (response.status !== 200 || response.data?.error) {
|
|
5819
5615
|
throw KadoaHttpException.wrap(response.data, {
|
|
5820
5616
|
message: "Failed to get latest validation"
|
|
5821
5617
|
});
|
|
@@ -5974,292 +5770,222 @@ var ValidationRulesService = class {
|
|
|
5974
5770
|
bulkDeleteRules: data
|
|
5975
5771
|
});
|
|
5976
5772
|
if (response.status !== 200 || response.data.error) {
|
|
5977
|
-
throw KadoaHttpException.wrap(response.data.data, {
|
|
5978
|
-
message: response.data.message || "Failed to bulk delete validation rules"
|
|
5979
|
-
});
|
|
5980
|
-
}
|
|
5981
|
-
return response.data.data;
|
|
5982
|
-
}
|
|
5983
|
-
async deleteAllRules(data) {
|
|
5984
|
-
const response = await this.validationApi.v4DataValidationRulesActionsDeleteAllDelete({
|
|
5985
|
-
deleteRuleWithReason: data
|
|
5986
|
-
});
|
|
5987
|
-
if (response.status !== 200 || response.data.error) {
|
|
5988
|
-
throw KadoaHttpException.wrap(response.data.data, {
|
|
5989
|
-
message: response.data.message || "Failed to delete all validation rules"
|
|
5990
|
-
});
|
|
5991
|
-
}
|
|
5992
|
-
return response.data.data;
|
|
5993
|
-
}
|
|
5994
|
-
};
|
|
5995
|
-
|
|
5996
|
-
// src/internal/domains/extraction/services/entity-resolver.service.ts
|
|
5997
|
-
var ENTITY_API_ENDPOINT = "/v4/entity";
|
|
5998
|
-
var EntityResolverService = class {
|
|
5999
|
-
constructor(client) {
|
|
6000
|
-
this.client = client;
|
|
6001
|
-
this.schemasService = new SchemasService(client);
|
|
6002
|
-
}
|
|
6003
|
-
/**
|
|
6004
|
-
* Resolves entity and fields from the provided entity configuration
|
|
6005
|
-
*
|
|
6006
|
-
* @param entityConfig The entity configuration to resolve
|
|
6007
|
-
* @param options Additional options for AI detection
|
|
6008
|
-
* @returns Resolved entity with fields
|
|
6009
|
-
*/
|
|
6010
|
-
async resolveEntity(entityConfig, options) {
|
|
6011
|
-
if (entityConfig === "ai-detection") {
|
|
6012
|
-
if (!options?.link) {
|
|
6013
|
-
throw new KadoaSdkException(ERROR_MESSAGES.LINK_REQUIRED, {
|
|
6014
|
-
code: "VALIDATION_ERROR",
|
|
6015
|
-
details: { entityConfig, options }
|
|
6016
|
-
});
|
|
6017
|
-
}
|
|
6018
|
-
const entityPrediction = await this.fetchEntityFields({
|
|
6019
|
-
link: options.link,
|
|
6020
|
-
location: options.location,
|
|
6021
|
-
navigationMode: options.navigationMode
|
|
6022
|
-
});
|
|
6023
|
-
return {
|
|
6024
|
-
entity: entityPrediction.entity,
|
|
6025
|
-
fields: entityPrediction.fields
|
|
6026
|
-
};
|
|
6027
|
-
} else if (entityConfig) {
|
|
6028
|
-
if ("schemaId" in entityConfig) {
|
|
6029
|
-
const schema = await this.schemasService.getSchema(
|
|
6030
|
-
entityConfig.schemaId
|
|
6031
|
-
);
|
|
6032
|
-
return {
|
|
6033
|
-
entity: schema.entity ?? "",
|
|
6034
|
-
fields: schema.schema
|
|
6035
|
-
};
|
|
6036
|
-
} else if ("name" in entityConfig && "fields" in entityConfig) {
|
|
6037
|
-
return {
|
|
6038
|
-
entity: entityConfig.name,
|
|
6039
|
-
fields: entityConfig.fields
|
|
6040
|
-
};
|
|
6041
|
-
}
|
|
6042
|
-
}
|
|
6043
|
-
throw new KadoaSdkException(ERROR_MESSAGES.ENTITY_INVARIANT_VIOLATION, {
|
|
6044
|
-
details: {
|
|
6045
|
-
entity: entityConfig
|
|
6046
|
-
}
|
|
6047
|
-
});
|
|
6048
|
-
}
|
|
6049
|
-
/**
|
|
6050
|
-
* Fetches entity fields dynamically from the /v4/entity endpoint.
|
|
6051
|
-
* This is a workaround implementation using native fetch since the endpoint
|
|
6052
|
-
* is not yet included in the OpenAPI specification.
|
|
6053
|
-
*
|
|
6054
|
-
* @param options Request options including the link to analyze
|
|
6055
|
-
* @returns EntityPrediction containing the detected entity type and fields
|
|
6056
|
-
*/
|
|
6057
|
-
async fetchEntityFields(options) {
|
|
6058
|
-
this.validateEntityOptions(options);
|
|
6059
|
-
const url = `${this.client.baseUrl}${ENTITY_API_ENDPOINT}`;
|
|
6060
|
-
const requestBody = options;
|
|
6061
|
-
const response = await this.client.axiosInstance.post(url, requestBody, {
|
|
6062
|
-
headers: {
|
|
6063
|
-
"Content-Type": "application/json",
|
|
6064
|
-
Accept: "application/json",
|
|
6065
|
-
"x-api-key": this.client.apiKey
|
|
6066
|
-
}
|
|
6067
|
-
});
|
|
6068
|
-
const data = response.data;
|
|
6069
|
-
if (!data.success || !data.entityPrediction || data.entityPrediction.length === 0) {
|
|
6070
|
-
throw new KadoaSdkException(ERROR_MESSAGES.NO_PREDICTIONS, {
|
|
6071
|
-
code: "NOT_FOUND",
|
|
6072
|
-
details: {
|
|
6073
|
-
success: data.success,
|
|
6074
|
-
hasPredictions: !!data.entityPrediction,
|
|
6075
|
-
predictionCount: data.entityPrediction?.length || 0,
|
|
6076
|
-
link: options.link
|
|
6077
|
-
}
|
|
6078
|
-
});
|
|
6079
|
-
}
|
|
6080
|
-
return data.entityPrediction[0];
|
|
6081
|
-
}
|
|
6082
|
-
/**
|
|
6083
|
-
* Validates entity request options
|
|
6084
|
-
*/
|
|
6085
|
-
validateEntityOptions(options) {
|
|
6086
|
-
if (!options.link) {
|
|
6087
|
-
throw new KadoaSdkException(ERROR_MESSAGES.LINK_REQUIRED, {
|
|
6088
|
-
code: "VALIDATION_ERROR",
|
|
6089
|
-
details: { options }
|
|
6090
|
-
});
|
|
6091
|
-
}
|
|
6092
|
-
}
|
|
6093
|
-
};
|
|
6094
|
-
var debug7 = logger.extraction;
|
|
6095
|
-
var ExtractionBuilderService = class {
|
|
6096
|
-
constructor(workflowsCoreService, entityResolverService, dataFetcherService, notificationSetupService) {
|
|
6097
|
-
this.workflowsCoreService = workflowsCoreService;
|
|
6098
|
-
this.entityResolverService = entityResolverService;
|
|
6099
|
-
this.dataFetcherService = dataFetcherService;
|
|
6100
|
-
this.notificationSetupService = notificationSetupService;
|
|
6101
|
-
}
|
|
6102
|
-
get options() {
|
|
6103
|
-
assert(this._options, "Options are not set");
|
|
6104
|
-
return this._options;
|
|
6105
|
-
}
|
|
6106
|
-
get notificationOptions() {
|
|
6107
|
-
return this._notificationOptions;
|
|
6108
|
-
}
|
|
6109
|
-
get monitoringOptions() {
|
|
6110
|
-
return this._monitoringOptions;
|
|
6111
|
-
}
|
|
6112
|
-
get workflowId() {
|
|
6113
|
-
assert(this._workflowId, "Workflow ID is not set");
|
|
6114
|
-
return this._workflowId;
|
|
6115
|
-
}
|
|
6116
|
-
get jobId() {
|
|
6117
|
-
assert(this._jobId, "Job ID is not set");
|
|
6118
|
-
return this._jobId;
|
|
6119
|
-
}
|
|
6120
|
-
extract({
|
|
6121
|
-
urls,
|
|
6122
|
-
name,
|
|
6123
|
-
description,
|
|
6124
|
-
navigationMode,
|
|
6125
|
-
extraction
|
|
6126
|
-
}) {
|
|
6127
|
-
let entity = "ai-detection";
|
|
6128
|
-
if (extraction) {
|
|
6129
|
-
const result = extraction(new SchemaBuilder());
|
|
6130
|
-
if ("schemaId" in result) {
|
|
6131
|
-
entity = { schemaId: result.schemaId };
|
|
6132
|
-
} else {
|
|
6133
|
-
const builtSchema = result.build();
|
|
6134
|
-
entity = { name: builtSchema.entityName, fields: builtSchema.fields };
|
|
6135
|
-
}
|
|
6136
|
-
}
|
|
6137
|
-
this._options = {
|
|
6138
|
-
urls,
|
|
6139
|
-
name,
|
|
6140
|
-
description,
|
|
6141
|
-
navigationMode: navigationMode || "single-page",
|
|
6142
|
-
entity,
|
|
6143
|
-
bypassPreview: false
|
|
6144
|
-
};
|
|
6145
|
-
return this;
|
|
6146
|
-
}
|
|
6147
|
-
withNotifications(options) {
|
|
6148
|
-
this._notificationOptions = options;
|
|
6149
|
-
return this;
|
|
6150
|
-
}
|
|
6151
|
-
withMonitoring(options) {
|
|
6152
|
-
this._monitoringOptions = options;
|
|
6153
|
-
return this;
|
|
6154
|
-
}
|
|
6155
|
-
bypassPreview() {
|
|
6156
|
-
assert(this._options, "Options are not set");
|
|
6157
|
-
this._options.bypassPreview = true;
|
|
6158
|
-
return this;
|
|
6159
|
-
}
|
|
6160
|
-
setInterval(options) {
|
|
6161
|
-
assert(this._options, "Options are not set");
|
|
6162
|
-
if ("interval" in options) {
|
|
6163
|
-
this._options.interval = options.interval;
|
|
6164
|
-
} else {
|
|
6165
|
-
this._options.interval = "CUSTOM";
|
|
6166
|
-
this._options.schedules = options.schedules;
|
|
5773
|
+
throw KadoaHttpException.wrap(response.data.data, {
|
|
5774
|
+
message: response.data.message || "Failed to bulk delete validation rules"
|
|
5775
|
+
});
|
|
6167
5776
|
}
|
|
6168
|
-
return
|
|
6169
|
-
}
|
|
6170
|
-
setLocation(options) {
|
|
6171
|
-
assert(this._options, "Options are not set");
|
|
6172
|
-
this._options.location = options;
|
|
6173
|
-
return this;
|
|
5777
|
+
return response.data.data;
|
|
6174
5778
|
}
|
|
6175
|
-
async
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
const resolvedEntity = typeof entity === "object" && "schemaId" in entity ? void 0 : await this.entityResolverService.resolveEntity(entity, {
|
|
6179
|
-
link: urls[0],
|
|
6180
|
-
location: this._options.location,
|
|
6181
|
-
navigationMode
|
|
5779
|
+
async deleteAllRules(data) {
|
|
5780
|
+
const response = await this.validationApi.v4DataValidationRulesActionsDeleteAllDelete({
|
|
5781
|
+
deleteRuleWithReason: data
|
|
6182
5782
|
});
|
|
6183
|
-
if (
|
|
6184
|
-
throw
|
|
6185
|
-
|
|
6186
|
-
details: { entity }
|
|
5783
|
+
if (response.status !== 200 || response.data.error) {
|
|
5784
|
+
throw KadoaHttpException.wrap(response.data.data, {
|
|
5785
|
+
message: response.data.message || "Failed to delete all validation rules"
|
|
6187
5786
|
});
|
|
6188
5787
|
}
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
5788
|
+
return response.data.data;
|
|
5789
|
+
}
|
|
5790
|
+
};
|
|
5791
|
+
|
|
5792
|
+
// src/domains/workflows/workflows.acl.ts
|
|
5793
|
+
var JobStateEnum = {
|
|
5794
|
+
Finished: "FINISHED",
|
|
5795
|
+
Failed: "FAILED",
|
|
5796
|
+
NotSupported: "NOT_SUPPORTED",
|
|
5797
|
+
FailedInsufficientFunds: "FAILED_INSUFFICIENT_FUNDS"
|
|
5798
|
+
};
|
|
5799
|
+
|
|
5800
|
+
// src/domains/workflows/workflows-core.service.ts
|
|
5801
|
+
var TERMINAL_JOB_STATES = /* @__PURE__ */ new Set([
|
|
5802
|
+
JobStateEnum.Finished,
|
|
5803
|
+
JobStateEnum.Failed,
|
|
5804
|
+
JobStateEnum.NotSupported,
|
|
5805
|
+
JobStateEnum.FailedInsufficientFunds
|
|
5806
|
+
]);
|
|
5807
|
+
var TERMINAL_RUN_STATES = /* @__PURE__ */ new Set([
|
|
5808
|
+
"FINISHED",
|
|
5809
|
+
"SUCCESS",
|
|
5810
|
+
"FAILED",
|
|
5811
|
+
"ERROR",
|
|
5812
|
+
"STOPPED",
|
|
5813
|
+
"CANCELLED"
|
|
5814
|
+
]);
|
|
5815
|
+
var debug6 = logger.workflow;
|
|
5816
|
+
var WorkflowsCoreService = class {
|
|
5817
|
+
constructor(workflowsApi) {
|
|
5818
|
+
this.workflowsApi = workflowsApi;
|
|
5819
|
+
}
|
|
5820
|
+
async create(input) {
|
|
5821
|
+
const request = {
|
|
5822
|
+
urls: input.urls,
|
|
5823
|
+
name: input.name,
|
|
5824
|
+
schemaId: input.schemaId,
|
|
5825
|
+
description: input.description,
|
|
5826
|
+
navigationMode: input.navigationMode,
|
|
5827
|
+
entity: input.entity,
|
|
5828
|
+
fields: input.fields,
|
|
5829
|
+
bypassPreview: input.bypassPreview ?? true,
|
|
5830
|
+
tags: input.tags,
|
|
5831
|
+
interval: input.interval,
|
|
5832
|
+
monitoring: input.monitoring,
|
|
5833
|
+
location: input.location,
|
|
5834
|
+
autoStart: input.autoStart,
|
|
5835
|
+
schedules: input.schedules
|
|
5836
|
+
};
|
|
5837
|
+
const response = await this.workflowsApi.v4WorkflowsPost({
|
|
5838
|
+
createWorkflowBody: request
|
|
6201
5839
|
});
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
5840
|
+
const workflowId = response.data?.workflowId;
|
|
5841
|
+
if (!workflowId) {
|
|
5842
|
+
throw new KadoaSdkException(ERROR_MESSAGES.NO_WORKFLOW_ID, {
|
|
5843
|
+
code: "INTERNAL_ERROR",
|
|
5844
|
+
details: {
|
|
5845
|
+
response: response.data
|
|
5846
|
+
}
|
|
6206
5847
|
});
|
|
6207
5848
|
}
|
|
6208
|
-
|
|
6209
|
-
return this;
|
|
5849
|
+
return { id: workflowId };
|
|
6210
5850
|
}
|
|
6211
|
-
async
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
{ variables: options?.variables, limit: options?.limit }
|
|
6217
|
-
);
|
|
6218
|
-
debug7("Job started: %O", startedJob);
|
|
6219
|
-
this._jobId = startedJob.jobId;
|
|
6220
|
-
const finishedJob = await this.workflowsCoreService.waitForJobCompletion(
|
|
6221
|
-
this._workflowId,
|
|
6222
|
-
startedJob.jobId
|
|
6223
|
-
);
|
|
6224
|
-
debug7("Job finished: %O", finishedJob);
|
|
6225
|
-
return this;
|
|
5851
|
+
async get(id) {
|
|
5852
|
+
const response = await this.workflowsApi.v4WorkflowsWorkflowIdGet({
|
|
5853
|
+
workflowId: id
|
|
5854
|
+
});
|
|
5855
|
+
return response.data;
|
|
6226
5856
|
}
|
|
6227
|
-
async
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
5857
|
+
async list(filters) {
|
|
5858
|
+
const response = await this.workflowsApi.v4WorkflowsGet(filters);
|
|
5859
|
+
return response.data?.workflows ?? [];
|
|
5860
|
+
}
|
|
5861
|
+
async getByName(name) {
|
|
5862
|
+
const response = await this.workflowsApi.v4WorkflowsGet({
|
|
5863
|
+
search: name
|
|
5864
|
+
});
|
|
5865
|
+
return response.data?.workflows?.[0];
|
|
5866
|
+
}
|
|
5867
|
+
async cancel(id) {
|
|
5868
|
+
await this.workflowsApi.v4WorkflowsWorkflowIdDelete({
|
|
5869
|
+
workflowId: id
|
|
5870
|
+
});
|
|
5871
|
+
}
|
|
5872
|
+
async resume(id) {
|
|
5873
|
+
await this.workflowsApi.v4WorkflowsWorkflowIdResumePut({
|
|
5874
|
+
workflowId: id
|
|
5875
|
+
});
|
|
5876
|
+
}
|
|
5877
|
+
/**
|
|
5878
|
+
* Wait for a workflow to reach the target state or a terminal state if no target state is provided
|
|
5879
|
+
*/
|
|
5880
|
+
async wait(id, options) {
|
|
5881
|
+
let last;
|
|
5882
|
+
const result = await pollUntil(
|
|
5883
|
+
async () => {
|
|
5884
|
+
const current = await this.get(id);
|
|
5885
|
+
if (last?.state !== current.state || last?.runState !== current.runState) {
|
|
5886
|
+
debug6(
|
|
5887
|
+
"workflow %s state: [workflowState: %s, jobState: %s]",
|
|
5888
|
+
id,
|
|
5889
|
+
current.state,
|
|
5890
|
+
current.runState
|
|
5891
|
+
);
|
|
5892
|
+
}
|
|
5893
|
+
last = current;
|
|
5894
|
+
return current;
|
|
5895
|
+
},
|
|
5896
|
+
(current) => {
|
|
5897
|
+
if (options?.targetState && current.state === options.targetState) {
|
|
5898
|
+
return true;
|
|
5899
|
+
}
|
|
5900
|
+
if (current.runState && TERMINAL_RUN_STATES.has(current.runState.toUpperCase()) && current.state !== "QUEUED") {
|
|
5901
|
+
return true;
|
|
5902
|
+
}
|
|
5903
|
+
return false;
|
|
5904
|
+
},
|
|
5905
|
+
options
|
|
6233
5906
|
);
|
|
6234
|
-
|
|
6235
|
-
|
|
5907
|
+
return result.result;
|
|
5908
|
+
}
|
|
5909
|
+
/**
|
|
5910
|
+
* Run a workflow with variables and optional limit
|
|
5911
|
+
*/
|
|
5912
|
+
async runWorkflow(workflowId, input) {
|
|
5913
|
+
const response = await this.workflowsApi.v4WorkflowsWorkflowIdRunPut({
|
|
5914
|
+
workflowId,
|
|
5915
|
+
v4WorkflowsWorkflowIdRunPutRequest: {
|
|
5916
|
+
variables: input.variables,
|
|
5917
|
+
limit: input.limit
|
|
5918
|
+
}
|
|
5919
|
+
});
|
|
5920
|
+
const jobId = response.data?.jobId;
|
|
5921
|
+
if (!jobId) {
|
|
5922
|
+
throw new KadoaSdkException(ERROR_MESSAGES.NO_WORKFLOW_ID, {
|
|
5923
|
+
code: "INTERNAL_ERROR",
|
|
5924
|
+
details: {
|
|
5925
|
+
response: response.data
|
|
5926
|
+
}
|
|
5927
|
+
});
|
|
5928
|
+
}
|
|
6236
5929
|
return {
|
|
6237
|
-
|
|
6238
|
-
|
|
5930
|
+
jobId,
|
|
5931
|
+
message: response.data?.message,
|
|
5932
|
+
status: response.data?.status
|
|
6239
5933
|
};
|
|
6240
5934
|
}
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
limit: options.limit ?? 100,
|
|
6249
|
-
...options
|
|
5935
|
+
/**
|
|
5936
|
+
* Get job status directly without polling workflow details
|
|
5937
|
+
*/
|
|
5938
|
+
async getJobStatus(workflowId, jobId) {
|
|
5939
|
+
const response = await this.workflowsApi.v4WorkflowsWorkflowIdJobsJobIdGet({
|
|
5940
|
+
workflowId,
|
|
5941
|
+
jobId
|
|
6250
5942
|
});
|
|
5943
|
+
return response.data;
|
|
6251
5944
|
}
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
5945
|
+
/**
|
|
5946
|
+
* Wait for a job to reach the target state or a terminal state
|
|
5947
|
+
*/
|
|
5948
|
+
async waitForJobCompletion(workflowId, jobId, options) {
|
|
5949
|
+
let last;
|
|
5950
|
+
const result = await pollUntil(
|
|
5951
|
+
async () => {
|
|
5952
|
+
const current = await this.getJobStatus(workflowId, jobId);
|
|
5953
|
+
if (last?.state !== current.state) {
|
|
5954
|
+
debug6("job %s state: %s", jobId, current.state);
|
|
5955
|
+
}
|
|
5956
|
+
last = current;
|
|
5957
|
+
return current;
|
|
5958
|
+
},
|
|
5959
|
+
(current) => {
|
|
5960
|
+
if (options?.targetStatus && current.state === options.targetStatus) {
|
|
5961
|
+
return true;
|
|
5962
|
+
}
|
|
5963
|
+
if (current.state && TERMINAL_JOB_STATES.has(current.state)) {
|
|
5964
|
+
return true;
|
|
5965
|
+
}
|
|
5966
|
+
return false;
|
|
5967
|
+
},
|
|
5968
|
+
options
|
|
5969
|
+
);
|
|
5970
|
+
return result.result;
|
|
6260
5971
|
}
|
|
6261
5972
|
};
|
|
6262
5973
|
|
|
5974
|
+
// src/domains/validation/validation.facade.ts
|
|
5975
|
+
function createValidationDomain(core, rules) {
|
|
5976
|
+
return {
|
|
5977
|
+
rules,
|
|
5978
|
+
schedule: (workflowId, jobId) => core.scheduleValidation(workflowId, jobId),
|
|
5979
|
+
listWorkflowValidations: (filters) => core.listWorkflowValidations(filters),
|
|
5980
|
+
getValidationDetails: (validationId) => core.getValidationDetails(validationId),
|
|
5981
|
+
toggleEnabled: (workflowId) => core.toggleValidationEnabled(workflowId),
|
|
5982
|
+
getLatest: (workflowId, jobId) => core.getLatestValidation(workflowId, jobId),
|
|
5983
|
+
getAnomalies: (validationId) => core.getValidationAnomalies(validationId),
|
|
5984
|
+
getAnomaliesByRule: (validationId, ruleName) => core.getValidationAnomaliesByRule(validationId, ruleName),
|
|
5985
|
+
waitUntilCompleted: (validationId, options) => core.waitUntilCompleted(validationId, options)
|
|
5986
|
+
};
|
|
5987
|
+
}
|
|
5988
|
+
|
|
6263
5989
|
// src/kadoa-client.ts
|
|
6264
5990
|
var KadoaClient = class {
|
|
6265
5991
|
constructor(config) {
|
|
@@ -6336,7 +6062,9 @@ var KadoaClient = class {
|
|
|
6336
6062
|
workflowsCoreService,
|
|
6337
6063
|
dataFetcherService,
|
|
6338
6064
|
entityResolverService,
|
|
6339
|
-
channelSetupService
|
|
6065
|
+
channelSetupService,
|
|
6066
|
+
channelsService,
|
|
6067
|
+
settingsService
|
|
6340
6068
|
);
|
|
6341
6069
|
this._extractionBuilderService = new ExtractionBuilderService(
|
|
6342
6070
|
workflowsCoreService,
|
|
@@ -6344,22 +6072,19 @@ var KadoaClient = class {
|
|
|
6344
6072
|
dataFetcherService,
|
|
6345
6073
|
channelSetupService
|
|
6346
6074
|
);
|
|
6347
|
-
this.user =
|
|
6348
|
-
this.extraction =
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
channelSetupService
|
|
6361
|
-
);
|
|
6362
|
-
this.validation = new ValidationModule(coreService, rulesService);
|
|
6075
|
+
this.user = userService;
|
|
6076
|
+
this.extraction = extractionService;
|
|
6077
|
+
this.workflow = workflowsCoreService;
|
|
6078
|
+
this.schema = schemasService;
|
|
6079
|
+
this.notification = {
|
|
6080
|
+
channels: channelsService,
|
|
6081
|
+
settings: settingsService,
|
|
6082
|
+
setup: channelSetupService,
|
|
6083
|
+
configure: (options) => channelSetupService.setup(options),
|
|
6084
|
+
setupForWorkflow: (request) => channelSetupService.setupForWorkflow(request),
|
|
6085
|
+
setupForWorkspace: (request) => channelSetupService.setupForWorkspace(request)
|
|
6086
|
+
};
|
|
6087
|
+
this.validation = createValidationDomain(coreService, rulesService);
|
|
6363
6088
|
if (config.enableRealtime && config.realtimeConfig?.autoConnect !== false) {
|
|
6364
6089
|
this.connectRealtime();
|
|
6365
6090
|
}
|
|
@@ -6498,6 +6223,6 @@ var KadoaClient = class {
|
|
|
6498
6223
|
}
|
|
6499
6224
|
};
|
|
6500
6225
|
|
|
6501
|
-
export { ERROR_MESSAGES, KadoaClient, KadoaHttpException, KadoaSdkException, SchemaBuilder,
|
|
6226
|
+
export { DataFetcherService, ERROR_MESSAGES, EntityResolverService, ExtractionBuilderService, ExtractionService, FetchDataOptions, KadoaClient, KadoaHttpException, KadoaSdkException, NotificationChannelType, NotificationChannelsService, V5NotificationsSettingsGetEventTypeEnum as NotificationSettingsEventTypeEnum, NotificationSettingsService, NotificationSetupService, Realtime, SchemaBuilder, SchemaFieldDataType, SchemasService, UserService, ValidationCoreService, ValidationRulesService, WorkflowsCoreService, pollUntil };
|
|
6502
6227
|
//# sourceMappingURL=index.mjs.map
|
|
6503
6228
|
//# sourceMappingURL=index.mjs.map
|