Skip to content

Commit 1595d6b

Browse files
fix(confluence-schemas): expose extendable bases before .superRefine
confluenceCommentScopedSchema and confluenceBlogPostScopedSchema were built with .extend(...).superRefine(...). superRefine returns a ZodEffects which has no .extend method, so the three downstream .extend() calls (confluenceUpdateCommentBodySchema, confluenceGetBlogPostBodySchema, confluenceUpdateBlogPostBodySchema) threw at module-init time. Next.js lazy-loads route code per-request and never executed this top-level chain, hiding the issue. Trigger.dev's bundler eagerly evaluates all task-reachable modules at startup, which is why the trigger.dev deploy surfaced it as "confluenceCommentScopedSchema.extend is not a function" across every background task that transitively imports this file. Fix: introduce un-superRefined base schemas and use them as the .extend target downstream; apply superRefine after each .extend so validation behavior is preserved for every consumer. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 91c6777 commit 1595d6b

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

apps/sim/lib/api/contracts/selectors/confluence.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,24 @@ function addAlphanumericIdIssue(
100100
}
101101
}
102102

103-
export const confluenceCommentScopedSchema = confluenceBaseSchema
104-
.extend({
105-
commentId: z.string().min(1, 'Comment ID is required'),
106-
})
107-
.superRefine((data, ctx) => addAlphanumericIdIssue(data, 'commentId', 'comment ID', ctx))
103+
// Keep the un-superRefined base separate so downstream schemas can .extend it.
104+
// .superRefine returns a ZodEffects which has no .extend method, so extending
105+
// the refined schema directly throws at module-init time (caught by bundlers
106+
// like esbuild/Trigger.dev that eagerly evaluate; Next.js lazy-loads per-route
107+
// and hides the issue).
108+
const confluenceCommentScopedBaseSchema = confluenceBaseSchema.extend({
109+
commentId: z.string().min(1, 'Comment ID is required'),
110+
})
111+
export const confluenceCommentScopedSchema = confluenceCommentScopedBaseSchema.superRefine(
112+
(data, ctx) => addAlphanumericIdIssue(data, 'commentId', 'comment ID', ctx)
113+
)
108114

109-
export const confluenceBlogPostScopedSchema = confluenceBaseSchema
110-
.extend({
111-
blogPostId: z.string({ error: 'Blog post ID is required' }).min(1, 'Blog post ID is required'),
112-
})
113-
.superRefine((data, ctx) => addAlphanumericIdIssue(data, 'blogPostId', 'blog post ID', ctx))
115+
const confluenceBlogPostScopedBaseSchema = confluenceBaseSchema.extend({
116+
blogPostId: z.string({ error: 'Blog post ID is required' }).min(1, 'Blog post ID is required'),
117+
})
118+
export const confluenceBlogPostScopedSchema = confluenceBlogPostScopedBaseSchema.superRefine(
119+
(data, ctx) => addAlphanumericIdIssue(data, 'blogPostId', 'blog post ID', ctx)
120+
)
114121

115122
export const confluenceDeleteAttachmentBodySchema = confluenceBaseSchema.extend({
116123
attachmentId: z
@@ -133,9 +140,11 @@ export const confluenceListCommentsQuerySchema = confluencePageScopedSchema.exte
133140
cursor: z.string().optional(),
134141
})
135142

136-
export const confluenceUpdateCommentBodySchema = confluenceCommentScopedSchema.extend({
137-
comment: z.string().min(1, 'Comment is required'),
138-
})
143+
export const confluenceUpdateCommentBodySchema = confluenceCommentScopedBaseSchema
144+
.extend({
145+
comment: z.string().min(1, 'Comment is required'),
146+
})
147+
.superRefine((data, ctx) => addAlphanumericIdIssue(data, 'commentId', 'comment ID', ctx))
139148

140149
export const confluenceCreatePageBodySchema = confluenceSpaceScopedSchema.extend({
141150
title: z.string({ error: 'Title is required' }).min(1, 'Title is required'),
@@ -276,9 +285,11 @@ export const confluenceUserBodySchema = confluenceBaseSchema.extend({
276285
accountId: z.string({ error: 'Account ID is required' }).min(1, 'Account ID is required'),
277286
})
278287

279-
export const confluenceGetBlogPostBodySchema = confluenceBlogPostScopedSchema.extend({
280-
bodyFormat: z.string().optional(),
281-
})
288+
export const confluenceGetBlogPostBodySchema = confluenceBlogPostScopedBaseSchema
289+
.extend({
290+
bodyFormat: z.string().optional(),
291+
})
292+
.superRefine((data, ctx) => addAlphanumericIdIssue(data, 'blogPostId', 'blog post ID', ctx))
282293

283294
export const confluenceCreateBlogPostBodySchema = confluenceSpaceScopedSchema.extend({
284295
title: z.string({ error: 'Title is required' }).min(1, 'Title is required'),
@@ -298,10 +309,12 @@ export const confluenceListBlogPostsQuerySchema = confluenceBaseSchema.extend({
298309
cursor: z.string().optional(),
299310
})
300311

301-
export const confluenceUpdateBlogPostBodySchema = confluenceBlogPostScopedSchema.extend({
302-
title: z.string().optional(),
303-
content: z.string().optional(),
304-
})
312+
export const confluenceUpdateBlogPostBodySchema = confluenceBlogPostScopedBaseSchema
313+
.extend({
314+
title: z.string().optional(),
315+
content: z.string().optional(),
316+
})
317+
.superRefine((data, ctx) => addAlphanumericIdIssue(data, 'blogPostId', 'blog post ID', ctx))
305318

306319
const defineConfluencePostContract = <TBody extends z.ZodType>(path: string, body: TBody) =>
307320
defineRouteContract({

0 commit comments

Comments
 (0)