sendlit 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -167,17 +167,28 @@ headers("created_at", [
167
167
  "created",
168
168
  "created_date",
169
169
  "date_added",
170
- "subscribed_at",
171
- "subscribe_date",
172
- "subscription_date",
173
170
  "signup_date",
174
171
  "sign_up_date",
172
+ "joined_at"
173
+ ]);
174
+ headers("opted_in_at", [
175
+ "opted_in_at",
175
176
  "optin_time",
177
+ "opt_in_time",
178
+ "opt_in_date",
176
179
  "confirm_time",
177
- "joined_at"
180
+ "subscribed_at",
181
+ "subscribe_date",
182
+ "subscription_date",
183
+ "consent_date"
178
184
  ]);
179
185
  headers("tag_from_value", ["tier", "plan", "subscription_tier"]);
180
- headers("ignore", ["suppression_reason"]);
186
+ headers("ignore", [
187
+ "suppression_reason",
188
+ "consent_channel",
189
+ "consent_source",
190
+ "consent_wording"
191
+ ]);
181
192
  function statuses(result, values) {
182
193
  for (const value of values)
183
194
  result;
@@ -832,6 +843,81 @@ function paginated(item) {
832
843
  function itemsList(item) {
833
844
  return zod.z.object({ items: zod.z.array(item) });
834
845
  }
846
+ var consentActions = ["opt_in", "opt_out", "suppressed"];
847
+ var consentChannels = [
848
+ /** A signup form: the hosted page, an embedded form, or `forms.submit`. */
849
+ "form",
850
+ /** A contact import (CSV in the dashboard, or `contacts.import`). */
851
+ "import",
852
+ /** The REST API with an API key or OAuth token. */
853
+ "api",
854
+ /** An MCP tool. */
855
+ "mcp",
856
+ /** A team member in the SendLit dashboard. */
857
+ "dashboard",
858
+ /** The unsubscribe link in an email. */
859
+ "unsubscribe_link",
860
+ /** A mailbox provider's one-click unsubscribe (RFC 8058 List-Unsubscribe). */
861
+ "list_unsubscribe",
862
+ /** A suppression: hard bounce, spam complaint, provider or manual. */
863
+ "suppression",
864
+ /** The contact existed before SendLit kept consent records. */
865
+ "pre_tracking"
866
+ ];
867
+ var consentActorTypes = ["contact", "member", "api_key", "system"];
868
+ var consentSource = zod.z.string().trim().regex(
869
+ /^[a-z0-9][a-z0-9_.:-]{0,63}$/,
870
+ "Lowercase letters, digits and _ . : - (up to 64 characters)"
871
+ );
872
+ var consentInputSchema = zod.z.object({
873
+ source: consentSource.optional().describe(
874
+ "Your own name for where consent was collected, e.g. `storefront_signup`, `checkout`, `admin_import`. Lowercase letters, digits and _ . : -."
875
+ ),
876
+ wording: zod.z.string().trim().min(1).max(2e3).optional().describe("The exact text the person agreed to, e.g. the checkbox label"),
877
+ consentedAt: zod.z.string().datetime({ offset: true }).refine((value) => Date.parse(value) <= Date.now() + 5 * 6e4, {
878
+ message: "Can't be in the future"
879
+ }).optional().describe(
880
+ "When the person gave consent, if earlier than this call (ISO 8601). Kept as a claimed time next to the time SendLit recorded it."
881
+ ),
882
+ actor: zod.z.enum(["contact", "app"]).optional().describe(
883
+ "Who made the change: `contact` when the person did it themself (ticked the box, clicked unsubscribe in your app), `app` when your app or its admin did (default)."
884
+ ),
885
+ externalActorId: zod.z.string().trim().min(1).max(200).optional().describe("Your own id for whoever made the change, e.g. your admin's user id"),
886
+ ipAddress: zod.z.string().trim().ip().optional().describe("IP address of the person giving consent, if your app saw it"),
887
+ userAgent: zod.z.string().trim().min(1).max(512).optional().describe("Browser user agent of the person giving consent")
888
+ });
889
+ var consentEventSchema = zod.z.object({
890
+ consentEventId: zod.z.string(),
891
+ action: zod.z.enum(consentActions).describe(
892
+ "`opt_in`, `opt_out`, or `suppressed` (mail stopped by a bounce or suppression without the person opting out)"
893
+ ),
894
+ channel: zod.z.enum(consentChannels).describe("How the change reached SendLit"),
895
+ source: zod.z.string().nullable().describe(
896
+ "Where consent was collected, as the client app named it, or the suppression reason for `suppression` events"
897
+ ),
898
+ wording: zod.z.string().nullable().describe("The exact text the person agreed to"),
899
+ recordedAt: zod.z.string().describe("When SendLit recorded the change"),
900
+ consentedAt: zod.z.string().nullable().describe(
901
+ "When the change happened according to the caller or the imported file, if earlier than recordedAt. A claim, not verified by SendLit."
902
+ ),
903
+ actorType: zod.z.enum(consentActorTypes).describe(
904
+ "`contact` (the person themself), `member` (a team member), `api_key` (an app using an API key) or `system`"
905
+ ),
906
+ actorUserId: zod.z.string().nullable().describe("The team member, for `member`"),
907
+ apiKeyId: zod.z.string().nullable().describe("The API key the change came through"),
908
+ externalActorId: zod.z.string().nullable().describe("The client app's own id for whoever made the change"),
909
+ ipAddress: zod.z.string().nullable(),
910
+ userAgent: zod.z.string().nullable(),
911
+ formId: zod.z.string().nullable().describe("The signup form, for `form` events"),
912
+ doubleOptIn: zod.z.boolean().nullable().describe("For `form` opt-ins: whether the person confirmed by email"),
913
+ importId: zod.z.string().nullable().describe("The import, for `import` events"),
914
+ importConfirmed: zod.z.boolean().nullable().describe(
915
+ "For `import` opt-ins: the importer confirmed these people agreed to receive marketing email"
916
+ )
917
+ });
918
+ var consentHistorySchema = zod.z.object({
919
+ items: zod.z.array(consentEventSchema).describe("Newest first")
920
+ });
835
921
  var customFieldScalarSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]);
