smartletter 0.0.0-stage → 1.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/dist/index.cjs ADDED
@@ -0,0 +1,2925 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ Resend: () => Smartletter,
34
+ Smartletter: () => Smartletter,
35
+ WebhookVerificationError: () => WebhookVerificationError
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/case.ts
40
+ function toWire(value, tree) {
41
+ if (!tree || value === null || typeof value !== "object") return value;
42
+ if (Array.isArray(value)) return value.map((item) => toWire(item, tree));
43
+ if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return value;
44
+ const out = {};
45
+ for (const [key, v] of Object.entries(value)) {
46
+ const node = tree[key];
47
+ out[node ? node.wire : key] = node ? toWire(v, node.items ?? node.props) : v;
48
+ }
49
+ return out;
50
+ }
51
+
52
+ // src/client.ts
53
+ var UNRESOLVED_MESSAGE = "Unable to fetch data. The request could not be resolved.";
54
+ var DEFAULT_BASE_URL = "https://api.smartletter.ai";
55
+ function env(name) {
56
+ return typeof process !== "undefined" ? process.env?.[name] || void 0 : void 0;
57
+ }
58
+ function camel(snake) {
59
+ return snake.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
60
+ }
61
+ function applicationError(message, statusCode) {
62
+ return { name: "application_error", message, statusCode };
63
+ }
64
+ function isEmptyObject(value) {
65
+ return !!value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
66
+ }
67
+ var Client = class {
68
+ key;
69
+ baseUrl;
70
+ userAgent;
71
+ constructor(key, options = {}) {
72
+ const resendKey = env("RESEND_API_KEY");
73
+ const resolved = key || env("SMARTLETTER_API_KEY") || (resendKey && /^(sl_|re_)/.test(resendKey) ? resendKey : void 0);
74
+ if (!resolved) {
75
+ throw new Error(
76
+ 'Missing API key. Pass it to the constructor `new Smartletter("sl_123")` or set SMARTLETTER_API_KEY.'
77
+ );
78
+ }
79
+ if (resolved.startsWith("re_")) {
80
+ throw new Error("This is a Resend key (re_\u2026). Create a Smartletter key (sl_\u2026) in Settings \u2192 API keys.");
81
+ }
82
+ this.key = resolved;
83
+ this.baseUrl = (options.baseUrl || env("SMARTLETTER_BASE_URL") || DEFAULT_BASE_URL).replace(/\/+$/, "");
84
+ this.userAgent = options.userAgent ?? `smartletter-node/${"1.1.0"}`;
85
+ }
86
+ async call(op, args, options = {}) {
87
+ const headers = new Headers(options.headers);
88
+ headers.set("Authorization", `Bearer ${this.key}`);
89
+ headers.set("User-Agent", this.userAgent);
90
+ if (options.idempotencyKey) headers.set("Idempotency-Key", options.idempotencyKey);
91
+ let path = op.path;
92
+ let rest = args;
93
+ if (op.pathParams.length > 0 && !Array.isArray(args)) {
94
+ const copy = { ...args ?? {} };
95
+ for (const wireName of op.pathParams) {
96
+ const name = camel(wireName);
97
+ const value = copy[name] ?? copy[wireName];
98
+ if (value === void 0 || value === null || value === "") {
99
+ return {
100
+ data: null,
101
+ error: { name: "missing_required_field", statusCode: null, message: `Missing \`${name}\` field.` },
102
+ headers: null
103
+ };
104
+ }
105
+ path = path.replace(`{${wireName}}`, encodeURIComponent(String(value)));
106
+ delete copy[name];
107
+ delete copy[wireName];
108
+ }
109
+ rest = copy;
110
+ }
111
+ let url = `${this.baseUrl}${path}`;
112
+ let body;
113
+ if (op.rawBody) {
114
+ body = args;
115
+ if (body !== void 0) headers.set("Content-Type", "application/octet-stream");
116
+ } else if (op.method === "GET") {
117
+ const params = new URLSearchParams();
118
+ const wire = toWire(rest, op.query) ?? {};
119
+ for (const [k, v] of Object.entries(wire)) {
120
+ if (v === void 0 || v === null) continue;
121
+ params.set(k, String(v));
122
+ }
123
+ const qs = params.toString();
124
+ if (qs) url += `?${qs}`;
125
+ } else if (rest !== void 0 && !isEmptyObject(rest)) {
126
+ const wire = op.bodyIsArray && Array.isArray(rest) ? rest.map((i) => toWire(i, op.body)) : toWire(rest, op.body);
127
+ body = JSON.stringify(wire);
128
+ headers.set("Content-Type", "application/json");
129
+ }
130
+ const unresolved = {
131
+ data: null,
132
+ error: applicationError(UNRESOLVED_MESSAGE, null),
133
+ headers: null
134
+ };
135
+ let response;
136
+ try {
137
+ response = await fetch(url, { method: op.method, headers, body, signal: options.signal });
138
+ } catch {
139
+ return unresolved;
140
+ }
141
+ const responseHeaders = Object.fromEntries(response.headers);
142
+ if (!response.ok) {
143
+ let text2;
144
+ try {
145
+ text2 = await response.text();
146
+ } catch (err) {
147
+ const message = err instanceof Error ? err.message : response.statusText;
148
+ return { data: null, error: applicationError(message, response.status), headers: responseHeaders };
149
+ }
150
+ try {
151
+ return { data: null, error: JSON.parse(text2), headers: responseHeaders };
152
+ } catch {
153
+ return {
154
+ data: null,
155
+ error: applicationError(
156
+ "Internal server error. We are unable to process your request right now, please try again later.",
157
+ response.status
158
+ ),
159
+ headers: responseHeaders
160
+ };
161
+ }
162
+ }
163
+ let text;
164
+ try {
165
+ text = await response.text();
166
+ } catch {
167
+ return unresolved;
168
+ }
169
+ if (op.responseType === "text") return { data: text, error: null, headers: responseHeaders };
170
+ if (text === "") return { data: null, error: null, headers: responseHeaders };
171
+ try {
172
+ return { data: JSON.parse(text), error: null, headers: responseHeaders };
173
+ } catch {
174
+ return { ...unresolved, headers: responseHeaders };
175
+ }
176
+ }
177
+ };
178
+
179
+ // src/generated/operations.ts
180
+ var OPERATIONS = {
181
+ "emails.send": {
182
+ id: "emails.send",
183
+ method: "POST",
184
+ path: "/emails",
185
+ pathParams: [],
186
+ paginated: false,
187
+ idempotent: true,
188
+ body: {
189
+ from: {
190
+ wire: "from"
191
+ },
192
+ to: {
193
+ wire: "to"
194
+ },
195
+ subject: {
196
+ wire: "subject"
197
+ },
198
+ template: {
199
+ wire: "template",
200
+ props: {
201
+ id: {
202
+ wire: "id"
203
+ },
204
+ variables: {
205
+ wire: "variables"
206
+ }
207
+ }
208
+ },
209
+ html: {
210
+ wire: "html"
211
+ },
212
+ text: {
213
+ wire: "text"
214
+ },
215
+ cc: {
216
+ wire: "cc"
217
+ },
218
+ bcc: {
219
+ wire: "bcc"
220
+ },
221
+ replyTo: {
222
+ wire: "reply_to"
223
+ },
224
+ headers: {
225
+ wire: "headers"
226
+ },
227
+ tags: {
228
+ wire: "tags",
229
+ items: {
230
+ name: {
231
+ wire: "name"
232
+ },
233
+ value: {
234
+ wire: "value"
235
+ }
236
+ }
237
+ },
238
+ scheduledAt: {
239
+ wire: "scheduled_at"
240
+ },
241
+ topicId: {
242
+ wire: "topic_id"
243
+ },
244
+ attachments: {
245
+ wire: "attachments",
246
+ items: {
247
+ content: {
248
+ wire: "content"
249
+ },
250
+ path: {
251
+ wire: "path"
252
+ },
253
+ filename: {
254
+ wire: "filename"
255
+ },
256
+ contentType: {
257
+ wire: "content_type"
258
+ },
259
+ contentId: {
260
+ wire: "content_id"
261
+ }
262
+ }
263
+ }
264
+ }
265
+ },
266
+ "batch.send": {
267
+ id: "batch.send",
268
+ method: "POST",
269
+ path: "/emails/batch",
270
+ pathParams: [],
271
+ paginated: false,
272
+ idempotent: true,
273
+ bodyIsArray: true,
274
+ body: {
275
+ from: {
276
+ wire: "from"
277
+ },
278
+ to: {
279
+ wire: "to"
280
+ },
281
+ subject: {
282
+ wire: "subject"
283
+ },
284
+ template: {
285
+ wire: "template",
286
+ props: {
287
+ id: {
288
+ wire: "id"
289
+ },
290
+ variables: {
291
+ wire: "variables"
292
+ }
293
+ }
294
+ },
295
+ html: {
296
+ wire: "html"
297
+ },
298
+ text: {
299
+ wire: "text"
300
+ },
301
+ cc: {
302
+ wire: "cc"
303
+ },
304
+ bcc: {
305
+ wire: "bcc"
306
+ },
307
+ replyTo: {
308
+ wire: "reply_to"
309
+ },
310
+ headers: {
311
+ wire: "headers"
312
+ },
313
+ tags: {
314
+ wire: "tags",
315
+ items: {
316
+ name: {
317
+ wire: "name"
318
+ },
319
+ value: {
320
+ wire: "value"
321
+ }
322
+ }
323
+ },
324
+ scheduledAt: {
325
+ wire: "scheduled_at"
326
+ },
327
+ topicId: {
328
+ wire: "topic_id"
329
+ }
330
+ }
331
+ },
332
+ "emails.list": {
333
+ id: "emails.list",
334
+ method: "GET",
335
+ path: "/emails",
336
+ pathParams: [],
337
+ paginated: true,
338
+ idempotent: false,
339
+ query: {
340
+ limit: {
341
+ wire: "limit"
342
+ },
343
+ after: {
344
+ wire: "after"
345
+ },
346
+ before: {
347
+ wire: "before"
348
+ }
349
+ }
350
+ },
351
+ "emails.get": {
352
+ id: "emails.get",
353
+ method: "GET",
354
+ path: "/emails/{id}",
355
+ pathParams: ["id"],
356
+ paginated: false,
357
+ idempotent: false
358
+ },
359
+ "emails.update": {
360
+ id: "emails.update",
361
+ method: "PATCH",
362
+ path: "/emails/{id}",
363
+ pathParams: ["id"],
364
+ paginated: false,
365
+ idempotent: false,
366
+ body: {
367
+ scheduledAt: {
368
+ wire: "scheduled_at"
369
+ }
370
+ }
371
+ },
372
+ "emails.cancel": {
373
+ id: "emails.cancel",
374
+ method: "POST",
375
+ path: "/emails/{id}/cancel",
376
+ pathParams: ["id"],
377
+ paginated: false,
378
+ idempotent: false
379
+ },
380
+ "templates.create": {
381
+ id: "templates.create",
382
+ method: "POST",
383
+ path: "/templates",
384
+ pathParams: [],
385
+ paginated: false,
386
+ idempotent: false,
387
+ body: {
388
+ name: {
389
+ wire: "name"
390
+ },
391
+ alias: {
392
+ wire: "alias"
393
+ },
394
+ from: {
395
+ wire: "from"
396
+ },
397
+ subject: {
398
+ wire: "subject"
399
+ },
400
+ replyTo: {
401
+ wire: "reply_to"
402
+ },
403
+ html: {
404
+ wire: "html"
405
+ },
406
+ text: {
407
+ wire: "text"
408
+ },
409
+ variables: {
410
+ wire: "variables",
411
+ items: {
412
+ key: {
413
+ wire: "key"
414
+ },
415
+ type: {
416
+ wire: "type"
417
+ },
418
+ fallbackValue: {
419
+ wire: "fallback_value"
420
+ },
421
+ required: {
422
+ wire: "required"
423
+ }
424
+ }
425
+ }
426
+ }
427
+ },
428
+ "templates.list": {
429
+ id: "templates.list",
430
+ method: "GET",
431
+ path: "/templates",
432
+ pathParams: [],
433
+ paginated: true,
434
+ idempotent: false,
435
+ query: {
436
+ limit: {
437
+ wire: "limit"
438
+ },
439
+ after: {
440
+ wire: "after"
441
+ },
442
+ before: {
443
+ wire: "before"
444
+ }
445
+ }
446
+ },
447
+ "templates.get": {
448
+ id: "templates.get",
449
+ method: "GET",
450
+ path: "/templates/{id}",
451
+ pathParams: ["id"],
452
+ paginated: false,
453
+ idempotent: false
454
+ },
455
+ "templates.update": {
456
+ id: "templates.update",
457
+ method: "PATCH",
458
+ path: "/templates/{id}",
459
+ pathParams: ["id"],
460
+ paginated: false,
461
+ idempotent: false,
462
+ body: {
463
+ name: {
464
+ wire: "name"
465
+ },
466
+ alias: {
467
+ wire: "alias"
468
+ },
469
+ from: {
470
+ wire: "from"
471
+ },
472
+ subject: {
473
+ wire: "subject"
474
+ },
475
+ replyTo: {
476
+ wire: "reply_to"
477
+ },
478
+ html: {
479
+ wire: "html"
480
+ },
481
+ text: {
482
+ wire: "text"
483
+ },
484
+ variables: {
485
+ wire: "variables",
486
+ items: {
487
+ key: {
488
+ wire: "key"
489
+ },
490
+ type: {
491
+ wire: "type"
492
+ },
493
+ fallbackValue: {
494
+ wire: "fallback_value"
495
+ },
496
+ required: {
497
+ wire: "required"
498
+ }
499
+ }
500
+ },
501
+ changeNote: {
502
+ wire: "change_note"
503
+ }
504
+ }
505
+ },
506
+ "templates.remove": {
507
+ id: "templates.remove",
508
+ method: "DELETE",
509
+ path: "/templates/{id}",
510
+ pathParams: ["id"],
511
+ paginated: false,
512
+ idempotent: false
513
+ },
514
+ "templates.publish": {
515
+ id: "templates.publish",
516
+ method: "POST",
517
+ path: "/templates/{id}/publish",
518
+ pathParams: ["id"],
519
+ paginated: false,
520
+ idempotent: false,
521
+ body: {
522
+ versionId: {
523
+ wire: "version_id"
524
+ }
525
+ }
526
+ },
527
+ "templates.duplicate": {
528
+ id: "templates.duplicate",
529
+ method: "POST",
530
+ path: "/templates/{id}/duplicate",
531
+ pathParams: ["id"],
532
+ paginated: false,
533
+ idempotent: false
534
+ },
535
+ "templates.versions": {
536
+ id: "templates.versions",
537
+ method: "GET",
538
+ path: "/templates/{id}/versions",
539
+ pathParams: ["id"],
540
+ paginated: true,
541
+ idempotent: false,
542
+ query: {
543
+ limit: {
544
+ wire: "limit"
545
+ },
546
+ after: {
547
+ wire: "after"
548
+ },
549
+ before: {
550
+ wire: "before"
551
+ }
552
+ }
553
+ },
554
+ "newsletters.list": {
555
+ id: "newsletters.list",
556
+ method: "GET",
557
+ path: "/newsletters",
558
+ pathParams: [],
559
+ paginated: true,
560
+ idempotent: false,
561
+ query: {
562
+ limit: {
563
+ wire: "limit"
564
+ },
565
+ after: {
566
+ wire: "after"
567
+ },
568
+ before: {
569
+ wire: "before"
570
+ },
571
+ status: {
572
+ wire: "status"
573
+ }
574
+ }
575
+ },
576
+ "newsletters.create": {
577
+ id: "newsletters.create",
578
+ method: "POST",
579
+ path: "/newsletters",
580
+ pathParams: [],
581
+ paginated: false,
582
+ idempotent: false,
583
+ body: {
584
+ subject: {
585
+ wire: "subject"
586
+ },
587
+ preheader: {
588
+ wire: "preheader"
589
+ },
590
+ segmentId: {
591
+ wire: "segment_id"
592
+ },
593
+ topicId: {
594
+ wire: "topic_id"
595
+ },
596
+ markdown: {
597
+ wire: "markdown"
598
+ },
599
+ html: {
600
+ wire: "html"
601
+ },
602
+ blocks: {
603
+ wire: "blocks",
604
+ items: {
605
+ kind: {
606
+ wire: "kind"
607
+ },
608
+ level: {
609
+ wire: "level"
610
+ },
611
+ text: {
612
+ wire: "text"
613
+ },
614
+ ordered: {
615
+ wire: "ordered"
616
+ },
617
+ items: {
618
+ wire: "items"
619
+ },
620
+ url: {
621
+ wire: "url"
622
+ },
623
+ alt: {
624
+ wire: "alt"
625
+ },
626
+ label: {
627
+ wire: "label"
628
+ },
629
+ title: {
630
+ wire: "title"
631
+ },
632
+ imageUrl: {
633
+ wire: "imageUrl"
634
+ },
635
+ price: {
636
+ wire: "price"
637
+ },
638
+ description: {
639
+ wire: "description"
640
+ },
641
+ ctaLabel: {
642
+ wire: "ctaLabel"
643
+ },
644
+ html: {
645
+ wire: "html"
646
+ },
647
+ columns: {
648
+ wire: "columns"
649
+ }
650
+ }
651
+ },
652
+ audienceFilterId: {
653
+ wire: "audience_filter_id"
654
+ },
655
+ abTest: {
656
+ wire: "ab_test",
657
+ props: {
658
+ variants: {
659
+ wire: "variants",
660
+ items: {
661
+ subject: {
662
+ wire: "subject"
663
+ },
664
+ preheader: {
665
+ wire: "preheader"
666
+ }
667
+ }
668
+ },
669
+ samplePct: {
670
+ wire: "sample_pct"
671
+ },
672
+ metric: {
673
+ wire: "metric"
674
+ },
675
+ waitHours: {
676
+ wire: "wait_hours"
677
+ },
678
+ winnerMode: {
679
+ wire: "winner_mode"
680
+ }
681
+ }
682
+ }
683
+ }
684
+ },
685
+ "newsletters.get": {
686
+ id: "newsletters.get",
687
+ method: "GET",
688
+ path: "/newsletters/{id}",
689
+ pathParams: ["id"],
690
+ paginated: false,
691
+ idempotent: false
692
+ },
693
+ "newsletters.update": {
694
+ id: "newsletters.update",
695
+ method: "PATCH",
696
+ path: "/newsletters/{id}",
697
+ pathParams: ["id"],
698
+ paginated: false,
699
+ idempotent: false,
700
+ body: {
701
+ subject: {
702
+ wire: "subject"
703
+ },
704
+ preheader: {
705
+ wire: "preheader"
706
+ },
707
+ topicId: {
708
+ wire: "topic_id"
709
+ },
710
+ markdown: {
711
+ wire: "markdown"
712
+ },
713
+ html: {
714
+ wire: "html"
715
+ },
716
+ blocks: {
717
+ wire: "blocks",
718
+ items: {
719
+ kind: {
720
+ wire: "kind"
721
+ },
722
+ level: {
723
+ wire: "level"
724
+ },
725
+ text: {
726
+ wire: "text"
727
+ },
728
+ ordered: {
729
+ wire: "ordered"
730
+ },
731
+ items: {
732
+ wire: "items"
733
+ },
734
+ url: {
735
+ wire: "url"
736
+ },
737
+ alt: {
738
+ wire: "alt"
739
+ },
740
+ label: {
741
+ wire: "label"
742
+ },
743
+ title: {
744
+ wire: "title"
745
+ },
746
+ imageUrl: {
747
+ wire: "imageUrl"
748
+ },
749
+ price: {
750
+ wire: "price"
751
+ },
752
+ description: {
753
+ wire: "description"
754
+ },
755
+ ctaLabel: {
756
+ wire: "ctaLabel"
757
+ },
758
+ html: {
759
+ wire: "html"
760
+ },
761
+ columns: {
762
+ wire: "columns"
763
+ }
764
+ }
765
+ },
766
+ audienceFilterId: {
767
+ wire: "audience_filter_id"
768
+ },
769
+ abTest: {
770
+ wire: "ab_test",
771
+ props: {
772
+ variants: {
773
+ wire: "variants",
774
+ items: {
775
+ subject: {
776
+ wire: "subject"
777
+ },
778
+ preheader: {
779
+ wire: "preheader"
780
+ }
781
+ }
782
+ },
783
+ samplePct: {
784
+ wire: "sample_pct"
785
+ },
786
+ metric: {
787
+ wire: "metric"
788
+ },
789
+ waitHours: {
790
+ wire: "wait_hours"
791
+ },
792
+ winnerMode: {
793
+ wire: "winner_mode"
794
+ }
795
+ }
796
+ }
797
+ }
798
+ },
799
+ "newsletters.remove": {
800
+ id: "newsletters.remove",
801
+ method: "DELETE",
802
+ path: "/newsletters/{id}",
803
+ pathParams: ["id"],
804
+ paginated: false,
805
+ idempotent: false
806
+ },
807
+ "newsletters.duplicate": {
808
+ id: "newsletters.duplicate",
809
+ method: "POST",
810
+ path: "/newsletters/{id}/duplicate",
811
+ pathParams: ["id"],
812
+ paginated: false,
813
+ idempotent: false
814
+ },
815
+ "newsletters.review": {
816
+ id: "newsletters.review",
817
+ method: "GET",
818
+ path: "/newsletters/{id}/review",
819
+ pathParams: ["id"],
820
+ paginated: false,
821
+ idempotent: false
822
+ },
823
+ "newsletters.test": {
824
+ id: "newsletters.test",
825
+ method: "POST",
826
+ path: "/newsletters/{id}/test",
827
+ pathParams: ["id"],
828
+ paginated: false,
829
+ idempotent: false
830
+ },
831
+ "newsletters.send": {
832
+ id: "newsletters.send",
833
+ method: "POST",
834
+ path: "/newsletters/{id}/send",
835
+ pathParams: ["id"],
836
+ paginated: false,
837
+ idempotent: true,
838
+ body: {
839
+ audienceLimit: {
840
+ wire: "audience_limit"
841
+ }
842
+ }
843
+ },
844
+ "newsletters.schedule": {
845
+ id: "newsletters.schedule",
846
+ method: "POST",
847
+ path: "/newsletters/{id}/schedule",
848
+ pathParams: ["id"],
849
+ paginated: false,
850
+ idempotent: true,
851
+ body: {
852
+ scheduledAt: {
853
+ wire: "scheduled_at"
854
+ },
855
+ audienceLimit: {
856
+ wire: "audience_limit"
857
+ }
858
+ }
859
+ },
860
+ "newsletters.unschedule": {
861
+ id: "newsletters.unschedule",
862
+ method: "POST",
863
+ path: "/newsletters/{id}/unschedule",
864
+ pathParams: ["id"],
865
+ paginated: false,
866
+ idempotent: false
867
+ },
868
+ "newsletters.pause": {
869
+ id: "newsletters.pause",
870
+ method: "POST",
871
+ path: "/newsletters/{id}/pause",
872
+ pathParams: ["id"],
873
+ paginated: false,
874
+ idempotent: false
875
+ },
876
+ "newsletters.resume": {
877
+ id: "newsletters.resume",
878
+ method: "POST",
879
+ path: "/newsletters/{id}/resume",
880
+ pathParams: ["id"],
881
+ paginated: false,
882
+ idempotent: false
883
+ },
884
+ "newsletters.sendMore": {
885
+ id: "newsletters.sendMore",
886
+ method: "POST",
887
+ path: "/newsletters/{id}/send-more",
888
+ pathParams: ["id"],
889
+ paginated: false,
890
+ idempotent: true,
891
+ body: {
892
+ count: {
893
+ wire: "count"
894
+ }
895
+ }
896
+ },
897
+ "newsletters.report": {
898
+ id: "newsletters.report",
899
+ method: "GET",
900
+ path: "/newsletters/{id}/report",
901
+ pathParams: ["id"],
902
+ paginated: false,
903
+ idempotent: false
904
+ },
905
+ "newsletters.abWinner": {
906
+ id: "newsletters.abWinner",
907
+ method: "POST",
908
+ path: "/newsletters/{id}/ab-winner",
909
+ pathParams: ["id"],
910
+ paginated: false,
911
+ idempotent: false,
912
+ body: {
913
+ variant: {
914
+ wire: "variant"
915
+ }
916
+ }
917
+ },
918
+ "contacts.list": {
919
+ id: "contacts.list",
920
+ method: "GET",
921
+ path: "/contacts",
922
+ pathParams: [],
923
+ paginated: true,
924
+ idempotent: false,
925
+ query: {
926
+ limit: {
927
+ wire: "limit"
928
+ },
929
+ after: {
930
+ wire: "after"
931
+ },
932
+ before: {
933
+ wire: "before"
934
+ },
935
+ segmentId: {
936
+ wire: "segment_id"
937
+ },
938
+ status: {
939
+ wire: "status"
940
+ },
941
+ search: {
942
+ wire: "search"
943
+ },
944
+ tag: {
945
+ wire: "tag"
946
+ }
947
+ }
948
+ },
949
+ "contacts.create": {
950
+ id: "contacts.create",
951
+ method: "POST",
952
+ path: "/contacts",
953
+ pathParams: [],
954
+ paginated: false,
955
+ idempotent: true,
956
+ body: {
957
+ email: {
958
+ wire: "email"
959
+ },
960
+ segmentId: {
961
+ wire: "segment_id"
962
+ },
963
+ name: {
964
+ wire: "name"
965
+ },
966
+ firstName: {
967
+ wire: "first_name"
968
+ },
969
+ lastName: {
970
+ wire: "last_name"
971
+ },
972
+ language: {
973
+ wire: "language"
974
+ },
975
+ customFields: {
976
+ wire: "custom_fields"
977
+ },
978
+ tags: {
979
+ wire: "tags"
980
+ }
981
+ }
982
+ },
983
+ "contacts.import": {
984
+ id: "contacts.import",
985
+ method: "POST",
986
+ path: "/contacts/import",
987
+ pathParams: [],
988
+ paginated: false,
989
+ idempotent: true,
990
+ body: {
991
+ segmentId: {
992
+ wire: "segment_id"
993
+ },
994
+ consent: {
995
+ wire: "consent"
996
+ },
997
+ contacts: {
998
+ wire: "contacts",
999
+ items: {
1000
+ email: {
1001
+ wire: "email"
1002
+ },
1003
+ name: {
1004
+ wire: "name"
1005
+ },
1006
+ firstName: {
1007
+ wire: "first_name"
1008
+ },
1009
+ lastName: {
1010
+ wire: "last_name"
1011
+ },
1012
+ language: {
1013
+ wire: "language"
1014
+ },
1015
+ customFields: {
1016
+ wire: "custom_fields"
1017
+ },
1018
+ openRate: {
1019
+ wire: "open_rate"
1020
+ },
1021
+ clickRate: {
1022
+ wire: "click_rate"
1023
+ },
1024
+ lastActivityAt: {
1025
+ wire: "last_activity_at"
1026
+ },
1027
+ tags: {
1028
+ wire: "tags"
1029
+ },
1030
+ status: {
1031
+ wire: "status"
1032
+ },
1033
+ unsubscribedAt: {
1034
+ wire: "unsubscribed_at"
1035
+ }
1036
+ }
1037
+ }
1038
+ }
1039
+ },
1040
+ "contacts.export": {
1041
+ id: "contacts.export",
1042
+ method: "GET",
1043
+ path: "/contacts/export",
1044
+ pathParams: [],
1045
+ paginated: false,
1046
+ idempotent: false,
1047
+ query: {
1048
+ segmentId: {
1049
+ wire: "segment_id"
1050
+ },
1051
+ status: {
1052
+ wire: "status"
1053
+ }
1054
+ },
1055
+ responseType: "text"
1056
+ },
1057
+ "contacts.get": {
1058
+ id: "contacts.get",
1059
+ method: "GET",
1060
+ path: "/contacts/{id}",
1061
+ pathParams: ["id"],
1062
+ paginated: false,
1063
+ idempotent: false
1064
+ },
1065
+ "contacts.unsubscribe": {
1066
+ id: "contacts.unsubscribe",
1067
+ method: "POST",
1068
+ path: "/contacts/{id}/unsubscribe",
1069
+ pathParams: ["id"],
1070
+ paginated: false,
1071
+ idempotent: false
1072
+ },
1073
+ "contacts.reactivate": {
1074
+ id: "contacts.reactivate",
1075
+ method: "POST",
1076
+ path: "/contacts/{id}/reactivate",
1077
+ pathParams: ["id"],
1078
+ paginated: false,
1079
+ idempotent: false
1080
+ },
1081
+ "contacts.remove": {
1082
+ id: "contacts.remove",
1083
+ method: "DELETE",
1084
+ path: "/contacts/{id}",
1085
+ pathParams: ["id"],
1086
+ paginated: false,
1087
+ idempotent: false
1088
+ },
1089
+ "contacts.update": {
1090
+ id: "contacts.update",
1091
+ method: "PATCH",
1092
+ path: "/contacts/{id}",
1093
+ pathParams: ["id"],
1094
+ paginated: false,
1095
+ idempotent: false,
1096
+ body: {
1097
+ firstName: {
1098
+ wire: "first_name"
1099
+ },
1100
+ lastName: {
1101
+ wire: "last_name"
1102
+ },
1103
+ name: {
1104
+ wire: "name"
1105
+ },
1106
+ language: {
1107
+ wire: "language"
1108
+ },
1109
+ customFields: {
1110
+ wire: "custom_fields"
1111
+ },
1112
+ tags: {
1113
+ wire: "tags"
1114
+ },
1115
+ addTags: {
1116
+ wire: "add_tags"
1117
+ },
1118
+ removeTags: {
1119
+ wire: "remove_tags"
1120
+ }
1121
+ }
1122
+ },
1123
+ "contactFields.list": {
1124
+ id: "contactFields.list",
1125
+ method: "GET",
1126
+ path: "/contact-fields",
1127
+ pathParams: [],
1128
+ paginated: false,
1129
+ idempotent: false
1130
+ },
1131
+ "contactFields.create": {
1132
+ id: "contactFields.create",
1133
+ method: "POST",
1134
+ path: "/contact-fields",
1135
+ pathParams: [],
1136
+ paginated: false,
1137
+ idempotent: false,
1138
+ body: {
1139
+ key: {
1140
+ wire: "key"
1141
+ },
1142
+ label: {
1143
+ wire: "label"
1144
+ },
1145
+ type: {
1146
+ wire: "type"
1147
+ },
1148
+ options: {
1149
+ wire: "options"
1150
+ },
1151
+ defaultValue: {
1152
+ wire: "default_value"
1153
+ },
1154
+ inSignup: {
1155
+ wire: "in_signup"
1156
+ }
1157
+ }
1158
+ },
1159
+ "contactFields.update": {
1160
+ id: "contactFields.update",
1161
+ method: "PATCH",
1162
+ path: "/contact-fields/{id}",
1163
+ pathParams: ["id"],
1164
+ paginated: false,
1165
+ idempotent: false,
1166
+ body: {
1167
+ label: {
1168
+ wire: "label"
1169
+ },
1170
+ options: {
1171
+ wire: "options"
1172
+ },
1173
+ defaultValue: {
1174
+ wire: "default_value"
1175
+ },
1176
+ inSignup: {
1177
+ wire: "in_signup"
1178
+ },
1179
+ position: {
1180
+ wire: "position"
1181
+ }
1182
+ }
1183
+ },
1184
+ "contactFields.remove": {
1185
+ id: "contactFields.remove",
1186
+ method: "DELETE",
1187
+ path: "/contact-fields/{id}",
1188
+ pathParams: ["id"],
1189
+ paginated: false,
1190
+ idempotent: false
1191
+ },
1192
+ "events.send": {
1193
+ id: "events.send",
1194
+ method: "POST",
1195
+ path: "/events",
1196
+ pathParams: [],
1197
+ paginated: false,
1198
+ idempotent: true,
1199
+ body: {
1200
+ email: {
1201
+ wire: "email"
1202
+ },
1203
+ contactId: {
1204
+ wire: "contact_id"
1205
+ },
1206
+ event: {
1207
+ wire: "event"
1208
+ },
1209
+ properties: {
1210
+ wire: "properties"
1211
+ },
1212
+ occurredAt: {
1213
+ wire: "occurred_at"
1214
+ },
1215
+ createContact: {
1216
+ wire: "create_contact"
1217
+ },
1218
+ segmentId: {
1219
+ wire: "segment_id"
1220
+ }
1221
+ }
1222
+ },
1223
+ "audienceFilters.list": {
1224
+ id: "audienceFilters.list",
1225
+ method: "GET",
1226
+ path: "/audience-filters",
1227
+ pathParams: [],
1228
+ paginated: true,
1229
+ idempotent: false,
1230
+ query: {
1231
+ limit: {
1232
+ wire: "limit"
1233
+ },
1234
+ after: {
1235
+ wire: "after"
1236
+ },
1237
+ before: {
1238
+ wire: "before"
1239
+ }
1240
+ }
1241
+ },
1242
+ "audienceFilters.create": {
1243
+ id: "audienceFilters.create",
1244
+ method: "POST",
1245
+ path: "/audience-filters",
1246
+ pathParams: [],
1247
+ paginated: false,
1248
+ idempotent: false,
1249
+ body: {
1250
+ name: {
1251
+ wire: "name"
1252
+ },
1253
+ description: {
1254
+ wire: "description"
1255
+ },
1256
+ rules: {
1257
+ wire: "rules"
1258
+ }
1259
+ }
1260
+ },
1261
+ "audienceFilters.get": {
1262
+ id: "audienceFilters.get",
1263
+ method: "GET",
1264
+ path: "/audience-filters/{id}",
1265
+ pathParams: ["id"],
1266
+ paginated: false,
1267
+ idempotent: false
1268
+ },
1269
+ "audienceFilters.update": {
1270
+ id: "audienceFilters.update",
1271
+ method: "PATCH",
1272
+ path: "/audience-filters/{id}",
1273
+ pathParams: ["id"],
1274
+ paginated: false,
1275
+ idempotent: false,
1276
+ body: {
1277
+ name: {
1278
+ wire: "name"
1279
+ },
1280
+ description: {
1281
+ wire: "description"
1282
+ },
1283
+ rules: {
1284
+ wire: "rules"
1285
+ }
1286
+ }
1287
+ },
1288
+ "audienceFilters.remove": {
1289
+ id: "audienceFilters.remove",
1290
+ method: "DELETE",
1291
+ path: "/audience-filters/{id}",
1292
+ pathParams: ["id"],
1293
+ paginated: false,
1294
+ idempotent: false
1295
+ },
1296
+ "audienceFilters.count": {
1297
+ id: "audienceFilters.count",
1298
+ method: "POST",
1299
+ path: "/audience-filters/count",
1300
+ pathParams: [],
1301
+ paginated: false,
1302
+ idempotent: false,
1303
+ body: {
1304
+ filterId: {
1305
+ wire: "filter_id"
1306
+ },
1307
+ rules: {
1308
+ wire: "rules"
1309
+ },
1310
+ segmentId: {
1311
+ wire: "segment_id"
1312
+ }
1313
+ }
1314
+ },
1315
+ "signups.create": {
1316
+ id: "signups.create",
1317
+ method: "POST",
1318
+ path: "/signups",
1319
+ pathParams: [],
1320
+ paginated: false,
1321
+ idempotent: true,
1322
+ body: {
1323
+ email: {
1324
+ wire: "email"
1325
+ },
1326
+ name: {
1327
+ wire: "name"
1328
+ },
1329
+ firstName: {
1330
+ wire: "first_name"
1331
+ },
1332
+ segmentId: {
1333
+ wire: "segment_id"
1334
+ },
1335
+ language: {
1336
+ wire: "language"
1337
+ },
1338
+ sourceUrl: {
1339
+ wire: "source_url"
1340
+ },
1341
+ customFields: {
1342
+ wire: "custom_fields"
1343
+ }
1344
+ }
1345
+ },
1346
+ "segments.list": {
1347
+ id: "segments.list",
1348
+ method: "GET",
1349
+ path: "/segments",
1350
+ pathParams: [],
1351
+ paginated: true,
1352
+ idempotent: false,
1353
+ query: {
1354
+ limit: {
1355
+ wire: "limit"
1356
+ },
1357
+ after: {
1358
+ wire: "after"
1359
+ },
1360
+ before: {
1361
+ wire: "before"
1362
+ }
1363
+ }
1364
+ },
1365
+ "segments.create": {
1366
+ id: "segments.create",
1367
+ method: "POST",
1368
+ path: "/segments",
1369
+ pathParams: [],
1370
+ paginated: false,
1371
+ idempotent: false,
1372
+ body: {
1373
+ name: {
1374
+ wire: "name"
1375
+ },
1376
+ slug: {
1377
+ wire: "slug"
1378
+ },
1379
+ language: {
1380
+ wire: "language"
1381
+ },
1382
+ description: {
1383
+ wire: "description"
1384
+ },
1385
+ themes: {
1386
+ wire: "themes"
1387
+ }
1388
+ }
1389
+ },
1390
+ "topics.list": {
1391
+ id: "topics.list",
1392
+ method: "GET",
1393
+ path: "/topics",
1394
+ pathParams: [],
1395
+ paginated: false,
1396
+ idempotent: false,
1397
+ query: {
1398
+ segmentId: {
1399
+ wire: "segment_id"
1400
+ }
1401
+ }
1402
+ },
1403
+ "segments.archive.get": {
1404
+ id: "segments.archive.get",
1405
+ method: "GET",
1406
+ path: "/segments/{id}/archive",
1407
+ pathParams: ["id"],
1408
+ paginated: false,
1409
+ idempotent: false
1410
+ },
1411
+ "segments.archive.update": {
1412
+ id: "segments.archive.update",
1413
+ method: "PATCH",
1414
+ path: "/segments/{id}/archive",
1415
+ pathParams: ["id"],
1416
+ paginated: false,
1417
+ idempotent: false,
1418
+ body: {
1419
+ enabled: {
1420
+ wire: "enabled"
1421
+ },
1422
+ slug: {
1423
+ wire: "slug"
1424
+ },
1425
+ description: {
1426
+ wire: "description"
1427
+ },
1428
+ author: {
1429
+ wire: "author"
1430
+ },
1431
+ about: {
1432
+ wire: "about"
1433
+ },
1434
+ avatarUrl: {
1435
+ wire: "avatar_url"
1436
+ },
1437
+ links: {
1438
+ wire: "links",
1439
+ props: {
1440
+ website: {
1441
+ wire: "website"
1442
+ },
1443
+ x: {
1444
+ wire: "x"
1445
+ },
1446
+ linkedin: {
1447
+ wire: "linkedin"
1448
+ },
1449
+ youtube: {
1450
+ wire: "youtube"
1451
+ },
1452
+ instagram: {
1453
+ wire: "instagram"
1454
+ },
1455
+ github: {
1456
+ wire: "github"
1457
+ },
1458
+ bluesky: {
1459
+ wire: "bluesky"
1460
+ }
1461
+ }
1462
+ }
1463
+ }
1464
+ },
1465
+ "newsletters.archive.update": {
1466
+ id: "newsletters.archive.update",
1467
+ method: "PATCH",
1468
+ path: "/newsletters/{id}/archive",
1469
+ pathParams: ["id"],
1470
+ paginated: false,
1471
+ idempotent: false,
1472
+ body: {
1473
+ pinned: {
1474
+ wire: "pinned"
1475
+ },
1476
+ hidden: {
1477
+ wire: "hidden"
1478
+ }
1479
+ }
1480
+ },
1481
+ "segments.domain.get": {
1482
+ id: "segments.domain.get",
1483
+ method: "GET",
1484
+ path: "/segments/{id}/domain",
1485
+ pathParams: ["id"],
1486
+ paginated: false,
1487
+ idempotent: false
1488
+ },
1489
+ "segments.domain.set": {
1490
+ id: "segments.domain.set",
1491
+ method: "POST",
1492
+ path: "/segments/{id}/domain",
1493
+ pathParams: ["id"],
1494
+ paginated: false,
1495
+ idempotent: false,
1496
+ body: {
1497
+ domain: {
1498
+ wire: "domain"
1499
+ }
1500
+ }
1501
+ },
1502
+ "segments.domain.remove": {
1503
+ id: "segments.domain.remove",
1504
+ method: "DELETE",
1505
+ path: "/segments/{id}/domain",
1506
+ pathParams: ["id"],
1507
+ paginated: false,
1508
+ idempotent: false
1509
+ },
1510
+ "suppressions.list": {
1511
+ id: "suppressions.list",
1512
+ method: "GET",
1513
+ path: "/suppressions",
1514
+ pathParams: [],
1515
+ paginated: true,
1516
+ idempotent: false,
1517
+ query: {
1518
+ limit: {
1519
+ wire: "limit"
1520
+ },
1521
+ after: {
1522
+ wire: "after"
1523
+ },
1524
+ before: {
1525
+ wire: "before"
1526
+ },
1527
+ reason: {
1528
+ wire: "reason"
1529
+ }
1530
+ }
1531
+ },
1532
+ "suppressions.create": {
1533
+ id: "suppressions.create",
1534
+ method: "POST",
1535
+ path: "/suppressions",
1536
+ pathParams: [],
1537
+ paginated: false,
1538
+ idempotent: false,
1539
+ body: {
1540
+ email: {
1541
+ wire: "email"
1542
+ },
1543
+ reason: {
1544
+ wire: "reason"
1545
+ },
1546
+ notes: {
1547
+ wire: "notes"
1548
+ }
1549
+ }
1550
+ },
1551
+ "suppressions.remove": {
1552
+ id: "suppressions.remove",
1553
+ method: "DELETE",
1554
+ path: "/suppressions/{id}",
1555
+ pathParams: ["id"],
1556
+ paginated: false,
1557
+ idempotent: false
1558
+ },
1559
+ "images.list": {
1560
+ id: "images.list",
1561
+ method: "GET",
1562
+ path: "/images",
1563
+ pathParams: [],
1564
+ paginated: true,
1565
+ idempotent: false,
1566
+ query: {
1567
+ limit: {
1568
+ wire: "limit"
1569
+ },
1570
+ after: {
1571
+ wire: "after"
1572
+ },
1573
+ before: {
1574
+ wire: "before"
1575
+ }
1576
+ }
1577
+ },
1578
+ "images.create": {
1579
+ id: "images.create",
1580
+ method: "POST",
1581
+ path: "/images",
1582
+ pathParams: [],
1583
+ paginated: false,
1584
+ idempotent: false,
1585
+ rawBody: true
1586
+ },
1587
+ "stats.overview": {
1588
+ id: "stats.overview",
1589
+ method: "GET",
1590
+ path: "/stats/overview",
1591
+ pathParams: [],
1592
+ paginated: false,
1593
+ idempotent: false
1594
+ },
1595
+ "domains.create": {
1596
+ id: "domains.create",
1597
+ method: "POST",
1598
+ path: "/domains",
1599
+ pathParams: [],
1600
+ paginated: false,
1601
+ idempotent: false,
1602
+ body: {
1603
+ name: {
1604
+ wire: "name"
1605
+ },
1606
+ trackingSubdomain: {
1607
+ wire: "tracking_subdomain"
1608
+ }
1609
+ }
1610
+ },
1611
+ "domains.list": {
1612
+ id: "domains.list",
1613
+ method: "GET",
1614
+ path: "/domains",
1615
+ pathParams: [],
1616
+ paginated: true,
1617
+ idempotent: false,
1618
+ query: {
1619
+ limit: {
1620
+ wire: "limit"
1621
+ },
1622
+ after: {
1623
+ wire: "after"
1624
+ },
1625
+ before: {
1626
+ wire: "before"
1627
+ }
1628
+ }
1629
+ },
1630
+ "domains.get": {
1631
+ id: "domains.get",
1632
+ method: "GET",
1633
+ path: "/domains/{id}",
1634
+ pathParams: ["id"],
1635
+ paginated: false,
1636
+ idempotent: false
1637
+ },
1638
+ "domains.verify": {
1639
+ id: "domains.verify",
1640
+ method: "POST",
1641
+ path: "/domains/{id}/verify",
1642
+ pathParams: ["id"],
1643
+ paginated: false,
1644
+ idempotent: false
1645
+ },
1646
+ "apiKeys.create": {
1647
+ id: "apiKeys.create",
1648
+ method: "POST",
1649
+ path: "/api-keys",
1650
+ pathParams: [],
1651
+ paginated: false,
1652
+ idempotent: false,
1653
+ body: {
1654
+ name: {
1655
+ wire: "name"
1656
+ },
1657
+ permission: {
1658
+ wire: "permission"
1659
+ },
1660
+ domainId: {
1661
+ wire: "domain_id"
1662
+ }
1663
+ }
1664
+ },
1665
+ "apiKeys.list": {
1666
+ id: "apiKeys.list",
1667
+ method: "GET",
1668
+ path: "/api-keys",
1669
+ pathParams: [],
1670
+ paginated: true,
1671
+ idempotent: false,
1672
+ query: {
1673
+ limit: {
1674
+ wire: "limit"
1675
+ },
1676
+ after: {
1677
+ wire: "after"
1678
+ },
1679
+ before: {
1680
+ wire: "before"
1681
+ }
1682
+ }
1683
+ },
1684
+ "apiKeys.update": {
1685
+ id: "apiKeys.update",
1686
+ method: "PATCH",
1687
+ path: "/api-keys/{id}",
1688
+ pathParams: ["id"],
1689
+ paginated: false,
1690
+ idempotent: false,
1691
+ body: {
1692
+ name: {
1693
+ wire: "name"
1694
+ }
1695
+ }
1696
+ },
1697
+ "apiKeys.remove": {
1698
+ id: "apiKeys.remove",
1699
+ method: "DELETE",
1700
+ path: "/api-keys/{id}",
1701
+ pathParams: ["id"],
1702
+ paginated: false,
1703
+ idempotent: false
1704
+ },
1705
+ "logs.list": {
1706
+ id: "logs.list",
1707
+ method: "GET",
1708
+ path: "/logs",
1709
+ pathParams: [],
1710
+ paginated: true,
1711
+ idempotent: false,
1712
+ query: {
1713
+ limit: {
1714
+ wire: "limit"
1715
+ },
1716
+ after: {
1717
+ wire: "after"
1718
+ },
1719
+ before: {
1720
+ wire: "before"
1721
+ }
1722
+ }
1723
+ },
1724
+ "logs.get": {
1725
+ id: "logs.get",
1726
+ method: "GET",
1727
+ path: "/logs/{id}",
1728
+ pathParams: ["id"],
1729
+ paginated: false,
1730
+ idempotent: false
1731
+ },
1732
+ "usage.get": {
1733
+ id: "usage.get",
1734
+ method: "GET",
1735
+ path: "/usage",
1736
+ pathParams: [],
1737
+ paginated: false,
1738
+ idempotent: false
1739
+ },
1740
+ "sequences.list": {
1741
+ id: "sequences.list",
1742
+ method: "GET",
1743
+ path: "/sequences",
1744
+ pathParams: [],
1745
+ paginated: false,
1746
+ idempotent: false,
1747
+ query: {
1748
+ includeArchived: {
1749
+ wire: "include_archived"
1750
+ }
1751
+ }
1752
+ },
1753
+ "sequences.create": {
1754
+ id: "sequences.create",
1755
+ method: "POST",
1756
+ path: "/sequences",
1757
+ pathParams: [],
1758
+ paginated: false,
1759
+ idempotent: false,
1760
+ body: {
1761
+ name: {
1762
+ wire: "name"
1763
+ },
1764
+ description: {
1765
+ wire: "description"
1766
+ },
1767
+ segmentId: {
1768
+ wire: "segment_id"
1769
+ },
1770
+ topicId: {
1771
+ wire: "topic_id"
1772
+ },
1773
+ trigger: {
1774
+ wire: "trigger",
1775
+ props: {
1776
+ type: {
1777
+ wire: "type"
1778
+ },
1779
+ includeImports: {
1780
+ wire: "include_imports"
1781
+ },
1782
+ topicId: {
1783
+ wire: "topic_id"
1784
+ },
1785
+ leadMagnetId: {
1786
+ wire: "lead_magnet_id"
1787
+ },
1788
+ event: {
1789
+ wire: "event"
1790
+ },
1791
+ newsletterId: {
1792
+ wire: "newsletter_id"
1793
+ },
1794
+ filterId: {
1795
+ wire: "filter_id"
1796
+ },
1797
+ includeExisting: {
1798
+ wire: "include_existing"
1799
+ }
1800
+ }
1801
+ },
1802
+ reentry: {
1803
+ wire: "reentry",
1804
+ props: {
1805
+ mode: {
1806
+ wire: "mode"
1807
+ },
1808
+ days: {
1809
+ wire: "days"
1810
+ }
1811
+ }
1812
+ },
1813
+ exit: {
1814
+ wire: "exit",
1815
+ props: {
1816
+ events: {
1817
+ wire: "events"
1818
+ },
1819
+ filterId: {
1820
+ wire: "filter_id"
1821
+ }
1822
+ }
1823
+ },
1824
+ steps: {
1825
+ wire: "steps",
1826
+ items: {
1827
+ id: {
1828
+ wire: "id"
1829
+ },
1830
+ type: {
1831
+ wire: "type"
1832
+ },
1833
+ subject: {
1834
+ wire: "subject"
1835
+ },
1836
+ preheader: {
1837
+ wire: "preheader"
1838
+ },
1839
+ markdown: {
1840
+ wire: "markdown"
1841
+ },
1842
+ html: {
1843
+ wire: "html"
1844
+ },
1845
+ doc: {
1846
+ wire: "doc"
1847
+ },
1848
+ templateId: {
1849
+ wire: "template_id"
1850
+ },
1851
+ amount: {
1852
+ wire: "amount"
1853
+ },
1854
+ unit: {
1855
+ wire: "unit"
1856
+ },
1857
+ until: {
1858
+ wire: "until",
1859
+ props: {
1860
+ time: {
1861
+ wire: "time"
1862
+ },
1863
+ weekdays: {
1864
+ wire: "weekdays"
1865
+ },
1866
+ timezone: {
1867
+ wire: "timezone"
1868
+ }
1869
+ }
1870
+ },
1871
+ event: {
1872
+ wire: "event"
1873
+ },
1874
+ timeoutHours: {
1875
+ wire: "timeout_hours"
1876
+ },
1877
+ onTimeout: {
1878
+ wire: "on_timeout"
1879
+ },
1880
+ filterId: {
1881
+ wire: "filter_id"
1882
+ },
1883
+ rule: {
1884
+ wire: "rule"
1885
+ },
1886
+ yes: {
1887
+ wire: "yes"
1888
+ },
1889
+ no: {
1890
+ wire: "no"
1891
+ },
1892
+ action: {
1893
+ wire: "action"
1894
+ },
1895
+ key: {
1896
+ wire: "key"
1897
+ },
1898
+ value: {
1899
+ wire: "value"
1900
+ },
1901
+ topicId: {
1902
+ wire: "topic_id"
1903
+ },
1904
+ webhookId: {
1905
+ wire: "webhook_id"
1906
+ }
1907
+ }
1908
+ }
1909
+ }
1910
+ },
1911
+ "sequences.get": {
1912
+ id: "sequences.get",
1913
+ method: "GET",
1914
+ path: "/sequences/{id}",
1915
+ pathParams: ["id"],
1916
+ paginated: false,
1917
+ idempotent: false
1918
+ },
1919
+ "sequences.update": {
1920
+ id: "sequences.update",
1921
+ method: "PATCH",
1922
+ path: "/sequences/{id}",
1923
+ pathParams: ["id"],
1924
+ paginated: false,
1925
+ idempotent: false,
1926
+ body: {
1927
+ name: {
1928
+ wire: "name"
1929
+ },
1930
+ description: {
1931
+ wire: "description"
1932
+ },
1933
+ segmentId: {
1934
+ wire: "segment_id"
1935
+ },
1936
+ topicId: {
1937
+ wire: "topic_id"
1938
+ },
1939
+ trigger: {
1940
+ wire: "trigger",
1941
+ props: {
1942
+ type: {
1943
+ wire: "type"
1944
+ },
1945
+ includeImports: {
1946
+ wire: "include_imports"
1947
+ },
1948
+ topicId: {
1949
+ wire: "topic_id"
1950
+ },
1951
+ leadMagnetId: {
1952
+ wire: "lead_magnet_id"
1953
+ },
1954
+ event: {
1955
+ wire: "event"
1956
+ },
1957
+ newsletterId: {
1958
+ wire: "newsletter_id"
1959
+ },
1960
+ filterId: {
1961
+ wire: "filter_id"
1962
+ },
1963
+ includeExisting: {
1964
+ wire: "include_existing"
1965
+ }
1966
+ }
1967
+ },
1968
+ reentry: {
1969
+ wire: "reentry",
1970
+ props: {
1971
+ mode: {
1972
+ wire: "mode"
1973
+ },
1974
+ days: {
1975
+ wire: "days"
1976
+ }
1977
+ }
1978
+ },
1979
+ exit: {
1980
+ wire: "exit",
1981
+ props: {
1982
+ events: {
1983
+ wire: "events"
1984
+ },
1985
+ filterId: {
1986
+ wire: "filter_id"
1987
+ }
1988
+ }
1989
+ },
1990
+ steps: {
1991
+ wire: "steps",
1992
+ items: {
1993
+ id: {
1994
+ wire: "id"
1995
+ },
1996
+ type: {
1997
+ wire: "type"
1998
+ },
1999
+ subject: {
2000
+ wire: "subject"
2001
+ },
2002
+ preheader: {
2003
+ wire: "preheader"
2004
+ },
2005
+ markdown: {
2006
+ wire: "markdown"
2007
+ },
2008
+ html: {
2009
+ wire: "html"
2010
+ },
2011
+ doc: {
2012
+ wire: "doc"
2013
+ },
2014
+ templateId: {
2015
+ wire: "template_id"
2016
+ },
2017
+ amount: {
2018
+ wire: "amount"
2019
+ },
2020
+ unit: {
2021
+ wire: "unit"
2022
+ },
2023
+ until: {
2024
+ wire: "until",
2025
+ props: {
2026
+ time: {
2027
+ wire: "time"
2028
+ },
2029
+ weekdays: {
2030
+ wire: "weekdays"
2031
+ },
2032
+ timezone: {
2033
+ wire: "timezone"
2034
+ }
2035
+ }
2036
+ },
2037
+ event: {
2038
+ wire: "event"
2039
+ },
2040
+ timeoutHours: {
2041
+ wire: "timeout_hours"
2042
+ },
2043
+ onTimeout: {
2044
+ wire: "on_timeout"
2045
+ },
2046
+ filterId: {
2047
+ wire: "filter_id"
2048
+ },
2049
+ rule: {
2050
+ wire: "rule"
2051
+ },
2052
+ yes: {
2053
+ wire: "yes"
2054
+ },
2055
+ no: {
2056
+ wire: "no"
2057
+ },
2058
+ action: {
2059
+ wire: "action"
2060
+ },
2061
+ key: {
2062
+ wire: "key"
2063
+ },
2064
+ value: {
2065
+ wire: "value"
2066
+ },
2067
+ topicId: {
2068
+ wire: "topic_id"
2069
+ },
2070
+ webhookId: {
2071
+ wire: "webhook_id"
2072
+ }
2073
+ }
2074
+ }
2075
+ }
2076
+ },
2077
+ "sequences.remove": {
2078
+ id: "sequences.remove",
2079
+ method: "DELETE",
2080
+ path: "/sequences/{id}",
2081
+ pathParams: ["id"],
2082
+ paginated: false,
2083
+ idempotent: false
2084
+ },
2085
+ "sequences.activate": {
2086
+ id: "sequences.activate",
2087
+ method: "POST",
2088
+ path: "/sequences/{id}/activate",
2089
+ pathParams: ["id"],
2090
+ paginated: false,
2091
+ idempotent: false
2092
+ },
2093
+ "sequences.pause": {
2094
+ id: "sequences.pause",
2095
+ method: "POST",
2096
+ path: "/sequences/{id}/pause",
2097
+ pathParams: ["id"],
2098
+ paginated: false,
2099
+ idempotent: false
2100
+ },
2101
+ "sequences.archive": {
2102
+ id: "sequences.archive",
2103
+ method: "POST",
2104
+ path: "/sequences/{id}/archive",
2105
+ pathParams: ["id"],
2106
+ paginated: false,
2107
+ idempotent: false
2108
+ },
2109
+ "sequences.enrollments": {
2110
+ id: "sequences.enrollments",
2111
+ method: "GET",
2112
+ path: "/sequences/{id}/enrollments",
2113
+ pathParams: ["id"],
2114
+ paginated: false,
2115
+ idempotent: false,
2116
+ query: {
2117
+ status: {
2118
+ wire: "status"
2119
+ },
2120
+ limit: {
2121
+ wire: "limit"
2122
+ }
2123
+ }
2124
+ },
2125
+ "sequences.enroll": {
2126
+ id: "sequences.enroll",
2127
+ method: "POST",
2128
+ path: "/sequences/{id}/enrollments",
2129
+ pathParams: ["id"],
2130
+ paginated: false,
2131
+ idempotent: false,
2132
+ body: {
2133
+ email: {
2134
+ wire: "email"
2135
+ },
2136
+ contactId: {
2137
+ wire: "contact_id"
2138
+ }
2139
+ }
2140
+ },
2141
+ "sequences.unenroll": {
2142
+ id: "sequences.unenroll",
2143
+ method: "DELETE",
2144
+ path: "/sequences/{id}/enrollments/{enrollment_id}",
2145
+ pathParams: ["id", "enrollment_id"],
2146
+ paginated: false,
2147
+ idempotent: false
2148
+ },
2149
+ "sequences.stats": {
2150
+ id: "sequences.stats",
2151
+ method: "GET",
2152
+ path: "/sequences/{id}/stats",
2153
+ pathParams: ["id"],
2154
+ paginated: false,
2155
+ idempotent: false
2156
+ },
2157
+ "webhooks.create": {
2158
+ id: "webhooks.create",
2159
+ method: "POST",
2160
+ path: "/webhooks",
2161
+ pathParams: [],
2162
+ paginated: false,
2163
+ idempotent: false,
2164
+ body: {
2165
+ endpoint: {
2166
+ wire: "endpoint"
2167
+ },
2168
+ events: {
2169
+ wire: "events"
2170
+ },
2171
+ description: {
2172
+ wire: "description"
2173
+ },
2174
+ includeNewsletters: {
2175
+ wire: "include_newsletters"
2176
+ },
2177
+ segmentIds: {
2178
+ wire: "segment_ids"
2179
+ },
2180
+ domains: {
2181
+ wire: "domains"
2182
+ }
2183
+ }
2184
+ },
2185
+ "webhooks.list": {
2186
+ id: "webhooks.list",
2187
+ method: "GET",
2188
+ path: "/webhooks",
2189
+ pathParams: [],
2190
+ paginated: true,
2191
+ idempotent: false,
2192
+ query: {
2193
+ limit: {
2194
+ wire: "limit"
2195
+ },
2196
+ after: {
2197
+ wire: "after"
2198
+ },
2199
+ before: {
2200
+ wire: "before"
2201
+ }
2202
+ }
2203
+ },
2204
+ "webhooks.get": {
2205
+ id: "webhooks.get",
2206
+ method: "GET",
2207
+ path: "/webhooks/{id}",
2208
+ pathParams: ["id"],
2209
+ paginated: false,
2210
+ idempotent: false
2211
+ },
2212
+ "webhooks.update": {
2213
+ id: "webhooks.update",
2214
+ method: "PATCH",
2215
+ path: "/webhooks/{id}",
2216
+ pathParams: ["id"],
2217
+ paginated: false,
2218
+ idempotent: false,
2219
+ body: {
2220
+ endpoint: {
2221
+ wire: "endpoint"
2222
+ },
2223
+ events: {
2224
+ wire: "events"
2225
+ },
2226
+ status: {
2227
+ wire: "status"
2228
+ },
2229
+ description: {
2230
+ wire: "description"
2231
+ },
2232
+ includeNewsletters: {
2233
+ wire: "include_newsletters"
2234
+ },
2235
+ segmentIds: {
2236
+ wire: "segment_ids"
2237
+ },
2238
+ domains: {
2239
+ wire: "domains"
2240
+ }
2241
+ }
2242
+ },
2243
+ "webhooks.remove": {
2244
+ id: "webhooks.remove",
2245
+ method: "DELETE",
2246
+ path: "/webhooks/{id}",
2247
+ pathParams: ["id"],
2248
+ paginated: false,
2249
+ idempotent: false
2250
+ },
2251
+ "webhooks.rotateSigningSecret": {
2252
+ id: "webhooks.rotateSigningSecret",
2253
+ method: "POST",
2254
+ path: "/webhooks/{id}/signing-secret/rotate",
2255
+ pathParams: ["id"],
2256
+ paginated: false,
2257
+ idempotent: false
2258
+ },
2259
+ "webhooks.test": {
2260
+ id: "webhooks.test",
2261
+ method: "POST",
2262
+ path: "/webhooks/{id}/test",
2263
+ pathParams: ["id"],
2264
+ paginated: false,
2265
+ idempotent: false,
2266
+ body: {
2267
+ type: {
2268
+ wire: "type"
2269
+ }
2270
+ }
2271
+ },
2272
+ "webhooks.deliveries": {
2273
+ id: "webhooks.deliveries",
2274
+ method: "GET",
2275
+ path: "/webhooks/{id}/deliveries",
2276
+ pathParams: ["id"],
2277
+ paginated: true,
2278
+ idempotent: false,
2279
+ query: {
2280
+ limit: {
2281
+ wire: "limit"
2282
+ },
2283
+ after: {
2284
+ wire: "after"
2285
+ },
2286
+ before: {
2287
+ wire: "before"
2288
+ },
2289
+ status: {
2290
+ wire: "status"
2291
+ }
2292
+ }
2293
+ },
2294
+ "webhooks.retryDelivery": {
2295
+ id: "webhooks.retryDelivery",
2296
+ method: "POST",
2297
+ path: "/webhooks/{id}/deliveries/{delivery_id}/retry",
2298
+ pathParams: ["id", "delivery_id"],
2299
+ paginated: false,
2300
+ idempotent: false
2301
+ },
2302
+ "inboxes.list": {
2303
+ id: "inboxes.list",
2304
+ method: "GET",
2305
+ path: "/inboxes",
2306
+ pathParams: [],
2307
+ paginated: false,
2308
+ idempotent: false
2309
+ },
2310
+ "inboxes.create": {
2311
+ id: "inboxes.create",
2312
+ method: "POST",
2313
+ path: "/inboxes",
2314
+ pathParams: [],
2315
+ paginated: false,
2316
+ idempotent: false,
2317
+ body: {
2318
+ name: {
2319
+ wire: "name"
2320
+ },
2321
+ displayName: {
2322
+ wire: "display_name"
2323
+ },
2324
+ description: {
2325
+ wire: "description"
2326
+ },
2327
+ domainId: {
2328
+ wire: "domain_id"
2329
+ },
2330
+ replyFrom: {
2331
+ wire: "reply_from"
2332
+ }
2333
+ }
2334
+ },
2335
+ "inboxes.get": {
2336
+ id: "inboxes.get",
2337
+ method: "GET",
2338
+ path: "/inboxes/{id}",
2339
+ pathParams: ["id"],
2340
+ paginated: false,
2341
+ idempotent: false
2342
+ },
2343
+ "inboxes.update": {
2344
+ id: "inboxes.update",
2345
+ method: "PATCH",
2346
+ path: "/inboxes/{id}",
2347
+ pathParams: ["id"],
2348
+ paginated: false,
2349
+ idempotent: false,
2350
+ body: {
2351
+ displayName: {
2352
+ wire: "display_name"
2353
+ },
2354
+ description: {
2355
+ wire: "description"
2356
+ },
2357
+ replyFrom: {
2358
+ wire: "reply_from"
2359
+ },
2360
+ status: {
2361
+ wire: "status"
2362
+ }
2363
+ }
2364
+ },
2365
+ "inboxes.remove": {
2366
+ id: "inboxes.remove",
2367
+ method: "DELETE",
2368
+ path: "/inboxes/{id}",
2369
+ pathParams: ["id"],
2370
+ paginated: false,
2371
+ idempotent: false
2372
+ },
2373
+ "threads.list": {
2374
+ id: "threads.list",
2375
+ method: "GET",
2376
+ path: "/threads",
2377
+ pathParams: [],
2378
+ paginated: false,
2379
+ idempotent: false,
2380
+ query: {
2381
+ inboxId: {
2382
+ wire: "inbox_id"
2383
+ },
2384
+ status: {
2385
+ wire: "status"
2386
+ },
2387
+ label: {
2388
+ wire: "label"
2389
+ },
2390
+ spam: {
2391
+ wire: "spam"
2392
+ },
2393
+ assigneeAgent: {
2394
+ wire: "assignee_agent"
2395
+ },
2396
+ unread: {
2397
+ wire: "unread"
2398
+ },
2399
+ limit: {
2400
+ wire: "limit"
2401
+ },
2402
+ after: {
2403
+ wire: "after"
2404
+ }
2405
+ }
2406
+ },
2407
+ "threads.get": {
2408
+ id: "threads.get",
2409
+ method: "GET",
2410
+ path: "/threads/{id}",
2411
+ pathParams: ["id"],
2412
+ paginated: false,
2413
+ idempotent: false
2414
+ },
2415
+ "threads.update": {
2416
+ id: "threads.update",
2417
+ method: "PATCH",
2418
+ path: "/threads/{id}",
2419
+ pathParams: ["id"],
2420
+ paginated: false,
2421
+ idempotent: false,
2422
+ body: {
2423
+ status: {
2424
+ wire: "status"
2425
+ },
2426
+ labels: {
2427
+ wire: "labels"
2428
+ },
2429
+ addLabels: {
2430
+ wire: "add_labels"
2431
+ },
2432
+ removeLabels: {
2433
+ wire: "remove_labels"
2434
+ },
2435
+ assigneeAgent: {
2436
+ wire: "assignee_agent"
2437
+ },
2438
+ assigneeUserId: {
2439
+ wire: "assignee_user_id"
2440
+ },
2441
+ spam: {
2442
+ wire: "spam"
2443
+ },
2444
+ unread: {
2445
+ wire: "unread"
2446
+ }
2447
+ }
2448
+ },
2449
+ "threads.reply": {
2450
+ id: "threads.reply",
2451
+ method: "POST",
2452
+ path: "/threads/{id}/reply",
2453
+ pathParams: ["id"],
2454
+ paginated: false,
2455
+ idempotent: false,
2456
+ body: {
2457
+ text: {
2458
+ wire: "text"
2459
+ },
2460
+ html: {
2461
+ wire: "html"
2462
+ },
2463
+ messageId: {
2464
+ wire: "message_id"
2465
+ },
2466
+ replyAll: {
2467
+ wire: "reply_all"
2468
+ },
2469
+ cc: {
2470
+ wire: "cc"
2471
+ },
2472
+ quote: {
2473
+ wire: "quote"
2474
+ },
2475
+ draft: {
2476
+ wire: "draft"
2477
+ },
2478
+ status: {
2479
+ wire: "status"
2480
+ }
2481
+ }
2482
+ },
2483
+ "messages.get": {
2484
+ id: "messages.get",
2485
+ method: "GET",
2486
+ path: "/messages/{id}",
2487
+ pathParams: ["id"],
2488
+ paginated: false,
2489
+ idempotent: false
2490
+ },
2491
+ "messages.update": {
2492
+ id: "messages.update",
2493
+ method: "PATCH",
2494
+ path: "/messages/{id}",
2495
+ pathParams: ["id"],
2496
+ paginated: false,
2497
+ idempotent: false,
2498
+ body: {
2499
+ text: {
2500
+ wire: "text"
2501
+ },
2502
+ html: {
2503
+ wire: "html"
2504
+ },
2505
+ cc: {
2506
+ wire: "cc"
2507
+ }
2508
+ }
2509
+ },
2510
+ "messages.send": {
2511
+ id: "messages.send",
2512
+ method: "POST",
2513
+ path: "/messages/{id}/send",
2514
+ pathParams: ["id"],
2515
+ paginated: false,
2516
+ idempotent: false,
2517
+ body: {
2518
+ status: {
2519
+ wire: "status"
2520
+ }
2521
+ }
2522
+ },
2523
+ "messages.remove": {
2524
+ id: "messages.remove",
2525
+ method: "DELETE",
2526
+ path: "/messages/{id}",
2527
+ pathParams: ["id"],
2528
+ paginated: false,
2529
+ idempotent: false
2530
+ },
2531
+ "messages.attachment": {
2532
+ id: "messages.attachment",
2533
+ method: "GET",
2534
+ path: "/messages/{id}/attachments/{attachment_id}",
2535
+ pathParams: ["id", "attachment_id"],
2536
+ paginated: false,
2537
+ idempotent: false
2538
+ }
2539
+ };
2540
+ var OPERATION_IDS = Object.keys(OPERATIONS);
2541
+
2542
+ // src/emails.ts
2543
+ var RENDER_ERROR = "Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`.";
2544
+ var RenderError = class extends Error {
2545
+ };
2546
+ async function renderReact(node) {
2547
+ let renderFn;
2548
+ try {
2549
+ ({ render: renderFn } = await import("@react-email/render"));
2550
+ } catch {
2551
+ throw new RenderError(RENDER_ERROR);
2552
+ }
2553
+ if (typeof renderFn !== "function") throw new RenderError(RENDER_ERROR);
2554
+ try {
2555
+ return await renderFn(node);
2556
+ } catch (err) {
2557
+ throw new RenderError(err instanceof Error ? err.message : String(err));
2558
+ }
2559
+ }
2560
+ function toBase64(bytes) {
2561
+ if (typeof Buffer !== "undefined") return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
2562
+ let binary = "";
2563
+ for (let i = 0; i < bytes.length; i += 32768) {
2564
+ binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
2565
+ }
2566
+ return btoa(binary);
2567
+ }
2568
+ async function prepare(email) {
2569
+ const { react, attachments, ...rest } = email;
2570
+ const out = { ...rest };
2571
+ if (react) out.html = await renderReact(react);
2572
+ if (attachments) {
2573
+ out.attachments = attachments.map((a) => {
2574
+ const { filename, ...file } = a;
2575
+ return {
2576
+ ...file,
2577
+ ...filename === false ? {} : { filename },
2578
+ ...a.content instanceof Uint8Array ? { content: toBase64(a.content) } : {}
2579
+ };
2580
+ });
2581
+ }
2582
+ return out;
2583
+ }
2584
+ function renderFailure(err) {
2585
+ if (!(err instanceof RenderError)) return void 0;
2586
+ return { data: null, error: { name: "application_error", statusCode: null, message: err.message }, headers: null };
2587
+ }
2588
+ function makeEmailsSend(client) {
2589
+ return async (payload, options) => {
2590
+ try {
2591
+ const body = await prepare(payload);
2592
+ return await client.call(OPERATIONS["emails.send"], body, options);
2593
+ } catch (err) {
2594
+ const failure = renderFailure(err);
2595
+ if (failure) return failure;
2596
+ throw err;
2597
+ }
2598
+ };
2599
+ }
2600
+ function makeBatchSend(client) {
2601
+ return async (emails, options = {}) => {
2602
+ try {
2603
+ const body = [];
2604
+ for (const email of emails) body.push(await prepare(email));
2605
+ const { batchValidation, ...requestOptions } = options;
2606
+ const headers = new Headers({ "x-batch-validation": batchValidation ?? "strict" });
2607
+ for (const [key, value] of new Headers(requestOptions.headers)) headers.set(key, value);
2608
+ return await client.call(OPERATIONS["batch.send"], body, { ...requestOptions, headers });
2609
+ } catch (err) {
2610
+ const failure = renderFailure(err);
2611
+ if (failure) return failure;
2612
+ throw err;
2613
+ }
2614
+ };
2615
+ }
2616
+
2617
+ // src/webhooks/sha256.ts
2618
+ var K = new Uint32Array([
2619
+ 1116352408,
2620
+ 1899447441,
2621
+ 3049323471,
2622
+ 3921009573,
2623
+ 961987163,
2624
+ 1508970993,
2625
+ 2453635748,
2626
+ 2870763221,
2627
+ 3624381080,
2628
+ 310598401,
2629
+ 607225278,
2630
+ 1426881987,
2631
+ 1925078388,
2632
+ 2162078206,
2633
+ 2614888103,
2634
+ 3248222580,
2635
+ 3835390401,
2636
+ 4022224774,
2637
+ 264347078,
2638
+ 604807628,
2639
+ 770255983,
2640
+ 1249150122,
2641
+ 1555081692,
2642
+ 1996064986,
2643
+ 2554220882,
2644
+ 2821834349,
2645
+ 2952996808,
2646
+ 3210313671,
2647
+ 3336571891,
2648
+ 3584528711,
2649
+ 113926993,
2650
+ 338241895,
2651
+ 666307205,
2652
+ 773529912,
2653
+ 1294757372,
2654
+ 1396182291,
2655
+ 1695183700,
2656
+ 1986661051,
2657
+ 2177026350,
2658
+ 2456956037,
2659
+ 2730485921,
2660
+ 2820302411,
2661
+ 3259730800,
2662
+ 3345764771,
2663
+ 3516065817,
2664
+ 3600352804,
2665
+ 4094571909,
2666
+ 275423344,
2667
+ 430227734,
2668
+ 506948616,
2669
+ 659060556,
2670
+ 883997877,
2671
+ 958139571,
2672
+ 1322822218,
2673
+ 1537002063,
2674
+ 1747873779,
2675
+ 1955562222,
2676
+ 2024104815,
2677
+ 2227730452,
2678
+ 2361852424,
2679
+ 2428436474,
2680
+ 2756734187,
2681
+ 3204031479,
2682
+ 3329325298
2683
+ ]);
2684
+ var rotr = (x, n) => x >>> n | x << 32 - n;
2685
+ function sha256(data) {
2686
+ const h = new Uint32Array([
2687
+ 1779033703,
2688
+ 3144134277,
2689
+ 1013904242,
2690
+ 2773480762,
2691
+ 1359893119,
2692
+ 2600822924,
2693
+ 528734635,
2694
+ 1541459225
2695
+ ]);
2696
+ const padded = new Uint8Array(data.length + 9 + 63 >> 6 << 6);
2697
+ padded.set(data);
2698
+ padded[data.length] = 128;
2699
+ const view = new DataView(padded.buffer);
2700
+ view.setUint32(padded.length - 8, Math.floor(data.length / 536870912));
2701
+ view.setUint32(padded.length - 4, data.length << 3 >>> 0);
2702
+ const w = new Uint32Array(64);
2703
+ for (let off = 0; off < padded.length; off += 64) {
2704
+ for (let i = 0; i < 16; i++) w[i] = view.getUint32(off + i * 4);
2705
+ for (let i = 16; i < 64; i++) {
2706
+ const a2 = w[i - 15];
2707
+ const b2 = w[i - 2];
2708
+ const s0 = rotr(a2, 7) ^ rotr(a2, 18) ^ a2 >>> 3;
2709
+ const s1 = rotr(b2, 17) ^ rotr(b2, 19) ^ b2 >>> 10;
2710
+ w[i] = w[i - 16] + s0 + w[i - 7] + s1 | 0;
2711
+ }
2712
+ let [a, b, c, d, e, f, g, hh] = h;
2713
+ for (let i = 0; i < 64; i++) {
2714
+ const t1 = hh + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + (e & f ^ ~e & g) + K[i] + w[i] | 0;
2715
+ const t2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) | 0;
2716
+ hh = g;
2717
+ g = f;
2718
+ f = e;
2719
+ e = d + t1 | 0;
2720
+ d = c;
2721
+ c = b;
2722
+ b = a;
2723
+ a = t1 + t2 | 0;
2724
+ }
2725
+ h[0] = h[0] + a | 0;
2726
+ h[1] = h[1] + b | 0;
2727
+ h[2] = h[2] + c | 0;
2728
+ h[3] = h[3] + d | 0;
2729
+ h[4] = h[4] + e | 0;
2730
+ h[5] = h[5] + f | 0;
2731
+ h[6] = h[6] + g | 0;
2732
+ h[7] = h[7] + hh | 0;
2733
+ }
2734
+ const out = new Uint8Array(32);
2735
+ const outView = new DataView(out.buffer);
2736
+ for (let i = 0; i < 8; i++) outView.setUint32(i * 4, h[i]);
2737
+ return out;
2738
+ }
2739
+ function hmacSha256(key, message) {
2740
+ const block = new Uint8Array(64);
2741
+ block.set(key.length > 64 ? sha256(key) : key);
2742
+ const inner = new Uint8Array(64 + message.length);
2743
+ const outer = new Uint8Array(64 + 32);
2744
+ for (let i = 0; i < 64; i++) {
2745
+ inner[i] = block[i] ^ 54;
2746
+ outer[i] = block[i] ^ 92;
2747
+ }
2748
+ inner.set(message, 64);
2749
+ outer.set(sha256(inner), 64);
2750
+ return sha256(outer);
2751
+ }
2752
+
2753
+ // src/webhooks/verify.ts
2754
+ var TOLERANCE_SECONDS = 5 * 60;
2755
+ var PREFIX = "whsec_";
2756
+ var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2757
+ var WebhookVerificationError = class _WebhookVerificationError extends Error {
2758
+ constructor(message) {
2759
+ super(message);
2760
+ Object.setPrototypeOf(this, _WebhookVerificationError.prototype);
2761
+ this.name = "WebhookVerificationError";
2762
+ }
2763
+ };
2764
+ function base64Decode(input) {
2765
+ const clean = input.replace(/=+$/, "");
2766
+ if (input.length < 4 || input.length - clean.length > 2) throw new Error("Base64Coder: incorrect padding");
2767
+ if (clean.length % 4 === 1) throw new Error("Base64Coder: incorrect characters for decoding");
2768
+ const out = new Uint8Array(Math.floor(clean.length * 3 / 4));
2769
+ let acc = 0;
2770
+ let bits = 0;
2771
+ let n = 0;
2772
+ for (let i = 0; i < clean.length; i++) {
2773
+ const v = B64.indexOf(clean[i]);
2774
+ if (v < 0) throw new Error("Base64Coder: incorrect characters for decoding");
2775
+ acc = acc << 6 | v;
2776
+ bits += 6;
2777
+ if (bits >= 8) {
2778
+ bits -= 8;
2779
+ out[n++] = acc >> bits & 255;
2780
+ acc &= (1 << bits) - 1;
2781
+ }
2782
+ }
2783
+ return out;
2784
+ }
2785
+ function base64Encode(bytes) {
2786
+ let out = "";
2787
+ for (let i = 0; i < bytes.length; i += 3) {
2788
+ const n = bytes[i] << 16 | (bytes[i + 1] ?? 0) << 8 | (bytes[i + 2] ?? 0);
2789
+ out += B64[n >> 18 & 63] + B64[n >> 12 & 63];
2790
+ out += i + 1 < bytes.length ? B64[n >> 6 & 63] : "=";
2791
+ out += i + 2 < bytes.length ? B64[n & 63] : "=";
2792
+ }
2793
+ return out;
2794
+ }
2795
+ function timingSafeEqual(a, b) {
2796
+ if (a.length !== b.length) return false;
2797
+ let diff = 0;
2798
+ for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
2799
+ return diff === 0;
2800
+ }
2801
+ function toPayloadString(payload) {
2802
+ if (typeof payload === "string") return payload;
2803
+ if (payload?.constructor?.name === "Buffer") return String(payload);
2804
+ throw new Error("Expected payload to be of type string or Buffer.");
2805
+ }
2806
+ function verify(input) {
2807
+ const secret = input.webhookSecret;
2808
+ if (typeof secret !== "string") throw new Error("Expected secret to be of type string");
2809
+ const key = base64Decode(secret.startsWith(PREFIX) ? secret.slice(PREFIX.length) : secret);
2810
+ if (key.length === 0) throw new Error("Secret can't be empty.");
2811
+ const { id, timestamp: timestampHeader, signature } = input.headers ?? {};
2812
+ if (!signature || !id || !timestampHeader) throw new WebhookVerificationError("Missing required headers");
2813
+ const now = Math.floor(Date.now() / 1e3);
2814
+ const timestamp = parseInt(timestampHeader, 10);
2815
+ if (Number.isNaN(timestamp)) throw new WebhookVerificationError("Invalid Signature Headers");
2816
+ if (now - timestamp > TOLERANCE_SECONDS) throw new WebhookVerificationError("Message timestamp too old");
2817
+ if (timestamp > now + TOLERANCE_SECONDS) throw new WebhookVerificationError("Message timestamp too new");
2818
+ const body = toPayloadString(input.payload);
2819
+ const encoder = new TextEncoder();
2820
+ const expected = encoder.encode(
2821
+ base64Encode(hmacSha256(key, encoder.encode(`${id}.${timestamp}.${body}`)))
2822
+ );
2823
+ for (const candidate of signature.split(" ")) {
2824
+ const [version, value] = candidate.split(",");
2825
+ if (version !== "v1") continue;
2826
+ if (timingSafeEqual(encoder.encode(value ?? ""), expected)) {
2827
+ return body === "" ? void 0 : JSON.parse(body);
2828
+ }
2829
+ }
2830
+ throw new WebhookVerificationError("No matching signature found");
2831
+ }
2832
+
2833
+ // src/resources.ts
2834
+ function camel2(snake) {
2835
+ return snake.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
2836
+ }
2837
+ var CALL_STYLE_OVERRIDES = {
2838
+ "apiKeys.update": "idBody",
2839
+ "templates.update": "idBody",
2840
+ "webhooks.update": "idBody",
2841
+ // Resend : `publish(identifier, requestOptions?)`. Le `versionId` optionnel de Smartletter n'y a pas de place.
2842
+ "templates.publish": "id"
2843
+ };
2844
+ function callStyle(op) {
2845
+ const forced = CALL_STYLE_OVERRIDES[op.id];
2846
+ if (forced) return forced;
2847
+ return op.pathParams.length === 1 && !op.body && !op.query && !op.rawBody && !op.bodyIsArray ? "id" : "params";
2848
+ }
2849
+ function makeLeaf(client, op) {
2850
+ const style = callStyle(op);
2851
+ if (style === "id") {
2852
+ const name = camel2(op.pathParams[0]);
2853
+ return (id, options) => client.call(op, { [name]: id }, options);
2854
+ }
2855
+ if (style === "idBody") {
2856
+ const name = camel2(op.pathParams[0]);
2857
+ return (id, payload, options) => client.call(op, { ...payload, [name]: id }, options);
2858
+ }
2859
+ return (args, options) => {
2860
+ const needsObject = op.pathParams.length > 0 && args === void 0;
2861
+ return client.call(op, needsObject ? {} : args, options);
2862
+ };
2863
+ }
2864
+ function chainable(promise, publish) {
2865
+ return Object.assign(promise, {
2866
+ async publish(options) {
2867
+ const { data, error } = await promise;
2868
+ if (error) return { data: null, error, headers: null };
2869
+ return publish(data.id, options);
2870
+ }
2871
+ });
2872
+ }
2873
+ function makeTemplateMethods(templates) {
2874
+ const create = templates.create;
2875
+ const duplicate = templates.duplicate;
2876
+ const publish = templates.publish;
2877
+ const createWithReact = async (payload, options) => {
2878
+ try {
2879
+ const { react, ...rest } = payload ?? {};
2880
+ const body = react ? { ...rest, html: await renderReact(react) } : payload;
2881
+ return await create(body, options);
2882
+ } catch (err) {
2883
+ const failure = renderFailure(err);
2884
+ if (failure) return failure;
2885
+ throw err;
2886
+ }
2887
+ };
2888
+ templates.create = ((payload, options) => chainable(createWithReact(payload, options), publish));
2889
+ templates.duplicate = ((id, options) => chainable(duplicate(id, options), publish));
2890
+ }
2891
+ function buildResources(client) {
2892
+ const root = {};
2893
+ for (const op of Object.values(OPERATIONS)) {
2894
+ const segments = op.id.split(".");
2895
+ const leaf = segments.pop();
2896
+ let node = root;
2897
+ for (const segment of segments) {
2898
+ const next = node[segment];
2899
+ node = node[segment] = typeof next === "object" ? next : {};
2900
+ }
2901
+ node[leaf] = makeLeaf(client, op);
2902
+ }
2903
+ root.emails.send = makeEmailsSend(client);
2904
+ root.batch.send = makeBatchSend(client);
2905
+ root.emails.create = root.emails.send;
2906
+ root.batch.create = root.batch.send;
2907
+ makeTemplateMethods(root.templates);
2908
+ root.webhooks.verify = verify;
2909
+ return root;
2910
+ }
2911
+
2912
+ // src/index.ts
2913
+ var Smartletter = class extends Client {
2914
+ constructor(key, options = {}) {
2915
+ super(key, options);
2916
+ Object.assign(this, buildResources(this));
2917
+ }
2918
+ };
2919
+ // Annotate the CommonJS export names for ESM import in node:
2920
+ 0 && (module.exports = {
2921
+ Resend,
2922
+ Smartletter,
2923
+ WebhookVerificationError
2924
+ });
2925
+ //# sourceMappingURL=index.cjs.map