fauna-api 1.0.693 → 1.0.703

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.
@@ -67,9 +67,9 @@ export declare function revokeSession(credentials: Credentials, session: Session
67
67
  export declare function signOut(credentials: Credentials): Promise<boolean>;
68
68
  /** Ends every one of your sessions, this one too. */
69
69
  export declare function signOutEverywhere(credentials: Credentials): Promise<boolean>;
70
- /** A single use code that passes this session to another page or app for a minute, so the token never rides in a URL. */
70
+ /** A single use code, good for a minute, that gives another page or app a new session of the same person, so no token rides in a URL. */
71
71
  export declare function handoff(credentials: Credentials): Promise<string>;
72
- /** Uses up a handoff code for the session token it passes. */
72
+ /** Uses up a handoff code for the new session token it carries. */
73
73
  export declare function redeemHandoff(code: string): Promise<Token>;
74
74
  export declare function allocateBalance(credentials: Credentials, target: ApiKey | Group, delta: number): Promise<true>;
75
75
  export declare function generateApiKey(credentials: Credentials): Promise<ApiKey>;
@@ -216,7 +216,7 @@ export async function signOutEverywhere(credentials) {
216
216
  }
217
217
  return response.ok;
218
218
  }
219
- /** A single use code that passes this session to another page or app for a minute, so the token never rides in a URL. */
219
+ /** A single use code, good for a minute, that gives another page or app a new session of the same person, so no token rides in a URL. */
220
220
  export async function handoff(credentials) {
221
221
  const response = await fetch(`${Fauna.getURL()}/authentification/handoff`, {
222
222
  method: "POST",
@@ -229,7 +229,7 @@ export async function handoff(credentials) {
229
229
  }
230
230
  return String((await response.json()).code);
231
231
  }
232
- /** Uses up a handoff code for the session token it passes. */
232
+ /** Uses up a handoff code for the new session token it carries. */
233
233
  export async function redeemHandoff(code) {
234
234
  const response = await fetch(`${Fauna.getURL()}/authentification/handoff/redeem`, {
235
235
  method: "POST",
@@ -114,7 +114,19 @@ export type NestOffer = {
114
114
  export declare const NestOffer: {
115
115
  fromJSON(json: any): NestOffer;
116
116
  };
117
- /** Start a group. You are its first admin. Needs a subscription. */
117
+ /** An email invite waiting to be accepted, as the group's admins see it. */
118
+ export type EmailInvite = {
119
+ token: string;
120
+ email: string;
121
+ /** Email of the admin who sent it. */
122
+ by?: string;
123
+ expires: Date;
124
+ };
125
+ export declare const EmailInvite: {
126
+ fromJSON(json: any): EmailInvite;
127
+ };
128
+ /** Start a group. You are its first admin. Needs a subscription, and room under
129
+ * `fauna/groups:N`, the most groups you may administer. */
118
130
  export declare function create(credentials: Credentials, name: string): Promise<Group>;
119
131
  /** Every group you are in, directly or through a nested group, oldest first.
120
132
  * Each says how you are in it (`through`). */
@@ -147,11 +159,20 @@ export declare function acceptInvite(credentials: Credentials, token: string): P
147
159
  group: Group;
148
160
  alreadyMember: boolean;
149
161
  }>;
150
- /** A join code good for seven days. Admins only. People join with it, and admins
151
- * of other groups put their group inside this one with it. `maxUses` caps how
152
- * many it lets in; without it, any number can join until it expires. */
162
+ /** The group's email invites waiting to be accepted, newest first. Admins only. */
163
+ export declare function invites(credentials: Credentials, id: string, query: {
164
+ cursor: number;
165
+ max: number;
166
+ }): Promise<EmailInvite[]>;
167
+ /** An email invite stops working, by its token. An admin of its group, or whoever sent it. */
168
+ export declare function revokeInvite(credentials: Credentials, token: string): Promise<void>;
169
+ /** A join code. Admins only. People join with it, and admins of other groups put
170
+ * their group inside this one with it. `maxUses` caps how many it lets in;
171
+ * without it, any number can join until it expires. It expires at `expires`,
172
+ * in the future and at most a year out, or in seven days without it. */
153
173
  export declare function generateLink(credentials: Credentials, id: string, options?: {
154
174
  maxUses?: number;
175
+ expires?: Date;
155
176
  }): Promise<string>;
156
177
  /** The group's join links that still work, newest first. Admins only. */
157
178
  export declare function links(credentials: Credentials, id: string): Promise<JoinLink[]>;
@@ -171,7 +192,8 @@ export declare function leave(credentials: Credentials, id: string): Promise<voi
171
192
  /** Remove a person who is directly in the group. Admins only. */
172
193
  export declare function kick(credentials: Credentials, id: string, email: string): Promise<void>;
173
194
  /** Make a person who is directly in the group an admin. Admins only. Someone in
174
- * it only through a nested group is invited directly first. */
195
+ * it only through a nested group is invited directly first. They need room under
196
+ * their own `fauna/groups:N`, the most groups they may administer. */
175
197
  export declare function promote(credentials: Credentials, id: string, email: string): Promise<Group>;
176
198
  /** Make an admin a member again. Admins only; a group keeps at least one admin. */
177
199
  export declare function demote(credentials: Credentials, id: string, email: string): Promise<Group>;
@@ -89,7 +89,18 @@ export const NestOffer = {
89
89
  return json.nested === true ? { nested: true } : { nested: false, token: String(json.token) };
90
90
  },
91
91
  };
92
- /** Start a group. You are its first admin. Needs a subscription. */
92
+ export const EmailInvite = {
93
+ fromJSON(json) {
94
+ return {
95
+ token: String(json.token),
96
+ email: String(json.email),
97
+ ...(json.by ? { by: String(json.by) } : {}),
98
+ expires: new Date(json.expires),
99
+ };
100
+ },
101
+ };
102
+ /** Start a group. You are its first admin. Needs a subscription, and room under
103
+ * `fauna/groups:N`, the most groups you may administer. */
93
104
  export async function create(credentials, name) {
94
105
  const response = await fetch(`${Fauna.getURL()}/groups`, {
95
106
  method: "POST",
@@ -228,9 +239,36 @@ export async function acceptInvite(credentials, token) {
228
239
  const raw = await response.json();
229
240
  return { group: Group.fromJSON(raw.group), alreadyMember: raw.alreadyMember === true };
230
241
  }
231
- /** A join code good for seven days. Admins only. People join with it, and admins
232
- * of other groups put their group inside this one with it. `maxUses` caps how
233
- * many it lets in; without it, any number can join until it expires. */
242
+ /** The group's email invites waiting to be accepted, newest first. Admins only. */
243
+ export async function invites(credentials, id, query) {
244
+ const params = new URLSearchParams({ cursor: String(query.cursor), max: String(query.max) });
245
+ const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/invites?${params}`, {
246
+ method: "GET",
247
+ headers: {
248
+ "Authorization": `Token ${credentials.token}`
249
+ }
250
+ });
251
+ if (!response.ok) {
252
+ throw new Error(await response.text());
253
+ }
254
+ return (await response.json()).map(EmailInvite.fromJSON);
255
+ }
256
+ /** An email invite stops working, by its token. An admin of its group, or whoever sent it. */
257
+ export async function revokeInvite(credentials, token) {
258
+ const response = await fetch(`${Fauna.getURL()}/groups/invites/${encodeURIComponent(token)}`, {
259
+ method: "DELETE",
260
+ headers: {
261
+ "Authorization": `Token ${credentials.token}`
262
+ }
263
+ });
264
+ if (!response.ok) {
265
+ throw new Error(await response.text());
266
+ }
267
+ }
268
+ /** A join code. Admins only. People join with it, and admins of other groups put
269
+ * their group inside this one with it. `maxUses` caps how many it lets in;
270
+ * without it, any number can join until it expires. It expires at `expires`,
271
+ * in the future and at most a year out, or in seven days without it. */
234
272
  export async function generateLink(credentials, id, options = {}) {
235
273
  const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/link`, {
236
274
  method: "POST",
@@ -238,7 +276,7 @@ export async function generateLink(credentials, id, options = {}) {
238
276
  "Content-Type": "application/json",
239
277
  "Authorization": `Token ${credentials.token}`
240
278
  },
241
- body: JSON.stringify({ maxUses: options.maxUses })
279
+ body: JSON.stringify({ maxUses: options.maxUses, expires: options.expires?.toISOString() })
242
280
  });
243
281
  if (!response.ok) {
244
282
  throw new Error(await response.text());
@@ -316,7 +354,8 @@ export async function kick(credentials, id, email) {
316
354
  }
317
355
  }
318
356
  /** Make a person who is directly in the group an admin. Admins only. Someone in
319
- * it only through a nested group is invited directly first. */
357
+ * it only through a nested group is invited directly first. They need room under
358
+ * their own `fauna/groups:N`, the most groups they may administer. */
320
359
  export async function promote(credentials, id, email) {
321
360
  const response = await fetch(`${Fauna.getURL()}/groups/${encodeURIComponent(id)}/admins/${encodeURIComponent(email)}`, {
322
361
  method: "POST",
@@ -1,6 +1,8 @@
1
1
  import { ApiKey, Credentials, Profile } from "./authentification.js";
2
- /** Event types a webhook can listen for: `chat.message` for groups and chats, payment events for API keys. */
3
- export type EventType = 'chat.message' | 'payment.succeeded' | 'payment.expired' | 'payment.refunded' | 'payment.disputed';
2
+ import { GroupRef } from "./groups.js";
3
+ /** Event types a webhook can listen for: `chat.message` for groups and chats,
4
+ * `group.joined` and `group.left` for groups, payment events for API keys. */
5
+ export type EventType = 'chat.message' | 'group.joined' | 'group.left' | 'payment.succeeded' | 'payment.expired' | 'payment.refunded' | 'payment.disputed';
4
6
  /** Who a webhook belongs to: a group, one chat, or the API key making the call. */
5
7
  export type WebhookOwner = {
6
8
  group: string;
@@ -51,6 +53,23 @@ export type ChatMessage = {
51
53
  /** Milliseconds since the epoch. */
52
54
  created: number;
53
55
  };
56
+ /** Who came into a group or went out of it: a person, or a group nested directly inside it. */
57
+ export type GroupChangeMember = {
58
+ email: string;
59
+ } | {
60
+ group: GroupRef;
61
+ };
62
+ /** Why: `joined` for `group.joined`; for `group.left`, the person `left` or was
63
+ * `removed` by an admin, or the nested group was `unnested` or `deleted`. */
64
+ export type GroupChangeReason = 'joined' | 'left' | 'removed' | 'unnested' | 'deleted';
65
+ /** `data` of `group.joined` and `group.left`: a person or a nested group came
66
+ * directly into `group` or went directly out of it. Changes further down (someone
67
+ * leaving a nested group) are told only to that group's own webhooks. */
68
+ export type GroupChange = {
69
+ group: GroupRef;
70
+ member: GroupChangeMember;
71
+ reason: GroupChangeReason;
72
+ };
54
73
  /**
55
74
  * Register a webhook for a group or a chat you can read, or, signed in with an
56
75
  * API key, for that key. In production `url` must be https on a public address.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fauna-api",
3
- "version": "1.0.693",
3
+ "version": "1.0.703",
4
4
  "description": "The Fauna SDK: accounts, Drive, groups, calendar, chats, payments and every Fauna app (Parrot, Marmot, Magpie, Cicada, Ant, Termite), plus React UI.",
5
5
  "homepage": "https://docs.faunakit.com",
6
6
  "repository": {