@superdurable/connector-google-gmail 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -178,7 +178,9 @@ var SendMessageDefinition = {
178
178
  { id: "providerRejected", description: "Gmail conclusively rejected the message.", optional: true },
179
179
  { id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
180
180
  ],
181
- stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } }
181
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } },
182
+ repeatOnUnknown: "limited",
183
+ maxSends: 3
182
184
  };
183
185
  var ReplyToMessageBranch = {
184
186
  Sent: "sent",
@@ -198,7 +200,9 @@ var ReplyToMessageDefinition = {
198
200
  { id: "invalidResponse", description: "Gmail returned an invalid or oversized source message response before sending the reply.", optional: true },
199
201
  { id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
200
202
  ],
201
- stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } }
203
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 5, totalDurationMs: 12e4 } },
204
+ repeatOnUnknown: "limited",
205
+ maxSends: 3
202
206
  };
203
207
 
204
208
  // src/message.ts
@@ -218,6 +222,20 @@ var GmailMessageResourceSchema = import_zod3.z.object({
218
222
  internalDate: import_zod3.z.string().nullish(),
219
223
  payload: GmailMessagePartSchema.nullish()
220
224
  });
225
+ function parseMailbox(value) {
226
+ if (Array.from(value).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127)) return void 0;
227
+ const trimmed = value.trim();
228
+ const angle = /^(.*?)<([^<>]+)>$/.exec(trimmed);
229
+ if (!angle && /[<>]/.test(trimmed)) return void 0;
230
+ const address = angle?.[2]?.trim() ?? trimmed;
231
+ if (!/^[^<>\s,;@]+@[^<>\s,;@]+$/.test(address)) return void 0;
232
+ let display = angle?.[1]?.trim() ?? "";
233
+ if (display.startsWith('"')) {
234
+ if (!/^"(?:[^"\\]|\\.)*"$/.test(display)) return void 0;
235
+ display = display.slice(1, -1).replace(/\\(.)/g, "$1");
236
+ } else if (/[,:;<>@"\\()[\]]/.test(display)) return void 0;
237
+ return { display, address };
238
+ }
221
239
 
222
240
  // src/http.ts
223
241
  var import_connectors_sdk2 = require("@superdurable/connectors-sdk");
@@ -227,6 +245,7 @@ var import_providerhttp = require("@superdurable/connectors-sdk/providerhttp");
227
245
  var import_zod4 = require("zod");
228
246
  var SentMessageSchema = import_zod4.z.object({ id: import_zod4.z.string().optional(), threadId: import_zod4.z.string().optional() });
229
247
  var SentSearchSchema = import_zod4.z.object({ messages: import_zod4.z.array(SentMessageSchema).nullish() });
248
+ var MessageListSchema = import_zod4.z.object({ messages: import_zod4.z.array(import_zod4.z.object({ id: import_zod4.z.string().nullish(), threadId: import_zod4.z.string().nullish() })).nullish() });
230
249
 
231
250
  // src/refresh.ts
232
251
  var import_connectors_sdk3 = require("@superdurable/connectors-sdk");
@@ -306,6 +325,60 @@ var ProjectGmailConfigurationSchema = import_zod5.z.object({
306
325
  // src/generated/steps.ts
307
326
  var import_connectors_sdk10 = require("@superdurable/connectors-sdk");
308
327
 
328
+ // src/trigger.ts
329
+ var import_connectors_sdk12 = require("@superdurable/connectors-sdk");
330
+ var import_projectconfig2 = require("@superdurable/connectors-sdk/projectconfig");
331
+ var import_zod6 = require("zod");
332
+
333
+ // src/trigger_source.ts
334
+ var import_node_crypto2 = require("crypto");
335
+ var import_connectors_sdk11 = require("@superdurable/connectors-sdk");
336
+ var uuidNamespaceURL = Buffer.from("6ba7b8119dad11d180b400c04fd430c8", "hex");
337
+
338
+ // src/trigger.ts
339
+ var MessageMatcherSchema = import_zod6.z.strictObject({
340
+ /** Case-insensitive substring of the subject or snippet, required when non-empty. */
341
+ messageContains: import_zod6.z.string().optional(),
342
+ /** Sender addresses allowed to match when non-empty; compared case-insensitively. */
343
+ senderEmails: import_zod6.z.array(import_zod6.z.string()).nullable().optional()
344
+ });
345
+ var MessageReceivedTriggerConfigurationSchema = import_zod6.z.strictObject({ searchQuery: import_zod6.z.string().optional(), messageMatcher: MessageMatcherSchema.optional() }).superRefine((configuration, context) => validateMessageMatcher(configuration.messageMatcher, context));
346
+ var ReplyReceivedTriggerConfigurationSchema = import_zod6.z.strictObject({ searchQuery: import_zod6.z.string().optional(), replyMatcher: MessageMatcherSchema.optional() }).superRefine((configuration, context) => validateMessageMatcher(configuration.replyMatcher, context));
347
+ var MessageEventSchema = import_zod6.z.object({
348
+ /** Mailbox that received the message. */
349
+ primaryEmail: import_zod6.z.string(),
350
+ /** Gmail message ID. */
351
+ messageId: import_zod6.z.string(),
352
+ /** Gmail thread ID. */
353
+ threadId: import_zod6.z.string(),
354
+ /** Sender header. */
355
+ from: import_zod6.z.string(),
356
+ /** Decoded subject. */
357
+ subject: import_zod6.z.string(),
358
+ /** Gmail snippet, omitted when empty. */
359
+ snippet: import_zod6.z.string().optional(),
360
+ /** Receive time as RFC 3339 UTC. */
361
+ receivedAt: import_zod6.z.string(),
362
+ /** Whether the message has In-Reply-To or References headers. */
363
+ isReply: import_zod6.z.boolean()
364
+ });
365
+ function validateMessageMatcher(matcher, context) {
366
+ const seen = /* @__PURE__ */ new Set();
367
+ for (const sender of matcher?.senderEmails ?? []) {
368
+ const address = parseMailbox(sender)?.address;
369
+ if (!address) {
370
+ context.addIssue({ code: "custom", message: "Gmail sender email is invalid" });
371
+ return;
372
+ }
373
+ const canonical = address.toLowerCase();
374
+ if (seen.has(canonical)) {
375
+ context.addIssue({ code: "custom", message: "Gmail sender emails must be unique" });
376
+ return;
377
+ }
378
+ seen.add(canonical);
379
+ }
380
+ }
381
+
309
382
  // src/generated/mock.ts
310
383
  var import_connectormock = require("@superdurable/connectors-sdk/connectormock");
311
384
  var emptyGetMessageInput = GetMessageInputSchema.parse({
@@ -10,7 +10,7 @@ import {
10
10
  SendMessageInputSchema,
11
11
  SendMessageOutputSchema,
12
12
  SendMessageOutputSchema2
13
- } from "../chunk-OKDZ42YK.js";
13
+ } from "../chunk-PW3NTBVH.js";
14
14
 
15
15
  // src/mock/index.ts
16
16
  import { branchCase as branchCase2, newMutation as newMutation2, newQuery as newQuery2, retryCase as retryCase2, uncertainCase } from "@superdurable/connectors-sdk/connectormock";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdurable/connector-google-gmail",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "description": "Dex Gmail connector for TypeScript",
6
6
  "repository": {
@@ -49,14 +49,15 @@
49
49
  "typecheck": "npm run build && tsc --noEmit",
50
50
  "lint": "eslint src test test-d examples",
51
51
  "test": "npm run build && vitest run test/*.test.ts",
52
- "test:integration": "npm run build && vitest run examples/gmail-flow/integration.test.ts",
52
+ "test:integration": "npm run build && vitest run examples/gmail-flow/integration.test.ts examples/thread-reply/integration.test.ts",
53
53
  "example:worker": "tsx examples/gmail-flow/main.ts",
54
54
  "example:start": "tsx examples/gmail-flow/start.ts",
55
55
  "test-d": "tsc -p test-d/tsconfig.json",
56
- "check": "npm run typecheck && npm run test-d && npm run lint && npm test"
56
+ "check": "npm run typecheck && npm run test-d && npm run lint && npm test",
57
+ "example:thread-reply": "tsx examples/thread-reply/main.ts"
57
58
  },
58
59
  "dependencies": {
59
- "@superdurable/connectors-sdk": "0.9.0",
60
+ "@superdurable/connectors-sdk": "0.11.0",
60
61
  "@superdurable/dex": ">=1.28.0",
61
62
  "zod": "^4.1.0"
62
63
  },