@wrelik/email 0.1.0 → 0.1.2

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.
@@ -0,0 +1,23 @@
1
+
2
+ > @wrelik/email@0.1.2 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
+ CLI Building entry: src/index.ts, src/unsupported.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Target: es2022
9
+ CLI Cleaning output folder
10
+ CJS Build start
11
+ ESM Build start
12
+ CJS dist/index.js 2.27 KB
13
+ CJS dist/unsupported.js 192.00 B
14
+ CJS ⚡️ Build success in 57ms
15
+ ESM dist/unsupported.mjs 177.00 B
16
+ ESM dist/index.mjs 1.15 KB
17
+ ESM ⚡️ Build success in 60ms
18
+ DTS Build start
19
+ DTS ⚡️ Build success in 1841ms
20
+ DTS dist/unsupported.d.ts 13.00 B
21
+ DTS dist/index.d.ts 900.00 B
22
+ DTS dist/unsupported.d.mts 13.00 B
23
+ DTS dist/index.d.mts 900.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @wrelik/email
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - a38ebcb: Add React Native / Expo support and enforce server-only boundaries.
8
+ - Updated dependencies [a38ebcb]
9
+ - @wrelik/errors@0.2.0
10
+
11
+ ## 0.1.1
12
+
13
+ ### Patch Changes
14
+
15
+ - Update publishConfig to access:public for all packages.
16
+ - Updated dependencies
17
+ - @wrelik/errors@0.1.1
18
+
3
19
  ## 0.1.0
4
20
 
5
21
  ### Minor Changes
@@ -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 };
@@ -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
+ };
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ // src/unsupported.ts
4
+ throw new Error(
5
+ "This package is server-only and cannot be used in client/mobile environments. Access this functionality via a backend API instead."
6
+ );
@@ -0,0 +1,4 @@
1
+ // src/unsupported.ts
2
+ throw new Error(
3
+ "This package is server-only and cannot be used in client/mobile environments. Access this functionality via a backend API instead."
4
+ );
package/package.json CHANGED
@@ -1,20 +1,29 @@
1
1
  {
2
2
  "name": "@wrelik/email",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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.0"
17
+ "@wrelik/errors": "0.2.0"
9
18
  },
10
19
  "devDependencies": {
11
20
  "tsup": "^8.0.1",
12
21
  "vitest": "^1.2.2",
13
- "@wrelik/eslint-config": "0.1.0",
14
- "@wrelik/tsconfig": "0.1.0"
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>) {
@@ -0,0 +1,4 @@
1
+ throw new Error(
2
+ 'This package is server-only and cannot be used in client/mobile environments. ' +
3
+ 'Access this functionality via a backend API instead.',
4
+ );
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "extends": "@wrelik/tsconfig/node.json",
3
3
  "compilerOptions": {
4
- "outDir": "dist"
4
+ "outDir": "dist", "skipLibCheck": true
5
5
  },
6
6
  "include": ["src"]
7
7
  }