Skip to content

Commit

Permalink
fix(framework): Resolve CJS issues this time with json-schema-faker (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SokratisVidros authored Oct 29, 2024
1 parent c8c51d0 commit d6d4250
Show file tree
Hide file tree
Showing 26 changed files with 6,683 additions and 670 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@
"apps/web/src/studio/components/workflows/step-editor/editor/files.ts",
"apps/web/src/pages/playground/web-container-configuration/sandbox-vite/*.ts",
"apps/api/src/app/analytics/usecases/hubspot-identify-form/hubspot-identify-form.usecase.ts",
"apps/dashboard/eslint.config.js"
"apps/dashboard/eslint.config.js",
"packages/framework/src/jsonSchemaFaker.js"
]
}
4 changes: 1 addition & 3 deletions packages/framework/express/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"main": "../dist/cjs/servers/express.cjs",
"module": "../dist/esm/servers/express.js",
"types": "../dist/esm/servers/express.d.ts"
"main": "../dist/cjs/servers/express.cjs"
}
4 changes: 1 addition & 3 deletions packages/framework/h3/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"main": "../dist/cjs/servers/h3.cjs",
"module": "../dist/esm/servers/h3.js",
"types": "../dist/esm/servers/h3.d.ts"
"main": "../dist/cjs/servers/h3.cjs"
}
4 changes: 1 addition & 3 deletions packages/framework/internal/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"main": "../dist/cjs/internal/index.cjs",
"module": "../dist/esm/internal/index.js",
"types": "../dist/esm/internal/index.d.ts"
"main": "../dist/cjs/internal/index.cjs"
}
4 changes: 1 addition & 3 deletions packages/framework/lambda/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"main": "../dist/cjs/servers/lambda.cjs",
"module": "../dist/esm/servers/lambda.js",
"types": "../dist/esm/servers/lambda.d.ts"
"main": "../dist/cjs/servers/lambda.cjs"
}
4 changes: 1 addition & 3 deletions packages/framework/nest/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"main": "../dist/cjs/servers/nest.cjs",
"module": "../dist/esm/servers/nest.js",
"types": "../dist/esm/servers/nest.d.ts"
"main": "../dist/cjs/servers/nest.cjs"
}
4 changes: 1 addition & 3 deletions packages/framework/next/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"main": "../dist/cjs/servers/next.cjs",
"module": "../dist/esm/servers/next.js",
"types": "../dist/esm/servers/next.d.ts"
"main": "../dist/cjs/servers/next.cjs"
}
4 changes: 1 addition & 3 deletions packages/framework/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"main": "../dist/cjs/servers/nuxt.cjs",
"module": "../dist/esm/servers/nuxt.js",
"types": "../dist/esm/servers/nuxt.d.ts"
"main": "../dist/cjs/servers/nuxt.cjs"
}
3 changes: 0 additions & 3 deletions packages/framework/package.cjs.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/framework/package.esm.json

This file was deleted.

3 changes: 1 addition & 2 deletions packages/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"format:fix": "prettier --write --ignore-path .gitignore .",
"build": "NODE_ENV=production tsup",
"build:watch": "tsup --watch",
"postbuild": "./scripts/copy-package-json.sh && pnpm run check:exports && pnpm check:circulars",
"postbuild": "pnpm run check:exports && pnpm check:circulars",
"check:exports": "attw --pack .",
"check:circulars": "madge --circular --extensions ts --exclude ../../shared ./src",
"$comment:bump:prerelease": "This is a workaround to support `npm version prerelease` with lerna",
Expand Down Expand Up @@ -239,7 +239,6 @@
"better-ajv-errors": "^1.2.0",
"chalk": "^4.1.2",
"cross-fetch": "^4.0.0",
"json-schema-faker": "^0.5.6",
"json-schema-to-ts": "^3.0.0",
"liquidjs": "^10.13.1",
"ora": "^5.4.1",
Expand Down
4 changes: 1 addition & 3 deletions packages/framework/remix/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"main": "../dist/cjs/servers/remix.cjs",
"module": "../dist/esm/servers/remix.js",
"types": "../dist/esm/servers/remix.d.ts"
"main": "../dist/cjs/servers/remix.cjs"
}
4 changes: 0 additions & 4 deletions packages/framework/scripts/copy-package-json.sh

This file was deleted.

2 changes: 1 addition & 1 deletion packages/framework/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from './errors';
import { workflow } from './resources';
import { Event, Step } from './types';
import { FRAMEWORK_VERSION, SDK_VERSION, PostActionEnum } from './constants';
import { PostActionEnum } from './constants';

describe('Novu Client', () => {
let client: Client;
Expand Down
27 changes: 5 additions & 22 deletions packages/framework/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Liquid } from 'liquidjs';
import ora from 'ora';

import { ChannelStepEnum, FRAMEWORK_VERSION, PostActionEnum, SDK_VERSION } from './constants';
import { ChannelStepEnum, PostActionEnum } from './constants';
import {
ExecutionEventControlsInvalidError,
ExecutionEventPayloadInvalidError,
Expand Down Expand Up @@ -37,25 +37,9 @@ import type {
} from './types';
import { WithPassthrough } from './types/provider.types';
import { EMOJI, log, sanitizeHtmlInObject, stringifyDataStructureWithSingleQuotes } from './utils';
import { transformSchema, validateData } from './validators';

/*
* JSONSchemaFaker needs to be imported as CJS to avoid HMR and Webpack issues when importing @novu/framework
* in Next.js. See https://github.com/json-schema-faker/json-schema-faker/issues/796#issuecomment-2433335751
*/
const { JSONSchemaFaker } = require('json-schema-faker');

/**
* We want to respond with a consistent string value for preview
*/
JSONSchemaFaker.random.shuffle = function shuffle() {
return ['[placeholder]'];
};

JSONSchemaFaker.option({
useDefaultValue: true,
alwaysFakeOptionals: true,
});
import { validateData } from './validators';

import { mockSchema } from './jsonSchemaFaker';

function isRuntimeInDevelopment() {
return ['development', undefined].includes(process.env.NODE_ENV);
Expand Down Expand Up @@ -169,8 +153,7 @@ export class Client {
* @returns mocked data
*/
private mock(schema: Schema): Record<string, unknown> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return JSONSchemaFaker.generate(transformSchema(schema) as any) as Record<string, unknown>;
return mockSchema(schema) as Record<string, unknown>;
}

private async validate<T extends Record<string, unknown>>(
Expand Down
1 change: 0 additions & 1 deletion packages/framework/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ export * from './http-query.constants';
export * from './http-status.constants';
export * from './resource.constants';
export * from './step.constants';
export * from './version.constants';
export * from './workflow.constants';
2 changes: 0 additions & 2 deletions packages/framework/src/constants/version.constants.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/framework/src/constants/version.test.ts

This file was deleted.

6 changes: 6 additions & 0 deletions packages/framework/src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export {};

declare global {
const SDK_VERSION: string;
const FRAMEWORK_VERSION: string;
}
2 changes: 0 additions & 2 deletions packages/framework/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import { createHmac } from 'node:crypto';

import { Client } from './client';
import {
FRAMEWORK_VERSION,
GetActionEnum,
HttpHeaderKeysEnum,
HttpMethodEnum,
HttpQueryKeysEnum,
HttpStatusEnum,
PostActionEnum,
SDK_VERSION,
SIGNATURE_TIMESTAMP_TOLERANCE,
} from './constants';
import {
Expand Down
Loading

0 comments on commit d6d4250

Please sign in to comment.