Skip to content

Commit

Permalink
feat(framework): add first five schemas for providers (novuhq#6039)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Fontein <[email protected]>
  • Loading branch information
davidsoderberg and rifont authored Jul 12, 2024
1 parent d5a7f29 commit 7a65b6f
Show file tree
Hide file tree
Showing 30 changed files with 3,197 additions and 364 deletions.
20 changes: 19 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,25 @@
"unarchived",
"Unarchived",
"grayscale",
"directcss"
"directcss",
"deliverytime",
"testmode",
"attatchment",
"Attatchment",
"ical",
"ganalytics",
"myicon",
"rrggbb",
"playerids",
"TVVV",
"Udnw",
"ARGB",
"EMUI",
"notif",
"suported",
"subresource",
"htmlonly",
"apidevtools"
],
"flagWords": [],
"patterns": [
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/conventional-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ on:
- opened
- edited
- synchronize
branches:
- '!prod'

# Use the following event if you want edit and test setting regarding conventional commits
# pull_request:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prepare-cloud-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Create Novu Cloud release PR
id: create-pr
run: |
echo "pr_url=$(gh pr create --base prod --head ${{steps.output-variables.outputs.branch_name}} --title 'Release ${{steps.output-variables.outputs.date_humanized}}' --body 'Automated daily production Novu Cloud release')" >> "$GITHUB_OUTPUT"
echo "pr_url=$(gh pr create --base prod --head ${{steps.output-variables.outputs.branch_name}} --title 'chore(root): Release ${{steps.output-variables.outputs.date_humanized}}' --body 'Automated daily production Novu Cloud release')" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
1 change: 1 addition & 0 deletions packages/framework/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
tsconfigRootDir: __dirname,
},
rules: {
'max-len': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'import/prefer-default-export': 0,
'no-else-return': 0,
Expand Down
26 changes: 15 additions & 11 deletions packages/framework/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ npm install @novu/framework
## Quickstart

```typescript
import { workflow, CronExpression, } from "@novu/framework";
import { serve } from "@novu/framework/next";
import { workflow, CronExpression } from '@novu/framework';
import { serve } from '@novu/framework/next';
import { z } from 'zod';

// Define your notification workflow
Expand All @@ -41,15 +41,19 @@ const weeklyComments = workflow(
cron: CronExpression.EVERY_WEEK,
}));

await step.email('weekly-comments', async (controls) => ({
subject: `${controls.prefix} - Weekly post comments (${weeklyDigest.events.length})`,
body: `Weekly digest: ${weeklyDigest.events.map(({ payload }) => payload.comment).join(', ')}`,
}), {
// Skip the notification if the user has already seen it
skip: () => inAppResponse.seen,
// Non-technical stakeholders can modify strongly-validated copy in Novu Cloud
inputSchema: z.object({ prefix: z.string().describe('The prefix of the subject.').default('Hi!') }),
});
await step.email(
'weekly-comments',
async (controls) => ({
subject: `${controls.prefix} - Weekly post comments (${weeklyDigest.events.length})`,
body: `Weekly digest: ${weeklyDigest.events.map(({ payload }) => payload.comment).join(', ')}`,
}),
{
// Skip the notification if the user has already seen it
skip: () => inAppResponse.seen,
// Non-technical stakeholders can modify strongly-validated copy in Novu Cloud
inputSchema: z.object({ prefix: z.string().describe('The prefix of the subject.').default('Hi!') }),
}
);
},
{ payloadSchema: z.object({ comment: z.string().describe('The comment on the post.') }) }
);
Expand Down
7 changes: 5 additions & 2 deletions packages/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"build:watch": "tsup --watch",
"$comment:bump:prerelease": "This is a workaround to support `npm version prerelease` with lerna",
"bump:prerelease": "npm version prerelease --preid=alpha & PID=$!; (sleep 1 && kill -9 $PID) & wait $PID",
"release:alpha": "pnpm bump:prerelease || pnpm build && npm publish"
"release:alpha": "pnpm bump:prerelease || pnpm build && npm publish",
"devtool": "tsx ./scripts/devtool.ts"
},
"keywords": [
"novu",
Expand Down Expand Up @@ -136,7 +137,9 @@
"typescript": "^5.3.3",
"vitest": "^1.2.1",
"zod": "^3.23.0",
"zod-to-json-schema": "^3.23.0"
"zod-to-json-schema": "^3.23.0",
"@apidevtools/json-schema-ref-parser": "11.6.4",
"tsx": "4.16.2"
},
"dependencies": {
"@novu/shared": "workspace:*",
Expand Down
4 changes: 4 additions & 0 deletions packages/framework/scripts/INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Devtool

`devtool.ts`, `schema_output.json` and `schema_input.json` is meant to be used to extract json schema object from openapi json.
Put you openapi json in `schema_input.json` and change line 9 in `devtool.ts` to the path where the schema object you need are located. run `npm run devtool` and open `schema_output.json` and copy the result from there.
15 changes: 15 additions & 0 deletions packages/framework/scripts/devtool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { writeFileSync } from 'fs';

import $RefParser from '@apidevtools/json-schema-ref-parser';

const main = async () => {
const parser = new $RefParser();
const schema = await parser.dereference(__dirname + '/schema_input.json');
// Edit this path to target the JSON schema that the send message endpoint uses
const body = schema['components']['schemas']['api.v2010.account.message'];
writeFileSync(__dirname + '/schema_output.json', JSON.stringify(body, null, 2));

console.log('schema.json updated');
};

main();
Empty file.
Empty file.
13 changes: 11 additions & 2 deletions packages/framework/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,11 @@ describe('Novu Client', () => {
} as const,
providers: {
sendgrid: async ({ controls, outputs }) => ({
ipPoolName: `${controls.foo} ${outputs.subject}`,
ip_pool_name: `${controls.foo} ${outputs.subject}`,
from: {
email: '[email protected]',
name: 'Test',
},
}),
},
});
Expand All @@ -571,7 +575,12 @@ describe('Novu Client', () => {

const executionResult = await client.executeWorkflow(event);

expect(executionResult.providers).toEqual({ sendgrid: { ipPoolName: 'foo Subject' } });
expect(executionResult.providers).toEqual({
sendgrid: {
ip_pool_name: 'foo Subject',
from: { email: '[email protected]', name: 'Test' },
},
});
});

it('should preview with mocked payload during preview', async () => {
Expand Down
Loading

0 comments on commit 7a65b6f

Please sign in to comment.