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.
Files changed (112) hide show
  1. package/dist/cjs/BaseClient.d.ts +12 -4
  2. package/dist/cjs/BaseClient.js +14 -2
  3. package/dist/cjs/Client.d.ts +3 -3
  4. package/dist/cjs/Client.js +1 -1
  5. package/dist/cjs/api/errors/ForbiddenError.js +5 -1
  6. package/dist/cjs/api/errors/NotFoundError.js +5 -1
  7. package/dist/cjs/api/errors/UnprocessableEntityError.js +5 -1
  8. package/dist/cjs/api/resources/jobs/client/Client.d.ts +5 -7
  9. package/dist/cjs/api/resources/jobs/client/Client.js +16 -74
  10. package/dist/cjs/api/resources/jobs/client/requests/SubmitRequestDto.d.ts +2 -3
  11. package/dist/cjs/api/resources/meta/client/Client.d.ts +3 -4
  12. package/dist/cjs/api/resources/meta/client/Client.js +5 -38
  13. package/dist/cjs/api/resources/monitors/client/Client.d.ts +11 -6
  14. package/dist/cjs/api/resources/monitors/client/Client.js +28 -105
  15. package/dist/cjs/api/resources/monitors/client/requests/CreateMonitorRequestDto.d.ts +2 -5
  16. package/dist/cjs/api/types/ListUserJobsResponseDto.d.ts +4 -0
  17. package/dist/cjs/api/types/MonitorCitation.d.ts +2 -0
  18. package/dist/cjs/api/types/MonitorListItemDto.d.ts +5 -0
  19. package/dist/cjs/api/types/PullJobResponseDto.d.ts +5 -0
  20. package/dist/cjs/api/types/Schema.d.ts +1 -1
  21. package/dist/cjs/api/types/WebhookPayload.d.ts +2 -4
  22. package/dist/cjs/auth/HeaderAuthProvider.d.ts +16 -0
  23. package/dist/cjs/auth/HeaderAuthProvider.js +71 -0
  24. package/dist/cjs/auth/index.d.ts +1 -0
  25. package/dist/cjs/auth/index.js +5 -0
  26. package/dist/cjs/core/auth/AuthProvider.d.ts +7 -0
  27. package/dist/cjs/core/auth/AuthProvider.js +2 -0
  28. package/dist/cjs/core/auth/AuthRequest.d.ts +9 -0
  29. package/dist/cjs/core/auth/AuthRequest.js +2 -0
  30. package/dist/cjs/core/auth/BasicAuth.d.ts +8 -0
  31. package/dist/cjs/core/auth/BasicAuth.js +27 -0
  32. package/dist/cjs/core/auth/BearerToken.d.ts +7 -0
  33. package/dist/cjs/core/auth/BearerToken.js +16 -0
  34. package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
  35. package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
  36. package/dist/cjs/core/auth/index.d.ts +5 -0
  37. package/dist/cjs/core/auth/index.js +9 -0
  38. package/dist/cjs/core/base64.d.ts +2 -0
  39. package/dist/cjs/core/base64.js +26 -0
  40. package/dist/cjs/core/fetcher/BinaryResponse.d.ts +6 -7
  41. package/dist/cjs/core/fetcher/Fetcher.d.ts +5 -1
  42. package/dist/cjs/core/fetcher/Fetcher.js +2 -1
  43. package/dist/cjs/core/fetcher/getResponseBody.js +18 -4
  44. package/dist/cjs/core/fetcher/signals.d.ts +1 -1
  45. package/dist/cjs/core/index.d.ts +2 -0
  46. package/dist/cjs/core/index.js +2 -0
  47. package/dist/cjs/core/runtime/runtime.js +11 -10
  48. package/dist/cjs/errors/CatchAllApiError.js +5 -1
  49. package/dist/cjs/errors/CatchAllApiTimeoutError.js +5 -1
  50. package/dist/cjs/errors/handleNonStatusCodeError.d.ts +2 -0
  51. package/dist/cjs/errors/handleNonStatusCodeError.js +65 -0
  52. package/dist/cjs/version.d.ts +1 -1
  53. package/dist/cjs/version.js +1 -1
  54. package/dist/esm/BaseClient.d.mts +12 -4
  55. package/dist/esm/BaseClient.mjs +13 -2
  56. package/dist/esm/Client.d.mts +3 -3
  57. package/dist/esm/Client.mjs +2 -2
  58. package/dist/esm/api/errors/ForbiddenError.mjs +5 -1
  59. package/dist/esm/api/errors/NotFoundError.mjs +5 -1
  60. package/dist/esm/api/errors/UnprocessableEntityError.mjs +5 -1
  61. package/dist/esm/api/resources/jobs/client/Client.d.mts +5 -7
  62. package/dist/esm/api/resources/jobs/client/Client.mjs +18 -76
  63. package/dist/esm/api/resources/jobs/client/requests/SubmitRequestDto.d.mts +2 -3
  64. package/dist/esm/api/resources/meta/client/Client.d.mts +3 -4
  65. package/dist/esm/api/resources/meta/client/Client.mjs +6 -39
  66. package/dist/esm/api/resources/monitors/client/Client.d.mts +11 -6
  67. package/dist/esm/api/resources/monitors/client/Client.mjs +30 -107
  68. package/dist/esm/api/resources/monitors/client/requests/CreateMonitorRequestDto.d.mts +2 -5
  69. package/dist/esm/api/types/ListUserJobsResponseDto.d.mts +4 -0
  70. package/dist/esm/api/types/MonitorCitation.d.mts +2 -0
  71. package/dist/esm/api/types/MonitorListItemDto.d.mts +5 -0
  72. package/dist/esm/api/types/PullJobResponseDto.d.mts +5 -0
  73. package/dist/esm/api/types/Schema.d.mts +1 -1
  74. package/dist/esm/api/types/WebhookPayload.d.mts +2 -4
  75. package/dist/esm/auth/HeaderAuthProvider.d.mts +16 -0
  76. package/dist/esm/auth/HeaderAuthProvider.mjs +34 -0
  77. package/dist/esm/auth/index.d.mts +1 -0
  78. package/dist/esm/auth/index.mjs +1 -0
  79. package/dist/esm/core/auth/AuthProvider.d.mts +7 -0
  80. package/dist/esm/core/auth/AuthProvider.mjs +1 -0
  81. package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
  82. package/dist/esm/core/auth/AuthRequest.mjs +1 -0
  83. package/dist/esm/core/auth/BasicAuth.d.mts +8 -0
  84. package/dist/esm/core/auth/BasicAuth.mjs +24 -0
  85. package/dist/esm/core/auth/BearerToken.d.mts +7 -0
  86. package/dist/esm/core/auth/BearerToken.mjs +13 -0
  87. package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
  88. package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
  89. package/dist/esm/core/auth/index.d.mts +5 -0
  90. package/dist/esm/core/auth/index.mjs +3 -0
  91. package/dist/esm/core/base64.d.mts +2 -0
  92. package/dist/esm/core/base64.mjs +22 -0
  93. package/dist/esm/core/fetcher/BinaryResponse.d.mts +6 -7
  94. package/dist/esm/core/fetcher/Fetcher.d.mts +5 -1
  95. package/dist/esm/core/fetcher/Fetcher.mjs +2 -1
  96. package/dist/esm/core/fetcher/getResponseBody.mjs +18 -4
  97. package/dist/esm/core/fetcher/signals.d.mts +1 -1
  98. package/dist/esm/core/index.d.mts +2 -0
  99. package/dist/esm/core/index.mjs +2 -0
  100. package/dist/esm/core/runtime/runtime.mjs +11 -10
  101. package/dist/esm/errors/CatchAllApiError.mjs +5 -1
  102. package/dist/esm/errors/CatchAllApiTimeoutError.mjs +5 -1
  103. package/dist/esm/errors/handleNonStatusCodeError.d.mts +2 -0
  104. package/dist/esm/errors/handleNonStatusCodeError.mjs +29 -0
  105. package/dist/esm/version.d.mts +1 -1
  106. package/dist/esm/version.mjs +1 -1
  107. package/package.json +5 -2
  108. package/reference.md +10 -5
  109. package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +0 -4
  110. package/dist/cjs/core/fetcher/ResponseWithBody.js +0 -6
  111. package/dist/esm/core/fetcher/ResponseWithBody.d.mts +0 -4
  112. 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: boolean;
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: () => ReadableStream<Uint8Array>;
8
+ stream: () => Response["body"];
10
9
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */
11
- arrayBuffer: () => Promise<ArrayBuffer>;
10
+ arrayBuffer: () => ReturnType<Response["arrayBuffer"]>;
12
11
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
13
- blob: () => Promise<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?(): Promise<Uint8Array>;
17
+ bytes?(): ReturnType<Response["bytes"]>;
19
18
  };
