@niledatabase/server 5.0.0-alpha.12 → 5.0.0-alpha.14
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 +155 -43
- package/dist/index.d.ts +155 -43
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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>;
|
|
@@ -496,92 +607,93 @@ type LoggerType = {
|
|
|
496
607
|
error: (args: unknown | unknown[]) => void;
|
|
497
608
|
debug: (args: unknown | unknown[]) => void;
|
|
498
609
|
};
|
|
610
|
+
/**
|
|
611
|
+
* Configuration options used by the {@link Server} class.
|
|
612
|
+
* Most values can be provided via environment variables if not set here.
|
|
613
|
+
*/
|
|
499
614
|
type NileConfig = {
|
|
500
615
|
/**
|
|
501
|
-
*
|
|
502
|
-
*
|
|
616
|
+
* Unique ID of the database.
|
|
617
|
+
* If omitted, the value is derived from `NILEDB_API_URL`.
|
|
618
|
+
* Environment variable: `NILEDB_ID`.
|
|
503
619
|
*/
|
|
504
620
|
databaseId?: string;
|
|
505
621
|
/**
|
|
506
|
-
*
|
|
507
|
-
*
|
|
622
|
+
* Database user used for authentication.
|
|
623
|
+
* Environment variable: `NILEDB_USER`.
|
|
508
624
|
*/
|
|
509
625
|
user?: string;
|
|
510
626
|
/**
|
|
511
|
-
*
|
|
512
|
-
*
|
|
627
|
+
* Password for the configured user.
|
|
628
|
+
* Environment variable: `NILEDB_PASSWORD`.
|
|
513
629
|
*/
|
|
514
630
|
password?: string;
|
|
515
631
|
/**
|
|
516
|
-
*
|
|
517
|
-
*
|
|
632
|
+
* Database name. Defaults to the name parsed from
|
|
633
|
+
* `NILEDB_POSTGRES_URL` when not provided.
|
|
634
|
+
* Environment variable: `NILEDB_NAME`.
|
|
518
635
|
*/
|
|
519
636
|
databaseName?: string;
|
|
520
637
|
/**
|
|
521
|
-
*
|
|
522
|
-
*
|
|
638
|
+
* Tenant context used for scoping API and DB calls.
|
|
639
|
+
* Environment variable: `NILEDB_TENANT`.
|
|
523
640
|
*/
|
|
524
641
|
tenantId?: string | null | undefined;
|
|
525
642
|
/**
|
|
526
|
-
*
|
|
527
|
-
*
|
|
643
|
+
* Optional user identifier to apply when interacting with the database.
|
|
644
|
+
* In most cases nile-auth injects the logged in user automatically so this
|
|
645
|
+
* value rarely needs to be specified directly. It can be useful when
|
|
646
|
+
* performing administrative actions on behalf of another user.
|
|
528
647
|
*/
|
|
529
648
|
userId?: string | null | undefined;
|
|
530
|
-
/**
|
|
531
|
-
* Shows a bunch of logging on the server side to see what's being done between the sdk and nile-auth
|
|
532
|
-
*/
|
|
649
|
+
/** Enable verbose logging of SDK behaviour. */
|
|
533
650
|
debug?: boolean;
|
|
534
651
|
/**
|
|
535
|
-
*
|
|
652
|
+
* Optional Postgres connection configuration.
|
|
653
|
+
* Environment variables will be used for any values not set here.
|
|
536
654
|
*/
|
|
537
655
|
db?: NilePoolConfig;
|
|
538
|
-
/**
|
|
539
|
-
* Some kind of logger if you want to send to an external service
|
|
540
|
-
*/
|
|
656
|
+
/** Custom logger implementation. */
|
|
541
657
|
logger?: LogReturn;
|
|
542
658
|
/**
|
|
543
|
-
*
|
|
659
|
+
* Base URL for nile-auth requests.
|
|
660
|
+
* Environment variable: `NILEDB_API_URL`.
|
|
544
661
|
*/
|
|
545
662
|
apiUrl?: string | undefined;
|
|
546
663
|
/**
|
|
547
|
-
*
|
|
548
|
-
*
|
|
664
|
+
* Override the client provided callback URL during authentication.
|
|
665
|
+
* Environment variable: `NILEDB_CALLBACK_URL`.
|
|
549
666
|
*/
|
|
550
667
|
callbackUrl?: string | undefined;
|
|
551
|
-
/**
|
|
552
|
-
* Need to override some routes? Change it here
|
|
553
|
-
*/
|
|
668
|
+
/** Override default API routes. */
|
|
554
669
|
routes?: Partial<Routes>;
|
|
555
|
-
/**
|
|
556
|
-
* don't like the default `/api`? change it here
|
|
557
|
-
*/
|
|
670
|
+
/** Prefix applied to all generated routes. */
|
|
558
671
|
routePrefix?: string | undefined;
|
|
559
672
|
/**
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
673
|
+
* Force usage of secure cookies when communicating with nile-auth.
|
|
674
|
+
* Defaults to `true` when `NODE_ENV` is `production`.
|
|
675
|
+
* Environment variable: `NILEDB_SECURECOOKIES`.
|
|
563
676
|
*/
|
|
564
677
|
secureCookies?: boolean;
|
|
565
678
|
/**
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
679
|
+
* Origin for requests made to nile-auth. This controls where users are
|
|
680
|
+
* redirected after authentication. For single-page apps running on a
|
|
681
|
+
* different port than the API, set this to the front-end origin
|
|
682
|
+
* (e.g. `http://localhost:3001`). In a full-stack setup the value defaults
|
|
683
|
+
* to the `host` header of the incoming request. When using secure cookies on
|
|
684
|
+
* server-to-server calls, explicitly setting the origin ensures nile-auth
|
|
685
|
+
* knows whether TLS is being used and which cookies to send.
|
|
571
686
|
*/
|
|
572
687
|
origin?: null | undefined | string;
|
|
573
688
|
/**
|
|
574
|
-
*
|
|
575
|
-
*
|
|
689
|
+
* Additional headers sent with every API request.
|
|
690
|
+
* Include a `cookie` header to forward session information.
|
|
576
691
|
*/
|
|
577
692
|
headers?: null | Headers | Record<string, string>;
|
|
578
|
-
/**
|
|
579
|
-
* Functions to run at various points to make life easier
|
|
580
|
-
*/
|
|
693
|
+
/** Hooks executed before and after each request. */
|
|
581
694
|
extensions?: Extension[];
|
|
582
695
|
/**
|
|
583
|
-
*
|
|
584
|
-
* regardless of what an extension might do
|
|
696
|
+
* Preserve incoming request headers when running extensions.
|
|
585
697
|
*/
|
|
586
698
|
preserveHeaders?: boolean;
|
|
587
699
|
};
|
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>;
|
|
@@ -496,92 +607,93 @@ type LoggerType = {
|
|
|
496
607
|
error: (args: unknown | unknown[]) => void;
|
|
497
608
|
debug: (args: unknown | unknown[]) => void;
|
|
498
609
|
};
|
|
610
|
+
/**
|
|
611
|
+
* Configuration options used by the {@link Server} class.
|
|
612
|
+
* Most values can be provided via environment variables if not set here.
|
|
613
|
+
*/
|
|
499
614
|
type NileConfig = {
|
|
500
615
|
/**
|
|
501
|
-
*
|
|
502
|
-
*
|
|
616
|
+
* Unique ID of the database.
|
|
617
|
+
* If omitted, the value is derived from `NILEDB_API_URL`.
|
|
618
|
+
* Environment variable: `NILEDB_ID`.
|
|
503
619
|
*/
|
|
504
620
|
databaseId?: string;
|
|
505
621
|
/**
|
|
506
|
-
*
|
|
507
|
-
*
|
|
622
|
+
* Database user used for authentication.
|
|
623
|
+
* Environment variable: `NILEDB_USER`.
|
|
508
624
|
*/
|
|
509
625
|
user?: string;
|
|
510
626
|
/**
|
|
511
|
-
*
|
|
512
|
-
*
|
|
627
|
+
* Password for the configured user.
|
|
628
|
+
* Environment variable: `NILEDB_PASSWORD`.
|
|
513
629
|
*/
|
|
514
630
|
password?: string;
|
|
515
631
|
/**
|
|
516
|
-
*
|
|
517
|
-
*
|
|
632
|
+
* Database name. Defaults to the name parsed from
|
|
633
|
+
* `NILEDB_POSTGRES_URL` when not provided.
|
|
634
|
+
* Environment variable: `NILEDB_NAME`.
|
|
518
635
|
*/
|
|
519
636
|
databaseName?: string;
|
|
520
637
|
/**
|
|
521
|
-
*
|
|
522
|
-
*
|
|
638
|
+
* Tenant context used for scoping API and DB calls.
|
|
639
|
+
* Environment variable: `NILEDB_TENANT`.
|
|
523
640
|
*/
|
|
524
641
|
tenantId?: string | null | undefined;
|
|
525
642
|
/**
|
|
526
|
-
*
|
|
527
|
-
*
|
|
643
|
+
* Optional user identifier to apply when interacting with the database.
|
|
644
|
+
* In most cases nile-auth injects the logged in user automatically so this
|
|
645
|
+
* value rarely needs to be specified directly. It can be useful when
|
|
646
|
+
* performing administrative actions on behalf of another user.
|
|
528
647
|
*/
|
|
529
648
|
userId?: string | null | undefined;
|
|
530
|
-
/**
|
|
531
|
-
* Shows a bunch of logging on the server side to see what's being done between the sdk and nile-auth
|
|
532
|
-
*/
|
|
649
|
+
/** Enable verbose logging of SDK behaviour. */
|
|
533
650
|
debug?: boolean;
|
|
534
651
|
/**
|
|
535
|
-
*
|
|
652
|
+
* Optional Postgres connection configuration.
|
|
653
|
+
* Environment variables will be used for any values not set here.
|
|
536
654
|
*/
|
|
537
655
|
db?: NilePoolConfig;
|
|
538
|
-
/**
|
|
539
|
-
* Some kind of logger if you want to send to an external service
|
|
540
|
-
*/
|
|
656
|
+
/** Custom logger implementation. */
|
|
541
657
|
logger?: LogReturn;
|
|
542
658
|
/**
|
|
543
|
-
*
|
|
659
|
+
* Base URL for nile-auth requests.
|
|
660
|
+
* Environment variable: `NILEDB_API_URL`.
|
|
544
661
|
*/
|
|
545
662
|
apiUrl?: string | undefined;
|
|
546
663
|
/**
|
|
547
|
-
*
|
|
548
|
-
*
|
|
664
|
+
* Override the client provided callback URL during authentication.
|
|
665
|
+
* Environment variable: `NILEDB_CALLBACK_URL`.
|
|
549
666
|
*/
|
|
550
667
|
callbackUrl?: string | undefined;
|
|
551
|
-
/**
|
|
552
|
-
* Need to override some routes? Change it here
|
|
553
|
-
*/
|
|
668
|
+
/** Override default API routes. */
|
|
554
669
|
routes?: Partial<Routes>;
|
|
555
|
-
/**
|
|
556
|
-
* don't like the default `/api`? change it here
|
|
557
|
-
*/
|
|
670
|
+
/** Prefix applied to all generated routes. */
|
|
558
671
|
routePrefix?: string | undefined;
|
|
559
672
|
/**
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
673
|
+
* Force usage of secure cookies when communicating with nile-auth.
|
|
674
|
+
* Defaults to `true` when `NODE_ENV` is `production`.
|
|
675
|
+
* Environment variable: `NILEDB_SECURECOOKIES`.
|
|
563
676
|
*/
|
|
564
677
|
secureCookies?: boolean;
|
|
565
678
|
/**
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
679
|
+
* Origin for requests made to nile-auth. This controls where users are
|
|
680
|
+
* redirected after authentication. For single-page apps running on a
|
|
681
|
+
* different port than the API, set this to the front-end origin
|
|
682
|
+
* (e.g. `http://localhost:3001`). In a full-stack setup the value defaults
|
|
683
|
+
* to the `host` header of the incoming request. When using secure cookies on
|
|
684
|
+
* server-to-server calls, explicitly setting the origin ensures nile-auth
|
|
685
|
+
* knows whether TLS is being used and which cookies to send.
|
|
571
686
|
*/
|
|
572
687
|
origin?: null | undefined | string;
|
|
573
688
|
/**
|
|
574
|
-
*
|
|
575
|
-
*
|
|
689
|
+
* Additional headers sent with every API request.
|
|
690
|
+
* Include a `cookie` header to forward session information.
|
|
576
691
|
*/
|
|
577
692
|
headers?: null | Headers | Record<string, string>;
|
|
578
|
-
/**
|
|
579
|
-
* Functions to run at various points to make life easier
|
|
580
|
-
*/
|
|
693
|
+
/** Hooks executed before and after each request. */
|
|
581
694
|
extensions?: Extension[];
|
|
582
695
|
/**
|
|
583
|
-
*
|
|
584
|
-
* regardless of what an extension might do
|
|
696
|
+
* Preserve incoming request headers when running extensions.
|
|
585
697
|
*/
|
|
586
698
|
preserveHeaders?: boolean;
|
|
587
699
|
};
|