@posthog/browser-common
Advanced tools
+5
-2
@@ -68,3 +68,6 @@ import type { Logger } from '@posthog/core'; | ||
| headers?: Record<string, string>; | ||
| /** Browser transport to prefer. `sendBeacon` returns a best-effort response immediately. */ | ||
| /** | ||
| * Browser transport to prefer. Fetch is the normal runtime transport. Use `sendBeacon` only for an eligible | ||
| * best-effort teardown POST. Its response confirms browser handoff, not delivery. | ||
| */ | ||
| transport?: RequestTransport; | ||
@@ -113,3 +116,3 @@ /** Abort the request if it does not complete within this many milliseconds. */ | ||
| readonly onEvent: Listener<CapturedEventInfo>; | ||
| /** Replays the latest remote-config outcome on subscription and fires for subsequent outcomes. */ | ||
| /** Replays the latest available remote-config outcome and fires subsequent outcomes when the host makes them available. */ | ||
| readonly onRemoteConfig: Listener<DeepReadonly<RemoteConfigResult>>; | ||
@@ -116,0 +119,0 @@ /** Public project token used to authenticate endpoint-specific requests. */ |
+1
-1
@@ -29,3 +29,3 @@ "use strict"; | ||
| }); | ||
| const packageVersion = "0.6.2"; | ||
| const packageVersion = "0.7.0"; | ||
| const Config = { | ||
@@ -32,0 +32,0 @@ DEBUG: false, |
+1
-1
@@ -1,2 +0,2 @@ | ||
| const packageVersion = "0.6.2"; | ||
| const packageVersion = "0.7.0"; | ||
| const Config = { | ||
@@ -3,0 +3,0 @@ DEBUG: false, |
+4
-1
@@ -1,2 +0,2 @@ | ||
| import { type Disposable } from './disposable'; | ||
| import type { Disposable } from './disposable'; | ||
| /** | ||
@@ -20,2 +20,5 @@ * Call it with a handler to start listening; dispose the returned | ||
| private _subscriptions; | ||
| private _disposed; | ||
| private readonly _onError; | ||
| constructor(onError?: (error: unknown) => void); | ||
| /** | ||
@@ -22,0 +25,0 @@ * Register a handler for future payloads. The returned disposable |
+33
-20
@@ -29,31 +29,44 @@ "use strict"; | ||
| }); | ||
| const external_disposable_js_namespaceObject = require("./disposable.js"); | ||
| class Publisher { | ||
| constructor(onError){ | ||
| this._subscriptions = []; | ||
| this._disposed = false; | ||
| this.listener = (handler)=>{ | ||
| if (this._disposed) return { | ||
| dispose () {} | ||
| }; | ||
| const subscription = [ | ||
| handler, | ||
| true | ||
| ]; | ||
| this._subscriptions.push(subscription); | ||
| let active = true; | ||
| return { | ||
| dispose: ()=>{ | ||
| if (!active) return; | ||
| active = false; | ||
| subscription[1] = false; | ||
| const index = this._subscriptions.indexOf(subscription); | ||
| if (-1 !== index) this._subscriptions.splice(index, 1); | ||
| } | ||
| }; | ||
| }; | ||
| this._onError = onError; | ||
| } | ||
| publish(payload) { | ||
| const subscriptions = this._subscriptions.slice(); | ||
| subscriptions.forEach((subscription)=>{ | ||
| if (subscription.isActive) subscription.handler(payload); | ||
| }); | ||
| for (const subscription of subscriptions)if (subscription[1]) try { | ||
| subscription[0](payload); | ||
| } catch (error) { | ||
| if (!this._onError) throw error; | ||
| this._onError(error); | ||
| } | ||
| } | ||
| dispose() { | ||
| this._disposed = true; | ||
| this._subscriptions.forEach((subscription)=>{ | ||
| subscription.isActive = false; | ||
| subscription[1] = false; | ||
| }); | ||
| this._subscriptions = []; | ||
| } | ||
| constructor(){ | ||
| this._subscriptions = []; | ||
| this.listener = (handler)=>{ | ||
| const subscription = { | ||
| handler, | ||
| isActive: true | ||
| }; | ||
| this._subscriptions.push(subscription); | ||
| return (0, external_disposable_js_namespaceObject.createDisposable)(()=>{ | ||
| subscription.isActive = false; | ||
| const index = this._subscriptions.indexOf(subscription); | ||
| if (-1 !== index) this._subscriptions.splice(index, 1); | ||
| }); | ||
| }; | ||
| } | ||
| } | ||
@@ -60,0 +73,0 @@ exports.Publisher = __webpack_exports__.Publisher; |
+33
-20
@@ -1,31 +0,44 @@ | ||
| import { createDisposable } from "./disposable.mjs"; | ||
| class Publisher { | ||
| constructor(onError){ | ||
| this._subscriptions = []; | ||
| this._disposed = false; | ||
| this.listener = (handler)=>{ | ||
| if (this._disposed) return { | ||
| dispose () {} | ||
| }; | ||
| const subscription = [ | ||
| handler, | ||
| true | ||
| ]; | ||
| this._subscriptions.push(subscription); | ||
| let active = true; | ||
| return { | ||
| dispose: ()=>{ | ||
| if (!active) return; | ||
| active = false; | ||
| subscription[1] = false; | ||
| const index = this._subscriptions.indexOf(subscription); | ||
| if (-1 !== index) this._subscriptions.splice(index, 1); | ||
| } | ||
| }; | ||
| }; | ||
| this._onError = onError; | ||
| } | ||
| publish(payload) { | ||
| const subscriptions = this._subscriptions.slice(); | ||
| subscriptions.forEach((subscription)=>{ | ||
| if (subscription.isActive) subscription.handler(payload); | ||
| }); | ||
| for (const subscription of subscriptions)if (subscription[1]) try { | ||
| subscription[0](payload); | ||
| } catch (error) { | ||
| if (!this._onError) throw error; | ||
| this._onError(error); | ||
| } | ||
| } | ||
| dispose() { | ||
| this._disposed = true; | ||
| this._subscriptions.forEach((subscription)=>{ | ||
| subscription.isActive = false; | ||
| subscription[1] = false; | ||
| }); | ||
| this._subscriptions = []; | ||
| } | ||
| constructor(){ | ||
| this._subscriptions = []; | ||
| this.listener = (handler)=>{ | ||
| const subscription = { | ||
| handler, | ||
| isActive: true | ||
| }; | ||
| this._subscriptions.push(subscription); | ||
| return createDisposable(()=>{ | ||
| subscription.isActive = false; | ||
| const index = this._subscriptions.indexOf(subscription); | ||
| if (-1 !== index) this._subscriptions.splice(index, 1); | ||
| }); | ||
| }; | ||
| } | ||
| } | ||
| export { Publisher }; |
+10
-2
| { | ||
| "name": "@posthog/browser-common", | ||
| "version": "0.6.2", | ||
| "version": "0.7.0", | ||
| "description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs", | ||
@@ -35,2 +35,5 @@ "license": "MIT", | ||
| ], | ||
| "pubsub": [ | ||
| "dist/pubsub.d.ts" | ||
| ], | ||
| "utils/*": [ | ||
@@ -62,2 +65,7 @@ "dist/utils/*.d.ts" | ||
| }, | ||
| "./pubsub": { | ||
| "types": "./dist/pubsub.d.ts", | ||
| "require": "./dist/pubsub.js", | ||
| "import": "./dist/pubsub.mjs" | ||
| }, | ||
| "./utils/*": { | ||
@@ -70,3 +78,3 @@ "types": "./dist/utils/*.d.ts", | ||
| "dependencies": { | ||
| "@posthog/core": "^1.49.1", | ||
| "@posthog/core": "^1.49.2", | ||
| "@posthog/types": "^1.407.1" | ||
@@ -73,0 +81,0 @@ }, |
+5
-4
@@ -68,5 +68,6 @@ # @posthog/browser-common | ||
| `capture` and `sendRequest` are awaitable. For `sendRequest`, `sentAt` controls `sent_at` placement on POST requests; GET query mode | ||
| uses the cache-busting `_` parameter instead, and GET body mode has no effect. `onRemoteConfig` immediately replays the | ||
| latest known success or failure and then reports subsequent outcomes. Extensions that want a named log prefix can | ||
| create a child with `client.logger.createLogger('[myExtension]')`. | ||
| uses the cache-busting `_` parameter instead, and GET body mode has no effect. `onRemoteConfig` replays the latest | ||
| available success or failure and then reports subsequent outcomes. Configuration timing is host-owned, and the | ||
| subscription remains active until disposed. Extensions that want a named log prefix can create a child with | ||
| `client.logger.createLogger('[myExtension]')`. | ||
@@ -127,3 +128,3 @@ Extensions that expose controls to other extensions should export a typed stable-name token: | ||
| ```ts | ||
| import { Publisher, type Listener } from '@posthog/browser-common' | ||
| import { Publisher, type Listener } from '@posthog/browser-common/pubsub' | ||
@@ -130,0 +131,0 @@ const changes = new Publisher<{ enabled: boolean }>() |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
250104
0.47%5769
0.56%158
0.64%Updated