20
- export declare function getBinaryResponse(response: ResponseWithBody): BinaryResponse;
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: (yield getResponseBody(response, args.responseType)),
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();
@@ -1,5 +1,5 @@
1
1
  export declare function getTimeoutSignal(timeoutMs: number): {
2
2
  signal: AbortSignal;
3
- abortId: NodeJS.Timeout;
3
+ abortId: ReturnType<typeof setTimeout>;
4
4
  };
5
5
  export declare function anySignal(...args: AbortSignal[] | [AbortSignal[]]): AbortSignal;
@@ -1,3 +1,5 @@
1
+ export * from "./auth/index.mjs";
2
+ export * from "./base64.mjs";
1
3
  export * from "./fetcher/index.mjs";
2
4
  export * as logging from "./logging/index.mjs";
3
5
  export * from "./runtime/index.mjs";
@@ -1,3 +1,5 @@
1
+ export * from "./auth/index.mjs";
2
+ export * from "./base64.mjs";
1
3
  export * from "./fetcher/index.mjs";
2
4
  export * as logging from "./logging/index.mjs";
3
5
  export * from "./runtime/index.mjs";
@@ -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, CatchAllApiError.prototype);
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, CatchAllApiTimeoutError.prototype);
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,2 @@
1
+ import type * as core from "../core/index.mjs";
2
+ export declare function handleNonStatusCodeError(error: core.Fetcher.Error, rawResponse: core.RawResponse, method: string, path: string): never;
@@ -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
+ }
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.0";
1
+ export declare const SDK_VERSION = "0.2.0";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.1.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.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
- "repository": "github:Newscatcher/newscatcher-catchall-typescript",
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: "Tech company earnings this quarter",
32
- schema: "Company [NAME] earned [REVENUE] in [QUARTER]",
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
- **Warning**: Schedule validation is limited. Invalid schedules may be parsed incorrectly.
271
- Always test schedules before production use.
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>
@@ -1,4 +0,0 @@
1
- export type ResponseWithBody = Response & {
2
- body: ReadableStream<Uint8Array>;
3
- };
4
- export declare function isResponseWithBody(response: Response): response is ResponseWithBody;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isResponseWithBody = isResponseWithBody;
4
- function isResponseWithBody(response) {
5
- return response.body != null;
6
- }
@@ -1,4 +0,0 @@
1
- export type ResponseWithBody = Response & {
2
- body: ReadableStream<Uint8Array>;
3
- };
4
- export declare function isResponseWithBody(response: Response): response is ResponseWithBody;
@@ -1,3 +0,0 @@
1
- export function isResponseWithBody(response) {
2
- return response.body != null;
3
- }