@superdurable/connector-google-gmail 0.1.0 → 0.1.2
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 +5 -1
- package/dex-connector.json +2 -2
- package/dist/{chunk-C6LCJ6ZY.js → chunk-IAO6TPJ3.js} +210 -134
- package/dist/connection-NE_da2Az.d.cts +181 -0
- package/dist/connection-NE_da2Az.d.ts +181 -0
- package/dist/index.cjs +257 -184
- package/dist/index.d.cts +34 -34
- package/dist/index.d.ts +34 -34
- package/dist/index.js +3 -3
- package/dist/mock/index.cjs +294 -202
- package/dist/mock/index.d.cts +31 -30
- package/dist/mock/index.d.ts +31 -30
- package/dist/mock/index.js +152 -113
- package/package.json +5 -4
- package/dist/connection-ce8JHjE8.d.cts +0 -99
- package/dist/connection-ce8JHjE8.d.ts +0 -99
package/dist/index.cjs
CHANGED
|
@@ -41,9 +41,9 @@ __export(index_exports, {
|
|
|
41
41
|
ReplyToMessageOperation: () => ReplyToMessageOperation,
|
|
42
42
|
SendMessageBranch: () => SendMessageBranch,
|
|
43
43
|
SendMessageDefinition: () => SendMessageDefinition,
|
|
44
|
-
SendMessageInputSchema: () =>
|
|
44
|
+
SendMessageInputSchema: () => SendMessageInputSchema2,
|
|
45
45
|
SendMessageOperation: () => SendMessageOperation,
|
|
46
|
-
SendMessageOutputSchema: () =>
|
|
46
|
+
SendMessageOutputSchema: () => SendMessageOutputSchema2,
|
|
47
47
|
WorkspaceDomainDelegationAuthMethodID: () => WorkspaceDomainDelegationAuthMethodID,
|
|
48
48
|
buildMIMEMessage: () => buildMIMEMessage,
|
|
49
49
|
buildReplyMIMEMessage: () => buildReplyMIMEMessage,
|
|
@@ -53,11 +53,11 @@ __export(index_exports, {
|
|
|
53
53
|
gmailFailure: () => gmailFailure,
|
|
54
54
|
gmailRequestID: () => gmailRequestID,
|
|
55
55
|
gmailRetryAfterMs: () => gmailRetryAfterMs,
|
|
56
|
-
newGetMessageStep: () =>
|
|
56
|
+
newGetMessageStep: () => newGetMessageStep2,
|
|
57
57
|
newProjectConnection: () => newProjectConnection,
|
|
58
58
|
newProjectGmailClient: () => newProjectGmailClient,
|
|
59
|
-
newReplyToMessageStep: () =>
|
|
60
|
-
newSendMessageStep: () =>
|
|
59
|
+
newReplyToMessageStep: () => newReplyToMessageStep2,
|
|
60
|
+
newSendMessageStep: () => newSendMessageStep2,
|
|
61
61
|
parseMailbox: () => parseMailbox,
|
|
62
62
|
parseSentResponse: () => parseSentResponse,
|
|
63
63
|
receiptFor: () => receiptFor,
|
|
@@ -69,52 +69,90 @@ __export(index_exports, {
|
|
|
69
69
|
module.exports = __toCommonJS(index_exports);
|
|
70
70
|
|
|
71
71
|
// src/models.ts
|
|
72
|
+
var import_zod2 = require("zod");
|
|
73
|
+
|
|
74
|
+
// src/generated/models.ts
|
|
72
75
|
var import_zod = require("zod");
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
subject: import_zod.z.string(),
|
|
81
|
-
textBody: import_zod.z.string(),
|
|
82
|
-
htmlBody: import_zod.z.string().optional()
|
|
76
|
+
var import_connectors_sdk = require("@superdurable/connectors-sdk");
|
|
77
|
+
var ConfigSchema = import_zod.z.object({
|
|
78
|
+
"endpoint": import_zod.z.string().optional(),
|
|
79
|
+
"maxResponseBytes": import_zod.z.number().int().optional(),
|
|
80
|
+
"maxMessageBytes": import_zod.z.number().int().optional(),
|
|
81
|
+
"pollIntervalMs": import_zod.z.number().int().optional(),
|
|
82
|
+
"pollPageSize": import_zod.z.number().int().optional()
|
|
83
83
|
});
|
|
84
|
-
var
|
|
85
|
-
messageId: import_zod.z.string()
|
|
86
|
-
textBody: import_zod.z.string(),
|
|
87
|
-
htmlBody: import_zod.z.string().optional()
|
|
84
|
+
var GetMessageInputSchema = import_zod.z.strictObject({
|
|
85
|
+
"messageId": import_zod.z.string()
|
|
88
86
|
});
|
|
89
87
|
var MessageSchema = import_zod.z.strictObject({
|
|
90
|
-
messageId: import_zod.z.string(),
|
|
91
|
-
threadId: import_zod.z.string(),
|
|
92
|
-
rfcMessageId: import_zod.z.string().optional(),
|
|
93
|
-
inReplyTo: import_zod.z.string().optional(),
|
|
94
|
-
references: import_zod.z.string().optional(),
|
|
95
|
-
from: import_zod.z.string(),
|
|
96
|
-
replyTo: import_zod.z.string().optional(),
|
|
97
|
-
to: import_zod.z.array(import_zod.z.string()).optional(),
|
|
98
|
-
subject: import_zod.z.string(),
|
|
99
|
-
textBody: import_zod.z.string().optional(),
|
|
100
|
-
htmlBody: import_zod.z.string().optional(),
|
|
101
|
-
snippet: import_zod.z.string().optional(),
|
|
102
|
-
receivedAt: import_zod.z.iso.datetime({ offset: true }),
|
|
103
|
-
labelIds: import_zod.z.array(import_zod.z.string()).optional()
|
|
88
|
+
"messageId": import_zod.z.string(),
|
|
89
|
+
"threadId": import_zod.z.string(),
|
|
90
|
+
"rfcMessageId": import_zod.z.string().optional(),
|
|
91
|
+
"inReplyTo": import_zod.z.string().optional(),
|
|
92
|
+
"references": import_zod.z.string().optional(),
|
|
93
|
+
"from": import_zod.z.string(),
|
|
94
|
+
"replyTo": import_zod.z.string().optional(),
|
|
95
|
+
"to": import_zod.z.array(import_zod.z.string()).optional(),
|
|
96
|
+
"subject": import_zod.z.string(),
|
|
97
|
+
"textBody": import_zod.z.string().optional(),
|
|
98
|
+
"htmlBody": import_zod.z.string().optional(),
|
|
99
|
+
"snippet": import_zod.z.string().optional(),
|
|
100
|
+
"receivedAt": import_zod.z.iso.datetime({ offset: true }),
|
|
101
|
+
"labelIds": import_zod.z.array(import_zod.z.string()).optional()
|
|
102
|
+
});
|
|
103
|
+
var SendMessageInputSchema = import_zod.z.strictObject({
|
|
104
|
+
"to": import_zod.z.array(import_zod.z.string()).nullable(),
|
|
105
|
+
"subject": import_zod.z.string(),
|
|
106
|
+
"textBody": import_zod.z.string(),
|
|
107
|
+
"htmlBody": import_zod.z.string().optional()
|
|
104
108
|
});
|
|
105
109
|
var SendMessageOutputSchema = import_zod.z.strictObject({
|
|
106
|
-
sender: import_zod.z.string(),
|
|
107
|
-
recipients: import_zod.z.array(import_zod.z.string()),
|
|
108
|
-
messageId: import_zod.z.string(),
|
|
109
|
-
threadId: import_zod.z.string()
|
|
110
|
+
"sender": import_zod.z.string(),
|
|
111
|
+
"recipients": import_zod.z.array(import_zod.z.string()).nullable(),
|
|
112
|
+
"messageId": import_zod.z.string(),
|
|
113
|
+
"threadId": import_zod.z.string()
|
|
114
|
+
});
|
|
115
|
+
var ReplyToMessageInputSchema = import_zod.z.strictObject({
|
|
116
|
+
"messageId": import_zod.z.string(),
|
|
117
|
+
"textBody": import_zod.z.string(),
|
|
118
|
+
"htmlBody": import_zod.z.string().optional()
|
|
110
119
|
});
|
|
111
120
|
|
|
112
|
-
// src/
|
|
113
|
-
var
|
|
114
|
-
|
|
115
|
-
|
|
121
|
+
// src/models.ts
|
|
122
|
+
var SendMessageInputSchema2 = import_zod2.z.strictObject({
|
|
123
|
+
to: import_zod2.z.array(import_zod2.z.string()),
|
|
124
|
+
subject: import_zod2.z.string(),
|
|
125
|
+
textBody: import_zod2.z.string(),
|
|
126
|
+
htmlBody: import_zod2.z.string().optional()
|
|
127
|
+
});
|
|
128
|
+
var SendMessageOutputSchema2 = import_zod2.z.strictObject({
|
|
129
|
+
sender: import_zod2.z.string(),
|
|
130
|
+
recipients: import_zod2.z.array(import_zod2.z.string()),
|
|
131
|
+
messageId: import_zod2.z.string(),
|
|
132
|
+
threadId: import_zod2.z.string()
|
|
133
|
+
});
|
|
134
|
+
var ConnectorID = "gmail";
|
|
135
|
+
var ProviderID = "google";
|
|
136
|
+
var GoogleOAuthAuthMethodID = "google-oauth";
|
|
137
|
+
var WorkspaceDomainDelegationAuthMethodID = "workspace-domain-delegation";
|
|
138
|
+
|
|
139
|
+
// src/generated/definitions.ts
|
|
140
|
+
var ConnectorID2 = "gmail";
|
|
141
|
+
var ProviderID2 = "google";
|
|
142
|
+
var GetMessageBranch = {
|
|
143
|
+
Read: "read",
|
|
144
|
+
NotFound: "notFound",
|
|
145
|
+
ProviderRejected: "providerRejected",
|
|
146
|
+
InvalidResponse: "invalidResponse",
|
|
147
|
+
Defect: "defect"
|
|
148
|
+
};
|
|
149
|
+
var GetMessageBranchRead = GetMessageBranch.Read;
|
|
150
|
+
var GetMessageBranchNotFound = GetMessageBranch.NotFound;
|
|
151
|
+
var GetMessageBranchProviderRejected = GetMessageBranch.ProviderRejected;
|
|
152
|
+
var GetMessageBranchInvalidResponse = GetMessageBranch.InvalidResponse;
|
|
153
|
+
var GetMessageBranchDefect = GetMessageBranch.Defect;
|
|
116
154
|
var GetMessageDefinition = {
|
|
117
|
-
operation: { connectorId:
|
|
155
|
+
operation: { connectorId: ConnectorID2, operationId: "getMessage" },
|
|
118
156
|
branches: [
|
|
119
157
|
{ id: "read", description: "The Gmail message was read." },
|
|
120
158
|
{ id: "notFound", description: "The Gmail message does not exist.", optional: true },
|
|
@@ -124,53 +162,59 @@ var GetMessageDefinition = {
|
|
|
124
162
|
],
|
|
125
163
|
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
126
164
|
};
|
|
165
|
+
var SendMessageBranch = {
|
|
166
|
+
Sent: "sent",
|
|
167
|
+
ProviderRejected: "providerRejected",
|
|
168
|
+
Defect: "defect"
|
|
169
|
+
};
|
|
170
|
+
var SendMessageBranchSent = SendMessageBranch.Sent;
|
|
171
|
+
var SendMessageBranchProviderRejected = SendMessageBranch.ProviderRejected;
|
|
172
|
+
var SendMessageBranchDefect = SendMessageBranch.Defect;
|
|
127
173
|
var SendMessageDefinition = {
|
|
128
|
-
operation: { connectorId:
|
|
174
|
+
operation: { connectorId: ConnectorID2, operationId: "sendMessage" },
|
|
129
175
|
branches: [
|
|
130
176
|
{ id: "sent", description: "Gmail accepted the message; its message and thread IDs can be empty when an unusable accepted response has no Sent Mail match." },
|
|
131
177
|
{ id: "providerRejected", description: "Gmail conclusively rejected the message.", optional: true },
|
|
132
178
|
{ id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
|
|
133
179
|
],
|
|
134
|
-
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
180
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } }
|
|
181
|
+
};
|
|
182
|
+
var ReplyToMessageBranch = {
|
|
183
|
+
Sent: "sent",
|
|
184
|
+
ProviderRejected: "providerRejected",
|
|
185
|
+
InvalidResponse: "invalidResponse",
|
|
186
|
+
Defect: "defect"
|
|
141
187
|
};
|
|
188
|
+
var ReplyToMessageBranchSent = ReplyToMessageBranch.Sent;
|
|
189
|
+
var ReplyToMessageBranchProviderRejected = ReplyToMessageBranch.ProviderRejected;
|
|
190
|
+
var ReplyToMessageBranchInvalidResponse = ReplyToMessageBranch.InvalidResponse;
|
|
191
|
+
var ReplyToMessageBranchDefect = ReplyToMessageBranch.Defect;
|
|
142
192
|
var ReplyToMessageDefinition = {
|
|
143
|
-
operation: { connectorId:
|
|
193
|
+
operation: { connectorId: ConnectorID2, operationId: "replyToMessage" },
|
|
144
194
|
branches: [
|
|
145
195
|
{ id: "sent", description: "Gmail accepted the reply; its message ID can be empty when an unusable accepted response has no Sent Mail match, while the requested thread ID remains." },
|
|
146
196
|
{ id: "providerRejected", description: "Gmail conclusively rejected the reply.", optional: true },
|
|
147
197
|
{ id: "invalidResponse", description: "Gmail returned an invalid or oversized source message response before sending the reply.", optional: true },
|
|
148
198
|
{ id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
|
|
149
199
|
],
|
|
150
|
-
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "
|
|
151
|
-
initialIntervalMs: 1e3,
|
|
152
|
-
backoffCoefficient: 2,
|
|
153
|
-
maximumIntervalMs: 3e4,
|
|
154
|
-
maximumAttempts: 5,
|
|
155
|
-
totalDurationMs: 12e4
|
|
156
|
-
} }
|
|
200
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } }
|
|
157
201
|
};
|
|
158
202
|
|
|
159
203
|
// src/message.ts
|
|
160
204
|
var import_node_crypto = require("crypto");
|
|
161
|
-
var
|
|
162
|
-
var GmailMessagePartSchema =
|
|
163
|
-
mimeType:
|
|
164
|
-
headers:
|
|
165
|
-
body:
|
|
166
|
-
parts:
|
|
205
|
+
var import_zod3 = require("zod");
|
|
206
|
+
var GmailMessagePartSchema = import_zod3.z.lazy(() => import_zod3.z.object({
|
|
207
|
+
mimeType: import_zod3.z.string().nullish(),
|
|
208
|
+
headers: import_zod3.z.array(import_zod3.z.object({ name: import_zod3.z.string(), value: import_zod3.z.string() })).nullish(),
|
|
209
|
+
body: import_zod3.z.object({ data: import_zod3.z.string().nullish() }).nullish(),
|
|
210
|
+
parts: import_zod3.z.array(GmailMessagePartSchema).nullish()
|
|
167
211
|
}));
|
|
168
|
-
var GmailMessageResourceSchema =
|
|
169
|
-
id:
|
|
170
|
-
threadId:
|
|
171
|
-
labelIds:
|
|
172
|
-
snippet:
|
|
173
|
-
internalDate:
|
|
212
|
+
var GmailMessageResourceSchema = import_zod3.z.object({
|
|
213
|
+
id: import_zod3.z.string().nullish().transform((value) => value ?? ""),
|
|
214
|
+
threadId: import_zod3.z.string().nullish().transform((value) => value ?? ""),
|
|
215
|
+
labelIds: import_zod3.z.array(import_zod3.z.string()).nullish(),
|
|
216
|
+
snippet: import_zod3.z.string().nullish(),
|
|
217
|
+
internalDate: import_zod3.z.string().nullish(),
|
|
174
218
|
payload: GmailMessagePartSchema.nullish()
|
|
175
219
|
});
|
|
176
220
|
function decodeGmailMessage(resource) {
|
|
@@ -185,18 +229,18 @@ function decodeGmailMessage(resource) {
|
|
|
185
229
|
return {
|
|
186
230
|
messageId: resource.id,
|
|
187
231
|
threadId: resource.threadId,
|
|
188
|
-
rfcMessageId: headers.get("message-id")
|
|
189
|
-
inReplyTo: headers.get("in-reply-to")
|
|
190
|
-
references: headers.get("references")
|
|
232
|
+
...headers.get("message-id") ? { rfcMessageId: headers.get("message-id") } : {},
|
|
233
|
+
...headers.get("in-reply-to") ? { inReplyTo: headers.get("in-reply-to") } : {},
|
|
234
|
+
...headers.get("references") ? { references: headers.get("references") } : {},
|
|
191
235
|
from: headers.get("from") ?? "",
|
|
192
|
-
replyTo: headers.get("reply-to")
|
|
193
|
-
to,
|
|
236
|
+
...headers.get("reply-to") ? { replyTo: headers.get("reply-to") } : {},
|
|
237
|
+
...to.length ? { to } : {},
|
|
194
238
|
subject: decodeRFC2047Header(headers.get("subject") ?? ""),
|
|
195
|
-
textBody: textBodies.join("\n"),
|
|
196
|
-
htmlBody: htmlBodies.join("\n"),
|
|
197
|
-
snippet: resource.snippet
|
|
239
|
+
...textBodies.length ? { textBody: textBodies.join("\n") } : {},
|
|
240
|
+
...htmlBodies.length ? { htmlBody: htmlBodies.join("\n") } : {},
|
|
241
|
+
...resource.snippet ? { snippet: resource.snippet } : {},
|
|
198
242
|
receivedAt: receivedAt.toISOString().replace(".000Z", "Z"),
|
|
199
|
-
labelIds: resource.labelIds
|
|
243
|
+
...resource.labelIds?.length ? { labelIds: resource.labelIds } : {}
|
|
200
244
|
};
|
|
201
245
|
}
|
|
202
246
|
function visitGmailBody(part, textBodies, htmlBodies) {
|
|
@@ -331,7 +375,7 @@ function encodeSubject(value) {
|
|
|
331
375
|
}
|
|
332
376
|
|
|
333
377
|
// src/http.ts
|
|
334
|
-
var
|
|
378
|
+
var import_connectors_sdk2 = require("@superdurable/connectors-sdk");
|
|
335
379
|
var import_providerhttp = require("@superdurable/connectors-sdk/providerhttp");
|
|
336
380
|
function gmailClientSettings(config = {}) {
|
|
337
381
|
const endpoint = (0, import_providerhttp.validateBaseURL)(config.endpoint ?? "https://gmail.googleapis.com/gmail/v1");
|
|
@@ -370,7 +414,7 @@ var GmailHTTPClient = class {
|
|
|
370
414
|
/** Resolve a private token at call time; never put it in a receipt or Flow value. */
|
|
371
415
|
async resolveCredentials(call, signal) {
|
|
372
416
|
try {
|
|
373
|
-
const credentials = await (0,
|
|
417
|
+
const credentials = await (0, import_connectors_sdk2.resolveCredential)(this.#credentials, call, this.#refreshDriver, signal);
|
|
374
418
|
validateCredentials(credentials);
|
|
375
419
|
return credentials;
|
|
376
420
|
} catch {
|
|
@@ -402,7 +446,7 @@ var GmailHTTPClient = class {
|
|
|
402
446
|
}
|
|
403
447
|
if (response.status !== 401 || attempt !== 0 || !("resolveAfterRejection" in this.#credentials)) return { response, credentials: currentCredentials };
|
|
404
448
|
try {
|
|
405
|
-
const refreshed = await (0,
|
|
449
|
+
const refreshed = await (0, import_connectors_sdk2.resolveCredentialAfterRejection)(this.#credentials, call, this.#refreshDriver, signal);
|
|
406
450
|
validateCredentials(refreshed);
|
|
407
451
|
currentCredentials = refreshed;
|
|
408
452
|
} catch {
|
|
@@ -448,9 +492,9 @@ function validateCredentials(credentials) {
|
|
|
448
492
|
}
|
|
449
493
|
|
|
450
494
|
// src/provider.ts
|
|
451
|
-
var
|
|
452
|
-
var SentMessageSchema =
|
|
453
|
-
var SentSearchSchema =
|
|
495
|
+
var import_zod4 = require("zod");
|
|
496
|
+
var SentMessageSchema = import_zod4.z.object({ id: import_zod4.z.string().optional(), threadId: import_zod4.z.string().optional() });
|
|
497
|
+
var SentSearchSchema = import_zod4.z.object({ messages: import_zod4.z.array(SentMessageSchema).nullish() });
|
|
454
498
|
var GmailProvider = class {
|
|
455
499
|
#http;
|
|
456
500
|
/** Bind the shared authenticated transport. */
|
|
@@ -511,13 +555,13 @@ function parseSentResponse(response) {
|
|
|
511
555
|
}
|
|
512
556
|
|
|
513
557
|
// src/refresh.ts
|
|
514
|
-
var
|
|
558
|
+
var import_connectors_sdk3 = require("@superdurable/connectors-sdk");
|
|
515
559
|
var import_oauthtoken = require("@superdurable/connectors-sdk/oauthtoken");
|
|
516
|
-
var
|
|
560
|
+
var import_zod5 = require("zod");
|
|
517
561
|
var GoogleOAuthTokenEndpoint = "https://oauth2.googleapis.com/token";
|
|
518
562
|
var RequiredGmailScopes = ["https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/gmail.send"];
|
|
519
563
|
var TerminalErrorCodes = ["invalid_grant", "invalid_client", "unauthorized_client"];
|
|
520
|
-
var ServiceAccountKeySchema =
|
|
564
|
+
var ServiceAccountKeySchema = import_zod5.z.object({ client_email: import_zod5.z.string().min(1), private_key: import_zod5.z.string().min(1), token_uri: import_zod5.z.url() });
|
|
521
565
|
var GmailCredentialRefreshDriver = class {
|
|
522
566
|
#fetch;
|
|
523
567
|
#now;
|
|
@@ -535,7 +579,7 @@ var GmailCredentialRefreshDriver = class {
|
|
|
535
579
|
async refresh(state, signal) {
|
|
536
580
|
const credentials = state.credentials;
|
|
537
581
|
if (!credentials.authMethodId || credentials.authMethodId === GoogleOAuthAuthMethodID) {
|
|
538
|
-
if (!credentials.oauthClientId || !credentials.oauthClientSecret || !credentials.refreshToken) throw new
|
|
582
|
+
if (!credentials.oauthClientId || !credentials.oauthClientSecret || !credentials.refreshToken) throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
539
583
|
const token2 = await this.#tokenEndpoint(GoogleOAuthTokenEndpoint).exchangeRefreshToken({
|
|
540
584
|
id: credentials.oauthClientId,
|
|
541
585
|
secret: credentials.oauthClientSecret,
|
|
@@ -547,26 +591,27 @@ var GmailCredentialRefreshDriver = class {
|
|
|
547
591
|
expiresAt: new Date(this.#now().getTime() + token2.expiresInMs)
|
|
548
592
|
};
|
|
549
593
|
}
|
|
550
|
-
if (credentials.authMethodId !== WorkspaceDomainDelegationAuthMethodID) throw new
|
|
594
|
+
if (credentials.authMethodId !== WorkspaceDomainDelegationAuthMethodID) throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
551
595
|
let key;
|
|
552
596
|
try {
|
|
553
597
|
key = ServiceAccountKeySchema.parse(JSON.parse(credentials.serviceAccountKey?.reveal() ?? ""));
|
|
554
598
|
} catch {
|
|
555
|
-
throw new
|
|
599
|
+
throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
556
600
|
}
|
|
557
|
-
|
|
601
|
+
const delegatedUser = credentials.delegatedUser;
|
|
602
|
+
if (new URL(key.token_uri).protocol !== "https:" || !delegatedUser || !parseMailbox(delegatedUser)) throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
558
603
|
let assertion;
|
|
559
604
|
try {
|
|
560
605
|
assertion = (0, import_oauthtoken.signJWTBearerAssertion)({
|
|
561
606
|
issuer: key.client_email,
|
|
562
|
-
subject:
|
|
607
|
+
subject: delegatedUser,
|
|
563
608
|
audience: key.token_uri,
|
|
564
609
|
scope: RequiredGmailScopes.join(" "),
|
|
565
610
|
issuedAt: this.#now(),
|
|
566
611
|
lifetimeMs: 36e5
|
|
567
612
|
}, (0, import_oauthtoken.parseRSAPrivateKeyPEM)(key.private_key));
|
|
568
613
|
} catch {
|
|
569
|
-
throw new
|
|
614
|
+
throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
570
615
|
}
|
|
571
616
|
const token = await this.#tokenEndpoint(key.token_uri).exchangeJWTBearerAssertion(assertion, signal);
|
|
572
617
|
this.#verifyScopes(token.scope);
|
|
@@ -579,12 +624,12 @@ var GmailCredentialRefreshDriver = class {
|
|
|
579
624
|
return new import_oauthtoken.TokenEndpoint({ providerName: "Google", url, terminalErrorCodes: TerminalErrorCodes, fetch: this.#fetch });
|
|
580
625
|
}
|
|
581
626
|
#verifyScopes(scope) {
|
|
582
|
-
if (scope && !(0, import_oauthtoken.hasAllScopes)(scope, RequiredGmailScopes)) throw new
|
|
627
|
+
if (scope && !(0, import_oauthtoken.hasAllScopes)(scope, RequiredGmailScopes)) throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
583
628
|
}
|
|
584
629
|
};
|
|
585
630
|
|
|
586
631
|
// src/send.ts
|
|
587
|
-
var
|
|
632
|
+
var import_connectors_sdk4 = require("@superdurable/connectors-sdk");
|
|
588
633
|
var import_providerhttp2 = require("@superdurable/connectors-sdk/providerhttp");
|
|
589
634
|
var import_singledispatch = require("@superdurable/connectors-sdk/singledispatch");
|
|
590
635
|
var import_promises = require("timers/promises");
|
|
@@ -697,7 +742,7 @@ var GmailSender = class {
|
|
|
697
742
|
const budget = new GmailSendAttemptBudget(call.context.cancellationSignal, dexDeadline);
|
|
698
743
|
if (!budget.sendSignal()) {
|
|
699
744
|
await recordPreSendRetry(fence);
|
|
700
|
-
return (0,
|
|
745
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure("sendMessage", "AVAILABILITY", "too little of the Execute attempt is left to send safely, so nothing was sent"));
|
|
701
746
|
}
|
|
702
747
|
let credentials;
|
|
703
748
|
try {
|
|
@@ -707,7 +752,7 @@ var GmailSender = class {
|
|
|
707
752
|
}
|
|
708
753
|
let recipients;
|
|
709
754
|
try {
|
|
710
|
-
if (!
|
|
755
|
+
if (!SendMessageInputSchema2.safeParse(input).success) throw new TypeError();
|
|
711
756
|
recipients = validateSendInput(input, credentials.primaryEmail);
|
|
712
757
|
} catch (error) {
|
|
713
758
|
return defect("sendMessage", "VALIDATION", error instanceof TypeError && error.message ? error.message : "sender, recipients, subject, and text body are required");
|
|
@@ -729,7 +774,7 @@ var GmailSender = class {
|
|
|
729
774
|
const budget = new GmailSendAttemptBudget(call.context.cancellationSignal, dexDeadline);
|
|
730
775
|
if (!budget.sendSignal()) {
|
|
731
776
|
await recordPreSendRetry(fence);
|
|
732
|
-
return (0,
|
|
777
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure("replyToMessage", "AVAILABILITY", "too little of the Execute attempt is left to send safely, so nothing was sent"));
|
|
733
778
|
}
|
|
734
779
|
let credentials;
|
|
735
780
|
try {
|
|
@@ -756,9 +801,9 @@ var GmailSender = class {
|
|
|
756
801
|
if (found) return this.#sentMessage(call, budget, credentials, ReplyToMessageOutcomes, { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true }, found, this.#receipt(call));
|
|
757
802
|
} catch {
|
|
758
803
|
await recordPreSendRetry(fence);
|
|
759
|
-
return (0,
|
|
804
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure("replyToMessage", "AVAILABILITY", "Gmail sent-mail search did not answer before the reply"));
|
|
760
805
|
}
|
|
761
|
-
if (fence.decide().kind === "readBackRequired") return (0,
|
|
806
|
+
if (fence.decide().kind === "readBackRequired") return (0, import_connectors_sdk4.newMutationRetry)(failure("replyToMessage", "AVAILABILITY", "Gmail reply outcome is unknown; the sent-mail search found no message"));
|
|
762
807
|
}
|
|
763
808
|
let source;
|
|
764
809
|
try {
|
|
@@ -781,16 +826,16 @@ var GmailSender = class {
|
|
|
781
826
|
try {
|
|
782
827
|
message = decodeGmailMessage(source.resource);
|
|
783
828
|
} catch {
|
|
784
|
-
return (0,
|
|
829
|
+
return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), this.#receipt(call, gmailRequestID(source.response.headers), input.messageId), failure("replyToMessage", "PROTOCOL", "source message lacks reply metadata"));
|
|
785
830
|
}
|
|
786
|
-
if (!message.threadId || !message.rfcMessageId) return (0,
|
|
831
|
+
if (!message.threadId || !message.rfcMessageId) return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), this.#receipt(call, gmailRequestID(source.response.headers), input.messageId), failure("replyToMessage", "PROTOCOL", "source message lacks reply metadata"));
|
|
787
832
|
let recipient;
|
|
788
833
|
try {
|
|
789
834
|
recipient = replyRecipient(message);
|
|
790
835
|
} catch {
|
|
791
|
-
return (0,
|
|
836
|
+
return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), this.#receipt(call, gmailRequestID(source.response.headers), input.messageId), failure("replyToMessage", "PROTOCOL", "Gmail returned an invalid source sender"));
|
|
792
837
|
}
|
|
793
|
-
if (/[\r\n]/.test(message.subject + message.rfcMessageId + (message.references ?? ""))) return (0,
|
|
838
|
+
if (/[\r\n]/.test(message.subject + message.rfcMessageId + (message.references ?? ""))) return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), this.#receipt(call, gmailRequestID(source.response.headers), input.messageId), failure("replyToMessage", "PROTOCOL", "Gmail returned invalid source reply headers"));
|
|
794
839
|
let raw;
|
|
795
840
|
try {
|
|
796
841
|
raw = buildReplyMIMEMessage(call.id, call.idempotencyKey ?? call.id, this.#messageID(call), credentials.primaryEmail, message, input);
|
|
@@ -819,18 +864,18 @@ var GmailSender = class {
|
|
|
819
864
|
if (found) return this.#sentMessage(call, budget, credentials, operation, message, found, this.#receipt(call));
|
|
820
865
|
} catch {
|
|
821
866
|
await recordPreSendRetry(fence);
|
|
822
|
-
return (0,
|
|
867
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, "AVAILABILITY", `Gmail sent-mail search did not answer before the ${operation.requestName}`));
|
|
823
868
|
}
|
|
824
869
|
}
|
|
825
|
-
if (fence.decide().kind === "readBackRequired") return (0,
|
|
870
|
+
if (fence.decide().kind === "readBackRequired") return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, "AVAILABILITY", `Gmail ${operation.requestName} outcome is unknown; the sent-mail search found no message`));
|
|
826
871
|
let response;
|
|
827
872
|
try {
|
|
828
873
|
response = await fence.dispatch((signal) => this.#provider.sendMessage(call, credentials, message.raw, message.requestedThreadId, signal));
|
|
829
874
|
} catch (error) {
|
|
830
|
-
if (error instanceof import_singledispatch.InsufficientTimeError || error instanceof import_singledispatch.CheckpointError) return (0,
|
|
875
|
+
if (error instanceof import_singledispatch.InsufficientTimeError || error instanceof import_singledispatch.CheckpointError) return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, "AVAILABILITY", "too little of the Execute attempt is left to send safely, so nothing was sent"));
|
|
831
876
|
if (error instanceof import_providerhttp2.ProviderTransportError && error.isProvablyNotSent || error instanceof import_providerhttp2.AddressRefusal) {
|
|
832
877
|
await recordSafeResend(fence);
|
|
833
|
-
return (0,
|
|
878
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, "TRANSPORT", `Gmail ${operation.requestName} request was not dispatched`));
|
|
834
879
|
}
|
|
835
880
|
if (error instanceof import_providerhttp2.BodyTooLargeError && error.status) return this.#classifySendStatus(call, fence, budget, credentials, operation, message, error.status, error.headers ?? {}, void 0);
|
|
836
881
|
return this.#confirmPossiblySent(call, budget, credentials, operation, message, "TRANSPORT", `Gmail ${operation.requestName} outcome is unknown`, this.#receipt(call));
|
|
@@ -861,7 +906,7 @@ var GmailSender = class {
|
|
|
861
906
|
} catch {
|
|
862
907
|
}
|
|
863
908
|
}
|
|
864
|
-
return (0,
|
|
909
|
+
return (0, import_connectors_sdk4.newMutationBranch)(operation.providerRejectedBranch, emptySend(), receipt, failure(operation.operationId, statusFailureKind(status), operation.rejectionMessage));
|
|
865
910
|
}
|
|
866
911
|
if (!sentResponse) {
|
|
867
912
|
const lookup = await this.#pollSentMessage(call, budget, credentials);
|
|
@@ -873,7 +918,7 @@ var GmailSender = class {
|
|
|
873
918
|
const lookup = await this.#pollSentMessage(call, budget, credentials);
|
|
874
919
|
if (lookup.sent) return this.#sentMessage(call, budget, credentials, operation, message, lookup.sent, receipt);
|
|
875
920
|
const suffix = lookup.hadError ? "the sent-mail search did not answer" : "the sent-mail search found no message";
|
|
876
|
-
return (0,
|
|
921
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, kind, `${reason}; ${suffix}`));
|
|
877
922
|
}
|
|
878
923
|
async #sentMessage(call, budget, credentials, operation, message, sent, receipt) {
|
|
879
924
|
let threadId = sent.threadId;
|
|
@@ -885,7 +930,7 @@ var GmailSender = class {
|
|
|
885
930
|
threadId = message.requestedThreadId;
|
|
886
931
|
}
|
|
887
932
|
}
|
|
888
|
-
return (0,
|
|
933
|
+
return (0, import_connectors_sdk4.newMutationBranch)(operation.sentBranch, { sender: credentials.primaryEmail, recipients: message.recipients, messageId: sent.id, threadId }, { ...receipt, providerObjectId: sent.id });
|
|
889
934
|
}
|
|
890
935
|
async #pollSentMessage(call, budget, credentials) {
|
|
891
936
|
let hadError = false;
|
|
@@ -941,23 +986,23 @@ function emptySend() {
|
|
|
941
986
|
return { sender: "", recipients: [], messageId: "", threadId: "" };
|
|
942
987
|
}
|
|
943
988
|
function defect(operation, kind, message) {
|
|
944
|
-
return (0,
|
|
989
|
+
return (0, import_connectors_sdk4.newMutationBranch)("defect", emptySend(), (0, import_connectors_sdk4.zeroReceipt)(), failure(operation, kind, message));
|
|
945
990
|
}
|
|
946
991
|
function retryAfterRefusal(operation, kind, message, headers) {
|
|
947
992
|
try {
|
|
948
|
-
return (0,
|
|
993
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation, kind, message), gmailRetryAfterMs(headers));
|
|
949
994
|
} catch {
|
|
950
|
-
return (0,
|
|
995
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation, "PROTOCOL", "Gmail returned an invalid Retry-After header"));
|
|
951
996
|
}
|
|
952
997
|
}
|
|
953
998
|
function classifySourceFailure(status, headers, receipt) {
|
|
954
999
|
if (status === 0 || status === 429 || status >= 500) return retryAfterRefusal("replyToMessage", "AVAILABILITY", "Gmail source message is temporarily unavailable", headers);
|
|
955
|
-
if (status >= 200 && status < 300) return (0,
|
|
956
|
-
return (0,
|
|
1000
|
+
if (status >= 200 && status < 300) return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), receipt, failure("replyToMessage", "PROTOCOL", "Gmail returned an invalid source message response"));
|
|
1001
|
+
return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.ProviderRejected, emptySend(), receipt, failure("replyToMessage", statusFailureKind(status), "Gmail rejected the source message lookup"));
|
|
957
1002
|
}
|
|
958
1003
|
|
|
959
1004
|
// src/client.ts
|
|
960
|
-
var
|
|
1005
|
+
var import_connectors_sdk5 = require("@superdurable/connectors-sdk");
|
|
961
1006
|
var import_providerhttp3 = require("@superdurable/connectors-sdk/providerhttp");
|
|
962
1007
|
var GmailClient = class {
|
|
963
1008
|
#http;
|
|
@@ -1002,21 +1047,21 @@ var GetMessageOperation = class {
|
|
|
1002
1047
|
/** Classify one Gmail message read as a branch or safe retry. */
|
|
1003
1048
|
async invoke(call, input) {
|
|
1004
1049
|
if (!GetMessageInputSchema.safeParse(input).success || !input.messageId.trim()) {
|
|
1005
|
-
return (0,
|
|
1050
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.Defect, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "VALIDATION", "message ID is required"));
|
|
1006
1051
|
}
|
|
1007
1052
|
let credentials;
|
|
1008
1053
|
try {
|
|
1009
1054
|
credentials = await this.#http.resolveCredentials(call, call.context.cancellationSignal);
|
|
1010
1055
|
} catch {
|
|
1011
|
-
return (0,
|
|
1056
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.Defect, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "AUTHENTICATION", "connection credentials are unavailable"));
|
|
1012
1057
|
}
|
|
1013
1058
|
let result;
|
|
1014
1059
|
try {
|
|
1015
1060
|
result = await this.#provider.readMessage(call, credentials, input.messageId, "full", call.context.cancellationSignal);
|
|
1016
1061
|
} catch (error) {
|
|
1017
|
-
if (error instanceof GmailCredentialError) return (0,
|
|
1062
|
+
if (error instanceof GmailCredentialError) return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.Defect, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "AUTHENTICATION", "connection credentials are unavailable"));
|
|
1018
1063
|
if (error instanceof import_providerhttp3.BodyTooLargeError && error.status && error.status >= 200 && error.status < 300) {
|
|
1019
|
-
return (0,
|
|
1064
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.InvalidResponse, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "PROTOCOL", "Gmail returned an invalid or oversized message response"));
|
|
1020
1065
|
}
|
|
1021
1066
|
const status = error instanceof import_providerhttp3.BodyTooLargeError ? error.status ?? 0 : 0;
|
|
1022
1067
|
const headers = error instanceof import_providerhttp3.BodyTooLargeError ? error.headers ?? {} : {};
|
|
@@ -1027,9 +1072,9 @@ var GetMessageOperation = class {
|
|
|
1027
1072
|
try {
|
|
1028
1073
|
message = decodeGmailMessage(result.resource);
|
|
1029
1074
|
} catch {
|
|
1030
|
-
return (0,
|
|
1075
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.InvalidResponse, emptyMessage(), receiptFor(call, this.#now(), gmailRequestID(result.response.headers), input.messageId), gmailFailure("getMessage", "PROTOCOL", "Gmail returned an invalid message"));
|
|
1031
1076
|
}
|
|
1032
|
-
return (0,
|
|
1077
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.Read, message, {
|
|
1033
1078
|
provider: "gmail",
|
|
1034
1079
|
providerObjectId: message.messageId,
|
|
1035
1080
|
providerRequestId: gmailRequestID(result.response.headers),
|
|
@@ -1059,50 +1104,64 @@ function classifyReadFailure(status, headers) {
|
|
|
1059
1104
|
try {
|
|
1060
1105
|
retryAfterMs = gmailRetryAfterMs(headers);
|
|
1061
1106
|
} catch {
|
|
1062
|
-
return (0,
|
|
1107
|
+
return (0, import_connectors_sdk5.newQueryRetry)(gmailFailure("getMessage", "PROTOCOL", "Gmail returned an invalid Retry-After header"));
|
|
1063
1108
|
}
|
|
1064
|
-
return (0,
|
|
1109
|
+
return (0, import_connectors_sdk5.newQueryRetry)(gmailFailure("getMessage", "AVAILABILITY", "Gmail message is temporarily unavailable"), retryAfterMs);
|
|
1065
1110
|
}
|
|
1066
|
-
if (status === 404) return (0,
|
|
1111
|
+
if (status === 404) return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.NotFound, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)());
|
|
1067
1112
|
if (status >= 200 && status < 300) {
|
|
1068
|
-
return (0,
|
|
1113
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.InvalidResponse, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "PROTOCOL", "Gmail returned an invalid or oversized message response"));
|
|
1069
1114
|
}
|
|
1070
|
-
return (0,
|
|
1115
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.ProviderRejected, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", statusFailureKind(status), "Gmail message lookup failed"));
|
|
1071
1116
|
}
|
|
1072
1117
|
|
|
1073
1118
|
// src/connection.ts
|
|
1074
|
-
var
|
|
1075
|
-
|
|
1076
|
-
|
|
1119
|
+
var import_connectors_sdk7 = require("@superdurable/connectors-sdk");
|
|
1120
|
+
|
|
1121
|
+
// src/generated/connection.ts
|
|
1122
|
+
var import_connectors_sdk6 = require("@superdurable/connectors-sdk");
|
|
1123
|
+
var Connection = class {
|
|
1124
|
+
/** Stable provider and connection name. */
|
|
1077
1125
|
reference;
|
|
1078
|
-
/**
|
|
1126
|
+
/** Bound provider operations. */
|
|
1079
1127
|
operations;
|
|
1128
|
+
/** Validate a reference and bind operations. */
|
|
1129
|
+
constructor(reference, operations) {
|
|
1130
|
+
this.reference = import_connectors_sdk6.ConnectionRefSchema.parse(reference);
|
|
1131
|
+
if (this.reference.provider !== ProviderID2) throw new TypeError("connection provider differs from the manifest");
|
|
1132
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
1133
|
+
this.operations = operations;
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
// src/connection.ts
|
|
1138
|
+
var GmailConnection = class extends Connection {
|
|
1080
1139
|
/** Bind operation implementations to a static named Google connection. */
|
|
1081
1140
|
constructor(operations, reference) {
|
|
1082
1141
|
if (!operations) throw new TypeError("Gmail connector operations are required");
|
|
1083
|
-
|
|
1084
|
-
if (
|
|
1085
|
-
|
|
1142
|
+
const validatedReference = import_connectors_sdk7.ConnectionRefSchema.parse(reference);
|
|
1143
|
+
if (validatedReference.provider !== "google") throw new TypeError("Gmail connection provider must be google");
|
|
1144
|
+
super(validatedReference, operations);
|
|
1086
1145
|
}
|
|
1087
1146
|
};
|
|
1088
1147
|
|
|
1089
1148
|
// src/project.ts
|
|
1090
|
-
var
|
|
1149
|
+
var import_connectors_sdk9 = require("@superdurable/connectors-sdk");
|
|
1091
1150
|
var import_projectconfig = require("@superdurable/connectors-sdk/projectconfig");
|
|
1092
|
-
var
|
|
1151
|
+
var import_zod7 = require("zod");
|
|
1093
1152
|
|
|
1094
1153
|
// src/credential_codec.ts
|
|
1095
|
-
var
|
|
1096
|
-
var
|
|
1097
|
-
var StoredCredentialsSchema =
|
|
1098
|
-
auth_method:
|
|
1099
|
-
oauth_client_id:
|
|
1100
|
-
oauth_client_secret:
|
|
1101
|
-
access_token:
|
|
1102
|
-
refresh_token:
|
|
1103
|
-
primary_email:
|
|
1104
|
-
service_account_key:
|
|
1105
|
-
delegated_user:
|
|
1154
|
+
var import_connectors_sdk8 = require("@superdurable/connectors-sdk");
|
|
1155
|
+
var import_zod6 = require("zod");
|
|
1156
|
+
var StoredCredentialsSchema = import_zod6.z.object({
|
|
1157
|
+
auth_method: import_zod6.z.string().optional(),
|
|
1158
|
+
oauth_client_id: import_zod6.z.string().optional(),
|
|
1159
|
+
oauth_client_secret: import_zod6.z.string().optional(),
|
|
1160
|
+
access_token: import_zod6.z.string().optional(),
|
|
1161
|
+
refresh_token: import_zod6.z.string().optional(),
|
|
1162
|
+
primary_email: import_zod6.z.string().optional(),
|
|
1163
|
+
service_account_key: import_zod6.z.string().optional(),
|
|
1164
|
+
delegated_user: import_zod6.z.string().optional()
|
|
1106
1165
|
});
|
|
1107
1166
|
function decodeGmailCredentials(value) {
|
|
1108
1167
|
return decodeCredentialFields(value, false);
|
|
@@ -1130,11 +1189,11 @@ function decodeCredentialFields(value, isShared) {
|
|
|
1130
1189
|
const credentials = {
|
|
1131
1190
|
authMethodId: stored.auth_method || GoogleOAuthAuthMethodID,
|
|
1132
1191
|
oauthClientId: stored.oauth_client_id ?? "",
|
|
1133
|
-
oauthClientSecret: new
|
|
1134
|
-
accessToken: new
|
|
1135
|
-
refreshToken: new
|
|
1192
|
+
oauthClientSecret: new import_connectors_sdk8.SecretString(stored.oauth_client_secret ?? ""),
|
|
1193
|
+
accessToken: new import_connectors_sdk8.SecretString(stored.access_token ?? ""),
|
|
1194
|
+
refreshToken: new import_connectors_sdk8.SecretString(stored.refresh_token ?? ""),
|
|
1136
1195
|
primaryEmail: stored.primary_email ?? "",
|
|
1137
|
-
serviceAccountKey: new
|
|
1196
|
+
serviceAccountKey: new import_connectors_sdk8.SecretString(stored.service_account_key ?? ""),
|
|
1138
1197
|
delegatedUser: stored.delegated_user ?? ""
|
|
1139
1198
|
};
|
|
1140
1199
|
if (credentials.authMethodId === GoogleOAuthAuthMethodID) {
|
|
@@ -1150,19 +1209,19 @@ function decodeCredentialFields(value, isShared) {
|
|
|
1150
1209
|
}
|
|
1151
1210
|
|
|
1152
1211
|
// src/project.ts
|
|
1153
|
-
var ProjectGmailConfigurationSchema =
|
|
1154
|
-
endpoint:
|
|
1155
|
-
maxResponseBytes:
|
|
1156
|
-
maxMessageBytes:
|
|
1157
|
-
pollInterval:
|
|
1158
|
-
pollPageSize:
|
|
1212
|
+
var ProjectGmailConfigurationSchema = import_zod7.z.object({
|
|
1213
|
+
endpoint: import_zod7.z.string().optional(),
|
|
1214
|
+
maxResponseBytes: import_zod7.z.number().int().safe().optional(),
|
|
1215
|
+
maxMessageBytes: import_zod7.z.number().int().safe().optional(),
|
|
1216
|
+
pollInterval: import_zod7.z.number().int().safe().optional(),
|
|
1217
|
+
pollPageSize: import_zod7.z.number().int().safe().optional()
|
|
1159
1218
|
});
|
|
1160
1219
|
function newProjectConnection(project, connectionName, options = {}) {
|
|
1161
1220
|
return new GmailConnection(newProjectGmailClient(project, connectionName, options), { provider: ProviderID, name: connectionName });
|
|
1162
1221
|
}
|
|
1163
1222
|
function newProjectGmailClient(project, connectionName, options = {}) {
|
|
1164
1223
|
if (!project) throw new TypeError("Gmail connection requires the loaded project configuration");
|
|
1165
|
-
|
|
1224
|
+
import_connectors_sdk9.ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
|
|
1166
1225
|
const entry = project.configuration.connections.find((connection) => connection.connectorId === ConnectorID && connection.connectionName === connectionName);
|
|
1167
1226
|
if (!entry) throw new TypeError("Gmail project connection is not configured");
|
|
1168
1227
|
if (entry.provider !== ProviderID) throw new TypeError("Gmail project connection provider differs from the manifest");
|
|
@@ -1178,43 +1237,57 @@ function newProjectGmailClient(project, connectionName, options = {}) {
|
|
|
1178
1237
|
return new GmailClient(config, provider, options);
|
|
1179
1238
|
}
|
|
1180
1239
|
|
|
1181
|
-
// src/steps.ts
|
|
1182
|
-
var
|
|
1240
|
+
// src/generated/steps.ts
|
|
1241
|
+
var import_connectors_sdk10 = require("@superdurable/connectors-sdk");
|
|
1183
1242
|
function newGetMessageStep(configuration) {
|
|
1184
|
-
const {
|
|
1185
|
-
|
|
1186
|
-
return (0,
|
|
1187
|
-
(0,
|
|
1188
|
-
...notFound ? [(0,
|
|
1189
|
-
...providerRejected ? [(0,
|
|
1190
|
-
...invalidResponse ? [(0,
|
|
1191
|
-
...defect2 ? [(0,
|
|
1243
|
+
const { connection, connectionName, read, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
1244
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1245
|
+
return (0, import_connectors_sdk10.newQueryStep)({ ...stepConfiguration, operation: connection.operations.getMessage(), connection: connection.reference, branches: [
|
|
1246
|
+
(0, import_connectors_sdk10.goToBranch)("read", read),
|
|
1247
|
+
...notFound ? [(0, import_connectors_sdk10.goToBranch)("notFound", notFound)] : [],
|
|
1248
|
+
...providerRejected ? [(0, import_connectors_sdk10.goToBranch)("providerRejected", providerRejected)] : [],
|
|
1249
|
+
...invalidResponse ? [(0, import_connectors_sdk10.goToBranch)("invalidResponse", invalidResponse)] : [],
|
|
1250
|
+
...defect2 ? [(0, import_connectors_sdk10.goToBranch)("defect", defect2)] : []
|
|
1192
1251
|
] });
|
|
1193
1252
|
}
|
|
1194
1253
|
function newSendMessageStep(configuration) {
|
|
1195
|
-
const {
|
|
1196
|
-
|
|
1197
|
-
return (0,
|
|
1198
|
-
(0,
|
|
1199
|
-
...providerRejected ? [(0,
|
|
1200
|
-
...defect2 ? [(0,
|
|
1254
|
+
const { connection, connectionName, sent, providerRejected, defect: defect2, ...stepConfiguration } = configuration;
|
|
1255
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1256
|
+
return (0, import_connectors_sdk10.newMutationStep)({ ...stepConfiguration, operation: connection.operations.sendMessage(), connection: connection.reference, branches: [
|
|
1257
|
+
(0, import_connectors_sdk10.goToBranch)("sent", sent),
|
|
1258
|
+
...providerRejected ? [(0, import_connectors_sdk10.goToBranch)("providerRejected", providerRejected)] : [],
|
|
1259
|
+
...defect2 ? [(0, import_connectors_sdk10.goToBranch)("defect", defect2)] : []
|
|
1201
1260
|
] });
|
|
1202
1261
|
}
|
|
1203
1262
|
function newReplyToMessageStep(configuration) {
|
|
1204
|
-
const {
|
|
1205
|
-
|
|
1206
|
-
return (0,
|
|
1207
|
-
(0,
|
|
1208
|
-
...providerRejected ? [(0,
|
|
1209
|
-
...invalidResponse ? [(0,
|
|
1210
|
-
...defect2 ? [(0,
|
|
1263
|
+
const { connection, connectionName, sent, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
1264
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1265
|
+
return (0, import_connectors_sdk10.newMutationStep)({ ...stepConfiguration, operation: connection.operations.replyToMessage(), connection: connection.reference, branches: [
|
|
1266
|
+
(0, import_connectors_sdk10.goToBranch)("sent", sent),
|
|
1267
|
+
...providerRejected ? [(0, import_connectors_sdk10.goToBranch)("providerRejected", providerRejected)] : [],
|
|
1268
|
+
...invalidResponse ? [(0, import_connectors_sdk10.goToBranch)("invalidResponse", invalidResponse)] : [],
|
|
1269
|
+
...defect2 ? [(0, import_connectors_sdk10.goToBranch)("defect", defect2)] : []
|
|
1211
1270
|
] });
|
|
1212
1271
|
}
|
|
1213
|
-
|
|
1272
|
+
|
|
1273
|
+
// src/steps.ts
|
|
1274
|
+
function requireGmailConnection(connection, connectionName) {
|
|
1214
1275
|
if (!(connection instanceof GmailConnection) || !connectionName || connection.reference.name !== connectionName) {
|
|
1215
1276
|
throw new TypeError("Gmail Step connection name must match its typed connection");
|
|
1216
1277
|
}
|
|
1217
1278
|
}
|
|
1279
|
+
function newGetMessageStep2(configuration) {
|
|
1280
|
+
requireGmailConnection(configuration.connection, configuration.connectionName);
|
|
1281
|
+
return newGetMessageStep(configuration);
|
|
1282
|
+
}
|
|
1283
|
+
function newSendMessageStep2(configuration) {
|
|
1284
|
+
requireGmailConnection(configuration.connection, configuration.connectionName);
|
|
1285
|
+
return newSendMessageStep(configuration);
|
|
1286
|
+
}
|
|
1287
|
+
function newReplyToMessageStep2(configuration) {
|
|
1288
|
+
requireGmailConnection(configuration.connection, configuration.connectionName);
|
|
1289
|
+
return newReplyToMessageStep(configuration);
|
|
1290
|
+
}
|
|
1218
1291
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1219
1292
|
0 && (module.exports = {
|
|
1220
1293
|
ConnectorID,
|