@convokitapp/react-native 0.4.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 +23 -0
- package/lib/commonjs/client.js +79 -0
- package/lib/commonjs/client.js.map +1 -0
- package/lib/commonjs/encoding.js +90 -0
- package/lib/commonjs/encoding.js.map +1 -0
- package/lib/commonjs/expo.js +60 -0
- package/lib/commonjs/expo.js.map +1 -0
- package/lib/commonjs/exports.js +58 -0
- package/lib/commonjs/exports.js.map +1 -0
- package/lib/commonjs/index.js +21 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/runtime.js +53 -0
- package/lib/commonjs/runtime.js.map +1 -0
- package/lib/module/client.js +74 -0
- package/lib/module/client.js.map +1 -0
- package/lib/module/encoding.js +86 -0
- package/lib/module/encoding.js.map +1 -0
- package/lib/module/expo.js +39 -0
- package/lib/module/expo.js.map +1 -0
- package/lib/module/exports.js +7 -0
- package/lib/module/exports.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/runtime.js +47 -0
- package/lib/module/runtime.js.map +1 -0
- package/lib/typescript/commonjs/client.d.ts +26 -0
- package/lib/typescript/commonjs/client.d.ts.map +1 -0
- package/lib/typescript/commonjs/encoding.d.ts +3 -0
- package/lib/typescript/commonjs/encoding.d.ts.map +1 -0
- package/lib/typescript/commonjs/expo.d.ts +9 -0
- package/lib/typescript/commonjs/expo.d.ts.map +1 -0
- package/lib/typescript/commonjs/exports.d.ts +8 -0
- package/lib/typescript/commonjs/exports.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +4 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/runtime.d.ts +21 -0
- package/lib/typescript/commonjs/runtime.d.ts.map +1 -0
- package/lib/typescript/module/client.d.ts +26 -0
- package/lib/typescript/module/client.d.ts.map +1 -0
- package/lib/typescript/module/encoding.d.ts +3 -0
- package/lib/typescript/module/encoding.d.ts.map +1 -0
- package/lib/typescript/module/expo.d.ts +9 -0
- package/lib/typescript/module/expo.d.ts.map +1 -0
- package/lib/typescript/module/exports.d.ts +8 -0
- package/lib/typescript/module/exports.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +4 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/runtime.d.ts +21 -0
- package/lib/typescript/module/runtime.d.ts.map +1 -0
- package/package.json +78 -0
- package/src/client.ts +92 -0
- package/src/encoding.ts +69 -0
- package/src/expo.ts +38 -0
- package/src/exports.ts +20 -0
- package/src/index.ts +7 -0
- package/src/runtime.ts +64 -0
package/src/exports.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { ConvoKitClient } from './client'
|
|
2
|
+
export type { NativeMessageMediaInput, ReactNativeClientOptions } from './client'
|
|
3
|
+
export { assertReactNativeRuntime, fetchRuntimeAdapter } from './runtime'
|
|
4
|
+
export { installEncodingPolyfills } from './encoding'
|
|
5
|
+
export type {
|
|
6
|
+
DownloadedMediaInput,
|
|
7
|
+
NativeFileInput,
|
|
8
|
+
ReactNativeRuntimeAdapter,
|
|
9
|
+
} from './runtime'
|
|
10
|
+
export { CONVOKIT_API_URL, ConvoKitError, ConvoKitRealtime, createClientMessageId } from '@convokitapp/sdk'
|
|
11
|
+
export type {
|
|
12
|
+
AppUser, ContactMedia, Conversation, ConversationListOptions, ConvoKitClientOptions,
|
|
13
|
+
CreateConversationInput, FetchImplementation, FileMedia, ImageMedia, JsonPrimitive,
|
|
14
|
+
JsonValue, LocationMedia, Message, MessageDeletedEvent, MessageEvent, MessageListOptions,
|
|
15
|
+
MessageMedia, Page, PaginationOptions, Participant, PresenceEvent,
|
|
16
|
+
ReadEvent, RealtimeConnectionEvent, RealtimeConnectionHandlers, RealtimeHandlers,
|
|
17
|
+
RealtimeStatus, RealtimeSubscription, SendMessageInput, TokenProvider, TypingEvent,
|
|
18
|
+
UploadBody, UploadConversationImageInput, UploadInput, UploadMessageMediaInput,
|
|
19
|
+
UploadUserAvatarInput,
|
|
20
|
+
} from '@convokitapp/sdk'
|
package/src/index.ts
ADDED
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ConvoKitError, type UploadBody } from '@convokitapp/sdk'
|
|
2
|
+
|
|
3
|
+
export interface NativeFileInput {
|
|
4
|
+
uri: string
|
|
5
|
+
fileName: string
|
|
6
|
+
contentType?: string
|
|
7
|
+
size?: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface DownloadedMediaInput {
|
|
11
|
+
blob: Blob
|
|
12
|
+
fileName: string
|
|
13
|
+
contentType?: string
|
|
14
|
+
destinationUri?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ReactNativeRuntimeAdapter {
|
|
18
|
+
readFile(input: NativeFileInput): Promise<UploadBody>
|
|
19
|
+
saveDownload?(input: DownloadedMediaInput): Promise<string>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const fetchRuntimeAdapter: ReactNativeRuntimeAdapter = {
|
|
23
|
+
async readFile(input) {
|
|
24
|
+
if (!input.uri.trim()) {
|
|
25
|
+
throw new ConvoKitError('uri is required', { code: 'INVALID_ARGUMENT' })
|
|
26
|
+
}
|
|
27
|
+
let response: Response
|
|
28
|
+
try {
|
|
29
|
+
response = await fetch(input.uri)
|
|
30
|
+
} catch (cause) {
|
|
31
|
+
throw new ConvoKitError('Could not read the selected file', {
|
|
32
|
+
code: 'NATIVE_FILE_READ_FAILED',
|
|
33
|
+
cause,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
throw new ConvoKitError('Could not read the selected file', {
|
|
38
|
+
code: 'NATIVE_FILE_READ_FAILED',
|
|
39
|
+
status: response.status,
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
return response.blob()
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function assertReactNativeRuntime(): void {
|
|
47
|
+
const missing = ['fetch', 'URL', 'WebSocket', 'atob', 'TextDecoder'].filter(
|
|
48
|
+
key => typeof (globalThis as Record<string, unknown>)[key] === 'undefined',
|
|
49
|
+
)
|
|
50
|
+
if (typeof globalThis.crypto?.getRandomValues !== 'function') {
|
|
51
|
+
missing.push('crypto.getRandomValues')
|
|
52
|
+
}
|
|
53
|
+
if (missing.length) {
|
|
54
|
+
throw new ConvoKitError(`React Native runtime is missing: ${missing.join(', ')}`, {
|
|
55
|
+
code: 'REACT_NATIVE_RUNTIME_UNAVAILABLE',
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function requiredText(value: string, name: string): string {
|
|
61
|
+
const result = value.trim()
|
|
62
|
+
if (!result) throw new ConvoKitError(`${name} is required`, { code: 'INVALID_ARGUMENT' })
|
|
63
|
+
return result
|
|
64
|
+
}
|