movoice 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +302 -2
  3. package/dist/cjs/client.d.ts +49 -0
  4. package/dist/cjs/client.d.ts.map +1 -0
  5. package/dist/cjs/client.js +66 -0
  6. package/dist/cjs/client.js.map +1 -0
  7. package/dist/cjs/errors.d.ts +115 -0
  8. package/dist/cjs/errors.d.ts.map +1 -0
  9. package/dist/cjs/errors.js +252 -0
  10. package/dist/cjs/errors.js.map +1 -0
  11. package/dist/cjs/http.d.ts +99 -0
  12. package/dist/cjs/http.d.ts.map +1 -0
  13. package/dist/cjs/http.js +281 -0
  14. package/dist/cjs/http.js.map +1 -0
  15. package/dist/cjs/index.d.ts +15 -0
  16. package/dist/cjs/index.d.ts.map +1 -0
  17. package/dist/cjs/index.js +32 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/package.json +1 -0
  20. package/dist/cjs/pagination.d.ts +67 -0
  21. package/dist/cjs/pagination.d.ts.map +1 -0
  22. package/dist/cjs/pagination.js +111 -0
  23. package/dist/cjs/pagination.js.map +1 -0
  24. package/dist/cjs/resources/account.d.ts +23 -0
  25. package/dist/cjs/resources/account.d.ts.map +1 -0
  26. package/dist/cjs/resources/account.js +29 -0
  27. package/dist/cjs/resources/account.js.map +1 -0
  28. package/dist/cjs/resources/agents.d.ts +43 -0
  29. package/dist/cjs/resources/agents.d.ts.map +1 -0
  30. package/dist/cjs/resources/agents.js +73 -0
  31. package/dist/cjs/resources/agents.js.map +1 -0
  32. package/dist/cjs/resources/appointments.d.ts +42 -0
  33. package/dist/cjs/resources/appointments.d.ts.map +1 -0
  34. package/dist/cjs/resources/appointments.js +102 -0
  35. package/dist/cjs/resources/appointments.js.map +1 -0
  36. package/dist/cjs/resources/calls.d.ts +62 -0
  37. package/dist/cjs/resources/calls.d.ts.map +1 -0
  38. package/dist/cjs/resources/calls.js +91 -0
  39. package/dist/cjs/resources/calls.js.map +1 -0
  40. package/dist/cjs/resources/contacts.d.ts +26 -0
  41. package/dist/cjs/resources/contacts.d.ts.map +1 -0
  42. package/dist/cjs/resources/contacts.js +55 -0
  43. package/dist/cjs/resources/contacts.js.map +1 -0
  44. package/dist/cjs/resources/memory.d.ts +27 -0
  45. package/dist/cjs/resources/memory.d.ts.map +1 -0
  46. package/dist/cjs/resources/memory.js +38 -0
  47. package/dist/cjs/resources/memory.js.map +1 -0
  48. package/dist/cjs/resources/messages.d.ts +35 -0
  49. package/dist/cjs/resources/messages.d.ts.map +1 -0
  50. package/dist/cjs/resources/messages.js +62 -0
  51. package/dist/cjs/resources/messages.js.map +1 -0
  52. package/dist/cjs/resources/numbers.d.ts +21 -0
  53. package/dist/cjs/resources/numbers.d.ts.map +1 -0
  54. package/dist/cjs/resources/numbers.js +37 -0
  55. package/dist/cjs/resources/numbers.js.map +1 -0
  56. package/dist/cjs/types.d.ts +519 -0
  57. package/dist/cjs/types.d.ts.map +1 -0
  58. package/dist/cjs/types.js +18 -0
  59. package/dist/cjs/types.js.map +1 -0
  60. package/dist/cjs/webhooks.d.ts +92 -0
  61. package/dist/cjs/webhooks.d.ts.map +1 -0
  62. package/dist/cjs/webhooks.js +129 -0
  63. package/dist/cjs/webhooks.js.map +1 -0
  64. package/dist/esm/client.d.ts +49 -0
  65. package/dist/esm/client.d.ts.map +1 -0
  66. package/dist/esm/client.js +62 -0
  67. package/dist/esm/client.js.map +1 -0
  68. package/dist/esm/errors.d.ts +115 -0
  69. package/dist/esm/errors.d.ts.map +1 -0
  70. package/dist/esm/errors.js +237 -0
  71. package/dist/esm/errors.js.map +1 -0
  72. package/dist/esm/http.d.ts +99 -0
  73. package/dist/esm/http.d.ts.map +1 -0
  74. package/dist/esm/http.js +277 -0
  75. package/dist/esm/http.js.map +1 -0
  76. package/dist/esm/index.d.ts +15 -0
  77. package/dist/esm/index.d.ts.map +1 -0
  78. package/dist/esm/index.js +11 -0
  79. package/dist/esm/index.js.map +1 -0
  80. package/dist/esm/package.json +1 -0
  81. package/dist/esm/pagination.d.ts +67 -0
  82. package/dist/esm/pagination.d.ts.map +1 -0
  83. package/dist/esm/pagination.js +106 -0
  84. package/dist/esm/pagination.js.map +1 -0
  85. package/dist/esm/resources/account.d.ts +23 -0
  86. package/dist/esm/resources/account.d.ts.map +1 -0
  87. package/dist/esm/resources/account.js +25 -0
  88. package/dist/esm/resources/account.js.map +1 -0
  89. package/dist/esm/resources/agents.d.ts +43 -0
  90. package/dist/esm/resources/agents.d.ts.map +1 -0
  91. package/dist/esm/resources/agents.js +69 -0
  92. package/dist/esm/resources/agents.js.map +1 -0
  93. package/dist/esm/resources/appointments.d.ts +42 -0
  94. package/dist/esm/resources/appointments.d.ts.map +1 -0
  95. package/dist/esm/resources/appointments.js +97 -0
  96. package/dist/esm/resources/appointments.js.map +1 -0
  97. package/dist/esm/resources/calls.d.ts +62 -0
  98. package/dist/esm/resources/calls.d.ts.map +1 -0
  99. package/dist/esm/resources/calls.js +87 -0
  100. package/dist/esm/resources/calls.js.map +1 -0
  101. package/dist/esm/resources/contacts.d.ts +26 -0
  102. package/dist/esm/resources/contacts.d.ts.map +1 -0
  103. package/dist/esm/resources/contacts.js +51 -0
  104. package/dist/esm/resources/contacts.js.map +1 -0
  105. package/dist/esm/resources/memory.d.ts +27 -0
  106. package/dist/esm/resources/memory.d.ts.map +1 -0
  107. package/dist/esm/resources/memory.js +34 -0
  108. package/dist/esm/resources/memory.js.map +1 -0
  109. package/dist/esm/resources/messages.d.ts +35 -0
  110. package/dist/esm/resources/messages.d.ts.map +1 -0
  111. package/dist/esm/resources/messages.js +58 -0
  112. package/dist/esm/resources/messages.js.map +1 -0
  113. package/dist/esm/resources/numbers.d.ts +21 -0
  114. package/dist/esm/resources/numbers.d.ts.map +1 -0
  115. package/dist/esm/resources/numbers.js +33 -0
  116. package/dist/esm/resources/numbers.js.map +1 -0
  117. package/dist/esm/types.d.ts +519 -0
  118. package/dist/esm/types.d.ts.map +1 -0
  119. package/dist/esm/types.js +17 -0
  120. package/dist/esm/types.js.map +1 -0
  121. package/dist/esm/webhooks.d.ts +92 -0
  122. package/dist/esm/webhooks.d.ts.map +1 -0
  123. package/dist/esm/webhooks.js +124 -0
  124. package/dist/esm/webhooks.js.map +1 -0
  125. package/package.json +64 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Movoice AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,303 @@
