@vectoriox/iox-ui 5.132.0 → 5.133.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/composite-core/index.d.ts +19 -2
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs +51 -6
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-mail-core.mjs +80 -2
- package/fesm2022/vectoriox-iox-ui-mail-core.mjs.map +1 -1
- package/mail-core/index.d.ts +127 -39
- package/package.json +1 -1
- package/src/composite-core/consent.ts +6 -2
- package/src/composite-core/shop-runtime.ts +47 -3
- package/src/composite-core/shop.ts +5 -0
- package/src/mail-core/mail-standing.ts +58 -0
- package/src/mail-core/mail-vocabulary.ts +3 -0
- package/src/mail-core/mail-wire.ts +62 -1
- package/src/mail-core/public-api.ts +4 -1
- package/styles/iox-design.css +14 -1
|
@@ -34,6 +34,8 @@ var MailSender;
|
|
|
34
34
|
MailSender["FormDelivery"] = "form-delivery";
|
|
35
35
|
/** the `sendEmail` element action — to the author's fixed address */
|
|
36
36
|
MailSender["SendEmailAction"] = "send-email-action";
|
|
37
|
+
/** Settings ▸ Email ▸ Send a test email — to the signed-in person's own address only (ML3-D3) */
|
|
38
|
+
MailSender["TestEmail"] = "test-email";
|
|
37
39
|
})(MailSender || (MailSender = {}));
|
|
38
40
|
/** ONE table: what kind of mail each sender sends (R-ML1). Only reminders are marketing. */
|
|
39
41
|
const MAIL_KIND_OF_SENDER = {
|
|
@@ -44,6 +46,7 @@ const MAIL_KIND_OF_SENDER = {
|
|
|
44
46
|
[MailSender.Reminder]: MailKind.Marketing,
|
|
45
47
|
[MailSender.FormDelivery]: MailKind.Transactional,
|
|
46
48
|
[MailSender.SendEmailAction]: MailKind.Transactional,
|
|
49
|
+
[MailSender.TestEmail]: MailKind.Transactional,
|
|
47
50
|
};
|
|
48
51
|
function mailKindOf(sender) {
|
|
49
52
|
return MAIL_KIND_OF_SENDER[sender];
|
|
@@ -128,6 +131,22 @@ const RELAY_MAIL_USAGE_PATH = '/instances/me/mail/usage';
|
|
|
128
131
|
const RELAY_MAX_MESSAGES = 50;
|
|
129
132
|
/** RFC 8058 one-click unsubscribe — the only headers a relayed message may carry. */
|
|
130
133
|
const RELAY_ALLOWED_HEADERS = ['List-Unsubscribe', 'List-Unsubscribe-Post'];
|
|
134
|
+
/** The mailer row's Reply-To (ML3-D1) — absent/blank = the relay's default, the studio's owner. */
|
|
135
|
+
const MAILER_REPLY_TO_KEY = 'replyTo';
|
|
136
|
+
/** At most this many test emails an hour, per studio (ML3-D3) — each counts against the month like any email. */
|
|
137
|
+
const MAIL_TEST_PER_HOUR = 5;
|
|
138
|
+
/** What became of a test email. */
|
|
139
|
+
var MailTestOutcome;
|
|
140
|
+
(function (MailTestOutcome) {
|
|
141
|
+
/** handed to IOX mail's relay or the studio's own Mailjet, which took it */
|
|
142
|
+
MailTestOutcome["Sent"] = "sent";
|
|
143
|
+
/** stored in IOX mail's outbox — the relay could not take it now; it goes when it can */
|
|
144
|
+
MailTestOutcome["Queued"] = "queued";
|
|
145
|
+
/** refused: no route, the relay's reason, Mailjet's words */
|
|
146
|
+
MailTestOutcome["Refused"] = "refused";
|
|
147
|
+
/** this hour's test emails are used */
|
|
148
|
+
MailTestOutcome["Limited"] = "limited";
|
|
149
|
+
})(MailTestOutcome || (MailTestOutcome = {}));
|
|
131
150
|
|
|
132
151
|
/** The studio's own Mailjet keys — the three an own mailer needs (the MAILER connector's `requiredKeys`, ML-D9). */
|
|
133
152
|
const OWN_MAILER_KEYS = ['publicKey', 'secretKey', 'originatorEmail'];
|
|
@@ -171,11 +190,70 @@ function planMailRoute(facts) {
|
|
|
171
190
|
return facts.ioxMail ? MailRoute.Iox : MailRoute.None;
|
|
172
191
|
}
|
|
173
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Where a studio's IOX mail stands this month (iox-mail-plan ML-D5, the ML3 board's E2). ONE reading of the relay's
|
|
195
|
+
* usage: the admin's pill, meter and note, System Health, Home and the bell (iox-cms's reconciler) all ask this — none
|
|
196
|
+
* of them compares counts with a quota on its own.
|
|
197
|
+
*/
|
|
198
|
+
var MailStanding;
|
|
199
|
+
(function (MailStanding) {
|
|
200
|
+
/** sending, under 80% of the month */
|
|
201
|
+
MailStanding["Healthy"] = "healthy";
|
|
202
|
+
/** 80% of the month's emails used — reminders still go */
|
|
203
|
+
MailStanding["Low"] = "low";
|
|
204
|
+
/** the month's emails used: reminders are paused, receipts and codes continue up to twice the month */
|
|
205
|
+
MailStanding["Full"] = "full";
|
|
206
|
+
/** twice the month's emails sent: nothing more goes until the month resets */
|
|
207
|
+
MailStanding["Ceiling"] = "ceiling";
|
|
208
|
+
/** reminders paused by complaints, bounces or the operator (ML-D7) — receipts and codes unaffected */
|
|
209
|
+
MailStanding["Paused"] = "paused";
|
|
210
|
+
/** IOX mail does not send for this studio: the relay never answered, holds no key, or the plan has none */
|
|
211
|
+
MailStanding["Off"] = "off";
|
|
212
|
+
})(MailStanding || (MailStanding = {}));
|
|
213
|
+
/** The meter turns low — and the bell says so — once this share of the month is used (ML3-D2). */
|
|
214
|
+
const MAIL_LOW_SHARE = 0.8;
|
|
215
|
+
/** The month's emails used so far (both kinds — what the quota counts). */
|
|
216
|
+
function mailEmailsUsed(usage) {
|
|
217
|
+
return Math.max(0, Number(usage?.month?.total ?? 0) || 0);
|
|
218
|
+
}
|
|
219
|
+
/** Emails left this month before reminders pause; null = unlimited (or no usage). */
|
|
220
|
+
function mailEmailsLeft(usage) {
|
|
221
|
+
if (!usage || usage.quota === null || usage.quota === undefined)
|
|
222
|
+
return null;
|
|
223
|
+
return Math.max(usage.quota - mailEmailsUsed(usage), 0);
|
|
224
|
+
}
|
|
225
|
+
/** THE standing rule. The worst line crossed wins: off → ceiling → full → paused → low → healthy. */
|
|
226
|
+
function mailStandingOf(usage) {
|
|
227
|
+
if (!usage || !usage.enabled || !usage.configured)
|
|
228
|
+
return MailStanding.Off;
|
|
229
|
+
const used = mailEmailsUsed(usage);
|
|
230
|
+
if (usage.ceiling !== null && usage.ceiling !== undefined && used >= usage.ceiling)
|
|
231
|
+
return MailStanding.Ceiling;
|
|
232
|
+
if (usage.quota !== null && usage.quota !== undefined && used >= usage.quota)
|
|
233
|
+
return MailStanding.Full;
|
|
234
|
+
if (usage.marketingPaused)
|
|
235
|
+
return MailStanding.Paused;
|
|
236
|
+
if (usage.quota !== null && usage.quota !== undefined && used >= MAIL_LOW_SHARE * usage.quota)
|
|
237
|
+
return MailStanding.Low;
|
|
238
|
+
return MailStanding.Healthy;
|
|
239
|
+
}
|
|
240
|
+
/** Reminders do not go in this standing (receipts and codes still do, except at the ceiling). */
|
|
241
|
+
function remindersStopped(standing) {
|
|
242
|
+
return standing === MailStanding.Full || standing === MailStanding.Ceiling || standing === MailStanding.Paused;
|
|
243
|
+
}
|
|
244
|
+
const MAIL_ADDRESS = /^[^\s@<>(),;:"]+@[^\s@<>(),;:"]+\.[^\s@<>(),;:".]{2,}$/;
|
|
245
|
+
/** A plain address a Reply-To may carry (`name@domain.tld`), trimmed — the admin's field and iox-cms's save both ask it. */
|
|
246
|
+
function isMailAddress(value) {
|
|
247
|
+
return typeof value === 'string' && value.trim().length <= 254 && MAIL_ADDRESS.test(value.trim());
|
|
248
|
+
}
|
|
249
|
+
|
|
174
250
|
/**
|
|
175
251
|
* @vectoriox/iox-ui/mail-core — IOX Mail's shared, FRAMEWORK-FREE vocabulary (iox-mail-plan ML2): a message's kind,
|
|
176
252
|
* who sends it, the relay's wire (`POST /instances/me/mail`, its usage) and refusals, and the ONE route rule — the
|
|
177
253
|
* studio's own active mailer wins, else IOX mail when the plan has it. The control plane (the relay), iox-cms (the
|
|
178
|
-
* transport and the MAILER connector) and the admin (Settings ▸ Email, ML3) speak it
|
|
254
|
+
* transport and the MAILER connector) and the admin (Settings ▸ Email, ML3) speak it — and ML3 adds the ONE reading
|
|
255
|
+
* of a studio's month (`mailStandingOf`: low at 80%, full, the 2× ceiling, paused, off), the connector's `MailerDetails`,
|
|
256
|
+
* the Reply-To check and the test email's answer. It imports nothing.
|
|
179
257
|
* ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets, jest
|
|
180
258
|
* moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM.
|
|
181
259
|
*/
|
|
@@ -184,5 +262,5 @@ function planMailRoute(facts) {
|
|
|
184
262
|
* Generated bundle index. Do not edit.
|
|
185
263
|
*/
|
|
186
264
|
|
|
187
|
-
export { MAIL_KIND_OF_SENDER, MailKind, MailMode, MailRefusal, MailRelayCode, MailResultStatus, MailRoute, MailSender, MailSenderState, MailStream, MarketingPauseReason, OWN_MAILER_KEYS, RELAY_ALLOWED_HEADERS, RELAY_MAIL_PATH, RELAY_MAIL_USAGE_PATH, RELAY_MAX_MESSAGES, RETRYABLE_REFUSALS, SuppressionReason, hasOwnMailerKeys, isRetryableRefusal, mailKindOf, mailModeOf, planMailRoute, requiredMailerKeys };
|
|
265
|
+
export { MAILER_REPLY_TO_KEY, MAIL_KIND_OF_SENDER, MAIL_LOW_SHARE, MAIL_TEST_PER_HOUR, MailKind, MailMode, MailRefusal, MailRelayCode, MailResultStatus, MailRoute, MailSender, MailSenderState, MailStanding, MailStream, MailTestOutcome, MarketingPauseReason, OWN_MAILER_KEYS, RELAY_ALLOWED_HEADERS, RELAY_MAIL_PATH, RELAY_MAIL_USAGE_PATH, RELAY_MAX_MESSAGES, RETRYABLE_REFUSALS, SuppressionReason, hasOwnMailerKeys, isMailAddress, isRetryableRefusal, mailEmailsLeft, mailEmailsUsed, mailKindOf, mailModeOf, mailStandingOf, planMailRoute, remindersStopped, requiredMailerKeys };
|
|
188
266
|
//# sourceMappingURL=vectoriox-iox-ui-mail-core.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vectoriox-iox-ui-mail-core.mjs","sources":["../../../projects/iox-ui/src/mail-core/mail-vocabulary.ts","../../../projects/iox-ui/src/mail-core/mail-wire.ts","../../../projects/iox-ui/src/mail-core/mail-route.ts","../../../projects/iox-ui/src/mail-core/public-api.ts","../../../projects/iox-ui/src/mail-core/vectoriox-iox-ui-mail-core.ts"],"sourcesContent":["/**\n * IOX Mail's words (iox-mail-plan ML1/ML2). ONE spelling for the relay (iox-control-plane), the studio (iox-cms) and\n * the admin — none of them re-spells a value.\n */\n\n/** Set by the sender, never guessed (iox-mail-plan §2): reminders are marketing, everything else transactional. */\nexport enum MailKind {\n Transactional = 'transactional',\n Marketing = 'marketing',\n}\n\n/** How a studio's mail goes (ML-D9): IOX's relay, or the studio's own Mailjet keys. */\nexport enum MailMode {\n Iox = 'iox',\n Own = 'own',\n}\n\n/**\n * Every place a studio sends mail from (iox-mail-plan §1: the seven senders). A message names its sender; its kind,\n * and anything else that follows from who sent it, is read from the tables below — never decided at the call site.\n */\nexport enum MailSender {\n /** a team invite (users) */\n Invite = 'invite',\n /** \"Forgot it?\" — a team member's reset link */\n PasswordReset = 'password-reset',\n /** a buyer's sign-in code (commerce E3) */\n SignInCode = 'sign-in-code',\n /** an order email — confirmation, payment, shipping (commerce E1/E2) */\n Order = 'order',\n /** a checkout recovery reminder (commerce E4) */\n Reminder = 'reminder',\n /** a form's \"email me\" delivery to the owner */\n FormDelivery = 'form-delivery',\n /** the `sendEmail` element action — to the author's fixed address */\n SendEmailAction = 'send-email-action',\n}\n\n/** ONE table: what kind of mail each sender sends (R-ML1). Only reminders are marketing. */\nexport const MAIL_KIND_OF_SENDER: Readonly<Record<MailSender, MailKind>> = {\n [MailSender.Invite]: MailKind.Transactional,\n [MailSender.PasswordReset]: MailKind.Transactional,\n [MailSender.SignInCode]: MailKind.Transactional,\n [MailSender.Order]: MailKind.Transactional,\n [MailSender.Reminder]: MailKind.Marketing,\n [MailSender.FormDelivery]: MailKind.Transactional,\n [MailSender.SendEmailAction]: MailKind.Transactional,\n};\n\nexport function mailKindOf(sender: MailSender): MailKind {\n return MAIL_KIND_OF_SENDER[sender];\n}\n\n/** What became of one relayed message. */\nexport enum MailResultStatus {\n Sent = 'sent',\n Refused = 'refused',\n}\n\n/** Why a message was not sent — iox-cms records the reason and says it to the owner (R-ML4). */\nexport enum MailRefusal {\n /** the message itself is malformed (`detail` names the field) */\n Invalid = 'invalid',\n /** it asked a From that is not the studio's IOX address for its stream, nor its own verified domain (R-ML3) */\n From = 'from',\n /** the address bounced hard, complained, or unsubscribed from this studio's marketing (R-ML5) */\n Suppressed = 'suppressed',\n /** this studio's marketing is paused — too many complaints or hard bounces, or the operator (ML-D7) */\n Paused = 'paused',\n /** marketing past 100% of the month's emails (ML-D5) */\n Quota = 'quota',\n /** transactional past twice the month's emails — the abuse ceiling (ML-D5) */\n Ceiling = 'ceiling',\n /** the same message id is being sent by another call right now — retry later */\n InProgress = 'in-progress',\n /** Mailjet refused this message (an address it will not take, a field it rejects) — not retried */\n Rejected = 'rejected',\n /** Mailjet could not be reached or failed — nothing was sent and nothing counted; retry */\n Upstream = 'upstream',\n}\n\n/** The refusals worth retrying later as they are. */\nexport const RETRYABLE_REFUSALS: ReadonlySet<MailRefusal> = new Set([MailRefusal.InProgress, MailRefusal.Upstream]);\n\nexport function isRetryableRefusal(reason: MailRefusal | string | null | undefined): boolean {\n return RETRYABLE_REFUSALS.has(reason as MailRefusal);\n}\n\n/** A whole call the relay cannot take (the HTTP answer carries it as `code`). */\nexport enum MailRelayCode {\n /** no Mailjet key in the control plane yet (ML0) — 503 */\n NotConfigured = 'not-configured',\n /** the studio's plan has no IOX mail — 403 */\n NotEnabled = 'not-enabled',\n}\n\n/** Which of a studio's streams a suppression closes. */\nexport enum MailStream {\n All = 'all',\n Marketing = 'marketing',\n}\n\n/** Why an address is suppressed for a studio (ML-D7). */\nexport enum SuppressionReason {\n HardBounce = 'hard_bounce',\n Spam = 'spam',\n Unsubscribed = 'unsubscribed',\n}\n\n/** Why a studio's marketing is paused. */\nexport enum MarketingPauseReason {\n Complaints = 'complaints',\n Bounces = 'bounces',\n Operator = 'operator',\n}\n\n/** What the relay says about the studio's sender (ML-D10 reads it). */\nexport enum MailSenderState {\n /** the platform key is set and the plan has IOX mail — IOX's verified domains send */\n Ready = 'ready',\n NotConfigured = 'not-configured',\n NotEnabled = 'not-enabled',\n}\n","import { MailKind, MailRefusal, MailResultStatus, MailSenderState, MarketingPauseReason } from './mail-vocabulary';\n\n/**\n * The relay's wire (iox-control-plane `src/mail/`, its `openapi.json` tag `instances`). The studio calls back with its\n * instance token: `Authorization: Bearer <INSTANCE_TOKEN>`.\n */\nexport const RELAY_MAIL_PATH = '/instances/me/mail';\nexport const RELAY_MAIL_USAGE_PATH = '/instances/me/mail/usage';\n\n/** At most this many messages a call. */\nexport const RELAY_MAX_MESSAGES = 50;\n\n/** RFC 8058 one-click unsubscribe — the only headers a relayed message may carry. */\nexport const RELAY_ALLOWED_HEADERS: readonly string[] = ['List-Unsubscribe', 'List-Unsubscribe-Post'];\n\nexport interface RelayAddress {\n email: string;\n name?: string;\n}\n\n/** One message as the studio asks it to be sent. ONE recipient a message. */\nexport interface RelayMessage {\n /** the studio's message id (its outbox row) — the relay sends one id at most once */\n id: string;\n kind: MailKind;\n to: RelayAddress;\n subject: string;\n text?: string;\n html?: string;\n /** absent = the studio's owner */\n replyTo?: RelayAddress;\n /** the From it expects — absent = the studio's stamped address */\n from?: string;\n /** the organization's name — the From's display name (else the studio's label) */\n fromName?: string;\n headers?: Record<string, string>;\n}\n\nexport interface RelayRequest {\n messages: RelayMessage[];\n}\n\nexport interface RelayResult {\n id: string;\n status: MailResultStatus;\n reason: MailRefusal | null;\n retryable: boolean;\n /** the field a malformed message got wrong, or Mailjet's words for a message it refused */\n detail: string | null;\n /** true when this id was already sent by an earlier call — nothing was sent twice */\n duplicate: boolean;\n messageUuid: string | null;\n}\n\n/** This month's counts — what the quota counts is `total`, both kinds. */\nexport interface RelayMonth {\n total: number;\n transactional: number;\n marketing: number;\n /** refusals this month by reason */\n refused: Partial<Record<MailRefusal | string, number>>;\n hardBounced: number;\n softBounced: number;\n blocked: number;\n complained: number;\n unsubscribed: number;\n}\n\n/** `GET /instances/me/mail/usage` (and every send's `usage`). Dates are ISO strings on the wire. */\nexport interface RelayUsage {\n /** the plan has IOX mail (`ioxMail`) */\n enabled: boolean;\n /** the control plane holds a Mailjet key */\n configured: boolean;\n senderState: MailSenderState;\n transactionalFrom: { email: string; name: string };\n marketingFrom: { email: string; name: string };\n defaultReplyTo: string;\n periodStart: string;\n periodEnd: string;\n /** `emailsPerMonth`; null = unlimited */\n quota: number | null;\n /** where transactional stops (2× the quota); null = unlimited */\n ceiling: number | null;\n month: RelayMonth;\n suppressions: number;\n marketingPaused: { at: string; reason: MarketingPauseReason | string } | null;\n}\n\nexport interface RelayResponse {\n results: RelayResult[];\n usage: RelayUsage;\n}\n","import { MailMode } from './mail-vocabulary';\n\n/** The studio's own Mailjet keys — the three an own mailer needs (the MAILER connector's `requiredKeys`, ML-D9). */\nexport const OWN_MAILER_KEYS: readonly string[] = ['publicKey', 'secretKey', 'originatorEmail'];\n\n/** Where one org's mail goes now. */\nexport enum MailRoute {\n /** its own active mailer row — ML-D8: own wins */\n Own = 'own',\n /** IOX's relay */\n Iox = 'iox',\n /** nowhere: no usable own row and no IOX mail in the plan */\n None = 'none',\n}\n\n/** A mailer row's settings, as the route reads them (decrypted; only presence is read). */\nexport interface MailerRowLike {\n mode?: unknown;\n publicKey?: unknown;\n secretKey?: unknown;\n originatorEmail?: unknown;\n}\n\nconst filled = (value: unknown): boolean => typeof value === 'string' && value.trim().length > 0;\n\n/** True when the row holds every key an own mailer needs. */\nexport function hasOwnMailerKeys(row: MailerRowLike | null | undefined): boolean {\n return !!row && OWN_MAILER_KEYS.every((key) => filled((row as Record<string, unknown>)[key]));\n}\n\n/**\n * A row's mode (ML-D9): the one it names; a row that names none is `own` when it holds its keys (every row stored\n * before IOX mail — its owner brought Mailjet), else `iox`. No row at all is `iox`.\n */\nexport function mailModeOf(row: MailerRowLike | null | undefined): MailMode {\n const asked = typeof row?.mode === 'string' ? row.mode.trim().toLowerCase() : '';\n if (asked === MailMode.Own || asked === MailMode.Iox) return asked as MailMode;\n return hasOwnMailerKeys(row) ? MailMode.Own : MailMode.Iox;\n}\n\n/** The keys a row needs to count as configured: its own keys in own mode, none in IOX mode (E1). */\nexport function requiredMailerKeys(row: MailerRowLike | null | undefined): string[] {\n return mailModeOf(row) === MailMode.Own ? [...OWN_MAILER_KEYS] : [];\n}\n\nexport interface MailRouteFacts {\n /** the org's ACTIVE mailer row, decrypted — null when it has none (or none is on) */\n activeRow: MailerRowLike | null;\n /** the plan has IOX mail (`features.ioxMail`) */\n ioxMail: boolean;\n}\n\n/**\n * THE route rule (ML-D8, R-ML1): an active row in own mode with its keys sends as today; anything else — no row, a row\n * turned off, a row set to IOX, a row still missing a key — goes through IOX mail when the plan has it, else nowhere.\n */\nexport function planMailRoute(facts: MailRouteFacts): MailRoute {\n const row = facts.activeRow;\n if (row && mailModeOf(row) === MailMode.Own && hasOwnMailerKeys(row)) return MailRoute.Own;\n return facts.ioxMail ? MailRoute.Iox : MailRoute.None;\n}\n","/**\n * @vectoriox/iox-ui/mail-core — IOX Mail's shared, FRAMEWORK-FREE vocabulary (iox-mail-plan ML2): a message's kind,\n * who sends it, the relay's wire (`POST /instances/me/mail`, its usage) and refusals, and the ONE route rule — the\n * studio's own active mailer wins, else IOX mail when the plan has it. The control plane (the relay), iox-cms (the\n * transport and the MAILER connector) and the admin (Settings ▸ Email, ML3) speak it. It imports nothing.\n * ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets, jest\n * moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM.\n */\nexport * from './mail-vocabulary';\nexport * from './mail-wire';\nexport * from './mail-route';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;;AAGG;AAEH;IACY;AAAZ,CAAA,UAAY,QAAQ,EAAA;AAChB,IAAA,QAAA,CAAA,eAAA,CAAA,GA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,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS;AAC3B,IAAA,IAAI,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC,GAAG,IAAI,gBAAgB,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC,GAAG;AAC1F,IAAA,OAAO,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC,GAAG,GAAG,SAAS,CAAC,IAAI;AACzD;;AC5DA;;;;;;;AAOG;;ACPH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"vectoriox-iox-ui-mail-core.mjs","sources":["../../../projects/iox-ui/src/mail-core/mail-vocabulary.ts","../../../projects/iox-ui/src/mail-core/mail-wire.ts","../../../projects/iox-ui/src/mail-core/mail-route.ts","../../../projects/iox-ui/src/mail-core/mail-standing.ts","../../../projects/iox-ui/src/mail-core/public-api.ts","../../../projects/iox-ui/src/mail-core/vectoriox-iox-ui-mail-core.ts"],"sourcesContent":["/**\n * IOX Mail's words (iox-mail-plan ML1/ML2). ONE spelling for the relay (iox-control-plane), the studio (iox-cms) and\n * the admin — none of them re-spells a value.\n */\n\n/** Set by the sender, never guessed (iox-mail-plan §2): reminders are marketing, everything else transactional. */\nexport enum MailKind {\n Transactional = 'transactional',\n Marketing = 'marketing',\n}\n\n/** How a studio's mail goes (ML-D9): IOX's relay, or the studio's own Mailjet keys. */\nexport enum MailMode {\n Iox = 'iox',\n Own = 'own',\n}\n\n/**\n * Every place a studio sends mail from (iox-mail-plan §1: the seven senders). A message names its sender; its kind,\n * and anything else that follows from who sent it, is read from the tables below — never decided at the call site.\n */\nexport enum MailSender {\n /** a team invite (users) */\n Invite = 'invite',\n /** \"Forgot it?\" — a team member's reset link */\n PasswordReset = 'password-reset',\n /** a buyer's sign-in code (commerce E3) */\n SignInCode = 'sign-in-code',\n /** an order email — confirmation, payment, shipping (commerce E1/E2) */\n Order = 'order',\n /** a checkout recovery reminder (commerce E4) */\n Reminder = 'reminder',\n /** a form's \"email me\" delivery to the owner */\n FormDelivery = 'form-delivery',\n /** the `sendEmail` element action — to the author's fixed address */\n SendEmailAction = 'send-email-action',\n /** Settings ▸ Email ▸ Send a test email — to the signed-in person's own address only (ML3-D3) */\n TestEmail = 'test-email',\n}\n\n/** ONE table: what kind of mail each sender sends (R-ML1). Only reminders are marketing. */\nexport const MAIL_KIND_OF_SENDER: Readonly<Record<MailSender, MailKind>> = {\n [MailSender.Invite]: MailKind.Transactional,\n [MailSender.PasswordReset]: MailKind.Transactional,\n [MailSender.SignInCode]: MailKind.Transactional,\n [MailSender.Order]: MailKind.Transactional,\n [MailSender.Reminder]: MailKind.Marketing,\n [MailSender.FormDelivery]: MailKind.Transactional,\n [MailSender.SendEmailAction]: MailKind.Transactional,\n [MailSender.TestEmail]: MailKind.Transactional,\n};\n\nexport function mailKindOf(sender: MailSender): MailKind {\n return MAIL_KIND_OF_SENDER[sender];\n}\n\n/** What became of one relayed message. */\nexport enum MailResultStatus {\n Sent = 'sent',\n Refused = 'refused',\n}\n\n/** Why a message was not sent — iox-cms records the reason and says it to the owner (R-ML4). */\nexport enum MailRefusal {\n /** the message itself is malformed (`detail` names the field) */\n Invalid = 'invalid',\n /** it asked a From that is not the studio's IOX address for its stream, nor its own verified domain (R-ML3) */\n From = 'from',\n /** the address bounced hard, complained, or unsubscribed from this studio's marketing (R-ML5) */\n Suppressed = 'suppressed',\n /** this studio's marketing is paused — too many complaints or hard bounces, or the operator (ML-D7) */\n Paused = 'paused',\n /** marketing past 100% of the month's emails (ML-D5) */\n Quota = 'quota',\n /** transactional past twice the month's emails — the abuse ceiling (ML-D5) */\n Ceiling = 'ceiling',\n /** the same message id is being sent by another call right now — retry later */\n InProgress = 'in-progress',\n /** Mailjet refused this message (an address it will not take, a field it rejects) — not retried */\n Rejected = 'rejected',\n /** Mailjet could not be reached or failed — nothing was sent and nothing counted; retry */\n Upstream = 'upstream',\n}\n\n/** The refusals worth retrying later as they are. */\nexport const RETRYABLE_REFUSALS: ReadonlySet<MailRefusal> = new Set([MailRefusal.InProgress, MailRefusal.Upstream]);\n\nexport function isRetryableRefusal(reason: MailRefusal | string | null | undefined): boolean {\n return RETRYABLE_REFUSALS.has(reason as MailRefusal);\n}\n\n/** A whole call the relay cannot take (the HTTP answer carries it as `code`). */\nexport enum MailRelayCode {\n /** no Mailjet key in the control plane yet (ML0) — 503 */\n NotConfigured = 'not-configured',\n /** the studio's plan has no IOX mail — 403 */\n NotEnabled = 'not-enabled',\n}\n\n/** Which of a studio's streams a suppression closes. */\nexport enum MailStream {\n All = 'all',\n Marketing = 'marketing',\n}\n\n/** Why an address is suppressed for a studio (ML-D7). */\nexport enum SuppressionReason {\n HardBounce = 'hard_bounce',\n Spam = 'spam',\n Unsubscribed = 'unsubscribed',\n}\n\n/** Why a studio's marketing is paused. */\nexport enum MarketingPauseReason {\n Complaints = 'complaints',\n Bounces = 'bounces',\n Operator = 'operator',\n}\n\n/** What the relay says about the studio's sender (ML-D10 reads it). */\nexport enum MailSenderState {\n /** the platform key is set and the plan has IOX mail — IOX's verified domains send */\n Ready = 'ready',\n NotConfigured = 'not-configured',\n NotEnabled = 'not-enabled',\n}\n","import { MailKind, MailMode, MailRefusal, MailResultStatus, MailSenderState, MarketingPauseReason } from './mail-vocabulary';\nimport type { MailRoute } from './mail-route';\nimport type { MailStanding } from './mail-standing';\n\n/**\n * The relay's wire (iox-control-plane `src/mail/`, its `openapi.json` tag `instances`). The studio calls back with its\n * instance token: `Authorization: Bearer <INSTANCE_TOKEN>`.\n */\nexport const RELAY_MAIL_PATH = '/instances/me/mail';\nexport const RELAY_MAIL_USAGE_PATH = '/instances/me/mail/usage';\n\n/** At most this many messages a call. */\nexport const RELAY_MAX_MESSAGES = 50;\n\n/** RFC 8058 one-click unsubscribe — the only headers a relayed message may carry. */\nexport const RELAY_ALLOWED_HEADERS: readonly string[] = ['List-Unsubscribe', 'List-Unsubscribe-Post'];\n\nexport interface RelayAddress {\n email: string;\n name?: string;\n}\n\n/** One message as the studio asks it to be sent. ONE recipient a message. */\nexport interface RelayMessage {\n /** the studio's message id (its outbox row) — the relay sends one id at most once */\n id: string;\n kind: MailKind;\n to: RelayAddress;\n subject: string;\n text?: string;\n html?: string;\n /** absent = the studio's owner */\n replyTo?: RelayAddress;\n /** the From it expects — absent = the studio's stamped address */\n from?: string;\n /** the organization's name — the From's display name (else the studio's label) */\n fromName?: string;\n headers?: Record<string, string>;\n}\n\nexport interface RelayRequest {\n messages: RelayMessage[];\n}\n\nexport interface RelayResult {\n id: string;\n status: MailResultStatus;\n reason: MailRefusal | null;\n retryable: boolean;\n /** the field a malformed message got wrong, or Mailjet's words for a message it refused */\n detail: string | null;\n /** true when this id was already sent by an earlier call — nothing was sent twice */\n duplicate: boolean;\n messageUuid: string | null;\n}\n\n/** This month's counts — what the quota counts is `total`, both kinds. */\nexport interface RelayMonth {\n total: number;\n transactional: number;\n marketing: number;\n /** refusals this month by reason */\n refused: Partial<Record<MailRefusal | string, number>>;\n hardBounced: number;\n softBounced: number;\n blocked: number;\n complained: number;\n unsubscribed: number;\n}\n\n/** `GET /instances/me/mail/usage` (and every send's `usage`). Dates are ISO strings on the wire. */\nexport interface RelayUsage {\n /** the plan has IOX mail (`ioxMail`) */\n enabled: boolean;\n /** the control plane holds a Mailjet key */\n configured: boolean;\n senderState: MailSenderState;\n transactionalFrom: { email: string; name: string };\n marketingFrom: { email: string; name: string };\n defaultReplyTo: string;\n periodStart: string;\n periodEnd: string;\n /** `emailsPerMonth`; null = unlimited */\n quota: number | null;\n /** where transactional stops (2× the quota); null = unlimited */\n ceiling: number | null;\n month: RelayMonth;\n suppressions: number;\n marketingPaused: { at: string; reason: MarketingPauseReason | string } | null;\n /** where the studio's owner changes its plan (the portal's studio page); absent/null = nowhere to send them */\n upgradeUrl?: string | null;\n}\n\nexport interface RelayResponse {\n results: RelayResult[];\n usage: RelayUsage;\n}\n\n/** The mailer row's Reply-To (ML3-D1) — absent/blank = the relay's default, the studio's owner. */\nexport const MAILER_REPLY_TO_KEY = 'replyTo';\n\n/**\n * What the MAILER connector reports about itself (its E3 `details`), read by Settings ▸ Email, System Health and Home\n * (iox-mail-plan ML3). Never a key. Own mode carries `mode` alone (plus what Mailjet's check found).\n */\nexport interface MailerDetails {\n mode: MailMode;\n /** IOX mode only: `mailStandingOf(usage)` */\n standing?: MailStanding;\n senderState?: MailSenderState;\n /** the transactional From — `<studio>@mail.iox.studio` */\n from?: string | null;\n /** the reminders' From — `<studio>@news.mail.iox.studio` */\n marketingFrom?: string | null;\n /** where replies go now: the row's `replyTo`, else the relay's default (the owner) */\n replyTo?: string | null;\n /** the row's own Reply-To, as typed — null when it uses the default */\n replyToSet?: string | null;\n quota?: number | null;\n ceiling?: number | null;\n periodStart?: string | null;\n periodEnd?: string | null;\n month?: RelayMonth | null;\n suppressions?: number;\n marketingPaused?: RelayUsage['marketingPaused'];\n /** this studio's emails refused for good in the last seven days (the outbox's own count) */\n notSentThisWeek?: number;\n upgradeUrl?: string | null;\n}\n\n/** At most this many test emails an hour, per studio (ML3-D3) — each counts against the month like any email. */\nexport const MAIL_TEST_PER_HOUR = 5;\n\n/** What became of a test email. */\nexport enum MailTestOutcome {\n /** handed to IOX mail's relay or the studio's own Mailjet, which took it */\n Sent = 'sent',\n /** stored in IOX mail's outbox — the relay could not take it now; it goes when it can */\n Queued = 'queued',\n /** refused: no route, the relay's reason, Mailjet's words */\n Refused = 'refused',\n /** this hour's test emails are used */\n Limited = 'limited',\n}\n\n/** `POST admin/api/org/:orgId/connectors/mailer/test-email` — the answer Settings ▸ Email shows in place. */\nexport interface MailTestAnswer {\n outcome: MailTestOutcome;\n /** the signed-in person's own address — the only one a test goes to */\n to: string;\n route: MailRoute;\n /** the relay's reason, or Mailjet's words — never a stack */\n detail: string | null;\n}\n","import { MailMode } from './mail-vocabulary';\n\n/** The studio's own Mailjet keys — the three an own mailer needs (the MAILER connector's `requiredKeys`, ML-D9). */\nexport const OWN_MAILER_KEYS: readonly string[] = ['publicKey', 'secretKey', 'originatorEmail'];\n\n/** Where one org's mail goes now. */\nexport enum MailRoute {\n /** its own active mailer row — ML-D8: own wins */\n Own = 'own',\n /** IOX's relay */\n Iox = 'iox',\n /** nowhere: no usable own row and no IOX mail in the plan */\n None = 'none',\n}\n\n/** A mailer row's settings, as the route reads them (decrypted; only presence is read). */\nexport interface MailerRowLike {\n mode?: unknown;\n publicKey?: unknown;\n secretKey?: unknown;\n originatorEmail?: unknown;\n}\n\nconst filled = (value: unknown): boolean => typeof value === 'string' && value.trim().length > 0;\n\n/** True when the row holds every key an own mailer needs. */\nexport function hasOwnMailerKeys(row: MailerRowLike | null | undefined): boolean {\n return !!row && OWN_MAILER_KEYS.every((key) => filled((row as Record<string, unknown>)[key]));\n}\n\n/**\n * A row's mode (ML-D9): the one it names; a row that names none is `own` when it holds its keys (every row stored\n * before IOX mail — its owner brought Mailjet), else `iox`. No row at all is `iox`.\n */\nexport function mailModeOf(row: MailerRowLike | null | undefined): MailMode {\n const asked = typeof row?.mode === 'string' ? row.mode.trim().toLowerCase() : '';\n if (asked === MailMode.Own || asked === MailMode.Iox) return asked as MailMode;\n return hasOwnMailerKeys(row) ? MailMode.Own : MailMode.Iox;\n}\n\n/** The keys a row needs to count as configured: its own keys in own mode, none in IOX mode (E1). */\nexport function requiredMailerKeys(row: MailerRowLike | null | undefined): string[] {\n return mailModeOf(row) === MailMode.Own ? [...OWN_MAILER_KEYS] : [];\n}\n\nexport interface MailRouteFacts {\n /** the org's ACTIVE mailer row, decrypted — null when it has none (or none is on) */\n activeRow: MailerRowLike | null;\n /** the plan has IOX mail (`features.ioxMail`) */\n ioxMail: boolean;\n}\n\n/**\n * THE route rule (ML-D8, R-ML1): an active row in own mode with its keys sends as today; anything else — no row, a row\n * turned off, a row set to IOX, a row still missing a key — goes through IOX mail when the plan has it, else nowhere.\n */\nexport function planMailRoute(facts: MailRouteFacts): MailRoute {\n const row = facts.activeRow;\n if (row && mailModeOf(row) === MailMode.Own && hasOwnMailerKeys(row)) return MailRoute.Own;\n return facts.ioxMail ? MailRoute.Iox : MailRoute.None;\n}\n","import type { RelayUsage } from './mail-wire';\n\n/**\n * Where a studio's IOX mail stands this month (iox-mail-plan ML-D5, the ML3 board's E2). ONE reading of the relay's\n * usage: the admin's pill, meter and note, System Health, Home and the bell (iox-cms's reconciler) all ask this — none\n * of them compares counts with a quota on its own.\n */\nexport enum MailStanding {\n /** sending, under 80% of the month */\n Healthy = 'healthy',\n /** 80% of the month's emails used — reminders still go */\n Low = 'low',\n /** the month's emails used: reminders are paused, receipts and codes continue up to twice the month */\n Full = 'full',\n /** twice the month's emails sent: nothing more goes until the month resets */\n Ceiling = 'ceiling',\n /** reminders paused by complaints, bounces or the operator (ML-D7) — receipts and codes unaffected */\n Paused = 'paused',\n /** IOX mail does not send for this studio: the relay never answered, holds no key, or the plan has none */\n Off = 'off',\n}\n\n/** The meter turns low — and the bell says so — once this share of the month is used (ML3-D2). */\nexport const MAIL_LOW_SHARE = 0.8;\n\n/** The month's emails used so far (both kinds — what the quota counts). */\nexport function mailEmailsUsed(usage: RelayUsage | null | undefined): number {\n return Math.max(0, Number(usage?.month?.total ?? 0) || 0);\n}\n\n/** Emails left this month before reminders pause; null = unlimited (or no usage). */\nexport function mailEmailsLeft(usage: RelayUsage | null | undefined): number | null {\n if (!usage || usage.quota === null || usage.quota === undefined) return null;\n return Math.max(usage.quota - mailEmailsUsed(usage), 0);\n}\n\n/** THE standing rule. The worst line crossed wins: off → ceiling → full → paused → low → healthy. */\nexport function mailStandingOf(usage: RelayUsage | null | undefined): MailStanding {\n if (!usage || !usage.enabled || !usage.configured) return MailStanding.Off;\n const used = mailEmailsUsed(usage);\n if (usage.ceiling !== null && usage.ceiling !== undefined && used >= usage.ceiling) return MailStanding.Ceiling;\n if (usage.quota !== null && usage.quota !== undefined && used >= usage.quota) return MailStanding.Full;\n if (usage.marketingPaused) return MailStanding.Paused;\n if (usage.quota !== null && usage.quota !== undefined && used >= MAIL_LOW_SHARE * usage.quota) return MailStanding.Low;\n return MailStanding.Healthy;\n}\n\n/** Reminders do not go in this standing (receipts and codes still do, except at the ceiling). */\nexport function remindersStopped(standing: MailStanding): boolean {\n return standing === MailStanding.Full || standing === MailStanding.Ceiling || standing === MailStanding.Paused;\n}\n\nconst MAIL_ADDRESS = /^[^\\s@<>(),;:\"]+@[^\\s@<>(),;:\"]+\\.[^\\s@<>(),;:\".]{2,}$/;\n\n/** A plain address a Reply-To may carry (`name@domain.tld`), trimmed — the admin's field and iox-cms's save both ask it. */\nexport function isMailAddress(value: unknown): boolean {\n return typeof value === 'string' && value.trim().length <= 254 && MAIL_ADDRESS.test(value.trim());\n}\n","/**\n * @vectoriox/iox-ui/mail-core — IOX Mail's shared, FRAMEWORK-FREE vocabulary (iox-mail-plan ML2): a message's kind,\n * who sends it, the relay's wire (`POST /instances/me/mail`, its usage) and refusals, and the ONE route rule — the\n * studio's own active mailer wins, else IOX mail when the plan has it. The control plane (the relay), iox-cms (the\n * transport and the MAILER connector) and the admin (Settings ▸ Email, ML3) speak it — and ML3 adds the ONE reading\n * of a studio's month (`mailStandingOf`: low at 80%, full, the 2× ceiling, paused, off), the connector's `MailerDetails`,\n * the Reply-To check and the test email's answer. It imports nothing.\n * ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets, jest\n * moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM.\n */\nexport * from './mail-vocabulary';\nexport * from './mail-wire';\nexport * from './mail-route';\nexport * from './mail-standing';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;;;AAGG;AAEH;IACY;AAAZ,CAAA,UAAY,QAAQ,EAAA;AAChB,IAAA,QAAA,CAAA,eAAA,CAAA,GAAA,eAA+B;AAC/B,IAAA,QAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;AAC3B,CAAC,EAHW,QAAQ,KAAR,QAAQ,GAAA,EAAA,CAAA,CAAA;AAKpB;IACY;AAAZ,CAAA,UAAY,QAA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ClH;AAEA,MAAM,YAAY,GAAG,wDAAwD;AAE7E;AACM,SAAU,aAAa,CAAC,KAAc,EAAA;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;AACrG;;ACzDA;;;;;;;;;AASG;;ACTH;;AAEG;;;;"}
|
package/mail-core/index.d.ts
CHANGED
|
@@ -30,7 +30,9 @@ declare enum MailSender {
|
|
|
30
30
|
/** a form's "email me" delivery to the owner */
|
|
31
31
|
FormDelivery = "form-delivery",
|
|
32
32
|
/** the `sendEmail` element action — to the author's fixed address */
|
|
33
|
-
SendEmailAction = "send-email-action"
|
|
33
|
+
SendEmailAction = "send-email-action",
|
|
34
|
+
/** Settings ▸ Email ▸ Send a test email — to the signed-in person's own address only (ML3-D3) */
|
|
35
|
+
TestEmail = "test-email"
|
|
34
36
|
}
|
|
35
37
|
/** ONE table: what kind of mail each sender sends (R-ML1). Only reminders are marketing. */
|
|
36
38
|
declare const MAIL_KIND_OF_SENDER: Readonly<Record<MailSender, MailKind>>;
|
|
@@ -96,6 +98,77 @@ declare enum MailSenderState {
|
|
|
96
98
|
NotEnabled = "not-enabled"
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
/** The studio's own Mailjet keys — the three an own mailer needs (the MAILER connector's `requiredKeys`, ML-D9). */
|
|
102
|
+
declare const OWN_MAILER_KEYS: readonly string[];
|
|
103
|
+
/** Where one org's mail goes now. */
|
|
104
|
+
declare enum MailRoute {
|
|
105
|
+
/** its own active mailer row — ML-D8: own wins */
|
|
106
|
+
Own = "own",
|
|
107
|
+
/** IOX's relay */
|
|
108
|
+
Iox = "iox",
|
|
109
|
+
/** nowhere: no usable own row and no IOX mail in the plan */
|
|
110
|
+
None = "none"
|
|
111
|
+
}
|
|
112
|
+
/** A mailer row's settings, as the route reads them (decrypted; only presence is read). */
|
|
113
|
+
interface MailerRowLike {
|
|
114
|
+
mode?: unknown;
|
|
115
|
+
publicKey?: unknown;
|
|
116
|
+
secretKey?: unknown;
|
|
117
|
+
originatorEmail?: unknown;
|
|
118
|
+
}
|
|
119
|
+
/** True when the row holds every key an own mailer needs. */
|
|
120
|
+
declare function hasOwnMailerKeys(row: MailerRowLike | null | undefined): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* A row's mode (ML-D9): the one it names; a row that names none is `own` when it holds its keys (every row stored
|
|
123
|
+
* before IOX mail — its owner brought Mailjet), else `iox`. No row at all is `iox`.
|
|
124
|
+
*/
|
|
125
|
+
declare function mailModeOf(row: MailerRowLike | null | undefined): MailMode;
|
|
126
|
+
/** The keys a row needs to count as configured: its own keys in own mode, none in IOX mode (E1). */
|
|
127
|
+
declare function requiredMailerKeys(row: MailerRowLike | null | undefined): string[];
|
|
128
|
+
interface MailRouteFacts {
|
|
129
|
+
/** the org's ACTIVE mailer row, decrypted — null when it has none (or none is on) */
|
|
130
|
+
activeRow: MailerRowLike | null;
|
|
131
|
+
/** the plan has IOX mail (`features.ioxMail`) */
|
|
132
|
+
ioxMail: boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* THE route rule (ML-D8, R-ML1): an active row in own mode with its keys sends as today; anything else — no row, a row
|
|
136
|
+
* turned off, a row set to IOX, a row still missing a key — goes through IOX mail when the plan has it, else nowhere.
|
|
137
|
+
*/
|
|
138
|
+
declare function planMailRoute(facts: MailRouteFacts): MailRoute;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Where a studio's IOX mail stands this month (iox-mail-plan ML-D5, the ML3 board's E2). ONE reading of the relay's
|
|
142
|
+
* usage: the admin's pill, meter and note, System Health, Home and the bell (iox-cms's reconciler) all ask this — none
|
|
143
|
+
* of them compares counts with a quota on its own.
|
|
144
|
+
*/
|
|
145
|
+
declare enum MailStanding {
|
|
146
|
+
/** sending, under 80% of the month */
|
|
147
|
+
Healthy = "healthy",
|
|
148
|
+
/** 80% of the month's emails used — reminders still go */
|
|
149
|
+
Low = "low",
|
|
150
|
+
/** the month's emails used: reminders are paused, receipts and codes continue up to twice the month */
|
|
151
|
+
Full = "full",
|
|
152
|
+
/** twice the month's emails sent: nothing more goes until the month resets */
|
|
153
|
+
Ceiling = "ceiling",
|
|
154
|
+
/** reminders paused by complaints, bounces or the operator (ML-D7) — receipts and codes unaffected */
|
|
155
|
+
Paused = "paused",
|
|
156
|
+
/** IOX mail does not send for this studio: the relay never answered, holds no key, or the plan has none */
|
|
157
|
+
Off = "off"
|
|
158
|
+
}
|
|
159
|
+
/** The meter turns low — and the bell says so — once this share of the month is used (ML3-D2). */
|
|
160
|
+
declare const MAIL_LOW_SHARE = 0.8;
|
|
161
|
+
/** The month's emails used so far (both kinds — what the quota counts). */
|
|
162
|
+
declare function mailEmailsUsed(usage: RelayUsage | null | undefined): number;
|
|
163
|
+
/** Emails left this month before reminders pause; null = unlimited (or no usage). */
|
|
164
|
+
declare function mailEmailsLeft(usage: RelayUsage | null | undefined): number | null;
|
|
165
|
+
/** THE standing rule. The worst line crossed wins: off → ceiling → full → paused → low → healthy. */
|
|
166
|
+
declare function mailStandingOf(usage: RelayUsage | null | undefined): MailStanding;
|
|
167
|
+
/** Reminders do not go in this standing (receipts and codes still do, except at the ceiling). */
|
|
168
|
+
declare function remindersStopped(standing: MailStanding): boolean;
|
|
169
|
+
/** A plain address a Reply-To may carry (`name@domain.tld`), trimmed — the admin's field and iox-cms's save both ask it. */
|
|
170
|
+
declare function isMailAddress(value: unknown): boolean;
|
|
171
|
+
|
|
99
172
|
/**
|
|
100
173
|
* The relay's wire (iox-control-plane `src/mail/`, its `openapi.json` tag `instances`). The studio calls back with its
|
|
101
174
|
* instance token: `Authorization: Bearer <INSTANCE_TOKEN>`.
|
|
@@ -182,50 +255,65 @@ interface RelayUsage {
|
|
|
182
255
|
at: string;
|
|
183
256
|
reason: MarketingPauseReason | string;
|
|
184
257
|
} | null;
|
|
258
|
+
/** where the studio's owner changes its plan (the portal's studio page); absent/null = nowhere to send them */
|
|
259
|
+
upgradeUrl?: string | null;
|
|
185
260
|
}
|
|
186
261
|
interface RelayResponse {
|
|
187
262
|
results: RelayResult[];
|
|
188
263
|
usage: RelayUsage;
|
|
189
264
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
declare const OWN_MAILER_KEYS: readonly string[];
|
|
193
|
-
/** Where one org's mail goes now. */
|
|
194
|
-
declare enum MailRoute {
|
|
195
|
-
/** its own active mailer row — ML-D8: own wins */
|
|
196
|
-
Own = "own",
|
|
197
|
-
/** IOX's relay */
|
|
198
|
-
Iox = "iox",
|
|
199
|
-
/** nowhere: no usable own row and no IOX mail in the plan */
|
|
200
|
-
None = "none"
|
|
201
|
-
}
|
|
202
|
-
/** A mailer row's settings, as the route reads them (decrypted; only presence is read). */
|
|
203
|
-
interface MailerRowLike {
|
|
204
|
-
mode?: unknown;
|
|
205
|
-
publicKey?: unknown;
|
|
206
|
-
secretKey?: unknown;
|
|
207
|
-
originatorEmail?: unknown;
|
|
208
|
-
}
|
|
209
|
-
/** True when the row holds every key an own mailer needs. */
|
|
210
|
-
declare function hasOwnMailerKeys(row: MailerRowLike | null | undefined): boolean;
|
|
265
|
+
/** The mailer row's Reply-To (ML3-D1) — absent/blank = the relay's default, the studio's owner. */
|
|
266
|
+
declare const MAILER_REPLY_TO_KEY = "replyTo";
|
|
211
267
|
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
268
|
+
* What the MAILER connector reports about itself (its E3 `details`), read by Settings ▸ Email, System Health and Home
|
|
269
|
+
* (iox-mail-plan ML3). Never a key. Own mode carries `mode` alone (plus what Mailjet's check found).
|
|
214
270
|
*/
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
271
|
+
interface MailerDetails {
|
|
272
|
+
mode: MailMode;
|
|
273
|
+
/** IOX mode only: `mailStandingOf(usage)` */
|
|
274
|
+
standing?: MailStanding;
|
|
275
|
+
senderState?: MailSenderState;
|
|
276
|
+
/** the transactional From — `<studio>@mail.iox.studio` */
|
|
277
|
+
from?: string | null;
|
|
278
|
+
/** the reminders' From — `<studio>@news.mail.iox.studio` */
|
|
279
|
+
marketingFrom?: string | null;
|
|
280
|
+
/** where replies go now: the row's `replyTo`, else the relay's default (the owner) */
|
|
281
|
+
replyTo?: string | null;
|
|
282
|
+
/** the row's own Reply-To, as typed — null when it uses the default */
|
|
283
|
+
replyToSet?: string | null;
|
|
284
|
+
quota?: number | null;
|
|
285
|
+
ceiling?: number | null;
|
|
286
|
+
periodStart?: string | null;
|
|
287
|
+
periodEnd?: string | null;
|
|
288
|
+
month?: RelayMonth | null;
|
|
289
|
+
suppressions?: number;
|
|
290
|
+
marketingPaused?: RelayUsage['marketingPaused'];
|
|
291
|
+
/** this studio's emails refused for good in the last seven days (the outbox's own count) */
|
|
292
|
+
notSentThisWeek?: number;
|
|
293
|
+
upgradeUrl?: string | null;
|
|
294
|
+
}
|
|
295
|
+
/** At most this many test emails an hour, per studio (ML3-D3) — each counts against the month like any email. */
|
|
296
|
+
declare const MAIL_TEST_PER_HOUR = 5;
|
|
297
|
+
/** What became of a test email. */
|
|
298
|
+
declare enum MailTestOutcome {
|
|
299
|
+
/** handed to IOX mail's relay or the studio's own Mailjet, which took it */
|
|
300
|
+
Sent = "sent",
|
|
301
|
+
/** stored in IOX mail's outbox — the relay could not take it now; it goes when it can */
|
|
302
|
+
Queued = "queued",
|
|
303
|
+
/** refused: no route, the relay's reason, Mailjet's words */
|
|
304
|
+
Refused = "refused",
|
|
305
|
+
/** this hour's test emails are used */
|
|
306
|
+
Limited = "limited"
|
|
307
|
+
}
|
|
308
|
+
/** `POST admin/api/org/:orgId/connectors/mailer/test-email` — the answer Settings ▸ Email shows in place. */
|
|
309
|
+
interface MailTestAnswer {
|
|
310
|
+
outcome: MailTestOutcome;
|
|
311
|
+
/** the signed-in person's own address — the only one a test goes to */
|
|
312
|
+
to: string;
|
|
313
|
+
route: MailRoute;
|
|
314
|
+
/** the relay's reason, or Mailjet's words — never a stack */
|
|
315
|
+
detail: string | null;
|
|
223
316
|
}
|
|
224
|
-
/**
|
|
225
|
-
* THE route rule (ML-D8, R-ML1): an active row in own mode with its keys sends as today; anything else — no row, a row
|
|
226
|
-
* turned off, a row set to IOX, a row still missing a key — goes through IOX mail when the plan has it, else nowhere.
|
|
227
|
-
*/
|
|
228
|
-
declare function planMailRoute(facts: MailRouteFacts): MailRoute;
|
|
229
317
|
|
|
230
|
-
export { MAIL_KIND_OF_SENDER, MailKind, MailMode, MailRefusal, MailRelayCode, MailResultStatus, MailRoute, MailSender, MailSenderState, MailStream, MarketingPauseReason, OWN_MAILER_KEYS, RELAY_ALLOWED_HEADERS, RELAY_MAIL_PATH, RELAY_MAIL_USAGE_PATH, RELAY_MAX_MESSAGES, RETRYABLE_REFUSALS, SuppressionReason, hasOwnMailerKeys, isRetryableRefusal, mailKindOf, mailModeOf, planMailRoute, requiredMailerKeys };
|
|
231
|
-
export type { MailRouteFacts, MailerRowLike, RelayAddress, RelayMessage, RelayMonth, RelayRequest, RelayResponse, RelayResult, RelayUsage };
|
|
318
|
+
export { MAILER_REPLY_TO_KEY, MAIL_KIND_OF_SENDER, MAIL_LOW_SHARE, MAIL_TEST_PER_HOUR, MailKind, MailMode, MailRefusal, MailRelayCode, MailResultStatus, MailRoute, MailSender, MailSenderState, MailStanding, MailStream, MailTestOutcome, MarketingPauseReason, OWN_MAILER_KEYS, RELAY_ALLOWED_HEADERS, RELAY_MAIL_PATH, RELAY_MAIL_USAGE_PATH, RELAY_MAX_MESSAGES, RETRYABLE_REFUSALS, SuppressionReason, hasOwnMailerKeys, isMailAddress, isRetryableRefusal, mailEmailsLeft, mailEmailsUsed, mailKindOf, mailModeOf, mailStandingOf, planMailRoute, remindersStopped, requiredMailerKeys };
|
|
319
|
+
export type { MailRouteFacts, MailTestAnswer, MailerDetails, MailerRowLike, RelayAddress, RelayMessage, RelayMonth, RelayRequest, RelayResponse, RelayResult, RelayUsage };
|
package/package.json
CHANGED
|
@@ -215,10 +215,14 @@ export function buildConsentRecipe(create: CompositeNodeFactory, options: Consen
|
|
|
215
215
|
onClickRun(accept, [{ type: ConsentActionType.Grant }, { type: ConsentActionType.CloseDialog, target: banner.id }]);
|
|
216
216
|
const reject = button(create, 'consent-reject', ConsentRole.Reject, Style.Secondary, t.reject, 'Reject all');
|
|
217
217
|
onClickRun(reject, [{ type: ConsentActionType.Deny }, { type: ConsentActionType.CloseDialog, target: banner.id }]);
|
|
218
|
-
|
|
218
|
+
// iox-ui#95: on a phone the buttons take their own line, and Accept beside Reject was wider than the words' column
|
|
219
|
+
// (Hebrew and a large type pushed Reject past the dialog's edge). The pair wraps inside the column instead, and
|
|
220
|
+
// the column never grows past its row — it shrinks to it.
|
|
221
|
+
const choices = recipePart(create, 'consent-choices', 'Container', ConsentRole.Choices, null, {}, 'Accept and reject',
|
|
222
|
+
{ ...ROW, flexWrap: 'wrap', justifyContent: 'center', gap: '8px' });
|
|
219
223
|
choices.children = [accept, reject];
|
|
220
224
|
const buttons = recipePart(create, 'consent-buttons', 'Container', null, null, {}, 'Buttons',
|
|
221
|
-
{ ...COLUMN, width: 'auto', flexShrink: '0', alignItems: 'center', gap: '6px' });
|
|
225
|
+
{ ...COLUMN, width: 'auto', maxWidth: '100%', flexShrink: '0', alignItems: 'center', gap: '6px' });
|
|
222
226
|
buttons.children = [choices];
|
|
223
227
|
if (withPreferences) {
|
|
224
228
|
const prefs = button(create, 'consent-open-preferences', ConsentRole.Preferences, Style.Ghost, t.preferences, 'Preferences');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CART_TRANSPORT_ERROR_LABELS, CartTransport, CartTransportError, CartTransportErrorCode, cartIssueWords, CartView, CartViewLine, chooseValue,
|
|
2
|
+
CART_TRANSPORT_ERROR_LABELS, CartTransport, CheckoutWord, checkoutWord, CartTransportError, CartTransportErrorCode, cartIssueWords, CartView, CartViewLine, chooseValue,
|
|
3
3
|
defaultChoice, emptyCartView, findVariant, formatMoney, optionValueStates, ProductOption, ProductVariantView, productOptions, productVariants,
|
|
4
4
|
QuantityBounds, quantityBounds, QuantityStep, canStep, clampQuantity, ShopSlot, ShopWord, shopWord, stepQuantity, StorefrontProduct, VariantChoice,
|
|
5
5
|
variantSlotOf,
|
|
@@ -10,7 +10,7 @@ import { ITEM_KEY_ATTRIBUTE } from './accordion';
|
|
|
10
10
|
import { CompositeKind } from './composite-kinds';
|
|
11
11
|
import { attachExclusiveAt, exclusiveRuntimeOf, ExclusiveRuntime } from './exclusive-runtime';
|
|
12
12
|
import {
|
|
13
|
-
ADDED_HOLD_MS, CART_EMPTY_ATTRIBUTE, CART_LINE_ATTRIBUTE, CART_TITLE_COUNT_ATTRIBUTE, ShopPickerKind, shopPickerKind, ShopRole, shopSelector,
|
|
13
|
+
ADDED_HOLD_MS, CART_EMPTY_ATTRIBUTE, CART_LINE_ATTRIBUTE, CART_WAITING_ATTRIBUTE, SHOP_REST_WORDS_ATTRIBUTE, CART_TITLE_COUNT_ATTRIBUTE, ShopPickerKind, shopPickerKind, ShopRole, shopSelector,
|
|
14
14
|
SHOP_ADDED_ATTRIBUTE, SHOP_CLONE_ATTRIBUTE, SHOP_HIDDEN_ATTRIBUTE, SHOP_LIVE_CLASS, SHOP_SELECT_CLASS, SHOP_UNUSED_ATTRIBUTE, swatchFill,
|
|
15
15
|
variantGroupLabel, variantGroupNote,
|
|
16
16
|
} from './shop';
|
|
@@ -26,6 +26,12 @@ import {
|
|
|
26
26
|
* instance; the rest are copies stamped after it (`data-iox-shop-clone`), restamped only when the list changes.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
/** An order this browser placed and has not paid yet (client-engine#22/#23): its number and the order page's address. */
|
|
30
|
+
export interface WaitingOrder {
|
|
31
|
+
number: string;
|
|
32
|
+
href: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
29
35
|
export interface ShopHost {
|
|
30
36
|
/** The cart: the engine's (E1d) on a live site, `simulatedCartTransport` on the builder canvas. */
|
|
31
37
|
transport: CartTransport;
|
|
@@ -39,6 +45,8 @@ export interface ShopHost {
|
|
|
39
45
|
openDrawer?: (drawer: HTMLElement) => void;
|
|
40
46
|
/** Go to the fixed checkout route (`checkoutHref(orgLabel)`); the canvas simulates it. */
|
|
41
47
|
goToCheckout?: () => void;
|
|
48
|
+
/** Go back to an unpaid order's page (the empty bag's "Continue to payment", client-engine#23). */
|
|
49
|
+
continueOrder?: (order: WaitingOrder) => void;
|
|
42
50
|
/** A change the cart refused (words in the page language) — the host may toast it; it is announced either way. */
|
|
43
51
|
onRefused?: (words: string, error: unknown) => void;
|
|
44
52
|
/** The colours a value is drawn with when it is not a colour word itself (the canvas' sample glazes). */
|
|
@@ -72,6 +80,19 @@ function setText(el: Element | null | undefined, words: string): void {
|
|
|
72
80
|
if (el && el.textContent !== words) el.textContent = words;
|
|
73
81
|
}
|
|
74
82
|
|
|
83
|
+
/** Say `words` in a part's place, keeping what it said; null gives the part its own words back. */
|
|
84
|
+
function swapWords(el: Element | null, words: string | null): void {
|
|
85
|
+
if (!el) return;
|
|
86
|
+
const kept = el.getAttribute(SHOP_REST_WORDS_ATTRIBUTE);
|
|
87
|
+
if (words !== null) {
|
|
88
|
+
if (kept === null) el.setAttribute(SHOP_REST_WORDS_ATTRIBUTE, el.textContent ?? '');
|
|
89
|
+
setText(el, words);
|
|
90
|
+
} else if (kept !== null) {
|
|
91
|
+
setText(el, kept);
|
|
92
|
+
el.removeAttribute(SHOP_REST_WORDS_ATTRIBUTE);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
75
96
|
/** The deepest element of a Text / Heading part that holds its words (a host may wrap them). */
|
|
76
97
|
function wordsOf(el: Element | null | undefined): Element | null {
|
|
77
98
|
if (!el) return null;
|
|
@@ -136,6 +157,7 @@ function announce(scope: Element, words: string): void {
|
|
|
136
157
|
export class ShopRuntime {
|
|
137
158
|
private readonly products = new Map<string, ProductState>();
|
|
138
159
|
private cart: CartView = emptyCartView();
|
|
160
|
+
private waiting: WaitingOrder | null = null;
|
|
139
161
|
private observer: MutationObserver | null = null;
|
|
140
162
|
private stampQueued = false;
|
|
141
163
|
private stamping = false;
|
|
@@ -178,6 +200,17 @@ export class ShopRuntime {
|
|
|
178
200
|
return this.stateFor(el)?.quantity ?? 1;
|
|
179
201
|
}
|
|
180
202
|
|
|
203
|
+
/** client-engine#23: the order this browser placed and has not paid (or null) — an empty bag offers it. */
|
|
204
|
+
setWaitingOrder(order: WaitingOrder | null): void {
|
|
205
|
+
this.waiting = order;
|
|
206
|
+
this.stamp();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The unpaid order an empty bag offers, or null. */
|
|
210
|
+
get waitingOrder(): WaitingOrder | null {
|
|
211
|
+
return this.cart.empty ? this.waiting : null;
|
|
212
|
+
}
|
|
213
|
+
|
|
181
214
|
/** Re-read every product and restamp (the host's data changed). */
|
|
182
215
|
refresh(): void {
|
|
183
216
|
this.products.clear();
|
|
@@ -447,8 +480,15 @@ export class ShopRuntime {
|
|
|
447
480
|
setAttr(button, 'aria-label', view.empty ? shopWord(ShopWord.Cart, lang) : shopWord(ShopWord.CartCount, lang, { n: view.count }));
|
|
448
481
|
setAttr(button, 'aria-haspopup', 'dialog');
|
|
449
482
|
}
|
|
483
|
+
const waiting = this.waitingOrder;
|
|
450
484
|
for (const drawer of own(this.scope, sel(ShopRole.CartDrawer))) {
|
|
451
485
|
setAttr(drawer, CART_EMPTY_ATTRIBUTE, view.empty ? '' : null);
|
|
486
|
+
// client-engine#23: Back from the order page lands on an empty bag — it names the order and goes back to it.
|
|
487
|
+
setAttr(drawer, CART_WAITING_ATTRIBUTE, waiting ? '' : null);
|
|
488
|
+
swapWords(wordsOf(first(drawer, sel(ShopRole.CartEmpty))), waiting
|
|
489
|
+
? `${checkoutWord(CheckoutWord.OrderAwaitsPayment, lang, { number: waiting.number })}. ${checkoutWord(CheckoutWord.OrderAwaitsNote, lang)}`
|
|
490
|
+
: null);
|
|
491
|
+
swapWords(wordsOf(first(drawer, sel(ShopRole.Checkout))), waiting ? checkoutWord(CheckoutWord.ContinueToPayment, lang) : null);
|
|
452
492
|
const title = wordsOf(first(drawer, sel(ShopRole.CartTitle)));
|
|
453
493
|
if (title) {
|
|
454
494
|
let count = title.querySelector(`[${CART_TITLE_COUNT_ATTRIBUTE}]`);
|
|
@@ -556,7 +596,11 @@ export class ShopRuntime {
|
|
|
556
596
|
const removeLine = remove?.closest(`[${CART_LINE_ATTRIBUTE}]`);
|
|
557
597
|
if (removeLine) { void this.changeLine(removeLine, null); return; }
|
|
558
598
|
if (target.closest(sel(ShopRole.CartButton))) { this.openCart(); return; }
|
|
559
|
-
if (target.closest(sel(ShopRole.Checkout))
|
|
599
|
+
if (target.closest(sel(ShopRole.Checkout))) {
|
|
600
|
+
const waiting = this.waitingOrder;
|
|
601
|
+
if (!this.cart.empty) this.host.goToCheckout?.();
|
|
602
|
+
else if (waiting) this.host.continueOrder?.(waiting);
|
|
603
|
+
}
|
|
560
604
|
};
|
|
561
605
|
|
|
562
606
|
private readonly onChange = (event: Event): void => {
|
|
@@ -89,6 +89,11 @@ export const SHOP_UNUSED_ATTRIBUTE = 'data-iox-shop-unused';
|
|
|
89
89
|
export const SHOP_ADDED_ATTRIBUTE = 'data-iox-added';
|
|
90
90
|
/** An empty bag: on the cart button (its count hides) and the drawer (its lines, summary and Check out hide). */
|
|
91
91
|
export const CART_EMPTY_ATTRIBUTE = 'data-iox-cart-empty';
|
|
92
|
+
/** client-engine#23: an empty bag while this browser holds an unpaid order — the drawer offers it (its Check out reads
|
|
93
|
+
* "Continue to payment", its empty words name the order). Only a live site's host sets it. */
|
|
94
|
+
export const CART_WAITING_ATTRIBUTE = 'data-iox-cart-waiting';
|
|
95
|
+
/** The words a part had before the runtime swapped them (restored when the swap ends). */
|
|
96
|
+
export const SHOP_REST_WORDS_ATTRIBUTE = 'data-iox-rest-words';
|
|
92
97
|
/** A cart line's id (`cartLineId`) on its line element. */
|
|
93
98
|
export const CART_LINE_ATTRIBUTE = 'data-iox-line-id';
|
|
94
99
|
/** The count the runtime adds to the drawer's title ("Your bag (2)"). */
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { RelayUsage } from './mail-wire';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where a studio's IOX mail stands this month (iox-mail-plan ML-D5, the ML3 board's E2). ONE reading of the relay's
|
|
5
|
+
* usage: the admin's pill, meter and note, System Health, Home and the bell (iox-cms's reconciler) all ask this — none
|
|
6
|
+
* of them compares counts with a quota on its own.
|
|
7
|
+
*/
|
|
8
|
+
export enum MailStanding {
|
|
9
|
+
/** sending, under 80% of the month */
|
|
10
|
+
Healthy = 'healthy',
|
|
11
|
+
/** 80% of the month's emails used — reminders still go */
|
|
12
|
+
Low = 'low',
|
|
13
|
+
/** the month's emails used: reminders are paused, receipts and codes continue up to twice the month */
|
|
14
|
+
Full = 'full',
|
|
15
|
+
/** twice the month's emails sent: nothing more goes until the month resets */
|
|
16
|
+
Ceiling = 'ceiling',
|
|
17
|
+
/** reminders paused by complaints, bounces or the operator (ML-D7) — receipts and codes unaffected */
|
|
18
|
+
Paused = 'paused',
|
|
19
|
+
/** IOX mail does not send for this studio: the relay never answered, holds no key, or the plan has none */
|
|
20
|
+
Off = 'off',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The meter turns low — and the bell says so — once this share of the month is used (ML3-D2). */
|
|
24
|
+
export const MAIL_LOW_SHARE = 0.8;
|
|
25
|
+
|
|
26
|
+
/** The month's emails used so far (both kinds — what the quota counts). */
|
|
27
|
+
export function mailEmailsUsed(usage: RelayUsage | null | undefined): number {
|
|
28
|
+
return Math.max(0, Number(usage?.month?.total ?? 0) || 0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Emails left this month before reminders pause; null = unlimited (or no usage). */
|
|
32
|
+
export function mailEmailsLeft(usage: RelayUsage | null | undefined): number | null {
|
|
33
|
+
if (!usage || usage.quota === null || usage.quota === undefined) return null;
|
|
34
|
+
return Math.max(usage.quota - mailEmailsUsed(usage), 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** THE standing rule. The worst line crossed wins: off → ceiling → full → paused → low → healthy. */
|
|
38
|
+
export function mailStandingOf(usage: RelayUsage | null | undefined): MailStanding {
|
|
39
|
+
if (!usage || !usage.enabled || !usage.configured) return MailStanding.Off;
|
|
40
|
+
const used = mailEmailsUsed(usage);
|
|
41
|
+
if (usage.ceiling !== null && usage.ceiling !== undefined && used >= usage.ceiling) return MailStanding.Ceiling;
|
|
42
|
+
if (usage.quota !== null && usage.quota !== undefined && used >= usage.quota) return MailStanding.Full;
|
|
43
|
+
if (usage.marketingPaused) return MailStanding.Paused;
|
|
44
|
+
if (usage.quota !== null && usage.quota !== undefined && used >= MAIL_LOW_SHARE * usage.quota) return MailStanding.Low;
|
|
45
|
+
return MailStanding.Healthy;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Reminders do not go in this standing (receipts and codes still do, except at the ceiling). */
|
|
49
|
+
export function remindersStopped(standing: MailStanding): boolean {
|
|
50
|
+
return standing === MailStanding.Full || standing === MailStanding.Ceiling || standing === MailStanding.Paused;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const MAIL_ADDRESS = /^[^\s@<>(),;:"]+@[^\s@<>(),;:"]+\.[^\s@<>(),;:".]{2,}$/;
|
|
54
|
+
|
|
55
|
+
/** A plain address a Reply-To may carry (`name@domain.tld`), trimmed — the admin's field and iox-cms's save both ask it. */
|
|
56
|
+
export function isMailAddress(value: unknown): boolean {
|
|
57
|
+
return typeof value === 'string' && value.trim().length <= 254 && MAIL_ADDRESS.test(value.trim());
|
|
58
|
+
}
|