@webotme/react-native 0.1.1

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/src/types.ts ADDED
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Public type surface for @webotme/react-native.
3
+ *
4
+ * The `Native*` types mirror the `screenContext` contract documented at
5
+ * /docs -> "Native & mobile apps". Send them and the same AutoFlow engine that
6
+ * guides the web widget will guide your app.
7
+ */
8
+
9
+ export type WebotMeButton = {
10
+ id?: string;
11
+ text?: string;
12
+ accessibilityLabel?: string;
13
+ disabled?: boolean;
14
+ };
15
+
16
+ export type WebotMeField = {
17
+ id?: string;
18
+ label?: string;
19
+ placeholder?: string;
20
+ name?: string;
21
+ type?: string;
22
+ value?: string;
23
+ required?: boolean;
24
+ options?: string[];
25
+ };
26
+
27
+ export type WebotMeLink = {
28
+ id?: string;
29
+ text?: string;
30
+ route?: string;
31
+ };
32
+
33
+ export type WebotMeList = {
34
+ label?: string;
35
+ items?: string[];
36
+ };
37
+
38
+ /**
39
+ * A snapshot of the screen the user is currently on. AutoFlow reads this
40
+ * instead of a DOM, which is what lets it pick the right next action.
41
+ */
42
+ export type WebotMeScreenContext = {
43
+ name?: string;
44
+ title?: string;
45
+ visibleText?: string[];
46
+ buttons?: WebotMeButton[];
47
+ forms?: WebotMeField[];
48
+ links?: WebotMeLink[];
49
+ alerts?: string[];
50
+ lists?: WebotMeList[];
51
+ };
52
+
53
+ export type WebotMeMessage = {
54
+ id: string;
55
+ from: "user" | "bot";
56
+ text: string;
57
+ createdAt: number;
58
+ /** Present when the server attached a native action (AutoFlow). */
59
+ action?: WebotMeAction;
60
+ pending?: boolean;
61
+ failed?: boolean;
62
+ };
63
+
64
+ export type WebotMeAction =
65
+ | { type: "navigate"; data: { url: string }; label?: string }
66
+ | { type: "click"; data: { selector?: string; text?: string; section?: string }; label?: string }
67
+ | { type: "fill"; data: { label?: string; selector?: string; text: string; currentValue?: string }; label?: string }
68
+ | { type: "checkout"; data: { url: string }; label?: string };
69
+
70
+ /** Pending multi-step workflow from server. */
71
+ export type WebotMePendingWorkflow = {
72
+ goal: string;
73
+ plan: string[];
74
+ done?: string[];
75
+ };
76
+
77
+ export type WebotMeAutoTask = {
78
+ goal: string;
79
+ plan: string[];
80
+ done?: string[];
81
+ };
82
+
83
+ /** Error codes returned by POST /native-chat/v1 (stable across versions). */
84
+ export type WebotMeErrorCode =
85
+ | "INVALID_REQUEST"
86
+ | "UNAUTHORIZED"
87
+ | "FORBIDDEN"
88
+ | "BOT_NOT_FOUND"
89
+ | "RATE_LIMITED"
90
+ | "PLAN_LIMIT_REACHED"
91
+ | "AI_UNAVAILABLE"
92
+ | "INTERNAL_ERROR"
93
+ | "NETWORK_ERROR";
94
+
95
+ export class WebotMeError extends Error {
96
+ code: WebotMeErrorCode;
97
+ status?: number;
98
+
99
+ constructor(code: WebotMeErrorCode, message: string, status?: number) {
100
+ super(message);
101
+ this.name = "WebotMeError";
102
+ this.code = code;
103
+ this.status = status;
104
+ }
105
+ }
106
+
107
+ export type WebotMeCapabilities = {
108
+ chat: boolean;
109
+ screenContext: boolean;
110
+ autoFlow: boolean;
111
+ fileUpload: boolean;
112
+ voice: boolean;
113
+ };
114
+
115
+ export type WebotMeContract = {
116
+ version: string;
117
+ botId: string;
118
+ endpoints: Record<string, string>;
119
+ capabilities: WebotMeCapabilities;
120
+ };
121
+
122
+ export type WebotMeTheme = {
123
+ primary?: string;
124
+ background?: string;
125
+ surface?: string;
126
+ text?: string;
127
+ muted?: string;
128
+ radius?: number;
129
+ };
130
+
131
+ export type WebotMeConfig = {
132
+ /** Bot ID from the WebotMe dashboard. */
133
+ botId: string;
134
+ /** Backend base URL, e.g. https://your-api.com (never localhost on device). */
135
+ apiBaseUrl: string;
136
+ /**
137
+ * Frontend base URL that serves the shareable chat page, e.g.
138
+ * https://your-frontend.com. Required by the WebView widget; falls back to
139
+ * apiBaseUrl when omitted.
140
+ */
141
+ chatBaseUrl?: string;
142
+ /** Stable visitor id. Generated and persisted when omitted. */
143
+ userId?: string;
144
+ theme?: WebotMeTheme;
145
+ /** Shown above the first bot message. */
146
+ welcome?: string;
147
+ /** Send this screen context with every message. */
148
+ screenContext?: WebotMeScreenContext;
149
+ /** Milliseconds before a send is treated as failed. Default 30000. */
150
+ timeoutMs?: number;
151
+ };