@superdurable/connector-google-gmail 0.2.1 → 0.2.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
@@ -11,7 +11,7 @@ This package provides typed `getMessage`, `sendMessage`, and `replyToMessage` op
11
11
  The checked-in `src/generated/` contracts come from `connector.yaml` and the
12
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
13
 
14
- Version 0.2.1 requires Connector SDK 0.9.0. Generated private and shared
14
+ Version 0.2.2 requires Connector SDK 0.9.0. Generated private and shared
15
15
  credential decoders validate project material, and the refresh driver reads
16
16
  generated manifest grants with Gmail-specific delegation checks. Each token
17
17
  exchange honors the declared `tokenExchangeTimeout`, as the Go driver does.
@@ -4,7 +4,7 @@
4
4
  "package": {
5
5
  "ecosystem": "npm",
6
6
  "name": "@superdurable/connector-google-gmail",
7
- "version": "0.2.1"
7
+ "version": "0.2.2"
8
8
  },
9
9
  "factories": [
10
10
  {
@@ -347,7 +347,8 @@ function validateSendInput(input, sender) {
347
347
  return recipients;
348
348
  }
349
349
  function rfcMessageIDAddress(idempotencyKey, runId, flowStartedAt) {
350
- const runIdentity = `${runId}\0${Math.floor(flowStartedAt.getTime() / 1e3)}`;
350
+ if (!runId) throw new TypeError("Dex run ID is required");
351
+ const runIdentity = flowStartedAt instanceof Date && Number.isFinite(flowStartedAt.getTime()) ? `${runId}\0${Math.floor(flowStartedAt.getTime() / 1e3)}` : `${runId}\0no-flow-start`;
351
352
  return `${createHash("sha256").update(`${idempotencyKey}\0${runIdentity}`).digest("hex")}@dex.superdurable.dev`;
352
353
  }
353
354
  function buildMIMEMessage(callId, idempotencyKey, messageIdAddress, sender, recipients, subject, textBody, htmlBody = "", replyHeaders) {
@@ -819,6 +820,7 @@ var ReplyToMessageOutcomes = {
819
820
  sentBranch: ReplyToMessageBranch.Sent,
820
821
  providerRejectedBranch: ReplyToMessageBranch.ProviderRejected
821
822
  };
823
+ var MissingRunIDMessage = "the Dex call context has no run ID, so nothing was sent";
822
824
  var GmailSendAttemptBudget = class {
823
825
  /** Read-back cutoff in Unix milliseconds. */
824
826
  attemptDeadline;
@@ -909,6 +911,8 @@ var GmailSender = class {
909
911
  /** Send one new message under the Dex attempt deadline. */
910
912
  async sendMessage(call, input, dexDeadline) {
911
913
  if (call.context.attempt < 1) return defect("sendMessage", "LOCAL_DEFECT", "Dex Execute attempt number is invalid");
914
+ const messageIdAddress = this.#messageID(call);
915
+ if (!messageIdAddress) return defect("sendMessage", "LOCAL_DEFECT", MissingRunIDMessage);
912
916
  const fence = newFence(call, SendMessageDefinition.stepDefaults.executeMethodTimeoutMs ?? 3e4);
913
917
  if (fence.decide().kind === "failClosed") return defect("sendMessage", "LOCAL_DEFECT", "Dex send checkpoint is unreadable");
914
918
  const budget = new GmailSendAttemptBudget(call.context.cancellationSignal, dexDeadline);
@@ -931,16 +935,18 @@ var GmailSender = class {
931
935
  }
932
936
  let raw;
933
937
  try {
934
- raw = buildMIMEMessage(call.id, call.idempotencyKey ?? call.id, this.#messageID(call), credentials.primaryEmail, recipients, input.subject, input.textBody, input.htmlBody);
938
+ raw = buildMIMEMessage(call.id, call.idempotencyKey ?? call.id, messageIdAddress, credentials.primaryEmail, recipients, input.subject, input.textBody, input.htmlBody);
935
939
  } catch {
936
940
  return defect("sendMessage", "VALIDATION", "message could not be encoded");
937
941
  }
938
942
  if (raw.length > this.#http.settings().maxMessageBytes) return defect("sendMessage", "VALIDATION", "message exceeds configured size limit");
939
- return this.#sendAndConfirm(call, fence, budget, credentials, SendMessageOutcomes, { raw, recipients, requestedThreadId: "", hasPreSendSearch: false });
943
+ return this.#sendAndConfirm(call, fence, budget, credentials, SendMessageOutcomes, { raw, recipients, requestedThreadId: "", hasPreSendSearch: false, messageIdAddress });
940
944
  }
941
945
  /** Read the source then reply in its Gmail thread under the Dex attempt deadline. */
942
946
  async replyToMessage(call, input, dexDeadline) {
943
947
  if (call.context.attempt < 1) return defect("replyToMessage", "LOCAL_DEFECT", "Dex Execute attempt number is invalid");
948
+ const messageIdAddress = this.#messageID(call);
949
+ if (!messageIdAddress) return defect("replyToMessage", "LOCAL_DEFECT", MissingRunIDMessage);
944
950
  const fence = newFence(call, ReplyToMessageDefinition.stepDefaults.executeMethodTimeoutMs ?? 3e4);
945
951
  if (fence.decide().kind === "failClosed") return defect("replyToMessage", "LOCAL_DEFECT", "Dex send checkpoint is unreadable");
946
952
  const budget = new GmailSendAttemptBudget(call.context.cancellationSignal, dexDeadline);
@@ -962,15 +968,15 @@ var GmailSender = class {
962
968
  budget,
963
969
  credentials,
964
970
  ReplyToMessageOutcomes,
965
- { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true },
971
+ { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true, messageIdAddress },
966
972
  { id: priorProviderId, threadId: "" },
967
973
  this.#receipt(call, "", priorProviderId)
968
974
  );
969
975
  }
970
976
  if (call.context.attempt > 1 || fence.decide().kind === "readBackRequired") {
971
977
  try {
972
- const found = await this.#provider.findSentMessage(call, credentials, this.#messageID(call), budget.preSendSignal());
973
- if (found) return this.#sentMessage(call, budget, credentials, ReplyToMessageOutcomes, { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true }, found, this.#receipt(call));
978
+ const found = await this.#provider.findSentMessage(call, credentials, messageIdAddress, budget.preSendSignal());
979
+ if (found) return this.#sentMessage(call, budget, credentials, ReplyToMessageOutcomes, { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true, messageIdAddress }, found, this.#receipt(call));
974
980
  } catch {
975
981
  await recordPreSendRetry(fence);
976
982
  return newMutationRetry(failure("replyToMessage", "AVAILABILITY", "Gmail sent-mail search did not answer before the reply"));
@@ -1010,12 +1016,12 @@ var GmailSender = class {
1010
1016
  if (/[\r\n]/.test(message.subject + message.rfcMessageId + (message.references ?? ""))) return newMutationBranch(ReplyToMessageBranch.InvalidResponse, emptySend(), this.#receipt(call, gmailRequestID(source.response.headers), input.messageId), failure("replyToMessage", "PROTOCOL", "Gmail returned invalid source reply headers"));
1011
1017
  let raw;
1012
1018
  try {
1013
- raw = buildReplyMIMEMessage(call.id, call.idempotencyKey ?? call.id, this.#messageID(call), credentials.primaryEmail, message, input);
1019
+ raw = buildReplyMIMEMessage(call.id, call.idempotencyKey ?? call.id, messageIdAddress, credentials.primaryEmail, message, input);
1014
1020
  } catch {
1015
1021
  return defect("replyToMessage", "VALIDATION", "reply could not be encoded within the configured limit");
1016
1022
  }
1017
1023
  if (raw.length > this.#http.settings().maxMessageBytes) return defect("replyToMessage", "VALIDATION", "reply could not be encoded within the configured limit");
1018
- return this.#sendAndConfirm(call, fence, budget, credentials, ReplyToMessageOutcomes, { raw, recipients: [recipient], requestedThreadId: message.threadId, hasPreSendSearch: call.context.attempt > 1 });
1024
+ return this.#sendAndConfirm(call, fence, budget, credentials, ReplyToMessageOutcomes, { raw, recipients: [recipient], requestedThreadId: message.threadId, hasPreSendSearch: call.context.attempt > 1, messageIdAddress });
1019
1025
  }
1020
1026
  async #sendAndConfirm(call, fence, budget, credentials, operation, message) {
1021
1027
  const priorProviderId = fence.decide().marker?.providerId;
@@ -1032,7 +1038,7 @@ var GmailSender = class {
1032
1038
  }
1033
1039
  if ((call.context.attempt > 1 || fence.decide().kind === "readBackRequired") && !message.hasPreSendSearch) {
1034
1040
  try {
1035
- const found = await this.#provider.findSentMessage(call, credentials, this.#messageID(call), budget.preSendSignal());
1041
+ const found = await this.#provider.findSentMessage(call, credentials, message.messageIdAddress, budget.preSendSignal());
1036
1042
  if (found) return this.#sentMessage(call, budget, credentials, operation, message, found, this.#receipt(call));
1037
1043
  } catch {
1038
1044
  await recordPreSendRetry(fence);
@@ -1064,7 +1070,7 @@ var GmailSender = class {
1064
1070
  return retryAfterRefusal(operation.operationId, "RATE_LIMIT", `Gmail temporarily rejected the ${operation.requestName}`, headers);
1065
1071
  }
1066
1072
  if (status === 503) {
1067
- const lookup = await this.#pollSentMessage(call, budget, credentials);
1073
+ const lookup = await this.#pollSentMessage(call, budget, credentials, message);
1068
1074
  if (lookup.sent) return this.#sentAfterDispatch(call, fence, budget, credentials, operation, message, lookup.sent, receipt);
1069
1075
  return retryAfterRefusal(operation.operationId, "AVAILABILITY", `Gmail ${operation.requestName} is temporarily unavailable`, headers);
1070
1076
  }
@@ -1072,7 +1078,7 @@ var GmailSender = class {
1072
1078
  if (status < 200 || status >= 300) {
1073
1079
  if (call.context.attempt > 1) {
1074
1080
  try {
1075
- const found = await this.#provider.findSentMessage(call, credentials, this.#messageID(call), budget.attemptSignal());
1081
+ const found = await this.#provider.findSentMessage(call, credentials, message.messageIdAddress, budget.attemptSignal());
1076
1082
  if (found) return this.#sentMessage(call, budget, credentials, operation, message, found, receipt);
1077
1083
  } catch {
1078
1084
  }
@@ -1080,14 +1086,14 @@ var GmailSender = class {
1080
1086
  return newMutationBranch(operation.providerRejectedBranch, emptySend(), receipt, failure(operation.operationId, statusFailureKind(status), operation.rejectionMessage));
1081
1087
  }
1082
1088
  if (!sentResponse) {
1083
- const lookup = await this.#pollSentMessage(call, budget, credentials);
1089
+ const lookup = await this.#pollSentMessage(call, budget, credentials, message);
1084
1090
  if (lookup.sent) return this.#sentAfterDispatch(call, fence, budget, credentials, operation, message, lookup.sent, receipt);
1085
1091
  return this.#sentMessage(call, budget, credentials, operation, message, { id: "", threadId: message.requestedThreadId }, receipt);
1086
1092
  }
1087
1093
  return this.#sentMessage(call, budget, credentials, operation, message, sentResponse, receipt);
1088
1094
  }
1089
1095
  async #confirmPossiblySent(call, fence, budget, credentials, operation, message, kind, reason, receipt) {
1090
- const lookup = await this.#pollSentMessage(call, budget, credentials);
1096
+ const lookup = await this.#pollSentMessage(call, budget, credentials, message);
1091
1097
  if (lookup.sent) return this.#sentAfterDispatch(call, fence, budget, credentials, operation, message, lookup.sent, receipt);
1092
1098
  const suffix = lookup.hadError ? "the sent-mail search did not answer" : "the sent-mail search found no message";
1093
1099
  return newMutationRetry(failure(operation.operationId, kind, `${reason}; ${suffix}`));
@@ -1108,7 +1114,7 @@ var GmailSender = class {
1108
1114
  }
1109
1115
  return newMutationBranch(operation.sentBranch, { sender: credentials.primaryEmail, recipients: message.recipients, messageId: sent.id, threadId }, { ...receipt, providerObjectId: sent.id });
1110
1116
  }
1111
- async #pollSentMessage(call, budget, credentials) {
1117
+ async #pollSentMessage(call, budget, credentials, message) {
1112
1118
  let hadError = false;
1113
1119
  for (let lookup = 0; lookup < 4; lookup++) {
1114
1120
  if (lookup > 0) {
@@ -1119,7 +1125,7 @@ var GmailSender = class {
1119
1125
  }
1120
1126
  }
1121
1127
  try {
1122
- const found = await this.#provider.findSentMessage(call, credentials, this.#messageID(call), budget.attemptSignal());
1128
+ const found = await this.#provider.findSentMessage(call, credentials, message.messageIdAddress, budget.attemptSignal());
1123
1129
  if (found) return { sent: found, hadError: false };
1124
1130
  hadError = false;
1125
1131
  } catch {
@@ -1130,7 +1136,9 @@ var GmailSender = class {
1130
1136
  return { hadError };
1131
1137
  }
1132
1138
  #messageID(call) {
1133
- return rfcMessageIDAddress(call.idempotencyKey ?? call.id, call.context.runId, call.context.flowStartedAt);
1139
+ const { runId, flowStartedAt } = call.context;
1140
+ if (typeof runId !== "string" || !runId) return void 0;
1141
+ return rfcMessageIDAddress(call.idempotencyKey ?? call.id, runId, flowStartedAt);
1134
1142
  }
1135
1143
  #receipt(call, requestId = "", objectId = "") {
1136
1144
  return { callId: call.id, ...call.idempotencyKey ? { idempotencyKey: call.idempotencyKey } : {}, provider: "gmail", providerObjectId: objectId, providerRequestId: requestId, observedAt: this.#now().toISOString() };
package/dist/index.cjs CHANGED
@@ -417,7 +417,8 @@ function validateSendInput(input, sender) {
417
417
  return recipients;
418
418
  }
419
419
  function rfcMessageIDAddress(idempotencyKey, runId, flowStartedAt) {
420
- const runIdentity = `${runId}\0${Math.floor(flowStartedAt.getTime() / 1e3)}`;
420
+ if (!runId) throw new TypeError("Dex run ID is required");
421
+ const runIdentity = flowStartedAt instanceof Date && Number.isFinite(flowStartedAt.getTime()) ? `${runId}\0${Math.floor(flowStartedAt.getTime() / 1e3)}` : `${runId}\0no-flow-start`;
421
422
  return `${(0, import_node_crypto.createHash)("sha256").update(`${idempotencyKey}\0${runIdentity}`).digest("hex")}@dex.superdurable.dev`;
422
423
  }
423
424
  function buildMIMEMessage(callId, idempotencyKey, messageIdAddress, sender, recipients, subject, textBody, htmlBody = "", replyHeaders) {
@@ -880,6 +881,7 @@ var ReplyToMessageOutcomes = {
880
881
  sentBranch: ReplyToMessageBranch.Sent,
881
882
  providerRejectedBranch: ReplyToMessageBranch.ProviderRejected
882
883
  };
884
+ var MissingRunIDMessage = "the Dex call context has no run ID, so nothing was sent";
883
885
  var GmailSendAttemptBudget = class {
884
886
  /** Read-back cutoff in Unix milliseconds. */
885
887
  attemptDeadline;
@@ -970,6 +972,8 @@ var GmailSender = class {
970
972
  /** Send one new message under the Dex attempt deadline. */
971
973
  async sendMessage(call, input, dexDeadline) {
972
974
  if (call.context.attempt < 1) return defect("sendMessage", "LOCAL_DEFECT", "Dex Execute attempt number is invalid");
975
+ const messageIdAddress = this.#messageID(call);
976
+ if (!messageIdAddress) return defect("sendMessage", "LOCAL_DEFECT", MissingRunIDMessage);
973
977
  const fence = (0, import_singledispatch.newFence)(call, SendMessageDefinition.stepDefaults.executeMethodTimeoutMs ?? 3e4);
974
978
  if (fence.decide().kind === "failClosed") return defect("sendMessage", "LOCAL_DEFECT", "Dex send checkpoint is unreadable");
975
979
  const budget = new GmailSendAttemptBudget(call.context.cancellationSignal, dexDeadline);
@@ -992,16 +996,18 @@ var GmailSender = class {
992
996
  }
993
997
  let raw;
994
998
  try {
995
- raw = buildMIMEMessage(call.id, call.idempotencyKey ?? call.id, this.#messageID(call), credentials.primaryEmail, recipients, input.subject, input.textBody, input.htmlBody);
999
+ raw = buildMIMEMessage(call.id, call.idempotencyKey ?? call.id, messageIdAddress, credentials.primaryEmail, recipients, input.subject, input.textBody, input.htmlBody);
996
1000
  } catch {
997
1001
  return defect("sendMessage", "VALIDATION", "message could not be encoded");
998
1002
  }
999
1003
  if (raw.length > this.#http.settings().maxMessageBytes) return defect("sendMessage", "VALIDATION", "message exceeds configured size limit");
1000
- return this.#sendAndConfirm(call, fence, budget, credentials, SendMessageOutcomes, { raw, recipients, requestedThreadId: "", hasPreSendSearch: false });
1004
+ return this.#sendAndConfirm(call, fence, budget, credentials, SendMessageOutcomes, { raw, recipients, requestedThreadId: "", hasPreSendSearch: false, messageIdAddress });
1001
1005
  }
1002
1006
  /** Read the source then reply in its Gmail thread under the Dex attempt deadline. */
1003
1007
  async replyToMessage(call, input, dexDeadline) {
1004
1008
  if (call.context.attempt < 1) return defect("replyToMessage", "LOCAL_DEFECT", "Dex Execute attempt number is invalid");
1009
+ const messageIdAddress = this.#messageID(call);
1010
+ if (!messageIdAddress) return defect("replyToMessage", "LOCAL_DEFECT", MissingRunIDMessage);
1005
1011
  const fence = (0, import_singledispatch.newFence)(call, ReplyToMessageDefinition.stepDefaults.executeMethodTimeoutMs ?? 3e4);
1006
1012
  if (fence.decide().kind === "failClosed") return defect("replyToMessage", "LOCAL_DEFECT", "Dex send checkpoint is unreadable");
1007
1013
  const budget = new GmailSendAttemptBudget(call.context.cancellationSignal, dexDeadline);
@@ -1023,15 +1029,15 @@ var GmailSender = class {
1023
1029
  budget,
1024
1030
  credentials,
1025
1031
  ReplyToMessageOutcomes,
1026
- { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true },
1032
+ { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true, messageIdAddress },
1027
1033
  { id: priorProviderId, threadId: "" },
1028
1034
  this.#receipt(call, "", priorProviderId)
1029
1035
  );
1030
1036
  }
1031
1037
  if (call.context.attempt > 1 || fence.decide().kind === "readBackRequired") {
1032
1038
  try {
1033
- const found = await this.#provider.findSentMessage(call, credentials, this.#messageID(call), budget.preSendSignal());
1034
- if (found) return this.#sentMessage(call, budget, credentials, ReplyToMessageOutcomes, { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true }, found, this.#receipt(call));
1039
+ const found = await this.#provider.findSentMessage(call, credentials, messageIdAddress, budget.preSendSignal());
1040
+ if (found) return this.#sentMessage(call, budget, credentials, ReplyToMessageOutcomes, { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true, messageIdAddress }, found, this.#receipt(call));
1035
1041
  } catch {
1036
1042
  await recordPreSendRetry(fence);
1037
1043
  return (0, import_connectors_sdk4.newMutationRetry)(failure("replyToMessage", "AVAILABILITY", "Gmail sent-mail search did not answer before the reply"));
@@ -1071,12 +1077,12 @@ var GmailSender = class {
1071
1077
  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"));
1072
1078
  let raw;
1073
1079
  try {
1074
- raw = buildReplyMIMEMessage(call.id, call.idempotencyKey ?? call.id, this.#messageID(call), credentials.primaryEmail, message, input);
1080
+ raw = buildReplyMIMEMessage(call.id, call.idempotencyKey ?? call.id, messageIdAddress, credentials.primaryEmail, message, input);
1075
1081
  } catch {
1076
1082
  return defect("replyToMessage", "VALIDATION", "reply could not be encoded within the configured limit");
1077
1083
  }
1078
1084
  if (raw.length > this.#http.settings().maxMessageBytes) return defect("replyToMessage", "VALIDATION", "reply could not be encoded within the configured limit");
1079
- return this.#sendAndConfirm(call, fence, budget, credentials, ReplyToMessageOutcomes, { raw, recipients: [recipient], requestedThreadId: message.threadId, hasPreSendSearch: call.context.attempt > 1 });
1085
+ return this.#sendAndConfirm(call, fence, budget, credentials, ReplyToMessageOutcomes, { raw, recipients: [recipient], requestedThreadId: message.threadId, hasPreSendSearch: call.context.attempt > 1, messageIdAddress });
1080
1086
  }
1081
1087
  async #sendAndConfirm(call, fence, budget, credentials, operation, message) {
1082
1088
  const priorProviderId = fence.decide().marker?.providerId;
@@ -1093,7 +1099,7 @@ var GmailSender = class {
1093
1099
  }
1094
1100
  if ((call.context.attempt > 1 || fence.decide().kind === "readBackRequired") && !message.hasPreSendSearch) {
1095
1101
  try {
1096
- const found = await this.#provider.findSentMessage(call, credentials, this.#messageID(call), budget.preSendSignal());
1102
+ const found = await this.#provider.findSentMessage(call, credentials, message.messageIdAddress, budget.preSendSignal());
1097
1103
  if (found) return this.#sentMessage(call, budget, credentials, operation, message, found, this.#receipt(call));
1098
1104
  } catch {
1099
1105
  await recordPreSendRetry(fence);
@@ -1125,7 +1131,7 @@ var GmailSender = class {
1125
1131
  return retryAfterRefusal(operation.operationId, "RATE_LIMIT", `Gmail temporarily rejected the ${operation.requestName}`, headers);
1126
1132
  }
1127
1133
  if (status === 503) {
1128
- const lookup = await this.#pollSentMessage(call, budget, credentials);
1134
+ const lookup = await this.#pollSentMessage(call, budget, credentials, message);
1129
1135
  if (lookup.sent) return this.#sentAfterDispatch(call, fence, budget, credentials, operation, message, lookup.sent, receipt);
1130
1136
  return retryAfterRefusal(operation.operationId, "AVAILABILITY", `Gmail ${operation.requestName} is temporarily unavailable`, headers);
1131
1137
  }
@@ -1133,7 +1139,7 @@ var GmailSender = class {
1133
1139
  if (status < 200 || status >= 300) {
1134
1140
  if (call.context.attempt > 1) {
1135
1141
  try {
1136
- const found = await this.#provider.findSentMessage(call, credentials, this.#messageID(call), budget.attemptSignal());
1142
+ const found = await this.#provider.findSentMessage(call, credentials, message.messageIdAddress, budget.attemptSignal());
1137
1143
  if (found) return this.#sentMessage(call, budget, credentials, operation, message, found, receipt);
1138
1144
  } catch {
1139
1145
  }
@@ -1141,14 +1147,14 @@ var GmailSender = class {
1141
1147
  return (0, import_connectors_sdk4.newMutationBranch)(operation.providerRejectedBranch, emptySend(), receipt, failure(operation.operationId, statusFailureKind(status), operation.rejectionMessage));
1142
1148
  }
1143
1149
  if (!sentResponse) {
1144
- const lookup = await this.#pollSentMessage(call, budget, credentials);
1150
+ const lookup = await this.#pollSentMessage(call, budget, credentials, message);
1145
1151
  if (lookup.sent) return this.#sentAfterDispatch(call, fence, budget, credentials, operation, message, lookup.sent, receipt);
1146
1152
  return this.#sentMessage(call, budget, credentials, operation, message, { id: "", threadId: message.requestedThreadId }, receipt);
1147
1153
  }
1148
1154
  return this.#sentMessage(call, budget, credentials, operation, message, sentResponse, receipt);
1149
1155
  }
1150
1156
  async #confirmPossiblySent(call, fence, budget, credentials, operation, message, kind, reason, receipt) {
1151
- const lookup = await this.#pollSentMessage(call, budget, credentials);
1157
+ const lookup = await this.#pollSentMessage(call, budget, credentials, message);
1152
1158
  if (lookup.sent) return this.#sentAfterDispatch(call, fence, budget, credentials, operation, message, lookup.sent, receipt);
1153
1159
  const suffix = lookup.hadError ? "the sent-mail search did not answer" : "the sent-mail search found no message";
1154
1160
  return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, kind, `${reason}; ${suffix}`));
@@ -1169,7 +1175,7 @@ var GmailSender = class {
1169
1175
  }
1170
1176
  return (0, import_connectors_sdk4.newMutationBranch)(operation.sentBranch, { sender: credentials.primaryEmail, recipients: message.recipients, messageId: sent.id, threadId }, { ...receipt, providerObjectId: sent.id });
1171
1177
  }
1172
- async #pollSentMessage(call, budget, credentials) {
1178
+ async #pollSentMessage(call, budget, credentials, message) {
1173
1179
  let hadError = false;
1174
1180
  for (let lookup = 0; lookup < 4; lookup++) {
1175
1181
  if (lookup > 0) {
@@ -1180,7 +1186,7 @@ var GmailSender = class {
1180
1186
  }
1181
1187
  }
1182
1188
  try {
1183
- const found = await this.#provider.findSentMessage(call, credentials, this.#messageID(call), budget.attemptSignal());
1189
+ const found = await this.#provider.findSentMessage(call, credentials, message.messageIdAddress, budget.attemptSignal());
1184
1190
  if (found) return { sent: found, hadError: false };
1185
1191
  hadError = false;
1186
1192
  } catch {
@@ -1191,7 +1197,9 @@ var GmailSender = class {
1191
1197
  return { hadError };
1192
1198
  }
1193
1199
  #messageID(call) {
1194
- return rfcMessageIDAddress(call.idempotencyKey ?? call.id, call.context.runId, call.context.flowStartedAt);
1200
+ const { runId, flowStartedAt } = call.context;
1201
+ if (typeof runId !== "string" || !runId) return void 0;
1202
+ return rfcMessageIDAddress(call.idempotencyKey ?? call.id, runId, flowStartedAt);
1195
1203
  }
1196
1204
  #receipt(call, requestId = "", objectId = "") {
1197
1205
  return { callId: call.id, ...call.idempotencyKey ? { idempotencyKey: call.idempotencyKey } : {}, provider: "gmail", providerObjectId: objectId, providerRequestId: requestId, observedAt: this.#now().toISOString() };
package/dist/index.d.cts CHANGED
@@ -73,8 +73,16 @@ declare function parseMailbox(value: string): {
73
73
  declare function replyRecipient(message: Message): string;
74
74
  /** Validate sender, recipients, subject, and body before sending. */
75
75
  declare function validateSendInput(input: SendMessageInput, sender: string): string[];
76
- /** Deterministic provider search identity for one Dex run and connector call. */
77
- declare function rfcMessageIDAddress(idempotencyKey: string, runId: string, flowStartedAt: Date): string;
76
+ /**
77
+ * Deterministic provider search identity for one Dex run and connector call.
78
+ *
79
+ * A valid `flowStartedAt` keeps the Go connector's derivation. An absent or
80
+ * invalid one derives the identity from the key and run ID alone, which stays
81
+ * stable across retries of the call within one run.
82
+ *
83
+ * @throws TypeError when `runId` is empty.
84
+ */
85
+ declare function rfcMessageIDAddress(idempotencyKey: string, runId: string, flowStartedAt?: Date | null): string;
78
86
  /** Build the exact raw RFC 5322 request body shared by sends and replies. */
79
87
  declare function buildMIMEMessage(callId: string, idempotencyKey: string, messageIdAddress: string, sender: string, recipients: string[], subject: string, textBody: string, htmlBody?: string, replyHeaders?: {
80
88
  inReplyTo: string;
package/dist/index.d.ts CHANGED
@@ -73,8 +73,16 @@ declare function parseMailbox(value: string): {
73
73
  declare function replyRecipient(message: Message): string;
74
74
  /** Validate sender, recipients, subject, and body before sending. */
75
75
  declare function validateSendInput(input: SendMessageInput, sender: string): string[];
76
- /** Deterministic provider search identity for one Dex run and connector call. */
77
- declare function rfcMessageIDAddress(idempotencyKey: string, runId: string, flowStartedAt: Date): string;
76
+ /**
77
+ * Deterministic provider search identity for one Dex run and connector call.
78
+ *
79
+ * A valid `flowStartedAt` keeps the Go connector's derivation. An absent or
80
+ * invalid one derives the identity from the key and run ID alone, which stays
81
+ * stable across retries of the call within one run.
82
+ *
83
+ * @throws TypeError when `runId` is empty.
84
+ */
85
+ declare function rfcMessageIDAddress(idempotencyKey: string, runId: string, flowStartedAt?: Date | null): string;
78
86
  /** Build the exact raw RFC 5322 request body shared by sends and replies. */
79
87
  declare function buildMIMEMessage(callId: string, idempotencyKey: string, messageIdAddress: string, sender: string, recipients: string[], subject: string, textBody: string, htmlBody?: string, replyHeaders?: {
80
88
  inReplyTo: string;
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  rfcMessageIDAddress,
45
45
  statusFailureKind,
46
46
  validateSendInput
47
- } from "./chunk-KVNIQW5Y.js";
47
+ } from "./chunk-OKDZ42YK.js";
48
48
  export {
49
49
  ConnectorID,
50
50
  GetMessageBranch,
@@ -10,7 +10,7 @@ import {
10
10
  SendMessageInputSchema,
11
11
  SendMessageOutputSchema,
12
12
  SendMessageOutputSchema2
13
- } from "../chunk-KVNIQW5Y.js";
13
+ } from "../chunk-OKDZ42YK.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.1",
3
+ "version": "0.2.2",
4
4
  "license": "MIT",
5
5
  "description": "Dex Gmail connector for TypeScript",
6
6
  "repository": {