{"info":{"_postman_id":"1ea0da76-a649-4d8d-b307-907d5069c0f6","name":"moment-timezone","description":"<html><head></head><body><p>This collection makes use of the <a href=\"https://explore.postman.com/templates/7170/browserify-cdn-modules\">Browserify CDN modules template</a> to require <code>moment-timezone</code>.  See the pre-request and test scripts associated with the first request in the collection for more info.</p>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[],"owner":"10825459","collectionId":"1ea0da76-a649-4d8d-b307-907d5069c0f6","publishedId":"Szf3ZVCh","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"EF5B25"},"publishDate":"2020-04-15T23:44:38.000Z"},"item":[{"name":"Using moment-timezone","event":[{"listen":"prerequest","script":{"id":"d0377fff-c3f4-4336-9732-3a6715ec2e1f","exec":["new Function(pm.variables.get('init'))(pm);","","const moment = require('moment-timezone');","","pm.variables.set('date', moment('2020-04-15T12:00:00Z').tz('Asia/Tokyo').format('ha z'));"],"type":"text/javascript"}},{"listen":"test","script":{"id":"b578b14e-6f4b-4b2f-9427-f5a3c2ca2120","exec":["pm.test('date is in Japan Standard Time', () => {","    const date = pm.response.json().data.date;","    pm.expect(date.slice(-3)).to.eql('JST');","});"],"type":"text/javascript"}}],"id":"585d7012-fddf-4e62-98be-7a1e3cc98693","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[],"body":{"mode":"raw","raw":"{\n\t\"date\": \"{{date}}\"\n}","options":{"raw":{"language":"json"}}},"url":"https://postman-echo.com/post","urlObject":{"protocol":"https","path":["post"],"host":["postman-echo","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"585d7012-fddf-4e62-98be-7a1e3cc98693"},{"name":"Clean Dependencies","event":[{"listen":"test","script":{"id":"dd4bef49-22d5-43c3-892a-c77c9620fe87","exec":["pm.test('dependencies cleaned', () => {","    pm.expect(true);","})"],"type":"text/javascript"}},{"listen":"prerequest","script":{"id":"50d81383-28e5-4a30-88b8-f935888e6221","exec":["new Function(pm.variables.get('clean'))(pm);"],"type":"text/javascript"}}],"id":"58100d7c-3fcf-43c1-a1d6-469880bf85be","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"postman-echo.com/get","urlObject":{"path":["get"],"host":["postman-echo","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"58100d7c-3fcf-43c1-a1d6-469880bf85be"}],"event":[{"listen":"prerequest","script":{"id":"bd4b19a1-8e7d-4495-8ff2-86cf02c28ef9","type":"text/javascript","exec":["/*","    This is a pre-request script for Postman collections, folders, or requests that imports","    packages from npm after bundling them through [Browserify-CDN](https://wzrd.in/).","    ","    ## Usage","    ","    In global, collection, or environment variables, define a variable named `dependencies`","    that lists packages to import in the form `<package-name>@<version>`.  To include","    multiple packages, separate the package specs with commas","    (e.g., `async@latest,debug@4.1.1`).","    ","    Then, in pre-request or test scripts, initialize dependency resolution support with","    the following code:","    ","    ```js","    new Function(pm.variables.get('init'))(pm);","    ```","    ","    Optionally, include specific packages to require.  This can be helpful if you've","    resolved a large number of dependencies but only need specific dependencies for","    the current script.","    ","    ```js","    new Function(pm.variables.get('init'))(pm, ['uniq']);","    ```","    ","    > Avoid using `eval()`, when possible, as it can pollute the Postman sandbox scope and ","    > potentially alter Postman built-ins.  The `Function` constructor prevents this.","    > While `eval()` is supported for the `init` and `clean` scripts, it is not encouraged.","    ","    > If using `eval` with the init script, you may enable filtered dependeny resolution","    > by declaring a variable named `dependencyFilter` with the specific dependencies listed","    > in an array value.  Example: `const dependencyFilter = ['uniq']`.","    ","    In practice, it may make sense to include a request in the collection that will clean up","    stored dependency variables.  You can do that by executing the following:","    ","    ```js","    new Function(pm.variables.get('clean'))(pm);","    ```","    ","    ## Advanced","    ","    By default, https://wzrd.in is used as the Browserify CDN.  This project is open source","    and can be run independently on infrastructure you control.  You can find the","    source on GitHub: https://github.com/browserify/wzrd.in.  To override the Browserify CDN","    URL, add a variable (global, collection, or environment) named `browserify-cdn` with the ","    custom Browserify CDN service URL (e.g., `http://localhost:8080`).","    ","*/","","const url = require('url');","","fetchAllBundles();","","function fetchAllBundles() {","    const key = 'dependencies';","    ","    if (pm.globals.has(key)) {","        fetchModuleBundles(pm.globals);","    }","    ","    if (pm.collectionVariables.has(key)) {","        fetchModuleBundles(pm.collectionVariables);","    }","     ","    if (pm.environment.has(key)) {","        fetchModuleBundles(pm.environment);","    }","    ","    // local scope","    if (pm.variables.values.has(key)) {","        fetchModuleBundles(pm.variables.values);","    }","}","","function fetchModuleBundles(variableList) {","    const browserifyHost = pm.variables.get('browserify-cdn') || 'https://wzrd.in';","    ","    const dependencies = {};","    const requestedDependencies = variableList.get('dependencies');","    ","    if (requestedDependencies) {","        requestedDependencies.split(',').forEach((dep) => {","            dep = dep.trim();","            let [key, val] = dep.split('@');","            if (!val) {","                val = 'latest';","            }","            dependencies[key] = val;","        });","    }","    ","    const dependenciesLength = Object.keys(dependencies).length;","    ","    let resolvedDependencies = [];","    let count = 0;","    ","    const maybeComplete = (key, value) => {","        count++;","        resolvedDependencies.push(`${key}@${value}`);","        ","        if (count == dependenciesLength) {","            variableList.set('resolvedDependencies', JSON.stringify(resolvedDependencies));","        }","    };","    ","    const createCallback = (key, value) => {","        return (err, res) => {","            if (err) {","                console.error(err);","                return;","            }","            ","            if (res.code != 200) {","                console.error(`error fetching browserified dependency: code: ${res.code}, dependency: ${key}@${value}`);","                count++;","                return;","            }","            ","            const bundled = res.text();","            ","    ","            variableList.set(`dependency:${key}@${value}`, bundled);","    ","            maybeComplete(key, value);","        };","    };","    ","    for (let [key, value] of Object.entries(dependencies)) {","        const existingModule = variableList.get(`dependency:${key}@${value}`);","        if (!existingModule) {","            const encoded = encodeURIComponent(`${key}@${value}`);","            pm.sendRequest(url.resolve(browserifyHost, `/bundle/${encoded}`),","                createCallback(key, value));","        } else {","            maybeComplete(key, value);","        }","    }","}","","const init = function() {","    let pm = this.pm; // checking for this.pm allows for eval support.","    let specificDependencies;","    ","    let hasSpecificDepsInContext = false;","    try {","        let tmp = dependencyFilter;","        hasSpecificDepsInContext = true;","        specificDependencies = tmp;","    } catch (e) {","        // swallow","    }","    ","    if (!pm) {","        const args = Array.prototype.slice.call(arguments);","        ","        if (!pm && args.length > 0) {","            pm = args[0];","        }","        ","        if (!hasSpecificDepsInContext && args.length > 1) {","            specificDependencies = args[1];","        }","    }","    ","    const evaluate = (variableList) => {","        const deps = JSON.parse(variableList.get('resolvedDependencies'));","        if (!Array.isArray(deps)) {","            return;","        }","        ","        let filteredDependencies = deps;","    ","        if (specificDependencies && Array.isArray(specificDependencies)) {","            filteredDependencies =","                filteredDependencies.filter((dep) => {","                    splitSpec = dep.split('@');","                    splitSpec.pop();","                    return specificDependencies.includes(splitSpec.join('@'))","                })","        }","","        const loadedDependencies = JSON.parse(pm.variables.get('_loadedDependencies'));","        ","        filteredDependencies =","            filteredDependencies.filter((dep) => !loadedDependencies.includes(dep));","","        // Don't use `eval()`, as it can pollute the Postman sandbox scope and ","        // potentially alter Postman built-ins.  The `Function` constructor","        // prevents this.","        filteredDependencies.forEach((m) => {","                new Function(variableList.get(`dependency:${m}`))()","                loadedDependencies.push(m);","        });","        ","        pm.variables.set('_loadedDependencies', JSON.stringify(loadedDependencies));","    };","    ","    const key = 'resolvedDependencies';","    ","    if (pm.globals.has(key)) {","        evaluate(pm.globals);","    }","    ","    if (pm.collectionVariables.has(key)) {","        evaluate(pm.collectionVariables);","    }","     ","    if (pm.environment.has(key)) {","        evaluate(pm.environment);","    }","    ","    // local scope","    if (pm.variables.values.has(key)) {","        evaluate(pm.variables.values);","    }","};","","const clean = function() {","    let pm = this.pm; // allow for eval","    ","    if (!pm) {","        const args = Array.prototype.slice.call(arguments);","","        if (args.length > 0) {","            pm = args[0];","        }","    }","    ","    const evaluate = (variableList) => {","        let dependencies = variableList.get('resolvedDependencies');","        if (!dependencies) {","           return;","        }","        ","        dependencies = JSON.parse(dependencies);","        if (!Array.isArray(dependencies)) {","            return;","        }","        ","        dependencies.forEach((dep) => variableList.unset(`dependency:${dep}`));","        variableList.unset('resolvedDependencies');","    };","    ","    const key = 'resolvedDependencies';","    ","    if (pm.globals.has(key)) {","        evaluate(pm.globals);","    }","    ","    if (pm.collectionVariables.has(key)) {","        evaluate(pm.collectionVariables);","    }","     ","    if (pm.environment.has(key)) {","        evaluate(pm.environment);","    }","    ","    // local scope","    if (pm.variables.values.has(key)) {","        evaluate(pm.variables.values);","    }","};","","const prepFunctionForExport = (f) => {","    let func = f.toString().split('\\n');","    func.pop();","    func.shift();","    return func.join('\\n');","};","","pm.variables.set('init', prepFunctionForExport(init));","pm.variables.set('clean', prepFunctionForExport(clean));","pm.variables.set('_loadedDependencies', JSON.stringify([]));"]}},{"listen":"test","script":{"id":"4b81a599-267d-46b2-8602-e9e711eb8bac","type":"text/javascript","exec":[""]}}],"variable":[{"key":"dependencies","value":"moment-timezone@0.5.28"},{"key":"dependency:moment-timezone@0.5.28","value":""},{"key":"resolvedDependencies","value":""}]}