@cripty2001/utils 0.0.59 → 0.0.61
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/dist/MailTemplate/image.d.ts +10 -0
- package/dist/MailTemplate/image.js +37 -0
- package/dist/MailTemplate/index.d.ts +31 -0
- package/dist/MailTemplate/index.js +91 -0
- package/dist/MailTemplate/raw.d.ts +7 -0
- package/dist/MailTemplate/raw.js +12 -0
- package/dist/MailTemplate/text.d.ts +13 -0
- package/dist/MailTemplate/text.js +28 -0
- package/package.json +14 -7
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Static } from "@cripty2001/utils/appserver/server";
|
|
2
|
+
export declare const SCHEMA: import("@sinclair/typebox").TObject<{
|
|
3
|
+
type: import("@sinclair/typebox").TLiteral<"image">;
|
|
4
|
+
mobile: import("@sinclair/typebox").TString;
|
|
5
|
+
desktop: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
6
|
+
link: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
7
|
+
alt: import("@sinclair/typebox").TString;
|
|
8
|
+
}>;
|
|
9
|
+
export type T = Static<typeof SCHEMA>;
|
|
10
|
+
export declare function build(config: T): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SCHEMA = void 0;
|
|
4
|
+
exports.build = build;
|
|
5
|
+
const server_1 = require("@cripty2001/utils/appserver/server");
|
|
6
|
+
exports.SCHEMA = server_1.Type.Object({
|
|
7
|
+
type: server_1.Type.Literal("image"),
|
|
8
|
+
mobile: server_1.Type.String(),
|
|
9
|
+
desktop: server_1.Type.Union([server_1.Type.String(), server_1.Type.Null()]),
|
|
10
|
+
link: server_1.Type.Union([server_1.Type.String(), server_1.Type.Null()]),
|
|
11
|
+
alt: server_1.Type.String()
|
|
12
|
+
});
|
|
13
|
+
function build(config) {
|
|
14
|
+
const img = (breakpoint, url) => `
|
|
15
|
+
<mj-image
|
|
16
|
+
css-class="${breakpoint ?? ''}"
|
|
17
|
+
src="${url}"
|
|
18
|
+
alt="${config.alt}"
|
|
19
|
+
${config.link ? `href="${config.link}"` : ''}
|
|
20
|
+
padding="0"
|
|
21
|
+
/>
|
|
22
|
+
`;
|
|
23
|
+
const imgs = config.desktop === null ?
|
|
24
|
+
img(null, config.mobile) :
|
|
25
|
+
[
|
|
26
|
+
img("onlyDesktop", config.desktop),
|
|
27
|
+
img("onlyMobile", config.mobile)
|
|
28
|
+
].join('\n');
|
|
29
|
+
const toReturn = `
|
|
30
|
+
<mj-section padding="0">
|
|
31
|
+
<mj-column width="100%" padding="0">
|
|
32
|
+
${imgs}
|
|
33
|
+
</mj-column>
|
|
34
|
+
</mj-section>
|
|
35
|
+
`;
|
|
36
|
+
return toReturn;
|
|
37
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Static } from "@cripty2001/utils/appserver/server";
|
|
2
|
+
export declare const TEMPLATE_SCHEMA: import("@sinclair/typebox").TObject<{
|
|
3
|
+
style: import("@sinclair/typebox").TObject<{
|
|
4
|
+
font: import("@sinclair/typebox").TString;
|
|
5
|
+
backgroundColor: import("@sinclair/typebox").TString;
|
|
6
|
+
textColor: import("@sinclair/typebox").TString;
|
|
7
|
+
}>;
|
|
8
|
+
content: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
9
|
+
type: import("@sinclair/typebox").TLiteral<"image">;
|
|
10
|
+
mobile: import("@sinclair/typebox").TString;
|
|
11
|
+
desktop: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
12
|
+
link: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>;
|
|
13
|
+
alt: import("@sinclair/typebox").TString;
|
|
14
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
15
|
+
type: import("@sinclair/typebox").TLiteral<"text">;
|
|
16
|
+
size: import("@sinclair/typebox").TNumber;
|
|
17
|
+
weight: import("@sinclair/typebox").TNumber;
|
|
18
|
+
color: import("@sinclair/typebox").TString;
|
|
19
|
+
padding: import("@sinclair/typebox").TObject<{
|
|
20
|
+
top: import("@sinclair/typebox").TNumber;
|
|
21
|
+
}>;
|
|
22
|
+
content: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
|
23
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
24
|
+
type: import("@sinclair/typebox").TLiteral<"raw">;
|
|
25
|
+
data: import("@sinclair/typebox").TString;
|
|
26
|
+
}>]>>;
|
|
27
|
+
}>;
|
|
28
|
+
export type Template = Static<typeof TEMPLATE_SCHEMA>;
|
|
29
|
+
export declare function genBuilder<T extends any>(config: Template): (params: T) => {
|
|
30
|
+
html: string;
|
|
31
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TEMPLATE_SCHEMA = void 0;
|
|
7
|
+
exports.genBuilder = genBuilder;
|
|
8
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
9
|
+
const mjml_1 = __importDefault(require("mjml"));
|
|
10
|
+
const server_1 = require("@cripty2001/utils/appserver/server");
|
|
11
|
+
const image_js_1 = require("./image.js");
|
|
12
|
+
const raw_js_1 = require("./raw.js");
|
|
13
|
+
const text_js_1 = require("./text.js");
|
|
14
|
+
exports.TEMPLATE_SCHEMA = server_1.Type.Object({
|
|
15
|
+
style: server_1.Type.Object({
|
|
16
|
+
font: server_1.Type.String(),
|
|
17
|
+
backgroundColor: server_1.Type.String(),
|
|
18
|
+
textColor: server_1.Type.String()
|
|
19
|
+
}),
|
|
20
|
+
content: server_1.Type.Array(server_1.Type.Union([
|
|
21
|
+
image_js_1.SCHEMA,
|
|
22
|
+
text_js_1.SCHEMA,
|
|
23
|
+
raw_js_1.SCHEMA
|
|
24
|
+
]))
|
|
25
|
+
});
|
|
26
|
+
function genBuilder(config) {
|
|
27
|
+
const mappedContent = config.content
|
|
28
|
+
.map(item => {
|
|
29
|
+
switch (item.type) {
|
|
30
|
+
case "image":
|
|
31
|
+
return (0, image_js_1.build)(item);
|
|
32
|
+
case "raw":
|
|
33
|
+
return (0, raw_js_1.build)(item);
|
|
34
|
+
case "text":
|
|
35
|
+
return (0, text_js_1.build)(item);
|
|
36
|
+
default:
|
|
37
|
+
// @ts-expect-error Should never happen
|
|
38
|
+
throw new Error(`Invalid type ${item.type}`);
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
.join('\n');
|
|
42
|
+
const builder = handlebars_1.default.compile(`
|
|
43
|
+
<mjml>
|
|
44
|
+
<mj-head>
|
|
45
|
+
<mj-style>
|
|
46
|
+
.onlyMobile {
|
|
47
|
+
display: none !important;
|
|
48
|
+
}
|
|
49
|
+
.onlyDesktop {
|
|
50
|
+
display: block !important;
|
|
51
|
+
}
|
|
52
|
+
@media only screen and (max-width: 500px) {
|
|
53
|
+
.onlyMobile {
|
|
54
|
+
display: block !important;
|
|
55
|
+
}
|
|
56
|
+
.onlyDesktop {
|
|
57
|
+
display: none !important;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
</mj-style>
|
|
61
|
+
|
|
62
|
+
<mj-attributes>
|
|
63
|
+
<mj-all
|
|
64
|
+
font-family="${config.style.font}, Arial, Helvetica, sans-serif"
|
|
65
|
+
/>
|
|
66
|
+
<mj-text
|
|
67
|
+
font-size="18px"
|
|
68
|
+
line-height="1.5"
|
|
69
|
+
color="${config.style.textColor}"
|
|
70
|
+
/>
|
|
71
|
+
<mj-body width="700px" />
|
|
72
|
+
<mj-section width="700px" padding="0" />
|
|
73
|
+
</mj-attributes>
|
|
74
|
+
</mj-head>
|
|
75
|
+
|
|
76
|
+
<mj-body background-color="${config.style.backgroundColor}">
|
|
77
|
+
${mappedContent}
|
|
78
|
+
</mj-body>
|
|
79
|
+
</mjml>
|
|
80
|
+
`);
|
|
81
|
+
return (data) => {
|
|
82
|
+
let { html, errors } = (0, mjml_1.default)(builder(data), {
|
|
83
|
+
validationLevel: 'soft'
|
|
84
|
+
});
|
|
85
|
+
if (errors.length > 0)
|
|
86
|
+
throw new Error(`Invalid template: ${errors.map(e => e.message).join(', ')}`);
|
|
87
|
+
return {
|
|
88
|
+
html: html,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Static } from "@cripty2001/utils/appserver/server";
|
|
2
|
+
export declare const SCHEMA: import("@sinclair/typebox").TObject<{
|
|
3
|
+
type: import("@sinclair/typebox").TLiteral<"raw">;
|
|
4
|
+
data: import("@sinclair/typebox").TString;
|
|
5
|
+
}>;
|
|
6
|
+
export type T = Static<typeof SCHEMA>;
|
|
7
|
+
export declare function build(config: T): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SCHEMA = void 0;
|
|
4
|
+
exports.build = build;
|
|
5
|
+
const server_1 = require("@cripty2001/utils/appserver/server");
|
|
6
|
+
exports.SCHEMA = server_1.Type.Object({
|
|
7
|
+
type: server_1.Type.Literal("raw"),
|
|
8
|
+
data: server_1.Type.String()
|
|
9
|
+
});
|
|
10
|
+
function build(config) {
|
|
11
|
+
return config.data;
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Static } from "@cripty2001/utils/appserver/server";
|
|
2
|
+
export declare const SCHEMA: import("@sinclair/typebox").TObject<{
|
|
3
|
+
type: import("@sinclair/typebox").TLiteral<"text">;
|
|
4
|
+
size: import("@sinclair/typebox").TNumber;
|
|
5
|
+
weight: import("@sinclair/typebox").TNumber;
|
|
6
|
+
color: import("@sinclair/typebox").TString;
|
|
7
|
+
padding: import("@sinclair/typebox").TObject<{
|
|
8
|
+
top: import("@sinclair/typebox").TNumber;
|
|
9
|
+
}>;
|
|
10
|
+
content: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
|
11
|
+
}>;
|
|
12
|
+
export type T = Static<typeof SCHEMA>;
|
|
13
|
+
export declare function build(config: T): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SCHEMA = void 0;
|
|
4
|
+
exports.build = build;
|
|
5
|
+
const server_1 = require("@cripty2001/utils/appserver/server");
|
|
6
|
+
exports.SCHEMA = server_1.Type.Object({
|
|
7
|
+
type: server_1.Type.Literal("text"),
|
|
8
|
+
size: server_1.Type.Number(),
|
|
9
|
+
weight: server_1.Type.Number(),
|
|
10
|
+
color: server_1.Type.String(),
|
|
11
|
+
padding: server_1.Type.Object({
|
|
12
|
+
top: server_1.Type.Number()
|
|
13
|
+
}),
|
|
14
|
+
content: server_1.Type.Array(server_1.Type.String())
|
|
15
|
+
});
|
|
16
|
+
function build(config) {
|
|
17
|
+
return `
|
|
18
|
+
<mj-section padding="0">
|
|
19
|
+
<mj-column width="100%" padding-top="${config.padding.top}px">
|
|
20
|
+
${config.content.map(item => `
|
|
21
|
+
<mj-text font-size="${config.size}px" font-weight="${config.weight}" color="${config.color}">
|
|
22
|
+
${item}
|
|
23
|
+
</mj-text>
|
|
24
|
+
`).join('')}
|
|
25
|
+
</mj-column>
|
|
26
|
+
</mj-section>
|
|
27
|
+
`;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cripty2001/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
|
|
5
5
|
"homepage": "https://github.com/cripty2001/utils#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -21,24 +21,27 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@cripty2001/whispr": "^0.2.0",
|
|
26
|
+
"lodash": "^4.17.21"
|
|
27
|
+
},
|
|
24
28
|
"devDependencies": {
|
|
25
29
|
"@types/express": "^5.0.5",
|
|
30
|
+
"@types/lodash": "^4.17.21",
|
|
31
|
+
"@types/mjml": "^4.7.4",
|
|
26
32
|
"@types/node": "^24.9.1",
|
|
27
33
|
"@types/react": "^19",
|
|
28
34
|
"react": "^19",
|
|
29
35
|
"typescript": "^5.9.3"
|
|
30
36
|
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@cripty2001/whispr": "^0.2.0",
|
|
33
|
-
"@types/lodash": "^4.17.20",
|
|
34
|
-
"lodash": "^4.17.21"
|
|
35
|
-
},
|
|
36
37
|
"peerDependencies": {
|
|
37
|
-
"lucide-react": "^0.552.0",
|
|
38
38
|
"@msgpack/msgpack": "^3.1.2",
|
|
39
39
|
"@sinclair/typebox": "^0.34.41",
|
|
40
40
|
"dotenv": "^17.2.3",
|
|
41
41
|
"express": "^5.1.0",
|
|
42
|
+
"handlebars": "^4.7.8",
|
|
43
|
+
"lucide-react": "^0.552.0",
|
|
44
|
+
"mjml": "^4.17.1",
|
|
42
45
|
"react": "^19"
|
|
43
46
|
},
|
|
44
47
|
"peerDependenciesMeta": {
|
|
@@ -74,6 +77,10 @@
|
|
|
74
77
|
"./appserver/client": {
|
|
75
78
|
"import": "./dist/Appserver/client.js",
|
|
76
79
|
"types": "./dist/Appserver/client.d.ts"
|
|
80
|
+
},
|
|
81
|
+
"./mail-template": {
|
|
82
|
+
"import": "./dist/MailTemplate/index.js",
|
|
83
|
+
"types": "./dist/MailTemplate/index.d.ts"
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
86
|
}
|