@transloadit/convex 0.0.1

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 (61) hide show
  1. package/README.md +235 -0
  2. package/dist/client/index.d.ts +244 -0
  3. package/dist/client/index.d.ts.map +1 -0
  4. package/dist/client/index.js +196 -0
  5. package/dist/client/index.js.map +1 -0
  6. package/dist/client/types.d.ts +24 -0
  7. package/dist/client/types.d.ts.map +1 -0
  8. package/dist/client/types.js +2 -0
  9. package/dist/client/types.js.map +1 -0
  10. package/dist/component/_generated/api.d.ts +20 -0
  11. package/dist/component/_generated/api.d.ts.map +1 -0
  12. package/dist/component/_generated/api.js +15 -0
  13. package/dist/component/_generated/api.js.map +1 -0
  14. package/dist/component/_generated/component.d.ts +101 -0
  15. package/dist/component/_generated/component.d.ts.map +1 -0
  16. package/dist/component/_generated/component.js +11 -0
  17. package/dist/component/_generated/component.js.map +1 -0
  18. package/dist/component/_generated/dataModel.d.ts +16 -0
  19. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  20. package/dist/component/_generated/dataModel.js +11 -0
  21. package/dist/component/_generated/dataModel.js.map +1 -0
  22. package/dist/component/_generated/server.d.ts +31 -0
  23. package/dist/component/_generated/server.d.ts.map +1 -0
  24. package/dist/component/_generated/server.js +18 -0
  25. package/dist/component/_generated/server.js.map +1 -0
  26. package/dist/component/apiUtils.d.ts +31 -0
  27. package/dist/component/apiUtils.d.ts.map +1 -0
  28. package/dist/component/apiUtils.js +94 -0
  29. package/dist/component/apiUtils.js.map +1 -0
  30. package/dist/component/convex.config.d.ts +3 -0
  31. package/dist/component/convex.config.d.ts.map +1 -0
  32. package/dist/component/convex.config.js +3 -0
  33. package/dist/component/convex.config.js.map +1 -0
  34. package/dist/component/lib.d.ts +226 -0
  35. package/dist/component/lib.d.ts.map +1 -0
  36. package/dist/component/lib.js +383 -0
  37. package/dist/component/lib.js.map +1 -0
  38. package/dist/component/schema.d.ts +67 -0
  39. package/dist/component/schema.d.ts.map +1 -0
  40. package/dist/component/schema.js +45 -0
  41. package/dist/component/schema.js.map +1 -0
  42. package/dist/package.json +3 -0
  43. package/dist/react/index.d.ts +85 -0
  44. package/dist/react/index.d.ts.map +1 -0
  45. package/dist/react/index.js +163 -0
  46. package/dist/react/index.js.map +1 -0
  47. package/package.json +86 -0
  48. package/src/client/index.ts +260 -0
  49. package/src/client/types.ts +64 -0
  50. package/src/component/_generated/api.ts +32 -0
  51. package/src/component/_generated/component.ts +122 -0
  52. package/src/component/_generated/dataModel.ts +30 -0
  53. package/src/component/_generated/server.ts +72 -0
  54. package/src/component/apiUtils.test.ts +48 -0
  55. package/src/component/apiUtils.ts +156 -0
  56. package/src/component/convex.config.ts +3 -0
  57. package/src/component/lib.test.ts +63 -0
  58. package/src/component/lib.ts +466 -0
  59. package/src/component/schema.ts +48 -0
  60. package/src/component/setup.test.ts +6 -0
  61. package/src/react/index.tsx +292 -0
