fauna-api 1.0.692 → 1.0.694
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/dist/src/authentification.d.ts +2 -2
- package/dist/src/authentification.js +2 -2
- package/dist/src/cicada/inboxes.d.ts +7 -1
- package/dist/src/cicada/inboxes.js +2 -0
- package/dist/src/cicada/phone.d.ts +45 -0
- package/dist/src/cicada/phone.js +46 -0
- package/dist/src/groups.d.ts +27 -5
- package/dist/src/groups.js +45 -6
- package/dist/src/webhooks.d.ts +21 -2
- package/package.json +1 -1
|
@@ -67,9 +67,9 @@ export declare function revokeSession(credentials: Credentials, session: Session
|
|
|
67
67
|
export declare function signOut(credentials: Credentials): Promise<boolean>;
|
|
68
68
|
/** Ends every one of your sessions, this one too. */
|
|
69
69
|
export declare function signOutEverywhere(credentials: Credentials): Promise<boolean>;
|
|
70
|
-
/** A single use code
|
|
70
|
+
/** A single use code, good for a minute, that gives another page or app a new session of the same person, so no token rides in a URL. */
|
|
71
71
|
export declare function handoff(credentials: Credentials): Promise<string>;
|
|
72
|
-
/** Uses up a handoff code for the session token it
|
|
72
|
+
/** Uses up a handoff code for the new session token it carries. */
|
|
73
73
|
export declare function redeemHandoff(code: string): Promise<Token>;
|
|
74
74
|
export declare function allocateBalance(credentials: Credentials, target: ApiKey | Group, delta: number): Promise<true>;
|
|
75
75
|
export declare function generateApiKey(credentials: Credentials): Promise<ApiKey>;
|
|
@@ -216,7 +216,7 @@ export async function signOutEverywhere(credentials) {
|
|
|
216
216
|
}
|
|
217
217
|
return response.ok;
|
|
218
218
|
}
|
|
219
|
-
/** A single use code
|
|
219
|
+
/** A single use code, good for a minute, that gives another page or app a new session of the same person, so no token rides in a URL. */
|
|
220
220
|
export async function handoff(credentials) {
|
|
221
221
|
const response = await fetch(`${Fauna.getURL()}/authentification/handoff`, {
|
|
222
222
|
method: "POST",
|
|
@@ -229,7 +229,7 @@ export async function handoff(credentials) {
|
|
|
229
229
|
}
|
|
230
230
|
return String((await response.json()).code);
|
|
231
231
|
}
|
|
232
|
-
/** Uses up a handoff code for the session token it
|
|
232
|
+
/** Uses up a handoff code for the new session token it carries. */
|
|
233
233
|
export async function redeemHandoff(code) {
|
|
234
234
|
const response = await fetch(`${Fauna.getURL()}/authentification/handoff/redeem`, {
|
|
235
235
|
method: "POST",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Cicada } from "./index.js";
|
|
2
2
|
import { Platform } from "../integrations.js";
|
|
3
3
|
import { Credentials, ApiKey } from "../authentification.js";
|
|
4
|
-
import type { Text } from "../parrot/generative.js";
|
|
4
|
+
import type { Text, Voice } from "../parrot/generative.js";
|
|
5
5
|
export type InboxGroup = {
|
|
6
6
|
id: string;
|
|
7
7
|
name: string;
|
|
@@ -30,8 +30,12 @@ export declare function assign(authorization: Credentials | ApiKey, inboxId: str
|
|
|
30
30
|
}): Promise<void>;
|
|
31
31
|
export declare function listAccounts(authorization: Credentials | ApiKey, inboxId: string): Promise<InboxAccount[]>;
|
|
32
32
|
/** `dailyLimit` and `spentToday` are dollars per UTC day; at the limit the agent pauses until midnight UTC. */
|
|
33
|
+
/** `reasoning` is one of the text model's catalog tiers, empty for its default; `voiceModel`
|
|
34
|
+
* is the realtime voice the agent talks with on calls, empty for the catalog's first. */
|
|
33
35
|
export type AgentSettings = {
|
|
34
36
|
model: Text;
|
|
37
|
+
reasoning: string;
|
|
38
|
+
voiceModel: Voice | '';
|
|
35
39
|
instructions: string;
|
|
36
40
|
dailyLimit: number;
|
|
37
41
|
spentToday: number;
|
|
@@ -44,6 +48,8 @@ export declare function getAgent(authorization: Credentials | ApiKey, inbox: str
|
|
|
44
48
|
/** Turns the agent on (it answers messages sent from now on) or updates it. */
|
|
45
49
|
export declare function setAgent(authorization: Credentials | ApiKey, inbox: string, settings: {
|
|
46
50
|
model: Text;
|
|
51
|
+
reasoning?: string;
|
|
52
|
+
voiceModel?: Voice;
|
|
47
53
|
instructions: string;
|
|
48
54
|
dailyLimit: number;
|
|
49
55
|
}): Promise<AgentSettings>;
|
|
@@ -61,6 +61,8 @@ export const AgentSettings = {
|
|
|
61
61
|
fromJSON(json) {
|
|
62
62
|
return {
|
|
63
63
|
model: json.model,
|
|
64
|
+
reasoning: String(json.reasoning ?? ''),
|
|
65
|
+
voiceModel: String(json.voiceModel ?? ''),
|
|
64
66
|
instructions: String(json.instructions ?? ''),
|
|
65
67
|
dailyLimit: Number(json.dailyLimit ?? 0),
|
|
66
68
|
spentToday: Number(json.spentToday ?? 0),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Cicada } from "./index.js";
|
|
1
2
|
import { Credentials, ApiKey } from "../authentification.js";
|
|
2
3
|
import WebSocket from "isomorphic-ws";
|
|
3
4
|
export type CallEnd = {
|
|
@@ -46,3 +47,47 @@ export declare function listen(authorization: Credentials | ApiKey, inbox: strin
|
|
|
46
47
|
}>;
|
|
47
48
|
/** Calls `to` from one of the inbox's phone lines: `from`, or its first line. */
|
|
48
49
|
export declare function call(authorization: Credentials | ApiKey, inbox: string, to: string, from?: string): Promise<PhoneCall>;
|
|
50
|
+
/** Where in a recording something was said, in milliseconds from its start. */
|
|
51
|
+
export type CallSpan = {
|
|
52
|
+
startMs: number;
|
|
53
|
+
endMs: number;
|
|
54
|
+
};
|
|
55
|
+
/** One side speaking in a recorded call, each word timed. `You` is the inbox's side on a
|
|
56
|
+
* call a person took or placed; `Agent` is the inbox's agent. */
|
|
57
|
+
export type CallSegment = CallSpan & {
|
|
58
|
+
speaker: 'Them' | 'You' | 'Agent';
|
|
59
|
+
text: string;
|
|
60
|
+
words: CallSpan[];
|
|
61
|
+
};
|
|
62
|
+
/** A call on one of the inbox's lines, with its recording's timed transcript. */
|
|
63
|
+
export type CallRecord = {
|
|
64
|
+
id: string;
|
|
65
|
+
direction: 'IN' | 'OUT';
|
|
66
|
+
/** The other party, E.164. */
|
|
67
|
+
peer: string;
|
|
68
|
+
/** The inbox's line, E.164. */
|
|
69
|
+
line: string;
|
|
70
|
+
status: string;
|
|
71
|
+
startedAt: Date;
|
|
72
|
+
/** Seconds it was connected. */
|
|
73
|
+
duration: number;
|
|
74
|
+
/** The inbox's agent took or placed it. */
|
|
75
|
+
agent: boolean;
|
|
76
|
+
/** A message left on the line, or a call that reached their voicemail. */
|
|
77
|
+
voicemail: boolean;
|
|
78
|
+
/** Its audio can be fetched with recording(). */
|
|
79
|
+
recorded: boolean;
|
|
80
|
+
segments: CallSegment[];
|
|
81
|
+
};
|
|
82
|
+
export declare const CallRecord: {
|
|
83
|
+
fromJSON(json: any): CallRecord;
|
|
84
|
+
};
|
|
85
|
+
/** The inbox's calls, newest first. `voicemails` keeps only voicemails; `query` matches what was said, the number, or the contact's name. */
|
|
86
|
+
export declare function history(authorization: Credentials | ApiKey, inbox: string, opts?: {
|
|
87
|
+
voicemails?: boolean;
|
|
88
|
+
query?: string;
|
|
89
|
+
cursor?: number;
|
|
90
|
+
max?: number;
|
|
91
|
+
}): Promise<CallRecord[]>;
|
|
92
|
+
/** A recorded call's audio, MP3. */
|
|
93
|
+
export declare function recording(authorization: Credentials | ApiKey, call: string): Promise<Blob>;
|
package/dist/src/cicada/phone.js
CHANGED
|
@@ -304,3 +304,49 @@ export async function listen(authorization, inbox, onIncoming) {
|
|
|
304
304
|
export async function call(authorization, inbox, to, from) {
|
|
305
305
|
return openCall(authorization, { event: 'dial', inbox, to, ...(from ? { from } : {}) });
|
|
306
306
|
}
|
|
307
|
+
export const CallRecord = {
|
|
308
|
+
fromJSON(json) {
|
|
309
|
+
return {
|
|
310
|
+
id: String(json.id),
|
|
311
|
+
direction: json.direction === 'in' ? 'IN' : 'OUT',
|
|
312
|
+
peer: String(json.peer ?? ''),
|
|
313
|
+
line: String(json.line ?? ''),
|
|
314
|
+
status: String(json.status ?? ''),
|
|
315
|
+
startedAt: new Date(json.startedAt),
|
|
316
|
+
duration: Number(json.duration ?? 0),
|
|
317
|
+
agent: Boolean(json.agent),
|
|
318
|
+
voicemail: Boolean(json.voicemail),
|
|
319
|
+
recorded: Boolean(json.recorded),
|
|
320
|
+
segments: Array.isArray(json.segments) ? json.segments : [],
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
/** The inbox's calls, newest first. `voicemails` keeps only voicemails; `query` matches what was said, the number, or the contact's name. */
|
|
325
|
+
export async function history(authorization, inbox, opts = {}) {
|
|
326
|
+
const response = await fetch(`${Cicada.getURL()}/cicada/phone/history`, {
|
|
327
|
+
method: 'POST',
|
|
328
|
+
headers: {
|
|
329
|
+
'Content-Type': 'application/json',
|
|
330
|
+
Authorization: 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
331
|
+
},
|
|
332
|
+
body: JSON.stringify({ inbox, ...opts }),
|
|
333
|
+
});
|
|
334
|
+
if (!response.ok)
|
|
335
|
+
throw new Error(await response.text());
|
|
336
|
+
const json = await response.json();
|
|
337
|
+
return (Array.isArray(json) ? json : []).map(CallRecord.fromJSON);
|
|
338
|
+
}
|
|
339
|
+
/** A recorded call's audio, MP3. */
|
|
340
|
+
export async function recording(authorization, call) {
|
|
341
|
+
const response = await fetch(`${Cicada.getURL()}/cicada/phone/recording`, {
|
|
342
|
+
method: 'POST',
|
|
343
|
+
headers: {
|
|
344
|
+
'Content-Type': 'application/json',
|
|
345
|
+
Authorization: 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
346
|
+
},
|
|
347
|
+
body: JSON.stringify({ call }),
|
|
348
|
+
});
|
|
349
|
+
if (!response.ok)
|
|
350
|
+
throw new Error(await response.text());
|
|
351
|
+
return await response.blob();
|
|
352
|
+
}
|
package/dist/src/groups.d.ts
CHANGED
|
@@ -114,7 +114,19 @@ export type NestOffer = {
|
|
|
114
114
|
export declare const NestOffer: {
|
|
115
115
|
fromJSON(json: any): NestOffer;
|
|
116
116
|
};
|
|
117
|
-
/**
|
|
117
|
+
/** An email invite waiting to be accepted, as the group's admins see it. */
|
|
118
|
+
export type EmailInvite = {
|
|
119
|
+
token: string;
|
|
120
|
+
email: string;
|
|
121
|
+
/** Email of the admin who sent it. */
|
|
122
|
+
by?: string;
|
|
123
|
+
expires: Date;
|
|
124
|
+
};
|
|
125
|
+
export declare const EmailInvite: {
|
|
126
|
+
fromJSON(json: any): EmailInvite;
|
|
127
|
+
};
|
|
128
|
+
/** Start a group. You are its first admin. Needs a subscription, and room under
|
|
129
|
+
* `fauna/groups:N`, the most groups you may administer. */
|
|
118
130
|
export declare function create(credentials: Credentials, name: string): Promise<Group>;
|
|
119
131
|
/** Every group you are in, directly or through a nested group, oldest first.
|
|
120
132
|
* Each says how you are in it (`through`). */
|
|
@@ -147,11 +159,20 @@ export declare function acceptInvite(credentials: Credentials, token: string): P
|
|
|
147
159
|
group: Group;
|
|
148
160
|
alreadyMember: boolean;
|
|
149
161
|
}>;
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
/** The group's email invites waiting to be accepted, newest first. Admins only. */
|
|
163
|
+
export declare function invites(credentials: Credentials, id: string, query: {
|
|
164
|
+
cursor: number;
|
|
165
|
+
max: number;
|
|
166
|
+
}): Promise<EmailInvite[]>;
|
|
167
|
+
/** An email invite stops working, by its token. An admin of its group, or whoever sent it. */
|
|
168
|
+
export declare function revokeInvite(credentials: Credentials, token: string): Promise<void>;
|
|
169
|
+
/** A join code. Admins only. People join with it, and admins of other groups put
|
|
170
|
+
* their group inside this one with it. `maxUses` caps how many it lets in;
|
|
171
|
+
* without it, any number can join until it expires. It expires at `expires`,
|
|
172
|
+
* in the future and at most a year out, or in seven days without it. */
|
|
153
173
|
export declare function generateLink(credentials: Credentials, id: string, options?: {
|
|
154
174
|
maxUses?: number;
|
|
175
|
+
expires?: Date;
|
|
155
176
|
}): Promise<string>;
|
|
156
177
|
/** The group's join links that still work, newest first. Admins only. */
|
|
157
178
|
export declare function links(credentials: Credentials, id: string): Promise<JoinLink[]>;
|
|
@@ -171,7 +192,8 @@ export declare function leave(credentials: Credentials, id: string): Promise<voi
|
|
|
171
192
|
/** Remove a person who is directly in the group. Admins only. */
|
|
172
193
|
export declare function kick(credentials: Credentials, id: string, email: string): Promise<void>;
|
|
173
194
|
/** Make a person who is directly in the group an admin. Admins only. Someone in
|
|
174
|
-
* it only through a nested group is invited directly first.
|
|
195
|
+
* it only through a nested group is invited directly first. They need room under
|
|
196
|
+
* their own `fauna/groups:N`, the most groups they may administer. */
|
|
175
197
|
export declare function promote(credentials: Credentials, id: string, email: string): Promise<Group>;
|
|
176
198
|
/** Make an admin a member again. Admins only; a group keeps at least one admin. */
|
|
177
199
|
export declare function demote(credentials: Credentials, id: string, email: string): Promise<Group>;
|
package/dist/src/groups.js
CHANGED
|
@@ -89,7 +89,18 @@ export const NestOffer = {
|
|
|
89
89
|
return json.nested === true ? { nested: true } : { nested: false, token: String(json.token) };
|
|
90
90
|
},
|
|
91
91
|
};
|
|
92
|
-
|
|
92
|
+
export const EmailInvite = {
|
|
93
|
+
fromJSON(json) {
|
|
94
|
+
return {
|
|
95
|
+
token: String(json.token),
|
|
96
|
+
email: String(json.email),
|
|
97
|
+
...(json.by ? { by: String(json.by) } : {}),
|
|
98
|
+
expires: new Date(json.expires),
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
/** Start a group. You are its first admin. Needs a subscription, and room under
|
|
103
|
+
* `fauna/groups:N`, the most groups you may administer. */
|
|
93
104
|
export async function create(credentials, name) {
|
|
94
105
|
const response = await fetch(`${Fauna.getURL()}/groups`, {
|
|
95
106
|
method: "POST",
|
|
@@ -228,9 +239,36 @@ export async function acceptInvite(credentials, token) {
|
|
|
228
239
|
const raw = await response.json();
|
|
229
240
|
return { group: Group.fromJSON(raw.group), alreadyMember: raw.alreadyMember === true };
|
|
230
241
|
}
|
|
231
|
-
/**
|
|
232
|
-
|
|
233
|
-
|
|
242
|
+
/** The group's email invites waiting to be accepted, newest first. Admins only. */
|
|
243
|
+
export async function invites(credentials, id, query) {
|
|
244
|
+
const params = new URLSearchParams({ cursor: String(query.cursor), max: String(query.max) });
|
|
245
|
+
const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/invites?${params}`, {
|
|
246
|
+
method: "GET",
|
|
247
|
+
headers: {
|
|
248
|
+
"Authorization": `Token ${credentials.token}`
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
if (!response.ok) {
|
|
252
|
+
throw new Error(await response.text());
|
|
253
|
+
}
|
|
254
|
+
return (await response.json()).map(EmailInvite.fromJSON);
|
|
255
|
+
}
|
|
256
|
+
/** An email invite stops working, by its token. An admin of its group, or whoever sent it. */
|
|
257
|
+
export async function revokeInvite(credentials, token) {
|
|
258
|
+
const response = await fetch(`${Fauna.getURL()}/groups/invites/${encodeURIComponent(token)}`, {
|
|
259
|
+
method: "DELETE",
|
|
260
|
+
headers: {
|
|
261
|
+
"Authorization": `Token ${credentials.token}`
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
if (!response.ok) {
|
|
265
|
+
throw new Error(await response.text());
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** A join code. Admins only. People join with it, and admins of other groups put
|
|
269
|
+
* their group inside this one with it. `maxUses` caps how many it lets in;
|
|
270
|
+
* without it, any number can join until it expires. It expires at `expires`,
|
|
271
|
+
* in the future and at most a year out, or in seven days without it. */
|
|
234
272
|
export async function generateLink(credentials, id, options = {}) {
|
|
235
273
|
const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/link`, {
|
|
236
274
|
method: "POST",
|
|
@@ -238,7 +276,7 @@ export async function generateLink(credentials, id, options = {}) {
|
|
|
238
276
|
"Content-Type": "application/json",
|
|
239
277
|
"Authorization": `Token ${credentials.token}`
|
|
240
278
|
},
|
|
241
|
-
body: JSON.stringify({ maxUses: options.maxUses })
|
|
279
|
+
body: JSON.stringify({ maxUses: options.maxUses, expires: options.expires?.toISOString() })
|
|
242
280
|
});
|
|
243
281
|
if (!response.ok) {
|
|
244
282
|
throw new Error(await response.text());
|
|
@@ -316,7 +354,8 @@ export async function kick(credentials, id, email) {
|
|
|
316
354
|
}
|
|
317
355
|
}
|
|
318
356
|
/** Make a person who is directly in the group an admin. Admins only. Someone in
|
|
319
|
-
* it only through a nested group is invited directly first.
|
|
357
|
+
* it only through a nested group is invited directly first. They need room under
|
|
358
|
+
* their own `fauna/groups:N`, the most groups they may administer. */
|
|
320
359
|
export async function promote(credentials, id, email) {
|
|
321
360
|
const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/admins/${encodeURIComponent(email)}`, {
|
|
322
361
|
method: "POST",
|
package/dist/src/webhooks.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ApiKey, Credentials, Profile } from "./authentification.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { GroupRef } from "./groups.js";
|
|
3
|
+
/** Event types a webhook can listen for: `chat.message` for groups and chats,
|
|
4
|
+
* `group.joined` and `group.left` for groups, payment events for API keys. */
|
|
5
|
+
export type EventType = 'chat.message' | 'group.joined' | 'group.left' | 'payment.succeeded' | 'payment.expired' | 'payment.refunded' | 'payment.disputed';
|
|
4
6
|
/** Who a webhook belongs to: a group, one chat, or the API key making the call. */
|
|
5
7
|
export type WebhookOwner = {
|
|
6
8
|
group: string;
|
|
@@ -51,6 +53,23 @@ export type ChatMessage = {
|
|
|
51
53
|
/** Milliseconds since the epoch. */
|
|
52
54
|
created: number;
|
|
53
55
|
};
|
|
56
|
+
/** Who came into a group or went out of it: a person, or a group nested directly inside it. */
|
|
57
|
+
export type GroupChangeMember = {
|
|
58
|
+
email: string;
|
|
59
|
+
} | {
|
|
60
|
+
group: GroupRef;
|
|
61
|
+
};
|
|
62
|
+
/** Why: `joined` for `group.joined`; for `group.left`, the person `left` or was
|
|
63
|
+
* `removed` by an admin, or the nested group was `unnested` or `deleted`. */
|
|
64
|
+
export type GroupChangeReason = 'joined' | 'left' | 'removed' | 'unnested' | 'deleted';
|
|
65
|
+
/** `data` of `group.joined` and `group.left`: a person or a nested group came
|
|
66
|
+
* directly into `group` or went directly out of it. Changes further down (someone
|
|
67
|
+
* leaving a nested group) are told only to that group's own webhooks. */
|
|
68
|
+
export type GroupChange = {
|
|
69
|
+
group: GroupRef;
|
|
70
|
+
member: GroupChangeMember;
|
|
71
|
+
reason: GroupChangeReason;
|
|
72
|
+
};
|
|
54
73
|
/**
|
|
55
74
|
* Register a webhook for a group or a chat you can read, or, signed in with an
|
|
56
75
|
* API key, for that key. In production `url` must be https on a public address.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fauna-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.694",
|
|
4
4
|
"description": "The Fauna SDK: accounts, Drive, groups, calendar, chats, payments and every Fauna app (Parrot, Marmot, Magpie, Cicada, Ant, Termite), plus React UI.",
|
|
5
5
|
"homepage": "https://docs.faunakit.com",
|
|
6
6
|
"repository": {
|