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(echo): Use dist for Echo artifacts #5590

Merged
merged 15 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@nestjs/throttler": "^5.0.1",
"@novu/application-generic": "^0.24.2",
"@novu/dal": "^0.24.2",
"@novu/echo": "^0.0.1-alpha.25",
"@novu/echo": "^0.24.3-alpha.0",
"@novu/node": "^0.24.2",
"@novu/shared": "^0.24.2",
"@novu/stateless": "^0.24.2",
Expand Down
83 changes: 56 additions & 27 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,63 @@
# Quickstart
<div align="center">
<a href="https://novu.co?utm_source=github" target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/2233092/213641039-220ac15f-f367-4d13-9eaf-56e79433b8c1.png">
<img alt="Novu Logo" src="https://user-images.githubusercontent.com/2233092/213641043-3bbb3f21-3c53-4e67-afe5-755aeb222159.png" width="280"/>
</picture>
</a>
</div>

# Code-First Notifications Workflow SDK

[![Version](https://img.shields.io/npm/v/@novu/echo.svg)](https://www.npmjs.org/package/@novu/echo)
[![Downloads](https://img.shields.io/npm/dm/@novu/echo.svg)](https://www.npmjs.com/package/@novu/echo)

Novu Echo SDK allows you to write notification workflows in your codebase. Workflows are functions that execute business logic and use your preferred libraries for email, SMS, and chat generation. You can use Echo with [React.Email](https://react.email/), [MJML](https://mjml.io/), or any other template generator.

Learn more about the Code-First Notifications Workflow SDK in our [docs](https://docs.novu.co/echo/quickstart).

## Installation

```bash
npm install @novu/echo
```

## Quickstart

```typescript
const client = new Echo();
client.workflow('comment-on-post', { type: 'object', properties: { post: { type: 'string' } } }, async ({ step }) => {
const userResponse = step.custom(
'fetch-user',
{ type: 'object', properties: { name: { type: 'string' } } },
async () => ({ email: '[email protected]' })
);

step.email('send-email', async (payload) => {
return {
subject: 'You received a post',
body: `<html><body>${payload.post}</body></html>`,
to: userResponse.email,
};
});
import { Echo } from '@novu/echo';

const echo = new Echo();

const commentWorkflow = echo.workflow('comment-on-post', async ({ payload, step }) => {
const inAppResponse = await step.inApp('notify-user', async () => ({
body: renderBody(payload.postId)
}));

step.email('send-follow-up', async (payload) => {
const weeklyDigest = await step.digest('wait-1-week', () => ({
amount: 7,
unit: 'days',
}));

await step.email('weekly-comments', async (inputs) => {
return {
subject: 'You received a follow-up',
body: `<html><body>${payload.post}</body></html>`,
to: userResponse.email,
subject: `Weekly post comments (${weeklyDigest.events.length + 1})`,
body: renderReactEmail(inputs, weeklyDigest.events)
};
});
}, { skip: () => inAppResponse.seen });
}, {
payloadSchema: {
type: "object",
properties: {
postId: {
title: "Post ID",
type: "string",
description: "The ID of the post.",
default: "123"
}
},
required: ["postId"],
additionalProperties: false,
} as const
});

// Get the workflows
const workflows = client.getRegisteredWorkflows();

// Invoke a step
const result = client.invokeStep('comment-on-post', 'fetch-user', { post: 'Hello' }).then(console.log);
```
77 changes: 49 additions & 28 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,72 @@
{
"name": "@novu/echo",
"version": "0.24.2",
"description": "The Echo SDK, used to programmatically declare and manage your notifications.",
"main": "./index.js",
"types": "./index.d.ts",
"version": "0.24.3-alpha.0",
"description": "The Code-First Notifications Workflow SDK.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"publishConfig": {
"registry": "https://registry.npmjs.org"
"registry": "https://registry.npmjs.org",
"access": "public"
},
"private": false,
"repository": "https://github.com/novuhq/novu",
"scripts": {
"preinstall": "npx only-allow pnpm",
"test": "jest",
"lint": "eslint src --ext .ts",
"lint:fix": "eslint src --ext .ts --fix",
"format": "prettier --check --ignore-path .gitignore .",
"format:fix": "prettier --write --ignore-path .gitignore .",
"start": "ts-node src/index.ts",
"clean": "rm -rf ./dist",
"build": "pnpm run clean && tsc --build && pnpm run build:copy",
"build": "pnpm run clean && tsc --build",
"build:watch": "tsc --build --watch",
"build:copy": "cp package.json README.md dist",
"release:alpha": "pnpm i && npm version prerelease --preid=alpha && pnpm build && cd dist && npm publish"
"$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"
},
"keywords": [],
"keywords": [
"novu",
"code-first",
"workflows",
"durable",
"sdk",
"notifications",
"email",
"sms",
"push",
"webhooks",
"next",
"nuxt",
"h3",
"express"
],
"author": "Athena",
"license": "ISC",
"license": "MIT",
"exports": {
".": {
"require": "./index.js",
"import": "./index.js",
"types": "./index.d.ts"
"require": "./dist/index.js",
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./express": {
"require": "./express.js",
"import": "./express.js",
"types": "./express.d.ts"
"require": "./dist/express.js",
"import": "./dist/express.js",
"types": "./dist/express.d.ts"
},
"./next": {
"require": "./next.js",
"import": "./next.js",
"types": "./next.d.ts"
"require": "./dist/next.js",
"import": "./dist/next.js",
"types": "./dist/next.d.ts"
},
"./nuxt": {
"require": "./nuxt.js",
"import": "./nuxt.js",
"types": "./nuxt.d.ts"
"require": "./dist/nuxt.js",
"import": "./dist/nuxt.js",
"types": "./dist/nuxt.d.ts"
},
"./h3": {
"require": "./h3.js",
"import": "./h3.js",
"types": "./h3.d.ts"
"require": "./dist/h3.js",
"import": "./dist/h3.js",
"types": "./dist/h3.d.ts"
}
},
"devDependencies": {
Expand All @@ -60,6 +77,7 @@
"@types/node": "^20.11.20",
"@vercel/node": "^2.15.9",
"express": "^4.18.2",
"h3": "^1.11.1",
"jest": "^29.7.0",
"next": "^13.5.4",
"prettier": "^3.2.5",
Expand All @@ -73,9 +91,12 @@
"better-ajv-errors": "^1.2.0",
"chalk": "^4.1.2",
"cross-fetch": "^4.0.0",
"h3": "^1.11.1",
"json-schema-faker": "^0.5.6",
"json-schema-to-ts": "^3.0.0",
"ora": "^5.4.1"
}
},
"files": [
"dist",
"README.md"
]
}
Loading
Loading