@astram/core 1.8.0 → 1.9.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/dist/index.d.ts CHANGED
@@ -44,4 +44,5 @@ export * from './metadata/index.js';
44
44
  export * from './admin/index.js';
45
45
  export * from './storage/index.js';
46
46
  export * from './database/index.js';
47
+ export * from './messaging/index.js';
47
48
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AAKpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AAKpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -50,4 +50,6 @@ export * from './admin/index.js';
50
50
  export * from './storage/index.js';
51
51
  // Framework database names (configurable-framework-db, ADR-0037) — append-only.
52
52
  export * from './database/index.js';
53
+ // Message delivery ports (G-010) — append-only.
54
+ export * from './messaging/index.js';
53
55
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,kEAAkE;AAClE,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAEnC,mFAAmF;AACnF,cAAc,qBAAqB,CAAC;AAEpC,4EAA4E;AAC5E,iFAAiF;AACjF,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAEnC,gFAAgF;AAChF,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,kEAAkE;AAClE,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAEnC,mFAAmF;AACnF,cAAc,qBAAqB,CAAC;AAEpC,4EAA4E;AAC5E,iFAAiF;AACjF,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AAEnC,gFAAgF;AAChF,cAAc,qBAAqB,CAAC;AAEpC,gDAAgD;AAChD,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Engine seam: **Messaging** — framework messages (password reset, invite, email-change
3
+ * confirmation, security notices) leave through a channel port (G-010,
4
+ * docs/features/message-delivery/SPEC.md). Core defines the ports and the failure class; the
5
+ * provider adapters ship in `@astram/messaging` and guard binds, bounds and audits them.
6
+ *
7
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
8
+ */
9
+ export type { MessageChannel, MessagePurpose, EmailMessage, SmsMessage, WhatsAppMessage, DeliveryReceipt, SendOptions, CancellationSignal, MessageProvider, EmailProvider, SmsProvider, WhatsAppProvider, DeliveryFailureClass, } from './ports.js';
10
+ export { MESSAGE_PURPOSES, MessageDeliveryError, isE164PhoneNumber } from './ports.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messaging/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Engine seam: **Messaging** — framework messages (password reset, invite, email-change
3
+ * confirmation, security notices) leave through a channel port (G-010,
4
+ * docs/features/message-delivery/SPEC.md). Core defines the ports and the failure class; the
5
+ * provider adapters ship in `@astram/messaging` and guard binds, bounds and audits them.
6
+ *
7
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
8
+ */
9
+ export { MESSAGE_PURPOSES, MessageDeliveryError, isE164PhoneNumber } from './ports.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/messaging/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiBH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Message delivery ports (G-010, docs/features/message-delivery/SPEC.md R1). One port per channel,
3
+ * each with its own message shape. Adapters (SMTP, Brevo, SendGrid, Mailgun) ship in
4
+ * `@astram/messaging`; guard binds and audits them. SMS and WhatsApp are ports only until users
5
+ * carry phone numbers (OD-1).
6
+ *
7
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
8
+ */
9
+ /** The channels a provider can serve. */
10
+ export type MessageChannel = 'email' | 'sms' | 'whatsapp';
11
+ /** Why the framework sends a message. Recorded on every `message.sent` / `message.failed` row. */
12
+ export declare const MESSAGE_PURPOSES: readonly ["password_reset", "invite", "email_change_confirm", "security_notice"];
13
+ export type MessagePurpose = (typeof MESSAGE_PURPOSES)[number];
14
+ /** An email built by the framework. `html` interpolations are already escaped by the builder. */
15
+ export interface EmailMessage {
16
+ to: string;
17
+ subject: string;
18
+ html: string;
19
+ text: string;
20
+ }
21
+ /** An SMS. `to` is an E.164 number (`isE164PhoneNumber`). */
22
+ export interface SmsMessage {
23
+ to: string;
24
+ text: string;
25
+ }
26
+ /**
27
+ * A WhatsApp business-initiated message. Providers accept only pre-approved templates for these,
28
+ * so the message names a template and its positional parameters instead of free text.
29
+ */
30
+ export interface WhatsAppMessage {
31
+ to: string;
32
+ template: string;
33
+ language: string;
34
+ params: readonly string[];
35
+ }
36
+ /** What a provider returns for an accepted message: its name and its own id, for audit. */
37
+ export interface DeliveryReceipt {
38
+ provider: string;
39
+ messageId?: string;
40
+ }
41
+ /**
42
+ * The part of an `AbortSignal` a provider needs. Core compiles without DOM or Node types, so the
43
+ * port names the shape; a platform `AbortSignal` satisfies it.
44
+ */
45
+ export interface CancellationSignal {
46
+ readonly aborted: boolean;
47
+ addEventListener(type: 'abort', listener: () => void): void;
48
+ }
49
+ /** Per-send options. The signal aborts the send when the caller's bound expires. */
50
+ export interface SendOptions {
51
+ signal: CancellationSignal;
52
+ }
53
+ /**
54
+ * A provider adapter for one channel. `send` resolves with a receipt or rejects with a
55
+ * `MessageDeliveryError`. `probe` checks reachability and credentials WITHOUT sending a message.
56
+ */
57
+ export interface MessageProvider<M> {
58
+ readonly name: string;
59
+ send(message: M, options: SendOptions): Promise<DeliveryReceipt>;
60
+ probe?(options: SendOptions): Promise<void>;
61
+ }
62
+ export type EmailProvider = MessageProvider<EmailMessage>;
63
+ export type SmsProvider = MessageProvider<SmsMessage>;
64
+ export type WhatsAppProvider = MessageProvider<WhatsAppMessage>;
65
+ /**
66
+ * How a send failed. `transient` (network, 429, 5xx) may be retried once; `permanent` (other 4xx,
67
+ * bad credentials, rejected recipient) never is; `timeout` means the bound expired.
68
+ */
69
+ export type DeliveryFailureClass = 'transient' | 'permanent' | 'timeout';
70
+ /**
71
+ * A classified delivery failure. The message is built from fixed parts only (provider name,
72
+ * class, HTTP status): never a provider response body, recipient, token or credential.
73
+ */
74
+ export declare class MessageDeliveryError extends Error {
75
+ readonly failureClass: DeliveryFailureClass;
76
+ readonly provider: string;
77
+ readonly status?: number;
78
+ constructor(failureClass: DeliveryFailureClass, provider: string, detail?: {
79
+ status?: number;
80
+ });
81
+ }
82
+ /** True for an E.164 number: `+`, a non-zero country digit, 7–15 digits in all, nothing else. */
83
+ export declare function isE164PhoneNumber(value: string): boolean;
84
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/messaging/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yCAAyC;AACzC,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,CAAC;AAE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AAM,aAAa,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;AAC1D,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;AACtD,MAAM,MAAM,gBAAgB,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG,WAAW,GAAG,SAAS,CAAC;AAEzE;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAGvB,YAAY,EAAE,oBAAoB,EAClC,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;CASnC;AAID,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAExD"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Message delivery ports (G-010, docs/features/message-delivery/SPEC.md R1). One port per channel,
3
+ * each with its own message shape. Adapters (SMTP, Brevo, SendGrid, Mailgun) ship in
4
+ * `@astram/messaging`; guard binds and audits them. SMS and WhatsApp are ports only until users
5
+ * carry phone numbers (OD-1).
6
+ *
7
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
8
+ */
9
+ /** Why the framework sends a message. Recorded on every `message.sent` / `message.failed` row. */
10
+ export const MESSAGE_PURPOSES = Object.freeze([
11
+ 'password_reset',
12
+ 'invite',
13
+ 'email_change_confirm',
14
+ 'security_notice',
15
+ ]);
16
+ /**
17
+ * A classified delivery failure. The message is built from fixed parts only (provider name,
18
+ * class, HTTP status): never a provider response body, recipient, token or credential.
19
+ */
20
+ export class MessageDeliveryError extends Error {
21
+ failureClass;
22
+ provider;
23
+ status;
24
+ constructor(failureClass, provider, detail = {}) {
25
+ const status = detail.status !== undefined ? `, HTTP ${detail.status}` : '';
26
+ super(`${provider} delivery failed (${failureClass}${status})`);
27
+ this.name = 'MessageDeliveryError';
28
+ this.failureClass = failureClass;
29
+ this.provider = provider;
30
+ if (detail.status !== undefined)
31
+ this.status = detail.status;
32
+ }
33
+ }
34
+ const E164 = /^\+[1-9]\d{6,14}$/;
35
+ /** True for an E.164 number: `+`, a non-zero country digit, 7–15 digits in all, nothing else. */
36
+ export function isE164PhoneNumber(value) {
37
+ return E164.test(value);
38
+ }
39
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.js","sourceRoot":"","sources":["../../src/messaging/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,kGAAkG;AAClG,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,gBAAgB;IAChB,QAAQ;IACR,sBAAsB;IACtB,iBAAiB;CACT,CAAC,CAAC;AAoEZ;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IACpC,YAAY,CAAuB;IACnC,QAAQ,CAAS;IACjB,MAAM,CAAU;IAEzB,YACE,YAAkC,EAClC,QAAgB,EAChB,SAA8B,EAAE;QAEhC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,KAAK,CAAC,GAAG,QAAQ,qBAAqB,YAAY,GAAG,MAAM,GAAG,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/D,CAAC;CACF;AAED,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC,iGAAiG;AACjG,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC"}
package/dist-cjs/index.js CHANGED
@@ -66,3 +66,5 @@ __exportStar(require("./admin/index.js"), exports);
66
66
  __exportStar(require("./storage/index.js"), exports);
