{
"version": 3,
"sources": ["../../../node_modules/fuzzysort/fuzzysort.js", "../../../node_modules/tslib/tslib.es6.mjs", "../../../node_modules/@segment/analytics-core/dist/esm/emitter/interface.js", "../../../node_modules/@segment/analytics-core/dist/esm/plugins/index.js", "../../../node_modules/@segment/analytics-core/dist/esm/events/interfaces.js", "../../../node_modules/dset/dist/index.mjs", "../../../node_modules/@segment/analytics-core/src/utils/pick.ts", "../../../node_modules/@segment/analytics-core/src/validation/errors.ts", "../../../node_modules/@segment/analytics-core/src/validation/helpers.ts", "../../../node_modules/@segment/analytics-core/src/validation/assertions.ts", "../../../node_modules/@segment/analytics-core/src/events/index.ts", "../../../node_modules/@segment/analytics-core/src/callback/index.ts", "../../../node_modules/@segment/analytics-generic-utils/src/create-deferred/create-deferred.ts", "../../../node_modules/@segment/analytics-generic-utils/src/create-deferred/index.ts", "../../../node_modules/@segment/analytics-generic-utils/src/emitter/emitter.ts", "../../../node_modules/@segment/analytics-generic-utils/src/emitter/index.ts", "../../../node_modules/@segment/analytics-generic-utils/src/index.ts", "../../../node_modules/@segment/analytics-core/src/priority-queue/backoff.ts", "../../../node_modules/@segment/analytics-core/src/priority-queue/index.ts", "../../../node_modules/@lukeed/uuid/dist/index.mjs", "../../../node_modules/@segment/analytics-core/src/logger/index.ts", "../../../node_modules/@segment/analytics-core/src/stats/index.ts", "../../../node_modules/@segment/analytics-core/src/context/index.ts", "../../../node_modules/@segment/analytics-core/src/utils/group-by.ts", "../../../node_modules/@segment/analytics-core/src/utils/is-thenable.ts", "../../../node_modules/@segment/analytics-core/src/task/task-group.ts", "../../../node_modules/@segment/analytics-core/src/queue/delivery.ts", "../../../node_modules/@segment/analytics-core/src/queue/event-queue.ts", "../../../node_modules/@segment/analytics-core/dist/esm/analytics/index.js", "../../../node_modules/@segment/analytics-core/src/analytics/dispatch.ts", "../../../node_modules/@segment/analytics-core/src/utils/bind-all.ts", "../../../node_modules/@segment/analytics-core/src/index.ts", "../../../node_modules/@segment/analytics-next/src/core/environment/index.ts", "../../../node_modules/@segment/analytics-next/src/core/connection/index.ts", "../../../node_modules/unfetch/src/index.mjs", "../../../node_modules/@segment/analytics-next/src/lib/get-global.ts", "../../../node_modules/@segment/analytics-next/src/lib/fetch.ts", "../../../node_modules/@segment/analytics-next/src/generated/version.ts", "../../../node_modules/@segment/analytics-next/src/lib/version-type.ts", "../../../node_modules/@segment/analytics-next/src/core/constants/index.ts", "../../../node_modules/@segment/analytics-next/src/core/stats/remote-metrics.ts", "../../../node_modules/@segment/analytics-next/src/core/stats/index.ts", "../../../node_modules/@segment/analytics-next/src/core/context/index.ts", "../../../node_modules/@segment/analytics-next/src/lib/priority-queue/index.ts", "../../../node_modules/@segment/analytics-next/src/lib/priority-queue/persisted.ts", "../../../node_modules/@segment/analytics-next/src/lib/global-analytics-helper.ts", "../../../node_modules/@segment/analytics-next/src/core/callback/index.ts", "../../../node_modules/@segment/analytics-next/src/core/auto-track.ts", "../../../node_modules/obj-case/index.js", "../../../node_modules/@segment/facade/lib/address.js", "../../../node_modules/@segment/facade/lib/clone.js", "../../../node_modules/@segment/facade/lib/is-enabled.js", "../../../node_modules/@segment/isodate/lib/index.js", "../../../node_modules/new-date/lib/milliseconds.js", "../../../node_modules/new-date/lib/seconds.js", "../../../node_modules/new-date/lib/index.js", "../../../node_modules/@segment/isodate-traverse/lib/index.js", "../../../node_modules/@segment/facade/lib/facade.js", "../../../node_modules/inherits/inherits_browser.js", "../../../node_modules/@segment/facade/lib/alias.js", "../../../node_modules/@segment/facade/lib/is-email.js", "../../../node_modules/@segment/facade/lib/group.js", "../../../node_modules/@segment/facade/lib/identify.js", "../../../node_modules/@segment/facade/lib/track.js", "../../../node_modules/@segment/facade/lib/page.js", "../../../node_modules/@segment/facade/lib/screen.js", "../../../node_modules/@segment/facade/lib/delete.js", "../../../node_modules/@segment/facade/lib/index.js", "../../../node_modules/@segment/analytics-next/src/lib/to-facade.ts", "../../../node_modules/@segment/analytics-next/src/plugins/middleware/index.ts", "../../../node_modules/@segment/analytics-next/src/core/query-string/pickPrefix.ts", "../../../node_modules/@segment/analytics-next/src/core/query-string/gracefulDecodeURIComponent.ts", "../../../node_modules/@segment/analytics-next/src/core/query-string/index.ts", "../../../node_modules/@segment/analytics-next/src/lib/parse-cdn.ts", "../../../node_modules/@segment/analytics-next/src/lib/merged-options.ts", "../../../node_modules/@segment/analytics-next/src/lib/load-script.ts", "../../../node_modules/@segment/analytics-next/src/core/stats/metric-helpers.ts", "../../../node_modules/@segment/analytics-next/src/lib/p-while.ts", "../../../node_modules/@segment/analytics-next/src/vendor/tsub/tsub.ts", "../../../node_modules/@segment/analytics-next/src/plugins/routing-middleware/index.ts", "../../../node_modules/@segment/analytics-next/src/lib/is-plan-event-enabled.ts", "../../../node_modules/@segment/analytics-next/src/plugins/ajs-destination/loader.ts", "../../../node_modules/@segment/analytics-next/src/plugins/ajs-destination/utils.ts", "../../../node_modules/@segment/analytics-next/src/plugins/ajs-destination/index.ts", "../../../node_modules/@segment/analytics.js-video-plugins/dist/index.umd.js", "../../../node_modules/@segment/analytics-next/src/plugins/legacy-video-plugins/index.ts", "../../../node_modules/@segment/analytics-next/src/plugins/schema-filter/index.ts", "../../../node_modules/@segment/analytics-next/src/plugins/remote-middleware/index.ts", "../../javascript/directory/filter.js", "../../../node_modules/@segment/analytics-next/src/core/arguments-resolver/index.ts", "../../../node_modules/@segment/analytics-next/src/core/events/index.ts", "../../../node_modules/@segment/analytics-next/src/core/page/get-page-context.ts", "../../../node_modules/@segment/analytics-next/src/lib/pick.ts", "../../../node_modules/@segment/analytics-next/src/core/plugin/index.ts", "../../../node_modules/@segment/analytics-next/src/core/queue/event-queue.ts", "../../../node_modules/@segment/analytics-next/src/core/user/index.ts", "../../../node_modules/@segment/analytics-next/src/lib/bind-all.ts", "../../../node_modules/js-cookie/dist/js.cookie.mjs", "../../../node_modules/@segment/analytics-next/src/core/user/tld.ts", "../../../node_modules/@segment/analytics-next/src/core/storage/localStorage.ts", "../../../node_modules/@segment/analytics-next/src/core/storage/memoryStorage.ts", "../../../node_modules/@segment/analytics-next/src/core/storage/types.ts", "../../../node_modules/@segment/analytics-next/src/core/storage/settings.ts", "../../../node_modules/@segment/analytics-next/src/core/storage/universalStorage.ts", "../../../node_modules/@segment/analytics-next/src/core/storage/index.ts", "../../../node_modules/@segment/analytics-next/src/lib/is-thenable.ts", "../../../node_modules/@segment/analytics-next/src/lib/get-process-env.ts", "../../../node_modules/@segment/analytics-next/src/lib/client-hints/index.ts", "../../../node_modules/@segment/analytics-next/src/plugins/remote-loader/index.ts", "../../../node_modules/@segment/analytics-next/src/plugins/segmentio/index.ts", "../../../node_modules/@segment/analytics-next/src/plugins/segmentio/batched-dispatcher.ts", "../../../node_modules/@segment/analytics-next/src/lib/on-page-change.ts", "../../../node_modules/@segment/analytics-next/src/plugins/segmentio/fetch-dispatcher.ts", "../../../node_modules/@segment/analytics-next/src/plugins/segmentio/normalize.ts", "../../../node_modules/@segment/analytics-next/src/plugins/segmentio/schedule-flush.ts", "../../../node_modules/@segment/analytics-next/src/core/inspector/index.ts", "../../../node_modules/@segment/analytics-next/src/index.ts", "../../../node_modules/@appsignal/javascript/node_modules/tslib/tslib.es6.mjs", "../../../node_modules/@appsignal/core/node_modules/tslib/tslib.es6.mjs", "../../../node_modules/@appsignal/core/src/utils/functional.ts", "../../../node_modules/@appsignal/core/src/utils/hashmap.ts", "../../../node_modules/@appsignal/core/src/utils/error.ts", "../../../node_modules/@appsignal/core/src/utils/url.ts", "../../../node_modules/@appsignal/core/src/utils/environment.ts", "../../../node_modules/@appsignal/core/src/serializable.ts", "../../../node_modules/@appsignal/javascript/src/version.ts", "../../../node_modules/@appsignal/javascript/src/environment.ts", "../../../node_modules/@appsignal/javascript/src/transports/xdomain.ts", "../../../node_modules/@appsignal/javascript/src/transports/xhr.ts", "../../../node_modules/@appsignal/javascript/src/transports/fetch.ts", "../../../node_modules/@appsignal/javascript/src/transports/node.ts", "../../../node_modules/@appsignal/javascript/src/api.ts", "../../../node_modules/@appsignal/javascript/src/span.ts", "../../../node_modules/@appsignal/javascript/src/queue.ts", "../../../node_modules/@appsignal/javascript/src/dispatcher.ts", "../../../node_modules/@appsignal/javascript/src/index.ts", "../../javascript/utils/logger.js", "../../javascript/utils/analytics.js", "../../javascript/directory/track.js"],
"sourcesContent": ["// https://github.com/farzher/fuzzysort v2.0.4\r\n/*\r\n SublimeText-like Fuzzy Search\r\n\r\n fuzzysort.single('fs', 'Fuzzy Search') // {score: -16}\r\n fuzzysort.single('test', 'test') // {score: 0}\r\n fuzzysort.single('doesnt exist', 'target') // null\r\n\r\n fuzzysort.go('mr', [{file:'Monitor.cpp'}, {file:'MeshRenderer.cpp'}], {key:'file'})\r\n // [{score:-18, obj:{file:'MeshRenderer.cpp'}}, {score:-6009, obj:{file:'Monitor.cpp'}}]\r\n\r\n fuzzysort.go('mr', ['Monitor.cpp', 'MeshRenderer.cpp'])\r\n // [{score: -18, target: \"MeshRenderer.cpp\"}, {score: -6009, target: \"Monitor.cpp\"}]\r\n\r\n fuzzysort.highlight(fuzzysort.single('fs', 'Fuzzy Search'), '', '')\r\n // Fuzzy Search\r\n*/\r\n\r\n// UMD (Universal Module Definition) for fuzzysort\r\n;((root, UMD) => {\r\n if(typeof define === 'function' && define.amd) define([], UMD)\r\n else if(typeof module === 'object' && module.exports) module.exports = UMD()\r\n else root['fuzzysort'] = UMD()\r\n})(this, _ => {\r\n 'use strict'\r\n\r\n var single = (search, target) => { if(search=='farzher')return{target:\"farzher was here (^-^*)/\",score:0,_indexes:[0]}\r\n if(!search || !target) return NULL\r\n\r\n var preparedSearch = getPreparedSearch(search)\r\n if(!isObj(target)) target = getPrepared(target)\r\n\r\n var searchBitflags = preparedSearch.bitflags\r\n if((searchBitflags & target._bitflags) !== searchBitflags) return NULL\r\n\r\n return algorithm(preparedSearch, target)\r\n }\r\n\r\n\r\n var go = (search, targets, options) => { if(search=='farzher')return[{target:\"farzher was here (^-^*)/\",score:0,_indexes:[0],obj:targets?targets[0]:NULL}]\r\n if(!search) return options&&options.all ? all(search, targets, options) : noResults\r\n\r\n var preparedSearch = getPreparedSearch(search)\r\n var searchBitflags = preparedSearch.bitflags\r\n var containsSpace = preparedSearch.containsSpace\r\n\r\n var threshold = options&&options.threshold || INT_MIN\r\n var limit = options&&options['limit'] || INT_MAX // for some reason only limit breaks when minified\r\n\r\n var resultsLen = 0; var limitedCount = 0\r\n var targetsLen = targets.length\r\n\r\n // This code is copy/pasted 3 times for performance reasons [options.keys, options.key, no keys]\r\n\r\n // options.key\r\n if(options && options.key) {\r\n var key = options.key\r\n for(var i = 0; i < targetsLen; ++i) { var obj = targets[i]\r\n var target = getValue(obj, key)\r\n if(!target) continue\r\n if(!isObj(target)) target = getPrepared(target)\r\n\r\n if((searchBitflags & target._bitflags) !== searchBitflags) continue\r\n var result = algorithm(preparedSearch, target)\r\n if(result === NULL) continue\r\n if(result.score < threshold) continue\r\n\r\n // have to clone result so duplicate targets from different obj can each reference the correct obj\r\n result = {target:result.target, _targetLower:'', _targetLowerCodes:NULL, _nextBeginningIndexes:NULL, _bitflags:0, score:result.score, _indexes:result._indexes, obj:obj} // hidden\r\n\r\n if(resultsLen < limit) { q.add(result); ++resultsLen }\r\n else {\r\n ++limitedCount\r\n if(result.score > q.peek().score) q.replaceTop(result)\r\n }\r\n }\r\n\r\n // options.keys\r\n } else if(options && options.keys) {\r\n var scoreFn = options['scoreFn'] || defaultScoreFn\r\n var keys = options.keys\r\n var keysLen = keys.length\r\n for(var i = 0; i < targetsLen; ++i) { var obj = targets[i]\r\n var objResults = new Array(keysLen)\r\n for (var keyI = 0; keyI < keysLen; ++keyI) {\r\n var key = keys[keyI]\r\n var target = getValue(obj, key)\r\n if(!target) { objResults[keyI] = NULL; continue }\r\n if(!isObj(target)) target = getPrepared(target)\r\n\r\n if((searchBitflags & target._bitflags) !== searchBitflags) objResults[keyI] = NULL\r\n else objResults[keyI] = algorithm(preparedSearch, target)\r\n }\r\n objResults.obj = obj // before scoreFn so scoreFn can use it\r\n var score = scoreFn(objResults)\r\n if(score === NULL) continue\r\n if(score < threshold) continue\r\n objResults.score = score\r\n if(resultsLen < limit) { q.add(objResults); ++resultsLen }\r\n else {\r\n ++limitedCount\r\n if(score > q.peek().score) q.replaceTop(objResults)\r\n }\r\n }\r\n\r\n // no keys\r\n } else {\r\n for(var i = 0; i < targetsLen; ++i) { var target = targets[i]\r\n if(!target) continue\r\n if(!isObj(target)) target = getPrepared(target)\r\n\r\n if((searchBitflags & target._bitflags) !== searchBitflags) continue\r\n var result = algorithm(preparedSearch, target)\r\n if(result === NULL) continue\r\n if(result.score < threshold) continue\r\n if(resultsLen < limit) { q.add(result); ++resultsLen }\r\n else {\r\n ++limitedCount\r\n if(result.score > q.peek().score) q.replaceTop(result)\r\n }\r\n }\r\n }\r\n\r\n if(resultsLen === 0) return noResults\r\n var results = new Array(resultsLen)\r\n for(var i = resultsLen - 1; i >= 0; --i) results[i] = q.poll()\r\n results.total = resultsLen + limitedCount\r\n return results\r\n }\r\n\r\n\r\n var highlight = (result, hOpen, hClose) => {\r\n if(typeof hOpen === 'function') return highlightCallback(result, hOpen)\r\n if(result === NULL) return NULL\r\n if(hOpen === undefined) hOpen = ''\r\n if(hClose === undefined) hClose = ''\r\n var highlighted = ''\r\n var matchesIndex = 0\r\n var opened = false\r\n var target = result.target\r\n var targetLen = target.length\r\n var indexes = result._indexes\r\n indexes = indexes.slice(0, indexes.len).sort((a,b)=>a-b)\r\n for(var i = 0; i < targetLen; ++i) { var char = target[i]\r\n if(indexes[matchesIndex] === i) {\r\n ++matchesIndex\r\n if(!opened) { opened = true\r\n highlighted += hOpen\r\n }\r\n\r\n if(matchesIndex === indexes.length) {\r\n highlighted += char + hClose + target.substr(i+1)\r\n break\r\n }\r\n } else {\r\n if(opened) { opened = false\r\n highlighted += hClose\r\n }\r\n }\r\n highlighted += char\r\n }\r\n\r\n return highlighted\r\n }\r\n var highlightCallback = (result, cb) => {\r\n if(result === NULL) return NULL\r\n var target = result.target\r\n var targetLen = target.length\r\n var indexes = result._indexes\r\n indexes = indexes.slice(0, indexes.len).sort((a,b)=>a-b)\r\n var highlighted = ''\r\n var matchI = 0\r\n var indexesI = 0\r\n var opened = false\r\n var result = []\r\n for(var i = 0; i < targetLen; ++i) { var char = target[i]\r\n if(indexes[indexesI] === i) {\r\n ++indexesI\r\n if(!opened) { opened = true\r\n result.push(highlighted); highlighted = ''\r\n }\r\n\r\n if(indexesI === indexes.length) {\r\n highlighted += char\r\n result.push(cb(highlighted, matchI++)); highlighted = ''\r\n result.push(target.substr(i+1))\r\n break\r\n }\r\n } else {\r\n if(opened) { opened = false\r\n result.push(cb(highlighted, matchI++)); highlighted = ''\r\n }\r\n }\r\n highlighted += char\r\n }\r\n return result\r\n }\r\n\r\n\r\n var indexes = result => result._indexes.slice(0, result._indexes.len).sort((a,b)=>a-b)\r\n\r\n\r\n var prepare = (target) => {\r\n if(typeof target !== 'string') target = ''\r\n var info = prepareLowerInfo(target)\r\n return {'target':target, _targetLower:info._lower, _targetLowerCodes:info.lowerCodes, _nextBeginningIndexes:NULL, _bitflags:info.bitflags, 'score':NULL, _indexes:[0], 'obj':NULL} // hidden\r\n }\r\n\r\n\r\n // Below this point is only internal code\r\n // Below this point is only internal code\r\n // Below this point is only internal code\r\n // Below this point is only internal code\r\n\r\n\r\n var prepareSearch = (search) => {\r\n if(typeof search !== 'string') search = ''\r\n search = search.trim()\r\n var info = prepareLowerInfo(search)\r\n\r\n var spaceSearches = []\r\n if(info.containsSpace) {\r\n var searches = search.split(/\\s+/)\r\n searches = [...new Set(searches)] // distinct\r\n for(var i=0; i {\r\n if(target.length > 999) return prepare(target) // don't cache huge targets\r\n var targetPrepared = preparedCache.get(target)\r\n if(targetPrepared !== undefined) return targetPrepared\r\n targetPrepared = prepare(target)\r\n preparedCache.set(target, targetPrepared)\r\n return targetPrepared\r\n }\r\n var getPreparedSearch = (search) => {\r\n if(search.length > 999) return prepareSearch(search) // don't cache huge searches\r\n var searchPrepared = preparedSearchCache.get(search)\r\n if(searchPrepared !== undefined) return searchPrepared\r\n searchPrepared = prepareSearch(search)\r\n preparedSearchCache.set(search, searchPrepared)\r\n return searchPrepared\r\n }\r\n\r\n\r\n var all = (search, targets, options) => {\r\n var results = []; results.total = targets.length\r\n\r\n var limit = options && options.limit || INT_MAX\r\n\r\n if(options && options.key) {\r\n for(var i=0;i= limit) return results\r\n }\r\n } else if(options && options.keys) {\r\n for(var i=0;i= 0; --keyI) {\r\n var target = getValue(obj, options.keys[keyI])\r\n if(!target) { objResults[keyI] = NULL; continue }\r\n if(!isObj(target)) target = getPrepared(target)\r\n target.score = INT_MIN\r\n target._indexes.len = 0\r\n objResults[keyI] = target\r\n }\r\n objResults.obj = obj\r\n objResults.score = INT_MIN\r\n results.push(objResults); if(results.length >= limit) return results\r\n }\r\n } else {\r\n for(var i=0;i= limit) return results\r\n }\r\n }\r\n\r\n return results\r\n }\r\n\r\n\r\n var algorithm = (preparedSearch, prepared, allowSpaces=false) => {\r\n if(allowSpaces===false && preparedSearch.containsSpace) return algorithmSpaces(preparedSearch, prepared)\r\n\r\n var searchLower = preparedSearch._lower\r\n var searchLowerCodes = preparedSearch.lowerCodes\r\n var searchLowerCode = searchLowerCodes[0]\r\n var targetLowerCodes = prepared._targetLowerCodes\r\n var searchLen = searchLowerCodes.length\r\n var targetLen = targetLowerCodes.length\r\n var searchI = 0 // where we at\r\n var targetI = 0 // where you at\r\n var matchesSimpleLen = 0\r\n\r\n // very basic fuzzy match; to remove non-matching targets ASAP!\r\n // walk through target. find sequential matches.\r\n // if all chars aren't found then exit\r\n for(;;) {\r\n var isMatch = searchLowerCode === targetLowerCodes[targetI]\r\n if(isMatch) {\r\n matchesSimple[matchesSimpleLen++] = targetI\r\n ++searchI; if(searchI === searchLen) break\r\n searchLowerCode = searchLowerCodes[searchI]\r\n }\r\n ++targetI; if(targetI >= targetLen) return NULL // Failed to find searchI\r\n }\r\n\r\n var searchI = 0\r\n var successStrict = false\r\n var matchesStrictLen = 0\r\n\r\n var nextBeginningIndexes = prepared._nextBeginningIndexes\r\n if(nextBeginningIndexes === NULL) nextBeginningIndexes = prepared._nextBeginningIndexes = prepareNextBeginningIndexes(prepared.target)\r\n var firstPossibleI = targetI = matchesSimple[0]===0 ? 0 : nextBeginningIndexes[matchesSimple[0]-1]\r\n\r\n // Our target string successfully matched all characters in sequence!\r\n // Let's try a more advanced and strict test to improve the score\r\n // only count it as a match if it's consecutive or a beginning character!\r\n var backtrackCount = 0\r\n if(targetI !== targetLen) for(;;) {\r\n if(targetI >= targetLen) {\r\n // We failed to find a good spot for this search char, go back to the previous search char and force it forward\r\n if(searchI <= 0) break // We failed to push chars forward for a better match\r\n\r\n ++backtrackCount; if(backtrackCount > 200) break // exponential backtracking is taking too long, just give up and return a bad match\r\n\r\n --searchI\r\n var lastMatch = matchesStrict[--matchesStrictLen]\r\n targetI = nextBeginningIndexes[lastMatch]\r\n\r\n } else {\r\n var isMatch = searchLowerCodes[searchI] === targetLowerCodes[targetI]\r\n if(isMatch) {\r\n matchesStrict[matchesStrictLen++] = targetI\r\n ++searchI; if(searchI === searchLen) { successStrict = true; break }\r\n ++targetI\r\n } else {\r\n targetI = nextBeginningIndexes[targetI]\r\n }\r\n }\r\n }\r\n\r\n // check if it's a substring match\r\n var substringIndex = prepared._targetLower.indexOf(searchLower, matchesSimple[0]) // perf: this is slow\r\n var isSubstring = ~substringIndex\r\n if(isSubstring && !successStrict) { // rewrite the indexes from basic to the substring\r\n for(var i=0; i 24) score *= (uniqueBeginningIndexes-24)*10 // quite arbitrary numbers here ...\r\n }\r\n\r\n if(isSubstring) score /= 1+searchLen*searchLen*1 // bonus for being a full substring\r\n if(isSubstringBeginning) score /= 1+searchLen*searchLen*1 // bonus for substring starting on a beginningIndex\r\n\r\n score -= targetLen - searchLen // penality for longer targets\r\n prepared.score = score\r\n\r\n for(var i = 0; i < matchesBestLen; ++i) prepared._indexes[i] = matchesBest[i]\r\n prepared._indexes.len = matchesBestLen\r\n\r\n return prepared\r\n }\r\n }\r\n var algorithmSpaces = (preparedSearch, target) => {\r\n var seen_indexes = new Set()\r\n var score = 0\r\n var result = NULL\r\n\r\n var first_seen_index_last_search = 0\r\n var searches = preparedSearch.spaceSearches\r\n for(var i=0; i score) {\r\n return allowSpacesResult\r\n }\r\n\r\n result.score = score\r\n\r\n var i = 0\r\n for (let index of seen_indexes) result._indexes[i++] = index\r\n result._indexes.len = i\r\n\r\n return result\r\n }\r\n\r\n\r\n var prepareLowerInfo = (str) => {\r\n var strLen = str.length\r\n var lower = str.toLowerCase()\r\n var lowerCodes = [] // new Array(strLen) sparse array is too slow\r\n var bitflags = 0\r\n var containsSpace = false // space isn't stored in bitflags because of how searching with a space works\r\n\r\n for(var i = 0; i < strLen; ++i) {\r\n var lowerCode = lowerCodes[i] = lower.charCodeAt(i)\r\n\r\n if(lowerCode === 32) {\r\n containsSpace = true\r\n continue // it's important that we don't set any bitflags for space\r\n }\r\n\r\n var bit = lowerCode>=97&&lowerCode<=122 ? lowerCode-97 // alphabet\r\n : lowerCode>=48&&lowerCode<=57 ? 26 // numbers\r\n // 3 bits available\r\n : lowerCode<=127 ? 30 // other ascii\r\n : 31 // other utf8\r\n bitflags |= 1< {\r\n var targetLen = target.length\r\n var beginningIndexes = []; var beginningIndexesLen = 0\r\n var wasUpper = false\r\n var wasAlphanum = false\r\n for(var i = 0; i < targetLen; ++i) {\r\n var targetCode = target.charCodeAt(i)\r\n var isUpper = targetCode>=65&&targetCode<=90\r\n var isAlphanum = isUpper || targetCode>=97&&targetCode<=122 || targetCode>=48&&targetCode<=57\r\n var isBeginning = isUpper && !wasUpper || !wasAlphanum || !isAlphanum\r\n wasUpper = isUpper\r\n wasAlphanum = isAlphanum\r\n if(isBeginning) beginningIndexes[beginningIndexesLen++] = i\r\n }\r\n return beginningIndexes\r\n }\r\n var prepareNextBeginningIndexes = (target) => {\r\n var targetLen = target.length\r\n var beginningIndexes = prepareBeginningIndexes(target)\r\n var nextBeginningIndexes = [] // new Array(targetLen) sparse array is too slow\r\n var lastIsBeginning = beginningIndexes[0]\r\n var lastIsBeginningI = 0\r\n for(var i = 0; i < targetLen; ++i) {\r\n if(lastIsBeginning > i) {\r\n nextBeginningIndexes[i] = lastIsBeginning\r\n } else {\r\n lastIsBeginning = beginningIndexes[++lastIsBeginningI]\r\n nextBeginningIndexes[i] = lastIsBeginning===undefined ? targetLen : lastIsBeginning\r\n }\r\n }\r\n return nextBeginningIndexes\r\n }\r\n\r\n\r\n var cleanup = () => { preparedCache.clear(); preparedSearchCache.clear(); matchesSimple = []; matchesStrict = [] }\r\n\r\n var preparedCache = new Map()\r\n var preparedSearchCache = new Map()\r\n var matchesSimple = []; var matchesStrict = []\r\n\r\n\r\n // for use with keys. just returns the maximum score\r\n var defaultScoreFn = (a) => {\r\n var max = INT_MIN\r\n var len = a.length\r\n for (var i = 0; i < len; ++i) {\r\n var result = a[i]; if(result === NULL) continue\r\n var score = result.score\r\n if(score > max) max = score\r\n }\r\n if(max === INT_MIN) return NULL\r\n return max\r\n }\r\n\r\n // prop = 'key' 2.5ms optimized for this case, seems to be about as fast as direct obj[prop]\r\n // prop = 'key1.key2' 10ms\r\n // prop = ['key1', 'key2'] 27ms\r\n var getValue = (obj, prop) => {\r\n var tmp = obj[prop]; if(tmp !== undefined) return tmp\r\n var segs = prop\r\n if(!Array.isArray(prop)) segs = prop.split('.')\r\n var len = segs.length\r\n var i = -1\r\n while (obj && (++i < len)) obj = obj[segs[i]]\r\n return obj\r\n }\r\n\r\n var isObj = (x) => { return typeof x === 'object' } // faster as a function\r\n // var INT_MAX = 9007199254740991; var INT_MIN = -INT_MAX\r\n var INT_MAX = Infinity; var INT_MIN = -INT_MAX\r\n var noResults = []; noResults.total = 0\r\n var NULL = null\r\n\r\n\r\n // Hacked version of https://github.com/lemire/FastPriorityQueue.js\r\n var fastpriorityqueue=r=>{var e=[],o=0,a={},v=r=>{for(var a=0,v=e[a],c=1;c>1]=e[a],c=1+(a<<1)}for(var f=a-1>>1;a>0&&v.score>1)e[a]=e[f];e[a]=v};return a.add=(r=>{var a=o;e[o++]=r;for(var v=a-1>>1;a>0&&r.score>1)e[a]=e[v];e[a]=r}),a.poll=(r=>{if(0!==o){var a=e[0];return e[0]=e[--o],v(),a}}),a.peek=(r=>{if(0!==o)return e[0]}),a.replaceTop=(r=>{e[0]=r,v()}),a}\r\n var q = fastpriorityqueue() // reuse this\r\n\r\n\r\n // fuzzysort is written this way for minification. all names are mangeled unless quoted\r\n return {'single':single, 'go':go, 'highlight':highlight, 'prepare':prepare, 'indexes':indexes, 'cleanup':cleanup}\r\n}) // UMD\r\n\r\n// TODO: (feature) frecency\r\n// TODO: (perf) use different sorting algo depending on the # of results?\r\n// TODO: (perf) preparedCache is a memory leak\r\n// TODO: (like sublime) backslash === forwardslash\r\n// TODO: (perf) prepareSearch seems slow\r\n", "/******************************************************************************\nCopyright (c) Microsoft Corporation.\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\n/* global Reflect, Promise, SuppressedError, Symbol */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nexport function __extends(d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\nexport var __assign = function() {\n __assign = Object.assign || function __assign(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\n }\n return t;\n }\n return __assign.apply(this, arguments);\n}\n\nexport function __rest(s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n}\n\nexport function __decorate(decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\nexport function __param(paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n}\n\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\n var _, done = false;\n for (var i = decorators.length - 1; i >= 0; i--) {\n var context = {};\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\n if (kind === \"accessor\") {\n if (result === void 0) continue;\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\n if (_ = accept(result.get)) descriptor.get = _;\n if (_ = accept(result.set)) descriptor.set = _;\n if (_ = accept(result.init)) initializers.unshift(_);\n }\n else if (_ = accept(result)) {\n if (kind === \"field\") initializers.unshift(_);\n else descriptor[key] = _;\n }\n }\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\n done = true;\n};\n\nexport function __runInitializers(thisArg, initializers, value) {\n var useValue = arguments.length > 2;\n for (var i = 0; i < initializers.length; i++) {\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\n }\n return useValue ? value : void 0;\n};\n\nexport function __propKey(x) {\n return typeof x === \"symbol\" ? x : \"\".concat(x);\n};\n\nexport function __setFunctionName(f, name, prefix) {\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\n};\n\nexport function __metadata(metadataKey, metadataValue) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\n}\n\nexport function __awaiter(thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n}\n\nexport function __generator(thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n}\n\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\n\nexport function __exportStar(m, o) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\n}\n\nexport function __values(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n}\n\nexport function __read(o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n}\n\n/** @deprecated */\nexport function __spread() {\n for (var ar = [], i = 0; i < arguments.length; i++)\n ar = ar.concat(__read(arguments[i]));\n return ar;\n}\n\n/** @deprecated */\nexport function __spreadArrays() {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n}\n\nexport function __spreadArray(to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n}\n\nexport function __await(v) {\n return this instanceof __await ? (this.v = v, this) : new __await(v);\n}\n\nexport function __asyncGenerator(thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;\n function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }\n function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n}\n\nexport function __asyncDelegator(o) {\n var i, p;\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\n}\n\nexport function __asyncValues(o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator], i;\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\n}\n\nexport function __makeTemplateObject(cooked, raw) {\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\n return cooked;\n};\n\nvar __setModuleDefault = Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n};\n\nexport function __importStar(mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n}\n\nexport function __importDefault(mod) {\n return (mod && mod.__esModule) ? mod : { default: mod };\n}\n\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\n}\n\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\n}\n\nexport function __classPrivateFieldIn(state, receiver) {\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\n}\n\nexport function __addDisposableResource(env, value, async) {\n if (value !== null && value !== void 0) {\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\n var dispose, inner;\n if (async) {\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\n dispose = value[Symbol.asyncDispose];\n }\n if (dispose === void 0) {\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\n dispose = value[Symbol.dispose];\n if (async) inner = dispose;\n }\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\n if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };\n env.stack.push({ value: value, dispose: dispose, async: async });\n }\n else if (async) {\n env.stack.push({ async: true });\n }\n return value;\n}\n\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\n var e = new Error(message);\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\n};\n\nexport function __disposeResources(env) {\n function fail(e) {\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\n env.hasError = true;\n }\n function next() {\n while (env.stack.length) {\n var rec = env.stack.pop();\n try {\n var result = rec.dispose && rec.dispose.call(rec.value);\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\n }\n catch (e) {\n fail(e);\n }\n }\n if (env.hasError) throw env.error;\n }\n return next();\n}\n\nexport default {\n __extends,\n __assign,\n __rest,\n __decorate,\n __param,\n __metadata,\n __awaiter,\n __generator,\n __createBinding,\n __exportStar,\n __values,\n __read,\n __spread,\n __spreadArrays,\n __spreadArray,\n __await,\n __asyncGenerator,\n __asyncDelegator,\n __asyncValues,\n __makeTemplateObject,\n __importStar,\n __importDefault,\n __classPrivateFieldGet,\n __classPrivateFieldSet,\n __classPrivateFieldIn,\n __addDisposableResource,\n __disposeResources,\n};\n", "export {};\n//# sourceMappingURL=interface.js.map", "export {};\n//# sourceMappingURL=index.js.map", "export {};\n//# sourceMappingURL=interfaces.js.map", "export function dset(obj, keys, val) {\n\tkeys.split && (keys=keys.split('.'));\n\tvar i=0, l=keys.length, t=obj, x, k;\n\twhile (i < l) {\n\t\tk = ''+keys[i++];\n\t\tif (k === '__proto__' || k === 'constructor' || k === 'prototype') break;\n\t\tt = t[k] = (i === l) ? val : (typeof(x=t[k])===typeof(keys)) ? x : (keys[i]*0 !== 0 || !!~(''+keys[i]).indexOf('.')) ? {} : [];\n\t}\n}\n", "export const pickBy = (\n obj: T,\n fn: (key: K, v: T[K]) => boolean\n) => {\n return (Object.keys(obj) as K[])\n .filter((k) => fn(k, obj[k]))\n .reduce((acc, key) => ((acc[key] = obj[key]), acc), {} as Partial)\n}\n", "export class ValidationError extends Error {\n field: string\n\n constructor(field: string, message: string) {\n super(`${field} ${message}`)\n this.field = field\n }\n}\n", "export function isString(obj: unknown): obj is string {\n return typeof obj === 'string'\n}\n\nexport function isNumber(obj: unknown): obj is number {\n return typeof obj === 'number'\n}\n\nexport function isFunction(obj: unknown): obj is Function {\n return typeof obj === 'function'\n}\n\nexport function exists(val: unknown): val is NonNullable {\n return val !== undefined && val !== null\n}\n\nexport function isPlainObject(\n obj: unknown\n): obj is Record {\n return (\n Object.prototype.toString.call(obj).slice(8, -1).toLowerCase() === 'object'\n )\n}\n", "import { CoreSegmentEvent } from '../events'\nimport { ValidationError } from './errors'\nimport { isString, isPlainObject, exists } from './helpers'\n\nconst stringError = 'is not a string'\nconst objError = 'is not an object'\nconst nilError = 'is nil'\n\n// user identity check could hypothetically could be used in the browser event factory, but not 100% sure -- so this is node only for now\nexport function assertUserIdentity(event: CoreSegmentEvent): void {\n const USER_FIELD_NAME = '.userId/anonymousId/previousId/groupId'\n\n const getAnyUserId = (event: CoreSegmentEvent) =>\n event.userId ?? event.anonymousId ?? event.groupId ?? event.previousId\n\n const id = getAnyUserId(event)\n if (!exists(id)) {\n throw new ValidationError(USER_FIELD_NAME, nilError)\n } else if (!isString(id)) {\n throw new ValidationError(USER_FIELD_NAME, stringError)\n }\n}\n\nexport function assertEventExists(\n event?: CoreSegmentEvent | null\n): asserts event is CoreSegmentEvent {\n if (!exists(event)) {\n throw new ValidationError('Event', nilError)\n }\n if (typeof event !== 'object') {\n throw new ValidationError('Event', objError)\n }\n}\n\nexport function assertEventType(event: CoreSegmentEvent): void {\n if (!isString(event.type)) {\n throw new ValidationError('.type', stringError)\n }\n}\n\nexport function assertTrackEventName(event: CoreSegmentEvent): void {\n if (!isString(event.event)) {\n throw new ValidationError('.event', stringError)\n }\n}\n\nexport function assertTrackEventProperties(event: CoreSegmentEvent): void {\n if (!isPlainObject(event.properties)) {\n throw new ValidationError('.properties', objError)\n }\n}\n\nexport function assertTraits(event: CoreSegmentEvent): void {\n if (!isPlainObject(event.traits)) {\n throw new ValidationError('.traits', objError)\n }\n}\n\nexport function assertMessageId(event: CoreSegmentEvent): void {\n if (!isString(event.messageId)) {\n throw new ValidationError('.messageId', stringError)\n }\n}\n\nexport function validateEvent(event?: CoreSegmentEvent | null) {\n assertEventExists(event)\n assertEventType(event)\n assertMessageId(event)\n\n if (event.type === 'track') {\n assertTrackEventName(event)\n assertTrackEventProperties(event)\n }\n\n if (['group', 'identify'].includes(event.type)) {\n assertTraits(event)\n }\n}\n", "export * from './interfaces'\nimport { dset } from 'dset'\nimport { ID } from '../user'\nimport {\n Integrations,\n EventProperties,\n CoreSegmentEvent,\n CoreOptions,\n CoreExtraContext,\n UserTraits,\n GroupTraits,\n} from './interfaces'\nimport { pickBy } from '../utils/pick'\nimport type { RemoveIndexSignature } from '../utils/ts-helpers'\nimport { validateEvent } from '../validation/assertions'\n\nexport type EventMethodCallHook = ({\n type,\n options,\n}: {\n type: 'track' | 'identify' | 'page' | 'group' | 'alias' | 'screen'\n options?: CoreOptions\n}) => void\n\nexport type EventHook = (event: CoreSegmentEvent) => void\n\nexport interface EventFactorySettings {\n /**\n * Universal `messageId` builder for all events (these must be unique)\n */\n createMessageId: () => string\n /**\n * Hook to do something with an event right before they are returned from the factory.\n * This includes event modification or additional validation.\n */\n onFinishedEvent?: EventHook\n /**\n * Hook whenever an event method is called (track, page, etc.)\n * Can be used to update Options (or just listen)\n */\n onEventMethodCall?: EventMethodCallHook\n}\n\n/**\n * Internal settings object that is used internally by the factory\n */\nclass InternalEventFactorySettings {\n public createMessageId: EventFactorySettings['createMessageId']\n public onEventMethodCall: EventMethodCallHook\n public onFinishedEvent: EventHook\n\n constructor(public settings: EventFactorySettings) {\n this.createMessageId = settings.createMessageId\n this.onEventMethodCall = settings.onEventMethodCall ?? (() => {})\n this.onFinishedEvent = settings.onFinishedEvent ?? (() => {})\n }\n}\n\nexport abstract class CoreEventFactory {\n private settings: InternalEventFactorySettings\n\n constructor(settings: EventFactorySettings) {\n this.settings = new InternalEventFactorySettings(settings)\n }\n\n track(\n event: string,\n properties?: EventProperties,\n options?: CoreOptions,\n globalIntegrations?: Integrations\n ) {\n this.settings.onEventMethodCall({ type: 'track', options })\n return this.normalize({\n ...this.baseEvent(),\n event,\n type: 'track',\n properties: properties ?? {}, // TODO: why is this not a shallow copy like everywhere else?\n options: { ...options },\n integrations: { ...globalIntegrations },\n })\n }\n\n page(\n category: string | null,\n page: string | null,\n properties?: EventProperties,\n options?: CoreOptions,\n globalIntegrations?: Integrations\n ): CoreSegmentEvent {\n this.settings.onEventMethodCall({ type: 'page', options })\n const event: CoreSegmentEvent = {\n type: 'page',\n properties: { ...properties },\n options: { ...options },\n integrations: { ...globalIntegrations },\n }\n\n if (category !== null) {\n event.category = category\n event.properties = event.properties ?? {}\n event.properties.category = category\n }\n\n if (page !== null) {\n event.name = page\n }\n\n return this.normalize({\n ...this.baseEvent(),\n ...event,\n })\n }\n\n screen(\n category: string | null,\n screen: string | null,\n properties?: EventProperties,\n options?: CoreOptions,\n globalIntegrations?: Integrations\n ): CoreSegmentEvent {\n this.settings.onEventMethodCall({ type: 'screen', options })\n const event: CoreSegmentEvent = {\n type: 'screen',\n properties: { ...properties },\n options: { ...options },\n integrations: { ...globalIntegrations },\n }\n\n if (category !== null) {\n event.category = category\n }\n\n if (screen !== null) {\n event.name = screen\n }\n\n return this.normalize({\n ...this.baseEvent(),\n ...event,\n })\n }\n\n identify(\n userId: ID,\n traits?: UserTraits,\n options?: CoreOptions,\n globalIntegrations?: Integrations\n ): CoreSegmentEvent {\n this.settings.onEventMethodCall({ type: 'identify', options })\n return this.normalize({\n ...this.baseEvent(),\n type: 'identify',\n userId,\n traits: traits ?? {},\n options: { ...options },\n integrations: globalIntegrations,\n })\n }\n\n group(\n groupId: ID,\n traits?: GroupTraits,\n options?: CoreOptions,\n globalIntegrations?: Integrations\n ): CoreSegmentEvent {\n this.settings.onEventMethodCall({ type: 'group', options })\n return this.normalize({\n ...this.baseEvent(),\n type: 'group',\n traits: traits ?? {},\n options: { ...options }, // this spreading is intentional\n integrations: { ...globalIntegrations }, //\n groupId,\n })\n }\n\n alias(\n to: string,\n from: string | null, // TODO: can we make this undefined?\n options?: CoreOptions,\n globalIntegrations?: Integrations\n ): CoreSegmentEvent {\n this.settings.onEventMethodCall({ type: 'alias', options })\n const base: CoreSegmentEvent = {\n userId: to,\n type: 'alias',\n options: { ...options },\n integrations: { ...globalIntegrations },\n }\n\n if (from !== null) {\n base.previousId = from\n }\n\n if (to === undefined) {\n return this.normalize({\n ...base,\n ...this.baseEvent(),\n })\n }\n\n return this.normalize({\n ...this.baseEvent(),\n ...base,\n })\n }\n\n private baseEvent(): Partial {\n return {\n integrations: {},\n options: {},\n }\n }\n\n /**\n * Builds the context part of an event based on \"foreign\" keys that\n * are provided in the `Options` parameter for an Event\n */\n private context(\n options: CoreOptions\n ): [CoreExtraContext, Partial] {\n type CoreOptionKeys = keyof RemoveIndexSignature\n /**\n * If the event options are known keys from this list, we move them to the top level of the event.\n * Any other options are moved to context.\n */\n const eventOverrideKeys: CoreOptionKeys[] = [\n 'userId',\n 'anonymousId',\n 'timestamp',\n 'messageId',\n ]\n\n delete options['integrations']\n const providedOptionsKeys = Object.keys(options) as Exclude<\n CoreOptionKeys,\n 'integrations'\n >[]\n\n const context = options.context ?? {}\n const eventOverrides = {}\n\n providedOptionsKeys.forEach((key) => {\n if (key === 'context') {\n return\n }\n\n if (eventOverrideKeys.includes(key)) {\n dset(eventOverrides, key, options[key])\n } else {\n dset(context, key, options[key])\n }\n })\n\n return [context, eventOverrides]\n }\n\n private normalize(event: CoreSegmentEvent): CoreSegmentEvent {\n const integrationBooleans = Object.keys(event.integrations ?? {}).reduce(\n (integrationNames, name) => {\n return {\n ...integrationNames,\n [name]: Boolean(event.integrations?.[name]),\n }\n },\n {} as Record\n )\n\n // filter out any undefined options\n event.options = pickBy(event.options || {}, (_, value) => {\n return value !== undefined\n })\n\n // This is pretty trippy, but here's what's going on:\n // - a) We don't pass initial integration options as part of the event, only if they're true or false\n // - b) We do accept per integration overrides (like integrations.Amplitude.sessionId) at the event level\n // Hence the need to convert base integration options to booleans, but maintain per event integration overrides\n const allIntegrations = {\n // Base config integrations object as booleans\n ...integrationBooleans,\n\n // Per event overrides, for things like amplitude sessionId, for example\n ...event.options?.integrations,\n }\n\n const [context, overrides] = event.options\n ? this.context(event.options)\n : []\n\n const { options, ...rest } = event\n\n const evt: CoreSegmentEvent = {\n timestamp: new Date(),\n ...rest,\n context,\n integrations: allIntegrations,\n ...overrides,\n messageId: options.messageId || this.settings.createMessageId(),\n }\n\n this.settings.onFinishedEvent(evt)\n validateEvent(evt)\n\n return evt\n }\n}\n", "import { CoreContext } from '../context'\nimport type { Callback } from '../events'\n\nexport function pTimeout(promise: Promise, timeout: number): Promise {\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n reject(Error('Promise timed out'))\n }, timeout)\n\n promise\n .then((val) => {\n clearTimeout(timeoutId)\n return resolve(val)\n })\n .catch(reject)\n })\n}\n\nexport function sleep(timeoutInMs: number): Promise {\n return new Promise((resolve) => setTimeout(resolve, timeoutInMs))\n}\n\n/**\n * @param ctx\n * @param callback - the function to invoke\n * @param delay - aka \"timeout\". The amount of time in ms to wait before invoking the callback.\n */\nexport function invokeCallback(\n ctx: Ctx,\n callback: Callback,\n delay: number\n): Promise {\n const cb = () => {\n try {\n return Promise.resolve(callback(ctx))\n } catch (err) {\n return Promise.reject(err)\n }\n }\n\n return (\n sleep(delay)\n // pTimeout ensures that the callback can't cause the context to hang\n .then(() => pTimeout(cb(), 1000))\n .catch((err) => {\n ctx?.log('warn', 'Callback Error', { error: err })\n ctx?.stats.increment('callback_error')\n })\n .then(() => ctx)\n )\n}\n", "/**\n * Return a promise that can be externally resolved\n */\nexport const createDeferred = () => {\n let resolve!: (value: T | PromiseLike) => void\n let reject!: (reason: any) => void\n let settled = false\n const promise = new Promise((_resolve, _reject) => {\n resolve = (...args) => {\n settled = true\n _resolve(...args)\n }\n reject = (...args) => {\n settled = true\n _reject(...args)\n }\n })\n\n return {\n resolve,\n reject,\n promise,\n isSettled: () => settled,\n }\n}\n", "export * from './create-deferred'\n", "type EventName = string\ntype EventFnArgs = any[]\ntype EmitterContract = Record\n\nexport interface EmitterOptions {\n /** How many event listeners for a particular event before emitting a warning (0 = disabled)\n * @default 10\n **/\n maxListeners?: number\n}\n\n/**\n * Event Emitter that takes the expected contract as a generic\n * @example\n * ```ts\n * type Contract = {\n * delivery_success: [DeliverySuccessResponse, Metrics],\n * delivery_failure: [DeliveryError]\n * }\n * new Emitter()\n * .on('delivery_success', (res, metrics) => ...)\n * .on('delivery_failure', (err) => ...)\n * ```\n */\nexport class Emitter {\n maxListeners: number\n constructor(options?: EmitterOptions) {\n this.maxListeners = options?.maxListeners ?? 10\n }\n private callbacks: Partial = {}\n private warned = false\n\n private warnIfPossibleMemoryLeak(\n event: EventName\n ) {\n if (this.warned) {\n return\n }\n if (\n this.maxListeners &&\n this.callbacks[event]!.length > this.maxListeners\n ) {\n console.warn(\n `Event Emitter: Possible memory leak detected; ${String(\n event\n )} has exceeded ${this.maxListeners} listeners.`\n )\n this.warned = true\n }\n }\n\n on(\n event: EventName,\n callback: (...args: Contract[EventName]) => void\n ): this {\n if (!this.callbacks[event]) {\n this.callbacks[event] = [callback] as Contract[EventName]\n } else {\n this.callbacks[event]!.push(callback)\n this.warnIfPossibleMemoryLeak(event)\n }\n return this\n }\n\n once(\n event: EventName,\n callback: (...args: Contract[EventName]) => void\n ): this {\n const on = (...args: Contract[EventName]): void => {\n this.off(event, on)\n callback.apply(this, args)\n }\n\n this.on(event, on)\n return this\n }\n\n off(\n event: EventName,\n callback: (...args: Contract[EventName]) => void\n ): this {\n const fns = this.callbacks[event] ?? []\n const without = fns.filter((fn) => fn !== callback) as Contract[EventName]\n this.callbacks[event] = without\n return this\n }\n\n emit(\n event: EventName,\n ...args: Contract[EventName]\n ): this {\n const callbacks = this.callbacks[event] ?? []\n callbacks.forEach((callback) => {\n callback.apply(this, args)\n })\n return this\n }\n}\n", "export * from './emitter'\n", "export * from './create-deferred'\nexport * from './emitter'\n", "type BackoffParams = {\n /** The number of milliseconds before starting the first retry. Default is 500 */\n minTimeout?: number\n\n /** The maximum number of milliseconds between two retries. Default is Infinity */\n maxTimeout?: number\n\n /** The exponential factor to use. Default is 2. */\n factor?: number\n\n /** The current attempt */\n attempt: number\n}\n\nexport function backoff(params: BackoffParams): number {\n const random = Math.random() + 1\n const {\n minTimeout = 500,\n factor = 2,\n attempt,\n maxTimeout = Infinity,\n } = params\n return Math.min(random * minTimeout * Math.pow(factor, attempt), maxTimeout)\n}\n", "import { Emitter } from '@segment/analytics-generic-utils'\nimport { backoff } from './backoff'\n\n/**\n * @internal\n */\nexport const ON_REMOVE_FROM_FUTURE = 'onRemoveFromFuture'\n\ninterface QueueItem {\n id: string\n}\n\nexport class PriorityQueue extends Emitter {\n protected future: Item[] = []\n protected queue: Item[]\n protected seen: Record\n\n public maxAttempts: number\n\n constructor(\n maxAttempts: number,\n queue: Item[],\n seen?: Record\n ) {\n super()\n this.maxAttempts = maxAttempts\n this.queue = queue\n this.seen = seen ?? {}\n }\n\n push(...items: Item[]): boolean[] {\n const accepted = items.map((operation) => {\n const attempts = this.updateAttempts(operation)\n\n if (attempts > this.maxAttempts || this.includes(operation)) {\n return false\n }\n\n this.queue.push(operation)\n return true\n })\n\n this.queue = this.queue.sort(\n (a, b) => this.getAttempts(a) - this.getAttempts(b)\n )\n return accepted\n }\n\n pushWithBackoff(item: Item): boolean {\n if (this.getAttempts(item) === 0) {\n return this.push(item)[0]\n }\n\n const attempt = this.updateAttempts(item)\n\n if (attempt > this.maxAttempts || this.includes(item)) {\n return false\n }\n\n const timeout = backoff({ attempt: attempt - 1 })\n\n setTimeout(() => {\n this.queue.push(item)\n // remove from future list\n this.future = this.future.filter((f) => f.id !== item.id)\n // Lets listeners know that a 'future' message is now available in the queue\n this.emit(ON_REMOVE_FROM_FUTURE)\n }, timeout)\n\n this.future.push(item)\n return true\n }\n\n public getAttempts(item: Item): number {\n return this.seen[item.id] ?? 0\n }\n\n public updateAttempts(item: Item): number {\n this.seen[item.id] = this.getAttempts(item) + 1\n return this.getAttempts(item)\n }\n\n includes(item: Item): boolean {\n return (\n this.queue.includes(item) ||\n this.future.includes(item) ||\n Boolean(this.queue.find((i) => i.id === item.id)) ||\n Boolean(this.future.find((i) => i.id === item.id))\n )\n }\n\n pop(): Item | undefined {\n return this.queue.shift()\n }\n\n public get length(): number {\n return this.queue.length\n }\n\n public get todo(): number {\n return this.queue.length + this.future.length\n }\n}\n", "var IDX=256, HEX=[], BUFFER;\nwhile (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1);\n\nexport function v4() {\n\tvar i=0, num, out='';\n\n\tif (!BUFFER || ((IDX + 16) > 256)) {\n\t\tBUFFER = Array(i=256);\n\t\twhile (i--) BUFFER[i] = 256 * Math.random() | 0;\n\t\ti = IDX = 0;\n\t}\n\n\tfor (; i < 16; i++) {\n\t\tnum = BUFFER[IDX + i];\n\t\tif (i==6) out += HEX[num & 15 | 64];\n\t\telse if (i==8) out += HEX[num & 63 | 128];\n\t\telse out += HEX[num];\n\n\t\tif (i & 1 && i > 1 && i < 11) out += '-';\n\t}\n\n\tIDX++;\n\treturn out;\n}\n", "export type LogLevel = 'debug' | 'info' | 'warn' | 'error'\nexport type LogMessage = {\n level: LogLevel\n message: string\n time?: Date\n extras?: Record\n}\n\nexport interface GenericLogger {\n log(level: LogLevel, message: string, extras?: object): void\n flush(): void\n logs: LogMessage[]\n}\n\nexport class CoreLogger implements GenericLogger {\n private _logs: LogMessage[] = []\n\n log(level: LogLevel, message: string, extras?: object) {\n const time = new Date()\n this._logs.push({\n level,\n message,\n time,\n extras,\n })\n }\n\n public get logs(): LogMessage[] {\n return this._logs\n }\n\n public flush(): void {\n if (this.logs.length > 1) {\n const formatted = this._logs.reduce((logs, log) => {\n const line = {\n ...log,\n json: JSON.stringify(log.extras, null, ' '),\n extras: log.extras,\n }\n\n delete line['time']\n\n let key = log.time?.toISOString() ?? ''\n if (logs[key]) {\n key = `${key}-${Math.random()}`\n }\n\n return {\n ...logs,\n [key]: line,\n }\n }, {} as Record)\n\n // ie doesn't like console.table\n if (console.table) {\n console.table(formatted)\n } else {\n console.log(formatted)\n }\n } else {\n this.logs.forEach((logEntry) => {\n const { level, message, extras } = logEntry\n\n if (level === 'info' || level === 'debug') {\n console.log(message, extras ?? '')\n } else {\n console[level](message, extras ?? '')\n }\n })\n }\n\n this._logs = []\n }\n}\n", "type CompactMetricType = 'g' | 'c'\n\nexport type CoreMetricType = 'gauge' | 'counter'\n\nexport interface CoreMetric {\n metric: string\n value: number\n type: CoreMetricType\n tags: string[]\n timestamp: number // unit milliseconds\n}\n\nexport interface CompactMetric {\n m: string // metric name\n v: number // value\n k: CompactMetricType\n t: string[] // tags\n e: number // timestamp in unit milliseconds\n}\n\nconst compactMetricType = (type: CoreMetricType): CompactMetricType => {\n const enums: Record = {\n gauge: 'g',\n counter: 'c',\n }\n return enums[type]\n}\n\nexport abstract class CoreStats {\n metrics: CoreMetric[] = []\n increment(metric: string, by = 1, tags?: string[]): void {\n this.metrics.push({\n metric,\n value: by,\n tags: tags ?? [],\n type: 'counter',\n timestamp: Date.now(),\n })\n }\n\n gauge(metric: string, value: number, tags?: string[]): void {\n this.metrics.push({\n metric,\n value,\n tags: tags ?? [],\n type: 'gauge',\n timestamp: Date.now(),\n })\n }\n\n flush(): void {\n const formatted = this.metrics.map((m) => ({\n ...m,\n tags: m.tags.join(','),\n }))\n // ie doesn't like console.table\n if (console.table) {\n console.table(formatted)\n } else {\n console.log(formatted)\n }\n this.metrics = []\n }\n\n /**\n * compact keys for smaller payload\n */\n serialize(): CompactMetric[] {\n return this.metrics.map((m) => {\n return {\n m: m.metric,\n v: m.value,\n t: m.tags,\n k: compactMetricType(m.type),\n e: m.timestamp,\n }\n })\n }\n}\n\nexport class NullStats extends CoreStats {\n override gauge(..._args: Parameters) {}\n override increment(..._args: Parameters) {}\n override flush(..._args: Parameters) {}\n override serialize(..._args: Parameters) {\n return []\n }\n}\n", "import { CoreSegmentEvent } from '../events/interfaces'\n\nimport { v4 as uuid } from '@lukeed/uuid'\nimport { dset } from 'dset'\nimport { CoreLogger, LogLevel, LogMessage } from '../logger'\nimport { CoreStats, CoreMetric, NullStats } from '../stats'\n\nexport interface SerializedContext {\n id: string\n event: CoreSegmentEvent\n logs: LogMessage[]\n metrics?: CoreMetric[]\n}\n\nexport interface ContextFailedDelivery {\n reason: unknown\n}\n\nexport interface CancelationOptions {\n retry?: boolean\n reason?: string\n type?: string\n}\n\nexport class ContextCancelation {\n retry: boolean\n type: string\n reason?: string\n\n constructor(options: CancelationOptions) {\n this.retry = options.retry ?? true\n this.type = options.type ?? 'plugin Error'\n this.reason = options.reason ?? ''\n }\n}\n\nexport abstract class CoreContext<\n Event extends CoreSegmentEvent = CoreSegmentEvent\n> {\n event: Event\n logger: CoreLogger\n stats: CoreStats\n attempts = 0\n\n private _failedDelivery?: ContextFailedDelivery\n private _id: string\n\n constructor(\n event: Event,\n id = uuid(),\n stats: CoreStats = new NullStats(),\n logger = new CoreLogger()\n ) {\n this.event = event\n this._id = id\n this.logger = logger\n this.stats = stats\n }\n\n static system(): void {\n // This should be overridden by the subclass to return an instance of the subclass.\n }\n\n isSame(other: CoreContext): boolean {\n return other.id === this.id\n }\n\n cancel(error?: Error | ContextCancelation): never {\n if (error) {\n throw error\n }\n\n throw new ContextCancelation({ reason: 'Context Cancel' })\n }\n\n log(level: LogLevel, message: string, extras?: object): void {\n this.logger.log(level, message, extras)\n }\n\n get id(): string {\n return this._id\n }\n\n updateEvent(path: string, val: unknown): Event {\n // Don't allow integrations that are set to false to be overwritten with integration settings.\n if (path.split('.')[0] === 'integrations') {\n const integrationName = path.split('.')[1]\n\n if (this.event.integrations?.[integrationName] === false) {\n return this.event\n }\n }\n\n dset(this.event, path, val)\n return this.event\n }\n\n failedDelivery(): ContextFailedDelivery | undefined {\n return this._failedDelivery\n }\n\n setFailedDelivery(options: ContextFailedDelivery) {\n this._failedDelivery = options\n }\n\n logs(): LogMessage[] {\n return this.logger.logs\n }\n\n flush(): void {\n this.logger.flush()\n this.stats.flush()\n }\n\n toJSON(): SerializedContext {\n return {\n id: this._id,\n event: this.event,\n logs: this.logger.logs,\n metrics: this.stats.metrics,\n }\n }\n}\n", "type Grouper = (obj: T) => string | number\n\nexport function groupBy(\n collection: T[],\n grouper: keyof T | Grouper\n): Record {\n const results: Record = {}\n\n collection.forEach((item) => {\n let key: string | number | undefined = undefined\n\n if (typeof grouper === 'string') {\n const suggestedKey = item[grouper]\n key =\n typeof suggestedKey !== 'string'\n ? JSON.stringify(suggestedKey)\n : suggestedKey\n } else if (grouper instanceof Function) {\n key = grouper(item)\n }\n\n if (key === undefined) {\n return\n }\n\n results[key] = [...(results[key] ?? []), item]\n })\n\n return results\n}\n", "/**\n * Check if thenable\n * (instanceof Promise doesn't respect realms)\n */\nexport const isThenable = (value: unknown): boolean =>\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof (value as any).then === 'function'\n", "import { isThenable } from '../utils/is-thenable'\n\nexport type TaskGroup = {\n done: () => Promise\n run: any>(\n op: Operation\n ) => ReturnType\n}\n\nexport const createTaskGroup = (): TaskGroup => {\n let taskCompletionPromise: Promise\n let resolvePromise: () => void\n let count = 0\n\n return {\n done: () => taskCompletionPromise,\n run: (op) => {\n const returnValue = op()\n\n if (isThenable(returnValue)) {\n if (++count === 1) {\n taskCompletionPromise = new Promise((res) => (resolvePromise = res))\n }\n\n returnValue.finally(() => --count === 0 && resolvePromise())\n }\n\n return returnValue\n },\n }\n}\n", "import { CoreContext, ContextCancelation } from '../context'\nimport { CorePlugin } from '../plugins'\n\nasync function tryAsync(fn: () => T | Promise): Promise {\n try {\n return await fn()\n } catch (err) {\n return Promise.reject(err)\n }\n}\n\nexport function attempt(\n ctx: Ctx,\n plugin: CorePlugin\n): Promise {\n ctx.log('debug', 'plugin', { plugin: plugin.name })\n const start = new Date().getTime()\n\n const hook = plugin[ctx.event.type]\n if (hook === undefined) {\n return Promise.resolve(ctx)\n }\n\n const newCtx = tryAsync(() => hook.apply(plugin, [ctx]))\n .then((ctx) => {\n const done = new Date().getTime() - start\n ctx.stats.gauge('plugin_time', done, [`plugin:${plugin.name}`])\n\n return ctx\n })\n .catch((err: Error | ContextCancelation) => {\n if (\n err instanceof ContextCancelation &&\n err.type === 'middleware_cancellation'\n ) {\n throw err\n }\n\n if (err instanceof ContextCancelation) {\n ctx.log('warn', err.type, {\n plugin: plugin.name,\n error: err,\n })\n\n return err\n }\n\n ctx.log('error', 'plugin Error', {\n plugin: plugin.name,\n error: err,\n })\n ctx.stats.increment('plugin_error', 1, [`plugin:${plugin.name}`])\n\n return err\n })\n\n return newCtx\n}\n\nexport function ensure(\n ctx: Ctx,\n plugin: CorePlugin\n): Promise {\n return attempt(ctx, plugin).then((newContext) => {\n if (newContext instanceof CoreContext) {\n return newContext\n }\n\n ctx.log('debug', 'Context canceled')\n ctx.stats.increment('context_canceled')\n ctx.cancel(newContext)\n })\n}\n", "import { CoreAnalytics } from '../analytics'\nimport { groupBy } from '../utils/group-by'\nimport { ON_REMOVE_FROM_FUTURE, PriorityQueue } from '../priority-queue'\n\nimport { CoreContext, ContextCancelation } from '../context'\nimport { Emitter } from '@segment/analytics-generic-utils'\nimport { Integrations, JSONObject } from '../events/interfaces'\nimport { CorePlugin } from '../plugins'\nimport { createTaskGroup, TaskGroup } from '../task/task-group'\nimport { attempt, ensure } from './delivery'\n\nexport type EventQueueEmitterContract = {\n message_delivered: [ctx: Ctx]\n message_enriched: [ctx: Ctx, plugin: CorePlugin]\n delivery_success: [ctx: Ctx]\n delivery_retry: [ctx: Ctx]\n delivery_failure: [ctx: Ctx, err: Ctx | Error | ContextCancelation]\n flush: [ctx: Ctx, delivered: boolean]\n initialization_failure: [CorePlugin]\n}\n\nexport abstract class CoreEventQueue<\n Ctx extends CoreContext = CoreContext,\n Plugin extends CorePlugin = CorePlugin\n> extends Emitter> {\n /**\n * All event deliveries get suspended until all the tasks in this task group are complete.\n * For example: a middleware that augments the event object should be loaded safely as a\n * critical task, this way, event queue will wait for it to be ready before sending events.\n *\n * This applies to all the events already in the queue, and the upcoming ones\n */\n criticalTasks: TaskGroup = createTaskGroup()\n queue: PriorityQueue\n plugins: Plugin[] = []\n failedInitializations: string[] = []\n private flushing = false\n\n constructor(priorityQueue: PriorityQueue) {\n super()\n\n this.queue = priorityQueue\n this.queue.on(ON_REMOVE_FROM_FUTURE, () => {\n this.scheduleFlush(0)\n })\n }\n\n async register(\n ctx: Ctx,\n plugin: Plugin,\n instance: CoreAnalytics\n ): Promise {\n this.plugins.push(plugin)\n\n const handleLoadError = (err: any) => {\n this.failedInitializations.push(plugin.name)\n this.emit('initialization_failure', plugin)\n console.warn(plugin.name, err)\n\n ctx.log('warn', 'Failed to load destination', {\n plugin: plugin.name,\n error: err,\n })\n\n // Filter out the failed plugin by excluding it from the list\n this.plugins = this.plugins.filter((p) => p !== plugin)\n }\n\n if (plugin.type === 'destination' && plugin.name !== 'Segment.io') {\n plugin.load(ctx, instance).catch(handleLoadError)\n } else {\n // for non-destinations plugins, we do need to wait for them to load\n // reminder: action destinations can require plugins that are not of type \"destination\".\n // For example, GA4 loads a type 'before' plugins and addition to a type 'destination' plugin\n try {\n await plugin.load(ctx, instance)\n } catch (err) {\n handleLoadError(err)\n }\n }\n }\n\n async deregister(\n ctx: Ctx,\n plugin: CorePlugin,\n instance: CoreAnalytics\n ): Promise {\n try {\n if (plugin.unload) {\n await Promise.resolve(plugin.unload(ctx, instance))\n }\n\n this.plugins = this.plugins.filter((p) => p.name !== plugin.name)\n } catch (e) {\n ctx.log('warn', 'Failed to unload destination', {\n plugin: plugin.name,\n error: e,\n })\n }\n }\n\n async dispatch(ctx: Ctx): Promise {\n ctx.log('debug', 'Dispatching')\n ctx.stats.increment('message_dispatched')\n\n this.queue.push(ctx)\n const willDeliver = this.subscribeToDelivery(ctx)\n this.scheduleFlush(0)\n return willDeliver\n }\n\n private async subscribeToDelivery(ctx: Ctx): Promise {\n return new Promise((resolve) => {\n const onDeliver = (flushed: Ctx, delivered: boolean): void => {\n if (flushed.isSame(ctx)) {\n this.off('flush', onDeliver)\n if (delivered) {\n resolve(flushed)\n } else {\n resolve(flushed)\n }\n }\n }\n\n this.on('flush', onDeliver)\n })\n }\n\n async dispatchSingle(ctx: Ctx): Promise {\n ctx.log('debug', 'Dispatching')\n ctx.stats.increment('message_dispatched')\n\n this.queue.updateAttempts(ctx)\n ctx.attempts = 1\n\n return this.deliver(ctx).catch((err) => {\n const accepted = this.enqueuRetry(err, ctx)\n if (!accepted) {\n ctx.setFailedDelivery({ reason: err })\n return ctx\n }\n\n return this.subscribeToDelivery(ctx)\n })\n }\n\n isEmpty(): boolean {\n return this.queue.length === 0\n }\n\n private scheduleFlush(timeout = 500): void {\n if (this.flushing) {\n return\n }\n\n this.flushing = true\n\n setTimeout(() => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.flush().then(() => {\n setTimeout(() => {\n this.flushing = false\n\n if (this.queue.length) {\n this.scheduleFlush(0)\n }\n }, 0)\n })\n }, timeout)\n }\n\n private async deliver(ctx: Ctx): Promise {\n await this.criticalTasks.done()\n\n const start = Date.now()\n try {\n ctx = await this.flushOne(ctx)\n const done = Date.now() - start\n this.emit('delivery_success', ctx)\n ctx.stats.gauge('delivered', done)\n ctx.log('debug', 'Delivered', ctx.event)\n return ctx\n } catch (err: any) {\n const error = err as Ctx | Error | ContextCancelation\n ctx.log('error', 'Failed to deliver', error)\n this.emit('delivery_failure', ctx, error)\n ctx.stats.increment('delivery_failed')\n throw err\n }\n }\n\n private enqueuRetry(err: Error, ctx: Ctx): boolean {\n const retriable = !(err instanceof ContextCancelation) || err.retry\n if (!retriable) {\n return false\n }\n\n return this.queue.pushWithBackoff(ctx)\n }\n\n async flush(): Promise {\n if (this.queue.length === 0) {\n return []\n }\n\n let ctx = this.queue.pop()\n if (!ctx) {\n return []\n }\n\n ctx.attempts = this.queue.getAttempts(ctx)\n\n try {\n ctx = await this.deliver(ctx)\n this.emit('flush', ctx, true)\n } catch (err: any) {\n const accepted = this.enqueuRetry(err, ctx)\n\n if (!accepted) {\n ctx.setFailedDelivery({ reason: err })\n this.emit('flush', ctx, false)\n }\n\n return []\n }\n\n return [ctx]\n }\n\n private isReady(): boolean {\n // return this.plugins.every((p) => p.isLoaded())\n // should we wait for every plugin to load?\n return true\n }\n\n private availableExtensions(denyList: Integrations) {\n const available = this.plugins.filter((p) => {\n // Only filter out destination plugins or the Segment.io plugin\n if (p.type !== 'destination' && p.name !== 'Segment.io') {\n return true\n }\n\n let alternativeNameMatch: boolean | JSONObject | undefined = undefined\n p.alternativeNames?.forEach((name) => {\n if (denyList[name] !== undefined) {\n alternativeNameMatch = denyList[name]\n }\n })\n\n // Explicit integration option takes precedence, `All: false` does not apply to Segment.io\n return (\n denyList[p.name] ??\n alternativeNameMatch ??\n (p.name === 'Segment.io' ? true : denyList.All) !== false\n )\n })\n\n const {\n before = [],\n enrichment = [],\n destination = [],\n after = [],\n } = groupBy(available, 'type')\n\n return {\n before,\n enrichment,\n destinations: destination,\n after,\n }\n }\n\n private async flushOne(ctx: Ctx): Promise {\n if (!this.isReady()) {\n throw new Error('Not ready')\n }\n\n if (ctx.attempts > 1) {\n this.emit('delivery_retry', ctx)\n }\n\n const { before, enrichment } = this.availableExtensions(\n ctx.event.integrations ?? {}\n )\n\n for (const beforeWare of before) {\n const temp = await ensure(ctx, beforeWare)\n if (temp instanceof CoreContext) {\n ctx = temp\n }\n\n this.emit('message_enriched', ctx, beforeWare)\n }\n\n for (const enrichmentWare of enrichment) {\n const temp = await attempt(ctx, enrichmentWare)\n if (temp instanceof CoreContext) {\n ctx = temp\n }\n\n this.emit('message_enriched', ctx, enrichmentWare)\n }\n\n // Enrichment and before plugins can re-arrange the deny list dynamically\n // so we need to pluck them at the end\n const { destinations, after } = this.availableExtensions(\n ctx.event.integrations ?? {}\n )\n\n await new Promise((resolve, reject) => {\n setTimeout(() => {\n const attempts = destinations.map((destination) =>\n attempt(ctx, destination)\n )\n Promise.all(attempts).then(resolve).catch(reject)\n }, 0)\n })\n\n ctx.stats.increment('message_delivered')\n\n this.emit('message_delivered', ctx)\n\n const afterCalls = after.map((after) => attempt(ctx, after))\n await Promise.all(afterCalls)\n\n return ctx\n }\n}\n", "export {};\n//# sourceMappingURL=index.js.map", "import { CoreContext } from '../context'\nimport { Callback } from '../events/interfaces'\nimport { CoreEventQueue } from '../queue/event-queue'\nimport { invokeCallback } from '../callback'\nimport { Emitter } from '@segment/analytics-generic-utils'\n\nexport type DispatchOptions = {\n timeout?: number\n debug?: boolean\n callback?: Callback\n}\n\n/* The amount of time in ms to wait before invoking the callback. */\nexport const getDelay = (startTimeInEpochMS: number, timeoutInMS?: number) => {\n const elapsedTime = Date.now() - startTimeInEpochMS\n // increasing the timeout increases the delay by almost the same amount -- this is weird legacy behavior.\n return Math.max((timeoutInMS ?? 300) - elapsedTime, 0)\n}\n/**\n * Push an event into the dispatch queue and invoke any callbacks.\n *\n * @param event - Segment event to enqueue.\n * @param queue - Queue to dispatch against.\n * @param emitter - This is typically an instance of \"Analytics\" -- used for metrics / progress information.\n * @param options\n */\nexport async function dispatch<\n Ctx extends CoreContext,\n EQ extends CoreEventQueue\n>(\n ctx: Ctx,\n queue: EQ,\n emitter: Emitter,\n options?: DispatchOptions\n): Promise {\n emitter.emit('dispatch_start', ctx)\n\n const startTime = Date.now()\n let dispatched: Ctx\n if (queue.isEmpty()) {\n dispatched = await queue.dispatchSingle(ctx)\n } else {\n dispatched = await queue.dispatch(ctx)\n }\n\n if (options?.callback) {\n dispatched = await invokeCallback(\n dispatched,\n options.callback,\n getDelay(startTime, options.timeout)\n )\n }\n if (options?.debug) {\n dispatched.flush()\n }\n\n return dispatched\n}\n", "export function bindAll<\n ObjType extends { [key: string]: any },\n KeyType extends keyof ObjType\n>(obj: ObjType): ObjType {\n const proto = obj.constructor.prototype\n for (const key of Object.getOwnPropertyNames(proto)) {\n if (key !== 'constructor') {\n const desc = Object.getOwnPropertyDescriptor(\n obj.constructor.prototype,\n key\n )\n if (!!desc && typeof desc.value === 'function') {\n obj[key as KeyType] = obj[key].bind(obj)\n }\n }\n }\n\n return obj\n}\n", "export * from './emitter/interface'\nexport * from './plugins'\nexport * from './events/interfaces'\nexport * from './events'\nexport * from './callback'\nexport * from './priority-queue'\nexport { backoff } from './priority-queue/backoff'\nexport * from './context'\nexport * from './queue/event-queue'\nexport * from './analytics'\nexport * from './analytics/dispatch'\nexport * from './validation/helpers'\nexport * from './validation/errors'\nexport * from './validation/assertions'\nexport * from './utils/bind-all'\nexport * from './stats'\nexport { CoreLogger } from './logger'\nexport * from './queue/delivery'\n", "export function isBrowser(): boolean {\n return typeof window !== 'undefined'\n}\n\nexport function isServer(): boolean {\n return !isBrowser()\n}\n", "import { isBrowser } from '../environment'\n\nexport function isOnline(): boolean {\n if (isBrowser()) {\n return window.navigator.onLine\n }\n\n return true\n}\n\nexport function isOffline(): boolean {\n return !isOnline()\n}\n", "export default function(url, options) {\n\toptions = options || {};\n\treturn new Promise( (resolve, reject) => {\n\t\tconst request = new XMLHttpRequest();\n\t\tconst keys = [];\n\t\tconst all = [];\n\t\tconst headers = {};\n\n\t\tconst response = () => ({\n\t\t\tok: (request.status/100|0) == 2,\t\t// 200-299\n\t\t\tstatusText: request.statusText,\n\t\t\tstatus: request.status,\n\t\t\turl: request.responseURL,\n\t\t\ttext: () => Promise.resolve(request.responseText),\n\t\t\tjson: () => Promise.resolve(request.responseText).then(JSON.parse),\n\t\t\tblob: () => Promise.resolve(new Blob([request.response])),\n\t\t\tclone: response,\n\t\t\theaders: {\n\t\t\t\tkeys: () => keys,\n\t\t\t\tentries: () => all,\n\t\t\t\tget: n => headers[n.toLowerCase()],\n\t\t\t\thas: n => n.toLowerCase() in headers\n\t\t\t}\n\t\t});\n\n\t\trequest.open(options.method || 'get', url, true);\n\n\t\trequest.onload = () => {\n\t\t\trequest.getAllResponseHeaders().replace(/^(.*?):[^\\S\\n]*([\\s\\S]*?)$/gm, (m, key, value) => {\n\t\t\t\tkeys.push(key = key.toLowerCase());\n\t\t\t\tall.push([key, value]);\n\t\t\t\theaders[key] = headers[key] ? `${headers[key]},${value}` : value;\n\t\t\t});\n\t\t\tresolve(response());\n\t\t};\n\n\t\trequest.onerror = reject;\n\n\t\trequest.withCredentials = options.credentials=='include';\n\n\t\tfor (const i in options.headers) {\n\t\t\trequest.setRequestHeader(i, options.headers[i]);\n\t\t}\n\n\t\trequest.send(options.body || null);\n\t});\n}\n", "// This an imperfect polyfill for globalThis\nexport const getGlobal = () => {\n if (typeof globalThis !== 'undefined') {\n return globalThis\n }\n if (typeof self !== 'undefined') {\n return self\n }\n if (typeof window !== 'undefined') {\n return window\n }\n if (typeof global !== 'undefined') {\n return global\n }\n return null\n}\n", "import unfetch from 'unfetch'\nimport { getGlobal } from './get-global'\n\n/**\n * Wrapper around native `fetch` containing `unfetch` fallback.\n */\nexport const fetch: typeof global.fetch = (...args) => {\n const global = getGlobal()\n return ((global && global.fetch) || unfetch)(...args)\n}\n", "// This file is generated.\nexport const version = '1.72.1'\n", "// Default value will be updated to 'web' in `bundle-umd.ts` for web build.\nlet _version: 'web' | 'npm' = 'npm'\n\nexport function setVersionType(version: typeof _version) {\n _version = version\n}\n\nexport function getVersionType(): typeof _version {\n return _version\n}\n", "export const SEGMENT_API_HOST = 'api.segment.io/v1'\n", "import { fetch } from '../../lib/fetch'\nimport { version } from '../../generated/version'\nimport { getVersionType } from '../../lib/version-type'\nimport { SEGMENT_API_HOST } from '../constants'\n\nexport interface MetricsOptions {\n host?: string\n sampleRate?: number\n flushTimer?: number\n maxQueueSize?: number\n protocol?: 'http' | 'https'\n}\n\n/**\n * Type expected by the segment metrics API endpoint\n */\ntype RemoteMetric = {\n type: 'Counter'\n metric: string\n value: 1\n tags: {\n library: string\n library_version: string\n [key: string]: string\n }\n}\n\nconst createRemoteMetric = (\n metric: string,\n tags: string[],\n versionType: 'web' | 'npm'\n): RemoteMetric => {\n const formattedTags = tags.reduce((acc, t) => {\n const [k, v] = t.split(':')\n acc[k] = v\n return acc\n }, {} as Record)\n\n return {\n type: 'Counter',\n metric,\n value: 1,\n tags: {\n ...formattedTags,\n library: 'analytics.js',\n library_version:\n versionType === 'web' ? `next-${version}` : `npm:next-${version}`,\n },\n }\n}\n\nfunction logError(err: unknown): void {\n console.error('Error sending segment performance metrics', err)\n}\n\nexport class RemoteMetrics {\n private host: string\n private flushTimer: number\n private maxQueueSize: number\n private protocol: string\n\n sampleRate: number\n queue: RemoteMetric[]\n\n constructor(options?: MetricsOptions) {\n this.host = options?.host ?? SEGMENT_API_HOST\n this.sampleRate = options?.sampleRate ?? 1\n this.flushTimer = options?.flushTimer ?? 30 * 1000 /* 30s */\n this.maxQueueSize = options?.maxQueueSize ?? 20\n this.protocol = options?.protocol ?? 'https'\n\n this.queue = []\n\n if (this.sampleRate > 0) {\n let flushing = false\n\n const run = (): void => {\n if (flushing) {\n return\n }\n\n flushing = true\n this.flush().catch(logError)\n\n flushing = false\n\n setTimeout(run, this.flushTimer)\n }\n run()\n }\n }\n\n increment(metric: string, tags: string[]): void {\n // All metrics are part of an allow list in Tracking API\n if (!metric.includes('analytics_js.')) {\n return\n }\n\n // /m doesn't like empty tags\n if (tags.length === 0) {\n return\n }\n\n if (Math.random() > this.sampleRate) {\n return\n }\n\n if (this.queue.length >= this.maxQueueSize) {\n return\n }\n\n const remoteMetric = createRemoteMetric(metric, tags, getVersionType())\n this.queue.push(remoteMetric)\n\n if (metric.includes('error')) {\n this.flush().catch(logError)\n }\n }\n\n async flush(): Promise {\n if (this.queue.length <= 0) {\n return\n }\n\n await this.send().catch((error) => {\n logError(error)\n this.sampleRate = 0\n })\n }\n\n private async send(): Promise {\n const payload = { series: this.queue }\n this.queue = []\n\n const headers = { 'Content-Type': 'text/plain' }\n const url = `${this.protocol}://${this.host}/m`\n\n return fetch(url, {\n headers,\n body: JSON.stringify(payload),\n method: 'POST',\n })\n }\n}\n", "import { CoreStats } from '@segment/analytics-core'\nimport { MetricsOptions, RemoteMetrics } from './remote-metrics'\n\nlet remoteMetrics: RemoteMetrics | undefined\n\nexport class Stats extends CoreStats {\n static initRemoteMetrics(options?: MetricsOptions) {\n remoteMetrics = new RemoteMetrics(options)\n }\n\n override increment(metric: string, by?: number, tags?: string[]): void {\n super.increment(metric, by, tags)\n remoteMetrics?.increment(metric, tags ?? [])\n }\n}\n", "import {\n CoreContext,\n ContextCancelation,\n ContextFailedDelivery,\n SerializedContext,\n CancelationOptions,\n} from '@segment/analytics-core'\nimport { SegmentEvent } from '../events/interfaces'\nimport { Stats } from '../stats'\n\nexport class Context extends CoreContext {\n static override system() {\n return new this({ type: 'track', event: 'system' })\n }\n constructor(event: SegmentEvent, id?: string) {\n super(event, id, new Stats())\n }\n}\n\nexport { ContextCancelation }\nexport type { ContextFailedDelivery, SerializedContext, CancelationOptions }\n", "import { PriorityQueue, ON_REMOVE_FROM_FUTURE } from '@segment/analytics-core'\n\nexport { PriorityQueue, ON_REMOVE_FROM_FUTURE }\n", "import { PriorityQueue } from '.'\nimport { Context, SerializedContext } from '../../core/context'\nimport { isBrowser } from '../../core/environment'\n\nlet loc:\n | Storage\n | { getItem: () => void; setItem: () => void; removeItem: () => void } = {\n getItem() {},\n setItem() {},\n removeItem() {},\n}\n\ntry {\n loc = isBrowser() && window.localStorage ? window.localStorage : loc\n} catch (err) {\n console.warn('Unable to access localStorage', err)\n}\n\nfunction persisted(key: string): Context[] {\n const items = loc.getItem(key)\n return (items ? JSON.parse(items) : []).map(\n (p: SerializedContext) => new Context(p.event, p.id)\n )\n}\n\nfunction persistItems(key: string, items: Context[]): void {\n const existing = persisted(key)\n const all = [...items, ...existing]\n\n const merged = all.reduce((acc, item) => {\n return {\n ...acc,\n [item.id]: item,\n }\n }, {} as Record)\n\n loc.setItem(key, JSON.stringify(Object.values(merged)))\n}\n\nfunction seen(key: string): Record {\n const stored = loc.getItem(key)\n return stored ? JSON.parse(stored) : {}\n}\n\nfunction persistSeen(key: string, memory: Record): void {\n const stored = seen(key)\n\n loc.setItem(\n key,\n JSON.stringify({\n ...stored,\n ...memory,\n })\n )\n}\n\nfunction remove(key: string): void {\n loc.removeItem(key)\n}\n\nconst now = (): number => new Date().getTime()\n\nfunction mutex(key: string, onUnlock: Function, attempt = 0): void {\n const lockTimeout = 50\n const lockKey = `persisted-queue:v1:${key}:lock`\n\n const expired = (lock: number): boolean => new Date().getTime() > lock\n const rawLock = loc.getItem(lockKey)\n const lock = rawLock ? (JSON.parse(rawLock) as number) : null\n\n const allowed = lock === null || expired(lock)\n if (allowed) {\n loc.setItem(lockKey, JSON.stringify(now() + lockTimeout))\n onUnlock()\n loc.removeItem(lockKey)\n return\n }\n\n if (!allowed && attempt < 3) {\n setTimeout(() => {\n mutex(key, onUnlock, attempt + 1)\n }, lockTimeout)\n } else {\n console.error('Unable to retrieve lock')\n }\n}\n\nexport class PersistedPriorityQueue extends PriorityQueue {\n constructor(maxAttempts: number, key: string) {\n super(maxAttempts, [])\n\n const itemsKey = `persisted-queue:v1:${key}:items`\n const seenKey = `persisted-queue:v1:${key}:seen`\n\n let saved: Context[] = []\n let lastSeen: Record = {}\n\n mutex(key, () => {\n try {\n saved = persisted(itemsKey)\n lastSeen = seen(seenKey)\n remove(itemsKey)\n remove(seenKey)\n\n this.queue = [...saved, ...this.queue]\n this.seen = { ...lastSeen, ...this.seen }\n } catch (err) {\n console.error(err)\n }\n })\n\n window.addEventListener('pagehide', () => {\n // we deliberately want to use the less powerful 'pagehide' API to only persist on events where the analytics instance gets destroyed, and not on tab away.\n if (this.todo > 0) {\n const items = [...this.queue, ...this.future]\n try {\n mutex(key, () => {\n persistItems(itemsKey, items)\n persistSeen(seenKey, this.seen)\n })\n } catch (err) {\n console.error(err)\n }\n }\n })\n }\n}\n", "import { AnalyticsSnippet } from '../browser/standalone-interface'\n\n/**\n * Stores the global window analytics key\n */\nlet _globalAnalyticsKey = 'analytics'\n\n/**\n * Gets the global analytics/buffer\n * @param key name of the window property where the buffer is stored (default: analytics)\n * @returns AnalyticsSnippet\n */\nexport function getGlobalAnalytics(): AnalyticsSnippet | undefined {\n return (window as any)[_globalAnalyticsKey]\n}\n\n/**\n * Replaces the global window key for the analytics/buffer object\n * @param key key name\n */\nexport function setGlobalAnalyticsKey(key: string) {\n _globalAnalyticsKey = key\n}\n\n/**\n * Sets the global analytics object\n * @param analytics analytics snippet\n */\nexport function setGlobalAnalytics(analytics: AnalyticsSnippet): void {\n ;(window as any)[_globalAnalyticsKey] = analytics\n}\n", "export { invokeCallback, pTimeout } from '@segment/analytics-core'\n", "import { Analytics } from './analytics'\nimport { EventProperties, Options } from './events'\nimport { pTimeout } from './callback'\n\n// Check if a user is opening the link in a new tab\nfunction userNewTab(event: Event): boolean {\n const typedEvent = event as Event & {\n ctrlKey: boolean\n shiftKey: boolean\n metaKey: boolean\n button: number\n }\n if (\n typedEvent.ctrlKey ||\n typedEvent.shiftKey ||\n typedEvent.metaKey ||\n (typedEvent.button && typedEvent.button == 1)\n ) {\n return true\n }\n return false\n}\n\n// Check if the link opens in new tab\nfunction linkNewTab(element: HTMLAnchorElement, href: string | null): boolean {\n if (element.target === '_blank' && href) {\n return true\n }\n return false\n}\n\nexport interface JQueryShim {\n toArray(): TElement[]\n}\n\nexport function link(\n this: Analytics,\n links: Element | Array | JQueryShim | null,\n event: string | Function,\n properties?: EventProperties | Function,\n options?: Options\n): Analytics {\n let elements: Array = []\n // always arrays, handles jquery\n if (!links) {\n return this\n }\n if (links instanceof Element) {\n elements = [links]\n } else if ('toArray' in links) {\n elements = links.toArray()\n } else {\n elements = links\n }\n\n elements.forEach((el: Element) => {\n el.addEventListener(\n 'click',\n (elementEvent: Event) => {\n const ev = event instanceof Function ? event(el) : event\n const props =\n properties instanceof Function ? properties(el) : properties\n const href =\n el.getAttribute('href') ||\n el.getAttributeNS('http://www.w3.org/1999/xlink', 'href') ||\n el.getAttribute('xlink:href') ||\n el.getElementsByTagName('a')[0]?.getAttribute('href')\n\n const trackEvent = pTimeout(\n this.track(ev, props, options ?? {}),\n this.settings.timeout ?? 500\n )\n\n if (\n !linkNewTab(el as HTMLAnchorElement, href) &&\n !userNewTab(elementEvent)\n ) {\n if (href) {\n elementEvent.preventDefault\n ? elementEvent.preventDefault()\n : (elementEvent.returnValue = false)\n trackEvent\n .catch(console.error)\n .then(() => {\n window.location.href = href\n })\n .catch(console.error)\n }\n }\n },\n false\n )\n })\n\n return this\n}\n\nexport type LinkArgs = Parameters\n\nexport function form(\n this: Analytics,\n forms: HTMLFormElement | Array | null,\n event: string | Function,\n properties?: EventProperties | Function,\n options?: Options\n): Analytics {\n // always arrays, handles jquery\n if (!forms) return this\n if (forms instanceof HTMLFormElement) forms = [forms]\n\n const elements = forms\n\n elements.forEach((el) => {\n if (!(el instanceof Element))\n throw new TypeError('Must pass HTMLElement to trackForm/trackSubmit.')\n const handler = (elementEvent: Event): void => {\n elementEvent.preventDefault\n ? elementEvent.preventDefault()\n : (elementEvent.returnValue = false)\n\n const ev = event instanceof Function ? event(el) : event\n const props = properties instanceof Function ? properties(el) : properties\n\n const trackEvent = pTimeout(\n this.track(ev, props, options ?? {}),\n this.settings.timeout ?? 500\n )\n\n trackEvent\n .catch(console.error)\n .then(() => {\n el.submit()\n })\n .catch(console.error)\n }\n\n // Support the events happening through jQuery or Zepto instead of through\n // the normal DOM API, because `el.submit` doesn't bubble up events...\n\n const $ = (window as any).jQuery || (window as any).Zepto\n if ($) {\n $(el).submit(handler)\n } else {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n el.addEventListener('submit', handler, false)\n }\n })\n\n return this\n}\n\nexport type FormArgs = Parameters\n", "\nvar identity = function(_){ return _; };\n\n\n/**\n * Module exports, export\n */\n\nmodule.exports = multiple(find);\nmodule.exports.find = module.exports;\n\n\n/**\n * Export the replacement function, return the modified object\n */\n\nmodule.exports.replace = function (obj, key, val, options) {\n multiple(replace).call(this, obj, key, val, options);\n return obj;\n};\n\n\n/**\n * Export the delete function, return the modified object\n */\n\nmodule.exports.del = function (obj, key, options) {\n multiple(del).call(this, obj, key, null, options);\n return obj;\n};\n\n\n/**\n * Compose applying the function to a nested key\n */\n\nfunction multiple (fn) {\n return function (obj, path, val, options) {\n var normalize = options && isFunction(options.normalizer) ? options.normalizer : defaultNormalize;\n path = normalize(path);\n\n var key;\n var finished = false;\n\n while (!finished) loop();\n\n function loop() {\n for (key in obj) {\n var normalizedKey = normalize(key);\n if (0 === path.indexOf(normalizedKey)) {\n var temp = path.substr(normalizedKey.length);\n if (temp.charAt(0) === '.' || temp.length === 0) {\n path = temp.substr(1);\n var child = obj[key];\n\n // we're at the end and there is nothing.\n if (null == child) {\n finished = true;\n return;\n }\n\n // we're at the end and there is something.\n if (!path.length) {\n finished = true;\n return;\n }\n\n // step into child\n obj = child;\n\n // but we're done here\n return;\n }\n }\n }\n\n key = undefined;\n // if we found no matching properties\n // on the current object, there's no match.\n finished = true;\n }\n\n if (!key) return;\n if (null == obj) return obj;\n\n // the `obj` and `key` is one above the leaf object and key, so\n // start object: { a: { 'b.c': 10 } }\n // end object: { 'b.c': 10 }\n // end key: 'b.c'\n // this way, you can do `obj[key]` and get `10`.\n return fn(obj, key, val);\n };\n}\n\n\n/**\n * Find an object by its key\n *\n * find({ first_name : 'Calvin' }, 'firstName')\n */\n\nfunction find (obj, key) {\n if (obj.hasOwnProperty(key)) return obj[key];\n}\n\n\n/**\n * Delete a value for a given key\n *\n * del({ a : 'b', x : 'y' }, 'X' }) -> { a : 'b' }\n */\n\nfunction del (obj, key) {\n if (obj.hasOwnProperty(key)) delete obj[key];\n return obj;\n}\n\n\n/**\n * Replace an objects existing value with a new one\n *\n * replace({ a : 'b' }, 'a', 'c') -> { a : 'c' }\n */\n\nfunction replace (obj, key, val) {\n if (obj.hasOwnProperty(key)) obj[key] = val;\n return obj;\n}\n\n/**\n * Normalize a `dot.separated.path`.\n *\n * A.HELL(!*(!)O_WOR LD.bar => ahelloworldbar\n *\n * @param {String} path\n * @return {String}\n */\n\nfunction defaultNormalize(path) {\n return path.replace(/[^a-zA-Z0-9\\.]+/g, '').toLowerCase();\n}\n\n/**\n * Check if a value is a function.\n *\n * @param {*} val\n * @return {boolean} Returns `true` if `val` is a function, otherwise `false`.\n */\n\nfunction isFunction(val) {\n return typeof val === 'function';\n}\n", "\"use strict\";\n\nimport get from \"obj-case\";\n\nfunction trait(a, b) {\n return function () {\n // @ts-ignore\n let traits = this.traits();\n // @ts-ignore\n let props = this.properties ? this.properties() : {};\n\n return (\n get(traits, \"address.\" + a) ||\n get(traits, a) ||\n (b ? get(traits, \"address.\" + b) : null) ||\n (b ? get(traits, b) : null) ||\n get(props, \"address.\" + a) ||\n get(props, a) ||\n (b ? get(props, \"address.\" + b) : null) ||\n (b ? get(props, b) : null)\n );\n };\n}\n\n/**\n * Add address getters to `proto`.\n *\n * @ignore\n * @param {Function} proto\n */\nexport default function (proto) {\n proto.zip = trait(\"postalCode\", \"zip\");\n proto.country = trait(\"country\");\n proto.street = trait(\"street\");\n proto.state = trait(\"state\");\n proto.city = trait(\"city\");\n proto.region = trait(\"region\");\n}\n", "export function clone(properties) {\n if (typeof properties !== 'object') return properties\n\n if (Object.prototype.toString.call(properties) === '[object Object]') {\n const temp = {};\n for (const key in properties) {\n if (Object.prototype.hasOwnProperty.call(properties, key)) {\n temp[key] = clone(properties[key]);\n }\n }\n return temp;\n } else if (Array.isArray(properties)) {\n return properties.map(clone);\n } else {\n // this is dangerous because it means this is not cloned\n return properties;\n }\n}\n", "\"use strict\";\n\n// A few integrations are disabled by default. They must be explicitly enabled\n// by setting options[Provider] = true.\nlet disabled = {\n Salesforce: true,\n};\n\n/**\n * Check whether an integration should be enabled by default.\n *\n * @ignore\n * @param {string} integration\n * @return {boolean}\n */\nexport default function (integration) {\n return !disabled[integration];\n}\n", "'use strict';\n\n/**\n * Matcher, slightly modified from:\n *\n * https://github.com/csnover/js-iso8601/blob/lax/iso8601.js\n */\n\nvar matcher = /^(\\d{4})(?:-?(\\d{2})(?:-?(\\d{2}))?)?(?:([ T])(\\d{2}):?(\\d{2})(?::?(\\d{2})(?:[,\\.](\\d{1,}))?)?(?:(Z)|([+\\-])(\\d{2})(?::?(\\d{2}))?)?)?$/;\n\n/**\n * Convert an ISO date string to a date. Fallback to native `Date.parse`.\n *\n * https://github.com/csnover/js-iso8601/blob/lax/iso8601.js\n *\n * @param {String} iso\n * @return {Date}\n */\n\nexports.parse = function(iso) {\n var numericKeys = [1, 5, 6, 7, 11, 12];\n var arr = matcher.exec(iso);\n var offset = 0;\n\n // fallback to native parsing\n if (!arr) {\n return new Date(iso);\n }\n\n /* eslint-disable no-cond-assign */\n // remove undefined values\n for (var i = 0, val; val = numericKeys[i]; i++) {\n arr[val] = parseInt(arr[val], 10) || 0;\n }\n /* eslint-enable no-cond-assign */\n\n // allow undefined days and months\n arr[2] = parseInt(arr[2], 10) || 1;\n arr[3] = parseInt(arr[3], 10) || 1;\n\n // month is 0-11\n arr[2]--;\n\n // allow abitrary sub-second precision\n arr[8] = arr[8] ? (arr[8] + '00').substring(0, 3) : 0;\n\n // apply timezone if one exists\n if (arr[4] === ' ') {\n offset = new Date().getTimezoneOffset();\n } else if (arr[9] !== 'Z' && arr[10]) {\n offset = arr[11] * 60 + arr[12];\n if (arr[10] === '+') {\n offset = 0 - offset;\n }\n }\n\n var millis = Date.UTC(arr[1], arr[2], arr[3], arr[5], arr[6] + offset, arr[7], arr[8]);\n return new Date(millis);\n};\n\n\n/**\n * Checks whether a `string` is an ISO date string. `strict` mode requires that\n * the date string at least have a year, month and date.\n *\n * @param {String} string\n * @param {Boolean} strict\n * @return {Boolean}\n */\n\nexports.is = function(string, strict) {\n if (typeof string !== 'string') {\n return false;\n }\n if (strict && (/^\\d{4}-\\d{2}-\\d{2}/).test(string) === false) {\n return false;\n }\n return matcher.test(string);\n};\n", "\"use strict\";\n\n/**\n * Matcher.\n */\n\nvar matcher = /\\d{13}/;\n\n/**\n * Check whether a string is a millisecond date string.\n *\n * @param {string} string\n * @return {boolean}\n */\nexports.is = function (string) {\n return matcher.test(string);\n};\n\n/**\n * Convert a millisecond string to a date.\n *\n * @param {string} millis\n * @return {Date}\n */\nexports.parse = function (millis) {\n millis = parseInt(millis, 10);\n return new Date(millis);\n};\n", "\"use strict\";\n\n/**\n * Matcher.\n */\n\nvar matcher = /\\d{10}/;\n\n/**\n * Check whether a string is a second date string.\n *\n * @param {string} string\n * @return {Boolean}\n */\nexports.is = function (string) {\n return matcher.test(string);\n};\n\n/**\n * Convert a second string to a date.\n *\n * @param {string} seconds\n * @return {Date}\n */\nexports.parse = function (seconds) {\n var millis = parseInt(seconds, 10) * 1000;\n return new Date(millis);\n};\n", "\"use strict\";\n\nvar isodate = require(\"@segment/isodate\");\nvar milliseconds = require(\"./milliseconds\");\nvar seconds = require(\"./seconds\");\n\nvar objProto = Object.prototype;\nvar toStr = objProto.toString;\n\nfunction isDate(value) {\n return toStr.call(value) === \"[object Date]\";\n}\n\nfunction isNumber(value) {\n return toStr.call(value) === \"[object Number]\";\n}\n\n/**\n * Returns a new Javascript Date object, allowing a variety of extra input types\n * over the native Date constructor.\n *\n * @param {Date|string|number} val\n */\nmodule.exports = function newDate(val) {\n if (isDate(val)) return val;\n if (isNumber(val)) return new Date(toMs(val));\n\n // date strings\n if (isodate.is(val)) {\n return isodate.parse(val);\n }\n if (milliseconds.is(val)) {\n return milliseconds.parse(val);\n }\n if (seconds.is(val)) {\n return seconds.parse(val);\n }\n\n // fallback to Date.parse\n return new Date(val);\n};\n\n/**\n * If the number passed val is seconds from the epoch, turn it into milliseconds.\n * Milliseconds would be greater than 31557600000 (December 31, 1970).\n *\n * @param {number} num\n */\nfunction toMs(num) {\n if (num < 31557600000) return num * 1000;\n return num;\n}\n", "'use strict';\n\nvar isodate = require('@segment/isodate');\n\n/**\n * Expose `traverse`.\n */\nmodule.exports = traverse;\n\n/**\n * Recursively traverse an object or array, and convert\n * all ISO date strings parse into Date objects.\n *\n * @param {Object} input - object, array, or string to convert\n * @param {Boolean} strict - only convert strings with year, month, and date\n * @return {Object}\n */\nfunction traverse(input, strict) {\n if (strict === undefined) strict = true;\n if (input && typeof input === 'object') {\n return traverseObject(input, strict);\n } else if (Array.isArray(input)) {\n return traverseArray(input, strict);\n } else if (isodate.is(input, strict)) {\n return isodate.parse(input);\n }\n return input;\n}\n\n/**\n * Object traverser helper function.\n *\n * @param {Object} obj - object to traverse\n * @param {Boolean} strict - only convert strings with year, month, and date\n * @return {Object}\n */\nfunction traverseObject(obj, strict) {\n Object.keys(obj).forEach(function(key) {\n obj[key] = traverse(obj[key], strict);\n });\n return obj;\n}\n\n/**\n * Array traverser helper function\n *\n * @param {Array} arr - array to traverse\n * @param {Boolean} strict - only convert strings with year, month, and date\n * @return {Array}\n */\nfunction traverseArray(arr, strict) {\n arr.forEach(function(value, index) {\n arr[index] = traverse(value, strict);\n });\n return arr;\n}\n", "\"use strict\";\n\nimport address from \"./address\";\nimport { clone } from \"./clone\";\nimport isEnabled from \"./is-enabled\";\nimport newDate from \"new-date\";\nimport objCase from \"obj-case\";\nimport traverse from \"@segment/isodate-traverse\";\n\n/**\n * A *Facade* is an object meant for creating convience wrappers around\n * objects. When developing integrations, you probably want to look at its\n * subclasses, such as {@link Track} or {@link Identify}, rather than this\n * general-purpose class.\n *\n * This letructor will initialize a new `Facade` with an `obj` of arguments.\n *\n * If the inputted `obj` doesn't have a `timestamp` property, one will be added\n * with the value `new Date()`. Otherwise, the `timestamp` property will be\n * converted to a Date using the `new-date` package.\n *\n * By default, the inputted object will be defensively copied, and all ISO\n * strings present in the string will be converted into Dates.\n *\n * @param {Object} obj - The object to wrap.\n * @param {Object} opts - Options about what kind of Facade to create.\n * @param {boolean} [opts.clone=true] - Whether to make defensive clones. If enabled,\n * the inputted object will be cloned, and any objects derived from this facade\n * will be cloned before being returned.\n * @param {boolean} [opts.traverse=true] - Whether to perform ISODate-Traverse\n * on the inputted object.\n *\n * @see {@link https://github.com/segmentio/new-date|new-date}\n * @see {@link https://github.com/segmentio/isodate-traverse|isodate-traverse}\n */\nexport function Facade (obj, opts) {\n opts = opts || {};\n this.raw = clone(obj);\n if (!(\"clone\" in opts)) opts.clone = true;\n if (opts.clone) obj = clone(obj);\n if (!(\"traverse\" in opts)) opts.traverse = true;\n if (!(\"timestamp\" in obj)) obj.timestamp = new Date();\n else obj.timestamp = newDate(obj.timestamp);\n if (opts.traverse) traverse(obj);\n this.opts = opts;\n this.obj = obj;\n}\n\nconst f = Facade.prototype;\n\n/**\n * Get a potentially-nested field in this facade. `field` should be a\n * period-separated sequence of properties.\n *\n * If the first field passed in points to a function (e.g. the `field` passed\n * in is `a.b.c` and this facade's `obj.a` is a function), then that function\n * will be called, and then the deeper fields will be fetched (using obj-case)\n * from what that function returns. If the first field isn't a function, then\n * this function works just like obj-case.\n *\n * Because this function uses obj-case, the camel- or snake-case of the input\n * is irrelevant.\n *\n * @example\n * YourClass.prototype.height = function() {\n * return this.proxy('getDimensions.height') ||\n * this.proxy('props.size.side_length');\n * }\n * @param {string} field - A sequence of properties, joined by periods (`.`).\n * @return {*} - A property of the inputted object.\n * @see {@link https://github.com/segmentio/obj-case|obj-case}\n */\nf.proxy = function(field) {\n let fields = field.split(\".\");\n field = fields.shift();\n\n // Call a function at the beginning to take advantage of facaded fields\n let obj = this[field] || this.obj[field];\n if (!obj) return obj;\n if (typeof obj === \"function\") obj = obj.call(this) || {};\n if (fields.length === 0) return this.opts.clone ? transform(obj) : obj;\n\n obj = objCase(obj, fields.join(\".\"));\n return this.opts.clone ? transform(obj) : obj;\n};\n\n/**\n * Directly access a specific `field` from the underlying object. Only\n * \"top-level\" fields will work with this function. \"Nested\" fields *will not\n * work* with this function.\n *\n * @param {string} field\n * @return {*}\n */\nf.field = function(field) {\n let obj = this.obj[field];\n return this.opts.clone ? transform(obj) : obj;\n};\n\n/**\n * Utility method to always proxy a particular `field`. In other words, it\n * returns a function that will always return `this.proxy(field)`.\n *\n * @example\n * MyClass.prototype.height = Facade.proxy('options.dimensions.height');\n *\n * @param {string} field\n * @return {Function}\n */\nFacade.proxy = function(field) {\n return function() {\n return this.proxy(field);\n };\n};\n\n/**\n * Utility method to always access a `field`. In other words, it returns a\n * function that will always return `this.field(field)`.\n *\n * @param {string} field\n * @return {Function}\n */\nFacade.field = function(field) {\n return function() {\n return this.field(field);\n };\n};\n\n/**\n * Create a helper function for fetching a \"plural\" thing.\n *\n * The generated method will take the inputted `path` and append an \"s\" to it\n * and calls `this.proxy` with this \"pluralized\" path. If that produces an\n * array, that will be returned. Otherwise, a one-element array containing\n * `this.proxy(path)` will be returned.\n *\n * @example\n * MyClass.prototype.birds = Facade.multi('animals.bird');\n *\n * @param {string} path\n * @return {Function}\n */\nFacade.multi = function(path) {\n return function() {\n let multi = this.proxy(path + \"s\");\n if (Array.isArray(multi)) return multi;\n let one = this.proxy(path);\n if (one) one = [this.opts.clone ? clone(one) : one];\n return one || [];\n };\n};\n\n/**\n * Create a helper function for getting a \"singular\" thing.\n *\n * The generated method will take the inputted path and call\n * `this.proxy(path)`. If a truthy thing is produced, it will be returned.\n * Otherwise, `this.proxy(path + 's')` will be called, and if that produces an\n * array the first element of that array will be returned. Otherwise,\n * `undefined` is returned.\n *\n * @example\n * MyClass.prototype.bird = Facade.one('animals.bird');\n *\n * @param {string} path\n * @return {Function}\n */\nFacade.one = function(path) {\n return function() {\n let one = this.proxy(path);\n if (one) return one;\n let multi = this.proxy(path + \"s\");\n if (Array.isArray(multi)) return multi[0];\n };\n};\n\n/**\n * Gets the underlying object this facade wraps around.\n *\n * If this facade has a property `type`, it will be invoked as a function and\n * will be assigned as the property `type` of the outputted object.\n *\n * @return {Object}\n */\nf.json = function() {\n let ret = this.opts.clone ? clone(this.obj) : this.obj;\n if (this.type) ret.type = this.type();\n return ret;\n};\n\n/**\n * Gets a copy of the unmodified input object this facade wraps around.\n * \n * Unlike the `json` method which does make some subtle modifications \n * to datetime values and the `type` property. This method returns a copy of \n * the unmodified input object\n * \n * @return {Object}\n */\nf.rawEvent = function() {\n return this.raw;\n};\n\n/**\n * Get the options of a call. If an integration is passed, only the options for\n * that integration are included. If the integration is not enabled, then\n * `undefined` is returned.\n *\n * Options are taken from the `options` property of the underlying object,\n * falling back to the object's `context` or simply `{}`.\n *\n * @param {string} integration - The name of the integration to get settings\n * for. Casing does not matter.\n * @return {Object|undefined}\n */\nf.options = function(integration) {\n let obj = this.obj.options || this.obj.context || {};\n let options = this.opts.clone ? clone(obj) : obj;\n if (!integration) return options;\n if (!this.enabled(integration)) return;\n let integrations = this.integrations();\n let value = integrations[integration] || objCase(integrations, integration);\n if (typeof value !== \"object\") value = objCase(this.options(), integration);\n return typeof value === \"object\" ? value : {};\n};\n\n/**\n * An alias for {@link Facade#options}.\n */\nf.context = f.options;\n\n/**\n * Check whether an integration is enabled.\n *\n * Basically, this method checks whether this integration is explicitly\n * enabled. If it isn'texplicitly mentioned, it checks whether it has been\n * enabled at the global level. Some integrations (e.g. Salesforce), cannot\n * enabled by these global event settings.\n *\n * More concretely, the deciding factors here are:\n *\n * 1. If `this.integrations()` has the integration set to `true`, return `true`.\n * 2. If `this.integrations().providers` has the integration set to `true`, return `true`.\n * 3. If integrations are set to default-disabled via global parameters (i.e.\n * `options.providers.all`, `options.all`, or `integrations.all`), then return\n * false.\n * 4. If the integration is one of the special default-deny integrations\n * (currently, only Salesforce), then return false.\n * 5. Else, return true.\n *\n * @param {string} integration\n * @return {boolean}\n */\nf.enabled = function(integration) {\n let allEnabled = this.proxy(\"options.providers.all\");\n if (typeof allEnabled !== \"boolean\") allEnabled = this.proxy(\"options.all\");\n if (typeof allEnabled !== \"boolean\")\n allEnabled = this.proxy(\"integrations.all\");\n if (typeof allEnabled !== \"boolean\") allEnabled = true;\n\n let enabled = allEnabled && isEnabled(integration);\n let options = this.integrations();\n\n // If the integration is explicitly enabled or disabled, use that\n // First, check options.providers for backwards compatibility\n if (options.providers && options.providers.hasOwnProperty(integration)) {\n enabled = options.providers[integration];\n }\n\n // Next, check for the integration's existence in 'options' to enable it.\n // If the settings are a boolean, use that, otherwise it should be enabled.\n if (options.hasOwnProperty(integration)) {\n let settings = options[integration];\n if (typeof settings === \"boolean\") {\n enabled = settings;\n } else {\n enabled = true;\n }\n }\n\n return !!enabled;\n};\n\n/**\n * Get all `integration` options.\n *\n * @ignore\n * @param {string} integration\n * @return {Object}\n */\nf.integrations = function() {\n return (\n this.obj.integrations || this.proxy(\"options.providers\") || this.options()\n );\n};\n\n/**\n * Check whether the user is active.\n *\n * @return {boolean}\n */\nf.active = function() {\n let active = this.proxy(\"options.active\");\n if (active === null || active === undefined) active = true;\n return active;\n};\n\n/**\n * Get `sessionId / anonymousId`.\n *\n * @return {*}\n */\nf.anonymousId = function() {\n return this.field(\"anonymousId\") || this.field(\"sessionId\");\n};\n\n/**\n * An alias for {@link Facade#anonymousId}.\n *\n * @function\n * @return {string}\n */\nf.sessionId = f.anonymousId;\n\n/**\n * Get `groupId` from `context.groupId`.\n *\n * @function\n * @return {string}\n */\nf.groupId = Facade.proxy(\"options.groupId\");\n\n/**\n * Get the call's \"traits\". All event types can pass in traits, though {@link\n * Identify} and {@link Group} override this implementation.\n *\n * Traits are gotten from `options.traits`, augmented with a property `id` with\n * the event's `userId`.\n *\n * The parameter `aliases` is meant to transform keys in `options.traits` into\n * new keys. Each alias like `{ \"xxx\": \"yyy\" }` will take whatever is at `xxx`\n * in the traits, and move it to `yyy`. If `xxx` is a method of this facade,\n * it'll be called as a function instead of treated as a key into the traits.\n *\n * @example\n * let obj = { options: { traits: { foo: \"bar\" } }, anonymousId: \"xxx\" }\n * let facade = new Facade(obj)\n *\n * facade.traits() // { \"foo\": \"bar\" }\n * facade.traits({ \"foo\": \"asdf\" }) // { \"asdf\": \"bar\" }\n * facade.traits({ \"sessionId\": \"rofl\" }) // { \"rofl\": \"xxx\" }\n *\n * @param {Object} aliases - A mapping from keys to the new keys they should be\n * transformed to.\n * @return {Object}\n */\nf.traits = function(aliases) {\n let ret = this.proxy(\"options.traits\") || {};\n let id = this.userId();\n aliases = aliases || {};\n\n if (id) ret.id = id;\n\n for (const alias in aliases) {\n if (Object.prototype.hasOwnProperty.call(aliases, alias)) {\n const value = this[alias] == null\n ? this.proxy(\"options.traits.\" + alias)\n : this[alias]();\n if (value == null) continue;\n ret[aliases[alias]] = value;\n delete ret[alias];\n }\n }\n\n return ret;\n};\n\n/**\n * The library and version of the client used to produce the message.\n *\n * If the library name cannot be determined, it is set to `\"unknown\"`. If the\n * version cannot be determined, it is set to `null`.\n *\n * @return {{name: string, version: string}}\n */\nf.library = function() {\n let library = this.proxy(\"options.library\");\n if (!library) return { name: \"unknown\", version: null };\n if (typeof library === \"string\") return { name: library, version: null };\n return library;\n};\n\n/**\n * Return the device information, falling back to an empty object.\n *\n * Interesting values of `type` are `\"ios\"` and `\"android\"`, but other values\n * are possible if the client is doing something unusual with `context.device`.\n *\n * @return {{type: string}}\n */\nf.device = function() {\n let device = this.proxy(\"context.device\");\n if (typeof device !== \"object\" || device === null) {\n device = {};\n }\n let library = this.library().name;\n if (device.type) return device;\n\n if (library.indexOf(\"ios\") > -1) device.type = \"ios\";\n if (library.indexOf(\"android\") > -1) device.type = \"android\";\n return device;\n};\n\n/**\n * Get the User-Agent from `context.userAgent`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return string\n */\nf.userAgent = Facade.proxy(\"context.userAgent\");\n\n/**\n * Get the timezone from `context.timezone`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return string\n */\nf.timezone = Facade.proxy(\"context.timezone\");\n\n/**\n * Get the timestamp from `context.timestamp`.\n *\n * @function\n * @return string\n */\nf.timestamp = Facade.field(\"timestamp\");\n\n/**\n * Get the channel from `channel`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return string\n */\nf.channel = Facade.field(\"channel\");\n\n/**\n * Get the IP address from `context.ip`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return string\n */\nf.ip = Facade.proxy(\"context.ip\");\n\n/**\n * Get the user ID from `userId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return string\n */\nf.userId = Facade.field(\"userId\");\n\n/**\n * Get the ZIP/Postal code from `traits`, `traits.address`, `properties`, or\n * `properties.address`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @name zip\n * @function\n * @memberof f\n * @return {string}\n */\n\n/**\n * Get the country from `traits`, `traits.address`, `properties`, or\n * `properties.address`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @name country\n * @function\n * @memberof f\n * @return {string}\n */\n\n/**\n * Get the street from `traits`, `traits.address`, `properties`, or\n * `properties.address`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @name street\n * @function\n * @memberof f\n * @return {string}\n */\n\n/**\n * Get the state from `traits`, `traits.address`, `properties`, or\n * `properties.address`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @name state\n * @function\n * @memberof f\n * @return {string}\n */\n\n/**\n * Get the city from `traits`, `traits.address`, `properties`, or\n * `properties.address`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @name city\n * @function\n * @memberof f\n * @return {string}\n */\n\n/**\n * Get the region from `traits`, `traits.address`, `properties`, or\n * `properties.address`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @name region\n * @function\n * @memberof f\n * @return {string}\n */\n\naddress(f);\n\n/**\n * Return the cloned and traversed object\n *\n * @ignore\n * @param {*} obj\n * @return {*}\n */\nfunction transform (obj) {\n return clone(obj);\n}\n", "if (typeof Object.create === 'function') {\n // implementation from standard node.js 'util' module\n module.exports = function inherits(ctor, superCtor) {\n if (superCtor) {\n ctor.super_ = superCtor\n ctor.prototype = Object.create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: false,\n writable: true,\n configurable: true\n }\n })\n }\n };\n} else {\n // old school shim for old browsers\n module.exports = function inherits(ctor, superCtor) {\n if (superCtor) {\n ctor.super_ = superCtor\n var TempCtor = function () {}\n TempCtor.prototype = superCtor.prototype\n ctor.prototype = new TempCtor()\n ctor.prototype.constructor = ctor\n }\n }\n}\n", "\"use strict\";\n\nimport inherit from \"inherits\";\nimport { Facade } from \"./facade\";\n\n/**\n * Initialize a new `Alias` facade with a `dictionary` of arguments.\n *\n * @param {Object} dictionary - The object to wrap.\n * @param {string} [dictionary.from] - The previous ID of the user.\n * @param {string} [dictionary.to] - The new ID of the user.\n * @param {Object} opts - Options about what kind of Facade to create.\n *\n * @augments Facade\n */\nexport function Alias(dictionary, opts) {\n Facade.call(this, dictionary, opts);\n}\n\ninherit(Alias, Facade);\n\n/**\n * Return the type of facade this is. This will always return `\"alias\"`.\n *\n * @return {string}\n */\nAlias.prototype.action = function () {\n return \"alias\";\n};\n\n/**\n * An alias for {@link Alias#action}.\n *\n * @function\n * @return {string}\n */\nAlias.prototype.type = Alias.prototype.action;\n\n/**\n * Get the user's previous ID from `previousId` or `from`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nAlias.prototype.previousId = function () {\n return this.field(\"previousId\") || this.field(\"from\");\n};\n\n/**\n * An alias for {@link Alias#previousId}.\n *\n * @function\n * @return {string}\n */\nAlias.prototype.from = Alias.prototype.previousId;\n\n/**\n * Get the user's new ID from `userId` or `to`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nAlias.prototype.userId = function () {\n return this.field(\"userId\") || this.field(\"to\");\n};\n\n/**\n * An alias for {@link Alias#userId}.\n *\n * @function\n * @return {string}\n */\nAlias.prototype.to = Alias.prototype.userId;\n", "const matcher = /.+\\@.+\\..+/;\n\nexport default function isEmail(string) {\n return matcher.test(string);\n}\n", "\"use strict\";\n\nimport inherit from \"inherits\";\nimport isEmail from \"./is-email\";\nimport newDate from \"new-date\";\nimport { Facade } from \"./facade\";\n\n/**\n * Initialize a new `Group` facade with a `dictionary` of arguments.\n *\n * @param {Object} dictionary - The object to wrap.\n * @param {string} [dictionary.userId] - The user to add to the group.\n * @param {string} [dictionary.groupId] - The ID of the group.\n * @param {Object} [dictionary.traits] - The traits of the group.\n * @param {Object} opts - Options about what kind of Facade to create.\n *\n * @augments Facade\n */\nexport function Group(dictionary, opts) {\n Facade.call(this, dictionary, opts);\n}\n\ninherit(Group, Facade);\n\nconst g = Group.prototype;\n\n/**\n * Return the type of facade this is. This will always return `\"group\"`.\n *\n * @return {string}\n */\ng.action = function () {\n return \"group\";\n};\n\n/**\n * An alias for {@link Group#action}.\n *\n * @function\n * @return {string}\n */\ng.type = g.action;\n\n/**\n * Get the group ID from `groupId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ng.groupId = Facade.field(\"groupId\");\n\n/**\n * Get the time of creation of the group from `traits.createdAt`,\n * `traits.created`, `properties.createdAt`, or `properties.created`.\n *\n * @return {Date}\n */\ng.created = function () {\n var created =\n this.proxy(\"traits.createdAt\") ||\n this.proxy(\"traits.created\") ||\n this.proxy(\"properties.createdAt\") ||\n this.proxy(\"properties.created\");\n\n if (created) return newDate(created);\n};\n\n/**\n * Get the group's email from `traits.email`, falling back to `groupId` only if\n * it looks like a valid email.\n *\n * @return {string}\n */\ng.email = function () {\n var email = this.proxy(\"traits.email\");\n if (email) return email;\n var groupId = this.groupId();\n if (isEmail(groupId)) return groupId;\n};\n\n/**\n * Get the group's traits. This is identical to how {@link Facade#traits}\n * works, except it looks at `traits.*` instead of `options.traits.*`.\n *\n * Traits are gotten from `traits`, augmented with a property `id` with\n * the event's `groupId`.\n *\n * The parameter `aliases` is meant to transform keys in `traits` into new\n * keys. Each alias like `{ \"xxx\": \"yyy\" }` will take whatever is at `xxx` in\n * the traits, and move it to `yyy`. If `xxx` is a method of this facade, it'll\n * be called as a function instead of treated as a key into the traits.\n *\n * @example\n * var obj = { traits: { foo: \"bar\" }, anonymousId: \"xxx\" }\n * var group = new Group(obj)\n *\n * group.traits() // { \"foo\": \"bar\" }\n * group.traits({ \"foo\": \"asdf\" }) // { \"asdf\": \"bar\" }\n * group.traits({ \"sessionId\": \"rofl\" }) // { \"rofl\": \"xxx\" }\n *\n * @param {Object} aliases - A mapping from keys to the new keys they should be\n * transformed to.\n * @return {Object}\n */\ng.traits = function (aliases) {\n var ret = this.properties();\n var id = this.groupId();\n aliases = aliases || {};\n\n if (id) ret.id = id;\n\n for (const alias in aliases) {\n if (Object.prototype.hasOwnProperty.call(aliases, alias)) {\n const value = this[alias] == null\n ? this.proxy(\"traits.\" + alias)\n : this[alias]();\n if (value == null) continue;\n ret[aliases[alias]] = value;\n delete ret[alias];\n }\n }\n\n return ret;\n};\n\n/**\n * Get the group's name from `traits.name`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\ng.name = Facade.proxy(\"traits.name\");\n\n/**\n * Get the group's industry from `traits.industry`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\ng.industry = Facade.proxy(\"traits.industry\");\n\n/**\n * Get the group's employee count from `traits.employees`.\n *\n * This *should* be a number, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {number}\n */\ng.employees = Facade.proxy(\"traits.employees\");\n\n/**\n * Get the group's properties from `traits` or `properties`, falling back to\n * simply an empty object.\n *\n * @return {Object}\n */\ng.properties = function () {\n // TODO remove this function\n return this.field(\"traits\") || this.field(\"properties\") || {};\n};\n", "\"use strict\";\n\nimport { Facade } from \"./facade\";\nimport get from \"obj-case\";\nimport inherit from \"inherits\";\nimport isEmail from \"./is-email\";\nimport newDate from \"new-date\";\n\nlet trim = (str) => str.trim();\n\n/**\n * Initialize a new `Identify` facade with a `dictionary` of arguments.\n *\n * @param {Object} dictionary - The object to wrap.\n * @param {string} [dictionary.userId] - The ID of the user.\n * @param {string} [dictionary.anonymousId] - The anonymous ID of the user.\n * @param {string} [dictionary.traits] - The user's traits.\n * @param {Object} opts - Options about what kind of Facade to create.\n *\n * @augments Facade\n */\nexport function Identify(dictionary, opts) {\n Facade.call(this, dictionary, opts);\n}\n\ninherit(Identify, Facade);\n\nconst i = Identify.prototype;\n\n/**\n * Return the type of facade this is. This will always return `\"identify\"`.\n *\n * @return {string}\n */\ni.action = function () {\n return \"identify\";\n};\n\n/**\n * An alias for {@link Identify#action}.\n *\n * @function\n * @return {string}\n */\ni.type = i.action;\n\n/**\n * Get the user's traits. This is identical to how {@link Facade#traits} works,\n * except it looks at `traits.*` instead of `options.traits.*`.\n *\n * Traits are gotten from `traits`, augmented with a property `id` with\n * the event's `userId`.\n *\n * The parameter `aliases` is meant to transform keys in `traits` into new\n * keys. Each alias like `{ \"xxx\": \"yyy\" }` will take whatever is at `xxx` in\n * the traits, and move it to `yyy`. If `xxx` is a method of this facade, it'll\n * be called as a function instead of treated as a key into the traits.\n *\n * @example\n * let obj = { traits: { foo: \"bar\" }, anonymousId: \"xxx\" }\n * let identify = new Identify(obj)\n *\n * identify.traits() // { \"foo\": \"bar\" }\n * identify.traits({ \"foo\": \"asdf\" }) // { \"asdf\": \"bar\" }\n * identify.traits({ \"sessionId\": \"rofl\" }) // { \"rofl\": \"xxx\" }\n *\n * @param {Object} aliases - A mapping from keys to the new keys they should be\n * transformed to.\n * @return {Object}\n */\ni.traits = function (aliases) {\n let ret = this.field(\"traits\") || {};\n let id = this.userId();\n aliases = aliases || {};\n\n if (id) ret.id = id;\n\n for (let alias in aliases) {\n let value =\n this[alias] == null ? this.proxy(\"traits.\" + alias) : this[alias]();\n if (value == null) continue;\n ret[aliases[alias]] = value;\n if (alias !== aliases[alias]) delete ret[alias];\n }\n\n return ret;\n};\n\n/**\n * Get the user's email from `traits.email`, falling back to `userId` only if\n * it looks like a valid email.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ni.email = function () {\n let email = this.proxy(\"traits.email\");\n if (email) return email;\n\n let userId = this.userId();\n if (isEmail(userId)) return userId;\n};\n\n/**\n * Get the time of creation of the user from `traits.created` or\n * `traits.createdAt`.\n *\n * @return {Date}\n */\ni.created = function () {\n let created = this.proxy(\"traits.created\") || this.proxy(\"traits.createdAt\");\n if (created) return newDate(created);\n};\n\n/**\n * Get the time of creation of the user's company from `traits.company.created`\n * or `traits.company.createdAt`.\n *\n * @return {Date}\n */\ni.companyCreated = function () {\n let created =\n this.proxy(\"traits.company.created\") ||\n this.proxy(\"traits.company.createdAt\");\n\n if (created) {\n return newDate(created);\n }\n};\n\n/**\n * Get the user's company name from `traits.company.name`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ni.companyName = function () {\n return this.proxy(\"traits.company.name\");\n};\n\n/**\n * Get the user's name `traits.name`, falling back to combining {@link\n * Identify#firstName} and {@link Identify#lastName} if possible.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ni.name = function () {\n let name = this.proxy(\"traits.name\");\n if (typeof name === \"string\") {\n return trim(name);\n }\n\n let firstName = this.firstName();\n let lastName = this.lastName();\n if (firstName && lastName) {\n return trim(firstName + \" \" + lastName);\n }\n};\n\n/**\n * Get the user's first name from `traits.firstName`, optionally splitting it\n * out of a the full name if that's all that was provided.\n *\n * Splitting the full name works on the assumption that the full name is of the\n * form \"FirstName LastName\"; it will not work for non-Western names.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ni.firstName = function () {\n let firstName = this.proxy(\"traits.firstName\");\n if (typeof firstName === \"string\") {\n return trim(firstName);\n }\n\n let name = this.proxy(\"traits.name\");\n if (typeof name === \"string\") {\n return trim(name).split(\" \")[0];\n }\n};\n\n/**\n * Get the user's last name from `traits.lastName`, optionally splitting it out\n * of a the full name if that's all that was provided.\n *\n * Splitting the full name works on the assumption that the full name is of the\n * form \"FirstName LastName\"; it will not work for non-Western names.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ni.lastName = function () {\n let lastName = this.proxy(\"traits.lastName\");\n if (typeof lastName === \"string\") {\n return trim(lastName);\n }\n\n let name = this.proxy(\"traits.name\");\n if (typeof name !== \"string\") {\n return;\n }\n\n let space = trim(name).indexOf(\" \");\n if (space === -1) {\n return;\n }\n\n return trim(name.substr(space + 1));\n};\n\n/**\n * Get the user's \"unique id\" from `userId`, `traits.username`, or\n * `traits.email`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ni.uid = function () {\n return this.userId() || this.username() || this.email();\n};\n\n/**\n * Get the user's description from `traits.description` or `traits.background`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ni.description = function () {\n return this.proxy(\"traits.description\") || this.proxy(\"traits.background\");\n};\n\n/**\n * Get the user's age from `traits.age`, falling back to computing it from\n * `traits.birthday` and the current time.\n *\n * @return {number}\n */\ni.age = function () {\n let date = this.birthday();\n let age = get(this.traits(), \"age\");\n if (age != null) return age;\n if (!(date instanceof Date)) return;\n let now = new Date();\n return now.getFullYear() - date.getFullYear();\n};\n\n/**\n * Get the URL of the user's avatar from `traits.avatar`, `traits.photoUrl`, or\n * `traits.avatarUrl`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ni.avatar = function () {\n let traits = this.traits();\n return (\n get(traits, \"avatar\") || get(traits, \"photoUrl\") || get(traits, \"avatarUrl\")\n );\n};\n\n/**\n * Get the user's job position from `traits.position` or `traits.jobTitle`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\ni.position = function () {\n let traits = this.traits();\n return get(traits, \"position\") || get(traits, \"jobTitle\");\n};\n\n/**\n * Get the user's username from `traits.username`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\ni.username = Facade.proxy(\"traits.username\");\n\n/**\n * Get the user's website from `traits.website`, or if there are multiple in\n * `traits.websites`, return the first one.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\ni.website = Facade.one(\"traits.website\");\n\n/**\n * Get the user's websites from `traits.websites`, or if there is only one in\n * `traits.website`, then wrap it in an array.\n *\n * This *should* be an array of strings, but may not be if the client isn't\n * adhering to the spec.\n *\n * @function\n * @return {array}\n */\ni.websites = Facade.multi(\"traits.website\");\n\n/**\n * Get the user's phone number from `traits.phone`, or if there are multiple in\n * `traits.phones`, return the first one.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\ni.phone = Facade.one(\"traits.phone\");\n\n/**\n * Get the user's phone numbers from `traits.phones`, or if there is only one\n * in `traits.phone`, then wrap it in an array.\n *\n * This *should* be an array of strings, but may not be if the client isn't\n * adhering to the spec.\n *\n * @function\n * @return {array}\n */\ni.phones = Facade.multi(\"traits.phone\");\n\n/**\n * Get the user's address from `traits.address`.\n *\n * This *should* be an object, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {object}\n */\ni.address = Facade.proxy(\"traits.address\");\n\n/**\n * Get the user's gender from `traits.gender`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\ni.gender = Facade.proxy(\"traits.gender\");\n\n/**\n * Get the user's birthday from `traits.birthday`.\n *\n * This *should* be a Date if `opts.traverse` was enabled (it is by default)\n * when letructing this Identify. Otherwise, it should be a string. But it\n * may be neither if the client isn't adhering to the spec.\n * spec.\n *\n * @function\n * @return {object}\n */\ni.birthday = Facade.proxy(\"traits.birthday\");\n", "\"use strict\";\n\nimport inherit from \"inherits\";\nimport { Facade } from \"./facade\";\nimport { Identify } from \"./identify\";\nimport isEmail from \"./is-email\";\nimport get from \"obj-case\";\n\n/**\n * Initialize a new `Track` facade with a `dictionary` of arguments.\n *\n * @param {Object} dictionary - The object to wrap.\n * @param {string} [dictionary.event] - The name of the event being tracked.\n * @param {string} [dictionary.userId] - The ID of the user being tracked.\n * @param {string} [dictionary.anonymousId] - The anonymous ID of the user.\n * @param {string} [dictionary.properties] - Properties of the track event.\n * @param {Object} opts - Options about what kind of Facade to create.\n *\n * @augments Facade\n */\nexport function Track(dictionary, opts) {\n Facade.call(this, dictionary, opts);\n}\n\ninherit(Track, Facade);\n\nlet t = Track.prototype;\n\n/**\n * Return the type of facade this is. This will always return `\"track\"`.\n *\n * @return {string}\n */\nt.action = function () {\n return \"track\";\n};\n\n/**\n * An alias for {@link Track#action}.\n *\n * @function\n * @return {string}\n */\nt.type = t.action;\n\n/**\n * Get the event name from `event`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\nt.event = Facade.field(\"event\");\n\n/**\n * Get the event value, usually the monetary value, from `properties.value`.\n *\n * This *should* be a number, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {number}\n */\nt.value = Facade.proxy(\"properties.value\");\n\n/**\n * Get the event cateogry from `properties.category`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\nt.category = Facade.proxy(\"properties.category\");\n\n/**\n * Get the event ID from `properties.id`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\nt.id = Facade.proxy(\"properties.id\");\n\n/**\n * Get the product ID from `properties.productId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.productId = function () {\n return (\n this.proxy(\"properties.product_id\") || this.proxy(\"properties.productId\")\n );\n};\n\n/**\n * Get the promotion ID from `properties.promotionId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.promotionId = function () {\n return (\n this.proxy(\"properties.promotion_id\") ||\n this.proxy(\"properties.promotionId\")\n );\n};\n\n/**\n * Get the cart ID from `properties.cartId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.cartId = function () {\n return this.proxy(\"properties.cart_id\") || this.proxy(\"properties.cartId\");\n};\n\n/**\n * Get the checkout ID from `properties.checkoutId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.checkoutId = function () {\n return (\n this.proxy(\"properties.checkout_id\") || this.proxy(\"properties.checkoutId\")\n );\n};\n\n/**\n * Get the payment ID from `properties.paymentId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.paymentId = function () {\n return (\n this.proxy(\"properties.payment_id\") || this.proxy(\"properties.paymentId\")\n );\n};\n\n/**\n * Get the coupon ID from `properties.couponId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.couponId = function () {\n return (\n this.proxy(\"properties.coupon_id\") || this.proxy(\"properties.couponId\")\n );\n};\n\n/**\n * Get the wishlist ID from `properties.wishlistId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.wishlistId = function () {\n return (\n this.proxy(\"properties.wishlist_id\") || this.proxy(\"properties.wishlistId\")\n );\n};\n\n/**\n * Get the review ID from `properties.reviewId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.reviewId = function () {\n return (\n this.proxy(\"properties.review_id\") || this.proxy(\"properties.reviewId\")\n );\n};\n\n/**\n * Get the order ID from `properties.id` or `properties.orderId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.orderId = function () {\n // doesn't follow above convention since this fallback order was how it used to be\n return (\n this.proxy(\"properties.id\") ||\n this.proxy(\"properties.order_id\") ||\n this.proxy(\"properties.orderId\")\n );\n};\n\n/**\n * Get the SKU from `properties.sku`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\nt.sku = Facade.proxy(\"properties.sku\");\n\n/**\n * Get the amount of tax for this purchase from `properties.tax`.\n *\n * This *should* be a number, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {number}\n */\nt.tax = Facade.proxy(\"properties.tax\");\n\n/**\n * Get the name of this event from `properties.name`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\nt.name = Facade.proxy(\"properties.name\");\n\n/**\n * Get the price of this purchase from `properties.price`.\n *\n * This *should* be a number, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {number}\n */\nt.price = Facade.proxy(\"properties.price\");\n\n/**\n * Get the total for this purchase from `properties.total`.\n *\n * This *should* be a number, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {number}\n */\nt.total = Facade.proxy(\"properties.total\");\n\n/**\n * Whether this is a repeat purchase from `properties.repeat`.\n *\n * This *should* be a boolean, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {boolean}\n */\nt.repeat = Facade.proxy(\"properties.repeat\");\n\n/**\n * Get the coupon for this purchase from `properties.coupon`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\nt.coupon = Facade.proxy(\"properties.coupon\");\n\n/**\n * Get the shipping for this purchase from `properties.shipping`.\n *\n * This *should* be a number, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {number}\n */\nt.shipping = Facade.proxy(\"properties.shipping\");\n\n/**\n * Get the discount for this purchase from `properties.discount`.\n *\n * This *should* be a number, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {number}\n */\nt.discount = Facade.proxy(\"properties.discount\");\n\n/**\n * Get the shipping method for this purchase from `properties.shippingMethod`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.shippingMethod = function () {\n return (\n this.proxy(\"properties.shipping_method\") ||\n this.proxy(\"properties.shippingMethod\")\n );\n};\n\n/**\n * Get the payment method for this purchase from `properties.paymentMethod`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.paymentMethod = function () {\n return (\n this.proxy(\"properties.payment_method\") ||\n this.proxy(\"properties.paymentMethod\")\n );\n};\n\n/**\n * Get a description for this event from `properties.description`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\nt.description = Facade.proxy(\"properties.description\");\n\n/**\n * Get a plan, as in the plan the user is on, for this event from\n * `properties.plan`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string}\n */\nt.plan = Facade.proxy(\"properties.plan\");\n\n/**\n * Get the subtotal for this purchase from `properties.subtotal`.\n *\n * If `properties.subtotal` isn't available, then fall back to computing the\n * total from `properties.total` or `properties.revenue`, and then subtracting\n * tax, shipping, and discounts.\n *\n * If neither subtotal, total, nor revenue are available, then return 0.\n *\n * @return {number}\n */\nt.subtotal = function () {\n let subtotal = get(this.properties(), \"subtotal\");\n let total = this.total() || this.revenue();\n\n if (subtotal) return subtotal;\n if (!total) return 0;\n\n if (this.total()) {\n let n = this.tax();\n if (n) total -= n;\n n = this.shipping();\n if (n) total -= n;\n n = this.discount();\n if (n) total += n;\n }\n\n return total;\n};\n\n/**\n * Get the products for this event from `properties.products` if it's an\n * array, falling back to an empty array.\n *\n * @return {Array}\n */\nt.products = function () {\n let props = this.properties();\n let products = get(props, \"products\");\n if (Array.isArray(products)) {\n return products.filter(item => item !== null)\n }\n return [];\n};\n\n/**\n * Get the quantity for this event from `properties.quantity`, falling back to\n * a quantity of one.\n *\n * @return {number}\n */\nt.quantity = function () {\n let props = this.obj.properties || {};\n return props.quantity || 1;\n};\n\n/**\n * Get the currency for this event from `properties.currency`, falling back to\n * \"USD\".\n *\n * @return {string}\n */\nt.currency = function () {\n let props = this.obj.properties || {};\n return props.currency || \"USD\";\n};\n\n/**\n * Get the referrer for this event from `context.referrer.url`,\n * `context.page.referrer`, or `properties.referrer`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\nt.referrer = function () {\n // TODO re-examine whether this function is necessary\n return (\n this.proxy(\"context.referrer.url\") ||\n this.proxy(\"context.page.referrer\") ||\n this.proxy(\"properties.referrer\")\n );\n};\n\n/**\n * Get the query for this event from `options.query`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @function\n * @return {string|object}\n */\nt.query = Facade.proxy(\"options.query\");\n\n/**\n * Get the page's properties. This is identical to how {@link Facade#traits}\n * works, except it looks at `properties.*` instead of `options.traits.*`.\n *\n * Properties are gotten from `properties`.\n *\n * The parameter `aliases` is meant to transform keys in `properties` into new\n * keys. Each alias like `{ \"xxx\": \"yyy\" }` will take whatever is at `xxx` in\n * the traits, and move it to `yyy`. If `xxx` is a method of this facade, it'll\n * be called as a function instead of treated as a key into the traits.\n *\n * @example\n * let obj = { properties: { foo: \"bar\" }, anonymousId: \"xxx\" }\n * let track = new Track(obj)\n *\n * track.traits() // { \"foo\": \"bar\" }\n * track.traits({ \"foo\": \"asdf\" }) // { \"asdf\": \"bar\" }\n * track.traits({ \"sessionId\": \"rofl\" }) // { \"rofl\": \"xxx\" }\n *\n * @param {Object} aliases - A mapping from keys to the new keys they should be\n * transformed to.\n * @return {Object}\n */\nt.properties = function (aliases) {\n let ret = this.field(\"properties\") || {};\n aliases = aliases || {};\n\n for (const alias in aliases) {\n if (Object.prototype.hasOwnProperty.call(aliases, alias)) {\n const value = this[alias] == null\n ? this.proxy(\"properties.\" + alias)\n : this[alias]();\n if (value == null) continue;\n ret[aliases[alias]] = value;\n delete ret[alias];\n }\n }\n\n return ret;\n};\n\n/**\n * Get the username of the user for this event from `traits.username`,\n * `properties.username`, `userId`, or `anonymousId`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string|undefined}\n */\nt.username = function () {\n return (\n this.proxy(\"traits.username\") ||\n this.proxy(\"properties.username\") ||\n this.userId() ||\n this.sessionId()\n );\n};\n\n/**\n * Get the email of the user for this event from `trais.email`,\n * `properties.email`, or `options.traits.email`, falling back to `userId` if\n * it looks like a valid email.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string|undefined}\n */\nt.email = function () {\n let email =\n this.proxy(\"traits.email\") ||\n this.proxy(\"properties.email\") ||\n this.proxy(\"options.traits.email\");\n if (email) return email;\n\n let userId = this.userId();\n if (isEmail(userId)) return userId;\n};\n\n/**\n * Get the revenue for this event.\n *\n * If this is an \"Order Completed\" event, this will be the `properties.total`\n * falling back to the `properties.revenue`. For all other events, this is\n * simply taken from `properties.revenue`.\n *\n * If there are dollar signs in these properties, they will be removed. The\n * result will be parsed into a number.\n *\n * @return {number}\n */\nt.revenue = function () {\n let revenue = this.proxy(\"properties.revenue\");\n let event = this.event();\n let orderCompletedRegExp = /^[ _]?completed[ _]?order[ _]?|^[ _]?order[ _]?completed[ _]?$/i;\n\n // it's always revenue, unless it's called during an order completion.\n if (!revenue && event && event.match(orderCompletedRegExp)) {\n revenue = this.proxy(\"properties.total\");\n }\n\n return currency(revenue);\n};\n\n/**\n * Get the revenue for this event in \"cents\" -- in other words, multiply the\n * {@link Track#revenue} by 100, or return 0 if there isn't a numerical revenue\n * for this event.\n *\n * @return {number}\n */\nt.cents = function () {\n let revenue = this.revenue();\n return typeof revenue !== \"number\" ? this.value() || 0 : revenue * 100;\n};\n\n/**\n * Convert this event into an {@link Identify} facade.\n *\n * This works by taking this event's underlying object and creating an Identify\n * from it. This event's traits, taken from `options.traits`, will be used as\n * the Identify's traits.\n *\n * @return {Identify}\n */\nt.identify = function () {\n // TODO: remove me.\n let json = this.json();\n json.traits = this.traits();\n return new Identify(json, this.opts);\n};\n\n/**\n * Get float from currency value.\n *\n * @ignore\n * @param {*} val\n * @return {number}\n */\nfunction currency(val) {\n if (!val) return;\n if (typeof val === \"number\") {\n return val;\n }\n if (typeof val !== \"string\") {\n return;\n }\n\n val = val.replace(/\\$/g, \"\");\n val = parseFloat(val);\n\n if (!isNaN(val)) {\n return val;\n }\n}\n", "\"use strict\";\n\nimport inherit from \"inherits\";\nimport { Facade } from \"./facade\";\nimport { Track } from \"./track\";\nimport isEmail from \"./is-email\";\n\n/**\n * Initialize a new `Page` facade with a `dictionary` of arguments.\n *\n * @param {Object} dictionary - The object to wrap.\n * @param {string} [dictionary.category] - The page category.\n * @param {string} [dictionary.name] - The page name.\n * @param {string} [dictionary.properties] - The page properties.\n * @param {Object} opts - Options about what kind of Facade to create.\n *\n * @augments Facade\n */\nexport function Page(dictionary, opts) {\n Facade.call(this, dictionary, opts);\n}\n\ninherit(Page, Facade);\n\nconst p = Page.prototype;\n\n/**\n * Return the type of facade this is. This will always return `\"page\"`.\n *\n * @return {string}\n */\np.action = function () {\n return \"page\";\n};\n\n/**\n * An alias for {@link Page#action}.\n *\n * @function\n * @return {string}\n */\np.type = p.action;\n\n/**\n * Get the page category from `category`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\np.category = Facade.field(\"category\");\n\n/**\n * Get the page name from `name`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\np.name = Facade.field(\"name\");\n\n/**\n * Get the page title from `properties.title`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\np.title = Facade.proxy(\"properties.title\");\n\n/**\n * Get the page path from `properties.path`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\np.path = Facade.proxy(\"properties.path\");\n\n/**\n * Get the page URL from `properties.url`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\np.url = Facade.proxy(\"properties.url\");\n\n/**\n * Get the HTTP referrer from `context.referrer.url`, `context.page.referrer`,\n * or `properties.referrer`.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\np.referrer = function () {\n return (\n this.proxy(\"context.referrer.url\") ||\n this.proxy(\"context.page.referrer\") ||\n this.proxy(\"properties.referrer\")\n );\n};\n\n/**\n * Get the page's properties. This is identical to how {@link Facade#traits}\n * works, except it looks at `properties.*` instead of `options.traits.*`.\n *\n * Properties are gotten from `properties`, augmented with the page's `name`\n * and `category`.\n *\n * The parameter `aliases` is meant to transform keys in `properties` into new\n * keys. Each alias like `{ \"xxx\": \"yyy\" }` will take whatever is at `xxx` in\n * the traits, and move it to `yyy`. If `xxx` is a method of this facade, it'll\n * be called as a function instead of treated as a key into the traits.\n *\n * @example\n * let obj = { properties: { foo: \"bar\" }, anonymousId: \"xxx\" }\n * let page = new Page(obj)\n *\n * page.traits() // { \"foo\": \"bar\" }\n * page.traits({ \"foo\": \"asdf\" }) // { \"asdf\": \"bar\" }\n * page.traits({ \"sessionId\": \"rofl\" }) // { \"rofl\": \"xxx\" }\n *\n * @param {Object} aliases - A mapping from keys to the new keys they should be\n * transformed to.\n * @return {Object}\n */\np.properties = function (aliases) {\n let props = this.field(\"properties\") || {};\n let category = this.category();\n let name = this.name();\n aliases = aliases || {};\n\n if (category) props.category = category;\n if (name) props.name = name;\n\n for (const alias in aliases) {\n if (Object.prototype.hasOwnProperty.call(aliases, alias)) {\n const value = this[alias] == null\n ? this.proxy(\"properties.\" + alias)\n : this[alias]();\n if (value == null) continue;\n props[aliases[alias]] = value;\n if (alias !== aliases[alias]) delete props[alias];\n }\n }\n\n return props;\n};\n\n/**\n * Get the user's email from `context.traits.email` or `properties.email`,\n * falling back to `userId` if it's a valid email.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\np.email = function () {\n let email =\n this.proxy(\"context.traits.email\") || this.proxy(\"properties.email\");\n if (email) return email;\n\n let userId = this.userId();\n if (isEmail(userId)) return userId;\n};\n\n/**\n * Get the page fullName. This is `$category $name` if both are present, and\n * just `name` otherwiser.\n *\n * This *should* be a string, but may not be if the client isn't adhering to\n * the spec.\n *\n * @return {string}\n */\np.fullName = function () {\n let category = this.category();\n let name = this.name();\n return name && category ? category + \" \" + name : name;\n};\n\n/**\n * Get an event name from this page call. If `name` is present, this will be\n * `Viewed $name Page`; otherwise, it will be `Loaded a Page`.\n *\n * @param {string} name - The name of this page.\n * @return {string}\n */\np.event = function (name) {\n return name ? \"Viewed \" + name + \" Page\" : \"Loaded a Page\";\n};\n\n/**\n * Convert this Page to a {@link Track} facade. The inputted `name` will be\n * converted to the Track's event name via {@link Page#event}.\n *\n * @param {string} name\n * @return {Track}\n */\np.track = function (name) {\n let json = this.json();\n json.event = this.event(name);\n json.timestamp = this.timestamp();\n json.properties = this.properties();\n return new Track(json, this.opts);\n};\n", "\"use strict\";\n\nimport inherit from \"inherits\";\nimport { Page } from \"./page\";\nimport { Track } from \"./track\";\n\n/**\n * Initialize a new `Screen` facade with a `dictionary` of arguments.\n *\n * Note that this class extends {@link Page}, so its methods are available to\n * instances of this class as well.\n *\n * @param {Object} dictionary - The object to wrap.\n * @param {string} [dictionary.category] - The page category.\n * @param {string} [dictionary.name] - The page name.\n * @param {string} [dictionary.properties] - The page properties.\n * @param {Object} opts - Options about what kind of Facade to create.\n *\n * @augments Page\n */\nexport function Screen(dictionary, opts) {\n Page.call(this, dictionary, opts);\n}\n\ninherit(Screen, Page);\n\n/**\n * Return the type of facade this is. This will always return `\"screen\"`.\n *\n * @return {string}\n */\nScreen.prototype.action = function () {\n return \"screen\";\n};\n\n/**\n * An alias for {@link Screen#action}.\n *\n * @function\n * @return {string}\n */\nScreen.prototype.type = Screen.prototype.action;\n\n/**\n * Get an event name from this screen call. If `name` is present, this will be\n * `Viewed $name Screen`; otherwise, it will be `Loaded a Screen`.\n *\n * @param {string} name - The name of this screen.\n * @return {string}\n */\nScreen.prototype.event = function (name) {\n return name ? \"Viewed \" + name + \" Screen\" : \"Loaded a Screen\";\n};\n\n/**\n * Convert this Screen to a {@link Track} facade. The inputted `name` will be\n * converted to the Track's event name via {@link Screen#event}.\n *\n * @param {string} name\n * @return {Track}\n */\nScreen.prototype.track = function (name) {\n let json = this.json();\n json.event = this.event(name);\n json.timestamp = this.timestamp();\n json.properties = this.properties();\n return new Track(json, this.opts);\n};\n", "\"use strict\";\n\nimport inherit from \"inherits\";\nimport { Facade } from \"./facade\";\n\n/**\n * Initialize a new `Delete` facade with a `dictionary` of arguments.\n *\n * @param {Object} dictionary - The object to wrap.\n * @param {string} [dictionary.category] - The delete category.\n * @param {string} [dictionary.name] - The delete name.\n * @param {string} [dictionary.properties] - The delete properties.\n * @param {Object} opts - Options about what kind of Facade to create.\n *\n * @augments Facade\n */\nexport function Delete(dictionary, opts) {\n Facade.call(this, dictionary, opts);\n}\n\ninherit(Delete, Facade);\n\n/**\n * Return the type of facade this is. This will always return `\"delete\"`.\n *\n * @return {string}\n */\nDelete.prototype.type = function () {\n return \"delete\";\n};\n", "\"use strict\";\n\nimport { Facade } from \"./facade\";\nimport { Alias } from \"./alias\";\nimport { Group } from \"./group\";\nimport { Identify } from \"./identify\";\nimport { Track } from \"./track\";\nimport { Page } from \"./page\";\nimport { Screen } from \"./screen\";\nimport { Delete } from \"./delete\";\n\nexport default {\n ...Facade,\n Alias,\n Group,\n Identify,\n Track,\n Page,\n Screen,\n Delete,\n};\n\nexport { Facade, Alias, Group, Identify, Track, Page, Screen, Delete };\n", "import {\n Alias,\n Facade,\n Group,\n Identify,\n Options,\n Page,\n Screen,\n Track,\n} from '@segment/facade'\nimport { SegmentEvent } from '../core/events'\n\nexport type SegmentFacade = Facade & {\n obj: SegmentEvent\n}\n\nexport function toFacade(evt: SegmentEvent, options?: Options): SegmentFacade {\n let fcd = new Facade(evt, options)\n\n if (evt.type === 'track') {\n fcd = new Track(evt, options)\n }\n\n if (evt.type === 'identify') {\n fcd = new Identify(evt, options)\n }\n\n if (evt.type === 'page') {\n fcd = new Page(evt, options)\n }\n\n if (evt.type === 'alias') {\n fcd = new Alias(evt, options)\n }\n\n if (evt.type === 'group') {\n fcd = new Group(evt, options)\n }\n\n if (evt.type === 'screen') {\n fcd = new Screen(evt, options)\n }\n\n Object.defineProperty(fcd, 'obj', {\n value: evt,\n writable: true,\n })\n\n return fcd as SegmentFacade\n}\n", "import { Context, ContextCancelation } from '../../core/context'\nimport { SegmentEvent } from '../../core/events'\nimport { Plugin } from '../../core/plugin'\nimport { SegmentFacade, toFacade } from '../../lib/to-facade'\n\nexport interface MiddlewareParams {\n payload: SegmentFacade\n\n integrations?: SegmentEvent['integrations']\n next: (payload: MiddlewareParams['payload'] | null) => void\n}\n\nexport interface DestinationMiddlewareParams {\n payload: SegmentFacade\n integration: string\n next: (payload: MiddlewareParams['payload'] | null) => void\n}\n\nexport type MiddlewareFunction = (\n middleware: MiddlewareParams\n) => void | Promise\n\nexport type DestinationMiddlewareFunction = (\n middleware: DestinationMiddlewareParams\n) => void | Promise\n\nexport async function applyDestinationMiddleware(\n destination: string,\n evt: SegmentEvent,\n middleware: DestinationMiddlewareFunction[]\n): Promise {\n // Clone the event so mutations are localized to a single destination.\n let modifiedEvent = toFacade(evt, {\n clone: true,\n traverse: false,\n }).rawEvent() as SegmentEvent\n async function applyMiddleware(\n event: SegmentEvent,\n fn: DestinationMiddlewareFunction\n ): Promise {\n let nextCalled = false\n let returnedEvent: SegmentEvent | null = null\n\n await fn({\n payload: toFacade(event, {\n clone: true,\n traverse: false,\n }),\n integration: destination,\n next(evt) {\n nextCalled = true\n\n if (evt === null) {\n returnedEvent = null\n }\n\n if (evt) {\n returnedEvent = evt.obj\n }\n },\n })\n\n if (!nextCalled && returnedEvent !== null) {\n returnedEvent = returnedEvent as SegmentEvent\n returnedEvent.integrations = {\n ...event.integrations,\n [destination]: false,\n }\n }\n\n return returnedEvent\n }\n\n for (const md of middleware) {\n const result = await applyMiddleware(modifiedEvent, md)\n if (result === null) {\n return null\n }\n modifiedEvent = result\n }\n\n return modifiedEvent\n}\n\nexport function sourceMiddlewarePlugin(\n fn: MiddlewareFunction,\n integrations: SegmentEvent['integrations']\n): Plugin {\n async function apply(ctx: Context): Promise {\n let nextCalled = false\n\n await fn({\n payload: toFacade(ctx.event, {\n clone: true,\n traverse: false,\n }),\n integrations: integrations ?? {},\n next(evt) {\n nextCalled = true\n if (evt) {\n ctx.event = evt.obj\n }\n },\n })\n\n if (!nextCalled) {\n throw new ContextCancelation({\n retry: false,\n type: 'middleware_cancellation',\n reason: 'Middleware `next` function skipped',\n })\n }\n\n return ctx\n }\n\n return {\n name: `Source Middleware ${fn.name}`,\n type: 'before',\n version: '0.1.0',\n\n isLoaded: (): boolean => true,\n load: (ctx): Promise => Promise.resolve(ctx),\n\n track: apply,\n page: apply,\n identify: apply,\n alias: apply,\n group: apply,\n }\n}\n", "import { QueryStringParams } from '.'\n\n/**\n * Returns an object containing only the properties prefixed by the input\n * string.\n * Ex: prefix('ajs_traits_', { ajs_traits_address: '123 St' })\n * will return { address: '123 St' }\n **/\nexport function pickPrefix(\n prefix: string,\n object: QueryStringParams\n): QueryStringParams {\n return Object.keys(object).reduce((acc: QueryStringParams, key: string) => {\n if (key.startsWith(prefix)) {\n const field = key.substr(prefix.length)\n acc[field] = object[key]!\n }\n return acc\n }, {})\n}\n", "/**\n * Tries to gets the unencoded version of an encoded component of a\n * Uniform Resource Identifier (URI). If input string is malformed,\n * returns it back as-is.\n *\n * Note: All occurences of the `+` character become ` ` (spaces).\n **/\nexport function gracefulDecodeURIComponent(\n encodedURIComponent: string\n): string {\n try {\n return decodeURIComponent(encodedURIComponent.replace(/\\+/g, ' '))\n } catch {\n return encodedURIComponent\n }\n}\n", "import { pickPrefix } from './pickPrefix'\nimport { gracefulDecodeURIComponent } from './gracefulDecodeURIComponent'\nimport { Analytics } from '../analytics'\nimport { Context } from '../context'\nimport { isPlainObject } from '@segment/analytics-core'\n\nexport interface QueryStringParams {\n [key: string]: string | null\n}\n\nexport function queryString(\n analytics: Analytics,\n query: string\n): Promise {\n const a = document.createElement('a')\n a.href = query\n const parsed = a.search.slice(1)\n const params = parsed.split('&').reduce((acc: QueryStringParams, str) => {\n const [k, v] = str.split('=')\n acc[k] = gracefulDecodeURIComponent(v)\n return acc\n }, {})\n\n const calls = []\n\n const { ajs_uid, ajs_event, ajs_aid } = params\n const { aid: aidPattern = /.+/, uid: uidPattern = /.+/ } = isPlainObject(\n analytics.options.useQueryString\n )\n ? analytics.options.useQueryString\n : {}\n\n if (ajs_aid) {\n const anonId = Array.isArray(params.ajs_aid)\n ? params.ajs_aid[0]\n : params.ajs_aid\n\n if (aidPattern.test(anonId)) {\n analytics.setAnonymousId(anonId)\n }\n }\n\n if (ajs_uid) {\n const uid = Array.isArray(params.ajs_uid)\n ? params.ajs_uid[0]\n : params.ajs_uid\n\n if (uidPattern.test(uid)) {\n const traits = pickPrefix('ajs_trait_', params)\n\n calls.push(analytics.identify(uid, traits))\n }\n }\n\n if (ajs_event) {\n const event = Array.isArray(params.ajs_event)\n ? params.ajs_event[0]\n : params.ajs_event\n const props = pickPrefix('ajs_prop_', params)\n calls.push(analytics.track(event, props))\n }\n\n return Promise.all(calls)\n}\n", "import { getGlobalAnalytics } from './global-analytics-helper'\nimport { embeddedWriteKey } from './embedded-write-key'\n\nconst analyticsScriptRegex =\n /(https:\\/\\/.*)\\/analytics\\.js\\/v1\\/(?:.*?)\\/(?:platform|analytics.*)?/\nconst getCDNUrlFromScriptTag = (): string | undefined => {\n let cdn: string | undefined\n const scripts = Array.prototype.slice.call(\n document.querySelectorAll('script')\n )\n scripts.forEach((s) => {\n const src = s.getAttribute('src') ?? ''\n const result = analyticsScriptRegex.exec(src)\n\n if (result && result[1]) {\n cdn = result[1]\n }\n })\n return cdn\n}\n\nlet _globalCDN: string | undefined // set globalCDN as in-memory singleton\nconst getGlobalCDNUrl = (): string | undefined => {\n const result = _globalCDN ?? getGlobalAnalytics()?._cdn\n return result\n}\n\nexport const setGlobalCDNUrl = (cdn: string) => {\n const globalAnalytics = getGlobalAnalytics()\n if (globalAnalytics) {\n globalAnalytics._cdn = cdn\n }\n _globalCDN = cdn\n}\n\nexport const getCDN = (): string => {\n const globalCdnUrl = getGlobalCDNUrl()\n\n if (globalCdnUrl) return globalCdnUrl\n\n const cdnFromScriptTag = getCDNUrlFromScriptTag()\n\n if (cdnFromScriptTag) {\n return cdnFromScriptTag\n } else {\n // it's possible that the CDN is not found in the page because:\n // - the script is loaded through a proxy\n // - the script is removed after execution\n // in this case, we fall back to the default Segment CDN\n return `https://cdn.segment.com`\n }\n}\n\nexport const getNextIntegrationsURL = () => {\n const cdn = getCDN()\n return `${cdn}/next-integrations`\n}\n\n/**\n * Replaces the CDN URL in the script tag with the one from Analytics.js 1.0\n *\n * @returns the path to Analytics JS 1.0\n **/\nexport function getLegacyAJSPath(): string {\n const writeKey = embeddedWriteKey() ?? getGlobalAnalytics()?._writeKey\n\n const scripts = Array.prototype.slice.call(\n document.querySelectorAll('script')\n )\n let path: string | undefined = undefined\n\n for (const s of scripts) {\n const src = s.getAttribute('src') ?? ''\n const result = analyticsScriptRegex.exec(src)\n\n if (result && result[1]) {\n path = src\n break\n }\n }\n\n if (path) {\n return path.replace('analytics.min.js', 'analytics.classic.js')\n }\n\n return `https://cdn.segment.com/analytics.js/v1/${writeKey}/analytics.classic.js`\n}\n", "import { JSONObject, Options } from '../core/events/interfaces'\nimport { CDNSettings } from '../browser'\n\n/**\n * Merge legacy settings and initialized Integration option overrides.\n *\n * This will merge any options that were passed from initialization into\n * overrides for settings that are returned by the Segment CDN.\n *\n * i.e. this allows for passing options directly into destinations from\n * the Analytics constructor.\n */\nexport function mergedOptions(\n cdnSettings: CDNSettings,\n options: Options\n): Record {\n const optionOverrides = Object.entries(options.integrations ?? {}).reduce(\n (overrides, [integration, options]) => {\n if (typeof options === 'object') {\n return {\n ...overrides,\n [integration]: options,\n }\n }\n\n return {\n ...overrides,\n [integration]: {},\n }\n },\n {} as Record\n )\n\n return Object.entries(cdnSettings.integrations).reduce(\n (integrationSettings, [integration, settings]) => {\n return {\n ...integrationSettings,\n [integration]: {\n ...settings,\n ...optionOverrides[integration],\n },\n }\n },\n {} as Record\n )\n}\n", "function findScript(src: string): HTMLScriptElement | undefined {\n const scripts = Array.prototype.slice.call(\n window.document.querySelectorAll('script')\n )\n return scripts.find((s) => s.src === src)\n}\n\nexport function loadScript(\n src: string,\n attributes?: Record\n): Promise {\n const found = findScript(src)\n\n if (found !== undefined) {\n const status = found?.getAttribute('status')\n\n if (status === 'loaded') {\n return Promise.resolve(found)\n }\n\n if (status === 'loading') {\n return new Promise((resolve, reject) => {\n found.addEventListener('load', () => resolve(found))\n found.addEventListener('error', (err) => reject(err))\n })\n }\n }\n\n return new Promise((resolve, reject) => {\n const script = window.document.createElement('script')\n\n script.type = 'text/javascript'\n script.src = src\n script.async = true\n\n script.setAttribute('status', 'loading')\n for (const [k, v] of Object.entries(attributes ?? {})) {\n script.setAttribute(k, v)\n }\n\n script.onload = (): void => {\n script.onerror = script.onload = null\n script.setAttribute('status', 'loaded')\n resolve(script)\n }\n\n script.onerror = (): void => {\n script.onerror = script.onload = null\n script.setAttribute('status', 'error')\n reject(new Error(`Failed to load ${src}`))\n }\n\n const tag = window.document.getElementsByTagName('script')[0]\n tag.parentElement?.insertBefore(script, tag)\n })\n}\n\nexport function unloadScript(src: string): Promise {\n const found = findScript(src)\n\n if (found !== undefined) {\n found.remove()\n }\n\n return Promise.resolve()\n}\n", "import { Context } from '../context'\n\nexport interface RecordIntegrationMetricProps {\n integrationName: string\n methodName: string\n didError?: boolean\n type: 'classic' | 'action'\n}\n\nexport function recordIntegrationMetric(\n ctx: Context,\n {\n methodName,\n integrationName,\n type,\n didError = false,\n }: RecordIntegrationMetricProps\n): void {\n ctx.stats.increment(\n `analytics_js.integration.invoke${didError ? '.error' : ''}`,\n 1,\n [\n `method:${methodName}`,\n `integration_name:${integrationName}`,\n `type:${type}`,\n ]\n )\n}\n", "export const pWhile = async (\n condition: (value: T | undefined) => boolean,\n action: () => T | PromiseLike\n): Promise => {\n const loop = async (actionResult: T | undefined): Promise => {\n if (condition(actionResult)) {\n return loop(await action())\n }\n }\n\n return loop(undefined)\n}\n", "// @ts-nocheck\n// prettier-ignore\n/* eslint-disable */\n// @segment/tsub 2.0.0 - GENERATED DO NOT MODIFY\n\n/*! For license information please see tsub.js.LICENSE.txt */\n!function(t,r){if(\"object\"==typeof exports&&\"object\"==typeof module)module.exports=r();else if(\"function\"==typeof define&&define.amd)define([],r);else{var e=r();for(var n in e)(\"object\"==typeof exports?exports:t)[n]=e[n]}}(self,(()=>(()=>{var t={2870:function(t,r,e){\"use strict\";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(r,\"__esModule\",{value:!0}),r.Store=r.matches=r.transform=void 0;var o=e(4303);Object.defineProperty(r,\"transform\",{enumerable:!0,get:function(){return n(o).default}});var s=e(2370);Object.defineProperty(r,\"matches\",{enumerable:!0,get:function(){return n(s).default}});var i=e(1444);Object.defineProperty(r,\"Store\",{enumerable:!0,get:function(){return n(i).default}})},2370:function(t,r,e){\"use strict\";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(r,\"__esModule\",{value:!0});var o=n(e(7843));function s(t,r){if(!Array.isArray(t))return!0===i(t,r);var e,n,o,f,p=t[0];switch(p){case\"!\":return!s(t[1],r);case\"or\":for(var l=1;l\":case\">=\":return function(t,r,e,n){if(u(t)&&(t=s(t,n)),u(r)&&(r=s(r,n)),\"number\"!=typeof t||\"number\"!=typeof r)return!1;switch(e){case\"<=\":return t<=r;case\">=\":return t>=r;case\"<\":return t\":return t>r;default:throw new Error(\"Invalid operator in compareNumbers: \".concat(e))}}(i(t[1],r),i(t[2],r),p,r);case\"in\":return function(t,r,e){return void 0!==r.find((function(r){return i(r,e)===t}))}(i(t[1],r),i(t[2],r),r);case\"contains\":return o=i(t[1],r),f=i(t[2],r),\"string\"==typeof o&&\"string\"==typeof f&&-1!==o.indexOf(f);case\"match\":return e=i(t[1],r),n=i(t[2],r),\"string\"==typeof e&&\"string\"==typeof n&&function(t,r){var e,n;t:for(;t.length>0;){var o,s;if(o=(e=a(t)).star,s=e.chunk,t=e.pattern,o&&\"\"===s)return!0;var i=c(s,r),u=i.t,f=i.ok,p=i.err;if(p)return!1;if(!f||!(0===u.length||t.length>0)){if(o)for(var l=0;l0)continue;r=u;continue t}if(p)return!1}return!1}r=u}return 0===r.length}(n,e);case\"lowercase\":var v=i(t[1],r);return\"string\"!=typeof v?null:v.toLowerCase();case\"typeof\":return typeof i(t[1],r);case\"length\":return function(t){return null===t?0:Array.isArray(t)||\"string\"==typeof t?t.length:NaN}(i(t[1],r));default:throw new Error(\"FQL IR could not evaluate for token: \".concat(p))}}function i(t,r){return Array.isArray(t)?t:\"object\"==typeof t?t.value:(0,o.default)(r,t)}function u(t){return!!Array.isArray(t)&&((\"lowercase\"===t[0]||\"length\"===t[0]||\"typeof\"===t[0])&&2===t.length||(\"contains\"===t[0]||\"match\"===t[0])&&3===t.length)}function a(t){for(var r={star:!1,chunk:\"\",pattern:\"\"};t.length>0&&\"*\"===t[0];)t=t.slice(1),r.star=!0;var e,n=!1;t:for(e=0;e0;){if(0===r.length)return o;switch(t[0]){case\"[\":var s=r[0];r=r.slice(1);var i=!0;(t=t.slice(1)).length>0&&\"^\"===t[0]&&(i=!1,t=t.slice(1));for(var u=!1,a=0;;){if(t.length>0&&\"]\"===t[0]&&a>0){t=t.slice(1);break}var c,p=\"\";if(c=(e=f(t)).char,t=e.newChunk,e.err)return o;if(p=c,\"-\"===t[0]&&(p=(n=f(t.slice(1))).char,t=n.newChunk,n.err))return o;c<=s&&s<=p&&(u=!0),a++}if(u!==i)return o;break;case\"?\":r=r.slice(1),t=t.slice(1);break;case\"\\\\\":if(0===(t=t.slice(1)).length)return o.err=!0,o;default:if(t[0]!==r[0])return o;r=r.slice(1),t=t.slice(1)}}return o.t=r,o.ok=!0,o.err=!1,o}function f(t){var r={char:\"\",newChunk:\"\",err:!1};return 0===t.length||\"-\"===t[0]||\"]\"===t[0]||\"\\\\\"===t[0]&&0===(t=t.slice(1)).length?(r.err=!0,r):(r.char=t[0],r.newChunk=t.slice(1),0===r.newChunk.length&&(r.err=!0),r)}r.default=function(t,r){if(!r)throw new Error(\"No matcher supplied!\");switch(r.type){case\"all\":return!0;case\"fql\":return function(t,r){if(!t)return!1;try{t=JSON.parse(t)}catch(r){throw new Error('Failed to JSON.parse FQL intermediate representation \"'.concat(t,'\": ').concat(r))}var e=s(t,r);return\"boolean\"==typeof e&&e}(r.ir,t);default:throw new Error(\"Matcher of type \".concat(r.type,\" unsupported.\"))}}},1444:(t,r)=>{\"use strict\";Object.defineProperty(r,\"__esModule\",{value:!0});var e=function(){function t(t){this.rules=[],this.rules=t||[]}return t.prototype.getRulesByDestinationName=function(t){for(var r=[],e=0,n=this.rules;e1?(i.pop(),c=(0,s.default)(e,i.join(\".\"))):c=t,\"object\"==typeof c){if(o.copy){var f=(0,s.default)(e,o.copy);void 0!==f&&(0,u.dset)(t,n,f)}else if(o.move){var p=(0,s.default)(e,o.move);void 0!==p&&(0,u.dset)(t,n,p),(0,a.unset)(t,o.move)}else o.hasOwnProperty(\"set\")&&(0,u.dset)(t,n,o.set);if(o.to_string){var l=(0,s.default)(t,n);if(\"string\"==typeof l||\"object\"==typeof l&&null!==l)continue;void 0!==l?(0,u.dset)(t,n,JSON.stringify(l)):(0,u.dset)(t,n,\"undefined\")}}}}function v(t,r){return!(r.sample.percent<=0)&&(r.sample.percent>=1||(r.sample.path?function(t,r){var e=(0,s.default)(t,r.sample.path),n=(0,o.default)(JSON.stringify(e)),u=-64,a=[];y(n.slice(0,8),a);for(var c=0,f=0;f<64&&1!==a[f];f++)c++;if(0!==c){var p=[];y(n.slice(9,16),p),u-=c,a.splice(0,c),p.splice(64-c),a=a.concat(p)}return a[63]=0===a[63]?1:0,(0,i.default)(parseInt(a.join(\"\"),2),u)=1;o/=2)n-o>=0?(n-=o,r.push(1)):r.push(0)}r.default=function(t,r){for(var e=t,n=0,o=r;n{r.dset=function(t,r,e){r.split&&(r=r.split(\".\"));for(var n,o,s=0,i=r.length,u=t;s{\"use strict\";var r=\"function\"==typeof Float64Array?Float64Array:void 0;t.exports=r},7382:(t,r,e)=>{\"use strict\";var n,o=e(5569),s=e(3304),i=e(8482);n=o()?s:i,t.exports=n},8482:t=>{\"use strict\";t.exports=function(){throw new Error(\"not implemented\")}},6322:(t,r,e)=>{\"use strict\";var n,o=e(2508),s=e(5679),i=e(882);n=o()?s:i,t.exports=n},882:t=>{\"use strict\";t.exports=function(){throw new Error(\"not implemented\")}},5679:t=>{\"use strict\";var r=\"function\"==typeof Uint16Array?Uint16Array:void 0;t.exports=r},4773:(t,r,e)=>{\"use strict\";var n,o=e(9773),s=e(3004),i=e(3078);n=o()?s:i,t.exports=n},3078:t=>{\"use strict\";t.exports=function(){throw new Error(\"not implemented\")}},3004:t=>{\"use strict\";var r=\"function\"==typeof Uint32Array?Uint32Array:void 0;t.exports=r},7980:(t,r,e)=>{\"use strict\";var n,o=e(8114),s=e(6737),i=e(3357);n=o()?s:i,t.exports=n},3357:t=>{\"use strict\";t.exports=function(){throw new Error(\"not implemented\")}},6737:t=>{\"use strict\";var r=\"function\"==typeof Uint8Array?Uint8Array:void 0;t.exports=r},2684:t=>{\"use strict\";var r=\"function\"==typeof Float64Array?Float64Array:null;t.exports=r},5569:(t,r,e)=>{\"use strict\";var n=e(3876);t.exports=n},3876:(t,r,e)=>{\"use strict\";var n=e(1448),o=e(2684);t.exports=function(){var t,r;if(\"function\"!=typeof o)return!1;try{r=new o([1,3.14,-3.14,NaN]),t=n(r)&&1===r[0]&&3.14===r[1]&&-3.14===r[2]&&r[3]!=r[3]}catch(r){t=!1}return t}},9048:(t,r,e)=>{\"use strict\";var n=e(3763);t.exports=n},3763:t=>{\"use strict\";var r=Object.prototype.hasOwnProperty;t.exports=function(t,e){return null!=t&&r.call(t,e)}},7009:(t,r,e)=>{\"use strict\";var n=e(6784);t.exports=n},6784:t=>{\"use strict\";t.exports=function(){return\"function\"==typeof Symbol&&\"symbol\"==typeof Symbol(\"foo\")}},3123:(t,r,e)=>{\"use strict\";var n=e(8481);t.exports=n},8481:(t,r,e)=>{\"use strict\";var n=e(7009)();t.exports=function(){return n&&\"symbol\"==typeof Symbol.toStringTag}},2508:(t,r,e)=>{\"use strict\";var n=e(3403);t.exports=n},3403:(t,r,e)=>{\"use strict\";var n=e(768),o=e(9668),s=e(187);t.exports=function(){var t,r;if(\"function\"!=typeof s)return!1;try{r=new s(r=[1,3.14,-3.14,o+1,o+2]),t=n(r)&&1===r[0]&&3===r[1]&&r[2]===o-2&&0===r[3]&&1===r[4]}catch(r){t=!1}return t}},187:t=>{\"use strict\";var r=\"function\"==typeof Uint16Array?Uint16Array:null;t.exports=r},9773:(t,r,e)=>{\"use strict\";var n=e(2822);t.exports=n},2822:(t,r,e)=>{\"use strict\";var n=e(2744),o=e(3899),s=e(746);t.exports=function(){var t,r;if(\"function\"!=typeof s)return!1;try{r=new s(r=[1,3.14,-3.14,o+1,o+2]),t=n(r)&&1===r[0]&&3===r[1]&&r[2]===o-2&&0===r[3]&&1===r[4]}catch(r){t=!1}return t}},746:t=>{\"use strict\";var r=\"function\"==typeof Uint32Array?Uint32Array:null;t.exports=r},8114:(t,r,e)=>{\"use strict\";var n=e(8066);t.exports=n},8066:(t,r,e)=>{\"use strict\";var n=e(8279),o=e(3443),s=e(2731);t.exports=function(){var t,r;if(\"function\"!=typeof s)return!1;try{r=new s(r=[1,3.14,-3.14,o+1,o+2]),t=n(r)&&1===r[0]&&3===r[1]&&r[2]===o-2&&0===r[3]&&1===r[4]}catch(r){t=!1}return t}},2731:t=>{\"use strict\";var r=\"function\"==typeof Uint8Array?Uint8Array:null;t.exports=r},1448:(t,r,e)=>{\"use strict\";var n=e(1453);t.exports=n},1453:(t,r,e)=>{\"use strict\";var n=e(6208),o=\"function\"==typeof Float64Array;t.exports=function(t){return o&&t instanceof Float64Array||\"[object Float64Array]\"===n(t)}},9331:(t,r,e)=>{\"use strict\";var n=e(7980),o={uint16:e(6322),uint8:n};t.exports=o},5902:(t,r,e)=>{\"use strict\";var n=e(4106);t.exports=n},4106:(t,r,e)=>{\"use strict\";var n,o,s=e(9331);(o=new s.uint16(1))[0]=4660,n=52===new s.uint8(o.buffer)[0],t.exports=n},768:(t,r,e)=>{\"use strict\";var n=e(3823);t.exports=n},3823:(t,r,e)=>{\"use strict\";var n=e(6208),o=\"function\"==typeof Uint16Array;t.exports=function(t){return o&&t instanceof Uint16Array||\"[object Uint16Array]\"===n(t)}},2744:(t,r,e)=>{\"use strict\";var n=e(2326);t.exports=n},2326:(t,r,e)=>{\"use strict\";var n=e(6208),o=\"function\"==typeof Uint32Array;t.exports=function(t){return o&&t instanceof Uint32Array||\"[object Uint32Array]\"===n(t)}},8279:(t,r,e)=>{\"use strict\";var n=e(208);t.exports=n},208:(t,r,e)=>{\"use strict\";var n=e(6208),o=\"function\"==typeof Uint8Array;t.exports=function(t){return o&&t instanceof Uint8Array||\"[object Uint8Array]\"===n(t)}},6315:t=>{\"use strict\";t.exports=1023},1686:t=>{\"use strict\";t.exports=2147483647},3105:t=>{\"use strict\";t.exports=2146435072},3449:t=>{\"use strict\";t.exports=2147483648},6988:t=>{\"use strict\";t.exports=-1023},9777:t=>{\"use strict\";t.exports=1023},3690:t=>{\"use strict\";t.exports=-1074},2918:(t,r,e)=>{\"use strict\";var n=e(4772).NEGATIVE_INFINITY;t.exports=n},4165:t=>{\"use strict\";var r=Number.POSITIVE_INFINITY;t.exports=r},6488:t=>{\"use strict\";t.exports=22250738585072014e-324},9668:t=>{\"use strict\";t.exports=65535},3899:t=>{\"use strict\";t.exports=4294967295},3443:t=>{\"use strict\";t.exports=255},7011:(t,r,e)=>{\"use strict\";var n=e(812);t.exports=n},812:(t,r,e)=>{\"use strict\";var n=e(4165),o=e(2918);t.exports=function(t){return t===n||t===o}},1883:(t,r,e)=>{\"use strict\";var n=e(1797);t.exports=n},1797:t=>{\"use strict\";t.exports=function(t){return t!=t}},513:(t,r,e)=>{\"use strict\";var n=e(5760);t.exports=n},5760:t=>{\"use strict\";t.exports=function(t){return Math.abs(t)}},5848:(t,r,e)=>{\"use strict\";var n=e(677);t.exports=n},677:(t,r,e)=>{\"use strict\";var n=e(3449),o=e(1686),s=e(7838),i=e(1921),u=e(2490),a=[0,0];t.exports=function(t,r){var e,c;return s.assign(t,a,1,0),e=a[0],e&=o,c=i(r),u(e|=c&=n,a[1])}},5500:(t,r,e)=>{\"use strict\";var n=e(8397);t.exports=n},8397:(t,r,e)=>{\"use strict\";var n=e(4165),o=e(2918),s=e(6315),i=e(9777),u=e(6988),a=e(3690),c=e(1883),f=e(7011),p=e(5848),l=e(4948),v=e(8478),y=e(7838),d=e(2490),h=[0,0],x=[0,0];t.exports=function(t,r){var e,b;return 0===t||c(t)||f(t)?t:(l(h,t),r+=h[1],(r+=v(t=h[0]))i?t<0?o:n:(r<=u?(r+=52,b=2220446049250313e-31):b=1,y(x,t),e=x[0],e&=2148532223,b*d(e|=r+s<<20,x[1])))}},4772:(t,r,e)=>{\"use strict\";var n=e(7548);t.exports=n},7548:t=>{\"use strict\";t.exports=Number},8478:(t,r,e)=>{\"use strict\";var n=e(4500);t.exports=n},4500:(t,r,e)=>{\"use strict\";var n=e(1921),o=e(3105),s=e(6315);t.exports=function(t){var r=n(t);return(r=(r&o)>>>20)-s|0}},2490:(t,r,e)=>{\"use strict\";var n=e(9639);t.exports=n},4445:(t,r,e)=>{\"use strict\";var n,o,s;!0===e(5902)?(o=1,s=0):(o=0,s=1),n={HIGH:o,LOW:s},t.exports=n},9639:(t,r,e)=>{\"use strict\";var n=e(4773),o=e(7382),s=e(4445),i=new o(1),u=new n(i.buffer),a=s.HIGH,c=s.LOW;t.exports=function(t,r){return u[a]=t,u[c]=r,i[0]}},5646:(t,r,e)=>{\"use strict\";var n;n=!0===e(5902)?1:0,t.exports=n},1921:(t,r,e)=>{\"use strict\";var n=e(6285);t.exports=n},6285:(t,r,e)=>{\"use strict\";var n=e(4773),o=e(7382),s=e(5646),i=new o(1),u=new n(i.buffer);t.exports=function(t){return i[0]=t,u[s]}},9024:(t,r,e)=>{\"use strict\";var n=e(6488),o=e(7011),s=e(1883),i=e(513);t.exports=function(t,r,e,u){return s(t)||o(t)?(r[u]=t,r[u+e]=0,r):0!==t&&i(t){\"use strict\";var n=e(7576),o=e(9422);n(o,\"assign\",e(9024)),t.exports=o},9422:(t,r,e)=>{\"use strict\";var n=e(9024);t.exports=function(t){return n(t,[0,0],1,0)}},5239:(t,r,e)=>{\"use strict\";var n=e(4773),o=e(7382),s=e(5782),i=new o(1),u=new n(i.buffer),a=s.HIGH,c=s.LOW;t.exports=function(t,r,e,n){return i[0]=t,r[n]=u[a],r[n+e]=u[c],r}},7838:(t,r,e)=>{\"use strict\";var n=e(7576),o=e(4010);n(o,\"assign\",e(5239)),t.exports=o},5782:(t,r,e)=>{\"use strict\";var n,o,s;!0===e(5902)?(o=1,s=0):(o=0,s=1),n={HIGH:o,LOW:s},t.exports=n},4010:(t,r,e)=>{\"use strict\";var n=e(5239);t.exports=function(t){return n(t,[0,0],1,0)}},7576:(t,r,e)=>{\"use strict\";var n=e(7063);t.exports=n},7063:(t,r,e)=>{\"use strict\";var n=e(6691);t.exports=function(t,r,e){n(t,r,{configurable:!1,enumerable:!1,writable:!1,value:e})}},2073:t=>{\"use strict\";var r=Object.defineProperty;t.exports=r},1680:t=>{\"use strict\";var r=\"function\"==typeof Object.defineProperty?Object.defineProperty:null;t.exports=r},1471:(t,r,e)=>{\"use strict\";var n=e(1680);t.exports=function(){try{return n({},\"x\",{}),!0}catch(t){return!1}}},6691:(t,r,e)=>{\"use strict\";var n,o=e(1471),s=e(2073),i=e(1309);n=o()?s:i,t.exports=n},1309:t=>{\"use strict\";var r=Object.prototype,e=r.toString,n=r.__defineGetter__,o=r.__defineSetter__,s=r.__lookupGetter__,i=r.__lookupSetter__;t.exports=function(t,u,a){var c,f,p,l;if(\"object\"!=typeof t||null===t||\"[object Array]\"===e.call(t))throw new TypeError(\"invalid argument. First argument must be an object. Value: `\"+t+\"`.\");if(\"object\"!=typeof a||null===a||\"[object Array]\"===e.call(a))throw new TypeError(\"invalid argument. Property descriptor must be an object. Value: `\"+a+\"`.\");if((f=\"value\"in a)&&(s.call(t,u)||i.call(t,u)?(c=t.__proto__,t.__proto__=r,delete t[u],t[u]=a.value,t.__proto__=c):t[u]=a.value),p=\"get\"in a,l=\"set\"in a,f&&(p||l))throw new Error(\"invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.\");return p&&n&&n.call(t,u,a.get),l&&o&&o.call(t,u,a.set),t}},6208:(t,r,e)=>{\"use strict\";var n,o=e(3123),s=e(7407),i=e(4210);n=o()?i:s,t.exports=n},7407:(t,r,e)=>{\"use strict\";var n=e(173);t.exports=function(t){return n.call(t)}},4210:(t,r,e)=>{\"use strict\";var n=e(9048),o=e(1403),s=e(173);t.exports=function(t){var r,e,i;if(null==t)return s.call(t);e=t[o],r=n(t,o);try{t[o]=void 0}catch(r){return s.call(t)}return i=s.call(t),r?t[o]=e:delete t[o],i}},173:t=>{\"use strict\";var r=Object.prototype.toString;t.exports=r},1403:t=>{\"use strict\";var r=\"function\"==typeof Symbol?Symbol.toStringTag:\"\";t.exports=r},7843:function(t){t.exports=function(t,r,e,n,o){for(r=r.split?r.split(\".\"):r,n=0;n{\"use strict\";e.r(r),e.d(r,{default:()=>s});for(var n=[],o=0;o<64;)n[o]=0|4294967296*Math.sin(++o%Math.PI);function s(t){var r,e,s,i=[r=1732584193,e=4023233417,~r,~e],u=[],a=unescape(encodeURI(t))+\"\u0080\",c=a.length;for(t=--c/4+2|15,u[--t]=8*c;~c;)u[c>>2]|=a.charCodeAt(c)<<8*c--;for(o=a=0;o>4]+n[a]+~~u[o|15&[a,5*a+1,3*a+5,7*a][c]])<<(c=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*c+a++%4])|s>>>-c),r,e])r=0|c[1],e=c[2];for(a=4;a;)i[--a]+=c[a]}for(t=\"\";a<32;)t+=(i[a>>3]>>4*(1^a++)&15).toString(16);return t}}},r={};function e(n){var o=r[n];if(void 0!==o)return o.exports;var s=r[n]={exports:{}};return t[n].call(s.exports,s,s.exports,e),s.exports}return e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),e.r=t=>{\"undefined\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:\"Module\"}),Object.defineProperty(t,\"__esModule\",{value:!0})},e(2870)})()));", "// @ts-ignore\nimport * as tsub from '../../vendor/tsub/tsub'\nimport type { Matcher, Rule, Store } from '../../vendor/tsub/types'\nimport { DestinationMiddlewareFunction } from '../middleware'\n\n// TODO: update tsub definition\ntype RoutingRuleMatcher = Matcher & {\n config?: {\n expr: string\n }\n}\n\nexport type RoutingRule = Rule & {\n matchers: RoutingRuleMatcher[]\n}\n\nexport const tsubMiddleware =\n (rules: RoutingRule[]): DestinationMiddlewareFunction =>\n ({ payload, integration, next }): void => {\n const store = new tsub.Store(rules) as Store\n const rulesToApply = store.getRulesByDestinationName(integration)\n\n rulesToApply.forEach((rule: Rule) => {\n const { matchers, transformers } = rule\n\n for (let i = 0; i < matchers.length; i++) {\n if (tsub.matches(payload.obj, matchers[i])) {\n payload.obj = tsub.transform(payload.obj, transformers[i])\n\n if (payload.obj === null) {\n return next(null)\n }\n }\n }\n })\n\n next(payload)\n }\n", "import { PlanEvent, TrackPlan } from '../core/events/interfaces'\n\n/**\n * Determines whether a track event is allowed to be sent based on the\n * user's tracking plan.\n * If the user does not have a tracking plan or the event is allowed based\n * on the tracking plan configuration, returns true.\n */\nexport function isPlanEventEnabled(\n plan: TrackPlan | undefined,\n planEvent: PlanEvent | undefined\n): boolean {\n // Always prioritize the event's `enabled` status\n if (typeof planEvent?.enabled === 'boolean') {\n return planEvent.enabled\n }\n\n // Assume absence of a tracking plan means events are enabled\n return plan?.__default?.enabled ?? true\n}\n", "import { Analytics } from '../../core/analytics'\nimport { RemoteIntegrationSettings } from '../../browser'\nimport { getNextIntegrationsURL } from '../../lib/parse-cdn'\nimport { Context } from '../../core/context'\nimport { User } from '../../core/user'\nimport { loadScript, unloadScript } from '../../lib/load-script'\nimport {\n LegacyIntegration,\n ClassicIntegrationBuilder,\n ClassicIntegrationSource,\n} from './types'\n\nfunction normalizeName(name: string): string {\n return name.toLowerCase().replace('.', '').replace(/\\s+/g, '-')\n}\n\nfunction obfuscatePathName(pathName: string, obfuscate = false): string | void {\n return obfuscate ? btoa(pathName).replace(/=/g, '') : undefined\n}\n\nexport function resolveIntegrationNameFromSource(\n integrationSource: ClassicIntegrationSource\n) {\n return (\n 'Integration' in integrationSource\n ? integrationSource.Integration\n : integrationSource\n ).prototype.name\n}\n\nfunction recordLoadMetrics(fullPath: string, ctx: Context, name: string): void {\n try {\n const [metric] =\n window?.performance?.getEntriesByName(fullPath, 'resource') ?? []\n // we assume everything that took under 100ms is cached\n metric &&\n ctx.stats.gauge('legacy_destination_time', Math.round(metric.duration), [\n name,\n ...(metric.duration < 100 ? ['cached'] : []),\n ])\n } catch (_) {\n // not available\n }\n}\n\nexport function buildIntegration(\n integrationSource: ClassicIntegrationSource,\n integrationSettings: { [key: string]: any },\n analyticsInstance: Analytics\n): LegacyIntegration {\n let integrationCtr: ClassicIntegrationBuilder\n // GA and Appcues use a different interface to instantiating integrations\n if ('Integration' in integrationSource) {\n const analyticsStub = {\n user: (): User => analyticsInstance.user(),\n addIntegration: (): void => {},\n }\n\n integrationSource(analyticsStub)\n integrationCtr = integrationSource.Integration\n } else {\n integrationCtr = integrationSource\n }\n\n const integration = new integrationCtr(integrationSettings)\n integration.analytics = analyticsInstance\n return integration\n}\n\nexport async function loadIntegration(\n ctx: Context,\n name: string,\n version: string,\n obfuscate?: boolean\n): Promise {\n const pathName = normalizeName(name)\n const obfuscatedPathName = obfuscatePathName(pathName, obfuscate)\n const path = getNextIntegrationsURL()\n\n const fullPath = `${path}/integrations/${\n obfuscatedPathName ?? pathName\n }/${version}/${obfuscatedPathName ?? pathName}.dynamic.js.gz`\n\n try {\n await loadScript(fullPath)\n recordLoadMetrics(fullPath, ctx, name)\n } catch (err) {\n ctx.stats.gauge('legacy_destination_time', -1, [`plugin:${name}`, `failed`])\n throw err\n }\n\n // @ts-ignore\n const deps: string[] = window[`${pathName}Deps`]\n await Promise.all(deps.map((dep) => loadScript(path + dep + '.gz')))\n\n // @ts-ignore\n window[`${pathName}Loader`]()\n\n return window[\n // @ts-ignore\n `${pathName}Integration`\n ] as ClassicIntegrationSource\n}\n\nexport async function unloadIntegration(\n name: string,\n version: string,\n obfuscate?: boolean\n): Promise {\n const path = getNextIntegrationsURL()\n const pathName = normalizeName(name)\n const obfuscatedPathName = obfuscatePathName(name, obfuscate)\n\n const fullPath = `${path}/integrations/${\n obfuscatedPathName ?? pathName\n }/${version}/${obfuscatedPathName ?? pathName}.dynamic.js.gz`\n\n return unloadScript(fullPath)\n}\n\nexport function resolveVersion(\n integrationConfig?: RemoteIntegrationSettings\n): string {\n return (\n integrationConfig?.versionSettings?.override ??\n integrationConfig?.versionSettings?.version ??\n 'latest'\n )\n}\n", "import { Integrations } from '@segment/analytics-core'\nimport { RemoteIntegrationSettings } from '../..'\n\nexport const isInstallableIntegration = (\n name: string,\n integrationSettings: RemoteIntegrationSettings\n) => {\n const { type, bundlingStatus, versionSettings } = integrationSettings\n // We use `!== 'unbundled'` (versus `=== 'bundled'`) to be inclusive of\n // destinations without a defined value for `bundlingStatus`\n const deviceMode =\n bundlingStatus !== 'unbundled' &&\n (type === 'browser' || versionSettings?.componentTypes?.includes('browser'))\n\n // checking for iterable is a quick fix we need in place to prevent\n // errors showing Iterable as a failed destiantion. Ideally, we should\n // fix the Iterable metadata instead, but that's a longer process.\n return !name.startsWith('Segment') && name !== 'Iterable' && deviceMode\n}\n\nexport const isDisabledIntegration = (\n integrationName: string,\n globalIntegrations: Integrations\n) => {\n const allDisableAndNotDefined =\n globalIntegrations.All === false &&\n globalIntegrations[integrationName] === undefined\n\n return (\n globalIntegrations[integrationName] === false || allDisableAndNotDefined\n )\n}\n", "import { Integrations, JSONObject } from '../../core/events'\nimport { Alias, Facade, Group, Identify, Page, Track } from '@segment/facade'\nimport { Analytics, InitOptions } from '../../core/analytics'\nimport { CDNSettings } from '../../browser'\nimport { isOffline, isOnline } from '../../core/connection'\nimport { Context, ContextCancelation } from '../../core/context'\nimport { isServer } from '../../core/environment'\nimport { InternalPluginWithAddMiddleware, Plugin } from '../../core/plugin'\nimport { attempt } from '@segment/analytics-core'\nimport { isPlanEventEnabled } from '../../lib/is-plan-event-enabled'\nimport { mergedOptions } from '../../lib/merged-options'\nimport { pWhile } from '../../lib/p-while'\nimport { PriorityQueue } from '../../lib/priority-queue'\nimport { PersistedPriorityQueue } from '../../lib/priority-queue/persisted'\nimport {\n applyDestinationMiddleware,\n DestinationMiddlewareFunction,\n} from '../middleware'\nimport {\n buildIntegration,\n loadIntegration,\n resolveIntegrationNameFromSource,\n resolveVersion,\n unloadIntegration,\n} from './loader'\nimport { LegacyIntegration, ClassicIntegrationSource } from './types'\nimport { isPlainObject } from '@segment/analytics-core'\nimport {\n isDisabledIntegration as shouldSkipIntegration,\n isInstallableIntegration,\n} from './utils'\nimport { recordIntegrationMetric } from '../../core/stats/metric-helpers'\nimport { createDeferred } from '@segment/analytics-generic-utils'\n\nexport type ClassType = new (...args: unknown[]) => T\n\nasync function flushQueue(\n xt: Plugin,\n queue: PriorityQueue\n): Promise> {\n const failedQueue: Context[] = []\n\n if (isOffline()) {\n return queue\n }\n\n await pWhile(\n () => queue.length > 0 && isOnline(),\n async () => {\n const ctx = queue.pop()\n if (!ctx) {\n return\n }\n\n const result = await attempt(ctx, xt)\n const success = result instanceof Context\n if (!success) {\n failedQueue.push(ctx)\n }\n }\n )\n\n // re-add failed tasks\n failedQueue.map((failed) => queue.pushWithBackoff(failed))\n return queue\n}\n\nexport class LegacyDestination implements InternalPluginWithAddMiddleware {\n name: string\n version: string\n settings: JSONObject\n options: InitOptions = {}\n readonly type = 'destination'\n middleware: DestinationMiddlewareFunction[] = []\n\n private _ready: boolean | undefined\n private _initialized: boolean | undefined\n private onReady: Promise | undefined\n private initializePromise = createDeferred()\n private disableAutoISOConversion: boolean\n\n integrationSource?: ClassicIntegrationSource\n integration: LegacyIntegration | undefined\n\n buffer: PriorityQueue\n flushing = false\n\n constructor(\n name: string,\n version: string,\n writeKey: string,\n settings: JSONObject = {},\n options: InitOptions,\n integrationSource?: ClassicIntegrationSource\n ) {\n this.name = name\n this.version = version\n this.settings = { ...settings }\n this.disableAutoISOConversion = options.disableAutoISOConversion || false\n this.integrationSource = integrationSource\n\n // AJS-Renderer sets an extraneous `type` setting that clobbers\n // existing type defaults. We need to remove it if it's present\n if (this.settings['type'] && this.settings['type'] === 'browser') {\n delete this.settings['type']\n }\n\n this.initializePromise.promise.then(\n (isInitialized) => (this._initialized = isInitialized),\n () => {}\n )\n\n this.options = options\n this.buffer = options.disableClientPersistence\n ? new PriorityQueue(4, [])\n : new PersistedPriorityQueue(4, `${writeKey}:dest-${name}`)\n\n this.scheduleFlush()\n }\n\n isLoaded(): boolean {\n return !!this._ready\n }\n\n ready(): Promise {\n return this.initializePromise.promise.then(\n () => this.onReady ?? Promise.resolve()\n )\n }\n\n async load(ctx: Context, analyticsInstance: Analytics): Promise {\n if (this._ready || this.onReady !== undefined) {\n return\n }\n\n const integrationSource =\n this.integrationSource ??\n (await loadIntegration(\n ctx,\n this.name,\n this.version,\n this.options.obfuscate\n ))\n\n this.integration = buildIntegration(\n integrationSource,\n this.settings,\n analyticsInstance\n )\n\n this.onReady = new Promise((resolve) => {\n const onReadyFn = (): void => {\n this._ready = true\n resolve(true)\n }\n\n this.integration!.once('ready', onReadyFn)\n })\n\n this.integration!.on('initialize', () => {\n this.initializePromise.resolve(true)\n })\n\n try {\n recordIntegrationMetric(ctx, {\n integrationName: this.name,\n methodName: 'initialize',\n type: 'classic',\n })\n this.integration.initialize()\n } catch (error) {\n recordIntegrationMetric(ctx, {\n integrationName: this.name,\n methodName: 'initialize',\n type: 'classic',\n didError: true,\n })\n this.initializePromise.resolve(false)\n throw error\n }\n }\n\n unload(_ctx: Context, _analyticsInstance: Analytics): Promise {\n return unloadIntegration(this.name, this.version, this.options.obfuscate)\n }\n\n addMiddleware(...fn: DestinationMiddlewareFunction[]): void {\n this.middleware = this.middleware.concat(...fn)\n }\n\n shouldBuffer(ctx: Context): boolean {\n return (\n // page events can't be buffered because of destinations that automatically add page views\n ctx.event.type !== 'page' &&\n (isOffline() || this._ready !== true || this._initialized !== true)\n )\n }\n\n private async send(\n ctx: Context,\n clz: ClassType,\n eventType: 'track' | 'identify' | 'page' | 'alias' | 'group'\n ): Promise {\n if (this.shouldBuffer(ctx)) {\n this.buffer.push(ctx)\n this.scheduleFlush()\n return ctx\n }\n\n const plan = this.options?.plan?.track\n const ev = ctx.event.event\n\n if (plan && ev && this.name !== 'Segment.io') {\n // events are always sent to segment (legacy behavior)\n const planEvent = plan[ev]\n if (!isPlanEventEnabled(plan, planEvent)) {\n ctx.updateEvent('integrations', {\n ...ctx.event.integrations,\n All: false,\n 'Segment.io': true,\n })\n ctx.cancel(\n new ContextCancelation({\n retry: false,\n reason: `Event ${ev} disabled for integration ${this.name} in tracking plan`,\n type: 'Dropped by plan',\n })\n )\n } else {\n ctx.updateEvent('integrations', {\n ...ctx.event.integrations,\n ...planEvent?.integrations,\n })\n }\n\n if (planEvent?.enabled && planEvent?.integrations![this.name] === false) {\n ctx.cancel(\n new ContextCancelation({\n retry: false,\n reason: `Event ${ev} disabled for integration ${this.name} in tracking plan`,\n type: 'Dropped by plan',\n })\n )\n }\n }\n\n const afterMiddleware = await applyDestinationMiddleware(\n this.name,\n ctx.event,\n this.middleware\n )\n\n if (afterMiddleware === null) {\n return ctx\n }\n\n const event = new clz(afterMiddleware, {\n traverse: !this.disableAutoISOConversion,\n })\n\n recordIntegrationMetric(ctx, {\n integrationName: this.name,\n methodName: eventType,\n type: 'classic',\n })\n\n try {\n if (this.integration) {\n await this.integration!.invoke.call(this.integration, eventType, event)\n }\n } catch (err) {\n recordIntegrationMetric(ctx, {\n integrationName: this.name,\n methodName: eventType,\n type: 'classic',\n didError: true,\n })\n throw err\n }\n\n return ctx\n }\n\n async track(ctx: Context): Promise {\n return this.send(ctx, Track as ClassType