@superdurable/connector-google-gmail 0.1.1 → 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/dex-connector.json +1 -1
- package/dist/{chunk-TWBWDIC7.js → chunk-IAO6TPJ3.js} +6 -5
- package/dist/index.cjs +71 -70
- package/dist/index.js +1 -1
- package/dist/mock/index.cjs +12 -11
- package/dist/mock/index.js +1 -1
- package/package.json +2 -2
package/dex-connector.json
CHANGED
|
@@ -3,6 +3,7 @@ import { z as z2 } from "zod";
|
|
|
3
3
|
|
|
4
4
|
// src/generated/models.ts
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { SecretString } from "@superdurable/connectors-sdk";
|
|
6
7
|
var ConfigSchema = z.object({
|
|
7
8
|
"endpoint": z.string().optional(),
|
|
8
9
|
"maxResponseBytes": z.number().int().optional(),
|
|
@@ -1099,7 +1100,7 @@ import { newRefreshingCredentialProvider } from "@superdurable/connectors-sdk/pr
|
|
|
1099
1100
|
import { z as z7 } from "zod";
|
|
1100
1101
|
|
|
1101
1102
|
// src/credential_codec.ts
|
|
1102
|
-
import { SecretString } from "@superdurable/connectors-sdk";
|
|
1103
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
1103
1104
|
import { z as z6 } from "zod";
|
|
1104
1105
|
var StoredCredentialsSchema = z6.object({
|
|
1105
1106
|
auth_method: z6.string().optional(),
|
|
@@ -1137,11 +1138,11 @@ function decodeCredentialFields(value, isShared) {
|
|
|
1137
1138
|
const credentials = {
|
|
1138
1139
|
authMethodId: stored.auth_method || GoogleOAuthAuthMethodID,
|
|
1139
1140
|
oauthClientId: stored.oauth_client_id ?? "",
|
|
1140
|
-
oauthClientSecret: new
|
|
1141
|
-
accessToken: new
|
|
1142
|
-
refreshToken: new
|
|
1141
|
+
oauthClientSecret: new SecretString2(stored.oauth_client_secret ?? ""),
|
|
1142
|
+
accessToken: new SecretString2(stored.access_token ?? ""),
|
|
1143
|
+
refreshToken: new SecretString2(stored.refresh_token ?? ""),
|
|
1143
1144
|
primaryEmail: stored.primary_email ?? "",
|
|
1144
|
-
serviceAccountKey: new
|
|
1145
|
+
serviceAccountKey: new SecretString2(stored.service_account_key ?? ""),
|
|
1145
1146
|
delegatedUser: stored.delegated_user ?? ""
|
|
1146
1147
|
};
|
|
1147
1148
|
if (credentials.authMethodId === GoogleOAuthAuthMethodID) {
|
package/dist/index.cjs
CHANGED
|
@@ -73,6 +73,7 @@ var import_zod2 = require("zod");
|
|
|
73
73
|
|
|
74
74
|
// src/generated/models.ts
|
|
75
75
|
var import_zod = require("zod");
|
|
76
|
+
var import_connectors_sdk = require("@superdurable/connectors-sdk");
|
|
76
77
|
var ConfigSchema = import_zod.z.object({
|
|
77
78
|
"endpoint": import_zod.z.string().optional(),
|
|
78
79
|
"maxResponseBytes": import_zod.z.number().int().optional(),
|
|
@@ -374,7 +375,7 @@ function encodeSubject(value) {
|
|
|
374
375
|
}
|
|
375
376
|
|
|
376
377
|
// src/http.ts
|
|
377
|
-
var
|
|
378
|
+
var import_connectors_sdk2 = require("@superdurable/connectors-sdk");
|
|
378
379
|
var import_providerhttp = require("@superdurable/connectors-sdk/providerhttp");
|
|
379
380
|
function gmailClientSettings(config = {}) {
|
|
380
381
|
const endpoint = (0, import_providerhttp.validateBaseURL)(config.endpoint ?? "https://gmail.googleapis.com/gmail/v1");
|
|
@@ -413,7 +414,7 @@ var GmailHTTPClient = class {
|
|
|
413
414
|
/** Resolve a private token at call time; never put it in a receipt or Flow value. */
|
|
414
415
|
async resolveCredentials(call, signal) {
|
|
415
416
|
try {
|
|
416
|
-
const credentials = await (0,
|
|
417
|
+
const credentials = await (0, import_connectors_sdk2.resolveCredential)(this.#credentials, call, this.#refreshDriver, signal);
|
|
417
418
|
validateCredentials(credentials);
|
|
418
419
|
return credentials;
|
|
419
420
|
} catch {
|
|
@@ -445,7 +446,7 @@ var GmailHTTPClient = class {
|
|
|
445
446
|
}
|
|
446
447
|
if (response.status !== 401 || attempt !== 0 || !("resolveAfterRejection" in this.#credentials)) return { response, credentials: currentCredentials };
|
|
447
448
|
try {
|
|
448
|
-
const refreshed = await (0,
|
|
449
|
+
const refreshed = await (0, import_connectors_sdk2.resolveCredentialAfterRejection)(this.#credentials, call, this.#refreshDriver, signal);
|
|
449
450
|
validateCredentials(refreshed);
|
|
450
451
|
currentCredentials = refreshed;
|
|
451
452
|
} catch {
|
|
@@ -554,7 +555,7 @@ function parseSentResponse(response) {
|
|
|
554
555
|
}
|
|
555
556
|
|
|
556
557
|
// src/refresh.ts
|
|
557
|
-
var
|
|
558
|
+
var import_connectors_sdk3 = require("@superdurable/connectors-sdk");
|
|
558
559
|
var import_oauthtoken = require("@superdurable/connectors-sdk/oauthtoken");
|
|
559
560
|
var import_zod5 = require("zod");
|
|
560
561
|
var GoogleOAuthTokenEndpoint = "https://oauth2.googleapis.com/token";
|
|
@@ -578,7 +579,7 @@ var GmailCredentialRefreshDriver = class {
|
|
|
578
579
|
async refresh(state, signal) {
|
|
579
580
|
const credentials = state.credentials;
|
|
580
581
|
if (!credentials.authMethodId || credentials.authMethodId === GoogleOAuthAuthMethodID) {
|
|
581
|
-
if (!credentials.oauthClientId || !credentials.oauthClientSecret || !credentials.refreshToken) throw new
|
|
582
|
+
if (!credentials.oauthClientId || !credentials.oauthClientSecret || !credentials.refreshToken) throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
582
583
|
const token2 = await this.#tokenEndpoint(GoogleOAuthTokenEndpoint).exchangeRefreshToken({
|
|
583
584
|
id: credentials.oauthClientId,
|
|
584
585
|
secret: credentials.oauthClientSecret,
|
|
@@ -590,15 +591,15 @@ var GmailCredentialRefreshDriver = class {
|
|
|
590
591
|
expiresAt: new Date(this.#now().getTime() + token2.expiresInMs)
|
|
591
592
|
};
|
|
592
593
|
}
|
|
593
|
-
if (credentials.authMethodId !== WorkspaceDomainDelegationAuthMethodID) throw new
|
|
594
|
+
if (credentials.authMethodId !== WorkspaceDomainDelegationAuthMethodID) throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
594
595
|
let key;
|
|
595
596
|
try {
|
|
596
597
|
key = ServiceAccountKeySchema.parse(JSON.parse(credentials.serviceAccountKey?.reveal() ?? ""));
|
|
597
598
|
} catch {
|
|
598
|
-
throw new
|
|
599
|
+
throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
599
600
|
}
|
|
600
601
|
const delegatedUser = credentials.delegatedUser;
|
|
601
|
-
if (new URL(key.token_uri).protocol !== "https:" || !delegatedUser || !parseMailbox(delegatedUser)) throw new
|
|
602
|
+
if (new URL(key.token_uri).protocol !== "https:" || !delegatedUser || !parseMailbox(delegatedUser)) throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
602
603
|
let assertion;
|
|
603
604
|
try {
|
|
604
605
|
assertion = (0, import_oauthtoken.signJWTBearerAssertion)({
|
|
@@ -610,7 +611,7 @@ var GmailCredentialRefreshDriver = class {
|
|
|
610
611
|
lifetimeMs: 36e5
|
|
611
612
|
}, (0, import_oauthtoken.parseRSAPrivateKeyPEM)(key.private_key));
|
|
612
613
|
} catch {
|
|
613
|
-
throw new
|
|
614
|
+
throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
614
615
|
}
|
|
615
616
|
const token = await this.#tokenEndpoint(key.token_uri).exchangeJWTBearerAssertion(assertion, signal);
|
|
616
617
|
this.#verifyScopes(token.scope);
|
|
@@ -623,12 +624,12 @@ var GmailCredentialRefreshDriver = class {
|
|
|
623
624
|
return new import_oauthtoken.TokenEndpoint({ providerName: "Google", url, terminalErrorCodes: TerminalErrorCodes, fetch: this.#fetch });
|
|
624
625
|
}
|
|
625
626
|
#verifyScopes(scope) {
|
|
626
|
-
if (scope && !(0, import_oauthtoken.hasAllScopes)(scope, RequiredGmailScopes)) throw new
|
|
627
|
+
if (scope && !(0, import_oauthtoken.hasAllScopes)(scope, RequiredGmailScopes)) throw new import_connectors_sdk3.ReauthorizationRequiredError();
|
|
627
628
|
}
|
|
628
629
|
};
|
|
629
630
|
|
|
630
631
|
// src/send.ts
|
|
631
|
-
var
|
|
632
|
+
var import_connectors_sdk4 = require("@superdurable/connectors-sdk");
|
|
632
633
|
var import_providerhttp2 = require("@superdurable/connectors-sdk/providerhttp");
|
|
633
634
|
var import_singledispatch = require("@superdurable/connectors-sdk/singledispatch");
|
|
634
635
|
var import_promises = require("timers/promises");
|
|
@@ -741,7 +742,7 @@ var GmailSender = class {
|
|
|
741
742
|
const budget = new GmailSendAttemptBudget(call.context.cancellationSignal, dexDeadline);
|
|
742
743
|
if (!budget.sendSignal()) {
|
|
743
744
|
await recordPreSendRetry(fence);
|
|
744
|
-
return (0,
|
|
745
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure("sendMessage", "AVAILABILITY", "too little of the Execute attempt is left to send safely, so nothing was sent"));
|
|
745
746
|
}
|
|
746
747
|
let credentials;
|
|
747
748
|
try {
|
|
@@ -773,7 +774,7 @@ var GmailSender = class {
|
|
|
773
774
|
const budget = new GmailSendAttemptBudget(call.context.cancellationSignal, dexDeadline);
|
|
774
775
|
if (!budget.sendSignal()) {
|
|
775
776
|
await recordPreSendRetry(fence);
|
|
776
|
-
return (0,
|
|
777
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure("replyToMessage", "AVAILABILITY", "too little of the Execute attempt is left to send safely, so nothing was sent"));
|
|
777
778
|
}
|
|
778
779
|
let credentials;
|
|
779
780
|
try {
|
|
@@ -800,9 +801,9 @@ var GmailSender = class {
|
|
|
800
801
|
if (found) return this.#sentMessage(call, budget, credentials, ReplyToMessageOutcomes, { raw: new Uint8Array(), recipients: [], requestedThreadId: "", hasPreSendSearch: true }, found, this.#receipt(call));
|
|
801
802
|
} catch {
|
|
802
803
|
await recordPreSendRetry(fence);
|
|
803
|
-
return (0,
|
|
804
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure("replyToMessage", "AVAILABILITY", "Gmail sent-mail search did not answer before the reply"));
|
|
804
805
|
}
|
|
805
|
-
if (fence.decide().kind === "readBackRequired") return (0,
|
|
806
|
+
if (fence.decide().kind === "readBackRequired") return (0, import_connectors_sdk4.newMutationRetry)(failure("replyToMessage", "AVAILABILITY", "Gmail reply outcome is unknown; the sent-mail search found no message"));
|
|
806
807
|
}
|
|
807
808
|
let source;
|
|
808
809
|
try {
|
|
@@ -825,16 +826,16 @@ var GmailSender = class {
|
|
|
825
826
|
try {
|
|
826
827
|
message = decodeGmailMessage(source.resource);
|
|
827
828
|
} catch {
|
|
828
|
-
return (0,
|
|
829
|
+
return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), this.#receipt(call, gmailRequestID(source.response.headers), input.messageId), failure("replyToMessage", "PROTOCOL", "source message lacks reply metadata"));
|
|
829
830
|
}
|
|
830
|
-
if (!message.threadId || !message.rfcMessageId) return (0,
|
|
831
|
+
if (!message.threadId || !message.rfcMessageId) return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), this.#receipt(call, gmailRequestID(source.response.headers), input.messageId), failure("replyToMessage", "PROTOCOL", "source message lacks reply metadata"));
|
|
831
832
|
let recipient;
|
|
832
833
|
try {
|
|
833
834
|
recipient = replyRecipient(message);
|
|
834
835
|
} catch {
|
|
835
|
-
return (0,
|
|
836
|
+
return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), this.#receipt(call, gmailRequestID(source.response.headers), input.messageId), failure("replyToMessage", "PROTOCOL", "Gmail returned an invalid source sender"));
|
|
836
837
|
}
|
|
837
|
-
if (/[\r\n]/.test(message.subject + message.rfcMessageId + (message.references ?? ""))) return (0,
|
|
838
|
+
if (/[\r\n]/.test(message.subject + message.rfcMessageId + (message.references ?? ""))) return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), this.#receipt(call, gmailRequestID(source.response.headers), input.messageId), failure("replyToMessage", "PROTOCOL", "Gmail returned invalid source reply headers"));
|
|
838
839
|
let raw;
|
|
839
840
|
try {
|
|
840
841
|
raw = buildReplyMIMEMessage(call.id, call.idempotencyKey ?? call.id, this.#messageID(call), credentials.primaryEmail, message, input);
|
|
@@ -863,18 +864,18 @@ var GmailSender = class {
|
|
|
863
864
|
if (found) return this.#sentMessage(call, budget, credentials, operation, message, found, this.#receipt(call));
|
|
864
865
|
} catch {
|
|
865
866
|
await recordPreSendRetry(fence);
|
|
866
|
-
return (0,
|
|
867
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, "AVAILABILITY", `Gmail sent-mail search did not answer before the ${operation.requestName}`));
|
|
867
868
|
}
|
|
868
869
|
}
|
|
869
|
-
if (fence.decide().kind === "readBackRequired") return (0,
|
|
870
|
+
if (fence.decide().kind === "readBackRequired") return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, "AVAILABILITY", `Gmail ${operation.requestName} outcome is unknown; the sent-mail search found no message`));
|
|
870
871
|
let response;
|
|
871
872
|
try {
|
|
872
873
|
response = await fence.dispatch((signal) => this.#provider.sendMessage(call, credentials, message.raw, message.requestedThreadId, signal));
|
|
873
874
|
} catch (error) {
|
|
874
|
-
if (error instanceof import_singledispatch.InsufficientTimeError || error instanceof import_singledispatch.CheckpointError) return (0,
|
|
875
|
+
if (error instanceof import_singledispatch.InsufficientTimeError || error instanceof import_singledispatch.CheckpointError) return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, "AVAILABILITY", "too little of the Execute attempt is left to send safely, so nothing was sent"));
|
|
875
876
|
if (error instanceof import_providerhttp2.ProviderTransportError && error.isProvablyNotSent || error instanceof import_providerhttp2.AddressRefusal) {
|
|
876
877
|
await recordSafeResend(fence);
|
|
877
|
-
return (0,
|
|
878
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, "TRANSPORT", `Gmail ${operation.requestName} request was not dispatched`));
|
|
878
879
|
}
|
|
879
880
|
if (error instanceof import_providerhttp2.BodyTooLargeError && error.status) return this.#classifySendStatus(call, fence, budget, credentials, operation, message, error.status, error.headers ?? {}, void 0);
|
|
880
881
|
return this.#confirmPossiblySent(call, budget, credentials, operation, message, "TRANSPORT", `Gmail ${operation.requestName} outcome is unknown`, this.#receipt(call));
|
|
@@ -905,7 +906,7 @@ var GmailSender = class {
|
|
|
905
906
|
} catch {
|
|
906
907
|
}
|
|
907
908
|
}
|
|
908
|
-
return (0,
|
|
909
|
+
return (0, import_connectors_sdk4.newMutationBranch)(operation.providerRejectedBranch, emptySend(), receipt, failure(operation.operationId, statusFailureKind(status), operation.rejectionMessage));
|
|
909
910
|
}
|
|
910
911
|
if (!sentResponse) {
|
|
911
912
|
const lookup = await this.#pollSentMessage(call, budget, credentials);
|
|
@@ -917,7 +918,7 @@ var GmailSender = class {
|
|
|
917
918
|
const lookup = await this.#pollSentMessage(call, budget, credentials);
|
|
918
919
|
if (lookup.sent) return this.#sentMessage(call, budget, credentials, operation, message, lookup.sent, receipt);
|
|
919
920
|
const suffix = lookup.hadError ? "the sent-mail search did not answer" : "the sent-mail search found no message";
|
|
920
|
-
return (0,
|
|
921
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation.operationId, kind, `${reason}; ${suffix}`));
|
|
921
922
|
}
|
|
922
923
|
async #sentMessage(call, budget, credentials, operation, message, sent, receipt) {
|
|
923
924
|
let threadId = sent.threadId;
|
|
@@ -929,7 +930,7 @@ var GmailSender = class {
|
|
|
929
930
|
threadId = message.requestedThreadId;
|
|
930
931
|
}
|
|
931
932
|
}
|
|
932
|
-
return (0,
|
|
933
|
+
return (0, import_connectors_sdk4.newMutationBranch)(operation.sentBranch, { sender: credentials.primaryEmail, recipients: message.recipients, messageId: sent.id, threadId }, { ...receipt, providerObjectId: sent.id });
|
|
933
934
|
}
|
|
934
935
|
async #pollSentMessage(call, budget, credentials) {
|
|
935
936
|
let hadError = false;
|
|
@@ -985,23 +986,23 @@ function emptySend() {
|
|
|
985
986
|
return { sender: "", recipients: [], messageId: "", threadId: "" };
|
|
986
987
|
}
|
|
987
988
|
function defect(operation, kind, message) {
|
|
988
|
-
return (0,
|
|
989
|
+
return (0, import_connectors_sdk4.newMutationBranch)("defect", emptySend(), (0, import_connectors_sdk4.zeroReceipt)(), failure(operation, kind, message));
|
|
989
990
|
}
|
|
990
991
|
function retryAfterRefusal(operation, kind, message, headers) {
|
|
991
992
|
try {
|
|
992
|
-
return (0,
|
|
993
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation, kind, message), gmailRetryAfterMs(headers));
|
|
993
994
|
} catch {
|
|
994
|
-
return (0,
|
|
995
|
+
return (0, import_connectors_sdk4.newMutationRetry)(failure(operation, "PROTOCOL", "Gmail returned an invalid Retry-After header"));
|
|
995
996
|
}
|
|
996
997
|
}
|
|
997
998
|
function classifySourceFailure(status, headers, receipt) {
|
|
998
999
|
if (status === 0 || status === 429 || status >= 500) return retryAfterRefusal("replyToMessage", "AVAILABILITY", "Gmail source message is temporarily unavailable", headers);
|
|
999
|
-
if (status >= 200 && status < 300) return (0,
|
|
1000
|
-
return (0,
|
|
1000
|
+
if (status >= 200 && status < 300) return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.InvalidResponse, emptySend(), receipt, failure("replyToMessage", "PROTOCOL", "Gmail returned an invalid source message response"));
|
|
1001
|
+
return (0, import_connectors_sdk4.newMutationBranch)(ReplyToMessageBranch.ProviderRejected, emptySend(), receipt, failure("replyToMessage", statusFailureKind(status), "Gmail rejected the source message lookup"));
|
|
1001
1002
|
}
|
|
1002
1003
|
|
|
1003
1004
|
// src/client.ts
|
|
1004
|
-
var
|
|
1005
|
+
var import_connectors_sdk5 = require("@superdurable/connectors-sdk");
|
|
1005
1006
|
var import_providerhttp3 = require("@superdurable/connectors-sdk/providerhttp");
|
|
1006
1007
|
var GmailClient = class {
|
|
1007
1008
|
#http;
|
|
@@ -1046,21 +1047,21 @@ var GetMessageOperation = class {
|
|
|
1046
1047
|
/** Classify one Gmail message read as a branch or safe retry. */
|
|
1047
1048
|
async invoke(call, input) {
|
|
1048
1049
|
if (!GetMessageInputSchema.safeParse(input).success || !input.messageId.trim()) {
|
|
1049
|
-
return (0,
|
|
1050
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.Defect, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "VALIDATION", "message ID is required"));
|
|
1050
1051
|
}
|
|
1051
1052
|
let credentials;
|
|
1052
1053
|
try {
|
|
1053
1054
|
credentials = await this.#http.resolveCredentials(call, call.context.cancellationSignal);
|
|
1054
1055
|
} catch {
|
|
1055
|
-
return (0,
|
|
1056
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.Defect, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "AUTHENTICATION", "connection credentials are unavailable"));
|
|
1056
1057
|
}
|
|
1057
1058
|
let result;
|
|
1058
1059
|
try {
|
|
1059
1060
|
result = await this.#provider.readMessage(call, credentials, input.messageId, "full", call.context.cancellationSignal);
|
|
1060
1061
|
} catch (error) {
|
|
1061
|
-
if (error instanceof GmailCredentialError) return (0,
|
|
1062
|
+
if (error instanceof GmailCredentialError) return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.Defect, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "AUTHENTICATION", "connection credentials are unavailable"));
|
|
1062
1063
|
if (error instanceof import_providerhttp3.BodyTooLargeError && error.status && error.status >= 200 && error.status < 300) {
|
|
1063
|
-
return (0,
|
|
1064
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.InvalidResponse, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "PROTOCOL", "Gmail returned an invalid or oversized message response"));
|
|
1064
1065
|
}
|
|
1065
1066
|
const status = error instanceof import_providerhttp3.BodyTooLargeError ? error.status ?? 0 : 0;
|
|
1066
1067
|
const headers = error instanceof import_providerhttp3.BodyTooLargeError ? error.headers ?? {} : {};
|
|
@@ -1071,9 +1072,9 @@ var GetMessageOperation = class {
|
|
|
1071
1072
|
try {
|
|
1072
1073
|
message = decodeGmailMessage(result.resource);
|
|
1073
1074
|
} catch {
|
|
1074
|
-
return (0,
|
|
1075
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.InvalidResponse, emptyMessage(), receiptFor(call, this.#now(), gmailRequestID(result.response.headers), input.messageId), gmailFailure("getMessage", "PROTOCOL", "Gmail returned an invalid message"));
|
|
1075
1076
|
}
|
|
1076
|
-
return (0,
|
|
1077
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.Read, message, {
|
|
1077
1078
|
provider: "gmail",
|
|
1078
1079
|
providerObjectId: message.messageId,
|
|
1079
1080
|
providerRequestId: gmailRequestID(result.response.headers),
|
|
@@ -1103,22 +1104,22 @@ function classifyReadFailure(status, headers) {
|
|
|
1103
1104
|
try {
|
|
1104
1105
|
retryAfterMs = gmailRetryAfterMs(headers);
|
|
1105
1106
|
} catch {
|
|
1106
|
-
return (0,
|
|
1107
|
+
return (0, import_connectors_sdk5.newQueryRetry)(gmailFailure("getMessage", "PROTOCOL", "Gmail returned an invalid Retry-After header"));
|
|
1107
1108
|
}
|
|
1108
|
-
return (0,
|
|
1109
|
+
return (0, import_connectors_sdk5.newQueryRetry)(gmailFailure("getMessage", "AVAILABILITY", "Gmail message is temporarily unavailable"), retryAfterMs);
|
|
1109
1110
|
}
|
|
1110
|
-
if (status === 404) return (0,
|
|
1111
|
+
if (status === 404) return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.NotFound, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)());
|
|
1111
1112
|
if (status >= 200 && status < 300) {
|
|
1112
|
-
return (0,
|
|
1113
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.InvalidResponse, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", "PROTOCOL", "Gmail returned an invalid or oversized message response"));
|
|
1113
1114
|
}
|
|
1114
|
-
return (0,
|
|
1115
|
+
return (0, import_connectors_sdk5.newQueryBranch)(GetMessageBranch.ProviderRejected, emptyMessage(), (0, import_connectors_sdk5.zeroReceipt)(), gmailFailure("getMessage", statusFailureKind(status), "Gmail message lookup failed"));
|
|
1115
1116
|
}
|
|
1116
1117
|
|
|
1117
1118
|
// src/connection.ts
|
|
1118
|
-
var
|
|
1119
|
+
var import_connectors_sdk7 = require("@superdurable/connectors-sdk");
|
|
1119
1120
|
|
|
1120
1121
|
// src/generated/connection.ts
|
|
1121
|
-
var
|
|
1122
|
+
var import_connectors_sdk6 = require("@superdurable/connectors-sdk");
|
|
1122
1123
|
var Connection = class {
|
|
1123
1124
|
/** Stable provider and connection name. */
|
|
1124
1125
|
reference;
|
|
@@ -1126,7 +1127,7 @@ var Connection = class {
|
|
|
1126
1127
|
operations;
|
|
1127
1128
|
/** Validate a reference and bind operations. */
|
|
1128
1129
|
constructor(reference, operations) {
|
|
1129
|
-
this.reference =
|
|
1130
|
+
this.reference = import_connectors_sdk6.ConnectionRefSchema.parse(reference);
|
|
1130
1131
|
if (this.reference.provider !== ProviderID2) throw new TypeError("connection provider differs from the manifest");
|
|
1131
1132
|
if (!operations) throw new TypeError("connector operations are required");
|
|
1132
1133
|
this.operations = operations;
|
|
@@ -1138,19 +1139,19 @@ var GmailConnection = class extends Connection {
|
|
|
1138
1139
|
/** Bind operation implementations to a static named Google connection. */
|
|
1139
1140
|
constructor(operations, reference) {
|
|
1140
1141
|
if (!operations) throw new TypeError("Gmail connector operations are required");
|
|
1141
|
-
const validatedReference =
|
|
1142
|
+
const validatedReference = import_connectors_sdk7.ConnectionRefSchema.parse(reference);
|
|
1142
1143
|
if (validatedReference.provider !== "google") throw new TypeError("Gmail connection provider must be google");
|
|
1143
1144
|
super(validatedReference, operations);
|
|
1144
1145
|
}
|
|
1145
1146
|
};
|
|
1146
1147
|
|
|
1147
1148
|
// src/project.ts
|
|
1148
|
-
var
|
|
1149
|
+
var import_connectors_sdk9 = require("@superdurable/connectors-sdk");
|
|
1149
1150
|
var import_projectconfig = require("@superdurable/connectors-sdk/projectconfig");
|
|
1150
1151
|
var import_zod7 = require("zod");
|
|
1151
1152
|
|
|
1152
1153
|
// src/credential_codec.ts
|
|
1153
|
-
var
|
|
1154
|
+
var import_connectors_sdk8 = require("@superdurable/connectors-sdk");
|
|
1154
1155
|
var import_zod6 = require("zod");
|
|
1155
1156
|
var StoredCredentialsSchema = import_zod6.z.object({
|
|
1156
1157
|
auth_method: import_zod6.z.string().optional(),
|
|
@@ -1188,11 +1189,11 @@ function decodeCredentialFields(value, isShared) {
|
|
|
1188
1189
|
const credentials = {
|
|
1189
1190
|
authMethodId: stored.auth_method || GoogleOAuthAuthMethodID,
|
|
1190
1191
|
oauthClientId: stored.oauth_client_id ?? "",
|
|
1191
|
-
oauthClientSecret: new
|
|
1192
|
-
accessToken: new
|
|
1193
|
-
refreshToken: new
|
|
1192
|
+
oauthClientSecret: new import_connectors_sdk8.SecretString(stored.oauth_client_secret ?? ""),
|
|
1193
|
+
accessToken: new import_connectors_sdk8.SecretString(stored.access_token ?? ""),
|
|
1194
|
+
refreshToken: new import_connectors_sdk8.SecretString(stored.refresh_token ?? ""),
|
|
1194
1195
|
primaryEmail: stored.primary_email ?? "",
|
|
1195
|
-
serviceAccountKey: new
|
|
1196
|
+
serviceAccountKey: new import_connectors_sdk8.SecretString(stored.service_account_key ?? ""),
|
|
1196
1197
|
delegatedUser: stored.delegated_user ?? ""
|
|
1197
1198
|
};
|
|
1198
1199
|
if (credentials.authMethodId === GoogleOAuthAuthMethodID) {
|
|
@@ -1220,7 +1221,7 @@ function newProjectConnection(project, connectionName, options = {}) {
|
|
|
1220
1221
|
}
|
|
1221
1222
|
function newProjectGmailClient(project, connectionName, options = {}) {
|
|
1222
1223
|
if (!project) throw new TypeError("Gmail connection requires the loaded project configuration");
|
|
1223
|
-
|
|
1224
|
+
import_connectors_sdk9.ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
|
|
1224
1225
|
const entry = project.configuration.connections.find((connection) => connection.connectorId === ConnectorID && connection.connectionName === connectionName);
|
|
1225
1226
|
if (!entry) throw new TypeError("Gmail project connection is not configured");
|
|
1226
1227
|
if (entry.provider !== ProviderID) throw new TypeError("Gmail project connection provider differs from the manifest");
|
|
@@ -1237,35 +1238,35 @@ function newProjectGmailClient(project, connectionName, options = {}) {
|
|
|
1237
1238
|
}
|
|
1238
1239
|
|
|
1239
1240
|
// src/generated/steps.ts
|
|
1240
|
-
var
|
|
1241
|
+
var import_connectors_sdk10 = require("@superdurable/connectors-sdk");
|
|
1241
1242
|
function newGetMessageStep(configuration) {
|
|
1242
1243
|
const { connection, connectionName, read, notFound, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
1243
1244
|
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1244
|
-
return (0,
|
|
1245
|
-
(0,
|
|
1246
|
-
...notFound ? [(0,
|
|
1247
|
-
...providerRejected ? [(0,
|
|
1248
|
-
...invalidResponse ? [(0,
|
|
1249
|
-
...defect2 ? [(0,
|
|
1245
|
+
return (0, import_connectors_sdk10.newQueryStep)({ ...stepConfiguration, operation: connection.operations.getMessage(), connection: connection.reference, branches: [
|
|
1246
|
+
(0, import_connectors_sdk10.goToBranch)("read", read),
|
|
1247
|
+
...notFound ? [(0, import_connectors_sdk10.goToBranch)("notFound", notFound)] : [],
|
|
1248
|
+
...providerRejected ? [(0, import_connectors_sdk10.goToBranch)("providerRejected", providerRejected)] : [],
|
|
1249
|
+
...invalidResponse ? [(0, import_connectors_sdk10.goToBranch)("invalidResponse", invalidResponse)] : [],
|
|
1250
|
+
...defect2 ? [(0, import_connectors_sdk10.goToBranch)("defect", defect2)] : []
|
|
1250
1251
|
] });
|
|
1251
1252
|
}
|
|
1252
1253
|
function newSendMessageStep(configuration) {
|
|
1253
1254
|
const { connection, connectionName, sent, providerRejected, defect: defect2, ...stepConfiguration } = configuration;
|
|
1254
1255
|
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1255
|
-
return (0,
|
|
1256
|
-
(0,
|
|
1257
|
-
...providerRejected ? [(0,
|
|
1258
|
-
...defect2 ? [(0,
|
|
1256
|
+
return (0, import_connectors_sdk10.newMutationStep)({ ...stepConfiguration, operation: connection.operations.sendMessage(), connection: connection.reference, branches: [
|
|
1257
|
+
(0, import_connectors_sdk10.goToBranch)("sent", sent),
|
|
1258
|
+
...providerRejected ? [(0, import_connectors_sdk10.goToBranch)("providerRejected", providerRejected)] : [],
|
|
1259
|
+
...defect2 ? [(0, import_connectors_sdk10.goToBranch)("defect", defect2)] : []
|
|
1259
1260
|
] });
|
|
1260
1261
|
}
|
|
1261
1262
|
function newReplyToMessageStep(configuration) {
|
|
1262
1263
|
const { connection, connectionName, sent, providerRejected, invalidResponse, defect: defect2, ...stepConfiguration } = configuration;
|
|
1263
1264
|
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1264
|
-
return (0,
|
|
1265
|
-
(0,
|
|
1266
|
-
...providerRejected ? [(0,
|
|
1267
|
-
...invalidResponse ? [(0,
|
|
1268
|
-
...defect2 ? [(0,
|
|
1265
|
+
return (0, import_connectors_sdk10.newMutationStep)({ ...stepConfiguration, operation: connection.operations.replyToMessage(), connection: connection.reference, branches: [
|
|
1266
|
+
(0, import_connectors_sdk10.goToBranch)("sent", sent),
|
|
1267
|
+
...providerRejected ? [(0, import_connectors_sdk10.goToBranch)("providerRejected", providerRejected)] : [],
|
|
1268
|
+
...invalidResponse ? [(0, import_connectors_sdk10.goToBranch)("invalidResponse", invalidResponse)] : [],
|
|
1269
|
+
...defect2 ? [(0, import_connectors_sdk10.goToBranch)("defect", defect2)] : []
|
|
1269
1270
|
] });
|
|
1270
1271
|
}
|
|
1271
1272
|
|
package/dist/index.js
CHANGED
package/dist/mock/index.cjs
CHANGED
|
@@ -55,6 +55,7 @@ var import_zod2 = require("zod");
|
|
|
55
55
|
|
|
56
56
|
// src/generated/models.ts
|
|
57
57
|
var import_zod = require("zod");
|
|
58
|
+
var import_connectors_sdk = require("@superdurable/connectors-sdk");
|
|
58
59
|
var ConfigSchema = import_zod.z.object({
|
|
59
60
|
"endpoint": import_zod.z.string().optional(),
|
|
60
61
|
"maxResponseBytes": import_zod.z.number().int().optional(),
|
|
@@ -196,7 +197,7 @@ var GmailMessageResourceSchema = import_zod3.z.object({
|
|
|
196
197
|
});
|
|
197
198
|
|
|
198
199
|
// src/http.ts
|
|
199
|
-
var
|
|
200
|
+
var import_connectors_sdk2 = require("@superdurable/connectors-sdk");
|
|
200
201
|
var import_providerhttp = require("@superdurable/connectors-sdk/providerhttp");
|
|
201
202
|
|
|
202
203
|
// src/provider.ts
|
|
@@ -205,13 +206,13 @@ var SentMessageSchema = import_zod4.z.object({ id: import_zod4.z.string().option
|
|
|
205
206
|
var SentSearchSchema = import_zod4.z.object({ messages: import_zod4.z.array(SentMessageSchema).nullish() });
|
|
206
207
|
|
|
207
208
|
// src/refresh.ts
|
|
208
|
-
var
|
|
209
|
+
var import_connectors_sdk3 = require("@superdurable/connectors-sdk");
|
|
209
210
|
var import_oauthtoken = require("@superdurable/connectors-sdk/oauthtoken");
|
|
210
211
|
var import_zod5 = require("zod");
|
|
211
212
|
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() });
|
|
212
213
|
|
|
213
214
|
// src/send.ts
|
|
214
|
-
var
|
|
215
|
+
var import_connectors_sdk4 = require("@superdurable/connectors-sdk");
|
|
215
216
|
var import_providerhttp2 = require("@superdurable/connectors-sdk/providerhttp");
|
|
216
217
|
var import_singledispatch = require("@superdurable/connectors-sdk/singledispatch");
|
|
217
218
|
var import_promises = require("timers/promises");
|
|
@@ -231,14 +232,14 @@ var ReplyToMessageOutcomes = {
|
|
|
231
232
|
};
|
|
232
233
|
|
|
233
234
|
// src/client.ts
|
|
234
|
-
var
|
|
235
|
+
var import_connectors_sdk5 = require("@superdurable/connectors-sdk");
|
|
235
236
|
var import_providerhttp3 = require("@superdurable/connectors-sdk/providerhttp");
|
|
236
237
|
|
|
237
238
|
// src/connection.ts
|
|
238
|
-
var
|
|
239
|
+
var import_connectors_sdk7 = require("@superdurable/connectors-sdk");
|
|
239
240
|
|
|
240
241
|
// src/generated/connection.ts
|
|
241
|
-
var
|
|
242
|
+
var import_connectors_sdk6 = require("@superdurable/connectors-sdk");
|
|
242
243
|
var Connection = class {
|
|
243
244
|
/** Stable provider and connection name. */
|
|
244
245
|
reference;
|
|
@@ -246,7 +247,7 @@ var Connection = class {
|
|
|
246
247
|
operations;
|
|
247
248
|
/** Validate a reference and bind operations. */
|
|
248
249
|
constructor(reference, operations) {
|
|
249
|
-
this.reference =
|
|
250
|
+
this.reference = import_connectors_sdk6.ConnectionRefSchema.parse(reference);
|
|
250
251
|
if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
|
|
251
252
|
if (!operations) throw new TypeError("connector operations are required");
|
|
252
253
|
this.operations = operations;
|
|
@@ -258,19 +259,19 @@ var GmailConnection = class extends Connection {
|
|
|
258
259
|
/** Bind operation implementations to a static named Google connection. */
|
|
259
260
|
constructor(operations, reference) {
|
|
260
261
|
if (!operations) throw new TypeError("Gmail connector operations are required");
|
|
261
|
-
const validatedReference =
|
|
262
|
+
const validatedReference = import_connectors_sdk7.ConnectionRefSchema.parse(reference);
|
|
262
263
|
if (validatedReference.provider !== "google") throw new TypeError("Gmail connection provider must be google");
|
|
263
264
|
super(validatedReference, operations);
|
|
264
265
|
}
|
|
265
266
|
};
|
|
266
267
|
|
|
267
268
|
// src/project.ts
|
|
268
|
-
var
|
|
269
|
+
var import_connectors_sdk9 = require("@superdurable/connectors-sdk");
|
|
269
270
|
var import_projectconfig = require("@superdurable/connectors-sdk/projectconfig");
|
|
270
271
|
var import_zod7 = require("zod");
|
|
271
272
|
|
|
272
273
|
// src/credential_codec.ts
|
|
273
|
-
var
|
|
274
|
+
var import_connectors_sdk8 = require("@superdurable/connectors-sdk");
|
|
274
275
|
var import_zod6 = require("zod");
|
|
275
276
|
var StoredCredentialsSchema = import_zod6.z.object({
|
|
276
277
|
auth_method: import_zod6.z.string().optional(),
|
|
@@ -293,7 +294,7 @@ var ProjectGmailConfigurationSchema = import_zod7.z.object({
|
|
|
293
294
|
});
|
|
294
295
|
|
|
295
296
|
// src/generated/steps.ts
|
|
296
|
-
var
|
|
297
|
+
var import_connectors_sdk10 = require("@superdurable/connectors-sdk");
|
|
297
298
|
|
|
298
299
|
// src/generated/mock.ts
|
|
299
300
|
var import_connectormock = require("@superdurable/connectors-sdk/connectormock");
|
package/dist/mock/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
SendMessageInputSchema,
|
|
11
11
|
SendMessageOutputSchema,
|
|
12
12
|
SendMessageOutputSchema2
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-IAO6TPJ3.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.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Dex Gmail connector for TypeScript",
|
|
6
6
|
"repository": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"check": "npm run typecheck && npm run test-d && npm run lint && npm test"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@superdurable/connectors-sdk": "0.1.
|
|
58
|
+
"@superdurable/connectors-sdk": "0.1.1",
|
|
59
59
|
"@superdurable/dex": ">=1.28.0",
|
|
60
60
|
"zod": "^4.1.0"
|
|
61
61
|
},
|