fauna-api 0.0.0-stage → 1.0.676
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 +106 -0
- package/dist/src/extensions/web/session.js +469 -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 +89 -6
- package/README.md +0 -3
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Credentials, ApiKey } from "../authentification.js";
|
|
2
|
+
import { Group } from "../groups.js";
|
|
3
|
+
import { Authorization, Presence, Room, Hooks as ServerHooks } from "../shared/server.js";
|
|
4
|
+
import { ChatRoom, RoomHooks } from "../parrot/room.js";
|
|
5
|
+
import type { Asset } from "./portfolio.js";
|
|
6
|
+
import type { Explorer } from "./explorer.js";
|
|
7
|
+
export type PortfolioEntry = Record<string, any> & {
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class PortfolioRoom extends Room {
|
|
11
|
+
portfolioId: string;
|
|
12
|
+
name: string;
|
|
13
|
+
profile: Map<string, PortfolioEntry>;
|
|
14
|
+
constructor(endpoint: string, ws: WebSocket, authorization: Authorization, id: string);
|
|
15
|
+
hydrate(state: any): void;
|
|
16
|
+
handleEvent(packet: any): void;
|
|
17
|
+
getChat(hooks?: RoomHooks): Promise<{
|
|
18
|
+
room: ChatRoom;
|
|
19
|
+
self: Presence;
|
|
20
|
+
chatId: string;
|
|
21
|
+
}>;
|
|
22
|
+
static connect(authorization: Credentials | ApiKey, target: {
|
|
23
|
+
id: string;
|
|
24
|
+
}, opts?: {
|
|
25
|
+
group?: Group;
|
|
26
|
+
hooks?: ServerHooks;
|
|
27
|
+
server?: string;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
room: PortfolioRoom;
|
|
30
|
+
self: Presence;
|
|
31
|
+
}>;
|
|
32
|
+
static join(authorization: Credentials | ApiKey, target: {
|
|
33
|
+
accessCode: string;
|
|
34
|
+
}, hooks?: ServerHooks): Promise<{
|
|
35
|
+
room: PortfolioRoom;
|
|
36
|
+
self: Presence;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
export declare class ExplorerRoom extends Room {
|
|
40
|
+
host: string;
|
|
41
|
+
entries: Map<string, Explorer>;
|
|
42
|
+
constructor(endpoint: string, ws: WebSocket, authorization: Authorization, id: string);
|
|
43
|
+
hydrate(state: any): void;
|
|
44
|
+
handleEvent(packet: any): void;
|
|
45
|
+
setTicker(asset: Asset, ticker: string): void;
|
|
46
|
+
commitDrawing(explorer: Explorer): void;
|
|
47
|
+
clearDrawings(asset: Asset, ticker: string): void;
|
|
48
|
+
static connect(authorization: Credentials | ApiKey, opts?: {
|
|
49
|
+
hooks?: ServerHooks;
|
|
50
|
+
server?: string;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
room: ExplorerRoom;
|
|
53
|
+
self: Presence;
|
|
54
|
+
}>;
|
|
55
|
+
static join(authorization: Credentials | ApiKey, target: {
|
|
56
|
+
accessCode: string;
|
|
57
|
+
}, hooks?: ServerHooks): Promise<{
|
|
58
|
+
room: ExplorerRoom;
|
|
59
|
+
self: Presence;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { Magpie } from "./index.js";
|
|
2
|
+
import { Room, connect as connectServer } from "../shared/server.js";
|
|
3
|
+
import { connectRoom } from "../parrot/room.js";
|
|
4
|
+
function entryKey(entry) {
|
|
5
|
+
if (entry.id)
|
|
6
|
+
return entry.id;
|
|
7
|
+
if (entry.asset && entry.ticker)
|
|
8
|
+
return `${entry.asset}:${entry.ticker}`;
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
export class PortfolioRoom extends Room {
|
|
12
|
+
constructor(endpoint, ws, authorization, id) {
|
|
13
|
+
super(endpoint, ws, authorization, id);
|
|
14
|
+
Object.defineProperty(this, "portfolioId", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "name", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "profile", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
});
|
|
32
|
+
this.portfolioId = id;
|
|
33
|
+
this.name = "";
|
|
34
|
+
this.profile = new Map();
|
|
35
|
+
}
|
|
36
|
+
hydrate(state) {
|
|
37
|
+
this.portfolioId = state?.id ?? this.portfolioId;
|
|
38
|
+
this.name = state?.name ?? this.name;
|
|
39
|
+
this.profile.clear();
|
|
40
|
+
for (const entry of state?.profile ?? []) {
|
|
41
|
+
const key = entryKey(entry);
|
|
42
|
+
if (key)
|
|
43
|
+
this.profile.set(key, entry);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
handleEvent(packet) {
|
|
47
|
+
switch (packet.event) {
|
|
48
|
+
case "upsert-entry": {
|
|
49
|
+
const entry = packet.entry ?? packet.data?.entry;
|
|
50
|
+
const key = entry ? entryKey(entry) : "";
|
|
51
|
+
if (key)
|
|
52
|
+
this.profile.set(key, entry);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case "remove-entry": {
|
|
56
|
+
const id = packet.id ?? packet.data?.id;
|
|
57
|
+
if (id)
|
|
58
|
+
this.profile.delete(id);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case "update-portfolio": {
|
|
62
|
+
const portfolio = packet.portfolio ?? packet.data?.portfolio;
|
|
63
|
+
if (portfolio?.name)
|
|
64
|
+
this.name = portfolio.name;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async getChat(hooks) {
|
|
70
|
+
const auth = this.authorization;
|
|
71
|
+
const response = await fetch(`${Magpie.getURL()}/magpie/portfolio/chat/ensure`, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: {
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
Authorization: "email" in auth.authorization ? `Token ${auth.authorization.token}` : `ApiKey ${auth.authorization.id}`,
|
|
76
|
+
...("accessCode" in auth
|
|
77
|
+
? { "Access-Code": auth.accessCode }
|
|
78
|
+
: { Server: this.portfolioId, ...(auth.group ? { Group: auth.group } : {}) }),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
if (!response.ok)
|
|
82
|
+
throw new Error(await response.text());
|
|
83
|
+
const { chatId, reference, code } = await response.json();
|
|
84
|
+
if (!chatId || !code)
|
|
85
|
+
throw new Error("Invalid ensure response.");
|
|
86
|
+
const guest = "accessCode" in this.authorization;
|
|
87
|
+
const target = guest
|
|
88
|
+
? { code }
|
|
89
|
+
: { reference: reference || `parrot:chat:${chatId}` };
|
|
90
|
+
const { room, self } = await connectRoom(this.authorization.authorization, target, hooks ?? {});
|
|
91
|
+
return { room, self, chatId };
|
|
92
|
+
}
|
|
93
|
+
static async connect(authorization, target, opts) {
|
|
94
|
+
const server = opts?.server ?? target.id;
|
|
95
|
+
let room;
|
|
96
|
+
const user = opts?.hooks ?? {};
|
|
97
|
+
const self = await connectServer({ authorization, server, ...(opts?.group ? { group: opts.group.id } : {}) }, `${Magpie.getURL()}/magpie/portfolio`, {
|
|
98
|
+
...user,
|
|
99
|
+
createRoom: (endpoint, ws, a, id, state) => {
|
|
100
|
+
room = (user.createRoom?.(endpoint, ws, a, id, state)
|
|
101
|
+
?? new PortfolioRoom(endpoint, ws, a, id));
|
|
102
|
+
return room;
|
|
103
|
+
},
|
|
104
|
+
onConnection: (r, state) => {
|
|
105
|
+
r.hydrate(state);
|
|
106
|
+
user.onConnection?.(r, state);
|
|
107
|
+
},
|
|
108
|
+
onEvent: (r, packet) => applyPortfolioEvent(r, packet, user),
|
|
109
|
+
});
|
|
110
|
+
return { room, self };
|
|
111
|
+
}
|
|
112
|
+
static async join(authorization, target, hooks) {
|
|
113
|
+
let room;
|
|
114
|
+
const user = hooks ?? {};
|
|
115
|
+
const self = await connectServer({ authorization, accessCode: target.accessCode }, `${Magpie.getURL()}/magpie/portfolio`, {
|
|
116
|
+
...user,
|
|
117
|
+
createRoom: (endpoint, ws, a, id, state) => {
|
|
118
|
+
room = (user.createRoom?.(endpoint, ws, a, id, state)
|
|
119
|
+
?? new PortfolioRoom(endpoint, ws, a, id));
|
|
120
|
+
return room;
|
|
121
|
+
},
|
|
122
|
+
onConnection: (r, state) => {
|
|
123
|
+
r.hydrate(state);
|
|
124
|
+
user.onConnection?.(r, state);
|
|
125
|
+
},
|
|
126
|
+
onEvent: (r, packet) => applyPortfolioEvent(r, packet, user),
|
|
127
|
+
});
|
|
128
|
+
return { room, self };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function applyPortfolioEvent(room, packet, user) {
|
|
132
|
+
room.handleEvent(packet);
|
|
133
|
+
return user.onEvent?.(room, packet) ?? true;
|
|
134
|
+
}
|
|
135
|
+
function explorerKey(entry) {
|
|
136
|
+
if (!entry.asset || !entry.ticker)
|
|
137
|
+
return "";
|
|
138
|
+
return `${entry.asset}:${entry.ticker}`;
|
|
139
|
+
}
|
|
140
|
+
export class ExplorerRoom extends Room {
|
|
141
|
+
constructor(endpoint, ws, authorization, id) {
|
|
142
|
+
super(endpoint, ws, authorization, id);
|
|
143
|
+
Object.defineProperty(this, "host", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: void 0
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(this, "entries", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
configurable: true,
|
|
152
|
+
writable: true,
|
|
153
|
+
value: void 0
|
|
154
|
+
});
|
|
155
|
+
this.host = id;
|
|
156
|
+
this.entries = new Map();
|
|
157
|
+
}
|
|
158
|
+
hydrate(state) {
|
|
159
|
+
this.host = state?.host ?? this.host;
|
|
160
|
+
this.entries.clear();
|
|
161
|
+
for (const entry of state?.entries ?? []) {
|
|
162
|
+
const key = explorerKey(entry);
|
|
163
|
+
if (key)
|
|
164
|
+
this.entries.set(key, entry);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
handleEvent(packet) {
|
|
168
|
+
switch (packet.event) {
|
|
169
|
+
case "upsert-entry": {
|
|
170
|
+
const entry = packet.entry ?? packet.data?.entry;
|
|
171
|
+
const key = entry ? explorerKey(entry) : "";
|
|
172
|
+
if (key)
|
|
173
|
+
this.entries.set(key, entry);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case "remove-entry": {
|
|
177
|
+
const ticker = packet.ticker ?? packet.data?.ticker;
|
|
178
|
+
const asset = packet.asset ?? packet.data?.asset;
|
|
179
|
+
const key = explorerKey({ ticker, asset });
|
|
180
|
+
if (key)
|
|
181
|
+
this.entries.delete(key);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
setTicker(asset, ticker) {
|
|
187
|
+
this.post({ event: "set-ticker", asset, ticker });
|
|
188
|
+
}
|
|
189
|
+
commitDrawing(explorer) {
|
|
190
|
+
this.post({ event: "draw-commit", explorer });
|
|
191
|
+
}
|
|
192
|
+
clearDrawings(asset, ticker) {
|
|
193
|
+
this.post({ event: "draw-clear", asset, ticker });
|
|
194
|
+
}
|
|
195
|
+
static async connect(authorization, opts) {
|
|
196
|
+
// "me" is resolved on the edge to the caller's credentials principal.
|
|
197
|
+
// Client Credentials has no server id.
|
|
198
|
+
const server = opts?.server ?? "me";
|
|
199
|
+
let room;
|
|
200
|
+
const user = opts?.hooks ?? {};
|
|
201
|
+
const self = await connectServer({ authorization, server }, `${Magpie.getURL()}/magpie/explorer`, {
|
|
202
|
+
...user,
|
|
203
|
+
createRoom: (endpoint, ws, a, id, state) => {
|
|
204
|
+
room = (user.createRoom?.(endpoint, ws, a, id, state)
|
|
205
|
+
?? new ExplorerRoom(endpoint, ws, a, id));
|
|
206
|
+
return room;
|
|
207
|
+
},
|
|
208
|
+
onConnection: (r, state) => {
|
|
209
|
+
r.hydrate(state);
|
|
210
|
+
user.onConnection?.(r, state);
|
|
211
|
+
},
|
|
212
|
+
onEvent: (r, packet) => applyExplorerEvent(r, packet, user),
|
|
213
|
+
});
|
|
214
|
+
return { room, self };
|
|
215
|
+
}
|
|
216
|
+
static async join(authorization, target, hooks) {
|
|
217
|
+
let room;
|
|
218
|
+
const user = hooks ?? {};
|
|
219
|
+
const self = await connectServer({ authorization, accessCode: target.accessCode }, `${Magpie.getURL()}/magpie/explorer`, {
|
|
220
|
+
...user,
|
|
221
|
+
createRoom: (endpoint, ws, a, id, state) => {
|
|
222
|
+
room = (user.createRoom?.(endpoint, ws, a, id, state)
|
|
223
|
+
?? new ExplorerRoom(endpoint, ws, a, id));
|
|
224
|
+
return room;
|
|
225
|
+
},
|
|
226
|
+
onConnection: (r, state) => {
|
|
227
|
+
r.hydrate(state);
|
|
228
|
+
user.onConnection?.(r, state);
|
|
229
|
+
},
|
|
230
|
+
onEvent: (r, packet) => applyExplorerEvent(r, packet, user),
|
|
231
|
+
});
|
|
232
|
+
return { room, self };
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function applyExplorerEvent(room, packet, user) {
|
|
236
|
+
room.handleEvent(packet);
|
|
237
|
+
return user.onEvent?.(room, packet) ?? true;
|
|
238
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Credentials, ApiKey } from "./authentification.js";
|
|
2
|
+
import type { Group } from "./groups.js";
|
|
3
|
+
export type Coordinates = {
|
|
4
|
+
latitude: number;
|
|
5
|
+
longitude: number;
|
|
6
|
+
};
|
|
7
|
+
/** A place to start or end at: coordinates, an address, or a place id. Set one. */
|
|
8
|
+
export type Waypoint = {
|
|
9
|
+
coordinates?: Coordinates;
|
|
10
|
+
address?: string;
|
|
11
|
+
place?: string;
|
|
12
|
+
};
|
|
13
|
+
export type Place = {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
address: string;
|
|
17
|
+
coordinates: Coordinates;
|
|
18
|
+
};
|
|
19
|
+
/** One autocomplete match. `place` resolves through `geocode({ place })`. */
|
|
20
|
+
export type Suggestion = {
|
|
21
|
+
place: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
export type TravelMode = 'drive' | 'walk' | 'transit' | 'flight';
|
|
26
|
+
export type Money = {
|
|
27
|
+
amount: number;
|
|
28
|
+
currency: string;
|
|
29
|
+
};
|
|
30
|
+
/** One instruction along a route. Transit steps also carry the line, stops and times. */
|
|
31
|
+
export type Step = {
|
|
32
|
+
mode: TravelMode;
|
|
33
|
+
instruction: string;
|
|
34
|
+
/** Meters. */
|
|
35
|
+
distance: number;
|
|
36
|
+
/** Seconds. */
|
|
37
|
+
duration: number;
|
|
38
|
+
line?: string;
|
|
39
|
+
vehicle?: string;
|
|
40
|
+
stops?: number;
|
|
41
|
+
from?: string;
|
|
42
|
+
to?: string;
|
|
43
|
+
departure?: Date;
|
|
44
|
+
arrival?: Date;
|
|
45
|
+
};
|
|
46
|
+
export type Route = {
|
|
47
|
+
mode: TravelMode;
|
|
48
|
+
/** Seconds. */
|
|
49
|
+
duration: number;
|
|
50
|
+
/** Meters. */
|
|
51
|
+
distance: number;
|
|
52
|
+
path: Coordinates[];
|
|
53
|
+
steps: Step[];
|
|
54
|
+
fare?: Money;
|
|
55
|
+
departure?: Date;
|
|
56
|
+
arrival?: Date;
|
|
57
|
+
};
|
|
58
|
+
export type Airport = {
|
|
59
|
+
code: string;
|
|
60
|
+
name: string;
|
|
61
|
+
city: string;
|
|
62
|
+
country: string;
|
|
63
|
+
coordinates: Coordinates;
|
|
64
|
+
/** Meters from the point searched. */
|
|
65
|
+
distance: number;
|
|
66
|
+
large: boolean;
|
|
67
|
+
};
|
|
68
|
+
export type Units = 'metric' | 'imperial';
|
|
69
|
+
export type Condition = 'clear' | 'partly_cloudy' | 'cloudy' | 'fog' | 'rain' | 'showers' | 'thunderstorm' | 'snow' | 'sleet' | 'hail' | 'wind' | 'unknown';
|
|
70
|
+
export type ForecastDay = {
|
|
71
|
+
/** The local date, YYYY-MM-DD. */
|
|
72
|
+
date: string;
|
|
73
|
+
high: number;
|
|
74
|
+
low: number;
|
|
75
|
+
condition: Condition;
|
|
76
|
+
summary: string;
|
|
77
|
+
/** Chance of precipitation, 0 to 100. */
|
|
78
|
+
precipitation: number;
|
|
79
|
+
wind: number;
|
|
80
|
+
sunrise?: Date;
|
|
81
|
+
sunset?: Date;
|
|
82
|
+
};
|
|
83
|
+
export type ForecastHour = {
|
|
84
|
+
time: Date;
|
|
85
|
+
temperature: number;
|
|
86
|
+
feelsLike: number;
|
|
87
|
+
condition: Condition;
|
|
88
|
+
summary: string;
|
|
89
|
+
precipitation: number;
|
|
90
|
+
wind: number;
|
|
91
|
+
};
|
|
92
|
+
/** Temperatures in °C and wind in km/h for metric, °F and mph for imperial. */
|
|
93
|
+
export type Forecast = {
|
|
94
|
+
units: Units;
|
|
95
|
+
timeZone: string;
|
|
96
|
+
days: ForecastDay[];
|
|
97
|
+
hours: ForecastHour[];
|
|
98
|
+
};
|
|
99
|
+
export type MapTheme = 'light' | 'dark';
|
|
100
|
+
/** What a map must show while its tiles are on screen. */
|
|
101
|
+
export type Attribution = {
|
|
102
|
+
text: string;
|
|
103
|
+
logo: string;
|
|
104
|
+
};
|
|
105
|
+
/** Prepaid map tiles. The pass id is all a tile request needs, so map libraries can fetch tiles directly. */
|
|
106
|
+
export type TilePass = {
|
|
107
|
+
id: string;
|
|
108
|
+
tiles: number;
|
|
109
|
+
expires: Date;
|
|
110
|
+
size: number;
|
|
111
|
+
maxZoom: number;
|
|
112
|
+
attribution: Attribution;
|
|
113
|
+
};
|
|
114
|
+
export type Bounds = {
|
|
115
|
+
north: number;
|
|
116
|
+
south: number;
|
|
117
|
+
east: number;
|
|
118
|
+
west: number;
|
|
119
|
+
};
|
|
120
|
+
/** Find places for an address, coordinates (reverse lookup) or a place id. */
|
|
121
|
+
export declare function geocode(authorization: Credentials | ApiKey, query: Waypoint, group?: Group): Promise<Place[]>;
|
|
122
|
+
export declare function searchPlaces(authorization: Credentials | ApiKey, text: string, options?: {
|
|
123
|
+
near?: Coordinates;
|
|
124
|
+
radius?: number;
|
|
125
|
+
max?: number;
|
|
126
|
+
}, group?: Group): Promise<Place[]>;
|
|
127
|
+
export declare function autocomplete(authorization: Credentials | ApiKey, text: string, options?: {
|
|
128
|
+
near?: Coordinates;
|
|
129
|
+
}, group?: Group): Promise<Suggestion[]>;
|
|
130
|
+
/** Drive, walk and transit routes between two waypoints, one per mode that has one. Flights come from Travel. */
|
|
131
|
+
export declare function getRoutes(authorization: Credentials | ApiKey, from: Waypoint, to: Waypoint, options?: {
|
|
132
|
+
modes?: TravelMode[];
|
|
133
|
+
departure?: Date;
|
|
134
|
+
arrival?: Date;
|
|
135
|
+
}, group?: Group): Promise<Route[]>;
|
|
136
|
+
/** The nearest airports with scheduled flights, closest first. Free. */
|
|
137
|
+
export declare function getAirports(authorization: Credentials | ApiKey, near: Coordinates, options?: {
|
|
138
|
+
max?: number;
|
|
139
|
+
large?: boolean;
|
|
140
|
+
}): Promise<Airport[]>;
|
|
141
|
+
/** Daily (up to 10) and hourly (up to 240) forecasts for a point. */
|
|
142
|
+
export declare function getWeather(authorization: Credentials | ApiKey, at: Coordinates, options?: {
|
|
143
|
+
days?: number;
|
|
144
|
+
hours?: number;
|
|
145
|
+
units?: Units;
|
|
146
|
+
}, group?: Group): Promise<Forecast>;
|
|
147
|
+
/** Buy a pass for `tiles` map tiles (default 150). Tiles are billed up front, when the pass is bought. */
|
|
148
|
+
export declare function createTilePass(authorization: Credentials | ApiKey, options?: {
|
|
149
|
+
theme?: MapTheme;
|
|
150
|
+
tiles?: number;
|
|
151
|
+
language?: string;
|
|
152
|
+
region?: string;
|
|
153
|
+
}, group?: Group): Promise<TilePass>;
|
|
154
|
+
/** A tile URL template with `{z}`, `{x}` and `{y}` left in, the way map libraries take them. */
|
|
155
|
+
export declare function getTileURL(pass: TilePass): string;
|
|
156
|
+
/** One map tile image, read as it streams in. */
|
|
157
|
+
export declare function getTile(pass: TilePass, z: number, x: number, y: number, onLoaded?: (loadedBytes: number) => void): Promise<Uint8Array>;
|
|
158
|
+
/** The attribution for what a map shows right now. Free; call it as the view moves. */
|
|
159
|
+
export declare function getAttribution(pass: TilePass, zoom: number, bounds: Bounds): Promise<Attribution>;
|
package/dist/src/maps.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Fauna } from "../index.js";
|
|
2
|
+
/** Find places for an address, coordinates (reverse lookup) or a place id. */
|
|
3
|
+
export async function geocode(authorization, query, group) {
|
|
4
|
+
const response = await fetch(`${Fauna.getURL()}/maps/geocode`, {
|
|
5
|
+
method: "POST",
|
|
6
|
+
headers: {
|
|
7
|
+
"Content-Type": "application/json",
|
|
8
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
9
|
+
...(group ? { "Group": group.id } : {})
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify({ query })
|
|
12
|
+
});
|
|
13
|
+
if (!response.ok)
|
|
14
|
+
throw new Error(await response.text());
|
|
15
|
+
return await response.json();
|
|
16
|
+
}
|
|
17
|
+
export async function searchPlaces(authorization, text, options = {}, group) {
|
|
18
|
+
const response = await fetch(`${Fauna.getURL()}/maps/places/search`, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
23
|
+
...(group ? { "Group": group.id } : {})
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({ text, near: options.near, radius: options.radius, max: options.max })
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok)
|
|
28
|
+
throw new Error(await response.text());
|
|
29
|
+
return await response.json();
|
|
30
|
+
}
|
|
31
|
+
export async function autocomplete(authorization, text, options = {}, group) {
|
|
32
|
+
const response = await fetch(`${Fauna.getURL()}/maps/places/autocomplete`, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers: {
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
37
|
+
...(group ? { "Group": group.id } : {})
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify({ text, near: options.near })
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok)
|
|
42
|
+
throw new Error(await response.text());
|
|
43
|
+
return await response.json();
|
|
44
|
+
}
|
|
45
|
+
/** Drive, walk and transit routes between two waypoints, one per mode that has one. Flights come from Travel. */
|
|
46
|
+
export async function getRoutes(authorization, from, to, options = {}, group) {
|
|
47
|
+
const response = await fetch(`${Fauna.getURL()}/maps/routes`, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
52
|
+
...(group ? { "Group": group.id } : {})
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({ from, to, modes: options.modes, departure: options.departure, arrival: options.arrival })
|
|
55
|
+
});
|
|
56
|
+
if (!response.ok)
|
|
57
|
+
throw new Error(await response.text());
|
|
58
|
+
const routes = await response.json();
|
|
59
|
+
return routes.map((route) => ({
|
|
60
|
+
...route,
|
|
61
|
+
departure: route.departure ? new Date(route.departure) : undefined,
|
|
62
|
+
arrival: route.arrival ? new Date(route.arrival) : undefined,
|
|
63
|
+
steps: route.steps.map((step) => ({
|
|
64
|
+
...step,
|
|
65
|
+
departure: step.departure ? new Date(step.departure) : undefined,
|
|
66
|
+
arrival: step.arrival ? new Date(step.arrival) : undefined,
|
|
67
|
+
})),
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
/** The nearest airports with scheduled flights, closest first. Free. */
|
|
71
|
+
export async function getAirports(authorization, near, options = {}) {
|
|
72
|
+
const response = await fetch(`${Fauna.getURL()}/maps/airports`, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: {
|
|
75
|
+
"Content-Type": "application/json",
|
|
76
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify({ near, max: options.max, large: options.large })
|
|
79
|
+
});
|
|
80
|
+
if (!response.ok)
|
|
81
|
+
throw new Error(await response.text());
|
|
82
|
+
return await response.json();
|
|
83
|
+
}
|
|
84
|
+
/** Daily (up to 10) and hourly (up to 240) forecasts for a point. */
|
|
85
|
+
export async function getWeather(authorization, at, options = {}, group) {
|
|
86
|
+
const response = await fetch(`${Fauna.getURL()}/maps/weather`, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers: {
|
|
89
|
+
"Content-Type": "application/json",
|
|
90
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
91
|
+
...(group ? { "Group": group.id } : {})
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify({ at, days: options.days, hours: options.hours, units: options.units })
|
|
94
|
+
});
|
|
95
|
+
if (!response.ok)
|
|
96
|
+
throw new Error(await response.text());
|
|
97
|
+
const forecast = await response.json();
|
|
98
|
+
return {
|
|
99
|
+
...forecast,
|
|
100
|
+
days: forecast.days.map((day) => ({
|
|
101
|
+
...day,
|
|
102
|
+
sunrise: day.sunrise ? new Date(day.sunrise) : undefined,
|
|
103
|
+
sunset: day.sunset ? new Date(day.sunset) : undefined,
|
|
104
|
+
})),
|
|
105
|
+
hours: forecast.hours.map((hour) => ({ ...hour, time: new Date(hour.time) })),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** Buy a pass for `tiles` map tiles (default 150). Tiles are billed up front, when the pass is bought. */
|
|
109
|
+
export async function createTilePass(authorization, options = {}, group) {
|
|
110
|
+
const response = await fetch(`${Fauna.getURL()}/maps/tiles/pass`, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: {
|
|
113
|
+
"Content-Type": "application/json",
|
|
114
|
+
"Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
|
|
115
|
+
...(group ? { "Group": group.id } : {})
|
|
116
|
+
},
|
|
117
|
+
body: JSON.stringify({ theme: options.theme, tiles: options.tiles, language: options.language, region: options.region })
|
|
118
|
+
});
|
|
119
|
+
if (!response.ok)
|
|
120
|
+
throw new Error(await response.text());
|
|
121
|
+
const pass = await response.json();
|
|
122
|
+
return { ...pass, expires: new Date(pass.expires) };
|
|
123
|
+
}
|
|
124
|
+
/** A tile URL template with `{z}`, `{x}` and `{y}` left in, the way map libraries take them. */
|
|
125
|
+
export function getTileURL(pass) {
|
|
126
|
+
return `${Fauna.getURL()}/maps/tile?pass=${encodeURIComponent(pass.id)}&z={z}&x={x}&y={y}`;
|
|
127
|
+
}
|
|
128
|
+
/** One map tile image, read as it streams in. */
|
|
129
|
+
export async function getTile(pass, z, x, y, onLoaded) {
|
|
130
|
+
const response = await fetch(`${Fauna.getURL()}/maps/tile?pass=${encodeURIComponent(pass.id)}&z=${z}&x=${x}&y=${y}`, {
|
|
131
|
+
method: "GET"
|
|
132
|
+
});
|
|
133
|
+
if (!response.ok)
|
|
134
|
+
throw new Error(await response.text());
|
|
135
|
+
const reader = response.body.getReader();
|
|
136
|
+
let buffer = new Uint8Array(0);
|
|
137
|
+
let loaded = 0;
|
|
138
|
+
while (true) {
|
|
139
|
+
const { done, value } = await reader.read();
|
|
140
|
+
if (done)
|
|
141
|
+
break;
|
|
142
|
+
if (value) {
|
|
143
|
+
const tmp = new Uint8Array(buffer.length + value.length);
|
|
144
|
+
tmp.set(buffer, 0);
|
|
145
|
+
tmp.set(value, buffer.length);
|
|
146
|
+
buffer = tmp;
|
|
147
|
+
loaded += value.length;
|
|
148
|
+
if (onLoaded) {
|
|
149
|
+
onLoaded(loaded);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return buffer;
|
|
154
|
+
}
|
|
155
|
+
/** The attribution for what a map shows right now. Free; call it as the view moves. */
|
|
156
|
+
export async function getAttribution(pass, zoom, bounds) {
|
|
157
|
+
const query = new URLSearchParams({
|
|
158
|
+
pass: pass.id,
|
|
159
|
+
zoom: String(zoom),
|
|
160
|
+
north: String(bounds.north),
|
|
161
|
+
south: String(bounds.south),
|
|
162
|
+
east: String(bounds.east),
|
|
163
|
+
west: String(bounds.west),
|
|
164
|
+
});
|
|
165
|
+
const response = await fetch(`${Fauna.getURL()}/maps/tiles/attribution?${query}`, {
|
|
166
|
+
method: "GET"
|
|
167
|
+
});
|
|
168
|
+
if (!response.ok)
|
|
169
|
+
throw new Error(await response.text());
|
|
170
|
+
return await response.json();
|
|
171
|
+
}
|