@vectoriox/iox-ui 5.130.1 → 5.132.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,61 @@
1
+ import { MailMode } from './mail-vocabulary';
2
+
3
+ /** The studio's own Mailjet keys — the three an own mailer needs (the MAILER connector's `requiredKeys`, ML-D9). */
4
+ export const OWN_MAILER_KEYS: readonly string[] = ['publicKey', 'secretKey', 'originatorEmail'];
5
+
6
+ /** Where one org's mail goes now. */
7
+ export enum MailRoute {
8
+ /** its own active mailer row — ML-D8: own wins */
9
+ Own = 'own',
10
+ /** IOX's relay */
11
+ Iox = 'iox',
12
+ /** nowhere: no usable own row and no IOX mail in the plan */
13
+ None = 'none',
14
+ }
15
+
16
+ /** A mailer row's settings, as the route reads them (decrypted; only presence is read). */
17
+ export interface MailerRowLike {
18
+ mode?: unknown;
19
+ publicKey?: unknown;
20
+ secretKey?: unknown;
21
+ originatorEmail?: unknown;
22
+ }
23
+
24
+ const filled = (value: unknown): boolean => typeof value === 'string' && value.trim().length > 0;
25
+
26
+ /** True when the row holds every key an own mailer needs. */
27
+ export function hasOwnMailerKeys(row: MailerRowLike | null | undefined): boolean {
28
+ return !!row && OWN_MAILER_KEYS.every((key) => filled((row as Record<string, unknown>)[key]));
29
+ }
30
+
31
+ /**
32
+ * 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
33
+ * before IOX mail — its owner brought Mailjet), else `iox`. No row at all is `iox`.
34
+ */
35
+ export function mailModeOf(row: MailerRowLike | null | undefined): MailMode {
36
+ const asked = typeof row?.mode === 'string' ? row.mode.trim().toLowerCase() : '';
37
+ if (asked === MailMode.Own || asked === MailMode.Iox) return asked as MailMode;
38
+ return hasOwnMailerKeys(row) ? MailMode.Own : MailMode.Iox;
39
+ }
40
+
41
+ /** The keys a row needs to count as configured: its own keys in own mode, none in IOX mode (E1). */
42
+ export function requiredMailerKeys(row: MailerRowLike | null | undefined): string[] {
43
+ return mailModeOf(row) === MailMode.Own ? [...OWN_MAILER_KEYS] : [];
44
+ }
45
+
46
+ export interface MailRouteFacts {
47
+ /** the org's ACTIVE mailer row, decrypted — null when it has none (or none is on) */
48
+ activeRow: MailerRowLike | null;
49
+ /** the plan has IOX mail (`features.ioxMail`) */
50
+ ioxMail: boolean;
51
+ }
52
+
53
+ /**
54
+ * 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
55
+ * turned off, a row set to IOX, a row still missing a key — goes through IOX mail when the plan has it, else nowhere.
56
+ */
57
+ export function planMailRoute(facts: MailRouteFacts): MailRoute {
58
+ const row = facts.activeRow;
59
+ if (row && mailModeOf(row) === MailMode.Own && hasOwnMailerKeys(row)) return MailRoute.Own;
60
+ return facts.ioxMail ? MailRoute.Iox : MailRoute.None;
61
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * IOX Mail's words (iox-mail-plan ML1/ML2). ONE spelling for the relay (iox-control-plane), the studio (iox-cms) and
3
+ * the admin — none of them re-spells a value.
4
+ */
5
+
6
+ /** Set by the sender, never guessed (iox-mail-plan §2): reminders are marketing, everything else transactional. */
7
+ export enum MailKind {
8
+ Transactional = 'transactional',
9
+ Marketing = 'marketing',
10
+ }
11
+
12
+ /** How a studio's mail goes (ML-D9): IOX's relay, or the studio's own Mailjet keys. */
13
+ export enum MailMode {
14
+ Iox = 'iox',
15
+ Own = 'own',
16
+ }
17
+
18
+ /**
19
+ * Every place a studio sends mail from (iox-mail-plan §1: the seven senders). A message names its sender; its kind,
20
+ * and anything else that follows from who sent it, is read from the tables below — never decided at the call site.
21
+ */
22
+ export enum MailSender {
23
+ /** a team invite (users) */
24
+ Invite = 'invite',
25
+ /** "Forgot it?" — a team member's reset link */
26
+ PasswordReset = 'password-reset',
27
+ /** a buyer's sign-in code (commerce E3) */
28
+ SignInCode = 'sign-in-code',
29
+ /** an order email — confirmation, payment, shipping (commerce E1/E2) */
30
+ Order = 'order',
31
+ /** a checkout recovery reminder (commerce E4) */
32
+ Reminder = 'reminder',
33
+ /** a form's "email me" delivery to the owner */
34
+ FormDelivery = 'form-delivery',
35
+ /** the `sendEmail` element action — to the author's fixed address */
36
+ SendEmailAction = 'send-email-action',
37
+ }
38
+
39
+ /** ONE table: what kind of mail each sender sends (R-ML1). Only reminders are marketing. */
40
+ export const MAIL_KIND_OF_SENDER: Readonly<Record<MailSender, MailKind>> = {
41
+ [MailSender.Invite]: MailKind.Transactional,
42
+ [MailSender.PasswordReset]: MailKind.Transactional,
43
+ [MailSender.SignInCode]: MailKind.Transactional,
44
+ [MailSender.Order]: MailKind.Transactional,
45
+ [MailSender.Reminder]: MailKind.Marketing,
46
+ [MailSender.FormDelivery]: MailKind.Transactional,
47
+ [MailSender.SendEmailAction]: MailKind.Transactional,
48
+ };
49
+
50
+ export function mailKindOf(sender: MailSender): MailKind {
51
+ return MAIL_KIND_OF_SENDER[sender];
52
+ }
53
+
54
+ /** What became of one relayed message. */
55
+ export enum MailResultStatus {
56
+ Sent = 'sent',
57
+ Refused = 'refused',
58
+ }
59
+
60
+ /** Why a message was not sent — iox-cms records the reason and says it to the owner (R-ML4). */
61
+ export enum MailRefusal {
62
+ /** the message itself is malformed (`detail` names the field) */
63
+ Invalid = 'invalid',
64
+ /** it asked a From that is not the studio's IOX address for its stream, nor its own verified domain (R-ML3) */
65
+ From = 'from',
66
+ /** the address bounced hard, complained, or unsubscribed from this studio's marketing (R-ML5) */
67
+ Suppressed = 'suppressed',
68
+ /** this studio's marketing is paused — too many complaints or hard bounces, or the operator (ML-D7) */
69
+ Paused = 'paused',
70
+ /** marketing past 100% of the month's emails (ML-D5) */
71
+ Quota = 'quota',
72
+ /** transactional past twice the month's emails — the abuse ceiling (ML-D5) */
73
+ Ceiling = 'ceiling',
74
+ /** the same message id is being sent by another call right now — retry later */
75
+ InProgress = 'in-progress',
76
+ /** Mailjet refused this message (an address it will not take, a field it rejects) — not retried */
77
+ Rejected = 'rejected',
78
+ /** Mailjet could not be reached or failed — nothing was sent and nothing counted; retry */
79
+ Upstream = 'upstream',
80
+ }
81
+
82
+ /** The refusals worth retrying later as they are. */
83
+ export const RETRYABLE_REFUSALS: ReadonlySet<MailRefusal> = new Set([MailRefusal.InProgress, MailRefusal.Upstream]);
84
+
85
+ export function isRetryableRefusal(reason: MailRefusal | string | null | undefined): boolean {
86
+ return RETRYABLE_REFUSALS.has(reason as MailRefusal);
87
+ }
88
+
89
+ /** A whole call the relay cannot take (the HTTP answer carries it as `code`). */
90
+ export enum MailRelayCode {
91
+ /** no Mailjet key in the control plane yet (ML0) — 503 */
92
+ NotConfigured = 'not-configured',
93
+ /** the studio's plan has no IOX mail — 403 */
94
+ NotEnabled = 'not-enabled',
95
+ }
96
+
97
+ /** Which of a studio's streams a suppression closes. */
98
+ export enum MailStream {
99
+ All = 'all',
100
+ Marketing = 'marketing',
101
+ }
102
+
103
+ /** Why an address is suppressed for a studio (ML-D7). */
104
+ export enum SuppressionReason {
105
+ HardBounce = 'hard_bounce',
106
+ Spam = 'spam',
107
+ Unsubscribed = 'unsubscribed',
108
+ }
109
+
110
+ /** Why a studio's marketing is paused. */
111
+ export enum MarketingPauseReason {
112
+ Complaints = 'complaints',
113
+ Bounces = 'bounces',
114
+ Operator = 'operator',
115
+ }
116
+
117
+ /** What the relay says about the studio's sender (ML-D10 reads it). */
118
+ export enum MailSenderState {
119
+ /** the platform key is set and the plan has IOX mail — IOX's verified domains send */
120
+ Ready = 'ready',
121
+ NotConfigured = 'not-configured',
122
+ NotEnabled = 'not-enabled',
123
+ }
@@ -0,0 +1,93 @@
1
+ import { MailKind, MailRefusal, MailResultStatus, MailSenderState, MarketingPauseReason } from './mail-vocabulary';
2
+
3
+ /**
4
+ * The relay's wire (iox-control-plane `src/mail/`, its `openapi.json` tag `instances`). The studio calls back with its
5
+ * instance token: `Authorization: Bearer <INSTANCE_TOKEN>`.
6
+ */
7
+ export const RELAY_MAIL_PATH = '/instances/me/mail';
8
+ export const RELAY_MAIL_USAGE_PATH = '/instances/me/mail/usage';
9
+
10
+ /** At most this many messages a call. */
11
+ export const RELAY_MAX_MESSAGES = 50;
12
+
13
+ /** RFC 8058 one-click unsubscribe — the only headers a relayed message may carry. */
14
+ export const RELAY_ALLOWED_HEADERS: readonly string[] = ['List-Unsubscribe', 'List-Unsubscribe-Post'];
15
+
16
+ export interface RelayAddress {
17
+ email: string;
18
+ name?: string;
19
+ }
20
+
21
+ /** One message as the studio asks it to be sent. ONE recipient a message. */
22
+ export interface RelayMessage {
23
+ /** the studio's message id (its outbox row) — the relay sends one id at most once */
24
+ id: string;
25
+ kind: MailKind;
26
+ to: RelayAddress;
27
+ subject: string;
28
+ text?: string;
29
+ html?: string;
30
+ /** absent = the studio's owner */
31
+ replyTo?: RelayAddress;
32
+ /** the From it expects — absent = the studio's stamped address */
33
+ from?: string;
34
+ /** the organization's name — the From's display name (else the studio's label) */
35
+ fromName?: string;
36
+ headers?: Record<string, string>;
37
+ }
38
+
39
+ export interface RelayRequest {
40
+ messages: RelayMessage[];
41
+ }
42
+
43
+ export interface RelayResult {
44
+ id: string;
45
+ status: MailResultStatus;
46
+ reason: MailRefusal | null;
47
+ retryable: boolean;
48
+ /** the field a malformed message got wrong, or Mailjet's words for a message it refused */
49
+ detail: string | null;
50
+ /** true when this id was already sent by an earlier call — nothing was sent twice */
51
+ duplicate: boolean;
52
+ messageUuid: string | null;
53
+ }
54
+
55
+ /** This month's counts — what the quota counts is `total`, both kinds. */
56
+ export interface RelayMonth {
57
+ total: number;
58
+ transactional: number;
59
+ marketing: number;
60
+ /** refusals this month by reason */
61
+ refused: Partial<Record<MailRefusal | string, number>>;
62
+ hardBounced: number;
63
+ softBounced: number;
64
+ blocked: number;
65
+ complained: number;
66
+ unsubscribed: number;
67
+ }
68
+
69
+ /** `GET /instances/me/mail/usage` (and every send's `usage`). Dates are ISO strings on the wire. */
70
+ export interface RelayUsage {
71
+ /** the plan has IOX mail (`ioxMail`) */
72
+ enabled: boolean;
73
+ /** the control plane holds a Mailjet key */
74
+ configured: boolean;
75
+ senderState: MailSenderState;
76
+ transactionalFrom: { email: string; name: string };
77
+ marketingFrom: { email: string; name: string };
78
+ defaultReplyTo: string;
79
+ periodStart: string;
80
+ periodEnd: string;
81
+ /** `emailsPerMonth`; null = unlimited */
82
+ quota: number | null;
83
+ /** where transactional stops (2× the quota); null = unlimited */
84
+ ceiling: number | null;
85
+ month: RelayMonth;
86
+ suppressions: number;
87
+ marketingPaused: { at: string; reason: MarketingPauseReason | string } | null;
88
+ }
89
+
90
+ export interface RelayResponse {
91
+ results: RelayResult[];
92
+ usage: RelayUsage;
93
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @vectoriox/iox-ui/mail-core — IOX Mail's shared, FRAMEWORK-FREE vocabulary (iox-mail-plan ML2): a message's kind,
3
+ * who sends it, the relay's wire (`POST /instances/me/mail`, its usage) and refusals, and the ONE route rule — the
4
+ * studio's own active mailer wins, else IOX mail when the plan has it. The control plane (the relay), iox-cms (the
5
+ * transport and the MAILER connector) and the admin (Settings ▸ Email, ML3) speak it. It imports nothing.
6
+ * ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets, jest
7
+ * moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM.
8
+ */
9
+ export * from './mail-vocabulary';
10
+ export * from './mail-wire';
11
+ export * from './mail-route';