@stack0/sdk 0.2.8 → 0.2.9

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.
@@ -0,0 +1,374 @@
1
+ import { H as HttpClientConfig } from '../http-client-Wr9lXo9_.mjs';
2
+ import { E as Environment, B as BatchJobStatus, S as ScheduleFrequency, C as CreateBatchResponse, G as GetBatchJobRequest, L as ListBatchJobsRequest, c as CreateScheduleResponse, a as GetScheduleRequest, b as ListSchedulesRequest } from '../shared-types-B0PyC7cF.mjs';
3
+
4
+ /**
5
+ * Type definitions for Stack0 AI Extraction API
6
+ */
7
+
8
+ type ExtractionStatus = "pending" | "processing" | "completed" | "failed";
9
+ type ExtractionMode = "auto" | "schema" | "markdown" | "raw";
10
+ interface PageMetadata {
11
+ title?: string;
12
+ description?: string;
13
+ ogImage?: string;
14
+ favicon?: string;
15
+ links?: string[];
16
+ images?: string[];
17
+ }
18
+ interface ExtractionResult {
19
+ id: string;
20
+ organizationId: string;
21
+ projectId: string | null;
22
+ environment: Environment;
23
+ url: string;
24
+ mode: string;
25
+ status: ExtractionStatus;
26
+ extractedData: Record<string, unknown> | null;
27
+ markdown: string | null;
28
+ rawHtml: string | null;
29
+ pageMetadata: PageMetadata | null;
30
+ error: string | null;
31
+ processingTimeMs: number | null;
32
+ tokensUsed: number | null;
33
+ metadata: Record<string, unknown> | null;
34
+ createdAt: Date;
35
+ completedAt: Date | null;
36
+ }
37
+ interface CreateExtractionRequest {
38
+ url: string;
39
+ environment?: Environment;
40
+ projectId?: string;
41
+ mode?: ExtractionMode;
42
+ schema?: Record<string, unknown>;
43
+ prompt?: string;
44
+ includeLinks?: boolean;
45
+ includeImages?: boolean;
46
+ includeMetadata?: boolean;
47
+ waitForSelector?: string;
48
+ waitForTimeout?: number;
49
+ headers?: Record<string, string>;
50
+ cookies?: Array<{
51
+ name: string;
52
+ value: string;
53
+ domain?: string;
54
+ }>;
55
+ webhookUrl?: string;
56
+ webhookSecret?: string;
57
+ metadata?: Record<string, unknown>;
58
+ }
59
+ interface CreateExtractionResponse {
60
+ id: string;
61
+ status: ExtractionStatus;
62
+ }
63
+ interface GetExtractionRequest {
64
+ id: string;
65
+ environment?: Environment;
66
+ projectId?: string;
67
+ }
68
+ interface ListExtractionsRequest {
69
+ environment?: Environment;
70
+ projectId?: string;
71
+ status?: ExtractionStatus;
72
+ url?: string;
73
+ limit?: number;
74
+ cursor?: string;
75
+ }
76
+ interface ListExtractionsResponse {
77
+ items: ExtractionResult[];
78
+ nextCursor?: string;
79
+ }
80
+ interface BatchExtractionJob {
81
+ id: string;
82
+ organizationId: string;
83
+ projectId: string | null;
84
+ environment: Environment;
85
+ type: "extraction";
86
+ name: string | null;
87
+ status: BatchJobStatus;
88
+ urls: string[];
89
+ config: Record<string, unknown>;
90
+ totalUrls: number;
91
+ processedUrls: number;
92
+ successfulUrls: number;
93
+ failedUrls: number;
94
+ webhookUrl: string | null;
95
+ metadata: Record<string, unknown> | null;
96
+ createdAt: Date;
97
+ startedAt: Date | null;
98
+ completedAt: Date | null;
99
+ }
100
+ interface CreateBatchExtractionsRequest {
101
+ urls: string[];
102
+ environment?: Environment;
103
+ projectId?: string;
104
+ name?: string;
105
+ config?: {
106
+ mode?: ExtractionMode;
107
+ schema?: Record<string, unknown>;
108
+ prompt?: string;
109
+ includeLinks?: boolean;
110
+ includeImages?: boolean;
111
+ includeMetadata?: boolean;
112
+ waitForSelector?: string;
113
+ waitForTimeout?: number;
114
+ };
115
+ webhookUrl?: string;
116
+ webhookSecret?: string;
117
+ metadata?: Record<string, unknown>;
118
+ }
119
+ interface ExtractionBatchJobsResponse {
120
+ items: BatchExtractionJob[];
121
+ nextCursor?: string;
122
+ }
123
+ interface ExtractionSchedule {
124
+ id: string;
125
+ organizationId: string;
126
+ projectId: string | null;
127
+ environment: Environment;
128
+ name: string;
129
+ url: string;
130
+ type: "extraction";
131
+ frequency: ScheduleFrequency;
132
+ config: Record<string, unknown>;
133
+ isActive: boolean;
134
+ detectChanges: boolean;
135
+ changeThreshold: number | null;
136
+ webhookUrl: string | null;
137
+ totalRuns: number;
138
+ successfulRuns: number;
139
+ failedRuns: number;
140
+ lastRunAt: Date | null;
141
+ nextRunAt: Date | null;
142
+ metadata: Record<string, unknown> | null;
143
+ createdAt: Date;
144
+ updatedAt: Date;
145
+ }
146
+ interface CreateExtractionScheduleRequest {
147
+ name: string;
148
+ url: string;
149
+ environment?: Environment;
150
+ projectId?: string;
151
+ frequency?: ScheduleFrequency;
152
+ config: {
153
+ mode?: ExtractionMode;
154
+ schema?: Record<string, unknown>;
155
+ prompt?: string;
156
+ includeLinks?: boolean;
157
+ includeImages?: boolean;
158
+ includeMetadata?: boolean;
159
+ waitForSelector?: string;
160
+ waitForTimeout?: number;
161
+ };
162
+ detectChanges?: boolean;
163
+ changeThreshold?: number;
164
+ webhookUrl?: string;
165
+ webhookSecret?: string;
166
+ metadata?: Record<string, unknown>;
167
+ }
168
+ interface UpdateExtractionScheduleRequest {
169
+ id: string;
170
+ environment?: Environment;
171
+ projectId?: string;
172
+ name?: string;
173
+ frequency?: ScheduleFrequency;
174
+ config?: Record<string, unknown>;
175
+ isActive?: boolean;
176
+ detectChanges?: boolean;
177
+ changeThreshold?: number;
178
+ webhookUrl?: string | null;
179
+ webhookSecret?: string | null;
180
+ metadata?: Record<string, unknown>;
181
+ }
182
+ interface ExtractionSchedulesResponse {
183
+ items: ExtractionSchedule[];
184
+ nextCursor?: string;
185
+ }
186
+ interface ExtractionUsage {
187
+ periodStart: Date;
188
+ periodEnd: Date;
189
+ extractionsTotal: number;
190
+ extractionsSuccessful: number;
191
+ extractionsFailed: number;
192
+ extractionCreditsUsed: number;
193
+ extractionTokensUsed: number;
194
+ }
195
+ interface GetUsageRequest {
196
+ environment?: Environment;
197
+ periodStart?: string;
198
+ periodEnd?: string;
199
+ }
200
+
201
+ /**
202
+ * Stack0 AI Extraction Client
203
+ * Extract structured data from any webpage using AI
204
+ */
205
+
206
+ declare class Extraction {
207
+ private http;
208
+ constructor(config: HttpClientConfig);
209
+ /**
210
+ * Extract content from a URL
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * const { id, status } = await extraction.extract({
215
+ * url: 'https://example.com/article',
216
+ * mode: 'markdown',
217
+ * includeMetadata: true,
218
+ * });
219
+ *
220
+ * // Poll for completion
221
+ * const result = await extraction.get({ id });
222
+ * console.log(result.markdown);
223
+ * ```
224
+ */
225
+ extract(request: CreateExtractionRequest): Promise<CreateExtractionResponse>;
226
+ /**
227
+ * Get an extraction by ID
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const extraction = await extraction.get({ id: 'extraction-id' });
232
+ * if (extraction.status === 'completed') {
233
+ * console.log(extraction.markdown);
234
+ * console.log(extraction.pageMetadata);
235
+ * }
236
+ * ```
237
+ */
238
+ get(request: GetExtractionRequest): Promise<ExtractionResult>;
239
+ /**
240
+ * List extractions with pagination and filters
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const { items, nextCursor } = await extraction.list({
245
+ * status: 'completed',
246
+ * limit: 20,
247
+ * });
248
+ * ```
249
+ */
250
+ list(request?: ListExtractionsRequest): Promise<ListExtractionsResponse>;
251
+ /**
252
+ * Delete an extraction
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * await extraction.delete({ id: 'extraction-id' });
257
+ * ```
258
+ */
259
+ delete(request: GetExtractionRequest): Promise<{
260
+ success: boolean;
261
+ }>;
262
+ /**
263
+ * Extract content and wait for completion
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * const extraction = await extraction.extractAndWait({
268
+ * url: 'https://example.com/article',
269
+ * mode: 'markdown',
270
+ * });
271
+ * console.log(extraction.markdown);
272
+ * ```
273
+ */
274
+ extractAndWait(request: CreateExtractionRequest, options?: {
275
+ pollInterval?: number;
276
+ timeout?: number;
277
+ }): Promise<ExtractionResult>;
278
+ /**
279
+ * Create a batch extraction job for multiple URLs
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const { id, totalUrls } = await extraction.batch({
284
+ * urls: [
285
+ * 'https://example.com/article1',
286
+ * 'https://example.com/article2',
287
+ * ],
288
+ * config: { mode: 'markdown' },
289
+ * });
290
+ * ```
291
+ */
292
+ batch(request: CreateBatchExtractionsRequest): Promise<CreateBatchResponse>;
293
+ /**
294
+ * Get a batch job by ID
295
+ */
296
+ getBatchJob(request: GetBatchJobRequest): Promise<BatchExtractionJob>;
297
+ /**
298
+ * List batch jobs with pagination and filters
299
+ */
300
+ listBatchJobs(request?: ListBatchJobsRequest): Promise<ExtractionBatchJobsResponse>;
301
+ /**
302
+ * Cancel a batch job
303
+ */
304
+ cancelBatchJob(request: GetBatchJobRequest): Promise<{
305
+ success: boolean;
306
+ }>;
307
+ /**
308
+ * Create a batch extraction job and wait for completion
309
+ */
310
+ batchAndWait(request: CreateBatchExtractionsRequest, options?: {
311
+ pollInterval?: number;
312
+ timeout?: number;
313
+ }): Promise<BatchExtractionJob>;
314
+ /**
315
+ * Create a scheduled extraction job
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * const { id } = await extraction.createSchedule({
320
+ * name: 'Daily price monitoring',
321
+ * url: 'https://competitor.com/pricing',
322
+ * frequency: 'daily',
323
+ * config: { mode: 'schema', schema: { ... } },
324
+ * });
325
+ * ```
326
+ */
327
+ createSchedule(request: CreateExtractionScheduleRequest): Promise<CreateScheduleResponse>;
328
+ /**
329
+ * Update a schedule
330
+ */
331
+ updateSchedule(request: UpdateExtractionScheduleRequest): Promise<{
332
+ success: boolean;
333
+ }>;
334
+ /**
335
+ * Get a schedule by ID
336
+ */
337
+ getSchedule(request: GetScheduleRequest): Promise<ExtractionSchedule>;
338
+ /**
339
+ * List schedules with pagination and filters
340
+ */
341
+ listSchedules(request?: ListSchedulesRequest): Promise<ExtractionSchedulesResponse>;
342
+ /**
343
+ * Delete a schedule
344
+ */
345
+ deleteSchedule(request: GetScheduleRequest): Promise<{
346
+ success: boolean;
347
+ }>;
348
+ /**
349
+ * Toggle a schedule on or off
350
+ */
351
+ toggleSchedule(request: GetScheduleRequest): Promise<{
352
+ isActive: boolean;
353
+ }>;
354
+ /**
355
+ * Get usage statistics
356
+ *
357
+ * @example
358
+ * ```typescript
359
+ * const usage = await extraction.getUsage({
360
+ * periodStart: '2024-01-01T00:00:00Z',
361
+ * periodEnd: '2024-01-31T23:59:59Z',
362
+ * });
363
+ * console.log(`Extractions: ${usage.extractionsTotal}`);
364
+ * console.log(`Tokens used: ${usage.extractionTokensUsed}`);
365
+ * ```
366
+ */
367
+ getUsage(request?: GetUsageRequest): Promise<ExtractionUsage>;
368
+ private convertDates;
369
+ private convertBatchJobDates;
370
+ private convertScheduleDates;
371
+ private convertUsageDates;
372
+ }
373
+
374
+ export { type BatchExtractionJob, type CreateBatchExtractionsRequest, type CreateExtractionRequest, type CreateExtractionResponse, type CreateExtractionScheduleRequest, Extraction, type ExtractionBatchJobsResponse, type ExtractionMode, type ExtractionResult, type ExtractionSchedule, type ExtractionSchedulesResponse, type ExtractionStatus, type ExtractionUsage, type GetExtractionRequest, type GetUsageRequest, type ListExtractionsRequest, type ListExtractionsResponse, type PageMetadata, type UpdateExtractionScheduleRequest };