How to use the postman-collection.Item 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
const headerList = new pmCollection.HeaderList(null, [header]);

headerList.contentSize(); // $ExpectType number

pmCollection.HeaderList.isHeaderList(headerList); // $ExpectType boolean

// ItemDefinition Tests

const itemDef: pmCollection.ItemDefinition = {};
itemDef.request; // $ExpectType RequestDefinition | undefined
itemDef.responses; // $ExpectType ResponseDefinition[] | undefined
itemDef.events; // $ExpectType EventDefinition[] | undefined

// Item Tests
let item = new pmCollection.Item();
item = new pmCollection.Item(itemDef);

item.events; // $ExpectType EventList
item.request; // $ExpectType Request
item.responses; // $ExpectType PropertyList

item.authorizeRequestUsing("string"); // $ExpectType void
item.authorizeRequestUsing({}); // $ExpectType void
item.authorizeRequestUsing("string", new pmCollection.VariableList(item, [])); // $ExpectType void

item.getAuth(); // $ExpectType RequestAuth

item.getEvents(); // $ExpectType Event[]
item.getEvents("string"); // $ExpectType Event[]

pmCollection.Item.isItem(item); // $ExpectType boolean
github DefinitelyTyped / DefinitelyTyped / types / postman-collection / postman-collection-tests.ts View on Github external
const headerList = new pmCollection.HeaderList(null, [header]);

headerList.contentSize(); // $ExpectType number

pmCollection.HeaderList.isHeaderList(headerList); // $ExpectType boolean

// ItemDefinition Tests

const itemDef: pmCollection.ItemDefinition = {};
itemDef.request; // $ExpectType RequestDefinition | undefined
itemDef.responses; // $ExpectType ResponseDefinition[] | undefined
itemDef.events; // $ExpectType EventDefinition[] | undefined

// Item Tests
let item = new pmCollection.Item();
item = new pmCollection.Item(itemDef);

item.events; // $ExpectType EventList
item.request; // $ExpectType Request
item.responses; // $ExpectType PropertyList

item.authorizeRequestUsing("string"); // $ExpectType void
item.authorizeRequestUsing({}); // $ExpectType void
item.authorizeRequestUsing("string", new pmCollection.VariableList(item, [])); // $ExpectType void

item.getAuth(); // $ExpectType RequestAuth

item.getEvents(); // $ExpectType Event[]
item.getEvents("string"); // $ExpectType Event[]

