@trycurious/js 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +141 -2
- package/dist/curious.iife.js +3 -0
- package/dist/curious.iife.js.map +1 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +1206 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
type CuriousErrorCode = "invalid_configuration" | "invalid_key_type" | "invalid_input" | "timeout" | "network_error" | "authentication_error" | "origin_not_allowed" | "rate_limited" | "undeclared_element" | "server_error" | "protocol_error" | "content_shape_mismatch" | "queue_full" | "event_rejected" | "identity_conflict" | "capability_unavailable" | "mutation_drift" | "lock_timeout";
|
|
2
|
+
type CuriousErrorSummary = {
|
|
3
|
+
code: CuriousErrorCode;
|
|
4
|
+
status?: number;
|
|
5
|
+
retryable: boolean;
|
|
6
|
+
requestId?: string;
|
|
7
|
+
serverCode?: string;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
declare class CuriousError extends Error {
|
|
11
|
+
readonly summary: CuriousErrorSummary;
|
|
12
|
+
constructor(summary: CuriousErrorSummary);
|
|
13
|
+
get code(): CuriousErrorCode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type FetchLike = (input: string, init: RequestInit) => Promise<Response>;
|
|
17
|
+
|
|
18
|
+
type BrowserEventInput = {
|
|
19
|
+
name: string;
|
|
20
|
+
value?: number | null;
|
|
21
|
+
properties?: Record<string, unknown>;
|
|
22
|
+
context?: Record<string, unknown>;
|
|
23
|
+
timestamp?: Date | string;
|
|
24
|
+
id?: string;
|
|
25
|
+
};
|
|
26
|
+
type FlushSummary = {
|
|
27
|
+
sent: number;
|
|
28
|
+
duplicates: number;
|
|
29
|
+
failed: number;
|
|
30
|
+
pending: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type ConsentMode = "implicit" | "required" | "denied";
|
|
34
|
+
type BrowserOptions = {
|
|
35
|
+
/** A publishable key (`curious_pk_...`). A secret key is refused: it must never reach a browser. */
|
|
36
|
+
publishableKey: string;
|
|
37
|
+
/** Default `https://api.trycurious.ai/v1`. */
|
|
38
|
+
baseUrl?: string;
|
|
39
|
+
/** The decide deadline; the page's text stays when it passes. Default 1000, may be lowered, never removed. */
|
|
40
|
+
decideTimeoutMs?: number;
|
|
41
|
+
/** `implicit` starts at once; `required` does nothing until grantConsent(); `denied` serves controls and collects nothing. */
|
|
42
|
+
consent?: ConsentMode;
|
|
43
|
+
/**
|
|
44
|
+
* The SDK's own events, on by default (docs/sdk.md §19, Autocapture V1): `$pageview` with the
|
|
45
|
+
* normalized path on start and each time a client-side navigation changes the path, `$click` and
|
|
46
|
+
* `$form_submit` on tagged nodes with the element name. `false` turns them all off; an object
|
|
47
|
+
* turns individual ones off. `pageviews: { historyChanges: false }` keeps the page view on start
|
|
48
|
+
* and leaves client-side navigation to your own `page()` calls. The API admits these events only
|
|
49
|
+
* under a publishable key with the SDK's client header, which the transport always sends.
|
|
50
|
+
*/
|
|
51
|
+
autocapture?: {
|
|
52
|
+
pageviews?: boolean | {
|
|
53
|
+
historyChanges?: boolean;
|
|
54
|
+
};
|
|
55
|
+
taggedClicks?: boolean;
|
|
56
|
+
taggedFormSubmits?: boolean;
|
|
57
|
+
} | false;
|
|
58
|
+
/** Context sent with every tagged decision; `path` and `locale` are added unless you set them. */
|
|
59
|
+
context?: Record<string, unknown>;
|
|
60
|
+
rootMargin?: string;
|
|
61
|
+
/** Queue tuning; the defaults are the spec's (5 s, 20 events, 100 queued). */
|
|
62
|
+
events?: {
|
|
63
|
+
flushIntervalMs?: number;
|
|
64
|
+
flushCount?: number;
|
|
65
|
+
queueLimit?: number;
|
|
66
|
+
};
|
|
67
|
+
cacheTtlMs?: number;
|
|
68
|
+
cookieMaxAgeSeconds?: number;
|
|
69
|
+
onDecision?: (element: string, result: DecisionResult<unknown>) => void;
|
|
70
|
+
onFallback?: (element: string, error: CuriousErrorSummary) => void;
|
|
71
|
+
onEventDrop?: (error: CuriousErrorSummary) => void;
|
|
72
|
+
onIdentityChange?: (userId: string | null) => void;
|
|
73
|
+
/** For tests. */
|
|
74
|
+
fetch?: FetchLike;
|
|
75
|
+
document?: Document;
|
|
76
|
+
storage?: Storage | null;
|
|
77
|
+
debug?: boolean;
|
|
78
|
+
};
|
|
79
|
+
type DecisionResult<T> = {
|
|
80
|
+
content: T;
|
|
81
|
+
served: "curious" | "fallback" | "cache";
|
|
82
|
+
armId: string | null;
|
|
83
|
+
armType: "control" | "variant" | null;
|
|
84
|
+
experimentId: string | null;
|
|
85
|
+
experimentStatus: string | null;
|
|
86
|
+
error?: CuriousErrorSummary;
|
|
87
|
+
requestId: string | null;
|
|
88
|
+
};
|
|
89
|
+
type BrowserDecisionInput<T> = {
|
|
90
|
+
element: string;
|
|
91
|
+
fallback: T;
|
|
92
|
+
identifiers?: Record<string, unknown>;
|
|
93
|
+
attributes?: Record<string, unknown>;
|
|
94
|
+
context?: Record<string, unknown>;
|
|
95
|
+
};
|
|
96
|
+
type CuriousBrowser = {
|
|
97
|
+
start(): void;
|
|
98
|
+
stop(): void;
|
|
99
|
+
scan(root?: ParentNode): void;
|
|
100
|
+
decide<T>(input: BrowserDecisionInput<T>): Promise<DecisionResult<T>>;
|
|
101
|
+
track(input: BrowserEventInput): {
|
|
102
|
+
id: string;
|
|
103
|
+
queued: boolean;
|
|
104
|
+
};
|
|
105
|
+
flush(options?: {
|
|
106
|
+
keepalive?: boolean;
|
|
107
|
+
}): Promise<FlushSummary>;
|
|
108
|
+
/**
|
|
109
|
+
* Record a page view for the current location. You need it only when you have turned automatic
|
|
110
|
+
* detection off (`autocapture: { pageviews: { historyChanges: false } }`): by default the SDK
|
|
111
|
+
* records a page view on start and whenever a client-side navigation changes the path, and then
|
|
112
|
+
* this call records nothing for a path whose page view is already recorded. It records nothing
|
|
113
|
+
* when page views are turned off through `autocapture`.
|
|
114
|
+
*/
|
|
115
|
+
page(): {
|
|
116
|
+
id: string;
|
|
117
|
+
queued: boolean;
|
|
118
|
+
};
|
|
119
|
+
identify(userId: string): Promise<{
|
|
120
|
+
userId: string;
|
|
121
|
+
}>;
|
|
122
|
+
reset(): Promise<void>;
|
|
123
|
+
grantConsent(): void;
|
|
124
|
+
denyConsent(): void;
|
|
125
|
+
readonly anonymousId: string | null;
|
|
126
|
+
readonly userId: string | null;
|
|
127
|
+
};
|
|
128
|
+
declare function createCurious(options: BrowserOptions): CuriousBrowser;
|
|
129
|
+
|
|
130
|
+
declare const SDK_VERSION = "0.2.0";
|
|
131
|
+
|
|
132
|
+
export { CuriousError, SDK_VERSION, createCurious };
|
|
133
|
+
export type { BrowserDecisionInput, BrowserEventInput, BrowserOptions, ConsentMode, CuriousBrowser, CuriousErrorCode, CuriousErrorSummary, DecisionResult, FlushSummary };
|