This commit is contained in:
2026-03-03 15:23:00 +00:00
parent 5e3726de39
commit 8e223bfbec
3689 changed files with 955330 additions and 1011 deletions

13
node_modules/@hapi/hapi/LICENSE.md generated vendored Executable file
View File

@@ -0,0 +1,13 @@
Copyright (c) 2011-2022, Project contributors
Copyright (c) 2011-2020, Sideway Inc
Copyright (c) 2011-2014, Walmart
Copyright (c) 2011, Yahoo Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- The names of any contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

26
node_modules/@hapi/hapi/README.md generated vendored Executable file
View File

@@ -0,0 +1,26 @@
<img src="https://raw.githubusercontent.com/hapijs/assets/master/images/hapi.png" width="400px" />
# @hapi/hapi
#### The Simple, Secure Framework Developers Trust
Build powerful, scalable applications, with minimal overhead and full out-of-the-box functionality - your code, your way.
### Visit the [hapi.dev](https://hapi.dev) Developer Portal for tutorials, documentation, and support
## Useful resources
- [Documentation and API](https://hapi.dev/)
- [Version status](https://hapi.dev/resources/status/#hapi) (builds, dependencies, node versions, licenses, eol)
- [Changelog](https://hapi.dev/resources/changelog/)
- [Project policies](https://hapi.dev/policies/)
- [Support](https://hapi.dev/support/)
## Technical Steering Committee (TSC) Members
- Devin Ivy ([@devinivy](https://github.com/devinivy))
- Lloyd Benson ([@lloydbenson](https://github.com/lloydbenson))
- Nathan LaFreniere ([@nlf](https://github.com/nlf))
- Wyatt Lyon Preul ([@geek](https://github.com/geek))
- Nicolas Morel ([@marsup](https://github.com/marsup))
- Jonathan Samines ([@jonathansamines](https://github.com/jonathansamines))

571
node_modules/@hapi/hapi/lib/auth.js generated vendored Executable file
View File

@@ -0,0 +1,571 @@
'use strict';
const Boom = require('@hapi/boom');
const Bounce = require('@hapi/bounce');
const Hoek = require('@hapi/hoek');
const Config = require('./config');
const Request = require('./request');
const internals = {
missing: Symbol('missing')
};
exports = module.exports = internals.Auth = class {
#core = null;
#schemes = {};
#strategies = {};
api = {}; // Do not reassign api or settings, as they are referenced in public()
settings = {
default: null // Strategy used as default if route has no auth settings
};
constructor(core) {
this.#core = core;
}
public(server) {
return {
api: this.api,
settings: this.settings,
scheme: this.scheme.bind(this),
strategy: this._strategy.bind(this, server),
default: this.default.bind(this),
test: this.test.bind(this),
verify: this.verify.bind(this),
lookup: this.lookup.bind(this)
};
}
scheme(name, scheme) {
Hoek.assert(name, 'Authentication scheme must have a name');
Hoek.assert(!this.#schemes[name], 'Authentication scheme name already exists:', name);
Hoek.assert(typeof scheme === 'function', 'scheme must be a function:', name);
this.#schemes[name] = scheme;
}
_strategy(server, name, scheme, options = {}) {
Hoek.assert(name, 'Authentication strategy must have a name');
Hoek.assert(typeof options === 'object', 'options must be an object');
Hoek.assert(!this.#strategies[name], 'Authentication strategy name already exists');
Hoek.assert(scheme, 'Authentication strategy', name, 'missing scheme');
Hoek.assert(this.#schemes[scheme], 'Authentication strategy', name, 'uses unknown scheme:', scheme);
server = server._clone();
const strategy = this.#schemes[scheme](server, options);
Hoek.assert(strategy.authenticate, 'Invalid scheme:', name, 'missing authenticate() method');
Hoek.assert(typeof strategy.authenticate === 'function', 'Invalid scheme:', name, 'invalid authenticate() method');
Hoek.assert(!strategy.payload || typeof strategy.payload === 'function', 'Invalid scheme:', name, 'invalid payload() method');
Hoek.assert(!strategy.response || typeof strategy.response === 'function', 'Invalid scheme:', name, 'invalid response() method');
strategy.options = strategy.options ?? {};
Hoek.assert(strategy.payload || !strategy.options.payload, 'Cannot require payload validation without a payload method');
this.#strategies[name] = {
methods: strategy,
realm: server.realm
};
if (strategy.api) {
this.api[name] = strategy.api;
}
}
default(options) {
Hoek.assert(!this.settings.default, 'Cannot set default strategy more than once');
options = Config.apply('auth', options, 'default strategy');
this.settings.default = this._setupRoute(Hoek.clone(options)); // Prevent changes to options
const routes = this.#core.router.table();
for (const route of routes) {
route.rebuild();
}
}
async test(name, request) {
Hoek.assert(name, 'Missing authentication strategy name');
const strategy = this.#strategies[name];
Hoek.assert(strategy, 'Unknown authentication strategy:', name);
const bind = strategy.methods;
const realm = strategy.realm;
const response = await request._core.toolkit.execute(strategy.methods.authenticate, request, { bind, realm, auth: true });
if (!response.isAuth) {
throw response;
}
if (response.error) {
throw response.error;
}
return response.data;
}
async verify(request) {
const auth = request.auth;
if (auth.error) {
throw auth.error;
}
if (!auth.isAuthenticated) {
return;
}
const strategy = this.#strategies[auth.strategy];
Hoek.assert(strategy, 'Unknown authentication strategy:', auth.strategy);
if (!strategy.methods.verify) {
return;
}
const bind = strategy.methods;
await strategy.methods.verify.call(bind, auth);
}
static testAccess(request, route) {
const auth = request._core.auth;
try {
return auth._access(request, route);
}
catch (err) {
Bounce.rethrow(err, 'system');
return false;
}
}
_setupRoute(options, path) {
if (!options) {
return options; // Preserve the difference between undefined and false
}
if (typeof options === 'string') {
options = { strategies: [options] };
}
else if (options.strategy) {
options.strategies = [options.strategy];
delete options.strategy;
}
if (path &&
!options.strategies) {
Hoek.assert(this.settings.default, 'Route missing authentication strategy and no default defined:', path);
options = Hoek.applyToDefaults(this.settings.default, options);
}
path = path ?? 'default strategy';
Hoek.assert(options.strategies?.length, 'Missing authentication strategy:', path);
options.mode = options.mode ?? 'required';
if (options.entity !== undefined || // Backwards compatibility with <= 11.x.x
options.scope !== undefined) {
options.access = [{ entity: options.entity, scope: options.scope }];
delete options.entity;
delete options.scope;
}
if (options.access) {
for (const access of options.access) {
access.scope = internals.setupScope(access);
}
}
if (options.payload === true) {
options.payload = 'required';
}
let hasAuthenticatePayload = false;
for (const name of options.strategies) {
const strategy = this.#strategies[name];
Hoek.assert(strategy, 'Unknown authentication strategy', name, 'in', path);
Hoek.assert(strategy.methods.payload || options.payload !== 'required', 'Payload validation can only be required when all strategies support it in', path);
hasAuthenticatePayload = hasAuthenticatePayload || strategy.methods.payload;
Hoek.assert(!strategy.methods.options.payload || options.payload === undefined || options.payload === 'required', 'Cannot set authentication payload to', options.payload, 'when a strategy requires payload validation in', path);
}
Hoek.assert(!options.payload || hasAuthenticatePayload, 'Payload authentication requires at least one strategy with payload support in', path);
return options;
}
lookup(route) {
if (route.settings.auth === false) {
return false;
}
return route.settings.auth || this.settings.default;
}
_enabled(route, type) {
const config = this.lookup(route);
if (!config) {
return false;
}
if (type === 'authenticate') {
return true;
}
if (type === 'access') {
return !!config.access;
}
for (const name of config.strategies) {
const strategy = this.#strategies[name];
if (strategy.methods[type]) {
return true;
}
}
return false;
}
static authenticate(request) {
const auth = request._core.auth;
return auth._authenticate(request);
}
async _authenticate(request) {
const config = this.lookup(request.route);
const errors = [];
request.auth.mode = config.mode;
// Injection bypass
if (request.auth.credentials) {
internals.validate(null, { credentials: request.auth.credentials, artifacts: request.auth.artifacts }, request.auth.strategy, config, request, errors);
return;
}
// Try each strategy
for (const name of config.strategies) {
const strategy = this.#strategies[name];
const bind = strategy.methods;
const realm = strategy.realm;
const response = await request._core.toolkit.execute(strategy.methods.authenticate, request, { bind, realm, auth: true });
const message = (response.isAuth ? internals.validate(response.error, response.data, name, config, request, errors) : internals.validate(response, null, name, config, request, errors));
if (!message) {
return;
}
if (message !== internals.missing) {
return message;
}
}
// No more strategies
const err = Boom.unauthorized('Missing authentication', errors);
if (config.mode === 'required') {
throw err;
}
request.auth.isAuthenticated = false;
request.auth.credentials = null;
request.auth.error = err;
request._log(['auth', 'unauthenticated']);
}
static access(request) {
const auth = request._core.auth;
request.auth.isAuthorized = auth._access(request);
}
_access(request, route) {
const config = this.lookup(route || request.route);
if (!config?.access) {
return true;
}
const credentials = request.auth.credentials;
if (!credentials) {
if (config.mode !== 'required') {
return false;
}
throw Boom.forbidden('Request is unauthenticated');
}
const requestEntity = (credentials.user ? 'user' : 'app');
const scopeErrors = [];
for (const access of config.access) {
// Check entity
const entity = access.entity;
if (entity &&
entity !== 'any' &&
entity !== requestEntity) {
continue;
}
// Check scope
let scope = access.scope;
if (scope) {
if (!credentials.scope) {
scopeErrors.push(scope);
continue;
}
scope = internals.expandScope(request, scope);
if (!internals.validateScope(credentials, scope, 'required') ||
!internals.validateScope(credentials, scope, 'selection') ||
!internals.validateScope(credentials, scope, 'forbidden')) {
scopeErrors.push(scope);
continue;
}
}
return true;
}
// Scope error
if (scopeErrors.length) {
request._log(['auth', 'scope', 'error']);
throw Boom.forbidden('Insufficient scope', { got: credentials.scope, need: scopeErrors });
}
// Entity error
if (requestEntity === 'app') {
request._log(['auth', 'entity', 'user', 'error']);
throw Boom.forbidden('Application credentials cannot be used on a user endpoint');
}
request._log(['auth', 'entity', 'app', 'error']);
throw Boom.forbidden('User credentials cannot be used on an application endpoint');
}
static async payload(request) {
if (!request.auth.isAuthenticated || !request.auth[Request.symbols.authPayload]) {
return;
}
const auth = request._core.auth;
const strategy = auth.#strategies[request.auth.strategy];
Hoek.assert(strategy, 'Unknown authentication strategy:', request.auth.strategy);
if (!strategy.methods.payload) {
return;
}
const config = auth.lookup(request.route);
const setting = config.payload ?? (strategy.methods.options.payload ? 'required' : false);
if (!setting) {
return;
}
const bind = strategy.methods;
const realm = strategy.realm;
const response = await request._core.toolkit.execute(strategy.methods.payload, request, { bind, realm });
if (response.isBoom &&
response.isMissing) {
return setting === 'optional' ? undefined : Boom.unauthorized('Missing payload authentication');
}
return response;
}
static async response(response) {
const request = response.request;
const auth = request._core.auth;
if (!request.auth.isAuthenticated) {
return;
}
const strategy = auth.#strategies[request.auth.strategy];
Hoek.assert(strategy, 'Unknown authentication strategy:', request.auth.strategy);
if (!strategy.methods.response) {
return;
}
const bind = strategy.methods;
const realm = strategy.realm;
const error = await request._core.toolkit.execute(strategy.methods.response, request, { bind, realm, continue: 'undefined' });
if (error) {
throw error;
}
}
};
internals.setupScope = function (access) {
// No scopes
if (!access.scope) {
return false;
}
// Already setup
if (!Array.isArray(access.scope)) {
return access.scope;
}
const scope = {};
for (const value of access.scope) {
const prefix = value[0];
const type = prefix === '+' ? 'required' : (prefix === '!' ? 'forbidden' : 'selection');
const clean = type === 'selection' ? value : value.slice(1);
scope[type] = scope[type] ?? [];
scope[type].push(clean);
if ((!scope._hasParameters?.[type]) &&
/{([^}]+)}/.test(clean)) {
scope._hasParameters = scope._hasParameters ?? {};
scope._hasParameters[type] = true;
}
}
return scope;
};
internals.validate = function (err, result, name, config, request, errors) { // err can be Boom, Error, or a valid response object
result = result ?? {};
request.auth.isAuthenticated = !err;
if (err) {
// Non-error response
if (err instanceof Error === false) {
request._log(['auth', 'unauthenticated', 'response', name], { statusCode: err.statusCode });
return err;
}
// Missing authenticated
if (err.isMissing) {
request._log(['auth', 'unauthenticated', 'missing', name], err);
errors.push(err.output.headers['WWW-Authenticate']);
return internals.missing;
}
}
request.auth.strategy = name;
request.auth.credentials = result.credentials;
request.auth.artifacts = result.artifacts;
// Authenticated
if (!err) {
return;
}
// Unauthenticated
request.auth.error = err;
if (config.mode === 'try') {
request._log(['auth', 'unauthenticated', 'try', name], err);
return;
}
request._log(['auth', 'unauthenticated', 'error', name], err);
throw err;
};
internals.expandScope = function (request, scope) {
if (!scope._hasParameters) {
return scope;
}
const expanded = {
required: internals.expandScopeType(request, scope, 'required'),
selection: internals.expandScopeType(request, scope, 'selection'),
forbidden: internals.expandScopeType(request, scope, 'forbidden')
};
return expanded;
};
internals.expandScopeType = function (request, scope, type) {
if (!scope._hasParameters[type]) {
return scope[type];
}
const expanded = [];
const context = {
params: request.params,
query: request.query,
payload: request.payload,
credentials: request.auth.credentials
};
for (const template of scope[type]) {
expanded.push(Hoek.reachTemplate(context, template));
}
return expanded;
};
internals.validateScope = function (credentials, scope, type) {
if (!scope[type]) {
return true;
}
const count = typeof credentials.scope === 'string' ?
scope[type].indexOf(credentials.scope) !== -1 ? 1 : 0 :
Hoek.intersect(scope[type], credentials.scope).length;
if (type === 'forbidden') {
return count === 0;
}
if (type === 'required') {
return count === scope.required.length;
}
return !!count;
};

119
node_modules/@hapi/hapi/lib/compression.js generated vendored Executable file
View File

@@ -0,0 +1,119 @@
'use strict';
const Zlib = require('zlib');
const Accept = require('@hapi/accept');
const Bounce = require('@hapi/bounce');
const Hoek = require('@hapi/hoek');
const internals = {
common: ['gzip, deflate', 'deflate, gzip', 'gzip', 'deflate', 'gzip, deflate, br']
};
exports = module.exports = internals.Compression = class {
decoders = {
gzip: (options) => Zlib.createGunzip(options),
deflate: (options) => Zlib.createInflate(options)
};
encodings = ['identity', 'gzip', 'deflate'];
encoders = {
identity: null,
gzip: (options) => Zlib.createGzip(options),
deflate: (options) => Zlib.createDeflate(options)
};
#common = null;
constructor() {
this._updateCommons();
}
_updateCommons() {
this.#common = new Map();
for (const header of internals.common) {
this.#common.set(header, Accept.encoding(header, this.encodings));
}
}
addEncoder(encoding, encoder) {
Hoek.assert(this.encoders[encoding] === undefined, `Cannot override existing encoder for ${encoding}`);
Hoek.assert(typeof encoder === 'function', `Invalid encoder function for ${encoding}`);
this.encoders[encoding] = encoder;
this.encodings.unshift(encoding);
this._updateCommons();
}
addDecoder(encoding, decoder) {
Hoek.assert(this.decoders[encoding] === undefined, `Cannot override existing decoder for ${encoding}`);
Hoek.assert(typeof decoder === 'function', `Invalid decoder function for ${encoding}`);
this.decoders[encoding] = decoder;
}
accept(request) {
const header = request.headers['accept-encoding'];
if (!header) {
return 'identity';
}
const common = this.#common.get(header);
if (common) {
return common;
}
try {
return Accept.encoding(header, this.encodings);
}
catch (err) {
Bounce.rethrow(err, 'system');
err.header = header;
request._log(['accept-encoding', 'error'], err);
return 'identity';
}
}
encoding(response, length) {
if (response.settings.compressed) {
response.headers['content-encoding'] = response.settings.compressed;
return null;
}
const request = response.request;
if (!request._core.settings.compression ||
length !== null && length < request._core.settings.compression.minBytes) {
return null;
}
const mime = request._core.mime.type(response.headers['content-type'] || 'application/octet-stream');
if (!mime.compressible) {
return null;
}
response.vary('accept-encoding');
if (response.headers['content-encoding']) {
return null;
}
return request.info.acceptEncoding === 'identity' ? null : request.info.acceptEncoding;
}
encoder(request, encoding) {
const encoder = this.encoders[encoding];
Hoek.assert(encoder !== undefined, `Unknown encoding ${encoding}`);
return encoder(request.route.settings.compression[encoding]);
}
};

446
node_modules/@hapi/hapi/lib/config.js generated vendored Executable file
View File

@@ -0,0 +1,446 @@
'use strict';
const Os = require('os');
const Somever = require('@hapi/somever');
const Validate = require('@hapi/validate');
const internals = {};
exports.symbol = Symbol('hapi-response');
exports.apply = function (type, options, ...message) {
const result = internals[type].validate(options);
if (result.error) {
throw new Error(`Invalid ${type} options ${message.length ? '(' + message.join(' ') + ')' : ''} ${result.error.annotate()}`);
}
return result.value;
};
exports.enable = function (options) {
const settings = options ? Object.assign({}, options) : {}; // Shallow cloned
if (settings.security === true) {
settings.security = {};
}
if (settings.cors === true) {
settings.cors = {};
}
return settings;
};
exports.versionMatch = (version, range) => Somever.match(version, range, { includePrerelease: true });
internals.access = Validate.object({
entity: Validate.valid('user', 'app', 'any'),
scope: [false, Validate.array().items(Validate.string()).single().min(1)]
});
internals.auth = Validate.alternatives([
Validate.string(),
internals.access.keys({
mode: Validate.valid('required', 'optional', 'try'),
strategy: Validate.string(),
strategies: Validate.array().items(Validate.string()).min(1),
access: Validate.array().items(internals.access.min(1)).single().min(1),
payload: [
Validate.valid('required', 'optional'),
Validate.boolean()
]
})
.without('strategy', 'strategies')
.without('access', ['scope', 'entity'])
]);
internals.event = Validate.object({
method: Validate.array().items(Validate.function()).single(),
options: Validate.object({
before: Validate.array().items(Validate.string()).single(),
after: Validate.array().items(Validate.string()).single(),
bind: Validate.any(),
sandbox: Validate.valid('server', 'plugin'),
timeout: Validate.number().integer().min(1)
})
.default({})
});
internals.exts = Validate.array()
.items(internals.event.keys({ type: Validate.string().required() })).single();
internals.failAction = Validate.alternatives([
Validate.valid('error', 'log', 'ignore'),
Validate.function()
])
.default('error');
internals.routeBase = Validate.object({
app: Validate.object().allow(null),
auth: internals.auth.allow(false),
bind: Validate.object().allow(null),
cache: Validate.object({
expiresIn: Validate.number(),
expiresAt: Validate.string(),
privacy: Validate.valid('default', 'public', 'private'),
statuses: Validate.array().items(Validate.number().integer().min(200)).min(1).single().default([200, 204]),
otherwise: Validate.string().default('no-cache')
})
.allow(false)
.default(),
compression: Validate.object()
.pattern(/.+/, Validate.object())
.default(),
cors: Validate.object({
origin: Validate.array().min(1).allow('ignore').default(['*']),
maxAge: Validate.number().default(86400),
headers: Validate.array().items(Validate.string()).default(['Accept', 'Authorization', 'Content-Type', 'If-None-Match']),
additionalHeaders: Validate.array().items(Validate.string()).default([]),
exposedHeaders: Validate.array().items(Validate.string()).default(['WWW-Authenticate', 'Server-Authorization']),
additionalExposedHeaders: Validate.array().items(Validate.string()).default([]),
credentials: Validate.boolean().when('origin', { is: 'ignore', then: false }).default(false),
preflightStatusCode: Validate.valid(200, 204).default(200)
})
.allow(false, true)
.default(false),
ext: Validate.object({
onPreAuth: Validate.array().items(internals.event).single(),
onCredentials: Validate.array().items(internals.event).single(),
onPostAuth: Validate.array().items(internals.event).single(),
onPreHandler: Validate.array().items(internals.event).single(),
onPostHandler: Validate.array().items(internals.event).single(),
onPreResponse: Validate.array().items(internals.event).single(),
onPostResponse: Validate.array().items(internals.event).single()
})
.default({}),
files: Validate.object({
relativeTo: Validate.string().pattern(/^([\/\.])|([A-Za-z]:\\)|(\\\\)/).default('.')
})
.default(),
json: Validate.object({
replacer: Validate.alternatives(Validate.function(), Validate.array()).allow(null).default(null),
space: Validate.number().allow(null).default(null),
suffix: Validate.string().allow(null).default(null),
escape: Validate.boolean().default(false)
})
.default(),
log: Validate.object({
collect: Validate.boolean().default(false)
})
.default(),
payload: Validate.object({
output: Validate.valid('data', 'stream', 'file').default('data'),
parse: Validate.boolean().allow('gunzip').default(true),
multipart: Validate.object({
output: Validate.valid('data', 'stream', 'file', 'annotated').required()
})
.default(false)
.allow(true, false),
allow: Validate.array().items(Validate.string()).single(),
override: Validate.string(),
protoAction: Validate.valid('error', 'remove', 'ignore').default('error'),
maxBytes: Validate.number().integer().positive().default(1024 * 1024),
maxParts: Validate.number().integer().positive().default(1000),
uploads: Validate.string().default(Os.tmpdir()),
failAction: internals.failAction,
timeout: Validate.number().integer().positive().allow(false).default(10 * 1000),
defaultContentType: Validate.string().default('application/json'),
compression: Validate.object()
.pattern(/.+/, Validate.object())
.default()
})
.default(),
plugins: Validate.object(),
response: Validate.object({
disconnectStatusCode: Validate.number().integer().min(400).default(499),
emptyStatusCode: Validate.valid(200, 204).default(204),
failAction: internals.failAction,
modify: Validate.boolean(),
options: Validate.object(),
ranges: Validate.boolean().default(true),
sample: Validate.number().min(0).max(100).when('modify', { then: Validate.forbidden() }),
schema: Validate.alternatives(Validate.object(), Validate.array(), Validate.function()).allow(true, false),
status: Validate.object().pattern(/\d\d\d/, Validate.alternatives(Validate.object(), Validate.array(), Validate.function()).allow(true, false))
})
.default(),
security: Validate.object({
hsts: Validate.alternatives([
Validate.object({
maxAge: Validate.number(),
includeSubdomains: Validate.boolean(),
includeSubDomains: Validate.boolean(),
preload: Validate.boolean()
}),
Validate.boolean(),
Validate.number()
])
.default(15768000),
xframe: Validate.alternatives([
Validate.boolean(),
Validate.valid('sameorigin', 'deny'),
Validate.object({
rule: Validate.valid('sameorigin', 'deny', 'allow-from'),
source: Validate.string()
})
])
.default('deny'),
xss: Validate.valid('enabled', 'disabled', false).default('disabled'),
noOpen: Validate.boolean().default(true),
noSniff: Validate.boolean().default(true),
referrer: Validate.alternatives([
Validate.boolean().valid(false),
Validate.valid('', 'no-referrer', 'no-referrer-when-downgrade',
'unsafe-url', 'same-origin', 'origin', 'strict-origin',
'origin-when-cross-origin', 'strict-origin-when-cross-origin')
])
.default(false)
})
.allow(null, false, true)
.default(false),
state: Validate.object({
parse: Validate.boolean().default(true),
failAction: internals.failAction
})
.default(),
timeout: Validate.object({
socket: Validate.number().integer().positive().allow(false),
server: Validate.number().integer().positive().allow(false).default(false)
})
.default(),
validate: Validate.object({
headers: Validate.alternatives(Validate.object(), Validate.array(), Validate.function()).allow(null, true),
params: Validate.alternatives(Validate.object(), Validate.array(), Validate.function()).allow(null, true),
query: Validate.alternatives(Validate.object(), Validate.array(), Validate.function()).allow(null, false, true),
payload: Validate.alternatives(Validate.object(), Validate.array(), Validate.function()).allow(null, false, true),
state: Validate.alternatives(Validate.object(), Validate.array(), Validate.function()).allow(null, false, true),
failAction: internals.failAction,
errorFields: Validate.object(),
options: Validate.object().default(),
validator: Validate.object()
})
.default()
});
internals.server = Validate.object({
address: Validate.string().hostname(),
app: Validate.object().allow(null),
autoListen: Validate.boolean(),
cache: Validate.allow(null), // Validated elsewhere
compression: Validate.object({
minBytes: Validate.number().min(1).integer().default(1024)
})
.allow(false)
.default(),
debug: Validate.object({
request: Validate.array().items(Validate.string()).single().allow(false).default(['implementation']),
log: Validate.array().items(Validate.string()).single().allow(false)
})
.allow(false)
.default(),
host: Validate.string().hostname().allow(null),
info: Validate.object({
remote: Validate.boolean().default(false)
})
.default({}),
listener: Validate.any(),
load: Validate.object({
sampleInterval: Validate.number().integer().min(0).default(0)
})
.unknown()
.default(),
mime: Validate.object().empty(null).default(),
operations: Validate.object({
cleanStop: Validate.boolean().default(true)
})
.default(),
plugins: Validate.object(),
port: Validate.alternatives([
Validate.number().integer().min(0), // TCP port
Validate.string().pattern(/\//), // Unix domain socket
Validate.string().pattern(/^\\\\\.\\pipe\\/) // Windows named pipe
])
.allow(null),
query: Validate.object({
parser: Validate.function()
})
.default(),
router: Validate.object({
isCaseSensitive: Validate.boolean().default(true),
stripTrailingSlash: Validate.boolean().default(false)
})
.default(),
routes: internals.routeBase.default(),
state: Validate.object(), // Cookie defaults
tls: Validate.alternatives([
Validate.object().allow(null),
Validate.boolean()
]),
uri: Validate.string().pattern(/[^/]$/)
});
internals.vhost = Validate.alternatives([
Validate.string().hostname(),
Validate.array().items(Validate.string().hostname()).min(1)
]);
internals.handler = Validate.alternatives([
Validate.function(),
Validate.object().length(1)
]);
internals.route = Validate.object({
method: Validate.string().pattern(/^[a-zA-Z0-9!#\$%&'\*\+\-\.^_`\|~]+$/).required(),
path: Validate.string().required(),
rules: Validate.object(),
vhost: internals.vhost,
// Validated in route construction
handler: Validate.any(),
options: Validate.any(),
config: Validate.any() // Backwards compatibility
})
.without('config', 'options');
internals.pre = [
Validate.function(),
Validate.object({
method: Validate.alternatives(Validate.string(), Validate.function()).required(),
assign: Validate.string(),
mode: Validate.valid('serial', 'parallel'),
failAction: internals.failAction
})
];
internals.routeConfig = internals.routeBase.keys({
description: Validate.string(),
id: Validate.string(),
isInternal: Validate.boolean(),
notes: [
Validate.string(),
Validate.array().items(Validate.string())
],
pre: Validate.array().items(...internals.pre.concat(Validate.array().items(...internals.pre).min(1))),
tags: [
Validate.string(),
Validate.array().items(Validate.string())
]
});
internals.cacheConfig = Validate.alternatives([
Validate.function(),
Validate.object({
name: Validate.string().invalid('_default'),
shared: Validate.boolean(),
provider: [
Validate.function(),
{
constructor: Validate.function().required(),
options: Validate.object({
partition: Validate.string().default('hapi-cache')
})
.unknown() // Catbox client validates other keys
.default({})
}
],
engine: Validate.object()
})
.xor('provider', 'engine')
]);
internals.cache = Validate.array().items(internals.cacheConfig).min(1).single();
internals.cachePolicy = Validate.object({
cache: Validate.string().allow(null).allow(''),
segment: Validate.string(),
shared: Validate.boolean()
})
.unknown(); // Catbox policy validates other keys
internals.method = Validate.object({
bind: Validate.object().allow(null),
generateKey: Validate.function(),
cache: internals.cachePolicy
});
internals.methodObject = Validate.object({
name: Validate.string().required(),
method: Validate.function().required(),
options: Validate.object()
});
internals.register = Validate.object({
once: true,
routes: Validate.object({
prefix: Validate.string().pattern(/^\/.+/),
vhost: internals.vhost
})
.default({})
});
internals.semver = Validate.string();
internals.plugin = internals.register.keys({
options: Validate.any(),
plugin: Validate.object({
register: Validate.function().required(),
name: Validate.string().when('pkg.name', { is: Validate.exist(), otherwise: Validate.required() }),
version: Validate.string(),
multiple: Validate.boolean().default(false),
dependencies: [
Validate.array().items(Validate.string()).single(),
Validate.object().pattern(/.+/, internals.semver)
],
once: true,
requirements: Validate.object({
hapi: Validate.string(),
node: Validate.string()
})
.default(),
pkg: Validate.object({
name: Validate.string(),
version: Validate.string().default('0.0.0')
})
.unknown()
.default({})
})
.unknown()
})
.without('once', 'options')
.unknown();
internals.rules = Validate.object({
validate: Validate.object({
schema: Validate.alternatives(Validate.object(), Validate.array()).required(),
options: Validate.object()
.default({ allowUnknown: true })
})
});

718
node_modules/@hapi/hapi/lib/core.js generated vendored Executable file
View File

@@ -0,0 +1,718 @@
'use strict';
const Http = require('http');
const Https = require('https');
const Os = require('os');
const Path = require('path');
const Boom = require('@hapi/boom');
const Bounce = require('@hapi/bounce');
const Call = require('@hapi/call');
const Catbox = require('@hapi/catbox');
const { Engine: CatboxMemory } = require('@hapi/catbox-memory');
const { Heavy } = require('@hapi/heavy');
const Hoek = require('@hapi/hoek');
const { Mimos } = require('@hapi/mimos');
const Podium = require('@hapi/podium');
const Statehood = require('@hapi/statehood');
const Auth = require('./auth');
const Compression = require('./compression');
const Config = require('./config');
const Cors = require('./cors');
const Ext = require('./ext');
const Methods = require('./methods');
const Request = require('./request');
const Response = require('./response');
const Route = require('./route');
const Toolkit = require('./toolkit');
const Validation = require('./validation');
const internals = {
counter: {
min: 10000,
max: 99999
},
events: [
{ name: 'cachePolicy', spread: true },
{ name: 'log', channels: ['app', 'internal'], tags: true },
{ name: 'request', channels: ['app', 'internal', 'error'], tags: true, spread: true },
'response',
'route',
'start',
'closing',
'stop'
],
badRequestResponse: Buffer.from('HTTP/1.1 400 Bad Request\r\n\r\n', 'ascii')
};
exports = module.exports = internals.Core = class {
actives = new WeakMap(); // Active requests being processed
app = {};
auth = new Auth(this);
caches = new Map(); // Cache clients
compression = new Compression();
controlled = null; // Other servers linked to the phases of this server
dependencies = []; // Plugin dependencies
events = new Podium.Podium(internals.events);
heavy = null;
info = null;
instances = new Set();
listener = null;
methods = new Methods(this); // Server methods
mime = null;
onConnection = null; // Used to remove event listener on stop
phase = 'stopped'; // 'stopped', 'initializing', 'initialized', 'starting', 'started', 'stopping', 'invalid'
plugins = {}; // Exposed plugin properties by name
registrations = {}; // Tracks plugin for dependency validation { name -> { version } }
registring = 0; // > 0 while register() is waiting for plugin callbacks
Request = class extends Request { };
Response = class extends Response { };
requestCounter = { value: internals.counter.min, min: internals.counter.min, max: internals.counter.max };
root = null;
router = null;
settings = null;
sockets = null; // Track open sockets for graceful shutdown
started = false;
states = null;
toolkit = new Toolkit.Manager();
type = null;
validator = null;
extensionsSeq = 0; // Used to keep absolute order of extensions based on the order added across locations
extensions = {
server: {
onPreStart: new Ext('onPreStart', this),
onPostStart: new Ext('onPostStart', this),
onPreStop: new Ext('onPreStop', this),
onPostStop: new Ext('onPostStop', this)
},
route: {
onRequest: new Ext('onRequest', this),
onPreAuth: new Ext('onPreAuth', this),
onCredentials: new Ext('onCredentials', this),
onPostAuth: new Ext('onPostAuth', this),
onPreHandler: new Ext('onPreHandler', this),
onPostHandler: new Ext('onPostHandler', this),
onPreResponse: new Ext('onPreResponse', this),
onPostResponse: new Ext('onPostResponse', this)
}
};
decorations = {
handler: new Map(),
request: new Map(),
response: new Map(),
server: new Map(),
toolkit: new Map(),
requestApply: null,
public: { handler: [], request: [], response: [], server: [], toolkit: [] }
};
constructor(options) {
const { settings, type } = internals.setup(options);
this.settings = settings;
this.type = type;
this.heavy = new Heavy(this.settings.load);
this.mime = new Mimos(this.settings.mime);
this.router = new Call.Router(this.settings.router);
this.states = new Statehood.Definitions(this.settings.state);
this._debug();
this._initializeCache();
if (this.settings.routes.validate.validator) {
this.validator = Validation.validator(this.settings.routes.validate.validator);
}
this.listener = this._createListener();
this._initializeListener();
this.info = this._info();
}
_debug() {
const debug = this.settings.debug;
if (!debug) {
return;
}
// Subscribe to server log events
const method = (event) => {
const data = event.error ?? event.data;
console.error('Debug:', event.tags.join(', '), data ? '\n ' + (data.stack ?? (typeof data === 'object' ? Hoek.stringify(data) : data)) : '');
};
if (debug.log) {
const filter = debug.log.some((tag) => tag === '*') ? undefined : debug.log;
this.events.on({ name: 'log', filter }, method);
}
if (debug.request) {
const filter = debug.request.some((tag) => tag === '*') ? undefined : debug.request;
this.events.on({ name: 'request', filter }, (request, event) => method(event));
}
}
_initializeCache() {
if (this.settings.cache) {
this._createCache(this.settings.cache);
}
if (!this.caches.has('_default')) {
this._createCache([{ provider: CatboxMemory }]); // Defaults to memory-based
}
}
_info() {
const now = Date.now();
const protocol = this.type === 'tcp' ? (this.settings.tls ? 'https' : 'http') : this.type;
const host = this.settings.host || Os.hostname() || 'localhost';
const port = this.settings.port;
const info = {
created: now,
started: 0,
host,
port,
protocol,
id: Os.hostname() + ':' + process.pid + ':' + now.toString(36),
uri: this.settings.uri ?? (protocol + ':' + (this.type === 'tcp' ? '//' + host + (port ? ':' + port : '') : port))
};
return info;
}
_counter() {
const next = ++this.requestCounter.value;
if (this.requestCounter.value > this.requestCounter.max) {
this.requestCounter.value = this.requestCounter.min;
}
return next - 1;
}
_createCache(configs) {
Hoek.assert(this.phase !== 'initializing', 'Cannot provision server cache while server is initializing');
configs = Config.apply('cache', configs);
const added = [];
for (let config of configs) {
// <function>
// { provider: <function> }
// { provider: { constructor: <function>, options } }
// { engine }
if (typeof config === 'function') {
config = { provider: { constructor: config } };
}
const name = config.name ?? '_default';
Hoek.assert(!this.caches.has(name), 'Cannot configure the same cache more than once: ', name === '_default' ? 'default cache' : name);
let client = null;
if (config.provider) {
let provider = config.provider;
if (typeof provider === 'function') {
provider = { constructor: provider };
}
client = new Catbox.Client(provider.constructor, provider.options ?? { partition: 'hapi-cache' });
}
else {
client = new Catbox.Client(config.engine);
}
this.caches.set(name, { client, segments: {}, shared: config.shared ?? false });
added.push(client);
}
return added;
}
registerServer(server) {
if (!this.root) {
this.root = server;
this._defaultRoutes();
}
this.instances.add(server);
}
async _start() {
if (this.phase === 'initialized' ||
this.phase === 'started') {
this._validateDeps();
}
if (this.phase === 'started') {
return;
}
if (this.phase !== 'stopped' &&
this.phase !== 'initialized') {
throw new Error('Cannot start server while it is in ' + this.phase + ' phase');
}
if (this.phase !== 'initialized') {
await this._initialize();
}
this.phase = 'starting';
this.started = true;
this.info.started = Date.now();
try {
await this._listen();
}
catch (err) {
this.started = false;
this.phase = 'invalid';
throw err;
}
this.phase = 'started';
this.events.emit('start');
try {
if (this.controlled) {
await Promise.all(this.controlled.map((control) => control.start()));
}
await this._invoke('onPostStart');
}
catch (err) {
this.phase = 'invalid';
throw err;
}
}
_listen() {
return new Promise((resolve, reject) => {
if (!this.settings.autoListen) {
resolve();
return;
}
const onError = (err) => {
reject(err);
return;
};
this.listener.once('error', onError);
const finalize = () => {
this.listener.removeListener('error', onError);
resolve();
return;
};
if (this.type !== 'tcp') {
this.listener.listen(this.settings.port, finalize);
}
else {
// Default is the unspecified address, :: if IPv6 is available or otherwise the IPv4 address 0.0.0.0
const address = this.settings.address || this.settings.host || null;
this.listener.listen(this.settings.port, address, finalize);
}
});
}
async _initialize() {
if (this.registring) {
throw new Error('Cannot start server before plugins finished registration');
}
if (this.phase === 'initialized') {
return;
}
if (this.phase !== 'stopped') {
throw new Error('Cannot initialize server while it is in ' + this.phase + ' phase');
}
this._validateDeps();
this.phase = 'initializing';
// Start cache
try {
const caches = [];
this.caches.forEach((cache) => caches.push(cache.client.start()));
await Promise.all(caches);
await this._invoke('onPreStart');
this.heavy.start();
this.phase = 'initialized';
if (this.controlled) {
await Promise.all(this.controlled.map((control) => control.initialize()));
}
}
catch (err) {
this.phase = 'invalid';
throw err;
}
}
_validateDeps() {
for (const { deps, plugin } of this.dependencies) {
for (const dep in deps) {
const version = deps[dep];
Hoek.assert(this.registrations[dep], 'Plugin', plugin, 'missing dependency', dep);
Hoek.assert(version === '*' || Config.versionMatch(this.registrations[dep].version, version), 'Plugin', plugin, 'requires', dep, 'version', version, 'but found', this.registrations[dep].version);
}
}
}
async _stop(options = {}) {
options.timeout = options.timeout ?? 5000; // Default timeout to 5 seconds
if (['stopped', 'initialized', 'started', 'invalid'].indexOf(this.phase) === -1) {
throw new Error('Cannot stop server while in ' + this.phase + ' phase');
}
this.phase = 'stopping';
try {
await this._invoke('onPreStop');
if (this.started) {
this.started = false;
this.info.started = 0;
await this._unlisten(options.timeout);
}
const caches = [];
this.caches.forEach((cache) => caches.push(cache.client.stop()));
await Promise.all(caches);
this.events.emit('stop');
this.heavy.stop();
if (this.controlled) {
await Promise.all(this.controlled.map((control) => control.stop(options)));
}
await this._invoke('onPostStop');
this.phase = 'stopped';
}
catch (err) {
this.phase = 'invalid';
throw err;
}
}
_unlisten(timeout) {
let timeoutId = null;
if (this.settings.operations.cleanStop) {
// Set connections timeout
const destroy = () => {
for (const connection of this.sockets) {
connection.destroy();
}
this.sockets.clear();
};
timeoutId = setTimeout(destroy, timeout);
// Tell idle keep-alive connections to close
for (const connection of this.sockets) {
if (!this.actives.has(connection)) {
connection.end();
}
}
}
// Close connection
return new Promise((resolve) => {
this.listener.close(() => {
if (this.settings.operations.cleanStop) {
this.listener.removeListener(this.settings.tls ? 'secureConnection' : 'connection', this.onConnection);
clearTimeout(timeoutId);
}
this._initializeListener();
resolve();
});
this.events.emit('closing');
});
}
async _invoke(type) {
const exts = this.extensions.server[type];
if (!exts.nodes) {
return;
}
// Execute extensions
for (const ext of exts.nodes) {
const bind = ext.bind ?? ext.realm.settings.bind;
const operation = ext.func.call(bind, ext.server, bind);
await Toolkit.timed(operation, { timeout: ext.timeout, name: type });
}
}
_defaultRoutes() {
this.router.special('notFound', new Route({ method: '_special', path: '/{p*}', handler: internals.notFound }, this.root, { special: true }));
this.router.special('badRequest', new Route({ method: '_special', path: '/{p*}', handler: internals.badRequest }, this.root, { special: true }));
if (this.settings.routes.cors) {
Cors.handler(this.root);
}
}
_dispatch(options = {}) {
return (req, res) => {
// Create request
const request = Request.generate(this.root, req, res, options);
// Track socket request processing state
if (this.settings.operations.cleanStop &&
req.socket) {
this.actives.set(req.socket, request);
const env = { core: this, req };
res.on('finish', internals.onFinish.bind(res, env));
}
// Check load
if (this.settings.load.sampleInterval) {
try {
this.heavy.check();
}
catch (err) {
Bounce.rethrow(err, 'system');
this._log(['load'], this.heavy.load);
request._reply(err);
return;
}
}
request._execute();
};
}
_createListener() {
const listener = this.settings.listener ?? (this.settings.tls ? Https.createServer(this.settings.tls) : Http.createServer());
listener.on('request', this._dispatch());
listener.on('checkContinue', this._dispatch({ expectContinue: true }));
listener.on('clientError', (err, socket) => {
this._log(['connection', 'client', 'error'], err);
if (socket.readable) {
const request = this.settings.operations.cleanStop && this.actives.get(socket);
if (request) {
// If a request is available, it means that the connection and parsing has progressed far enough to have created the request.
if (err.code === 'HPE_INVALID_METHOD') {
// This parser error is for a pipelined request. Schedule destroy once current request is done.
request.raw.res.once('close', () => {
if (socket.readable) {
socket.end(internals.badRequestResponse);
}
else {
socket.destroy(err);
}
});
return;
}
const error = Boom.badRequest();
error.output.headers = { connection: 'close' };
request._reply(error);
}
else {
socket.end(internals.badRequestResponse);
}
}
else {
socket.destroy(err);
}
});
return listener;
}
_initializeListener() {
this.listener.once('listening', () => {
// Update the address, port, and uri with active values
if (this.type === 'tcp') {
const address = this.listener.address();
this.info.address = address.address;
this.info.port = address.port;
this.info.uri = this.settings.uri ?? this.info.protocol + '://' + this.info.host + ':' + this.info.port;
}
if (this.settings.operations.cleanStop) {
this.sockets = new Set();
const self = this;
const onClose = function () { // 'this' is bound to the emitter
self.sockets.delete(this);
};
this.onConnection = (connection) => {
this.sockets.add(connection);
connection.on('close', onClose);
};
this.listener.on(this.settings.tls ? 'secureConnection' : 'connection', this.onConnection);
}
});
}
_cachePolicy(options, _segment, realm) {
options = Config.apply('cachePolicy', options);
const plugin = realm?.plugin;
const segment = options.segment ?? _segment ?? (plugin ? `!${plugin}` : '');
Hoek.assert(segment, 'Missing cache segment name');
const cacheName = options.cache ?? '_default';
const cache = this.caches.get(cacheName);
Hoek.assert(cache, 'Unknown cache', cacheName);
Hoek.assert(!cache.segments[segment] || cache.shared || options.shared, 'Cannot provision the same cache segment more than once');
cache.segments[segment] = true;
const policy = new Catbox.Policy(options, cache.client, segment);
this.events.emit('cachePolicy', [policy, options.cache, segment]);
return policy;
}
log(tags, data) {
return this._log(tags, data, 'app');
}
_log(tags, data, channel = 'internal') {
if (!this.events.hasListeners('log')) {
return;
}
if (!Array.isArray(tags)) {
tags = [tags];
}
const timestamp = Date.now();
const field = data instanceof Error ? 'error' : 'data';
let event = { timestamp, tags, [field]: data, channel };
if (typeof data === 'function') {
event = () => ({ timestamp, tags, data: data(), channel });
}
this.events.emit({ name: 'log', tags, channel }, event);
}
};
internals.setup = function (options = {}) {
let settings = Hoek.clone(options, { shallow: ['cache', 'listener', 'routes.bind'] });
settings.app = settings.app ?? {};
settings.routes = Config.enable(settings.routes);
settings = Config.apply('server', settings);
if (settings.port === undefined) {
settings.port = 0;
}
const type = (typeof settings.port === 'string' ? 'socket' : 'tcp');
if (type === 'socket') {
settings.port = (settings.port.indexOf('/') !== -1 ? Path.resolve(settings.port) : settings.port.toLowerCase());
}
if (settings.autoListen === undefined) {
settings.autoListen = true;
}
Hoek.assert(settings.autoListen || !settings.port, 'Cannot specify port when autoListen is false');
Hoek.assert(settings.autoListen || !settings.address, 'Cannot specify address when autoListen is false');
return { settings, type };
};
internals.notFound = function () {
throw Boom.notFound();
};
internals.badRequest = function () {
throw Boom.badRequest();
};
internals.onFinish = function (env) {
const { core, req } = env;
core.actives.delete(req.socket);
if (!core.started) {
req.socket.end();
}
};

208
node_modules/@hapi/hapi/lib/cors.js generated vendored Executable file
View File

@@ -0,0 +1,208 @@
'use strict';
const Boom = require('@hapi/boom');
const Hoek = require('@hapi/hoek');
let Route = null; // Delayed load due to circular dependency
const internals = {};
exports.route = function (options) {
if (!options) {
return false;
}
const settings = Hoek.clone(options);
settings._headers = settings.headers.concat(settings.additionalHeaders);
settings._headersString = settings._headers.join(',');
for (let i = 0; i < settings._headers.length; ++i) {
settings._headers[i] = settings._headers[i].toLowerCase();
}
if (settings._headers.indexOf('origin') === -1) {
settings._headers.push('origin');
}
settings._exposedHeaders = settings.exposedHeaders.concat(settings.additionalExposedHeaders).join(',');
if (settings.origin === 'ignore') {
settings._origin = false;
}
else if (settings.origin.indexOf('*') !== -1) {
Hoek.assert(settings.origin.length === 1, 'Cannot specify cors.origin * together with other values');
settings._origin = true;
}
else {
settings._origin = {
qualified: [],
wildcards: []
};
for (const origin of settings.origin) {
if (origin.indexOf('*') !== -1) {
settings._origin.wildcards.push(new RegExp('^' + Hoek.escapeRegex(origin).replace(/\\\*/g, '.*').replace(/\\\?/g, '.') + '$'));
}
else {
settings._origin.qualified.push(origin);
}
}
}
return settings;
};
exports.options = function (route, server) {
if (route.method === 'options' ||
!route.settings.cors) {
return;
}
exports.handler(server);
};
exports.handler = function (server) {
Route = Route || require('./route');
if (server._core.router.specials.options) {
return;
}
const definition = {
method: '_special',
path: '/{p*}',
handler: internals.handler,
options: {
cors: false
}
};
const route = new Route(definition, server, { special: true });
server._core.router.special('options', route);
};
internals.handler = function (request, h) {
// Validate CORS preflight request
const method = request.headers['access-control-request-method'];
if (!method) {
throw Boom.notFound('CORS error: Missing Access-Control-Request-Method header');
}
// Lookup route
const route = request.server.match(method, request.path, request.info.hostname);
if (!route) {
throw Boom.notFound();
}
const settings = route.settings.cors;
if (!settings) {
return { message: 'CORS is disabled for this route' };
}
// Validate Origin header
const origin = request.headers.origin;
if (!origin &&
settings._origin !== false) {
throw Boom.notFound('CORS error: Missing Origin header');
}
if (!exports.matchOrigin(origin, settings)) {
return { message: 'CORS error: Origin not allowed' };
}
// Validate allowed headers
let headers = request.headers['access-control-request-headers'];
if (headers) {
headers = headers.toLowerCase().split(/\s*,\s*/);
if (Hoek.intersect(headers, settings._headers).length !== headers.length) {
return { message: 'CORS error: Some headers are not allowed' };
}
}
// Reply with the route CORS headers
const response = h.response();
response.code(settings.preflightStatusCode);
response._header('access-control-allow-origin', settings._origin ? origin : '*');
response._header('access-control-allow-methods', method);
response._header('access-control-allow-headers', settings._headersString);
response._header('access-control-max-age', settings.maxAge);
if (settings.credentials) {
response._header('access-control-allow-credentials', 'true');
}
if (settings._exposedHeaders) {
response._header('access-control-expose-headers', settings._exposedHeaders);
}
return response;
};
exports.headers = function (response) {
const request = response.request;
const settings = request.route.settings.cors;
if (settings._origin !== false) {
response.vary('origin');
}
if ((request.info.cors && !request.info.cors.isOriginMatch) || // After route lookup
!exports.matchOrigin(request.headers.origin, request.route.settings.cors)) { // Response from onRequest
return;
}
response._header('access-control-allow-origin', settings._origin ? request.headers.origin : '*');
if (settings.credentials) {
response._header('access-control-allow-credentials', 'true');
}
if (settings._exposedHeaders) {
response._header('access-control-expose-headers', settings._exposedHeaders, { append: true });
}
};
exports.matchOrigin = function (origin, settings) {
if (settings._origin === true ||
settings._origin === false) {
return true;
}
if (!origin) {
return false;
}
if (settings._origin.qualified.indexOf(origin) !== -1) {
return true;
}
for (const wildcard of settings._origin.wildcards) {
if (origin.match(wildcard)) {
return true;
}
}
return false;
};

96
node_modules/@hapi/hapi/lib/ext.js generated vendored Executable file
View File

@@ -0,0 +1,96 @@
'use strict';
const Hoek = require('@hapi/hoek');
const Topo = require('@hapi/topo');
const internals = {};
exports = module.exports = internals.Ext = class {
type = null;
nodes = null;
#core = null;
#routes = [];
#topo = new Topo.Sorter();
constructor(type, core) {
this.#core = core;
this.type = type;
}
add(event) {
const methods = [].concat(event.method);
for (const method of methods) {
const settings = {
before: event.options.before,
after: event.options.after,
group: event.realm.plugin,
sort: this.#core.extensionsSeq++
};
const node = {
func: method, // Request: function (request, h), Server: function (server)
bind: event.options.bind,
server: event.server, // Server event
realm: event.realm,
timeout: event.options.timeout
};
this.#topo.add(node, settings);
}
this.nodes = this.#topo.nodes;
// Notify routes
for (const route of this.#routes) {
route.rebuild(event);
}
}
merge(others) {
const merge = [];
for (const other of others) {
merge.push(other.#topo);
}
this.#topo.merge(merge);
this.nodes = this.#topo.nodes.length ? this.#topo.nodes : null;
}
subscribe(route) {
this.#routes.push(route);
}
static combine(route, type) {
const ext = new internals.Ext(type, route._core);
const events = route.settings.ext[type];
if (events) {
for (let event of events) {
event = Object.assign({}, event); // Shallow cloned
Hoek.assert(!event.options.sandbox, 'Cannot specify sandbox option for route extension');
event.realm = route.realm;
ext.add(event);
}
}
const server = route._core.extensions.route[type];
const realm = route.realm._extensions[type];
ext.merge([server, realm]);
server.subscribe(route);
realm.subscribe(route);
return ext;
}
};

165
node_modules/@hapi/hapi/lib/handler.js generated vendored Executable file
View File

@@ -0,0 +1,165 @@
'use strict';
const Hoek = require('@hapi/hoek');
const internals = {};
exports.execute = async function (request) {
// Prerequisites
if (request._route._prerequisites) {
for (const set of request._route._prerequisites) { // Serial execution of each set
const pres = [];
for (const item of set) {
pres.push(internals.handler(request, item.method, item));
}
const responses = await Promise.all(pres); // Parallel execution within sets
for (const response of responses) {
if (response !== undefined) {
return response;
}
}
}
}
// Handler
const result = await internals.handler(request, request.route.settings.handler);
if (result._takeover ||
typeof result === 'symbol') {
return result;
}
request._setResponse(result);
};
internals.handler = async function (request, method, pre) {
const bind = request.route.settings.bind;
const realm = request.route.realm;
let response = await request._core.toolkit.execute(method, request, { bind, realm, continue: 'null' });
// Handler
if (!pre) {
if (response.isBoom) {
request._log(['handler', 'error'], response);
throw response;
}
return response;
}
// Pre
if (response.isBoom) {
response.assign = pre.assign;
response = await request._core.toolkit.failAction(request, pre.failAction, response, { tags: ['pre', 'error'], retain: true });
}
if (typeof response === 'symbol') {
return response;
}
if (pre.assign) {
request.pre[pre.assign] = (response.isBoom ? response : response.source);
request.preResponses[pre.assign] = response;
}
if (response._takeover) {
return response;
}
};
exports.defaults = function (method, handler, core) {
let defaults = null;
if (typeof handler === 'object') {
const type = Object.keys(handler)[0];
const serverHandler = core.decorations.handler.get(type);
Hoek.assert(serverHandler, 'Unknown handler:', type);
if (serverHandler.defaults) {
defaults = (typeof serverHandler.defaults === 'function' ? serverHandler.defaults(method) : serverHandler.defaults);
}
}
return defaults ?? {};
};
exports.configure = function (handler, route) {
if (typeof handler === 'object') {
const type = Object.keys(handler)[0];
const serverHandler = route._core.decorations.handler.get(type);
Hoek.assert(serverHandler, 'Unknown handler:', type);
return serverHandler(route.public, handler[type]);
}
return handler;
};
exports.prerequisitesConfig = function (config) {
if (!config) {
return null;
}
/*
[
[
function (request, h) { },
{
method: function (request, h) { }
assign: key1
},
{
method: function (request, h) { },
assign: key2
}
],
{
method: function (request, h) { },
assign: key3
}
]
*/
const prerequisites = [];
for (let pres of config) {
pres = [].concat(pres);
const set = [];
for (let pre of pres) {
if (typeof pre !== 'object') {
pre = { method: pre };
}
const item = {
method: pre.method,
assign: pre.assign,
failAction: pre.failAction ?? 'error'
};
set.push(item);
}
prerequisites.push(set);
}
return prerequisites.length ? prerequisites : null;
};

177
node_modules/@hapi/hapi/lib/headers.js generated vendored Executable file
View File

@@ -0,0 +1,177 @@
'use strict';
const Stream = require('stream');
const Boom = require('@hapi/boom');
const internals = {};
exports.cache = function (response) {
const request = response.request;
if (response.headers['cache-control']) {
return;
}
const settings = request.route.settings.cache;
const policy = settings && request._route._cache && (settings._statuses.has(response.statusCode) || (response.statusCode === 304 && settings._statuses.has(200)));
if (policy ||
response.settings.ttl) {
const ttl = response.settings.ttl !== null ? response.settings.ttl : request._route._cache.ttl();
const privacy = request.auth.isAuthenticated || response.headers['set-cookie'] ? 'private' : settings.privacy ?? 'default';
response._header('cache-control', 'max-age=' + Math.floor(ttl / 1000) + ', must-revalidate' + (privacy !== 'default' ? ', ' + privacy : ''));
}
else if (settings) {
response._header('cache-control', settings.otherwise);
}
};
exports.content = async function (response) {
const request = response.request;
if (response._isPayloadSupported() ||
request.method === 'head') {
await response._marshal();
if (typeof response._payload.size === 'function') {
response._header('content-length', response._payload.size(), { override: false });
}
if (!response._isPayloadSupported()) {
response._close(); // Close unused file streams
response._payload = new internals.Empty(); // Set empty stream
}
exports.type(response);
}
else {
// Set empty stream
response._close(); // Close unused file streams
response._payload = new internals.Empty();
delete response.headers['content-length'];
}
};
exports.state = async function (response) {
const request = response.request;
const states = [];
for (const stateName in request._states) {
states.push(request._states[stateName]);
}
try {
for (const name in request._core.states.cookies) {
const autoValue = request._core.states.cookies[name].autoValue;
if (!autoValue || name in request._states || name in request.state) {
continue;
}
if (typeof autoValue !== 'function') {
states.push({ name, value: autoValue });
continue;
}
const value = await autoValue(request);
states.push({ name, value });
}
if (!states.length) {
return;
}
let header = await request._core.states.format(states, request);
const existing = response.headers['set-cookie'];
if (existing) {
header = (Array.isArray(existing) ? existing : [existing]).concat(header);
}
response._header('set-cookie', header);
}
catch (err) {
const error = Boom.boomify(err);
request._log(['state', 'response', 'error'], error);
request._states = {}; // Clear broken state
throw error;
}
};
exports.type = function (response) {
const type = response.contentType;
if (type !== null && type !== response.headers['content-type']) {
response.type(type);
}
};
exports.entity = function (response) {
const request = response.request;
if (!request._entity) {
return;
}
if (request._entity.etag &&
!response.headers.etag) {
response.etag(request._entity.etag, { vary: request._entity.vary });
}
if (request._entity.modified &&
!response.headers['last-modified']) {
response.header('last-modified', request._entity.modified);
}
};
exports.unmodified = function (response) {
const request = response.request;
if (response.statusCode === 304) {
return;
}
const entity = {
etag: response.headers.etag,
vary: response.settings.varyEtag,
modified: response.headers['last-modified']
};
const etag = request._core.Response.unmodified(request, entity);
if (etag) {
response.code(304);
if (etag !== true) { // Override etag with incoming weak match
response.headers.etag = etag;
}
}
};
internals.Empty = class extends Stream.Readable {
_read(/* size */) {
this.push(null);
}
writeToStream(stream) {
stream.end();
}
};

1
node_modules/@hapi/hapi/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export * from './types';

11
node_modules/@hapi/hapi/lib/index.js generated vendored Executable file
View File

@@ -0,0 +1,11 @@
'use strict';
const Server = require('./server');
const internals = {};
exports.Server = Server;
exports.server = Server;

126
node_modules/@hapi/hapi/lib/methods.js generated vendored Executable file
View File

@@ -0,0 +1,126 @@
'use strict';
const Boom = require('@hapi/boom');
const Hoek = require('@hapi/hoek');
const Config = require('./config');
const internals = {
methodNameRx: /^[_$a-zA-Z][$\w]*(?:\.[_$a-zA-Z][$\w]*)*$/
};
exports = module.exports = internals.Methods = class {
methods = {};
#core = null;
constructor(core) {
this.#core = core;
}
add(name, method, options, realm) {
if (typeof name !== 'object') {
return this._add(name, method, options, realm);
}
// {} or [{}, {}]
const items = [].concat(name);
for (let item of items) {
item = Config.apply('methodObject', item);
this._add(item.name, item.method, item.options ?? {}, realm);
}
}
_add(name, method, options, realm) {
Hoek.assert(typeof method === 'function', 'method must be a function');
Hoek.assert(typeof name === 'string', 'name must be a string');
Hoek.assert(name.match(internals.methodNameRx), 'Invalid name:', name);
Hoek.assert(!Hoek.reach(this.methods, name, { functions: false }), 'Server method function name already exists:', name);
options = Config.apply('method', options, name);
const settings = Hoek.clone(options, { shallow: ['bind'] });
settings.generateKey = settings.generateKey ?? internals.generateKey;
const bind = settings.bind ?? realm.settings.bind ?? null;
const bound = !bind ? method : (...args) => method.apply(bind, args);
// Not cached
if (!settings.cache) {
return this._assign(name, bound);
}
// Cached
Hoek.assert(!settings.cache.generateFunc, 'Cannot set generateFunc with method caching:', name);
Hoek.assert(settings.cache.generateTimeout !== undefined, 'Method caching requires a timeout value in generateTimeout:', name);
settings.cache.generateFunc = (id, flags) => bound(...id.args, flags);
const cache = this.#core._cachePolicy(settings.cache, '#' + name);
const func = function (...args) {
const key = settings.generateKey.apply(bind, args);
if (typeof key !== 'string') {
return Promise.reject(Boom.badImplementation('Invalid method key when invoking: ' + name, { name, args }));
}
return cache.get({ id: key, args });
};
func.cache = {
drop: function (...args) {
const key = settings.generateKey.apply(bind, args);
if (typeof key !== 'string') {
return Promise.reject(Boom.badImplementation('Invalid method key when invoking: ' + name, { name, args }));
}
return cache.drop(key);
},
stats: cache.stats
};
this._assign(name, func, func);
}
_assign(name, method) {
const path = name.split('.');
let ref = this.methods;
for (let i = 0; i < path.length; ++i) {
if (!ref[path[i]]) {
ref[path[i]] = (i + 1 === path.length ? method : {});
}
ref = ref[path[i]];
}
}
};
internals.supportedArgs = ['string', 'number', 'boolean'];
internals.generateKey = function (...args) {
let key = '';
for (let i = 0; i < args.length; ++i) {
const arg = args[i];
if (!internals.supportedArgs.includes(typeof arg)) {
return null;
}
key = key + (i ? ':' : '') + encodeURIComponent(arg.toString());
}
return key;
};

754
node_modules/@hapi/hapi/lib/request.js generated vendored Executable file
View File

@@ -0,0 +1,754 @@
'use strict';
const Querystring = require('querystring');
const Url = require('url');
const Boom = require('@hapi/boom');
const Bounce = require('@hapi/bounce');
const Hoek = require('@hapi/hoek');
const Podium = require('@hapi/podium');
const Cors = require('./cors');
const Toolkit = require('./toolkit');
const Transmit = require('./transmit');
const internals = {
events: Podium.validate(['finish', { name: 'peek', spread: true }, 'disconnect']),
reserved: ['server', 'url', 'query', 'path', 'method', 'mime', 'setUrl', 'setMethod', 'headers', 'id', 'app', 'plugins', 'route', 'auth', 'pre', 'preResponses', 'info', 'isInjected', 'orig', 'params', 'paramsArray', 'payload', 'state', 'response', 'raw', 'domain', 'log', 'logs', 'generateResponse']
};
exports = module.exports = internals.Request = class {
constructor(server, req, res, options) {
this._allowInternals = !!options.allowInternals;
this._closed = false; // true once the response has closed (esp. early) and will not emit any more events
this._core = server._core;
this._entity = null; // Entity information set via h.entity()
this._eventContext = { request: this };
this._events = null; // Assigned an emitter when request.events is accessed
this._expectContinue = !!options.expectContinue;
this._isInjected = !!options.isInjected;
this._isPayloadPending = !!(req.headers['content-length'] || req.headers['transfer-encoding']); // Changes to false when incoming payload fully processed
this._isReplied = false; // true when response processing started
this._route = this._core.router.specials.notFound.route; // Used prior to routing (only settings are used, not the handler)
this._serverTimeoutId = null;
this._states = {};
this._url = null;
this._urlError = null;
this.app = options.app ? Object.assign({}, options.app) : {}; // Place for application-specific state without conflicts with hapi, should not be used by plugins (shallow cloned)
this.headers = req.headers;
this.logs = [];
this.method = req.method.toLowerCase();
this.mime = null;
this.orig = {};
this.params = null;
this.paramsArray = null; // Array of path parameters in path order
this.path = null;
this.payload = undefined;
this.plugins = options.plugins ? Object.assign({}, options.plugins) : {}; // Place for plugins to store state without conflicts with hapi, should be namespaced using plugin name (shallow cloned)
this.pre = {}; // Pre raw values
this.preResponses = {}; // Pre response values
this.raw = { req, res };
this.response = null;
this.route = this._route.public;
this.query = null;
this.server = server;
this.state = null;
this.info = new internals.Info(this);
this.auth = {
isAuthenticated: false,
isAuthorized: false,
isInjected: options.auth ? true : false,
[internals.Request.symbols.authPayload]: options.auth?.payload ?? true,
credentials: options.auth?.credentials ?? null, // Special keys: 'app', 'user', 'scope'
artifacts: options.auth?.artifacts ?? null, // Scheme-specific artifacts
strategy: options.auth?.strategy ?? null,
mode: null,
error: null
};
// Parse request url
this._initializeUrl();
}
static generate(server, req, res, options) {
const request = new server._core.Request(server, req, res, options);
// Decorate
if (server._core.decorations.requestApply) {
for (const [property, assignment] of server._core.decorations.requestApply.entries()) {
request[property] = assignment(request);
}
}
request._listen();
return request;
}
get events() {
if (!this._events) {
this._events = new Podium.Podium(internals.events);
}
return this._events;
}
get isInjected() {
return this._isInjected;
}
get url() {
if (this._urlError) {
return null;
}
if (this._url) {
return this._url;
}
return this._parseUrl(this.raw.req.url, this._core.settings.router);
}
_initializeUrl() {
try {
this._setUrl(this.raw.req.url, this._core.settings.router.stripTrailingSlash, { fast: true });
}
catch (err) {
this.path = this.raw.req.url;
this.query = {};
this._urlError = Boom.boomify(err, { statusCode: 400, override: false });
}
}
setUrl(url, stripTrailingSlash) {
Hoek.assert(this.params === null, 'Cannot change request URL after routing');
if (url instanceof Url.URL) {
url = url.href;
}
Hoek.assert(typeof url === 'string', 'Url must be a string or URL object');
this._setUrl(url, stripTrailingSlash, { fast: false });
}
_setUrl(source, stripTrailingSlash, { fast }) {
const url = this._parseUrl(source, { stripTrailingSlash, _fast: fast });
this.query = this._parseQuery(url.searchParams);
this.path = url.pathname;
}
_parseUrl(source, options) {
if (source[0] === '/') {
// Relative URL
if (options._fast) {
const url = {
pathname: source,
searchParams: ''
};
const q = source.indexOf('?');
const h = source.indexOf('#');
if (q !== -1 &&
(h === -1 || q < h)) {
url.pathname = source.slice(0, q);
const query = h === -1 ? source.slice(q + 1) : source.slice(q + 1, h);
url.searchParams = Querystring.parse(query);
}
else {
url.pathname = h === -1 ? source : source.slice(0, h);
}
this._normalizePath(url, options);
return url;
}
this._url = new Url.URL(`${this._core.info.protocol}://${this.info.host || `${this._core.info.host}:${this._core.info.port}`}${source}`);
}
else {
// Absolute URI (proxied)
this._url = new Url.URL(source);
this.info.hostname = this._url.hostname;
this.info.host = this._url.host;
}
this._normalizePath(this._url, options);
this._urlError = null;
return this._url;
}
_normalizePath(url, options) {
let path = this._core.router.normalize(url.pathname);
if (options.stripTrailingSlash &&
path.length > 1 &&
path[path.length - 1] === '/') {
path = path.slice(0, -1);
}
url.pathname = path;
}
_parseQuery(searchParams) {
let query = Object.create(null);
// Flatten map
if (searchParams instanceof Url.URLSearchParams) {
for (let [key, value] of searchParams) {
const entry = query[key];
if (entry !== undefined) {
value = [].concat(entry, value);
}
query[key] = value;
}
}
else {
query = Object.assign(query, searchParams);
}
// Custom parser
const parser = this._core.settings.query.parser;
if (parser) {
query = parser(query);
if (!query ||
typeof query !== 'object') {
throw Boom.badImplementation('Parsed query must be an object');
}
}
return query;
}
setMethod(method) {
Hoek.assert(this.params === null, 'Cannot change request method after routing');
Hoek.assert(method && typeof method === 'string', 'Missing method');
this.method = method.toLowerCase();
}
active() {
return !!this._eventContext.request;
}
async _execute() {
this.info.acceptEncoding = this._core.compression.accept(this);
try {
await this._onRequest();
}
catch (err) {
Bounce.rethrow(err, 'system');
return this._reply(err);
}
this._lookup();
this._setTimeouts();
await this._lifecycle();
this._reply();
}
async _onRequest() {
// onRequest (can change request method and url)
if (this._core.extensions.route.onRequest.nodes) {
const response = await this._invoke(this._core.extensions.route.onRequest);
if (response) {
if (!internals.skip(response)) {
throw Boom.badImplementation('onRequest extension methods must return an error, a takeover response, or a continue signal');
}
throw response;
}
}
// Validate path
if (this._urlError) {
throw this._urlError;
}
}
_listen() {
if (this._isPayloadPending) {
this.raw.req.on('end', internals.event.bind(this.raw.req, this._eventContext, 'end'));
}
this.raw.res.on('close', internals.event.bind(this.raw.res, this._eventContext, 'close'));
this.raw.req.on('error', internals.event.bind(this.raw.req, this._eventContext, 'error'));
this.raw.req.on('aborted', internals.event.bind(this.raw.req, this._eventContext, 'abort'));
this.raw.res.once('close', internals.closed.bind(this.raw.res, this));
}
_lookup() {
const match = this._core.router.route(this.method, this.path, this.info.hostname);
if (!match.route.settings.isInternal ||
this._allowInternals) {
this._route = match.route;
this.route = this._route.public;
}
this.params = match.params ?? {};
this.paramsArray = match.paramsArray ?? [];
if (this.route.settings.cors) {
this.info.cors = {
isOriginMatch: Cors.matchOrigin(this.headers.origin, this.route.settings.cors)
};
}
}
_setTimeouts() {
if (this.raw.req.socket &&
this.route.settings.timeout.socket !== undefined) {
this.raw.req.socket.setTimeout(this.route.settings.timeout.socket || 0); // Value can be false or positive
}
let serverTimeout = this.route.settings.timeout.server;
if (!serverTimeout) {
return;
}
const elapsed = Date.now() - this.info.received;
serverTimeout = Math.floor(serverTimeout - elapsed); // Calculate the timeout from when the request was constructed
if (serverTimeout <= 0) {
internals.timeoutReply(this, serverTimeout);
return;
}
this._serverTimeoutId = setTimeout(internals.timeoutReply, serverTimeout, this, serverTimeout);
}
async _lifecycle() {
for (const func of this._route._cycle) {
if (this._isReplied) {
return;
}
try {
var response = await (typeof func === 'function' ? func(this) : this._invoke(func));
}
catch (err) {
Bounce.rethrow(err, 'system');
response = this._core.Response.wrap(err, this);
}
if (!response ||
response === Toolkit.symbols.continue) { // Continue
continue;
}
if (!internals.skip(response)) {
response = Boom.badImplementation('Lifecycle methods called before the handler can only return an error, a takeover response, or a continue signal');
}
this._setResponse(response);
return;
}
}
async _invoke(event, options = {}) {
for (const ext of event.nodes) {
const realm = ext.realm;
const bind = ext.bind ?? realm.settings.bind;
const response = await this._core.toolkit.execute(ext.func, this, { bind, realm, timeout: ext.timeout, name: event.type, ignoreResponse: options.ignoreResponse });
if (options.ignoreResponse) {
if (Boom.isBoom(response)) {
this._log(['ext', 'error'], response);
}
continue;
}
if (response === Toolkit.symbols.continue) {
continue;
}
if (internals.skip(response) ||
this.response === null) {
return response;
}
this._setResponse(response);
}
}
async _reply(exit) {
if (this._isReplied) { // Prevent any future responses to this request
return;
}
this._isReplied = true;
if (this._serverTimeoutId) {
clearTimeout(this._serverTimeoutId);
}
if (exit) { // Can be a valid response or error (if returned from an ext, already handled because this.response is also set)
this._setResponse(this._core.Response.wrap(exit, this)); // Wrap to ensure any object thrown is always a valid Boom or Response object
}
if (!this._eventContext.request) {
this._finalize();
return;
}
if (typeof this.response === 'symbol') { // close or abandon
this._abort();
return;
}
await this._postCycle();
if (!this._eventContext.request ||
typeof this.response === 'symbol') { // close or abandon
this._abort();
return;
}
await Transmit.send(this);
this._finalize();
}
async _postCycle() {
for (const func of this._route._postCycle) {
if (!this._eventContext.request) {
return;
}
try {
var response = await (typeof func === 'function' ? func(this) : this._invoke(func));
}
catch (err) {
Bounce.rethrow(err, 'system');
response = this._core.Response.wrap(err, this);
}
if (response &&
response !== Toolkit.symbols.continue) { // Continue
this._setResponse(response);
}
}
}
_abort() {
if (this.response === Toolkit.symbols.close) {
this.raw.res.end(); // End the response in case it wasn't already closed
}
this._finalize();
}
_finalize() {
this._eventContext.request = null; // Disable req events
if (this.response._close) {
if (this.response.statusCode === 500 &&
this.response._error) {
const tags = this.response._error.isDeveloperError ? ['internal', 'implementation', 'error'] : ['internal', 'error'];
this._log(tags, this.response._error, 'error');
}
this.response._close();
}
this.info.completed = Date.now();
this._core.events.emit('response', this);
if (this._route._extensions.onPostResponse.nodes) {
this._invoke(this._route._extensions.onPostResponse, { ignoreResponse: true });
}
}
_setResponse(response) {
if (this.response &&
!this.response.isBoom &&
this.response !== response &&
this.response.source !== response.source) {
this.response._close?.();
}
if (this.info.completed) {
response._close?.();
return;
}
this.response = response;
}
_setState(name, value, options) {
const state = { name, value };
if (options) {
Hoek.assert(!options.autoValue, 'Cannot set autoValue directly in a response');
state.options = Hoek.clone(options);
}
this._states[name] = state;
}
_clearState(name, options = {}) {
const state = { name };
state.options = Hoek.clone(options);
state.options.ttl = 0;
this._states[name] = state;
}
_tap() {
if (!this._events) {
return null;
}
if (this._events.hasListeners('peek') ||
this._events.hasListeners('finish')) {
return new this._core.Response.Peek(this._events);
}
return null;
}
log(tags, data) {
return this._log(tags, data, 'app');
}
_log(tags, data, channel = 'internal') {
if (!this._core.events.hasListeners('request') &&
!this.route.settings.log.collect) {
return;
}
if (!Array.isArray(tags)) {
tags = [tags];
}
const timestamp = Date.now();
const field = data instanceof Error ? 'error' : 'data';
let event = [this, { request: this.info.id, timestamp, tags, [field]: data, channel }];
if (typeof data === 'function') {
event = () => [this, { request: this.info.id, timestamp, tags, data: data(), channel }];
}
if (this.route.settings.log.collect) {
if (typeof data === 'function') {
event = event();
}
this.logs.push(event[1]);
}
this._core.events.emit({ name: 'request', channel, tags }, event);
}
generateResponse(source, options) {
return new this._core.Response(source, this, options);
}
};
internals.Request.reserved = internals.reserved;
internals.Request.symbols = {
authPayload: Symbol('auth.payload')
};
internals.Info = class {
constructor(request) {
this._request = request;
const req = request.raw.req;
const host = req.headers.host ? req.headers.host.trim() : '';
const received = Date.now();
this.received = received;
this.referrer = req.headers.referrer || req.headers.referer || '';
this.host = host;
this.hostname = /^(.*?)(?::\d+)?$/.exec(host)[1];
this.id = `${received}:${request._core.info.id}:${request._core._counter()}`;
this._remoteAddress = null;
this._remotePort = null;
// Assigned later
this.acceptEncoding = null;
this.cors = null;
this.responded = 0;
this.completed = 0;
if (request._core.settings.info.remote) {
this.remoteAddress;
this.remotePort;
}
}
get remoteAddress() {
if (!this._remoteAddress) {
const ipv6Prefix = '::ffff:';
const socketAddress = this._request.raw.req.socket.remoteAddress;
if (socketAddress && socketAddress.startsWith(ipv6Prefix) && socketAddress.includes('.', ipv6Prefix.length)) {
// Normalize IPv4-mapped IPv6 address, e.g. ::ffff:127.0.0.1 -> 127.0.0.1
this._remoteAddress = socketAddress.slice(ipv6Prefix.length);
}
else {
this._remoteAddress = socketAddress;
}
}
return this._remoteAddress;
}
get remotePort() {
if (this._remotePort === null) {
this._remotePort = this._request.raw.req.socket.remotePort || '';
}
return this._remotePort;
}
toJSON() {
return {
acceptEncoding: this.acceptEncoding,
completed: this.completed,
cors: this.cors,
host: this.host,
hostname: this.hostname,
id: this.id,
received: this.received,
referrer: this.referrer,
remoteAddress: this.remoteAddress,
remotePort: this.remotePort,
responded: this.responded
};
}
};
internals.closed = function (request) {
request._closed = true;
};
internals.event = function ({ request }, event, err) {
if (!request) {
return;
}
request._isPayloadPending = false;
if (event === 'close' &&
request.raw.res.writableEnded) {
return;
}
if (event === 'end') {
return;
}
request._log(err ? ['request', 'error'] : ['request', 'error', event], err);
if (event === 'error') {
return;
}
request._eventContext.request = null;
if (event === 'abort') {
// Calling _reply() means that the abort is applied immediately, unless the response has already
// called _reply(), in which case this call is ignored and the transmit logic is responsible for
// handling the abort.
request._reply(new Boom.Boom('Request aborted', { statusCode: request.route.settings.response.disconnectStatusCode, data: request.response }));
if (request._events) {
request._events.emit('disconnect');
}
}
};
internals.timeoutReply = function (request, timeout) {
const elapsed = Date.now() - request.info.received;
request._log(['request', 'server', 'timeout', 'error'], { timeout, elapsed });
request._reply(Boom.serverUnavailable());
};
internals.skip = function (response) {
return response.isBoom || response._takeover || typeof response === 'symbol';
};

751
node_modules/@hapi/hapi/lib/response.js generated vendored Executable file
View File

@@ -0,0 +1,751 @@
'use strict';
const Stream = require('stream');
const Boom = require('@hapi/boom');
const Bounce = require('@hapi/bounce');
const Hoek = require('@hapi/hoek');
const Podium = require('@hapi/podium');
const Streams = require('./streams');
const internals = {
events: Podium.validate(['finish', { name: 'peek', spread: true }]),
hopByHop: {
connection: true,
'keep-alive': true,
'proxy-authenticate': true,
'proxy-authorization': true,
'te': true,
'trailer': true,
'transfer-encoding': true,
'upgrade': true
},
reserved: ['app', 'headers', 'plugins', 'request', 'source', 'statusCode', 'variety',
'settings', 'events', 'code', 'message', 'header', 'vary', 'etag', 'type', 'contentType',
'bytes', 'location', 'created', 'compressed', 'replacer', 'space', 'suffix', 'escape',
'passThrough', 'redirect', 'temporary', 'permanent', 'rewritable', 'encoding', 'charset',
'ttl', 'state', 'unstate', 'takeover']
};
exports = module.exports = internals.Response = class {
constructor(source, request, options = {}) {
this.app = {};
this.headers = {}; // Incomplete as some headers are stored in flags
this.plugins = {};
this.request = request;
this.source = null;
this.statusCode = null;
this.variety = null;
this.settings = {
charset: 'utf-8', // '-' required by IANA
compressed: null,
encoding: 'utf8',
message: null,
passThrough: true,
stringify: null, // JSON.stringify options
ttl: null,
varyEtag: false
};
this._events = null;
this._payload = null; // Readable stream
this._error = options.error ?? null; // The boom object when created from an error (used for logging)
this._contentType = null; // Used if no explicit content-type is set and type is known
this._takeover = false;
this._statusCode = false; // true when code() called
this._state = this._error ? 'prepare' : 'init'; // One of 'init', 'prepare', 'marshall', 'close'
this._processors = {
marshal: options.marshal,
prepare: options.prepare,
close: options.close
};
this._setSource(source, options.variety);
}
static wrap(result, request) {
if (result instanceof request._core.Response ||
typeof result === 'symbol') {
return result;
}
if (result instanceof Error) {
return Boom.boomify(result);
}
return new request._core.Response(result, request);
}
_setSource(source, variety) {
// Method must not set any headers or other properties as source can change later
this.variety = variety ?? 'plain';
if (source === null ||
source === undefined) {
source = null;
}
else if (Buffer.isBuffer(source)) {
this.variety = 'buffer';
this._contentType = 'application/octet-stream';
}
else if (Streams.isStream(source)) {
this.variety = 'stream';
this._contentType = 'application/octet-stream';
}
this.source = source;
if (this.variety === 'plain' &&
this.source !== null) {
this._contentType = typeof this.source === 'string' ? 'text/html' : 'application/json';
}
}
get events() {
if (!this._events) {
this._events = new Podium.Podium(internals.events);
}
return this._events;
}
code(statusCode) {
Hoek.assert(Number.isSafeInteger(statusCode), 'Status code must be an integer');
this.statusCode = statusCode;
this._statusCode = true;
return this;
}
message(httpMessage) {
this.settings.message = httpMessage;
return this;
}
header(key, value, options) {
key = key.toLowerCase();
if (key === 'vary') {
return this.vary(value);
}
return this._header(key, value, options);
}
_header(key, value, options = {}) {
const append = options.append ?? false;
const separator = options.separator || ',';
const override = options.override !== false;
const duplicate = options.duplicate !== false;
if (!append && override ||
!this.headers[key]) {
this.headers[key] = value;
}
else if (override) {
if (key === 'set-cookie') {
this.headers[key] = [].concat(this.headers[key], value);
}
else {
const existing = this.headers[key];
if (!duplicate) {
const values = existing.split(separator);
for (const v of values) {
if (v === value) {
return this;
}
}
}
this.headers[key] = existing + separator + value;
}
}
return this;
}
vary(value) {
if (value === '*') {
this.headers.vary = '*';
}
else if (!this.headers.vary) {
this.headers.vary = value;
}
else if (this.headers.vary !== '*') {
this._header('vary', value, { append: true, duplicate: false });
}
return this;
}
etag(tag, options) {
const entity = this.request._core.Response.entity(tag, options);
this._header('etag', entity.etag);
this.settings.varyEtag = entity.vary;
return this;
}
static entity(tag, options = {}) {
Hoek.assert(tag !== '*', 'ETag cannot be *');
return {
etag: (options.weak ? 'W/' : '') + '"' + tag + '"',
vary: options.vary !== false && !options.weak, // vary defaults to true
modified: options.modified
};
}
static unmodified(request, entity) {
if (request.method !== 'get' &&
request.method !== 'head') {
return false;
}
// Strong verifier
if (entity.etag &&
request.headers['if-none-match']) {
const ifNoneMatch = request.headers['if-none-match'].split(/\s*,\s*/);
for (const etag of ifNoneMatch) {
// Compare tags (https://tools.ietf.org/html/rfc7232#section-2.3.2)
if (etag === entity.etag) { // Strong comparison
return true;
}
if (!entity.vary) {
continue;
}
if (etag === `W/${entity.etag}`) { // Weak comparison
return etag;
}
const etagBase = entity.etag.slice(0, -1);
const encoders = request._core.compression.encodings;
for (const encoder of encoders) {
if (etag === etagBase + `-${encoder}"`) {
return true;
}
}
}
return false;
}
// Weak verifier
if (!entity.modified) {
return false;
}
const ifModifiedSinceHeader = request.headers['if-modified-since'];
if (!ifModifiedSinceHeader) {
return false;
}
const ifModifiedSince = internals.parseDate(ifModifiedSinceHeader);
if (!ifModifiedSince) {
return false;
}
const lastModified = internals.parseDate(entity.modified);
if (!lastModified) {
return false;
}
return ifModifiedSince >= lastModified;
}
type(type) {
this._header('content-type', type);
return this;
}
get contentType() {
let type = this.headers['content-type'];
if (type) {
type = type.trim();
if (this.settings.charset &&
type.match(/^(?:text\/)|(?:application\/(?:json)|(?:javascript))/) &&
!type.match(/; *charset=/)) {
const semi = type[type.length - 1] === ';';
return type + (semi ? ' ' : '; ') + 'charset=' + this.settings.charset;
}
return type;
}
if (this._contentType) {
const charset = this.settings.charset && this._contentType !== 'application/octet-stream' ? '; charset=' + this.settings.charset : '';
return this._contentType + charset;
}
return null;
}
bytes(bytes) {
this._header('content-length', bytes);
return this;
}
location(uri) {
this._header('location', uri);
return this;
}
created(location) {
Hoek.assert(this.request.method === 'post' ||
this.request.method === 'put' ||
this.request.method === 'patch', 'Cannot return 201 status codes for ' + this.request.method.toUpperCase());
this.statusCode = 201;
this.location(location);
return this;
}
compressed(encoding) {
Hoek.assert(encoding && typeof encoding === 'string', 'Invalid content-encoding');
this.settings.compressed = encoding;
return this;
}
replacer(method) {
this.settings.stringify = this.settings.stringify ?? {};
this.settings.stringify.replacer = method;
return this;
}
spaces(count) {
this.settings.stringify = this.settings.stringify ?? {};
this.settings.stringify.space = count;
return this;
}
suffix(suffix) {
this.settings.stringify = this.settings.stringify ?? {};
this.settings.stringify.suffix = suffix;
return this;
}
escape(escape) {
this.settings.stringify = this.settings.stringify ?? {};
this.settings.stringify.escape = escape;
return this;
}
passThrough(enabled) {
this.settings.passThrough = enabled !== false; // Defaults to true
return this;
}
redirect(location) {
this.statusCode = 302;
this.location(location);
return this;
}
temporary(isTemporary) {
Hoek.assert(this.headers.location, 'Cannot set redirection mode without first setting a location');
this._setTemporary(isTemporary !== false); // Defaults to true
return this;
}
permanent(isPermanent) {
Hoek.assert(this.headers.location, 'Cannot set redirection mode without first setting a location');
this._setTemporary(isPermanent === false); // Defaults to true
return this;
}
rewritable(isRewritable) {
Hoek.assert(this.headers.location, 'Cannot set redirection mode without first setting a location');
this._setRewritable(isRewritable !== false); // Defaults to true
return this;
}
_isTemporary() {
return this.statusCode === 302 || this.statusCode === 307;
}
_isRewritable() {
return this.statusCode === 301 || this.statusCode === 302;
}
_setTemporary(isTemporary) {
if (isTemporary) {
if (this._isRewritable()) {
this.statusCode = 302;
}
else {
this.statusCode = 307;
}
}
else {
if (this._isRewritable()) {
this.statusCode = 301;
}
else {
this.statusCode = 308;
}
}
}
_setRewritable(isRewritable) {
if (isRewritable) {
if (this._isTemporary()) {
this.statusCode = 302;
}
else {
this.statusCode = 301;
}
}
else {
if (this._isTemporary()) {
this.statusCode = 307;
}
else {
this.statusCode = 308;
}
}
}
encoding(encoding) {
this.settings.encoding = encoding;
return this;
}
charset(charset) {
this.settings.charset = charset ?? null;
return this;
}
ttl(ttl) {
this.settings.ttl = ttl;
return this;
}
state(name, value, options) {
this.request._setState(name, value, options);
return this;
}
unstate(name, options) {
this.request._clearState(name, options);
return this;
}
takeover() {
this._takeover = true;
return this;
}
_prepare() {
Hoek.assert(this._state === 'init');
this._state = 'prepare';
this._passThrough();
if (!this._processors.prepare) {
return this;
}
try {
return this._processors.prepare(this);
}
catch (err) {
throw Boom.boomify(err);
}
}
_passThrough() {
if (this.variety === 'stream' &&
this.settings.passThrough) {
if (this.source.statusCode &&
!this.statusCode) {
this.statusCode = this.source.statusCode; // Stream is an HTTP response
}
if (this.source.headers) {
let headerKeys = Object.keys(this.source.headers);
if (headerKeys.length) {
const localHeaders = this.headers;
this.headers = {};
const connection = this.source.headers.connection;
const byHop = {};
if (connection) {
connection.split(/\s*,\s*/).forEach((header) => {
byHop[header] = true;
});
}
for (const key of headerKeys) {
const lower = key.toLowerCase();
if (!internals.hopByHop[lower] &&
!byHop[lower]) {
this.header(lower, Hoek.clone(this.source.headers[key])); // Clone arrays
}
}
headerKeys = Object.keys(localHeaders);
for (const key of headerKeys) {
this.header(key, localHeaders[key], { append: key === 'set-cookie' });
}
}
}
}
this.statusCode = this.statusCode ?? 200;
}
async _marshal() {
Hoek.assert(this._state === 'prepare');
this._state = 'marshall';
// Processor marshal
let source = this.source;
if (this._processors.marshal) {
try {
source = await this._processors.marshal(this);
}
catch (err) {
throw Boom.boomify(err);
}
}
// Stream source
if (Streams.isStream(source)) {
this._payload = source;
return;
}
// Plain source (non string or null)
const jsonify = this.variety === 'plain' && source !== null && typeof source !== 'string';
if (!jsonify &&
this.settings.stringify) {
throw Boom.badImplementation('Cannot set formatting options on non object response');
}
let payload = source;
if (jsonify) {
const options = this.settings.stringify ?? {};
const space = options.space ?? this.request.route.settings.json.space;
const replacer = options.replacer ?? this.request.route.settings.json.replacer;
const suffix = options.suffix ?? this.request.route.settings.json.suffix ?? '';
const escape = this.request.route.settings.json.escape;
try {
if (replacer || space) {
payload = JSON.stringify(payload, replacer, space);
}
else {
payload = JSON.stringify(payload);
}
}
catch (err) {
throw Boom.boomify(err);
}
if (suffix) {
payload = payload + suffix;
}
if (escape) {
payload = Hoek.escapeJson(payload);
}
}
this._payload = new internals.Response.Payload(payload, this.settings);
}
_tap() {
if (!this._events) {
return null;
}
if (this._events.hasListeners('peek') ||
this._events.hasListeners('finish')) {
return new internals.Response.Peek(this._events);
}
return null;
}
_close() {
if (this._state === 'close') {
return;
}
this._state = 'close';
if (this._processors.close) {
try {
this._processors.close(this);
}
catch (err) {
Bounce.rethrow(err, 'system');
this.request._log(['response', 'cleanup', 'error'], err);
}
}
const stream = this._payload || this.source;
if (Streams.isStream(stream)) {
internals.Response.drain(stream);
}
}
_isPayloadSupported() {
return this.request.method !== 'head' && this.statusCode !== 304 && this.statusCode !== 204;
}
static drain(stream) {
stream.destroy();
}
};
internals.Response.reserved = internals.reserved;
internals.parseDate = function (string) {
try {
return Date.parse(string);
}
catch (errIgnore) { }
};
internals.Response.Payload = class extends Stream.Readable {
constructor(payload, options) {
super();
this._data = payload;
this._encoding = options.encoding;
}
_read(size) {
if (this._data) {
this.push(this._data, this._encoding);
}
this.push(null);
}
size() {
if (!this._data) {
return 0;
}
return Buffer.isBuffer(this._data) ? this._data.length : Buffer.byteLength(this._data, this._encoding);
}
writeToStream(stream) {
if (this._data) {
stream.write(this._data, this._encoding);
}
stream.end();
}
};
internals.Response.Peek = class extends Stream.Transform {
constructor(podium) {
super();
this._podium = podium;
this.on('finish', () => podium.emit('finish'));
}
_transform(chunk, encoding, callback) {
this._podium.emit('peek', [chunk, encoding]);
this.push(chunk, encoding);
callback();
}
};

489
node_modules/@hapi/hapi/lib/route.js generated vendored Executable file
View File

@@ -0,0 +1,489 @@
'use strict';
const Assert = require('assert');
const Bounce = require('@hapi/bounce');
const Catbox = require('@hapi/catbox');
const Hoek = require('@hapi/hoek');
const Subtext = require('@hapi/subtext');
const Validate = require('@hapi/validate');
const Auth = require('./auth');
const Config = require('./config');
const Cors = require('./cors');
const Ext = require('./ext');
const Handler = require('./handler');
const Headers = require('./headers');
const Security = require('./security');
const Streams = require('./streams');
const Validation = require('./validation');
const internals = {};
exports = module.exports = internals.Route = class {
constructor(route, server, options = {}) {
const core = server._core;
const realm = server.realm;
// Routing information
Config.apply('route', route, route.method, route.path);
const method = route.method.toLowerCase();
Hoek.assert(method !== 'head', 'Cannot set HEAD route:', route.path);
const path = realm.modifiers.route.prefix ? realm.modifiers.route.prefix + (route.path !== '/' ? route.path : '') : route.path;
Hoek.assert(path === '/' || path[path.length - 1] !== '/' || !core.settings.router.stripTrailingSlash, 'Path cannot end with a trailing slash when configured to strip:', route.method, route.path);
const vhost = realm.modifiers.route.vhost ?? route.vhost;
// Set identifying members (assert)
this.method = method;
this.path = path;
// Prepare configuration
let config = route.options ?? route.config ?? {};
if (typeof config === 'function') {
config = config.call(realm.settings.bind, server);
}
config = Config.enable(config); // Shallow clone
// Verify route level config (as opposed to the merged settings)
this._assert(method !== 'get' || !config.payload, 'Cannot set payload settings on HEAD or GET request');
this._assert(method !== 'get' || !config.validate?.payload, 'Cannot validate HEAD or GET request payload');
// Rules
this._assert(!route.rules || !config.rules, 'Route rules can only appear once'); // XOR
const rules = route.rules ?? config.rules;
const rulesConfig = internals.rules(rules, { method, path, vhost }, server);
delete config.rules;
// Handler
this._assert(route.handler || config.handler, 'Missing or undefined handler');
this._assert(!!route.handler ^ !!config.handler, 'Handler must only appear once'); // XOR
const handler = Config.apply('handler', route.handler ?? config.handler);
delete config.handler;
const handlerDefaults = Handler.defaults(method, handler, core);
// Apply settings in order: server <- handler <- realm <- route
const settings = internals.config([core.settings.routes, handlerDefaults, realm.settings, rulesConfig, config]);
this.settings = Config.apply('routeConfig', settings, method, path);
// Route members
this._core = core;
this.realm = realm;
this.settings.vhost = vhost;
this.settings.plugins = this.settings.plugins ?? {}; // Route-specific plugins settings, namespaced using plugin name
this.settings.app = this.settings.app ?? {}; // Route-specific application settings
// Path parsing
this._special = !!options.special;
this._analysis = this._core.router.analyze(this.path);
this.params = this._analysis.params;
this.fingerprint = this._analysis.fingerprint;
this.public = {
method: this.method,
path: this.path,
vhost,
realm,
settings: this.settings,
fingerprint: this.fingerprint,
auth: {
access: (request) => Auth.testAccess(request, this.public)
}
};
// Validation
this._setupValidation();
// Payload parsing
if (this.method === 'get') {
this.settings.payload = null;
}
else {
this.settings.payload.decoders = this._core.compression.decoders; // Reference the shared object to keep up to date
}
this._assert(!this.settings.validate.payload || this.settings.payload.parse, 'Route payload must be set to \'parse\' when payload validation enabled');
this._assert(!this.settings.validate.state || this.settings.state.parse, 'Route state must be set to \'parse\' when state validation enabled');
// Authentication configuration
this.settings.auth = this._special ? false : this._core.auth._setupRoute(this.settings.auth, path);
// Cache
if (this.method === 'get' &&
typeof this.settings.cache === 'object' &&
(this.settings.cache.expiresIn || this.settings.cache.expiresAt)) {
this.settings.cache._statuses = new Set(this.settings.cache.statuses);
this._cache = new Catbox.Policy({ expiresIn: this.settings.cache.expiresIn, expiresAt: this.settings.cache.expiresAt });
}
// CORS
this.settings.cors = Cors.route(this.settings.cors);
// Security
this.settings.security = Security.route(this.settings.security);
// Handler
this.settings.handler = Handler.configure(handler, this);
this._prerequisites = Handler.prerequisitesConfig(this.settings.pre);
// Route lifecycle
this._extensions = {
onPreResponse: Ext.combine(this, 'onPreResponse'),
onPostResponse: Ext.combine(this, 'onPostResponse')
};
if (this._special) {
this._cycle = [internals.drain, Handler.execute];
this.rebuild();
return;
}
this._extensions.onPreAuth = Ext.combine(this, 'onPreAuth');
this._extensions.onCredentials = Ext.combine(this, 'onCredentials');
this._extensions.onPostAuth = Ext.combine(this, 'onPostAuth');
this._extensions.onPreHandler = Ext.combine(this, 'onPreHandler');
this._extensions.onPostHandler = Ext.combine(this, 'onPostHandler');
this.rebuild();
}
_setupValidation() {
const validation = this.settings.validate;
if (this.method === 'get') {
validation.payload = null;
}
this._assert(!validation.params || this.params.length, 'Cannot set path parameters validations without path parameters');
for (const type of ['headers', 'params', 'query', 'payload', 'state']) {
validation[type] = Validation.compile(validation[type], this.settings.validate.validator, this.realm, this._core);
}
if (this.settings.response.schema !== undefined ||
this.settings.response.status) {
this.settings.response._validate = true;
const rule = this.settings.response.schema;
this.settings.response.status = this.settings.response.status ?? {};
const statuses = Object.keys(this.settings.response.status);
if (rule === true &&
!statuses.length) {
this.settings.response._validate = false;
}
else {
this.settings.response.schema = Validation.compile(rule, this.settings.validate.validator, this.realm, this._core);
for (const code of statuses) {
this.settings.response.status[code] = Validation.compile(this.settings.response.status[code], this.settings.validate.validator, this.realm, this._core);
}
}
}
}
rebuild(event) {
if (event) {
this._extensions[event.type].add(event);
}
if (this._special) {
this._postCycle = this._extensions.onPreResponse.nodes ? [this._extensions.onPreResponse] : [];
this._buildMarshalCycle();
return;
}
// Build lifecycle array
this._cycle = [];
// 'onRequest'
if (this.settings.state.parse) {
this._cycle.push(internals.state);
}
if (this._extensions.onPreAuth.nodes) {
this._cycle.push(this._extensions.onPreAuth);
}
if (this._core.auth._enabled(this, 'authenticate')) {
this._cycle.push(Auth.authenticate);
}
if (this.method !== 'get') {
this._cycle.push(internals.payload);
if (this._core.auth._enabled(this, 'payload')) {
this._cycle.push(Auth.payload);
}
}
if (this._core.auth._enabled(this, 'authenticate') &&
this._extensions.onCredentials.nodes) {
this._cycle.push(this._extensions.onCredentials);
}
if (this._core.auth._enabled(this, 'access')) {
this._cycle.push(Auth.access);
}
if (this._extensions.onPostAuth.nodes) {
this._cycle.push(this._extensions.onPostAuth);
}
if (this.settings.validate.headers) {
this._cycle.push(Validation.headers);
}
if (this.settings.validate.params) {
this._cycle.push(Validation.params);
}
if (this.settings.validate.query) {
this._cycle.push(Validation.query);
}
if (this.settings.validate.payload) {
this._cycle.push(Validation.payload);
}
if (this.settings.validate.state) {
this._cycle.push(Validation.state);
}
if (this._extensions.onPreHandler.nodes) {
this._cycle.push(this._extensions.onPreHandler);
}
this._cycle.push(Handler.execute);
if (this._extensions.onPostHandler.nodes) {
this._cycle.push(this._extensions.onPostHandler);
}
this._postCycle = [];
if (this.settings.response._validate &&
this.settings.response.sample !== 0) {
this._postCycle.push(Validation.response);
}
if (this._extensions.onPreResponse.nodes) {
this._postCycle.push(this._extensions.onPreResponse);
}
this._buildMarshalCycle();
// onPostResponse
}
_buildMarshalCycle() {
this._marshalCycle = [Headers.type];
if (this.settings.cors) {
this._marshalCycle.push(Cors.headers);
}
if (this.settings.security) {
this._marshalCycle.push(Security.headers);
}
this._marshalCycle.push(Headers.entity);
if (this.method === 'get' ||
this.method === '*') {
this._marshalCycle.push(Headers.unmodified);
}
this._marshalCycle.push(Headers.cache);
this._marshalCycle.push(Headers.state);
this._marshalCycle.push(Headers.content);
if (this._core.auth._enabled(this, 'response')) {
this._marshalCycle.push(Auth.response); // Must be last in case requires access to headers
}
}
_assert(condition, message) {
if (condition) {
return;
}
if (this.method[0] !== '_') {
message = `${message}: ${this.method.toUpperCase()} ${this.path}`;
}
throw new Assert.AssertionError({
message,
actual: false,
expected: true,
operator: '==',
stackStartFunction: this._assert
});
}
};
internals.state = async function (request) {
request.state = {};
const req = request.raw.req;
const cookies = req.headers.cookie;
if (!cookies) {
return;
}
try {
var result = await request._core.states.parse(cookies);
}
catch (err) {
Bounce.rethrow(err, 'system');
var parseError = err;
}
const { states, failed = [] } = result ?? parseError;
request.state = states ?? {};
// Clear cookies
for (const item of failed) {
if (item.settings.clearInvalid) {
request._clearState(item.name);
}
}
if (!parseError) {
return;
}
parseError.header = cookies;
return request._core.toolkit.failAction(request, request.route.settings.state.failAction, parseError, { tags: ['state', 'error'] });
};
internals.payload = async function (request) {
if (request.method === 'get' ||
request.method === 'head') { // When route.method is '*'
return;
}
if (request.payload !== undefined) {
return internals.drain(request);
}
if (request._expectContinue) {
request._expectContinue = false;
request.raw.res.writeContinue();
}
try {
const { payload, mime } = await Subtext.parse(request.raw.req, request._tap(), request.route.settings.payload);
request._isPayloadPending = !!payload?._readableState;
request.mime = mime;
request.payload = payload;
}
catch (err) {
Bounce.rethrow(err, 'system');
await internals.drain(request);
request.mime = err.mime;
request.payload = null;
return request._core.toolkit.failAction(request, request.route.settings.payload.failAction, err, { tags: ['payload', 'error'] });
}
};
internals.drain = async function (request) {
// Flush out any pending request payload not consumed due to errors
if (request._expectContinue) {
request._isPayloadPending = false; // If we don't continue, client should not send a payload
request._expectContinue = false;
}
if (request._isPayloadPending) {
await Streams.drain(request.raw.req);
request._isPayloadPending = false;
}
};
internals.config = function (chain) {
if (!chain.length) {
return {};
}
let config = chain[0];
for (const item of chain) {
config = Hoek.applyToDefaults(config, item, { shallow: ['bind', 'validate.headers', 'validate.payload', 'validate.params', 'validate.query', 'validate.state'] });
}
return config;
};
internals.rules = function (rules, info, server) {
const configs = [];
let realm = server.realm;
while (realm) {
if (realm._rules) {
const source = !realm._rules.settings.validate ? rules : Validate.attempt(rules, realm._rules.settings.validate.schema, realm._rules.settings.validate.options);
const config = realm._rules.processor(source, info);
if (config) {
configs.unshift(config);
}
}
realm = realm.parent;
}
return internals.config(configs);
};

86
node_modules/@hapi/hapi/lib/security.js generated vendored Executable file
View File

@@ -0,0 +1,86 @@
'use strict';
const internals = {};
exports.route = function (settings) {
if (!settings) {
return null;
}
const security = settings;
if (security.hsts) {
if (security.hsts === true) {
security._hsts = 'max-age=15768000';
}
else if (typeof security.hsts === 'number') {
security._hsts = 'max-age=' + security.hsts;
}
else {
security._hsts = 'max-age=' + (security.hsts.maxAge ?? 15768000);
if (security.hsts.includeSubdomains || security.hsts.includeSubDomains) {
security._hsts = security._hsts + '; includeSubDomains';
}
if (security.hsts.preload) {
security._hsts = security._hsts + '; preload';
}
}
}
if (security.xframe) {
if (security.xframe === true) {
security._xframe = 'DENY';
}
else if (typeof security.xframe === 'string') {
security._xframe = security.xframe.toUpperCase();
}
else if (security.xframe.rule === 'allow-from') {
if (!security.xframe.source) {
security._xframe = 'SAMEORIGIN';
}
else {
security._xframe = 'ALLOW-FROM ' + security.xframe.source;
}
}
else {
security._xframe = security.xframe.rule.toUpperCase();
}
}
return security;
};
exports.headers = function (response) {
const security = response.request.route.settings.security;
if (security._hsts) {
response._header('strict-transport-security', security._hsts, { override: false });
}
if (security._xframe) {
response._header('x-frame-options', security._xframe, { override: false });
}
if (security.xss === 'enabled') {
response._header('x-xss-protection', '1; mode=block', { override: false });
}
else if (security.xss === 'disabled') {
response._header('x-xss-protection', '0', { override: false });
}
if (security.noOpen) {
response._header('x-download-options', 'noopen', { override: false });
}
if (security.noSniff) {
response._header('x-content-type-options', 'nosniff', { override: false });
}
if (security.referrer !== false) {
response._header('referrer-policy', security.referrer, { override: false });
}
};

604
node_modules/@hapi/hapi/lib/server.js generated vendored Executable file
View File

@@ -0,0 +1,604 @@
'use strict';
const Hoek = require('@hapi/hoek');
const Shot = require('@hapi/shot');
const Teamwork = require('@hapi/teamwork');
const Config = require('./config');
const Core = require('./core');
const Cors = require('./cors');
const Ext = require('./ext');
const Package = require('../package.json');
const Route = require('./route');
const Toolkit = require('./toolkit');
const Validation = require('./validation');
const internals = {};
exports = module.exports = function (options) {
const core = new Core(options);
return new internals.Server(core);
};
internals.Server = class {
constructor(core, name, parent) {
this._core = core;
// Public interface
this.app = core.app;
this.auth = core.auth.public(this);
this.decorations = core.decorations.public;
this.cache = internals.cache(this);
this.events = core.events;
this.info = core.info;
this.listener = core.listener;
this.load = core.heavy.load;
this.methods = core.methods.methods;
this.mime = core.mime;
this.plugins = core.plugins;
this.registrations = core.registrations;
this.settings = core.settings;
this.states = core.states;
this.type = core.type;
this.version = Package.version;
this.realm = {
_extensions: {
onPreAuth: new Ext('onPreAuth', core),
onCredentials: new Ext('onCredentials', core),
onPostAuth: new Ext('onPostAuth', core),
onPreHandler: new Ext('onPreHandler', core),
onPostHandler: new Ext('onPostHandler', core),
onPreResponse: new Ext('onPreResponse', core),
onPostResponse: new Ext('onPostResponse', core)
},
modifiers: {
route: {}
},
parent: parent ? parent.realm : null,
plugin: name,
pluginOptions: {},
plugins: {},
_rules: null,
settings: {
bind: undefined,
files: {
relativeTo: undefined
}
},
validator: null
};
// Decorations
for (const [property, method] of core.decorations.server.entries()) {
this[property] = method;
}
core.registerServer(this);
}
_clone(name) {
return new internals.Server(this._core, name, this);
}
bind(context) {
Hoek.assert(typeof context === 'object', 'bind must be an object');
this.realm.settings.bind = context;
}
control(server) {
Hoek.assert(server instanceof internals.Server, 'Can only control Server objects');
this._core.controlled = this._core.controlled ?? [];
this._core.controlled.push(server);
}
decoder(encoding, decoder) {
return this._core.compression.addDecoder(encoding, decoder);
}
decorate(type, property, method, options = {}) {
Hoek.assert(this._core.decorations.public[type], 'Unknown decoration type:', type);
Hoek.assert(property, 'Missing decoration property name');
Hoek.assert(typeof property === 'string' || typeof property === 'symbol', 'Decoration property must be a string or a symbol');
const propertyName = property.toString();
Hoek.assert(propertyName[0] !== '_', 'Property name cannot begin with an underscore:', propertyName);
const existing = this._core.decorations[type].get(property);
if (options.extend) {
Hoek.assert(type !== 'handler', 'Cannot extend handler decoration:', propertyName);
Hoek.assert(existing, `Cannot extend missing ${type} decoration: ${propertyName}`);
Hoek.assert(typeof method === 'function', `Extended ${type} decoration method must be a function: ${propertyName}`);
method = method(existing);
}
else {
Hoek.assert(existing === undefined, `${type[0].toUpperCase() + type.slice(1)} decoration already defined: ${propertyName}`);
}
if (type === 'handler') {
// Handler
Hoek.assert(typeof method === 'function', 'Handler must be a function:', propertyName);
Hoek.assert(!method.defaults || typeof method.defaults === 'object' || typeof method.defaults === 'function', 'Handler defaults property must be an object or function');
Hoek.assert(!options.extend, 'Cannot extend handler decoration:', propertyName);
}
else if (type === 'request') {
// Request
Hoek.assert(!this._core.Request.reserved.includes(property), 'Cannot override the built-in request interface decoration:', propertyName);
if (options.apply) {
this._core.decorations.requestApply = this._core.decorations.requestApply ?? new Map();
this._core.decorations.requestApply.set(property, method);
}
else {
this._core.Request.prototype[property] = method;
}
}
else if (type === 'response') {
// Response
Hoek.assert(!this._core.Response.reserved.includes(property), 'Cannot override the built-in response interface decoration:', propertyName);
this._core.Response.prototype[property] = method;
}
else if (type === 'toolkit') {
// Toolkit
Hoek.assert(!Toolkit.reserved.includes(property), 'Cannot override the built-in toolkit decoration:', propertyName);
this._core.toolkit.decorate(property, method);
}
else {
// Server
if (typeof property === 'string') {
Hoek.assert(!Object.getOwnPropertyNames(internals.Server.prototype).includes(property), 'Cannot override the built-in server interface method:', propertyName);
}
else {
Hoek.assert(!Object.getOwnPropertySymbols(internals.Server.prototype).includes(property), 'Cannot override the built-in server interface method:', propertyName);
}
this._core.instances.forEach((server) => {
server[property] = method;
});
}
this._core.decorations[type].set(property, method);
this._core.decorations.public[type].push(property);
}
dependency(dependencies, after) {
Hoek.assert(this.realm.plugin, 'Cannot call dependency() outside of a plugin');
Hoek.assert(!after || typeof after === 'function', 'Invalid after method');
// Normalize to { plugin: version }
if (typeof dependencies === 'string') {
dependencies = { [dependencies]: '*' };
}
else if (Array.isArray(dependencies)) {
const map = {};
for (const dependency of dependencies) {
map[dependency] = '*';
}
dependencies = map;
}
this._core.dependencies.push({ plugin: this.realm.plugin, deps: dependencies });
if (after) {
this.ext('onPreStart', after, { after: Object.keys(dependencies) });
}
}
encoder(encoding, encoder) {
return this._core.compression.addEncoder(encoding, encoder);
}
event(event) {
this._core.events.registerEvent(event);
}
expose(key, value, options = {}) {
Hoek.assert(this.realm.plugin, 'Cannot call expose() outside of a plugin');
let plugin = this.realm.plugin;
if (plugin[0] === '@' &&
options.scope !== true) {
plugin = plugin.replace(/^@([^/]+)\//, ($0, $1) => {
return !options.scope ? '' : `${$1}__`;
});
}
this._core.plugins[plugin] = this._core.plugins[plugin] ?? {};
if (typeof key === 'string') {
this._core.plugins[plugin][key] = value;
}
else {
Hoek.merge(this._core.plugins[plugin], key);
}
}
ext(events, method, options) { // (event, method, options) -OR- (events)
let promise;
if (typeof events === 'string') {
if (!method) {
const team = new Teamwork.Team();
method = (request, h) => {
team.attend(request);
return h.continue;
};
promise = team.work;
}
events = { type: events, method, options };
}
events = Config.apply('exts', events);
for (const event of events) {
this._ext(event);
}
return promise;
}
_ext(event) {
event = Object.assign({}, event); // Shallow cloned
event.realm = this.realm;
const type = event.type;
if (!this._core.extensions.server[type]) {
// Realm route extensions
if (event.options.sandbox === 'plugin') {
Hoek.assert(this.realm._extensions[type], 'Unknown event type', type);
return this.realm._extensions[type].add(event);
}
// Connection route extensions
Hoek.assert(this._core.extensions.route[type], 'Unknown event type', type);
return this._core.extensions.route[type].add(event);
}
// Server extensions
Hoek.assert(!event.options.sandbox, 'Cannot specify sandbox option for server extension');
Hoek.assert(type !== 'onPreStart' || this._core.phase === 'stopped', 'Cannot add onPreStart (after) extension after the server was initialized');
event.server = this;
this._core.extensions.server[type].add(event);
}
async inject(options) {
let settings = options;
if (typeof settings === 'string') {
settings = { url: settings };
}
if (!settings.authority ||
settings.auth ||
settings.app ||
settings.plugins ||
settings.allowInternals !== undefined) { // Can be false
settings = Object.assign({}, settings); // options can be reused (shallow cloned)
delete settings.auth;
delete settings.app;
delete settings.plugins;
delete settings.allowInternals;
settings.authority = settings.authority ?? this._core.info.host + ':' + this._core.info.port;
}
Hoek.assert(!options.credentials, 'options.credentials no longer supported (use options.auth)');
if (options.auth) {
Hoek.assert(typeof options.auth === 'object', 'options.auth must be an object');
Hoek.assert(options.auth.credentials, 'options.auth.credentials is missing');
Hoek.assert(options.auth.strategy, 'options.auth.strategy is missing');
}
const needle = this._core._dispatch({
auth: options.auth,
allowInternals: options.allowInternals,
app: options.app,
plugins: options.plugins,
isInjected: true
});
const res = await Shot.inject(needle, settings);
const custom = res.raw.res[Config.symbol];
if (custom) {
delete res.raw.res[Config.symbol];
res.request = custom.request;
if (custom.error) {
throw custom.error;
}
if (custom.result !== undefined) {
res.result = custom.result;
}
}
if (res.result === undefined) {
res.result = res.payload;
}
return res;
}
log(tags, data) {
return this._core.log(tags, data);
}
lookup(id) {
Hoek.assert(id && typeof id === 'string', 'Invalid route id:', id);
const record = this._core.router.ids.get(id);
if (!record) {
return null;
}
return record.route.public;
}
match(method, path, host) {
Hoek.assert(method && typeof method === 'string', 'Invalid method:', method);
Hoek.assert(path && typeof path === 'string' && path[0] === '/', 'Invalid path:', path);
Hoek.assert(!host || typeof host === 'string', 'Invalid host:', host);
const match = this._core.router.route(method.toLowerCase(), path, host);
Hoek.assert(match !== this._core.router.specials.badRequest, 'Invalid path:', path);
if (match === this._core.router.specials.notFound) {
return null;
}
return match.route.public;
}
method(name, method, options = {}) {
return this._core.methods.add(name, method, options, this.realm);
}
path(relativeTo) {
Hoek.assert(relativeTo && typeof relativeTo === 'string', 'relativeTo must be a non-empty string');
this.realm.settings.files.relativeTo = relativeTo;
}
async register(plugins, options = {}) {
if (this.realm.modifiers.route.prefix ||
this.realm.modifiers.route.vhost) {
options = Hoek.clone(options);
options.routes = options.routes ?? {};
options.routes.prefix = (this.realm.modifiers.route.prefix ?? '') + (options.routes.prefix ?? '') || undefined;
options.routes.vhost = this.realm.modifiers.route.vhost ?? options.routes.vhost;
}
options = Config.apply('register', options);
++this._core.registring;
try {
const items = [].concat(plugins);
for (let item of items) {
/*
{ register, ...attributes }
{ plugin: { register, ...attributes }, options, once, routes }
{ plugin: { plugin: { register, ...attributes } }, options, once, routes } // Required module
*/
if (!item.plugin) {
item = {
plugin: item
};
}
else if (!item.plugin.register) {
item = {
options: item.options,
once: item.once,
routes: item.routes,
plugin: item.plugin.plugin
};
}
else if (typeof item === 'function') {
item = Object.assign({}, item); // Shallow cloned
}
item = Config.apply('plugin', item);
const name = item.plugin.name ?? item.plugin.pkg.name;
const clone = this._clone(name);
clone.realm.modifiers.route.prefix = item.routes.prefix ?? options.routes.prefix;
clone.realm.modifiers.route.vhost = item.routes.vhost ?? options.routes.vhost;
clone.realm.pluginOptions = item.options ?? {};
// Validate requirements
const requirements = item.plugin.requirements;
Hoek.assert(!requirements.node || Config.versionMatch(process.version, requirements.node), 'Plugin', name, 'requires node version', requirements.node, 'but found', process.version);
Hoek.assert(!requirements.hapi || Config.versionMatch(this.version, requirements.hapi), 'Plugin', name, 'requires hapi version', requirements.hapi, 'but found', this.version);
// Protect against multiple registrations
if (this._core.registrations[name]) {
if (item.plugin.once ||
item.once ||
options.once) {
continue;
}
Hoek.assert(item.plugin.multiple, 'Plugin', name, 'already registered');
}
else {
this._core.registrations[name] = {
version: item.plugin.version ?? item.plugin.pkg.version,
name,
options: item.options
};
}
if (item.plugin.dependencies) {
clone.dependency(item.plugin.dependencies);
}
// Register
await item.plugin.register(clone, item.options ?? {});
}
}
finally {
--this._core.registring;
}
return this;
}
route(options) {
Hoek.assert(typeof options === 'object', 'Invalid route options');
options = [].concat(options);
for (const config of options) {
if (Array.isArray(config.method)) {
for (const method of config.method) {
const settings = Object.assign({}, config); // Shallow cloned
settings.method = method;
this._addRoute(settings, this);
}
}
else {
this._addRoute(config, this);
}
}
}
_addRoute(config, server) {
const route = new Route(config, server); // Do no use config beyond this point, use route members
const vhosts = [].concat(route.settings.vhost ?? '*');
for (const vhost of vhosts) {
const record = this._core.router.add({ method: route.method, path: route.path, vhost, analysis: route._analysis, id: route.settings.id }, route);
route.fingerprint = record.fingerprint;
route.params = record.params;
}
this.events.emit('route', route.public);
Cors.options(route.public, server);
}
rules(processor, options = {}) {
Hoek.assert(!this.realm._rules, 'Server realm rules already defined');
const settings = Config.apply('rules', options);
if (settings.validate) {
const schema = settings.validate.schema;
settings.validate.schema = Validation.compile(schema, null, this.realm, this._core);
}
this.realm._rules = { processor, settings };
}
state(name, options) {
this.states.add(name, options);
}
table(host) {
return this._core.router.table(host);
}
validator(validator) {
Hoek.assert(!this.realm.validator, 'Validator already set');
this.realm.validator = Validation.validator(validator);
}
start() {
return this._core._start();
}
initialize() {
return this._core._initialize();
}
stop(options) {
return this._core._stop(options);
}
};
internals.cache = (plugin) => {
const policy = function (options, _segment) {
return this._core._cachePolicy(options, _segment, plugin.realm);
};
policy.provision = async (opts) => {
const clients = plugin._core._createCache(opts);
// Start cache
if (['initialized', 'starting', 'started'].includes(plugin._core.phase)) {
await Promise.all(clients.map((client) => client.start()));
}
};
return policy;
};

62
node_modules/@hapi/hapi/lib/streams.js generated vendored Executable file
View File

@@ -0,0 +1,62 @@
'use strict';
const Stream = require('stream');
const Boom = require('@hapi/boom');
const Teamwork = require('@hapi/teamwork');
const internals = {
team: Symbol('team')
};
exports.isStream = function (stream) {
const isReadableStream = stream instanceof Stream.Readable;
if (!isReadableStream &&
typeof stream?.pipe === 'function') {
throw Boom.badImplementation('Cannot reply with a stream-like object that is not an instance of Stream.Readable');
}
if (!isReadableStream) {
return false;
}
if (stream.readableObjectMode) {
throw Boom.badImplementation('Cannot reply with stream in object mode');
}
return true;
};
exports.drain = function (stream) {
const team = new Teamwork.Team();
stream[internals.team] = team;
stream.on('readable', internals.read);
stream.on('error', internals.end);
stream.on('end', internals.end);
stream.on('close', internals.end);
return team.work;
};
internals.read = function () {
while (this.read()) { }
};
internals.end = function () {
this.removeListener('readable', internals.read);
this.removeListener('error', internals.end);
this.removeListener('end', internals.end);
this.removeListener('close', internals.end);
this[internals.team].attend();
};

258
node_modules/@hapi/hapi/lib/toolkit.js generated vendored Executable file
View File

@@ -0,0 +1,258 @@
'use strict';
const Boom = require('@hapi/boom');
const Bounce = require('@hapi/bounce');
const Hoek = require('@hapi/hoek');
const internals = {};
exports.reserved = [
'abandon',
'authenticated',
'close',
'context',
'continue',
'entity',
'redirect',
'realm',
'request',
'response',
'state',
'unauthenticated',
'unstate'
];
exports.symbols = {
abandon: Symbol('abandon'),
close: Symbol('close'),
continue: Symbol('continue')
};
exports.Manager = class {
constructor() {
this._toolkit = internals.toolkit();
}
async execute(method, request, options) {
const h = new this._toolkit(request, options);
const bind = options.bind ?? null;
try {
let operation;
if (bind) {
operation = method.call(bind, request, h);
}
else if (options.args) {
operation = method(request, h, ...options.args);
}
else {
operation = method(request, h);
}
var response = await exports.timed(operation, options);
}
catch (err) {
if (Bounce.isSystem(err)) {
response = Boom.badImplementation(err);
}
else if (!Bounce.isError(err)) {
response = Boom.badImplementation('Cannot throw non-error object', err);
}
else {
response = Boom.boomify(err);
}
}
// Process response
if (options.ignoreResponse) {
return response;
}
if (response === undefined) {
response = Boom.badImplementation(`${method.name} method did not return a value, a promise, or throw an error`);
}
if (options.continue &&
response === exports.symbols.continue) {
if (options.continue === 'undefined') {
return;
}
// 'null'
response = null;
}
if (options.auth &&
response instanceof internals.Auth) {
return response;
}
if (typeof response !== 'symbol') {
response = request._core.Response.wrap(response, request);
if (!response.isBoom && response._state === 'init') {
await response._prepare();
}
}
return response;
}
decorate(name, method) {
this._toolkit.prototype[name] = method;
}
async failAction(request, failAction, err, options) {
const retain = options.retain ? err : undefined;
if (failAction === 'ignore') {
return retain;
}
if (failAction === 'log') {
request._log(options.tags, err);
return retain;
}
if (failAction === 'error') {
throw err;
}
return await this.execute(failAction, request, { realm: request.route.realm, args: [options.details ?? err] });
}
};
exports.timed = async function (method, options) {
if (!options.timeout) {
return method;
}
const timer = new Promise((resolve, reject) => {
const handler = () => {
reject(Boom.internal(`${options.name} timed out`));
};
setTimeout(handler, options.timeout);
});
return await Promise.race([timer, method]);
};
/*
const handler = function (request, h) {
result / h.response(result) -> result // Not allowed before handler
h.response(result).takeover() -> result (respond)
h.continue -> null // Defaults to null only in handler and pre, not allowed in auth
throw error / h.response(error) -> error (respond) // failAction override in pre
<undefined> -> badImplementation (respond)
// Auth only (scheme.payload and scheme.response use the same interface as pre-handler extension methods)
h.unauthenticated(error, data) -> error (respond) + data
h.authenticated(data ) -> (continue) + data
};
*/
internals.toolkit = function () {
const Toolkit = class {
constructor(request, options) {
this.context = options.bind;
this.realm = options.realm;
this.request = request;
this._auth = options.auth;
}
response(result) {
Hoek.assert(!result || typeof result !== 'object' || typeof result.then !== 'function', 'Cannot wrap a promise');
Hoek.assert(result instanceof Error === false, 'Cannot wrap an error');
Hoek.assert(typeof result !== 'symbol', 'Cannot wrap a symbol');
return this.request._core.Response.wrap(result, this.request);
}
redirect(location) {
return this.response('').redirect(location);
}
entity(options) {
Hoek.assert(options, 'Entity method missing required options');
Hoek.assert(options.etag || options.modified, 'Entity methods missing required options key');
this.request._entity = options;
const entity = this.request._core.Response.entity(options.etag, options);
if (this.request._core.Response.unmodified(this.request, entity)) {
return this.response().code(304).takeover();
}
}
state(name, value, options) {
this.request._setState(name, value, options);
}
unstate(name, options) {
this.request._clearState(name, options);
}
authenticated(data) {
Hoek.assert(this._auth, 'Method not supported outside of authentication');
Hoek.assert(data?.credentials, 'Authentication data missing credentials information');
return new internals.Auth(null, data);
}
unauthenticated(error, data) {
Hoek.assert(this._auth, 'Method not supported outside of authentication');
Hoek.assert(!data || data.credentials, 'Authentication data missing credentials information');
return new internals.Auth(error, data);
}
};
Toolkit.prototype.abandon = exports.symbols.abandon;
Toolkit.prototype.close = exports.symbols.close;
Toolkit.prototype.continue = exports.symbols.continue;
return Toolkit;
};
internals.Auth = class {
constructor(error, data) {
this.isAuth = true;
this.error = error;
this.data = data;
}
};

388
node_modules/@hapi/hapi/lib/transmit.js generated vendored Executable file
View File

@@ -0,0 +1,388 @@
'use strict';
const Http = require('http');
const Ammo = require('@hapi/ammo');
const Boom = require('@hapi/boom');
const Bounce = require('@hapi/bounce');
const Hoek = require('@hapi/hoek');
const Teamwork = require('@hapi/teamwork');
const Config = require('./config');
const internals = {};
exports.send = async function (request) {
const response = request.response;
try {
if (response.isBoom) {
await internals.fail(request, response);
return;
}
await internals.marshal(response);
await internals.transmit(response);
}
catch (err) {
Bounce.rethrow(err, 'system');
request._setResponse(err);
return internals.fail(request, err);
}
};
internals.marshal = async function (response) {
for (const func of response.request._route._marshalCycle) {
await func(response);
}
};
internals.fail = async function (request, boom) {
const response = internals.error(request, boom);
request.response = response; // Not using request._setResponse() to avoid double log
try {
await internals.marshal(response);
}
catch (err) {
Bounce.rethrow(err, 'system');
// Failed to marshal an error - replace with minimal representation of original error
const minimal = {
statusCode: response.statusCode,
error: Http.STATUS_CODES[response.statusCode],
message: boom.message
};
response._payload = new request._core.Response.Payload(JSON.stringify(minimal), {});
}
return internals.transmit(response);
};
internals.error = function (request, boom) {
const error = boom.output;
const response = new request._core.Response(error.payload, request, { error: boom });
response.code(error.statusCode);
response.headers = Hoek.clone(error.headers); // Prevent source from being modified
return response;
};
internals.transmit = function (response) {
const request = response.request;
const length = internals.length(response);
// Pipes
const encoding = request._core.compression.encoding(response, length);
const ranger = encoding ? null : internals.range(response, length);
const compressor = internals.encoding(response, encoding);
// Connection: close
const isInjection = request.isInjected;
if (!(isInjection || request._core.started) ||
request._isPayloadPending && !request.raw.req._readableState.ended) {
response._header('connection', 'close');
}
// Write headers
internals.writeHead(response);
// Injection
if (isInjection) {
request.raw.res[Config.symbol] = { request };
if (response.variety === 'plain') {
request.raw.res[Config.symbol].result = response._isPayloadSupported() ? response.source : null;
}
}
// Finalize response stream
const stream = internals.chain([response._payload, response._tap(), compressor, ranger]);
return internals.pipe(request, stream);
};
internals.length = function (response) {
const request = response.request;
const header = response.headers['content-length'];
if (header === undefined) {
return null;
}
let length = header;
if (typeof length === 'string') {
length = parseInt(header, 10);
if (!isFinite(length)) {
delete response.headers['content-length'];
return null;
}
}
// Empty response
if (length === 0 &&
!response._statusCode &&
response.statusCode === 200 &&
request.route.settings.response.emptyStatusCode !== 200) {
response.code(204);
delete response.headers['content-length'];
}
return length;
};
internals.range = function (response, length) {
const request = response.request;
if (!length ||
!request.route.settings.response.ranges ||
request.method !== 'get' ||
response.statusCode !== 200) {
return null;
}
response._header('accept-ranges', 'bytes');
if (!request.headers.range) {
return null;
}
// Check If-Range
if (request.headers['if-range'] &&
request.headers['if-range'] !== response.headers.etag) { // Ignoring last-modified date (weak)
return null;
}
// Parse header
const ranges = Ammo.header(request.headers.range, length);
if (!ranges) {
const error = Boom.rangeNotSatisfiable();
error.output.headers['content-range'] = 'bytes */' + length;
throw error;
}
// Prepare transform
if (ranges.length !== 1) { // Ignore requests for multiple ranges
return null;
}
const range = ranges[0];
response.code(206);
response.bytes(range.to - range.from + 1);
response._header('content-range', 'bytes ' + range.from + '-' + range.to + '/' + length);
return new Ammo.Clip(range);
};
internals.encoding = function (response, encoding) {
const request = response.request;
const header = response.headers['content-encoding'] || encoding;
if (header &&
response.headers.etag &&
response.settings.varyEtag) {
response.headers.etag = response.headers.etag.slice(0, -1) + '-' + header + '"';
}
if (!encoding ||
response.statusCode === 206 ||
!response._isPayloadSupported()) {
return null;
}
delete response.headers['content-length'];
response._header('content-encoding', encoding);
const compressor = request._core.compression.encoder(request, encoding);
if (response.variety === 'stream' &&
typeof response._payload.setCompressor === 'function') {
response._payload.setCompressor(compressor);
}
return compressor;
};
internals.pipe = function (request, stream) {
const team = new Teamwork.Team();
// Write payload
const env = { stream, request, team };
if (request._closed) {
// The request has already been aborted - no need to wait or attempt to write.
internals.end(env, 'aborted');
return team.work;
}
const aborted = internals.end.bind(null, env, 'aborted');
const close = internals.end.bind(null, env, 'close');
const end = internals.end.bind(null, env, null);
request.raw.req.on('aborted', aborted);
request.raw.res.on('close', close);
request.raw.res.on('error', end);
request.raw.res.on('finish', end);
if (stream.writeToStream) {
stream.writeToStream(request.raw.res);
}
else {
stream.on('error', end);
stream.on('close', aborted);
stream.pipe(request.raw.res);
}
return team.work;
};
internals.end = function (env, event, err) {
const { request, stream, team } = env;
if (!team) { // Used instead of cleaning up emitter listeners
return;
}
env.team = null;
if (request.raw.res.writableEnded) {
request.info.responded = Date.now();
team.attend();
return;
}
if (err) {
request.raw.res.destroy();
request._core.Response.drain(stream);
}
// Update reported response to reflect the error condition
const origResponse = request.response;
const error = err ? Boom.boomify(err) :
new Boom.Boom(`Request ${event}`, { statusCode: request.route.settings.response.disconnectStatusCode, data: origResponse });
request._setResponse(error);
// Make inject throw a disconnect error
if (request.raw.res[Config.symbol]) {
request.raw.res[Config.symbol].error = event ? error :
new Boom.Boom(`Response error`, { statusCode: request.route.settings.response.disconnectStatusCode, data: origResponse });
}
if (event) {
request._log(['response', 'error', event]);
}
else {
request._log(['response', 'error'], err);
}
request.raw.res.end(); // Triggers injection promise resolve
team.attend();
};
internals.writeHead = function (response) {
const res = response.request.raw.res;
const headers = Object.keys(response.headers);
let i = 0;
try {
for (; i < headers.length; ++i) {
const header = headers[i];
const value = response.headers[header];
if (value !== undefined) {
res.setHeader(header, value);
}
}
}
catch (err) {
for (--i; i >= 0; --i) {
res.removeHeader(headers[i]); // Undo headers
}
throw Boom.boomify(err);
}
if (response.settings.message) {
res.statusMessage = response.settings.message;
}
try {
res.writeHead(response.statusCode);
}
catch (err) {
throw Boom.boomify(err);
}
};
internals.chain = function (sources) {
let from = sources[0];
for (let i = 1; i < sources.length; ++i) {
const to = sources[i];
if (to) {
from.on('close', internals.destroyPipe.bind(from, to));
from.on('error', internals.errorPipe.bind(from, to));
from = from.pipe(to);
}
}
return from;
};
internals.destroyPipe = function (to) {
if (!this.readableEnded && !this.errored) {
to.destroy();
}
};
internals.errorPipe = function (to, err) {
to.emit('error', err);
};

21
node_modules/@hapi/hapi/lib/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,21 @@
// Definitions adapted from DefinitelyTyped, originally created by:
// Rafael Souza Fijalkowski <https://github.com/rafaelsouzaf>
// Justin Simms <https://github.com/jhsimms>
// Simon Schick <https://github.com/SimonSchick>
// Rodrigo Saboya <https://github.com/saboya>
// Silas Rech <https://github.com/lenovouser>
export * from './plugin';
export * from './response';
export * from './request';
export * from './route';
export * from './server';
export * from './utils';
// Kept for backwards compatibility only (remove in next major)
export namespace Utils {
interface Dictionary<T> {
[key: string]: T;
}
}

266
node_modules/@hapi/hapi/lib/types/plugin.d.ts generated vendored Normal file
View File

@@ -0,0 +1,266 @@
import { RequestRoute } from './request';
import { RouteOptions } from './route';
import { Server } from './server';
import { Lifecycle } from './utils';
/**
* one of
* a single plugin name string.
* an array of plugin name strings.
* an object where each key is a plugin name and each matching value is a
* {@link https://www.npmjs.com/package/semver version range string} which must match the registered
* plugin version.
*/
export type Dependencies = string | string[] | Record<string, string>;
/**
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverregistrations)
*/
export interface PluginsListRegistered {
}
/**
* An object of the currently registered plugins where each key is a registered plugin name and the value is an
* object containing:
* * version - the plugin version.
* * name - the plugin name.
* * options - (optional) options passed to the plugin during registration.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverregistrations)
*/
export interface PluginRegistered {
/**
* the plugin version.
*/
version: string;
/**
* the plugin name.
*/
name: string;
/**
* options used to register the plugin.
*/
options: object;
}
export interface PluginsStates {
}
export interface PluginSpecificConfiguration {
}
export interface PluginNameVersion {
/**
* (required) the plugin name string. The name is used as a unique key. Published plugins (e.g. published in the npm
* registry) should use the same name as the name field in their 'package.json' file. Names must be
* unique within each application.
*/
name: string;
/**
* optional plugin version. The version is only used informatively to enable other plugins to find out the versions loaded. The version should be the same as the one specified in the plugin's
* 'package.json' file.
*/
version?: string | undefined;
}
export interface PluginPackage {
/**
* Alternatively, the name and version can be included via the pkg property containing the 'package.json' file for the module which already has the name and version included
*/
pkg: PluginNameVersion;
}
export interface PluginBase<T, D> {
/**
* (required) the registration function with the signature async function(server, options) where:
* * server - the server object with a plugin-specific server.realm.
* * options - any options passed to the plugin during registration via server.register().
*/
register: (server: Server, options: T) => void | Promise<void>;
/** (optional) if true, allows the plugin to be registered multiple times with the same server. Defaults to false. */
multiple?: boolean | undefined;
/** (optional) a string or an array of strings indicating a plugin dependency. Same as setting dependencies via server.dependency(). */
dependencies?: Dependencies | undefined;
/**
* Allows defining semver requirements for node and hapi.
* @default Allows all.
*/
requirements?: {
node?: string | undefined;
hapi?: string | undefined;
} | undefined;
/** once - (optional) if true, will only register the plugin once per server. If set, overrides the once option passed to server.register(). Defaults to no override. */
once?: boolean | undefined;
/**
* We need to use D within the PluginBase type to be able to infer it later on,
* but this property has no concrete existence in the code.
*
* See https://github.com/Microsoft/TypeScript/wiki/FAQ#why-doesnt-type-inference-work-on-this-interface-interface-foot-- for details.
*/
___$type_of_plugin_decorations$___?: D;
}
/**
* A plugin that is registered by name and version.
*/
export interface NamedPlugin<T, D = void> extends PluginBase<T, D>, PluginNameVersion {}
/**
* A plugin that is registered by its package.json file.
*/
export interface PackagedPlugin<T, D = void> extends PluginBase<T, D>, PluginPackage {}
/**
* Plugins provide a way to organize application code by splitting the server logic into smaller components. Each
* plugin can manipulate the server through the standard server interface, but with the added ability to sandbox
* certain properties. For example, setting a file path in one plugin doesn't affect the file path set
* in another plugin.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#plugins)
*
* The type T is the type of the plugin options.
*/
export type Plugin<T, D = void> = NamedPlugin<T, D> | PackagedPlugin<T, D>;
/**
* The realm object contains sandboxed server settings specific to each plugin or authentication strategy. When registering a plugin or an authentication scheme, a server object reference is provided
* with a new server.realm container specific to that registration. It allows each plugin to maintain its own settings without leaking and affecting other plugins. For example, a plugin can set a
* default file path for local resources without breaking other plugins' configured paths. When calling server.bind(), the active realm's settings.bind property is set which is then used by routes
* and extensions added at the same level (server root or plugin).
*
* https://github.com/hapijs/hapi/blob/master/API.md#server.realm
*/
export interface ServerRealm {
/** when the server object is provided as an argument to the plugin register() method, modifiers provides the registration preferences passed the server.register() method and includes: */
modifiers: {
/** routes preferences: */
route: {
/**
* the route path prefix used by any calls to server.route() from the server. Note that if a prefix is used and the route path is set to '/', the resulting path will not include
* the trailing slash.
*/
prefix: string;
/** the route virtual host settings used by any calls to server.route() from the server. */
vhost: string;
}
};
/** the realm of the parent server object, or null for the root server. */
parent: ServerRealm | null;
/** the active plugin name (empty string if at the server root). */
plugin: string;
/** the plugin options object passed at registration. */
pluginOptions: object;
/** plugin-specific state to be shared only among activities sharing the same active state. plugins is an object where each key is a plugin name and the value is the plugin state. */
plugins: PluginsStates;
/** settings overrides */
settings: {
files: {
relativeTo: string;
};
bind: object;
};
}
/**
* Registration options (different from the options passed to the registration function):
* * once - if true, subsequent registrations of the same plugin are skipped without error. Cannot be used with plugin options. Defaults to false. If not set to true, an error will be thrown the
* second time a plugin is registered on the server.
* * routes - modifiers applied to each route added by the plugin:
* * * prefix - string added as prefix to any route path (must begin with '/'). If a plugin registers a child plugin the prefix is passed on to the child or is added in front of the child-specific
* prefix.
* * * vhost - virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverregisterplugins-options)
*/
export interface ServerRegisterOptions {
/**
* if true, subsequent registrations of the same plugin are skipped without error. Cannot be used with plugin options. Defaults to false. If not set to true, an error will be thrown the second
* time a plugin is registered on the server.
*/
once?: boolean | undefined;
/**
* modifiers applied to each route added by the plugin:
*/
routes?: {
/**
* string added as prefix to any route path (must begin with '/'). If a plugin registers a child plugin the prefix is passed on to the child or is added in front of the child-specific prefix.
*/
prefix: string;
/**
* virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
*/
vhost?: string | string[] | undefined;
} | undefined;
}
export interface ServerRegisterPluginObjectDirect<T, D> extends ServerRegisterOptions {
/**
* a plugin object.
*/
plugin: Plugin<T, D>;
/**
* options passed to the plugin during registration.
*/
options?: T | undefined;
}
export interface ServerRegisterPluginObjectWrapped<T, D> extends ServerRegisterOptions {
/**
* a plugin object.
*/
plugin: { plugin: Plugin<T, D> };
/**
* options passed to the plugin during registration.
*/
options?: T | undefined;
}
/**
* An object with the following:
* * plugin - a plugin object or a wrapped plugin loaded module.
* * options - (optional) options passed to the plugin during registration.
* * once - if true, subsequent registrations of the same plugin are skipped without error. Cannot be used with plugin options. Defaults to false. If not set to true, an error will be thrown the
* second time a plugin is registered on the server.
* * routes - modifiers applied to each route added by the plugin:
* * * prefix - string added as prefix to any route path (must begin with '/'). If a plugin registers a child plugin the prefix is passed on to the child or is added in front of the child-specific
* prefix.
* * * vhost - virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverregisterplugins-options)
*
* The type parameter T is the type of the plugin configuration options.
*/
export type ServerRegisterPluginObject<T, D = void> =
ServerRegisterPluginObjectDirect<T, D> |
ServerRegisterPluginObjectWrapped<T, D>;
export type ServerRegisterPluginObjectArray<T, U, V, W, X, Y, Z> = (
ServerRegisterPluginObject<T> |
ServerRegisterPluginObject<U> |
ServerRegisterPluginObject<V> |
ServerRegisterPluginObject<W> |
ServerRegisterPluginObject<X> |
ServerRegisterPluginObject<Y> |
ServerRegisterPluginObject<Z>
)[];
/**
* The method function can have a defaults object or function property. If the property is set to an object, that object is used as the default route config for routes using this handler.
* If the property is set to a function, the function uses the signature function(method) and returns the route default configuration.
*/
export interface HandlerDecorationMethod {
(route: RequestRoute, options: any): Lifecycle.Method;
defaults?: RouteOptions | ((method: any) => RouteOptions) | undefined;
}
/**
* An empty interface to allow typings of custom plugin properties.
*/
export interface PluginProperties {
}

531
node_modules/@hapi/hapi/lib/types/request.d.ts generated vendored Normal file
View File

@@ -0,0 +1,531 @@
import * as http from 'http';
import * as stream from 'stream';
import * as url from 'url';
import { Boom } from '@hapi/boom';
import { Podium } from '@hapi/podium';
import { PluginsStates, ServerRealm } from './plugin';
import { ResponseValue, ResponseObject } from "./response";
import { RouteRules, RouteSettings } from './route';
import { Server, ServerAuthSchemeObjectApi } from './server';
import { HTTP_METHODS, PeekListener } from './utils';
/**
* User extensible types user credentials.
*/
export interface UserCredentials {
}
/**
* User extensible types app credentials.
*/
export interface AppCredentials {
}
/**
* User-extensible type for request.auth credentials.
*/
export interface AuthCredentials<
AuthUser = UserCredentials,
AuthApp = AppCredentials
> {
/**
* The application scopes to be granted.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessscope)
*/
scope?: string[] | undefined;
/**
* If set, will only work with routes that set `access.entity` to `user`.
*/
user?: AuthUser
/**
* If set, will only work with routes that set `access.entity` to `app`.
*/
app?: AuthApp;
}
export interface AuthArtifacts {
[key: string]: unknown;
}
export type AuthMode = 'required' | 'optional' | 'try';
/**
* Authentication information:
* * artifacts - an artifact object received from the authentication strategy and used in authentication-related actions.
* * credentials - the credential object received during the authentication process. The presence of an object does not mean successful authentication.
* * error - the authentication error is failed and mode set to 'try'.
* * isAuthenticated - true if the request has been successfully authenticated, otherwise false.
* * isAuthorized - true is the request has been successfully authorized against the route authentication access configuration. If the route has not access rules defined or if the request failed
* authorization, set to false.
* * mode - the route authentication mode.
* * strategy - the name of the strategy used.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestauth)
*/
export interface RequestAuth<
AuthUser = UserCredentials,
AuthApp = AppCredentials,
CredentialsExtra = Record<string, unknown>,
ArtifactsExtra = Record<string, unknown>
> {
/** an artifact object received from the authentication strategy and used in authentication-related actions. */
artifacts: ArtifactsExtra;
/** the credential object received during the authentication process. The presence of an object does not mean successful authentication. */
credentials: (
AuthCredentials<AuthUser, AuthApp> &
CredentialsExtra
);
/** the authentication error is failed and mode set to 'try'. */
error: Error;
/** true if the request has been successfully authenticated, otherwise false. */
isAuthenticated: boolean;
/**
* true is the request has been successfully authorized against the route authentication access configuration. If the route has not access rules defined or if the request failed authorization,
* set to false.
*/
isAuthorized: boolean;
/** true if the request has been authenticated via the `server.inject()` `auth` option, otherwise `undefined`. */
isInjected?: boolean | undefined;
/** the route authentication mode. */
mode: AuthMode;
/** the name of the strategy used. */
strategy: string;
}
/**
* 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
* 'finish' - emitted when the request payload finished reading. The event method signature is function ().
* 'disconnect' - emitted when a request errors or aborts unexpectedly.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
*/
export type RequestEventType = 'peek' | 'finish' | 'disconnect';
/**
* Access: read only and the public podium interface.
* The request.events supports the following events:
* * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
* * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
* * 'disconnect' - emitted when a request errors or aborts unexpectedly.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
*/
export interface RequestEvents extends Podium {
/**
* Access: read only and the public podium interface.
* The request.events supports the following events:
* * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
* * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
* * 'disconnect' - emitted when a request errors or aborts unexpectedly.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
*/
on(criteria: 'peek', listener: PeekListener): this;
on(criteria: 'finish' | 'disconnect', listener: (data: undefined) => void): this;
/**
* Access: read only and the public podium interface.
* The request.events supports the following events:
* * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
* * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
* * 'disconnect' - emitted when a request errors or aborts unexpectedly.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
*/
once(criteria: 'peek', listener: PeekListener): this;
once(criteria: 'peek'): Promise<Parameters<PeekListener>>;
once(criteria: 'finish' | 'disconnect', listener: (data: undefined) => void): this;
}
/**
* Request information:
* * acceptEncoding - the request preferred encoding.
* * cors - if CORS is enabled for the route, contains the following:
* * isOriginMatch - true if the request 'Origin' header matches the configured CORS restrictions. Set to false if no 'Origin' header is found or if it does not match. Note that this is only
* available after the 'onRequest' extension point as CORS is configured per-route and no routing decisions are made at that point in the request lifecycle.
* * host - content of the HTTP 'Host' header (e.g. 'example.com:8080').
* * hostname - the hostname part of the 'Host' header (e.g. 'example.com').
* * id - a unique request identifier (using the format '{now}:{connection.info.id}:{5 digits counter}').
* * received - request reception timestamp.
* * referrer - content of the HTTP 'Referrer' (or 'Referer') header.
* * remoteAddress - remote client IP address.
* * remotePort - remote client port.
* * responded - request response timestamp (0 is not responded yet).
* Note that the request.info object is not meant to be modified.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestinfo)
*/
export interface RequestInfo {
/** the request preferred encoding. */
acceptEncoding: string;
/** if CORS is enabled for the route, contains the following: */
cors: {
/**
* true if the request 'Origin' header matches the configured CORS restrictions. Set to false if no 'Origin' header is found or if it does not match. Note that this is only available after
* the 'onRequest' extension point as CORS is configured per-route and no routing decisions are made at that point in the request lifecycle.
*/
isOriginMatch?: boolean | undefined;
};
/** content of the HTTP 'Host' header (e.g. 'example.com:8080'). */
host: string;
/** the hostname part of the 'Host' header (e.g. 'example.com'). */
hostname: string;
/** a unique request identifier (using the format '{now}:{connection.info.id}:{5 digits counter}') */
id: string;
/** request reception timestamp. */
received: number;
/** content of the HTTP 'Referrer' (or 'Referer') header. */
referrer: string;
/** remote client IP address. */
remoteAddress: string;
/** remote client port. */
remotePort: string;
/** request response timestamp (0 is not responded yet). */
responded: number;
/** request processing completion timestamp (0 is still processing). */
completed: number;
}
/**
* The request route information object, where:
* * method - the route HTTP method.
* * path - the route path.
* * vhost - the route vhost option if configured.
* * realm - the active realm associated with the route.
* * settings - the route options object with all defaults applied.
* * fingerprint - the route internal normalized string representing the normalized path.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestroute)
*/
export interface RequestRoute<Refs extends ReqRef = ReqRefDefaults> {
/** the route HTTP method. */
method: Exclude<Lowercase<HTTP_METHODS>, 'head'> | '*';
/** the route path. */
path: string;
/** the route vhost option if configured. */
vhost?: string | string[] | undefined;
/** the active realm associated with the route. */
realm: ServerRealm;
/** the route options object with all defaults applied. */
settings: RouteSettings<Refs>;
/** the route internal normalized string representing the normalized path. */
fingerprint: string;
auth: {
/**
* Validates a request against the route's authentication access configuration, where:
* @param request - the request object.
* @return Return value: true if the request would have passed the route's access requirements.
* Note that the route's authentication mode and strategies are ignored. The only match is made between the request.auth.credentials scope and entity information and the route access
* configuration. If the route uses dynamic scopes, the scopes are constructed against the request.query, request.params, request.payload, and request.auth.credentials which may or may
* not match between the route and the request's route. If this method is called using a request that has not been authenticated (yet or not at all), it will return false if the route
* requires any authentication.
* [See docs](https://hapijs.com/api/17.0.1#-requestrouteauthaccessrequest)
*/
access(request: Request): boolean;
};
}
/**
* An object containing the values of params, query, and payload before any validation modifications made. Only set when input validation is performed.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestorig)
*/
export interface RequestOrig {
params: object;
query: object;
payload: object;
}
export interface RequestLog {
request: string;
timestamp: number;
tags: string[];
data: string | object;
channel: string;
}
export interface RequestQuery {
[key: string]: string | string[] | undefined;
}
/**
* Empty interface to allow for user-defined augmentations.
*/
export interface RouteOptionsApp {}
/**
* User-extensible type for application specific state on requests (`request.app`).
*/
export interface RequestApplicationState {
}
export interface InternalRequestDefaults {
Server: Server;
Payload: stream.Readable | Buffer | string | object;
Query: RequestQuery;
Params: Record<string, string>;
Pres: Record<string, any>;
Headers: Record<string, string | string[] | undefined>;
RequestApp: RequestApplicationState;
AuthUser: UserCredentials;
AuthApp: AppCredentials;
AuthApi: ServerAuthSchemeObjectApi;
AuthCredentialsExtra: Record<string, unknown>;
AuthArtifactsExtra: Record<string, unknown>;
Rules: RouteRules;
Bind: object | null;
RouteApp: RouteOptionsApp;
}
/**
* Default request references. Used to give typing to requests,
* route handlers, lifecycle methods, auth credentials, etc.
* This can be overwritten to whatever is suitable and universal
* in your specific app, but whatever references you pass to
* server route generic, or lifecycle methods will take precedence
* over these.
*/
export interface ReqRefDefaults extends InternalRequestDefaults {}
/**
* Route request overrides
*/
export type ReqRef = Partial<Record<keyof ReqRefDefaults, unknown>>;
/**
* Utilities for merging request refs and other things
*/
export type MergeType<T, U> = Omit<T, keyof U> & U;
export type MergeRefs<T extends ReqRef> = MergeType<ReqRefDefaults, T>;
/**
* The request object is created internally for each incoming request. It is not the same object received from the node
* HTTP server callback (which is available via [request.raw.req](https://github.com/hapijs/hapi/blob/master/API.md#request.raw)). The request properties change throughout
* the request [lifecycle](https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle).
*/
export interface Request<Refs extends ReqRef = ReqRefDefaults> extends Podium {
/**
* Application-specific state. Provides a safe place to store application data without potential conflicts with the framework. Should not be used by plugins which should use plugins[name].
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestapp)
*/
app: MergeRefs<Refs>['RequestApp'];
/**
* Authentication information:
* * artifacts - an artifact object received from the authentication strategy and used in authentication-related actions.
* * credentials - the credential object received during the authentication process. The presence of an object does not mean successful authentication.
* * error - the authentication error is failed and mode set to 'try'.
* * isAuthenticated - true if the request has been successfully authenticated, otherwise false.
* * isAuthorized - true is the request has been successfully authorized against the route authentication access configuration. If the route has not access rules defined or if the request failed
* authorization, set to false.
* * mode - the route authentication mode.
* * strategy - the name of the strategy used.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestauth)
*/
readonly auth: RequestAuth<
MergeRefs<Refs>['AuthUser'],
MergeRefs<Refs>['AuthApp'],
MergeRefs<Refs>['AuthCredentialsExtra'],
MergeRefs<Refs>['AuthArtifactsExtra']
>;
/**
* Access: read only and the public podium interface.
* The request.events supports the following events:
* * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
* * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
* * 'disconnect' - emitted when a request errors or aborts unexpectedly.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
*/
events: RequestEvents;
/**
* The raw request headers (references request.raw.req.headers).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestheaders)
*/
readonly headers: MergeRefs<Refs>['Headers'];
/**
* Request information:
* * acceptEncoding - the request preferred encoding.
* * cors - if CORS is enabled for the route, contains the following:
* * isOriginMatch - true if the request 'Origin' header matches the configured CORS restrictions. Set to false if no 'Origin' header is found or if it does not match. Note that this is only
* available after the 'onRequest' extension point as CORS is configured per-route and no routing decisions are made at that point in the request lifecycle.
* * host - content of the HTTP 'Host' header (e.g. 'example.com:8080').
* * hostname - the hostname part of the 'Host' header (e.g. 'example.com').
* * id - a unique request identifier (using the format '{now}:{connection.info.id}:{5 digits counter}').
* * received - request reception timestamp.
* * referrer - content of the HTTP 'Referrer' (or 'Referer') header.
* * remoteAddress - remote client IP address.
* * remotePort - remote client port.
* * responded - request response timestamp (0 is not responded yet).
* Note that the request.info object is not meant to be modified.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestinfo)
*/
readonly info: RequestInfo;
/**
* An array containing the logged request events.
* Note that this array will be empty if route log.collect is set to false.
*/
readonly logs: RequestLog[];
/**
* The request method in lower case (e.g. 'get', 'post').
*/
readonly method: Lowercase<HTTP_METHODS>;
/**
* The parsed content-type header. Only available when payload parsing enabled and no payload error occurred.
*/
readonly mime: string;
/**
* An object containing the values of params, query, and payload before any validation modifications made. Only set when input validation is performed.
*/
readonly orig: RequestOrig;
/**
* An object where each key is a path parameter name with matching value as described in [Path parameters](https://github.com/hapijs/hapi/blob/master/API.md#path-parameters).
*/
readonly params: MergeRefs<Refs>['Params'];
/**
* An array containing all the path params values in the order they appeared in the path.
*/
readonly paramsArray: keyof MergeRefs<Refs>['Params'] | string[];
/**
* The request URI's pathname component.
*/
readonly path: string;
/**
* The request payload based on the route payload.output and payload.parse settings.
* TODO check this typing and add references / links.
*/
readonly payload: MergeRefs<Refs>['Payload'];
/**
* Plugin-specific state. Provides a place to store and pass request-level plugin data. The plugins is an object where each key is a plugin name and the value is the state.
*/
plugins: PluginsStates;
/**
* An object where each key is the name assigned by a route pre-handler methods function. The values are the raw values provided to the continuation function as argument. For the wrapped response
* object, use responses.
*/
readonly pre: MergeRefs<Refs>['Pres'];
/**
* Access: read / write (see limitations below).
* The response object when set. The object can be modified but must not be assigned another object. To replace the response with another from within an extension point, use reply(response) to
* override with a different response.
* In case of an aborted request the status code will be set to `disconnectStatusCode`.
*/
response: ResponseObject | Boom;
/**
* Same as pre but represented as the response object created by the pre method.
*/
readonly preResponses: Record<string, unknown>;
/**
* By default the object outputted from node's URL parse() method.
*/
readonly query: MergeRefs<Refs>['Query'];
/**
* An object containing the Node HTTP server objects. Direct interaction with these raw objects is not recommended.
* * req - the node request object.
* * res - the node response object.
*/
readonly raw: {
req: http.IncomingMessage;
res: http.ServerResponse;
};
/**
* The request route information object and method
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestroute)
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestrouteauthaccessrequest)
*/
readonly route: RequestRoute<Refs>;
/**
* Access: read only and the public server interface.
* The server object.
*/
readonly server: MergeRefs<Refs>['Server'];
/**
* An object containing parsed HTTP state information (cookies) where each key is the cookie name and value is the matching cookie content after processing using any registered cookie definition.
*/
readonly state: Record<string, unknown>;
/**
* The parsed request URI.
*/
readonly url: url.URL;
/**
* Returns `true` when the request is active and processing should continue and `false` when the
* request terminated early or completed its lifecycle. Useful when request processing is a
* resource-intensive operation and should be terminated early if the request is no longer active
* (e.g. client disconnected or aborted early).
*/
active(): boolean;
/**
* Returns a response which you can pass into the reply interface where:
* @param source - the value to set as the source of the reply interface, optional.
* @param options - options for the method, optional.
* @return ResponseObject
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestgenerateresponsesource-options)
*/
/* tslint:disable-next-line:max-line-length */
generateResponse(source: string | object | null, options?: { variety?: string | undefined; prepare?: ((response: ResponseObject) => Promise<ResponseObject>) | undefined; marshal?: ((response: ResponseObject) => Promise<ResponseValue>) | undefined; close?: ((response: ResponseObject) => void) | undefined; } | undefined): ResponseObject;
/**
* Logs request-specific events. When called, the server emits a 'request' event which can be used by other listeners or plugins. The arguments are:
* @param tags - a string or an array of strings (e.g. ['error', 'database', 'read']) used to identify the event. Tags are used instead of log levels and provide a much more expressive mechanism
* for describing and filtering events.
* @param data - (optional) an message string or object with the application data being logged. If data is a function, the function signature is function() and it called once to generate (return
* value) the actual data emitted to the listeners. Any logs generated by the server internally will be emitted only on the 'request-internal' channel and will include the event.internal flag
* set to true.
* @return void
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestlogtags-data)
*/
log(tags: string | string[], data?: string | object | (() => string | object) | undefined): void;
/**
* Changes the request method before the router begins processing the request where:
* @param method - is the request HTTP method (e.g. 'GET').
* @return void
* Can only be called from an 'onRequest' extension method.
* [See docs](https://hapijs.com/api/17.0.1#-requestsetmethodmethod)
*/
setMethod(method: HTTP_METHODS | Lowercase<HTTP_METHODS>): void;
/**
* Changes the request URI before the router begins processing the request where:
* Can only be called from an 'onRequest' extension method.
* @param url - the new request URI. If url is a string, it is parsed with node's URL parse() method with parseQueryString set to true. url can also be set to an object compatible with node's URL
* parse() method output.
* @param stripTrailingSlash - if true, strip the trailing slash from the path. Defaults to false.
* @return void
* [See docs](https://hapijs.com/api/17.0.1#-requestseturlurl-striptrailingslash)
*/
setUrl(url: string | url.URL, stripTrailingSlash?: boolean | undefined): void;
}

568
node_modules/@hapi/hapi/lib/types/response.d.ts generated vendored Normal file
View File

@@ -0,0 +1,568 @@
import { Podium } from '@hapi/podium';
import { PluginsStates, ServerRealm } from './plugin';
import {
UserCredentials,
AppCredentials,
AuthArtifacts,
AuthCredentials,
ReqRef,
ReqRefDefaults,
MergeRefs,
Request
} from './request';
import { PeekListener, Lifecycle, Json } from './utils';
import { ServerStateCookieOptions } from './server';
/**
* User-extensible type for application specific state on responses (`response.app`).
*/
export interface ResponseApplicationState {
}
/**
* Access: read only and the public podium interface.
* The response.events object supports the following events:
* * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
* * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
* [See docs](https://hapijs.com/api/17.0.1#-responseevents)
*/
export interface ResponseEvents extends Podium {
/**
* 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
* 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
*/
on(criteria: 'peek', listener: PeekListener): this;
on(criteria: 'finish', listener: (data: undefined) => void): this;
/**
* 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
* 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
*/
once(criteria: 'peek', listener: PeekListener): this;
once(criteria: 'peek'): Promise<Parameters<PeekListener>>;
once(criteria: 'finish', listener: (data: undefined) => void): this;
}
/**
* Object where:
* * append - if true, the value is appended to any existing header value using separator. Defaults to false.
* * separator - string used as separator when appending to an existing value. Defaults to ','.
* * override - if false, the header value is not set if an existing value present. Defaults to true.
* * duplicate - if false, the header value is not modified if the provided value is already included. Does not apply when append is false or if the name is 'set-cookie'. Defaults to true.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheadername-value-options)
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-object)
*/
export interface ResponseObjectHeaderOptions {
append?: boolean | undefined;
separator?: string | undefined;
override?: boolean | undefined;
duplicate?: boolean | undefined;
}
/**
* The response object contains the request response value along with various HTTP headers and flags. When a lifecycle
* method returns a value, the value is wrapped in a response object along with some default flags (e.g. 200 status
* code). In order to customize a response before it is returned, the h.response() method is provided.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-object)
* TODO, check extending from Podium is correct. Extending because of "The response object supports the following events" [See docs](https://hapijs.com/api/17.0.1#-responseevents)
*/
export interface ResponseObject extends Podium {
/**
* @default {}.
* Application-specific state. Provides a safe place to store application data without potential conflicts with the framework. Should not be used by plugins which should use plugins[name].
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseapp)
*/
app: ResponseApplicationState;
/**
* Access: read only and the public podium interface.
* The response.events object supports the following events:
* * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
* * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
* [See docs](https://hapijs.com/api/17.0.1#-responseevents)
*/
readonly events: ResponseEvents;
/**
* @default {}.
* An object containing the response headers where each key is a header field name and the value is the string header value or array of string.
* Note that this is an incomplete list of headers to be included with the response. Additional headers will be added once the response is prepared for transmission.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheaders)
*/
readonly headers: Record<string, string | string[]>;
/**
* @default {}.
* Plugin-specific state. Provides a place to store and pass request-level plugin data. plugins is an object where each key is a plugin name and the value is the state.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseplugins)
*/
plugins: PluginsStates;
/**
* Object containing the response handling flags.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesettings)
*/
readonly settings: ResponseSettings;
/**
* The raw value returned by the lifecycle method.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesource)
*/
readonly source: Lifecycle.ReturnValue;
/**
* @default 200.
* The HTTP response status code.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsestatuscode)
*/
readonly statusCode: number;
/**
* A string indicating the type of source with available values:
* * 'plain' - a plain response such as string, number, null, or simple object.
* * 'buffer' - a Buffer.
* * 'stream' - a Stream.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsevariety)
*/
readonly variety: 'plain' | 'buffer' | 'stream';
/**
* Sets the HTTP 'Content-Length' header (to avoid chunked transfer encoding) where:
* @param length - the header value. Must match the actual payload size.
* @return Return value: the current response object.
* [See docs](https://hapijs.com/api/17.0.1#-responsebyteslength)
*/
bytes(length: number): ResponseObject;
/**
* Controls the 'Content-Type' HTTP header 'charset' property of the response.
* * When invoked without any parameter, will prevent hapi from applying its default charset normalization to 'utf-8'
* * When 'charset' parameter is provided, will set the 'Content-Type' HTTP header 'charset' property where:
* @param charset - the charset property value.
* @return Return value: the current response object.
* [See docs](https://hapijs.com/api/17.0.1#-responsecharsetcharset)
*/
charset(charset?: string): ResponseObject | undefined;
/**
* Sets the HTTP status code where:
* @param statusCode - the HTTP status code (e.g. 200).
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecodestatuscode)
*/
code(statusCode: number): ResponseObject;
/**
* Sets the HTTP status message where:
* @param httpMessage - the HTTP status message (e.g. 'Ok' for status code 200).
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsemessagehttpmessage)
*/
message(httpMessage: string): ResponseObject;
/**
* Sets the HTTP 'content-encoding' header where:
* @param encoding - the header value string.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecompressedencoding)
*/
compressed(encoding: string): ResponseObject;
/**
* Sets the HTTP status code to Created (201) and the HTTP 'Location' header where:
* @param uri - an absolute or relative URI used as the 'Location' header value.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecreateduri)
*/
created(uri: string): ResponseObject;
/**
* Sets the string encoding scheme used to serial data into the HTTP payload where:
* @param encoding the encoding property value (see node Buffer encoding [See docs](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings)).
* * 'ascii' - for 7-bit ASCII data only. This encoding is fast and will strip the high bit if set.
* * 'utf8' - Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
* * 'utf16le' - 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.
* * 'ucs2' - Alias of 'utf16le'.
* * 'base64' - Base64 encoding. When creating a Buffer from a string, this encoding will also correctly accept "URL and Filename Safe Alphabet" as specified in RFC4648, Section 5.
* * 'latin1' - A way of encoding the Buffer into a one-byte encoded string (as defined by the IANA in RFC1345, page 63, to be the Latin-1 supplement block and C0/C1 control codes).
* * 'binary' - Alias for 'latin1'.
* * 'hex' - Encode each byte as two hexadecimal characters.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseencodingencoding)
*/
encoding(encoding: 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64' | 'latin1' | 'binary' | 'hex'): ResponseObject;
/**
* Sets the representation entity tag where:
* @param tag - the entity tag string without the double-quote.
* @param options - (optional) settings where:
* * weak - if true, the tag will be prefixed with the 'W/' weak signifier. Weak tags will fail to match identical tags for the purpose of determining 304 response status. Defaults to false.
* * vary - if true and content encoding is set or applied to the response (e.g 'gzip' or 'deflate'), the encoding name will be automatically added to the tag at transmission time (separated by
* a '-' character). Ignored when weak is true. Defaults to true.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseetagtag-options)
*/
etag(tag: string, options?: {weak: boolean, vary: boolean} | undefined): ResponseObject;
/**
* Sets an HTTP header where:
* @param name - the header name.
* @param value - the header value.
* @param options - (optional) object where:
* * append - if true, the value is appended to any existing header value using separator. Defaults to false.
* * separator - string used as separator when appending to an existing value. Defaults to ','.
* * override - if false, the header value is not set if an existing value present. Defaults to true.
* * duplicate - if false, the header value is not modified if the provided value is already included. Does not apply when append is false or if the name is 'set-cookie'. Defaults to true.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheadername-value-options)
*/
header(name: string, value: string, options?: ResponseObjectHeaderOptions | undefined): ResponseObject;
/**
* Sets the HTTP 'Location' header where:
* @param uri - an absolute or relative URI used as the 'Location' header value.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responselocationuri)
*/
location(uri: string): ResponseObject;
/**
* Sets an HTTP redirection response (302) and decorates the response with additional methods, where:
* @param uri - an absolute or relative URI used to redirect the client to another resource.
* @return Return value: the current response object.
* Decorates the response object with the response.temporary(), response.permanent(), and response.rewritable() methods to easily change the default redirection code (302).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseredirecturi)
*/
redirect(uri: string): ResponseObject;
/**
* Sets the JSON.stringify() replacer argument where:
* @param method - the replacer function or array. Defaults to none.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsereplacermethod)
*/
replacer(method: Json.StringifyReplacer): ResponseObject;
/**
* Sets the JSON.stringify() space argument where:
* @param count - the number of spaces to indent nested object keys. Defaults to no indentation.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsespacescount)
*/
spaces(count: number): ResponseObject;
/**
* Sets an HTTP cookie where:
* @param name - the cookie name.
* @param value - the cookie value. If no options.encoding is defined, must be a string. See server.state() for supported encoding values.
* @param options - (optional) configuration. If the state was previously registered with the server using server.state(), the specified keys in options are merged with the default server
* definition.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsestatename-value-options)
*/
state(name: string, value: object | string, options?: ServerStateCookieOptions | undefined): ResponseObject;
/**
* Sets a string suffix when the response is process via JSON.stringify() where:
* @param suffix - the string suffix.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesuffixsuffix)
*/
suffix(suffix: string): ResponseObject;
/**
* Overrides the default route cache expiration rule for this response instance where:
* @param msec - the time-to-live value in milliseconds.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsettlmsec)
*/
ttl(msec: number): ResponseObject;
/**
* Sets the HTTP 'Content-Type' header where:
* @param mimeType - is the mime type.
* @return Return value: the current response object.
* Should only be used to override the built-in default for each response type.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetypemimetype)
*/
type(mimeType: string): ResponseObject;
/**
* Clears the HTTP cookie by setting an expired value where:
* @param name - the cookie name.
* @param options - (optional) configuration for expiring cookie. If the state was previously registered with the server using server.state(), the specified options are merged with the server
* definition.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseunstatename-options)
*/
unstate(name: string, options?: ServerStateCookieOptions | undefined): ResponseObject;
/**
* Adds the provided header to the list of inputs affected the response generation via the HTTP 'Vary' header where:
* @param header - the HTTP request header name.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsevaryheader)
*/
vary(header: string): ResponseObject;
/**
* Marks the response object as a takeover response.
* @return Return value: the current response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetakeover)
*/
takeover(): ResponseObject;
/**
* Sets the status code to 302 or 307 (based on the response.rewritable() setting) where:
* @param isTemporary - if false, sets status to permanent. Defaults to true.
* @return Return value: the current response object.
* Only available after calling the response.redirect() method.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetemporaryistemporary)
*/
temporary(isTemporary?: boolean): ResponseObject;
/**
* Sets the status code to 301 or 308 (based on the response.rewritable() setting) where:
* @param isPermanent - if false, sets status to temporary. Defaults to true.
* @return Return value: the current response object.
* Only available after calling the response.redirect() method.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsepermanentispermanent)
*/
permanent(isPermanent?: boolean): ResponseObject;
/**
* Sets the status code to 301/302 for rewritable (allows changing the request method from 'POST' to 'GET') or 307/308 for non-rewritable (does not allow changing the request method from 'POST'
* to 'GET'). Exact code based on the response.temporary() or response.permanent() setting. Arguments:
* @param isRewritable - if false, sets to non-rewritable. Defaults to true.
* @return Return value: the current response object.
* Only available after calling the response.redirect() method.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responserewritableisrewritable)
*/
rewritable(isRewritable?: boolean): ResponseObject;
}
/**
* Object containing the response handling flags.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesettings)
*/
export interface ResponseSettings {
/**
* Defaults value: true.
* If true and source is a Stream, copies the statusCode and headers properties of the stream object to the outbound response.
*/
readonly passThrough: boolean;
/**
* @default null (use route defaults).
* Override the route json options used when source value requires stringification.
*/
readonly stringify: Json.StringifyArguments;
/**
* @default null (use route defaults).
* If set, overrides the route cache with an expiration value in milliseconds.
*/
readonly ttl: number;
/**
* @default false.
* If true, a suffix will be automatically added to the 'ETag' header at transmission time (separated by a '-' character) when the HTTP 'Vary' header is present.
*/
varyEtag: boolean;
}
/**
* See more about Lifecycle
* https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle
*
*/
export type ResponseValue = string | object;
export interface AuthenticationData<
AuthUser = UserCredentials,
AuthApp = AppCredentials,
CredentialsExtra = Record<string, unknown>,
ArtifactsExtra = AuthArtifacts
> {
credentials: AuthCredentials<AuthUser, AuthApp> & CredentialsExtra;
artifacts?: ArtifactsExtra | undefined;
}
export interface Auth<
AuthUser = UserCredentials,
AuthApp = AppCredentials,
CredentialsExtra = Record<string, unknown>,
ArtifactsExtra = AuthArtifacts
> {
readonly isAuth: true;
readonly error?: Error | null | undefined;
readonly data?: AuthenticationData<AuthUser, AuthApp, CredentialsExtra, ArtifactsExtra> | undefined;
}
/**
* The response toolkit is a collection of properties and utilities passed to every [lifecycle method](https://github.com/hapijs/hapi/blob/master/API.md#lifecycle-methods)
* It is somewhat hard to define as it provides both utilities for manipulating responses as well as other information. Since the
* toolkit is passed as a function argument, developers can name it whatever they want. For the purpose of this
* document the h notation is used. It is named in the spirit of the RethinkDB r method, with h for hapi.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-toolkit)
*/
export interface ResponseToolkit<Refs extends ReqRef = ReqRefDefaults> {
/**
* A response symbol. When returned by a lifecycle method, the request lifecycle skips to the finalizing step
* without further interaction with the node response stream. It is the developer's responsibility to write
* and end the response directly via [request.raw.res](https://github.com/hapijs/hapi/blob/master/API.md#request.raw).
*/
readonly abandon: symbol;
/**
* A response symbol. When returned by a lifecycle method, the request lifecycle skips to the finalizing step after
* calling request.raw.res.end()) to close the the node response stream.
*/
readonly close: symbol;
/**
* A response symbol. Provides access to the route or server context set via the route [bind](https://github.com/hapijs/hapi/blob/master/API.md#route.options.bind)
* option or [server.bind()](https://github.com/hapijs/hapi/blob/master/API.md#server.bind()).
*/
readonly context: any;
/**
* A response symbol. When returned by a lifecycle method, the request lifecycle continues without changing the response.
*/
readonly continue: symbol;
/**
* The [server realm](https://github.com/hapijs/hapi/blob/master/API.md#server.realm) associated with the matching
* route. Defaults to the root server realm in the onRequest step.
*/
readonly realm: ServerRealm;
/**
* Access: read only and public request interface.
* The [request] object. This is a duplication of the request lifecycle method argument used by
* [toolkit decorations](https://github.com/hapijs/hapi/blob/master/API.md#server.decorate()) to access the current request.
*/
readonly request: Readonly<Request<Refs>>;
/**
* Used by the [authentication] method to pass back valid credentials where:
* @param data - an object with:
* * credentials - (required) object representing the authenticated entity.
* * artifacts - (optional) authentication artifacts object specific to the authentication scheme.
* @return Return value: an internal authentication object.
*/
authenticated <
AuthUser = MergeRefs<Refs>['AuthUser'],
AuthApp = MergeRefs<Refs>['AuthApp'],
CredentialsExtra = MergeRefs<Refs>['AuthCredentialsExtra'],
ArtifactsExtra = MergeRefs<Refs>['AuthArtifactsExtra']
>(
data: (
AuthenticationData<
AuthUser,
AuthApp,
CredentialsExtra,
ArtifactsExtra
>
)
): Auth<
AuthUser,
AuthApp,
CredentialsExtra,
ArtifactsExtra
>;
/**
* Sets the response 'ETag' and 'Last-Modified' headers and checks for any conditional request headers to decide if
* the response is going to qualify for an HTTP 304 (Not Modified). If the entity values match the request
* conditions, h.entity() returns a response object for the lifecycle method to return as its value which will
* set a 304 response. Otherwise, it sets the provided entity headers and returns undefined.
* The method arguments are:
* @param options - a required configuration object with:
* * etag - the ETag string. Required if modified is not present. Defaults to no header.
* * modified - the Last-Modified header value. Required if etag is not present. Defaults to no header.
* * vary - same as the response.etag() option. Defaults to true.
* @return Return value: - a response object if the response is unmodified. - undefined if the response has changed.
* If undefined is returned, the developer must return a valid lifecycle method value. If a response is returned,
* it should be used as the return value (but may be customize using the response methods).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hentityoptions)
*/
entity(options?: {etag?: string | undefined, modified?: string | undefined, vary?: boolean | undefined} | undefined): ResponseObject;
/**
* Redirects the client to the specified uri. Same as calling h.response().redirect(uri).
* @param url
* @return Returns a response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hredirecturi)
*/
redirect(uri?: string | undefined): ResponseObject;
/**
* Wraps the provided value and returns a response object which allows customizing the response
* (e.g. setting the HTTP status code, custom headers, etc.), where:
* @param value - (optional) return value. Defaults to null.
* @return Returns a response object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hresponsevalue)
*/
response(value?: ResponseValue | undefined): ResponseObject;
/**
* Sets a response cookie using the same arguments as response.state().
* @param name of the cookie
* @param value of the cookie
* @param (optional) ServerStateCookieOptions object.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hstatename-value-options)
*/
state(name: string, value: string | object, options?: ServerStateCookieOptions | undefined): void;
/**
* Used by the [authentication] method to indicate authentication failed and pass back the credentials received where:
* @param error - (required) the authentication error.
* @param data - (optional) an object with:
* * credentials - (required) object representing the authenticated entity.
* * artifacts - (optional) authentication artifacts object specific to the authentication scheme.
* @return void.
* The method is used to pass both the authentication error and the credentials. For example, if a request included
* expired credentials, it allows the method to pass back the user information (combined with a 'try'
* authentication mode) for error customization.
* There is no difference between throwing the error or passing it with the h.unauthenticated() method is no credentials are passed, but it might still be helpful for code clarity.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunauthenticatederror-data)
*/
unauthenticated <
AuthUser = MergeRefs<Refs>['AuthUser'],
AuthApp = MergeRefs<Refs>['AuthApp'],
CredentialsExtra = MergeRefs<Refs>['AuthCredentialsExtra'],
ArtifactsExtra = MergeRefs<Refs>['AuthArtifactsExtra']
>(
error: Error,
data?: (
AuthenticationData<
AuthUser,
AuthApp,
CredentialsExtra,
ArtifactsExtra
>
) | undefined
): Auth<
AuthUser,
AuthApp,
CredentialsExtra,
ArtifactsExtra
>;
/**
* Clears a response cookie using the same arguments as
* @param name of the cookie
* @param options (optional) ServerStateCookieOptions object.
* @return void.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunstatename-options)
*/
unstate(name: string, options?: ServerStateCookieOptions | undefined): void;
}

982
node_modules/@hapi/hapi/lib/types/route.d.ts generated vendored Normal file
View File

@@ -0,0 +1,982 @@
import { ObjectSchema, ValidationOptions, SchemaMap, Schema } from 'joi';
import { PluginSpecificConfiguration} from './plugin';
import { MergeType, ReqRef, ReqRefDefaults, MergeRefs, AuthMode } from './request';
import { ContentDecoders, ContentEncoders, RouteRequestExtType, RouteExtObject, Server } from './server';
import { Lifecycle, Json, HTTP_METHODS } from './utils';
/**
* Overrides for `InternalRouteOptionType`. Extend this to have
* typings for route.options.auth['strategy' || 'scope']
*
* @example
*
* interface RoutOptionTypes {
* Strategy: 'jwt' | 'basic' | 'myCustom'
* Scope: 'user' | 'admin' | 'manager-users'
* }
*/
export interface RouteOptionTypes {
}
export interface InternalRouteOptionType {
Strategy: string;
Scope: RouteOptionsAccessScope;
}
export type RouteOptionsAccessScope = false | string | string[];
export type AccessEntity = 'any' | 'user' | 'app';
export interface RouteOptionsAccessScopeObject {
scope: RouteOptionsAccessScope;
}
export interface RouteOptionsAccessEntityObject {
entity: AccessEntity;
}
export type RouteOptionsAccessObject =
RouteOptionsAccessScopeObject
| RouteOptionsAccessEntityObject
| (RouteOptionsAccessScopeObject & RouteOptionsAccessEntityObject);
/**
* Route Authentication Options
*/
export interface RouteOptionsAccess {
/**
* @default none.
* An object or array of objects specifying the route access rules. Each rule is evaluated against an incoming request and access is granted if at least one of the rules matches. Each rule object
* must include at least one of scope or entity.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccess)
*/
access?: RouteOptionsAccessObject | RouteOptionsAccessObject[] | undefined;
/**
* @default false (no scope requirements).
* The application scope required to access the route. Value can be a scope string or an array of scope strings. When authenticated, the credentials object scope property must contain at least
* one of the scopes defined to access the route. If a scope string begins with a + character, that scope is required. If a scope string begins with a ! character, that scope is forbidden. For
* example, the scope ['!a', '+b', 'c', 'd'] means the incoming request credentials' scope must not include 'a', must include 'b', and must include one of 'c' or 'd'. You may also access
* properties on the request object (query, params, payload, and credentials) to populate a dynamic scope by using the '{' and '}' characters around the property name, such as 'user-{params.id}'.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessscope)
*/
scope?: MergeType<InternalRouteOptionType, RouteOptionTypes>['Scope'] | undefined;
/**
* @default 'any'.
* The required authenticated entity type. If set, must match the entity value of the request authenticated credentials. Available values:
* * 'any' - the authentication can be on behalf of a user or application.
* * 'user' - the authentication must be on behalf of a user which is identified by the presence of a 'user' attribute in the credentials object returned by the authentication strategy.
* * 'app' - the authentication must be on behalf of an application which is identified by the lack of presence of a user attribute in the credentials object returned by the authentication
* strategy.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessentity)
*/
entity?: AccessEntity | undefined;
/**
* @default 'required'.
* The authentication mode. Available values:
* * 'required' - authentication is required.
* * 'optional' - authentication is optional - the request must include valid credentials or no credentials at all.
* * 'try' - similar to 'optional', any request credentials are attempted authentication, but if the credentials are invalid, the request proceeds regardless of the authentication error.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthmode)
*/
mode?: AuthMode | undefined;
/**
* @default false, unless the scheme requires payload authentication.
* If set, the incoming request payload is authenticated after it is processed. Requires a strategy with payload authentication support (e.g. Hawk). Cannot be set to a value other than 'required'
* when the scheme sets the authentication options.payload to true. Available values:
* * false - no payload authentication.
* * 'required' - payload authentication required.
* * 'optional' - payload authentication performed only when the client includes payload authentication information (e.g. hash attribute in Hawk).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthpayload)
*/
payload?: false | 'required' | 'optional' | undefined;
/**
* @default the default strategy set via server.auth.default().
* An array of string strategy names in the order they should be attempted. Cannot be used together with strategy.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthstrategies)
*/
strategies?: (MergeType<InternalRouteOptionType, RouteOptionTypes>['Strategy'])[] | undefined;
/**
* @default the default strategy set via server.auth.default().
* A string strategy names. Cannot be used together with strategies.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthstrategy)
*/
strategy?: MergeType<InternalRouteOptionType, RouteOptionTypes>['Strategy'] | undefined;
}
/**
* Values are:
* * * 'default' - no privacy flag.
* * * 'public' - mark the response as suitable for public caching.
* * * 'private' - mark the response as suitable only for private caching.
* * expiresIn - relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt.
* * expiresAt - time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire. Cannot be used together with expiresIn.
* * statuses - an array of HTTP response status code numbers (e.g. 200) which are allowed to include a valid caching directive.
* * otherwise - a string with the value of the 'Cache-Control' header when caching is disabled.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscache)
*/
export type RouteOptionsCache = {
privacy?: 'default' | 'public' | 'private' | undefined;
statuses?: number[] | undefined;
otherwise?: string | undefined;
} & (
{
expiresIn?: number | undefined;
expiresAt?: undefined;
} | {
expiresIn?: undefined;
expiresAt?: string | undefined;
} | {
expiresIn?: undefined;
expiresAt?: undefined;
}
);
/**
* @default false (no CORS headers).
* The Cross-Origin Resource Sharing protocol allows browsers to make cross-origin API calls. CORS is required by web applications running inside a browser which are loaded from a different domain
* than the API server. To enable, set cors to true, or to an object with the following options:
* * origin - an array of allowed origin servers strings ('Access-Control-Allow-Origin'). The array can contain any combination of fully qualified origins along with origin strings containing a
* wildcard '*' character, or a single '*' origin string. If set to 'ignore', any incoming Origin header is ignored (present or not) and the 'Access-Control-Allow-Origin' header is set to '*'.
* Defaults to any origin ['*'].
* * maxAge - number of seconds the browser should cache the CORS response ('Access-Control-Max-Age'). The greater the value, the longer it will take before the browser checks for changes in policy.
* Defaults to 86400 (one day).
* * headers - a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to ['Accept', 'Authorization', 'Content-Type', 'If-None-Match'].
* * additionalHeaders - a strings array of additional headers to headers. Use this to keep the default headers in place.
* * exposedHeaders - a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to ['WWW-Authenticate', 'Server-Authorization'].
* * additionalExposedHeaders - a strings array of additional headers to exposedHeaders. Use this to keep the default headers in place.
* * credentials - if true, allows user credentials to be sent ('Access-Control-Allow-Credentials'). Defaults to false.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscors)
*/
export interface RouteOptionsCors {
/**
* an array of allowed origin servers strings ('Access-Control-Allow-Origin'). The array can contain any combination of fully qualified origins along with origin strings containing a wildcard '*'
* character, or a single '*' origin string. If set to 'ignore', any incoming Origin header is ignored (present or not) and the 'Access-Control-Allow-Origin' header is set to '*'. Defaults to any
* origin ['*'].
*/
origin?: string[] | '*' | 'ignore' | undefined;
/**
* number of seconds the browser should cache the CORS response ('Access-Control-Max-Age'). The greater the value, the longer it will take before the browser checks for changes in policy.
* Defaults to 86400 (one day).
*/
maxAge?: number | undefined;
/**
* a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to ['Accept', 'Authorization', 'Content-Type', 'If-None-Match'].
*/
headers?: string[] | undefined;
/**
* a strings array of additional headers to headers. Use this to keep the default headers in place.
*/
additionalHeaders?: string[] | undefined;
/**
* a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to ['WWW-Authenticate', 'Server-Authorization'].
*/
exposedHeaders?: string[] | undefined;
/**
* a strings array of additional headers to exposedHeaders. Use this to keep the default headers in place.
*/
additionalExposedHeaders?: string[] | undefined;
/**
* if true, allows user credentials to be sent ('Access-Control-Allow-Credentials'). Defaults to false.
*/
credentials?: boolean | undefined;
/**
* the status code used for CORS preflight responses, either 200 or 204. Defaults to 200.
*/
preflightStatusCode?: 200 | 204;
}
/**
* The value must be one of:
* * 'data' - the incoming payload is read fully into memory. If parse is true, the payload is parsed (JSON, form-decoded, multipart) based on the 'Content-Type' header. If parse is false, a raw
* Buffer is returned.
* * 'stream' - the incoming payload is made available via a Stream.Readable interface. If the payload is 'multipart/form-data' and parse is true, field values are presented as text while files are
* provided as streams. File streams from a 'multipart/form-data' upload will also have a hapi property containing the filename and headers properties. Note that payload streams for multipart
* payloads are a synthetic interface created on top of the entire multipart content loaded into memory. To avoid loading large multipart payloads into memory, set parse to false and handle the
* multipart payload in the handler using a streaming parser (e.g. pez).
* * 'file' - the incoming payload is written to temporary file in the directory specified by the uploads settings. If the payload is 'multipart/form-data' and parse is true, field values are
* presented as text while files are saved to disk. Note that it is the sole responsibility of the application to clean up the files generated by the framework. This can be done by keeping track of
* which files are used (e.g. using the request.app object), and listening to the server 'response' event to perform cleanup. For context [See
* docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadoutput)
*/
export type PayloadOutput = 'data' | 'stream' | 'file';
/**
* Determines how the request payload is processed.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayload)
*/
export interface RouteOptionsPayload {
/**
* @default allows parsing of the following mime types:
* * application/json
* * application/*+json
* * application/octet-stream
* * application/x-www-form-urlencoded
* * multipart/form-data
* * text/*
* A string or an array of strings with the allowed mime types for the endpoint. Use this settings to limit the set of allowed mime types. Note that allowing additional mime types not listed
* above will not enable them to be parsed, and if parse is true, the request will result in an error response.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadallow)
*/
allow?: string | string[] | undefined;
/**
* @default none.
* An object where each key is a content-encoding name and each value is an object with the desired decoder settings. Note that encoder settings are set in compression.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadcompression)
*/
compression?: { [P in keyof ContentDecoders]?: Parameters<ContentDecoders[P]>[0] } | undefined;
/**
* @default 'application/json'.
* The default content type if the 'Content-Type' request header is missing.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloaddefaultcontenttype)
*/
defaultContentType?: string | undefined;
/**
* @default 'error' (return a Bad Request (400) error response).
* A failAction value which determines how to handle payload parsing errors.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadfailaction)
*/
failAction?: Lifecycle.FailAction | undefined;
/**
* @default 1048576 (1MB).
* Limits the size of incoming payloads to the specified byte count. Allowing very large payloads may cause the server to run out of memory.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadmaxbytes)
*/
maxBytes?: number | undefined;
/**
* @default 1000
* Limits the number of parts allowed in multipart payloads.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadmaxparts)
*/
maxParts?: number;
/**
* @default none.
* Overrides payload processing for multipart requests. Value can be one of:
* * false - disable multipart processing.
* an object with the following required options:
* * output - same as the output option with an additional value option:
* * * annotated - wraps each multipart part in an object with the following keys: // TODO type this?
* * * * headers - the part headers.
* * * * filename - the part file name.
* * * * payload - the processed part payload.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadmultipart)
*/
multipart?: boolean | { output: PayloadOutput | 'annotated' };
/**
* @default 'data'.
* The processed payload format. The value must be one of:
* * 'data' - the incoming payload is read fully into memory. If parse is true, the payload is parsed (JSON, form-decoded, multipart) based on the 'Content-Type' header. If parse is false, a raw
* Buffer is returned.
* * 'stream' - the incoming payload is made available via a Stream.Readable interface. If the payload is 'multipart/form-data' and parse is true, field values are presented as text while files
* are provided as streams. File streams from a 'multipart/form-data' upload will also have a hapi property containing the filename and headers properties. Note that payload streams for multipart
* payloads are a synthetic interface created on top of the entire multipart content loaded into memory. To avoid loading large multipart payloads into memory, set parse to false and handle the
* multipart payload in the handler using a streaming parser (e.g. pez).
* * 'file' - the incoming payload is written to temporary file in the directory specified by the uploads settings. If the payload is 'multipart/form-data' and parse is true, field values are
* presented as text while files are saved to disk. Note that it is the sole responsibility of the application to clean up the files generated by the framework. This can be done by keeping track
* of which files are used (e.g. using the request.app object), and listening to the server 'response' event to perform cleanup.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadoutput)
*/
output?: PayloadOutput | undefined;
/**
* @default none.
* A mime type string overriding the 'Content-Type' header value received.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadoverride)
*/
override?: string | undefined;
/**
* @default true.
* Determines if the incoming payload is processed or presented raw. Available values:
* * true - if the request 'Content-Type' matches the allowed mime types set by allow (for the whole payload as well as parts), the payload is converted into an object when possible. If the
* format is unknown, a Bad Request (400) error response is sent. Any known content encoding is decoded.
* * false - the raw payload is returned unmodified.
* * 'gunzip' - the raw payload is returned unmodified after any known content encoding is decoded.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadparse)
*/
parse?: boolean | 'gunzip' | undefined;
/**
* @default to 'error'.
* Sets handling of incoming payload that may contain a prototype poisoning security attack.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadprotoaction)
*/
protoAction?: 'error' | 'remove' | 'ignore';
/**
* @default to 10000 (10 seconds).
* Payload reception timeout in milliseconds. Sets the maximum time allowed for the client to transmit the request payload (body) before giving up and responding with a Request Timeout (408)
* error response. Set to false to disable.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadtimeout)
*/
timeout?: false | number | undefined;
/**
* @default os.tmpdir().
* The directory used for writing file uploads.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloaduploads)
*/
uploads?: string | undefined;
}
/**
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
*/
export type RouteOptionsPreArray<Refs extends ReqRef = ReqRefDefaults> = RouteOptionsPreAllOptions<Refs>[];
/**
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
*/
export type RouteOptionsPreAllOptions<Refs extends ReqRef = ReqRefDefaults> = RouteOptionsPreObject<Refs> | RouteOptionsPreObject<Refs>[] | Lifecycle.Method<Refs>;
/**
* An object with:
* * method - a lifecycle method.
* * assign - key name used to assign the response of the method to in request.pre and request.preResponses.
* * failAction - A failAction value which determine what to do when a pre-handler method throws an error. If assign is specified and the failAction setting is not 'error', the error will be assigned.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
*/
export interface RouteOptionsPreObject<Refs extends ReqRef = ReqRefDefaults> {
/**
* a lifecycle method.
*/
method: Lifecycle.Method<Refs>;
/**
* key name used to assign the response of the method to in request.pre and request.preResponses.
*/
assign?: keyof MergeRefs<Refs>['Pres'] | undefined;
/**
* A failAction value which determine what to do when a pre-handler method throws an error. If assign is specified and the failAction setting is not 'error', the error will be assigned.
*/
failAction?: Lifecycle.FailAction | undefined;
}
export type ValidationObject = SchemaMap;
/**
* * true - any query parameter value allowed (no validation performed). false - no parameter value allowed.
* * a joi validation object.
* * a validation function using the signature async function(value, options) where:
* * * value - the request.* object containing the request parameters.
* * * options - options.
*/
export type RouteOptionsResponseSchema =
boolean
| ValidationObject
| Schema
| ((value: object | Buffer | string, options: ValidationOptions) => Promise<any>);
/**
* Processing rules for the outgoing response.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponse)
*/
export interface RouteOptionsResponse {
/**
* @default 204.
* The default HTTP status code when the payload is considered empty. Value can be 200 or 204. Note that a 200 status code is converted to a 204 only at the time of response transmission (the
* response status code will remain 200 throughout the request lifecycle unless manually set).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseemptystatuscode)
*/
emptyStatusCode?: 200 | 204 | undefined;
/**
* @default 'error' (return an Internal Server Error (500) error response).
* A failAction value which defines what to do when a response fails payload validation.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsefailaction)
*/
failAction?: Lifecycle.FailAction | undefined;
/**
* @default false.
* If true, applies the validation rule changes to the response payload.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsemodify)
*/
modify?: boolean | undefined;
/**
* @default none.
* [joi](https://github.com/hapijs/joi) options object pass to the validation function. Useful to set global options such as stripUnknown or abortEarly (the complete list is available here). If a
* custom validation function is defined via schema or status then options can an arbitrary object that will be passed to this function as the second argument.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseoptions)
*/
options?: ValidationOptions | undefined; // TODO needs validation
/**
* @default true.
* If false, payload range support is disabled.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseranges)
*/
ranges?: boolean | undefined;
/**
* @default 100 (all responses).
* The percent of response payloads validated (0 - 100). Set to 0 to disable all validation.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsesample)
*/
sample?: number | undefined;
/**
* @default true (no validation).
* The default response payload validation rules (for all non-error responses) expressed as one of:
* * true - any payload allowed (no validation).
* * false - no payload allowed.
* * a joi validation object. The options along with the request context ({ headers, params, query, payload, app, auth }) are passed to the validation function.
* * a validation function using the signature async function(value, options) where:
* * * value - the pending response payload.
* * * options - The options along with the request context ({ headers, params, query, payload, app, auth }).
* * * if the function returns a value and modify is true, the value is used as the new response. If the original response is an error, the return value is used to override the original error
* output.payload. If an error is thrown, the error is processed according to failAction.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseschema)
*/
schema?: RouteOptionsResponseSchema | undefined;
/**
* @default none.
* Validation schemas for specific HTTP status codes. Responses (excluding errors) not matching the listed status codes are validated using the default schema.
* status is set to an object where each key is a 3 digit HTTP status code and the value has the same definition as schema.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsestatus)
*/
status?: Record<string, RouteOptionsResponseSchema> | undefined;
/**
* The default HTTP status code used to set a response error when the request is closed or aborted before the
* response is fully transmitted.
* Value can be any integer greater or equal to 400.
* The default value 499 is based on the non-standard nginx "CLIENT CLOSED REQUEST" error.
* The value is only used for logging as the request has already ended.
* @default 499
*/
disconnectStatusCode?: number | undefined;
}
/**
* @see https://www.w3.org/TR/referrer-policy/
*/
export type ReferrerPolicy = '' | 'no-referrer' | 'no-referrer-when-downgrade' | 'unsafe-url' |
'same-origin' | 'origin' | 'strict-origin' | 'origin-when-cross-origin' | 'strict-origin-when-cross-origin';
/**
* @default false (security headers disabled).
* Sets common security headers. To enable, set security to true or to an object with the following options:
* * hsts - controls the 'Strict-Transport-Security' header, where:
* * * true - the header will be set to max-age=15768000. This is the default value.
* * * a number - the maxAge parameter will be set to the provided value.
* * * an object with the following fields:
* * * * maxAge - the max-age portion of the header, as a number. Default is 15768000.
* * * * includeSubDomains - a boolean specifying whether to add the includeSubDomains flag to the header.
* * * * preload - a boolean specifying whether to add the 'preload' flag (used to submit domains inclusion in Chrome's HTTP Strict Transport Security (HSTS) preload list) to the header.
* * xframe - controls the 'X-Frame-Options' header, where:
* * * true - the header will be set to 'DENY'. This is the default value.
* * * 'deny' - the headers will be set to 'DENY'.
* * * 'sameorigin' - the headers will be set to 'SAMEORIGIN'.
* * * an object for specifying the 'allow-from' rule, where:
* * * * rule - one of:
* * * * * 'deny'
* * * * * 'sameorigin'
* * * * * 'allow-from'
* * * * source - when rule is 'allow-from' this is used to form the rest of the header, otherwise this field is ignored. If rule is 'allow-from' but source is unset, the rule will be automatically
* changed to 'sameorigin'.
* * xss - controls the 'X-XSS-Protection' header, where:
* * * 'disabled' - the header will be set to '0'. This is the default value.
* * * 'enabled' - the header will be set to '1; mode=block'.
* * * false - the header will be omitted
* * noOpen - boolean controlling the 'X-Download-Options' header for Internet Explorer, preventing downloads from executing in your context. Defaults to true setting the header to 'noopen'.
* * noSniff - boolean controlling the 'X-Content-Type-Options' header. Defaults to true setting the header to its only and default option, 'nosniff'.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionssecurity)
*/
export interface RouteOptionsSecureObject {
/**
* hsts - controls the 'Strict-Transport-Security' header
*/
hsts?: boolean | number | {
/**
* the max-age portion of the header, as a number. Default is 15768000.
*/
maxAge?: number;
/**
* a boolean specifying whether to add the includeSubDomains flag to the header.
*/
includeSubDomains?: boolean;
/**
* a boolean specifying whether to add the 'preload' flag (used to submit domains inclusion in Chrome's HTTP Strict Transport Security (HSTS) preload list) to the header.
*/
preload?: boolean;
} | undefined;
/**
* controls the 'X-Frame-Options' header
*/
xframe?: true | 'deny' | 'sameorigin' | {
/**
* an object for specifying the 'allow-from' rule,
*/
rule: 'deny' | 'sameorigin' | 'allow-from';
/**
* when rule is 'allow-from' this is used to form the rest of the header, otherwise this field is ignored. If rule is 'allow-from' but source is unset, the rule will be automatically changed
* to 'sameorigin'.
*/
source: string;
} | undefined;
/**
* controls the 'X-XSS-Protection' header, where:
* * 'disabled' - the header will be set to '0'. This is the default value.
* * 'enabled' - the header will be set to '1; mode=block'.
* * false - the header will be omitted
*/
xss?: 'disabled' | 'enabled' | false | undefined;
/**
* boolean controlling the 'X-Download-Options' header for Internet Explorer, preventing downloads from executing in your context. Defaults to true setting the header to 'noopen'.
*/
noOpen?: boolean | undefined;
/**
* boolean controlling the 'X-Content-Type-Options' header. Defaults to true setting the header to its only and default option, 'nosniff'.
*/
noSniff?: boolean | undefined;
/**
* Controls the `Referrer-Policy` header, which has the following possible values.
* @default false Header will not be send.
*/
referrer?: false | ReferrerPolicy | undefined;
}
export type RouteOptionsSecure = boolean | RouteOptionsSecureObject;
/**
* @default { headers: true, params: true, query: true, payload: true, failAction: 'error' }.
* Request input validation rules for various request components.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidate)
*/
export interface RouteOptionsValidate {
/**
* @default none.
* An optional object with error fields copied into every validation error response.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidateerrorfields)
*/
errorFields?: object | undefined;
/**
* @default 'error' (return a Bad Request (400) error response).
* A failAction value which determines how to handle failed validations. When set to a function, the err argument includes the type of validation error under err.output.payload.validation.source.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidatefailaction)
*/
failAction?: Lifecycle.FailAction | undefined;
/**
* Validation rules for incoming request headers:
* * If a value is returned, the value is used as the new request.headers value and the original value is stored in request.orig.headers. Otherwise, the headers are left unchanged. If an error
* is thrown, the error is handled according to failAction. Note that all header field names must be in lowercase to match the headers normalized by node.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidateheaders)
* @default true
*/
headers?: RouteOptionsResponseSchema | undefined;
/**
* An options object passed to the joi rules or the custom validation methods. Used for setting global options such as stripUnknown or abortEarly (the complete list is available here).
* If a custom validation function (see headers, params, query, or payload above) is defined then options can an arbitrary object that will be passed to this function as the second parameter.
* The values of the other inputs (i.e. headers, query, params, payload, app, and auth) are added to the options object under the validation context (accessible in rules as
* Joi.ref('$query.key')).
* Note that validation is performed in order (i.e. headers, params, query, and payload) and if type casting is used (e.g. converting a string to a number), the value of inputs not yet validated
* will reflect the raw, unvalidated and unmodified values. If the validation rules for headers, params, query, and payload are defined at both the server routes level and at the route level, the
* individual route settings override the routes defaults (the rules are not merged).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidateparams)
* @default true
*/
options?: ValidationOptions | object | undefined;
/**
* Validation rules for incoming request path parameters, after matching the path against the route, extracting any parameters, and storing them in request.params, where:
* * true - any path parameter value allowed (no validation performed).
* * a joi validation object.
* * a validation function using the signature async function(value, options) where:
* * * value - the request.params object containing the request path parameters.
* * * options - options.
* if a value is returned, the value is used as the new request.params value and the original value is stored in request.orig.params. Otherwise, the path parameters are left unchanged. If an
* error is thrown, the error is handled according to failAction. Note that failing to match the validation rules to the route path parameters definition will cause all requests to fail.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidateparams)
* @default true
*/
params?: RouteOptionsResponseSchema | undefined;
/**
* Validation rules for incoming request payload (request body), where:
* * If a value is returned, the value is used as the new request.payload value and the original value is stored in request.orig.payload. Otherwise, the payload is left unchanged. If an error is
* thrown, the error is handled according to failAction. Note that validating large payloads and modifying them will cause memory duplication of the payload (since the original is kept), as well
* as the significant performance cost of validating large amounts of data.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidatepayload)
* @default true
*/
payload?: RouteOptionsResponseSchema | undefined;
/**
* Validation rules for incoming request URI query component (the key-value part of the URI between '?' and '#'). The query is parsed into its individual key-value pairs, decoded, and stored in
* request.query prior to validation. Where:
* * If a value is returned, the value is used as the new request.query value and the original value is stored in request.orig.query. Otherwise, the query parameters are left unchanged.
* If an error
* is thrown, the error is handled according to failAction. Note that changes to the query parameters will not be reflected in request.url.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidatequery)
* @default true
*/
query?: RouteOptionsResponseSchema | undefined;
/**
* Validation rules for incoming cookies.
* The cookie header is parsed and decoded into the request.state prior to validation.
* @default true
*/
state?: RouteOptionsResponseSchema | undefined;
}
export interface CommonRouteProperties<Refs extends ReqRef = ReqRefDefaults> {
/**
* Application-specific route configuration state. Should not be used by plugins which should use options.plugins[name] instead.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsapp)
*/
app?: MergeRefs<Refs>['RouteApp'] | undefined;
/**
* @default null.
* An object passed back to the provided handler (via this) when called. Ignored if the method is an arrow function.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsbind)
*/
bind?: MergeRefs<Refs>['Bind'] | undefined;
/**
* @default { privacy: 'default', statuses: [200], otherwise: 'no-cache' }.
* If the route method is 'GET', the route can be configured to include HTTP caching directives in the response. Caching can be customized using an object with the following options:
* privacy - determines the privacy flag included in client-side caching using the 'Cache-Control' header. Values are:
* * * 'default' - no privacy flag.
* * * 'public' - mark the response as suitable for public caching.
* * * 'private' - mark the response as suitable only for private caching.
* * expiresIn - relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt.
* * expiresAt - time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire. Cannot be used together with expiresIn.
* * statuses - an array of HTTP response status code numbers (e.g. 200) which are allowed to include a valid caching directive.
* * otherwise - a string with the value of the 'Cache-Control' header when caching is disabled.
* The default Cache-Control: no-cache header can be disabled by setting cache to false.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscache)
*/
cache?: false | RouteOptionsCache | undefined;
/**
* An object where each key is a content-encoding name and each value is an object with the desired encoder settings. Note that decoder settings are set in compression.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscompression)
*/
compression?: { [P in keyof ContentEncoders]?: Parameters<ContentEncoders[P]>[0] } | undefined;
/**
* @default false (no CORS headers).
* The Cross-Origin Resource Sharing protocol allows browsers to make cross-origin API calls. CORS is required by web applications running inside a browser which are loaded from a different
* domain than the API server. To enable, set cors to true, or to an object with the following options:
* * origin - an array of allowed origin servers strings ('Access-Control-Allow-Origin'). The array can contain any combination of fully qualified origins along with origin strings containing a
* wildcard '*' character, or a single '*' origin string. If set to 'ignore', any incoming Origin header is ignored (present or not) and the 'Access-Control-Allow-Origin' header is set to '*'.
* Defaults to any origin ['*'].
* * maxAge - number of seconds the browser should cache the CORS response ('Access-Control-Max-Age'). The greater the value, the longer it will take before the browser checks for changes in
* policy. Defaults to 86400 (one day).
* * headers - a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to ['Accept', 'Authorization', 'Content-Type', 'If-None-Match'].
* * additionalHeaders - a strings array of additional headers to headers. Use this to keep the default headers in place.
* * exposedHeaders - a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to ['WWW-Authenticate', 'Server-Authorization'].
* * additionalExposedHeaders - a strings array of additional headers to exposedHeaders. Use this to keep the default headers in place.
* * credentials - if true, allows user credentials to be sent ('Access-Control-Allow-Credentials'). Defaults to false.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscors)
*/
cors?: boolean | RouteOptionsCors | undefined;
/**
* @default none.
* Route description used for generating documentation (string).
* This setting is not available when setting server route defaults using server.options.routes.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsdescription)
*/
description?: string | undefined;
/**
* @default none.
* Route-level request extension points by setting the option to an object with a key for each of the desired extension points ('onRequest' is not allowed), and the value is the same as the
* server.ext(events) event argument.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsext)
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle)
*/
ext?: {
[key in RouteRequestExtType]?: RouteExtObject | RouteExtObject[] | undefined;
} | undefined;
/**
* @default { relativeTo: '.' }.
* Defines the behavior for accessing files:
* * relativeTo - determines the folder relative paths are resolved against.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsfiles)
*/
files?: {
relativeTo: string;
} | undefined;
/**
* @default none.
* The route handler function performs the main business logic of the route and sets the response. handler can be assigned:
* * a lifecycle method.
* * an object with a single property using the name of a handler type registered with the server.handler() method. The matching property value is passed as options to the registered handler
* generator. Note: handlers using a fat arrow style function cannot be bound to any bind property. Instead, the bound context is available under h.context.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionshandler)
*/
handler?: Lifecycle.Method<Refs> | object | undefined;
/**
* @default none.
* An optional unique identifier used to look up the route using server.lookup(). Cannot be assigned to routes added with an array of methods.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsid)
*/
id?: string | undefined;
/**
* @default false.
* If true, the route cannot be accessed through the HTTP listener but only through the server.inject() interface with the allowInternals option set to true. Used for internal routes that should
* not be accessible to the outside world.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsisinternal)
*/
isInternal?: boolean | undefined;
/**
* @default none.
* Optional arguments passed to JSON.stringify() when converting an object or error response to a string payload or escaping it after stringification. Supports the following:
* * replacer - the replacer function or array. Defaults to no action.
* * space - number of spaces to indent nested object keys. Defaults to no indentation.
* * suffix - string suffix added after conversion to JSON string. Defaults to no suffix.
* * escape - calls Hoek.jsonEscape() after conversion to JSON string. Defaults to false.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsjson)
*/
json?: Json.StringifyArguments | undefined;
/**
* @default { collect: false }.
* Request logging options:
* collect - if true, request-level logs (both internal and application) are collected and accessible via request.logs.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionslog)
*/
log?: {
collect: boolean;
} | undefined;
/**
* @default none.
* Route notes used for generating documentation (string or array of strings).
* This setting is not available when setting server route defaults using server.options.routes.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsnotes)
*/
notes?: string | string[] | undefined;
/**
* Determines how the request payload is processed.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayload)
*/
payload?: RouteOptionsPayload | undefined;
/**
* @default {}.
* Plugin-specific configuration. plugins is an object where each key is a plugin name and the value is the plugin configuration.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsplugins)
*/
plugins?: PluginSpecificConfiguration | undefined;
/**
* @default none.
* The pre option allows defining methods for performing actions before the handler is called. These methods allow breaking the handler logic into smaller, reusable components that can be shared
* across routes, as well as provide a cleaner error handling of prerequisite operations (e.g. load required reference data from a database). pre is assigned an ordered array of methods which
* are called serially in order. If the pre array contains another array of methods as one of its elements, those methods are called in parallel. Note that during parallel execution, if any of
* the methods error, return a takeover response, or abort signal, the other parallel methods will continue to execute but will be ignored once completed. pre can be assigned a mixed array of:
* * an array containing the elements listed below, which are executed in parallel.
* * an object with:
* * * method - a lifecycle method.
* * * assign - key name used to assign the response of the method to in request.pre and request.preResponses.
* * * failAction - A failAction value which determine what to do when a pre-handler method throws an error. If assign is specified and the failAction setting is not 'error', the error will be
* assigned.
* * a method function - same as including an object with a single method key.
* Note that pre-handler methods do not behave the same way other lifecycle methods do when a value is returned. Instead of the return value becoming the new response payload, the value is used
* to assign the corresponding request.pre and request.preResponses properties. Otherwise, the handling of errors, takeover response response, or abort signal behave the same as any other
* lifecycle methods.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
*/
pre?: RouteOptionsPreArray<Refs> | undefined;
/**
* Processing rules for the outgoing response.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponse)
*/
response?: RouteOptionsResponse | undefined;
/**
* @default false (security headers disabled).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionssecurity)
*/
security?: RouteOptionsSecure | undefined;
/**
* @default { parse: true, failAction: 'error' }.
* HTTP state management (cookies) allows the server to store information on the client which is sent back to the server with every request (as defined in RFC 6265). state supports the following
* options: parse - determines if incoming 'Cookie' headers are parsed and stored in the request.state object. failAction - A failAction value which determines how to handle cookie parsing
* errors. Defaults to 'error' (return a Bad Request (400) error response).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsstate)
*/
state?: {
parse?: boolean | undefined;
failAction?: Lifecycle.FailAction | undefined;
} | undefined;
/**
* @default none.
* Route tags used for generating documentation (array of strings).
* This setting is not available when setting server route defaults using server.options.routes.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionstags)
*/
tags?: string[] | undefined;
/**
* @default { server: false }.
* Timeouts for processing durations.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionstimeout)
*/
timeout?: {
/**
* Response timeout in milliseconds. Sets the maximum time allowed for the server to respond to an incoming request before giving up and responding with a Service Unavailable (503) error
* response.
*/
server?: boolean | number | undefined;
/**
* @default none (use node default of 2 minutes).
* By default, node sockets automatically timeout after 2 minutes. Use this option to override this behavior. Set to false to disable socket timeouts.
*/
socket?: boolean | number | undefined;
} | undefined;
/**
* @default { headers: true, params: true, query: true, payload: true, failAction: 'error' }.
* Request input validation rules for various request components.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidate)
*/
validate?: RouteOptionsValidate | undefined;
}
export interface AccessScopes {
forbidden?: string[] | undefined;
required?: string[] | undefined;
selection?: string[] | undefined;
}
export interface AccessSetting {
entity?: AccessEntity | undefined;
scope: AccessScopes | false;
}
export interface AuthSettings {
strategies: string[];
mode: AuthMode;
access?: AccessSetting[] | undefined;
}
export interface RouteSettings<Refs extends ReqRef = ReqRefDefaults> extends CommonRouteProperties<Refs> {
auth?: AuthSettings | undefined;
}
/**
* Each route can be customized to change the default behavior of the request lifecycle.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#route-options)
*/
export interface RouteOptions<Refs extends ReqRef = ReqRefDefaults> extends CommonRouteProperties<Refs> {
/**
* Route authentication configuration. Value can be:
* false to disable authentication if a default strategy is set.
* a string with the name of an authentication strategy registered with server.auth.strategy(). The strategy will be set to 'required' mode.
* an authentication configuration object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsapp)
*/
auth?: false | string | RouteOptionsAccess | undefined;
}
export interface HandlerDecorations {}
export interface RouteRules {}
export interface RulesInfo {
method: string;
path: string;
vhost: string;
}
export interface RulesOptions<Refs extends ReqRef = ReqRefDefaults> {
validate: {
schema?: ObjectSchema<MergeRefs<Refs>['Rules']> | Record<keyof MergeRefs<Refs>['Rules'], Schema> | undefined;
options?: ValidationOptions | undefined;
};
}
export interface RulesProcessor<Refs extends ReqRef = ReqRefDefaults> {
(rules: MergeRefs<Refs>['Rules'] | null, info: RulesInfo): Partial<RouteOptions<Refs>> | null;
}
type RouteDefMethods = Exclude<HTTP_METHODS | Lowercase<HTTP_METHODS>, 'HEAD' | 'head'>;
/**
* A route configuration object or an array of configuration objects where each object contains:
* * path - (required) the absolute path used to match incoming requests (must begin with '/'). Incoming requests are compared to the configured paths based on the server's router configuration. The
* path can include named parameters enclosed in {} which will be matched against literal values in the request as described in Path parameters.
* * method - (required) the HTTP method. Typically one of 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', or 'OPTIONS'. Any HTTP method is allowed, except for 'HEAD'. Use '*' to match against any HTTP
* method (only when an exact match was not found, and any match with a specific method will be given a higher priority over a wildcard match). Can be assigned an array of methods which has the same
* result as adding the same route with different methods manually.
* * vhost - (optional) a domain string or an array of domain strings for limiting the route to only requests with a matching host header field. Matching is done against the hostname part of the
* header only (excluding the port). Defaults to all hosts.
* * handler - (required when handler is not set) the route handler function called to generate the response after successful authentication and validation.
* * options - additional route options. The options value can be an object or a function that returns an object using the signature function(server) where server is the server the route is being
* added to and this is bound to the current realm's bind option.
* * rules - route custom rules object. The object is passed to each rules processor registered with server.rules(). Cannot be used if route.options.rules is defined.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrouteroute)
*/
export interface ServerRoute<Refs extends ReqRef = ReqRefDefaults> {
/**
* (required) the absolute path used to match incoming requests (must begin with '/'). Incoming requests are compared to the configured paths based on the server's router configuration. The path
* can include named parameters enclosed in {} which will be matched against literal values in the request as described in Path parameters. For context [See
* docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrouteroute) For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#path-parameters)
*/
path: string;
/**
* (required) the HTTP method. Typically one of 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', or 'OPTIONS'. Any HTTP method is allowed, except for 'HEAD'. Use '*' to match against any HTTP method
* (only when an exact match was not found, and any match with a specific method will be given a higher priority over a wildcard match). Can be assigned an array of methods which has the same
* result as adding the same route with different methods manually.
*/
method: RouteDefMethods | RouteDefMethods[] | '*';
/**
* (optional) a domain string or an array of domain strings for limiting the route to only requests with a matching host header field. Matching is done against the hostname part of the header
* only (excluding the port). Defaults to all hosts.
*/
vhost?: string | string[] | undefined;
/**
* (required when handler is not set) the route handler function called to generate the response after successful authentication and validation.
*/
handler?: Lifecycle.Method<Refs> | HandlerDecorations | undefined;
/**
* additional route options. The options value can be an object or a function that returns an object using the signature function(server) where server is the server the route is being added to
* and this is bound to the current realm's bind option.
*/
options?: RouteOptions<Refs> | ((server: Server) => RouteOptions<Refs>) | undefined;
/**
* route custom rules object. The object is passed to each rules processor registered with server.rules(). Cannot be used if route.options.rules is defined.
*/
rules?: MergeRefs<Refs>['Rules'] | undefined;
}

201
node_modules/@hapi/hapi/lib/types/server/auth.d.ts generated vendored Normal file
View File

@@ -0,0 +1,201 @@
import { Server } from './server';
import {
MergeType,
ReqRef,
ReqRefDefaults,
MergeRefs,
Request,
RequestAuth} from '../request';
import { ResponseToolkit, AuthenticationData } from '../response';
import { RouteOptionsAccess, InternalRouteOptionType, RouteOptionTypes} from '../route';
import { Lifecycle } from '../utils';
/**
* The scheme options argument passed to server.auth.strategy() when instantiation a strategy.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthschemename-scheme)
*/
export type ServerAuthSchemeOptions = object;
/**
* the method implementing the scheme with signature function(server, options) where:
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthschemename-scheme)
* @param server - a reference to the server object the scheme is added to.
* @param options - (optional) the scheme options argument passed to server.auth.strategy() when instantiation a strategy.
*/
export type ServerAuthScheme<
// tslint:disable-next-line no-unnecessary-generics
Options extends ServerAuthSchemeOptions = ServerAuthSchemeOptions,
// tslint:disable-next-line no-unnecessary-generics
Refs extends ReqRef = ReqRefDefaults
> = (server: Server, options?: Options) => ServerAuthSchemeObject<Refs>;
export interface ServerAuthSchemeObjectApi {}
/**
* The scheme method must return an object with the following
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#authentication-scheme)
*/
export interface ServerAuthSchemeObject<Refs extends ReqRef = ReqRefDefaults> {
/**
* optional object which is exposed via the [server.auth.api](https://github.com/hapijs/hapi/blob/master/API.md#server.auth.api) object.
*/
api?: MergeRefs<Refs>['AuthApi'] | undefined;
/**
* A lifecycle method function called for each incoming request configured with the authentication scheme. The
* method is provided with two special toolkit methods for returning an authenticated or an unauthenticated result:
* * h.authenticated() - indicate request authenticated successfully.
* * h.unauthenticated() - indicate request failed to authenticate.
* @param request the request object.
* @param h the ResponseToolkit
* @return the Lifecycle.ReturnValue
*/
authenticate(request: Request<Refs>, h: ResponseToolkit<Refs>): Lifecycle.ReturnValue<Refs>;
/**
* A lifecycle method to authenticate the request payload.
* When the scheme payload() method returns an error with a message, it means payload validation failed due to bad
* payload. If the error has no message but includes a scheme name (e.g. Boom.unauthorized(null, 'Custom')),
* authentication may still be successful if the route auth.payload configuration is set to 'optional'.
* @param request the request object.
* @param h the ResponseToolkit
* @return the Lifecycle.ReturnValue
*/
payload?(request: Request<Refs>, h: ResponseToolkit<Refs>): Lifecycle.ReturnValue<Refs>;
/**
* A lifecycle method to decorate the response with authentication headers before the response headers or payload is written.
* @param request the request object.
* @param h the ResponseToolkit
* @return the Lifecycle.ReturnValue
*/
response?(request: Request<Refs>, h: ResponseToolkit<Refs>): Lifecycle.ReturnValue<Refs>;
/**
* a method used to verify the authentication credentials provided
* are still valid (e.g. not expired or revoked after the initial authentication).
* the method throws an `Error` when the credentials passed are no longer valid (e.g. expired or
* revoked). Note that the method does not have access to the original request, only to the
* credentials and artifacts produced by the `authenticate()` method.
*/
verify?(
auth: RequestAuth<
MergeRefs<Refs>['AuthUser'],
MergeRefs<Refs>['AuthApp'],
MergeRefs<Refs>['AuthCredentialsExtra'],
MergeRefs<Refs>['AuthArtifactsExtra']
>
): Promise<void>;
/**
* An object with the following keys:
* * payload
*/
options?: {
/**
* if true, requires payload validation as part of the scheme and forbids routes from disabling payload auth validation. Defaults to false.
*/
payload?: boolean | undefined;
} | undefined;
}
/**
* An authentication configuration object using the same format as the route auth handler options.
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthdefaultoptions)
*/
export interface ServerAuthConfig extends RouteOptionsAccess {
}
export interface ServerAuth {
/**
* An object where each key is an authentication strategy name and the value is the exposed strategy API.
* Available only when the authentication scheme exposes an API by returning an api key in the object
* returned from its implementation function.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthapi)
*/
api: Record<string, ServerAuthSchemeObjectApi>;
/**
* Contains the default authentication configuration is a default strategy was set via
* [server.auth.default()](https://github.com/hapijs/hapi/blob/master/API.md#server.auth.default()).
*/
readonly settings: {
default: ServerAuthConfig;
};
/**
* Sets a default strategy which is applied to every route where:
* @param options - one of:
* * a string with the default strategy name
* * an authentication configuration object using the same format as the route auth handler options.
* @return void.
* The default does not apply when a route config specifies auth as false, or has an authentication strategy
* configured (contains the strategy or strategies authentication settings). Otherwise, the route authentication
* config is applied to the defaults.
* Note that if the route has authentication configured, the default only applies at the time of adding the route,
* not at runtime. This means that calling server.auth.default() after adding a route with some authentication
* config will have no impact on the routes added prior. However, the default will apply to routes added
* before server.auth.default() is called if those routes lack any authentication config.
* The default auth strategy configuration can be accessed via server.auth.settings.default. To obtain the active
* authentication configuration of a route, use server.auth.lookup(request.route).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthdefaultoptions)
*/
default(options: string | ServerAuthConfig): void;
/**
* Registers an authentication scheme where:
* @param name the scheme name.
* @param scheme - the method implementing the scheme with signature function(server, options) where:
* * server - a reference to the server object the scheme is added to.
* * options - (optional) the scheme options argument passed to server.auth.strategy() when instantiation a strategy.
* @return void.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthschemename-scheme)
*/
scheme <
Refs extends ReqRef = ReqRefDefaults,
Options extends object = {}
// tslint:disable-next-line no-unnecessary-generics
>(name: string, scheme: ServerAuthScheme<Options, Refs>): void;
/**
* Registers an authentication strategy where:
* @param name - the strategy name.
* @param scheme - the scheme name (must be previously registered using server.auth.scheme()).
* @param options - scheme options based on the scheme requirements.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthstrategyname-scheme-options)
*/
strategy(
name: MergeType<InternalRouteOptionType, RouteOptionTypes>['Strategy'],
scheme: string,
options?: object
): void;
/**
* Tests a request against an authentication strategy where:
* @param strategy - the strategy name registered with server.auth.strategy().
* @param request - the request object.
* @return an object containing the authentication credentials and artifacts if authentication was successful, otherwise throws an error.
* Note that the test() method does not take into account the route authentication configuration. It also does not
* perform payload authentication. It is limited to the basic strategy authentication execution. It does not
* include verifying scope, entity, or other route properties.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverauthteststrategy-request)
*/
test(strategy: string, request: Request): Promise<AuthenticationData>;
/**
* Verify a request's authentication credentials against an authentication strategy.
* Returns nothing if verification was successful, otherwise throws an error.
*
* Note that the `verify()` method does not take into account the route authentication configuration
* or any other information from the request other than the `request.auth` object. It also does not
* perform payload authentication. It is limited to verifying that the previously valid credentials
* are still valid (e.g. have not been revoked or expired). It does not include verifying scope,
* entity, or other route properties.
*/
// tslint:disable-next-line no-unnecessary-generics
verify <Refs extends ReqRef = ReqRefDefaults>(request: Request<Refs>): Promise<void>;
}

85
node_modules/@hapi/hapi/lib/types/server/cache.d.ts generated vendored Normal file
View File

@@ -0,0 +1,85 @@
import { PolicyOptionVariants, Policy, ClientApi, ClientOptions, EnginePrototype, PolicyOptions } from '@hapi/catbox';
export type CachePolicyOptions<T> = PolicyOptionVariants<T> & {
/**
* @default '_default'
*/
cache?: string | undefined;
segment?: string | undefined;
};
/**
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
*/
export interface ServerCache {
/**
* Provisions a cache segment within the server cache facility where:
* @param options - [catbox policy](https://github.com/hapijs/catbox#policy) configuration where:
* * expiresIn - relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt.
* * expiresAt - time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records expire. Uses local time. Cannot be used together with expiresIn.
* * generateFunc - a function used to generate a new cache item if one is not found in the cache when calling get(). The method's signature is async function(id, flags) where:
* - `id` - the `id` string or object provided to the `get()` method.
* - `flags` - an object used to pass back additional flags to the cache where:
* - `ttl` - the cache ttl value in milliseconds. Set to `0` to skip storing in the cache. Defaults to the cache global policy.
* * staleIn - number of milliseconds to mark an item stored in cache as stale and attempt to regenerate it when generateFunc is provided. Must be less than expiresIn.
* * staleTimeout - number of milliseconds to wait before checking if an item is stale.
* * generateTimeout - number of milliseconds to wait before returning a timeout error when the generateFunc function takes too long to return a value. When the value is eventually returned, it
* is stored in the cache for future requests. Required if generateFunc is present. Set to false to disable timeouts which may cause all get() requests to get stuck forever.
* * generateOnReadError - if false, an upstream cache read error will stop the cache.get() method from calling the generate function and will instead pass back the cache error. Defaults to true.
* * generateIgnoreWriteError - if false, an upstream cache write error when calling cache.get() will be passed back with the generated value when calling. Defaults to true.
* * dropOnError - if true, an error or timeout in the generateFunc causes the stale value to be evicted from the cache. Defaults to true.
* * pendingGenerateTimeout - number of milliseconds while generateFunc call is in progress for a given id, before a subsequent generateFunc call is allowed. Defaults to 0 (no blocking of
* concurrent generateFunc calls beyond staleTimeout).
* * cache - the cache name configured in server.cache. Defaults to the default cache.
* * segment - string segment name, used to isolate cached items within the cache partition. When called within a plugin, defaults to '!name' where 'name' is the plugin name. When called within a
* server method, defaults to '#name' where 'name' is the server method name. Required when called outside of a plugin.
* * shared - if true, allows multiple cache provisions to share the same segment. Default to false.
* @return Catbox Policy.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
*/
<T, O extends CachePolicyOptions<T> = CachePolicyOptions<T>>(options: O): Policy<T, O>;
/**
* Provisions a server cache as described in server.cache where:
* @param options - same as the server cache configuration options.
* @return Return value: none.
* Note that if the server has been initialized or started, the cache will be automatically started to match the state of any other provisioned server cache.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-servercacheprovisionoptions)
*/
provision(options: ServerOptionsCache): Promise<void>;
}
export type CacheProvider<T extends ClientOptions = ClientOptions> = EnginePrototype<any> | {
constructor: EnginePrototype<any>;
options?: T | undefined;
};
/**
* hapi uses catbox for its cache implementation which includes support for common storage solutions (e.g. Redis,
* MongoDB, Memcached, Riak, among others). Caching is only utilized if methods and plugins explicitly store their state in the cache.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-cache)
*/
export interface ServerOptionsCache extends PolicyOptions<any> {
/** catbox engine object. */
engine?: ClientApi<any> | undefined;
/**
* a class or a prototype function
*/
provider?: CacheProvider | undefined;
/**
* an identifier used later when provisioning or configuring caching for server methods or plugins. Each cache name must be unique. A single item may omit the name option which defines
* the default cache. If every cache includes a name, a default memory cache is provisioned as well.
*/
name?: string | undefined;
/** if true, allows multiple cache users to share the same segment (e.g. multiple methods using the same cache storage container). Default to false. */
shared?: boolean | undefined;
/** (optional) string used to isolate cached data. Defaults to 'hapi-cache'. */
partition?: string | undefined;
/** other options passed to the catbox strategy used. Other options are only passed to catbox when engine above is a class or function and ignored if engine is a catbox engine object). */
[s: string]: any;
}

19
node_modules/@hapi/hapi/lib/types/server/encoders.d.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
import { createDeflate, createGunzip, createGzip, createInflate } from 'zlib';
/**
* Available [content encoders](https://github.com/hapijs/hapi/blob/master/API.md#-serverencoderencoding-encoder).
*/
export interface ContentEncoders {
deflate: typeof createDeflate;
gzip: typeof createGzip;
}
/**
* Available [content decoders](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecoderencoding-decoder).
*/
export interface ContentDecoders {
deflate: typeof createInflate;
gzip: typeof createGunzip;
}

217
node_modules/@hapi/hapi/lib/types/server/events.d.ts generated vendored Normal file
View File

@@ -0,0 +1,217 @@
import { Podium } from '@hapi/podium';
import { Request, RequestRoute } from '../request';
/**
* an event name string.
* an event options object.
* a podium emitter object.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventevents)
*/
export type ServerEventsApplication = string | ServerEventsApplicationObject | Podium;
/**
* Object that it will be used in Event
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventevents)
*/
export interface ServerEventsApplicationObject {
/** the event name string (required). */
name: string;
/** a string or array of strings specifying the event channels available. Defaults to no channel restrictions (event updates can specify a channel or not). */
channels?: string | string[] | undefined;
/**
* if true, the data object passed to server.events.emit() is cloned before it is passed to the listeners (unless an override specified by each listener). Defaults to false (data is passed as-is).
*/
clone?: boolean | undefined;
/**
* if true, the data object passed to server.event.emit() must be an array and the listener method is called with each array element passed as a separate argument (unless an override specified
* by each listener). This should only be used when the emitted data structure is known and predictable. Defaults to false (data is emitted as a single argument regardless of its type).
*/
spread?: boolean | undefined;
/**
* if true and the criteria object passed to server.event.emit() includes tags, the tags are mapped to an object (where each tag string is the key and the value is true) which is appended to
* the arguments list at the end. A configuration override can be set by each listener. Defaults to false.
*/
tags?: boolean | undefined;
/**
* if true, the same event name can be registered multiple times where the second registration is ignored. Note that if the registration config is changed between registrations, only the first
* configuration is used. Defaults to false (a duplicate registration will throw an error).
*/
shared?: boolean | undefined;
}
/**
* A criteria object with the following optional keys (unless noted otherwise):
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventsoncriteria-listener)
*
* The type parameter T is the type of the name of the event.
*/
export interface ServerEventCriteria<T> {
/** (required) the event name string. */
name: T;
/**
* a string or array of strings specifying the event channels to subscribe to. If the event registration specified a list of allowed channels, the channels array must match the allowed
* channels. If channels are specified, event updates without any channel designation will not be included in the subscription. Defaults to no channels filter.
*/
channels?: string | string[] | undefined;
/** if true, the data object passed to server.event.emit() is cloned before it is passed to the listener method. Defaults to the event registration option (which defaults to false). */
clone?: boolean | undefined;
/**
* a positive integer indicating the number of times the listener can be called after which the subscription is automatically removed. A count of 1 is the same as calling server.events.once().
* Defaults to no limit.
*/
count?: number | undefined;
/**
* filter - the event tags (if present) to subscribe to which can be one of:
* * a tag string.
* * an array of tag strings.
* * an object with the following:
* * * tags - a tag string or array of tag strings.
* * * all - if true, all tags must be present for the event update to match the subscription. Defaults to false (at least one matching tag).
*/
filter?: string | string[] | { tags: string | string[] | undefined, all?: boolean | undefined } | undefined;
/**
* if true, and the data object passed to server.event.emit() is an array, the listener method is called with each array element passed as a separate argument. This should only be used
* when the emitted data structure is known and predictable. Defaults to the event registration option (which defaults to false).
*/
spread?: boolean | undefined;
/**
* if true and the criteria object passed to server.event.emit() includes tags, the tags are mapped to an object (where each tag string is the key and the value is true) which is appended
* to the arguments list at the end. Defaults to the event registration option (which defaults to false).
*/
tags?: boolean | undefined;
}
export interface LogEvent<T = object | string> {
/** the event timestamp. */
timestamp: string;
/** an array of tags identifying the event (e.g. ['error', 'http']) */
tags: string[];
/** set to 'internal' for internally generated events, otherwise 'app' for events generated by server.log() */
channel: 'internal' | 'app';
/** the request identifier. */
request: string;
/** event-specific information. Available when event data was provided and is not an error. Errors are passed via error. */
data: T;
/** the error object related to the event if applicable. Cannot appear together with data */
error: object;
}
export interface RequestEvent {
/** the event timestamp. */
timestamp: string;
/** an array of tags identifying the event (e.g. ['error', 'http']) */
tags: string[];
/** set to 'internal' for internally generated events, otherwise 'app' for events generated by server.log() */
channel: 'internal' | 'app' | 'error';
/** event-specific information. Available when event data was provided and is not an error. Errors are passed via error. */
data: object | string;
/** the error object related to the event if applicable. Cannot appear together with data */
error: object;
}
export type LogEventHandler = (event: LogEvent, tags: { [key: string]: true }) => void;
export type RequestEventHandler = (request: Request, event: RequestEvent, tags: { [key: string]: true }) => void;
export type ResponseEventHandler = (request: Request) => void;
export type RouteEventHandler = (route: RequestRoute) => void;
export type StartEventHandler = () => void;
export type StopEventHandler = () => void;
export interface PodiumEvent<K extends string, T> {
emit(criteria: K, listener: (value: T) => void): void;
on(criteria: K, listener: (value: T) => void): void;
once(criteria: K, listener: (value: T) => void): void;
once(criteria: K): Promise<T>;
removeListener(criteria: K, listener: Podium.Listener): this;
removeAllListeners(criteria: K): this;
hasListeners(criteria: K): this;
}
/**
* Access: podium public interface.
* The server events emitter. Utilizes the podium with support for event criteria validation, channels, and filters.
* Use the following methods to interact with server.events:
* [server.event(events)](https://github.com/hapijs/hapi/blob/master/API.md#server.event()) - register application events.
* [server.events.emit(criteria, data)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.emit()) - emit server events.
* [server.events.on(criteria, listener)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.on()) - subscribe to all events.
* [server.events.once(criteria, listener)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.once()) - subscribe to
* Other methods include: server.events.removeListener(name, listener), server.events.removeAllListeners(name), and server.events.hasListeners(name).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
*/
export interface ServerEvents extends Podium {
/**
* Subscribe to an event where:
* @param criteria - the subscription criteria which must be one of:
* * event name string which can be any of the built-in server events
* * a custom application event registered with server.event().
* * a criteria object
* @param listener - the handler method set to receive event updates. The function signature depends on the event argument, and the spread and tags options.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventsoncriteria-listener)
* See ['log' event](https://github.com/hapijs/hapi/blob/master/API.md#-log-event)
* See ['request' event](https://github.com/hapijs/hapi/blob/master/API.md#-request-event)
* See ['response' event](https://github.com/hapijs/hapi/blob/master/API.md#-response-event)
* See ['route' event](https://github.com/hapijs/hapi/blob/master/API.md#-route-event)
* See ['start' event](https://github.com/hapijs/hapi/blob/master/API.md#-start-event)
* See ['stop' event](https://github.com/hapijs/hapi/blob/master/API.md#-stop-event)
*/
on(criteria: 'log' | ServerEventCriteria<'log'>, listener: LogEventHandler): this;
on(criteria: 'request' | ServerEventCriteria<'request'>, listener: RequestEventHandler): this;
on(criteria: 'response' | ServerEventCriteria<'response'>, listener: ResponseEventHandler): this;
on(criteria: 'route' | ServerEventCriteria<'route'>, listener: RouteEventHandler): this;
on(criteria: 'start' | ServerEventCriteria<'start'>, listener: StartEventHandler): this;
on(criteria: 'stop' | ServerEventCriteria<'stop'>, listener: StopEventHandler): this;
on(criteria: string | ServerEventCriteria<string>, listener: (value: any) => void): this;
/**
* Same as calling [server.events.on()](https://github.com/hapijs/hapi/blob/master/API.md#server.events.on()) with the count option set to 1.
* @param criteria - the subscription criteria which must be one of:
* * event name string which can be any of the built-in server events
* * a custom application event registered with server.event().
* * a criteria object
* @param listener - the handler method set to receive event updates. The function signature depends on the event argument, and the spread and tags options.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventsoncecriteria-listener)
*/
once(criteria: 'log' | ServerEventCriteria<'log'>, listener: LogEventHandler): this;
once(criteria: 'request' | ServerEventCriteria<'request'>, listener: RequestEventHandler): this;
once(criteria: 'response' | ServerEventCriteria<'response'>, listener: ResponseEventHandler): this;
once(criteria: 'route' | ServerEventCriteria<'route'>, listener: RouteEventHandler): this;
once(criteria: 'start' | ServerEventCriteria<'start'>, listener: StartEventHandler): this;
once(criteria: 'stop' | ServerEventCriteria<'stop'>, listener: StopEventHandler): this;
/**
* Same as calling server.events.on() with the count option set to 1.
* @param criteria - the subscription criteria which must be one of:
* * event name string which can be any of the built-in server events
* * a custom application event registered with server.event().
* * a criteria object
* @return Return value: a promise that resolves when the event is emitted.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-servereventsoncecriteria)
*/
once(criteria: string | ServerEventCriteria<string>): Promise<any>;
/**
* The follow method is only mentioned in Hapi API. The doc about that method can be found [here](https://github.com/hapijs/podium/blob/master/API.md#podiumremovelistenername-listener)
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
*/
removeListener(name: string, listener: Podium.Listener): this;
/**
* The follow method is only mentioned in Hapi API. The doc about that method can be found [here](https://github.com/hapijs/podium/blob/master/API.md#podiumremovealllistenersname)
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
*/
removeAllListeners(name: string): this;
/**
* The follow method is only mentioned in Hapi API. The doc about that method can be found [here](https://github.com/hapijs/podium/blob/master/API.md#podiumhaslistenersname)
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
*/
hasListeners(name: string): boolean;
}

152
node_modules/@hapi/hapi/lib/types/server/ext.d.ts generated vendored Normal file
View File

@@ -0,0 +1,152 @@
import { Server, ServerApplicationState } from './server';
import { ReqRef, ReqRefDefaults } from '../request';
import { Lifecycle } from '../utils';
/**
* The extension point event name. The available extension points include the request extension points as well as the following server extension points:
* 'onPreStart' - called before the connection listeners are started.
* 'onPostStart' - called after the connection listeners are started.
* 'onPreStop' - called before the connection listeners are stopped.
* 'onPostStop' - called after the connection listeners are stopped.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle)
*/
export type ServerExtType = 'onPreStart' | 'onPostStart' | 'onPreStop' | 'onPostStop';
export type RouteRequestExtType = 'onPreAuth'
| 'onCredentials'
| 'onPostAuth'
| 'onPreHandler'
| 'onPostHandler'
| 'onPreResponse'
| 'onPostResponse';
export type ServerRequestExtType =
RouteRequestExtType
| 'onRequest';
/**
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
* Registers an extension function in one of the request lifecycle extension points where:
* @param events - an object or array of objects with the following:
* * type - (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
* * * 'onPreStart' - called before the connection listeners are started.
* * * 'onPostStart' - called after the connection listeners are started.
* * * 'onPreStop' - called before the connection listeners are stopped.
* * * 'onPostStop' - called after the connection listeners are stopped.
* * method - (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
* * * server extension points: async function(server) where:
* * * * server - the server object.
* * * * this - the object provided via options.bind or the current active context set with server.bind().
* * * request extension points: a lifecycle method.
* * options - (optional) an object with the following:
* * * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
* * * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
* * * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
* * * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or
* when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
* @return void
*/
export interface ServerExtEventsObject<A = ServerApplicationState> {
/**
* (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
* * 'onPreStart' - called before the connection listeners are started.
* * 'onPostStart' - called after the connection listeners are started.
* * 'onPreStop' - called before the connection listeners are stopped.
*/
type: ServerExtType;
/**
* (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
* * server extension points: async function(server) where:
* * * server - the server object.
* * * this - the object provided via options.bind or the current active context set with server.bind().
* * request extension points: a lifecycle method.
*/
method: ServerExtPointFunction<A> | ServerExtPointFunction<A>[];
options?: ServerExtOptions | undefined;
}
export interface RouteExtObject<Refs extends ReqRef = ReqRefDefaults> {
method: Lifecycle.Method<Refs>;
options?: ServerExtOptions | undefined;
}
/**
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
* Registers an extension function in one of the request lifecycle extension points where:
* @param events - an object or array of objects with the following:
* * type - (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
* * * 'onPreStart' - called before the connection listeners are started.
* * * 'onPostStart' - called after the connection listeners are started.
* * * 'onPreStop' - called before the connection listeners are stopped.
* * * 'onPostStop' - called after the connection listeners are stopped.
* * method - (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
* * * server extension points: async function(server) where:
* * * * server - the server object.
* * * * this - the object provided via options.bind or the current active context set with server.bind().
* * * request extension points: a lifecycle method.
* * options - (optional) an object with the following:
* * * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
* * * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
* * * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
* * * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or
* when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
* @return void
*/
export interface ServerExtEventsRequestObject {
/**
* (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
* * 'onPreStart' - called before the connection listeners are started.
* * 'onPostStart' - called after the connection listeners are started.
* * 'onPreStop' - called before the connection listeners are stopped.
* * 'onPostStop' - called after the connection listeners are stopped.
*/
type: ServerRequestExtType;
/**
* (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
* * server extension points: async function(server) where:
* * * server - the server object.
* * * this - the object provided via options.bind or the current active context set with server.bind().
* * request extension points: a lifecycle method.
*/
method: Lifecycle.Method | Lifecycle.Method[];
/**
* (optional) an object with the following:
* * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
* * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
* * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
* * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions,
* or when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
*/
options?: ServerExtOptions | undefined;
}
export type ServerExtPointFunction<A = ServerApplicationState> = (server: Server<A>) => void;
/**
* An object with the following:
* * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
* * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
* * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
* * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or
* when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to. For context [See
* docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
*/
export interface ServerExtOptions {
/**
* a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
*/
before?: string | string[] | undefined;
/**
* a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
*/
after?: string | string[] | undefined;
/**
* a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
*/
bind?: object | undefined;
/**
* if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or when
* adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
*/
sandbox?: 'server' | 'plugin' | undefined;
}

11
node_modules/@hapi/hapi/lib/types/server/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
export * from './auth';
export * from './cache';
export * from './encoders';
export * from './events';
export * from './ext';
export * from './info';
export * from './inject';
export * from './methods';
export * from './options';
export * from './server';
export * from './state';

53
node_modules/@hapi/hapi/lib/types/server/info.d.ts generated vendored Normal file
View File

@@ -0,0 +1,53 @@
/**
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverinfo)
* An object containing information about the server where:
*/
export interface ServerInfo {
/**
* a unique server identifier (using the format '{hostname}:{pid}:{now base36}').
*/
id: string;
/**
* server creation timestamp.
*/
created: number;
/**
* server start timestamp (0 when stopped).
*/
started: number;
/**
* the connection [port](https://github.com/hapijs/hapi/blob/master/API.md#server.options.port) based on the following rules:
* * before the server has been started: the configured port value.
* * after the server has been started: the actual port assigned when no port is configured or was set to 0.
*/
port: number | string;
/**
* The [host](https://github.com/hapijs/hapi/blob/master/API.md#server.options.host) configuration value.
*/
host: string;
/**
* the active IP address the connection was bound to after starting. Set to undefined until the server has been
* started or when using a non TCP port (e.g. UNIX domain socket).
*/
address: undefined | string;
/**
* the protocol used:
* * 'http' - HTTP.
* * 'https' - HTTPS.
* * 'socket' - UNIX domain socket or Windows named pipe.
*/
protocol: 'http' | 'https' | 'socket';
/**
* a string representing the connection (e.g. 'http://example.com:8080' or 'socket:/unix/domain/socket/path'). Contains
* the uri value if set, otherwise constructed from the available settings. If no port is configured or is set
* to 0, the uri will not include a port component until the server is started.
*/
uri: string;
}

89
node_modules/@hapi/hapi/lib/types/server/inject.d.ts generated vendored Normal file
View File

@@ -0,0 +1,89 @@
import { RequestOptions as ShotRequestOptions, ResponseObject as ShotResponseObject } from '@hapi/shot';
import { PluginsStates } from '../plugin';
import { AuthArtifacts, AuthCredentials, Request, RequestApplicationState } from '../request';
/**
* An object with:
* * method - (optional) the request HTTP method (e.g. 'POST'). Defaults to 'GET'.
* * url - (required) the request URL. If the URI includes an authority (e.g. 'example.com:8080'), it is used to automatically set an HTTP 'Host' header, unless one was specified in headers.
* * headers - (optional) an object with optional request headers where each key is the header name and the value is the header content. Defaults to no additions to the default shot headers.
* * payload - (optional) an string, buffer or object containing the request payload. In case of an object it will be converted to a string for you. Defaults to no payload. Note that payload
* processing defaults to 'application/json' if no 'Content-Type' header provided.
* * credentials - (optional) an credentials object containing authentication information. The credentials are used to bypass the default authentication strategies, and are validated directly as if
* they were received via an authentication scheme. Defaults to no credentials.
* * artifacts - (optional) an artifacts object containing authentication artifact information. The artifacts are used to bypass the default authentication strategies, and are validated directly as
* if they were received via an authentication scheme. Ignored if set without credentials. Defaults to no artifacts.
* * app - (optional) sets the initial value of request.app, defaults to {}.
* * plugins - (optional) sets the initial value of request.plugins, defaults to {}.
* * allowInternals - (optional) allows access to routes with config.isInternal set to true. Defaults to false.
* * remoteAddress - (optional) sets the remote address for the incoming connection.
* * simulate - (optional) an object with options used to simulate client request stream conditions for testing:
* * error - if true, emits an 'error' event after payload transmission (if any). Defaults to false.
* * close - if true, emits a 'close' event after payload transmission (if any). Defaults to false.
* * end - if false, does not end the stream. Defaults to true.
* * split - indicates whether the request payload will be split into chunks. Defaults to undefined, meaning payload will not be chunked.
* * validate - (optional) if false, the options inputs are not validated. This is recommended for run-time usage of inject() to make it perform faster where input validation can be tested
* separately.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverinjectoptions)
* For context [Shot module](https://github.com/hapijs/shot)
*/
export interface ServerInjectOptions extends ShotRequestOptions {
/**
* Authentication bypass options.
*/
auth?: {
/**
* The authentication strategy name matching the provided credentials.
*/
strategy: string;
/**
* The credentials are used to bypass the default authentication strategies,
* and are validated directly as if they were received via an authentication scheme.
*/
credentials: AuthCredentials;
/**
* The artifacts are used to bypass the default authentication strategies,
* and are validated directly as if they were received via an authentication scheme. Defaults to no artifacts.
*/
artifacts?: AuthArtifacts | undefined;
} | undefined;
/**
* sets the initial value of request.app, defaults to {}.
*/
app?: RequestApplicationState | undefined;
/**
* sets the initial value of request.plugins, defaults to {}.
*/
plugins?: PluginsStates | undefined;
/**
* allows access to routes with config.isInternal set to true. Defaults to false.
*/
allowInternals?: boolean | undefined;
}
/**
* A response object with the following properties:
* * statusCode - the HTTP status code.
* * headers - an object containing the headers set.
* * payload - the response payload string.
* * rawPayload - the raw response payload buffer.
* * raw - an object with the injection request and response objects:
* * req - the simulated node request object.
* * res - the simulated node response object.
* * result - the raw handler response (e.g. when not a stream or a view) before it is serialized for transmission. If not available, the value is set to payload. Useful for inspection and reuse of
* the internal objects returned (instead of parsing the response string).
* * request - the request object.
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverinjectoptions)
* For context [Shot module](https://github.com/hapijs/shot)
*/
export interface ServerInjectResponse<Result = object> extends ShotResponseObject {
/**
* the raw handler response (e.g. when not a stream or a view) before it is serialized for transmission. If not available, the value is set to payload. Useful for inspection and reuse of the
* internal objects returned (instead of parsing the response string).
*/
result: Result | undefined;
/**
* the request object.
*/
request: Request;
}

95
node_modules/@hapi/hapi/lib/types/server/methods.d.ts generated vendored Normal file
View File

@@ -0,0 +1,95 @@
import { CacheStatisticsObject, PolicyOptions } from "@hapi/catbox";
type AnyMethod = (...args: any[]) => any;
export type CachedServerMethod<T extends AnyMethod> = T & {
cache?: {
drop(...args: Parameters<T>): Promise<void>;
stats: CacheStatisticsObject
}
};
/**
* The method function with a signature async function(...args, [flags]) where:
* * ...args - the method function arguments (can be any number of arguments or none).
* * flags - when caching is enabled, an object used to set optional method result flags:
* * * ttl - 0 if result is valid but cannot be cached. Defaults to cache policy.
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
*/
export type ServerMethod = AnyMethod;
/**
* The same cache configuration used in server.cache().
* The generateTimeout option is required.
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
*/
export interface ServerMethodCache extends PolicyOptions<any> {
generateTimeout: number | false;
cache?: string;
segment?: string;
}
/**
* Configuration object:
* * bind - a context object passed back to the method function (via this) when called. Defaults to active context (set via server.bind() when the method is registered. Ignored if the method is an
* arrow function.
* * cache - the same cache configuration used in server.cache(). The generateTimeout option is required.
* * generateKey - a function used to generate a unique key (for caching) from the arguments passed to the method function (the flags argument is not passed as input). The server will automatically
* generate a unique key if the function's arguments are all of types 'string', 'number', or 'boolean'. However if the method uses other types of arguments, a key generation function must be provided
* which takes the same arguments as the function and returns a unique string (or null if no key can be generated). For reference [See
* docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
*/
export interface ServerMethodOptions {
/**
* a context object passed back to the method function (via this) when called. Defaults to active context (set via server.bind() when the method is registered. Ignored if the method is an arrow
* function.
*/
bind?: object | undefined;
/**
* the same cache configuration used in server.cache(). The generateTimeout option is required.
*/
cache?: ServerMethodCache | undefined;
/**
* a function used to generate a unique key (for caching) from the arguments passed to the method function (the flags argument is not passed as input). The server will automatically generate a
* unique key if the function's arguments are all of types 'string', 'number', or 'boolean'. However if the method uses other types of arguments, a key generation function must be provided which
* takes the same arguments as the function and returns a unique string (or null if no key can be generated).
*/
generateKey?(...args: any[]): string | null;
}
/**
* An object or an array of objects where each one contains:
* * name - the method name.
* * method - the method function.
* * options - (optional) settings.
* For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodmethods)
*/
export interface ServerMethodConfigurationObject {
/**
* the method name.
*/
name: string;
/**
* the method function.
*/
method: ServerMethod;
/**
* (optional) settings.
*/
options?: ServerMethodOptions | undefined;
}
interface BaseServerMethods {
[name: string]: (
ServerMethod |
CachedServerMethod<ServerMethod> |
BaseServerMethods
);
}
/**
* An empty interface to allow typings of custom server.methods.
*/
export interface ServerMethods extends BaseServerMethods {
}

235
node_modules/@hapi/hapi/lib/types/server/options.d.ts generated vendored Normal file
View File

@@ -0,0 +1,235 @@
import * as http from 'http';
import * as https from 'https';
import { MimosOptions } from '@hapi/mimos';
import { PluginSpecificConfiguration } from '../plugin';
import { RouteOptions } from '../route';
import { CacheProvider, ServerOptionsCache } from './cache';
import { SameSitePolicy, ServerStateCookieOptions } from './state';
export interface ServerOptionsCompression {
minBytes: number;
}
/**
* Empty interface to allow for custom augmentation.
*/
export interface ServerOptionsApp {
}
/**
* The server options control the behavior of the server object. Note that the options object is deeply cloned
* (with the exception of listener which is shallowly copied) and should not contain any values that are unsafe to perform deep copy on.
* All options are optionals.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-server-options)
*/
export interface ServerOptions {
/**
* @default '0.0.0.0' (all available network interfaces).
* Sets the hostname or IP address the server will listen on. If not configured, defaults to host if present, otherwise to all available network interfaces. Set to '127.0.0.1' or 'localhost' to
* restrict the server to only those coming from the same host.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsaddress)
*/
address?: string | undefined;
/**
* @default {}.
* Provides application-specific configuration which can later be accessed via server.settings.app. The framework does not interact with this object. It is simply a reference made available
* anywhere a server reference is provided. Note the difference between server.settings.app which is used to store static configuration values and server.app which is meant for storing run-time
* state.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsapp)
*/
app?: ServerOptionsApp | undefined;
/**
* @default true.
* Used to disable the automatic initialization of the listener. When false, indicates that the listener will be started manually outside the framework.
* Cannot be set to true along with a port value.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsautolisten)
*/
autoListen?: boolean | undefined;
/**
* @default { engine: require('@hapi/catbox-memory' }.
* Sets up server-side caching providers. Every server includes a default cache for storing application state. By default, a simple memory-based cache is created which has limited capacity and
* capabilities. hapi uses catbox for its cache implementation which includes support for common storage solutions (e.g. Redis, MongoDB, Memcached, Riak, among others). Caching is only utilized
* if methods and plugins explicitly store their state in the cache. The server cache configuration only defines the storage container itself. The configuration can be assigned one or more
* (array):
* * a class or prototype function (usually obtained by calling require() on a catbox strategy such as require('@hapi/catbox-redis')). A new catbox client will be created internally using this
* function.
* * a configuration object with the following:
* * * engine - a class, a prototype function, or a catbox engine object.
* * * name - an identifier used later when provisioning or configuring caching for server methods or plugins. Each cache name must be unique. A single item may omit the name option which defines
* the default cache. If every cache includes a name, a default memory cache is provisioned as well.
* * * shared - if true, allows multiple cache users to share the same segment (e.g. multiple methods using the same cache storage container). Default to false.
* * * partition - (optional) string used to isolate cached data. Defaults to 'hapi-cache'.
* * * other options passed to the catbox strategy used. Other options are only passed to catbox when engine above is a class or function and ignored if engine is a catbox engine object).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionscache)
*/
cache?: CacheProvider | ServerOptionsCache | ServerOptionsCache[] | undefined;
/**
* @default { minBytes: 1024 }.
* Defines server handling of content encoding requests. If false, response content encoding is disabled and no compression is performed by the server.
*/
compression?: boolean | ServerOptionsCompression | undefined;
/**
* @default { request: ['implementation'] }.
* Determines which logged events are sent to the console. This should only be used for development and does not affect which events are actually logged internally and recorded. Set to false to
* disable all console logging, or to an object with:
* * log - a string array of server log tags to be displayed via console.error() when the events are logged via server.log() as well as internally generated server logs. Defaults to no output.
* * request - a string array of request log tags to be displayed via console.error() when the events are logged via request.log() as well as internally generated request logs. For example, to
* display all errors, set the option to ['error']. To turn off all console debug messages set it to false. To display all request logs, set it to '*'. Defaults to uncaught errors thrown in
* external code (these errors are handled automatically and result in an Internal Server Error response) or runtime errors due to developer error. For example, to display all errors, set the log
* or request to ['error']. To turn off all output set the log or request to false. To display all server logs, set the log or request to '*'. To disable all debug information, set debug to
* false.
*/
debug?: false | {
log?: string | string[] | false | undefined;
request?: string | string[] | false | undefined;
} | undefined;
/**
* @default the operating system hostname and if not available, to 'localhost'.
* The public hostname or IP address. Used to set server.info.host and server.info.uri and as address is none provided.
*/
host?: string | undefined;
info?: {
/**
* @default false.
* If true, the request.info.remoteAddress and request.info.remotePort are populated when the request is received which can consume more resource (but is ok if the information is needed,
* especially for aborted requests). When false, the fields are only populated upon demand (but will be undefined if accessed after the request is aborted).
*/
remote?: boolean | undefined;
} | undefined;
/**
* @default none.
* An optional node HTTP (or HTTPS) http.Server object (or an object with a compatible interface).
* If the listener needs to be manually started, set autoListen to false.
* If the listener uses TLS, set tls to true.
*/
listener?: http.Server | undefined;
/**
* @default { sampleInterval: 0 }.
* Server excessive load handling limits where:
* * sampleInterval - the frequency of sampling in milliseconds. When set to 0, the other load options are ignored. Defaults to 0 (no sampling).
* * maxHeapUsedBytes - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
* * maxRssBytes - maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
* * maxEventLoopDelay - maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
*/
load?: {
/** the frequency of sampling in milliseconds. When set to 0, the other load options are ignored. Defaults to 0 (no sampling). */
sampleInterval?: number | undefined;
/** maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). */
maxHeapUsedBytes?: number | undefined;
/**
* maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
*/
maxRssBytes?: number | undefined;
/**
* maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response.
* Defaults to 0 (no limit).
*/
maxEventLoopDelay?: number | undefined;
} | undefined;
/**
* @default none.
* Options passed to the mimos module when generating the mime database used by the server (and accessed via server.mime):
* * override - an object hash that is merged into the built in mime information specified here. Each key value pair represents a single mime object. Each override value must contain:
* * key - the lower-cased mime-type string (e.g. 'application/javascript').
* * value - an object following the specifications outlined here. Additional values include:
* * * type - specify the type value of result objects, defaults to key.
* * * predicate - method with signature function(mime) when this mime type is found in the database, this function will execute to allows customizations.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsmime)
*/
mime?: MimosOptions | undefined;
/**
* @default { cleanStop: true }
* Defines server handling of server operations.
*/
operations?: {
/**
* @default true
* If true, the server keeps track of open connections and properly closes them when the server is stopped.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsoperations)
*/
cleanStop?: boolean;
}
/**
* @default {}.
* Plugin-specific configuration which can later be accessed via server.settings.plugins. plugins is an object where each key is a plugin name and the value is the configuration. Note the
* difference between server.settings.plugins which is used to store static configuration values and server.plugins which is meant for storing run-time state.
*/
plugins?: PluginSpecificConfiguration | undefined;
/**
* @default 0 (an ephemeral port).
* The TCP port the server will listen to. Defaults the next available port when the server is started (and assigned to server.info.port).
* If port is a string containing a '/' character, it is used as a UNIX domain socket path. If it starts with '\.\pipe', it is used as a Windows named pipe.
*/
port?: number | string | undefined;
/**
* @default { isCaseSensitive: true, stripTrailingSlash: false }.
* Controls how incoming request URIs are matched against the routing table:
* * isCaseSensitive - determines whether the paths '/example' and '/EXAMPLE' are considered different resources. Defaults to true.
* * stripTrailingSlash - removes trailing slashes on incoming paths. Defaults to false.
*/
router?: {
isCaseSensitive?: boolean | undefined;
stripTrailingSlash?: boolean | undefined;
} | undefined;
/**
* @default none.
* A route options object used as the default configuration for every route.
*/
routes?: RouteOptions | undefined;
/**
* Default value:
* {
* strictHeader: true,
* ignoreErrors: false,
* isSecure: true,
* isHttpOnly: true,
* isSameSite: 'Strict',
* encoding: 'none'
* }
* Sets the default configuration for every state (cookie) set explicitly via server.state() or implicitly (without definition) using the state configuration object.
*/
state?: ServerStateCookieOptions | undefined;
/**
* @default none.
* Used to create an HTTPS connection. The tls object is passed unchanged to the node HTTPS server as described in the node HTTPS documentation.
*/
tls?: boolean | https.ServerOptions | undefined;
/**
* @default constructed from runtime server information.
* The full public URI without the path (e.g. 'http://example.com:8080'). If present, used as the server server.info.uri, otherwise constructed from the server settings.
*/
uri?: string | undefined;
/**
* Query parameter configuration.
*/
query?: {
/**
* the method must return an object where each key is a parameter and matching value is the parameter value.
* If the method throws, the error is used as the response or returned when `request.setUrl` is called.
*/
parser(raw: Record<string, string>): Record<string, any>;
} | undefined;
}

701
node_modules/@hapi/hapi/lib/types/server/server.d.ts generated vendored Normal file
View File

@@ -0,0 +1,701 @@
import * as http from 'http';
import { Stream } from 'stream';
import { Root } from 'joi';
import { Mimos } from '@hapi/mimos';
import {
Dependencies,
PluginsListRegistered,
Plugin,
ServerRealm,
ServerRegisterOptions,
ServerRegisterPluginObject,
ServerRegisterPluginObjectArray,
HandlerDecorationMethod,
PluginProperties
} from '../plugin';
import {
ReqRef,
ReqRefDefaults,
Request,
RequestRoute
} from '../request';
import { ResponseToolkit } from '../response';
import {
RulesOptions,
RulesProcessor,
ServerRoute
} from '../route';
import { HTTP_METHODS, Lifecycle } from '../utils';
import { ServerAuth } from './auth';
import { ServerCache } from './cache';
import { ContentDecoders, ContentEncoders } from './encoders';
import { ServerEventsApplication, ServerEvents } from './events';
import {
ServerExtEventsObject,
ServerExtEventsRequestObject,
ServerExtType,
ServerExtPointFunction,
ServerExtOptions,
ServerRequestExtType
} from './ext';
import { ServerInfo } from './info';
import { ServerInjectOptions, ServerInjectResponse } from './inject';
import {
ServerMethod,
ServerMethodOptions,
ServerMethodConfigurationObject,
ServerMethods
} from './methods';
import { ServerOptions } from './options';
import { ServerState, ServerStateCookieOptions } from './state';
/**
* The general case for decorators added via server.decorate.
*/
export type DecorationMethod<T> = (this: T, ...args: any[]) => any;
export type DecorateName = string | symbol;
export type DecorationValue = object | any[] | boolean | number | string | symbol | Map<any, any> | Set<any>;
type ReservedRequestKeys = (
'server' | 'url' | 'query' | 'path' | 'method' |
'mime' | 'setUrl' | 'setMethod' | 'headers' | 'id' |
'app' | 'plugins' | 'route' | 'auth' | 'pre' |
'preResponses' | 'info' | 'isInjected' | 'orig' |
'params' | 'paramsArray' | 'payload' | 'state' |
'response' | 'raw' | 'domain' | 'log' | 'logs' |
'generateResponse' |
// Private functions
'_allowInternals' | '_closed' | '_core' |
'_entity' | '_eventContext' | '_events' | '_expectContinue' |
'_isInjected' | '_isPayloadPending' | '_isReplied' |
'_route' | '_serverTimeoutId' | '_states' | '_url' |
'_urlError' | '_initializeUrl' | '_setUrl' | '_parseUrl' |
'_parseQuery'
);
type ReservedToolkitKeys = (
'abandon' | 'authenticated' | 'close' | 'context' | 'continue' |
'entity' | 'redirect' | 'realm' | 'request' | 'response' |
'state' | 'unauthenticated' | 'unstate'
);
type ReservedServerKeys = (
// Public functions
'app' | 'auth' | 'cache' | 'decorations' | 'events' | 'info' |
'listener' | 'load' | 'methods' | 'mime' | 'plugins' | 'registrations' |
'settings' | 'states' | 'type' | 'version' | 'realm' | 'control' | 'decoder' |
'bind' | 'control' | 'decoder' | 'decorate' | 'dependency' | 'encoder' |
'event' | 'expose' | 'ext' | 'inject' | 'log' | 'lookup' | 'match' | 'method' |
'path' | 'register' | 'route' | 'rules' | 'state' | 'table' | 'validator' |
'start' | 'initialize' | 'stop' |
// Private functions
'_core' | '_initialize' | '_start' | '_stop' | '_cachePolicy' | '_createCache' |
'_clone' | '_ext' | '_addRoute'
);
type ExceptName<Property, ReservedKeys> = Property extends ReservedKeys ? never : Property;
/**
* User-extensible type for application specific state (`server.app`).
*/
export interface ServerApplicationState {
}
/**
* The server object is the main application container. The server manages all incoming requests along with all
* the facilities provided by the framework. Each server supports a single connection (e.g. listen to port 80).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#server)
*/
export class Server<A = ServerApplicationState> {
/**
* Creates a new server object
* @param options server configuration object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptions)
*/
constructor(options?: ServerOptions);
/**
* Provides a safe place to store server-specific run-time application data without potential conflicts with
* the framework internals. The data can be accessed whenever the server is accessible.
* Initialized with an empty object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverapp)
*/
app: A;
/**
* Server Auth: properties and methods
*/
readonly auth: ServerAuth;
/**
* Links another server to the initialize/start/stop state of the current server by calling the
* controlled server `initialize()`/`start()`/`stop()` methods whenever the current server methods
* are called, where:
*/
control(server: Server): void;
/**
* Provides access to the decorations already applied to various framework interfaces. The object must not be
* modified directly, but only through server.decorate.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecorations)
*/
readonly decorations: {
/**
* decorations on the request object.
*/
request: string[],
/**
* decorations on the response toolkit.
*/
toolkit: string[],
/**
* decorations on the server object.
*/
server: string[]
};
/**
* Register custom application events where:
* @param events must be one of:
* * an event name string.
* * an event options object with the following optional keys (unless noted otherwise):
* * * name - the event name string (required).
* * * channels - a string or array of strings specifying the event channels available. Defaults to no channel restrictions (event updates can specify a channel or not).
* * * clone - if true, the data object passed to server.events.emit() is cloned before it is passed to the listeners (unless an override specified by each listener). Defaults to false (data is
* passed as-is).
* * * spread - if true, the data object passed to server.event.emit() must be an array and the listener method is called with each array element passed as a separate argument (unless an override
* specified by each listener). This should only be used when the emitted data structure is known and predictable. Defaults to false (data is emitted as a single argument regardless of its
* type).
* * * tags - if true and the criteria object passed to server.event.emit() includes tags, the tags are mapped to an object (where each tag string is the key and the value is true) which is
* appended to the arguments list at the end. A configuration override can be set by each listener. Defaults to false.
* * * shared - if true, the same event name can be registered multiple times where the second registration is ignored. Note that if the registration config is changed between registrations, only
* the first configuration is used. Defaults to false (a duplicate registration will throw an error).
* * a podium emitter object.
* * an array containing any of the above.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
*/
event(events: ServerEventsApplication | ServerEventsApplication[]): void;
/**
* Access: podium public interface.
* The server events emitter. Utilizes the podium with support for event criteria validation, channels, and filters.
* Use the following methods to interact with server.events:
* [server.events.emit(criteria, data)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.emit()) - emit server events.
* [server.events.on(criteria, listener)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.on()) - subscribe to all events.
* [server.events.once(criteria, listener)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.once()) - subscribe to
* Other methods include: server.events.removeListener(name, listener), server.events.removeAllListeners(name), and server.events.hasListeners(name).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
*/
events: ServerEvents;
/**
* An object containing information about the server where:
* * id - a unique server identifier (using the format '{hostname}:{pid}:{now base36}').
* * created - server creation timestamp.
* * started - server start timestamp (0 when stopped).
* * port - the connection port based on the following rules:
* * host - The host configuration value.
* * address - the active IP address the connection was bound to after starting. Set to undefined until the server has been started or when using a non TCP port (e.g. UNIX domain socket).
* * protocol - the protocol used:
* * 'http' - HTTP.
* * 'https' - HTTPS.
* * 'socket' - UNIX domain socket or Windows named pipe.
* * uri - a string representing the connection (e.g. 'http://example.com:8080' or 'socket:/unix/domain/socket/path'). Contains the uri value if set, otherwise constructed from the available
* settings. If no port is configured or is set to 0, the uri will not include a port component until the server is started.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverinfo)
*/
readonly info: ServerInfo;
/**
* Access: read only and listener public interface.
* The node HTTP server object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverlistener)
*/
listener: http.Server;
/**
* An object containing the process load metrics (when load.sampleInterval is enabled):
* * eventLoopDelay - event loop delay milliseconds.
* * heapUsed - V8 heap usage.
* * rss - RSS memory usage.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverload)
*/
readonly load: {
/**
* event loop delay milliseconds.
*/
eventLoopDelay: number;
/**
* V8 heap usage.
*/
heapUsed: number;
/**
* RSS memory usage.
*/
rss: number;
};
/**
* Server methods are functions registered with the server and used throughout the application as a common utility.
* Their advantage is in the ability to configure them to use the built-in cache and share across multiple request
* handlers without having to create a common module.
* sever.methods is an object which provides access to the methods registered via server.method() where each
* server method name is an object property.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethods
*/
readonly methods: ServerMethods;
/**
* Provides access to the server MIME database used for setting content-type information. The object must not be
* modified directly but only through the [mime](https://github.com/hapijs/hapi/blob/master/API.md#server.options.mime) server setting.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermime)
*/
mime: Mimos;
/**
* An object containing the values exposed by each registered plugin where each key is a plugin name and the values
* are the exposed properties by each plugin using server.expose(). Plugins may set the value of
* the server.plugins[name] object directly or via the server.expose() method.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverplugins)
*/
plugins: PluginProperties;
/**
* The realm object contains sandboxed server settings specific to each plugin or authentication strategy. When
* registering a plugin or an authentication scheme, a server object reference is provided with a new server.realm
* container specific to that registration. It allows each plugin to maintain its own settings without leaking
* and affecting other plugins.
* For example, a plugin can set a default file path for local resources without breaking other plugins' configured
* paths. When calling server.bind(), the active realm's settings.bind property is set which is then used by
* routes and extensions added at the same level (server root or plugin).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrealm)
*/
readonly realm: ServerRealm;
/**
* An object of the currently registered plugins where each key is a registered plugin name and the value is
* an object containing:
* * version - the plugin version.
* * name - the plugin name.
* * options - (optional) options passed to the plugin during registration.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverregistrations)
*/
readonly registrations: PluginsListRegistered;
/**
* The server configuration object after defaults applied.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serversettings)
*/
readonly settings: ServerOptions;
/**
* The server cookies manager.
* Access: read only and statehood public interface.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverstates)
*/
readonly states: ServerState;
/**
* A string indicating the listener type where:
* * 'socket' - UNIX domain socket or Windows named pipe.
* * 'tcp' - an HTTP listener.
*/
readonly type: 'socket' | 'tcp';
/**
* The hapi module version number.
*/
readonly version: string;
/**
* Sets a global context used as the default bind object when adding a route or an extension where:
* @param context - the object used to bind this in lifecycle methods such as the route handler and extension methods. The context is also made available as h.context.
* @return Return value: none.
* When setting a context inside a plugin, the context is applied only to methods set up by the plugin. Note that the context applies only to routes and extensions added after it has been set.
* Ignored if the method being bound is an arrow function.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverbindcontext)
*/
bind(context: object): void;
/**
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
*/
cache: ServerCache;
/**
* Registers a custom content decoding compressor to extend the built-in support for 'gzip' and 'deflate' where:
* @param encoding - the decoder name string.
* @param decoder - a function using the signature function(options) where options are the encoding specific options configured in the route payload.compression configuration option, and the
* return value is an object compatible with the output of node's zlib.createGunzip().
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecoderencoding-decoder)
*/
decoder<T extends keyof ContentDecoders>(encoding: T, decoder: ContentDecoders[T]): void;
decoder(encoding: string, decoder: ((options?: object) => Stream)): void;
/**
* Extends various framework interfaces with custom methods where:
* @param type - the interface being decorated. Supported types:
* 'handler' - adds a new handler type to be used in routes handlers.
* 'request' - adds methods to the Request object.
* 'server' - adds methods to the Server object.
* 'toolkit' - adds methods to the response toolkit.
* @param property - the object decoration key name.
* @param method - the extension function or other value.
* @param options - (optional) supports the following optional settings:
* apply - when the type is 'request', if true, the method function is invoked using the signature function(request) where request is the current request object and the returned value is assigned
* as the decoration. extend - if true, overrides an existing decoration. The method must be a function with the signature function(existing) where: existing - is the previously set
* decoration method value. must return the new decoration function or value. cannot be used to extend handler decorations.
* @return void;
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecoratetype-property-method-options)
*/
decorate <P extends DecorateName>(type: 'handler', property: P, method: HandlerDecorationMethod, options?: { apply?: boolean | undefined, extend?: never }): void;
decorate <P extends DecorateName>(type: 'request', property: ExceptName<P, ReservedRequestKeys>, method: (existing: ((...args: any[]) => any)) => (request: Request) => DecorationMethod<Request>, options: {apply: true, extend: true}): void;
decorate <P extends DecorateName>(type: 'request', property: ExceptName<P, ReservedRequestKeys>, method: (request: Request) => DecorationMethod<Request>, options: {apply: true, extend?: boolean | undefined}): void;
decorate <P extends DecorateName>(type: 'request', property: ExceptName<P, ReservedRequestKeys>, method: DecorationMethod<Request>, options?: {apply?: boolean | undefined, extend?: boolean | undefined}): void;
decorate <P extends DecorateName>(type: 'request', property: ExceptName<P, ReservedRequestKeys>, value: (existing: ((...args: any[]) => any)) => (request: Request) => any, options: {apply: true, extend: true}): void;
decorate <P extends DecorateName>(type: 'request', property: ExceptName<P, ReservedRequestKeys>, value: (request: Request) => any, options: {apply: true, extend?: boolean | undefined}): void;
decorate <P extends DecorateName>(type: 'request', property: ExceptName<P, ReservedRequestKeys>, value: DecorationValue, options?: never): void;
decorate <P extends DecorateName>(type: 'toolkit', property: ExceptName<P, ReservedToolkitKeys>, method: (existing: ((...args: any[]) => any)) => DecorationMethod<ResponseToolkit>, options: {apply?: boolean | undefined, extend: true}): void;
decorate <P extends DecorateName>(type: 'toolkit', property: ExceptName<P, ReservedToolkitKeys>, method: DecorationMethod<ResponseToolkit>, options?: {apply?: boolean | undefined, extend?: boolean | undefined}): void;
decorate <P extends DecorateName>(type: 'toolkit', property: ExceptName<P, ReservedToolkitKeys>, value: (existing: ((...args: any[]) => any)) => any, options: {apply?: boolean | undefined, extend: true}): void;
decorate <P extends DecorateName>(type: 'toolkit', property: ExceptName<P, ReservedToolkitKeys>, value: DecorationValue, options?: never): void;
decorate <P extends DecorateName>(type: 'server', property: ExceptName<P, ReservedServerKeys>, method: (existing: ((...args: any[]) => any)) => DecorationMethod<Server>, options: {apply?: boolean | undefined, extend: true}): void;
decorate <P extends DecorateName>(type: 'server', property: ExceptName<P, ReservedServerKeys>, method: DecorationMethod<Server>, options?: {apply?: boolean | undefined, extend?: boolean | undefined}): void;
decorate <P extends DecorateName>(type: 'server', property: ExceptName<P, ReservedServerKeys>, value: (existing: ((...args: any[]) => any)) => any, options: {apply?: boolean | undefined, extend: true}): void;
decorate <P extends DecorateName>(type: 'server', property: ExceptName<P, ReservedServerKeys>, value: DecorationValue, options?: never): void;
/**
* Used within a plugin to declare a required dependency on other plugins where:
* @param dependencies - plugins which must be registered in order for this plugin to operate. Plugins listed must be registered before the server is
* initialized or started.
* @param after - (optional) a function that is called after all the specified dependencies have been registered and before the server starts. The function is only called if the server is
* initialized or started. The function signature is async function(server) where: server - the server the dependency() method was called on.
* @return Return value: none.
* The after method is identical to setting a server extension point on 'onPreStart'.
* If a circular dependency is detected, an exception is thrown (e.g. two plugins each has an after function to be called after the other).
* The method does not provide version dependency which should be implemented using npm peer dependencies.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdependencydependencies-after)
*/
dependency(dependencies: Dependencies, after?: ((server: Server) => Promise<void>) | undefined): void;
/**
* Registers a custom content encoding compressor to extend the built-in support for 'gzip' and 'deflate' where:
* @param encoding - the encoder name string.
* @param encoder - a function using the signature function(options) where options are the encoding specific options configured in the route compression option, and the return value is an object
* compatible with the output of node's zlib.createGzip().
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverencoderencoding-encoder)
*/
encoder<T extends keyof ContentEncoders>(encoding: T, encoder: ContentEncoders[T]): void;
encoder(encoding: string, encoder: ((options?: object) => Stream)): void;
/**
* Used within a plugin to expose a property via server.plugins[name] where:
* @param key - the key assigned (server.plugins[name][key]).
* @param value - the value assigned.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverexposekey-value)
*/
expose(key: string, value: any): void;
/**
* Merges an object into to the existing content of server.plugins[name] where:
* @param obj - the object merged into the exposed properties container.
* @return Return value: none.
* Note that all the properties of obj are deeply cloned into server.plugins[name], so avoid using this method
* for exposing large objects that may be expensive to clone or singleton objects such as database client
* objects. Instead favor server.expose(key, value), which only copies a reference to value.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverexposeobj)
*/
expose(obj: object): void;
/**
* Registers an extension function in one of the request lifecycle extension points where:
* @param events - an object or array of objects with the following:
* * type - (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
* * * 'onPreStart' - called before the connection listeners are started.
* * * 'onPostStart' - called after the connection listeners are started.
* * * 'onPreStop' - called before the connection listeners are stopped.
* * * 'onPostStop' - called after the connection listeners are stopped.
* * method - (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
* * * server extension points: async function(server) where:
* * * * server - the server object.
* * * * this - the object provided via options.bind or the current active context set with server.bind().
* * * request extension points: a lifecycle method.
* * options - (optional) an object with the following:
* * * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
* * * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
* * * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
* * * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level
* extensions, or when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
* @return void
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
*/
ext(events: ServerExtEventsObject<A> | ServerExtEventsObject<A>[] | ServerExtEventsRequestObject | ServerExtEventsRequestObject[]): void;
/**
* Registers a single extension event using the same properties as used in server.ext(events), but passed as arguments.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevent-method-options)
*/
ext(event: ServerExtType, method: ServerExtPointFunction<A>, options?: ServerExtOptions | undefined): void;
ext(event: ServerRequestExtType, method: Lifecycle.Method, options?: ServerExtOptions | undefined): void;
/**
* Initializes the server (starts the caches, finalizes plugin registration) but does not start listening on the connection port.
* @return Return value: none.
* Note that if the method fails and throws an error, the server is considered to be in an undefined state and
* should be shut down. In most cases it would be impossible to fully recover as the various plugins, caches, and
* other event listeners will get confused by repeated attempts to start the server or make assumptions about the
* healthy state of the environment. It is recommended to abort the process when the server fails to start properly.
* If you must try to resume after an error, call server.stop() first to reset the server state.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverinitialize)
*/
initialize(): Promise<void>;
/**
* Injects a request into the server simulating an incoming HTTP request without making an actual socket connection. Injection is useful for testing purposes as well as for invoking routing logic
* internally without the overhead and limitations of the network stack. The method utilizes the shot module for performing injections, with some additional options and response properties:
* @param options - can be assigned a string with the requested URI, or an object with:
* * method - (optional) the request HTTP method (e.g. 'POST'). Defaults to 'GET'.
* * url - (required) the request URL. If the URI includes an authority (e.g. 'example.com:8080'), it is used to automatically set an HTTP 'Host' header, unless one was specified in headers.
* * headers - (optional) an object with optional request headers where each key is the header name and the value is the header content. Defaults to no additions to the default shot headers.
* * payload - (optional) an string, buffer or object containing the request payload. In case of an object it will be converted to a string for you. Defaults to no payload. Note that payload
* processing defaults to 'application/json' if no 'Content-Type' header provided.
* * credentials - (optional) an credentials object containing authentication information. The credentials are used to bypass the default authentication strategies, and are validated directly as
* if they were received via an authentication scheme. Defaults to no credentials.
* * artifacts - (optional) an artifacts object containing authentication artifact information. The artifacts are used to bypass the default authentication strategies, and are validated directly
* as if they were received via an authentication scheme. Ignored if set without credentials. Defaults to no artifacts.
* * app - (optional) sets the initial value of request.app, defaults to {}.
* * plugins - (optional) sets the initial value of request.plugins, defaults to {}.
* * allowInternals - (optional) allows access to routes with config.isInternal set to true. Defaults to false.
* * remoteAddress - (optional) sets the remote address for the incoming connection.
* * simulate - (optional) an object with options used to simulate client request stream conditions for testing:
* * error - if true, emits an 'error' event after payload transmission (if any). Defaults to false.
* * close - if true, emits a 'close' event after payload transmission (if any). Defaults to false.
* * end - if false, does not end the stream. Defaults to true.
* * split - indicates whether the request payload will be split into chunks. Defaults to undefined, meaning payload will not be chunked.
* * validate - (optional) if false, the options inputs are not validated. This is recommended for run-time usage of inject() to make it perform faster where input validation can be tested
* separately.
* @return Return value: a response object with the following properties:
* * statusCode - the HTTP status code.
* * headers - an object containing the headers set.
* * payload - the response payload string.
* * rawPayload - the raw response payload buffer.
* * raw - an object with the injection request and response objects:
* * req - the simulated node request object.
* * res - the simulated node response object.
* * result - the raw handler response (e.g. when not a stream or a view) before it is serialized for transmission. If not available, the value is set to payload. Useful for inspection and reuse
* of the internal objects returned (instead of parsing the response string).
* * request - the request object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverinjectoptions)
*/
inject <Result = object>(options: string | ServerInjectOptions): Promise<ServerInjectResponse<Result>>;
/**
* Logs server events that cannot be associated with a specific request. When called the server emits a 'log' event which can be used by other listeners or plugins to record the information or
* output to the console. The arguments are:
* @param tags - (required) a string or an array of strings (e.g. ['error', 'database', 'read']) used to identify the event. Tags are used instead of log levels and provide a much more expressive
* mechanism for describing and filtering events. Any logs generated by the server internally include the 'hapi' tag along with event-specific information.
* @param data - (optional) an message string or object with the application data being logged. If data is a function, the function signature is function() and it called once to generate (return
* value) the actual data emitted to the listeners. If no listeners match the event, the data function is not invoked.
* @param timestamp - (optional) an timestamp expressed in milliseconds. Defaults to Date.now() (now).
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverlogtags-data-timestamp)
*/
log(tags: string | string[], data?: string | object | (() => any) | undefined, timestamp?: number | undefined): void;
/**
* Looks up a route configuration where:
* @param id - the route identifier.
* @return Return value: the route information if found, otherwise null.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverlookupid)
*/
lookup(id: string): RequestRoute | null;
/**
* Looks up a route configuration where:
* @param method - the HTTP method (e.g. 'GET', 'POST').
* @param path - the requested path (must begin with '/').
* @param host - (optional) hostname (to match against routes with vhost).
* @return Return value: the route information if found, otherwise null.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermatchmethod-path-host)
*/
match(method: HTTP_METHODS | Lowercase<HTTP_METHODS>, path: string, host?: string | undefined): RequestRoute | null;
/**
* Registers a server method where:
* @param name - a unique method name used to invoke the method via server.methods[name].
* @param method - the method function with a signature async function(...args, [flags]) where:
* * ...args - the method function arguments (can be any number of arguments or none).
* * flags - when caching is enabled, an object used to set optional method result flags:
* * * ttl - 0 if result is valid but cannot be cached. Defaults to cache policy.
* @param options - (optional) configuration object:
* * bind - a context object passed back to the method function (via this) when called. Defaults to active context (set via server.bind() when the method is registered. Ignored if the method is
* an arrow function.
* * cache - the same cache configuration used in server.cache(). The generateTimeout option is required.
* * generateKey - a function used to generate a unique key (for caching) from the arguments passed to the method function (the flags argument is not passed as input). The server will
* automatically generate a unique key if the function's arguments are all of types 'string', 'number', or 'boolean'. However if the method uses other types of arguments, a key generation
* function must be provided which takes the same arguments as the function and returns a unique string (or null if no key can be generated).
* @return Return value: none.
* Method names can be nested (e.g. utils.users.get) which will automatically create the full path under server.methods (e.g. accessed via server.methods.utils.users.get).
* When configured with caching enabled, server.methods[name].cache is assigned an object with the following properties and methods: - await drop(...args) - a function that can be used to clear
* the cache for a given key. - stats - an object with cache statistics, see catbox for stats documentation.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
*/
method(name: string, method: ServerMethod, options?: ServerMethodOptions | undefined): void;
/**
* Registers a server method function as described in server.method() using a configuration object where:
* @param methods - an object or an array of objects where each one contains:
* * name - the method name.
* * method - the method function.
* * options - (optional) settings.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodmethods)
*/
method(methods: ServerMethodConfigurationObject | ServerMethodConfigurationObject[]): void;
/**
* Sets the path prefix used to locate static resources (files and view templates) when relative paths are used where:
* @param relativeTo - the path prefix added to any relative file path starting with '.'.
* @return Return value: none.
* Note that setting a path within a plugin only applies to resources accessed by plugin methods. If no path is set, the server default route configuration files.relativeTo settings is used. The
* path only applies to routes added after it has been set.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverpathrelativeto)
*/
path(relativeTo: string): void;
/**
* Registers a plugin where:
* @param plugins - one or an array of:
* * a plugin object.
* * an object with the following:
* * * plugin - a plugin object.
* * * options - (optional) options passed to the plugin during registration.
* * * once, routes - (optional) plugin-specific registration options as defined below.
* @param options - (optional) registration options (different from the options passed to the registration function):
* * once - if true, subsequent registrations of the same plugin are skipped without error. Cannot be used with plugin options. Defaults to false. If not set to true, an error will be thrown the
* second time a plugin is registered on the server.
* * routes - modifiers applied to each route added by the plugin:
* * * prefix - string added as prefix to any route path (must begin with '/'). If a plugin registers a child plugin the prefix is passed on to the child or is added in front of the
* child-specific prefix.
* * * vhost - virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverregisterplugins-options)
*/
register<T, D>(plugins: Plugin<T, D>, options?: ServerRegisterOptions | undefined): Promise<this & D>;
register<T, D>(plugin: ServerRegisterPluginObject<T, D>, options?: ServerRegisterOptions | undefined): Promise<this & D>;
register(plugins: Plugin<any>[], options?: ServerRegisterOptions | undefined): Promise<this>;
register(plugins: ServerRegisterPluginObject<any>[], options?: ServerRegisterOptions | undefined): Promise<this>;
register<T, U, V, W, X, Y, Z>(plugins: ServerRegisterPluginObjectArray<T, U, V, W, X, Y, Z>, options?: ServerRegisterOptions | undefined): Promise<this>;
/**
* Adds a route where:
* @param route - a route configuration object or an array of configuration objects where each object contains:
* * path - (required) the absolute path used to match incoming requests (must begin with '/'). Incoming requests are compared to the configured paths based on the server's router configuration.
* The path can include named parameters enclosed in {} which will be matched against literal values in the request as described in Path parameters.
* * method - (required) the HTTP method. Typically one of 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', or 'OPTIONS'. Any HTTP method is allowed, except for 'HEAD'. Use '*' to match against any HTTP
* method (only when an exact match was not found, and any match with a specific method will be given a higher priority over a wildcard match). Can be assigned an array of methods which has
* the same result as adding the same route with different methods manually.
* * vhost - (optional) a domain string or an array of domain strings for limiting the route to only requests with a matching host header field. Matching is done against the hostname part of the
* header only (excluding the port). Defaults to all hosts.
* * handler - (required when handler is not set) the route handler function called to generate the response after successful authentication and validation.
* * options - additional route options. The options value can be an object or a function that returns an object using the signature function(server) where server is the server the route is being
* added to and this is bound to the current realm's bind option.
* * rules - route custom rules object. The object is passed to each rules processor registered with server.rules(). Cannot be used if route.options.rules is defined.
* @return Return value: none.
* Note that the options object is deeply cloned (with the exception of bind which is shallowly copied) and cannot contain any values that are unsafe to perform deep copy on.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrouteroute)
*/
route <Refs extends ReqRef = ReqRefDefaults>(route: ServerRoute<Refs> | ServerRoute<Refs>[]): void;
/**
* Defines a route rules processor for converting route rules object into route configuration where:
* @param processor - a function using the signature function(rules, info) where:
* * rules -
* * info - an object with the following properties:
* * * method - the route method.
* * * path - the route path.
* * * vhost - the route virtual host (if any defined).
* * returns a route config object.
* @param options - optional settings:
* * validate - rules object validation:
* * * schema - joi schema.
* * * options - optional joi validation options. Defaults to { allowUnknown: true }.
* Note that the root server and each plugin server instance can only register one rules processor. If a route is added after the rules are configured, it will not include the rules config.
* Routes added by plugins apply the rules to each of the parent realms' rules from the root to the route's realm. This means the processor defined by the plugin override the config generated
* by the root processor if they overlap. The route config overrides the rules config if the overlap.
* @return void
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrulesprocessor-options)
*/
rules <Refs extends ReqRef = ReqRefDefaults>(
processor: RulesProcessor<Refs>,
options?: RulesOptions<Refs> | undefined
): void;
/**
* Starts the server by listening for incoming requests on the configured port (unless the connection was configured with autoListen set to false).
* @return Return value: none.
* Note that if the method fails and throws an error, the server is considered to be in an undefined state and should be shut down. In most cases it would be impossible to fully recover as the
* various plugins, caches, and other event listeners will get confused by repeated attempts to start the server or make assumptions about the healthy state of the environment. It is
* recommended to abort the process when the server fails to start properly. If you must try to resume after an error, call server.stop() first to reset the server state. If a started server
* is started again, the second call to server.start() is ignored. No events will be emitted and no extension points invoked.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverstart)
*/
start(): Promise<void>;
/**
* HTTP state management uses client cookies to persist a state across multiple requests.
* @param name - the cookie name string.
* @param options - are the optional cookie settings
* @return Return value: none.
* State defaults can be modified via the server default state configuration option.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverstatename-options)
*/
state(name: string, options?: ServerStateCookieOptions | undefined): void;
/**
* Stops the server's listener by refusing to accept any new connections or requests (existing connections will continue until closed or timeout), where:
* @param options - (optional) object with:
* * timeout - overrides the timeout in millisecond before forcefully terminating a connection. Defaults to 5000 (5 seconds).
* @return Return value: none.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverstopoptions)
*/
stop(options?: {timeout: number} | undefined): Promise<void>;
/**
* Returns a copy of the routing table where:
* @param host - (optional) host to filter routes matching a specific virtual host. Defaults to all virtual hosts.
* @return Return value: an array of routes where each route contains:
* * settings - the route config with defaults applied.
* * method - the HTTP method in lower case.
* * path - the route path.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servertablehost)
*/
table(host?: string | string[] | undefined): RequestRoute[];
/**
* Registers a server validation module used to compile raw validation rules into validation schemas for all routes.
* The validator is only used when validation rules are not pre-compiled schemas. When a validation rules is a function or schema object, the rule is used as-is and the validator is not used.
*/
validator(joi: Root): void;
}
/**
* Factory function to create a new server object (introduced in v17).
*/
export function server<A = ServerApplicationState>(opts?: ServerOptions | undefined): Server<A>;

79
node_modules/@hapi/hapi/lib/types/server/state.d.ts generated vendored Normal file
View File

@@ -0,0 +1,79 @@
import { StateOptions, SameSitePolicy } from '@hapi/statehood';
import { Request } from '../request';
export { SameSitePolicy };
/**
* Optional cookie settings
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverstatename-options)
*/
export interface ServerStateCookieOptions extends StateOptions<Request> {}
/**
* A single object or an array of object where each contains:
* * name - the cookie name.
* * value - the cookie value.
* * options - cookie configuration to override the server settings.
*/
export interface ServerStateFormat {
name: string;
value: string;
options: ServerStateCookieOptions;
}
/**
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverstatename-options)
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsstate)
*/
export interface ServerState {
/**
* The server cookies manager.
* Access: read only and statehood public interface.
*/
readonly states: object;
/**
* The server cookies manager settings. The settings are based on the values configured in [server.options.state](https://github.com/hapijs/hapi/blob/master/API.md#server.options.state).
*/
readonly settings: ServerStateCookieOptions;
/**
* An object containing the configuration of each cookie added via [server.state()](https://github.com/hapijs/hapi/blob/master/API.md#server.state()) where each key is the
* cookie name and value is the configuration object.
*/
readonly cookies: {
[key: string]: ServerStateCookieOptions;
};
/**
* An array containing the names of all configured cookies.
*/
readonly names: string[];
/**
* Same as calling [server.state()](https://github.com/hapijs/hapi/blob/master/API.md#server.state()).
*/
add(name: string, options?: ServerStateCookieOptions | undefined): void;
/**
* Formats an HTTP 'Set-Cookie' header based on the server.options.state where:
* @param cookies - a single object or an array of object where each contains:
* * name - the cookie name.
* * value - the cookie value.
* * options - cookie configuration to override the server settings.
* @return Return value: a header string.
* Note that this utility uses the server configuration but does not change the server state. It is provided for manual cookie formatting (e.g. when headers are set manually).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-async-serverstatesformatcookies)
*/
format(cookies: ServerStateFormat | ServerStateFormat[]): Promise<string>;
/**
* Parses an HTTP 'Cookies' header based on the server.options.state where:
* @param header - the HTTP header.
* @return Return value: an object where each key is a cookie name and value is the parsed cookie.
* Note that this utility uses the server configuration but does not change the server state. It is provided for manual cookie parsing (e.g. when server parsing is disabled).
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-async-serverstatesparseheader)
*/
parse(header: string): Promise<Record<string, string>>;
}

113
node_modules/@hapi/hapi/lib/types/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,113 @@
import * as https from 'https';
import * as stream from 'stream';
import { Boom } from '@hapi/boom';
import { ResponseObject as ShotResponseObject } from '@hapi/shot';
import {
ReqRef,
ReqRefDefaults,
MergeRefs,
Request} from './request';
import { ResponseToolkit, Auth } from './response';
/**
* All http parser [supported HTTP methods](https://nodejs.org/api/http.html#httpmethods).
*/
export type HTTP_METHODS = 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' |
'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' |
'PROPFIND' | 'PROPPATCH' | 'PURGE' | 'PUT' | 'REBIND' | 'REPORT' | 'SEARCH' | 'SOURCE' | 'SUBSCRIBE' | 'TRACE' |
'UNBIND' | 'UNLINK' | 'UNLOCK' | 'UNSUBSCRIBE';
export type PeekListener = (chunk: string, encoding: string) => void;
export namespace Json {
/**
* @see {@link https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter}
*/
type StringifyReplacer = ((key: string, value: any) => any) | (string | number)[] | undefined;
/**
* Any value greater than 10 is truncated.
*/
type StringifySpace = number | string;
/**
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsjson)
*/
interface StringifyArguments {
/** the replacer function or array. Defaults to no action. */
replacer?: StringifyReplacer | undefined;
/** number of spaces to indent nested object keys. Defaults to no indentation. */
space?: StringifySpace | undefined;
/* string suffix added after conversion to JSON string. Defaults to no suffix. */
suffix?: string | undefined;
/* calls Hoek.jsonEscape() after conversion to JSON string. Defaults to false. */
escape?: boolean | undefined;
}
}
export namespace Lifecycle {
/**
* Lifecycle methods are the interface between the framework and the application. Many of the request lifecycle steps:
* extensions, authentication, handlers, pre-handler methods, and failAction function values are lifecycle methods
* provided by the developer and executed by the framework.
* Each lifecycle method is a function with the signature await function(request, h, [err]) where:
* * request - the request object.
* * h - the response toolkit the handler must call to set a response and return control back to the framework.
* * err - an error object available only when the method is used as a failAction value.
*/
type Method<
Refs extends ReqRef = ReqRefDefaults,
R extends ReturnValue<any> = ReturnValue<Refs>
> = (
this: MergeRefs<Refs>['Bind'],
request: Request<Refs>,
h: ResponseToolkit<Refs>,
err?: Error | undefined
) => R;
/**
* Each lifecycle method must return a value or a promise that resolves into a value. If a lifecycle method returns
* without a value or resolves to an undefined value, an Internal Server Error (500) error response is sent.
* The return value must be one of:
* - Plain value: null, string, number, boolean
* - Buffer object
* - Error object: plain Error OR a Boom object.
* - Stream object
* - any object or array
* - a toolkit signal:
* - a toolkit method response:
* - a promise object that resolve to any of the above values
* For more info please [See docs](https://github.com/hapijs/hapi/blob/master/API.md#lifecycle-methods)
*/
type ReturnValue<Refs extends ReqRef = ReqRefDefaults> = ReturnValueTypes<Refs> | (Promise<ReturnValueTypes<Refs>>);
type ReturnValueTypes<Refs extends ReqRef = ReqRefDefaults> =
(null | string | number | boolean) |
(Buffer) |
(Error | Boom) |
(stream.Stream) |
(object | object[]) |
symbol |
Auth<
MergeRefs<Refs>['AuthUser'],
MergeRefs<Refs>['AuthApp'],
MergeRefs<Refs>['AuthCredentialsExtra'],
MergeRefs<Refs>['AuthArtifactsExtra']
> |
ShotResponseObject;
/**
* Various configuration options allows defining how errors are handled. For example, when invalid payload is received or malformed cookie, instead of returning an error, the framework can be
* configured to perform another action. When supported the failAction option supports the following values:
* * 'error' - return the error object as the response.
* * 'log' - report the error but continue processing the request.
* * 'ignore' - take no action and continue processing the request.
* * a lifecycle method with the signature async function(request, h, err) where:
* * * request - the request object.
* * * h - the response toolkit.
* * * err - the error object.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-failaction-configuration)
*/
type FailAction = 'error' | 'log' | 'ignore' | Method;
}

250
node_modules/@hapi/hapi/lib/validation.js generated vendored Executable file
View File

@@ -0,0 +1,250 @@
'use strict';
const Boom = require('@hapi/boom');
const Hoek = require('@hapi/hoek');
const Validate = require('@hapi/validate');
const internals = {};
exports.validator = function (validator) {
Hoek.assert(validator, 'Missing validator');
Hoek.assert(typeof validator.compile === 'function', 'Invalid validator compile method');
return validator;
};
exports.compile = function (rule, validator, realm, core) {
validator = validator ?? internals.validator(realm, core);
// false - nothing allowed
if (rule === false) {
return Validate.object({}).allow(null);
}
// Custom function
if (typeof rule === 'function') {
return rule;
}
// null, undefined, true - anything allowed
if (!rule || // false tested above
rule === true) {
return null;
}
// {...} - ... allowed
if (typeof rule.validate === 'function') {
return rule;
}
Hoek.assert(validator, 'Cannot set uncompiled validation rules without configuring a validator');
return validator.compile(rule);
};
internals.validator = function (realm, core) {
while (realm) {
if (realm.validator) {
return realm.validator;
}
realm = realm.parent;
}
return core.validator;
};
exports.headers = function (request) {
return internals.input('headers', request);
};
exports.params = function (request) {
return internals.input('params', request);
};
exports.payload = function (request) {
if (request.method === 'get' ||
request.method === 'head') { // When route.method is '*'
return;
}
return internals.input('payload', request);
};
exports.query = function (request) {
return internals.input('query', request);
};
exports.state = function (request) {
return internals.input('state', request);
};
internals.input = async function (source, request) {
const localOptions = {
context: {
headers: request.headers,
params: request.params,
query: request.query,
payload: request.payload,
state: request.state,
auth: request.auth,
app: {
route: request.route.settings.app,
request: request.app
}
}
};
delete localOptions.context[source];
Hoek.merge(localOptions, request.route.settings.validate.options);
try {
const schema = request.route.settings.validate[source];
const bind = request.route.settings.bind;
var value = await (typeof schema !== 'function' ? internals.validate(request[source], schema, localOptions) : schema.call(bind, request[source], localOptions));
return;
}
catch (err) {
var validationError = err;
}
finally {
request.orig[source] = request[source];
if (value !== undefined) {
request[source] = value;
}
}
if (request.route.settings.validate.failAction === 'ignore') {
return;
}
// Prepare error
const defaultError = validationError.isBoom ? validationError : Boom.badRequest(`Invalid request ${source} input`);
const detailedError = Boom.boomify(validationError, { statusCode: 400, override: false, data: { defaultError } });
detailedError.output.payload.validation = { source, keys: [] };
if (validationError.details) {
for (const details of validationError.details) {
const path = details.path;
detailedError.output.payload.validation.keys.push(Hoek.escapeHtml(path.join('.')));
}
}
if (request.route.settings.validate.errorFields) {
for (const field in request.route.settings.validate.errorFields) {
detailedError.output.payload[field] = request.route.settings.validate.errorFields[field];
}
}
return request._core.toolkit.failAction(request, request.route.settings.validate.failAction, defaultError, { details: detailedError, tags: ['validation', 'error', source] });
};
exports.response = async function (request) {
if (request.route.settings.response.sample) {
const currentSample = Math.ceil(Math.random() * 100);
if (currentSample > request.route.settings.response.sample) {
return;
}
}
const response = request.response;
const statusCode = response.isBoom ? response.output.statusCode : response.statusCode;
const statusSchema = request.route.settings.response.status[statusCode];
if (statusCode >= 400 &&
!statusSchema) {
return; // Do not validate errors by default
}
const schema = statusSchema !== undefined ? statusSchema : request.route.settings.response.schema;
if (schema === null) {
return; // No rules
}
if (!response.isBoom &&
request.response.variety !== 'plain') {
throw Boom.badImplementation('Cannot validate non-object response');
}
const localOptions = {
context: {
headers: request.headers,
params: request.params,
query: request.query,
payload: request.payload,
state: request.state,
auth: request.auth,
app: {
route: request.route.settings.app,
request: request.app
}
}
};
const source = response.isBoom ? response.output.payload : response.source;
Hoek.merge(localOptions, request.route.settings.response.options);
try {
let value;
if (typeof schema !== 'function') {
value = await internals.validate(source, schema, localOptions);
}
else {
value = await schema(source, localOptions);
}
if (value !== undefined &&
request.route.settings.response.modify) {
if (response.isBoom) {
response.output.payload = value;
}
else {
response.source = value;
}
}
}
catch (err) {
return request._core.toolkit.failAction(request, request.route.settings.response.failAction, err, { tags: ['validation', 'response', 'error'] });
}
};
internals.validate = function (value, schema, options) {
if (typeof schema.validateAsync === 'function') {
return schema.validateAsync(value, options);
}
return schema.validate(value, options);
};

66
node_modules/@hapi/hapi/package.json generated vendored Executable file
View File

@@ -0,0 +1,66 @@
{
"name": "@hapi/hapi",
"description": "HTTP Server framework",
"homepage": "https://hapi.dev",
"version": "21.4.6",
"repository": "git://github.com/hapijs/hapi",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"engines": {
"node": ">=14.15.0"
},
"files": [
"lib"
],
"keywords": [
"framework",
"http",
"api",
"web"
],
"eslintConfig": {
"extends": [
"plugin:@hapi/module"
]
},
"dependencies": {
"@hapi/accept": "^6.0.3",
"@hapi/ammo": "^6.0.1",
"@hapi/boom": "^10.0.1",
"@hapi/bounce": "^3.0.2",
"@hapi/call": "^9.0.1",
"@hapi/catbox": "^12.1.1",
"@hapi/catbox-memory": "^6.0.2",
"@hapi/heavy": "^8.0.1",
"@hapi/hoek": "^11.0.7",
"@hapi/mimos": "^7.0.1",
"@hapi/podium": "^5.0.2",
"@hapi/shot": "^6.0.2",
"@hapi/somever": "^4.1.1",
"@hapi/statehood": "^8.2.1",
"@hapi/subtext": "^8.1.1",
"@hapi/teamwork": "^6.0.1",
"@hapi/topo": "^6.0.2",
"@hapi/validate": "^2.0.1"
},
"devDependencies": {
"@hapi/code": "^9.0.3",
"@hapi/eslint-plugin": "^6.0.0",
"@hapi/inert": "^7.1.0",
"@hapi/joi-legacy-test": "npm:@hapi/joi@^15.0.0",
"@hapi/lab": "^25.3.2",
"@hapi/vision": "^7.0.3",
"@hapi/wreck": "^18.1.0",
"@types/node": "^18.19.130",
"handlebars": "^4.7.8",
"joi": "^17.13.3",
"legacy-readable-stream": "npm:readable-stream@^1.0.34",
"typescript": "^5.9.3"
},
"scripts": {
"test": "lab -a @hapi/code -t 100 -L -m 5000 -Y",
"test-tap": "lab -a @hapi/code -r tap -o tests.tap -m 5000",
"test-cov-html": "lab -a @hapi/code -r html -o coverage.html -m 5000"
},
"license": "BSD-3-Clause"
}