samva 0.50.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +49 -5
- package/README.md +137 -7
- package/dist/client/sdk.gen.d.ts +78 -38
- package/dist/client/sdk.gen.js +1554 -967
- package/dist/client/types.gen.d.ts +541 -291
- package/dist/effect/agents.d.ts +4 -4
- package/dist/effect/api-keys.d.ts +4 -6
- package/dist/effect/campaigns.d.ts +222 -230
- package/dist/effect/categories.d.ts +2 -2
- package/dist/effect/categories.js +6 -4
- package/dist/effect/contact-groups.d.ts +4 -4
- package/dist/effect/contacts.d.ts +8 -8
- package/dist/effect/conversations.d.ts +4 -4
- package/dist/effect/descriptors/integrations-catalog.d.ts +1 -1
- package/dist/effect/descriptors/integrations-catalog.js +1 -1
- package/dist/effect/descriptors/integrations.d.ts +1 -1
- package/dist/effect/descriptors/integrations.js +1 -1
- package/dist/effect/descriptors/logs.d.ts +21 -0
- package/dist/effect/descriptors/logs.js +23 -0
- package/dist/effect/descriptors/whats-app.d.ts +1 -1
- package/dist/effect/descriptors/whats-app.js +1 -1
- package/dist/effect/email.d.ts +17 -16
- package/dist/effect/errors.d.ts +1 -0
- package/dist/effect/errors.js +2 -1
- package/dist/effect/generated/agents.js +4 -4
- package/dist/effect/generated/api-keys.d.ts +0 -15
- package/dist/effect/generated/api-keys.js +1 -2
- package/dist/effect/generated/campaigns.d.ts +18 -68
- package/dist/effect/generated/campaigns.js +5 -15
- package/dist/effect/generated/email.d.ts +10 -3
- package/dist/effect/generated/email.js +6 -5
- package/dist/effect/generated/index.d.ts +3 -1
- package/dist/effect/generated/integrations-catalog.d.ts +93 -49
- package/dist/effect/generated/integrations-catalog.js +17 -28
- package/dist/effect/generated/integrations.d.ts +20 -40
- package/dist/effect/generated/integrations.js +9 -13
- package/dist/effect/generated/journeys.d.ts +61 -13
- package/dist/effect/generated/journeys.js +5 -5
- package/dist/effect/generated/logs.d.ts +2311 -0
- package/dist/effect/generated/logs.js +312 -0
- package/dist/effect/generated/mailboxes.d.ts +30 -24
- package/dist/effect/generated/mailboxes.js +25 -25
- package/dist/effect/generated/messages.d.ts +1 -882
- package/dist/effect/generated/messages.js +4 -243
- package/dist/effect/generated/namespaces.js +1 -1
- package/dist/effect/generated/newsletter-domains.d.ts +61 -13
- package/dist/effect/generated/newsletter-domains.js +5 -5
- package/dist/effect/generated/newsletter-issues.d.ts +166 -34
- package/dist/effect/generated/newsletter-issues.js +12 -12
- package/dist/effect/generated/newsletters.d.ts +76 -16
- package/dist/effect/generated/newsletters.js +6 -6
- package/dist/effect/generated/organizations.js +1 -1
- package/dist/effect/generated/policies.js +2 -2
- package/dist/effect/generated/scheduled-messages.d.ts +0 -26
- package/dist/effect/generated/scheduled-messages.js +2 -4
- package/dist/effect/generated/shared.d.ts +1139 -257
- package/dist/effect/generated/shared.js +323 -83
- package/dist/effect/generated/subscriptions.d.ts +4 -4
- package/dist/effect/generated/subscriptions.js +2 -6
- package/dist/effect/generated/template-registrations.d.ts +46 -10
- package/dist/effect/generated/template-registrations.js +4 -4
- package/dist/effect/generated/templates.js +2 -2
- package/dist/effect/generated/whats-app-flows.d.ts +151 -31
- package/dist/effect/generated/whats-app-flows.js +11 -11
- package/dist/effect/generated/whats-app-setup-links.d.ts +61 -13
- package/dist/effect/generated/whats-app-setup-links.js +5 -5
- package/dist/effect/generated/whats-app.d.ts +187 -65
- package/dist/effect/generated/whats-app.js +18 -24
- package/dist/effect/generated-metadata.d.ts +15 -3
- package/dist/effect/generated-metadata.js +375 -349
- package/dist/effect/index.d.ts +1 -0
- package/dist/effect/index.js +3 -1
- package/dist/effect/integrations-catalog.d.ts +92 -4
- package/dist/effect/integrations.d.ts +42 -10
- package/dist/effect/internal/client.d.ts +19 -2
- package/dist/effect/internal/client.js +35 -5
- package/dist/effect/internal/email-sender.d.ts +4 -4
- package/dist/effect/internal/email-sender.js +5 -3
- package/dist/effect/internal/log-events.d.ts +19 -0
- package/dist/effect/internal/log-events.js +53 -0
- package/dist/effect/internal/mailbox-events.d.ts +6 -2
- package/dist/effect/internal/mailbox-events.js +4 -3
- package/dist/effect/internal/operation.d.ts +11 -0
- package/dist/effect/internal/operation.js +10 -6
- package/dist/effect/internal/send.d.ts +4 -0
- package/dist/effect/internal/send.js +11 -8
- package/dist/effect/internal/timeout.d.ts +16 -0
- package/dist/effect/internal/timeout.js +20 -0
- package/dist/effect/journeys.d.ts +4 -4
- package/dist/effect/logs.d.ts +149 -0
- package/dist/effect/logs.js +18 -0
- package/dist/effect/mailboxes.d.ts +184 -178
- package/dist/effect/mailboxes.js +1 -1
- package/dist/effect/messages.d.ts +5 -5
- package/dist/effect/namespaces.d.ts +4 -4
- package/dist/effect/newsletter-domains.d.ts +2 -2
- package/dist/effect/operations.d.ts +2 -2
- package/dist/effect/scheduled-messages.d.ts +2 -6
- package/dist/effect/templates.d.ts +6 -6
- package/dist/effect/topics.d.ts +4 -4
- package/dist/effect/webhooks.d.ts +4 -4
- package/dist/effect/whatsapp-setup-links.d.ts +2 -2
- package/dist/effect/whatsapp.d.ts +73 -3
- package/dist/index.js +2 -2
- package/dist/mailbox-events.d.ts +50 -3
- package/dist/mailbox-events.js +38 -19
- package/dist/package.js +1 -1
- package/dist/promises/client.d.ts +8 -1
- package/dist/promises/client.js +15 -9
- package/dist/promises/errors.gen.d.ts +14 -1
- package/dist/promises/errors.gen.js +158 -36
- package/dist/promises/index.js +2 -2
- package/dist/promises/request.d.ts +31 -2
- package/dist/promises/request.js +42 -7
- package/dist/promises/types.gen.d.ts +1 -1
- package/dist/request-id.d.ts +3 -0
- package/dist/request-id.js +7 -0
- package/dist/request-policy.d.ts +9 -0
- package/dist/request-policy.js +16 -1
- package/dist/service-map.d.ts +14 -3
- package/package.json +6 -2
package/dist/mailbox-events.js
CHANGED
|
@@ -126,7 +126,7 @@ const decodeFrame = (raw) => {
|
|
|
126
126
|
cursor: parsed.cursor
|
|
127
127
|
};
|
|
128
128
|
if (parsed.kind !== "event" || typeof parsed.id !== "string" || !isRecord(parsed.event)) return;
|
|
129
|
-
const { type, timestamp, data } = parsed.event;
|
|
129
|
+
const { type, timestamp, data, match } = parsed.event;
|
|
130
130
|
if (typeof type !== "string" || typeof timestamp !== "string") return void 0;
|
|
131
131
|
return {
|
|
132
132
|
kind: "event",
|
|
@@ -135,12 +135,13 @@ const decodeFrame = (raw) => {
|
|
|
135
135
|
event: {
|
|
136
136
|
type,
|
|
137
137
|
timestamp,
|
|
138
|
-
data
|
|
138
|
+
data,
|
|
139
|
+
match
|
|
139
140
|
}
|
|
140
141
|
};
|
|
141
142
|
};
|
|
142
143
|
/** The events URL for an API origin: `https://api.samva.dev` → `wss://events.samva.dev/v1/…`. */
|
|
143
|
-
const
|
|
144
|
+
const eventStreamUrl = (connection, options, path = MAILBOX_EVENT_STREAM_PATH) => {
|
|
144
145
|
const invalid = (message) => new MailboxEventStreamError({
|
|
145
146
|
_tag: "StreamClientError",
|
|
146
147
|
message
|
|
@@ -158,7 +159,7 @@ const mailboxEventsUrl = (connection, options) => {
|
|
|
158
159
|
if (url.protocol === "https:") url.protocol = "wss:";
|
|
159
160
|
else if (url.protocol === "http:") url.protocol = "ws:";
|
|
160
161
|
if (url.protocol !== "wss:" && url.protocol !== "ws:") throw invalid("The events origin must be an http, https, ws, or wss URL.");
|
|
161
|
-
url.pathname =
|
|
162
|
+
url.pathname = path;
|
|
162
163
|
url.search = "";
|
|
163
164
|
url.hash = "";
|
|
164
165
|
if (options.cursor !== void 0) url.searchParams.set("cursor", options.cursor);
|
|
@@ -255,7 +256,9 @@ const sleep = (millis, signal) => new Promise((resolve) => {
|
|
|
255
256
|
* A resumable stream of mailbox events. Iterate it with `for await`; break out of the loop or call
|
|
256
257
|
* {@link close} to end it.
|
|
257
258
|
*/
|
|
258
|
-
var
|
|
259
|
+
var EventStream = class {
|
|
260
|
+
path;
|
|
261
|
+
readEvent;
|
|
259
262
|
#connection;
|
|
260
263
|
#options;
|
|
261
264
|
#stop = new AbortController();
|
|
@@ -276,11 +279,13 @@ var MailboxEventStream = class {
|
|
|
276
279
|
#inHand;
|
|
277
280
|
#cursor;
|
|
278
281
|
#unacked = 0;
|
|
279
|
-
constructor(connection, options
|
|
282
|
+
constructor(connection, options, path, readEvent) {
|
|
283
|
+
this.path = path;
|
|
284
|
+
this.readEvent = readEvent;
|
|
280
285
|
this.#connection = connection;
|
|
281
286
|
this.#options = options;
|
|
282
287
|
this.#cursor = options.cursor;
|
|
283
|
-
|
|
288
|
+
eventStreamUrl(connection, options, path);
|
|
284
289
|
if (options.signal?.aborted) this.close();
|
|
285
290
|
else {
|
|
286
291
|
this.#callerSignal = options.signal;
|
|
@@ -484,10 +489,10 @@ var MailboxEventStream = class {
|
|
|
484
489
|
}));
|
|
485
490
|
return resolve({ kind: "stopped" });
|
|
486
491
|
}
|
|
487
|
-
const url =
|
|
492
|
+
const url = eventStreamUrl(this.#connection, {
|
|
488
493
|
...this.#options,
|
|
489
494
|
cursor: this.#resumeCursor()
|
|
490
|
-
});
|
|
495
|
+
}, this.path);
|
|
491
496
|
let opened = false;
|
|
492
497
|
let settled = false;
|
|
493
498
|
let idleTimer;
|
|
@@ -544,13 +549,16 @@ var MailboxEventStream = class {
|
|
|
544
549
|
}
|
|
545
550
|
if (frame.kind === "pong") return;
|
|
546
551
|
if (frame.kind === "event") {
|
|
547
|
-
this
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
552
|
+
const event = this.readEvent(frame);
|
|
553
|
+
if (event === void 0) {
|
|
554
|
+
this.#fail(new MailboxEventStreamError({
|
|
555
|
+
_tag: "StreamProtocolError",
|
|
556
|
+
message: DESCRIPTION.StreamProtocolError,
|
|
557
|
+
cursor: this.#cursor
|
|
558
|
+
}));
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
this.#queue.push(event);
|
|
554
562
|
this.#wake();
|
|
555
563
|
return;
|
|
556
564
|
}
|
|
@@ -580,10 +588,10 @@ var MailboxEventStream = class {
|
|
|
580
588
|
* are worth a retry.
|
|
581
589
|
*/
|
|
582
590
|
async #diagnose() {
|
|
583
|
-
const url =
|
|
591
|
+
const url = eventStreamUrl(this.#connection, {
|
|
584
592
|
...this.#options,
|
|
585
593
|
cursor: this.#resumeCursor()
|
|
586
|
-
});
|
|
594
|
+
}, this.path);
|
|
587
595
|
url.protocol = url.protocol === "wss:" ? "https:" : "http:";
|
|
588
596
|
const deadline = new AbortController();
|
|
589
597
|
const onStop = () => deadline.abort();
|
|
@@ -653,6 +661,17 @@ const readRefusalBody = async (response) => {
|
|
|
653
661
|
return;
|
|
654
662
|
}
|
|
655
663
|
};
|
|
656
|
-
|
|
664
|
+
var MailboxEventStream = class extends EventStream {
|
|
665
|
+
constructor(connection, options = {}) {
|
|
666
|
+
super(connection, options, MAILBOX_EVENT_STREAM_PATH, (frame) => ({
|
|
667
|
+
cursor: frame.cursor,
|
|
668
|
+
id: frame.id,
|
|
669
|
+
type: frame.event.type,
|
|
670
|
+
timestamp: frame.event.timestamp,
|
|
671
|
+
data: isRecord(frame.event.data) ? frame.event.data : {}
|
|
672
|
+
}));
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
export { EventStream, MAILBOX_EVENT_STREAM_IDLE_MILLIS, MAILBOX_EVENT_STREAM_PING_MILLIS, MailboxEventStream, MailboxEventStreamCloseCode, MailboxEventStreamError, eventStreamUrl, readRefusalBody, refusalOutcome };
|
|
657
676
|
|
|
658
677
|
//# sourceMappingURL=mailbox-events.js.map
|
package/dist/package.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
import { type Client, type Config } from "../client/client/index.js";
|
|
30
|
-
import { Agents as agents, Accounts as accounts, Integrations as integrations, IntegrationCatalog as integrationCatalog, Whatsapp as whatsapp, WhatsappFlows as whatsappFlows, WhatsappSetupLinks as whatsappSetupLinks, TemplateRegistrations as templateRegistrations, TemplateShareLinks as templateShareLinks, Analytics as analytics, ApiKeys as apiKeys, ApprovalRequests as approvalRequests, 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, 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, Policies as policies, 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.js";
|
|
30
|
+
import { Agents as agents, Accounts as accounts, Integrations as integrations, IntegrationCatalog as integrationCatalog, Whatsapp as whatsapp, WhatsappFlows as whatsappFlows, WhatsappSetupLinks as whatsappSetupLinks, TemplateRegistrations as templateRegistrations, TemplateShareLinks as templateShareLinks, Analytics as analytics, ApiKeys as apiKeys, ApprovalRequests as approvalRequests, 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, Events as events, Feedback as feedback, Journeys as journeys, Logs as logs, Mailboxes as mailboxes, Media as media, Messages as messages, Namespaces as namespaces, Operations as operations, Organizations as organizations, Policies as policies, 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.js";
|
|
31
31
|
import type { MessagesSendData } from "../client/types.gen.js";
|
|
32
32
|
import { MailboxEventStream, type MailboxEventStreamOptions } from "../mailbox-events.js";
|
|
33
33
|
import { type RequestPolicy } from "./request.js";
|
|
@@ -54,6 +54,11 @@ type MessageSendRequestOptions<ThrowOnError extends boolean = false> = Omit<NonN
|
|
|
54
54
|
type MessageSendOptions<ThrowOnError extends boolean = false> = MessageSendRequestOptions<ThrowOnError> & {
|
|
55
55
|
/** Sent as the `idempotency-key` header; defaults to a fresh UUID per call. */
|
|
56
56
|
readonly idempotencyKey?: string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Overrides the client's `uploadTimeoutMs` for the storage puts of oversized inline
|
|
59
|
+
* attachments; `undefined` inherits it.
|
|
60
|
+
*/
|
|
61
|
+
readonly uploadTimeoutMs?: number | null | undefined;
|
|
57
62
|
};
|
|
58
63
|
type MessageSendResponse<ThrowOnError extends boolean = false> = ReturnType<typeof messages.send<ThrowOnError>>;
|
|
59
64
|
/** The send's own promise, or the promise that resolves to the same value once uploads finish. */
|
|
@@ -165,6 +170,7 @@ export interface SamvaRawClient {
|
|
|
165
170
|
readonly feedback: typeof feedback;
|
|
166
171
|
readonly whoami: typeof whoami;
|
|
167
172
|
readonly journeys: typeof journeys;
|
|
173
|
+
readonly logs: typeof logs;
|
|
168
174
|
readonly mailboxes: typeof mailboxes;
|
|
169
175
|
readonly namespaces: typeof namespaces;
|
|
170
176
|
}
|
|
@@ -179,6 +185,7 @@ export type PromiseMailboxesService = DirectService<typeof mailboxes> & {
|
|
|
179
185
|
export interface SamvaClient {
|
|
180
186
|
/** Bound, unmodified Hey API methods and their original result envelopes. */
|
|
181
187
|
readonly raw: SamvaRawClient;
|
|
188
|
+
readonly logs: DirectService<typeof logs>;
|
|
182
189
|
readonly messages: DirectService<PromiseMessagesTransport>;
|
|
183
190
|
readonly scheduledMessages: DirectService<typeof scheduledMessages>;
|
|
184
191
|
readonly brands: DirectService<typeof brands>;
|
package/dist/promises/client.js
CHANGED
|
@@ -2,9 +2,9 @@ import { CLIENT_ATTRIBUTION_HEADER, clientAttribution } from "../client-attribut
|
|
|
2
2
|
import { mergeHeaders } from "../client/client/utils.gen.js";
|
|
3
3
|
import { createClient as createClient$1 } from "../client/client/client.gen.js";
|
|
4
4
|
import { SamvaOperations } from "../effect/generated-metadata.js";
|
|
5
|
-
import { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, fromApiError } from "./errors.gen.js";
|
|
6
|
-
import { configureRequests } from "./request.js";
|
|
7
|
-
import { Accounts, Agents, Analytics, ApiKeys, ApprovalRequests, Attachments, Brands, Campaigns, ContactEvents, ContactGroups, Contacts, Conversations, CustomFields, Email, Events, Feedback, IntegrationCatalog, Integrations, Journeys, Mailboxes, Media, Messages, Namespaces, Newsletters, Operations, Organizations, Policies, ScheduledMessages, Subscriptions, TemplateRegistrations, TemplateShareLinks, Templates, TopicForms, Topics, Webhooks, Whatsapp, WhatsappFlows, WhatsappSetupLinks, Whoami } from "../client/sdk.gen.js";
|
|
5
|
+
import { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTimeoutError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, fromApiError } from "./errors.gen.js";
|
|
6
|
+
import { configureRequests, startAttempt, uploadTimeout } from "./request.js";
|
|
7
|
+
import { Accounts, Agents, Analytics, ApiKeys, ApprovalRequests, Attachments, Brands, Campaigns, ContactEvents, ContactGroups, Contacts, Conversations, CustomFields, Email, Events, Feedback, IntegrationCatalog, Integrations, Journeys, Logs, Mailboxes, Media, Messages, Namespaces, Newsletters, Operations, Organizations, Policies, ScheduledMessages, Subscriptions, TemplateRegistrations, TemplateShareLinks, Templates, TopicForms, Topics, Webhooks, Whatsapp, WhatsappFlows, WhatsappSetupLinks, Whoami } from "../client/sdk.gen.js";
|
|
8
8
|
import { MediaUploadError, mediaCreateBody, planInlineUploads, withUploadedAttachments } from "../inline-attachments.js";
|
|
9
9
|
import { MailboxEventStream } from "../mailbox-events.js";
|
|
10
10
|
import { buildEmailSendPayload, buildMessagesSendPayload, replyToEmailsPayload } from "../normalize.js";
|
|
@@ -51,7 +51,7 @@ async function uploadOversizedAttachments(clientInstance, payload, requestOption
|
|
|
51
51
|
const directMedia = createDirectService(createBoundService(Media, clientInstance));
|
|
52
52
|
for (const upload of plan) {
|
|
53
53
|
const created = await directMedia.create(mediaCreateBody(upload), requestOptions);
|
|
54
|
-
await putUpload(clientInstance, upload, created, requestOptions
|
|
54
|
+
await putUpload(clientInstance, upload, created, requestOptions);
|
|
55
55
|
await directMedia.complete({ id: created.id }, requestOptions);
|
|
56
56
|
uploaded.set(upload.index, {
|
|
57
57
|
mediaId: created.id,
|
|
@@ -72,23 +72,27 @@ function sendWithUploads(clientInstance, payload, requestOptions, send) {
|
|
|
72
72
|
async function sendAfterUploads(clientInstance, payload, requestOptions, send) {
|
|
73
73
|
return await send(await uploadOversizedAttachments(clientInstance, payload, requestOptions));
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
/** A put that outlasts its `uploadTimeoutMs` fails as `MediaUploadError` caused by `SamvaTimeoutError`. */
|
|
76
|
+
async function putUpload(clientInstance, upload, created, options) {
|
|
76
77
|
const fail = (status, cause) => new MediaUploadError({
|
|
77
78
|
filename: upload.filename,
|
|
78
79
|
mediaId: created.id,
|
|
79
80
|
status,
|
|
80
81
|
cause
|
|
81
82
|
});
|
|
83
|
+
const attempt = startAttempt(options.signal ?? clientInstance.getConfig().signal, uploadTimeout(clientInstance, options.uploadTimeoutMs));
|
|
82
84
|
let response;
|
|
83
85
|
try {
|
|
84
86
|
response = await (clientInstance.getConfig().fetch ?? globalThis.fetch)(new Request(created.upload.url, {
|
|
85
87
|
method: created.upload.method,
|
|
86
88
|
headers: created.upload.headers,
|
|
87
89
|
body: upload.bytes,
|
|
88
|
-
signal: signal ?? null
|
|
90
|
+
signal: attempt.signal ?? null
|
|
89
91
|
}));
|
|
90
92
|
} catch (error) {
|
|
91
|
-
throw fail(void 0, error);
|
|
93
|
+
throw fail(void 0, attempt.timedOut() ?? error);
|
|
94
|
+
} finally {
|
|
95
|
+
attempt.end();
|
|
92
96
|
}
|
|
93
97
|
if (!response.ok) throw fail(response.status);
|
|
94
98
|
}
|
|
@@ -169,7 +173,7 @@ async function unwrap(method, arguments_) {
|
|
|
169
173
|
try {
|
|
170
174
|
result = await method(...arguments_);
|
|
171
175
|
} catch (error) {
|
|
172
|
-
if (error instanceof MediaUploadError) throw error;
|
|
176
|
+
if (error instanceof MediaUploadError || error instanceof RangeError) throw error;
|
|
173
177
|
throw fromApiError(error);
|
|
174
178
|
}
|
|
175
179
|
if (!isObject(result)) throw new SamvaTransportError(result);
|
|
@@ -282,6 +286,7 @@ function makeClient(config) {
|
|
|
282
286
|
feedback: createBoundService(Feedback, clientInstance),
|
|
283
287
|
whoami: createBoundService(Whoami, clientInstance),
|
|
284
288
|
journeys: createBoundService(Journeys, clientInstance),
|
|
289
|
+
logs: createBoundService(Logs, clientInstance),
|
|
285
290
|
mailboxes: createBoundService(Mailboxes, clientInstance),
|
|
286
291
|
namespaces: createBoundService(Namespaces, clientInstance)
|
|
287
292
|
};
|
|
@@ -294,6 +299,7 @@ function makeClient(config) {
|
|
|
294
299
|
const promiseEmail = createPromiseEmailTransport(clientInstance);
|
|
295
300
|
const result = {
|
|
296
301
|
raw,
|
|
302
|
+
logs: createDirectService(raw.logs),
|
|
297
303
|
messages: createDirectService(promiseMessages),
|
|
298
304
|
scheduledMessages: createDirectService(raw.scheduledMessages),
|
|
299
305
|
brands: createDirectService(raw.brands),
|
|
@@ -339,6 +345,6 @@ function makeClient(config) {
|
|
|
339
345
|
}));
|
|
340
346
|
return result;
|
|
341
347
|
}
|
|
342
|
-
export { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, clientWithIdempotency, createBoundClient, createClient, fromApiError };
|
|
348
|
+
export { AnalyticsQueryError, BillingProviderError, BrandAddressRequiredError, CampaignFooterRequiredError, ConflictError, CredentialsError, DeliveryUnavailableError, EmailChannelError, ExternalServiceError, FlagDisabledError, ForbiddenError, FromAddressRequiredError, GatewayTimeoutError, InternalError, MailboxSendConflictError, MailboxSendRefusedError, MalformedRequestError, OnboardingReviewRequiredError, PaymentRequiredError, RateLimitedError, ResourceNotFoundError, SamvaApiError, SamvaTimeoutError, SamvaTransportError, SenderNotReadyError, ServiceUnavailableError, ShareLinkUnavailable, SlugTaken, TemplateInUseError, TemplateSourceError, UnauthorizedError, ValidationError, WhatsAppChannelError, WhatsAppServiceWindowClosedError, WhatsAppSetupLinkUnavailableError, clientWithIdempotency, createBoundClient, createClient, fromApiError };
|
|
343
349
|
|
|
344
350
|
//# sourceMappingURL=client.js.map
|
|
@@ -10,17 +10,28 @@ export declare abstract class SamvaApiError<Tag extends SamvaApiErrorTag = Samva
|
|
|
10
10
|
readonly request: Request | undefined;
|
|
11
11
|
readonly response: Response | undefined;
|
|
12
12
|
readonly status: number | undefined;
|
|
13
|
+
readonly requestId: string | undefined;
|
|
13
14
|
protected constructor(message: string, context?: SamvaApiErrorContext);
|
|
14
15
|
}
|
|
15
16
|
/** A transport or malformed-response failure that is not part of the API error contract. */
|
|
16
17
|
export declare class SamvaTransportError extends Error {
|
|
17
|
-
readonly _tag: "SamvaTransportError";
|
|
18
|
+
readonly _tag: "SamvaTransportError" | "SamvaTimeoutError";
|
|
18
19
|
readonly request: Request | undefined;
|
|
19
20
|
readonly response: Response | undefined;
|
|
20
21
|
readonly status: number | undefined;
|
|
22
|
+
readonly requestId: string | undefined;
|
|
21
23
|
readonly cause: unknown;
|
|
22
24
|
constructor(cause: unknown, context?: SamvaApiErrorContext);
|
|
23
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* A request attempt that did not finish within its `timeoutMs`. The request may still have
|
|
28
|
+
* reached the API, so a keyed write retries with the same idempotency key.
|
|
29
|
+
*/
|
|
30
|
+
export declare class SamvaTimeoutError extends SamvaTransportError {
|
|
31
|
+
readonly _tag: "SamvaTimeoutError";
|
|
32
|
+
readonly timeoutMs: number;
|
|
33
|
+
constructor(timeoutMs: number);
|
|
34
|
+
}
|
|
24
35
|
type AnalyticsQueryErrorPayload = {
|
|
25
36
|
readonly _tag: "AnalyticsQueryError";
|
|
26
37
|
readonly message: string;
|
|
@@ -127,11 +138,13 @@ export declare class ForbiddenError extends SamvaApiError<"ForbiddenError"> {
|
|
|
127
138
|
}
|
|
128
139
|
type FromAddressRequiredErrorPayload = {
|
|
129
140
|
readonly _tag: "FromAddressRequiredError";
|
|
141
|
+
readonly addresses: Array<string>;
|
|
130
142
|
readonly message: string;
|
|
131
143
|
readonly verifiedDomains: Array<string>;
|
|
132
144
|
};
|
|
133
145
|
export declare class FromAddressRequiredError extends SamvaApiError<"FromAddressRequiredError"> {
|
|
134
146
|
readonly _tag: "FromAddressRequiredError";
|
|
147
|
+
readonly "addresses": Array<string>;
|
|
135
148
|
readonly "verifiedDomains": Array<string>;
|
|
136
149
|
constructor(payload: Omit<FromAddressRequiredErrorPayload, "_tag">, context?: SamvaApiErrorContext);
|
|
137
150
|
}
|