@giveitsmaller/sdk 0.2.0 → 0.2.2
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/client.d.ts +1 -0
- package/dist/client.js +15 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -2
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { UploadResponse, WorkflowCreateResponse, WorkflowStatusResponse, WorkflowDownloadResponse, MetadataResponse, OperationsSchemaResponse, RetryResponse } from '@giveitsmaller/contracts/openapi';
|
|
2
2
|
import type { GislClientConfig, GislSseEvent, UploadOptions, WaitOptions, WorkflowCreatePayload } from './types.js';
|
|
3
|
+
export declare const DEFAULT_MULTIPART_FIRST_CHUNK_SIZE: number;
|
|
3
4
|
export declare class GislClient {
|
|
4
5
|
private readonly baseUrl;
|
|
5
6
|
private readonly headers;
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,12 @@ import { parseSseStream } from './sse.js';
|
|
|
6
6
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
7
7
|
const DEFAULT_MULTIPART_THRESHOLD = 10 * 1024 * 1024; // 10 MB
|
|
8
8
|
const DEFAULT_MULTIPART_CONCURRENCY = 4;
|
|
9
|
+
// Fixed per contract (compression_contracts/openapi/api.yaml:134). The server
|
|
10
|
+
// uses the first chunk for MIME detection + throughput measurement and stores
|
|
11
|
+
// it as S3 multipart part 1. Must NOT be derived from multipartThreshold —
|
|
12
|
+
// that is the "use multipart above this size" routing threshold, a separate
|
|
13
|
+
// concept. Conflating them caused the /api/uploads/multipart/initiate 413.
|
|
14
|
+
export const DEFAULT_MULTIPART_FIRST_CHUNK_SIZE = 8 * 1024 * 1024; // 8 MB
|
|
9
15
|
const DEFAULT_POLL_INTERVAL_MS = 2_000;
|
|
10
16
|
const DEFAULT_POLL_TIMEOUT_MS = 300_000; // 5 min
|
|
11
17
|
const TERMINAL_STATUSES = new Set([
|
|
@@ -22,7 +28,10 @@ export class GislClient {
|
|
|
22
28
|
constructor(config) {
|
|
23
29
|
this.baseUrl = config.baseUrl.replace(/\/+$/, '');
|
|
24
30
|
this.timeoutMs = config.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
25
|
-
|
|
31
|
+
// Floor the threshold at the first-chunk size: the multipart initiate
|
|
32
|
+
// must always carry an 8MB chunk, so routing a sub-8MB file into the
|
|
33
|
+
// multipart path would violate the contract.
|
|
34
|
+
this.multipartThreshold = Math.max(config.multipartThreshold ?? DEFAULT_MULTIPART_THRESHOLD, DEFAULT_MULTIPART_FIRST_CHUNK_SIZE);
|
|
26
35
|
this.multipartConcurrency = config.multipartConcurrency ?? DEFAULT_MULTIPART_CONCURRENCY;
|
|
27
36
|
this.headers = { ...config.headers };
|
|
28
37
|
if (config.apiKey) {
|
|
@@ -136,12 +145,12 @@ export class GislClient {
|
|
|
136
145
|
}
|
|
137
146
|
async multipartUpload(blob, fileName, totalSize, options) {
|
|
138
147
|
// Step 1: Initiate with first chunk
|
|
139
|
-
const firstChunkSize = Math.min(totalSize,
|
|
148
|
+
const firstChunkSize = Math.min(totalSize, DEFAULT_MULTIPART_FIRST_CHUNK_SIZE);
|
|
140
149
|
const firstChunk = blob.slice(0, firstChunkSize);
|
|
141
150
|
const initiateForm = new FormData();
|
|
142
|
-
initiateForm.append('
|
|
143
|
-
initiateForm.append('
|
|
144
|
-
initiateForm.append('
|
|
151
|
+
initiateForm.append('file', firstChunk, fileName);
|
|
152
|
+
initiateForm.append('filename', fileName);
|
|
153
|
+
initiateForm.append('total_size', totalSize.toString());
|
|
145
154
|
const initResponse = await this.request('POST', '/api/uploads/multipart/initiate', {
|
|
146
155
|
body: initiateForm,
|
|
147
156
|
json: false,
|
|
@@ -236,7 +245,7 @@ export class GislClient {
|
|
|
236
245
|
* Get download URLs for a completed workflow.
|
|
237
246
|
*/
|
|
238
247
|
async getWorkflowDownloads(workflowId) {
|
|
239
|
-
return this.request('GET', `/api/workflows/${encodeURIComponent(workflowId)}/
|
|
248
|
+
return this.request('GET', `/api/workflows/${encodeURIComponent(workflowId)}/downloads`, {
|
|
240
249
|
deserialize: WorkflowDownloadResponseFromJSON,
|
|
241
250
|
});
|
|
242
251
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { GislClient } from './client.js';
|
|
1
|
+
export { GislClient, DEFAULT_MULTIPART_FIRST_CHUNK_SIZE } from './client.js';
|
|
2
2
|
export { verifyWebhook } from './webhook.js';
|
|
3
3
|
export { parseSseStream } from './sse.js';
|
|
4
4
|
export type { GislClientConfig, GislSseEvent, UploadOptions, WaitOptions, WorkflowCreatePayload, OperationDef, FileJobPayload, SourceJobPayload, InputsJobPayload, JobDefinitionPayload, } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SDK classes and functions
|
|
2
|
-
export { GislClient } from './client.js';
|
|
2
|
+
export { GislClient, DEFAULT_MULTIPART_FIRST_CHUNK_SIZE } from './client.js';
|
|
3
3
|
export { verifyWebhook } from './webhook.js';
|
|
4
4
|
export { parseSseStream } from './sse.js';
|
|
5
5
|
export { fileJob, sourceJob, inputsJob } from './types.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giveitsmaller/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Node.js SDK for the GISL (Give It Smaller) file compression and processing API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^22",
|
|
26
26
|
"typescript": "^5.7",
|
|
27
|
-
"vitest": "^3.1"
|
|
27
|
+
"vitest": "^3.1",
|
|
28
|
+
"yaml": "^2.6"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
31
|
"build": "tsc",
|