sendlit 0.2.0 → 0.3.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/README.md +28 -2
- package/dist/index.d.mts +1227 -289
- package/dist/index.d.ts +1227 -289
- package/dist/index.js +409 -46
- package/dist/index.mjs +408 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -588,10 +588,204 @@ var sendingOptionSchema = zod.z.discriminatedUnion("type", [
|
|
|
588
588
|
countsAgainstQuota: zod.z.literal(false)
|
|
589
589
|
})
|
|
590
590
|
]);
|
|
591
|
+
var EVENT_NAME_MAX_LENGTH = 128;
|
|
592
|
+
var EVENT_PROPERTIES_MAX_BYTES = 32 * 1024;
|
|
593
|
+
var EVENT_PROPERTIES_MAX_KEYS = 100;
|
|
594
|
+
var EVENT_PROPERTIES_MAX_DEPTH = 3;
|
|
595
|
+
var EVENT_FILTER_MAX_CONDITIONS = 10;
|
|
596
|
+
var EVENT_MAX_FUTURE_MS = 24 * 60 * 60 * 1e3;
|
|
597
|
+
var eventPropertyKeyPattern = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
|
|
598
|
+
var controlCharacters = /[\u0000-\u001f\u007f]/;
|
|
599
|
+
var eventNameSchema = zod.z.string().trim().min(1).max(EVENT_NAME_MAX_LENGTH).refine((name) => !controlCharacters.test(name), {
|
|
600
|
+
message: "Event names can't contain control characters"
|
|
601
|
+
}).refine((name) => !name.startsWith("$"), {
|
|
602
|
+
message: "Event names can't start with $"
|
|
603
|
+
});
|
|
604
|
+
function propertiesProblem(value, depth) {
|
|
605
|
+
if (Array.isArray(value)) {
|
|
606
|
+
for (const item of value) {
|
|
607
|
+
const problem = propertiesProblem(item, depth + 1);
|
|
608
|
+
if (problem)
|
|
609
|
+
return problem;
|
|
610
|
+
}
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
if (value && typeof value === "object") {
|
|
614
|
+
if (depth >= EVENT_PROPERTIES_MAX_DEPTH) {
|
|
615
|
+
return `Properties can be nested at most ${EVENT_PROPERTIES_MAX_DEPTH} levels`;
|
|
616
|
+
}
|
|
617
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
618
|
+
if (!eventPropertyKeyPattern.test(key)) {
|
|
619
|
+
return `Property key "${key}" must start with a letter or _ and contain only letters, digits and _ (max 64)`;
|
|
620
|
+
}
|
|
621
|
+
const problem = propertiesProblem(nested, depth + 1);
|
|
622
|
+
if (problem)
|
|
623
|
+
return problem;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
var eventPropertiesSchema = zod.z.record(zod.z.unknown()).superRefine((properties, ctx) => {
|
|
629
|
+
if (Object.keys(properties).length > EVENT_PROPERTIES_MAX_KEYS) {
|
|
630
|
+
ctx.addIssue({
|
|
631
|
+
code: zod.z.ZodIssueCode.custom,
|
|
632
|
+
message: `At most ${EVENT_PROPERTIES_MAX_KEYS} top-level properties`
|
|
633
|
+
});
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const bytes = new TextEncoder().encode(JSON.stringify(properties)).length;
|
|
637
|
+
if (bytes > EVENT_PROPERTIES_MAX_BYTES) {
|
|
638
|
+
ctx.addIssue({
|
|
639
|
+
code: zod.z.ZodIssueCode.custom,
|
|
640
|
+
message: `Properties can be at most ${EVENT_PROPERTIES_MAX_BYTES} bytes as JSON`
|
|
641
|
+
});
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const problem = propertiesProblem(properties, 0);
|
|
645
|
+
if (problem)
|
|
646
|
+
ctx.addIssue({ code: zod.z.ZodIssueCode.custom, message: problem });
|
|
647
|
+
});
|
|
648
|
+
var trackEventFieldsSchema = zod.z.object({
|
|
649
|
+
email: zod.z.string().email().optional(),
|
|
650
|
+
contactId: zod.z.string().min(1).optional(),
|
|
651
|
+
eventName: eventNameSchema,
|
|
652
|
+
properties: eventPropertiesSchema.optional(),
|
|
653
|
+
occurredAt: zod.z.string().datetime({ offset: true }).optional().describe("When it happened. At most 24 h in the future; defaults to now."),
|
|
654
|
+
idempotencyKey: zod.z.string().min(1).max(256).optional().describe("The same key within 30 days stores one event and enrolls once."),
|
|
655
|
+
backfill: zod.z.boolean().optional().describe("Record only: the event never starts a sequence."),
|
|
656
|
+
createContact: zod.z.boolean().optional().describe(
|
|
657
|
+
"Create the contact when the email is unknown (default true). Ignored with contactId."
|
|
658
|
+
),
|
|
659
|
+
contact: zod.z.object({
|
|
660
|
+
name: zod.z.string().optional(),
|
|
661
|
+
customFields: customFieldsSchema.optional()
|
|
662
|
+
}).strict().optional().describe(
|
|
663
|
+
"Applied to the contact. Custom fields are merged into the existing ones."
|
|
664
|
+
)
|
|
665
|
+
}).strict();
|
|
666
|
+
var trackEventBodySchema = trackEventFieldsSchema.refine((body) => !!body.email !== !!body.contactId, {
|
|
667
|
+
message: "Provide exactly one of email or contactId"
|
|
668
|
+
}).refine(
|
|
669
|
+
(body) => !body.occurredAt || new Date(body.occurredAt).getTime() <= Date.now() + EVENT_MAX_FUTURE_MS,
|
|
670
|
+
{ message: "occurredAt can be at most 24 hours in the future" }
|
|
671
|
+
);
|
|
672
|
+
var trackEventResponseSchema = zod.z.object({
|
|
673
|
+
eventId: zod.z.string(),
|
|
674
|
+
contactId: zod.z.string(),
|
|
675
|
+
duplicate: zod.z.boolean(),
|
|
676
|
+
contactCreated: zod.z.boolean()
|
|
677
|
+
});
|
|
678
|
+
var eventSources = ["api", "session", "mcp"];
|
|
679
|
+
var contactEventSchema = zod.z.object({
|
|
680
|
+
eventId: zod.z.string(),
|
|
681
|
+
name: zod.z.string(),
|
|
682
|
+
properties: zod.z.record(zod.z.unknown()),
|
|
683
|
+
occurredAt: zod.z.string(),
|
|
684
|
+
receivedAt: zod.z.string(),
|
|
685
|
+
source: zod.z.enum(eventSources),
|
|
686
|
+
backfill: zod.z.boolean(),
|
|
687
|
+
triggers: zod.z.boolean(),
|
|
688
|
+
enrolledSequences: zod.z.array(zod.z.object({ sequenceId: zod.z.string(), title: zod.z.string() }))
|
|
689
|
+
});
|
|
690
|
+
var listContactEventsQuerySchema = zod.z.object({
|
|
691
|
+
page: zod.z.coerce.number().int().min(1).optional(),
|
|
692
|
+
limit: zod.z.coerce.number().int().min(1).max(50).optional(),
|
|
693
|
+
name: eventNameSchema.optional()
|
|
694
|
+
});
|
|
695
|
+
var eventPropertyTypes = [
|
|
696
|
+
"string",
|
|
697
|
+
"number",
|
|
698
|
+
"boolean",
|
|
699
|
+
"date",
|
|
700
|
+
"object",
|
|
701
|
+
"array"
|
|
702
|
+
];
|
|
703
|
+
var eventDefinitionPropertySchema = zod.z.object({
|
|
704
|
+
key: zod.z.string().regex(eventPropertyKeyPattern),
|
|
705
|
+
type: zod.z.enum(eventPropertyTypes),
|
|
706
|
+
declared: zod.z.boolean()
|
|
707
|
+
});
|
|
708
|
+
var eventDefinitionSchema = zod.z.object({
|
|
709
|
+
name: zod.z.string(),
|
|
710
|
+
origin: zod.z.enum(["received", "manual"]),
|
|
711
|
+
description: zod.z.string().nullable(),
|
|
712
|
+
properties: zod.z.array(eventDefinitionPropertySchema),
|
|
713
|
+
firstSeenAt: zod.z.string().nullable(),
|
|
714
|
+
lastSeenAt: zod.z.string().nullable(),
|
|
715
|
+
createdAt: zod.z.string(),
|
|
716
|
+
/** Non-deleted sequences whose trigger is this event. */
|
|
717
|
+
sequenceCount: zod.z.number().int()
|
|
718
|
+
});
|
|
719
|
+
var eventDefinitionDetailSchema = eventDefinitionSchema.extend({
|
|
720
|
+
lastProperties: zod.z.record(zod.z.unknown()).nullable()
|
|
721
|
+
});
|
|
722
|
+
var declaredPropertiesSchema = zod.z.array(
|
|
723
|
+
zod.z.object({
|
|
724
|
+
key: zod.z.string().regex(eventPropertyKeyPattern),
|
|
725
|
+
type: zod.z.enum(eventPropertyTypes)
|
|
726
|
+
})
|
|
727
|
+
).max(EVENT_PROPERTIES_MAX_KEYS).refine((props) => new Set(props.map((p) => p.key)).size === props.length, {
|
|
728
|
+
message: "Property keys must be unique"
|
|
729
|
+
});
|
|
730
|
+
var createEventDefinitionBodySchema = zod.z.object({
|
|
731
|
+
name: eventNameSchema,
|
|
732
|
+
description: zod.z.string().max(500).optional(),
|
|
733
|
+
properties: declaredPropertiesSchema.optional()
|
|
734
|
+
}).strict();
|
|
735
|
+
var updateEventDefinitionBodySchema = zod.z.object({
|
|
736
|
+
description: zod.z.string().max(500).nullable().optional(),
|
|
737
|
+
properties: declaredPropertiesSchema.optional().describe("Replaces the declared properties. Observed keys stay.")
|
|
738
|
+
}).strict();
|
|
739
|
+
var filterScalarSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()]);
|
|
740
|
+
var eventFilterConditions = [
|
|
741
|
+
"is",
|
|
742
|
+
"is_not",
|
|
743
|
+
"contains",
|
|
744
|
+
"not_contains",
|
|
745
|
+
"gt",
|
|
746
|
+
"gte",
|
|
747
|
+
"lt",
|
|
748
|
+
"lte",
|
|
749
|
+
"exists",
|
|
750
|
+
"not_exists"
|
|
751
|
+
];
|
|
752
|
+
var eventFilterKeySchema = zod.z.string().refine(
|
|
753
|
+
(key) => {
|
|
754
|
+
const parts = key.split(".");
|
|
755
|
+
return parts.length <= EVENT_PROPERTIES_MAX_DEPTH && parts.every((part) => eventPropertyKeyPattern.test(part));
|
|
756
|
+
},
|
|
757
|
+
{ message: "Use a property key, or a dot path up to 3 levels" }
|
|
758
|
+
);
|
|
759
|
+
var eventPropertyFilterSchema = zod.z.object({
|
|
760
|
+
aggregator: zod.z.enum(["and", "or"]),
|
|
761
|
+
filters: zod.z.array(
|
|
762
|
+
zod.z.object({
|
|
763
|
+
key: eventFilterKeySchema,
|
|
764
|
+
condition: zod.z.enum(eventFilterConditions),
|
|
765
|
+
value: filterScalarSchema.optional()
|
|
766
|
+
}).refine(
|
|
767
|
+
(f) => f.condition === "exists" || f.condition === "not_exists" || f.value !== void 0,
|
|
768
|
+
{ message: "This condition needs a value" }
|
|
769
|
+
)
|
|
770
|
+
).min(1).max(EVENT_FILTER_MAX_CONDITIONS)
|
|
771
|
+
});
|
|
772
|
+
var propertyChangeFilterSchema = zod.z.object({
|
|
773
|
+
from: filterScalarSchema.nullable().optional(),
|
|
774
|
+
to: filterScalarSchema.nullable().optional()
|
|
775
|
+
}).strict();
|
|
591
776
|
|
|
592
777
|
// ../api-contract/src/schemas/sequences.ts
|
|
593
778
|
var mailTypes = ["broadcast", "sequence"];
|
|
594
779
|
var emailActionTypes = ["tag:add", "tag:remove"];
|
|
780
|
+
var triggerTypes = [
|
|
781
|
+
"subscriber:added",
|
|
782
|
+
"tag:added",
|
|
783
|
+
"tag:removed",
|
|
784
|
+
"date:occurred",
|
|
785
|
+
"event:custom",
|
|
786
|
+
"contact:property_changed"
|
|
787
|
+
];
|
|
788
|
+
var reentryModes = ["every_time", "once", "once_per_period"];
|
|
595
789
|
var sequenceEmailSchema = zod.z.object({
|
|
596
790
|
// NOTE: intentionally no `id`/`sequenceId` here — `sequence_emails.id` is
|
|
597
791
|
// internal-only, and its `sequence_id` column holds the *parent*
|
|
@@ -688,8 +882,14 @@ var sequenceSchema = zod.z.object({
|
|
|
688
882
|
title: zod.z.string(),
|
|
689
883
|
status: zod.z.string(),
|
|
690
884
|
deliverySource: deliverySourceSelectionSchema.nullable(),
|
|
691
|
-
triggerType: zod.z.
|
|
885
|
+
triggerType: zod.z.enum(triggerTypes).nullable().optional(),
|
|
692
886
|
triggerData: zod.z.string().nullable().optional(),
|
|
887
|
+
/** Property filter (`event:custom`) or from/to filter
|
|
888
|
+
* (`contact:property_changed`). */
|
|
889
|
+
triggerFilter: zod.z.any().nullable().optional(),
|
|
890
|
+
/** Who can enter again: sequences only. */
|
|
891
|
+
reentry: zod.z.enum(reentryModes).optional(),
|
|
892
|
+
reentryPeriodDays: zod.z.number().int().nullable().optional(),
|
|
693
893
|
filter: zod.z.any().nullable().optional(),
|
|
694
894
|
excludeFilter: zod.z.any().nullable().optional(),
|
|
695
895
|
/** Active enrollments for a sequence or its locked recipient count for a broadcast. */
|
|
@@ -697,6 +897,9 @@ var sequenceSchema = zod.z.object({
|
|
|
697
897
|
emailsOrder: zod.z.array(zod.z.string()),
|
|
698
898
|
entrants: zod.z.array(zod.z.string()),
|
|
699
899
|
report: zod.z.any(),
|
|
900
|
+
/** Whether sends link a hosted web version ("View in browser"). On for
|
|
901
|
+
* new broadcasts, off for new sequences. */
|
|
902
|
+
viewInBrowser: zod.z.boolean(),
|
|
700
903
|
createdAt: zod.z.string().nullable(),
|
|
701
904
|
updatedAt: zod.z.string().nullable(),
|
|
702
905
|
emails: zod.z.array(sequenceEmailSchema),
|
|
@@ -722,8 +925,19 @@ var createSequenceBodySchema = zod.z.object({
|
|
|
722
925
|
});
|
|
723
926
|
var updateSequenceBodySchema = zod.z.object({
|
|
724
927
|
title: zod.z.string().optional(),
|
|
725
|
-
triggerType: zod.z.
|
|
726
|
-
|
|
928
|
+
triggerType: zod.z.enum(triggerTypes).optional().describe(
|
|
929
|
+
"Broadcasts use date:occurred. Sequences: subscriber:added, tag:added, tag:removed, event:custom or contact:property_changed."
|
|
930
|
+
),
|
|
931
|
+
triggerData: zod.z.string().optional().describe(
|
|
932
|
+
"Tag name for tag triggers, event name for event:custom, custom field key for contact:property_changed."
|
|
933
|
+
),
|
|
934
|
+
triggerFilter: zod.z.union([eventPropertyFilterSchema, propertyChangeFilterSchema]).nullable().optional().describe(
|
|
935
|
+
"event:custom: { aggregator, filters: [{ key, condition, value }] }. contact:property_changed: { from?, to? }. null clears it."
|
|
936
|
+
),
|
|
937
|
+
reentry: zod.z.enum(reentryModes).optional().describe(
|
|
938
|
+
"Sequences only. every_time (default), once, or once_per_period with reentryPeriodDays."
|
|
939
|
+
),
|
|
940
|
+
reentryPeriodDays: zod.z.number().int().min(1).max(365).nullable().optional(),
|
|
727
941
|
filter: contactFilterSchema.optional().describe(
|
|
728
942
|
"Audience: subscribed contacts matching this filter; empty means everyone"
|
|
729
943
|
),
|
|
@@ -732,7 +946,10 @@ var updateSequenceBodySchema = zod.z.object({
|
|
|
732
946
|
),
|
|
733
947
|
emailsOrder: zod.z.array(zod.z.string()).optional(),
|
|
734
948
|
/** `null` clears the intent so the default is resolved on next start. */
|
|
735
|
-
deliverySource: deliverySourceSelectionSchema.nullable().optional()
|
|
949
|
+
deliverySource: deliverySourceSelectionSchema.nullable().optional(),
|
|
950
|
+
viewInBrowser: zod.z.boolean().optional().describe(
|
|
951
|
+
'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.'
|
|
952
|
+
)
|
|
736
953
|
});
|
|
737
954
|
var addSequenceEmailBodySchema = zod.z.object({
|
|
738
955
|
templateId: zod.z.string().min(1)
|
|
@@ -754,7 +971,10 @@ var sendSequenceEmailTestBodySchema = zod.z.object({
|
|
|
754
971
|
var sequenceEmailTestResultSchema = zod.z.object({
|
|
755
972
|
sent: zod.z.array(zod.z.string()).describe("Addresses the test was sent to"),
|
|
756
973
|
skipped: zod.z.array(zod.z.object({ email: zod.z.string(), reason: zod.z.enum(["suppressed"]) })).describe("Addresses on the suppression list, which never get mail"),
|
|
757
|
-
lastTestSentAt: zod.z.string().nullable()
|
|
974
|
+
lastTestSentAt: zod.z.string().nullable(),
|
|
975
|
+
/** Event-triggered sequences: `last_event` when `{{ event.* }}` used the
|
|
976
|
+
* last payload received for the event, `none` when there is none yet. */
|
|
977
|
+
eventSample: zod.z.enum(["last_event", "none"]).optional()
|
|
758
978
|
});
|
|
759
979
|
var sequenceStatsSchema = zod.z.object({
|
|
760
980
|
sent: zod.z.number(),
|
|
@@ -1813,6 +2033,14 @@ var contactsContract = c.router(
|
|
|
1813
2033
|
},
|
|
1814
2034
|
summary: "List broadcasts/sequence emails delivered to a contact"
|
|
1815
2035
|
},
|
|
2036
|
+
events: {
|
|
2037
|
+
method: "GET",
|
|
2038
|
+
path: "/contacts/:contactId/events",
|
|
2039
|
+
query: listContactEventsQuerySchema,
|
|
2040
|
+
responses: { 200: paginated(contactEventSchema), 404: errorSchema },
|
|
2041
|
+
summary: "List the custom events received for a contact",
|
|
2042
|
+
description: "Newest first by occurredAt. `enrolledSequences` lists the sequences each event started."
|
|
2043
|
+
},
|
|
1816
2044
|
remove: {
|
|
1817
2045
|
method: "DELETE",
|
|
1818
2046
|
path: "/contacts/:contactId",
|
|
@@ -2029,7 +2257,7 @@ var sequencesContract = c.router(
|
|
|
2029
2257
|
404: errorSchema
|
|
2030
2258
|
},
|
|
2031
2259
|
summary: "Update a broadcast or sequence",
|
|
2032
|
-
description:
|
|
2260
|
+
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\". `viewInBrowser` can be changed at any time; turning it off also takes down the web versions linked from emails already sent."
|
|
2033
2261
|
},
|
|
2034
2262
|
remove: {
|
|
2035
2263
|
method: "DELETE",
|
|
@@ -2180,6 +2408,70 @@ var transactionalContract = c.router(
|
|
|
2180
2408
|
},
|
|
2181
2409
|
{ metadata: { tag: "Transactional Emails" } }
|
|
2182
2410
|
);
|
|
2411
|
+
var eventsContract = c.router(
|
|
2412
|
+
{
|
|
2413
|
+
track: {
|
|
2414
|
+
method: "POST",
|
|
2415
|
+
path: "/events",
|
|
2416
|
+
body: trackEventBodySchema,
|
|
2417
|
+
responses: {
|
|
2418
|
+
202: trackEventResponseSchema,
|
|
2419
|
+
400: errorSchema,
|
|
2420
|
+
402: errorSchema,
|
|
2421
|
+
404: errorSchema,
|
|
2422
|
+
409: errorSchema,
|
|
2423
|
+
422: errorSchema,
|
|
2424
|
+
429: errorSchema
|
|
2425
|
+
},
|
|
2426
|
+
summary: "Track a custom event",
|
|
2427
|
+
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."
|
|
2428
|
+
},
|
|
2429
|
+
definitions: {
|
|
2430
|
+
method: "GET",
|
|
2431
|
+
path: "/events/definitions",
|
|
2432
|
+
responses: { 200: itemsList(eventDefinitionSchema) },
|
|
2433
|
+
summary: "List the team's events"
|
|
2434
|
+
},
|
|
2435
|
+
definition: {
|
|
2436
|
+
method: "GET",
|
|
2437
|
+
path: "/events/definitions/:name",
|
|
2438
|
+
responses: { 200: eventDefinitionDetailSchema, 404: errorSchema },
|
|
2439
|
+
summary: "Get an event, with its last payload"
|
|
2440
|
+
},
|
|
2441
|
+
createDefinition: {
|
|
2442
|
+
method: "POST",
|
|
2443
|
+
path: "/events/definitions",
|
|
2444
|
+
body: createEventDefinitionBodySchema,
|
|
2445
|
+
responses: {
|
|
2446
|
+
201: eventDefinitionDetailSchema,
|
|
2447
|
+
400: errorSchema,
|
|
2448
|
+
409: errorSchema,
|
|
2449
|
+
422: errorSchema
|
|
2450
|
+
},
|
|
2451
|
+
summary: "Register an event before it is sent"
|
|
2452
|
+
},
|
|
2453
|
+
updateDefinition: {
|
|
2454
|
+
method: "PATCH",
|
|
2455
|
+
path: "/events/definitions/:name",
|
|
2456
|
+
body: updateEventDefinitionBodySchema,
|
|
2457
|
+
responses: {
|
|
2458
|
+
200: eventDefinitionDetailSchema,
|
|
2459
|
+
400: errorSchema,
|
|
2460
|
+
404: errorSchema
|
|
2461
|
+
},
|
|
2462
|
+
summary: "Update an event's description or declared properties"
|
|
2463
|
+
},
|
|
2464
|
+
deleteDefinition: {
|
|
2465
|
+
method: "DELETE",
|
|
2466
|
+
path: "/events/definitions/:name",
|
|
2467
|
+
body: c.noBody(),
|
|
2468
|
+
responses: { 204: c.noBody(), 404: errorSchema, 409: errorSchema },
|
|
2469
|
+
summary: "Remove an event from the list",
|
|
2470
|
+
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."
|
|
2471
|
+
}
|
|
2472
|
+
},
|
|
2473
|
+
{ metadata: { tag: "Events" } }
|
|
2474
|
+
);
|
|
2183
2475
|
var espCollectionContract = c.router(
|
|
2184
2476
|
{
|
|
2185
2477
|
list: {
|
|
@@ -3482,6 +3774,7 @@ var contract = c.router({
|
|
|
3482
3774
|
templates: templatesContract,
|
|
3483
3775
|
sequences: sequencesContract,
|
|
3484
3776
|
transactional: transactionalContract,
|
|
3777
|
+
events: eventsContract,
|
|
3485
3778
|
settings: settingsContract,
|
|
3486
3779
|
teams: teamsContract,
|
|
3487
3780
|
organizations: organizationsContract,
|
|
@@ -3580,6 +3873,14 @@ var Contacts = class {
|
|
|
3580
3873
|
params: { contactId: assertId(contactId, "contactId") }
|
|
3581
3874
|
});
|
|
3582
3875
|
}
|
|
3876
|
+
/** Custom events received for this contact, newest first, with the
|
|
3877
|
+
* sequences each one started. */
|
|
3878
|
+
async events(contactId, query = {}) {
|
|
3879
|
+
return this.http.request(routes.events, {
|
|
3880
|
+
params: { contactId: assertId(contactId, "contactId") },
|
|
3881
|
+
query
|
|
3882
|
+
});
|
|
3883
|
+
}
|
|
3583
3884
|
};
|
|
3584
3885
|
|
|
3585
3886
|
// src/resources/delivery-events.ts
|
|
@@ -3631,8 +3932,67 @@ var Emails = class {
|
|
|
3631
3932
|
}
|
|
3632
3933
|
};
|
|
3633
3934
|
|
|
3935
|
+
// src/resources/events.ts
|
|
3936
|
+
var routes4 = contract.events;
|
|
3937
|
+
var EventDefinitions = class {
|
|
3938
|
+
constructor(http) {
|
|
3939
|
+
this.http = http;
|
|
3940
|
+
}
|
|
3941
|
+
async list() {
|
|
3942
|
+
return this.http.request(routes4.definitions);
|
|
3943
|
+
}
|
|
3944
|
+
/** One event with its last received payload. Names are case-sensitive. */
|
|
3945
|
+
async get(name) {
|
|
3946
|
+
return this.http.request(routes4.definition, {
|
|
3947
|
+
params: { name: encodeSegment(name, "name") }
|
|
3948
|
+
});
|
|
3949
|
+
}
|
|
3950
|
+
async create(input) {
|
|
3951
|
+
return this.http.request(routes4.createDefinition, { body: input });
|
|
3952
|
+
}
|
|
3953
|
+
/** `properties` replaces the declared set; observed keys stay. */
|
|
3954
|
+
async update(name, input) {
|
|
3955
|
+
return this.http.request(routes4.updateDefinition, {
|
|
3956
|
+
params: { name: encodeSegment(name, "name") },
|
|
3957
|
+
body: input
|
|
3958
|
+
});
|
|
3959
|
+
}
|
|
3960
|
+
/** Removes the event from the list. Stored events are kept, and the API
|
|
3961
|
+
* refuses (409 `event_definition_in_use`) while a sequence uses it. */
|
|
3962
|
+
async delete(name) {
|
|
3963
|
+
await this.http.request(routes4.deleteDefinition, {
|
|
3964
|
+
params: { name: encodeSegment(name, "name") }
|
|
3965
|
+
});
|
|
3966
|
+
}
|
|
3967
|
+
};
|
|
3968
|
+
var Events = class {
|
|
3969
|
+
constructor(http) {
|
|
3970
|
+
this.http = http;
|
|
3971
|
+
this.definitions = new EventDefinitions(http);
|
|
3972
|
+
}
|
|
3973
|
+
/**
|
|
3974
|
+
* Records an event for one contact (by `email` or `contactId`) and starts
|
|
3975
|
+
* every active sequence listening for `eventName`.
|
|
3976
|
+
*
|
|
3977
|
+
* - An unknown `email` creates the contact, since `createContact`
|
|
3978
|
+
* defaults to `true`. Pass `false` to get a 404 instead. An unknown
|
|
3979
|
+
* `contactId` is always a 404.
|
|
3980
|
+
* - The same `idempotencyKey` within 30 days stores one event and
|
|
3981
|
+
* returns the original with `duplicate: true`. With a key, the SDK
|
|
3982
|
+
* also retries the call on 5xx and network errors.
|
|
3983
|
+
* - `backfill: true` stores history without starting sequences. Events
|
|
3984
|
+
* whose `occurredAt` is more than 72 hours old never start one either.
|
|
3985
|
+
*/
|
|
3986
|
+
async track(input) {
|
|
3987
|
+
return this.http.request(routes4.track, {
|
|
3988
|
+
body: input,
|
|
3989
|
+
retrySafe: !!input.idempotencyKey
|
|
3990
|
+
});
|
|
3991
|
+
}
|
|
3992
|
+
};
|
|
3993
|
+
|
|
3634
3994
|
// src/resources/provisioning.ts
|
|
3635
|
-
var
|
|
3995
|
+
var routes5 = contract.provisioning;
|
|
3636
3996
|
var Provisioning = class {
|
|
3637
3997
|
constructor(http) {
|
|
3638
3998
|
this.http = http;
|
|
@@ -3643,20 +4003,20 @@ var Provisioning = class {
|
|
|
3643
4003
|
* `created: false, apiKey: null`, so it's safe to retry.
|
|
3644
4004
|
*/
|
|
3645
4005
|
async provisionTeam(input) {
|
|
3646
|
-
return this.http.request(
|
|
4006
|
+
return this.http.request(routes5.provisionTeam, {
|
|
3647
4007
|
body: input,
|
|
3648
4008
|
retrySafe: true
|
|
3649
4009
|
});
|
|
3650
4010
|
}
|
|
3651
4011
|
/** `teams:read` */
|
|
3652
4012
|
async getTeam(teamId) {
|
|
3653
|
-
return this.http.request(
|
|
4013
|
+
return this.http.request(routes5.getTeam, {
|
|
3654
4014
|
params: { teamId: assertId(teamId, "teamId") }
|
|
3655
4015
|
});
|
|
3656
4016
|
}
|
|
3657
4017
|
/** `teams:manage` */
|
|
3658
4018
|
async updateTeam(teamId, input) {
|
|
3659
|
-
return this.http.request(
|
|
4019
|
+
return this.http.request(routes5.updateTeam, {
|
|
3660
4020
|
params: { teamId: assertId(teamId, "teamId") },
|
|
3661
4021
|
body: input
|
|
3662
4022
|
});
|
|
@@ -3664,106 +4024,106 @@ var Provisioning = class {
|
|
|
3664
4024
|
/** Replaces the team's integration key (`teams:keys`); keys previously
|
|
3665
4025
|
* issued through provisioning are revoked. */
|
|
3666
4026
|
async createTeamKey(teamId, input) {
|
|
3667
|
-
return this.http.request(
|
|
4027
|
+
return this.http.request(routes5.createTeamKey, {
|
|
3668
4028
|
params: { teamId: assertId(teamId, "teamId") },
|
|
3669
4029
|
body: input
|
|
3670
4030
|
});
|
|
3671
4031
|
}
|
|
3672
4032
|
/** `teams:manage` */
|
|
3673
4033
|
async suspendTeam(teamId) {
|
|
3674
|
-
return this.http.request(
|
|
4034
|
+
return this.http.request(routes5.suspendTeam, {
|
|
3675
4035
|
params: { teamId: assertId(teamId, "teamId") }
|
|
3676
4036
|
});
|
|
3677
4037
|
}
|
|
3678
4038
|
/** `teams:manage` */
|
|
3679
4039
|
async resumeTeam(teamId) {
|
|
3680
|
-
return this.http.request(
|
|
4040
|
+
return this.http.request(routes5.resumeTeam, {
|
|
3681
4041
|
params: { teamId: assertId(teamId, "teamId") }
|
|
3682
4042
|
});
|
|
3683
4043
|
}
|
|
3684
4044
|
/** Soft-deprovisions the team (`teams:manage`). There is no unarchive. */
|
|
3685
4045
|
async archiveTeam(teamId) {
|
|
3686
|
-
await this.http.request(
|
|
4046
|
+
await this.http.request(routes5.archiveTeam, {
|
|
3687
4047
|
params: { teamId: assertId(teamId, "teamId") }
|
|
3688
4048
|
});
|
|
3689
4049
|
}
|
|
3690
4050
|
/** `usage:read` */
|
|
3691
4051
|
async getTeamUsage(teamId) {
|
|
3692
|
-
return this.http.request(
|
|
4052
|
+
return this.http.request(routes5.getTeamUsage, {
|
|
3693
4053
|
params: { teamId: assertId(teamId, "teamId") }
|
|
3694
4054
|
});
|
|
3695
4055
|
}
|
|
3696
4056
|
};
|
|
3697
4057
|
|
|
3698
4058
|
// src/resources/segments.ts
|
|
3699
|
-
var
|
|
4059
|
+
var routes6 = contract.segments;
|
|
3700
4060
|
var Segments = class {
|
|
3701
4061
|
constructor(http) {
|
|
3702
4062
|
this.http = http;
|
|
3703
4063
|
}
|
|
3704
4064
|
async create(input) {
|
|
3705
|
-
return this.http.request(
|
|
4065
|
+
return this.http.request(routes6.create, { body: input });
|
|
3706
4066
|
}
|
|
3707
4067
|
async list() {
|
|
3708
|
-
return this.http.request(
|
|
4068
|
+
return this.http.request(routes6.list);
|
|
3709
4069
|
}
|
|
3710
4070
|
async get(segmentId) {
|
|
3711
|
-
return this.http.request(
|
|
4071
|
+
return this.http.request(routes6.get, {
|
|
3712
4072
|
params: { segmentId: assertId(segmentId, "segmentId") }
|
|
3713
4073
|
});
|
|
3714
4074
|
}
|
|
3715
4075
|
async update(segmentId, input) {
|
|
3716
|
-
return this.http.request(
|
|
4076
|
+
return this.http.request(routes6.update, {
|
|
3717
4077
|
params: { segmentId: assertId(segmentId, "segmentId") },
|
|
3718
4078
|
body: input
|
|
3719
4079
|
});
|
|
3720
4080
|
}
|
|
3721
4081
|
async remove(segmentId) {
|
|
3722
|
-
await this.http.request(
|
|
4082
|
+
await this.http.request(routes6.remove, {
|
|
3723
4083
|
params: { segmentId: assertId(segmentId, "segmentId") }
|
|
3724
4084
|
});
|
|
3725
4085
|
}
|
|
3726
4086
|
};
|
|
3727
4087
|
|
|
3728
4088
|
// src/resources/sequences.ts
|
|
3729
|
-
var
|
|
4089
|
+
var routes7 = contract.sequences;
|
|
3730
4090
|
var Sequences = class {
|
|
3731
4091
|
constructor(http) {
|
|
3732
4092
|
this.http = http;
|
|
3733
4093
|
}
|
|
3734
4094
|
async create(input) {
|
|
3735
|
-
return this.http.request(
|
|
4095
|
+
return this.http.request(routes7.create, { body: input });
|
|
3736
4096
|
}
|
|
3737
4097
|
async list(query) {
|
|
3738
|
-
return this.http.request(
|
|
4098
|
+
return this.http.request(routes7.list, { query });
|
|
3739
4099
|
}
|
|
3740
4100
|
listAll(query) {
|
|
3741
4101
|
return paginate((offset) => this.list({ ...query, offset }));
|
|
3742
4102
|
}
|
|
3743
4103
|
async get(sequenceId) {
|
|
3744
|
-
return this.http.request(
|
|
4104
|
+
return this.http.request(routes7.get, {
|
|
3745
4105
|
params: { sequenceId: assertId(sequenceId, "sequenceId") }
|
|
3746
4106
|
});
|
|
3747
4107
|
}
|
|
3748
4108
|
async update(sequenceId, input) {
|
|
3749
|
-
return this.http.request(
|
|
4109
|
+
return this.http.request(routes7.update, {
|
|
3750
4110
|
params: { sequenceId: assertId(sequenceId, "sequenceId") },
|
|
3751
4111
|
body: input
|
|
3752
4112
|
});
|
|
3753
4113
|
}
|
|
3754
4114
|
async remove(sequenceId) {
|
|
3755
|
-
await this.http.request(
|
|
4115
|
+
await this.http.request(routes7.remove, {
|
|
3756
4116
|
params: { sequenceId: assertId(sequenceId, "sequenceId") }
|
|
3757
4117
|
});
|
|
3758
4118
|
}
|
|
3759
4119
|
async addEmail(sequenceId, input) {
|
|
3760
|
-
return this.http.request(
|
|
4120
|
+
return this.http.request(routes7.addEmail, {
|
|
3761
4121
|
params: { sequenceId: assertId(sequenceId, "sequenceId") },
|
|
3762
4122
|
body: input
|
|
3763
4123
|
});
|
|
3764
4124
|
}
|
|
3765
4125
|
async updateEmail(sequenceId, emailId, input) {
|
|
3766
|
-
return this.http.request(
|
|
4126
|
+
return this.http.request(routes7.updateEmail, {
|
|
3767
4127
|
params: {
|
|
3768
4128
|
sequenceId: assertId(sequenceId, "sequenceId"),
|
|
3769
4129
|
emailId: assertId(emailId, "emailId")
|
|
@@ -3772,7 +4132,7 @@ var Sequences = class {
|
|
|
3772
4132
|
});
|
|
3773
4133
|
}
|
|
3774
4134
|
async removeEmail(sequenceId, emailId) {
|
|
3775
|
-
return this.http.request(
|
|
4135
|
+
return this.http.request(routes7.removeEmail, {
|
|
3776
4136
|
params: {
|
|
3777
4137
|
sequenceId: assertId(sequenceId, "sequenceId"),
|
|
3778
4138
|
emailId: assertId(emailId, "emailId")
|
|
@@ -3782,23 +4142,23 @@ var Sequences = class {
|
|
|
3782
4142
|
/** Sends a broadcast, or activates a sequence so its trigger starts
|
|
3783
4143
|
* enrolling contacts. Requires a mailing address in general settings. */
|
|
3784
4144
|
async start(sequenceId) {
|
|
3785
|
-
return this.http.request(
|
|
4145
|
+
return this.http.request(routes7.start, {
|
|
3786
4146
|
params: { sequenceId: assertId(sequenceId, "sequenceId") }
|
|
3787
4147
|
});
|
|
3788
4148
|
}
|
|
3789
4149
|
async pause(sequenceId) {
|
|
3790
|
-
return this.http.request(
|
|
4150
|
+
return this.http.request(routes7.pause, {
|
|
3791
4151
|
params: { sequenceId: assertId(sequenceId, "sequenceId") }
|
|
3792
4152
|
});
|
|
3793
4153
|
}
|
|
3794
4154
|
async stats(sequenceId) {
|
|
3795
|
-
return this.http.request(
|
|
4155
|
+
return this.http.request(routes7.stats, {
|
|
3796
4156
|
params: { sequenceId: assertId(sequenceId, "sequenceId") }
|
|
3797
4157
|
});
|
|
3798
4158
|
}
|
|
3799
4159
|
/** IDs of contacts that have received this broadcast or sequence. */
|
|
3800
4160
|
async subscribers(sequenceId, query = {}) {
|
|
3801
|
-
return this.http.request(
|
|
4161
|
+
return this.http.request(routes7.subscribers, {
|
|
3802
4162
|
params: { sequenceId: assertId(sequenceId, "sequenceId") },
|
|
3803
4163
|
query
|
|
3804
4164
|
});
|
|
@@ -3806,26 +4166,26 @@ var Sequences = class {
|
|
|
3806
4166
|
};
|
|
3807
4167
|
|
|
3808
4168
|
// src/resources/suppressions.ts
|
|
3809
|
-
var
|
|
4169
|
+
var routes8 = contract.suppressions;
|
|
3810
4170
|
var Suppressions = class {
|
|
3811
4171
|
constructor(http) {
|
|
3812
4172
|
this.http = http;
|
|
3813
4173
|
}
|
|
3814
4174
|
async list(query = {}) {
|
|
3815
|
-
return this.http.request(
|
|
4175
|
+
return this.http.request(routes8.list, { query });
|
|
3816
4176
|
}
|
|
3817
4177
|
listAll(query = {}) {
|
|
3818
4178
|
return paginate((offset) => this.list({ ...query, offset }));
|
|
3819
4179
|
}
|
|
3820
4180
|
async get(suppressionId) {
|
|
3821
|
-
return this.http.request(
|
|
4181
|
+
return this.http.request(routes8.get, {
|
|
3822
4182
|
params: { suppressionId: assertId(suppressionId, "suppressionId") }
|
|
3823
4183
|
});
|
|
3824
4184
|
}
|
|
3825
4185
|
/** Complaint suppressions can't be released (409
|
|
3826
4186
|
* `suppression_not_releasable`). */
|
|
3827
4187
|
async release(suppressionId, input = {}) {
|
|
3828
|
-
return this.http.request(
|
|
4188
|
+
return this.http.request(routes8.release, {
|
|
3829
4189
|
params: { suppressionId: assertId(suppressionId, "suppressionId") },
|
|
3830
4190
|
body: input
|
|
3831
4191
|
});
|
|
@@ -3833,41 +4193,41 @@ var Suppressions = class {
|
|
|
3833
4193
|
};
|
|
3834
4194
|
|
|
3835
4195
|
// src/resources/templates.ts
|
|
3836
|
-
var
|
|
4196
|
+
var routes9 = contract.templates;
|
|
3837
4197
|
var Templates = class {
|
|
3838
4198
|
constructor(http) {
|
|
3839
4199
|
this.http = http;
|
|
3840
4200
|
}
|
|
3841
4201
|
async list(query = {}) {
|
|
3842
|
-
return this.http.request(
|
|
4202
|
+
return this.http.request(routes9.list, { query });
|
|
3843
4203
|
}
|
|
3844
4204
|
/** Built-in starters, shared by every team. Duplicate one into the team
|
|
3845
4205
|
* before using it for transactional sends. */
|
|
3846
4206
|
async listSystem(query = {}) {
|
|
3847
|
-
return this.http.request(
|
|
4207
|
+
return this.http.request(routes9.listSystem, { query });
|
|
3848
4208
|
}
|
|
3849
4209
|
async get(templateId) {
|
|
3850
|
-
return this.http.request(
|
|
4210
|
+
return this.http.request(routes9.get, {
|
|
3851
4211
|
params: { templateId: assertId(templateId, "templateId") }
|
|
3852
4212
|
});
|
|
3853
4213
|
}
|
|
3854
4214
|
async create(input) {
|
|
3855
|
-
return this.http.request(
|
|
4215
|
+
return this.http.request(routes9.create, { body: input });
|
|
3856
4216
|
}
|
|
3857
4217
|
async update(templateId, input) {
|
|
3858
|
-
return this.http.request(
|
|
4218
|
+
return this.http.request(routes9.update, {
|
|
3859
4219
|
params: { templateId: assertId(templateId, "templateId") },
|
|
3860
4220
|
body: input
|
|
3861
4221
|
});
|
|
3862
4222
|
}
|
|
3863
4223
|
async duplicate(templateId, input = {}) {
|
|
3864
|
-
return this.http.request(
|
|
4224
|
+
return this.http.request(routes9.duplicate, {
|
|
3865
4225
|
params: { templateId: assertId(templateId, "templateId") },
|
|
3866
4226
|
body: input
|
|
3867
4227
|
});
|
|
3868
4228
|
}
|
|
3869
4229
|
async remove(templateId) {
|
|
3870
|
-
await this.http.request(
|
|
4230
|
+
await this.http.request(routes9.remove, {
|
|
3871
4231
|
params: { templateId: assertId(templateId, "templateId") }
|
|
3872
4232
|
});
|
|
3873
4233
|
}
|
|
@@ -3931,6 +4291,7 @@ var SendLit = class {
|
|
|
3931
4291
|
this.templates = new Templates(http);
|
|
3932
4292
|
this.sequences = new Sequences(http);
|
|
3933
4293
|
this.emails = new Emails(http);
|
|
4294
|
+
this.events = new Events(http);
|
|
3934
4295
|
this.provisioning = new Provisioning(http);
|
|
3935
4296
|
this.suppressions = new Suppressions(http);
|
|
3936
4297
|
this.deliveryEvents = new DeliveryEvents(http);
|
|
@@ -3941,6 +4302,8 @@ exports.Contacts = Contacts;
|
|
|
3941
4302
|
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
3942
4303
|
exports.DeliveryEvents = DeliveryEvents;
|
|
3943
4304
|
exports.Emails = Emails;
|
|
4305
|
+
exports.EventDefinitions = EventDefinitions;
|
|
4306
|
+
exports.Events = Events;
|
|
3944
4307
|
exports.Provisioning = Provisioning;
|
|
3945
4308
|
exports.Segments = Segments;
|
|
3946
4309
|
exports.SendLit = SendLit;
|