sendlit 0.0.0 → 0.2.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.mjs CHANGED
@@ -14,14 +14,14 @@ var SendLitError = class extends Error {
14
14
  this.cause = init.cause;
15
15
  }
16
16
  }
17
- static fromResponse(status, body, headers) {
17
+ static fromResponse(status, body, headers2) {
18
18
  const fields = body && typeof body === "object" ? body : {};
19
19
  const text = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
20
20
  const code = text(fields.error) ?? // ts-rest's request-validation 400s carry `message` + `*Errors`
21
21
  // instead of an `error` code.
22
22
  (status === 400 ? "validation_error" : `http_${status}`);
23
23
  const message = text(fields.error_description) ?? text(fields.message) ?? text(fields.error) ?? (typeof body === "string" && body ? body : void 0) ?? `Request failed with status ${status}`;
24
- return new SendLitError({ status, code, message, body, headers });
24
+ return new SendLitError({ status, code, message, body, headers: headers2 });
25
25
  }
26
26
  };
27
27
  var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "PUT", "DELETE"]);
@@ -39,13 +39,13 @@ var HttpClient = class {
39
39
  path: route.path,
40
40
  params: args.params ?? {}
41
41
  }) + convertQueryParamsToUrlString(args.query ?? {}, false);
42
- const headers = {
42
+ const headers2 = {
43
43
  accept: "application/json",
44
44
  ...this.config.headers
45
45
  };
46
46
  let payload;
47
47
  if (route.method !== "GET" && args.body !== void 0) {
48
- headers["content-type"] = "application/json";
48
+ headers2["content-type"] = "application/json";
49
49
  payload = JSON.stringify(args.body);
50
50
  }
51
51
  const retryServerErrors = args.retrySafe || IDEMPOTENT_METHODS.has(route.method);
@@ -53,7 +53,7 @@ var HttpClient = class {
53
53
  const canRetry = attempt < this.config.maxRetries;
54
54
  let response;
55
55
  try {
56
- response = await this.send(url, route.method, headers, payload);
56
+ response = await this.send(url, route.method, headers2, payload);
57
57
  } catch (error) {
58
58
  if (canRetry && retryServerErrors) {
59
59
  await sleep(backoff(attempt));
@@ -69,20 +69,16 @@ var HttpClient = class {
69
69
  await sleep(retryAfter(response.headers) ?? backoff(attempt));
70
70
  continue;
71
71
  }
72
- throw SendLitError.fromResponse(
73
- response.status,
74
- body,
75
- response.headers
76
- );
72
+ throw SendLitError.fromResponse(response.status, body, response.headers);
77
73
  }
78
74
  }
79
- async send(url, method, headers, body) {
75
+ async send(url, method, headers2, body) {
80
76
  const controller = new AbortController();
81
77
  const timer = setTimeout(() => controller.abort(), this.config.timeout);
82
78
  try {
83
79
  return await this.config.fetch(url, {
84
80
  method,
85
- headers,
81
+ headers: headers2,
86
82
  body,
87
83
  signal: controller.signal
88
84
  });
@@ -118,8 +114,8 @@ function backoff(attempt) {
118
114
  const base = Math.min(500 * 2 ** attempt, MAX_RETRY_DELAY_MS);
119
115
  return base * (0.75 + Math.random() * 0.25);
120
116
  }
121
- function retryAfter(headers) {
122
- const value = headers.get("retry-after");
117
+ function retryAfter(headers2) {
118
+ const value = headers2.get("retry-after");
123
119
  if (!value)
124
120
  return void 0;
125
121
  const seconds = Number(value);
@@ -140,6 +136,252 @@ async function* paginate(fetchPage) {
140
136
  return;
141
137
  }
142
138
  }
139
+ function headers(field, names) {
140
+ for (const name of names)
141
+ field;
142
+ }
143
+ headers("email", [
144
+ "email",
145
+ "email_address",
146
+ "e_mail",
147
+ "emailaddress",
148
+ "subscriber_email",
149
+ "contact_email",
150
+ "mail"
151
+ ]);
152
+ headers("name", ["name", "full_name", "fullname", "display_name", "subscriber_name"]);
153
+ headers("first_name", ["first_name", "firstname", "fname", "given_name"]);
154
+ headers("last_name", ["last_name", "lastname", "lname", "surname", "family_name"]);
155
+ headers("tags", ["tags", "tag", "labels"]);
156
+ headers("status", [
157
+ "status",
158
+ "subscription_status",
159
+ "subscriber_status",
160
+ "member_status",
161
+ "state"
162
+ ]);
163
+ headers("created_at", [
164
+ "created_at",
165
+ "created",
166
+ "created_date",
167
+ "date_added",
168
+ "subscribed_at",
169
+ "subscribe_date",
170
+ "subscription_date",
171
+ "signup_date",
172
+ "sign_up_date",
173
+ "optin_time",
174
+ "confirm_time",
175
+ "joined_at"
176
+ ]);
177
+ headers("tag_from_value", ["tier", "plan", "subscription_tier"]);
178
+ headers("ignore", ["suppression_reason"]);
179
+ function statuses(result, values) {
180
+ for (const value of values)
181
+ result;
182
+ }
183
+ statuses({ status: "subscribed" }, [
184
+ "",
185
+ "active",
186
+ "subscribed",
187
+ "subscriber",
188
+ "confirmed",
189
+ "opted_in",
190
+ "true",
191
+ "yes",
192
+ "1"
193
+ ]);
194
+ statuses({ status: "subscribed", tag: "paused" }, ["paused"]);
195
+ statuses({ status: "unsubscribed" }, [
196
+ "unsubscribed",
197
+ "unsubscribe",
198
+ "inactive",
199
+ "cancelled",
200
+ "canceled",
201
+ "opted_out",
202
+ "disabled",
203
+ "deactivated",
204
+ "false",
205
+ "no",
206
+ "0"
207
+ ]);
208
+ statuses({ status: "bounced" }, [
209
+ "bounced",
210
+ "bounce",
211
+ "hard_bounce",
212
+ "hard_bounced",
213
+ "cleaned",
214
+ "invalid"
215
+ ]);
216
+ statuses({ status: "complained" }, [
217
+ "complained",
218
+ "complaint",
219
+ "spam",
220
+ "spam_complaint",
221
+ "marked_as_spam",
222
+ "abuse"
223
+ ]);
224
+ statuses({ skip: "pending_confirmation" }, [
225
+ "pending",
226
+ "needs_approval",
227
+ "unconfirmed",
228
+ "awaiting_confirmation",
229
+ "not_confirmed"
230
+ ]);
231
+ var paidPlans = ["starter", "pro", "business"];
232
+ var billingPlans = ["oss", "free", ...paidPlans];
233
+ var billingCatalogKeys = paidPlans.flatMap(
234
+ (plan) => [`${plan}_month`, `${plan}_year`]
235
+ );
236
+ var billingPlanSchema = z.enum(billingPlans);
237
+ var paidPlanSchema = z.enum(paidPlans);
238
+ var billingIntervalSchema = z.enum(["month", "year"]);
239
+ var paymentStatusSchema = z.enum([
240
+ "free",
241
+ "checkout_pending",
242
+ "trialing",
243
+ "active",
244
+ "past_due",
245
+ "cancel_at_period_end",
246
+ "cancelled",
247
+ "expired"
248
+ ]);
249
+ var billingOfferSchema = z.object({
250
+ catalogKey: z.enum(billingCatalogKeys),
251
+ plan: paidPlanSchema,
252
+ interval: billingIntervalSchema,
253
+ currency: z.string().regex(/^[A-Z]{3}$/),
254
+ amountMinor: z.number().int().positive(),
255
+ trialDays: z.number().int().nonnegative()
256
+ });
257
+ var billingPlanFeaturesSchema = z.object({
258
+ plan: paidPlanSchema,
259
+ teamsLimit: z.number().int().positive().nullable(),
260
+ monthlySendsLimit: z.number().int().positive().nullable(),
261
+ marketingBranding: z.boolean(),
262
+ sharedOrganizationMailbox: z.boolean(),
263
+ provisioning: z.boolean(),
264
+ organizationApiKeys: z.boolean()
265
+ });
266
+ var billingCatalogSchema = z.object({
267
+ catalogRevision: z.number().int().positive().nullable(),
268
+ currency: z.string().regex(/^[A-Z]{3}$/).nullable(),
269
+ offers: z.array(billingOfferSchema),
270
+ plans: z.array(billingPlanFeaturesSchema).optional(),
271
+ checkoutAvailable: z.boolean()
272
+ });
273
+ var organizationPlanUsageSchema = z.object({
274
+ plan: billingPlanSchema,
275
+ paymentStatus: paymentStatusSchema,
276
+ teams: z.number().int().nonnegative(),
277
+ subscribedContacts: z.number().int().nonnegative(),
278
+ monthlySends: z.number().int().nonnegative(),
279
+ monthlySendsReserved: z.number().int().nonnegative(),
280
+ bucketStartsAt: z.string(),
281
+ bucketEndsAt: z.string(),
282
+ teamsLimit: z.number().int().positive().nullable(),
283
+ subscribedContactsLimit: z.number().int().positive().nullable(),
284
+ monthlySendsLimit: z.number().int().positive().nullable()
285
+ });
286
+ var billingPlanChangeSummarySchema = z.object({
287
+ changeId: z.string(),
288
+ targetPlan: paidPlanSchema,
289
+ targetInterval: billingIntervalSchema,
290
+ effectiveAt: z.enum(["immediately", "next_billing_date"])
291
+ });
292
+ var organizationBillingSchema = z.object({
293
+ plan: billingPlanSchema,
294
+ billingInterval: billingIntervalSchema.nullable(),
295
+ paymentStatus: paymentStatusSchema,
296
+ trialEndsAt: z.string().nullable(),
297
+ currentPeriodEndsAt: z.string().nullable(),
298
+ /** When paid access ends if the subscription is not renewed. With
299
+ * `cancelAtPeriodEnd`, this is the "access until" date. */
300
+ paidThroughAt: z.string().nullable(),
301
+ cancelAtPeriodEnd: z.boolean(),
302
+ graceEndsAt: z.string().nullable(),
303
+ canManageBilling: z.boolean(),
304
+ entitlements: z.object({
305
+ teamsLimit: z.number().int().positive().nullable(),
306
+ subscribedContactsLimit: z.number().int().positive().nullable(),
307
+ monthlySendsLimit: z.number().int().positive().nullable(),
308
+ sharedOrganizationMailbox: z.boolean(),
309
+ provisioning: z.boolean(),
310
+ organizationApiKeys: z.boolean(),
311
+ marketingBranding: z.boolean()
312
+ }),
313
+ usage: organizationPlanUsageSchema,
314
+ pendingPlanChange: billingPlanChangeSummarySchema.nullable()
315
+ });
316
+ var billingCheckoutBodySchema = z.object({
317
+ plan: paidPlanSchema,
318
+ interval: billingIntervalSchema,
319
+ catalogRevision: z.number().int().positive()
320
+ });
321
+ var billingCheckoutResponseSchema = z.object({
322
+ checkoutUrl: z.string().url(),
323
+ expiresAt: z.string()
324
+ });
325
+ var billingPortalResponseSchema = z.object({
326
+ portalUrl: z.string().url()
327
+ });
328
+ var billingActionSchema = z.enum([
329
+ "organization_checkout",
330
+ "checkout",
331
+ "portal",
332
+ "plan_change",
333
+ "cancellation",
334
+ "organization_close",
335
+ "pending_hide"
336
+ ]);
337
+ var billingActionTokenBodySchema = z.object({
338
+ action: billingActionSchema,
339
+ target: z.string().trim().min(1).max(300)
340
+ });
341
+ var billingActionTokenResponseSchema = z.object({
342
+ token: z.string().min(32),
343
+ expiresAt: z.string().datetime()
344
+ });
345
+ var billingCancellationResponseSchema = z.object({
346
+ accepted: z.literal(true),
347
+ subscriptionId: z.string()
348
+ });
349
+ var billingPlanChangeBodySchema = z.object({
350
+ plan: paidPlanSchema,
351
+ interval: billingIntervalSchema,
352
+ catalogRevision: z.number().int().positive(),
353
+ idempotencyKey: z.string().trim().min(1).max(256).optional()
354
+ });
355
+ var billingPlanChangeResponseSchema = z.object({
356
+ changeId: z.string(),
357
+ status: z.enum(["pending", "succeeded", "failed", "conflicted"]),
358
+ targetPlan: paidPlanSchema,
359
+ targetInterval: billingIntervalSchema,
360
+ effectiveAt: z.enum(["immediately", "next_billing_date"]),
361
+ paymentUrl: z.string().url().nullable(),
362
+ completedAt: z.string().nullable()
363
+ });
364
+ var organizationCheckoutBodySchema = billingCheckoutBodySchema.extend({
365
+ organizationName: z.string().trim().min(1).max(120),
366
+ teamName: z.string().trim().min(1).max(120)
367
+ });
368
+ var organizationCheckoutResponseSchema = billingCheckoutResponseSchema.extend({
369
+ organizationId: z.string()
370
+ });
371
+ var sendingDomainSchema = z.object({
372
+ domainId: z.string(),
373
+ domain: z.string(),
374
+ status: z.enum(["pending", "verified", "revoked", "failed"]),
375
+ verifiedAt: z.string().nullable(),
376
+ lastCheckedAt: z.string().nullable(),
377
+ nextCheckAt: z.string().nullable(),
378
+ challengeToken: z.string().nullable(),
379
+ challengeRecordName: z.string().nullable(),
380
+ challengeRecordValue: z.string().nullable()
381
+ });
382
+ var createSendingDomainBodySchema = z.object({
383
+ domain: z.string().trim().min(1).max(253)
384
+ });
143
385
  var errorSchema = z.object({ error: z.string() });
144
386
  z.object({ message: z.string() });
145
387
  var emailContentSchema = z.object({
@@ -147,10 +389,7 @@ var emailContentSchema = z.object({
147
389
  meta: z.record(z.any()),
148
390
  content: z.array(z.record(z.any()))
149
391
  });
150
- var cssColorSchema = z.string().regex(
151
- /^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i,
152
- "Expected a hex color"
153
- );
392
+ var cssColorSchema = z.string().regex(/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i, "Expected a hex color");
154
393
  var pixelSchema = z.string().regex(/^\d+(?:\.\d+)?px$/, "Expected a pixel value such as 16px");
155
394
  var typographySectionSchema = z.object({}).passthrough();
156
395
  var emailStyleInputSchema = z.object({
@@ -242,6 +481,12 @@ function paginated(item) {
242
481
  function itemsList(item) {
243
482
  return z.object({ items: z.array(item) });
244
483
  }
484
+ var customFieldScalarSchema = z.union([z.string(), z.number(), z.boolean()]);
485
+ var customFieldValueSchema = z.union([
486
+ customFieldScalarSchema,
487
+ z.array(customFieldScalarSchema)
488
+ ]);
489
+ var customFieldsSchema = z.record(customFieldValueSchema).default({});
245
490
  var nullableLimit = z.number().int().nonnegative().nullable();
246
491
  var organizationDeliveryPolicySchema = z.object({
247
492
  defaultEspId: z.string().nullable(),
@@ -341,6 +586,8 @@ var sendingOptionSchema = z.discriminatedUnion("type", [
341
586
  countsAgainstQuota: z.literal(false)
342
587
  })
343
588
  ]);
589
+
590
+ // ../api-contract/src/schemas/sequences.ts
344
591
  var mailTypes = ["broadcast", "sequence"];
345
592
  var emailActionTypes = ["tag:add", "tag:remove"];
346
593
  var sequenceEmailSchema = z.object({
@@ -356,6 +603,11 @@ var sequenceEmailSchema = z.object({
356
603
  // Plain string (see `contactSchema.lead`'s comment) — validated on write.
357
604
  actionType: z.string().nullable().optional(),
358
605
  actionData: z.record(z.any()).nullable().optional(),
606
+ /** When a test of this email was last sent; `null` if never. */
607
+ lastTestSentAt: z.string().nullable().optional(),
608
+ /** Hosted content check: `clean`, `review` (held for SendLit's review),
609
+ * `blocked`, or `approved` after review; `null` when not scanned. */
610
+ contentScanVerdict: z.string().nullable().optional(),
359
611
  createdAt: z.string().nullable(),
360
612
  updatedAt: z.string().nullable()
361
613
  });
@@ -438,12 +690,23 @@ var sequenceSchema = z.object({
438
690
  triggerData: z.string().nullable().optional(),
439
691
  filter: z.any().nullable().optional(),
440
692
  excludeFilter: z.any().nullable().optional(),
693
+ /** Active enrollments for a sequence or its locked recipient count for a broadcast. */
694
+ entrantsCount: z.number().int().nonnegative().optional(),
441
695
  emailsOrder: z.array(z.string()),
442
696
  entrants: z.array(z.string()),
443
697
  report: z.any(),
444
698
  createdAt: z.string().nullable(),
445
699
  updatedAt: z.string().nullable(),
446
- emails: z.array(sequenceEmailSchema)
700
+ emails: z.array(sequenceEmailSchema),
701
+ /** Set while a running broadcast of a new hosted organization is sent
702
+ * gradually (`get` only). */
703
+ pacing: z.object({
704
+ reason: z.enum(["new_account"]),
705
+ hourlyLimit: z.number().int(),
706
+ dailyLimit: z.number().int(),
707
+ remaining: z.number().int(),
708
+ estimatedCompletionAt: z.string()
709
+ }).nullable().optional()
447
710
  });
448
711
  var listSequencesQuerySchema = z.object({
449
712
  type: z.enum(mailTypes),
@@ -459,7 +722,12 @@ var updateSequenceBodySchema = z.object({
459
722
  title: z.string().optional(),
460
723
  triggerType: z.string().optional(),
461
724
  triggerData: z.string().optional(),
462
- filter: contactFilterSchema.optional(),
725
+ filter: contactFilterSchema.optional().describe(
726
+ "Audience: subscribed contacts matching this filter; empty means everyone"
727
+ ),
728
+ excludeFilter: contactFilterSchema.nullable().optional().describe(
729
+ "Contacts matching this filter are left out of the audience, even when they match `filter`. `null` clears it."
730
+ ),
463
731
  emailsOrder: z.array(z.string()).optional(),
464
732
  /** `null` clears the intent so the default is resolved on next start. */
465
733
  deliverySource: deliverySourceSelectionSchema.nullable().optional()
@@ -476,22 +744,31 @@ var updateSequenceEmailBodySchema = z.object({
476
744
  actionData: z.record(z.any()).optional(),
477
745
  published: z.boolean().optional()
478
746
  });
747
+ var sendSequenceEmailTestBodySchema = z.object({
748
+ to: z.array(z.string().email()).max(5).optional().describe(
749
+ "Up to 5 addresses. Defaults to the signed-in user's address; API keys must set it."
750
+ )
751
+ });
752
+ var sequenceEmailTestResultSchema = z.object({
753
+ sent: z.array(z.string()).describe("Addresses the test was sent to"),
754
+ skipped: z.array(z.object({ email: z.string(), reason: z.enum(["suppressed"]) })).describe("Addresses on the suppression list, which never get mail"),
755
+ lastTestSentAt: z.string().nullable()
756
+ });
479
757
  var sequenceStatsSchema = z.object({
480
758
  sent: z.number(),
481
759
  openRate: z.number(),
482
760
  clickThroughRate: z.number(),
483
- subscribersCount: z.number()
761
+ subscribersCount: z.number(),
762
+ /** Share of accepted emails that bounced / were marked as spam (0-1). */
763
+ bounceRate: z.number().optional(),
764
+ complaintRate: z.number().optional()
484
765
  });
485
766
  var listSubscribersQuerySchema = z.object({
486
767
  page: z.coerce.number().int().min(1).optional(),
487
768
  limit: z.coerce.number().int().min(1).optional()
488
769
  });
489
- var customFieldScalarSchema = z.union([z.string(), z.number(), z.boolean()]);
490
- var customFieldValueSchema = z.union([
491
- customFieldScalarSchema,
492
- z.array(customFieldScalarSchema)
493
- ]);
494
- var customFieldsSchema = z.record(customFieldValueSchema).default({});
770
+
771
+ // ../api-contract/src/schemas/contacts.ts
495
772
  var contactSchema = z.object({
496
773
  contactId: z.string(),
497
774
  email: z.string(),
@@ -523,6 +800,9 @@ var listContactsQuerySchema = z.object({
523
800
  filter: z.string().optional().describe(
524
801
  "Serialized ContactFilterWithAggregator JSON; combines with q and segmentId using AND"
525
802
  ),
803
+ excludeFilter: z.string().optional().describe(
804
+ "Serialized ContactFilterWithAggregator JSON; contacts matching it are left out"
805
+ ),
526
806
  offset: z.coerce.number().int().min(1).optional(),
527
807
  rowsPerPage: z.coerce.number().int().min(1).optional()
528
808
  });
@@ -533,66 +813,92 @@ z.object({
533
813
  emailId: z.string(),
534
814
  createdAt: z.string().nullable()
535
815
  });
536
- var templatePurposes = ["marketing", "transactional"];
537
- var templatePurposeSchema = z.enum(templatePurposes).describe(
538
- "Immutable sending purpose. Marketing templates require a final managed footer; transactional templates are footer-free and are valid for POST /emails."
539
- );
540
- var templateVariableDefinitionSchema = z.object({
541
- path: z.string().min(1).describe("Dot-separated Liquid variable path."),
542
- description: z.string().describe("Human-readable value description."),
543
- example: z.any().describe("Example value used in generated requests.")
544
- });
545
- var emailTemplateSchema = z.object({
546
- templateId: z.string(),
547
- title: z.string(),
548
- purpose: templatePurposeSchema,
549
- content: emailContentSchema,
550
- requiredVariables: z.array(z.string()).describe(
551
- "Sorted, server-discovered Liquid paths that must be supplied. Defaults and inactive guarded branches are omitted."
552
- ),
553
- validationError: z.string().optional().describe(
554
- "Present only for a retired template that predates the managed-footer format. It cannot be edited, duplicated, or sent; recreate it instead."
816
+ var importContactRowSchema = z.object({
817
+ /** Validated per row; an invalid address is reported as skipped. */
818
+ email: z.string(),
819
+ name: z.string().optional(),
820
+ tags: z.array(z.string()).optional(),
821
+ status: z.string().optional().describe(
822
+ "The source platform's status, e.g. beehiiv's Active/Paused/Inactive/Pending or Mailchimp's subscribed/unsubscribed/cleaned. Empty means subscribed."
555
823
  ),
556
- createdAt: z.string().nullable(),
557
- updatedAt: z.string().nullable()
558
- });
559
- var createTemplateBodySchema = z.object({
560
- title: z.string().min(1),
561
- purpose: templatePurposeSchema.default("marketing"),
562
- content: emailContentInputSchema
563
- });
564
- var updateTemplateBodySchema = z.object({
565
- title: z.string().min(1).optional(),
566
- content: emailContentInputSchema.optional()
567
- });
568
- var systemTemplateSchema = z.object({
569
- templateId: z.string(),
570
- title: z.string(),
571
- description: z.string(),
572
- purpose: templatePurposeSchema,
573
- content: emailContentSchema,
574
- requiredVariables: z.array(z.string()).describe(
575
- "Sorted, server-discovered Liquid paths that must be supplied."
824
+ createdAt: z.string().optional().describe("Original signup date; kept as the contact's createdAt"),
825
+ customFields: customFieldsSchema.optional(),
826
+ /** Echoed back in `skipped` so callers can point at the CSV line. */
827
+ row: z.number().int().optional()
828
+ });
829
+ var importContactsBodySchema = z.object({
830
+ contacts: z.array(importContactRowSchema).min(1).max(1e3),
831
+ tags: z.array(z.string().min(1)).max(20).optional().describe("Added to every imported contact"),
832
+ pending: z.enum(["skip", "unsubscribed"]).optional().describe(
833
+ "Contacts who never confirmed (Pending / Needs approval): skip them (default) or import them unsubscribed with the `pending` tag"
576
834
  ),
577
- variableDefinitions: z.array(templateVariableDefinitionSchema).optional().describe(
578
- "Documentation metadata for built-in starter variables; runtime discovery remains authoritative."
835
+ source: z.string().max(200).optional().describe(
836
+ "Where the rows came from, e.g. the CSV file name; kept in the audit log"
579
837
  )
580
838
  });
581
- var listTemplatesQuerySchema = z.object({
582
- purpose: templatePurposeSchema.optional()
583
- });
584
- var duplicateTemplateBodySchema = z.object({
585
- title: z.string().min(1).optional()
839
+ var importContactsResultSchema = z.object({
840
+ created: z.number().int(),
841
+ updated: z.number().int(),
842
+ unchanged: z.number().int(),
843
+ /** Imported as bounced/complained and added to the suppression list. */
844
+ suppressed: z.number().int(),
845
+ skipped: z.array(
846
+ z.object({
847
+ row: z.number().int().optional(),
848
+ email: z.string(),
849
+ reason: z.enum([
850
+ "invalid_email",
851
+ "duplicate",
852
+ "pending_confirmation",
853
+ "unknown_status",
854
+ "plan_limit_reached"
855
+ ])
856
+ })
857
+ )
586
858
  });
587
- var templateValidationErrorSchema = z.object({
588
- error: z.string(),
589
- variables: z.array(z.string()).optional()
859
+ var exportContactsQuerySchema = z.object({
860
+ segmentId: z.string().optional().describe("Only export this saved segment"),
861
+ filter: z.string().optional().describe("Serialized ContactFilterWithAggregator JSON; combines with segmentId")
590
862
  });
591
- var templateNotTransactionalErrorSchema = z.object({
592
- error: z.literal("template_not_transactional")
863
+ var deliveryEventType = [
864
+ "accepted",
865
+ "delivered",
866
+ "delayed",
867
+ "soft_bounce",
868
+ "hard_bounce",
869
+ "failed",
870
+ "complaint",
871
+ "suppressed",
872
+ "rejected",
873
+ "unknown"
874
+ ];
875
+ var bounceClass = ["permanent", "transient", "undetermined"];
876
+ var deliverySourceTypes = ["organization", "team"];
877
+ var deliveryEventSchema = z.object({
878
+ eventId: z.string(),
879
+ provider: z.string(),
880
+ espId: z.string().nullable(),
881
+ deliverySourceType: z.enum(deliverySourceTypes).nullable(),
882
+ /** Public `msg_...` id of the correlated outbound message, when the
883
+ * event was matched to one — see the PRD's correlation section. */
884
+ messageId: z.string().nullable(),
885
+ recipientEmail: z.string().nullable(),
886
+ eventType: z.enum(deliveryEventType),
887
+ bounceClass: z.enum(bounceClass).nullable().optional(),
888
+ smtpCode: z.number().nullable().optional(),
889
+ enhancedStatusCode: z.string().nullable().optional(),
890
+ reason: z.string().nullable().optional(),
891
+ occurredAt: z.string(),
892
+ receivedAt: z.string()
593
893
  });
594
- var templateNotMarketingErrorSchema = z.object({
595
- error: z.literal("template_not_marketing")
894
+ var listDeliveryEventsQuerySchema = z.object({
895
+ espId: z.string().optional(),
896
+ deliverySourceType: z.enum(deliverySourceTypes).optional(),
897
+ eventType: z.enum(deliveryEventType).optional(),
898
+ createdAfter: z.coerce.number().int().optional(),
899
+ createdBefore: z.coerce.number().int().optional(),
900
+ offset: z.coerce.number().int().min(1).optional(),
901
+ itemsPerPage: z.coerce.number().int().min(1).optional()
596
902
  });
597
903
  var espProviders = [
598
904
  "smtp",
@@ -602,6 +908,19 @@ var espProviders = [
602
908
  "ses",
603
909
  "resend"
604
910
  ];
911
+ var espWarmupSchema = z.object({
912
+ targetDailyVolume: z.number().int(),
913
+ startedAt: z.string(),
914
+ /** Day of the warm-up, starting at 1. */
915
+ day: z.number().int(),
916
+ totalDays: z.number().int(),
917
+ /** Most marketing email this ESP sends today because of the warm-up. */
918
+ todayLimit: z.number().int(),
919
+ complete: z.boolean()
920
+ });
921
+ var warmupTargetSchema = z.number().int().min(100).max(1e7).nullable().optional().describe(
922
+ "Turns on automatic warm-up up to this many marketing emails a day: the daily limit starts at 50 and grows each UTC day until it reaches the target, with the most engaged contacts sent to first. Setting it starts the warm-up from day 1 (changing the target of a running warm-up keeps its progress). `null` turns it off."
923
+ );
605
924
  var espConfigSchema = z.object({
606
925
  espId: z.string(),
607
926
  name: z.string(),
@@ -615,6 +934,15 @@ var espConfigSchema = z.object({
615
934
  hasPassword: z.boolean(),
616
935
  fromName: z.string().nullable().optional(),
617
936
  fromEmail: z.string().nullable().optional(),
937
+ replyTo: z.string().nullable().optional(),
938
+ /** Configured messages per second; `null` means the provider default. */
939
+ maxSendRate: z.number().nullable().optional(),
940
+ /** Daily cap on marketing sends (UTC days); `null` means none. */
941
+ dailySendLimit: z.number().int().nullable().optional(),
942
+ /** Marketing sends today (UTC), when the ESP has a daily cap. */
943
+ sentToday: z.number().int().nullable().optional(),
944
+ /** Automatic warm-up, while one is set up. */
945
+ warmup: espWarmupSchema.nullable().optional(),
618
946
  status: z.enum(["draft", "active", "suspended", "draining", "retired"]),
619
947
  secretVersion: z.number().int().positive(),
620
948
  lastTestedAt: z.string().nullable().optional(),
@@ -625,6 +953,12 @@ var espConfigSchema = z.object({
625
953
  retiredAt: z.string().nullable().optional(),
626
954
  updatedAt: z.string().optional()
627
955
  });
956
+ var maxSendRateSchema = z.number().positive().max(1e4).nullable().optional().describe(
957
+ "Messages per second to send through this ESP, across all workers. `null` uses the provider default (Amazon SES 14, Resend 2, others unlimited)."
958
+ );
959
+ var dailySendLimitSchema = z.number().int().positive().nullable().optional().describe(
960
+ "Most marketing emails (broadcasts and sequences) to send through this ESP per UTC day, e.g. while warming up a new domain. Emails over the cap wait for the next day. `null` removes the cap; transactional email is never capped."
961
+ );
628
962
  var upsertEspConfigBodySchema = z.object({
629
963
  provider: z.enum(espProviders),
630
964
  host: z.string().min(1),
@@ -634,7 +968,11 @@ var upsertEspConfigBodySchema = z.object({
634
968
  /** Omit to keep the existing secret unchanged; send `""` to clear it. */
635
969
  password: z.string().optional(),
636
970
  fromName: z.string().optional(),
637
- fromEmail: z.string().email().optional()
971
+ fromEmail: z.string().email().optional(),
972
+ replyTo: z.union([z.string().email(), z.literal("")]).optional().describe('Where replies go, when not the from address. `""` clears it.'),
973
+ maxSendRate: maxSendRateSchema,
974
+ dailySendLimit: dailySendLimitSchema,
975
+ warmupTargetDailyVolume: warmupTargetSchema
638
976
  });
639
977
  var createEspConfigBodySchema = upsertEspConfigBodySchema.extend({
640
978
  name: z.string().trim().min(1).max(100)
@@ -648,7 +986,11 @@ var updateEspConfigBodySchema = z.object({
648
986
  username: z.string().optional(),
649
987
  password: z.string().optional(),
650
988
  fromName: z.string().optional(),
651
- fromEmail: z.union([z.string().email(), z.literal("")]).optional()
989
+ fromEmail: z.union([z.string().email(), z.literal("")]).optional(),
990
+ replyTo: z.union([z.string().email(), z.literal("")]).optional(),
991
+ maxSendRate: maxSendRateSchema,
992
+ dailySendLimit: dailySendLimitSchema,
993
+ warmupTargetDailyVolume: warmupTargetSchema
652
994
  }).refine((body) => Object.keys(body).length > 0, {
653
995
  message: "At least one field is required"
654
996
  });
@@ -666,133 +1008,103 @@ var retireEspConfigBodySchema = z.discriminatedUnion("transition", [
666
1008
  }),
667
1009
  z.object({ transition: z.literal("cancel") })
668
1010
  ]);
669
- var generalSettingsSchema = z.object({
670
- /** Physical postal address rendered in email footers
671
- * (CAN-SPAM/GDPR requirement). */
672
- mailingAddress: z.string().nullable(),
673
- updatedAt: z.string().nullable().optional()
674
- });
675
- var updateGeneralSettingsBodySchema = z.object({
676
- /** Send an empty string to clear the mailing address. */
677
- mailingAddress: z.string().optional()
1011
+ var domainAuthStatuses = ["pass", "warn", "fail"];
1012
+ var domainAuthCheckSchema = z.object({
1013
+ status: z.enum(domainAuthStatuses),
1014
+ message: z.string(),
1015
+ /** The DNS record SendLit found, if any. */
1016
+ record: z.string().nullable()
1017
+ });
1018
+ var domainAuthenticationSchema = z.object({
1019
+ domain: z.string(),
1020
+ provider: z.enum(espProviders),
1021
+ spf: domainAuthCheckSchema.extend({ host: z.string() }),
1022
+ dkim: domainAuthCheckSchema.extend({ selector: z.string().nullable() }),
1023
+ dmarc: domainAuthCheckSchema.extend({ policy: z.string().nullable() }),
1024
+ records: z.array(
1025
+ z.object({
1026
+ type: z.enum(["TXT", "CNAME", "MX"]),
1027
+ name: z.string(),
1028
+ /** `null` when only the provider's console knows the value. */
1029
+ value: z.string().nullable(),
1030
+ purpose: z.string(),
1031
+ present: z.boolean()
1032
+ })
1033
+ ),
1034
+ providerConsoleUrl: z.string().nullable(),
1035
+ checkedAt: z.string()
678
1036
  });
679
- var teamSchema = z.object({
680
- teamId: z.string(),
681
- /** Public organization identifier. Present when an end user lists the
682
- * teams they belong to, so the dashboard can keep workspace selection
683
- * scoped to one organization. */
684
- organizationId: z.string().optional(),
685
- organizationName: z.string().optional(),
686
- name: z.string(),
687
- status: z.enum(["active", "sending_suspended", "archived"]),
688
- externalId: z.string().nullable().optional(),
689
- createdAt: z.string().nullable().optional(),
690
- updatedAt: z.string().nullable().optional(),
691
- /** True when the calling human is already a `team_members` row. Always
692
- * false for organization API keys. Omitted on non-list team payloads. */
693
- viewerIsMember: z.boolean().optional()
1037
+ var domainAuthenticationQuerySchema = z.object({
1038
+ dkimSelector: z.string().regex(/^[A-Za-z0-9._-]{1,63}$/).optional().describe(
1039
+ "DKIM selector to check (for Amazon SES, one Easy DKIM token). A selector that passes is saved on the ESP and used by later checks that omit it."
1040
+ )
694
1041
  });
695
- var apiKeySchema = z.object({
696
- keyId: z.string(),
697
- keyPrefix: z.string(),
698
- name: z.string(),
699
- expiresAt: z.string().nullable().optional(),
700
- lastUsedAt: z.string().nullable().optional(),
701
- revokedAt: z.string().nullable().optional(),
702
- createdAt: z.string().nullable().optional()
1042
+ var feedbackConnectionStatus = [
1043
+ "pending",
1044
+ "healthy",
1045
+ "stale",
1046
+ "error",
1047
+ "retiring",
1048
+ "disabled"
1049
+ ];
1050
+ var feedbackConnectionSchema = z.object({
1051
+ connectionId: z.string(),
1052
+ espId: z.string(),
1053
+ provider: z.string(),
1054
+ webhookUrl: z.string(),
1055
+ hasCredential: z.boolean(),
1056
+ /** SES only: the SNS topic this connection accepts messages from. */
1057
+ expectedTopicArn: z.string().nullable().optional(),
1058
+ /** SES only: when SendLit confirmed the SNS subscription. */
1059
+ subscriptionConfirmedAt: z.string().nullable().optional(),
1060
+ status: z.enum(feedbackConnectionStatus),
1061
+ lastReceivedAt: z.string().nullable().optional(),
1062
+ lastVerifiedAt: z.string().nullable().optional(),
1063
+ lastErrorCode: z.string().nullable().optional(),
1064
+ createdAt: z.string().optional(),
1065
+ updatedAt: z.string().optional()
703
1066
  });
704
- var createdApiKeySchema = apiKeySchema.extend({
705
- key: z.string()
1067
+ var upsertFeedbackConnectionBodySchema = z.object({
1068
+ /** The provider's webhook signing secret / public key / shared header
1069
+ * value, depending on provider. Never returned after this call.
1070
+ * Required for every provider except SES. */
1071
+ credential: z.string().min(1).optional(),
1072
+ /** SES only, required: the ARN of the SNS topic SES publishes events to
1073
+ * and that is subscribed to this connection's webhook URL. */
1074
+ expectedTopicArn: z.string().min(1).optional()
1075
+ }).refine((body) => body.credential || body.expectedTopicArn, {
1076
+ message: "Provide `credential`, or `expectedTopicArn` for SES"
706
1077
  });
707
- var createTeamBodySchema = z.object({ name: z.string().min(1) });
708
- var renameTeamBodySchema = z.object({ name: z.string().min(1) });
709
- var createApiKeyBodySchema = z.object({ name: z.string().min(1) });
710
- var provisionTeamBodySchema = z.object({
711
- externalId: z.string().min(1),
712
- name: z.string().min(1),
713
- sender: z.object({
714
- fromName: z.string().min(1).optional(),
715
- replyTo: z.string().email().optional()
716
- }).optional(),
717
- mailingAddress: z.string().min(1).optional(),
718
- delivery: z.object({
719
- useOrganizationDefault: z.boolean().optional(),
720
- teamEspEnabled: z.boolean().optional(),
721
- teamCanChangeDefault: z.boolean().optional()
722
- }).optional(),
723
- quota: z.object({
724
- dailyLimit: z.number().int().positive().nullable().optional(),
725
- monthlyLimit: z.number().int().positive().nullable().optional()
726
- }).optional()
1078
+ var testFeedbackConnectionResponseSchema = z.object({
1079
+ success: z.boolean(),
1080
+ error: z.string().optional()
727
1081
  });
728
- var provisionedTeamBaseSchema = z.object({
729
- teamId: z.string(),
730
- externalId: z.string(),
1082
+ var signupFormSchema = z.object({
1083
+ formId: z.string(),
731
1084
  name: z.string(),
732
- deliverySource: z.object({ type: z.literal("organization") })
1085
+ tags: z.array(z.string()),
1086
+ doubleOptIn: z.boolean(),
1087
+ redirectUrl: z.string().nullable(),
1088
+ url: z.string(),
1089
+ sendingIssue: z.string().nullable().describe(
1090
+ "Why this double opt-in form can't email confirmation links right now (e.g. the team has no sending mailbox); null when it can. Submissions fail until it's fixed."
1091
+ ),
1092
+ createdAt: z.string(),
1093
+ updatedAt: z.string()
733
1094
  });
734
- var provisionTeamResponseSchema = z.discriminatedUnion("created", [
735
- provisionedTeamBaseSchema.extend({
736
- created: z.literal(true),
737
- apiKey: z.string()
738
- }),
739
- provisionedTeamBaseSchema.extend({
740
- created: z.literal(false),
741
- apiKey: z.null()
742
- })
743
- ]);
744
- var provisionedTeamSchema = provisionedTeamBaseSchema.extend({
745
- status: z.enum(["active", "sending_suspended", "archived"]),
746
- mailingAddress: z.string().nullable(),
747
- teamEspEnabled: z.boolean(),
748
- teamCanChangeDefault: z.boolean(),
749
- createdAt: z.string().nullable(),
750
- updatedAt: z.string().nullable()
1095
+ var signupFormSenderErrorSchema = z.object({
1096
+ error: z.literal("confirmation_sender_unavailable"),
1097
+ message: z.string()
751
1098
  });
752
- var updateProvisionedTeamBodySchema = z.object({
753
- name: z.string().min(1).optional(),
754
- sender: z.object({
755
- fromName: z.string().min(1).nullable().optional(),
756
- replyTo: z.string().email().nullable().optional()
757
- }).optional(),
758
- mailingAddress: z.string().min(1).nullable().optional(),
759
- delivery: z.object({
760
- teamEspEnabled: z.boolean().optional(),
761
- teamCanChangeDefault: z.boolean().optional()
762
- }).optional(),
763
- quota: z.object({
764
- dailyLimit: z.number().int().nonnegative().nullable().optional(),
765
- monthlyLimit: z.number().int().nonnegative().nullable().optional()
766
- }).optional()
767
- }).refine((body) => Object.keys(body).length > 0, {
768
- message: "At least one field is required"
769
- });
770
- var usageWindowSchema = z.object({
771
- limit: z.number().int().nullable(),
772
- accepted: z.number().int().nonnegative(),
773
- reserved: z.number().int().nonnegative(),
774
- remaining: z.number().int().nullable(),
775
- resetsAt: z.string()
776
- });
777
- var provisionedTeamUsageSchema = z.object({
778
- day: usageWindowSchema,
779
- month: usageWindowSchema
780
- });
781
- var segmentSchema = z.object({
782
- segmentId: z.string(),
783
- name: z.string(),
784
- filter: contactFilterSchema,
785
- createdAt: z.string().nullable(),
786
- updatedAt: z.string().nullable()
787
- });
788
- var createSegmentBodySchema = z.object({
789
- name: z.string().min(1),
790
- filter: contactFilterSchema
791
- });
792
- var updateSegmentBodySchema = z.object({
793
- name: z.string().min(1).optional(),
794
- filter: contactFilterSchema.optional()
1099
+ var createSignupFormBodySchema = z.object({
1100
+ name: z.string().trim().min(1).max(200),
1101
+ tags: z.array(z.string().min(1)).max(20).optional().describe("Added to everyone who subscribes through the form"),
1102
+ doubleOptIn: z.boolean().optional().describe(
1103
+ "Send a confirmation email and subscribe only once it's clicked (default true)"
1104
+ ),
1105
+ redirectUrl: z.string().url().refine((value) => /^https?:\/\//i.test(value), "Must be an http(s) URL").nullable().optional().describe("Where to send people after they submit the hosted or embedded form")
795
1106
  });
1107
+ var updateSignupFormBodySchema = createSignupFormBodySchema.partial();
796
1108
  var mediaSchema = z.object({
797
1109
  mediaId: z.string(),
798
1110
  url: z.string(),
@@ -828,208 +1140,11 @@ var mediaUploadSignatureSchema = z.object({
828
1140
  signature: z.string(),
829
1141
  endpoint: z.string()
830
1142
  });
831
- var transactionalEmailStatus = [
832
- "queued",
833
- "sent",
834
- "failed",
835
- "bounced",
836
- "suppressed"
837
- ];
838
- var transactionalEmailSchema = z.object({
839
- txeId: z.string(),
840
- to: z.string(),
841
- from: z.string().nullable(),
842
- replyTo: z.string().nullable(),
843
- subject: z.string(),
844
- templateId: z.string().nullable(),
845
- variables: z.record(z.any()),
846
- status: z.enum(transactionalEmailStatus),
847
- error: z.string().nullable(),
848
- trackOpens: z.boolean(),
849
- trackClicks: z.boolean(),
850
- openCount: z.number(),
851
- clickCount: z.number(),
852
- sentAt: z.string().nullable(),
853
- createdAt: z.string().nullable(),
854
- updatedAt: z.string().nullable()
855
- });
856
- var transactionalEmailDetailSchema = transactionalEmailSchema.extend({
857
- html: z.string().nullable()
858
- });
859
- var reservedHeaders = ["from", "to", "subject", "content-type"];
860
- var emailHeadersSchema = z.record(z.string()).superRefine((headers, ctx) => {
861
- for (const [name, value] of Object.entries(headers)) {
862
- if (/[\r\n]/.test(name) || /[\r\n]/.test(value)) {
863
- ctx.addIssue({
864
- code: z.ZodIssueCode.custom,
865
- message: "Header names and values must not contain CR/LF characters"
866
- });
867
- } else if (reservedHeaders.includes(
868
- name.toLowerCase()
869
- )) {
870
- ctx.addIssue({
871
- code: z.ZodIssueCode.custom,
872
- message: `Header "${name}" is set by the send pipeline and cannot be overridden`
873
- });
874
- }
875
- }
876
- });
877
- var sendEmailBodySchema = z.object({
878
- to: z.string().email(),
879
- subject: z.string().min(1),
880
- templateId: z.string().min(1).optional(),
881
- html: z.string().min(1).optional(),
882
- variables: z.record(z.any()).optional(),
883
- replyTo: z.string().email().optional(),
884
- headers: emailHeadersSchema.optional(),
885
- idempotencyKey: z.string().min(1).max(256).optional(),
886
- trackOpens: z.boolean().optional(),
887
- trackClicks: z.boolean().optional(),
888
- deliverySource: deliverySourceSelectionSchema.optional()
889
- }).refine((body) => !!body.templateId !== !!body.html, {
890
- message: "Provide exactly one of templateId or html"
891
- }).refine((body) => !(body.html && body.variables), {
892
- message: "variables requires templateId; inline html is sent verbatim"
893
- });
894
- var sendEmailResponseSchema = transactionalEmailSchema.pick({
895
- txeId: true,
896
- status: true
897
- });
898
- var missingTemplateVariablesErrorSchema = z.object({
899
- error: z.literal("missing_template_variables"),
900
- missingVariables: z.array(z.string()).min(1)
901
- });
902
- var listTransactionalEmailsQuerySchema = z.object({
903
- status: z.enum(transactionalEmailStatus).optional(),
904
- createdAfter: z.coerce.number().int().optional().describe("Millisecond timestamp lower bound (inclusive)"),
905
- createdBefore: z.coerce.number().int().optional().describe("Millisecond timestamp upper bound (exclusive)"),
906
- offset: z.coerce.number().int().min(1).optional(),
907
- itemsPerPage: z.coerce.number().int().min(1).max(50).optional()
908
- });
909
- var overviewQuerySchema = z.object({
910
- /** Delivery activity window, in days. Defaults to the last 7 days. */
911
- rangeDays: z.coerce.number().int().refine((value) => [1, 3, 7, 30].includes(value)).optional()
912
- });
913
- var overviewSchema = z.object({
914
- activeSequences: z.number(),
915
- ongoingContacts: z.number(),
916
- scheduledBroadcasts: z.number(),
917
- mail: z.object({
918
- sent: z.number(),
919
- queued: z.number(),
920
- failed: z.number(),
921
- bounced: z.number()
922
- }),
923
- quota: z.object({
924
- dailyUsed: z.number(),
925
- dailyLimit: z.number(),
926
- monthlyUsed: z.number(),
927
- monthlyLimit: z.number()
928
- })
929
- });
930
- var feedbackConnectionStatus = [
931
- "pending",
932
- "healthy",
933
- "stale",
934
- "error",
935
- "retiring",
936
- "disabled"
937
- ];
938
- var feedbackConnectionSchema = z.object({
939
- connectionId: z.string(),
940
- espId: z.string(),
941
- provider: z.string(),
942
- webhookUrl: z.string(),
943
- hasCredential: z.boolean(),
944
- status: z.enum(feedbackConnectionStatus),
945
- lastReceivedAt: z.string().nullable().optional(),
946
- lastVerifiedAt: z.string().nullable().optional(),
947
- lastErrorCode: z.string().nullable().optional(),
948
- createdAt: z.string().optional(),
949
- updatedAt: z.string().optional()
950
- });
951
- var upsertFeedbackConnectionBodySchema = z.object({
952
- /** The provider's webhook signing secret / public key / shared header
953
- * value, depending on provider. Never returned after this call. */
954
- credential: z.string().min(1),
955
- /** SES only (reserved — not usable until the platform/SES phase ships). */
956
- expectedTopicArn: z.string().optional()
957
- });
958
- var testFeedbackConnectionResponseSchema = z.object({
959
- success: z.boolean(),
960
- error: z.string().optional()
961
- });
962
- var deliveryEventType = [
963
- "accepted",
964
- "delivered",
965
- "delayed",
966
- "soft_bounce",
967
- "hard_bounce",
968
- "failed",
969
- "complaint",
970
- "suppressed",
971
- "rejected",
972
- "unknown"
973
- ];
974
- var bounceClass = ["permanent", "transient", "undetermined"];
975
- var deliverySourceTypes = ["organization", "team"];
976
- var deliveryEventSchema = z.object({
977
- eventId: z.string(),
978
- provider: z.string(),
979
- espId: z.string().nullable(),
980
- deliverySourceType: z.enum(deliverySourceTypes).nullable(),
981
- /** Public `msg_...` id of the correlated outbound message, when the
982
- * event was matched to one — see the PRD's correlation section. */
983
- messageId: z.string().nullable(),
984
- recipientEmail: z.string().nullable(),
985
- eventType: z.enum(deliveryEventType),
986
- bounceClass: z.enum(bounceClass).nullable().optional(),
987
- smtpCode: z.number().nullable().optional(),
988
- enhancedStatusCode: z.string().nullable().optional(),
989
- reason: z.string().nullable().optional(),
990
- occurredAt: z.string(),
991
- receivedAt: z.string()
992
- });
993
- var listDeliveryEventsQuerySchema = z.object({
994
- espId: z.string().optional(),
995
- deliverySourceType: z.enum(deliverySourceTypes).optional(),
996
- eventType: z.enum(deliveryEventType).optional(),
997
- createdAfter: z.coerce.number().int().optional(),
998
- createdBefore: z.coerce.number().int().optional(),
999
- offset: z.coerce.number().int().min(1).optional(),
1000
- itemsPerPage: z.coerce.number().int().min(1).optional()
1001
- });
1002
- var suppressionReason = [
1003
- "hard_bounce",
1004
- "complaint",
1005
- "repeated_soft_bounce",
1006
- "provider_suppression",
1007
- "manual"
1008
- ];
1009
- var suppressionSchema = z.object({
1010
- suppressionId: z.string(),
1011
- recipientEmail: z.string().nullable(),
1012
- reason: z.enum(suppressionReason),
1013
- active: z.boolean(),
1014
- firstSuppressedAt: z.string(),
1015
- lastSuppressedAt: z.string(),
1016
- releasedAt: z.string().nullable().optional(),
1017
- releaseReason: z.string().nullable().optional()
1018
- });
1019
- var listSuppressionsQuerySchema = z.object({
1020
- active: z.coerce.boolean().optional(),
1021
- reason: z.enum(suppressionReason).optional(),
1022
- offset: z.coerce.number().int().min(1).optional(),
1023
- itemsPerPage: z.coerce.number().int().min(1).optional()
1024
- });
1025
- var releaseSuppressionBodySchema = z.object({
1026
- explanation: z.string().min(1).max(2e3).optional()
1027
- });
1028
1143
  var organizationRoleSchema = z.enum(["owner", "admin", "member"]);
1029
1144
  var organizationSchema = z.object({
1030
1145
  organizationId: z.string(),
1031
1146
  name: z.string(),
1032
- status: z.enum(["active", "suspended", "closed"]),
1147
+ status: z.enum(["pending_payment", "active", "suspended", "abandoned", "closed"]),
1033
1148
  createdAt: z.string(),
1034
1149
  updatedAt: z.string()
1035
1150
  });
@@ -1059,6 +1174,8 @@ var updateOrganizationMemberBodySchema = z.object({
1059
1174
  });
1060
1175
  var organizationKeyScopes = [
1061
1176
  "organization:read",
1177
+ "delivery:read",
1178
+ "delivery:manage",
1062
1179
  "teams:provision",
1063
1180
  "teams:read",
1064
1181
  "teams:manage",
@@ -1114,12 +1231,7 @@ var organizationMailActivityTeamSchema = z.object({
1114
1231
  mail: organizationMailCountsSchema
1115
1232
  });
1116
1233
  var organizationMailActivitySchema = z.object({
1117
- rangeDays: z.union([
1118
- z.literal(1),
1119
- z.literal(3),
1120
- z.literal(7),
1121
- z.literal(30)
1122
- ]),
1234
+ rangeDays: z.union([z.literal(1), z.literal(3), z.literal(7), z.literal(30)]),
1123
1235
  totals: organizationMailCountsSchema,
1124
1236
  teams: z.array(organizationMailActivityTeamSchema)
1125
1237
  });
@@ -1138,28 +1250,526 @@ var organizationAuditEventSchema = z.object({
1138
1250
  metadata: z.record(z.any()),
1139
1251
  createdAt: z.string()
1140
1252
  });
1141
- var c = initContract();
1142
- var contactsContract = c.router(
1143
- {
1144
- create: {
1145
- method: "POST",
1146
- path: "/contacts",
1147
- body: createContactBodySchema,
1148
- responses: { 201: contactSchema },
1149
- summary: "Create a contact",
1150
- description: "Creates a contact (subscriber). If a contact with the same email already exists for this team, the existing contact is returned."
1253
+ var overviewQuerySchema = z.object({
1254
+ /** Delivery activity window, in days. Defaults to the last 7 days. */
1255
+ rangeDays: z.coerce.number().int().refine((value) => [1, 3, 7, 30].includes(value)).optional()
1256
+ });
1257
+ var overviewSchema = z.object({
1258
+ activeSequences: z.number(),
1259
+ ongoingContacts: z.number(),
1260
+ scheduledBroadcasts: z.number(),
1261
+ mail: z.object({
1262
+ sent: z.number(),
1263
+ queued: z.number(),
1264
+ failed: z.number(),
1265
+ bounced: z.number()
1266
+ }),
1267
+ quota: z.object({
1268
+ dailyUsed: z.number(),
1269
+ dailyLimit: z.number(),
1270
+ monthlyUsed: z.number(),
1271
+ monthlyLimit: z.number()
1272
+ })
1273
+ });
1274
+ var reputationProviders = ["google_postmaster", "microsoft_snds"];
1275
+ var connectionSchema = z.object({
1276
+ status: z.enum(["active", "error"]),
1277
+ /** e.g. the Google account that connected Postmaster Tools. */
1278
+ accountLabel: z.string().nullable(),
1279
+ lastSyncedAt: z.string().nullable(),
1280
+ lastError: z.string().nullable(),
1281
+ connectedAt: z.string()
1282
+ });
1283
+ var googleDaySchema = z.object({
1284
+ day: z.string(),
1285
+ spamRate: z.number().nullable(),
1286
+ spfRate: z.number().nullable(),
1287
+ dkimRate: z.number().nullable(),
1288
+ dmarcRate: z.number().nullable(),
1289
+ deliveryErrorRate: z.number().nullable()
1290
+ });
1291
+ var sndsDaySchema = z.object({
1292
+ day: z.string(),
1293
+ /** Outlook's spam filter verdict for the IP's mail. */
1294
+ filterResult: z.enum(["green", "yellow", "red"]).nullable(),
1295
+ /** Complaints per recipient; `null` when SNDS reports "< 0.1%". */
1296
+ complaintRate: z.number().nullable(),
1297
+ complaintRateText: z.string().nullable(),
1298
+ trapHits: z.number().int().nullable(),
1299
+ recipients: z.number().int().nullable()
1300
+ });
1301
+ var reputationAlertSchema = z.object({
1302
+ provider: z.enum(reputationProviders),
1303
+ /** The domain or IP. */
1304
+ subject: z.string(),
1305
+ signal: z.enum(["spam_rate", "compliance", "snds_filter"]),
1306
+ level: z.enum(["warning", "critical"]),
1307
+ message: z.string()
1308
+ });
1309
+ var reputationSchema = z.object({
1310
+ google: z.object({
1311
+ /** Whether this SendLit deployment has a Google OAuth client set up. */
1312
+ available: z.boolean(),
1313
+ connection: connectionSchema.nullable(),
1314
+ domains: z.array(
1315
+ z.object({
1316
+ domain: z.string(),
1317
+ /** `not_in_postmaster`: verify the domain in Postmaster Tools with the
1318
+ * connected Google account. */
1319
+ status: z.enum(["ok", "not_in_postmaster", "pending"]),
1320
+ /** Google's verdict on its bulk-sender requirements. */
1321
+ compliance: z.object({
1322
+ status: z.enum(["compliant", "needs_work", "unknown"]),
1323
+ needsWork: z.array(z.string())
1324
+ }).nullable(),
1325
+ days: z.array(googleDaySchema)
1326
+ })
1327
+ )
1328
+ }),
1329
+ snds: z.object({
1330
+ connection: connectionSchema.nullable(),
1331
+ ips: z.array(z.object({ ip: z.string(), days: z.array(sndsDaySchema) }))
1332
+ }),
1333
+ alerts: z.array(reputationAlertSchema)
1334
+ });
1335
+ var connectSndsBodySchema = z.object({
1336
+ dataUrl: z.string().url().describe(
1337
+ "The SNDS automated data access link (Automated Data Access page in SNDS). It expires after 30 days; paste the new one when it does."
1338
+ )
1339
+ });
1340
+ var segmentSchema = z.object({
1341
+ segmentId: z.string(),
1342
+ name: z.string(),
1343
+ filter: contactFilterSchema,
1344
+ createdAt: z.string().nullable(),
1345
+ updatedAt: z.string().nullable()
1346
+ });
1347
+ var createSegmentBodySchema = z.object({
1348
+ name: z.string().min(1),
1349
+ filter: contactFilterSchema
1350
+ });
1351
+ var updateSegmentBodySchema = z.object({
1352
+ name: z.string().min(1).optional(),
1353
+ filter: contactFilterSchema.optional()
1354
+ });
1355
+ var generalSettingsSchema = z.object({
1356
+ /** Physical postal address rendered in email footers
1357
+ * (CAN-SPAM/GDPR requirement). */
1358
+ mailingAddress: z.string().nullable(),
1359
+ updatedAt: z.string().nullable().optional()
1360
+ });
1361
+ var updateGeneralSettingsBodySchema = z.object({
1362
+ /** Send an empty string to clear the mailing address. */
1363
+ mailingAddress: z.string().optional()
1364
+ });
1365
+ var trackingDomainStatuses = ["pending", "verified", "failed"];
1366
+ var trackingDomainSchema = z.object({
1367
+ domain: z.string().nullable(),
1368
+ /** `pending` until the CNAME and HTTPS work; `failed` after the domain
1369
+ * stopped working, when links fall back to SendLit's own host. */
1370
+ status: z.enum(trackingDomainStatuses).nullable(),
1371
+ /** The host the domain's CNAME record must point to. */
1372
+ cnameTarget: z.string(),
1373
+ /** Why the last check failed: `cname_missing`, `cname_mismatch`,
1374
+ * `unreachable` (no HTTPS answer yet) or `dns_error`. */
1375
+ error: z.string().nullable(),
1376
+ verifiedAt: z.string().nullable(),
1377
+ checkedAt: z.string().nullable()
1378
+ });
1379
+ var updateTrackingDomainBodySchema = z.object({
1380
+ /** A subdomain such as `track.example.com`; `null` removes it. */
1381
+ domain: z.string().max(253).nullable()
1382
+ });
1383
+ var suppressionReason = [
1384
+ "hard_bounce",
1385
+ "complaint",
1386
+ "repeated_soft_bounce",
1387
+ "provider_suppression",
1388
+ "manual"
1389
+ ];
1390
+ var suppressionSchema = z.object({
1391
+ suppressionId: z.string(),
1392
+ recipientEmail: z.string().nullable(),
1393
+ reason: z.enum(suppressionReason),
1394
+ active: z.boolean(),
1395
+ firstSuppressedAt: z.string(),
1396
+ lastSuppressedAt: z.string(),
1397
+ releasedAt: z.string().nullable().optional(),
1398
+ releaseReason: z.string().nullable().optional()
1399
+ });
1400
+ var listSuppressionsQuerySchema = z.object({
1401
+ active: z.coerce.boolean().optional(),
1402
+ reason: z.enum(suppressionReason).optional(),
1403
+ offset: z.coerce.number().int().min(1).optional(),
1404
+ itemsPerPage: z.coerce.number().int().min(1).optional()
1405
+ });
1406
+ var releaseSuppressionBodySchema = z.object({
1407
+ explanation: z.string().min(1).max(2e3).optional()
1408
+ });
1409
+ var createSuppressionBodySchema = z.object({
1410
+ email: z.string().email(),
1411
+ note: z.string().max(2e3).optional().describe(
1412
+ "Why the address is blocked, e.g. a legal request; kept in the audit trail"
1413
+ )
1414
+ });
1415
+ var teamSchema = z.object({
1416
+ teamId: z.string(),
1417
+ /** Public organization identifier. Present when an end user lists the
1418
+ * teams they belong to, so the dashboard can keep workspace selection
1419
+ * scoped to one organization. */
1420
+ organizationId: z.string().optional(),
1421
+ organizationName: z.string().optional(),
1422
+ name: z.string(),
1423
+ status: z.enum(["active", "sending_suspended", "archived"]),
1424
+ externalId: z.string().nullable().optional(),
1425
+ createdAt: z.string().nullable().optional(),
1426
+ updatedAt: z.string().nullable().optional(),
1427
+ /** True when the calling human is already a `team_members` row. Always
1428
+ * false for organization API keys. Omitted on non-list team payloads. */
1429
+ viewerIsMember: z.boolean().optional()
1430
+ });
1431
+ var apiKeySchema = z.object({
1432
+ keyId: z.string(),
1433
+ keyPrefix: z.string(),
1434
+ name: z.string(),
1435
+ expiresAt: z.string().nullable().optional(),
1436
+ lastUsedAt: z.string().nullable().optional(),
1437
+ revokedAt: z.string().nullable().optional(),
1438
+ createdAt: z.string().nullable().optional()
1439
+ });
1440
+ var createdApiKeySchema = apiKeySchema.extend({
1441
+ key: z.string()
1442
+ });
1443
+ var createTeamBodySchema = z.object({ name: z.string().min(1) });
1444
+ var renameTeamBodySchema = z.object({ name: z.string().min(1) });
1445
+ var createApiKeyBodySchema = z.object({ name: z.string().min(1) });
1446
+ var provisionTeamBodySchema = z.object({
1447
+ externalId: z.string().min(1),
1448
+ name: z.string().min(1),
1449
+ sender: z.object({
1450
+ fromName: z.string().min(1).optional(),
1451
+ replyTo: z.string().email().optional()
1452
+ }).optional(),
1453
+ mailingAddress: z.string().min(1).optional(),
1454
+ delivery: z.object({
1455
+ useOrganizationDefault: z.boolean().optional(),
1456
+ teamEspEnabled: z.boolean().optional(),
1457
+ teamCanChangeDefault: z.boolean().optional()
1458
+ }).optional(),
1459
+ quota: z.object({
1460
+ dailyLimit: z.number().int().positive().nullable().optional(),
1461
+ monthlyLimit: z.number().int().positive().nullable().optional()
1462
+ }).optional()
1463
+ });
1464
+ var provisionedTeamBaseSchema = z.object({
1465
+ teamId: z.string(),
1466
+ externalId: z.string(),
1467
+ name: z.string(),
1468
+ deliverySource: z.object({ type: z.literal("organization") })
1469
+ });
1470
+ var provisionTeamResponseSchema = z.discriminatedUnion("created", [
1471
+ provisionedTeamBaseSchema.extend({
1472
+ created: z.literal(true),
1473
+ apiKey: z.string()
1474
+ }),
1475
+ provisionedTeamBaseSchema.extend({
1476
+ created: z.literal(false),
1477
+ apiKey: z.null()
1478
+ })
1479
+ ]);
1480
+ var provisionedTeamSchema = provisionedTeamBaseSchema.extend({
1481
+ status: z.enum(["active", "sending_suspended", "archived"]),
1482
+ mailingAddress: z.string().nullable(),
1483
+ teamEspEnabled: z.boolean(),
1484
+ teamCanChangeDefault: z.boolean(),
1485
+ createdAt: z.string().nullable(),
1486
+ updatedAt: z.string().nullable()
1487
+ });
1488
+ var updateProvisionedTeamBodySchema = z.object({
1489
+ name: z.string().min(1).optional(),
1490
+ sender: z.object({
1491
+ fromName: z.string().min(1).nullable().optional(),
1492
+ replyTo: z.string().email().nullable().optional()
1493
+ }).optional(),
1494
+ mailingAddress: z.string().min(1).nullable().optional(),
1495
+ delivery: z.object({
1496
+ teamEspEnabled: z.boolean().optional(),
1497
+ teamCanChangeDefault: z.boolean().optional()
1498
+ }).optional(),
1499
+ quota: z.object({
1500
+ dailyLimit: z.number().int().nonnegative().nullable().optional(),
1501
+ monthlyLimit: z.number().int().nonnegative().nullable().optional()
1502
+ }).optional()
1503
+ }).refine((body) => Object.keys(body).length > 0, {
1504
+ message: "At least one field is required"
1505
+ });
1506
+ var usageWindowSchema = z.object({
1507
+ limit: z.number().int().nullable(),
1508
+ accepted: z.number().int().nonnegative(),
1509
+ reserved: z.number().int().nonnegative(),
1510
+ remaining: z.number().int().nullable(),
1511
+ resetsAt: z.string()
1512
+ });
1513
+ var provisionedTeamUsageSchema = z.object({
1514
+ day: usageWindowSchema,
1515
+ month: usageWindowSchema
1516
+ });
1517
+ var templatePurposes = ["marketing", "transactional"];
1518
+ var templatePurposeSchema = z.enum(templatePurposes).describe(
1519
+ "Immutable sending purpose. Marketing templates require a final managed footer; transactional templates are footer-free and are valid for POST /emails."
1520
+ );
1521
+ var templateVariableDefinitionSchema = z.object({
1522
+ path: z.string().min(1).describe("Dot-separated Liquid variable path."),
1523
+ description: z.string().describe("Human-readable value description."),
1524
+ example: z.any().describe("Example value used in generated requests.")
1525
+ });
1526
+ var emailTemplateSchema = z.object({
1527
+ templateId: z.string(),
1528
+ title: z.string(),
1529
+ purpose: templatePurposeSchema,
1530
+ content: emailContentSchema,
1531
+ requiredVariables: z.array(z.string()).describe(
1532
+ "Sorted, server-discovered Liquid paths that must be supplied. Defaults and inactive guarded branches are omitted."
1533
+ ),
1534
+ validationError: z.string().optional().describe(
1535
+ "Present only for a retired template that predates the managed-footer format. It cannot be edited, duplicated, or sent; recreate it instead."
1536
+ ),
1537
+ createdAt: z.string().nullable(),
1538
+ updatedAt: z.string().nullable()
1539
+ });
1540
+ var createTemplateBodySchema = z.object({
1541
+ title: z.string().min(1),
1542
+ purpose: templatePurposeSchema.default("marketing"),
1543
+ content: emailContentInputSchema
1544
+ });
1545
+ var updateTemplateBodySchema = z.object({
1546
+ title: z.string().min(1).optional(),
1547
+ content: emailContentInputSchema.optional()
1548
+ });
1549
+ var systemTemplateSchema = z.object({
1550
+ templateId: z.string(),
1551
+ title: z.string(),
1552
+ description: z.string(),
1553
+ purpose: templatePurposeSchema,
1554
+ content: emailContentSchema,
1555
+ requiredVariables: z.array(z.string()).describe("Sorted, server-discovered Liquid paths that must be supplied."),
1556
+ variableDefinitions: z.array(templateVariableDefinitionSchema).optional().describe(
1557
+ "Documentation metadata for built-in starter variables; runtime discovery remains authoritative."
1558
+ )
1559
+ });
1560
+ var listTemplatesQuerySchema = z.object({
1561
+ purpose: templatePurposeSchema.optional()
1562
+ });
1563
+ var duplicateTemplateBodySchema = z.object({
1564
+ title: z.string().min(1).optional()
1565
+ });
1566
+ var templateValidationErrorSchema = z.object({
1567
+ error: z.string(),
1568
+ variables: z.array(z.string()).optional()
1569
+ });
1570
+ var templateNotTransactionalErrorSchema = z.object({
1571
+ error: z.literal("template_not_transactional")
1572
+ });
1573
+ var templateNotMarketingErrorSchema = z.object({
1574
+ error: z.literal("template_not_marketing")
1575
+ });
1576
+ var transactionalEmailStatus = [
1577
+ "queued",
1578
+ "sent",
1579
+ "failed",
1580
+ "bounced",
1581
+ "suppressed"
1582
+ ];
1583
+ var transactionalEmailSchema = z.object({
1584
+ txeId: z.string(),
1585
+ to: z.string(),
1586
+ from: z.string().nullable(),
1587
+ replyTo: z.string().nullable(),
1588
+ subject: z.string(),
1589
+ templateId: z.string().nullable(),
1590
+ variables: z.record(z.any()),
1591
+ status: z.enum(transactionalEmailStatus),
1592
+ error: z.string().nullable(),
1593
+ trackOpens: z.boolean(),
1594
+ trackClicks: z.boolean(),
1595
+ openCount: z.number(),
1596
+ clickCount: z.number(),
1597
+ sentAt: z.string().nullable(),
1598
+ createdAt: z.string().nullable(),
1599
+ updatedAt: z.string().nullable()
1600
+ });
1601
+ var transactionalEmailDetailSchema = transactionalEmailSchema.extend({
1602
+ html: z.string().nullable(),
1603
+ /** Caller-supplied plain text; `null` when it was generated from `html`. */
1604
+ text: z.string().nullable().optional()
1605
+ });
1606
+ var reservedHeaders = ["from", "to", "subject", "content-type"];
1607
+ var emailHeadersSchema = z.record(z.string()).superRefine((headers2, ctx) => {
1608
+ for (const [name, value] of Object.entries(headers2)) {
1609
+ if (/[\r\n]/.test(name) || /[\r\n]/.test(value)) {
1610
+ ctx.addIssue({
1611
+ code: z.ZodIssueCode.custom,
1612
+ message: "Header names and values must not contain CR/LF characters"
1613
+ });
1614
+ } else if (reservedHeaders.includes(name.toLowerCase())) {
1615
+ ctx.addIssue({
1616
+ code: z.ZodIssueCode.custom,
1617
+ message: `Header "${name}" is set by the send pipeline and cannot be overridden`
1618
+ });
1619
+ }
1620
+ }
1621
+ });
1622
+ var sendEmailBodySchema = z.object({
1623
+ to: z.string().email(),
1624
+ subject: z.string().min(1),
1625
+ templateId: z.string().min(1).optional(),
1626
+ html: z.string().min(1).optional(),
1627
+ text: z.string().min(1).optional().describe(
1628
+ "Plain-text part, sent verbatim. When omitted it is generated from the HTML."
1629
+ ),
1630
+ variables: z.record(z.any()).optional(),
1631
+ replyTo: z.string().email().optional(),
1632
+ headers: emailHeadersSchema.optional(),
1633
+ idempotencyKey: z.string().min(1).max(256).optional(),
1634
+ trackOpens: z.boolean().optional(),
1635
+ trackClicks: z.boolean().optional(),
1636
+ deliverySource: deliverySourceSelectionSchema.optional()
1637
+ }).refine((body) => !!body.templateId !== !!body.html, {
1638
+ message: "Provide exactly one of templateId or html"
1639
+ }).refine((body) => !(body.html && body.variables), {
1640
+ message: "variables requires templateId; inline html is sent verbatim"
1641
+ });
1642
+ var sendEmailResponseSchema = transactionalEmailSchema.pick({
1643
+ txeId: true,
1644
+ status: true
1645
+ });
1646
+ var missingTemplateVariablesErrorSchema = z.object({
1647
+ error: z.literal("missing_template_variables"),
1648
+ missingVariables: z.array(z.string()).min(1)
1649
+ });
1650
+ var listTransactionalEmailsQuerySchema = z.object({
1651
+ status: z.enum(transactionalEmailStatus).optional(),
1652
+ createdAfter: z.coerce.number().int().optional().describe("Millisecond timestamp lower bound (inclusive)"),
1653
+ createdBefore: z.coerce.number().int().optional().describe("Millisecond timestamp upper bound (exclusive)"),
1654
+ offset: z.coerce.number().int().min(1).optional(),
1655
+ itemsPerPage: z.coerce.number().int().min(1).max(50).optional()
1656
+ });
1657
+ var httpUrl = z.string().url().refine((value) => /^https?:\/\//i.test(value), "Must be an http(s) URL");
1658
+ var webSlugSchema = z.string().min(1).max(100).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Lowercase letters, digits and dashes");
1659
+ var webHandleSchema = z.string().min(2).max(40).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Lowercase letters, digits and dashes");
1660
+ var webPublishingSchema = z.object({
1661
+ published: z.boolean(),
1662
+ slug: z.string().nullable(),
1663
+ seoTitle: z.string().nullable(),
1664
+ seoDescription: z.string().nullable(),
1665
+ ogImage: z.string().nullable(),
1666
+ noindex: z.boolean(),
1667
+ canonicalUrl: z.string().nullable(),
1668
+ /** Published and already sent, so the page is public. */
1669
+ live: z.boolean(),
1670
+ /** When the issue was sent; `null` until then. */
1671
+ publishedAt: z.string().nullable(),
1672
+ /** The SendLit-hosted page; `null` while hosted pages are off. */
1673
+ url: z.string().nullable()
1674
+ });
1675
+ var updateWebPublishingBodySchema = z.object({
1676
+ published: z.boolean().optional().describe("Publish the broadcast as a public web page once it's sent"),
1677
+ slug: webSlugSchema.optional().describe("URL slug; defaults to one made from the title"),
1678
+ seoTitle: z.string().trim().max(200).nullable().optional(),
1679
+ seoDescription: z.string().trim().max(500).nullable().optional(),
1680
+ ogImage: httpUrl.nullable().optional().describe("Image for social previews"),
1681
+ noindex: z.boolean().optional().describe("Ask search engines not to index the page"),
1682
+ canonicalUrl: httpUrl.nullable().optional().describe("Canonical URL, when a platform hosts the issue on its own site")
1683
+ });
1684
+ var webSettingsSchema = z.object({
1685
+ enabled: z.boolean(),
1686
+ handle: z.string().nullable(),
1687
+ title: z.string().nullable(),
1688
+ description: z.string().nullable(),
1689
+ /** Signup form shown on the archive page. */
1690
+ signupFormId: z.string().nullable(),
1691
+ archiveUrl: z.string().nullable(),
1692
+ rssUrl: z.string().nullable()
1693
+ });
1694
+ var updateWebSettingsBodySchema = z.object({
1695
+ enabled: z.boolean().optional().describe(
1696
+ "Host the archive and issue pages on SendLit; off when a platform renders them"
1697
+ ),
1698
+ handle: webHandleSchema.optional().describe("Archive URL: /w/<handle>"),
1699
+ title: z.string().trim().max(200).nullable().optional(),
1700
+ description: z.string().trim().max(1e3).nullable().optional(),
1701
+ signupFormId: z.string().nullable().optional()
1702
+ });
1703
+ var webIssueSummarySchema = z.object({
1704
+ slug: z.string(),
1705
+ title: z.string(),
1706
+ publishedAt: z.string(),
1707
+ excerpt: z.string(),
1708
+ seoTitle: z.string().nullable(),
1709
+ seoDescription: z.string().nullable(),
1710
+ ogImage: z.string().nullable(),
1711
+ noindex: z.boolean(),
1712
+ canonicalUrl: z.string().nullable(),
1713
+ url: z.string().nullable()
1714
+ });
1715
+ var webIssueSchema = webIssueSummarySchema.extend({
1716
+ html: z.string()
1717
+ });
1718
+ var listWebIssuesQuerySchema = z.object({
1719
+ offset: z.coerce.number().int().min(1).optional(),
1720
+ itemsPerPage: z.coerce.number().int().min(1).max(50).optional()
1721
+ });
1722
+
1723
+ // ../api-contract/src/contract.ts
1724
+ var c = initContract();
1725
+ var contactsContract = c.router(
1726
+ {
1727
+ create: {
1728
+ method: "POST",
1729
+ path: "/contacts",
1730
+ body: createContactBodySchema,
1731
+ responses: {
1732
+ 201: contactSchema,
1733
+ 402: errorSchema,
1734
+ 409: errorSchema
1735
+ },
1736
+ summary: "Create a contact",
1737
+ description: "Creates a contact (subscriber). If a contact with the same email already exists for this team, the existing contact is returned."
1738
+ },
1739
+ list: {
1740
+ method: "GET",
1741
+ path: "/contacts",
1742
+ query: listContactsQuerySchema,
1743
+ responses: {
1744
+ 200: paginated(contactSchema),
1745
+ 400: errorSchema,
1746
+ 404: errorSchema
1747
+ },
1748
+ summary: "List contacts",
1749
+ 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."
1750
+ },
1751
+ import: {
1752
+ method: "POST",
1753
+ path: "/contacts/import",
1754
+ body: importContactsBodySchema,
1755
+ responses: {
1756
+ 200: importContactsResultSchema,
1757
+ 400: errorSchema
1758
+ },
1759
+ summary: "Import contacts",
1760
+ description: "Creates or updates up to 1000 contacts per request, matched by email. A status can only get stricter (subscribed < unsubscribed < bounced < complained): an import never re-subscribes an unsubscribed or suppressed contact, and bounced or complained rows are imported unsubscribed and added to the suppression list. Paused contacts stay subscribed with the `paused` tag. Tags and custom fields are merged into existing contacts, and an earlier createdAt replaces a later one. Imports don't trigger sequences. Subscribed contacts over the plan's limit are skipped with `plan_limit_reached`."
1151
1761
  },
1152
- list: {
1762
+ export: {
1153
1763
  method: "GET",
1154
- path: "/contacts",
1155
- query: listContactsQuerySchema,
1764
+ path: "/contacts/export",
1765
+ query: exportContactsQuerySchema,
1156
1766
  responses: {
1157
- 200: paginated(contactSchema),
1767
+ 200: c.otherResponse({ contentType: "text/csv", body: z.string() }),
1158
1768
  400: errorSchema,
1159
1769
  404: errorSchema
1160
1770
  },
1161
- summary: "List contacts",
1162
- 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."
1771
+ summary: "Export contacts as CSV",
1772
+ description: "Returns every contact, or those matching segmentId and/or filter, as CSV: email, name, status (subscribed, unsubscribed, bounced or complained), tags, created_at, suppression_reason, then one column per custom field."
1163
1773
  },
1164
1774
  get: {
1165
1775
  method: "GET",
@@ -1171,7 +1781,12 @@ var contactsContract = c.router(
1171
1781
  method: "PATCH",
1172
1782
  path: "/contacts/:contactId",
1173
1783
  body: updateContactBodySchema,
1174
- responses: { 200: contactSchema, 404: errorSchema },
1784
+ responses: {
1785
+ 200: contactSchema,
1786
+ 402: errorSchema,
1787
+ 404: errorSchema,
1788
+ 409: errorSchema
1789
+ },
1175
1790
  summary: "Update a contact"
1176
1791
  },
1177
1792
  addTag: {
@@ -1262,7 +1877,10 @@ var mediaContract = c.router(
1262
1877
  body: c.noBody(),
1263
1878
  responses: { 200: mediaUploadSignatureSchema, 500: errorSchema },
1264
1879
  summary: "Generate a MediaLit upload signature",
1265
- 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."
1880
+ description: (
1881
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: literal placeholder in user-facing API docs, not a template
1882
+ "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."
1883
+ )
1266
1884
  },
1267
1885
  get: {
1268
1886
  method: "GET",
@@ -1408,7 +2026,8 @@ var sequencesContract = c.router(
1408
2026
  400: errorSchema,
1409
2027
  404: errorSchema
1410
2028
  },
1411
- summary: "Update a broadcast or sequence"
2029
+ summary: "Update a broadcast or sequence",
2030
+ description: `A broadcast's title is its email's subject, so once the broadcast has been sent, changing the title returns 400 with the error "This broadcast has already been sent".`
1412
2031
  },
1413
2032
  remove: {
1414
2033
  method: "DELETE",
@@ -1440,7 +2059,20 @@ var sequencesContract = c.router(
1440
2059
  422: templateNotMarketingErrorSchema
1441
2060
  },
1442
2061
  summary: "Update an email within a sequence",
1443
- description: "When templateId is supplied, it must identify a marketing template; transactional templates return 422 template_not_marketing."
2062
+ description: `When templateId is supplied, it must identify a marketing template; transactional templates return 422 template_not_marketing. Edits to an active sequence's email apply to later sends only: the "view in browser" page of an email already sent keeps showing what was sent. A sent broadcast can't be edited; the request returns it unchanged.`
2063
+ },
2064
+ sendEmailTest: {
2065
+ method: "POST",
2066
+ path: "/sequences/:sequenceId/emails/:emailId/test",
2067
+ body: sendSequenceEmailTestBodySchema,
2068
+ responses: {
2069
+ 200: sequenceEmailTestResultSchema,
2070
+ 400: errorSchema,
2071
+ 404: errorSchema,
2072
+ 429: errorSchema
2073
+ },
2074
+ summary: "Send a test of a broadcast or sequence email",
2075
+ description: "Renders the email exactly like a real send (merge tags, footer, tracking) and sends it with a `[Test]` subject prefix through the delivery source the real send would use. Its \"view in browser\" link shows the email as it was when tested, not later edits. Merge tags use the recipient's contact data when they are a contact. Opens, clicks and the unsubscribe link in a test change nothing. Suppressed addresses are skipped. Every recipient counts as one test: by default a team can send 100 test emails in any 24 hours (50 in any 3 hours) and 20 per email per 24 hours, after which this returns 429 `test_send_limit_reached` or `test_send_email_limit_reached`. Tests through an organization's shared mailbox also count against the team's shared-delivery quota (429 `organization_team_quota_exhausted` or `organization_quota_exhausted`)."
1444
2076
  },
1445
2077
  removeEmail: {
1446
2078
  method: "DELETE",
@@ -1462,7 +2094,7 @@ var sequencesContract = c.router(
1462
2094
  422: errorSchema
1463
2095
  },
1464
2096
  summary: "Start a broadcast or activate a sequence",
1465
- description: "Requires a non-empty mailing address in the team's general settings."
2097
+ description: "Requires a non-empty mailing address in the team's general settings. On SendLit Cloud, a new organization's first broadcast to 1,000 or more contacts through its own ESP is reviewed once before it can start (400 `broadcast_held_for_review`); start it again once approved."
1466
2098
  },
1467
2099
  pause: {
1468
2100
  method: "POST",
@@ -1471,17 +2103,36 @@ var sequencesContract = c.router(
1471
2103
  responses: { 200: sequenceSchema, 400: errorSchema },
1472
2104
  summary: "Pause an active sequence"
1473
2105
  },
2106
+ getWeb: {
2107
+ method: "GET",
2108
+ path: "/sequences/:sequenceId/web",
2109
+ responses: { 200: webPublishingSchema, 404: errorSchema },
2110
+ summary: "Get a broadcast's web publishing settings"
2111
+ },
2112
+ updateWeb: {
2113
+ method: "PATCH",
2114
+ path: "/sequences/:sequenceId/web",
2115
+ body: updateWebPublishingBodySchema,
2116
+ responses: {
2117
+ 200: webPublishingSchema,
2118
+ 400: errorSchema,
2119
+ 404: errorSchema,
2120
+ 409: errorSchema
2121
+ },
2122
+ summary: "Publish a broadcast to the web, or change how it's published",
2123
+ description: "Only broadcasts can be published. The page goes live once the broadcast is sent. Publishing without a slug makes one from the title; 409 `slug_taken` when another issue of the team uses the slug."
2124
+ },
1474
2125
  stats: {
1475
2126
  method: "GET",
1476
2127
  path: "/sequences/:sequenceId/stats",
1477
- responses: { 200: sequenceStatsSchema },
2128
+ responses: { 200: sequenceStatsSchema, 404: errorSchema },
1478
2129
  summary: "Delivery / open-rate / click-through-rate stats for a sequence"
1479
2130
  },
1480
2131
  subscribers: {
1481
2132
  method: "GET",
1482
2133
  path: "/sequences/:sequenceId/subscribers",
1483
2134
  query: listSubscribersQuerySchema,
1484
- responses: { 200: c.type() },
2135
+ responses: { 200: c.type(), 404: errorSchema },
1485
2136
  summary: "List contact ids that have received this sequence"
1486
2137
  }
1487
2138
  },
@@ -1496,11 +2147,13 @@ var transactionalContract = c.router(
1496
2147
  responses: {
1497
2148
  202: sendEmailResponseSchema,
1498
2149
  400: errorSchema,
2150
+ 402: errorSchema,
1499
2151
  422: z.union([
1500
2152
  missingTemplateVariablesErrorSchema,
1501
2153
  templateNotTransactionalErrorSchema,
1502
2154
  errorSchema
1503
2155
  ]),
2156
+ 409: errorSchema,
1504
2157
  429: errorSchema
1505
2158
  },
1506
2159
  summary: "Send a transactional email",
@@ -1575,6 +2228,18 @@ var espCollectionContract = c.router(
1575
2228
  summary: "Remove a user-managed ESP configuration",
1576
2229
  description: "Removes an ESP with no active or queued dependencies. Draft, paused, and completed sequences are detached first."
1577
2230
  },
2231
+ domainAuthentication: {
2232
+ method: "GET",
2233
+ path: "/settings/esps/:espId/domain-authentication",
2234
+ query: domainAuthenticationQuerySchema,
2235
+ responses: {
2236
+ 200: domainAuthenticationSchema,
2237
+ 404: errorSchema,
2238
+ 422: errorSchema
2239
+ },
2240
+ summary: "Check SPF, DKIM and DMARC for an ESP's sending domain",
2241
+ description: "Looks up the DNS records of the ESP's From address domain and returns each check's status with the records to add. Returns 422 `from_email_missing` when the ESP has no From address."
2242
+ },
1578
2243
  test: {
1579
2244
  method: "POST",
1580
2245
  path: "/settings/esps/:espId/test",
@@ -1662,10 +2327,131 @@ var generalSettingsContract = c.router(
1662
2327
  },
1663
2328
  { metadata: { tag: "Settings" } }
1664
2329
  );
2330
+ var webSettingsContract = c.router(
2331
+ {
2332
+ get: {
2333
+ method: "GET",
2334
+ path: "/settings/web",
2335
+ responses: { 200: webSettingsSchema },
2336
+ summary: "Get the team's web archive settings"
2337
+ },
2338
+ update: {
2339
+ method: "PATCH",
2340
+ path: "/settings/web",
2341
+ body: updateWebSettingsBodySchema,
2342
+ responses: { 200: webSettingsSchema, 400: errorSchema, 409: errorSchema },
2343
+ summary: "Update the team's web archive settings",
2344
+ description: "Turning hosted pages on picks a handle from the team name and creates a signup form for the archive when none is set. 409 `handle_taken` when another team uses the handle."
2345
+ }
2346
+ },
2347
+ { metadata: { tag: "Web publishing" } }
2348
+ );
2349
+ var trackingDomainContract = c.router(
2350
+ {
2351
+ get: {
2352
+ method: "GET",
2353
+ path: "/settings/tracking-domain",
2354
+ responses: { 200: trackingDomainSchema },
2355
+ summary: "Get the team's custom tracking domain",
2356
+ description: `Open, click, unsubscribe and "view in browser" links use the domain once it is verified; until then, and after it stops working, they use SendLit's own host.`
2357
+ },
2358
+ update: {
2359
+ method: "PUT",
2360
+ path: "/settings/tracking-domain",
2361
+ body: updateTrackingDomainBodySchema,
2362
+ responses: { 200: trackingDomainSchema, 400: errorSchema, 409: errorSchema },
2363
+ summary: "Set or remove the team's custom tracking domain",
2364
+ description: "Use a subdomain (for example `track.example.com`) with a CNAME record pointing to `cnameTarget`. A new domain is `pending` until it is verified; SendLit rechecks pending domains every hour. `null` removes it. Links in emails already sent on a previous domain keep working. 400 `tracking_domain_invalid`, 409 `tracking_domain_taken`."
2365
+ },
2366
+ verify: {
2367
+ method: "POST",
2368
+ path: "/settings/tracking-domain/verify",
2369
+ body: c.noBody(),
2370
+ responses: { 200: trackingDomainSchema, 400: errorSchema },
2371
+ summary: "Check the team's custom tracking domain now",
2372
+ description: "Checks the CNAME record and that SendLit answers over HTTPS on the domain. 400 `tracking_domain_not_set`."
2373
+ }
2374
+ },
2375
+ { metadata: { tag: "Settings" } }
2376
+ );
1665
2377
  var settingsContract = c.router({
1666
2378
  esps: espCollectionContract,
1667
- general: generalSettingsContract
2379
+ general: generalSettingsContract,
2380
+ trackingDomain: trackingDomainContract,
2381
+ web: webSettingsContract
1668
2382
  });
2383
+ var reputationContract = c.router(
2384
+ {
2385
+ get: {
2386
+ method: "GET",
2387
+ path: "/reputation",
2388
+ responses: { 200: reputationSchema },
2389
+ summary: "Get mailbox provider reputation data for the last 30 days",
2390
+ description: "Google Postmaster Tools (spam rate, SPF/DKIM/DMARC pass rates, delivery errors and compliance per sending domain) and Microsoft SNDS (filter result, complaint rate and trap hits per IP), with current alerts."
2391
+ },
2392
+ connectGoogle: {
2393
+ method: "POST",
2394
+ path: "/reputation/google/connect",
2395
+ body: c.noBody(),
2396
+ responses: {
2397
+ 200: z.object({ authorizationUrl: z.string() }),
2398
+ 403: errorSchema,
2399
+ 409: errorSchema
2400
+ },
2401
+ summary: "Start connecting Google Postmaster Tools",
2402
+ description: "Returns the Google sign-in URL to open in a browser. After consent, Google redirects back to SendLit and the data syncs daily. 409 `google_postmaster_not_configured` when this deployment has no Google OAuth client."
2403
+ },
2404
+ disconnectGoogle: {
2405
+ method: "DELETE",
2406
+ path: "/reputation/google",
2407
+ responses: { 204: c.noBody(), 403: errorSchema, 404: errorSchema },
2408
+ summary: "Disconnect Google Postmaster Tools and delete its data"
2409
+ },
2410
+ connectSnds: {
2411
+ method: "PUT",
2412
+ path: "/reputation/snds",
2413
+ body: connectSndsBodySchema,
2414
+ responses: { 200: reputationSchema, 403: errorSchema, 422: errorSchema },
2415
+ summary: "Connect Microsoft SNDS with its automated data access link",
2416
+ description: "The link is checked by downloading the data once. 422 `snds_link_invalid` for links that aren't SNDS links or don't return SNDS data."
2417
+ },
2418
+ disconnectSnds: {
2419
+ method: "DELETE",
2420
+ path: "/reputation/snds",
2421
+ responses: { 204: c.noBody(), 403: errorSchema, 404: errorSchema },
2422
+ summary: "Disconnect Microsoft SNDS and delete its data"
2423
+ },
2424
+ sync: {
2425
+ method: "POST",
2426
+ path: "/reputation/sync",
2427
+ body: c.noBody(),
2428
+ responses: { 200: reputationSchema, 429: errorSchema },
2429
+ summary: "Refresh reputation data now",
2430
+ description: "Data also refreshes daily on its own. Limited to once every 5 minutes."
2431
+ }
2432
+ },
2433
+ { metadata: { tag: "Reputation" } }
2434
+ );
2435
+ var webIssuesContract = c.router(
2436
+ {
2437
+ list: {
2438
+ method: "GET",
2439
+ path: "/web/issues",
2440
+ query: listWebIssuesQuerySchema,
2441
+ responses: { 200: paginated(webIssueSummarySchema) },
2442
+ summary: "List the team's published issues",
2443
+ description: "Broadcasts published to the web that have been sent, newest first. Works whether or not SendLit hosts the pages, so a platform can render the archive itself."
2444
+ },
2445
+ get: {
2446
+ method: "GET",
2447
+ path: "/web/issues/:slug",
2448
+ responses: { 200: webIssueSchema, 404: errorSchema },
2449
+ summary: "Get a published issue with its HTML",
2450
+ description: "The HTML has no personal data, tracking or unsubscribe links. Merge tags fall back to their defaults."
2451
+ }
2452
+ },
2453
+ { metadata: { tag: "Web publishing" } }
2454
+ );
1669
2455
  var teamsContract = c.router(
1670
2456
  {
1671
2457
  list: {
@@ -1680,6 +2466,7 @@ var teamsContract = c.router(
1680
2466
  body: createTeamBodySchema,
1681
2467
  responses: {
1682
2468
  201: teamSchema,
2469
+ 402: errorSchema,
1683
2470
  403: errorSchema,
1684
2471
  409: errorSchema
1685
2472
  },
@@ -1723,6 +2510,18 @@ var teamsContract = c.router(
1723
2510
  );
1724
2511
  var provisioningContract = c.router(
1725
2512
  {
2513
+ getOrganization: {
2514
+ method: "GET",
2515
+ path: "/provisioning/organization",
2516
+ responses: {
2517
+ 200: organizationSchema,
2518
+ 401: errorSchema,
2519
+ 403: errorSchema,
2520
+ 404: errorSchema
2521
+ },
2522
+ summary: "Get the organization bound to the calling API key",
2523
+ description: "Returns only the organization associated with the authenticated organization API key. Requires the organization:read scope; the organization cannot be selected in the request."
2524
+ },
1726
2525
  provisionTeam: {
1727
2526
  method: "POST",
1728
2527
  path: "/provisioning/teams",
@@ -1731,6 +2530,7 @@ var provisioningContract = c.router(
1731
2530
  200: provisionTeamResponseSchema,
1732
2531
  400: errorSchema,
1733
2532
  401: errorSchema,
2533
+ 402: errorSchema,
1734
2534
  403: errorSchema,
1735
2535
  409: errorSchema,
1736
2536
  500: errorSchema
@@ -1820,7 +2620,10 @@ var organizationsContract = c.router(
1820
2620
  method: "GET",
1821
2621
  path: "/organizations",
1822
2622
  responses: {
1823
- 200: itemsList(organizationSchema),
2623
+ 200: z.object({
2624
+ items: z.array(organizationSchema),
2625
+ ownsFreeOrganization: z.boolean()
2626
+ }),
1824
2627
  403: errorSchema
1825
2628
  },
1826
2629
  summary: "List organizations for the current user"
@@ -1829,7 +2632,11 @@ var organizationsContract = c.router(
1829
2632
  method: "POST",
1830
2633
  path: "/organizations",
1831
2634
  body: createOrganizationBodySchema,
1832
- responses: { 201: organizationSchema, 403: errorSchema },
2635
+ responses: {
2636
+ 201: organizationSchema,
2637
+ 403: errorSchema,
2638
+ 409: errorSchema
2639
+ },
1833
2640
  summary: "Create an organization"
1834
2641
  },
1835
2642
  get: {
@@ -1858,11 +2665,27 @@ var organizationsContract = c.router(
1858
2665
  path: "/organizations/:organizationId",
1859
2666
  responses: {
1860
2667
  204: c.noBody(),
2668
+ 401: errorSchema,
1861
2669
  403: errorSchema,
1862
- 404: errorSchema
2670
+ 404: errorSchema,
2671
+ 409: errorSchema,
2672
+ 503: errorSchema
1863
2673
  },
1864
2674
  summary: "Close an organization"
1865
2675
  },
2676
+ abandon: {
2677
+ method: "POST",
2678
+ path: "/organizations/:organizationId/abandon",
2679
+ body: c.noBody(),
2680
+ responses: {
2681
+ 204: c.noBody(),
2682
+ 401: errorSchema,
2683
+ 403: errorSchema,
2684
+ 404: errorSchema,
2685
+ 409: errorSchema
2686
+ },
2687
+ summary: "Hide a pending-payment organization after a cancelled checkout"
2688
+ },
1866
2689
  listMembers: {
1867
2690
  method: "GET",
1868
2691
  path: "/organizations/:organizationId/members",
@@ -2035,7 +2858,8 @@ var organizationsContract = c.router(
2035
2858
  422: errorSchema,
2036
2859
  502: testEspConfigResponseSchema
2037
2860
  },
2038
- summary: "Test an organization-owned ESP configuration"
2861
+ summary: "Test an organization-owned ESP configuration",
2862
+ description: "Organization API keys may test an ESP with an explicit `to` address; they have no signed-in user email to use as a fallback. Requires `esps:manage` and organization binding."
2039
2863
  },
2040
2864
  activateEsp: {
2041
2865
  method: "POST",
@@ -2125,6 +2949,7 @@ var organizationsContract = c.router(
2125
2949
  body: upsertFeedbackConnectionBodySchema,
2126
2950
  responses: {
2127
2951
  200: feedbackConnectionSchema,
2952
+ 400: errorSchema,
2128
2953
  403: errorSchema,
2129
2954
  404: errorSchema
2130
2955
  },
@@ -2159,7 +2984,8 @@ var organizationsContract = c.router(
2159
2984
  403: errorSchema,
2160
2985
  404: errorSchema
2161
2986
  },
2162
- summary: "Get organization delivery policy"
2987
+ summary: "Get organization delivery policy",
2988
+ description: "Organization API keys require the delivery:read scope and must be bound to the path organization. Owner/admin user sessions remain supported."
2163
2989
  },
2164
2990
  updateDeliveryPolicy: {
2165
2991
  method: "PUT",
@@ -2171,7 +2997,8 @@ var organizationsContract = c.router(
2171
2997
  404: errorSchema,
2172
2998
  422: errorSchema
2173
2999
  },
2174
- summary: "Update organization delivery policy"
3000
+ summary: "Update organization delivery policy",
3001
+ description: "Organization API keys require the delivery:manage scope and must be bound to the path organization. This scope authorizes every field in the delivery-policy schema, including shared quotas and team delivery controls. Owner/admin user sessions remain supported."
2175
3002
  },
2176
3003
  getUsage: {
2177
3004
  method: "GET",
@@ -2253,6 +3080,47 @@ var organizationsContract = c.router(
2253
3080
  409: errorSchema
2254
3081
  },
2255
3082
  summary: "Transition a team's organization ESP grant; revoking detaches safe campaigns"
3083
+ },
3084
+ listSendingDomains: {
3085
+ method: "GET",
3086
+ path: "/organizations/:organizationId/sending-domains",
3087
+ responses: {
3088
+ 200: itemsList(sendingDomainSchema),
3089
+ 403: errorSchema,
3090
+ 404: errorSchema
3091
+ },
3092
+ summary: "List verified sending domains"
3093
+ },
3094
+ createSendingDomain: {
3095
+ method: "POST",
3096
+ path: "/organizations/:organizationId/sending-domains",
3097
+ body: createSendingDomainBodySchema,
3098
+ responses: {
3099
+ 201: sendingDomainSchema,
3100
+ 400: errorSchema,
3101
+ 403: errorSchema,
3102
+ 404: errorSchema,
3103
+ 409: errorSchema
3104
+ },
3105
+ summary: "Create a DNS verification challenge for a sending domain"
3106
+ },
3107
+ verifySendingDomain: {
3108
+ method: "POST",
3109
+ path: "/organizations/:organizationId/sending-domains/:domainId/verify",
3110
+ body: c.noBody(),
3111
+ responses: {
3112
+ 200: sendingDomainSchema,
3113
+ 403: errorSchema,
3114
+ 404: errorSchema,
3115
+ 422: errorSchema
3116
+ },
3117
+ summary: "Refresh DNS verification for a sending domain"
3118
+ },
3119
+ revokeSendingDomain: {
3120
+ method: "DELETE",
3121
+ path: "/organizations/:organizationId/sending-domains/:domainId",
3122
+ responses: { 204: c.noBody(), 403: errorSchema, 404: errorSchema },
3123
+ summary: "Revoke a sending domain"
2256
3124
  }
2257
3125
  },
2258
3126
  { metadata: { tag: "Organizations" } }
@@ -2321,7 +3189,7 @@ var feedbackContract = c.router(
2321
3189
  404: errorSchema
2322
3190
  },
2323
3191
  summary: "Create or rotate a user ESP's delivery-feedback connection",
2324
- 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."
3192
+ 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. Amazon SES takes `expectedTopicArn` (the SNS topic subscribed to the webhook URL) instead of `credential`; SendLit confirms the SNS subscription automatically. Fails with 400 `feedback_credential_required`, `feedback_topic_arn_required`, or `feedback_topic_arn_invalid` when the body doesn't fit the provider."
2325
3193
  },
2326
3194
  rotate: {
2327
3195
  method: "POST",
@@ -2343,7 +3211,8 @@ var feedbackContract = c.router(
2343
3211
  200: testFeedbackConnectionResponseSchema,
2344
3212
  404: errorSchema
2345
3213
  },
2346
- summary: "Verify a feedback connection's stored credential"
3214
+ summary: "Verify a feedback connection's stored credential",
3215
+ description: "A smoke test that does not call the provider. Fails with `feedback_invalid_credentials` when the stored credential can't be read, or for Amazon SES with `feedback_subscription_unconfirmed` until SNS has confirmed the subscription."
2347
3216
  },
2348
3217
  remove: {
2349
3218
  method: "DELETE",
@@ -2372,6 +3241,53 @@ var deliveryEventsContract = c.router(
2372
3241
  },
2373
3242
  { metadata: { tag: "Delivery" } }
2374
3243
  );
3244
+ var formsContract = c.router(
3245
+ {
3246
+ list: {
3247
+ method: "GET",
3248
+ path: "/forms",
3249
+ responses: { 200: z.object({ items: z.array(signupFormSchema) }) },
3250
+ summary: "List signup forms"
3251
+ },
3252
+ create: {
3253
+ method: "POST",
3254
+ path: "/forms",
3255
+ body: createSignupFormBodySchema,
3256
+ responses: {
3257
+ 201: signupFormSchema,
3258
+ 400: errorSchema,
3259
+ 422: signupFormSenderErrorSchema
3260
+ },
3261
+ summary: "Create a signup form",
3262
+ description: "A public signup form for the team. People subscribe on its hosted page (`url`) or through an HTML form on your site that posts `email` (and optionally `name`) to the same URL, as a form post or JSON. Double opt-in (the default) emails a confirmation link through the team's delivery source and subscribes only once it is clicked, so it needs a sending mailbox: without one, creating a double opt-in form (or switching a form to it) fails with 422 `confirmation_sender_unavailable`, and an existing form's `sendingIssue` says why submissions are failing; single opt-in never resubscribes someone who unsubscribed. Submissions are rate limited per IP and per form, and suppressed or disposable addresses are dropped. A new subscriber triggers `subscriber:added` sequences."
3263
+ },
3264
+ get: {
3265
+ method: "GET",
3266
+ path: "/forms/:formId",
3267
+ responses: { 200: signupFormSchema, 404: errorSchema },
3268
+ summary: "Get a signup form"
3269
+ },
3270
+ update: {
3271
+ method: "PATCH",
3272
+ path: "/forms/:formId",
3273
+ body: updateSignupFormBodySchema,
3274
+ responses: {
3275
+ 200: signupFormSchema,
3276
+ 404: errorSchema,
3277
+ 422: signupFormSenderErrorSchema
3278
+ },
3279
+ summary: "Update a signup form",
3280
+ description: "Turning double opt-in on fails with 422 `confirmation_sender_unavailable` when the team can't send the confirmation email."
3281
+ },
3282
+ remove: {
3283
+ method: "DELETE",
3284
+ path: "/forms/:formId",
3285
+ responses: { 204: c.noBody(), 404: errorSchema },
3286
+ summary: "Delete a signup form"
3287
+ }
3288
+ },
3289
+ { metadata: { tag: "Contacts" } }
3290
+ );
2375
3291
  var suppressionsContract = c.router(
2376
3292
  {
2377
3293
  list: {
@@ -2381,6 +3297,14 @@ var suppressionsContract = c.router(
2381
3297
  responses: { 200: paginated(suppressionSchema) },
2382
3298
  summary: "List the team's suppressed recipients"
2383
3299
  },
3300
+ create: {
3301
+ method: "POST",
3302
+ path: "/suppressions",
3303
+ body: createSuppressionBodySchema,
3304
+ responses: { 201: suppressionSchema, 400: errorSchema },
3305
+ summary: "Suppress an address",
3306
+ description: "Adds a manual suppression: SendLit never mails the address again from this team (broadcasts, sequences or transactional) until the suppression is released. Use it for role accounts, legal requests or known spam traps. An existing stronger suppression (for example a complaint) is kept."
3307
+ },
2384
3308
  get: {
2385
3309
  method: "GET",
2386
3310
  path: "/suppressions/:suppressionId",
@@ -2402,6 +3326,153 @@ var suppressionsContract = c.router(
2402
3326
  },
2403
3327
  { metadata: { tag: "Delivery" } }
2404
3328
  );
3329
+ var billingContract = c.router(
3330
+ {
3331
+ actionToken: {
3332
+ method: "POST",
3333
+ path: "/billing/action-token",
3334
+ body: billingActionTokenBodySchema,
3335
+ responses: {
3336
+ 201: billingActionTokenResponseSchema,
3337
+ 401: errorSchema,
3338
+ 403: errorSchema,
3339
+ 503: errorSchema
3340
+ },
3341
+ summary: "Issue a single-use token for a sensitive billing action"
3342
+ },
3343
+ organizationCheckout: {
3344
+ method: "POST",
3345
+ path: "/billing/organization-checkouts",
3346
+ body: organizationCheckoutBodySchema,
3347
+ responses: {
3348
+ 201: organizationCheckoutResponseSchema,
3349
+ 400: errorSchema,
3350
+ 401: errorSchema,
3351
+ 402: errorSchema,
3352
+ 403: errorSchema,
3353
+ 409: errorSchema,
3354
+ 503: errorSchema
3355
+ },
3356
+ summary: "Create a paid organization and hosted checkout"
3357
+ },
3358
+ catalog: {
3359
+ method: "GET",
3360
+ path: "/billing/catalog",
3361
+ responses: { 200: billingCatalogSchema, 503: errorSchema },
3362
+ summary: "Read the active billing catalog",
3363
+ description: "Returns environment-configured offers without provider product IDs. Amounts are integer minor units."
3364
+ },
3365
+ organizationBilling: {
3366
+ method: "GET",
3367
+ path: "/organizations/:organizationId/billing",
3368
+ responses: {
3369
+ 200: organizationBillingSchema,
3370
+ 403: errorSchema,
3371
+ 404: errorSchema
3372
+ },
3373
+ summary: "Read organization plan and billing status"
3374
+ },
3375
+ organizationPlanUsage: {
3376
+ method: "GET",
3377
+ path: "/organizations/:organizationId/plan-usage",
3378
+ responses: {
3379
+ 200: organizationPlanUsageSchema,
3380
+ 403: errorSchema,
3381
+ 404: errorSchema
3382
+ },
3383
+ summary: "Read organization plan usage"
3384
+ },
3385
+ checkout: {
3386
+ method: "POST",
3387
+ path: "/organizations/:organizationId/billing/checkout",
3388
+ body: billingCheckoutBodySchema,
3389
+ responses: {
3390
+ 201: billingCheckoutResponseSchema,
3391
+ 400: errorSchema,
3392
+ 401: errorSchema,
3393
+ 402: errorSchema,
3394
+ 403: errorSchema,
3395
+ 409: errorSchema,
3396
+ 503: errorSchema
3397
+ },
3398
+ summary: "Create a hosted organization checkout"
3399
+ },
3400
+ portal: {
3401
+ method: "POST",
3402
+ path: "/organizations/:organizationId/billing/portal",
3403
+ body: c.noBody(),
3404
+ responses: {
3405
+ 201: billingPortalResponseSchema,
3406
+ 401: errorSchema,
3407
+ 402: errorSchema,
3408
+ 403: errorSchema,
3409
+ 404: errorSchema,
3410
+ 503: errorSchema
3411
+ },
3412
+ summary: "Create the billing manager's hosted portal session"
3413
+ },
3414
+ cancel: {
3415
+ method: "POST",
3416
+ path: "/organizations/:organizationId/billing/cancel",
3417
+ body: c.noBody(),
3418
+ responses: {
3419
+ 200: billingCancellationResponseSchema,
3420
+ 401: errorSchema,
3421
+ 402: errorSchema,
3422
+ 403: errorSchema,
3423
+ 404: errorSchema,
3424
+ 409: errorSchema,
3425
+ 503: errorSchema
3426
+ },
3427
+ summary: "Cancel the organization's subscription at the end of the paid period",
3428
+ description: "Requires a browser session, the CSRF headers, and a single-use `cancellation` action token in `X-SendLit-Billing-Action-Token`. Paid access continues until `paidThroughAt`. Idempotent: an already scheduled cancellation returns 200."
3429
+ },
3430
+ resume: {
3431
+ method: "POST",
3432
+ path: "/organizations/:organizationId/billing/resume",
3433
+ body: c.noBody(),
3434
+ responses: {
3435
+ 200: billingCancellationResponseSchema,
3436
+ 401: errorSchema,
3437
+ 402: errorSchema,
3438
+ 403: errorSchema,
3439
+ 404: errorSchema,
3440
+ 409: errorSchema,
3441
+ 503: errorSchema
3442
+ },
3443
+ summary: "Resume a subscription that is scheduled to cancel",
3444
+ description: "Clears a cancellation scheduled for the end of the paid period. Uses a single-use `cancellation` action token. Returns 409 `operation_conflicted` (retryable) while a cancellation is still being sent to the payment provider."
3445
+ },
3446
+ changePlan: {
3447
+ method: "POST",
3448
+ path: "/organizations/:organizationId/billing/plan-change",
3449
+ body: billingPlanChangeBodySchema,
3450
+ responses: {
3451
+ 202: billingPlanChangeResponseSchema,
3452
+ 200: billingPlanChangeResponseSchema,
3453
+ 400: errorSchema,
3454
+ 401: errorSchema,
3455
+ 402: errorSchema,
3456
+ 403: errorSchema,
3457
+ 404: errorSchema,
3458
+ 409: errorSchema,
3459
+ 503: errorSchema
3460
+ },
3461
+ summary: "Request a SendLit-owned organization plan change"
3462
+ },
3463
+ getPlanChange: {
3464
+ method: "GET",
3465
+ path: "/organizations/:organizationId/billing/plan-changes/:changeId",
3466
+ responses: {
3467
+ 200: billingPlanChangeResponseSchema,
3468
+ 403: errorSchema,
3469
+ 404: errorSchema
3470
+ },
3471
+ summary: "Read a plan-change request status"
3472
+ }
3473
+ },
3474
+ { metadata: { tag: "Billing" } }
3475
+ );
2405
3476
  var contract = c.router({
2406
3477
  contacts: contactsContract,
2407
3478
  segments: segmentsContract,
@@ -2417,7 +3488,11 @@ var contract = c.router({
2417
3488
  overview: overviewContract,
2418
3489
  feedback: feedbackContract,
2419
3490
  deliveryEvents: deliveryEventsContract,
2420
- suppressions: suppressionsContract
3491
+ suppressions: suppressionsContract,
3492
+ forms: formsContract,
3493
+ web: webIssuesContract,
3494
+ reputation: reputationContract,
3495
+ billing: billingContract
2421
3496
  });
2422
3497
 
2423
3498
  // src/validate.ts
@@ -2809,7 +3884,7 @@ function configError(message) {
2809
3884
  var SendLit = class {
2810
3885
  constructor(options = {}) {
2811
3886
  const g = globalThis;
2812
- if (typeof g.window !== "undefined" && g.window.document) {
3887
+ if (g.window?.document) {
2813
3888
  throw configError(
2814
3889
  "The SendLit SDK is server-only. Never expose your API key in browser code."
2815
3890
  );
@@ -2824,17 +3899,17 @@ var SendLit = class {
2824
3899
  "Missing credentials: pass apiKey or accessToken, or set SENDLIT_API_KEY"
2825
3900
  );
2826
3901
  }
2827
- const headers = {};
3902
+ const headers2 = {};
2828
3903
  if (accessToken) {
2829
- headers.authorization = `Bearer ${accessToken}`;
3904
+ headers2.authorization = `Bearer ${accessToken}`;
2830
3905
  } else if (apiKey.startsWith(ORGANIZATION_KEY_PREFIX)) {
2831
- headers.authorization = `Bearer ${apiKey}`;
3906
+ headers2.authorization = `Bearer ${apiKey}`;
2832
3907
  } else {
2833
- headers["x-sendlit-apikey"] = apiKey;
3908
+ headers2["x-sendlit-apikey"] = apiKey;
2834
3909
  }
2835
3910
  const teamId = options.teamId ?? env("SENDLIT_TEAM_ID");
2836
3911
  if (teamId)
2837
- headers["x-sendlit-team-id"] = assertId(teamId, "teamId");
3912
+ headers2["x-sendlit-team-id"] = assertId(teamId, "teamId");
2838
3913
  const endpoint = (options.endpoint ?? env("SENDLIT_ENDPOINT") ?? DEFAULT_ENDPOINT).replace(/\/+$/, "");
2839
3914
  const fetchImpl = options.fetch ?? globalThis.fetch;
2840
3915
  if (typeof fetchImpl !== "function") {
@@ -2844,7 +3919,7 @@ var SendLit = class {
2844
3919
  }
2845
3920
  const http = new HttpClient({
2846
3921
  endpoint,
2847
- headers,
3922
+ headers: headers2,
2848
3923
  maxRetries: options.maxRetries ?? 2,
2849
3924
  timeout: options.timeout ?? 3e4,
2850
3925
  fetch: fetchImpl