@posthog/browser-common
Advanced tools
+20
-17
| import type { Logger } from '@posthog/core'; | ||
| import type { KeyValueStore } from './persistence'; | ||
| import type { ExtensionToken } from './token'; | ||
| /** A minimal response from {@link Client.apiRequest}. */ | ||
| /** A minimal response from {@link Client.sendRequest}. */ | ||
| export interface ApiResponse { | ||
| /** The HTTP status code returned by the transport, or a client-defined best-effort status for unload sends. */ | ||
| /** The HTTP status code returned by the transport, or a client-defined best-effort status for sendBeacon sends. */ | ||
| statusCode: number; | ||
@@ -15,5 +15,11 @@ /** The response body parsed as JSON when available. */ | ||
| } | ||
| /** Options for sending a request through {@link Client.apiRequest}. */ | ||
| export interface ApiRequestInit { | ||
| /** HTTP method to use; defaults to the client's normal request method for the endpoint. */ | ||
| /** Configured host used to resolve a relative request path. */ | ||
| export type RequestTarget = 'api' | 'flags' | 'assets'; | ||
| /** Browser transport requested for a send. */ | ||
| export type RequestTransport = 'XHR' | 'fetch' | 'sendBeacon'; | ||
| /** Options for sending a request through {@link Client.sendRequest}. */ | ||
| export interface SendRequestInit { | ||
| /** Configured host to send through; defaults to the regular API host. */ | ||
| target?: RequestTarget; | ||
| /** HTTP method to use; the host transport's default applies when omitted. */ | ||
| method?: 'GET' | 'POST'; | ||
@@ -24,10 +30,6 @@ /** JSON-serialized by the client. */ | ||
| query?: Record<string, string>; | ||
| /** | ||
| * Mark this as a teardown send (pagehide / shutdown): the client picks the | ||
| * most reliable fire-and-forget transport available — `sendBeacon`, fetch | ||
| * `keepalive`, or sync XHR. The response is best-effort: `json` may be | ||
| * unavailable (e.g. `sendBeacon` only reports "queued"), so callers must not | ||
| * depend on it. | ||
| */ | ||
| unload?: boolean; | ||
| /** Additional headers merged with the host SDK's configured request headers. */ | ||
| headers?: Record<string, string>; | ||
| /** Browser transport to prefer. `sendBeacon` returns a best-effort response immediately. */ | ||
| transport?: RequestTransport; | ||
| /** Abort the request if it does not complete within this many milliseconds. */ | ||
@@ -46,8 +48,9 @@ timeoutMs?: number; | ||
| export interface Client { | ||
| /** Public project token used to authenticate endpoint-specific requests. */ | ||
| readonly projectToken: string; | ||
| /** | ||
| * Sends a request to a PostHog endpoint; the client owns auth, headers, and | ||
| * transport (fetch / XHR / keepalive). `path` is relative to the configured | ||
| * API host, e.g. `/s/`, `/flags/`, `/api/surveys/`. | ||
| * Sends a request through the host SDK's transport. The extension owns the | ||
| * endpoint-specific path, method, authentication shape, body, and headers. | ||
| */ | ||
| apiRequest(path: string, init?: ApiRequestInit): Promise<ApiResponse>; | ||
| sendRequest(path: string, init?: SendRequestInit): Promise<ApiResponse>; | ||
| /** | ||
@@ -54,0 +57,0 @@ * Resolves another registered extension by a capability token it provides, or |
+1
-1
@@ -29,3 +29,3 @@ "use strict"; | ||
| }); | ||
| const packageVersion = "0.2.2"; | ||
| const packageVersion = "0.2.3"; | ||
| const Config = { | ||
@@ -32,0 +32,0 @@ DEBUG: false, |
+1
-1
@@ -1,2 +0,2 @@ | ||
| const packageVersion = "0.2.2"; | ||
| const packageVersion = "0.2.3"; | ||
| const Config = { | ||
@@ -3,0 +3,0 @@ DEBUG: false, |
+1
-1
@@ -13,3 +13,3 @@ /** | ||
| export { Publisher } from './pubsub'; | ||
| export type { Client, ApiResponse, ApiRequestInit } from './client'; | ||
| export type { Client, ApiResponse, RequestTarget, RequestTransport, SendRequestInit } from './client'; | ||
| export type { KeyValueStore } from './persistence'; |
+1
-1
| { | ||
| "name": "@posthog/browser-common", | ||
| "version": "0.2.2", | ||
| "version": "0.2.3", | ||
| "description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+4
-4
@@ -63,3 +63,3 @@ # @posthog/browser-common | ||
| - **transport**: `apiRequest(path, init?)` | ||
| - **transport**: `projectToken`, `sendRequest(path, init?)` | ||
| - **registry**: `getExtension(token)` | ||
@@ -79,5 +79,5 @@ - **storage & logging**: `kv`, `logger` | ||
| Identity and session are always-ready synchronous reads. Operations that perform | ||
| I/O, including `capture`, `apiRequest`, `kv`, and `getRemoteConfig`, are | ||
| awaitable. | ||
| Identity, session, and the public project token are always-ready synchronous | ||
| reads. Operations that perform I/O, including `capture`, `sendRequest`, `kv`, | ||
| and `getRemoteConfig`, are awaitable. | ||
@@ -84,0 +84,0 @@ ### Host runtime |
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.
253567
0.14%5834
0.05%