samva 0.16.0 → 0.18.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.
Files changed (167) hide show
  1. package/AGENTS.md +9 -1
  2. package/README.md +57 -1
  3. package/dist/{rolldown-runtime-D7D4PA-g.js → _virtual/_rolldown/runtime.js} +1 -1
  4. package/dist/client/client/client.gen.js +174 -0
  5. package/dist/client/client/utils.gen.js +177 -0
  6. package/dist/client/client.gen.js +8 -0
  7. package/dist/client/core/auth.gen.js +12 -0
  8. package/dist/client/core/bodySerializer.gen.js +6 -0
  9. package/dist/client/core/params.gen.js +77 -0
  10. package/dist/client/core/pathSerializer.gen.js +82 -0
  11. package/dist/client/core/serverSentEvents.gen.js +96 -0
  12. package/dist/client/core/utils.gen.js +78 -0
  13. package/dist/client/sdk.gen.d.ts +174 -3
  14. package/dist/{promises-KrA2nSLg.js → client/sdk.gen.js} +464 -2289
  15. package/dist/client/types.gen.d.ts +1126 -11
  16. package/dist/client-attribution.js +9 -0
  17. package/dist/effect/analytics.d.ts +6 -6
  18. package/dist/effect/analytics.js +11 -9
  19. package/dist/effect/api-keys.d.ts +13 -13
  20. package/dist/effect/api-keys.js +13 -12
  21. package/dist/effect/attachments.d.ts +4 -4
  22. package/dist/effect/attachments.js +9 -7
  23. package/dist/effect/brands.d.ts +7 -7
  24. package/dist/effect/brands.js +12 -10
  25. package/dist/effect/campaigns.d.ts +18 -18
  26. package/dist/effect/campaigns.js +17 -15
  27. package/dist/effect/categories.d.ts +2 -2
  28. package/dist/effect/categories.js +95 -1
  29. package/dist/effect/client.d.ts +1 -1
  30. package/dist/effect/client.js +4 -5
  31. package/dist/effect/contact-groups.d.ts +14 -14
  32. package/dist/effect/contact-groups.js +15 -13
  33. package/dist/effect/contacts.d.ts +77 -25
  34. package/dist/effect/contacts.js +27 -22
  35. package/dist/effect/conversations.d.ts +17 -17
  36. package/dist/effect/conversations.js +18 -16
  37. package/dist/effect/custom-fields.d.ts +4 -4
  38. package/dist/effect/custom-fields.js +9 -7
  39. package/dist/effect/email.d.ts +78 -77
  40. package/dist/effect/email.js +68 -65
  41. package/dist/effect/errors.d.ts +2 -0
  42. package/dist/effect/errors.js +3 -0
  43. package/dist/effect/events.d.ts +121 -0
  44. package/dist/effect/events.js +17 -0
  45. package/dist/effect/extension-installations.d.ts +11 -11
  46. package/dist/effect/extension-installations.js +14 -12
  47. package/dist/effect/extensions.d.ts +9 -9
  48. package/dist/effect/extensions.js +10 -8
  49. package/dist/effect/feedback.d.ts +2 -2
  50. package/dist/effect/feedback.js +6 -5
  51. package/dist/effect/generated/analytics.d.ts +715 -0
  52. package/dist/effect/generated/analytics.js +188 -0
  53. package/dist/effect/generated/api-keys.d.ts +1627 -0
  54. package/dist/effect/generated/api-keys.js +249 -0
  55. package/dist/effect/generated/attachments.d.ts +554 -0
  56. package/dist/effect/generated/attachments.js +125 -0
  57. package/dist/effect/generated/brands.d.ts +1118 -0
  58. package/dist/effect/generated/brands.js +155 -0
  59. package/dist/effect/generated/campaigns.d.ts +3783 -0
  60. package/dist/effect/generated/campaigns.js +491 -0
  61. package/dist/effect/generated/contact-events.d.ts +158 -0
  62. package/dist/effect/generated/contact-events.js +37 -0
  63. package/dist/effect/generated/contact-groups.d.ts +1445 -0
  64. package/dist/effect/generated/contact-groups.js +419 -0
  65. package/dist/effect/generated/contacts.d.ts +3789 -0
  66. package/dist/effect/generated/contacts.js +709 -0
  67. package/dist/effect/generated/conversations.d.ts +2870 -0
  68. package/dist/effect/generated/conversations.js +461 -0
  69. package/dist/effect/generated/custom-fields.d.ts +562 -0
  70. package/dist/effect/generated/custom-fields.js +162 -0
  71. package/dist/effect/generated/email.d.ts +10622 -0
  72. package/dist/effect/generated/email.js +2347 -0
  73. package/dist/effect/generated/events.d.ts +463 -0
  74. package/dist/effect/generated/events.js +70 -0
  75. package/dist/effect/generated/extension-installations.d.ts +1786 -0
  76. package/dist/effect/generated/extension-installations.js +382 -0
  77. package/dist/effect/generated/extensions.d.ts +927 -0
  78. package/dist/effect/generated/extensions.js +203 -0
  79. package/dist/effect/generated/feedback.d.ts +116 -0
  80. package/dist/effect/generated/feedback.js +43 -0
  81. package/dist/effect/generated/index.d.ts +61 -0
  82. package/dist/effect/generated/journeys.d.ts +6135 -0
  83. package/dist/effect/generated/journeys.js +464 -0
  84. package/dist/effect/generated/mailboxes.d.ts +13641 -0
  85. package/dist/effect/generated/mailboxes.js +2312 -0
  86. package/dist/effect/generated/media.d.ts +741 -0
  87. package/dist/effect/generated/media.js +181 -0
  88. package/dist/effect/generated/messages.d.ts +2355 -0
  89. package/dist/effect/generated/messages.js +671 -0
  90. package/dist/effect/generated/namespaces.d.ts +654 -0
  91. package/dist/effect/generated/namespaces.js +135 -0
  92. package/dist/effect/generated/operations.d.ts +514 -0
  93. package/dist/effect/generated/operations.js +80 -0
  94. package/dist/effect/generated/organizations.d.ts +1111 -0
  95. package/dist/effect/generated/organizations.js +231 -0
  96. package/dist/effect/generated/scheduled-messages.d.ts +1798 -0
  97. package/dist/effect/generated/scheduled-messages.js +190 -0
  98. package/dist/effect/generated/shared.d.ts +3250 -0
  99. package/dist/effect/generated/shared.js +1053 -0
  100. package/dist/effect/generated/subscriptions.d.ts +188 -0
  101. package/dist/effect/generated/subscriptions.js +61 -0
  102. package/dist/effect/generated/templates.d.ts +8177 -0
  103. package/dist/effect/generated/templates.js +2214 -0
  104. package/dist/effect/generated/unsubscribe-groups.d.ts +1153 -0
  105. package/dist/effect/generated/unsubscribe-groups.js +267 -0
  106. package/dist/effect/generated/webhooks.d.ts +1697 -0
  107. package/dist/effect/generated/webhooks.js +500 -0
  108. package/dist/effect/generated/whoami.d.ts +291 -0
  109. package/dist/effect/generated/whoami.js +54 -0
  110. package/dist/effect/generated-metadata.d.ts +1627 -0
  111. package/dist/effect/generated-metadata.js +919 -0
  112. package/dist/effect/index.d.ts +3 -2
  113. package/dist/effect/index.js +33 -31
  114. package/dist/effect/internal/client.d.ts +10 -7
  115. package/dist/effect/internal/client.js +69 -0
  116. package/dist/effect/internal/email-sender.d.ts +17 -0
  117. package/dist/effect/internal/email-sender.js +21 -0
  118. package/dist/effect/internal/mailbox-events.js +33 -0
  119. package/dist/effect/internal/operation.d.ts +12 -72
  120. package/dist/effect/internal/operation.js +116 -0
  121. package/dist/effect/internal/send.d.ts +60 -0
  122. package/dist/effect/internal/send.js +56 -0
  123. package/dist/effect/journeys.d.ts +2153 -0
  124. package/dist/effect/journeys.js +39 -0
  125. package/dist/effect/mailboxes.d.ts +80 -80
  126. package/dist/effect/mailboxes.js +135 -3
  127. package/dist/effect/media.d.ts +5 -5
  128. package/dist/effect/media.js +10 -8
  129. package/dist/effect/messages.d.ts +16 -16
  130. package/dist/effect/messages.js +15 -12
  131. package/dist/effect/namespaces.d.ts +7 -7
  132. package/dist/effect/namespaces.js +10 -8
  133. package/dist/effect/operations.d.ts +5 -5
  134. package/dist/effect/operations.js +8 -6
  135. package/dist/effect/organizations.d.ts +7 -7
  136. package/dist/effect/organizations.js +12 -10
  137. package/dist/effect/pagination.js +39 -0
  138. package/dist/effect/retry.js +3 -3
  139. package/dist/effect/runtime.js +25 -0
  140. package/dist/effect/scheduled-messages.d.ts +7 -7
  141. package/dist/effect/scheduled-messages.js +10 -8
  142. package/dist/effect/subscriptions.d.ts +1 -1
  143. package/dist/effect/subscriptions.js +5 -4
  144. package/dist/effect/templates.d.ts +40 -40
  145. package/dist/effect/templates.js +39 -37
  146. package/dist/effect/unsubscribe-groups.d.ts +11 -11
  147. package/dist/effect/unsubscribe-groups.js +14 -12
  148. package/dist/effect/webhooks.d.ts +23 -23
  149. package/dist/effect/webhooks.js +16 -14
  150. package/dist/effect/whoami.d.ts +1 -1
  151. package/dist/effect/whoami.js +5 -4
  152. package/dist/index.js +4 -3
  153. package/dist/{inline-attachments-Cegg6tTF.js → inline-attachments.js} +13 -7
  154. package/dist/{mailbox-events-VKR4f3qq.js → mailbox-events.js} +2 -2
  155. package/dist/{normalize-B79uJIeb.js → normalize.js} +2 -2
  156. package/dist/package.js +6 -0
  157. package/dist/promises/errors.gen.js +1340 -0
  158. package/dist/promises/index.d.ts +7 -3
  159. package/dist/promises/index.js +288 -3
  160. package/dist/promises/types.gen.d.ts +1 -1
  161. package/dist/service-map.d.ts +85 -0
  162. package/dist/{operation-BTXjPrwf.js → service-map.js} +58 -219
  163. package/package.json +17 -3
  164. package/dist/categories-DV51kr2H.js +0 -187
  165. package/dist/client-BMUew5Wp.js +0 -13794
  166. package/dist/effect/generated.d.ts +0 -64004
  167. package/dist/mailboxes-Thp5z0oX.js +0 -161
