@memberjunction/communication-gmail 3.4.0 → 4.1.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/README.md +166 -211
- package/dist/GmailProvider.d.ts +175 -0
- package/dist/GmailProvider.d.ts.map +1 -0
- package/dist/GmailProvider.js +242 -70
- package/dist/GmailProvider.js.map +1 -1
- package/dist/auth.d.ts +3 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +13 -35
- package/dist/auth.js.map +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +14 -35
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -19
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
# @memberjunction/communication-gmail
|
|
2
2
|
|
|
3
|
-
Gmail/Google
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
Gmail / Google Workspace provider for the MemberJunction Communication Framework. This provider enables full mailbox operations -- sending, receiving, searching, managing labels, attachments, drafts, and more -- through the Gmail API with OAuth2 authentication.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
graph TD
|
|
9
|
+
subgraph gmail["@memberjunction/communication-gmail"]
|
|
10
|
+
GP["GmailProvider"]
|
|
11
|
+
AUTH["Auth Module\n(OAuth2 Client)"]
|
|
12
|
+
CFG["Config Module\n(Environment Variables)"]
|
|
13
|
+
CRED["GmailCredentials"]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
subgraph google["Google APIs"]
|
|
17
|
+
OAUTH["Google OAuth2"]
|
|
18
|
+
GAPI["Gmail API v1\n(/users/me/...)"]
|
|
19
|
+
MAILBOX["Gmail Mailbox"]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
subgraph base["@memberjunction/communication-types"]
|
|
23
|
+
BCP["BaseCommunicationProvider"]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
BCP --> GP
|
|
27
|
+
GP --> AUTH
|
|
28
|
+
GP --> CFG
|
|
29
|
+
GP --> CRED
|
|
30
|
+
AUTH --> OAUTH
|
|
31
|
+
GP --> GAPI
|
|
32
|
+
GAPI --> MAILBOX
|
|
33
|
+
|
|
34
|
+
style gmail fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
35
|
+
style google fill:#7c5295,stroke:#563a6b,color:#fff
|
|
36
|
+
style base fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
37
|
+
```
|
|
16
38
|
|
|
17
39
|
## Installation
|
|
18
40
|
|
|
@@ -22,260 +44,193 @@ npm install @memberjunction/communication-gmail
|
|
|
22
44
|
|
|
23
45
|
## Configuration
|
|
24
46
|
|
|
25
|
-
|
|
47
|
+
Set the following environment variables:
|
|
26
48
|
|
|
27
49
|
```env
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# Optional: Default sender email
|
|
35
|
-
GMAIL_SERVICE_ACCOUNT_EMAIL=noreply@yourdomain.com
|
|
50
|
+
GMAIL_CLIENT_ID=your-oauth2-client-id
|
|
51
|
+
GMAIL_CLIENT_SECRET=your-oauth2-client-secret
|
|
52
|
+
GMAIL_REDIRECT_URI=your-redirect-uri
|
|
53
|
+
GMAIL_REFRESH_TOKEN=your-refresh-token
|
|
54
|
+
GMAIL_SERVICE_ACCOUNT_EMAIL=noreply@yourdomain.com # optional default sender
|
|
36
55
|
```
|
|
37
56
|
|
|
38
|
-
### Obtaining OAuth2 Credentials
|
|
39
|
-
|
|
40
|
-
1. Go to the [Google Cloud Console](https://console.cloud.google.com/)
|
|
41
|
-
2. Create a new project or select an existing one
|
|
42
|
-
3. Enable the Gmail API for your project
|
|
43
|
-
4. Create OAuth2 credentials (OAuth 2.0 Client ID)
|
|
44
|
-
5. Set up the OAuth consent screen
|
|
45
|
-
6. Use the OAuth2 flow to obtain a refresh token with the required scopes
|
|
46
|
-
|
|
47
57
|
### Required OAuth2 Scopes
|
|
48
58
|
|
|
49
|
-
The provider requires the following Gmail API scopes:
|
|
50
59
|
- `https://www.googleapis.com/auth/gmail.send`
|
|
51
60
|
- `https://www.googleapis.com/auth/gmail.readonly`
|
|
52
61
|
- `https://www.googleapis.com/auth/gmail.modify`
|
|
53
62
|
- `https://www.googleapis.com/auth/gmail.compose`
|
|
54
63
|
|
|
64
|
+
### Obtaining OAuth2 Credentials
|
|
65
|
+
|
|
66
|
+
1. Go to the [Google Cloud Console](https://console.cloud.google.com/)
|
|
67
|
+
2. Create or select a project and enable the Gmail API
|
|
68
|
+
3. Create OAuth 2.0 Client ID credentials
|
|
69
|
+
4. Configure the OAuth consent screen
|
|
70
|
+
5. Use the OAuth2 flow to obtain a refresh token with the required scopes
|
|
71
|
+
|
|
72
|
+
## Supported Operations
|
|
73
|
+
|
|
74
|
+
This provider supports all 14 operations defined in `BaseCommunicationProvider`:
|
|
75
|
+
|
|
76
|
+
| Operation | Gmail Implementation |
|
|
77
|
+
|-----------|---------------------|
|
|
78
|
+
| `SendSingleMessage` | Send via `users.messages.send` |
|
|
79
|
+
| `GetMessages` | List and fetch with Gmail search query support |
|
|
80
|
+
| `GetSingleMessage` | Fetch single message by ID |
|
|
81
|
+
| `ForwardMessage` | Reconstruct and send as RFC 822 attachment |
|
|
82
|
+
| `ReplyToMessage` | Send in same thread via `threadId` |
|
|
83
|
+
| `CreateDraft` | Create via `users.drafts.create` |
|
|
84
|
+
| `DeleteMessage` | Trash or permanently delete |
|
|
85
|
+
| `MoveMessage` | Add/remove labels via `users.messages.modify` |
|
|
86
|
+
| `ListFolders` | List labels with optional message/unread counts |
|
|
87
|
+
| `MarkAsRead` | Add/remove UNREAD label (batch) |
|
|
88
|
+
| `ArchiveMessage` | Remove INBOX label |
|
|
89
|
+
| `SearchMessages` | Gmail query syntax with date filters |
|
|
90
|
+
| `ListAttachments` | Parse message parts recursively for attachments |
|
|
91
|
+
| `DownloadAttachment` | Download via `users.messages.attachments.get` |
|
|
92
|
+
|
|
55
93
|
## Usage
|
|
56
94
|
|
|
57
|
-
###
|
|
95
|
+
### Sending Email
|
|
58
96
|
|
|
59
97
|
```typescript
|
|
60
|
-
import {
|
|
98
|
+
import { CommunicationEngine } from '@memberjunction/communication-engine';
|
|
99
|
+
import { Message } from '@memberjunction/communication-types';
|
|
61
100
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Sending Emails
|
|
101
|
+
const engine = CommunicationEngine.Instance;
|
|
102
|
+
await engine.Config(false, contextUser);
|
|
67
103
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
104
|
+
const message = new Message();
|
|
105
|
+
message.From = 'sender@gmail.com';
|
|
106
|
+
message.To = 'recipient@example.com';
|
|
107
|
+
message.Subject = 'Hello from Gmail';
|
|
108
|
+
message.HTMLBody = '<h1>Hello</h1>';
|
|
109
|
+
message.CCRecipients = ['cc@example.com'];
|
|
71
110
|
|
|
72
|
-
const
|
|
111
|
+
const result = await engine.SendSingleMessage('Gmail', 'Email', message);
|
|
112
|
+
```
|
|
73
113
|
|
|
74
|
-
|
|
75
|
-
To: 'recipient@example.com',
|
|
76
|
-
From: 'sender@example.com', // Optional, uses authenticated account if not specified
|
|
77
|
-
FromName: 'Sender Name',
|
|
78
|
-
ProcessedSubject: 'Test Email',
|
|
79
|
-
ProcessedBody: 'This is a plain text email body',
|
|
80
|
-
ProcessedHTMLBody: '<html><body><h1>This is an HTML email</h1></body></html>',
|
|
81
|
-
CCRecipients: ['cc@example.com'],
|
|
82
|
-
BCCRecipients: ['bcc@example.com']
|
|
83
|
-
};
|
|
114
|
+
### Per-Request Credentials
|
|
84
115
|
|
|
85
|
-
|
|
116
|
+
Override credentials for multi-user scenarios:
|
|
86
117
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
118
|
+
```typescript
|
|
119
|
+
import { GmailCredentials } from '@memberjunction/communication-gmail';
|
|
120
|
+
|
|
121
|
+
const result = await provider.SendSingleMessage(processedMessage, {
|
|
122
|
+
clientId: 'other-client-id',
|
|
123
|
+
clientSecret: 'other-secret',
|
|
124
|
+
redirectUri: 'other-redirect',
|
|
125
|
+
refreshToken: 'user-specific-refresh-token'
|
|
126
|
+
} as GmailCredentials);
|
|
92
127
|
```
|
|
93
128
|
|
|
94
129
|
### Retrieving Messages
|
|
95
130
|
|
|
96
131
|
```typescript
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
console.log(`From: ${message.From}`);
|
|
113
|
-
console.log(`Subject: ${message.Subject}`);
|
|
114
|
-
console.log(`Body: ${message.Body}`);
|
|
115
|
-
});
|
|
116
|
-
} else {
|
|
117
|
-
console.error('Failed to get messages:', result.ErrorMessage);
|
|
118
|
-
}
|
|
132
|
+
const provider = engine.GetProvider('Gmail');
|
|
133
|
+
|
|
134
|
+
const result = await provider.GetMessages({
|
|
135
|
+
NumMessages: 10,
|
|
136
|
+
UnreadOnly: true,
|
|
137
|
+
ContextData: {
|
|
138
|
+
query: 'from:important@example.com', // Gmail search syntax
|
|
139
|
+
MarkAsRead: true
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
result.Messages.forEach(msg => {
|
|
144
|
+
console.log(`${msg.From}: ${msg.Subject}`);
|
|
145
|
+
console.log(`Thread: ${msg.ThreadID}`);
|
|
146
|
+
});
|
|
119
147
|
```
|
|
120
148
|
|
|
121
|
-
### Creating
|
|
149
|
+
### Creating Drafts
|
|
122
150
|
|
|
123
151
|
```typescript
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const draftMessage: ProcessedMessage = {
|
|
127
|
-
To: 'recipient@example.com',
|
|
128
|
-
From: 'sender@example.com',
|
|
129
|
-
ProcessedSubject: 'Draft Email Subject',
|
|
130
|
-
ProcessedBody: 'This is a draft email that can be edited later',
|
|
131
|
-
ProcessedHTMLBody: '<p>This is a draft email that can be edited later</p>',
|
|
132
|
-
CCRecipients: ['cc@example.com']
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const params: CreateDraftParams = {
|
|
136
|
-
Message: draftMessage
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const result: CreateDraftResult = await provider.CreateDraft(params);
|
|
140
|
-
|
|
152
|
+
const result = await provider.CreateDraft({ Message: processedMessage });
|
|
141
153
|
if (result.Success) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
} else {
|
|
145
|
-
console.error('Failed to create draft:', result.ErrorMessage);
|
|
154
|
+
console.log(`Draft ID: ${result.DraftID}`);
|
|
155
|
+
// Draft appears in Gmail drafts folder
|
|
146
156
|
}
|
|
147
157
|
```
|
|
148
158
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
### Replying to Messages
|
|
159
|
+
### Searching with Gmail Query Syntax
|
|
152
160
|
|
|
153
161
|
```typescript
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const params: ReplyToMessageParams = {
|
|
163
|
-
MessageID: 'original-message-id', // Gmail message ID
|
|
164
|
-
Message: replyMessage
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const result = await provider.ReplyToMessage(params);
|
|
168
|
-
|
|
169
|
-
if (result.Success) {
|
|
170
|
-
console.log('Reply sent successfully');
|
|
171
|
-
}
|
|
162
|
+
const result = await provider.SearchMessages({
|
|
163
|
+
Query: 'has:attachment',
|
|
164
|
+
FromDate: new Date('2025-01-01'),
|
|
165
|
+
ToDate: new Date('2025-06-01'),
|
|
166
|
+
FolderID: 'INBOX', // Gmail label ID
|
|
167
|
+
MaxResults: 50
|
|
168
|
+
});
|
|
172
169
|
```
|
|
173
170
|
|
|
174
|
-
###
|
|
171
|
+
### Managing Labels (Folders)
|
|
175
172
|
|
|
176
173
|
```typescript
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
BCCRecipients: ['bcc@example.com'],
|
|
184
|
-
Message: 'FYI - forwarding this message' // Optional forward comment
|
|
185
|
-
};
|
|
174
|
+
const folders = await provider.ListFolders({ IncludeCounts: true });
|
|
175
|
+
folders.Folders.forEach(f => {
|
|
176
|
+
console.log(`${f.Name} (${f.ID}): ${f.MessageCount} messages`);
|
|
177
|
+
console.log(` System: ${f.IsSystemFolder}, Type: ${f.SystemFolderType}`);
|
|
178
|
+
});
|
|
179
|
+
```
|
|
186
180
|
|
|
187
|
-
|
|
181
|
+
### Downloading Attachments
|
|
188
182
|
|
|
189
|
-
|
|
190
|
-
|
|
183
|
+
```typescript
|
|
184
|
+
const attachments = await provider.ListAttachments({ MessageID: 'msg-id' });
|
|
185
|
+
for (const att of attachments.Attachments) {
|
|
186
|
+
const download = await provider.DownloadAttachment({
|
|
187
|
+
MessageID: 'msg-id',
|
|
188
|
+
AttachmentID: att.ID
|
|
189
|
+
});
|
|
190
|
+
// download.Content is a Buffer
|
|
191
|
+
// download.ContentBase64 is base64 string
|
|
192
|
+
// download.Filename, download.ContentType available
|
|
191
193
|
}
|
|
192
194
|
```
|
|
193
195
|
|
|
194
|
-
##
|
|
195
|
-
|
|
196
|
-
### GmailProvider Class
|
|
197
|
-
|
|
198
|
-
The main provider class that extends `BaseCommunicationProvider` from `@memberjunction/communication-types`.
|
|
199
|
-
|
|
200
|
-
#### Methods
|
|
201
|
-
|
|
202
|
-
##### `SendSingleMessage(message: ProcessedMessage): Promise<MessageResult>`
|
|
203
|
-
Sends a single email message through Gmail.
|
|
204
|
-
|
|
205
|
-
##### `GetMessages(params: GetMessagesParams): Promise<GetMessagesResult>`
|
|
206
|
-
Retrieves messages from Gmail based on the provided parameters.
|
|
207
|
-
|
|
208
|
-
##### `ReplyToMessage(params: ReplyToMessageParams): Promise<ReplyToMessageResult>`
|
|
209
|
-
Replies to an existing Gmail message, maintaining the thread context.
|
|
210
|
-
|
|
211
|
-
##### `ForwardMessage(params: ForwardMessageParams): Promise<ForwardMessageResult>`
|
|
212
|
-
Forwards an existing Gmail message to new recipients.
|
|
196
|
+
## Gmail Label Mapping
|
|
213
197
|
|
|
214
|
-
|
|
198
|
+
Gmail uses labels instead of traditional folders. The provider maps system labels to standard folder types:
|
|
215
199
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
200
|
+
| Gmail Label | SystemFolderType |
|
|
201
|
+
|-------------|-----------------|
|
|
202
|
+
| `INBOX` | `inbox` |
|
|
203
|
+
| `SENT` | `sent` |
|
|
204
|
+
| `DRAFT` | `drafts` |
|
|
205
|
+
| `TRASH` | `trash` |
|
|
206
|
+
| `SPAM` | `spam` |
|
|
207
|
+
| User labels | `undefined` |
|
|
222
208
|
|
|
223
|
-
|
|
209
|
+
## Client Caching
|
|
224
210
|
|
|
225
|
-
The
|
|
226
|
-
- `GmailClient`: Pre-configured Gmail API client
|
|
227
|
-
- `getAuthenticatedUser()`: Helper function to verify authentication
|
|
211
|
+
The provider caches Gmail API client instances for performance. Environment credential clients are shared across all calls; per-request credential clients are cached by a key derived from `clientId` and `refreshToken`.
|
|
228
212
|
|
|
229
|
-
##
|
|
230
|
-
|
|
231
|
-
This provider integrates seamlessly with MemberJunction's communication framework:
|
|
213
|
+
## Security Considerations
|
|
232
214
|
|
|
233
|
-
1.
|
|
234
|
-
2.
|
|
235
|
-
3.
|
|
236
|
-
4.
|
|
215
|
+
1. Store refresh tokens securely and never commit them to version control
|
|
216
|
+
2. Request only the minimum required OAuth2 scopes
|
|
217
|
+
3. Use secure methods to manage environment variables in production
|
|
218
|
+
4. Regularly rotate client secrets and monitor API usage
|
|
237
219
|
|
|
238
220
|
## Dependencies
|
|
239
221
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
The provider includes comprehensive error handling:
|
|
250
|
-
- OAuth2 authentication failures
|
|
251
|
-
- API rate limiting
|
|
252
|
-
- Network errors
|
|
253
|
-
- Invalid message formats
|
|
254
|
-
- Missing required fields
|
|
255
|
-
|
|
256
|
-
All errors are logged using MemberJunction's logging system and returned with descriptive error messages.
|
|
257
|
-
|
|
258
|
-
## Security Considerations
|
|
259
|
-
|
|
260
|
-
1. **Refresh Token Security**: Store refresh tokens securely and never commit them to version control
|
|
261
|
-
2. **Scope Limitations**: Request only the minimum required OAuth2 scopes
|
|
262
|
-
3. **Environment Variables**: Use secure methods to manage environment variables in production
|
|
263
|
-
4. **API Credentials**: Regularly rotate client secrets and monitor API usage
|
|
222
|
+
| Package | Purpose |
|
|
223
|
+
|---------|---------|
|
|
224
|
+
| `@memberjunction/communication-types` | Base provider class and type definitions |
|
|
225
|
+
| `@memberjunction/core` | Logging utilities |
|
|
226
|
+
| `@memberjunction/global` | RegisterClass decorator |
|
|
227
|
+
| `googleapis` | Google APIs Node.js client |
|
|
228
|
+
| `dotenv` | Environment variable loading |
|
|
229
|
+
| `env-var` | Environment variable validation |
|
|
264
230
|
|
|
265
231
|
## Development
|
|
266
232
|
|
|
267
|
-
### Building
|
|
268
|
-
|
|
269
233
|
```bash
|
|
270
|
-
npm run build
|
|
234
|
+
npm run build # Compile TypeScript
|
|
235
|
+
npm run clean # Remove dist directory
|
|
271
236
|
```
|
|
272
|
-
|
|
273
|
-
### Cleaning
|
|
274
|
-
|
|
275
|
-
```bash
|
|
276
|
-
npm run clean
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
## License
|
|
280
|
-
|
|
281
|
-
This package is part of the MemberJunction ecosystem. See the root repository for license information.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { BaseCommunicationProvider, CreateDraftParams, CreateDraftResult, ForwardMessageParams, ForwardMessageResult, GetMessagesParams, GetMessagesResult, MessageResult, ProcessedMessage, ProviderCredentialsBase, ReplyToMessageParams, ReplyToMessageResult, ProviderOperation, GetSingleMessageParams, GetSingleMessageResult, DeleteMessageParams, DeleteMessageResult, MoveMessageParams, MoveMessageResult, ListFoldersParams, ListFoldersResult, MarkAsReadParams, MarkAsReadResult, ArchiveMessageParams, ArchiveMessageResult, SearchMessagesParams, SearchMessagesResult, ListAttachmentsParams, ListAttachmentsResult, DownloadAttachmentParams, DownloadAttachmentResult } from "@memberjunction/communication-types";
|
|
2
|
+
/**
|
|
3
|
+
* Credentials for Gmail provider using OAuth2.
|
|
4
|
+
* Extend ProviderCredentialsBase to support per-request credential override.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* **TEMPORARY INTERFACE**: This interface is part of the interim credential solution for 2.x patch release.
|
|
8
|
+
* In MemberJunction 3.0, this will be integrated with the comprehensive credential management system.
|
|
9
|
+
*/
|
|
10
|
+
export interface GmailCredentials extends ProviderCredentialsBase {
|
|
11
|
+
/** Google OAuth2 Client ID */
|
|
12
|
+
clientId?: string;
|
|
13
|
+
/** Google OAuth2 Client Secret */
|
|
14
|
+
clientSecret?: string;
|
|
15
|
+
/** OAuth2 Redirect URI */
|
|
16
|
+
redirectUri?: string;
|
|
17
|
+
/** OAuth2 Refresh Token */
|
|
18
|
+
refreshToken?: string;
|
|
19
|
+
/** Service account email (optional) */
|
|
20
|
+
serviceAccountEmail?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Implementation of the Gmail provider for sending and receiving messages
|
|
24
|
+
*/
|
|
25
|
+
export declare class GmailProvider extends BaseCommunicationProvider {
|
|
26
|
+
/** Cached Gmail client for environment credentials */
|
|
27
|
+
private envGmailClient;
|
|
28
|
+
/** Cache of Gmail clients for per-request credentials */
|
|
29
|
+
private clientCache;
|
|
30
|
+
/**
|
|
31
|
+
* Resolves credentials by merging request credentials with environment fallback
|
|
32
|
+
*/
|
|
33
|
+
private resolveCredentials;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a Gmail client with the given credentials
|
|
36
|
+
*/
|
|
37
|
+
private createGmailClient;
|
|
38
|
+
/**
|
|
39
|
+
* Gets a Gmail client for the given credentials, using caching for efficiency
|
|
40
|
+
*/
|
|
41
|
+
private getGmailClient;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the authenticated user's email address for a given cached client
|
|
44
|
+
*/
|
|
45
|
+
private getUserEmail;
|
|
46
|
+
/**
|
|
47
|
+
* Encode and format email content for Gmail API
|
|
48
|
+
*/
|
|
49
|
+
private createEmailContent;
|
|
50
|
+
/**
|
|
51
|
+
* Sends a single message using the Gmail API
|
|
52
|
+
* @param message - The message to send
|
|
53
|
+
* @param credentials - Optional credentials override for this request.
|
|
54
|
+
* If not provided, uses environment variables.
|
|
55
|
+
* Set `credentials.disableEnvironmentFallback = true` to require explicit credentials.
|
|
56
|
+
*/
|
|
57
|
+
SendSingleMessage(message: ProcessedMessage, credentials?: GmailCredentials): Promise<MessageResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets messages from Gmail
|
|
60
|
+
* @param params - Parameters for fetching messages
|
|
61
|
+
* @param credentials - Optional credentials override for this request.
|
|
62
|
+
* If not provided, uses environment variables.
|
|
63
|
+
* Set `credentials.disableEnvironmentFallback = true` to require explicit credentials.
|
|
64
|
+
*/
|
|
65
|
+
GetMessages(params: GetMessagesParams, credentials?: GmailCredentials): Promise<GetMessagesResult>;
|
|
66
|
+
/**
|
|
67
|
+
* Reply to a message using Gmail API
|
|
68
|
+
* @param params - Parameters for replying to a message
|
|
69
|
+
* @param credentials - Optional credentials override for this request.
|
|
70
|
+
* If not provided, uses environment variables.
|
|
71
|
+
* Set `credentials.disableEnvironmentFallback = true` to require explicit credentials.
|
|
72
|
+
*/
|
|
73
|
+
ReplyToMessage(params: ReplyToMessageParams, credentials?: GmailCredentials): Promise<ReplyToMessageResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Forward a message using Gmail API
|
|
76
|
+
* @param params - Parameters for forwarding a message
|
|
77
|
+
* @param credentials - Optional credentials override for this request.
|
|
78
|
+
* If not provided, uses environment variables.
|
|
79
|
+
* Set `credentials.disableEnvironmentFallback = true` to require explicit credentials.
|
|
80
|
+
*/
|
|
81
|
+
ForwardMessage(params: ForwardMessageParams, credentials?: GmailCredentials): Promise<ForwardMessageResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Helper to mark a message as read
|
|
84
|
+
*/
|
|
85
|
+
private markMessageAsRead;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a draft message in Gmail
|
|
88
|
+
* @param params - Parameters for creating a draft
|
|
89
|
+
* @param credentials - Optional credentials override for this request.
|
|
90
|
+
* If not provided, uses environment variables.
|
|
91
|
+
* Set `credentials.disableEnvironmentFallback = true` to require explicit credentials.
|
|
92
|
+
*/
|
|
93
|
+
CreateDraft(params: CreateDraftParams, credentials?: GmailCredentials): Promise<CreateDraftResult>;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the list of operations supported by the Gmail provider.
|
|
96
|
+
* Gmail supports all operations through its label-based system.
|
|
97
|
+
*/
|
|
98
|
+
getSupportedOperations(): ProviderOperation[];
|
|
99
|
+
/**
|
|
100
|
+
* Gets a single message by ID
|
|
101
|
+
* @param params - Parameters for retrieving the message
|
|
102
|
+
* @param credentials - Optional credentials override for this request
|
|
103
|
+
*/
|
|
104
|
+
GetSingleMessage(params: GetSingleMessageParams, credentials?: GmailCredentials): Promise<GetSingleMessageResult>;
|
|
105
|
+
/**
|
|
106
|
+
* Deletes a message from Gmail
|
|
107
|
+
* @param params - Parameters for deleting the message
|
|
108
|
+
* @param credentials - Optional credentials override for this request
|
|
109
|
+
*/
|
|
110
|
+
DeleteMessage(params: DeleteMessageParams, credentials?: GmailCredentials): Promise<DeleteMessageResult>;
|
|
111
|
+
/**
|
|
112
|
+
* Moves a message to a different label (Gmail's equivalent of folders)
|
|
113
|
+
* In Gmail, moving is done by adding/removing labels
|
|
114
|
+
* @param params - Parameters for moving the message
|
|
115
|
+
* @param credentials - Optional credentials override for this request
|
|
116
|
+
*/
|
|
117
|
+
MoveMessage(params: MoveMessageParams, credentials?: GmailCredentials): Promise<MoveMessageResult>;
|
|
118
|
+
/**
|
|
119
|
+
* Lists Gmail labels (Gmail's equivalent of folders)
|
|
120
|
+
* @param params - Parameters for listing labels
|
|
121
|
+
* @param credentials - Optional credentials override for this request
|
|
122
|
+
*/
|
|
123
|
+
ListFolders(params: ListFoldersParams, credentials?: GmailCredentials): Promise<ListFoldersResult>;
|
|
124
|
+
/**
|
|
125
|
+
* Marks messages as read or unread
|
|
126
|
+
* @param params - Parameters for marking messages
|
|
127
|
+
* @param credentials - Optional credentials override for this request
|
|
128
|
+
*/
|
|
129
|
+
MarkAsRead(params: MarkAsReadParams, credentials?: GmailCredentials): Promise<MarkAsReadResult>;
|
|
130
|
+
/**
|
|
131
|
+
* Archives a message (removes INBOX label in Gmail)
|
|
132
|
+
* @param params - Parameters for archiving the message
|
|
133
|
+
* @param credentials - Optional credentials override for this request
|
|
134
|
+
*/
|
|
135
|
+
ArchiveMessage(params: ArchiveMessageParams, credentials?: GmailCredentials): Promise<ArchiveMessageResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Searches messages using Gmail's search syntax
|
|
138
|
+
* @param params - Parameters for searching messages
|
|
139
|
+
* @param credentials - Optional credentials override for this request
|
|
140
|
+
*/
|
|
141
|
+
SearchMessages(params: SearchMessagesParams, credentials?: GmailCredentials): Promise<SearchMessagesResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Lists attachments on a message
|
|
144
|
+
* @param params - Parameters for listing attachments
|
|
145
|
+
* @param credentials - Optional credentials override for this request
|
|
146
|
+
*/
|
|
147
|
+
ListAttachments(params: ListAttachmentsParams, credentials?: GmailCredentials): Promise<ListAttachmentsResult>;
|
|
148
|
+
/**
|
|
149
|
+
* Downloads an attachment from a message
|
|
150
|
+
* @param params - Parameters for downloading the attachment
|
|
151
|
+
* @param credentials - Optional credentials override for this request
|
|
152
|
+
*/
|
|
153
|
+
DownloadAttachment(params: DownloadAttachmentParams, credentials?: GmailCredentials): Promise<DownloadAttachmentResult>;
|
|
154
|
+
/**
|
|
155
|
+
* Parses a Gmail message into the standard GetMessageMessage format
|
|
156
|
+
*/
|
|
157
|
+
private parseGmailMessage;
|
|
158
|
+
/**
|
|
159
|
+
* Maps Gmail label IDs to system folder types
|
|
160
|
+
*/
|
|
161
|
+
private mapGmailLabelToSystemFolder;
|
|
162
|
+
/**
|
|
163
|
+
* Formats a date for Gmail search query (YYYY/MM/DD)
|
|
164
|
+
*/
|
|
165
|
+
private formatDateForGmail;
|
|
166
|
+
/**
|
|
167
|
+
* Recursively extracts attachment information from message parts
|
|
168
|
+
*/
|
|
169
|
+
private extractAttachments;
|
|
170
|
+
/**
|
|
171
|
+
* Finds attachment info (filename, content type) by attachment ID
|
|
172
|
+
*/
|
|
173
|
+
private findAttachmentInfo;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=GmailProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GmailProvider.d.ts","sourceRoot":"","sources":["../src/GmailProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EAEpB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EAGpB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAm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