@niledatabase/server 5.0.0-alpha.21 → 5.0.0-alpha.23
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 +19 -15
- package/dist/index.d.ts +19 -15
- package/dist/index.js +24 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -540,10 +540,8 @@ declare class Server {
|
|
|
540
540
|
/**
|
|
541
541
|
* A convenience function that applies a config and ensures whatever was passed is set properly
|
|
542
542
|
*/
|
|
543
|
-
getInstance<T = Request | Headers | Record<string, string>>(config: NileConfig, req?: T):
|
|
544
|
-
get handlers():
|
|
545
|
-
withContext: CTXHandlerType;
|
|
546
|
-
};
|
|
543
|
+
getInstance<T = Request | Headers | Record<string, string>>(config: NileConfig, req?: T): this;
|
|
544
|
+
get handlers(): NileHandlers;
|
|
547
545
|
get paths(): ConfigurablePaths;
|
|
548
546
|
set paths(paths: ConfigurablePaths);
|
|
549
547
|
/**
|
|
@@ -559,7 +557,7 @@ declare class Server {
|
|
|
559
557
|
}, ...remaining: unknown[]) => void;
|
|
560
558
|
getContext(): any;
|
|
561
559
|
}
|
|
562
|
-
declare function create(config?: NileConfig):
|
|
560
|
+
declare function create<T = Server>(config?: NileConfig): T;
|
|
563
561
|
|
|
564
562
|
type Opts = {
|
|
565
563
|
basePath?: string;
|
|
@@ -574,6 +572,12 @@ type ExtensionResult = {
|
|
|
574
572
|
onConfigure?: (...params: Any) => void;
|
|
575
573
|
onSetContext?: (...params: Any) => void;
|
|
576
574
|
onGetContext?: () => Any;
|
|
575
|
+
replace?: {
|
|
576
|
+
handlers: (handlers: NileHandlers) => Any;
|
|
577
|
+
};
|
|
578
|
+
};
|
|
579
|
+
type NileHandlers = RouteFunctions & {
|
|
580
|
+
withContext: CTXHandlerType;
|
|
577
581
|
};
|
|
578
582
|
type Extension = (instance: Server) => ExtensionResult;
|
|
579
583
|
declare enum ExtensionState {
|
|
@@ -778,19 +782,19 @@ type DefaultRouteReturn = Request | Response | ExtensionState;
|
|
|
778
782
|
type RouteReturn<T = unknown> = void | T | Promise<void | T>;
|
|
779
783
|
type RouteFunctions<T = DefaultRouteReturn> = {
|
|
780
784
|
GET: (req: Request, config?: ExtensionConfig, ...args: unknown[]) => RouteReturn<T>;
|
|
781
|
-
POST: (req: Request, config?: ExtensionConfig) => RouteReturn<T>;
|
|
782
|
-
DELETE: (req: Request, config?: ExtensionConfig) => RouteReturn<T>;
|
|
783
|
-
PUT: (req: Request, config?: ExtensionConfig) => RouteReturn<T>;
|
|
785
|
+
POST: (req: Request, config?: ExtensionConfig, ...args: unknown[]) => RouteReturn<T>;
|
|
786
|
+
DELETE: (req: Request, config?: ExtensionConfig, ...args: unknown[]) => RouteReturn<T>;
|
|
787
|
+
PUT: (req: Request, config?: ExtensionConfig, ...args: unknown[]) => RouteReturn<T>;
|
|
784
788
|
};
|
|
785
|
-
type ContextReturn = {
|
|
786
|
-
response:
|
|
789
|
+
type ContextReturn<T = Response> = {
|
|
790
|
+
response: T;
|
|
787
791
|
nile: Server;
|
|
788
792
|
};
|
|
789
793
|
type CTXHandlerType = {
|
|
790
|
-
GET: (req: Request) => Promise<ContextReturn
|
|
791
|
-
POST: (req: Request) => Promise<ContextReturn
|
|
792
|
-
DELETE: (req: Request) => Promise<ContextReturn
|
|
793
|
-
PUT: (req: Request) => Promise<ContextReturn
|
|
794
|
+
GET: <T = Response>(req: Request) => Promise<ContextReturn<T>>;
|
|
795
|
+
POST: <T = Response>(req: Request) => Promise<ContextReturn<T>>;
|
|
796
|
+
DELETE: <T = Response>(req: Request) => Promise<ContextReturn<T>>;
|
|
797
|
+
PUT: <T = Response>(req: Request) => Promise<ContextReturn<T>>;
|
|
794
798
|
};
|
|
795
799
|
|
|
796
800
|
declare const TENANT_COOKIE = "nile.tenant-id";
|
|
@@ -798,4 +802,4 @@ declare const USER_COOKIE = "nile.user-id";
|
|
|
798
802
|
declare const HEADER_ORIGIN = "nile-origin";
|
|
799
803
|
declare const HEADER_SECURE_COOKIES = "nile-secure-cookies";
|
|
800
804
|
|
|
801
|
-
export { type APIError, APIErrorErrorCodeEnum, type ActiveSession, type AfterCreate, type CTXHandlerType, type CreateBasicUserRequest, type CreateTenantUserRequest, type Extension, type ExtensionResult, ExtensionState, 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, type RouteFunctions, type RouteReturn, Server, TENANT_COOKIE, type Tenant, USER_COOKIE, type User, parseCSRF, parseCallback, parseResetToken, parseToken };
|
|
805
|
+
export { type APIError, APIErrorErrorCodeEnum, type ActiveSession, type AfterCreate, type CTXHandlerType, type ContextReturn, type CreateBasicUserRequest, type CreateTenantUserRequest, type Extension, type ExtensionResult, ExtensionState, HEADER_ORIGIN, HEADER_SECURE_COOKIES, type Invite, type JWT, type LoggerType, type LoginUserResponse, type LoginUserResponseToken, LoginUserResponseTokenTypeEnum, create as Nile, type NileConfig, type NileDb, type NileHandlers, type NilePoolConfig, type NileRequest, type NileResponse, type Opts, type Providers, type RouteFunctions, type RouteReturn, Server, TENANT_COOKIE, type Tenant, USER_COOKIE, type User, parseCSRF, parseCallback, parseResetToken, parseToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -540,10 +540,8 @@ declare class Server {
|
|
|
540
540
|
/**
|
|
541
541
|
* A convenience function that applies a config and ensures whatever was passed is set properly
|
|
542
542
|
*/
|
|
543
|
-
getInstance<T = Request | Headers | Record<string, string>>(config: NileConfig, req?: T):
|
|
544
|
-
get handlers():
|
|
545
|
-
withContext: CTXHandlerType;
|
|
546
|
-
};
|
|
543
|
+
getInstance<T = Request | Headers | Record<string, string>>(config: NileConfig, req?: T): this;
|
|
544
|
+
get handlers(): NileHandlers;
|
|
547
545
|
get paths(): ConfigurablePaths;
|
|
548
546
|
set paths(paths: ConfigurablePaths);
|
|
549
547
|
/**
|
|
@@ -559,7 +557,7 @@ declare class Server {
|
|
|
559
557
|
}, ...remaining: unknown[]) => void;
|
|
560
558
|
getContext(): any;
|
|
561
559
|
}
|
|
562
|
-
declare function create(config?: NileConfig):
|
|
560
|
+
declare function create<T = Server>(config?: NileConfig): T;
|
|
563
561
|
|
|
564
562
|
type Opts = {
|
|
565
563
|
basePath?: string;
|
|
@@ -574,6 +572,12 @@ type ExtensionResult = {
|
|
|
574
572
|
onConfigure?: (...params: Any) => void;
|
|
575
573
|
onSetContext?: (...params: Any) => void;
|
|
576
574
|
onGetContext?: () => Any;
|
|
575
|
+
replace?: {
|
|
576
|
+
handlers: (handlers: NileHandlers) => Any;
|
|
577
|
+
};
|
|
578
|
+
};
|
|
579
|
+
type NileHandlers = RouteFunctions & {
|
|
580
|
+
withContext: CTXHandlerType;
|
|
577
581
|
};
|
|
578
582
|
type Extension = (instance: Server) => ExtensionResult;
|
|
579
583
|
declare enum ExtensionState {
|
|
@@ -778,19 +782,19 @@ type DefaultRouteReturn = Request | Response | ExtensionState;
|
|
|
778
782
|
type RouteReturn<T = unknown> = void | T | Promise<void | T>;
|
|
779
783
|
type RouteFunctions<T = DefaultRouteReturn> = {
|
|
780
784
|
GET: (req: Request, config?: ExtensionConfig, ...args: unknown[]) => RouteReturn<T>;
|
|
781
|
-
POST: (req: Request, config?: ExtensionConfig) => RouteReturn<T>;
|
|
782
|
-
DELETE: (req: Request, config?: ExtensionConfig) => RouteReturn<T>;
|
|
783
|
-
PUT: (req: Request, config?: ExtensionConfig) => RouteReturn<T>;
|
|
785
|
+
POST: (req: Request, config?: ExtensionConfig, ...args: unknown[]) => RouteReturn<T>;
|
|
786
|
+
DELETE: (req: Request, config?: ExtensionConfig, ...args: unknown[]) => RouteReturn<T>;
|
|
787
|
+
PUT: (req: Request, config?: ExtensionConfig, ...args: unknown[]) => RouteReturn<T>;
|
|
784
788
|
};
|
|
785
|
-
type ContextReturn = {
|
|
786
|
-
response:
|
|
789
|
+
type ContextReturn<T = Response> = {
|
|
790
|
+
response: T;
|
|
787
791
|
nile: Server;
|
|
788
792
|
};
|
|
789
793
|
type CTXHandlerType = {
|
|
790
|
-
GET: (req: Request) => Promise<ContextReturn
|
|
791
|
-
POST: (req: Request) => Promise<ContextReturn
|
|
792
|
-
DELETE: (req: Request) => Promise<ContextReturn
|
|
793
|
-
PUT: (req: Request) => Promise<ContextReturn
|
|
794
|
+
GET: <T = Response>(req: Request) => Promise<ContextReturn<T>>;
|
|
795
|
+
POST: <T = Response>(req: Request) => Promise<ContextReturn<T>>;
|
|
796
|
+
DELETE: <T = Response>(req: Request) => Promise<ContextReturn<T>>;
|
|
797
|
+
PUT: <T = Response>(req: Request) => Promise<ContextReturn<T>>;
|
|
794
798
|
};
|
|
795
799
|
|
|
796
800
|
declare const TENANT_COOKIE = "nile.tenant-id";
|
|
@@ -798,4 +802,4 @@ declare const USER_COOKIE = "nile.user-id";
|
|
|
798
802
|
declare const HEADER_ORIGIN = "nile-origin";
|
|
799
803
|
declare const HEADER_SECURE_COOKIES = "nile-secure-cookies";
|
|
800
804
|
|
|
801
|
-
export { type APIError, APIErrorErrorCodeEnum, type ActiveSession, type AfterCreate, type CTXHandlerType, type CreateBasicUserRequest, type CreateTenantUserRequest, type Extension, type ExtensionResult, ExtensionState, 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, type RouteFunctions, type RouteReturn, Server, TENANT_COOKIE, type Tenant, USER_COOKIE, type User, parseCSRF, parseCallback, parseResetToken, parseToken };
|
|
805
|
+
export { type APIError, APIErrorErrorCodeEnum, type ActiveSession, type AfterCreate, type CTXHandlerType, type ContextReturn, type CreateBasicUserRequest, type CreateTenantUserRequest, type Extension, type ExtensionResult, ExtensionState, HEADER_ORIGIN, HEADER_SECURE_COOKIES, type Invite, type JWT, type LoggerType, type LoginUserResponse, type LoginUserResponseToken, LoginUserResponseTokenTypeEnum, create as Nile, type NileConfig, type NileDb, type NileHandlers, type NilePoolConfig, type NileRequest, type NileResponse, type Opts, type Providers, type RouteFunctions, type RouteReturn, Server, TENANT_COOKIE, type Tenant, USER_COOKIE, type User, parseCSRF, parseCallback, parseResetToken, parseToken };
|
package/dist/index.js
CHANGED
|
@@ -223,7 +223,7 @@ async function request(url, _init, config) {
|
|
|
223
223
|
const updatedRes = await config.extensionCtx?.runExtensions(
|
|
224
224
|
"onResponse" /* onResponse */,
|
|
225
225
|
config,
|
|
226
|
-
params
|
|
226
|
+
{ ...params, response: res }
|
|
227
227
|
);
|
|
228
228
|
if (updatedRes) {
|
|
229
229
|
return updatedRes;
|
|
@@ -1147,7 +1147,7 @@ var baseLogger = (config, ...params) => ({
|
|
|
1147
1147
|
},
|
|
1148
1148
|
debug(message, meta) {
|
|
1149
1149
|
if (config?.debug) {
|
|
1150
|
-
console.
|
|
1150
|
+
console.info(
|
|
1151
1151
|
`${orange}[niledb]${reset}${purple}[DEBUG]${reset}${params.join(
|
|
1152
1152
|
""
|
|
1153
1153
|
)}${reset} ${message}`,
|
|
@@ -2637,7 +2637,7 @@ var Users = class {
|
|
|
2637
2637
|
}
|
|
2638
2638
|
}
|
|
2639
2639
|
async verifySelf(options, rawResponse = false) {
|
|
2640
|
-
const bypassEmail = typeof options === "object"
|
|
2640
|
+
const bypassEmail = typeof options === "object" && options?.bypassEmail === true;
|
|
2641
2641
|
const callbackUrl = typeof options === "object" ? options.callbackUrl : defaultCallbackUrl2(this.#config).callbackUrl;
|
|
2642
2642
|
let res;
|
|
2643
2643
|
try {
|
|
@@ -2647,17 +2647,22 @@ var Users = class {
|
|
|
2647
2647
|
}
|
|
2648
2648
|
res = await verifyEmailAddress(this.#config, me, String(callbackUrl));
|
|
2649
2649
|
return res;
|
|
2650
|
-
} catch {
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2650
|
+
} catch (e) {
|
|
2651
|
+
if (!bypassEmail) {
|
|
2652
|
+
let message = "Unable to verify email.";
|
|
2653
|
+
if (e instanceof Error) {
|
|
2654
|
+
message = e.message;
|
|
2655
|
+
}
|
|
2656
|
+
this.#logger?.error(
|
|
2657
|
+
`${message} you can bypass this message by setting bypassEmail: true when calling 'verifySelf'`
|
|
2658
|
+
);
|
|
2659
|
+
res = new Response(message, { status: 400 });
|
|
2660
|
+
}
|
|
2654
2661
|
}
|
|
2655
2662
|
if (bypassEmail) {
|
|
2663
|
+
this.#logger?.info("bypassing email requirements for email verification");
|
|
2656
2664
|
res = this.updateSelf({ emailVerified: true }, rawResponse);
|
|
2657
2665
|
}
|
|
2658
|
-
this.#logger.error(
|
|
2659
|
-
"Unable to verify email address. Configure your SMTP server in the console."
|
|
2660
|
-
);
|
|
2661
2666
|
return res;
|
|
2662
2667
|
}
|
|
2663
2668
|
};
|
|
@@ -3047,10 +3052,10 @@ function bindRunExtensions(instance) {
|
|
|
3047
3052
|
const result = await ext.onHandleRequest(
|
|
3048
3053
|
...Array.isArray(params) ? params : [params]
|
|
3049
3054
|
);
|
|
3055
|
+
debug(`${ext.id ?? create2.name} ran onHandleRequest`);
|
|
3050
3056
|
if (result != null) {
|
|
3051
3057
|
return result;
|
|
3052
3058
|
}
|
|
3053
|
-
continue;
|
|
3054
3059
|
}
|
|
3055
3060
|
const [param] = Array.isArray(params) ? params : [params];
|
|
3056
3061
|
if (ext.onRequest && toRun === "onRequest" /* onRequest */) {
|
|
@@ -3082,14 +3087,13 @@ function bindRunExtensions(instance) {
|
|
|
3082
3087
|
}
|
|
3083
3088
|
}
|
|
3084
3089
|
debug(`${ext.id ?? create2.name} ran onRequest`);
|
|
3085
|
-
continue;
|
|
3086
3090
|
}
|
|
3087
3091
|
if (ext.onResponse && toRun === "onResponse" /* onResponse */) {
|
|
3088
3092
|
const result = await ext.onResponse(param);
|
|
3093
|
+
debug(`${ext.id ?? create2.name} ran onResponse`);
|
|
3089
3094
|
if (result != null) {
|
|
3090
3095
|
return result;
|
|
3091
3096
|
}
|
|
3092
|
-
continue;
|
|
3093
3097
|
}
|
|
3094
3098
|
}
|
|
3095
3099
|
}
|
|
@@ -3164,6 +3168,13 @@ var Server = class {
|
|
|
3164
3168
|
if (ext.onConfigure) {
|
|
3165
3169
|
ext.onConfigure();
|
|
3166
3170
|
}
|
|
3171
|
+
if (ext?.replace?.handlers) {
|
|
3172
|
+
this.#config.logger("[EXTENSION]").debug(`${ext.id} replacing handlers`);
|
|
3173
|
+
this.#handlers = ext.replace.handlers({
|
|
3174
|
+
...this.#config.handlers,
|
|
3175
|
+
withContext: handlersWithContext(this.#config)
|
|
3176
|
+
});
|
|
3177
|
+
}
|
|
3167
3178
|
}
|
|
3168
3179
|
}
|
|
3169
3180
|
}
|