@@ -1,679 +1,5 @@
1
- import { a as withUploadedAttachments, n as mediaCreateBody, o as CLIENT_ATTRIBUTION_HEADER, r as planInlineUploads, s as clientAttribution, t as MediaUploadError } from "./inline-attachments-Cegg6tTF.js";
2
- import { t as MailboxEventStream } from "./mailbox-events-VKR4f3qq.js";
3
- import { n as buildMessagesSendPayload, r as replyToEmailsPayload, t as buildEmailSendPayload } from "./normalize-B79uJIeb.js";
4
- //#region src/client/core/bodySerializer.gen.ts
5
- const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
6
- //#endregion
7
- //#region src/client/core/params.gen.ts
8
- const extraPrefixes = Object.entries({
9
- $body_: "body",
10
- $headers_: "headers",
11
- $path_: "path",
12
- $query_: "query"
13
- });
14
- function buildKeyMap(fields, map) {
15
- if (!map) map = /* @__PURE__ */ new Map();
16
- for (const config of fields) if ("in" in config) {
17
- if (config.key) map.set(config.key, {
18
- in: config.in,
19
- map: config.map
20
- });
21
- } else if ("key" in config) map.set(config.key, { map: config.map });
22
- else if (config.args) buildKeyMap(config.args, map);
23
- return map;
24
- }
25
- function stripEmptySlots(params) {
26
- for (const [slot, value] of Object.entries(params)) {
27
- if (slot === "body") continue;
28
- if (value && typeof value === "object" && !Array.isArray(value) && !Object.keys(value).length) delete params[slot];
29
- }
30
- }
31
- function buildClientParams(args, fields) {
32
- const params = {
33
- headers: Object.create(null),
34
- path: Object.create(null),
35
- query: Object.create(null)
36
- };
37
- const map = buildKeyMap(fields);
38
- function writeSlot(slot, key, value) {
39
- let record = params[slot];
40
- if (record === void 0) {
41
- record = Object.create(null);
42
- params[slot] = record;
43
- }
44
- record[key] = value;
45
- }
46
- let config;
47
- for (const [index, arg] of args.entries()) {
48
- if (fields[index]) config = fields[index];
49
- if (!config) continue;
50
- if ("in" in config) {
51
- if (config.key) {
52
- const field = map.get(config.key);
53
- const name = field.map || config.key;
54
- if (field.in) writeSlot(field.in, name, arg);
55
- } else params.body = arg;
56
- } else for (const [key, value] of Object.entries(arg ?? {})) {
57
- const field = map.get(key);
58
- if (field) {
59
- if (field.in) {
60
- const name = field.map || key;
61
- writeSlot(field.in, name, value);
62
- } else params[field.map] = value;
63
- } else {
64
- const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
65
- if (extra) {
66
- const [prefix, slot] = extra;
67
- writeSlot(slot, key.slice(prefix.length), value);
68
- } else if ("allowExtra" in config && config.allowExtra) {
69
- for (const [slot, allowed] of Object.entries(config.allowExtra)) if (allowed) {
70
- writeSlot(slot, key, value);
71
- break;
72
- }
73
- }
74
- }
75
- }
76
- }
77
- stripEmptySlots(params);
78
- return params;
79
- }
80
- //#endregion
81
- //#region src/client/core/serverSentEvents.gen.ts
82
- function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
83
- let lastEventId;
84
- const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
85
- const createStream = async function* () {
86
- let retryDelay = sseDefaultRetryDelay ?? 3e3;
87
- let attempt = 0;
88
- const signal = options.signal ?? new AbortController().signal;
89
- while (true) {
90
- if (signal.aborted) break;
91
- attempt++;
92
- const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
93
- if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
94
- try {
95
- const requestInit = {
96
- redirect: "follow",
97
- ...options,
98
- body: options.serializedBody,
99
- headers,
100
- signal
101
- };
102
- let request = new Request(url, requestInit);
103
- if (onRequest) request = await onRequest(url, requestInit);
104
- const response = await (options.fetch ?? globalThis.fetch)(request);
105
- if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
106
- if (!response.body) throw new Error("No body in SSE response");
107
- const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
108
- let buffer = "";
109
- const abortHandler = () => {
110
- try {
111
- reader.cancel();
112
- } catch {}
113
- };
114
- signal.addEventListener("abort", abortHandler);
115
- try {
116
- while (true) {
117
- const { done, value } = await reader.read();
118
- if (done) break;
119
- buffer += value;
120
- buffer = buffer.replace(/\r\n?/g, "\n");
121
- const chunks = buffer.split("\n\n");
122
- buffer = chunks.pop() ?? "";
123
- for (const chunk of chunks) {
124
- const lines = chunk.split("\n");
125
- const dataLines = [];
126
- let eventName;
127
- for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
128
- else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
129
- else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
130
- else if (line.startsWith("retry:")) {
131
- const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
132
- if (!Number.isNaN(parsed)) retryDelay = parsed;
133
- }
134
- let data;
135
- let parsedJson = false;
136
- if (dataLines.length) {
137
- const rawData = dataLines.join("\n");
138
- try {
139
- data = JSON.parse(rawData);
140
- parsedJson = true;
141
- } catch {
142
- data = rawData;
143
- }
144
- }
145
- if (parsedJson) {
146
- if (responseValidator) await responseValidator(data);
147
- if (responseTransformer) data = await responseTransformer(data);
148
- }
149
- onSseEvent?.({
150
- data,
151
- event: eventName,
152
- id: lastEventId,
153
- retry: retryDelay
154
- });
155
- if (dataLines.length) yield data;
156
- }
157
- }
158
- } finally {
159
- signal.removeEventListener("abort", abortHandler);
160
- reader.releaseLock();
161
- }
162
- break;
163
- } catch (error) {
164
- onSseError?.(error);
165
- if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
166
- const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
167
- await sleep(backoff);
168
- }
169
- }
170
- };
171
- return { stream: createStream() };
172
- }
173
- //#endregion
174
- //#region src/client/core/pathSerializer.gen.ts
175
- const separatorArrayExplode = (style) => {
176
- switch (style) {
177
- case "label": return ".";
178
- case "matrix": return ";";
179
- case "simple": return ",";
180
- default: return "&";
181
- }
182
- };
183
- const separatorArrayNoExplode = (style) => {
184
- switch (style) {
185
- case "form": return ",";
186
- case "pipeDelimited": return "|";
187
- case "spaceDelimited": return "%20";
188
- default: return ",";
189
- }
190
- };
191
- const separatorObjectExplode = (style) => {
192
- switch (style) {
193
- case "label": return ".";
194
- case "matrix": return ";";
195
- case "simple": return ",";
196
- default: return "&";
197
- }
198
- };
199
- const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
200
- if (!explode) {
201
- const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
202
- switch (style) {
203
- case "label": return `.${joinedValues}`;
204
- case "matrix": return `;${name}=${joinedValues}`;
205
- case "simple": return joinedValues;
206
- default: return `${name}=${joinedValues}`;
207
- }
208
- }
209
- const separator = separatorArrayExplode(style);
210
- const joinedValues = value.map((v) => {
211
- if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
212
- return serializePrimitiveParam({
213
- allowReserved,
214
- name,
215
- value: v
216
- });
217
- }).join(separator);
218
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
219
- };
220
- const serializePrimitiveParam = ({ allowReserved, name, value }) => {
221
- if (value === void 0 || value === null) return "";
222
- if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
223
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
224
- };
225
- const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
226
- if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
227
- if (style !== "deepObject" && !explode) {
228
- let values = [];
229
- Object.entries(value).forEach(([key, v]) => {
230
- values = [
231
- ...values,
232
- key,
233
- allowReserved ? v : encodeURIComponent(v)
234
- ];
235
- });
236
- const joinedValues = values.join(",");
237
- switch (style) {
238
- case "form": return `${name}=${joinedValues}`;
239
- case "label": return `.${joinedValues}`;
240
- case "matrix": return `;${name}=${joinedValues}`;
241
- default: return joinedValues;
242
- }
243
- }
244
- const separator = separatorObjectExplode(style);
245
- const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
246
- allowReserved,
247
- name: style === "deepObject" ? `${name}[${key}]` : key,
248
- value: v
249
- })).join(separator);
250
- return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
251
- };
252
- //#endregion
253
- //#region src/client/core/utils.gen.ts
254
- const PATH_PARAM_RE = /\{[^{}]+\}/g;
255
- const defaultPathSerializer = ({ path, url: _url }) => {
256
- let url = _url;
257
- const matches = _url.match(PATH_PARAM_RE);
258
- if (matches) for (const match of matches) {
259
- let explode = false;
260
- let name = match.substring(1, match.length - 1);
261
- let style = "simple";
262
- if (name.endsWith("*")) {
263
- explode = true;
264
- name = name.substring(0, name.length - 1);
265
- }
266
- if (name.startsWith(".")) {
267
- name = name.substring(1);
268
- style = "label";
269
- } else if (name.startsWith(";")) {
270
- name = name.substring(1);
271
- style = "matrix";
272
- }
273
- const value = path[name];
274
- if (value === void 0 || value === null) continue;
275
- if (Array.isArray(value)) {
276
- url = url.replace(match, serializeArrayParam({
277
- explode,
278
- name,
279
- style,
280
- value
281
- }));
282
- continue;
283
- }
284
- if (typeof value === "object") {
285
- url = url.replace(match, serializeObjectParam({
286
- explode,
287
- name,
288
- style,
289
- value,
290
- valueOnly: true
291
- }));
292
- continue;
293
- }
294
- if (style === "matrix") {
295
- url = url.replace(match, `;${serializePrimitiveParam({
296
- name,
297
- value
298
- })}`);
299
- continue;
300
- }
301
- const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
302
- url = url.replace(match, replaceValue);
303
- }
304
- return url;
305
- };
306
- const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
307
- const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
308
- let url = (baseUrl ?? "") + pathUrl;
309
- if (path) url = defaultPathSerializer({
310
- path,
311
- url
312
- });
313
- let search = query ? querySerializer(query) : "";
314
- if (search.startsWith("?")) search = search.substring(1);
315
- if (search) url += `?${search}`;
316
- return url;
317
- };
318
- function getValidRequestBody(options) {
319
- const hasBody = options.body !== void 0;
320
- if (hasBody && options.bodySerializer) {
321
- if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
322
- return options.body !== "" ? options.body : null;
323
- }
324
- if (hasBody) return options.body;
325
- }
326
- //#endregion
327
- //#region src/client/core/auth.gen.ts
328
- const getAuthToken = async (auth, callback) => {
329
- const token = typeof callback === "function" ? await callback(auth) : callback;
330
- if (!token) return;
331
- if (auth.scheme === "bearer") return `Bearer ${token}`;
332
- if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
333
- return token;
334
- };
335
- //#endregion
336
- //#region src/client/client/utils.gen.ts
337
- const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
338
- const querySerializer = (queryParams) => {
339
- const search = [];
340
- if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
341
- const value = queryParams[name];
342
- if (value === void 0 || value === null) continue;
343
- const options = parameters[name] || args;
344
- if (Array.isArray(value)) {
345
- const serializedArray = serializeArrayParam({
346
- allowReserved: options.allowReserved,
347
- explode: true,
348
- name,
349
- style: "form",
350
- value,
351
- ...options.array
352
- });
353
- if (serializedArray) search.push(serializedArray);
354
- } else if (typeof value === "object") {
355
- const serializedObject = serializeObjectParam({
356
- allowReserved: options.allowReserved,
357
- explode: true,
358
- name,
359
- style: "deepObject",
360
- value,
361
- ...options.object
362
- });
363
- if (serializedObject) search.push(serializedObject);
364
- } else {
365
- const serializedPrimitive = serializePrimitiveParam({
366
- allowReserved: options.allowReserved,
367
- name,
368
- value
369
- });
370
- if (serializedPrimitive) search.push(serializedPrimitive);
371
- }
372
- }
373
- return search.join("&");
374
- };
375
- return querySerializer;
376
- };
377
- /**
378
- * Infers parseAs value from provided Content-Type header.
379
- */
380
- const getParseAs = (contentType) => {
381
- if (!contentType) return "stream";
382
- const cleanContent = contentType.split(";")[0]?.trim();
383
- if (!cleanContent) return;
384
- if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
385
- if (cleanContent === "multipart/form-data") return "formData";
386
- if ([
387
- "application/",
388
- "audio/",
389
- "image/",
390
- "video/"
391
- ].some((type) => cleanContent.startsWith(type))) return "blob";
392
- if (cleanContent.startsWith("text/")) return "text";
393
- };
394
- const checkForExistence = (options, name) => {
395
- if (!name) return false;
396
- if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
397
- return false;
398
- };
399
- async function setAuthParams(options) {
400
- for (const auth of options.security ?? []) {
401
- if (checkForExistence(options, auth.name)) continue;
402
- const token = await getAuthToken(auth, options.auth);
403
- if (!token) continue;
404
- const name = auth.name ?? "Authorization";
405
- switch (auth.in) {
406
- case "query":
407
- if (!options.query) options.query = {};
408
- options.query[name] = token;
409
- break;
410
- case "cookie":
411
- options.headers.append("Cookie", `${name}=${token}`);
412
- break;
413
- default: options.headers.set(name, token);
414
- }
415
- }
416
- }
417
- const buildUrl = (options) => getUrl({
418
- baseUrl: options.baseUrl,
419
- path: options.path,
420
- query: options.query,
421
- querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
422
- url: options.url
423
- });
424
- const mergeConfigs = (a, b) => {
425
- const config = {
426
- ...a,
427
- ...b
428
- };
429
- if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
430
- config.headers = mergeHeaders(a.headers, b.headers);
431
- return config;
432
- };
433
- const headersEntries = (headers) => {
434
- const entries = [];
435
- headers.forEach((value, key) => {
436
- entries.push([key, value]);
437
- });
438
- return entries;
439
- };
440
- const mergeHeaders = (...headers) => {
441
- const mergedHeaders = new Headers();
442
- for (const header of headers) {
443
- if (!header) continue;
444
- const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
445
- for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
446
- else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
447
- else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
448
- }
449
- return mergedHeaders;
450
- };
451
- var Interceptors = class {
452
- fns = [];
453
- clear() {
454
- this.fns = [];
455
- }
456
- eject(id) {
457
- const index = this.getInterceptorIndex(id);
458
- if (this.fns[index]) this.fns[index] = null;
459
- }
460
- exists(id) {
461
- const index = this.getInterceptorIndex(id);
462
- return Boolean(this.fns[index]);
463
- }
464
- getInterceptorIndex(id) {
465
- if (typeof id === "number") return this.fns[id] ? id : -1;
466
- return this.fns.indexOf(id);
467
- }
468
- update(id, fn) {
469
- const index = this.getInterceptorIndex(id);
470
- if (this.fns[index]) {
471
- this.fns[index] = fn;
472
- return id;
473
- }
474
- return false;
475
- }
476
- use(fn) {
477
- this.fns.push(fn);
478
- return this.fns.length - 1;
479
- }
480
- };
481
- const createInterceptors = () => ({
482
- error: new Interceptors(),
483
- request: new Interceptors(),
484
- response: new Interceptors()
485
- });
486
- const defaultQuerySerializer = createQuerySerializer({
487
- allowReserved: false,
488
- array: {
489
- explode: true,
490
- style: "form"
491
- },
492
- object: {
493
- explode: true,
494
- style: "deepObject"
495
- }
496
- });
497
- const defaultHeaders = { "Content-Type": "application/json" };
498
- const createConfig = (override = {}) => ({
499
- ...jsonBodySerializer,
500
- headers: defaultHeaders,
501
- parseAs: "auto",
502
- querySerializer: defaultQuerySerializer,
503
- ...override
504
- });
505
- //#endregion
506
- //#region src/client/client/client.gen.ts
507
- const createClient$1 = (config = {}) => {
508
- let _config = mergeConfigs(createConfig(), config);
509
- const getConfig = () => ({ ..._config });
510
- const setConfig = (config) => {
511
- _config = mergeConfigs(_config, config);
512
- return getConfig();
513
- };
514
- const interceptors = createInterceptors();
515
- const beforeRequest = async (options) => {
516
- const opts = {
517
- ..._config,
518
- ...options,
519
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
520
- headers: mergeHeaders(_config.headers, options.headers),
521
- serializedBody: void 0
522
- };
523
- if (opts.security) await setAuthParams(opts);
524
- if (opts.requestValidator) await opts.requestValidator(opts);
525
- if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
526
- if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
527
- const resolvedOpts = opts;
528
- return {
529
- opts: resolvedOpts,
530
- url: buildUrl(resolvedOpts)
531
- };
532
- };
533
- const request = async (options) => {
534
- const throwOnError = options.throwOnError ?? _config.throwOnError;
535
- const responseStyle = options.responseStyle ?? _config.responseStyle;
536
- let request;
537
- let response;
538
- try {
539
- const { opts, url } = await beforeRequest(options);
540
- const requestInit = {
541
- redirect: "follow",
542
- ...opts,
543
- body: getValidRequestBody(opts)
544
- };
545
- request = new Request(url, requestInit);
546
- for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
547
- const _fetch = opts.fetch;
548
- response = await _fetch(request);
549
- for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
550
- const result = {
551
- request,
552
- response
553
- };
554
- if (response.ok) {
555
- const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
556
- if (response.status === 204 || response.headers.get("Content-Length") === "0") {
557
- let emptyData;
558
- switch (parseAs) {
559
- case "arrayBuffer":
560
- case "blob":
561
- case "text":
562
- emptyData = await response[parseAs]();
563
- break;
564
- case "formData":
565
- emptyData = new FormData();
566
- break;
567
- case "stream":
568
- emptyData = response.body;
569
- break;
570
- default: emptyData = {};
571
- }
572
- return opts.responseStyle === "data" ? emptyData : {
573
- data: emptyData,
574
- ...result
575
- };
576
- }
577
- let data;
578
- switch (parseAs) {
579
- case "arrayBuffer":
580
- case "blob":
581
- case "formData":
582
- case "text":
583
- data = await response[parseAs]();
584
- break;
585
- case "json": {
586
- const text = await response.text();
587
- data = text ? JSON.parse(text) : {};
588
- break;
589
- }
590
- case "stream": return opts.responseStyle === "data" ? response.body : {
591
- data: response.body,
592
- ...result
593
- };
594
- }
595
- if (parseAs === "json") {
596
- if (opts.responseValidator) await opts.responseValidator(data);
597
- if (opts.responseTransformer) data = await opts.responseTransformer(data);
598
- }
599
- return opts.responseStyle === "data" ? data : {
600
- data,
601
- ...result
602
- };
603
- }
604
- const textError = await response.text();
605
- let jsonError;
606
- try {
607
- jsonError = JSON.parse(textError);
608
- } catch {}
609
- throw jsonError ?? textError;
610
- } catch (error) {
611
- let finalError = error;
612
- for (const fn of interceptors.error.fns) if (fn) finalError = await fn(finalError, response, request, options);
613
- finalError = finalError || {};
614
- if (throwOnError) throw finalError;
615
- return responseStyle === "data" ? void 0 : {
616
- error: finalError,
617
- request,
618
- response
619
- };
620
- }
621
- };
622
- const makeMethodFn = (method) => (options) => request({
623
- ...options,
624
- method
625
- });
626
- const makeSseFn = (method) => async (options) => {
627
- const { opts, url } = await beforeRequest(options);
628
- return createSseClient({
629
- ...opts,
630
- body: opts.body,
631
- method,
632
- onRequest: async (url, init) => {
633
- let request = new Request(url, init);
634
- for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
635
- return request;
636
- },
637
- serializedBody: getValidRequestBody(opts),
638
- url
639
- });
640
- };
641
- const _buildUrl = (options) => buildUrl({
642
- ..._config,
643
- ...options
644
- });
645
- return {
646
- buildUrl: _buildUrl,
647
- connect: makeMethodFn("CONNECT"),
648
- delete: makeMethodFn("DELETE"),
649
- get: makeMethodFn("GET"),
650
- getConfig,
651
- head: makeMethodFn("HEAD"),
652
- interceptors,
653
- options: makeMethodFn("OPTIONS"),
654
- patch: makeMethodFn("PATCH"),
655
- post: makeMethodFn("POST"),
656
- put: makeMethodFn("PUT"),
657
- request,
658
- setConfig,
659
- sse: {
660
- connect: makeSseFn("CONNECT"),
661
- delete: makeSseFn("DELETE"),
662
- get: makeSseFn("GET"),
663
- head: makeSseFn("HEAD"),
664
- options: makeSseFn("OPTIONS"),
665
- patch: makeSseFn("PATCH"),
666
- post: makeSseFn("POST"),
667
- put: makeSseFn("PUT"),
668
- trace: makeSseFn("TRACE")
669
- },
670
- trace: makeMethodFn("TRACE")
671
- };
672
- };
673
- //#endregion
674
- //#region src/client/client.gen.ts
675
- const client = createClient$1(createConfig({ baseUrl: "https://api.samva.dev" }));
676
- //#endregion
1
+ import { buildClientParams } from "./core/params.gen.js";
2
+ import { client } from "./client.gen.js";
677
3
  //#region src/client/sdk.gen.ts
