@kadoa/node-sdk 0.0.2 → 0.1.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/dist/index.d.ts CHANGED
@@ -1,5 +1,157 @@
1
- import { AxiosInstance, AxiosError } from 'axios';
2
1
  import { EventEmitter } from 'events';
2
+ import { AxiosError, AxiosInstance } from 'axios';
3
+
4
+ type EntityEventPayloads = {
5
+ "entity:detected": {
6
+ /** Name of the detected entity type (e.g., "Product", "Article", "Job Listing") */
7
+ entity: string;
8
+ /** Data fields detected for the entity */
9
+ fields: Array<{
10
+ name: string;
11
+ description: string;
12
+ example: string;
13
+ dataType: string | Record<string, unknown>;
14
+ isPrimaryKey?: boolean;
15
+ }>;
16
+ /** URL that was analyzed for entity detection */
17
+ url: string;
18
+ };
19
+ };
20
+ type ExtractionEventPayloads = {
21
+ "extraction:started": {
22
+ /** Unique ID of the extraction process */
23
+ workflowId: string;
24
+ /** Name given to this extraction */
25
+ name: string;
26
+ /** URLs to extract data from */
27
+ urls: string[];
28
+ };
29
+ "extraction:status_changed": {
30
+ /** Unique ID of the extraction process */
31
+ workflowId: string;
32
+ /** Previous processing state */
33
+ previousState?: string;
34
+ /** Previous execution status */
35
+ previousRunState?: string;
36
+ /** Current processing state */
37
+ currentState?: string;
38
+ /** Current execution status */
39
+ currentRunState?: string;
40
+ };
41
+ "extraction:data_available": {
42
+ /** Unique ID of the extraction process */
43
+ workflowId: string;
44
+ /** Number of data records retrieved */
45
+ recordCount: number;
46
+ /** Whether this is a partial data set */
47
+ isPartial: boolean;
48
+ };
49
+ "extraction:completed": {
50
+ /** Unique ID of the extraction process */
51
+ workflowId: string;
52
+ /** Whether the extraction completed successfully */
53
+ success: boolean;
54
+ /** Final execution status */
55
+ finalRunState?: string;
56
+ /** Final processing state */
57
+ finalState?: string;
58
+ /** Number of records extracted (if successful) */
59
+ recordCount?: number;
60
+ /** Error message (if failed) */
61
+ error?: string;
62
+ };
63
+ };
64
+ type EventPayloadMap = EntityEventPayloads & ExtractionEventPayloads;
65
+
66
+ /**
67
+ * Unified event structure with discriminated union
68
+ */
69
+ interface KadoaEvent<T extends keyof EventPayloadMap = keyof EventPayloadMap> {
70
+ /** Event type identifier */
71
+ type: T;
72
+ /** ISO timestamp when the event occurred */
73
+ timestamp: Date;
74
+ /** Module or component that emitted the event */
75
+ source: string;
76
+ /** Event-specific payload */
77
+ payload: EventPayloadMap[T];
78
+ /** Optional metadata for debugging and tracking */
79
+ metadata?: Record<string, unknown>;
80
+ }
81
+ /**
82
+ * Type aliases for convenience
83
+ */
84
+ type KadoaEventName = keyof EventPayloadMap;
85
+ type AnyKadoaEvent = KadoaEvent<KadoaEventName>;
86
+ /**
87
+ * Simplified type-safe event emitter for Kadoa SDK events
88
+ */
89
+ declare class KadoaEventEmitter extends EventEmitter {
90
+ /**
91
+ * Emit a typed SDK event
92
+ */
93
+ emit<T extends KadoaEventName>(eventName: T, payload: EventPayloadMap[T], source?: string, metadata?: Record<string, unknown>): boolean;
94
+ /**
95
+ * Subscribe to SDK events
96
+ */
97
+ onEvent(listener: (event: AnyKadoaEvent) => void): this;
98
+ /**
99
+ * Subscribe to SDK events (once)
100
+ */
101
+ onceEvent(listener: (event: AnyKadoaEvent) => void): this;
102
+ /**
103
+ * Unsubscribe from SDK events
104
+ */
105
+ offEvent(listener: (event: AnyKadoaEvent) => void): this;
106
+ /**
107
+ * Remove all event listeners
108
+ */
109
+ removeAllEventListeners(): this;
110
+ }
111
+
112
+ type KadoaErrorCode = "UNKNOWN" | "CONFIG_ERROR" | "AUTH_ERROR" | "VALIDATION_ERROR" | "NOT_FOUND" | "RATE_LIMITED" | "TIMEOUT" | "NETWORK_ERROR" | "HTTP_ERROR" | "INTERNAL_ERROR";
113
+ type KadoaSdkExceptionOptions = {
114
+ code?: KadoaErrorCode;
115
+ details?: Record<string, unknown>;
116
+ cause?: unknown;
117
+ };
118
+ declare class KadoaSdkException extends Error {
119
+ readonly code: KadoaErrorCode;
120
+ readonly details?: Record<string, unknown>;
121
+ readonly cause?: unknown;
122
+ constructor(message: string, options?: KadoaSdkExceptionOptions);
123
+ static from(error: unknown, details?: Record<string, unknown>): KadoaSdkException;
124
+ toJSON(): Record<string, unknown>;
125
+ toString(): string;
126
+ }
127
+
128
+ type KadoaHttpExceptionOptions = {
129
+ httpStatus?: number;
130
+ requestId?: string;
131
+ endpoint?: string;
132
+ method?: string;
133
+ responseBody?: unknown;
134
+ details?: Record<string, unknown>;
135
+ code?: KadoaErrorCode;
136
+ cause?: unknown;
137
+ };
138
+ declare class KadoaHttpException extends KadoaSdkException {
139
+ readonly httpStatus?: number;
140
+ readonly requestId?: string;
141
+ readonly endpoint?: string;
142
+ readonly method?: string;
143
+ readonly responseBody?: unknown;
144
+ constructor(message: string, options?: KadoaHttpExceptionOptions);
145
+ static fromAxiosError(error: AxiosError, extra?: {
146
+ message?: string;
147
+ details?: Record<string, unknown>;
148
+ }): KadoaHttpException;
149
+ toJSON(): Record<string, unknown>;
150
+ private static mapStatusToCode;
151
+ }
152
+
153
+ declare function isKadoaSdkException(error: unknown): error is KadoaSdkException;
154
+ declare function isKadoaHttpException(error: unknown): error is KadoaHttpException;
3
155
 
