samva 0.10.0 → 0.12.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 (71) hide show
  1. package/README.md +59 -9
  2. package/dist/client/sdk.gen.d.ts +1126 -219
  3. package/dist/client/types.gen.d.ts +11655 -6311
  4. package/dist/{client-mI4S99Ts.js → client-Cj1bqIEe.js} +5169 -1639
  5. package/dist/{client-attribution-Bl4nTEsE.js → client-attribution-BTWYSXxo.js} +2 -2
  6. package/dist/effect/analytics.d.ts +18 -18
  7. package/dist/effect/analytics.js +1 -1
  8. package/dist/effect/api-keys.d.ts +99 -43
  9. package/dist/effect/api-keys.js +2 -4
  10. package/dist/effect/attachments.d.ts +5 -6
  11. package/dist/effect/attachments.js +1 -1
  12. package/dist/effect/brands.d.ts +4 -4
  13. package/dist/effect/brands.js +2 -2
  14. package/dist/effect/campaigns.d.ts +30 -60
  15. package/dist/effect/campaigns.js +1 -1
  16. package/dist/effect/client.js +1 -1
  17. package/dist/effect/contact-groups.d.ts +29 -46
  18. package/dist/effect/contact-groups.js +1 -1
  19. package/dist/effect/contacts.d.ts +324 -726
  20. package/dist/effect/contacts.js +10 -2
  21. package/dist/effect/conversations.d.ts +575 -1130
  22. package/dist/effect/conversations.js +14 -2
  23. package/dist/effect/custom-fields.d.ts +3 -53
  24. package/dist/effect/custom-fields.js +1 -1
  25. package/dist/effect/email.d.ts +349 -298
  26. package/dist/effect/email.js +9 -3
  27. package/dist/effect/extension-installations.d.ts +218 -0
  28. package/dist/effect/extension-installations.js +25 -0
  29. package/dist/effect/extensions.d.ts +192 -0
  30. package/dist/effect/extensions.js +19 -0
  31. package/dist/effect/feedback.d.ts +12 -0
  32. package/dist/effect/feedback.js +13 -0
  33. package/dist/effect/generated.d.ts +33011 -15519
  34. package/dist/effect/index.d.ts +6 -1
  35. package/dist/effect/index.js +7 -2
  36. package/dist/effect/internal/client.d.ts +3 -0
  37. package/dist/effect/internal/mailbox-events.d.ts +11 -0
  38. package/dist/effect/internal/operation.d.ts +20 -374
  39. package/dist/effect/mailboxes.d.ts +1676 -0
  40. package/dist/effect/mailboxes.js +3 -0
  41. package/dist/effect/media.d.ts +5 -5
  42. package/dist/effect/media.js +1 -1
  43. package/dist/effect/messages.d.ts +171 -938
  44. package/dist/effect/messages.js +6 -2
  45. package/dist/effect/namespaces.d.ts +82 -0
  46. package/dist/effect/namespaces.js +19 -0
  47. package/dist/effect/operations.d.ts +68 -12
  48. package/dist/effect/operations.js +1 -1
  49. package/dist/effect/organizations.d.ts +5 -4
  50. package/dist/effect/organizations.js +1 -1
  51. package/dist/effect/pagination.d.ts +16 -21
  52. package/dist/effect/scheduled-messages.d.ts +13 -23
  53. package/dist/effect/scheduled-messages.js +1 -1
  54. package/dist/effect/templates.d.ts +204 -281
  55. package/dist/effect/templates.js +2 -2
  56. package/dist/effect/unsubscribe-groups.d.ts +21 -75
  57. package/dist/effect/unsubscribe-groups.js +1 -1
  58. package/dist/effect/webhooks.d.ts +117 -39
  59. package/dist/effect/webhooks.js +2 -2
  60. package/dist/index.js +3 -2
  61. package/dist/mailbox-events-CsbF35vH.js +629 -0
  62. package/dist/mailbox-events.d.ts +178 -0
  63. package/dist/mailboxes-BtcktcNB.js +147 -0
  64. package/dist/{operation-DQWJO4jY.js → operation-BEghYyLu.js} +411 -67
  65. package/dist/promises/errors.gen.d.ts +5 -0
  66. package/dist/promises/index.d.ts +23 -1
  67. package/dist/promises/index.js +3 -2
  68. package/dist/promises/types.gen.d.ts +1 -1
  69. package/dist/{promises-C7D4oaHn.js → promises-BzrwhHEW.js} +3273 -547
  70. package/dist/service-map.d.ts +468 -36
  71. package/package.json +22 -2
