@superdurable/connector-google-gmail 0.0.0-stage → 0.1.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.
@@ -0,0 +1,275 @@
1
+ import { M as Message, R as ReplyToMessageInput, S as SendMessageInput, C as Config, a as CredentialSource, b as Credentials, c as SendMessageOutput, G as GetMessageInput, d as GmailOperations, e as GmailConnection } from './connection-ce8JHjE8.cjs';
2
+ export { f as ConnectorID, g as GetMessageInputSchema, h as GoogleOAuthAuthMethodID, i as MessageSchema, P as ProviderID, j as ReplyToMessageInputSchema, k as SendMessageInputSchema, l as SendMessageOutputSchema, W as WorkspaceDomainDelegationAuthMethodID } from './connection-ce8JHjE8.cjs';
3
+ import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
4
+ import { QueryDefinition, MutationDefinition, CredentialRefreshDriver, Call, FailureKind, CredentialRefreshState, CredentialRefreshResult, Mutation, MutationAttempt, Query, QueryAttempt, Failure, ReceiptDraft, QueryStepConfig, QueryResult, MutationStepConfig, MutationResult, QueryStep, MutationStep } from '@superdurable/connectors-sdk';
5
+ import { z } from 'zod';
6
+ import { ProviderRequest, ProviderResponse, AddressPolicy } from '@superdurable/connectors-sdk/providerhttp';
7
+ import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
8
+ import { StepTarget } from '@superdurable/dex';
9
+
10
+ /** Stable getMessage routes. */
11
+ declare const GetMessageBranch: {
12
+ readonly Read: "read";
13
+ readonly NotFound: "notFound";
14
+ readonly ProviderRejected: "providerRejected";
15
+ readonly InvalidResponse: "invalidResponse";
16
+ readonly Defect: "defect";
17
+ };
18
+ /** Stable sendMessage routes. */
19
+ declare const SendMessageBranch: {
20
+ readonly Sent: "sent";
21
+ readonly ProviderRejected: "providerRejected";
22
+ readonly Defect: "defect";
23
+ };
24
+ /** Stable replyToMessage routes. */
25
+ declare const ReplyToMessageBranch: {
26
+ readonly Sent: "sent";
27
+ readonly ProviderRejected: "providerRejected";
28
+ readonly InvalidResponse: "invalidResponse";
29
+ readonly Defect: "defect";
30
+ };
31
+ /** Manifest-derived getMessage definition. */
32
+ declare const GetMessageDefinition: QueryDefinition;
33
+ /** Manifest-derived sendMessage definition. */
34
+ declare const SendMessageDefinition: MutationDefinition;
35
+ /** Manifest-derived replyToMessage definition. */
36
+ declare const ReplyToMessageDefinition: MutationDefinition;
37
+
38
+ /** Provider message part with nested MIME children. */
39
+ interface GmailMessagePart {
40
+ /** MIME content type. */
41
+ mimeType?: string | null;
42
+ /** Message headers supplied on the root part. */
43
+ headers?: {
44
+ name: string;
45
+ value: string;
46
+ }[] | null;
47
+ /** Base64url-encoded body. */
48
+ body?: {
49
+ data?: string | null;
50
+ } | null;
51
+ /** Child parts of a multipart message. */
52
+ parts?: GmailMessagePart[] | null;
53
+ }
54
+ /** Gmail message resource required by the reader. */
55
+ declare const GmailMessageResourceSchema: z.ZodObject<{
56
+ id: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string, string | null | undefined>>;
57
+ threadId: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string, string | null | undefined>>;
58
+ labelIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
59
+ snippet: z.ZodOptional<z.ZodNullable<z.ZodString>>;
60
+ internalDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
61
+ payload: z.ZodOptional<z.ZodNullable<z.ZodType<GmailMessagePart, unknown, z.core.$ZodTypeInternals<GmailMessagePart, unknown>>>>;
62
+ }, z.core.$strip>;
63
+ /** Gmail message resource required by the reader. */
64
+ type GmailMessageResource = z.infer<typeof GmailMessageResourceSchema>;
65
+ /** Decode a Gmail full or metadata resource with the Go connector's message fields. */
66
+ declare function decodeGmailMessage(resource: GmailMessageResource): Message;
67
+ /** Parse one safe mailbox, rejecting ambiguous display-name separators. */
68
+ declare function parseMailbox(value: string): {
69
+ display: string;
70
+ address: string;
71
+ } | undefined;
72
+ /** Return the safe reply target, preferring Reply-To. */
73
+ declare function replyRecipient(message: Message): string;
74
+ /** Validate sender, recipients, subject, and body before sending. */
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;
78
+ /** Build the exact raw RFC 5322 request body shared by sends and replies. */
79
+ declare function buildMIMEMessage(callId: string, idempotencyKey: string, messageIdAddress: string, sender: string, recipients: string[], subject: string, textBody: string, htmlBody?: string, replyHeaders?: {
80
+ inReplyTo: string;
81
+ references: string;
82
+ }): Uint8Array;
83
+ /** Build a reply's subject and threading fields from its source message. */
84
+ declare function buildReplyMIMEMessage(callId: string, idempotencyKey: string, messageIdAddress: string, sender: string, source: Message, input: ReplyToMessageInput): Uint8Array;
85
+
86
+ /** Testable provider transport; production uses the SDK's pinned, bounded HTTP sender. */
87
+ type GmailTransport = (request: ProviderRequest) => Promise<ProviderResponse>;
88
+ /** Public Gmail client settings after applying manifest defaults. */
89
+ interface GmailClientSettings {
90
+ /** Validated API base URL. */ readonly endpoint: string;
91
+ /** Maximum complete response bytes. */ readonly maxResponseBytes: number;
92
+ /** Maximum encoded MIME message bytes. */ readonly maxMessageBytes: number;
93
+ /** Address policy for the configured endpoint. */ readonly addressPolicy: AddressPolicy;
94
+ }
95
+ /** Apply and validate the Gmail manifest's transport defaults. */
96
+ declare function gmailClientSettings(config?: Config): GmailClientSettings;
97
+ /** Failure after credential lookup or credential validation. */
98
+ declare class GmailCredentialError extends Error {
99
+ constructor();
100
+ }
101
+ /** Credential-safe HTTP client shared by all three operations. */
102
+ declare class GmailHTTPClient {
103
+ #private;
104
+ /** Inject settings, host-managed credential store, refresh driver, and optional test transport. */
105
+ constructor(config: Config, credentials: CredentialSource, refreshDriver: CredentialRefreshDriver<Credentials>, transport?: GmailTransport);
106
+ /** Return validated request and message bounds. */
107
+ settings(): GmailClientSettings;
108
+ /** Resolve a private token at call time; never put it in a receipt or Flow value. */
109
+ resolveCredentials(call: Call, signal?: AbortSignal): Promise<Credentials>;
110
+ /** Send one authenticated request, refreshing at most once after a 401. */
111
+ request(call: Call, credentials: Credentials, method: string, pathAndQuery: string, body?: Uint8Array, signal?: AbortSignal): Promise<{
112
+ response: ProviderResponse;
113
+ credentials: Credentials;
114
+ }>;
115
+ }
116
+ /** Map conclusive Gmail HTTP refusals to the Go connector's FailureKind. */
117
+ declare function statusFailureKind(status: number): FailureKind;
118
+ /** Parse Gmail's integer Retry-After seconds, rejecting malformed values. */
119
+ declare function gmailRetryAfterMs(headers: Record<string, string | string[] | undefined>): number;
120
+ /** Read the safe Gmail request correlation ID. */
121
+ declare function gmailRequestID(headers: Record<string, string | string[] | undefined>): string;
122
+
123
+ /** Provider identity returned by a Gmail send or Sent Mail lookup. */
124
+ interface SentMessageIdentity {
125
+ /** Gmail message ID. */ id: string;
126
+ /** Gmail thread ID, possibly empty in an accepted response. */ threadId: string;
127
+ }
128
+ /** One Gmail request result, including the response for precise classification. */
129
+ interface GmailReadResult {
130
+ /** Bounded HTTP response and status. */ response: ProviderResponse;
131
+ /** Credential after an optional 401 refresh. */ credentials: Credentials;
132
+ /** Parsed provider resource when HTTP and JSON are usable. */ resource?: GmailMessageResource;
133
+ }
134
+ /** Bounded provider API methods; classification belongs to connector operations. */
135
+ declare class GmailProvider {
136
+ #private;
137
+ /** Bind the shared authenticated transport. */
138
+ constructor(http: GmailHTTPClient);
139
+ /** Read one full or metadata message, returning the raw response on refusal or malformed JSON. */
140
+ readMessage(call: Call, credentials: Credentials, messageId: string, format: 'full' | 'metadata' | 'minimal', signal?: AbortSignal): Promise<GmailReadResult>;
141
+ /** Search Sent Mail once for the run-specific RFC Message-ID. */
142
+ findSentMessage(call: Call, credentials: Credentials, messageIdAddress: string, signal?: AbortSignal): Promise<SentMessageIdentity | undefined>;
143
+ /** Post one encoded Gmail messages.send request without redirects or transport replay. */
144
+ sendMessage(call: Call, credentials: Credentials, rawMessage: Uint8Array, threadId?: string, signal?: AbortSignal): Promise<{
145
+ response: ProviderResponse;
146
+ credentials: Credentials;
147
+ }>;
148
+ }
149
+ /** Parse one accepted Gmail send response. */
150
+ declare function parseSentResponse(response: ProviderResponse): SentMessageIdentity | undefined;
151
+
152
+ /** Refresh Gmail OAuth or Workspace delegation credentials without owning persistence. */
153
+ declare class GmailCredentialRefreshDriver implements CredentialRefreshDriver<Credentials> {
154
+ #private;
155
+ /** Inject the token request transport and clock for deterministic verification. */
156
+ constructor(fetchImplementation?: typeof fetch, now?: () => Date);
157
+ /** Refresh absent credentials or tokens whose expiry is within five minutes. */
158
+ refreshRequired(state: CredentialRefreshState<Credentials>): boolean;
159
+ /** Make one Google token exchange after the host admits and serializes refresh. */
160
+ refresh(state: CredentialRefreshState<Credentials>, signal: AbortSignal): Promise<CredentialRefreshResult<Credentials>>;
161
+ }
162
+
163
+ /** New-message Mutation bound to a Gmail client. */
164
+ declare class SendMessageOperation implements Mutation<SendMessageInput, SendMessageOutput> {
165
+ private readonly sender;
166
+ /** Inject the provider sender used by each Dex attempt. */
167
+ constructor(sender: GmailSender);
168
+ /** Return the immutable manifest operation definition. */
169
+ definition(): _superdurable_connectors_sdk.QueryDefinition;
170
+ /** Use the stable connector Call ID as the send correlation key. */
171
+ idempotencyKey(callId: string, input: SendMessageInput): string;
172
+ /** Classify a send using Dex's public current-attempt deadline. */
173
+ invoke(call: Call, input: SendMessageInput): Promise<MutationAttempt<SendMessageOutput>>;
174
+ }
175
+ /** Thread-reply Mutation bound to a Gmail client. */
176
+ declare class ReplyToMessageOperation implements Mutation<ReplyToMessageInput, SendMessageOutput> {
177
+ private readonly sender;
178
+ /** Inject the provider sender used by each Dex attempt. */
179
+ constructor(sender: GmailSender);
180
+ /** Return the immutable manifest operation definition. */
181
+ definition(): _superdurable_connectors_sdk.QueryDefinition;
182
+ /** Use the stable connector Call ID as the reply correlation key. */
183
+ idempotencyKey(callId: string, input: ReplyToMessageInput): string;
184
+ /** Classify a reply using Dex's public current-attempt deadline. */
185
+ invoke(call: Call, input: ReplyToMessageInput): Promise<MutationAttempt<SendMessageOutput>>;
186
+ }
187
+ /** Gmail send and reply logic with attempt-aware read-back reconciliation. */
188
+ declare class GmailSender {
189
+ #private;
190
+ /** Inject the shared authenticated provider client and observation clock. */
191
+ constructor(http: GmailHTTPClient, provider: GmailProvider, now?: () => Date);
192
+ /** Send one new message under the Dex attempt deadline. */
193
+ sendMessage(call: Call, input: SendMessageInput, dexDeadline: Date | undefined): Promise<MutationAttempt<SendMessageOutput>>;
194
+ /** Read the source then reply in its Gmail thread under the Dex attempt deadline. */
195
+ replyToMessage(call: Call, input: ReplyToMessageInput, dexDeadline: Date | undefined): Promise<MutationAttempt<SendMessageOutput>>;
196
+ }
197
+
198
+ /** Constructor-injected transport and credential refresh collaborators. */
199
+ interface GmailClientOptions {
200
+ /** Provider-specific renewal driver; defaults to Google OAuth and Workspace support. */
201
+ refreshDriver?: CredentialRefreshDriver<Credentials>;
202
+ /** Bounded HTTP transport override for provider fakes and controlled gateways. */
203
+ transport?: GmailTransport;
204
+ /** Observation clock for receipts. */
205
+ now?: () => Date;
206
+ }
207
+ /** Gmail connection with operation-specific provider interfaces. */
208
+ declare class GmailClient implements GmailOperations {
209
+ #private;
210
+ /** Validate settings and inject a host-owned credential source. */
211
+ constructor(config: Config, credentials: CredentialSource, options?: GmailClientOptions);
212
+ /** Return the getMessage Query bound to this connection. */
213
+ getMessage(): GetMessageOperation;
214
+ /** Return the sendMessage Mutation bound to this connection. */
215
+ sendMessage(): SendMessageOperation;
216
+ /** Return the replyToMessage Mutation bound to this connection. */
217
+ replyToMessage(): ReplyToMessageOperation;
218
+ }
219
+ /** Read and decode one Gmail message. */
220
+ declare class GetMessageOperation implements Query<GetMessageInput, Message> {
221
+ #private;
222
+ /** Inject authenticated transport and observation clock. */
223
+ constructor(http: GmailHTTPClient, provider: GmailProvider, now: () => Date);
224
+ /** Return the immutable manifest operation definition. */
225
+ definition(): _superdurable_connectors_sdk.QueryDefinition;
226
+ /** Classify one Gmail message read as a branch or safe retry. */
227
+ invoke(call: Call, input: GetMessageInput): Promise<QueryAttempt<Message>>;
228
+ }
229
+ /** Safe Gmail failure with no request or credential values. */
230
+ declare function gmailFailure(operation: string, kind: Failure['kind'], message: string): Failure;
231
+ /** Provider-safe receipt from one observed response. */
232
+ declare function receiptFor(call: Call, observedAt: Date, requestId?: string, objectId?: string): ReceiptDraft;
233
+ /** Go-compatible zero value used on failed operation branches. */
234
+ declare function emptyMessage(): Message;
235
+
236
+ /** Open one statically named Gmail connection from a loaded Dex project. */
237
+ declare function newProjectConnection(project: LoadedProject, connectionName: string, options?: GmailClientOptions): GmailConnection;
238
+ /** Bind startup-pinned settings to credentials refreshed in private project storage. */
239
+ declare function newProjectGmailClient(project: LoadedProject, connectionName: string, options?: GmailClientOptions): GmailClient;
240
+
241
+ /** Application wiring for one getMessage Query Step. */
242
+ interface GetMessageStepConfig<StepInput> extends Omit<QueryStepConfig<StepInput, GetMessageInput, Message>, 'operation' | 'connection' | 'branches'> {
243
+ /** Static name declared by the consuming application. */ connectionName: string;
244
+ /** Gmail provider or scripted mock connection. */ connection: GmailConnection;
245
+ /** Receiver for a successfully read message. */ read: StepTarget<QueryResult<Message>>;
246
+ /** Optional receiver for a missing message. */ notFound?: StepTarget<QueryResult<Message>>;
247
+ /** Optional receiver for a conclusive provider refusal. */ providerRejected?: StepTarget<QueryResult<Message>>;
248
+ /** Optional receiver for an invalid provider response. */ invalidResponse?: StepTarget<QueryResult<Message>>;
249
+ /** Optional receiver for a local defect. */ defect?: StepTarget<QueryResult<Message>>;
250
+ }
251
+ /** Application wiring for one sendMessage Mutation Step. */
252
+ interface SendMessageStepConfig<StepInput> extends Omit<MutationStepConfig<StepInput, SendMessageInput, SendMessageOutput>, 'operation' | 'connection' | 'branches'> {
253
+ /** Static name declared by the consuming application. */ connectionName: string;
254
+ /** Gmail provider or scripted mock connection. */ connection: GmailConnection;
255
+ /** Receiver after Gmail accepts the message. */ sent: StepTarget<MutationResult<SendMessageOutput>>;
256
+ /** Optional receiver for a conclusive provider refusal. */ providerRejected?: StepTarget<MutationResult<SendMessageOutput>>;
257
+ /** Optional receiver for a local defect. */ defect?: StepTarget<MutationResult<SendMessageOutput>>;
258
+ }
259
+ /** Application wiring for one replyToMessage Mutation Step. */
260
+ interface ReplyToMessageStepConfig<StepInput> extends Omit<MutationStepConfig<StepInput, ReplyToMessageInput, SendMessageOutput>, 'operation' | 'connection' | 'branches'> {
261
+ /** Static name declared by the consuming application. */ connectionName: string;
262
+ /** Gmail provider or scripted mock connection. */ connection: GmailConnection;
263
+ /** Receiver after Gmail accepts the reply. */ sent: StepTarget<MutationResult<SendMessageOutput>>;
264
+ /** Optional receiver for a conclusive provider refusal. */ providerRejected?: StepTarget<MutationResult<SendMessageOutput>>;
265
+ /** Optional receiver for an invalid source response. */ invalidResponse?: StepTarget<MutationResult<SendMessageOutput>>;
266
+ /** Optional receiver for a local defect. */ defect?: StepTarget<MutationResult<SendMessageOutput>>;
267
+ }
268
+ /** Construct the operation-specific Gmail message read Step. */
269
+ declare function newGetMessageStep<StepInput>(configuration: GetMessageStepConfig<StepInput>): QueryStep<StepInput, GetMessageInput, Message>;
270
+ /** Construct the operation-specific Gmail send Step. */
271
+ declare function newSendMessageStep<StepInput>(configuration: SendMessageStepConfig<StepInput>): MutationStep<StepInput, SendMessageInput, SendMessageOutput>;
272
+ /** Construct the operation-specific Gmail reply Step. */
273
+ declare function newReplyToMessageStep<StepInput>(configuration: ReplyToMessageStepConfig<StepInput>): MutationStep<StepInput, ReplyToMessageInput, SendMessageOutput>;
274
+
275
+ export { Config, CredentialSource, Credentials, GetMessageBranch, GetMessageDefinition, GetMessageInput, GetMessageOperation, type GetMessageStepConfig, GmailClient, type GmailClientOptions, type GmailClientSettings, GmailConnection, GmailCredentialError, GmailCredentialRefreshDriver, GmailHTTPClient, type GmailMessagePart, type GmailMessageResource, GmailMessageResourceSchema, GmailOperations, GmailProvider, type GmailReadResult, type GmailTransport, Message, ReplyToMessageBranch, ReplyToMessageDefinition, ReplyToMessageInput, ReplyToMessageOperation, type ReplyToMessageStepConfig, SendMessageBranch, SendMessageDefinition, SendMessageInput, SendMessageOperation, SendMessageOutput, type SendMessageStepConfig, type SentMessageIdentity, buildMIMEMessage, buildReplyMIMEMessage, decodeGmailMessage, emptyMessage, gmailClientSettings, gmailFailure, gmailRequestID, gmailRetryAfterMs, newGetMessageStep, newProjectConnection, newProjectGmailClient, newReplyToMessageStep, newSendMessageStep, parseMailbox, parseSentResponse, receiptFor, replyRecipient, rfcMessageIDAddress, statusFailureKind, validateSendInput };
@@ -0,0 +1,275 @@
1
+ import { M as Message, R as ReplyToMessageInput, S as SendMessageInput, C as Config, a as CredentialSource, b as Credentials, c as SendMessageOutput, G as GetMessageInput, d as GmailOperations, e as GmailConnection } from './connection-ce8JHjE8.js';
2
+ export { f as ConnectorID, g as GetMessageInputSchema, h as GoogleOAuthAuthMethodID, i as MessageSchema, P as ProviderID, j as ReplyToMessageInputSchema, k as SendMessageInputSchema, l as SendMessageOutputSchema, W as WorkspaceDomainDelegationAuthMethodID } from './connection-ce8JHjE8.js';
3
+ import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
4
+ import { QueryDefinition, MutationDefinition, CredentialRefreshDriver, Call, FailureKind, CredentialRefreshState, CredentialRefreshResult, Mutation, MutationAttempt, Query, QueryAttempt, Failure, ReceiptDraft, QueryStepConfig, QueryResult, MutationStepConfig, MutationResult, QueryStep, MutationStep } from '@superdurable/connectors-sdk';
5
+ import { z } from 'zod';
6
+ import { ProviderRequest, ProviderResponse, AddressPolicy } from '@superdurable/connectors-sdk/providerhttp';
7
+ import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
8
+ import { StepTarget } from '@superdurable/dex';
9
+
10
+ /** Stable getMessage routes. */
11
+ declare const GetMessageBranch: {
12
+ readonly Read: "read";
13
+ readonly NotFound: "notFound";
14
+ readonly ProviderRejected: "providerRejected";
15
+ readonly InvalidResponse: "invalidResponse";
16
+ readonly Defect: "defect";
17
+ };
18
+ /** Stable sendMessage routes. */
19
+ declare const SendMessageBranch: {
20
+ readonly Sent: "sent";
21
+ readonly ProviderRejected: "providerRejected";
22
+ readonly Defect: "defect";
23
+ };
24
+ /** Stable replyToMessage routes. */
25
+ declare const ReplyToMessageBranch: {
26
+ readonly Sent: "sent";
27
+ readonly ProviderRejected: "providerRejected";
28
+ readonly InvalidResponse: "invalidResponse";
29
+ readonly Defect: "defect";
30
+ };
31
+ /** Manifest-derived getMessage definition. */
32
+ declare const GetMessageDefinition: QueryDefinition;
33
+ /** Manifest-derived sendMessage definition. */
34
+ declare const SendMessageDefinition: MutationDefinition;
35
+ /** Manifest-derived replyToMessage definition. */
36
+ declare const ReplyToMessageDefinition: MutationDefinition;
37
+
38
+ /** Provider message part with nested MIME children. */
39
+ interface GmailMessagePart {
40
+ /** MIME content type. */
41
+ mimeType?: string | null;
42
+ /** Message headers supplied on the root part. */
43
+ headers?: {
44
+ name: string;
45
+ value: string;
46
+ }[] | null;
47
+ /** Base64url-encoded body. */
48
+ body?: {
49
+ data?: string | null;
50
+ } | null;
51
+ /** Child parts of a multipart message. */
52
+ parts?: GmailMessagePart[] | null;
53
+ }
54
+ /** Gmail message resource required by the reader. */
55
+ declare const GmailMessageResourceSchema: z.ZodObject<{
56
+ id: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string, string | null | undefined>>;
57
+ threadId: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string, string | null | undefined>>;
58
+ labelIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
59
+ snippet: z.ZodOptional<z.ZodNullable<z.ZodString>>;
60
+ internalDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
61
+ payload: z.ZodOptional<z.ZodNullable<z.ZodType<GmailMessagePart, unknown, z.core.$ZodTypeInternals<GmailMessagePart, unknown>>>>;
62
+ }, z.core.$strip>;
63
+ /** Gmail message resource required by the reader. */
64
+ type GmailMessageResource = z.infer<typeof GmailMessageResourceSchema>;
65
+ /** Decode a Gmail full or metadata resource with the Go connector's message fields. */
66
+ declare function decodeGmailMessage(resource: GmailMessageResource): Message;
67
+ /** Parse one safe mailbox, rejecting ambiguous display-name separators. */
68
+ declare function parseMailbox(value: string): {
69
+ display: string;
70
+ address: string;
71
+ } | undefined;
72
+ /** Return the safe reply target, preferring Reply-To. */
73
+ declare function replyRecipient(message: Message): string;
74
+ /** Validate sender, recipients, subject, and body before sending. */
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;
78
+ /** Build the exact raw RFC 5322 request body shared by sends and replies. */
79
+ declare function buildMIMEMessage(callId: string, idempotencyKey: string, messageIdAddress: string, sender: string, recipients: string[], subject: string, textBody: string, htmlBody?: string, replyHeaders?: {
80
+ inReplyTo: string;
81
+ references: string;
82
+ }): Uint8Array;
83
+ /** Build a reply's subject and threading fields from its source message. */
84
+ declare function buildReplyMIMEMessage(callId: string, idempotencyKey: string, messageIdAddress: string, sender: string, source: Message, input: ReplyToMessageInput): Uint8Array;
85
+
86
+ /** Testable provider transport; production uses the SDK's pinned, bounded HTTP sender. */
87
+ type GmailTransport = (request: ProviderRequest) => Promise<ProviderResponse>;
88
+ /** Public Gmail client settings after applying manifest defaults. */
89
+ interface GmailClientSettings {
90
+ /** Validated API base URL. */ readonly endpoint: string;
91
+ /** Maximum complete response bytes. */ readonly maxResponseBytes: number;
92
+ /** Maximum encoded MIME message bytes. */ readonly maxMessageBytes: number;
93
+ /** Address policy for the configured endpoint. */ readonly addressPolicy: AddressPolicy;
94
+ }
95
+ /** Apply and validate the Gmail manifest's transport defaults. */
96
+ declare function gmailClientSettings(config?: Config): GmailClientSettings;
97
+ /** Failure after credential lookup or credential validation. */
98
+ declare class GmailCredentialError extends Error {
99
+ constructor();
100
+ }
101
+ /** Credential-safe HTTP client shared by all three operations. */
102
+ declare class GmailHTTPClient {
103
+ #private;
104
+ /** Inject settings, host-managed credential store, refresh driver, and optional test transport. */
105
+ constructor(config: Config, credentials: CredentialSource, refreshDriver: CredentialRefreshDriver<Credentials>, transport?: GmailTransport);
106
+ /** Return validated request and message bounds. */
107
+ settings(): GmailClientSettings;
108
+ /** Resolve a private token at call time; never put it in a receipt or Flow value. */
109
+ resolveCredentials(call: Call, signal?: AbortSignal): Promise<Credentials>;
110
+ /** Send one authenticated request, refreshing at most once after a 401. */
111
+ request(call: Call, credentials: Credentials, method: string, pathAndQuery: string, body?: Uint8Array, signal?: AbortSignal): Promise<{
112
+ response: ProviderResponse;
113
+ credentials: Credentials;
114
+ }>;
115
+ }
116
+ /** Map conclusive Gmail HTTP refusals to the Go connector's FailureKind. */
117
+ declare function statusFailureKind(status: number): FailureKind;
118
+ /** Parse Gmail's integer Retry-After seconds, rejecting malformed values. */
119
+ declare function gmailRetryAfterMs(headers: Record<string, string | string[] | undefined>): number;
120
+ /** Read the safe Gmail request correlation ID. */
121
+ declare function gmailRequestID(headers: Record<string, string | string[] | undefined>): string;
122
+
123
+ /** Provider identity returned by a Gmail send or Sent Mail lookup. */
124
+ interface SentMessageIdentity {
125
+ /** Gmail message ID. */ id: string;
126
+ /** Gmail thread ID, possibly empty in an accepted response. */ threadId: string;
127
+ }
128
+ /** One Gmail request result, including the response for precise classification. */
129
+ interface GmailReadResult {
130
+ /** Bounded HTTP response and status. */ response: ProviderResponse;
131
+ /** Credential after an optional 401 refresh. */ credentials: Credentials;
132
+ /** Parsed provider resource when HTTP and JSON are usable. */ resource?: GmailMessageResource;
133
+ }
134
+ /** Bounded provider API methods; classification belongs to connector operations. */
135
+ declare class GmailProvider {
136
+ #private;
137
+ /** Bind the shared authenticated transport. */
138
+ constructor(http: GmailHTTPClient);
139
+ /** Read one full or metadata message, returning the raw response on refusal or malformed JSON. */
140
+ readMessage(call: Call, credentials: Credentials, messageId: string, format: 'full' | 'metadata' | 'minimal', signal?: AbortSignal): Promise<GmailReadResult>;
141
+ /** Search Sent Mail once for the run-specific RFC Message-ID. */
142
+ findSentMessage(call: Call, credentials: Credentials, messageIdAddress: string, signal?: AbortSignal): Promise<SentMessageIdentity | undefined>;
143
+ /** Post one encoded Gmail messages.send request without redirects or transport replay. */
144
+ sendMessage(call: Call, credentials: Credentials, rawMessage: Uint8Array, threadId?: string, signal?: AbortSignal): Promise<{
145
+ response: ProviderResponse;
146
+ credentials: Credentials;
147
+ }>;
148
+ }
149
+ /** Parse one accepted Gmail send response. */
150
+ declare function parseSentResponse(response: ProviderResponse): SentMessageIdentity | undefined;
151
+
152
+ /** Refresh Gmail OAuth or Workspace delegation credentials without owning persistence. */
153
+ declare class GmailCredentialRefreshDriver implements CredentialRefreshDriver<Credentials> {
154
+ #private;
155
+ /** Inject the token request transport and clock for deterministic verification. */
156
+ constructor(fetchImplementation?: typeof fetch, now?: () => Date);
157
+ /** Refresh absent credentials or tokens whose expiry is within five minutes. */
158
+ refreshRequired(state: CredentialRefreshState<Credentials>): boolean;
159
+ /** Make one Google token exchange after the host admits and serializes refresh. */
160
+ refresh(state: CredentialRefreshState<Credentials>, signal: AbortSignal): Promise<CredentialRefreshResult<Credentials>>;
161
+ }
162
+
163
+ /** New-message Mutation bound to a Gmail client. */
164
+ declare class SendMessageOperation implements Mutation<SendMessageInput, SendMessageOutput> {
165
+ private readonly sender;
166
+ /** Inject the provider sender used by each Dex attempt. */
167
+ constructor(sender: GmailSender);
168
+ /** Return the immutable manifest operation definition. */
169
+ definition(): _superdurable_connectors_sdk.QueryDefinition;
170
+ /** Use the stable connector Call ID as the send correlation key. */
171
+ idempotencyKey(callId: string, input: SendMessageInput): string;
172
+ /** Classify a send using Dex's public current-attempt deadline. */
173
+ invoke(call: Call, input: SendMessageInput): Promise<MutationAttempt<SendMessageOutput>>;
174
+ }
175
+ /** Thread-reply Mutation bound to a Gmail client. */
176
+ declare class ReplyToMessageOperation implements Mutation<ReplyToMessageInput, SendMessageOutput> {
177
+ private readonly sender;
178
+ /** Inject the provider sender used by each Dex attempt. */
179
+ constructor(sender: GmailSender);
180
+ /** Return the immutable manifest operation definition. */
181
+ definition(): _superdurable_connectors_sdk.QueryDefinition;
182
+ /** Use the stable connector Call ID as the reply correlation key. */
183
+ idempotencyKey(callId: string, input: ReplyToMessageInput): string;
184
+ /** Classify a reply using Dex's public current-attempt deadline. */
185
+ invoke(call: Call, input: ReplyToMessageInput): Promise<MutationAttempt<SendMessageOutput>>;
186
+ }
187
+ /** Gmail send and reply logic with attempt-aware read-back reconciliation. */
188
+ declare class GmailSender {
189
+ #private;
190
+ /** Inject the shared authenticated provider client and observation clock. */
191
+ constructor(http: GmailHTTPClient, provider: GmailProvider, now?: () => Date);
192
+ /** Send one new message under the Dex attempt deadline. */
193
+ sendMessage(call: Call, input: SendMessageInput, dexDeadline: Date | undefined): Promise<MutationAttempt<SendMessageOutput>>;
194
+ /** Read the source then reply in its Gmail thread under the Dex attempt deadline. */
195
+ replyToMessage(call: Call, input: ReplyToMessageInput, dexDeadline: Date | undefined): Promise<MutationAttempt<SendMessageOutput>>;
196
+ }
197
+
198
+ /** Constructor-injected transport and credential refresh collaborators. */
199
+ interface GmailClientOptions {
200
+ /** Provider-specific renewal driver; defaults to Google OAuth and Workspace support. */
201
+ refreshDriver?: CredentialRefreshDriver<Credentials>;
202
+ /** Bounded HTTP transport override for provider fakes and controlled gateways. */
203
+ transport?: GmailTransport;
204
+ /** Observation clock for receipts. */
205
+ now?: () => Date;
206
+ }
207
+ /** Gmail connection with operation-specific provider interfaces. */
208
+ declare class GmailClient implements GmailOperations {
209
+ #private;
210
+ /** Validate settings and inject a host-owned credential source. */
211
+ constructor(config: Config, credentials: CredentialSource, options?: GmailClientOptions);
212
+ /** Return the getMessage Query bound to this connection. */
213
+ getMessage(): GetMessageOperation;
214
+ /** Return the sendMessage Mutation bound to this connection. */
215
+ sendMessage(): SendMessageOperation;
216
+ /** Return the replyToMessage Mutation bound to this connection. */
217
+ replyToMessage(): ReplyToMessageOperation;
218
+ }
219
+ /** Read and decode one Gmail message. */
220
+ declare class GetMessageOperation implements Query<GetMessageInput, Message> {
221
+ #private;
222
+ /** Inject authenticated transport and observation clock. */
223
+ constructor(http: GmailHTTPClient, provider: GmailProvider, now: () => Date);
224
+ /** Return the immutable manifest operation definition. */
225
+ definition(): _superdurable_connectors_sdk.QueryDefinition;
226
+ /** Classify one Gmail message read as a branch or safe retry. */
227
+ invoke(call: Call, input: GetMessageInput): Promise<QueryAttempt<Message>>;
228
+ }
229
+ /** Safe Gmail failure with no request or credential values. */
230
+ declare function gmailFailure(operation: string, kind: Failure['kind'], message: string): Failure;
231
+ /** Provider-safe receipt from one observed response. */
232
+ declare function receiptFor(call: Call, observedAt: Date, requestId?: string, objectId?: string): ReceiptDraft;
233
+ /** Go-compatible zero value used on failed operation branches. */
234
+ declare function emptyMessage(): Message;
235
+
236
+ /** Open one statically named Gmail connection from a loaded Dex project. */
237
+ declare function newProjectConnection(project: LoadedProject, connectionName: string, options?: GmailClientOptions): GmailConnection;
238
+ /** Bind startup-pinned settings to credentials refreshed in private project storage. */
239
+ declare function newProjectGmailClient(project: LoadedProject, connectionName: string, options?: GmailClientOptions): GmailClient;
240
+
241
+ /** Application wiring for one getMessage Query Step. */
242
+ interface GetMessageStepConfig<StepInput> extends Omit<QueryStepConfig<StepInput, GetMessageInput, Message>, 'operation' | 'connection' | 'branches'> {
243
+ /** Static name declared by the consuming application. */ connectionName: string;
244
+ /** Gmail provider or scripted mock connection. */ connection: GmailConnection;
245
+ /** Receiver for a successfully read message. */ read: StepTarget<QueryResult<Message>>;
246
+ /** Optional receiver for a missing message. */ notFound?: StepTarget<QueryResult<Message>>;
247
+ /** Optional receiver for a conclusive provider refusal. */ providerRejected?: StepTarget<QueryResult<Message>>;
248
+ /** Optional receiver for an invalid provider response. */ invalidResponse?: StepTarget<QueryResult<Message>>;
249
+ /** Optional receiver for a local defect. */ defect?: StepTarget<QueryResult<Message>>;
250
+ }
251
+ /** Application wiring for one sendMessage Mutation Step. */
252
+ interface SendMessageStepConfig<StepInput> extends Omit<MutationStepConfig<StepInput, SendMessageInput, SendMessageOutput>, 'operation' | 'connection' | 'branches'> {
253
+ /** Static name declared by the consuming application. */ connectionName: string;
254
+ /** Gmail provider or scripted mock connection. */ connection: GmailConnection;
255
+ /** Receiver after Gmail accepts the message. */ sent: StepTarget<MutationResult<SendMessageOutput>>;
256
+ /** Optional receiver for a conclusive provider refusal. */ providerRejected?: StepTarget<MutationResult<SendMessageOutput>>;
257
+ /** Optional receiver for a local defect. */ defect?: StepTarget<MutationResult<SendMessageOutput>>;
258
+ }
259
+ /** Application wiring for one replyToMessage Mutation Step. */
260
+ interface ReplyToMessageStepConfig<StepInput> extends Omit<MutationStepConfig<StepInput, ReplyToMessageInput, SendMessageOutput>, 'operation' | 'connection' | 'branches'> {
261
+ /** Static name declared by the consuming application. */ connectionName: string;
262
+ /** Gmail provider or scripted mock connection. */ connection: GmailConnection;
263
+ /** Receiver after Gmail accepts the reply. */ sent: StepTarget<MutationResult<SendMessageOutput>>;
264
+ /** Optional receiver for a conclusive provider refusal. */ providerRejected?: StepTarget<MutationResult<SendMessageOutput>>;
265
+ /** Optional receiver for an invalid source response. */ invalidResponse?: StepTarget<MutationResult<SendMessageOutput>>;
266
+ /** Optional receiver for a local defect. */ defect?: StepTarget<MutationResult<SendMessageOutput>>;
267
+ }
268
+ /** Construct the operation-specific Gmail message read Step. */
269
+ declare function newGetMessageStep<StepInput>(configuration: GetMessageStepConfig<StepInput>): QueryStep<StepInput, GetMessageInput, Message>;
270
+ /** Construct the operation-specific Gmail send Step. */
271
+ declare function newSendMessageStep<StepInput>(configuration: SendMessageStepConfig<StepInput>): MutationStep<StepInput, SendMessageInput, SendMessageOutput>;
272
+ /** Construct the operation-specific Gmail reply Step. */
273
+ declare function newReplyToMessageStep<StepInput>(configuration: ReplyToMessageStepConfig<StepInput>): MutationStep<StepInput, ReplyToMessageInput, SendMessageOutput>;
274
+
275
+ export { Config, CredentialSource, Credentials, GetMessageBranch, GetMessageDefinition, GetMessageInput, GetMessageOperation, type GetMessageStepConfig, GmailClient, type GmailClientOptions, type GmailClientSettings, GmailConnection, GmailCredentialError, GmailCredentialRefreshDriver, GmailHTTPClient, type GmailMessagePart, type GmailMessageResource, GmailMessageResourceSchema, GmailOperations, GmailProvider, type GmailReadResult, type GmailTransport, Message, ReplyToMessageBranch, ReplyToMessageDefinition, ReplyToMessageInput, ReplyToMessageOperation, type ReplyToMessageStepConfig, SendMessageBranch, SendMessageDefinition, SendMessageInput, SendMessageOperation, SendMessageOutput, type SendMessageStepConfig, type SentMessageIdentity, buildMIMEMessage, buildReplyMIMEMessage, decodeGmailMessage, emptyMessage, gmailClientSettings, gmailFailure, gmailRequestID, gmailRetryAfterMs, newGetMessageStep, newProjectConnection, newProjectGmailClient, newReplyToMessageStep, newSendMessageStep, parseMailbox, parseSentResponse, receiptFor, replyRecipient, rfcMessageIDAddress, statusFailureKind, validateSendInput };
package/dist/index.js ADDED
@@ -0,0 +1,94 @@
1
+ import {
2
+ ConnectorID,
3
+ GetMessageBranch,
4
+ GetMessageDefinition,
5
+ GetMessageInputSchema,
6
+ GetMessageOperation,
7
+ GmailClient,
8
+ GmailConnection,
9
+ GmailCredentialError,
10
+ GmailCredentialRefreshDriver,
11
+ GmailHTTPClient,
12
+ GmailMessageResourceSchema,
13
+ GmailProvider,
14
+ GoogleOAuthAuthMethodID,
15
+ MessageSchema,
16
+ ProviderID,
17
+ ReplyToMessageBranch,
18
+ ReplyToMessageDefinition,
19
+ ReplyToMessageInputSchema,
20
+ ReplyToMessageOperation,
21
+ SendMessageBranch,
22
+ SendMessageDefinition,
23
+ SendMessageInputSchema,
24
+ SendMessageOperation,
25
+ SendMessageOutputSchema,
26
+ WorkspaceDomainDelegationAuthMethodID,
27
+ buildMIMEMessage,
28
+ buildReplyMIMEMessage,
29
+ decodeGmailMessage,
30
+ emptyMessage,
31
+ gmailClientSettings,
32
+ gmailFailure,
33
+ gmailRequestID,
34
+ gmailRetryAfterMs,
35
+ newGetMessageStep,
36
+ newProjectConnection,
37
+ newProjectGmailClient,
38
+ newReplyToMessageStep,
39
+ newSendMessageStep,
40
+ parseMailbox,
41
+ parseSentResponse,
42
+ receiptFor,
43
+ replyRecipient,
44
+ rfcMessageIDAddress,
45
+ statusFailureKind,
46
+ validateSendInput
47
+ } from "./chunk-C6LCJ6ZY.js";
48
+ export {
49
+ ConnectorID,
50
+ GetMessageBranch,
51
+ GetMessageDefinition,
52
+ GetMessageInputSchema,
53
+ GetMessageOperation,
54
+ GmailClient,
55
+ GmailConnection,
56
+ GmailCredentialError,
57
+ GmailCredentialRefreshDriver,
58
+ GmailHTTPClient,
59
+ GmailMessageResourceSchema,
60
+ GmailProvider,
61
+ GoogleOAuthAuthMethodID,
62
+ MessageSchema,
63
+ ProviderID,
64
+ ReplyToMessageBranch,
65
+ ReplyToMessageDefinition,
66
+ ReplyToMessageInputSchema,
67
+ ReplyToMessageOperation,
68
+ SendMessageBranch,
69
+ SendMessageDefinition,
70
+ SendMessageInputSchema,
71
+ SendMessageOperation,
72
+ SendMessageOutputSchema,
73
+ WorkspaceDomainDelegationAuthMethodID,
74
+ buildMIMEMessage,
75
+ buildReplyMIMEMessage,
76
+ decodeGmailMessage,
77
+ emptyMessage,
78
+ gmailClientSettings,
79
+ gmailFailure,
80
+ gmailRequestID,
81
+ gmailRetryAfterMs,
82
+ newGetMessageStep,
83
+ newProjectConnection,
84
+ newProjectGmailClient,
85
+ newReplyToMessageStep,
86
+ newSendMessageStep,
87
+ parseMailbox,
88
+ parseSentResponse,
89
+ receiptFor,
90
+ replyRecipient,
91
+ rfcMessageIDAddress,
92
+ statusFailureKind,
93
+ validateSendInput
94
+ };