@keycloakify/angular-email 0.0.1-rc.9 → 0.0.1
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/README.md +160 -13
- package/bin/{build.js → build.mjs} +4 -3
- package/fesm2022/keycloakify-angular-email.mjs +125 -114
- package/fesm2022/keycloakify-angular-email.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/lib/components/button/button.component.d.ts +6 -6
- package/lib/components/row/row.component.d.ts +8 -0
- package/lib/render.d.ts +4 -3
- package/node/index.cjs +1 -0
- package/node/index.d.ts +5 -0
- package/node/index.js +1 -0
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Angular Email
|
|
2
2
|
|
|
3
|
-
Angular Email is a library that enables email template development using Angular, inspired by [jsx-email](https://github.com/
|
|
3
|
+
Angular Email is a library that enables email template development using Angular, inspired by [jsx-email](https://github.com/shellscape/jsx-email). It provides a way to create email components using Angular's templating system.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -23,22 +23,69 @@ see this [example](https://github.com/keycloakify/angular-email/blob/main/projec
|
|
|
23
23
|
To render the email as HTML or plaintext, use Angular's rendering engine:
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
+
// email.component.ts
|
|
26
27
|
...
|
|
27
|
-
import { render } from '@keycloakify/angular-email';
|
|
28
|
+
import { render, RenderToHtml } from '@keycloakify/angular-email';
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
...
|
|
31
|
+
export class EmailComponent {
|
|
32
|
+
....
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type EmailComponentProps = {};
|
|
36
|
+
|
|
37
|
+
export const renderToHtml: RenderToHtml<EmailComponentProps> = (props) => {
|
|
38
|
+
return render({
|
|
39
|
+
component: EmailComponent,
|
|
40
|
+
selector: 'app-root',
|
|
41
|
+
props,
|
|
42
|
+
options: {
|
|
43
|
+
pretty: true,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
};
|
|
38
47
|
```
|
|
39
48
|
|
|
49
|
+
```sh
|
|
50
|
+
# cmd
|
|
51
|
+
|
|
52
|
+
export $EMAIL_COMPONENTS_DIR_PATH="src/emails"
|
|
53
|
+
npx keycloakify-angular-email build -p $EMAIL_COMPONENTS_DIR_PATH
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
NB: use `keycloakify-angular-email build` when you don't need to pass dynamic inputs to your components, otherwise see [Standalone Dynamic Rendering](#standalone-dynamic-rendering)
|
|
57
|
+
|
|
40
58
|
### With Keycloakify Emails
|
|
41
59
|
|
|
60
|
+
```ts
|
|
61
|
+
// email.component.ts
|
|
62
|
+
...
|
|
63
|
+
import { render } from '@keycloakify/angular-email';
|
|
64
|
+
import type { GetSubject, GetTemplate } from 'keycloakify-emails';
|
|
65
|
+
|
|
66
|
+
...
|
|
67
|
+
export class EmailComponent {
|
|
68
|
+
....
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const getTemplate: GetTemplate = async (props) => {
|
|
72
|
+
return await render({
|
|
73
|
+
component: EmailComponent,
|
|
74
|
+
props,
|
|
75
|
+
selector: 'kc-email-test',
|
|
76
|
+
options: {
|
|
77
|
+
signalInputsPrefix: '$',
|
|
78
|
+
pretty: true,
|
|
79
|
+
plainText: props.plainText,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const getSubject: GetSubject = async (_props) => {
|
|
85
|
+
return '[KEYCLOAK] - SMTP test message';
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
42
89
|
```ts
|
|
43
90
|
// vite.config.ts
|
|
44
91
|
|
|
@@ -55,14 +102,16 @@ export default defineConfig(({ mode }) => ({
|
|
|
55
102
|
postBuild: async (buildContext) => {
|
|
56
103
|
await buildEmailTheme({
|
|
57
104
|
templatesSrcDirPath: join(import.meta.dirname, '/emails/templates'),
|
|
58
|
-
filterTemplate: (filePath: string) =>
|
|
105
|
+
filterTemplate: (filePath: string) => !!filePath.endsWith('.component.ts'),
|
|
59
106
|
themeNames: buildContext.themeNames,
|
|
60
107
|
keycloakifyBuildDirPath: buildContext.keycloakifyBuildDirPath,
|
|
61
108
|
locales: ['en'],
|
|
62
109
|
cwd: import.meta.dirname,
|
|
63
110
|
esbuild: {
|
|
64
111
|
packages: 'bundle',
|
|
65
|
-
external: ['
|
|
112
|
+
external: ['juice', 'postcss'],
|
|
113
|
+
format: 'cjs',
|
|
114
|
+
outExtension: { '.js': '.cjs' },
|
|
66
115
|
plugins: [angularEsbuildPlugin(import.meta.dirname)],
|
|
67
116
|
},
|
|
68
117
|
});
|
|
@@ -72,6 +121,104 @@ export default defineConfig(({ mode }) => ({
|
|
|
72
121
|
}));
|
|
73
122
|
```
|
|
74
123
|
|
|
124
|
+
### Standalone Dynamic Rendering
|
|
125
|
+
|
|
126
|
+
Use it in a server environment
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
// index.mjs
|
|
130
|
+
|
|
131
|
+
import { toHTML } from '@keycloakify/angular-email/node';
|
|
132
|
+
|
|
133
|
+
toHTML({
|
|
134
|
+
filePath: 'path/to/your.component.ts',
|
|
135
|
+
props: { foo: 'bar' },
|
|
136
|
+
})
|
|
137
|
+
.then((html) => {
|
|
138
|
+
console.log(html);
|
|
139
|
+
})
|
|
140
|
+
.catch((e) => {
|
|
141
|
+
console.error(e);
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
or
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
// index.cjs
|
|
149
|
+
|
|
150
|
+
const { toHTML } = require('@keycloakify/angular-email/node');
|
|
151
|
+
|
|
152
|
+
toHTML({
|
|
153
|
+
filePath: 'path/to/your.component.ts',
|
|
154
|
+
props: { foo: 'bar' },
|
|
155
|
+
})
|
|
156
|
+
.then((html) => {
|
|
157
|
+
console.log(html);
|
|
158
|
+
})
|
|
159
|
+
.catch((e) => {
|
|
160
|
+
console.error(e);
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```sh
|
|
165
|
+
# cmd
|
|
166
|
+
|
|
167
|
+
node index.mjs # or node index.cjs
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## API
|
|
171
|
+
|
|
172
|
+
### @keycloakify/angular-email
|
|
173
|
+
|
|
174
|
+
### Render
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
type Render<Input extends Record<string, any>> = {
|
|
178
|
+
component: Type<unknown>;
|
|
179
|
+
/** Component selector */
|
|
180
|
+
selector: string;
|
|
181
|
+
/** Component inputs */
|
|
182
|
+
props?: Input;
|
|
183
|
+
options?: {
|
|
184
|
+
/** render as text */
|
|
185
|
+
plainText?: boolean;
|
|
186
|
+
/** format the html output */
|
|
187
|
+
pretty?: boolean;
|
|
188
|
+
/** tailwind configuration object */
|
|
189
|
+
tailwindConfig?: Partial<Config>;
|
|
190
|
+
/** if you use prefix conventions on signal inputs */
|
|
191
|
+
signalInputsPrefix?: string;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### render()
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
render<Input extends Record<string, any>>({ component, selector, props, options }: Render<Input>) => Promise<string>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### @keycloakify/angular-email/esbuild
|
|
203
|
+
|
|
204
|
+
### angularEsbuildPlugin()
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
angularEsbuildPlugin(cwd: string) => Plugin
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### @keycloakify/angular-email/node
|
|
211
|
+
|
|
212
|
+
### toHTML()
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
toHTML<Input extends Record<string, any>>(options: {
|
|
216
|
+
filePath: string;
|
|
217
|
+
props?: Input;
|
|
218
|
+
root?: string;
|
|
219
|
+
}) => Promise<string>
|
|
220
|
+
```
|
|
221
|
+
|
|
75
222
|
## Contributing
|
|
76
223
|
|
|
77
224
|
Contributions are welcome! Feel free to open an issue or submit a pull request on [GitHub](https://github.com/keycloakify/angular-email).
|
|
@@ -20,8 +20,9 @@ async function bundle(entryPoints, cwd, outdir) {
|
|
|
20
20
|
platform: 'node',
|
|
21
21
|
sourcemap: true,
|
|
22
22
|
packages: 'bundle',
|
|
23
|
-
external: ['
|
|
24
|
-
format: '
|
|
23
|
+
external: ['juice', 'postcss'],
|
|
24
|
+
format: 'cjs',
|
|
25
|
+
outExtension: { '.js': '.cjs' },
|
|
25
26
|
target: 'node20',
|
|
26
27
|
plugins: [angularEsbuildPlugin(cwd)],
|
|
27
28
|
metafile: true,
|
|
@@ -108,7 +109,7 @@ const program = termost({
|
|
|
108
109
|
version: pkg.version,
|
|
109
110
|
onException: (error) => {
|
|
110
111
|
console.error(error);
|
|
111
|
-
|
|
112
|
+
exit(1);
|
|
112
113
|
},
|
|
113
114
|
});
|
|
114
115
|
program.option({
|