@planningcenter/chat-react-native 4.8.0-rc.1 → 4.8.0-rc.10
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/build/components/conversations/bulk_conversation_actions_bar.d.ts +2 -0
- package/build/components/conversations/bulk_conversation_actions_bar.d.ts.map +1 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js +215 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js.map +1 -0
- package/build/components/conversations/conversation_actions.d.ts +2 -1
- package/build/components/conversations/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +173 -130
- package/build/components/conversations/conversation_actions.js.map +1 -1
- package/build/components/conversations/conversation_preview.d.ts.map +1 -1
- package/build/components/conversations/conversation_preview.js +168 -110
- package/build/components/conversations/conversation_preview.js.map +1 -1
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +50 -48
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/display/checkbox.d.ts +8 -0
- package/build/components/display/checkbox.d.ts.map +1 -0
- package/build/components/display/checkbox.js +87 -0
- package/build/components/display/checkbox.js.map +1 -0
- package/build/components/display/icon.d.ts +3 -1
- package/build/components/display/icon.d.ts.map +1 -1
- package/build/components/display/icon.js +2 -0
- package/build/components/display/icon.js.map +1 -1
- package/build/components/display/index.d.ts +1 -0
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +1 -0
- package/build/components/display/index.js.map +1 -1
- package/build/contexts/api_provider.d.ts.map +1 -1
- package/build/contexts/api_provider.js +2 -0
- package/build/contexts/api_provider.js.map +1 -1
- package/build/contexts/chat_context.d.ts +0 -2
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +16 -93
- package/build/contexts/chat_context.js.map +1 -1
- package/build/contexts/conversations_context.d.ts +5 -0
- package/build/contexts/conversations_context.d.ts.map +1 -1
- package/build/contexts/conversations_context.js +121 -32
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/contexts/session_context.d.ts +0 -1
- package/build/contexts/session_context.d.ts.map +1 -1
- package/build/contexts/session_context.js +3 -0
- package/build/contexts/session_context.js.map +1 -1
- package/build/hooks/groups/use_group_chat_conversation_payload.d.ts +11 -1
- package/build/hooks/groups/use_group_chat_conversation_payload.d.ts.map +1 -1
- package/build/hooks/groups/use_group_chat_conversation_payload.js +92 -47
- package/build/hooks/groups/use_group_chat_conversation_payload.js.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +27 -25
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.js +125 -110
- package/build/hooks/groups/use_group_members_for_new_conversation.js.map +1 -1
- package/build/hooks/groups/use_groups_conversation_create.d.ts.map +1 -1
- package/build/hooks/groups/use_groups_conversation_create.js +39 -31
- package/build/hooks/groups/use_groups_conversation_create.js.map +1 -1
- package/build/hooks/groups/use_groups_proxy.d.ts +2 -0
- package/build/hooks/groups/use_groups_proxy.d.ts.map +1 -0
- package/build/hooks/groups/use_groups_proxy.js +18 -0
- package/build/hooks/groups/use_groups_proxy.js.map +1 -0
- package/build/hooks/use_bulk_conversation_actions.d.ts +8 -0
- package/build/hooks/use_bulk_conversation_actions.d.ts.map +1 -0
- package/build/hooks/use_bulk_conversation_actions.js +309 -0
- package/build/hooks/use_bulk_conversation_actions.js.map +1 -0
- package/build/hooks/use_conversation_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_jolt_events.js +3 -2
- package/build/hooks/use_conversation_jolt_events.js.map +1 -1
- package/build/hooks/use_conversations_actions.d.ts +9 -9
- package/build/hooks/use_conversations_actions.d.ts.map +1 -1
- package/build/hooks/use_conversations_actions.js +12 -7
- package/build/hooks/use_conversations_actions.js.map +1 -1
- package/build/hooks/use_conversations_cache.d.ts +15 -5
- package/build/hooks/use_conversations_cache.d.ts.map +1 -1
- package/build/hooks/use_conversations_cache.js +170 -122
- package/build/hooks/use_conversations_cache.js.map +1 -1
- package/build/hooks/use_conversations_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversations_jolt_events.js +47 -20
- package/build/hooks/use_conversations_jolt_events.js.map +1 -1
- package/build/hooks/use_features.d.ts +1 -0
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +1 -0
- package/build/hooks/use_features.js.map +1 -1
- package/build/hooks/use_groups_groups.d.ts.map +1 -1
- package/build/hooks/use_groups_groups.js +25 -9
- package/build/hooks/use_groups_groups.js.map +1 -1
- package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
- package/build/hooks/use_mark_latest_message_read.js +5 -4
- package/build/hooks/use_mark_latest_message_read.js.map +1 -1
- package/build/hooks/use_new_conversation_from_filter.d.ts.map +1 -1
- package/build/hooks/use_new_conversation_from_filter.js +11 -1
- package/build/hooks/use_new_conversation_from_filter.js.map +1 -1
- package/build/hooks/use_product_analytics.d.ts.map +1 -1
- package/build/hooks/use_product_analytics.js +93 -75
- package/build/hooks/use_product_analytics.js.map +1 -1
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -7
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_actions_screen.d.ts +2 -0
- package/build/screens/conversation_actions_screen.d.ts.map +1 -1
- package/build/screens/conversation_actions_screen.js +380 -46
- package/build/screens/conversation_actions_screen.js.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.d.ts.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.js +9 -64
- package/build/screens/conversation_filter_recipients/components/checkbox_row.js.map +1 -1
- package/build/screens/conversation_new/components/groups_form.d.ts.map +1 -1
- package/build/screens/conversation_new/components/groups_form.js +96 -93
- package/build/screens/conversation_new/components/groups_form.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts +5 -0
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +156 -31
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/types/jolt_events/index.d.ts +2 -0
- package/build/types/jolt_events/index.d.ts.map +1 -1
- package/build/types/jolt_events/index.js.map +1 -1
- package/build/types/jolt_events/person_events.d.ts +9 -0
- package/build/types/jolt_events/person_events.d.ts.map +1 -0
- package/build/types/jolt_events/person_events.js +2 -0
- package/build/types/jolt_events/person_events.js.map +1 -0
- package/build/types/resources/groups/groups_group_resource.d.ts +1 -1
- package/build/types/resources/groups/groups_group_resource.d.ts.map +1 -1
- package/build/types/resources/groups/groups_group_resource.js.map +1 -1
- package/build/types/resources/groups/groups_membership_resource.d.ts +11 -0
- package/build/types/resources/groups/groups_membership_resource.d.ts.map +1 -0
- package/build/types/resources/groups/groups_membership_resource.js +2 -0
- package/build/types/resources/groups/groups_membership_resource.js.map +1 -0
- package/build/types/resources/groups/index.d.ts +1 -0
- package/build/types/resources/groups/index.d.ts.map +1 -1
- package/build/types/resources/groups/index.js +1 -0
- package/build/types/resources/groups/index.js.map +1 -1
- package/build/utils/jolt/parse_stream_user_event_type.d.ts +3 -0
- package/build/utils/jolt/parse_stream_user_event_type.d.ts.map +1 -0
- package/build/utils/jolt/parse_stream_user_event_type.js +9 -0
- package/build/utils/jolt/parse_stream_user_event_type.js.map +1 -0
- package/build/utils/native_adapters/configuration.d.ts +3 -0
- package/build/utils/native_adapters/configuration.d.ts.map +1 -1
- package/build/utils/native_adapters/configuration.js +3 -0
- package/build/utils/native_adapters/configuration.js.map +1 -1
- package/build/utils/native_adapters/index.d.ts +1 -0
- package/build/utils/native_adapters/index.d.ts.map +1 -1
- package/build/utils/native_adapters/index.js +1 -0
- package/build/utils/native_adapters/index.js.map +1 -1
- package/build/utils/native_adapters/updates.d.ts +11 -0
- package/build/utils/native_adapters/updates.d.ts.map +1 -0
- package/build/utils/native_adapters/updates.js +8 -0
- package/build/utils/native_adapters/updates.js.map +1 -0
- package/build/utils/product_analytics_token.d.ts +12 -0
- package/build/utils/product_analytics_token.d.ts.map +1 -0
- package/build/utils/product_analytics_token.js +84 -0
- package/build/utils/product_analytics_token.js.map +1 -0
- package/build/utils/throttled_refresh.d.ts +7 -0
- package/build/utils/throttled_refresh.d.ts.map +1 -0
- package/build/utils/throttled_refresh.js +42 -0
- package/build/utils/throttled_refresh.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/contexts/session_context.tsx +19 -39
- package/src/__tests__/hooks/useTheme.tsx +0 -7
- package/src/__tests__/hooks/use_async_storage.test.tsx +1 -87
- package/src/__tests__/hooks/use_attachment_uploader.test.tsx +0 -11
- package/src/__tests__/hooks/use_font_scale.test.ts +0 -25
- package/src/__tests__/hooks/use_group_chat_conversation_payload.test.tsx +31 -0
- package/src/__tests__/utils/cache/page_mutations.ts +3 -68
- package/src/__tests__/utils/client.ts +6 -15
- package/src/__tests__/utils/native_adapters/configuration.ts +15 -50
- package/src/__tests__/utils/parse_simple_markdown.ts +0 -6
- package/src/__tests__/utils/session.ts +0 -11
- package/src/__tests__/utils/theme.ts +0 -17
- package/src/components/conversations/__tests__/bulk_conversation_actions_bar.test.tsx +95 -0
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +35 -3
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +69 -3
- package/src/components/conversations/__tests__/conversations.test.tsx +4 -1
- package/src/components/conversations/bulk_conversation_actions_bar.tsx +140 -0
- package/src/components/conversations/conversation_actions.tsx +17 -9
- package/src/components/conversations/conversation_preview.tsx +20 -2
- package/src/components/conversations/conversations.tsx +2 -1
- package/src/components/display/__tests__/filter_dropdown.test.tsx +1 -19
- package/src/components/display/__tests__/icon_tile.test.tsx +24 -7
- package/src/components/display/checkbox.tsx +47 -0
- package/src/components/display/icon.tsx +3 -0
- package/src/components/display/index.ts +1 -0
- package/src/components/page/__tests__/component_error_boundary.test.tsx +0 -12
- package/src/contexts/__tests__/conversations_context.test.tsx +86 -0
- package/src/contexts/api_provider.tsx +2 -0
- package/src/contexts/chat_context.tsx +2 -58
- package/src/contexts/conversations_context.tsx +69 -2
- package/src/contexts/session_context.tsx +3 -1
- package/src/hooks/__tests__/jolt_refresh_throttling.test.tsx +194 -0
- package/src/hooks/__tests__/use_bulk_conversation_actions.test.tsx +119 -0
- package/src/hooks/__tests__/use_conversations_jolt_events.test.tsx +1 -0
- package/src/hooks/__tests__/use_conversations_mark_read.test.tsx +38 -12
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +15 -3
- package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +23 -2
- package/src/hooks/__tests__/use_product_analytics.test.tsx +304 -0
- package/src/hooks/groups/use_group_chat_conversation_payload.ts +30 -12
- package/src/hooks/groups/use_group_members_for_new_conversation.ts +49 -18
- package/src/hooks/groups/use_groups_conversation_create.ts +10 -14
- package/src/hooks/groups/use_groups_proxy.ts +6 -0
- package/src/hooks/use_bulk_conversation_actions.ts +173 -0
- package/src/hooks/use_conversation_jolt_events.ts +2 -1
- package/src/hooks/use_conversations_actions.ts +7 -4
- package/src/hooks/use_conversations_cache.ts +33 -26
- package/src/hooks/use_conversations_jolt_events.ts +24 -10
- package/src/hooks/use_features.ts +1 -0
- package/src/hooks/use_groups_groups.ts +21 -16
- package/src/hooks/use_mark_latest_message_read.ts +6 -5
- package/src/hooks/use_new_conversation_from_filter.ts +13 -5
- package/src/hooks/use_product_analytics.ts +74 -41
- package/src/navigation/index.tsx +8 -8
- package/src/screens/__tests__/conversation_actions_screen.test.tsx +48 -6
- package/src/screens/__tests__/conversation_details_screen.test.tsx +0 -19
- package/src/screens/avatar_picker/__tests__/avatar_picker_state.test.ts +0 -14
- package/src/screens/conversation_actions_screen.tsx +145 -12
- package/src/screens/conversation_filter_recipients/components/checkbox_row.tsx +3 -35
- package/src/screens/conversation_new/components/groups_form.tsx +11 -9
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +35 -9
- package/src/screens/conversations/components/__tests__/filter_dropdown_list_header_component.test.tsx +0 -8
- package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +0 -10
- package/src/screens/conversations/conversations_screen.tsx +67 -3
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +1 -0
- package/src/types/jolt_events/index.ts +2 -0
- package/src/types/jolt_events/person_events.ts +16 -0
- package/src/types/resources/groups/groups_group_resource.ts +1 -1
- package/src/types/resources/groups/groups_membership_resource.ts +10 -0
- package/src/types/resources/groups/index.ts +1 -0
- package/src/utils/__tests__/attachment_kind.test.ts +0 -4
- package/src/utils/__tests__/convert_attachments_for_create.test.ts +0 -28
- package/src/utils/__tests__/is_input_editable.test.ts +1 -2
- package/src/utils/__tests__/message_text.test.ts +0 -5
- package/src/utils/__tests__/session_manager.test.ts +0 -83
- package/src/utils/__tests__/sha_256.test.ts +0 -34
- package/src/utils/__tests__/throttled_refresh.test.ts +101 -0
- package/src/utils/__tests__/uri.test.ts +51 -0
- package/src/utils/jolt/__tests__/parse_stream_user_event_type.test.ts +27 -0
- package/src/utils/jolt/parse_stream_user_event_type.ts +16 -0
- package/src/utils/native_adapters/configuration.ts +5 -0
- package/src/utils/native_adapters/index.ts +1 -0
- package/src/utils/native_adapters/updates.ts +16 -0
- package/src/utils/product_analytics_token.ts +120 -0
- package/src/utils/throttled_refresh.ts +62 -0
- package/src/__tests__/event-polyfill.test.ts +0 -313
- package/src/__tests__/index.tsx +0 -5
- package/src/__tests__/jest.ts +0 -11
- package/src/__tests__/utils/uri.ts +0 -65
- package/src/components/display/__tests__/version_footer.test.tsx +0 -48
- package/src/screens/search/components/__tests__/search_blank_states.test.tsx +0 -20
- package/src/utils/__tests__/membership_sync_info_text.test.ts +0 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/configuration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,aAAa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E,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,KAAK,kBAAkB,GAAG;IACxB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,KAAK,EAAE,YAAY,CAAA;IACnB,KAAK,EAAE,YAAY,CAAA;IACnB,WAAW,EAAE,kBAAkB,CAAA;IAC/B,cAAc,CAAC,EAAE,qBAAqB,CAAA;IACtC,GAAG,CAAC,EAAE,UAAU,CAAA;IAChB,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB,CAAA;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB;CAYpD;AAMD,eAAO,IAAI,SAAS,EAAE,gBAMpB,CAAA;AAEF,eAAO,IAAI,KAAK,EAAE,YAKhB,CAAA;AAEF,eAAO,IAAI,KAAK,EAAE,YAQhB,CAAA;AAEF,eAAO,IAAI,WAAW,EAAE,kBAStB,CAAA;AAEF,eAAO,IAAI,cAAc,EAAE,qBAAmD,CAAA;AAE9E,eAAO,IAAI,GAAG,EAAE,UAA6B,CAAA;AAE7C,eAAO,IAAI,OAAO,EAAE,cAA8C,CAAA;AAElE,eAAO,IAAI,MAAM,EAAE,aAAmC,CAAA;AAEtD,eAAO,IAAI,IAAI,EAAE,WAA+B,CAAA;AAEhD,eAAO,IAAI,OAAO,EAAE,cAAqC,CAAA;AAEzD,eAAO,IAAI,OAAO,gBAIhB,CAAA"}
|
|
@@ -9,6 +9,7 @@ import { LinkingAdapter } from './linking';
|
|
|
9
9
|
import { LogAdapter } from './log';
|
|
10
10
|
import { MenuAdapter } from './menu';
|
|
11
11
|
import { StorageAdapter } from './storage_adapter';
|
|
12
|
+
import { UpdatesAdapter } from './updates';
|
|
12
13
|
import { VideoAdapter } from './video';
|
|
13
14
|
export class ChatAdapters {
|
|
14
15
|
static configure(configurations) {
|
|
@@ -21,6 +22,7 @@ export class ChatAdapters {
|
|
|
21
22
|
Linking = configurations.linking || new LinkingAdapter(RNLinking);
|
|
22
23
|
Haptic = configurations.haptic || new HapticAdapter();
|
|
23
24
|
Menu = configurations.menu || new MenuAdapter();
|
|
25
|
+
Updates = configurations.updates || new UpdatesAdapter();
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
const methodMissing = () => {
|
|
@@ -68,6 +70,7 @@ export let Log = new LogAdapter();
|
|
|
68
70
|
export let Linking = new LinkingAdapter(RNLinking);
|
|
69
71
|
export let Haptic = new HapticAdapter();
|
|
70
72
|
export let Menu = new MenuAdapter();
|
|
73
|
+
export let Updates = new UpdatesAdapter();
|
|
71
74
|
export let Storage = new StorageAdapter({
|
|
72
75
|
getItem: AsyncStorage.getItem,
|
|
73
76
|
setItem: AsyncStorage.setItem,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","names":["AsyncStorage","Linking","RNLinking","AudioAdapter","ClipboardAdapter","DocumentPickerAdapter","HapticAdapter","ImagePickerAdapter","LinkingAdapter","LogAdapter","MenuAdapter","StorageAdapter","VideoAdapter","ChatAdapters","configure","configurations","Clipboard","clipboard","Audio","audio","Video","video","ImagePicker","imagePicker","DocumentPicker","documentPicker","Log","log","linking","Haptic","haptic","Menu","menu","methodMissing","console","warn","getStringAsync","setStringAsync","_","useAudio","Player","Object","assign","$$typeof","Symbol","for","openCameraAsync","canceled","assets","openImageLibraryAsync","Storage","getItem","setItem","removeItem"],"sources":["../../../src/utils/native_adapters/configuration.ts"],"sourcesContent":["import AsyncStorage from '@react-native-async-storage/async-storage'\nimport { Linking as RNLinking } from 'react-native'\nimport { AudioAdapter } from './audio'\nimport { ClipboardAdapter } from './clipboard'\nimport { DocumentPickerAdapter } from './document_picker'\nimport { HapticAdapter } from './haptic'\nimport { ImagePickerAdapter } from './image_picker'\nimport { LinkingAdapter } from './linking'\nimport { LogAdapter } from './log'\nimport { MenuAdapter } from './menu'\nimport { StorageAdapter } from './storage_adapter'\nimport { VideoAdapter } from './video'\n\ntype ChatConfigurations = {\n clipboard: ClipboardAdapter\n audio: AudioAdapter\n video: VideoAdapter\n imagePicker: ImagePickerAdapter\n documentPicker?: DocumentPickerAdapter\n log?: LogAdapter\n linking?: LinkingAdapter\n haptic?: HapticAdapter\n menu?: MenuAdapter\n}\n\nexport class ChatAdapters {\n static configure(configurations: ChatConfigurations) {\n Clipboard = configurations.clipboard\n Audio = configurations.audio\n Video = configurations.video\n ImagePicker = configurations.imagePicker\n DocumentPicker = configurations.documentPicker || new DocumentPickerAdapter()\n Log = configurations.log || new LogAdapter()\n Linking = configurations.linking || new LinkingAdapter(RNLinking)\n Haptic = configurations.haptic || new HapticAdapter()\n Menu = configurations.menu || new MenuAdapter()\n }\n}\n\nconst methodMissing = () => {\n console.warn('ChatAdapters.configure() must be called before using any adapters')\n}\n\nexport let Clipboard: ClipboardAdapter = new ClipboardAdapter({\n getStringAsync: async () => {\n methodMissing()\n return ''\n },\n setStringAsync: async (_: string) => methodMissing(),\n})\n\nexport let Audio: AudioAdapter = new AudioAdapter({\n useAudio: (_: string) => {\n methodMissing()\n return {} as any\n },\n})\n\nexport let Video: VideoAdapter = new VideoAdapter({\n Player: Object.assign(\n () => {\n methodMissing()\n return null\n },\n { $$typeof: Symbol.for('react.forward_ref') }\n ),\n})\n\nexport let ImagePicker: ImagePickerAdapter = new ImagePickerAdapter({\n openCameraAsync: async () => {\n methodMissing()\n return { canceled: true, assets: null }\n },\n openImageLibraryAsync: async () => {\n methodMissing()\n return { canceled: true, assets: null }\n },\n})\n\nexport let DocumentPicker: DocumentPickerAdapter = new DocumentPickerAdapter()\n\nexport let Log: LogAdapter = new LogAdapter()\n\nexport let Linking: LinkingAdapter = new LinkingAdapter(RNLinking)\n\nexport let Haptic: HapticAdapter = new HapticAdapter()\n\nexport let Menu: MenuAdapter = new MenuAdapter()\n\nexport let Storage = new StorageAdapter({\n getItem: AsyncStorage.getItem,\n setItem: AsyncStorage.setItem,\n removeItem: AsyncStorage.removeItem,\n})\n"],"mappings":"AAAA,OAAOA,YAAY,MAAM,2CAA2C;AACpE,SAASC,OAAO,IAAIC,SAAS,QAAQ,cAAc;AACnD,SAASC,YAAY,QAAQ,SAAS;AACtC,SAASC,gBAAgB,QAAQ,aAAa;AAC9C,SAASC,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,aAAa,QAAQ,UAAU;AACxC,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,cAAc,QAAQ,WAAW;AAC1C,SAASC,UAAU,QAAQ,OAAO;AAClC,SAASC,WAAW,QAAQ,QAAQ;AACpC,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,YAAY,QAAQ,SAAS;
|
|
1
|
+
{"version":3,"file":"configuration.js","names":["AsyncStorage","Linking","RNLinking","AudioAdapter","ClipboardAdapter","DocumentPickerAdapter","HapticAdapter","ImagePickerAdapter","LinkingAdapter","LogAdapter","MenuAdapter","StorageAdapter","UpdatesAdapter","VideoAdapter","ChatAdapters","configure","configurations","Clipboard","clipboard","Audio","audio","Video","video","ImagePicker","imagePicker","DocumentPicker","documentPicker","Log","log","linking","Haptic","haptic","Menu","menu","Updates","updates","methodMissing","console","warn","getStringAsync","setStringAsync","_","useAudio","Player","Object","assign","$$typeof","Symbol","for","openCameraAsync","canceled","assets","openImageLibraryAsync","Storage","getItem","setItem","removeItem"],"sources":["../../../src/utils/native_adapters/configuration.ts"],"sourcesContent":["import AsyncStorage from '@react-native-async-storage/async-storage'\nimport { Linking as RNLinking } from 'react-native'\nimport { AudioAdapter } from './audio'\nimport { ClipboardAdapter } from './clipboard'\nimport { DocumentPickerAdapter } from './document_picker'\nimport { HapticAdapter } from './haptic'\nimport { ImagePickerAdapter } from './image_picker'\nimport { LinkingAdapter } from './linking'\nimport { LogAdapter } from './log'\nimport { MenuAdapter } from './menu'\nimport { StorageAdapter } from './storage_adapter'\nimport { UpdatesAdapter } from './updates'\nimport { VideoAdapter } from './video'\n\ntype ChatConfigurations = {\n clipboard: ClipboardAdapter\n audio: AudioAdapter\n video: VideoAdapter\n imagePicker: ImagePickerAdapter\n documentPicker?: DocumentPickerAdapter\n log?: LogAdapter\n linking?: LinkingAdapter\n haptic?: HapticAdapter\n menu?: MenuAdapter\n updates?: UpdatesAdapter\n}\n\nexport class ChatAdapters {\n static configure(configurations: ChatConfigurations) {\n Clipboard = configurations.clipboard\n Audio = configurations.audio\n Video = configurations.video\n ImagePicker = configurations.imagePicker\n DocumentPicker = configurations.documentPicker || new DocumentPickerAdapter()\n Log = configurations.log || new LogAdapter()\n Linking = configurations.linking || new LinkingAdapter(RNLinking)\n Haptic = configurations.haptic || new HapticAdapter()\n Menu = configurations.menu || new MenuAdapter()\n Updates = configurations.updates || new UpdatesAdapter()\n }\n}\n\nconst methodMissing = () => {\n console.warn('ChatAdapters.configure() must be called before using any adapters')\n}\n\nexport let Clipboard: ClipboardAdapter = new ClipboardAdapter({\n getStringAsync: async () => {\n methodMissing()\n return ''\n },\n setStringAsync: async (_: string) => methodMissing(),\n})\n\nexport let Audio: AudioAdapter = new AudioAdapter({\n useAudio: (_: string) => {\n methodMissing()\n return {} as any\n },\n})\n\nexport let Video: VideoAdapter = new VideoAdapter({\n Player: Object.assign(\n () => {\n methodMissing()\n return null\n },\n { $$typeof: Symbol.for('react.forward_ref') }\n ),\n})\n\nexport let ImagePicker: ImagePickerAdapter = new ImagePickerAdapter({\n openCameraAsync: async () => {\n methodMissing()\n return { canceled: true, assets: null }\n },\n openImageLibraryAsync: async () => {\n methodMissing()\n return { canceled: true, assets: null }\n },\n})\n\nexport let DocumentPicker: DocumentPickerAdapter = new DocumentPickerAdapter()\n\nexport let Log: LogAdapter = new LogAdapter()\n\nexport let Linking: LinkingAdapter = new LinkingAdapter(RNLinking)\n\nexport let Haptic: HapticAdapter = new HapticAdapter()\n\nexport let Menu: MenuAdapter = new MenuAdapter()\n\nexport let Updates: UpdatesAdapter = new UpdatesAdapter()\n\nexport let Storage = new StorageAdapter({\n getItem: AsyncStorage.getItem,\n setItem: AsyncStorage.setItem,\n removeItem: AsyncStorage.removeItem,\n})\n"],"mappings":"AAAA,OAAOA,YAAY,MAAM,2CAA2C;AACpE,SAASC,OAAO,IAAIC,SAAS,QAAQ,cAAc;AACnD,SAASC,YAAY,QAAQ,SAAS;AACtC,SAASC,gBAAgB,QAAQ,aAAa;AAC9C,SAASC,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,aAAa,QAAQ,UAAU;AACxC,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,cAAc,QAAQ,WAAW;AAC1C,SAASC,UAAU,QAAQ,OAAO;AAClC,SAASC,WAAW,QAAQ,QAAQ;AACpC,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,cAAc,QAAQ,WAAW;AAC1C,SAASC,YAAY,QAAQ,SAAS;AAetC,OAAO,MAAMC,YAAY,CAAC;EACxB,OAAOC,SAASA,CAACC,cAAkC,EAAE;IACnDC,SAAS,GAAGD,cAAc,CAACE,SAAS;IACpCC,KAAK,GAAGH,cAAc,CAACI,KAAK;IAC5BC,KAAK,GAAGL,cAAc,CAACM,KAAK;IAC5BC,WAAW,GAAGP,cAAc,CAACQ,WAAW;IACxCC,cAAc,GAAGT,cAAc,CAACU,cAAc,IAAI,IAAIrB,qBAAqB,CAAC,CAAC;IAC7EsB,GAAG,GAAGX,cAAc,CAACY,GAAG,IAAI,IAAInB,UAAU,CAAC,CAAC;IAC5CR,OAAO,GAAGe,cAAc,CAACa,OAAO,IAAI,IAAIrB,cAAc,CAACN,SAAS,CAAC;IACjE4B,MAAM,GAAGd,cAAc,CAACe,MAAM,IAAI,IAAIzB,aAAa,CAAC,CAAC;IACrD0B,IAAI,GAAGhB,cAAc,CAACiB,IAAI,IAAI,IAAIvB,WAAW,CAAC,CAAC;IAC/CwB,OAAO,GAAGlB,cAAc,CAACmB,OAAO,IAAI,IAAIv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AC;AAE7C,OAAO,IAAIR,OAAuB,GAAG,IAAIO,cAAc,CAACN,SAAS,CAAC;AAElE,OAAO,IAAI4B,MAAqB,GAAG,IAAIxB,aAAa,CAAC,CAAC;AAEtD,OAAO,IAAI0B,IAAiB,GAAG,IAAItB,WAAW,CAAC,CAAC;AAEhD,OAAO,IAAIwB,OAAuB,GAAG,IAAItB,cAAc,CAAC,CAAC;AAEzD,OAAO,IAAIyC,OAAO,GAAG,IAAI1C,cAAc,CAAC;EACtC2C,OAAO,EAAEtD,YAAY,CAACsD,OAAO;EAC7BC,OAAO,EAAEvD,YAAY,CAACuD,OAAO;EAC7BC,UAAU,EAAExD,YAAY,CAACwD;AAC3B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/native_adapters/index.ts"],"sourcesContent":["export * from './audio'\nexport * from './clipboard'\nexport * from './configuration'\nexport * from './document_picker'\nexport * from './image_picker'\nexport * from './linking'\nexport * from './log'\nexport * from './menu'\nexport * from './video'\nexport * from './haptic'\nexport * from './storage_adapter'\n"],"mappings":"AAAA,cAAc,SAAS;AACvB,cAAc,aAAa;AAC3B,cAAc,iBAAiB;AAC/B,cAAc,mBAAmB;AACjC,cAAc,gBAAgB;AAC9B,cAAc,WAAW;AACzB,cAAc,OAAO;AACrB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,mBAAmB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/native_adapters/index.ts"],"sourcesContent":["export * from './audio'\nexport * from './clipboard'\nexport * from './configuration'\nexport * from './document_picker'\nexport * from './image_picker'\nexport * from './linking'\nexport * from './log'\nexport * from './menu'\nexport * from './video'\nexport * from './haptic'\nexport * from './storage_adapter'\nexport * from './updates'\n"],"mappings":"AAAA,cAAc,SAAS;AACvB,cAAc,aAAa;AAC3B,cAAc,iBAAiB;AAC/B,cAAc,mBAAmB;AACjC,cAAc,gBAAgB;AAC9B,cAAc,WAAW;AACzB,cAAc,OAAO;AACrB,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,mBAAmB;AACjC,cAAc,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Updates {
|
|
2
|
+
useDownloadedUpdateId: () => string | undefined;
|
|
3
|
+
restart: () => void;
|
|
4
|
+
}
|
|
5
|
+
export declare class UpdatesAdapter {
|
|
6
|
+
useDownloadedUpdateId: () => string | undefined;
|
|
7
|
+
restart: () => void;
|
|
8
|
+
constructor(methods?: Updates);
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=updates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updates.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/updates.ts"],"names":[],"mappings":"AAEA,UAAU,OAAO;IACf,qBAAqB,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IAC/C,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED,qBAAa,cAAc;IACzB,qBAAqB,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IAC/C,OAAO,EAAE,MAAM,IAAI,CAAA;gBAEP,OAAO,CAAC,EAAE,OAAO;CAI9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updates.js","names":["noop","UpdatesAdapter","constructor","methods","useDownloadedUpdateId","undefined","restart"],"sources":["../../../src/utils/native_adapters/updates.ts"],"sourcesContent":["import { noop } from 'lodash'\n\ninterface Updates {\n useDownloadedUpdateId: () => string | undefined\n restart: () => void\n}\n\nexport class UpdatesAdapter {\n useDownloadedUpdateId: () => string | undefined\n restart: () => void\n\n constructor(methods?: Updates) {\n this.useDownloadedUpdateId = methods?.useDownloadedUpdateId ?? (() => undefined)\n this.restart = methods?.restart ?? noop\n }\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,QAAQ;AAO7B,OAAO,MAAMC,cAAc,CAAC;EAI1BC,WAAWA,CAACC,OAAiB,EAAE;IAC7B,IAAI,CAACC,qBAAqB,GAAGD,OAAO,EAAEC,qBAAqB,KAAK,MAAMC,SAAS,CAAC;IAChF,IAAI,CAACC,OAAO,GAAGH,OAAO,EAAEG,OAAO,IAAIN,IAAI;EACzC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { ProductAnalyticsConfig } from '../types/product_analytics';
|
|
3
|
+
import { Session } from './session';
|
|
4
|
+
export interface StoredProductAnalyticsConfig extends ProductAnalyticsConfig {
|
|
5
|
+
expiresAt: number;
|
|
6
|
+
personId: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const TOKEN_EXPIRY_TIME: number;
|
|
9
|
+
export declare const productAnalyticsStorageKey: (session: Session) => string;
|
|
10
|
+
export declare const productAnalyticsQueryKey: (session: Session) => string[];
|
|
11
|
+
export declare function fetchProductAnalyticsConfig(queryClient: QueryClient, session: Session): Promise<StoredProductAnalyticsConfig>;
|
|
12
|
+
//# sourceMappingURL=product_analytics_token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product_analytics_token.d.ts","sourceRoot":"","sources":["../../src/utils/product_analytics_token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAGnE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAWnC,MAAM,WAAW,4BAA6B,SAAQ,sBAAsB;IAC1E,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,eAAO,MAAM,iBAAiB,QAAwB,CAAA;AAKtD,eAAO,MAAM,0BAA0B,GAAI,SAAS,OAAO,WACjB,CAAA;AAE1C,eAAO,MAAM,wBAAwB,GAAI,SAAS,OAAO,aAIxD,CAAA;AAyED,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,4BAA4B,CAAC,CASvC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { currentPersonQueryKey } from '../hooks/use_current_person';
|
|
2
|
+
import { Client } from './client';
|
|
3
|
+
import { Storage } from './native_adapters';
|
|
4
|
+
import { ONE_HOUR, toMs } from './time';
|
|
5
|
+
import { Uri } from './uri';
|
|
6
|
+
export const TOKEN_EXPIRY_TIME = toMs(7 * 24, 'hours');
|
|
7
|
+
const EXPIRY_MARGIN = ONE_HOUR;
|
|
8
|
+
|
|
9
|
+
// One slot per environment, tagged with the person it belongs to. Keying on
|
|
10
|
+
// session.id would miss on every access-token refresh and leave orphaned entries.
|
|
11
|
+
export const productAnalyticsStorageKey = session => `product-analytics-token:${session.env}`;
|
|
12
|
+
export const productAnalyticsQueryKey = session => ['product-analytics-token', session.env, session.id];
|
|
13
|
+
const renewalTime = config => config.expiresAt - EXPIRY_MARGIN;
|
|
14
|
+
const isStoredConfig = value => typeof value === 'object' && value !== null && typeof value.token === 'string' && typeof value.endpoint === 'string' && typeof value.expiresAt === 'number' && typeof value.personId === 'string';
|
|
15
|
+
async function readStoredConfig(key) {
|
|
16
|
+
try {
|
|
17
|
+
const raw = await Storage.getItem(key);
|
|
18
|
+
if (!raw) return undefined;
|
|
19
|
+
const parsed = JSON.parse(raw);
|
|
20
|
+
return isStoredConfig(parsed) ? parsed : undefined;
|
|
21
|
+
} catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function writeStoredConfig(key, config) {
|
|
26
|
+
return Storage.setItem(key, JSON.stringify(config)).catch(() => {});
|
|
27
|
+
}
|
|
28
|
+
function requestConfig(session, personId) {
|
|
29
|
+
const uri = new Uri({
|
|
30
|
+
session
|
|
31
|
+
});
|
|
32
|
+
const client = new Client({
|
|
33
|
+
root: uri.api('/chat/v2'),
|
|
34
|
+
defaultHeaders: uri.headers,
|
|
35
|
+
version: '2018-11-01'
|
|
36
|
+
});
|
|
37
|
+
return client.post({
|
|
38
|
+
url: '/me/product_analytics_authorize',
|
|
39
|
+
data: {
|
|
40
|
+
data: {
|
|
41
|
+
type: 'ProductAnalyticsToken',
|
|
42
|
+
attributes: {}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}).then(res => ({
|
|
46
|
+
token: res.data.id,
|
|
47
|
+
endpoint: res.data.url,
|
|
48
|
+
metadata: res.data.metadata,
|
|
49
|
+
expiresAt: Date.now() + TOKEN_EXPIRY_TIME,
|
|
50
|
+
personId
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The chat screens that publish events already load /me, and the package's query
|
|
55
|
+
// client is cleared whenever the access token changes, so this is normally a cache hit.
|
|
56
|
+
async function currentPersonId(queryClient) {
|
|
57
|
+
const {
|
|
58
|
+
data
|
|
59
|
+
} = await queryClient.ensureQueryData({
|
|
60
|
+
queryKey: currentPersonQueryKey
|
|
61
|
+
});
|
|
62
|
+
return String(data.id);
|
|
63
|
+
}
|
|
64
|
+
async function loadConfig(queryClient, session) {
|
|
65
|
+
const personId = await currentPersonId(queryClient);
|
|
66
|
+
const key = productAnalyticsStorageKey(session);
|
|
67
|
+
const stored = await readStoredConfig(key);
|
|
68
|
+
if (stored && stored.personId === personId && renewalTime(stored) > Date.now()) return stored;
|
|
69
|
+
const config = await requestConfig(session, personId);
|
|
70
|
+
await writeStoredConfig(key, config);
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
export function fetchProductAnalyticsConfig(queryClient, session) {
|
|
74
|
+
return queryClient.fetchQuery({
|
|
75
|
+
queryKey: productAnalyticsQueryKey(session),
|
|
76
|
+
queryFn: () => loadConfig(queryClient, session),
|
|
77
|
+
staleTime: ({
|
|
78
|
+
state
|
|
79
|
+
}) => state.data ? Math.max(0, renewalTime(state.data) - state.dataUpdatedAt) : 0,
|
|
80
|
+
gcTime: TOKEN_EXPIRY_TIME,
|
|
81
|
+
retry: false
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=product_analytics_token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product_analytics_token.js","names":["currentPersonQueryKey","Client","Storage","ONE_HOUR","toMs","Uri","TOKEN_EXPIRY_TIME","EXPIRY_MARGIN","productAnalyticsStorageKey","session","env","productAnalyticsQueryKey","id","renewalTime","config","expiresAt","isStoredConfig","value","token","endpoint","personId","readStoredConfig","key","raw","getItem","undefined","parsed","JSON","parse","writeStoredConfig","setItem","stringify","catch","requestConfig","uri","client","root","api","defaultHeaders","headers","version","post","url","data","type","attributes","then","res","metadata","Date","now","currentPersonId","queryClient","ensureQueryData","queryKey","String","loadConfig","stored","fetchProductAnalyticsConfig","fetchQuery","queryFn","staleTime","state","Math","max","dataUpdatedAt","gcTime","retry"],"sources":["../../src/utils/product_analytics_token.ts"],"sourcesContent":["import { QueryClient } from '@tanstack/react-query'\nimport { currentPersonQueryKey } from '../hooks/use_current_person'\nimport { ApiResource, CurrentPersonResource } from '../types'\nimport { ProductAnalyticsConfig } from '../types/product_analytics'\nimport { Client } from './client'\nimport { Storage } from './native_adapters'\nimport { Session } from './session'\nimport { ONE_HOUR, toMs } from './time'\nimport { Uri } from './uri'\n\ninterface ProductAnalyticsTokenResponse {\n type: 'ProductAnalyticsToken'\n id: string\n url: string\n metadata: Record<string, unknown>\n}\n\nexport interface StoredProductAnalyticsConfig extends ProductAnalyticsConfig {\n expiresAt: number\n personId: string\n}\n\nexport const TOKEN_EXPIRY_TIME = toMs(7 * 24, 'hours')\nconst EXPIRY_MARGIN = ONE_HOUR\n\n// One slot per environment, tagged with the person it belongs to. Keying on\n// session.id would miss on every access-token refresh and leave orphaned entries.\nexport const productAnalyticsStorageKey = (session: Session) =>\n `product-analytics-token:${session.env}`\n\nexport const productAnalyticsQueryKey = (session: Session) => [\n 'product-analytics-token',\n session.env,\n session.id,\n]\n\nconst renewalTime = (config: StoredProductAnalyticsConfig) => config.expiresAt - EXPIRY_MARGIN\n\nconst isStoredConfig = (value: unknown): value is StoredProductAnalyticsConfig =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as StoredProductAnalyticsConfig).token === 'string' &&\n typeof (value as StoredProductAnalyticsConfig).endpoint === 'string' &&\n typeof (value as StoredProductAnalyticsConfig).expiresAt === 'number' &&\n typeof (value as StoredProductAnalyticsConfig).personId === 'string'\n\nasync function readStoredConfig(key: string): Promise<StoredProductAnalyticsConfig | undefined> {\n try {\n const raw = await Storage.getItem(key)\n if (!raw) return undefined\n\n const parsed: unknown = JSON.parse(raw)\n return isStoredConfig(parsed) ? parsed : undefined\n } catch {\n return undefined\n }\n}\n\nfunction writeStoredConfig(key: string, config: StoredProductAnalyticsConfig): Promise<void> {\n return Storage.setItem(key, JSON.stringify(config)).catch(() => {})\n}\n\nfunction requestConfig(session: Session, personId: string): Promise<StoredProductAnalyticsConfig> {\n const uri = new Uri({ session })\n const client = new Client({\n root: uri.api('/chat/v2'),\n defaultHeaders: uri.headers,\n version: '2018-11-01',\n })\n\n return client\n .post<ApiResource<ProductAnalyticsTokenResponse>>({\n url: '/me/product_analytics_authorize',\n data: { data: { type: 'ProductAnalyticsToken', attributes: {} } },\n })\n .then(res => ({\n token: res.data.id,\n endpoint: res.data.url,\n metadata: res.data.metadata,\n expiresAt: Date.now() + TOKEN_EXPIRY_TIME,\n personId,\n }))\n}\n\n// The chat screens that publish events already load /me, and the package's query\n// client is cleared whenever the access token changes, so this is normally a cache hit.\nasync function currentPersonId(queryClient: QueryClient): Promise<string> {\n const { data } = await queryClient.ensureQueryData<ApiResource<CurrentPersonResource>>({\n queryKey: currentPersonQueryKey,\n })\n return String(data.id)\n}\n\nasync function loadConfig(\n queryClient: QueryClient,\n session: Session\n): Promise<StoredProductAnalyticsConfig> {\n const personId = await currentPersonId(queryClient)\n const key = productAnalyticsStorageKey(session)\n const stored = await readStoredConfig(key)\n if (stored && stored.personId === personId && renewalTime(stored) > Date.now()) return stored\n\n const config = await requestConfig(session, personId)\n await writeStoredConfig(key, config)\n return config\n}\n\nexport function fetchProductAnalyticsConfig(\n queryClient: QueryClient,\n session: Session\n): Promise<StoredProductAnalyticsConfig> {\n return queryClient.fetchQuery({\n queryKey: productAnalyticsQueryKey(session),\n queryFn: () => loadConfig(queryClient, session),\n staleTime: ({ state }) =>\n state.data ? Math.max(0, renewalTime(state.data) - state.dataUpdatedAt) : 0,\n gcTime: TOKEN_EXPIRY_TIME,\n retry: false,\n })\n}\n"],"mappings":"AACA,SAASA,qBAA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OAAgB,EACuB;EACvC,MAAMW,QAAQ,GAAG,MAAM+B,eAAe,CAACC,WAAW,CAAC;EACnD,MAAM9B,GAAG,GAAGd,0BAA0B,CAACC,OAAO,CAAC;EAC/C,MAAMgD,MAAM,GAAG,MAAMpC,gBAAgB,CAACC,GAAG,CAAC;EAC1C,IAAImC,MAAM,IAAIA,MAAM,CAACrC,QAAQ,KAAKA,QAAQ,IAAIP,WAAW,CAAC4C,MAAM,CAAC,GAAGR,IAAI,CAACC,GAAG,CAAC,CAAC,EAAE,OAAOO,MAAM;EAE7F,MAAM3C,MAAM,GAAG,MAAMmB,aAAa,CAACxB,OAAO,EAAEW,QAAQ,CAAC;EACrD,MAAMS,iBAAiB,CAACP,GAAG,EAAER,MAAM,CAAC;EACpC,OAAOA,MAAM;AACf;AAEA,OAAO,SAAS4C,2BAA2BA,CACzCN,WAAwB,EACxB3C,OAAgB,EACuB;EACvC,OAAO2C,WAAW,CAACO,UAAU,CAAC;IAC5BL,QAAQ,EAAE3C,wBAAwB,CAACF,OAAO,CAAC;IAC3CmD,OAAO,EAAEA,CAAA,KAAMJ,UAAU,CAACJ,WAAW,EAAE3C,OAAO,CAAC;IAC/CoD,SAAS,EAAEA,CAAC;MAAEC;IAAM,CAAC,KACnBA,KAAK,CAACnB,IAAI,GAAGoB,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEnD,WAAW,CAACiD,KAAK,CAACnB,IAAI,CAAC,GAAGmB,KAAK,CAACG,aAAa,CAAC,GAAG,CAAC;IAC7EC,MAAM,EAAE5D,iBAAiB;IACzB6D,KAAK,EAAE;EACT,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { QueryClient, QueryKey } from '@tanstack/react-query';
|
|
2
|
+
export declare const REFRESH_THROTTLE_MS = 3000;
|
|
3
|
+
type Refresh = () => unknown;
|
|
4
|
+
export declare const throttledRefresh: (queryClient: QueryClient, key: QueryKey, event: object, refresh: Refresh) => void;
|
|
5
|
+
export declare const cancelThrottledRefreshes: (queryClient: QueryClient) => void;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=throttled_refresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttled_refresh.d.ts","sourceRoot":"","sources":["../../src/utils/throttled_refresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAGtE,eAAO,MAAM,mBAAmB,OAAO,CAAA;AAEvC,KAAK,OAAO,GAAG,MAAM,OAAO,CAAA;AAqC5B,eAAO,MAAM,gBAAgB,GAC3B,aAAa,WAAW,EACxB,KAAK,QAAQ,EACb,OAAO,MAAM,EACb,SAAS,OAAO,SAOjB,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI,aAAa,WAAW,SAMhE,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { hashKey } from '@tanstack/react-query';
|
|
2
|
+
import { throttle } from 'lodash';
|
|
3
|
+
export const REFRESH_THROTTLE_MS = 3000;
|
|
4
|
+
const refreshesByClient = new WeakMap();
|
|
5
|
+
const refreshesFor = queryClient => {
|
|
6
|
+
const existing = refreshesByClient.get(queryClient);
|
|
7
|
+
if (existing) return existing;
|
|
8
|
+
const refreshes = new Map();
|
|
9
|
+
refreshesByClient.set(queryClient, refreshes);
|
|
10
|
+
return refreshes;
|
|
11
|
+
};
|
|
12
|
+
const throttledRefreshFor = (queryClient, key) => {
|
|
13
|
+
const refreshes = refreshesFor(queryClient);
|
|
14
|
+
const hashedKey = hashKey(key);
|
|
15
|
+
const existing = refreshes.get(hashedKey);
|
|
16
|
+
if (existing) return existing;
|
|
17
|
+
const created = {
|
|
18
|
+
run: throttle(refresh => {
|
|
19
|
+
refresh();
|
|
20
|
+
}, REFRESH_THROTTLE_MS, {
|
|
21
|
+
leading: true,
|
|
22
|
+
trailing: true
|
|
23
|
+
})
|
|
24
|
+
};
|
|
25
|
+
refreshes.set(hashedKey, created);
|
|
26
|
+
return created;
|
|
27
|
+
};
|
|
28
|
+
export const throttledRefresh = (queryClient, key, event, refresh) => {
|
|
29
|
+
const throttled = throttledRefreshFor(queryClient, key);
|
|
30
|
+
if (throttled.lastEvent === event) return;
|
|
31
|
+
throttled.lastEvent = event;
|
|
32
|
+
throttled.run(refresh);
|
|
33
|
+
};
|
|
34
|
+
export const cancelThrottledRefreshes = queryClient => {
|
|
35
|
+
const refreshes = refreshesByClient.get(queryClient);
|
|
36
|
+
if (!refreshes) return;
|
|
37
|
+
refreshes.forEach(({
|
|
38
|
+
run
|
|
39
|
+
}) => run.cancel());
|
|
40
|
+
refreshesByClient.delete(queryClient);
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=throttled_refresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttled_refresh.js","names":["hashKey","throttle","REFRESH_THROTTLE_MS","refreshesByClient","WeakMap","refreshesFor","queryClient","existing","get","refreshes","Map","set","throttledRefreshFor","key","hashedKey","created","run","refresh","leading","trailing","throttledRefresh","event","throttled","lastEvent","cancelThrottledRefreshes","forEach","cancel","delete"],"sources":["../../src/utils/throttled_refresh.ts"],"sourcesContent":["import { hashKey, QueryClient, QueryKey } from '@tanstack/react-query'\nimport { DebouncedFuncLeading, throttle } from 'lodash'\n\nexport const REFRESH_THROTTLE_MS = 3000\n\ntype Refresh = () => unknown\n\ninterface ThrottledRefresh {\n run: DebouncedFuncLeading<(refresh: Refresh) => void>\n lastEvent?: object\n}\n\nconst refreshesByClient = new WeakMap<QueryClient, Map<string, ThrottledRefresh>>()\n\nconst refreshesFor = (queryClient: QueryClient) => {\n const existing = refreshesByClient.get(queryClient)\n if (existing) return existing\n\n const refreshes = new Map<string, ThrottledRefresh>()\n refreshesByClient.set(queryClient, refreshes)\n return refreshes\n}\n\nconst throttledRefreshFor = (queryClient: QueryClient, key: QueryKey) => {\n const refreshes = refreshesFor(queryClient)\n const hashedKey = hashKey(key)\n const existing = refreshes.get(hashedKey)\n if (existing) return existing\n\n const created: ThrottledRefresh = {\n run: throttle(\n (refresh: Refresh) => {\n refresh()\n },\n REFRESH_THROTTLE_MS,\n { leading: true, trailing: true }\n ),\n }\n refreshes.set(hashedKey, created)\n return created\n}\n\nexport const throttledRefresh = (\n queryClient: QueryClient,\n key: QueryKey,\n event: object,\n refresh: Refresh\n) => {\n const throttled = throttledRefreshFor(queryClient, key)\n if (throttled.lastEvent === event) return\n\n throttled.lastEvent = event\n throttled.run(refresh)\n}\n\nexport const cancelThrottledRefreshes = (queryClient: QueryClient) => {\n const refreshes = refreshesByClient.get(queryClient)\n if (!refreshes) return\n\n refreshes.forEach(({ run }) => run.cancel())\n refreshesByClient.delete(queryClient)\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAA+B,uBAAuB;AACtE,SAA+BC,QAAQ,QAAQ,QAAQ;AAEvD,OAAO,MAAMC,mBAAmB,GAAG,IAAI;AASvC,MAAMC,iBAAiB,GAAG,IAAIC,OAAO,CAA6C,CAAC;AAEnF,MAAMC,YAAY,GAAIC,WAAwB,IAAK;EACjD,MAAMC,QAAQ,GAAGJ,iBAAiB,CAACK,GAAG,CAACF,WAAW,CAAC;EACnD,IAAIC,QAAQ,EAAE,OAAOA,QAAQ;EAE7B,MAAME,SAAS,GAAG,IAAIC,GAAG,CAA2B,CAAC;EACrDP,iBAAiB,CAACQ,GAAG,CAACL,WAAW,EAAEG,SAAS,CAAC;EAC7C,OAAOA,SAAS;AAClB,CAAC;AAED,MAAMG,mBAAmB,GAAGA,CAACN,WAAwB,EAAEO,GAAa,KAAK;EACvE,MAAMJ,SAAS,GAAGJ,YAAY,CAACC,WAAW,CAAC;EAC3C,MAAMQ,SAAS,GAAGd,OAAO,CAACa,GAAG,CAAC;EAC9B,MAAMN,QAAQ,GAAGE,SAAS,CAACD,GAAG,CAACM,SAAS,CAAC;EACzC,IAAIP,QAAQ,EAAE,OAAOA,QAAQ;EAE7B,MAAMQ,OAAyB,GAAG;IAChCC,GAAG,EAAEf,QAAQ,CACVgB,OAAgB,IAAK;MACpBA,OAAO,CAAC,CAAC;IACX,CAAC,EACDf,mBAAmB,EACnB;MAAEgB,OAAO,EAAE,IAAI;MAAEC,QAAQ,EAAE;IAAK,CAClC;EACF,CAAC;EACDV,SAAS,CAACE,GAAG,CAACG,SAAS,EAAEC,OAAO,CAAC;EACjC,OAAOA,OAAO;AAChB,CAAC;AAED,OAAO,MAAMK,gBAAgB,GAAGA,CAC9Bd,WAAwB,EACxBO,GAAa,EACbQ,KAAa,EACbJ,OAAgB,KACb;EACH,MAAMK,SAAS,GAAGV,mBAAmB,CAACN,WAAW,EAAEO,GAAG,CAAC;EACvD,IAAIS,SAAS,CAACC,SAAS,KAAKF,KAAK,EAAE;EAEnCC,SAAS,CAACC,SAAS,GAAGF,KAAK;EAC3BC,SAAS,CAACN,GAAG,CAACC,OAAO,CAAC;AACxB,CAAC;AAED,OAAO,MAAMO,wBAAwB,GAAIlB,WAAwB,IAAK;EACpE,MAAMG,SAAS,GAAGN,iBAAiB,CAACK,GAAG,CAACF,WAAW,CAAC;EACpD,IAAI,CAACG,SAAS,EAAE;EAEhBA,SAAS,CAACgB,OAAO,CAAC,CAAC;IAAET;EAAI,CAAC,KAAKA,GAAG,CAACU,MAAM,CAAC,CAAC,CAAC;EAC5CvB,iBAAiB,CAACwB,MAAM,CAACrB,WAAW,CAAC;AACvC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "4.8.0-rc.
|
|
3
|
+
"version": "4.8.0-rc.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"sf-symbols-typescript": "^2.2.0",
|
|
85
85
|
"typescript": "~6.0.3"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "df8a720a12b8fe7b3b69d3304c38cab8af607fe8"
|
|
88
88
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
-
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
3
3
|
import { renderHook, act } from '@testing-library/react-native'
|
|
4
4
|
import React, { useContext, Suspense } from 'react'
|
|
5
5
|
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
6
|
+
import { chatQueryClient } from '../../contexts/api_provider'
|
|
6
7
|
import {
|
|
7
8
|
SessionContext,
|
|
8
9
|
SessionContextProvider,
|
|
@@ -85,6 +86,7 @@ beforeEach(() => {
|
|
|
85
86
|
mockSecureStorage = createMockStorage()
|
|
86
87
|
mockRefreshTokenFn = jest.fn()
|
|
87
88
|
mockOnLogout = jest.fn()
|
|
89
|
+
jest.mocked(chatQueryClient.clear).mockClear()
|
|
88
90
|
// Reset AsyncStorage mocks with a storage implementation
|
|
89
91
|
const asyncStorageData: Record<string, string> = {}
|
|
90
92
|
mockAsyncStorage.getItem.mockImplementation(async (key: string) => {
|
|
@@ -131,20 +133,6 @@ describe('SessionContextProvider', () => {
|
|
|
131
133
|
expect(result.current.env).toBe('production')
|
|
132
134
|
expect(result.current.token).toBeUndefined()
|
|
133
135
|
})
|
|
134
|
-
|
|
135
|
-
it('should use custom default environment', async () => {
|
|
136
|
-
// Note: defaultEnv is not currently used in the implementation
|
|
137
|
-
// This test verifies the current behavior (defaults to 'production')
|
|
138
|
-
const config = createConfig({ defaultEnv: 'staging' })
|
|
139
|
-
const { result } = renderHook(() => useSessionContext(), {
|
|
140
|
-
wrapper: createWrapper(config),
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
await waitForQuery()
|
|
144
|
-
|
|
145
|
-
// Currently defaults to 'production' regardless of defaultEnv config
|
|
146
|
-
expect(result.current.env).toBe('production')
|
|
147
|
-
})
|
|
148
136
|
})
|
|
149
137
|
|
|
150
138
|
describe('logout', () => {
|
|
@@ -182,23 +170,24 @@ describe('SessionContextProvider', () => {
|
|
|
182
170
|
await waitForQuery() // Extra wait for async operations
|
|
183
171
|
|
|
184
172
|
expect(mockOnLogout).toHaveBeenCalledTimes(1)
|
|
173
|
+
const storedValue = await mockSecureStorage.getItem(TEST_SESSIONS_KEY)
|
|
174
|
+
expect(SessionManager.hydrate(JSON.parse(storedValue!)).sessions).toEqual({})
|
|
185
175
|
})
|
|
186
176
|
|
|
187
|
-
it('should clear query clients
|
|
188
|
-
const
|
|
177
|
+
it('should clear the chat and host query clients', async () => {
|
|
178
|
+
const hostClear = jest.spyOn(QueryClient.prototype, 'clear')
|
|
189
179
|
const { result } = renderHook(() => useSessionContext(), {
|
|
190
|
-
wrapper: createWrapper(
|
|
180
|
+
wrapper: createWrapper(createConfig()),
|
|
191
181
|
})
|
|
192
182
|
|
|
193
183
|
await waitForQuery()
|
|
194
184
|
|
|
195
|
-
// Note: We can't spy on the queryClient since it's created inside createWrapper
|
|
196
|
-
// But we can verify logout was called
|
|
197
185
|
await act(async () => {
|
|
198
186
|
await result.current.logout()
|
|
199
187
|
})
|
|
200
188
|
|
|
201
|
-
expect(
|
|
189
|
+
expect(chatQueryClient.clear).toHaveBeenCalledTimes(1)
|
|
190
|
+
expect(hostClear).toHaveBeenCalledTimes(1)
|
|
202
191
|
})
|
|
203
192
|
})
|
|
204
193
|
|
|
@@ -256,7 +245,7 @@ describe('SessionContextProvider', () => {
|
|
|
256
245
|
})
|
|
257
246
|
})
|
|
258
247
|
|
|
259
|
-
it('should
|
|
248
|
+
it('should start only one refresh while one is already running', async () => {
|
|
260
249
|
const token: OAuthToken = {
|
|
261
250
|
access_token: 'old-token-12345678',
|
|
262
251
|
refresh_token: 'refresh-token',
|
|
@@ -266,22 +255,13 @@ describe('SessionContextProvider', () => {
|
|
|
266
255
|
created_at: Date.now(),
|
|
267
256
|
}
|
|
268
257
|
|
|
269
|
-
const newToken: OAuthToken = {
|
|
270
|
-
access_token: 'new-token-87654321',
|
|
271
|
-
refresh_token: 'new-refresh-token',
|
|
272
|
-
expires_in: 3600,
|
|
273
|
-
token_type: 'Bearer',
|
|
274
|
-
scope: 'read write',
|
|
275
|
-
created_at: Date.now(),
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
mockRefreshTokenFn.mockResolvedValue(newToken)
|
|
279
|
-
|
|
280
258
|
const session = new Session({ env: 'production', token })
|
|
281
259
|
const manager = new SessionManager()
|
|
282
260
|
manager.upsertSession(session)
|
|
283
261
|
await mockSecureStorage.setItem(TEST_SESSIONS_KEY, JSON.stringify(manager.toString()))
|
|
284
262
|
|
|
263
|
+
mockRefreshTokenFn.mockReturnValue(new Promise(() => {}))
|
|
264
|
+
|
|
285
265
|
const config = createConfig()
|
|
286
266
|
const { result } = renderHook(() => useSessionContext(), {
|
|
287
267
|
wrapper: createWrapper(config),
|
|
@@ -289,23 +269,23 @@ describe('SessionContextProvider', () => {
|
|
|
289
269
|
|
|
290
270
|
await waitForQuery()
|
|
291
271
|
|
|
292
|
-
expect(result.current.token).toBeDefined()
|
|
293
|
-
|
|
294
272
|
const failedResponse: FailedResponse = {
|
|
295
273
|
status: 401,
|
|
296
274
|
statusText: 'Unauthorized',
|
|
297
275
|
errors: [{ detail: 'other-error', title: 'Unauthorized', status: '401' }],
|
|
298
276
|
} as FailedResponse
|
|
299
277
|
|
|
300
|
-
// Call handleUnauthorizedResponse - should trigger refresh
|
|
301
278
|
await act(async () => {
|
|
302
279
|
result.current.handleUnauthorizedResponse(failedResponse)
|
|
280
|
+
await jest.runOnlyPendingTimersAsync()
|
|
303
281
|
})
|
|
304
282
|
|
|
305
|
-
await
|
|
283
|
+
await act(async () => {
|
|
284
|
+
result.current.handleUnauthorizedResponse(failedResponse)
|
|
285
|
+
await jest.runOnlyPendingTimersAsync()
|
|
286
|
+
})
|
|
306
287
|
|
|
307
|
-
|
|
308
|
-
expect(mockRefreshTokenFn).toHaveBeenCalled()
|
|
288
|
+
expect(mockRefreshTokenFn).toHaveBeenCalledTimes(1)
|
|
309
289
|
})
|
|
310
290
|
|
|
311
291
|
it('should logout on forced logout error (capuchin)', async () => {
|
|
@@ -55,13 +55,6 @@ const Wrapper = ({ children }: { children: React.ReactNode }) => {
|
|
|
55
55
|
)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
test('should use theme', () => {
|
|
59
|
-
themeProps = {}
|
|
60
|
-
const { result } = renderHook(() => useTheme(), { wrapper: Wrapper })
|
|
61
|
-
|
|
62
|
-
expect(result.current).toBeDefined()
|
|
63
|
-
})
|
|
64
|
-
|
|
65
58
|
describe('configurable theme', () => {
|
|
66
59
|
test('should not error is theme is undefined', () => {
|
|
67
60
|
//@ts-expect-error
|
|
@@ -71,6 +71,7 @@ describe('useAsyncStorage', () => {
|
|
|
71
71
|
|
|
72
72
|
expect(result.current).toBeDefined()
|
|
73
73
|
expect(result.current[0]).toEqual(storedValue)
|
|
74
|
+
expect(mockAsyncStorage.getItem).toHaveBeenCalledWith('test-key')
|
|
74
75
|
})
|
|
75
76
|
|
|
76
77
|
it('returns raw string value when JSON parsing fails', async () => {
|
|
@@ -99,22 +100,6 @@ describe('useAsyncStorage', () => {
|
|
|
99
100
|
expect(result.current).toBeDefined()
|
|
100
101
|
expect(result.current[0]).toBe('initial-value')
|
|
101
102
|
})
|
|
102
|
-
|
|
103
|
-
it('returns initial value when getItem throws quota exceeded error', async () => {
|
|
104
|
-
const quotaError = new Error('database or disk is full (code 13): SQLITE_FULL')
|
|
105
|
-
mockAsyncStorage.getItem.mockRejectedValue(quotaError)
|
|
106
|
-
|
|
107
|
-
const { result } = renderHook(() => useAsyncStorage('test-key', 'initial-value'), {
|
|
108
|
-
wrapper: createWrapper(),
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
await act(async () => {
|
|
112
|
-
await waitForQuery()
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
expect(result.current).toBeDefined()
|
|
116
|
-
expect(result.current[0]).toBe('initial-value')
|
|
117
|
-
})
|
|
118
103
|
})
|
|
119
104
|
|
|
120
105
|
describe('setValue', () => {
|
|
@@ -136,23 +121,6 @@ describe('useAsyncStorage', () => {
|
|
|
136
121
|
expect(mockAsyncStorage.setItem).toHaveBeenCalledWith('test-key', JSON.stringify(newValue))
|
|
137
122
|
})
|
|
138
123
|
|
|
139
|
-
it('saves object value to storage', async () => {
|
|
140
|
-
const { result } = renderHook(() => useAsyncStorage('test-key', { initial: 'value' }), {
|
|
141
|
-
wrapper: createWrapper(),
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
await waitForQuery()
|
|
145
|
-
|
|
146
|
-
expect(result.current).toBeDefined()
|
|
147
|
-
|
|
148
|
-
const newValue = { initial: 'new-value', data: 'test' }
|
|
149
|
-
await act(async () => {
|
|
150
|
-
await result.current[1](newValue)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
expect(mockAsyncStorage.setItem).toHaveBeenCalledWith('test-key', JSON.stringify(newValue))
|
|
154
|
-
})
|
|
155
|
-
|
|
156
124
|
it('removes item when value is null', async () => {
|
|
157
125
|
mockAsyncStorage.getItem.mockResolvedValue(JSON.stringify({ data: 'existing' }))
|
|
158
126
|
|
|
@@ -230,27 +198,6 @@ describe('useAsyncStorage', () => {
|
|
|
230
198
|
})
|
|
231
199
|
})
|
|
232
200
|
|
|
233
|
-
it('does not throw error when setItem throws other errors by default', async () => {
|
|
234
|
-
const error = new Error('Storage write failed')
|
|
235
|
-
mockAsyncStorage.setItem.mockRejectedValue(error)
|
|
236
|
-
|
|
237
|
-
const { result } = renderHook(() => useAsyncStorage('test-key', 'initial'), {
|
|
238
|
-
wrapper: createWrapper(),
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
await waitForQuery()
|
|
242
|
-
|
|
243
|
-
expect(result.current).toBeDefined()
|
|
244
|
-
expect(result.current[0]).toBe('initial')
|
|
245
|
-
|
|
246
|
-
// Should not throw - errors are caught by default
|
|
247
|
-
let promiseResult: void | undefined
|
|
248
|
-
await act(async () => {
|
|
249
|
-
promiseResult = await result.current[1]('new-value')
|
|
250
|
-
})
|
|
251
|
-
expect(promiseResult).toBeUndefined()
|
|
252
|
-
})
|
|
253
|
-
|
|
254
201
|
it('does not throw error when removeItem throws an error by default', async () => {
|
|
255
202
|
const error = new Error('Remove failed')
|
|
256
203
|
mockAsyncStorage.removeItem.mockRejectedValue(error)
|
|
@@ -272,37 +219,4 @@ describe('useAsyncStorage', () => {
|
|
|
272
219
|
expect(promiseResult).toBeUndefined()
|
|
273
220
|
})
|
|
274
221
|
})
|
|
275
|
-
|
|
276
|
-
describe('edge cases', () => {
|
|
277
|
-
it('handles complex nested objects', async () => {
|
|
278
|
-
const complexValue = {
|
|
279
|
-
nested: {
|
|
280
|
-
array: [1, 2, { deep: 'value' }],
|
|
281
|
-
date: '2024-01-01',
|
|
282
|
-
},
|
|
283
|
-
}
|
|
284
|
-
mockAsyncStorage.getItem.mockResolvedValue(JSON.stringify(complexValue))
|
|
285
|
-
|
|
286
|
-
const { result } = renderHook(() => useAsyncStorage('test-key', {}), {
|
|
287
|
-
wrapper: createWrapper(),
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
await waitForQuery()
|
|
291
|
-
|
|
292
|
-
expect(result.current).toBeDefined()
|
|
293
|
-
expect(result.current[0]).toEqual(complexValue)
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
it('uses correct cache key format', async () => {
|
|
297
|
-
const { result } = renderHook(() => useAsyncStorage('my-unique-key', 'value'), {
|
|
298
|
-
wrapper: createWrapper(),
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
await waitForQuery()
|
|
302
|
-
|
|
303
|
-
expect(result.current).toBeDefined()
|
|
304
|
-
expect(result.current[0]).toBe('value')
|
|
305
|
-
expect(mockAsyncStorage.getItem).toHaveBeenCalledWith('my-unique-key')
|
|
306
|
-
})
|
|
307
|
-
})
|
|
308
222
|
})
|
|
@@ -126,17 +126,6 @@ describe('useAttachmentUploader', () => {
|
|
|
126
126
|
expect(result.current.attachments).toHaveLength(0)
|
|
127
127
|
})
|
|
128
128
|
|
|
129
|
-
it('formats an integer MB limit without a trailing decimal', () => {
|
|
130
|
-
setChatConfiguration({ maxFileSizeInBytes: 25 * 1024 * 1024 })
|
|
131
|
-
const { result } = renderUploader()
|
|
132
|
-
|
|
133
|
-
act(() => {
|
|
134
|
-
result.current.handleFilesAttached([makeFile({ size: 25 * 1024 * 1024 + 1 })])
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
expect(result.current.errorMessage).toBe('File size exceeds 25 MB')
|
|
138
|
-
})
|
|
139
|
-
|
|
140
129
|
it('formats a fractional MB limit to one decimal', () => {
|
|
141
130
|
// 50.5 MB — server could in principle return a non-multiple-of-MB cap.
|
|
142
131
|
setChatConfiguration({ maxFileSizeInBytes: Math.round(50.5 * 1024 * 1024) })
|