How to use the postman-collection.VariableScope function in postman-collection

To help you get started, we’ve selected a few postman-collection 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 DefinitelyTyped / DefinitelyTyped / types / postman-collection / postman-collection-tests.ts View on Github external
vList.syncFromObject({}, false, false); // $ExpectType { created: string[]; updated: string[]; deleted: string[]; } | undefined

vList.syncToObject(); // $ExpectType { [key: string]: VariableDefinition; }
vList.syncToObject({key: varDef}); // $ExpectType { [key: string]: VariableDefinition; }

pmCollection.VariableList.isVariableList(vList); // $ExpectType boolean

// VariableScopeDefinition Tests
const varScopeDef: pmCollection.VariableScopeDefinition = {};
varScopeDef.values; // $ExpectType VariableDefinition[] | undefined

// VariableScope Tests
let varScope = new pmCollection.VariableScope(varScopeDef, []);
varScope = new pmCollection.VariableScope(vList, []);
varScope = new pmCollection.VariableScope([varDef], []);
varScope = new pmCollection.VariableScope(varScopeDef, [vList]);

varScope.values; // $ExpectType VariableDefinition[] | undefined

varScope.variables(); // ExpectType { [key: string]: VariableDefinition; }

varScope.toObject(false, false); // $ExpectType any

varScope.has("string"); // $ExpectType boolean

varScope.get("string"); // $ExpectType any

varScope.set("string", {}, "any"); // $ExpectType void

varScope.unset("string"); // $ExpectType void

varScope.clear(); // $ExpectType void
github DefinitelyTyped / DefinitelyTyped / types / postman-collection / postman-collection-tests.ts View on Github external
vList.syncFromObject({}); // $ExpectType { created: string[]; updated: string[]; deleted: string[]; } | undefined
vList.syncFromObject({}, false); // $ExpectType { created: string[]; updated: string[]; deleted: string[]; } | undefined
vList.syncFromObject({}, false, false); // $ExpectType { created: string[]; updated: string[]; deleted: string[]; } | undefined

vList.syncToObject(); // $ExpectType { [key: string]: VariableDefinition; }
vList.syncToObject({key: varDef}); // $ExpectType { [key: string]: VariableDefinition; }

pmCollection.VariableList.isVariableList(vList); // $ExpectType boolean

// VariableScopeDefinition Tests
const varScopeDef: pmCollection.VariableScopeDefinition = {};
varScopeDef.values; // $ExpectType VariableDefinition[] | undefined

// VariableScope Tests
let varScope = new pmCollection.VariableScope(varScopeDef, []);
varScope = new pmCollection.VariableScope(vList, []);
varScope = new pmCollection.VariableScope([varDef], []);
varScope = new pmCollection.VariableScope(varScopeDef, [vList]);

varScope.values; // $ExpectType VariableDefinition[] | undefined

varScope.variables(); // ExpectType { [key: string]: VariableDefinition; }

varScope.toObject(false, false); // $ExpectType any

varScope.has("string"); // $ExpectType boolean

varScope.get("string"); // $ExpectType any

varScope.set("string", {}, "any"); // $ExpectType void
github postmanlabs / postman-runtime / lib / runner / extensions / event.command.js View on Github external
// @todo: unify the non variable scope flows and consume diff always
                        // and drop sending the full variable scope from sandbox
                        else {
                            util.syncObject(contextVariable, result[variable]);
                        }
                    });

                    // Get the failures. If there was an error running the script itself, that takes precedence
                    if (!err && (abortOnFailure || stopOnFailure)) {
                        err = postProcessContext(result, assertionFailed); // also use async assertions
                    }

                    // Ensure that we have SDK instances, not serialized plain objects.
                    // @todo - should this be handled by the sandbox?
                    result && result._variables && (result._variables = new sdk.VariableScope(result._variables));
                    result && result.environment && (result.environment = new sdk.VariableScope(result.environment));
                    result && result.globals && (result.globals = new sdk.VariableScope(result.globals));
                    result && result.collectionVariables &&
                        (result.collectionVariables = new sdk.VariableScope(result.collectionVariables));
                    result && result.request && (result.request = new sdk.Request(result.request));

                    // @note Since postman-sandbox@3.5.2, response object is not included in the execution result.
                    // Refer: https://github.com/postmanlabs/postman-sandbox/pull/512
                    // Adding back here to avoid breaking change in `script` callback.
                    // @todo revisit script callback args in runtime v8.
                    payload.context && payload.context.response &&
                        (result.response = new sdk.Response(payload.context.response));

                    // persist the pm.variables for the next script
                    result && result._variables &&
                        (payload.context._variables = new sdk.VariableScope(result._variables));
