@superdurable/connector-google-gmail 0.1.0 → 0.1.1
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-TWBWDIC7.js} +204 -129
- package/dist/connection-NE_da2Az.d.cts +181 -0
- package/dist/connection-NE_da2Az.d.ts +181 -0
- package/dist/index.cjs +213 -141
- 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 +288 -197
- 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 +4 -3
- 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,89 @@ __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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
to: import_zod.z.array(import_zod.z.string()),
|
|
80
|
-
subject: import_zod.z.string(),
|
|
81
|
-
textBody: import_zod.z.string(),
|
|
82
|
-
htmlBody: import_zod.z.string().optional()
|
|
76
|
+
var ConfigSchema = import_zod.z.object({
|
|
77
|
+
"endpoint": import_zod.z.string().optional(),
|
|
78
|
+
"maxResponseBytes": import_zod.z.number().int().optional(),
|
|
79
|
+
"maxMessageBytes": import_zod.z.number().int().optional(),
|
|
80
|
+
"pollIntervalMs": import_zod.z.number().int().optional(),
|
|
81
|
+
"pollPageSize": import_zod.z.number().int().optional()
|
|
83
82
|
});
|
|
84
|
-
var
|
|
85
|
-
messageId: import_zod.z.string()
|
|
86
|
-
textBody: import_zod.z.string(),
|
|
87
|
-
htmlBody: import_zod.z.string().optional()
|
|
83
|
+
var GetMessageInputSchema = import_zod.z.strictObject({
|
|
84
|
+
"messageId": import_zod.z.string()
|
|
88
85
|
});
|
|
89
86
|
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()
|
|
87
|
+
"messageId": import_zod.z.string(),
|
|
88
|
+
"threadId": import_zod.z.string(),
|
|
89
|
+
"rfcMessageId": import_zod.z.string().optional(),
|
|
90
|
+
"inReplyTo": import_zod.z.string().optional(),
|
|
91
|
+
"references": import_zod.z.string().optional(),
|
|
92
|
+
"from": import_zod.z.string(),
|
|
93
|
+
"replyTo": import_zod.z.string().optional(),
|
|
94
|
+
"to": import_zod.z.array(import_zod.z.string()).optional(),
|
|
95
|
+
"subject": import_zod.z.string(),
|
|
96
|
+
"textBody": import_zod.z.string().optional(),
|
|
97
|
+
"htmlBody": import_zod.z.string().optional(),
|
|
98
|
+
"snippet": import_zod.z.string().optional(),
|
|
99
|
+
"receivedAt": import_zod.z.iso.datetime({ offset: true }),
|
|
100
|
+
"labelIds": import_zod.z.array(import_zod.z.string()).optional()
|
|
101
|
+
});
|
|
102
|
+
var SendMessageInputSchema = import_zod.z.strictObject({
|
|
103
|
+
"to": import_zod.z.array(import_zod.z.string()).nullable(),
|
|
104
|
+
"subject": import_zod.z.string(),
|
|
105
|
+
"textBody": import_zod.z.string(),
|
|
106
|
+
"htmlBody": import_zod.z.string().optional()
|
|
104
107
|
});
|
|
105
108
|
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()
|
|
109
|
+
"sender": import_zod.z.string(),
|
|
110
|
+
"recipients": import_zod.z.array(import_zod.z.string()).nullable(),
|
|
111
|
+
"messageId": import_zod.z.string(),
|
|
112
|
+
"threadId": import_zod.z.string()
|
|
113
|
+
});
|
|
114
|
+
var ReplyToMessageInputSchema = import_zod.z.strictObject({
|
|
115
|
+
"messageId": import_zod.z.string(),
|
|
116
|
+
"textBody": import_zod.z.string(),
|
|
117
|
+
"htmlBody": import_zod.z.string().optional()
|
|
110
118
|
});
|
|
111
119
|
|
|
112
|
-
// src/
|
|
113
|
-
var
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
// src/models.ts
|
|
121
|
+
var SendMessageInputSchema2 = import_zod2.z.strictObject({
|
|
122
|
+
to: import_zod2.z.array(import_zod2.z.string()),
|
|
123
|
+
subject: import_zod2.z.string(),
|
|
124
|
+
textBody: import_zod2.z.string(),
|
|
125
|
+
htmlBody: import_zod2.z.string().optional()
|
|
126
|
+
});
|
|
127
|
+
var SendMessageOutputSchema2 = import_zod2.z.strictObject({
|
|
128
|
+
sender: import_zod2.z.string(),
|
|
129
|
+
recipients: import_zod2.z.array(import_zod2.z.string()),
|
|
130
|
+
messageId: import_zod2.z.string(),
|
|
131
|
+
threadId: import_zod2.z.string()
|
|
132
|
+
});
|
|
133
|
+
var ConnectorID = "gmail";
|
|
134
|
+
var ProviderID = "google";
|
|
135
|
+
var GoogleOAuthAuthMethodID = "google-oauth";
|
|
136
|
+
var WorkspaceDomainDelegationAuthMethodID = "workspace-domain-delegation";
|
|
137
|
+
|
|
138
|
+
// src/generated/definitions.ts
|
|
139
|
+
var ConnectorID2 = "gmail";
|
|
140
|
+
var ProviderID2 = "google";
|
|
141
|
+
var GetMessageBranch = {
|
|
142
|
+
Read: "read",
|
|
143
|
+
NotFound: "notFound",
|
|
144
|
+
ProviderRejected: "providerRejected",
|
|
145
|
+
InvalidResponse: "invalidResponse",
|
|
146
|
+
Defect: "defect"
|
|
147
|
+
};
|
|
148
|
+
var GetMessageBranchRead = GetMessageBranch.Read;
|
|
149
|
+
var GetMessageBranchNotFound = GetMessageBranch.NotFound;
|
|
150
|
+
var GetMessageBranchProviderRejected = GetMessageBranch.ProviderRejected;
|
|
151
|
+
var GetMessageBranchInvalidResponse = GetMessageBranch.InvalidResponse;
|
|
152
|
+
var GetMessageBranchDefect = GetMessageBranch.Defect;
|
|
116
153
|
var GetMessageDefinition = {
|
|
117
|
-
operation: { connectorId:
|
|
154
|
+
operation: { connectorId: ConnectorID2, operationId: "getMessage" },
|
|
118
155
|
branches: [
|
|
119
156
|
{ id: "read", description: "The Gmail message was read." },
|
|
120
157
|
{ id: "notFound", description: "The Gmail message does not exist.", optional: true },
|
|
@@ -124,53 +161,59 @@ var GetMessageDefinition = {
|
|
|
124
161
|
],
|
|
125
162
|
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
126
163
|
};
|
|
164
|
+
var SendMessageBranch = {
|
|
165
|
+
Sent: "sent",
|
|
166
|
+
ProviderRejected: "providerRejected",
|
|
167
|
+
Defect: "defect"
|
|
168
|
+
};
|
|
169
|
+
var SendMessageBranchSent = SendMessageBranch.Sent;
|
|
170
|
+
var SendMessageBranchProviderRejected = SendMessageBranch.ProviderRejected;
|
|
171
|
+
var SendMessageBranchDefect = SendMessageBranch.Defect;
|
|
127
172
|
var SendMessageDefinition = {
|
|
128
|
-
operation: { connectorId:
|
|
173
|
+
operation: { connectorId: ConnectorID2, operationId: "sendMessage" },
|
|
129
174
|
branches: [
|
|
130
175
|
{ 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
176
|
{ id: "providerRejected", description: "Gmail conclusively rejected the message.", optional: true },
|
|
132
177
|
{ id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
|
|
133
178
|
],
|
|
134
|
-
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
179
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } }
|
|
180
|
+
};
|
|
181
|
+
var ReplyToMessageBranch = {
|
|
182
|
+
Sent: "sent",
|
|
183
|
+
ProviderRejected: "providerRejected",
|
|
184
|
+
InvalidResponse: "invalidResponse",
|
|
185
|
+
Defect: "defect"
|
|
141
186
|
};
|
|
187
|
+
var ReplyToMessageBranchSent = ReplyToMessageBranch.Sent;
|
|
188
|
+
var ReplyToMessageBranchProviderRejected = ReplyToMessageBranch.ProviderRejected;
|
|
189
|
+
var ReplyToMessageBranchInvalidResponse = ReplyToMessageBranch.InvalidResponse;
|
|
190
|
+
var ReplyToMessageBranchDefect = ReplyToMessageBranch.Defect;
|
|
142
191
|
var ReplyToMessageDefinition = {
|
|
143
|
-
operation: { connectorId:
|
|
192
|
+
operation: { connectorId: ConnectorID2, operationId: "replyToMessage" },
|
|
144
193
|
branches: [
|
|
145
194
|
{ 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
195
|
{ id: "providerRejected", description: "Gmail conclusively rejected the reply.", optional: true },
|
|
147
196
|
{ id: "invalidResponse", description: "Gmail returned an invalid or oversized source message response before sending the reply.", optional: true },
|
|
148
197
|
{ id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
|
|
149
198
|
],
|
|
150
|
-
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "
|
|
151
|
-
initialIntervalMs: 1e3,
|
|
152
|
-
backoffCoefficient: 2,
|
|
153
|
-
maximumIntervalMs: 3e4,
|
|
154
|
-
maximumAttempts: 5,
|
|
155
|
-
totalDurationMs: 12e4
|
|
156
|
-
} }
|
|
199
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } }
|
|
157
200
|
};
|
|
158
201
|
|
|
159
202
|
// src/message.ts
|
|
160
203
|
var import_node_crypto = require("crypto");
|
|
161
|
-
var
|
|
162
|
-
var GmailMessagePartSchema =
|
|
163
|
-
mimeType:
|
|
164
|
-
headers:
|
|
165
|
-
body:
|
|
166
|
-
parts:
|
|
204
|
+
var import_zod3 = require("zod");
|
|
205
|
+
var GmailMessagePartSchema = import_zod3.z.lazy(() => import_zod3.z.object({
|
|
206
|
+
mimeType: import_zod3.z.string().nullish(),
|
|
207
|
+
headers: import_zod3.z.array(import_zod3.z.object({ name: import_zod3.z.string(), value: import_zod3.z.string() })).nullish(),
|
|
208
|
+
body: import_zod3.z.object({ data: import_zod3.z.string().nullish() }).nullish(),
|
|
209
|
+
parts: import_zod3.z.array(GmailMessagePartSchema).nullish()
|
|
167
210
|
}));
|
|
168
|
-
var GmailMessageResourceSchema =
|
|
169
|
-
id:
|
|
170
|
-
threadId:
|
|
171
|
-
labelIds:
|
|
172
|
-
snippet:
|
|
173
|
-
internalDate:
|
|
211
|
+
var GmailMessageResourceSchema = import_zod3.z.object({
|
|
212
|
+
id: import_zod3.z.string().nullish().transform((value) => value ?? ""),
|
|
213
|
+
threadId: import_zod3.z.string().nullish().transform((value) => value ?? ""),
|
|
214
|
+
labelIds: import_zod3.z.array(import_zod3.z.string()).nullish(),
|
|
215
|
+
snippet: import_zod3.z.string().nullish(),
|
|
216
|
+
internalDate: import_zod3.z.string().nullish(),
|
|
174
217
|
payload: GmailMessagePartSchema.nullish()
|
|
175
218
|
});
|
|
176
219
|
function decodeGmailMessage(resource) {
|
|
@@ -185,18 +228,18 @@ function decodeGmailMessage(resource) {
|
|
|
185
228
|
return {
|
|
186
229
|
messageId: resource.id,
|
|
187
230
|
threadId: resource.threadId,
|
|
188
|
-
rfcMessageId: headers.get("message-id")
|
|
189
|
-
inReplyTo: headers.get("in-reply-to")
|
|
190
|
-
references: headers.get("references")
|
|
231
|
+
...headers.get("message-id") ? { rfcMessageId: headers.get("message-id") } : {},
|
|
232
|
+
...headers.get("in-reply-to") ? { inReplyTo: headers.get("in-reply-to") } : {},
|
|
233
|
+
...headers.get("references") ? { references: headers.get("references") } : {},
|
|
191
234
|
from: headers.get("from") ?? "",
|
|
192
|
-
replyTo: headers.get("reply-to")
|
|
193
|
-
to,
|
|
235
|
+
...headers.get("reply-to") ? { replyTo: headers.get("reply-to") } : {},
|
|
236
|
+
...to.length ? { to } : {},
|
|
194
237
|
subject: decodeRFC2047Header(headers.get("subject") ?? ""),
|
|
195
|
-
textBody: textBodies.join("\n"),
|
|
196
|
-
htmlBody: htmlBodies.join("\n"),
|
|
197
|
-
snippet: resource.snippet
|
|
238
|
+
...textBodies.length ? { textBody: textBodies.join("\n") } : {},
|
|
239
|
+
...htmlBodies.length ? { htmlBody: htmlBodies.join("\n") } : {},
|
|
240
|
+
...resource.snippet ? { snippet: resource.snippet } : {},
|
|
198
241
|
receivedAt: receivedAt.toISOString().replace(".000Z", "Z"),
|
|
199
|
-
labelIds: resource.labelIds
|
|
242
|
+
...resource.labelIds?.length ? { labelIds: resource.labelIds } : {}
|
|
200
243
|
};
|
|
201
244
|
}
|
|
202
245
|
function visitGmailBody(part, textBodies, htmlBodies) {
|
|
@@ -448,9 +491,9 @@ function validateCredentials(credentials) {
|
|
|
448
491
|
}
|
|
449
492
|
|
|
450
493
|
// src/provider.ts
|
|
451
|
-
var
|
|
452
|
-
var SentMessageSchema =
|
|
453
|
-
var SentSearchSchema =
|
|
494
|
+
var import_zod4 = require("zod");
|
|
495
|
+
var SentMessageSchema = import_zod4.z.object({ id: import_zod4.z.string().optional(), threadId: import_zod4.z.string().optional() });
|
|
496
|
+
var SentSearchSchema = import_zod4.z.object({ messages: import_zod4.z.array(SentMessageSchema).nullish() });
|
|
454
497
|
var GmailProvider = class {
|
|
455
498
|
#http;
|
|
456
499
|
/** Bind the shared authenticated transport. */
|
|
@@ -513,11 +556,11 @@ function parseSentResponse(response) {
|
|
|
513
556
|
// src/refresh.ts
|
|
514
557
|
var import_connectors_sdk2 = require("@superdurable/connectors-sdk");
|
|
515
558
|
var import_oauthtoken = require("@superdurable/connectors-sdk/oauthtoken");
|
|
516
|
-
var
|
|
559
|
+
var import_zod5 = require("zod");
|
|
517
560
|
var GoogleOAuthTokenEndpoint = "https://oauth2.googleapis.com/token";
|
|
518
561
|
var RequiredGmailScopes = ["https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/gmail.send"];
|
|
519
562
|
var TerminalErrorCodes = ["invalid_grant", "invalid_client", "unauthorized_client"];
|
|
520
|
-
var ServiceAccountKeySchema =
|
|
563
|
+
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
564
|
var GmailCredentialRefreshDriver = class {
|
|
522
565
|
#fetch;
|
|
523
566
|
#now;
|
|
@@ -554,12 +597,13 @@ var GmailCredentialRefreshDriver = class {
|
|
|
554
597
|
} catch {
|
|
555
598
|
throw new import_connectors_sdk2.ReauthorizationRequiredError();
|
|
556
599
|
}
|
|
557
|
-
|
|
600
|
+
const delegatedUser = credentials.delegatedUser;
|
|
601
|
+
if (new URL(key.token_uri).protocol !== "https:" || !delegatedUser || !parseMailbox(delegatedUser)) throw new import_connectors_sdk2.ReauthorizationRequiredError();
|
|
558
602
|
let assertion;
|
|
559
603
|
try {
|
|
560
604
|
assertion = (0, import_oauthtoken.signJWTBearerAssertion)({
|
|
561
605
|
issuer: key.client_email,
|
|
562
|
-
subject:
|
|
606
|
+
subject: delegatedUser,
|
|
563
607
|
audience: key.token_uri,
|
|
564
608
|
scope: RequiredGmailScopes.join(" "),
|
|
565
609
|
issuedAt: this.#now(),
|
|
@@ -707,7 +751,7 @@ var GmailSender = class {
|
|
|
707
751
|
}
|
|
708
752
|
let recipients;
|
|
709
753
|
try {
|
|
710
|
-
if (!
|
|
754
|
+
if (!SendMessageInputSchema2.safeParse(input).success) throw new TypeError();
|
|
711
755
|
recipients = validateSendInput(input, credentials.primaryEmail);
|
|
712
756
|
} catch (error) {
|
|
713
757
|
return defect("sendMessage", "VALIDATION", error instanceof TypeError && error.message ? error.message : "sender, recipients, subject, and text body are required");
|
|
@@ -1071,38 +1115,52 @@ function classifyReadFailure(status, headers) {
|
|
|
1071
1115
|
}
|
|
1072
1116
|
|
|
1073
1117
|
// src/connection.ts
|
|
1118
|
+
var import_connectors_sdk6 = require("@superdurable/connectors-sdk");
|
|
1119
|
+
|
|
1120
|
+
// src/generated/connection.ts
|
|
1074
1121
|
var import_connectors_sdk5 = require("@superdurable/connectors-sdk");
|
|
1075
|
-
var
|
|
1076
|
-
/** Stable
|
|
1122
|
+
var Connection = class {
|
|
1123
|
+
/** Stable provider and connection name. */
|
|
1077
1124
|
reference;
|
|
1078
|
-
/**
|
|
1125
|
+
/** Bound provider operations. */
|
|
1079
1126
|
operations;
|
|
1127
|
+
/** Validate a reference and bind operations. */
|
|
1128
|
+
constructor(reference, operations) {
|
|
1129
|
+
this.reference = import_connectors_sdk5.ConnectionRefSchema.parse(reference);
|
|
1130
|
+
if (this.reference.provider !== ProviderID2) throw new TypeError("connection provider differs from the manifest");
|
|
1131
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
1132
|
+
this.operations = operations;
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
// src/connection.ts
|
|
1137
|
+
var GmailConnection = class extends Connection {
|
|
1080
1138
|
/** Bind operation implementations to a static named Google connection. */
|
|
1081
1139
|
constructor(operations, reference) {
|
|
1082
1140
|
if (!operations) throw new TypeError("Gmail connector operations are required");
|
|
1083
|
-
|
|
1084
|
-
if (
|
|
1085
|
-
|
|
1141
|
+
const validatedReference = import_connectors_sdk6.ConnectionRefSchema.parse(reference);
|
|
1142
|
+
if (validatedReference.provider !== "google") throw new TypeError("Gmail connection provider must be google");
|
|
1143
|
+
super(validatedReference, operations);
|
|
1086
1144
|
}
|
|
1087
1145
|
};
|
|
1088
1146
|
|
|
1089
1147
|
// src/project.ts
|
|
1090
|
-
var
|
|
1148
|
+
var import_connectors_sdk8 = require("@superdurable/connectors-sdk");
|
|
1091
1149
|
var import_projectconfig = require("@superdurable/connectors-sdk/projectconfig");
|
|
1092
|
-
var
|
|
1150
|
+
var import_zod7 = require("zod");
|
|
1093
1151
|
|
|
1094
1152
|
// 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:
|
|
1153
|
+
var import_connectors_sdk7 = require("@superdurable/connectors-sdk");
|
|
1154
|
+
var import_zod6 = require("zod");
|
|
1155
|
+
var StoredCredentialsSchema = import_zod6.z.object({
|
|
1156
|
+
auth_method: import_zod6.z.string().optional(),
|
|
1157
|
+
oauth_client_id: import_zod6.z.string().optional(),
|
|
1158
|
+
oauth_client_secret: import_zod6.z.string().optional(),
|
|
1159
|
+
access_token: import_zod6.z.string().optional(),
|
|
1160
|
+
refresh_token: import_zod6.z.string().optional(),
|
|
1161
|
+
primary_email: import_zod6.z.string().optional(),
|
|
1162
|
+
service_account_key: import_zod6.z.string().optional(),
|
|
1163
|
+
delegated_user: import_zod6.z.string().optional()
|
|
1106
1164
|
});
|
|
1107
1165
|
function decodeGmailCredentials(value) {
|
|
1108
1166
|
return decodeCredentialFields(value, false);
|
|
@@ -1130,11 +1188,11 @@ function decodeCredentialFields(value, isShared) {
|
|
|
1130
1188
|
const credentials = {
|
|
1131
1189
|
authMethodId: stored.auth_method || GoogleOAuthAuthMethodID,
|
|
1132
1190
|
oauthClientId: stored.oauth_client_id ?? "",
|
|
1133
|
-
oauthClientSecret: new
|
|
1134
|
-
accessToken: new
|
|
1135
|
-
refreshToken: new
|
|
1191
|
+
oauthClientSecret: new import_connectors_sdk7.SecretString(stored.oauth_client_secret ?? ""),
|
|
1192
|
+
accessToken: new import_connectors_sdk7.SecretString(stored.access_token ?? ""),
|
|
1193
|
+
refreshToken: new import_connectors_sdk7.SecretString(stored.refresh_token ?? ""),
|
|
1136
1194
|
primaryEmail: stored.primary_email ?? "",
|
|
1137
|
-
serviceAccountKey: new
|
|
1195
|
+
serviceAccountKey: new import_connectors_sdk7.SecretString(stored.service_account_key ?? ""),
|
|
1138
1196
|
delegatedUser: stored.delegated_user ?? ""
|
|
1139
1197
|
};
|
|
1140
1198
|
if (credentials.authMethodId === GoogleOAuthAuthMethodID) {
|
|
@@ -1150,19 +1208,19 @@ function decodeCredentialFields(value, isShared) {
|
|
|
1150
1208
|
}
|
|
1151
1209
|
|
|
1152
1210
|
// src/project.ts
|
|
1153
|
-
var ProjectGmailConfigurationSchema =
|
|
1154
|
-
endpoint:
|
|
1155
|
-
maxResponseBytes:
|
|
1156
|
-
maxMessageBytes:
|
|
1157
|
-
pollInterval:
|
|
1158
|
-
pollPageSize:
|
|
1211
|
+
var ProjectGmailConfigurationSchema = import_zod7.z.object({
|
|
1212
|
+
endpoint: import_zod7.z.string().optional(),
|
|
1213
|
+
maxResponseBytes: import_zod7.z.number().int().safe().optional(),
|
|
1214
|
+
maxMessageBytes: import_zod7.z.number().int().safe().optional(),
|
|
1215
|
+
pollInterval: import_zod7.z.number().int().safe().optional(),
|
|
1216
|
+
pollPageSize: import_zod7.z.number().int().safe().optional()
|
|
1159
1217
|
});
|
|
1160
1218
|
function newProjectConnection(project, connectionName, options = {}) {
|
|
1161
1219
|
return new GmailConnection(newProjectGmailClient(project, connectionName, options), { provider: ProviderID, name: connectionName });
|
|
1162
1220
|
}
|
|
1163
1221
|
function newProjectGmailClient(project, connectionName, options = {}) {
|
|
1164
1222
|
if (!project) throw new TypeError("Gmail connection requires the loaded project configuration");
|
|
1165
|
-
|
|
1223
|
+
import_connectors_sdk8.ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
|
|
1166
1224
|
const entry = project.configuration.connections.find((connection) => connection.connectorId === ConnectorID && connection.connectionName === connectionName);
|
|
1167
1225
|
if (!entry) throw new TypeError("Gmail project connection is not configured");
|
|
1168
1226
|
if (entry.provider !== ProviderID) throw new TypeError("Gmail project connection provider differs from the manifest");
|
|
@@ -1178,43 +1236,57 @@ function newProjectGmailClient(project, connectionName, options = {}) {
|
|
|
1178
1236
|
return new GmailClient(config, provider, options);
|
|
1179
1237
|
}
|
|
1180
1238
|
|
|
1181
|
-
// src/steps.ts
|
|
1182
|
-
var
|
|
1239
|
+
// src/generated/steps.ts
|
|
1240
|
+
var import_connectors_sdk9 = require("@superdurable/connectors-sdk");
|
|
1183
1241
|
function newGetMessageStep(configuration) {
|
|
1184
|
-
const {
|
|
1185
|
-
|
|
1186
|
-
return (0,
|
|
1187
|
-
(0,
|
|
1188
|
-
...notFound ? [(0,
|
|
1189
|
-
...providerRejected ? [(0,
|
|
1190
|
-
...invalidResponse ? [(0,
|
|
1191
|
-
...defect2 ? [(0,
|
|
1242
|
+
const { connection, connectionName, read, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
1243
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1244
|
+
return (0, import_connectors_sdk9.newQueryStep)({ ...stepConfiguration, operation: connection.operations.getMessage(), connection: connection.reference, branches: [
|
|
1245
|
+
(0, import_connectors_sdk9.goToBranch)("read", read),
|
|
1246
|
+
...notFound ? [(0, import_connectors_sdk9.goToBranch)("notFound", notFound)] : [],
|
|
1247
|
+
...providerRejected ? [(0, import_connectors_sdk9.goToBranch)("providerRejected", providerRejected)] : [],
|
|
1248
|
+
...invalidResponse ? [(0, import_connectors_sdk9.goToBranch)("invalidResponse", invalidResponse)] : [],
|
|
1249
|
+
...defect2 ? [(0, import_connectors_sdk9.goToBranch)("defect", defect2)] : []
|
|
1192
1250
|
] });
|
|
1193
1251
|
}
|
|
1194
1252
|
function newSendMessageStep(configuration) {
|
|
1195
|
-
const {
|
|
1196
|
-
|
|
1197
|
-
return (0,
|
|
1198
|
-
(0,
|
|
1199
|
-
...providerRejected ? [(0,
|
|
1200
|
-
...defect2 ? [(0,
|
|
1253
|
+
const { connection, connectionName, sent, providerRejected, defect: defect2, ...stepConfiguration } = configuration;
|
|
1254
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1255
|
+
return (0, import_connectors_sdk9.newMutationStep)({ ...stepConfiguration, operation: connection.operations.sendMessage(), connection: connection.reference, branches: [
|
|
1256
|
+
(0, import_connectors_sdk9.goToBranch)("sent", sent),
|
|
1257
|
+
...providerRejected ? [(0, import_connectors_sdk9.goToBranch)("providerRejected", providerRejected)] : [],
|
|
1258
|
+
...defect2 ? [(0, import_connectors_sdk9.goToBranch)("defect", defect2)] : []
|
|
1201
1259
|
] });
|
|
1202
1260
|
}
|
|
1203
1261
|
function newReplyToMessageStep(configuration) {
|
|
1204
|
-
const {
|
|
1205
|
-
|
|
1206
|
-
return (0,
|
|
1207
|
-
(0,
|
|
1208
|
-
...providerRejected ? [(0,
|
|
1209
|
-
...invalidResponse ? [(0,
|
|
1210
|
-
...defect2 ? [(0,
|
|
1262
|
+
const { connection, connectionName, sent, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
1263
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1264
|
+
return (0, import_connectors_sdk9.newMutationStep)({ ...stepConfiguration, operation: connection.operations.replyToMessage(), connection: connection.reference, branches: [
|
|
1265
|
+
(0, import_connectors_sdk9.goToBranch)("sent", sent),
|
|
1266
|
+
...providerRejected ? [(0, import_connectors_sdk9.goToBranch)("providerRejected", providerRejected)] : [],
|
|
1267
|
+
...invalidResponse ? [(0, import_connectors_sdk9.goToBranch)("invalidResponse", invalidResponse)] : [],
|
|
1268
|
+
...defect2 ? [(0, import_connectors_sdk9.goToBranch)("defect", defect2)] : []
|
|
1211
1269
|
] });
|
|
1212
1270
|
}
|
|
1213
|
-
|
|
1271
|
+
|
|
1272
|
+
// src/steps.ts
|
|
1273
|
+
function requireGmailConnection(connection, connectionName) {
|
|
1214
1274
|
if (!(connection instanceof GmailConnection) || !connectionName || connection.reference.name !== connectionName) {
|
|
1215
1275
|
throw new TypeError("Gmail Step connection name must match its typed connection");
|
|
1216
1276
|
}
|
|
1217
1277
|
}
|
|
1278
|
+
function newGetMessageStep2(configuration) {
|
|
1279
|
+
requireGmailConnection(configuration.connection, configuration.connectionName);
|
|
1280
|
+
return newGetMessageStep(configuration);
|
|
1281
|
+
}
|
|
1282
|
+
function newSendMessageStep2(configuration) {
|
|
1283
|
+
requireGmailConnection(configuration.connection, configuration.connectionName);
|
|
1284
|
+
return newSendMessageStep(configuration);
|
|
1285
|
+
}
|
|
1286
|
+
function newReplyToMessageStep2(configuration) {
|
|
1287
|
+
requireGmailConnection(configuration.connection, configuration.connectionName);
|
|
1288
|
+
return newReplyToMessageStep(configuration);
|
|
1289
|
+
}
|
|
1218
1290
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1219
1291
|
0 && (module.exports = {
|
|
1220
1292
|
ConnectorID,
|