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,119 @@
1
+ import { Fauna } from "../index.js";
2
+ import { LastMessage } from "./parrot/chat.js";
3
+ function hydrateChats(raw) {
4
+ return (raw ?? []).map((row) => ({ ...row, human: row.human === true, locked: row.locked === true, last: LastMessage.fromJSON(row.last), unread: typeof row.unread === 'number' ? row.unread : 0 }));
5
+ }
6
+ function hydrate(raw) {
7
+ return { ...raw, chats: hydrateChats(raw.chats), created: new Date(raw.created) };
8
+ }
9
+ /** Your friends, each with your chats together and what you haven't read. An API key reads them too. */
10
+ export async function list(authorization) {
11
+ const response = await fetch(`${Fauna.getURL()}/friends`, {
12
+ method: "GET",
13
+ headers: {
14
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
15
+ }
16
+ });
17
+ if (!response.ok)
18
+ throw new Error(await response.text());
19
+ return (await response.json()).map(hydrate);
20
+ }
21
+ /** Start a chat with someone by their Fauna email. The first chat makes you friends. */
22
+ export async function startChat(credentials, email, name) {
23
+ const response = await fetch(`${Fauna.getURL()}/friends/chats`, {
24
+ method: "POST",
25
+ headers: {
26
+ "Content-Type": "application/json",
27
+ "Authorization": `Token ${credentials.token}`
28
+ },
29
+ body: JSON.stringify({ email, name })
30
+ });
31
+ if (!response.ok)
32
+ throw new Error(await response.text());
33
+ const raw = await response.json();
34
+ return { friend: hydrate(raw.friend), chat: raw.chat };
35
+ }
36
+ /** Another chat with a friend. Resolves to its id. */
37
+ export async function createChat(credentials, friend, name) {
38
+ const response = await fetch(`${Fauna.getURL()}/friends/${encodeURIComponent(friend)}/chats`, {
39
+ method: "POST",
40
+ headers: {
41
+ "Content-Type": "application/json",
42
+ "Authorization": `Token ${credentials.token}`
43
+ },
44
+ body: JSON.stringify({ name })
45
+ });
46
+ if (!response.ok)
47
+ throw new Error(await response.text());
48
+ return (await response.json()).id;
49
+ }
50
+ /** Delete a chat with a friend, for both of you. */
51
+ export async function deleteChat(credentials, friend, chat) {
52
+ const response = await fetch(`${Fauna.getURL()}/friends/${encodeURIComponent(friend)}/chats/${encodeURIComponent(chat)}`, {
53
+ method: "DELETE",
54
+ headers: {
55
+ "Authorization": `Token ${credentials.token}`
56
+ }
57
+ });
58
+ if (!response.ok)
59
+ throw new Error(await response.text());
60
+ }
61
+ /** Bring a hidden friend out of Hidden. */
62
+ export async function show(credentials, friend) {
63
+ const response = await fetch(`${Fauna.getURL()}/friends/${encodeURIComponent(friend)}/show`, {
64
+ method: "POST",
65
+ headers: {
66
+ "Authorization": `Token ${credentials.token}`
67
+ }
68
+ });
69
+ if (!response.ok)
70
+ throw new Error(await response.text());
71
+ return hydrate(await response.json());
72
+ }
73
+ /** End a friendship. Its chats and their files go with it, for both of you. */
74
+ export async function end(credentials, friend) {
75
+ const response = await fetch(`${Fauna.getURL()}/friends/${encodeURIComponent(friend)}`, {
76
+ method: "DELETE",
77
+ headers: {
78
+ "Authorization": `Token ${credentials.token}`
79
+ }
80
+ });
81
+ if (!response.ok)
82
+ throw new Error(await response.text());
83
+ }
84
+ export async function settings(credentials) {
85
+ const response = await fetch(`${Fauna.getURL()}/friends/settings`, {
86
+ method: "GET",
87
+ headers: {
88
+ "Authorization": `Token ${credentials.token}`
89
+ }
90
+ });
91
+ if (!response.ok)
92
+ throw new Error(await response.text());
93
+ return await response.json();
94
+ }
95
+ export async function updateSettings(credentials, update) {
96
+ const response = await fetch(`${Fauna.getURL()}/friends/settings`, {
97
+ method: "PUT",
98
+ headers: {
99
+ "Content-Type": "application/json",
100
+ "Authorization": `Token ${credentials.token}`
101
+ },
102
+ body: JSON.stringify(update)
103
+ });
104
+ if (!response.ok)
105
+ throw new Error(await response.text());
106
+ return await response.json();
107
+ }
108
+ /** Your own trust edges, strongest first. Nobody else can read them; your API keys can. */
109
+ export async function trust(authorization) {
110
+ const response = await fetch(`${Fauna.getURL()}/friends/trust`, {
111
+ method: "GET",
112
+ headers: {
113
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
114
+ }
115
+ });
116
+ if (!response.ok)
117
+ throw new Error(await response.text());
118
+ return await response.json();
119
+ }
@@ -0,0 +1,82 @@
1
+ import { ApiKey, Credentials, Profile } from "./authentification.js";
2
+ import { ChatSummary } from "./parrot/chat.js";
3
+ export type Group = {
4
+ id: string;
5
+ name: string;
6
+ icon?: string;
7
+ balance: number;
8
+ members: Profile[];
9
+ createdAt: Date;
10
+ };
11
+ /** A group as someone outside it sees it: no balance, no member list. */
12
+ export type GroupSummary = {
13
+ id: string;
14
+ name: string;
15
+ icon?: string;
16
+ memberCount: number;
17
+ };
18
+ /** A person found by `query`, with the groups they belong to. */
19
+ export type GroupMatch = {
20
+ profile: Profile;
21
+ groups: GroupSummary[];
22
+ };
23
+ export declare function create(credentials: Credentials, name: string): Promise<Group>;
24
+ export declare function list(authorization: Credentials | ApiKey): Promise<Group[]>;
25
+ /** People matching a partial email or name, best first, each with their groups.
26
+ * Only people in at least one group come back. */
27
+ export declare function query(authorization: Credentials | ApiKey, profile: Partial<Profile>): Promise<GroupMatch[]>;
28
+ /** Name, icon and member count of groups by id, including groups you are not in.
29
+ * Unknown ids are left out. */
30
+ export declare function summaries(authorization: Credentials | ApiKey, ids: string[]): Promise<GroupSummary[]>;
31
+ export declare function get(authorization: Credentials | ApiKey, id: string): Promise<Group>;
32
+ export declare function edit(credentials: Credentials, id: string, update: Partial<Group>): Promise<Group>;
33
+ /** Add a user to a group by email. Resolves `{ status: 'added' }` if they were
34
+ * added directly (they have a Fauna account), or `{ status: 'invited', token }`
35
+ * if a pending invite was stored instead (no Fauna account for that email yet).
36
+ * Fauna emails the invite unless `notify` is false, so an app can send its own
37
+ * email carrying the token. */
38
+ export declare function invite(credentials: Credentials, id: string, email: string, options?: {
39
+ notify?: boolean;
40
+ }): Promise<{
41
+ status: 'added';
42
+ } | {
43
+ status: 'invited';
44
+ token: string;
45
+ }>;
46
+ /** Join the group an email invite points at, using the token from the invite. */
47
+ export declare function acceptInvite(credentials: Credentials, token: string): Promise<{
48
+ group: Group;
49
+ alreadyMember: boolean;
50
+ }>;
51
+ export declare function generateLink(credentials: Credentials, id: string): Promise<string>;
52
+ export declare function join(credentials: Credentials, code: string): Promise<{
53
+ group: Group;
54
+ alreadyMember: boolean;
55
+ }>;
56
+ export declare function leave(credentials: Credentials, id: string): Promise<void>;
57
+ export declare function kick(credentials: Credentials, id: string, email: string): Promise<void>;
58
+ /** Two groups with people only chats between them. `group` is the one of yours it was listed for. */
59
+ export type Partnership = {
60
+ id: string;
61
+ group: string;
62
+ partner: GroupSummary;
63
+ /** Under Hidden: the partner started at no trust while you hide strangers, and your group hasn't engaged. */
64
+ hidden: boolean;
65
+ chats: ChatSummary[];
66
+ created: Date;
67
+ };
68
+ /** A group's partnerships, each with their chats and what you haven't read. An API key reads them too. */
69
+ export declare function listPartnerships(authorization: Credentials | ApiKey, id: string): Promise<Partnership[]>;
70
+ /** Start a chat between your group `id` and `partner`. The first chat partners the groups. */
71
+ export declare function startPartnershipChat(credentials: Credentials, id: string, partner: string, name?: string): Promise<{
72
+ partnership: Partnership;
73
+ chat: string;
74
+ }>;
75
+ /** Another chat in a partnership. Resolves to its id. */
76
+ export declare function createPartnershipChat(credentials: Credentials, partnership: string, name?: string): Promise<string>;
77
+ /** Delete a partnership chat, for both groups. */
78
+ export declare function deletePartnershipChat(credentials: Credentials, partnership: string, chat: string): Promise<void>;
79
+ /** Bring a hidden partnership out of Hidden for your group. */
80
+ export declare function showPartnership(credentials: Credentials, partnership: string): Promise<Partnership>;
81
+ /** End a partnership. Its chats and their files go with it, for both groups. */
82
+ export declare function endPartnership(credentials: Credentials, partnership: string): Promise<void>;
@@ -0,0 +1,269 @@
1
+ import { Fauna } from "../index.js";
2
+ import { LastMessage } from "./parrot/chat.js";
3
+ export async function create(credentials, name) {
4
+ const response = await fetch(`${Fauna.getURL()}/groups`, {
5
+ method: "POST",
6
+ headers: {
7
+ "Content-Type": "application/json",
8
+ "Authorization": `Token ${credentials.token}`
9
+ },
10
+ body: JSON.stringify({ name })
11
+ });
12
+ if (!response.ok) {
13
+ throw new Error(await response.text());
14
+ }
15
+ const raw = await response.json();
16
+ return { ...raw, createdAt: new Date(raw.createdAt) };
17
+ }
18
+ export async function list(authorization) {
19
+ const response = await fetch(`${Fauna.getURL()}/groups`, {
20
+ method: "GET",
21
+ headers: {
22
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
23
+ }
24
+ });
25
+ if (!response.ok) {
26
+ throw new Error(await response.text());
27
+ }
28
+ const raw = await response.json();
29
+ return raw.map((group) => ({ ...group, createdAt: new Date(group.createdAt) }));
30
+ }
31
+ /** People matching a partial email or name, best first, each with their groups.
32
+ * Only people in at least one group come back. */
33
+ export async function query(authorization, profile) {
34
+ const response = await fetch(`${Fauna.getURL()}/groups/query`, {
35
+ method: "POST",
36
+ headers: {
37
+ "Content-Type": "application/json",
38
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
39
+ },
40
+ body: JSON.stringify({ email: profile.email, displayName: profile.displayName })
41
+ });
42
+ if (!response.ok) {
43
+ throw new Error(await response.text());
44
+ }
45
+ return await response.json();
46
+ }
47
+ /** Name, icon and member count of groups by id, including groups you are not in.
48
+ * Unknown ids are left out. */
49
+ export async function summaries(authorization, ids) {
50
+ const response = await fetch(`${Fauna.getURL()}/groups/summaries`, {
51
+ method: "POST",
52
+ headers: {
53
+ "Content-Type": "application/json",
54
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
55
+ },
56
+ body: JSON.stringify({ ids })
57
+ });
58
+ if (!response.ok) {
59
+ throw new Error(await response.text());
60
+ }
61
+ return await response.json();
62
+ }
63
+ export async function get(authorization, id) {
64
+ const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}`, {
65
+ method: "GET",
66
+ headers: {
67
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
68
+ }
69
+ });
70
+ if (!response.ok) {
71
+ throw new Error(await response.text());
72
+ }
73
+ const raw = await response.json();
74
+ return { ...raw, createdAt: new Date(raw.createdAt) };
75
+ }
76
+ export async function edit(credentials, id, update) {
77
+ const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}`, {
78
+ method: "PATCH",
79
+ headers: {
80
+ "Content-Type": "application/json",
81
+ "Authorization": `Token ${credentials.token}`
82
+ },
83
+ body: JSON.stringify({ update })
84
+ });
85
+ if (!response.ok) {
86
+ throw new Error(await response.text());
87
+ }
88
+ const raw = await response.json();
89
+ return { ...raw, createdAt: new Date(raw.createdAt) };
90
+ }
91
+ /** Add a user to a group by email. Resolves `{ status: 'added' }` if they were
92
+ * added directly (they have a Fauna account), or `{ status: 'invited', token }`
93
+ * if a pending invite was stored instead (no Fauna account for that email yet).
94
+ * Fauna emails the invite unless `notify` is false, so an app can send its own
95
+ * email carrying the token. */
96
+ export async function invite(credentials, id, email, options = {}) {
97
+ const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/invite`, {
98
+ method: "POST",
99
+ headers: {
100
+ "Content-Type": "application/json",
101
+ "Authorization": `Token ${credentials.token}`
102
+ },
103
+ body: JSON.stringify({ email, notify: options.notify })
104
+ });
105
+ if (!response.ok) {
106
+ throw new Error(await response.text());
107
+ }
108
+ return await response.json();
109
+ }
110
+ /** Join the group an email invite points at, using the token from the invite. */
111
+ export async function acceptInvite(credentials, token) {
112
+ const response = await fetch(`${Fauna.getURL()}/groups/invites/accept`, {
113
+ method: "POST",
114
+ headers: {
115
+ "Content-Type": "application/json",
116
+ "Authorization": `Token ${credentials.token}`
117
+ },
118
+ body: JSON.stringify({ token })
119
+ });
120
+ if (!response.ok) {
121
+ throw new Error(await response.text());
122
+ }
123
+ const raw = await response.json();
124
+ return {
125
+ group: { ...raw.group, createdAt: new Date(raw.group.createdAt) },
126
+ alreadyMember: raw.alreadyMember
127
+ };
128
+ }
129
+ export async function generateLink(credentials, id) {
130
+ const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/link`, {
131
+ method: "POST",
132
+ headers: {
133
+ "Authorization": `Token ${credentials.token}`
134
+ }
135
+ });
136
+ if (!response.ok) {
137
+ throw new Error(await response.text());
138
+ }
139
+ const json = await response.json();
140
+ return json.code;
141
+ }
142
+ export async function join(credentials, code) {
143
+ const response = await fetch(`${Fauna.getURL()}/groups/join`, {
144
+ method: "POST",
145
+ headers: {
146
+ "Content-Type": "application/json",
147
+ "Authorization": `Token ${credentials.token}`
148
+ },
149
+ body: JSON.stringify({ code })
150
+ });
151
+ if (!response.ok) {
152
+ throw new Error(await response.text());
153
+ }
154
+ const raw = await response.json();
155
+ return {
156
+ group: { ...raw.group, createdAt: new Date(raw.group.createdAt) },
157
+ alreadyMember: raw.alreadyMember
158
+ };
159
+ }
160
+ export async function leave(credentials, id) {
161
+ const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/membership`, {
162
+ method: "DELETE",
163
+ headers: {
164
+ "Authorization": `Token ${credentials.token}`
165
+ }
166
+ });
167
+ if (!response.ok) {
168
+ throw new Error(await response.text());
169
+ }
170
+ }
171
+ export async function kick(credentials, id, email) {
172
+ const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/members/${encodeURIComponent(email)}`, {
173
+ method: "DELETE",
174
+ headers: {
175
+ "Authorization": `Token ${credentials.token}`
176
+ }
177
+ });
178
+ if (!response.ok) {
179
+ throw new Error(await response.text());
180
+ }
181
+ }
182
+ function hydratePartnership(raw) {
183
+ return {
184
+ ...raw,
185
+ chats: (raw.chats ?? []).map((row) => ({ ...row, human: row.human === true, locked: row.locked === true, last: LastMessage.fromJSON(row.last), unread: typeof row.unread === 'number' ? row.unread : 0 })),
186
+ created: new Date(raw.created),
187
+ };
188
+ }
189
+ /** A group's partnerships, each with their chats and what you haven't read. An API key reads them too. */
190
+ export async function listPartnerships(authorization, id) {
191
+ const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/partnerships`, {
192
+ method: "GET",
193
+ headers: {
194
+ "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}`
195
+ }
196
+ });
197
+ if (!response.ok) {
198
+ throw new Error(await response.text());
199
+ }
200
+ return (await response.json()).map(hydratePartnership);
201
+ }
202
+ /** Start a chat between your group `id` and `partner`. The first chat partners the groups. */
203
+ export async function startPartnershipChat(credentials, id, partner, name) {
204
+ const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/partnerships`, {
205
+ method: "POST",
206
+ headers: {
207
+ "Content-Type": "application/json",
208
+ "Authorization": `Token ${credentials.token}`
209
+ },
210
+ body: JSON.stringify({ partner, name })
211
+ });
212
+ if (!response.ok) {
213
+ throw new Error(await response.text());
214
+ }
215
+ const raw = await response.json();
216
+ return { partnership: hydratePartnership(raw.partnership), chat: raw.chat };
217
+ }
218
+ /** Another chat in a partnership. Resolves to its id. */
219
+ export async function createPartnershipChat(credentials, partnership, name) {
220
+ const response = await fetch(`${Fauna.getURL()}/partnerships/${encodeURIComponent(partnership)}/chats`, {
221
+ method: "POST",
222
+ headers: {
223
+ "Content-Type": "application/json",
224
+ "Authorization": `Token ${credentials.token}`
225
+ },
226
+ body: JSON.stringify({ name })
227
+ });
228
+ if (!response.ok) {
229
+ throw new Error(await response.text());
230
+ }
231
+ return (await response.json()).id;
232
+ }
233
+ /** Delete a partnership chat, for both groups. */
234
+ export async function deletePartnershipChat(credentials, partnership, chat) {
235
+ const response = await fetch(`${Fauna.getURL()}/partnerships/${encodeURIComponent(partnership)}/chats/${encodeURIComponent(chat)}`, {
236
+ method: "DELETE",
237
+ headers: {
238
+ "Authorization": `Token ${credentials.token}`
239
+ }
240
+ });
241
+ if (!response.ok) {
242
+ throw new Error(await response.text());
243
+ }
244
+ }
245
+ /** Bring a hidden partnership out of Hidden for your group. */
246
+ export async function showPartnership(credentials, partnership) {
247
+ const response = await fetch(`${Fauna.getURL()}/partnerships/${encodeURIComponent(partnership)}/show`, {
248
+ method: "POST",
249
+ headers: {
250
+ "Authorization": `Token ${credentials.token}`
251
+ }
252
+ });
253
+ if (!response.ok) {
254
+ throw new Error(await response.text());
255
+ }
256
+ return hydratePartnership(await response.json());
257
+ }
258
+ /** End a partnership. Its chats and their files go with it, for both groups. */
259
+ export async function endPartnership(credentials, partnership) {
260
+ const response = await fetch(`${Fauna.getURL()}/partnerships/${encodeURIComponent(partnership)}`, {
261
+ method: "DELETE",
262
+ headers: {
263
+ "Authorization": `Token ${credentials.token}`
264
+ }
265
+ });
266
+ if (!response.ok) {
267
+ throw new Error(await response.text());
268
+ }
269
+ }
@@ -0,0 +1,11 @@
1
+ import { Credentials } from "./authentification.js";
2
+ export type Message = {
3
+ id: string;
4
+ icon: string;
5
+ header: string;
6
+ content: string;
7
+ href?: string;
8
+ };
9
+ export declare function read(credentials: Credentials): Promise<Message[]>;
10
+ export declare function remove(credentials: Credentials, id: string): Promise<void>;
11
+ export declare function clear(credentials: Credentials): Promise<void>;
@@ -0,0 +1,35 @@
1
+ import { Fauna } from "../index.js";
2
+ export async function read(credentials) {
3
+ const response = await fetch(`${Fauna.getURL()}/inbox`, {
4
+ method: "GET",
5
+ headers: {
6
+ "Authorization": `Token ${credentials.token}`
7
+ }
8
+ });
9
+ if (!response.ok) {
10
+ throw new Error(await response.text());
11
+ }
12
+ return await response.json();
13
+ }
14
+ export async function remove(credentials, id) {
15
+ const response = await fetch(`${Fauna.getURL()}/inbox/${encodeURIComponent(id)}`, {
16
+ method: "DELETE",
17
+ headers: {
18
+ "Authorization": `Token ${credentials.token}`
19
+ }
20
+ });
21
+ if (!response.ok) {
22
+ throw new Error(await response.text());
23
+ }
24
+ }
25
+ export async function clear(credentials) {
26
+ const response = await fetch(`${Fauna.getURL()}/inbox`, {
27
+ method: "DELETE",
28
+ headers: {
29
+ "Authorization": `Token ${credentials.token}`
30
+ }
31
+ });
32
+ if (!response.ok) {
33
+ throw new Error(await response.text());
34
+ }
35
+ }
@@ -0,0 +1,52 @@
1
+ import { Credentials } from "./authentification.js";
2
+ export declare enum Platform {
3
+ GOOGLE = "GOOGLE",
4
+ SLACK = "SLACK",
5
+ DISCORD = "DISCORD",
6
+ TWILIO = "TWILIO",
7
+ MICROSOFT = "MICROSOFT",
8
+ WHATSAPP = "WHATSAPP"
9
+ }
10
+ export declare abstract class Account {
11
+ readonly authorization: Credentials;
12
+ readonly platform: Platform;
13
+ readonly authorized: boolean;
14
+ readonly createdAt: Date;
15
+ readonly id: string;
16
+ constructor(authorization: Credentials, platform: Platform, raw: any);
17
+ unlink(): Promise<void>;
18
+ }
19
+ export declare class Google extends Account {
20
+ readonly email: string;
21
+ readonly scopes: string[];
22
+ constructor(authorization: Credentials, raw: any);
23
+ getDemographics(): Promise<{
24
+ ageRange: [number, number];
25
+ gender: string;
26
+ percentage: number;
27
+ }[]>;
28
+ }
29
+ export declare class Slack extends Account {
30
+ readonly email: string;
31
+ readonly scopes: string[];
32
+ constructor(authorization: Credentials, raw: any);
33
+ }
34
+ export declare class Discord extends Account {
35
+ readonly handle: string;
36
+ constructor(authorization: Credentials, raw: any);
37
+ }
38
+ export declare class Twilio extends Account {
39
+ readonly phone: string;
40
+ constructor(authorization: Credentials, raw: any);
41
+ }
42
+ export declare class Microsoft extends Account {
43
+ readonly email: string;
44
+ readonly scopes: string[];
45
+ constructor(authorization: Credentials, raw: any);
46
+ }
47
+ export declare class WhatsApp extends Account {
48
+ readonly phone: string;
49
+ constructor(authorization: Credentials, raw: any);
50
+ }
51
+ export declare function linkPlatform(credentials: Credentials, integration: Platform): Promise<WindowProxy | null>;
52
+ export declare function getAccounts(credentials: Credentials): Promise<Account[]>;