admin-lib-cms 1.0.5 → 1.0.7

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,152 @@
1
+ // src/emails/templates/default.ts
2
+ function generateDefaultTemplate(data, title, description, companyName = "Admin CMS") {
3
+ const items = Object.entries(data).filter(([_, value]) => value !== void 0 && value !== null && value !== "").map(([key, value]) => {
4
+ const label = key.replace(/([A-Z])/g, " $1").replace(/^./, (str) => str.toUpperCase());
5
+ const displayValue = Array.isArray(value) ? value.join(", ") : String(value);
6
+ return `
7
+ <div class="detail-item">
8
+ <span class="detail-label">${label}</span>
9
+ <span class="detail-value">${displayValue}</span>
10
+ </div>
11
+ `;
12
+ }).join("");
13
+ return `
14
+ <!DOCTYPE html>
15
+ <html lang="en">
16
+ <head>
17
+ <meta charset="UTF-8">
18
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
19
+ <title>${title}</title>
20
+ <style>
21
+ * { margin: 0; padding: 0; box-sizing: border-box; }
22
+ body {
23
+ background-color: #f4f4f5;
24
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
25
+ color: #18181b;
26
+ line-height: 1.5;
27
+ }
28
+ .wrapper { width: 100%; padding: 40px 20px; }
29
+ .container { max-width: 600px; margin: 0 auto; }
30
+ .card {
31
+ background: #ffffff;
32
+ border-radius: 12px;
33
+ overflow: hidden;
34
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
35
+ border: 1px solid #e4e4e7;
36
+ }
37
+ .header {
38
+ background: #1a2d42;
39
+ padding: 40px 32px;
40
+ text-align: center;
41
+ border-bottom: 4px solid #d4af37;
42
+ }
43
+ .header h1 {
44
+ color: #ffffff;
45
+ font-size: 24px;
46
+ font-weight: 700;
47
+ margin-bottom: 8px;
48
+ text-transform: uppercase;
49
+ letter-spacing: 0.05em;
50
+ }
51
+ .header p {
52
+ color: rgba(255, 255, 255, 0.9);
53
+ font-size: 14px;
54
+ }
55
+ .content { padding: 32px; }
56
+ .details-grid {
57
+ display: grid;
58
+ gap: 12px;
59
+ margin-bottom: 24px;
60
+ }
61
+ .detail-item {
62
+ background: #fafafa;
63
+ padding: 12px 16px;
64
+ border-radius: 8px;
65
+ border: 1px solid #f1f1f4;
66
+ }
67
+ .detail-label {
68
+ font-size: 11px;
69
+ font-weight: 700;
70
+ color: #71717a;
71
+ text-transform: uppercase;
72
+ letter-spacing: 0.05em;
73
+ display: block;
74
+ margin-bottom: 4px;
75
+ }
76
+ .detail-value {
77
+ font-size: 14px;
78
+ font-weight: 500;
79
+ color: #18181b;
80
+ word-break: break-word;
81
+ }
82
+ .footer {
83
+ padding: 24px 32px;
84
+ background: #f8fafc;
85
+ border-top: 1px solid #e2e8f0;
86
+ text-align: center;
87
+ }
88
+ .footer-text {
89
+ font-size: 12px;
90
+ color: #64748b;
91
+ }
92
+ </style>
93
+ </head>
94
+ <body>
95
+ <div class="wrapper">
96
+ <div class="container">
97
+ <div class="card">
98
+ <div class="header">
99
+ <h1>${title}</h1>
100
+ <p>${description}</p>
101
+ </div>
102
+ <div class="content">
103
+ <div class="details-grid">
104
+ ${items}
105
+ </div>
106
+ </div>
107
+ <div class="footer">
108
+ <p class="footer-text">\xA9 ${(/* @__PURE__ */ new Date()).getFullYear()} ${companyName}. This is an automated notification.</p>
109
+ </div>
110
+ </div>
111
+ </div>
112
+ </div>
113
+ </body>
114
+ </html>
115
+ `;
116
+ }
117
+
118
+ // src/emails/index.ts
119
+ async function sendEmailNotification(content, apiUrl) {
120
+ try {
121
+ const url = apiUrl || process.env.API_URL || process.env.NEXT_PUBLIC_API_URL || "";
122
+ const response = await fetch(`${url}/api/send-email`, {
123
+ method: "POST",
124
+ headers: {
125
+ "Content-Type": "application/json"
126
+ },
127
+ body: JSON.stringify({
128
+ content: {
129
+ ...content,
130
+ from: content.from || "Admin CMS <notifications@admincms.com>"
131
+ }
132
+ })
133
+ });
134
+ if (response.ok) {
135
+ const result = await response.json();
136
+ if (!result.success) {
137
+ console.error("Failed to send email:", result.error);
138
+ }
139
+ return result;
140
+ } else {
141
+ console.warn("Email API endpoint error:", response.status);
142
+ }
143
+ } catch (error) {
144
+ console.error("Error sending email:", error);
145
+ }
146
+ return null;
147
+ }
148
+
149
+ export {
150
+ generateDefaultTemplate,
151
+ sendEmailNotification
152
+ };
@@ -0,0 +1,10 @@
1
+ declare function generateDefaultTemplate(data: any, title: string, description: string, companyName?: string): string;
2
+
3
+ declare function sendEmailNotification(content: {
4
+ to: string;
5
+ subject: string;
6
+ html: string;
7
+ from?: string;
8
+ }, apiUrl?: string): Promise<any>;
9
+
10
+ export { generateDefaultTemplate, sendEmailNotification };
@@ -0,0 +1,10 @@
1
+ declare function generateDefaultTemplate(data: any, title: string, description: string, companyName?: string): string;
2
+
3
+ declare function sendEmailNotification(content: {
4
+ to: string;
5
+ subject: string;
6
+ html: string;
7
+ from?: string;
8
+ }, apiUrl?: string): Promise<any>;
9
+
10
+ export { generateDefaultTemplate, sendEmailNotification };
@@ -0,0 +1,179 @@
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/emails/index.ts
21
+ var emails_exports = {};
22
+ __export(emails_exports, {
23
+ generateDefaultTemplate: () => generateDefaultTemplate,
24
+ sendEmailNotification: () => sendEmailNotification
25
+ });
26
+ module.exports = __toCommonJS(emails_exports);
27
+
28
+ // src/emails/templates/default.ts
29
+ function generateDefaultTemplate(data, title, description, companyName = "Admin CMS") {
30
+ const items = Object.entries(data).filter(([_, value]) => value !== void 0 && value !== null && value !== "").map(([key, value]) => {
31
+ const label = key.replace(/([A-Z])/g, " $1").replace(/^./, (str) => str.toUpperCase());
32
+ const displayValue = Array.isArray(value) ? value.join(", ") : String(value);
33
+ return `
34
+ <div class="detail-item">
35
+ <span class="detail-label">${label}</span>
36
+ <span class="detail-value">${displayValue}</span>
37
+ </div>
38
+ `;
39
+ }).join("");
40
+ return `
41
+ <!DOCTYPE html>
42
+ <html lang="en">
43
+ <head>
44
+ <meta charset="UTF-8">
45
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
46
+ <title>${title}</title>
47
+ <style>
48
+ * { margin: 0; padding: 0; box-sizing: border-box; }
49
+ body {
50
+ background-color: #f4f4f5;
51
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
52
+ color: #18181b;
53
+ line-height: 1.5;
54
+ }
55
+ .wrapper { width: 100%; padding: 40px 20px; }
56
+ .container { max-width: 600px; margin: 0 auto; }
57
+ .card {
58
+ background: #ffffff;
59
+ border-radius: 12px;
60
+ overflow: hidden;
61
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
62
+ border: 1px solid #e4e4e7;
63
+ }
64
+ .header {
65
+ background: #1a2d42;
66
+ padding: 40px 32px;
67
+ text-align: center;
68
+ border-bottom: 4px solid #d4af37;
69
+ }
70
+ .header h1 {
71
+ color: #ffffff;
72
+ font-size: 24px;
73
+ font-weight: 700;
74
+ margin-bottom: 8px;
75
+ text-transform: uppercase;
76
+ letter-spacing: 0.05em;
77
+ }
78
+ .header p {
79
+ color: rgba(255, 255, 255, 0.9);
80
+ font-size: 14px;
81
+ }
82
+ .content { padding: 32px; }
83
+ .details-grid {
84
+ display: grid;
85
+ gap: 12px;
86
+ margin-bottom: 24px;
87
+ }
88
+ .detail-item {
89
+ background: #fafafa;
90
+ padding: 12px 16px;
91
+ border-radius: 8px;
92
+ border: 1px solid #f1f1f4;
93
+ }
94
+ .detail-label {
95
+ font-size: 11px;
96
+ font-weight: 700;
97
+ color: #71717a;
98
+ text-transform: uppercase;
99
+ letter-spacing: 0.05em;
100
+ display: block;
101
+ margin-bottom: 4px;
102
+ }
103
+ .detail-value {
104
+ font-size: 14px;
105
+ font-weight: 500;
106
+ color: #18181b;
107
+ word-break: break-word;
108
+ }
109
+ .footer {
110
+ padding: 24px 32px;
111
+ background: #f8fafc;
112
+ border-top: 1px solid #e2e8f0;
113
+ text-align: center;
114
+ }
115
+ .footer-text {
116
+ font-size: 12px;
117
+ color: #64748b;
118
+ }
119
+ </style>
120
+ </head>
121
+ <body>
122
+ <div class="wrapper">
123
+ <div class="container">
124
+ <div class="card">
125
+ <div class="header">
126
+ <h1>${title}</h1>
127
+ <p>${description}</p>
128
+ </div>
129
+ <div class="content">
130
+ <div class="details-grid">
131
+ ${items}
132
+ </div>
133
+ </div>
134
+ <div class="footer">
135
+ <p class="footer-text">\xA9 ${(/* @__PURE__ */ new Date()).getFullYear()} ${companyName}. This is an automated notification.</p>
136
+ </div>
137
+ </div>
138
+ </div>
139
+ </div>
140
+ </body>
141
+ </html>
142
+ `;
143
+ }
144
+
145
+ // src/emails/index.ts
146
+ async function sendEmailNotification(content, apiUrl) {
147
+ try {
148
+ const url = apiUrl || process.env.API_URL || process.env.NEXT_PUBLIC_API_URL || "";
149
+ const response = await fetch(`${url}/api/send-email`, {
150
+ method: "POST",
151
+ headers: {
152
+ "Content-Type": "application/json"
153
+ },
154
+ body: JSON.stringify({
155
+ content: {
156
+ ...content,
157
+ from: content.from || "Admin CMS <notifications@admincms.com>"
158
+ }
159
+ })
160
+ });
161
+ if (response.ok) {
162
+ const result = await response.json();
163
+ if (!result.success) {
164
+ console.error("Failed to send email:", result.error);
165
+ }
166
+ return result;
167
+ } else {
168
+ console.warn("Email API endpoint error:", response.status);
169
+ }
170
+ } catch (error) {
171
+ console.error("Error sending email:", error);
172
+ }
173
+ return null;
174
+ }
175
+ // Annotate the CommonJS export names for ESM import in node:
176
+ 0 && (module.exports = {
177
+ generateDefaultTemplate,
178
+ sendEmailNotification
179
+ });
@@ -0,0 +1,8 @@
1
+ import {
2
+ generateDefaultTemplate,
3
+ sendEmailNotification
4
+ } from "../chunk-ZG5XBIW7.mjs";
5
+ export {
6
+ generateDefaultTemplate,
7
+ sendEmailNotification
8
+ };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { CmsConfig, StorageAdapter, OverridesMap, EditableMeta } from './types.mjs';
4
- export { generateEmailTemplate } from './email.mjs';
4
+ export { generateDefaultTemplate, sendEmailNotification } from './emails/index.mjs';
5
5
 
