sendlit 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.
package/dist/index.js ADDED
@@ -0,0 +1,2875 @@
1
+ 'use strict';
2
+
3
+ var core = require('@ts-rest/core');
4
+ var zod = require('zod');
5
+
6
+ // src/errors.ts
7
+ var SendLitError = class extends Error {
8
+ constructor(init) {
9
+ super(init.message);
10
+ this.name = "SendLitError";
11
+ this.status = init.status;
12
+ this.code = init.code;
13
+ this.body = init.body;
14
+ this.headers = init.headers;
15
+ if (init.cause !== void 0) {
16
+ this.cause = init.cause;
17
+ }
18
+ }
19
+ static fromResponse(status, body, headers) {
20
+ const fields = body && typeof body === "object" ? body : {};
21
+ const text = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
22
+ const code = text(fields.error) ?? // ts-rest's request-validation 400s carry `message` + `*Errors`
23
+ // instead of an `error` code.
24
+ (status === 400 ? "validation_error" : `http_${status}`);
25
+ const message = text(fields.error_description) ?? text(fields.message) ?? text(fields.error) ?? (typeof body === "string" && body ? body : void 0) ?? `Request failed with status ${status}`;
26
+ return new SendLitError({ status, code, message, body, headers });
27
+ }
28
+ };
29
+ var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "PUT", "DELETE"]);
30
+ var MAX_RETRY_DELAY_MS = 3e4;
31
+ var HttpClient = class {
32
+ constructor(config) {
33
+ this.config = config;
34
+ }
35
+ /**
36
+ * Calls a route of `@sendlit/api-contract` — method, path and types all
37
+ * come from the contract, so the SDK can't drift from the server.
38
+ */
39
+ async request(route, args = {}) {
40
+ const url = this.config.endpoint + core.insertParamsIntoPath({
41
+ path: route.path,
42
+ params: args.params ?? {}
43
+ }) + core.convertQueryParamsToUrlString(args.query ?? {}, false);
44
+ const headers = {
45
+ accept: "application/json",
46
+ ...this.config.headers
47
+ };
48
+ let payload;
49
+ if (route.method !== "GET" && args.body !== void 0) {
50
+ headers["content-type"] = "application/json";
51
+ payload = JSON.stringify(args.body);
52
+ }
53
+ const retryServerErrors = args.retrySafe || IDEMPOTENT_METHODS.has(route.method);
54
+ for (let attempt = 0; ; attempt++) {
55
+ const canRetry = attempt < this.config.maxRetries;
56
+ let response;
57
+ try {
58
+ response = await this.send(url, route.method, headers, payload);
59
+ } catch (error) {
60
+ if (canRetry && retryServerErrors) {
61
+ await sleep(backoff(attempt));
62
+ continue;
63
+ }
64
+ throw error;
65
+ }
66
+ const body = await readBody(response);
67
+ if (response.ok)
68
+ return body;
69
+ const retryable = response.status === 429 || response.status >= 500 && retryServerErrors;
70
+ if (canRetry && retryable) {
71
+ await sleep(retryAfter(response.headers) ?? backoff(attempt));
72
+ continue;
73
+ }
74
+ throw SendLitError.fromResponse(
75
+ response.status,
76
+ body,
77
+ response.headers
78
+ );
79
+ }
80
+ }
81
+ async send(url, method, headers, body) {
82
+ const controller = new AbortController();
83
+ const timer = setTimeout(() => controller.abort(), this.config.timeout);
84
+ try {
85
+ return await this.config.fetch(url, {
86
+ method,
87
+ headers,
88
+ body,
89
+ signal: controller.signal
90
+ });
91
+ } catch (error) {
92
+ const timedOut = controller.signal.aborted;
93
+ throw new SendLitError({
94
+ status: 0,
95
+ code: timedOut ? "timeout" : "connection_error",
96
+ message: timedOut ? `Request timed out after ${this.config.timeout}ms` : `Could not reach SendLit at ${this.config.endpoint}`,
97
+ cause: error
98
+ });
99
+ } finally {
100
+ clearTimeout(timer);
101
+ }
102
+ }
103
+ };
104
+ async function readBody(response) {
105
+ if (response.status === 204)
106
+ return void 0;
107
+ const text = await response.text();
108
+ if (!text)
109
+ return void 0;
110
+ if (response.headers.get("content-type")?.includes("json")) {
111
+ try {
112
+ return JSON.parse(text);
113
+ } catch {
114
+ return text;
115
+ }
116
+ }
117
+ return text;
118
+ }
119
+ function backoff(attempt) {
120
+ const base = Math.min(500 * 2 ** attempt, MAX_RETRY_DELAY_MS);
121
+ return base * (0.75 + Math.random() * 0.25);
122
+ }
123
+ function retryAfter(headers) {
124
+ const value = headers.get("retry-after");
125
+ if (!value)
126
+ return void 0;
127
+ const seconds = Number(value);
128
+ const ms = Number.isFinite(seconds) ? seconds * 1e3 : Date.parse(value) - Date.now();
129
+ return Number.isFinite(ms) ? Math.min(Math.max(ms, 0), MAX_RETRY_DELAY_MS) : void 0;
130
+ }
131
+ function sleep(ms) {
132
+ return new Promise((resolve) => setTimeout(resolve, ms));
133
+ }
134
+ async function* paginate(fetchPage) {
135
+ let seen = 0;
136
+ for (let page = 1; ; page++) {
137
+ const { items, total } = await fetchPage(page);
138
+ for (const item of items)
139
+ yield item;
140
+ seen += items.length;
141
+ if (items.length === 0 || seen >= total)
142
+ return;
143
+ }
144
+ }
145
+ var errorSchema = zod.z.object({ error: zod.z.string() });
146
+ zod.z.object({ message: zod.z.string() });
147
+ var emailContentSchema = zod.z.object({
148
+ style: zod.z.record(zod.z.any()),
149
+ meta: zod.z.record(zod.z.any()),
150
+ content: zod.z.array(zod.z.record(zod.z.any()))
151
+ });
152
+ var cssColorSchema = zod.z.string().regex(
153
+ /^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i,
154
+ "Expected a hex color"
155
+ );
156
+ var pixelSchema = zod.z.string().regex(/^\d+(?:\.\d+)?px$/, "Expected a pixel value such as 16px");
157
+ var typographySectionSchema = zod.z.object({}).passthrough();
158
+ var emailStyleInputSchema = zod.z.object({
159
+ colors: zod.z.object({
160
+ background: cssColorSchema,
161
+ foreground: cssColorSchema,
162
+ border: cssColorSchema,
163
+ accent: cssColorSchema,
164
+ accentForeground: cssColorSchema
165
+ }).strict(),
166
+ typography: zod.z.object({
167
+ header: typographySectionSchema,
168
+ text: typographySectionSchema,
169
+ link: typographySectionSchema
170
+ }).strict(),
171
+ interactives: zod.z.object({
172
+ button: zod.z.object({
173
+ padding: zod.z.object({
174
+ x: pixelSchema.optional(),
175
+ y: pixelSchema.optional()
176
+ }).optional(),
177
+ border: zod.z.object({
178
+ width: pixelSchema.optional(),
179
+ radius: pixelSchema.optional(),
180
+ style: zod.z.string().min(1).optional()
181
+ }).optional()
182
+ }).passthrough(),
183
+ link: zod.z.object({
184
+ padding: zod.z.object({
185
+ x: pixelSchema.optional(),
186
+ y: pixelSchema.optional()
187
+ }).optional()
188
+ }).passthrough()
189
+ }).strict(),
190
+ structure: zod.z.object({
191
+ page: zod.z.object({
192
+ background: cssColorSchema.optional(),
193
+ foreground: cssColorSchema.optional(),
194
+ width: pixelSchema.optional(),
195
+ marginY: pixelSchema.optional(),
196
+ borderWidth: pixelSchema.optional(),
197
+ borderStyle: zod.z.string().min(1).optional(),
198
+ borderRadius: pixelSchema.optional()
199
+ }).strict(),
200
+ section: zod.z.object({
201
+ padding: zod.z.object({
202
+ x: pixelSchema.optional(),
203
+ y: pixelSchema.optional()
204
+ }).optional()
205
+ }).strict()
206
+ }).strict()
207
+ }).strict();
208
+ var blockBaseSchema = zod.z.object({
209
+ id: zod.z.string().optional(),
210
+ settings: zod.z.record(zod.z.any())
211
+ });
212
+ var emailBlockInputSchema = zod.z.discriminatedUnion("blockType", [
213
+ blockBaseSchema.extend({
214
+ blockType: zod.z.literal("text"),
215
+ settings: zod.z.object({ content: zod.z.string() }).passthrough()
216
+ }),
217
+ blockBaseSchema.extend({
218
+ blockType: zod.z.literal("link"),
219
+ settings: zod.z.object({ text: zod.z.string(), url: zod.z.string().min(1) }).passthrough()
220
+ }),
221
+ blockBaseSchema.extend({
222
+ blockType: zod.z.literal("image"),
223
+ settings: zod.z.object({ src: zod.z.string().min(1) }).passthrough()
224
+ }),
225
+ blockBaseSchema.extend({ blockType: zod.z.literal("separator") }),
226
+ blockBaseSchema.extend({ blockType: zod.z.literal("footer") })
227
+ ]);
228
+ var emailMetaInputSchema = zod.z.object({
229
+ previewText: zod.z.string().optional(),
230
+ utm: zod.z.object({
231
+ source: zod.z.string(),
232
+ medium: zod.z.string(),
233
+ campaign: zod.z.string()
234
+ }).strict().optional()
235
+ }).strict();
236
+ var emailContentInputSchema = zod.z.object({
237
+ style: emailStyleInputSchema,
238
+ meta: emailMetaInputSchema,
239
+ content: zod.z.array(emailBlockInputSchema)
240
+ });
241
+ function paginated(item) {
242
+ return zod.z.object({ items: zod.z.array(item), total: zod.z.number() });
243
+ }
244
+ function itemsList(item) {
245
+ return zod.z.object({ items: zod.z.array(item) });
246
+ }
247
+ var nullableLimit = zod.z.number().int().nonnegative().nullable();
248
+ var organizationDeliveryPolicySchema = zod.z.object({
249
+ defaultEspId: zod.z.string().nullable(),
250
+ autoGrantDefaultEsp: zod.z.boolean(),
251
+ defaultDailyLimit: nullableLimit,
252
+ defaultMonthlyLimit: nullableLimit,
253
+ aggregateDailyLimit: nullableLimit,
254
+ aggregateMonthlyLimit: nullableLimit,
255
+ teamEspEnabledByDefault: zod.z.boolean(),
256
+ teamCanChangeDefault: zod.z.boolean(),
257
+ updatedAt: zod.z.string()
258
+ });
259
+ var updateOrganizationDeliveryPolicyBodySchema = zod.z.object({
260
+ defaultEspId: zod.z.string().nullable().optional(),
261
+ autoGrantDefaultEsp: zod.z.boolean().optional(),
262
+ defaultDailyLimit: nullableLimit.optional(),
263
+ defaultMonthlyLimit: nullableLimit.optional(),
264
+ aggregateDailyLimit: nullableLimit.optional(),
265
+ aggregateMonthlyLimit: nullableLimit.optional(),
266
+ teamEspEnabledByDefault: zod.z.boolean().optional(),
267
+ teamCanChangeDefault: zod.z.boolean().optional()
268
+ }).refine((value) => Object.keys(value).length > 0, {
269
+ message: "At least one field is required"
270
+ });
271
+ var espGrantSchema = zod.z.object({
272
+ grantId: zod.z.string(),
273
+ teamId: zod.z.string(),
274
+ espId: zod.z.string(),
275
+ status: zod.z.enum(["active", "draining", "suspended", "revoked"]),
276
+ drainUntil: zod.z.string().nullable(),
277
+ fromName: zod.z.string().nullable(),
278
+ replyTo: zod.z.string().nullable(),
279
+ dailyLimit: nullableLimit,
280
+ monthlyLimit: nullableLimit,
281
+ createdAt: zod.z.string(),
282
+ updatedAt: zod.z.string()
283
+ });
284
+ var upsertEspGrantBodySchema = zod.z.object({
285
+ espId: zod.z.string(),
286
+ fromName: zod.z.string().nullable().optional(),
287
+ replyTo: zod.z.string().email().nullable().optional(),
288
+ dailyLimit: nullableLimit.optional(),
289
+ monthlyLimit: nullableLimit.optional(),
290
+ /** Organization owners/integrations may select the newly granted shared
291
+ * source as the team's default. This does not grant the team access to
292
+ * the ESP credentials. */
293
+ makeDefault: zod.z.boolean().optional()
294
+ });
295
+ var transitionEspGrantBodySchema = zod.z.discriminatedUnion("action", [
296
+ zod.z.object({ action: zod.z.literal("suspend") }),
297
+ zod.z.object({ action: zod.z.literal("resume") }),
298
+ zod.z.object({
299
+ action: zod.z.literal("drain"),
300
+ drainUntil: zod.z.string().datetime().optional()
301
+ }),
302
+ zod.z.object({ action: zod.z.literal("cancel") })
303
+ ]);
304
+ var teamDeliverySettingsSchema = zod.z.object({
305
+ teamEspEnabled: zod.z.boolean(),
306
+ teamCanChangeDefault: zod.z.boolean(),
307
+ defaultSource: zod.z.enum(["organization", "team"]).nullable(),
308
+ defaultTeamEspId: zod.z.string().nullable(),
309
+ updatedAt: zod.z.string()
310
+ });
311
+ var updateTeamDeliverySettingsBodySchema = zod.z.object({
312
+ deliverySource: zod.z.discriminatedUnion("type", [
313
+ zod.z.object({ type: zod.z.literal("organization") }),
314
+ zod.z.object({ type: zod.z.literal("team"), espId: zod.z.string() })
315
+ ])
316
+ });
317
+ var deliverySourceSelectionSchema = zod.z.discriminatedUnion("type", [
318
+ zod.z.object({ type: zod.z.literal("organization") }),
319
+ zod.z.object({
320
+ type: zod.z.literal("team"),
321
+ espId: zod.z.string().min(1).optional()
322
+ })
323
+ ]);
324
+ var sendingOptionSchema = zod.z.discriminatedUnion("type", [
325
+ zod.z.object({
326
+ type: zod.z.literal("organization"),
327
+ name: zod.z.string(),
328
+ fromName: zod.z.string().nullable(),
329
+ fromEmail: zod.z.string().nullable(),
330
+ replyTo: zod.z.string().nullable(),
331
+ isDefault: zod.z.boolean(),
332
+ available: zod.z.boolean(),
333
+ countsAgainstQuota: zod.z.literal(true)
334
+ }),
335
+ zod.z.object({
336
+ type: zod.z.literal("team"),
337
+ espId: zod.z.string(),
338
+ name: zod.z.string(),
339
+ fromName: zod.z.string().nullable(),
340
+ fromEmail: zod.z.string().nullable(),
341
+ isDefault: zod.z.boolean(),
342
+ available: zod.z.boolean(),
343
+ countsAgainstQuota: zod.z.literal(false)
344
+ })
345
+ ]);
346
+ var mailTypes = ["broadcast", "sequence"];
347
+ var emailActionTypes = ["tag:add", "tag:remove"];
348
+ var sequenceEmailSchema = zod.z.object({
349
+ // NOTE: intentionally no `id`/`sequenceId` here — `sequence_emails.id` is
350
+ // internal-only, and its `sequence_id` column holds the *parent*
351
+ // sequence's internal id (see `db/schema.ts`), not a public identifier.
352
+ emailId: zod.z.string(),
353
+ subject: zod.z.string(),
354
+ content: emailContentSchema,
355
+ delayInMillis: zod.z.number(),
356
+ published: zod.z.boolean(),
357
+ templateId: zod.z.string().nullable().optional(),
358
+ // Plain string (see `contactSchema.lead`'s comment) — validated on write.
359
+ actionType: zod.z.string().nullable().optional(),
360
+ actionData: zod.z.record(zod.z.any()).nullable().optional(),
361
+ createdAt: zod.z.string().nullable(),
362
+ updatedAt: zod.z.string().nullable()
363
+ });
364
+ var filterValueLabelSchema = zod.z.object({
365
+ valueLabel: zod.z.string().optional()
366
+ });
367
+ var contactFilterConditionSchema = zod.z.union([
368
+ zod.z.object({
369
+ name: zod.z.literal("email"),
370
+ condition: zod.z.enum(["is", "contains", "not_contains"]),
371
+ value: zod.z.string()
372
+ }).merge(filterValueLabelSchema),
373
+ zod.z.object({
374
+ name: zod.z.literal("tag"),
375
+ condition: zod.z.enum(["is", "is_not"]),
376
+ value: zod.z.string()
377
+ }).merge(filterValueLabelSchema),
378
+ zod.z.object({
379
+ name: zod.z.literal("subscription"),
380
+ condition: zod.z.literal("is"),
381
+ value: zod.z.enum(["subscribed", "unsubscribed"])
382
+ }).merge(filterValueLabelSchema),
383
+ zod.z.object({
384
+ name: zod.z.literal("signedUp"),
385
+ condition: zod.z.enum(["before", "after", "on"]),
386
+ value: zod.z.string().refine((value) => Number.isFinite(Number(value)), {
387
+ message: "Expected a millisecond timestamp string"
388
+ })
389
+ }).merge(filterValueLabelSchema),
390
+ zod.z.object({
391
+ name: zod.z.literal("customField"),
392
+ key: zod.z.string().min(1),
393
+ condition: zod.z.enum([
394
+ "is",
395
+ "is_not",
396
+ "contains",
397
+ "not_contains",
398
+ "has",
399
+ "not_has",
400
+ "before",
401
+ "after",
402
+ "on",
403
+ "exists",
404
+ "not_exists"
405
+ ]),
406
+ value: zod.z.string().optional()
407
+ }).merge(filterValueLabelSchema).superRefine((filter, ctx) => {
408
+ if (!["exists", "not_exists"].includes(filter.condition) && typeof filter.value !== "string") {
409
+ ctx.addIssue({
410
+ code: zod.z.ZodIssueCode.custom,
411
+ message: "Expected a value for this custom field filter",
412
+ path: ["value"]
413
+ });
414
+ }
415
+ })
416
+ ]);
417
+ var contactFilterSchema = zod.z.object({
418
+ aggregator: zod.z.enum(["and", "or"]),
419
+ filters: zod.z.array(contactFilterConditionSchema)
420
+ });
421
+ zod.z.object({
422
+ broadcast: zod.z.object({
423
+ sentAt: zod.z.number().nullable(),
424
+ lockedAt: zod.z.number().nullable()
425
+ }).optional(),
426
+ sequence: zod.z.object({
427
+ subscribers: zod.z.array(zod.z.string()).optional(),
428
+ unsubscribers: zod.z.array(zod.z.string()).optional(),
429
+ failed: zod.z.array(zod.z.string()).optional()
430
+ }).optional()
431
+ });
432
+ var sequenceSchema = zod.z.object({
433
+ sequenceId: zod.z.string(),
434
+ // Plain strings (see `contactSchema.lead`'s comment) — validated on write.
435
+ type: zod.z.string(),
436
+ title: zod.z.string(),
437
+ status: zod.z.string(),
438
+ deliverySource: deliverySourceSelectionSchema.nullable(),
439
+ triggerType: zod.z.string().nullable().optional(),
440
+ triggerData: zod.z.string().nullable().optional(),
441
+ filter: zod.z.any().nullable().optional(),
442
+ excludeFilter: zod.z.any().nullable().optional(),
443
+ emailsOrder: zod.z.array(zod.z.string()),
444
+ entrants: zod.z.array(zod.z.string()),
445
+ report: zod.z.any(),
446
+ createdAt: zod.z.string().nullable(),
447
+ updatedAt: zod.z.string().nullable(),
448
+ emails: zod.z.array(sequenceEmailSchema)
449
+ });
450
+ var listSequencesQuerySchema = zod.z.object({
451
+ type: zod.z.enum(mailTypes),
452
+ offset: zod.z.coerce.number().int().min(1).optional(),
453
+ itemsPerPage: zod.z.coerce.number().int().min(1).max(50).optional()
454
+ });
455
+ var createSequenceBodySchema = zod.z.object({
456
+ type: zod.z.enum(mailTypes),
457
+ templateId: zod.z.string().min(1),
458
+ deliverySource: deliverySourceSelectionSchema.optional()
459
+ });
460
+ var updateSequenceBodySchema = zod.z.object({
461
+ title: zod.z.string().optional(),
462
+ triggerType: zod.z.string().optional(),
463
+ triggerData: zod.z.string().optional(),
464
+ filter: contactFilterSchema.optional(),
465
+ emailsOrder: zod.z.array(zod.z.string()).optional(),
466
+ /** `null` clears the intent so the default is resolved on next start. */
467
+ deliverySource: deliverySourceSelectionSchema.nullable().optional()
468
+ });
469
+ var addSequenceEmailBodySchema = zod.z.object({
470
+ templateId: zod.z.string().min(1)
471
+ });
472
+ var updateSequenceEmailBodySchema = zod.z.object({
473
+ subject: zod.z.string().optional(),
474
+ content: emailContentInputSchema.optional(),
475
+ delayInMillis: zod.z.number().optional(),
476
+ templateId: zod.z.string().min(1).optional(),
477
+ actionType: zod.z.enum(emailActionTypes).optional(),
478
+ actionData: zod.z.record(zod.z.any()).optional(),
479
+ published: zod.z.boolean().optional()
480
+ });
481
+ var sequenceStatsSchema = zod.z.object({
482
+ sent: zod.z.number(),
483
+ openRate: zod.z.number(),
484
+ clickThroughRate: zod.z.number(),
485
+ subscribersCount: zod.z.number()
486
+ });
487
+ var listSubscribersQuerySchema = zod.z.object({
488
+ page: zod.z.coerce.number().int().min(1).optional(),
489
+ limit: zod.z.coerce.number().int().min(1).optional()
490
+ });
491
+ var customFieldScalarSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]);
492
+ var customFieldValueSchema = zod.z.union([
493
+ customFieldScalarSchema,
494
+ zod.z.array(customFieldScalarSchema)
495
+ ]);
496
+ var customFieldsSchema = zod.z.record(customFieldValueSchema).default({});
497
+ var contactSchema = zod.z.object({
498
+ contactId: zod.z.string(),
499
+ email: zod.z.string(),
500
+ name: zod.z.string().nullable().optional(),
501
+ subscribed: zod.z.boolean(),
502
+ customFields: customFieldsSchema,
503
+ tags: zod.z.array(zod.z.string()),
504
+ unsubscribeToken: zod.z.string(),
505
+ createdAt: zod.z.string().nullable(),
506
+ updatedAt: zod.z.string().nullable()
507
+ });
508
+ var createContactBodySchema = zod.z.object({
509
+ email: zod.z.string().email(),
510
+ name: zod.z.string().optional(),
511
+ tags: zod.z.array(zod.z.string()).optional(),
512
+ customFields: customFieldsSchema.optional()
513
+ });
514
+ var updateContactBodySchema = zod.z.object({
515
+ name: zod.z.string().optional(),
516
+ subscribed: zod.z.boolean().optional(),
517
+ tags: zod.z.array(zod.z.string()).optional(),
518
+ customFields: customFieldsSchema.optional()
519
+ });
520
+ var listContactsQuerySchema = zod.z.object({
521
+ q: zod.z.string().optional().describe("Search term matched against email or name"),
522
+ segmentId: zod.z.string().optional().describe(
523
+ "Only return contacts matching this saved segment's filter; combines with q using AND"
524
+ ),
525
+ filter: zod.z.string().optional().describe(
526
+ "Serialized ContactFilterWithAggregator JSON; combines with q and segmentId using AND"
527
+ ),
528
+ offset: zod.z.coerce.number().int().min(1).optional(),
529
+ rowsPerPage: zod.z.coerce.number().int().min(1).optional()
530
+ });
531
+ zod.z.object({
532
+ sequenceId: zod.z.string(),
533
+ sequenceTitle: zod.z.string(),
534
+ sequenceType: zod.z.string(),
535
+ emailId: zod.z.string(),
536
+ createdAt: zod.z.string().nullable()
537
+ });
538
+ var templatePurposes = ["marketing", "transactional"];
539
+ var templatePurposeSchema = zod.z.enum(templatePurposes).describe(
540
+ "Immutable sending purpose. Marketing templates require a final managed footer; transactional templates are footer-free and are valid for POST /emails."
541
+ );
542
+ var templateVariableDefinitionSchema = zod.z.object({
543
+ path: zod.z.string().min(1).describe("Dot-separated Liquid variable path."),
544
+ description: zod.z.string().describe("Human-readable value description."),
545
+ example: zod.z.any().describe("Example value used in generated requests.")
546
+ });
547
+ var emailTemplateSchema = zod.z.object({
548
+ templateId: zod.z.string(),
549
+ title: zod.z.string(),
550
+ purpose: templatePurposeSchema,
551
+ content: emailContentSchema,
552
+ requiredVariables: zod.z.array(zod.z.string()).describe(
553
+ "Sorted, server-discovered Liquid paths that must be supplied. Defaults and inactive guarded branches are omitted."
554
+ ),
555
+ validationError: zod.z.string().optional().describe(
556
+ "Present only for a retired template that predates the managed-footer format. It cannot be edited, duplicated, or sent; recreate it instead."
557
+ ),
558
+ createdAt: zod.z.string().nullable(),
559
+ updatedAt: zod.z.string().nullable()
560
+ });
561
+ var createTemplateBodySchema = zod.z.object({
562
+ title: zod.z.string().min(1),
563
+ purpose: templatePurposeSchema.default("marketing"),
564
+ content: emailContentInputSchema
565
+ });
566
+ var updateTemplateBodySchema = zod.z.object({
567
+ title: zod.z.string().min(1).optional(),
568
+ content: emailContentInputSchema.optional()
569
+ });
570
+ var systemTemplateSchema = zod.z.object({
571
+ templateId: zod.z.string(),
572
+ title: zod.z.string(),
573
+ description: zod.z.string(),
574
+ purpose: templatePurposeSchema,
575
+ content: emailContentSchema,
576
+ requiredVariables: zod.z.array(zod.z.string()).describe(
577
+ "Sorted, server-discovered Liquid paths that must be supplied."
578
+ ),
579
+ variableDefinitions: zod.z.array(templateVariableDefinitionSchema).optional().describe(
580
+ "Documentation metadata for built-in starter variables; runtime discovery remains authoritative."
581
+ )
582
+ });
583
+ var listTemplatesQuerySchema = zod.z.object({
584
+ purpose: templatePurposeSchema.optional()
585
+ });
586
+ var duplicateTemplateBodySchema = zod.z.object({
587
+ title: zod.z.string().min(1).optional()
588
+ });
589
+ var templateValidationErrorSchema = zod.z.object({
590
+ error: zod.z.string(),
591
+ variables: zod.z.array(zod.z.string()).optional()
592
+ });
593
+ var templateNotTransactionalErrorSchema = zod.z.object({
594
+ error: zod.z.literal("template_not_transactional")
595
+ });
596
+ var templateNotMarketingErrorSchema = zod.z.object({
597
+ error: zod.z.literal("template_not_marketing")
598
+ });
599
+ var espProviders = [
600
+ "smtp",
601
+ "sendgrid",
602
+ "mailgun",
603
+ "postmark",
604
+ "ses",
605
+ "resend"
606
+ ];
607
+ var espConfigSchema = zod.z.object({
608
+ espId: zod.z.string(),
609
+ name: zod.z.string(),
610
+ // Plain string, not the enum — the DB column is unconstrained text and
611
+ // validated on write (see `upsertEspConfigBodySchema`).
612
+ provider: zod.z.string(),
613
+ host: zod.z.string(),
614
+ port: zod.z.number(),
615
+ secure: zod.z.boolean(),
616
+ username: zod.z.string().nullable().optional(),
617
+ hasPassword: zod.z.boolean(),
618
+ fromName: zod.z.string().nullable().optional(),
619
+ fromEmail: zod.z.string().nullable().optional(),
620
+ status: zod.z.enum(["draft", "active", "suspended", "draining", "retired"]),
621
+ secretVersion: zod.z.number().int().positive(),
622
+ lastTestedAt: zod.z.string().nullable().optional(),
623
+ lastTestStatus: zod.z.enum(["success", "failed"]).nullable().optional(),
624
+ lastTestError: zod.z.string().nullable().optional(),
625
+ activatedAt: zod.z.string().nullable().optional(),
626
+ drainUntil: zod.z.string().nullable().optional(),
627
+ retiredAt: zod.z.string().nullable().optional(),
628
+ updatedAt: zod.z.string().optional()
629
+ });
630
+ var upsertEspConfigBodySchema = zod.z.object({
631
+ provider: zod.z.enum(espProviders),
632
+ host: zod.z.string().min(1),
633
+ port: zod.z.number().int().min(1).max(65535),
634
+ secure: zod.z.boolean(),
635
+ username: zod.z.string().optional(),
636
+ /** Omit to keep the existing secret unchanged; send `""` to clear it. */
637
+ password: zod.z.string().optional(),
638
+ fromName: zod.z.string().optional(),
639
+ fromEmail: zod.z.string().email().optional()
640
+ });
641
+ var createEspConfigBodySchema = upsertEspConfigBodySchema.extend({
642
+ name: zod.z.string().trim().min(1).max(100)
643
+ });
644
+ var updateEspConfigBodySchema = zod.z.object({
645
+ name: zod.z.string().trim().min(1).max(100).optional(),
646
+ provider: zod.z.enum(espProviders).optional(),
647
+ host: zod.z.string().min(1).optional(),
648
+ port: zod.z.number().int().min(1).max(65535).optional(),
649
+ secure: zod.z.boolean().optional(),
650
+ username: zod.z.string().optional(),
651
+ password: zod.z.string().optional(),
652
+ fromName: zod.z.string().optional(),
653
+ fromEmail: zod.z.union([zod.z.string().email(), zod.z.literal("")]).optional()
654
+ }).refine((body) => Object.keys(body).length > 0, {
655
+ message: "At least one field is required"
656
+ });
657
+ var testEspConfigBodySchema = zod.z.object({
658
+ to: zod.z.string().email().optional()
659
+ });
660
+ var testEspConfigResponseSchema = zod.z.object({
661
+ success: zod.z.boolean(),
662
+ error: zod.z.string().optional()
663
+ });
664
+ var retireEspConfigBodySchema = zod.z.discriminatedUnion("transition", [
665
+ zod.z.object({
666
+ transition: zod.z.literal("drain"),
667
+ drainUntil: zod.z.string().datetime().optional()
668
+ }),
669
+ zod.z.object({ transition: zod.z.literal("cancel") })
670
+ ]);
671
+ var generalSettingsSchema = zod.z.object({
672
+ /** Physical postal address rendered in email footers
673
+ * (CAN-SPAM/GDPR requirement). */
674
+ mailingAddress: zod.z.string().nullable(),
675
+ updatedAt: zod.z.string().nullable().optional()
676
+ });
677
+ var updateGeneralSettingsBodySchema = zod.z.object({
678
+ /** Send an empty string to clear the mailing address. */
679
+ mailingAddress: zod.z.string().optional()
680
+ });
681
+ var teamSchema = zod.z.object({
682
+ teamId: zod.z.string(),
683
+ /** Public organization identifier. Present when an end user lists the
684
+ * teams they belong to, so the dashboard can keep workspace selection
685
+ * scoped to one organization. */
686
+ organizationId: zod.z.string().optional(),
687
+ organizationName: zod.z.string().optional(),
688
+ name: zod.z.string(),
689
+ status: zod.z.enum(["active", "sending_suspended", "archived"]),
690
+ externalId: zod.z.string().nullable().optional(),
691
+ createdAt: zod.z.string().nullable().optional(),
692
+ updatedAt: zod.z.string().nullable().optional(),
693
+ /** True when the calling human is already a `team_members` row. Always
694
+ * false for organization API keys. Omitted on non-list team payloads. */
695
+ viewerIsMember: zod.z.boolean().optional()
696
+ });
697
+ var apiKeySchema = zod.z.object({
698
+ keyId: zod.z.string(),
699
+ keyPrefix: zod.z.string(),
700
+ name: zod.z.string(),
701
+ expiresAt: zod.z.string().nullable().optional(),
702
+ lastUsedAt: zod.z.string().nullable().optional(),
703
+ revokedAt: zod.z.string().nullable().optional(),
704
+ createdAt: zod.z.string().nullable().optional()
705
+ });
706
+ var createdApiKeySchema = apiKeySchema.extend({
707
+ key: zod.z.string()
708
+ });
709
+ var createTeamBodySchema = zod.z.object({ name: zod.z.string().min(1) });
710
+ var renameTeamBodySchema = zod.z.object({ name: zod.z.string().min(1) });
711
+ var createApiKeyBodySchema = zod.z.object({ name: zod.z.string().min(1) });
712
+ var provisionTeamBodySchema = zod.z.object({
713
+ externalId: zod.z.string().min(1),
714
+ name: zod.z.string().min(1),
715
+ sender: zod.z.object({
716
+ fromName: zod.z.string().min(1).optional(),
717
+ replyTo: zod.z.string().email().optional()
718
+ }).optional(),
719
+ mailingAddress: zod.z.string().min(1).optional(),
720
+ delivery: zod.z.object({
721
+ useOrganizationDefault: zod.z.boolean().optional(),
722
+ teamEspEnabled: zod.z.boolean().optional(),
723
+ teamCanChangeDefault: zod.z.boolean().optional()
724
+ }).optional(),
725
+ quota: zod.z.object({
726
+ dailyLimit: zod.z.number().int().positive().nullable().optional(),
727
+ monthlyLimit: zod.z.number().int().positive().nullable().optional()
728
+ }).optional()
729
+ });
730
+ var provisionedTeamBaseSchema = zod.z.object({
731
+ teamId: zod.z.string(),
732
+ externalId: zod.z.string(),
733
+ name: zod.z.string(),
734
+ deliverySource: zod.z.object({ type: zod.z.literal("organization") })
735
+ });
736
+ var provisionTeamResponseSchema = zod.z.discriminatedUnion("created", [
737
+ provisionedTeamBaseSchema.extend({
738
+ created: zod.z.literal(true),
739
+ apiKey: zod.z.string()
740
+ }),
741
+ provisionedTeamBaseSchema.extend({
742
+ created: zod.z.literal(false),
743
+ apiKey: zod.z.null()
744
+ })
745
+ ]);
746
+ var provisionedTeamSchema = provisionedTeamBaseSchema.extend({
747
+ status: zod.z.enum(["active", "sending_suspended", "archived"]),
748
+ mailingAddress: zod.z.string().nullable(),
749
+ teamEspEnabled: zod.z.boolean(),
750
+ teamCanChangeDefault: zod.z.boolean(),
751
+ createdAt: zod.z.string().nullable(),
752
+ updatedAt: zod.z.string().nullable()
753
+ });
754
+ var updateProvisionedTeamBodySchema = zod.z.object({
755
+ name: zod.z.string().min(1).optional(),
756
+ sender: zod.z.object({
757
+ fromName: zod.z.string().min(1).nullable().optional(),
758
+ replyTo: zod.z.string().email().nullable().optional()
759
+ }).optional(),
760
+ mailingAddress: zod.z.string().min(1).nullable().optional(),
761
+ delivery: zod.z.object({
762
+ teamEspEnabled: zod.z.boolean().optional(),
763
+ teamCanChangeDefault: zod.z.boolean().optional()
764
+ }).optional(),
765
+ quota: zod.z.object({
766
+ dailyLimit: zod.z.number().int().nonnegative().nullable().optional(),
767
+ monthlyLimit: zod.z.number().int().nonnegative().nullable().optional()
768
+ }).optional()
769
+ }).refine((body) => Object.keys(body).length > 0, {
770
+ message: "At least one field is required"
771
+ });
772
+ var usageWindowSchema = zod.z.object({
773
+ limit: zod.z.number().int().nullable(),
774
+ accepted: zod.z.number().int().nonnegative(),
775
+ reserved: zod.z.number().int().nonnegative(),
776
+ remaining: zod.z.number().int().nullable(),
777
+ resetsAt: zod.z.string()
778
+ });
779
+ var provisionedTeamUsageSchema = zod.z.object({
780
+ day: usageWindowSchema,
781
+ month: usageWindowSchema
782
+ });
783
+ var segmentSchema = zod.z.object({
784
+ segmentId: zod.z.string(),
785
+ name: zod.z.string(),
786
+ filter: contactFilterSchema,
787
+ createdAt: zod.z.string().nullable(),
788
+ updatedAt: zod.z.string().nullable()
789
+ });
790
+ var createSegmentBodySchema = zod.z.object({
791
+ name: zod.z.string().min(1),
792
+ filter: contactFilterSchema
793
+ });
794
+ var updateSegmentBodySchema = zod.z.object({
795
+ name: zod.z.string().min(1).optional(),
796
+ filter: contactFilterSchema.optional()
797
+ });
798
+ var mediaSchema = zod.z.object({
799
+ mediaId: zod.z.string(),
800
+ url: zod.z.string(),
801
+ thumbnailUrl: zod.z.string().nullable().optional(),
802
+ mediaLitId: zod.z.string(),
803
+ fileName: zod.z.string().nullable().optional(),
804
+ mimeType: zod.z.string().nullable().optional(),
805
+ size: zod.z.number().nullable().optional(),
806
+ width: zod.z.number().nullable().optional(),
807
+ height: zod.z.number().nullable().optional(),
808
+ alt: zod.z.string().nullable().optional(),
809
+ caption: zod.z.string().nullable().optional(),
810
+ createdAt: zod.z.string().or(zod.z.date()).nullable().optional(),
811
+ updatedAt: zod.z.string().or(zod.z.date()).nullable().optional()
812
+ });
813
+ var mediaReferenceSchema = zod.z.object({
814
+ resourceType: zod.z.enum(["TEMPLATE", "SEQUENCE_EMAIL"]),
815
+ resourcePublicId: zod.z.string(),
816
+ parentResourcePublicId: zod.z.string().nullable().optional(),
817
+ createdAt: zod.z.string().or(zod.z.date()).nullable().optional(),
818
+ updatedAt: zod.z.string().or(zod.z.date()).nullable().optional()
819
+ });
820
+ var listMediaQuerySchema = zod.z.object({
821
+ page: zod.z.coerce.number().int().min(1).optional(),
822
+ pageSize: zod.z.coerce.number().int().min(1).max(100).optional(),
823
+ query: zod.z.string().optional()
824
+ });
825
+ var updateMediaBodySchema = zod.z.object({
826
+ alt: zod.z.string().nullable().optional(),
827
+ caption: zod.z.string().nullable().optional()
828
+ });
829
+ var mediaUploadSignatureSchema = zod.z.object({
830
+ signature: zod.z.string(),
831
+ endpoint: zod.z.string()
832
+ });
833
+ var transactionalEmailStatus = [
834
+ "queued",
835
+ "sent",
836
+ "failed",
837
+ "bounced",
838
+ "suppressed"
839
+ ];
840
+ var transactionalEmailSchema = zod.z.object({
841
+ txeId: zod.z.string(),
842
+ to: zod.z.string(),
843
+ from: zod.z.string().nullable(),
844
+ replyTo: zod.z.string().nullable(),
845
+ subject: zod.z.string(),
846
+ templateId: zod.z.string().nullable(),
847
+ variables: zod.z.record(zod.z.any()),
848
+ status: zod.z.enum(transactionalEmailStatus),
849
+ error: zod.z.string().nullable(),
850
+ trackOpens: zod.z.boolean(),
851
+ trackClicks: zod.z.boolean(),
852
+ openCount: zod.z.number(),
853
+ clickCount: zod.z.number(),
854
+ sentAt: zod.z.string().nullable(),
855
+ createdAt: zod.z.string().nullable(),
856
+ updatedAt: zod.z.string().nullable()
857
+ });
858
+ var transactionalEmailDetailSchema = transactionalEmailSchema.extend({
859
+ html: zod.z.string().nullable()
860
+ });
861
+ var reservedHeaders = ["from", "to", "subject", "content-type"];
862
+ var emailHeadersSchema = zod.z.record(zod.z.string()).superRefine((headers, ctx) => {
863
+ for (const [name, value] of Object.entries(headers)) {
864
+ if (/[\r\n]/.test(name) || /[\r\n]/.test(value)) {
865
+ ctx.addIssue({
866
+ code: zod.z.ZodIssueCode.custom,
867
+ message: "Header names and values must not contain CR/LF characters"
868
+ });
869
+ } else if (reservedHeaders.includes(
870
+ name.toLowerCase()
871
+ )) {
872
+ ctx.addIssue({
873
+ code: zod.z.ZodIssueCode.custom,
874
+ message: `Header "${name}" is set by the send pipeline and cannot be overridden`
875
+ });
876
+ }
877
+ }
878
+ });
879
+ var sendEmailBodySchema = zod.z.object({
880
+ to: zod.z.string().email(),
881
+ subject: zod.z.string().min(1),
882
+ templateId: zod.z.string().min(1).optional(),
883
+ html: zod.z.string().min(1).optional(),
884
+ variables: zod.z.record(zod.z.any()).optional(),
885
+ replyTo: zod.z.string().email().optional(),
886
+ headers: emailHeadersSchema.optional(),
887
+ idempotencyKey: zod.z.string().min(1).max(256).optional(),
888
+ trackOpens: zod.z.boolean().optional(),
889
+ trackClicks: zod.z.boolean().optional(),
890
+ deliverySource: deliverySourceSelectionSchema.optional()
891
+ }).refine((body) => !!body.templateId !== !!body.html, {
892
+ message: "Provide exactly one of templateId or html"
893
+ }).refine((body) => !(body.html && body.variables), {
894
+ message: "variables requires templateId; inline html is sent verbatim"
895
+ });
896
+ var sendEmailResponseSchema = transactionalEmailSchema.pick({
897
+ txeId: true,
898
+ status: true
899
+ });
900
+ var missingTemplateVariablesErrorSchema = zod.z.object({
901
+ error: zod.z.literal("missing_template_variables"),
902
+ missingVariables: zod.z.array(zod.z.string()).min(1)
903
+ });
904
+ var listTransactionalEmailsQuerySchema = zod.z.object({
905
+ status: zod.z.enum(transactionalEmailStatus).optional(),
906
+ createdAfter: zod.z.coerce.number().int().optional().describe("Millisecond timestamp lower bound (inclusive)"),
907
+ createdBefore: zod.z.coerce.number().int().optional().describe("Millisecond timestamp upper bound (exclusive)"),
908
+ offset: zod.z.coerce.number().int().min(1).optional(),
909
+ itemsPerPage: zod.z.coerce.number().int().min(1).max(50).optional()
910
+ });
911
+ var overviewQuerySchema = zod.z.object({
912
+ /** Delivery activity window, in days. Defaults to the last 7 days. */
913
+ rangeDays: zod.z.coerce.number().int().refine((value) => [1, 3, 7, 30].includes(value)).optional()
914
+ });
915
+ var overviewSchema = zod.z.object({
916
+ activeSequences: zod.z.number(),
917
+ ongoingContacts: zod.z.number(),
918
+ scheduledBroadcasts: zod.z.number(),
919
+ mail: zod.z.object({
920
+ sent: zod.z.number(),
921
+ queued: zod.z.number(),
922
+ failed: zod.z.number(),
923
+ bounced: zod.z.number()
924
+ }),
925
+ quota: zod.z.object({
926
+ dailyUsed: zod.z.number(),
927
+ dailyLimit: zod.z.number(),
928
+ monthlyUsed: zod.z.number(),
929
+ monthlyLimit: zod.z.number()
930
+ })
931
+ });
932
+ var feedbackConnectionStatus = [
933
+ "pending",
934
+ "healthy",
935
+ "stale",
936
+ "error",
937
+ "retiring",
938
+ "disabled"
939
+ ];
940
+ var feedbackConnectionSchema = zod.z.object({
941
+ connectionId: zod.z.string(),
942
+ espId: zod.z.string(),
943
+ provider: zod.z.string(),
944
+ webhookUrl: zod.z.string(),
945
+ hasCredential: zod.z.boolean(),
946
+ status: zod.z.enum(feedbackConnectionStatus),
947
+ lastReceivedAt: zod.z.string().nullable().optional(),
948
+ lastVerifiedAt: zod.z.string().nullable().optional(),
949
+ lastErrorCode: zod.z.string().nullable().optional(),
950
+ createdAt: zod.z.string().optional(),
951
+ updatedAt: zod.z.string().optional()
952
+ });
953
+ var upsertFeedbackConnectionBodySchema = zod.z.object({
954
+ /** The provider's webhook signing secret / public key / shared header
955
+ * value, depending on provider. Never returned after this call. */
956
+ credential: zod.z.string().min(1),
957
+ /** SES only (reserved — not usable until the platform/SES phase ships). */
958
+ expectedTopicArn: zod.z.string().optional()
959
+ });
960
+ var testFeedbackConnectionResponseSchema = zod.z.object({
961
+ success: zod.z.boolean(),
962
+ error: zod.z.string().optional()
963
+ });
964
+ var deliveryEventType = [
965
+ "accepted",
966
+ "delivered",
967
+ "delayed",
968
+ "soft_bounce",
969
+ "hard_bounce",
970
+ "failed",
971
+ "complaint",
972
+ "suppressed",
973
+ "rejected",
974
+ "unknown"
975
+ ];
976
+ var bounceClass = ["permanent", "transient", "undetermined"];
977
+ var deliverySourceTypes = ["organization", "team"];
978
+ var deliveryEventSchema = zod.z.object({
979
+ eventId: zod.z.string(),
980
+ provider: zod.z.string(),
981
+ espId: zod.z.string().nullable(),
982
+ deliverySourceType: zod.z.enum(deliverySourceTypes).nullable(),
983
+ /** Public `msg_...` id of the correlated outbound message, when the
984
+ * event was matched to one — see the PRD's correlation section. */
985
+ messageId: zod.z.string().nullable(),
986
+ recipientEmail: zod.z.string().nullable(),
987
+ eventType: zod.z.enum(deliveryEventType),
988
+ bounceClass: zod.z.enum(bounceClass).nullable().optional(),
989
+ smtpCode: zod.z.number().nullable().optional(),
990
+ enhancedStatusCode: zod.z.string().nullable().optional(),
991
+ reason: zod.z.string().nullable().optional(),
992
+ occurredAt: zod.z.string(),
993
+ receivedAt: zod.z.string()
994
+ });
995
+ var listDeliveryEventsQuerySchema = zod.z.object({
996
+ espId: zod.z.string().optional(),
997
+ deliverySourceType: zod.z.enum(deliverySourceTypes).optional(),
998
+ eventType: zod.z.enum(deliveryEventType).optional(),
999
+ createdAfter: zod.z.coerce.number().int().optional(),
1000
+ createdBefore: zod.z.coerce.number().int().optional(),
1001
+ offset: zod.z.coerce.number().int().min(1).optional(),
1002
+ itemsPerPage: zod.z.coerce.number().int().min(1).optional()
1003
+ });
1004
+ var suppressionReason = [
1005
+ "hard_bounce",
1006
+ "complaint",
1007
+ "repeated_soft_bounce",
1008
+ "provider_suppression",
1009
+ "manual"
1010
+ ];
1011
+ var suppressionSchema = zod.z.object({
1012
+ suppressionId: zod.z.string(),
1013
+ recipientEmail: zod.z.string().nullable(),
1014
+ reason: zod.z.enum(suppressionReason),
1015
+ active: zod.z.boolean(),
1016
+ firstSuppressedAt: zod.z.string(),
1017
+ lastSuppressedAt: zod.z.string(),
1018
+ releasedAt: zod.z.string().nullable().optional(),
1019
+ releaseReason: zod.z.string().nullable().optional()
1020
+ });
1021
+ var listSuppressionsQuerySchema = zod.z.object({
1022
+ active: zod.z.coerce.boolean().optional(),
1023
+ reason: zod.z.enum(suppressionReason).optional(),
1024
+ offset: zod.z.coerce.number().int().min(1).optional(),
1025
+ itemsPerPage: zod.z.coerce.number().int().min(1).optional()
1026
+ });
1027
+ var releaseSuppressionBodySchema = zod.z.object({
1028
+ explanation: zod.z.string().min(1).max(2e3).optional()
1029
+ });
1030
+ var organizationRoleSchema = zod.z.enum(["owner", "admin", "member"]);
1031
+ var organizationSchema = zod.z.object({
1032
+ organizationId: zod.z.string(),
1033
+ name: zod.z.string(),
1034
+ status: zod.z.enum(["active", "suspended", "closed"]),
1035
+ createdAt: zod.z.string(),
1036
+ updatedAt: zod.z.string()
1037
+ });
1038
+ var organizationMemberSchema = zod.z.object({
1039
+ userId: zod.z.string(),
1040
+ email: zod.z.string().email(),
1041
+ name: zod.z.string(),
1042
+ image: zod.z.string().nullable(),
1043
+ role: organizationRoleSchema,
1044
+ createdAt: zod.z.string(),
1045
+ updatedAt: zod.z.string()
1046
+ });
1047
+ var createOrganizationBodySchema = zod.z.object({
1048
+ name: zod.z.string().trim().min(1)
1049
+ });
1050
+ var updateOrganizationBodySchema = zod.z.object({
1051
+ name: zod.z.string().trim().min(1)
1052
+ });
1053
+ var addOrganizationMemberBodySchema = zod.z.object({
1054
+ /** Existing Better Auth user only. This is a membership lookup, never an
1055
+ * authentication or account-creation flow. */
1056
+ email: zod.z.string().trim().email(),
1057
+ role: organizationRoleSchema
1058
+ });
1059
+ var updateOrganizationMemberBodySchema = zod.z.object({
1060
+ role: organizationRoleSchema
1061
+ });
1062
+ var organizationKeyScopes = [
1063
+ "organization:read",
1064
+ "teams:provision",
1065
+ "teams:read",
1066
+ "teams:manage",
1067
+ "teams:keys",
1068
+ "esps:read",
1069
+ "esps:manage",
1070
+ "grants:manage",
1071
+ "usage:read"
1072
+ ];
1073
+ var organizationApiKeySchema = zod.z.object({
1074
+ keyId: zod.z.string(),
1075
+ name: zod.z.string(),
1076
+ keyPrefix: zod.z.string(),
1077
+ scopes: zod.z.array(zod.z.enum(organizationKeyScopes)),
1078
+ expiresAt: zod.z.string().nullable(),
1079
+ lastUsedAt: zod.z.string().nullable(),
1080
+ revokedAt: zod.z.string().nullable(),
1081
+ createdAt: zod.z.string()
1082
+ });
1083
+ var createOrganizationApiKeyBodySchema = zod.z.object({
1084
+ name: zod.z.string().trim().min(1),
1085
+ scopes: zod.z.array(zod.z.enum(organizationKeyScopes)).min(1),
1086
+ expiresAt: zod.z.string().datetime().nullable().optional()
1087
+ });
1088
+ var createdOrganizationApiKeySchema = organizationApiKeySchema.extend({
1089
+ key: zod.z.string()
1090
+ });
1091
+ var organizationUsageWindowSchema = zod.z.object({
1092
+ limit: zod.z.number().int().nullable(),
1093
+ accepted: zod.z.number().int().nonnegative(),
1094
+ reserved: zod.z.number().int().nonnegative(),
1095
+ remaining: zod.z.number().int().nullable(),
1096
+ resetsAt: zod.z.string()
1097
+ });
1098
+ var organizationUsageSchema = zod.z.object({
1099
+ day: organizationUsageWindowSchema,
1100
+ month: organizationUsageWindowSchema
1101
+ });
1102
+ var organizationMailActivityQuerySchema = zod.z.object({
1103
+ rangeDays: zod.z.coerce.number().int().refine((value) => [1, 3, 7, 30].includes(value)).optional()
1104
+ });
1105
+ var organizationMailCountsSchema = zod.z.object({
1106
+ sent: zod.z.number().int().nonnegative(),
1107
+ queued: zod.z.number().int().nonnegative(),
1108
+ failed: zod.z.number().int().nonnegative(),
1109
+ bounced: zod.z.number().int().nonnegative()
1110
+ });
1111
+ var organizationMailActivityTeamSchema = zod.z.object({
1112
+ teamId: zod.z.string(),
1113
+ name: zod.z.string(),
1114
+ status: zod.z.enum(["active", "sending_suspended", "archived"]),
1115
+ externalId: zod.z.string().nullable(),
1116
+ mail: organizationMailCountsSchema
1117
+ });
1118
+ var organizationMailActivitySchema = zod.z.object({
1119
+ rangeDays: zod.z.union([
1120
+ zod.z.literal(1),
1121
+ zod.z.literal(3),
1122
+ zod.z.literal(7),
1123
+ zod.z.literal(30)
1124
+ ]),
1125
+ totals: organizationMailCountsSchema,
1126
+ teams: zod.z.array(organizationMailActivityTeamSchema)
1127
+ });
1128
+ var organizationEnterTeamBodySchema = zod.z.object({});
1129
+ var organizationEnterTeamResponseSchema = zod.z.object({
1130
+ teamId: zod.z.string(),
1131
+ role: zod.z.enum(["admin", "member"]),
1132
+ created: zod.z.boolean()
1133
+ });
1134
+ var organizationAuditEventSchema = zod.z.object({
1135
+ action: zod.z.string(),
1136
+ actorType: zod.z.enum(["user", "organization_key", "team_key", "system"]),
1137
+ teamId: zod.z.string().nullable(),
1138
+ espId: zod.z.string().nullable(),
1139
+ grantId: zod.z.string().nullable(),
1140
+ metadata: zod.z.record(zod.z.any()),
1141
+ createdAt: zod.z.string()
1142
+ });
1143
+ var c = core.initContract();
1144
+ var contactsContract = c.router(
1145
+ {
1146
+ create: {
1147
+ method: "POST",
1148
+ path: "/contacts",
1149
+ body: createContactBodySchema,
1150
+ responses: { 201: contactSchema },
1151
+ summary: "Create a contact",
1152
+ description: "Creates a contact (subscriber). If a contact with the same email already exists for this team, the existing contact is returned."
1153
+ },
1154
+ list: {
1155
+ method: "GET",
1156
+ path: "/contacts",
1157
+ query: listContactsQuerySchema,
1158
+ responses: {
1159
+ 200: paginated(contactSchema),
1160
+ 400: errorSchema,
1161
+ 404: errorSchema
1162
+ },
1163
+ summary: "List contacts",
1164
+ description: "Returns a paginated list of contacts. Pass filter as serialized ContactFilterWithAggregator JSON for inline filtering, or segmentId to only return contacts currently matching that saved segment's filter (404 if the segment doesn't exist). SendLit supports fixed generic contact filters over first-class fields, tags, and custom fields; client-specific concepts should be synced into namespaced tags or customFields. q, filter, and segmentId combine with AND. The response's total reflects the combined filters."
1165
+ },
1166
+ get: {
1167
+ method: "GET",
1168
+ path: "/contacts/:contactId",
1169
+ responses: { 200: contactSchema, 404: errorSchema },
1170
+ summary: "Get a contact"
1171
+ },
1172
+ update: {
1173
+ method: "PATCH",
1174
+ path: "/contacts/:contactId",
1175
+ body: updateContactBodySchema,
1176
+ responses: { 200: contactSchema, 404: errorSchema },
1177
+ summary: "Update a contact"
1178
+ },
1179
+ addTag: {
1180
+ method: "POST",
1181
+ path: "/contacts/:contactId/tags/:tag",
1182
+ body: c.noBody(),
1183
+ responses: { 200: contactSchema, 404: errorSchema },
1184
+ summary: "Add a tag to a contact"
1185
+ },
1186
+ removeTag: {
1187
+ method: "DELETE",
1188
+ path: "/contacts/:contactId/tags/:tag",
1189
+ responses: { 200: contactSchema, 404: errorSchema },
1190
+ summary: "Remove a tag from a contact"
1191
+ },
1192
+ deliveries: {
1193
+ method: "GET",
1194
+ path: "/contacts/:contactId/deliveries",
1195
+ responses: {
1196
+ 200: c.type(),
1197
+ 404: errorSchema
1198
+ },
1199
+ summary: "List broadcasts/sequence emails delivered to a contact"
1200
+ },
1201
+ remove: {
1202
+ method: "DELETE",
1203
+ path: "/contacts/:contactId",
1204
+ responses: { 204: c.noBody() },
1205
+ summary: "Delete a contact"
1206
+ }
1207
+ },
1208
+ { metadata: { tag: "Contacts" } }
1209
+ );
1210
+ var segmentsContract = c.router(
1211
+ {
1212
+ create: {
1213
+ method: "POST",
1214
+ path: "/segments",
1215
+ body: createSegmentBodySchema,
1216
+ responses: { 201: segmentSchema, 409: errorSchema },
1217
+ summary: "Create a saved segment"
1218
+ },
1219
+ list: {
1220
+ method: "GET",
1221
+ path: "/segments",
1222
+ responses: { 200: c.type() },
1223
+ summary: "List saved segments"
1224
+ },
1225
+ get: {
1226
+ method: "GET",
1227
+ path: "/segments/:segmentId",
1228
+ responses: { 200: segmentSchema, 404: errorSchema },
1229
+ summary: "Get a saved segment"
1230
+ },
1231
+ update: {
1232
+ method: "PATCH",
1233
+ path: "/segments/:segmentId",
1234
+ body: updateSegmentBodySchema,
1235
+ responses: {
1236
+ 200: segmentSchema,
1237
+ 404: errorSchema,
1238
+ 409: errorSchema
1239
+ },
1240
+ summary: "Update a saved segment"
1241
+ },
1242
+ remove: {
1243
+ method: "DELETE",
1244
+ path: "/segments/:segmentId",
1245
+ responses: { 204: c.noBody() },
1246
+ summary: "Delete a saved segment"
1247
+ }
1248
+ },
1249
+ { metadata: { tag: "Segments" } }
1250
+ );
1251
+ var mediaContract = c.router(
1252
+ {
1253
+ list: {
1254
+ method: "GET",
1255
+ path: "/media",
1256
+ query: listMediaQuerySchema,
1257
+ responses: { 200: paginated(mediaSchema) },
1258
+ summary: "List uploaded media",
1259
+ description: "Returns the team's uploaded MediaLit-backed media. Unsplash and external URL images are not stored here."
1260
+ },
1261
+ presigned: {
1262
+ method: "POST",
1263
+ path: "/media/presigned",
1264
+ body: c.noBody(),
1265
+ responses: { 200: mediaUploadSignatureSchema, 500: errorSchema },
1266
+ summary: "Generate a MediaLit upload signature",
1267
+ description: "Returns a short-lived MediaLit signature and endpoint. Upload image files directly to `${endpoint}/media/create/resumable` with the signature in the `x-medialit-signature` header."
1268
+ },
1269
+ get: {
1270
+ method: "GET",
1271
+ path: "/media/:mediaId",
1272
+ responses: { 200: mediaSchema, 404: errorSchema },
1273
+ summary: "Get uploaded media"
1274
+ },
1275
+ update: {
1276
+ method: "PATCH",
1277
+ path: "/media/:mediaId",
1278
+ body: updateMediaBodySchema,
1279
+ responses: { 200: mediaSchema, 404: errorSchema },
1280
+ summary: "Update uploaded media metadata"
1281
+ },
1282
+ remove: {
1283
+ method: "DELETE",
1284
+ path: "/media/:mediaId",
1285
+ responses: {
1286
+ 204: c.noBody(),
1287
+ 404: errorSchema,
1288
+ 409: errorSchema
1289
+ },
1290
+ summary: "Delete unused uploaded media",
1291
+ description: "Deletes the MediaLit file and SendLit media row only when no saved email content references it."
1292
+ },
1293
+ references: {
1294
+ method: "GET",
1295
+ path: "/media/:mediaId/references",
1296
+ responses: {
1297
+ 200: itemsList(mediaReferenceSchema),
1298
+ 404: errorSchema
1299
+ },
1300
+ summary: "List uploaded media references"
1301
+ }
1302
+ },
1303
+ { metadata: { tag: "Media" } }
1304
+ );
1305
+ var templatesContract = c.router(
1306
+ {
1307
+ listSystem: {
1308
+ method: "GET",
1309
+ path: "/system-templates",
1310
+ query: listTemplatesQuerySchema,
1311
+ responses: { 200: itemsList(systemTemplateSchema) },
1312
+ summary: "List built-in starting templates",
1313
+ description: "Not team-scoped\u2014the same for every team. Filter by purpose. System templates are starters and must be duplicated into a team-owned template before transactional sending."
1314
+ },
1315
+ create: {
1316
+ method: "POST",
1317
+ path: "/templates",
1318
+ body: createTemplateBodySchema,
1319
+ responses: {
1320
+ 201: emailTemplateSchema,
1321
+ 422: templateValidationErrorSchema
1322
+ },
1323
+ summary: "Create an email template",
1324
+ description: "Purpose is immutable. Marketing content must contain exactly one final managed footer; transactional content must not contain a footer or marketing-only variables."
1325
+ },
1326
+ list: {
1327
+ method: "GET",
1328
+ path: "/templates",
1329
+ query: listTemplatesQuerySchema,
1330
+ responses: { 200: c.type() },
1331
+ summary: "List email templates",
1332
+ description: "Returns team-owned templates with their immutable purpose and server-computed requiredVariables. Optionally filter by purpose."
1333
+ },
1334
+ get: {
1335
+ method: "GET",
1336
+ path: "/templates/:templateId",
1337
+ responses: {
1338
+ 200: emailTemplateSchema,
1339
+ 404: errorSchema,
1340
+ 422: templateValidationErrorSchema
1341
+ },
1342
+ summary: "Get an email template"
1343
+ },
1344
+ update: {
1345
+ method: "PATCH",
1346
+ path: "/templates/:templateId",
1347
+ body: updateTemplateBodySchema,
1348
+ responses: {
1349
+ 200: emailTemplateSchema,
1350
+ 404: errorSchema,
1351
+ 409: errorSchema,
1352
+ 422: templateValidationErrorSchema
1353
+ },
1354
+ summary: "Update an email template"
1355
+ },
1356
+ duplicate: {
1357
+ method: "POST",
1358
+ path: "/templates/:templateId/duplicate",
1359
+ body: duplicateTemplateBodySchema,
1360
+ responses: {
1361
+ 201: emailTemplateSchema,
1362
+ 404: errorSchema,
1363
+ 422: templateValidationErrorSchema
1364
+ },
1365
+ summary: "Duplicate an email template",
1366
+ description: "Creates a new team-owned copy with the same immutable purpose as the source template."
1367
+ },
1368
+ remove: {
1369
+ method: "DELETE",
1370
+ path: "/templates/:templateId",
1371
+ responses: { 204: c.noBody() },
1372
+ summary: "Delete an email template"
1373
+ }
1374
+ },
1375
+ { metadata: { tag: "Templates" } }
1376
+ );
1377
+ var sequencesContract = c.router(
1378
+ {
1379
+ create: {
1380
+ method: "POST",
1381
+ path: "/sequences",
1382
+ body: createSequenceBodySchema,
1383
+ responses: {
1384
+ 201: sequenceSchema,
1385
+ 400: errorSchema,
1386
+ 422: templateNotMarketingErrorSchema
1387
+ },
1388
+ summary: "Create a broadcast or a sequence",
1389
+ description: "templateId must identify a marketing team template or marketing system starter. Transactional templates return 422 template_not_marketing."
1390
+ },
1391
+ list: {
1392
+ method: "GET",
1393
+ path: "/sequences",
1394
+ query: listSequencesQuerySchema,
1395
+ responses: { 200: paginated(sequenceSchema) },
1396
+ summary: "List broadcasts or sequences"
1397
+ },
1398
+ get: {
1399
+ method: "GET",
1400
+ path: "/sequences/:sequenceId",
1401
+ responses: { 200: sequenceSchema, 404: errorSchema },
1402
+ summary: "Get a broadcast or sequence"
1403
+ },
1404
+ update: {
1405
+ method: "PATCH",
1406
+ path: "/sequences/:sequenceId",
1407
+ body: updateSequenceBodySchema,
1408
+ responses: {
1409
+ 200: sequenceSchema,
1410
+ 400: errorSchema,
1411
+ 404: errorSchema
1412
+ },
1413
+ summary: "Update a broadcast or sequence"
1414
+ },
1415
+ remove: {
1416
+ method: "DELETE",
1417
+ path: "/sequences/:sequenceId",
1418
+ responses: { 204: c.noBody(), 404: errorSchema },
1419
+ summary: "Delete a broadcast or sequence"
1420
+ },
1421
+ addEmail: {
1422
+ method: "POST",
1423
+ path: "/sequences/:sequenceId/emails",
1424
+ body: addSequenceEmailBodySchema,
1425
+ responses: {
1426
+ 201: sequenceSchema,
1427
+ 400: errorSchema,
1428
+ 404: errorSchema,
1429
+ 422: templateNotMarketingErrorSchema
1430
+ },
1431
+ summary: "Add an email to a sequence",
1432
+ description: "templateId must identify a marketing template; transactional templates return 422 template_not_marketing."
1433
+ },
1434
+ updateEmail: {
1435
+ method: "PATCH",
1436
+ path: "/sequences/:sequenceId/emails/:emailId",
1437
+ body: updateSequenceEmailBodySchema,
1438
+ responses: {
1439
+ 200: sequenceSchema,
1440
+ 400: errorSchema,
1441
+ 404: errorSchema,
1442
+ 422: templateNotMarketingErrorSchema
1443
+ },
1444
+ summary: "Update an email within a sequence",
1445
+ description: "When templateId is supplied, it must identify a marketing template; transactional templates return 422 template_not_marketing."
1446
+ },
1447
+ removeEmail: {
1448
+ method: "DELETE",
1449
+ path: "/sequences/:sequenceId/emails/:emailId",
1450
+ responses: {
1451
+ 200: sequenceSchema,
1452
+ 400: errorSchema,
1453
+ 404: errorSchema
1454
+ },
1455
+ summary: "Remove an email from a sequence"
1456
+ },
1457
+ start: {
1458
+ method: "POST",
1459
+ path: "/sequences/:sequenceId/start",
1460
+ body: c.noBody(),
1461
+ responses: {
1462
+ 200: sequenceSchema,
1463
+ 400: errorSchema,
1464
+ 422: errorSchema
1465
+ },
1466
+ summary: "Start a broadcast or activate a sequence",
1467
+ description: "Requires a non-empty mailing address in the team's general settings."
1468
+ },
1469
+ pause: {
1470
+ method: "POST",
1471
+ path: "/sequences/:sequenceId/pause",
1472
+ body: c.noBody(),
1473
+ responses: { 200: sequenceSchema, 400: errorSchema },
1474
+ summary: "Pause an active sequence"
1475
+ },
1476
+ stats: {
1477
+ method: "GET",
1478
+ path: "/sequences/:sequenceId/stats",
1479
+ responses: { 200: sequenceStatsSchema },
1480
+ summary: "Delivery / open-rate / click-through-rate stats for a sequence"
1481
+ },
1482
+ subscribers: {
1483
+ method: "GET",
1484
+ path: "/sequences/:sequenceId/subscribers",
1485
+ query: listSubscribersQuerySchema,
1486
+ responses: { 200: c.type() },
1487
+ summary: "List contact ids that have received this sequence"
1488
+ }
1489
+ },
1490
+ { metadata: { tag: "Sequences" } }
1491
+ );
1492
+ var transactionalContract = c.router(
1493
+ {
1494
+ send: {
1495
+ method: "POST",
1496
+ path: "/emails",
1497
+ body: sendEmailBodySchema,
1498
+ responses: {
1499
+ 202: sendEmailResponseSchema,
1500
+ 400: errorSchema,
1501
+ 422: zod.z.union([
1502
+ missingTemplateVariablesErrorSchema,
1503
+ templateNotTransactionalErrorSchema,
1504
+ errorSchema
1505
+ ]),
1506
+ 429: errorSchema
1507
+ },
1508
+ summary: "Send a transactional email",
1509
+ description: "Requires a non-empty mailing address in the team's general settings. `templateId` must identify a team-owned transactional template; marketing templates return 422 template_not_transactional. Unguarded Liquid variables must be supplied in `variables`, or the API returns 422 missing_template_variables without creating a row or queue job. Inline `html` is sent verbatim without Liquid rendering. address, unsubscribe_link, and subscriber are marketing-only server-owned values and are unavailable to transactional templates."
1510
+ },
1511
+ get: {
1512
+ method: "GET",
1513
+ path: "/emails/:txeId",
1514
+ responses: {
1515
+ 200: transactionalEmailDetailSchema,
1516
+ 404: errorSchema
1517
+ },
1518
+ summary: "Get a transactional email"
1519
+ },
1520
+ list: {
1521
+ method: "GET",
1522
+ path: "/emails",
1523
+ query: listTransactionalEmailsQuerySchema,
1524
+ responses: { 200: paginated(transactionalEmailSchema) },
1525
+ summary: "List transactional emails"
1526
+ }
1527
+ },
1528
+ { metadata: { tag: "Transactional Emails" } }
1529
+ );
1530
+ var espCollectionContract = c.router(
1531
+ {
1532
+ list: {
1533
+ method: "GET",
1534
+ path: "/settings/esps",
1535
+ responses: { 200: itemsList(espConfigSchema) },
1536
+ summary: "List the team's user-managed ESP configurations"
1537
+ },
1538
+ create: {
1539
+ method: "POST",
1540
+ path: "/settings/esps",
1541
+ body: createEspConfigBodySchema,
1542
+ responses: { 201: espConfigSchema, 403: errorSchema },
1543
+ summary: "Create a user-managed ESP configuration"
1544
+ },
1545
+ get: {
1546
+ method: "GET",
1547
+ path: "/settings/esps/:espId",
1548
+ responses: {
1549
+ 200: espConfigSchema,
1550
+ 403: errorSchema,
1551
+ 404: errorSchema,
1552
+ 409: errorSchema
1553
+ },
1554
+ summary: "Get a user-managed ESP configuration"
1555
+ },
1556
+ update: {
1557
+ method: "PATCH",
1558
+ path: "/settings/esps/:espId",
1559
+ body: updateEspConfigBodySchema,
1560
+ responses: {
1561
+ 200: espConfigSchema,
1562
+ 403: errorSchema,
1563
+ 404: errorSchema,
1564
+ 409: errorSchema
1565
+ },
1566
+ summary: "Update a user-managed ESP configuration"
1567
+ },
1568
+ remove: {
1569
+ method: "DELETE",
1570
+ path: "/settings/esps/:espId",
1571
+ responses: {
1572
+ 204: c.noBody(),
1573
+ 403: errorSchema,
1574
+ 404: errorSchema,
1575
+ 409: errorSchema
1576
+ },
1577
+ summary: "Remove a user-managed ESP configuration",
1578
+ description: "Removes an ESP with no active or queued dependencies. Draft, paused, and completed sequences are detached first."
1579
+ },
1580
+ test: {
1581
+ method: "POST",
1582
+ path: "/settings/esps/:espId/test",
1583
+ body: testEspConfigBodySchema,
1584
+ responses: {
1585
+ 200: testEspConfigResponseSchema,
1586
+ 400: errorSchema,
1587
+ 403: errorSchema,
1588
+ 422: errorSchema,
1589
+ 404: errorSchema,
1590
+ 502: testEspConfigResponseSchema
1591
+ },
1592
+ summary: "Send a test email through a user-managed ESP",
1593
+ description: "Requires a non-empty mailing address in the team's general settings."
1594
+ },
1595
+ activate: {
1596
+ method: "POST",
1597
+ path: "/settings/esps/:espId/activate",
1598
+ body: c.noBody(),
1599
+ responses: {
1600
+ 200: espConfigSchema,
1601
+ 403: errorSchema,
1602
+ 404: errorSchema,
1603
+ 409: errorSchema,
1604
+ 422: errorSchema
1605
+ },
1606
+ summary: "Activate a verified team ESP"
1607
+ },
1608
+ suspend: {
1609
+ method: "POST",
1610
+ path: "/settings/esps/:espId/suspend",
1611
+ body: c.noBody(),
1612
+ responses: {
1613
+ 200: espConfigSchema,
1614
+ 403: errorSchema,
1615
+ 404: errorSchema,
1616
+ 409: errorSchema
1617
+ },
1618
+ summary: "Suspend a team ESP"
1619
+ },
1620
+ resume: {
1621
+ method: "POST",
1622
+ path: "/settings/esps/:espId/resume",
1623
+ body: c.noBody(),
1624
+ responses: {
1625
+ 200: espConfigSchema,
1626
+ 403: errorSchema,
1627
+ 404: errorSchema,
1628
+ 409: errorSchema
1629
+ },
1630
+ summary: "Resume a team ESP"
1631
+ },
1632
+ retire: {
1633
+ method: "POST",
1634
+ path: "/settings/esps/:espId/retire",
1635
+ body: retireEspConfigBodySchema,
1636
+ responses: {
1637
+ 200: espConfigSchema,
1638
+ 403: errorSchema,
1639
+ 404: errorSchema,
1640
+ 409: errorSchema
1641
+ },
1642
+ summary: "Drain or cancel a team ESP"
1643
+ }
1644
+ },
1645
+ { metadata: { tag: "Settings" } }
1646
+ );
1647
+ var generalSettingsContract = c.router(
1648
+ {
1649
+ get: {
1650
+ method: "GET",
1651
+ path: "/settings/general",
1652
+ responses: { 200: generalSettingsSchema },
1653
+ summary: "Get the team's general settings",
1654
+ description: "Returns defaults (all-null fields) when nothing has been saved yet."
1655
+ },
1656
+ update: {
1657
+ method: "PUT",
1658
+ path: "/settings/general",
1659
+ body: updateGeneralSettingsBodySchema,
1660
+ responses: { 200: generalSettingsSchema },
1661
+ summary: "Update the team's general settings",
1662
+ description: "Omitted fields are left unchanged; send an empty string to clear a field."
1663
+ }
1664
+ },
1665
+ { metadata: { tag: "Settings" } }
1666
+ );
1667
+ var settingsContract = c.router({
1668
+ esps: espCollectionContract,
1669
+ general: generalSettingsContract
1670
+ });
1671
+ var teamsContract = c.router(
1672
+ {
1673
+ list: {
1674
+ method: "GET",
1675
+ path: "/teams",
1676
+ responses: { 200: itemsList(teamSchema) },
1677
+ summary: "List the teams the current user belongs to"
1678
+ },
1679
+ create: {
1680
+ method: "POST",
1681
+ path: "/teams",
1682
+ body: createTeamBodySchema,
1683
+ responses: {
1684
+ 201: teamSchema,
1685
+ 403: errorSchema,
1686
+ 409: errorSchema
1687
+ },
1688
+ summary: "Create a new team"
1689
+ },
1690
+ rename: {
1691
+ method: "PATCH",
1692
+ path: "/teams/:teamId",
1693
+ body: renameTeamBodySchema,
1694
+ responses: { 200: teamSchema, 404: errorSchema },
1695
+ summary: "Rename a team"
1696
+ },
1697
+ remove: {
1698
+ method: "DELETE",
1699
+ path: "/teams/:teamId",
1700
+ responses: { 204: c.noBody(), 403: errorSchema, 404: errorSchema },
1701
+ summary: "Archive a team"
1702
+ },
1703
+ listKeys: {
1704
+ method: "GET",
1705
+ path: "/teams/:teamId/keys",
1706
+ responses: { 200: itemsList(apiKeySchema), 404: errorSchema },
1707
+ summary: "List a team's API keys"
1708
+ },
1709
+ createKey: {
1710
+ method: "POST",
1711
+ path: "/teams/:teamId/keys",
1712
+ body: createApiKeyBodySchema,
1713
+ responses: { 201: createdApiKeySchema, 404: errorSchema },
1714
+ summary: "Create a new API key for a team",
1715
+ description: "The response's `key` field is the full secret and is only ever returned once \u2014 store it securely. Subsequent listings only expose the key's prefix."
1716
+ },
1717
+ removeKey: {
1718
+ method: "DELETE",
1719
+ path: "/teams/:teamId/keys/:keyId",
1720
+ responses: { 204: c.noBody(), 404: errorSchema },
1721
+ summary: "Revoke an API key by its id"
1722
+ }
1723
+ },
1724
+ { metadata: { tag: "Teams" } }
1725
+ );
1726
+ var provisioningContract = c.router(
1727
+ {
1728
+ provisionTeam: {
1729
+ method: "POST",
1730
+ path: "/provisioning/teams",
1731
+ body: provisionTeamBodySchema,
1732
+ responses: {
1733
+ 200: provisionTeamResponseSchema,
1734
+ 400: errorSchema,
1735
+ 401: errorSchema,
1736
+ 403: errorSchema,
1737
+ 409: errorSchema,
1738
+ 500: errorSchema
1739
+ },
1740
+ summary: "Find-or-create a team for a consumer-supplied tenant id",
1741
+ description: "Server-to-server endpoint for multi-tenant consumers (e.g. CourseLit) to provision one SendLit team per tenant. Requires a scoped organization key as a Bearer token."
1742
+ },
1743
+ getTeam: {
1744
+ method: "GET",
1745
+ path: "/provisioning/teams/:teamId",
1746
+ responses: {
1747
+ 200: provisionedTeamSchema,
1748
+ 403: errorSchema,
1749
+ 404: errorSchema
1750
+ },
1751
+ summary: "Get a provisioned team within the authenticated organization"
1752
+ },
1753
+ updateTeam: {
1754
+ method: "PATCH",
1755
+ path: "/provisioning/teams/:teamId",
1756
+ body: updateProvisionedTeamBodySchema,
1757
+ responses: {
1758
+ 200: provisionedTeamSchema,
1759
+ 403: errorSchema,
1760
+ 404: errorSchema,
1761
+ 409: errorSchema
1762
+ },
1763
+ summary: "Update a provisioned team's sender, limits, or settings"
1764
+ },
1765
+ createTeamKey: {
1766
+ method: "POST",
1767
+ path: "/provisioning/teams/:teamId/keys",
1768
+ body: createApiKeyBodySchema,
1769
+ responses: {
1770
+ 201: createdApiKeySchema,
1771
+ 403: errorSchema,
1772
+ 404: errorSchema
1773
+ },
1774
+ summary: "Replace a provisioned team's integration key"
1775
+ },
1776
+ suspendTeam: {
1777
+ method: "POST",
1778
+ path: "/provisioning/teams/:teamId/suspend",
1779
+ body: c.noBody(),
1780
+ responses: {
1781
+ 200: provisionedTeamSchema,
1782
+ 403: errorSchema,
1783
+ 404: errorSchema,
1784
+ 409: errorSchema
1785
+ },
1786
+ summary: "Suspend new sends for a provisioned team"
1787
+ },
1788
+ resumeTeam: {
1789
+ method: "POST",
1790
+ path: "/provisioning/teams/:teamId/resume",
1791
+ body: c.noBody(),
1792
+ responses: {
1793
+ 200: provisionedTeamSchema,
1794
+ 403: errorSchema,
1795
+ 404: errorSchema,
1796
+ 409: errorSchema
1797
+ },
1798
+ summary: "Resume sends for a provisioned team"
1799
+ },
1800
+ archiveTeam: {
1801
+ method: "DELETE",
1802
+ path: "/provisioning/teams/:teamId",
1803
+ responses: { 204: c.noBody(), 403: errorSchema, 404: errorSchema },
1804
+ summary: "Archive a provisioned team"
1805
+ },
1806
+ getTeamUsage: {
1807
+ method: "GET",
1808
+ path: "/provisioning/teams/:teamId/usage",
1809
+ responses: {
1810
+ 200: provisionedTeamUsageSchema,
1811
+ 403: errorSchema,
1812
+ 404: errorSchema
1813
+ },
1814
+ summary: "Get organization-delivery quota usage for a provisioned team"
1815
+ }
1816
+ },
1817
+ { metadata: { tag: "Teams" } }
1818
+ );
1819
+ var organizationsContract = c.router(
1820
+ {
1821
+ list: {
1822
+ method: "GET",
1823
+ path: "/organizations",
1824
+ responses: {
1825
+ 200: itemsList(organizationSchema),
1826
+ 403: errorSchema
1827
+ },
1828
+ summary: "List organizations for the current user"
1829
+ },
1830
+ create: {
1831
+ method: "POST",
1832
+ path: "/organizations",
1833
+ body: createOrganizationBodySchema,
1834
+ responses: { 201: organizationSchema, 403: errorSchema },
1835
+ summary: "Create an organization"
1836
+ },
1837
+ get: {
1838
+ method: "GET",
1839
+ path: "/organizations/:organizationId",
1840
+ responses: {
1841
+ 200: organizationSchema,
1842
+ 403: errorSchema,
1843
+ 404: errorSchema
1844
+ },
1845
+ summary: "Get an organization"
1846
+ },
1847
+ update: {
1848
+ method: "PATCH",
1849
+ path: "/organizations/:organizationId",
1850
+ body: updateOrganizationBodySchema,
1851
+ responses: {
1852
+ 200: organizationSchema,
1853
+ 403: errorSchema,
1854
+ 404: errorSchema
1855
+ },
1856
+ summary: "Update an organization"
1857
+ },
1858
+ close: {
1859
+ method: "DELETE",
1860
+ path: "/organizations/:organizationId",
1861
+ responses: {
1862
+ 204: c.noBody(),
1863
+ 403: errorSchema,
1864
+ 404: errorSchema
1865
+ },
1866
+ summary: "Close an organization"
1867
+ },
1868
+ listMembers: {
1869
+ method: "GET",
1870
+ path: "/organizations/:organizationId/members",
1871
+ responses: {
1872
+ 200: itemsList(organizationMemberSchema),
1873
+ 403: errorSchema,
1874
+ 404: errorSchema
1875
+ },
1876
+ summary: "List organization members"
1877
+ },
1878
+ addMember: {
1879
+ method: "POST",
1880
+ path: "/organizations/:organizationId/members",
1881
+ body: addOrganizationMemberBodySchema,
1882
+ responses: {
1883
+ 201: organizationMemberSchema,
1884
+ 403: errorSchema,
1885
+ 404: errorSchema,
1886
+ 409: errorSchema
1887
+ },
1888
+ summary: "Add an existing user to an organization"
1889
+ },
1890
+ updateMember: {
1891
+ method: "PATCH",
1892
+ path: "/organizations/:organizationId/members/:userId",
1893
+ body: updateOrganizationMemberBodySchema,
1894
+ responses: {
1895
+ 200: organizationMemberSchema,
1896
+ 403: errorSchema,
1897
+ 404: errorSchema,
1898
+ 409: errorSchema
1899
+ },
1900
+ summary: "Change an organization member role"
1901
+ },
1902
+ removeMember: {
1903
+ method: "DELETE",
1904
+ path: "/organizations/:organizationId/members/:userId",
1905
+ responses: {
1906
+ 204: c.noBody(),
1907
+ 403: errorSchema,
1908
+ 404: errorSchema,
1909
+ 409: errorSchema
1910
+ },
1911
+ summary: "Remove an organization member"
1912
+ },
1913
+ listTeams: {
1914
+ method: "GET",
1915
+ path: "/organizations/:organizationId/teams",
1916
+ responses: {
1917
+ 200: itemsList(teamSchema),
1918
+ 403: errorSchema,
1919
+ 404: errorSchema
1920
+ },
1921
+ summary: "List teams in an organization"
1922
+ },
1923
+ createTeam: {
1924
+ method: "POST",
1925
+ path: "/organizations/:organizationId/teams",
1926
+ body: createTeamBodySchema,
1927
+ responses: {
1928
+ 201: teamSchema,
1929
+ 403: errorSchema,
1930
+ 404: errorSchema,
1931
+ 409: errorSchema
1932
+ },
1933
+ summary: "Create a human-managed team in an organization"
1934
+ },
1935
+ getTeam: {
1936
+ method: "GET",
1937
+ path: "/organizations/:organizationId/teams/:teamId",
1938
+ responses: { 200: teamSchema, 403: errorSchema, 404: errorSchema },
1939
+ summary: "Get organization team metadata"
1940
+ },
1941
+ updateTeam: {
1942
+ method: "PATCH",
1943
+ path: "/organizations/:organizationId/teams/:teamId",
1944
+ body: renameTeamBodySchema,
1945
+ responses: { 200: teamSchema, 403: errorSchema, 404: errorSchema },
1946
+ summary: "Rename an organization team"
1947
+ },
1948
+ archiveTeam: {
1949
+ method: "DELETE",
1950
+ path: "/organizations/:organizationId/teams/:teamId",
1951
+ responses: { 204: c.noBody(), 403: errorSchema, 404: errorSchema },
1952
+ summary: "Archive an organization team"
1953
+ },
1954
+ listKeys: {
1955
+ method: "GET",
1956
+ path: "/organizations/:organizationId/keys",
1957
+ responses: {
1958
+ 200: itemsList(organizationApiKeySchema),
1959
+ 403: errorSchema,
1960
+ 404: errorSchema
1961
+ },
1962
+ summary: "List organization API keys"
1963
+ },
1964
+ createKey: {
1965
+ method: "POST",
1966
+ path: "/organizations/:organizationId/keys",
1967
+ body: createOrganizationApiKeyBodySchema,
1968
+ responses: {
1969
+ 201: createdOrganizationApiKeySchema,
1970
+ 403: errorSchema,
1971
+ 404: errorSchema
1972
+ },
1973
+ summary: "Create an organization API key"
1974
+ },
1975
+ revokeKey: {
1976
+ method: "DELETE",
1977
+ path: "/organizations/:organizationId/keys/:keyId",
1978
+ responses: {
1979
+ 204: c.noBody(),
1980
+ 403: errorSchema,
1981
+ 404: errorSchema
1982
+ },
1983
+ summary: "Revoke an organization API key"
1984
+ },
1985
+ listEsps: {
1986
+ method: "GET",
1987
+ path: "/organizations/:organizationId/esps",
1988
+ responses: {
1989
+ 200: itemsList(espConfigSchema),
1990
+ 403: errorSchema,
1991
+ 404: errorSchema
1992
+ },
1993
+ summary: "List organization-owned ESP configurations"
1994
+ },
1995
+ createEsp: {
1996
+ method: "POST",
1997
+ path: "/organizations/:organizationId/esps",
1998
+ body: createEspConfigBodySchema,
1999
+ responses: {
2000
+ 201: espConfigSchema,
2001
+ 403: errorSchema,
2002
+ 404: errorSchema
2003
+ },
2004
+ summary: "Create an organization-owned ESP configuration"
2005
+ },
2006
+ getEsp: {
2007
+ method: "GET",
2008
+ path: "/organizations/:organizationId/esps/:espId",
2009
+ responses: {
2010
+ 200: espConfigSchema,
2011
+ 403: errorSchema,
2012
+ 404: errorSchema
2013
+ },
2014
+ summary: "Get an organization-owned ESP configuration"
2015
+ },
2016
+ updateEsp: {
2017
+ method: "PATCH",
2018
+ path: "/organizations/:organizationId/esps/:espId",
2019
+ body: updateEspConfigBodySchema,
2020
+ responses: {
2021
+ 200: espConfigSchema,
2022
+ 403: errorSchema,
2023
+ 404: errorSchema,
2024
+ 409: errorSchema
2025
+ },
2026
+ summary: "Update an organization-owned ESP configuration"
2027
+ },
2028
+ testEsp: {
2029
+ method: "POST",
2030
+ path: "/organizations/:organizationId/esps/:espId/test",
2031
+ body: testEspConfigBodySchema,
2032
+ responses: {
2033
+ 200: testEspConfigResponseSchema,
2034
+ 400: errorSchema,
2035
+ 403: errorSchema,
2036
+ 404: errorSchema,
2037
+ 422: errorSchema,
2038
+ 502: testEspConfigResponseSchema
2039
+ },
2040
+ summary: "Test an organization-owned ESP configuration"
2041
+ },
2042
+ activateEsp: {
2043
+ method: "POST",
2044
+ path: "/organizations/:organizationId/esps/:espId/activate",
2045
+ body: c.noBody(),
2046
+ responses: {
2047
+ 200: espConfigSchema,
2048
+ 403: errorSchema,
2049
+ 404: errorSchema,
2050
+ 409: errorSchema,
2051
+ 422: errorSchema
2052
+ },
2053
+ summary: "Activate a verified organization ESP"
2054
+ },
2055
+ suspendEsp: {
2056
+ method: "POST",
2057
+ path: "/organizations/:organizationId/esps/:espId/suspend",
2058
+ body: c.noBody(),
2059
+ responses: {
2060
+ 200: espConfigSchema,
2061
+ 403: errorSchema,
2062
+ 404: errorSchema,
2063
+ 409: errorSchema
2064
+ },
2065
+ summary: "Suspend an organization ESP"
2066
+ },
2067
+ resumeEsp: {
2068
+ method: "POST",
2069
+ path: "/organizations/:organizationId/esps/:espId/resume",
2070
+ body: c.noBody(),
2071
+ responses: {
2072
+ 200: espConfigSchema,
2073
+ 403: errorSchema,
2074
+ 404: errorSchema,
2075
+ 409: errorSchema
2076
+ },
2077
+ summary: "Resume an organization ESP"
2078
+ },
2079
+ retireEsp: {
2080
+ method: "POST",
2081
+ path: "/organizations/:organizationId/esps/:espId/retire",
2082
+ body: retireEspConfigBodySchema,
2083
+ responses: {
2084
+ 200: espConfigSchema,
2085
+ 403: errorSchema,
2086
+ 404: errorSchema,
2087
+ 409: errorSchema
2088
+ },
2089
+ summary: "Drain or cancel an organization ESP"
2090
+ },
2091
+ deleteEsp: {
2092
+ method: "DELETE",
2093
+ path: "/organizations/:organizationId/esps/:espId",
2094
+ responses: {
2095
+ 204: c.noBody(),
2096
+ 403: errorSchema,
2097
+ 404: errorSchema,
2098
+ 409: errorSchema
2099
+ },
2100
+ summary: "Delete an eligible never-activated organization ESP"
2101
+ },
2102
+ getEspFeedback: {
2103
+ method: "GET",
2104
+ path: "/organizations/:organizationId/esps/:espId/feedback",
2105
+ responses: {
2106
+ 200: feedbackConnectionSchema.nullable(),
2107
+ 403: errorSchema,
2108
+ 404: errorSchema
2109
+ },
2110
+ summary: "Get organization ESP feedback configuration"
2111
+ },
2112
+ upsertEspFeedback: {
2113
+ method: "PUT",
2114
+ path: "/organizations/:organizationId/esps/:espId/feedback",
2115
+ body: upsertFeedbackConnectionBodySchema,
2116
+ responses: {
2117
+ 200: feedbackConnectionSchema,
2118
+ 400: errorSchema,
2119
+ 403: errorSchema,
2120
+ 404: errorSchema
2121
+ },
2122
+ summary: "Configure organization ESP feedback"
2123
+ },
2124
+ rotateEspFeedback: {
2125
+ method: "POST",
2126
+ path: "/organizations/:organizationId/esps/:espId/feedback/rotate",
2127
+ body: upsertFeedbackConnectionBodySchema,
2128
+ responses: {
2129
+ 200: feedbackConnectionSchema,
2130
+ 403: errorSchema,
2131
+ 404: errorSchema
2132
+ },
2133
+ summary: "Rotate organization ESP feedback credentials"
2134
+ },
2135
+ testEspFeedback: {
2136
+ method: "POST",
2137
+ path: "/organizations/:organizationId/esps/:espId/feedback/test",
2138
+ body: c.noBody(),
2139
+ responses: {
2140
+ 200: testFeedbackConnectionResponseSchema,
2141
+ 403: errorSchema,
2142
+ 404: errorSchema
2143
+ },
2144
+ summary: "Verify organization ESP feedback configuration"
2145
+ },
2146
+ removeEspFeedback: {
2147
+ method: "DELETE",
2148
+ path: "/organizations/:organizationId/esps/:espId/feedback",
2149
+ responses: {
2150
+ 204: c.noBody(),
2151
+ 403: errorSchema,
2152
+ 404: errorSchema
2153
+ },
2154
+ summary: "Disable organization ESP feedback configuration"
2155
+ },
2156
+ getDeliveryPolicy: {
2157
+ method: "GET",
2158
+ path: "/organizations/:organizationId/delivery-policy",
2159
+ responses: {
2160
+ 200: organizationDeliveryPolicySchema,
2161
+ 403: errorSchema,
2162
+ 404: errorSchema
2163
+ },
2164
+ summary: "Get organization delivery policy"
2165
+ },
2166
+ updateDeliveryPolicy: {
2167
+ method: "PUT",
2168
+ path: "/organizations/:organizationId/delivery-policy",
2169
+ body: updateOrganizationDeliveryPolicyBodySchema,
2170
+ responses: {
2171
+ 200: organizationDeliveryPolicySchema,
2172
+ 403: errorSchema,
2173
+ 404: errorSchema,
2174
+ 422: errorSchema
2175
+ },
2176
+ summary: "Update organization delivery policy"
2177
+ },
2178
+ getUsage: {
2179
+ method: "GET",
2180
+ path: "/organizations/:organizationId/usage",
2181
+ responses: {
2182
+ 200: organizationUsageSchema,
2183
+ 403: errorSchema,
2184
+ 404: errorSchema
2185
+ },
2186
+ summary: "Get aggregate organization delivery quota usage"
2187
+ },
2188
+ getMailActivity: {
2189
+ method: "GET",
2190
+ path: "/organizations/:organizationId/mail-activity",
2191
+ query: organizationMailActivityQuerySchema,
2192
+ responses: {
2193
+ 200: organizationMailActivitySchema,
2194
+ 400: errorSchema,
2195
+ 403: errorSchema,
2196
+ 404: errorSchema
2197
+ },
2198
+ summary: "Get organization transactional mail activity",
2199
+ description: "Returns per-team and organization-total transactional mail counts (`sent`, `queued`, `failed`, `bounced`) for a window of 1, 3, 7, or 30 days (default 7). Includes teams with zero activity. Does not include campaigns, broadcasts, sequences, recipients, subjects, or email bodies. Shared-delivery quota remains on `/usage`."
2200
+ },
2201
+ enterTeam: {
2202
+ method: "POST",
2203
+ path: "/organizations/:organizationId/teams/:teamId/enter",
2204
+ body: organizationEnterTeamBodySchema,
2205
+ responses: {
2206
+ 200: organizationEnterTeamResponseSchema,
2207
+ 403: errorSchema,
2208
+ 404: errorSchema,
2209
+ 422: errorSchema
2210
+ },
2211
+ summary: "Enter an organization team as a human admin",
2212
+ description: "Grants the calling human organization owner or administrator a permanent team `admin` membership, recorded as organization audit action `team.entered`. Organization API keys cannot enter. Archived teams cannot be entered. Idempotent if membership already exists."
2213
+ },
2214
+ listAuditEvents: {
2215
+ method: "GET",
2216
+ path: "/organizations/:organizationId/audit-events",
2217
+ responses: {
2218
+ 200: itemsList(organizationAuditEventSchema),
2219
+ 403: errorSchema,
2220
+ 404: errorSchema
2221
+ },
2222
+ summary: "List recent organization audit events"
2223
+ },
2224
+ getEspGrant: {
2225
+ method: "GET",
2226
+ path: "/organizations/:organizationId/teams/:teamId/esp-grant",
2227
+ responses: {
2228
+ 200: espGrantSchema.nullable(),
2229
+ 403: errorSchema,
2230
+ 404: errorSchema
2231
+ },
2232
+ summary: "Get a team's organization ESP grant"
2233
+ },
2234
+ upsertEspGrant: {
2235
+ method: "PUT",
2236
+ path: "/organizations/:organizationId/teams/:teamId/esp-grant",
2237
+ body: upsertEspGrantBodySchema,
2238
+ responses: {
2239
+ 200: espGrantSchema,
2240
+ 403: errorSchema,
2241
+ 404: errorSchema,
2242
+ 409: errorSchema,
2243
+ 422: errorSchema
2244
+ },
2245
+ summary: "Create or update a team's organization ESP grant"
2246
+ },
2247
+ transitionEspGrant: {
2248
+ method: "POST",
2249
+ path: "/organizations/:organizationId/teams/:teamId/esp-grant/transition",
2250
+ body: transitionEspGrantBodySchema,
2251
+ responses: {
2252
+ 200: espGrantSchema,
2253
+ 403: errorSchema,
2254
+ 404: errorSchema,
2255
+ 409: errorSchema
2256
+ },
2257
+ summary: "Transition a team's organization ESP grant; revoking detaches safe campaigns"
2258
+ }
2259
+ },
2260
+ { metadata: { tag: "Organizations" } }
2261
+ );
2262
+ var deliveryContract = c.router(
2263
+ {
2264
+ sendingOptions: {
2265
+ method: "GET",
2266
+ path: "/sending-options",
2267
+ responses: { 200: itemsList(sendingOptionSchema) },
2268
+ summary: "List sanitized sending options for the active team"
2269
+ },
2270
+ getSettings: {
2271
+ method: "GET",
2272
+ path: "/settings/delivery",
2273
+ responses: { 200: teamDeliverySettingsSchema },
2274
+ summary: "Get team delivery settings"
2275
+ },
2276
+ updateSettings: {
2277
+ method: "PATCH",
2278
+ path: "/settings/delivery",
2279
+ body: updateTeamDeliverySettingsBodySchema,
2280
+ responses: {
2281
+ 200: teamDeliverySettingsSchema,
2282
+ 403: errorSchema,
2283
+ 409: errorSchema,
2284
+ 422: errorSchema
2285
+ },
2286
+ summary: "Choose the team's default delivery source"
2287
+ }
2288
+ },
2289
+ { metadata: { tag: "Delivery" } }
2290
+ );
2291
+ var overviewContract = c.router(
2292
+ {
2293
+ get: {
2294
+ method: "GET",
2295
+ path: "/overview",
2296
+ query: overviewQuerySchema,
2297
+ responses: { 200: overviewSchema },
2298
+ summary: "Get team overview metrics for a delivery activity window",
2299
+ description: "Use `rangeDays` (1, 3, 7, or 30; default 7) to filter transactional delivery activity and scheduled broadcasts."
2300
+ }
2301
+ },
2302
+ { metadata: { tag: "Overview" } }
2303
+ );
2304
+ var feedbackContract = c.router(
2305
+ {
2306
+ get: {
2307
+ method: "GET",
2308
+ path: "/settings/esps/:espId/feedback",
2309
+ responses: {
2310
+ 200: feedbackConnectionSchema.nullable(),
2311
+ 404: errorSchema
2312
+ },
2313
+ summary: "Get a user ESP's delivery-feedback connection",
2314
+ description: "Returns null when feedback hasn't been configured for this ESP yet."
2315
+ },
2316
+ upsert: {
2317
+ method: "PUT",
2318
+ path: "/settings/esps/:espId/feedback",
2319
+ body: upsertFeedbackConnectionBodySchema,
2320
+ responses: {
2321
+ 200: feedbackConnectionSchema,
2322
+ 400: errorSchema,
2323
+ 404: errorSchema
2324
+ },
2325
+ summary: "Create or rotate a user ESP's delivery-feedback connection",
2326
+ description: "Creates the connection (and its stable webhook URL) on first call; a later call rotates the credential without changing the URL. The provider is always the ESP's current provider, not client-writable."
2327
+ },
2328
+ rotate: {
2329
+ method: "POST",
2330
+ path: "/settings/esps/:espId/feedback/rotate",
2331
+ body: upsertFeedbackConnectionBodySchema,
2332
+ responses: {
2333
+ 200: feedbackConnectionSchema,
2334
+ 400: errorSchema,
2335
+ 404: errorSchema
2336
+ },
2337
+ summary: "Rotate an existing feedback connection's credential",
2338
+ description: "Same effect as PUT, but fails with 404 if no connection exists yet. The previous credential remains valid for 24h so in-flight provider retries aren't lost."
2339
+ },
2340
+ test: {
2341
+ method: "POST",
2342
+ path: "/settings/esps/:espId/feedback/test",
2343
+ body: c.noBody(),
2344
+ responses: {
2345
+ 200: testFeedbackConnectionResponseSchema,
2346
+ 404: errorSchema
2347
+ },
2348
+ summary: "Verify a feedback connection's stored credential"
2349
+ },
2350
+ remove: {
2351
+ method: "DELETE",
2352
+ path: "/settings/esps/:espId/feedback",
2353
+ responses: { 204: c.noBody(), 404: errorSchema },
2354
+ summary: "Disable a user ESP's delivery-feedback connection"
2355
+ }
2356
+ },
2357
+ { metadata: { tag: "Settings" } }
2358
+ );
2359
+ var deliveryEventsContract = c.router(
2360
+ {
2361
+ list: {
2362
+ method: "GET",
2363
+ path: "/delivery-events",
2364
+ query: listDeliveryEventsQuerySchema,
2365
+ responses: { 200: paginated(deliveryEventSchema) },
2366
+ summary: "List normalized delivery events for the team"
2367
+ },
2368
+ get: {
2369
+ method: "GET",
2370
+ path: "/delivery-events/:eventId",
2371
+ responses: { 200: deliveryEventSchema, 404: errorSchema },
2372
+ summary: "Get a single normalized delivery event"
2373
+ }
2374
+ },
2375
+ { metadata: { tag: "Delivery" } }
2376
+ );
2377
+ var suppressionsContract = c.router(
2378
+ {
2379
+ list: {
2380
+ method: "GET",
2381
+ path: "/suppressions",
2382
+ query: listSuppressionsQuerySchema,
2383
+ responses: { 200: paginated(suppressionSchema) },
2384
+ summary: "List the team's suppressed recipients"
2385
+ },
2386
+ get: {
2387
+ method: "GET",
2388
+ path: "/suppressions/:suppressionId",
2389
+ responses: { 200: suppressionSchema, 404: errorSchema },
2390
+ summary: "Get a single suppression"
2391
+ },
2392
+ release: {
2393
+ method: "POST",
2394
+ path: "/suppressions/:suppressionId/release",
2395
+ body: releaseSuppressionBodySchema,
2396
+ responses: {
2397
+ 200: suppressionSchema,
2398
+ 404: errorSchema,
2399
+ 409: errorSchema
2400
+ },
2401
+ summary: "Release an active suppression",
2402
+ description: "A workspace owner may release hard_bounce, repeated_soft_bounce, and manual suppressions only. Complaint suppressions cannot be released through this endpoint (409 suppression_not_releasable) \u2014 see the PRD's reactivation policy."
2403
+ }
2404
+ },
2405
+ { metadata: { tag: "Delivery" } }
2406
+ );
2407
+ var contract = c.router({
2408
+ contacts: contactsContract,
2409
+ segments: segmentsContract,
2410
+ media: mediaContract,
2411
+ templates: templatesContract,
2412
+ sequences: sequencesContract,
2413
+ transactional: transactionalContract,
2414
+ settings: settingsContract,
2415
+ teams: teamsContract,
2416
+ organizations: organizationsContract,
2417
+ delivery: deliveryContract,
2418
+ provisioning: provisioningContract,
2419
+ overview: overviewContract,
2420
+ feedback: feedbackContract,
2421
+ deliveryEvents: deliveryEventsContract,
2422
+ suppressions: suppressionsContract
2423
+ });
2424
+
2425
+ // src/validate.ts
2426
+ var ID_PATTERN = /^[A-Za-z0-9_-]+$/;
2427
+ function invalid(message) {
2428
+ return new SendLitError({ status: 0, code: "invalid_argument", message });
2429
+ }
2430
+ function assertId(value, name) {
2431
+ if (typeof value !== "string" || !ID_PATTERN.test(value)) {
2432
+ throw invalid(`Invalid ${name}: expected a SendLit ID`);
2433
+ }
2434
+ return value;
2435
+ }
2436
+ function encodeSegment(value, name) {
2437
+ if (typeof value !== "string" || value.trim().length === 0) {
2438
+ throw invalid(`Invalid ${name}: expected a non-empty string`);
2439
+ }
2440
+ return encodeURIComponent(value);
2441
+ }
2442
+
2443
+ // src/resources/contacts.ts
2444
+ var routes = contract.contacts;
2445
+ var Contacts = class {
2446
+ constructor(http) {
2447
+ this.http = http;
2448
+ }
2449
+ /**
2450
+ * Find-or-create by email within the team. A newly created contact fires
2451
+ * `subscriber:added`, enrolling it in active sequences with that trigger.
2452
+ * If the email already exists, the existing contact is returned
2453
+ * unchanged and **no event fires**, so it is not re-enrolled. Tags passed
2454
+ * here don't fire `tag:added`.
2455
+ */
2456
+ async create(input) {
2457
+ return this.http.request(routes.create, {
2458
+ body: input,
2459
+ retrySafe: true
2460
+ });
2461
+ }
2462
+ async list(query = {}) {
2463
+ return this.http.request(routes.list, { query });
2464
+ }
2465
+ /** Iterates every contact matching `query`, fetching pages lazily. */
2466
+ listAll(query = {}) {
2467
+ return paginate((offset) => this.list({ ...query, offset }));
2468
+ }
2469
+ async get(contactId) {
2470
+ return this.http.request(routes.get, {
2471
+ params: { contactId: assertId(contactId, "contactId") }
2472
+ });
2473
+ }
2474
+ async update(contactId, input) {
2475
+ return this.http.request(routes.update, {
2476
+ params: { contactId: assertId(contactId, "contactId") },
2477
+ body: input
2478
+ });
2479
+ }
2480
+ async remove(contactId) {
2481
+ await this.http.request(routes.remove, {
2482
+ params: { contactId: assertId(contactId, "contactId") }
2483
+ });
2484
+ }
2485
+ async addTag(contactId, tag) {
2486
+ return this.http.request(routes.addTag, {
2487
+ params: {
2488
+ contactId: assertId(contactId, "contactId"),
2489
+ tag: encodeSegment(tag, "tag")
2490
+ },
2491
+ retrySafe: true
2492
+ });
2493
+ }
2494
+ async removeTag(contactId, tag) {
2495
+ return this.http.request(routes.removeTag, {
2496
+ params: {
2497
+ contactId: assertId(contactId, "contactId"),
2498
+ tag: encodeSegment(tag, "tag")
2499
+ }
2500
+ });
2501
+ }
2502
+ /** Broadcast and sequence emails delivered to this contact. */
2503
+ async deliveries(contactId) {
2504
+ return this.http.request(routes.deliveries, {
2505
+ params: { contactId: assertId(contactId, "contactId") }
2506
+ });
2507
+ }
2508
+ };
2509
+
2510
+ // src/resources/delivery-events.ts
2511
+ var routes2 = contract.deliveryEvents;
2512
+ var DeliveryEvents = class {
2513
+ constructor(http) {
2514
+ this.http = http;
2515
+ }
2516
+ async list(query = {}) {
2517
+ return this.http.request(routes2.list, { query });
2518
+ }
2519
+ listAll(query = {}) {
2520
+ return paginate((offset) => this.list({ ...query, offset }));
2521
+ }
2522
+ async get(eventId) {
2523
+ return this.http.request(routes2.get, {
2524
+ params: { eventId: assertId(eventId, "eventId") }
2525
+ });
2526
+ }
2527
+ };
2528
+
2529
+ // src/resources/emails.ts
2530
+ var routes3 = contract.transactional;
2531
+ var Emails = class {
2532
+ constructor(http) {
2533
+ this.http = http;
2534
+ }
2535
+ /**
2536
+ * Queues one email and resolves with its id and initial status; poll
2537
+ * `get` for delivery progress. Passing `idempotencyKey` makes the call
2538
+ * safe to retry, so the SDK retries it on 5xx and network errors too.
2539
+ */
2540
+ async send(input) {
2541
+ return this.http.request(routes3.send, {
2542
+ body: input,
2543
+ retrySafe: !!input.idempotencyKey
2544
+ });
2545
+ }
2546
+ async get(txeId) {
2547
+ return this.http.request(routes3.get, {
2548
+ params: { txeId: assertId(txeId, "txeId") }
2549
+ });
2550
+ }
2551
+ async list(query = {}) {
2552
+ return this.http.request(routes3.list, { query });
2553
+ }
2554
+ listAll(query = {}) {
2555
+ return paginate((offset) => this.list({ ...query, offset }));
2556
+ }
2557
+ };
2558
+
2559
+ // src/resources/provisioning.ts
2560
+ var routes4 = contract.provisioning;
2561
+ var Provisioning = class {
2562
+ constructor(http) {
2563
+ this.http = http;
2564
+ }
2565
+ /**
2566
+ * Find-or-create the team for `externalId` (`teams:provision`). Only the
2567
+ * first call returns the plaintext team key (`apiKey`); replays return
2568
+ * `created: false, apiKey: null`, so it's safe to retry.
2569
+ */
2570
+ async provisionTeam(input) {
2571
+ return this.http.request(routes4.provisionTeam, {
2572
+ body: input,
2573
+ retrySafe: true
2574
+ });
2575
+ }
2576
+ /** `teams:read` */
2577
+ async getTeam(teamId) {
2578
+ return this.http.request(routes4.getTeam, {
2579
+ params: { teamId: assertId(teamId, "teamId") }
2580
+ });
2581
+ }
2582
+ /** `teams:manage` */
2583
+ async updateTeam(teamId, input) {
2584
+ return this.http.request(routes4.updateTeam, {
2585
+ params: { teamId: assertId(teamId, "teamId") },
2586
+ body: input
2587
+ });
2588
+ }
2589
+ /** Replaces the team's integration key (`teams:keys`); keys previously
2590
+ * issued through provisioning are revoked. */
2591
+ async createTeamKey(teamId, input) {
2592
+ return this.http.request(routes4.createTeamKey, {
2593
+ params: { teamId: assertId(teamId, "teamId") },
2594
+ body: input
2595
+ });
2596
+ }
2597
+ /** `teams:manage` */
2598
+ async suspendTeam(teamId) {
2599
+ return this.http.request(routes4.suspendTeam, {
2600
+ params: { teamId: assertId(teamId, "teamId") }
2601
+ });
2602
+ }
2603
+ /** `teams:manage` */
2604
+ async resumeTeam(teamId) {
2605
+ return this.http.request(routes4.resumeTeam, {
2606
+ params: { teamId: assertId(teamId, "teamId") }
2607
+ });
2608
+ }
2609
+ /** Soft-deprovisions the team (`teams:manage`). There is no unarchive. */
2610
+ async archiveTeam(teamId) {
2611
+ await this.http.request(routes4.archiveTeam, {
2612
+ params: { teamId: assertId(teamId, "teamId") }
2613
+ });
2614
+ }
2615
+ /** `usage:read` */
2616
+ async getTeamUsage(teamId) {
2617
+ return this.http.request(routes4.getTeamUsage, {
2618
+ params: { teamId: assertId(teamId, "teamId") }
2619
+ });
2620
+ }
2621
+ };
2622
+
2623
+ // src/resources/segments.ts
2624
+ var routes5 = contract.segments;
2625
+ var Segments = class {
2626
+ constructor(http) {
2627
+ this.http = http;
2628
+ }
2629
+ async create(input) {
2630
+ return this.http.request(routes5.create, { body: input });
2631
+ }
2632
+ async list() {
2633
+ return this.http.request(routes5.list);
2634
+ }
2635
+ async get(segmentId) {
2636
+ return this.http.request(routes5.get, {
2637
+ params: { segmentId: assertId(segmentId, "segmentId") }
2638
+ });
2639
+ }
2640
+ async update(segmentId, input) {
2641
+ return this.http.request(routes5.update, {
2642
+ params: { segmentId: assertId(segmentId, "segmentId") },
2643
+ body: input
2644
+ });
2645
+ }
2646
+ async remove(segmentId) {
2647
+ await this.http.request(routes5.remove, {
2648
+ params: { segmentId: assertId(segmentId, "segmentId") }
2649
+ });
2650
+ }
2651
+ };
2652
+
2653
+ // src/resources/sequences.ts
2654
+ var routes6 = contract.sequences;
2655
+ var Sequences = class {
2656
+ constructor(http) {
2657
+ this.http = http;
2658
+ }
2659
+ async create(input) {
2660
+ return this.http.request(routes6.create, { body: input });
2661
+ }
2662
+ async list(query) {
2663
+ return this.http.request(routes6.list, { query });
2664
+ }
2665
+ listAll(query) {
2666
+ return paginate((offset) => this.list({ ...query, offset }));
2667
+ }
2668
+ async get(sequenceId) {
2669
+ return this.http.request(routes6.get, {
2670
+ params: { sequenceId: assertId(sequenceId, "sequenceId") }
2671
+ });
2672
+ }
2673
+ async update(sequenceId, input) {
2674
+ return this.http.request(routes6.update, {
2675
+ params: { sequenceId: assertId(sequenceId, "sequenceId") },
2676
+ body: input
2677
+ });
2678
+ }
2679
+ async remove(sequenceId) {
2680
+ await this.http.request(routes6.remove, {
2681
+ params: { sequenceId: assertId(sequenceId, "sequenceId") }
2682
+ });
2683
+ }
2684
+ async addEmail(sequenceId, input) {
2685
+ return this.http.request(routes6.addEmail, {
2686
+ params: { sequenceId: assertId(sequenceId, "sequenceId") },
2687
+ body: input
2688
+ });
2689
+ }
2690
+ async updateEmail(sequenceId, emailId, input) {
2691
+ return this.http.request(routes6.updateEmail, {
2692
+ params: {
2693
+ sequenceId: assertId(sequenceId, "sequenceId"),
2694
+ emailId: assertId(emailId, "emailId")
2695
+ },
2696
+ body: input
2697
+ });
2698
+ }
2699
+ async removeEmail(sequenceId, emailId) {
2700
+ return this.http.request(routes6.removeEmail, {
2701
+ params: {
2702
+ sequenceId: assertId(sequenceId, "sequenceId"),
2703
+ emailId: assertId(emailId, "emailId")
2704
+ }
2705
+ });
2706
+ }
2707
+ /** Sends a broadcast, or activates a sequence so its trigger starts
2708
+ * enrolling contacts. Requires a mailing address in general settings. */
2709
+ async start(sequenceId) {
2710
+ return this.http.request(routes6.start, {
2711
+ params: { sequenceId: assertId(sequenceId, "sequenceId") }
2712
+ });
2713
+ }
2714
+ async pause(sequenceId) {
2715
+ return this.http.request(routes6.pause, {
2716
+ params: { sequenceId: assertId(sequenceId, "sequenceId") }
2717
+ });
2718
+ }
2719
+ async stats(sequenceId) {
2720
+ return this.http.request(routes6.stats, {
2721
+ params: { sequenceId: assertId(sequenceId, "sequenceId") }
2722
+ });
2723
+ }
2724
+ /** IDs of contacts that have received this broadcast or sequence. */
2725
+ async subscribers(sequenceId, query = {}) {
2726
+ return this.http.request(routes6.subscribers, {
2727
+ params: { sequenceId: assertId(sequenceId, "sequenceId") },
2728
+ query
2729
+ });
2730
+ }
2731
+ };
2732
+
2733
+ // src/resources/suppressions.ts
2734
+ var routes7 = contract.suppressions;
2735
+ var Suppressions = class {
2736
+ constructor(http) {
2737
+ this.http = http;
2738
+ }
2739
+ async list(query = {}) {
2740
+ return this.http.request(routes7.list, { query });
2741
+ }
2742
+ listAll(query = {}) {
2743
+ return paginate((offset) => this.list({ ...query, offset }));
2744
+ }
2745
+ async get(suppressionId) {
2746
+ return this.http.request(routes7.get, {
2747
+ params: { suppressionId: assertId(suppressionId, "suppressionId") }
2748
+ });
2749
+ }
2750
+ /** Complaint suppressions can't be released (409
2751
+ * `suppression_not_releasable`). */
2752
+ async release(suppressionId, input = {}) {
2753
+ return this.http.request(routes7.release, {
2754
+ params: { suppressionId: assertId(suppressionId, "suppressionId") },
2755
+ body: input
2756
+ });
2757
+ }
2758
+ };
2759
+
2760
+ // src/resources/templates.ts
2761
+ var routes8 = contract.templates;
2762
+ var Templates = class {
2763
+ constructor(http) {
2764
+ this.http = http;
2765
+ }
2766
+ async list(query = {}) {
2767
+ return this.http.request(routes8.list, { query });
2768
+ }
2769
+ /** Built-in starters, shared by every team. Duplicate one into the team
2770
+ * before using it for transactional sends. */
2771
+ async listSystem(query = {}) {
2772
+ return this.http.request(routes8.listSystem, { query });
2773
+ }
2774
+ async get(templateId) {
2775
+ return this.http.request(routes8.get, {
2776
+ params: { templateId: assertId(templateId, "templateId") }
2777
+ });
2778
+ }
2779
+ async create(input) {
2780
+ return this.http.request(routes8.create, { body: input });
2781
+ }
2782
+ async update(templateId, input) {
2783
+ return this.http.request(routes8.update, {
2784
+ params: { templateId: assertId(templateId, "templateId") },
2785
+ body: input
2786
+ });
2787
+ }
2788
+ async duplicate(templateId, input = {}) {
2789
+ return this.http.request(routes8.duplicate, {
2790
+ params: { templateId: assertId(templateId, "templateId") },
2791
+ body: input
2792
+ });
2793
+ }
2794
+ async remove(templateId) {
2795
+ await this.http.request(routes8.remove, {
2796
+ params: { templateId: assertId(templateId, "templateId") }
2797
+ });
2798
+ }
2799
+ };
2800
+
2801
+ // src/client.ts
2802
+ var DEFAULT_ENDPOINT = "https://api.sendlit.app";
2803
+ var ORGANIZATION_KEY_PREFIX = "sl_org_live_";
2804
+ function env(name) {
2805
+ const value = typeof process !== "undefined" ? process.env?.[name] : void 0;
2806
+ return value || void 0;
2807
+ }
2808
+ function configError(message) {
2809
+ return new SendLitError({ status: 0, code: "invalid_config", message });
2810
+ }
2811
+ var SendLit = class {
2812
+ constructor(options = {}) {
2813
+ const g = globalThis;
2814
+ if (typeof g.window !== "undefined" && g.window.document) {
2815
+ throw configError(
2816
+ "The SendLit SDK is server-only. Never expose your API key in browser code."
2817
+ );
2818
+ }
2819
+ if (options.apiKey && options.accessToken) {
2820
+ throw configError("Provide either apiKey or accessToken, not both");
2821
+ }
2822
+ const accessToken = options.accessToken;
2823
+ const apiKey = accessToken ? void 0 : options.apiKey ?? env("SENDLIT_API_KEY");
2824
+ if (!apiKey && !accessToken) {
2825
+ throw configError(
2826
+ "Missing credentials: pass apiKey or accessToken, or set SENDLIT_API_KEY"
2827
+ );
2828
+ }
2829
+ const headers = {};
2830
+ if (accessToken) {
2831
+ headers.authorization = `Bearer ${accessToken}`;
2832
+ } else if (apiKey.startsWith(ORGANIZATION_KEY_PREFIX)) {
2833
+ headers.authorization = `Bearer ${apiKey}`;
2834
+ } else {
2835
+ headers["x-sendlit-apikey"] = apiKey;
2836
+ }
2837
+ const teamId = options.teamId ?? env("SENDLIT_TEAM_ID");
2838
+ if (teamId)
2839
+ headers["x-sendlit-team-id"] = assertId(teamId, "teamId");
2840
+ const endpoint = (options.endpoint ?? env("SENDLIT_ENDPOINT") ?? DEFAULT_ENDPOINT).replace(/\/+$/, "");
2841
+ const fetchImpl = options.fetch ?? globalThis.fetch;
2842
+ if (typeof fetchImpl !== "function") {
2843
+ throw configError(
2844
+ "No fetch implementation found. Use Node.js 18+ or pass `fetch`."
2845
+ );
2846
+ }
2847
+ const http = new HttpClient({
2848
+ endpoint,
2849
+ headers,
2850
+ maxRetries: options.maxRetries ?? 2,
2851
+ timeout: options.timeout ?? 3e4,
2852
+ fetch: fetchImpl
2853
+ });
2854
+ this.contacts = new Contacts(http);
2855
+ this.segments = new Segments(http);
2856
+ this.templates = new Templates(http);
2857
+ this.sequences = new Sequences(http);
2858
+ this.emails = new Emails(http);
2859
+ this.provisioning = new Provisioning(http);
2860
+ this.suppressions = new Suppressions(http);
2861
+ this.deliveryEvents = new DeliveryEvents(http);
2862
+ }
2863
+ };
2864
+
2865
+ exports.Contacts = Contacts;
2866
+ exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
2867
+ exports.DeliveryEvents = DeliveryEvents;
2868
+ exports.Emails = Emails;
2869
+ exports.Provisioning = Provisioning;
2870
+ exports.Segments = Segments;
2871
+ exports.SendLit = SendLit;
2872
+ exports.SendLitError = SendLitError;
2873
+ exports.Sequences = Sequences;
2874
+ exports.Suppressions = Suppressions;
2875
+ exports.Templates = Templates;