sendlit 0.2.0 → 0.4.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
@@ -228,6 +228,151 @@ statuses({ skip: "pending_confirmation" }, [
228
228
  "awaiting_confirmation",
229
229
  "not_confirmed"
230
230
  ]);
231
+ var organizationRoleSchema = z.enum(["owner", "admin", "member"]);
232
+ var organizationSchema = z.object({
233
+ organizationId: z.string(),
234
+ name: z.string(),
235
+ status: z.enum(["pending_payment", "active", "suspended", "abandoned", "closed"]),
236
+ createdAt: z.string(),
237
+ updatedAt: z.string()
238
+ });
239
+ var organizationListItemSchema = organizationSchema.extend({
240
+ role: organizationRoleSchema
241
+ });
242
+ var organizationMemberSchema = z.object({
243
+ userId: z.string(),
244
+ email: z.string().email(),
245
+ name: z.string(),
246
+ image: z.string().nullable(),
247
+ role: organizationRoleSchema,
248
+ createdAt: z.string(),
249
+ updatedAt: z.string()
250
+ });
251
+ var createOrganizationBodySchema = z.object({
252
+ name: z.string().trim().min(1)
253
+ });
254
+ var updateOrganizationBodySchema = z.object({
255
+ name: z.string().trim().min(1)
256
+ });
257
+ var addOrganizationMemberBodySchema = z.object({
258
+ /** Existing Better Auth user only. This is a membership lookup, never an
259
+ * authentication or account-creation flow. */
260
+ email: z.string().trim().email(),
261
+ role: organizationRoleSchema
262
+ });
263
+ var updateOrganizationMemberBodySchema = z.object({
264
+ role: organizationRoleSchema
265
+ });
266
+ var organizationKeyScopes = [
267
+ "organization:read",
268
+ "delivery:read",
269
+ "delivery:manage",
270
+ "teams:provision",
271
+ "teams:read",
272
+ "teams:manage",
273
+ "teams:keys",
274
+ "esps:read",
275
+ "esps:manage",
276
+ "grants:manage",
277
+ "usage:read"
278
+ ];
279
+ var organizationApiKeySchema = z.object({
280
+ keyId: z.string(),
281
+ name: z.string(),
282
+ keyPrefix: z.string(),
283
+ scopes: z.array(z.enum(organizationKeyScopes)),
284
+ expiresAt: z.string().nullable(),
285
+ lastUsedAt: z.string().nullable(),
286
+ revokedAt: z.string().nullable(),
287
+ createdAt: z.string()
288
+ });
289
+ var createOrganizationApiKeyBodySchema = z.object({
290
+ name: z.string().trim().min(1),
291
+ scopes: z.array(z.enum(organizationKeyScopes)).min(1),
292
+ expiresAt: z.string().datetime().nullable().optional()
293
+ });
294
+ var createdOrganizationApiKeySchema = organizationApiKeySchema.extend({
295
+ key: z.string()
296
+ });
297
+ var organizationUsageWindowSchema = z.object({
298
+ limit: z.number().int().nullable(),
299
+ accepted: z.number().int().nonnegative(),
300
+ reserved: z.number().int().nonnegative(),
301
+ remaining: z.number().int().nullable(),
302
+ resetsAt: z.string()
303
+ });
304
+ var organizationUsageSchema = z.object({
305
+ day: organizationUsageWindowSchema,
306
+ month: organizationUsageWindowSchema
307
+ });
308
+ var organizationMailActivityQuerySchema = z.object({
309
+ rangeDays: z.coerce.number().int().refine((value) => [1, 3, 7, 30].includes(value)).optional()
310
+ });
311
+ var organizationMailCountsSchema = z.object({
312
+ sent: z.number().int().nonnegative(),
313
+ queued: z.number().int().nonnegative(),
314
+ failed: z.number().int().nonnegative(),
315
+ bounced: z.number().int().nonnegative()
316
+ });
317
+ var organizationMailActivityTeamSchema = z.object({
318
+ teamId: z.string(),
319
+ name: z.string(),
320
+ status: z.enum(["active", "sending_suspended", "archived"]),
321
+ externalId: z.string().nullable(),
322
+ mail: organizationMailCountsSchema
323
+ });
324
+ var organizationMailActivitySchema = z.object({
325
+ rangeDays: z.union([z.literal(1), z.literal(3), z.literal(7), z.literal(30)]),
326
+ totals: organizationMailCountsSchema,
327
+ teams: z.array(organizationMailActivityTeamSchema)
328
+ });
329
+ var organizationEnterTeamBodySchema = z.object({});
330
+ var organizationEnterTeamResponseSchema = z.object({
331
+ teamId: z.string(),
332
+ role: z.enum(["admin", "member"]),
333
+ created: z.boolean()
334
+ });
335
+ var organizationAuditEventSchema = z.object({
336
+ action: z.string(),
337
+ actorType: z.enum(["user", "organization_key", "team_key", "system"]),
338
+ teamId: z.string().nullable(),
339
+ espId: z.string().nullable(),
340
+ grantId: z.string().nullable(),
341
+ metadata: z.record(z.any()),
342
+ createdAt: z.string()
343
+ });
344
+
345
+ // ../api-contract/src/schemas/account.ts
346
+ var accountDeletionBlockerSchema = z.enum([
347
+ "active_subscription_exists",
348
+ "billing_checkout_pending",
349
+ "last_organization_owner",
350
+ "billing_manager_required"
351
+ ]);
352
+ var accountDeletionOrganizationSchema = z.object({
353
+ organizationId: z.string(),
354
+ name: z.string(),
355
+ status: z.enum(["pending_payment", "active", "suspended", "abandoned", "closed"]),
356
+ role: organizationRoleSchema,
357
+ /** `delete`: they are its last owner, so it is deleted with its contacts'
358
+ * data. `leave`: someone else stays in charge; only their membership goes. */
359
+ action: z.enum(["delete", "leave"]),
360
+ teamCount: z.number().int(),
361
+ /** What has to happen before the account can be deleted, if anything. */
362
+ blocker: accountDeletionBlockerSchema.nullable()
363
+ });
364
+ var accountDeletionPreviewSchema = z.object({
365
+ email: z.string(),
366
+ organizations: z.array(accountDeletionOrganizationSchema),
367
+ blocked: z.boolean()
368
+ });
369
+ var deleteAccountBodySchema = z.object({
370
+ /** The account's email, typed to confirm. */
371
+ email: z.string().trim().min(1),
372
+ /** The code sent by `POST /account/deletion/code`. */
373
+ code: z.string().trim().min(1)
374
+ });
375
+ var accountDeletionBlockedSchema = accountDeletionPreviewSchema.omit({ email: true }).extend({ error: z.literal("account_deletion_blocked") });
231
376
  var paidPlans = ["starter", "pro", "business"];
232
377
  var billingPlans = ["oss", "free", ...paidPlans];
233
378
  var billingCatalogKeys = paidPlans.flatMap(
@@ -460,6 +605,50 @@ var emailBlockInputSchema = z.discriminatedUnion("blockType", [
460
605
  settings: z.object({ src: z.string().min(1) }).passthrough()
461
606
  }),
462
607
  blockBaseSchema.extend({ blockType: z.literal("separator") }),
608
+ blockBaseSchema.extend({
609
+ blockType: z.literal("spacer"),
610
+ settings: z.object({ height: pixelSchema.optional() }).passthrough()
611
+ }),
612
+ blockBaseSchema.extend({
613
+ blockType: z.literal("columns"),
614
+ settings: z.object({
615
+ left: z.string(),
616
+ right: z.string(),
617
+ ratio: z.enum(["11", "12", "21"]).optional(),
618
+ stack: z.boolean().optional()
619
+ }).passthrough()
620
+ }),
621
+ blockBaseSchema.extend({
622
+ blockType: z.literal("social"),
623
+ settings: z.object({
624
+ links: z.array(
625
+ z.object({
626
+ network: z.enum([
627
+ "website",
628
+ "instagram",
629
+ "linkedin",
630
+ "youtube",
631
+ "x",
632
+ "facebook",
633
+ "tiktok"
634
+ ]),
635
+ url: z.string().regex(/^(?:https?:\/\/\S+)?$/i, "Expected an http(s) URL")
636
+ })
637
+ )
638
+ }).passthrough()
639
+ }),
640
+ blockBaseSchema.extend({
641
+ blockType: z.literal("html"),
642
+ settings: z.object({ code: z.string() }).passthrough()
643
+ }),
644
+ blockBaseSchema.extend({
645
+ blockType: z.literal("conditional"),
646
+ settings: z.object({
647
+ tag: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9 _.-]{0,39}$/, "Expected a plain tag name"),
648
+ has: z.boolean().optional(),
649
+ content: z.string()
650
+ }).passthrough()
651
+ }),
463
652
  blockBaseSchema.extend({ blockType: z.literal("footer") })
464
653
  ]);
465
654
  var emailMetaInputSchema = z.object({
@@ -586,10 +775,204 @@ var sendingOptionSchema = z.discriminatedUnion("type", [
586
775
  countsAgainstQuota: z.literal(false)
587
776
  })
588
777
  ]);
