@vrplatform/email 1.0.2-stage.557 → 1.0.2-stage.573
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/build/main/components/ActionEmailTemplate.js +1 -3
- package/build/main/components/ActionEmailTemplate.js.map +1 -1
- package/build/main/components/EmailContainer.d.ts +3 -1
- package/build/main/components/EmailContainer.js +3 -3
- package/build/main/components/EmailContainer.js.map +1 -1
- package/build/main/types.d.ts +1 -0
- package/build/main/types.js.map +1 -1
- package/build/main/utils/find-postmark-email.d.ts +2 -2
- package/build/main/utils/find-postmark-email.js +19 -30
- package/build/main/utils/find-postmark-email.js.map +1 -1
- package/build/main/utils/index.d.ts +0 -1
- package/build/main/utils/index.js +0 -1
- package/build/main/utils/index.js.map +1 -1
- package/build/main/utils/send-email.d.ts +7 -0
- package/build/main/utils/send-email.js +37 -34
- package/build/main/utils/send-email.js.map +1 -1
- package/build/module/components/ActionEmailTemplate.js +1 -3
- package/build/module/components/ActionEmailTemplate.js.map +1 -1
- package/build/module/components/EmailContainer.d.ts +3 -1
- package/build/module/components/EmailContainer.js +3 -3
- package/build/module/components/EmailContainer.js.map +1 -1
- package/build/module/types.d.ts +1 -0
- package/build/module/types.js.map +1 -1
- package/build/module/utils/find-postmark-email.d.ts +2 -2
- package/build/module/utils/find-postmark-email.js +19 -30
- package/build/module/utils/find-postmark-email.js.map +1 -1
- package/build/module/utils/index.d.ts +0 -1
- package/build/module/utils/index.js +0 -1
- package/build/module/utils/index.js.map +1 -1
- package/build/module/utils/send-email.d.ts +7 -0
- package/build/module/utils/send-email.js +36 -34
- package/build/module/utils/send-email.js.map +1 -1
- package/package.json +3 -2
- package/src/components/ActionEmailTemplate.tsx +1 -3
- package/src/components/EmailContainer.tsx +9 -3
- package/src/types.ts +1 -0
- package/src/utils/find-postmark-email.ts +23 -36
- package/src/utils/index.ts +0 -1
- package/src/utils/send-email.ts +45 -38
|
@@ -8,9 +8,7 @@ const EmailContainer_1 = require("./EmailContainer");
|
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
const Button_1 = require("./Button");
|
|
10
10
|
const ActionEmailTemplate = ({ data, tenant, themeColors, mode, user, listing, month, }) => {
|
|
11
|
-
return ((0, jsx_runtime_1.jsxs)(EmailContainer_1.EmailContainer, { title: data.subject, shortDescription: data.shortDescription, tenant: {
|
|
12
|
-
logo: tenant.logo,
|
|
13
|
-
}, mode: mode, children: [(0, jsx_runtime_1.jsx)(heading_1.Heading, { style: {
|
|
11
|
+
return ((0, jsx_runtime_1.jsxs)(EmailContainer_1.EmailContainer, { title: data.subject, shortDescription: data.shortDescription, tenant: tenant, mode: mode, children: [(0, jsx_runtime_1.jsx)(heading_1.Heading, { style: {
|
|
14
12
|
fontSize: 28,
|
|
15
13
|
fontWeight: 600,
|
|
16
14
|
marginBottom: '50px',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionEmailTemplate.js","sourceRoot":"src/","sources":["components/ActionEmailTemplate.tsx"],"names":[],"mappings":";;;;AAAA,kDAA+C;AAC/C,4CAAyC;AACzC,qDAAkD;AAElD,mCAAyC;AACzC,qCAAkC;AAiB3B,MAAM,mBAAmB,GAAG,CAAC,EAClC,IAAI,EACJ,MAAM,EACN,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,KAAK,GACoB,EAAE,EAAE;IAC7B,OAAO,CACL,wBAAC,+BAAc,IACb,KAAK,EAAE,IAAI,CAAC,OAAO,EACnB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EACvC,MAAM,EAAE
|
|
1
|
+
{"version":3,"file":"ActionEmailTemplate.js","sourceRoot":"src/","sources":["components/ActionEmailTemplate.tsx"],"names":[],"mappings":";;;;AAAA,kDAA+C;AAC/C,4CAAyC;AACzC,qDAAkD;AAElD,mCAAyC;AACzC,qCAAkC;AAiB3B,MAAM,mBAAmB,GAAG,CAAC,EAClC,IAAI,EACJ,MAAM,EACN,WAAW,EACX,IAAI,EAC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EAAE;wBACnC,IAAI,EAAE,IAAI,CAAC,IAAI;wBACf,QAAQ,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;wBAC9B,IAAI,EAAE,KAAK,IAAI,EAAE;wBACjB,WAAW,EAAE,OAAO,IAAI,EAAE;qBAC3B,CAAC;iBACH,GACD,IACa,CAClB,CAAC;AACJ,CAAC,CAAC;AAxEW,QAAA,mBAAmB,uBAwE9B","sourcesContent":["import { Heading } from '@react-email/heading';\nimport { Text } from '@react-email/text';\nimport { EmailContainer } from './EmailContainer';\nimport type { EmailBaseProps } from '../types';\nimport { parseEmailHtml } from './utils';\nimport { Button } from './Button';\n\nexport type ActionEmailData = {\n subject: string;\n shortDescription: string;\n banner?: string;\n header: string;\n bodyOne: string;\n bodyTwo: string;\n href: string;\n buttonText: string;\n};\n\nexport interface ActionEmailTemplateProps extends EmailBaseProps {\n data: ActionEmailData;\n}\n\nexport const ActionEmailTemplate = ({\n data,\n tenant,\n themeColors,\n mode,\n user,\n listing,\n month,\n}: ActionEmailTemplateProps) => {\n return (\n <EmailContainer\n title={data.subject}\n shortDescription={data.shortDescription}\n tenant={tenant}\n mode={mode}\n >\n <Heading\n style={{\n fontSize: 28,\n fontWeight: 600,\n marginBottom: '50px',\n }}\n >\n {data.header?.trim() || `Welcome to ${tenant.name}!`}\n </Heading>\n\n {data.banner?.trim() && (\n <Text\n style={{\n padding: '24px',\n backgroundColor: '#f2f3f3',\n borderRadius: '4px',\n marginBottom: '40px',\n }}\n >\n {data.banner.trim()}\n </Text>\n )}\n\n <div\n // biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>\n dangerouslySetInnerHTML={{\n __html: parseEmailHtml(data.bodyOne, {\n href: data.href,\n userName: user.firstName || '',\n date: month || '',\n listingName: listing || '',\n }),\n }}\n />\n\n <Button\n href={data.href}\n mode={mode}\n data-testid=\"accept-invite-button\"\n label={data.buttonText?.trim() || 'Accept Invitation'}\n themeColors={themeColors}\n />\n\n <div\n // biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>\n dangerouslySetInnerHTML={{\n __html: parseEmailHtml(data.bodyTwo, {\n href: data.href,\n userName: user.firstName || '',\n date: month || '',\n listingName: listing || '',\n }),\n }}\n />\n </EmailContainer>\n );\n};\n"]}
|
|
@@ -2,7 +2,9 @@ import type { EmailBaseProps } from '../types';
|
|
|
2
2
|
type Props = {
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
title: string;
|
|
5
|
-
tenant: Omit<EmailBaseProps['tenant'], 'name'
|
|
5
|
+
tenant: Omit<EmailBaseProps['tenant'], 'name'> & {
|
|
6
|
+
name?: string;
|
|
7
|
+
};
|
|
6
8
|
mode: EmailBaseProps['mode'];
|
|
7
9
|
shortDescription?: string;
|
|
8
10
|
};
|
|
@@ -31,7 +31,7 @@ const EmailContainer = (props) => {
|
|
|
31
31
|
}, fontWeight: 600, fontStyle: "normal" })] }), shortDescription && (0, jsx_runtime_1.jsx)(preview_1.Preview, { children: shortDescription }), (0, jsx_runtime_1.jsx)(body_1.Body, { style: contentWrapperStyle, children: (0, jsx_runtime_1.jsx)(Content, { ...props, children: children }) })] }));
|
|
32
32
|
};
|
|
33
33
|
exports.EmailContainer = EmailContainer;
|
|
34
|
-
const Content = ({ children, tenant: { logo: tenantLogo }, mode }) => {
|
|
34
|
+
const Content = ({ children, tenant: { logo: tenantLogo, name, showPlatformBranding = true }, mode, }) => {
|
|
35
35
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [tenantLogo ? ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
36
36
|
marginBottom: '60px',
|
|
37
37
|
padding: '5px',
|
|
@@ -41,9 +41,9 @@ const Content = ({ children, tenant: { logo: tenantLogo }, mode }) => {
|
|
|
41
41
|
display: 'flex',
|
|
42
42
|
justifyContent: 'center',
|
|
43
43
|
alignItems: 'center',
|
|
44
|
-
}, children: (0, jsx_runtime_1.jsx)(img_1.Img, { src: tenantLogo, alt: 'Logo', width: 70 }) })) : mode === 'send' ? ((0, jsx_runtime_1.jsx)(img_1.Img, { src: 'https://staging.portal.vrplatform.app/logo.png', alt: 'Logo', width: 70, style: { marginBottom: '60px' } })) : ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
44
|
+
}, children: (0, jsx_runtime_1.jsx)(img_1.Img, { src: tenantLogo, alt: 'Logo', width: 70 }) })) : !showPlatformBranding ? ((0, jsx_runtime_1.jsx)(text_1.Text, { children: name })) : mode === 'send' ? ((0, jsx_runtime_1.jsx)(img_1.Img, { src: 'https://staging.portal.vrplatform.app/logo.png', alt: 'Logo', width: 70, style: { marginBottom: '60px' } })) : ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
45
45
|
width: '60px',
|
|
46
|
-
}, children: (0, jsx_runtime_1.jsx)(VrpLogo, {}) })), children, (0, jsx_runtime_1.jsx)(Footer, {})] }));
|
|
46
|
+
}, children: (0, jsx_runtime_1.jsx)(VrpLogo, {}) })), children, showPlatformBranding ? (0, jsx_runtime_1.jsx)(Footer, {}) : (0, jsx_runtime_1.jsx)(text_1.Text, { children: name })] }));
|
|
47
47
|
};
|
|
48
48
|
const Footer = () => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(hr_1.Hr, { style: {
|
|
49
49
|
marginTop: '30px',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailContainer.js","sourceRoot":"src/","sources":["components/EmailContainer.tsx"],"names":[],"mappings":";;;;AAAA,4CAAyC;AACzC,4CAAyC;AACzC,4CAAyC;AACzC,wCAAqC;AACrC,4CAAyC;AACzC,0CAAuC;AACvC,kDAA+C;AAC/C,4CAAyC;AACzC,6CAAwC;AAWjC,MAAM,cAAc,GAAG,CAAC,KAAY,EAAE,EAAE;IAC7C,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAEpD,MAAM,mBAAmB,GAAG;QAC1B,aAAa,EAAE,MAAM;QACrB,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aACjB,wBAEE,IAAA,WAAG,GAAE,CAAC,IAAI,EAAE,8CACV,EACP,uBAAC,WAAI,IACH,KAAK,EAAE;gBACL,KAAK,EAAE,SAAS;aACjB,4IAII,IACN,CACJ,CAAC;AAEF,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CACpB,iCACE,KAAK,EAAC,MAAM,EACZ,MAAM,EAAC,MAAM,EACb,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,KAAK,EAAC,4BAA4B,aAElC,iCACE,CAAC,EAAC,mNAAmN,EACrN,IAAI,EAAC,SAAS,GACd,EACF,iCACE,CAAC,EAAC,gUAAgU,EAClU,IAAI,EAAC,SAAS,EACd,WAAW,EAAC,KAAK,GACjB,EACF,iCACE,CAAC,EAAC,4WAA4W,EAC9W,IAAI,EAAC,SAAS,GACd,IACE,CACP,CAAC","sourcesContent":["import { Body } from '@react-email/body';\nimport { Font } from '@react-email/font';\nimport { Head } from '@react-email/head';\nimport { Hr } from '@react-email/hr';\nimport { Html } from '@react-email/html';\nimport { Img } from '@react-email/img';\nimport { Preview } from '@react-email/preview';\nimport { Text } from '@react-email/text';\nimport { day } from '@vrplatform/utils';\nimport type { EmailBaseProps } from '../types';\n\ntype Props = {\n children: React.ReactNode;\n title: string;\n tenant: Omit<EmailBaseProps['tenant'], 'name'> & { name?: string };\n mode: EmailBaseProps['mode'];\n shortDescription?: string;\n};\n\nexport const EmailContainer = (props: Props) => {\n const { children, shortDescription, title } = props;\n\n const contentWrapperStyle = {\n paddingInline: '20px',\n paddingBlock: '10px',\n maxWidth: '500px',\n margin: '0 auto',\n };\n\n if (props.mode !== 'send') {\n return (\n <div style={contentWrapperStyle}>\n <Content {...props}>{children}</Content>\n </div>\n );\n }\n\n return (\n <Html lang=\"en\">\n <Head>\n <title>{title}</title>\n <Font\n fontFamily=\"Inter\"\n fallbackFontFamily=\"Verdana\"\n webFont={{\n url: 'https://fonts.gstatic.com/s/inter/v13/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7W0Q5nw.woff2',\n format: 'woff2',\n }}\n fontWeight={400}\n fontStyle=\"normal\"\n />\n <Font\n fontFamily=\"Inter\"\n fallbackFontFamily=\"Verdana\"\n webFont={{\n url: 'https://fonts.gstatic.com/s/inter/v13/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7W0Q5nw.woff2',\n format: 'woff2',\n }}\n fontWeight={600}\n fontStyle=\"normal\"\n />\n </Head>\n {shortDescription && <Preview>{shortDescription}</Preview>}\n <Body style={contentWrapperStyle}>\n <Content {...props}>{children}</Content>\n </Body>\n </Html>\n );\n};\n\nconst Content = ({\n children,\n tenant: { logo: tenantLogo, name, showPlatformBranding = true },\n mode,\n}: Props) => {\n return (\n <>\n {tenantLogo ? (\n <div\n style={{\n marginBottom: '60px',\n padding: '5px',\n // border: '1px solid rgb(233,236,239)',\n borderRadius: '5px',\n width: '80px',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n }}\n >\n <Img src={tenantLogo} alt={'Logo'} width={70} />\n </div>\n ) : !showPlatformBranding ? (\n <Text>{name}</Text>\n ) : mode === 'send' ? (\n <Img\n src={'https://staging.portal.vrplatform.app/logo.png'}\n alt={'Logo'}\n width={70}\n style={{ marginBottom: '60px' }}\n />\n ) : (\n <div\n style={{\n width: '60px',\n }}\n >\n <VrpLogo />\n </div>\n )}\n\n {children}\n\n {showPlatformBranding ? <Footer /> : <Text>{name}</Text>}\n </>\n );\n};\n\nconst Footer = () => (\n <>\n <Hr\n style={{\n marginTop: '30px',\n marginBottom: '50px',\n }}\n />\n\n <Text\n style={{\n color: '#737373',\n }}\n >\n © {day().year()} VR Technologies. All rights reserved.\n </Text>\n <Text\n style={{\n color: '#737373',\n }}\n >\n VR Technologies, LLC, a company incorporated and registered in the United\n States of America with company number 20201965158\n </Text>\n </>\n);\n\nconst VrpLogo = () => (\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox=\"0 0 28 29\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M18.2549 8.25161C18.2549 5.89704 20.1636 3.98828 22.5182 3.98828C24.8728 3.98828 26.7815 5.89704 26.7815 8.25161C26.7815 10.6062 24.8728 12.5149 22.5182 12.5149C20.1636 12.5149 18.2549 10.6062 18.2549 8.25161Z\"\n fill=\"#172554\"\n />\n <path\n d=\"M7.02441 8.46593C7.02441 6.01867 9.20858 3.99805 11.6558 3.99805C14.1031 3.99805 15.0558 5.59785 16.5612 7.52728C17.1957 8.34054 20.7921 13.3413 20.7921 13.3413C20.7921 13.3413 21.566 14.6863 21.566 15.7894C21.566 18.5287 17.1993 22.8381 17.1993 22.8381L7.66841 10.6799C7.66841 10.6799 7.02441 10.0502 7.02441 8.46593Z\"\n fill=\"#172554\"\n fillOpacity=\"0.8\"\n />\n <path\n d=\"M1.24707 8.42687C1.24707 5.97961 3.43123 3.95898 5.8785 3.95898C8.32576 3.95898 9.27845 5.55879 10.7839 7.48824C11.4184 8.30147 14.6041 12.4888 16.8247 15.5727C18.3585 17.703 18.474 17.705 18.474 20.3439C18.474 22.9827 15.1592 24.1379 14.1483 24.1914C12.0203 24.304 10.5418 22.4681 10.5418 22.4681L1.89106 10.6408C1.89106 10.6408 1.24707 10.0111 1.24707 8.42687Z\"\n fill=\"#172554\"\n />\n </svg>\n);\n"]}
|
package/build/main/types.d.ts
CHANGED
package/build/main/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["export type EmailBaseProps = {\n mode: 'edit' | 'preview' | 'send';\n tenant: {\n name: string;\n logo: string | undefined | null;\n };\n listing: string | undefined;\n month: string | undefined;\n user: {\n firstName: string | undefined;\n };\n themeColors: readonly [\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n ...string[],\n ];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["export type EmailBaseProps = {\n mode: 'edit' | 'preview' | 'send';\n tenant: {\n name: string;\n showPlatformBranding?: boolean;\n logo: string | undefined | null;\n };\n listing: string | undefined;\n month: string | undefined;\n user: {\n firstName: string | undefined;\n };\n themeColors: readonly [\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n ...string[],\n ];\n};\n"]}
|
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findPostmarkEmail = findPostmarkEmail;
|
|
4
4
|
const utils_1 = require("@vrplatform/utils");
|
|
5
|
+
const zod_1 = require("zod");
|
|
5
6
|
const send_email_1 = require("./send-email");
|
|
7
|
+
const postmarkMessagesResponseSchema = zod_1.z.object({
|
|
8
|
+
TotalCount: zod_1.z.number().int().nonnegative(),
|
|
9
|
+
Messages: zod_1.z.array(zod_1.z.object({
|
|
10
|
+
MessageID: zod_1.z.string().min(1),
|
|
11
|
+
ReceivedAt: zod_1.z.string().refine((value) => (0, utils_1.day)(value).isValid()),
|
|
12
|
+
Metadata: zod_1.z.object({ deliveryId: zod_1.z.string() }).passthrough(),
|
|
13
|
+
})),
|
|
14
|
+
});
|
|
6
15
|
async function findPostmarkEmail(deliveryId, options) {
|
|
7
16
|
if (!options.postmarkToken) {
|
|
8
17
|
throw new send_email_1.EmailDeliveryError('Postmark is not configured', undefined, false, false);
|
|
@@ -27,40 +36,20 @@ async function findPostmarkEmail(deliveryId, options) {
|
|
|
27
36
|
httpStatus: response.status,
|
|
28
37
|
}, false, response.status === 429 || response.status >= 500);
|
|
29
38
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
!('TotalCount' in providerResponse) ||
|
|
33
|
-
typeof providerResponse.TotalCount !== 'number' ||
|
|
34
|
-
!('Messages' in providerResponse) ||
|
|
35
|
-
!Array.isArray(providerResponse.Messages)) {
|
|
39
|
+
const result = postmarkMessagesResponseSchema.safeParse(providerResponse);
|
|
40
|
+
if (!result.success) {
|
|
36
41
|
throw new send_email_1.EmailDeliveryError('Postmark returned an invalid response');
|
|
37
42
|
}
|
|
38
|
-
if (
|
|
43
|
+
if (result.data.TotalCount === 0)
|
|
39
44
|
return undefined;
|
|
40
|
-
const message =
|
|
41
|
-
|
|
42
|
-
'Metadata' in value &&
|
|
43
|
-
value.Metadata &&
|
|
44
|
-
typeof value.Metadata === 'object' &&
|
|
45
|
-
'deliveryId' in value.Metadata &&
|
|
46
|
-
value.Metadata.deliveryId === deliveryId);
|
|
47
|
-
const messageId = message &&
|
|
48
|
-
typeof message === 'object' &&
|
|
49
|
-
'MessageID' in message &&
|
|
50
|
-
typeof message.MessageID === 'string' &&
|
|
51
|
-
message.MessageID
|
|
52
|
-
? message.MessageID
|
|
53
|
-
: undefined;
|
|
54
|
-
const submittedAt = message &&
|
|
55
|
-
typeof message === 'object' &&
|
|
56
|
-
'ReceivedAt' in message &&
|
|
57
|
-
typeof message.ReceivedAt === 'string' &&
|
|
58
|
-
(0, utils_1.day)(message.ReceivedAt).isValid()
|
|
59
|
-
? message.ReceivedAt
|
|
60
|
-
: undefined;
|
|
61
|
-
if (!messageId || !submittedAt) {
|
|
45
|
+
const message = result.data.Messages.find(({ Metadata }) => Metadata.deliveryId === deliveryId);
|
|
46
|
+
if (!message) {
|
|
62
47
|
throw new send_email_1.EmailDeliveryError('Postmark returned an invalid response');
|
|
63
48
|
}
|
|
64
|
-
return {
|
|
49
|
+
return {
|
|
50
|
+
httpStatus: response.status,
|
|
51
|
+
messageId: message.MessageID,
|
|
52
|
+
submittedAt: message.ReceivedAt,
|
|
53
|
+
};
|
|
65
54
|
}
|
|
66
55
|
//# sourceMappingURL=find-postmark-email.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-postmark-email.js","sourceRoot":"src/","sources":["utils/find-postmark-email.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"find-postmark-email.js","sourceRoot":"src/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AS;QAC5B,WAAW,EAAE,OAAO,CAAC,UAAU;KAChC,CAAC;AACJ,CAAC","sourcesContent":["import { day } from '@vrplatform/utils';\nimport { z } from 'zod';\nimport { EmailDeliveryError } from './send-email';\n\nconst postmarkMessagesResponseSchema = z.object({\n TotalCount: z.number().int().nonnegative(),\n Messages: z.array(\n z.object({\n MessageID: z.string().min(1),\n ReceivedAt: z.string().refine((value) => day(value).isValid()),\n Metadata: z.object({ deliveryId: z.string() }).passthrough(),\n })\n ),\n});\n\nexport async function findPostmarkEmail(\n deliveryId: string,\n options: {\n fetch?: (\n input: string | URL | Request,\n init?: RequestInit\n ) => Promise<Response>;\n postmarkToken?: string;\n }\n) {\n if (!options.postmarkToken) {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n undefined,\n false,\n false\n );\n }\n\n const url = new URL('https://api.postmarkapp.com/messages/outbound');\n url.searchParams.set('count', '1');\n url.searchParams.set('offset', '0');\n url.searchParams.set('messagestream', 'outbound');\n url.searchParams.set('metadata_deliveryId', deliveryId);\n const response = await (options.fetch ?? fetch)(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n 'X-Postmark-Server-Token': options.postmarkToken,\n },\n });\n const providerResponse: unknown = await response.json().catch(() => ({}));\n\n if (!response.ok) {\n throw new EmailDeliveryError(\n 'Postmark message lookup failed',\n {\n provider: 'postmark',\n providerCategory: 'rejected',\n httpStatus: response.status,\n },\n false,\n response.status === 429 || response.status >= 500\n );\n }\n\n const result = postmarkMessagesResponseSchema.safeParse(providerResponse);\n if (!result.success) {\n throw new EmailDeliveryError('Postmark returned an invalid response');\n }\n if (result.data.TotalCount === 0) return undefined;\n\n const message = result.data.Messages.find(\n ({ Metadata }) => Metadata.deliveryId === deliveryId\n );\n if (!message) {\n throw new EmailDeliveryError('Postmark returned an invalid response');\n }\n\n return {\n httpStatus: response.status,\n messageId: message.MessageID,\n submittedAt: message.ReceivedAt,\n };\n}\n"]}
|
|
@@ -15,6 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./find-postmark-email"), exports);
|
|
18
|
-
__exportStar(require("./find-postmark-email"), exports);
|
|
19
18
|
__exportStar(require("./send-email"), exports);
|
|
20
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,+CAA6B","sourcesContent":["export * from './find-postmark-email';\nexport * from './send-email';\n"]}
|
|
@@ -14,6 +14,12 @@ export declare class EmailDeliveryError extends Error {
|
|
|
14
14
|
readonly retryable: boolean;
|
|
15
15
|
constructor(message: string, details?: EmailDeliveryErrorDetails | undefined, expected?: boolean, retryable?: boolean);
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Formats a verified sender address with a display name for the From header.
|
|
19
|
+
* Registrations store bare addresses; recipients should still see the company
|
|
20
|
+
* name the way they see `VRPlatform <notifications@vrplatform.app>`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatSenderIdentity(name: string | null | undefined, address: string): string;
|
|
17
23
|
export declare function sendEmail(data: {
|
|
18
24
|
to: string;
|
|
19
25
|
subject: string;
|
|
@@ -22,6 +28,7 @@ export declare function sendEmail(data: {
|
|
|
22
28
|
replyTo?: string;
|
|
23
29
|
tag?: string;
|
|
24
30
|
metadata?: Record<string, string>;
|
|
31
|
+
from?: string;
|
|
25
32
|
}, options: {
|
|
26
33
|
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
27
34
|
postmarkToken?: string;
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EmailDeliveryError = void 0;
|
|
4
|
+
exports.formatSenderIdentity = formatSenderIdentity;
|
|
4
5
|
exports.sendEmail = sendEmail;
|
|
5
6
|
exports.settleEmailDeliveries = settleEmailDeliveries;
|
|
6
7
|
const utils_1 = require("@vrplatform/utils");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const postmarkErrorCodeSchema = zod_1.z.number().int().nonnegative();
|
|
10
|
+
const postmarkResponseErrorCodeSchema = zod_1.z
|
|
11
|
+
.object({ ErrorCode: postmarkErrorCodeSchema })
|
|
12
|
+
.transform(({ ErrorCode }) => ErrorCode);
|
|
13
|
+
const postmarkHeaderErrorCodeSchema = zod_1.z
|
|
14
|
+
.string()
|
|
15
|
+
.regex(/^\d+$/)
|
|
16
|
+
.transform(Number)
|
|
17
|
+
.pipe(postmarkErrorCodeSchema);
|
|
18
|
+
const postmarkSuccessResponseSchema = zod_1.z.object({
|
|
19
|
+
ErrorCode: zod_1.z.literal(0),
|
|
20
|
+
MessageID: zod_1.z.string().min(1),
|
|
21
|
+
SubmittedAt: zod_1.z.string().refine((value) => (0, utils_1.day)(value).isValid()),
|
|
22
|
+
});
|
|
23
|
+
function parseOptional(schema, value) {
|
|
24
|
+
const result = schema.safeParse(value);
|
|
25
|
+
if (result.success)
|
|
26
|
+
return result.data;
|
|
27
|
+
}
|
|
7
28
|
class EmailDeliveryError extends Error {
|
|
8
29
|
constructor(message, details, expected = false, retryable = true) {
|
|
9
30
|
super(message);
|
|
@@ -14,6 +35,15 @@ class EmailDeliveryError extends Error {
|
|
|
14
35
|
}
|
|
15
36
|
}
|
|
16
37
|
exports.EmailDeliveryError = EmailDeliveryError;
|
|
38
|
+
/**
|
|
39
|
+
* Formats a verified sender address with a display name for the From header.
|
|
40
|
+
* Registrations store bare addresses; recipients should still see the company
|
|
41
|
+
* name the way they see `VRPlatform <notifications@vrplatform.app>`.
|
|
42
|
+
*/
|
|
43
|
+
function formatSenderIdentity(name, address) {
|
|
44
|
+
const display = (name ?? '').replace(/[\r\n"<>]/g, '').trim();
|
|
45
|
+
return display ? `"${display}" <${address}>` : address;
|
|
46
|
+
}
|
|
17
47
|
async function sendEmail(data, options) {
|
|
18
48
|
if (!options.postmarkToken) {
|
|
19
49
|
throw new EmailDeliveryError('Postmark is not configured', undefined, false, false);
|
|
@@ -26,7 +56,7 @@ async function sendEmail(data, options) {
|
|
|
26
56
|
'X-Postmark-Server-Token': options.postmarkToken,
|
|
27
57
|
},
|
|
28
58
|
body: JSON.stringify({
|
|
29
|
-
From: 'VRPlatform <notifications@vrplatform.app>',
|
|
59
|
+
From: data.from ?? 'VRPlatform <notifications@vrplatform.app>',
|
|
30
60
|
To: data.to,
|
|
31
61
|
Subject: data.subject,
|
|
32
62
|
ReplyTo: data.replyTo,
|
|
@@ -38,22 +68,8 @@ async function sendEmail(data, options) {
|
|
|
38
68
|
}),
|
|
39
69
|
});
|
|
40
70
|
const providerResponse = await response.json().catch(() => ({}));
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
'ErrorCode' in providerResponse &&
|
|
44
|
-
typeof providerResponse.ErrorCode === 'number'
|
|
45
|
-
? providerResponse.ErrorCode
|
|
46
|
-
: undefined;
|
|
47
|
-
const headerErrorCode = response.headers.get('X-PM-ApiErrorCode');
|
|
48
|
-
const errorCode = responseErrorCode ??
|
|
49
|
-
(headerErrorCode && /^\d+$/.test(headerErrorCode)
|
|
50
|
-
? Number(headerErrorCode)
|
|
51
|
-
: undefined);
|
|
52
|
-
const postmarkErrorCode = typeof errorCode === 'number' &&
|
|
53
|
-
Number.isSafeInteger(errorCode) &&
|
|
54
|
-
errorCode >= 0
|
|
55
|
-
? errorCode
|
|
56
|
-
: undefined;
|
|
71
|
+
const postmarkErrorCode = parseOptional(postmarkResponseErrorCodeSchema, providerResponse) ??
|
|
72
|
+
parseOptional(postmarkHeaderErrorCodeSchema, response.headers.get('X-PM-ApiErrorCode'));
|
|
57
73
|
if (!response.ok ||
|
|
58
74
|
(postmarkErrorCode !== undefined && postmarkErrorCode !== 0)) {
|
|
59
75
|
const inactiveRecipient = response.status === 422 && postmarkErrorCode === 406;
|
|
@@ -68,21 +84,8 @@ async function sendEmail(data, options) {
|
|
|
68
84
|
}
|
|
69
85
|
throw new EmailDeliveryError('Postmark rejected the email', details, false, response.status === 429 || response.status >= 500);
|
|
70
86
|
}
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
'MessageID' in providerResponse &&
|
|
74
|
-
typeof providerResponse.MessageID === 'string' &&
|
|
75
|
-
providerResponse.MessageID
|
|
76
|
-
? providerResponse.MessageID
|
|
77
|
-
: undefined;
|
|
78
|
-
const submittedAt = providerResponse !== null &&
|
|
79
|
-
typeof providerResponse === 'object' &&
|
|
80
|
-
'SubmittedAt' in providerResponse &&
|
|
81
|
-
typeof providerResponse.SubmittedAt === 'string' &&
|
|
82
|
-
(0, utils_1.day)(providerResponse.SubmittedAt).isValid()
|
|
83
|
-
? providerResponse.SubmittedAt
|
|
84
|
-
: undefined;
|
|
85
|
-
if (!messageId || !submittedAt || postmarkErrorCode !== 0) {
|
|
87
|
+
const result = postmarkSuccessResponseSchema.safeParse(providerResponse);
|
|
88
|
+
if (!result.success) {
|
|
86
89
|
throw new EmailDeliveryError('Postmark returned an invalid response', {
|
|
87
90
|
provider: 'postmark',
|
|
88
91
|
providerCategory: 'rejected',
|
|
@@ -92,8 +95,8 @@ async function sendEmail(data, options) {
|
|
|
92
95
|
}
|
|
93
96
|
return {
|
|
94
97
|
httpStatus: response.status,
|
|
95
|
-
messageId,
|
|
96
|
-
submittedAt,
|
|
98
|
+
messageId: result.data.MessageID,
|
|
99
|
+
submittedAt: result.data.SubmittedAt,
|
|
97
100
|
};
|
|
98
101
|
}
|
|
99
102
|
async function settleEmailDeliveries(deliveries) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-email.js","sourceRoot":"src/","sources":["utils/send-email.ts"],"names":[],"mappings":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CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAClE;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,GAA8B;QACzC,YAAY,EAAE,QAAQ,CAAC,MAAM;QAC7B,QAAQ,EAAE,cAAc;KACzB,CAAC;IACF,IAAI,uBAAuB,YAAY,kBAAkB,EAAE,CAAC;QAC1D,IAAI,uBAAuB,CAAC,OAAO,KAAK,4BAA4B,EAAE,CAAC;YACrE,MAAM,IAAI,kBAAkB,CAC1B,4BAA4B,EAC5B,OAAO,EACP,KAAK,EACL,KAAK,CACN,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,kBAAkB,CAC1B,6BAA6B,EAC7B,OAAO,EACP,KAAK,EACL,uBAAuB,CAAC,SAAS,CAClC,CAAC;IACJ,CAAC;IACD,IAAI,WAAW,IAAI,kBAAkB,YAAY,kBAAkB,EAAE,CAAC;QACpE,MAAM,IAAI,kBAAkB,CAC1B,gCAAgC,EAChC,OAAO,EACP,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,kBAAkB,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { day } from '@vrplatform/utils';\n\ntype EmailDeliveryFailureDetails = {\n httpStatus: number;\n postmarkErrorCode?: number;\n provider: 'postmark';\n providerCategory: 'inactiveRecipient' | 'rejected';\n};\n\ntype EmailDeliveryErrorDetails =\n | EmailDeliveryFailureDetails\n | {\n failureCount: number;\n failures: EmailDeliveryFailureDetails[];\n };\n\nexport class EmailDeliveryError extends Error {\n constructor(\n message: string,\n public readonly details?: EmailDeliveryErrorDetails,\n public readonly expected = false,\n public readonly retryable = true\n ) {\n super(message);\n this.name = 'EmailDeliveryError';\n }\n}\n\nexport async function sendEmail(\n data: {\n to: string;\n subject: string;\n text: string;\n html: string;\n replyTo?: string;\n tag?: string;\n metadata?: Record<string, string>;\n },\n options: {\n fetch?: (\n input: string | URL | Request,\n init?: RequestInit\n ) => Promise<Response>;\n postmarkToken?: string;\n }\n) {\n if (!options.postmarkToken) {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n undefined,\n false,\n false\n );\n }\n\n const response = await (options.fetch ?? fetch)(\n 'https://api.postmarkapp.com/email',\n {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'X-Postmark-Server-Token': options.postmarkToken,\n },\n body: JSON.stringify({\n From: 'VRPlatform <notifications@vrplatform.app>',\n To: data.to,\n Subject: data.subject,\n ReplyTo: data.replyTo,\n TextBody: data.text,\n HtmlBody: data.html,\n MessageStream: 'outbound',\n Tag: data.tag,\n Metadata: data.metadata,\n }),\n }\n );\n\n const providerResponse: unknown = await response.json().catch(() => ({}));\n const responseErrorCode =\n providerResponse !== null &&\n typeof providerResponse === 'object' &&\n 'ErrorCode' in providerResponse &&\n typeof providerResponse.ErrorCode === 'number'\n ? providerResponse.ErrorCode\n : undefined;\n const headerErrorCode = response.headers.get('X-PM-ApiErrorCode');\n const errorCode =\n responseErrorCode ??\n (headerErrorCode && /^\\d+$/.test(headerErrorCode)\n ? Number(headerErrorCode)\n : undefined);\n const postmarkErrorCode =\n typeof errorCode === 'number' &&\n Number.isSafeInteger(errorCode) &&\n errorCode >= 0\n ? errorCode\n : undefined;\n\n if (\n !response.ok ||\n (postmarkErrorCode !== undefined && postmarkErrorCode !== 0)\n ) {\n const inactiveRecipient =\n response.status === 422 && postmarkErrorCode === 406;\n const details: EmailDeliveryFailureDetails = {\n provider: 'postmark',\n providerCategory: inactiveRecipient ? 'inactiveRecipient' : 'rejected',\n httpStatus: response.status,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n };\n\n if (inactiveRecipient) {\n throw new EmailDeliveryError(\n 'Postmark recipient is inactive',\n details,\n true,\n false\n );\n }\n\n throw new EmailDeliveryError(\n 'Postmark rejected the email',\n details,\n false,\n response.status === 429 || response.status >= 500\n );\n }\n\n const messageId =\n providerResponse !== null &&\n typeof providerResponse === 'object' &&\n 'MessageID' in providerResponse &&\n typeof providerResponse.MessageID === 'string' &&\n providerResponse.MessageID\n ? providerResponse.MessageID\n : undefined;\n const submittedAt =\n providerResponse !== null &&\n typeof providerResponse === 'object' &&\n 'SubmittedAt' in providerResponse &&\n typeof providerResponse.SubmittedAt === 'string' &&\n day(providerResponse.SubmittedAt).isValid()\n ? providerResponse.SubmittedAt\n : undefined;\n if (!messageId || !submittedAt || postmarkErrorCode !== 0) {\n throw new EmailDeliveryError('Postmark returned an invalid response', {\n provider: 'postmark',\n providerCategory: 'rejected',\n httpStatus: response.status,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n });\n }\n\n return {\n httpStatus: response.status,\n messageId,\n submittedAt,\n };\n}\n\nexport async function settleEmailDeliveries(deliveries: Promise<unknown>[]) {\n const failures = (await Promise.allSettled(deliveries)).filter(\n (result) => result.status === 'rejected'\n );\n if (failures.length === 0) return;\n\n const unexpectedDeliveryError = failures.find(\n (failure) =>\n failure.reason instanceof EmailDeliveryError && !failure.reason.expected\n )?.reason;\n const allExpected = failures.every(\n (failure) =>\n failure.reason instanceof EmailDeliveryError && failure.reason.expected\n );\n const firstDeliveryError = failures.find(\n (failure) => failure.reason instanceof EmailDeliveryError\n )?.reason;\n const failureDetails = failures.flatMap((failure) => {\n if (\n !(failure.reason instanceof EmailDeliveryError) ||\n !failure.reason.details ||\n !('provider' in failure.reason.details)\n ) {\n return [];\n }\n const { httpStatus, postmarkErrorCode, provider, providerCategory } =\n failure.reason.details;\n return [\n {\n httpStatus,\n provider,\n providerCategory,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n },\n ];\n });\n\n const details: EmailDeliveryErrorDetails = {\n failureCount: failures.length,\n failures: failureDetails,\n };\n if (unexpectedDeliveryError instanceof EmailDeliveryError) {\n if (unexpectedDeliveryError.message === 'Postmark is not configured') {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n details,\n false,\n false\n );\n }\n throw new EmailDeliveryError(\n 'Postmark rejected the email',\n details,\n false,\n unexpectedDeliveryError.retryable\n );\n }\n if (allExpected && firstDeliveryError instanceof EmailDeliveryError) {\n throw new EmailDeliveryError(\n 'Postmark recipient is inactive',\n details,\n true,\n false\n );\n }\n throw new EmailDeliveryError('Email delivery failed', details);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"send-email.js","sourceRoot":"src/","sources":["utils/send-email.ts"],"names":[],"mappings":";;;AAsDA,oDAMC;AAED,8BAwGC;AAED,sDAkEC;AA1OD,6CAAwC;AACxC,6BAAwB;AAExB,MAAM,uBAAuB,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;AAC/D,MAAM,+BAA+B,GAAG,OAAC;KACtC,MAAM,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;KAC9C,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;AAC3C,MAAM,6BAA6B,GAAG,OAAC;KACpC,MAAM,EAAE;KACR,KAAK,CAAC,OAAO,CAAC;KACd,SAAS,CAAC,MAAM,CAAC;KACjB,IAAI,CAAC,uBAAuB,CAAC,CAAC;AACjC,MAAM,6BAA6B,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,OAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACvB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,WAAG,EAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;CAChE,CAAC,CAAC;AAEH,SAAS,aAAa,CAAI,MAAoB,EAAE,KAAc;IAC5D,MAAM,MAAM,GAAG,MAAM,C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,CAClC,CAAC;IACJ,CAAC;IACD,IAAI,WAAW,IAAI,kBAAkB,YAAY,kBAAkB,EAAE,CAAC;QACpE,MAAM,IAAI,kBAAkB,CAC1B,gCAAgC,EAChC,OAAO,EACP,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,kBAAkB,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { day } from '@vrplatform/utils';\nimport { z } from 'zod';\n\nconst postmarkErrorCodeSchema = z.number().int().nonnegative();\nconst postmarkResponseErrorCodeSchema = z\n .object({ ErrorCode: postmarkErrorCodeSchema })\n .transform(({ ErrorCode }) => ErrorCode);\nconst postmarkHeaderErrorCodeSchema = z\n .string()\n .regex(/^\\d+$/)\n .transform(Number)\n .pipe(postmarkErrorCodeSchema);\nconst postmarkSuccessResponseSchema = z.object({\n ErrorCode: z.literal(0),\n MessageID: z.string().min(1),\n SubmittedAt: z.string().refine((value) => day(value).isValid()),\n});\n\nfunction parseOptional<T>(schema: z.ZodType<T>, value: unknown) {\n const result = schema.safeParse(value);\n if (result.success) return result.data;\n}\n\ntype EmailDeliveryFailureDetails = {\n httpStatus: number;\n postmarkErrorCode?: number;\n provider: 'postmark';\n providerCategory: 'inactiveRecipient' | 'rejected';\n};\n\ntype EmailDeliveryErrorDetails =\n | EmailDeliveryFailureDetails\n | {\n failureCount: number;\n failures: EmailDeliveryFailureDetails[];\n };\n\nexport class EmailDeliveryError extends Error {\n constructor(\n message: string,\n public readonly details?: EmailDeliveryErrorDetails,\n public readonly expected = false,\n public readonly retryable = true\n ) {\n super(message);\n this.name = 'EmailDeliveryError';\n }\n}\n\n/**\n * Formats a verified sender address with a display name for the From header.\n * Registrations store bare addresses; recipients should still see the company\n * name the way they see `VRPlatform <notifications@vrplatform.app>`.\n */\nexport function formatSenderIdentity(\n name: string | null | undefined,\n address: string\n) {\n const display = (name ?? '').replace(/[\\r\\n\"<>]/g, '').trim();\n return display ? `\"${display}\" <${address}>` : address;\n}\n\nexport async function sendEmail(\n data: {\n to: string;\n subject: string;\n text: string;\n html: string;\n replyTo?: string;\n tag?: string;\n metadata?: Record<string, string>;\n from?: string;\n },\n options: {\n fetch?: (\n input: string | URL | Request,\n init?: RequestInit\n ) => Promise<Response>;\n postmarkToken?: string;\n }\n) {\n if (!options.postmarkToken) {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n undefined,\n false,\n false\n );\n }\n\n const response = await (options.fetch ?? fetch)(\n 'https://api.postmarkapp.com/email',\n {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'X-Postmark-Server-Token': options.postmarkToken,\n },\n body: JSON.stringify({\n From: data.from ?? 'VRPlatform <notifications@vrplatform.app>',\n To: data.to,\n Subject: data.subject,\n ReplyTo: data.replyTo,\n TextBody: data.text,\n HtmlBody: data.html,\n MessageStream: 'outbound',\n Tag: data.tag,\n Metadata: data.metadata,\n }),\n }\n );\n\n const providerResponse: unknown = await response.json().catch(() => ({}));\n const postmarkErrorCode =\n parseOptional(postmarkResponseErrorCodeSchema, providerResponse) ??\n parseOptional(\n postmarkHeaderErrorCodeSchema,\n response.headers.get('X-PM-ApiErrorCode')\n );\n\n if (\n !response.ok ||\n (postmarkErrorCode !== undefined && postmarkErrorCode !== 0)\n ) {\n const inactiveRecipient =\n response.status === 422 && postmarkErrorCode === 406;\n const details: EmailDeliveryFailureDetails = {\n provider: 'postmark',\n providerCategory: inactiveRecipient ? 'inactiveRecipient' : 'rejected',\n httpStatus: response.status,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n };\n\n if (inactiveRecipient) {\n throw new EmailDeliveryError(\n 'Postmark recipient is inactive',\n details,\n true,\n false\n );\n }\n\n throw new EmailDeliveryError(\n 'Postmark rejected the email',\n details,\n false,\n response.status === 429 || response.status >= 500\n );\n }\n\n const result = postmarkSuccessResponseSchema.safeParse(providerResponse);\n if (!result.success) {\n throw new EmailDeliveryError('Postmark returned an invalid response', {\n provider: 'postmark',\n providerCategory: 'rejected',\n httpStatus: response.status,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n });\n }\n\n return {\n httpStatus: response.status,\n messageId: result.data.MessageID,\n submittedAt: result.data.SubmittedAt,\n };\n}\n\nexport async function settleEmailDeliveries(deliveries: Promise<unknown>[]) {\n const failures = (await Promise.allSettled(deliveries)).filter(\n (result) => result.status === 'rejected'\n );\n if (failures.length === 0) return;\n\n const unexpectedDeliveryError = failures.find(\n (failure) =>\n failure.reason instanceof EmailDeliveryError && !failure.reason.expected\n )?.reason;\n const allExpected = failures.every(\n (failure) =>\n failure.reason instanceof EmailDeliveryError && failure.reason.expected\n );\n const firstDeliveryError = failures.find(\n (failure) => failure.reason instanceof EmailDeliveryError\n )?.reason;\n const failureDetails = failures.flatMap((failure) => {\n if (\n !(failure.reason instanceof EmailDeliveryError) ||\n !failure.reason.details ||\n !('provider' in failure.reason.details)\n ) {\n return [];\n }\n const { httpStatus, postmarkErrorCode, provider, providerCategory } =\n failure.reason.details;\n return [\n {\n httpStatus,\n provider,\n providerCategory,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n },\n ];\n });\n\n const details: EmailDeliveryErrorDetails = {\n failureCount: failures.length,\n failures: failureDetails,\n };\n if (unexpectedDeliveryError instanceof EmailDeliveryError) {\n if (unexpectedDeliveryError.message === 'Postmark is not configured') {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n details,\n false,\n false\n );\n }\n throw new EmailDeliveryError(\n 'Postmark rejected the email',\n details,\n false,\n unexpectedDeliveryError.retryable\n );\n }\n if (allExpected && firstDeliveryError instanceof EmailDeliveryError) {\n throw new EmailDeliveryError(\n 'Postmark recipient is inactive',\n details,\n true,\n false\n );\n }\n throw new EmailDeliveryError('Email delivery failed', details);\n}\n"]}
|
|
@@ -5,9 +5,7 @@ import { EmailContainer } from './EmailContainer';
|
|
|
5
5
|
import { parseEmailHtml } from './utils';
|
|
6
6
|
import { Button } from './Button';
|
|
7
7
|
export const ActionEmailTemplate = ({ data, tenant, themeColors, mode, user, listing, month, }) => {
|
|
8
|
-
return (_jsxs(EmailContainer, { title: data.subject, shortDescription: data.shortDescription, tenant: {
|
|
9
|
-
logo: tenant.logo,
|
|
10
|
-
}, mode: mode, children: [_jsx(Heading, { style: {
|
|
8
|
+
return (_jsxs(EmailContainer, { title: data.subject, shortDescription: data.shortDescription, tenant: tenant, mode: mode, children: [_jsx(Heading, { style: {
|
|
11
9
|
fontSize: 28,
|
|
12
10
|
fontWeight: 600,
|
|
13
11
|
marginBottom: '50px',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionEmailTemplate.js","sourceRoot":"src/","sources":["components/ActionEmailTemplate.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAiBlC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,IAAI,EACJ,MAAM,EACN,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,KAAK,GACoB,EAAE,EAAE;IAC7B,OAAO,CACL,MAAC,cAAc,IACb,KAAK,EAAE,IAAI,CAAC,OAAO,EACnB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EACvC,MAAM,EAAE
|
|
1
|
+
{"version":3,"file":"ActionEmailTemplate.js","sourceRoot":"src/","sources":["components/ActionEmailTemplate.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAA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C,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,mBAAmB,EACrD,WAAW,EAAE,WAAW,GACxB,EAEF;gBACE,sEAAsE;gBACtE,uBAAuB,EAAE;oBACvB,MAAM,EAAE,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE;wBACnC,IAAI,EAAE,IAAI,CAAC,IAAI;wBACf,QAAQ,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;wBAC9B,IAAI,EAAE,KAAK,IAAI,EAAE;wBACjB,WAAW,EAAE,OAAO,IAAI,EAAE;qBAC3B,CAAC;iBACH,GACD,IACa,CAClB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Heading } from '@react-email/heading';\nimport { Text } from '@react-email/text';\nimport { EmailContainer } from './EmailContainer';\nimport type { EmailBaseProps } from '../types';\nimport { parseEmailHtml } from './utils';\nimport { Button } from './Button';\n\nexport type ActionEmailData = {\n subject: string;\n shortDescription: string;\n banner?: string;\n header: string;\n bodyOne: string;\n bodyTwo: string;\n href: string;\n buttonText: string;\n};\n\nexport interface ActionEmailTemplateProps extends EmailBaseProps {\n data: ActionEmailData;\n}\n\nexport const ActionEmailTemplate = ({\n data,\n tenant,\n themeColors,\n mode,\n user,\n listing,\n month,\n}: ActionEmailTemplateProps) => {\n return (\n <EmailContainer\n title={data.subject}\n shortDescription={data.shortDescription}\n tenant={tenant}\n mode={mode}\n >\n <Heading\n style={{\n fontSize: 28,\n fontWeight: 600,\n marginBottom: '50px',\n }}\n >\n {data.header?.trim() || `Welcome to ${tenant.name}!`}\n </Heading>\n\n {data.banner?.trim() && (\n <Text\n style={{\n padding: '24px',\n backgroundColor: '#f2f3f3',\n borderRadius: '4px',\n marginBottom: '40px',\n }}\n >\n {data.banner.trim()}\n </Text>\n )}\n\n <div\n // biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>\n dangerouslySetInnerHTML={{\n __html: parseEmailHtml(data.bodyOne, {\n href: data.href,\n userName: user.firstName || '',\n date: month || '',\n listingName: listing || '',\n }),\n }}\n />\n\n <Button\n href={data.href}\n mode={mode}\n data-testid=\"accept-invite-button\"\n label={data.buttonText?.trim() || 'Accept Invitation'}\n themeColors={themeColors}\n />\n\n <div\n // biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>\n dangerouslySetInnerHTML={{\n __html: parseEmailHtml(data.bodyTwo, {\n href: data.href,\n userName: user.firstName || '',\n date: month || '',\n listingName: listing || '',\n }),\n }}\n />\n </EmailContainer>\n );\n};\n"]}
|
|
@@ -2,7 +2,9 @@ import type { EmailBaseProps } from '../types';
|
|
|
2
2
|
type Props = {
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
title: string;
|
|
5
|
-
tenant: Omit<EmailBaseProps['tenant'], 'name'
|
|
5
|
+
tenant: Omit<EmailBaseProps['tenant'], 'name'> & {
|
|
6
|
+
name?: string;
|
|
7
|
+
};
|
|
6
8
|
mode: EmailBaseProps['mode'];
|
|
7
9
|
shortDescription?: string;
|
|
8
10
|
};
|
|
@@ -27,7 +27,7 @@ export const EmailContainer = (props) => {
|
|
|
27
27
|
format: 'woff2',
|
|
28
28
|
}, fontWeight: 600, fontStyle: "normal" })] }), shortDescription && _jsx(Preview, { children: shortDescription }), _jsx(Body, { style: contentWrapperStyle, children: _jsx(Content, { ...props, children: children }) })] }));
|
|
29
29
|
};
|
|
30
|
-
const Content = ({ children, tenant: { logo: tenantLogo }, mode }) => {
|
|
30
|
+
const Content = ({ children, tenant: { logo: tenantLogo, name, showPlatformBranding = true }, mode, }) => {
|
|
31
31
|
return (_jsxs(_Fragment, { children: [tenantLogo ? (_jsx("div", { style: {
|
|
32
32
|
marginBottom: '60px',
|
|
33
33
|
padding: '5px',
|
|
@@ -37,9 +37,9 @@ const Content = ({ children, tenant: { logo: tenantLogo }, mode }) => {
|
|
|
37
37
|
display: 'flex',
|
|
38
38
|
justifyContent: 'center',
|
|
39
39
|
alignItems: 'center',
|
|
40
|
-
}, children: _jsx(Img, { src: tenantLogo, alt: 'Logo', width: 70 }) })) : mode === 'send' ? (_jsx(Img, { src: 'https://staging.portal.vrplatform.app/logo.png', alt: 'Logo', width: 70, style: { marginBottom: '60px' } })) : (_jsx("div", { style: {
|
|
40
|
+
}, children: _jsx(Img, { src: tenantLogo, alt: 'Logo', width: 70 }) })) : !showPlatformBranding ? (_jsx(Text, { children: name })) : mode === 'send' ? (_jsx(Img, { src: 'https://staging.portal.vrplatform.app/logo.png', alt: 'Logo', width: 70, style: { marginBottom: '60px' } })) : (_jsx("div", { style: {
|
|
41
41
|
width: '60px',
|
|
42
|
-
}, children: _jsx(VrpLogo, {}) })), children, _jsx(Footer, {})] }));
|
|
42
|
+
}, children: _jsx(VrpLogo, {}) })), children, showPlatformBranding ? _jsx(Footer, {}) : _jsx(Text, { children: name })] }));
|
|
43
43
|
};
|
|
44
44
|
const Footer = () => (_jsxs(_Fragment, { children: [_jsx(Hr, { style: {
|
|
45
45
|
marginTop: '30px',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailContainer.js","sourceRoot":"src/","sources":["components/EmailContainer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAWxC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAY,EAAE,EAAE;IAC7C,MAAM,EAAE,QA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ACP,EAEA,QAAQ,EAER,oBAAoB,CAAC,CAAC,CAAC,KAAC,MAAM,KAAG,CAAC,CAAC,CAAC,KAAC,IAAI,cAAE,IAAI,GAAQ,IACvD,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,CACnB,8BACE,KAAC,EAAE,IACD,KAAK,EAAE;gBACL,SAAS,EAAE,MAAM;gBACjB,YAAY,EAAE,MAAM;aACrB,GACD,EAEF,MAAC,IAAI,IACH,KAAK,EAAE;gBACL,KAAK,EAAE,SAAS;aACjB,wBAEE,GAAG,EAAE,CAAC,IAAI,EAAE,8CACV,EACP,KAAC,IAAI,IACH,KAAK,EAAE;gBACL,KAAK,EAAE,SAAS;aACjB,4IAII,IACN,CACJ,CAAC;AAEF,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CACpB,eACE,KAAK,EAAC,MAAM,EACZ,MAAM,EAAC,MAAM,EACb,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,KAAK,EAAC,4BAA4B,aAElC,eACE,CAAC,EAAC,mNAAmN,EACrN,IAAI,EAAC,SAAS,GACd,EACF,eACE,CAAC,EAAC,gUAAgU,EAClU,IAAI,EAAC,SAAS,EACd,WAAW,EAAC,KAAK,GACjB,EACF,eACE,CAAC,EAAC,4WAA4W,EAC9W,IAAI,EAAC,SAAS,GACd,IACE,CACP,CAAC","sourcesContent":["import { Body } from '@react-email/body';\nimport { Font } from '@react-email/font';\nimport { Head } from '@react-email/head';\nimport { Hr } from '@react-email/hr';\nimport { Html } from '@react-email/html';\nimport { Img } from '@react-email/img';\nimport { Preview } from '@react-email/preview';\nimport { Text } from '@react-email/text';\nimport { day } from '@vrplatform/utils';\nimport type { EmailBaseProps } from '../types';\n\ntype Props = {\n children: React.ReactNode;\n title: string;\n tenant: Omit<EmailBaseProps['tenant'], 'name'> & { name?: string };\n mode: EmailBaseProps['mode'];\n shortDescription?: string;\n};\n\nexport const EmailContainer = (props: Props) => {\n const { children, shortDescription, title } = props;\n\n const contentWrapperStyle = {\n paddingInline: '20px',\n paddingBlock: '10px',\n maxWidth: '500px',\n margin: '0 auto',\n };\n\n if (props.mode !== 'send') {\n return (\n <div style={contentWrapperStyle}>\n <Content {...props}>{children}</Content>\n </div>\n );\n }\n\n return (\n <Html lang=\"en\">\n <Head>\n <title>{title}</title>\n <Font\n fontFamily=\"Inter\"\n fallbackFontFamily=\"Verdana\"\n webFont={{\n url: 'https://fonts.gstatic.com/s/inter/v13/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7W0Q5nw.woff2',\n format: 'woff2',\n }}\n fontWeight={400}\n fontStyle=\"normal\"\n />\n <Font\n fontFamily=\"Inter\"\n fallbackFontFamily=\"Verdana\"\n webFont={{\n url: 'https://fonts.gstatic.com/s/inter/v13/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7W0Q5nw.woff2',\n format: 'woff2',\n }}\n fontWeight={600}\n fontStyle=\"normal\"\n />\n </Head>\n {shortDescription && <Preview>{shortDescription}</Preview>}\n <Body style={contentWrapperStyle}>\n <Content {...props}>{children}</Content>\n </Body>\n </Html>\n );\n};\n\nconst Content = ({\n children,\n tenant: { logo: tenantLogo, name, showPlatformBranding = true },\n mode,\n}: Props) => {\n return (\n <>\n {tenantLogo ? (\n <div\n style={{\n marginBottom: '60px',\n padding: '5px',\n // border: '1px solid rgb(233,236,239)',\n borderRadius: '5px',\n width: '80px',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n }}\n >\n <Img src={tenantLogo} alt={'Logo'} width={70} />\n </div>\n ) : !showPlatformBranding ? (\n <Text>{name}</Text>\n ) : mode === 'send' ? (\n <Img\n src={'https://staging.portal.vrplatform.app/logo.png'}\n alt={'Logo'}\n width={70}\n style={{ marginBottom: '60px' }}\n />\n ) : (\n <div\n style={{\n width: '60px',\n }}\n >\n <VrpLogo />\n </div>\n )}\n\n {children}\n\n {showPlatformBranding ? <Footer /> : <Text>{name}</Text>}\n </>\n );\n};\n\nconst Footer = () => (\n <>\n <Hr\n style={{\n marginTop: '30px',\n marginBottom: '50px',\n }}\n />\n\n <Text\n style={{\n color: '#737373',\n }}\n >\n © {day().year()} VR Technologies. All rights reserved.\n </Text>\n <Text\n style={{\n color: '#737373',\n }}\n >\n VR Technologies, LLC, a company incorporated and registered in the United\n States of America with company number 20201965158\n </Text>\n </>\n);\n\nconst VrpLogo = () => (\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox=\"0 0 28 29\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M18.2549 8.25161C18.2549 5.89704 20.1636 3.98828 22.5182 3.98828C24.8728 3.98828 26.7815 5.89704 26.7815 8.25161C26.7815 10.6062 24.8728 12.5149 22.5182 12.5149C20.1636 12.5149 18.2549 10.6062 18.2549 8.25161Z\"\n fill=\"#172554\"\n />\n <path\n d=\"M7.02441 8.46593C7.02441 6.01867 9.20858 3.99805 11.6558 3.99805C14.1031 3.99805 15.0558 5.59785 16.5612 7.52728C17.1957 8.34054 20.7921 13.3413 20.7921 13.3413C20.7921 13.3413 21.566 14.6863 21.566 15.7894C21.566 18.5287 17.1993 22.8381 17.1993 22.8381L7.66841 10.6799C7.66841 10.6799 7.02441 10.0502 7.02441 8.46593Z\"\n fill=\"#172554\"\n fillOpacity=\"0.8\"\n />\n <path\n d=\"M1.24707 8.42687C1.24707 5.97961 3.43123 3.95898 5.8785 3.95898C8.32576 3.95898 9.27845 5.55879 10.7839 7.48824C11.4184 8.30147 14.6041 12.4888 16.8247 15.5727C18.3585 17.703 18.474 17.705 18.474 20.3439C18.474 22.9827 15.1592 24.1379 14.1483 24.1914C12.0203 24.304 10.5418 22.4681 10.5418 22.4681L1.89106 10.6408C1.89106 10.6408 1.24707 10.0111 1.24707 8.42687Z\"\n fill=\"#172554\"\n />\n </svg>\n);\n"]}
|
package/build/module/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["export type EmailBaseProps = {\n mode: 'edit' | 'preview' | 'send';\n tenant: {\n name: string;\n logo: string | undefined | null;\n };\n listing: string | undefined;\n month: string | undefined;\n user: {\n firstName: string | undefined;\n };\n themeColors: readonly [\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n ...string[],\n ];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["export type EmailBaseProps = {\n mode: 'edit' | 'preview' | 'send';\n tenant: {\n name: string;\n showPlatformBranding?: boolean;\n logo: string | undefined | null;\n };\n listing: string | undefined;\n month: string | undefined;\n user: {\n firstName: string | undefined;\n };\n themeColors: readonly [\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n ...string[],\n ];\n};\n"]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { day } from '@vrplatform/utils';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import { EmailDeliveryError } from './send-email';
|
|
4
|
+
const postmarkMessagesResponseSchema = z.object({
|
|
5
|
+
TotalCount: z.number().int().nonnegative(),
|
|
6
|
+
Messages: z.array(z.object({
|
|
7
|
+
MessageID: z.string().min(1),
|
|
8
|
+
ReceivedAt: z.string().refine((value) => day(value).isValid()),
|
|
9
|
+
Metadata: z.object({ deliveryId: z.string() }).passthrough(),
|
|
10
|
+
})),
|
|
11
|
+
});
|
|
3
12
|
export async function findPostmarkEmail(deliveryId, options) {
|
|
4
13
|
if (!options.postmarkToken) {
|
|
5
14
|
throw new EmailDeliveryError('Postmark is not configured', undefined, false, false);
|
|
@@ -24,40 +33,20 @@ export async function findPostmarkEmail(deliveryId, options) {
|
|
|
24
33
|
httpStatus: response.status,
|
|
25
34
|
}, false, response.status === 429 || response.status >= 500);
|
|
26
35
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
!('TotalCount' in providerResponse) ||
|
|
30
|
-
typeof providerResponse.TotalCount !== 'number' ||
|
|
31
|
-
!('Messages' in providerResponse) ||
|
|
32
|
-
!Array.isArray(providerResponse.Messages)) {
|
|
36
|
+
const result = postmarkMessagesResponseSchema.safeParse(providerResponse);
|
|
37
|
+
if (!result.success) {
|
|
33
38
|
throw new EmailDeliveryError('Postmark returned an invalid response');
|
|
34
39
|
}
|
|
35
|
-
if (
|
|
40
|
+
if (result.data.TotalCount === 0)
|
|
36
41
|
return undefined;
|
|
37
|
-
const message =
|
|
38
|
-
|
|
39
|
-
'Metadata' in value &&
|
|
40
|
-
value.Metadata &&
|
|
41
|
-
typeof value.Metadata === 'object' &&
|
|
42
|
-
'deliveryId' in value.Metadata &&
|
|
43
|
-
value.Metadata.deliveryId === deliveryId);
|
|
44
|
-
const messageId = message &&
|
|
45
|
-
typeof message === 'object' &&
|
|
46
|
-
'MessageID' in message &&
|
|
47
|
-
typeof message.MessageID === 'string' &&
|
|
48
|
-
message.MessageID
|
|
49
|
-
? message.MessageID
|
|
50
|
-
: undefined;
|
|
51
|
-
const submittedAt = message &&
|
|
52
|
-
typeof message === 'object' &&
|
|
53
|
-
'ReceivedAt' in message &&
|
|
54
|
-
typeof message.ReceivedAt === 'string' &&
|
|
55
|
-
day(message.ReceivedAt).isValid()
|
|
56
|
-
? message.ReceivedAt
|
|
57
|
-
: undefined;
|
|
58
|
-
if (!messageId || !submittedAt) {
|
|
42
|
+
const message = result.data.Messages.find(({ Metadata }) => Metadata.deliveryId === deliveryId);
|
|
43
|
+
if (!message) {
|
|
59
44
|
throw new EmailDeliveryError('Postmark returned an invalid response');
|
|
60
45
|
}
|
|
61
|
-
return {
|
|
46
|
+
return {
|
|
47
|
+
httpStatus: response.status,
|
|
48
|
+
messageId: message.MessageID,
|
|
49
|
+
submittedAt: message.ReceivedAt,
|
|
50
|
+
};
|
|
62
51
|
}
|
|
63
52
|
//# sourceMappingURL=find-postmark-email.js.map
|
|
@@ -1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AAO,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CACvC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,UAAU,CACrD,CAAC;IACF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,kBAAkB,CAAC,uCAAuC,CAAC,CAAC;IACxE,CAAC;IAED,OAAO;QACL,UAAU,EAAE,QAAQ,CAAC,MAAM;QAC3B,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,WAAW,EAAE,OAAO,CAAC,UAAU;KAChC,CAAC;AACJ,CAAC","sourcesContent":["import { day } from '@vrplatform/utils';\nimport { z } from 'zod';\nimport { EmailDeliveryError } from './send-email';\n\nconst postmarkMessagesResponseSchema = z.object({\n TotalCount: z.number().int().nonnegative(),\n Messages: z.array(\n z.object({\n MessageID: z.string().min(1),\n ReceivedAt: z.string().refine((value) => day(value).isValid()),\n Metadata: z.object({ deliveryId: z.string() }).passthrough(),\n })\n ),\n});\n\nexport async function findPostmarkEmail(\n deliveryId: string,\n options: {\n fetch?: (\n input: string | URL | Request,\n init?: RequestInit\n ) => Promise<Response>;\n postmarkToken?: string;\n }\n) {\n if (!options.postmarkToken) {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n undefined,\n false,\n false\n );\n }\n\n const url = new URL('https://api.postmarkapp.com/messages/outbound');\n url.searchParams.set('count', '1');\n url.searchParams.set('offset', '0');\n url.searchParams.set('messagestream', 'outbound');\n url.searchParams.set('metadata_deliveryId', deliveryId);\n const response = await (options.fetch ?? fetch)(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n 'X-Postmark-Server-Token': options.postmarkToken,\n },\n });\n const providerResponse: unknown = await response.json().catch(() => ({}));\n\n if (!response.ok) {\n throw new EmailDeliveryError(\n 'Postmark message lookup failed',\n {\n provider: 'postmark',\n providerCategory: 'rejected',\n httpStatus: response.status,\n },\n false,\n response.status === 429 || response.status >= 500\n );\n }\n\n const result = postmarkMessagesResponseSchema.safeParse(providerResponse);\n if (!result.success) {\n throw new EmailDeliveryError('Postmark returned an invalid response');\n }\n if (result.data.TotalCount === 0) return undefined;\n\n const message = result.data.Messages.find(\n ({ Metadata }) => Metadata.deliveryId === deliveryId\n );\n if (!message) {\n throw new EmailDeliveryError('Postmark returned an invalid response');\n }\n\n return {\n httpStatus: response.status,\n messageId: message.MessageID,\n submittedAt: message.ReceivedAt,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC","sourcesContent":["export * from './find-postmark-email';\nexport * from './send-email';\n"]}
|
|
@@ -14,6 +14,12 @@ export declare class EmailDeliveryError extends Error {
|
|
|
14
14
|
readonly retryable: boolean;
|
|
15
15
|
constructor(message: string, details?: EmailDeliveryErrorDetails | undefined, expected?: boolean, retryable?: boolean);
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Formats a verified sender address with a display name for the From header.
|
|
19
|
+
* Registrations store bare addresses; recipients should still see the company
|
|
20
|
+
* name the way they see `VRPlatform <notifications@vrplatform.app>`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatSenderIdentity(name: string | null | undefined, address: string): string;
|
|
17
23
|
export declare function sendEmail(data: {
|
|
18
24
|
to: string;
|
|
19
25
|
subject: string;
|
|
@@ -22,6 +28,7 @@ export declare function sendEmail(data: {
|
|
|
22
28
|
replyTo?: string;
|
|
23
29
|
tag?: string;
|
|
24
30
|
metadata?: Record<string, string>;
|
|
31
|
+
from?: string;
|
|
25
32
|
}, options: {
|
|
26
33
|
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
27
34
|
postmarkToken?: string;
|
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { day } from '@vrplatform/utils';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const postmarkErrorCodeSchema = z.number().int().nonnegative();
|
|
4
|
+
const postmarkResponseErrorCodeSchema = z
|
|
5
|
+
.object({ ErrorCode: postmarkErrorCodeSchema })
|
|
6
|
+
.transform(({ ErrorCode }) => ErrorCode);
|
|
7
|
+
const postmarkHeaderErrorCodeSchema = z
|
|
8
|
+
.string()
|
|
9
|
+
.regex(/^\d+$/)
|
|
10
|
+
.transform(Number)
|
|
11
|
+
.pipe(postmarkErrorCodeSchema);
|
|
12
|
+
const postmarkSuccessResponseSchema = z.object({
|
|
13
|
+
ErrorCode: z.literal(0),
|
|
14
|
+
MessageID: z.string().min(1),
|
|
15
|
+
SubmittedAt: z.string().refine((value) => day(value).isValid()),
|
|
16
|
+
});
|
|
17
|
+
function parseOptional(schema, value) {
|
|
18
|
+
const result = schema.safeParse(value);
|
|
19
|
+
if (result.success)
|
|
20
|
+
return result.data;
|
|
21
|
+
}
|
|
2
22
|
export class EmailDeliveryError extends Error {
|
|
3
23
|
details;
|
|
4
24
|
expected;
|
|
@@ -11,6 +31,15 @@ export class EmailDeliveryError extends Error {
|
|
|
11
31
|
this.name = 'EmailDeliveryError';
|
|
12
32
|
}
|
|
13
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Formats a verified sender address with a display name for the From header.
|
|
36
|
+
* Registrations store bare addresses; recipients should still see the company
|
|
37
|
+
* name the way they see `VRPlatform <notifications@vrplatform.app>`.
|
|
38
|
+
*/
|
|
39
|
+
export function formatSenderIdentity(name, address) {
|
|
40
|
+
const display = (name ?? '').replace(/[\r\n"<>]/g, '').trim();
|
|
41
|
+
return display ? `"${display}" <${address}>` : address;
|
|
42
|
+
}
|
|
14
43
|
export async function sendEmail(data, options) {
|
|
15
44
|
if (!options.postmarkToken) {
|
|
16
45
|
throw new EmailDeliveryError('Postmark is not configured', undefined, false, false);
|
|
@@ -23,7 +52,7 @@ export async function sendEmail(data, options) {
|
|
|
23
52
|
'X-Postmark-Server-Token': options.postmarkToken,
|
|
24
53
|
},
|
|
25
54
|
body: JSON.stringify({
|
|
26
|
-
From: 'VRPlatform <notifications@vrplatform.app>',
|
|
55
|
+
From: data.from ?? 'VRPlatform <notifications@vrplatform.app>',
|
|
27
56
|
To: data.to,
|
|
28
57
|
Subject: data.subject,
|
|
29
58
|
ReplyTo: data.replyTo,
|
|
@@ -35,22 +64,8 @@ export async function sendEmail(data, options) {
|
|
|
35
64
|
}),
|
|
36
65
|
});
|
|
37
66
|
const providerResponse = await response.json().catch(() => ({}));
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
'ErrorCode' in providerResponse &&
|
|
41
|
-
typeof providerResponse.ErrorCode === 'number'
|
|
42
|
-
? providerResponse.ErrorCode
|
|
43
|
-
: undefined;
|
|
44
|
-
const headerErrorCode = response.headers.get('X-PM-ApiErrorCode');
|
|
45
|
-
const errorCode = responseErrorCode ??
|
|
46
|
-
(headerErrorCode && /^\d+$/.test(headerErrorCode)
|
|
47
|
-
? Number(headerErrorCode)
|
|
48
|
-
: undefined);
|
|
49
|
-
const postmarkErrorCode = typeof errorCode === 'number' &&
|
|
50
|
-
Number.isSafeInteger(errorCode) &&
|
|
51
|
-
errorCode >= 0
|
|
52
|
-
? errorCode
|
|
53
|
-
: undefined;
|
|
67
|
+
const postmarkErrorCode = parseOptional(postmarkResponseErrorCodeSchema, providerResponse) ??
|
|
68
|
+
parseOptional(postmarkHeaderErrorCodeSchema, response.headers.get('X-PM-ApiErrorCode'));
|
|
54
69
|
if (!response.ok ||
|
|
55
70
|
(postmarkErrorCode !== undefined && postmarkErrorCode !== 0)) {
|
|
56
71
|
const inactiveRecipient = response.status === 422 && postmarkErrorCode === 406;
|
|
@@ -65,21 +80,8 @@ export async function sendEmail(data, options) {
|
|
|
65
80
|
}
|
|
66
81
|
throw new EmailDeliveryError('Postmark rejected the email', details, false, response.status === 429 || response.status >= 500);
|
|
67
82
|
}
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
'MessageID' in providerResponse &&
|
|
71
|
-
typeof providerResponse.MessageID === 'string' &&
|
|
72
|
-
providerResponse.MessageID
|
|
73
|
-
? providerResponse.MessageID
|
|
74
|
-
: undefined;
|
|
75
|
-
const submittedAt = providerResponse !== null &&
|
|
76
|
-
typeof providerResponse === 'object' &&
|
|
77
|
-
'SubmittedAt' in providerResponse &&
|
|
78
|
-
typeof providerResponse.SubmittedAt === 'string' &&
|
|
79
|
-
day(providerResponse.SubmittedAt).isValid()
|
|
80
|
-
? providerResponse.SubmittedAt
|
|
81
|
-
: undefined;
|
|
82
|
-
if (!messageId || !submittedAt || postmarkErrorCode !== 0) {
|
|
83
|
+
const result = postmarkSuccessResponseSchema.safeParse(providerResponse);
|
|
84
|
+
if (!result.success) {
|
|
83
85
|
throw new EmailDeliveryError('Postmark returned an invalid response', {
|
|
84
86
|
provider: 'postmark',
|
|
85
87
|
providerCategory: 'rejected',
|
|
@@ -89,8 +91,8 @@ export async function sendEmail(data, options) {
|
|
|
89
91
|
}
|
|
90
92
|
return {
|
|
91
93
|
httpStatus: response.status,
|
|
92
|
-
messageId,
|
|
93
|
-
submittedAt,
|
|
94
|
+
messageId: result.data.MessageID,
|
|
95
|
+
submittedAt: result.data.SubmittedAt,
|
|
94
96
|
};
|
|
95
97
|
}
|
|
96
98
|
export async function settleEmailDeliveries(deliveries) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-email.js","sourceRoot":"src/","sources":["utils/send-email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAgBxC,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGzB;IACA;IACA;IAJlB,YACE,OAAe,EACC,OAAmC,EACnC,WAAW,KAAK,EAChB,YAAY,IAAI;QAEhC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,YAAO,G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QAC7B,QAAQ,EAAE,cAAc;KACzB,CAAC;IACF,IAAI,uBAAuB,YAAY,kBAAkB,EAAE,CAAC;QAC1D,IAAI,uBAAuB,CAAC,OAAO,KAAK,4BAA4B,EAAE,CAAC;YACrE,MAAM,IAAI,kBAAkB,CAC1B,4BAA4B,EAC5B,OAAO,EACP,KAAK,EACL,KAAK,CACN,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,kBAAkB,CAC1B,6BAA6B,EAC7B,OAAO,EACP,KAAK,EACL,uBAAuB,CAAC,SAAS,CAClC,CAAC;IACJ,CAAC;IACD,IAAI,WAAW,IAAI,kBAAkB,YAAY,kBAAkB,EAAE,CAAC;QACpE,MAAM,IAAI,kBAAkB,CAC1B,gCAAgC,EAChC,OAAO,EACP,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,kBAAkB,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { day } from '@vrplatform/utils';\n\ntype EmailDeliveryFailureDetails = {\n httpStatus: number;\n postmarkErrorCode?: number;\n provider: 'postmark';\n providerCategory: 'inactiveRecipient' | 'rejected';\n};\n\ntype EmailDeliveryErrorDetails =\n | EmailDeliveryFailureDetails\n | {\n failureCount: number;\n failures: EmailDeliveryFailureDetails[];\n };\n\nexport class EmailDeliveryError extends Error {\n constructor(\n message: string,\n public readonly details?: EmailDeliveryErrorDetails,\n public readonly expected = false,\n public readonly retryable = true\n ) {\n super(message);\n this.name = 'EmailDeliveryError';\n }\n}\n\nexport async function sendEmail(\n data: {\n to: string;\n subject: string;\n text: string;\n html: string;\n replyTo?: string;\n tag?: string;\n metadata?: Record<string, string>;\n },\n options: {\n fetch?: (\n input: string | URL | Request,\n init?: RequestInit\n ) => Promise<Response>;\n postmarkToken?: string;\n }\n) {\n if (!options.postmarkToken) {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n undefined,\n false,\n false\n );\n }\n\n const response = await (options.fetch ?? fetch)(\n 'https://api.postmarkapp.com/email',\n {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'X-Postmark-Server-Token': options.postmarkToken,\n },\n body: JSON.stringify({\n From: 'VRPlatform <notifications@vrplatform.app>',\n To: data.to,\n Subject: data.subject,\n ReplyTo: data.replyTo,\n TextBody: data.text,\n HtmlBody: data.html,\n MessageStream: 'outbound',\n Tag: data.tag,\n Metadata: data.metadata,\n }),\n }\n );\n\n const providerResponse: unknown = await response.json().catch(() => ({}));\n const responseErrorCode =\n providerResponse !== null &&\n typeof providerResponse === 'object' &&\n 'ErrorCode' in providerResponse &&\n typeof providerResponse.ErrorCode === 'number'\n ? providerResponse.ErrorCode\n : undefined;\n const headerErrorCode = response.headers.get('X-PM-ApiErrorCode');\n const errorCode =\n responseErrorCode ??\n (headerErrorCode && /^\\d+$/.test(headerErrorCode)\n ? Number(headerErrorCode)\n : undefined);\n const postmarkErrorCode =\n typeof errorCode === 'number' &&\n Number.isSafeInteger(errorCode) &&\n errorCode >= 0\n ? errorCode\n : undefined;\n\n if (\n !response.ok ||\n (postmarkErrorCode !== undefined && postmarkErrorCode !== 0)\n ) {\n const inactiveRecipient =\n response.status === 422 && postmarkErrorCode === 406;\n const details: EmailDeliveryFailureDetails = {\n provider: 'postmark',\n providerCategory: inactiveRecipient ? 'inactiveRecipient' : 'rejected',\n httpStatus: response.status,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n };\n\n if (inactiveRecipient) {\n throw new EmailDeliveryError(\n 'Postmark recipient is inactive',\n details,\n true,\n false\n );\n }\n\n throw new EmailDeliveryError(\n 'Postmark rejected the email',\n details,\n false,\n response.status === 429 || response.status >= 500\n );\n }\n\n const messageId =\n providerResponse !== null &&\n typeof providerResponse === 'object' &&\n 'MessageID' in providerResponse &&\n typeof providerResponse.MessageID === 'string' &&\n providerResponse.MessageID\n ? providerResponse.MessageID\n : undefined;\n const submittedAt =\n providerResponse !== null &&\n typeof providerResponse === 'object' &&\n 'SubmittedAt' in providerResponse &&\n typeof providerResponse.SubmittedAt === 'string' &&\n day(providerResponse.SubmittedAt).isValid()\n ? providerResponse.SubmittedAt\n : undefined;\n if (!messageId || !submittedAt || postmarkErrorCode !== 0) {\n throw new EmailDeliveryError('Postmark returned an invalid response', {\n provider: 'postmark',\n providerCategory: 'rejected',\n httpStatus: response.status,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n });\n }\n\n return {\n httpStatus: response.status,\n messageId,\n submittedAt,\n };\n}\n\nexport async function settleEmailDeliveries(deliveries: Promise<unknown>[]) {\n const failures = (await Promise.allSettled(deliveries)).filter(\n (result) => result.status === 'rejected'\n );\n if (failures.length === 0) return;\n\n const unexpectedDeliveryError = failures.find(\n (failure) =>\n failure.reason instanceof EmailDeliveryError && !failure.reason.expected\n )?.reason;\n const allExpected = failures.every(\n (failure) =>\n failure.reason instanceof EmailDeliveryError && failure.reason.expected\n );\n const firstDeliveryError = failures.find(\n (failure) => failure.reason instanceof EmailDeliveryError\n )?.reason;\n const failureDetails = failures.flatMap((failure) => {\n if (\n !(failure.reason instanceof EmailDeliveryError) ||\n !failure.reason.details ||\n !('provider' in failure.reason.details)\n ) {\n return [];\n }\n const { httpStatus, postmarkErrorCode, provider, providerCategory } =\n failure.reason.details;\n return [\n {\n httpStatus,\n provider,\n providerCategory,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n },\n ];\n });\n\n const details: EmailDeliveryErrorDetails = {\n failureCount: failures.length,\n failures: failureDetails,\n };\n if (unexpectedDeliveryError instanceof EmailDeliveryError) {\n if (unexpectedDeliveryError.message === 'Postmark is not configured') {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n details,\n false,\n false\n );\n }\n throw new EmailDeliveryError(\n 'Postmark rejected the email',\n details,\n false,\n unexpectedDeliveryError.retryable\n );\n }\n if (allExpected && firstDeliveryError instanceof EmailDeliveryError) {\n throw new EmailDeliveryError(\n 'Postmark recipient is inactive',\n details,\n true,\n false\n );\n }\n throw new EmailDeliveryError('Email delivery failed', details);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"send-email.js","sourceRoot":"src/","sources":["utils/send-email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;AAC/D,MAAM,+BAA+B,GAAG,CAAC;KACtC,MAAM,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;KAC9C,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;AAC3C,MAAM,6BAA6B,GAAG,CAAC;KACpC,MAAM,EAAE;KACR,KAAK,CAAC,OAAO,CAAC;KACd,SAAS,CAAC,MAAM,CAAC;KACjB,IAAI,CAAC,uBAAuB,CAAC,CAAC;AACjC,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACvB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;CAChE,CAAC,CAAC;AAEH,SAAS,aAAa,CAAI,MAAoB,EAAE,KAAc;IAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;AACzC,CAAC;AAgBD,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGzB;IACA;IACA;IAJlB,Y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AAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,kBAAkB,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { day } from '@vrplatform/utils';\nimport { z } from 'zod';\n\nconst postmarkErrorCodeSchema = z.number().int().nonnegative();\nconst postmarkResponseErrorCodeSchema = z\n .object({ ErrorCode: postmarkErrorCodeSchema })\n .transform(({ ErrorCode }) => ErrorCode);\nconst postmarkHeaderErrorCodeSchema = z\n .string()\n .regex(/^\\d+$/)\n .transform(Number)\n .pipe(postmarkErrorCodeSchema);\nconst postmarkSuccessResponseSchema = z.object({\n ErrorCode: z.literal(0),\n MessageID: z.string().min(1),\n SubmittedAt: z.string().refine((value) => day(value).isValid()),\n});\n\nfunction parseOptional<T>(schema: z.ZodType<T>, value: unknown) {\n const result = schema.safeParse(value);\n if (result.success) return result.data;\n}\n\ntype EmailDeliveryFailureDetails = {\n httpStatus: number;\n postmarkErrorCode?: number;\n provider: 'postmark';\n providerCategory: 'inactiveRecipient' | 'rejected';\n};\n\ntype EmailDeliveryErrorDetails =\n | EmailDeliveryFailureDetails\n | {\n failureCount: number;\n failures: EmailDeliveryFailureDetails[];\n };\n\nexport class EmailDeliveryError extends Error {\n constructor(\n message: string,\n public readonly details?: EmailDeliveryErrorDetails,\n public readonly expected = false,\n public readonly retryable = true\n ) {\n super(message);\n this.name = 'EmailDeliveryError';\n }\n}\n\n/**\n * Formats a verified sender address with a display name for the From header.\n * Registrations store bare addresses; recipients should still see the company\n * name the way they see `VRPlatform <notifications@vrplatform.app>`.\n */\nexport function formatSenderIdentity(\n name: string | null | undefined,\n address: string\n) {\n const display = (name ?? '').replace(/[\\r\\n\"<>]/g, '').trim();\n return display ? `\"${display}\" <${address}>` : address;\n}\n\nexport async function sendEmail(\n data: {\n to: string;\n subject: string;\n text: string;\n html: string;\n replyTo?: string;\n tag?: string;\n metadata?: Record<string, string>;\n from?: string;\n },\n options: {\n fetch?: (\n input: string | URL | Request,\n init?: RequestInit\n ) => Promise<Response>;\n postmarkToken?: string;\n }\n) {\n if (!options.postmarkToken) {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n undefined,\n false,\n false\n );\n }\n\n const response = await (options.fetch ?? fetch)(\n 'https://api.postmarkapp.com/email',\n {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n 'X-Postmark-Server-Token': options.postmarkToken,\n },\n body: JSON.stringify({\n From: data.from ?? 'VRPlatform <notifications@vrplatform.app>',\n To: data.to,\n Subject: data.subject,\n ReplyTo: data.replyTo,\n TextBody: data.text,\n HtmlBody: data.html,\n MessageStream: 'outbound',\n Tag: data.tag,\n Metadata: data.metadata,\n }),\n }\n );\n\n const providerResponse: unknown = await response.json().catch(() => ({}));\n const postmarkErrorCode =\n parseOptional(postmarkResponseErrorCodeSchema, providerResponse) ??\n parseOptional(\n postmarkHeaderErrorCodeSchema,\n response.headers.get('X-PM-ApiErrorCode')\n );\n\n if (\n !response.ok ||\n (postmarkErrorCode !== undefined && postmarkErrorCode !== 0)\n ) {\n const inactiveRecipient =\n response.status === 422 && postmarkErrorCode === 406;\n const details: EmailDeliveryFailureDetails = {\n provider: 'postmark',\n providerCategory: inactiveRecipient ? 'inactiveRecipient' : 'rejected',\n httpStatus: response.status,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n };\n\n if (inactiveRecipient) {\n throw new EmailDeliveryError(\n 'Postmark recipient is inactive',\n details,\n true,\n false\n );\n }\n\n throw new EmailDeliveryError(\n 'Postmark rejected the email',\n details,\n false,\n response.status === 429 || response.status >= 500\n );\n }\n\n const result = postmarkSuccessResponseSchema.safeParse(providerResponse);\n if (!result.success) {\n throw new EmailDeliveryError('Postmark returned an invalid response', {\n provider: 'postmark',\n providerCategory: 'rejected',\n httpStatus: response.status,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n });\n }\n\n return {\n httpStatus: response.status,\n messageId: result.data.MessageID,\n submittedAt: result.data.SubmittedAt,\n };\n}\n\nexport async function settleEmailDeliveries(deliveries: Promise<unknown>[]) {\n const failures = (await Promise.allSettled(deliveries)).filter(\n (result) => result.status === 'rejected'\n );\n if (failures.length === 0) return;\n\n const unexpectedDeliveryError = failures.find(\n (failure) =>\n failure.reason instanceof EmailDeliveryError && !failure.reason.expected\n )?.reason;\n const allExpected = failures.every(\n (failure) =>\n failure.reason instanceof EmailDeliveryError && failure.reason.expected\n );\n const firstDeliveryError = failures.find(\n (failure) => failure.reason instanceof EmailDeliveryError\n )?.reason;\n const failureDetails = failures.flatMap((failure) => {\n if (\n !(failure.reason instanceof EmailDeliveryError) ||\n !failure.reason.details ||\n !('provider' in failure.reason.details)\n ) {\n return [];\n }\n const { httpStatus, postmarkErrorCode, provider, providerCategory } =\n failure.reason.details;\n return [\n {\n httpStatus,\n provider,\n providerCategory,\n ...(postmarkErrorCode !== undefined ? { postmarkErrorCode } : {}),\n },\n ];\n });\n\n const details: EmailDeliveryErrorDetails = {\n failureCount: failures.length,\n failures: failureDetails,\n };\n if (unexpectedDeliveryError instanceof EmailDeliveryError) {\n if (unexpectedDeliveryError.message === 'Postmark is not configured') {\n throw new EmailDeliveryError(\n 'Postmark is not configured',\n details,\n false,\n false\n );\n }\n throw new EmailDeliveryError(\n 'Postmark rejected the email',\n details,\n false,\n unexpectedDeliveryError.retryable\n );\n }\n if (allExpected && firstDeliveryError instanceof EmailDeliveryError) {\n throw new EmailDeliveryError(\n 'Postmark recipient is inactive',\n details,\n true,\n false\n );\n }\n throw new EmailDeliveryError('Email delivery failed', details);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vrplatform/email",
|
|
3
|
-
"version": "1.0.2-stage.
|
|
3
|
+
"version": "1.0.2-stage.573",
|
|
4
4
|
"description": "VRTrust transactional email templates and Postmark transport",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"main": "build/main/index.js",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"@react-email/img": "0.0.9",
|
|
31
31
|
"@react-email/preview": "0.0.10",
|
|
32
32
|
"@react-email/render": "0.0.17",
|
|
33
|
-
"@react-email/text": "0.0.9"
|
|
33
|
+
"@react-email/text": "0.0.9",
|
|
34
|
+
"zod": "^4.4.3"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
37
|
"@vrplatform/utils": "*",
|
|
@@ -12,7 +12,7 @@ import type { EmailBaseProps } from '../types';
|
|
|
12
12
|
type Props = {
|
|
13
13
|
children: React.ReactNode;
|
|
14
14
|
title: string;
|
|
15
|
-
tenant: Omit<EmailBaseProps['tenant'], 'name'
|
|
15
|
+
tenant: Omit<EmailBaseProps['tenant'], 'name'> & { name?: string };
|
|
16
16
|
mode: EmailBaseProps['mode'];
|
|
17
17
|
shortDescription?: string;
|
|
18
18
|
};
|
|
@@ -68,7 +68,11 @@ export const EmailContainer = (props: Props) => {
|
|
|
68
68
|
);
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
const Content = ({
|
|
71
|
+
const Content = ({
|
|
72
|
+
children,
|
|
73
|
+
tenant: { logo: tenantLogo, name, showPlatformBranding = true },
|
|
74
|
+
mode,
|
|
75
|
+
}: Props) => {
|
|
72
76
|
return (
|
|
73
77
|
<>
|
|
74
78
|
{tenantLogo ? (
|
|
@@ -86,6 +90,8 @@ const Content = ({ children, tenant: { logo: tenantLogo }, mode }: Props) => {
|
|
|
86
90
|
>
|
|
87
91
|
<Img src={tenantLogo} alt={'Logo'} width={70} />
|
|
88
92
|
</div>
|
|
93
|
+
) : !showPlatformBranding ? (
|
|
94
|
+
<Text>{name}</Text>
|
|
89
95
|
) : mode === 'send' ? (
|
|
90
96
|
<Img
|
|
91
97
|
src={'https://staging.portal.vrplatform.app/logo.png'}
|
|
@@ -105,7 +111,7 @@ const Content = ({ children, tenant: { logo: tenantLogo }, mode }: Props) => {
|
|
|
105
111
|
|
|
106
112
|
{children}
|
|
107
113
|
|
|
108
|
-
<Footer />
|
|
114
|
+
{showPlatformBranding ? <Footer /> : <Text>{name}</Text>}
|
|
109
115
|
</>
|
|
110
116
|
);
|
|
111
117
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { day } from '@vrplatform/utils';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import { EmailDeliveryError } from './send-email';
|
|
3
4
|
|
|
5
|
+
const postmarkMessagesResponseSchema = z.object({
|
|
6
|
+
TotalCount: z.number().int().nonnegative(),
|
|
7
|
+
Messages: z.array(
|
|
8
|
+
z.object({
|
|
9
|
+
MessageID: z.string().min(1),
|
|
10
|
+
ReceivedAt: z.string().refine((value) => day(value).isValid()),
|
|
11
|
+
Metadata: z.object({ deliveryId: z.string() }).passthrough(),
|
|
12
|
+
})
|
|
13
|
+
),
|
|
14
|
+
});
|
|
15
|
+
|
|
4
16
|
export async function findPostmarkEmail(
|
|
5
17
|
deliveryId: string,
|
|
6
18
|
options: {
|
|
@@ -47,47 +59,22 @@ export async function findPostmarkEmail(
|
|
|
47
59
|
);
|
|
48
60
|
}
|
|
49
61
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
typeof providerResponse !== 'object' ||
|
|
53
|
-
!('TotalCount' in providerResponse) ||
|
|
54
|
-
typeof providerResponse.TotalCount !== 'number' ||
|
|
55
|
-
!('Messages' in providerResponse) ||
|
|
56
|
-
!Array.isArray(providerResponse.Messages)
|
|
57
|
-
) {
|
|
62
|
+
const result = postmarkMessagesResponseSchema.safeParse(providerResponse);
|
|
63
|
+
if (!result.success) {
|
|
58
64
|
throw new EmailDeliveryError('Postmark returned an invalid response');
|
|
59
65
|
}
|
|
60
|
-
if (
|
|
66
|
+
if (result.data.TotalCount === 0) return undefined;
|
|
61
67
|
|
|
62
|
-
const message =
|
|
63
|
-
(
|
|
64
|
-
value &&
|
|
65
|
-
typeof value === 'object' &&
|
|
66
|
-
'Metadata' in value &&
|
|
67
|
-
value.Metadata &&
|
|
68
|
-
typeof value.Metadata === 'object' &&
|
|
69
|
-
'deliveryId' in value.Metadata &&
|
|
70
|
-
value.Metadata.deliveryId === deliveryId
|
|
68
|
+
const message = result.data.Messages.find(
|
|
69
|
+
({ Metadata }) => Metadata.deliveryId === deliveryId
|
|
71
70
|
);
|
|
72
|
-
|
|
73
|
-
message &&
|
|
74
|
-
typeof message === 'object' &&
|
|
75
|
-
'MessageID' in message &&
|
|
76
|
-
typeof message.MessageID === 'string' &&
|
|
77
|
-
message.MessageID
|
|
78
|
-
? message.MessageID
|
|
79
|
-
: undefined;
|
|
80
|
-
const submittedAt =
|
|
81
|
-
message &&
|
|
82
|
-
typeof message === 'object' &&
|
|
83
|
-
'ReceivedAt' in message &&
|
|
84
|
-
typeof message.ReceivedAt === 'string' &&
|
|
85
|
-
day(message.ReceivedAt).isValid()
|
|
86
|
-
? message.ReceivedAt
|
|
87
|
-
: undefined;
|
|
88
|
-
if (!messageId || !submittedAt) {
|
|
71
|
+
if (!message) {
|
|
89
72
|
throw new EmailDeliveryError('Postmark returned an invalid response');
|
|
90
73
|
}
|
|
91
74
|
|
|
92
|
-
return {
|
|
75
|
+
return {
|
|
76
|
+
httpStatus: response.status,
|
|
77
|
+
messageId: message.MessageID,
|
|
78
|
+
submittedAt: message.ReceivedAt,
|
|
79
|
+
};
|
|
93
80
|
}
|
package/src/utils/index.ts
CHANGED
package/src/utils/send-email.ts
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import { day } from '@vrplatform/utils';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const postmarkErrorCodeSchema = z.number().int().nonnegative();
|
|
5
|
+
const postmarkResponseErrorCodeSchema = z
|
|
6
|
+
.object({ ErrorCode: postmarkErrorCodeSchema })
|
|
7
|
+
.transform(({ ErrorCode }) => ErrorCode);
|
|
8
|
+
const postmarkHeaderErrorCodeSchema = z
|
|
9
|
+
.string()
|
|
10
|
+
.regex(/^\d+$/)
|
|
11
|
+
.transform(Number)
|
|
12
|
+
.pipe(postmarkErrorCodeSchema);
|
|
13
|
+
const postmarkSuccessResponseSchema = z.object({
|
|
14
|
+
ErrorCode: z.literal(0),
|
|
15
|
+
MessageID: z.string().min(1),
|
|
16
|
+
SubmittedAt: z.string().refine((value) => day(value).isValid()),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function parseOptional<T>(schema: z.ZodType<T>, value: unknown) {
|
|
20
|
+
const result = schema.safeParse(value);
|
|
21
|
+
if (result.success) return result.data;
|
|
22
|
+
}
|
|
2
23
|
|
|
3
24
|
type EmailDeliveryFailureDetails = {
|
|
4
25
|
httpStatus: number;
|
|
@@ -26,6 +47,19 @@ export class EmailDeliveryError extends Error {
|
|
|
26
47
|
}
|
|
27
48
|
}
|
|
28
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Formats a verified sender address with a display name for the From header.
|
|
52
|
+
* Registrations store bare addresses; recipients should still see the company
|
|
53
|
+
* name the way they see `VRPlatform <notifications@vrplatform.app>`.
|
|
54
|
+
*/
|
|
55
|
+
export function formatSenderIdentity(
|
|
56
|
+
name: string | null | undefined,
|
|
57
|
+
address: string
|
|
58
|
+
) {
|
|
59
|
+
const display = (name ?? '').replace(/[\r\n"<>]/g, '').trim();
|
|
60
|
+
return display ? `"${display}" <${address}>` : address;
|
|
61
|
+
}
|
|
62
|
+
|
|
29
63
|
export async function sendEmail(
|
|
30
64
|
data: {
|
|
31
65
|
to: string;
|
|
@@ -35,6 +69,7 @@ export async function sendEmail(
|
|
|
35
69
|
replyTo?: string;
|
|
36
70
|
tag?: string;
|
|
37
71
|
metadata?: Record<string, string>;
|
|
72
|
+
from?: string;
|
|
38
73
|
},
|
|
39
74
|
options: {
|
|
40
75
|
fetch?: (
|
|
@@ -63,7 +98,7 @@ export async function sendEmail(
|
|
|
63
98
|
'X-Postmark-Server-Token': options.postmarkToken,
|
|
64
99
|
},
|
|
65
100
|
body: JSON.stringify({
|
|
66
|
-
From: 'VRPlatform <notifications@vrplatform.app>',
|
|
101
|
+
From: data.from ?? 'VRPlatform <notifications@vrplatform.app>',
|
|
67
102
|
To: data.to,
|
|
68
103
|
Subject: data.subject,
|
|
69
104
|
ReplyTo: data.replyTo,
|
|
@@ -77,25 +112,12 @@ export async function sendEmail(
|
|
|
77
112
|
);
|
|
78
113
|
|
|
79
114
|
const providerResponse: unknown = await response.json().catch(() => ({}));
|
|
80
|
-
const responseErrorCode =
|
|
81
|
-
providerResponse !== null &&
|
|
82
|
-
typeof providerResponse === 'object' &&
|
|
83
|
-
'ErrorCode' in providerResponse &&
|
|
84
|
-
typeof providerResponse.ErrorCode === 'number'
|
|
85
|
-
? providerResponse.ErrorCode
|
|
86
|
-
: undefined;
|
|
87
|
-
const headerErrorCode = response.headers.get('X-PM-ApiErrorCode');
|
|
88
|
-
const errorCode =
|
|
89
|
-
responseErrorCode ??
|
|
90
|
-
(headerErrorCode && /^\d+$/.test(headerErrorCode)
|
|
91
|
-
? Number(headerErrorCode)
|
|
92
|
-
: undefined);
|
|
93
115
|
const postmarkErrorCode =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
116
|
+
parseOptional(postmarkResponseErrorCodeSchema, providerResponse) ??
|
|
117
|
+
parseOptional(
|
|
118
|
+
postmarkHeaderErrorCodeSchema,
|
|
119
|
+
response.headers.get('X-PM-ApiErrorCode')
|
|
120
|
+
);
|
|
99
121
|
|
|
100
122
|
if (
|
|
101
123
|
!response.ok ||
|
|
@@ -127,23 +149,8 @@ export async function sendEmail(
|
|
|
127
149
|
);
|
|
128
150
|
}
|
|
129
151
|
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
typeof providerResponse === 'object' &&
|
|
133
|
-
'MessageID' in providerResponse &&
|
|
134
|
-
typeof providerResponse.MessageID === 'string' &&
|
|
135
|
-
providerResponse.MessageID
|
|
136
|
-
? providerResponse.MessageID
|
|
137
|
-
: undefined;
|
|
138
|
-
const submittedAt =
|
|
139
|
-
providerResponse !== null &&
|
|
140
|
-
typeof providerResponse === 'object' &&
|
|
141
|
-
'SubmittedAt' in providerResponse &&
|
|
142
|
-
typeof providerResponse.SubmittedAt === 'string' &&
|
|
143
|
-
day(providerResponse.SubmittedAt).isValid()
|
|
144
|
-
? providerResponse.SubmittedAt
|
|
145
|
-
: undefined;
|
|
146
|
-
if (!messageId || !submittedAt || postmarkErrorCode !== 0) {
|
|
152
|
+
const result = postmarkSuccessResponseSchema.safeParse(providerResponse);
|
|
153
|
+
if (!result.success) {
|
|
147
154
|
throw new EmailDeliveryError('Postmark returned an invalid response', {
|
|
148
155
|
provider: 'postmark',
|
|
149
156
|
providerCategory: 'rejected',
|
|
@@ -154,8 +161,8 @@ export async function sendEmail(
|
|
|
154
161
|
|
|
155
162
|
return {
|
|
156
163
|
httpStatus: response.status,
|
|
157
|
-
messageId,
|
|
158
|
-
submittedAt,
|
|
164
|
+
messageId: result.data.MessageID,
|
|
165
|
+
submittedAt: result.data.SubmittedAt,
|
|
159
166
|
};
|
|
160
167
|
}
|
|
161
168
|
|