@niledatabase/server 5.0.0-alpha.1 → 5.0.0-alpha.10

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.ts CHANGED
@@ -1,5 +1,22 @@
1
1
  import pg, { PoolConfig, PoolClient } from 'pg';
2
2
 
3
+ type LogFunction = (message: string | unknown, meta?: Record<string, unknown>) => void;
4
+ type Loggable = {
5
+ info: LogFunction;
6
+ debug: LogFunction;
7
+ warn: LogFunction;
8
+ error: LogFunction;
9
+ };
10
+ type LogReturn = (prefixes?: string | string[]) => Loggable;
11
+
12
+ type ExtensionCtx = {
13
+ handleOnRequest: (config: Config, _init: RequestInit & {
14
+ request: Request;
15
+ }, params: RequestInit) => Promise<void>;
16
+ };
17
+ type ConfigConstructor = NileConfig & {
18
+ extensionCtx?: ExtensionCtx;
19
+ };
3
20
  declare class Config {
4
21
  routes: Routes;
5
22
  handlers: {
@@ -14,7 +31,9 @@ declare class Config {
14
31
  delete: string[];
15
32
  put: string[];
16
33
  };
17
- logger?: LoggerType;
34
+ extensionCtx: ExtensionCtx;
35
+ extensions?: Extension[];
36
+ logger: LogReturn;
18
37
  /**
19
38
  * Stores the set tenant id from Server for use in sub classes
20
39
  */
@@ -32,6 +51,10 @@ declare class Config {
32
51
  */
33
52
  apiUrl: string;
34
53
  origin?: string | undefined | null;
54
+ /**
55
+ * important for separating the `origin` config value from a default in order to make requests
56
+ */
57
+ serverOrigin: string;
35
58
  debug?: boolean;
36
59
  /**
37
60
  * To use secure cookies or not in the fetch
@@ -43,7 +66,7 @@ declare class Config {
43
66
  */
44
67
  routePrefix: string;
45
68
  db: NilePoolConfig;
46
- constructor(config?: NileConfig, logger?: string);
69
+ constructor(config?: ConfigConstructor);
47
70
  }
48
71
 
49
72
  type Routes = {
@@ -65,191 +88,11 @@ type Routes = {
65
88
  VERIFY_REQUEST: string;
66
89
  PASSWORD_RESET: string;
67
90
  LOG: string;
91
+ VERIFY_EMAIL: string;
92
+ INVITES: string;
93
+ INVITE: string;
68
94
  };
69
95
 
70
- type Opts = {
71
- basePath?: string;
72
- fetch?: typeof fetch;
73
- };
74
- type NilePoolConfig = PoolConfig & {
75
- afterCreate?: AfterCreate;
76
- };
77
- type LoggerType = {
78
- info?: (args: unknown | unknown[]) => void;
79
- warn?: (args: unknown | unknown[]) => void;
80
- error?: (args: unknown | unknown[]) => void;
81
- debug?: (args: unknown | unknown[]) => void;
82
- };
83
- type NileConfig = {
84
- /**
85
- * The specific database id. Either passed in or figured out by NILEDB_API_URL
86
- * process.env.NILEDB_ID
87
- */
88
- databaseId?: string;
89
- /**
90
- * The user UUID to the database
91
- * process.env.NILEDB_USER
92
- */
93
- user?: string;
94
- /**
95
- * The password UUID to the database
96
- * process.env.NILEDB_PASSWORD
97
- */
98
- password?: string;
99
- /**
100
- * The name of the database. Automatically obtained from NILEDB_POSTGRES_URL
101
- * process.env.NILEDB_NAME
102
- */
103
- databaseName?: string;
104
- /**
105
- * A tenant id. Scopes requests to a specific tenant, both API and DB
106
- * process.env.NILEDB_TENANT
107
- */
108
- tenantId?: string | null | undefined;
109
- /**
110
- * A user id. Possibly not the logged in user, used for setting database context (nile.user_id)
111
- * Generally speaking, this wouldn't be used for authentication, and in some cases simply won't do anything on some endpoints
112
- */
113
- userId?: string | null | undefined;
114
- /**
115
- * Shows a bunch of logging on the server side to see what's being done between the sdk and nile-auth
116
- */
117
- debug?: boolean;
118
- /**
119
- * DB configuration overrides. Environment variables are the way to go, but maybe you need something more
120
- */
121
- db?: NilePoolConfig;
122
- /**
123
- * Some kind of logger if you want to send to an external service
124
- */
125
- logger?: LoggerType;
126
- /**
127
- * The configuration value that maps to `NILEDB_API_URL` - its going to be nile-auth (or similar service)
128
- */
129
- apiUrl?: string | undefined;
130
- /**
131
- * Ignore client callbackUrls by setting this.
132
- * You can force the callback URL server side to be sure nile-auth redirects to whatever location.
133
- */
134
- callbackUrl?: string | undefined;
135
- /**
136
- * Need to override some routes? Change it here
137
- */
138
- routes?: Partial<Routes>;
139
- /**
140
- * don't like the default `/api`? change it here
141
- */
142
- routePrefix?: string | undefined;
143
- /**
144
- * In some cases, you may want to force secure cookies.
145
- * The SDK handles this for you, but might be necessary in some firewall / internal cases
146
- */
147
- secureCookies?: boolean;
148
- /**
149
- * The origin for the requests.
150
- * Allows the setting of the callback origin to a random FE
151
- * eg FE localhost:3001 -> BE: localhost:5432 would set to localhost:3001 to be sure nile-auth uses that.
152
- * In full stack cases, will just be the `host` header of the incoming request, which is used by default
153
- */
154
- origin?: null | undefined | string;
155
- /**
156
- * Set the headers to use in API requests.
157
- * The `cookie` would be expected if you are setting this, else most calls will be unauthorized
158
- */
159
- headers?: null | Headers | Record<string, string>;
160
- };
161
- type NileDb = NilePoolConfig & {
162
- tenantId?: string;
163
- };
164
- type AfterCreate = (conn: PoolClient, done: (err: null | Error, conn: PoolClient) => void) => void;
165
- interface NileBody<R, B> {
166
- readonly body: ReadableStream<Uint8Array> | null | B;
167
- readonly bodyUsed: boolean;
168
- arrayBuffer(): Promise<ArrayBuffer>;
169
- blob(): Promise<Blob>;
170
- formData(): Promise<FormData>;
171
- json(): Promise<R>;
172
- text(): Promise<string>;
173
- }
174
- interface NResponse<T> extends NileBody<T, any> {
175
- readonly headers: Headers;
176
- readonly ok: boolean;
177
- readonly redirected: boolean;
178
- readonly status: number;
179
- readonly statusText: string;
180
- readonly type: ResponseType;
181
- readonly url: string;
182
- clone(): Response;
183
- }
184
- interface NRequest<T> extends NileBody<any, T> {
185
- /** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. */
186
- readonly cache: RequestCache;
187
- /** Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. */
188
- readonly credentials: RequestCredentials;
189
- /** Returns the kind of resource requested by request, e.g., "document" or "script". */
190
- readonly destination: RequestDestination;
191
- /** Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. */
192
- readonly headers: Headers;
193
- /** Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] */
194
- readonly integrity: string;
195
- /** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
196
- readonly keepalive: boolean;
197
- /** Returns request's HTTP method, which is "GET" by default. */
198
- readonly method: string;
199
- /** Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs. */
200
- readonly mode: RequestMode;
201
- /** Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default. */
202
- readonly redirect: RequestRedirect;
203
- /** Returns the referrer of request. Its value can be a same-origin URL if explicitly set in init, the empty string to indicate no referrer, and "about:client" when defaulting to the global's default. This is used during fetching to determine the value of the `Referer` header of the request being made. */
204
- readonly referrer: string;
205
- /** Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer. */
206
- readonly referrerPolicy: ReferrerPolicy;
207
- /** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
208
- readonly signal: AbortSignal;
209
- /** Returns the URL of request as a string. */
210
- readonly url: string;
211
- clone(): Request;
212
- }
213
- type NileRequest<T> = NRequest<T> | T;
214
- declare const APIErrorErrorCodeEnum: {
215
- readonly InternalError: "internal_error";
216
- readonly BadRequest: "bad_request";
217
- readonly EntityNotFound: "entity_not_found";
218
- readonly DuplicateEntity: "duplicate_entity";
219
- readonly InvalidCredentials: "invalid_credentials";
220
- readonly UnknownOidcProvider: "unknown_oidc_provider";
221
- readonly ProviderAlreadyExists: "provider_already_exists";
222
- readonly ProviderConfigError: "provider_config_error";
223
- readonly ProviderMismatch: "provider_mismatch";
224
- readonly ProviderUpdateError: "provider_update_error";
225
- readonly SessionStateMissing: "session_state_missing";
226
- readonly SessionStateMismatch: "session_state_mismatch";
227
- readonly OidcCodeMissing: "oidc_code_missing";
228
- };
229
- type APIErrorErrorCodeEnum = (typeof APIErrorErrorCodeEnum)[keyof typeof APIErrorErrorCodeEnum];
230
- interface APIError {
231
- [key: string]: any | any;
232
- /**
233
- *
234
- * @type {string}
235
- * @memberof APIError
236
- */
237
- errorCode: APIErrorErrorCodeEnum;
238
- /**
239
- *
240
- * @type {string}
241
- * @memberof APIError
242
- */
243
- message: string;
244
- /**
245
- *
246
- * @type {number}
247
- * @memberof APIError
248
- */
249
- statusCode: number;
250
- }
251
- type NileResponse<T> = Promise<T | NResponse<T & APIError>>;
252
-
253
96
  interface CreateBasicUserRequest {
254
97
  email: string;
255
98
  password: string;
@@ -297,49 +140,37 @@ interface User {
297
140
  tenants: string[];
298
141
  }
299
142
 
300
- type Tenant = {
301
- id: string;
302
- name: string;
303
- };
304
-
305
- type ProviderName = 'discord' | 'github' | 'google' | 'hubspot' | 'linkedin' | 'slack' | 'twitter' | 'email' | 'credentials' | 'azure';
306
- type Provider = {
307
- id: string;
308
- name: string;
309
- type: string;
310
- signinUrl: string;
311
- callbackUrl: string;
312
- };
313
- type JWT = {
314
- email: string;
315
- sub: string;
316
- id: string;
317
- iat: number;
318
- exp: number;
319
- jti: string;
320
- };
321
- type ActiveSession = {
322
- id: string;
323
- email: string;
324
- expires: string;
325
- user?: {
326
- id: string;
327
- name: string;
328
- image: string;
329
- email: string;
330
- emailVerified: void | Date;
331
- };
332
- };
333
-
334
143
  declare class Users {
335
144
  #private;
336
145
  constructor(config: Config);
337
- updateSelf<T = User[] | Response>(req: Partial<Omit<User, 'email' | 'tenants' | 'created' | 'updated'>>, rawResponse?: boolean): Promise<T>;
146
+ updateSelf<T = User[] | Response>(req: Partial<Omit<User, 'email' | 'tenants' | 'created' | 'updated' | 'emailVerified'> & {
147
+ emailVerified: boolean;
148
+ }>, rawResponse?: boolean): Promise<T>;
338
149
  removeSelf(): Promise<Response>;
339
- getSelf(rawResponse?: true): Promise<Response>;
340
150
  getSelf<T = User | Response>(): Promise<T>;
151
+ getSelf(rawResponse?: true): Promise<Response>;
152
+ verifySelf<T = void>(): Promise<T>;
153
+ verifySelf(rawResponse: true): Promise<Response>;
154
+ verifySelf<T = Response | User>(options: {
155
+ bypassEmail?: boolean;
156
+ callbackUrl?: string;
157
+ }, rawResponse?: true): Promise<T>;
341
158
  }
342
159
 
160
+ type Tenant = {
161
+ id: string;
162
+ name: string;
163
+ };
164
+ type Invite = {
165
+ id: string;
166
+ tenant_id: string;
167
+ token: string;
168
+ identifier: string;
169
+ roles: null | string;
170
+ created_by: string;
171
+ expires: Date;
172
+ };
173
+
343
174
  type ReqContext = {
344
175
  userId?: string;
345
176
  tenantId?: string;
@@ -350,6 +181,7 @@ type JoinTenantRequest = string | ReqContext | {
350
181
  declare class Tenants {
351
182
  #private;
352
183
  constructor(config: Config);
184
+ create(name: string, rawResponse: true): Promise<Response>;
353
185
  create<T = Tenant | Response>(name: string, rawResponse?: boolean): Promise<T>;
354
186
  create<T = Tenant | Response>(payload: {
355
187
  name: string;
@@ -359,27 +191,79 @@ declare class Tenants {
359
191
  delete<T = Response>(payload: {
360
192
  id: string;
361
193
  }): Promise<T>;
362
- get(rawResponse: true): Promise<Response>;
194
+ get<T = Tenant | Response>(): Promise<T>;
363
195
  get<T = Tenant | Response>(id: string, rawResponse?: boolean): Promise<T>;
196
+ get(rawResponse: true): Promise<Response>;
364
197
  get<T = Tenant | Response>(payload: {
365
198
  id: string;
366
199
  }, rawResponse?: boolean): Promise<T>;
367
200
  update(req: Partial<Tenant>, rawResponse: true): Promise<Response>;
368
201
  update<T = Tenant | Response | undefined>(req: Partial<Tenant>, rawResponse?: boolean): Promise<T>;
369
- list(rawResponse: true): Promise<Response>;
370
202
  list<T = Tenant[] | Response>(): Promise<T>;
203
+ list(rawResponse: true): Promise<Response>;
371
204
  leaveTenant<T = Response>(req?: string | {
372
205
  tenantId: string;
373
206
  }): Promise<T>;
374
207
  addMember(req: JoinTenantRequest, rawResponse: true): Promise<Response>;
375
208
  addMember<T = User | Response>(req: JoinTenantRequest, rawResponse?: boolean): Promise<T>;
376
209
  removeMember(req: JoinTenantRequest, rawResponse?: boolean): Promise<Response>;
377
- users(req: boolean): Promise<Response>;
378
210
  users<T = User[] | Response>(req?: boolean | {
379
211
  tenantId?: string;
380
212
  }, rawResponse?: boolean): Promise<T>;
213
+ users(req: true): Promise<Response>;
214
+ invites<T = Invite[] | Response>(): Promise<T>;
215
+ invite<T = Response | Invite>(req: string | {
216
+ email: string;
217
+ callbackUrl?: string;
218
+ redirectUrl?: string;
219
+ }, rawResponse?: boolean): Promise<T>;
220
+ invite(req: string | {
221
+ email: string;
222
+ callbackUrl?: string;
223
+ redirectUrl?: string;
224
+ }, rawResponse: true): Promise<Response>;
225
+ acceptInvite<T = Response>(req?: {
226
+ identifier: string;
227
+ token: string;
228
+ redirectUrl?: string;
229
+ }, rawResponse?: boolean): Promise<T>;
230
+ deleteInvite<T = Response>(req: string | {
231
+ id: string;
232
+ }): Promise<T>;
381
233
  }
382
234
 
235
+ type ProviderName = 'discord' | 'github' | 'google' | 'hubspot' | 'linkedin' | 'slack' | 'twitter' | 'email' | 'credentials' | 'azure';
236
+ type Providers = {
237
+ [providerName in ProviderName]: Provider;
238
+ };
239
+ type Provider = {
240
+ id: string;
241
+ name: string;
242
+ type: string;
243
+ signinUrl: string;
244
+ callbackUrl: string;
245
+ };
246
+ type JWT = {
247
+ email: string;
248
+ sub: string;
249
+ id: string;
250
+ iat: number;
251
+ exp: number;
252
+ jti: string;
253
+ };
254
+ type ActiveSession = {
255
+ id: string;
256
+ email: string;
257
+ expires: string;
258
+ user?: {
259
+ id: string;
260
+ name: string;
261
+ image: string;
262
+ email: string;
263
+ emailVerified: void | Date;
264
+ };
265
+ };
266
+
383
267
  type SignUpPayload = {
384
268
  email: string;
385
269
  password: string;
@@ -389,10 +273,10 @@ type SignUpPayload = {
389
273
  declare class Auth {
390
274
  #private;
391
275
  constructor(config: Config);
392
- getSession(rawResponse: true): Promise<Response>;
393
276
  getSession<T = JWT | ActiveSession | undefined>(rawResponse?: false): Promise<T>;
394
- getCsrf(rawResponse: true): Promise<Response>;
277
+ getSession(rawResponse: true): Promise<Response>;
395
278
  getCsrf<T = Response | JSON>(rawResponse?: false): Promise<T>;
279
+ getCsrf(rawResponse: true): Promise<Response>;
396
280
  listProviders(rawResponse: true): Promise<Response>;
397
281
  listProviders<T = {
398
282
  [key: string]: Provider;
@@ -405,13 +289,25 @@ declare class Auth {
405
289
  */
406
290
  signUp(payload: SignUpPayload, rawResponse: true): Promise<Response>;
407
291
  signUp<T = User | Response>(payload: SignUpPayload): Promise<T>;
292
+ forgotPassword(req: {
293
+ email: string;
294
+ callbackUrl?: string;
295
+ redirectUrl?: string;
296
+ }): Promise<Response>;
297
+ resetPassword(req: Request | {
298
+ email: string;
299
+ password: string;
300
+ callbackUrl?: string;
301
+ redirectUrl?: string;
302
+ }): Promise<Response>;
303
+ callback(provider: ProviderName, body?: string | Request): Promise<Response>;
408
304
  /**
409
305
  * The return value from this will be a redirect for the client
410
306
  * In most cases, you should forward the response directly to the client
411
307
  * @param payload
412
308
  * @param rawResponse
413
309
  */
414
- signIn<T = Response>(provider: ProviderName, payload?: {
310
+ signIn<T = Response>(provider: ProviderName, payload?: Request | {
415
311
  email: string;
416
312
  password: string;
417
313
  }, rawResponse?: true): Promise<T>;
@@ -480,8 +376,215 @@ declare class Server {
480
376
  headers: Headers | undefined;
481
377
  userId: string | null | undefined;
482
378
  tenantId: string | null | undefined;
379
+ preserveHeaders: boolean;
483
380
  };
484
381
  }
485
382
  declare function create(config?: NileConfig): Server;
486
383
 
487
- export { type APIError, APIErrorErrorCodeEnum, type ActiveSession, type AfterCreate, type CreateBasicUserRequest, type CreateTenantUserRequest, type JWT, type LoggerType, type LoginUserResponse, type LoginUserResponseToken, LoginUserResponseTokenTypeEnum, create as Nile, type NileConfig, type NileDb, type NilePoolConfig, type NileRequest, type NileResponse, type Opts, Server, type Tenant, type User, parseCSRF, parseCallback, parseToken };
384
+ type Opts = {
385
+ basePath?: string;
386
+ fetch?: typeof fetch;
387
+ };
388
+ interface ExtensionResult {
389
+ id?: string;
390
+ [key: string]: unknown;
391
+ onRequest?: (req: Request) => void | Promise<void | RequestInit>;
392
+ onResponse?: (res: Response) => void | Promise<void>;
393
+ }
394
+ type Extension = (instance: Server) => ExtensionResult | Promise<ExtensionResult>;
395
+ type NilePoolConfig = PoolConfig & {
396
+ afterCreate?: AfterCreate;
397
+ };
398
+ type LoggerType = {
399
+ info: (args: unknown | unknown[]) => void;
400
+ warn: (args: unknown | unknown[]) => void;
401
+ error: (args: unknown | unknown[]) => void;
402
+ debug: (args: unknown | unknown[]) => void;
403
+ };
404
+ type NileConfig = {
405
+ /**
406
+ * The specific database id. Either passed in or figured out by NILEDB_API_URL
407
+ * process.env.NILEDB_ID
408
+ */
409
+ databaseId?: string;
410
+ /**
411
+ * The user UUID to the database
412
+ * process.env.NILEDB_USER
413
+ */
414
+ user?: string;
415
+ /**
416
+ * The password UUID to the database
417
+ * process.env.NILEDB_PASSWORD
418
+ */
419
+ password?: string;
420
+ /**
421
+ * The name of the database. Automatically obtained from NILEDB_POSTGRES_URL
422
+ * process.env.NILEDB_NAME
423
+ */
424
+ databaseName?: string;
425
+ /**
426
+ * A tenant id. Scopes requests to a specific tenant, both API and DB
427
+ * process.env.NILEDB_TENANT
428
+ */
429
+ tenantId?: string | null | undefined;
430
+ /**
431
+ * A user id. Possibly not the logged in user, used for setting database context (nile.user_id)
432
+ * Generally speaking, this wouldn't be used for authentication, and in some cases simply won't do anything on some endpoints
433
+ */
434
+ userId?: string | null | undefined;
435
+ /**
436
+ * Shows a bunch of logging on the server side to see what's being done between the sdk and nile-auth
437
+ */
438
+ debug?: boolean;
439
+ /**
440
+ * DB configuration overrides. Environment variables are the way to go, but maybe you need something more
441
+ */
442
+ db?: NilePoolConfig;
443
+ /**
444
+ * Some kind of logger if you want to send to an external service
445
+ */
446
+ logger?: LogReturn;
447
+ /**
448
+ * The configuration value that maps to `NILEDB_API_URL` - its going to be nile-auth (or similar service)
449
+ */
450
+ apiUrl?: string | undefined;
451
+ /**
452
+ * Ignore client callbackUrls by setting this.
453
+ * You can force the callback URL server side to be sure nile-auth redirects to whatever location.
454
+ */
455
+ callbackUrl?: string | undefined;
456
+ /**
457
+ * Need to override some routes? Change it here
458
+ */
459
+ routes?: Partial<Routes>;
460
+ /**
461
+ * don't like the default `/api`? change it here
462
+ */
463
+ routePrefix?: string | undefined;
464
+ /**
465
+ * In some cases, you may want to force secure cookies.
466
+ * The SDK handles this for you, but might be necessary in some firewall / internal cases
467
+ * Defaults to true if you're in production
468
+ */
469
+ secureCookies?: boolean;
470
+ /**
471
+ * The origin for the requests.
472
+ * Allows the setting of the callback origin to a random FE
473
+ * eg FE localhost:3001 -> BE: localhost:5432 would set to localhost:3001 to be sure nile-auth uses that.
474
+ * In full stack cases, will just be the `host` header of the incoming request, which is used by default
475
+ * It is also important to set this when dealing with secure cookies. Calling via server side needs to know if TLS is being used so that nile-auth knows which cookies to be sent.
476
+ */
477
+ origin?: null | undefined | string;
478
+ /**
479
+ * Set the headers to use in API requests.
480
+ * The `cookie` would be expected if you are setting this, else most calls will be unauthorized
481
+ */
482
+ headers?: null | Headers | Record<string, string>;
483
+ /**
484
+ * Functions to run at various points to make life easier
485
+ */
486
+ extensions?: Extension[];
487
+ /**
488
+ * In some cases, like when using REST context, we want to preserve the headers from the request,
489
+ * regardless of what an extension might do
490
+ */
491
+ preserveHeaders?: boolean;
492
+ };
493
+ type NileDb = NilePoolConfig & {
494
+ tenantId?: string;
495
+ };
496
+ type AfterCreate = (conn: PoolClient, done: (err: null | Error, conn: PoolClient) => void) => void;
497
+ interface NileBody<R, B> {
498
+ readonly body: ReadableStream<Uint8Array> | null | B;
499
+ readonly bodyUsed: boolean;
500
+ arrayBuffer(): Promise<ArrayBuffer>;
501
+ blob(): Promise<Blob>;
502
+ formData(): Promise<FormData>;
503
+ json(): Promise<R>;
504
+ text(): Promise<string>;
505
+ }
506
+ interface NResponse<T> extends NileBody<T, any> {
507
+ readonly headers: Headers;
508
+ readonly ok: boolean;
509
+ readonly redirected: boolean;
510
+ readonly status: number;
511
+ readonly statusText: string;
512
+ readonly type: ResponseType;
513
+ readonly url: string;
514
+ clone(): Response;
515
+ }
516
+ interface NRequest<T> extends NileBody<any, T> {
517
+ /** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. */
518
+ readonly cache: RequestCache;
519
+ /** Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. */
520
+ readonly credentials: RequestCredentials;
521
+ /** Returns the kind of resource requested by request, e.g., "document" or "script". */
522
+ readonly destination: RequestDestination;
523
+ /** Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. */
524
+ readonly headers: Headers;
525
+ /** Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] */
526
+ readonly integrity: string;
527
+ /** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
528
+ readonly keepalive: boolean;
529
+ /** Returns request's HTTP method, which is "GET" by default. */
530
+ readonly method: string;
531
+ /** Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs. */
532
+ readonly mode: RequestMode;
533
+ /** Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default. */
534
+ readonly redirect: RequestRedirect;
535
+ /** Returns the referrer of request. Its value can be a same-origin URL if explicitly set in init, the empty string to indicate no referrer, and "about:client" when defaulting to the global's default. This is used during fetching to determine the value of the `Referer` header of the request being made. */
536
+ readonly referrer: string;
537
+ /** Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer. */
538
+ readonly referrerPolicy: ReferrerPolicy;
539
+ /** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
540
+ readonly signal: AbortSignal;
541
+ /** Returns the URL of request as a string. */
542
+ readonly url: string;
543
+ clone(): Request;
544
+ }
545
+ type NileRequest<T> = NRequest<T> | T;
546
+ declare const APIErrorErrorCodeEnum: {
547
+ readonly InternalError: "internal_error";
548
+ readonly BadRequest: "bad_request";
549
+ readonly EntityNotFound: "entity_not_found";
550
+ readonly DuplicateEntity: "duplicate_entity";
551
+ readonly InvalidCredentials: "invalid_credentials";
552
+ readonly UnknownOidcProvider: "unknown_oidc_provider";
553
+ readonly ProviderAlreadyExists: "provider_already_exists";
554
+ readonly ProviderConfigError: "provider_config_error";
555
+ readonly ProviderMismatch: "provider_mismatch";
556
+ readonly ProviderUpdateError: "provider_update_error";
557
+ readonly SessionStateMissing: "session_state_missing";
558
+ readonly SessionStateMismatch: "session_state_mismatch";
559
+ readonly OidcCodeMissing: "oidc_code_missing";
560
+ };
561
+ type APIErrorErrorCodeEnum = (typeof APIErrorErrorCodeEnum)[keyof typeof APIErrorErrorCodeEnum];
562
+ interface APIError {
563
+ [key: string]: any | any;
564
+ /**
565
+ *
566
+ * @type {string}
567
+ * @memberof APIError
568
+ */
569
+ errorCode: APIErrorErrorCodeEnum;
570
+ /**
571
+ *
572
+ * @type {string}
573
+ * @memberof APIError
574
+ */
575
+ message: string;
576
+ /**
577
+ *
578
+ * @type {number}
579
+ * @memberof APIError
580
+ */
581
+ statusCode: number;
582
+ }
583
+ type NileResponse<T> = Promise<T | NResponse<T & APIError>>;
584
+
585
+ declare const TENANT_COOKIE = "nile.tenant-id";
586
+ declare const USER_COOKIE = "nile.user-id";
587
+ declare const HEADER_ORIGIN = "nile-origin";
588
+ declare const HEADER_SECURE_COOKIES = "nile-secure-cookies";
589
+
590
+ export { type APIError, APIErrorErrorCodeEnum, type ActiveSession, type AfterCreate, type CreateBasicUserRequest, type CreateTenantUserRequest, type Extension, type ExtensionResult, HEADER_ORIGIN, HEADER_SECURE_COOKIES, type Invite, type JWT, type LoggerType, type LoginUserResponse, type LoginUserResponseToken, LoginUserResponseTokenTypeEnum, create as Nile, type NileConfig, type NileDb, type NilePoolConfig, type NileRequest, type NileResponse, type Opts, type Providers, Server, TENANT_COOKIE, type Tenant, USER_COOKIE, type User, parseCSRF, parseCallback, parseToken };