@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.
- package/README.md +235 -0
- package/dist/client/index.d.ts +244 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +196 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +24 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +20 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +15 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +101 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +16 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +31 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +18 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/apiUtils.d.ts +31 -0
- package/dist/component/apiUtils.d.ts.map +1 -0
- package/dist/component/apiUtils.js +94 -0
- package/dist/component/apiUtils.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +226 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +383 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +67 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +45 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/package.json +3 -0
- package/dist/react/index.d.ts +85 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +163 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +86 -0
- package/src/client/index.ts +260 -0
- package/src/client/types.ts +64 -0
- package/src/component/_generated/api.ts +32 -0
- package/src/component/_generated/component.ts +122 -0
- package/src/component/_generated/dataModel.ts +30 -0
- package/src/component/_generated/server.ts +72 -0
- package/src/component/apiUtils.test.ts +48 -0
- package/src/component/apiUtils.ts +156 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/lib.test.ts +63 -0
- package/src/component/lib.ts +466 -0
- package/src/component/schema.ts +48 -0
- package/src/component/setup.test.ts +6 -0
- package/src/react/index.tsx +292 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { actionGeneric, mutationGeneric, queryGeneric } from "convex/server";
|
|
2
|
+
import { type Infer, v } from "convex/values";
|
|
3
|
+
import type { ComponentApi } from "../component/_generated/component.js";
|
|
4
|
+
import type { RunActionCtx, RunMutationCtx, RunQueryCtx } from "./types.js";
|
|
5
|
+
|
|
6
|
+
export interface TransloaditConfig {
|
|
7
|
+
authKey: string;
|
|
8
|
+
authSecret: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type TransloaditComponent = ComponentApi;
|
|
12
|
+
|
|
13
|
+
function requireEnv(names: string[]): string {
|
|
14
|
+
for (const name of names) {
|
|
15
|
+
const value = process.env[name];
|
|
16
|
+
if (value) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`Missing ${names.join(" or ")} environment variable`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const vAssemblyResponse = v.object({
|
|
24
|
+
_id: v.string(),
|
|
25
|
+
_creationTime: v.number(),
|
|
26
|
+
assemblyId: v.string(),
|
|
27
|
+
status: v.optional(v.string()),
|
|
28
|
+
ok: v.optional(v.string()),
|
|
29
|
+
message: v.optional(v.string()),
|
|
30
|
+
templateId: v.optional(v.string()),
|
|
31
|
+
notifyUrl: v.optional(v.string()),
|
|
32
|
+
numExpectedUploadFiles: v.optional(v.number()),
|
|
33
|
+
fields: v.optional(v.any()),
|
|
34
|
+
uploads: v.optional(v.any()),
|
|
35
|
+
results: v.optional(v.any()),
|
|
36
|
+
error: v.optional(v.any()),
|
|
37
|
+
raw: v.optional(v.any()),
|
|
38
|
+
createdAt: v.number(),
|
|
39
|
+
updatedAt: v.number(),
|
|
40
|
+
userId: v.optional(v.string()),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export type AssemblyResponse = Infer<typeof vAssemblyResponse>;
|
|
44
|
+
|
|
45
|
+
export const vAssemblyResultResponse = v.object({
|
|
46
|
+
_id: v.string(),
|
|
47
|
+
_creationTime: v.number(),
|
|
48
|
+
assemblyId: v.string(),
|
|
49
|
+
stepName: v.string(),
|
|
50
|
+
resultId: v.optional(v.string()),
|
|
51
|
+
sslUrl: v.optional(v.string()),
|
|
52
|
+
name: v.optional(v.string()),
|
|
53
|
+
size: v.optional(v.number()),
|
|
54
|
+
mime: v.optional(v.string()),
|
|
55
|
+
raw: v.any(),
|
|
56
|
+
createdAt: v.number(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export type AssemblyResultResponse = Infer<typeof vAssemblyResultResponse>;
|
|
60
|
+
|
|
61
|
+
export const vCreateAssemblyArgs = v.object({
|
|
62
|
+
templateId: v.optional(v.string()),
|
|
63
|
+
steps: v.optional(v.any()),
|
|
64
|
+
fields: v.optional(v.any()),
|
|
65
|
+
notifyUrl: v.optional(v.string()),
|
|
66
|
+
numExpectedUploadFiles: v.optional(v.number()),
|
|
67
|
+
expires: v.optional(v.string()),
|
|
68
|
+
additionalParams: v.optional(v.any()),
|
|
69
|
+
userId: v.optional(v.string()),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export class TransloaditClient {
|
|
73
|
+
declare component: TransloaditComponent;
|
|
74
|
+
declare config: TransloaditConfig;
|
|
75
|
+
|
|
76
|
+
constructor(
|
|
77
|
+
component: TransloaditComponent,
|
|
78
|
+
config?: Partial<TransloaditConfig>,
|
|
79
|
+
) {
|
|
80
|
+
this.component = component;
|
|
81
|
+
this.config = {
|
|
82
|
+
authKey:
|
|
83
|
+
config?.authKey ??
|
|
84
|
+
requireEnv(["TRANSLOADIT_AUTH_KEY", "TRANSLOADIT_KEY"]),
|
|
85
|
+
authSecret:
|
|
86
|
+
config?.authSecret ??
|
|
87
|
+
requireEnv(["TRANSLOADIT_AUTH_SECRET", "TRANSLOADIT_SECRET"]),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static create(component: TransloaditComponent, config: TransloaditConfig) {
|
|
92
|
+
return new TransloaditClient(component, config);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async createAssembly(
|
|
96
|
+
ctx: RunActionCtx,
|
|
97
|
+
args: Infer<typeof vCreateAssemblyArgs>,
|
|
98
|
+
) {
|
|
99
|
+
return ctx.runAction(this.component.lib.createAssembly, {
|
|
100
|
+
...args,
|
|
101
|
+
config: this.config,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async generateUploadParams(
|
|
106
|
+
ctx: RunActionCtx,
|
|
107
|
+
args: Infer<typeof vCreateAssemblyArgs>,
|
|
108
|
+
) {
|
|
109
|
+
return ctx.runAction(this.component.lib.generateUploadParams, {
|
|
110
|
+
...args,
|
|
111
|
+
config: this.config,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async handleWebhook(
|
|
116
|
+
ctx: RunActionCtx,
|
|
117
|
+
args: {
|
|
118
|
+
payload: unknown;
|
|
119
|
+
rawBody?: string;
|
|
120
|
+
signature?: string;
|
|
121
|
+
verifySignature?: boolean;
|
|
122
|
+
},
|
|
123
|
+
) {
|
|
124
|
+
return ctx.runAction(this.component.lib.handleWebhook, {
|
|
125
|
+
...args,
|
|
126
|
+
config: { authSecret: this.config.authSecret },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async getAssemblyStatus(ctx: RunQueryCtx, assemblyId: string) {
|
|
131
|
+
return ctx.runQuery(this.component.lib.getAssemblyStatus, { assemblyId });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async listAssemblies(
|
|
135
|
+
ctx: RunQueryCtx,
|
|
136
|
+
args?: { status?: string; userId?: string; limit?: number },
|
|
137
|
+
) {
|
|
138
|
+
return ctx.runQuery(this.component.lib.listAssemblies, args ?? {});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async listResults(
|
|
142
|
+
ctx: RunQueryCtx,
|
|
143
|
+
args: { assemblyId: string; stepName?: string; limit?: number },
|
|
144
|
+
) {
|
|
145
|
+
return ctx.runQuery(this.component.lib.listResults, args);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async storeAssemblyMetadata(
|
|
149
|
+
ctx: RunMutationCtx,
|
|
150
|
+
args: { assemblyId: string; userId?: string; fields?: unknown },
|
|
151
|
+
) {
|
|
152
|
+
return ctx.runMutation(this.component.lib.storeAssemblyMetadata, args);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
api() {
|
|
156
|
+
return makeTransloaditAPI(this.component, this.config);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function makeTransloaditAPI(
|
|
161
|
+
component: TransloaditComponent,
|
|
162
|
+
config?: Partial<TransloaditConfig>,
|
|
163
|
+
) {
|
|
164
|
+
const resolvedConfig: TransloaditConfig = {
|
|
165
|
+
authKey:
|
|
166
|
+
config?.authKey ??
|
|
167
|
+
requireEnv(["TRANSLOADIT_AUTH_KEY", "TRANSLOADIT_KEY"]),
|
|
168
|
+
authSecret:
|
|
169
|
+
config?.authSecret ??
|
|
170
|
+
requireEnv(["TRANSLOADIT_AUTH_SECRET", "TRANSLOADIT_SECRET"]),
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
createAssembly: actionGeneric({
|
|
175
|
+
args: vCreateAssemblyArgs,
|
|
176
|
+
returns: v.object({
|
|
177
|
+
assemblyId: v.string(),
|
|
178
|
+
data: v.any(),
|
|
179
|
+
}),
|
|
180
|
+
handler: async (ctx, args) => {
|
|
181
|
+
return ctx.runAction(component.lib.createAssembly, {
|
|
182
|
+
...args,
|
|
183
|
+
config: resolvedConfig,
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
}),
|
|
187
|
+
generateUploadParams: actionGeneric({
|
|
188
|
+
args: vCreateAssemblyArgs,
|
|
189
|
+
returns: v.object({
|
|
190
|
+
params: v.string(),
|
|
191
|
+
signature: v.string(),
|
|
192
|
+
url: v.string(),
|
|
193
|
+
}),
|
|
194
|
+
handler: async (ctx, args) => {
|
|
195
|
+
return ctx.runAction(component.lib.generateUploadParams, {
|
|
196
|
+
...args,
|
|
197
|
+
config: resolvedConfig,
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
handleWebhook: actionGeneric({
|
|
202
|
+
args: {
|
|
203
|
+
payload: v.any(),
|
|
204
|
+
rawBody: v.optional(v.string()),
|
|
205
|
+
signature: v.optional(v.string()),
|
|
206
|
+
verifySignature: v.optional(v.boolean()),
|
|
207
|
+
},
|
|
208
|
+
returns: v.object({
|
|
209
|
+
assemblyId: v.string(),
|
|
210
|
+
resultCount: v.number(),
|
|
211
|
+
}),
|
|
212
|
+
handler: async (ctx, args) => {
|
|
213
|
+
return ctx.runAction(component.lib.handleWebhook, {
|
|
214
|
+
...args,
|
|
215
|
+
config: { authSecret: resolvedConfig.authSecret },
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
}),
|
|
219
|
+
getAssemblyStatus: queryGeneric({
|
|
220
|
+
args: { assemblyId: v.string() },
|
|
221
|
+
returns: v.union(vAssemblyResponse, v.null()),
|
|
222
|
+
handler: async (ctx, args) => {
|
|
223
|
+
return ctx.runQuery(component.lib.getAssemblyStatus, args);
|
|
224
|
+
},
|
|
225
|
+
}),
|
|
226
|
+
listAssemblies: queryGeneric({
|
|
227
|
+
args: {
|
|
228
|
+
status: v.optional(v.string()),
|
|
229
|
+
userId: v.optional(v.string()),
|
|
230
|
+
limit: v.optional(v.number()),
|
|
231
|
+
},
|
|
232
|
+
returns: v.array(vAssemblyResponse),
|
|
233
|
+
handler: async (ctx, args) => {
|
|
234
|
+
return ctx.runQuery(component.lib.listAssemblies, args);
|
|
235
|
+
},
|
|
236
|
+
}),
|
|
237
|
+
listResults: queryGeneric({
|
|
238
|
+
args: {
|
|
239
|
+
assemblyId: v.string(),
|
|
240
|
+
stepName: v.optional(v.string()),
|
|
241
|
+
limit: v.optional(v.number()),
|
|
242
|
+
},
|
|
243
|
+
returns: v.array(vAssemblyResultResponse),
|
|
244
|
+
handler: async (ctx, args) => {
|
|
245
|
+
return ctx.runQuery(component.lib.listResults, args);
|
|
246
|
+
},
|
|
247
|
+
}),
|
|
248
|
+
storeAssemblyMetadata: mutationGeneric({
|
|
249
|
+
args: {
|
|
250
|
+
assemblyId: v.string(),
|
|
251
|
+
userId: v.optional(v.string()),
|
|
252
|
+
fields: v.optional(v.any()),
|
|
253
|
+
},
|
|
254
|
+
returns: v.union(vAssemblyResponse, v.null()),
|
|
255
|
+
handler: async (ctx, args) => {
|
|
256
|
+
return ctx.runMutation(component.lib.storeAssemblyMetadata, args);
|
|
257
|
+
},
|
|
258
|
+
}),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Expand,
|
|
3
|
+
FunctionArgs,
|
|
4
|
+
FunctionReference,
|
|
5
|
+
FunctionReturnType,
|
|
6
|
+
StorageActionWriter,
|
|
7
|
+
StorageReader,
|
|
8
|
+
} from "convex/server";
|
|
9
|
+
import type { GenericId } from "convex/values";
|
|
10
|
+
|
|
11
|
+
export type RunQueryCtx = {
|
|
12
|
+
runQuery: <Query extends FunctionReference<"query", "internal">>(
|
|
13
|
+
query: Query,
|
|
14
|
+
args: FunctionArgs<Query>,
|
|
15
|
+
) => Promise<FunctionReturnType<Query>>;
|
|
16
|
+
};
|
|
17
|
+
export type RunMutationCtx = RunQueryCtx & {
|
|
18
|
+
runMutation: <Mutation extends FunctionReference<"mutation", "internal">>(
|
|
19
|
+
mutation: Mutation,
|
|
20
|
+
args: FunctionArgs<Mutation>,
|
|
21
|
+
) => Promise<FunctionReturnType<Mutation>>;
|
|
22
|
+
};
|
|
23
|
+
export type RunActionCtx = RunMutationCtx & {
|
|
24
|
+
runAction: <Action extends FunctionReference<"action", "internal">>(
|
|
25
|
+
action: Action,
|
|
26
|
+
args: FunctionArgs<Action>,
|
|
27
|
+
) => Promise<FunctionReturnType<Action>>;
|
|
28
|
+
};
|
|
29
|
+
export type ActionCtx = RunActionCtx & {
|
|
30
|
+
storage: StorageActionWriter;
|
|
31
|
+
};
|
|
32
|
+
export type QueryCtx = RunQueryCtx & {
|
|
33
|
+
storage: StorageReader;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type OpaqueIds<T> = T extends GenericId<infer _T>
|
|
37
|
+
? string
|
|
38
|
+
: T extends (infer U)[]
|
|
39
|
+
? OpaqueIds<U>[]
|
|
40
|
+
: T extends ArrayBuffer
|
|
41
|
+
? ArrayBuffer
|
|
42
|
+
: T extends object
|
|
43
|
+
? {
|
|
44
|
+
[K in keyof T]: OpaqueIds<T[K]>;
|
|
45
|
+
}
|
|
46
|
+
: T;
|
|
47
|
+
|
|
48
|
+
export type UseApi<API> = Expand<{
|
|
49
|
+
[mod in keyof API]: API[mod] extends FunctionReference<
|
|
50
|
+
infer FType,
|
|
51
|
+
"public",
|
|
52
|
+
infer FArgs,
|
|
53
|
+
infer FReturnType,
|
|
54
|
+
infer FComponentPath
|
|
55
|
+
>
|
|
56
|
+
? FunctionReference<
|
|
57
|
+
FType,
|
|
58
|
+
"internal",
|
|
59
|
+
OpaqueIds<FArgs>,
|
|
60
|
+
OpaqueIds<FReturnType>,
|
|
61
|
+
FComponentPath
|
|
62
|
+
>
|
|
63
|
+
: UseApi<API[mod]>;
|
|
64
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `api` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type * as apiUtils from "../apiUtils.js";
|
|
12
|
+
import type * as lib from "../lib.js";
|
|
13
|
+
|
|
14
|
+
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
15
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
16
|
+
|
|
17
|
+
const fullApi: ApiFromModules<{
|
|
18
|
+
apiUtils: typeof apiUtils;
|
|
19
|
+
lib: typeof lib;
|
|
20
|
+
}> = anyApi as any;
|
|
21
|
+
|
|
22
|
+
export const api: FilterApi<
|
|
23
|
+
typeof fullApi,
|
|
24
|
+
FunctionReference<any, "public">
|
|
25
|
+
> = anyApi as any;
|
|
26
|
+
|
|
27
|
+
export const internal: FilterApi<
|
|
28
|
+
typeof fullApi,
|
|
29
|
+
FunctionReference<any, "internal">
|
|
30
|
+
> = anyApi as any;
|
|
31
|
+
|
|
32
|
+
export const components = componentsGeneric() as unknown as {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `ComponentApi` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { FunctionReference } from "convex/server";
|
|
12
|
+
|
|
13
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
14
|
+
lib: {
|
|
15
|
+
upsertAssembly: FunctionReference<
|
|
16
|
+
"mutation",
|
|
17
|
+
"internal",
|
|
18
|
+
{
|
|
19
|
+
assemblyId: string;
|
|
20
|
+
status?: string;
|
|
21
|
+
ok?: string;
|
|
22
|
+
message?: string;
|
|
23
|
+
templateId?: string;
|
|
24
|
+
notifyUrl?: string;
|
|
25
|
+
numExpectedUploadFiles?: number;
|
|
26
|
+
fields?: any;
|
|
27
|
+
uploads?: any;
|
|
28
|
+
results?: any;
|
|
29
|
+
error?: any;
|
|
30
|
+
raw?: any;
|
|
31
|
+
userId?: string;
|
|
32
|
+
},
|
|
33
|
+
string,
|
|
34
|
+
Name
|
|
35
|
+
>;
|
|
36
|
+
replaceResultsForAssembly: FunctionReference<
|
|
37
|
+
"mutation",
|
|
38
|
+
"internal",
|
|
39
|
+
{
|
|
40
|
+
assemblyId: string;
|
|
41
|
+
results: Array<{ stepName: string; result: any }>;
|
|
42
|
+
},
|
|
43
|
+
null,
|
|
44
|
+
Name
|
|
45
|
+
>;
|
|
46
|
+
createAssembly: FunctionReference<
|
|
47
|
+
"action",
|
|
48
|
+
"internal",
|
|
49
|
+
{
|
|
50
|
+
config: { authKey: string; authSecret: string };
|
|
51
|
+
templateId?: string;
|
|
52
|
+
steps?: any;
|
|
53
|
+
fields?: any;
|
|
54
|
+
notifyUrl?: string;
|
|
55
|
+
numExpectedUploadFiles?: number;
|
|
56
|
+
expires?: string;
|
|
57
|
+
additionalParams?: any;
|
|
58
|
+
userId?: string;
|
|
59
|
+
},
|
|
60
|
+
{ assemblyId: string; data: any },
|
|
61
|
+
Name
|
|
62
|
+
>;
|
|
63
|
+
generateUploadParams: FunctionReference<
|
|
64
|
+
"action",
|
|
65
|
+
"internal",
|
|
66
|
+
{
|
|
67
|
+
config: { authKey: string; authSecret: string };
|
|
68
|
+
templateId?: string;
|
|
69
|
+
steps?: any;
|
|
70
|
+
fields?: any;
|
|
71
|
+
notifyUrl?: string;
|
|
72
|
+
numExpectedUploadFiles?: number;
|
|
73
|
+
expires?: string;
|
|
74
|
+
additionalParams?: any;
|
|
75
|
+
userId?: string;
|
|
76
|
+
},
|
|
77
|
+
{ params: string; signature: string; url: string },
|
|
78
|
+
Name
|
|
79
|
+
>;
|
|
80
|
+
handleWebhook: FunctionReference<
|
|
81
|
+
"action",
|
|
82
|
+
"internal",
|
|
83
|
+
{
|
|
84
|
+
payload: any;
|
|
85
|
+
rawBody?: string;
|
|
86
|
+
signature?: string;
|
|
87
|
+
verifySignature?: boolean;
|
|
88
|
+
config?: { authSecret: string };
|
|
89
|
+
},
|
|
90
|
+
{ assemblyId: string; resultCount: number },
|
|
91
|
+
Name
|
|
92
|
+
>;
|
|
93
|
+
getAssemblyStatus: FunctionReference<
|
|
94
|
+
"query",
|
|
95
|
+
"internal",
|
|
96
|
+
{ assemblyId: string },
|
|
97
|
+
any,
|
|
98
|
+
Name
|
|
99
|
+
>;
|
|
100
|
+
listAssemblies: FunctionReference<
|
|
101
|
+
"query",
|
|
102
|
+
"internal",
|
|
103
|
+
{ status?: string; userId?: string; limit?: number },
|
|
104
|
+
Array<any>,
|
|
105
|
+
Name
|
|
106
|
+
>;
|
|
107
|
+
listResults: FunctionReference<
|
|
108
|
+
"query",
|
|
109
|
+
"internal",
|
|
110
|
+
{ assemblyId: string; stepName?: string; limit?: number },
|
|
111
|
+
Array<any>,
|
|
112
|
+
Name
|
|
113
|
+
>;
|
|
114
|
+
storeAssemblyMetadata: FunctionReference<
|
|
115
|
+
"mutation",
|
|
116
|
+
"internal",
|
|
117
|
+
{ assemblyId: string; userId?: string; fields?: any },
|
|
118
|
+
any,
|
|
119
|
+
Name
|
|
120
|
+
>;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated data model types.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
DataModelFromSchemaDefinition,
|
|
13
|
+
DocumentByName,
|
|
14
|
+
TableNamesInDataModel,
|
|
15
|
+
SystemTableNames,
|
|
16
|
+
} from "convex/server";
|
|
17
|
+
import type { GenericId } from "convex/values";
|
|
18
|
+
import schema from "../schema.js";
|
|
19
|
+
|
|
20
|
+
export type TableNames = TableNamesInDataModel<DataModel>;
|
|
21
|
+
|
|
22
|
+
export type Doc<TableName extends TableNames> = DocumentByName<
|
|
23
|
+
DataModel,
|
|
24
|
+
TableName
|
|
25
|
+
>;
|
|
26
|
+
|
|
27
|
+
export type Id<TableName extends TableNames | SystemTableNames> =
|
|
28
|
+
GenericId<TableName>;
|
|
29
|
+
|
|
30
|
+
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
ActionBuilder,
|
|
13
|
+
HttpActionBuilder,
|
|
14
|
+
MutationBuilder,
|
|
15
|
+
QueryBuilder,
|
|
16
|
+
GenericActionCtx,
|
|
17
|
+
GenericMutationCtx,
|
|
18
|
+
GenericQueryCtx,
|
|
19
|
+
GenericDatabaseReader,
|
|
20
|
+
GenericDatabaseWriter,
|
|
21
|
+
} from "convex/server";
|
|
22
|
+
import {
|
|
23
|
+
actionGeneric,
|
|
24
|
+
httpActionGeneric,
|
|
25
|
+
queryGeneric,
|
|
26
|
+
mutationGeneric,
|
|
27
|
+
internalActionGeneric,
|
|
28
|
+
internalMutationGeneric,
|
|
29
|
+
internalQueryGeneric,
|
|
30
|
+
} from "convex/server";
|
|
31
|
+
import type { DataModel } from "./dataModel.js";
|
|
32
|
+
|
|
33
|
+
export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
|
|
34
|
+
|
|
35
|
+
export const internalQuery: QueryBuilder<DataModel, "internal"> =
|
|
36
|
+
internalQueryGeneric;
|
|
37
|
+
|
|
38
|
+
export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
|
|
39
|
+
|
|
40
|
+
export const internalMutation: MutationBuilder<DataModel, "internal"> =
|
|
41
|
+
internalMutationGeneric;
|
|
42
|
+
|
|
43
|
+
export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
|
|
44
|
+
|
|
45
|
+
export const internalAction: ActionBuilder<DataModel, "internal"> =
|
|
46
|
+
internalActionGeneric;
|
|
47
|
+
|
|
48
|
+
export const httpAction: HttpActionBuilder = httpActionGeneric;
|
|
49
|
+
|
|
50
|
+
type GenericCtx =
|
|
51
|
+
| GenericActionCtx<DataModel>
|
|
52
|
+
| GenericMutationCtx<DataModel>
|
|
53
|
+
| GenericQueryCtx<DataModel>;
|
|
54
|
+
|
|
55
|
+
export type QueryCtx = GenericQueryCtx<DataModel>;
|
|
56
|
+
|
|
57
|
+
export type MutationCtx = GenericMutationCtx<DataModel>;
|
|
58
|
+
|
|
59
|
+
export type ActionCtx = GenericActionCtx<DataModel>;
|
|
60
|
+
|
|
61
|
+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
62
|
+
|
|
63
|
+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
64
|
+
|
|
65
|
+
export type DatabaseReaderWriter = GenericDatabaseWriter<DataModel> &
|
|
66
|
+
GenericDatabaseReader<DataModel>;
|
|
67
|
+
|
|
68
|
+
export type FunctionCtx = GenericCtx & {
|
|
69
|
+
runQuery: GenericQueryCtx<DataModel>["runQuery"];
|
|
70
|
+
runMutation: GenericMutationCtx<DataModel>["runMutation"];
|
|
71
|
+
runAction: GenericActionCtx<DataModel>["runAction"];
|
|
72
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createHmac } from "node:crypto";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
buildTransloaditParams,
|
|
5
|
+
signTransloaditParams,
|
|
6
|
+
verifyWebhookSignature,
|
|
7
|
+
} from "./apiUtils.js";
|
|
8
|
+
|
|
9
|
+
describe("apiUtils", () => {
|
|
10
|
+
test("buildTransloaditParams requires templateId or steps", () => {
|
|
11
|
+
expect(() =>
|
|
12
|
+
buildTransloaditParams({
|
|
13
|
+
authKey: "key",
|
|
14
|
+
}),
|
|
15
|
+
).toThrow("Provide either templateId or steps");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("signTransloaditParams uses sha384", async () => {
|
|
19
|
+
const { paramsString } = buildTransloaditParams({
|
|
20
|
+
authKey: "key",
|
|
21
|
+
templateId: "tmpl_123",
|
|
22
|
+
notifyUrl: "https://example.com/webhook",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const signature = await signTransloaditParams(paramsString, "secret");
|
|
26
|
+
expect(signature.startsWith("sha384:")).toBe(true);
|
|
27
|
+
|
|
28
|
+
const expected = createHmac("sha384", "secret")
|
|
29
|
+
.update(paramsString)
|
|
30
|
+
.digest("hex");
|
|
31
|
+
expect(signature).toBe(`sha384:${expected}`);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("verifyWebhookSignature supports sha1 fallback", async () => {
|
|
35
|
+
const payload = { ok: "ASSEMBLY_COMPLETED", assembly_id: "asm_123" };
|
|
36
|
+
const rawBody = JSON.stringify(payload);
|
|
37
|
+
const secret = "webhook-secret";
|
|
38
|
+
const digest = createHmac("sha1", secret).update(rawBody).digest("hex");
|
|
39
|
+
|
|
40
|
+
const verified = await verifyWebhookSignature({
|
|
41
|
+
rawBody,
|
|
42
|
+
signatureHeader: `sha1:${digest}`,
|
|
43
|
+
authSecret: secret,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(verified).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
});
|