posthog-js 1.151.2 → 1.152.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.full.js +2 -2
- package/dist/array.full.js.map +1 -1
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/exception-autocapture.js.map +1 -1
- package/dist/lib/src/extensions/surveys/components/PostHogLogo.d.ts +1 -3
- package/dist/lib/src/extensions/surveys/surveys-utils.d.ts +2 -1
- package/dist/lib/src/extensions/surveys.d.ts +11 -3
- package/dist/lib/src/posthog-core.d.ts +4 -0
- package/dist/lib/src/posthog-surveys-types.d.ts +4 -0
- package/dist/lib/src/posthog-surveys.d.ts +3 -0
- package/dist/lib/src/types.d.ts +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +13 -2
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/surveys-preview.js +1 -1
- package/dist/surveys-preview.js.map +1 -1
- package/dist/surveys.js +1 -1
- package/dist/surveys.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/src/extensions/surveys/components/BottomSection.jsx +4 -4
- package/lib/src/extensions/surveys/components/BottomSection.jsx.map +1 -1
- package/lib/src/extensions/surveys/components/ConfirmationMessage.jsx +5 -2
- package/lib/src/extensions/surveys/components/ConfirmationMessage.jsx.map +1 -1
- package/lib/src/extensions/surveys/components/PostHogLogo.d.ts +1 -3
- package/lib/src/extensions/surveys/components/PostHogLogo.jsx +2 -5
- package/lib/src/extensions/surveys/components/PostHogLogo.jsx.map +1 -1
- package/lib/src/extensions/surveys/components/QuestionHeader.jsx +2 -1
- package/lib/src/extensions/surveys/components/QuestionHeader.jsx.map +1 -1
- package/lib/src/extensions/surveys/components/QuestionTypes.jsx +9 -17
- package/lib/src/extensions/surveys/components/QuestionTypes.jsx.map +1 -1
- package/lib/src/extensions/surveys/surveys-utils.d.ts +2 -1
- package/lib/src/extensions/surveys/surveys-utils.jsx +4 -2
- package/lib/src/extensions/surveys/surveys-utils.jsx.map +1 -1
- package/lib/src/extensions/surveys.d.ts +11 -3
- package/lib/src/extensions/surveys.jsx +62 -7
- package/lib/src/extensions/surveys.jsx.map +1 -1
- package/lib/src/posthog-core.d.ts +4 -0
- package/lib/src/posthog-core.js +8 -0
- package/lib/src/posthog-core.js.map +1 -1
- package/lib/src/posthog-persistence.js +1 -1
- package/lib/src/posthog-persistence.js.map +1 -1
- package/lib/src/posthog-surveys-types.d.ts +4 -0
- package/lib/src/posthog-surveys-types.js.map +1 -1
- package/lib/src/posthog-surveys.d.ts +3 -0
- package/lib/src/posthog-surveys.js +23 -1
- package/lib/src/posthog-surveys.js.map +1 -1
- package/lib/src/storage.js +15 -6
- package/lib/src/storage.js.map +1 -1
- package/lib/src/types.d.ts +1 -1
- package/lib/src/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -108,7 +108,7 @@ var PostHogPersistence = /** @class */ (function () {
|
|
|
108
108
|
if (this.disabled) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
|
-
this.storage.set(this.name, this.props, this.expire_days, this.cross_subdomain, this.secure);
|
|
111
|
+
this.storage.set(this.name, this.props, this.expire_days, this.cross_subdomain, this.secure, this.config.debug);
|
|
112
112
|
};
|
|
113
113
|
PostHogPersistence.prototype.remove = function () {
|
|
114
114
|
// remove both domain and subdomain cookies
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-persistence.js","sourceRoot":"","sources":["../../src/posthog-persistence.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACzF,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAEpG,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACv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,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;QACrB,IAAI,CAAC,IAAI,EAAE,CAAA;IACf,CAAC;IACL,yBAAC;AAAD,CAAC,AAnUD,IAmUC","sourcesContent":["/* eslint camelcase: \"off\" */\n\nimport { each, extend, include, stripEmptyProperties, stripLeadingDollar } from './utils'\nimport { cookieStore, localPlusCookieStore, localStore, memoryStore, sessionStore } from './storage'\nimport { PersistentStore, PostHogConfig, Properties } from './types'\nimport {\n ENABLED_FEATURE_FLAGS,\n EVENT_TIMERS_KEY,\n INITIAL_CAMPAIGN_PARAMS,\n INITIAL_PERSON_INFO,\n INITIAL_REFERRER_INFO,\n PERSISTENCE_RESERVED_PROPERTIES,\n} from './constants'\n\nimport { isObject, isUndefined } from './utils/type-utils'\nimport { Info } from './utils/event-utils'\nimport { logger } from './utils/logger'\n\nconst CASE_INSENSITIVE_PERSISTENCE_TYPES: readonly Lowercase<PostHogConfig['persistence']>[] = [\n 'cookie',\n 'localstorage',\n 'localstorage+cookie',\n 'sessionstorage',\n 'memory',\n]\n\nconst parseName = (config: PostHogConfig): string => {\n let token = ''\n if (config['token']) {\n token = config['token'].replace(/\\+/g, 'PL').replace(/\\//g, 'SL').replace(/=/g, 'EQ')\n }\n\n if (config['persistence_name']) {\n return 'ph_' + config['persistence_name']\n } else {\n return 'ph_' + token + '_posthog'\n }\n}\n\n/**\n * PostHog Persistence Object\n * @constructor\n */\nexport class PostHogPersistence {\n private config: PostHogConfig\n props: Properties\n storage: PersistentStore\n campaign_params_saved: boolean\n name: string\n disabled: boolean | undefined\n secure: boolean | undefined\n expire_days: number | undefined\n default_expiry: number | undefined\n cross_subdomain: boolean | undefined\n\n constructor(config: PostHogConfig) {\n this.config = config\n this.props = {}\n this.campaign_params_saved = false\n this.name = parseName(config)\n this.storage = this.buildStorage(config)\n this.load()\n if (config.debug) {\n logger.info('Persistence loaded', this.props)\n }\n this.update_config(config, config)\n this.save()\n }\n\n private buildStorage(config: PostHogConfig) {\n if (\n CASE_INSENSITIVE_PERSISTENCE_TYPES.indexOf(\n config['persistence'].toLowerCase() as Lowercase<PostHogConfig['persistence']>\n ) === -1\n ) {\n logger.critical(\n 'Unknown persistence type ' + config['persistence'] + '; falling back to localStorage+cookie'\n )\n config['persistence'] = 'localStorage+cookie'\n }\n\n let store: PersistentStore\n // We handle storage type in a case-insensitive way for backwards compatibility\n const storage_type = config['persistence'].toLowerCase() as Lowercase<PostHogConfig['persistence']>\n if (storage_type === 'localstorage' && localStore.is_supported()) {\n store = localStore\n } else if (storage_type === 'localstorage+cookie' && localPlusCookieStore.is_supported()) {\n store = localPlusCookieStore\n } else if (storage_type === 'sessionstorage' && sessionStore.is_supported()) {\n store = sessionStore\n } else if (storage_type === 'memory') {\n store = memoryStore\n } else if (storage_type === 'cookie') {\n store = cookieStore\n } else if (localPlusCookieStore.is_supported()) {\n // selected storage type wasn't supported, fallback to 'localstorage+cookie' if possible\n store = localPlusCookieStore\n } else {\n store = cookieStore\n }\n\n return store\n }\n\n properties(): Properties {\n const p: Properties = {}\n // Filter out reserved properties\n each(this.props, function (v, k) {\n if (k === ENABLED_FEATURE_FLAGS && isObject(v)) {\n const keys = Object.keys(v)\n for (let i = 0; i < keys.length; i++) {\n p[`$feature/${keys[i]}`] = v[keys[i]]\n }\n } else if (!include(PERSISTENCE_RESERVED_PROPERTIES, k)) {\n p[k] = v\n }\n })\n return p\n }\n\n load(): void {\n if (this.disabled) {\n return\n }\n\n const entry = this.storage.parse(this.name)\n\n if (entry) {\n this.props = extend({}, entry)\n }\n }\n\n /**\n * NOTE: Saving frequently causes issues with Recordings and Consent Management Platform (CMP) tools which\n * observe cookie changes, and modify their UI, often causing infinite loops.\n * As such callers of this should ideally check that the data has changed beforehand\n */\n save(): void {\n if (this.disabled) {\n return\n }\n this.storage.set(this.name, this.props, this.expire_days, this.cross_subdomain, this.secure)\n }\n\n remove(): void {\n // remove both domain and subdomain cookies\n this.storage.remove(this.name, false)\n this.storage.remove(this.name, true)\n }\n\n // removes the storage entry and deletes all loaded data\n // forced name for tests\n\n clear(): void {\n this.remove()\n this.props = {}\n }\n\n /**\n * @param {Object} props\n * @param {*=} default_value\n * @param {number=} days\n */\n\n register_once(props: Properties, default_value: any, days?: number): boolean {\n if (isObject(props)) {\n if (isUndefined(default_value)) {\n default_value = 'None'\n }\n this.expire_days = isUndefined(days) ? this.default_expiry : days\n\n let hasChanges = false\n\n each(props, (val, prop) => {\n if (!this.props.hasOwnProperty(prop) || this.props[prop] === default_value) {\n this.props[prop] = val\n hasChanges = true\n }\n })\n\n if (hasChanges) {\n this.save()\n return true\n }\n }\n return false\n }\n\n /**\n * @param {Object} props\n * @param {number=} days\n */\n\n register(props: Properties, days?: number): boolean {\n if (isObject(props)) {\n this.expire_days = isUndefined(days) ? this.default_expiry : days\n\n let hasChanges = false\n\n each(props, (val, prop) => {\n if (props.hasOwnProperty(prop) && this.props[prop] !== val) {\n this.props[prop] = val\n hasChanges = true\n }\n })\n\n if (hasChanges) {\n this.save()\n return true\n }\n }\n return false\n }\n\n unregister(prop: string): void {\n if (prop in this.props) {\n delete this.props[prop]\n this.save()\n }\n }\n\n update_campaign_params(): void {\n if (!this.campaign_params_saved) {\n this.register(Info.campaignParams(this.config.custom_campaign_params))\n this.campaign_params_saved = true\n }\n }\n update_search_keyword(): void {\n this.register(Info.searchInfo())\n }\n\n update_referrer_info(): void {\n this.register_once(Info.referrerInfo(), undefined)\n }\n\n set_initial_person_info(): void {\n if (this.props[INITIAL_CAMPAIGN_PARAMS] || this.props[INITIAL_REFERRER_INFO]) {\n // the user has initial properties stored the previous way, don't save them again\n return\n }\n\n this.register_once(\n {\n [INITIAL_PERSON_INFO]: Info.initialPersonInfo(),\n },\n undefined\n )\n }\n\n get_referrer_info(): Properties {\n return stripEmptyProperties({\n $referrer: this['props']['$referrer'],\n $referring_domain: this['props']['$referring_domain'],\n })\n }\n\n get_initial_props(): Properties {\n const p: Properties = {}\n\n // this section isn't written to anymore, but we should keep reading from it for backwards compatibility\n // for a while\n each([INITIAL_REFERRER_INFO, INITIAL_CAMPAIGN_PARAMS], (key) => {\n const initialReferrerInfo = this.props[key]\n if (initialReferrerInfo) {\n each(initialReferrerInfo, function (v, k) {\n p['$initial_' + stripLeadingDollar(k)] = v\n })\n }\n })\n const initialPersonInfo = this.props[INITIAL_PERSON_INFO]\n if (initialPersonInfo) {\n const initialPersonProps = Info.initialPersonPropsFromInfo(initialPersonInfo)\n extend(p, initialPersonProps)\n }\n\n return p\n }\n\n // safely fills the passed in object with stored properties,\n // does not override any properties defined in both\n // returns the passed in object\n\n safe_merge(props: Properties): Properties {\n each(this.props, function (val, prop) {\n if (!(prop in props)) {\n props[prop] = val\n }\n })\n\n return props\n }\n\n update_config(config: PostHogConfig, oldConfig: PostHogConfig): void {\n this.default_expiry = this.expire_days = config['cookie_expiration']\n this.set_disabled(config['disable_persistence'])\n this.set_cross_subdomain(config['cross_subdomain_cookie'])\n this.set_secure(config['secure_cookie'])\n\n if (config.persistence !== oldConfig.persistence) {\n // If the persistence type has changed, we need to migrate the data.\n const newStore = this.buildStorage(config)\n const props = this.props\n\n // clear the old store\n this.clear()\n this.storage = newStore\n this.props = props\n\n this.save()\n }\n }\n\n set_disabled(disabled: boolean): void {\n this.disabled = disabled\n if (this.disabled) {\n this.remove()\n } else {\n this.save()\n }\n }\n\n set_cross_subdomain(cross_subdomain: boolean): void {\n if (cross_subdomain !== this.cross_subdomain) {\n this.cross_subdomain = cross_subdomain\n this.remove()\n this.save()\n }\n }\n\n get_cross_subdomain(): boolean {\n return !!this.cross_subdomain\n }\n\n set_secure(secure: boolean): void {\n if (secure !== this.secure) {\n this.secure = secure\n this.remove()\n this.save()\n }\n }\n\n set_event_timer(event_name: string, timestamp: number): void {\n const timers = this.props[EVENT_TIMERS_KEY] || {}\n timers[event_name] = timestamp\n this.props[EVENT_TIMERS_KEY] = timers\n this.save()\n }\n\n remove_event_timer(event_name: string): number {\n const timers = this.props[EVENT_TIMERS_KEY] || {}\n const timestamp = timers[event_name]\n if (!isUndefined(timestamp)) {\n delete this.props[EVENT_TIMERS_KEY][event_name]\n this.save()\n }\n return timestamp\n }\n\n get_property(prop: string): any {\n return this.props[prop]\n }\n\n set_property(prop: string, to: any): void {\n this.props[prop] = to\n this.save()\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"posthog-persistence.js","sourceRoot":"","sources":["../../src/posthog-persistence.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACzF,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAEpG,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,+BAA+B,GAClC,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,IAAM,kCAAkC,GAAuD;IAC3F,QAAQ;IACR,cAAc;IACd,qBAAqB;IACrB,gBAAgB;IAChB,QAAQ;CACX,CAAA;AAED,IAAM,SAAS,GAAG,UAAC,MAAqB;IACpC,IAAI,KAAK,GAAG,EAAE,CAAA;IACd,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE;QACjB,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;KACxF;IAED,IAAI,MAAM,CAAC,kBAAkB,CAAC,EAAE;QAC5B,OAAO,KAAK,GAAG,MAA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IAAI,EAAE,CAAA;IACf,CAAC;IAED,+CAAkB,GAAlB,UAAmB,UAAkB;QACjC,IAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAA;QACjD,IAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;QACpC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAA;YAC/C,IAAI,CAAC,IAAI,EAAE,CAAA;SACd;QACD,OAAO,SAAS,CAAA;IACpB,CAAC;IAED,yCAAY,GAAZ,UAAa,IAAY;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAED,yCAAY,GAAZ,UAAa,IAAY,EAAE,EAAO;QAC9B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;QACrB,IAAI,CAAC,IAAI,EAAE,CAAA;IACf,CAAC;IACL,yBAAC;AAAD,CAAC,AAnUD,IAmUC","sourcesContent":["/* eslint camelcase: \"off\" */\n\nimport { each, extend, include, stripEmptyProperties, stripLeadingDollar } from './utils'\nimport { cookieStore, localPlusCookieStore, localStore, memoryStore, sessionStore } from './storage'\nimport { PersistentStore, PostHogConfig, Properties } from './types'\nimport {\n ENABLED_FEATURE_FLAGS,\n EVENT_TIMERS_KEY,\n INITIAL_CAMPAIGN_PARAMS,\n INITIAL_PERSON_INFO,\n INITIAL_REFERRER_INFO,\n PERSISTENCE_RESERVED_PROPERTIES,\n} from './constants'\n\nimport { isObject, isUndefined } from './utils/type-utils'\nimport { Info } from './utils/event-utils'\nimport { logger } from './utils/logger'\n\nconst CASE_INSENSITIVE_PERSISTENCE_TYPES: readonly Lowercase<PostHogConfig['persistence']>[] = [\n 'cookie',\n 'localstorage',\n 'localstorage+cookie',\n 'sessionstorage',\n 'memory',\n]\n\nconst parseName = (config: PostHogConfig): string => {\n let token = ''\n if (config['token']) {\n token = config['token'].replace(/\\+/g, 'PL').replace(/\\//g, 'SL').replace(/=/g, 'EQ')\n }\n\n if (config['persistence_name']) {\n return 'ph_' + config['persistence_name']\n } else {\n return 'ph_' + token + '_posthog'\n }\n}\n\n/**\n * PostHog Persistence Object\n * @constructor\n */\nexport class PostHogPersistence {\n private config: PostHogConfig\n props: Properties\n storage: PersistentStore\n campaign_params_saved: boolean\n name: string\n disabled: boolean | undefined\n secure: boolean | undefined\n expire_days: number | undefined\n default_expiry: number | undefined\n cross_subdomain: boolean | undefined\n\n constructor(config: PostHogConfig) {\n this.config = config\n this.props = {}\n this.campaign_params_saved = false\n this.name = parseName(config)\n this.storage = this.buildStorage(config)\n this.load()\n if (config.debug) {\n logger.info('Persistence loaded', this.props)\n }\n this.update_config(config, config)\n this.save()\n }\n\n private buildStorage(config: PostHogConfig) {\n if (\n CASE_INSENSITIVE_PERSISTENCE_TYPES.indexOf(\n config['persistence'].toLowerCase() as Lowercase<PostHogConfig['persistence']>\n ) === -1\n ) {\n logger.critical(\n 'Unknown persistence type ' + config['persistence'] + '; falling back to localStorage+cookie'\n )\n config['persistence'] = 'localStorage+cookie'\n }\n\n let store: PersistentStore\n // We handle storage type in a case-insensitive way for backwards compatibility\n const storage_type = config['persistence'].toLowerCase() as Lowercase<PostHogConfig['persistence']>\n if (storage_type === 'localstorage' && localStore.is_supported()) {\n store = localStore\n } else if (storage_type === 'localstorage+cookie' && localPlusCookieStore.is_supported()) {\n store = localPlusCookieStore\n } else if (storage_type === 'sessionstorage' && sessionStore.is_supported()) {\n store = sessionStore\n } else if (storage_type === 'memory') {\n store = memoryStore\n } else if (storage_type === 'cookie') {\n store = cookieStore\n } else if (localPlusCookieStore.is_supported()) {\n // selected storage type wasn't supported, fallback to 'localstorage+cookie' if possible\n store = localPlusCookieStore\n } else {\n store = cookieStore\n }\n\n return store\n }\n\n properties(): Properties {\n const p: Properties = {}\n // Filter out reserved properties\n each(this.props, function (v, k) {\n if (k === ENABLED_FEATURE_FLAGS && isObject(v)) {\n const keys = Object.keys(v)\n for (let i = 0; i < keys.length; i++) {\n p[`$feature/${keys[i]}`] = v[keys[i]]\n }\n } else if (!include(PERSISTENCE_RESERVED_PROPERTIES, k)) {\n p[k] = v\n }\n })\n return p\n }\n\n load(): void {\n if (this.disabled) {\n return\n }\n\n const entry = this.storage.parse(this.name)\n\n if (entry) {\n this.props = extend({}, entry)\n }\n }\n\n /**\n * NOTE: Saving frequently causes issues with Recordings and Consent Management Platform (CMP) tools which\n * observe cookie changes, and modify their UI, often causing infinite loops.\n * As such callers of this should ideally check that the data has changed beforehand\n */\n save(): void {\n if (this.disabled) {\n return\n }\n this.storage.set(this.name, this.props, this.expire_days, this.cross_subdomain, this.secure, this.config.debug)\n }\n\n remove(): void {\n // remove both domain and subdomain cookies\n this.storage.remove(this.name, false)\n this.storage.remove(this.name, true)\n }\n\n // removes the storage entry and deletes all loaded data\n // forced name for tests\n\n clear(): void {\n this.remove()\n this.props = {}\n }\n\n /**\n * @param {Object} props\n * @param {*=} default_value\n * @param {number=} days\n */\n\n register_once(props: Properties, default_value: any, days?: number): boolean {\n if (isObject(props)) {\n if (isUndefined(default_value)) {\n default_value = 'None'\n }\n this.expire_days = isUndefined(days) ? this.default_expiry : days\n\n let hasChanges = false\n\n each(props, (val, prop) => {\n if (!this.props.hasOwnProperty(prop) || this.props[prop] === default_value) {\n this.props[prop] = val\n hasChanges = true\n }\n })\n\n if (hasChanges) {\n this.save()\n return true\n }\n }\n return false\n }\n\n /**\n * @param {Object} props\n * @param {number=} days\n */\n\n register(props: Properties, days?: number): boolean {\n if (isObject(props)) {\n this.expire_days = isUndefined(days) ? this.default_expiry : days\n\n let hasChanges = false\n\n each(props, (val, prop) => {\n if (props.hasOwnProperty(prop) && this.props[prop] !== val) {\n this.props[prop] = val\n hasChanges = true\n }\n })\n\n if (hasChanges) {\n this.save()\n return true\n }\n }\n return false\n }\n\n unregister(prop: string): void {\n if (prop in this.props) {\n delete this.props[prop]\n this.save()\n }\n }\n\n update_campaign_params(): void {\n if (!this.campaign_params_saved) {\n this.register(Info.campaignParams(this.config.custom_campaign_params))\n this.campaign_params_saved = true\n }\n }\n update_search_keyword(): void {\n this.register(Info.searchInfo())\n }\n\n update_referrer_info(): void {\n this.register_once(Info.referrerInfo(), undefined)\n }\n\n set_initial_person_info(): void {\n if (this.props[INITIAL_CAMPAIGN_PARAMS] || this.props[INITIAL_REFERRER_INFO]) {\n // the user has initial properties stored the previous way, don't save them again\n return\n }\n\n this.register_once(\n {\n [INITIAL_PERSON_INFO]: Info.initialPersonInfo(),\n },\n undefined\n )\n }\n\n get_referrer_info(): Properties {\n return stripEmptyProperties({\n $referrer: this['props']['$referrer'],\n $referring_domain: this['props']['$referring_domain'],\n })\n }\n\n get_initial_props(): Properties {\n const p: Properties = {}\n\n // this section isn't written to anymore, but we should keep reading from it for backwards compatibility\n // for a while\n each([INITIAL_REFERRER_INFO, INITIAL_CAMPAIGN_PARAMS], (key) => {\n const initialReferrerInfo = this.props[key]\n if (initialReferrerInfo) {\n each(initialReferrerInfo, function (v, k) {\n p['$initial_' + stripLeadingDollar(k)] = v\n })\n }\n })\n const initialPersonInfo = this.props[INITIAL_PERSON_INFO]\n if (initialPersonInfo) {\n const initialPersonProps = Info.initialPersonPropsFromInfo(initialPersonInfo)\n extend(p, initialPersonProps)\n }\n\n return p\n }\n\n // safely fills the passed in object with stored properties,\n // does not override any properties defined in both\n // returns the passed in object\n\n safe_merge(props: Properties): Properties {\n each(this.props, function (val, prop) {\n if (!(prop in props)) {\n props[prop] = val\n }\n })\n\n return props\n }\n\n update_config(config: PostHogConfig, oldConfig: PostHogConfig): void {\n this.default_expiry = this.expire_days = config['cookie_expiration']\n this.set_disabled(config['disable_persistence'])\n this.set_cross_subdomain(config['cross_subdomain_cookie'])\n this.set_secure(config['secure_cookie'])\n\n if (config.persistence !== oldConfig.persistence) {\n // If the persistence type has changed, we need to migrate the data.\n const newStore = this.buildStorage(config)\n const props = this.props\n\n // clear the old store\n this.clear()\n this.storage = newStore\n this.props = props\n\n this.save()\n }\n }\n\n set_disabled(disabled: boolean): void {\n this.disabled = disabled\n if (this.disabled) {\n this.remove()\n } else {\n this.save()\n }\n }\n\n set_cross_subdomain(cross_subdomain: boolean): void {\n if (cross_subdomain !== this.cross_subdomain) {\n this.cross_subdomain = cross_subdomain\n this.remove()\n this.save()\n }\n }\n\n get_cross_subdomain(): boolean {\n return !!this.cross_subdomain\n }\n\n set_secure(secure: boolean): void {\n if (secure !== this.secure) {\n this.secure = secure\n this.remove()\n this.save()\n }\n }\n\n set_event_timer(event_name: string, timestamp: number): void {\n const timers = this.props[EVENT_TIMERS_KEY] || {}\n timers[event_name] = timestamp\n this.props[EVENT_TIMERS_KEY] = timers\n this.save()\n }\n\n remove_event_timer(event_name: string): number {\n const timers = this.props[EVENT_TIMERS_KEY] || {}\n const timestamp = timers[event_name]\n if (!isUndefined(timestamp)) {\n delete this.props[EVENT_TIMERS_KEY][event_name]\n this.save()\n }\n return timestamp\n }\n\n get_property(prop: string): any {\n return this.props[prop]\n }\n\n set_property(prop: string, to: any): void {\n this.props[prop] = to\n this.save()\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-surveys-types.js","sourceRoot":"","sources":["../../src/posthog-surveys-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoCH,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IAClB,iCAAmB,CAAA;IACnB,yBAAW,CAAA;IACX,+BAAiB,CAAA;AACrB,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB;AAwCD,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC1B,mCAAa,CAAA;IACb,wDAAkC,CAAA;IAClC,oDAA8B,CAAA;IAC9B,uCAAiB,CAAA;IACjB,mCAAa,CAAA;AACjB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B;AAED,MAAM,CAAN,IAAY,2BAKX;AALD,WAAY,2BAA2B;IACnC,6DAA8B,CAAA;IAC9B,0CAAW,CAAA;IACX,+DAAgC,CAAA;IAChC,qEAAsC,CAAA;AAC1C,CAAC,EALW,2BAA2B,KAA3B,2BAA2B,QAKtC","sourcesContent":["/**\n * Having Survey types in types.ts was confusing tsc\n * and generating an invalid module.d.ts\n * See https://github.com/PostHog/posthog-js/issues/698\n */\n\nexport interface SurveyAppearance {\n // keep in sync with frontend/src/types.ts -> SurveyAppearance\n backgroundColor?: string\n submitButtonColor?: string\n // text color is deprecated, use auto contrast text color instead\n textColor?: string\n // deprecate submit button text eventually\n submitButtonText?: string\n descriptionTextColor?: string\n ratingButtonColor?: string\n ratingButtonActiveColor?: string\n ratingButtonHoverColor?: string\n whiteLabel?: boolean\n autoDisappear?: boolean\n displayThankYouMessage?: boolean\n thankYouMessageHeader?: string\n thankYouMessageDescription?: string\n thankYouMessageDescriptionContentType?: SurveyQuestionDescriptionContentType\n thankYouMessageCloseButtonText?: string\n borderColor?: string\n position?: 'left' | 'right' | 'center'\n placeholder?: string\n shuffleQuestions?: boolean\n surveyPopupDelaySeconds?: number\n // widget options\n widgetType?: 'button' | 'tab' | 'selector'\n widgetSelector?: string\n widgetLabel?: string\n widgetColor?: string\n // questionable: Not in frontend/src/types.ts -> SurveyAppearance, but used in site app\n maxWidth?: string\n zIndex?: string\n}\n\nexport enum SurveyType {\n Popover = 'popover',\n API = 'api',\n Widget = 'widget',\n}\n\nexport type SurveyQuestion = BasicSurveyQuestion | LinkSurveyQuestion | RatingSurveyQuestion | MultipleSurveyQuestion\n\nexport type SurveyQuestionDescriptionContentType = 'html' | 'text'\n\ninterface SurveyQuestionBase {\n question: string\n description?: string | null\n descriptionContentType?: SurveyQuestionDescriptionContentType\n optional?: boolean\n buttonText?: string\n originalQuestionIndex: number\n branching?: NextQuestionBranching | EndBranching | ResponseBasedBranching | SpecificQuestionBranching\n}\n\nexport interface BasicSurveyQuestion extends SurveyQuestionBase {\n type: SurveyQuestionType.Open\n}\n\nexport interface LinkSurveyQuestion extends SurveyQuestionBase {\n type: SurveyQuestionType.Link\n link?: string | null\n}\n\nexport interface RatingSurveyQuestion extends SurveyQuestionBase {\n type: SurveyQuestionType.Rating\n display: 'number' | 'emoji'\n scale: 3 | 5 | 7 | 10\n lowerBoundLabel: string\n upperBoundLabel: string\n}\n\nexport interface MultipleSurveyQuestion extends SurveyQuestionBase {\n type: SurveyQuestionType.SingleChoice | SurveyQuestionType.MultipleChoice\n choices: string[]\n hasOpenChoice?: boolean\n shuffleOptions?: boolean\n}\n\nexport enum SurveyQuestionType {\n Open = 'open',\n MultipleChoice = 'multiple_choice',\n SingleChoice = 'single_choice',\n Rating = 'rating',\n Link = 'link',\n}\n\nexport enum SurveyQuestionBranchingType {\n NextQuestion = 'next_question',\n End = 'end',\n ResponseBased = 'response_based',\n SpecificQuestion = 'specific_question',\n}\n\ninterface NextQuestionBranching {\n type: SurveyQuestionBranchingType.NextQuestion\n}\n\ninterface EndBranching {\n type: SurveyQuestionBranchingType.End\n}\n\ninterface ResponseBasedBranching {\n type: SurveyQuestionBranchingType.ResponseBased\n responseValues: Record<string, any>\n}\n\ninterface SpecificQuestionBranching {\n type: SurveyQuestionBranchingType.SpecificQuestion\n index: number\n}\n\nexport interface SurveyResponse {\n surveys: Survey[]\n}\n\nexport type SurveyCallback = (surveys: Survey[]) => void\n\nexport type SurveyUrlMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains'\n\nexport interface SurveyElement {\n text?: string\n $el_text?: string\n tag_name?: string\n href?: string\n attr_id?: string\n attr_class?: string[]\n nth_child?: number\n nth_of_type?: number\n attributes?: Record<string, any>\n event_id?: number\n order?: number\n group_id?: number\n}\nexport interface Survey {\n // Sync this with the backend's SurveyAPISerializer!\n id: string\n name: string\n description: string\n type: SurveyType\n linked_flag_key: string | null\n targeting_flag_key: string | null\n internal_targeting_flag_key: string | null\n questions: SurveyQuestion[]\n appearance: SurveyAppearance | null\n conditions: {\n url?: string\n selector?: string\n seenSurveyWaitPeriodInDays?: number\n urlMatchType?: SurveyUrlMatchType\n events: {\n repeatedActivation?: boolean\n values: {\n name: string\n }[]\n } | null\n actions: {\n values: ActionType[]\n } | null\n } | null\n start_date: string | null\n end_date: string | null\n current_iteration: number | null\n current_iteration_start_date: string | null\n}\n\nexport interface ActionType {\n count?: number\n created_at: string\n deleted?: boolean\n id: number\n name: string | null\n steps?: ActionStepType[]\n tags?: string[]\n is_action?: true\n action_id?: number // alias of id to make it compatible with event definitions uuid\n}\n\n/** Sync with plugin-server/src/types.ts */\nexport type ActionStepStringMatching = 'contains' | 'exact' | 'regex'\n\nexport interface ActionStepType {\n event?: string | null\n selector?: string | null\n /** @deprecated Only `selector` should be used now. */\n tag_name?: string\n text?: string | null\n /** @default StringMatching.Exact */\n text_matching?: ActionStepStringMatching | null\n href?: string | null\n /** @default ActionStepStringMatching.Exact */\n href_matching?: ActionStepStringMatching | null\n url?: string | null\n /** @default StringMatching.Contains */\n url_matching?: ActionStepStringMatching | null\n}\n"]}
|
|
1
|
+
{"version":3,"file":"posthog-surveys-types.js","sourceRoot":"","sources":["../../src/posthog-surveys-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoCH,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IAClB,iCAAmB,CAAA;IACnB,yBAAW,CAAA;IACX,+BAAiB,CAAA;AACrB,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB;AAwCD,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC1B,mCAAa,CAAA;IACb,wDAAkC,CAAA;IAClC,oDAA8B,CAAA;IAC9B,uCAAiB,CAAA;IACjB,mCAAa,CAAA;AACjB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B;AAED,MAAM,CAAN,IAAY,2BAKX;AALD,WAAY,2BAA2B;IACnC,6DAA8B,CAAA;IAC9B,0CAAW,CAAA;IACX,+DAAgC,CAAA;IAChC,qEAAsC,CAAA;AAC1C,CAAC,EALW,2BAA2B,KAA3B,2BAA2B,QAKtC","sourcesContent":["/**\n * Having Survey types in types.ts was confusing tsc\n * and generating an invalid module.d.ts\n * See https://github.com/PostHog/posthog-js/issues/698\n */\n\nexport interface SurveyAppearance {\n // keep in sync with frontend/src/types.ts -> SurveyAppearance\n backgroundColor?: string\n submitButtonColor?: string\n // text color is deprecated, use auto contrast text color instead\n textColor?: string\n // deprecate submit button text eventually\n submitButtonText?: string\n descriptionTextColor?: string\n ratingButtonColor?: string\n ratingButtonActiveColor?: string\n ratingButtonHoverColor?: string\n whiteLabel?: boolean\n autoDisappear?: boolean\n displayThankYouMessage?: boolean\n thankYouMessageHeader?: string\n thankYouMessageDescription?: string\n thankYouMessageDescriptionContentType?: SurveyQuestionDescriptionContentType\n thankYouMessageCloseButtonText?: string\n borderColor?: string\n position?: 'left' | 'right' | 'center'\n placeholder?: string\n shuffleQuestions?: boolean\n surveyPopupDelaySeconds?: number\n // widget options\n widgetType?: 'button' | 'tab' | 'selector'\n widgetSelector?: string\n widgetLabel?: string\n widgetColor?: string\n // questionable: Not in frontend/src/types.ts -> SurveyAppearance, but used in site app\n maxWidth?: string\n zIndex?: string\n}\n\nexport enum SurveyType {\n Popover = 'popover',\n API = 'api',\n Widget = 'widget',\n}\n\nexport type SurveyQuestion = BasicSurveyQuestion | LinkSurveyQuestion | RatingSurveyQuestion | MultipleSurveyQuestion\n\nexport type SurveyQuestionDescriptionContentType = 'html' | 'text'\n\ninterface SurveyQuestionBase {\n question: string\n description?: string | null\n descriptionContentType?: SurveyQuestionDescriptionContentType\n optional?: boolean\n buttonText?: string\n originalQuestionIndex: number\n branching?: NextQuestionBranching | EndBranching | ResponseBasedBranching | SpecificQuestionBranching\n}\n\nexport interface BasicSurveyQuestion extends SurveyQuestionBase {\n type: SurveyQuestionType.Open\n}\n\nexport interface LinkSurveyQuestion extends SurveyQuestionBase {\n type: SurveyQuestionType.Link\n link?: string | null\n}\n\nexport interface RatingSurveyQuestion extends SurveyQuestionBase {\n type: SurveyQuestionType.Rating\n display: 'number' | 'emoji'\n scale: 3 | 5 | 7 | 10\n lowerBoundLabel: string\n upperBoundLabel: string\n}\n\nexport interface MultipleSurveyQuestion extends SurveyQuestionBase {\n type: SurveyQuestionType.SingleChoice | SurveyQuestionType.MultipleChoice\n choices: string[]\n hasOpenChoice?: boolean\n shuffleOptions?: boolean\n}\n\nexport enum SurveyQuestionType {\n Open = 'open',\n MultipleChoice = 'multiple_choice',\n SingleChoice = 'single_choice',\n Rating = 'rating',\n Link = 'link',\n}\n\nexport enum SurveyQuestionBranchingType {\n NextQuestion = 'next_question',\n End = 'end',\n ResponseBased = 'response_based',\n SpecificQuestion = 'specific_question',\n}\n\ninterface NextQuestionBranching {\n type: SurveyQuestionBranchingType.NextQuestion\n}\n\ninterface EndBranching {\n type: SurveyQuestionBranchingType.End\n}\n\ninterface ResponseBasedBranching {\n type: SurveyQuestionBranchingType.ResponseBased\n responseValues: Record<string, any>\n}\n\ninterface SpecificQuestionBranching {\n type: SurveyQuestionBranchingType.SpecificQuestion\n index: number\n}\n\nexport interface SurveyResponse {\n surveys: Survey[]\n}\n\nexport type SurveyCallback = (surveys: Survey[]) => void\n\nexport type SurveyUrlMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains'\n\nexport interface SurveyElement {\n text?: string\n $el_text?: string\n tag_name?: string\n href?: string\n attr_id?: string\n attr_class?: string[]\n nth_child?: number\n nth_of_type?: number\n attributes?: Record<string, any>\n event_id?: number\n order?: number\n group_id?: number\n}\nexport interface SurveyRenderReason {\n visible: boolean\n disabledReason?: string\n}\n\nexport interface Survey {\n // Sync this with the backend's SurveyAPISerializer!\n id: string\n name: string\n description: string\n type: SurveyType\n linked_flag_key: string | null\n targeting_flag_key: string | null\n internal_targeting_flag_key: string | null\n questions: SurveyQuestion[]\n appearance: SurveyAppearance | null\n conditions: {\n url?: string\n selector?: string\n seenSurveyWaitPeriodInDays?: number\n urlMatchType?: SurveyUrlMatchType\n events: {\n repeatedActivation?: boolean\n values: {\n name: string\n }[]\n } | null\n actions: {\n values: ActionType[]\n } | null\n } | null\n start_date: string | null\n end_date: string | null\n current_iteration: number | null\n current_iteration_start_date: string | null\n}\n\nexport interface ActionType {\n count?: number\n created_at: string\n deleted?: boolean\n id: number\n name: string | null\n steps?: ActionStepType[]\n tags?: string[]\n is_action?: true\n action_id?: number // alias of id to make it compatible with event definitions uuid\n}\n\n/** Sync with plugin-server/src/types.ts */\nexport type ActionStepStringMatching = 'contains' | 'exact' | 'regex'\n\nexport interface ActionStepType {\n event?: string | null\n selector?: string | null\n /** @deprecated Only `selector` should be used now. */\n tag_name?: string\n text?: string | null\n /** @default StringMatching.Exact */\n text_matching?: ActionStepStringMatching | null\n href?: string | null\n /** @default ActionStepStringMatching.Exact */\n href_matching?: ActionStepStringMatching | null\n url?: string | null\n /** @default StringMatching.Contains */\n url_matching?: ActionStepStringMatching | null\n}\n"]}
|
|
@@ -7,6 +7,7 @@ export declare class PostHogSurveys {
|
|
|
7
7
|
private readonly instance;
|
|
8
8
|
private _decideServerResponse?;
|
|
9
9
|
_surveyEventReceiver: SurveyEventReceiver | null;
|
|
10
|
+
private _surveyManager;
|
|
10
11
|
constructor(instance: PostHog);
|
|
11
12
|
afterDecideResponse(response: DecideResponse): void;
|
|
12
13
|
loadIfEnabled(): void;
|
|
@@ -14,4 +15,6 @@ export declare class PostHogSurveys {
|
|
|
14
15
|
getActiveMatchingSurveys(callback: SurveyCallback, forceReload?: boolean): void;
|
|
15
16
|
getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null): any;
|
|
16
17
|
private _canActivateRepeatedly;
|
|
18
|
+
canRenderSurvey(surveyId: string): void;
|
|
19
|
+
renderSurvey(surveyId: string, selector: string): void;
|
|
17
20
|
}
|
|
@@ -61,7 +61,7 @@ var PostHogSurveys = /** @class */ (function () {
|
|
|
61
61
|
if (err) {
|
|
62
62
|
return logger.error(LOGGER_PREFIX, 'Could not load surveys script', err);
|
|
63
63
|
}
|
|
64
|
-
assignableWindow.extendPostHogWithSurveys(_this.instance);
|
|
64
|
+
_this._surveyManager = assignableWindow.extendPostHogWithSurveys(_this.instance);
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
};
|
|
@@ -226,6 +226,28 @@ var PostHogSurveys = /** @class */ (function () {
|
|
|
226
226
|
}
|
|
227
227
|
return assignableWindow.__PosthogExtensions__.canActivateRepeatedly(survey);
|
|
228
228
|
};
|
|
229
|
+
PostHogSurveys.prototype.canRenderSurvey = function (surveyId) {
|
|
230
|
+
var _this = this;
|
|
231
|
+
if (isNullish(this._surveyManager)) {
|
|
232
|
+
logger.warn(LOGGER_PREFIX, 'canActivateRepeatedly is not defined, must init before calling');
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
this.getSurveys(function (surveys) {
|
|
236
|
+
var survey = surveys.filter(function (x) { return x.id === surveyId; })[0];
|
|
237
|
+
_this._surveyManager.canRenderSurvey(survey);
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
PostHogSurveys.prototype.renderSurvey = function (surveyId, selector) {
|
|
241
|
+
var _this = this;
|
|
242
|
+
if (isNullish(this._surveyManager)) {
|
|
243
|
+
logger.warn(LOGGER_PREFIX, 'canActivateRepeatedly is not defined, must init before calling');
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
this.getSurveys(function (surveys) {
|
|
247
|
+
var survey = surveys.filter(function (x) { return x.id === surveyId; })[0];
|
|
248
|
+
_this._surveyManager.renderSurvey(survey, document === null || document === void 0 ? void 0 : document.querySelector(selector));
|
|
249
|
+
});
|
|
250
|
+
};
|
|
229
251
|
return PostHogSurveys;
|
|
230
252
|
}());
|
|
231
253
|
export { PostHogSurveys };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-surveys.js","sourceRoot":"","sources":["../../src/posthog-surveys.ts"],"names":[],"mappings":"AACA,OAAO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C,KAAK,CAAC,CAAA;gBAE9E,IAAI,MAAA,MAAA,QAAQ,CAAC,SAAS,0CAAE,cAAc,0CAAE,cAAc,CAAC,YAAY,CAAC,EAAE;oBAClE,IAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;oBAEhE,oBAAoB;oBACpB,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;wBAC5B,OAAO,QAAQ,CAAA;qBAClB;oBAED,IAAI,QAAQ,KAAK,2BAA2B,CAAC,GAAG,EAAE;wBAC9C,OAAO,2BAA2B,CAAC,GAAG,CAAA;qBACzC;oBAED,OAAO,iBAAiB,CAAA;iBAC3B;aACJ;YAED,OAAO,iBAAiB,CAAA;SAC3B;QAED,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,sEAAsE,CAAC,CAAA;QAClG,OAAO,iBAAiB,CAAA;IAC5B,CAAC;IAED,wHAAwH;IAChH,+CAAsB,GAA9B,UAA+B,MAAc;QACzC,IAAI,SAAS,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,qBAAqB,CAAC,EAAE;YACzE,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,gEAAgE,CAAC,CAAA;SAC/F;QACD,OAAO,gBAAgB,CAAC,qBAAqB,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;IAC/E,CAAC;IACL,qBAAC;AAAD,CAAC,AA1ND,IA0NC","sourcesContent":["import { PostHog } from './posthog-core'\nimport { SURVEYS } from './constants'\nimport {\n Survey,\n SurveyCallback,\n SurveyQuestionBranchingType,\n SurveyQuestionType,\n SurveyUrlMatchType,\n} from './posthog-surveys-types'\nimport { isUrlMatchingRegex } from './utils/request-utils'\nimport { SurveyEventReceiver } from './utils/survey-event-receiver'\nimport { assignableWindow, document, window } from './utils/globals'\nimport { DecideResponse } from './types'\nimport { logger } from './utils/logger'\nimport { isNullish } from './utils/type-utils'\n\nconst LOGGER_PREFIX = '[Surveys]'\n\nexport const surveyUrlValidationMap: Record<SurveyUrlMatchType, (conditionsUrl: string) => boolean> = {\n icontains: (conditionsUrl) =>\n !!window && window.location.href.toLowerCase().indexOf(conditionsUrl.toLowerCase()) > -1,\n not_icontains: (conditionsUrl) =>\n !!window && window.location.href.toLowerCase().indexOf(conditionsUrl.toLowerCase()) === -1,\n regex: (conditionsUrl) => !!window && isUrlMatchingRegex(window.location.href, conditionsUrl),\n not_regex: (conditionsUrl) => !!window && !isUrlMatchingRegex(window.location.href, conditionsUrl),\n exact: (conditionsUrl) => window?.location.href === conditionsUrl,\n is_not: (conditionsUrl) => window?.location.href !== conditionsUrl,\n}\n\nfunction getRatingBucketForResponseValue(responseValue: number, scale: number) {\n if (scale === 3) {\n if (responseValue < 1 || responseValue > 3) {\n throw new Error('The response must be in range 1-3')\n }\n\n return responseValue === 1 ? 'negative' : responseValue === 2 ? 'neutral' : 'positive'\n } else if (scale === 5) {\n if (responseValue < 1 || responseValue > 5) {\n throw new Error('The response must be in range 1-5')\n }\n\n return responseValue <= 2 ? 'negative' : responseValue === 3 ? 'neutral' : 'positive'\n } else if (scale === 10) {\n if (responseValue < 0 || responseValue > 10) {\n throw new Error('The response must be in range 0-10')\n }\n\n return responseValue <= 6 ? 'detractors' : responseValue <= 8 ? 'passives' : 'promoters'\n }\n\n throw new Error('The scale must be one of: 3, 5, 10')\n}\n\nexport class PostHogSurveys {\n private _decideServerResponse?: boolean\n public _surveyEventReceiver: SurveyEventReceiver | null\n\n constructor(private readonly instance: PostHog) {\n // we set this to undefined here because we need the persistence storage for this type\n // but that's not initialized until loadIfEnabled is called.\n this._surveyEventReceiver = null\n }\n\n afterDecideResponse(response: DecideResponse) {\n this._decideServerResponse = !!response['surveys']\n this.loadIfEnabled()\n }\n\n loadIfEnabled() {\n const surveysGenerator = assignableWindow?.extendPostHogWithSurveys\n\n if (!this.instance.config.disable_surveys && this._decideServerResponse && !surveysGenerator) {\n if (this._surveyEventReceiver == null) {\n this._surveyEventReceiver = new SurveyEventReceiver(this.instance)\n }\n this.instance.requestRouter.loadScript('/static/surveys.js', (err) => {\n if (err) {\n return logger.error(LOGGER_PREFIX, 'Could not load surveys script', err)\n }\n\n assignableWindow.extendPostHogWithSurveys(this.instance)\n })\n }\n }\n\n getSurveys(callback: SurveyCallback, forceReload = false) {\n // In case we manage to load the surveys script, but config says not to load surveys\n // then we shouldn't return survey data\n if (this.instance.config.disable_surveys) {\n return callback([])\n }\n\n if (this._surveyEventReceiver == null) {\n this._surveyEventReceiver = new SurveyEventReceiver(this.instance)\n }\n\n const existingSurveys = this.instance.get_property(SURVEYS)\n if (!existingSurveys || forceReload) {\n this.instance._send_request({\n url: this.instance.requestRouter.endpointFor(\n 'api',\n `/api/surveys/?token=${this.instance.config.token}`\n ),\n method: 'GET',\n transport: 'XHR',\n callback: (response) => {\n if (response.statusCode !== 200 || !response.json) {\n return callback([])\n }\n const surveys = response.json.surveys || []\n\n const eventOrActionBasedSurveys = surveys.filter(\n (survey: Survey) =>\n (survey.conditions?.events &&\n survey.conditions?.events?.values &&\n survey.conditions?.events?.values?.length > 0) ||\n (survey.conditions?.actions &&\n survey.conditions?.actions?.values &&\n survey.conditions?.actions?.values?.length > 0)\n )\n\n if (eventOrActionBasedSurveys.length > 0) {\n this._surveyEventReceiver?.register(eventOrActionBasedSurveys)\n }\n\n this.instance.persistence?.register({ [SURVEYS]: surveys })\n return callback(surveys)\n },\n })\n } else {\n return callback(existingSurveys)\n }\n }\n\n getActiveMatchingSurveys(callback: SurveyCallback, forceReload = false) {\n this.getSurveys((surveys) => {\n const activeSurveys = surveys.filter((survey) => {\n return !!(survey.start_date && !survey.end_date)\n })\n\n const conditionMatchedSurveys = activeSurveys.filter((survey) => {\n if (!survey.conditions) {\n return true\n }\n\n // use urlMatchType to validate url condition, fallback to contains for backwards compatibility\n const urlCheck = survey.conditions?.url\n ? surveyUrlValidationMap[survey.conditions?.urlMatchType ?? 'icontains'](survey.conditions.url)\n : true\n const selectorCheck = survey.conditions?.selector\n ? document?.querySelector(survey.conditions.selector)\n : true\n return urlCheck && selectorCheck\n })\n\n // get all the surveys that have been activated so far with user actions.\n const activatedSurveys: string[] | undefined = this._surveyEventReceiver?.getSurveys()\n const targetingMatchedSurveys = conditionMatchedSurveys.filter((survey) => {\n if (!survey.linked_flag_key && !survey.targeting_flag_key && !survey.internal_targeting_flag_key) {\n return true\n }\n const linkedFlagCheck = survey.linked_flag_key\n ? this.instance.featureFlags.isFeatureEnabled(survey.linked_flag_key)\n : true\n const targetingFlagCheck = survey.targeting_flag_key\n ? this.instance.featureFlags.isFeatureEnabled(survey.targeting_flag_key)\n : true\n\n const hasEvents =\n survey.conditions?.events &&\n survey.conditions?.events?.values &&\n survey.conditions?.events?.values.length > 0\n\n const hasActions =\n survey.conditions?.actions &&\n survey.conditions?.actions?.values &&\n survey.conditions?.actions?.values.length > 0\n const eventBasedTargetingFlagCheck =\n hasEvents || hasActions ? activatedSurveys?.includes(survey.id) : true\n\n const overrideInternalTargetingFlagCheck = this._canActivateRepeatedly(survey)\n const internalTargetingFlagCheck =\n survey.internal_targeting_flag_key && !overrideInternalTargetingFlagCheck\n ? this.instance.featureFlags.isFeatureEnabled(survey.internal_targeting_flag_key)\n : true\n\n return (\n linkedFlagCheck && targetingFlagCheck && internalTargetingFlagCheck && eventBasedTargetingFlagCheck\n )\n })\n\n return callback(targetingMatchedSurveys)\n }, forceReload)\n }\n\n getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null) {\n const question = survey.questions[currentQuestionIndex]\n const nextQuestionIndex = currentQuestionIndex + 1\n\n if (!question.branching?.type) {\n if (currentQuestionIndex === survey.questions.length - 1) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n\n if (question.branching.type === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n } else if (question.branching.type === SurveyQuestionBranchingType.SpecificQuestion) {\n if (Number.isInteger(question.branching.index)) {\n return question.branching.index\n }\n } else if (question.branching.type === SurveyQuestionBranchingType.ResponseBased) {\n // Single choice\n if (question.type === SurveyQuestionType.SingleChoice) {\n // :KLUDGE: for now, look up the choiceIndex based on the response\n // TODO: once QuestionTypes.MultipleChoiceQuestion is refactored, pass the selected choiceIndex into this method\n const selectedChoiceIndex = question.choices.indexOf(`${response}`)\n\n if (question.branching?.responseValues?.hasOwnProperty(selectedChoiceIndex)) {\n const nextStep = question.branching.responseValues[selectedChoiceIndex]\n\n // Specific question\n if (Number.isInteger(nextStep)) {\n return nextStep\n }\n\n if (nextStep === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n } else if (question.type === SurveyQuestionType.Rating) {\n if (typeof response !== 'number' || !Number.isInteger(response)) {\n throw new Error('The response type must be an integer')\n }\n\n const ratingBucket = getRatingBucketForResponseValue(response, question.scale)\n\n if (question.branching?.responseValues?.hasOwnProperty(ratingBucket)) {\n const nextStep = question.branching.responseValues[ratingBucket]\n\n // Specific question\n if (Number.isInteger(nextStep)) {\n return nextStep\n }\n\n if (nextStep === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n }\n\n return nextQuestionIndex\n }\n\n logger.warn(LOGGER_PREFIX, 'Falling back to next question index due to unexpected branching type')\n return nextQuestionIndex\n }\n\n // this method is lazily loaded onto the window to avoid loading preact and other dependencies if surveys is not enabled\n private _canActivateRepeatedly(survey: Survey) {\n if (isNullish(assignableWindow.__PosthogExtensions__.canActivateRepeatedly)) {\n logger.warn(LOGGER_PREFIX, 'canActivateRepeatedly is not defined, must init before calling')\n }\n return assignableWindow.__PosthogExtensions__.canActivateRepeatedly(survey)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"posthog-surveys.js","sourceRoot":"","sources":["../../src/posthog-surveys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAGH,2BAA2B,EAC3B,kBAAkB,GAErB,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C,CAAC,CAAC,CAAA;IACN,CAAC;IAED,qCAAY,GAAZ,UAAa,QAAgB,EAAE,QAAgB;QAA/C,iBAUC;QATG,IAAI,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;YAChC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,gEAAgE,CAAC,CAAA;YAC5F,OAAM;SACT;QACD,IAAI,CAAC,UAAU,CAAC,UAAC,OAAO;YACpB,IAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,EAAE,KAAK,QAAQ,EAAjB,CAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;YAE1D,KAAI,CAAC,cAAc,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAA;QAC/E,CAAC,CAAC,CAAA;IACN,CAAC;IACL,qBAAC;AAAD,CAAC,AAnPD,IAmPC","sourcesContent":["import { PostHog } from './posthog-core'\nimport { SURVEYS } from './constants'\nimport {\n Survey,\n SurveyCallback,\n SurveyQuestionBranchingType,\n SurveyQuestionType,\n SurveyUrlMatchType,\n} from './posthog-surveys-types'\nimport { isUrlMatchingRegex } from './utils/request-utils'\nimport { SurveyEventReceiver } from './utils/survey-event-receiver'\nimport { assignableWindow, document, window } from './utils/globals'\nimport { DecideResponse } from './types'\nimport { logger } from './utils/logger'\nimport { isNullish } from './utils/type-utils'\n\nconst LOGGER_PREFIX = '[Surveys]'\n\nexport const surveyUrlValidationMap: Record<SurveyUrlMatchType, (conditionsUrl: string) => boolean> = {\n icontains: (conditionsUrl) =>\n !!window && window.location.href.toLowerCase().indexOf(conditionsUrl.toLowerCase()) > -1,\n not_icontains: (conditionsUrl) =>\n !!window && window.location.href.toLowerCase().indexOf(conditionsUrl.toLowerCase()) === -1,\n regex: (conditionsUrl) => !!window && isUrlMatchingRegex(window.location.href, conditionsUrl),\n not_regex: (conditionsUrl) => !!window && !isUrlMatchingRegex(window.location.href, conditionsUrl),\n exact: (conditionsUrl) => window?.location.href === conditionsUrl,\n is_not: (conditionsUrl) => window?.location.href !== conditionsUrl,\n}\n\nfunction getRatingBucketForResponseValue(responseValue: number, scale: number) {\n if (scale === 3) {\n if (responseValue < 1 || responseValue > 3) {\n throw new Error('The response must be in range 1-3')\n }\n\n return responseValue === 1 ? 'negative' : responseValue === 2 ? 'neutral' : 'positive'\n } else if (scale === 5) {\n if (responseValue < 1 || responseValue > 5) {\n throw new Error('The response must be in range 1-5')\n }\n\n return responseValue <= 2 ? 'negative' : responseValue === 3 ? 'neutral' : 'positive'\n } else if (scale === 10) {\n if (responseValue < 0 || responseValue > 10) {\n throw new Error('The response must be in range 0-10')\n }\n\n return responseValue <= 6 ? 'detractors' : responseValue <= 8 ? 'passives' : 'promoters'\n }\n\n throw new Error('The scale must be one of: 3, 5, 10')\n}\n\nexport class PostHogSurveys {\n private _decideServerResponse?: boolean\n public _surveyEventReceiver: SurveyEventReceiver | null\n private _surveyManager: any\n\n constructor(private readonly instance: PostHog) {\n // we set this to undefined here because we need the persistence storage for this type\n // but that's not initialized until loadIfEnabled is called.\n this._surveyEventReceiver = null\n }\n\n afterDecideResponse(response: DecideResponse) {\n this._decideServerResponse = !!response['surveys']\n this.loadIfEnabled()\n }\n\n loadIfEnabled() {\n const surveysGenerator = assignableWindow?.extendPostHogWithSurveys\n\n if (!this.instance.config.disable_surveys && this._decideServerResponse && !surveysGenerator) {\n if (this._surveyEventReceiver == null) {\n this._surveyEventReceiver = new SurveyEventReceiver(this.instance)\n }\n this.instance.requestRouter.loadScript('/static/surveys.js', (err) => {\n if (err) {\n return logger.error(LOGGER_PREFIX, 'Could not load surveys script', err)\n }\n\n this._surveyManager = assignableWindow.extendPostHogWithSurveys(this.instance)\n })\n }\n }\n\n getSurveys(callback: SurveyCallback, forceReload = false) {\n // In case we manage to load the surveys script, but config says not to load surveys\n // then we shouldn't return survey data\n if (this.instance.config.disable_surveys) {\n return callback([])\n }\n\n if (this._surveyEventReceiver == null) {\n this._surveyEventReceiver = new SurveyEventReceiver(this.instance)\n }\n\n const existingSurveys = this.instance.get_property(SURVEYS)\n if (!existingSurveys || forceReload) {\n this.instance._send_request({\n url: this.instance.requestRouter.endpointFor(\n 'api',\n `/api/surveys/?token=${this.instance.config.token}`\n ),\n method: 'GET',\n transport: 'XHR',\n callback: (response) => {\n if (response.statusCode !== 200 || !response.json) {\n return callback([])\n }\n const surveys = response.json.surveys || []\n\n const eventOrActionBasedSurveys = surveys.filter(\n (survey: Survey) =>\n (survey.conditions?.events &&\n survey.conditions?.events?.values &&\n survey.conditions?.events?.values?.length > 0) ||\n (survey.conditions?.actions &&\n survey.conditions?.actions?.values &&\n survey.conditions?.actions?.values?.length > 0)\n )\n\n if (eventOrActionBasedSurveys.length > 0) {\n this._surveyEventReceiver?.register(eventOrActionBasedSurveys)\n }\n\n this.instance.persistence?.register({ [SURVEYS]: surveys })\n return callback(surveys)\n },\n })\n } else {\n return callback(existingSurveys)\n }\n }\n\n getActiveMatchingSurveys(callback: SurveyCallback, forceReload = false) {\n this.getSurveys((surveys) => {\n const activeSurveys = surveys.filter((survey) => {\n return !!(survey.start_date && !survey.end_date)\n })\n\n const conditionMatchedSurveys = activeSurveys.filter((survey) => {\n if (!survey.conditions) {\n return true\n }\n\n // use urlMatchType to validate url condition, fallback to contains for backwards compatibility\n const urlCheck = survey.conditions?.url\n ? surveyUrlValidationMap[survey.conditions?.urlMatchType ?? 'icontains'](survey.conditions.url)\n : true\n const selectorCheck = survey.conditions?.selector\n ? document?.querySelector(survey.conditions.selector)\n : true\n return urlCheck && selectorCheck\n })\n\n // get all the surveys that have been activated so far with user actions.\n const activatedSurveys: string[] | undefined = this._surveyEventReceiver?.getSurveys()\n const targetingMatchedSurveys = conditionMatchedSurveys.filter((survey) => {\n if (!survey.linked_flag_key && !survey.targeting_flag_key && !survey.internal_targeting_flag_key) {\n return true\n }\n const linkedFlagCheck = survey.linked_flag_key\n ? this.instance.featureFlags.isFeatureEnabled(survey.linked_flag_key)\n : true\n const targetingFlagCheck = survey.targeting_flag_key\n ? this.instance.featureFlags.isFeatureEnabled(survey.targeting_flag_key)\n : true\n\n const hasEvents =\n survey.conditions?.events &&\n survey.conditions?.events?.values &&\n survey.conditions?.events?.values.length > 0\n\n const hasActions =\n survey.conditions?.actions &&\n survey.conditions?.actions?.values &&\n survey.conditions?.actions?.values.length > 0\n const eventBasedTargetingFlagCheck =\n hasEvents || hasActions ? activatedSurveys?.includes(survey.id) : true\n\n const overrideInternalTargetingFlagCheck = this._canActivateRepeatedly(survey)\n const internalTargetingFlagCheck =\n survey.internal_targeting_flag_key && !overrideInternalTargetingFlagCheck\n ? this.instance.featureFlags.isFeatureEnabled(survey.internal_targeting_flag_key)\n : true\n\n return (\n linkedFlagCheck && targetingFlagCheck && internalTargetingFlagCheck && eventBasedTargetingFlagCheck\n )\n })\n\n return callback(targetingMatchedSurveys)\n }, forceReload)\n }\n\n getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null) {\n const question = survey.questions[currentQuestionIndex]\n const nextQuestionIndex = currentQuestionIndex + 1\n\n if (!question.branching?.type) {\n if (currentQuestionIndex === survey.questions.length - 1) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n\n if (question.branching.type === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n } else if (question.branching.type === SurveyQuestionBranchingType.SpecificQuestion) {\n if (Number.isInteger(question.branching.index)) {\n return question.branching.index\n }\n } else if (question.branching.type === SurveyQuestionBranchingType.ResponseBased) {\n // Single choice\n if (question.type === SurveyQuestionType.SingleChoice) {\n // :KLUDGE: for now, look up the choiceIndex based on the response\n // TODO: once QuestionTypes.MultipleChoiceQuestion is refactored, pass the selected choiceIndex into this method\n const selectedChoiceIndex = question.choices.indexOf(`${response}`)\n\n if (question.branching?.responseValues?.hasOwnProperty(selectedChoiceIndex)) {\n const nextStep = question.branching.responseValues[selectedChoiceIndex]\n\n // Specific question\n if (Number.isInteger(nextStep)) {\n return nextStep\n }\n\n if (nextStep === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n } else if (question.type === SurveyQuestionType.Rating) {\n if (typeof response !== 'number' || !Number.isInteger(response)) {\n throw new Error('The response type must be an integer')\n }\n\n const ratingBucket = getRatingBucketForResponseValue(response, question.scale)\n\n if (question.branching?.responseValues?.hasOwnProperty(ratingBucket)) {\n const nextStep = question.branching.responseValues[ratingBucket]\n\n // Specific question\n if (Number.isInteger(nextStep)) {\n return nextStep\n }\n\n if (nextStep === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n }\n\n return nextQuestionIndex\n }\n\n logger.warn(LOGGER_PREFIX, 'Falling back to next question index due to unexpected branching type')\n return nextQuestionIndex\n }\n\n // this method is lazily loaded onto the window to avoid loading preact and other dependencies if surveys is not enabled\n private _canActivateRepeatedly(survey: Survey) {\n if (isNullish(assignableWindow.__PosthogExtensions__.canActivateRepeatedly)) {\n logger.warn(LOGGER_PREFIX, 'canActivateRepeatedly is not defined, must init before calling')\n }\n return assignableWindow.__PosthogExtensions__.canActivateRepeatedly(survey)\n }\n\n canRenderSurvey(surveyId: string) {\n if (isNullish(this._surveyManager)) {\n logger.warn(LOGGER_PREFIX, 'canActivateRepeatedly is not defined, must init before calling')\n return\n }\n this.getSurveys((surveys) => {\n const survey = surveys.filter((x) => x.id === surveyId)[0]\n\n this._surveyManager.canRenderSurvey(survey)\n })\n }\n\n renderSurvey(surveyId: string, selector: string) {\n if (isNullish(this._surveyManager)) {\n logger.warn(LOGGER_PREFIX, 'canActivateRepeatedly is not defined, must init before calling')\n return\n }\n this.getSurveys((surveys) => {\n const survey = surveys.filter((x) => x.id === surveyId)[0]\n\n this._surveyManager.renderSurvey(survey, document?.querySelector(selector))\n })\n }\n}\n"]}
|
package/lib/src/storage.js
CHANGED
|
@@ -118,7 +118,7 @@ export var cookieStore = {
|
|
|
118
118
|
}
|
|
119
119
|
return cookie;
|
|
120
120
|
},
|
|
121
|
-
set: function (name, value, days, cross_subdomain, is_secure) {
|
|
121
|
+
set: function (name, value, days, cross_subdomain, is_secure, debug) {
|
|
122
122
|
if (!document) {
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
@@ -144,6 +144,9 @@ export var cookieStore = {
|
|
|
144
144
|
if (new_cookie_val.length > 4096 * 0.9) {
|
|
145
145
|
logger.warn('cookieStore warning: large cookie, len=' + new_cookie_val.length);
|
|
146
146
|
}
|
|
147
|
+
if (debug) {
|
|
148
|
+
logger.info('cookie set', new_cookie_val);
|
|
149
|
+
}
|
|
147
150
|
document.cookie = new_cookie_val;
|
|
148
151
|
return new_cookie_val;
|
|
149
152
|
}
|
|
@@ -210,8 +213,11 @@ export var localStore = {
|
|
|
210
213
|
}
|
|
211
214
|
return null;
|
|
212
215
|
},
|
|
213
|
-
set: function (name, value) {
|
|
216
|
+
set: function (name, value, _days, _cross_subdomain, _secure, debug) {
|
|
214
217
|
try {
|
|
218
|
+
if (debug) {
|
|
219
|
+
logger.info('localStorage set', name, value);
|
|
220
|
+
}
|
|
215
221
|
window === null || window === void 0 ? void 0 : window.localStorage.setItem(name, JSON.stringify(value));
|
|
216
222
|
}
|
|
217
223
|
catch (err) {
|
|
@@ -247,9 +253,9 @@ export var localPlusCookieStore = __assign(__assign({}, localStore), { parse: fu
|
|
|
247
253
|
// noop
|
|
248
254
|
}
|
|
249
255
|
return null;
|
|
250
|
-
}, set: function (name, value, days, cross_subdomain, is_secure) {
|
|
256
|
+
}, set: function (name, value, days, cross_subdomain, is_secure, debug) {
|
|
251
257
|
try {
|
|
252
|
-
localStore.set(name, value);
|
|
258
|
+
localStore.set(name, value, undefined, undefined, debug);
|
|
253
259
|
var cookiePersistedProperties_1 = {};
|
|
254
260
|
COOKIE_PERSISTED_PROPERTIES.forEach(function (key) {
|
|
255
261
|
if (value[key]) {
|
|
@@ -257,7 +263,7 @@ export var localPlusCookieStore = __assign(__assign({}, localStore), { parse: fu
|
|
|
257
263
|
}
|
|
258
264
|
});
|
|
259
265
|
if (Object.keys(cookiePersistedProperties_1).length) {
|
|
260
|
-
cookieStore.set(name, cookiePersistedProperties_1, days, cross_subdomain, is_secure);
|
|
266
|
+
cookieStore.set(name, cookiePersistedProperties_1, days, cross_subdomain, is_secure, debug);
|
|
261
267
|
}
|
|
262
268
|
}
|
|
263
269
|
catch (err) {
|
|
@@ -344,8 +350,11 @@ export var sessionStore = {
|
|
|
344
350
|
}
|
|
345
351
|
return null;
|
|
346
352
|
},
|
|
347
|
-
set: function (name, value) {
|
|
353
|
+
set: function (name, value, _days, _cross_subdomain, _secure, debug) {
|
|
348
354
|
try {
|
|
355
|
+
if (debug) {
|
|
356
|
+
logger.info('sessionStorage set', name, value);
|
|
357
|
+
}
|
|
349
358
|
window === null || window === void 0 ? void 0 : window.sessionStorage.setItem(name, JSON.stringify(value));
|
|
350
359
|
}
|
|
351
360
|
catch (err) {
|
package/lib/src/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhC,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,UAAU,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAE7G,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,IAAM,KAAK,GAAG,+BAA+B,CAAA;AAC7C,sFAAsF;AACtF,IAAI,uBAAuB,GAAG,EAAE,CAAA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9C;QAAC,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAC1B;QACD,OAAO,IAAI,CAAA;IACf,CAAC;IAED,KAAK,EAAE,UAAU,IAAI;QACjB,IAAI;YACA,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAA;SACpD;QAAC,OAAO,GAAG,EAAE;YACV,OAAO;SACV;QACD,OAAO,IAAI,CAAA;IACf,CAAC;IAED,GAAG,EAAE,UAAU,IAAI,EAAE,KAAK;QACtB,IAAI;YACA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;SAC9D;QAAC,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAC1B;IACL,CAAC;IAED,MAAM,EAAE,UAAU,IAAI;QAClB,IAAI;YACA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;SAC1C;QAAC,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAC1B;IACL,CAAC;CACJ,CAAA","sourcesContent":["import { extend } from './utils'\nimport { PersistentStore, Properties } from './types'\nimport { DISTINCT_ID, ENABLE_PERSON_PROCESSING, SESSION_ID, SESSION_RECORDING_IS_SAMPLED } from './constants'\n\nimport { isNull, isUndefined } from './utils/type-utils'\nimport { logger } from './utils/logger'\nimport { window, document } from './utils/globals'\nimport { uuidv7 } from './uuidv7'\n\nconst Y1970 = 'Thu, 01 Jan 1970 00:00:00 GMT'\n// we store the discovered subdomain in memory because it might be read multiple times\nlet firstNonPublicSubDomain = ''\n\n// helper to allow tests to clear this \"cache\"\nexport const resetSubDomainCache = () => {\n firstNonPublicSubDomain = ''\n}\n\n/**\n * Browsers don't offer a way to check if something is a public suffix\n * e.g. `.com.au`, `.io`, `.org.uk`\n *\n * But they do reject cookies set on public suffixes\n * Setting a cookie on `.co.uk` would mean it was sent for every `.co.uk` site visited\n *\n * So, we can use this to check if a domain is a public suffix\n * by trying to set a cookie on a subdomain of the provided hostname\n * until the browser accepts it\n *\n * inspired by https://github.com/AngusFu/browser-root-domain\n */\nexport function seekFirstNonPublicSubDomain(hostname: string, cookieJar = document): string {\n if (firstNonPublicSubDomain) {\n return firstNonPublicSubDomain\n }\n\n if (!cookieJar) {\n return ''\n }\n if (['localhost', '127.0.0.1'].includes(hostname)) return ''\n\n const list = hostname.split('.')\n let len = Math.min(list.length, 8) // paranoia - we know this number should be small\n const key = 'dmn_chk_' + uuidv7()\n const R = new RegExp('(^|;)\\\\s*' + key + '=1')\n\n while (!firstNonPublicSubDomain && len--) {\n const candidate = list.slice(len).join('.')\n const candidateCookieValue = key + '=1;domain=.' + candidate\n\n // try to set cookie\n cookieJar.cookie = candidateCookieValue\n\n if (R.test(cookieJar.cookie)) {\n // the cookie was accepted by the browser, remove the test cookie\n cookieJar.cookie = candidateCookieValue + ';expires=' + Y1970\n firstNonPublicSubDomain = candidate\n }\n }\n\n return firstNonPublicSubDomain\n}\n\nconst DOMAIN_MATCH_REGEX = /[a-z0-9][a-z0-9-]+\\.[a-z]{2,}$/i\nconst originalCookieDomainFn = (hostname: string): string => {\n const matches = hostname.match(DOMAIN_MATCH_REGEX)\n return matches ? matches[0] : ''\n}\n\nexport function chooseCookieDomain(hostname: string, cross_subdomain: boolean | undefined): string {\n if (cross_subdomain) {\n // NOTE: Could we use this for cross domain tracking?\n let matchedSubDomain = seekFirstNonPublicSubDomain(hostname)\n\n if (!matchedSubDomain) {\n const originalMatch = originalCookieDomainFn(hostname)\n if (originalMatch !== matchedSubDomain) {\n logger.info('Warning: cookie subdomain discovery mismatch', originalMatch, matchedSubDomain)\n }\n matchedSubDomain = originalMatch\n }\n\n return matchedSubDomain ? '; domain=.' + matchedSubDomain : ''\n }\n return ''\n}\n\n// Methods partially borrowed from quirksmode.org/js/cookies.html\nexport const cookieStore: PersistentStore = {\n is_supported: () => !!document,\n\n error: function (msg) {\n logger.error('cookieStore error: ' + msg)\n },\n\n get: function (name) {\n if (!document) {\n return\n }\n\n try {\n const nameEQ = name + '='\n const ca = document.cookie.split(';').filter((x) => x.length)\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i]\n while (c.charAt(0) == ' ') {\n c = c.substring(1, c.length)\n }\n if (c.indexOf(nameEQ) === 0) {\n return decodeURIComponent(c.substring(nameEQ.length, c.length))\n }\n }\n } catch (err) {}\n return null\n },\n\n parse: function (name) {\n let cookie\n try {\n cookie = JSON.parse(cookieStore.get(name)) || {}\n } catch (err) {\n // noop\n }\n return cookie\n },\n\n set: function (name, value, days, cross_subdomain, is_secure) {\n if (!document) {\n return\n }\n try {\n let expires = '',\n secure = ''\n\n const cdomain = chooseCookieDomain(document.location.hostname, cross_subdomain)\n\n if (days) {\n const date = new Date()\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000)\n expires = '; expires=' + date.toUTCString()\n }\n\n if (is_secure) {\n secure = '; secure'\n }\n\n const new_cookie_val =\n name +\n '=' +\n encodeURIComponent(JSON.stringify(value)) +\n expires +\n '; SameSite=Lax; path=/' +\n cdomain +\n secure\n\n // 4096 bytes is the size at which some browsers (e.g. firefox) will not store a cookie, warn slightly before that\n if (new_cookie_val.length > 4096 * 0.9) {\n logger.warn('cookieStore warning: large cookie, len=' + new_cookie_val.length)\n }\n\n document.cookie = new_cookie_val\n return new_cookie_val\n } catch (err) {\n return\n }\n },\n\n remove: function (name, cross_subdomain) {\n try {\n cookieStore.set(name, '', -1, cross_subdomain)\n } catch (err) {\n return\n }\n },\n}\n\nlet _localStorage_supported: boolean | null = null\n\nexport const localStore: PersistentStore = {\n is_supported: function () {\n if (!isNull(_localStorage_supported)) {\n return _localStorage_supported\n }\n\n let supported = true\n if (!isUndefined(window)) {\n try {\n const key = '__mplssupport__',\n val = 'xyz'\n localStore.set(key, val)\n if (localStore.get(key) !== '\"xyz\"') {\n supported = false\n }\n localStore.remove(key)\n } catch (err) {\n supported = false\n }\n } else {\n supported = false\n }\n if (!supported) {\n logger.error('localStorage unsupported; falling back to cookie store')\n }\n\n _localStorage_supported = supported\n return supported\n },\n\n error: function (msg) {\n logger.error('localStorage error: ' + msg)\n },\n\n get: function (name) {\n try {\n return window?.localStorage.getItem(name)\n } catch (err) {\n localStore.error(err)\n }\n return null\n },\n\n parse: function (name) {\n try {\n return JSON.parse(localStore.get(name)) || {}\n } catch (err) {\n // noop\n }\n return null\n },\n\n set: function (name, value) {\n try {\n window?.localStorage.setItem(name, JSON.stringify(value))\n } catch (err) {\n localStore.error(err)\n }\n },\n\n remove: function (name) {\n try {\n window?.localStorage.removeItem(name)\n } catch (err) {\n localStore.error(err)\n }\n },\n}\n\n// Use localstorage for most data but still use cookie for COOKIE_PERSISTED_PROPERTIES\n// This solves issues with cookies having too much data in them causing headers too large\n// Also makes sure we don't have to send a ton of data to the server\nconst COOKIE_PERSISTED_PROPERTIES = [DISTINCT_ID, SESSION_ID, SESSION_RECORDING_IS_SAMPLED, ENABLE_PERSON_PROCESSING]\n\nexport const localPlusCookieStore: PersistentStore = {\n ...localStore,\n parse: function (name) {\n try {\n let cookieProperties: Properties = {}\n try {\n // See if there's a cookie stored with data.\n cookieProperties = cookieStore.parse(name) || {}\n } catch (err) {}\n const value = extend(cookieProperties, JSON.parse(localStore.get(name) || '{}'))\n localStore.set(name, value)\n return value\n } catch (err) {\n // noop\n }\n return null\n },\n\n set: function (name, value, days, cross_subdomain, is_secure) {\n try {\n localStore.set(name, value)\n const cookiePersistedProperties: Record<string, any> = {}\n COOKIE_PERSISTED_PROPERTIES.forEach((key) => {\n if (value[key]) {\n cookiePersistedProperties[key] = value[key]\n }\n })\n\n if (Object.keys(cookiePersistedProperties).length) {\n cookieStore.set(name, cookiePersistedProperties, days, cross_subdomain, is_secure)\n }\n } catch (err) {\n localStore.error(err)\n }\n },\n\n remove: function (name, cross_subdomain) {\n try {\n window?.localStorage.removeItem(name)\n cookieStore.remove(name, cross_subdomain)\n } catch (err) {\n localStore.error(err)\n }\n },\n}\n\nconst memoryStorage: Properties = {}\n\n// Storage that only lasts the length of the pageview if we don't want to use cookies\nexport const memoryStore: PersistentStore = {\n is_supported: function () {\n return true\n },\n\n error: function (msg) {\n logger.error('memoryStorage error: ' + msg)\n },\n\n get: function (name) {\n return memoryStorage[name] || null\n },\n\n parse: function (name) {\n return memoryStorage[name] || null\n },\n\n set: function (name, value) {\n memoryStorage[name] = value\n },\n\n remove: function (name) {\n delete memoryStorage[name]\n },\n}\n\nlet sessionStorageSupported: boolean | null = null\nexport const resetSessionStorageSupported = () => {\n sessionStorageSupported = null\n}\n// Storage that only lasts the length of a tab/window. Survives page refreshes\nexport const sessionStore: PersistentStore = {\n is_supported: function () {\n if (!isNull(sessionStorageSupported)) {\n return sessionStorageSupported\n }\n sessionStorageSupported = true\n if (!isUndefined(window)) {\n try {\n const key = '__support__',\n val = 'xyz'\n sessionStore.set(key, val)\n if (sessionStore.get(key) !== '\"xyz\"') {\n sessionStorageSupported = false\n }\n sessionStore.remove(key)\n } catch (err) {\n sessionStorageSupported = false\n }\n } else {\n sessionStorageSupported = false\n }\n return sessionStorageSupported\n },\n\n error: function (msg) {\n logger.error('sessionStorage error: ', msg)\n },\n\n get: function (name) {\n try {\n return window?.sessionStorage.getItem(name)\n } catch (err) {\n sessionStore.error(err)\n }\n return null\n },\n\n parse: function (name) {\n try {\n return JSON.parse(sessionStore.get(name)) || null\n } catch (err) {\n // noop\n }\n return null\n },\n\n set: function (name, value) {\n try {\n window?.sessionStorage.setItem(name, JSON.stringify(value))\n } catch (err) {\n sessionStore.error(err)\n }\n },\n\n remove: function (name) {\n try {\n window?.sessionStorage.removeItem(name)\n } catch (err) {\n sessionStore.error(err)\n }\n },\n}\n"]}
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRo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AAO,EAAE,KAAK;QAC/D,IAAI;YACA,IAAI,KAAK,EAAE;gBACP,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;aACjD;YACD,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;SAC9D;QAAC,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAC1B;IACL,CAAC;IAED,MAAM,EAAE,UAAU,IAAI;QAClB,IAAI;YACA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;SAC1C;QAAC,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SAC1B;IACL,CAAC;CACJ,CAAA","sourcesContent":["import { extend } from './utils'\nimport { PersistentStore, Properties } from './types'\nimport { DISTINCT_ID, ENABLE_PERSON_PROCESSING, SESSION_ID, SESSION_RECORDING_IS_SAMPLED } from './constants'\n\nimport { isNull, isUndefined } from './utils/type-utils'\nimport { logger } from './utils/logger'\nimport { window, document } from './utils/globals'\nimport { uuidv7 } from './uuidv7'\n\nconst Y1970 = 'Thu, 01 Jan 1970 00:00:00 GMT'\n// we store the discovered subdomain in memory because it might be read multiple times\nlet firstNonPublicSubDomain = ''\n\n// helper to allow tests to clear this \"cache\"\nexport const resetSubDomainCache = () => {\n firstNonPublicSubDomain = ''\n}\n\n/**\n * Browsers don't offer a way to check if something is a public suffix\n * e.g. `.com.au`, `.io`, `.org.uk`\n *\n * But they do reject cookies set on public suffixes\n * Setting a cookie on `.co.uk` would mean it was sent for every `.co.uk` site visited\n *\n * So, we can use this to check if a domain is a public suffix\n * by trying to set a cookie on a subdomain of the provided hostname\n * until the browser accepts it\n *\n * inspired by https://github.com/AngusFu/browser-root-domain\n */\nexport function seekFirstNonPublicSubDomain(hostname: string, cookieJar = document): string {\n if (firstNonPublicSubDomain) {\n return firstNonPublicSubDomain\n }\n\n if (!cookieJar) {\n return ''\n }\n if (['localhost', '127.0.0.1'].includes(hostname)) return ''\n\n const list = hostname.split('.')\n let len = Math.min(list.length, 8) // paranoia - we know this number should be small\n const key = 'dmn_chk_' + uuidv7()\n const R = new RegExp('(^|;)\\\\s*' + key + '=1')\n\n while (!firstNonPublicSubDomain && len--) {\n const candidate = list.slice(len).join('.')\n const candidateCookieValue = key + '=1;domain=.' + candidate\n\n // try to set cookie\n cookieJar.cookie = candidateCookieValue\n\n if (R.test(cookieJar.cookie)) {\n // the cookie was accepted by the browser, remove the test cookie\n cookieJar.cookie = candidateCookieValue + ';expires=' + Y1970\n firstNonPublicSubDomain = candidate\n }\n }\n\n return firstNonPublicSubDomain\n}\n\nconst DOMAIN_MATCH_REGEX = /[a-z0-9][a-z0-9-]+\\.[a-z]{2,}$/i\nconst originalCookieDomainFn = (hostname: string): string => {\n const matches = hostname.match(DOMAIN_MATCH_REGEX)\n return matches ? matches[0] : ''\n}\n\nexport function chooseCookieDomain(hostname: string, cross_subdomain: boolean | undefined): string {\n if (cross_subdomain) {\n // NOTE: Could we use this for cross domain tracking?\n let matchedSubDomain = seekFirstNonPublicSubDomain(hostname)\n\n if (!matchedSubDomain) {\n const originalMatch = originalCookieDomainFn(hostname)\n if (originalMatch !== matchedSubDomain) {\n logger.info('Warning: cookie subdomain discovery mismatch', originalMatch, matchedSubDomain)\n }\n matchedSubDomain = originalMatch\n }\n\n return matchedSubDomain ? '; domain=.' + matchedSubDomain : ''\n }\n return ''\n}\n\n// Methods partially borrowed from quirksmode.org/js/cookies.html\nexport const cookieStore: PersistentStore = {\n is_supported: () => !!document,\n\n error: function (msg) {\n logger.error('cookieStore error: ' + msg)\n },\n\n get: function (name) {\n if (!document) {\n return\n }\n\n try {\n const nameEQ = name + '='\n const ca = document.cookie.split(';').filter((x) => x.length)\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i]\n while (c.charAt(0) == ' ') {\n c = c.substring(1, c.length)\n }\n if (c.indexOf(nameEQ) === 0) {\n return decodeURIComponent(c.substring(nameEQ.length, c.length))\n }\n }\n } catch (err) {}\n return null\n },\n\n parse: function (name) {\n let cookie\n try {\n cookie = JSON.parse(cookieStore.get(name)) || {}\n } catch (err) {\n // noop\n }\n return cookie\n },\n\n set: function (name, value, days, cross_subdomain, is_secure, debug) {\n if (!document) {\n return\n }\n try {\n let expires = '',\n secure = ''\n\n const cdomain = chooseCookieDomain(document.location.hostname, cross_subdomain)\n\n if (days) {\n const date = new Date()\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000)\n expires = '; expires=' + date.toUTCString()\n }\n\n if (is_secure) {\n secure = '; secure'\n }\n\n const new_cookie_val =\n name +\n '=' +\n encodeURIComponent(JSON.stringify(value)) +\n expires +\n '; SameSite=Lax; path=/' +\n cdomain +\n secure\n\n // 4096 bytes is the size at which some browsers (e.g. firefox) will not store a cookie, warn slightly before that\n if (new_cookie_val.length > 4096 * 0.9) {\n logger.warn('cookieStore warning: large cookie, len=' + new_cookie_val.length)\n }\n\n if (debug) {\n logger.info('cookie set', new_cookie_val)\n }\n\n document.cookie = new_cookie_val\n return new_cookie_val\n } catch (err) {\n return\n }\n },\n\n remove: function (name, cross_subdomain) {\n try {\n cookieStore.set(name, '', -1, cross_subdomain)\n } catch (err) {\n return\n }\n },\n}\n\nlet _localStorage_supported: boolean | null = null\n\nexport const localStore: PersistentStore = {\n is_supported: function () {\n if (!isNull(_localStorage_supported)) {\n return _localStorage_supported\n }\n\n let supported = true\n if (!isUndefined(window)) {\n try {\n const key = '__mplssupport__',\n val = 'xyz'\n localStore.set(key, val)\n if (localStore.get(key) !== '\"xyz\"') {\n supported = false\n }\n localStore.remove(key)\n } catch (err) {\n supported = false\n }\n } else {\n supported = false\n }\n if (!supported) {\n logger.error('localStorage unsupported; falling back to cookie store')\n }\n\n _localStorage_supported = supported\n return supported\n },\n\n error: function (msg) {\n logger.error('localStorage error: ' + msg)\n },\n\n get: function (name) {\n try {\n return window?.localStorage.getItem(name)\n } catch (err) {\n localStore.error(err)\n }\n return null\n },\n\n parse: function (name) {\n try {\n return JSON.parse(localStore.get(name)) || {}\n } catch (err) {\n // noop\n }\n return null\n },\n\n set: function (name, value, _days, _cross_subdomain, _secure, debug) {\n try {\n if (debug) {\n logger.info('localStorage set', name, value)\n }\n window?.localStorage.setItem(name, JSON.stringify(value))\n } catch (err) {\n localStore.error(err)\n }\n },\n\n remove: function (name) {\n try {\n window?.localStorage.removeItem(name)\n } catch (err) {\n localStore.error(err)\n }\n },\n}\n\n// Use localstorage for most data but still use cookie for COOKIE_PERSISTED_PROPERTIES\n// This solves issues with cookies having too much data in them causing headers too large\n// Also makes sure we don't have to send a ton of data to the server\nconst COOKIE_PERSISTED_PROPERTIES = [DISTINCT_ID, SESSION_ID, SESSION_RECORDING_IS_SAMPLED, ENABLE_PERSON_PROCESSING]\n\nexport const localPlusCookieStore: PersistentStore = {\n ...localStore,\n parse: function (name) {\n try {\n let cookieProperties: Properties = {}\n try {\n // See if there's a cookie stored with data.\n cookieProperties = cookieStore.parse(name) || {}\n } catch (err) {}\n const value = extend(cookieProperties, JSON.parse(localStore.get(name) || '{}'))\n localStore.set(name, value)\n return value\n } catch (err) {\n // noop\n }\n return null\n },\n\n set: function (name, value, days, cross_subdomain, is_secure, debug) {\n try {\n localStore.set(name, value, undefined, undefined, debug)\n const cookiePersistedProperties: Record<string, any> = {}\n COOKIE_PERSISTED_PROPERTIES.forEach((key) => {\n if (value[key]) {\n cookiePersistedProperties[key] = value[key]\n }\n })\n\n if (Object.keys(cookiePersistedProperties).length) {\n cookieStore.set(name, cookiePersistedProperties, days, cross_subdomain, is_secure, debug)\n }\n } catch (err) {\n localStore.error(err)\n }\n },\n\n remove: function (name, cross_subdomain) {\n try {\n window?.localStorage.removeItem(name)\n cookieStore.remove(name, cross_subdomain)\n } catch (err) {\n localStore.error(err)\n }\n },\n}\n\nconst memoryStorage: Properties = {}\n\n// Storage that only lasts the length of the pageview if we don't want to use cookies\nexport const memoryStore: PersistentStore = {\n is_supported: function () {\n return true\n },\n\n error: function (msg) {\n logger.error('memoryStorage error: ' + msg)\n },\n\n get: function (name) {\n return memoryStorage[name] || null\n },\n\n parse: function (name) {\n return memoryStorage[name] || null\n },\n\n set: function (name, value) {\n memoryStorage[name] = value\n },\n\n remove: function (name) {\n delete memoryStorage[name]\n },\n}\n\nlet sessionStorageSupported: boolean | null = null\nexport const resetSessionStorageSupported = () => {\n sessionStorageSupported = null\n}\n// Storage that only lasts the length of a tab/window. Survives page refreshes\nexport const sessionStore: PersistentStore = {\n is_supported: function () {\n if (!isNull(sessionStorageSupported)) {\n return sessionStorageSupported\n }\n sessionStorageSupported = true\n if (!isUndefined(window)) {\n try {\n const key = '__support__',\n val = 'xyz'\n sessionStore.set(key, val)\n if (sessionStore.get(key) !== '\"xyz\"') {\n sessionStorageSupported = false\n }\n sessionStore.remove(key)\n } catch (err) {\n sessionStorageSupported = false\n }\n } else {\n sessionStorageSupported = false\n }\n return sessionStorageSupported\n },\n\n error: function (msg) {\n logger.error('sessionStorage error: ', msg)\n },\n\n get: function (name) {\n try {\n return window?.sessionStorage.getItem(name)\n } catch (err) {\n sessionStore.error(err)\n }\n return null\n },\n\n parse: function (name) {\n try {\n return JSON.parse(sessionStore.get(name)) || null\n } catch (err) {\n // noop\n }\n return null\n },\n\n set: function (name, value, _days, _cross_subdomain, _secure, debug) {\n try {\n if (debug) {\n logger.info('sessionStorage set', name, value)\n }\n window?.sessionStorage.setItem(name, JSON.stringify(value))\n } catch (err) {\n sessionStore.error(err)\n }\n },\n\n remove: function (name) {\n try {\n window?.sessionStorage.removeItem(name)\n } catch (err) {\n sessionStore.error(err)\n }\n },\n}\n"]}
|
package/lib/src/types.d.ts
CHANGED
|
@@ -338,7 +338,7 @@ export interface PersistentStore {
|
|
|
338
338
|
error: (error: any) => void;
|
|
339
339
|
parse: (name: string) => any;
|
|
340
340
|
get: (name: string) => any;
|
|
341
|
-
set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean) => void;
|
|
341
|
+
set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean, debug?: boolean) => void;
|
|
342
342
|
remove: (name: string, cross_subdomain?: boolean) => void;
|
|
343
343
|
}
|
|
344
344
|
export type Breaker = {};
|