@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 +4 -4
- package/dist/client.d.ts +20 -17
- package/dist/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
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**: `
|
|
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
|
|
79
|
-
I/O, including `capture`, `
|
|
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.
|
|
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
|
|
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
|
-
/**
|
|
16
|
-
export
|
|
17
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
46
|
-
*
|
|
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
|
-
|
|
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.
|
|
29
|
+
const packageVersion = "0.2.3";
|
|
30
30
|
const Config = {
|
|
31
31
|
DEBUG: false,
|
|
32
32
|
LIB_VERSION: packageVersion,
|
package/dist/config.mjs
CHANGED
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,
|
|
13
|
+
export type { Client, ApiResponse, RequestTarget, RequestTransport, SendRequestInit } from './client';
|
|
14
14
|
export type { KeyValueStore } from './persistence';
|