fauna-api 0.0.0-stage → 1.0.679
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/brands.d.ts +2 -0
- package/dist/brands.js +2 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +121 -0
- package/dist/src/ant/chat.d.ts +130 -0
- package/dist/src/ant/chat.js +467 -0
- package/dist/src/ant/format.d.ts +40 -0
- package/dist/src/ant/format.js +143 -0
- package/dist/src/ant/graph.d.ts +130 -0
- package/dist/src/ant/graph.js +449 -0
- package/dist/src/ant/index.d.ts +16 -0
- package/dist/src/ant/index.js +61 -0
- package/dist/src/ant/persona.d.ts +151 -0
- package/dist/src/ant/persona.js +136 -0
- package/dist/src/ant/timeline.d.ts +283 -0
- package/dist/src/ant/timeline.js +1025 -0
- package/dist/src/authentification.d.ts +45 -0
- package/dist/src/authentification.js +194 -0
- package/dist/src/billing.d.ts +135 -0
- package/dist/src/billing.js +128 -0
- package/dist/src/calendar.d.ts +83 -0
- package/dist/src/calendar.js +133 -0
- package/dist/src/chats.d.ts +113 -0
- package/dist/src/chats.js +100 -0
- package/dist/src/cicada/contacts.d.ts +31 -0
- package/dist/src/cicada/contacts.js +28 -0
- package/dist/src/cicada/conversations.d.ts +73 -0
- package/dist/src/cicada/conversations.js +236 -0
- package/dist/src/cicada/inboxes.d.ts +48 -0
- package/dist/src/cicada/inboxes.js +82 -0
- package/dist/src/cicada/index.d.ts +16 -0
- package/dist/src/cicada/index.js +61 -0
- package/dist/src/cicada/phone.d.ts +48 -0
- package/dist/src/cicada/phone.js +306 -0
- package/dist/src/drive.d.ts +80 -0
- package/dist/src/drive.js +472 -0
- package/dist/src/extensions/index.d.ts +4 -0
- package/dist/src/extensions/index.js +5 -0
- package/dist/src/extensions/web/index.d.ts +6 -0
- package/dist/src/extensions/web/index.js +7 -0
- package/dist/src/extensions/web/session.d.ts +108 -0
- package/dist/src/extensions/web/session.js +470 -0
- package/dist/src/extensions/web/tools.d.ts +13 -0
- package/dist/src/extensions/web/tools.js +72 -0
- package/dist/src/friends.d.ts +39 -0
- package/dist/src/friends.js +119 -0
- package/dist/src/groups.d.ts +82 -0
- package/dist/src/groups.js +269 -0
- package/dist/src/inbox.d.ts +11 -0
- package/dist/src/inbox.js +35 -0
- package/dist/src/integrations.d.ts +52 -0
- package/dist/src/integrations.js +205 -0
- package/dist/src/magpie/explorer.d.ts +14 -0
- package/dist/src/magpie/explorer.js +36 -0
- package/dist/src/magpie/index.d.ts +16 -0
- package/dist/src/magpie/index.js +61 -0
- package/dist/src/magpie/portfolio.d.ts +52 -0
- package/dist/src/magpie/portfolio.js +179 -0
- package/dist/src/magpie/quotes.d.ts +35 -0
- package/dist/src/magpie/quotes.js +47 -0
- package/dist/src/magpie/room.d.ts +61 -0
- package/dist/src/magpie/room.js +238 -0
- package/dist/src/maps.d.ts +159 -0
- package/dist/src/maps.js +171 -0
- package/dist/src/marmot/browser.d.ts +139 -0
- package/dist/src/marmot/browser.js +389 -0
- package/dist/src/marmot/index.d.ts +20 -0
- package/dist/src/marmot/index.js +65 -0
- package/dist/src/marmot/media.d.ts +56 -0
- package/dist/src/marmot/media.js +265 -0
- package/dist/src/marmot/research.d.ts +337 -0
- package/dist/src/marmot/research.js +1138 -0
- package/dist/src/marmot/scraper.d.ts +59 -0
- package/dist/src/marmot/scraper.js +94 -0
- package/dist/src/marmot/web.d.ts +402 -0
- package/dist/src/marmot/web.js +2586 -0
- package/dist/src/marmot/workspace.d.ts +81 -0
- package/dist/src/marmot/workspace.js +263 -0
- package/dist/src/parrot/agent.d.ts +53 -0
- package/dist/src/parrot/agent.js +93 -0
- package/dist/src/parrot/chat.d.ts +84 -0
- package/dist/src/parrot/chat.js +237 -0
- package/dist/src/parrot/format.d.ts +128 -0
- package/dist/src/parrot/format.js +639 -0
- package/dist/src/parrot/generative.d.ts +261 -0
- package/dist/src/parrot/generative.js +185 -0
- package/dist/src/parrot/index.d.ts +22 -0
- package/dist/src/parrot/index.js +67 -0
- package/dist/src/parrot/room.d.ts +225 -0
- package/dist/src/parrot/room.js +466 -0
- package/dist/src/parrot/routing.d.ts +90 -0
- package/dist/src/parrot/routing.js +78 -0
- package/dist/src/parrot/share.d.ts +126 -0
- package/dist/src/parrot/share.js +261 -0
- package/dist/src/parrot/socket.d.ts +41 -0
- package/dist/src/parrot/socket.js +478 -0
- package/dist/src/payments.d.ts +73 -0
- package/dist/src/payments.js +107 -0
- package/dist/src/private/cards.css +75 -0
- package/dist/src/rooms.d.ts +76 -0
- package/dist/src/rooms.js +168 -0
- package/dist/src/shared/schema.d.ts +24 -0
- package/dist/src/shared/schema.js +1 -0
- package/dist/src/shared/server.d.ts +65 -0
- package/dist/src/shared/server.js +302 -0
- package/dist/src/termite/environment.d.ts +110 -0
- package/dist/src/termite/environment.js +263 -0
- package/dist/src/termite/index.d.ts +14 -0
- package/dist/src/termite/index.js +59 -0
- package/dist/src/termite/os.d.ts +326 -0
- package/dist/src/termite/os.js +572 -0
- package/dist/src/termite/versioning.d.ts +94 -0
- package/dist/src/termite/versioning.js +217 -0
- package/dist/src/tickets.d.ts +43 -0
- package/dist/src/tickets.js +138 -0
- package/dist/src/travel.d.ts +85 -0
- package/dist/src/travel.js +44 -0
- package/dist/src/ui/authentification.d.ts +24 -0
- package/dist/src/ui/authentification.js +177 -0
- package/dist/src/ui/brands.css +11 -0
- package/dist/src/ui/brands.d.ts +7 -0
- package/dist/src/ui/brands.js +14 -0
- package/dist/src/ui/browser.d.ts +74 -0
- package/dist/src/ui/browser.js +470 -0
- package/dist/src/ui/chat.d.ts +183 -0
- package/dist/src/ui/chat.js +2379 -0
- package/dist/src/ui/chatPanel.d.ts +109 -0
- package/dist/src/ui/chatPanel.js +768 -0
- package/dist/src/ui/chatSequence.d.ts +36 -0
- package/dist/src/ui/chatSequence.js +42 -0
- package/dist/src/ui/crown.d.ts +19 -0
- package/dist/src/ui/crown.js +199 -0
- package/dist/src/ui/cursor.d.ts +73 -0
- package/dist/src/ui/cursor.js +175 -0
- package/dist/src/ui/device.d.ts +33 -0
- package/dist/src/ui/device.js +49 -0
- package/dist/src/ui/drive.d.ts +69 -0
- package/dist/src/ui/drive.js +1243 -0
- package/dist/src/ui/generative.d.ts +39 -0
- package/dist/src/ui/generative.js +313 -0
- package/dist/src/ui/hover.d.ts +6 -0
- package/dist/src/ui/hover.js +210 -0
- package/dist/src/ui/index.d.ts +42 -0
- package/dist/src/ui/index.js +87 -0
- package/dist/src/ui/integrations.d.ts +13 -0
- package/dist/src/ui/integrations.js +175 -0
- package/dist/src/ui/maps.d.ts +87 -0
- package/dist/src/ui/maps.js +547 -0
- package/dist/src/ui/roster.d.ts +32 -0
- package/dist/src/ui/roster.js +163 -0
- package/dist/src/ui/talk.d.ts +12 -0
- package/dist/src/ui/talk.js +560 -0
- package/dist/src/ui/tickets.d.ts +13 -0
- package/dist/src/ui/tickets.js +966 -0
- package/dist/src/ui/toast.d.ts +7 -0
- package/dist/src/ui/toast.js +258 -0
- package/dist/src/ui/tokenText.d.ts +18 -0
- package/dist/src/ui/tokenText.js +96 -0
- package/dist/src/ui/tokenized.d.ts +42 -0
- package/dist/src/ui/tokenized.js +622 -0
- package/dist/src/ui/ui.css +4763 -0
- package/dist/src/ui/view.d.ts +23 -0
- package/dist/src/ui/view.js +584 -0
- package/dist/src/view.d.ts +113 -0
- package/dist/src/view.js +386 -0
- package/dist/src/webhooks.d.ts +66 -0
- package/dist/src/webhooks.js +78 -0
- package/dist/ui.d.ts +1 -0
- package/dist/ui.js +1 -0
- package/package.json +87 -4
- package/README.md +0 -3
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _PhoneCall_instances, _PhoneCall_ws, _PhoneCall_statusListeners, _PhoneCall_queue, _PhoneCall_wake, _PhoneCall_closed, _PhoneCall_ended, _PhoneCall_setStatus, _IncomingCall_authorization, _IncomingCall_ringing, _IncomingCall_accepted;
|
|
13
|
+
import { Cicada } from "./index.js";
|
|
14
|
+
import WebSocket from "isomorphic-ws";
|
|
15
|
+
function toBytes(data) {
|
|
16
|
+
if (data instanceof Uint8Array)
|
|
17
|
+
return data;
|
|
18
|
+
if (data instanceof ArrayBuffer)
|
|
19
|
+
return new Uint8Array(data);
|
|
20
|
+
if (ArrayBuffer.isView(data))
|
|
21
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
22
|
+
return new Uint8Array(0);
|
|
23
|
+
}
|
|
24
|
+
function phoneSocket(authorization, path, query = {}) {
|
|
25
|
+
const base = Cicada.getURL().replace('https://', 'wss://').replace('http://', 'ws://');
|
|
26
|
+
const params = new URLSearchParams({
|
|
27
|
+
...query,
|
|
28
|
+
authorization: JSON.stringify({
|
|
29
|
+
Authorization: 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
const ws = new WebSocket(`${base}${path}?${params}`);
|
|
33
|
+
ws.binaryType = 'arraybuffer';
|
|
34
|
+
return ws;
|
|
35
|
+
}
|
|
36
|
+
export class PhoneCall {
|
|
37
|
+
constructor(json, ws) {
|
|
38
|
+
_PhoneCall_instances.add(this);
|
|
39
|
+
Object.defineProperty(this, "id", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(this, "direction", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
51
|
+
/** The linked Twilio number, E.164. */
|
|
52
|
+
Object.defineProperty(this, "line", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: void 0
|
|
57
|
+
});
|
|
58
|
+
/** The other party, E.164. */
|
|
59
|
+
Object.defineProperty(this, "peer", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "status", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
_PhoneCall_ws.set(this, void 0);
|
|
72
|
+
_PhoneCall_statusListeners.set(this, new Set());
|
|
73
|
+
_PhoneCall_queue.set(this, []);
|
|
74
|
+
_PhoneCall_wake.set(this, void 0);
|
|
75
|
+
_PhoneCall_closed.set(this, false);
|
|
76
|
+
_PhoneCall_ended.set(this, void 0);
|
|
77
|
+
this.id = String(json.id);
|
|
78
|
+
this.direction = json.direction === 'IN' ? 'IN' : 'OUT';
|
|
79
|
+
this.line = String(json.line ?? '');
|
|
80
|
+
this.peer = String(json.peer ?? '');
|
|
81
|
+
this.status = json.status === 'ACTIVE' ? 'ACTIVE' : json.status === 'ENDED' ? 'ENDED' : 'RINGING';
|
|
82
|
+
__classPrivateFieldSet(this, _PhoneCall_ws, ws, "f");
|
|
83
|
+
let finish = () => { };
|
|
84
|
+
__classPrivateFieldSet(this, _PhoneCall_ended, new Promise((resolve) => { finish = resolve; }), "f");
|
|
85
|
+
const close = (end) => {
|
|
86
|
+
if (__classPrivateFieldGet(this, _PhoneCall_closed, "f"))
|
|
87
|
+
return;
|
|
88
|
+
__classPrivateFieldGet(this, _PhoneCall_instances, "m", _PhoneCall_setStatus).call(this, 'ENDED');
|
|
89
|
+
__classPrivateFieldSet(this, _PhoneCall_closed, true, "f");
|
|
90
|
+
__classPrivateFieldGet(this, _PhoneCall_wake, "f")?.call(this);
|
|
91
|
+
finish(end);
|
|
92
|
+
};
|
|
93
|
+
ws.onmessage = (msg) => {
|
|
94
|
+
if (typeof msg.data !== 'string') {
|
|
95
|
+
__classPrivateFieldGet(this, _PhoneCall_queue, "f").push(toBytes(msg.data));
|
|
96
|
+
__classPrivateFieldGet(this, _PhoneCall_wake, "f")?.call(this);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
let packet;
|
|
100
|
+
try {
|
|
101
|
+
packet = JSON.parse(msg.data);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (packet.event === 'status') {
|
|
107
|
+
if (packet.data?.status === 'ACTIVE')
|
|
108
|
+
__classPrivateFieldGet(this, _PhoneCall_instances, "m", _PhoneCall_setStatus).call(this, 'ACTIVE');
|
|
109
|
+
}
|
|
110
|
+
else if (packet.event === 'ended') {
|
|
111
|
+
close({ status: packet.data?.status ?? 'COMPLETED', duration: Number(packet.data?.duration ?? 0) });
|
|
112
|
+
try {
|
|
113
|
+
ws.close();
|
|
114
|
+
}
|
|
115
|
+
catch { }
|
|
116
|
+
}
|
|
117
|
+
else if (packet.event === 'error') {
|
|
118
|
+
close({ status: 'FAILED', duration: 0 });
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
ws.onclose = () => close({ status: this.status === 'ACTIVE' ? 'COMPLETED' : 'FAILED', duration: 0 });
|
|
122
|
+
ws.onerror = () => close({ status: 'FAILED', duration: 0 });
|
|
123
|
+
}
|
|
124
|
+
/** Calls `listener` when the call is answered (ACTIVE) and when it ends (ENDED). */
|
|
125
|
+
onStatus(listener) {
|
|
126
|
+
__classPrivateFieldGet(this, _PhoneCall_statusListeners, "f").add(listener);
|
|
127
|
+
return () => { __classPrivateFieldGet(this, _PhoneCall_statusListeners, "f").delete(listener); };
|
|
128
|
+
}
|
|
129
|
+
/** The other party's audio: PCM16 mono 16 kHz, the same as generateVoice's audio input. */
|
|
130
|
+
async *audio() {
|
|
131
|
+
for (;;) {
|
|
132
|
+
const chunk = __classPrivateFieldGet(this, _PhoneCall_queue, "f").shift();
|
|
133
|
+
if (chunk) {
|
|
134
|
+
yield chunk;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (__classPrivateFieldGet(this, _PhoneCall_closed, "f"))
|
|
138
|
+
return;
|
|
139
|
+
await new Promise((resolve) => { __classPrivateFieldSet(this, _PhoneCall_wake, resolve, "f"); });
|
|
140
|
+
__classPrivateFieldSet(this, _PhoneCall_wake, undefined, "f");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Audio to the other party: PCM16 mono 24 kHz, the same as generateVoice's audio output. */
|
|
144
|
+
send(pcm) {
|
|
145
|
+
if (__classPrivateFieldGet(this, _PhoneCall_ws, "f").readyState === WebSocket.OPEN)
|
|
146
|
+
__classPrivateFieldGet(this, _PhoneCall_ws, "f").send(pcm);
|
|
147
|
+
}
|
|
148
|
+
async hangup() {
|
|
149
|
+
if (__classPrivateFieldGet(this, _PhoneCall_ws, "f").readyState === WebSocket.OPEN)
|
|
150
|
+
__classPrivateFieldGet(this, _PhoneCall_ws, "f").send(JSON.stringify({ event: 'hangup' }));
|
|
151
|
+
await __classPrivateFieldGet(this, _PhoneCall_ended, "f");
|
|
152
|
+
}
|
|
153
|
+
/** Resolves once the call is over. duration is seconds of talk, 0 when never answered. */
|
|
154
|
+
ended() {
|
|
155
|
+
return __classPrivateFieldGet(this, _PhoneCall_ended, "f");
|
|
156
|
+
}
|
|
157
|
+
static fromJSON(json, ws) {
|
|
158
|
+
return new PhoneCall(json, ws);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
_PhoneCall_ws = new WeakMap(), _PhoneCall_statusListeners = new WeakMap(), _PhoneCall_queue = new WeakMap(), _PhoneCall_wake = new WeakMap(), _PhoneCall_closed = new WeakMap(), _PhoneCall_ended = new WeakMap(), _PhoneCall_instances = new WeakSet(), _PhoneCall_setStatus = function _PhoneCall_setStatus(status) {
|
|
162
|
+
if (this.status === status)
|
|
163
|
+
return;
|
|
164
|
+
this.status = status;
|
|
165
|
+
for (const listener of __classPrivateFieldGet(this, _PhoneCall_statusListeners, "f"))
|
|
166
|
+
listener(status);
|
|
167
|
+
};
|
|
168
|
+
// Opens a call socket and resolves with the call once the server confirms it.
|
|
169
|
+
function openCall(authorization, first) {
|
|
170
|
+
const ws = phoneSocket(authorization, '/cicada/phone/call');
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
|
+
ws.onopen = () => ws.send(JSON.stringify(first));
|
|
173
|
+
ws.onerror = () => reject(new Error('Phone connection failed.'));
|
|
174
|
+
ws.onclose = () => reject(new Error('The call ended before it started.'));
|
|
175
|
+
ws.onmessage = (msg) => {
|
|
176
|
+
if (typeof msg.data !== 'string')
|
|
177
|
+
return;
|
|
178
|
+
let packet;
|
|
179
|
+
try {
|
|
180
|
+
packet = JSON.parse(msg.data);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (packet.event === 'call') {
|
|
186
|
+
resolve(PhoneCall.fromJSON(packet.data, ws));
|
|
187
|
+
}
|
|
188
|
+
else if (packet.event === 'error') {
|
|
189
|
+
reject(new Error(packet.message ?? 'The call failed.'));
|
|
190
|
+
try {
|
|
191
|
+
ws.close();
|
|
192
|
+
}
|
|
193
|
+
catch { }
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// How listen() tells an IncomingCall it stopped ringing.
|
|
199
|
+
const ringEnders = new WeakMap();
|
|
200
|
+
export class IncomingCall {
|
|
201
|
+
constructor(json, authorization) {
|
|
202
|
+
Object.defineProperty(this, "id", {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
configurable: true,
|
|
205
|
+
writable: true,
|
|
206
|
+
value: void 0
|
|
207
|
+
});
|
|
208
|
+
/** The inbox's number that was called. */
|
|
209
|
+
Object.defineProperty(this, "line", {
|
|
210
|
+
enumerable: true,
|
|
211
|
+
configurable: true,
|
|
212
|
+
writable: true,
|
|
213
|
+
value: void 0
|
|
214
|
+
});
|
|
215
|
+
/** Who is calling. */
|
|
216
|
+
Object.defineProperty(this, "peer", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
configurable: true,
|
|
219
|
+
writable: true,
|
|
220
|
+
value: void 0
|
|
221
|
+
});
|
|
222
|
+
_IncomingCall_authorization.set(this, void 0);
|
|
223
|
+
_IncomingCall_ringing.set(this, void 0);
|
|
224
|
+
_IncomingCall_accepted.set(this, false);
|
|
225
|
+
this.id = String(json.id);
|
|
226
|
+
this.line = String(json.line ?? '');
|
|
227
|
+
this.peer = String(json.peer ?? '');
|
|
228
|
+
__classPrivateFieldSet(this, _IncomingCall_authorization, authorization, "f");
|
|
229
|
+
let end = () => { };
|
|
230
|
+
__classPrivateFieldSet(this, _IncomingCall_ringing, new Promise((resolve) => { end = resolve; }), "f");
|
|
231
|
+
ringEnders.set(this, (reason) => end(__classPrivateFieldGet(this, _IncomingCall_accepted, "f") ? 'ACCEPTED' : reason));
|
|
232
|
+
}
|
|
233
|
+
/** Rejects with "Someone else took the call." when another listener won. */
|
|
234
|
+
async accept() {
|
|
235
|
+
const call = await openCall(__classPrivateFieldGet(this, _IncomingCall_authorization, "f"), { event: 'answer', id: this.id });
|
|
236
|
+
__classPrivateFieldSet(this, _IncomingCall_accepted, true, "f");
|
|
237
|
+
ringEnders.get(this)?.('ACCEPTED');
|
|
238
|
+
return call;
|
|
239
|
+
}
|
|
240
|
+
/** Resolves when it stops ringing for you. */
|
|
241
|
+
ringing() {
|
|
242
|
+
return __classPrivateFieldGet(this, _IncomingCall_ringing, "f");
|
|
243
|
+
}
|
|
244
|
+
static fromJSON(json, authorization) {
|
|
245
|
+
return new IncomingCall(json, authorization);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
_IncomingCall_authorization = new WeakMap(), _IncomingCall_ringing = new WeakMap(), _IncomingCall_accepted = new WeakMap();
|
|
249
|
+
/** Rings for calls to any Twilio number linked to the inbox, until close(). */
|
|
250
|
+
export async function listen(authorization, inbox, onIncoming) {
|
|
251
|
+
const ws = phoneSocket(authorization, '/cicada/phone/listen', { inbox });
|
|
252
|
+
const ringing = new Map();
|
|
253
|
+
await new Promise((resolve, reject) => {
|
|
254
|
+
ws.onerror = () => reject(new Error('Phone connection failed.'));
|
|
255
|
+
ws.onclose = () => reject(new Error('Phone connection closed.'));
|
|
256
|
+
ws.onmessage = (msg) => {
|
|
257
|
+
if (typeof msg.data !== 'string')
|
|
258
|
+
return;
|
|
259
|
+
let packet;
|
|
260
|
+
try {
|
|
261
|
+
packet = JSON.parse(msg.data);
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (packet.event === 'listening') {
|
|
267
|
+
resolve();
|
|
268
|
+
}
|
|
269
|
+
else if (packet.event === 'error') {
|
|
270
|
+
reject(new Error(packet.message ?? 'Could not listen for calls.'));
|
|
271
|
+
}
|
|
272
|
+
else if (packet.event === 'incoming') {
|
|
273
|
+
const call = IncomingCall.fromJSON(packet.data, authorization);
|
|
274
|
+
ringing.set(call.id, call);
|
|
275
|
+
onIncoming(call);
|
|
276
|
+
}
|
|
277
|
+
else if (packet.event === 'ring-end') {
|
|
278
|
+
const call = ringing.get(String(packet.data?.id));
|
|
279
|
+
if (!call)
|
|
280
|
+
return;
|
|
281
|
+
ringing.delete(call.id);
|
|
282
|
+
ringEnders.get(call)?.(packet.data?.reason ?? 'HUNG_UP');
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
const endAll = () => {
|
|
287
|
+
for (const call of ringing.values())
|
|
288
|
+
ringEnders.get(call)?.('HUNG_UP');
|
|
289
|
+
ringing.clear();
|
|
290
|
+
};
|
|
291
|
+
ws.onclose = endAll;
|
|
292
|
+
ws.onerror = endAll;
|
|
293
|
+
return {
|
|
294
|
+
close() {
|
|
295
|
+
endAll();
|
|
296
|
+
try {
|
|
297
|
+
ws.close();
|
|
298
|
+
}
|
|
299
|
+
catch { }
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/** Calls `to` from one of the inbox's phone lines: `from`, or its first line. */
|
|
304
|
+
export async function call(authorization, inbox, to, from) {
|
|
305
|
+
return openCall(authorization, { event: 'dial', inbox, to, ...(from ? { from } : {}) });
|
|
306
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ApiKey, Credentials } from "./authentification.js";
|
|
2
|
+
export { FaunaFile as File };
|
|
3
|
+
declare class FaunaFile {
|
|
4
|
+
readonly authorization: DriveAuthorization;
|
|
5
|
+
readonly contentType: string;
|
|
6
|
+
readonly contentLength: number;
|
|
7
|
+
readonly accessDate: Date;
|
|
8
|
+
readonly createDate: Date;
|
|
9
|
+
private _name;
|
|
10
|
+
get name(): string;
|
|
11
|
+
private _online;
|
|
12
|
+
get online(): boolean;
|
|
13
|
+
constructor(authorization: DriveAuthorization, name: string, online: boolean, contentType: string, contentLength: number, accessDate: Date, createDate: Date, data?: Uint8Array | undefined);
|
|
14
|
+
static fromJSON(json: any, authorization: DriveAuthorization): FaunaFile;
|
|
15
|
+
private data;
|
|
16
|
+
private previewData;
|
|
17
|
+
download(revalidate?: boolean, onProgress?: (percent: number) => void): Promise<Uint8Array>;
|
|
18
|
+
preview(revalidate?: boolean): Promise<Uint8Array | undefined>;
|
|
19
|
+
upload(onProgress?: (percent: number) => void): Promise<void>;
|
|
20
|
+
copy(path: string): Promise<void>;
|
|
21
|
+
text(): Promise<string>;
|
|
22
|
+
json<T>(): Promise<T>;
|
|
23
|
+
remove(): Promise<void>;
|
|
24
|
+
generateAccessCode(expiration?: number): Promise<string>;
|
|
25
|
+
owner(): Promise<{
|
|
26
|
+
email: string;
|
|
27
|
+
displayName?: string;
|
|
28
|
+
icon?: string;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
export type DriveAuthorization = {
|
|
32
|
+
authorization: Credentials | ApiKey;
|
|
33
|
+
path: string;
|
|
34
|
+
group?: string;
|
|
35
|
+
} | {
|
|
36
|
+
authorization: Credentials | ApiKey;
|
|
37
|
+
accessCode: string;
|
|
38
|
+
} | {
|
|
39
|
+
authorization: Credentials | ApiKey;
|
|
40
|
+
repository: number;
|
|
41
|
+
path: string;
|
|
42
|
+
group?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function list(authorization: Credentials | ApiKey, path: string, group?: string): Promise<string[]>;
|
|
45
|
+
export declare function wrap(authorization: DriveAuthorization, file: File, options?: Partial<{
|
|
46
|
+
accessDate: Date;
|
|
47
|
+
createDate: Date;
|
|
48
|
+
}>): Promise<FaunaFile>;
|
|
49
|
+
/**
|
|
50
|
+
* Build an in-memory FaunaFile from raw bytes (not yet uploaded). `path` is
|
|
51
|
+
* the Drive destination (e.g. `tmp/${uuid}-${name}`); the display name is the
|
|
52
|
+
* last path segment. `authorization` is the caller's credentials/api key; the
|
|
53
|
+
* file is `online: false` until an explicit `upload()`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function fromBytes(authorization: Credentials | ApiKey, path: string, contentType: string, data: Uint8Array, options?: Partial<{
|
|
56
|
+
accessDate: Date;
|
|
57
|
+
createDate: Date;
|
|
58
|
+
}>): FaunaFile;
|
|
59
|
+
/**
|
|
60
|
+
* Build a streaming FaunaFile addressed by a per-file access code. Bytes are
|
|
61
|
+
* pulled on demand via `download()` (the `Access-Code` path). Used to hydrate
|
|
62
|
+
* chat message FILE parts returned by the server (each carries its own code),
|
|
63
|
+
* so members stream file bytes uniformly without a host-drive path.
|
|
64
|
+
*/
|
|
65
|
+
export declare function fromAccessCode(authorization: Credentials | ApiKey, accessCode: string, meta: {
|
|
66
|
+
name: string;
|
|
67
|
+
contentType: string;
|
|
68
|
+
contentLength?: number;
|
|
69
|
+
accessDate?: Date;
|
|
70
|
+
createDate?: Date;
|
|
71
|
+
}): FaunaFile;
|
|
72
|
+
export declare function folder(authorization: DriveAuthorization, options?: Partial<{
|
|
73
|
+
accessDate: Date;
|
|
74
|
+
createDate: Date;
|
|
75
|
+
}>): Promise<FaunaFile>;
|
|
76
|
+
export declare function pull(authorization: DriveAuthorization): Promise<FaunaFile>;
|
|
77
|
+
export declare function remove(authorization: Credentials | ApiKey, path: string, group?: string): Promise<boolean>;
|
|
78
|
+
/** Split a Drive style response into its parts. With `Encoding-Size` above 1 the
|
|
79
|
+
* body is a `--BOUNDARY` separated multipart and this returns every part. */
|
|
80
|
+
export declare function parseStream(response: Response, onLoaded?: (loadedBytes: number) => void): Promise<Uint8Array<ArrayBuffer> | Uint8Array<ArrayBufferLike>[]>;
|