totalum-sdk 1.11.0 → 1.12.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 (51) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/_types/{coerce.d-BKhuaDya.d.ts → coerce.d-Cp5NZQN-.d.ts} +1 -1
  3. package/dist/_types/{errors.d-RTRkidv5.d.ts → errors.d-ve4rY-Hx.d.ts} +37 -5
  4. package/dist/_types/{integrations.d-CzTa9T-L.d.ts → integrations.d-BRhNKT7K.d.ts} +2 -2
  5. package/dist/_types/{ops.d-CNsrT4Ma.d.ts → ops.d-DIC4u0go.d.ts} +2 -2
  6. package/dist/ai/index.d.ts +275 -23
  7. package/dist/ai/index.js +305 -24
  8. package/dist/analytics/index.d.ts +58 -12
  9. package/dist/analytics/index.js +46 -3
  10. package/dist/browser/index.d.ts +228 -20
  11. package/dist/browser/index.js +122 -13
  12. package/dist/connections/index.d.ts +305 -23
  13. package/dist/connections/index.js +302 -21
  14. package/dist/cron/index.d.ts +147 -20
  15. package/dist/cron/index.js +157 -15
  16. package/dist/d1/errors.js +15 -0
  17. package/dist/d1/index.d.ts +254 -10
  18. package/dist/d1/index.js +24 -4
  19. package/dist/d1/session.js +26 -2
  20. package/dist/email/index.d.ts +65 -10
  21. package/dist/email/index.js +60 -5
  22. package/dist/errors.js +17 -0
  23. package/dist/files/index.d.ts +243 -20
  24. package/dist/files/index.js +247 -14
  25. package/dist/index.d.ts +25 -10
  26. package/dist/index.js +19 -5
  27. package/dist/logs/index.d.ts +48 -10
  28. package/dist/logs/index.js +39 -4
  29. package/dist/payments/index.d.ts +221 -23
  30. package/dist/payments/index.js +216 -18
  31. package/dist/pdf/index.d.ts +59 -9
  32. package/dist/pdf/index.js +54 -4
  33. package/dist/react/index.d.ts +78 -6
  34. package/dist/react/index.js +51 -5
  35. package/dist/realtime/index.d.ts +55 -8
  36. package/dist/realtime/index.js +53 -6
  37. package/dist/scan/index.d.ts +78 -10
  38. package/dist/scan/index.js +63 -3
  39. package/dist/seo/index.d.ts +1118 -8
  40. package/dist/seo/index.js +325 -4
  41. package/dist/speech/index.d.ts +34 -10
  42. package/dist/speech/index.js +25 -5
  43. package/dist/vectors/index.d.ts +96 -9
  44. package/dist/vectors/index.js +93 -7
  45. package/dist/web/index.d.ts +168 -15
  46. package/dist/web/index.js +163 -10
  47. package/dist/webhooks/index.d.ts +122 -15
  48. package/dist/webhooks/index.js +119 -13
  49. package/package.json +2 -1
  50. package/totalum-sdk.md +10336 -754
  51. package/totalum-sdk.signatures.json +69 -1
@@ -1,29 +1,97 @@
1
- import { S as ScanDocumentInput, u as ScanOcrInput } from '../_types/integrations.d-CzTa9T-L.js';
2
- export { v as ScanOcrOutput } from '../_types/integrations.d-CzTa9T-L.js';
3
- import { U as Usage, T as TotalumClientOptions } from '../_types/errors.d-RTRkidv5.js';
4
- export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-RTRkidv5.js';
5
- import '../_types/coerce.d-BKhuaDya.js';
1
+ import { S as ScanDocumentInput, u as ScanOcrInput } from '../_types/integrations.d-BRhNKT7K.js';
2
+ export { v as ScanOcrOutput } from '../_types/integrations.d-BRhNKT7K.js';
3
+ import { U as Usage, T as TotalumClientOptions } from '../_types/errors.d-ve4rY-Hx.js';
4
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-ve4rY-Hx.js';
5
+ import '../_types/coerce.d-Cp5NZQN-.js';
6
6
 
7
7
  /**
8
- * The v1 scan result: the extracted fields (one set per page with `processEveryPdfPageAsDifferentScan`), the v1
9
- * `metadata`, and `usage` like every other paid call.
8
+ * What `scan.document()` returns: the extracted fields (one set per page with `processEveryPdfPageAsDifferentScan`),
9
+ * details of the scan, and what it cost.
10
10
  */
11
11
  interface ScanDocumentResult {
12
+ /** The fields you described in `properties`, with the values read from the document (`null` when absent); an array of them, one per page, with `processEveryPdfPageAsDifferentScan`. */
12
13
  data: Record<string, unknown> | Record<string, unknown>[];
14
+ /** Details of the scan, kept in the shape of the first scan API. */
13
15
  metadata: {
16
+ /** Pages read. */
14
17
  usageUnits: number;
18
+ /** Same as `usageUnits`. */
15
19
  exactUsageUnits: number;
20
+ /** Pages in the document. */
16
21
  pages: number;
22
+ /** Always `'totalum'`. */
17
23
  provider: string;
24
+ /** Same as `usage.credits`. */
18
25
  credits: number;
19
26
  };
27
+ /** What the scan cost. */
20
28
  usage: Usage;
21
29
  }
