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.
Files changed (171) hide show
  1. package/dist/brands.d.ts +2 -0
  2. package/dist/brands.js +2 -0
  3. package/dist/index.d.ts +64 -0
  4. package/dist/index.js +121 -0
  5. package/dist/src/ant/chat.d.ts +130 -0
  6. package/dist/src/ant/chat.js +467 -0
  7. package/dist/src/ant/format.d.ts +40 -0
  8. package/dist/src/ant/format.js +143 -0
  9. package/dist/src/ant/graph.d.ts +130 -0
  10. package/dist/src/ant/graph.js +449 -0
  11. package/dist/src/ant/index.d.ts +16 -0
  12. package/dist/src/ant/index.js +61 -0
  13. package/dist/src/ant/persona.d.ts +151 -0
  14. package/dist/src/ant/persona.js +136 -0
  15. package/dist/src/ant/timeline.d.ts +283 -0
  16. package/dist/src/ant/timeline.js +1025 -0
  17. package/dist/src/authentification.d.ts +45 -0
  18. package/dist/src/authentification.js +194 -0
  19. package/dist/src/billing.d.ts +135 -0
  20. package/dist/src/billing.js +128 -0
  21. package/dist/src/calendar.d.ts +83 -0
  22. package/dist/src/calendar.js +133 -0
  23. package/dist/src/chats.d.ts +113 -0
  24. package/dist/src/chats.js +100 -0
  25. package/dist/src/cicada/contacts.d.ts +31 -0
  26. package/dist/src/cicada/contacts.js +28 -0
  27. package/dist/src/cicada/conversations.d.ts +73 -0
  28. package/dist/src/cicada/conversations.js +236 -0
  29. package/dist/src/cicada/inboxes.d.ts +48 -0
  30. package/dist/src/cicada/inboxes.js +82 -0
  31. package/dist/src/cicada/index.d.ts +16 -0
  32. package/dist/src/cicada/index.js +61 -0
  33. package/dist/src/cicada/phone.d.ts +48 -0
  34. package/dist/src/cicada/phone.js +306 -0
  35. package/dist/src/drive.d.ts +80 -0
  36. package/dist/src/drive.js +472 -0
  37. package/dist/src/extensions/index.d.ts +4 -0
  38. package/dist/src/extensions/index.js +5 -0
  39. package/dist/src/extensions/web/index.d.ts +6 -0
  40. package/dist/src/extensions/web/index.js +7 -0
  41. package/dist/src/extensions/web/session.d.ts +108 -0
  42. package/dist/src/extensions/web/session.js +470 -0
  43. package/dist/src/extensions/web/tools.d.ts +13 -0
  44. package/dist/src/extensions/web/tools.js +72 -0
  45. package/dist/src/friends.d.ts +39 -0
  46. package/dist/src/friends.js +119 -0
  47. package/dist/src/groups.d.ts +82 -0
  48. package/dist/src/groups.js +269 -0
  49. package/dist/src/inbox.d.ts +11 -0
  50. package/dist/src/inbox.js +35 -0
  51. package/dist/src/integrations.d.ts +52 -0
  52. package/dist/src/integrations.js +205 -0
  53. package/dist/src/magpie/explorer.d.ts +14 -0
  54. package/dist/src/magpie/explorer.js +36 -0
  55. package/dist/src/magpie/index.d.ts +16 -0
  56. package/dist/src/magpie/index.js +61 -0
  57. package/dist/src/magpie/portfolio.d.ts +52 -0
  58. package/dist/src/magpie/portfolio.js +179 -0
  59. package/dist/src/magpie/quotes.d.ts +35 -0
  60. package/dist/src/magpie/quotes.js +47 -0
  61. package/dist/src/magpie/room.d.ts +61 -0
  62. package/dist/src/magpie/room.js +238 -0
  63. package/dist/src/maps.d.ts +159 -0
  64. package/dist/src/maps.js +171 -0
  65. package/dist/src/marmot/browser.d.ts +139 -0
  66. package/dist/src/marmot/browser.js +389 -0
  67. package/dist/src/marmot/index.d.ts +20 -0
  68. package/dist/src/marmot/index.js +65 -0
  69. package/dist/src/marmot/media.d.ts +56 -0
  70. package/dist/src/marmot/media.js +265 -0
  71. package/dist/src/marmot/research.d.ts +337 -0
  72. package/dist/src/marmot/research.js +1138 -0
  73. package/dist/src/marmot/scraper.d.ts +59 -0
  74. package/dist/src/marmot/scraper.js +94 -0
  75. package/dist/src/marmot/web.d.ts +402 -0
  76. package/dist/src/marmot/web.js +2586 -0
  77. package/dist/src/marmot/workspace.d.ts +81 -0
  78. package/dist/src/marmot/workspace.js +263 -0
  79. package/dist/src/parrot/agent.d.ts +53 -0
  80. package/dist/src/parrot/agent.js +93 -0
  81. package/dist/src/parrot/chat.d.ts +84 -0
  82. package/dist/src/parrot/chat.js +237 -0
  83. package/dist/src/parrot/format.d.ts +128 -0
  84. package/dist/src/parrot/format.js +639 -0
  85. package/dist/src/parrot/generative.d.ts +261 -0
  86. package/dist/src/parrot/generative.js +185 -0
  87. package/dist/src/parrot/index.d.ts +22 -0
  88. package/dist/src/parrot/index.js +67 -0
  89. package/dist/src/parrot/room.d.ts +225 -0
  90. package/dist/src/parrot/room.js +466 -0
  91. package/dist/src/parrot/routing.d.ts +90 -0
  92. package/dist/src/parrot/routing.js +78 -0
  93. package/dist/src/parrot/share.d.ts +126 -0
  94. package/dist/src/parrot/share.js +261 -0
  95. package/dist/src/parrot/socket.d.ts +41 -0
  96. package/dist/src/parrot/socket.js +478 -0
  97. package/dist/src/payments.d.ts +73 -0
  98. package/dist/src/payments.js +107 -0
  99. package/dist/src/private/cards.css +75 -0
  100. package/dist/src/rooms.d.ts +76 -0
  101. package/dist/src/rooms.js +168 -0
  102. package/dist/src/shared/schema.d.ts +24 -0
  103. package/dist/src/shared/schema.js +1 -0
  104. package/dist/src/shared/server.d.ts +65 -0
  105. package/dist/src/shared/server.js +302 -0
  106. package/dist/src/termite/environment.d.ts +110 -0
  107. package/dist/src/termite/environment.js +263 -0
  108. package/dist/src/termite/index.d.ts +14 -0
  109. package/dist/src/termite/index.js +59 -0
  110. package/dist/src/termite/os.d.ts +326 -0
  111. package/dist/src/termite/os.js +572 -0
  112. package/dist/src/termite/versioning.d.ts +94 -0
  113. package/dist/src/termite/versioning.js +217 -0
  114. package/dist/src/tickets.d.ts +43 -0
  115. package/dist/src/tickets.js +138 -0
  116. package/dist/src/travel.d.ts +85 -0
  117. package/dist/src/travel.js +44 -0
  118. package/dist/src/ui/authentification.d.ts +24 -0
  119. package/dist/src/ui/authentification.js +177 -0
  120. package/dist/src/ui/brands.css +11 -0
  121. package/dist/src/ui/brands.d.ts +7 -0
  122. package/dist/src/ui/brands.js +14 -0
  123. package/dist/src/ui/browser.d.ts +74 -0
  124. package/dist/src/ui/browser.js +470 -0
  125. package/dist/src/ui/chat.d.ts +183 -0
  126. package/dist/src/ui/chat.js +2379 -0
  127. package/dist/src/ui/chatPanel.d.ts +109 -0
  128. package/dist/src/ui/chatPanel.js +768 -0
  129. package/dist/src/ui/chatSequence.d.ts +36 -0
  130. package/dist/src/ui/chatSequence.js +42 -0
  131. package/dist/src/ui/crown.d.ts +19 -0
  132. package/dist/src/ui/crown.js +199 -0
  133. package/dist/src/ui/cursor.d.ts +73 -0
  134. package/dist/src/ui/cursor.js +175 -0
  135. package/dist/src/ui/device.d.ts +33 -0
  136. package/dist/src/ui/device.js +49 -0
  137. package/dist/src/ui/drive.d.ts +69 -0
  138. package/dist/src/ui/drive.js +1243 -0
  139. package/dist/src/ui/generative.d.ts +39 -0
  140. package/dist/src/ui/generative.js +313 -0
  141. package/dist/src/ui/hover.d.ts +6 -0
  142. package/dist/src/ui/hover.js +210 -0
  143. package/dist/src/ui/index.d.ts +42 -0
  144. package/dist/src/ui/index.js +87 -0
  145. package/dist/src/ui/integrations.d.ts +13 -0
  146. package/dist/src/ui/integrations.js +175 -0
  147. package/dist/src/ui/maps.d.ts +87 -0
  148. package/dist/src/ui/maps.js +547 -0
  149. package/dist/src/ui/roster.d.ts +32 -0
  150. package/dist/src/ui/roster.js +163 -0
  151. package/dist/src/ui/talk.d.ts +12 -0
  152. package/dist/src/ui/talk.js +560 -0
  153. package/dist/src/ui/tickets.d.ts +13 -0
  154. package/dist/src/ui/tickets.js +966 -0
  155. package/dist/src/ui/toast.d.ts +7 -0
  156. package/dist/src/ui/toast.js +258 -0
  157. package/dist/src/ui/tokenText.d.ts +18 -0
  158. package/dist/src/ui/tokenText.js +96 -0
  159. package/dist/src/ui/tokenized.d.ts +42 -0
  160. package/dist/src/ui/tokenized.js +622 -0
  161. package/dist/src/ui/ui.css +4763 -0
  162. package/dist/src/ui/view.d.ts +23 -0
  163. package/dist/src/ui/view.js +584 -0
  164. package/dist/src/view.d.ts +113 -0
  165. package/dist/src/view.js +386 -0
  166. package/dist/src/webhooks.d.ts +66 -0
  167. package/dist/src/webhooks.js +78 -0
  168. package/dist/ui.d.ts +1 -0
  169. package/dist/ui.js +1 -0
  170. package/package.json +87 -4
  171. package/README.md +0 -3
