@niledatabase/server 5.0.0-alpha.1 → 5.0.0-alpha.3
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/express.js +102 -48
- package/dist/express.js.map +1 -1
- package/dist/express.mjs +102 -48
- package/dist/express.mjs.map +1 -1
- package/dist/index.d.mts +35 -9
- package/dist/index.d.ts +35 -9
- package/dist/index.js +686 -385
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +686 -385
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -32,6 +32,10 @@ declare class Config {
|
|
|
32
32
|
*/
|
|
33
33
|
apiUrl: string;
|
|
34
34
|
origin?: string | undefined | null;
|
|
35
|
+
/**
|
|
36
|
+
* important for separating the `origin` config value from a default in order to make requests
|
|
37
|
+
*/
|
|
38
|
+
serverOrigin: string;
|
|
35
39
|
debug?: boolean;
|
|
36
40
|
/**
|
|
37
41
|
* To use secure cookies or not in the fetch
|
|
@@ -65,6 +69,7 @@ type Routes = {
|
|
|
65
69
|
VERIFY_REQUEST: string;
|
|
66
70
|
PASSWORD_RESET: string;
|
|
67
71
|
LOG: string;
|
|
72
|
+
VERIFY_EMAIL: string;
|
|
68
73
|
};
|
|
69
74
|
|
|
70
75
|
type Opts = {
|
|
@@ -143,6 +148,7 @@ type NileConfig = {
|
|
|
143
148
|
/**
|
|
144
149
|
* In some cases, you may want to force secure cookies.
|
|
145
150
|
* The SDK handles this for you, but might be necessary in some firewall / internal cases
|
|
151
|
+
* Defaults to true if you're in production
|
|
146
152
|
*/
|
|
147
153
|
secureCookies?: boolean;
|
|
148
154
|
/**
|
|
@@ -150,6 +156,7 @@ type NileConfig = {
|
|
|
150
156
|
* Allows the setting of the callback origin to a random FE
|
|
151
157
|
* eg FE localhost:3001 -> BE: localhost:5432 would set to localhost:3001 to be sure nile-auth uses that.
|
|
152
158
|
* In full stack cases, will just be the `host` header of the incoming request, which is used by default
|
|
159
|
+
* 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.
|
|
153
160
|
*/
|
|
154
161
|
origin?: null | undefined | string;
|
|
155
162
|
/**
|
|
@@ -303,6 +310,9 @@ type Tenant = {
|
|
|
303
310
|
};
|
|
304
311
|
|
|
305
312
|
type ProviderName = 'discord' | 'github' | 'google' | 'hubspot' | 'linkedin' | 'slack' | 'twitter' | 'email' | 'credentials' | 'azure';
|
|
313
|
+
type Providers = {
|
|
314
|
+
[providerName in ProviderName]: Provider;
|
|
315
|
+
};
|
|
306
316
|
type Provider = {
|
|
307
317
|
id: string;
|
|
308
318
|
name: string;
|
|
@@ -334,10 +344,14 @@ type ActiveSession = {
|
|
|
334
344
|
declare class Users {
|
|
335
345
|
#private;
|
|
336
346
|
constructor(config: Config);
|
|
337
|
-
updateSelf<T = User[] | Response>(req: Partial<Omit<User, 'email' | 'tenants' | 'created' | 'updated'
|
|
347
|
+
updateSelf<T = User[] | Response>(req: Partial<Omit<User, 'email' | 'tenants' | 'created' | 'updated' | 'emailVerified'> & {
|
|
348
|
+
emailVerified: boolean;
|
|
349
|
+
}>, rawResponse?: boolean): Promise<T>;
|
|
338
350
|
removeSelf(): Promise<Response>;
|
|
339
|
-
getSelf(rawResponse?: true): Promise<Response>;
|
|
340
351
|
getSelf<T = User | Response>(): Promise<T>;
|
|
352
|
+
getSelf(rawResponse?: true): Promise<Response>;
|
|
353
|
+
verifySelf<T = Response | void>(): Promise<T>;
|
|
354
|
+
verifySelf(rawResponse?: true): Promise<Response>;
|
|
341
355
|
}
|
|
342
356
|
|
|
343
357
|
type ReqContext = {
|
|
@@ -359,25 +373,25 @@ declare class Tenants {
|
|
|
359
373
|
delete<T = Response>(payload: {
|
|
360
374
|
id: string;
|
|
361
375
|
}): Promise<T>;
|
|
362
|
-
get(rawResponse: true): Promise<Response>;
|
|
363
376
|
get<T = Tenant | Response>(id: string, rawResponse?: boolean): Promise<T>;
|
|
377
|
+
get(rawResponse: true): Promise<Response>;
|
|
364
378
|
get<T = Tenant | Response>(payload: {
|
|
365
379
|
id: string;
|
|
366
380
|
}, rawResponse?: boolean): Promise<T>;
|
|
367
381
|
update(req: Partial<Tenant>, rawResponse: true): Promise<Response>;
|
|
368
382
|
update<T = Tenant | Response | undefined>(req: Partial<Tenant>, rawResponse?: boolean): Promise<T>;
|
|
369
|
-
list(rawResponse: true): Promise<Response>;
|
|
370
383
|
list<T = Tenant[] | Response>(): Promise<T>;
|
|
384
|
+
list(rawResponse: true): Promise<Response>;
|
|
371
385
|
leaveTenant<T = Response>(req?: string | {
|
|
372
386
|
tenantId: string;
|
|
373
387
|
}): Promise<T>;
|
|
374
388
|
addMember(req: JoinTenantRequest, rawResponse: true): Promise<Response>;
|
|
375
389
|
addMember<T = User | Response>(req: JoinTenantRequest, rawResponse?: boolean): Promise<T>;
|
|
376
390
|
removeMember(req: JoinTenantRequest, rawResponse?: boolean): Promise<Response>;
|
|
377
|
-
users(req: boolean): Promise<Response>;
|
|
378
391
|
users<T = User[] | Response>(req?: boolean | {
|
|
379
392
|
tenantId?: string;
|
|
380
393
|
}, rawResponse?: boolean): Promise<T>;
|
|
394
|
+
users(req: true): Promise<Response>;
|
|
381
395
|
}
|
|
382
396
|
|
|
383
397
|
type SignUpPayload = {
|
|
@@ -389,10 +403,10 @@ type SignUpPayload = {
|
|
|
389
403
|
declare class Auth {
|
|
390
404
|
#private;
|
|
391
405
|
constructor(config: Config);
|
|
392
|
-
getSession(rawResponse: true): Promise<Response>;
|
|
393
406
|
getSession<T = JWT | ActiveSession | undefined>(rawResponse?: false): Promise<T>;
|
|
394
|
-
|
|
407
|
+
getSession(rawResponse: true): Promise<Response>;
|
|
395
408
|
getCsrf<T = Response | JSON>(rawResponse?: false): Promise<T>;
|
|
409
|
+
getCsrf(rawResponse: true): Promise<Response>;
|
|
396
410
|
listProviders(rawResponse: true): Promise<Response>;
|
|
397
411
|
listProviders<T = {
|
|
398
412
|
[key: string]: Provider;
|
|
@@ -405,13 +419,25 @@ declare class Auth {
|
|
|
405
419
|
*/
|
|
406
420
|
signUp(payload: SignUpPayload, rawResponse: true): Promise<Response>;
|
|
407
421
|
signUp<T = User | Response>(payload: SignUpPayload): Promise<T>;
|
|
422
|
+
forgotPassword(req: {
|
|
423
|
+
email: string;
|
|
424
|
+
callbackUrl?: string;
|
|
425
|
+
redirectUrl?: string;
|
|
426
|
+
}): Promise<Response>;
|
|
427
|
+
resetPassword(req: Request | {
|
|
428
|
+
email: string;
|
|
429
|
+
password: string;
|
|
430
|
+
callbackUrl?: string;
|
|
431
|
+
redirectUrl?: string;
|
|
432
|
+
}): Promise<Response>;
|
|
433
|
+
callback(provider: ProviderName, body?: string | Request): Promise<Response>;
|
|
408
434
|
/**
|
|
409
435
|
* The return value from this will be a redirect for the client
|
|
410
436
|
* In most cases, you should forward the response directly to the client
|
|
411
437
|
* @param payload
|
|
412
438
|
* @param rawResponse
|
|
413
439
|
*/
|
|
414
|
-
signIn<T = Response>(provider: ProviderName, payload?: {
|
|
440
|
+
signIn<T = Response>(provider: ProviderName, payload?: Request | {
|
|
415
441
|
email: string;
|
|
416
442
|
password: string;
|
|
417
443
|
}, rawResponse?: true): Promise<T>;
|
|
@@ -484,4 +510,4 @@ declare class Server {
|
|
|
484
510
|
}
|
|
485
511
|
declare function create(config?: NileConfig): Server;
|
|
486
512
|
|
|
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 };
|
|
513
|
+
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, type Providers, Server, type Tenant, type User, parseCSRF, parseCallback, parseToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ declare class Config {
|
|
|
32
32
|
*/
|
|
33
33
|
apiUrl: string;
|
|
34
34
|
origin?: string | undefined | null;
|
|
35
|
+
/**
|
|
36
|
+
* important for separating the `origin` config value from a default in order to make requests
|
|
37
|
+
*/
|
|
38
|
+
serverOrigin: string;
|
|
35
39
|
debug?: boolean;
|
|
36
40
|
/**
|
|
37
41
|
* To use secure cookies or not in the fetch
|
|
@@ -65,6 +69,7 @@ type Routes = {
|
|
|
65
69
|
VERIFY_REQUEST: string;
|
|
66
70
|
PASSWORD_RESET: string;
|
|
67
71
|
LOG: string;
|
|
72
|
+
VERIFY_EMAIL: string;
|
|
68
73
|
};
|
|
69
74
|
|
|
70
75
|
type Opts = {
|
|
@@ -143,6 +148,7 @@ type NileConfig = {
|
|
|
143
148
|
/**
|
|
144
149
|
* In some cases, you may want to force secure cookies.
|
|
145
150
|
* The SDK handles this for you, but might be necessary in some firewall / internal cases
|
|
151
|
+
* Defaults to true if you're in production
|
|
146
152
|
*/
|
|
147
153
|
secureCookies?: boolean;
|
|
148
154
|
/**
|
|
@@ -150,6 +156,7 @@ type NileConfig = {
|
|
|
150
156
|
* Allows the setting of the callback origin to a random FE
|
|
151
157
|
* eg FE localhost:3001 -> BE: localhost:5432 would set to localhost:3001 to be sure nile-auth uses that.
|
|
152
158
|
* In full stack cases, will just be the `host` header of the incoming request, which is used by default
|
|
159
|
+
* 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.
|
|
153
160
|
*/
|
|
154
161
|
origin?: null | undefined | string;
|
|
155
162
|
/**
|
|
@@ -303,6 +310,9 @@ type Tenant = {
|
|
|
303
310
|
};
|
|
304
311
|
|
|
305
312
|
type ProviderName = 'discord' | 'github' | 'google' | 'hubspot' | 'linkedin' | 'slack' | 'twitter' | 'email' | 'credentials' | 'azure';
|
|
313
|
+
type Providers = {
|
|
314
|
+
[providerName in ProviderName]: Provider;
|
|
315
|
+
};
|
|
306
316
|
type Provider = {
|
|
307
317
|
id: string;
|
|
308
318
|
name: string;
|
|
@@ -334,10 +344,14 @@ type ActiveSession = {
|
|
|
334
344
|
declare class Users {
|
|
335
345
|
#private;
|
|
336
346
|
constructor(config: Config);
|
|
337
|
-
updateSelf<T = User[] | Response>(req: Partial<Omit<User, 'email' | 'tenants' | 'created' | 'updated'
|
|
347
|
+
updateSelf<T = User[] | Response>(req: Partial<Omit<User, 'email' | 'tenants' | 'created' | 'updated' | 'emailVerified'> & {
|
|
348
|
+
emailVerified: boolean;
|
|
349
|
+
}>, rawResponse?: boolean): Promise<T>;
|
|
338
350
|
removeSelf(): Promise<Response>;
|
|
339
|
-
getSelf(rawResponse?: true): Promise<Response>;
|
|
340
351
|
getSelf<T = User | Response>(): Promise<T>;
|
|
352
|
+
getSelf(rawResponse?: true): Promise<Response>;
|
|
353
|
+
verifySelf<T = Response | void>(): Promise<T>;
|
|
354
|
+
verifySelf(rawResponse?: true): Promise<Response>;
|
|
341
355
|
}
|
|
342
356
|
|
|
343
357
|
type ReqContext = {
|
|
@@ -359,25 +373,25 @@ declare class Tenants {
|
|
|
359
373
|
delete<T = Response>(payload: {
|
|
360
374
|
id: string;
|
|
361
375
|
}): Promise<T>;
|
|
362
|
-
get(rawResponse: true): Promise<Response>;
|
|
363
376
|
get<T = Tenant | Response>(id: string, rawResponse?: boolean): Promise<T>;
|
|
377
|
+
get(rawResponse: true): Promise<Response>;
|
|
364
378
|
get<T = Tenant | Response>(payload: {
|
|
365
379
|
id: string;
|
|
366
380
|
}, rawResponse?: boolean): Promise<T>;
|
|
367
381
|
update(req: Partial<Tenant>, rawResponse: true): Promise<Response>;
|
|
368
382
|
update<T = Tenant | Response | undefined>(req: Partial<Tenant>, rawResponse?: boolean): Promise<T>;
|
|
369
|
-
list(rawResponse: true): Promise<Response>;
|
|
370
383
|
list<T = Tenant[] | Response>(): Promise<T>;
|
|
384
|
+
list(rawResponse: true): Promise<Response>;
|
|
371
385
|
leaveTenant<T = Response>(req?: string | {
|
|
372
386
|
tenantId: string;
|
|
373
387
|
}): Promise<T>;
|
|
374
388
|
addMember(req: JoinTenantRequest, rawResponse: true): Promise<Response>;
|
|
375
389
|
addMember<T = User | Response>(req: JoinTenantRequest, rawResponse?: boolean): Promise<T>;
|
|
376
390
|
removeMember(req: JoinTenantRequest, rawResponse?: boolean): Promise<Response>;
|
|
377
|
-
users(req: boolean): Promise<Response>;
|
|
378
391
|
users<T = User[] | Response>(req?: boolean | {
|
|
379
392
|
tenantId?: string;
|
|
380
393
|
}, rawResponse?: boolean): Promise<T>;
|
|
394
|
+
users(req: true): Promise<Response>;
|
|
381
395
|
}
|
|
382
396
|
|
|
383
397
|
type SignUpPayload = {
|
|
@@ -389,10 +403,10 @@ type SignUpPayload = {
|
|
|
389
403
|
declare class Auth {
|
|
390
404
|
#private;
|
|
391
405
|
constructor(config: Config);
|
|
392
|
-
getSession(rawResponse: true): Promise<Response>;
|
|
393
406
|
getSession<T = JWT | ActiveSession | undefined>(rawResponse?: false): Promise<T>;
|
|
394
|
-
|
|
407
|
+
getSession(rawResponse: true): Promise<Response>;
|
|
395
408
|
getCsrf<T = Response | JSON>(rawResponse?: false): Promise<T>;
|
|
409
|
+
getCsrf(rawResponse: true): Promise<Response>;
|
|
396
410
|
listProviders(rawResponse: true): Promise<Response>;
|
|
397
411
|
listProviders<T = {
|
|
398
412
|
[key: string]: Provider;
|
|
@@ -405,13 +419,25 @@ declare class Auth {
|
|
|
405
419
|
*/
|
|
406
420
|
signUp(payload: SignUpPayload, rawResponse: true): Promise<Response>;
|
|
407
421
|
signUp<T = User | Response>(payload: SignUpPayload): Promise<T>;
|
|
422
|
+
forgotPassword(req: {
|
|
423
|
+
email: string;
|
|
424
|
+
callbackUrl?: string;
|
|
425
|
+
redirectUrl?: string;
|
|
426
|
+
}): Promise<Response>;
|
|
427
|
+
resetPassword(req: Request | {
|
|
428
|
+
email: string;
|
|
429
|
+
password: string;
|
|
430
|
+
callbackUrl?: string;
|
|
431
|
+
redirectUrl?: string;
|
|
432
|
+
}): Promise<Response>;
|
|
433
|
+
callback(provider: ProviderName, body?: string | Request): Promise<Response>;
|
|
408
434
|
/**
|
|
409
435
|
* The return value from this will be a redirect for the client
|
|
410
436
|
* In most cases, you should forward the response directly to the client
|
|
411
437
|
* @param payload
|
|
412
438
|
* @param rawResponse
|
|
413
439
|
*/
|
|
414
|
-
signIn<T = Response>(provider: ProviderName, payload?: {
|
|
440
|
+
signIn<T = Response>(provider: ProviderName, payload?: Request | {
|
|
415
441
|
email: string;
|
|
416
442
|
password: string;
|
|
417
443
|
}, rawResponse?: true): Promise<T>;
|
|
@@ -484,4 +510,4 @@ declare class Server {
|
|
|
484
510
|
}
|
|
485
511
|
declare function create(config?: NileConfig): Server;
|
|
486
512
|
|
|
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 };
|
|
513
|
+
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, type Providers, Server, type Tenant, type User, parseCSRF, parseCallback, parseToken };
|