@shotik/react-native 0.1.0 → 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/CHANGELOG.md +16 -0
- package/LICENSE +26 -0
- package/README.md +39 -3
- package/README.ru.md +40 -3
- package/dist/analytics/core.d.ts +96 -11
- package/dist/analytics/core.js +295 -22
- package/dist/analytics/privacy.d.ts +4 -0
- package/dist/analytics/privacy.js +46 -0
- package/dist/analytics/replay.d.ts +41 -0
- package/dist/analytics/replay.js +192 -0
- package/dist/analytics/rn.d.ts +52 -2
- package/dist/analytics/rn.js +669 -62
- package/dist/analytics/wire.d.ts +54 -2
- package/dist/analytics/wire.js +44 -4
- package/dist/client.d.ts +94 -1
- package/dist/client.js +254 -17
- package/dist/flow.d.ts +48 -0
- package/dist/flow.js +56 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/parts.d.ts +42 -1
- package/dist/parts.js +72 -14
- package/dist/react.d.ts +24 -3
- package/dist/react.js +42 -15
- package/dist/sheet.d.ts +2 -1
- package/dist/sheet.js +207 -16
- package/dist/support.js +2 -2
- package/dist/theme.d.ts +43 -0
- package/dist/theme.js +90 -4
- package/package.json +15 -2
- package/recipe.json +1 -1
- package/src/analytics/README.md +10 -6
- package/src/analytics/core.ts +314 -25
- package/src/analytics/privacy.ts +50 -0
- package/src/analytics/recipe.json +1 -1
- package/src/analytics/replay.ts +190 -0
- package/src/analytics/rn.tsx +620 -63
- package/src/analytics/wire.ts +99 -8
- package/src/client.ts +344 -19
- package/src/flow.ts +100 -0
- package/src/index.ts +4 -4
- package/src/parts.tsx +102 -14
- package/src/react.tsx +57 -16
- package/src/sheet.tsx +423 -20
- package/src/support.ts +2 -2
- package/src/theme.ts +90 -4
package/dist/analytics/wire.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const WIRE_VERSION = 1;
|
|
2
|
-
export declare const TYPES: readonly ["session", "open", "close", "screen", "leave", "tap", "rage", "scroll", "error", "slow", "purchase", "custom", "identify", "snapshot"];
|
|
2
|
+
export declare const TYPES: readonly ["session", "open", "close", "screen", "leave", "tap", "rage", "scroll", "error", "slow", "purchase", "custom", "identify", "snapshot", "net", "field", "state", "gesture"];
|
|
3
3
|
export type EventType = (typeof TYPES)[number];
|
|
4
4
|
export interface DeviceContext {
|
|
5
5
|
platform?: string;
|
|
@@ -11,6 +11,12 @@ export interface DeviceContext {
|
|
|
11
11
|
tz?: string;
|
|
12
12
|
w?: number;
|
|
13
13
|
h?: number;
|
|
14
|
+
ota?: string;
|
|
15
|
+
ch?: string;
|
|
16
|
+
rt?: string;
|
|
17
|
+
sdk?: string;
|
|
18
|
+
tzo?: number;
|
|
19
|
+
dev?: 1;
|
|
14
20
|
}
|
|
15
21
|
export interface WireEvent {
|
|
16
22
|
seq: number;
|
|
@@ -20,6 +26,7 @@ export interface WireEvent {
|
|
|
20
26
|
name?: string;
|
|
21
27
|
screen?: string;
|
|
22
28
|
props?: Record<string, unknown>;
|
|
29
|
+
kind?: 'test';
|
|
23
30
|
}
|
|
24
31
|
export interface Batch {
|
|
25
32
|
anonymousId: string;
|
|
@@ -28,7 +35,7 @@ export interface Batch {
|
|
|
28
35
|
device?: DeviceContext;
|
|
29
36
|
events: WireEvent[];
|
|
30
37
|
}
|
|
31
|
-
export type PackedEvent = [number, number, number, number, number, number, Record<string, unknown> | 0];
|
|
38
|
+
export type PackedEvent = [number, number, number, number, number, number, Record<string, unknown> | 0, 1?];
|
|
32
39
|
export interface PackedBatch {
|
|
33
40
|
v: 1;
|
|
34
41
|
a: string;
|
|
@@ -51,3 +58,48 @@ export interface Wireframe {
|
|
|
51
58
|
dark?: boolean;
|
|
52
59
|
nodes: WireNode[];
|
|
53
60
|
}
|
|
61
|
+
export type KeyedNode = [string, string, number, number, number, number, (string | null)?, (number | null)?, (string | null)?];
|
|
62
|
+
export interface ReplayScroll {
|
|
63
|
+
node: string;
|
|
64
|
+
y: number;
|
|
65
|
+
x?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface ReplayRun {
|
|
68
|
+
after: string | null;
|
|
69
|
+
nodes: KeyedNode[];
|
|
70
|
+
}
|
|
71
|
+
export interface ReplayChunk {
|
|
72
|
+
sess: string;
|
|
73
|
+
seq: number;
|
|
74
|
+
t: number;
|
|
75
|
+
keyframe?: {
|
|
76
|
+
screen: string;
|
|
77
|
+
w: number;
|
|
78
|
+
h: number;
|
|
79
|
+
nodes: KeyedNode[];
|
|
80
|
+
};
|
|
81
|
+
diff?: {
|
|
82
|
+
add?: ReplayRun[];
|
|
83
|
+
rm?: string[];
|
|
84
|
+
mv?: [string, number, number][];
|
|
85
|
+
};
|
|
86
|
+
scroll?: ReplayScroll[];
|
|
87
|
+
}
|
|
88
|
+
export type ReplayWhy = 'sample' | 'rage' | 'dead' | 'unresponsive' | 'errtap' | 'error' | 'crash';
|
|
89
|
+
export interface ReplayUpload {
|
|
90
|
+
v: 1;
|
|
91
|
+
a: string;
|
|
92
|
+
why: ReplayWhy;
|
|
93
|
+
chunks: ReplayChunk[];
|
|
94
|
+
}
|
|
95
|
+
export interface ReplayPicture {
|
|
96
|
+
screen: string;
|
|
97
|
+
w: number;
|
|
98
|
+
h: number;
|
|
99
|
+
nodes: KeyedNode[];
|
|
100
|
+
scroll: Record<string, {
|
|
101
|
+
x: number;
|
|
102
|
+
y: number;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
export declare function applyChunk(prev: ReplayPicture | null, c: ReplayChunk): ReplayPicture | null;
|
package/dist/analytics/wire.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// native code, so this is the compression: about 6x smaller than plain JSON on tap-heavy batches.
|
|
5
5
|
export const WIRE_VERSION = 1;
|
|
6
6
|
// Event types. Codes are the array position, so append only.
|
|
7
|
-
export const TYPES = ['session', 'open', 'close', 'screen', 'leave', 'tap', 'rage', 'scroll', 'error', 'slow', 'purchase', 'custom', 'identify', 'snapshot'];
|
|
7
|
+
export const TYPES = ['session', 'open', 'close', 'screen', 'leave', 'tap', 'rage', 'scroll', 'error', 'slow', 'purchase', 'custom', 'identify', 'snapshot', 'net', 'field', 'state', 'gesture'];
|
|
8
8
|
const PACKED_PROPS = ['el', 'label', 'from'];
|
|
9
9
|
export function pack(b) {
|
|
10
10
|
const d = [];
|
|
@@ -35,14 +35,17 @@ export function pack(b) {
|
|
|
35
35
|
p[k] = PACKED_PROPS.includes(k) && typeof v === 'string' ? s(v) : v;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
const row = [dt, TYPES.indexOf(ev.type), ev.seq, s(ev.sessionId), s(ev.screen), s(ev.name), p];
|
|
39
|
+
if (ev.kind === 'test')
|
|
40
|
+
row.push(1);
|
|
41
|
+
return row;
|
|
39
42
|
});
|
|
40
43
|
return { v: 1, a: b.anonymousId, u: b.userId ?? null, f: b.firstSeen, c: b.device, t0, d, e };
|
|
41
44
|
}
|
|
42
45
|
export function unpack(p) {
|
|
43
46
|
const str = (i) => (i >= 0 && i < p.d.length ? p.d[i] : undefined);
|
|
44
47
|
let ts = p.t0;
|
|
45
|
-
const events = p.e.map(([dt, type, seq, sess, screen, name, props]) => {
|
|
48
|
+
const events = p.e.map(([dt, type, seq, sess, screen, name, props, test]) => {
|
|
46
49
|
ts += dt;
|
|
47
50
|
let pr;
|
|
48
51
|
if (props) {
|
|
@@ -50,7 +53,44 @@ export function unpack(p) {
|
|
|
50
53
|
for (const k in props)
|
|
51
54
|
pr[k] = PACKED_PROPS.includes(k) && typeof props[k] === 'number' ? str(props[k]) : props[k];
|
|
52
55
|
}
|
|
53
|
-
return { seq, ts, type: TYPES[type] ?? 'custom', sessionId: str(sess) ?? '', screen: str(screen), name: str(name), props: pr };
|
|
56
|
+
return { seq, ts, type: TYPES[type] ?? 'custom', sessionId: str(sess) ?? '', screen: str(screen), name: str(name), props: pr, ...(test === 1 && { kind: 'test' }) };
|
|
54
57
|
});
|
|
55
58
|
return { anonymousId: p.a, userId: p.u ?? null, firstSeen: p.f, device: p.c, events };
|
|
56
59
|
}
|
|
60
|
+
export function applyChunk(prev, c) {
|
|
61
|
+
let pic;
|
|
62
|
+
if (c.keyframe)
|
|
63
|
+
pic = { screen: c.keyframe.screen, w: c.keyframe.w, h: c.keyframe.h, nodes: c.keyframe.nodes.slice(), scroll: {} };
|
|
64
|
+
else if (prev)
|
|
65
|
+
pic = { ...prev, nodes: prev.nodes.slice(), scroll: { ...prev.scroll } };
|
|
66
|
+
else
|
|
67
|
+
return null;
|
|
68
|
+
const d = c.diff;
|
|
69
|
+
if (d) {
|
|
70
|
+
const gone = new Set(d.rm ?? []);
|
|
71
|
+
for (const r of d.add ?? [])
|
|
72
|
+
for (const n of r.nodes)
|
|
73
|
+
gone.add(n[0]);
|
|
74
|
+
let nodes = pic.nodes.filter((n) => !gone.has(n[0]));
|
|
75
|
+
for (const r of d.add ?? []) {
|
|
76
|
+
const i = r.after === null ? 0 : nodes.findIndex((n) => n[0] === r.after) + 1;
|
|
77
|
+
nodes = nodes.slice(0, i).concat(r.nodes, nodes.slice(i));
|
|
78
|
+
}
|
|
79
|
+
if (d.mv?.length) {
|
|
80
|
+
const mv = new Map(d.mv.map((m) => [m[0], m]));
|
|
81
|
+
nodes = nodes.map((n) => {
|
|
82
|
+
const m = mv.get(n[0]);
|
|
83
|
+
if (!m)
|
|
84
|
+
return n;
|
|
85
|
+
const k = n.slice();
|
|
86
|
+
k[2] = m[1];
|
|
87
|
+
k[3] = m[2];
|
|
88
|
+
return k;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
pic.nodes = nodes;
|
|
92
|
+
}
|
|
93
|
+
for (const s of c.scroll ?? [])
|
|
94
|
+
pic.scroll[s.node] = { x: s.x ?? 0, y: s.y };
|
|
95
|
+
return pic;
|
|
96
|
+
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export interface ErasableAnalytics {
|
|
2
|
+
forget(): Promise<boolean>;
|
|
3
|
+
reset(): Promise<void> | void;
|
|
4
|
+
}
|
|
5
|
+
export declare function registerAnalytics(a: ErasableAnalytics | null): void;
|
|
1
6
|
export type Author = 'user' | 'ai' | 'founder' | 'system';
|
|
2
7
|
export type ConversationStatus = 'open' | 'needs_human' | 'resolved' | 'closed' | string;
|
|
3
8
|
export type Status = 'idle' | 'identifying' | 'connecting' | 'live' | 'offline' | 'error';
|
|
@@ -10,7 +15,60 @@ export interface Conversation {
|
|
|
10
15
|
lastAuthor: Author | null;
|
|
11
16
|
createdAt: number;
|
|
12
17
|
founderUnread?: number;
|
|
18
|
+
csat?: 1 | -1 | null;
|
|
19
|
+
}
|
|
20
|
+
export interface Subscription {
|
|
21
|
+
status: 'trial' | 'active' | 'grace' | 'billing_retry' | 'cancelled' | 'expired' | 'refunded' | 'none';
|
|
22
|
+
product?: string | null;
|
|
23
|
+
period?: 'P1W' | 'P1M' | 'P3M' | 'P6M' | 'P1Y' | 'lifetime' | null;
|
|
24
|
+
price?: string | null;
|
|
25
|
+
renewsAt?: number | null;
|
|
26
|
+
expiresAt?: number | null;
|
|
27
|
+
trialEndsAt?: number | null;
|
|
28
|
+
willRenew?: boolean | null;
|
|
29
|
+
store?: 'app_store' | 'play' | 'stripe' | null;
|
|
30
|
+
}
|
|
31
|
+
export type ActionKind = 'manage_subscription' | 'restore' | 'redeem_code' | 'change_plan' | 'request_refund' | 'open_url' | 'write_review' | 'custom';
|
|
32
|
+
export interface SupportAction {
|
|
33
|
+
id: string;
|
|
34
|
+
kind: ActionKind;
|
|
35
|
+
label: string;
|
|
36
|
+
value?: string | null;
|
|
37
|
+
}
|
|
38
|
+
export type ActionResult = 'done' | 'cancelled' | 'failed';
|
|
39
|
+
export declare const actionsOf: (m: Message) => SupportAction[];
|
|
40
|
+
export type CancelReason = 'too_expensive' | 'not_using' | 'bug' | 'mistake' | 'other';
|
|
41
|
+
export interface Offer {
|
|
42
|
+
kind: 'chat';
|
|
43
|
+
label: string;
|
|
44
|
+
}
|
|
45
|
+
export interface WidgetConfig {
|
|
46
|
+
offers: Partial<Record<CancelReason, Offer>>;
|
|
47
|
+
offerEligible: boolean;
|
|
48
|
+
review: {
|
|
49
|
+
moments: Record<string, number>;
|
|
50
|
+
minDaysSinceInstall: number;
|
|
51
|
+
maxPerYear: number;
|
|
52
|
+
quietDaysAfterFriction: number;
|
|
53
|
+
quietDaysAfterRefundOrCancel: number;
|
|
54
|
+
};
|
|
55
|
+
quietScreens: string[];
|
|
56
|
+
customActions: {
|
|
57
|
+
id: string;
|
|
58
|
+
label: string;
|
|
59
|
+
}[];
|
|
60
|
+
}
|
|
61
|
+
export interface Friction {
|
|
62
|
+
kind: 'purchase_fail' | 'rage' | 'error';
|
|
63
|
+
screen?: string | null;
|
|
64
|
+
element?: string | null;
|
|
13
65
|
}
|
|
66
|
+
export type Trigger = Friction | {
|
|
67
|
+
kind: 'offer';
|
|
68
|
+
screen?: null;
|
|
69
|
+
element: CancelReason;
|
|
70
|
+
};
|
|
71
|
+
export type SupportEventKind = 'action' | 'cancel_started' | 'cancel_reason' | 'offer_shown' | 'offer_accepted' | 'cancel_continued' | 'refund_help' | 'refund_requested' | 'review_prompt' | 'friction_shown' | 'friction_opened' | 'friction_dismissed';
|
|
14
72
|
export interface LocalAttachment {
|
|
15
73
|
uri: string;
|
|
16
74
|
type?: string;
|
|
@@ -37,7 +95,7 @@ export interface Message {
|
|
|
37
95
|
meta?: Record<string, unknown> | null;
|
|
38
96
|
deliveredAt?: number | null;
|
|
39
97
|
localId?: string;
|
|
40
|
-
pending?: 'sending' | 'failed';
|
|
98
|
+
pending?: 'sending' | 'waiting' | 'failed';
|
|
41
99
|
}
|
|
42
100
|
export interface UserInfo {
|
|
43
101
|
userId?: string;
|
|
@@ -64,6 +122,12 @@ export interface SupportConfig {
|
|
|
64
122
|
serverUrl: string;
|
|
65
123
|
storage?: KeyValueStorage;
|
|
66
124
|
device?: () => DeviceInfo | Promise<DeviceInfo>;
|
|
125
|
+
aiConsent?: boolean;
|
|
126
|
+
onAction?: (action: SupportAction) => ActionResult | void | Promise<ActionResult | void>;
|
|
127
|
+
openUrl?: (url: string) => unknown;
|
|
128
|
+
requestReview?: () => unknown;
|
|
129
|
+
appStoreId?: string;
|
|
130
|
+
analytics?: ErasableAnalytics | null;
|
|
67
131
|
}
|
|
68
132
|
export interface SupportState {
|
|
69
133
|
status: Status;
|
|
@@ -76,6 +140,10 @@ export interface SupportState {
|
|
|
76
140
|
activeConversationId: string | null;
|
|
77
141
|
error: string | null;
|
|
78
142
|
typing: Record<string, Typing>;
|
|
143
|
+
aiConsent: boolean | null;
|
|
144
|
+
subscription: Subscription | null;
|
|
145
|
+
widget: WidgetConfig | null;
|
|
146
|
+
friction: Friction | null;
|
|
79
147
|
}
|
|
80
148
|
export declare function receiptOf(m: Message, list: Message[], conv: Conversation | undefined, offline?: boolean): Receipt | null;
|
|
81
149
|
export declare const attachmentsOf: (m: Message) => (Partial<Attachment> & {
|
|
@@ -91,6 +159,13 @@ export declare class SupportClient {
|
|
|
91
159
|
private storage;
|
|
92
160
|
private listeners;
|
|
93
161
|
private state;
|
|
162
|
+
private subscriptionSet;
|
|
163
|
+
private ledger;
|
|
164
|
+
private session_;
|
|
165
|
+
private pendingTrigger;
|
|
166
|
+
private offerShown;
|
|
167
|
+
private eraseTimer;
|
|
168
|
+
private eraseStep;
|
|
94
169
|
private typingTimers;
|
|
95
170
|
private session;
|
|
96
171
|
private anonId;
|
|
@@ -118,6 +193,21 @@ export declare class SupportClient {
|
|
|
118
193
|
request<T>(method: 'GET' | 'POST', path: string, body?: unknown): Promise<T>;
|
|
119
194
|
identify(user?: UserInfo): Promise<void>;
|
|
120
195
|
ensureIdentified(): Promise<void>;
|
|
196
|
+
setAiConsent(allowed: boolean): Promise<void>;
|
|
197
|
+
setSubscription(sub: Subscription | null): Promise<void>;
|
|
198
|
+
private loadWidget;
|
|
199
|
+
track(kind: SupportEventKind, data?: Record<string, string | number | boolean>, conversationId?: string | null): void;
|
|
200
|
+
runAction(action: SupportAction, conversationId?: string | null): Promise<ActionResult>;
|
|
201
|
+
fallbackUrl(action: Pick<SupportAction, 'kind' | 'value'>): string | null;
|
|
202
|
+
private openFallback;
|
|
203
|
+
rate(conversationId: string, score: 1 | -1, comment?: string): Promise<void>;
|
|
204
|
+
reviewMoment(name: string): Promise<boolean>;
|
|
205
|
+
friction(f: Friction): void;
|
|
206
|
+
openFriction(): void;
|
|
207
|
+
askForOffer(reason: CancelReason): void;
|
|
208
|
+
dismissFriction(): void;
|
|
209
|
+
private ledgerSet;
|
|
210
|
+
private platform;
|
|
121
211
|
setPushToken(token: string | null, platform?: string): Promise<void>;
|
|
122
212
|
private sendPushToken;
|
|
123
213
|
open(conversationId?: string | null): void;
|
|
@@ -149,5 +239,8 @@ export declare class SupportClient {
|
|
|
149
239
|
get reconnectAttempts(): number;
|
|
150
240
|
disconnect(): void;
|
|
151
241
|
stop(): void;
|
|
242
|
+
deleteMyData(): Promise<'done' | 'pending'>;
|
|
243
|
+
private erasing;
|
|
244
|
+
private flushErase;
|
|
152
245
|
reset(): Promise<void>;
|
|
153
246
|
}
|