22
- /** `totalum.scan` over `/v1/scan/*` (scope `scan`): a vision model through Totalum's AI gateway. */
30
+ /**
31
+ * Creates the `scan` namespace (the same object as `totalum.scan`, scope `scan`): documents and images read by a
32
+ * vision model.
33
+ *
34
+ * @param options - The project key, API URL and environment; each falls back to its environment variable.
35
+ * @returns The `scan` namespace: the methods below.
36
+ * @example
37
+ * import { totalumScan } from 'totalum-sdk/scan';
38
+ *
39
+ * const scan = totalumScan();
40
+ * const { text } = await scan.ocr({ key: 'p/acme-crm/01M4P0SFVZXNRS871ZSKZNWHY0.png' });
41
+ */
23
42
  declare function totalumScan(options?: TotalumClientOptions): {
24
- /** Extracts the fields described by `properties` from a document or image (one set per page on request). */
43
+ /**
44
+ * Reads a document or image (a PDF, a photo, a scan) and returns the fields you describe — an invoice's number,
45
+ * date and total, an ID card's name — as JSON. Describe each field with a JSON Schema type and a `description`;
46
+ * fields not found are `null`. Pass exactly one of `key`, `fileName` or `url`.
47
+ *
48
+ * @param input - The document and the fields to extract.
49
+ * @returns The extracted fields, details of the scan, and what it cost.
50
+ * @throws UNSUPPORTED_FILE_TYPE (400) The file is not a PDF or an image.
51
+ * @throws FILE_NOT_FOUND (404) No file with this key.
52
+ * @throws FILE_KEY_FORBIDDEN (403) The key belongs to another project.
53
+ * @throws FILE_TOO_LARGE (413) The file is over the plan's largest file.
54
+ * @throws URL_NOT_ALLOWED (400) The `url` is not a public `http(s)` URL.
55
+ * @throws SCAN_DOCUMENT_ERROR (502) The document could not be read; retry, or try `model: 'scanum-pro'`.
56
+ * @example
57
+ * const scan = await totalum.scan.document({
58
+ * key: invoice.key,
59
+ * properties: {
60
+ * invoiceNumber: { type: 'string', description: 'the invoice number' },
61
+ * issueDate: { type: 'string', description: 'the issue date as YYYY-MM-DD' },
62
+ * total: { type: 'number', description: 'the total amount including tax' },
63
+ * },
64
+ * });
65
+ * //=>
66
+ * {
67
+ * "data": { "invoiceNumber": "F-2026-0012", "issueDate": "2026-09-30", "total": 1210 },
68
+ * "metadata": { "usageUnits": 1, "exactUsageUnits": 1, "pages": 1, "provider": "totalum", "credits": 0.0039 },
69
+ * "usage": { "credits": 0.0039 }
70
+ * }
71
+ */
25
72
  document: (input: ScanDocumentInput) => Promise<ScanDocumentResult>;
26
- /** The text of a document or image, per page as Markdown. */
73
+ /**
74
+ * The text of a document or image (OCR), as Markdown per page, keeping reading order and tables. Use it to index a
75
+ * PDF for search, or to read a photo of a sign. Long PDFs are read in parallel chunks. Pass exactly one of `key`,
76
+ * `fileName` or `url`.
77
+ *
78
+ * @param input - The document to read.
79
+ * @returns The whole text, the text of each page, and what it cost.
80
+ * @throws UNSUPPORTED_FILE_TYPE (400) The file is not a PDF or an image.
81
+ * @throws FILE_NOT_FOUND (404) No file with this key.
82
+ * @throws FILE_KEY_FORBIDDEN (403) The key belongs to another project.
83
+ * @throws FILE_TOO_LARGE (413) The file is over the plan's largest file.
84
+ * @throws OCR_PDF_PROCESSING_ERROR (502) A PDF could not be read.
85
+ * @throws OCR_IMAGE_PROCESSING_ERROR (502) An image could not be read.
86
+ * @example
87
+ * const { text, pages } = await totalum.scan.ocr({ key: 'p/acme-crm/01M4P0SFVZXNRS871ZSKZNWHY0.png' });
88
+ * //=>
89
+ * {
90
+ * "text": "TOTALUM 42",
91
+ * "pages": [{ "markdown": "TOTALUM 42", "width": 0, "height": 0 }],
92
+ * "usage": { "credits": 0.021 }
93
+ * }
94
+ */
27
95
  ocr: (input: ScanOcrInput) => Promise<Omit<{
28
96
  text: string;
29
97
  pages: {
@@ -1,16 +1,76 @@
1
1
  import { envelopeClient, withUsage } from '../http.js';
2
2
  export { TotalumError, isTotalumError } from '../errors.js';
3
- /** `totalum.scan` over `/v1/scan/*` (scope `scan`): a vision model through Totalum's AI gateway. */
3
+ /**
4
+ * Creates the `scan` namespace (the same object as `totalum.scan`, scope `scan`): documents and images read by a
5
+ * vision model.
6
+ *
7
+ * @param options - The project key, API URL and environment; each falls back to its environment variable.
8
+ * @returns The `scan` namespace: the methods below.
9
+ * @example
10
+ * import { totalumScan } from 'totalum-sdk/scan';
11
+ *
12
+ * const scan = totalumScan();
13
+ * const { text } = await scan.ocr({ key: 'p/acme-crm/01M4P0SFVZXNRS871ZSKZNWHY0.png' });
14
+ */
4
15
  export function totalumScan(options = {}) {
5
16
  const call = envelopeClient(options);
6
17
  return {
7
- /** Extracts the fields described by `properties` from a document or image (one set per page on request). */
18
+ /**
19
+ * Reads a document or image (a PDF, a photo, a scan) and returns the fields you describe — an invoice's number,
20
+ * date and total, an ID card's name — as JSON. Describe each field with a JSON Schema type and a `description`;
21
+ * fields not found are `null`. Pass exactly one of `key`, `fileName` or `url`.
22
+ *
23
+ * @param input - The document and the fields to extract.
24
+ * @returns The extracted fields, details of the scan, and what it cost.
25
+ * @throws UNSUPPORTED_FILE_TYPE (400) The file is not a PDF or an image.
26
+ * @throws FILE_NOT_FOUND (404) No file with this key.
27
+ * @throws FILE_KEY_FORBIDDEN (403) The key belongs to another project.
28
+ * @throws FILE_TOO_LARGE (413) The file is over the plan's largest file.
29
+ * @throws URL_NOT_ALLOWED (400) The `url` is not a public `http(s)` URL.
30
+ * @throws SCAN_DOCUMENT_ERROR (502) The document could not be read; retry, or try `model: 'scanum-pro'`.
31
+ * @example
32
+ * const scan = await totalum.scan.document({
33
+ * key: invoice.key,
34
+ * properties: {
35
+ * invoiceNumber: { type: 'string', description: 'the invoice number' },
36
+ * issueDate: { type: 'string', description: 'the issue date as YYYY-MM-DD' },
37
+ * total: { type: 'number', description: 'the total amount including tax' },
38
+ * },
39
+ * });
40
+ * //=>
41
+ * {
42
+ * "data": { "invoiceNumber": "F-2026-0012", "issueDate": "2026-09-30", "total": 1210 },
43
+ * "metadata": { "usageUnits": 1, "exactUsageUnits": 1, "pages": 1, "provider": "totalum", "credits": 0.0039 },
44
+ * "usage": { "credits": 0.0039 }
45
+ * }
46
+ */
8
47
  document: async (input) => {
9
48
  const envelope = await call('POST', '/v1/scan/document', input);
10
49
  const { usage } = withUsage({ ...envelope, data: {} });
11
50
  return { data: envelope.data, metadata: envelope.metadata, usage };
12
51
  },
13
- /** The text of a document or image, per page as Markdown. */
52
+ /**
53
+ * The text of a document or image (OCR), as Markdown per page, keeping reading order and tables. Use it to index a
54
+ * PDF for search, or to read a photo of a sign. Long PDFs are read in parallel chunks. Pass exactly one of `key`,
55
+ * `fileName` or `url`.
56
+ *
57
+ * @param input - The document to read.
58
+ * @returns The whole text, the text of each page, and what it cost.
59
+ * @throws UNSUPPORTED_FILE_TYPE (400) The file is not a PDF or an image.
60
+ * @throws FILE_NOT_FOUND (404) No file with this key.
61
+ * @throws FILE_KEY_FORBIDDEN (403) The key belongs to another project.
62
+ * @throws FILE_TOO_LARGE (413) The file is over the plan's largest file.
63
+ * @throws OCR_PDF_PROCESSING_ERROR (502) A PDF could not be read.
64
+ * @throws OCR_IMAGE_PROCESSING_ERROR (502) An image could not be read.
65
+ * @example
66
+ * const { text, pages } = await totalum.scan.ocr({ key: 'p/acme-crm/01M4P0SFVZXNRS871ZSKZNWHY0.png' });
67
+ * //=>
68
+ * {
69
+ * "text": "TOTALUM 42",
70
+ * "pages": [{ "markdown": "TOTALUM 42", "width": 0, "height": 0 }],
71
+ * "usage": { "credits": 0.021 }
72
+ * }
73
+ */
14
74
  ocr: async (input) => withUsage(await call('POST', '/v1/scan/ocr', input)),
15
75
  };
16
76
  }