@push.rocks/smartjmap 1.0.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,110 @@
1
+ import type { IJmapEmailAddress } from './classes.jmapclient.js';
2
+ export interface IJmapServerMailbox {
3
+ id: string;
4
+ name: string;
5
+ role: string | null;
6
+ parentId: string | null;
7
+ sortOrder: number;
8
+ }
9
+ export interface IJmapServerBlob {
10
+ data: Buffer;
11
+ type: string;
12
+ name?: string;
13
+ }
14
+ export interface IJmapServerChangeEntry {
15
+ state: number;
16
+ created: string[];
17
+ updated: string[];
18
+ destroyed: string[];
19
+ }
20
+ export interface IJmapServerIdentity {
21
+ id: string;
22
+ name: string;
23
+ email: string;
24
+ mayDelete: boolean;
25
+ }
26
+ export interface IJmapServerSubmission {
27
+ id: string;
28
+ emailId: string;
29
+ identityId: string;
30
+ undoStatus: string;
31
+ sendAt: string;
32
+ }
33
+ export interface IJmapServerUser {
34
+ username: string;
35
+ password: string;
36
+ bearerTokens: Set<string>;
37
+ accountId: string;
38
+ mailboxes: Map<string, IJmapServerMailbox>;
39
+ emails: Map<string, Record<string, any>>;
40
+ blobs: Map<string, IJmapServerBlob>;
41
+ submissions: Map<string, IJmapServerSubmission>;
42
+ identities: IJmapServerIdentity[];
43
+ state: number;
44
+ changes: IJmapServerChangeEntry[];
45
+ idCounter: number;
46
+ }
47
+ export interface IJmapServerEmailInput {
48
+ from: IJmapEmailAddress | IJmapEmailAddress[];
49
+ to: IJmapEmailAddress | IJmapEmailAddress[];
50
+ cc?: IJmapEmailAddress[];
51
+ bcc?: IJmapEmailAddress[];
52
+ subject?: string;
53
+ textBody?: string;
54
+ htmlBody?: string;
55
+ keywords?: Record<string, boolean>;
56
+ receivedAt?: string;
57
+ attachments?: Array<{
58
+ name: string;
59
+ type: string;
60
+ content: string | Uint8Array;
61
+ }>;
62
+ }
63
+ /**
64
+ * A minimal in-memory JMAP server (RFC 8620 core + RFC 8621 mail subset)
65
+ * for offline testing. Serves the session resource at /.well-known/jmap and
66
+ * /jmap/session, the API at /jmap/api, blob downloads at /jmap/download/...,
67
+ * and StateChange pushes via SSE at /jmap/eventsource.
68
+ */
69
+ export declare class JmapServer {
70
+ users: Map<string, IJmapServerUser>;
71
+ private server;
72
+ private sockets;
73
+ private eventStreams;
74
+ constructor();
75
+ addUser(username: string, password: string): void;
76
+ /** Registers a valid Bearer token for a user. */
77
+ addBearerToken(username: string, token: string): void;
78
+ createMailbox(username: string, name: string, role?: string): string;
79
+ /** Seeds an email into a user's mailbox; bumps state and pushes a StateChange. Returns the email id. */
80
+ addEmail(username: string, mailboxName: string, input: IJmapServerEmailInput): string;
81
+ /** Starts the server. Resolves with the bound port (pass 0 for an ephemeral port). */
82
+ start(port: number): Promise<number>;
83
+ /** Stops the server, ending open event streams and destroying open connections. */
84
+ stop(): Promise<void>;
85
+ private handleRequest;
86
+ private authenticate;
87
+ private handleSession;
88
+ private handleApi;
89
+ private handleEventSource;
90
+ private handleDownload;
91
+ private dispatchMethod;
92
+ private methodMailboxGet;
93
+ private methodMailboxQuery;
94
+ private methodEmailGet;
95
+ private methodEmailQuery;
96
+ private methodEmailChanges;
97
+ private methodEmailSet;
98
+ private methodIdentityGet;
99
+ private methodEmailSubmissionSet;
100
+ private requireUser;
101
+ private createEmailFromSpec;
102
+ /**
103
+ * Applies an Email/set update patch: either whole properties (e.g. keywords)
104
+ * or JSON-pointer style paths like "keywords/$seen" (RFC 8620 §5.3).
105
+ */
106
+ private applyPatch;
107
+ /** Increments the account state, records the change, and pushes a StateChange to open event streams. */
108
+ private bumpState;
109
+ private notifyStateChange;
110
+ }