@@ -0,0 +1,217 @@
1
+ import { File, parseStream } from "../drive.js";
2
+ import { mimeFromFileName } from "../marmot/media.js";
3
+ import { Termite } from "./index.js";
4
+ export const Change = {
5
+ fromJSON(json) {
6
+ return {
7
+ revision: Number(json.revision),
8
+ ...(json.rollback ? { rollback: Number(json.rollback) } : {}),
9
+ head: String(json.head ?? ""),
10
+ lines: Array.isArray(json.lines) ? json.lines : [],
11
+ date: new Date(json.date),
12
+ };
13
+ },
14
+ };
15
+ /**
16
+ * A saved machine: a numbered, principal owned chain of disk revisions on the
17
+ * one Termite base image. `/repository` inside it is a git folder whose history
18
+ * is `changes()`. Start it with `OS.MachineRoom.start`.
19
+ */
20
+ export class Repository {
21
+ constructor(authorization, row, group) {
22
+ Object.defineProperty(this, "id", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ Object.defineProperty(this, "name", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: void 0
33
+ });
34
+ Object.defineProperty(this, "sizeBytes", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: void 0
39
+ });
40
+ Object.defineProperty(this, "createdAt", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: void 0
45
+ });
46
+ Object.defineProperty(this, "updatedAt", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: void 0
51
+ });
52
+ /** Its machine while one is booting, running, or saving. */
53
+ Object.defineProperty(this, "machine", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ /** The group that owns it, when it isn't personal. */
60
+ Object.defineProperty(this, "group", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ Object.defineProperty(this, "authorization", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
72
+ this.authorization = authorization;
73
+ this.group = group;
74
+ this.id = row.id;
75
+ this.name = row.name;
76
+ this.sizeBytes = row.sizeBytes;
77
+ this.createdAt = row.createdAt;
78
+ this.updatedAt = row.updatedAt;
79
+ this.machine = row.machine;
80
+ }
81
+ static fromJSON(json, authorization, group) {
82
+ return new Repository(authorization, {
83
+ id: Number(json.id),
84
+ name: json.name ?? "",
85
+ sizeBytes: Number(json.sizeBytes ?? 0),
86
+ createdAt: new Date(json.createdAt),
87
+ updatedAt: new Date(json.updatedAt),
88
+ machine: json.machine ? { id: Number(json.machine.id), status: json.machine.status } : null,
89
+ }, group);
90
+ }
91
+ routes() {
92
+ throw new Error("Termite routes are not implemented.");
93
+ }
94
+ /** Revisions newest first. `cursor: 0` is the latest revision. */
95
+ async changes(query) {
96
+ const params = new URLSearchParams({ cursor: String(query.cursor), max: String(query.max) });
97
+ const response = await fetch(`${Termite.getURL()}/termite/repositories/${this.id}/changes?${params}`, {
98
+ method: "GET",
99
+ headers: {
100
+ Authorization: "email" in this.authorization ? `Token ${this.authorization.token}` : `ApiKey ${this.authorization.id}`,
101
+ ...(this.group ? { Group: this.group.id } : {}),
102
+ },
103
+ });
104
+ if (!response.ok)
105
+ throw new Error(await response.text());
106
+ const parsed = await parseStream(response);
107
+ const decoder = new TextDecoder();
108
+ return (Array.isArray(parsed) ? parsed : [parsed])
109
+ .filter((part) => part.length > 0)
110
+ .map((part) => Change.fromJSON(JSON.parse(decoder.decode(part))));
111
+ }
112
+ /** A folder gives one `File` per entry, a file gives its own `File`. Nothing downloads until asked. */
113
+ async open(path = '/') {
114
+ const tail = path.split('/').filter(Boolean).map(encodeURIComponent).join('/');
115
+ const response = await fetch(`${Termite.getURL()}/termite/repositories/${this.id}/files${tail ? `/${tail}` : ''}`, {
116
+ method: "GET",
117
+ headers: {
118
+ Authorization: "email" in this.authorization ? `Token ${this.authorization.token}` : `ApiKey ${this.authorization.id}`,
119
+ ...(this.group ? { Group: this.group.id } : {}),
120
+ },
121
+ });
122
+ if (!response.ok)
123
+ throw new Error(await response.text());
124
+ const json = await response.json();
125
+ return Array.isArray(json)
126
+ ? json.map((entry) => File.fromJSON(entry, { authorization: this.authorization, repository: this.id, path: entry.path, group: this.group?.id }))
127
+ : File.fromJSON(json, { authorization: this.authorization, repository: this.id, path: json.path, group: this.group?.id });
128
+ }
129
+ /** Create or overwrite a file under /repository, running or not. */
130
+ async write(path, data, onProgress) {
131
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
132
+ const name = path.split('/').filter(Boolean).pop() ?? "";
133
+ const now = new Date();
134
+ const file = new File({ authorization: this.authorization, repository: this.id, path, group: this.group?.id }, name, false, mimeFromFileName(name) || "application/octet-stream", bytes.length, now, now, bytes);
135
+ await file.upload(onProgress);
136
+ return file;
137
+ }
138
+ /** Record a new revision whose disk is exactly `revision`'s. Refused while a machine is live. */
139
+ async rollback(revision) {
140
+ const response = await fetch(`${Termite.getURL()}/termite/repositories/${this.id}/rollback`, {
141
+ method: "POST",
142
+ headers: {
143
+ "Content-Type": "application/json",
144
+ Authorization: "email" in this.authorization ? `Token ${this.authorization.token}` : `ApiKey ${this.authorization.id}`,
145
+ ...(this.group ? { Group: this.group.id } : {}),
146
+ },
147
+ body: JSON.stringify({ revision }),
148
+ });
149
+ if (!response.ok)
150
+ throw new Error(await response.text());
151
+ }
152
+ /** Rename it. Returns the repository with its new name. */
153
+ async rename(name) {
154
+ const response = await fetch(`${Termite.getURL()}/termite/repositories/${this.id}`, {
155
+ method: "PATCH",
156
+ headers: {
157
+ "Content-Type": "application/json",
158
+ Authorization: "email" in this.authorization ? `Token ${this.authorization.token}` : `ApiKey ${this.authorization.id}`,
159
+ ...(this.group ? { Group: this.group.id } : {}),
160
+ },
161
+ body: JSON.stringify({ name }),
162
+ });
163
+ if (!response.ok)
164
+ throw new Error(await response.text());
165
+ return Repository.fromJSON(await response.json(), this.authorization, this.group);
166
+ }
167
+ async delete() {
168
+ const response = await fetch(`${Termite.getURL()}/termite/repositories/${this.id}`, {
169
+ method: "DELETE",
170
+ headers: {
171
+ Authorization: "email" in this.authorization ? `Token ${this.authorization.token}` : `ApiKey ${this.authorization.id}`,
172
+ ...(this.group ? { Group: this.group.id } : {}),
173
+ },
174
+ });
175
+ if (!response.ok)
176
+ throw new Error(await response.text());
177
+ }
178
+ }
179
+ export async function create(authorization, opts) {
180
+ const response = await fetch(`${Termite.getURL()}/termite/repositories`, {
181
+ method: "POST",
182
+ headers: {
183
+ "Content-Type": "application/json",
184
+ Authorization: "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
185
+ ...(opts?.group ? { Group: opts.group.id } : {}),
186
+ },
187
+ body: JSON.stringify({ name: opts?.name }),
188
+ });
189
+ if (!response.ok)
190
+ throw new Error(await response.text());
191
+ return Repository.fromJSON(await response.json(), authorization, opts?.group);
192
+ }
193
+ export async function get(authorization, id, opts) {
194
+ const response = await fetch(`${Termite.getURL()}/termite/repositories/${id}`, {
195
+ method: "GET",
196
+ headers: {
197
+ Authorization: "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
198
+ ...(opts?.group ? { Group: opts.group.id } : {}),
199
+ },
200
+ });
201
+ if (!response.ok)
202
+ throw new Error(await response.text());
203
+ return Repository.fromJSON(await response.json(), authorization, opts?.group);
204
+ }
205
+ export async function list(authorization, opts) {
206
+ const response = await fetch(`${Termite.getURL()}/termite/repositories`, {
207
+ method: "GET",
208
+ headers: {
209
+ Authorization: "email" in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
210
+ ...(opts?.group ? { Group: opts.group.id } : {}),
211
+ },
212
+ });
213
+ if (!response.ok)
214
+ throw new Error(await response.text());
215
+ const json = await response.json();
216
+ return (Array.isArray(json) ? json : []).map((row) => Repository.fromJSON(row, authorization, opts?.group));
217
+ }
@@ -0,0 +1,43 @@
1
+ import { Fauna } from "../index.js";
2
+ import { ChatRoom, type RoomHooks } from "./parrot/room.js";
3
+ import { LastMessage } from "./parrot/chat.js";
4
+ import { Authorization, Presence, Room, Hooks as ServerHooks } from "./shared/server.js";
5
+ export declare function ticketChatAutoEnabled(emails: Iterable<string>, reporter: string): boolean;
6
+ export type TicketLast = LastMessage;
7
+ export type Ticket = {
8
+ id: string;
9
+ title: string;
10
+ description: string;
11
+ source?: string;
12
+ reporter?: string;
13
+ roomReference?: string;
14
+ createdAt: Date;
15
+ updatedAt: Date;
16
+ last: TicketLast | null;
17
+ unread: boolean;
18
+ };
19
+ export declare const Ticket: {
20
+ fromJSON(json: any): Ticket;
21
+ };
22
+ export declare class TicketRoom extends Room {
23
+ ticket: Ticket;
24
+ constructor(endpoint: string, ws: WebSocket, authorization: Authorization, id: string);
25
+ hydrate(state: any): void;
26
+ handleEvent(packet: any): boolean;
27
+ getChat(hooks?: RoomHooks): Promise<{
28
+ room: ChatRoom;
29
+ self: Presence;
30
+ }>;
31
+ static connect(authorization: Fauna.Authentification.Credentials, target: {
32
+ id: string;
33
+ }, hooks?: ServerHooks): Promise<{
34
+ room: TicketRoom;
35
+ self: Presence;
36
+ }>;
37
+ }
38
+ export declare function list(credentials: Fauna.Authentification.Credentials): Promise<Ticket[]>;
39
+ export declare function create(credentials: Fauna.Authentification.Credentials, partial: {
40
+ title?: string;
41
+ source?: string;
42
+ description?: string;
43
+ }): Promise<Ticket>;
@@ -0,0 +1,138 @@
1
+ import { Fauna } from "../index.js";
2
+ import { connectRoom } from "./parrot/room.js";
3
+ import { LastMessage } from "./parrot/chat.js";
4
+ import { Room, connect as connectServer } from "./shared/server.js";
5
+ export function ticketChatAutoEnabled(emails, reporter) {
6
+ const reporterEmail = reporter.trim().toLowerCase();
7
+ if (!reporterEmail)
8
+ return false;
9
+ let reporterPresent = false;
10
+ let otherPresent = false;
11
+ for (const raw of emails) {
12
+ const email = raw.trim().toLowerCase();
13
+ if (!email)
14
+ continue;
15
+ if (email === reporterEmail)
16
+ reporterPresent = true;
17
+ else
18
+ otherPresent = true;
19
+ }
20
+ return reporterPresent && !otherPresent;
21
+ }
22
+ export const Ticket = {
23
+ fromJSON(json) {
24
+ return {
25
+ id: String(json.id),
26
+ title: json.title ?? "",
27
+ description: json.description ?? "",
28
+ source: json.source || undefined,
29
+ reporter: json.reporter || undefined,
30
+ roomReference: json.roomReference || json.room_reference || undefined,
31
+ createdAt: new Date(json.createdAt ?? json.created_at),
32
+ updatedAt: new Date(json.updatedAt ?? json.updated_at),
33
+ last: LastMessage.fromJSON(json.last),
34
+ unread: Boolean(json.unread),
35
+ };
36
+ },
37
+ };
38
+ export class TicketRoom extends Room {
39
+ constructor(endpoint, ws, authorization, id) {
40
+ super(endpoint, ws, authorization, id);
41
+ Object.defineProperty(this, "ticket", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: void 0
46
+ });
47
+ this.ticket = {
48
+ id,
49
+ title: "",
50
+ description: "",
51
+ createdAt: new Date(0),
52
+ updatedAt: new Date(0),
53
+ last: null,
54
+ unread: false,
55
+ };
56
+ }
57
+ hydrate(state) {
58
+ if (state && typeof state === "object" && state.id != null) {
59
+ this.ticket = Ticket.fromJSON(state);
60
+ }
61
+ }
62
+ handleEvent(packet) {
63
+ const event = packet?.event;
64
+ if (event === "update-ticket" || event === "ticket") {
65
+ const data = packet.ticket ?? packet.data?.ticket ?? packet.data;
66
+ if (data && data.id != null)
67
+ this.ticket = Ticket.fromJSON(data);
68
+ return true;
69
+ }
70
+ return false;
71
+ }
72
+ async getChat(hooks) {
73
+ const auth = this.authorization;
74
+ const token = "email" in auth.authorization ? auth.authorization.token : undefined;
75
+ if (!token)
76
+ throw new Error("Ticket chat requires user credentials.");
77
+ const response = await fetch(`${Fauna.getURL()}/tickets/${encodeURIComponent(this.ticket.id)}/chat`, {
78
+ method: "POST",
79
+ headers: {
80
+ "Content-Type": "application/json",
81
+ Authorization: `Token ${token}`,
82
+ },
83
+ body: JSON.stringify({}),
84
+ });
85
+ if (!response.ok)
86
+ throw new Error(await response.text());
87
+ const { chatId, reference } = await response.json();
88
+ if (!chatId && !reference)
89
+ throw new Error("Invalid ensure response.");
90
+ return connectRoom(auth.authorization, { reference: reference || `parrot:chat:${chatId}` }, hooks ?? {});
91
+ }
92
+ static async connect(authorization, target, hooks) {
93
+ let room;
94
+ const user = hooks ?? {};
95
+ const self = await connectServer({ authorization, server: `fauna:ticket:${target.id}` }, `${Fauna.getURL()}/tickets`, {
96
+ ...user,
97
+ createRoom: (endpoint, ws, a, id, state) => {
98
+ room = (user.createRoom?.(endpoint, ws, a, id, state)
99
+ ?? new TicketRoom(endpoint, ws, a, id));
100
+ return room;
101
+ },
102
+ onConnection: (r, state) => {
103
+ r.hydrate(state);
104
+ user.onConnection?.(r, state);
105
+ },
106
+ onEvent: (r, packet) => {
107
+ const handled = r.handleEvent(packet);
108
+ return user.onEvent?.(r, packet) ?? handled;
109
+ },
110
+ });
111
+ return { room, self };
112
+ }
113
+ }
114
+ export async function list(credentials) {
115
+ const response = await fetch(`${Fauna.getURL()}/tickets`, {
116
+ method: "GET",
117
+ headers: {
118
+ Authorization: `Token ${credentials.token}`,
119
+ },
120
+ });
121
+ if (!response.ok)
122
+ throw new Error(await response.text());
123
+ const rows = await response.json();
124
+ return (Array.isArray(rows) ? rows : []).map((row) => Ticket.fromJSON(row));
125
+ }
126
+ export async function create(credentials, partial) {
127
+ const response = await fetch(`${Fauna.getURL()}/tickets`, {
128
+ method: "POST",
129
+ headers: {
130
+ "Content-Type": "application/json",
131
+ Authorization: `Token ${credentials.token}`,
132
+ },
133
+ body: JSON.stringify(partial),
134
+ });
135
+ if (!response.ok)
136
+ throw new Error(await response.text());
137
+ return Ticket.fromJSON(await response.json());
138
+ }
@@ -0,0 +1,85 @@
1
+ import { Credentials, ApiKey } from "./authentification.js";
2
+ import type { Group } from "./groups.js";
3
+ import type { Coordinates, Money, Waypoint } from "./maps.js";
4
+ export type Cabin = 'economy' | 'premium' | 'business' | 'first';
5
+ /** One way flights between two airports (IATA codes, or several joined with commas) on a local date. */
6
+ export type FlightQuery = {
7
+ from: string;
8
+ to: string;
9
+ /** YYYY-MM-DD. */
10
+ date: string;
11
+ adults?: number;
12
+ cabin?: Cabin;
13
+ currency?: string;
14
+ max?: number;
15
+ };
16
+ export type FlightStop = {
17
+ code: string;
18
+ name: string;
19
+ };
20
+ /** Times are local to each airport, YYYY-MM-DDTHH:mm. */
21
+ export type FlightLeg = {
22
+ airline: string;
23
+ number: string;
24
+ from: FlightStop;
25
+ to: FlightStop;
26
+ departure: string;
27
+ arrival: string;
28
+ /** Seconds. */
29
+ duration: number;
30
+ aircraft?: string;
31
+ logo?: string;
32
+ };
33
+ export type Flight = {
34
+ id: string;
35
+ price: Money;
36
+ /** Seconds, layovers included. */
37
+ duration: number;
38
+ stops: number;
39
+ from: string;
40
+ to: string;
41
+ departure: string;
42
+ arrival: string;
43
+ airlines: string[];
44
+ logo?: string;
45
+ legs: FlightLeg[];
46
+ };
47
+ /** Somewhere to book. When `form` is set, POST it to `url` as a url encoded form instead of opening `url`. */
48
+ export type Offer = {
49
+ seller: string;
50
+ price?: Money;
51
+ url: string;
52
+ form?: string;
53
+ logo?: string;
54
+ };
55
+ export type HotelSort = 'relevance' | 'price' | 'rating';
56
+ export type HotelQuery = {
57
+ near: Waypoint;
58
+ /** YYYY-MM-DD. */
59
+ checkIn: string;
60
+ /** YYYY-MM-DD. */
61
+ checkOut: string;
62
+ adults?: number;
63
+ currency?: string;
64
+ max?: number;
65
+ sort?: HotelSort;
66
+ };
67
+ export type Hotel = {
68
+ id: string;
69
+ name: string;
70
+ address?: string;
71
+ coordinates?: Coordinates;
72
+ /** Out of 5. */
73
+ rating?: number;
74
+ reviews?: number;
75
+ stars?: number;
76
+ nightly?: Money;
77
+ total?: Money;
78
+ image?: string;
79
+ amenities: string[];
80
+ offers: Offer[];
81
+ };
82
+ export declare function searchFlights(authorization: Credentials | ApiKey, query: FlightQuery, group?: Group): Promise<Flight[]>;
83
+ /** Where a flight can be booked, and for how much. */
84
+ export declare function getOffers(authorization: Credentials | ApiKey, flight: Flight, group?: Group): Promise<Offer[]>;
85
+ export declare function searchHotels(authorization: Credentials | ApiKey, query: HotelQuery, group?: Group): Promise<Hotel[]>;
@@ -0,0 +1,44 @@
1
+ import { Fauna } from "../index.js";
2
+ export async function searchFlights(authorization, query, group) {
3
+ const response = await fetch(`${Fauna.getURL()}/travel/flights`, {
4
+ method: "POST",
5
+ headers: {
6
+ "Content-Type": "application/json",
7
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`,
8
+ ...(group ? { "Group": group.id } : {})
9
+ },
10
+ body: JSON.stringify({ query })
11
+ });
12
+ if (!response.ok)
13
+ throw new Error(await response.text());
14
+ return await response.json();
15
+ }
16
+ /** Where a flight can be booked, and for how much. */
17
+ export async function getOffers(authorization, flight, group) {
18
+ const response = await fetch(`${Fauna.getURL()}/travel/flights/offers`, {
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({ id: flight.id })
26
+ });
27
+ if (!response.ok)
28
+ throw new Error(await response.text());
29
+ return await response.json();
30
+ }
31
+ export async function searchHotels(authorization, query, group) {
32
+ const response = await fetch(`${Fauna.getURL()}/travel/hotels`, {
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({ query })
40
+ });
41
+ if (!response.ok)
42
+ throw new Error(await response.text());
43
+ return await response.json();
44
+ }
@@ -0,0 +1,24 @@
1
+ export declare function getToken(): string | undefined;
2
+ export declare function setToken(token: string): void;
3
+ export declare function clearToken(): void;
4
+ /** Whether this tab is a support session opened from Fauna's ticket board. */
5
+ export declare function isSupportView(): boolean;
6
+ /**
7
+ * Takes `token` and `support` off a page's query. A support token stays in this tab; any other token
8
+ * becomes the login cookie and ends the tab's support session. Returns whether the query changed.
9
+ */
10
+ export declare function takeTokenFromURL(params: URLSearchParams): boolean;
11
+ /** The token this tab signs in with: the support session's in a support view, else the login cookie. */
12
+ export declare function sessionToken(): string | undefined;
13
+ export type OAuthProvider = 'google' | 'microsoft';
14
+ export type OAuthButtonsInstance = {
15
+ getElement: () => HTMLElement;
16
+ destroy: () => void;
17
+ };
18
+ export declare function createOAuthButtons(container: HTMLElement, options?: Partial<{
19
+ providers: OAuthProvider[];
20
+ redirect: string;
21
+ label: string;
22
+ divider: boolean | string;
23
+ onError: (message: string) => void;
24
+ }>): OAuthButtonsInstance;