newscatcher-catchall-sdk 0.1.0 → 0.2.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/cjs/BaseClient.d.ts +12 -4
- package/dist/cjs/BaseClient.js +14 -2
- package/dist/cjs/Client.d.ts +3 -3
- package/dist/cjs/Client.js +1 -1
- package/dist/cjs/api/errors/ForbiddenError.js +5 -1
- package/dist/cjs/api/errors/NotFoundError.js +5 -1
- package/dist/cjs/api/errors/UnprocessableEntityError.js +5 -1
- package/dist/cjs/api/resources/jobs/client/Client.d.ts +5 -7
- package/dist/cjs/api/resources/jobs/client/Client.js +16 -74
- package/dist/cjs/api/resources/jobs/client/requests/SubmitRequestDto.d.ts +2 -3
- package/dist/cjs/api/resources/meta/client/Client.d.ts +3 -4
- package/dist/cjs/api/resources/meta/client/Client.js +5 -38
- package/dist/cjs/api/resources/monitors/client/Client.d.ts +11 -6
- package/dist/cjs/api/resources/monitors/client/Client.js +28 -105
- package/dist/cjs/api/resources/monitors/client/requests/CreateMonitorRequestDto.d.ts +2 -5
- package/dist/cjs/api/types/ListUserJobsResponseDto.d.ts +4 -0
- package/dist/cjs/api/types/MonitorCitation.d.ts +2 -0
- package/dist/cjs/api/types/MonitorListItemDto.d.ts +5 -0
- package/dist/cjs/api/types/PullJobResponseDto.d.ts +5 -0
- package/dist/cjs/api/types/Schema.d.ts +1 -1
- package/dist/cjs/api/types/WebhookPayload.d.ts +2 -4
- package/dist/cjs/auth/HeaderAuthProvider.d.ts +16 -0
- package/dist/cjs/auth/HeaderAuthProvider.js +71 -0
- package/dist/cjs/auth/index.d.ts +1 -0
- package/dist/cjs/auth/index.js +5 -0
- package/dist/cjs/core/auth/AuthProvider.d.ts +7 -0
- package/dist/cjs/core/auth/AuthProvider.js +2 -0
- package/dist/cjs/core/auth/AuthRequest.d.ts +9 -0
- package/dist/cjs/core/auth/AuthRequest.js +2 -0
- package/dist/cjs/core/auth/BasicAuth.d.ts +8 -0
- package/dist/cjs/core/auth/BasicAuth.js +27 -0
- package/dist/cjs/core/auth/BearerToken.d.ts +7 -0
- package/dist/cjs/core/auth/BearerToken.js +16 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
- package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
- package/dist/cjs/core/auth/index.d.ts +5 -0
- package/dist/cjs/core/auth/index.js +9 -0
- package/dist/cjs/core/base64.d.ts +2 -0
- package/dist/cjs/core/base64.js +26 -0
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +6 -7
- package/dist/cjs/core/fetcher/Fetcher.d.ts +5 -1
- package/dist/cjs/core/fetcher/Fetcher.js +2 -1
- package/dist/cjs/core/fetcher/getResponseBody.js +18 -4
- package/dist/cjs/core/fetcher/signals.d.ts +1 -1
- package/dist/cjs/core/index.d.ts +2 -0
- package/dist/cjs/core/index.js +2 -0
- package/dist/cjs/core/runtime/runtime.js +11 -10
- package/dist/cjs/errors/CatchAllApiError.js +5 -1
- package/dist/cjs/errors/CatchAllApiTimeoutError.js +5 -1
- package/dist/cjs/errors/handleNonStatusCodeError.d.ts +2 -0
- package/dist/cjs/errors/handleNonStatusCodeError.js +65 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +12 -4
- package/dist/esm/BaseClient.mjs +13 -2
- package/dist/esm/Client.d.mts +3 -3
- package/dist/esm/Client.mjs +2 -2
- package/dist/esm/api/errors/ForbiddenError.mjs +5 -1
- package/dist/esm/api/errors/NotFoundError.mjs +5 -1
- package/dist/esm/api/errors/UnprocessableEntityError.mjs +5 -1
- package/dist/esm/api/resources/jobs/client/Client.d.mts +5 -7
- package/dist/esm/api/resources/jobs/client/Client.mjs +18 -76
- package/dist/esm/api/resources/jobs/client/requests/SubmitRequestDto.d.mts +2 -3
- package/dist/esm/api/resources/meta/client/Client.d.mts +3 -4
- package/dist/esm/api/resources/meta/client/Client.mjs +6 -39
- package/dist/esm/api/resources/monitors/client/Client.d.mts +11 -6
- package/dist/esm/api/resources/monitors/client/Client.mjs +30 -107
- package/dist/esm/api/resources/monitors/client/requests/CreateMonitorRequestDto.d.mts +2 -5
- package/dist/esm/api/types/ListUserJobsResponseDto.d.mts +4 -0
- package/dist/esm/api/types/MonitorCitation.d.mts +2 -0
- package/dist/esm/api/types/MonitorListItemDto.d.mts +5 -0
- package/dist/esm/api/types/PullJobResponseDto.d.mts +5 -0
- package/dist/esm/api/types/Schema.d.mts +1 -1
- package/dist/esm/api/types/WebhookPayload.d.mts +2 -4
- package/dist/esm/auth/HeaderAuthProvider.d.mts +16 -0
- package/dist/esm/auth/HeaderAuthProvider.mjs +34 -0
- package/dist/esm/auth/index.d.mts +1 -0
- package/dist/esm/auth/index.mjs +1 -0
- package/dist/esm/core/auth/AuthProvider.d.mts +7 -0
- package/dist/esm/core/auth/AuthProvider.mjs +1 -0
- package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
- package/dist/esm/core/auth/AuthRequest.mjs +1 -0
- package/dist/esm/core/auth/BasicAuth.d.mts +8 -0
- package/dist/esm/core/auth/BasicAuth.mjs +24 -0
- package/dist/esm/core/auth/BearerToken.d.mts +7 -0
- package/dist/esm/core/auth/BearerToken.mjs +13 -0
- package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
- package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
- package/dist/esm/core/auth/index.d.mts +5 -0
- package/dist/esm/core/auth/index.mjs +3 -0
- package/dist/esm/core/base64.d.mts +2 -0
- package/dist/esm/core/base64.mjs +22 -0
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +6 -7
- package/dist/esm/core/fetcher/Fetcher.d.mts +5 -1
- package/dist/esm/core/fetcher/Fetcher.mjs +2 -1
- package/dist/esm/core/fetcher/getResponseBody.mjs +18 -4
- package/dist/esm/core/fetcher/signals.d.mts +1 -1
- package/dist/esm/core/index.d.mts +2 -0
- package/dist/esm/core/index.mjs +2 -0
- package/dist/esm/core/runtime/runtime.mjs +11 -10
- package/dist/esm/errors/CatchAllApiError.mjs +5 -1
- package/dist/esm/errors/CatchAllApiTimeoutError.mjs +5 -1
- package/dist/esm/errors/handleNonStatusCodeError.d.mts +2 -0
- package/dist/esm/errors/handleNonStatusCodeError.mjs +29 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +5 -2
- package/reference.md +10 -5
- package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +0 -4
- package/dist/cjs/core/fetcher/ResponseWithBody.js +0 -6
- package/dist/esm/core/fetcher/ResponseWithBody.d.mts +0 -4
- package/dist/esm/core/fetcher/ResponseWithBody.mjs +0 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function base64ToBytes(base64) {
|
|
2
|
+
const binString = atob(base64);
|
|
3
|
+
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
4
|
+
}
|
|
5
|
+
function bytesToBase64(bytes) {
|
|
6
|
+
const binString = String.fromCodePoint(...bytes);
|
|
7
|
+
return btoa(binString);
|
|
8
|
+
}
|
|
9
|
+
export function base64Encode(input) {
|
|
10
|
+
if (typeof Buffer !== "undefined") {
|
|
11
|
+
return Buffer.from(input, "utf8").toString("base64");
|
|
12
|
+
}
|
|
13
|
+
const bytes = new TextEncoder().encode(input);
|
|
14
|
+
return bytesToBase64(bytes);
|
|
15
|
+
}
|
|
16
|
+
export function base64Decode(input) {
|
|
17
|
+
if (typeof Buffer !== "undefined") {
|
|
18
|
+
return Buffer.from(input, "base64").toString("utf8");
|
|
19
|
+
}
|
|
20
|
+
const bytes = base64ToBytes(input);
|
|
21
|
+
return new TextDecoder().decode(bytes);
|
|
22
|
+
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import type { ResponseWithBody } from "./ResponseWithBody.mjs";
|
|
2
1
|
export type BinaryResponse = {
|
|
3
2
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */
|
|
4
|
-
bodyUsed:
|
|
3
|
+
bodyUsed: Response["bodyUsed"];
|
|
5
4
|
/**
|
|
6
5
|
* Returns a ReadableStream of the response body.
|
|
7
6
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/body)
|
|
8
7
|
*/
|
|
9
|
-
stream: () =>
|
|
8
|
+
stream: () => Response["body"];
|
|
10
9
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */
|
|
11
|
-
arrayBuffer: () =>
|
|
10
|
+
arrayBuffer: () => ReturnType<Response["arrayBuffer"]>;
|
|
12
11
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
|
|
13
|
-
blob: () =>
|
|
12
|
+
blob: () => ReturnType<Response["blob"]>;
|
|
14
13
|
/**
|
|
15
14
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
|
|
16
15
|
* Some versions of the Fetch API may not support this method.
|
|
17
16
|
*/
|
|
18
|
-
bytes?():
|
|
17
|
+
bytes?(): ReturnType<Response["bytes"]>;
|
|
19
18
|
};
|
|
20
|
-
export declare function getBinaryResponse(response:
|
|
19
|
+
export declare function getBinaryResponse(response: Response): BinaryResponse;
|
|
@@ -22,7 +22,7 @@ export declare namespace Fetcher {
|
|
|
22
22
|
fetchFn?: typeof fetch;
|
|
23
23
|
logging?: LogConfig | Logger;
|
|
24
24
|
}
|
|
25
|
-
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
25
|
+
type Error = FailedStatusCodeError | NonJsonError | BodyIsNullError | TimeoutError | UnknownError;
|
|
26
26
|
interface FailedStatusCodeError {
|
|
27
27
|
reason: "status-code";
|
|
28
28
|
statusCode: number;
|
|
@@ -33,6 +33,10 @@ export declare namespace Fetcher {
|
|
|
33
33
|
statusCode: number;
|
|
34
34
|
rawBody: string;
|
|
35
35
|
}
|
|
36
|
+
interface BodyIsNullError {
|
|
37
|
+
reason: "body-is-null";
|
|
38
|
+
statusCode: number;
|
|
39
|
+
}
|
|
36
40
|
interface TimeoutError {
|
|
37
41
|
reason: "timeout";
|
|
38
42
|
}
|
|
@@ -208,9 +208,10 @@ export function fetcherImpl(args) {
|
|
|
208
208
|
};
|
|
209
209
|
logger.debug("HTTP request succeeded", metadata);
|
|
210
210
|
}
|
|
211
|
+
const body = yield getResponseBody(response, args.responseType);
|
|
211
212
|
return {
|
|
212
213
|
ok: true,
|
|
213
|
-
body:
|
|
214
|
+
body: body,
|
|
214
215
|
headers: response.headers,
|
|
215
216
|
rawResponse: toRawResponse(response),
|
|
216
217
|
};
|
|
@@ -9,12 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { fromJson } from "../json.mjs";
|
|
11
11
|
import { getBinaryResponse } from "./BinaryResponse.mjs";
|
|
12
|
-
import { isResponseWithBody } from "./ResponseWithBody.mjs";
|
|
13
12
|
export function getResponseBody(response, responseType) {
|
|
14
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
if (!isResponseWithBody(response)) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
14
|
switch (responseType) {
|
|
19
15
|
case "binary-response":
|
|
20
16
|
return getBinaryResponse(response);
|
|
@@ -23,8 +19,26 @@ export function getResponseBody(response, responseType) {
|
|
|
23
19
|
case "arrayBuffer":
|
|
24
20
|
return yield response.arrayBuffer();
|
|
25
21
|
case "sse":
|
|
22
|
+
if (response.body == null) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
error: {
|
|
26
|
+
reason: "body-is-null",
|
|
27
|
+
statusCode: response.status,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
26
31
|
return response.body;
|
|
27
32
|
case "streaming":
|
|
33
|
+
if (response.body == null) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
error: {
|
|
37
|
+
reason: "body-is-null",
|
|
38
|
+
statusCode: response.status,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
28
42
|
return response.body;
|
|
29
43
|
case "text":
|
|
30
44
|
return yield response.text();
|
package/dist/esm/core/index.mjs
CHANGED
|
@@ -68,6 +68,17 @@ function evaluateRuntime() {
|
|
|
68
68
|
version: Bun.version,
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* A constant that indicates whether the environment the code is running is in React-Native.
|
|
73
|
+
* This check should come before Node.js detection since React Native may have a process polyfill.
|
|
74
|
+
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
75
|
+
*/
|
|
76
|
+
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
77
|
+
if (isReactNative) {
|
|
78
|
+
return {
|
|
79
|
+
type: "react-native",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
71
82
|
/**
|
|
72
83
|
* A constant that indicates whether the environment the code is running is Node.JS.
|
|
73
84
|
*/
|
|
@@ -83,16 +94,6 @@ function evaluateRuntime() {
|
|
|
83
94
|
parsedVersion: Number(process.versions.node.split(".")[0]),
|
|
84
95
|
};
|
|
85
96
|
}
|
|
86
|
-
/**
|
|
87
|
-
* A constant that indicates whether the environment the code is running is in React-Native.
|
|
88
|
-
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
|
|
89
|
-
*/
|
|
90
|
-
const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
|
|
91
|
-
if (isReactNative) {
|
|
92
|
-
return {
|
|
93
|
-
type: "react-native",
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
97
|
return {
|
|
97
98
|
type: "unknown",
|
|
98
99
|
};
|
|
@@ -3,7 +3,11 @@ import { toJson } from "../core/json.mjs";
|
|
|
3
3
|
export class CatchAllApiError extends Error {
|
|
4
4
|
constructor({ message, statusCode, body, rawResponse, }) {
|
|
5
5
|
super(buildMessage({ message, statusCode, body }));
|
|
6
|
-
Object.setPrototypeOf(this,
|
|
6
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
+
if (Error.captureStackTrace) {
|
|
8
|
+
Error.captureStackTrace(this, this.constructor);
|
|
9
|
+
}
|
|
10
|
+
this.name = this.constructor.name;
|
|
7
11
|
this.statusCode = statusCode;
|
|
8
12
|
this.body = body;
|
|
9
13
|
this.rawResponse = rawResponse;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
export class CatchAllApiTimeoutError extends Error {
|
|
3
3
|
constructor(message) {
|
|
4
4
|
super(message);
|
|
5
|
-
Object.setPrototypeOf(this,
|
|
5
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
6
|
+
if (Error.captureStackTrace) {
|
|
7
|
+
Error.captureStackTrace(this, this.constructor);
|
|
8
|
+
}
|
|
9
|
+
this.name = this.constructor.name;
|
|
6
10
|
}
|
|
7
11
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
import * as errors from "./index.mjs";
|
|
3
|
+
export function handleNonStatusCodeError(error, rawResponse, method, path) {
|
|
4
|
+
switch (error.reason) {
|
|
5
|
+
case "non-json":
|
|
6
|
+
throw new errors.CatchAllApiError({
|
|
7
|
+
statusCode: error.statusCode,
|
|
8
|
+
body: error.rawBody,
|
|
9
|
+
rawResponse: rawResponse,
|
|
10
|
+
});
|
|
11
|
+
case "body-is-null":
|
|
12
|
+
throw new errors.CatchAllApiError({
|
|
13
|
+
statusCode: error.statusCode,
|
|
14
|
+
rawResponse: rawResponse,
|
|
15
|
+
});
|
|
16
|
+
case "timeout":
|
|
17
|
+
throw new errors.CatchAllApiTimeoutError(`Timeout exceeded when calling ${method} ${path}.`);
|
|
18
|
+
case "unknown":
|
|
19
|
+
throw new errors.CatchAllApiError({
|
|
20
|
+
message: error.errorMessage,
|
|
21
|
+
rawResponse: rawResponse,
|
|
22
|
+
});
|
|
23
|
+
default:
|
|
24
|
+
throw new errors.CatchAllApiError({
|
|
25
|
+
message: "Unknown error",
|
|
26
|
+
rawResponse: rawResponse,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.2.0";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.2.0";
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "newscatcher-catchall-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Newscatcher/newscatcher-catchall-typescript.git"
|
|
8
|
+
},
|
|
6
9
|
"license": "MIT",
|
|
7
10
|
"type": "commonjs",
|
|
8
11
|
"main": "./dist/cjs/index.js",
|
package/reference.md
CHANGED
|
@@ -28,9 +28,8 @@ Submit a natural language query to create a new processing job.
|
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
30
|
await client.jobs.createJob({
|
|
31
|
-
query: "
|
|
32
|
-
|
|
33
|
-
context: "Focus on revenue and profit margins"
|
|
31
|
+
query: "AI company acquisitions",
|
|
32
|
+
context: "Focus on deal size and acquiring company details"
|
|
34
33
|
});
|
|
35
34
|
|
|
36
35
|
```
|
|
@@ -267,8 +266,14 @@ await client.jobs.getJobResults({
|
|
|
267
266
|
|
|
268
267
|
Create a monitor that runs jobs based on a reference job with a specified schedule.
|
|
269
268
|
|
|
270
|
-
**
|
|
271
|
-
|
|
269
|
+
**Schedule requirements:**
|
|
270
|
+
- Minimum 24-hour interval between executions
|
|
271
|
+
- Natural language format (e.g., "every day at 12 PM UTC", "every 48 hours")
|
|
272
|
+
|
|
273
|
+
**Validation:**
|
|
274
|
+
- Schedules below minimum frequency return error with descriptive message.
|
|
275
|
+
- Invalid job IDs return 400 Bad Request.
|
|
276
|
+
- Duplicate monitors (same job already monitored) return error.
|
|
272
277
|
</dd>
|
|
273
278
|
</dl>
|
|
274
279
|
</dd>
|