@niledatabase/server 5.0.0-alpha.12 → 5.0.0-alpha.13

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/index.d.mts CHANGED
@@ -140,15 +140,62 @@ interface User {
140
140
  tenants: string[];
141
141
  }
142
142
 
143
+ /**
144
+ * Convenience wrapper around the user endpoints.
145
+ *
146
+ * Requests are issued via {@link fetchMe} against `/api/me`. The Swagger
147
+ * definitions for these APIs live in
148
+ * `packages/server/src/api/routes/me/index.ts`.
149
+ */
143
150
  declare class Users {
144
151
  #private;
152
+ /**
153
+ * Create a new Users helper.
154
+ * @param config - The configuration used for requests.
155
+ */
145
156
  constructor(config: Config);
157
+ /**
158
+ * Update the current user via `PUT /api/me`.
159
+ *
160
+ * The OpenAPI description for this endpoint can be found in
161
+ * `packages/server/src/api/routes/me/index.ts` under `updateSelf`.
162
+ *
163
+ * @param req - Partial user fields to send.
164
+ * @param [rawResponse] - When `true`, return the raw {@link Response}.
165
+ */
146
166
  updateSelf<T = User[] | Response>(req: Partial<Omit<User, 'email' | 'tenants' | 'created' | 'updated' | 'emailVerified'> & {
147
167
  emailVerified: boolean;
148
168
  }>, rawResponse?: boolean): Promise<T>;
169
+ /**
170
+ * Remove the current user using `DELETE /api/me`.
171
+ *
172
+ * After the request the authentication headers are cleared with
173
+ * {@link updateHeaders}. The OpenAPI docs for this route are in
174
+ * `packages/server/src/api/routes/me/index.ts` under `removeSelf`.
175
+ */
149
176
  removeSelf(): Promise<Response>;
177
+ /**
178
+ * Retrieve the current user with `GET /api/me`.
179
+ *
180
+ * OpenAPI for this endpoint resides in
181
+ * `packages/server/src/api/routes/me/index.ts` (`getSelf`).
182
+ *
183
+ * @param [rawResponse] - When `true` return the raw {@link Response}.
184
+ */
150
185
  getSelf<T = User | Response>(): Promise<T>;
151
186
  getSelf(rawResponse?: true): Promise<Response>;
187
+ /**
188
+ * Initiate an email verification flow.
189
+ *
190
+ * The current user is fetched and then `/auth/verify-email` is called.
191
+ * In development or when `bypassEmail` is set, the user's
192
+ * `emailVerified` field is updated instead of sending an email.
193
+ * See `packages/server/src/api/routes/auth/verify-email.ts` for the
194
+ * underlying request.
195
+ *
196
+ * @param [options] - Flags controlling bypass behaviour and callback URL.
197
+ * @param [rawResponse] - When `true` return the raw {@link Response}.
198
+ */
152
199
  verifySelf<T = void>(): Promise<T>;
153
200
  verifySelf(rawResponse: true): Promise<Response>;
154
201
  verifySelf<T = Response | User>(options: {
@@ -171,6 +218,12 @@ type Invite = {
171
218
  expires: Date;
172
219
  };
173
220
 
221
+ /**
222
+ * Convenience wrapper around the tenant endpoints. These methods call
223
+ * the `fetch*` helpers in `packages/server/src/api/routes/tenants` which
224
+ * in turn hit routes such as `/api/tenants` and `/api/tenants/{tenantId}`.
225
+ * See those files for the Swagger definitions.
226
+ */
174
227
  type ReqContext = {
175
228
  userId?: string;
176
229
  tenantId?: string;
@@ -187,7 +240,16 @@ declare class Tenants {
187
240
  name: string;
188
241
  id?: string;
189
242
  }, rawResponse?: boolean): Promise<T>;
243
+ /**
244
+ * Delete a tenant using `DELETE /api/tenants/{tenantId}`.
245
+ * The OpenAPI operation is defined in
246
+ * `packages/server/src/api/routes/tenants/[tenantId]/DELETE.ts`.
247
+ */
190
248
  delete<T = Response>(id?: string): Promise<T>;
249
+ /**
250
+ * Delete a tenant using `DELETE /api/tenants/{tenantId}`.
251
+ * See `packages/server/src/api/routes/tenants/[tenantId]/DELETE.ts`.
252
+ */
191
253
  delete<T = Response>(payload: {
192
254
  id: string;
193
255
  }): Promise<T>;
@@ -198,20 +260,58 @@ declare class Tenants {
198
260
  id: string;
199
261
  }, rawResponse?: boolean): Promise<T>;
200
262
  update(req: Partial<Tenant>, rawResponse: true): Promise<Response>;
263
+ /**
264
+ * Modify a tenant using `PUT /api/tenants/{tenantId}`.
265
+ *
266
+ * @param req - Tenant data to update. Can include an id.
267
+ * @param [rawResponse] - When true, return the raw {@link Response}.
268
+ */
201
269
  update<T = Tenant | Response | undefined>(req: Partial<Tenant>, rawResponse?: boolean): Promise<T>;
202
270
  list<T = Tenant[] | Response>(): Promise<T>;
203
271
  list(rawResponse: true): Promise<Response>;
272
+ /**
273
+ * Leave the current tenant using `DELETE /api/tenants/{tenantId}/users/{userId}`.
274
+ *
275
+ * @param [req] - Optionally specify the tenant id to leave.
276
+ */
204
277
  leaveTenant<T = Response>(req?: string | {
205
278
  tenantId: string;
206
279
  }): Promise<T>;
207
280
  addMember(req: JoinTenantRequest, rawResponse: true): Promise<Response>;
281
+ /**
282
+ * Add a user to a tenant via `PUT /api/tenants/{tenantId}/users/{userId}`.
283
+ *
284
+ * @param req - User and tenant identifiers or context.
285
+ * @param [rawResponse] - When true, return the raw {@link Response}.
286
+ */
208
287
  addMember<T = User | Response>(req: JoinTenantRequest, rawResponse?: boolean): Promise<T>;
288
+ /**
289
+ * Remove a user from a tenant with `DELETE /api/tenants/{tenantId}/users/{userId}`.
290
+ *
291
+ * @param req - User and tenant identifiers or context.
292
+ * @param [rawResponse] - When true, return the raw {@link Response}.
293
+ */
209
294
  removeMember(req: JoinTenantRequest, rawResponse?: boolean): Promise<Response>;
295
+ /**
296
+ * List users for a tenant via `GET /api/tenants/{tenantId}/users`.
297
+ *
298
+ * @param [req] - Tenant identifier or context.
299
+ * @param [rawResponse] - When true, return the raw {@link Response}.
300
+ */
210
301
  users<T = User[] | Response>(req?: boolean | {
211
302
  tenantId?: string;
212
303
  }, rawResponse?: boolean): Promise<T>;
213
304
  users(req: true): Promise<Response>;
305
+ /**
306
+ * List invites for the current tenant via `GET /api/tenants/{tenantId}/invites`.
307
+ */
214
308
  invites<T = Invite[] | Response>(): Promise<T>;
309
+ /**
310
+ * Send an invitation via `POST /api/tenants/{tenantId}/invite`.
311
+ *
312
+ * @param req - Email and optional callback/redirect URLs.
313
+ * @param [rawResponse] - When true, return the raw {@link Response}.
314
+ */
215
315
  invite<T = Response | Invite>(req: string | {
216
316
  email: string;
217
317
  callbackUrl?: string;
@@ -222,11 +322,22 @@ declare class Tenants {
222
322
  callbackUrl?: string;
223
323
  redirectUrl?: string;
224
324
  }, rawResponse: true): Promise<Response>;
325
+ /**
326
+ * Accept an invite using `PUT /api/tenants/{tenantId}/invite`.
327
+ *
328
+ * @param req - Identifier and token from the invite email.
329
+ * @param [rawResponse] - When true, return the raw {@link Response}.
330
+ */
225
331
  acceptInvite<T = Response>(req?: {
226
332
  identifier: string;
227
333
  token: string;
228
334
  redirectUrl?: string;
229
335
  }, rawResponse?: boolean): Promise<T>;
336
+ /**
337
+ * Delete a pending invite using `DELETE /api/tenants/{tenantId}/invite/{inviteId}`.
338
+ *
339
+ * @param req - Identifier of the invite to remove.
340
+ */
230
341
  deleteInvite<T = Response>(req: string | {
231
342
  id: string;
232
343
  }): Promise<T>;
package/dist/index.d.ts CHANGED
@@ -140,15 +140,62 @@ interface User {
140
140
  tenants: string[];
141
141
  }
142
142
 
143
+ /**
144
+ * Convenience wrapper around the user endpoints.
145
+ *
146
+ * Requests are issued via {@link fetchMe} against `/api/me`. The Swagger
147
+ * definitions for these APIs live in
148
+ * `packages/server/src/api/routes/me/index.ts`.
149
+ */
143
150
  declare class Users {
144
151
  #private;
152
+ /**
153
+ * Create a new Users helper.
154
+ * @param config - The configuration used for requests.
155
+ */
145
156
  constructor(config: Config);
157
+ /**
158
+ * Update the current user via `PUT /api/me`.
159
+ *
160
+ * The OpenAPI description for this endpoint can be found in
161
+ * `packages/server/src/api/routes/me/index.ts` under `updateSelf`.
162
+ *
163
+ * @param req - Partial user fields to send.
164
+ * @param [rawResponse] - When `true`, return the raw {@link Response}.
165
+ */
146
166
  updateSelf<T = User[] | Response>(req: Partial<Omit<User, 'email' | 'tenants' | 'created' | 'updated' | 'emailVerified'> & {
147
167
  emailVerified: boolean;
148
168
  }>, rawResponse?: boolean): Promise<T>;
169
+ /**
170
+ * Remove the current user using `DELETE /api/me`.
171
+ *
172
+ * After the request the authentication headers are cleared with
173
+ * {@link updateHeaders}. The OpenAPI docs for this route are in
174
+ * `packages/server/src/api/routes/me/index.ts` under `removeSelf`.
175
+ */
149
176
  removeSelf(): Promise<Response>;
177
+ /**
178
+ * Retrieve the current user with `GET /api/me`.
179
+ *
180
+ * OpenAPI for this endpoint resides in
181
+ * `packages/server/src/api/routes/me/index.ts` (`getSelf`).
182
+ *
183
+ * @param [rawResponse] - When `true` return the raw {@link Response}.
184
+ */
150
185
  getSelf<T = User | Response>(): Promise<T>;
151
186
  getSelf(rawResponse?: true): Promise<Response>;
187
+ /**
188
+ * Initiate an email verification flow.
189
+ *
190
+ * The current user is fetched and then `/auth/verify-email` is called.
191
+ * In development or when `bypassEmail` is set, the user's
192
+ * `emailVerified` field is updated instead of sending an email.
193
+ * See `packages/server/src/api/routes/auth/verify-email.ts` for the
194
+ * underlying request.
195
+ *
196
+ * @param [options] - Flags controlling bypass behaviour and callback URL.
197
+ * @param [rawResponse] - When `true` return the raw {@link Response}.
198
+ */
152
199
  verifySelf<T = void>(): Promise<T>;
153
200
  verifySelf(rawResponse: true): Promise<Response>;
154
201
  verifySelf<T = Response | User>(options: {
@@ -171,6 +218,12 @@ type Invite = {
171
218
  expires: Date;
172
219
  };
173
220
 
221
+ /**
222
+ * Convenience wrapper around the tenant endpoints. These methods call
223
+ * the `fetch*` helpers in `packages/server/src/api/routes/tenants` which
224
+ * in turn hit routes such as `/api/tenants` and `/api/tenants/{tenantId}`.
225
+ * See those files for the Swagger definitions.
226
+ */
174
227
  type ReqContext = {
175
228
  userId?: string;
176
229
  tenantId?: string;
@@ -187,7 +240,16 @@ declare class Tenants {
187
240
  name: string;
188
241
  id?: string;
189
242
  }, rawResponse?: boolean): Promise<T>;
243
+ /**
244
+ * Delete a tenant using `DELETE /api/tenants/{tenantId}`.
245
+ * The OpenAPI operation is defined in
246
+ * `packages/server/src/api/routes/tenants/[tenantId]/DELETE.ts`.
247
+ */
190
248
  delete<T = Response>(id?: string): Promise<T>;
249
+ /**
250
+ * Delete a tenant using `DELETE /api/tenants/{tenantId}`.
251
+ * See `packages/server/src/api/routes/tenants/[tenantId]/DELETE.ts`.
252
+ */
191
253
  delete<T = Response>(payload: {
192
254
  id: string;
193
255
  }): Promise<T>;
@@ -198,20 +260,58 @@ declare class Tenants {
198
260
  id: string;
199
261
  }, rawResponse?: boolean): Promise<T>;
200
262
  update(req: Partial<Tenant>, rawResponse: true): Promise<Response>;
263
+ /**
264
+ * Modify a tenant using `PUT /api/tenants/{tenantId}`.
265
+ *
266
+ * @param req - Tenant data to update. Can include an id.
267
+ * @param [rawResponse] - When true, return the raw {@link Response}.
268
+ */
201
269
  update<T = Tenant | Response | undefined>(req: Partial<Tenant>, rawResponse?: boolean): Promise<T>;
202
270
  list<T = Tenant[] | Response>(): Promise<T>;
203
271
  list(rawResponse: true): Promise<Response>;
272
+ /**
273
+ * Leave the current tenant using `DELETE /api/tenants/{tenantId}/users/{userId}`.
274
+ *
275
+ * @param [req] - Optionally specify the tenant id to leave.
276
+ */
204
277
  leaveTenant<T = Response>(req?: string | {
205
278
  tenantId: string;
206
279
  }): Promise<T>;
207
280
  addMember(req: JoinTenantRequest, rawResponse: true): Promise<Response>;
281
+ /**
282
+ * Add a user to a tenant via `PUT /api/tenants/{tenantId}/users/{userId}`.
283
+ *
284
+ * @param req - User and tenant identifiers or context.
285
+ * @param [rawResponse] - When true, return the raw {@link Response}.
286
+ */
208
287
  addMember<T = User | Response>(req: JoinTenantRequest, rawResponse?: boolean): Promise<T>;
288
+ /**
289
+ * Remove a user from a tenant with `DELETE /api/tenants/{tenantId}/users/{userId}`.
290
+ *
291
+ * @param req - User and tenant identifiers or context.
292
+ * @param [rawResponse] - When true, return the raw {@link Response}.
293
+ */
209
294
  removeMember(req: JoinTenantRequest, rawResponse?: boolean): Promise<Response>;
295
+ /**
296
+ * List users for a tenant via `GET /api/tenants/{tenantId}/users`.
297
+ *
298
+ * @param [req] - Tenant identifier or context.
299
+ * @param [rawResponse] - When true, return the raw {@link Response}.
300
+ */
210
301
  users<T = User[] | Response>(req?: boolean | {
211
302
  tenantId?: string;
212
303
  }, rawResponse?: boolean): Promise<T>;
213
304
  users(req: true): Promise<Response>;
305
+ /**
306
+ * List invites for the current tenant via `GET /api/tenants/{tenantId}/invites`.
307
+ */
214
308
  invites<T = Invite[] | Response>(): Promise<T>;
309
+ /**
310
+ * Send an invitation via `POST /api/tenants/{tenantId}/invite`.
311
+ *
312
+ * @param req - Email and optional callback/redirect URLs.
313
+ * @param [rawResponse] - When true, return the raw {@link Response}.
314
+ */
215
315
  invite<T = Response | Invite>(req: string | {
216
316
  email: string;
217
317
  callbackUrl?: string;
@@ -222,11 +322,22 @@ declare class Tenants {
222
322
  callbackUrl?: string;
223
323
  redirectUrl?: string;
224
324
  }, rawResponse: true): Promise<Response>;
325
+ /**
326
+ * Accept an invite using `PUT /api/tenants/{tenantId}/invite`.
327
+ *
328
+ * @param req - Identifier and token from the invite email.
329
+ * @param [rawResponse] - When true, return the raw {@link Response}.
330
+ */
225
331
  acceptInvite<T = Response>(req?: {
226
332
  identifier: string;
227
333
  token: string;
228
334
  redirectUrl?: string;
229
335
  }, rawResponse?: boolean): Promise<T>;
336
+ /**
337
+ * Delete a pending invite using `DELETE /api/tenants/{tenantId}/invite/{inviteId}`.
338
+ *
339
+ * @param req - Identifier of the invite to remove.
340
+ */
230
341
  deleteInvite<T = Response>(req: string | {
231
342
  id: string;
232
343
  }): Promise<T>;
package/dist/index.js CHANGED
@@ -2512,10 +2512,23 @@ async function obtainCsrf(config, rawResponse = false) {
2512
2512
  var Users = class {
2513
2513
  #config;
2514
2514
  #logger;
2515
+ /**
2516
+ * Create a new Users helper.
2517
+ * @param config - The configuration used for requests.
2518
+ */
2515
2519
  constructor(config) {
2516
2520
  this.#config = config;
2517
2521
  this.#logger = config.logger("[me]");
2518
2522
  }
2523
+ /**
2524
+ * Update the current user via `PUT /api/me`.
2525
+ *
2526
+ * The OpenAPI description for this endpoint can be found in
2527
+ * `packages/server/src/api/routes/me/index.ts` under `updateSelf`.
2528
+ *
2529
+ * @param req - Partial user fields to send.
2530
+ * @param [rawResponse] - When `true`, return the raw {@link Response}.
2531
+ */
2519
2532
  async updateSelf(req, rawResponse) {
2520
2533
  const res = await fetchMe(this.#config, "PUT", JSON.stringify(req));
2521
2534
  if (rawResponse) {
@@ -2527,6 +2540,13 @@ var Users = class {
2527
2540
  return res;
2528
2541
  }
2529
2542
  }
2543
+ /**
2544
+ * Remove the current user using `DELETE /api/me`.
2545
+ *
2546
+ * After the request the authentication headers are cleared with
2547
+ * {@link updateHeaders}. The OpenAPI docs for this route are in
2548
+ * `packages/server/src/api/routes/me/index.ts` under `removeSelf`.
2549
+ */
2530
2550
  async removeSelf() {
2531
2551
  const me = await this.getSelf();
2532
2552
  if ("id" in me) {
@@ -2607,6 +2627,11 @@ var Tenants = class {
2607
2627
  constructor(config) {
2608
2628
  this.#config = config;
2609
2629
  }
2630
+ /**
2631
+ * Create a new tenant using `POST /api/tenants`.
2632
+ * See `packages/server/src/api/routes/tenants/POST.ts` for the
2633
+ * `createTenant` operation definition.
2634
+ */
2610
2635
  async create(req, rawResponse) {
2611
2636
  let res;
2612
2637
  if (typeof req === "string") {
@@ -2627,6 +2652,11 @@ var Tenants = class {
2627
2652
  return res;
2628
2653
  }
2629
2654
  }
2655
+ /**
2656
+ * Remove a tenant via `DELETE /api/tenants/{tenantId}`.
2657
+ *
2658
+ * @param req - The tenant to remove or context containing the id.
2659
+ */
2630
2660
  async delete(req) {
2631
2661
  if (typeof req === "string") {
2632
2662
  this.#config.tenantId = req;
@@ -2637,6 +2667,12 @@ var Tenants = class {
2637
2667
  const res = await fetchTenant(this.#config, "DELETE");
2638
2668
  return res;
2639
2669
  }
2670
+ /**
2671
+ * Fetch details for a tenant using `GET /api/tenants/{tenantId}`.
2672
+ *
2673
+ * @param req - Tenant identifier or context.
2674
+ * @param [rawResponse] - When true, return the raw {@link Response}.
2675
+ */
2640
2676
  async get(req, rawResponse) {
2641
2677
  if (typeof req === "string") {
2642
2678
  this.#config.tenantId = req;
@@ -2671,6 +2707,10 @@ var Tenants = class {
2671
2707
  return res;
2672
2708
  }
2673
2709
  }
2710
+ /**
2711
+ * List tenants for the current user via `GET /api/tenants`.
2712
+ * See `packages/server/src/api/routes/tenants/GET.ts` for details.
2713
+ */
2674
2714
  async list(req) {
2675
2715
  const res = await fetchTenantsByUser(this.#config);
2676
2716
  if (req === true) {
@@ -2682,6 +2722,11 @@ var Tenants = class {
2682
2722
  return res;
2683
2723
  }
2684
2724
  }
2725
+ /**
2726
+ * Leave the current tenant using `DELETE /api/tenants/{tenantId}/users/{userId}`.
2727
+ *
2728
+ * @param [req] - Optionally specify the tenant id to leave.
2729
+ */
2685
2730
  async leaveTenant(req) {
2686
2731
  const me = await fetchMe(this.#config);
2687
2732
  try {
@@ -2707,6 +2752,12 @@ var Tenants = class {
2707
2752
  const res = await fetchTenantUser(this.#config, "PUT");
2708
2753
  return responseHandler(res, rawResponse);
2709
2754
  }
2755
+ /**
2756
+ * Remove a user from a tenant with `DELETE /api/tenants/{tenantId}/users/{userId}`.
2757
+ *
2758
+ * @param req - User and tenant identifiers or context.
2759
+ * @param [rawResponse] - When true, return the raw {@link Response}.
2760
+ */
2710
2761
  async removeMember(req, rawResponse) {
2711
2762
  this.#handleContext(req);
2712
2763
  const res = await fetchTenantUser(this.#config, "DELETE");
@@ -2720,6 +2771,9 @@ var Tenants = class {
2720
2771
  rawResponse || typeof req === "boolean" && req
2721
2772
  );
2722
2773
  }
2774
+ /**
2775
+ * List invites for the current tenant via `GET /api/tenants/{tenantId}/invites`.
2776
+ */
2723
2777
  async invites() {
2724
2778
  const res = await fetchInvites(this.#config);
2725
2779
  return responseHandler(res);
@@ -2757,6 +2811,12 @@ var Tenants = class {
2757
2811
  );
2758
2812
  return responseHandler(res, rawResponse);
2759
2813
  }
2814
+ /**
2815
+ * Accept an invite using `PUT /api/tenants/{tenantId}/invite`.
2816
+ *
2817
+ * @param req - Identifier and token from the invite email.
2818
+ * @param [rawResponse] - When true, return the raw {@link Response}.
2819
+ */
2760
2820
  async acceptInvite(req, rawResponse) {
2761
2821
  if (!req) {
2762
2822
  throw new Error("The identifier and token are required.");
@@ -2775,6 +2835,11 @@ var Tenants = class {
2775
2835
  );
2776
2836
  return responseHandler(res, rawResponse);
2777
2837
  }
2838
+ /**
2839
+ * Delete a pending invite using `DELETE /api/tenants/{tenantId}/invite/{inviteId}`.
2840
+ *
2841
+ * @param req - Identifier of the invite to remove.
2842
+ */
2778
2843
  async deleteInvite(req) {
2779
2844
  let id = "";
2780
2845
  if (typeof req === "object") {