6
6
  interface CmsContextValue {
7
7
  config: CmsConfig;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { CmsConfig, StorageAdapter, OverridesMap, EditableMeta } from './types.js';
4
- export { generateEmailTemplate } from './email.js';
4
+ export { generateDefaultTemplate, sendEmailNotification } from './emails/index.js';
5
5
 
6
6
  interface CmsContextValue {
7
7
  config: CmsConfig;
package/dist/index.js CHANGED
@@ -30,7 +30,8 @@ __export(index_exports, {
30
30
  EditableText: () => EditableText,
31
31
  SubscriptionPage: () => SubscriptionPage,
32
32
  SubscriptionProvider: () => SubscriptionProvider,
33
- generateEmailTemplate: () => generateEmailTemplate,
33
+ generateDefaultTemplate: () => generateDefaultTemplate,
34
+ sendEmailNotification: () => sendEmailNotification,
34
35
  useCmsContext: () => useCmsContext,
35
36
  useCmsOptional: () => useCmsOptional,
36
37
  useSubmit: () => useSubmit,
@@ -2208,8 +2209,8 @@ function AdminLogin({
2208
2209
  ] }) });
2209
2210
  }
2210
2211
 
2211
- // src/email.ts
2212
- function generateEmailTemplate(data, title, description) {
2212
+ // src/emails/templates/default.ts
2213
+ function generateDefaultTemplate(data, title, description, companyName = "Admin CMS") {
2213
2214
  const items = Object.entries(data).filter(([_, value]) => value !== void 0 && value !== null && value !== "").map(([key, value]) => {
2214
2215
  const label = key.replace(/([A-Z])/g, " $1").replace(/^./, (str) => str.toUpperCase());
2215
2216
  const displayValue = Array.isArray(value) ? value.join(", ") : String(value);
@@ -2245,10 +2246,10 @@ function generateEmailTemplate(data, title, description) {
2245
2246
  border: 1px solid #e4e4e7;
2246
2247
  }
2247
2248
  .header {
2248
- background: #5fa075;
2249
+ background: #1a2d42;
2249
2250
  padding: 40px 32px;
2250
2251
  text-align: center;
2251
- border-bottom: 4px solid #48805c;
2252
+ border-bottom: 4px solid #d4af37;
2252
2253
  }
2253
2254
  .header h1 {
2254
2255
  color: #ffffff;
@@ -2315,7 +2316,7 @@ function generateEmailTemplate(data, title, description) {
2315
2316
  </div>
2316
2317
  </div>
2317
2318
  <div class="footer">
2318
- <p class="footer-text">\xA9 ${(/* @__PURE__ */ new Date()).getFullYear()} Serenity Wellness. This is an automated notification.</p>
2319
+ <p class="footer-text">\xA9 ${(/* @__PURE__ */ new Date()).getFullYear()} ${companyName}. This is an automated notification.</p>
2319
2320
  </div>
2320
2321
  </div>
2321
2322
  </div>
@@ -2324,6 +2325,37 @@ function generateEmailTemplate(data, title, description) {
2324
2325
  </html>
2325
2326
  `;
2326
2327
  }
2328
+
2329
+ // src/emails/index.ts
2330
+ async function sendEmailNotification(content, apiUrl) {
2331
+ try {
2332
+ const url = apiUrl || process.env.API_URL || process.env.NEXT_PUBLIC_API_URL || "";
2333
+ const response = await fetch(`${url}/api/send-email`, {
2334
+ method: "POST",
2335
+ headers: {
2336
+ "Content-Type": "application/json"
2337
+ },
2338
+ body: JSON.stringify({
2339
+ content: {
2340
+ ...content,
2341
+ from: content.from || "Admin CMS <notifications@admincms.com>"
2342
+ }
2343
+ })
2344
+ });
2345
+ if (response.ok) {
2346
+ const result = await response.json();
2347
+ if (!result.success) {
2348
+ console.error("Failed to send email:", result.error);
2349
+ }
2350
+ return result;
2351
+ } else {
2352
+ console.warn("Email API endpoint error:", response.status);
2353
+ }
2354
+ } catch (error) {
2355
+ console.error("Error sending email:", error);
2356
+ }
2357
+ return null;
2358
+ }
2327
2359
  // Annotate the CommonJS export names for ESM import in node:
2328
2360
  0 && (module.exports = {
2329
2361
  AdminApp,
@@ -2335,7 +2367,8 @@ function generateEmailTemplate(data, title, description) {
2335
2367
  EditableText,
2336
2368
  SubscriptionPage,
2337
2369
  SubscriptionProvider,
2338
- generateEmailTemplate,
2370
+ generateDefaultTemplate,
2371
+ sendEmailNotification,
2339
2372
  useCmsContext,
2340
2373
  useCmsOptional,
2341
2374
  useSubmit,
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  "use client";
2
2
  import {
3
- generateEmailTemplate
4
- } from "./chunk-CQW7KMB2.mjs";
3
+ generateDefaultTemplate,
4
+ sendEmailNotification
5
+ } from "./chunk-ZG5XBIW7.mjs";
5
6
 
6
7
  // src/provider.tsx
7
8
  import {
@@ -2214,7 +2215,8 @@ export {
2214
2215
  EditableText,
2215
2216
  SubscriptionPage,
2216
2217
  SubscriptionProvider,
2217
- generateEmailTemplate,
2218
+ generateDefaultTemplate,
2219
+ sendEmailNotification,
2218
2220
  useCmsContext,
2219
2221
  useCmsOptional,
2220
2222
  useSubmit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin-lib-cms",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Agnostic Admin CMS Library",
5
5
  "keywords": [
6
6
  "cms",
@@ -37,11 +37,11 @@
37
37
  "require": "./dist/auth.js",
38
38
  "default": "./dist/auth.js"
39
39
  },
40
- "./email": {
41
- "types": "./dist/email.d.ts",
42
- "import": "./dist/email.mjs",
43
- "require": "./dist/email.js",
44
- "default": "./dist/email.js"
40
+ "./emails": {
41
+ "types": "./dist/emails/index.d.ts",
42
+ "import": "./dist/emails/index.mjs",
43
+ "require": "./dist/emails/index.js",
44
+ "default": "./dist/emails/index.js"
45
45
  },
46
46
  "./storage": {
47
47
  "types": "./dist/storage.d.ts",
@@ -57,8 +57,8 @@
57
57
  }
58
58
  },
59
59
  "scripts": {
60
- "build": "tsup \"src/*.ts\" --format cjs,esm --dts --external next",
61
- "dev": "tsup \"src/*.ts\" --format cjs,esm --dts --external next --watch"
60
+ "build": "tsup \"src/*.ts\" \"src/emails/index.ts\" --format cjs,esm --dts --external next",
61
+ "dev": "tsup \"src/*.ts\" \"src/emails/index.ts\" --format cjs,esm --dts --external next --watch"
62
62
  },
63
63
  "dependencies": {
64
64
  "bcryptjs": "^3.0.3",
@@ -77,7 +77,7 @@
77
77
  "typescript": "^5.0.0"
78
78
  },
79
79
  "peerDependencies": {
80
- "@sanity/client": "^6.15.0",
80
+ "@sanity/client": "^6.15.0 || ^7.0.0",
81
81
  "next": "^14.0.0 || ^15.0.0 || ^16.0.0",
82
82
  "react": "^18.0.0 || ^19.0.0",
83
83
  "react-dom": "^18.0.0 || ^19.0.0"