Skip to content

Commit 298f705

Browse files
committed
fix qa app template for assembly options
1 parent 15ae03a commit 298f705

File tree

1 file changed

+53
-10
lines changed

1 file changed

+53
-10
lines changed

scripts/qa/app-template.ts

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ export const writeAppFiles = async ({
292292
await writeFile(
293293
join(convexDir, "wedding.ts"),
294294
[
295-
'import { action, internalMutation } from "./_generated/server";',
295+
'import { vAssemblyOptions } from "@transloadit/convex";',
296296
'import { v } from "convex/values";',
297+
'import { action, internalMutation } from "./_generated/server";',
297298
'import { components, internal } from "./_generated/api";',
298299
'import { buildWeddingSteps } from "../lib/transloadit-steps";',
299300
"",
@@ -345,15 +346,15 @@ export const writeAppFiles = async ({
345346
" },",
346347
"});",
347348
"",
348-
"export const createWeddingAssembly = action({",
349+
"export const createWeddingAssemblyOptions = action({",
349350
" args: {",
350351
" fileCount: v.number(),",
351352
" guestName: v.optional(v.string()),",
352353
" uploadCode: v.optional(v.string()),",
353354
" },",
354355
" returns: v.object({",
355-
" assemblyId: v.string(),",
356-
" data: v.any(),",
356+
" assemblyOptions: vAssemblyOptions,",
357+
" params: v.any(),",
357358
" }),",
358359
" handler: async (ctx, args) => {",
359360
" const identity = await ctx.auth.getUserIdentity();",
@@ -370,10 +371,10 @@ export const writeAppFiles = async ({
370371
" }",
371372
" }",
372373
"",
373-
' const notifyUrl = requireEnv("TRANSLOADIT_NOTIFY_URL");',
374374
" const steps = buildWeddingSteps();",
375+
' const notifyUrl = requireEnv("TRANSLOADIT_NOTIFY_URL");',
375376
" const fileCount = Math.max(1, args.fileCount);",
376-
" return ctx.runAction(components.transloadit.lib.createAssembly, {",
377+
" const assemblyArgs = {",
377378
" steps,",
378379
" notifyUrl,",
379380
" numExpectedUploadFiles: fileCount,",
@@ -384,14 +385,56 @@ export const writeAppFiles = async ({
384385
" userId: identity.subject,",
385386
" },",
386387
" userId: identity.subject,",
387-
" config: {",
388-
' authKey: requireEnv("TRANSLOADIT_KEY"),',
389-
' authSecret: requireEnv("TRANSLOADIT_SECRET"),',
388+
" };",
389+
" const assemblyOptions = await ctx.runAction(",
390+
" components.transloadit.lib.createAssemblyOptions,",
391+
" {",
392+
" ...assemblyArgs,",
393+
" config: {",
394+
' authKey: requireEnv("TRANSLOADIT_KEY"),',
395+
' authSecret: requireEnv("TRANSLOADIT_SECRET"),',
396+
" },",
390397
" },",
391-
" });",
398+
" );",
399+
" const parsedParams = safeParseParams(assemblyOptions.params);",
400+
" const params = redactSecrets(parsedParams ?? assemblyArgs);",
401+
" return { assemblyOptions, params };",
392402
" },",
393403
"});",
394404
"",
405+
"const safeParseParams = (value: string) => {",
406+
" try {",
407+
" return JSON.parse(value);",
408+
" } catch (error) {",
409+
' console.warn("Failed to parse Transloadit params", error);',
410+
" return null;",
411+
" }",
412+
"};",
413+
"",
414+
"const secretKeys = new Set([",
415+
' "secret",',
416+
' "key",',
417+
' "credentials",',
418+
' "authSecret",',
419+
' "authKey",',
420+
"]);",
421+
"",
422+
"const redactSecrets = (value: unknown): unknown => {",
423+
" if (Array.isArray(value)) {",
424+
" return value.map((item) => redactSecrets(item));",
425+
" }",
426+
' if (value && typeof value === "object") {',
427+
" const entries = Object.entries(value).map(([key, val]) => {",
428+
" if (secretKeys.has(key)) {",
429+
' return [key, "***"];',
430+
" }",
431+
" return [key, redactSecrets(val)];",
432+
" });",
433+
" return Object.fromEntries(entries);",
434+
" }",
435+
" return value;",
436+
"};",
437+
"",
395438
].join("\n"),
396439
"utf8",
397440
);

0 commit comments

Comments
 (0)