posthog-js 1.78.2 → 1.78.3
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 +2 -2
- package/dist/array.js.map +1 -1
- package/dist/es.js +2 -2
- package/dist/es.js.map +1 -1
- package/dist/module.d.ts +2 -2
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/src/extensions/sessionrecording.d.ts +1 -1
- package/lib/src/extensions/sessionrecording.js +1 -1
- package/lib/src/extensions/sessionrecording.js.map +1 -1
- package/lib/src/posthog-core.js +1 -4
- package/lib/src/posthog-core.js.map +1 -1
- package/lib/src/rate-limiter.d.ts +1 -1
- package/lib/src/rate-limiter.js +17 -51
- package/lib/src/rate-limiter.js.map +1 -1
- package/lib/src/retry-queue.js +1 -4
- package/lib/src/retry-queue.js.map +1 -1
- package/lib/src/send-request.d.ts +1 -1
- package/lib/src/send-request.js +6 -10
- package/lib/src/send-request.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
package/lib/src/rate-limiter.js
CHANGED
|
@@ -1,36 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
|
-
import { SESSION_RECORDING_BATCH_KEY } from './extensions/sessionrecording';
|
|
18
|
-
/**
|
|
19
|
-
* Really a 429 response should have a `Retry-After` header which is either a date string,
|
|
20
|
-
* or the number of seconds to wait before retrying
|
|
21
|
-
*
|
|
22
|
-
* But we can rate limit endpoints differently, so send custom header per endpoint
|
|
23
|
-
* The endpoints are configurable, so we tie the headers/retries to specific batch keys
|
|
24
|
-
*
|
|
25
|
-
* And only support a number of seconds to wait before retrying
|
|
26
|
-
*/
|
|
27
|
-
var supportedRetryHeaders = {
|
|
28
|
-
'X-PostHog-Retry-After-Recordings': SESSION_RECORDING_BATCH_KEY,
|
|
29
|
-
'X-PostHog-Retry-After-Events': 'events',
|
|
30
|
-
};
|
|
1
|
+
import { logger } from './utils';
|
|
2
|
+
var oneMinuteInMilliseconds = 60 * 1000;
|
|
31
3
|
var RateLimiter = /** @class */ (function () {
|
|
32
4
|
function RateLimiter() {
|
|
5
|
+
var _this = this;
|
|
33
6
|
this.limits = {};
|
|
7
|
+
this.checkForLimiting = function (xmlHttpRequest) {
|
|
8
|
+
try {
|
|
9
|
+
var response = JSON.parse(xmlHttpRequest.responseText);
|
|
10
|
+
var quotaLimitedProducts = response.quota_limited || [];
|
|
11
|
+
quotaLimitedProducts.forEach(function (batchKey) {
|
|
12
|
+
logger.log("[PostHog RateLimiter] ".concat(batchKey || 'events', " is quota limited."));
|
|
13
|
+
_this.limits[batchKey] = new Date().getTime() + oneMinuteInMilliseconds;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
logger.error(e);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
34
21
|
}
|
|
35
22
|
RateLimiter.prototype.isRateLimited = function (batchKey) {
|
|
36
23
|
var retryAfter = this.limits[batchKey || 'events'] || false;
|
|
@@ -39,27 +26,6 @@ var RateLimiter = /** @class */ (function () {
|
|
|
39
26
|
}
|
|
40
27
|
return new Date().getTime() < retryAfter;
|
|
41
28
|
};
|
|
42
|
-
RateLimiter.prototype.on429Response = function (response) {
|
|
43
|
-
var _this = this;
|
|
44
|
-
if (response.status !== 429) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
Object.entries(supportedRetryHeaders).forEach(function (_a) {
|
|
48
|
-
var _b = __read(_a, 2), header = _b[0], batchKey = _b[1];
|
|
49
|
-
var responseHeader = response.getResponseHeader(header);
|
|
50
|
-
if (!responseHeader) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
var retryAfterSeconds = parseInt(responseHeader, 10);
|
|
54
|
-
if (isNaN(retryAfterSeconds)) {
|
|
55
|
-
retryAfterSeconds = 60;
|
|
56
|
-
}
|
|
57
|
-
if (retryAfterSeconds) {
|
|
58
|
-
var retryAfterMillis = retryAfterSeconds * 1000;
|
|
59
|
-
_this.limits[batchKey] = new Date().getTime() + retryAfterMillis;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
29
|
return RateLimiter;
|
|
64
30
|
}());
|
|
65
31
|
export { RateLimiter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/rate-limiter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rate-limiter.js","sourceRoot":"","sources":["../../src/rate-limiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhC,IAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAA;AAMzC;IAAA;QAAA,iBAyBC;QAxBG,WAAM,GAA2B,EAAE,CAAA;QAW5B,qBAAgB,GAAG,UAAC,cAA8B;YACrD,IAAI;gBACA,IAAM,QAAQ,GAAoB,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;gBACzE,IAAM,oBAAoB,GAAG,QAAQ,CAAC,aAAa,IAAI,EAAE,CAAA;gBACzD,oBAAoB,CAAC,OAAO,CAAC,UAAC,QAAQ;oBAClC,MAAM,CAAC,GAAG,CAAC,gCAAyB,QAAQ,IAAI,QAAQ,uBAAoB,CAAC,CAAA;oBAC7E,KAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,uBAAuB,CAAA;gBAC1E,CAAC,CAAC,CAAA;aACL;YAAC,OAAO,CAAC,EAAE;gBACR,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBACf,OAAM;aACT;QACL,CAAC,CAAA;IACL,CAAC;IAtBU,mCAAa,GAApB,UAAqB,QAA4B;QAC7C,IAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAA;QAE7D,IAAI,UAAU,KAAK,KAAK,EAAE;YACtB,OAAO,KAAK,CAAA;SACf;QACD,OAAO,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,UAAU,CAAA;IAC5C,CAAC;IAeL,kBAAC;AAAD,CAAC,AAzBD,IAyBC","sourcesContent":["import { logger } from './utils'\n\nconst oneMinuteInMilliseconds = 60 * 1000\n\ninterface CaptureResponse {\n quota_limited?: string[]\n}\n\nexport class RateLimiter {\n limits: Record<string, number> = {}\n\n public isRateLimited(batchKey: string | undefined): boolean {\n const retryAfter = this.limits[batchKey || 'events'] || false\n\n if (retryAfter === false) {\n return false\n }\n return new Date().getTime() < retryAfter\n }\n\n public checkForLimiting = (xmlHttpRequest: XMLHttpRequest): void => {\n try {\n const response: CaptureResponse = JSON.parse(xmlHttpRequest.responseText)\n const quotaLimitedProducts = response.quota_limited || []\n quotaLimitedProducts.forEach((batchKey) => {\n logger.log(`[PostHog RateLimiter] ${batchKey || 'events'} is quota limited.`)\n this.limits[batchKey] = new Date().getTime() + oneMinuteInMilliseconds\n })\n } catch (e) {\n logger.error(e)\n return\n }\n }\n}\n"]}
|
package/lib/src/retry-queue.js
CHANGED
|
@@ -171,9 +171,6 @@ var RetryQueue = /** @class */ (function (_super) {
|
|
|
171
171
|
RetryQueue.prototype._executeXhrRequest = function (_a) {
|
|
172
172
|
var url = _a.url, data = _a.data, options = _a.options, headers = _a.headers, callback = _a.callback, retriesPerformedSoFar = _a.retriesPerformedSoFar;
|
|
173
173
|
if (this.rateLimiter.isRateLimited(options._batchKey)) {
|
|
174
|
-
if (Config.DEBUG) {
|
|
175
|
-
console.warn('[PostHog RetryQueue] in quota limited mode. Dropping request.');
|
|
176
|
-
}
|
|
177
174
|
return;
|
|
178
175
|
}
|
|
179
176
|
xhr({
|
|
@@ -185,7 +182,7 @@ var RetryQueue = /** @class */ (function (_super) {
|
|
|
185
182
|
callback: callback,
|
|
186
183
|
retryQueue: this,
|
|
187
184
|
onXHRError: this.onXHRError,
|
|
188
|
-
|
|
185
|
+
onResponse: this.rateLimiter.checkForLimiting,
|
|
189
186
|
});
|
|
190
187
|
};
|
|
191
188
|
RetryQueue.prototype._handleWeAreNowOnline = function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry-queue.js","sourceRoot":"","sources":["../../src/retry-queue.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,MAAM,MAAM,UAAU,CAAA;AAG7B,IAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;AAEpC;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,qBAA6B;IAC5D,IAAM,cAAc,GAAG,IAAI,GAAG,SAAA,CAAC,EAAI,qBAAqB,CAAA,CAAA;IACxD,IAAM,UAAU,GAAG,cAAc,GAAG,CAAC,CAAA;IACrC,IAAM,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,cAAc,CAAC,CAAA;IACjE,IAAM,cAAc,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAA,CAA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S,CAAC,UAAU,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,wBAAO,OAAO,KAAE,UAAU,EAAE,IAAI,IAAG,CAAC,CAAA;iBAC3F;gBAAC,OAAO,CAAC,EAAE;oBACR,gHAAgH;oBAChH,+DAA+D;oBAC/D,IAAI,MAAM,CAAC,KAAK,EAAE;wBACd,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;qBACnB;iBACJ;aACJ;;;;;;;;;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;IACnB,CAAC;IAED,uCAAkB,GAAlB,UAAmB,EAAmF;YAAjF,GAAG,SAAA,EAAE,IAAI,UAAA,EAAE,OAAO,aAAA,EAAE,OAAO,aAAA,EAAE,QAAQ,cAAA,EAAE,qBAAqB,2BAAA;QAC7E,IAAI,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACnD,OAAM;SACT;QAED,GAAG,CAAC;YACA,GAAG,KAAA;YACH,IAAI,EAAE,IAAI,IAAI,EAAE;YAChB,OAAO,EAAE,OAAO,IAAI,EAAE;YACtB,OAAO,EAAE,OAAO,IAAI,EAAE;YACtB,qBAAqB,EAAE,qBAAqB,IAAI,CAAC;YACjD,QAAQ,UAAA;YACR,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,gBAAgB;SAChD,CAAC,CAAA;IACN,CAAC;IAED,0CAAqB,GAArB;QACI,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;QACvB,IAAI,CAAC,KAAK,EAAE,CAAA;IAChB,CAAC;IACL,iBAAC;AAAD,CAAC,AArHD,CAAgC,oBAAoB,GAqHnD","sourcesContent":["import { RequestQueueScaffold } from './base-request-queue'\nimport { encodePostData, xhr } from './send-request'\nimport { QueuedRequestData, RetryQueueElement } from './types'\nimport Config from './config'\nimport { RateLimiter } from './rate-limiter'\n\nconst thirtyMinutes = 30 * 60 * 1000\n\n/**\n * Generates a jitter-ed exponential backoff delay in milliseconds\n *\n * The base value is 6 seconds, which is doubled with each retry\n * up to the maximum of 30 minutes\n *\n * Each value then has +/- 50% jitter\n *\n * Giving a range of 6 seconds up to 45 minutes\n */\nexport function pickNextRetryDelay(retriesPerformedSoFar: number): number {\n const rawBackoffTime = 3000 * 2 ** retriesPerformedSoFar\n const minBackoff = rawBackoffTime / 2\n const cappedBackoffTime = Math.min(thirtyMinutes, rawBackoffTime)\n const jitterFraction = Math.random() - 0.5 // A random number between -0.5 and 0.5\n const jitter = jitterFraction * (cappedBackoffTime - minBackoff)\n return Math.ceil(cappedBackoffTime + jitter)\n}\n\nexport class RetryQueue extends RequestQueueScaffold {\n queue: RetryQueueElement[]\n isPolling: boolean\n areWeOnline: boolean\n onXHRError: (failedRequest: XMLHttpRequest) => void\n rateLimiter: RateLimiter\n\n constructor(onXHRError: (failedRequest: XMLHttpRequest) => void, rateLimiter: RateLimiter) {\n super()\n this.isPolling = false\n this.queue = []\n this.areWeOnline = true\n this.onXHRError = onXHRError\n this.rateLimiter = rateLimiter\n\n if (typeof window !== 'undefined' && 'onLine' in window.navigator) {\n this.areWeOnline = window.navigator.onLine\n window.addEventListener('online', () => {\n this._handleWeAreNowOnline()\n })\n window.addEventListener('offline', () => {\n this.areWeOnline = false\n })\n }\n }\n\n enqueue(requestData: QueuedRequestData): void {\n const retriesPerformedSoFar = requestData.retriesPerformedSoFar || 0\n if (retriesPerformedSoFar >= 10) {\n return\n }\n const msToNextRetry = pickNextRetryDelay(retriesPerformedSoFar)\n const retryAt = new Date(Date.now() + msToNextRetry)\n\n this.queue.push({ retryAt, requestData })\n console.warn(`Enqueued failed request for retry in ${msToNextRetry}`)\n if (!this.isPolling) {\n this.isPolling = true\n this.poll()\n }\n }\n\n poll(): void {\n this._poller && clearTimeout(this._poller)\n this._poller = setTimeout(() => {\n if (this.areWeOnline && this.queue.length > 0) {\n this.flush()\n }\n this.poll()\n }, this._pollInterval) as any as number\n }\n\n flush(): void {\n // using Date.now to make tests easier, as recommended here https://codewithhugo.com/mocking-the-current-date-in-jest-tests/\n const now = new Date(Date.now())\n const toFlush = this.queue.filter(({ retryAt }) => retryAt < now)\n if (toFlush.length > 0) {\n this.queue = this.queue.filter(({ retryAt }) => retryAt >= now)\n for (const { requestData } of toFlush) {\n this._executeXhrRequest(requestData)\n }\n }\n }\n\n unload(): void {\n if (this._poller) {\n clearTimeout(this._poller)\n this._poller = undefined\n }\n\n for (const { requestData } of this.queue) {\n const { url, data, options } = requestData\n\n if (this.rateLimiter.isRateLimited(options._batchKey)) {\n if (Config.DEBUG) {\n console.warn('[PostHog RetryQueue] is quota limited. Dropping request.')\n }\n continue\n }\n\n try {\n // we've had send beacon in place for at least 2 years\n // eslint-disable-next-line compat/compat\n window.navigator.sendBeacon(url, encodePostData(data, { ...options, sendBeacon: true }))\n } catch (e) {\n // Note sendBeacon automatically retries, and after the first retry it will lose reference to contextual `this`.\n // This means in some cases `this.getConfig` will be undefined.\n if (Config.DEBUG) {\n console.error(e)\n }\n }\n }\n this.queue = []\n }\n\n _executeXhrRequest({ url, data, options, headers, callback, retriesPerformedSoFar }: QueuedRequestData): void {\n if (this.rateLimiter.isRateLimited(options._batchKey)) {\n return\n }\n\n xhr({\n url,\n data: data || {},\n options: options || {},\n headers: headers || {},\n retriesPerformedSoFar: retriesPerformedSoFar || 0,\n callback,\n retryQueue: this,\n onXHRError: this.onXHRError,\n onResponse: this.rateLimiter.checkForLimiting,\n })\n }\n\n _handleWeAreNowOnline(): void {\n this.areWeOnline = true\n this.flush()\n }\n}\n"]}
|
|
@@ -3,4 +3,4 @@ export declare const addParamsToURL: (url: string, urlQueryArgs: Record<string,
|
|
|
3
3
|
ip?: boolean;
|
|
4
4
|
}) => string;
|
|
5
5
|
export declare const encodePostData: (data: PostData | Uint8Array, options: Partial<XHROptions>) => string | BlobPart | null;
|
|
6
|
-
export declare const xhr: ({ url, data, headers, options, callback, retriesPerformedSoFar, retryQueue, onXHRError, timeout,
|
|
6
|
+
export declare const xhr: ({ url, data, headers, options, callback, retriesPerformedSoFar, retryQueue, onXHRError, timeout, onResponse, }: XHRParams) => void;
|
package/lib/src/send-request.js
CHANGED
|
@@ -66,7 +66,7 @@ export var encodePostData = function (data, options) {
|
|
|
66
66
|
return body_data;
|
|
67
67
|
};
|
|
68
68
|
export var xhr = function (_a) {
|
|
69
|
-
var url = _a.url, data = _a.data, headers = _a.headers, options = _a.options, callback = _a.callback, retriesPerformedSoFar = _a.retriesPerformedSoFar, retryQueue = _a.retryQueue, onXHRError = _a.onXHRError, _b = _a.timeout, timeout = _b === void 0 ? 10000 : _b,
|
|
69
|
+
var url = _a.url, data = _a.data, headers = _a.headers, options = _a.options, callback = _a.callback, retriesPerformedSoFar = _a.retriesPerformedSoFar, retryQueue = _a.retryQueue, onXHRError = _a.onXHRError, _b = _a.timeout, timeout = _b === void 0 ? 10000 : _b, onResponse = _a.onResponse;
|
|
70
70
|
var req = new XMLHttpRequest();
|
|
71
71
|
req.open(options.method || 'GET', url, true);
|
|
72
72
|
var body = encodePostData(data, options);
|
|
@@ -81,8 +81,9 @@ export var xhr = function (_a) {
|
|
|
81
81
|
// withCredentials cannot be modified until after calling .open on Android and Mobile Safari
|
|
82
82
|
req.withCredentials = true;
|
|
83
83
|
req.onreadystatechange = function () {
|
|
84
|
+
// XMLHttpRequest.DONE == 4, except in safari 4
|
|
84
85
|
if (req.readyState === 4) {
|
|
85
|
-
|
|
86
|
+
onResponse === null || onResponse === void 0 ? void 0 : onResponse(req);
|
|
86
87
|
if (req.status === 200) {
|
|
87
88
|
if (callback) {
|
|
88
89
|
var response = void 0;
|
|
@@ -100,8 +101,8 @@ export var xhr = function (_a) {
|
|
|
100
101
|
if (typeof onXHRError === 'function') {
|
|
101
102
|
onXHRError(req);
|
|
102
103
|
}
|
|
103
|
-
// don't retry
|
|
104
|
-
if (
|
|
104
|
+
// don't retry errors between 400 and 500 inclusive
|
|
105
|
+
if (req.status < 400 || req.status > 500) {
|
|
105
106
|
retryQueue.enqueue({
|
|
106
107
|
url: url,
|
|
107
108
|
data: data,
|
|
@@ -111,12 +112,7 @@ export var xhr = function (_a) {
|
|
|
111
112
|
callback: callback,
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
|
-
|
|
115
|
-
onRateLimited === null || onRateLimited === void 0 ? void 0 : onRateLimited(req);
|
|
116
|
-
}
|
|
117
|
-
if (callback) {
|
|
118
|
-
callback({ status: 0 });
|
|
119
|
-
}
|
|
115
|
+
callback === null || callback === void 0 ? void 0 : callback({ status: 0 });
|
|
120
116
|
}
|
|
121
117
|
}
|
|
122
118
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-request.js","sourceRoot":"","sources":["../../src/send-request.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,MAAM,MAAM,UAAU,CAAA;AAG7B,MAAM,CAAC,IAAM,cAAc,GAAG,UAC1B,GAAW,EACX,YAA6C,EAC7C,gBAAkC;;IAElC,IAAM,IAAI,GAAG,YAAY,IAAI,EAAE,CAAA;IAC/B,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3C,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAA;IAC3C,IAAI,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,WAAW,CAAA;IAEhC,IAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACnB,IAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;;Y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,QAAQ,CAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAA;aAC5B;SACJ;IACL,CAAC,CAAA;IACD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAClB,CAAC,CAAA","sourcesContent":["import { _each, _HTTPBuildQuery, logger } from './utils'\nimport Config from './config'\nimport { PostData, XHROptions, XHRParams } from './types'\n\nexport const addParamsToURL = (\n url: string,\n urlQueryArgs: Record<string, any> | undefined,\n parameterOptions: { ip?: boolean }\n): string => {\n const args = urlQueryArgs || {}\n args['ip'] = parameterOptions['ip'] ? 1 : 0\n args['_'] = new Date().getTime().toString()\n args['ver'] = Config.LIB_VERSION\n\n const halves = url.split('?')\n if (halves.length > 1) {\n const params = halves[1].split('&')\n for (const p of params) {\n const key = p.split('=')[0]\n if (args[key]) {\n delete args[key]\n }\n }\n }\n\n const argSeparator = url.indexOf('?') > -1 ? '&' : '?'\n return url + argSeparator + _HTTPBuildQuery(args)\n}\n\nexport const encodePostData = (data: PostData | Uint8Array, options: Partial<XHROptions>): string | BlobPart | null => {\n if (options.blob && data.buffer) {\n return new Blob([data.buffer], { type: 'text/plain' })\n }\n\n if (options.sendBeacon || options.blob) {\n const body = encodePostData(data, { method: 'POST' }) as BlobPart\n return new Blob([body], { type: 'application/x-www-form-urlencoded' })\n }\n\n if (options.method !== 'POST') {\n return null\n }\n\n let body_data\n const isUint8Array = (d: unknown): d is Uint8Array => Object.prototype.toString.call(d) === '[object Uint8Array]'\n if (Array.isArray(data) || isUint8Array(data)) {\n // TODO: eh? passing an Array here?\n body_data = 'data=' + encodeURIComponent(data as any)\n } else {\n body_data = 'data=' + encodeURIComponent(data.data as string)\n }\n\n if ('compression' in data && data.compression) {\n body_data += '&compression=' + data.compression\n }\n\n return body_data\n}\n\nexport const xhr = ({\n url,\n data,\n headers,\n options,\n callback,\n retriesPerformedSoFar,\n retryQueue,\n onXHRError,\n timeout = 10000,\n onResponse,\n}: XHRParams) => {\n const req = new XMLHttpRequest()\n req.open(options.method || 'GET', url, true)\n\n const body = encodePostData(data, options)\n\n _each(headers, function (headerValue, headerName) {\n req.setRequestHeader(headerName, headerValue)\n })\n\n if (options.method === 'POST' && !options.blob) {\n req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')\n }\n\n req.timeout = timeout\n // send the ph_optout cookie\n // withCredentials cannot be modified until after calling .open on Android and Mobile Safari\n req.withCredentials = true\n req.onreadystatechange = () => {\n // XMLHttpRequest.DONE == 4, except in safari 4\n if (req.readyState === 4) {\n onResponse?.(req)\n if (req.status === 200) {\n if (callback) {\n let response\n try {\n response = JSON.parse(req.responseText)\n } catch (e) {\n logger.error(e)\n return\n }\n callback(response)\n }\n } else {\n if (typeof onXHRError === 'function') {\n onXHRError(req)\n }\n\n // don't retry errors between 400 and 500 inclusive\n if (req.status < 400 || req.status > 500) {\n retryQueue.enqueue({\n url,\n data,\n options,\n headers,\n retriesPerformedSoFar: (retriesPerformedSoFar || 0) + 1,\n callback,\n })\n }\n\n callback?.({ status: 0 })\n }\n }\n }\n req.send(body)\n}\n"]}
|
package/lib/src/types.d.ts
CHANGED
|
@@ -183,7 +183,7 @@ export interface XHRParams extends QueuedRequestData {
|
|
|
183
183
|
retryQueue: RetryQueue;
|
|
184
184
|
onXHRError: (req: XMLHttpRequest) => void;
|
|
185
185
|
timeout?: number;
|
|
186
|
-
|
|
186
|
+
onResponse?: (req: XMLHttpRequest) => void;
|
|
187
187
|
}
|
|
188
188
|
export interface DecideResponse {
|
|
189
189
|
status: number;
|
package/lib/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAgKA,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACnB,iCAAkB,CAAA;IAClB,gCAAiB,CAAA;AACrB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB","sourcesContent":["import type { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot'\nimport { PostHog } from './posthog-core'\nimport { RetryQueue } from './retry-queue'\n\nexport type Property = any\nexport type Properties = Record<string, Property>\nexport interface CaptureResult {\n uuid: string\n event: string\n properties: Properties\n $set?: Properties\n $set_once?: Properties\n timestamp?: Date\n}\nexport type CaptureCallback = (response: any, data: any) => void\n\nexport type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label'\nexport type DomAutocaptureEvents = 'click' | 'change' | 'submit'\n\n/**\n * If an array is passed for an allowlist, autocapture events will only be sent for elements matching\n * at least one of the elements in the array. Multiple allowlists can be used\n */\nexport interface AutocaptureConfig {\n /**\n * List of URLs to allow autocapture on, can be strings to match\n * or regexes e.g. ['https://example.com', 'test.com/.*']\n */\n url_allowlist?: (string | RegExp)[]\n\n /**\n * List of DOM events to allow autocapture on e.g. ['click', 'change', 'submit']\n */\n dom_event_allowlist?: DomAutocaptureEvents[]\n\n /**\n * List of DOM elements to allow autocapture on\n * e.g. ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']\n */\n element_allowlist?: AutocaptureCompatibleElement[]\n\n /**\n * List of CSS selectors to allow autocapture on\n * e.g. ['[ph-capture]']\n */\n css_selector_allowlist?: string[]\n}\n\nexport type UUIDVersion = 'og' | 'v7'\n\nexport interface PostHogConfig {\n api_host: string\n api_method: string\n api_transport: string\n ui_host: string | null\n token: string\n autocapture: boolean | AutocaptureConfig\n rageclick: boolean\n cross_subdomain_cookie: boolean\n persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage'\n persistence_name: string\n cookie_name: string\n loaded: (posthog_instance: PostHog) => void\n store_google: boolean\n custom_campaign_params: string[]\n // a list of strings to be tested against navigator.userAgent to determine if the source is a bot\n // this is **added to** the default list of bots that we check\n // defaults to the empty array\n custom_blocked_useragents: string[]\n save_referrer: boolean\n test: boolean\n verbose: boolean\n capture_pageview: boolean\n capture_pageleave: boolean\n debug: boolean\n cookie_expiration: number\n upgrade: boolean\n disable_session_recording: boolean\n disable_persistence: boolean\n disable_cookie: boolean\n enable_recording_console_log?: boolean\n secure_cookie: boolean\n ip: boolean\n opt_out_capturing_by_default: boolean\n opt_out_persistence_by_default: boolean\n opt_out_capturing_persistence_type: 'localStorage' | 'cookie'\n opt_out_capturing_cookie_prefix: string | null\n opt_in_site_apps: boolean\n respect_dnt: boolean\n property_blacklist: string[]\n xhr_headers: { [header_name: string]: string }\n on_xhr_error: (failedRequest: XMLHttpRequest) => void\n inapp_protocol: string\n inapp_link_new_window: boolean\n request_batching: boolean\n sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null\n properties_string_max_length: number\n session_recording: SessionRecordingOptions\n session_idle_timeout_seconds: number\n mask_all_element_attributes: boolean\n mask_all_text: boolean\n advanced_disable_decide: boolean\n advanced_disable_feature_flags: boolean\n advanced_disable_feature_flags_on_first_load: boolean\n advanced_disable_toolbar_metrics: boolean\n get_device_id: (uuid: string) => string\n name: string\n callback_fn: string\n _onCapture: (eventName: string, eventData: CaptureResult) => void\n capture_performance?: boolean\n // Should only be used for testing. Could negatively impact performance.\n disable_compression: boolean\n bootstrap: {\n distinctID?: string\n isIdentifiedID?: boolean\n featureFlags?: Record<string, boolean | string>\n featureFlagPayloads?: Record<string, JsonType>\n }\n segment?: any\n __preview_measure_pageview_stats?: boolean\n}\n\nexport interface OptInOutCapturingOptions {\n capture: (event: string, properties: Properties, options: CaptureOptions) => void\n capture_event_name: string\n capture_properties: Properties\n enable_persistence: boolean\n clear_persistence: boolean\n persistence_type: 'cookie' | 'localStorage' | 'localStorage+cookie'\n cookie_prefix: string\n cookie_expiration: number\n cross_subdomain_cookie: boolean\n secure_cookie: boolean\n}\n\nexport interface isFeatureEnabledOptions {\n send_event: boolean\n}\n\nexport interface SessionRecordingOptions {\n blockClass?: string | RegExp\n blockSelector?: string | null\n ignoreClass?: string\n maskTextClass?: string | RegExp\n maskTextSelector?: string | null\n maskTextFn?: ((text: string) => string) | null\n maskAllInputs?: boolean\n maskInputOptions?: MaskInputOptions\n maskInputFn?: ((text: string, element?: HTMLElement) => string) | null\n /** Modify the network request before it is captured. Returning null stops it being captured */\n maskNetworkRequestFn?: ((url: NetworkRequest) => NetworkRequest | null | undefined) | null\n slimDOMOptions?: SlimDOMOptions | 'all' | true\n collectFonts?: boolean\n inlineStylesheet?: boolean\n recorderVersion?: 'v1' | 'v2'\n recordCrossOriginIframes?: boolean\n}\n\nexport type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined) => void\n\nexport enum Compression {\n GZipJS = 'gzip-js',\n Base64 = 'base64',\n}\n\nexport interface XHROptions {\n transport?: 'XHR' | 'sendBeacon'\n method?: 'POST' | 'GET'\n urlQueryArgs?: { compression: Compression }\n verbose?: boolean\n blob?: boolean\n sendBeacon?: boolean\n}\n\nexport interface CaptureOptions extends XHROptions {\n $set?: Properties /** used with $identify */\n $set_once?: Properties /** used with $identify */\n _batchKey?: string /** key of queue, e.g. 'sessionRecording' vs 'event' */\n _metrics?: Properties\n _noTruncate?: boolean /** if set, overrides and disables config.properties_string_max_length */\n endpoint?: string /** defaults to '/e/' */\n send_instantly?: boolean /** if set skips the batched queue */\n timestamp?: Date\n}\n\nexport interface RetryQueueElement {\n retryAt: Date\n requestData: QueuedRequestData\n}\nexport interface QueuedRequestData {\n url: string\n data: Properties\n options: CaptureOptions\n headers?: Properties\n callback?: RequestCallback\n retriesPerformedSoFar?: number\n}\n\nexport interface XHRParams extends QueuedRequestData {\n retryQueue: RetryQueue\n onXHRError: (req: XMLHttpRequest) => void\n timeout?: number\n onRateLimited?: (req: XMLHttpRequest) => void\n}\n\nexport interface DecideResponse {\n status: number\n supportedCompression: Compression[]\n config: {\n enable_collect_everything: boolean\n }\n custom_properties: AutoCaptureCustomProperty[] // TODO: delete, not sent\n featureFlags: Record<string, string | boolean>\n featureFlagPayloads: Record<string, JsonType>\n errorsWhileComputingFlags: boolean\n autocapture_opt_out?: boolean\n capturePerformance?: boolean\n // this is currently in development and may have breaking changes without a major version bump\n autocaptureExceptions?:\n | boolean\n | {\n endpoint?: string\n errors_to_ignore: string[]\n }\n sessionRecording?: {\n endpoint?: string\n consoleLogRecordingEnabled?: boolean\n recorderVersion?: 'v1' | 'v2'\n }\n toolbarParams: ToolbarParams\n editorParams?: ToolbarParams /** @deprecated, renamed to toolbarParams, still present on older API responses */\n toolbarVersion: 'toolbar' /** @deprecated, moved to toolbarParams */\n isAuthenticated: boolean\n siteApps: { id: number; url: string }[]\n}\n\nexport type FeatureFlagsCallback = (flags: string[], variants: Record<string, string | boolean>) => void\n\n// TODO: delete custom_properties after changeless typescript refactor\nexport interface AutoCaptureCustomProperty {\n name: string\n css_selector: string\n event_selectors: string[]\n}\n\nexport interface CompressionData {\n data: string\n compression?: Compression\n}\n\nexport interface GDPROptions {\n capture?: (\n event: string,\n properties: Properties,\n options: CaptureOptions\n ) => void /** function used for capturing a PostHog event to record the opt-in action */\n captureEventName?: string /** event name to be used for capturing the opt-in action */\n captureProperties?: Properties /** set of properties to be captured along with the opt-in action */\n /** persistence mechanism used */\n persistenceType?: 'cookie' | 'localStorage' | 'localStorage+cookie'\n persistencePrefix?: string /** [__ph_opt_in_out] - custom prefix to be used in the cookie/localstorage name */\n cookieExpiration?: number /** number of days until the opt-in cookie expires */\n crossSubdomainCookie?: boolean /** whether the opt-in cookie is set as cross-subdomain or not */\n secureCookie?: boolean /** whether the opt-in cookie is set as secure or not */\n respectDnt?: boolean\n window?: Window\n}\n\nexport type RequestCallback = (response: Record<string, any>, data?: Properties) => void\n\nexport interface PersistentStore {\n is_supported: () => boolean\n error: (error: any) => void\n parse: (name: string) => any\n get: (name: string) => any\n set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean) => void\n remove: (name: string, cross_subdomain?: boolean) => void\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type Breaker = {}\nexport type EventHandler = (event: Event) => boolean | void\n\nexport type ToolbarUserIntent = 'add-action' | 'edit-action'\nexport type ToolbarSource = 'url' | 'localstorage'\nexport type ToolbarVersion = 'toolbar'\n\n/* sync with posthog */\nexport interface ToolbarParams {\n token?: string /** public posthog-js token */\n temporaryToken?: string /** private temporary user token */\n actionId?: number\n userIntent?: ToolbarUserIntent\n source?: ToolbarSource\n toolbarVersion?: ToolbarVersion\n instrument?: boolean\n distinctId?: string\n userEmail?: string\n dataAttributes?: string[]\n featureFlags?: Record<string, string | boolean>\n}\n\nexport interface PostData {\n buffer?: BlobPart\n compression?: Compression\n data?: string\n}\n\nexport interface JSC {\n (): void\n [key: string]: (response: any) => void\n}\n\nexport type SnippetArrayItem = [method: string, ...args: any[]]\n\nexport type JsonType = string | number | boolean | null | { [key: string]: JsonType } | Array<JsonType>\n\n/** A feature that isn't publicly available yet.*/\nexport interface EarlyAccessFeature {\n // Sync this with the backend's EarlyAccessFeatureSerializer!\n name: string\n description: string\n stage: 'concept' | 'alpha' | 'beta'\n documentationUrl: string | null\n flagKey: string | null\n}\n\nexport type EarlyAccessFeatureCallback = (earlyAccessFeatures: EarlyAccessFeature[]) => void\n\nexport interface EarlyAccessFeatureResponse {\n earlyAccessFeatures: EarlyAccessFeature[]\n}\n\nexport type NetworkRequest = {\n url: string\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAgKA,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACnB,iCAAkB,CAAA;IAClB,gCAAiB,CAAA;AACrB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB","sourcesContent":["import type { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot'\nimport { PostHog } from './posthog-core'\nimport { RetryQueue } from './retry-queue'\n\nexport type Property = any\nexport type Properties = Record<string, Property>\nexport interface CaptureResult {\n uuid: string\n event: string\n properties: Properties\n $set?: Properties\n $set_once?: Properties\n timestamp?: Date\n}\nexport type CaptureCallback = (response: any, data: any) => void\n\nexport type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label'\nexport type DomAutocaptureEvents = 'click' | 'change' | 'submit'\n\n/**\n * If an array is passed for an allowlist, autocapture events will only be sent for elements matching\n * at least one of the elements in the array. Multiple allowlists can be used\n */\nexport interface AutocaptureConfig {\n /**\n * List of URLs to allow autocapture on, can be strings to match\n * or regexes e.g. ['https://example.com', 'test.com/.*']\n */\n url_allowlist?: (string | RegExp)[]\n\n /**\n * List of DOM events to allow autocapture on e.g. ['click', 'change', 'submit']\n */\n dom_event_allowlist?: DomAutocaptureEvents[]\n\n /**\n * List of DOM elements to allow autocapture on\n * e.g. ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']\n */\n element_allowlist?: AutocaptureCompatibleElement[]\n\n /**\n * List of CSS selectors to allow autocapture on\n * e.g. ['[ph-capture]']\n */\n css_selector_allowlist?: string[]\n}\n\nexport type UUIDVersion = 'og' | 'v7'\n\nexport interface PostHogConfig {\n api_host: string\n api_method: string\n api_transport: string\n ui_host: string | null\n token: string\n autocapture: boolean | AutocaptureConfig\n rageclick: boolean\n cross_subdomain_cookie: boolean\n persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage'\n persistence_name: string\n cookie_name: string\n loaded: (posthog_instance: PostHog) => void\n store_google: boolean\n custom_campaign_params: string[]\n // a list of strings to be tested against navigator.userAgent to determine if the source is a bot\n // this is **added to** the default list of bots that we check\n // defaults to the empty array\n custom_blocked_useragents: string[]\n save_referrer: boolean\n test: boolean\n verbose: boolean\n capture_pageview: boolean\n capture_pageleave: boolean\n debug: boolean\n cookie_expiration: number\n upgrade: boolean\n disable_session_recording: boolean\n disable_persistence: boolean\n disable_cookie: boolean\n enable_recording_console_log?: boolean\n secure_cookie: boolean\n ip: boolean\n opt_out_capturing_by_default: boolean\n opt_out_persistence_by_default: boolean\n opt_out_capturing_persistence_type: 'localStorage' | 'cookie'\n opt_out_capturing_cookie_prefix: string | null\n opt_in_site_apps: boolean\n respect_dnt: boolean\n property_blacklist: string[]\n xhr_headers: { [header_name: string]: string }\n on_xhr_error: (failedRequest: XMLHttpRequest) => void\n inapp_protocol: string\n inapp_link_new_window: boolean\n request_batching: boolean\n sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null\n properties_string_max_length: number\n session_recording: SessionRecordingOptions\n session_idle_timeout_seconds: number\n mask_all_element_attributes: boolean\n mask_all_text: boolean\n advanced_disable_decide: boolean\n advanced_disable_feature_flags: boolean\n advanced_disable_feature_flags_on_first_load: boolean\n advanced_disable_toolbar_metrics: boolean\n get_device_id: (uuid: string) => string\n name: string\n callback_fn: string\n _onCapture: (eventName: string, eventData: CaptureResult) => void\n capture_performance?: boolean\n // Should only be used for testing. Could negatively impact performance.\n disable_compression: boolean\n bootstrap: {\n distinctID?: string\n isIdentifiedID?: boolean\n featureFlags?: Record<string, boolean | string>\n featureFlagPayloads?: Record<string, JsonType>\n }\n segment?: any\n __preview_measure_pageview_stats?: boolean\n}\n\nexport interface OptInOutCapturingOptions {\n capture: (event: string, properties: Properties, options: CaptureOptions) => void\n capture_event_name: string\n capture_properties: Properties\n enable_persistence: boolean\n clear_persistence: boolean\n persistence_type: 'cookie' | 'localStorage' | 'localStorage+cookie'\n cookie_prefix: string\n cookie_expiration: number\n cross_subdomain_cookie: boolean\n secure_cookie: boolean\n}\n\nexport interface isFeatureEnabledOptions {\n send_event: boolean\n}\n\nexport interface SessionRecordingOptions {\n blockClass?: string | RegExp\n blockSelector?: string | null\n ignoreClass?: string\n maskTextClass?: string | RegExp\n maskTextSelector?: string | null\n maskTextFn?: ((text: string) => string) | null\n maskAllInputs?: boolean\n maskInputOptions?: MaskInputOptions\n maskInputFn?: ((text: string, element?: HTMLElement) => string) | null\n /** Modify the network request before it is captured. Returning null stops it being captured */\n maskNetworkRequestFn?: ((url: NetworkRequest) => NetworkRequest | null | undefined) | null\n slimDOMOptions?: SlimDOMOptions | 'all' | true\n collectFonts?: boolean\n inlineStylesheet?: boolean\n recorderVersion?: 'v1' | 'v2'\n recordCrossOriginIframes?: boolean\n}\n\nexport type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined) => void\n\nexport enum Compression {\n GZipJS = 'gzip-js',\n Base64 = 'base64',\n}\n\nexport interface XHROptions {\n transport?: 'XHR' | 'sendBeacon'\n method?: 'POST' | 'GET'\n urlQueryArgs?: { compression: Compression }\n verbose?: boolean\n blob?: boolean\n sendBeacon?: boolean\n}\n\nexport interface CaptureOptions extends XHROptions {\n $set?: Properties /** used with $identify */\n $set_once?: Properties /** used with $identify */\n _batchKey?: string /** key of queue, e.g. 'sessionRecording' vs 'event' */\n _metrics?: Properties\n _noTruncate?: boolean /** if set, overrides and disables config.properties_string_max_length */\n endpoint?: string /** defaults to '/e/' */\n send_instantly?: boolean /** if set skips the batched queue */\n timestamp?: Date\n}\n\nexport interface RetryQueueElement {\n retryAt: Date\n requestData: QueuedRequestData\n}\nexport interface QueuedRequestData {\n url: string\n data: Properties\n options: CaptureOptions\n headers?: Properties\n callback?: RequestCallback\n retriesPerformedSoFar?: number\n}\n\nexport interface XHRParams extends QueuedRequestData {\n retryQueue: RetryQueue\n onXHRError: (req: XMLHttpRequest) => void\n timeout?: number\n onResponse?: (req: XMLHttpRequest) => void\n}\n\nexport interface DecideResponse {\n status: number\n supportedCompression: Compression[]\n config: {\n enable_collect_everything: boolean\n }\n custom_properties: AutoCaptureCustomProperty[] // TODO: delete, not sent\n featureFlags: Record<string, string | boolean>\n featureFlagPayloads: Record<string, JsonType>\n errorsWhileComputingFlags: boolean\n autocapture_opt_out?: boolean\n capturePerformance?: boolean\n // this is currently in development and may have breaking changes without a major version bump\n autocaptureExceptions?:\n | boolean\n | {\n endpoint?: string\n errors_to_ignore: string[]\n }\n sessionRecording?: {\n endpoint?: string\n consoleLogRecordingEnabled?: boolean\n recorderVersion?: 'v1' | 'v2'\n }\n toolbarParams: ToolbarParams\n editorParams?: ToolbarParams /** @deprecated, renamed to toolbarParams, still present on older API responses */\n toolbarVersion: 'toolbar' /** @deprecated, moved to toolbarParams */\n isAuthenticated: boolean\n siteApps: { id: number; url: string }[]\n}\n\nexport type FeatureFlagsCallback = (flags: string[], variants: Record<string, string | boolean>) => void\n\n// TODO: delete custom_properties after changeless typescript refactor\nexport interface AutoCaptureCustomProperty {\n name: string\n css_selector: string\n event_selectors: string[]\n}\n\nexport interface CompressionData {\n data: string\n compression?: Compression\n}\n\nexport interface GDPROptions {\n capture?: (\n event: string,\n properties: Properties,\n options: CaptureOptions\n ) => void /** function used for capturing a PostHog event to record the opt-in action */\n captureEventName?: string /** event name to be used for capturing the opt-in action */\n captureProperties?: Properties /** set of properties to be captured along with the opt-in action */\n /** persistence mechanism used */\n persistenceType?: 'cookie' | 'localStorage' | 'localStorage+cookie'\n persistencePrefix?: string /** [__ph_opt_in_out] - custom prefix to be used in the cookie/localstorage name */\n cookieExpiration?: number /** number of days until the opt-in cookie expires */\n crossSubdomainCookie?: boolean /** whether the opt-in cookie is set as cross-subdomain or not */\n secureCookie?: boolean /** whether the opt-in cookie is set as secure or not */\n respectDnt?: boolean\n window?: Window\n}\n\nexport type RequestCallback = (response: Record<string, any>, data?: Properties) => void\n\nexport interface PersistentStore {\n is_supported: () => boolean\n error: (error: any) => void\n parse: (name: string) => any\n get: (name: string) => any\n set: (name: string, value: any, expire_days?: number | null, cross_subdomain?: boolean, secure?: boolean) => void\n remove: (name: string, cross_subdomain?: boolean) => void\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type Breaker = {}\nexport type EventHandler = (event: Event) => boolean | void\n\nexport type ToolbarUserIntent = 'add-action' | 'edit-action'\nexport type ToolbarSource = 'url' | 'localstorage'\nexport type ToolbarVersion = 'toolbar'\n\n/* sync with posthog */\nexport interface ToolbarParams {\n token?: string /** public posthog-js token */\n temporaryToken?: string /** private temporary user token */\n actionId?: number\n userIntent?: ToolbarUserIntent\n source?: ToolbarSource\n toolbarVersion?: ToolbarVersion\n instrument?: boolean\n distinctId?: string\n userEmail?: string\n dataAttributes?: string[]\n featureFlags?: Record<string, string | boolean>\n}\n\nexport interface PostData {\n buffer?: BlobPart\n compression?: Compression\n data?: string\n}\n\nexport interface JSC {\n (): void\n [key: string]: (response: any) => void\n}\n\nexport type SnippetArrayItem = [method: string, ...args: any[]]\n\nexport type JsonType = string | number | boolean | null | { [key: string]: JsonType } | Array<JsonType>\n\n/** A feature that isn't publicly available yet.*/\nexport interface EarlyAccessFeature {\n // Sync this with the backend's EarlyAccessFeatureSerializer!\n name: string\n description: string\n stage: 'concept' | 'alpha' | 'beta'\n documentationUrl: string | null\n flagKey: string | null\n}\n\nexport type EarlyAccessFeatureCallback = (earlyAccessFeatures: EarlyAccessFeature[]) => void\n\nexport interface EarlyAccessFeatureResponse {\n earlyAccessFeatures: EarlyAccessFeature[]\n}\n\nexport type NetworkRequest = {\n url: string\n}\n"]}
|
package/package.json
CHANGED