@primitivedotdev/sdk 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1338 @@
1
+ import { __export } from "./chunk-Cl8Af3a2.js";
2
+ import { formatAddress } from "./received-email-Q6Cha3wc.js";
3
+
4
+ //#region src/api/generated/core/bodySerializer.gen.ts
5
+ const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
6
+
7
+ //#endregion
8
+ //#region src/api/generated/core/serverSentEvents.gen.ts
9
+ function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url,...options }) {
10
+ let lastEventId;
11
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
12
+ const createStream = async function* () {
13
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
14
+ let attempt = 0;
15
+ const signal = options.signal ?? new AbortController().signal;
16
+ while (true) {
17
+ if (signal.aborted) break;
18
+ attempt++;
19
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
20
+ if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
21
+ try {
22
+ const requestInit = {
23
+ redirect: "follow",
24
+ ...options,
25
+ body: options.serializedBody,
26
+ headers,
27
+ signal
28
+ };
29
+ let request = new Request(url, requestInit);
30
+ if (onRequest) request = await onRequest(url, requestInit);
31
+ const _fetch = options.fetch ?? globalThis.fetch;
32
+ const response = await _fetch(request);
33
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
34
+ if (!response.body) throw new Error("No body in SSE response");
35
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
36
+ let buffer = "";
37
+ const abortHandler = () => {
38
+ try {
39
+ reader.cancel();
40
+ } catch {}
41
+ };
42
+ signal.addEventListener("abort", abortHandler);
43
+ try {
44
+ while (true) {
45
+ const { done, value } = await reader.read();
46
+ if (done) break;
47
+ buffer += value;
48
+ buffer = buffer.replace(/\r\n?/g, "\n");
49
+ const chunks = buffer.split("\n\n");
50
+ buffer = chunks.pop() ?? "";
51
+ for (const chunk of chunks) {
52
+ const lines = chunk.split("\n");
53
+ const dataLines = [];
54
+ let eventName;
55
+ for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
56
+ else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
57
+ else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
58
+ else if (line.startsWith("retry:")) {
59
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
60
+ if (!Number.isNaN(parsed)) retryDelay = parsed;
61
+ }
62
+ let data;
63
+ let parsedJson = false;
64
+ if (dataLines.length) {
65
+ const rawData = dataLines.join("\n");
66
+ try {
67
+ data = JSON.parse(rawData);
68
+ parsedJson = true;
69
+ } catch {
70
+ data = rawData;
71
+ }
72
+ }
73
+ if (parsedJson) {
74
+ if (responseValidator) await responseValidator(data);
75
+ if (responseTransformer) data = await responseTransformer(data);
76
+ }
77
+ onSseEvent?.({
78
+ data,
79
+ event: eventName,
80
+ id: lastEventId,
81
+ retry: retryDelay
82
+ });
83
+ if (dataLines.length) yield data;
84
+ }
85
+ }
86
+ } finally {
87
+ signal.removeEventListener("abort", abortHandler);
88
+ reader.releaseLock();
89
+ }
90
+ break;
91
+ } catch (error) {
92
+ onSseError?.(error);
93
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
94
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
95
+ await sleep(backoff);
96
+ }
97
+ }
98
+ };
99
+ const stream = createStream();
100
+ return { stream };
101
+ }
102
+
103
+ //#endregion
104
+ //#region src/api/generated/core/pathSerializer.gen.ts
105
+ const separatorArrayExplode = (style) => {
106
+ switch (style) {
107
+ case "label": return ".";
108
+ case "matrix": return ";";
109
+ case "simple": return ",";
110
+ default: return "&";
111
+ }
112
+ };
113
+ const separatorArrayNoExplode = (style) => {
114
+ switch (style) {
115
+ case "form": return ",";
116
+ case "pipeDelimited": return "|";
117
+ case "spaceDelimited": return "%20";
118
+ default: return ",";
119
+ }
120
+ };
121
+ const separatorObjectExplode = (style) => {
122
+ switch (style) {
123
+ case "label": return ".";
124
+ case "matrix": return ";";
125
+ case "simple": return ",";
126
+ default: return "&";
127
+ }
128
+ };
129
+ const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
130
+ if (!explode) {
131
+ const joinedValues$1 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
132
+ switch (style) {
133
+ case "label": return `.${joinedValues$1}`;
134
+ case "matrix": return `;${name}=${joinedValues$1}`;
135
+ case "simple": return joinedValues$1;
136
+ default: return `${name}=${joinedValues$1}`;
137
+ }
138
+ }
139
+ const separator = separatorArrayExplode(style);
140
+ const joinedValues = value.map((v) => {
141
+ if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
142
+ return serializePrimitiveParam({
143
+ allowReserved,
144
+ name,
145
+ value: v
146
+ });
147
+ }).join(separator);
148
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
149
+ };
150
+ const serializePrimitiveParam = ({ allowReserved, name, value }) => {
151
+ if (value === void 0 || value === null) return "";
152
+ if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
153
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
154
+ };
155
+ const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
156
+ if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
157
+ if (style !== "deepObject" && !explode) {
158
+ let values = [];
159
+ Object.entries(value).forEach(([key, v]) => {
160
+ values = [
161
+ ...values,
162
+ key,
163
+ allowReserved ? v : encodeURIComponent(v)
164
+ ];
165
+ });
166
+ const joinedValues$1 = values.join(",");
167
+ switch (style) {
168
+ case "form": return `${name}=${joinedValues$1}`;
169
+ case "label": return `.${joinedValues$1}`;
170
+ case "matrix": return `;${name}=${joinedValues$1}`;
171
+ default: return joinedValues$1;
172
+ }
173
+ }
174
+ const separator = separatorObjectExplode(style);
175
+ const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
176
+ allowReserved,
177
+ name: style === "deepObject" ? `${name}[${key}]` : key,
178
+ value: v
179
+ })).join(separator);
180
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
181
+ };
182
+
183
+ //#endregion
184
+ //#region src/api/generated/core/utils.gen.ts
185
+ const PATH_PARAM_RE = /\{[^{}]+\}/g;
186
+ const defaultPathSerializer = ({ path, url: _url }) => {
187
+ let url = _url;
188
+ const matches = _url.match(PATH_PARAM_RE);
189
+ if (matches) for (const match of matches) {
190
+ let explode = false;
191
+ let name = match.substring(1, match.length - 1);
192
+ let style = "simple";
193
+ if (name.endsWith("*")) {
194
+ explode = true;
195
+ name = name.substring(0, name.length - 1);
196
+ }
197
+ if (name.startsWith(".")) {
198
+ name = name.substring(1);
199
+ style = "label";
200
+ } else if (name.startsWith(";")) {
201
+ name = name.substring(1);
202
+ style = "matrix";
203
+ }
204
+ const value = path[name];
205
+ if (value === void 0 || value === null) continue;
206
+ if (Array.isArray(value)) {
207
+ url = url.replace(match, serializeArrayParam({
208
+ explode,
209
+ name,
210
+ style,
211
+ value
212
+ }));
213
+ continue;
214
+ }
215
+ if (typeof value === "object") {
216
+ url = url.replace(match, serializeObjectParam({
217
+ explode,
218
+ name,
219
+ style,
220
+ value,
221
+ valueOnly: true
222
+ }));
223
+ continue;
224
+ }
225
+ if (style === "matrix") {
226
+ url = url.replace(match, `;${serializePrimitiveParam({
227
+ name,
228
+ value
229
+ })}`);
230
+ continue;
231
+ }
232
+ const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
233
+ url = url.replace(match, replaceValue);
234
+ }
235
+ return url;
236
+ };
237
+ const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
238
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
239
+ let url = (baseUrl ?? "") + pathUrl;
240
+ if (path) url = defaultPathSerializer({
241
+ path,
242
+ url
243
+ });
244
+ let search = query ? querySerializer(query) : "";
245
+ if (search.startsWith("?")) search = search.substring(1);
246
+ if (search) url += `?${search}`;
247
+ return url;
248
+ };
249
+ function getValidRequestBody(options) {
250
+ const hasBody = options.body !== void 0;
251
+ const isSerializedBody = hasBody && options.bodySerializer;
252
+ if (isSerializedBody) {
253
+ if ("serializedBody" in options) {
254
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
255
+ return hasSerializedBody ? options.serializedBody : null;
256
+ }
257
+ return options.body !== "" ? options.body : null;
258
+ }
259
+ if (hasBody) return options.body;
260
+ return void 0;
261
+ }
262
+
263
+ //#endregion
264
+ //#region src/api/generated/core/auth.gen.ts
265
+ const getAuthToken = async (auth, callback) => {
266
+ const token = typeof callback === "function" ? await callback(auth) : callback;
267
+ if (!token) return;
268
+ if (auth.scheme === "bearer") return `Bearer ${token}`;
269
+ if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
270
+ return token;
271
+ };
272
+
273
+ //#endregion
274
+ //#region src/api/generated/client/utils.gen.ts
275
+ const createQuerySerializer = ({ parameters = {},...args } = {}) => {
276
+ const querySerializer = (queryParams) => {
277
+ const search = [];
278
+ if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
279
+ const value = queryParams[name];
280
+ if (value === void 0 || value === null) continue;
281
+ const options = parameters[name] || args;
282
+ if (Array.isArray(value)) {
283
+ const serializedArray = serializeArrayParam({
284
+ allowReserved: options.allowReserved,
285
+ explode: true,
286
+ name,
287
+ style: "form",
288
+ value,
289
+ ...options.array
290
+ });
291
+ if (serializedArray) search.push(serializedArray);
292
+ } else if (typeof value === "object") {
293
+ const serializedObject = serializeObjectParam({
294
+ allowReserved: options.allowReserved,
295
+ explode: true,
296
+ name,
297
+ style: "deepObject",
298
+ value,
299
+ ...options.object
300
+ });
301
+ if (serializedObject) search.push(serializedObject);
302
+ } else {
303
+ const serializedPrimitive = serializePrimitiveParam({
304
+ allowReserved: options.allowReserved,
305
+ name,
306
+ value
307
+ });
308
+ if (serializedPrimitive) search.push(serializedPrimitive);
309
+ }
310
+ }
311
+ return search.join("&");
312
+ };
313
+ return querySerializer;
314
+ };
315
+ /**
316
+ * Infers parseAs value from provided Content-Type header.
317
+ */
318
+ const getParseAs = (contentType) => {
319
+ if (!contentType) return "stream";
320
+ const cleanContent = contentType.split(";")[0]?.trim();
321
+ if (!cleanContent) return;
322
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
323
+ if (cleanContent === "multipart/form-data") return "formData";
324
+ if ([
325
+ "application/",
326
+ "audio/",
327
+ "image/",
328
+ "video/"
329
+ ].some((type) => cleanContent.startsWith(type))) return "blob";
330
+ if (cleanContent.startsWith("text/")) return "text";
331
+ return;
332
+ };
333
+ const checkForExistence = (options, name) => {
334
+ if (!name) return false;
335
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
336
+ return false;
337
+ };
338
+ const setAuthParams = async ({ security,...options }) => {
339
+ for (const auth of security) {
340
+ if (checkForExistence(options, auth.name)) continue;
341
+ const token = await getAuthToken(auth, options.auth);
342
+ if (!token) continue;
343
+ const name = auth.name ?? "Authorization";
344
+ switch (auth.in) {
345
+ case "query":
346
+ if (!options.query) options.query = {};
347
+ options.query[name] = token;
348
+ break;
349
+ case "cookie":
350
+ options.headers.append("Cookie", `${name}=${token}`);
351
+ break;
352
+ case "header":
353
+ default:
354
+ options.headers.set(name, token);
355
+ break;
356
+ }
357
+ }
358
+ };
359
+ const buildUrl = (options) => getUrl({
360
+ baseUrl: options.baseUrl,
361
+ path: options.path,
362
+ query: options.query,
363
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
364
+ url: options.url
365
+ });
366
+ const mergeConfigs = (a, b) => {
367
+ const config = {
368
+ ...a,
369
+ ...b
370
+ };
371
+ if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
372
+ config.headers = mergeHeaders(a.headers, b.headers);
373
+ return config;
374
+ };
375
+ const headersEntries = (headers) => {
376
+ const entries = [];
377
+ headers.forEach((value, key) => {
378
+ entries.push([key, value]);
379
+ });
380
+ return entries;
381
+ };
382
+ const mergeHeaders = (...headers) => {
383
+ const mergedHeaders = new Headers();
384
+ for (const header of headers) {
385
+ if (!header) continue;
386
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
387
+ for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
388
+ else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
389
+ else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
390
+ }
391
+ return mergedHeaders;
392
+ };
393
+ var Interceptors = class {
394
+ fns = [];
395
+ clear() {
396
+ this.fns = [];
397
+ }
398
+ eject(id) {
399
+ const index = this.getInterceptorIndex(id);
400
+ if (this.fns[index]) this.fns[index] = null;
401
+ }
402
+ exists(id) {
403
+ const index = this.getInterceptorIndex(id);
404
+ return Boolean(this.fns[index]);
405
+ }
406
+ getInterceptorIndex(id) {
407
+ if (typeof id === "number") return this.fns[id] ? id : -1;
408
+ return this.fns.indexOf(id);
409
+ }
410
+ update(id, fn) {
411
+ const index = this.getInterceptorIndex(id);
412
+ if (this.fns[index]) {
413
+ this.fns[index] = fn;
414
+ return id;
415
+ }
416
+ return false;
417
+ }
418
+ use(fn) {
419
+ this.fns.push(fn);
420
+ return this.fns.length - 1;
421
+ }
422
+ };
423
+ const createInterceptors = () => ({
424
+ error: new Interceptors(),
425
+ request: new Interceptors(),
426
+ response: new Interceptors()
427
+ });
428
+ const defaultQuerySerializer = createQuerySerializer({
429
+ allowReserved: false,
430
+ array: {
431
+ explode: true,
432
+ style: "form"
433
+ },
434
+ object: {
435
+ explode: true,
436
+ style: "deepObject"
437
+ }
438
+ });
439
+ const defaultHeaders = { "Content-Type": "application/json" };
440
+ const createConfig = (override = {}) => ({
441
+ ...jsonBodySerializer,
442
+ headers: defaultHeaders,
443
+ parseAs: "auto",
444
+ querySerializer: defaultQuerySerializer,
445
+ ...override
446
+ });
447
+
448
+ //#endregion
449
+ //#region src/api/generated/client/client.gen.ts
450
+ const createClient = (config = {}) => {
451
+ let _config = mergeConfigs(createConfig(), config);
452
+ const getConfig = () => ({ ..._config });
453
+ const setConfig = (config$1) => {
454
+ _config = mergeConfigs(_config, config$1);
455
+ return getConfig();
456
+ };
457
+ const interceptors = createInterceptors();
458
+ const beforeRequest = async (options) => {
459
+ const opts = {
460
+ ..._config,
461
+ ...options,
462
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
463
+ headers: mergeHeaders(_config.headers, options.headers),
464
+ serializedBody: void 0
465
+ };
466
+ if (opts.security) await setAuthParams({
467
+ ...opts,
468
+ security: opts.security
469
+ });
470
+ if (opts.requestValidator) await opts.requestValidator(opts);
471
+ if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
472
+ if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
473
+ const resolvedOpts = opts;
474
+ const url = buildUrl(resolvedOpts);
475
+ return {
476
+ opts: resolvedOpts,
477
+ url
478
+ };
479
+ };
480
+ const request = async (options) => {
481
+ const { opts, url } = await beforeRequest(options);
482
+ const requestInit = {
483
+ redirect: "follow",
484
+ ...opts,
485
+ body: getValidRequestBody(opts)
486
+ };
487
+ let request$1 = new Request(url, requestInit);
488
+ for (const fn of interceptors.request.fns) if (fn) request$1 = await fn(request$1, opts);
489
+ const _fetch = opts.fetch;
490
+ let response;
491
+ try {
492
+ response = await _fetch(request$1);
493
+ } catch (error$1) {
494
+ let finalError$1 = error$1;
495
+ for (const fn of interceptors.error.fns) if (fn) finalError$1 = await fn(error$1, void 0, request$1, opts);
496
+ finalError$1 = finalError$1 || {};
497
+ if (opts.throwOnError) throw finalError$1;
498
+ return opts.responseStyle === "data" ? void 0 : {
499
+ error: finalError$1,
500
+ request: request$1,
501
+ response: void 0
502
+ };
503
+ }
504
+ for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request$1, opts);
505
+ const result = {
506
+ request: request$1,
507
+ response
508
+ };
509
+ if (response.ok) {
510
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
511
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
512
+ let emptyData;
513
+ switch (parseAs) {
514
+ case "arrayBuffer":
515
+ case "blob":
516
+ case "text":
517
+ emptyData = await response[parseAs]();
518
+ break;
519
+ case "formData":
520
+ emptyData = new FormData();
521
+ break;
522
+ case "stream":
523
+ emptyData = response.body;
524
+ break;
525
+ case "json":
526
+ default:
527
+ emptyData = {};
528
+ break;
529
+ }
530
+ return opts.responseStyle === "data" ? emptyData : {
531
+ data: emptyData,
532
+ ...result
533
+ };
534
+ }
535
+ let data;
536
+ switch (parseAs) {
537
+ case "arrayBuffer":
538
+ case "blob":
539
+ case "formData":
540
+ case "text":
541
+ data = await response[parseAs]();
542
+ break;
543
+ case "json": {
544
+ const text = await response.text();
545
+ data = text ? JSON.parse(text) : {};
546
+ break;
547
+ }
548
+ case "stream": return opts.responseStyle === "data" ? response.body : {
549
+ data: response.body,
550
+ ...result
551
+ };
552
+ }
553
+ if (parseAs === "json") {
554
+ if (opts.responseValidator) await opts.responseValidator(data);
555
+ if (opts.responseTransformer) data = await opts.responseTransformer(data);
556
+ }
557
+ return opts.responseStyle === "data" ? data : {
558
+ data,
559
+ ...result
560
+ };
561
+ }
562
+ const textError = await response.text();
563
+ let jsonError;
564
+ try {
565
+ jsonError = JSON.parse(textError);
566
+ } catch {}
567
+ const error = jsonError ?? textError;
568
+ let finalError = error;
569
+ for (const fn of interceptors.error.fns) if (fn) finalError = await fn(error, response, request$1, opts);
570
+ finalError = finalError || {};
571
+ if (opts.throwOnError) throw finalError;
572
+ return opts.responseStyle === "data" ? void 0 : {
573
+ error: finalError,
574
+ ...result
575
+ };
576
+ };
577
+ const makeMethodFn = (method) => (options) => request({
578
+ ...options,
579
+ method
580
+ });
581
+ const makeSseFn = (method) => async (options) => {
582
+ const { opts, url } = await beforeRequest(options);
583
+ return createSseClient({
584
+ ...opts,
585
+ body: opts.body,
586
+ headers: opts.headers,
587
+ method,
588
+ onRequest: async (url$1, init) => {
589
+ let request$1 = new Request(url$1, init);
590
+ for (const fn of interceptors.request.fns) if (fn) request$1 = await fn(request$1, opts);
591
+ return request$1;
592
+ },
593
+ serializedBody: getValidRequestBody(opts),
594
+ url
595
+ });
596
+ };
597
+ const _buildUrl = (options) => buildUrl({
598
+ ..._config,
599
+ ...options
600
+ });
601
+ return {
602
+ buildUrl: _buildUrl,
603
+ connect: makeMethodFn("CONNECT"),
604
+ delete: makeMethodFn("DELETE"),
605
+ get: makeMethodFn("GET"),
606
+ getConfig,
607
+ head: makeMethodFn("HEAD"),
608
+ interceptors,
609
+ options: makeMethodFn("OPTIONS"),
610
+ patch: makeMethodFn("PATCH"),
611
+ post: makeMethodFn("POST"),
612
+ put: makeMethodFn("PUT"),
613
+ request,
614
+ setConfig,
615
+ sse: {
616
+ connect: makeSseFn("CONNECT"),
617
+ delete: makeSseFn("DELETE"),
618
+ get: makeSseFn("GET"),
619
+ head: makeSseFn("HEAD"),
620
+ options: makeSseFn("OPTIONS"),
621
+ patch: makeSseFn("PATCH"),
622
+ post: makeSseFn("POST"),
623
+ put: makeSseFn("PUT"),
624
+ trace: makeSseFn("TRACE")
625
+ },
626
+ trace: makeMethodFn("TRACE")
627
+ };
628
+ };
629
+
630
+ //#endregion
631
+ //#region src/api/generated/client.gen.ts
632
+ const client$1 = createClient(createConfig({ baseUrl: "https://www.primitive.dev/api/v1" }));
633
+
634
+ //#endregion
635
+ //#region src/api/generated/sdk.gen.ts
636
+ var sdk_gen_exports = {};
637
+ __export(sdk_gen_exports, {
638
+ addDomain: () => addDomain,
639
+ createEndpoint: () => createEndpoint,
640
+ createFilter: () => createFilter,
641
+ deleteDomain: () => deleteDomain,
642
+ deleteEmail: () => deleteEmail,
643
+ deleteEndpoint: () => deleteEndpoint,
644
+ deleteFilter: () => deleteFilter,
645
+ downloadAttachments: () => downloadAttachments,
646
+ downloadRawEmail: () => downloadRawEmail,
647
+ getAccount: () => getAccount,
648
+ getEmail: () => getEmail,
649
+ getStorageStats: () => getStorageStats,
650
+ getWebhookSecret: () => getWebhookSecret,
651
+ listDeliveries: () => listDeliveries,
652
+ listDomains: () => listDomains,
653
+ listEmails: () => listEmails,
654
+ listEndpoints: () => listEndpoints,
655
+ listFilters: () => listFilters,
656
+ replayDelivery: () => replayDelivery,
657
+ replayEmailWebhooks: () => replayEmailWebhooks,
658
+ rotateWebhookSecret: () => rotateWebhookSecret,
659
+ sendEmail: () => sendEmail,
660
+ testEndpoint: () => testEndpoint,
661
+ updateAccount: () => updateAccount,
662
+ updateDomain: () => updateDomain,
663
+ updateEndpoint: () => updateEndpoint,
664
+ updateFilter: () => updateFilter,
665
+ verifyDomain: () => verifyDomain
666
+ });
667
+ /**
668
+ * Get account info
669
+ */
670
+ const getAccount = (options) => (options?.client ?? client$1).get({
671
+ security: [{
672
+ scheme: "bearer",
673
+ type: "http"
674
+ }],
675
+ url: "/account",
676
+ ...options
677
+ });
678
+ /**
679
+ * Update account settings
680
+ */
681
+ const updateAccount = (options) => (options.client ?? client$1).patch({
682
+ security: [{
683
+ scheme: "bearer",
684
+ type: "http"
685
+ }],
686
+ url: "/account",
687
+ ...options,
688
+ headers: {
689
+ "Content-Type": "application/json",
690
+ ...options.headers
691
+ }
692
+ });
693
+ /**
694
+ * Get storage usage
695
+ */
696
+ const getStorageStats = (options) => (options?.client ?? client$1).get({
697
+ security: [{
698
+ scheme: "bearer",
699
+ type: "http"
700
+ }],
701
+ url: "/account/storage",
702
+ ...options
703
+ });
704
+ /**
705
+ * Get webhook signing secret
706
+ *
707
+ * Returns the webhook signing secret for your account. If no secret
708
+ * exists yet, one is generated automatically on first access.
709
+ *
710
+ */
711
+ const getWebhookSecret = (options) => (options?.client ?? client$1).get({
712
+ security: [{
713
+ scheme: "bearer",
714
+ type: "http"
715
+ }],
716
+ url: "/account/webhook-secret",
717
+ ...options
718
+ });
719
+ /**
720
+ * Rotate webhook signing secret
721
+ *
722
+ * Generates a new webhook signing secret, replacing the current one.
723
+ * Rate limited to once per 60 minutes.
724
+ *
725
+ */
726
+ const rotateWebhookSecret = (options) => (options?.client ?? client$1).post({
727
+ security: [{
728
+ scheme: "bearer",
729
+ type: "http"
730
+ }],
731
+ url: "/account/webhook-secret/rotate",
732
+ ...options
733
+ });
734
+ /**
735
+ * List all domains
736
+ *
737
+ * Returns all verified and unverified domains for your organization,
738
+ * sorted by creation date (newest first). Each domain includes a
739
+ * `verified` boolean to distinguish between the two states.
740
+ *
741
+ */
742
+ const listDomains = (options) => (options?.client ?? client$1).get({
743
+ security: [{
744
+ scheme: "bearer",
745
+ type: "http"
746
+ }],
747
+ url: "/domains",
748
+ ...options
749
+ });
750
+ /**
751
+ * Claim a new domain
752
+ *
753
+ * Creates an unverified domain claim. You will receive a
754
+ * `verification_token` to add as a DNS TXT record before
755
+ * calling the verify endpoint.
756
+ *
757
+ */
758
+ const addDomain = (options) => (options.client ?? client$1).post({
759
+ security: [{
760
+ scheme: "bearer",
761
+ type: "http"
762
+ }],
763
+ url: "/domains",
764
+ ...options,
765
+ headers: {
766
+ "Content-Type": "application/json",
767
+ ...options.headers
768
+ }
769
+ });
770
+ /**
771
+ * Delete a domain
772
+ *
773
+ * Deletes a verified or unverified domain claim.
774
+ */
775
+ const deleteDomain = (options) => (options.client ?? client$1).delete({
776
+ security: [{
777
+ scheme: "bearer",
778
+ type: "http"
779
+ }],
780
+ url: "/domains/{id}",
781
+ ...options
782
+ });
783
+ /**
784
+ * Update domain settings
785
+ *
786
+ * Update a verified domain's settings. Only verified domains can be
787
+ * updated. Per-domain spam thresholds require a Pro plan.
788
+ *
789
+ */
790
+ const updateDomain = (options) => (options.client ?? client$1).patch({
791
+ security: [{
792
+ scheme: "bearer",
793
+ type: "http"
794
+ }],
795
+ url: "/domains/{id}",
796
+ ...options,
797
+ headers: {
798
+ "Content-Type": "application/json",
799
+ ...options.headers
800
+ }
801
+ });
802
+ /**
803
+ * Verify domain ownership
804
+ *
805
+ * Checks DNS records (MX and TXT) to verify domain ownership.
806
+ * On success, the domain is promoted from unverified to verified.
807
+ * On failure, returns which checks passed and which failed.
808
+ *
809
+ */
810
+ const verifyDomain = (options) => (options.client ?? client$1).post({
811
+ security: [{
812
+ scheme: "bearer",
813
+ type: "http"
814
+ }],
815
+ url: "/domains/{id}/verify",
816
+ ...options
817
+ });
818
+ /**
819
+ * List emails
820
+ *
821
+ * Returns a paginated list of received emails. Supports filtering by
822
+ * domain, status, date range, and free-text search across subject,
823
+ * sender, and recipient fields.
824
+ *
825
+ */
826
+ const listEmails = (options) => (options?.client ?? client$1).get({
827
+ security: [{
828
+ scheme: "bearer",
829
+ type: "http"
830
+ }],
831
+ url: "/emails",
832
+ ...options
833
+ });
834
+ /**
835
+ * Delete an email
836
+ */
837
+ const deleteEmail = (options) => (options.client ?? client$1).delete({
838
+ security: [{
839
+ scheme: "bearer",
840
+ type: "http"
841
+ }],
842
+ url: "/emails/{id}",
843
+ ...options
844
+ });
845
+ /**
846
+ * Get email details
847
+ */
848
+ const getEmail = (options) => (options.client ?? client$1).get({
849
+ security: [{
850
+ scheme: "bearer",
851
+ type: "http"
852
+ }],
853
+ url: "/emails/{id}",
854
+ ...options
855
+ });
856
+ /**
857
+ * Download raw email
858
+ *
859
+ * Downloads the raw RFC 822 email file (.eml). Authenticates via
860
+ * a signed download token (provided in webhook payloads) or a
861
+ * valid session.
862
+ *
863
+ */
864
+ const downloadRawEmail = (options) => (options.client ?? client$1).get({
865
+ security: [{
866
+ scheme: "bearer",
867
+ type: "http"
868
+ }, {
869
+ in: "query",
870
+ name: "token",
871
+ type: "apiKey"
872
+ }],
873
+ url: "/emails/{id}/raw",
874
+ ...options
875
+ });
876
+ /**
877
+ * Download email attachments
878
+ *
879
+ * Downloads all attachments as a gzip-compressed tar archive.
880
+ * Authenticates via a signed download token (provided in webhook
881
+ * payloads) or a valid session.
882
+ *
883
+ */
884
+ const downloadAttachments = (options) => (options.client ?? client$1).get({
885
+ security: [{
886
+ scheme: "bearer",
887
+ type: "http"
888
+ }, {
889
+ in: "query",
890
+ name: "token",
891
+ type: "apiKey"
892
+ }],
893
+ url: "/emails/{id}/attachments.tar.gz",
894
+ ...options
895
+ });
896
+ /**
897
+ * Replay email webhooks
898
+ *
899
+ * Re-delivers the webhook payload for this email to all active
900
+ * endpoints matching the email's domain. Rate limited per-email
901
+ * (short cooldown between successive replays of the same email)
902
+ * and per-org (burst + sustained windows), sharing an org-wide
903
+ * budget with delivery replays.
904
+ *
905
+ */
906
+ const replayEmailWebhooks = (options) => (options.client ?? client$1).post({
907
+ security: [{
908
+ scheme: "bearer",
909
+ type: "http"
910
+ }],
911
+ url: "/emails/{id}/replay",
912
+ ...options
913
+ });
914
+ /**
915
+ * List webhook endpoints
916
+ *
917
+ * Returns all active (non-deleted) webhook endpoints.
918
+ */
919
+ const listEndpoints = (options) => (options?.client ?? client$1).get({
920
+ security: [{
921
+ scheme: "bearer",
922
+ type: "http"
923
+ }],
924
+ url: "/endpoints",
925
+ ...options
926
+ });
927
+ /**
928
+ * Create a webhook endpoint
929
+ *
930
+ * Creates a new webhook endpoint. If a deactivated endpoint with the
931
+ * same URL and domain exists, it is reactivated instead.
932
+ * Subject to plan limits on the number of active endpoints.
933
+ *
934
+ */
935
+ const createEndpoint = (options) => (options.client ?? client$1).post({
936
+ security: [{
937
+ scheme: "bearer",
938
+ type: "http"
939
+ }],
940
+ url: "/endpoints",
941
+ ...options,
942
+ headers: {
943
+ "Content-Type": "application/json",
944
+ ...options.headers
945
+ }
946
+ });
947
+ /**
948
+ * Delete a webhook endpoint
949
+ *
950
+ * Soft-deletes a webhook endpoint. The endpoint will no longer
951
+ * receive webhook deliveries.
952
+ *
953
+ */
954
+ const deleteEndpoint = (options) => (options.client ?? client$1).delete({
955
+ security: [{
956
+ scheme: "bearer",
957
+ type: "http"
958
+ }],
959
+ url: "/endpoints/{id}",
960
+ ...options
961
+ });
962
+ /**
963
+ * Update a webhook endpoint
964
+ *
965
+ * Updates an active webhook endpoint. If the URL is changed, the old
966
+ * endpoint is deactivated and a new one is created (or an existing
967
+ * deactivated endpoint with the new URL is reactivated).
968
+ *
969
+ */
970
+ const updateEndpoint = (options) => (options.client ?? client$1).patch({
971
+ security: [{
972
+ scheme: "bearer",
973
+ type: "http"
974
+ }],
975
+ url: "/endpoints/{id}",
976
+ ...options,
977
+ headers: {
978
+ "Content-Type": "application/json",
979
+ ...options.headers
980
+ }
981
+ });
982
+ /**
983
+ * Send a test webhook
984
+ *
985
+ * Sends a sample `email.received` event to the endpoint. The request
986
+ * includes SSRF protection (private IP rejection and DNS pinning).
987
+ * Rate limited to 4 per minute and 30 per hour (non-exempt).
988
+ * Successful deliveries and verified-domain endpoints are exempt
989
+ * from the rate limit.
990
+ *
991
+ */
992
+ const testEndpoint = (options) => (options.client ?? client$1).post({
993
+ security: [{
994
+ scheme: "bearer",
995
+ type: "http"
996
+ }],
997
+ url: "/endpoints/{id}/test",
998
+ ...options
999
+ });
1000
+ /**
1001
+ * List filter rules
1002
+ *
1003
+ * Returns all whitelist and blocklist filter rules.
1004
+ */
1005
+ const listFilters = (options) => (options?.client ?? client$1).get({
1006
+ security: [{
1007
+ scheme: "bearer",
1008
+ type: "http"
1009
+ }],
1010
+ url: "/filters",
1011
+ ...options
1012
+ });
1013
+ /**
1014
+ * Create a filter rule
1015
+ *
1016
+ * Creates a new whitelist or blocklist filter. Per-domain filters
1017
+ * require a Pro plan. Patterns are stored as lowercase.
1018
+ *
1019
+ */
1020
+ const createFilter = (options) => (options.client ?? client$1).post({
1021
+ security: [{
1022
+ scheme: "bearer",
1023
+ type: "http"
1024
+ }],
1025
+ url: "/filters",
1026
+ ...options,
1027
+ headers: {
1028
+ "Content-Type": "application/json",
1029
+ ...options.headers
1030
+ }
1031
+ });
1032
+ /**
1033
+ * Delete a filter rule
1034
+ */
1035
+ const deleteFilter = (options) => (options.client ?? client$1).delete({
1036
+ security: [{
1037
+ scheme: "bearer",
1038
+ type: "http"
1039
+ }],
1040
+ url: "/filters/{id}",
1041
+ ...options
1042
+ });
1043
+ /**
1044
+ * Update a filter rule
1045
+ *
1046
+ * Toggle a filter's enabled state.
1047
+ */
1048
+ const updateFilter = (options) => (options.client ?? client$1).patch({
1049
+ security: [{
1050
+ scheme: "bearer",
1051
+ type: "http"
1052
+ }],
1053
+ url: "/filters/{id}",
1054
+ ...options,
1055
+ headers: {
1056
+ "Content-Type": "application/json",
1057
+ ...options.headers
1058
+ }
1059
+ });
1060
+ /**
1061
+ * List webhook deliveries
1062
+ *
1063
+ * Returns a paginated list of webhook delivery attempts. Each delivery
1064
+ * includes a nested `email` object with sender, recipient, and subject.
1065
+ *
1066
+ */
1067
+ const listDeliveries = (options) => (options?.client ?? client$1).get({
1068
+ security: [{
1069
+ scheme: "bearer",
1070
+ type: "http"
1071
+ }],
1072
+ url: "/webhooks/deliveries",
1073
+ ...options
1074
+ });
1075
+ /**
1076
+ * Replay a webhook delivery
1077
+ *
1078
+ * Re-sends the stored webhook payload from a previous delivery attempt.
1079
+ * If the original endpoint is still active, it is targeted. If the
1080
+ * original endpoint was deleted, the oldest active endpoint is used.
1081
+ * Deactivated endpoints cannot be replayed to. Rate limited per-org,
1082
+ * sharing an org-wide budget with email replays.
1083
+ *
1084
+ */
1085
+ const replayDelivery = (options) => (options.client ?? client$1).post({
1086
+ security: [{
1087
+ scheme: "bearer",
1088
+ type: "http"
1089
+ }],
1090
+ url: "/webhooks/deliveries/{id}/replay",
1091
+ ...options
1092
+ });
1093
+ /**
1094
+ * Send outbound email
1095
+ *
1096
+ * Sends an outbound email through Primitive's outbound relay. By default
1097
+ * the request returns once the relay accepts the message for delivery.
1098
+ * Set `wait: true` to wait for the first downstream SMTP delivery outcome.
1099
+ *
1100
+ */
1101
+ const sendEmail = (options) => (options.client ?? client$1).post({
1102
+ security: [{
1103
+ scheme: "bearer",
1104
+ type: "http"
1105
+ }],
1106
+ url: "/send-mail",
1107
+ ...options,
1108
+ headers: {
1109
+ "Content-Type": "application/json",
1110
+ ...options.headers
1111
+ }
1112
+ });
1113
+
1114
+ //#endregion
1115
+ //#region src/api/index.ts
1116
+ const DEFAULT_BASE_URL = "https://www.primitive.dev/api/v1";
1117
+ const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1118
+ const MAX_THREAD_REFERENCES = 100;
1119
+ const MAX_THREAD_HEADER_BYTES = 8 * 1024;
1120
+ const MAX_FROM_HEADER_LENGTH = 998;
1121
+ const MAX_TO_HEADER_LENGTH = 320;
1122
+ function createDefaultAuth(apiKey) {
1123
+ return (security) => {
1124
+ if (security.type === "http" && security.scheme === "bearer") return apiKey;
1125
+ return void 0;
1126
+ };
1127
+ }
1128
+ function validateAddressHeader(field, value) {
1129
+ const trimmed = value.trim();
1130
+ const maxLength = field === "from" ? MAX_FROM_HEADER_LENGTH : MAX_TO_HEADER_LENGTH;
1131
+ if (trimmed.length < 3) throw new TypeError(`${field} must be at least 3 characters`);
1132
+ if (trimmed.length > maxLength) throw new TypeError(`${field} must be at most ${maxLength} characters`);
1133
+ }
1134
+ function validateEmailAddress(field, value) {
1135
+ if (!EMAIL_REGEX.test(value) && !/^.+<[^\s@]+@[^\s@]+\.[^\s@]+>$/.test(value)) throw new TypeError(`${field} must be a valid email address`);
1136
+ }
1137
+ function validateThreadHeaderValue(field, value) {
1138
+ if (value.trim().length === 0) throw new TypeError(`${field} must be a non-empty string`);
1139
+ if ([...value].some((char) => {
1140
+ const code = char.charCodeAt(0);
1141
+ return code <= 31 || code === 127;
1142
+ })) throw new TypeError(`${field} must not contain control characters`);
1143
+ if (value.length > 998) throw new TypeError(`${field} must be at most 998 characters`);
1144
+ }
1145
+ function validateSendInput(input) {
1146
+ validateAddressHeader("from", input.from);
1147
+ validateAddressHeader("to", input.to);
1148
+ validateEmailAddress("to", input.to);
1149
+ if (input.subject.trim().length === 0) throw new TypeError("subject must be a non-empty string");
1150
+ if (!input.bodyText && !input.bodyHtml) throw new TypeError("one of bodyText or bodyHtml is required");
1151
+ if (input.thread?.inReplyTo) validateThreadHeaderValue("thread.inReplyTo", input.thread.inReplyTo);
1152
+ if (input.thread?.references) {
1153
+ if (input.thread.references.length > MAX_THREAD_REFERENCES) throw new TypeError(`thread.references must contain at most ${MAX_THREAD_REFERENCES} values`);
1154
+ for (const [index, reference] of input.thread.references.entries()) validateThreadHeaderValue(`thread.references[${index}]`, reference);
1155
+ if (input.thread.references.join(" ").length > MAX_THREAD_HEADER_BYTES) throw new TypeError(`thread.references header must be at most ${MAX_THREAD_HEADER_BYTES} characters`);
1156
+ }
1157
+ if (input.waitTimeoutMs !== void 0) {
1158
+ if (!Number.isInteger(input.waitTimeoutMs)) throw new TypeError("waitTimeoutMs must be an integer");
1159
+ if (input.waitTimeoutMs < 1e3 || input.waitTimeoutMs > 3e4) throw new TypeError("waitTimeoutMs must be between 1000 and 30000");
1160
+ }
1161
+ }
1162
+ function validateForwardInput(input) {
1163
+ validateEmailAddress("to", input.to);
1164
+ if (input.subject !== void 0 && input.subject.trim().length === 0) throw new TypeError("subject must be a non-empty string");
1165
+ }
1166
+ function parseApiErrorPayload(payload) {
1167
+ const fallback = {
1168
+ message: "Primitive API request failed",
1169
+ code: void 0,
1170
+ gates: void 0,
1171
+ requestId: void 0,
1172
+ details: void 0
1173
+ };
1174
+ if (!payload || typeof payload !== "object") return fallback;
1175
+ if ("error" in payload && payload.error && typeof payload.error === "object") {
1176
+ const err = payload.error;
1177
+ return {
1178
+ message: typeof err.message === "string" ? err.message : fallback.message,
1179
+ code: typeof err.code === "string" ? err.code : void 0,
1180
+ gates: Array.isArray(err.gates) ? err.gates : void 0,
1181
+ requestId: typeof err.request_id === "string" ? err.request_id : void 0,
1182
+ details: err.details && typeof err.details === "object" ? err.details : void 0
1183
+ };
1184
+ }
1185
+ if ("message" in payload && typeof payload.message === "string") return {
1186
+ ...fallback,
1187
+ message: payload.message
1188
+ };
1189
+ return fallback;
1190
+ }
1191
+ var PrimitiveApiError = class extends Error {
1192
+ status;
1193
+ code;
1194
+ gates;
1195
+ requestId;
1196
+ retryAfter;
1197
+ details;
1198
+ payload;
1199
+ constructor(message, options) {
1200
+ super(message);
1201
+ this.name = "PrimitiveApiError";
1202
+ this.payload = options.payload;
1203
+ this.status = options.status;
1204
+ this.code = options.code;
1205
+ this.gates = options.gates;
1206
+ this.requestId = options.requestId;
1207
+ this.retryAfter = options.retryAfter;
1208
+ this.details = options.details;
1209
+ }
1210
+ };
1211
+ function parseRetryAfterHeader(response) {
1212
+ if (!response) return void 0;
1213
+ const raw = response.headers.get("retry-after");
1214
+ if (!raw) return void 0;
1215
+ const seconds = Number.parseInt(raw, 10);
1216
+ return Number.isFinite(seconds) ? seconds : void 0;
1217
+ }
1218
+ var PrimitiveApiClient = class {
1219
+ client;
1220
+ constructor(options = {}) {
1221
+ const { apiKey, auth, baseUrl = DEFAULT_BASE_URL,...config } = options;
1222
+ this.client = createClient(createConfig({
1223
+ ...config,
1224
+ auth: auth ?? createDefaultAuth(apiKey),
1225
+ baseUrl
1226
+ }));
1227
+ }
1228
+ getConfig() {
1229
+ return this.client.getConfig();
1230
+ }
1231
+ setConfig(config) {
1232
+ return this.client.setConfig(config);
1233
+ }
1234
+ };
1235
+ var PrimitiveClient = class extends PrimitiveApiClient {
1236
+ async send(input) {
1237
+ validateSendInput(input);
1238
+ const body = {
1239
+ from: input.from,
1240
+ to: input.to,
1241
+ subject: input.subject,
1242
+ ...input.bodyText !== void 0 ? { body_text: input.bodyText } : {},
1243
+ ...input.bodyHtml !== void 0 ? { body_html: input.bodyHtml } : {},
1244
+ ...input.thread?.inReplyTo ? { in_reply_to: input.thread.inReplyTo } : {},
1245
+ ...input.thread?.references?.length ? { references: input.thread.references } : {},
1246
+ ...input.wait !== void 0 ? { wait: input.wait } : {},
1247
+ ...input.waitTimeoutMs !== void 0 ? { wait_timeout_ms: input.waitTimeoutMs } : {}
1248
+ };
1249
+ const result = await sendEmail({
1250
+ body,
1251
+ ...input.idempotencyKey ? { headers: { "Idempotency-Key": input.idempotencyKey } } : {},
1252
+ client: this.client,
1253
+ responseStyle: "fields"
1254
+ });
1255
+ const response = result.response;
1256
+ if (result.error) {
1257
+ const parsed = parseApiErrorPayload(result.error);
1258
+ throw new PrimitiveApiError(parsed.message, {
1259
+ payload: result.error,
1260
+ status: response?.status,
1261
+ code: parsed.code,
1262
+ gates: parsed.gates,
1263
+ requestId: parsed.requestId,
1264
+ retryAfter: parseRetryAfterHeader(response),
1265
+ details: parsed.details
1266
+ });
1267
+ }
1268
+ if (!result.data?.data) throw new PrimitiveApiError("Primitive API returned no send result", {
1269
+ payload: result,
1270
+ status: response?.status
1271
+ });
1272
+ return mapSendResult(result.data.data);
1273
+ }
1274
+ async reply(email, input) {
1275
+ const resolved = typeof input === "string" ? { text: input } : input;
1276
+ return this.send({
1277
+ from: resolved.from ?? email.receivedBy,
1278
+ to: email.replyTarget.address,
1279
+ subject: resolved.subject ?? email.replySubject,
1280
+ bodyText: resolved.text,
1281
+ thread: {
1282
+ ...email.thread.messageId ? { inReplyTo: email.thread.messageId } : {},
1283
+ references: email.thread.messageId ? [...email.thread.references, email.thread.messageId] : email.thread.references
1284
+ }
1285
+ });
1286
+ }
1287
+ async forward(email, input) {
1288
+ validateForwardInput(input);
1289
+ return this.send({
1290
+ from: input.from ?? email.receivedBy,
1291
+ to: input.to,
1292
+ subject: input.subject ?? email.forwardSubject,
1293
+ bodyText: buildForwardText(email, input.bodyText)
1294
+ });
1295
+ }
1296
+ };
1297
+ function buildForwardText(email, intro) {
1298
+ const lines = [
1299
+ ...intro ? [intro.trim(), ""] : [],
1300
+ "---------- Forwarded message ----------",
1301
+ `From: ${formatAddress(email.sender)}`,
1302
+ `To: ${email.raw.email.headers.to}`,
1303
+ `Subject: ${email.subject ?? ""}`,
1304
+ ...email.raw.email.headers.date ? [`Date: ${email.raw.email.headers.date}`] : [],
1305
+ ...email.thread.messageId ? [`Message-ID: ${email.thread.messageId}`] : [],
1306
+ "",
1307
+ email.text ?? ""
1308
+ ];
1309
+ return lines.join("\n").trimEnd();
1310
+ }
1311
+ function mapSendResult(result) {
1312
+ return {
1313
+ id: result.id,
1314
+ status: result.status,
1315
+ queueId: result.queue_id,
1316
+ accepted: result.accepted,
1317
+ rejected: result.rejected,
1318
+ clientIdempotencyKey: result.client_idempotency_key,
1319
+ requestId: result.request_id,
1320
+ contentHash: result.content_hash,
1321
+ ...result.delivery_status !== void 0 ? { deliveryStatus: result.delivery_status } : {},
1322
+ ...result.smtp_response_code !== void 0 ? { smtpResponseCode: result.smtp_response_code } : {},
1323
+ ...result.smtp_response_text !== void 0 ? { smtpResponseText: result.smtp_response_text } : {}
1324
+ };
1325
+ }
1326
+ function createPrimitiveApiClient(options = {}) {
1327
+ return new PrimitiveApiClient(options);
1328
+ }
1329
+ function createPrimitiveClient(options = {}) {
1330
+ return new PrimitiveClient(options);
1331
+ }
1332
+ function client(options = {}) {
1333
+ return new PrimitiveClient(options);
1334
+ }
1335
+ const operations = sdk_gen_exports;
1336
+
1337
+ //#endregion
1338
+ export { DEFAULT_BASE_URL, PrimitiveApiClient, PrimitiveApiError, PrimitiveClient, addDomain, client, createEndpoint, createFilter, createPrimitiveApiClient, createPrimitiveClient, deleteDomain, deleteEmail, deleteEndpoint, deleteFilter, downloadAttachments, downloadRawEmail, getAccount, getEmail, getStorageStats, getWebhookSecret, listDeliveries, listDomains, listEmails, listEndpoints, listFilters, operations, replayDelivery, replayEmailWebhooks, rotateWebhookSecret, sendEmail, testEndpoint, updateAccount, updateDomain, updateEndpoint, updateFilter, verifyDomain };