@superdurable/connector-front 0.0.0-stage → 0.1.1

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,413 @@
1
+ // src/generated/models.ts
2
+ import { z } from "zod";
3
+ import { SecretString } from "@superdurable/connectors-sdk";
4
+ var goTimeJSONPattern = /^(\d{4})-(\d{2})-(\d{2})T(\d{1,2}):(\d{2}):(\d{2})(?:[.,](\d+))?(Z|([+-])(\d{2}):(\d{2}))$/;
5
+ function isGoTimeJSON(value) {
6
+ const match = goTimeJSONPattern.exec(value);
7
+ if (!match) return false;
8
+ const [, yearText, monthText, dayText, hourText, minuteText, secondText, , zone, , zoneHourText, zoneMinuteText] = match;
9
+ const year = Number(yearText);
10
+ const month = Number(monthText);
11
+ const day = Number(dayText);
12
+ const isLeap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
13
+ const monthDays = [31, isLeap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
14
+ return month >= 1 && month <= 12 && day >= 1 && day <= monthDays[month - 1] && Number(hourText) <= 23 && Number(minuteText) <= 59 && Number(secondText) <= 59 && (zone === "Z" || Number(zoneHourText) <= 24 && Number(zoneMinuteText) <= 60);
15
+ }
16
+ function canonicalGoTimeJSON(value) {
17
+ const match = goTimeJSONPattern.exec(value);
18
+ const [, year, month, day, hour, minute, second, fraction, zone, sign, zoneHour, zoneMinute] = match;
19
+ const clock = year + "-" + month + "-" + day + "T" + hour.padStart(2, "0") + ":" + minute + ":" + second;
20
+ const digits = (fraction ?? "").slice(0, 9).replace(/0+$/, "");
21
+ const offsetMinutes = zone === "Z" ? 0 : (Number(zoneHour) * 60 + Number(zoneMinute)) * (sign === "+" ? 1 : -1);
22
+ if (Math.abs(offsetMinutes) >= 1440) return value;
23
+ const offset = offsetMinutes === 0 ? "Z" : (offsetMinutes > 0 ? "+" : "-") + String(Math.floor(Math.abs(offsetMinutes) / 60)).padStart(2, "0") + ":" + String(Math.abs(offsetMinutes) % 60).padStart(2, "0");
24
+ return clock + (digits ? "." + digits : "") + offset;
25
+ }
26
+ var GoTimeJSONSchema = z.string().refine(isGoTimeJSON, "invalid Go time.Time JSON timestamp").transform(canonicalGoTimeJSON);
27
+ var ConfigSchema = z.object({
28
+ "maxResponseBytes": z.number().int().optional()
29
+ });
30
+ var CredentialMaterialError = class extends TypeError {
31
+ constructor(message) {
32
+ super(message);
33
+ this.name = "CredentialMaterialError";
34
+ }
35
+ };
36
+ var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
37
+ "project credential decoding failed",
38
+ "shared project credential decoding failed",
39
+ "project credential decoding failed: this connector version does not support shared credentials"
40
+ ]);
41
+ function isCredentialMaterialError(error) {
42
+ return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
43
+ }
44
+ function decodeCredentials(value) {
45
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
46
+ const fields = value;
47
+ const allowed = /* @__PURE__ */ new Set(["api_token"]);
48
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
49
+ if (fields["api_token"] != null && !(typeof fields["api_token"] === "string")) throw new CredentialMaterialError("credential api_token has an invalid type");
50
+ const credentials = {};
51
+ if (!fields["api_token"]) throw new CredentialMaterialError("credential api_token is required");
52
+ credentials.apiToken = new SecretString(fields["api_token"] ?? "");
53
+ return credentials;
54
+ }
55
+ var SearchConversationsInputSchema = z.strictObject({
56
+ "text": z.string().optional(),
57
+ "inboxId": z.string().optional(),
58
+ "tagId": z.string().optional(),
59
+ "statuses": z.array(z.string()).optional(),
60
+ "recipientEmail": z.string().optional(),
61
+ "assigneeId": z.string().optional(),
62
+ "activityAfter": GoTimeJSONSchema.nullable().optional(),
63
+ "pageSize": z.number().int().optional(),
64
+ "pageToken": z.string().optional()
65
+ });
66
+ var TeammateSchema = z.strictObject({
67
+ "id": z.string(),
68
+ "email": z.string().optional(),
69
+ "firstName": z.string().optional(),
70
+ "lastName": z.string().optional()
71
+ });
72
+ var RecipientSchema = z.strictObject({
73
+ "handle": z.string(),
74
+ "role": z.string().optional(),
75
+ "name": z.string().optional(),
76
+ "contactId": z.string().optional()
77
+ });
78
+ var TagSchema = z.strictObject({
79
+ "id": z.string(),
80
+ "name": z.string().optional()
81
+ });
82
+ var ConversationSchema = z.strictObject({
83
+ "id": z.string(),
84
+ "type": z.string().optional(),
85
+ "subject": z.string().optional(),
86
+ "status": z.string(),
87
+ "statusId": z.string().optional(),
88
+ "statusCategory": z.string().optional(),
89
+ "ticketIds": z.array(z.string()).optional(),
90
+ "assignee": TeammateSchema.optional(),
91
+ "recipient": RecipientSchema.optional(),
92
+ "tags": z.array(TagSchema).optional(),
93
+ "isPrivate": z.boolean().optional(),
94
+ "isSnoozed": z.boolean().optional(),
95
+ "createdAt": GoTimeJSONSchema,
96
+ "updatedAt": GoTimeJSONSchema.nullable().optional(),
97
+ "waitingSince": GoTimeJSONSchema.nullable().optional(),
98
+ "dueAt": GoTimeJSONSchema.nullable().optional()
99
+ });
100
+ var SearchConversationsOutputSchema = z.strictObject({
101
+ "conversations": z.array(ConversationSchema).nullable(),
102
+ "totalCount": z.number().int(),
103
+ "nextPageToken": z.string().optional(),
104
+ "query": z.string()
105
+ });
106
+ var GetConversationInputSchema = z.strictObject({
107
+ "conversationId": z.string(),
108
+ "messageLimit": z.number().int().optional(),
109
+ "commentLimit": z.number().int().optional()
110
+ });
111
+ var MessageSchema = z.strictObject({
112
+ "id": z.string(),
113
+ "type": z.string().optional(),
114
+ "isInbound": z.boolean(),
115
+ "isDraft": z.boolean().optional(),
116
+ "subject": z.string().optional(),
117
+ "blurb": z.string().optional(),
118
+ "body": z.string().optional(),
119
+ "isBodyTruncated": z.boolean().optional(),
120
+ "author": TeammateSchema.optional(),
121
+ "recipients": z.array(RecipientSchema).optional(),
122
+ "createdAt": GoTimeJSONSchema
123
+ });
124
+ var CommentSchema = z.strictObject({
125
+ "id": z.string(),
126
+ "body": z.string().optional(),
127
+ "isBodyTruncated": z.boolean().optional(),
128
+ "author": TeammateSchema.optional(),
129
+ "isPinned": z.boolean().optional(),
130
+ "postedAt": GoTimeJSONSchema
131
+ });
132
+ var ConversationDetailsSchema = z.strictObject({
133
+ "conversation": ConversationSchema,
134
+ "messages": z.array(MessageSchema).nullable(),
135
+ "hasOlderMessages": z.boolean().optional(),
136
+ "comments": z.array(CommentSchema).nullable(),
137
+ "hasOlderComments": z.boolean().optional(),
138
+ "mergedIntoConversationId": z.string().optional()
139
+ });
140
+ var ReplyToConversationInputSchema = z.strictObject({
141
+ "conversationId": z.string(),
142
+ "text": z.string(),
143
+ "isInternalNote": z.boolean().optional(),
144
+ "authorId": z.string().optional(),
145
+ "shouldArchive": z.boolean().optional()
146
+ });
147
+ var ConversationReplySchema = z.strictObject({
148
+ "conversationId": z.string(),
149
+ "isInternalNote": z.boolean().optional(),
150
+ "messageUid": z.string().optional(),
151
+ "commentId": z.string().optional(),
152
+ "authorId": z.string().optional()
153
+ });
154
+ var UpdateConversationInputSchema = z.strictObject({
155
+ "conversationId": z.string(),
156
+ "status": z.string().optional(),
157
+ "statusId": z.string().optional(),
158
+ "assigneeId": z.string().optional(),
159
+ "isUnassigned": z.boolean().optional(),
160
+ "addTagIds": z.array(z.string()).optional(),
161
+ "removeTagIds": z.array(z.string()).optional()
162
+ });
163
+ var UpdateConversationOutputSchema = z.strictObject({
164
+ "conversation": ConversationSchema,
165
+ "wasAlreadyApplied": z.boolean().optional()
166
+ });
167
+ var FindContactByEmailInputSchema = z.strictObject({
168
+ "email": z.string()
169
+ });
170
+ var ContactHandleSchema = z.strictObject({
171
+ "handle": z.string(),
172
+ "source": z.string()
173
+ });
174
+ var ContactSchema = z.strictObject({
175
+ "id": z.string(),
176
+ "name": z.string().optional(),
177
+ "description": z.string().optional(),
178
+ "handles": z.array(ContactHandleSchema).optional(),
179
+ "listNames": z.array(z.string()).optional(),
180
+ "isPrivate": z.boolean().optional(),
181
+ "updatedAt": GoTimeJSONSchema.nullable().optional()
182
+ });
183
+ var FindContactByEmailOutputSchema = z.strictObject({
184
+ "contacts": z.array(ContactSchema).nullable()
185
+ });
186
+
187
+ // src/generated/definitions.ts
188
+ var ConnectorID = "front";
189
+ var ProviderID = "front";
190
+ var SearchConversationsBranch = {
191
+ Searched: "searched",
192
+ ProviderRejected: "providerRejected",
193
+ InvalidResponse: "invalidResponse",
194
+ Defect: "defect"
195
+ };
196
+ var SearchConversationsBranchSearched = SearchConversationsBranch.Searched;
197
+ var SearchConversationsBranchProviderRejected = SearchConversationsBranch.ProviderRejected;
198
+ var SearchConversationsBranchInvalidResponse = SearchConversationsBranch.InvalidResponse;
199
+ var SearchConversationsBranchDefect = SearchConversationsBranch.Defect;
200
+ var SearchConversationsDefinition = {
201
+ operation: { connectorId: ConnectorID, operationId: "searchConversations" },
202
+ branches: [
203
+ { id: "searched", description: "Front returned one page of matching conversations; it may be empty." },
204
+ { id: "providerRejected", description: "Front conclusively rejected the search, such as an invalid token, a token without conversation read access, or an expired page token.", optional: true },
205
+ { id: "invalidResponse", description: "Front returned a malformed or oversized page, or a next-page link outside Front's API hosts.", optional: true },
206
+ { id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
207
+ ],
208
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
209
+ };
210
+ var SearchConversationsMetadata = { kind: "query", idempotency: "none", authorization: "required" };
211
+ var GetConversationBranch = {
212
+ Found: "found",
213
+ Merged: "merged",
214
+ NotFound: "notFound",
215
+ ProviderRejected: "providerRejected",
216
+ InvalidResponse: "invalidResponse",
217
+ Defect: "defect"
218
+ };
219
+ var GetConversationBranchFound = GetConversationBranch.Found;
220
+ var GetConversationBranchMerged = GetConversationBranch.Merged;
221
+ var GetConversationBranchNotFound = GetConversationBranch.NotFound;
222
+ var GetConversationBranchProviderRejected = GetConversationBranch.ProviderRejected;
223
+ var GetConversationBranchInvalidResponse = GetConversationBranch.InvalidResponse;
224
+ var GetConversationBranchDefect = GetConversationBranch.Defect;
225
+ var GetConversationDefinition = {
226
+ operation: { connectorId: ConnectorID, operationId: "getConversation" },
227
+ branches: [
228
+ { id: "found", description: "Front returned the conversation with its newest messages and comments." },
229
+ { id: "merged", description: "The conversation was merged into another; mergedIntoConversationId names the conversation to read instead.", optional: true },
230
+ { id: "notFound", description: "The conversation does not exist or is not visible to the API token.", optional: true },
231
+ { id: "providerRejected", description: "Front conclusively rejected the read, such as an invalid token or a token without message or comment read access.", optional: true },
232
+ { id: "invalidResponse", description: "Front returned a malformed or oversized conversation, message page, or comment list.", optional: true },
233
+ { id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
234
+ ],
235
+ stepDefaults: { executeMethodTimeoutMs: 45e3, executeDurability: "async" }
236
+ };
237
+ var GetConversationMetadata = { kind: "query", idempotency: "none", authorization: "required" };
238
+ var ReplyToConversationBranch = {
239
+ Replied: "replied",
240
+ NotFound: "notFound",
241
+ ProviderRejected: "providerRejected",
242
+ Uncertain: "uncertain",
243
+ Defect: "defect"
244
+ };
245
+ var ReplyToConversationBranchReplied = ReplyToConversationBranch.Replied;
246
+ var ReplyToConversationBranchNotFound = ReplyToConversationBranch.NotFound;
247
+ var ReplyToConversationBranchProviderRejected = ReplyToConversationBranch.ProviderRejected;
248
+ var ReplyToConversationBranchUncertain = ReplyToConversationBranch.Uncertain;
249
+ var ReplyToConversationBranchDefect = ReplyToConversationBranch.Defect;
250
+ var ReplyToConversationDefinition = {
251
+ operation: { connectorId: ConnectorID, operationId: "replyToConversation" },
252
+ branches: [
253
+ { id: "replied", description: "Front accepted the reply for delivery or created the comment." },
254
+ { id: "notFound", description: "The conversation does not exist or is not visible to the API token (HTTP 404); nothing was sent. A merged conversation's 301 is an unknown outcome instead.", optional: true },
255
+ { id: "providerRejected", description: "Front conclusively rejected the reply or comment, such as a token without send permission or an unknown author; nothing was sent.", optional: true },
256
+ { id: "uncertain", description: "The reply or comment may exist: the send cap is reached after answers that were lost, late, 409, a 3xx such as a merged conversation's 301, an unlisted status, an ambiguous server error, or a refusal with an unreadable body; Front accepted it with a 2xx that carries no usable provider ID; a refusal or a reconnection requirement follows a possible earlier send; or an accepted write could not be read back, such as after a terminal credential failure or a deleted comment. Without a provider ID, an unknown outcome is resent while the cap allows; a 2xx is never resent.", optional: true },
257
+ { id: "defect", description: "Local input, connection credentials that require reauthorization or are unusable before a first send, or the connector definition is invalid; transient credential failures Retry.", optional: true }
258
+ ],
259
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 1e3, backoffCoefficient: 2, maximumIntervalMs: 6e4, maximumAttempts: 5, totalDurationMs: 3e5 } },
260
+ repeatOnUnknown: "limited",
261
+ maxSends: 3
262
+ };
263
+ var ReplyToConversationMetadata = { kind: "mutation", idempotency: "required", authorization: "required" };
264
+ var UpdateConversationBranch = {
265
+ Updated: "updated",
266
+ NotFound: "notFound",
267
+ ProviderRejected: "providerRejected",
268
+ InvalidResponse: "invalidResponse",
269
+ Defect: "defect"
270
+ };
271
+ var UpdateConversationBranchUpdated = UpdateConversationBranch.Updated;
272
+ var UpdateConversationBranchNotFound = UpdateConversationBranch.NotFound;
273
+ var UpdateConversationBranchProviderRejected = UpdateConversationBranch.ProviderRejected;
274
+ var UpdateConversationBranchInvalidResponse = UpdateConversationBranch.InvalidResponse;
275
+ var UpdateConversationBranchDefect = UpdateConversationBranch.Defect;
276
+ var UpdateConversationDefinition = {
277
+ operation: { connectorId: ConnectorID, operationId: "updateConversation" },
278
+ branches: [
279
+ { id: "updated", description: "The conversation holds the requested status, assignee, and tags, written now or by an earlier attempt." },
280
+ { id: "notFound", description: "The conversation does not exist, was merged, or is not visible to the API token.", optional: true },
281
+ { id: "providerRejected", description: "Front conclusively rejected a change, such as an unknown teammate, tag, or ticket status; changes sent before it stay applied.", optional: true },
282
+ { id: "invalidResponse", description: "Declared for compatibility and no longer selected: an earlier attempt's change may have applied, so a malformed or oversized conversation on any read is retried.", optional: true },
283
+ { id: "defect", description: "Local input, connection configuration, or connector definition is invalid, or the connection needs reconnection on the first attempt; a transient credential failure, or one after an earlier attempt, Retries.", optional: true }
284
+ ],
285
+ stepDefaults: { executeMethodTimeoutMs: 6e4, executeDurability: "async" },
286
+ repeatOnUnknown: "safe"
287
+ };
288
+ var UpdateConversationMetadata = { kind: "mutation", idempotency: "required", authorization: "required" };
289
+ var FindContactByEmailBranch = {
290
+ Found: "found",
291
+ NotFound: "notFound",
292
+ ProviderRejected: "providerRejected",
293
+ InvalidResponse: "invalidResponse",
294
+ Defect: "defect"
295
+ };
296
+ var FindContactByEmailBranchFound = FindContactByEmailBranch.Found;
297
+ var FindContactByEmailBranchNotFound = FindContactByEmailBranch.NotFound;
298
+ var FindContactByEmailBranchProviderRejected = FindContactByEmailBranch.ProviderRejected;
299
+ var FindContactByEmailBranchInvalidResponse = FindContactByEmailBranch.InvalidResponse;
300
+ var FindContactByEmailBranchDefect = FindContactByEmailBranch.Defect;
301
+ var FindContactByEmailDefinition = {
302
+ operation: { connectorId: ConnectorID, operationId: "findContactByEmail" },
303
+ branches: [
304
+ { id: "found", description: "A Front contact has the email handle." },
305
+ { id: "notFound", description: "No Front contact has the email handle.", optional: true },
306
+ { id: "providerRejected", description: "Front conclusively rejected the lookup, such as an invalid token or a token without contact read access.", optional: true },
307
+ { id: "invalidResponse", description: "Front returned a malformed or oversized contact.", optional: true },
308
+ { id: "defect", description: "Local input, connection configuration, or connector definition is invalid.", optional: true }
309
+ ],
310
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
311
+ };
312
+ var FindContactByEmailMetadata = { kind: "query", idempotency: "none", authorization: "required" };
313
+
314
+ // src/generated/connection.ts
315
+ import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
316
+ var Connection = class {
317
+ /** Stable provider and connection name. */
318
+ reference;
319
+ /** Bound provider operations. */
320
+ operations;
321
+ /** Validate a reference and bind operations. */
322
+ constructor(reference, operations) {
323
+ this.reference = ConnectionRefSchema.parse(reference);
324
+ if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
325
+ if (!operations) throw new TypeError("connector operations are required");
326
+ this.operations = operations;
327
+ }
328
+ };
329
+ function newConnection(client, reference) {
330
+ if (!client) throw new TypeError("connector client is required");
331
+ return new Connection(reference, client);
332
+ }
333
+ function newConnectionWithOperations(operations, reference) {
334
+ return new Connection(reference, operations);
335
+ }
336
+ function newProjectConnection(project, connectionName, createClient) {
337
+ if (!project) throw new TypeError("loaded project is required");
338
+ const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
339
+ const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
340
+ if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
341
+ return newConnection(createClient(project, connectionName), reference);
342
+ }
343
+
344
+ export {
345
+ ConfigSchema,
346
+ CredentialMaterialError,
347
+ isCredentialMaterialError,
348
+ decodeCredentials,
349
+ SearchConversationsInputSchema,
350
+ TeammateSchema,
351
+ RecipientSchema,
352
+ TagSchema,
353
+ ConversationSchema,
354
+ SearchConversationsOutputSchema,
355
+ GetConversationInputSchema,
356
+ MessageSchema,
357
+ CommentSchema,
358
+ ConversationDetailsSchema,
359
+ ReplyToConversationInputSchema,
360
+ ConversationReplySchema,
361
+ UpdateConversationInputSchema,
362
+ UpdateConversationOutputSchema,
363
+ FindContactByEmailInputSchema,
364
+ ContactHandleSchema,
365
+ ContactSchema,
366
+ FindContactByEmailOutputSchema,
367
+ ConnectorID,
368
+ ProviderID,
369
+ SearchConversationsBranch,
370
+ SearchConversationsBranchSearched,
371
+ SearchConversationsBranchProviderRejected,
372
+ SearchConversationsBranchInvalidResponse,
373
+ SearchConversationsBranchDefect,
374
+ SearchConversationsDefinition,
375
+ SearchConversationsMetadata,
376
+ GetConversationBranch,
377
+ GetConversationBranchFound,
378
+ GetConversationBranchMerged,
379
+ GetConversationBranchNotFound,
380
+ GetConversationBranchProviderRejected,
381
+ GetConversationBranchInvalidResponse,
382
+ GetConversationBranchDefect,
383
+ GetConversationDefinition,
384
+ GetConversationMetadata,
385
+ ReplyToConversationBranch,
386
+ ReplyToConversationBranchReplied,
387
+ ReplyToConversationBranchNotFound,
388
+ ReplyToConversationBranchProviderRejected,
389
+ ReplyToConversationBranchUncertain,
390
+ ReplyToConversationBranchDefect,
391
+ ReplyToConversationDefinition,
392
+ ReplyToConversationMetadata,
393
+ UpdateConversationBranch,
394
+ UpdateConversationBranchUpdated,
395
+ UpdateConversationBranchNotFound,
396
+ UpdateConversationBranchProviderRejected,
397
+ UpdateConversationBranchInvalidResponse,
398
+ UpdateConversationBranchDefect,
399
+ UpdateConversationDefinition,
400
+ UpdateConversationMetadata,
401
+ FindContactByEmailBranch,
402
+ FindContactByEmailBranchFound,
403
+ FindContactByEmailBranchNotFound,
404
+ FindContactByEmailBranchProviderRejected,
405
+ FindContactByEmailBranchInvalidResponse,
406
+ FindContactByEmailBranchDefect,
407
+ FindContactByEmailDefinition,
408
+ FindContactByEmailMetadata,
409
+ Connection,
410
+ newConnection,
411
+ newConnectionWithOperations,
412
+ newProjectConnection
413
+ };