1
- # Temporary Holding Version
1
+ # movoice
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The official TypeScript client for the [Movoice AI](https://movoice.ai) API: voice agents,
4
+ calls, contacts, bookings, SMS, WhatsApp, and webhook verification.
5
+
6
+ Zero dependencies. Works on Node 18+, Bun, Deno, and edge runtimes. ESM and CommonJS.
7
+
8
+ ```bash
9
+ npm install movoice
10
+ ```
11
+
12
+ > **Rolling out:** the call-result fields `id`, `context_data` and `agent`, and giving an agent a phone number with `agents.update(id, { phoneNumber })`, arrive with the December 2026 Movoice release. Until then they are already on Movoice's testing server.
13
+
14
+ ## Call a lead from your CRM and get the result back
15
+
16
+ ```ts
17
+ import { Movoice, webhooks } from "movoice";
18
+
19
+ const mv = new Movoice({ apiKey: process.env.MOVOICE_API_KEY! });
20
+
21
+ // 1. Your CRM says "call this lead". contextData fills {name} in the agent's prompt and comes back on every event.
22
+ const call = await mv.calls.create(
23
+ { agentId: process.env.MOVOICE_AGENT_ID!, phoneNumber: "+14155550123", contextData: { leadId: "L-889", name: "Rahul" } },
24
+ { idempotencyKey: "call-L-889-1" }, // retry safely: the same key never dials twice
25
+ );
26
+ await crm.saveCallId("L-889", call.id);
27
+
28
+ // 2. Movoice posts call.completed to your webhook. Verify it, then match it back to the lead.
29
+ export async function POST(request: Request) {
30
+ const event = await webhooks.verify(await request.text(), request.headers, process.env.MOVOICE_WEBHOOK_SECRET!);
31
+ if (event.event === "call.completed") await crm.logCall(event.context_data?.leadId, event.summary, event.duration_seconds);
32
+ return new Response(null, { status: 200 });
33
+ }
34
+ ```
35
+
36
+ `call.id` is the call's Movoice id. Every webhook for that call carries it as `id`, plus the
37
+ `contextData` you sent as `context_data` and the agent as `agent.id`, so either one leads back to
38
+ the record in your CRM. `mv.calls.get(call.id)` reads the call (status, duration, `summary`,
39
+ transcript) whenever you want it instead.
40
+
41
+ ## Test keys and live keys
42
+
43
+ Create keys on the Developer page: https://app.movoice.ai/admin/developer
44
+
45
+ | Key | What it does |
46
+ | --- | --- |
47
+ | `mv_live_...` | The real thing. Calls dial and are charged; writes change your account. |
48
+ | `mv_test_...` | A sandbox. `calls.create` places a pretend call (`id` starts with `test_call_`, `livemode: false`) that dials nobody and costs nothing, and your webhook endpoints receive pretend `call.started` and `call.completed` events for it, carrying your `contextData`. Reads return sample data; writes answer with `livemode: false` and change nothing. |
49
+ | `mv_pk_...` | Publishable, for the chat widget in a browser. It cannot call this API, and the client refuses it at construction. |
50
+
51
+ Build and test the whole loop with a test key, then swap in the live key.
52
+
53
+ ## Server-side only
54
+
55
+ Keep your key on your server. There are no CORS headers on the API, so a browser request
56
+ fails preflight anyway — but the real reason is that a secret key can place calls and spend
57
+ your balance.
58
+
59
+ Publishable keys (`mv_pk_`) are for the chat widget and cannot call these endpoints. Passing
60
+ one throws immediately, rather than failing later with a 403.
61
+
62
+ ## Errors
63
+
64
+ Every failure throws. One class hierarchy, whatever shape the API replied with:
65
+
66
+ ```ts
67
+ import { InsufficientBalanceError, RateLimitError, MovoiceError } from "movoice";
68
+
69
+ try {
70
+ await mv.calls.create({ agentId, phoneNumber });
71
+ } catch (err) {
72
+ if (err instanceof InsufficientBalanceError) return topUpWallet();
73
+ if (err instanceof RateLimitError) return retryAfter(err.retryAfter);
74
+ if (err instanceof MovoiceError) console.error(err.code, err.message, err.status);
75
+ throw err;
76
+ }
77
+ ```
78
+
79
+ | Class | When |
80
+ | --- | --- |
81
+ | `AuthenticationError` | 401 — key missing, expired, or unknown |
82
+ | `PermissionError` | 403 — key lacks the scope. `err.requiredScopes` lists what it needed |
83
+ | `InvalidRequestError` | 400 / 422. `err.fieldErrors` has per-field messages |
84
+ | `NotFoundError` | 404 — also returned for another account's ids |
85
+ | `InsufficientBalanceError` | 402 — plan allowance and wallet both empty |
86
+ | `RateLimitError` | 429. `err.retryAfter` in seconds, when the API sent one |
87
+ | `ApiError` | 5xx |
88
+ | `ConnectionError` | never reached the server, or timed out |
89
+
90
+ `err.code` is normalised to upper case, so `forbidden` and `FORBIDDEN` both arrive as
91
+ `"FORBIDDEN"`. The API's own value is on `err.rawCode`, and the parsed body on `err.body`.
92
+
93
+ ## Paging
94
+
95
+ ```ts
96
+ const page = await mv.calls.list({ perPage: 50, agentId });
97
+ page.data; // Call[]
98
+ page.hasMore;
99
+ page.total; // may be undefined — see below
100
+
101
+ const next = await page.next(); // Page<Call> | null
102
+ ```
103
+
104
+ Or walk everything:
105
+
106
+ ```ts
107
+ for await (const call of mv.calls.listAll({ agentId })) {
108
+ console.log(call.id, call.status);
109
+ }
110
+ ```
111
+
112
+ `next()` follows a cursor where the endpoint offers one and increments the page number
113
+ where it does not, so the same loop is correct everywhere. On `/calls`, prefer it: a cursor
114
+ page costs the same however many calls you have, while deep page numbers are capped and
115
+ eventually rejected.
116
+
117
+ `total` and `totalPages` are **absent** when the result set is too large to count. Do not
118
+ build a page-count UI that requires them.
119
+
120
+ ## Retries and idempotency
121
+
122
+ Retried automatically: `429` on any method, and `5xx` or network faults **on GET**.
123
+
124
+ A `POST` or `PATCH` that failed with a `5xx` or timed out is **not** retried on its own: a `500`
125
+ does not tell you whether the work happened first, and retrying `calls.create` would place a
126
+ second call and bill you twice.
127
+
128
+ Unless you give it an idempotency key. `calls.create`, `agents.create`, `agents.update`,
129
+ `appointments.create`, `appointments.cancel` and `appointments.reschedule` accept one, sent as the
130
+ `Idempotency-Key` header:
131
+
132
+ ```ts
133
+ await mv.calls.create({ agentId, phoneNumber }, { idempotencyKey: `call-${leadId}-${attempt}` });
134
+ ```
135
+
136
+ The server keeps the first answer under that key (per API key) and hands it back for any repeat
137
+ instead of acting again, so with a key the SDK does retry a timeout or a `5xx`, and so can you,
138
+ for as long as you like. Use one key per thing you mean to happen once; reusing a key with a
139
+ different body is refused (`422`), and a repeat that arrives while the first is still running gets
140
+ `ConflictError` (`409`): wait a moment and repeat it again to get the first answer. Keys are 8 to
141
+ 255 characters. Passing a key to a method that does not accept one throws before sending, rather
142
+ than looking like protection it is not.
143
+
144
+ Tune with `new Movoice({ apiKey, maxRetries: 0 })`, or set `timeout` (default 30s) per
145
+ client or per request.
146
+
147
+ ## Webhooks
148
+
149
+ Add an endpoint on the Developer page and copy its signing secret (it starts with `whsec_`).
150
+ Every delivery is signed:
151
+
152
+ ```
153
+ X-Movoice-Timestamp: <unix seconds>
154
+ X-Movoice-Signature: sha256=<hex HMAC-SHA256 of "<timestamp>.<raw body>", keyed with the whole whsec_ secret>
155
+ X-Movoice-Event: call.completed
156
+ X-Movoice-Delivery: <event_id>
157
+ ```
158
+
159
+ `webhooks.verify(rawBody, headers, secret)` checks the signature (constant-time) and that the
160
+ timestamp is within 5 minutes of now, then returns the parsed event. Anything else throws
161
+ `WebhookVerificationError`: answer it with a 400.
162
+
163
+ ```ts
164
+ // Express: keep the body raw, or the signature cannot match.
165
+ app.post("/movoice-webhook", express.raw({ type: "application/json" }), async (req, res) => {
166
+ try {
167
+ const event = await webhooks.verify(req.body, req.headers, process.env.MOVOICE_WEBHOOK_SECRET!);
168
+ if (seen.has(event.event_id)) return res.sendStatus(200); // a retry carries the same event_id
169
+ seen.add(event.event_id);
170
+ // event.id, event.context_data, event.summary, event.transcript ...
171
+ res.sendStatus(200);
172
+ } catch {
173
+ res.sendStatus(400);
174
+ }
175
+ });
176
+ ```
177
+
178
+ `headers` may be a Fetch `Headers` or a plain object such as Node's `req.headers`; `rawBody` a
179
+ string or bytes (a `Buffer`). It needs no API key, so `import { webhooks } from "movoice"` works
180
+ on a receiver that has none; `mv.webhooks` is the same thing. Events: `call.started`,
181
+ `call.completed`, `call.failed`, `call.missed`. Answer quickly with a 2xx: a failed delivery is
182
+ retried with the same `event_id`.
183
+
184
+ ## Sending messages
185
+
186
+ ```ts
187
+ await mv.messages.send({ to: "+14155550123", body: "Your appointment is confirmed." });
188
+ await mv.messages.sendWhatsApp({ to: "+14155550123", body: "Your appointment is confirmed." });
189
+ ```
190
+
191
+ Both spend your balance and are capped at 500 messages per key per 24 hours.
192
+
193
+ The response field `status` is always the string `"sent"` and means nothing. The honest
194
+ signal is `providerMessageId`, and the SDK throws (`code: "NOT_SENT"`) when a nominally
195
+ successful response carries no carrier id — so a message that did not go out cannot look
196
+ like one that did.
197
+
198
+ A recipient who replied STOP is suppressed on **every** channel, not just the one the STOP
199
+ arrived on. That throws `InvalidRequestError` with the reason. Meta's WhatsApp rules
200
+ (approved templates, the 24-hour window) are enforced by Meta at delivery, not before
201
+ sending.
202
+
203
+ ## Caller memory
204
+
205
+ The one endpoint that answers with a bare object and reports "nothing found" as a 200.
206
+ Branch on `found`, never on catching an error:
207
+
208
+ ```ts
209
+ const memory = await mv.memory.recall({ agentId, phone: "+14155550123" });
210
+
211
+ if (memory.found) {
212
+ console.log(memory.data.total_calls, memory.data.facts);
213
+ } else {
214
+ console.log(memory.message); // no memory yet, memory disabled, or unknown caller
215
+ }
216
+ ```
217
+
218
+ `data.last_call_date` is a display string in `en-IN` (`"14/3/2026"`), not a timestamp.
219
+
220
+ ## Your account
221
+
222
+ ```ts
223
+ const account = await mv.account.get();
224
+ account.accountNumber; // "72601815914" -- your Movoice Account ID
225
+ account.creditBalanceUsdCents; // US cents, whatever currency you pay in
226
+ ```
227
+
228
+ `accountNumber` is the number to quote when you contact support. Any secret key can read
229
+ the account unless its only scope is Widget (`widget:access`); publishable keys (`mv_pk_`)
230
+ cannot either, because both are meant for public web pages. `maxCallsPerMonth` is the plan's limit, not a usage
231
+ count. Unlike most responses, absent fields here are `null` rather than omitted.
232
+
233
+ ## Hang up a call
234
+
235
+ ```ts
236
+ await mv.calls.hangup(call.id); // the network is asked to end it; call.completed follows
237
+ ```
238
+
239
+ ## Give an agent a phone number
240
+
241
+ ```ts
242
+ await mv.agents.update(agentId, { phoneNumber: "+14155550123" }); // or the number's id from numbers.list()
243
+ ```
244
+
245
+ The agent then answers that number, as when you pick it in the dashboard. A number not on your
246
+ account throws `NotFoundError`; one another agent answers throws `ConflictError`.
247
+
248
+ ## Contacts
249
+
250
+ ```ts
251
+ const [existing] = await mv.contacts.list({ search: "+14155550123" });
252
+ const contact = existing ?? (await mv.contacts.create({ name: "Rahul", phone: "+14155550123", tags: ["crm"] }));
253
+ await mv.contacts.update(contact.id, { notes: "Wants a callback on Thursday" });
254
+ await mv.contacts.delete(contact.id);
255
+ ```
256
+
257
+ `list` returns up to `perPage` (max 100) contacts, newest first, with no paging: narrow it with
258
+ `search`. A second contact with the same phone throws `ConflictError`.
259
+
260
+ ## Appointments and availability
261
+
262
+ ```ts
263
+ const { slots } = await mv.availability.get({ agentId, date: "2026-12-01", timezone: "Asia/Kolkata" });
264
+ const booking = await mv.appointments.create(
265
+ { agentId, customerName: "Rahul", customerPhone: "+919845000001", date: "2026-12-01", time: slots[0]! },
266
+ { idempotencyKey: "book-L-889" },
267
+ );
268
+ await mv.appointments.reschedule(booking.id, { date: "2026-12-02", time: "11:00" });
269
+ await mv.appointments.cancel(booking.id, { tellCustomer: true });
270
+
271
+ for await (const a of mv.appointments.listAll({ from: "2026-12-01", to: "2026-12-31" })) console.log(a.date, a.time);
272
+ ```
273
+
274
+ A time that was just taken throws `ConflictError` whose message lists the free times that day.
275
+
276
+ ## Conventions
277
+
278
+ - Every timestamp is **epoch milliseconds**.
279
+ - `call.duration` is **seconds**.
280
+ - Optional fields are **omitted**, not null, except on phone numbers, contacts, appointments and
281
+ the account, where they are null.
282
+ - A null `assignedAgentId` on a phone number does not mean it is unrouted — it can be
283
+ answered by an agent group or sent to the dialer.
284
+
285
+ ## Escape hatch
286
+
287
+ For anything this version does not wrap yet:
288
+
289
+ ```ts
290
+ const data = await mv.http.request({ method: "GET", path: "/some/new/endpoint" });
291
+ ```
292
+
293
+ Paths are relative to `/api/v1`. Auth, retries, error handling and envelope unwrapping all
294
+ still apply.
295
+
296
+ ## Reference
297
+
298
+ Docs: https://docs.movoice.ai. The machine-readable spec lives at
299
+ [`/api/v1/openapi.json`](https://app.movoice.ai/api/v1/openapi.json).
300
+
301
+ ## Licence
302
+
303
+ MIT
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The Movoice client.
3
+ *
4
+ * import { Movoice } from "movoice";
5
+ *
6
+ * const mv = new Movoice({ apiKey: process.env.MOVOICE_API_KEY! });
7
+ * const call = await mv.calls.create({ agentId, phoneNumber: "+14155550123" });
8
+ *
9
+ * Server-side only. There are no CORS headers on the API, so a browser request fails
10
+ * preflight — and a secret key in browser code can place calls and spend your balance.
11
+ *
12
+ * @module client
13
+ */
14
+ import { HttpClient, type ClientOptions } from "./http.js";
15
+ import { AccountResource } from "./resources/account.js";
16
+ import { Agents } from "./resources/agents.js";
17
+ import { Appointments, AvailabilityResource } from "./resources/appointments.js";
18
+ import { Calls } from "./resources/calls.js";
19
+ import { Contacts } from "./resources/contacts.js";
20
+ import { Memory } from "./resources/memory.js";
21
+ import { Messages } from "./resources/messages.js";
22
+ import { Numbers } from "./resources/numbers.js";
23
+ import { type Webhooks } from "./webhooks.js";
24
+ export declare class Movoice {
25
+ /** The voice agents that answer and place calls. */
26
+ readonly agents: Agents;
27
+ /** Place calls, hang them up, and read their history and transcripts. */
28
+ readonly calls: Calls;
29
+ /** Your address book. */
30
+ readonly contacts: Contacts;
31
+ /** Bookings on your agents' calendars. */
32
+ readonly appointments: Appointments;
33
+ /** Free times on an agent's calendar. */
34
+ readonly availability: AvailabilityResource;
35
+ /** The phone numbers on your account. Read only. */
36
+ readonly numbers: Numbers;
37
+ /** SMS and WhatsApp. These spend your balance. */
38
+ readonly messages: Messages;
39
+ /** What an agent remembers about a caller. */
40
+ readonly memory: Memory;
41
+ /** The account behind the key, including your Movoice Account ID. */
42
+ readonly account: AccountResource;
43
+ /** Verify a webhook delivery. Also importable on its own: `import { webhooks } from "movoice"`. */
44
+ readonly webhooks: Webhooks;
45
+ /** Escape hatch for endpoints this version does not wrap yet. */
46
+ readonly http: HttpClient;
47
+ constructor(options: ClientOptions | string);
48
+ }
49
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CA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_API_KEY! });
8
+ * const call = await mv.calls.create({ agentId, phoneNumber: "+14155550123" });
9
+ *
10
+ * Server-side only. There are no CORS headers on the API, so a browser request fails
11
+ * preflight — and a secret key in browser code can place calls and spend your balance.
12
+ *
13
+ * @module client
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.Movoice = void 0;
17
+ const http_js_1 = require("./http.js");
18
+ const account_js_1 = require("./resources/account.js");
19
+ const agents_js_1 = require("./resources/agents.js");
20
+ const appointments_js_1 = require("./resources/appointments.js");
21
+ const calls_js_1 = require("./resources/calls.js");
22
+ const contacts_js_1 = require("./resources/contacts.js");
23
+ const memory_js_1 = require("./resources/memory.js");
24
+ const messages_js_1 = require("./resources/messages.js");
25
+ const numbers_js_1 = require("./resources/numbers.js");
26
+ const webhooks_js_1 = require("./webhooks.js");
27
+ class Movoice {
28
+ /** The voice agents that answer and place calls. */
29
+ agents;
30
+ /** Place calls, hang them up, and read their history and transcripts. */
31
+ calls;
32
+ /** Your address book. */
33
+ contacts;
34
+ /** Bookings on your agents' calendars. */
35
+ appointments;
36
+ /** Free times on an agent's calendar. */
37
+ availability;
38
+ /** The phone numbers on your account. Read only. */
39
+ numbers;
40
+ /** SMS and WhatsApp. These spend your balance. */
41
+ messages;
42
+ /** What an agent remembers about a caller. */
43
+ memory;
44
+ /** The account behind the key, including your Movoice Account ID. */
45
+ account;
46
+ /** Verify a webhook delivery. Also importable on its own: `import { webhooks } from "movoice"`. */
47
+ webhooks;
48
+ /** Escape hatch for endpoints this version does not wrap yet. */
49
+ http;
50
+ constructor(options) {
51
+ const opts = typeof options === "string" ? { apiKey: options } : options;
52
+ this.http = new http_js_1.HttpClient(opts);
53
+ this.agents = new agents_js_1.Agents(this.http);
54
+ this.calls = new calls_js_1.Calls(this.http);
55
+ this.contacts = new contacts_js_1.Contacts(this.http);
56
+ this.appointments = new appointments_js_1.Appointments(this.http);
57
+ this.availability = new appointments_js_1.AvailabilityResource(this.http);
58
+ this.numbers = new numbers_js_1.Numbers(this.http);
59
+ this.messages = new messages_js_1.Messages(this.http);
60
+ this.memory = new memory_js_1.Memory(this.http);
61
+ this.account = new account_js_1.AccountResource(this.http);
62
+ this.webhooks = webhooks_js_1.webhooks;
63
+ }
64
+ }
65
+ exports.Movoice = Movoice;
66
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,uCAA2D;AAC3D,uDAAyD;AACzD,qDAA+C;AAC/C,iEAAiF;AACjF,mDAA6C;AAC7C,yDAAmD;AACnD,qDAA+C;AAC/C,yDAAmD;AACnD,uDAAiD;AACjD,+CAAwD;AAExD,MAAa,OAAO;IAClB,oDAAoD;IAC3C,MAAM,CAAS;IACxB,yEAAyE;IAChE,KAAK,CAAQ;IACtB,yBAAyB;IAChB,QAAQ,CAAW;IAC5B,0CAA0C;IACjC,YAAY,CAAe;IACpC,yCAAyC;IAChC,YAAY,CAAuB;IAC5C,oDAAoD;IAC3C,OAAO,CAAU;IAC1B,kDAAkD;IACzC,QAAQ,CAAW;IAC5B,8CAA8C;IACrC,MAAM,CAAS;IACxB,qEAAqE;IAC5D,OAAO,CAAkB;IAClC,mGAAmG;IAC1F,QAAQ,CAAW;IAE5B,iEAAiE;IACxD,IAAI,CAAa;IAE1B,YAAY,OAA+B;QACzC,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACzE,IAAI,CAAC,IAAI,GAAG,IAAI,oBAAU,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,IAAI,gBAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,YAAY,GAAG,IAAI,8BAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,IAAI,sCAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxD,IAAI,CAAC,OAAO,GAAG,IAAI,oBAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,4BAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,GAAG,sBAAQ,CAAC;IAC3B,CAAC;CACF;AAvCD,0BAuCC"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * One error type, whatever the API actually sent.
3
+ *
4
+ * The API now answers every failure in one shape:
5
+ *
6
+ * { "success": false, "error": { "code": "NOT_FOUND", "message": "..." } }
7
+ *
8
+ * It did not always. Until the envelopes were unified there were four at once: this
9
+ * one, an auth variant with no `success` field and lowercase codes, and two where
10
+ * `error` was a bare string that was sometimes a reason code and sometimes an English
11
+ * sentence. This module still reads all of them, deliberately — a proxy or an older
12
+ * deployment can still produce the old shapes, and being tolerant on the way in costs
13
+ * nothing. What it emits is always the same: one class hierarchy, with `code`
14
+ * upper-cased so `forbidden` and `FORBIDDEN` both arrive as `"FORBIDDEN"`.
15
+ *
16
+ * The raw values are kept on `rawCode` and `body` for anyone who needs to see what
17
+ * really came back.
18
+ *
19
+ * @module errors
20
+ */
21
+ /** Every code the API can return, after normalisation. */
22
+ export type MovoiceErrorCode = "UNAUTHORIZED" | "INVALID_API_KEY" | "FORBIDDEN" | "INSUFFICIENT_PERMISSIONS" | "BAD_REQUEST" | "VALIDATION_ERROR" | "UNPROCESSABLE_ENTITY" | "NOT_FOUND" | "CONFLICT" | "PAYMENT_REQUIRED" | "RATE_LIMITED" | "INTERNAL_ERROR" | "SERVICE_UNAVAILABLE" | "SERVER_ERROR" | "CONNECTION_ERROR" | "TIMEOUT" | "INVALID_RESPONSE" | "NOT_SENT" | "WEBHOOK_SIGNATURE_INVALID" | (string & {});
23
+ export interface MovoiceErrorInit {
24
+ message: string;
25
+ code: MovoiceErrorCode;
26
+ /** HTTP status, or undefined when the request never got a response. */
27
+ status?: number;
28
+ /** The code exactly as the API sent it, before upper-casing. */
29
+ rawCode?: string;
30
+ details?: Record<string, unknown>;
31
+ /** The parsed response body, for debugging. */
32
+ body?: unknown;
33
+ cause?: unknown;
34
+ }
35
+ /**
36
+ * Base class for everything this library throws. Catch this to catch all of it.
37
+ *
38
+ * try { await mv.calls.create({ ... }); }
39
+ * catch (err) {
40
+ * if (err instanceof MovoiceError) console.error(err.code, err.message);
41
+ * }
42
+ */
43
+ export declare class MovoiceError extends Error {
44
+ readonly code: MovoiceErrorCode;
45
+ readonly status?: number;
46
+ readonly rawCode?: string;
47
+ readonly details?: Record<string, unknown>;
48
+ readonly body?: unknown;
49
+ constructor(init: MovoiceErrorInit);
50
+ /**
51
+ * True when retrying the identical request could plausibly succeed. Note this is
52
+ * about the error, not about the request: the SDK will not automatically retry a
53
+ * POST that may already have placed a call or sent a message, even when this is
54
+ * true. See `docs/retries` in the README.
55
+ */
56
+ get isRetryable(): boolean;
57
+ }
58
+ /** 401 — the key is missing, malformed, expired, or unknown. */
59
+ export declare class AuthenticationError extends MovoiceError {
60
+ }
61
+ /**
62
+ * 403 — the key is real but is not allowed to do this.
63
+ *
64
+ * Usually a missing scope: `details.required` lists the scopes the endpoint wanted.
65
+ * A legacy `mvai_` key lands here for everything except widget access.
66
+ */
67
+ export declare class PermissionError extends MovoiceError {
68
+ /** The scopes the endpoint required, when the API said. */
69
+ get requiredScopes(): string[] | undefined;
70
+ }
71
+ /** 400 / 422 — the request was understood and rejected. */
72
+ export declare class InvalidRequestError extends MovoiceError {
73
+ /**
74
+ * Per-field validation messages, when the failure was a schema validation.
75
+ * Shape is `{ phoneNumber: ["Invalid phone number"] }`.
76
+ */
77
+ get fieldErrors(): Record<string, string[]> | undefined;
78
+ }
79
+ /** 404 — no such agent or call on this account. Also returned for another account's ids. */
80
+ export declare class NotFoundError extends MovoiceError {
81
+ }
82
+ /** 409 — the request conflicts with the current state. */
83
+ export declare class ConflictError extends MovoiceError {
84
+ }
85
+ /** 402 — plan allowance and wallet are both empty. Top up, then retry. */
86
+ export declare class InsufficientBalanceError extends MovoiceError {
87
+ }
88
+ /** 429 — too many requests for this key. */
89
+ export declare class RateLimitError extends MovoiceError {
90
+ /** Seconds to wait, from the `Retry-After` header, when the API sent one. */
91
+ readonly retryAfter?: number;
92
+ constructor(init: MovoiceErrorInit & {
93
+ retryAfter?: number;
94
+ });
95
+ }
96
+ /** 5xx — the failure was on our side, not in your request. */
97
+ export declare class ApiError extends MovoiceError {
98
+ }
99
+ /**
100
+ * The request never completed: DNS, TLS, socket, timeout, or an aborted signal.
101
+ * Nothing was necessarily *not* done — a timeout can still have reached the server.
102
+ */
103
+ export declare class ConnectionError extends MovoiceError {
104
+ }
105
+ /** A response came back, but it was not the JSON envelope the API is supposed to send. */
106
+ export declare class InvalidResponseError extends MovoiceError {
107
+ }
108
+ /**
109
+ * Build the right error class from an HTTP response.
110
+ *
111
+ * The class is chosen by status first and code second, because status is the one
112
+ * thing both envelopes agree on.
113
+ */
114
+ export declare function errorFromResponse(status: number, body: unknown, headers?: Headers): MovoiceError;
115
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,0DAA0D;AAC1D,MAAM,MAAM,g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