4
156
  /**
5
157
  * Kadoa API
@@ -660,115 +812,6 @@ declare const V4WorkflowsWorkflowIdGet200ResponseSchemaTypeEnum: {
660
812
  };
661
813
  type V4WorkflowsWorkflowIdGet200ResponseSchemaTypeEnum = typeof V4WorkflowsWorkflowIdGet200ResponseSchemaTypeEnum[keyof typeof V4WorkflowsWorkflowIdGet200ResponseSchemaTypeEnum];
662
814
 
663
- type EntityEventPayloads = {
664
- "entity:detected": {
665
- /** Name of the detected entity type (e.g., "Product", "Article", "Job Listing") */
666
- entity: string;
667
- /** Data fields detected for the entity */
668
- fields: Array<{
669
- name: string;
670
- description: string;
671
- example: string;
672
- dataType: string | Record<string, unknown>;
673
- isPrimaryKey?: boolean;
674
- }>;
675
- /** URL that was analyzed for entity detection */
676
- url: string;
677
- };
678
- };
679
- type ExtractionEventPayloads = {
680
- "extraction:started": {
681
- /** Unique ID of the extraction process */
682
- workflowId: string;
683
- /** Name given to this extraction */
684
- name: string;
685
- /** URLs to extract data from */
686
- urls: string[];
687
- };
688
- "extraction:status_changed": {
689
- /** Unique ID of the extraction process */
690
- workflowId: string;
691
- /** Previous processing state */
692
- previousState?: string;
693
- /** Previous execution status */
694
- previousRunState?: string;
695
- /** Current processing state */
696
- currentState?: string;
697
- /** Current execution status */
698
- currentRunState?: string;
699
- };
700
- "extraction:data_available": {
701
- /** Unique ID of the extraction process */
702
- workflowId: string;
703
- /** Number of data records retrieved */
704
- recordCount: number;
705
- /** Whether this is a partial data set */
706
- isPartial: boolean;
707
- };
708
- "extraction:completed": {
709
- /** Unique ID of the extraction process */
710
- workflowId: string;
711
- /** Whether the extraction completed successfully */
712
- success: boolean;
713
- /** Final execution status */
714
- finalRunState?: string;
715
- /** Final processing state */
716
- finalState?: string;
717
- /** Number of records extracted (if successful) */
718
- recordCount?: number;
719
- /** Error message (if failed) */
720
- error?: string;
721
- };
722
- };
723
- type EventPayloadMap = EntityEventPayloads & ExtractionEventPayloads;
724
-
725
- /**
726
- * Unified event structure with discriminated union
727
- */
728
- interface KadoaEvent<T extends keyof EventPayloadMap = keyof EventPayloadMap> {
729
- /** Event type identifier */
730
- type: T;
731
- /** ISO timestamp when the event occurred */
732
- timestamp: Date;
733
- /** Module or component that emitted the event */
734
- source: string;
735
- /** Event-specific payload */
736
- payload: EventPayloadMap[T];
737
- /** Optional metadata for debugging and tracking */
738
- metadata?: Record<string, unknown>;
739
- }
740
- /**
741
- * Type aliases for convenience
742
- */
743
- type KadoaEventName = keyof EventPayloadMap;
744
- type KadoaEventPayload<T extends KadoaEventName> = EventPayloadMap[T];
745
- type AnyKadoaEvent = KadoaEvent<KadoaEventName>;
746
- /**
747
- * Simplified type-safe event emitter for Kadoa SDK events
748
- */
749
- declare class KadoaEventEmitter extends EventEmitter {
750
- /**
751
- * Emit a typed SDK event
752
- */
753
- emit<T extends KadoaEventName>(eventName: T, payload: EventPayloadMap[T], source?: string, metadata?: Record<string, unknown>): boolean;
754
- /**
755
- * Subscribe to SDK events
756
- */
757
- onEvent(listener: (event: AnyKadoaEvent) => void): this;
758
- /**
759
- * Subscribe to SDK events (once)
760
- */
761
- onceEvent(listener: (event: AnyKadoaEvent) => void): this;
762
- /**
763
- * Unsubscribe from SDK events
764
- */
765
- offEvent(listener: (event: AnyKadoaEvent) => void): this;
766
- /**
767
- * Remove all event listeners
768
- */
769
- removeAllEventListeners(): this;
770
- }
771
-
772
815
  interface KadoaSDK {
773
816
  configuration: Configuration;
774
817
  axiosInstance: AxiosInstance;
@@ -811,69 +854,33 @@ declare function initializeSdk(config: KadoaConfig): KadoaSDK;
811
854
  */
812
855
  declare function dispose(sdkInstance: KadoaSDK): void;
813
856
 
814
- type ExtractionOptions = {
857
+ type NavigationMode = (typeof WorkflowWithExistingSchemaNavigationModeEnum)[keyof typeof WorkflowWithExistingSchemaNavigationModeEnum];
858
+ interface ExtractionConfig {
815
859
  urls: string[];
816
- navigationMode?: WorkflowWithExistingSchemaNavigationModeEnum;
817
- name?: string;
818
- location?: {
860
+ navigationMode: NavigationMode;
861
+ name: string;
862
+ location: {
819
863
  type: string;
820
864
  };
821
- pollingInterval?: number;
822
- maxWaitTime?: number;
823
- };
824
- type ExtractionResult = {
865
+ pollingInterval: number;
866
+ maxWaitTime: number;
867
+ }
868
+ type ExtractionOptions = {
869
+ urls: string[];
870
+ } & Partial<Omit<ExtractionConfig, "urls">>;
871
+ interface ExtractionResult {
825
872
  workflowId: string | undefined;
826
873
  workflow?: V4WorkflowsWorkflowIdGet200Response;
827
874
  data?: Array<object>;
828
- };
875
+ }
829
876
 
830
877
  /**
831
878
  * Run extraction workflow using dynamic entity detection
879
+ *
880
+ * @param sdkInstance The Kadoa SDK instance
881
+ * @param options Extraction configuration options
882
+ * @returns ExtractionResult containing workflow ID, workflow details, and extracted data
832
883
  */
833
884
  declare function runExtraction(sdkInstance: KadoaSDK, options: ExtractionOptions): Promise<ExtractionResult>;
834
885
 
835
- type KadoaErrorCode = "UNKNOWN" | "CONFIG_ERROR" | "AUTH_ERROR" | "VALIDATION_ERROR" | "NOT_FOUND" | "RATE_LIMITED" | "TIMEOUT" | "NETWORK_ERROR" | "HTTP_ERROR" | "INTERNAL_ERROR";
836
- type KadoaSdkExceptionOptions = {
837
- code?: KadoaErrorCode;
838
- details?: Record<string, unknown>;
839
- cause?: unknown;
840
- };
841
- declare class KadoaSdkException extends Error {
842
- readonly code: KadoaErrorCode;
843
- readonly details?: Record<string, unknown>;
844
- readonly cause?: unknown;
845
- constructor(message: string, options?: KadoaSdkExceptionOptions);
846
- static from(error: unknown, details?: Record<string, unknown>): KadoaSdkException;
847
- toJSON(): Record<string, unknown>;
848
- toString(): string;
849
- }
850
-
851
- type KadoaHttpExceptionOptions = {
852
- httpStatus?: number;
853
- requestId?: string;
854
- endpoint?: string;
855
- method?: string;
856
- responseBody?: unknown;
857
- details?: Record<string, unknown>;
858
- code?: KadoaErrorCode;
859
- cause?: unknown;
860
- };
861
- declare class KadoaHttpException extends KadoaSdkException {
862
- readonly httpStatus?: number;
863
- readonly requestId?: string;
864
- readonly endpoint?: string;
865
- readonly method?: string;
866
- readonly responseBody?: unknown;
867
- constructor(message: string, options?: KadoaHttpExceptionOptions);
868
- static fromAxiosError(error: AxiosError, extra?: {
869
- message?: string;
870
- details?: Record<string, unknown>;
871
- }): KadoaHttpException;
872
- toJSON(): Record<string, unknown>;
873
- private static mapStatusToCode;
874
- }
875
-
876
- declare function isKadoaSdkException(error: unknown): error is KadoaSdkException;
877
- declare function isKadoaHttpException(error: unknown): error is KadoaHttpException;
878
-
879
- export { type AnyKadoaEvent, type ExtractionOptions, type ExtractionResult, type KadoaConfig, type KadoaErrorCode, type KadoaEvent, KadoaEventEmitter, type KadoaEventName, type KadoaEventPayload, KadoaHttpException, type KadoaHttpExceptionOptions, type KadoaSDK, KadoaSdkException, type KadoaSdkExceptionOptions, dispose, initializeSdk, isKadoaHttpException, isKadoaSdkException, runExtraction };
886
+ export { type ExtractionOptions, type ExtractionResult, type KadoaConfig, type KadoaErrorCode, type KadoaEvent, KadoaEventEmitter, KadoaHttpException, type KadoaSDK, KadoaSdkException, dispose, initializeSdk, isKadoaHttpException, isKadoaSdkException, runExtraction };