@wrelik/email 0.1.0 → 0.1.3
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/.turbo/turbo-build.log +23 -0
- package/CHANGELOG.md +23 -0
- package/dist/index.d.mts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +80 -0
- package/dist/index.mjs +52 -0
- package/dist/unsupported.d.mts +2 -0
- package/dist/unsupported.d.ts +2 -0
- package/dist/unsupported.js +6 -0
- package/dist/unsupported.mjs +4 -0
- package/package.json +14 -5
- package/src/index.ts +2 -0
- package/src/unsupported.ts +4 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
> @wrelik/email@0.1.3 build /home/runner/work/wrelik-kit/wrelik-kit/packages/email
|
|
3
|
+
> tsup src/index.ts src/unsupported.ts --format cjs,esm --dts --clean
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts, src/unsupported.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.5.1
|
|
8
|
+
[34mCLI[39m Target: es2022
|
|
9
|
+
[34mCLI[39m Cleaning output folder
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[32mCJS[39m [1mdist/index.js [22m[32m2.27 KB[39m
|
|
13
|
+
[32mCJS[39m [1mdist/unsupported.js [22m[32m192.00 B[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 74ms
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m1.15 KB[39m
|
|
16
|
+
[32mESM[39m [1mdist/unsupported.mjs [22m[32m177.00 B[39m
|
|
17
|
+
[32mESM[39m ⚡️ Build success in 75ms
|
|
18
|
+
[34mDTS[39m Build start
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 2068ms
|
|
20
|
+
[32mDTS[39m [1mdist/unsupported.d.ts [22m[32m13.00 B[39m
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m900.00 B[39m
|
|
22
|
+
[32mDTS[39m [1mdist/unsupported.d.mts [22m[32m13.00 B[39m
|
|
23
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m900.00 B[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @wrelik/email
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [2b9cbf7]
|
|
8
|
+
- @wrelik/errors@0.2.1
|
|
9
|
+
|
|
10
|
+
## 0.1.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- a38ebcb: Add React Native / Expo support and enforce server-only boundaries.
|
|
15
|
+
- Updated dependencies [a38ebcb]
|
|
16
|
+
- @wrelik/errors@0.2.0
|
|
17
|
+
|
|
18
|
+
## 0.1.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Update publishConfig to access:public for all packages.
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
- @wrelik/errors@0.1.1
|
|
25
|
+
|
|
3
26
|
## 0.1.0
|
|
4
27
|
|
|
5
28
|
### Minor Changes
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as resend from 'resend';
|
|
2
|
+
|
|
3
|
+
declare function initEmail(apiKey: string, defaultFromAddress: string): void;
|
|
4
|
+
interface SendEmailOptions {
|
|
5
|
+
to: string | string[];
|
|
6
|
+
subject: string;
|
|
7
|
+
html?: string;
|
|
8
|
+
text?: string;
|
|
9
|
+
from?: string;
|
|
10
|
+
tags?: Array<{
|
|
11
|
+
name: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
declare function sendEmail({ to, subject, html, text, from, tags }: SendEmailOptions): Promise<resend.CreateEmailResponseSuccess | null>;
|
|
16
|
+
type TemplateRenderer<T> = (data: T) => {
|
|
17
|
+
subject: string;
|
|
18
|
+
html: string;
|
|
19
|
+
text?: string;
|
|
20
|
+
};
|
|
21
|
+
declare function defineTemplate<T>(id: string, renderer: TemplateRenderer<T>): void;
|
|
22
|
+
declare function sendTemplate<T>(id: string, to: string | string[], data: T, options?: Partial<SendEmailOptions>): Promise<resend.CreateEmailResponseSuccess | null>;
|
|
23
|
+
|
|
24
|
+
export { type SendEmailOptions, defineTemplate, initEmail, sendEmail, sendTemplate };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as resend from 'resend';
|
|
2
|
+
|
|
3
|
+
declare function initEmail(apiKey: string, defaultFromAddress: string): void;
|
|
4
|
+
interface SendEmailOptions {
|
|
5
|
+
to: string | string[];
|
|
6
|
+
subject: string;
|
|
7
|
+
html?: string;
|
|
8
|
+
text?: string;
|
|
9
|
+
from?: string;
|
|
10
|
+
tags?: Array<{
|
|
11
|
+
name: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
declare function sendEmail({ to, subject, html, text, from, tags }: SendEmailOptions): Promise<resend.CreateEmailResponseSuccess | null>;
|
|
16
|
+
type TemplateRenderer<T> = (data: T) => {
|
|
17
|
+
subject: string;
|
|
18
|
+
html: string;
|
|
19
|
+
text?: string;
|
|
20
|
+
};
|
|
21
|
+
declare function defineTemplate<T>(id: string, renderer: TemplateRenderer<T>): void;
|
|
22
|
+
declare function sendTemplate<T>(id: string, to: string | string[], data: T, options?: Partial<SendEmailOptions>): Promise<resend.CreateEmailResponseSuccess | null>;
|
|
23
|
+
|
|
24
|
+
export { type SendEmailOptions, defineTemplate, initEmail, sendEmail, sendTemplate };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
defineTemplate: () => defineTemplate,
|
|
24
|
+
initEmail: () => initEmail,
|
|
25
|
+
sendEmail: () => sendEmail,
|
|
26
|
+
sendTemplate: () => sendTemplate
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var import_resend = require("resend");
|
|
30
|
+
var import_errors = require("@wrelik/errors");
|
|
31
|
+
var client;
|
|
32
|
+
var defaultFrom;
|
|
33
|
+
function initEmail(apiKey, defaultFromAddress) {
|
|
34
|
+
client = new import_resend.Resend(apiKey);
|
|
35
|
+
defaultFrom = defaultFromAddress;
|
|
36
|
+
}
|
|
37
|
+
function getClient() {
|
|
38
|
+
if (!client) throw new Error("Email not initialized");
|
|
39
|
+
return client;
|
|
40
|
+
}
|
|
41
|
+
async function sendEmail({ to, subject, html, text, from, tags }) {
|
|
42
|
+
const result = await getClient().emails.send({
|
|
43
|
+
from: from || defaultFrom,
|
|
44
|
+
to,
|
|
45
|
+
subject,
|
|
46
|
+
html,
|
|
47
|
+
text,
|
|
48
|
+
tags,
|
|
49
|
+
react: null
|
|
50
|
+
});
|
|
51
|
+
if (result.error) {
|
|
52
|
+
throw new Error(`Failed to send email: ${result.error.message}`);
|
|
53
|
+
}
|
|
54
|
+
return result.data;
|
|
55
|
+
}
|
|
56
|
+
var templates = /* @__PURE__ */ new Map();
|
|
57
|
+
function defineTemplate(id, renderer) {
|
|
58
|
+
templates.set(id, renderer);
|
|
59
|
+
}
|
|
60
|
+
async function sendTemplate(id, to, data, options) {
|
|
61
|
+
const renderer = templates.get(id);
|
|
62
|
+
if (!renderer) {
|
|
63
|
+
throw new import_errors.ValidationError(`Template ${id} not found`);
|
|
64
|
+
}
|
|
65
|
+
const { subject, html, text } = renderer(data);
|
|
66
|
+
return sendEmail({
|
|
67
|
+
to,
|
|
68
|
+
subject,
|
|
69
|
+
html,
|
|
70
|
+
text,
|
|
71
|
+
...options
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
defineTemplate,
|
|
77
|
+
initEmail,
|
|
78
|
+
sendEmail,
|
|
79
|
+
sendTemplate
|
|
80
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { Resend } from "resend";
|
|
3
|
+
import { ValidationError } from "@wrelik/errors";
|
|
4
|
+
var client;
|
|
5
|
+
var defaultFrom;
|
|
6
|
+
function initEmail(apiKey, defaultFromAddress) {
|
|
7
|
+
client = new Resend(apiKey);
|
|
8
|
+
defaultFrom = defaultFromAddress;
|
|
9
|
+
}
|
|
10
|
+
function getClient() {
|
|
11
|
+
if (!client) throw new Error("Email not initialized");
|
|
12
|
+
return client;
|
|
13
|
+
}
|
|
14
|
+
async function sendEmail({ to, subject, html, text, from, tags }) {
|
|
15
|
+
const result = await getClient().emails.send({
|
|
16
|
+
from: from || defaultFrom,
|
|
17
|
+
to,
|
|
18
|
+
subject,
|
|
19
|
+
html,
|
|
20
|
+
text,
|
|
21
|
+
tags,
|
|
22
|
+
react: null
|
|
23
|
+
});
|
|
24
|
+
if (result.error) {
|
|
25
|
+
throw new Error(`Failed to send email: ${result.error.message}`);
|
|
26
|
+
}
|
|
27
|
+
return result.data;
|
|
28
|
+
}
|
|
29
|
+
var templates = /* @__PURE__ */ new Map();
|
|
30
|
+
function defineTemplate(id, renderer) {
|
|
31
|
+
templates.set(id, renderer);
|
|
32
|
+
}
|
|
33
|
+
async function sendTemplate(id, to, data, options) {
|
|
34
|
+
const renderer = templates.get(id);
|
|
35
|
+
if (!renderer) {
|
|
36
|
+
throw new ValidationError(`Template ${id} not found`);
|
|
37
|
+
}
|
|
38
|
+
const { subject, html, text } = renderer(data);
|
|
39
|
+
return sendEmail({
|
|
40
|
+
to,
|
|
41
|
+
subject,
|
|
42
|
+
html,
|
|
43
|
+
text,
|
|
44
|
+
...options
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
defineTemplate,
|
|
49
|
+
initEmail,
|
|
50
|
+
sendEmail,
|
|
51
|
+
sendTemplate
|
|
52
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wrelik/email",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/lwhite702/wrelik-kit.git",
|
|
10
|
+
"directory": "packages/email"
|
|
11
|
+
},
|
|
4
12
|
"main": "./dist/index.js",
|
|
5
13
|
"types": "./dist/index.d.ts",
|
|
14
|
+
"react-native": "./dist/unsupported.js",
|
|
6
15
|
"dependencies": {
|
|
7
16
|
"resend": "^3.2.0",
|
|
8
|
-
"@wrelik/errors": "0.1
|
|
17
|
+
"@wrelik/errors": "0.2.1"
|
|
9
18
|
},
|
|
10
19
|
"devDependencies": {
|
|
11
20
|
"tsup": "^8.0.1",
|
|
12
21
|
"vitest": "^1.2.2",
|
|
13
|
-
"@wrelik/eslint-config": "0.1.
|
|
14
|
-
"@wrelik/tsconfig": "0.1.
|
|
22
|
+
"@wrelik/eslint-config": "0.1.1",
|
|
23
|
+
"@wrelik/tsconfig": "0.1.1"
|
|
15
24
|
},
|
|
16
25
|
"scripts": {
|
|
17
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
26
|
+
"build": "tsup src/index.ts src/unsupported.ts --format cjs,esm --dts --clean",
|
|
18
27
|
"lint": "eslint src/",
|
|
19
28
|
"test": "vitest run --passWithNoTests"
|
|
20
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// eslint-disable-next-line no-restricted-imports
|
|
1
2
|
import { Resend } from 'resend';
|
|
2
3
|
import { ValidationError } from '@wrelik/errors';
|
|
3
4
|
|
|
@@ -43,6 +44,7 @@ export async function sendEmail({ to, subject, html, text, from, tags }: SendEma
|
|
|
43
44
|
|
|
44
45
|
// Template Registry
|
|
45
46
|
type TemplateRenderer<T> = (data: T) => { subject: string; html: string; text?: string };
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
48
|
const templates = new Map<string, TemplateRenderer<any>>();
|
|
47
49
|
|
|
48
50
|
export function defineTemplate<T>(id: string, renderer: TemplateRenderer<T>) {
|