@zean-chat/react-native 0.1.6 → 0.1.9
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/README.md +7 -6
- package/dist/components/AppMark.d.ts +1 -1
- package/dist/components/ChatHeader.d.ts +1 -1
- package/dist/components/ChatModal.d.ts +1 -1
- package/dist/components/ChatNotice.d.ts +1 -1
- package/dist/components/ChatScreen.d.ts +1 -1
- package/dist/components/Composer.d.ts +1 -1
- package/dist/components/ContactCodeCard.d.ts +3 -3
- package/dist/components/EmailForm.d.ts +1 -1
- package/dist/components/Icon.d.ts +1 -1
- package/dist/components/ImageViewer.d.ts +1 -1
- package/dist/components/MessageBubble.d.ts +1 -1
- package/dist/components/MessageFiles.d.ts +1 -1
- package/dist/components/MessageList.d.ts +1 -1
- package/dist/components/MessageMeta.d.ts +1 -1
- package/dist/components/PendingPhotos.d.ts +1 -1
- package/dist/components/PoweredBy.d.ts +1 -1
- package/dist/components/Skeleton.d.ts +1 -1
- package/dist/components/TeamAvatar.d.ts +1 -1
- package/dist/components/TypingBubble.d.ts +1 -1
- package/dist/components/ZeanChat.d.ts +1 -1
- package/dist/i18n/en.d.ts +2 -0
- package/dist/i18n/fr.d.ts +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +165 -25
- package/dist/interfaces.d.ts +14 -7
- package/dist/models/sdk.constants.d.ts +2 -0
- package/dist/models/sdk.interface.d.ts +21 -1
- package/dist/models/sdk.utils.d.ts +15 -1
- package/package.json +27 -7
package/README.md
CHANGED
|
@@ -2,26 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
Add a free customer support chat inside your iOS and Android app, with [Zean](https://zean.chat/?utm_source=npm&utm_medium=readme&utm_campaign=react-native). Plain React Native: no native module of its own, works in Expo Go. Your App key is in your Zean dashboard.
|
|
4
4
|
|
|
5
|
+
First, in App settings, set your app's Bundle ID (iOS) and Package name (Android): the chat shows only in that app, and always in Expo Go.
|
|
6
|
+
|
|
5
7
|
```bash
|
|
6
|
-
npx expo install @zean-chat/react-native @react-native-async-storage/async-storage expo-image-picker
|
|
8
|
+
npx expo install @zean-chat/react-native expo-application @react-native-async-storage/async-storage expo-image-picker
|
|
7
9
|
# or
|
|
8
|
-
npm install @zean-chat/react-native @react-native-async-storage/async-storage react-native-image-picker
|
|
10
|
+
npm install @zean-chat/react-native react-native-device-info @react-native-async-storage/async-storage react-native-image-picker
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
The photo picker is optional: without one, the chat has no photo button.
|
|
13
|
+
Already using MMKV or Expo SQLite? Skip AsyncStorage: the chat finds your storage by itself, with no code. Already have a photo picker? Skip it too. The photo picker is optional: without one, the chat has no photo button. `expo-application` (Expo) or `react-native-device-info` (React Native CLI) is required: the chat reads your app's Bundle ID or Package name with it, and stays hidden without it.
|
|
12
14
|
|
|
13
15
|
```tsx
|
|
14
|
-
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
15
16
|
import { ZeanChat, useZean } from "@zean-chat/react-native";
|
|
16
17
|
|
|
17
18
|
// Once, at the root of the app (beside the navigator, or in app/_layout.tsx with Expo Router).
|
|
18
|
-
<ZeanChat appKey="app_your_app_key"
|
|
19
|
+
<ZeanChat appKey="app_your_app_key" user={user ? { id: user.id, name: user.name, email: user.email } : undefined} locale="fr" />;
|
|
19
20
|
|
|
20
21
|
// Anywhere. The chat opens in a modal over the app.
|
|
21
22
|
const { open, close, toggle, unreadCount, identify, signOut, setAttributes } = useZean();
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
Passing `user` signs the person in; `undefined` signs them out. `locale` (`fr`, `en`) and `colorScheme` (`light`, `dark`) default to the phone's. `maxPhotos` sets the photos per message, 1 to 6; 4 by default.
|
|
25
|
+
Passing `user` signs the person in; `undefined` signs them out. `locale` (`fr`, `en`) and `colorScheme` (`light`, `dark`) default to the phone's. `maxPhotos` sets the photos per message, 1 to 6; 4 by default. The chat keeps the newest 100 messages in your app's storage: it shows them at once and downloads only new ones. To choose the storage, pass `storage`: AsyncStorage, an MMKV instance (any version) or anything with `getItem` and `setItem`. Full guide: [install the chat in React Native and Expo](https://zean.chat/docs/install-react-native), [React Native reference](https://zean.chat/docs/reference-react-native).
|
|
25
26
|
|
|
26
27
|
## Why Zean
|
|
27
28
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AppMarkProps } from '../models/sdk.interface';
|
|
2
2
|
/** The App in the header: its logo in a circle, as the dashboard shows it, else a chat bubble in its colour. */
|
|
3
|
-
export declare function AppMark({ app }: AppMarkProps): import("react
|
|
3
|
+
export declare function AppMark({ app }: AppMarkProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ChatHeaderProps } from '../models/sdk.interface';
|
|
2
2
|
/** The App's name and whether the team is there: one short row, so the Conversation keeps the room, even on a small phone. */
|
|
3
|
-
export declare function ChatHeader({ app, online, topInset, onClose }: ChatHeaderProps): import("react
|
|
3
|
+
export declare function ChatHeader({ app, online, topInset, onClose }: ChatHeaderProps): import("react").JSX.Element;
|
|
@@ -4,4 +4,4 @@ import type { ChatModalProps } from '../models/sdk.interface';
|
|
|
4
4
|
* screen on Android, closed with back, and on an iPad. It shows once the App and the Conversation are loaded, in the
|
|
5
5
|
* App's colour and the Contact's language.
|
|
6
6
|
*/
|
|
7
|
-
export declare function ChatModal({ chat, colorScheme, maxPhotos }: ChatModalProps): import("react
|
|
7
|
+
export declare function ChatModal({ chat, colorScheme, maxPhotos }: ChatModalProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ChatNoticeProps } from '../models/sdk.interface';
|
|
2
2
|
/** A card from the chat itself: offline, blocked, unavailable. */
|
|
3
|
-
export declare function ChatNotice({ children }: ChatNoticeProps): import("react
|
|
3
|
+
export declare function ChatNotice({ children }: ChatNoticeProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ChatScreenProps } from '../models/sdk.interface';
|
|
2
2
|
/** The open chat: the header, the Conversation, and the message field above the keyboard. */
|
|
3
|
-
export declare function ChatScreen({ state, insets, onClose }: ChatScreenProps): import("react
|
|
3
|
+
export declare function ChatScreen({ state, insets, onClose }: ChatScreenProps): import("react").JSX.Element;
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* in the App's colour. 16 point text; the field grows with the text up to five lines. Emoji come from the phone's keyboard.
|
|
4
4
|
* Picked photos show above the field and upload when the message is sent.
|
|
5
5
|
*/
|
|
6
|
-
export declare function Composer(): import("react
|
|
6
|
+
export declare function Composer(): import("react").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContactCodeCardProps } from '../models/sdk.interface';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* A Contact code to the person's email: it joins this device to their Conversation (ADR 0010), or brings in what they
|
|
4
|
+
* wrote before signing in (ADR 0014). The code field takes the code the phone offers from the email.
|
|
5
5
|
*/
|
|
6
|
-
export declare function ContactCodeCard({ code, onDismiss }: ContactCodeCardProps): import("react
|
|
6
|
+
export declare function ContactCodeCard({ code, onDismiss }: ContactCodeCardProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { EmailFormProps } from '../models/sdk.interface';
|
|
2
2
|
/** Asked once the Contact has written, until they leave an email: where the team reaches them back. */
|
|
3
|
-
export declare function EmailForm({ onSubmit }: EmailFormProps): import("react
|
|
3
|
+
export declare function EmailForm({ onSubmit }: EmailFormProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { IconProps } from '../models/sdk.interface';
|
|
2
2
|
/** One of the chat's icons, in a colour. Decorative: the button around it carries the name. */
|
|
3
|
-
export declare function Icon({ name, color, size }: IconProps): import("react
|
|
3
|
+
export declare function Icon({ name, color, size }: IconProps): import("react").JSX.Element;
|
|
@@ -3,4 +3,4 @@ import type { ImageViewerProps } from '../models/sdk.interface';
|
|
|
3
3
|
* A message's images at full size over the chat, swiped from one to the next, pinched to zoom on iOS. The close button,
|
|
4
4
|
* or Android's back, goes back to the chat.
|
|
5
5
|
*/
|
|
6
|
-
export declare function ImageViewer({ gallery, topInset, onClose }: ImageViewerProps): import("react
|
|
6
|
+
export declare function ImageViewer({ gallery, topInset, onClose }: ImageViewerProps): import("react").JSX.Element;
|
|
@@ -3,4 +3,4 @@ import type { MessageBubbleProps } from '../models/sdk.interface';
|
|
|
3
3
|
* One message: the Contact's on the right in the App's colour, the team's on the left beside the sender's avatar.
|
|
4
4
|
* Messages of a run sit close, with tight corners where they meet; the run's last one carries the time.
|
|
5
5
|
*/
|
|
6
|
-
export declare function MessageBubble({ row, app, onRetry }: MessageBubbleProps): import("react
|
|
6
|
+
export declare function MessageBubble({ row, app, onRetry }: MessageBubbleProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { MessageFilesProps } from '../models/sdk.interface';
|
|
2
2
|
/** A message's files: images that open in the viewer, a bone while each one's link is signed, other files to open. */
|
|
3
|
-
export declare function MessageFiles({ attachments, own, stored }: MessageFilesProps): import("react
|
|
3
|
+
export declare function MessageFiles({ attachments, own, stored }: MessageFilesProps): import("react").JSX.Element | null;
|
|
@@ -4,4 +4,4 @@ import type { MessageListProps } from '../models/sdk.interface';
|
|
|
4
4
|
* new messages stay in view, and older ones loaded at the top keep the reader's place. Scrolled up, a button goes back
|
|
5
5
|
* to the latest message; the Contact's own message brings them back too.
|
|
6
6
|
*/
|
|
7
|
-
export declare function MessageList({ state }: MessageListProps): import("react
|
|
7
|
+
export declare function MessageList({ state }: MessageListProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { MessageMetaProps } from '../models/sdk.interface';
|
|
2
2
|
/** Under the last message of a run: its time, and for the Contact's own how far it went, or why it did not go. */
|
|
3
|
-
export declare function MessageMeta({ row, onRetry }: MessageMetaProps): import("react
|
|
3
|
+
export declare function MessageMeta({ row, onRetry }: MessageMetaProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PendingPhotosProps } from '../models/sdk.interface';
|
|
2
2
|
/** The photos going with the next message, above the field: a spinner while each uploads, red when it did not. */
|
|
3
|
-
export declare function PendingPhotos({ photos, locked, onRemove }: PendingPhotosProps): import("react
|
|
3
|
+
export declare function PendingPhotos({ photos, locked, onRemove }: PendingPhotosProps): import("react").JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The badge the Plan shows, in the product's own colour. Opens the public site. */
|
|
2
|
-
export declare function PoweredBy(): import("react
|
|
2
|
+
export declare function PoweredBy(): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SkeletonProps } from '../models/sdk.interface';
|
|
2
2
|
/** A bone that breathes where something is loading. Its size and shape come from `style`. */
|
|
3
|
-
export declare function Skeleton({ style }: SkeletonProps): import("react
|
|
3
|
+
export declare function Skeleton({ style }: SkeletonProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TeamAvatarProps } from '../models/sdk.interface';
|
|
2
2
|
/** Beside the team's messages: the Member's photo or initials, else the App's logo or initial. */
|
|
3
|
-
export declare function TeamAvatar({ app, sender }: TeamAvatarProps): import("react
|
|
3
|
+
export declare function TeamAvatar({ app, sender }: TeamAvatarProps): import("react").JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TypingBubbleProps } from '../models/sdk.interface';
|
|
2
2
|
/** Three dots that bounce in turn while a Member writes a reply. */
|
|
3
|
-
export declare function TypingBubble({ app, sender }: TypingBubbleProps): import("react
|
|
3
|
+
export declare function TypingBubble({ app, sender }: TypingBubbleProps): import("react").JSX.Element;
|
|
@@ -3,4 +3,4 @@ import type { ZeanChatProps } from '../interfaces';
|
|
|
3
3
|
* The chat. Render it once, near the root of the app, inside or outside any navigator: it opens in its own modal when
|
|
4
4
|
* `open()` from `useZean()` is called, and shows nothing until then.
|
|
5
5
|
*/
|
|
6
|
-
export declare function ZeanChat({ appKey, storage, user, attributes, locale, colorScheme, maxPhotos, backendUrl }: ZeanChatProps): import("react
|
|
6
|
+
export declare function ZeanChat({ appKey, storage, user, attributes, locale, colorScheme, maxPhotos, backendUrl }: ZeanChatProps): import("react").JSX.Element | null;
|
package/dist/i18n/en.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare const en: {
|
|
|
24
24
|
email_saved: string;
|
|
25
25
|
error: string;
|
|
26
26
|
code_prompt: string;
|
|
27
|
+
code_prompt_earlier: string;
|
|
27
28
|
code_send: string;
|
|
28
29
|
code_label: string;
|
|
29
30
|
code_submit: string;
|
|
@@ -32,6 +33,7 @@ export declare const en: {
|
|
|
32
33
|
code_expired: string;
|
|
33
34
|
code_rate_limited: string;
|
|
34
35
|
code_dismiss: string;
|
|
36
|
+
code_not_me: string;
|
|
35
37
|
attach: string;
|
|
36
38
|
uploading: string;
|
|
37
39
|
ready: string;
|
package/dist/i18n/fr.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare const fr: {
|
|
|
25
25
|
email_saved: string;
|
|
26
26
|
error: string;
|
|
27
27
|
code_prompt: string;
|
|
28
|
+
code_prompt_earlier: string;
|
|
28
29
|
code_send: string;
|
|
29
30
|
code_label: string;
|
|
30
31
|
code_submit: string;
|
|
@@ -33,6 +34,7 @@ export declare const fr: {
|
|
|
33
34
|
code_expired: string;
|
|
34
35
|
code_rate_limited: string;
|
|
35
36
|
code_dismiss: string;
|
|
37
|
+
code_not_me: string;
|
|
36
38
|
attach: string;
|
|
37
39
|
uploading: string;
|
|
38
40
|
ready: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ZeanChat } from './components/ZeanChat';
|
|
2
2
|
export { useZean } from './hooks/use-zean';
|
|
3
|
-
export type { ZeanAttributeValue, ZeanAttributes, ZeanChatProps, ZeanColorScheme, ZeanControls, ZeanLocale, ZeanStorage, ZeanUser } from './interfaces';
|
|
3
|
+
export type { ZeanAttributeValue, ZeanAttributes, ZeanChatProps, ZeanColorScheme, ZeanControls, ZeanKeyValueStorage, ZeanLocale, ZeanMMKV, ZeanStorage, ZeanUser } from './interfaces';
|
package/dist/index.js
CHANGED
|
@@ -208,6 +208,9 @@ var KEPT_MESSAGES = 100;
|
|
|
208
208
|
var KEPT_VERSION = 1;
|
|
209
209
|
var LIVE_AFTER_CLOSE_MS = 2 * 6e4;
|
|
210
210
|
var ADVANCE_AFTER = WIDGET_PAGE_SIZE / 2;
|
|
211
|
+
function emailKey(offer) {
|
|
212
|
+
return `${offer.kind}:${offer.email}`;
|
|
213
|
+
}
|
|
211
214
|
function createChatStore(backend, options) {
|
|
212
215
|
const secretKey = `zean:${options.appKey}:device`;
|
|
213
216
|
const outboxKey = `zean:${options.appKey}:outbox`;
|
|
@@ -241,7 +244,10 @@ function createChatStore(backend, options) {
|
|
|
241
244
|
let started = false;
|
|
242
245
|
let reported = false;
|
|
243
246
|
let user = null;
|
|
244
|
-
let
|
|
247
|
+
let idCode = null;
|
|
248
|
+
let idCodeDismissed = false;
|
|
249
|
+
let emailCodeSent = null;
|
|
250
|
+
let emailCodeDismissed = null;
|
|
245
251
|
let emailGiven = false;
|
|
246
252
|
let wroteHere = false;
|
|
247
253
|
let emailAskWanted = false;
|
|
@@ -258,7 +264,7 @@ function createChatStore(backend, options) {
|
|
|
258
264
|
state = derive();
|
|
259
265
|
for (const listener of listeners2) listener();
|
|
260
266
|
};
|
|
261
|
-
const args = () => ({ appKey: options.appKey, deviceSecret, host: options.host });
|
|
267
|
+
const args = () => ({ appKey: options.appKey, deviceSecret, host: options.host, bundle: options.bundle });
|
|
262
268
|
const deviceLanguage = options.deviceLanguage ?? options.languages[0];
|
|
263
269
|
const device = () => ({
|
|
264
270
|
locale: state.locale,
|
|
@@ -292,7 +298,6 @@ function createChatStore(backend, options) {
|
|
|
292
298
|
stops.push(() => clearInterval(clock));
|
|
293
299
|
})();
|
|
294
300
|
function watchAll() {
|
|
295
|
-
for (const stop of watchers) stop();
|
|
296
301
|
watchers = [
|
|
297
302
|
backend.watch("session", args(), handleSession, () => {
|
|
298
303
|
failedToLoad = true;
|
|
@@ -353,7 +358,7 @@ function createChatStore(backend, options) {
|
|
|
353
358
|
try {
|
|
354
359
|
const result = await backend.call("identify", { ...args(), user: person, device: device() });
|
|
355
360
|
if (mine !== generation) return;
|
|
356
|
-
|
|
361
|
+
idCode = result.state === "code_available" ? { email: result.email, sent: idCode?.sent ?? false } : null;
|
|
357
362
|
identified = true;
|
|
358
363
|
emit2();
|
|
359
364
|
} catch (error) {
|
|
@@ -370,9 +375,8 @@ function createChatStore(backend, options) {
|
|
|
370
375
|
if (session?.state !== result.state && result.state === "not_found")
|
|
371
376
|
console.warn(`${APP_NAME}: no App has the key "${options.appKey}". Check the install snippet.`);
|
|
372
377
|
if (session?.state !== result.state && result.state === "domain_not_allowed")
|
|
373
|
-
console.warn(
|
|
374
|
-
|
|
375
|
-
);
|
|
378
|
+
console.warn(`${APP_NAME}: ${options.host ?? "this page"} is not the App's Domain. Set it in the App settings.`);
|
|
379
|
+
if (session?.state !== result.state && result.state === "bundle_id_not_allowed") console.warn(bundleWarning(options.bundle));
|
|
376
380
|
session = result;
|
|
377
381
|
failedToLoad = false;
|
|
378
382
|
if (keep) checkKept(result);
|
|
@@ -480,7 +484,7 @@ function createChatStore(backend, options) {
|
|
|
480
484
|
function wantsEmail() {
|
|
481
485
|
const app = session && "app" in session ? session.app : null;
|
|
482
486
|
const contact = session && "contact" in session ? session.contact : null;
|
|
483
|
-
return statusOf() === "ready" && !!contact && contact.email === null && !emailGiven &&
|
|
487
|
+
return statusOf() === "ready" && !!contact && contact.email === null && !emailGiven && app?.askEmail === true;
|
|
484
488
|
}
|
|
485
489
|
function holdEmailAsk() {
|
|
486
490
|
const wanted = wantsEmail();
|
|
@@ -533,10 +537,16 @@ function createChatStore(backend, options) {
|
|
|
533
537
|
askEmail: emailAskWanted && !emailAskTimer,
|
|
534
538
|
emailGiven,
|
|
535
539
|
verified,
|
|
536
|
-
contactCode: verified
|
|
540
|
+
contactCode: codeOffer(verified),
|
|
537
541
|
connected
|
|
538
542
|
};
|
|
539
543
|
}
|
|
544
|
+
function codeOffer(verified) {
|
|
545
|
+
if (idCode && !verified) return idCodeDismissed ? null : { kind: "id", ...idCode };
|
|
546
|
+
const offer = session && "emailCode" in session ? session.emailCode : null;
|
|
547
|
+
if (!offer || emailKey(offer) === emailCodeDismissed) return null;
|
|
548
|
+
return { ...offer, sent: emailKey(offer) === emailCodeSent };
|
|
549
|
+
}
|
|
540
550
|
function checkKept(result) {
|
|
541
551
|
const history = "contact" in result ? result.contact?.historyKey ?? null : null;
|
|
542
552
|
if (history !== keptHistory) {
|
|
@@ -546,7 +556,7 @@ function createChatStore(backend, options) {
|
|
|
546
556
|
if (hidesChat(result)) forgetKept();
|
|
547
557
|
else if (history !== null && !stopMessages && serverMessages().length === 0 && deviceSecret) {
|
|
548
558
|
watchLive();
|
|
549
|
-
|
|
559
|
+
stopLiveLater();
|
|
550
560
|
} else saveKept();
|
|
551
561
|
}
|
|
552
562
|
async function loadKept() {
|
|
@@ -745,7 +755,8 @@ function createChatStore(backend, options) {
|
|
|
745
755
|
}
|
|
746
756
|
if (user?.id !== person.id) {
|
|
747
757
|
generation += 1;
|
|
748
|
-
|
|
758
|
+
idCode = null;
|
|
759
|
+
idCodeDismissed = false;
|
|
749
760
|
emailGiven = false;
|
|
750
761
|
}
|
|
751
762
|
user = person;
|
|
@@ -753,12 +764,17 @@ function createChatStore(backend, options) {
|
|
|
753
764
|
await sendIdentity();
|
|
754
765
|
},
|
|
755
766
|
async requestCode() {
|
|
767
|
+
const offer = state.contactCode;
|
|
756
768
|
const person = user;
|
|
757
|
-
if (!
|
|
769
|
+
if (!deviceSecret || !offer || offer.kind === "id" && !person) return { ok: false, code: "not_found" };
|
|
758
770
|
try {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
771
|
+
if (offer.kind !== "id") {
|
|
772
|
+
await backend.call("requestEmailCode", args());
|
|
773
|
+
emailCodeSent = emailKey(offer);
|
|
774
|
+
} else {
|
|
775
|
+
await backend.call("requestCode", { ...args(), userId: person.id });
|
|
776
|
+
if (idCode && user === person) idCode = { ...idCode, sent: true };
|
|
777
|
+
}
|
|
762
778
|
emit2();
|
|
763
779
|
return { ok: true };
|
|
764
780
|
} catch (error) {
|
|
@@ -766,12 +782,20 @@ function createChatStore(backend, options) {
|
|
|
766
782
|
}
|
|
767
783
|
},
|
|
768
784
|
async confirmCode(code2) {
|
|
785
|
+
const offer = state.contactCode;
|
|
769
786
|
const person = user;
|
|
770
|
-
if (!
|
|
787
|
+
if (!deviceSecret || !offer || offer.kind === "id" && !person) return { ok: false, code: "not_found" };
|
|
771
788
|
try {
|
|
789
|
+
if (offer.kind !== "id") {
|
|
790
|
+
const result2 = await backend.call("confirmEmailCode", { ...args(), code: code2 });
|
|
791
|
+
if (!result2.ok) return result2;
|
|
792
|
+
emailCodeSent = null;
|
|
793
|
+
emit2();
|
|
794
|
+
return { ok: true };
|
|
795
|
+
}
|
|
772
796
|
const result = await backend.call("confirmCode", { ...args(), userId: person.id, code: code2 });
|
|
773
797
|
if (!result.ok) return result;
|
|
774
|
-
|
|
798
|
+
idCode = null;
|
|
775
799
|
emit2();
|
|
776
800
|
void sendIdentity();
|
|
777
801
|
return { ok: true };
|
|
@@ -779,6 +803,17 @@ function createChatStore(backend, options) {
|
|
|
779
803
|
return { ok: false, code: codeOf(error) };
|
|
780
804
|
}
|
|
781
805
|
},
|
|
806
|
+
dismissCode() {
|
|
807
|
+
const offer = state.contactCode;
|
|
808
|
+
if (!offer) return;
|
|
809
|
+
if (offer.kind === "id") idCodeDismissed = true;
|
|
810
|
+
else {
|
|
811
|
+
emailCodeDismissed = emailKey(offer);
|
|
812
|
+
backend.call("dismissEmailCode", args()).catch(() => {
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
emit2();
|
|
816
|
+
},
|
|
782
817
|
async signOut() {
|
|
783
818
|
generation += 1;
|
|
784
819
|
const mine = generation;
|
|
@@ -786,7 +821,10 @@ function createChatStore(backend, options) {
|
|
|
786
821
|
if (mine !== generation) return;
|
|
787
822
|
user = null;
|
|
788
823
|
identified = false;
|
|
789
|
-
|
|
824
|
+
idCode = null;
|
|
825
|
+
idCodeDismissed = false;
|
|
826
|
+
emailCodeSent = null;
|
|
827
|
+
emailCodeDismissed = null;
|
|
790
828
|
emailGiven = false;
|
|
791
829
|
identifying = null;
|
|
792
830
|
identifiedKnown = false;
|
|
@@ -860,8 +898,14 @@ function fromOutbox(entry) {
|
|
|
860
898
|
error: entry.error
|
|
861
899
|
};
|
|
862
900
|
}
|
|
901
|
+
function bundleWarning(bundle) {
|
|
902
|
+
if (!bundle)
|
|
903
|
+
return `${APP_NAME}: the chat could not read this app's Bundle ID or Package name. Install expo-application (Expo) or react-native-device-info.`;
|
|
904
|
+
const field = bundle.os === "ios" ? "Bundle ID" : "Package name";
|
|
905
|
+
return `${APP_NAME}: ${bundle.id} is not the App's ${field}. Set it in the App settings.`;
|
|
906
|
+
}
|
|
863
907
|
function hidesChat(result) {
|
|
864
|
-
return result.state === "not_found" || result.state === "domain_not_allowed";
|
|
908
|
+
return result.state === "not_found" || result.state === "domain_not_allowed" || result.state === "bundle_id_not_allowed";
|
|
865
909
|
}
|
|
866
910
|
function quietly(write) {
|
|
867
911
|
try {
|
|
@@ -6378,6 +6422,7 @@ var IMAGE_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
|
|
6378
6422
|
var OFFLINE_NOTICE_MS = 3e3;
|
|
6379
6423
|
var ANDROID_NAVIGATION_BAR = 48;
|
|
6380
6424
|
var DEFAULT_MAX_PHOTOS = 4;
|
|
6425
|
+
var CHAT_STORAGE_ID = "zean-chat";
|
|
6381
6426
|
var LINK_RETRY_MS = 1500;
|
|
6382
6427
|
var LINK_RETRIES = 5;
|
|
6383
6428
|
var LINK_LIFETIME_MS = 50 * 60 * 1e3;
|
|
@@ -6444,6 +6489,92 @@ function deviceLanguages() {
|
|
|
6444
6489
|
return [];
|
|
6445
6490
|
}
|
|
6446
6491
|
}
|
|
6492
|
+
function appBundle() {
|
|
6493
|
+
if (import_react_native.Platform.OS !== "ios" && import_react_native.Platform.OS !== "android") return void 0;
|
|
6494
|
+
const id = expoApplicationId() ?? deviceInfoBundleId();
|
|
6495
|
+
return id ? { os: import_react_native.Platform.OS, id } : void 0;
|
|
6496
|
+
}
|
|
6497
|
+
function chatStorage(storage) {
|
|
6498
|
+
const found2 = storage ? keyValue(storage) : installedStorage();
|
|
6499
|
+
if (!found2) {
|
|
6500
|
+
console.warn(
|
|
6501
|
+
`${APP_NAME}: no storage found, so the conversation is forgotten when the app closes. Install react-native-mmkv, @react-native-async-storage/async-storage or expo-sqlite, then build the app again.`
|
|
6502
|
+
);
|
|
6503
|
+
}
|
|
6504
|
+
const memory = /* @__PURE__ */ new Map();
|
|
6505
|
+
return {
|
|
6506
|
+
getItem: async (key) => {
|
|
6507
|
+
try {
|
|
6508
|
+
if (found2) return await found2.getItem(key);
|
|
6509
|
+
} catch {
|
|
6510
|
+
}
|
|
6511
|
+
return memory.get(key) ?? null;
|
|
6512
|
+
},
|
|
6513
|
+
setItem: async (key, value) => {
|
|
6514
|
+
memory.set(key, value);
|
|
6515
|
+
try {
|
|
6516
|
+
await found2?.setItem(key, value);
|
|
6517
|
+
} catch {
|
|
6518
|
+
}
|
|
6519
|
+
}
|
|
6520
|
+
};
|
|
6521
|
+
}
|
|
6522
|
+
function keyValue(storage) {
|
|
6523
|
+
if ("getItem" in storage) return storage;
|
|
6524
|
+
return { getItem: (key) => storage.getString(key) ?? null, setItem: (key, value) => storage.set(key, value) };
|
|
6525
|
+
}
|
|
6526
|
+
function installedStorage() {
|
|
6527
|
+
return mmkvStorage() ?? moduleStorage("async-storage") ?? moduleStorage("kv-store") ?? browserStorage();
|
|
6528
|
+
}
|
|
6529
|
+
function mmkvStorage() {
|
|
6530
|
+
try {
|
|
6531
|
+
const module2 = require("react-native-mmkv");
|
|
6532
|
+
const config = { id: CHAT_STORAGE_ID };
|
|
6533
|
+
if (typeof module2?.createMMKV === "function") return keyValue(module2.createMMKV(config));
|
|
6534
|
+
if (typeof module2?.MMKV === "function") return keyValue(new module2.MMKV(config));
|
|
6535
|
+
return null;
|
|
6536
|
+
} catch {
|
|
6537
|
+
return null;
|
|
6538
|
+
}
|
|
6539
|
+
}
|
|
6540
|
+
function moduleStorage(name) {
|
|
6541
|
+
try {
|
|
6542
|
+
const module2 = name === "async-storage" ? require("@react-native-async-storage/async-storage") : require("expo-sqlite/kv-store");
|
|
6543
|
+
return [module2, module2.default, module2.Storage].find(isKeyValue) ?? null;
|
|
6544
|
+
} catch {
|
|
6545
|
+
return null;
|
|
6546
|
+
}
|
|
6547
|
+
}
|
|
6548
|
+
function browserStorage() {
|
|
6549
|
+
try {
|
|
6550
|
+
const storage = globalThis.localStorage;
|
|
6551
|
+
return isKeyValue(storage) ? storage : null;
|
|
6552
|
+
} catch {
|
|
6553
|
+
return null;
|
|
6554
|
+
}
|
|
6555
|
+
}
|
|
6556
|
+
function isKeyValue(value) {
|
|
6557
|
+
if (typeof value !== "object" || value === null) return false;
|
|
6558
|
+
const { getItem, setItem } = value;
|
|
6559
|
+
return typeof getItem === "function" && typeof setItem === "function";
|
|
6560
|
+
}
|
|
6561
|
+
function expoApplicationId() {
|
|
6562
|
+
try {
|
|
6563
|
+
const expo = require("expo-application");
|
|
6564
|
+
return typeof expo?.applicationId === "string" ? expo.applicationId : null;
|
|
6565
|
+
} catch {
|
|
6566
|
+
return null;
|
|
6567
|
+
}
|
|
6568
|
+
}
|
|
6569
|
+
function deviceInfoBundleId() {
|
|
6570
|
+
try {
|
|
6571
|
+
const module2 = require("react-native-device-info");
|
|
6572
|
+
const getBundleId = module2?.getBundleId ?? module2?.default?.getBundleId;
|
|
6573
|
+
return typeof getBundleId === "function" ? getBundleId() : null;
|
|
6574
|
+
} catch {
|
|
6575
|
+
return null;
|
|
6576
|
+
}
|
|
6577
|
+
}
|
|
6447
6578
|
function deviceOs() {
|
|
6448
6579
|
if (import_react_native.Platform.OS === "ios") return `iOS ${import_react_native.Platform.Version}`;
|
|
6449
6580
|
if (import_react_native.Platform.OS === "android") return `Android ${import_react_native.Platform.constants.Release}`;
|
|
@@ -6531,6 +6662,7 @@ var en = {
|
|
|
6531
6662
|
email_saved: "Thanks, we will write to {email}.",
|
|
6532
6663
|
error: "Something went wrong. Try again.",
|
|
6533
6664
|
code_prompt: "Chatted with us on another device? Get a code at {email} to see your conversation here.",
|
|
6665
|
+
code_prompt_earlier: "Wrote to us before signing in? Get a code at {email} to bring that conversation here.",
|
|
6534
6666
|
code_send: "Get the code",
|
|
6535
6667
|
code_label: "Enter the 6-digit code sent to {email}.",
|
|
6536
6668
|
code_submit: "Confirm",
|
|
@@ -6539,6 +6671,7 @@ var en = {
|
|
|
6539
6671
|
code_expired: "This code no longer works. Ask for a new one.",
|
|
6540
6672
|
code_rate_limited: "Too many codes asked for. Try again in an hour.",
|
|
6541
6673
|
code_dismiss: "Not now",
|
|
6674
|
+
code_not_me: "Not me",
|
|
6542
6675
|
attach: "Send a photo",
|
|
6543
6676
|
uploading: "Uploading\u2026",
|
|
6544
6677
|
ready: "Ready",
|
|
@@ -6583,6 +6716,7 @@ var fr = {
|
|
|
6583
6716
|
email_saved: "Merci, nous vous \xE9crirons \xE0 {email}.",
|
|
6584
6717
|
error: "Une erreur est survenue. R\xE9essayez.",
|
|
6585
6718
|
code_prompt: "D\xE9j\xE0 \xE9chang\xE9 avec nous sur un autre appareil ? Recevez un code \xE0 {email} pour retrouver votre conversation ici.",
|
|
6719
|
+
code_prompt_earlier: "Vous nous avez \xE9crit avant de vous connecter ? Recevez un code \xE0 {email} pour retrouver cette conversation ici.",
|
|
6586
6720
|
code_send: "Recevoir le code",
|
|
6587
6721
|
code_label: "Saisissez le code \xE0 6 chiffres envoy\xE9 \xE0 {email}.",
|
|
6588
6722
|
code_submit: "Valider",
|
|
@@ -6591,6 +6725,7 @@ var fr = {
|
|
|
6591
6725
|
code_expired: "Ce code ne fonctionne plus. Demandez-en un nouveau.",
|
|
6592
6726
|
code_rate_limited: "Trop de codes demand\xE9s. R\xE9essayez dans une heure.",
|
|
6593
6727
|
code_dismiss: "Plus tard",
|
|
6728
|
+
code_not_me: "Ce n\u2019est pas moi",
|
|
6594
6729
|
attach: "Envoyer une photo",
|
|
6595
6730
|
uploading: "Envoi\u2026",
|
|
6596
6731
|
ready: "Pr\xEAt",
|
|
@@ -6853,6 +6988,9 @@ var import_react_native9 = require("react-native");
|
|
|
6853
6988
|
// ../shared/src/constants/auth.ts
|
|
6854
6989
|
var CODE_LENGTH = 6;
|
|
6855
6990
|
var CODE_MAX_AGE_SECONDS = 15 * 60;
|
|
6991
|
+
var TEST_EMAIL_DOMAIN = "zean-test.local";
|
|
6992
|
+
var DEV_OPERATOR_EMAIL = `operator@${TEST_EMAIL_DOMAIN}`;
|
|
6993
|
+
var MOBILE_AUTH_CODE_TTL_MS = 2 * 6e4;
|
|
6856
6994
|
|
|
6857
6995
|
// src/components/ContactCodeCard.tsx
|
|
6858
6996
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
@@ -6882,7 +7020,8 @@ function ContactCodeCard({ code: code2, onDismiss }) {
|
|
|
6882
7020
|
setBusy(false);
|
|
6883
7021
|
if (!result.ok) setError(errorOf(result.code));
|
|
6884
7022
|
};
|
|
6885
|
-
const
|
|
7023
|
+
const prompt = code2.kind === "earlier" ? t.code_prompt_earlier : t.code_prompt;
|
|
7024
|
+
const label = format(code2.sent ? t.code_label : prompt, { email: code2.email });
|
|
6886
7025
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native9.View, { style: [styles5.card, { backgroundColor: colors.surface }], children: [
|
|
6887
7026
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.prompt, { color: colors.text }], children: label }),
|
|
6888
7027
|
code2.sent ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_native9.View, { style: styles5.row, children: [
|
|
@@ -6927,7 +7066,7 @@ function ContactCodeCard({ code: code2, onDismiss }) {
|
|
|
6927
7066
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.buttonText, { color: colors.primaryForeground }], children: t.code_send })
|
|
6928
7067
|
}
|
|
6929
7068
|
),
|
|
6930
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Pressable, { onPress: onDismiss, accessibilityRole: "button", hitSlop: 8, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.link, { color: colors.muted }], children: t.code_dismiss }) })
|
|
7069
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Pressable, { onPress: onDismiss, accessibilityRole: "button", hitSlop: 8, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.link, { color: colors.muted }], children: code2.kind === "id" ? t.code_dismiss : t.code_not_me }) })
|
|
6931
7070
|
] }),
|
|
6932
7071
|
error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { accessibilityLiveRegion: "polite", style: [styles5.error, { color: colors.danger }], children: error }),
|
|
6933
7072
|
code2.sent && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Pressable, { onPress: () => void handleSend(), disabled: busy, accessibilityRole: "button", hitSlop: 8, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_native9.Text, { style: [styles5.link, { color: colors.primaryText }, busy && styles5.dim], children: t.code_resend }) })
|
|
@@ -7938,18 +8077,17 @@ var styles15 = import_react_native21.StyleSheet.create({
|
|
|
7938
8077
|
// src/components/ChatScreen.tsx
|
|
7939
8078
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
7940
8079
|
function ChatScreen({ state, insets, onClose }) {
|
|
7941
|
-
const { t, colors } = useChatContext();
|
|
8080
|
+
const { chat: chat2, t, colors } = useChatContext();
|
|
7942
8081
|
const rootRef = (0, import_react15.useRef)(null);
|
|
7943
8082
|
const keyboard = useKeyboardOverlap(rootRef);
|
|
7944
8083
|
const connectionLost = useConnectionLost(state.connected);
|
|
7945
|
-
const [codeDismissed, setCodeDismissed] = (0, import_react15.useState)(false);
|
|
7946
8084
|
const app = state.app;
|
|
7947
8085
|
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_react_native22.View, { ref: rootRef, style: [styles16.screen, { backgroundColor: colors.background, paddingBottom: keyboard }], children: [
|
|
7948
8086
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChatHeader, { app, online: state.online, topInset: insets.top, onClose }),
|
|
7949
8087
|
connectionLost && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_native22.View, { style: styles16.notice, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChatNotice, { children: t.reconnecting }) }),
|
|
7950
8088
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(MessageList, { state }),
|
|
7951
8089
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_react_native22.View, { style: [styles16.footer, { paddingBottom: 8 + (keyboard > 0 ? 0 : insets.bottom) }], children: [
|
|
7952
|
-
state.contactCode &&
|
|
8090
|
+
state.contactCode && state.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ContactCodeCard, { code: state.contactCode, onDismiss: chat2.dismissCode }),
|
|
7953
8091
|
state.status === "blocked" ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChatNotice, { children: t.blocked }) : state.status === "unavailable" ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ChatNotice, { children: t.unavailable }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(Composer, {}),
|
|
7954
8092
|
app.showBadge && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(PoweredBy, {})
|
|
7955
8093
|
] })
|
|
@@ -8036,11 +8174,13 @@ function ZeanChat({
|
|
|
8036
8174
|
const started = createChat({
|
|
8037
8175
|
appKey,
|
|
8038
8176
|
backendUrl,
|
|
8039
|
-
storage: storageRef.current,
|
|
8177
|
+
storage: chatStorage(storageRef.current),
|
|
8040
8178
|
// A chosen language goes first: the chat takes the first one it speaks.
|
|
8041
8179
|
languages: locale ? [locale] : deviceLanguages(),
|
|
8042
8180
|
deviceLanguage: deviceLanguages()[0],
|
|
8043
8181
|
os: deviceOs(),
|
|
8182
|
+
// Checked against the App's Bundle ID or Package name: another app with the same key shows no chat.
|
|
8183
|
+
bundle: appBundle(),
|
|
8044
8184
|
// The Conversation stays on the phone: the next start shows it at once and asks only for newer messages.
|
|
8045
8185
|
keep: true
|
|
8046
8186
|
});
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
export type ZeanAttributeValue = string | number | boolean;
|
|
2
2
|
/** What the app knows about the person, shown on the Contact's profile: `{ city: 'Douala', orders: 12 }`. */
|
|
3
3
|
export type ZeanAttributes = Record<string, ZeanAttributeValue>;
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
* with these two.
|
|
7
|
-
*/
|
|
8
|
-
export interface ZeanStorage {
|
|
4
|
+
/** Storage read with `getItem` and written with `setItem`: AsyncStorage, Expo SQLite's `expo-sqlite/kv-store`, or your own. */
|
|
5
|
+
export interface ZeanKeyValueStorage {
|
|
9
6
|
getItem: (key: string) => string | null | Promise<string | null>;
|
|
10
7
|
setItem: (key: string, value: string) => void | Promise<void>;
|
|
11
8
|
}
|
|
9
|
+
/** An MMKV instance from `react-native-mmkv`, any version, passed as it is. */
|
|
10
|
+
export interface ZeanMMKV {
|
|
11
|
+
getString: (key: string) => string | undefined;
|
|
12
|
+
set: (key: string, value: string) => void;
|
|
13
|
+
}
|
|
14
|
+
/** Where the chat keeps the device's secret, unsent messages and the newest 100 messages. */
|
|
15
|
+
export type ZeanStorage = ZeanKeyValueStorage | ZeanMMKV;
|
|
12
16
|
export type ZeanLocale = 'fr' | 'en';
|
|
13
17
|
/** The person signed in to your app. Only `id` is needed; the rest shows on their Contact. */
|
|
14
18
|
export interface ZeanUser {
|
|
@@ -24,8 +28,11 @@ export type ZeanColorScheme = 'light' | 'dark';
|
|
|
24
28
|
export interface ZeanChatProps {
|
|
25
29
|
/** The App's public key, from the install code. */
|
|
26
30
|
appKey: string;
|
|
27
|
-
/**
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Leave it out: the chat finds the storage the app has, MMKV, AsyncStorage or Expo SQLite. Pass one to choose it.
|
|
33
|
+
* Read once, when the chat starts.
|
|
34
|
+
*/
|
|
35
|
+
storage?: ZeanStorage;
|
|
29
36
|
/** The person signed in to your app: `{ id, name, email }`. Leave it out when no one is: the chat signs out. */
|
|
30
37
|
user?: ZeanUser;
|
|
31
38
|
/** What the app knows about the person, shown on the Contact's profile. */
|
|
@@ -6,6 +6,8 @@ export declare const OFFLINE_NOTICE_MS = 3000;
|
|
|
6
6
|
export declare const ANDROID_NAVIGATION_BAR = 48;
|
|
7
7
|
/** Photos a Contact sends in one message, unless `ZeanChat`'s `maxPhotos` says otherwise. */
|
|
8
8
|
export declare const DEFAULT_MAX_PHOTOS = 4;
|
|
9
|
+
/** The chat's own MMKV instance, apart from the app's. */
|
|
10
|
+
export declare const CHAT_STORAGE_ID = "zean-chat";
|
|
9
11
|
/** A photo's link asked for before its message is stored is refused: asked again this often, a few times. */
|
|
10
12
|
export declare const LINK_RETRY_MS = 1500;
|
|
11
13
|
export declare const LINK_RETRIES = 5;
|
|
@@ -3,7 +3,7 @@ import type { Locale } from '@zean/shared/constants/app';
|
|
|
3
3
|
import type { AccentColors } from '@zean/shared/interfaces/widget';
|
|
4
4
|
import type { ReactNode } from 'react';
|
|
5
5
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
6
|
-
import type { ZeanColorScheme } from '../interfaces';
|
|
6
|
+
import type { ZeanColorScheme, ZeanMMKV } from '../interfaces';
|
|
7
7
|
import type { fr } from '../i18n/fr';
|
|
8
8
|
export interface ChatView {
|
|
9
9
|
open: boolean;
|
|
@@ -229,6 +229,26 @@ export interface ImagePickerResult {
|
|
|
229
229
|
errorCode?: string;
|
|
230
230
|
assets?: Array<ImagePickerAsset>;
|
|
231
231
|
}
|
|
232
|
+
/** `react-native-mmkv`: `createMMKV` from version 4, the `MMKV` class before. */
|
|
233
|
+
export interface MMKVModule {
|
|
234
|
+
createMMKV?: (config: {
|
|
235
|
+
id: string;
|
|
236
|
+
}) => ZeanMMKV;
|
|
237
|
+
MMKV?: new (config: {
|
|
238
|
+
id: string;
|
|
239
|
+
}) => ZeanMMKV;
|
|
240
|
+
}
|
|
241
|
+
/** `expo-application`: the app's Bundle ID on iOS, its Package name on Android. */
|
|
242
|
+
export interface ExpoApplicationModule {
|
|
243
|
+
applicationId: string | null;
|
|
244
|
+
}
|
|
245
|
+
/** `react-native-device-info`, its named exports or its default one. */
|
|
246
|
+
export interface DeviceInfoModule {
|
|
247
|
+
getBundleId?: () => string;
|
|
248
|
+
default?: {
|
|
249
|
+
getBundleId?: () => string;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
232
252
|
export interface ImagePickerModule {
|
|
233
253
|
launchImageLibrary: (options: ImagePickerOptions) => Promise<ImagePickerResult>;
|
|
234
254
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChatColors, ScreenInsets } from './sdk.interface';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AppBundle, ChatStorage } from '@zean/sdk-core';
|
|
3
|
+
import type { ZeanColorScheme, ZeanStorage } from '../interfaces';
|
|
3
4
|
/** `{name}` in a text, filled from `values`. */
|
|
4
5
|
export declare function format(template: string, values: Record<string, string | number>): string;
|
|
5
6
|
/** The chat's colours: the App's, made for the screen's scheme, and the neutral ones around them. */
|
|
@@ -11,6 +12,19 @@ export declare function chatColors(color: string, scheme: ZeanColorScheme): Chat
|
|
|
11
12
|
* only one the app was translated into.
|
|
12
13
|
*/
|
|
13
14
|
export declare function deviceLanguages(): Array<string>;
|
|
15
|
+
/**
|
|
16
|
+
* The app the chat runs in, which the App must allow: its Bundle ID on iOS, its Package name on Android. Read through
|
|
17
|
+
* `expo-application`, else `react-native-device-info`. With neither, none: the chat stays hidden and says which to
|
|
18
|
+
* install.
|
|
19
|
+
*/
|
|
20
|
+
export declare function appBundle(): AppBundle | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Where the chat keeps what lasts across launches: the storage the app passed, else the one it has, found by itself:
|
|
23
|
+
* MMKV, then AsyncStorage, then Expo SQLite's `kv-store`, then the browser's on the web. With none, memory: the chat
|
|
24
|
+
* starts over at each launch. A read or a write that fails, as when a native module is missing from the build, falls
|
|
25
|
+
* back to memory too.
|
|
26
|
+
*/
|
|
27
|
+
export declare function chatStorage(storage?: ZeanStorage): ChatStorage;
|
|
14
28
|
/** "iOS 18.2" or "Android 15", for the Contact panel. */
|
|
15
29
|
export declare function deviceOs(): string | undefined;
|
|
16
30
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zean-chat/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "In-app support chat for React Native and Expo, iOS and Android. Pure JS, no native module. A free Intercom, Crisp and Zendesk mobile SDK alternative.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -56,33 +56,53 @@
|
|
|
56
56
|
"test": "jest --coverage"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
+
"@react-native-async-storage/async-storage": "*",
|
|
60
|
+
"expo-application": "*",
|
|
59
61
|
"expo-image-picker": "*",
|
|
62
|
+
"expo-sqlite": "*",
|
|
60
63
|
"react": ">=19",
|
|
61
64
|
"react-native": ">=0.78",
|
|
62
|
-
"react-native-
|
|
65
|
+
"react-native-device-info": "*",
|
|
66
|
+
"react-native-image-picker": "*",
|
|
67
|
+
"react-native-mmkv": "*"
|
|
63
68
|
},
|
|
64
69
|
"peerDependenciesMeta": {
|
|
70
|
+
"expo-application": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"react-native-device-info": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
65
76
|
"expo-image-picker": {
|
|
66
77
|
"optional": true
|
|
67
78
|
},
|
|
68
79
|
"react-native-image-picker": {
|
|
69
80
|
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"@react-native-async-storage/async-storage": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"expo-sqlite": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
88
|
+
"react-native-mmkv": {
|
|
89
|
+
"optional": true
|
|
70
90
|
}
|
|
71
91
|
},
|
|
72
92
|
"devDependencies": {
|
|
73
93
|
"@jest/globals": "29.7.0",
|
|
74
|
-
"@react-native/babel-preset": "0.
|
|
75
|
-
"@react-native/jest-preset": "0.
|
|
94
|
+
"@react-native/babel-preset": "0.88.0",
|
|
95
|
+
"@react-native/jest-preset": "0.88.0",
|
|
76
96
|
"@testing-library/react-native": "14.1.0",
|
|
77
|
-
"@types/react": "19.
|
|
97
|
+
"@types/react": "19.3.0",
|
|
78
98
|
"@zean/config": "*",
|
|
79
99
|
"@zean/sdk-core": "*",
|
|
80
100
|
"@zean/shared": "*",
|
|
81
101
|
"babel-jest": "29.7.0",
|
|
82
102
|
"convex": "1.46.0",
|
|
83
103
|
"jest": "29.7.0",
|
|
84
|
-
"react": "19.
|
|
85
|
-
"react-native": "0.
|
|
104
|
+
"react": "19.3.0",
|
|
105
|
+
"react-native": "0.88.0",
|
|
86
106
|
"test-renderer": "1.3.1",
|
|
87
107
|
"typescript": "6.0.3",
|
|
88
108
|
"vitest": "4.1.11"
|