package/README.md ADDED
@@ -0,0 +1,235 @@
1
+ # Transloadit Convex Component
2
+
3
+ A Convex component for creating Transloadit Assemblies, tracking their status/results, and supporting both form uploads and resumable tus uploads.
4
+
5
+ ## Features
6
+
7
+ - Create Assemblies with templates or inline steps.
8
+ - Generate signed upload params for browser form uploads.
9
+ - Resumable uploads via tus (client-side hook).
10
+ - Webhook ingestion with signature verification.
11
+ - Persist Assembly status + results in Convex.
12
+ - Typed API wrappers and React hooks.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ yarn add @transloadit/convex
18
+ ```
19
+
20
+ ## Setup
21
+
22
+ ### 1) Register the component
23
+
24
+ ```ts
25
+ // convex/convex.config.ts
26
+ import { defineApp } from "convex/server";
27
+ import transloadit from "@transloadit/convex/convex.config";
28
+
29
+ const app = defineApp();
30
+ app.use(transloadit);
31
+
32
+ export default app;
33
+ ```
34
+
35
+ ### 2) Set environment variables
36
+
37
+ Preferred names:
38
+
39
+ ```bash
40
+ npx convex env set TRANSLOADIT_AUTH_KEY <your_auth_key>
41
+ npx convex env set TRANSLOADIT_AUTH_SECRET <your_auth_secret>
42
+ ```
43
+
44
+ Aliases also supported:
45
+
46
+ ```bash
47
+ npx convex env set TRANSLOADIT_KEY <your_auth_key>
48
+ npx convex env set TRANSLOADIT_SECRET <your_auth_secret>
49
+ ```
50
+
51
+ ### 3) Create a demo template (idempotent)
52
+
53
+ We use the Transloadit CLI under the hood for the best DX and to avoid hand-rolling API calls.
54
+
55
+ ```bash
56
+ yarn template:ensure
57
+ ```
58
+
59
+ The script reads `TRANSLOADIT_KEY/TRANSLOADIT_SECRET` (or `TRANSLOADIT_AUTH_KEY/TRANSLOADIT_AUTH_SECRET`) from `.env`,
60
+ creates or updates the template `convex-demo`, and prints the template id.
61
+ Use that id as `VITE_TRANSLOADIT_TEMPLATE_ID` in `example/.env` when running the demo app.
62
+
63
+ ## Backend API
64
+
65
+ ```ts
66
+ // convex/transloadit.ts
67
+ import { makeTransloaditAPI } from "@transloadit/convex";
68
+ import { components } from "./_generated/api";
69
+
70
+ export const {
71
+ createAssembly,
72
+ generateUploadParams,
73
+ handleWebhook,
74
+ getAssemblyStatus,
75
+ listAssemblies,
76
+ listResults,
77
+ storeAssemblyMetadata,
78
+ } = makeTransloaditAPI(components.transloadit);
79
+ ```
80
+
81
+ Note: if you don’t supply `expires`, the component defaults it to 1 hour from now.
82
+
83
+ ## Webhook route
84
+
85
+ Transloadit sends webhooks as `multipart/form-data` with `transloadit` (JSON) and `signature` fields.
86
+
87
+ ```ts
88
+ // convex/http.ts
89
+ import { httpAction, httpRouter } from "convex/server";
90
+ import { api } from "./_generated/api";
91
+
92
+ const http = httpRouter();
93
+
94
+ http.route({
95
+ path: "/transloadit/webhook",
96
+ method: "POST",
97
+ handler: httpAction(async (ctx, request) => {
98
+ const formData = await request.formData();
99
+ const rawPayload = formData.get("transloadit");
100
+ const signature = formData.get("signature");
101
+
102
+ if (typeof rawPayload !== "string") {
103
+ return new Response("Missing payload", { status: 400 });
104
+ }
105
+
106
+ const payload = JSON.parse(rawPayload);
107
+
108
+ await ctx.runAction(api.transloadit.handleWebhook, {
109
+ payload,
110
+ rawBody: rawPayload,
111
+ signature: typeof signature === "string" ? signature : undefined,
112
+ });
113
+
114
+ return new Response(null, { status: 204 });
115
+ }),
116
+ });
117
+
118
+ export default http;
119
+ ```
120
+
121
+ ### Local webhook testing with cloudflared
122
+
123
+ If you want to test webhooks locally, tunnel your Convex dev HTTP endpoint:
124
+
125
+ ```bash
126
+ yarn tunnel
127
+ ```
128
+
129
+ Use the generated public URL as `notifyUrl` when creating Assemblies or set
130
+ `VITE_TRANSLOADIT_NOTIFY_URL` for the example app.
131
+
132
+ You can also run `yarn tunnel --once` to print the URL and exit.
133
+
134
+ ### Full QA flow (template + tunnel + webhook)
135
+
136
+ This runs an end-to-end webhook QA flow against Transloadit using a local webhook server
137
+ and cloudflared (auto-downloaded if missing):
138
+
139
+ ```bash
140
+ yarn qa:full
141
+ ```
142
+
143
+ It prints a JSON summary including the assembly id, webhook status, and number of stored results.
144
+
145
+ ## React usage
146
+
147
+ ### Form upload
148
+
149
+ ```tsx
150
+ import { useTransloaditUpload } from "@transloadit/convex/react";
151
+ import { api } from "../convex/_generated/api";
152
+
153
+ function UploadButton() {
154
+ const { upload, isUploading, progress, error } = useTransloaditUpload(
155
+ api.transloadit.generateUploadParams,
156
+ );
157
+
158
+ const handleUpload = async (file: File) => {
159
+ await upload(file, {
160
+ templateId: "template_id_here",
161
+ onProgress: (percent) => console.log(percent),
162
+ });
163
+ };
164
+
165
+ return (
166
+ <div>
167
+ <input type="file" onChange={(e) => handleUpload(e.target.files![0])} />
168
+ {isUploading && <p>Uploading: {progress}%</p>}
169
+ {error && <p>{error.message}</p>}
170
+ </div>
171
+ );
172
+ }
173
+ ```
174
+
175
+ ### Resumable tus upload
176
+
177
+ ```tsx
178
+ import { useTransloaditTusUpload } from "@transloadit/convex/react";
179
+ import { api } from "../convex/_generated/api";
180
+
181
+ function TusUpload() {
182
+ const { upload, isUploading, progress } = useTransloaditTusUpload(
183
+ api.transloadit.createAssembly,
184
+ );
185
+
186
+ const handleUpload = async (file: File) => {
187
+ await upload(file, {
188
+ templateId: "template_id_here",
189
+ });
190
+ };
191
+
192
+ return (
193
+ <div>
194
+ <input type="file" onChange={(e) => handleUpload(e.target.files![0])} />
195
+ {isUploading && <p>Uploading: {progress}%</p>}
196
+ </div>
197
+ );
198
+ }
199
+ ```
200
+
201
+ ### Reactive status/results
202
+
203
+ ```tsx
204
+ import { useAssemblyStatus, useTransloaditFiles } from "@transloadit/convex/react";
205
+ import { api } from "../convex/_generated/api";
206
+
207
+ function AssemblyStatus({ assemblyId }: { assemblyId: string }) {
208
+ const status = useAssemblyStatus(api.transloadit.getAssemblyStatus, assemblyId);
209
+ const results = useTransloaditFiles(api.transloadit.listResults, {
210
+ assemblyId,
211
+ });
212
+
213
+ if (!status) return null;
214
+ return (
215
+ <div>
216
+ <p>Status: {status.ok}</p>
217
+ <p>Results: {results?.length ?? 0}</p>
218
+ </div>
219
+ );
220
+ }
221
+ ```
222
+
223
+ ## Smoke test
224
+
225
+ Create a `.env` file in the repo root and run:
226
+
227
+ ```bash
228
+ yarn smoke
229
+ ```
230
+
231
+ Expected output: a JSON blob containing `assemblyId` and (when available) `tusUrl`.
232
+
233
+ ## Example app
234
+
235
+ See `example/README.md` for setup and usage.
@@ -0,0 +1,244 @@
1
+ import { type Infer } from "convex/values";
2
+ import type { ComponentApi } from "../component/_generated/component.js";
3
+ import type { RunActionCtx, RunMutationCtx, RunQueryCtx } from "./types.js";
4
+ export interface TransloaditConfig {
5
+ authKey: string;
6
+ authSecret: string;
7
+ }
8
+ export type TransloaditComponent = ComponentApi;
9
+ export declare const vAssemblyResponse: import("convex/values").VObject<{
10
+ status?: string | undefined;
11
+ fields?: any;
12
+ ok?: string | undefined;
13
+ message?: string | undefined;
14
+ templateId?: string | undefined;
15
+ notifyUrl?: string | undefined;
16
+ numExpectedUploadFiles?: number | undefined;
17
+ uploads?: any;
18
+ results?: any;
19
+ error?: any;
20
+ raw?: any;
21
+ userId?: string | undefined;
22
+ _id: string;
23
+ _creationTime: number;
24
+ assemblyId: string;
25
+ createdAt: number;
26
+ updatedAt: number;
27
+ }, {
28
+ _id: import("convex/values").VString<string, "required">;
29
+ _creationTime: import("convex/values").VFloat64<number, "required">;
30
+ assemblyId: import("convex/values").VString<string, "required">;
31
+ status: import("convex/values").VString<string | undefined, "optional">;
32
+ ok: import("convex/values").VString<string | undefined, "optional">;
33
+ message: import("convex/values").VString<string | undefined, "optional">;
34
+ templateId: import("convex/values").VString<string | undefined, "optional">;
35
+ notifyUrl: import("convex/values").VString<string | undefined, "optional">;
36
+ numExpectedUploadFiles: import("convex/values").VFloat64<number | undefined, "optional">;
37
+ fields: import("convex/values").VAny<any, "optional", string>;
38
+ uploads: import("convex/values").VAny<any, "optional", string>;
39
+ results: import("convex/values").VAny<any, "optional", string>;
40
+ error: import("convex/values").VAny<any, "optional", string>;
41
+ raw: import("convex/values").VAny<any, "optional", string>;
42
+ createdAt: import("convex/values").VFloat64<number, "required">;
43
+ updatedAt: import("convex/values").VFloat64<number, "required">;
44
+ userId: import("convex/values").VString<string | undefined, "optional">;
45
+ }, "required", "_id" | "_creationTime" | "assemblyId" | "status" | "fields" | "ok" | "message" | "templateId" | "notifyUrl" | "numExpectedUploadFiles" | "uploads" | "results" | "error" | "raw" | "createdAt" | "updatedAt" | "userId" | `fields.${string}` | `uploads.${string}` | `results.${string}` | `error.${string}` | `raw.${string}`>;
46
+ export type AssemblyResponse = Infer<typeof vAssemblyResponse>;
47
+ export declare const vAssemblyResultResponse: import("convex/values").VObject<{
48
+ resultId?: string | undefined;
49
+ sslUrl?: string | undefined;
50
+ name?: string | undefined;
51
+ size?: number | undefined;
52
+ mime?: string | undefined;
53
+ _id: string;
54
+ _creationTime: number;
55
+ assemblyId: string;
56
+ raw: any;
57
+ createdAt: number;
58
+ stepName: string;
59
+ }, {
60
+ _id: import("convex/values").VString<string, "required">;
61
+ _creationTime: import("convex/values").VFloat64<number, "required">;
62
+ assemblyId: import("convex/values").VString<string, "required">;
63
+ stepName: import("convex/values").VString<string, "required">;
64
+ resultId: import("convex/values").VString<string | undefined, "optional">;
65
+ sslUrl: import("convex/values").VString<string | undefined, "optional">;
66
+ name: import("convex/values").VString<string | undefined, "optional">;
67
+ size: import("convex/values").VFloat64<number | undefined, "optional">;
68
+ mime: import("convex/values").VString<string | undefined, "optional">;
69
+ raw: import("convex/values").VAny<any, "required", string>;
70
+ createdAt: import("convex/values").VFloat64<number, "required">;
71
+ }, "required", "_id" | "_creationTime" | "assemblyId" | "raw" | "createdAt" | `raw.${string}` | "stepName" | "resultId" | "sslUrl" | "name" | "size" | "mime">;
72
+ export type AssemblyResultResponse = Infer<typeof vAssemblyResultResponse>;
73
+ export declare const vCreateAssemblyArgs: import("convex/values").VObject<{
74
+ fields?: any;
75
+ templateId?: string | undefined;
76
+ notifyUrl?: string | undefined;
77
+ numExpectedUploadFiles?: number | undefined;
78
+ userId?: string | undefined;
79
+ steps?: any;
80
+ expires?: string | undefined;
81
+ additionalParams?: any;
82
+ }, {
83
+ templateId: import("convex/values").VString<string | undefined, "optional">;
84
+ steps: import("convex/values").VAny<any, "optional", string>;
85
+ fields: import("convex/values").VAny<any, "optional", string>;
86
+ notifyUrl: import("convex/values").VString<string | undefined, "optional">;
87
+ numExpectedUploadFiles: import("convex/values").VFloat64<number | undefined, "optional">;
88
+ expires: import("convex/values").VString<string | undefined, "optional">;
89
+ additionalParams: import("convex/values").VAny<any, "optional", string>;
90
+ userId: import("convex/values").VString<string | undefined, "optional">;
91
+ }, "required", "fields" | "templateId" | "notifyUrl" | "numExpectedUploadFiles" | "userId" | `fields.${string}` | "steps" | "expires" | "additionalParams" | `steps.${string}` | `additionalParams.${string}`>;
92
+ export declare class TransloaditClient {
93
+ component: TransloaditComponent;
94
+ config: TransloaditConfig;
95
+ constructor(component: TransloaditComponent, config?: Partial<TransloaditConfig>);
96
+ static create(component: TransloaditComponent, config: TransloaditConfig): TransloaditClient;
97
+ createAssembly(ctx: RunActionCtx, args: Infer<typeof vCreateAssemblyArgs>): Promise<{
98
+ assemblyId: string;
99
+ data: any;
100
+ }>;
101
+ generateUploadParams(ctx: RunActionCtx, args: Infer<typeof vCreateAssemblyArgs>): Promise<{
102
+ params: string;
103
+ signature: string;
104
+ url: string;
105
+ }>;
106
+ handleWebhook(ctx: RunActionCtx, args: {
107
+ payload: unknown;
108
+ rawBody?: string;
109
+ signature?: string;
110
+ verifySignature?: boolean;
111
+ }): Promise<{
112
+ assemblyId: string;
113
+ resultCount: number;
114
+ }>;
115
+ getAssemblyStatus(ctx: RunQueryCtx, assemblyId: string): Promise<any>;
116
+ listAssemblies(ctx: RunQueryCtx, args?: {
117
+ status?: string;
118
+ userId?: string;
119
+ limit?: number;
120
+ }): Promise<any[]>;
121
+ listResults(ctx: RunQueryCtx, args: {
122
+ assemblyId: string;
123
+ stepName?: string;
124
+ limit?: number;
125
+ }): Promise<any[]>;
126
+ storeAssemblyMetadata(ctx: RunMutationCtx, args: {
127
+ assemblyId: string;
128
+ userId?: string;
129
+ fields?: unknown;
130
+ }): Promise<any>;
131
+ api(): {
132
+ createAssembly: import("convex/server").RegisteredAction<"public", {
133
+ fields?: any;
134
+ templateId?: string | undefined;
135
+ notifyUrl?: string | undefined;
136
+ numExpectedUploadFiles?: number | undefined;
137
+ userId?: string | undefined;
138
+ steps?: any;
139
+ expires?: string | undefined;
140
+ additionalParams?: any;
141
+ }, Promise<{
142
+ assemblyId: string;
143
+ data: any;
144
+ }>>;
145
+ generateUploadParams: import("convex/server").RegisteredAction<"public", {
146
+ fields?: any;
147
+ templateId?: string | undefined;
148
+ notifyUrl?: string | undefined;
149
+ numExpectedUploadFiles?: number | undefined;
150
+ userId?: string | undefined;
151
+ steps?: any;
152
+ expires?: string | undefined;
153
+ additionalParams?: any;
154
+ }, Promise<{
155
+ params: string;
156
+ signature: string;
157
+ url: string;
158
+ }>>;
159
+ handleWebhook: import("convex/server").RegisteredAction<"public", {
160
+ signature?: string | undefined;
161
+ rawBody?: string | undefined;
162
+ verifySignature?: boolean | undefined;
163
+ payload: any;
164
+ }, Promise<{
165
+ assemblyId: string;
166
+ resultCount: number;
167
+ }>>;
168
+ getAssemblyStatus: import("convex/server").RegisteredQuery<"public", {
169
+ assemblyId: string;
170
+ }, Promise<any>>;
171
+ listAssemblies: import("convex/server").RegisteredQuery<"public", {
172
+ status?: string | undefined;
173
+ userId?: string | undefined;
174
+ limit?: number | undefined;
175
+ }, Promise<any[]>>;
176
+ listResults: import("convex/server").RegisteredQuery<"public", {
177
+ stepName?: string | undefined;
178
+ limit?: number | undefined;
179
+ assemblyId: string;
180
+ }, Promise<any[]>>;
181
+ storeAssemblyMetadata: import("convex/server").RegisteredMutation<"public", {
182
+ fields?: any;
183
+ userId?: string | undefined;
184
+ assemblyId: string;
185
+ }, Promise<any>>;
186
+ };
187
+ }
188
+ export declare function makeTransloaditAPI(component: TransloaditComponent, config?: Partial<TransloaditConfig>): {
189
+ createAssembly: import("convex/server").RegisteredAction<"public", {
190
+ fields?: any;
191
+ templateId?: string | undefined;
192
+ notifyUrl?: string | undefined;
193
+ numExpectedUploadFiles?: number | undefined;
194
+ userId?: string | undefined;
195
+ steps?: any;
196
+ expires?: string | undefined;
197
+ additionalParams?: any;
198
+ }, Promise<{
199
+ assemblyId: string;
200
+ data: any;
201
+ }>>;
202
+ generateUploadParams: import("convex/server").RegisteredAction<"public", {
203
+ fields?: any;
204
+ templateId?: string | undefined;
205
+ notifyUrl?: string | undefined;
206
+ numExpectedUploadFiles?: number | undefined;
207
+ userId?: string | undefined;
208
+ steps?: any;
209
+ expires?: string | undefined;
210
+ additionalParams?: any;
211
+ }, Promise<{
212
+ params: string;
213
+ signature: string;
214
+ url: string;
215
+ }>>;
216
+ handleWebhook: import("convex/server").RegisteredAction<"public", {
217
+ signature?: string | undefined;
218
+ rawBody?: string | undefined;
219
+ verifySignature?: boolean | undefined;
220
+ payload: any;
221
+ }, Promise<{
222
+ assemblyId: string;
223
+ resultCount: number;
224
+ }>>;
225
+ getAssemblyStatus: import("convex/server").RegisteredQuery<"public", {
226
+ assemblyId: string;
227
+ }, Promise<any>>;
228
+ listAssemblies: import("convex/server").RegisteredQuery<"public", {
229
+ status?: string | undefined;
230
+ userId?: string | undefined;
231
+ limit?: number | undefined;
232
+ }, Promise<any[]>>;
233
+ listResults: import("convex/server").RegisteredQuery<"public", {
234
+ stepName?: string | undefined;
235
+ limit?: number | undefined;
236
+ assemblyId: string;
237
+ }, Promise<any[]>>;
238
+ storeAssemblyMetadata: import("convex/server").RegisteredMutation<"public", {
239
+ fields?: any;
240
+ userId?: string | undefined;
241
+ assemblyId: string;
242
+ }, Promise<any>>;
243
+ };
244
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAK,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5E,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAYhD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+UAkB5B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE/D,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;8JAYlC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE3E,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;8MAS9B,CAAC;AAEH,qBAAa,iBAAiB;IACpB,SAAS,EAAE,oBAAoB,CAAC;IAChC,MAAM,EAAE,iBAAiB,CAAC;gBAGhC,SAAS,EAAE,oBAAoB,EAC/B,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;IAarC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,oBAAoB,EAAE,MAAM,EAAE,iBAAiB;IAIlE,cAAc,CAClB,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,KAAK,CAAC,OAAO,mBAAmB,CAAC;;;;IAQnC,oBAAoB,CACxB,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,KAAK,CAAC,OAAO,mBAAmB,CAAC;;;;;IAQnC,aAAa,CACjB,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE;QACJ,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;;;;IAQG,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM;IAItD,cAAc,CAClB,GAAG,EAAE,WAAW,EAChB,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAKvD,WAAW,CACf,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAK3D,qBAAqB,CACzB,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE;IAKjE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGJ;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,oBAAoB,EAC/B,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkGpC"}
@@ -0,0 +1,196 @@
1
+ import { actionGeneric, mutationGeneric, queryGeneric } from "convex/server";
2
+ import { v } from "convex/values";
3
+ function requireEnv(names) {
4
+ for (const name of names) {
5
+ const value = process.env[name];
6
+ if (value) {
7
+ return value;
8
+ }
9
+ }
10
+ throw new Error(`Missing ${names.join(" or ")} environment variable`);
11
+ }
12
+ export const vAssemblyResponse = v.object({
13
+ _id: v.string(),
14
+ _creationTime: v.number(),
15
+ assemblyId: v.string(),
16
+ status: v.optional(v.string()),
17
+ ok: v.optional(v.string()),
18
+ message: v.optional(v.string()),
19
+ templateId: v.optional(v.string()),
20
+ notifyUrl: v.optional(v.string()),
21
+ numExpectedUploadFiles: v.optional(v.number()),
22
+ fields: v.optional(v.any()),
23
+ uploads: v.optional(v.any()),
24
+ results: v.optional(v.any()),
25
+ error: v.optional(v.any()),
26
+ raw: v.optional(v.any()),
27
+ createdAt: v.number(),
28
+ updatedAt: v.number(),
29
+ userId: v.optional(v.string()),
30
+ });
31
+ export const vAssemblyResultResponse = v.object({
32
+ _id: v.string(),
33
+ _creationTime: v.number(),
34
+ assemblyId: v.string(),
35
+ stepName: v.string(),
36
+ resultId: v.optional(v.string()),
37
+ sslUrl: v.optional(v.string()),
38
+ name: v.optional(v.string()),
39
+ size: v.optional(v.number()),
40
+ mime: v.optional(v.string()),
41
+ raw: v.any(),
42
+ createdAt: v.number(),
43
+ });
44
+ export const vCreateAssemblyArgs = v.object({
45
+ templateId: v.optional(v.string()),
46
+ steps: v.optional(v.any()),
47
+ fields: v.optional(v.any()),
48
+ notifyUrl: v.optional(v.string()),
49
+ numExpectedUploadFiles: v.optional(v.number()),
50
+ expires: v.optional(v.string()),
51
+ additionalParams: v.optional(v.any()),
52
+ userId: v.optional(v.string()),
53
+ });
54
+ export class TransloaditClient {
55
+ constructor(component, config) {
56
+ this.component = component;
57
+ this.config = {
58
+ authKey: config?.authKey ??
59
+ requireEnv(["TRANSLOADIT_AUTH_KEY", "TRANSLOADIT_KEY"]),
60
+ authSecret: config?.authSecret ??
61
+ requireEnv(["TRANSLOADIT_AUTH_SECRET", "TRANSLOADIT_SECRET"]),
62
+ };
63
+ }
64
+ static create(component, config) {
65
+ return new TransloaditClient(component, config);
66
+ }
67
+ async createAssembly(ctx, args) {
68
+ return ctx.runAction(this.component.lib.createAssembly, {
69
+ ...args,
70
+ config: this.config,
71
+ });
72
+ }
73
+ async generateUploadParams(ctx, args) {
74
+ return ctx.runAction(this.component.lib.generateUploadParams, {
75
+ ...args,
76
+ config: this.config,
77
+ });
78
+ }
79
+ async handleWebhook(ctx, args) {
80
+ return ctx.runAction(this.component.lib.handleWebhook, {
81
+ ...args,
82
+ config: { authSecret: this.config.authSecret },
83
+ });
84
+ }
85
+ async getAssemblyStatus(ctx, assemblyId) {
86
+ return ctx.runQuery(this.component.lib.getAssemblyStatus, { assemblyId });
87
+ }
88
+ async listAssemblies(ctx, args) {
89
+ return ctx.runQuery(this.component.lib.listAssemblies, args ?? {});
90
+ }
91
+ async listResults(ctx, args) {
92
+ return ctx.runQuery(this.component.lib.listResults, args);
93
+ }
94
+ async storeAssemblyMetadata(ctx, args) {
95
+ return ctx.runMutation(this.component.lib.storeAssemblyMetadata, args);
96
+ }
97
+ api() {
98
+ return makeTransloaditAPI(this.component, this.config);
99
+ }
100
+ }
101
+ export function makeTransloaditAPI(component, config) {
102
+ const resolvedConfig = {
103
+ authKey: config?.authKey ??
104
+ requireEnv(["TRANSLOADIT_AUTH_KEY", "TRANSLOADIT_KEY"]),
105
+ authSecret: config?.authSecret ??
106
+ requireEnv(["TRANSLOADIT_AUTH_SECRET", "TRANSLOADIT_SECRET"]),
107
+ };
108
+ return {
109
+ createAssembly: actionGeneric({
110
+ args: vCreateAssemblyArgs,
111
+ returns: v.object({
112
+ assemblyId: v.string(),
113
+ data: v.any(),
114
+ }),
115
+ handler: async (ctx, args) => {
116
+ return ctx.runAction(component.lib.createAssembly, {
117
+ ...args,
118
+ config: resolvedConfig,
119
+ });
120
+ },
121
+ }),
122
+ generateUploadParams: actionGeneric({
123
+ args: vCreateAssemblyArgs,
124
+ returns: v.object({
125
+ params: v.string(),
126
+ signature: v.string(),
127
+ url: v.string(),
128
+ }),
129
+ handler: async (ctx, args) => {
130
+ return ctx.runAction(component.lib.generateUploadParams, {
131
+ ...args,
132
+ config: resolvedConfig,
133
+ });
134
+ },
135
+ }),
136
+ handleWebhook: actionGeneric({
137
+ args: {
138
+ payload: v.any(),
139
+ rawBody: v.optional(v.string()),
140
+ signature: v.optional(v.string()),
141
+ verifySignature: v.optional(v.boolean()),
142
+ },
143
+ returns: v.object({
144
+ assemblyId: v.string(),
145
+ resultCount: v.number(),
146
+ }),
147
+ handler: async (ctx, args) => {
148
+ return ctx.runAction(component.lib.handleWebhook, {
149
+ ...args,
150
+ config: { authSecret: resolvedConfig.authSecret },
151
+ });
152
+ },
153
+ }),
154
+ getAssemblyStatus: queryGeneric({
155
+ args: { assemblyId: v.string() },
156
+ returns: v.union(vAssemblyResponse, v.null()),
157
+ handler: async (ctx, args) => {
158
+ return ctx.runQuery(component.lib.getAssemblyStatus, args);
159
+ },
160
+ }),
161
+ listAssemblies: queryGeneric({
162
+ args: {
163
+ status: v.optional(v.string()),
164
+ userId: v.optional(v.string()),
165
+ limit: v.optional(v.number()),
166
+ },
167
+ returns: v.array(vAssemblyResponse),
168
+ handler: async (ctx, args) => {
169
+ return ctx.runQuery(component.lib.listAssemblies, args);
170
+ },
171
+ }),
172
+ listResults: queryGeneric({
173
+ args: {
174
+ assemblyId: v.string(),
175
+ stepName: v.optional(v.string()),
176
+ limit: v.optional(v.number()),
177
+ },
178
+ returns: v.array(vAssemblyResultResponse),
179
+ handler: async (ctx, args) => {
180
+ return ctx.runQuery(component.lib.listResults, args);
181
+ },
182
+ }),
183
+ storeAssemblyMetadata: mutationGeneric({
184
+ args: {
185
+ assemblyId: v.string(),
186
+ userId: v.optional(v.string()),
187
+ fields: v.optional(v.any()),
188
+ },
189
+ returns: v.union(vAssemblyResponse, v.null()),
190
+ handler: async (ctx, args) => {
191
+ return ctx.runMutation(component.lib.storeAssemblyMetadata, args);
192
+ },
193
+ }),
194
+ };
195
+ }
196
+ //# sourceMappingURL=index.js.map