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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeNewinstanceChat.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;;AAEpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeNewinstanceChat.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;;AAEpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoBA,eAAeA,mBAAmB,CAACC,YAAY,CAAO,iBAAiB,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -29,11 +29,27 @@ export class NewinstanceChat {
|
|
|
29
29
|
* Identify the customer. Safe to call before or after `initialize()`. If
|
|
30
30
|
* called before `configure()` resolves, the user is queued and applied
|
|
31
31
|
* once the native instance exists.
|
|
32
|
+
*
|
|
33
|
+
* Prefer `customerToken`: it is minted by your backend, so the server can
|
|
34
|
+
* verify who the customer is. `customerName` / `customerEmail` /
|
|
35
|
+
* `customerId` alone are client-asserted and are not trusted as identity.
|
|
32
36
|
*/
|
|
33
37
|
setUser(user) {
|
|
34
38
|
NativeNewinstanceChat.setUser(user);
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Identify the customer with a backend-minted chat identity token only.
|
|
43
|
+
* Nothing else needs to be supplied: the server derives the name, email and
|
|
44
|
+
* customer id from the token's signed claims.
|
|
45
|
+
*/
|
|
46
|
+
setUserToken(customerToken) {
|
|
47
|
+
NativeNewinstanceChat.setUser({
|
|
48
|
+
customerName: 'Customer',
|
|
49
|
+
customerToken
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
37
53
|
/**
|
|
38
54
|
* Fetch org config, restore the saved conversation, and connect the
|
|
39
55
|
* subscription transport in the background. Concurrent callers share
|
|
@@ -65,9 +81,22 @@ export class NewinstanceChat {
|
|
|
65
81
|
* uploaded reference into the next `sendMessage()`.
|
|
66
82
|
*/
|
|
67
83
|
attachFile(opts) {
|
|
84
|
+
if (!opts.source && !opts.uri) {
|
|
85
|
+
return Promise.reject(new Error('attachFile requires `source` (or the legacy `uri`)'));
|
|
86
|
+
}
|
|
68
87
|
return NativeNewinstanceChat.attachFile(opts);
|
|
69
88
|
}
|
|
70
89
|
|
|
90
|
+
/** Remove a queued attachment; cancels its upload if still in flight. */
|
|
91
|
+
removeAttachment(id) {
|
|
92
|
+
NativeNewinstanceChat.removeAttachment(id);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Remove every queued attachment and cancel in-flight uploads. */
|
|
96
|
+
clearAttachments() {
|
|
97
|
+
NativeNewinstanceChat.clearAttachments();
|
|
98
|
+
}
|
|
99
|
+
|
|
71
100
|
/**
|
|
72
101
|
* Subscribe to a native event. Returns an unsubscribe function — call it
|
|
73
102
|
* when your component unmounts to avoid leaks.
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","NativeModules","NativeNewinstanceChat","emitterSource","NewinstanceChat","emitter","constructor","config","ready","configure","setUser","user","initialize","openChat","closeChat","sendMessage","text","retryMessage","messageId","attachFile","opts","addListener","event","handler","sub","remove","destroy"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SACEA,kBAAkB,EAClBC,aAAa,QAER,cAAc;AAErB,OAAOC,qBAAqB,MAAM,4BAAyB;
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","NativeModules","NativeNewinstanceChat","emitterSource","NewinstanceChat","emitter","constructor","config","ready","configure","setUser","user","setUserToken","customerToken","customerName","initialize","openChat","closeChat","sendMessage","text","retryMessage","messageId","attachFile","opts","source","uri","Promise","reject","Error","removeAttachment","id","clearAttachments","addListener","event","handler","sub","remove","destroy"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SACEA,kBAAkB,EAClBC,aAAa,QAER,cAAc;AAErB,OAAOC,qBAAqB,MAAM,4BAAyB;AAyB3D;AACA;AACA;AACA,MAAMC,aAAkB,GACtBF,aAAa,CAACG,eAAe,IAAKF,qBAAiC;AACrE,MAAMG,OAAO,GAAG,IAAIL,kBAAkB,CAACG,aAAa,CAAC;;AAErD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,CAAC;EAC3B;;EAGAE,WAAWA,CAACC,MAA6B,EAAE;IACzC,IAAI,CAACC,KAAK,GAAGN,qBAAqB,CAACO,SAAS,CAACF,MAAM,CAAC;EACtD;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEG,OAAOA,CAACC,IAAc,EAAQ;IAC5BT,qBAAqB,CAACQ,OAAO,CAACC,IAAI,CAAC;EACrC;;EAEA;AACF;AACA;AACA;AACA;EACEC,YAAY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ACF;AACA;AACA;EACEC,OAAOA,CAAA,EAAS;IACdnC,qBAAqB,CAACmC,OAAO,CAAC,CAAC;EACjC;AACF","ignoreList":[]}
|
|
@@ -17,7 +17,9 @@ export interface Spec extends TurboModule {
|
|
|
17
17
|
closeChat(): void;
|
|
18
18
|
sendMessage(text: string): void;
|
|
19
19
|
retryMessage(messageId: string): void;
|
|
20
|
-
attachFile(opts: Object): Promise<
|
|
20
|
+
attachFile(opts: Object): Promise<string>;
|
|
21
|
+
removeAttachment(id: string): void;
|
|
22
|
+
clearAttachments(): void;
|
|
21
23
|
destroy(): void;
|
|
22
24
|
addListener(eventName: string): void;
|
|
23
25
|
removeListeners(count: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeNewinstanceChat.d.ts","sourceRoot":"","sources":["../../../src/NativeNewinstanceChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE;;;;;;;;;GASG;AACH,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,QAAQ,IAAI,IAAI,CAAC;IACjB,SAAS,IAAI,IAAI,CAAC;IAClB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"NativeNewinstanceChat.d.ts","sourceRoot":"","sources":["../../../src/NativeNewinstanceChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE;;;;;;;;;GASG;AACH,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,QAAQ,IAAI,IAAI,CAAC;IACjB,SAAS,IAAI,IAAI,CAAC;IAClB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1C,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,gBAAgB,IAAI,IAAI,CAAC;IACzB,OAAO,IAAI,IAAI,CAAC;IAIhB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;;AAED,wBAAyE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AttachmentInput, ChatUser, EventHandler, EventName, NewinstanceChatConfig } from './types';
|
|
2
|
-
export type { AttachmentInput, ChatMessage, ChatUser, ConnectionState, EventMap, EventName, NewinstanceChatConfig, NewinstanceChatError, NewinstanceChatErrorType, } from './types';
|
|
2
|
+
export type { AttachmentInput, AttachmentUpdate, ChatClosedEvent, ChatMessage, ChatThemeOverride, ChatUser, ConnectionState, EventMap, EventName, NewinstanceChatConfig, NewinstanceChatError, NewinstanceChatErrorCode, NewinstanceChatErrorType, } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* React Native binding for the native LiveAndAiChat iOS / Android SDKs.
|
|
5
5
|
*
|
|
@@ -18,8 +18,18 @@ export declare class NewinstanceChat {
|
|
|
18
18
|
* Identify the customer. Safe to call before or after `initialize()`. If
|
|
19
19
|
* called before `configure()` resolves, the user is queued and applied
|
|
20
20
|
* once the native instance exists.
|
|
21
|
+
*
|
|
22
|
+
* Prefer `customerToken`: it is minted by your backend, so the server can
|
|
23
|
+
* verify who the customer is. `customerName` / `customerEmail` /
|
|
24
|
+
* `customerId` alone are client-asserted and are not trusted as identity.
|
|
21
25
|
*/
|
|
22
26
|
setUser(user: ChatUser): void;
|
|
27
|
+
/**
|
|
28
|
+
* Identify the customer with a backend-minted chat identity token only.
|
|
29
|
+
* Nothing else needs to be supplied: the server derives the name, email and
|
|
30
|
+
* customer id from the token's signed claims.
|
|
31
|
+
*/
|
|
32
|
+
setUserToken(customerToken: string): void;
|
|
23
33
|
/**
|
|
24
34
|
* Fetch org config, restore the saved conversation, and connect the
|
|
25
35
|
* subscription transport in the background. Concurrent callers share
|
|
@@ -37,7 +47,11 @@ export declare class NewinstanceChat {
|
|
|
37
47
|
* `uri`, pushes them through the SDK's upload pipeline, and bundles the
|
|
38
48
|
* uploaded reference into the next `sendMessage()`.
|
|
39
49
|
*/
|
|
40
|
-
attachFile(opts: AttachmentInput): Promise<
|
|
50
|
+
attachFile(opts: AttachmentInput): Promise<string>;
|
|
51
|
+
/** Remove a queued attachment; cancels its upload if still in flight. */
|
|
52
|
+
removeAttachment(id: string): void;
|
|
53
|
+
/** Remove every queued attachment and cancel in-flight uploads. */
|
|
54
|
+
clearAttachments(): void;
|
|
41
55
|
/**
|
|
42
56
|
* Subscribe to a native event. Returns an unsubscribe function — call it
|
|
43
57
|
* when your component unmounts to avoid leaks.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,eAAe,EACf,WAAW,EACX,QAAQ,EACR,e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;IACzE,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIlC,mEAAmE;IACnE,gBAAgB,IAAI,IAAI;IAIxB;;;OAGG;IACH,WAAW,CAAC,CAAC,SAAS,SAAS,EAC7B,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GACvB,MAAM,IAAI;IAQb;;;OAGG;IACH,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -14,18 +14,124 @@ export interface NewinstanceChatConfig {
|
|
|
14
14
|
transport?: 'sse' | 'ws';
|
|
15
15
|
/** Optional message pre-seeded as the first outbound message. */
|
|
16
16
|
initialMessage?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Local theme. Ranked BELOW whatever the merchant configured in the
|
|
19
|
+
* dashboard and ABOVE the SDK's built-in palette, merged per property, so a
|
|
20
|
+
* token you set here applies only where the dashboard did not set one.
|
|
21
|
+
*/
|
|
22
|
+
theme?: ChatThemeOverride;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Local theme tokens. Every field is optional; colours are hex strings
|
|
26
|
+
* (`#RRGGBB` or `#AARRGGBB`). An unparseable value is ignored rather than
|
|
27
|
+
* throwing, so a bad colour can never crash the app.
|
|
28
|
+
*/
|
|
29
|
+
export interface ChatThemeOverride {
|
|
30
|
+
/**
|
|
31
|
+
* Force light or dark. Omit for "no opinion": the dashboard's mode wins if
|
|
32
|
+
* it set one, otherwise the device setting.
|
|
33
|
+
*/
|
|
34
|
+
mode?: 'light' | 'dark';
|
|
35
|
+
chatBackground?: string;
|
|
36
|
+
headerBackground?: string;
|
|
37
|
+
headerPrimaryText?: string;
|
|
38
|
+
headerSecondaryText?: string;
|
|
39
|
+
headerIcon?: string;
|
|
40
|
+
closeButton?: string;
|
|
41
|
+
receivedBubble?: string;
|
|
42
|
+
receivedText?: string;
|
|
43
|
+
receivedTimestamp?: string;
|
|
44
|
+
sentBubble?: string;
|
|
45
|
+
sentText?: string;
|
|
46
|
+
sentTimestamp?: string;
|
|
47
|
+
systemMessageText?: string;
|
|
48
|
+
daySeparatorBackground?: string;
|
|
49
|
+
daySeparatorText?: string;
|
|
50
|
+
footerContainer?: string;
|
|
51
|
+
chatInputBackground?: string;
|
|
52
|
+
chatInputText?: string;
|
|
53
|
+
chatInputPlaceholder?: string;
|
|
54
|
+
chatInputBorder?: string;
|
|
55
|
+
sendButtonBackground?: string;
|
|
56
|
+
sendButtonIcon?: string;
|
|
57
|
+
attachmentButton?: string;
|
|
58
|
+
unreadBadgeBackground?: string;
|
|
59
|
+
unreadBadgeText?: string;
|
|
17
60
|
}
|
|
18
61
|
export interface ChatUser {
|
|
19
62
|
customerName: string;
|
|
20
63
|
customerEmail?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Your reference for this customer. Sent for agent context but NOT trusted
|
|
66
|
+
* as identity: an id asserted by app code cannot be verified. For a trusted
|
|
67
|
+
* identity use `customerToken`.
|
|
68
|
+
*/
|
|
21
69
|
customerId?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Chat identity token minted by YOUR backend with `createCsCustomerToken`
|
|
72
|
+
* and handed to the app. When set it is the authoritative identity: the
|
|
73
|
+
* server derives name, email and customer id from its signed claims, so a
|
|
74
|
+
* tampered app cannot impersonate another customer.
|
|
75
|
+
*/
|
|
76
|
+
customerToken?: string;
|
|
22
77
|
}
|
|
23
|
-
|
|
78
|
+
export type AttachmentSourceType = 'auto' | 'base64' | 'dataUri' | 'file' | 'contentUri' | 'url';
|
|
79
|
+
/**
|
|
80
|
+
* A programmatic attachment. Provide `source` + optional `sourceType`
|
|
81
|
+
* (`'auto'` detects data URIs, `content://`/`file://` URIs, absolute
|
|
82
|
+
* paths, http(s) URLs — remote URLs upload only when the native SDK is
|
|
83
|
+
* configured with `allowRemoteAttachmentUrls` — and raw base64).
|
|
84
|
+
* The legacy `uri` field keeps working and behaves like
|
|
85
|
+
* `source` + `sourceType: 'auto'`.
|
|
86
|
+
*/
|
|
24
87
|
export interface AttachmentInput {
|
|
25
|
-
/**
|
|
26
|
-
|
|
88
|
+
/** Attachment data or locator, interpreted per `sourceType`. */
|
|
89
|
+
source?: string;
|
|
90
|
+
sourceType?: AttachmentSourceType;
|
|
91
|
+
/** @deprecated Use `source`. Local file URI, still fully supported. */
|
|
92
|
+
uri?: string;
|
|
93
|
+
name: string;
|
|
94
|
+
/** Required unless the source itself carries one (data URIs, content URIs) or the extension resolves it. */
|
|
95
|
+
mimeType?: string;
|
|
96
|
+
/** Expected byte size — validated against the resolved data as a corruption guard. */
|
|
97
|
+
size?: number;
|
|
98
|
+
/** Free-form string metadata carried on the queued attachment. */
|
|
99
|
+
metadata?: Record<string, string>;
|
|
100
|
+
}
|
|
101
|
+
export type AttachmentStatus = 'queued' | 'uploading' | 'uploaded' | 'failed' | 'cancelled';
|
|
102
|
+
/** Streamed on `attachmentUpdated` for every attachment state/progress change. */
|
|
103
|
+
export interface AttachmentUpdate {
|
|
104
|
+
id: string;
|
|
27
105
|
name: string;
|
|
28
106
|
mimeType: string;
|
|
107
|
+
size: number;
|
|
108
|
+
status: AttachmentStatus;
|
|
109
|
+
/** 0..1 — real byte progress while uploading. */
|
|
110
|
+
progress: number;
|
|
111
|
+
/** Public URL once `status === 'uploaded'`. */
|
|
112
|
+
url?: string;
|
|
113
|
+
/** Failure reason once `status === 'failed'`. */
|
|
114
|
+
error?: string;
|
|
115
|
+
}
|
|
116
|
+
export type ChatCloseReason = 'close_button' | 'back_navigation' | 'gesture' | 'programmatic' | 'session_ended' | 'host_navigation';
|
|
117
|
+
/**
|
|
118
|
+
* Fired exactly once per chat presentation when the chat screen goes
|
|
119
|
+
* away, however it was dismissed. Never contains message contents,
|
|
120
|
+
* credentials, or attachment data.
|
|
121
|
+
*/
|
|
122
|
+
export interface ChatClosedEvent {
|
|
123
|
+
reason: ChatCloseReason;
|
|
124
|
+
initiator: 'user' | 'host' | 'sdk';
|
|
125
|
+
/** Unix milliseconds. */
|
|
126
|
+
timestamp: number;
|
|
127
|
+
conversationId?: string;
|
|
128
|
+
assignmentId?: string;
|
|
129
|
+
channel: string;
|
|
130
|
+
previousState: string;
|
|
131
|
+
unreadCount: number;
|
|
132
|
+
hasDraft: boolean;
|
|
133
|
+
pendingAttachmentCount: number;
|
|
134
|
+
metadata: Record<string, string>;
|
|
29
135
|
}
|
|
30
136
|
export type ConnectionState = 'idle' | 'connecting' | 'connected' | 'disconnected' | 'offline';
|
|
31
137
|
export interface ChatMessage {
|
|
@@ -50,9 +156,54 @@ export interface ChatMessage {
|
|
|
50
156
|
totalMessages?: number;
|
|
51
157
|
}
|
|
52
158
|
export type NewinstanceChatErrorType = 'network' | 'validation' | 'auth' | 'system';
|
|
159
|
+
/**
|
|
160
|
+
* Stable, cross-platform diagnostic codes. The same strings are emitted by the
|
|
161
|
+
* web, Android, iOS and Flutter SDKs, so `code` is the value to branch on and
|
|
162
|
+
* to quote in a support request.
|
|
163
|
+
*/
|
|
164
|
+
export type NewinstanceChatErrorCode =
|
|
165
|
+
/** The API key was rejected: wrong key, wrong environment, revoked, or expired. */
|
|
166
|
+
'INVALID_PUBLIC_KEY'
|
|
167
|
+
/** No API key was supplied. */
|
|
168
|
+
| 'MISSING_WIDGET_KEY'
|
|
169
|
+
/** The key is valid but no chat configuration exists for the organization. */
|
|
170
|
+
| 'CHAT_CONFIG_UNAVAILABLE'
|
|
171
|
+
/** The key and config are fine, but chat is switched off in the dashboard. */
|
|
172
|
+
| 'CHAT_DISABLED'
|
|
173
|
+
/** Remote configuration could not be fetched; the built-in theme is in use. */
|
|
174
|
+
| 'CONFIG_FETCH_FAILED'
|
|
175
|
+
/** The chat identity token was malformed, expired, or signed for another organization. */
|
|
176
|
+
| 'INVALID_IDENTITY_TOKEN'
|
|
177
|
+
/** A request could not reach the backend at all. */
|
|
178
|
+
| 'NETWORK_ERROR'
|
|
179
|
+
/** The realtime transport dropped and could not be re-established. */
|
|
180
|
+
| 'TRANSPORT_ERROR'
|
|
181
|
+
/** Starting a conversation failed. */
|
|
182
|
+
| 'CHAT_INITIALIZATION_FAILED'
|
|
183
|
+
/** A message could not be delivered. */
|
|
184
|
+
| 'MESSAGE_SEND_FAILED'
|
|
185
|
+
/** An attachment could not be uploaded. */
|
|
186
|
+
| 'ATTACHMENT_FAILED'
|
|
187
|
+
/** The backend answered, but not with anything the SDK could use. */
|
|
188
|
+
| 'SERVER_ERROR';
|
|
189
|
+
/**
|
|
190
|
+
* Delivered on the `error` event. This is the channel for "why is my chat not
|
|
191
|
+
* working": it is never rendered inside the chat interface, and it never
|
|
192
|
+
* carries the API key, the identity token, or customer personal data.
|
|
193
|
+
*/
|
|
53
194
|
export interface NewinstanceChatError {
|
|
195
|
+
/** Stable code to branch on. Undefined only from SDK versions older than 0.3.0. */
|
|
196
|
+
code?: NewinstanceChatErrorCode;
|
|
197
|
+
/** Broad category, kept for backwards compatibility with 0.2.x handlers. */
|
|
54
198
|
type: NewinstanceChatErrorType;
|
|
199
|
+
/** Safe to log and to show a developer. Not written for end users. */
|
|
55
200
|
message: string;
|
|
201
|
+
/**
|
|
202
|
+
* Extra detail for developers, when the SDK had any that was safe to
|
|
203
|
+
* expose. Never a raw server response body.
|
|
204
|
+
*/
|
|
205
|
+
developerMessage?: string;
|
|
206
|
+
/** False when the SDK has given up until the host fixes something. */
|
|
56
207
|
recoverable: boolean;
|
|
57
208
|
}
|
|
58
209
|
/** Native event names. Subscribe with `sdk.addListener(event, handler)`. */
|
|
@@ -63,6 +214,8 @@ export interface EventMap {
|
|
|
63
214
|
connectionStateChanged: (state: ConnectionState) => void;
|
|
64
215
|
unreadCountChanged: (count: number) => void;
|
|
65
216
|
error: (e: NewinstanceChatError) => void;
|
|
217
|
+
attachmentUpdated: (attachment: AttachmentUpdate) => void;
|
|
218
|
+
chatClosed: (event: ChatClosedEvent) => void;
|
|
66
219
|
}
|
|
67
220
|
export type EventName = keyof EventMap;
|
|
68
221
|
export type EventHandler<K extends EventName> = EventMap[K];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,qBAAqB;IACpC,qFAAqF;IACrF,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yGAAyG;IACzG,SAAS,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACzB,iEAAiE;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,qBAAqB;IACpC,qFAAqF;IACrF,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yGAAyG;IACzG,SAAS,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACzB,iEAAiE;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE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AI,CAAC;IAChD,sBAAsB,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IACzD,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,KAAK,EAAE,CAAC,CAAC,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACzC,iBAAiB,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC1D,UAAU,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;CAC9C;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC;AACvC,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,SAAS,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-newinstance-chat",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "New instance LiveAndAiChat React Native SDK
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "New instance LiveAndAiChat React Native SDK \u2014 AI + live-agent chat, drop-in native chat screen for iOS and Android.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -130,7 +130,9 @@
|
|
|
130
130
|
"preset": "@react-native/jest-preset",
|
|
131
131
|
"modulePathIgnorePatterns": [
|
|
132
132
|
"<rootDir>/example/node_modules",
|
|
133
|
-
"<rootDir>/lib/"
|
|
133
|
+
"<rootDir>/lib/",
|
|
134
|
+
"<rootDir>/example/ios",
|
|
135
|
+
"<rootDir>/example/android"
|
|
134
136
|
]
|
|
135
137
|
},
|
|
136
138
|
"release-it": {
|
|
@@ -162,5 +164,9 @@
|
|
|
162
164
|
"vite"
|
|
163
165
|
],
|
|
164
166
|
"version": "0.62.0"
|
|
167
|
+
},
|
|
168
|
+
"resolutions": {
|
|
169
|
+
"jest-environment-node": "^30.4.1",
|
|
170
|
+
"jest-mock": "^30.4.1"
|
|
165
171
|
}
|
|
166
172
|
}
|
|
@@ -18,7 +18,9 @@ export interface Spec extends TurboModule {
|
|
|
18
18
|
closeChat(): void;
|
|
19
19
|
sendMessage(text: string): void;
|
|
20
20
|
retryMessage(messageId: string): void;
|
|
21
|
-
attachFile(opts: Object): Promise<
|
|
21
|
+
attachFile(opts: Object): Promise<string>;
|
|
22
|
+
removeAttachment(id: string): void;
|
|
23
|
+
clearAttachments(): void;
|
|
22
24
|
destroy(): void;
|
|
23
25
|
|
|
24
26
|
// NativeEventEmitter on iOS calls these to track listener counts.
|
package/src/index.tsx
CHANGED
|
@@ -15,13 +15,17 @@ import type {
|
|
|
15
15
|
|
|
16
16
|
export type {
|
|
17
17
|
AttachmentInput,
|
|
18
|
+
AttachmentUpdate,
|
|
19
|
+
ChatClosedEvent,
|
|
18
20
|
ChatMessage,
|
|
21
|
+
ChatThemeOverride,
|
|
19
22
|
ChatUser,
|
|
20
23
|
ConnectionState,
|
|
21
24
|
EventMap,
|
|
22
25
|
EventName,
|
|
23
26
|
NewinstanceChatConfig,
|
|
24
27
|
NewinstanceChatError,
|
|
28
|
+
NewinstanceChatErrorCode,
|
|
25
29
|
NewinstanceChatErrorType,
|
|
26
30
|
} from './types';
|
|
27
31
|
|
|
@@ -54,11 +58,24 @@ export class NewinstanceChat {
|
|
|
54
58
|
* Identify the customer. Safe to call before or after `initialize()`. If
|
|
55
59
|
* called before `configure()` resolves, the user is queued and applied
|
|
56
60
|
* once the native instance exists.
|
|
61
|
+
*
|
|
62
|
+
* Prefer `customerToken`: it is minted by your backend, so the server can
|
|
63
|
+
* verify who the customer is. `customerName` / `customerEmail` /
|
|
64
|
+
* `customerId` alone are client-asserted and are not trusted as identity.
|
|
57
65
|
*/
|
|
58
66
|
setUser(user: ChatUser): void {
|
|
59
67
|
NativeNewinstanceChat.setUser(user);
|
|
60
68
|
}
|
|
61
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Identify the customer with a backend-minted chat identity token only.
|
|
72
|
+
* Nothing else needs to be supplied: the server derives the name, email and
|
|
73
|
+
* customer id from the token's signed claims.
|
|
74
|
+
*/
|
|
75
|
+
setUserToken(customerToken: string): void {
|
|
76
|
+
NativeNewinstanceChat.setUser({ customerName: 'Customer', customerToken });
|
|
77
|
+
}
|
|
78
|
+
|
|
62
79
|
/**
|
|
63
80
|
* Fetch org config, restore the saved conversation, and connect the
|
|
64
81
|
* subscription transport in the background. Concurrent callers share
|
|
@@ -91,10 +108,23 @@ export class NewinstanceChat {
|
|
|
91
108
|
* `uri`, pushes them through the SDK's upload pipeline, and bundles the
|
|
92
109
|
* uploaded reference into the next `sendMessage()`.
|
|
93
110
|
*/
|
|
94
|
-
attachFile(opts: AttachmentInput): Promise<
|
|
111
|
+
attachFile(opts: AttachmentInput): Promise<string> {
|
|
112
|
+
if (!opts.source && !opts.uri) {
|
|
113
|
+
return Promise.reject(new Error('attachFile requires `source` (or the legacy `uri`)'));
|
|
114
|
+
}
|
|
95
115
|
return NativeNewinstanceChat.attachFile(opts);
|
|
96
116
|
}
|
|
97
117
|
|
|
118
|
+
/** Remove a queued attachment; cancels its upload if still in flight. */
|
|
119
|
+
removeAttachment(id: string): void {
|
|
120
|
+
NativeNewinstanceChat.removeAttachment(id);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Remove every queued attachment and cancel in-flight uploads. */
|
|
124
|
+
clearAttachments(): void {
|
|
125
|
+
NativeNewinstanceChat.clearAttachments();
|
|
126
|
+
}
|
|
127
|
+
|
|
98
128
|
/**
|
|
99
129
|
* Subscribe to a native event. Returns an unsubscribe function — call it
|
|
100
130
|
* when your component unmounts to avoid leaks.
|