@kadoa/node-sdk 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/index.d.mts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +135 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -93,16 +93,29 @@ client.onEvent((event) => {
|
|
|
93
93
|
- `timeout` (optional): Request timeout in milliseconds (default: 30000)
|
|
94
94
|
|
|
95
95
|
Returns a client instance with:
|
|
96
|
-
- `extraction`: Extraction module with `run()`
|
|
96
|
+
- `extraction`: Extraction module with `run()`, `submit()`, `fetchData()` methods
|
|
97
|
+
- `workflow`: Workflow module with `get()`, `submit()`, `cancel()`, `wait()` methods
|
|
97
98
|
- `onEvent()`: Subscribe to events
|
|
98
99
|
- `offEvent()`: Unsubscribe from events
|
|
99
100
|
- `dispose()`: Releases resources and removes all event listeners
|
|
100
101
|
|
|
101
102
|
### client.extraction.run(options)
|
|
103
|
+
Runs extraction and waits for completion.
|
|
102
104
|
- `urls`: Array of URLs to extract from
|
|
103
105
|
- `name`: Workflow name
|
|
104
106
|
- Additional options available in API documentation
|
|
105
107
|
|
|
108
|
+
### client.extraction.submit(options)
|
|
109
|
+
Submits extraction without waiting for completion.
|
|
110
|
+
- `urls`: Array of URLs to extract from
|
|
111
|
+
- `name`: Workflow name
|
|
112
|
+
- Returns: `{ workflowId: string }`
|
|
113
|
+
|
|
114
|
+
### client.workflow.get(workflowId)
|
|
115
|
+
Gets the current status of a workflow.
|
|
116
|
+
- `workflowId`: The workflow ID to query
|
|
117
|
+
- Returns: Workflow status object
|
|
118
|
+
|
|
106
119
|
## Examples
|
|
107
120
|
|
|
108
121
|
See [examples directory](https://github.com/kadoa-org/kadoa-sdks/tree/main/examples/node-examples) for more usage examples.
|
package/dist/index.d.mts
CHANGED
|
@@ -1282,6 +1282,7 @@ declare const V4WorkflowsGet200ResponseWorkflowsInnerSchemaInnerDataTypeEnum: {
|
|
|
1282
1282
|
readonly Date: "DATE";
|
|
1283
1283
|
readonly Datetime: "DATETIME";
|
|
1284
1284
|
readonly Currency: "CURRENCY";
|
|
1285
|
+
readonly Money: "MONEY";
|
|
1285
1286
|
readonly Image: "IMAGE";
|
|
1286
1287
|
readonly Link: "LINK";
|
|
1287
1288
|
readonly Object: "OBJECT";
|
|
@@ -1726,6 +1727,7 @@ declare const WorkflowWithCustomSchemaFieldsInnerDataTypeEnum: {
|
|
|
1726
1727
|
readonly Date: "DATE";
|
|
1727
1728
|
readonly Datetime: "DATETIME";
|
|
1728
1729
|
readonly Currency: "CURRENCY";
|
|
1730
|
+
readonly Money: "MONEY";
|
|
1729
1731
|
readonly Image: "IMAGE";
|
|
1730
1732
|
readonly Link: "LINK";
|
|
1731
1733
|
readonly Object: "OBJECT";
|
|
@@ -5125,11 +5127,14 @@ type ExtractionOptions = {
|
|
|
5125
5127
|
urls: string[];
|
|
5126
5128
|
} & Partial<Omit<ExtractionConfig, "urls">>;
|
|
5127
5129
|
interface ExtractionResult {
|
|
5128
|
-
workflowId: string
|
|
5130
|
+
workflowId: string;
|
|
5129
5131
|
workflow?: V4WorkflowsWorkflowIdGet200Response;
|
|
5130
5132
|
data?: Array<object>;
|
|
5131
5133
|
pagination?: PageInfo;
|
|
5132
5134
|
}
|
|
5135
|
+
interface SubmitExtractionResult {
|
|
5136
|
+
workflowId: string;
|
|
5137
|
+
}
|
|
5133
5138
|
|
|
5134
5139
|
type DataPagination = V4WorkflowsWorkflowIdDataGet200ResponsePagination;
|
|
5135
5140
|
type WorkflowDataResponse = V4WorkflowsWorkflowIdDataGet200Response;
|
|
@@ -5165,6 +5170,7 @@ declare class ExtractionModule {
|
|
|
5165
5170
|
* ```
|
|
5166
5171
|
*/
|
|
5167
5172
|
run(options: ExtractionOptions): Promise<ExtractionResult>;
|
|
5173
|
+
submit(options: ExtractionOptions): Promise<SubmitExtractionResult>;
|
|
5168
5174
|
/**
|
|
5169
5175
|
* Fetch paginated data from a workflow
|
|
5170
5176
|
*
|
|
@@ -5217,6 +5223,33 @@ declare class ExtractionModule {
|
|
|
5217
5223
|
fetchDataPages(options: FetchDataOptions): AsyncGenerator<FetchDataResult, void, unknown>;
|
|
5218
5224
|
}
|
|
5219
5225
|
|
|
5226
|
+
interface CreateWorkflowInput {
|
|
5227
|
+
urls: string[];
|
|
5228
|
+
navigationMode: string;
|
|
5229
|
+
name: string;
|
|
5230
|
+
entity?: string;
|
|
5231
|
+
fields?: Array<WorkflowWithCustomSchemaFieldsInner>;
|
|
5232
|
+
tags?: string[];
|
|
5233
|
+
}
|
|
5234
|
+
|
|
5235
|
+
interface SubmitOptions {
|
|
5236
|
+
idempotencyKey?: string;
|
|
5237
|
+
}
|
|
5238
|
+
interface WaitOptions {
|
|
5239
|
+
pollIntervalMs?: number;
|
|
5240
|
+
timeoutMs?: number;
|
|
5241
|
+
}
|
|
5242
|
+
declare class WorkflowsModule {
|
|
5243
|
+
private readonly core;
|
|
5244
|
+
constructor(client: KadoaClient);
|
|
5245
|
+
submit(input: CreateWorkflowInput, options?: SubmitOptions): Promise<{
|
|
5246
|
+
workflowId: string;
|
|
5247
|
+
}>;
|
|
5248
|
+
get(workflowId: string): Promise<V4WorkflowsWorkflowIdGet200Response>;
|
|
5249
|
+
cancel(workflowId: string): Promise<void>;
|
|
5250
|
+
wait(workflowId: string, options?: WaitOptions): Promise<V4WorkflowsWorkflowIdGet200Response>;
|
|
5251
|
+
}
|
|
5252
|
+
|
|
5220
5253
|
interface KadoaClientConfig {
|
|
5221
5254
|
apiKey: string;
|
|
5222
5255
|
baseUrl?: string;
|
|
@@ -5252,6 +5285,7 @@ declare class KadoaClient implements ApiProvider {
|
|
|
5252
5285
|
private readonly _workflowsApi;
|
|
5253
5286
|
private readonly _crawlApi;
|
|
5254
5287
|
readonly extraction: ExtractionModule;
|
|
5288
|
+
readonly workflow: WorkflowsModule;
|
|
5255
5289
|
constructor(config: KadoaClientConfig);
|
|
5256
5290
|
/**
|
|
5257
5291
|
* Register an event listener
|
package/dist/index.d.ts
CHANGED
|
@@ -1282,6 +1282,7 @@ declare const V4WorkflowsGet200ResponseWorkflowsInnerSchemaInnerDataTypeEnum: {
|
|
|
1282
1282
|
readonly Date: "DATE";
|
|
1283
1283
|
readonly Datetime: "DATETIME";
|
|
1284
1284
|
readonly Currency: "CURRENCY";
|
|
1285
|
+
readonly Money: "MONEY";
|
|
1285
1286
|
readonly Image: "IMAGE";
|
|
1286
1287
|
readonly Link: "LINK";
|
|
1287
1288
|
readonly Object: "OBJECT";
|
|
@@ -1726,6 +1727,7 @@ declare const WorkflowWithCustomSchemaFieldsInnerDataTypeEnum: {
|
|
|
1726
1727
|
readonly Date: "DATE";
|
|
1727
1728
|
readonly Datetime: "DATETIME";
|
|
1728
1729
|
readonly Currency: "CURRENCY";
|
|
1730
|
+
readonly Money: "MONEY";
|
|
1729
1731
|
readonly Image: "IMAGE";
|
|
1730
1732
|
readonly Link: "LINK";
|
|
1731
1733
|
readonly Object: "OBJECT";
|
|
@@ -5125,11 +5127,14 @@ type ExtractionOptions = {
|
|
|
5125
5127
|
urls: string[];
|
|
5126
5128
|
} & Partial<Omit<ExtractionConfig, "urls">>;
|
|
5127
5129
|
interface ExtractionResult {
|
|
5128
|
-
workflowId: string
|
|
5130
|
+
workflowId: string;
|
|
5129
5131
|
workflow?: V4WorkflowsWorkflowIdGet200Response;
|
|
5130
5132
|
data?: Array<object>;
|
|
5131
5133
|
pagination?: PageInfo;
|
|
5132
5134
|
}
|
|
5135
|
+
interface SubmitExtractionResult {
|
|
5136
|
+
workflowId: string;
|
|
5137
|
+
}
|
|
5133
5138
|
|
|
5134
5139
|
type DataPagination = V4WorkflowsWorkflowIdDataGet200ResponsePagination;
|
|
5135
5140
|
type WorkflowDataResponse = V4WorkflowsWorkflowIdDataGet200Response;
|
|
@@ -5165,6 +5170,7 @@ declare class ExtractionModule {
|
|
|
5165
5170
|
* ```
|
|
5166
5171
|
*/
|
|
5167
5172
|
run(options: ExtractionOptions): Promise<ExtractionResult>;
|
|
5173
|
+
submit(options: ExtractionOptions): Promise<SubmitExtractionResult>;
|
|
5168
5174
|
/**
|
|
5169
5175
|
* Fetch paginated data from a workflow
|
|
5170
5176
|
*
|
|
@@ -5217,6 +5223,33 @@ declare class ExtractionModule {
|
|
|
5217
5223
|
fetchDataPages(options: FetchDataOptions): AsyncGenerator<FetchDataResult, void, unknown>;
|
|
5218
5224
|
}
|
|
5219
5225
|
|
|
5226
|
+
interface CreateWorkflowInput {
|
|
5227
|
+
urls: string[];
|
|
5228
|
+
navigationMode: string;
|
|
5229
|
+
name: string;
|
|
5230
|
+
entity?: string;
|
|
5231
|
+
fields?: Array<WorkflowWithCustomSchemaFieldsInner>;
|
|
5232
|
+
tags?: string[];
|
|
5233
|
+
}
|
|
5234
|
+
|
|
5235
|
+
interface SubmitOptions {
|
|
5236
|
+
idempotencyKey?: string;
|
|
5237
|
+
}
|
|
5238
|
+
interface WaitOptions {
|
|
5239
|
+
pollIntervalMs?: number;
|
|
5240
|
+
timeoutMs?: number;
|
|
5241
|
+
}
|
|
5242
|
+
declare class WorkflowsModule {
|
|
5243
|
+
private readonly core;
|
|
5244
|
+
constructor(client: KadoaClient);
|
|
5245
|
+
submit(input: CreateWorkflowInput, options?: SubmitOptions): Promise<{
|
|
5246
|
+
workflowId: string;
|
|
5247
|
+
}>;
|
|
5248
|
+
get(workflowId: string): Promise<V4WorkflowsWorkflowIdGet200Response>;
|
|
5249
|
+
cancel(workflowId: string): Promise<void>;
|
|
5250
|
+
wait(workflowId: string, options?: WaitOptions): Promise<V4WorkflowsWorkflowIdGet200Response>;
|
|
5251
|
+
}
|
|
5252
|
+
|
|
5220
5253
|
interface KadoaClientConfig {
|
|
5221
5254
|
apiKey: string;
|
|
5222
5255
|
baseUrl?: string;
|
|
@@ -5252,6 +5285,7 @@ declare class KadoaClient implements ApiProvider {
|
|
|
5252
5285
|
private readonly _workflowsApi;
|
|
5253
5286
|
private readonly _crawlApi;
|
|
5254
5287
|
readonly extraction: ExtractionModule;
|
|
5288
|
+
readonly workflow: WorkflowsModule;
|
|
5255
5289
|
constructor(config: KadoaClientConfig);
|
|
5256
5290
|
/**
|
|
5257
5291
|
* Register an event listener
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
var events = require('events');
|
|
4
4
|
var globalAxios3 = require('axios');
|
|
5
5
|
var url = require('url');
|
|
6
|
+
var esToolkit = require('es-toolkit');
|
|
6
7
|
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
9
|
|
|
9
10
|
var globalAxios3__default = /*#__PURE__*/_interopDefault(globalAxios3);
|
|
10
11
|
|
|
11
|
-
// src/
|
|
12
|
+
// src/internal/runtime/events/event-emitter.ts
|
|
12
13
|
var KadoaEventEmitter = class extends events.EventEmitter {
|
|
13
14
|
/**
|
|
14
15
|
* Emit a typed SDK event
|
|
@@ -49,7 +50,7 @@ var KadoaEventEmitter = class extends events.EventEmitter {
|
|
|
49
50
|
}
|
|
50
51
|
};
|
|
51
52
|
|
|
52
|
-
// src/
|
|
53
|
+
// src/internal/runtime/exceptions/base.exception.ts
|
|
53
54
|
var _KadoaSdkException = class _KadoaSdkException extends Error {
|
|
54
55
|
constructor(message, options) {
|
|
55
56
|
super(message);
|
|
@@ -2276,11 +2277,11 @@ var Configuration = class {
|
|
|
2276
2277
|
}
|
|
2277
2278
|
};
|
|
2278
2279
|
|
|
2279
|
-
// src/
|
|
2280
|
+
// src/internal/runtime/patterns/command.ts
|
|
2280
2281
|
var Command = class {
|
|
2281
2282
|
};
|
|
2282
2283
|
|
|
2283
|
-
// src/
|
|
2284
|
+
// src/internal/runtime/pagination/paginator.ts
|
|
2284
2285
|
var PagedIterator = class {
|
|
2285
2286
|
constructor(fetchPage) {
|
|
2286
2287
|
this.fetchPage = fetchPage;
|
|
@@ -2400,7 +2401,7 @@ var FetchDataQuery = class {
|
|
|
2400
2401
|
}
|
|
2401
2402
|
};
|
|
2402
2403
|
|
|
2403
|
-
// src/
|
|
2404
|
+
// src/internal/runtime/config/constants.ts
|
|
2404
2405
|
var DEFAULT_API_BASE_URL = "https://api.kadoa.com";
|
|
2405
2406
|
|
|
2406
2407
|
// src/modules/extraction/services/entity-detector.service.ts
|
|
@@ -2626,10 +2627,7 @@ var RunExtractionCommand = class extends Command {
|
|
|
2626
2627
|
*/
|
|
2627
2628
|
async execute(options) {
|
|
2628
2629
|
this.validateOptions(options);
|
|
2629
|
-
const config =
|
|
2630
|
-
...DEFAULT_OPTIONS,
|
|
2631
|
-
...options
|
|
2632
|
-
};
|
|
2630
|
+
const config = esToolkit.merge(DEFAULT_OPTIONS, options);
|
|
2633
2631
|
try {
|
|
2634
2632
|
const entityPrediction = await this.entityDetector.fetchEntityFields({
|
|
2635
2633
|
link: config.urls[0],
|
|
@@ -2663,6 +2661,11 @@ var RunExtractionCommand = class extends Command {
|
|
|
2663
2661
|
},
|
|
2664
2662
|
"extraction"
|
|
2665
2663
|
);
|
|
2664
|
+
if (options.mode === "submit") {
|
|
2665
|
+
return {
|
|
2666
|
+
workflowId
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2666
2669
|
const workflow = await this.workflowManager.waitForWorkflowCompletion(
|
|
2667
2670
|
workflowId,
|
|
2668
2671
|
config.pollingInterval,
|
|
@@ -2777,7 +2780,10 @@ var ExtractionModule = class {
|
|
|
2777
2780
|
* ```
|
|
2778
2781
|
*/
|
|
2779
2782
|
async run(options) {
|
|
2780
|
-
return this.runExtractionCommand.execute(options);
|
|
2783
|
+
return this.runExtractionCommand.execute({ ...options, mode: "run" });
|
|
2784
|
+
}
|
|
2785
|
+
async submit(options) {
|
|
2786
|
+
return this.runExtractionCommand.execute({ ...options, mode: "submit" });
|
|
2781
2787
|
}
|
|
2782
2788
|
/**
|
|
2783
2789
|
* Fetch paginated data from a workflow
|
|
@@ -2837,8 +2843,125 @@ var ExtractionModule = class {
|
|
|
2837
2843
|
}
|
|
2838
2844
|
};
|
|
2839
2845
|
|
|
2846
|
+
// src/internal/domains/workflows/workflows-core.service.ts
|
|
2847
|
+
var TERMINAL_RUN_STATES2 = /* @__PURE__ */ new Set([
|
|
2848
|
+
"FINISHED",
|
|
2849
|
+
"SUCCESS",
|
|
2850
|
+
"FAILED",
|
|
2851
|
+
"ERROR",
|
|
2852
|
+
"STOPPED",
|
|
2853
|
+
"CANCELLED"
|
|
2854
|
+
]);
|
|
2855
|
+
var WorkflowsCoreService = class {
|
|
2856
|
+
constructor(client) {
|
|
2857
|
+
this.client = client;
|
|
2858
|
+
}
|
|
2859
|
+
async create(input, _idempotencyKey) {
|
|
2860
|
+
const request = {
|
|
2861
|
+
urls: input.urls,
|
|
2862
|
+
navigationMode: input.navigationMode,
|
|
2863
|
+
entity: input.entity,
|
|
2864
|
+
name: input.name,
|
|
2865
|
+
fields: input.fields,
|
|
2866
|
+
bypassPreview: true,
|
|
2867
|
+
tags: input.tags ?? ["sdk"]
|
|
2868
|
+
};
|
|
2869
|
+
try {
|
|
2870
|
+
const response = await this.client.workflows.v4WorkflowsPost({
|
|
2871
|
+
v4WorkflowsPostRequest: request
|
|
2872
|
+
});
|
|
2873
|
+
const workflowId = response.data?.workflowId;
|
|
2874
|
+
if (!workflowId) {
|
|
2875
|
+
throw new KadoaSdkException(ERROR_MESSAGES.NO_WORKFLOW_ID, {
|
|
2876
|
+
code: "INTERNAL_ERROR",
|
|
2877
|
+
details: {
|
|
2878
|
+
response: response.data
|
|
2879
|
+
}
|
|
2880
|
+
});
|
|
2881
|
+
}
|
|
2882
|
+
return { id: workflowId };
|
|
2883
|
+
} catch (error) {
|
|
2884
|
+
throw KadoaHttpException.wrap(error, {
|
|
2885
|
+
message: ERROR_MESSAGES.WORKFLOW_CREATE_FAILED,
|
|
2886
|
+
details: request
|
|
2887
|
+
});
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
async get(id) {
|
|
2891
|
+
try {
|
|
2892
|
+
const response = await this.client.workflows.v4WorkflowsWorkflowIdGet({
|
|
2893
|
+
workflowId: id
|
|
2894
|
+
});
|
|
2895
|
+
return response.data;
|
|
2896
|
+
} catch (error) {
|
|
2897
|
+
throw KadoaHttpException.wrap(error, {
|
|
2898
|
+
message: ERROR_MESSAGES.PROGRESS_CHECK_FAILED,
|
|
2899
|
+
details: { workflowId: id }
|
|
2900
|
+
});
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
async cancel(id) {
|
|
2904
|
+
try {
|
|
2905
|
+
await this.client.workflows.v4WorkflowsWorkflowIdDelete({
|
|
2906
|
+
workflowId: id
|
|
2907
|
+
});
|
|
2908
|
+
} catch (error) {
|
|
2909
|
+
throw KadoaHttpException.wrap(error, {
|
|
2910
|
+
message: ERROR_MESSAGES.WORKFLOW_CREATE_FAILED,
|
|
2911
|
+
details: { workflowId: id }
|
|
2912
|
+
});
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
async wait(id, options) {
|
|
2916
|
+
const pollInterval = Math.max(250, options?.pollIntervalMs ?? 1e3);
|
|
2917
|
+
const timeoutMs = options?.timeoutMs ?? 5 * 60 * 1e3;
|
|
2918
|
+
const start = Date.now();
|
|
2919
|
+
let last;
|
|
2920
|
+
while (Date.now() - start < timeoutMs) {
|
|
2921
|
+
if (options?.abortSignal?.aborted) {
|
|
2922
|
+
throw new KadoaSdkException("Aborted");
|
|
2923
|
+
}
|
|
2924
|
+
const current = await this.get(id);
|
|
2925
|
+
if (last?.state !== current.state || last?.runState !== current.runState) ;
|
|
2926
|
+
if (current.runState && TERMINAL_RUN_STATES2.has(current.runState.toUpperCase())) {
|
|
2927
|
+
return current;
|
|
2928
|
+
}
|
|
2929
|
+
last = current;
|
|
2930
|
+
await new Promise((r) => setTimeout(r, pollInterval));
|
|
2931
|
+
}
|
|
2932
|
+
throw new KadoaSdkException(ERROR_MESSAGES.WORKFLOW_TIMEOUT, {
|
|
2933
|
+
details: {
|
|
2934
|
+
workflowId: id,
|
|
2935
|
+
lastState: last?.state,
|
|
2936
|
+
lastRunState: last?.runState,
|
|
2937
|
+
timeoutMs
|
|
2938
|
+
}
|
|
2939
|
+
});
|
|
2940
|
+
}
|
|
2941
|
+
};
|
|
2942
|
+
|
|
2943
|
+
// src/modules/workflows/workflows.module.ts
|
|
2944
|
+
var WorkflowsModule = class {
|
|
2945
|
+
constructor(client) {
|
|
2946
|
+
this.core = new WorkflowsCoreService(client);
|
|
2947
|
+
}
|
|
2948
|
+
async submit(input, options) {
|
|
2949
|
+
const { id } = await this.core.create(input, options?.idempotencyKey);
|
|
2950
|
+
return { workflowId: id };
|
|
2951
|
+
}
|
|
2952
|
+
async get(workflowId) {
|
|
2953
|
+
return this.core.get(workflowId);
|
|
2954
|
+
}
|
|
2955
|
+
async cancel(workflowId) {
|
|
2956
|
+
return this.core.cancel(workflowId);
|
|
2957
|
+
}
|
|
2958
|
+
async wait(workflowId, options) {
|
|
2959
|
+
return this.core.wait(workflowId, options);
|
|
2960
|
+
}
|
|
2961
|
+
};
|
|
2962
|
+
|
|
2840
2963
|
// src/version.ts
|
|
2841
|
-
var SDK_VERSION = "0.
|
|
2964
|
+
var SDK_VERSION = "0.7.0";
|
|
2842
2965
|
var SDK_NAME = "kadoa-node-sdk";
|
|
2843
2966
|
var SDK_LANGUAGE = "node";
|
|
2844
2967
|
|
|
@@ -2871,6 +2994,7 @@ var KadoaClient = class {
|
|
|
2871
2994
|
this._workflowsApi = config.apiOverrides?.workflows || new WorkflowsApi(this._configuration, this._baseUrl, this._axiosInstance);
|
|
2872
2995
|
this._crawlApi = config.apiOverrides?.crawl || new CrawlApi(this._configuration, this._baseUrl, this._axiosInstance);
|
|
2873
2996
|
this.extraction = new ExtractionModule(this);
|
|
2997
|
+
this.workflow = new WorkflowsModule(this);
|
|
2874
2998
|
}
|
|
2875
2999
|
/**
|
|
2876
3000
|
* Register an event listener
|