678
4
  var Messages = class {
679
5
  /**
@@ -4723,6 +4049,466 @@ var Contacts = class {
4723
4049
  });
4724
4050
  }
4725
4051
  };
4052
+ var Events = class {
4053
+ /**
4054
+ * Record a contact event
4055
+ *
4056
+ * Records a custom contact event. Identify the contact by exactly one ID, external ID, or email. A missing email or external ID creates a contact; an unknown contact ID returns 404. An organization-scoped idempotency key replays the original event. Event names use letters, digits, underscores, hyphens, and dots, up to 255 characters; contact. and samva. prefixes are reserved. Properties allow at most 50 keys and 32 KiB of UTF-8 JSON. Events are retained for 90 days.
4057
+ */
4058
+ static create(parameters, options) {
4059
+ const params = buildClientParams([parameters], [{ args: [
4060
+ {
4061
+ in: "body",
4062
+ key: "contact"
4063
+ },
4064
+ {
4065
+ in: "body",
4066
+ key: "name"
4067
+ },
4068
+ {
4069
+ in: "body",
4070
+ key: "properties"
4071
+ },
4072
+ {
4073
+ in: "body",
4074
+ key: "occurredAt"
4075
+ },
4076
+ {
4077
+ in: "body",
4078
+ key: "idempotencyKey"
4079
+ }
4080
+ ] }]);
4081
+ return (options?.client ?? client).post({
4082
+ security: [{
4083
+ name: "x-api-key",
4084
+ type: "apiKey"
4085
+ }],
4086
+ url: "/v1/events",
4087
+ ...options,
4088
+ ...params,
4089
+ headers: {
4090
+ "Content-Type": "application/json",
4091
+ ...options?.headers,
4092
+ ...params.headers
4093
+ }
4094
+ });
4095
+ }
4096
+ /**
4097
+ * Record contact events in a batch
4098
+ *
4099
+ * Validates the full request shape, contact references, and event names before processing. A schema failure rejects the entire batch without writes. Between 1 and 100 valid entries are then processed in input order, with independent indexed results for properties limits, contact resolution, and idempotency.
4100
+ */
4101
+ static batch(parameters, options) {
4102
+ const params = buildClientParams([parameters], [{ args: [{
4103
+ in: "body",
4104
+ key: "events"
4105
+ }] }]);
4106
+ return (options?.client ?? client).post({
4107
+ security: [{
4108
+ name: "x-api-key",
4109
+ type: "apiKey"
4110
+ }],
4111
+ url: "/v1/events/batch",
4112
+ ...options,
4113
+ ...params,
4114
+ headers: {
4115
+ "Content-Type": "application/json",
4116
+ ...options?.headers,
4117
+ ...params.headers
4118
+ }
4119
+ });
4120
+ }
4121
+ };
4122
+ var ContactEvents = class {
4123
+ /**
4124
+ * List contact events
4125
+ *
4126
+ * Returns custom and Samva lifecycle events, newest occurrence first, within the 90-day retention window. Pass nextCursor back as cursor for the next page.
4127
+ */
4128
+ static listEvents(parameters, options) {
4129
+ const params = buildClientParams([parameters], [{ args: [
4130
+ {
4131
+ in: "path",
4132
+ key: "id"
4133
+ },
4134
+ {
4135
+ in: "query",
4136
+ key: "limit"
4137
+ },
4138
+ {
4139
+ in: "query",
4140
+ key: "cursor"
4141
+ }
4142
+ ] }]);
4143
+ return (options?.client ?? client).get({
4144
+ security: [{
4145
+ name: "x-api-key",
4146
+ type: "apiKey"
4147
+ }],
4148
+ url: "/v1/contacts/{id}/events",
4149
+ ...options,
4150
+ ...params
4151
+ });
4152
+ }
4153
+ };
4154
+ var Journeys = class {
4155
+ /**
4156
+ * List journeys
4157
+ *
4158
+ * Returns the organization's journeys, newest first, optionally filtered by status. Pass nextCursor back as cursor for the next page.
4159
+ */
4160
+ static list(parameters, options) {
4161
+ const params = buildClientParams([parameters], [{ args: [
4162
+ {
4163
+ in: "query",
4164
+ key: "status"
4165
+ },
4166
+ {
4167
+ in: "query",
4168
+ key: "limit"
4169
+ },
4170
+ {
4171
+ in: "query",
4172
+ key: "cursor"
4173
+ }
4174
+ ] }]);
4175
+ return (options?.client ?? client).get({
4176
+ security: [{
4177
+ name: "x-api-key",
4178
+ type: "apiKey"
4179
+ }],
4180
+ url: "/v1/journeys",
4181
+ ...options,
4182
+ ...params
4183
+ });
4184
+ }
4185
+ /**
4186
+ * Create a journey
4187
+ *
4188
+ * Creates a draft journey from a definition: a trigger, a root node, and a graph of at most 200 nodes that is acyclic and fully reachable. Templates, senders, and groups the definition names must belong to the organization. Requires a plan that includes journeys.
4189
+ */
4190
+ static create(parameters, options) {
4191
+ const params = buildClientParams([parameters], [{ args: [{
4192
+ in: "body",
4193
+ key: "name"
4194
+ }, {
4195
+ in: "body",
4196
+ key: "definition"
4197
+ }] }]);
4198
+ return (options?.client ?? client).post({
4199
+ security: [{
4200
+ name: "x-api-key",
4201
+ type: "apiKey"
4202
+ }],
4203
+ url: "/v1/journeys",
4204
+ ...options,
4205
+ ...params,
4206
+ headers: {
4207
+ "Content-Type": "application/json",
4208
+ ...options?.headers,
4209
+ ...params.headers
4210
+ }
4211
+ });
4212
+ }
4213
+ /**
4214
+ * Delete a journey
4215
+ *
4216
+ * Deletes a journey that was never published or is archived, with its versions and runs. An active or paused journey returns 409; archive it first.
4217
+ */
4218
+ static remove(parameters, options) {
4219
+ const params = buildClientParams([parameters], [{ args: [{
4220
+ in: "path",
4221
+ key: "id"
4222
+ }] }]);
4223
+ return (options?.client ?? client).delete({
4224
+ security: [{
4225
+ name: "x-api-key",
4226
+ type: "apiKey"
4227
+ }],
4228
+ url: "/v1/journeys/{id}",
4229
+ ...options,
4230
+ ...params
4231
+ });
4232
+ }
4233
+ /**
4234
+ * Get a journey
4235
+ *
4236
+ * Returns a journey with its draft definition, its current revision, and its newest published version number.
4237
+ */
4238
+ static get(parameters, options) {
4239
+ const params = buildClientParams([parameters], [{ args: [{
4240
+ in: "path",
4241
+ key: "id"
4242
+ }] }]);
4243
+ return (options?.client ?? client).get({
4244
+ security: [{
4245
+ name: "x-api-key",
4246
+ type: "apiKey"
4247
+ }],
4248
+ url: "/v1/journeys/{id}",
4249
+ ...options,
4250
+ ...params
4251
+ });
4252
+ }
4253
+ /**
4254
+ * Rename a journey
4255
+ *
4256
+ * Renames a journey.
4257
+ */
4258
+ static update(parameters, options) {
4259
+ const params = buildClientParams([parameters], [{ args: [{
4260
+ in: "path",
4261
+ key: "id"
4262
+ }, {
4263
+ in: "body",
4264
+ key: "name"
4265
+ }] }]);
4266
+ return (options?.client ?? client).patch({
4267
+ security: [{
4268
+ name: "x-api-key",
4269
+ type: "apiKey"
4270
+ }],
4271
+ url: "/v1/journeys/{id}",
4272
+ ...options,
4273
+ ...params,
4274
+ headers: {
4275
+ "Content-Type": "application/json",
4276
+ ...options?.headers,
4277
+ ...params.headers
4278
+ }
4279
+ });
4280
+ }
4281
+ /**
4282
+ * Replace a journey draft
4283
+ *
4284
+ * Replaces the draft definition and returns the journey with a new revision. The request names the revision it read; a stale revision returns 409. Published versions and the runs on them do not change.
4285
+ */
4286
+ static replaceDraft(parameters, options) {
4287
+ const params = buildClientParams([parameters], [{ args: [
4288
+ {
4289
+ in: "path",
4290
+ key: "id"
4291
+ },
4292
+ {
4293
+ in: "body",
4294
+ key: "revision"
4295
+ },
4296
+ {
4297
+ in: "body",
4298
+ key: "definition"
4299
+ }
4300
+ ] }]);
4301
+ return (options?.client ?? client).put({
4302
+ security: [{
4303
+ name: "x-api-key",
4304
+ type: "apiKey"
4305
+ }],
4306
+ url: "/v1/journeys/{id}/draft",
4307
+ ...options,
4308
+ ...params,
4309
+ headers: {
4310
+ "Content-Type": "application/json",
4311
+ ...options?.headers,
4312
+ ...params.headers
4313
+ }
4314
+ });
4315
+ }
4316
+ /**
4317
+ * Publish a journey
4318
+ *
4319
+ * Publishes the draft as the next immutable version; new runs start on it and existing runs stay on the version they entered. The request names the revision it read; a stale revision returns 409. Publishing a draft identical to the newest version changes nothing. A draft journey becomes active; a paused journey stays paused. A published version sends and updates tags as its publisher, so a draft with a send_email node requires a key that can send email and one with an update_tags node requires contacts:update; without them the request returns 403.
4320
+ */
4321
+ static publish(parameters, options) {
4322
+ const params = buildClientParams([parameters], [{ args: [{
4323
+ in: "path",
4324
+ key: "id"
4325
+ }, {
4326
+ in: "body",
4327
+ key: "revision"
4328
+ }] }]);
4329
+ return (options?.client ?? client).post({
4330
+ security: [{
4331
+ name: "x-api-key",
4332
+ type: "apiKey"
4333
+ }],
4334
+ url: "/v1/journeys/{id}/publish",
4335
+ ...options,
4336
+ ...params,
4337
+ headers: {
4338
+ "Content-Type": "application/json",
4339
+ ...options?.headers,
4340
+ ...params.headers
4341
+ }
4342
+ });
4343
+ }
4344
+ /**
4345
+ * Pause a journey
4346
+ *
4347
+ * Stops new enrollment and holds every live run before its next node, including a run whose wait ends while the journey is paused. Held runs report status paused.
4348
+ */
4349
+ static pause(parameters, options) {
4350
+ const params = buildClientParams([parameters], [{ args: [{
4351
+ in: "path",
4352
+ key: "id"
4353
+ }] }]);
4354
+ return (options?.client ?? client).post({
4355
+ security: [{
4356
+ name: "x-api-key",
4357
+ type: "apiKey"
4358
+ }],
4359
+ url: "/v1/journeys/{id}/pause",
4360
+ ...options,
4361
+ ...params
4362
+ });
4363
+ }
4364
+ /**
4365
+ * Resume a journey
4366
+ *
4367
+ * Resumes enrollment and continues the runs the pause held. Requires a plan that includes journeys.
4368
+ */
4369
+ static resume(parameters, options) {
4370
+ const params = buildClientParams([parameters], [{ args: [{
4371
+ in: "path",
4372
+ key: "id"
4373
+ }] }]);
4374
+ return (options?.client ?? client).post({
4375
+ security: [{
4376
+ name: "x-api-key",
4377
+ type: "apiKey"
4378
+ }],
4379
+ url: "/v1/journeys/{id}/resume",
4380
+ ...options,
4381
+ ...params
4382
+ });
4383
+ }
4384
+ /**
4385
+ * Archive a journey
4386
+ *
4387
+ * Stops new enrollment for good and exits every live run with exit reason archived. An archived journey cannot be edited, published, or resumed.
4388
+ */
4389
+ static archive(parameters, options) {
4390
+ const params = buildClientParams([parameters], [{ args: [{
4391
+ in: "path",
4392
+ key: "id"
4393
+ }] }]);
4394
+ return (options?.client ?? client).post({
4395
+ security: [{
4396
+ name: "x-api-key",
4397
+ type: "apiKey"
4398
+ }],
4399
+ url: "/v1/journeys/{id}/archive",
4400
+ ...options,
4401
+ ...params
4402
+ });
4403
+ }
4404
+ /**
4405
+ * Get a published journey version
4406
+ *
4407
+ * Returns the immutable definition of one published version.
4408
+ */
4409
+ static getVersion(parameters, options) {
4410
+ const params = buildClientParams([parameters], [{ args: [{
4411
+ in: "path",
4412
+ key: "id"
4413
+ }, {
4414
+ in: "path",
4415
+ key: "version"
4416
+ }] }]);
4417
+ return (options?.client ?? client).get({
4418
+ security: [{
4419
+ name: "x-api-key",
4420
+ type: "apiKey"
4421
+ }],
4422
+ url: "/v1/journeys/{id}/versions/{version}",
4423
+ ...options,
4424
+ ...params
4425
+ });
4426
+ }
4427
+ /**
4428
+ * Get journey run counts
4429
+ *
4430
+ * Counts one published version's runs by status, and per node the live runs there now and the runs that have entered it. Defaults to the newest published version.
4431
+ */
4432
+ static stats(parameters, options) {
4433
+ const params = buildClientParams([parameters], [{ args: [{
4434
+ in: "path",
4435
+ key: "id"
4436
+ }, {
4437
+ in: "query",
4438
+ key: "version"
4439
+ }] }]);
4440
+ return (options?.client ?? client).get({
4441
+ security: [{
4442
+ name: "x-api-key",
4443
+ type: "apiKey"
4444
+ }],
4445
+ url: "/v1/journeys/{id}/stats",
4446
+ ...options,
4447
+ ...params
4448
+ });
4449
+ }
4450
+ /**
4451
+ * List journey runs
4452
+ *
4453
+ * Returns a journey's runs, newest first, optionally filtered by status or contact. Pass nextCursor back as cursor for the next page.
4454
+ */
4455
+ static listRuns(parameters, options) {
4456
+ const params = buildClientParams([parameters], [{ args: [
4457
+ {
4458
+ in: "path",
4459
+ key: "id"
4460
+ },
4461
+ {
4462
+ in: "query",
4463
+ key: "status"
4464
+ },
4465
+ {
4466
+ in: "query",
4467
+ key: "contactId"
4468
+ },
4469
+ {
4470
+ in: "query",
4471
+ key: "limit"
4472
+ },
4473
+ {
4474
+ in: "query",
4475
+ key: "cursor"
4476
+ }
4477
+ ] }]);
4478
+ return (options?.client ?? client).get({
4479
+ security: [{
4480
+ name: "x-api-key",
4481
+ type: "apiKey"
4482
+ }],
4483
+ url: "/v1/journeys/{id}/runs",
4484
+ ...options,
4485
+ ...params
4486
+ });
4487
+ }
4488
+ /**
4489
+ * Get a journey run
4490
+ *
4491
+ * Returns one run with every node it entered, in order: when it entered and left, how it left, and the message a send node created.
4492
+ */
4493
+ static getRun(parameters, options) {
4494
+ const params = buildClientParams([parameters], [{ args: [{
4495
+ in: "path",
4496
+ key: "id"
4497
+ }, {
4498
+ in: "path",
4499
+ key: "runId"
4500
+ }] }]);
4501
+ return (options?.client ?? client).get({
4502
+ security: [{
4503
+ name: "x-api-key",
4504
+ type: "apiKey"
4505
+ }],
4506
+ url: "/v1/journeys/{id}/runs/{runId}",
4507
+ ...options,
4508
+ ...params
4509
+ });
4510
+ }
4511
+ };
4726
4512
  var Subscriptions = class {
4727
4513
  /**
4728
4514
  * Request subscription confirmation
@@ -10263,1617 +10049,6 @@ var ExtensionInstallations = class {
10263
10049
  }
10264
10050
  };
10265
10051
  //#endregion
10266
- //#region src/promises/errors.gen.ts
10267
- const redactRequest = (request) => request === void 0 ? void 0 : new Request(request.url, { method: request.method });
10268
- /** Base class for failures declared by the public Samva OpenAPI contract. */
10269
- var SamvaApiError = class extends Error {
10270
- request;
10271
- response;
10272
- status;
10273
- constructor(message, context = {}) {
10274
- super(message);
10275
- this.name = new.target.name;
10276
- this.request = redactRequest(context.request);
10277
- this.response = context.response;
10278
- this.status = context.response?.status;
10279
- }
10280
- };
10281
- /** A transport or malformed-response failure that is not part of the API error contract. */
10282
- var SamvaTransportError = class extends Error {
10283
- _tag = "SamvaTransportError";
10284
- request;
10285
- response;
10286
- status;
10287
- cause;
10288
- constructor(cause, context = {}) {
10289
- super(cause instanceof Error ? cause.message : "Samva request failed", { cause });
10290
- this.name = "SamvaTransportError";
10291
- this.cause = cause;
10292
- this.request = redactRequest(context.request);
10293
- this.response = context.response;
10294
- this.status = context.response?.status;
10295
- }
10296
- };
10297
- const messageOf = (tag, payload) => {
10298
- const message = payload.message;
10299
- return typeof message === "string" ? message : tag;
10300
- };
10301
- var AnalyticsQueryError = class extends SamvaApiError {
10302
- _tag = "AnalyticsQueryError";
10303
- constructor(payload, context = {}) {
10304
- super(messageOf("AnalyticsQueryError", payload), context);
10305
- Object.assign(this, payload);
10306
- }
10307
- };
10308
- var BillingProviderError = class extends SamvaApiError {
10309
- _tag = "BillingProviderError";
10310
- constructor(payload, context = {}) {
10311
- super(messageOf("BillingProviderError", payload), context);
10312
- Object.assign(this, payload);
10313
- }
10314
- };
10315
- var BrandAddressRequiredError = class extends SamvaApiError {
10316
- _tag = "BrandAddressRequiredError";
10317
- constructor(payload, context = {}) {
10318
- super(messageOf("BrandAddressRequiredError", payload), context);
10319
- Object.assign(this, payload);
10320
- }
10321
- };
10322
- var CampaignFooterRequiredError = class extends SamvaApiError {
10323
- _tag = "CampaignFooterRequiredError";
10324
- constructor(payload, context = {}) {
10325
- super(messageOf("CampaignFooterRequiredError", payload), context);
10326
- Object.assign(this, payload);
10327
- }
10328
- };
10329
- var ConflictError = class extends SamvaApiError {
10330
- _tag = "ConflictError";
10331
- constructor(payload, context = {}) {
10332
- super(messageOf("ConflictError", payload), context);
10333
- Object.assign(this, payload);
10334
- }
10335
- };
10336
- var DeliveryUnavailableError = class extends SamvaApiError {
10337
- _tag = "DeliveryUnavailableError";
10338
- constructor(payload, context = {}) {
10339
- super(messageOf("DeliveryUnavailableError", payload), context);
10340
- Object.assign(this, payload);
10341
- }
10342
- };
10343
- var EmailChannelError = class extends SamvaApiError {
10344
- _tag = "EmailChannelError";
10345
- constructor(payload, context = {}) {
10346
- super(messageOf("EmailChannelError", payload), context);
10347
- Object.assign(this, payload);
10348
- }
10349
- };
10350
- var ExternalServiceError = class extends SamvaApiError {
10351
- _tag = "ExternalServiceError";
10352
- constructor(payload, context = {}) {
10353
- super(messageOf("ExternalServiceError", payload), context);
10354
- Object.assign(this, payload);
10355
- }
10356
- };
10357
- var FlagDisabledError = class extends SamvaApiError {
10358
- _tag = "FlagDisabledError";
10359
- constructor(payload, context = {}) {
10360
- super(messageOf("FlagDisabledError", payload), context);
10361
- Object.assign(this, payload);
10362
- }
10363
- };
10364
- var ForbiddenError = class extends SamvaApiError {
10365
- _tag = "ForbiddenError";
10366
- constructor(payload, context = {}) {
10367
- super(messageOf("ForbiddenError", payload), context);
10368
- Object.assign(this, payload);
10369
- }
10370
- };
10371
- var GatewayTimeoutError = class extends SamvaApiError {
10372
- _tag = "GatewayTimeoutError";
10373
- constructor(payload, context = {}) {
10374
- super(messageOf("GatewayTimeoutError", payload), context);
10375
- Object.assign(this, payload);
10376
- }
10377
- };
10378
- var InternalError = class extends SamvaApiError {
10379
- _tag = "InternalError";
10380
- constructor(payload, context = {}) {
10381
- super(messageOf("InternalError", payload), context);
10382
- Object.assign(this, payload);
10383
- }
10384
- };
10385
- var MailboxChannelUnsupportedError = class extends SamvaApiError {
10386
- _tag = "MailboxChannelUnsupportedError";
10387
- constructor(payload, context = {}) {
10388
- super(messageOf("MailboxChannelUnsupportedError", payload), context);
10389
- Object.assign(this, payload);
10390
- }
10391
- };
10392
- var MailboxSendConflictError = class extends SamvaApiError {
10393
- _tag = "MailboxSendConflictError";
10394
- constructor(payload, context = {}) {
10395
- super(messageOf("MailboxSendConflictError", payload), context);
10396
- Object.assign(this, payload);
10397
- }
10398
- };
10399
- var MailboxSendRefusedError = class extends SamvaApiError {
10400
- _tag = "MailboxSendRefusedError";
10401
- constructor(payload, context = {}) {
10402
- super(messageOf("MailboxSendRefusedError", payload), context);
10403
- Object.assign(this, payload);
10404
- }
10405
- };
10406
- var OnboardingReviewRequiredError = class extends SamvaApiError {
10407
- _tag = "OnboardingReviewRequiredError";
10408
- constructor(payload, context = {}) {
10409
- super(messageOf("OnboardingReviewRequiredError", payload), context);
10410
- Object.assign(this, payload);
10411
- }
10412
- };
10413
- var PaymentRequiredError = class extends SamvaApiError {
10414
- _tag = "PaymentRequiredError";
10415
- constructor(payload, context = {}) {
10416
- super(messageOf("PaymentRequiredError", payload), context);
10417
- Object.assign(this, payload);
10418
- }
10419
- };
10420
- var RateLimitedError = class extends SamvaApiError {
10421
- _tag = "RateLimitedError";
10422
- constructor(payload, context = {}) {
10423
- super(messageOf("RateLimitedError", payload), context);
10424
- Object.assign(this, payload);
10425
- }
10426
- };
10427
- var ResourceNotFoundError = class extends SamvaApiError {
10428
- _tag = "ResourceNotFoundError";
10429
- constructor(payload, context = {}) {
10430
- super(messageOf("ResourceNotFoundError", payload), context);
10431
- Object.assign(this, payload);
10432
- }
10433
- };
10434
- var SenderNotReadyError = class extends SamvaApiError {
10435
- _tag = "SenderNotReadyError";
10436
- constructor(payload, context = {}) {
10437
- super(messageOf("SenderNotReadyError", payload), context);
10438
- Object.assign(this, payload);
10439
- }
10440
- };
10441
- var UnauthorizedError = class extends SamvaApiError {
10442
- _tag = "UnauthorizedError";
10443
- constructor(payload, context = {}) {
10444
- super(messageOf("UnauthorizedError", payload), context);
10445
- Object.assign(this, payload);
10446
- }
10447
- };
10448
- var ValidationError = class extends SamvaApiError {
10449
- _tag = "ValidationError";
10450
- constructor(payload, context = {}) {
10451
- super(messageOf("ValidationError", payload), context);
10452
- Object.assign(this, payload);
10453
- }
10454
- };
10455
- const constructors = {
10456
- AnalyticsQueryError,
10457
- BillingProviderError,
10458
- BrandAddressRequiredError,
10459
- CampaignFooterRequiredError,
10460
- ConflictError,
10461
- DeliveryUnavailableError,
10462
- EmailChannelError,
10463
- ExternalServiceError,
10464
- FlagDisabledError,
10465
- ForbiddenError,
10466
- GatewayTimeoutError,
10467
- InternalError,
10468
- MailboxChannelUnsupportedError,
10469
- MailboxSendConflictError,
10470
- MailboxSendRefusedError,
10471
- OnboardingReviewRequiredError,
10472
- PaymentRequiredError,
10473
- RateLimitedError,
10474
- ResourceNotFoundError,
10475
- SenderNotReadyError,
10476
- UnauthorizedError,
10477
- ValidationError
10478
- };
10479
- const payloadSchemas = {
10480
- AnalyticsQueryError: {
10481
- type: "object",
10482
- properties: {
10483
- _tag: {
10484
- type: "string",
10485
- enum: ["AnalyticsQueryError"]
10486
- },
10487
- message: { type: "string" }
10488
- },
10489
- required: ["_tag", "message"],
10490
- additionalProperties: false
10491
- },
10492
- BillingProviderError: {
10493
- type: "object",
10494
- properties: {
10495
- _tag: {
10496
- type: "string",
10497
- enum: ["BillingProviderError"]
10498
- },
10499
- message: { type: "string" }
10500
- },
10501
- required: ["_tag", "message"],
10502
- additionalProperties: false,
10503
- "x-category": ["transient"],
10504
- "x-retryable": true
10505
- },
10506
- BrandAddressRequiredError: {
10507
- type: "object",
10508
- properties: {
10509
- _tag: {
10510
- type: "string",
10511
- enum: ["BrandAddressRequiredError"]
10512
- },
10513
- message: { type: "string" },
10514
- brand: { anyOf: [{ type: "string" }, { type: "null" }] }
10515
- },
10516
- required: [
10517
- "_tag",
10518
- "message",
10519
- "brand"
10520
- ],
10521
- additionalProperties: false
10522
- },
10523
- CampaignFooterRequiredError: {
10524
- type: "object",
10525
- properties: {
10526
- _tag: {
10527
- type: "string",
10528
- enum: ["CampaignFooterRequiredError"]
10529
- },
10530
- message: { type: "string" }
10531
- },
10532
- required: ["_tag", "message"],
10533
- additionalProperties: false
10534
- },
10535
- ConflictError: {
10536
- type: "object",
10537
- properties: {
10538
- _tag: {
10539
- type: "string",
10540
- enum: ["ConflictError"]
10541
- },
10542
- message: { type: "string" },
10543
- resource: { type: "string" },
10544
- id: { anyOf: [{ type: "string" }, { type: "null" }] }
10545
- },
10546
- required: [
10547
- "_tag",
10548
- "message",
10549
- "resource"
10550
- ],
10551
- additionalProperties: false,
10552
- "x-category": ["conflict"],
10553
- "x-retryable": false
10554
- },
10555
- DeliveryUnavailableError: {
10556
- type: "object",
10557
- properties: {
10558
- _tag: {
10559
- type: "string",
10560
- enum: ["DeliveryUnavailableError"]
10561
- },
10562
- message: { type: "string" },
10563
- retryAfterSeconds: { type: "number" }
10564
- },
10565
- required: [
10566
- "_tag",
10567
- "message",
10568
- "retryAfterSeconds"
10569
- ],
10570
- additionalProperties: false,
10571
- "x-category": ["transient"],
10572
- "x-retryable": true
10573
- },
10574
- EmailChannelError: {
10575
- type: "object",
10576
- properties: {
10577
- _tag: {
10578
- type: "string",
10579
- enum: ["EmailChannelError"]
10580
- },
10581
- reason: {
10582
- type: "string",
10583
- enum: [
10584
- "transport",
10585
- "rejected",
10586
- "rate_limited",
10587
- "auth"
10588
- ]
10589
- },
10590
- message: { type: "string" },
10591
- statusCode: { anyOf: [{ type: "number" }, { type: "null" }] }
10592
- },
10593
- required: [
10594
- "_tag",
10595
- "reason",
10596
- "message"
10597
- ],
10598
- additionalProperties: false
10599
- },
10600
- ExternalServiceError: {
10601
- type: "object",
10602
- properties: {
10603
- _tag: {
10604
- type: "string",
10605
- enum: ["ExternalServiceError"]
10606
- },
10607
- message: { type: "string" }
10608
- },
10609
- required: ["_tag", "message"],
10610
- additionalProperties: false,
10611
- "x-category": ["transient"],
10612
- "x-retryable": true
10613
- },
10614
- FlagDisabledError: {
10615
- type: "object",
10616
- properties: {
10617
- _tag: {
10618
- type: "string",
10619
- enum: ["FlagDisabledError"]
10620
- },
10621
- flag: { type: "string" },
10622
- message: { type: "string" }
10623
- },
10624
- required: [
10625
- "_tag",
10626
- "flag",
10627
- "message"
10628
- ],
10629
- additionalProperties: false,
10630
- "x-retryable": false
10631
- },
10632
- ForbiddenError: {
10633
- type: "object",
10634
- properties: {
10635
- _tag: {
10636
- type: "string",
10637
- enum: ["ForbiddenError"]
10638
- },
10639
- message: { type: "string" }
10640
- },
10641
- required: ["_tag", "message"],
10642
- additionalProperties: false,
10643
- "x-category": ["auth"],
10644
- "x-retryable": false
10645
- },
10646
- GatewayTimeoutError: {
10647
- type: "object",
10648
- properties: {
10649
- _tag: {
10650
- type: "string",
10651
- enum: ["GatewayTimeoutError"]
10652
- },
10653
- message: { type: "string" },
10654
- retryAfterSeconds: { type: "number" }
10655
- },
10656
- required: [
10657
- "_tag",
10658
- "message",
10659
- "retryAfterSeconds"
10660
- ],
10661
- additionalProperties: false,
10662
- "x-category": ["transient"],
10663
- "x-retryable": true
10664
- },
10665
- InternalError: {
10666
- type: "object",
10667
- properties: {
10668
- _tag: {
10669
- type: "string",
10670
- enum: ["InternalError"]
10671
- },
10672
- message: { type: "string" }
10673
- },
10674
- required: ["_tag", "message"],
10675
- additionalProperties: false,
10676
- "x-category": ["transient"],
10677
- "x-retryable": true
10678
- },
10679
- MailboxChannelUnsupportedError: {
10680
- type: "object",
10681
- properties: {
10682
- _tag: {
10683
- type: "string",
10684
- enum: ["MailboxChannelUnsupportedError"]
10685
- },
10686
- message: { type: "string" },
10687
- channel: { type: "string" }
10688
- },
10689
- required: [
10690
- "_tag",
10691
- "message",
10692
- "channel"
10693
- ],
10694
- additionalProperties: false
10695
- },
10696
- MailboxSendConflictError: {
10697
- type: "object",
10698
- properties: {
10699
- _tag: {
10700
- type: "string",
10701
- enum: ["MailboxSendConflictError"]
10702
- },
10703
- message: { type: "string" },
10704
- resource: { type: "string" },
10705
- id: {
10706
- type: "string",
10707
- pattern: "^mbxact_[0-9a-hjkmnp-tv-z]{16,24}$",
10708
- "x-samva-brand": "MailboxActionId"
10709
- },
10710
- receipt: {
10711
- type: "object",
10712
- properties: {
10713
- actionId: {
10714
- type: "string",
10715
- pattern: "^mbxact_[0-9a-hjkmnp-tv-z]{16,24}$",
10716
- "x-samva-brand": "MailboxActionId"
10717
- },
10718
- draftId: { anyOf: [{
10719
- type: "string",
10720
- pattern: "^mdraft_[0-9a-hjkmnp-tv-z]{16,24}$",
10721
- "x-samva-brand": "MailboxDraftId"
10722
- }, { type: "null" }] },
10723
- messageId: { anyOf: [{
10724
- type: "string",
10725
- pattern: "^msg_[0-9a-hjkmnp-tv-z]{16,24}$",
10726
- "x-samva-brand": "MessageId"
10727
- }, { type: "null" }] },
10728
- threadId: { anyOf: [{
10729
- type: "string",
10730
- pattern: "^thread_[0-9a-hjkmnp-tv-z]{16,24}$",
10731
- "x-samva-brand": "MailboxThreadId"
10732
- }, { type: "null" }] },
10733
- state: {
10734
- type: "string",
10735
- enum: [
10736
- "approvalRequired",
10737
- "queued",
10738
- "accepted",
10739
- "completed",
10740
- "notSent",
10741
- "uncertain"
10742
- ]
10743
- },
10744
- acceptedAt: { anyOf: [{ type: "string" }, { type: "null" }] },
10745
- waitReason: { anyOf: [{
10746
- type: "string",
10747
- enum: [
10748
- "rate",
10749
- "daily-quota",
10750
- "domain-health",
10751
- "sending-paused",
10752
- "upstream-unavailable",
10753
- "retry",
10754
- "campaign-paused",
10755
- "domain-warming",
10756
- "onboarding-review",
10757
- "content-review",
10758
- "screening-unavailable"
10759
- ]
10760
- }, { type: "null" }] },
10761
- reviewExpectedAt: { anyOf: [{ type: "string" }, { type: "null" }] },
10762
- skippedRecipients: {
10763
- type: "array",
10764
- items: {
10765
- type: "object",
10766
- properties: {
10767
- address: { type: "string" },
10768
- reason: {
10769
- type: "string",
10770
- enum: [
10771
- "bounce",
10772
- "complaint",
10773
- "unsubscribe",
10774
- "manual",
10775
- "group-unsubscribe"
10776
- ]
10777
- },
10778
- unsubscribeGroupId: { anyOf: [{
10779
- type: "string",
10780
- pattern: "^unsub_[0-9a-hjkmnp-tv-z]{16,24}$",
10781
- "x-samva-brand": "UnsubscribeId"
10782
- }, { type: "null" }] }
10783
- },
10784
- required: ["address", "reason"],
10785
- additionalProperties: false
10786
- }
10787
- },
10788
- executeUntil: { anyOf: [{ type: "string" }, { type: "null" }] },
10789
- retryAt: { anyOf: [{ type: "string" }, { type: "null" }] },
10790
- problem: { anyOf: [{
10791
- type: "object",
10792
- properties: {
10793
- code: { type: "string" },
10794
- message: { type: "string" },
10795
- error: { anyOf: [{ anyOf: [
10796
- {
10797
- type: "object",
10798
- properties: {
10799
- _tag: {
10800
- type: "string",
10801
- enum: ["SenderNotReadyError"]
10802
- },
10803
- message: { type: "string" },
10804
- sender: { type: "string" },
10805
- retryAfterSeconds: { anyOf: [{ type: "number" }, { type: "null" }] }
10806
- },
10807
- required: [
10808
- "_tag",
10809
- "message",
10810
- "sender"
10811
- ],
10812
- additionalProperties: false
10813
- },
10814
- {
10815
- type: "object",
10816
- properties: {
10817
- _tag: {
10818
- type: "string",
10819
- enum: ["RateLimitedError"]
10820
- },
10821
- message: { type: "string" },
10822
- retryAfterSeconds: { type: "number" }
10823
- },
10824
- required: [
10825
- "_tag",
10826
- "message",
10827
- "retryAfterSeconds"
10828
- ],
10829
- additionalProperties: false
10830
- },
10831
- {
10832
- type: "object",
10833
- properties: {
10834
- _tag: {
10835
- type: "string",
10836
- enum: ["OnboardingReviewRequiredError"]
10837
- },
10838
- message: { type: "string" },
10839
- code: {
10840
- type: "string",
10841
- enum: [
10842
- "review_required",
10843
- "review_in_progress",
10844
- "information_required",
10845
- "review_rejected",
10846
- "identity_review_required",
10847
- "identity_review_rejected",
10848
- "identity_changed"
10849
- ]
10850
- },
10851
- decision: {
10852
- type: "string",
10853
- enum: [
10854
- "undecided",
10855
- "approved",
10856
- "rejected"
10857
- ]
10858
- },
10859
- stage: {
10860
- type: "string",
10861
- enum: [
10862
- "collecting",
10863
- "automated_review",
10864
- "manual_review",
10865
- "information_requested",
10866
- "complete"
10867
- ]
10868
- },
10869
- nextAction: {
10870
- type: "string",
10871
- enum: [
10872
- "wait_for_review",
10873
- "provide_information",
10874
- "verify_sending_identity",
10875
- "reapply",
10876
- "contact_support"
10877
- ]
10878
- },
10879
- identityId: { anyOf: [{ type: "string" }, { type: "null" }] }
10880
- },
10881
- required: [
10882
- "_tag",
10883
- "message",
10884
- "code",
10885
- "decision",
10886
- "stage",
10887
- "nextAction"
10888
- ],
10889
- additionalProperties: false
10890
- },
10891
- {
10892
- type: "object",
10893
- properties: {
10894
- _tag: {
10895
- type: "string",
10896
- enum: ["PaymentRequiredError"]
10897
- },
10898
- message: { type: "string" },
10899
- resource: { type: "string" },
10900
- currentUsage: { type: "number" },
10901
- limit: { type: "number" }
10902
- },
10903
- required: [
10904
- "_tag",
10905
- "message",
10906
- "resource",
10907
- "currentUsage",
10908
- "limit"
10909
- ],
10910
- additionalProperties: false
10911
- },
10912
- {
10913
- type: "object",
10914
- properties: {
10915
- _tag: {
10916
- type: "string",
10917
- enum: ["ValidationError"]
10918
- },
10919
- message: { type: "string" },
10920
- fields: { anyOf: [{
10921
- type: "object",
10922
- additionalProperties: {
10923
- type: "array",
10924
- items: { type: "string" }
10925
- }
10926
- }, { type: "null" }] }
10927
- },
10928
- required: ["_tag", "message"],
10929
- additionalProperties: false
10930
- },
10931
- {
10932
- type: "object",
10933
- properties: {
10934
- _tag: {
10935
- type: "string",
10936
- enum: ["ForbiddenError"]
10937
- },
10938
- message: { type: "string" }
10939
- },
10940
- required: ["_tag", "message"],
10941
- additionalProperties: false
10942
- },
10943
- {
10944
- type: "object",
10945
- properties: {
10946
- _tag: {
10947
- type: "string",
10948
- enum: ["ResourceNotFoundError"]
10949
- },
10950
- resource: { type: "string" },
10951
- id: { type: "string" },
10952
- message: { type: "string" }
10953
- },
10954
- required: [
10955
- "_tag",
10956
- "resource",
10957
- "id",
10958
- "message"
10959
- ],
10960
- additionalProperties: false
10961
- }
10962
- ] }, { type: "null" }] }
10963
- },
10964
- required: ["code", "message"],
10965
- additionalProperties: false
10966
- }, { type: "null" }] },
10967
- retryEligible: { type: "boolean" },
10968
- decision: { anyOf: [{
10969
- type: "object",
10970
- properties: {
10971
- outcome: {
10972
- type: "string",
10973
- enum: [
10974
- "allow",
10975
- "requireApproval",
10976
- "deny"
10977
- ]
10978
- },
10979
- reason: { anyOf: [{ type: "string" }, { type: "null" }] },
10980
- policyId: { anyOf: [{
10981
- type: "string",
10982
- pattern: "^mbxpol_[0-9a-hjkmnp-tv-z]{16,24}$",
10983
- "x-samva-brand": "MailboxPolicyId"
10984
- }, { type: "null" }] },
10985
- source: { anyOf: [{
10986
- type: "string",
10987
- enum: [
10988
- "grant",
10989
- "installation",
10990
- "policy"
10991
- ]
10992
- }, { type: "null" }] },
10993
- decidedAt: { type: "string" }
10994
- },
10995
- required: [
10996
- "outcome",
10997
- "reason",
10998
- "policyId",
10999
- "source",
11000
- "decidedAt"
11001
- ],
11002
- additionalProperties: false
11003
- }, { type: "null" }] },
11004
- createdAt: { type: "string" },
11005
- updatedAt: { type: "string" }
11006
- },
11007
- required: [
11008
- "actionId",
11009
- "draftId",
11010
- "messageId",
11011
- "threadId",
11012
- "state",
11013
- "acceptedAt",
11014
- "waitReason",
11015
- "reviewExpectedAt",
11016
- "skippedRecipients",
11017
- "executeUntil",
11018
- "retryAt",
11019
- "problem",
11020
- "retryEligible",
11021
- "decision",
11022
- "createdAt",
11023
- "updatedAt"
11024
- ],
11025
- additionalProperties: false
11026
- }
11027
- },
11028
- required: [
11029
- "_tag",
11030
- "message",
11031
- "resource",
11032
- "id",
11033
- "receipt"
11034
- ],
11035
- additionalProperties: false
11036
- },
11037
- MailboxSendRefusedError: {
11038
- type: "object",
11039
- properties: {
11040
- _tag: {
11041
- type: "string",
11042
- enum: ["MailboxSendRefusedError"]
11043
- },
11044
- message: { type: "string" },
11045
- receipt: {
11046
- type: "object",
11047
- properties: {
11048
- actionId: {
11049
- type: "string",
11050
- pattern: "^mbxact_[0-9a-hjkmnp-tv-z]{16,24}$",
11051
- "x-samva-brand": "MailboxActionId"
11052
- },
11053
- draftId: { anyOf: [{
11054
- type: "string",
11055
- pattern: "^mdraft_[0-9a-hjkmnp-tv-z]{16,24}$",
11056
- "x-samva-brand": "MailboxDraftId"
11057
- }, { type: "null" }] },
11058
- messageId: { anyOf: [{
11059
- type: "string",
11060
- pattern: "^msg_[0-9a-hjkmnp-tv-z]{16,24}$",
11061
- "x-samva-brand": "MessageId"
11062
- }, { type: "null" }] },
11063
- threadId: { anyOf: [{
11064
- type: "string",
11065
- pattern: "^thread_[0-9a-hjkmnp-tv-z]{16,24}$",
11066
- "x-samva-brand": "MailboxThreadId"
11067
- }, { type: "null" }] },
11068
- state: {
11069
- type: "string",
11070
- enum: [
11071
- "approvalRequired",
11072
- "queued",
11073
- "accepted",
11074
- "completed",
11075
- "notSent",
11076
- "uncertain"
11077
- ]
11078
- },
11079
- acceptedAt: { anyOf: [{ type: "string" }, { type: "null" }] },
11080
- waitReason: { anyOf: [{
11081
- type: "string",
11082
- enum: [
11083
- "rate",
11084
- "daily-quota",
11085
- "domain-health",
11086
- "sending-paused",
11087
- "upstream-unavailable",
11088
- "retry",
11089
- "campaign-paused",
11090
- "domain-warming",
11091
- "onboarding-review",
11092
- "content-review",
11093
- "screening-unavailable"
11094
- ]
11095
- }, { type: "null" }] },
11096
- reviewExpectedAt: { anyOf: [{ type: "string" }, { type: "null" }] },
11097
- skippedRecipients: {
11098
- type: "array",
11099
- items: {
11100
- type: "object",
11101
- properties: {
11102
- address: { type: "string" },
11103
- reason: {
11104
- type: "string",
11105
- enum: [
11106
- "bounce",
11107
- "complaint",
11108
- "unsubscribe",
11109
- "manual",
11110
- "group-unsubscribe"
11111
- ]
11112
- },
11113
- unsubscribeGroupId: { anyOf: [{
11114
- type: "string",
11115
- pattern: "^unsub_[0-9a-hjkmnp-tv-z]{16,24}$",
11116
- "x-samva-brand": "UnsubscribeId"
11117
- }, { type: "null" }] }
11118
- },
11119
- required: ["address", "reason"],
11120
- additionalProperties: false
11121
- }
11122
- },
11123
- executeUntil: { anyOf: [{ type: "string" }, { type: "null" }] },
11124
- retryAt: { anyOf: [{ type: "string" }, { type: "null" }] },
11125
- problem: { anyOf: [{
11126
- type: "object",
11127
- properties: {
11128
- code: { type: "string" },
11129
- message: { type: "string" },
11130
- error: { anyOf: [{ anyOf: [
11131
- {
11132
- type: "object",
11133
- properties: {
11134
- _tag: {
11135
- type: "string",
11136
- enum: ["SenderNotReadyError"]
11137
- },
11138
- message: { type: "string" },
11139
- sender: { type: "string" },
11140
- retryAfterSeconds: { anyOf: [{ type: "number" }, { type: "null" }] }
11141
- },
11142
- required: [
11143
- "_tag",
11144
- "message",
11145
- "sender"
11146
- ],
11147
- additionalProperties: false
11148
- },
11149
- {
11150
- type: "object",
11151
- properties: {
11152
- _tag: {
11153
- type: "string",
11154
- enum: ["RateLimitedError"]
11155
- },
11156
- message: { type: "string" },
11157
- retryAfterSeconds: { type: "number" }
11158
- },
11159
- required: [
11160
- "_tag",
11161
- "message",
11162
- "retryAfterSeconds"
11163
- ],
11164
- additionalProperties: false
11165
- },
11166
- {
11167
- type: "object",
11168
- properties: {
11169
- _tag: {
11170
- type: "string",
11171
- enum: ["OnboardingReviewRequiredError"]
11172
- },
11173
- message: { type: "string" },
11174
- code: {
11175
- type: "string",
11176
- enum: [
11177
- "review_required",
11178
- "review_in_progress",
11179
- "information_required",
11180
- "review_rejected",
11181
- "identity_review_required",
11182
- "identity_review_rejected",
11183
- "identity_changed"
11184
- ]
11185
- },
11186
- decision: {
11187
- type: "string",
11188
- enum: [
11189
- "undecided",
11190
- "approved",
11191
- "rejected"
11192
- ]
11193
- },
11194
- stage: {
11195
- type: "string",
11196
- enum: [
11197
- "collecting",
11198
- "automated_review",
11199
- "manual_review",
11200
- "information_requested",
11201
- "complete"
11202
- ]
11203
- },
11204
- nextAction: {
11205
- type: "string",
11206
- enum: [
11207
- "wait_for_review",
11208
- "provide_information",
11209
- "verify_sending_identity",
11210
- "reapply",
11211
- "contact_support"
11212
- ]
11213
- },
11214
- identityId: { anyOf: [{ type: "string" }, { type: "null" }] }
11215
- },
11216
- required: [
11217
- "_tag",
11218
- "message",
11219
- "code",
11220
- "decision",
11221
- "stage",
11222
- "nextAction"
11223
- ],
11224
- additionalProperties: false
11225
- },
11226
- {
11227
- type: "object",
11228
- properties: {
11229
- _tag: {
11230
- type: "string",
11231
- enum: ["PaymentRequiredError"]
11232
- },
11233
- message: { type: "string" },
11234
- resource: { type: "string" },
11235
- currentUsage: { type: "number" },
11236
- limit: { type: "number" }
11237
- },
11238
- required: [
11239
- "_tag",
11240
- "message",
11241
- "resource",
11242
- "currentUsage",
11243
- "limit"
11244
- ],
11245
- additionalProperties: false
11246
- },
11247
- {
11248
- type: "object",
11249
- properties: {
11250
- _tag: {
11251
- type: "string",
11252
- enum: ["ValidationError"]
11253
- },
11254
- message: { type: "string" },
11255
- fields: { anyOf: [{
11256
- type: "object",
11257
- additionalProperties: {
11258
- type: "array",
11259
- items: { type: "string" }
11260
- }
11261
- }, { type: "null" }] }
11262
- },
11263
- required: ["_tag", "message"],
11264
- additionalProperties: false
11265
- },
11266
- {
11267
- type: "object",
11268
- properties: {
11269
- _tag: {
11270
- type: "string",
11271
- enum: ["ForbiddenError"]
11272
- },
11273
- message: { type: "string" }
11274
- },
11275
- required: ["_tag", "message"],
11276
- additionalProperties: false
11277
- },
11278
- {
11279
- type: "object",
11280
- properties: {
11281
- _tag: {
11282
- type: "string",
11283
- enum: ["ResourceNotFoundError"]
11284
- },
11285
- resource: { type: "string" },
11286
- id: { type: "string" },
11287
- message: { type: "string" }
11288
- },
11289
- required: [
11290
- "_tag",
11291
- "resource",
11292
- "id",
11293
- "message"
11294
- ],
11295
- additionalProperties: false
11296
- }
11297
- ] }, { type: "null" }] }
11298
- },
11299
- required: ["code", "message"],
11300
- additionalProperties: false
11301
- }, { type: "null" }] },
11302
- retryEligible: { type: "boolean" },
11303
- decision: { anyOf: [{
11304
- type: "object",
11305
- properties: {
11306
- outcome: {
11307
- type: "string",
11308
- enum: [
11309
- "allow",
11310
- "requireApproval",
11311
- "deny"
11312
- ]
11313
- },
11314
- reason: { anyOf: [{ type: "string" }, { type: "null" }] },
11315
- policyId: { anyOf: [{
11316
- type: "string",
11317
- pattern: "^mbxpol_[0-9a-hjkmnp-tv-z]{16,24}$",
11318
- "x-samva-brand": "MailboxPolicyId"
11319
- }, { type: "null" }] },
11320
- source: { anyOf: [{
11321
- type: "string",
11322
- enum: [
11323
- "grant",
11324
- "installation",
11325
- "policy"
11326
- ]
11327
- }, { type: "null" }] },
11328
- decidedAt: { type: "string" }
11329
- },
11330
- required: [
11331
- "outcome",
11332
- "reason",
11333
- "policyId",
11334
- "source",
11335
- "decidedAt"
11336
- ],
11337
- additionalProperties: false
11338
- }, { type: "null" }] },
11339
- createdAt: { type: "string" },
11340
- updatedAt: { type: "string" }
11341
- },
11342
- required: [
11343
- "actionId",
11344
- "draftId",
11345
- "messageId",
11346
- "threadId",
11347
- "state",
11348
- "acceptedAt",
11349
- "waitReason",
11350
- "reviewExpectedAt",
11351
- "skippedRecipients",
11352
- "executeUntil",
11353
- "retryAt",
11354
- "problem",
11355
- "retryEligible",
11356
- "decision",
11357
- "createdAt",
11358
- "updatedAt"
11359
- ],
11360
- additionalProperties: false
11361
- }
11362
- },
11363
- required: [
11364
- "_tag",
11365
- "message",
11366
- "receipt"
11367
- ],
11368
- additionalProperties: false
11369
- },
11370
- OnboardingReviewRequiredError: {
11371
- type: "object",
11372
- properties: {
11373
- _tag: {
11374
- type: "string",
11375
- enum: ["OnboardingReviewRequiredError"]
11376
- },
11377
- message: { type: "string" },
11378
- code: {
11379
- type: "string",
11380
- enum: [
11381
- "review_required",
11382
- "review_in_progress",
11383
- "information_required",
11384
- "review_rejected",
11385
- "identity_review_required",
11386
- "identity_review_rejected",
11387
- "identity_changed"
11388
- ]
11389
- },
11390
- decision: {
11391
- type: "string",
11392
- enum: [
11393
- "undecided",
11394
- "approved",
11395
- "rejected"
11396
- ]
11397
- },
11398
- stage: {
11399
- type: "string",
11400
- enum: [
11401
- "collecting",
11402
- "automated_review",
11403
- "manual_review",
11404
- "information_requested",
11405
- "complete"
11406
- ]
11407
- },
11408
- nextAction: {
11409
- type: "string",
11410
- enum: [
11411
- "wait_for_review",
11412
- "provide_information",
11413
- "verify_sending_identity",
11414
- "reapply",
11415
- "contact_support"
11416
- ]
11417
- },
11418
- identityId: { anyOf: [{ type: "string" }, { type: "null" }] }
11419
- },
11420
- required: [
11421
- "_tag",
11422
- "message",
11423
- "code",
11424
- "decision",
11425
- "stage",
11426
- "nextAction"
11427
- ],
11428
- additionalProperties: false,
11429
- "x-category": ["validation"],
11430
- "x-retryable": false
11431
- },
11432
- PaymentRequiredError: {
11433
- type: "object",
11434
- properties: {
11435
- _tag: {
11436
- type: "string",
11437
- enum: ["PaymentRequiredError"]
11438
- },
11439
- message: { type: "string" },
11440
- resource: { type: "string" },
11441
- currentUsage: { type: "number" },
11442
- limit: { type: "number" }
11443
- },
11444
- required: [
11445
- "_tag",
11446
- "message",
11447
- "resource",
11448
- "currentUsage",
11449
- "limit"
11450
- ],
11451
- additionalProperties: false,
11452
- "x-category": ["billing"],
11453
- "x-retryable": false
11454
- },
11455
- RateLimitedError: {
11456
- type: "object",
11457
- properties: {
11458
- _tag: {
11459
- type: "string",
11460
- enum: ["RateLimitedError"]
11461
- },
11462
- message: { type: "string" },
11463
- retryAfterSeconds: { type: "number" }
11464
- },
11465
- required: [
11466
- "_tag",
11467
- "message",
11468
- "retryAfterSeconds"
11469
- ],
11470
- additionalProperties: false,
11471
- "x-category": ["throttling", "transient"],
11472
- "x-retryable": true
11473
- },
11474
- ResourceNotFoundError: {
11475
- type: "object",
11476
- properties: {
11477
- _tag: {
11478
- type: "string",
11479
- enum: ["ResourceNotFoundError"]
11480
- },
11481
- resource: { type: "string" },
11482
- id: { type: "string" },
11483
- message: { type: "string" }
11484
- },
11485
- required: [
11486
- "_tag",
11487
- "resource",
11488
- "id",
11489
- "message"
11490
- ],
11491
- additionalProperties: false,
11492
- "x-category": ["notFound"],
11493
- "x-retryable": false
11494
- },
11495
- SenderNotReadyError: {
11496
- type: "object",
11497
- properties: {
11498
- _tag: {
11499
- type: "string",
11500
- enum: ["SenderNotReadyError"]
11501
- },
11502
- message: { type: "string" },
11503
- sender: { type: "string" },
11504
- retryAfterSeconds: { anyOf: [{ type: "number" }, { type: "null" }] }
11505
- },
11506
- required: [
11507
- "_tag",
11508
- "message",
11509
- "sender"
11510
- ],
11511
- additionalProperties: false,
11512
- "x-category": ["transient"],
11513
- "x-retryable": true
11514
- },
11515
- UnauthorizedError: {
11516
- type: "object",
11517
- properties: {
11518
- _tag: {
11519
- type: "string",
11520
- enum: ["UnauthorizedError"]
11521
- },
11522
- message: { type: "string" }
11523
- },
11524
- required: ["_tag", "message"],
11525
- additionalProperties: false,
11526
- "x-category": ["auth"],
11527
- "x-retryable": false
11528
- },
11529
- ValidationError: {
11530
- type: "object",
11531
- properties: {
11532
- _tag: {
11533
- type: "string",
11534
- enum: ["ValidationError"]
11535
- },
11536
- message: { type: "string" },
11537
- fields: { anyOf: [{
11538
- type: "object",
11539
- additionalProperties: {
11540
- type: "array",
11541
- items: { type: "string" }
11542
- }
11543
- }, { type: "null" }] }
11544
- },
11545
- required: ["_tag", "message"],
11546
- additionalProperties: false,
11547
- "x-category": ["validation"],
11548
- "x-retryable": false
11549
- }
11550
- };
11551
- const isRecord = (value) => typeof value === "object" && value !== null;
11552
- const matchesType = (value, type) => {
11553
- switch (type) {
11554
- case "string": return typeof value === "string";
11555
- case "number": return typeof value === "number" && Number.isFinite(value);
11556
- case "integer": return typeof value === "number" && Number.isInteger(value);
11557
- case "boolean": return typeof value === "boolean";
11558
- case "null": return value === null;
11559
- case "array": return Array.isArray(value);
11560
- case "object": return isRecord(value) && !Array.isArray(value);
11561
- default: return false;
11562
- }
11563
- };
11564
- const matchesSchema = (value, schema) => {
11565
- if (schema.anyOf !== void 0 && !schema.anyOf.some((member) => matchesSchema(value, member))) return false;
11566
- if (schema.enum !== void 0 && !schema.enum.some((member) => Object.is(value, member))) return false;
11567
- if (schema.type !== void 0) {
11568
- if (!(typeof schema.type === "string" ? [schema.type] : schema.type).some((type) => matchesType(value, type))) return false;
11569
- }
11570
- const items = schema.items;
11571
- if (Array.isArray(value) && items !== void 0) return value.every((item) => matchesSchema(item, items));
11572
- if (!isRecord(value) || Array.isArray(value)) return true;
11573
- if (schema.required?.some((key) => !Object.hasOwn(value, key)) === true) return false;
11574
- const properties = schema.properties ?? {};
11575
- for (const [key, propertySchema] of Object.entries(properties)) if (Object.hasOwn(value, key) && !matchesSchema(value[key], propertySchema)) return false;
11576
- if (schema.additionalProperties === false) {
11577
- if (Object.keys(value).some((key) => !Object.hasOwn(properties, key))) return false;
11578
- } else if (typeof schema.additionalProperties === "object") {
11579
- for (const [key, propertyValue] of Object.entries(value)) if (!Object.hasOwn(properties, key) && !matchesSchema(propertyValue, schema.additionalProperties)) return false;
11580
- }
11581
- return true;
11582
- };
11583
- /** Convert a decoded error payload into its generated JavaScript error class. */
11584
- function fromApiError(error, context = {}) {
11585
- if (error instanceof SamvaApiError) return error;
11586
- if (error instanceof SamvaTransportError) return error;
11587
- if (isRecord(error) && typeof error._tag === "string" && Object.hasOwn(constructors, error._tag)) {
11588
- const tag = error._tag;
11589
- if (!matchesSchema(error, payloadSchemas[tag])) return new SamvaTransportError(error, context);
11590
- const Constructor = constructors[tag];
11591
- return new Constructor(error, context);
11592
- }
11593
- if (context.response?.status === 504) {
11594
- const retryAfter = Number(context.response.headers.get("retry-after"));
11595
- return new GatewayTimeoutError({
11596
- message: "The request did not finish in time. Retry with the same idempotency key.",
11597
- retryAfterSeconds: Number.isInteger(retryAfter) && retryAfter > 0 ? retryAfter : 1
11598
- }, context);
11599
- }
11600
- return new SamvaTransportError(error, context);
11601
- }
11602
- //#endregion
11603
- //#region src/promises/index.ts
11604
- /**
11605
- * Samva SDK - TypeScript client for the Samva API.
11606
- *
11607
- * Ergonomic methods resolve with decoded success values and throw generated
11608
- * plain-JavaScript error classes. The bound Hey API result surface remains
11609
- * available under `client.raw` for transport-level access.
11610
- *
11611
- * @example
11612
- * ```typescript
11613
- * import { createClient, RateLimitedError } from "samva";
11614
- *
11615
- * const samva = createClient({ apiKey: "<samva-api-key>" });
11616
- *
11617
- * try {
11618
- * const { contact } = await samva.contacts.findOrCreate({
11619
- * create: { name: "Ada Lovelace" },
11620
- * lookup: { type: "email", value: "ada@example.com" },
11621
- * });
11622
- * await samva.email.send({
11623
- * to: contact,
11624
- * subject: "Hello",
11625
- * html: "<p>Hi there!</p>",
11626
- * });
11627
- * } catch (error) {
11628
- * if (error instanceof RateLimitedError) console.log(error.retryAfterSeconds);
11629
- * }
11630
- * ```
11631
- */
11632
- const isObject = (value) => typeof value === "object" && value !== null;
11633
- /**
11634
- * The key a retry-safe call sends as `idempotency-key`: the `idempotencyKey`
11635
- * option, else one the caller set in `headers`, else a fresh UUID. The
11636
- * generated header parameter is applied after request headers, so it must carry
11637
- * a caller-set header value rather than overwrite it.
11638
- */
11639
- function resolveIdempotencyKey(options) {
11640
- const { idempotencyKey, ...requestOptions } = options ?? {};
11641
- return {
11642
- idempotencyKey: idempotencyKey ?? mergeHeaders(requestOptions.headers).get("idempotency-key") ?? crypto.randomUUID(),
11643
- requestOptions
11644
- };
11645
- }
11646
- /**
11647
- * Inline attachment content over the API's request cap travels as media instead: the largest
11648
- * attachments are uploaded (create, put to the presigned URL, complete) and replaced by their
11649
- * `mediaId`. The returned payload is the one request every send attempt reuses, so nothing is
11650
- * uploaded twice.
11651
- */
11652
- async function uploadOversizedAttachments(clientInstance, payload, requestOptions) {
11653
- const plan = planInlineUploads(payload);
11654
- if (plan.length === 0) return payload;
11655
- const uploaded = /* @__PURE__ */ new Map();
11656
- const directMedia = createDirectService(createBoundService(Media, clientInstance));
11657
- for (const upload of plan) {
11658
- const created = await directMedia.create(mediaCreateBody(upload), requestOptions);
11659
- await putUpload(clientInstance, upload, created, requestOptions.signal ?? void 0);
11660
- await directMedia.complete({ id: created.id }, requestOptions);
11661
- uploaded.set(upload.index, {
11662
- mediaId: created.id,
11663
- upload
11664
- });
11665
- }
11666
- return withUploadedAttachments(payload, uploaded);
11667
- }
11668
- /**
11669
- * Send with oversized inline attachments uploaded first. Within the cap this is the send call
11670
- * itself, one request and no extra await, so its result is returned unchanged.
11671
- */
11672
- function sendWithUploads(clientInstance, payload, requestOptions, send) {
11673
- if (planInlineUploads(payload).length === 0) return send(payload);
11674
- return uploadOversizedAttachments(clientInstance, payload, requestOptions).then(send);
11675
- }
11676
- async function putUpload(clientInstance, upload, created, signal) {
11677
- const fail = (status, cause) => new MediaUploadError({
11678
- filename: upload.filename,
11679
- mediaId: created.id,
11680
- status,
11681
- cause
11682
- });
11683
- let response;
11684
- try {
11685
- response = await (clientInstance.getConfig().fetch ?? globalThis.fetch)(new Request(created.upload.url, {
11686
- method: created.upload.method,
11687
- headers: created.upload.headers,
11688
- body: upload.bytes,
11689
- signal: signal ?? null
11690
- }));
11691
- } catch (error) {
11692
- throw fail(void 0, error);
11693
- }
11694
- if (!response.ok) throw fail(response.status);
11695
- }
11696
- function createPromiseMessagesTransport(clientInstance) {
11697
- const boundMessages = createBoundService(Messages, clientInstance);
11698
- return {
11699
- list: boundMessages.list,
11700
- remove: boundMessages.remove,
11701
- get: boundMessages.get,
11702
- getEmail: boundMessages.getEmail,
11703
- getStatus: boundMessages.getStatus,
11704
- getEvents: boundMessages.getEvents,
11705
- listDeliveries: boundMessages.listDeliveries,
11706
- getContent: boundMessages.getContent,
11707
- validateEmail: boundMessages.validateEmail,
11708
- send: (input, options) => {
11709
- const { idempotencyKey, requestOptions } = resolveIdempotencyKey(options);
11710
- return sendWithUploads(clientInstance, buildMessagesSendPayload(input), requestOptions, (payload) => Messages.send({
11711
- "idempotency-key": idempotencyKey,
11712
- ...payload
11713
- }, {
11714
- ...requestOptions,
11715
- client: clientInstance
11716
- }));
11717
- }
11718
- };
11719
- }
11720
- function createPromiseEmailTransport(clientInstance) {
11721
- const boundEmail = createBoundService(Email, clientInstance);
11722
- return Object.assign(boundEmail, {
11723
- addSender: (input, options) => {
11724
- const { replyToEmails, ...sender } = input;
11725
- const { idempotencyKey, requestOptions } = resolveIdempotencyKey(options);
11726
- return Email.addSender({
11727
- "idempotency-key": idempotencyKey,
11728
- ...sender,
11729
- ...replyToEmailsPayload(replyToEmails)
11730
- }, {
11731
- ...requestOptions,
11732
- client: clientInstance
11733
- });
11734
- },
11735
- send: (input, options) => {
11736
- const { idempotencyKey, requestOptions } = resolveIdempotencyKey(options);
11737
- return sendWithUploads(clientInstance, buildEmailSendPayload(input), requestOptions, (payload) => Messages.send({
11738
- "idempotency-key": idempotencyKey,
11739
- ...payload
11740
- }, {
11741
- ...requestOptions,
11742
- client: clientInstance
11743
- }));
11744
- }
11745
- });
11746
- }
11747
- function createPromiseTemplatesTransport(clientInstance) {
11748
- return createBoundService(Templates, clientInstance);
11749
- }
11750
- function createBoundService(service, clientInstance) {
11751
- const bound = {};
11752
- for (const key of Object.getOwnPropertyNames(service)) {
11753
- if (key === "length" || key === "name" || key === "prototype") continue;
11754
- const value = service[key];
11755
- if (typeof value === "function") bound[key] = value.length >= 2 ? (parameters, options) => value(parameters ?? {}, {
11756
- ...options,
11757
- client: clientInstance
11758
- }) : (options) => value({
11759
- ...options,
11760
- client: clientInstance
11761
- });
11762
- else if (isObject(value)) bound[key] = createBoundService(value, clientInstance);
11763
- else bound[key] = value;
11764
- }
11765
- return bound;
11766
- }
11767
- const directOptions = (options) => ({
11768
- ...isObject(options) ? options : {},
11769
- responseStyle: "fields",
11770
- throwOnError: false
11771
- });
11772
- async function unwrap(method, arguments_) {
11773
- let result;
11774
- try {
11775
- result = await method(...arguments_);
11776
- } catch (error) {
11777
- if (error instanceof MediaUploadError) throw error;
11778
- throw fromApiError(error);
11779
- }
11780
- if (!isObject(result)) throw new SamvaTransportError(result);
11781
- const raw = result;
11782
- const context = {
11783
- request: raw.request,
11784
- response: raw.response
11785
- };
11786
- if (raw.error !== void 0) throw fromApiError(raw.error, context);
11787
- if ("data" in raw) return raw.data;
11788
- throw new SamvaTransportError(result, context);
11789
- }
11790
- function createDirectService(service) {
11791
- const direct = {};
11792
- for (const [key, value] of Object.entries(service)) if (typeof value === "function") direct[key] = value.length >= 2 ? (parameters = {}, options = {}) => unwrap(value, [parameters, directOptions(options)]) : (options = {}) => unwrap(value, [directOptions(options)]);
11793
- else if (isObject(value)) direct[key] = createDirectService(value);
11794
- else direct[key] = value;
11795
- return direct;
11796
- }
11797
- /** Create a configured Promise client. */
11798
- function createClient(config) {
11799
- const authHeaders = config.authToken !== void 0 ? { Authorization: `Bearer ${config.authToken}` } : { "X-API-Key": config.apiKey };
11800
- const clientInstance = createClient$1({
11801
- ...config,
11802
- baseUrl: config.baseUrl ?? "https://api.samva.dev",
11803
- headers: mergeHeaders({ [CLIENT_ATTRIBUTION_HEADER]: clientAttribution("typescript-promise") }, config.headers, authHeaders),
11804
- responseStyle: "fields",
11805
- throwOnError: false
11806
- });
11807
- clientInstance.interceptors.request.use((request) => {
11808
- const headers = new Headers(request.headers);
11809
- for (const [name, value] of Object.entries(authHeaders)) headers.set(name, value);
11810
- return new Request(request, { headers });
11811
- });
11812
- const raw = {
11813
- client: clientInstance,
11814
- messages: createBoundService(Messages, clientInstance),
11815
- scheduledMessages: createBoundService(ScheduledMessages, clientInstance),
11816
- brands: createBoundService(Brands, clientInstance),
11817
- campaigns: createBoundService(Campaigns, clientInstance),
11818
- email: createBoundService(Email, clientInstance),
11819
- media: createBoundService(Media, clientInstance),
11820
- templates: createPromiseTemplatesTransport(clientInstance),
11821
- contacts: createBoundService(Contacts, clientInstance),
11822
- conversations: createBoundService(Conversations, clientInstance),
11823
- webhooks: createBoundService(Webhooks, clientInstance),
11824
- operations: createBoundService(Operations, clientInstance),
11825
- apiKeys: createBoundService(ApiKeys, clientInstance),
11826
- organizations: createBoundService(Organizations, clientInstance),
11827
- attachments: createBoundService(Attachments, clientInstance),
11828
- contactGroups: createBoundService(ContactGroups, clientInstance),
11829
- customFields: createBoundService(CustomFields, clientInstance),
11830
- subscriptions: createBoundService(Subscriptions, clientInstance),
11831
- unsubscribeGroups: createBoundService(Unsubscribe, clientInstance),
11832
- analytics: createBoundService(Analytics, clientInstance),
11833
- feedback: createBoundService(Feedback, clientInstance),
11834
- whoami: createBoundService(Whoami, clientInstance),
11835
- mailboxes: createBoundService(Mailboxes, clientInstance),
11836
- namespaces: createBoundService(Namespaces, clientInstance),
11837
- extensions: createBoundService(Extensions, clientInstance),
11838
- extensionInstallations: createBoundService(ExtensionInstallations, clientInstance)
11839
- };
11840
- const streamConnection = {
11841
- baseUrl: config.baseUrl ?? "https://api.samva.dev",
11842
- headers: async () => Object.fromEntries(mergeHeaders({ [CLIENT_ATTRIBUTION_HEADER]: clientAttribution("typescript-promise") }, config.headers, authHeaders).entries()),
11843
- fetch: config.fetch
11844
- };
11845
- const promiseMessages = createPromiseMessagesTransport(clientInstance);
11846
- const promiseEmail = createPromiseEmailTransport(clientInstance);
11847
- return {
11848
- raw,
11849
- messages: createDirectService(promiseMessages),
11850
- scheduledMessages: createDirectService(raw.scheduledMessages),
11851
- brands: createDirectService(raw.brands),
11852
- campaigns: createDirectService(raw.campaigns),
11853
- email: createDirectService(promiseEmail),
11854
- media: createDirectService(raw.media),
11855
- templates: createDirectService(raw.templates),
11856
- contacts: createDirectService(raw.contacts),
11857
- conversations: createDirectService(raw.conversations),
11858
- webhooks: createDirectService(raw.webhooks),
11859
- operations: createDirectService(raw.operations),
11860
- apiKeys: createDirectService(raw.apiKeys),
11861
- organizations: createDirectService(raw.organizations),
11862
- attachments: createDirectService(raw.attachments),
11863
- contactGroups: createDirectService(raw.contactGroups),
11864
- customFields: createDirectService(raw.customFields),
11865
- subscriptions: createDirectService(raw.subscriptions),
11866
- unsubscribeGroups: createDirectService(raw.unsubscribeGroups),
11867
- analytics: createDirectService(raw.analytics),
11868
- feedback: createDirectService(raw.feedback),
11869
- whoami: createDirectService(raw.whoami),
11870
- mailboxes: Object.assign(createDirectService(raw.mailboxes), { events: (options) => new MailboxEventStream(streamConnection, options) }),
11871
- namespaces: createDirectService(raw.namespaces),
11872
- extensions: createDirectService(raw.extensions),
11873
- extensionInstallations: createDirectService(raw.extensionInstallations)
11874
- };
11875
- }
11876
- //#endregion
11877
- export { SenderNotReadyError as C, fromApiError as E, SamvaTransportError as S, ValidationError as T, OnboardingReviewRequiredError as _, CampaignFooterRequiredError as a, ResourceNotFoundError as b, EmailChannelError as c, ForbiddenError as d, GatewayTimeoutError as f, MailboxSendRefusedError as g, MailboxSendConflictError as h, BrandAddressRequiredError as i, ExternalServiceError as l, MailboxChannelUnsupportedError as m, AnalyticsQueryError as n, ConflictError as o, InternalError as p, BillingProviderError as r, DeliveryUnavailableError as s, createClient as t, FlagDisabledError as u, PaymentRequiredError as v, UnauthorizedError as w, SamvaApiError as x, RateLimitedError as y };
10052
+ export { Analytics, ApiKeys, Attachments, Brands, Campaigns, ContactEvents, ContactGroups, Contacts, Conversations, CustomFields, Email, Events, ExtensionInstallations, Extensions, Feedback, Journeys, Mailboxes, Media, Messages, Namespaces, Operations, Organizations, ScheduledMessages, Subscriptions, Templates, Unsubscribe, Webhooks, Whoami };
11878
10053
 
11879
- //# sourceMappingURL=promises-KrA2nSLg.js.map
10054
+ //# sourceMappingURL=sdk.gen.js.map