@planningcenter/chat-react-native 4.8.0-rc.1 → 4.8.0-rc.11
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/app_update_banner.d.ts +2 -0
- package/build/components/conversations/app_update_banner.d.ts.map +1 -0
- package/build/components/conversations/app_update_banner.js +52 -0
- package/build/components/conversations/app_update_banner.js.map +1 -0
- 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/components/primitive/banner_primitive.js +7 -3
- package/build/components/primitive/banner_primitive.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 +176 -33
- 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/theme.js +20 -21
- package/build/utils/theme.js.map +1 -1
- 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__/app_update_banner.test.tsx +27 -0
- 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/app_update_banner.tsx +36 -0
- 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/components/primitive/banner_primitive.tsx +5 -1
- 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 +37 -12
- 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 +76 -4
- 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/theme.ts +20 -21
- 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
|
@@ -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,qBAAqB,QAAQ,6BAA6B;AAGnE,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,OAAO,QAAQ,mBAAmB;AAE3C,SAASC,QAAQ,EAAEC,IAAI,QAAQ,QAAQ;AACvC,SAASC,GAAG,QAAQ,OAAO;AAc3B,OAAO,MAAMC,iBAAiB,GAAGF,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC;AACtD,MAAMG,aAAa,GAAGJ,QAAQ;;AAE9B;AACA;AACA,OAAO,MAAMK,0BAA0B,GAAIC,OAAgB,IACzD,2BAA2BA,OAAO,CAACC,GAAG,EAAE;AAE1C,OAAO,MAAMC,wBAAwB,GAAIF,OAAgB,IAAK,CAC5D,yBAAyB,EACzBA,OAAO,CAACC,GAAG,EACXD,OAAO,CAACG,EAAE,CACX;AAED,MAAMC,WAAW,GAAIC,MAAoC,IAAKA,MAAM,CAACC,SAAS,GAAGR,aAAa;AAE9F,MAAMS,cAAc,GAAIC,KAAc,IACpC,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAQA,KAAK,CAAkCC,KAAK,KAAK,QAAQ,IACjE,OAAQD,KAAK,CAAkCE,QAAQ,KAAK,QAAQ,IACpE,OAAQF,KAAK,CAAkCF,SAAS,KAAK,QAAQ,IACrE,OAAQE,KAAK,CAAkCG,QAAQ,KAAK,QAAQ;AAEtE,eAAeC,gBAAgBA,CAACC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I,CAAC,GAAGmB,KAAK,CAACG,aAAa,CAAC,GAAG,CAAC;IAC7EC,MAAM,EAAE5D,iBAAiB;IACzB6D,KAAK,EAAE;EACT,CAAC,CAAC;AACJ","ignoreList":[]}
|
package/build/utils/theme.js
CHANGED
|
@@ -63,20 +63,20 @@ const colorsChatLight = {
|
|
|
63
63
|
statusErrorText: tokens.textColorStatusError,
|
|
64
64
|
statusErrorBorder: tokens.borderColorStatusError,
|
|
65
65
|
statusErrorFill: tokens.fillColorStatusErrorSolid,
|
|
66
|
-
statusInfoComposedIcon: tokens.
|
|
67
|
-
statusInfoComposedText: tokens.
|
|
66
|
+
statusInfoComposedIcon: tokens.textColorStatusInfo,
|
|
67
|
+
statusInfoComposedText: tokens.colorNeutral24,
|
|
68
68
|
statusInfoComposedBackground: tokens.fillColorStatusInfoGhost,
|
|
69
|
-
statusSuccessComposedIcon: tokens.
|
|
70
|
-
statusSuccessComposedText: tokens.
|
|
69
|
+
statusSuccessComposedIcon: tokens.textColorStatusSuccess,
|
|
70
|
+
statusSuccessComposedText: tokens.colorNeutral24,
|
|
71
71
|
statusSuccessComposedBackground: tokens.fillColorStatusSuccessGhost,
|
|
72
|
-
statusWarningComposedIcon: tokens.
|
|
73
|
-
statusWarningComposedText: tokens.
|
|
72
|
+
statusWarningComposedIcon: tokens.textColorStatusWarning,
|
|
73
|
+
statusWarningComposedText: tokens.colorNeutral24,
|
|
74
74
|
statusWarningComposedBackground: tokens.fillColorStatusWarningGhost,
|
|
75
|
-
statusErrorComposedIcon: tokens.
|
|
76
|
-
statusErrorComposedText: tokens.
|
|
75
|
+
statusErrorComposedIcon: tokens.textColorStatusError,
|
|
76
|
+
statusErrorComposedText: tokens.colorNeutral24,
|
|
77
77
|
statusErrorComposedBackground: tokens.fillColorStatusErrorGhost,
|
|
78
|
-
statusNeutralComposedIcon: tokens.
|
|
79
|
-
statusNeutralComposedText: tokens.
|
|
78
|
+
statusNeutralComposedIcon: tokens.textColorStatusNeutral,
|
|
79
|
+
statusNeutralComposedText: tokens.colorNeutral24,
|
|
80
80
|
statusNeutralComposedBackground: tokens.fillColorStatusNeutralGhost,
|
|
81
81
|
borderColorChip: tokens.colorNeutral88,
|
|
82
82
|
fillColorChip: 'transparent',
|
|
@@ -108,21 +108,20 @@ const colorsChatDark = {
|
|
|
108
108
|
statusErrorText: tokens.textColorStatusErrorDark,
|
|
109
109
|
statusErrorBorder: tokens.borderColorStatusErrorDark,
|
|
110
110
|
statusErrorFill: tokens.fillColorStatusErrorSolidDark,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
statusInfoComposedText: tokens.textColorStatusInfoDark,
|
|
111
|
+
statusInfoComposedIcon: tokens.textColorStatusInfoDark,
|
|
112
|
+
statusInfoComposedText: tokens.colorNeutral88,
|
|
114
113
|
statusInfoComposedBackground: tokens.fillColorStatusInfoGhostDark,
|
|
115
|
-
statusSuccessComposedIcon: tokens.
|
|
116
|
-
statusSuccessComposedText: tokens.
|
|
114
|
+
statusSuccessComposedIcon: tokens.textColorStatusSuccessDark,
|
|
115
|
+
statusSuccessComposedText: tokens.colorNeutral88,
|
|
117
116
|
statusSuccessComposedBackground: tokens.fillColorStatusSuccessGhostDark,
|
|
118
|
-
statusWarningComposedIcon: tokens.
|
|
119
|
-
statusWarningComposedText: tokens.
|
|
117
|
+
statusWarningComposedIcon: tokens.textColorStatusWarningDark,
|
|
118
|
+
statusWarningComposedText: tokens.colorNeutral88,
|
|
120
119
|
statusWarningComposedBackground: tokens.fillColorStatusWarningGhostDark,
|
|
121
|
-
statusErrorComposedIcon: tokens.
|
|
122
|
-
statusErrorComposedText: tokens.
|
|
120
|
+
statusErrorComposedIcon: tokens.textColorStatusErrorDark,
|
|
121
|
+
statusErrorComposedText: tokens.colorNeutral88,
|
|
123
122
|
statusErrorComposedBackground: tokens.fillColorStatusErrorGhostDark,
|
|
124
|
-
statusNeutralComposedIcon: tokens.
|
|
125
|
-
statusNeutralComposedText: tokens.
|
|
123
|
+
statusNeutralComposedIcon: tokens.textColorStatusNeutralDark,
|
|
124
|
+
statusNeutralComposedText: tokens.colorNeutral88,
|
|
126
125
|
statusNeutralComposedBackground: tokens.fillColorStatusNeutralGhostDark,
|
|
127
126
|
borderColorChip: tokens.colorNeutral24,
|
|
128
127
|
fillColorChip: 'transparent',
|
package/build/utils/theme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","names":["Platform","PlatformColor","aliasTokensColorMap","tokens","defaultTheme","colorScheme","scheme","defaultColors","chatThemeColorMap","colors","button","borderRadius","chip","hslLightnessChipSelected","showBadgeProductLogo","iOSLinkColor","OS","undefined","colorsChatLight","name","androidModalHeaderButtonTextColor","fillColorInteractionDefault","iOSModalHeaderButtonTextColor","buttonStart","buttonEnd","interaction","androidSwitchThumbColor","conversationActionsBackground","colorNeutral100White","testColor","statusInfoIcon","iconColorStatusInfoPrimary","statusInfoText","textColorStatusInfo","statusInfoBorder","borderColorStatusInfo","statusInfoFill","fillColorStatusInfoSolid","statusSuccessIcon","iconColorStatusSuccessPrimary","statusSuccessText","textColorStatusSuccess","statusSuccessBorder","borderColorStatusSuccess","statusSuccessFill","fillColorStatusSuccessSolid","statusWarningIcon","iconColorStatusWarningPrimary","statusWarningText","textColorStatusWarning","statusWarningBorder","borderColorStatusWarning","statusWarningFill","fillColorStatusWarningSolid","statusErrorIcon","iconColorStatusErrorPrimary","statusErrorText","textColorStatusError","statusErrorBorder","borderColorStatusError","statusErrorFill","fillColorStatusErrorSolid","statusInfoComposedIcon","statusInfoComposedText","statusInfoComposedBackground","fillColorStatusInfoGhost","statusSuccessComposedIcon","statusSuccessComposedText","statusSuccessComposedBackground","fillColorStatusSuccessGhost","statusWarningComposedIcon","statusWarningComposedText","statusWarningComposedBackground","fillColorStatusWarningGhost","statusErrorComposedIcon","statusErrorComposedText","statusErrorComposedBackground","fillColorStatusErrorGhost","statusNeutralComposedIcon","iconColorStatusNeutralPrimary","statusNeutralComposedText","textColorStatusNeutral","statusNeutralComposedBackground","fillColorStatusNeutralGhost","borderColorChip","colorNeutral88","fillColorChip","textColorChip","colorNeutral45","colorsChatDark","fillColorInteractionDefaultDark","colorNeutral7","iconColorStatusInfoPrimaryDark","textColorStatusInfoDark","borderColorStatusInfoDark","fillColorStatusInfoSolidDark","iconColorStatusSuccessPrimaryDark","textColorStatusSuccessDark","borderColorStatusSuccessDark","fillColorStatusSuccessSolidDark","iconColorStatusWarningPrimaryDark","textColorStatusWarningDark","borderColorStatusWarningDark","fillColorStatusWarningSolidDark","iconColorStatusErrorPrimaryDark","textColorStatusErrorDark","borderColorStatusErrorDark","fillColorStatusErrorSolidDark","fillColorStatusInfoGhostDark","fillColorStatusSuccessGhostDark","fillColorStatusWarningGhostDark","fillColorStatusErrorGhostDark","iconColorStatusNeutralPrimaryDark","textColorStatusNeutralDark","fillColorStatusNeutralGhostDark","colorNeutral24","colorNeutral68","light","dark"],"sources":["../../src/utils/theme.ts"],"sourcesContent":["import { Platform, PlatformColor } from 'react-native'\nimport type { ColorSchemeName, ColorValue, OpaqueColorValue } from 'react-native'\nimport { aliasTokensColorMap } from '../vendor/tapestry/alias_tokens_color_map'\nimport { tokens } from '../vendor/tapestry/tokens'\n\nexport interface ChatTheme extends DefaultTheme {\n colors: DefaultTheme['colors'] &\n (typeof aliasTokensColorMap.light | typeof aliasTokensColorMap.dark)\n}\n\n/** =============================================\n NOTE: The specific values for `colors` and the `productBadge` are temporary examples that can be replaced once we start building out UI. This line's comment can be removed at that time too.\n\n The default theme is intended to support two types of customizations:\n 1. Specific color properties for a chat component (eg. `primaryButtonBackgroundColor`)\n 2. Any styles for a specific component. (Use only one level of nesting.)\n ```\n primaryButton: {\n borderRadius: number\n container: ViewStyle\n text: TextStyle\n }\n ```\n============================================= */\n\nexport interface DefaultTheme {\n colors: ChatColors\n button: {\n borderRadius: number\n }\n chip: {\n hslLightnessChipSelected: number\n }\n showBadgeProductLogo: boolean\n}\n\nexport const defaultTheme = (colorScheme: ColorSchemeName | null): ChatTheme => {\n const scheme: 'light' | 'dark' = colorScheme === 'dark' ? 'dark' : 'light'\n\n const defaultColors = {\n ...chatThemeColorMap[scheme],\n ...aliasTokensColorMap[scheme],\n }\n\n return {\n colors: defaultColors,\n button: {\n borderRadius: 40,\n },\n chip: {\n hslLightnessChipSelected: scheme === 'dark' ? 12 : 92,\n },\n showBadgeProductLogo: true, // Overrides visibility of the product logo in `src/display/badge.tsx`\n }\n}\n\nexport type TemporaryDefaultColorsType = Partial<ChatColors>\n\ninterface ChatColors {\n name: string\n buttonStart: string | undefined\n buttonEnd: string | undefined\n interaction: string\n androidModalHeaderButtonTextColor: ColorValue | string | undefined\n iOSModalHeaderButtonTextColor: OpaqueColorValue | string | undefined\n androidSwitchThumbColor: string | undefined\n conversationActionsBackground: string\n testColor: string\n statusSuccessIcon: string\n statusSuccessText: string\n statusSuccessBorder: string\n statusSuccessFill: string\n statusInfoIcon: string\n statusInfoText: string\n statusInfoBorder: string\n statusInfoFill: string\n statusWarningIcon: string\n statusWarningText: string\n statusWarningBorder: string\n statusWarningFill: string\n statusErrorIcon: string\n statusErrorText: string\n statusErrorBorder: string\n statusErrorFill: string\n statusSuccessComposedIcon: string\n statusSuccessComposedText: string\n statusSuccessComposedBackground: string\n statusInfoComposedIcon: string\n statusInfoComposedText: string\n statusInfoComposedBackground: string\n statusWarningComposedIcon: string\n statusWarningComposedText: string\n statusWarningComposedBackground: string\n statusErrorComposedIcon: string\n statusErrorComposedText: string\n statusErrorComposedBackground: string\n statusNeutralComposedIcon: string\n statusNeutralComposedText: string\n statusNeutralComposedBackground: string\n borderColorChip: string\n fillColorChip: string\n textColorChip: string\n /**\n * Selected-chip colors (border/fill/text). Never assign a static default\n * directly — these stay optional so they always fall back to\n * `colors.interaction` via `??` at the read site. Every current consumer\n * overrides `interaction` at runtime, and a seeded default here could win\n * over that override depending on merge order.\n */\n borderColorChipSelected?: string\n fillColorChipSelected?: string\n textColorChipSelected?: string\n}\n\n// 'link' is an iOS-only semantic color name — constructing it on Android is\n// undefined behavior, so only build it when the code is actually running on iOS\nconst iOSLinkColor = Platform.OS === 'ios' ? PlatformColor('link') : undefined\n\nconst colorsChatLight: ChatColors = {\n name: 'light',\n androidModalHeaderButtonTextColor: tokens.fillColorInteractionDefault,\n iOSModalHeaderButtonTextColor: iOSLinkColor,\n buttonStart: undefined,\n buttonEnd: undefined,\n interaction: tokens.fillColorInteractionDefault,\n androidSwitchThumbColor: undefined,\n conversationActionsBackground: tokens.colorNeutral100White,\n testColor: 'hotpink',\n statusInfoIcon: tokens.iconColorStatusInfoPrimary,\n statusInfoText: tokens.textColorStatusInfo,\n statusInfoBorder: tokens.borderColorStatusInfo,\n statusInfoFill: tokens.fillColorStatusInfoSolid,\n statusSuccessIcon: tokens.iconColorStatusSuccessPrimary,\n statusSuccessText: tokens.textColorStatusSuccess,\n statusSuccessBorder: tokens.borderColorStatusSuccess,\n statusSuccessFill: tokens.fillColorStatusSuccessSolid,\n statusWarningIcon: tokens.iconColorStatusWarningPrimary,\n statusWarningText: tokens.textColorStatusWarning,\n statusWarningBorder: tokens.borderColorStatusWarning,\n statusWarningFill: tokens.fillColorStatusWarningSolid,\n statusErrorIcon: tokens.iconColorStatusErrorPrimary,\n statusErrorText: tokens.textColorStatusError,\n statusErrorBorder: tokens.borderColorStatusError,\n statusErrorFill: tokens.fillColorStatusErrorSolid,\n statusInfoComposedIcon: tokens.iconColorStatusInfoPrimary,\n statusInfoComposedText: tokens.textColorStatusInfo,\n statusInfoComposedBackground: tokens.fillColorStatusInfoGhost,\n statusSuccessComposedIcon: tokens.iconColorStatusSuccessPrimary,\n statusSuccessComposedText: tokens.textColorStatusSuccess,\n statusSuccessComposedBackground: tokens.fillColorStatusSuccessGhost,\n statusWarningComposedIcon: tokens.iconColorStatusWarningPrimary,\n statusWarningComposedText: tokens.textColorStatusWarning,\n statusWarningComposedBackground: tokens.fillColorStatusWarningGhost,\n statusErrorComposedIcon: tokens.iconColorStatusErrorPrimary,\n statusErrorComposedText: tokens.textColorStatusError,\n statusErrorComposedBackground: tokens.fillColorStatusErrorGhost,\n statusNeutralComposedIcon: tokens.iconColorStatusNeutralPrimary,\n statusNeutralComposedText: tokens.textColorStatusNeutral,\n statusNeutralComposedBackground: tokens.fillColorStatusNeutralGhost,\n borderColorChip: tokens.colorNeutral88,\n fillColorChip: 'transparent',\n textColorChip: tokens.colorNeutral45,\n}\n\nconst colorsChatDark: ChatColors = {\n name: 'dark',\n androidModalHeaderButtonTextColor: tokens.fillColorInteractionDefaultDark,\n iOSModalHeaderButtonTextColor: iOSLinkColor,\n buttonStart: undefined,\n buttonEnd: undefined,\n interaction: tokens.fillColorInteractionDefaultDark,\n androidSwitchThumbColor: undefined,\n conversationActionsBackground: tokens.colorNeutral7,\n testColor: 'pink',\n statusInfoIcon: tokens.iconColorStatusInfoPrimaryDark,\n statusInfoText: tokens.textColorStatusInfoDark,\n statusInfoBorder: tokens.borderColorStatusInfoDark,\n statusInfoFill: tokens.fillColorStatusInfoSolidDark,\n statusSuccessIcon: tokens.iconColorStatusSuccessPrimaryDark,\n statusSuccessText: tokens.textColorStatusSuccessDark,\n statusSuccessBorder: tokens.borderColorStatusSuccessDark,\n statusSuccessFill: tokens.fillColorStatusSuccessSolidDark,\n statusWarningIcon: tokens.iconColorStatusWarningPrimaryDark,\n statusWarningText: tokens.textColorStatusWarningDark,\n statusWarningBorder: tokens.borderColorStatusWarningDark,\n statusWarningFill: tokens.fillColorStatusWarningSolidDark,\n statusErrorIcon: tokens.iconColorStatusErrorPrimaryDark,\n statusErrorText: tokens.textColorStatusErrorDark,\n statusErrorBorder: tokens.borderColorStatusErrorDark,\n statusErrorFill: tokens.fillColorStatusErrorSolidDark,\n\n // Note: CCA inverts composed status colors in dark mode\n statusInfoComposedIcon: tokens.iconColorStatusInfoPrimaryDark,\n statusInfoComposedText: tokens.textColorStatusInfoDark,\n statusInfoComposedBackground: tokens.fillColorStatusInfoGhostDark,\n statusSuccessComposedIcon: tokens.iconColorStatusSuccessPrimaryDark,\n statusSuccessComposedText: tokens.textColorStatusSuccessDark,\n statusSuccessComposedBackground: tokens.fillColorStatusSuccessGhostDark,\n statusWarningComposedIcon: tokens.iconColorStatusWarningPrimaryDark,\n statusWarningComposedText: tokens.textColorStatusWarningDark,\n statusWarningComposedBackground: tokens.fillColorStatusWarningGhostDark,\n statusErrorComposedIcon: tokens.iconColorStatusErrorPrimaryDark,\n statusErrorComposedText: tokens.textColorStatusErrorDark,\n statusErrorComposedBackground: tokens.fillColorStatusErrorGhostDark,\n statusNeutralComposedIcon: tokens.iconColorStatusNeutralPrimaryDark,\n statusNeutralComposedText: tokens.textColorStatusNeutralDark,\n statusNeutralComposedBackground: tokens.fillColorStatusNeutralGhostDark,\n borderColorChip: tokens.colorNeutral24,\n fillColorChip: 'transparent',\n textColorChip: tokens.colorNeutral68,\n}\n\nconst chatThemeColorMap = {\n light: colorsChatLight,\n dark: colorsChatDark,\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,aAAa,QAAQ,cAAc;AAEtD,SAASC,mBAAmB,QAAQ,2CAA2C;AAC/E,SAASC,MAAM,QAAQ,2BAA2B;;AAOlD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,OAAO,MAAMC,YAAY,GAAIC,WAAmC,IAAgB;EAC9E,MAAMC,MAAwB,GAAGD,WAAW,KAAK,MAAM,GAAG,MAAM,GAAG,OAAO;EAE1E,MAAME,aAAa,GAAG;IACpB,GAAGC,iBAAiB,CAACF,MAAM,CAAC;IAC5B,GAAGJ,mBAAmB,CAACI,MAAM;EAC/B,CAAC;EAED,OAAO;IACLG,MAAM,EAAEF,aAAa;IACrBG,MAAM,EAAE;MACNC,YAAY,EAAE;IAChB,CAAC;IACDC,IAAI,EAAE;MACJC,wBAAwB,EAAEP,MAAM,KAAK,MAAM,GAAG,EAAE,GAAG;IACrD,CAAC;IACDQ,oBAAoB,EAAE,IAAI,CAAE;EAC9B,CAAC;AACH,CAA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yBAAyB,EAAE7E,MAAM,CAAC8G,0BAA0B;EAC5D/B,+BAA+B,EAAE/E,MAAM,CAAC+G,+BAA+B;EACvE9B,eAAe,EAAEjF,MAAM,CAACgH,cAAc;EACtC7B,aAAa,EAAE,aAAa;EAC5BC,aAAa,EAAEpF,MAAM,CAACiH;AACxB,CAAC;AAED,MAAM5G,iBAAiB,GAAG;EACxB6G,KAAK,EAAEnG,eAAe;EACtBoG,IAAI,EAAE7B;AACR,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"theme.js","names":["Platform","PlatformColor","aliasTokensColorMap","tokens","defaultTheme","colorScheme","scheme","defaultColors","chatThemeColorMap","colors","button","borderRadius","chip","hslLightnessChipSelected","showBadgeProductLogo","iOSLinkColor","OS","undefined","colorsChatLight","name","androidModalHeaderButtonTextColor","fillColorInteractionDefault","iOSModalHeaderButtonTextColor","buttonStart","buttonEnd","interaction","androidSwitchThumbColor","conversationActionsBackground","colorNeutral100White","testColor","statusInfoIcon","iconColorStatusInfoPrimary","statusInfoText","textColorStatusInfo","statusInfoBorder","borderColorStatusInfo","statusInfoFill","fillColorStatusInfoSolid","statusSuccessIcon","iconColorStatusSuccessPrimary","statusSuccessText","textColorStatusSuccess","statusSuccessBorder","borderColorStatusSuccess","statusSuccessFill","fillColorStatusSuccessSolid","statusWarningIcon","iconColorStatusWarningPrimary","statusWarningText","textColorStatusWarning","statusWarningBorder","borderColorStatusWarning","statusWarningFill","fillColorStatusWarningSolid","statusErrorIcon","iconColorStatusErrorPrimary","statusErrorText","textColorStatusError","statusErrorBorder","borderColorStatusError","statusErrorFill","fillColorStatusErrorSolid","statusInfoComposedIcon","statusInfoComposedText","colorNeutral24","statusInfoComposedBackground","fillColorStatusInfoGhost","statusSuccessComposedIcon","statusSuccessComposedText","statusSuccessComposedBackground","fillColorStatusSuccessGhost","statusWarningComposedIcon","statusWarningComposedText","statusWarningComposedBackground","fillColorStatusWarningGhost","statusErrorComposedIcon","statusErrorComposedText","statusErrorComposedBackground","fillColorStatusErrorGhost","statusNeutralComposedIcon","textColorStatusNeutral","statusNeutralComposedText","statusNeutralComposedBackground","fillColorStatusNeutralGhost","borderColorChip","colorNeutral88","fillColorChip","textColorChip","colorNeutral45","colorsChatDark","fillColorInteractionDefaultDark","colorNeutral7","iconColorStatusInfoPrimaryDark","textColorStatusInfoDark","borderColorStatusInfoDark","fillColorStatusInfoSolidDark","iconColorStatusSuccessPrimaryDark","textColorStatusSuccessDark","borderColorStatusSuccessDark","fillColorStatusSuccessSolidDark","iconColorStatusWarningPrimaryDark","textColorStatusWarningDark","borderColorStatusWarningDark","fillColorStatusWarningSolidDark","iconColorStatusErrorPrimaryDark","textColorStatusErrorDark","borderColorStatusErrorDark","fillColorStatusErrorSolidDark","fillColorStatusInfoGhostDark","fillColorStatusSuccessGhostDark","fillColorStatusWarningGhostDark","fillColorStatusErrorGhostDark","textColorStatusNeutralDark","fillColorStatusNeutralGhostDark","colorNeutral68","light","dark"],"sources":["../../src/utils/theme.ts"],"sourcesContent":["import { Platform, PlatformColor } from 'react-native'\nimport type { ColorSchemeName, ColorValue, OpaqueColorValue } from 'react-native'\nimport { aliasTokensColorMap } from '../vendor/tapestry/alias_tokens_color_map'\nimport { tokens } from '../vendor/tapestry/tokens'\n\nexport interface ChatTheme extends DefaultTheme {\n colors: DefaultTheme['colors'] &\n (typeof aliasTokensColorMap.light | typeof aliasTokensColorMap.dark)\n}\n\n/** =============================================\n NOTE: The specific values for `colors` and the `productBadge` are temporary examples that can be replaced once we start building out UI. This line's comment can be removed at that time too.\n\n The default theme is intended to support two types of customizations:\n 1. Specific color properties for a chat component (eg. `primaryButtonBackgroundColor`)\n 2. Any styles for a specific component. (Use only one level of nesting.)\n ```\n primaryButton: {\n borderRadius: number\n container: ViewStyle\n text: TextStyle\n }\n ```\n============================================= */\n\nexport interface DefaultTheme {\n colors: ChatColors\n button: {\n borderRadius: number\n }\n chip: {\n hslLightnessChipSelected: number\n }\n showBadgeProductLogo: boolean\n}\n\nexport const defaultTheme = (colorScheme: ColorSchemeName | null): ChatTheme => {\n const scheme: 'light' | 'dark' = colorScheme === 'dark' ? 'dark' : 'light'\n\n const defaultColors = {\n ...chatThemeColorMap[scheme],\n ...aliasTokensColorMap[scheme],\n }\n\n return {\n colors: defaultColors,\n button: {\n borderRadius: 40,\n },\n chip: {\n hslLightnessChipSelected: scheme === 'dark' ? 12 : 92,\n },\n showBadgeProductLogo: true, // Overrides visibility of the product logo in `src/display/badge.tsx`\n }\n}\n\nexport type TemporaryDefaultColorsType = Partial<ChatColors>\n\ninterface ChatColors {\n name: string\n buttonStart: string | undefined\n buttonEnd: string | undefined\n interaction: string\n androidModalHeaderButtonTextColor: ColorValue | string | undefined\n iOSModalHeaderButtonTextColor: OpaqueColorValue | string | undefined\n androidSwitchThumbColor: string | undefined\n conversationActionsBackground: string\n testColor: string\n statusSuccessIcon: string\n statusSuccessText: string\n statusSuccessBorder: string\n statusSuccessFill: string\n statusInfoIcon: string\n statusInfoText: string\n statusInfoBorder: string\n statusInfoFill: string\n statusWarningIcon: string\n statusWarningText: string\n statusWarningBorder: string\n statusWarningFill: string\n statusErrorIcon: string\n statusErrorText: string\n statusErrorBorder: string\n statusErrorFill: string\n statusSuccessComposedIcon: string\n statusSuccessComposedText: string\n statusSuccessComposedBackground: string\n statusInfoComposedIcon: string\n statusInfoComposedText: string\n statusInfoComposedBackground: string\n statusWarningComposedIcon: string\n statusWarningComposedText: string\n statusWarningComposedBackground: string\n statusErrorComposedIcon: string\n statusErrorComposedText: string\n statusErrorComposedBackground: string\n statusNeutralComposedIcon: string\n statusNeutralComposedText: string\n statusNeutralComposedBackground: string\n borderColorChip: string\n fillColorChip: string\n textColorChip: string\n /**\n * Selected-chip colors (border/fill/text). Never assign a static default\n * directly — these stay optional so they always fall back to\n * `colors.interaction` via `??` at the read site. Every current consumer\n * overrides `interaction` at runtime, and a seeded default here could win\n * over that override depending on merge order.\n */\n borderColorChipSelected?: string\n fillColorChipSelected?: string\n textColorChipSelected?: string\n}\n\n// 'link' is an iOS-only semantic color name — constructing it on Android is\n// undefined behavior, so only build it when the code is actually running on iOS\nconst iOSLinkColor = Platform.OS === 'ios' ? PlatformColor('link') : undefined\n\nconst colorsChatLight: ChatColors = {\n name: 'light',\n androidModalHeaderButtonTextColor: tokens.fillColorInteractionDefault,\n iOSModalHeaderButtonTextColor: iOSLinkColor,\n buttonStart: undefined,\n buttonEnd: undefined,\n interaction: tokens.fillColorInteractionDefault,\n androidSwitchThumbColor: undefined,\n conversationActionsBackground: tokens.colorNeutral100White,\n testColor: 'hotpink',\n statusInfoIcon: tokens.iconColorStatusInfoPrimary,\n statusInfoText: tokens.textColorStatusInfo,\n statusInfoBorder: tokens.borderColorStatusInfo,\n statusInfoFill: tokens.fillColorStatusInfoSolid,\n statusSuccessIcon: tokens.iconColorStatusSuccessPrimary,\n statusSuccessText: tokens.textColorStatusSuccess,\n statusSuccessBorder: tokens.borderColorStatusSuccess,\n statusSuccessFill: tokens.fillColorStatusSuccessSolid,\n statusWarningIcon: tokens.iconColorStatusWarningPrimary,\n statusWarningText: tokens.textColorStatusWarning,\n statusWarningBorder: tokens.borderColorStatusWarning,\n statusWarningFill: tokens.fillColorStatusWarningSolid,\n statusErrorIcon: tokens.iconColorStatusErrorPrimary,\n statusErrorText: tokens.textColorStatusError,\n statusErrorBorder: tokens.borderColorStatusError,\n statusErrorFill: tokens.fillColorStatusErrorSolid,\n statusInfoComposedIcon: tokens.textColorStatusInfo,\n statusInfoComposedText: tokens.colorNeutral24,\n statusInfoComposedBackground: tokens.fillColorStatusInfoGhost,\n statusSuccessComposedIcon: tokens.textColorStatusSuccess,\n statusSuccessComposedText: tokens.colorNeutral24,\n statusSuccessComposedBackground: tokens.fillColorStatusSuccessGhost,\n statusWarningComposedIcon: tokens.textColorStatusWarning,\n statusWarningComposedText: tokens.colorNeutral24,\n statusWarningComposedBackground: tokens.fillColorStatusWarningGhost,\n statusErrorComposedIcon: tokens.textColorStatusError,\n statusErrorComposedText: tokens.colorNeutral24,\n statusErrorComposedBackground: tokens.fillColorStatusErrorGhost,\n statusNeutralComposedIcon: tokens.textColorStatusNeutral,\n statusNeutralComposedText: tokens.colorNeutral24,\n statusNeutralComposedBackground: tokens.fillColorStatusNeutralGhost,\n borderColorChip: tokens.colorNeutral88,\n fillColorChip: 'transparent',\n textColorChip: tokens.colorNeutral45,\n}\n\nconst colorsChatDark: ChatColors = {\n name: 'dark',\n androidModalHeaderButtonTextColor: tokens.fillColorInteractionDefaultDark,\n iOSModalHeaderButtonTextColor: iOSLinkColor,\n buttonStart: undefined,\n buttonEnd: undefined,\n interaction: tokens.fillColorInteractionDefaultDark,\n androidSwitchThumbColor: undefined,\n conversationActionsBackground: tokens.colorNeutral7,\n testColor: 'pink',\n statusInfoIcon: tokens.iconColorStatusInfoPrimaryDark,\n statusInfoText: tokens.textColorStatusInfoDark,\n statusInfoBorder: tokens.borderColorStatusInfoDark,\n statusInfoFill: tokens.fillColorStatusInfoSolidDark,\n statusSuccessIcon: tokens.iconColorStatusSuccessPrimaryDark,\n statusSuccessText: tokens.textColorStatusSuccessDark,\n statusSuccessBorder: tokens.borderColorStatusSuccessDark,\n statusSuccessFill: tokens.fillColorStatusSuccessSolidDark,\n statusWarningIcon: tokens.iconColorStatusWarningPrimaryDark,\n statusWarningText: tokens.textColorStatusWarningDark,\n statusWarningBorder: tokens.borderColorStatusWarningDark,\n statusWarningFill: tokens.fillColorStatusWarningSolidDark,\n statusErrorIcon: tokens.iconColorStatusErrorPrimaryDark,\n statusErrorText: tokens.textColorStatusErrorDark,\n statusErrorBorder: tokens.borderColorStatusErrorDark,\n statusErrorFill: tokens.fillColorStatusErrorSolidDark,\n\n statusInfoComposedIcon: tokens.textColorStatusInfoDark,\n statusInfoComposedText: tokens.colorNeutral88,\n statusInfoComposedBackground: tokens.fillColorStatusInfoGhostDark,\n statusSuccessComposedIcon: tokens.textColorStatusSuccessDark,\n statusSuccessComposedText: tokens.colorNeutral88,\n statusSuccessComposedBackground: tokens.fillColorStatusSuccessGhostDark,\n statusWarningComposedIcon: tokens.textColorStatusWarningDark,\n statusWarningComposedText: tokens.colorNeutral88,\n statusWarningComposedBackground: tokens.fillColorStatusWarningGhostDark,\n statusErrorComposedIcon: tokens.textColorStatusErrorDark,\n statusErrorComposedText: tokens.colorNeutral88,\n statusErrorComposedBackground: tokens.fillColorStatusErrorGhostDark,\n statusNeutralComposedIcon: tokens.textColorStatusNeutralDark,\n statusNeutralComposedText: tokens.colorNeutral88,\n statusNeutralComposedBackground: tokens.fillColorStatusNeutralGhostDark,\n borderColorChip: tokens.colorNeutral24,\n fillColorChip: 'transparent',\n textColorChip: tokens.colorNeutral68,\n}\n\nconst chatThemeColorMap = {\n light: colorsChatLight,\n dark: colorsChatDark,\n}\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,aAAa,QAAQ,cAAc;AAEtD,SAASC,mBAAmB,QAAQ,2CAA2C;AAC/E,SAASC,MAAM,QAAQ,2BAA2B;;AAOlD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaA,OAAO,MAAMC,YAAY,GAAIC,WAAmC,IAAgB;EAC9E,MAAMC,MAAwB,GAAGD,WAAW,KAAK,MAAM,GAAG,MAAM,GAAG,OAAO;EAE1E,MAAME,aAAa,GAAG;IACpB,GAAGC,iBAAiB,CAACF,MAAM,CAAC;IAC5B,GAAGJ,mBAAmB,CAACI,MAAM;EAC/B,CAAC;EAED,OAAO;IACLG,MAAM,EAAEF,aAAa;IACrBG,MAAM,EAAE;MACNC,YAAY,EAAE;IAChB,CAAC;IACDC,IAAI,EAAE;MACJC,wBAAwB,EAAEP,MAAM,KAAK,MAAM,GAAG,EAAE,GAAG;IACrD,CAAC;IACDQ,oBAAoB,EAAE,IAAI,CAAE;EAC9B,CAAC;AACH,CAAC;AA4DD;AACA;AACA,MAAMC,YAAY,GAAGf,QAAQ,CAACgB,EAAE,KAAK,KAAK,GAAGf,aAAa,CAAC,MAA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ACtCsB,aAAa,EAAE,aAAa;EAC5BC,aAAa,EAAEpF,MAAM,CAAC+G;AACxB,CAAC;AAED,MAAM1G,iBAAiB,GAAG;EACxB2G,KAAK,EAAEjG,eAAe;EACtBkG,IAAI,EAAE3B;AACR,CAAC","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,C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AiB,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.11",
|
|
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": "de07677a557e9387ac63a96fed82e54bf2b9f6c9"
|
|
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) })
|
|
@@ -41,29 +41,4 @@ describe('useFontScale', () => {
|
|
|
41
41
|
expect(result.current).toBe(2)
|
|
42
42
|
})
|
|
43
43
|
})
|
|
44
|
-
|
|
45
|
-
describe('with both constraints', () => {
|
|
46
|
-
test('returns native scale when within bounds', () => {
|
|
47
|
-
const { result } = renderHook(() =>
|
|
48
|
-
useFontScale({ minFontSizeMultiplier: 0.5, maxFontSizeMultiplier: 2 })
|
|
49
|
-
)
|
|
50
|
-
expect(result.current).toBe(DEFAULT_NATIVE_FONT_SCALE)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
test('clamps to minimum when native scale is below', () => {
|
|
54
|
-
mockUseWindowDimensions.mockReturnValue({ fontScale: SMALL_NATIVE_FONT_SCALE })
|
|
55
|
-
const { result } = renderHook(() =>
|
|
56
|
-
useFontScale({ minFontSizeMultiplier: 1, maxFontSizeMultiplier: 2 })
|
|
57
|
-
)
|
|
58
|
-
expect(result.current).toBe(1)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
test('clamps to maximum when native scale exceeds', () => {
|
|
62
|
-
mockUseWindowDimensions.mockReturnValue({ fontScale: LARGE_NATIVE_FONT_SCALE })
|
|
63
|
-
const { result } = renderHook(() =>
|
|
64
|
-
useFontScale({ minFontSizeMultiplier: 1, maxFontSizeMultiplier: 2 })
|
|
65
|
-
)
|
|
66
|
-
expect(result.current).toBe(2)
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
44
|
})
|