github postmanlabs / postman-runtime / lib / runner / extensions / waterfall.command.js View on Github external
init: function (done) {
        var state = this.state;

        // ensure that the environment, globals and collectionVariables are in VariableScope instance format
        state.environment = VariableScope.isVariableScope(state.environment) ? state.environment :
            new VariableScope(state.environment);
        state.globals = VariableScope.isVariableScope(state.globals) ? state.globals :
            new VariableScope(state.globals);
        state.collectionVariables = VariableScope.isVariableScope(state.collectionVariables) ?
            state.collectionVariables : new VariableScope(state.collectionVariables);
        state._variables = new VariableScope();

        // ensure that the items and iteration data set is in place
        !_.isArray(state.items) && (state.items = []);
        !_.isArray(state.data) && (state.data = []);
        !_.isObject(state.data[0]) && (state.data[0] = {});

        // if the location in state is already normalised then go ahead and queue iteration, else normalise the
        // location
        state.cursor = Cursor.box(state.cursor, { // we pass bounds to ensure there is no stale state
            cycles: state.data.length,
            length: state.items.length
github postmanlabs / postman-sandbox / lib / sandbox / execution.js View on Github external
this.id = id;
    this.target = event.listen || PROPERTY.SCRIPT;
    this.legacy = options.legacy || {};
    this.cursor = _.isObject(options.cursor) ? options.cursor : {};

    this.data = _.get(context, PROPERTY.DATA, {});
    this.cookies = new sdk.PropertyList(sdk.Cookie, null, context.cookies);

    this.environment = sdk.VariableScope.isVariableScope(context.environment) ?
        context.environment : new sdk.VariableScope(context.environment, null, {enableTracking: true, changeTracker: {compressed: true}});
    this._variables = sdk.VariableScope.isVariableScope(context._variables) ?
        context._variables : new sdk.VariableScope(context._variables, null, {enableTracking: true, changeTracker: {compressed: true}});
    this.globals = sdk.VariableScope.isVariableScope(context.globals) ?
        context.globals : new sdk.VariableScope(context.globals, null, {enableTracking: true, changeTracker: {compressed: true}});
    this.collectionVariables = sdk.VariableScope.isVariableScope(context.collectionVariables) ?
        context.collectionVariables : new sdk.VariableScope(context.collectionVariables, null, {enableTracking: true, changeTracker: {compressed: true}});

    if (TARGETS_WITH_REQUEST[this.target] || _.has(context, PROPERTY.REQUEST)) {
        /**
         * @note:
         * this reference is passed on as `pm.request`, pm api adds helper functions like `to` to `pm.request`
         * sandbox overrides collection Request.prototype.toJSON to remove helpers before toJSON, see `purse.js`
         */
        this.request = sdk.Request.isRequest(context.request) ? context.request : new sdk.Request(context.request);
    }

    if (TARGETS_WITH_RESPONSE[this.target] || _.has(context, PROPERTY.RESPONSE)) {
        /**
         * @note:
         * this reference is passed on as `pm.response`, pm api adds helper functions like `to` to `pm.response`
         * sandbox overrides collection Response.prototype.toJSON to remove helpers before toJSON, see `purse.js`
         */
github postmanlabs / postman-sandbox / lib / sandbox / execution.js View on Github external
Execution = function (id, event, context, options) {
    this.id = id;
    this.target = event.listen || PROPERTY.SCRIPT;
    this.legacy = options.legacy || {};
    this.cursor = _.isObject(options.cursor) ? options.cursor : {};

    this.data = _.get(context, PROPERTY.DATA, {});
    this.cookies = new sdk.PropertyList(sdk.Cookie, null, context.cookies);

    this.environment = sdk.VariableScope.isVariableScope(context.environment) ?
        context.environment : new sdk.VariableScope(context.environment, null, {enableTracking: true, changeTracker: {compressed: true}});
    this._variables = sdk.VariableScope.isVariableScope(context._variables) ?
        context._variables : new sdk.VariableScope(context._variables, null, {enableTracking: true, changeTracker: {compressed: true}});
    this.globals = sdk.VariableScope.isVariableScope(context.globals) ?
        context.globals : new sdk.VariableScope(context.globals, null, {enableTracking: true, changeTracker: {compressed: true}});
    this.collectionVariables = sdk.VariableScope.isVariableScope(context.collectionVariables) ?
        context.collectionVariables : new sdk.VariableScope(context.collectionVariables, null, {enableTracking: true, changeTracker: {compressed: true}});

    if (TARGETS_WITH_REQUEST[this.target] || _.has(context, PROPERTY.REQUEST)) {
        /**
         * @note:
         * this reference is passed on as `pm.request`, pm api adds helper functions like `to` to `pm.request`
         * sandbox overrides collection Request.prototype.toJSON to remove helpers before toJSON, see `purse.js`
         */
        this.request = sdk.Request.isRequest(context.request) ? context.request : new sdk.Request(context.request);
    }
github postmanlabs / postman-sandbox / lib / sandbox / execution.js View on Github external
Execution = function (id, event, context, options) {
    this.id = id;
    this.target = event.listen || PROPERTY.SCRIPT;
    this.legacy = options.legacy || {};
    this.cursor = _.isObject(options.cursor) ? options.cursor : {};

    this.data = _.get(context, PROPERTY.DATA, {});
    this.cookies = new sdk.PropertyList(sdk.Cookie, null, context.cookies);

    this.environment = sdk.VariableScope.isVariableScope(context.environment) ?
        context.environment : new sdk.VariableScope(context.environment, null, {enableTracking: true, changeTracker: {compressed: true}});
    this._variables = sdk.VariableScope.isVariableScope(context._variables) ?
        context._variables : new sdk.VariableScope(context._variables, null, {enableTracking: true, changeTracker: {compressed: true}});
    this.globals = sdk.VariableScope.isVariableScope(context.globals) ?
        context.globals : new sdk.VariableScope(context.globals, null, {enableTracking: true, changeTracker: {compressed: true}});
    this.collectionVariables = sdk.VariableScope.isVariableScope(context.collectionVariables) ?
        context.collectionVariables : new sdk.VariableScope(context.collectionVariables, null, {enableTracking: true, changeTracker: {compressed: true}});

    if (TARGETS_WITH_REQUEST[this.target] || _.has(context, PROPERTY.REQUEST)) {
        /**
         * @note:
         * this reference is passed on as `pm.request`, pm api adds helper functions like `to` to `pm.request`
         * sandbox overrides collection Request.prototype.toJSON to remove helpers before toJSON, see `purse.js`
         */
        this.request = sdk.Request.isRequest(context.request) ? context.request : new sdk.Request(context.request);
    }

    if (TARGETS_WITH_RESPONSE[this.target] || _.has(context, PROPERTY.RESPONSE)) {
        /**
github postmanlabs / postman-sandbox / lib / sandbox / execution.js View on Github external
Execution = function (id, event, context, options) {
    this.id = id;
    this.target = event.listen || PROPERTY.SCRIPT;
    this.legacy = options.legacy || {};
    this.cursor = _.isObject(options.cursor) ? options.cursor : {};

    this.data = _.get(context, PROPERTY.DATA, {});
    this.cookies = new sdk.PropertyList(sdk.Cookie, null, context.cookies);

    this.environment = sdk.VariableScope.isVariableScope(context.environment) ?
        context.environment : new sdk.VariableScope(context.environment, null, {enableTracking: true, changeTracker: {compressed: true}});
    this._variables = sdk.VariableScope.isVariableScope(context._variables) ?
        context._variables : new sdk.VariableScope(context._variables, null, {enableTracking: true, changeTracker: {compressed: true}});
    this.globals = sdk.VariableScope.isVariableScope(context.globals) ?
        context.globals : new sdk.VariableScope(context.globals, null, {enableTracking: true, changeTracker: {compressed: true}});
    this.collectionVariables = sdk.VariableScope.isVariableScope(context.collectionVariables) ?
        context.collectionVariables : new sdk.VariableScope(context.collectionVariables, null, {enableTracking: true, changeTracker: {compressed: true}});

    if (TARGETS_WITH_REQUEST[this.target] || _.has(context, PROPERTY.REQUEST)) {
        /**
         * @note:
         * this reference is passed on as `pm.request`, pm api adds helper functions like `to` to `pm.request`
         * sandbox overrides collection Request.prototype.toJSON to remove helpers before toJSON, see `purse.js`
         */
        this.request = sdk.Request.isRequest(context.request) ? context.request : new sdk.Request(context.request);
    }

    if (TARGETS_WITH_RESPONSE[this.target] || _.has(context, PROPERTY.RESPONSE)) {
        /**
         * @note:
         * this reference is passed on as `pm.response`, pm api adds helper functions like `to` to `pm.response`