diffio 0.1.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 (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +204 -0
  3. package/dist/BaseClient.d.ts +26 -0
  4. package/dist/BaseClient.js +17 -0
  5. package/dist/Client.d.ts +109 -0
  6. package/dist/Client.js +689 -0
  7. package/dist/api/index.d.ts +2 -0
  8. package/dist/api/index.js +18 -0
  9. package/dist/api/resources/audioIsolation/client/Client.d.ts +41 -0
  10. package/dist/api/resources/audioIsolation/client/Client.js +32 -0
  11. package/dist/api/resources/generations/client/Client.d.ts +47 -0
  12. package/dist/api/resources/generations/client/Client.js +36 -0
  13. package/dist/api/resources/index.d.ts +4 -0
  14. package/dist/api/resources/index.js +11 -0
  15. package/dist/api/resources/projects/client/Client.d.ts +15 -0
  16. package/dist/api/resources/projects/client/Client.js +15 -0
  17. package/dist/api/resources/webhooks/client/Client.d.ts +20 -0
  18. package/dist/api/resources/webhooks/client/Client.js +15 -0
  19. package/dist/api/serialization.d.ts +14 -0
  20. package/dist/api/serialization.js +138 -0
  21. package/dist/api/types.d.ts +122 -0
  22. package/dist/api/types.js +2 -0
  23. package/dist/core/headers.d.ts +6 -0
  24. package/dist/core/headers.js +44 -0
  25. package/dist/core/retry.d.ts +7 -0
  26. package/dist/core/retry.js +31 -0
  27. package/dist/core/supplier.d.ts +4 -0
  28. package/dist/core/supplier.js +14 -0
  29. package/dist/core/url.d.ts +1 -0
  30. package/dist/core/url.js +14 -0
  31. package/dist/errors/index.d.ts +14 -0
  32. package/dist/errors/index.js +26 -0
  33. package/dist/index.d.ts +4 -0
  34. package/dist/index.js +45 -0
  35. package/dist/version.d.ts +1 -0
  36. package/dist/version.js +4 -0
  37. package/package.json +36 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Diffio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # Diffio JS SDK
2
+
3
+ The Diffio JS SDK helps you call the Diffio API from Node. This version covers project creation, upload, generation, progress checks, and download URLs.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install diffio
9
+ ```
10
+
11
+ For local development:
12
+
13
+ ```bash
14
+ cd diffio-js
15
+ npm install
16
+ ```
17
+
18
+ ## Configuration
19
+
20
+ Set the API key with `DIFFIO_API_KEY`. You can also override the base URL with `DIFFIO_API_BASE_URL`.
21
+
22
+ ```bash
23
+ export DIFFIO_API_KEY="diffio_live_..."
24
+ export DIFFIO_API_BASE_URL="https://us-central1-diffioai.cloudfunctions.net"
25
+ ```
26
+
27
+ For emulators, set the base URL to the Functions emulator host.
28
+
29
+ ```bash
30
+ export DIFFIO_API_BASE_URL="http://127.0.0.1:5001/diffioai/us-central1"
31
+ ```
32
+
33
+ ## Request options
34
+
35
+ Use request options to override headers, timeouts, retries, or the API key per request.
36
+
37
+ ```ts
38
+ import { DiffioClient } from "diffio";
39
+
40
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
41
+ const projects = await client.listProjects({
42
+ requestOptions: {
43
+ headers: { "X-Debug": "1" },
44
+ timeoutInSeconds: 30,
45
+ maxRetries: 2,
46
+ retryBackoff: 0.5
47
+ }
48
+ });
49
+ ```
50
+
51
+ ## Create a project and generation
52
+
53
+ `createProject` uploads the file and returns the project metadata.
54
+
55
+ ```ts
56
+ import { DiffioClient } from "diffio";
57
+
58
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
59
+ const filePath = "sample.wav";
60
+
61
+ const project = await client.createProject({
62
+ filePath
63
+ });
64
+
65
+ const generation = await client.createGeneration({
66
+ apiProjectId: project.apiProjectId,
67
+ model: "diffio-2",
68
+ sampling: { steps: 12, guidance: 1.5 }
69
+ });
70
+
71
+ console.log(generation.generationId);
72
+ ```
73
+
74
+ ## Audio isolation helper
75
+
76
+ ```ts
77
+ import { DiffioClient } from "diffio";
78
+
79
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
80
+ const result = await client.audioIsolation.isolate({
81
+ filePath: "sample.wav",
82
+ model: "diffio-2",
83
+ sampling: { steps: 12, guidance: 1.5 }
84
+ });
85
+
86
+ console.log(result.generation.generationId);
87
+ ```
88
+
89
+ ## Restore audio in one call
90
+
91
+ This helper runs the full flow and returns the downloaded bytes plus a metadata object.
92
+
93
+ ```ts
94
+ import fs from "node:fs";
95
+ import { DiffioClient } from "diffio";
96
+
97
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
98
+ const [audioBytes, info] = await client.restoreAudio({
99
+ filePath: "sample.wav",
100
+ model: "diffio-2",
101
+ sampling: { steps: 12, guidance: 1.5 },
102
+ onProgress: (progress) => console.log(progress.status)
103
+ });
104
+
105
+ if (info.error) {
106
+ console.log(info.error);
107
+ } else if (audioBytes) {
108
+ fs.writeFileSync("restored.mp3", Buffer.from(audioBytes));
109
+ }
110
+
111
+ console.log(info.apiProjectId, info.generationId);
112
+ ```
113
+
114
+ ## Generation progress
115
+
116
+ ```ts
117
+ import { DiffioClient } from "diffio";
118
+
119
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
120
+ const progress = await client.generations.getProgress({
121
+ generationId: "gen_123",
122
+ apiProjectId: "proj_123"
123
+ });
124
+
125
+ console.log(progress.status);
126
+ ```
127
+
128
+ ## Generation download
129
+
130
+ ```ts
131
+ import { DiffioClient } from "diffio";
132
+
133
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
134
+ const download = await client.generations.getDownload({
135
+ generationId: "gen_123",
136
+ apiProjectId: "proj_123",
137
+ downloadType: "audio"
138
+ });
139
+
140
+ console.log(download.downloadUrl);
141
+ ```
142
+
143
+ ## List projects
144
+
145
+ ```ts
146
+ import { DiffioClient } from "diffio";
147
+
148
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
149
+ const projects = await client.projects.list();
150
+
151
+ for (const project of projects.projects) {
152
+ console.log(project.apiProjectId, project.status);
153
+ }
154
+ ```
155
+
156
+ ## List project generations
157
+
158
+ ```ts
159
+ import { DiffioClient } from "diffio";
160
+
161
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
162
+ const generations = await client.projects.listGenerations({ apiProjectId: "proj_123" });
163
+
164
+ for (const generation of generations.generations) {
165
+ console.log(generation.generationId, generation.status);
166
+ }
167
+ ```
168
+
169
+ ## Webhooks portal access
170
+
171
+ ```ts
172
+ import { DiffioClient } from "diffio";
173
+
174
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
175
+ const portal = await client.webhooks.getPortalAccess({ mode: "test" });
176
+ console.log(portal.portalUrl);
177
+ ```
178
+
179
+ ## Send a test webhook event
180
+
181
+ ```ts
182
+ import { DiffioClient } from "diffio";
183
+
184
+ const client = new DiffioClient({ apiKey: "diffio_live_..." });
185
+ const event = await client.webhooks.sendTestEvent({
186
+ eventType: "generation.completed",
187
+ mode: "test",
188
+ samplePayload: { apiProjectId: "proj_123" }
189
+ });
190
+
191
+ console.log(event.svixMessageId);
192
+ ```
193
+
194
+ ## Runtime compatibility
195
+
196
+ Use Node 18 or later so `fetch` is available without extra packages.
197
+ Examples use ES modules. Save files with a `.mjs` extension or set `"type": "module"` in your package.json.
198
+
199
+ ## Tests
200
+
201
+ ```bash
202
+ cd diffio-js
203
+ npm run build
204
+ ```
@@ -0,0 +1,26 @@
1
+ import type { Supplier } from "./core/supplier";
2
+ export interface BaseClientOptions {
3
+ baseUrl?: Supplier<string>;
4
+ apiKey?: Supplier<string | undefined>;
5
+ headers?: Record<string, string | Supplier<string | null | undefined> | null | undefined>;
6
+ timeoutInSeconds?: number;
7
+ timeout?: number;
8
+ maxRetries?: number;
9
+ retryBackoff?: number;
10
+ retryStatusCodes?: number[];
11
+ fetch?: typeof fetch;
12
+ }
13
+ export interface BaseRequestOptions {
14
+ timeoutInSeconds?: number;
15
+ timeout?: number;
16
+ maxRetries?: number;
17
+ retryBackoff?: number;
18
+ retryStatusCodes?: number[];
19
+ abortSignal?: AbortSignal;
20
+ apiKey?: string | undefined;
21
+ headers?: Record<string, string | Supplier<string | null | undefined> | null | undefined>;
22
+ }
23
+ export type NormalizedClientOptions<T extends BaseClientOptions> = T & {
24
+ headers: Record<string, string | Supplier<string | null | undefined> | null | undefined>;
25
+ };
26
+ export declare function normalizeClientOptions<T extends BaseClientOptions>(options: T): NormalizedClientOptions<T>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeClientOptions = normalizeClientOptions;
4
+ const version_1 = require("./version");
5
+ const headers_1 = require("./core/headers");
6
+ function normalizeClientOptions(options) {
7
+ const headers = (0, headers_1.mergeHeaders)({
8
+ "X-Diffio-SDK-Language": "JavaScript",
9
+ "X-Diffio-SDK-Name": "diffio",
10
+ "X-Diffio-SDK-Version": version_1.DIFFIO_SDK_VERSION,
11
+ "User-Agent": `diffio/${version_1.DIFFIO_SDK_VERSION}`
12
+ }, options?.headers);
13
+ return {
14
+ ...options,
15
+ headers
16
+ };
17
+ }
@@ -0,0 +1,109 @@
1
+ import type { BaseClientOptions, BaseRequestOptions, NormalizedClientOptions } from "./BaseClient";
2
+ import type { AudioIsolationResult, CreateGenerationResponse, CreateProjectResponse, GenerationDownloadResponse, GenerationProgressResponse, ListProjectGenerationsResponse, ListProjectsResponse, RestoreMetadata, WebhookPortalResponse, WebhookTestEventResponse } from "./api/types";
3
+ import { AudioIsolationClient, GenerationsClient, ProjectsClient, WebhooksClient } from "./api/resources";
4
+ export declare namespace DiffioClient {
5
+ type Options = BaseClientOptions;
6
+ interface RequestOptions extends BaseRequestOptions {
7
+ }
8
+ }
9
+ export declare class DiffioClient {
10
+ protected readonly _options: NormalizedClientOptions<DiffioClient.Options>;
11
+ readonly audioIsolation: AudioIsolationClient;
12
+ readonly generations: GenerationsClient;
13
+ readonly projects: ProjectsClient;
14
+ readonly webhooks: WebhooksClient;
15
+ constructor(options?: DiffioClient.Options);
16
+ close(): void;
17
+ createProject(options: {
18
+ filePath: string;
19
+ contentType?: string;
20
+ contentLength?: number;
21
+ params?: Record<string, unknown>;
22
+ fileFormat?: string;
23
+ requestOptions?: DiffioClient.RequestOptions;
24
+ }): Promise<CreateProjectResponse>;
25
+ private _uploadFile;
26
+ createGeneration(options: {
27
+ apiProjectId: string;
28
+ model?: string;
29
+ sampling?: Record<string, unknown>;
30
+ params?: Record<string, unknown>;
31
+ requestOptions?: DiffioClient.RequestOptions;
32
+ }): Promise<CreateGenerationResponse>;
33
+ listProjects(options?: {
34
+ requestOptions?: DiffioClient.RequestOptions;
35
+ }): Promise<ListProjectsResponse>;
36
+ listProjectGenerations(options: {
37
+ apiProjectId: string;
38
+ requestOptions?: DiffioClient.RequestOptions;
39
+ }): Promise<ListProjectGenerationsResponse>;
40
+ getGenerationProgress(options: {
41
+ generationId: string;
42
+ apiProjectId?: string;
43
+ requestOptions?: DiffioClient.RequestOptions;
44
+ }): Promise<GenerationProgressResponse>;
45
+ waitForGeneration(options: {
46
+ generationId: string;
47
+ apiProjectId?: string;
48
+ pollInterval?: number;
49
+ timeout?: number;
50
+ timeoutInSeconds?: number;
51
+ onProgress?: (progress: GenerationProgressResponse) => void | Promise<void>;
52
+ showProgress?: boolean;
53
+ requestOptions?: DiffioClient.RequestOptions;
54
+ }): Promise<GenerationProgressResponse>;
55
+ getGenerationDownload(options: {
56
+ generationId: string;
57
+ apiProjectId: string;
58
+ downloadType?: string;
59
+ requestOptions?: DiffioClient.RequestOptions;
60
+ }): Promise<GenerationDownloadResponse>;
61
+ getWebhooksPortalAccess(options: {
62
+ mode: string;
63
+ apiKeyId?: string;
64
+ requestOptions?: DiffioClient.RequestOptions;
65
+ }): Promise<WebhookPortalResponse>;
66
+ sendWebhookTestEvent(options: {
67
+ eventType: string;
68
+ mode: string;
69
+ apiKeyId?: string;
70
+ samplePayload?: Record<string, unknown>;
71
+ requestOptions?: DiffioClient.RequestOptions;
72
+ }): Promise<WebhookTestEventResponse>;
73
+ restoreAudio(options: {
74
+ filePath: string;
75
+ contentType?: string;
76
+ contentLength?: number;
77
+ fileFormat?: string;
78
+ model?: string;
79
+ sampling?: Record<string, unknown>;
80
+ projectParams?: Record<string, unknown>;
81
+ generationParams?: Record<string, unknown>;
82
+ downloadType?: string;
83
+ pollInterval?: number;
84
+ timeout?: number;
85
+ timeoutInSeconds?: number;
86
+ onProgress?: (progress: GenerationProgressResponse) => void | Promise<void>;
87
+ showProgress?: boolean;
88
+ requestOptions?: DiffioClient.RequestOptions;
89
+ progressRequestOptions?: DiffioClient.RequestOptions;
90
+ downloadRequestOptions?: DiffioClient.RequestOptions;
91
+ raiseOnError?: boolean;
92
+ }): Promise<[Uint8Array | null, RestoreMetadata]>;
93
+ restore(options: Parameters<DiffioClient["restoreAudio"]>[0]): Promise<[Uint8Array | null, RestoreMetadata]>;
94
+ audioIsolationIsolate(options: {
95
+ filePath: string;
96
+ contentType?: string;
97
+ contentLength?: number;
98
+ fileFormat?: string;
99
+ model?: string;
100
+ sampling?: Record<string, unknown>;
101
+ projectParams?: Record<string, unknown>;
102
+ generationParams?: Record<string, unknown>;
103
+ requestOptions?: DiffioClient.RequestOptions;
104
+ }): Promise<AudioIsolationResult>;
105
+ private _downloadBinary;
106
+ private _requestJson;
107
+ private _requestBinary;
108
+ private _buildRequest;
109
+ }