pmCollection.Item.isItem(item); // $ExpectType boolean
github postmanlabs / postman-runtime / lib / runner / request-helpers-presend.js View on Github external
// sync all auth system parameters to the original auth
                originalAuthParams && auth.parameters().each(function (param) {
                    param && param.system &&
                        originalAuthParams.upsert({key: param.key, value: param.value, system: true});
                });

                // authHandler gave a go, sign the request
                if (success) { return authSignHook(); }

                // auth gave a no go, but no intermediate request
                if (!request) { return done(); }

                // prepare for sending intermediate request
                var replayController = new ReplayController(context.replayState, run),
                    item = new sdk.Item({request: request});

                // auth handler gave a no go, and an intermediate request.
                // make the intermediate request the response is passed to `init` hook
                replayController.requestReplay(context,
                    item,
                    // marks the auth as source for intermediate request
                    {source: auth.type + DOT_AUTH},
                    function (err, response) {
                        // errors for intermediate requests are passed to request callback
                        // passing it here will add it to original request as well, so don't do it
                        if (err) { return done(); }

                        // pass the response to Auth `init` hook
                        authHandler.init(authInterface, response, function (error) {
                            if (error) {
                                // warn about the err
github postmanlabs / postman-runtime / lib / runner / create-item-context.js View on Github external
module.exports = function (payload, defaults) {
    // extract properties from defaults that can/should be reused in new context
    var context = defaults ? _.pick(defaults, SAFE_CONTEXT_PROPERTIES) : {};

    // set cursor to context
    !context.coords && (context.coords = payload.coords);

    // save original item for reference
    context.originalItem = payload.item;

    // we clone item from the payload, so that we can make any changes we need there, without mutating the
    // collection
    context.item = new sdk.Item(payload.item.toJSON());

    // get a reference to the Auth instance from the item, so changes are synced back
    context.auth = context.originalItem.getAuth();

    /**
     * @typedef {Object} ItemContext
     * @property {Object} coords - current cursor
     * @property {Item} originalItem - reference to the item in the collection
     * @property {Item} item -  Holds a copy of the item given in the payload, so that it can be manipulated
     * as necessary
     * @property {RequestAuthBase|undefined} auth - If present, is the instance of Auth in the collection, which
     * is changed as necessary using intermediate requests, etc.
     * @property {ReplayState} replayState - has context on number of replays(if any) for this request
     */
    return context;
};
github postmanlabs / postman-runtime / lib / runner / extensions / request.command.js View on Github external
// @todo - resolve variables in a more graceful way
        var variableDefinitions = [
                // extract the variable list from variable scopes
                // @note: this is the order of precedence for variable resolution - don't change it
                payload._variables.values,
                payload.data,
                payload.environment.values,
                payload.collectionVariables.values,
                payload.globals.values
            ],
            item,
            auth;

        // @todo - no need to sync variables when SDK starts supporting resolution from scope directly
        item = context.item = new sdk.Item(context.item.toObjectResolved(null,
            variableDefinitions, {ignoreOwnVariables: true}));

        auth = context.auth;

        // Re-parse the URL, because variables have been resolved now, and things might be moved around
        item.request.url = new (sdk.Url)(item.request.url.toString());

        // resolve variables in auth
        auth && (context.auth = new sdk.RequestAuth(auth.toObjectResolved(null,
            variableDefinitions, {ignoreOwnVariables: true})));
    };
github postmanlabs / postman-runtime / lib / runner / extensions / event.command.js View on Github external
sanitizeFiles(request, function (err, request, sanitisedFiles) {
                            if (err) {
                                return this.host.dispatch(EXECUTION_RESPONSE_EVENT_BASE + id, requestId, err);
                            }

                            var nextPayload;

                            // if request is sanitized send a warning
                            if (!_.isEmpty(sanitisedFiles)) {
                                this.triggers.console(scriptCursor, 'warn',
                                    'uploading files from scripts is not allowed');
                            }

                            nextPayload = {
                                item: new sdk.Item({request: request}),
                                coords: scriptCursor,
                                // @todo - get script type from the sandbox
                                source: 'script',
                                // abortOnError makes sure request command bubbles errors
                                // so we can pass it on to the callback
                                abortOnError: true
                            };

                            // create context for executing this request
                            nextPayload.context = createItemContext(nextPayload);

                            this.immediate('httprequest', nextPayload).done(function (result) {
                                this.host.dispatch(
                                    EXECUTION_RESPONSE_EVENT_BASE + id,
                                    requestId,
                                    null,
github postmanlabs / openapi-to-postman / lib / util.js View on Github external
}
      default : {
        reqName = operation[this.options.requestNameSource];
        break;
      }
    }
    if (!reqName) {
      throw new openApiErr(`requestNameSource (${this.options.requestNameSource})` +
        ` in options is invalid or property does not exist in ${operationItem.path}`);
    }

    // handling authentication here (for http type only)
    authHelper = this.getAuthHelper(openapi, operation.security);

    // creating the request object
    item = new sdk.Item({
      name: reqName,
      request: {
        description: operation.description,
        url: displayUrl || baseUrl,
        name: reqName,
        method: operationItem.method.toUpperCase()
      }
    });

    // using the auth helper
    authMeta = operation['x-postman-meta'];
    if (authMeta && authMeta.currentHelper && authMap[authMeta.currentHelper]) {
      let thisAuthObject = {
        type: authMap[authMeta.currentHelper]
      };
github postmanlabs / swagger2-postman2 / convert.js View on Github external
else if (thisParams[param].in === 'path') {
                    if (!rPathVariables) {
                        rPathVariables = {};
                    }
                    rPathVariables[thisParams[param].name] = defaultVal;
                }
            }
        }

        var request = new Request({
            method: rMethod,
            name: rName,
            url: rUrl,
            header: rHeaders
        }),
        item = new Item({name: rName});
        

        var requestBodyJSON = {
            mode: rDataMode
        };
        if (rDataMode === "formdata") {
            requestBodyJSON.formdata = rData;
        }
        else if (rDataMode === "urlencoded") {
            requestBodyJSON.urlencoded = rData;
        }
        else {
            requestBodyJSON.raw = JSON.stringify(rData, null, 2);
        }
        request.body = new RequestBody(requestBodyJSON);
        item.request = request;