samva 0.29.1 → 0.30.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 (185) hide show
  1. package/AGENTS.md +23 -5
  2. package/README.md +166 -133
  3. package/dist/_virtual/_rolldown/runtime.js +1 -2
  4. package/dist/client/client/client.gen.js +1 -2
  5. package/dist/client/client/utils.gen.js +1 -2
  6. package/dist/client/client.gen.js +1 -2
  7. package/dist/client/core/auth.gen.js +1 -2
  8. package/dist/client/core/bodySerializer.gen.js +1 -2
  9. package/dist/client/core/params.gen.js +1 -2
  10. package/dist/client/core/pathSerializer.gen.js +1 -2
  11. package/dist/client/core/serverSentEvents.gen.js +1 -2
  12. package/dist/client/core/utils.gen.js +1 -2
  13. package/dist/client/sdk.gen.d.ts +216 -191
  14. package/dist/client/sdk.gen.js +2392 -1153
  15. package/dist/client/types.gen.d.ts +766 -376
  16. package/dist/client-attribution.js +1 -2
  17. package/dist/effect/agents.d.ts +33 -11
  18. package/dist/effect/agents.js +1 -2
  19. package/dist/effect/analytics.d.ts +6 -6
  20. package/dist/effect/analytics.js +1 -2
  21. package/dist/effect/api-keys.d.ts +8 -8
  22. package/dist/effect/api-keys.js +1 -2
  23. package/dist/effect/attachments.d.ts +4 -4
  24. package/dist/effect/attachments.js +1 -2
  25. package/dist/effect/brands.d.ts +6 -6
  26. package/dist/effect/brands.js +1 -2
  27. package/dist/effect/campaigns.d.ts +15 -16
  28. package/dist/effect/campaigns.js +1 -2
  29. package/dist/effect/categories.js +1 -2
  30. package/dist/effect/client.js +1 -2
  31. package/dist/effect/contact-groups.d.ts +10 -10
  32. package/dist/effect/contact-groups.js +1 -2
  33. package/dist/effect/contacts.d.ts +23 -24
  34. package/dist/effect/contacts.js +1 -2
  35. package/dist/effect/conversations.d.ts +13 -13
  36. package/dist/effect/conversations.js +1 -2
  37. package/dist/effect/custom-fields.d.ts +4 -4
  38. package/dist/effect/custom-fields.js +1 -2
  39. package/dist/effect/email.d.ts +61 -63
  40. package/dist/effect/email.js +1 -2
  41. package/dist/effect/events.d.ts +2 -4
  42. package/dist/effect/events.js +1 -2
  43. package/dist/effect/extension-installations.d.ts +9 -9
  44. package/dist/effect/extension-installations.js +1 -2
  45. package/dist/effect/extensions.d.ts +5 -5
  46. package/dist/effect/extensions.js +1 -2
  47. package/dist/effect/feedback.d.ts +1 -1
  48. package/dist/effect/feedback.js +1 -2
  49. package/dist/effect/generated/agents.d.ts +264 -22
  50. package/dist/effect/generated/agents.js +2 -3
  51. package/dist/effect/generated/analytics.js +1 -2
  52. package/dist/effect/generated/api-keys.js +1 -2
  53. package/dist/effect/generated/attachments.js +1 -2
  54. package/dist/effect/generated/brands.js +1 -2
  55. package/dist/effect/generated/campaigns.d.ts +160 -155
  56. package/dist/effect/generated/campaigns.js +7 -9
  57. package/dist/effect/generated/contact-events.js +1 -2
  58. package/dist/effect/generated/contact-groups.d.ts +26 -26
  59. package/dist/effect/generated/contact-groups.js +22 -19
  60. package/dist/effect/generated/contacts.d.ts +119 -90
  61. package/dist/effect/generated/contacts.js +32 -32
  62. package/dist/effect/generated/conversations.d.ts +22 -22
  63. package/dist/effect/generated/conversations.js +7 -8
  64. package/dist/effect/generated/custom-fields.d.ts +6 -6
  65. package/dist/effect/generated/custom-fields.js +3 -4
  66. package/dist/effect/generated/email.d.ts +38 -38
  67. package/dist/effect/generated/email.js +13 -14
  68. package/dist/effect/generated/events.d.ts +18 -9
  69. package/dist/effect/generated/events.js +8 -6
  70. package/dist/effect/generated/extension-installations.d.ts +2 -2
  71. package/dist/effect/generated/extension-installations.js +6 -3
  72. package/dist/effect/generated/extensions.js +1 -2
  73. package/dist/effect/generated/feedback.js +1 -2
  74. package/dist/effect/generated/index.d.ts +7 -5
  75. package/dist/effect/generated/journeys.js +1 -2
  76. package/dist/effect/generated/mailboxes.d.ts +44 -44
  77. package/dist/effect/generated/mailboxes.js +17 -18
  78. package/dist/effect/generated/media.js +1 -2
  79. package/dist/effect/generated/messages.d.ts +42 -42
  80. package/dist/effect/generated/messages.js +3 -4
  81. package/dist/effect/generated/namespaces.js +1 -2
  82. package/dist/effect/generated/{publication-domains.d.ts → newsletter-domains.d.ts} +304 -80
  83. package/dist/effect/generated/newsletter-domains.js +218 -0
  84. package/dist/effect/generated/{topic-issues.d.ts → newsletter-issues.d.ts} +330 -288
  85. package/dist/effect/generated/{topic-issues.js → newsletter-issues.js} +255 -246
  86. package/dist/effect/generated/newsletters.d.ts +741 -0
  87. package/dist/effect/generated/newsletters.js +143 -0
  88. package/dist/effect/generated/operations.js +1 -2
  89. package/dist/effect/generated/organizations.d.ts +9 -9
  90. package/dist/effect/generated/organizations.js +4 -5
  91. package/dist/effect/generated/scheduled-messages.d.ts +174 -169
  92. package/dist/effect/generated/scheduled-messages.js +7 -7
  93. package/dist/effect/generated/shared.d.ts +276 -208
  94. package/dist/effect/generated/shared.js +50 -36
  95. package/dist/effect/generated/subscriptions.js +1 -2
  96. package/dist/effect/generated/templates.d.ts +118 -67
  97. package/dist/effect/generated/templates.js +43 -35
  98. package/dist/effect/generated/topic-forms.d.ts +79 -19
  99. package/dist/effect/generated/topic-forms.js +13 -14
  100. package/dist/effect/generated/topics.d.ts +27 -65
  101. package/dist/effect/generated/topics.js +13 -20
  102. package/dist/effect/generated/webhooks.d.ts +9 -9
  103. package/dist/effect/generated/webhooks.js +4 -5
  104. package/dist/effect/generated/whoami.js +1 -2
  105. package/dist/effect/generated-metadata.d.ts +475 -70
  106. package/dist/effect/generated-metadata.js +642 -432
  107. package/dist/effect/index.d.ts +3 -2
  108. package/dist/effect/index.js +4 -3
  109. package/dist/effect/internal/client.d.ts +5 -0
  110. package/dist/effect/internal/client.js +9 -5
  111. package/dist/effect/internal/email-sender.d.ts +1 -1
  112. package/dist/effect/internal/email-sender.js +4 -3
  113. package/dist/effect/internal/mailbox-events.js +1 -2
  114. package/dist/effect/internal/operation.d.ts +4 -15
  115. package/dist/effect/internal/operation.js +21 -33
  116. package/dist/effect/internal/send.js +2 -3
  117. package/dist/effect/journeys.d.ts +14 -14
  118. package/dist/effect/journeys.js +1 -2
  119. package/dist/effect/mailboxes.d.ts +60 -70
  120. package/dist/effect/mailboxes.js +1 -2
  121. package/dist/effect/media.d.ts +5 -5
  122. package/dist/effect/media.js +1 -2
  123. package/dist/effect/messages.d.ts +9 -9
  124. package/dist/effect/messages.js +1 -2
  125. package/dist/effect/namespaces.d.ts +8 -8
  126. package/dist/effect/namespaces.js +1 -2
  127. package/dist/effect/newsletter-domains.d.ts +71 -0
  128. package/dist/effect/newsletter-domains.js +18 -0
  129. package/dist/effect/{topic-issues.d.ts → newsletter-issues.d.ts} +11 -15
  130. package/dist/effect/newsletter-issues.js +32 -0
  131. package/dist/effect/newsletters.d.ts +22 -0
  132. package/dist/effect/newsletters.js +20 -0
  133. package/dist/effect/operations.d.ts +3 -3
  134. package/dist/effect/operations.js +1 -2
  135. package/dist/effect/organizations.d.ts +8 -10
  136. package/dist/effect/organizations.js +1 -2
  137. package/dist/effect/pagination.js +1 -2
  138. package/dist/effect/retry.d.ts +4 -4
  139. package/dist/effect/retry.js +5 -6
  140. package/dist/effect/runtime.js +1 -2
  141. package/dist/effect/scheduled-messages.d.ts +5 -6
  142. package/dist/effect/scheduled-messages.js +1 -2
  143. package/dist/effect/subscriptions.d.ts +1 -1
  144. package/dist/effect/subscriptions.js +1 -2
  145. package/dist/effect/templates.d.ts +34 -43
  146. package/dist/effect/templates.js +1 -2
  147. package/dist/effect/topic-forms.d.ts +5 -5
  148. package/dist/effect/topic-forms.js +1 -2
  149. package/dist/effect/topics.d.ts +9 -13
  150. package/dist/effect/topics.js +1 -2
  151. package/dist/effect/webhooks.d.ts +11 -11
  152. package/dist/effect/webhooks.js +1 -2
  153. package/dist/effect/whoami.d.ts +1 -1
  154. package/dist/effect/whoami.js +1 -2
  155. package/dist/index.js +2 -2
  156. package/dist/inline-attachments.js +1 -2
  157. package/dist/mailbox/dispatch.d.ts +10 -0
  158. package/dist/mailbox/dispatch.js +66 -0
  159. package/dist/mailbox/index.d.ts +17 -0
  160. package/dist/mailbox/index.js +30 -0
  161. package/dist/mailbox/test.d.ts +25 -0
  162. package/dist/mailbox/test.js +174 -0
  163. package/dist/mailbox/types.d.ts +184 -0
  164. package/dist/mailbox/webhook.d.ts +10 -0
  165. package/dist/mailbox/webhook.js +41 -0
  166. package/dist/mailbox-events.js +1 -2
  167. package/dist/normalize.js +1 -2
  168. package/dist/package.js +2 -3
  169. package/dist/promises/client.d.ts +215 -0
  170. package/dist/promises/client.js +324 -0
  171. package/dist/promises/errors.gen.js +1 -2
  172. package/dist/promises/index.d.ts +2 -196
  173. package/dist/promises/index.js +3 -295
  174. package/dist/promises/request.d.ts +15 -0
  175. package/dist/promises/request.js +75 -0
  176. package/dist/promises/types.gen.d.ts +1 -1
  177. package/dist/request-policy.d.ts +3 -0
  178. package/dist/request-policy.js +16 -0
  179. package/dist/service-map.d.ts +78 -47
  180. package/dist/service-map.js +52 -32
  181. package/package.json +34 -18
  182. package/dist/effect/generated/publication-domains.js +0 -163
  183. package/dist/effect/publication-domains.d.ts +0 -14
  184. package/dist/effect/publication-domains.js +0 -17
  185. package/dist/effect/topic-issues.js +0 -33
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Samva SDK - TypeScript client for the Samva API.
3
+ *
4
+ * Ergonomic methods resolve with decoded success values and throw generated
5
+ * plain-JavaScript error classes. The bound Hey API result surface remains
6
+ * available under `client.raw` for transport-level access.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { createClient, RateLimitedError } from "samva";
11
+ *
12
+ * const samva = createClient({ apiKey: "<samva-api-key>" });
13
+ *
14
+ * try {
15
+ * const { contact } = await samva.contacts.findOrCreate({
16
+ * create: { name: "Ada Lovelace" },
17
+ * lookup: { type: "email", value: "ada@example.com" },
18
+ * });
19
+ * await samva.email.send({
20
+ * to: contact,
21
+ * subject: "Hello",
22
+ * html: "<p>Hi there!</p>",
23
+ * });
24
+ * } catch (error) {
25
+ * if (error instanceof RateLimitedError) console.log(error.retryAfterSeconds);
26
+ * }
27
+ * ```
28
+ */
29
+ import { type Client, type Config } from "../client/client";
30
+ import { Agents as agents, Analytics as analytics, ApiKeys as apiKeys, Attachments as attachments, Brands as brands, Campaigns as campaigns, ContactGroups as contactGroups, ContactEvents as contactEvents, Contacts as contacts, Conversations as conversations, CustomFields as customFields, Email as email, ExtensionInstallations as extensionInstallations, Extensions as extensions, Events as events, Feedback as feedback, Journeys as journeys, Mailboxes as mailboxes, Media as media, Messages as messages, Namespaces as namespaces, Operations as operations, Organizations as organizations, ScheduledMessages as scheduledMessages, Subscriptions as subscriptions, Templates as templates, Topics as topics, TopicForms as topicForms, Newsletters as newsletters, Webhooks as webhooks, Whoami as whoami } from "../client/sdk.gen";
31
+ import type { MessagesSendData } from "../client/types.gen";
32
+ import { MailboxEventStream, type MailboxEventStreamOptions } from "../mailbox-events";
33
+ import { type RequestPolicy } from "./request";
34
+ export * from "./errors.gen";
35
+ export { MediaUploadError } from "../inline-attachments";
36
+ export type * from "./types.gen";
37
+ export { MailboxEventStream, MailboxEventStreamError, type MailboxEvent, type MailboxEventStreamErrorFields, type MailboxEventStreamErrorReason, type MailboxEventStreamErrorTag, type MailboxEventStreamFailure, type MailboxEventStreamOptions, type MailboxEventStreamReconnect, type MailboxEventStreamWebSocket, type MailboxEventType, } from "../mailbox-events";
38
+ interface SamvaClientConfigBase extends Omit<Config, "baseUrl" | "responseStyle" | "throwOnError">, RequestPolicy {
39
+ /** Base URL for the API (defaults to https://api.samva.dev). */
40
+ baseUrl?: string;
41
+ }
42
+ export type SamvaClientConfig = (SamvaClientConfigBase & {
43
+ /** Your Samva API key. The organization is derived from the key. */
44
+ apiKey: string;
45
+ authToken?: never;
46
+ orgSlug?: never;
47
+ }) | (SamvaClientConfigBase & {
48
+ /** OAuth bearer token, such as one obtained by `samva login`. */
49
+ authToken: string;
50
+ orgSlug?: string | undefined;
51
+ apiKey?: never;
52
+ });
53
+ type MessageSendBody = MessagesSendData["body"];
54
+ type MessageRecipient = MessageSendBody["to"][number];
55
+ type MessageSendRequestOptions<ThrowOnError extends boolean = false> = Omit<NonNullable<Parameters<typeof messages.send<ThrowOnError>>[1]>, "client">;
56
+ type MessageSendOptions<ThrowOnError extends boolean = false> = MessageSendRequestOptions<ThrowOnError> & {
57
+ /** Sent as the `idempotency-key` header; defaults to a fresh UUID per call. */
58
+ readonly idempotencyKey?: string | undefined;
59
+ };
60
+ type MessageSendResponse<ThrowOnError extends boolean = false> = ReturnType<typeof messages.send<ThrowOnError>>;
61
+ type ContactObjectRecipient = {
62
+ readonly id: string;
63
+ };
64
+ type ErgonomicMessageRecipient = MessageRecipient | ContactObjectRecipient | string;
65
+ type EmailMessageSendBody = Extract<MessageSendBody, {
66
+ readonly channel: "email";
67
+ }>;
68
+ type ErgonomicReplyTo = string | ReadonlyArray<string>;
69
+ type ErgonomicEmailList = string | ReadonlyArray<string>;
70
+ type ErgonomicEmailContent = Omit<EmailMessageSendBody["email"], "replyTo"> & {
71
+ readonly replyTo?: ErgonomicReplyTo | null | undefined;
72
+ };
73
+ type EmailAddSenderWireInput = NonNullable<Parameters<typeof email.addSender>[0]>;
74
+ type EmailAddSenderRequestOptions<ThrowOnError extends boolean = false> = Parameters<typeof email.addSender<ThrowOnError>>[1];
75
+ type ErgonomicEmailAddSenderInput = Omit<EmailAddSenderWireInput, "idempotency-key" | "replyToEmails"> & {
76
+ readonly replyToEmails?: ErgonomicEmailList | null | undefined;
77
+ };
78
+ type EmailAddSenderOptions<ThrowOnError extends boolean = false> = EmailAddSenderRequestOptions<ThrowOnError> & {
79
+ readonly idempotencyKey?: string | undefined;
80
+ };
81
+ type ErgonomicEmailMessageSendBody = Omit<EmailMessageSendBody, "to" | "cc" | "bcc" | "email"> & {
82
+ readonly to: ErgonomicMessageRecipient | ReadonlyArray<ErgonomicMessageRecipient>;
83
+ readonly cc?: ErgonomicMessageRecipient | ReadonlyArray<ErgonomicMessageRecipient> | null;
84
+ readonly bcc?: ErgonomicMessageRecipient | ReadonlyArray<ErgonomicMessageRecipient> | null;
85
+ readonly email: ErgonomicEmailContent;
86
+ };
87
+ type ErgonomicMessageSendInput = ErgonomicEmailMessageSendBody;
88
+ type PromiseMessagesTransport = {
89
+ readonly list: typeof messages.list;
90
+ readonly remove: typeof messages.remove;
91
+ readonly get: typeof messages.get;
92
+ readonly getEmail: typeof messages.getEmail;
93
+ readonly getStatus: typeof messages.getStatus;
94
+ readonly getEvents: typeof messages.getEvents;
95
+ readonly listDeliveries: typeof messages.listDeliveries;
96
+ readonly getContent: typeof messages.getContent;
97
+ readonly validateEmail: typeof messages.validateEmail;
98
+ readonly send: <ThrowOnError extends boolean = false>(input: ErgonomicMessageSendInput, options?: MessageSendOptions<ThrowOnError>) => MessageSendResponse<ThrowOnError>;
99
+ };
100
+ type ErgonomicEmailSendBody = Omit<EmailMessageSendBody, "channel" | "email" | "to" | "cc" | "bcc"> & ErgonomicEmailContent & {
101
+ readonly to: ErgonomicMessageRecipient | ReadonlyArray<ErgonomicMessageRecipient>;
102
+ readonly cc?: ErgonomicMessageRecipient | ReadonlyArray<ErgonomicMessageRecipient>;
103
+ readonly bcc?: ErgonomicMessageRecipient | ReadonlyArray<ErgonomicMessageRecipient>;
104
+ };
105
+ type PromiseEmailTransport = Omit<typeof email, "send"> & {
106
+ readonly send: <ThrowOnError extends boolean = false>(input: ErgonomicEmailSendBody, options?: MessageSendOptions<ThrowOnError>) => MessageSendResponse<ThrowOnError>;
107
+ readonly addSender: <ThrowOnError extends boolean = false>(input: ErgonomicEmailAddSenderInput, options?: EmailAddSenderOptions<ThrowOnError>) => ReturnType<typeof email.addSender<ThrowOnError>>;
108
+ };
109
+ type PromiseTemplatesTransport = typeof templates;
110
+ type RawMethod = (...arguments_: Array<never>) => PromiseLike<unknown>;
111
+ type SuccessValue<Method extends RawMethod> = Exclude<Awaited<ReturnType<Method>> extends infer Result ? Result extends {
112
+ readonly data: infer Data;
113
+ } ? Data : never : never, undefined>;
114
+ type ErgonomicOptions<Options> = Options extends object ? Omit<Options, "client" | "responseStyle" | "throwOnError"> : Options;
115
+ type DirectArguments<Method extends RawMethod> = {
116
+ [Key in keyof Parameters<Method>]: Key extends 1 | "1" ? ErgonomicOptions<Parameters<Method>[Key]> : Parameters<Method>[Key];
117
+ };
118
+ type DirectCall<Method extends RawMethod> = (...arguments_: DirectArguments<Method>) => Promise<SuccessValue<Method>>;
119
+ type DirectMethod<Method extends RawMethod> = DirectCall<Method> & (SuccessValue<Method> extends {
120
+ readonly items: ReadonlyArray<infer Item>;
121
+ readonly nextCursor: string | null;
122
+ } ? {
123
+ readonly pages: (...args: DirectArguments<Method>) => AsyncIterableIterator<SuccessValue<Method>>;
124
+ readonly items: (...args: DirectArguments<Method>) => AsyncIterableIterator<Item>;
125
+ } : unknown);
126
+ type DirectService<Service extends object> = {
127
+ readonly [Key in keyof Service]: Service[Key] extends RawMethod ? DirectMethod<Service[Key]> : Service[Key] extends object ? DirectService<Service[Key]> : Service[Key];
128
+ };
129
+ export interface SamvaRawClient {
130
+ /** The underlying generated HTTP client. */
131
+ readonly client: Client;
132
+ readonly messages: typeof messages;
133
+ readonly scheduledMessages: typeof scheduledMessages;
134
+ readonly brands: typeof brands;
135
+ readonly campaigns: typeof campaigns;
136
+ readonly email: typeof email;
137
+ readonly media: typeof media;
138
+ readonly templates: PromiseTemplatesTransport;
139
+ readonly contacts: typeof contacts & typeof contactEvents;
140
+ readonly events: typeof events;
141
+ readonly conversations: typeof conversations;
142
+ readonly webhooks: typeof webhooks;
143
+ readonly operations: typeof operations;
144
+ readonly apiKeys: typeof apiKeys;
145
+ readonly organizations: typeof organizations;
146
+ readonly attachments: typeof attachments;
147
+ readonly contactGroups: typeof contactGroups;
148
+ readonly customFields: typeof customFields;
149
+ readonly subscriptions: typeof subscriptions;
150
+ readonly topics: typeof topics;
151
+ readonly topicForms: typeof topicForms;
152
+ readonly newsletters: typeof newsletters;
153
+ readonly agents: typeof agents;
154
+ readonly analytics: typeof analytics;
155
+ readonly feedback: typeof feedback;
156
+ readonly whoami: typeof whoami;
157
+ readonly journeys: typeof journeys;
158
+ readonly mailboxes: typeof mailboxes;
159
+ readonly namespaces: typeof namespaces;
160
+ readonly extensions: typeof extensions;
161
+ readonly extensionInstallations: typeof extensionInstallations;
162
+ }
163
+ /** The mailbox operations, plus the mailbox event stream. */
164
+ export type PromiseMailboxesService = DirectService<typeof mailboxes> & {
165
+ /**
166
+ * The organization's mailbox events over a WebSocket, as an async iterable that resumes from
167
+ * the last handled event. See {@link MailboxEventStream}.
168
+ */
169
+ readonly events: (options?: MailboxEventStreamOptions) => MailboxEventStream;
170
+ };
171
+ export interface SamvaClient {
172
+ /** Bound, unmodified Hey API methods and their original result envelopes. */
173
+ readonly raw: SamvaRawClient;
174
+ readonly messages: DirectService<PromiseMessagesTransport>;
175
+ readonly scheduledMessages: DirectService<typeof scheduledMessages>;
176
+ readonly brands: DirectService<typeof brands>;
177
+ readonly campaigns: DirectService<typeof campaigns>;
178
+ readonly email: DirectService<PromiseEmailTransport>;
179
+ readonly media: DirectService<typeof media>;
180
+ readonly templates: DirectService<PromiseTemplatesTransport>;
181
+ readonly contacts: DirectService<typeof contacts & typeof contactEvents>;
182
+ readonly events: DirectService<typeof events>;
183
+ readonly conversations: DirectService<typeof conversations>;
184
+ readonly webhooks: DirectService<typeof webhooks>;
185
+ readonly operations: DirectService<typeof operations>;
186
+ readonly apiKeys: DirectService<typeof apiKeys>;
187
+ readonly organizations: DirectService<typeof organizations>;
188
+ readonly attachments: DirectService<typeof attachments>;
189
+ readonly contactGroups: DirectService<typeof contactGroups>;
190
+ readonly customFields: DirectService<typeof customFields>;
191
+ readonly subscriptions: DirectService<typeof subscriptions>;
192
+ readonly topics: DirectService<typeof topics>;
193
+ readonly topicForms: DirectService<typeof topicForms>;
194
+ readonly newsletters: DirectService<typeof newsletters>;
195
+ readonly agents: DirectService<typeof agents>;
196
+ readonly analytics: DirectService<typeof analytics>;
197
+ readonly feedback: DirectService<typeof feedback>;
198
+ readonly whoami: DirectService<typeof whoami>;
199
+ readonly journeys: DirectService<typeof journeys>;
200
+ readonly mailboxes: PromiseMailboxesService;
201
+ readonly namespaces: DirectService<typeof namespaces>;
202
+ readonly extensions: DirectService<typeof extensions>;
203
+ readonly extensionInstallations: DirectService<typeof extensionInstallations>;
204
+ }
205
+ /** Create a configured Promise client. */
206
+ type BoundClientConfig = SamvaClientConfigBase & {
207
+ fetch: typeof globalThis.fetch;
208
+ apiKey?: never;
209
+ authToken?: never;
210
+ orgSlug?: never;
211
+ };
212
+ export declare function clientWithIdempotency(client: SamvaClient, idempotency: (operation: string) => string): SamvaClient;
213
+ export declare const createBoundClient: (config: BoundClientConfig) => SamvaClient;
214
+ export declare const createClient: (config: SamvaClientConfig) => SamvaClient;
215
+ export type { Client, Config } from "../client/client";
@@ -0,0 +1,324 @@
1
+ import { CLIENT_ATTRIBUTION_HEADER, clientAttribution } from "../client-attribution.js";
2
+ import { mergeHeaders } from "../client/client/utils.gen.js";
3
+ import { createClient as createClient$1 } from "../client/client/client.gen.js";
4
+ import { SamvaOperations } from "../effect/generated-metadata.js";
5
+ import { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTransportError, SenderNotReadyError, TemplateSourceError, UnauthorizedError, ValidationError, fromApiError } from "./errors.gen.js";
6
+ import { configureRequests } from "./request.js";
7
+ import { Agents, Analytics, ApiKeys, Attachments, Brands, Campaigns, ContactEvents, ContactGroups, Contacts, Conversations, CustomFields, Email, Events, ExtensionInstallations, Extensions, Feedback, Journeys, Mailboxes, Media, Messages, Namespaces, Newsletters, Operations, Organizations, ScheduledMessages, Subscriptions, Templates, TopicForms, Topics, Webhooks, Whoami } from "../client/sdk.gen.js";
8
+ import { MediaUploadError, mediaCreateBody, planInlineUploads, withUploadedAttachments } from "../inline-attachments.js";
9
+ import { MailboxEventStream } from "../mailbox-events.js";
10
+ import { buildEmailSendPayload, buildMessagesSendPayload, replyToEmailsPayload } from "../normalize.js";
11
+ // src/promises/client.ts
12
+ /**
13
+ * Samva SDK - TypeScript client for the Samva API.
14
+ *
15
+ * Ergonomic methods resolve with decoded success values and throw generated
16
+ * plain-JavaScript error classes. The bound Hey API result surface remains
17
+ * available under `client.raw` for transport-level access.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { createClient, RateLimitedError } from "samva";
22
+ *
23
+ * const samva = createClient({ apiKey: "<samva-api-key>" });
24
+ *
25
+ * try {
26
+ * const { contact } = await samva.contacts.findOrCreate({
27
+ * create: { name: "Ada Lovelace" },
28
+ * lookup: { type: "email", value: "ada@example.com" },
29
+ * });
30
+ * await samva.email.send({
31
+ * to: contact,
32
+ * subject: "Hello",
33
+ * html: "<p>Hi there!</p>",
34
+ * });
35
+ * } catch (error) {
36
+ * if (error instanceof RateLimitedError) console.log(error.retryAfterSeconds);
37
+ * }
38
+ * ```
39
+ */
40
+ const isObject = (value) => typeof value === "object" && value !== null;
41
+ /**
42
+ * Inline attachment content over the API's request cap travels as media instead: the largest
43
+ * attachments are uploaded (create, put to the presigned URL, complete) and replaced by their
44
+ * `mediaId`. The returned payload is the one request every send attempt reuses, so nothing is
45
+ * uploaded twice.
46
+ */
47
+ async function uploadOversizedAttachments(clientInstance, payload, requestOptions) {
48
+ const plan = planInlineUploads(payload);
49
+ if (plan.length === 0) return payload;
50
+ const uploaded = /* @__PURE__ */ new Map();
51
+ const directMedia = createDirectService(createBoundService(Media, clientInstance));
52
+ for (const upload of plan) {
53
+ const created = await directMedia.create(mediaCreateBody(upload), requestOptions);
54
+ await putUpload(clientInstance, upload, created, requestOptions.signal ?? void 0);
55
+ await directMedia.complete({ id: created.id }, requestOptions);
56
+ uploaded.set(upload.index, {
57
+ mediaId: created.id,
58
+ upload
59
+ });
60
+ }
61
+ return withUploadedAttachments(payload, uploaded);
62
+ }
63
+ /**
64
+ * Send with oversized inline attachments uploaded first. Within the cap this is the send call
65
+ * itself, one request and no extra await, so its result is returned unchanged.
66
+ */
67
+ function sendWithUploads(clientInstance, payload, requestOptions, send) {
68
+ if (planInlineUploads(payload).length === 0) return send(payload);
69
+ return uploadOversizedAttachments(clientInstance, payload, requestOptions).then(send);
70
+ }
71
+ async function putUpload(clientInstance, upload, created, signal) {
72
+ const fail = (status, cause) => new MediaUploadError({
73
+ filename: upload.filename,
74
+ mediaId: created.id,
75
+ status,
76
+ cause
77
+ });
78
+ let response;
79
+ try {
80
+ response = await (clientInstance.getConfig().fetch ?? globalThis.fetch)(new Request(created.upload.url, {
81
+ method: created.upload.method,
82
+ headers: created.upload.headers,
83
+ body: upload.bytes,
84
+ signal: signal ?? null
85
+ }));
86
+ } catch (error) {
87
+ throw fail(void 0, error);
88
+ }
89
+ if (!response.ok) throw fail(response.status);
90
+ }
91
+ function createPromiseMessagesTransport(clientInstance) {
92
+ const boundMessages = createBoundService(Messages, clientInstance);
93
+ return {
94
+ list: boundMessages.list,
95
+ remove: boundMessages.remove,
96
+ get: boundMessages.get,
97
+ getEmail: boundMessages.getEmail,
98
+ getStatus: boundMessages.getStatus,
99
+ getEvents: boundMessages.getEvents,
100
+ listDeliveries: boundMessages.listDeliveries,
101
+ getContent: boundMessages.getContent,
102
+ validateEmail: boundMessages.validateEmail,
103
+ send: (input, options) => {
104
+ const requestOptions = options ?? {};
105
+ return sendWithUploads(clientInstance, buildMessagesSendPayload(input), requestOptions, (payload) => Messages.send({ ...payload }, {
106
+ ...requestOptions,
107
+ client: clientInstance
108
+ }));
109
+ }
110
+ };
111
+ }
112
+ function createPromiseEmailTransport(clientInstance) {
113
+ const boundEmail = createBoundService(Email, clientInstance);
114
+ return Object.assign(boundEmail, {
115
+ addSender: (input, options) => {
116
+ const { replyToEmails, ...sender } = input;
117
+ const requestOptions = options ?? {};
118
+ return Email.addSender({
119
+ ...sender,
120
+ ...replyToEmailsPayload(replyToEmails)
121
+ }, {
122
+ ...requestOptions,
123
+ client: clientInstance
124
+ });
125
+ },
126
+ send: (input, options) => {
127
+ const requestOptions = options ?? {};
128
+ return sendWithUploads(clientInstance, buildEmailSendPayload(input), requestOptions, (payload) => Messages.send({ ...payload }, {
129
+ ...requestOptions,
130
+ client: clientInstance
131
+ }));
132
+ }
133
+ });
134
+ }
135
+ function createPromiseTemplatesTransport(clientInstance) {
136
+ return createBoundService(Templates, clientInstance);
137
+ }
138
+ function createBoundService(service, clientInstance) {
139
+ const bound = {};
140
+ for (const key of Object.getOwnPropertyNames(service)) {
141
+ if (key === "length" || key === "name" || key === "prototype") continue;
142
+ const value = service[key];
143
+ if (typeof value === "function" && Object.getOwnPropertyNames(value).some((name) => typeof Reflect.get(value, name) === "function")) bound[key] = createBoundService(value, clientInstance);
144
+ else if (typeof value === "function") {
145
+ bound[key] = value.length >= 2 ? (parameters, options) => value(parameters ?? {}, {
146
+ ...options,
147
+ client: clientInstance
148
+ }) : (options) => value({
149
+ ...options,
150
+ client: clientInstance
151
+ });
152
+ Object.assign(bound[key], value);
153
+ } else if (isObject(value)) bound[key] = createBoundService(value, clientInstance);
154
+ else bound[key] = value;
155
+ }
156
+ return bound;
157
+ }
158
+ const directOptions = (options) => ({
159
+ ...isObject(options) ? options : {},
160
+ responseStyle: "fields",
161
+ throwOnError: false
162
+ });
163
+ async function unwrap(method, arguments_) {
164
+ let result;
165
+ try {
166
+ result = await method(...arguments_);
167
+ } catch (error) {
168
+ if (error instanceof MediaUploadError) throw error;
169
+ throw fromApiError(error);
170
+ }
171
+ if (!isObject(result)) throw new SamvaTransportError(result);
172
+ const raw = result;
173
+ const context = {
174
+ request: raw.request,
175
+ response: raw.response
176
+ };
177
+ if (raw.error !== void 0) throw fromApiError(raw.error, context);
178
+ if ("data" in raw) return raw.data;
179
+ throw new SamvaTransportError(result, context);
180
+ }
181
+ function createDirectService(service) {
182
+ const direct = {};
183
+ for (const key of Object.getOwnPropertyNames(service)) {
184
+ if (key === "length" || key === "name" || key === "prototype") continue;
185
+ const value = service[key];
186
+ if (typeof value === "function" && Object.getOwnPropertyNames(value).some((name) => typeof Reflect.get(value, name) === "function")) direct[key] = createDirectService(value);
187
+ else if (typeof value === "function") {
188
+ const method = (...args) => value(...args);
189
+ direct[key] = value.length >= 2 ? (parameters = {}, options = {}) => unwrap(method, [parameters, directOptions(options)]) : (options = {}) => unwrap(method, [directOptions(options)]);
190
+ const operation = value.operation;
191
+ if (operation !== void 0 && SamvaOperations[operation].paginated) {
192
+ const list = direct[key];
193
+ const pages = async function* (params = {}, options = {}) {
194
+ let cursor = params.cursor;
195
+ do {
196
+ const page = await list({
197
+ ...params,
198
+ cursor
199
+ }, options);
200
+ if (!isObject(page) || !Array.isArray(page.items) || !(page.nextCursor === null || typeof page.nextCursor === "string")) throw new SamvaTransportError(page);
201
+ yield page;
202
+ cursor = page.nextCursor;
203
+ } while (cursor !== null);
204
+ };
205
+ Object.assign(direct[key], {
206
+ pages,
207
+ items: async function* (params, options) {
208
+ for await (const page of pages(params, options)) yield* page.items;
209
+ }
210
+ });
211
+ }
212
+ } else if (isObject(value)) direct[key] = createDirectService(value);
213
+ else direct[key] = value;
214
+ }
215
+ return direct;
216
+ }
217
+ const clientFactories = /* @__PURE__ */ new WeakMap();
218
+ function clientWithIdempotency(client, idempotency) {
219
+ const factory = clientFactories.get(client);
220
+ if (factory === void 0) throw new TypeError("Expected a client created by samva");
221
+ return factory(idempotency);
222
+ }
223
+ const createBoundClient = (config) => makeClient(config);
224
+ const createClient = (config) => makeClient(config);
225
+ function makeClient(config) {
226
+ const authHeaders = config.authToken !== void 0 ? {
227
+ Authorization: `Bearer ${config.authToken}`,
228
+ ...config.orgSlug === void 0 ? {} : { "x-org-slug": config.orgSlug }
229
+ } : config.apiKey === void 0 ? {} : { "X-API-Key": config.apiKey };
230
+ const clientInstance = createClient$1({
231
+ ...config,
232
+ baseUrl: config.baseUrl ?? "https://api.samva.dev",
233
+ headers: mergeHeaders({ [CLIENT_ATTRIBUTION_HEADER]: clientAttribution("typescript-promise") }, config.headers, authHeaders),
234
+ responseStyle: "fields",
235
+ throwOnError: false
236
+ });
237
+ configureRequests(clientInstance, config);
238
+ clientInstance.interceptors.request.use((request) => {
239
+ const headers = new Headers(request.headers);
240
+ for (const [name, value] of Object.entries(authHeaders)) headers.set(name, value);
241
+ return new Request(request, { headers });
242
+ });
243
+ const raw = {
244
+ client: clientInstance,
245
+ messages: createBoundService(Messages, clientInstance),
246
+ scheduledMessages: createBoundService(ScheduledMessages, clientInstance),
247
+ brands: createBoundService(Brands, clientInstance),
248
+ campaigns: createBoundService(Campaigns, clientInstance),
249
+ email: createBoundService(Email, clientInstance),
250
+ media: createBoundService(Media, clientInstance),
251
+ templates: createPromiseTemplatesTransport(clientInstance),
252
+ contacts: Object.assign(createBoundService(Contacts, clientInstance), createBoundService(ContactEvents, clientInstance)),
253
+ events: createBoundService(Events, clientInstance),
254
+ conversations: createBoundService(Conversations, clientInstance),
255
+ webhooks: createBoundService(Webhooks, clientInstance),
256
+ operations: createBoundService(Operations, clientInstance),
257
+ apiKeys: createBoundService(ApiKeys, clientInstance),
258
+ organizations: createBoundService(Organizations, clientInstance),
259
+ attachments: createBoundService(Attachments, clientInstance),
260
+ contactGroups: createBoundService(ContactGroups, clientInstance),
261
+ customFields: createBoundService(CustomFields, clientInstance),
262
+ subscriptions: createBoundService(Subscriptions, clientInstance),
263
+ topics: createBoundService(Topics, clientInstance),
264
+ topicForms: createBoundService(TopicForms, clientInstance),
265
+ newsletters: createBoundService(Newsletters, clientInstance),
266
+ agents: createBoundService(Agents, clientInstance),
267
+ analytics: createBoundService(Analytics, clientInstance),
268
+ feedback: createBoundService(Feedback, clientInstance),
269
+ whoami: createBoundService(Whoami, clientInstance),
270
+ journeys: createBoundService(Journeys, clientInstance),
271
+ mailboxes: createBoundService(Mailboxes, clientInstance),
272
+ namespaces: createBoundService(Namespaces, clientInstance),
273
+ extensions: createBoundService(Extensions, clientInstance),
274
+ extensionInstallations: createBoundService(ExtensionInstallations, clientInstance)
275
+ };
276
+ const streamConnection = {
277
+ baseUrl: config.baseUrl ?? "https://api.samva.dev",
278
+ headers: async () => Object.fromEntries(mergeHeaders({ [CLIENT_ATTRIBUTION_HEADER]: clientAttribution("typescript-promise") }, config.headers, authHeaders).entries()),
279
+ fetch: config.fetch
280
+ };
281
+ const promiseMessages = createPromiseMessagesTransport(clientInstance);
282
+ const promiseEmail = createPromiseEmailTransport(clientInstance);
283
+ const result = {
284
+ raw,
285
+ messages: createDirectService(promiseMessages),
286
+ scheduledMessages: createDirectService(raw.scheduledMessages),
287
+ brands: createDirectService(raw.brands),
288
+ campaigns: createDirectService(raw.campaigns),
289
+ email: createDirectService(promiseEmail),
290
+ media: createDirectService(raw.media),
291
+ templates: createDirectService(raw.templates),
292
+ contacts: createDirectService(raw.contacts),
293
+ events: createDirectService(raw.events),
294
+ conversations: createDirectService(raw.conversations),
295
+ webhooks: createDirectService(raw.webhooks),
296
+ operations: createDirectService(raw.operations),
297
+ apiKeys: createDirectService(raw.apiKeys),
298
+ organizations: createDirectService(raw.organizations),
299
+ attachments: createDirectService(raw.attachments),
300
+ contactGroups: createDirectService(raw.contactGroups),
301
+ customFields: createDirectService(raw.customFields),
302
+ subscriptions: createDirectService(raw.subscriptions),
303
+ topics: createDirectService(raw.topics),
304
+ topicForms: createDirectService(raw.topicForms),
305
+ newsletters: createDirectService(raw.newsletters),
306
+ agents: createDirectService(raw.agents),
307
+ analytics: createDirectService(raw.analytics),
308
+ feedback: createDirectService(raw.feedback),
309
+ whoami: createDirectService(raw.whoami),
310
+ journeys: createDirectService(raw.journeys),
311
+ mailboxes: Object.assign(createDirectService(raw.mailboxes), { events: (options) => new MailboxEventStream(streamConnection, options) }),
312
+ namespaces: createDirectService(raw.namespaces),
313
+ extensions: createDirectService(raw.extensions),
314
+ extensionInstallations: createDirectService(raw.extensionInstallations)
315
+ };
316
+ clientFactories.set(result, (idempotency) => makeClient({
317
+ ...config,
318
+ idempotency
319
+ }));
320
+ return result;
321
+ }
322
+ export { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTransportError, SenderNotReadyError, TemplateSourceError, UnauthorizedError, ValidationError, clientWithIdempotency, createBoundClient, createClient, fromApiError };
323
+
324
+ //# sourceMappingURL=client.js.map
@@ -1,4 +1,4 @@
1
- //#region src/promises/errors.gen.ts
1
+ // src/promises/errors.gen.ts
2
2
  const redactRequest = (request) => request === void 0 ? void 0 : new Request(request.url, { method: request.method });
3
3
  /** Base class for failures declared by the public Samva OpenAPI contract. */
4
4
  var SamvaApiError = class extends Error {
@@ -1471,7 +1471,6 @@ function fromApiError(error, context = {}) {
1471
1471
  }
1472
1472
  return new SamvaTransportError(error, context);
1473
1473
  }
1474
- //#endregion
1475
1474
  export { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTransportError, SenderNotReadyError, TemplateSourceError, UnauthorizedError, ValidationError, fromApiError };
1476
1475
 
1477
1476
  //# sourceMappingURL=errors.gen.js.map