@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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +23 -0
  3. package/lib/commonjs/client.js +79 -0
  4. package/lib/commonjs/client.js.map +1 -0
  5. package/lib/commonjs/encoding.js +90 -0
  6. package/lib/commonjs/encoding.js.map +1 -0
  7. package/lib/commonjs/expo.js +60 -0
  8. package/lib/commonjs/expo.js.map +1 -0
  9. package/lib/commonjs/exports.js +58 -0
  10. package/lib/commonjs/exports.js.map +1 -0
  11. package/lib/commonjs/index.js +21 -0
  12. package/lib/commonjs/index.js.map +1 -0
  13. package/lib/commonjs/package.json +1 -0
  14. package/lib/commonjs/runtime.js +53 -0
  15. package/lib/commonjs/runtime.js.map +1 -0
  16. package/lib/module/client.js +74 -0
  17. package/lib/module/client.js.map +1 -0
  18. package/lib/module/encoding.js +86 -0
  19. package/lib/module/encoding.js.map +1 -0
  20. package/lib/module/expo.js +39 -0
  21. package/lib/module/expo.js.map +1 -0
  22. package/lib/module/exports.js +7 -0
  23. package/lib/module/exports.js.map +1 -0
  24. package/lib/module/index.js +8 -0
  25. package/lib/module/index.js.map +1 -0
  26. package/lib/module/package.json +1 -0
  27. package/lib/module/runtime.js +47 -0
  28. package/lib/module/runtime.js.map +1 -0
  29. package/lib/typescript/commonjs/client.d.ts +26 -0
  30. package/lib/typescript/commonjs/client.d.ts.map +1 -0
  31. package/lib/typescript/commonjs/encoding.d.ts +3 -0
  32. package/lib/typescript/commonjs/encoding.d.ts.map +1 -0
  33. package/lib/typescript/commonjs/expo.d.ts +9 -0
  34. package/lib/typescript/commonjs/expo.d.ts.map +1 -0
  35. package/lib/typescript/commonjs/exports.d.ts +8 -0
  36. package/lib/typescript/commonjs/exports.d.ts.map +1 -0
  37. package/lib/typescript/commonjs/index.d.ts +4 -0
  38. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  39. package/lib/typescript/commonjs/package.json +1 -0
  40. package/lib/typescript/commonjs/runtime.d.ts +21 -0
  41. package/lib/typescript/commonjs/runtime.d.ts.map +1 -0
  42. package/lib/typescript/module/client.d.ts +26 -0
  43. package/lib/typescript/module/client.d.ts.map +1 -0
  44. package/lib/typescript/module/encoding.d.ts +3 -0
  45. package/lib/typescript/module/encoding.d.ts.map +1 -0
  46. package/lib/typescript/module/expo.d.ts +9 -0
  47. package/lib/typescript/module/expo.d.ts.map +1 -0
  48. package/lib/typescript/module/exports.d.ts +8 -0
  49. package/lib/typescript/module/exports.d.ts.map +1 -0
  50. package/lib/typescript/module/index.d.ts +4 -0
  51. package/lib/typescript/module/index.d.ts.map +1 -0
  52. package/lib/typescript/module/package.json +1 -0
  53. package/lib/typescript/module/runtime.d.ts +21 -0
  54. package/lib/typescript/module/runtime.d.ts.map +1 -0
  55. package/package.json +78 -0
  56. package/src/client.ts +92 -0
  57. package/src/encoding.ts +69 -0
  58. package/src/expo.ts +38 -0
  59. package/src/exports.ts +20 -0
  60. package/src/index.ts +7 -0
  61. 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
@@ -0,0 +1,7 @@
1
+ import 'react-native-url-polyfill/auto'
2
+ import 'react-native-get-random-values'
3
+ import { installEncodingPolyfills } from './encoding'
4
+
5
+ installEncodingPolyfills()
6
+
7
+ export * from './exports'
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
+ }