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,0BAA2B,SAAU,GAEjC,IAAI,EAAO,KAAK,sBAAsB,UAAW,GACjD,GAAI,EAAK,MACL,OAAO,KAAK,YAAY,EAAK,MAAO,EAAK,UAG7C,IAAI,EAAU,EAAK,SAAW,CAAC,EAC3B,EAAW,EAAK,UAAY,KAGhC,MAA8B,iBAApB,GAAyD,IAAzB,EAAc,OAC7C,KAAK,YAAY,kDAAmD,GAGrE,KAAK,KAAK,KAAK,SAAU,6BAA8B,CACzD,cAAe,EACf,WAAW,EAAQ,YACpB,KAAM,EAAU,EAAQ,EAAQ,EAG3C,EAKA,kBAAmB,WAGf,OADA,KAAK,eACE,KAAK,WAChB,EAER,CAEA,OAAO,QAAU","file":"/npm/loop54-js-connector@1.16.186/lib/loop54-js-connector-client.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/loop54-js-connector@1.16.186/lib/loop54-js-connector-client.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar axios = _interopDefault(require('axios'));\n\nlet cookies = {\n    \n    getItem: function (sKey) {\n        if (!sKey || typeof(document) == \"undefined\") {\n            return null;\n        }\n        return decodeURIComponent(document.cookie.replace(new RegExp(\"(?:(?:^|.*;)\\\\s*\" + encodeURIComponent(sKey).replace(/[\\-\\.\\+\\*]/g, \"\\\\$&\") + \"\\\\s*\\\\=\\\\s*([^;]*).*$)|^.*$\"), \"$1\")) || null;\n    },\n    \n    setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {\n        if (!sKey || /^(?:expires|max\\-age|path|domain|secure)$/i.test(sKey) || typeof(document) == \"undefined\") {\n            return false;\n        }\n        var sExpires = \"\";\n        if (vEnd) {\n            switch (vEnd.constructor) {\n            case Number:\n                sExpires = vEnd === Infinity ? \"; expires=Fri, 31 Dec 9999 23:59:59 GMT\" : \"; max-age=\" + vEnd;\n                break;\n            case String:\n                sExpires = \"; expires=\" + vEnd;\n                break;\n            case Date:\n                sExpires = \"; expires=\" + vEnd.toUTCString();\n                break;\n            }\n        }\n        document.cookie = encodeURIComponent(sKey) + \"=\" + encodeURIComponent(sValue) + sExpires + (sDomain ? \"; domain=\" + sDomain : \"\") + (sPath ? \"; path=\" + sPath : \"\") + (bSecure ? \"; secure\" : \"\");\n        return true;\n    },\n    \n    removeItem: function (sKey, sPath, sDomain) {\n        if (!this.hasItem(sKey)) {\n            return false;\n        }\n        document.cookie = encodeURIComponent(sKey) + \"=; expires=Thu, 01 Jan 1970 00:00:00 GMT\" + (sDomain ? \"; domain=\" + sDomain : \"\") + (sPath ? \"; path=\" + sPath : \"\");\n        return true;\n    },\n    \n    hasItem: function (sKey) {\n        if (!sKey || /^(?:expires|max\\-age|path|domain|secure)$/i.test(sKey)) {\n            return false;\n        }\n        return (new RegExp(\"(?:^|;\\\\s*)\" + encodeURIComponent(sKey).replace(/[\\-\\.\\+\\*]/g, \"\\\\$&\") + \"\\\\s*\\\\=\")).test(document.cookie);\n    },\n    \n    keys: function () {\n        var aKeys = document.cookie.replace(/((?:^|\\s*;)[^\\=]+)(?=;|$)|^\\s*|\\s*(?:\\=[^;]*)?(?:\\1|$)/g, \"\").split(/\\s*(?:\\=[^;]*)?;\\s*/);\n        for (var nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) {\n            aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);\n        }\n        return aKeys;\n    }\n};\n\nlet core = {\n\n    versions: {\n        // Do not change `libVersion` manually. See README.\n        // The \"5454545454-build-number\" part will be replaced automatically during the build process.\n        libVersion: \"1.16.186\",\n        apiVersion: \"V3\"\n    },\n\n    userIdCookieKey: \"Loop54User\",\n    userIdCookiePath: \"/\",\n\n    setUserId: function () {\n        var text = \"\";\n        var possible = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n        for (var i = 0; i < 10; i++) {\n            text += possible.charAt(Math.floor(Math.random() * possible.length));\n        }\n        cookies.setItem(core.userIdCookieKey, text, 365 * 24 * 60 * 60, core.userIdCookiePath); //365 days\n        return text;\n    },\n\n    getUserId: function () {\n        var existing = cookies.getItem(core.userIdCookieKey);\n        if (existing) {\n            return existing;\n        }\n        return core.setUserId();\n    },\n\n    removeUserId: function () {\n        return cookies.removeItem(core.userIdCookieKey, core.userIdCookiePath);\n    },\n\n    call: function (endpoint, path, body, method, callback, userId, apiKey, customHeaders) {\n\n        if(!userId)\n            userId = core.getUserId();\n\n        body = JSON.parse(JSON.stringify(body));\n\n        var url = core.ensureProtocol(endpoint) + path;\n\n        var headers = {\n            \"user-id\": userId,\n            \"lib-version\": \"JS:\" + core.versions.libVersion,\n            \"api-version\": core.versions.apiVersion,\n        };\n\n        if(customHeaders){\n            for (const key in customHeaders) {\n                headers[key] = customHeaders[key];\n            }\n        }\n\n        if(apiKey)\n            headers[\"Loop54-key\"] = apiKey;\n\n        var cancellationSource = axios.CancelToken.source();\n        var request = axios({\n            method: method ? method : \"post\",\n            url: url,\n            headers: headers,\n            responseType: \"json\",\n            data: body,\n            cancelToken: cancellationSource.token\n        })\n        .then(function (response) {\n\n            if(response.status === 200)\n                return response;\n            else {\n                return Promise.reject(response);\n            }\n        })\n        .catch(function (error) {\n\n            if (axios.isCancel(error)) {\n                return { cancelled:true };\n            }\n        \n            var ret = error;\n\n            //if there is no data, that means something went wrong before we got a response\n            //construct a \"fake\" response object with the same properties as an error from the engine\n            if(!ret.response || !ret.response.data) {\n                ret = {\n                    data: {\n                        error: {\n                            title: error.message\n                        }\n                    }\n                };\n            }\n            return Promise.reject(ret);\n        });\n        \n        request.cancel = function () {\n            cancellationSource.cancel();\n            return request;\n        };\n        \n        if (callback) {\n            request.then(callback).catch(function(response){\n                callback(response);\n            });\n        }\n            \n        return request;\n    },\n\n    ensureProtocol: function (url) {\n\n        //make sure it starts with http or https\n        if (!url.startsWith(\"http://\") && !url.startsWith(\"https://\"))\n            url = \"https://\" + url;\n\n        //make sure it doesnt end with slash\n        while (url.endsWith(\"/\"))\n            url = url.substring(0, url.length - 1);\n\n        return url;\n\n    },\n\n    returnError: function (message, callback) {\n\n        //construct a \"fake\" response object with the same properties as an error from the engine\n        var ret = {\n            data: {\n                error: {\n                    title: message\n                }\n            }\n        };\n\n        if (callback) {\n            return callback(ret);\n        } else {\n            return Promise.reject(ret);\n        }\n    },\n\n    getOptionsAndCallback: function (args, numRequiredParameters, maxNumParameters) {\n\n        //too few parameters\n        if (args.length < numRequiredParameters)\n            return {\n                error: \"Expected at least \" + numRequiredParameters + \" parameters.\"\n            };\n\n        //no options or other extra parameter\n        if (args.length == numRequiredParameters)\n            return {};\n        \n        if(!maxNumParameters)\n            maxNumParameters = numRequiredParameters + 2;\n\n        //too many parameters\n        if (args.length > maxNumParameters)\n            return {\n                error: \"Expected at most \" + (maxNumParameters) + \" parameters.\"\n            };\n\n        var options;\n        var callback;\n\n        //loop through the last parameters to find options and callback\n        for (var i = numRequiredParameters; i < args.length; i++) {\n            if (typeof(args[i]) === \"function\")\n                callback = args[i];\n            else if (typeof(args[i]) === \"object\")\n                options = args[i];\n        }\n\n        return {\n            options: options,\n            callback: callback\n        };\n    },\n\n    validateEvent: function(event) {\n        if (typeof event !== 'object') {\n            return \"event needs to be an object.\";\n        }\n        if (typeof event.type !== \"string\" || event.type.length === 0) {\n            return \"type needs to be set, standard events are \\\"click\\\", \\\"addtocart\\\" and \\\"purchase\\\".\";\n        }\n        if(!event.entity) {\n            return \"entity needs to be set.\";\n        }\n        if (!event.entity.type) {\n            return \"entity needs to have a \\\"type\\\" set, usually this is \\\"Product\\\".\";\n        }\n        if (!event.entity.id) {\n            return \"entity needs to have an \\\"id\\\" provided, this is usually the productId.\";\n        }\n\n        return null;\n    },\n\n    deleteCustomData: function(options){\n        let ret = JSON.parse(JSON.stringify(options));\n        delete ret.customData;\n\n        return ret;\n    }\n};\n\n/**\n * Returns a client that can be used to communicate with the engine.\n * @param {string} endpoint The complete URL to the engine.\n*/\nfunction getLoop54Client (endpoint, userId, apiKey, customHeaders) {\n\n    if (typeof endpoint !== 'string' || endpoint.length === 0) {\n        throw new Error('Parameter \"endpoint\" must be present and have a non-zero length.');\n    }\n\n    const currentUserPlaceholder = \"(CurrentUser)\";\n\n    return {\n\n        /**\n         * The engine endpoint this client communicates with.\n         */\n        endpoint: endpoint,\n\n        /**\n         * The user ID to use for communications. If left falsy, cookies will be used to track user ID.\n         */\n        userId: userId,\n\n        /**\n         * The api key to use for communications. This is required for administrative operations.\n         */\n        apiKey: apiKey,\n\n        /**\n         * Object of custom headers to be set with the calls.\n         */\n        customHeaders: customHeaders,\n\n        /**\n         * Used for performing autocomplete requests to the engine.\n         * @param {string} searchTerm The query to find suggestions.\n         */\n        autoComplete: function (query) {\n\n            var args = core.getOptionsAndCallback(arguments, 1);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            if (typeof(query) !== \"string\" || query.length === 0) {\n                return core.returnError(\"query is either missing or not a string\", callback);\n            }\n\n            var req = core.call(this.endpoint, \"/autoComplete\", {\n                    query: query,\n                    queriesOptions: core.deleteCustomData(options),\n                    customData:options.customData\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for tracking a user interaction.\n         * @param {string} eventType The type of event. Typically \"click\", \"addtocart\" or \"purchase\".\n         * @param {object} entity The entity that was interacted with. Must have properties \"type\" and \"id\".\n         * @param {string} orderId The id of the order. Typically only used with purchase events.\n         * @param {number} quantity The quantity of this product in the order. Typically only used with purchase events.\n         * @param {number} revenue The revenue for this product in the order. Typically only used with purchase events.\n         */\n        createEvent: function (eventType, entity, orderId, quantity, revenue) {\n\n            var args = core.getOptionsAndCallback(arguments, 2, 7);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            var event = {\n                type: eventType,\n                entity: entity\n            };\n\n            // purchase event extra attributes\n            if (orderId) {\n                event.orderId = orderId;\n            }\n            if (quantity) {\n                event.quantity = parseFloat(quantity);\n            }\n            if (revenue) {\n                event.revenue = parseFloat(revenue);\n            }\n\n            var error = core.validateEvent(event, callback);\n\n            if(error)\n                return core.returnError(error, callback);\n\n            var req = core.call(this.endpoint, \"/createEvents\", {\n                events: [event],\n                customData:options.customData\n            }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for tracking a multiple user interactions, for instance when purchasing multiple products at once.\n         * @param {array} events The events to push. See createEvent for detailed information about events.\n         */\n        createEvents: function (events) {\n\n            var args = core.getOptionsAndCallback(arguments, 1);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            if (!Array.isArray(events) || events.length === 0) {\n                return core.returnError(\"Events must be a non-empty array\", callback);\n            }\n\n            if (events.some(core.validateEvent)) {\n                return core.returnError(\n                    \"Malformed event errors: [\" + events.map(core.validateEvent).filter(function (e) {\n                            return e;\n                        }).map(function (e) {\n                                return '\"' + e + '\"';\n                            }).join(\",\") + \"]\",\n                    callback\n                )\n            }\n\n            var req = core.call(this.endpoint, \"/createEvents\", {\n                events: events,\n                customData:options.customData\n            }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for performing getRelatedEntities requests to the engine.\n         * @param {object} entity The entity for which to find related entities.\n         */\n        getRelatedEntities: function (entity) {\n\n            var args = core.getOptionsAndCallback(arguments, 1, 4);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            //validate entity\n            if (typeof(entity) !== \"object\" || !entity.type || !entity.id) {\n                return core.returnError('entity must be an object with properties \"type\" and \"id\".', callback);\n            }\n\n            var req = core.call(this.endpoint, \"/getRelatedEntities\", {\n                    entity: entity,\n                    resultsOptions: core.deleteCustomData(options),\n                    customData: options.customData,\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for performing getComplementaryEntities requests to the engine.\n         * @param {object} entity The entity for which to find complementary entities.\n         */\n        getComplementaryEntities: function (entity) {\n\n            var args = core.getOptionsAndCallback(arguments, 1, 4);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            //validate entity\n            if (typeof(entity) !== \"object\" || !entity.type || !entity.id) {\n                return core.returnError('entity must be an object with properties \"type\" and \"id\".', callback);\n            }\n\n            var req = core.call(this.endpoint, \"/getComplementaryEntities\", {\n                    entity: entity,\n                    resultsOptions: core.deleteCustomData(options),\n                    customData: options.customData,\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for performing getBasketRecommendations requests to the engine.\n         * @param {object[]} entities The set of entities in the basket to get recommendations for.\n         */\n        getBasketRecommendations: function (entities) {\n\n            var args = core.getOptionsAndCallback(arguments, 1, 4);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            //validate entities\n            if (!Array.isArray(entities) || entities.filter(entity => entity.type && entity.id).length !== entities.length) {\n                return core.returnError('entities must be a non-empty array where each item is an object with properties \"type\" and \"id\".', callback);\n            }\n\n            var req = core.call(this.endpoint, \"/getBasketRecommendations\", {\n                    entities: entities,\n                    resultsOptions: core.deleteCustomData(options),\n                    customData: options.customData,\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for performing getRecommendedEntities requests to the engine.\n         */\n        getRecommendedEntities: function () {\n            var args = core.getOptionsAndCallback(arguments, 0, 2);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            var req = core.call(this.endpoint, \"/getRecommendedEntities\", {\n                    resultsOptions: core.deleteCustomData(options),\n                    customData: options.customData,\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for performing getRecentEntities requests to the engine for the current user.\n         * @param {string} behaviorType The interaction or navigation type to include (such as \"click\", \"purchase\" or \"search\").\n         * @param {string[]} [entityType] The entity types to include (such as \"Product\" or \"Query\") or null for all.\n         */\n        getRecentEntitiesForCurrentUser: function (behaviorType, entityType) {\n            return this.getRecentEntities(behaviorType, currentUserPlaceholder, entityType);\n        },\n\n        /**\n         * Used for performing getRecentEntities requests to the engine.\n         * @param {string} behaviorType The interaction or navigation type to include (such as \"click\", \"purchase\" or \"search\").\n         * @param {string} [forUserId] User ID (normally the same as the one in the User-Id header) to retrieve the most recent entities for that user, null or undefined to retrieve the globally most recent entities.\n         * @param {string[]} [entityType] The entity types to include (such as \"Product\" or \"Query\") or null for all.\n         */\n        getRecentEntities: function (behaviorType, forUserId, entityType) {\n            var argumentsArray = Array.prototype.slice.call(arguments);\n\n            if (typeof forUserId !== \"string\" && forUserId !== null) {\n                argumentsArray.splice(1, 0, null);\n                forUserId = null;\n            }\n            if (!Array.isArray(entityType) && entityType !== null) {\n                argumentsArray.splice(2, 0, null);\n                entityType = null;\n            }\n\n            var args = core.getOptionsAndCallback(argumentsArray.slice(2), 1);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            var req = core.call(this.endpoint, \"/getRecentEntities\", {\n                    behaviorType,\n                    forUserId,\n                    entityType,\n                    resultsOptions: core.deleteCustomData(options),\n                    customData: options.customData,\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for performing getPopularEntities requests to the engine for the current user.\n         * @param {string} behaviorType The interaction or navigation type to include (such as \"click\", \"purchase\" or \"search\").\n         * @param {string[]} [entityType] The entity types to include (such as \"Product\" or \"Query\") or null for all.\n         */\n        getPopularEntitiesForCurrentUser: function (behaviorType, entityType) {\n            return this.getPopularEntities(behaviorType, currentUserPlaceholder, entityType);\n        },\n\n        /**\n         * Used for performing getPopularEntities requests to the engine.\n         * @param {string} behaviorType The interaction or navigation type to include (such as \"click\", \"purchase\" or \"search\").\n         * @param {string} [forUserId] User ID (normally the same as the one in the User-Id header) to retrieve the most common entities for that user, null or undefined to retrieve the globally most common entities.\n         * @param {string[]} [entityType] The entity types to include (such as \"Product\" or \"Query\") or null for all.\n         */\n        getPopularEntities: function (behaviorType, forUserId, entityType) {\n            var argumentsArray = Array.prototype.slice.call(arguments);\n\n            if (typeof forUserId !== \"string\" && forUserId !== null) {\n                argumentsArray.splice(1, 0, null);\n                forUserId = null;\n            }\n            if (!Array.isArray(entityType) && entityType !== null) {\n                argumentsArray.splice(2, 0, null);\n                entityType = null;\n            }\n\n            var args = core.getOptionsAndCallback(argumentsArray.slice(2), 1);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            var req = core.call(this.endpoint, \"/getPopularEntities\", {\n                    behaviorType,\n                    forUserId,\n                    entityType,\n                    resultsOptions: core.deleteCustomData(options),\n                    customData: options.customData,\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for performing getEntitiesByAttribute requests to the engine.\n         * @param {string} attributeName The name of the attribute for which to get entities.\n         * @param {any} attributeValues The value of the attribute for which to get entities. This can be a single value, or an array of values.\n         */\n        getEntitiesByAttribute: function (attributeName, attributeValues) {\n\n            var args = core.getOptionsAndCallback(arguments, 2);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            //validate arguments\n            if (typeof(attributeName) !== \"string\") {\n                return core.returnError(\"Missing argument attributeName or attributeName was not of type string.\", callback);\n            }\n\n            //copy alias to separate variable and remove it from options\n            var alias = options.requestAlias;\n            if (alias)\n                delete options.requestAlias;\n\n            var req = core.call(this.endpoint, \"/getEntitiesByAttribute\", {\n                    attribute: {\n                        name: attributeName,\n                        value: attributeValues\n                    },\n                    requestAlias: alias,\n                    resultsOptions: core.deleteCustomData(options),\n                    customData:options.customData\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for performing getEntities requests to the engine.\n         */\n        getEntities: function () {\n\n            var args = core.getOptionsAndCallback(arguments, 0);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            var req = core.call(this.endpoint, \"/getEntities\", {\n                    resultsOptions: core.deleteCustomData(options),\n                    customData:options.customData\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for performing search requests to the engine.\n         * @param {string} query The query to search for\n         */\n        search: function (query) {\n\n            var args = core.getOptionsAndCallback(arguments, 1);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            //validate input\n            if (typeof(query) !== \"string\" || query.length === 0) {\n                return core.returnError(\"query is either missing or not a string\", callback);\n            }\n\n            var req = core.call(this.endpoint, \"/search\", {\n                    query: query,\n                    relatedResultsOptions: options.relatedResultsOptions,\n                    spellingSuggestionsOptions: options.spellingSuggestionsOptions,\n                    relatedQueriesOptions: options.relatedQueriesOptions,\n                    resultsOptions: {\n                        sortBy: options.sortBy,\n                        filter: options.filter,\n                        take: options.take,\n                        skip: options.skip,\n                        facets: options.facets\n                    },\n                    customData:options.customData\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for telling the engine to re-sync the catalog.\n         */\n        sync: function () {\n\n            var args = core.getOptionsAndCallback(arguments, 0);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            var req = core.call(this.endpoint, \"/sync\", {\n                    customData:options.customData\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used to perform a request to get information about attributes, indexed and non-indexed.\n         */\n        getIndexedAttributes:  function () {\n\n            var args = core.getOptionsAndCallback(arguments, 0);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            var req = core.call(this.endpoint, \"/getIndexedAttributes\", {\n                    customData:options.customData\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used to perform a request to get a list of all unique values that are indexed for the provided attribute.\n         * @param {string} attributeName The name of the attribute for which to fetch indexed values.\n         */\n        getIndexedAttributeValues: function (attributeName) {\n\n            var args = core.getOptionsAndCallback(arguments, 1);\n            if (args.error) {\n                return core.returnError(args.error, args.callback);\n            }\n\n            var options = args.options || {};\n            var callback = args.callback || null;\n\n            //validate input\n            if (typeof(attributeName) !== \"string\" || attributeName.length === 0) {\n                return core.returnError(\"attributeName is either missing or not a string\", callback);\n            }\n\n            var req = core.call(this.endpoint, \"/getIndexedAttributeValues\", {\n                    attributeName: attributeName,\n                    customData:options.customData\n                }, null, callback, userId, apiKey, customHeaders);\n\n            return req;\n        },\n\n        /**\n         * Used for removing current userId cookie and setting a new one.\n         */\n        generateNewUserId: function () {\n\n            core.removeUserId();\n            return core.setUserId();\n        }\n    }\n}\n\nmodule.exports = getLoop54Client;\n"]}