newscatcher-catchall-sdk 0.3.0 → 0.3.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/README.md CHANGED
@@ -1,290 +1,190 @@
1
- # Newscatcher CatchAll TypeScript Library
1
+ # Newscatcher TypeScript Library
2
2
 
3
3
  [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FNewscatcher%2Fnewscatcher-catchall-typescript)
4
4
  [![npm shield](https://img.shields.io/npm/v/newscatcher-catchall-sdk)](https://www.npmjs.com/package/newscatcher-catchall-sdk)
5
5
 
6
- The Newscatcher CatchAll TypeScript library provides access to the [CatchAll API](https://www.newscatcherapi.com/docs/v3/catch-all/overview/introduction), which transforms natural language queries into structured data extracted from web sources.
6
+ The Newscatcher TypeScript library provides convenient access to the Newscatcher APIs from TypeScript.
7
+
8
+ ## Table of Contents
9
+
10
+ - [Documentation](#documentation)
11
+ - [Installation](#installation)
12
+ - [Reference](#reference)
13
+ - [Usage](#usage)
14
+ - [Request and Response Types](#request-and-response-types)
15
+ - [Exception Handling](#exception-handling)
16
+ - [Advanced](#advanced)
17
+ - [Additional Headers](#additional-headers)
18
+ - [Additional Query String Parameters](#additional-query-string-parameters)
19
+ - [Retries](#retries)
20
+ - [Timeouts](#timeouts)
21
+ - [Aborting Requests](#aborting-requests)
22
+ - [Access Raw Response Data](#access-raw-response-data)
23
+ - [Logging](#logging)
24
+ - [Runtime Compatibility](#runtime-compatibility)
25
+ - [Beta Status](#beta-status)
26
+ - [Contributing](#contributing)
27
+ - [Support](#support)
28
+
29
+ ## Documentation
30
+
31
+ API reference documentation is available [here](https://www.newscatcherapi.com/docs/v3/catch-all/endpoints/create-job).
7
32
 
8
33
  ## Installation
9
34
 
10
35
  ```sh
11
- npm install newscatcher-catchall-sdk
36
+ npm i -s newscatcher-catchall-sdk
12
37
  ```
13
38
 
14
39
  ## Reference
15
40
 
16
- A full reference for this library is available [here](./reference.md).
41
+ A full reference for this library is available [here](https://github.com/Newscatcher/newscatcher-catchall-typescript/blob/HEAD/./reference.md).
17
42
 
18
43
  ## Usage
19
44
 
20
- ### Jobs
21
-
22
- Submit a query and retrieve structured results:
45
+ Instantiate and use the client with the following:
23
46
 
24
47
  ```typescript
25
48
  import { CatchAllApiClient } from "newscatcher-catchall-sdk";
26
49
 
27
50
  const client = new CatchAllApiClient({ apiKey: "YOUR_API_KEY" });
28
-
29
- // Create a job with optional limit for testing
30
- const job = await client.jobs.createJob({
31
- query: "Tech company earnings this quarter",
32
- context: "Focus on revenue and profit margins",
33
- limit: 10, // Start with 10 records for quick testing
51
+ await client.jobs.createJob({
52
+ query: "AI company acquisitions",
53
+ context: "Focus on deal size and acquiring company details"
34
54
  });
35
- console.log(`Job created: ${job.jobId}`);
36
-
37
- // Poll for completion with progress updates
38
- while (true) {
39
- const status = await client.jobs.getJobStatus(job.jobId);
40
-
41
- // Check if completed or enriching (early access)
42
- const currentStatus = status.status;
43
- if (currentStatus === "completed" || currentStatus === "enriching") {
44
- console.log(`Job ${currentStatus}!`);
45
- break;
46
- }
47
-
48
- // Show current processing step
49
- const currentStep = status.steps.find(s => !s.completed);
50
- if (currentStep) {
51
- console.log(`Processing: ${currentStep.status} (step ${currentStep.order}/7)`);
52
- }
53
-
54
- await new Promise(resolve => setTimeout(resolve, 60000)); // Wait 60 seconds
55
- }
56
-
57
- // Retrieve initial results (available during enriching stage)
58
- const results = await client.jobs.getJobResults(job.jobId);
59
- console.log(`Found ${results.validRecords} valid records`);
60
- console.log(`Progress: ${results.progressValidated}/${results.candidateRecords} validated`);
61
-
62
- // Continue job to process more records
63
- if (results.validRecords >= 10) {
64
- const continued = await client.jobs.continueJob({
65
- jobId: job.jobId,
66
- newLimit: 50, // Increase to 50 records
67
- });
68
- console.log(`Job continued: ${continued.jobId}`);
69
-
70
- // Wait for completion
71
- while (true) {
72
- const status = await client.jobs.getJobStatus(job.jobId);
73
- if (status.status === "completed") {
74
- break;
75
- }
76
- await new Promise(resolve => setTimeout(resolve, 60000));
77
- }
78
-
79
- // Get final results
80
- const finalResults = await client.jobs.getJobResults(job.jobId);
81
- console.log(`Final: ${finalResults.validRecords} records`);
82
- }
83
55
  ```
84
56
 
85
- Jobs process asynchronously and typically complete in 10-15 minutes. To learn more, see the [Quickstart](https://www.newscatcherapi.com/docs/v3/catch-all/overview/quickstart).
86
-
87
- ### Monitors
57
+ ## Request and Response Types
88
58
 
89
- Automate recurring queries with scheduled execution:
90
-
91
- ```typescript
92
- import { CatchAllApiClient } from "newscatcher-catchall-sdk";
93
-
94
- const client = new CatchAllApiClient({ apiKey: "YOUR_API_KEY" });
95
-
96
- // Create a monitor from a completed job
97
- const monitor = await client.monitors.createMonitor({
98
- referenceJobId: job.jobId,
99
- schedule: "every day at 12 PM UTC",
100
- webhook: {
101
- url: "https://your-endpoint.com/webhook",
102
- method: "POST",
103
- headers: { "Authorization": "Bearer YOUR_TOKEN" },
104
- },
105
- });
106
- console.log(`Monitor created: ${monitor.monitorId}`);
107
-
108
- // Update webhook configuration without recreating monitor
109
- const updated = await client.monitors.updateMonitor(monitor.monitorId, {
110
- webhook: {
111
- url: "https://new-endpoint.com/webhook",
112
- method: "POST",
113
- headers: { "Authorization": "Bearer NEW_TOKEN" },
114
- },
115
- });
116
-
117
- // Pause monitor execution
118
- await client.monitors.disableMonitor(monitor.monitorId);
119
- console.log("Monitor paused");
120
-
121
- // Resume monitor execution
122
- await client.monitors.enableMonitor(monitor.monitorId);
123
- console.log("Monitor resumed");
124
-
125
- // List monitor execution history
126
- const jobs = await client.monitors.listMonitorJobs(monitor.monitorId, {
127
- sort: "desc", // Most recent first
128
- });
129
- console.log(`Monitor has executed ${jobs.totalJobs} jobs`);
130
- for (const job of jobs.jobs) {
131
- console.log(` Job ${job.jobId}: ${job.startDate} to ${job.endDate}`);
132
- }
133
-
134
- // Get aggregated results
135
- const results = await client.monitors.pullMonitorResults(monitor.monitorId);
136
- console.log(`Collected ${results.records} records across all executions`);
137
- ```
138
-
139
- Monitors run jobs on your schedule and send webhook notifications when complete. See the [Monitors documentation](https://www.newscatcherapi.com/docs/v3/catch-all/overview/monitors) for setup and configuration.
140
-
141
- ## Request and response types
142
-
143
- The SDK exports all request and response types as TypeScript interfaces:
59
+ The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
60
+ following namespace:
144
61
 
145
62
  ```typescript
146
63
  import { CatchAllApi } from "newscatcher-catchall-sdk";
147
64
 
148
65
  const request: CatchAllApi.SubmitRequestDto = {
149
- query: "Tech company earnings this quarter",
150
- context: "Focus on revenue and profit margins",
66
+ ...
151
67
  };
152
68
  ```
153
69
 
154
- ## Exception handling
70
+ ## Exception Handling
155
71
 
156
- Handle API errors with the `CatchAllApiError` exception:
72
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
73
+ will be thrown.
157
74
 
158
75
  ```typescript
159
76
  import { CatchAllApiError } from "newscatcher-catchall-sdk";
160
77
 
161
78
  try {
162
- await client.jobs.createJob({
163
- query: "Tech company earnings this quarter",
164
- });
79
+ await client.jobs.createJob(...);
165
80
  } catch (err) {
166
81
  if (err instanceof CatchAllApiError) {
167
- console.log(`Status: ${err.statusCode}`);
168
- console.log(`Message: ${err.message}`);
169
- console.log(`Body: ${JSON.stringify(err.body)}`);
82
+ console.log(err.statusCode);
83
+ console.log(err.message);
84
+ console.log(err.body);
85
+ console.log(err.rawResponse);
170
86
  }
171
87
  }
172
88
  ```
173
89
 
174
90
  ## Advanced
175
91
 
176
- ### Pagination
177
-
178
- Retrieve large result sets with pagination:
179
-
180
- ```typescript
181
- // Retrieve large result sets with pagination
182
- let page = 1;
183
- while (true) {
184
- const results = await client.jobs.getJobResults(
185
- jobId,
186
- {
187
- page: page,
188
- pageSize: 100,
189
- }
190
- );
191
-
192
- console.log(`Page ${results.page}/${results.totalPages}: ${results.allRecords.length} records`);
193
-
194
- for (const record of results.allRecords) {
195
- // Process each record
196
- console.log(` - ${record.recordTitle}`);
197
- }
198
-
199
- if (results.page >= results.totalPages) {
200
- break;
201
- }
202
- page++;
203
- }
204
-
205
- console.log(`Processed ${results.validRecords} total records`);
206
- ```
207
-
208
- ### Access raw response data
92
+ ### Additional Headers
209
93
 
210
- Access response headers and raw data:
94
+ If you would like to send additional headers as part of the request, use the `headers` request option.
211
95
 
212
96
  ```typescript
213
- const { data, rawResponse } = await client.jobs.createJob({
214
- query: "Tech company earnings this quarter",
215
- }).withRawResponse();
216
-
217
- console.log(data);
218
- console.log(rawResponse.headers.get('X-Custom-Header'));
219
- ```
220
-
221
- ### Additional headers
97
+ import { CatchAllApiClient } from "newscatcher-catchall-sdk";
222
98
 
223
- Send custom headers with your request:
99
+ const client = new CatchAllApiClient({
100
+ ...
101
+ headers: {
102
+ 'X-Custom-Header': 'custom value'
103
+ }
104
+ });
224
105
 
225
- ```typescript
226
- const response = await client.jobs.createJob({
227
- query: "Tech company earnings this quarter",
228
- }, {
106
+ const response = await client.jobs.createJob(..., {
229
107
  headers: {
230
108
  'X-Custom-Header': 'custom value'
231
109
  }
232
110
  });
233
111
  ```
234
112
 
235
- ### Retries
113
+ ### Additional Query String Parameters
236
114
 
237
- The SDK retries failed requests automatically with exponential backoff. Configure retry behavior:
115
+ If you would like to send additional query string parameters as part of the request, use the `queryParams` request option.
238
116
 
239
117
  ```typescript
240
- const response = await client.jobs.createJob({
241
- query: "Tech company earnings this quarter",
242
- }, {
243
- maxRetries: 3, // override maxRetries at the request level (default: 2)
118
+ const response = await client.jobs.createJob(..., {
119
+ queryParams: {
120
+ 'customQueryParamKey': 'custom query param value'
121
+ }
244
122
  });
245
123
  ```
246
124
 
247
- A request is retried when any of these HTTP status codes is returned:
125
+ ### Retries
126
+
127
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
128
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
129
+ retry limit (default: 2).
130
+
131
+ A request is deemed retryable when any of the following HTTP status codes is returned:
248
132
 
249
133
  - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
250
134
  - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
251
135
  - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
252
136
 
137
+ Use the `maxRetries` request option to configure this behavior.
138
+
139
+ ```typescript
140
+ const response = await client.jobs.createJob(..., {
141
+ maxRetries: 0 // override maxRetries at the request level
142
+ });
143
+ ```
144
+
253
145
  ### Timeouts
254
146
 
255
- Set custom timeouts at the request level:
147
+ The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
256
148
 
257
149
  ```typescript
258
- const response = await client.jobs.createJob({
259
- query: "Tech company earnings this quarter",
260
- }, {
261
- timeoutInSeconds: 30, // override timeout to 30s (default: 60s)
150
+ const response = await client.jobs.createJob(..., {
151
+ timeoutInSeconds: 30 // override timeout to 30s
262
152
  });
263
153
  ```
264
154
 
265
- ### Aborting requests
155
+ ### Aborting Requests
266
156
 
267
- Cancel requests using an abort signal:
157
+ The SDK allows users to abort requests at any point by passing in an abort signal.
268
158
 
269
159
  ```typescript
270
160
  const controller = new AbortController();
271
- const response = await client.jobs.createJob({
272
- query: "Tech company earnings this quarter",
273
- }, {
161
+ const response = await client.jobs.createJob(..., {
274
162
  abortSignal: controller.signal
275
163
  });
276
- controller.abort(); // cancels the request
164
+ controller.abort(); // aborts the request
165
+ ```
166
+
167
+ ### Access Raw Response Data
168
+
169
+ The SDK provides access to raw response data, including headers, through the `.withRawResponse()` method.
170
+ The `.withRawResponse()` method returns a promise that results to an object with a `data` and a `rawResponse` property.
171
+
172
+ ```typescript
173
+ const { data, rawResponse } = await client.jobs.createJob(...).withRawResponse();
174
+
175
+ console.log(data);
176
+ console.log(rawResponse.headers['X-My-Header']);
277
177
  ```
278
178
 
279
179
  ### Logging
280
180
 
281
- Configure logging to debug SDK behavior:
181
+ The SDK supports logging. You can configure the logger by passing in a `logging` object to the client options.
282
182
 
283
183
  ```typescript
284
184
  import { CatchAllApiClient, logging } from "newscatcher-catchall-sdk";
285
185
 
286
186
  const client = new CatchAllApiClient({
287
- apiKey: "YOUR_API_KEY",
187
+ ...
288
188
  logging: {
289
189
  level: logging.LogLevel.Debug, // defaults to logging.LogLevel.Info
290
190
  logger: new logging.ConsoleLogger(), // defaults to ConsoleLogger
@@ -292,20 +192,24 @@ const client = new CatchAllApiClient({
292
192
  }
293
193
  });
294
194
  ```
195
+ The `logging` object can have the following properties:
196
+ - `level`: The log level to use. Defaults to `logging.LogLevel.Info`.
197
+ - `logger`: The logger to use. Defaults to a `logging.ConsoleLogger`.
198
+ - `silent`: Whether to silence the logger. Defaults to `true`.
295
199
 
296
- Available log levels:
297
-
200
+ The `level` property can be one of the following values:
298
201
  - `logging.LogLevel.Debug`
299
202
  - `logging.LogLevel.Info`
300
203
  - `logging.LogLevel.Warn`
301
204
  - `logging.LogLevel.Error`
302
205
 
206
+ To provide a custom logger, you can pass in an object that implements the `logging.ILogger` interface.
207
+
303
208
  <details>
304
209
  <summary>Custom logger examples</summary>
305
210
 
306
- Using Winston:
307
-
308
- ```typescript
211
+ Here's an example using the popular `winston` logging library.
212
+ ```ts
309
213
  import winston from 'winston';
310
214
 
311
215
  const winstonLogger = winston.createLogger({...});
@@ -318,27 +222,30 @@ const logger: logging.ILogger = {
318
222
  };
319
223
  ```
320
224
 
321
- Using Pino:
225
+ Here's an example using the popular `pino` logging library.
322
226
 
323
- ```typescript
227
+ ```ts
324
228
  import pino from 'pino';
325
229
 
326
230
  const pinoLogger = pino({...});
327
231
 
328
232
  const logger: logging.ILogger = {
329
- debug: (msg, ...args) => pinoLogger.debug(args, msg),
330
- info: (msg, ...args) => pinoLogger.info(args, msg),
331
- warn: (msg, ...args) => pinoLogger.warn(args, msg),
332
- error: (msg, ...args) => pinoLogger.error(args, msg),
233
+ debug: (msg, ...args) => pinoLogger.debug(args, msg),
234
+ info: (msg, ...args) => pinoLogger.info(args, msg),
235
+ warn: (msg, ...args) => pinoLogger.warn(args, msg),
236
+ error: (msg, ...args) => pinoLogger.error(args, msg),
333
237
  };
334
238
  ```
335
-
336
239
  </details>
337
240
 
338
- ### Runtime compatibility
241
+
242
+ ### Runtime Compatibility
243
+
339
244
 
340
245
  The SDK works in the following runtimes:
341
246
 
247
+
248
+
342
249
  - Node.js 18+
343
250
  - Vercel
344
251
  - Cloudflare Workers
@@ -346,15 +253,16 @@ The SDK works in the following runtimes:
346
253
  - Bun 1.0+
347
254
  - React Native
348
255
 
349
- ### Custom fetch client
256
+ ### Customizing Fetch Client
350
257
 
351
- Customize the underlying HTTP client for unsupported environments:
258
+ The SDK provides a way for you to customize the underlying HTTP client / Fetch function. If you're running in an
259
+ unsupported environment, this provides a way for you to break glass and ensure the SDK works.
352
260
 
353
261
  ```typescript
354
262
  import { CatchAllApiClient } from "newscatcher-catchall-sdk";
355
263
 
356
264
  const client = new CatchAllApiClient({
357
- apiKey: "YOUR_API_KEY",
265
+ ...
358
266
  fetcher: // provide your implementation here
359
267
  });
360
268
  ```
@@ -365,8 +273,13 @@ CatchAll API is in beta. Breaking changes may occur in minor version updates. Se
365
273
 
366
274
  ## Contributing
367
275
 
368
- This library is generated programmatically from our API specification. Direct contributions to the generated code cannot be merged, but README improvements are welcome. To suggest SDK changes, please [open an issue](https://github.com/Newscatcher/newscatcher-catchall-typescript/issues).
276
+ While we value open-source contributions to this SDK, this library is generated programmatically.
277
+ Additions made directly to this library would have to be moved over to our generation code,
278
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
279
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
280
+ an issue first to discuss with us!
369
281
 
282
+ On the other hand, contributions to the README are always very welcome!
370
283
  ## Support
371
284
 
372
285
  - Documentation: [https://www.newscatcherapi.com/docs/v3/catch-all](https://www.newscatcherapi.com/docs/v3/catch-all)
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
43
43
  const headers = (0, headers_js_1.mergeHeaders)({
44
44
  "X-Fern-Language": "JavaScript",
45
45
  "X-Fern-SDK-Name": "newscatcher-catchall-sdk",
46
- "X-Fern-SDK-Version": "0.3.0",
47
- "User-Agent": "newscatcher-catchall-sdk/0.3.0",
46
+ "X-Fern-SDK-Version": "0.3.1",
47
+ "User-Agent": "newscatcher-catchall-sdk/0.3.1",
48
48
  "X-Fern-Runtime": core.RUNTIME.type,
49
49
  "X-Fern-Runtime-Version": core.RUNTIME.version,
50
50
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.3.0";
1
+ export declare const SDK_VERSION = "0.3.1";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.3.0";
4
+ exports.SDK_VERSION = "0.3.1";
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
6
6
  const headers = mergeHeaders({
7
7
  "X-Fern-Language": "JavaScript",
8
8
  "X-Fern-SDK-Name": "newscatcher-catchall-sdk",
9
- "X-Fern-SDK-Version": "0.3.0",
10
- "User-Agent": "newscatcher-catchall-sdk/0.3.0",
9
+ "X-Fern-SDK-Version": "0.3.1",
10
+ "User-Agent": "newscatcher-catchall-sdk/0.3.1",
11
11
  "X-Fern-Runtime": core.RUNTIME.type,
12
12
  "X-Fern-Runtime-Version": core.RUNTIME.version,
13
13
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.3.0";
1
+ export declare const SDK_VERSION = "0.3.1";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.3.0";
1
+ export const SDK_VERSION = "0.3.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newscatcher-catchall-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",