@ultimat3/mail 31.46.0 → 31.47.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.
- package/README.md +6 -0
- package/package.json +7 -7
- package/src/driver-resend.ts +3 -6
- package/src/driver-ses.ts +2 -5
- package/src/ses-failure.ts +2 -6
package/README.md
CHANGED
|
@@ -7,6 +7,12 @@ every string is an i18n key, every colour is a design token, and delivery is a j
|
|
|
7
7
|
|
|
8
8
|
```ts
|
|
9
9
|
import { defineMail, send, blocks, t } from '@ultimat3/mail';
|
|
10
|
+
import { type Ctx } from '@ultimat3/core';
|
|
11
|
+
|
|
12
|
+
declare const user: { readonly id: string; readonly name: string; readonly email: string; readonly role: string };
|
|
13
|
+
|
|
14
|
+
declare const url: string;
|
|
15
|
+
declare const ctx: Ctx;
|
|
10
16
|
|
|
11
17
|
export const receiptMail = defineMail({
|
|
12
18
|
id: 'receipt',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/mail",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.47.0",
|
|
4
4
|
"description": "Transactional email as data: one template renders HTML and text, sent through a job.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"test": "bun test"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@ultimat3/core": "31.
|
|
48
|
-
"@ultimat3/i18n": "31.
|
|
49
|
-
"@ultimat3/jobs": "31.
|
|
50
|
-
"@ultimat3/schema": "31.
|
|
51
|
-
"@ultimat3/storage": "31.
|
|
52
|
-
"@ultimat3/time": "31.
|
|
47
|
+
"@ultimat3/core": "31.47.0",
|
|
48
|
+
"@ultimat3/i18n": "31.47.0",
|
|
49
|
+
"@ultimat3/jobs": "31.47.0",
|
|
50
|
+
"@ultimat3/schema": "31.47.0",
|
|
51
|
+
"@ultimat3/storage": "31.47.0",
|
|
52
|
+
"@ultimat3/time": "31.47.0"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/driver-resend.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
ConfigInvalidError,
|
|
7
7
|
EnvMissingError,
|
|
8
8
|
finiteCount,
|
|
9
|
+
isJsonObject,
|
|
9
10
|
// The status table is core's: this package's copy and `packages/cache/src/purge-http.ts`'s were
|
|
10
11
|
// byte-identical in two packages that cannot import each other, so one was always going to be
|
|
11
12
|
// edited alone. A throttle or a transient conflict can land unchanged; every other 4xx here is a
|
|
@@ -72,17 +73,13 @@ function fixFor(status: number): string {
|
|
|
72
73
|
return 'check the request against https://resend.com/docs/api-reference/emails/send-email';
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
76
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
76
|
/** Prefers Resend's own message; falls back to the raw body, capped so a huge page can't flood logs. */
|
|
80
77
|
async function detailFor(response: Response): Promise<string> {
|
|
81
78
|
const text = await response.text().catch(() => '');
|
|
82
79
|
if (text === '') return `HTTP ${response.status} with an empty body`;
|
|
83
80
|
try {
|
|
84
81
|
const parsed: unknown = JSON.parse(text);
|
|
85
|
-
const message =
|
|
82
|
+
const message = isJsonObject(parsed) ? parsed['message'] : undefined;
|
|
86
83
|
if (typeof message === 'string' && message !== '') return message;
|
|
87
84
|
} catch {
|
|
88
85
|
// Not JSON — fall through to the truncated raw text below.
|
|
@@ -93,7 +90,7 @@ async function detailFor(response: Response): Promise<string> {
|
|
|
93
90
|
/** A 2xx is acceptance regardless of body shape; the id is best-effort, never a reason to fail. */
|
|
94
91
|
async function idFor(response: Response, message: MailMessage): Promise<string> {
|
|
95
92
|
const parsed: unknown = await response.json().catch(() => undefined);
|
|
96
|
-
const id =
|
|
93
|
+
const id = isJsonObject(parsed) ? parsed['id'] : undefined;
|
|
97
94
|
if (typeof id === 'string' && id !== '') return id;
|
|
98
95
|
const local = `resend_${nanoid(12)}`;
|
|
99
96
|
logger.warn('mail.resend.no_id', { mailId: message.mailId, id: local });
|
package/src/driver-ses.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ConfigInvalidError,
|
|
10
10
|
EnvMissingError,
|
|
11
11
|
finiteCount,
|
|
12
|
+
isJsonObject,
|
|
12
13
|
isUltimateError,
|
|
13
14
|
liveClock,
|
|
14
15
|
nanoid,
|
|
@@ -101,10 +102,6 @@ function requireFrom(from: string): string {
|
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
105
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
105
|
/**
|
|
109
106
|
* `Destination` is the envelope, and it is sent even though the raw message holds `To:` and `Cc:`
|
|
110
107
|
* — `Bcc` is never a header (`mime.ts`), so without it the blind list would receive nothing.
|
|
@@ -207,7 +204,7 @@ export function sesMailDriver(options: SesDriverOptions): MailDriver {
|
|
|
207
204
|
}
|
|
208
205
|
|
|
209
206
|
const parsed: unknown = await response.json().catch(() => undefined);
|
|
210
|
-
const id =
|
|
207
|
+
const id = isJsonObject(parsed) ? parsed['MessageId'] : undefined;
|
|
211
208
|
// A 2xx is acceptance. The id is what SNS notifications name the message by, so a local one
|
|
212
209
|
// is a correlation lost — but never a reason to report an accepted send as failed.
|
|
213
210
|
const result = resultFor(
|
package/src/ses-failure.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// its status does — `MessageRejected`, `SendingPausedException` and a bad request are all 400 — so
|
|
4
4
|
// the type decides, and core's status table answers only for a type this table does not know.
|
|
5
5
|
|
|
6
|
-
import { isRetryableStatus } from '@ultimat3/core';
|
|
6
|
+
import { isJsonObject, isRetryableStatus } from '@ultimat3/core';
|
|
7
7
|
|
|
8
8
|
/** What the driver needs to build `sendFailed(...)`: the verdict, the fix, and the text to show. */
|
|
9
9
|
export interface SesFailure {
|
|
@@ -71,10 +71,6 @@ function fixFor(kind: SesClass | undefined, region: string): string {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
75
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
74
|
/** `MessageRejected:http://internal.amazon.com/…` or `com.amazonaws.ses#MessageRejected` → the name. */
|
|
79
75
|
function typeName(raw: string): string | undefined {
|
|
80
76
|
const name = (raw.split(':')[0] ?? '').split('#').pop()?.trim() ?? '';
|
|
@@ -82,7 +78,7 @@ function typeName(raw: string): string | undefined {
|
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
function bodyField(body: unknown, ...keys: readonly string[]): string | undefined {
|
|
85
|
-
if (!
|
|
81
|
+
if (!isJsonObject(body)) return undefined;
|
|
86
82
|
for (const key of keys) {
|
|
87
83
|
const value = body[key];
|
|
88
84
|
if (typeof value === 'string' && value !== '') return value;
|