declare namespace _exports { export { RouteFunc, Options, HttpOptions, WebsocketOptions, ProxyOptions, getIpHeaderCallback, getIpNetworkCallback, AuthOptions, AuthSignOptions, AuthVerifyOptions, DefaultOptions, ClientProperties, CookieOptions }; } declare const _exports: any; export = _exports; /** * Typedef imports */ type RouteFunc = import("../routes/Route").RouteFunc; type Options = { /** * - the root path to use. */ path?: string; /** * - the port to bind the server on. */ port?: number; /** * - when false (default), `bind()` * installs `uncaughtException` / `unhandledRejection` handlers that LOG the * error and keep the process alive, so a single misbehaving client cannot * terminate the server. Set to true to skip installation and revert to the * default Node.js behavior (process exits on unhandled errors). RestNio never * overwrites pre-existing listeners. */ crashOnUnhandled?: boolean; /** * - http settings. */ http?: HttpOptions; /** * - websocket options. */ websocket?: WebsocketOptions; /** * - proxy options. */ proxy?: ProxyOptions; /** * - auth settings. */ auth?: AuthOptions; /** * - default routes and settings. */ default?: DefaultOptions; }; type HttpOptions = { /** * - whether the http module should be enabled. */ enabled?: boolean; }; type WebsocketOptions = { /** * - whether the websocket module should be enabled. */ enabled?: boolean; /** * - the timeout in ms before unresponsive websocket */ timeout?: number; /** * - extra client timeout for heartbeat. * clients will be kicked from the server. */ clientTimeoutExtra?: number; /** * - the time a socket connection is forcibly closed after client.close() is called. * Defaults to 10 seconds. */ hardClose?: number; /** * - whether or not to add a noop * upgrade path specifically for websockets to use the token header seperately. */ addUpgradeRoute?: boolean; }; type ProxyOptions = { /** * - array of trusted proxy ips. If empty (default) all proxies are trusted. */ trustedProxies?: string[]; /** * - wether or not to reject connections with unkown ip. Default is false. */ rejectUnknown?: boolean; /** * - list with proxy ip grabbers in order of checking. Defaults to a pretty comprehensive list. */ ipHeaderGrabbers?: getIpHeaderCallback[]; /** * - list with ip grabbers in order of checking. Defaults to a pretty compresensive list. */ ipNetworkGrabbers?: getIpNetworkCallback[]; /** * - Message to show when connecting with unkown ip. (Only used if rejectUnknown is set to true). */ rejectMessage?: string; }; /** * Ip callback */ type getIpHeaderCallback = (headers: { [x: string]: string; }) => string; /** * Ip callback */ type getIpNetworkCallback = (req: Request) => string; type AuthOptions = { /** * - whether the auth module should be enabled. */ enabled?: boolean; /** * - what authentication type to use. * (Currently JWT is included and the only supported option) */ type?: string; /** * - the algorithm used to create JWT tokens. */ algorithm?: string; /** * - in case tokens are signed with a secret, * this is the secret to sign wiht and check against. When using public / private keys this * value should be set to `null`. */ secret?: string; /** * - the privateKey to encode JWT tokens with. * If using an algorithm supporting key pairs, be sure to also set the `auth.secret` option to `null`. */ privateKey?: string; /** * - the publicKey to check JWT tokens with. * If using an algorithm supporting key pairs, be sure to also set the `auth.secret` option to `null`. */ publicKey?: string; /** * - sign options used with the JWTs. Dictates thinks like when it expires. */ sign?: AuthSignOptions; /** * - verify options used with the JWTs. Tells what to care about. */ verify?: AuthVerifyOptions; /** * - whether to automatically verify token from (HTTP) cookie. */ cookietoken?: boolean; }; type AuthSignOptions = { /** * - how soon the token expires. * Expressed in seconds or a string describing a time span zeit/ms. * Eg: 60, "2 days", "10h", "7d". A numeric value is interpreted as a seconds count. * If you use a string be sure you provide the time units (days, hours, etc), * otherwise milliseconds unit is used by default ("120" is equal to "120ms"). */ expiresIn?: string; /** * - override for how soon the token expires. Given in DatTime. */ exp?: NumericDate; /** * - after what time the token starts working. * Expressed in seconds or a string describing a time span zeit/ms. * Eg: 60, "2 days", "10h", "7d". A numeric value is interpreted as a seconds count. * If you use a string be sure you provide the time units (days, hours, etc), * otherwise milliseconds unit is used by default ("120" is equal to "120ms"). */ notBefore?: string; /** * - override for how soon the token starts working. Given in DatTime. */ nbf?: NumericDate; /** * - what the audience of this token is. */ audience?: string; /** * - the issuer of the token. This can be used as extra check * and is useful if there are multiple token issuers. */ issuer?: string; /** * - optional id. */ jwtid?: string; /** * - set subject of token. */ subject?: string; /** * - stop current timestamp from being automatically * filled into the iat claim. Default is false. */ noTimestamp?: boolean; /** * - override for the issued at, in case fake/historic tokens are wanted. */ iat?: NumericDate; /** * - optional header objects for the signed tokens. */ header?: any; /** * - some id for the token key. */ keyid?: any; /** * - if `true`, the sign function will modify the payload object directly. * This is useful if you need a raw reference to the payload after claims * have been applied to it but before it has been encoded into a token. */ mutatePayload?: boolean; }; type AuthVerifyOptions = { /** * - if specified, all audience members that are accaptable. */ audience?: (string[] | RegExp[]); /** * - if specifed, what the issuer must be (or one of, if array). */ issuer?: (string | string[]); /** * - if `true` do not validate the expiration of the token. */ ignoreExpiration?: boolean; /** * - if `true` do not validate the starttime of the token. */ ignoreNotBefore?: boolean; /** * - if specifed, what the subject must be. */ subject?: string; /** * - if specified what tolerance to give iat and nbf claims. */ clockTolerance?: number; /** * - the maximum allowed age for tokens to still be valid. * Expressed in seconds or a string describing a time span zeit/ms. * Eg: 60, "2 days", "10h", "7d". A numeric value is interpreted as a seconds count. * If you use a string be sure you provide the time units (days, hours, etc), * otherwise milliseconds unit is used by default ("120" is equal to "120ms"). */ maxAge?: string; /** * - the time in seconds that should be used as the current time for all necessary comparisons. * Usefull if you want to compare tokens to a certain time. */ clockTimestamp?: number; /** * - if you want to check nonce claim, provide a string value here. It is used on Open ID for the ID Tokens. */ nonce?: string; }; type DefaultOptions = { /** * - default routes to define inside the main * router. This is used to define some standard errors and functions that may be overridden if wanted. * '404' is the route that gets executed when no other route is found. * Note that params are not passed to this route and are thus not available. The client however, is. * '500' is the observer route that runs when a route throws anything other than a * `[code, message]` tuple. Params are `{ error }` with the thrown value. Default is a * NOOP and the error is then sent to the client as usual (`err.toString()`, status 500), * so custom error classes keep working. Throw `[code, message]` from it to replace the * reply, or return a value to send that instead. * 'wsConnect' is the websocket message of the day, this is a function that gets executed * when a websocket client is succesfully connected. Params is empty object. * The client is active and can be send stuff. Setting to NOOP function will disable the MOTD. * 'wsClose' is the websocket end function. Note that returning data here will cause errors. * The websocket connection is already closed. The client properties etc are still available. * Useful to hook into this route to further handle applications dealing with active clients. * Contains the param `reason` with the reason of the closure. * 'wsBin' is the default catch-all for incoming binary frames that are neither a * codec envelope nor routed to a named `wsBin-` route via `client.setBinRoute()`. * Params are `{ data: Buffer, size: number }`. Default: throws a 400 error. * 'wsNoPath' is the catch-all for incoming text-frame envelopes on a * regular WebSocketClient that don't carry a `path` field (e.g. error * replies `{code, error}` returning from a sibling, or stray frames from * misbehaving clients). Default is NOOP — the frame is silently dropped. * Override via `router.on('wsNoPath', fn)` to log/inspect path-less * frames; the full envelope is passed as `params`. * Critical: this default deliberately does NOT route the frame to '/' as * earlier versions did, because GET-/ handlers also match WS:/ and would * echo string bodies back, producing reflective loops between peers. * 'interNoPath' is the same idea but on the peer-link side * ({@link InterClient}). Default NOOP. Hook here to surface error frames * coming back from the upstream peer (remote-side 404s, parse errors, * `throw [code, msg]` replies) — they arrive as `{code, error}` with no * path. Override via `router.on('interNoPath', fn)` inside the * `interconnect({routes})` callback so the hook lands on the peer's * route map. */ routes?: { [x: string]: import("../routes/Route").RouteFunc; }; /** * - default websocket-client properties. */ wsProperties?: ClientProperties; /** * - default http-client properties. */ httpProperties?: ClientProperties; /** * - default client properties. Applied after default http and ws props. */ properties?: ClientProperties; /** * - default cookie options. Applied on top of specific cookie-options. */ cookieOptions?: CookieOptions; }; type ClientProperties = { /** * - whether to prioritise json encoded response * over plain strings even if the client is not specifically json. */ jsonResponse?: boolean; /** * - whether to always send client errors as json * regarless of if the request was not json encoded. (such as urlform) */ jsonError?: boolean; /** * - whether or not to console.log all incoming and outgoing messages for this client. */ debug?: boolean; /** * - whether to console.log 500 errors this client causes. */ logErrors?: boolean; /** * - whether or not to always include cors headers in errors. * This is present because some RestNio errors like malformatted tokens might be handled before any * CORS allowing routes are executed. These 'primal' errors are usually still wanted, which this option enables. * If set to a null value, errors will not pass through CORS on default. */ corsErrorOrigin?: string; }; type CookieOptions = { /** * - The maximum lifetime of the cookie as an HTTP-date timestamp. * If not specified, the cookie will have the lifetime of a session cookie. * A session is finished when the client is shut down meaning that session cookies will get removed at that point. * However, many web browsers have a feature called session restore that will save all your tabs and have them * come back next time you use the browser. Cookies will also be present and it's like you had never actually closed the browser. {MDN} */ expires?: Date; /** * - Number of seconds until the cookie expires. * A zero or negative number will expire the cookie immediately. * Older browsers (ie6, ie7, and ie8) do not support max-age. For other browsers, * if both (Expires and Max-Age) are set, Max-Age will have precedence. {MDN} */ maxAge?: number; /** * - Specifies those hosts to which the cookie will be sent. * If not specified, defaults to the host portion of the current document location (but not including subdomains). * Contrary to earlier specifications, leading dots in domain names are ignored. * If a domain is specified, subdomains are always included. {MDN} */ domain?: string; /** * - Indicates a URL path that must exist in the requested resource before sending the Cookie header. * The %x2F ("/") character is interpreted as a directory separator and sub directories will be matched as well * (e.g. path=/docs, "/docs", "/docs/Web/", or "/docs/Web/HTTP" will all be matched). {MDN} */ path?: string; /** * - A secure cookie will only be sent to the server when a request is made using SSL and the HTTPS protocol. * However, confidential or sensitive information should never be stored or transmitted in * HTTP Cookies as the entire mechanism is inherently insecure and this doesn't mean that any information is encrypted. {MDN} */ secure?: boolean; /** * - HTTP-only cookies aren't accessible via JavaScript through the Document.cookie property, * the XMLHttpRequest API, or the Request API to mitigate attacks against cross-site scripting (XSS). {MDN} */ httpOnly?: boolean; /** * - Allows servers to assert that a cookie ought not to be sent along with cross-site requests, * which provides some protection against cross-site request forgery attacks (CSRF). {MDN} */ sameSite?: ("Strict" | "Lax"); };