Skip to content

Commit

Permalink
Merge branch 'next' into com-27-js-sdk-package-config
Browse files Browse the repository at this point in the history
  • Loading branch information
LetItRock committed Jun 3, 2024
2 parents 042aadf + d780d4e commit ecaf5eb
Show file tree
Hide file tree
Showing 14 changed files with 1,382 additions and 799 deletions.
2 changes: 1 addition & 1 deletion apps/api/e2e/echo.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as http from 'http';
import * as express from 'express';
// FIXME: subpath import not working with `workspace:` protocol. Currently we need to drill into the module instead of using the ES export.
import { serve } from '../../../packages/echo/dist/src/express';
import { serve } from '../../../packages/echo/dist/express';
import { Echo } from '@novu/echo';

class EchoServer {
Expand Down
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"uuid": "^8.3.2"
},
"devDependencies": {
"@faker-js/faker": "^6.0.0",
"@nestjs/cli": "^10.1.16",
"@nestjs/schematics": "^10.0.2",
"@nestjs/testing": "^10.2.2",
Expand Down
46 changes: 27 additions & 19 deletions apps/web/src/pages/auth/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface LocationState {

export function LoginForm({ email, invitationToken }: LoginFormProps) {
const segment = useSegment();
const { login, currentUser } = useAuth();
const { login, currentUser, organizationId, environmentId } = useAuth();
const { startVercelSetup } = useVercelIntegration();
const { isFromVercel, params: vercelParams } = useVercelParams();
const [params] = useSearchParams();
Expand All @@ -48,31 +48,39 @@ export function LoginForm({ email, invitationToken }: LoginFormProps) {
>((data) => api.post('/v1/auth/login', data));

useEffect(() => {
async () => {
if (tokenInQuery) {
await login(tokenInQuery);
(async () => {
if (!tokenInQuery) {
return;
}

if (isFromVercel) {
startVercelSetup();
if (!invitationToken && (!organizationId || !environmentId)) {
await login(tokenInQuery, ROUTES.AUTH_APPLICATION);

return;
}
return;
}

if (source === 'cli') {
segment.track('Dashboard Visit', {
widget: sourceWidget || 'unknown',
source: 'cli',
});
navigate(ROUTES.GET_STARTED);
if (isFromVercel) {
await login(tokenInQuery);
startVercelSetup();

return;
}
return;
}

if (source === 'cli') {
segment.track('Dashboard Visit', {
widget: sourceWidget || 'unknown',
source: 'cli',
});
await login(tokenInQuery, ROUTES.GET_STARTED);

navigate(ROUTES.WORKFLOWS);
return;
}
};

await login(tokenInQuery);
navigate(ROUTES.WORKFLOWS);
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [login, navigate, currentUser, tokenInQuery, segment]);
}, [login, navigate, currentUser, tokenInQuery, segment, organizationId, environmentId]);

const signupLink = isFromVercel ? `${ROUTES.AUTH_SIGNUP}?${params.toString()}` : ROUTES.AUTH_SIGNUP;
const resetPasswordLink = isFromVercel
Expand Down
2 changes: 1 addition & 1 deletion packages/echo/.eslintrc.js → packages/echo/.eslintrc.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
extends: ['../../.eslintrc.js'],
parserOptions: {
project: './tsconfig.json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* https://jestjs.io/docs/configuration
*/

module.exports = {
export default {
/*
* All imported modules in your tests should be mocked automatically
* automock: false,
Expand Down
47 changes: 26 additions & 21 deletions packages/echo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@novu/echo",
"version": "0.24.3-alpha.0",
"description": "The Code-First Notifications Workflow SDK.",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
Expand All @@ -17,10 +17,8 @@
"lint:fix": "eslint src --ext .ts --fix",
"format": "prettier --check --ignore-path .gitignore .",
"format:fix": "prettier --write --ignore-path .gitignore .",
"clean": "rm -rf ./dist",
"prebuild": "rimraf dist",
"build": "pnpm run clean && tsc --build",
"build:watch": "tsc --build --watch",
"build": "tsup",
"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"
Expand All @@ -45,33 +43,39 @@
"license": "MIT",
"exports": {
".": {
"require": "./dist/src/index.js",
"import": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./express": {
"require": "./dist/src/express.js",
"import": "./dist/src/express.js",
"types": "./dist/src/express.d.ts"
"require": "./dist/express.js",
"import": "./dist/express.mjs",
"types": "./dist/express.d.ts"
},
"./next": {
"require": "./dist/src/next.js",
"import": "./dist/src/next.js",
"types": "./dist/src/next.d.ts"
"require": "./dist/next.js",
"import": "./dist/next.mjs",
"types": "./dist/next.d.ts"
},
"./nuxt": {
"require": "./dist/src/nuxt.js",
"import": "./dist/src/nuxt.js",
"types": "./dist/src/nuxt.d.ts"
"require": "./dist/nuxt.js",
"import": "./dist/nuxt.mjs",
"types": "./dist/nuxt.d.ts"
},
"./h3": {
"require": "./dist/src/h3.js",
"import": "./dist/src/h3.js",
"types": "./dist/src/h3.d.ts"
"require": "./dist/h3.js",
"import": "./dist/h3.mjs",
"types": "./dist/h3.d.ts"
},
"./sveltekit": {
"require": "./dist/sveltekit.js",
"import": "./dist/sveltekit.mjs",
"types": "./dist/sveltekit.d.ts"
}
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@sveltejs/kit": "^2.5.10",
"@types/express": "^4.17.13",
"@types/jest": "^29.5.12",
"@types/json-schema": "^7.0.15",
Expand All @@ -84,6 +88,7 @@
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsup": "^8.0.2",
"typescript": "^5.3.3"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/echo/src/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Either } from './types';
import { type SupportedFrameworkName } from './types';
import { getResponse } from './utils';

export const frameworkName: SupportedFrameworkName = 'nextjs';
export const frameworkName: SupportedFrameworkName = 'next';

/**
* In Next.js, serve and register any declared workflows with Echo, making
Expand Down
62 changes: 62 additions & 0 deletions packages/echo/src/sveltekit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { RequestEvent } from '@sveltejs/kit';
import { EchoRequestHandler, ServeHandlerOptions } from './handler';
import { type SupportedFrameworkName } from './types';

export const frameworkName: SupportedFrameworkName = 'sveltekit';

export const serve = (
options: ServeHandlerOptions
): ((event: RequestEvent) => Promise<Response>) & {
GET: (event: RequestEvent) => Promise<Response>;
POST: (event: RequestEvent) => Promise<Response>;
PUT: (event: RequestEvent) => Promise<Response>;
} => {
const handler = new EchoRequestHandler({
frameworkName,
...options,
handler: (reqMethod: 'GET' | 'POST' | 'PUT' | undefined, event: RequestEvent) => {
return {
method: () => reqMethod || event.request.method || '',
body: () => event.request.json(),
headers: (key) => event.request.headers.get(key),
url: () => {
const protocol = process.env.NODE_ENV === 'development' ? 'http' : 'https';

return new URL(event.request.url, `${protocol}://${event.request.headers.get('host') || ''}`);
},
transformResponse: ({ body, headers, status }) => {
// Handle Response polyfills
// eslint-disable-next-line @typescript-eslint/naming-convention
let Res: typeof Response;

if (typeof Response === 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-var-requires
Res = require('cross-fetch').Response;
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Res = Response;
}

return new Res(body, { status, headers });
},
};
},
});

const baseFn = handler.createHandler();

const fn = baseFn.bind(null, undefined);
type Fn = typeof fn;

const handlerFn = Object.defineProperties(fn, {
GET: { value: baseFn.bind(null, 'GET') },
POST: { value: baseFn.bind(null, 'POST') },
PUT: { value: baseFn.bind(null, 'PUT') },
}) as Fn & {
GET: Fn;
POST: Fn;
PUT: Fn;
};

return handlerFn;
};
2 changes: 1 addition & 1 deletion packages/echo/src/types/framework.types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type SupportedFrameworkName = 'nextjs' | 'express' | 'nuxt' | 'h3';
export type SupportedFrameworkName = 'next' | 'express' | 'nuxt' | 'h3' | 'sveltekit';
4 changes: 2 additions & 2 deletions packages/echo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "ES2019",
"module": "CommonJS",
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"skipLibCheck": true,
"resolveJsonModule": true,
Expand Down
12 changes: 0 additions & 12 deletions packages/echo/tsconfig.module.json

This file was deleted.

17 changes: 17 additions & 0 deletions packages/echo/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from 'tsup';
import { type SupportedFrameworkName } from './src';

const frameworks: SupportedFrameworkName[] = ['h3', 'express', 'next', 'nuxt', 'sveltekit'];

export default defineConfig({
entry: ['src/index.ts', ...frameworks.map((framework) => `src/${framework}.ts`)],
sourcemap: false,
clean: true,
treeshake: true,
dts: true,
format: ['cjs', 'esm'],
minify: true,
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true,
});
Loading

0 comments on commit ecaf5eb

Please sign in to comment.