How to use the @hapi/hoek.clone function in @hapi/hoek

To help you get started, we’ve selected a few @hapi/hoek examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hapijs / hapi / lib / methods.js View on Github external
_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);
github hapijs / hapi / lib / auth.js View on Github external
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();
        }
    }
github hapijs / hapi / test / transmit.js View on Github external
const proxyHandler = async (request, h) => {

                const options = {};
                options.headers = Hoek.clone(request.headers);
                delete options.headers.host;

                const res = await Wreck.request(request.method, 'http://localhost:' + upstream.info.port + '/headers', options);
                return h.response(res).code(res.statusCode);
            };
github hapijs / bell / test / index.js View on Github external
server.auth.strategy('custom_1', 'bell', {
            password: 'cookie_encryption_password_secure',
            isSecure: false,
            clientId: 'test',
            clientSecret: 'secret',
            provider: Hoek.merge(Hoek.clone(mock.provider), { name: 'custom_1' }),
            cookie: 'ring_1'
        });

        server.auth.strategy('custom_2', 'bell', {
            password: 'cookie_encryption_password_secure',
            isSecure: false,
            clientId: 'test',
            clientSecret: 'secret',
            provider: Hoek.merge(Hoek.clone(mock.provider), { name: 'custom_2' }),
            cookie: 'ring_2'
        });

        server.route({
            method: '*',
            path: '/login_1',
            options: {
                auth: 'custom_1',
                handler: function (request, h) {

                    return request.auth.credentials;
                }
            }
        });

        server.route({
github hapijs / hapi / lib / server.js View on Github external
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 }
github hapijs / glue / lib / index.js View on Github external
internals.parsePlugin = function (plugin, relativeTo) {

    if (typeof plugin === 'string') {
        return internals.requireRelativeTo(plugin, relativeTo);
    }

    if (typeof plugin.plugin === 'string') {
        const pluginObject = Hoek.clone(plugin, { shallow: ['options'] });
        pluginObject.plugin = internals.requireRelativeTo(plugin.plugin, relativeTo);

        return pluginObject;
    }

    return plugin;
};
github nearform / udaru / packages / udaru-hapi-plugin / lib / authentication.js View on Github external
server.auth.scheme('udaru', function (server, options) {
      Hoek.assert(options, 'Missing service auth strategy options')

      if (typeof options.validateFunc === 'undefined' || options.validateFunc === null) options.validateFunc = validate
      Hoek.assert(typeof options.validateFunc === 'function', 'options.validateFunc must be a valid function')

      const settings = Hoek.clone(options)

      const scheme = {
        async authenticate (request, h) {
          return h.authenticated(await authenticate(server, settings, request))
        },

        payload (request, h) {
          if (server.udaruAuthorization.needTeamsValidation(request)) return request.server.udaruAuthorization.validateTeamsInPayload(server, request, h)

          return h.continue
        },

        options: {
          payload: true
        }
      }
github hapijs / hapi / lib / request.js View on Github external
_clearState(name, options = {}) {

        const state = { name };

        state.options = Hoek.clone(options);
        state.options.ttl = 0;

        this._states[name] = state;
    }
github academia-de-codigo / noire-server / lib / modules / authorization / services / role.js View on Github external
.query()
                  .skipUndefined()
                  .where('name', entity.name)
            : Promise.resolve([]);

        const [role, equalRoles] = await Promise.all([getRoleById, getEqualRoles]);

        if (!role) {
            throw NSError.RESOURCE_NOT_FOUND();
        }

        if (equalRoles.length > 0 && equalRoles[0].id !== id) {
            throw NSError.RESOURCE_DUPLICATE();
        }

        Hoek.merge(role, Hoek.clone(entity, { shallow: Repository.Role.model.updateFields }));
        return txRoleRepository.update(role);
    });
};
github outmoded / lout / lib / index.js View on Github external
register: function (server, options) {

        const validateOptions = internals.options.validate(options);
        if (validateOptions.error) {
            throw validateOptions.error;
        }

        const settings = Hoek.clone(internals.defaults);
        Hoek.merge(settings, options);

        if (settings.endpoint[0] !== '/') {
            settings.endpoint = `/${settings.endpoint}`;
        }

        if (settings.endpoint.length > 1 && settings.endpoint[settings.endpoint.length - 1] === '/') {
            settings.endpoint = settings.endpoint.slice(0, -1);
        }

        const cssBaseUrl = `${settings.endpoint === '/' ? '' : settings.endpoint}/css`;

        server.dependency(['inert', 'vision'], () => {

            server.views({
                engines: settings.engines || {