Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(framework): Specify zod-to-json-schema as a dependency #6741

Merged
merged 7 commits into from
Oct 23, 2024

Conversation

rifont
Copy link
Contributor

@rifont rifont commented Oct 22, 2024

What changed? Why was the change needed?

  • Use runtime import for zod-to-json-schema in @novu/framework
    • Without a runtime import, build tools would attempt to import zod-to-json-schema at build-time which results in build failure when the optional peer dependency is not installed. This forces @novu/framework consumers to always install zod-to-json-schema even if they don't use zod

Screenshots

Before - error shown at build time:

Module not found: Can't resolve 'zod-to-json-schema'
  12 | var Ce = require('ajv');
  13 | var Le = require('ajv-formats');
> 14 | var zodToJsonSchema = require('zod-to-json-schema');
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  15 |
  16 | function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
  17 |



https://nextjs.org/docs/messages/module-not-found


 GET /api/novu?action=health-check 500 in 90ms
 ⨯ ./node_modules/.pnpm/@novu+framework@2.3.0_@nestjs+common@10.4.5_class-transformer@0.5.1_class-validator@0.14.1_re_6qslqckf3f4j3hmeq5cl5pprvm/node_modules/@novu/framework/dist/index.js:13:23

After - error only shown at build-time

Tried to use a zod schema in @novu/framework without `zod-to-json-schema` installed. Please install it by running `npm install zod-to-json-schema`.
 ⨯ Error: Cannot find module 'zod-to-json-schema'
Require stack:
- /Users/rifont/git/framework-base/.next/server/app/api/novu/route.js
- /Users/rifont/git/framework-base/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0_react@19.0.0_react@19.0.0/node_modules/next/dist/server/require.js
- /Users/rifont/git/framework-base/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0_react@19.0.0_react@19.0.0/node_modules/next/dist/server/load-components.js
- /Users/rifont/git/framework-base/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0_react@19.0.0_react@19.0.0/node_modules/next/dist/build/utils.js
- /Users/rifont/git/framework-base/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0_react@19.0.0_react@19.0.0/node_modules/next/dist/build/swc/options.js
- /Users/rifont/git/framework-base/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0_react@19.0.0_react@19.0.0/node_modules/next/dist/build/swc/index.js
- /Users/rifont/git/framework-base/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0_react@19.0.0_react@19.0.0/node_modules/next/dist/build/next-config-ts/transpile-config.js
- /Users/rifont/git/framework-base/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0_react@19.0.0_react@19.0.0/node_modules/next/dist/server/config.js
- /Users/rifont/git/framework-base/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0_react@19.0.0_react@19.0.0/node_modules/next/dist/server/next.js
- /Users/rifont/git/framework-base/node_modules/.pnpm/next@15.0.0_react-dom@19.0.0_react@19.0.0_react@19.0.0/node_modules/next/dist/server/lib/start-server.js

Verifying that @novu/framework can be used without Zod now

import { serve } from "@novu/framework/next";
import { workflow } from '@novu/framework';

export const myNamedWorkflow = workflow('welcome-onboarding', async ({ step }) => {
    await step.email('send-email', async () => {
      return ({
        subject: 'Welcome to our platform!',
        body: 'Welcome to our platform!',
      })
    });
  }, {
    payloadSchema: {
        type: 'object',
        properties: {
            name: { type: 'string' },
        },
        required: ['name'],
        additionalProperties: false,
    } as const,
  });

export const { GET, POST, OPTIONS } = serve({
    workflows: [
        myNamedWorkflow
    ]
})
Discovered workflowId: 'welcome-onboarding'
└ σ Discovered stepId: 'send-email'     Type: 'email'
 GET /api/novu?action=discover 200 in 2233ms
 GET /api/novu?action=discover 200 in 2236ms
Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

netlify bot commented Oct 22, 2024

Deploy Preview for novu-stg-vite-dashboard-poc ready!

Name Link
🔨 Latest commit 04aa43d
🔍 Latest deploy log https://app.netlify.com/sites/novu-stg-vite-dashboard-poc/deploys/6718a45fcce33d0008f2ec46
😎 Deploy Preview https://deploy-preview-6741--novu-stg-vite-dashboard-poc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@merrcury merrcury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -53,6 +53,7 @@ export type DiscoverStepOutput = {
export type DiscoverWorkflowOutput = {
workflowId: string;
execute: Execute<Record<string, unknown>, Record<string, unknown>>;
/** @deprecated use top-level properties instead */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should've been added already. It will be cleaned up soon.

Copy link

pkg-pr-new bot commented Oct 22, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/novuhq/novu/@novu/framework@6741

commit: 04aa43d

@rifont rifont changed the title fix(framework): Use runtime import for zod-to-json-schema fix(framework): Specify zod-to-json-schema as a dependency Oct 22, 2024
@rifont rifont marked this pull request as draft October 22, 2024 14:53
@rifont rifont merged commit ca3dddc into next Oct 23, 2024
46 checks passed
@rifont rifont deleted the use-runtime-zod-to-json-schema-import branch October 23, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants