@pallasoft/ps-utilities 2.4.0 → 2.6.0

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,30 @@
1
+ export declare const EmailPreviewConfig: {
2
+ readonly documentName: "email.html";
3
+ readonly documentContentType: "text/html";
4
+ readonly imageName: "email.png";
5
+ readonly imageContentType: "image/png";
6
+ readonly fallbackSubject: "Email";
7
+ readonly dateFormat: "D MMM YYYY, h:mm A";
8
+ readonly page: {
9
+ readonly width: 860;
10
+ readonly padding: 48;
11
+ readonly headerGap: 28;
12
+ readonly subjectSize: 22;
13
+ readonly metaSize: 13;
14
+ readonly bodySize: 15;
15
+ readonly lineHeight: 24;
16
+ readonly maxLines: 140;
17
+ readonly minHeight: 320;
18
+ readonly charWidth: 7.4;
19
+ readonly subjectWidthRatio: 1.45;
20
+ readonly metaWidthRatio: 0.9;
21
+ readonly fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, 'DejaVu Sans', 'Liberation Sans', sans-serif";
22
+ readonly paperColour: "#ffffff";
23
+ readonly bandColour: "#0f9d58";
24
+ readonly bandHeight: 6;
25
+ readonly ruleColour: "#e4e8ee";
26
+ readonly subjectColour: "#101828";
27
+ readonly metaColour: "#667085";
28
+ readonly bodyColour: "#344054";
29
+ };
30
+ };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmailPreviewConfig = void 0;
4
+ exports.EmailPreviewConfig = {
5
+ documentName: 'email.html',
6
+ documentContentType: 'text/html',
7
+ imageName: 'email.png',
8
+ imageContentType: 'image/png',
9
+ fallbackSubject: 'Email',
10
+ dateFormat: 'D MMM YYYY, h:mm A',
11
+ page: {
12
+ width: 860,
13
+ padding: 48,
14
+ headerGap: 28,
15
+ subjectSize: 22,
16
+ metaSize: 13,
17
+ bodySize: 15,
18
+ lineHeight: 24,
19
+ maxLines: 140,
20
+ minHeight: 320,
21
+ charWidth: 7.4,
22
+ subjectWidthRatio: 1.45,
23
+ metaWidthRatio: 0.9,
24
+ fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, 'DejaVu Sans', 'Liberation Sans', sans-serif",
25
+ paperColour: '#ffffff',
26
+ bandColour: '#0f9d58',
27
+ bandHeight: 6,
28
+ ruleColour: '#e4e8ee',
29
+ subjectColour: '#101828',
30
+ metaColour: '#667085',
31
+ bodyColour: '#344054',
32
+ },
33
+ };
@@ -0,0 +1 @@
1
+ export * from './email-preview-config';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./email-preview-config"), exports);
@@ -1,18 +1,8 @@
1
- export interface EmailPreviewInput {
2
- from: string;
3
- html: string | null;
4
- receivedAt: string;
5
- subject: string | null;
6
- text: string | null;
7
- }
1
+ import type { EmailPreviewInput } from '../models/email-preview-input';
8
2
  export declare class EmailPreviewService {
9
- static readonly fileName = "email.html";
10
- static readonly contentType = "text/html";
11
- static readonly imageFileName = "email.png";
12
- static readonly imageContentType = "image/png";
13
- private static readonly page;
14
3
  static escape(value: string): string;
15
4
  static hasContent(input: EmailPreviewInput): boolean;
5
+ static receivedOf(input: EmailPreviewInput): string;
16
6
  static subjectOf(input: EmailPreviewInput): string;
17
7
  static toText(input: EmailPreviewInput): string;
18
8
  static toDocument(input: EmailPreviewInput): string;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EmailPreviewService = void 0;
4
+ var email_preview_config_1 = require("./constants/email-preview-config");
5
+ var date_service_1 = require("./date-service");
4
6
  var EmailPreviewService = /** @class */ (function () {
5
7
  function EmailPreviewService() {
6
8
  }
@@ -16,8 +18,13 @@ var EmailPreviewService = /** @class */ (function () {
16
18
  return ((input.html !== null && input.html.trim() !== '') ||
17
19
  (input.text !== null && input.text.trim() !== ''));
18
20
  };
21
+ EmailPreviewService.receivedOf = function (input) {
22
+ return date_service_1.DateService.formatDateInTimezone(input.receivedAt, input.timezone, email_preview_config_1.EmailPreviewConfig.dateFormat);
23
+ };
19
24
  EmailPreviewService.subjectOf = function (input) {
20
- return input.subject === null || input.subject.trim() === '' ? 'Email' : input.subject.trim();
25
+ return input.subject === null || input.subject.trim() === ''
26
+ ? email_preview_config_1.EmailPreviewConfig.fallbackSubject
27
+ : input.subject.trim();
21
28
  };
22
29
  EmailPreviewService.toText = function (input) {
23
30
  if (input.text !== null && input.text.trim() !== '')
@@ -31,22 +38,23 @@ var EmailPreviewService = /** @class */ (function () {
31
38
  var body = input.html !== null && input.html.trim() !== ''
32
39
  ? EmailPreviewService.body(input.html)
33
40
  : "<pre style=\"white-space:pre-wrap;font-family:inherit;margin:0;\">".concat(EmailPreviewService.escape(input.text === null ? '' : input.text), "</pre>");
34
- return "<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<meta charset=\"utf-8\" />\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n\t\t<title>".concat(EmailPreviewService.escape(subject), "</title>\n\t</head>\n\t<body style=\"margin:0;padding:24px;background:#f5f7fa;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;color:#101828;\">\n\t\t<div style=\"max-width:760px;margin:0 auto;background:#ffffff;border:1px solid #e4e8ee;border-radius:12px;overflow:hidden;\">\n\t\t\t<div style=\"padding:16px 20px;border-bottom:1px solid #e4e8ee;background:#f9fafb;\">\n\t\t\t\t<div style=\"font-size:15px;font-weight:700;\">").concat(EmailPreviewService.escape(subject), "</div>\n\t\t\t\t<div style=\"margin-top:4px;font-size:12px;color:#667085;\">From ").concat(EmailPreviewService.escape(input.from), " \u00B7 ").concat(EmailPreviewService.escape(input.receivedAt), "</div>\n\t\t\t</div>\n\t\t\t<div style=\"padding:20px;\">").concat(body, "</div>\n\t\t</div>\n\t</body>\n</html>");
41
+ return "<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<meta charset=\"utf-8\" />\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n\t\t<title>".concat(EmailPreviewService.escape(subject), "</title>\n\t</head>\n\t<body style=\"margin:0;padding:24px;background:#f5f7fa;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;color:#101828;\">\n\t\t<div style=\"max-width:760px;margin:0 auto;background:#ffffff;border:1px solid #e4e8ee;border-radius:12px;overflow:hidden;\">\n\t\t\t<div style=\"padding:16px 20px;border-bottom:1px solid #e4e8ee;background:#f9fafb;\">\n\t\t\t\t<div style=\"font-size:15px;font-weight:700;\">").concat(EmailPreviewService.escape(subject), "</div>\n\t\t\t\t<div style=\"margin-top:4px;font-size:12px;color:#667085;\">From ").concat(EmailPreviewService.escape(input.from), " \u00B7 ").concat(EmailPreviewService.escape(EmailPreviewService.receivedOf(input)), "</div>\n\t\t\t</div>\n\t\t\t<div style=\"padding:20px;\">").concat(body, "</div>\n\t\t</div>\n\t</body>\n</html>");
35
42
  };
36
43
  EmailPreviewService.toImageMarkup = function (input) {
37
- var page = EmailPreviewService.page;
38
- var subject = EmailPreviewService.subjectOf(input);
39
- var meta = "From ".concat(input.from, " \u00B7 ").concat(input.receivedAt);
44
+ var page = email_preview_config_1.EmailPreviewConfig.page;
40
45
  var width = page.width - page.padding * 2;
46
+ var subject = EmailPreviewService.clip(EmailPreviewService.subjectOf(input), Math.floor(width / (page.charWidth * page.subjectWidthRatio)));
47
+ var meta = EmailPreviewService.clip("From ".concat(input.from, " \u00B7 ").concat(EmailPreviewService.receivedOf(input)), Math.floor(width / (page.charWidth * page.metaWidthRatio)));
41
48
  var lines = EmailPreviewService.wrap(EmailPreviewService.toText(input), Math.floor(width / page.charWidth)).slice(0, page.maxLines);
42
- var bodyTop = page.padding + page.subjectSize + 10 + page.metaSize + page.headerGap;
49
+ var metaBaseline = page.padding + page.subjectSize + 10 + page.metaSize;
50
+ var bodyTop = metaBaseline + page.headerGap;
43
51
  var height = Math.max(page.minHeight, bodyTop + lines.length * page.lineHeight + page.padding);
44
52
  var body = lines
45
53
  .map(function (line, index) {
46
- return "<text x=\"".concat(page.padding, "\" y=\"").concat(bodyTop + index * page.lineHeight, "\" font-size=\"").concat(page.bodySize, "\" fill=\"#344054\">").concat(EmailPreviewService.escape(line), "</text>");
54
+ return "<text x=\"".concat(page.padding, "\" y=\"").concat(bodyTop + index * page.lineHeight, "\" font-size=\"").concat(page.bodySize, "\" fill=\"").concat(page.bodyColour, "\">").concat(EmailPreviewService.escape(line), "</text>");
47
55
  })
48
56
  .join('');
49
- return "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(page.width, "\" height=\"").concat(height, "\" viewBox=\"0 0 ").concat(page.width, " ").concat(height, "\" font-family=\"").concat(page.fontFamily, "\">\n\t<rect width=\"").concat(page.width, "\" height=\"").concat(height, "\" fill=\"#ffffff\" />\n\t<rect x=\"0\" y=\"0\" width=\"").concat(page.width, "\" height=\"6\" fill=\"#0f9d58\" />\n\t<text x=\"").concat(page.padding, "\" y=\"").concat(page.padding + page.subjectSize, "\" font-size=\"").concat(page.subjectSize, "\" font-weight=\"700\" fill=\"#101828\">").concat(EmailPreviewService.escape(EmailPreviewService.clip(subject, Math.floor(width / (page.charWidth * 1.45)))), "</text>\n\t<text x=\"").concat(page.padding, "\" y=\"").concat(page.padding + page.subjectSize + 10 + page.metaSize, "\" font-size=\"").concat(page.metaSize, "\" fill=\"#667085\">").concat(EmailPreviewService.escape(EmailPreviewService.clip(meta, Math.floor(width / (page.charWidth * 0.9)))), "</text>\n\t<line x1=\"").concat(page.padding, "\" y1=\"").concat(bodyTop - page.headerGap + 8, "\" x2=\"").concat(page.width - page.padding, "\" y2=\"").concat(bodyTop - page.headerGap + 8, "\" stroke=\"#e4e8ee\" stroke-width=\"1\" />\n\t").concat(body, "\n</svg>");
57
+ return "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(page.width, "\" height=\"").concat(height, "\" viewBox=\"0 0 ").concat(page.width, " ").concat(height, "\" font-family=\"").concat(page.fontFamily, "\">\n\t<rect width=\"").concat(page.width, "\" height=\"").concat(height, "\" fill=\"").concat(page.paperColour, "\" />\n\t<rect x=\"0\" y=\"0\" width=\"").concat(page.width, "\" height=\"").concat(page.bandHeight, "\" fill=\"").concat(page.bandColour, "\" />\n\t<text x=\"").concat(page.padding, "\" y=\"").concat(page.padding + page.subjectSize, "\" font-size=\"").concat(page.subjectSize, "\" font-weight=\"700\" fill=\"").concat(page.subjectColour, "\">").concat(EmailPreviewService.escape(subject), "</text>\n\t<text x=\"").concat(page.padding, "\" y=\"").concat(metaBaseline, "\" font-size=\"").concat(page.metaSize, "\" fill=\"").concat(page.metaColour, "\">").concat(EmailPreviewService.escape(meta), "</text>\n\t<line x1=\"").concat(page.padding, "\" y1=\"").concat(metaBaseline + 8, "\" x2=\"").concat(page.width - page.padding, "\" y2=\"").concat(metaBaseline + 8, "\" stroke=\"").concat(page.ruleColour, "\" stroke-width=\"1\" />\n\t").concat(body, "\n</svg>");
50
58
  };
51
59
  EmailPreviewService.clip = function (value, limit) {
52
60
  return value.length <= limit ? value : "".concat(value.slice(0, Math.max(limit - 1, 1)), "\u2026");
@@ -117,23 +125,6 @@ var EmailPreviewService = /** @class */ (function () {
117
125
  var inner = withoutScripts.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
118
126
  return inner === null ? withoutScripts : inner[1];
119
127
  };
120
- EmailPreviewService.fileName = 'email.html';
121
- EmailPreviewService.contentType = 'text/html';
122
- EmailPreviewService.imageFileName = 'email.png';
123
- EmailPreviewService.imageContentType = 'image/png';
124
- EmailPreviewService.page = {
125
- width: 860,
126
- padding: 48,
127
- headerGap: 28,
128
- subjectSize: 22,
129
- metaSize: 13,
130
- bodySize: 15,
131
- lineHeight: 24,
132
- maxLines: 140,
133
- minHeight: 520,
134
- charWidth: 7.4,
135
- fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, 'DejaVu Sans', 'Liberation Sans', sans-serif",
136
- };
137
128
  return EmailPreviewService;
138
129
  }());
139
130
  exports.EmailPreviewService = EmailPreviewService;
@@ -1,4 +1,5 @@
1
1
  export * from './color-service';
2
+ export * from './constants';
2
3
  export * from './crypto-service';
3
4
  export * from './email-preview-service';
4
5
  export * from './encrypted-fields-service';
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./color-service"), exports);
18
+ __exportStar(require("./constants"), exports);
18
19
  __exportStar(require("./crypto-service"), exports);
19
20
  __exportStar(require("./email-preview-service"), exports);
20
21
  __exportStar(require("./encrypted-fields-service"), exports);
package/dist/index.d.ts CHANGED
@@ -2,5 +2,6 @@ import * as ClientNamespace from './client';
2
2
  import * as CommonNamespace from './common';
3
3
  export declare const Common: typeof CommonNamespace;
4
4
  export declare const Client: typeof ClientNamespace;
5
+ export type { EmailPreviewInput } from './models/email-preview-input';
5
6
  export type { EncryptedFieldsSpec } from './common/encrypted-fields-service';
6
7
  export type { DataKeyPair } from './common/envelope-crypto-service';
@@ -0,0 +1,8 @@
1
+ export interface EmailPreviewInput {
2
+ from: string;
3
+ html: string | null;
4
+ receivedAt: string;
5
+ subject: string | null;
6
+ timezone: string;
7
+ text: string | null;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-utilities",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",