@posthog/browser-common 0.2.2 → 0.2.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/README.md CHANGED
@@ -60,7 +60,7 @@ callback into idempotent teardown.
60
60
 
61
61
  What an extension is given in `setup` — the host's extension services:
62
62
 
63
- - **transport**: `apiRequest(path, init?)`
63
+ - **transport**: `projectToken`, `sendRequest(path, init?)`
64
64
  - **registry**: `getExtension(token)`
65
65
  - **storage & logging**: `kv`, `logger`
66
66
 
@@ -75,9 +75,9 @@ owned by the PostHog client's analytics core:
75
75
  - **lifecycle**: `onNewSession(...)`
76
76
  - **server config**: `getRemoteConfig()` (current), `onRemoteConfig(...)` (changes)
77
77
 
78
- Identity and session are always-ready synchronous reads. Operations that perform
79
- I/O, including `capture`, `apiRequest`, `kv`, and `getRemoteConfig`, are
80
- awaitable.
78
+ Identity, session, and the public project token are always-ready synchronous
79
+ reads. Operations that perform I/O, including `capture`, `sendRequest`, `kv`,
80
+ and `getRemoteConfig`, are awaitable.
81
81
 
82
82
  ### Host runtime
83
83
 
package/dist/client.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { Logger } from '@posthog/core';
2
2
  import type { KeyValueStore } from './persistence';
3
3
  import type { ExtensionToken } from './token';
4
- /** A minimal response from {@link Client.apiRequest}. */
4
+ /** A minimal response from {@link Client.sendRequest}. */
5
5
  export interface ApiResponse {
6
- /** The HTTP status code returned by the transport, or a client-defined best-effort status for unload sends. */
6
+ /** The HTTP status code returned by the transport, or a client-defined best-effort status for sendBeacon sends. */
7
7
  statusCode: number;
8
8
  /** The response body parsed as JSON when available. */
9
9
  json?: unknown;
@@ -12,22 +12,24 @@ export interface ApiResponse {
12
12
  /** The transport error when the request failed before receiving an HTTP response. */
13
13
  error?: unknown;
14
14
  }
15
- /** Options for sending a request through {@link Client.apiRequest}. */
16
- export interface ApiRequestInit {
17
- /** HTTP method to use; defaults to the client's normal request method for the endpoint. */
15
+ /** Configured host used to resolve a relative request path. */
16
+ export type RequestTarget = 'api' | 'flags' | 'assets';
17
+ /** Browser transport requested for a send. */
18
+ export type RequestTransport = 'XHR' | 'fetch' | 'sendBeacon';
19
+ /** Options for sending a request through {@link Client.sendRequest}. */
20
+ export interface SendRequestInit {
21
+ /** Configured host to send through; defaults to the regular API host. */
22
+ target?: RequestTarget;
23
+ /** HTTP method to use; the host transport's default applies when omitted. */
18
24
  method?: 'GET' | 'POST';
19
25
  /** JSON-serialized by the client. */
20
26
  body?: unknown;
21
27
  /** Query string parameters appended to the request URL. */
22
28
  query?: Record<string, string>;
23
- /**
24
- * Mark this as a teardown send (pagehide / shutdown): the client picks the
25
- * most reliable fire-and-forget transport available `sendBeacon`, fetch
26
- * `keepalive`, or sync XHR. The response is best-effort: `json` may be
27
- * unavailable (e.g. `sendBeacon` only reports "queued"), so callers must not
28
- * depend on it.
29
- */
30
- unload?: boolean;
29
+ /** Additional headers merged with the host SDK's configured request headers. */
30
+ headers?: Record<string, string>;
31
+ /** Browser transport to prefer. `sendBeacon` returns a best-effort response immediately. */
32
+ transport?: RequestTransport;
31
33
  /** Abort the request if it does not complete within this many milliseconds. */
32
34
  timeoutMs?: number;
33
35
  }
@@ -41,12 +43,13 @@ export interface ApiRequestInit {
41
43
  * analytics behavior is provided separately by the core extension.
42
44
  */
43
45
  export interface Client {
46
+ /** Public project token used to authenticate endpoint-specific requests. */
47
+ readonly projectToken: string;
44
48
  /**
45
- * Sends a request to a PostHog endpoint; the client owns auth, headers, and
46
- * transport (fetch / XHR / keepalive). `path` is relative to the configured
47
- * API host, e.g. `/s/`, `/flags/`, `/api/surveys/`.
49
+ * Sends a request through the host SDK's transport. The extension owns the
50
+ * endpoint-specific path, method, authentication shape, body, and headers.
48
51
  */
49
- apiRequest(path: string, init?: ApiRequestInit): Promise<ApiResponse>;
52
+ sendRequest(path: string, init?: SendRequestInit): Promise<ApiResponse>;
50
53
  /**
51
54
  * Resolves another registered extension by a capability token it provides, or
52
55
  * `undefined` if nothing registered provides it (not installed, or not loaded
package/dist/config.js CHANGED
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  default: ()=>__WEBPACK_DEFAULT_EXPORT__
28
28
  });
29
- const packageVersion = "0.2.2";
29
+ const packageVersion = "0.2.3";
30
30
  const Config = {
31
31
  DEBUG: false,
32
32
  LIB_VERSION: packageVersion,
package/dist/config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const packageVersion = "0.2.2";
1
+ const packageVersion = "0.2.3";
2
2
  const Config = {
3
3
  DEBUG: false,
4
4
  LIB_VERSION: packageVersion,
package/dist/index.d.ts CHANGED
@@ -10,5 +10,5 @@ export { createDisposable, type Disposable } from './disposable';
10
10
  export type { ExtensionToken } from './token';
11
11
  export type { Listener } from './pubsub';
12
12
  export { Publisher } from './pubsub';
13
- export type { Client, ApiResponse, ApiRequestInit } from './client';
13
+ export type { Client, ApiResponse, RequestTarget, RequestTransport, SendRequestInit } from './client';
14
14
  export type { KeyValueStore } from './persistence';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/browser-common",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs",
5
5
  "license": "MIT",
6
6
  "repository": {