diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index b7181b012..9b69907c6 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -3,6 +3,7 @@ unreleased: - GH-1366 Fixed a bug where $randomAvatarImage was returning an invalid URL chores: - GH-1362 Updated `Request~size` to handle `downloadedBytes` property + - GH-1364 Added support for `prefix` in VariableScope 4.4.0: date: 2024-02-28 diff --git a/lib/collection/variable-scope.js b/lib/collection/variable-scope.js index 64f8759d9..7cf99bee9 100644 --- a/lib/collection/variable-scope.js +++ b/lib/collection/variable-scope.js @@ -26,6 +26,7 @@ var _ = require('../util').lodash, * @typedef VariableScope.definition * @property {String} [id] ID of the scope * @property {String} [name] A name of the scope + * @property {String} [prefix] A prefix to be used for variable names in this scope * @property {Array.} [values] A list of variables defined in an array in form of `{name:String, * value:String}` * @@ -140,16 +141,6 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ { */ _postman_propertyRequiresId: true, - /** - * Defines the prefix associated with the VariableList variables for internal use. - * - * @private - * @type {String} - * - */ - prefix: '', - - /** * @private * @deprecated discontinued in v4.0 @@ -190,7 +181,9 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ { * false otherwise */ has: function (key) { - var variable = this.values.oneNormalizedVariable(this.prefix + key), + key = (this.prefix || '') + key; + + var variable = this.values.oneNormalizedVariable(key), i, ii; @@ -213,7 +206,9 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ { * @returns {*} The value of the specified variable across scopes. */ get: function (key) { - var variable = this.values.oneNormalizedVariable(this.prefix + key), + key = (this.prefix || '') + key; + + var variable = this.values.oneNormalizedVariable(key), i, ii; @@ -236,10 +231,12 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ { * @param {Variable.types} [type] - Optionally, the value of the variable can be set to a type */ set: function (key, value, type) { - var variable = this.values.oneNormalizedVariable(this.prefix + key), + key = (this.prefix || '') + key; + + var variable = this.values.oneNormalizedVariable(key), // create an object that will be used as setter - update = { key: this.prefix + key, value: value }; + update = { key, value }; _.isString(type) && (update.type = type); @@ -262,11 +259,13 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ { * @param {String} key - */ unset: function (key) { + key = (this.prefix || '') + key; + var lastDisabledVariable; this.values.remove((variable) => { // bail out if variable name didn't match - if (variable.key !== (this.prefix + key)) { + if (variable.key !== key) { return false; } @@ -283,7 +282,7 @@ _.assign(VariableScope.prototype, /** @lends VariableScope.prototype */ { // restore the reference with the last disabled variable if (lastDisabledVariable) { - this.values.reference[this.prefix + key] = lastDisabledVariable; + this.values.reference[key] = lastDisabledVariable; } // track the change if mutation tracking is enabled diff --git a/types/index.d.ts b/types/index.d.ts index c70741ffe..a680117da 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2333,6 +2333,7 @@ declare module "postman-collection" { * } * @property [id] - ID of the scope * @property [name] - A name of the scope + * @property [prefix] - A prefix to be used for variable names in this scope * @property [values] - A list of variables defined in an array in form of `{name:String, * value:String}` */