67
67
  // Framework database names (configurable-framework-db, ADR-0037) — append-only.
68
68
  __exportStar(require("./database/index.js"), exports);
69
+ // Message delivery ports (G-010) — append-only.
70
+ __exportStar(require("./messaging/index.js"), exports);
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * Engine seam: **Messaging** — framework messages (password reset, invite, email-change
4
+ * confirmation, security notices) leave through a channel port (G-010,
5
+ * docs/features/message-delivery/SPEC.md). Core defines the ports and the failure class; the
6
+ * provider adapters ship in `@astram/messaging` and guard binds, bounds and audits them.
7
+ *
8
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.isE164PhoneNumber = exports.MessageDeliveryError = exports.MESSAGE_PURPOSES = void 0;
12
+ var ports_js_1 = require("./ports.js");
13
+ Object.defineProperty(exports, "MESSAGE_PURPOSES", { enumerable: true, get: function () { return ports_js_1.MESSAGE_PURPOSES; } });
14
+ Object.defineProperty(exports, "MessageDeliveryError", { enumerable: true, get: function () { return ports_js_1.MessageDeliveryError; } });
15
+ Object.defineProperty(exports, "isE164PhoneNumber", { enumerable: true, get: function () { return ports_js_1.isE164PhoneNumber; } });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /**
3
+ * Message delivery ports (G-010, docs/features/message-delivery/SPEC.md R1). One port per channel,
4
+ * each with its own message shape. Adapters (SMTP, Brevo, SendGrid, Mailgun) ship in
5
+ * `@astram/messaging`; guard binds and audits them. SMS and WhatsApp are ports only until users
6
+ * carry phone numbers (OD-1).
7
+ *
8
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.MessageDeliveryError = exports.MESSAGE_PURPOSES = void 0;
12
+ exports.isE164PhoneNumber = isE164PhoneNumber;
13
+ /** Why the framework sends a message. Recorded on every `message.sent` / `message.failed` row. */
14
+ exports.MESSAGE_PURPOSES = Object.freeze([
15
+ 'password_reset',
16
+ 'invite',
17
+ 'email_change_confirm',
18
+ 'security_notice',
19
+ ]);
20
+ /**
21
+ * A classified delivery failure. The message is built from fixed parts only (provider name,
22
+ * class, HTTP status): never a provider response body, recipient, token or credential.
23
+ */
24
+ class MessageDeliveryError extends Error {
25
+ failureClass;
26
+ provider;
27
+ status;
28
+ constructor(failureClass, provider, detail = {}) {
29
+ const status = detail.status !== undefined ? `, HTTP ${detail.status}` : '';
30
+ super(`${provider} delivery failed (${failureClass}${status})`);
31
+ this.name = 'MessageDeliveryError';
32
+ this.failureClass = failureClass;
33
+ this.provider = provider;
34
+ if (detail.status !== undefined)
35
+ this.status = detail.status;
36
+ }
37
+ }
38
+ exports.MessageDeliveryError = MessageDeliveryError;
39
+ const E164 = /^\+[1-9]\d{6,14}$/;
40
+ /** True for an E.164 number: `+`, a non-zero country digit, 7–15 digits in all, nothing else. */
41
+ function isE164PhoneNumber(value) {
42
+ return E164.test(value);
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astram/core",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "license": "MIT",
5
5
  "description": "Astram framework — sealed security core (Identity, Authentication, Session, Risk, Authorization, Audit). ZERO framework deps — the portable decision brain (ADR-0003). The frozen public contract consumers build against; installed, not edited (ADR-0023).",
6
6
  "type": "module",