@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/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import globalAxios3, { isAxiosError } from 'axios';
|
|
3
3
|
import { URL, URLSearchParams } from 'url';
|
|
4
|
+
import { merge } from 'es-toolkit';
|
|
4
5
|
|
|
5
|
-
// src/
|
|
6
|
+
// src/internal/runtime/events/event-emitter.ts
|
|
6
7
|
var KadoaEventEmitter = class extends EventEmitter {
|
|
7
8
|
/**
|
|
8
9
|
* Emit a typed SDK event
|
|
@@ -43,7 +44,7 @@ var KadoaEventEmitter = class extends EventEmitter {
|
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
|
|
46
|
-
// src/
|
|
47
|
+
// src/internal/runtime/exceptions/base.exception.ts
|
|
47
48
|
var _KadoaSdkException = class _KadoaSdkException extends Error {
|
|
48
49
|
constructor(message, options) {
|
|
49
50
|
super(message);
|
|
@@ -2270,11 +2271,11 @@ var Configuration = class {
|
|
|
2270
2271
|
}
|
|
2271
2272
|
};
|
|
2272
2273
|
|
|
2273
|
-
// src/
|
|
2274
|
+
// src/internal/runtime/patterns/command.ts
|
|
2274
2275
|
var Command = class {
|
|
2275
2276
|
};
|
|
2276
2277
|
|
|
2277
|
-
// src/
|
|
2278
|
+
// src/internal/runtime/pagination/paginator.ts
|
|
2278
2279
|
var PagedIterator = class {
|
|
2279
2280
|
constructor(fetchPage) {
|
|
2280
2281
|
this.fetchPage = fetchPage;
|
|
@@ -2394,7 +2395,7 @@ var FetchDataQuery = class {
|
|
|
2394
2395
|
}
|
|
2395
2396
|
};
|
|
2396
2397
|
|
|
2397
|
-
// src/
|
|
2398
|
+
// src/internal/runtime/config/constants.ts
|
|
2398
2399
|
var DEFAULT_API_BASE_URL = "https://api.kadoa.com";
|
|
2399
2400
|
|
|
2400
2401
|
// src/modules/extraction/services/entity-detector.service.ts
|
|
@@ -2620,10 +2621,7 @@ var RunExtractionCommand = class extends Command {
|
|
|
2620
2621
|
*/
|
|
2621
2622
|
async execute(options) {
|
|
2622
2623
|
this.validateOptions(options);
|
|
2623
|
-
const config =
|
|
2624
|
-
...DEFAULT_OPTIONS,
|
|
2625
|
-
...options
|
|
2626
|
-
};
|
|
2624
|
+
const config = merge(DEFAULT_OPTIONS, options);
|
|
2627
2625
|
try {
|
|
2628
2626
|
const entityPrediction = await this.entityDetector.fetchEntityFields({
|
|
2629
2627
|
link: config.urls[0],
|
|
@@ -2657,6 +2655,11 @@ var RunExtractionCommand = class extends Command {
|
|
|
2657
2655
|
},
|
|
2658
2656
|
"extraction"
|
|
2659
2657
|
);
|
|
2658
|
+
if (options.mode === "submit") {
|
|
2659
|
+
return {
|
|
2660
|
+
workflowId
|
|
2661
|
+
};
|
|
2662
|
+
}
|
|
2660
2663
|
const workflow = await this.workflowManager.waitForWorkflowCompletion(
|
|
2661
2664
|
workflowId,
|
|
2662
2665
|
config.pollingInterval,
|
|
@@ -2771,7 +2774,10 @@ var ExtractionModule = class {
|
|
|
2771
2774
|
* ```
|
|
2772
2775
|
*/
|
|
2773
2776
|
async run(options) {
|
|
2774
|
-
return this.runExtractionCommand.execute(options);
|
|
2777
|
+
return this.runExtractionCommand.execute({ ...options, mode: "run" });
|
|
2778
|
+
}
|
|
2779
|
+
async submit(options) {
|
|
2780
|
+
return this.runExtractionCommand.execute({ ...options, mode: "submit" });
|
|
2775
2781
|
}
|
|
2776
2782
|
/**
|
|
2777
2783
|
* Fetch paginated data from a workflow
|
|
@@ -2831,8 +2837,125 @@ var ExtractionModule = class {
|
|
|
2831
2837
|
}
|
|
2832
2838
|
};
|
|
2833
2839
|
|
|
2840
|
+
// src/internal/domains/workflows/workflows-core.service.ts
|
|
2841
|
+
var TERMINAL_RUN_STATES2 = /* @__PURE__ */ new Set([
|
|
2842
|
+
"FINISHED",
|
|
2843
|
+
"SUCCESS",
|
|
2844
|
+
"FAILED",
|
|
2845
|
+
"ERROR",
|
|
2846
|
+
"STOPPED",
|
|
2847
|
+
"CANCELLED"
|
|
2848
|
+
]);
|
|
2849
|
+
var WorkflowsCoreService = class {
|
|
2850
|
+
constructor(client) {
|
|
2851
|
+
this.client = client;
|
|
2852
|
+
}
|
|
2853
|
+
async create(input, _idempotencyKey) {
|
|
2854
|
+
const request = {
|
|
2855
|
+
urls: input.urls,
|
|
2856
|
+
navigationMode: input.navigationMode,
|
|
2857
|
+
entity: input.entity,
|
|
2858
|
+
name: input.name,
|
|
2859
|
+
fields: input.fields,
|
|
2860
|
+
bypassPreview: true,
|
|
2861
|
+
tags: input.tags ?? ["sdk"]
|
|
2862
|
+
};
|
|
2863
|
+
try {
|
|
2864
|
+
const response = await this.client.workflows.v4WorkflowsPost({
|
|
2865
|
+
v4WorkflowsPostRequest: request
|
|
2866
|
+
});
|
|
2867
|
+
const workflowId = response.data?.workflowId;
|
|
2868
|
+
if (!workflowId) {
|
|
2869
|
+
throw new KadoaSdkException(ERROR_MESSAGES.NO_WORKFLOW_ID, {
|
|
2870
|
+
code: "INTERNAL_ERROR",
|
|
2871
|
+
details: {
|
|
2872
|
+
response: response.data
|
|
2873
|
+
}
|
|
2874
|
+
});
|
|
2875
|
+
}
|
|
2876
|
+
return { id: workflowId };
|
|
2877
|
+
} catch (error) {
|
|
2878
|
+
throw KadoaHttpException.wrap(error, {
|
|
2879
|
+
message: ERROR_MESSAGES.WORKFLOW_CREATE_FAILED,
|
|
2880
|
+
details: request
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
async get(id) {
|
|
2885
|
+
try {
|
|
2886
|
+
const response = await this.client.workflows.v4WorkflowsWorkflowIdGet({
|
|
2887
|
+
workflowId: id
|
|
2888
|
+
});
|
|
2889
|
+
return response.data;
|
|
2890
|
+
} catch (error) {
|
|
2891
|
+
throw KadoaHttpException.wrap(error, {
|
|
2892
|
+
message: ERROR_MESSAGES.PROGRESS_CHECK_FAILED,
|
|
2893
|
+
details: { workflowId: id }
|
|
2894
|
+
});
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
async cancel(id) {
|
|
2898
|
+
try {
|
|
2899
|
+
await this.client.workflows.v4WorkflowsWorkflowIdDelete({
|
|
2900
|
+
workflowId: id
|
|
2901
|
+
});
|
|
2902
|
+
} catch (error) {
|
|
2903
|
+
throw KadoaHttpException.wrap(error, {
|
|
2904
|
+
message: ERROR_MESSAGES.WORKFLOW_CREATE_FAILED,
|
|
2905
|
+
details: { workflowId: id }
|
|
2906
|
+
});
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
async wait(id, options) {
|
|
2910
|
+
const pollInterval = Math.max(250, options?.pollIntervalMs ?? 1e3);
|
|
2911
|
+
const timeoutMs = options?.timeoutMs ?? 5 * 60 * 1e3;
|
|
2912
|
+
const start = Date.now();
|
|
2913
|
+
let last;
|
|
2914
|
+
while (Date.now() - start < timeoutMs) {
|
|
2915
|
+
if (options?.abortSignal?.aborted) {
|
|
2916
|
+
throw new KadoaSdkException("Aborted");
|
|
2917
|
+
}
|
|
2918
|
+
const current = await this.get(id);
|
|
2919
|
+
if (last?.state !== current.state || last?.runState !== current.runState) ;
|
|
2920
|
+
if (current.runState && TERMINAL_RUN_STATES2.has(current.runState.toUpperCase())) {
|
|
2921
|
+
return current;
|
|
2922
|
+
}
|
|
2923
|
+
last = current;
|
|
2924
|
+
await new Promise((r) => setTimeout(r, pollInterval));
|
|
2925
|
+
}
|
|
2926
|
+
throw new KadoaSdkException(ERROR_MESSAGES.WORKFLOW_TIMEOUT, {
|
|
2927
|
+
details: {
|
|
2928
|
+
workflowId: id,
|
|
2929
|
+
lastState: last?.state,
|
|
2930
|
+
lastRunState: last?.runState,
|
|
2931
|
+
timeoutMs
|
|
2932
|
+
}
|
|
2933
|
+
});
|
|
2934
|
+
}
|
|
2935
|
+
};
|
|
2936
|
+
|
|
2937
|
+
// src/modules/workflows/workflows.module.ts
|
|
2938
|
+
var WorkflowsModule = class {
|
|
2939
|
+
constructor(client) {
|
|
2940
|
+
this.core = new WorkflowsCoreService(client);
|
|
2941
|
+
}
|
|
2942
|
+
async submit(input, options) {
|
|
2943
|
+
const { id } = await this.core.create(input, options?.idempotencyKey);
|
|
2944
|
+
return { workflowId: id };
|
|
2945
|
+
}
|
|
2946
|
+
async get(workflowId) {
|
|
2947
|
+
return this.core.get(workflowId);
|
|
2948
|
+
}
|
|
2949
|
+
async cancel(workflowId) {
|
|
2950
|
+
return this.core.cancel(workflowId);
|
|
2951
|
+
}
|
|
2952
|
+
async wait(workflowId, options) {
|
|
2953
|
+
return this.core.wait(workflowId, options);
|
|
2954
|
+
}
|
|
2955
|
+
};
|
|
2956
|
+
|
|
2834
2957
|
// src/version.ts
|
|
2835
|
-
var SDK_VERSION = "0.
|
|
2958
|
+
var SDK_VERSION = "0.7.0";
|
|
2836
2959
|
var SDK_NAME = "kadoa-node-sdk";
|
|
2837
2960
|
var SDK_LANGUAGE = "node";
|
|
2838
2961
|
|
|
@@ -2865,6 +2988,7 @@ var KadoaClient = class {
|
|
|
2865
2988
|
this._workflowsApi = config.apiOverrides?.workflows || new WorkflowsApi(this._configuration, this._baseUrl, this._axiosInstance);
|
|
2866
2989
|
this._crawlApi = config.apiOverrides?.crawl || new CrawlApi(this._configuration, this._baseUrl, this._axiosInstance);
|
|
2867
2990
|
this.extraction = new ExtractionModule(this);
|
|
2991
|
+
this.workflow = new WorkflowsModule(this);
|
|
2868
2992
|
}
|
|
2869
2993
|
/**
|
|
2870
2994
|
* Register an event listener
|