@websolutespa/bom-mixer-emails 3.1.2 → 4.0.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +21 -22
- package/src/__tests/example.test.ts +8 -8
- package/src/__tests/render.test.tsx +29 -31
- package/src/app.tsx +15 -15
- package/src/index.ts +3 -4
- package/src/render.tsx +18 -18
- package/src/types.ts +30 -30
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,12 +4,12 @@ import { isDevelopment } from "@websolutespa/bom-core";
|
|
|
4
4
|
//#region src/app.tsx
|
|
5
5
|
const App = ({ Component, Layout, ...props }) => {
|
|
6
6
|
const LayoutComponent = Component.Layout || Layout;
|
|
7
|
-
return <LayoutProvider layout={props.layout}>
|
|
8
|
-
<LabelProvider>
|
|
9
|
-
<LayoutComponent {...props}>
|
|
10
|
-
<Component {...props}></Component>
|
|
11
|
-
</LayoutComponent>
|
|
12
|
-
</LabelProvider>
|
|
7
|
+
return <LayoutProvider layout={props.layout}>
|
|
8
|
+
<LabelProvider>
|
|
9
|
+
<LayoutComponent {...props}>
|
|
10
|
+
<Component {...props}></Component>
|
|
11
|
+
</LayoutComponent>
|
|
12
|
+
</LabelProvider>
|
|
13
13
|
</LayoutProvider>;
|
|
14
14
|
};
|
|
15
15
|
//#endregion
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/app.tsx","../src/render.tsx"],"sourcesContent":["import { LabelProvider, LayoutProvider } from '@websolutespa/bom-mixer-hooks';\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/app.tsx","../src/render.tsx"],"sourcesContent":["import { LabelProvider, LayoutProvider } from '@websolutespa/bom-mixer-hooks';\nimport { IEmailAppComponent } from './types';\n\nexport const App: IEmailAppComponent = ({ Component, Layout, ...props }) => {\n const LayoutComponent = Component.Layout || Layout;\n return (\n <LayoutProvider layout={props.layout}>\n <LabelProvider>\n <LayoutComponent {...props}>\n <Component {...props}></Component>\n </LayoutComponent>\n </LabelProvider>\n </LayoutProvider>\n );\n};\n","import { render } from '@react-email/render';\nimport { isDevelopment } from '@websolutespa/bom-core';\nimport { App } from './app';\nimport { IEmailAppProps } from './types';\n\nexport async function renderEmail<T>(props: IEmailAppProps<T>): Promise<string> {\n // console.log('renderEmail.props', props);\n const renderOptions = { pretty: isDevelopment };\n // console.log('renderEmail.renderOptions', renderOptions);\n try {\n const html = await render(<App {...props} />, renderOptions);\n // console.log('renderEmail', 'html', html);\n return html;\n } catch (error) {\n console.log(error);\n return 'An error occurred';\n }\n}\n"],"mappings":";;;;AAGA,MAAa,OAA2B,EAAE,WAAW,QAAQ,GAAG,YAAY;CAC1E,MAAM,kBAAkB,UAAU,UAAU;AAC5C,QACE,CAAC,eAAe,QAAQ,MAAM,QAAQ;MACpC,CAAC,cAAc;QACb,CAAC,oBAAoB,OAAO;UAC1B,CAAC,cAAc,OAAO,EAAE,UAAU;QACpC,EAAE,gBAAgB;MACpB,EAAE,cAAc;IAClB,EAAE;;;;ACPN,eAAsB,YAAe,OAA2C;CAE9E,MAAM,gBAAgB,EAAE,QAAQ,eAAe;AAE/C,KAAI;AAGF,SAFa,MAAM,OAAO,CAAC,QAAQ,WAAW,cAAc;UAGrD,OAAO;AACd,UAAQ,IAAI,MAAM;AAClB,SAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@websolutespa/bom-mixer-emails",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-next.6",
|
|
4
4
|
"description": "Mixer Emails module of the BOM Repository",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bom",
|
|
@@ -12,41 +12,31 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git://github.com/websolutespa/bom.git"
|
|
14
14
|
},
|
|
15
|
-
"scripts": {
|
|
16
|
-
"lint": "eslint .",
|
|
17
|
-
"test": "vitest run",
|
|
18
|
-
"test-watch": "vitest",
|
|
19
|
-
"coverage:integration": "npm run test -- --coverage.enabled --coverage.provider=istanbul --coverage.all",
|
|
20
|
-
"coverage": "run-s -c --silent coverage:*",
|
|
21
|
-
"compile": "tsdown",
|
|
22
|
-
"prepack": "bom prepack",
|
|
23
|
-
"postpack": "bom postpack",
|
|
24
|
-
"types": "tsc --noemit"
|
|
25
|
-
},
|
|
26
|
-
"dependencies": {},
|
|
27
15
|
"peerDependencies": {
|
|
28
16
|
"@react-email/components": "^1.0.12",
|
|
29
17
|
"@react-email/render": "^2.1.1",
|
|
30
|
-
"@websolutespa/bom-core": "^
|
|
31
|
-
"@websolutespa/bom-mixer-hooks": "^
|
|
18
|
+
"@websolutespa/bom-core": "^4.0.0-next.1",
|
|
19
|
+
"@websolutespa/bom-mixer-hooks": "^4.0.0-next.0",
|
|
32
20
|
"react": "^19.2.1",
|
|
33
21
|
"react-dom": "^19.2.1"
|
|
34
22
|
},
|
|
35
23
|
"devDependencies": {
|
|
36
24
|
"@react-email/components": "1.0.12",
|
|
37
25
|
"@react-email/render": "2.1.1",
|
|
26
|
+
"@types/node": "24.19.2",
|
|
38
27
|
"@types/react": "19.2.18",
|
|
39
28
|
"@types/react-dom": "19.2.7",
|
|
40
29
|
"@vitest/coverage-istanbul": "5.0.5",
|
|
41
|
-
"@websolutespa/bom-cli": "^
|
|
42
|
-
"@websolutespa/eslint-config": "^
|
|
43
|
-
"@websolutespa/test": "^
|
|
44
|
-
"@websolutespa/tsconfig": "^
|
|
45
|
-
"eslint": "10.13.0",
|
|
30
|
+
"@websolutespa/bom-cli": "^4.0.0-next.6",
|
|
31
|
+
"@websolutespa/eslint-config": "^4.0.0-next.6",
|
|
32
|
+
"@websolutespa/test": "^4.0.0-next.6",
|
|
33
|
+
"@websolutespa/tsconfig": "^4.0.0-next.6",
|
|
46
34
|
"npm-run-all": "4.1.5",
|
|
35
|
+
"oxlint": "1.89.0",
|
|
36
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
47
37
|
"react": "19.2.9",
|
|
48
38
|
"react-dom": "19.2.9",
|
|
49
|
-
"react-error-boundary": "6.1.6",
|
|
39
|
+
"react-error-boundary": "^6.1.6",
|
|
50
40
|
"tsdown": "0.21.0",
|
|
51
41
|
"typescript": "6.0.3",
|
|
52
42
|
"vitest": "5.0.5"
|
|
@@ -88,5 +78,14 @@
|
|
|
88
78
|
"default": "./dist/index.js"
|
|
89
79
|
}
|
|
90
80
|
},
|
|
91
|
-
"source": "./src/index.ts"
|
|
81
|
+
"source": "./src/index.ts",
|
|
82
|
+
"scripts": {
|
|
83
|
+
"lint": "oxlint --type-aware",
|
|
84
|
+
"test": "vitest run",
|
|
85
|
+
"test-watch": "vitest",
|
|
86
|
+
"coverage:integration": "vitest run --coverage.enabled --coverage.provider=istanbul --coverage.all",
|
|
87
|
+
"coverage": "run-s -c --silent coverage:*",
|
|
88
|
+
"compile": "tsdown",
|
|
89
|
+
"types": "tsc --noemit"
|
|
90
|
+
}
|
|
92
91
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
describe('Example', () => {
|
|
4
|
-
it('passes', async () => {
|
|
5
|
-
const value = 'test';
|
|
6
|
-
expect(value).toEqual(value);
|
|
7
|
-
});
|
|
8
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
describe('Example', () => {
|
|
4
|
+
it('passes', async () => {
|
|
5
|
+
const value = 'test';
|
|
6
|
+
expect(value).toEqual(value);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import { Body, Html, Text } from '@react-email/components';
|
|
2
|
-
import type { ILayout } from '@websolutespa/bom-core';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
import { renderEmail } from '../render';
|
|
5
|
-
import type { IEmailComponent, IEmailLayoutComponent } from '../types';
|
|
6
|
-
|
|
7
|
-
const Layout: IEmailLayoutComponent = ({ children }) => (
|
|
8
|
-
<Html lang="en">
|
|
9
|
-
<Body>{children}</Body>
|
|
10
|
-
</Html>
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
const Component: IEmailComponent<{ name: string }> = ({ props }) =>
|
|
14
|
-
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
expect(html.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
});
|
|
1
|
+
import { Body, Html, Text } from '@react-email/components';
|
|
2
|
+
import type { ILayout } from '@websolutespa/bom-core';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { renderEmail } from '../render';
|
|
5
|
+
import type { IEmailComponent, IEmailLayoutComponent } from '../types';
|
|
6
|
+
|
|
7
|
+
const Layout: IEmailLayoutComponent = ({ children }) => (
|
|
8
|
+
<Html lang="en">
|
|
9
|
+
<Body>{children}</Body>
|
|
10
|
+
</Html>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const Component: IEmailComponent<{ name: string }> = ({ props }) => <Text>Hello {props.name}</Text>;
|
|
14
|
+
|
|
15
|
+
describe('renderEmail', () => {
|
|
16
|
+
it('renders the component inside the layout as an html document', async () => {
|
|
17
|
+
const html = await renderEmail({
|
|
18
|
+
Component,
|
|
19
|
+
Layout,
|
|
20
|
+
layout: { labels: [] } as unknown as ILayout,
|
|
21
|
+
origin: 'https://example.com',
|
|
22
|
+
props: { name: 'Ada' },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(html.startsWith('<!DOCTYPE html')).toBe(true);
|
|
26
|
+
expect(html).toMatch(/<html[^>]* lang="en"/);
|
|
27
|
+
expect(html).toMatch(/Hello (<!-- -->)?Ada/);
|
|
28
|
+
});
|
|
29
|
+
});
|
package/src/app.tsx
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { LabelProvider, LayoutProvider } from '@websolutespa/bom-mixer-hooks';
|
|
2
|
-
import { IEmailAppComponent } from './types';
|
|
3
|
-
|
|
4
|
-
export const App: IEmailAppComponent = ({ Component, Layout, ...props }) => {
|
|
5
|
-
const LayoutComponent = Component.Layout || Layout;
|
|
6
|
-
return (
|
|
7
|
-
<LayoutProvider layout={props.layout}>
|
|
8
|
-
<LabelProvider>
|
|
9
|
-
<LayoutComponent {...props}>
|
|
10
|
-
<Component {...props}></Component>
|
|
11
|
-
</LayoutComponent>
|
|
12
|
-
</LabelProvider>
|
|
13
|
-
</LayoutProvider>
|
|
14
|
-
);
|
|
15
|
-
};
|
|
1
|
+
import { LabelProvider, LayoutProvider } from '@websolutespa/bom-mixer-hooks';
|
|
2
|
+
import { IEmailAppComponent } from './types';
|
|
3
|
+
|
|
4
|
+
export const App: IEmailAppComponent = ({ Component, Layout, ...props }) => {
|
|
5
|
+
const LayoutComponent = Component.Layout || Layout;
|
|
6
|
+
return (
|
|
7
|
+
<LayoutProvider layout={props.layout}>
|
|
8
|
+
<LabelProvider>
|
|
9
|
+
<LayoutComponent {...props}>
|
|
10
|
+
<Component {...props}></Component>
|
|
11
|
+
</LayoutComponent>
|
|
12
|
+
</LabelProvider>
|
|
13
|
+
</LayoutProvider>
|
|
14
|
+
);
|
|
15
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from './app';
|
|
2
|
-
export * from './render';
|
|
3
|
-
export * from './types';
|
|
4
|
-
|
|
1
|
+
export * from './app';
|
|
2
|
+
export * from './render';
|
|
3
|
+
export * from './types';
|
package/src/render.tsx
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { render } from '@react-email/render';
|
|
2
|
-
import { isDevelopment } from '@websolutespa/bom-core';
|
|
3
|
-
import { App } from './app';
|
|
4
|
-
import { IEmailAppProps } from './types';
|
|
5
|
-
|
|
6
|
-
export async function renderEmail<T>(props: IEmailAppProps<T>): Promise<string> {
|
|
7
|
-
// console.log('renderEmail.props', props);
|
|
8
|
-
const renderOptions = { pretty: isDevelopment };
|
|
9
|
-
// console.log('renderEmail.renderOptions', renderOptions);
|
|
10
|
-
try {
|
|
11
|
-
const html = await render(
|
|
12
|
-
// console.log('renderEmail', 'html', html);
|
|
13
|
-
return html;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
console.log(error);
|
|
16
|
-
return 'An error occurred';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
import { render } from '@react-email/render';
|
|
2
|
+
import { isDevelopment } from '@websolutespa/bom-core';
|
|
3
|
+
import { App } from './app';
|
|
4
|
+
import { IEmailAppProps } from './types';
|
|
5
|
+
|
|
6
|
+
export async function renderEmail<T>(props: IEmailAppProps<T>): Promise<string> {
|
|
7
|
+
// console.log('renderEmail.props', props);
|
|
8
|
+
const renderOptions = { pretty: isDevelopment };
|
|
9
|
+
// console.log('renderEmail.renderOptions', renderOptions);
|
|
10
|
+
try {
|
|
11
|
+
const html = await render(<App {...props} />, renderOptions);
|
|
12
|
+
// console.log('renderEmail', 'html', html);
|
|
13
|
+
return html;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.log(error);
|
|
16
|
+
return 'An error occurred';
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { ILayout } from '@websolutespa/bom-core';
|
|
2
|
-
import { FC, ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
export type IEmailSharedProps = {
|
|
5
|
-
origin: string;
|
|
6
|
-
layout: ILayout;
|
|
7
|
-
optInUrl?: string;
|
|
8
|
-
optOutUrl?: string;
|
|
9
|
-
viewOnWebUrl?: string;
|
|
10
|
-
preview?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type IEmailAppProps<T> = IEmailSharedProps & {
|
|
14
|
-
Component: IEmailComponent<T>;
|
|
15
|
-
Layout: IEmailLayoutComponent;
|
|
16
|
-
props: T;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type IEmailAppComponent<T = any> = FC<Readonly<IEmailAppProps<T>>>;
|
|
20
|
-
|
|
21
|
-
export type IEmailLayoutProps<T> = IEmailSharedProps & {
|
|
22
|
-
Component: IEmailComponent<T>;
|
|
23
|
-
props: T;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type IEmailLayoutComponent = FC<Readonly<IEmailSharedProps & { children: ReactNode }>>;
|
|
27
|
-
|
|
28
|
-
export type IEmailComponent<T> = FC<Readonly<IEmailSharedProps & { props: T }>> & {
|
|
29
|
-
Layout?: IEmailLayoutComponent;
|
|
30
|
-
};
|
|
1
|
+
import { ILayout } from '@websolutespa/bom-core';
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
export type IEmailSharedProps = {
|
|
5
|
+
origin: string;
|
|
6
|
+
layout: ILayout;
|
|
7
|
+
optInUrl?: string;
|
|
8
|
+
optOutUrl?: string;
|
|
9
|
+
viewOnWebUrl?: string;
|
|
10
|
+
preview?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type IEmailAppProps<T> = IEmailSharedProps & {
|
|
14
|
+
Component: IEmailComponent<T>;
|
|
15
|
+
Layout: IEmailLayoutComponent;
|
|
16
|
+
props: T;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type IEmailAppComponent<T = any> = FC<Readonly<IEmailAppProps<T>>>;
|
|
20
|
+
|
|
21
|
+
export type IEmailLayoutProps<T> = IEmailSharedProps & {
|
|
22
|
+
Component: IEmailComponent<T>;
|
|
23
|
+
props: T;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type IEmailLayoutComponent = FC<Readonly<IEmailSharedProps & { children: ReactNode }>>;
|
|
27
|
+
|
|
28
|
+
export type IEmailComponent<T> = FC<Readonly<IEmailSharedProps & { props: T }>> & {
|
|
29
|
+
Layout?: IEmailLayoutComponent;
|
|
30
|
+
};
|