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Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nvar Queryparam = require('./lib/queryparam');\nvar template = require('lodash.template');\n\nvar colonTemplateSettings = {\n    interpolate: /:(.+?)\\b/g\n};\n\nmodule.exports = function httpfy(pipe, Ctor) {\n    // allow extending client API\n    Ctor = Ctor || Client;\n\n    pipe.set('client:default', function api(pipe) {\n        return new Ctor(pipe);\n    });\n};\n\nfunction Client(pipe, config) {\n    this.pipe = pipe;\n    this.config = config;\n    this.ctx = {};\n}\n\nmodule.exports.Client = Client;\n\nvar proto = Client.prototype;\n\n/*\n * Sets a new context\n */\nproto.context = function (ctx) {\n    var newClient = new Client(this.pipe, this.config);\n    newClient.ctx = Object.assign({}, ctx);\n    return newClient;\n};\n\n/**\n * General request\n * @param options\n */\nproto.request = function request(request, Ctor) {\n    request.headers = request.headers || {};\n    Ctor = Ctor || Request;\n    return new Ctor(request, this.pipe, this.ctx);\n};\n\n/**\n * GET request\n * @param params is query string in json or string format\n */\nproto.get = function get(qsParams) {\n    var options = {\n        method: 'GET'\n    };\n    if (qsParams && typeof qsParams === 'object') {\n        qsParams = Queryparam.stringify(qsParams);\n    }\n    qsParams && (options.search = qsParams);\n    return this.request(options);\n};\n\n/**\n * POST request\n * @param 'request body'\n */\nproto.post = function post(postParams) {\n    return this.request({\n        method: 'POST',\n        body: postParams\n    });\n};\n\n/**\n * PUT request\n * @param 'request body'\n */\nproto.put = function put(putParams) {\n    return this.request({\n        method: 'PUT',\n        body: putParams\n    });\n};\n\n/**\n * PATCH request\n * @param 'request body'\n */\nproto.patch = function patch(patchParams) {\n    return this.request({\n        method: 'PATCH',\n        body: patchParams\n    });\n};\n\n/**\n * DETELE request\n * @param path: 'path to target'\n */\nproto.delete = function _delete(path) {\n    return this.request({\n        path: path,\n        method: 'DELETE'\n    });\n};\n\nfunction Request(request, pipe, context) {\n    this.request = request;\n    this.pipe = pipe;\n    this.context = context;\n}\n\nmodule.exports.Request = Request;\n\nRequest.prototype = {\n\n    options: function options(opts) {\n        if (opts) {\n            opts.headers = opts.headers || {};\n            Utils.mixin(this.request.headers, opts.headers);\n            Utils.mixin(opts, this.request);\n        }\n        return this;\n    },\n\n    path: function path(pathValue, pathParams) {\n        if (!pathParams) {\n            this.request.path = pathValue;\n        } else {\n            this.request.path = template(pathValue, colonTemplateSettings)(pathParams);\n        }\n        return this;\n    },\n\n    /*\n     * Sets the request headers\n     * The method have two signatures\n     *  - set(kvpName) - to setup multi-value headers\n     *  - set(name, value) - for simaple headers\n    */\n    set: function set(key, value) {\n        this.request.headers[key] = value;\n        return this;\n    },\n\n    end: function end(callback) {\n        var request = this.request;\n        request = request;\n        request.headers = request.headers || {};\n\n        // stringify some headers\n        request.headers =\n            Utils.stringifyHeaders(request.headers);\n\n        return this.pipe.create(Object.assign({}, this.context)).request(request, callback);\n    }\n};\n\nvar Utils = {\n    // This is isomorphic version of mixin\n    mixin: function mixin(src1, src2, etc, dest) {\n        var args = [].slice.call(arguments);\n        dest = args.pop();\n        if (dest) {\n            args.forEach(function forEach(src) {\n                if (src) {\n                    Object.keys(src).forEach(function forEach(key) {\n                        dest[key] = src[key];\n                    });\n                }\n            });\n        }\n        return dest;\n    },\n\n    stringifyHeaders: function stringifyHeaders(headers) {\n        return Object.keys(headers).reduce(function reduce(memo, key) {\n            var val = memo[key];\n            if (val && typeof val === 'object' && val.set) {\n                // assume it is multi-value headers\n                memo[key] = val.toString();\n            }\n            return memo;\n        }, headers);\n    },\n\n    stringifyQuery: Queryparam.stringify\n};\n\nmodule.exports.Utils = Utils;\n"]}