836
922
  var customFieldValueSchema = zod.z.union([
837
923
  customFieldScalarSchema,
@@ -1585,13 +1671,19 @@ var createContactBodySchema = zod.z.object({
1585
1671
  email: zod.z.string().email(),
1586
1672
  name: zod.z.string().optional(),
1587
1673
  tags: zod.z.array(zod.z.string()).optional(),
1588
- customFields: customFieldsSchema.optional()
1674
+ customFields: customFieldsSchema.optional(),
1675
+ consent: consentInputSchema.optional().describe(
1676
+ "How the person opted in. Recorded in the contact's consent history when this call creates the contact."
1677
+ )
1589
1678
  });
1590
1679
  var updateContactBodySchema = zod.z.object({
1591
1680
  name: zod.z.string().optional(),
1592
1681
  subscribed: zod.z.boolean().optional(),
1593
1682
  tags: zod.z.array(zod.z.string()).optional(),
1594
- customFields: customFieldsSchema.optional()
1683
+ customFields: customFieldsSchema.optional(),
1684
+ consent: consentInputSchema.optional().describe(
1685
+ "How the person opted in or out. Recorded in the consent history when `subscribed` changes, or with `subscribed` set to re-record an unchanged choice (for example a fresh opt-in at checkout)."
1686
+ )
1595
1687
  });
1596
1688
  var listContactsQuerySchema = zod.z.object({
1597
1689
  q: zod.z.string().optional().describe("Search term matched against email or name"),
@@ -1629,6 +1721,9 @@ var importContactRowSchema = zod.z.object({
1629
1721
  "The source platform's status, e.g. beehiiv's Active/Paused/Inactive/Pending or Mailchimp's subscribed/unsubscribed/cleaned. Empty means subscribed."
1630
1722
  ),
1631
1723
  createdAt: zod.z.string().optional().describe("Original signup date; kept as the contact's createdAt"),
1724
+ optedInAt: zod.z.string().optional().describe(
1725
+ "When the person opted in on the source platform (e.g. Mailchimp's OPTIN_TIME, a subscribed_at column). Kept in the consent history as a claimed time, marked as imported."
1726
+ ),
1632
1727
  customFields: customFieldsSchema.optional(),
1633
1728
  /** Echoed back in `skipped` so callers can point at the CSV line. */
1634
1729
  row: zod.z.number().int().optional()
@@ -1641,9 +1736,16 @@ var importContactsBodySchema = zod.z.object({
1641
1736
  ),
1642
1737
  source: zod.z.string().max(200).optional().describe(
1643
1738
  "Where the rows came from, e.g. the CSV file name; kept in the audit log"
1739
+ ),
1740
+ consentConfirmed: zod.z.boolean().optional().describe(
1741
+ "Required (true) when any row would be imported subscribed: you confirm that these people agreed to receive marketing email from you. Stored on each imported contact's consent record. Without it the import fails with 400 `consent_confirmation_required`."
1742
+ ),
1743
+ consent: consentInputSchema.pick({ source: true, wording: true }).optional().describe(
1744
+ "Where and with what wording the imported people opted in, if known; stored on each imported opt-in"
1644
1745
  )
1645
1746
  });
1646
1747
  var importContactsResultSchema = zod.z.object({
1748
+ importId: zod.z.string().describe("Identifies this import in the imported contacts' consent history"),
1647
1749
  created: zod.z.number().int(),
1648
1750
  updated: zod.z.number().int(),
1649
1751
  unchanged: zod.z.number().int(),
@@ -1929,11 +2031,33 @@ var createSignupFormBodySchema = zod.z.object({
1929
2031
  redirectUrl: zod.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")
1930
2032
  });
1931
2033
  var updateSignupFormBodySchema = createSignupFormBodySchema.partial();
2034
+ var SIGNUP_CONFIRMATION_TOKEN_PLACEHOLDER = "{{token}}";
2035
+ var SIGNUP_CONFIRMATION_URL_PLACEHOLDER = "{{confirmUrl}}";
2036
+ var containsConfirmUrl = (value) => value.includes(SIGNUP_CONFIRMATION_URL_PLACEHOLDER);
2037
+ var signupConfirmationOptionsSchema = zod.z.object({
2038
+ url: zod.z.string().url().max(2e3).refine((value) => /^https?:\/\//i.test(value), "Must be an http(s) URL").refine(
2039
+ (value) => value.includes(SIGNUP_CONFIRMATION_TOKEN_PLACEHOLDER),
2040
+ "Must contain {{token}}"
2041
+ ).optional().describe(
2042
+ "Where the emailed link points instead of SendLit's confirmation page. `{{token}}` is replaced with the confirmation token; the page there confirms it with POST /forms/{formId}/confirmations."
2043
+ ),
2044
+ email: zod.z.object({
2045
+ subject: zod.z.string().trim().min(1).max(200),
2046
+ html: zod.z.string().min(1).max(1e5).refine(containsConfirmUrl, "Must contain {{confirmUrl}}"),
2047
+ text: zod.z.string().min(1).max(5e4).refine(containsConfirmUrl, "Must contain {{confirmUrl}}")
2048
+ }).optional().describe(
2049
+ "The confirmation email to send instead of SendLit's own. `{{confirmUrl}}` is replaced with the confirmation link in both bodies."
2050
+ )
2051
+ });
1932
2052
  var submitSignupFormBodySchema = zod.z.object({
1933
2053
  email: zod.z.string().trim().min(1).max(254),
1934
2054
  name: zod.z.string().trim().max(200).optional(),
1935
2055
  clientIp: zod.z.string().trim().min(1).max(64).optional().describe(
1936
2056
  "IP address of the person signing up. Per-IP rate limits apply to it; without it they apply to the calling server."
2057
+ ),
2058
+ confirmation: signupConfirmationOptionsSchema.optional().describe("Double opt-in only: your own confirmation link and email"),
2059
+ consent: consentInputSchema.pick({ source: true, wording: true, userAgent: true }).optional().describe(
2060
+ "Recorded in the person's consent history: your name for the signup place, the exact text they agreed to, and their browser user agent. `clientIp` is recorded as their IP address."
1937
2061
  )
1938
2062
  });
1939
2063
  var signupFormSubmissionSchema = zod.z.object({
@@ -1941,6 +2065,16 @@ var signupFormSubmissionSchema = zod.z.object({
1941
2065
  "`confirmation_sent` for double opt-in forms, `subscribed` for single opt-in. The same for every address, accepted or quietly dropped."
1942
2066
  )
1943
2067
  });
2068
+ var confirmSignupBodySchema = zod.z.object({
2069
+ token: zod.z.string().trim().min(1).max(200),
2070
+ clientIp: zod.z.string().trim().ip().optional().describe("IP address of the person confirming; kept in their consent history"),
2071
+ userAgent: zod.z.string().trim().min(1).max(512).optional().describe(
2072
+ "Browser user agent of the person confirming; kept in their consent history"
2073
+ )
2074
+ });
2075
+ var signupConfirmationSchema = zod.z.object({
2076
+ status: zod.z.literal("confirmed").describe("The person is subscribed. Confirming again is harmless.")
2077
+ });
1944
2078
  var mediaSchema = zod.z.object({
1945
2079
  mediaId: zod.z.string(),
1946
2080
  url: zod.z.string(),
@@ -2375,7 +2509,7 @@ var contactsContract = c.router(
2375
2509
  400: errorSchema
2376
2510
  },
2377
2511
  summary: "Import contacts",
2378
- 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`."
2512
+ 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`. When any row would be imported subscribed, `consentConfirmed: true` is required (400 `consent_confirmation_required` otherwise): you confirm these people agreed to receive marketing email from you. Each imported contact gets a consent event with the returned `importId`, the confirmation, who imported, and the row's `optedInAt` as a claimed time."
2379
2513
  },
2380
2514
  export: {
2381
2515
  method: "GET",
@@ -2387,7 +2521,7 @@ var contactsContract = c.router(
2387
2521
  404: errorSchema
2388
2522
  },
2389
2523
  summary: "Export contacts as CSV",
2390
- 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."
2524
+ 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, the latest opt-in's opted_in_at, consent_channel, consent_source and consent_wording, then one column per custom field."
2391
2525
  },
2392
2526
  previewBulkDelete: {
2393
2527
  method: "POST",
@@ -2471,11 +2605,19 @@ var contactsContract = c.router(
2471
2605
  summary: "List the custom events received for a contact",
2472
2606
  description: "Newest first by occurredAt. `enrolledSequences` lists the sequences each event started."
2473
2607
  },
2608
+ consent: {
2609
+ method: "GET",
2610
+ path: "/contacts/:contactId/consent",
2611
+ responses: { 200: consentHistorySchema, 404: errorSchema },
2612
+ summary: "List a contact's consent history",
2613
+ description: "Every opt-in, opt-out and suppression recorded for the contact, newest first: how it reached SendLit (`channel`), where it was collected (`source`), the wording the person agreed to, who made it, and for forms and imports the IP address, user agent, double opt-in and import confirmation. Contacts that existed before consent records start with one `pre_tracking` event holding their state at that time. The history is deleted with the contact."
2614
+ },
2474
2615
  remove: {
2475
2616
  method: "DELETE",
2476
2617
  path: "/contacts/:contactId",
2477
2618
  responses: { 204: c.noBody() },
2478
- summary: "Delete a contact"
2619
+ summary: "Delete a contact",
2620
+ description: "Deletes the contact with its consent history, custom field values, events and delivery records."
2479
2621
  }
2480
2622
  },
2481
2623
  { metadata: { tag: "Contacts" } }
@@ -4268,7 +4410,19 @@ var formsContract = c.router(
4268
4410
  })
4269
4411
  },
4270
4412
  summary: "Submit a signup to a form",
4271
- description: "Signs someone up through the form from your own server, for a signup page you host yourself. It works like a submission to the form's public URL: double opt-in forms email the confirmation link and subscribe only once it's clicked, single opt-in never resubscribes someone who unsubscribed, and suppressed or disposable addresses are dropped quietly. A double opt-in form doesn't email someone who is already subscribed. Pass `clientIp` so the per-IP rate limit applies to the person, not your server. Fails with 400 `invalid_email`, 429 `too_many_requests`, or 503 `form_unavailable` when the team can't send the confirmation email."
4413
+ description: "Signs someone up through the form from your own server, for a signup page you host yourself. It works like a submission to the form's public URL: double opt-in forms email the confirmation link and subscribe only once it's clicked, single opt-in never resubscribes someone who unsubscribed, and suppressed or disposable addresses are dropped quietly. A double opt-in form doesn't email someone who is already subscribed. Pass `clientIp` so the per-IP rate limit applies to the person, not your server. For double opt-in, `confirmation` replaces the email and points its link at your own page (for example to match your site's language); that page confirms the token with POST /forms/{formId}/confirmations. Fails with 400 `invalid_email`, 429 `too_many_requests`, or 503 `form_unavailable` when the team can't send the confirmation email."
4414
+ },
4415
+ confirm: {
4416
+ method: "POST",
4417
+ path: "/forms/:formId/confirmations",
4418
+ body: confirmSignupBodySchema,
4419
+ responses: {
4420
+ 200: signupConfirmationSchema,
4421
+ 400: errorSchema,
4422
+ 404: errorSchema
4423
+ },
4424
+ summary: "Confirm a double opt-in signup",
4425
+ description: "Confirms a signup from the token in its confirmation link, for a confirmation page you host yourself (see `confirmation.url` on submit). Subscribes the person with the form's tags; confirming again is harmless. Only call it when the person presses a button on your page: link scanners open emailed links too. Fails with 400 `invalid_token` when the token is unknown, expired, or belongs to another form."
4272
4426
  }
4273
4427
  },
4274
4428
  { metadata: { tag: "Contacts" } }
@@ -4606,6 +4760,22 @@ var Contacts = class {
4606
4760
  params: { contactId: assertId(contactId, "contactId") }
4607
4761
  });
4608
4762
  }
4763
+ /** The contact's consent history, newest first: every opt-in, opt-out
4764
+ * and suppression with its channel, source, wording, actor, and for forms
4765
+ * and imports the IP address, user agent, double opt-in and import
4766
+ * confirmation. Keep it as proof of consent. */
4767
+ async consent(contactId) {
4768
+ const { items } = await this.http.request(routes.consent, {
4769
+ params: { contactId: assertId(contactId, "contactId") }
4770
+ });
4771
+ return items;
4772
+ }
4773
+ /** Imports up to 1000 contacts, matched by email. Importing anyone as
4774
+ * subscribed requires `consentConfirmed: true`: you confirm they agreed
4775
+ * to receive marketing email from you. */
4776
+ async import(input) {
4777
+ return this.http.request(routes.import, { body: input });
4778
+ }
4609
4779
  /** Custom events received for this contact, newest first, with the
4610
4780
  * sequences each one started. */
4611
4781
  async events(contactId, query = {}) {
@@ -4765,6 +4935,17 @@ var Forms = class {
4765
4935
  body: input
4766
4936
  });
4767
4937
  }
4938
+ /**
4939
+ * Confirms a double opt-in signup from the token in its link, for a
4940
+ * confirmation page you host (`confirmation.url` on `submit`). Call it only
4941
+ * when the person presses a button there: link scanners open links too.
4942
+ */
4943
+ async confirm(formId, token) {
4944
+ return this.http.request(routes5.confirm, {
4945
+ params: { formId: assertId(formId, "formId") },
4946
+ body: { token }
4947
+ });
4948
+ }
4768
4949
  };
