@hodela/site 0.3.0 → 0.3.1

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.
@@ -26,7 +26,9 @@ export type EmailLogEntry = {
26
26
  error: string | null;
27
27
  createdAt: string;
28
28
  };
29
- export type EmailErrorCode = "not_configured" | "unauthorized" | "disabled" | "invalid_request" | "rate_limited" | "unavailable" | "network";
29
+ export type EmailErrorCode = "not_configured" | "unauthorized" | "disabled" | "invalid_request" | "rate_limited"
30
+ /** Tài khoản chủ web đã dùng hết hạn mức mail của tháng và không đủ credit để gửi tiếp. */
31
+ | "insufficient_credits" | "unavailable" | "network";
30
32
  export declare class HodelaEmailError extends Error {
31
33
  readonly code: EmailErrorCode;
32
34
  readonly status: number | null;
@@ -40,6 +40,8 @@ export function createHodelaEmailClient(options) {
40
40
  const message = body?.error?.message ?? `API Hodela trả về HTTP ${res.status}.`;
41
41
  if (res.status === 401)
42
42
  return new HodelaEmailError("unauthorized", message, { status: 401 });
43
+ if (res.status === 402)
44
+ return new HodelaEmailError("insufficient_credits", message, { status: 402 });
43
45
  if (res.status === 403)
44
46
  return new HodelaEmailError("disabled", message, { status: 403 });
45
47
  if (res.status === 400 || res.status === 422)
package/dist/mailer.d.ts CHANGED
@@ -13,7 +13,7 @@ export type MailInput = {
13
13
  export type MailResult = {
14
14
  sent: boolean;
15
15
  provider: MailProvider;
16
- reason?: "not_configured" | "rate_limited" | "failed" | "invalid" | "suppressed";
16
+ reason?: "not_configured" | "rate_limited" | "insufficient_credits" | "failed" | "invalid" | "suppressed";
17
17
  };
18
18
  type Env = (name: string) => string | undefined;
19
19
  type Deps = {
package/dist/mailer.js CHANGED
@@ -64,7 +64,8 @@ export function createMailer(deps) {
64
64
  catch (e) {
65
65
  const limited = e instanceof HodelaEmailError && e.code === "rate_limited";
66
66
  console.warn(`[mailer] không gửi được (${provider}): ${e instanceof Error ? e.message : String(e)}`);
67
- return { sent: false, provider, reason: limited ? "rate_limited" : "failed" };
67
+ const noCredits = e instanceof HodelaEmailError && e.code === "insufficient_credits";
68
+ return { sent: false, provider, reason: noCredits ? "insufficient_credits" : limited ? "rate_limited" : "failed" };
68
69
  }
69
70
  }
70
71
  /** Gửi tới hộp thư của chủ web (NOTIFY_EMAIL). Chưa đặt NOTIFY_EMAIL thì bỏ qua êm. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hodela/site",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",