@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 CHANGED
@@ -8,7 +8,11 @@ npm install @superdurable/connector-google-gmail @superdurable/dex
8
8
 
9
9
  This package provides typed `getMessage`, `sendMessage`, and `replyToMessage` operations. Its operation identities, branches, retry policy, authorization fields, and mock cases mirror [the manifest](https://github.com/superdurable/dex-connectors-library/blob/main/connectors/google/gmail/connector.yaml). Gmail Triggers and the thread-reply Trigger runner currently belong to the Go connector.
10
10
 
11
+ The checked-in `src/generated/` contracts come from `connector.yaml` and the
12
+ Go operation structs. Run `go run ./cmd/connectorctl generate --lang typescript connectors/google/gmail/connector.yaml` from the repository root after either source changes. `src/models.ts` keeps credential requirements specific to Google OAuth and Workspace delegation, plus the public non-null send recipient arrays. `src/steps.ts` delegates to generated factories while requiring `GmailConnection` at compile time; `src/mock/index.ts` re-exports matching generated scenarios and validates send scenarios against the public result type. `src/project.ts` keeps the refresh codec and public connection constructor.
13
+
11
14
  Send and reply recipients are validated as mailboxes and returned in canonical header form, such as `<ada@example.com>` or `"Ada" <ada@example.com>`.
15
+ Decoded messages omit absent optional metadata and body fields, matching the Go connector's JSON output.
12
16
 
13
17
  ## Configure a connection
14
18
 
@@ -18,7 +22,7 @@ For personal Gmail or ordinary Workspace accounts, select **Google OAuth**. In [
18
22
 
19
23
  For administrator-managed Workspace delegation, use [Google Cloud service accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) to create a service account and download its JSON key. In [Workspace domain-wide delegation](https://admin.google.com/ac/owl/domainwidedelegation), authorize that account's OAuth client ID for the Gmail readonly and send scopes. Put the JSON key and one managed mailbox in the connection form. The connector mints short-lived delegated tokens and uses that mailbox as the sender.
20
24
 
21
- `sendMessage` and `replyToMessage` claim a Dex heartbeat checkpoint before POST and search Sent Mail under a run-specific RFC `Message-ID` after an ambiguous send. A confirmed match returns `sent`; a miss retries read-back within the manifest budget without another POST. A conclusive 429 or 503 can permit another attempt after its own read-back; delayed Sent Mail indexing after a 503 can still cause duplicate delivery. An accepted 2xx never resends merely because its response body is unusable.
25
+ `sendMessage` and `replyToMessage` use synchronous Execute and claim a Dex heartbeat checkpoint before POST. They search Sent Mail under a run-specific RFC `Message-ID` after an ambiguous send. A confirmed match returns `sent`; a miss retries read-back within the manifest budget without another POST. A conclusive 429 or 503 can permit another attempt after its own read-back; delayed Sent Mail indexing after a 503 can still cause duplicate delivery. An accepted 2xx never resends merely because its response body is unusable.
22
26
 
23
27
  ## Run the example
24
28
 
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "connectorId": "gmail",
3
- "releaseTag": "connectors/google/gmail/v0.24.1",
3
+ "releaseTag": "connectors/google/gmail/go/v0.25.2",
4
4
  "package": {
5
5
  "ecosystem": "npm",
6
6
  "name": "@superdurable/connector-google-gmail",
7
- "version": "0.1.0"
7
+ "version": "0.1.2"
8
8
  },
9
9
  "factories": [
10
10
  {
@@ -1,50 +1,88 @@
1
1
  // src/models.ts
2
+ import { z as z2 } from "zod";
3
+
4
+ // src/generated/models.ts
2
5
  import { z } from "zod";
3
- var ConnectorID = "gmail";
4
- var ProviderID = "google";
5
- var GoogleOAuthAuthMethodID = "google-oauth";
6
- var WorkspaceDomainDelegationAuthMethodID = "workspace-domain-delegation";
7
- var GetMessageInputSchema = z.strictObject({ messageId: z.string() });
8
- var SendMessageInputSchema = z.strictObject({
9
- to: z.array(z.string()),
10
- subject: z.string(),
11
- textBody: z.string(),
12
- htmlBody: z.string().optional()
6
+ import { SecretString } from "@superdurable/connectors-sdk";
7
+ var ConfigSchema = z.object({
8
+ "endpoint": z.string().optional(),
9
+ "maxResponseBytes": z.number().int().optional(),
10
+ "maxMessageBytes": z.number().int().optional(),
11
+ "pollIntervalMs": z.number().int().optional(),
12
+ "pollPageSize": z.number().int().optional()
13
13
  });
14
- var ReplyToMessageInputSchema = z.strictObject({
15
- messageId: z.string(),
16
- textBody: z.string(),
17
- htmlBody: z.string().optional()
14
+ var GetMessageInputSchema = z.strictObject({
15
+ "messageId": z.string()
18
16
  });
19
17
  var MessageSchema = z.strictObject({
20
- messageId: z.string(),
21
- threadId: z.string(),
22
- rfcMessageId: z.string().optional(),
23
- inReplyTo: z.string().optional(),
24
- references: z.string().optional(),
25
- from: z.string(),
26
- replyTo: z.string().optional(),
27
- to: z.array(z.string()).optional(),
28
- subject: z.string(),
29
- textBody: z.string().optional(),
30
- htmlBody: z.string().optional(),
31
- snippet: z.string().optional(),
32
- receivedAt: z.iso.datetime({ offset: true }),
33
- labelIds: z.array(z.string()).optional()
18
+ "messageId": z.string(),
19
+ "threadId": z.string(),
20
+ "rfcMessageId": z.string().optional(),
21
+ "inReplyTo": z.string().optional(),
22
+ "references": z.string().optional(),
23
+ "from": z.string(),
24
+ "replyTo": z.string().optional(),
25
+ "to": z.array(z.string()).optional(),
26
+ "subject": z.string(),
27
+ "textBody": z.string().optional(),
28
+ "htmlBody": z.string().optional(),
29
+ "snippet": z.string().optional(),
30
+ "receivedAt": z.iso.datetime({ offset: true }),
31
+ "labelIds": z.array(z.string()).optional()
32
+ });
33
+ var SendMessageInputSchema = z.strictObject({
34
+ "to": z.array(z.string()).nullable(),
35
+ "subject": z.string(),
36
+ "textBody": z.string(),
37
+ "htmlBody": z.string().optional()
34
38
  });
35
39
  var SendMessageOutputSchema = z.strictObject({
36
- sender: z.string(),
37
- recipients: z.array(z.string()),
38
- messageId: z.string(),
39
- threadId: z.string()
40
+ "sender": z.string(),
41
+ "recipients": z.array(z.string()).nullable(),
42
+ "messageId": z.string(),
43
+ "threadId": z.string()
44
+ });
45
+ var ReplyToMessageInputSchema = z.strictObject({
46
+ "messageId": z.string(),
47
+ "textBody": z.string(),
48
+ "htmlBody": z.string().optional()
40
49
  });
41
50
 
42
- // src/definitions.ts
43
- var GetMessageBranch = { Read: "read", NotFound: "notFound", ProviderRejected: "providerRejected", InvalidResponse: "invalidResponse", Defect: "defect" };
44
- var SendMessageBranch = { Sent: "sent", ProviderRejected: "providerRejected", Defect: "defect" };
45
- var ReplyToMessageBranch = { Sent: "sent", ProviderRejected: "providerRejected", InvalidResponse: "invalidResponse", Defect: "defect" };
51
+ // src/models.ts
52
+ var SendMessageInputSchema2 = z2.strictObject({
53
+ to: z2.array(z2.string()),
54
+ subject: z2.string(),
55
+ textBody: z2.string(),
56
+ htmlBody: z2.string().optional()
57
+ });
58
+ var SendMessageOutputSchema2 = z2.strictObject({
59
+ sender: z2.string(),
60
+ recipients: z2.array(z2.string()),
61
+ messageId: z2.string(),
62
+ threadId: z2.string()
63
+ });
64
+ var ConnectorID = "gmail";
65
+ var ProviderID = "google";
66
+ var GoogleOAuthAuthMethodID = "google-oauth";
67
+ var WorkspaceDomainDelegationAuthMethodID = "workspace-domain-delegation";
68
+
69
+ // src/generated/definitions.ts
70
+ var ConnectorID2 = "gmail";
71
+ var ProviderID2 = "google";
72
+ var GetMessageBranch = {
73
+ Read: "read",
74
+ NotFound: "notFound",
75
+ ProviderRejected: "providerRejected",
76
+ InvalidResponse: "invalidResponse",
77
+ Defect: "defect"
78
+ };
79
+ var GetMessageBranchRead = GetMessageBranch.Read;
80
+ var GetMessageBranchNotFound = GetMessageBranch.NotFound;
81
+ var GetMessageBranchProviderRejected = GetMessageBranch.ProviderRejected;
82
+ var GetMessageBranchInvalidResponse = GetMessageBranch.InvalidResponse;
83
+ var GetMessageBranchDefect = GetMessageBranch.Defect;
46
84
  var GetMessageDefinition = {
47
- operation: { connectorId: ConnectorID, operationId: "getMessage" },
85
+ operation: { connectorId: ConnectorID2, operationId: "getMessage" },
48
86
  branches: [
49
87
  { id: "read", description: "The Gmail message was read." },
50
88
  { id: "notFound", description: "The Gmail message does not exist.", optional: true },
@@ -54,53 +92,59 @@ var GetMessageDefinition = {
54
92
  ],
55
93
  stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
56
94
  };
95
+ var SendMessageBranch = {
96
+ Sent: "sent",
97
+ ProviderRejected: "providerRejected",
98
+ Defect: "defect"
99
+ };
100
+ var SendMessageBranchSent = SendMessageBranch.Sent;
101
+ var SendMessageBranchProviderRejected = SendMessageBranch.ProviderRejected;
102
+ var SendMessageBranchDefect = SendMessageBranch.Defect;
57
103
  var SendMessageDefinition = {
58
- operation: { connectorId: ConnectorID, operationId: "sendMessage" },
104
+ operation: { connectorId: ConnectorID2, operationId: "sendMessage" },
59
105
  branches: [
60
106
  { 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." },
61
107
  { id: "providerRejected", description: "Gmail conclusively rejected the message.", optional: true },
62
108
  { id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
63
109
  ],
64
- stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async", executeRetry: {
65
- initialIntervalMs: 1e3,
66
- backoffCoefficient: 2,
67
- maximumIntervalMs: 3e4,
68
- maximumAttempts: 5,
69
- totalDurationMs: 12e4
70
- } }
110
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } }
71
111
  };
112
+ var ReplyToMessageBranch = {
113
+ Sent: "sent",
114
+ ProviderRejected: "providerRejected",
115
+ InvalidResponse: "invalidResponse",
116
+ Defect: "defect"
117
+ };
118
+ var ReplyToMessageBranchSent = ReplyToMessageBranch.Sent;
119
+ var ReplyToMessageBranchProviderRejected = ReplyToMessageBranch.ProviderRejected;
120
+ var ReplyToMessageBranchInvalidResponse = ReplyToMessageBranch.InvalidResponse;
121
+ var ReplyToMessageBranchDefect = ReplyToMessageBranch.Defect;
72
122
  var ReplyToMessageDefinition = {
73
- operation: { connectorId: ConnectorID, operationId: "replyToMessage" },
123
+ operation: { connectorId: ConnectorID2, operationId: "replyToMessage" },
74
124
  branches: [
75
125
  { 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." },
76
126
  { id: "providerRejected", description: "Gmail conclusively rejected the reply.", optional: true },
77
127
  { id: "invalidResponse", description: "Gmail returned an invalid or oversized source message response before sending the reply.", optional: true },
78
128
  { id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
79
129
  ],
80
- stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async", executeRetry: {
81
- initialIntervalMs: 1e3,
82
- backoffCoefficient: 2,
83
- maximumIntervalMs: 3e4,
84
- maximumAttempts: 5,
85
- totalDurationMs: 12e4
86
- } }
130
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } }
87
131
  };
88
132
 
89
133
  // src/message.ts
90
134
  import { createHash } from "crypto";
91
- import { z as z2 } from "zod";
92
- var GmailMessagePartSchema = z2.lazy(() => z2.object({
93
- mimeType: z2.string().nullish(),
94
- headers: z2.array(z2.object({ name: z2.string(), value: z2.string() })).nullish(),
95
- body: z2.object({ data: z2.string().nullish() }).nullish(),
96
- parts: z2.array(GmailMessagePartSchema).nullish()
135
+ import { z as z3 } from "zod";
136
+ var GmailMessagePartSchema = z3.lazy(() => z3.object({
137
+ mimeType: z3.string().nullish(),
138
+ headers: z3.array(z3.object({ name: z3.string(), value: z3.string() })).nullish(),
139
+ body: z3.object({ data: z3.string().nullish() }).nullish(),
140
+ parts: z3.array(GmailMessagePartSchema).nullish()
97
141
  }));
98
- var GmailMessageResourceSchema = z2.object({
99
- id: z2.string().nullish().transform((value) => value ?? ""),
100
- threadId: z2.string().nullish().transform((value) => value ?? ""),
101
- labelIds: z2.array(z2.string()).nullish(),
102
- snippet: z2.string().nullish(),
103
- internalDate: z2.string().nullish(),
142
+ var GmailMessageResourceSchema = z3.object({
143
+ id: z3.string().nullish().transform((value) => value ?? ""),
144
+ threadId: z3.string().nullish().transform((value) => value ?? ""),
145
+ labelIds: z3.array(z3.string()).nullish(),
146
+ snippet: z3.string().nullish(),
147
+ internalDate: z3.string().nullish(),
104
148
  payload: GmailMessagePartSchema.nullish()
105
149
  });
106
150
  function decodeGmailMessage(resource) {
@@ -115,18 +159,18 @@ function decodeGmailMessage(resource) {
115
159
  return {
116
160
  messageId: resource.id,
117
161
  threadId: resource.threadId,
118
- rfcMessageId: headers.get("message-id") ?? "",
119
- inReplyTo: headers.get("in-reply-to") ?? "",
120
- references: headers.get("references") ?? "",
162
+ ...headers.get("message-id") ? { rfcMessageId: headers.get("message-id") } : {},
163
+ ...headers.get("in-reply-to") ? { inReplyTo: headers.get("in-reply-to") } : {},
164
+ ...headers.get("references") ? { references: headers.get("references") } : {},
121
165
  from: headers.get("from") ?? "",
122
- replyTo: headers.get("reply-to") ?? "",
123
- to,
166
+ ...headers.get("reply-to") ? { replyTo: headers.get("reply-to") } : {},
167
+ ...to.length ? { to } : {},
124
168
  subject: decodeRFC2047Header(headers.get("subject") ?? ""),
125
- textBody: textBodies.join("\n"),
126
- htmlBody: htmlBodies.join("\n"),
127
- snippet: resource.snippet ?? "",
169
+ ...textBodies.length ? { textBody: textBodies.join("\n") } : {},
170
+ ...htmlBodies.length ? { htmlBody: htmlBodies.join("\n") } : {},
171
+ ...resource.snippet ? { snippet: resource.snippet } : {},
128
172
  receivedAt: receivedAt.toISOString().replace(".000Z", "Z"),
129
- labelIds: resource.labelIds ?? []
173
+ ...resource.labelIds?.length ? { labelIds: resource.labelIds } : {}
130
174
  };
131
175
  }
132
176
  function visitGmailBody(part, textBodies, htmlBodies) {
@@ -383,9 +427,9 @@ function validateCredentials(credentials) {
383
427
  }
384
428
 
385
429
  // src/provider.ts
386
- import { z as z3 } from "zod";
387
- var SentMessageSchema = z3.object({ id: z3.string().optional(), threadId: z3.string().optional() });
388
- var SentSearchSchema = z3.object({ messages: z3.array(SentMessageSchema).nullish() });
430
+ import { z as z4 } from "zod";
431
+ var SentMessageSchema = z4.object({ id: z4.string().optional(), threadId: z4.string().optional() });
432
+ var SentSearchSchema = z4.object({ messages: z4.array(SentMessageSchema).nullish() });
389
433
  var GmailProvider = class {
390
434
  #http;
391
435
  /** Bind the shared authenticated transport. */
@@ -454,11 +498,11 @@ import {
454
498
  signJWTBearerAssertion,
455
499
  TokenEndpoint
456
500
  } from "@superdurable/connectors-sdk/oauthtoken";
457
- import { z as z4 } from "zod";
501
+ import { z as z5 } from "zod";
458
502
  var GoogleOAuthTokenEndpoint = "https://oauth2.googleapis.com/token";
459
503
  var RequiredGmailScopes = ["https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/gmail.send"];
460
504
  var TerminalErrorCodes = ["invalid_grant", "invalid_client", "unauthorized_client"];
461
- var ServiceAccountKeySchema = z4.object({ client_email: z4.string().min(1), private_key: z4.string().min(1), token_uri: z4.url() });
505
+ var ServiceAccountKeySchema = z5.object({ client_email: z5.string().min(1), private_key: z5.string().min(1), token_uri: z5.url() });
462
506
  var GmailCredentialRefreshDriver = class {
463
507
  #fetch;
464
508
  #now;
@@ -495,12 +539,13 @@ var GmailCredentialRefreshDriver = class {
495
539
  } catch {
496
540
  throw new ReauthorizationRequiredError();
497
541
  }
498
- if (new URL(key.token_uri).protocol !== "https:" || !parseMailbox(credentials.delegatedUser ?? "")) throw new ReauthorizationRequiredError();
542
+ const delegatedUser = credentials.delegatedUser;
543
+ if (new URL(key.token_uri).protocol !== "https:" || !delegatedUser || !parseMailbox(delegatedUser)) throw new ReauthorizationRequiredError();
499
544
  let assertion;
500
545
  try {
501
546
  assertion = signJWTBearerAssertion({
502
547
  issuer: key.client_email,
503
- subject: credentials.delegatedUser,
548
+ subject: delegatedUser,
504
549
  audience: key.token_uri,
505
550
  scope: RequiredGmailScopes.join(" "),
506
551
  issuedAt: this.#now(),
@@ -652,7 +697,7 @@ var GmailSender = class {
652
697
  }
653
698
  let recipients;
654
699
  try {
655
- if (!SendMessageInputSchema.safeParse(input).success) throw new TypeError();
700
+ if (!SendMessageInputSchema2.safeParse(input).success) throw new TypeError();
656
701
  recipients = validateSendInput(input, credentials.primaryEmail);
657
702
  } catch (error) {
658
703
  return defect("sendMessage", "VALIDATION", error instanceof TypeError && error.message ? error.message : "sender, recipients, subject, and text body are required");
@@ -1020,38 +1065,52 @@ function classifyReadFailure(status, headers) {
1020
1065
  }
1021
1066
 
1022
1067
  // src/connection.ts
1068
+ import { ConnectionRefSchema as ConnectionRefSchema2 } from "@superdurable/connectors-sdk";
1069
+
1070
+ // src/generated/connection.ts
1023
1071
  import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
1024
- var GmailConnection = class {
1025
- /** Stable logical credential reference. */
1072
+ var Connection = class {
1073
+ /** Stable provider and connection name. */
1026
1074
  reference;
1027
- /** Provider or mock operation implementations. */
1075
+ /** Bound provider operations. */
1028
1076
  operations;
1077
+ /** Validate a reference and bind operations. */
1078
+ constructor(reference, operations) {
1079
+ this.reference = ConnectionRefSchema.parse(reference);
1080
+ if (this.reference.provider !== ProviderID2) throw new TypeError("connection provider differs from the manifest");
1081
+ if (!operations) throw new TypeError("connector operations are required");
1082
+ this.operations = operations;
1083
+ }
1084
+ };
1085
+
1086
+ // src/connection.ts
1087
+ var GmailConnection = class extends Connection {
1029
1088
  /** Bind operation implementations to a static named Google connection. */
1030
1089
  constructor(operations, reference) {
1031
1090
  if (!operations) throw new TypeError("Gmail connector operations are required");
1032
- this.reference = ConnectionRefSchema.parse(reference);
1033
- if (this.reference.provider !== "google") throw new TypeError("Gmail connection provider must be google");
1034
- this.operations = operations;
1091
+ const validatedReference = ConnectionRefSchema2.parse(reference);
1092
+ if (validatedReference.provider !== "google") throw new TypeError("Gmail connection provider must be google");
1093
+ super(validatedReference, operations);
1035
1094
  }
1036
1095
  };
1037
1096
 
1038
1097
  // src/project.ts
1039
- import { ConnectionRefSchema as ConnectionRefSchema2 } from "@superdurable/connectors-sdk";
1098
+ import { ConnectionRefSchema as ConnectionRefSchema3 } from "@superdurable/connectors-sdk";
1040
1099
  import { newRefreshingCredentialProvider } from "@superdurable/connectors-sdk/projectconfig";
1041
- import { z as z6 } from "zod";
1100
+ import { z as z7 } from "zod";
1042
1101
 
1043
1102
  // src/credential_codec.ts
1044
- import { SecretString } from "@superdurable/connectors-sdk";
1045
- import { z as z5 } from "zod";
1046
- var StoredCredentialsSchema = z5.object({
1047
- auth_method: z5.string().optional(),
1048
- oauth_client_id: z5.string().optional(),
1049
- oauth_client_secret: z5.string().optional(),
1050
- access_token: z5.string().optional(),
1051
- refresh_token: z5.string().optional(),
1052
- primary_email: z5.string().optional(),
1053
- service_account_key: z5.string().optional(),
1054
- delegated_user: z5.string().optional()
1103
+ import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
1104
+ import { z as z6 } from "zod";
1105
+ var StoredCredentialsSchema = z6.object({
1106
+ auth_method: z6.string().optional(),
1107
+ oauth_client_id: z6.string().optional(),
1108
+ oauth_client_secret: z6.string().optional(),
1109
+ access_token: z6.string().optional(),
1110
+ refresh_token: z6.string().optional(),
1111
+ primary_email: z6.string().optional(),
1112
+ service_account_key: z6.string().optional(),
1113
+ delegated_user: z6.string().optional()
1055
1114
  });
1056
1115
  function decodeGmailCredentials(value) {
1057
1116
  return decodeCredentialFields(value, false);
@@ -1079,11 +1138,11 @@ function decodeCredentialFields(value, isShared) {
1079
1138
  const credentials = {
1080
1139
  authMethodId: stored.auth_method || GoogleOAuthAuthMethodID,
1081
1140
  oauthClientId: stored.oauth_client_id ?? "",
1082
- oauthClientSecret: new SecretString(stored.oauth_client_secret ?? ""),
1083
- accessToken: new SecretString(stored.access_token ?? ""),
1084
- refreshToken: new SecretString(stored.refresh_token ?? ""),
1141
+ oauthClientSecret: new SecretString2(stored.oauth_client_secret ?? ""),
1142
+ accessToken: new SecretString2(stored.access_token ?? ""),
1143
+ refreshToken: new SecretString2(stored.refresh_token ?? ""),
1085
1144
  primaryEmail: stored.primary_email ?? "",
1086
- serviceAccountKey: new SecretString(stored.service_account_key ?? ""),
1145
+ serviceAccountKey: new SecretString2(stored.service_account_key ?? ""),
1087
1146
  delegatedUser: stored.delegated_user ?? ""
1088
1147
  };
1089
1148
  if (credentials.authMethodId === GoogleOAuthAuthMethodID) {
@@ -1099,19 +1158,19 @@ function decodeCredentialFields(value, isShared) {
1099
1158
  }
1100
1159
 
1101
1160
  // src/project.ts
1102
- var ProjectGmailConfigurationSchema = z6.object({
1103
- endpoint: z6.string().optional(),
1104
- maxResponseBytes: z6.number().int().safe().optional(),
1105
- maxMessageBytes: z6.number().int().safe().optional(),
1106
- pollInterval: z6.number().int().safe().optional(),
1107
- pollPageSize: z6.number().int().safe().optional()
1161
+ var ProjectGmailConfigurationSchema = z7.object({
1162
+ endpoint: z7.string().optional(),
1163
+ maxResponseBytes: z7.number().int().safe().optional(),
1164
+ maxMessageBytes: z7.number().int().safe().optional(),
1165
+ pollInterval: z7.number().int().safe().optional(),
1166
+ pollPageSize: z7.number().int().safe().optional()
1108
1167
  });
1109
1168
  function newProjectConnection(project, connectionName, options = {}) {
1110
1169
  return new GmailConnection(newProjectGmailClient(project, connectionName, options), { provider: ProviderID, name: connectionName });
1111
1170
  }
1112
1171
  function newProjectGmailClient(project, connectionName, options = {}) {
1113
1172
  if (!project) throw new TypeError("Gmail connection requires the loaded project configuration");
1114
- ConnectionRefSchema2.parse({ provider: ProviderID, name: connectionName });
1173
+ ConnectionRefSchema3.parse({ provider: ProviderID, name: connectionName });
1115
1174
  const entry = project.configuration.connections.find((connection) => connection.connectorId === ConnectorID && connection.connectionName === connectionName);
1116
1175
  if (!entry) throw new TypeError("Gmail project connection is not configured");
1117
1176
  if (entry.provider !== ProviderID) throw new TypeError("Gmail project connection provider differs from the manifest");
@@ -1127,12 +1186,12 @@ function newProjectGmailClient(project, connectionName, options = {}) {
1127
1186
  return new GmailClient(config, provider, options);
1128
1187
  }
1129
1188
 
1130
- // src/steps.ts
1131
- import { newMutationStep, newQueryStep, goToBranch } from "@superdurable/connectors-sdk";
1189
+ // src/generated/steps.ts
1190
+ import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
1132
1191
  function newGetMessageStep(configuration) {
1133
- const { connectionName, connection, read, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
1134
- validateNamedConnection(connectionName, connection);
1135
- return newQueryStep({ ...stepConfiguration, connection: connection.reference, operation: connection.operations.getMessage(), branches: [
1192
+ const { connection, connectionName, read, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
1193
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
1194
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.getMessage(), connection: connection.reference, branches: [
1136
1195
  goToBranch("read", read),
1137
1196
  ...notFound ? [goToBranch("notFound", notFound)] : [],
1138
1197
  ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
@@ -1141,45 +1200,62 @@ function newGetMessageStep(configuration) {
1141
1200
  ] });
1142
1201
  }
1143
1202
  function newSendMessageStep(configuration) {
1144
- const { connectionName, connection, sent, providerRejected, defect: defect2, ...stepConfiguration } = configuration;
1145
- validateNamedConnection(connectionName, connection);
1146
- return newMutationStep({ ...stepConfiguration, connection: connection.reference, operation: connection.operations.sendMessage(), branches: [
1203
+ const { connection, connectionName, sent, providerRejected, defect: defect2, ...stepConfiguration } = configuration;
1204
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
1205
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.sendMessage(), connection: connection.reference, branches: [
1147
1206
  goToBranch("sent", sent),
1148
1207
  ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
1149
1208
  ...defect2 ? [goToBranch("defect", defect2)] : []
1150
1209
  ] });
1151
1210
  }
1152
1211
  function newReplyToMessageStep(configuration) {
1153
- const { connectionName, connection, sent, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
1154
- validateNamedConnection(connectionName, connection);
1155
- return newMutationStep({ ...stepConfiguration, connection: connection.reference, operation: connection.operations.replyToMessage(), branches: [
1212
+ const { connection, connectionName, sent, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
1213
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
1214
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.replyToMessage(), connection: connection.reference, branches: [
1156
1215
  goToBranch("sent", sent),
1157
1216
  ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
1158
1217
  ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
1159
1218
  ...defect2 ? [goToBranch("defect", defect2)] : []
1160
1219
  ] });
1161
1220
  }
1162
- function validateNamedConnection(connectionName, connection) {
1221
+
1222
+ // src/steps.ts
1223
+ function requireGmailConnection(connection, connectionName) {
1163
1224
  if (!(connection instanceof GmailConnection) || !connectionName || connection.reference.name !== connectionName) {
1164
1225
  throw new TypeError("Gmail Step connection name must match its typed connection");
1165
1226
  }
1166
1227
  }
1228
+ function newGetMessageStep2(configuration) {
1229
+ requireGmailConnection(configuration.connection, configuration.connectionName);
1230
+ return newGetMessageStep(configuration);
1231
+ }
1232
+ function newSendMessageStep2(configuration) {
1233
+ requireGmailConnection(configuration.connection, configuration.connectionName);
1234
+ return newSendMessageStep(configuration);
1235
+ }
1236
+ function newReplyToMessageStep2(configuration) {
1237
+ requireGmailConnection(configuration.connection, configuration.connectionName);
1238
+ return newReplyToMessageStep(configuration);
1239
+ }
1167
1240
 
1168
1241
  export {
1242
+ GetMessageInputSchema,
1243
+ MessageSchema,
1244
+ SendMessageInputSchema,
1245
+ SendMessageOutputSchema,
1246
+ ReplyToMessageInputSchema,
1247
+ SendMessageInputSchema2,
1248
+ SendMessageOutputSchema2,
1169
1249
  ConnectorID,
1170
1250
  ProviderID,
1171
1251
  GoogleOAuthAuthMethodID,
1172
1252
  WorkspaceDomainDelegationAuthMethodID,
1173
- GetMessageInputSchema,
1174
- SendMessageInputSchema,
1175
- ReplyToMessageInputSchema,
1176
- MessageSchema,
1177
- SendMessageOutputSchema,
1253
+ ConnectorID2,
1178
1254
  GetMessageBranch,
1179
- SendMessageBranch,
1180
- ReplyToMessageBranch,
1181
1255
  GetMessageDefinition,
1256
+ SendMessageBranch,
1182
1257
  SendMessageDefinition,
1258
+ ReplyToMessageBranch,
1183
1259
  ReplyToMessageDefinition,
1184
1260
  GmailMessageResourceSchema,
1185
1261
  decodeGmailMessage,
@@ -1208,7 +1284,7 @@ export {
1208
1284
  GmailConnection,
1209
1285
  newProjectConnection,
1210
1286
  newProjectGmailClient,
1211
- newGetMessageStep,
1212
- newSendMessageStep,
1213
- newReplyToMessageStep
1287
+ newGetMessageStep2 as newGetMessageStep,
1288
+ newSendMessageStep2 as newSendMessageStep,
1289
+ newReplyToMessageStep2 as newReplyToMessageStep
1214
1290
  };