778
+ var EVENT_NAME_MAX_LENGTH = 128;
779
+ var EVENT_PROPERTIES_MAX_BYTES = 32 * 1024;
780
+ var EVENT_PROPERTIES_MAX_KEYS = 100;
781
+ var EVENT_PROPERTIES_MAX_DEPTH = 3;
782
+ var EVENT_FILTER_MAX_CONDITIONS = 10;
783
+ var EVENT_MAX_FUTURE_MS = 24 * 60 * 60 * 1e3;
784
+ var eventPropertyKeyPattern = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
785
+ var controlCharacters = /[\u0000-\u001f\u007f]/;
786
+ var eventNameSchema = z.string().trim().min(1).max(EVENT_NAME_MAX_LENGTH).refine((name) => !controlCharacters.test(name), {
787
+ message: "Event names can't contain control characters"
788
+ }).refine((name) => !name.startsWith("$"), {
789
+ message: "Event names can't start with $"
790
+ });
791
+ function propertiesProblem(value, depth) {
792
+ if (Array.isArray(value)) {
793
+ for (const item of value) {
794
+ const problem = propertiesProblem(item, depth + 1);
795
+ if (problem)
796
+ return problem;
797
+ }
798
+ return null;
799
+ }
800
+ if (value && typeof value === "object") {
801
+ if (depth >= EVENT_PROPERTIES_MAX_DEPTH) {
802
+ return `Properties can be nested at most ${EVENT_PROPERTIES_MAX_DEPTH} levels`;
803
+ }
804
+ for (const [key, nested] of Object.entries(value)) {
805
+ if (!eventPropertyKeyPattern.test(key)) {
806
+ return `Property key "${key}" must start with a letter or _ and contain only letters, digits and _ (max 64)`;
807
+ }
808
+ const problem = propertiesProblem(nested, depth + 1);
809
+ if (problem)
810
+ return problem;
811
+ }
812
+ }
813
+ return null;
814
+ }
815
+ var eventPropertiesSchema = z.record(z.unknown()).superRefine((properties, ctx) => {
816
+ if (Object.keys(properties).length > EVENT_PROPERTIES_MAX_KEYS) {
817
+ ctx.addIssue({
818
+ code: z.ZodIssueCode.custom,
819
+ message: `At most ${EVENT_PROPERTIES_MAX_KEYS} top-level properties`
820
+ });
821
+ return;
822
+ }
823
+ const bytes = new TextEncoder().encode(JSON.stringify(properties)).length;
824
+ if (bytes > EVENT_PROPERTIES_MAX_BYTES) {
825
+ ctx.addIssue({
826
+ code: z.ZodIssueCode.custom,
827
+ message: `Properties can be at most ${EVENT_PROPERTIES_MAX_BYTES} bytes as JSON`
828
+ });
829
+ return;
830
+ }
831
+ const problem = propertiesProblem(properties, 0);
832
+ if (problem)
833
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: problem });
834
+ });
835
+ var trackEventFieldsSchema = z.object({
836
+ email: z.string().email().optional(),
837
+ contactId: z.string().min(1).optional(),
838
+ eventName: eventNameSchema,
839
+ properties: eventPropertiesSchema.optional(),
840
+ occurredAt: z.string().datetime({ offset: true }).optional().describe("When it happened. At most 24 h in the future; defaults to now."),
841
+ idempotencyKey: z.string().min(1).max(256).optional().describe("The same key within 30 days stores one event and enrolls once."),
842
+ backfill: z.boolean().optional().describe("Record only: the event never starts a sequence."),
843
+ createContact: z.boolean().optional().describe(
844
+ "Create the contact when the email is unknown (default true). Ignored with contactId."
845
+ ),
846
+ contact: z.object({
847
+ name: z.string().optional(),
848
+ customFields: customFieldsSchema.optional()
849
+ }).strict().optional().describe(
850
+ "Applied to the contact. Custom fields are merged into the existing ones."
851
+ )
852
+ }).strict();
853
+ var trackEventBodySchema = trackEventFieldsSchema.refine((body) => !!body.email !== !!body.contactId, {
854
+ message: "Provide exactly one of email or contactId"
855
+ }).refine(
856
+ (body) => !body.occurredAt || new Date(body.occurredAt).getTime() <= Date.now() + EVENT_MAX_FUTURE_MS,
857
+ { message: "occurredAt can be at most 24 hours in the future" }
858
+ );
859
+ var trackEventResponseSchema = z.object({
860
+ eventId: z.string(),
861
+ contactId: z.string(),
862
+ duplicate: z.boolean(),
863
+ contactCreated: z.boolean()
864
+ });
865
+ var eventSources = ["api", "session", "mcp"];
866
+ var contactEventSchema = z.object({
867
+ eventId: z.string(),
868
+ name: z.string(),
869
+ properties: z.record(z.unknown()),
870
+ occurredAt: z.string(),
871
+ receivedAt: z.string(),
872
+ source: z.enum(eventSources),
873
+ backfill: z.boolean(),
874
+ triggers: z.boolean(),
875
+ enrolledSequences: z.array(z.object({ sequenceId: z.string(), title: z.string() }))
876
+ });
877
+ var listContactEventsQuerySchema = z.object({
878
+ page: z.coerce.number().int().min(1).optional(),
879
+ limit: z.coerce.number().int().min(1).max(50).optional(),
880
+ name: eventNameSchema.optional()
881
+ });
882
+ var eventPropertyTypes = [
883
+ "string",
884
+ "number",
885
+ "boolean",
886
+ "date",
887
+ "object",
888
+ "array"
889
+ ];
890
+ var eventDefinitionPropertySchema = z.object({
891
+ key: z.string().regex(eventPropertyKeyPattern),
892
+ type: z.enum(eventPropertyTypes),
893
+ declared: z.boolean()
894
+ });
895
+ var eventDefinitionSchema = z.object({
896
+ name: z.string(),
897
+ origin: z.enum(["received", "manual"]),
898
+ description: z.string().nullable(),
899
+ properties: z.array(eventDefinitionPropertySchema),
900
+ firstSeenAt: z.string().nullable(),
901
+ lastSeenAt: z.string().nullable(),
902
+ createdAt: z.string(),
903
+ /** Non-deleted sequences whose trigger is this event. */
904
+ sequenceCount: z.number().int()
905
+ });
906
+ var eventDefinitionDetailSchema = eventDefinitionSchema.extend({
907
+ lastProperties: z.record(z.unknown()).nullable()
908
+ });
909
+ var declaredPropertiesSchema = z.array(
910
+ z.object({
911
+ key: z.string().regex(eventPropertyKeyPattern),
912
+ type: z.enum(eventPropertyTypes)
913
+ })
914
+ ).max(EVENT_PROPERTIES_MAX_KEYS).refine((props) => new Set(props.map((p) => p.key)).size === props.length, {
915
+ message: "Property keys must be unique"
916
+ });
917
+ var createEventDefinitionBodySchema = z.object({
918
+ name: eventNameSchema,
919
+ description: z.string().max(500).optional(),
920
+ properties: declaredPropertiesSchema.optional()
921
+ }).strict();
922
+ var updateEventDefinitionBodySchema = z.object({
923
+ description: z.string().max(500).nullable().optional(),
924
+ properties: declaredPropertiesSchema.optional().describe("Replaces the declared properties. Observed keys stay.")
925
+ }).strict();
926
+ var filterScalarSchema = z.union([z.string(), z.number(), z.boolean()]);
927
+ var eventFilterConditions = [
928
+ "is",
929
+ "is_not",
930
+ "contains",
931
+ "not_contains",
932
+ "gt",
933
+ "gte",
934
+ "lt",
935
+ "lte",
936
+ "exists",
937
+ "not_exists"
938
+ ];
939
+ var eventFilterKeySchema = z.string().refine(
940
+ (key) => {
941
+ const parts = key.split(".");
942
+ return parts.length <= EVENT_PROPERTIES_MAX_DEPTH && parts.every((part) => eventPropertyKeyPattern.test(part));
943
+ },
944
+ { message: "Use a property key, or a dot path up to 3 levels" }
945
+ );
946
+ var eventPropertyFilterSchema = z.object({
947
+ aggregator: z.enum(["and", "or"]),
948
+ filters: z.array(
949
+ z.object({
950
+ key: eventFilterKeySchema,
951
+ condition: z.enum(eventFilterConditions),
952
+ value: filterScalarSchema.optional()
953
+ }).refine(
954
+ (f) => f.condition === "exists" || f.condition === "not_exists" || f.value !== void 0,
955
+ { message: "This condition needs a value" }
956
+ )
957
+ ).min(1).max(EVENT_FILTER_MAX_CONDITIONS)
958
+ });
959
+ var propertyChangeFilterSchema = z.object({
960
+ from: filterScalarSchema.nullable().optional(),
961
+ to: filterScalarSchema.nullable().optional()
962
+ }).strict();
589
963
 
590
964
  // ../api-contract/src/schemas/sequences.ts
591
965
  var mailTypes = ["broadcast", "sequence"];
592
966
  var emailActionTypes = ["tag:add", "tag:remove"];