4769
4950
 
4770
4951
  // src/resources/overview.ts
package/dist/index.mjs CHANGED
@@ -165,17 +165,28 @@ headers("created_at", [
165
165
  "created",
166
166
  "created_date",
167
167
  "date_added",
168
- "subscribed_at",
169
- "subscribe_date",
170
- "subscription_date",
171
168
  "signup_date",
172
169
  "sign_up_date",
170
+ "joined_at"
171
+ ]);
172
+ headers("opted_in_at", [
173
+ "opted_in_at",
173
174
  "optin_time",
175
+ "opt_in_time",
176
+ "opt_in_date",
174
177
  "confirm_time",
175
- "joined_at"
178
+ "subscribed_at",
179
+ "subscribe_date",
180
+ "subscription_date",
181
+ "consent_date"
176
182
  ]);
177
183
  headers("tag_from_value", ["tier", "plan", "subscription_tier"]);
178
- headers("ignore", ["suppression_reason"]);
184
+ headers("ignore", [
185
+ "suppression_reason",
186
+ "consent_channel",
187
+ "consent_source",
188
+ "consent_wording"
189
+ ]);
179
190
  function statuses(result, values) {
180
191
  for (const value of values)
181
192
  result;
@@ -830,6 +841,81 @@ function paginated(item) {
830
841
  function itemsList(item) {
831
842
  return z.object({ items: z.array(item) });
832
843
  }
844
+ var consentActions = ["opt_in", "opt_out", "suppressed"];
845
+ var consentChannels = [
846
+ /** A signup form: the hosted page, an embedded form, or `forms.submit`. */
847
+ "form",
848
+ /** A contact import (CSV in the dashboard, or `contacts.import`). */
849
+ "import",
850
+ /** The REST API with an API key or OAuth token. */
851
+ "api",
852
+ /** An MCP tool. */
853
+ "mcp",
854
+ /** A team member in the SendLit dashboard. */
855
+ "dashboard",
856
+ /** The unsubscribe link in an email. */
857
+ "unsubscribe_link",
858
+ /** A mailbox provider's one-click unsubscribe (RFC 8058 List-Unsubscribe). */
859
+ "list_unsubscribe",
860
+ /** A suppression: hard bounce, spam complaint, provider or manual. */
861
+ "suppression",
862
+ /** The contact existed before SendLit kept consent records. */
863
+ "pre_tracking"
864
+ ];
865
+ var consentActorTypes = ["contact", "member", "api_key", "system"];
866
+ var consentSource = z.string().trim().regex(
867
+ /^[a-z0-9][a-z0-9_.:-]{0,63}$/,
868
+ "Lowercase letters, digits and _ . : - (up to 64 characters)"
869
+ );
870
+ var consentInputSchema = z.object({
871
+ source: consentSource.optional().describe(
872
+ "Your own name for where consent was collected, e.g. `storefront_signup`, `checkout`, `admin_import`. Lowercase letters, digits and _ . : -."
873
+ ),
874
+ wording: z.string().trim().min(1).max(2e3).optional().describe("The exact text the person agreed to, e.g. the checkbox label"),
875
+ consentedAt: z.string().datetime({ offset: true }).refine((value) => Date.parse(value) <= Date.now() + 5 * 6e4, {
876
+ message: "Can't be in the future"
877
+ }).optional().describe(
878
+ "When the person gave consent, if earlier than this call (ISO 8601). Kept as a claimed time next to the time SendLit recorded it."
879
+ ),
880
+ actor: z.enum(["contact", "app"]).optional().describe(
881
+ "Who made the change: `contact` when the person did it themself (ticked the box, clicked unsubscribe in your app), `app` when your app or its admin did (default)."
882
+ ),
883
+ externalActorId: z.string().trim().min(1).max(200).optional().describe("Your own id for whoever made the change, e.g. your admin's user id"),
884
+ ipAddress: z.string().trim().ip().optional().describe("IP address of the person giving consent, if your app saw it"),
885
+ userAgent: z.string().trim().min(1).max(512).optional().describe("Browser user agent of the person giving consent")
886
+ });
887
+ var consentEventSchema = z.object({
888
+ consentEventId: z.string(),
889
+ action: z.enum(consentActions).describe(
890
+ "`opt_in`, `opt_out`, or `suppressed` (mail stopped by a bounce or suppression without the person opting out)"
891
+ ),
892
+ channel: z.enum(consentChannels).describe("How the change reached SendLit"),
893
+ source: z.string().nullable().describe(
894
+ "Where consent was collected, as the client app named it, or the suppression reason for `suppression` events"
895
+ ),
896
+ wording: z.string().nullable().describe("The exact text the person agreed to"),
897
+ recordedAt: z.string().describe("When SendLit recorded the change"),
898
+ consentedAt: z.string().nullable().describe(
899
+ "When the change happened according to the caller or the imported file, if earlier than recordedAt. A claim, not verified by SendLit."
900
+ ),
901
+ actorType: z.enum(consentActorTypes).describe(
902
+ "`contact` (the person themself), `member` (a team member), `api_key` (an app using an API key) or `system`"
903
+ ),
904
+ actorUserId: z.string().nullable().describe("The team member, for `member`"),
905
+ apiKeyId: z.string().nullable().describe("The API key the change came through"),
906
+ externalActorId: z.string().nullable().describe("The client app's own id for whoever made the change"),
907
+ ipAddress: z.string().nullable(),
908
+ userAgent: z.string().nullable(),
909
+ formId: z.string().nullable().describe("The signup form, for `form` events"),
910
+ doubleOptIn: z.boolean().nullable().describe("For `form` opt-ins: whether the person confirmed by email"),
911
+ importId: z.string().nullable().describe("The import, for `import` events"),
912
+ importConfirmed: z.boolean().nullable().describe(
913
+ "For `import` opt-ins: the importer confirmed these people agreed to receive marketing email"
914
+ )
915
+ });
916
+ var consentHistorySchema = z.object({
917
+ items: z.array(consentEventSchema).describe("Newest first")
918
+ });
833
919
  var customFieldScalarSchema = z.union([z.string(), z.number(), z.boolean()]);
834
920
  var customFieldValueSchema = z.union([
835
921
  customFieldScalarSchema,
@@ -1583,13 +1669,19 @@ var createContactBodySchema = z.object({
1583
1669
  email: z.string().email(),
1584
1670
  name: z.string().optional(),
1585
1671
  tags: z.array(z.string()).optional(),
1586
- customFields: customFieldsSchema.optional()
1672
+ customFields: customFieldsSchema.optional(),
1673
+ consent: consentInputSchema.optional().describe(
1674
+ "How the person opted in. Recorded in the contact's consent history when this call creates the contact."
1675
+ )
1587
1676
  });
1588
1677
  var updateContactBodySchema = z.object({
1589
1678
  name: z.string().optional(),
1590
1679
  subscribed: z.boolean().optional(),
1591
1680
  tags: z.array(z.string()).optional(),
1592
- customFields: customFieldsSchema.optional()
1681
+ customFields: customFieldsSchema.optional(),
1682
+ consent: consentInputSchema.optional().describe(
1683
+ "How the person opted in or out. Recorded in the consent history when `subscribed` changes, or with `subscribed` set to re-record an unchanged choice (for example a fresh opt-in at checkout)."
1684
+ )
1593
1685
  });
1594
1686
  var listContactsQuerySchema = z.object({
1595
1687
  q: z.string().optional().describe("Search term matched against email or name"),
@@ -1627,6 +1719,9 @@ var importContactRowSchema = z.object({
1627
1719
  "The source platform's status, e.g. beehiiv's Active/Paused/Inactive/Pending or Mailchimp's subscribed/unsubscribed/cleaned. Empty means subscribed."
1628
1720
  ),
1629
1721
  createdAt: z.string().optional().describe("Original signup date; kept as the contact's createdAt"),
1722
+ optedInAt: z.string().optional().describe(
1723
+ "When the person opted in on the source platform (e.g. Mailchimp's OPTIN_TIME, a subscribed_at column). Kept in the consent history as a claimed time, marked as imported."
1724
+ ),
1630
1725
  customFields: customFieldsSchema.optional(),
1631
1726
  /** Echoed back in `skipped` so callers can point at the CSV line. */
1632
1727
  row: z.number().int().optional()
@@ -1639,9 +1734,16 @@ var importContactsBodySchema = z.object({
1639
1734
  ),
1640
1735
  source: z.string().max(200).optional().describe(
1641
1736
  "Where the rows came from, e.g. the CSV file name; kept in the audit log"
1737
+ ),
1738
+ consentConfirmed: z.boolean().optional().describe(
1739
+ "Required (true) when any row would be imported subscribed: you confirm that these people agreed to receive marketing email from you. Stored on each imported contact's consent record. Without it the import fails with 400 `consent_confirmation_required`."
1740
+ ),
1741
+ consent: consentInputSchema.pick({ source: true, wording: true }).optional().describe(
1742
+ "Where and with what wording the imported people opted in, if known; stored on each imported opt-in"
1642
1743
  )
1643
1744
  });
1644
1745
  var importContactsResultSchema = z.object({
1746
+ importId: z.string().describe("Identifies this import in the imported contacts' consent history"),
1645
1747
  created: z.number().int(),
1646
1748
  updated: z.number().int(),
1647
1749
  unchanged: z.number().int(),
@@ -1927,11 +2029,33 @@ var createSignupFormBodySchema = z.object({
1927
2029
  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")
1928
2030
  });
1929
2031
  var updateSignupFormBodySchema = createSignupFormBodySchema.partial();
2032
+ var SIGNUP_CONFIRMATION_TOKEN_PLACEHOLDER = "{{token}}";
2033
+ var SIGNUP_CONFIRMATION_URL_PLACEHOLDER = "{{confirmUrl}}";
2034
+ var containsConfirmUrl = (value) => value.includes(SIGNUP_CONFIRMATION_URL_PLACEHOLDER);
2035
+ var signupConfirmationOptionsSchema = z.object({
2036
+ url: z.string().url().max(2e3).refine((value) => /^https?:\/\//i.test(value), "Must be an http(s) URL").refine(
2037
+ (value) => value.includes(SIGNUP_CONFIRMATION_TOKEN_PLACEHOLDER),
2038
+ "Must contain {{token}}"
2039
+ ).optional().describe(
2040
+ "Where the emailed link points instead of SendLit's confirmation page. `{{token}}` is replaced with the confirmation token; the page there confirms it with POST /forms/{formId}/confirmations."
2041
+ ),
2042
+ email: z.object({
2043
+ subject: z.string().trim().min(1).max(200),
2044
+ html: z.string().min(1).max(1e5).refine(containsConfirmUrl, "Must contain {{confirmUrl}}"),
2045
+ text: z.string().min(1).max(5e4).refine(containsConfirmUrl, "Must contain {{confirmUrl}}")
2046
+ }).optional().describe(
2047
+ "The confirmation email to send instead of SendLit's own. `{{confirmUrl}}` is replaced with the confirmation link in both bodies."
2048
+ )
2049
+ });
1930
2050
  var submitSignupFormBodySchema = z.object({
1931
2051
  email: z.string().trim().min(1).max(254),
1932
2052
  name: z.string().trim().max(200).optional(),
1933
2053
  clientIp: z.string().trim().min(1).max(64).optional().describe(
1934
2054
  "IP address of the person signing up. Per-IP rate limits apply to it; without it they apply to the calling server."
2055
+ ),
2056
+ confirmation: signupConfirmationOptionsSchema.optional().describe("Double opt-in only: your own confirmation link and email"),
2057
+ consent: consentInputSchema.pick({ source: true, wording: true, userAgent: true }).optional().describe(
2058
+ "Recorded in the person's consent history: your name for the signup place, the exact text they agreed to, and their browser user agent. `clientIp` is recorded as their IP address."
1935
2059
  )
1936
2060
  });
1937
2061
  var signupFormSubmissionSchema = z.object({
@@ -1939,6 +2063,16 @@ var signupFormSubmissionSchema = z.object({
1939
2063
  "`confirmation_sent` for double opt-in forms, `subscribed` for single opt-in. The same for every address, accepted or quietly dropped."
1940
2064
  )
1941
2065
  });
2066
+ var confirmSignupBodySchema = z.object({
2067
+ token: z.string().trim().min(1).max(200),
2068
+ clientIp: z.string().trim().ip().optional().describe("IP address of the person confirming; kept in their consent history"),
2069
+ userAgent: z.string().trim().min(1).max(512).optional().describe(
2070
+ "Browser user agent of the person confirming; kept in their consent history"
2071
+ )
2072
+ });
2073
+ var signupConfirmationSchema = z.object({
2074
+ status: z.literal("confirmed").describe("The person is subscribed. Confirming again is harmless.")
2075
+ });
1942
2076
  var mediaSchema = z.object({
1943
2077
  mediaId: z.string(),
1944
2078
  url: z.string(),
@@ -2373,7 +2507,7 @@ var contactsContract = c.router(
2373
2507
  400: errorSchema
2374
2508
  },
2375
2509
  summary: "Import contacts",
2376
- 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`."
2510
+ 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`. When any row would be imported subscribed, `consentConfirmed: true` is required (400 `consent_confirmation_required` otherwise): you confirm these people agreed to receive marketing email from you. Each imported contact gets a consent event with the returned `importId`, the confirmation, who imported, and the row's `optedInAt` as a claimed time."
2377
2511
  },
2378
2512
  export: {
2379
2513
  method: "GET",
@@ -2385,7 +2519,7 @@ var contactsContract = c.router(
2385
2519
  404: errorSchema
2386
2520
  },
2387
2521
  summary: "Export contacts as CSV",
2388
- 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."
2522
+ 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, the latest opt-in's opted_in_at, consent_channel, consent_source and consent_wording, then one column per custom field."
2389
2523
  },
2390
2524
  previewBulkDelete: {
2391
2525
  method: "POST",
@@ -2469,11 +2603,19 @@ var contactsContract = c.router(
2469
2603
  summary: "List the custom events received for a contact",
2470
2604
  description: "Newest first by occurredAt. `enrolledSequences` lists the sequences each event started."
2471
2605
  },
2606
+ consent: {
2607
+ method: "GET",
2608
+ path: "/contacts/:contactId/consent",
2609
+ responses: { 200: consentHistorySchema, 404: errorSchema },
2610
+ summary: "List a contact's consent history",
2611
+ description: "Every opt-in, opt-out and suppression recorded for the contact, newest first: how it reached SendLit (`channel`), where it was collected (`source`), the wording the person agreed to, who made it, and for forms and imports the IP address, user agent, double opt-in and import confirmation. Contacts that existed before consent records start with one `pre_tracking` event holding their state at that time. The history is deleted with the contact."
2612
+ },
2472
2613
  remove: {
2473
2614
  method: "DELETE",
2474
2615
  path: "/contacts/:contactId",
2475
2616
  responses: { 204: c.noBody() },
2476
- summary: "Delete a contact"
2617
+ summary: "Delete a contact",
2618
+ description: "Deletes the contact with its consent history, custom field values, events and delivery records."
2477
2619
  }
2478
2620
  },
2479
2621
  { metadata: { tag: "Contacts" } }
@@ -4266,7 +4408,19 @@ var formsContract = c.router(
4266
4408
  })
4267
4409
  },
4268
4410
  summary: "Submit a signup to a form",
4269
- description: "Signs someone up through the form from your own server, for a signup page you host yourself. It works like a submission to the form's public URL: double opt-in forms email the confirmation link and subscribe only once it's clicked, single opt-in never resubscribes someone who unsubscribed, and suppressed or disposable addresses are dropped quietly. A double opt-in form doesn't email someone who is already subscribed. Pass `clientIp` so the per-IP rate limit applies to the person, not your server. Fails with 400 `invalid_email`, 429 `too_many_requests`, or 503 `form_unavailable` when the team can't send the confirmation email."
4411
+ description: "Signs someone up through the form from your own server, for a signup page you host yourself. It works like a submission to the form's public URL: double opt-in forms email the confirmation link and subscribe only once it's clicked, single opt-in never resubscribes someone who unsubscribed, and suppressed or disposable addresses are dropped quietly. A double opt-in form doesn't email someone who is already subscribed. Pass `clientIp` so the per-IP rate limit applies to the person, not your server. For double opt-in, `confirmation` replaces the email and points its link at your own page (for example to match your site's language); that page confirms the token with POST /forms/{formId}/confirmations. Fails with 400 `invalid_email`, 429 `too_many_requests`, or 503 `form_unavailable` when the team can't send the confirmation email."
4412
+ },
4413
+ confirm: {
4414
+ method: "POST",
4415
+ path: "/forms/:formId/confirmations",
4416
+ body: confirmSignupBodySchema,
4417
+ responses: {
4418
+ 200: signupConfirmationSchema,
4419
+ 400: errorSchema,
4420
+ 404: errorSchema
4421
+ },
4422
+ summary: "Confirm a double opt-in signup",
4423
+ description: "Confirms a signup from the token in its confirmation link, for a confirmation page you host yourself (see `confirmation.url` on submit). Subscribes the person with the form's tags; confirming again is harmless. Only call it when the person presses a button on your page: link scanners open emailed links too. Fails with 400 `invalid_token` when the token is unknown, expired, or belongs to another form."
4270
4424
  }
4271
4425
  },
4272
4426
  { metadata: { tag: "Contacts" } }
@@ -4604,6 +4758,22 @@ var Contacts = class {
4604
4758
  params: { contactId: assertId(contactId, "contactId") }
4605
4759
  });
4606
4760
  }
4761
+ /** The contact's consent history, newest first: every opt-in, opt-out
4762
+ * and suppression with its channel, source, wording, actor, and for forms
4763
+ * and imports the IP address, user agent, double opt-in and import
4764
+ * confirmation. Keep it as proof of consent. */
4765
+ async consent(contactId) {
4766
+ const { items } = await this.http.request(routes.consent, {
4767
+ params: { contactId: assertId(contactId, "contactId") }
4768
+ });
4769
+ return items;
4770
+ }
4771
+ /** Imports up to 1000 contacts, matched by email. Importing anyone as
4772
+ * subscribed requires `consentConfirmed: true`: you confirm they agreed
4773
+ * to receive marketing email from you. */
4774
+ async import(input) {
4775
+ return this.http.request(routes.import, { body: input });
4776
+ }
4607
4777
  /** Custom events received for this contact, newest first, with the
4608
4778
  * sequences each one started. */
4609
4779
  async events(contactId, query = {}) {
@@ -4763,6 +4933,17 @@ var Forms = class {
4763
4933
  body: input
4764
4934
  });
4765
4935
  }
4936
+ /**
4937
+ * Confirms a double opt-in signup from the token in its link, for a
4938
+ * confirmation page you host (`confirmation.url` on `submit`). Call it only
4939
+ * when the person presses a button there: link scanners open links too.
4940
+ */
4941
+ async confirm(formId, token) {
4942
+ return this.http.request(routes5.confirm, {
4943
+ params: { formId: assertId(formId, "formId") },
4944
+ body: { token }
4945
+ });
4946
+ }
4766
4947
  };
4767
4948
 
4768
4949
  // src/resources/overview.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sendlit",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Official server-side TypeScript SDK for the SendLit email marketing API",
5
5
  "author": "SendLit",
6
6
  "license": "MIT",