@stacksjs/email 0.70.112 → 0.70.113
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/sdk/index.d.ts +9 -0
- package/dist/sdk/index.js +14 -2
- package/package.json +5 -5
package/dist/sdk/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export declare const emailSDK: EmailSDK;
|
|
|
3
3
|
// Export convenience functions
|
|
4
4
|
export declare const sendEmail: (message: EmailMessage) => unknown;
|
|
5
5
|
export declare const getInbox: (mailbox: string, options?: { limit?: number; offset?: number }) => unknown;
|
|
6
|
+
export declare const getInboxStats: (mailbox: string) => unknown;
|
|
7
|
+
export declare const getUnreadCount: (mailbox: string) => unknown;
|
|
6
8
|
export declare const searchEmails: (mailbox: string, options: EmailSearchOptions) => unknown;
|
|
7
9
|
export declare const deleteEmail: (mailbox: string, messageId: string) => unknown;
|
|
8
10
|
export declare interface EmailAddress {
|
|
@@ -38,6 +40,11 @@ export declare interface InboxEmail {
|
|
|
38
40
|
hasAttachments?: boolean
|
|
39
41
|
path: string
|
|
40
42
|
}
|
|
43
|
+
export declare interface InboxStats {
|
|
44
|
+
total: number
|
|
45
|
+
unread: number
|
|
46
|
+
read: number
|
|
47
|
+
}
|
|
41
48
|
export declare interface EmailSearchOptions {
|
|
42
49
|
from?: string
|
|
43
50
|
to?: string
|
|
@@ -67,6 +74,8 @@ export declare class EmailSDK {
|
|
|
67
74
|
subject?: string
|
|
68
75
|
}): Promise<SendResult>;
|
|
69
76
|
getInbox(mailbox: string, options?: { limit?: number; offset?: number }): Promise<InboxEmail[]>;
|
|
77
|
+
getInboxStats(mailbox: string): Promise<InboxStats>;
|
|
78
|
+
getUnreadCount(mailbox: string): Promise<number>;
|
|
70
79
|
getEmail(mailbox: string, messageId: string): Promise<{
|
|
71
80
|
metadata: Record<string, any>
|
|
72
81
|
html?: string
|
package/dist/sdk/index.js
CHANGED
|
@@ -6,7 +6,8 @@ export class EmailSDK {
|
|
|
6
6
|
region;
|
|
7
7
|
domain;
|
|
8
8
|
constructor(options) {
|
|
9
|
-
|
|
9
|
+
const appName = (process.env.APP_NAME || "stacks").toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
10
|
+
this.bucket = options?.bucket || process.env.AWS_BUCKET || `${appName}-production-email`;
|
|
10
11
|
this.region = options?.region || process.env.AWS_REGION || "us-east-1";
|
|
11
12
|
const fromAddress = emailConfig?.from?.address, parsedDomain = fromAddress?.includes("@") ? fromAddress.split("@")[1] : void 0;
|
|
12
13
|
this.domain = options?.domain || parsedDomain || "stacksjs.com";
|
|
@@ -78,6 +79,17 @@ export class EmailSDK {
|
|
|
78
79
|
throw error;
|
|
79
80
|
}
|
|
80
81
|
}
|
|
82
|
+
async getInboxStats(mailbox) {
|
|
83
|
+
const inbox = await this.getInbox(mailbox, { limit: 1000 }), unread = inbox.filter((e) => !e.read).length;
|
|
84
|
+
return {
|
|
85
|
+
total: inbox.length,
|
|
86
|
+
unread,
|
|
87
|
+
read: inbox.length - unread
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async getUnreadCount(mailbox) {
|
|
91
|
+
return (await this.getInboxStats(mailbox)).unread;
|
|
92
|
+
}
|
|
81
93
|
async getEmail(mailbox, messageId) {
|
|
82
94
|
try {
|
|
83
95
|
const { S3Client } = await import("@stacksjs/ts-cloud"), s3 = new S3Client(this.region), [localPart, domain] = mailbox.includes("@") ? mailbox.split("@") : [mailbox, this.domain], email = (await this.getInbox(mailbox, { limit: 1000 })).find((e) => e.messageId === messageId);
|
|
@@ -215,5 +227,5 @@ export class EmailSDK {
|
|
|
215
227
|
return result;
|
|
216
228
|
}
|
|
217
229
|
}
|
|
218
|
-
export const emailSDK = new EmailSDK, sendEmail = (message) => emailSDK.send(message), getInbox = (mailbox, options) => emailSDK.getInbox(mailbox, options), searchEmails = (mailbox, options) => emailSDK.search(mailbox, options), deleteEmail = (mailbox, messageId) => emailSDK.delete(mailbox, messageId);
|
|
230
|
+
export const emailSDK = new EmailSDK, sendEmail = (message) => emailSDK.send(message), getInbox = (mailbox, options) => emailSDK.getInbox(mailbox, options), getInboxStats = (mailbox) => emailSDK.getInboxStats(mailbox), getUnreadCount = (mailbox) => emailSDK.getUnreadCount(mailbox), searchEmails = (mailbox, options) => emailSDK.search(mailbox, options), deleteEmail = (mailbox, messageId) => emailSDK.delete(mailbox, messageId);
|
|
219
231
|
export default EmailSDK;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/email",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.70.
|
|
5
|
+
"version": "0.70.113",
|
|
6
6
|
"description": "The Stacks Email integration. Painlessly create & manage your inboxes, templates, and send emails.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -58,10 +58,10 @@
|
|
|
58
58
|
"@stacksjs/ts-cloud": "^0.7.17"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@stacksjs/cli": "0.70.
|
|
62
|
-
"@stacksjs/config": "0.70.
|
|
61
|
+
"@stacksjs/cli": "0.70.113",
|
|
62
|
+
"@stacksjs/config": "0.70.113",
|
|
63
63
|
"better-dx": "^0.2.16",
|
|
64
|
-
"@stacksjs/error-handling": "0.70.
|
|
65
|
-
"@stacksjs/types": "0.70.
|
|
64
|
+
"@stacksjs/error-handling": "0.70.113",
|
|
65
|
+
"@stacksjs/types": "0.70.113"
|
|
66
66
|
}
|
|
67
67
|
}
|