@@ -0,0 +1,178 @@
1
+ /**
2
+ * The mailbox event stream: the `mailbox.*` events a webhook endpoint receives, delivered over a
3
+ * WebSocket to a program that has no public URL for webhooks to reach.
4
+ *
5
+ * {@link MailboxEventStream} is an async iterable. The loop body handling an event is the
6
+ * acknowledgement: asking for the next event marks the previous one handled, and the stream
7
+ * resumes from the last handled event whenever it reconnects. Transient closes reconnect by
8
+ * themselves; a close the caller has to act on ends the loop with a {@link MailboxEventStreamError}.
9
+ *
10
+ * This module has no runtime dependencies so the Promise and Effect clients share it.
11
+ */
12
+ /** The WebSocket path on the events host. */
13
+ export declare const MAILBOX_EVENT_STREAM_PATH = "/v1/mailboxes/events";
14
+ /** Close codes the events host ends an accepted connection with. */
15
+ export declare const MailboxEventStreamCloseCode: {
16
+ /** The client sent a frame that is not an acknowledgement of a cursor it was sent. */
17
+ readonly invalidFrame: 4400;
18
+ /** The credential stopped authenticating: revoked, rotated, or expired. */
19
+ readonly unauthorized: 4401;
20
+ /** The credential authenticates but may no longer read mailboxes. */
21
+ readonly forbidden: 4403;
22
+ /** Mailboxes are unavailable to the organization. */
23
+ readonly gone: 4404;
24
+ /** Too many events went unacknowledged. Reconnecting from the last handled cursor recovers. */
25
+ readonly slowConsumer: 4408;
26
+ /** Events after the cursor are no longer retained. Read current state and start without one. */
27
+ readonly cursorExpired: 4410;
28
+ /** Access could not be confirmed for a while. Reconnecting from the last cursor recovers. */
29
+ readonly accessUnavailable: 4503;
30
+ };
31
+ /** The event types the stream carries: the `mailbox.*` webhook events. */
32
+ export type MailboxEventType = "mailbox.message.received" | "mailbox.message.sent" | "mailbox.action.pending_approval" | "mailbox.message.quarantined" | "mailbox.message.released" | "mailbox.message.discarded";
33
+ /** One event, as a webhook delivery of it would carry it, plus its stream position. */
34
+ export interface MailboxEvent {
35
+ /** The stream position of this event. Persist it after handling to resume from here. */
36
+ readonly cursor: string;
37
+ /** The event id: the `webhook-id` a webhook delivery of the same event carries. */
38
+ readonly id: string;
39
+ readonly type: MailboxEventType;
40
+ readonly timestamp: string;
41
+ /** The event's `data`, exactly as the webhook body carries it. */
42
+ readonly data: Readonly<Record<string, unknown>>;
43
+ }
44
+ /**
45
+ * Why a stream ended, as the `_tag` of its {@link MailboxEventStreamError}. The first nine are the
46
+ * API error tags the events host refuses with, or that a close code stands for. The rest are the
47
+ * client's own: `StreamDisconnectedError` is a close or an unreachable host that was not retried
48
+ * because `reconnect` is `false`, `StreamClientError` is a request this client could not make,
49
+ * `StreamProtocolError` is a frame from the host it could not read, and `StreamRefusedError` is a refusal whose tag and status this client
50
+ * does not know (`serverTag` carries the tag the host sent).
51
+ */
52
+ export type MailboxEventStreamErrorTag = "UnauthorizedError" | "ForbiddenError" | "ResourceNotFoundError" | "CursorExpiredError" | "ValidationError" | "UpgradeRequiredError" | "RateLimitedError" | "ServiceUnavailableError" | "MethodNotAllowedError" | "StreamDisconnectedError" | "StreamClientError" | "StreamProtocolError" | "StreamRefusedError";
53
+ /** Field-level validation messages, keyed by dotted path, as a `ValidationError` carries them. */
54
+ export type MailboxEventStreamErrorFields = Readonly<Record<string, ReadonlyArray<string>>>;
55
+ /**
56
+ * A stream that ended. `_tag` names the cause and `message` says what to do next, as the host
57
+ * wrote it when the host refused. Branch on `_tag`; in the Effect client the stream fails with
58
+ * {@link MailboxEventStreamFailure}, which `Effect.catchTag` narrows by `_tag`.
59
+ *
60
+ * The stream retries by itself only where retrying can help: a transient close, an unreachable
61
+ * host, a `408`, a `429`, or a `5xx`. Every other refusal ends it, so a caller never loops on a
62
+ * request the host will keep refusing.
63
+ */
64
+ export declare class MailboxEventStreamError<Tag extends MailboxEventStreamErrorTag = MailboxEventStreamErrorTag> extends Error {
65
+ readonly name = "MailboxEventStreamError";
66
+ readonly _tag: Tag;
67
+ /** The HTTP status, when the host refused the connection before accepting it. */
68
+ readonly status: number | undefined;
69
+ /** The WebSocket close code, when the host closed an accepted connection. */
70
+ readonly closeCode: number | undefined;
71
+ /** The last handled cursor; reconnect with it unless `_tag` is `CursorExpiredError`. */
72
+ readonly cursor: string | undefined;
73
+ /** A `ValidationError`'s field messages, such as `fields.cursor` or `fields.mailboxId`. */
74
+ readonly fields: MailboxEventStreamErrorFields | undefined;
75
+ /** How long a `RateLimitedError` or `ServiceUnavailableError` asked the caller to wait. */
76
+ readonly retryAfterSeconds: number | undefined;
77
+ /** The tag the host sent, when it is not one this client maps. */
78
+ readonly serverTag: string | undefined;
79
+ constructor(input: {
80
+ readonly _tag: Tag;
81
+ readonly message: string;
82
+ readonly status?: number | undefined;
83
+ readonly closeCode?: number | undefined;
84
+ readonly cursor?: string | undefined;
85
+ readonly fields?: MailboxEventStreamErrorFields | undefined;
86
+ readonly retryAfterSeconds?: number | undefined;
87
+ readonly serverTag?: string | undefined;
88
+ });
89
+ }
90
+ /** Every stream error as a union over `_tag`, so `Effect.catchTag` can narrow it. */
91
+ export type MailboxEventStreamFailure = {
92
+ [Tag in MailboxEventStreamErrorTag]: MailboxEventStreamError<Tag>;
93
+ }[MailboxEventStreamErrorTag];
94
+ /** The subset of the WebSocket API the stream uses. */
95
+ export interface MailboxEventStreamSocket {
96
+ readonly readyState: number;
97
+ send(data: string): void;
98
+ close(code?: number, reason?: string): void;
99
+ addEventListener(type: "open", listener: () => void): void;
100
+ addEventListener(type: "message", listener: (event: {
101
+ readonly data: unknown;
102
+ }) => void): void;
103
+ addEventListener(type: "error", listener: () => void): void;
104
+ addEventListener(type: "close", listener: (event: {
105
+ readonly code: number;
106
+ readonly reason: string;
107
+ }) => void): void;
108
+ }
109
+ /**
110
+ * A WebSocket constructor that accepts request headers, as Node's, Bun's, and the `ws` package's
111
+ * do. The stream authenticates the upgrade with the client's credential headers.
112
+ */
113
+ export type MailboxEventStreamWebSocket = new (url: string, options: {
114
+ readonly headers: Readonly<Record<string, string>>;
115
+ }) => MailboxEventStreamSocket;
116
+ export interface MailboxEventStreamOptions {
117
+ /** Resume after this cursor: every retained event after it, then live. Omit to start live. */
118
+ readonly cursor?: string | undefined;
119
+ /** Only these mailboxes, within what the credential can read. Omit for every readable one. */
120
+ readonly mailboxIds?: ReadonlyArray<string> | undefined;
121
+ /** Ends the stream, as {@link MailboxEventStream.close} does. */
122
+ readonly signal?: AbortSignal | undefined;
123
+ /** Called each time replay has caught up and the stream is delivering live events. */
124
+ readonly onLive?: (() => void) | undefined;
125
+ /** Reconnect after transient closes. Defaults to `true`. */
126
+ readonly reconnect?: boolean | undefined;
127
+ /**
128
+ * The events origin, such as `wss://events.samva.dev`. Defaults to the API origin with its
129
+ * `api` host label replaced by `events`.
130
+ */
131
+ readonly eventsUrl?: string | undefined;
132
+ /** Defaults to the runtime's global `WebSocket`. */
133
+ readonly WebSocket?: MailboxEventStreamWebSocket | undefined;
134
+ }
135
+ /** What the stream needs from a configured client. */
136
+ export interface MailboxEventStreamConnection {
137
+ readonly baseUrl: string;
138
+ /** The credential and attribution headers every request of the client carries. */
139
+ readonly headers: Readonly<Record<string, string>>;
140
+ readonly fetch?: typeof fetch | undefined;
141
+ }
142
+ /** The frame that asks the events host whether the connection is alive; pinned to the host's by a test. */
143
+ export declare const MAILBOX_EVENT_STREAM_PING_FRAME = "{\"kind\":\"ping\"}";
144
+ /** How often the stream sends a ping; pinned to the host's constant by a test. */
145
+ export declare const MAILBOX_EVENT_STREAM_PING_MILLIS = 30000;
146
+ /**
147
+ * How long a connection may stay silent before it is treated as dropped: three ping intervals, so
148
+ * one late or lost pong does not reconnect. The host sends nothing on a quiet mailbox, so the
149
+ * pong is the only proof of life; a socket that died without a close event is otherwise
150
+ * indistinguishable from a quiet mailbox.
151
+ */
152
+ export declare const MAILBOX_EVENT_STREAM_IDLE_MILLIS: number;
153
+ /** The events URL for an API origin: `https://api.samva.dev` → `wss://events.samva.dev/v1/…`. */
154
+ export declare const mailboxEventsUrl: (connection: Pick<MailboxEventStreamConnection, "baseUrl">, options: Pick<MailboxEventStreamOptions, "eventsUrl" | "cursor" | "mailboxIds">) => URL;
155
+ /**
156
+ * A resumable stream of mailbox events. Iterate it with `for await`; break out of the loop or call
157
+ * {@link close} to end it.
158
+ */
159
+ export declare class MailboxEventStream implements AsyncIterable<MailboxEvent> {
160
+ #private;
161
+ constructor(connection: MailboxEventStreamConnection, options?: MailboxEventStreamOptions);
162
+ /**
163
+ * The position to resume from: the last handled event's cursor, or a later position the
164
+ * server confirmed with nothing in between for this stream. Undefined until there is one.
165
+ */
166
+ get cursor(): string | undefined;
167
+ /**
168
+ * Mark the event in hand handled now, before asking for the next one: for a caller that stops
169
+ * after handling it, so {@link close} acknowledges it and {@link cursor} moves past it.
170
+ */
171
+ markHandled(): void;
172
+ /**
173
+ * End the stream. Handled events are acknowledged; the event in hand is not, unless
174
+ * {@link markHandled} was called, so a resume repeats it. A pending iteration finishes.
175
+ */
176
+ close(): void;
177
+ [Symbol.asyncIterator](): AsyncIterator<MailboxEvent>;
178
+ }
@@ -0,0 +1,147 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
+ import { n as MailboxEventStreamError, t as MailboxEventStream } from "./mailbox-events-CsbF35vH.js";
3
+ import { n as make } from "./operation-BEghYyLu.js";
4
+ import { t as Service } from "./client-Cj1bqIEe.js";
5
+ import { Cause, Effect, Exit, Stream } from "effect";
6
+ //#region src/effect/internal/mailbox-events.ts
7
+ const toStreamError = (cause) => cause instanceof MailboxEventStreamError ? cause : new MailboxEventStreamError({
8
+ _tag: "StreamDisconnectedError",
9
+ message: String(cause)
10
+ });
11
+ /**
12
+ * The organization's mailbox events as a stream, resuming from `cursor`. An event counts as handled
13
+ * once the stream is pulled again, or once it ends successfully after the event (as `Stream.take`
14
+ * does); a failure or interruption leaves the event in hand unacknowledged, so a resume repeats it.
15
+ * The stream fails with a {@link MailboxEventStreamFailure}, which `Effect.catchTag` narrows by the
16
+ * `_tag` of the host's refusal.
17
+ */
18
+ const events = (options = {}) => Stream.scoped(Stream.unwrap(Effect.gen(function* () {
19
+ const client = yield* Service;
20
+ const iterator = (yield* Effect.acquireRelease(Effect.try({
21
+ try: () => new MailboxEventStream(client.connection, options),
22
+ catch: toStreamError
23
+ }), (opened, exit) => Effect.sync(() => {
24
+ if (Exit.isSuccess(exit)) opened.markHandled();
25
+ opened.close();
26
+ })))[Symbol.asyncIterator]();
27
+ return Stream.fromEffectRepeat(Effect.tryPromise({
28
+ try: () => iterator.next(),
29
+ catch: toStreamError
30
+ }).pipe(Effect.flatMap((next) => next.done ? Cause.done() : Effect.succeed(next.value))));
31
+ })));
32
+ //#endregion
33
+ //#region src/effect/mailboxes.ts
34
+ var mailboxes_exports = /* @__PURE__ */ __exportAll({
35
+ MailboxEventStreamError: () => MailboxEventStreamError,
36
+ addThreadLabels: () => addThreadLabels,
37
+ approveAction: () => approveAction,
38
+ create: () => create,
39
+ createDraft: () => createDraft,
40
+ createGrant: () => createGrant,
41
+ createLabel: () => createLabel,
42
+ createNote: () => createNote,
43
+ createPolicy: () => createPolicy,
44
+ deleteDraft: () => deleteDraft,
45
+ deleteLabel: () => deleteLabel,
46
+ deleteNote: () => deleteNote,
47
+ deletePolicy: () => deletePolicy,
48
+ denyAction: () => denyAction,
49
+ discardMessage: () => discardMessage,
50
+ events: () => events,
51
+ forward: () => forward,
52
+ get: () => get,
53
+ getAgentActivity: () => getAgentActivity,
54
+ getDraft: () => getDraft,
55
+ getMessage: () => getMessage,
56
+ getMessageAttachment: () => getMessageAttachment,
57
+ getMessageRaw: () => getMessageRaw,
58
+ getPolicy: () => getPolicy,
59
+ getThread: () => getThread,
60
+ getThreadContent: () => getThreadContent,
61
+ list: () => list,
62
+ listActions: () => listActions,
63
+ listDrafts: () => listDrafts,
64
+ listEvents: () => listEvents,
65
+ listFolders: () => listFolders,
66
+ listGrants: () => listGrants,
67
+ listLabels: () => listLabels,
68
+ listPolicies: () => listPolicies,
69
+ listQuarantine: () => listQuarantine,
70
+ listThreadMessages: () => listThreadMessages,
71
+ listThreadNotes: () => listThreadNotes,
72
+ listThreads: () => listThreads,
73
+ pause: () => pause,
74
+ releaseMessage: () => releaseMessage,
75
+ remove: () => remove,
76
+ removeThreadLabels: () => removeThreadLabels,
77
+ reply: () => reply,
78
+ replyAll: () => replyAll,
79
+ resume: () => resume,
80
+ revokeGrant: () => revokeGrant,
81
+ sendDraft: () => sendDraft,
82
+ sendMessage: () => sendMessage,
83
+ update: () => update,
84
+ updateDraft: () => updateDraft,
85
+ updateGrant: () => updateGrant,
86
+ updateLabel: () => updateLabel,
87
+ updateNote: () => updateNote,
88
+ updatePolicy: () => updatePolicy,
89
+ updateThread: () => updateThread
90
+ });
91
+ const list = make("mailboxesList");
92
+ const create = make("mailboxesCreate");
93
+ const get = make("mailboxesGet");
94
+ const update = make("mailboxesUpdate");
95
+ const remove = make("mailboxesRemove");
96
+ const pause = make("mailboxesPause");
97
+ const resume = make("mailboxesResume");
98
+ const getAgentActivity = make("mailboxesGetAgentActivity");
99
+ const listGrants = make("mailboxesListGrants");
100
+ const createGrant = make("mailboxesCreateGrant");
101
+ const updateGrant = make("mailboxesUpdateGrant");
102
+ const revokeGrant = make("mailboxesRevokeGrant");
103
+ const listPolicies = make("mailboxesListPolicies");
104
+ const createPolicy = make("mailboxesCreatePolicy");
105
+ const getPolicy = make("mailboxesGetPolicy");
106
+ const updatePolicy = make("mailboxesUpdatePolicy");
107
+ const deletePolicy = make("mailboxesDeletePolicy");
108
+ const listFolders = make("mailboxesListFolders");
109
+ const listLabels = make("mailboxesListLabels");
110
+ const createLabel = make("mailboxesCreateLabel");
111
+ const updateLabel = make("mailboxesUpdateLabel");
112
+ const deleteLabel = make("mailboxesDeleteLabel");
113
+ const listThreads = make("mailboxesListThreads");
114
+ const getThread = make("mailboxesGetThread");
115
+ const updateThread = make("mailboxesUpdateThread");
116
+ const addThreadLabels = make("mailboxesAddThreadLabels");
117
+ const removeThreadLabels = make("mailboxesRemoveThreadLabels");
118
+ const listThreadMessages = make("mailboxesListThreadMessages");
119
+ const getThreadContent = make("mailboxesGetThreadContent");
120
+ const listThreadNotes = make("mailboxesListThreadNotes");
121
+ const createNote = make("mailboxesCreateNote");
122
+ const updateNote = make("mailboxesUpdateNote");
123
+ const deleteNote = make("mailboxesDeleteNote");
124
+ const sendMessage = make("mailboxesSendMessage");
125
+ const getMessage = make("mailboxesGetMessage");
126
+ const getMessageRaw = make("mailboxesGetMessageRaw");
127
+ const getMessageAttachment = make("mailboxesGetMessageAttachment");
128
+ const reply = make("mailboxesReply");
129
+ const replyAll = make("mailboxesReplyAll");
130
+ const forward = make("mailboxesForward");
131
+ const listQuarantine = make("mailboxesListQuarantine");
132
+ const releaseMessage = make("mailboxesReleaseMessage");
133
+ const discardMessage = make("mailboxesDiscardMessage");
134
+ const listDrafts = make("mailboxesListDrafts");
135
+ const createDraft = make("mailboxesCreateDraft");
136
+ const getDraft = make("mailboxesGetDraft");
137
+ const updateDraft = make("mailboxesUpdateDraft");
138
+ const deleteDraft = make("mailboxesDeleteDraft");
139
+ const sendDraft = make("mailboxesSendDraft");
140
+ const listActions = make("mailboxesListActions");
141
+ const approveAction = make("mailboxesApproveAction");
142
+ const denyAction = make("mailboxesDenyAction");
143
+ const listEvents = make("mailboxesListEvents");
144
+ //#endregion
145
+ export { updatePolicy as $, listGrants as A, remove as B, getThread as C, listDrafts as D, listActions as E, listThreadNotes as F, revokeGrant as G, reply as H, listThreads as I, update as J, sendDraft as K, mailboxes_exports as L, listPolicies as M, listQuarantine as N, listEvents as O, listThreadMessages as P, updateNote as Q, pause as R, getPolicy as S, list as T, replyAll as U, removeThreadLabels as V, resume as W, updateGrant as X, updateDraft as Y, updateLabel as Z, getAgentActivity as _, createGrant as a, getMessageAttachment as b, createPolicy as c, deleteNote as d, updateThread as et, deletePolicy as f, get as g, forward as h, createDraft as i, listLabels as j, listFolders as k, deleteDraft as l, discardMessage as m, approveAction as n, createLabel as o, denyAction as p, sendMessage as q, create as r, createNote as s, addThreadLabels as t, events as tt, deleteLabel as u, getDraft as v, getThreadContent as w, getMessageRaw as x, getMessage as y, releaseMessage as z };
146
+
147
+ //# sourceMappingURL=mailboxes-BtcktcNB.js.map