@zean-chat/react-native 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +35 -2
- package/dist/components/AppMark.d.ts +3 -0
- package/dist/components/ChatHeader.d.ts +3 -0
- package/dist/components/ChatModal.d.ts +6 -0
- package/dist/components/ChatNotice.d.ts +3 -0
- package/dist/components/ChatScreen.d.ts +3 -0
- package/dist/components/Composer.d.ts +5 -0
- package/dist/components/EmailForm.d.ts +3 -0
- package/dist/components/Icon.d.ts +3 -0
- package/dist/components/ImageViewer.d.ts +3 -0
- package/dist/components/MessageBubble.d.ts +3 -0
- package/dist/components/MessageFiles.d.ts +3 -0
- package/dist/components/MessageList.d.ts +6 -0
- package/dist/components/PoweredBy.d.ts +2 -0
- package/dist/components/TeamAvatar.d.ts +3 -0
- package/dist/components/TypingBubble.d.ts +3 -0
- package/dist/components/ZeanChat.d.ts +6 -0
- package/dist/hooks/use-app-active.d.ts +2 -0
- package/dist/hooks/use-attachment-links.d.ts +6 -0
- package/dist/hooks/use-chat-context.d.ts +4 -0
- package/dist/hooks/use-connection-lost.d.ts +2 -0
- package/dist/hooks/use-keyboard-overlap.d.ts +8 -0
- package/dist/hooks/use-pending-photos.d.ts +15 -0
- package/dist/hooks/use-zean.d.ts +3 -0
- package/dist/i18n/en.d.ts +36 -0
- package/dist/i18n/fr.d.ts +37 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7264 -0
- package/dist/interfaces.d.ts +44 -0
- package/dist/models/photos.utils.d.ts +7 -0
- package/dist/models/sdk.constants.d.ts +18 -0
- package/dist/models/sdk.interface.d.ts +187 -0
- package/dist/models/sdk.store.d.ts +10 -0
- package/dist/models/sdk.utils.d.ts +24 -0
- package/package.json +81 -5
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Returns a token the Company's server signed for the signed-in person, or null when there is none. */
|
|
2
|
+
export type ZeanTokenSource = () => Promise<string | null>;
|
|
3
|
+
export type ZeanAttributeValue = string | number | boolean;
|
|
4
|
+
/** What the app knows about the person, shown on the Contact's profile: `{ city: 'Douala', orders: 12 }`. */
|
|
5
|
+
export type ZeanAttributes = Record<string, ZeanAttributeValue>;
|
|
6
|
+
/** Where the chat keeps the device's secret and unsent messages: AsyncStorage, MMKV, or anything with these two. */
|
|
7
|
+
export interface ZeanStorage {
|
|
8
|
+
getItem: (key: string) => string | null | Promise<string | null>;
|
|
9
|
+
setItem: (key: string, value: string) => void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export type ZeanLocale = 'fr' | 'en';
|
|
12
|
+
export type ZeanColorScheme = 'light' | 'dark';
|
|
13
|
+
export interface ZeanChatProps {
|
|
14
|
+
/** The App's public key, from the install code. */
|
|
15
|
+
appKey: string;
|
|
16
|
+
/** Read once, when the chat starts. */
|
|
17
|
+
storage: ZeanStorage;
|
|
18
|
+
/**
|
|
19
|
+
* While a person is signed in: returns a token your server signed. Leave it out when no one is; to switch people,
|
|
20
|
+
* leave it out once in between.
|
|
21
|
+
*/
|
|
22
|
+
getToken?: ZeanTokenSource;
|
|
23
|
+
/** What the app knows about the person, shown on the Contact's profile. */
|
|
24
|
+
attributes?: ZeanAttributes;
|
|
25
|
+
/** The chat's language. Leave it out: the phone's, when the chat speaks it, else the App's default. */
|
|
26
|
+
locale?: ZeanLocale;
|
|
27
|
+
/** Leave it out: the phone's. */
|
|
28
|
+
colorScheme?: ZeanColorScheme;
|
|
29
|
+
/** Where the chat's backend is. Leave it out: the default is Zean's own. */
|
|
30
|
+
backendUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
/** The chat's methods, and the count of replies the Contact has not seen. */
|
|
33
|
+
export interface ZeanControls {
|
|
34
|
+
open: () => void;
|
|
35
|
+
close: () => void;
|
|
36
|
+
toggle: () => void;
|
|
37
|
+
/** The person signed in: `getToken` is called now and whenever the token expires. */
|
|
38
|
+
identify: (getToken: ZeanTokenSource) => void;
|
|
39
|
+
/** The person signed out: the chat starts over, anonymous. */
|
|
40
|
+
signOut: () => void;
|
|
41
|
+
/** Joined to what was set before. Values the chat cannot keep are refused, and the console says why. */
|
|
42
|
+
setAttributes: (attributes: ZeanAttributes) => void;
|
|
43
|
+
unreadCount: number;
|
|
44
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ExpoImagePickerModule, ImagePickerModule, PhotoPicker } from './sdk.interface';
|
|
2
|
+
/** The photo picker the app installed, or null: `expo-image-picker` first, then `react-native-image-picker`. */
|
|
3
|
+
export declare function photoPicker(): PhotoPicker | null;
|
|
4
|
+
/** `expo-image-picker`: the system's photo library, no permission asked. It cannot make photos smaller. */
|
|
5
|
+
export declare function expoPicker(module: ExpoImagePickerModule): PhotoPicker;
|
|
6
|
+
/** `react-native-image-picker`: photos made smaller on the phone, as the web widget does. */
|
|
7
|
+
export declare function imagePicker(module: ImagePickerModule): PhotoPicker;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IconName, NeutralColors } from './sdk.interface';
|
|
2
|
+
import type { ZeanColorScheme } from '../interfaces';
|
|
3
|
+
/** How long the connection is down before the chat says so: a short blip is not worth a notice. */
|
|
4
|
+
export declare const OFFLINE_NOTICE_MS = 3000;
|
|
5
|
+
/** Android's navigation bar with its three buttons, in points: the gesture bar is half as tall. */
|
|
6
|
+
export declare const ANDROID_NAVIGATION_BAR = 48;
|
|
7
|
+
/** A photo's link asked for before its message is stored is refused: asked again this often, a few times. */
|
|
8
|
+
export declare const LINK_RETRY_MS = 1500;
|
|
9
|
+
export declare const LINK_RETRIES = 5;
|
|
10
|
+
/** Signed links last an hour: asked again after 50 minutes. */
|
|
11
|
+
export declare const LINK_LIFETIME_MS: number;
|
|
12
|
+
/** The colours around the App's own, as in the web widget (zinc). */
|
|
13
|
+
export declare const NEUTRAL_COLORS: Record<ZeanColorScheme, NeutralColors>;
|
|
14
|
+
/**
|
|
15
|
+
* The web widget's icons (Lucide), and the product's mark, drawn black at 72 pixels and tinted on screen: React Native
|
|
16
|
+
* draws no SVG without a native package.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ICONS: Record<IconName, string>;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import type { Chat, ChatApp, ChatAttachment, ChatMessage, ChatResult, ChatSender, ChatState } from '@zean/sdk-core';
|
|
2
|
+
import type { AccentColors } from '@zean/shared/interfaces/widget';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import type { ZeanColorScheme } from '../interfaces';
|
|
5
|
+
import type { fr } from '../i18n/fr';
|
|
6
|
+
export interface ChatView {
|
|
7
|
+
open: boolean;
|
|
8
|
+
unread: number;
|
|
9
|
+
}
|
|
10
|
+
/** The colours around the App's own, the same for every App. */
|
|
11
|
+
export interface NeutralColors {
|
|
12
|
+
background: string;
|
|
13
|
+
/** The team's bubbles, notices, image placeholders. */
|
|
14
|
+
surface: string;
|
|
15
|
+
text: string;
|
|
16
|
+
muted: string;
|
|
17
|
+
border: string;
|
|
18
|
+
danger: string;
|
|
19
|
+
online: string;
|
|
20
|
+
}
|
|
21
|
+
/** The colours of the chat, for the App's colour and the screen's scheme. */
|
|
22
|
+
export interface ChatColors extends AccentColors, NeutralColors {
|
|
23
|
+
}
|
|
24
|
+
/** A signed link to read a file, and until when it works. */
|
|
25
|
+
export interface SignedLink {
|
|
26
|
+
url: string;
|
|
27
|
+
until: number;
|
|
28
|
+
}
|
|
29
|
+
/** What every part of the open chat reads: the chat, its words and colours, and the image viewer. */
|
|
30
|
+
export interface ChatContextValue {
|
|
31
|
+
chat: Chat;
|
|
32
|
+
t: typeof fr;
|
|
33
|
+
colors: ChatColors;
|
|
34
|
+
openImage: (image: ViewedImage) => void;
|
|
35
|
+
}
|
|
36
|
+
/** An image shown full screen: its link and its file name, read as its label. */
|
|
37
|
+
export interface ViewedImage {
|
|
38
|
+
url: string;
|
|
39
|
+
name: string;
|
|
40
|
+
}
|
|
41
|
+
/** A photo from the phone's library, before it is sent. */
|
|
42
|
+
export interface PickedPhoto {
|
|
43
|
+
uri: string;
|
|
44
|
+
name: string;
|
|
45
|
+
/** `image/jpeg`; null when the picker does not say. */
|
|
46
|
+
type: string | null;
|
|
47
|
+
width?: number;
|
|
48
|
+
height?: number;
|
|
49
|
+
/** Bytes; null when the picker does not say. */
|
|
50
|
+
size: number | null;
|
|
51
|
+
}
|
|
52
|
+
/** The photo picker the app installed: `expo-image-picker` or `react-native-image-picker`. */
|
|
53
|
+
export interface PhotoPicker {
|
|
54
|
+
pick: (limit: number) => Promise<Array<PickedPhoto>>;
|
|
55
|
+
}
|
|
56
|
+
/** A photo being sent with the Contact's next message. */
|
|
57
|
+
export interface PendingPhoto {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
uri: string;
|
|
61
|
+
status: 'uploading' | 'ready' | 'failed';
|
|
62
|
+
attachment: ChatAttachment | null;
|
|
63
|
+
}
|
|
64
|
+
/** The space the screen's edges and the keyboard take, in points. */
|
|
65
|
+
export interface ScreenInsets {
|
|
66
|
+
top: number;
|
|
67
|
+
bottom: number;
|
|
68
|
+
}
|
|
69
|
+
export interface ChatModalProps {
|
|
70
|
+
chat: Chat;
|
|
71
|
+
colorScheme?: ZeanColorScheme;
|
|
72
|
+
}
|
|
73
|
+
export interface ChatScreenProps {
|
|
74
|
+
state: ChatState;
|
|
75
|
+
insets: ScreenInsets;
|
|
76
|
+
onClose: () => void;
|
|
77
|
+
}
|
|
78
|
+
export interface ChatHeaderProps {
|
|
79
|
+
app: ChatApp;
|
|
80
|
+
online: boolean;
|
|
81
|
+
/** The header text, shown until the Contact writes. */
|
|
82
|
+
greeting: string | null;
|
|
83
|
+
topInset: number;
|
|
84
|
+
onClose: () => void;
|
|
85
|
+
}
|
|
86
|
+
export interface MessageListProps {
|
|
87
|
+
state: ChatState;
|
|
88
|
+
}
|
|
89
|
+
export interface MessageBubbleProps {
|
|
90
|
+
message: ChatMessage;
|
|
91
|
+
app: ChatApp;
|
|
92
|
+
/** The team's name above the first message of a run. */
|
|
93
|
+
showName: boolean;
|
|
94
|
+
/** Under the Contact's latest message: sending, sent or seen. */
|
|
95
|
+
status: string | null;
|
|
96
|
+
onRetry: () => void;
|
|
97
|
+
}
|
|
98
|
+
export interface MessageFilesProps {
|
|
99
|
+
attachments: Array<ChatAttachment>;
|
|
100
|
+
/** The Contact's own message: aligned right. */
|
|
101
|
+
own: boolean;
|
|
102
|
+
/** False while the message is on its way: its files cannot be read yet. */
|
|
103
|
+
stored: boolean;
|
|
104
|
+
}
|
|
105
|
+
export interface TeamAvatarProps {
|
|
106
|
+
app: ChatApp;
|
|
107
|
+
/** Null: the App. */
|
|
108
|
+
sender: ChatSender | null;
|
|
109
|
+
}
|
|
110
|
+
export interface AppMarkProps {
|
|
111
|
+
app: ChatApp;
|
|
112
|
+
}
|
|
113
|
+
export interface TypingBubbleProps {
|
|
114
|
+
app: ChatApp;
|
|
115
|
+
sender: ChatSender | null;
|
|
116
|
+
}
|
|
117
|
+
export interface EmailFormProps {
|
|
118
|
+
onSubmit: (email: string) => Promise<ChatResult>;
|
|
119
|
+
}
|
|
120
|
+
export interface ChatNoticeProps {
|
|
121
|
+
children: ReactNode;
|
|
122
|
+
}
|
|
123
|
+
export interface ImageViewerProps {
|
|
124
|
+
image: ViewedImage;
|
|
125
|
+
onClose: () => void;
|
|
126
|
+
}
|
|
127
|
+
export interface IconProps {
|
|
128
|
+
name: IconName;
|
|
129
|
+
color: string;
|
|
130
|
+
size?: number;
|
|
131
|
+
}
|
|
132
|
+
export type IconName = 'close' | 'send' | 'photo' | 'file' | 'download' | 'remove' | 'mark';
|
|
133
|
+
export interface ExpoImagePickerAsset {
|
|
134
|
+
uri: string;
|
|
135
|
+
fileName?: string | null;
|
|
136
|
+
mimeType?: string | null;
|
|
137
|
+
width?: number;
|
|
138
|
+
height?: number;
|
|
139
|
+
fileSize?: number | null;
|
|
140
|
+
}
|
|
141
|
+
export interface ExpoImagePickerOptions {
|
|
142
|
+
mediaTypes: Array<'images'>;
|
|
143
|
+
allowsMultipleSelection: boolean;
|
|
144
|
+
selectionLimit: number;
|
|
145
|
+
quality: number;
|
|
146
|
+
preferredAssetRepresentationMode: 'compatible';
|
|
147
|
+
}
|
|
148
|
+
export interface ExpoImagePickerResult {
|
|
149
|
+
canceled: boolean;
|
|
150
|
+
assets: Array<ExpoImagePickerAsset> | null;
|
|
151
|
+
}
|
|
152
|
+
export interface ExpoImagePickerModule {
|
|
153
|
+
launchImageLibraryAsync: (options: ExpoImagePickerOptions) => Promise<ExpoImagePickerResult>;
|
|
154
|
+
}
|
|
155
|
+
export interface ImagePickerAsset {
|
|
156
|
+
uri?: string;
|
|
157
|
+
fileName?: string;
|
|
158
|
+
type?: string;
|
|
159
|
+
width?: number;
|
|
160
|
+
height?: number;
|
|
161
|
+
fileSize?: number;
|
|
162
|
+
}
|
|
163
|
+
/** A photo as either picker describes it. */
|
|
164
|
+
export interface PickerAsset {
|
|
165
|
+
uri: string;
|
|
166
|
+
fileName?: string | null;
|
|
167
|
+
type?: string | null;
|
|
168
|
+
width?: number;
|
|
169
|
+
height?: number;
|
|
170
|
+
fileSize?: number | null;
|
|
171
|
+
}
|
|
172
|
+
export interface ImagePickerOptions {
|
|
173
|
+
mediaType: 'photo';
|
|
174
|
+
selectionLimit: number;
|
|
175
|
+
maxWidth: number;
|
|
176
|
+
maxHeight: number;
|
|
177
|
+
quality: number;
|
|
178
|
+
assetRepresentationMode: 'compatible';
|
|
179
|
+
}
|
|
180
|
+
export interface ImagePickerResult {
|
|
181
|
+
didCancel?: boolean;
|
|
182
|
+
errorCode?: string;
|
|
183
|
+
assets?: Array<ImagePickerAsset>;
|
|
184
|
+
}
|
|
185
|
+
export interface ImagePickerModule {
|
|
186
|
+
launchImageLibrary: (options: ImagePickerOptions) => Promise<ImagePickerResult>;
|
|
187
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Chat } from '@zean/sdk-core';
|
|
2
|
+
import type { ZeanControls } from '../interfaces';
|
|
3
|
+
import type { ChatView } from './sdk.interface';
|
|
4
|
+
/** The chat's methods. Usable before `<ZeanChat>` mounts: what is asked waits for the chat. */
|
|
5
|
+
export declare const zean: Omit<ZeanControls, 'unreadCount'>;
|
|
6
|
+
/** `<ZeanChat>` hands over the chat it started. Returns the way to let it go. */
|
|
7
|
+
export declare function attachChat(next: Chat): () => void;
|
|
8
|
+
/** Whether the chat is open and how many replies wait: the same object until one changes. */
|
|
9
|
+
export declare function chatView(): ChatView;
|
|
10
|
+
export declare function subscribeChatView(listener: () => void): () => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ChatColors, ScreenInsets } from './sdk.interface';
|
|
2
|
+
import type { ZeanColorScheme } from '../interfaces';
|
|
3
|
+
/** `{name}` in a text, filled from `values`. */
|
|
4
|
+
export declare function format(template: string, values: Record<string, string | number>): string;
|
|
5
|
+
/** The chat's colours: the App's, made for the screen's scheme, and the neutral ones around them. */
|
|
6
|
+
export declare function chatColors(color: string, scheme: ZeanColorScheme): ChatColors;
|
|
7
|
+
/**
|
|
8
|
+
* The phone's languages, preferred first. On iOS the list the person ordered in Settings: the app's own language is
|
|
9
|
+
* only one the app was translated into.
|
|
10
|
+
*/
|
|
11
|
+
export declare function deviceLanguages(): Array<string>;
|
|
12
|
+
/** "iOS 18.2" or "Android 15", for the Contact panel. */
|
|
13
|
+
export declare function deviceOs(): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The room the system takes at the top and the bottom of the chat, without a native module. On Android and on an iPad
|
|
16
|
+
* the chat covers the whole screen, under the status bar and the navigation bar. On an iPhone it is a sheet below the
|
|
17
|
+
* status bar; an iPhone without a Home button keeps 34 points at the bottom for its home bar (21 lying down).
|
|
18
|
+
*/
|
|
19
|
+
export declare function screenInsets(): ScreenInsets;
|
|
20
|
+
/**
|
|
21
|
+
* Closes the keyboard and waits until it is gone. A picker opened while it shows can fail to appear on iOS: it looks
|
|
22
|
+
* for the screen on top, and finds the keyboard's.
|
|
23
|
+
*/
|
|
24
|
+
export declare function hideKeyboard(): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@zean-chat/react-native",
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"keywords": [
|
|
6
|
+
"react-native",
|
|
7
|
+
"expo",
|
|
8
|
+
"ios",
|
|
9
|
+
"android",
|
|
10
|
+
"mobile-chat",
|
|
11
|
+
"mobile-sdk",
|
|
12
|
+
"in-app-messaging",
|
|
13
|
+
"typescript",
|
|
14
|
+
"live-chat",
|
|
15
|
+
"chat-widget",
|
|
16
|
+
"support-chat",
|
|
17
|
+
"customer-support",
|
|
18
|
+
"customer-service",
|
|
19
|
+
"helpdesk",
|
|
20
|
+
"help-desk",
|
|
21
|
+
"in-app-chat",
|
|
22
|
+
"chat",
|
|
23
|
+
"messaging",
|
|
24
|
+
"zean",
|
|
25
|
+
"intercom-alternative",
|
|
26
|
+
"crisp-alternative",
|
|
27
|
+
"tawk-to-alternative",
|
|
28
|
+
"zendesk-alternative"
|
|
29
|
+
],
|
|
30
|
+
"homepage": "https://zean.chat/docs/install-react-native",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://zean.chat/contact"
|
|
33
|
+
},
|
|
34
|
+
"author": "Zean (https://zean.chat)",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"zean-source": "./src/index.ts",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"prepublishOnly": "npm run build",
|
|
54
|
+
"build": "node ../../scripts/build-sdk.mjs cjs",
|
|
55
|
+
"check-types": "tsc --noEmit"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"expo-image-picker": "*",
|
|
59
|
+
"react": ">=19",
|
|
60
|
+
"react-native": ">=0.78",
|
|
61
|
+
"react-native-image-picker": "*"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"expo-image-picker": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"react-native-image-picker": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@types/react": "19.2.14",
|
|
73
|
+
"@zean/config": "*",
|
|
74
|
+
"@zean/sdk-core": "*",
|
|
75
|
+
"@zean/shared": "*",
|
|
76
|
+
"convex": "1.46.0",
|
|
77
|
+
"react": "19.2.5",
|
|
78
|
+
"react-native": "0.87.1",
|
|
79
|
+
"typescript": "6.0.3",
|
|
80
|
+
"vitest": "4.1.11"
|
|
81
|
+
}
|
|
82
|
+
}
|