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