notion-multipart-uploader 2.1.1 → 2.1.4

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
@@ -19,6 +19,12 @@ Because the official `@notionhq/client` SDK requires manually orchestrating a mu
19
19
  npm install notion-multipart-uploader
20
20
  ```
21
21
 
22
+ > **Looking for the ultra-lightweight Version 1?**
23
+ > If you are absolutely certain your app will only ever upload small files (under 20MB) and you want the absolute leanest possible script without the V2 multi-part chunking logic, you can install the legacy V1:
24
+ > ```bash
25
+ > npm install notion-multipart-uploader@1.0.1
26
+ > ```
27
+
22
28
  ## Getting an API Key
23
29
  To use this package, you need a Notion Integration Token:
24
30
  1. Go to [Notion's Integration Dashboard](https://www.notion.so/my-integrations).
@@ -55,8 +61,8 @@ async function run() {
55
61
  object: "block",
56
62
  type: "audio",
57
63
  audio: {
58
- type: "external",
59
- external: { url: `https://www.notion.so/signed/${fileId}` } // Simplified for example
64
+ type: "file_upload",
65
+ file_upload: { id: fileId }
60
66
  }
61
67
  }]
62
68
  });
package/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export interface UploadOptions {
11
11
 
12
12
  export declare function uploadToNotion(
13
13
  apiKey: string,
14
- fileBuffer: Buffer | Blob | Uint8Array,
14
+ fileBuffer: Uint8Array | Blob | any,
15
15
  mimeType: string,
16
16
  filename?: string,
17
17
  options?: UploadOptions
package/index.js CHANGED
@@ -17,12 +17,25 @@ async function uploadToNotion(apiKey, fileBuffer, mimeType, filename, options =
17
17
  const maxRetries = options.retries || 3;
18
18
  const timeoutMs = options.timeoutMs;
19
19
  const userSignal = options.signal;
20
- const CHUNK_SIZE = 10 * 1024 * 1024; // 10MB (allows 5GiB / 10MiB = 512 parts, well under 1000 limit)
21
20
 
22
21
  const size = fileBuffer.length || fileBuffer.size || fileBuffer.byteLength;
22
+
23
+ // Notion strictly limits files to 5GB (paid workspaces)
24
+ if (size > 5 * 1024 * 1024 * 1024) {
25
+ throw new Error("File exceeds Notion's absolute maximum size limit of 5GB.");
26
+ }
27
+
23
28
  const isMultiPart = size > 20971520; // Notion's 20MB limit
24
29
  const mode = isMultiPart ? "multi_part" : "single_part";
25
- const numParts = isMultiPart ? Math.ceil(size / CHUNK_SIZE) : 1;
30
+
31
+ // Default to 10MB chunks, but dynamically scale up if we hit the 1000 part limit
32
+ let CHUNK_SIZE = 10 * 1024 * 1024;
33
+ let numParts = isMultiPart ? Math.ceil(size / CHUNK_SIZE) : 1;
34
+
35
+ if (numParts > 1000) {
36
+ CHUNK_SIZE = Math.ceil(size / 1000);
37
+ numParts = 1000;
38
+ }
26
39
 
27
40
  // Exponential backoff retry wrapper with Abort/Timeout support
28
41
  const fetchWithRetry = async (url, fetchOptions, retries = maxRetries) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notion-multipart-uploader",
3
- "version": "2.1.1",
3
+ "version": "2.1.4",
4
4
  "description": "Native zero-dependency multipart file uploader for Notion API. Direct upload any media type (videos, phone gallery images, audio, PDFs, and binary blobs) to Notion without external hosting.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",