react-native-newinstance-chat 0.1.2 → 0.3.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/NewinstanceChat.podspec +1 -1
- package/README.md +210 -3
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/newinstancechat/NewinstanceChatModule.kt +145 -12
- package/ios/NewinstanceChat.mm +10 -0
- package/ios/NewinstanceChatImpl.swift +104 -18
- package/lib/module/NativeNewinstanceChat.js.map +1 -1
- package/lib/module/index.js +29 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeNewinstanceChat.d.ts +3 -1
- package/lib/typescript/src/NativeNewinstanceChat.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +16 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +156 -3
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +9 -3
- package/src/NativeNewinstanceChat.ts +3 -1
- package/src/index.tsx +31 -1
- package/src/types.ts +180 -3
package/src/types.ts
CHANGED
|
@@ -15,20 +15,149 @@ export interface NewinstanceChatConfig {
|
|
|
15
15
|
transport?: 'sse' | 'ws';
|
|
16
16
|
/** Optional message pre-seeded as the first outbound message. */
|
|
17
17
|
initialMessage?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Local theme. Ranked BELOW whatever the merchant configured in the
|
|
20
|
+
* dashboard and ABOVE the SDK's built-in palette, merged per property, so a
|
|
21
|
+
* token you set here applies only where the dashboard did not set one.
|
|
22
|
+
*/
|
|
23
|
+
theme?: ChatThemeOverride;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Local theme tokens. Every field is optional; colours are hex strings
|
|
28
|
+
* (`#RRGGBB` or `#AARRGGBB`). An unparseable value is ignored rather than
|
|
29
|
+
* throwing, so a bad colour can never crash the app.
|
|
30
|
+
*/
|
|
31
|
+
export interface ChatThemeOverride {
|
|
32
|
+
/**
|
|
33
|
+
* Force light or dark. Omit for "no opinion": the dashboard's mode wins if
|
|
34
|
+
* it set one, otherwise the device setting.
|
|
35
|
+
*/
|
|
36
|
+
mode?: 'light' | 'dark';
|
|
37
|
+
chatBackground?: string;
|
|
38
|
+
headerBackground?: string;
|
|
39
|
+
headerPrimaryText?: string;
|
|
40
|
+
headerSecondaryText?: string;
|
|
41
|
+
headerIcon?: string;
|
|
42
|
+
closeButton?: string;
|
|
43
|
+
receivedBubble?: string;
|
|
44
|
+
receivedText?: string;
|
|
45
|
+
receivedTimestamp?: string;
|
|
46
|
+
sentBubble?: string;
|
|
47
|
+
sentText?: string;
|
|
48
|
+
sentTimestamp?: string;
|
|
49
|
+
systemMessageText?: string;
|
|
50
|
+
daySeparatorBackground?: string;
|
|
51
|
+
daySeparatorText?: string;
|
|
52
|
+
footerContainer?: string;
|
|
53
|
+
chatInputBackground?: string;
|
|
54
|
+
chatInputText?: string;
|
|
55
|
+
chatInputPlaceholder?: string;
|
|
56
|
+
chatInputBorder?: string;
|
|
57
|
+
sendButtonBackground?: string;
|
|
58
|
+
sendButtonIcon?: string;
|
|
59
|
+
attachmentButton?: string;
|
|
60
|
+
unreadBadgeBackground?: string;
|
|
61
|
+
unreadBadgeText?: string;
|
|
18
62
|
}
|
|
19
63
|
|
|
20
64
|
export interface ChatUser {
|
|
21
65
|
customerName: string;
|
|
22
66
|
customerEmail?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Your reference for this customer. Sent for agent context but NOT trusted
|
|
69
|
+
* as identity: an id asserted by app code cannot be verified. For a trusted
|
|
70
|
+
* identity use `customerToken`.
|
|
71
|
+
*/
|
|
23
72
|
customerId?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Chat identity token minted by YOUR backend with `createCsCustomerToken`
|
|
75
|
+
* and handed to the app. When set it is the authoritative identity: the
|
|
76
|
+
* server derives name, email and customer id from its signed claims, so a
|
|
77
|
+
* tampered app cannot impersonate another customer.
|
|
78
|
+
*/
|
|
79
|
+
customerToken?: string;
|
|
24
80
|
}
|
|
25
81
|
|
|
26
|
-
|
|
82
|
+
export type AttachmentSourceType =
|
|
83
|
+
| 'auto'
|
|
84
|
+
| 'base64'
|
|
85
|
+
| 'dataUri'
|
|
86
|
+
| 'file'
|
|
87
|
+
| 'contentUri'
|
|
88
|
+
| 'url';
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A programmatic attachment. Provide `source` + optional `sourceType`
|
|
92
|
+
* (`'auto'` detects data URIs, `content://`/`file://` URIs, absolute
|
|
93
|
+
* paths, http(s) URLs — remote URLs upload only when the native SDK is
|
|
94
|
+
* configured with `allowRemoteAttachmentUrls` — and raw base64).
|
|
95
|
+
* The legacy `uri` field keeps working and behaves like
|
|
96
|
+
* `source` + `sourceType: 'auto'`.
|
|
97
|
+
*/
|
|
27
98
|
export interface AttachmentInput {
|
|
28
|
-
/**
|
|
29
|
-
|
|
99
|
+
/** Attachment data or locator, interpreted per `sourceType`. */
|
|
100
|
+
source?: string;
|
|
101
|
+
sourceType?: AttachmentSourceType;
|
|
102
|
+
/** @deprecated Use `source`. Local file URI, still fully supported. */
|
|
103
|
+
uri?: string;
|
|
104
|
+
name: string;
|
|
105
|
+
/** Required unless the source itself carries one (data URIs, content URIs) or the extension resolves it. */
|
|
106
|
+
mimeType?: string;
|
|
107
|
+
/** Expected byte size — validated against the resolved data as a corruption guard. */
|
|
108
|
+
size?: number;
|
|
109
|
+
/** Free-form string metadata carried on the queued attachment. */
|
|
110
|
+
metadata?: Record<string, string>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type AttachmentStatus =
|
|
114
|
+
| 'queued'
|
|
115
|
+
| 'uploading'
|
|
116
|
+
| 'uploaded'
|
|
117
|
+
| 'failed'
|
|
118
|
+
| 'cancelled';
|
|
119
|
+
|
|
120
|
+
/** Streamed on `attachmentUpdated` for every attachment state/progress change. */
|
|
121
|
+
export interface AttachmentUpdate {
|
|
122
|
+
id: string;
|
|
30
123
|
name: string;
|
|
31
124
|
mimeType: string;
|
|
125
|
+
size: number;
|
|
126
|
+
status: AttachmentStatus;
|
|
127
|
+
/** 0..1 — real byte progress while uploading. */
|
|
128
|
+
progress: number;
|
|
129
|
+
/** Public URL once `status === 'uploaded'`. */
|
|
130
|
+
url?: string;
|
|
131
|
+
/** Failure reason once `status === 'failed'`. */
|
|
132
|
+
error?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type ChatCloseReason =
|
|
136
|
+
| 'close_button'
|
|
137
|
+
| 'back_navigation'
|
|
138
|
+
| 'gesture'
|
|
139
|
+
| 'programmatic'
|
|
140
|
+
| 'session_ended'
|
|
141
|
+
| 'host_navigation';
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Fired exactly once per chat presentation when the chat screen goes
|
|
145
|
+
* away, however it was dismissed. Never contains message contents,
|
|
146
|
+
* credentials, or attachment data.
|
|
147
|
+
*/
|
|
148
|
+
export interface ChatClosedEvent {
|
|
149
|
+
reason: ChatCloseReason;
|
|
150
|
+
initiator: 'user' | 'host' | 'sdk';
|
|
151
|
+
/** Unix milliseconds. */
|
|
152
|
+
timestamp: number;
|
|
153
|
+
conversationId?: string;
|
|
154
|
+
assignmentId?: string;
|
|
155
|
+
channel: string;
|
|
156
|
+
previousState: string;
|
|
157
|
+
unreadCount: number;
|
|
158
|
+
hasDraft: boolean;
|
|
159
|
+
pendingAttachmentCount: number;
|
|
160
|
+
metadata: Record<string, string>;
|
|
32
161
|
}
|
|
33
162
|
|
|
34
163
|
export type ConnectionState =
|
|
@@ -66,9 +195,55 @@ export type NewinstanceChatErrorType =
|
|
|
66
195
|
| 'auth'
|
|
67
196
|
| 'system';
|
|
68
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Stable, cross-platform diagnostic codes. The same strings are emitted by the
|
|
200
|
+
* web, Android, iOS and Flutter SDKs, so `code` is the value to branch on and
|
|
201
|
+
* to quote in a support request.
|
|
202
|
+
*/
|
|
203
|
+
export type NewinstanceChatErrorCode =
|
|
204
|
+
/** The API key was rejected: wrong key, wrong environment, revoked, or expired. */
|
|
205
|
+
| 'INVALID_PUBLIC_KEY'
|
|
206
|
+
/** No API key was supplied. */
|
|
207
|
+
| 'MISSING_WIDGET_KEY'
|
|
208
|
+
/** The key is valid but no chat configuration exists for the organization. */
|
|
209
|
+
| 'CHAT_CONFIG_UNAVAILABLE'
|
|
210
|
+
/** The key and config are fine, but chat is switched off in the dashboard. */
|
|
211
|
+
| 'CHAT_DISABLED'
|
|
212
|
+
/** Remote configuration could not be fetched; the built-in theme is in use. */
|
|
213
|
+
| 'CONFIG_FETCH_FAILED'
|
|
214
|
+
/** The chat identity token was malformed, expired, or signed for another organization. */
|
|
215
|
+
| 'INVALID_IDENTITY_TOKEN'
|
|
216
|
+
/** A request could not reach the backend at all. */
|
|
217
|
+
| 'NETWORK_ERROR'
|
|
218
|
+
/** The realtime transport dropped and could not be re-established. */
|
|
219
|
+
| 'TRANSPORT_ERROR'
|
|
220
|
+
/** Starting a conversation failed. */
|
|
221
|
+
| 'CHAT_INITIALIZATION_FAILED'
|
|
222
|
+
/** A message could not be delivered. */
|
|
223
|
+
| 'MESSAGE_SEND_FAILED'
|
|
224
|
+
/** An attachment could not be uploaded. */
|
|
225
|
+
| 'ATTACHMENT_FAILED'
|
|
226
|
+
/** The backend answered, but not with anything the SDK could use. */
|
|
227
|
+
| 'SERVER_ERROR';
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Delivered on the `error` event. This is the channel for "why is my chat not
|
|
231
|
+
* working": it is never rendered inside the chat interface, and it never
|
|
232
|
+
* carries the API key, the identity token, or customer personal data.
|
|
233
|
+
*/
|
|
69
234
|
export interface NewinstanceChatError {
|
|
235
|
+
/** Stable code to branch on. Undefined only from SDK versions older than 0.3.0. */
|
|
236
|
+
code?: NewinstanceChatErrorCode;
|
|
237
|
+
/** Broad category, kept for backwards compatibility with 0.2.x handlers. */
|
|
70
238
|
type: NewinstanceChatErrorType;
|
|
239
|
+
/** Safe to log and to show a developer. Not written for end users. */
|
|
71
240
|
message: string;
|
|
241
|
+
/**
|
|
242
|
+
* Extra detail for developers, when the SDK had any that was safe to
|
|
243
|
+
* expose. Never a raw server response body.
|
|
244
|
+
*/
|
|
245
|
+
developerMessage?: string;
|
|
246
|
+
/** False when the SDK has given up until the host fixes something. */
|
|
72
247
|
recoverable: boolean;
|
|
73
248
|
}
|
|
74
249
|
|
|
@@ -80,6 +255,8 @@ export interface EventMap {
|
|
|
80
255
|
connectionStateChanged: (state: ConnectionState) => void;
|
|
81
256
|
unreadCountChanged: (count: number) => void;
|
|
82
257
|
error: (e: NewinstanceChatError) => void;
|
|
258
|
+
attachmentUpdated: (attachment: AttachmentUpdate) => void;
|
|
259
|
+
chatClosed: (event: ChatClosedEvent) => void;
|
|
83
260
|
}
|
|
84
261
|
|
|
85
262
|
export type EventName = keyof EventMap;
|