967
+ var triggerTypes = [
968
+ "subscriber:added",
969
+ "tag:added",
970
+ "tag:removed",
971
+ "date:occurred",
972
+ "event:custom",
973
+ "contact:property_changed"
974
+ ];
975
+ var reentryModes = ["every_time", "once", "once_per_period"];
593
976
  var sequenceEmailSchema = z.object({
594
977
  // NOTE: intentionally no `id`/`sequenceId` here — `sequence_emails.id` is
595
978
  // internal-only, and its `sequence_id` column holds the *parent*
@@ -608,6 +991,15 @@ var sequenceEmailSchema = z.object({
608
991
  /** Hosted content check: `clean`, `review` (held for SendLit's review),
609
992
  * `blocked`, or `approved` after review; `null` when not scanned. */
610
993
  contentScanVerdict: z.string().nullable().optional(),
994
+ /** Unpublished edits saved while the broadcast or sequence is active. `subject` and
995
+ * `content` above are the published version that sends use. */
996
+ draft: z.object({
997
+ subject: z.string(),
998
+ content: emailContentSchema,
999
+ updatedAt: z.string().nullable()
1000
+ }).nullable().optional(),
1001
+ /** Whether `draft` holds changes that aren't published yet. */
1002
+ hasUnpublishedChanges: z.boolean().optional(),
611
1003
  createdAt: z.string().nullable(),
612
1004
  updatedAt: z.string().nullable()
613
1005
  });
@@ -686,8 +1078,14 @@ var sequenceSchema = z.object({
686
1078
  title: z.string(),
687
1079
  status: z.string(),
688
1080
  deliverySource: deliverySourceSelectionSchema.nullable(),
689
- triggerType: z.string().nullable().optional(),
1081
+ triggerType: z.enum(triggerTypes).nullable().optional(),
690
1082
  triggerData: z.string().nullable().optional(),
1083
+ /** Property filter (`event:custom`) or from/to filter
1084
+ * (`contact:property_changed`). */
1085
+ triggerFilter: z.any().nullable().optional(),
1086
+ /** Who can enter again: sequences only. */
1087
+ reentry: z.enum(reentryModes).optional(),
1088
+ reentryPeriodDays: z.number().int().nullable().optional(),
691
1089
  filter: z.any().nullable().optional(),
692
1090
  excludeFilter: z.any().nullable().optional(),
693
1091
  /** Active enrollments for a sequence or its locked recipient count for a broadcast. */
@@ -695,9 +1093,16 @@ var sequenceSchema = z.object({
695
1093
  emailsOrder: z.array(z.string()),
696
1094
  entrants: z.array(z.string()),
697
1095
  report: z.any(),
1096
+ /** Whether sends link a hosted web version ("View in browser"). On for
1097
+ * new broadcasts, off for new sequences. */
1098
+ viewInBrowser: z.boolean(),
1099
+ /** When a sent broadcast was archived; `null` when it isn't. */
1100
+ archivedAt: z.string().nullable().optional(),
698
1101
  createdAt: z.string().nullable(),
699
1102
  updatedAt: z.string().nullable(),
700
1103
  emails: z.array(sequenceEmailSchema),
1104
+ /** Whether any of its emails has unpublished changes. */
1105
+ hasUnpublishedChanges: z.boolean().optional(),
701
1106
  /** Set while a running broadcast of a new hosted organization is sent
702
1107
  * gradually (`get` only). */
703
1108
  pacing: z.object({
@@ -708,8 +1113,12 @@ var sequenceSchema = z.object({
708
1113
  estimatedCompletionAt: z.string()
709
1114
  }).nullable().optional()
710
1115
  });
1116
+ var archivedFilters = ["exclude", "only", "include"];
711
1117
  var listSequencesQuerySchema = z.object({
712
1118
  type: z.enum(mailTypes),
1119
+ archived: z.enum(archivedFilters).optional().describe(
1120
+ "Archived broadcasts: exclude (default) hides them, only lists just them, include lists both"
1121
+ ),
713
1122
  offset: z.coerce.number().int().min(1).optional(),
714
1123
  itemsPerPage: z.coerce.number().int().min(1).max(50).optional()
715
1124
  });
@@ -720,8 +1129,19 @@ var createSequenceBodySchema = z.object({
720
1129
  });
721
1130
  var updateSequenceBodySchema = z.object({
722
1131
  title: z.string().optional(),
723
- triggerType: z.string().optional(),
724
- triggerData: z.string().optional(),
1132
+ triggerType: z.enum(triggerTypes).optional().describe(
1133
+ "Broadcasts use date:occurred. Sequences: subscriber:added, tag:added, tag:removed, event:custom or contact:property_changed."
1134
+ ),
1135
+ triggerData: z.string().optional().describe(
1136
+ "Tag name for tag triggers, event name for event:custom, custom field key for contact:property_changed."
1137
+ ),
1138
+ triggerFilter: z.union([eventPropertyFilterSchema, propertyChangeFilterSchema]).nullable().optional().describe(
1139
+ "event:custom: { aggregator, filters: [{ key, condition, value }] }. contact:property_changed: { from?, to? }. null clears it."
1140
+ ),
1141
+ reentry: z.enum(reentryModes).optional().describe(
1142
+ "Sequences only. every_time (default), once, or once_per_period with reentryPeriodDays."
1143
+ ),
1144
+ reentryPeriodDays: z.number().int().min(1).max(365).nullable().optional(),
725
1145
  filter: contactFilterSchema.optional().describe(
726
1146
  "Audience: subscribed contacts matching this filter; empty means everyone"
727
1147
  ),
@@ -730,7 +1150,10 @@ var updateSequenceBodySchema = z.object({
730
1150
  ),
731
1151
  emailsOrder: z.array(z.string()).optional(),
732
1152
  /** `null` clears the intent so the default is resolved on next start. */
733
- deliverySource: deliverySourceSelectionSchema.nullable().optional()
1153
+ deliverySource: deliverySourceSelectionSchema.nullable().optional(),
1154
+ viewInBrowser: z.boolean().optional().describe(
1155
+ 'Whether emails link a hosted web version ("View in browser"). `false` leaves the link out of later sends and takes down the web versions behind links already sent. Can be changed at any time.'
1156
+ )
734
1157
  });
735
1158
  var addSequenceEmailBodySchema = z.object({
736
1159
  templateId: z.string().min(1)
@@ -744,6 +1167,24 @@ var updateSequenceEmailBodySchema = z.object({
744
1167
  actionData: z.record(z.any()).optional(),
745
1168
  published: z.boolean().optional()
746
1169
  });
1170
+ var publishScopes = ["in_flight", "new_entrants"];
1171
+ var emailIdsSchema = z.array(z.string()).min(1).optional().describe("The emails to act on; omit for every email with unpublished changes");
1172
+ var publishSequenceChangesBodySchema = z.object({
1173
+ emailIds: emailIdsSchema,
1174
+ scope: z.enum(publishScopes).optional().describe(
1175
+ "Sequences only. in_flight (default): contacts already in the sequence get the new version at their next step. new_entrants: they keep the version they entered with; only contacts who enter from now on get the new one."
1176
+ )
1177
+ });
1178
+ var discardSequenceChangesBodySchema = z.object({
1179
+ emailIds: emailIdsSchema
1180
+ });
1181
+ var sequenceEmailVersionSchema = z.object({
1182
+ versionId: z.string(),
1183
+ subject: z.string(),
1184
+ content: emailContentSchema,
1185
+ publishedAt: z.string().describe("When this version last went live"),
1186
+ live: z.boolean().describe("Whether sends use this version now")
1187
+ });
747
1188
  var sendSequenceEmailTestBodySchema = z.object({
748
1189
  to: z.array(z.string().email()).max(5).optional().describe(
749
1190
  "Up to 5 addresses. Defaults to the signed-in user's address; API keys must set it."
@@ -752,7 +1193,10 @@ var sendSequenceEmailTestBodySchema = z.object({
752
1193
  var sequenceEmailTestResultSchema = z.object({
753
1194
  sent: z.array(z.string()).describe("Addresses the test was sent to"),
754
1195
  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()
1196
+ lastTestSentAt: z.string().nullable(),
1197
+ /** Event-triggered sequences: `last_event` when `{{ event.* }}` used the
1198
+ * last payload received for the event, `none` when there is none yet. */
1199
+ eventSample: z.enum(["last_event", "none"]).optional()
756
1200
  });
757
1201
  var sequenceStatsSchema = z.object({
758
1202
  sent: z.number(),
@@ -763,6 +1207,42 @@ var sequenceStatsSchema = z.object({
763
1207
  bounceRate: z.number().optional(),
764
1208
  complaintRate: z.number().optional()
765
1209
  });
1210
+ var sequenceScheduleSchema = z.object({
1211
+ waiting: z.number().describe("Contacts in the sequence who are waiting for their next email"),
1212
+ emails: z.array(
1213
+ z.object({
1214
+ emailId: z.string(),
1215
+ waiting: z.number().describe("Contacts whose next email is this one"),
1216
+ nextSendAt: z.number().nullable().describe(
1217
+ "The earliest due time among them (epoch millis), not a time they share: each contact's delay counts from their own entry. null when no one is waiting"
1218
+ )
1219
+ })
1220
+ )
1221
+ });
1222
+ var waitingContactSchema = z.object({
1223
+ contactId: z.string(),
1224
+ email: z.string(),
1225
+ name: z.string().nullable(),
1226
+ nextSendAt: z.number().describe("When this contact is due to get the email (epoch millis)")
1227
+ });
1228
+ var listWaitingContactsQuerySchema = z.object({
1229
+ after: z.string().optional().describe("The previous page's `nextCursor`; omit for the first page"),
1230
+ limit: z.coerce.number().int().min(1).max(100).optional(),
1231
+ q: z.string().optional().describe("Matches the contact's email or name")
1232
+ });
1233
+ var waitingContactsPageSchema = z.object({
1234
+ items: z.array(waitingContactSchema),
1235
+ total: z.number().describe("Every waiting contact that matches, across all pages"),
1236
+ nextCursor: z.string().nullable().describe("Pass as `after` for the next page; null on the last page")
1237
+ });
1238
+ var sequenceDeletionPreviewSchema = z.object({
1239
+ status: z.string().describe("The broadcast or sequence's current status"),
1240
+ blocker: z.enum(["sequence_active", "broadcast_sent"]).nullable().describe(
1241
+ "Why it can't be deleted right now (sequence_active: pause it first; broadcast_sent: archive the broadcast instead), or null when it can"
1242
+ ),
1243
+ enrolledCount: z.number().int().describe("Contacts currently in the sequence; deleting it stops their emails"),
1244
+ emailsSentCount: z.number().int().describe("Emails it has sent; their delivery, open and click history is deleted")
1245
+ });
766
1246
  var listSubscribersQuerySchema = z.object({
767
1247
  page: z.coerce.number().int().min(1).optional(),
768
1248
  limit: z.coerce.number().int().min(1).optional()
@@ -860,6 +1340,46 @@ var exportContactsQuerySchema = z.object({
860
1340
  segmentId: z.string().optional().describe("Only export this saved segment"),
861
1341
  filter: z.string().optional().describe("Serialized ContactFilterWithAggregator JSON; combines with segmentId")
862
1342
  });
1343
+ var contactSelectionObjectSchema = z.object({
1344
+ contactIds: z.array(z.string().min(1)).min(1).max(1e3).optional().describe("Contact IDs, up to 1000. Unknown IDs are ignored."),
1345
+ match: z.object({
1346
+ q: z.string().optional().describe("Search term matched against email or name"),
1347
+ segmentId: z.string().optional().describe("Only contacts in this saved segment"),
1348
+ filter: contactFilterSchema.optional().describe("Inline ContactFilterWithAggregator; combines with q and segmentId")
1349
+ }).optional().describe(
1350
+ "Every contact matching q, segmentId and filter (AND). `{}` selects every contact in the team."
1351
+ )
1352
+ });
1353
+ var exactlyOneSelection = (body) => Boolean(body.contactIds) !== Boolean(body.match);
1354
+ var exactlyOneSelectionMessage = {
1355
+ message: "Pass exactly one of contactIds or match"
1356
+ };
1357
+ var contactSelectionSchema = contactSelectionObjectSchema.refine(
1358
+ exactlyOneSelection,
1359
+ exactlyOneSelectionMessage
1360
+ );
1361
+ var previewContactDeletionResultSchema = z.object({
1362
+ count: z.number().int().describe("Contacts that would be deleted right now"),
1363
+ unsubscribed: z.number().int().describe(
1364
+ "How many of them are unsubscribed; their addresses are added to the suppression list"
1365
+ )
1366
+ });
1367
+ var deleteContactsObjectSchema = contactSelectionObjectSchema.extend({
1368
+ expectedCount: z.number().int().min(0).optional().describe(
1369
+ "The count from the preview. Required with match: if the live count differs, nothing is deleted and the response is 409 count_changed."
1370
+ )
1371
+ });
1372
+ var deleteContactsBodySchema = deleteContactsObjectSchema.refine(exactlyOneSelection, exactlyOneSelectionMessage).refine((body) => !body.match || body.expectedCount !== void 0, {
1373
+ message: "expectedCount is required with match",
1374
+ path: ["expectedCount"]
1375
+ });
1376
+ var contactDeletionSchema = z.object({
1377
+ deletionId: z.string().nullable().describe("Background job id for large deletions; null when it ran inline"),
1378
+ status: z.enum(["queued", "running", "completed", "failed"]),
1379
+ count: z.number().int().describe("Contacts selected for deletion"),
1380
+ deleted: z.number().int().describe("Contacts deleted so far"),
1381
+ suppressed: z.number().int().describe("Unsubscribed addresses newly added to the suppression list")
1382
+ });
863
1383
  var deliveryEventType = [
864
1384
  "accepted",
865
1385
  "delivered",
@@ -1079,6 +1599,14 @@ var testFeedbackConnectionResponseSchema = z.object({
1079
1599
  success: z.boolean(),
1080
1600
  error: z.string().optional()
1081
1601
  });
1602
+ var feedbackRequirementSchema = z.object({
1603
+ /** False on self-hosted SendLit, where the rule doesn't apply. */
1604
+ required: z.boolean(),
1605
+ /** Emails the organization can send before the rule applies. */
1606
+ requiredAfterSends: z.number().int(),
1607
+ /** Emails the organization has sent so far, across all its teams. */
1608
+ sentSoFar: z.number().int()
1609
+ });
1082
1610
  var signupFormSchema = z.object({
1083
1611
  formId: z.string(),
1084
1612
  name: z.string(),
@@ -1097,158 +1625,48 @@ var signupFormSenderErrorSchema = z.object({
1097
1625
  message: z.string()
1098
1626
  });
1099
1627
  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")
1106
- });
1107
- var updateSignupFormBodySchema = createSignupFormBodySchema.partial();
1108
- var mediaSchema = z.object({
1109
- mediaId: z.string(),
1110
- url: z.string(),
1111
- thumbnailUrl: z.string().nullable().optional(),
1112
- mediaLitId: z.string(),
1113
- fileName: z.string().nullable().optional(),
1114
- mimeType: z.string().nullable().optional(),
1115
- size: z.number().nullable().optional(),
1116
- width: z.number().nullable().optional(),
1117
- height: z.number().nullable().optional(),
1118
- alt: z.string().nullable().optional(),
1119
- caption: z.string().nullable().optional(),
1120
- createdAt: z.string().or(z.date()).nullable().optional(),
1121
- updatedAt: z.string().or(z.date()).nullable().optional()
1122
- });
1123
- var mediaReferenceSchema = z.object({
1124
- resourceType: z.enum(["TEMPLATE", "SEQUENCE_EMAIL"]),
1125
- resourcePublicId: z.string(),
1126
- parentResourcePublicId: z.string().nullable().optional(),
1127
- createdAt: z.string().or(z.date()).nullable().optional(),
1128
- updatedAt: z.string().or(z.date()).nullable().optional()
1129
- });
1130
- var listMediaQuerySchema = z.object({
1131
- page: z.coerce.number().int().min(1).optional(),
1132
- pageSize: z.coerce.number().int().min(1).max(100).optional(),
1133
- query: z.string().optional()
1134
- });
1135
- var updateMediaBodySchema = z.object({
1136
- alt: z.string().nullable().optional(),
1137
- caption: z.string().nullable().optional()
1138
- });
1139
- var mediaUploadSignatureSchema = z.object({
1140
- signature: z.string(),
1141
- endpoint: z.string()
1142
- });
1143
- var organizationRoleSchema = z.enum(["owner", "admin", "member"]);
1144
- var organizationSchema = z.object({
1145
- organizationId: z.string(),
1146
- name: z.string(),
1147
- status: z.enum(["pending_payment", "active", "suspended", "abandoned", "closed"]),
1148
- createdAt: z.string(),
1149
- updatedAt: z.string()
1150
- });
1151
- var organizationMemberSchema = z.object({
1152
- userId: z.string(),
1153
- email: z.string().email(),
1154
- name: z.string(),
1155
- image: z.string().nullable(),
1156
- role: organizationRoleSchema,
1157
- createdAt: z.string(),
1158
- updatedAt: z.string()
1159
- });
1160
- var createOrganizationBodySchema = z.object({
1161
- name: z.string().trim().min(1)
1162
- });
1163
- var updateOrganizationBodySchema = z.object({
1164
- name: z.string().trim().min(1)
1165
- });
1166
- var addOrganizationMemberBodySchema = z.object({
1167
- /** Existing Better Auth user only. This is a membership lookup, never an
1168
- * authentication or account-creation flow. */
1169
- email: z.string().trim().email(),
1170
- role: organizationRoleSchema
1171
- });
1172
- var updateOrganizationMemberBodySchema = z.object({
1173
- role: organizationRoleSchema
1174
- });
1175
- var organizationKeyScopes = [
1176
- "organization:read",
1177
- "delivery:read",
1178
- "delivery:manage",
1179
- "teams:provision",
1180
- "teams:read",
1181
- "teams:manage",
1182
- "teams:keys",
1183
- "esps:read",
1184
- "esps:manage",
1185
- "grants:manage",
1186
- "usage:read"
1187
- ];
1188
- var organizationApiKeySchema = z.object({
1189
- keyId: z.string(),
1190
- name: z.string(),
1191
- keyPrefix: z.string(),
1192
- scopes: z.array(z.enum(organizationKeyScopes)),
1193
- expiresAt: z.string().nullable(),
1194
- lastUsedAt: z.string().nullable(),
1195
- revokedAt: z.string().nullable(),
1196
- createdAt: z.string()
1197
- });
1198
- var createOrganizationApiKeyBodySchema = z.object({
1199
- name: z.string().trim().min(1),
1200
- scopes: z.array(z.enum(organizationKeyScopes)).min(1),
1201
- expiresAt: z.string().datetime().nullable().optional()
1202
- });
1203
- var createdOrganizationApiKeySchema = organizationApiKeySchema.extend({
1204
- key: z.string()
1205
- });
1206
- var organizationUsageWindowSchema = z.object({
1207
- limit: z.number().int().nullable(),
1208
- accepted: z.number().int().nonnegative(),
1209
- reserved: z.number().int().nonnegative(),
1210
- remaining: z.number().int().nullable(),
1211
- resetsAt: z.string()
1212
- });
1213
- var organizationUsageSchema = z.object({
1214
- day: organizationUsageWindowSchema,
1215
- month: organizationUsageWindowSchema
1216
- });
1217
- var organizationMailActivityQuerySchema = z.object({
1218
- rangeDays: z.coerce.number().int().refine((value) => [1, 3, 7, 30].includes(value)).optional()
1628
+ name: z.string().trim().min(1).max(200),
1629
+ tags: z.array(z.string().min(1)).max(20).optional().describe("Added to everyone who subscribes through the form"),
1630
+ doubleOptIn: z.boolean().optional().describe(
1631
+ "Send a confirmation email and subscribe only once it's clicked (default true)"
1632
+ ),
1633
+ 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")
1219
1634
  });
1220
- var organizationMailCountsSchema = z.object({
1221
- sent: z.number().int().nonnegative(),
1222
- queued: z.number().int().nonnegative(),
1223
- failed: z.number().int().nonnegative(),
1224
- bounced: z.number().int().nonnegative()
1635
+ var updateSignupFormBodySchema = createSignupFormBodySchema.partial();
1636
+ var mediaSchema = z.object({
1637
+ mediaId: z.string(),
1638
+ url: z.string(),
1639
+ thumbnailUrl: z.string().nullable().optional(),
1640
+ mediaLitId: z.string(),
1641
+ fileName: z.string().nullable().optional(),
1642
+ mimeType: z.string().nullable().optional(),
1643
+ size: z.number().nullable().optional(),
1644
+ width: z.number().nullable().optional(),
1645
+ height: z.number().nullable().optional(),
1646
+ alt: z.string().nullable().optional(),
1647
+ caption: z.string().nullable().optional(),
1648
+ createdAt: z.string().or(z.date()).nullable().optional(),
1649
+ updatedAt: z.string().or(z.date()).nullable().optional()
1225
1650
  });
1226
- var organizationMailActivityTeamSchema = z.object({
1227
- teamId: z.string(),
1228
- name: z.string(),
1229
- status: z.enum(["active", "sending_suspended", "archived"]),
1230
- externalId: z.string().nullable(),
1231
- mail: organizationMailCountsSchema
1651
+ var mediaReferenceSchema = z.object({
1652
+ resourceType: z.enum(["TEMPLATE", "SEQUENCE_EMAIL", "BROADCAST_WEB_PAGE"]),
1653
+ resourcePublicId: z.string(),
1654
+ parentResourcePublicId: z.string().nullable().optional(),
1655
+ createdAt: z.string().or(z.date()).nullable().optional(),
1656
+ updatedAt: z.string().or(z.date()).nullable().optional()
1232
1657
  });
1233
- var organizationMailActivitySchema = z.object({
1234
- rangeDays: z.union([z.literal(1), z.literal(3), z.literal(7), z.literal(30)]),
1235
- totals: organizationMailCountsSchema,
1236
- teams: z.array(organizationMailActivityTeamSchema)
1658
+ var listMediaQuerySchema = z.object({
1659
+ page: z.coerce.number().int().min(1).optional(),
1660
+ pageSize: z.coerce.number().int().min(1).max(100).optional(),
1661
+ query: z.string().optional()
1237
1662
  });
1238
- var organizationEnterTeamBodySchema = z.object({});
1239
- var organizationEnterTeamResponseSchema = z.object({
1240
- teamId: z.string(),
1241
- role: z.enum(["admin", "member"]),
1242
- created: z.boolean()
1663
+ var updateMediaBodySchema = z.object({
1664
+ alt: z.string().nullable().optional(),
1665
+ caption: z.string().nullable().optional()
1243
1666
  });
1244
- var organizationAuditEventSchema = z.object({
1245
- action: z.string(),
1246
- actorType: z.enum(["user", "organization_key", "team_key", "system"]),
1247
- teamId: z.string().nullable(),
1248
- espId: z.string().nullable(),
1249
- grantId: z.string().nullable(),
1250
- metadata: z.record(z.any()),
1251
- createdAt: z.string()
1667
+ var mediaUploadSignatureSchema = z.object({
1668
+ signature: z.string(),
1669
+ endpoint: z.string()
1252
1670
  });
1253
1671
  var overviewQuerySchema = z.object({
1254
1672
  /** Delivery activity window, in days. Defaults to the last 7 days. */
@@ -1412,6 +1830,47 @@ var createSuppressionBodySchema = z.object({
1412
1830
  "Why the address is blocked, e.g. a legal request; kept in the audit trail"
1413
1831
  )
1414
1832
  });
1833
+ var tagSummarySchema = z.object({
1834
+ tag: z.string(),
1835
+ contactCount: z.number().int()
1836
+ });
1837
+ var tagSequenceUsageSchema = z.enum([
1838
+ "filter",
1839
+ "exclude_filter",
1840
+ "trigger",
1841
+ "email_action"
1842
+ ]);
1843
+ var tagReferencesSchema = z.object({
1844
+ tag: z.string(),
1845
+ contactCount: z.number().int(),
1846
+ segments: z.array(z.object({ segmentId: z.string(), name: z.string() })),
1847
+ sequences: z.array(
1848
+ z.object({
1849
+ sequenceId: z.string(),
1850
+ title: z.string(),
1851
+ type: z.enum(["broadcast", "sequence"]),
1852
+ status: z.string(),
1853
+ usages: z.array(tagSequenceUsageSchema)
1854
+ })
1855
+ ),
1856
+ signupForms: z.array(z.object({ formId: z.string(), name: z.string() }))
1857
+ });
1858
+ var renameTagBodySchema = z.object({
1859
+ name: z.string().trim().min(1).describe("The tag's new name")
1860
+ });
1861
+ var renameTagResultSchema = z.object({
1862
+ tag: z.string(),
1863
+ previousTag: z.string(),
1864
+ contactsUpdated: z.number().int(),
1865
+ segmentsUpdated: z.number().int(),
1866
+ sequencesUpdated: z.number().int(),
1867
+ signupFormsUpdated: z.number().int()
1868
+ });
1869
+ var deleteTagResultSchema = z.object({
1870
+ tag: z.string(),
1871
+ contactsUpdated: z.number().int(),
1872
+ references: tagReferencesSchema
1873
+ });
1415
1874
  var teamSchema = z.object({
1416
1875
  teamId: z.string(),
1417
1876
  /** Public organization identifier. Present when an end user lists the
@@ -1665,7 +2124,7 @@ var webPublishingSchema = z.object({
1665
2124
  ogImage: z.string().nullable(),
1666
2125
  noindex: z.boolean(),
1667
2126
  canonicalUrl: z.string().nullable(),
1668
- /** Published and already sent, so the page is public. */
2127
+ /** Published, already sent and not archived, so the page is public. */
1669
2128
  live: z.boolean(),
1670
2129
  /** When the issue was sent; `null` until then. */
1671
2130
  publishedAt: z.string().nullable(),
@@ -1677,7 +2136,9 @@ var updateWebPublishingBodySchema = z.object({
1677
2136
  slug: webSlugSchema.optional().describe("URL slug; defaults to one made from the title"),
1678
2137
  seoTitle: z.string().trim().max(200).nullable().optional(),
1679
2138
  seoDescription: z.string().trim().max(500).nullable().optional(),
1680
- ogImage: httpUrl.nullable().optional().describe("Image for social previews"),
2139
+ ogImage: httpUrl.nullable().optional().describe(
2140
+ "Image for social previews. An image uploaded to MediaLit is added to the media library and can't be deleted while the page uses it"
2141
+ ),
1681
2142
  noindex: z.boolean().optional().describe("Ask search engines not to index the page"),
1682
2143
  canonicalUrl: httpUrl.nullable().optional().describe("Canonical URL, when a platform hosts the issue on its own site")
1683
2144
  });
@@ -1771,6 +2232,39 @@ var contactsContract = c.router(
1771
2232
  summary: "Export contacts as CSV",
1772
2233
  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."
1773
2234
  },
2235
+ previewBulkDelete: {
2236
+ method: "POST",
2237
+ path: "/contacts/bulk-delete/preview",
2238
+ body: contactSelectionSchema,
2239
+ responses: {
2240
+ 200: previewContactDeletionResultSchema,
2241
+ 400: errorSchema,
2242
+ 404: errorSchema
2243
+ },
2244
+ summary: "Preview a bulk contact deletion",
2245
+ description: "Counts the contacts a bulk delete would remove (and how many are unsubscribed) without deleting anything. Pass the count to bulkDelete as expectedCount. 404 when segmentId doesn't exist."
2246
+ },
2247
+ bulkDelete: {
2248
+ method: "POST",
2249
+ path: "/contacts/bulk-delete",
2250
+ body: deleteContactsBodySchema,
2251
+ responses: {
2252
+ 200: contactDeletionSchema,
2253
+ 202: contactDeletionSchema,
2254
+ 400: errorSchema,
2255
+ 404: errorSchema,
2256
+ 409: errorSchema.extend({ count: z.number().int().optional() })
2257
+ },
2258
+ summary: "Delete contacts in bulk",
2259
+ description: "Permanently deletes up to 1000 contacts by id, or every contact matching q, segmentId and filter. With match, pass the preview's count as expectedCount; if the live count differs nothing is deleted (409 count_changed, with the new count). Only contacts that existed when the request arrived are deleted. Up to 1000 contacts are deleted before the response (200, status completed); larger selections run in the background (202, status queued) and report progress at GET /contacts/bulk-delete/{deletionId}. Each contact's custom field values, sequence progress, events and delivery records are deleted with it, and no sequence triggers fire. Suppressions are kept, and the address of every deleted unsubscribed contact is added to the suppression list (reason manual), so re-importing or re-adding it never mails it again. This is not a full privacy erasure: delivery logs and the suppression list keep the address."
2260
+ },
2261
+ bulkDeleteStatus: {
2262
+ method: "GET",
2263
+ path: "/contacts/bulk-delete/:deletionId",
2264
+ responses: { 200: contactDeletionSchema, 404: errorSchema },
2265
+ summary: "Get a bulk contact deletion",
2266
+ description: "Progress of a background bulk delete. Finished deletions are kept for 24 hours."
2267
+ },
1774
2268
  get: {
1775
2269
  method: "GET",
1776
2270
  path: "/contacts/:contactId",
@@ -1811,6 +2305,14 @@ var contactsContract = c.router(
1811
2305
  },
1812
2306
  summary: "List broadcasts/sequence emails delivered to a contact"
1813
2307
  },
2308
+ events: {
2309
+ method: "GET",
2310
+ path: "/contacts/:contactId/events",
2311
+ query: listContactEventsQuerySchema,
2312
+ responses: { 200: paginated(contactEventSchema), 404: errorSchema },
2313
+ summary: "List the custom events received for a contact",
2314
+ description: "Newest first by occurredAt. `enrolledSequences` lists the sequences each event started."
2315
+ },
1814
2316
  remove: {
1815
2317
  method: "DELETE",
1816
2318
  path: "/contacts/:contactId",
@@ -1820,6 +2322,45 @@ var contactsContract = c.router(
1820
2322
  },
1821
2323
  { metadata: { tag: "Contacts" } }
1822
2324
  );
2325
+ var tagsContract = c.router(
2326
+ {
2327
+ list: {
2328
+ method: "GET",
2329
+ path: "/tags",
2330
+ responses: { 200: itemsList(tagSummarySchema) },
2331
+ summary: "List tags",
2332
+ description: "Returns every tag carried by at least one of the team's contacts, sorted by name, with the number of contacts that carry it."
2333
+ },
2334
+ references: {
2335
+ method: "GET",
2336
+ path: "/tags/:tag/references",
2337
+ responses: { 200: tagReferencesSchema },
2338
+ summary: "List where a tag is used",
2339
+ description: "Returns how many contacts carry the tag and the segments, broadcasts, sequences (audience filters, tag triggers, email tag actions) and signup forms that name it. Call it before deleting a tag."
2340
+ },
2341
+ rename: {
2342
+ method: "PATCH",
2343
+ path: "/tags/:tag",
2344
+ body: renameTagBodySchema,
2345
+ responses: {
2346
+ 200: renameTagResultSchema,
2347
+ 400: errorSchema,
2348
+ 404: errorSchema
2349
+ },
2350
+ summary: "Rename a tag",
2351
+ description: "Renames the tag on every contact, and in segments, broadcast and sequence filters and tag triggers, sequence email tag actions and signup forms. Renaming to a tag that already exists merges the two. Sent broadcasts keep their original filters. Renaming doesn't trigger tag-added or tag-removed sequences. 404 `tag_not_found` when nothing uses the tag; 400 `tag_unchanged` when the new name is the same."
2352
+ },
2353
+ remove: {
2354
+ method: "DELETE",
2355
+ path: "/tags/:tag",
2356
+ body: c.noBody(),
2357
+ responses: { 200: deleteTagResultSchema, 404: errorSchema },
2358
+ summary: "Delete a tag from every contact",
2359
+ description: "Removes the tag from every contact of the team. Segments, filters, triggers, email actions and signup forms that name the tag are left as they are and returned in `references`: a filter on a deleted tag matches nobody, and a trigger or form can add it again. Check `GET /tags/:tag/references` first. Deleting doesn't trigger tag-removed sequences. 404 `tag_not_found` when nothing uses the tag."
2360
+ }
2361
+ },
2362
+ { metadata: { tag: "Tags" } }
2363
+ );
1823
2364
  var segmentsContract = c.router(
1824
2365
  {
1825
2366
  create: {
@@ -1985,7 +2526,8 @@ var templatesContract = c.router(
1985
2526
  method: "DELETE",
1986
2527
  path: "/templates/:templateId",
1987
2528
  responses: { 204: c.noBody() },
1988
- summary: "Delete an email template"
2529
+ summary: "Delete an email template",
2530
+ description: "Permanently deletes the template. Its images that no other template or email uses are deleted from the media library and storage, unless a transactional email was sent with the template."
1989
2531
  }
1990
2532
  },
1991
2533
  { metadata: { tag: "Templates" } }
@@ -2009,7 +2551,8 @@ var sequencesContract = c.router(
2009
2551
  path: "/sequences",
2010
2552
  query: listSequencesQuerySchema,
2011
2553
  responses: { 200: paginated(sequenceSchema) },
2012
- summary: "List broadcasts or sequences"
2554
+ summary: "List broadcasts or sequences",
2555
+ description: "Archived broadcasts are left out unless `archived` is `only` or `include`."
2013
2556
  },
2014
2557
  get: {
2015
2558
  method: "GET",
@@ -2027,13 +2570,37 @@ var sequencesContract = c.router(
2027
2570
  404: errorSchema
2028
2571
  },
2029
2572
  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".`
2573
+ description: "A broadcast's title is its email's published subject. While it's scheduled, a new title is saved as the email's draft subject (see `draft`) and becomes the title when the changes are published. Once the broadcast has been sent, changing the title returns 400 with the error \"This broadcast has already been sent\". `viewInBrowser` can be changed at any time; turning it off also takes down the web versions linked from emails already sent."
2031
2574
  },
2032
2575
  remove: {
2033
2576
  method: "DELETE",
2034
2577
  path: "/sequences/:sequenceId",
2035
- responses: { 204: c.noBody(), 404: errorSchema },
2036
- summary: "Delete a broadcast or sequence"
2578
+ responses: { 204: c.noBody(), 404: errorSchema, 409: errorSchema },
2579
+ summary: "Delete a broadcast or sequence",
2580
+ description: "Permanently deletes the broadcast or sequence, its emails and triggers. An active sequence or a sending broadcast can't be deleted: pause it first (409 `sequence_active`). A draft or scheduled broadcast can be deleted; one that has started sending can't (409 `broadcast_sent`): archive it instead with POST /sequences/{sequenceId}/archive. Contacts still enrolled in a paused sequence leave it, and its delivery, open and click history is deleted too, so its stats are gone; check GET /sequences/{sequenceId}/deletion-preview first. The outbound message log and suppressions are kept. Images it uses that nothing else uses are deleted from the media library and storage; images used by sent mail are kept."
2581
+ },
2582
+ deletionPreview: {
2583
+ method: "GET",
2584
+ path: "/sequences/:sequenceId/deletion-preview",
2585
+ responses: { 200: sequenceDeletionPreviewSchema, 404: errorSchema },
2586
+ summary: "Preview what deleting a broadcast or sequence removes",
2587
+ description: "How many contacts are enrolled and how many emails it has sent, and whether it can be deleted right now. Nothing is changed."
2588
+ },
2589
+ archive: {
2590
+ method: "POST",
2591
+ path: "/sequences/:sequenceId/archive",
2592
+ body: c.noBody(),
2593
+ responses: { 200: sequenceSchema, 404: errorSchema, 409: errorSchema },
2594
+ summary: "Archive a sent broadcast",
2595
+ description: 'Hides a sent broadcast from the broadcasts list (see `archived` on GET /sequences) and from the public web archive, its feed and sitemap. Its report, delivery history and images are kept, and recipients\' "view in browser" links keep working. 409 `broadcast_not_sent` for a draft or scheduled broadcast (delete it instead) and `sequence_active` while it is sending. Archiving an archived broadcast changes nothing. 404 for sequences.'
2596
+ },
2597
+ unarchive: {
2598
+ method: "POST",
2599
+ path: "/sequences/:sequenceId/unarchive",
2600
+ body: c.noBody(),
2601
+ responses: { 200: sequenceSchema, 404: errorSchema },
2602
+ summary: "Restore an archived broadcast",
2603
+ description: "Puts an archived broadcast back in the broadcasts list, and back on the web archive when it is published there."
2037
2604
  },
2038
2605
  addEmail: {
2039
2606
  method: "POST",
@@ -2059,7 +2626,50 @@ var sequencesContract = c.router(
2059
2626
  422: templateNotMarketingErrorSchema
2060
2627
  },
2061
2628
  summary: "Update an email within a sequence",
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.`
2629
+ description: "When templateId is supplied, it must identify a marketing template; transactional templates return 422 template_not_marketing. While a broadcast or sequence is active (a running sequence or a scheduled broadcast), `subject` and `content` are saved as a draft (returned as the email's `draft`) and sends keep using the published version until the changes are published with POST /sequences/{sequenceId}/publish-changes. Otherwise nothing is sending, so they're saved directly, along with any open draft. Delay, published and tag action changes always apply right away. 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."
2630
+ },
2631
+ publishChanges: {
2632
+ method: "POST",
2633
+ path: "/sequences/:sequenceId/publish-changes",
2634
+ body: publishSequenceChangesBodySchema,
2635
+ responses: {
2636
+ 200: sequenceSchema,
2637
+ 400: errorSchema,
2638
+ 404: errorSchema,
2639
+ 409: errorSchema
2640
+ },
2641
+ summary: "Publish the unpublished changes of a broadcast or sequence",
2642
+ description: "Makes the drafts of the given emails (or all of them) the version that sends use. Emails without unpublished changes are left alone, so publishing twice changes nothing. For a sequence, `scope` says whether contacts already in it get the new version at their next step (`in_flight`, the default) or keep the version they entered with (`new_entrants`). Each published version is kept in the email's history (GET /sequences/{sequenceId}/emails/{emailId}/versions), including the one it replaces. On SendLit Cloud the content is checked first, as when a sequence starts. 404 `email_not_found` for an email the sequence doesn't have; 409 `mail_already_sent` for a broadcast that has started sending (its unpublished changes are dropped then); 409 `draft_changed` when the draft was edited during the publish (publish again)."
2643
+ },
2644
+ discardChanges: {
2645
+ method: "POST",
2646
+ path: "/sequences/:sequenceId/discard-changes",
2647
+ body: discardSequenceChangesBodySchema,
2648
+ responses: { 200: sequenceSchema, 404: errorSchema },
2649
+ summary: "Discard the unpublished changes of a broadcast or sequence",
2650
+ description: "Deletes the drafts of the given emails (or all of them), so they show the published version again. A broadcast's title goes back to its published subject. Sends are not affected."
2651
+ },
2652
+ emailVersions: {
2653
+ method: "GET",
2654
+ path: "/sequences/:sequenceId/emails/:emailId/versions",
2655
+ responses: {
2656
+ 200: itemsList(sequenceEmailVersionSchema),
2657
+ 404: errorSchema
2658
+ },
2659
+ summary: "List the published versions of a broadcast or sequence email",
2660
+ description: "The live version first, then the versions the email was published with before, newest first (at most 20). Restore one with POST /sequences/{sequenceId}/emails/{emailId}/versions/{versionId}/restore."
2661
+ },
2662
+ restoreEmailVersion: {
2663
+ method: "POST",
2664
+ path: "/sequences/:sequenceId/emails/:emailId/versions/:versionId/restore",
2665
+ body: c.noBody(),
2666
+ responses: {
2667
+ 200: sequenceSchema,
2668
+ 404: errorSchema,
2669
+ 409: errorSchema
2670
+ },
2671
+ summary: "Restore an earlier version of a broadcast or sequence email",
2672
+ description: "Loads a published version's subject and content into the email's draft; publish it to roll back. Unless the broadcast or sequence is active, it's restored directly. Restoring the live version discards the draft. A broadcast's title follows the restored subject once it's published. 404 `version_not_found` for a version that isn't one of this email's published versions; 409 `mail_already_sent` for a broadcast that has started sending."
2063
2673
  },
2064
2674
  sendEmailTest: {
2065
2675
  method: "POST",
@@ -2072,7 +2682,7 @@ var sequencesContract = c.router(
2072
2682
  429: errorSchema
2073
2683
  },
2074
2684
  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`)."
2685
+ 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. When the email has unpublished changes, the test sends the draft, so they can be checked before they're published. 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`)."
2076
2686
  },
2077
2687
  removeEmail: {
2078
2688
  method: "DELETE",
@@ -2082,7 +2692,8 @@ var sequencesContract = c.router(
2082
2692
  400: errorSchema,
2083
2693
  404: errorSchema
2084
2694
  },
2085
- summary: "Remove an email from a sequence"
2695
+ summary: "Remove an email from a sequence",
2696
+ description: "Removes the email. Images it uses that nothing else uses are deleted from the media library and storage; images used by sent mail are kept."
2086
2697
  },
2087
2698
  start: {
2088
2699
  method: "POST",
@@ -2128,6 +2739,25 @@ var sequencesContract = c.router(
2128
2739
  responses: { 200: sequenceStatsSchema, 404: errorSchema },
2129
2740
  summary: "Delivery / open-rate / click-through-rate stats for a sequence"
2130
2741
  },
2742
+ schedule: {
2743
+ method: "GET",
2744
+ path: "/sequences/:sequenceId/schedule",
2745
+ responses: { 200: sequenceScheduleSchema, 404: errorSchema },
2746
+ summary: "Contacts waiting for each email of a sequence",
2747
+ description: "For each email, in send order: how many contacts in the sequence will get it next and the earliest of their due times. A contact counts once, against the email they're waiting for, so emails they've had or will get later don't count them. Each contact's delay counts from their own entry, so their due times differ; list them with `GET /sequences/{sequenceId}/emails/{emailId}/waiting`. Due times are the earliest a contact can get the email; pauses and sending limits can make it later."
2748
+ },
2749
+ waitingContacts: {
2750
+ method: "GET",
2751
+ path: "/sequences/:sequenceId/emails/:emailId/waiting",
2752
+ query: listWaitingContactsQuerySchema,
2753
+ responses: {
2754
+ 200: waitingContactsPageSchema,
2755
+ 400: errorSchema,
2756
+ 404: errorSchema
2757
+ },
2758
+ summary: "Contacts waiting for a sequence email",
2759
+ description: "The contacts whose next email in the sequence is this one, soonest due first, each with their own due time. `q` matches email or name. Pages hold `limit` contacts (default 10, at most 100); pass `nextCursor` as `after` for the next page. `total` counts every match. A cursor that can't be read returns 400 `invalid_cursor`."
2760
+ },
2131
2761
  subscribers: {
2132
2762
  method: "GET",
2133
2763
  path: "/sequences/:sequenceId/subscribers",
@@ -2178,6 +2808,70 @@ var transactionalContract = c.router(
2178
2808
  },
2179
2809
  { metadata: { tag: "Transactional Emails" } }
2180
2810
  );
2811
+ var eventsContract = c.router(
2812
+ {
2813
+ track: {
2814
+ method: "POST",
2815
+ path: "/events",
2816
+ body: trackEventBodySchema,
2817
+ responses: {
2818
+ 202: trackEventResponseSchema,
2819
+ 400: errorSchema,
2820
+ 402: errorSchema,
2821
+ 404: errorSchema,
2822
+ 409: errorSchema,
2823
+ 422: errorSchema,
2824
+ 429: errorSchema
2825
+ },
2826
+ summary: "Track a custom event",
2827
+ description: "Stores the event, then starts every active sequence whose trigger is `event:custom` with this name and whose filters match. An unknown email creates the contact unless `createContact` is false (then 404). An unknown `contactId` is always 404. The same `idempotencyKey` within 30 days returns the original event with `duplicate: true`. Events with `backfill: true`, or an `occurredAt` more than 72 hours old, are stored but never start a sequence."
2828
+ },
2829
+ definitions: {
2830
+ method: "GET",
2831
+ path: "/events/definitions",
2832
+ responses: { 200: itemsList(eventDefinitionSchema) },
2833
+ summary: "List the team's events"
2834
+ },
2835
+ definition: {
2836
+ method: "GET",
2837
+ path: "/events/definitions/:name",
2838
+ responses: { 200: eventDefinitionDetailSchema, 404: errorSchema },
2839
+ summary: "Get an event, with its last payload"
2840
+ },
2841
+ createDefinition: {
2842
+ method: "POST",
2843
+ path: "/events/definitions",
2844
+ body: createEventDefinitionBodySchema,
2845
+ responses: {
2846
+ 201: eventDefinitionDetailSchema,
2847
+ 400: errorSchema,
2848
+ 409: errorSchema,
2849
+ 422: errorSchema
2850
+ },
2851
+ summary: "Register an event before it is sent"
2852
+ },
2853
+ updateDefinition: {
2854
+ method: "PATCH",
2855
+ path: "/events/definitions/:name",
2856
+ body: updateEventDefinitionBodySchema,
2857
+ responses: {
2858
+ 200: eventDefinitionDetailSchema,
2859
+ 400: errorSchema,
2860
+ 404: errorSchema
2861
+ },
2862
+ summary: "Update an event's description or declared properties"
2863
+ },
2864
+ deleteDefinition: {
2865
+ method: "DELETE",
2866
+ path: "/events/definitions/:name",
2867
+ body: c.noBody(),
2868
+ responses: { 204: c.noBody(), 404: errorSchema, 409: errorSchema },
2869
+ summary: "Remove an event from the list",
2870
+ description: "Stored events are kept, and a later event with this name registers it again. Returns 409 event_definition_in_use while a sequence uses it as its trigger."
2871
+ }
2872
+ },
2873
+ { metadata: { tag: "Events" } }
2874
+ );
2181
2875
  var espCollectionContract = c.router(
2182
2876
  {
2183
2877
  list: {
@@ -2226,7 +2920,7 @@ var espCollectionContract = c.router(
2226
2920
  409: errorSchema
2227
2921
  },
2228
2922
  summary: "Remove a user-managed ESP configuration",
2229
- description: "Removes an ESP with no active or queued dependencies. Draft, paused, and completed sequences are detached first."
2923
+ description: "Deletes an ESP that has never carried delivery history; delivery history is never deleted. Draft, paused, and completed sequences are detached first. 409 explains a blocked delete: `esp_is_default` (the team's live default; pick another default or retire it first), `delivery_source_in_use` (a sending sequence or broadcast, or queued email, needs it), or `esp_has_delivery_history` (transactional email, delivery feedback, or grants point at it; retire it instead)."
2230
2924
  },
2231
2925
  domainAuthentication: {
2232
2926
  method: "GET",
@@ -2621,7 +3315,7 @@ var organizationsContract = c.router(
2621
3315
  path: "/organizations",
2622
3316
  responses: {
2623
3317
  200: z.object({
2624
- items: z.array(organizationSchema),
3318
+ items: z.array(organizationListItemSchema),
2625
3319
  ownsFreeOrganization: z.boolean()
2626
3320
  }),
2627
3321
  403: errorSchema
@@ -2671,7 +3365,8 @@ var organizationsContract = c.router(
2671
3365
  409: errorSchema,
2672
3366
  503: errorSchema
2673
3367
  },
2674
- summary: "Close an organization"
3368
+ summary: "Delete an organization",
3369
+ description: "Owner only, from a dashboard session. Fails with `409 active_subscription_exists` while a subscription is active or paid through a future date (cancel it in billing first), and with `409 billing_checkout_pending` while a checkout is open. Deleting closes the organization, archives its teams, revokes organization and team API keys and sending domains, retires every ESP config with its credentials wiped, and deletes its teams' MediaLit files. Billing history, audit events, delivery reporting and suppressions are kept."
2675
3370
  },
2676
3371
  abandon: {
2677
3372
  method: "POST",
@@ -2919,7 +3614,8 @@ var organizationsContract = c.router(
2919
3614
  404: errorSchema,
2920
3615
  409: errorSchema
2921
3616
  },
2922
- summary: "Delete an eligible never-activated organization ESP"
3617
+ summary: "Delete an eligible never-activated organization ESP",
3618
+ description: "Only a never-activated draft with no history is deleted. 409 explains a blocked delete: `esp_retire_instead` (it has been activated; retire it instead), `esp_has_delivery_history`, or `delivery_source_in_use`."
2923
3619
  },
2924
3620
  getEspFeedback: {
2925
3621
  method: "GET",
@@ -3169,6 +3865,13 @@ var overviewContract = c.router(
3169
3865
  );
3170
3866
  var feedbackContract = c.router(
3171
3867
  {
3868
+ requirement: {
3869
+ method: "GET",
3870
+ path: "/settings/feedback-requirement",
3871
+ responses: { 200: feedbackRequirementSchema },
3872
+ summary: "Get when ESPs need a delivery-feedback connection",
3873
+ description: "On SendLit Cloud, once the organization has sent `requiredAfterSends` emails, SendLit only sends through ESPs with a healthy bounce/complaint feedback connection. `required` is false on self-hosted SendLit."
3874
+ },
3172
3875
  get: {
3173
3876
  method: "GET",
3174
3877
  path: "/settings/esps/:espId/feedback",
@@ -3473,13 +4176,56 @@ var billingContract = c.router(
3473
4176
  },
3474
4177
  { metadata: { tag: "Billing" } }
3475
4178
  );
4179
+ var accountContract = c.router({
4180
+ getDeletion: {
4181
+ method: "GET",
4182
+ path: "/account/deletion",
4183
+ responses: {
4184
+ 200: accountDeletionPreviewSchema,
4185
+ 401: errorSchema,
4186
+ 403: errorSchema
4187
+ },
4188
+ summary: "Preview deleting your account",
4189
+ description: "Dashboard session only. Lists every organization you belong to and what deleting your account does to it: `delete` when you are its last owner (it is deleted and its contacts' personal data erased), `leave` otherwise. `blocker` says what has to happen first: `active_subscription_exists` or `billing_checkout_pending` (cancel billing), `last_organization_owner` (other people are members: make one of them an owner or remove them), `billing_manager_required` (you pay for a running subscription of an organization you would leave)."
4190
+ },
4191
+ sendDeletionCode: {
4192
+ method: "POST",
4193
+ path: "/account/deletion/code",
4194
+ body: c.noBody(),
4195
+ responses: {
4196
+ 204: c.noBody(),
4197
+ 401: errorSchema,
4198
+ 403: errorSchema,
4199
+ 429: errorSchema
4200
+ },
4201
+ summary: "Email a code to confirm deleting your account",
4202
+ description: "Dashboard session only. Sends a one-time code, valid for 5 minutes, to the account's email. `POST /account/deletion` needs it."
4203
+ },
4204
+ delete: {
4205
+ method: "POST",
4206
+ path: "/account/deletion",
4207
+ body: deleteAccountBodySchema,
4208
+ responses: {
4209
+ 204: c.noBody(),
4210
+ 400: errorSchema,
4211
+ 401: errorSchema,
4212
+ 403: errorSchema,
4213
+ 409: accountDeletionBlockedSchema
4214
+ },
4215
+ summary: "Delete your account",
4216
+ description: "Dashboard session only, with the account's email typed to confirm and the code from `POST /account/deletion/code` (`400 email_mismatch`, `400 invalid_code`). Fails with `409 account_deletion_blocked`, listing the blocking organizations, while any blocker from `GET /account/deletion` remains; nothing changes then. Otherwise every organization you are the last owner of is deleted like `DELETE /organizations/:organizationId` and its contacts, signup confirmations, recipient addresses and raw webhook payloads are erased (suppression hashes stay); you leave every other organization and team; your sessions, sign-in methods, OAuth tokens and consents end; and your name and email are erased. Billing records and audit events keep an anonymous id. Signing in again with the same email creates a new, empty account."
4217
+ }
4218
+ });
3476
4219
  var contract = c.router({
4220
+ account: accountContract,
3477
4221
  contacts: contactsContract,
3478
4222
  segments: segmentsContract,
4223
+ tags: tagsContract,
3479
4224
  media: mediaContract,
3480
4225
  templates: templatesContract,
3481
4226
  sequences: sequencesContract,
3482
4227
  transactional: transactionalContract,
4228
+ events: eventsContract,
3483
4229
  settings: settingsContract,
3484
4230
  teams: teamsContract,
3485
4231
  organizations: organizationsContract,
@@ -3578,6 +4324,14 @@ var Contacts = class {
3578
4324
  params: { contactId: assertId(contactId, "contactId") }
3579
4325
  });
3580
4326
  }
4327
+ /** Custom events received for this contact, newest first, with the
4328
+ * sequences each one started. */
4329
+ async events(contactId, query = {}) {
4330
+ return this.http.request(routes.events, {
4331
+ params: { contactId: assertId(contactId, "contactId") },
4332
+ query
4333
+ });
4334
+ }
3581
4335
  };
3582
4336
 
3583
4337
  // src/resources/delivery-events.ts
@@ -3629,8 +4383,67 @@ var Emails = class {
3629
4383
  }
3630
4384
  };
3631
4385
 
4386
+ // src/resources/events.ts
4387
+ var routes4 = contract.events;
4388
+ var EventDefinitions = class {
4389
+ constructor(http) {
4390
+ this.http = http;
4391
+ }
4392
+ async list() {
4393
+ return this.http.request(routes4.definitions);
4394
+ }
4395
+ /** One event with its last received payload. Names are case-sensitive. */
4396
+ async get(name) {
4397
+ return this.http.request(routes4.definition, {
4398
+ params: { name: encodeSegment(name, "name") }
4399
+ });
4400
+ }
4401
+ async create(input) {
4402
+ return this.http.request(routes4.createDefinition, { body: input });
4403
+ }
4404
+ /** `properties` replaces the declared set; observed keys stay. */
4405
+ async update(name, input) {
4406
+ return this.http.request(routes4.updateDefinition, {
4407
+ params: { name: encodeSegment(name, "name") },
4408
+ body: input
4409
+ });
4410
+ }
4411
+ /** Removes the event from the list. Stored events are kept, and the API
4412
+ * refuses (409 `event_definition_in_use`) while a sequence uses it. */
4413
+ async delete(name) {
4414
+ await this.http.request(routes4.deleteDefinition, {
4415
+ params: { name: encodeSegment(name, "name") }
4416
+ });
4417
+ }
4418
+ };
4419
+ var Events = class {
4420
+ constructor(http) {
4421
+ this.http = http;
4422
+ this.definitions = new EventDefinitions(http);
4423
+ }
4424
+ /**
4425
+ * Records an event for one contact (by `email` or `contactId`) and starts
4426
+ * every active sequence listening for `eventName`.
4427
+ *
4428
+ * - An unknown `email` creates the contact, since `createContact`
4429
+ * defaults to `true`. Pass `false` to get a 404 instead. An unknown
4430
+ * `contactId` is always a 404.
4431
+ * - The same `idempotencyKey` within 30 days stores one event and
4432
+ * returns the original with `duplicate: true`. With a key, the SDK
4433
+ * also retries the call on 5xx and network errors.
4434
+ * - `backfill: true` stores history without starting sequences. Events
4435
+ * whose `occurredAt` is more than 72 hours old never start one either.
4436
+ */
4437
+ async track(input) {
4438
+ return this.http.request(routes4.track, {
4439
+ body: input,
4440
+ retrySafe: !!input.idempotencyKey
4441
+ });
4442
+ }
4443
+ };
4444
+
3632
4445
  // src/resources/provisioning.ts
3633
- var routes4 = contract.provisioning;
4446
+ var routes5 = contract.provisioning;
3634
4447
  var Provisioning = class {
3635
4448
  constructor(http) {
3636
4449
  this.http = http;
@@ -3641,20 +4454,20 @@ var Provisioning = class {
3641
4454
  * `created: false, apiKey: null`, so it's safe to retry.
3642
4455
  */
3643
4456
  async provisionTeam(input) {
3644
- return this.http.request(routes4.provisionTeam, {
4457
+ return this.http.request(routes5.provisionTeam, {
3645
4458
  body: input,
3646
4459
  retrySafe: true
3647
4460
  });
3648
4461
  }
3649
4462
  /** `teams:read` */
3650
4463
  async getTeam(teamId) {
3651
- return this.http.request(routes4.getTeam, {
4464
+ return this.http.request(routes5.getTeam, {
3652
4465
  params: { teamId: assertId(teamId, "teamId") }
3653
4466
  });
3654
4467
  }
3655
4468
  /** `teams:manage` */
3656
4469
  async updateTeam(teamId, input) {
3657
- return this.http.request(routes4.updateTeam, {
4470
+ return this.http.request(routes5.updateTeam, {
3658
4471
  params: { teamId: assertId(teamId, "teamId") },
3659
4472
  body: input
3660
4473
  });
@@ -3662,106 +4475,106 @@ var Provisioning = class {
3662
4475
  /** Replaces the team's integration key (`teams:keys`); keys previously
3663
4476
  * issued through provisioning are revoked. */
3664
4477
  async createTeamKey(teamId, input) {
3665
- return this.http.request(routes4.createTeamKey, {
4478
+ return this.http.request(routes5.createTeamKey, {
3666
4479
  params: { teamId: assertId(teamId, "teamId") },
3667
4480
  body: input
3668
4481
  });
3669
4482
  }
3670
4483
  /** `teams:manage` */
3671
4484
  async suspendTeam(teamId) {
3672
- return this.http.request(routes4.suspendTeam, {
4485
+ return this.http.request(routes5.suspendTeam, {
3673
4486
  params: { teamId: assertId(teamId, "teamId") }
3674
4487
  });
3675
4488
  }
3676
4489
  /** `teams:manage` */
3677
4490
  async resumeTeam(teamId) {
3678
- return this.http.request(routes4.resumeTeam, {
4491
+ return this.http.request(routes5.resumeTeam, {
3679
4492
  params: { teamId: assertId(teamId, "teamId") }
3680
4493
  });
3681
4494
  }
3682
4495
  /** Soft-deprovisions the team (`teams:manage`). There is no unarchive. */
3683
4496
  async archiveTeam(teamId) {
3684
- await this.http.request(routes4.archiveTeam, {
4497
+ await this.http.request(routes5.archiveTeam, {
3685
4498
  params: { teamId: assertId(teamId, "teamId") }
3686
4499
  });
3687
4500
  }
3688
4501
  /** `usage:read` */
3689
4502
  async getTeamUsage(teamId) {
3690
- return this.http.request(routes4.getTeamUsage, {
4503
+ return this.http.request(routes5.getTeamUsage, {
3691
4504
  params: { teamId: assertId(teamId, "teamId") }
3692
4505
  });
3693
4506
  }
3694
4507
  };
3695
4508
 
3696
4509
  // src/resources/segments.ts
3697
- var routes5 = contract.segments;
4510
+ var routes6 = contract.segments;
3698
4511
  var Segments = class {
3699
4512
  constructor(http) {
3700
4513
  this.http = http;
3701
4514
  }
3702
4515
  async create(input) {
3703
- return this.http.request(routes5.create, { body: input });
4516
+ return this.http.request(routes6.create, { body: input });
3704
4517
  }
3705
4518
  async list() {
3706
- return this.http.request(routes5.list);
4519
+ return this.http.request(routes6.list);
3707
4520
  }
3708
4521
  async get(segmentId) {
3709
- return this.http.request(routes5.get, {
4522
+ return this.http.request(routes6.get, {
3710
4523
  params: { segmentId: assertId(segmentId, "segmentId") }
3711
4524
  });
3712
4525
  }
3713
4526
  async update(segmentId, input) {
3714
- return this.http.request(routes5.update, {
4527
+ return this.http.request(routes6.update, {
3715
4528
  params: { segmentId: assertId(segmentId, "segmentId") },
3716
4529
  body: input
3717
4530
  });
3718
4531
  }
3719
4532
  async remove(segmentId) {
3720
- await this.http.request(routes5.remove, {
4533
+ await this.http.request(routes6.remove, {
3721
4534
  params: { segmentId: assertId(segmentId, "segmentId") }
3722
4535
  });
3723
4536
  }
3724
4537
  };
3725
4538
 
3726
4539
  // src/resources/sequences.ts
3727
- var routes6 = contract.sequences;
4540
+ var routes7 = contract.sequences;
3728
4541
  var Sequences = class {
3729
4542
  constructor(http) {
3730
4543
  this.http = http;
3731
4544
  }
3732
4545
  async create(input) {
3733
- return this.http.request(routes6.create, { body: input });
4546
+ return this.http.request(routes7.create, { body: input });
3734
4547
  }
3735
4548
  async list(query) {
3736
- return this.http.request(routes6.list, { query });
4549
+ return this.http.request(routes7.list, { query });
3737
4550
  }
3738
4551
  listAll(query) {
3739
4552
  return paginate((offset) => this.list({ ...query, offset }));
3740
4553
  }
3741
4554
  async get(sequenceId) {
3742
- return this.http.request(routes6.get, {
4555
+ return this.http.request(routes7.get, {
3743
4556
  params: { sequenceId: assertId(sequenceId, "sequenceId") }
3744
4557
  });
3745
4558
  }
3746
4559
  async update(sequenceId, input) {
3747
- return this.http.request(routes6.update, {
4560
+ return this.http.request(routes7.update, {
3748
4561
  params: { sequenceId: assertId(sequenceId, "sequenceId") },
3749
4562
  body: input
3750
4563
  });
3751
4564
  }
3752
4565
  async remove(sequenceId) {
3753
- await this.http.request(routes6.remove, {
4566
+ await this.http.request(routes7.remove, {
3754
4567
  params: { sequenceId: assertId(sequenceId, "sequenceId") }
3755
4568
  });
3756
4569
  }
3757
4570
  async addEmail(sequenceId, input) {
3758
- return this.http.request(routes6.addEmail, {
4571
+ return this.http.request(routes7.addEmail, {
3759
4572
  params: { sequenceId: assertId(sequenceId, "sequenceId") },
3760
4573
  body: input
3761
4574
  });
3762
4575
  }
3763
4576
  async updateEmail(sequenceId, emailId, input) {
3764
- return this.http.request(routes6.updateEmail, {
4577
+ return this.http.request(routes7.updateEmail, {
3765
4578
  params: {
3766
4579
  sequenceId: assertId(sequenceId, "sequenceId"),
3767
4580
  emailId: assertId(emailId, "emailId")
@@ -3769,8 +4582,45 @@ var Sequences = class {
3769
4582
  body: input
3770
4583
  });
3771
4584
  }
4585
+ /** Publishes unpublished email changes (drafts) of a broadcast or
4586
+ * sequence, so sends use them. While it's active, `updateEmail` saves
4587
+ * subject and content changes as a draft. */
4588
+ async publishChanges(sequenceId, input = {}) {
4589
+ return this.http.request(routes7.publishChanges, {
4590
+ params: { sequenceId: assertId(sequenceId, "sequenceId") },
4591
+ body: input
4592
+ });
4593
+ }
4594
+ /** Throws away unpublished email changes. Sends are not affected. */
4595
+ async discardChanges(sequenceId, input = {}) {
4596
+ return this.http.request(routes7.discardChanges, {
4597
+ params: { sequenceId: assertId(sequenceId, "sequenceId") },
4598
+ body: input
4599
+ });
4600
+ }
4601
+ /** The versions an email has been published with, live one first. */
4602
+ async emailVersions(sequenceId, emailId) {
4603
+ const { items } = await this.http.request(routes7.emailVersions, {
4604
+ params: {
4605
+ sequenceId: assertId(sequenceId, "sequenceId"),
4606
+ emailId: assertId(emailId, "emailId")
4607
+ }
4608
+ });
4609
+ return items;
4610
+ }
4611
+ /** Loads an earlier published version into the email's draft; publish
4612
+ * it with `publishChanges` to roll back. */
4613
+ async restoreEmailVersion(sequenceId, emailId, versionId) {
4614
+ return this.http.request(routes7.restoreEmailVersion, {
4615
+ params: {
4616
+ sequenceId: assertId(sequenceId, "sequenceId"),
4617
+ emailId: assertId(emailId, "emailId"),
4618
+ versionId: assertId(versionId, "versionId")
4619
+ }
4620
+ });
4621
+ }
3772
4622
  async removeEmail(sequenceId, emailId) {
3773
- return this.http.request(routes6.removeEmail, {
4623
+ return this.http.request(routes7.removeEmail, {
3774
4624
  params: {
3775
4625
  sequenceId: assertId(sequenceId, "sequenceId"),
3776
4626
  emailId: assertId(emailId, "emailId")
@@ -3780,23 +4630,23 @@ var Sequences = class {
3780
4630
  /** Sends a broadcast, or activates a sequence so its trigger starts
3781
4631
  * enrolling contacts. Requires a mailing address in general settings. */
3782
4632
  async start(sequenceId) {
3783
- return this.http.request(routes6.start, {
4633
+ return this.http.request(routes7.start, {
3784
4634
  params: { sequenceId: assertId(sequenceId, "sequenceId") }
3785
4635
  });
3786
4636
  }
3787
4637
  async pause(sequenceId) {
3788
- return this.http.request(routes6.pause, {
4638
+ return this.http.request(routes7.pause, {
3789
4639
  params: { sequenceId: assertId(sequenceId, "sequenceId") }
3790
4640
  });
3791
4641
  }
3792
4642
  async stats(sequenceId) {
3793
- return this.http.request(routes6.stats, {
4643
+ return this.http.request(routes7.stats, {
3794
4644
  params: { sequenceId: assertId(sequenceId, "sequenceId") }
3795
4645
  });
3796
4646
  }
3797
4647
  /** IDs of contacts that have received this broadcast or sequence. */
3798
4648
  async subscribers(sequenceId, query = {}) {
3799
- return this.http.request(routes6.subscribers, {
4649
+ return this.http.request(routes7.subscribers, {
3800
4650
  params: { sequenceId: assertId(sequenceId, "sequenceId") },
3801
4651
  query
3802
4652
  });
@@ -3804,26 +4654,26 @@ var Sequences = class {
3804
4654
  };
3805
4655
 
3806
4656
  // src/resources/suppressions.ts
3807
- var routes7 = contract.suppressions;
4657
+ var routes8 = contract.suppressions;
3808
4658
  var Suppressions = class {
3809
4659
  constructor(http) {
3810
4660
  this.http = http;
3811
4661
  }
3812
4662
  async list(query = {}) {
3813
- return this.http.request(routes7.list, { query });
4663
+ return this.http.request(routes8.list, { query });
3814
4664
  }
3815
4665
  listAll(query = {}) {
3816
4666
  return paginate((offset) => this.list({ ...query, offset }));
3817
4667
  }
3818
4668
  async get(suppressionId) {
3819
- return this.http.request(routes7.get, {
4669
+ return this.http.request(routes8.get, {
3820
4670
  params: { suppressionId: assertId(suppressionId, "suppressionId") }
3821
4671
  });
3822
4672
  }
3823
4673
  /** Complaint suppressions can't be released (409
3824
4674
  * `suppression_not_releasable`). */
3825
4675
  async release(suppressionId, input = {}) {
3826
- return this.http.request(routes7.release, {
4676
+ return this.http.request(routes8.release, {
3827
4677
  params: { suppressionId: assertId(suppressionId, "suppressionId") },
3828
4678
  body: input
3829
4679
  });
@@ -3831,41 +4681,41 @@ var Suppressions = class {
3831
4681
  };
3832
4682
 
3833
4683
  // src/resources/templates.ts
3834
- var routes8 = contract.templates;
4684
+ var routes9 = contract.templates;
3835
4685
  var Templates = class {
3836
4686
  constructor(http) {
3837
4687
  this.http = http;
3838
4688
  }
3839
4689
  async list(query = {}) {
3840
- return this.http.request(routes8.list, { query });
4690
+ return this.http.request(routes9.list, { query });
3841
4691
  }
3842
4692
  /** Built-in starters, shared by every team. Duplicate one into the team
3843
4693
  * before using it for transactional sends. */
3844
4694
  async listSystem(query = {}) {
3845
- return this.http.request(routes8.listSystem, { query });
4695
+ return this.http.request(routes9.listSystem, { query });
3846
4696
  }
3847
4697
  async get(templateId) {
3848
- return this.http.request(routes8.get, {
4698
+ return this.http.request(routes9.get, {
3849
4699
  params: { templateId: assertId(templateId, "templateId") }
3850
4700
  });
3851
4701
  }
3852
4702
  async create(input) {
3853
- return this.http.request(routes8.create, { body: input });
4703
+ return this.http.request(routes9.create, { body: input });
3854
4704
  }
3855
4705
  async update(templateId, input) {
3856
- return this.http.request(routes8.update, {
4706
+ return this.http.request(routes9.update, {
3857
4707
  params: { templateId: assertId(templateId, "templateId") },
3858
4708
  body: input
3859
4709
  });
3860
4710
  }
3861
4711
  async duplicate(templateId, input = {}) {
3862
- return this.http.request(routes8.duplicate, {
4712
+ return this.http.request(routes9.duplicate, {
3863
4713
  params: { templateId: assertId(templateId, "templateId") },
3864
4714
  body: input
3865
4715
  });
3866
4716
  }
3867
4717
  async remove(templateId) {
3868
- await this.http.request(routes8.remove, {
4718
+ await this.http.request(routes9.remove, {
3869
4719
  params: { templateId: assertId(templateId, "templateId") }
3870
4720
  });
3871
4721
  }
@@ -3929,10 +4779,11 @@ var SendLit = class {
3929
4779
  this.templates = new Templates(http);
3930
4780
  this.sequences = new Sequences(http);
3931
4781
  this.emails = new Emails(http);
4782
+ this.events = new Events(http);
3932
4783
  this.provisioning = new Provisioning(http);
3933
4784
  this.suppressions = new Suppressions(http);
3934
4785
  this.deliveryEvents = new DeliveryEvents(http);
3935
4786
  }
3936
4787
  };
3937
4788
 
3938
- export { Contacts, DEFAULT_ENDPOINT, DeliveryEvents, Emails, Provisioning, Segments, SendLit, SendLitError, Sequences, Suppressions, Templates };
4789
+ export { Contacts, DEFAULT_ENDPOINT, DeliveryEvents, Emails, EventDefinitions, Events, Provisioning, Segments, SendLit, SendLitError, Sequences, Suppressions, Templates };