@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.
Files changed (253) hide show
  1. package/build/components/conversations/app_update_banner.d.ts +2 -0
  2. package/build/components/conversations/app_update_banner.d.ts.map +1 -0
  3. package/build/components/conversations/app_update_banner.js +52 -0
  4. package/build/components/conversations/app_update_banner.js.map +1 -0
  5. package/build/components/conversations/bulk_conversation_actions_bar.d.ts +2 -0
  6. package/build/components/conversations/bulk_conversation_actions_bar.d.ts.map +1 -0
  7. package/build/components/conversations/bulk_conversation_actions_bar.js +215 -0
  8. package/build/components/conversations/bulk_conversation_actions_bar.js.map +1 -0
  9. package/build/components/conversations/conversation_actions.d.ts +2 -1
  10. package/build/components/conversations/conversation_actions.d.ts.map +1 -1
  11. package/build/components/conversations/conversation_actions.js +173 -130
  12. package/build/components/conversations/conversation_actions.js.map +1 -1
  13. package/build/components/conversations/conversation_preview.d.ts.map +1 -1
  14. package/build/components/conversations/conversation_preview.js +168 -110
  15. package/build/components/conversations/conversation_preview.js.map +1 -1
  16. package/build/components/conversations/conversations.d.ts.map +1 -1
  17. package/build/components/conversations/conversations.js +50 -48
  18. package/build/components/conversations/conversations.js.map +1 -1
  19. package/build/components/display/checkbox.d.ts +8 -0
  20. package/build/components/display/checkbox.d.ts.map +1 -0
  21. package/build/components/display/checkbox.js +87 -0
  22. package/build/components/display/checkbox.js.map +1 -0
  23. package/build/components/display/icon.d.ts +3 -1
  24. package/build/components/display/icon.d.ts.map +1 -1
  25. package/build/components/display/icon.js +2 -0
  26. package/build/components/display/icon.js.map +1 -1
  27. package/build/components/display/index.d.ts +1 -0
  28. package/build/components/display/index.d.ts.map +1 -1
  29. package/build/components/display/index.js +1 -0
  30. package/build/components/display/index.js.map +1 -1
  31. package/build/components/primitive/banner_primitive.js +7 -3
  32. package/build/components/primitive/banner_primitive.js.map +1 -1
  33. package/build/contexts/api_provider.d.ts.map +1 -1
  34. package/build/contexts/api_provider.js +2 -0
  35. package/build/contexts/api_provider.js.map +1 -1
  36. package/build/contexts/chat_context.d.ts +0 -2
  37. package/build/contexts/chat_context.d.ts.map +1 -1
  38. package/build/contexts/chat_context.js +16 -93
  39. package/build/contexts/chat_context.js.map +1 -1
  40. package/build/contexts/conversations_context.d.ts +5 -0
  41. package/build/contexts/conversations_context.d.ts.map +1 -1
  42. package/build/contexts/conversations_context.js +121 -32
  43. package/build/contexts/conversations_context.js.map +1 -1
  44. package/build/contexts/session_context.d.ts +0 -1
  45. package/build/contexts/session_context.d.ts.map +1 -1
  46. package/build/contexts/session_context.js +3 -0
  47. package/build/contexts/session_context.js.map +1 -1
  48. package/build/hooks/groups/use_group_chat_conversation_payload.d.ts +11 -1
  49. package/build/hooks/groups/use_group_chat_conversation_payload.d.ts.map +1 -1
  50. package/build/hooks/groups/use_group_chat_conversation_payload.js +92 -47
  51. package/build/hooks/groups/use_group_chat_conversation_payload.js.map +1 -1
  52. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +27 -25
  53. package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
  54. package/build/hooks/groups/use_group_members_for_new_conversation.js +125 -110
  55. package/build/hooks/groups/use_group_members_for_new_conversation.js.map +1 -1
  56. package/build/hooks/groups/use_groups_conversation_create.d.ts.map +1 -1
  57. package/build/hooks/groups/use_groups_conversation_create.js +39 -31
  58. package/build/hooks/groups/use_groups_conversation_create.js.map +1 -1
  59. package/build/hooks/groups/use_groups_proxy.d.ts +2 -0
  60. package/build/hooks/groups/use_groups_proxy.d.ts.map +1 -0
  61. package/build/hooks/groups/use_groups_proxy.js +18 -0
  62. package/build/hooks/groups/use_groups_proxy.js.map +1 -0
  63. package/build/hooks/use_bulk_conversation_actions.d.ts +8 -0
  64. package/build/hooks/use_bulk_conversation_actions.d.ts.map +1 -0
  65. package/build/hooks/use_bulk_conversation_actions.js +309 -0
  66. package/build/hooks/use_bulk_conversation_actions.js.map +1 -0
  67. package/build/hooks/use_conversation_jolt_events.d.ts.map +1 -1
  68. package/build/hooks/use_conversation_jolt_events.js +3 -2
  69. package/build/hooks/use_conversation_jolt_events.js.map +1 -1
  70. package/build/hooks/use_conversations_actions.d.ts +9 -9
  71. package/build/hooks/use_conversations_actions.d.ts.map +1 -1
  72. package/build/hooks/use_conversations_actions.js +12 -7
  73. package/build/hooks/use_conversations_actions.js.map +1 -1
  74. package/build/hooks/use_conversations_cache.d.ts +15 -5
  75. package/build/hooks/use_conversations_cache.d.ts.map +1 -1
  76. package/build/hooks/use_conversations_cache.js +170 -122
  77. package/build/hooks/use_conversations_cache.js.map +1 -1
  78. package/build/hooks/use_conversations_jolt_events.d.ts.map +1 -1
  79. package/build/hooks/use_conversations_jolt_events.js +47 -20
  80. package/build/hooks/use_conversations_jolt_events.js.map +1 -1
  81. package/build/hooks/use_features.d.ts +1 -0
  82. package/build/hooks/use_features.d.ts.map +1 -1
  83. package/build/hooks/use_features.js +1 -0
  84. package/build/hooks/use_features.js.map +1 -1
  85. package/build/hooks/use_groups_groups.d.ts.map +1 -1
  86. package/build/hooks/use_groups_groups.js +25 -9
  87. package/build/hooks/use_groups_groups.js.map +1 -1
  88. package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
  89. package/build/hooks/use_mark_latest_message_read.js +5 -4
  90. package/build/hooks/use_mark_latest_message_read.js.map +1 -1
  91. package/build/hooks/use_new_conversation_from_filter.d.ts.map +1 -1
  92. package/build/hooks/use_new_conversation_from_filter.js +11 -1
  93. package/build/hooks/use_new_conversation_from_filter.js.map +1 -1
  94. package/build/hooks/use_product_analytics.d.ts.map +1 -1
  95. package/build/hooks/use_product_analytics.js +93 -75
  96. package/build/hooks/use_product_analytics.js.map +1 -1
  97. package/build/navigation/index.d.ts.map +1 -1
  98. package/build/navigation/index.js +5 -7
  99. package/build/navigation/index.js.map +1 -1
  100. package/build/screens/conversation_actions_screen.d.ts +2 -0
  101. package/build/screens/conversation_actions_screen.d.ts.map +1 -1
  102. package/build/screens/conversation_actions_screen.js +380 -46
  103. package/build/screens/conversation_actions_screen.js.map +1 -1
  104. package/build/screens/conversation_filter_recipients/components/checkbox_row.d.ts.map +1 -1
  105. package/build/screens/conversation_filter_recipients/components/checkbox_row.js +9 -64
  106. package/build/screens/conversation_filter_recipients/components/checkbox_row.js.map +1 -1
  107. package/build/screens/conversation_new/components/groups_form.d.ts.map +1 -1
  108. package/build/screens/conversation_new/components/groups_form.js +96 -93
  109. package/build/screens/conversation_new/components/groups_form.js.map +1 -1
  110. package/build/screens/conversations/conversations_screen.d.ts +5 -0
  111. package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
  112. package/build/screens/conversations/conversations_screen.js +176 -33
  113. package/build/screens/conversations/conversations_screen.js.map +1 -1
  114. package/build/types/jolt_events/index.d.ts +2 -0
  115. package/build/types/jolt_events/index.d.ts.map +1 -1
  116. package/build/types/jolt_events/index.js.map +1 -1
  117. package/build/types/jolt_events/person_events.d.ts +9 -0
  118. package/build/types/jolt_events/person_events.d.ts.map +1 -0
  119. package/build/types/jolt_events/person_events.js +2 -0
  120. package/build/types/jolt_events/person_events.js.map +1 -0
  121. package/build/types/resources/groups/groups_group_resource.d.ts +1 -1
  122. package/build/types/resources/groups/groups_group_resource.d.ts.map +1 -1
  123. package/build/types/resources/groups/groups_group_resource.js.map +1 -1
  124. package/build/types/resources/groups/groups_membership_resource.d.ts +11 -0
  125. package/build/types/resources/groups/groups_membership_resource.d.ts.map +1 -0
  126. package/build/types/resources/groups/groups_membership_resource.js +2 -0
  127. package/build/types/resources/groups/groups_membership_resource.js.map +1 -0
  128. package/build/types/resources/groups/index.d.ts +1 -0
  129. package/build/types/resources/groups/index.d.ts.map +1 -1
  130. package/build/types/resources/groups/index.js +1 -0
  131. package/build/types/resources/groups/index.js.map +1 -1
  132. package/build/utils/jolt/parse_stream_user_event_type.d.ts +3 -0
  133. package/build/utils/jolt/parse_stream_user_event_type.d.ts.map +1 -0
  134. package/build/utils/jolt/parse_stream_user_event_type.js +9 -0
  135. package/build/utils/jolt/parse_stream_user_event_type.js.map +1 -0
  136. package/build/utils/native_adapters/configuration.d.ts +3 -0
  137. package/build/utils/native_adapters/configuration.d.ts.map +1 -1
  138. package/build/utils/native_adapters/configuration.js +3 -0
  139. package/build/utils/native_adapters/configuration.js.map +1 -1
  140. package/build/utils/native_adapters/index.d.ts +1 -0
  141. package/build/utils/native_adapters/index.d.ts.map +1 -1
  142. package/build/utils/native_adapters/index.js +1 -0
  143. package/build/utils/native_adapters/index.js.map +1 -1
  144. package/build/utils/native_adapters/updates.d.ts +11 -0
  145. package/build/utils/native_adapters/updates.d.ts.map +1 -0
  146. package/build/utils/native_adapters/updates.js +8 -0
  147. package/build/utils/native_adapters/updates.js.map +1 -0
  148. package/build/utils/product_analytics_token.d.ts +12 -0
  149. package/build/utils/product_analytics_token.d.ts.map +1 -0
  150. package/build/utils/product_analytics_token.js +84 -0
  151. package/build/utils/product_analytics_token.js.map +1 -0
  152. package/build/utils/theme.js +20 -21
  153. package/build/utils/theme.js.map +1 -1
  154. package/build/utils/throttled_refresh.d.ts +7 -0
  155. package/build/utils/throttled_refresh.d.ts.map +1 -0
  156. package/build/utils/throttled_refresh.js +42 -0
  157. package/build/utils/throttled_refresh.js.map +1 -0
  158. package/package.json +2 -2
  159. package/src/__tests__/contexts/session_context.tsx +19 -39
  160. package/src/__tests__/hooks/useTheme.tsx +0 -7
  161. package/src/__tests__/hooks/use_async_storage.test.tsx +1 -87
  162. package/src/__tests__/hooks/use_attachment_uploader.test.tsx +0 -11
  163. package/src/__tests__/hooks/use_font_scale.test.ts +0 -25
  164. package/src/__tests__/hooks/use_group_chat_conversation_payload.test.tsx +31 -0
  165. package/src/__tests__/utils/cache/page_mutations.ts +3 -68
  166. package/src/__tests__/utils/client.ts +6 -15
  167. package/src/__tests__/utils/native_adapters/configuration.ts +15 -50
  168. package/src/__tests__/utils/parse_simple_markdown.ts +0 -6
  169. package/src/__tests__/utils/session.ts +0 -11
  170. package/src/__tests__/utils/theme.ts +0 -17
  171. package/src/components/conversations/__tests__/app_update_banner.test.tsx +27 -0
  172. package/src/components/conversations/__tests__/bulk_conversation_actions_bar.test.tsx +95 -0
  173. package/src/components/conversations/__tests__/conversation_actions.test.tsx +35 -3
  174. package/src/components/conversations/__tests__/conversation_preview.test.tsx +69 -3
  175. package/src/components/conversations/__tests__/conversations.test.tsx +4 -1
  176. package/src/components/conversations/app_update_banner.tsx +36 -0
  177. package/src/components/conversations/bulk_conversation_actions_bar.tsx +140 -0
  178. package/src/components/conversations/conversation_actions.tsx +17 -9
  179. package/src/components/conversations/conversation_preview.tsx +20 -2
  180. package/src/components/conversations/conversations.tsx +2 -1
  181. package/src/components/display/__tests__/filter_dropdown.test.tsx +1 -19
  182. package/src/components/display/__tests__/icon_tile.test.tsx +24 -7
  183. package/src/components/display/checkbox.tsx +47 -0
  184. package/src/components/display/icon.tsx +3 -0
  185. package/src/components/display/index.ts +1 -0
  186. package/src/components/page/__tests__/component_error_boundary.test.tsx +0 -12
  187. package/src/components/primitive/banner_primitive.tsx +5 -1
  188. package/src/contexts/__tests__/conversations_context.test.tsx +86 -0
  189. package/src/contexts/api_provider.tsx +2 -0
  190. package/src/contexts/chat_context.tsx +2 -58
  191. package/src/contexts/conversations_context.tsx +69 -2
  192. package/src/contexts/session_context.tsx +3 -1
  193. package/src/hooks/__tests__/jolt_refresh_throttling.test.tsx +194 -0
  194. package/src/hooks/__tests__/use_bulk_conversation_actions.test.tsx +119 -0
  195. package/src/hooks/__tests__/use_conversations_jolt_events.test.tsx +1 -0
  196. package/src/hooks/__tests__/use_conversations_mark_read.test.tsx +38 -12
  197. package/src/hooks/__tests__/use_hide_conversation.test.tsx +15 -3
  198. package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +23 -2
  199. package/src/hooks/__tests__/use_product_analytics.test.tsx +304 -0
  200. package/src/hooks/groups/use_group_chat_conversation_payload.ts +30 -12
  201. package/src/hooks/groups/use_group_members_for_new_conversation.ts +49 -18
  202. package/src/hooks/groups/use_groups_conversation_create.ts +10 -14
  203. package/src/hooks/groups/use_groups_proxy.ts +6 -0
  204. package/src/hooks/use_bulk_conversation_actions.ts +173 -0
  205. package/src/hooks/use_conversation_jolt_events.ts +2 -1
  206. package/src/hooks/use_conversations_actions.ts +7 -4
  207. package/src/hooks/use_conversations_cache.ts +33 -26
  208. package/src/hooks/use_conversations_jolt_events.ts +24 -10
  209. package/src/hooks/use_features.ts +1 -0
  210. package/src/hooks/use_groups_groups.ts +21 -16
  211. package/src/hooks/use_mark_latest_message_read.ts +6 -5
  212. package/src/hooks/use_new_conversation_from_filter.ts +13 -5
  213. package/src/hooks/use_product_analytics.ts +74 -41
  214. package/src/navigation/index.tsx +8 -8
  215. package/src/screens/__tests__/conversation_actions_screen.test.tsx +48 -6
  216. package/src/screens/__tests__/conversation_details_screen.test.tsx +0 -19
  217. package/src/screens/avatar_picker/__tests__/avatar_picker_state.test.ts +0 -14
  218. package/src/screens/conversation_actions_screen.tsx +145 -12
  219. package/src/screens/conversation_filter_recipients/components/checkbox_row.tsx +3 -35
  220. package/src/screens/conversation_new/components/groups_form.tsx +11 -9
  221. package/src/screens/conversations/__tests__/conversations_screen.test.tsx +37 -12
  222. package/src/screens/conversations/components/__tests__/filter_dropdown_list_header_component.test.tsx +0 -8
  223. package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +0 -10
  224. package/src/screens/conversations/conversations_screen.tsx +76 -4
  225. package/src/screens/search/components/__tests__/search_results_list.test.tsx +1 -0
  226. package/src/types/jolt_events/index.ts +2 -0
  227. package/src/types/jolt_events/person_events.ts +16 -0
  228. package/src/types/resources/groups/groups_group_resource.ts +1 -1
  229. package/src/types/resources/groups/groups_membership_resource.ts +10 -0
  230. package/src/types/resources/groups/index.ts +1 -0
  231. package/src/utils/__tests__/attachment_kind.test.ts +0 -4
  232. package/src/utils/__tests__/convert_attachments_for_create.test.ts +0 -28
  233. package/src/utils/__tests__/is_input_editable.test.ts +1 -2
  234. package/src/utils/__tests__/message_text.test.ts +0 -5
  235. package/src/utils/__tests__/session_manager.test.ts +0 -83
  236. package/src/utils/__tests__/sha_256.test.ts +0 -34
  237. package/src/utils/__tests__/throttled_refresh.test.ts +101 -0
  238. package/src/utils/__tests__/uri.test.ts +51 -0
  239. package/src/utils/jolt/__tests__/parse_stream_user_event_type.test.ts +27 -0
  240. package/src/utils/jolt/parse_stream_user_event_type.ts +16 -0
  241. package/src/utils/native_adapters/configuration.ts +5 -0
  242. package/src/utils/native_adapters/index.ts +1 -0
  243. package/src/utils/native_adapters/updates.ts +16 -0
  244. package/src/utils/product_analytics_token.ts +120 -0
  245. package/src/utils/theme.ts +20 -21
  246. package/src/utils/throttled_refresh.ts +62 -0
  247. package/src/__tests__/event-polyfill.test.ts +0 -313
  248. package/src/__tests__/index.tsx +0 -5
  249. package/src/__tests__/jest.ts +0 -11
  250. package/src/__tests__/utils/uri.ts +0 -65
  251. package/src/components/display/__tests__/version_footer.test.tsx +0 -48
  252. package/src/screens/search/components/__tests__/search_blank_states.test.tsx +0 -20
  253. package/src/utils/__tests__/membership_sync_info_text.test.ts +0 -15
@@ -0,0 +1,16 @@
1
+ import { noop } from 'lodash'
2
+
3
+ interface Updates {
4
+ useDownloadedUpdateId: () => string | undefined
5
+ restart: () => void
6
+ }
7
+
8
+ export class UpdatesAdapter {
9
+ useDownloadedUpdateId: () => string | undefined
10
+ restart: () => void
11
+
12
+ constructor(methods?: Updates) {
13
+ this.useDownloadedUpdateId = methods?.useDownloadedUpdateId ?? (() => undefined)
14
+ this.restart = methods?.restart ?? noop
15
+ }
16
+ }
@@ -0,0 +1,120 @@
1
+ import { QueryClient } from '@tanstack/react-query'
2
+ import { currentPersonQueryKey } from '../hooks/use_current_person'
3
+ import { ApiResource, CurrentPersonResource } from '../types'
4
+ import { ProductAnalyticsConfig } from '../types/product_analytics'
5
+ import { Client } from './client'
6
+ import { Storage } from './native_adapters'
7
+ import { Session } from './session'
8
+ import { ONE_HOUR, toMs } from './time'
9
+ import { Uri } from './uri'
10
+
11
+ interface ProductAnalyticsTokenResponse {
12
+ type: 'ProductAnalyticsToken'
13
+ id: string
14
+ url: string
15
+ metadata: Record<string, unknown>
16
+ }
17
+
18
+ export interface StoredProductAnalyticsConfig extends ProductAnalyticsConfig {
19
+ expiresAt: number
20
+ personId: string
21
+ }
22
+
23
+ export const TOKEN_EXPIRY_TIME = toMs(7 * 24, 'hours')
24
+ const EXPIRY_MARGIN = ONE_HOUR
25
+
26
+ // One slot per environment, tagged with the person it belongs to. Keying on
27
+ // session.id would miss on every access-token refresh and leave orphaned entries.
28
+ export const productAnalyticsStorageKey = (session: Session) =>
29
+ `product-analytics-token:${session.env}`
30
+
31
+ export const productAnalyticsQueryKey = (session: Session) => [
32
+ 'product-analytics-token',
33
+ session.env,
34
+ session.id,
35
+ ]
36
+
37
+ const renewalTime = (config: StoredProductAnalyticsConfig) => config.expiresAt - EXPIRY_MARGIN
38
+
39
+ const isStoredConfig = (value: unknown): value is StoredProductAnalyticsConfig =>
40
+ typeof value === 'object' &&
41
+ value !== null &&
42
+ typeof (value as StoredProductAnalyticsConfig).token === 'string' &&
43
+ typeof (value as StoredProductAnalyticsConfig).endpoint === 'string' &&
44
+ typeof (value as StoredProductAnalyticsConfig).expiresAt === 'number' &&
45
+ typeof (value as StoredProductAnalyticsConfig).personId === 'string'
46
+
47
+ async function readStoredConfig(key: string): Promise<StoredProductAnalyticsConfig | undefined> {
48
+ try {
49
+ const raw = await Storage.getItem(key)
50
+ if (!raw) return undefined
51
+
52
+ const parsed: unknown = JSON.parse(raw)
53
+ return isStoredConfig(parsed) ? parsed : undefined
54
+ } catch {
55
+ return undefined
56
+ }
57
+ }
58
+
59
+ function writeStoredConfig(key: string, config: StoredProductAnalyticsConfig): Promise<void> {
60
+ return Storage.setItem(key, JSON.stringify(config)).catch(() => {})
61
+ }
62
+
63
+ function requestConfig(session: Session, personId: string): Promise<StoredProductAnalyticsConfig> {
64
+ const uri = new Uri({ session })
65
+ const client = new Client({
66
+ root: uri.api('/chat/v2'),
67
+ defaultHeaders: uri.headers,
68
+ version: '2018-11-01',
69
+ })
70
+
71
+ return client
72
+ .post<ApiResource<ProductAnalyticsTokenResponse>>({
73
+ url: '/me/product_analytics_authorize',
74
+ data: { data: { type: 'ProductAnalyticsToken', attributes: {} } },
75
+ })
76
+ .then(res => ({
77
+ token: res.data.id,
78
+ endpoint: res.data.url,
79
+ metadata: res.data.metadata,
80
+ expiresAt: Date.now() + TOKEN_EXPIRY_TIME,
81
+ personId,
82
+ }))
83
+ }
84
+
85
+ // The chat screens that publish events already load /me, and the package's query
86
+ // client is cleared whenever the access token changes, so this is normally a cache hit.
87
+ async function currentPersonId(queryClient: QueryClient): Promise<string> {
88
+ const { data } = await queryClient.ensureQueryData<ApiResource<CurrentPersonResource>>({
89
+ queryKey: currentPersonQueryKey,
90
+ })
91
+ return String(data.id)
92
+ }
93
+
94
+ async function loadConfig(
95
+ queryClient: QueryClient,
96
+ session: Session
97
+ ): Promise<StoredProductAnalyticsConfig> {
98
+ const personId = await currentPersonId(queryClient)
99
+ const key = productAnalyticsStorageKey(session)
100
+ const stored = await readStoredConfig(key)
101
+ if (stored && stored.personId === personId && renewalTime(stored) > Date.now()) return stored
102
+
103
+ const config = await requestConfig(session, personId)
104
+ await writeStoredConfig(key, config)
105
+ return config
106
+ }
107
+
108
+ export function fetchProductAnalyticsConfig(
109
+ queryClient: QueryClient,
110
+ session: Session
111
+ ): Promise<StoredProductAnalyticsConfig> {
112
+ return queryClient.fetchQuery({
113
+ queryKey: productAnalyticsQueryKey(session),
114
+ queryFn: () => loadConfig(queryClient, session),
115
+ staleTime: ({ state }) =>
116
+ state.data ? Math.max(0, renewalTime(state.data) - state.dataUpdatedAt) : 0,
117
+ gcTime: TOKEN_EXPIRY_TIME,
118
+ retry: false,
119
+ })
120
+ }
@@ -142,20 +142,20 @@ const colorsChatLight: ChatColors = {
142
142
  statusErrorText: tokens.textColorStatusError,
143
143
  statusErrorBorder: tokens.borderColorStatusError,
144
144
  statusErrorFill: tokens.fillColorStatusErrorSolid,
145
- statusInfoComposedIcon: tokens.iconColorStatusInfoPrimary,
146
- statusInfoComposedText: tokens.textColorStatusInfo,
145
+ statusInfoComposedIcon: tokens.textColorStatusInfo,
146
+ statusInfoComposedText: tokens.colorNeutral24,
147
147
  statusInfoComposedBackground: tokens.fillColorStatusInfoGhost,
148
- statusSuccessComposedIcon: tokens.iconColorStatusSuccessPrimary,
149
- statusSuccessComposedText: tokens.textColorStatusSuccess,
148
+ statusSuccessComposedIcon: tokens.textColorStatusSuccess,
149
+ statusSuccessComposedText: tokens.colorNeutral24,
150
150
  statusSuccessComposedBackground: tokens.fillColorStatusSuccessGhost,
151
- statusWarningComposedIcon: tokens.iconColorStatusWarningPrimary,
152
- statusWarningComposedText: tokens.textColorStatusWarning,
151
+ statusWarningComposedIcon: tokens.textColorStatusWarning,
152
+ statusWarningComposedText: tokens.colorNeutral24,
153
153
  statusWarningComposedBackground: tokens.fillColorStatusWarningGhost,
154
- statusErrorComposedIcon: tokens.iconColorStatusErrorPrimary,
155
- statusErrorComposedText: tokens.textColorStatusError,
154
+ statusErrorComposedIcon: tokens.textColorStatusError,
155
+ statusErrorComposedText: tokens.colorNeutral24,
156
156
  statusErrorComposedBackground: tokens.fillColorStatusErrorGhost,
157
- statusNeutralComposedIcon: tokens.iconColorStatusNeutralPrimary,
158
- statusNeutralComposedText: tokens.textColorStatusNeutral,
157
+ statusNeutralComposedIcon: tokens.textColorStatusNeutral,
158
+ statusNeutralComposedText: tokens.colorNeutral24,
159
159
  statusNeutralComposedBackground: tokens.fillColorStatusNeutralGhost,
160
160
  borderColorChip: tokens.colorNeutral88,
161
161
  fillColorChip: 'transparent',
@@ -189,21 +189,20 @@ const colorsChatDark: ChatColors = {
189
189
  statusErrorBorder: tokens.borderColorStatusErrorDark,
190
190
  statusErrorFill: tokens.fillColorStatusErrorSolidDark,
191
191
 
192
- // Note: CCA inverts composed status colors in dark mode
193
- statusInfoComposedIcon: tokens.iconColorStatusInfoPrimaryDark,
194
- statusInfoComposedText: tokens.textColorStatusInfoDark,
192
+ statusInfoComposedIcon: tokens.textColorStatusInfoDark,
193
+ statusInfoComposedText: tokens.colorNeutral88,
195
194
  statusInfoComposedBackground: tokens.fillColorStatusInfoGhostDark,
196
- statusSuccessComposedIcon: tokens.iconColorStatusSuccessPrimaryDark,
197
- statusSuccessComposedText: tokens.textColorStatusSuccessDark,
195
+ statusSuccessComposedIcon: tokens.textColorStatusSuccessDark,
196
+ statusSuccessComposedText: tokens.colorNeutral88,
198
197
  statusSuccessComposedBackground: tokens.fillColorStatusSuccessGhostDark,
199
- statusWarningComposedIcon: tokens.iconColorStatusWarningPrimaryDark,
200
- statusWarningComposedText: tokens.textColorStatusWarningDark,
198
+ statusWarningComposedIcon: tokens.textColorStatusWarningDark,
199
+ statusWarningComposedText: tokens.colorNeutral88,
201
200
  statusWarningComposedBackground: tokens.fillColorStatusWarningGhostDark,
202
- statusErrorComposedIcon: tokens.iconColorStatusErrorPrimaryDark,
203
- statusErrorComposedText: tokens.textColorStatusErrorDark,
201
+ statusErrorComposedIcon: tokens.textColorStatusErrorDark,
202
+ statusErrorComposedText: tokens.colorNeutral88,
204
203
  statusErrorComposedBackground: tokens.fillColorStatusErrorGhostDark,
205
- statusNeutralComposedIcon: tokens.iconColorStatusNeutralPrimaryDark,
206
- statusNeutralComposedText: tokens.textColorStatusNeutralDark,
204
+ statusNeutralComposedIcon: tokens.textColorStatusNeutralDark,
205
+ statusNeutralComposedText: tokens.colorNeutral88,
207
206
  statusNeutralComposedBackground: tokens.fillColorStatusNeutralGhostDark,
208
207
  borderColorChip: tokens.colorNeutral24,
209
208
  fillColorChip: 'transparent',
@@ -0,0 +1,62 @@
1
+ import { hashKey, QueryClient, QueryKey } from '@tanstack/react-query'
2
+ import { DebouncedFuncLeading, throttle } from 'lodash'
3
+
4
+ export const REFRESH_THROTTLE_MS = 3000
5
+
6
+ type Refresh = () => unknown
7
+
8
+ interface ThrottledRefresh {
9
+ run: DebouncedFuncLeading<(refresh: Refresh) => void>
10
+ lastEvent?: object
11
+ }
12
+
13
+ const refreshesByClient = new WeakMap<QueryClient, Map<string, ThrottledRefresh>>()
14
+
15
+ const refreshesFor = (queryClient: QueryClient) => {
16
+ const existing = refreshesByClient.get(queryClient)
17
+ if (existing) return existing
18
+
19
+ const refreshes = new Map<string, ThrottledRefresh>()
20
+ refreshesByClient.set(queryClient, refreshes)
21
+ return refreshes
22
+ }
23
+
24
+ const throttledRefreshFor = (queryClient: QueryClient, key: QueryKey) => {
25
+ const refreshes = refreshesFor(queryClient)
26
+ const hashedKey = hashKey(key)
27
+ const existing = refreshes.get(hashedKey)
28
+ if (existing) return existing
29
+
30
+ const created: ThrottledRefresh = {
31
+ run: throttle(
32
+ (refresh: Refresh) => {
33
+ refresh()
34
+ },
35
+ REFRESH_THROTTLE_MS,
36
+ { leading: true, trailing: true }
37
+ ),
38
+ }
39
+ refreshes.set(hashedKey, created)
40
+ return created
41
+ }
42
+
43
+ export const throttledRefresh = (
44
+ queryClient: QueryClient,
45
+ key: QueryKey,
46
+ event: object,
47
+ refresh: Refresh
48
+ ) => {
49
+ const throttled = throttledRefreshFor(queryClient, key)
50
+ if (throttled.lastEvent === event) return
51
+
52
+ throttled.lastEvent = event
53
+ throttled.run(refresh)
54
+ }
55
+
56
+ export const cancelThrottledRefreshes = (queryClient: QueryClient) => {
57
+ const refreshes = refreshesByClient.get(queryClient)
58
+ if (!refreshes) return
59
+
60
+ refreshes.forEach(({ run }) => run.cancel())
61
+ refreshesByClient.delete(queryClient)
62
+ }
@@ -1,313 +0,0 @@
1
- /**
2
- * Tests for Event/CustomEvent/EventTarget polyfills
3
- */
4
-
5
- import { CustomEvent } from '../polyfills/events/CustomEvent'
6
- // Set up global polyfill for tests
7
- import Event from '../polyfills/events/Event'
8
- import EventTarget from '../polyfills/events/EventTarget'
9
- ;(global as any).Event = Event
10
- ;(global as any).CustomEvent = CustomEvent
11
-
12
- describe('Event Polyfill', () => {
13
- describe('Event', () => {
14
- it('should create a basic event', () => {
15
- const event = new Event('test')
16
- expect(event.type).toBe('test')
17
- expect(event.bubbles).toBe(false)
18
- expect(event.cancelable).toBe(false)
19
- expect(event.composed).toBe(false)
20
- expect(event.defaultPrevented).toBe(false)
21
- expect(event.isTrusted).toBe(false)
22
- expect(event.eventPhase).toBe(Event.NONE)
23
- expect(typeof event.timeStamp).toBe('number')
24
- })
25
-
26
- it('should create an event with options', () => {
27
- const event = new Event('test', {
28
- bubbles: true,
29
- cancelable: true,
30
- composed: true,
31
- })
32
- expect(event.bubbles).toBe(true)
33
- expect(event.cancelable).toBe(true)
34
- expect(event.composed).toBe(true)
35
- })
36
-
37
- it('should have correct phase constants', () => {
38
- expect(Event.NONE).toBe(0)
39
- expect(Event.CAPTURING_PHASE).toBe(1)
40
- expect(Event.AT_TARGET).toBe(2)
41
- expect(Event.BUBBLING_PHASE).toBe(3)
42
- })
43
-
44
- it('should prevent default when cancelable', () => {
45
- const event = new Event('test', { cancelable: true })
46
- expect(event.defaultPrevented).toBe(false)
47
- event.preventDefault()
48
- expect(event.defaultPrevented).toBe(true)
49
- })
50
-
51
- it('should not prevent default when not cancelable', () => {
52
- const event = new Event('test', { cancelable: false })
53
- event.preventDefault()
54
- expect(event.defaultPrevented).toBe(false)
55
- })
56
-
57
- it('should support stopPropagation', () => {
58
- const event = new Event('test')
59
- // No error thrown - internal flags are set
60
- event.stopPropagation()
61
- event.stopImmediatePropagation()
62
- })
63
- })
64
-
65
- describe('CustomEvent', () => {
66
- it('should create a custom event with detail', () => {
67
- const detail = { foo: 'bar', count: 42 }
68
- const event = new CustomEvent('custom', { detail })
69
- expect(event.type).toBe('custom')
70
- expect(event.detail).toEqual(detail)
71
- })
72
-
73
- it('should inherit from Event', () => {
74
- const event = new CustomEvent('custom', {
75
- bubbles: true,
76
- cancelable: true,
77
- detail: 'test',
78
- })
79
- expect(event instanceof Event).toBe(true)
80
- expect(event.bubbles).toBe(true)
81
- expect(event.cancelable).toBe(true)
82
- })
83
-
84
- it('should handle undefined detail', () => {
85
- const event = new CustomEvent('custom')
86
- expect(event.detail).toBeUndefined()
87
- })
88
- })
89
-
90
- describe('EventTarget', () => {
91
- let target: EventTarget
92
-
93
- beforeEach(() => {
94
- target = new EventTarget()
95
- })
96
-
97
- it('should add and remove event listeners', () => {
98
- const listener = jest.fn()
99
- target.addEventListener('test', listener)
100
-
101
- const event = new Event('test')
102
- const result = target.dispatchEvent(event)
103
-
104
- expect(listener).toHaveBeenCalledWith(event)
105
- expect(listener).toHaveBeenCalledTimes(1)
106
- expect(result).toBe(true) // not prevented
107
-
108
- target.removeEventListener('test', listener)
109
- target.dispatchEvent(new Event('test'))
110
- expect(listener).toHaveBeenCalledTimes(1) // not called again
111
- })
112
-
113
- it('should handle multiple listeners for the same event', () => {
114
- const listener1 = jest.fn()
115
- const listener2 = jest.fn()
116
-
117
- target.addEventListener('test', listener1)
118
- target.addEventListener('test', listener2)
119
-
120
- target.dispatchEvent(new Event('test'))
121
-
122
- expect(listener1).toHaveBeenCalledTimes(1)
123
- expect(listener2).toHaveBeenCalledTimes(1)
124
- })
125
-
126
- it('should handle once option', () => {
127
- const listener = jest.fn()
128
- target.addEventListener('test', listener, { once: true })
129
-
130
- target.dispatchEvent(new Event('test'))
131
- target.dispatchEvent(new Event('test'))
132
-
133
- expect(listener).toHaveBeenCalledTimes(1)
134
- })
135
-
136
- it('should handle capture option', () => {
137
- const listener = jest.fn()
138
- target.addEventListener('test', listener, { capture: true })
139
-
140
- target.dispatchEvent(new Event('test'))
141
- expect(listener).toHaveBeenCalledTimes(1)
142
-
143
- target.removeEventListener('test', listener, { capture: true })
144
- target.dispatchEvent(new Event('test'))
145
- expect(listener).toHaveBeenCalledTimes(1)
146
- })
147
-
148
- it('should handle passive option', () => {
149
- const listener = jest.fn()
150
- target.addEventListener('test', listener, { passive: true })
151
-
152
- target.dispatchEvent(new Event('test'))
153
- expect(listener).toHaveBeenCalledTimes(1)
154
- })
155
-
156
- it('should handle object listeners with handleEvent', () => {
157
- const listener = {
158
- handleEvent: jest.fn(),
159
- }
160
-
161
- target.addEventListener('test', listener)
162
- target.dispatchEvent(new Event('test'))
163
-
164
- expect(listener.handleEvent).toHaveBeenCalledTimes(1)
165
- })
166
-
167
- it('should return false when event is prevented', () => {
168
- const listener = (event: Event) => {
169
- event.preventDefault()
170
- }
171
-
172
- target.addEventListener('test', listener)
173
- const event = new Event('test', { cancelable: true })
174
- const result = target.dispatchEvent(event)
175
-
176
- expect(result).toBe(false)
177
- expect(event.defaultPrevented).toBe(true)
178
- })
179
-
180
- it('should set event properties during dispatch', () => {
181
- let capturedEvent: Event | null = null
182
-
183
- const listener = (event: Event) => {
184
- capturedEvent = event
185
- expect(event.target).toBe(target)
186
- expect(event.currentTarget).toBe(target)
187
- expect(event.eventPhase).toBe(Event.AT_TARGET)
188
- }
189
-
190
- target.addEventListener('test', listener)
191
- target.dispatchEvent(new Event('test'))
192
-
193
- expect(capturedEvent).not.toBeNull()
194
- // After dispatch, these should be reset
195
- expect(capturedEvent!.currentTarget).toBeNull()
196
- expect(capturedEvent!.eventPhase).toBe(Event.NONE)
197
- })
198
-
199
- it('should handle bubbling events', () => {
200
- const listener = jest.fn()
201
- target.addEventListener('test', listener)
202
-
203
- const bubblingEvent = new Event('test', { bubbles: true })
204
- target.dispatchEvent(bubblingEvent)
205
-
206
- expect(listener).toHaveBeenCalledWith(bubblingEvent)
207
- })
208
-
209
- it('should handle error in listener gracefully', () => {
210
- const errorListener = () => {
211
- throw new Error('Test error')
212
- }
213
- const normalListener = jest.fn()
214
-
215
- // Mock console.error to avoid test output noise
216
- const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
217
-
218
- target.addEventListener('test', errorListener)
219
- target.addEventListener('test', normalListener)
220
-
221
- target.dispatchEvent(new Event('test'))
222
-
223
- expect(normalListener).toHaveBeenCalledTimes(1)
224
- expect(consoleErrorSpy).toHaveBeenCalled()
225
-
226
- consoleErrorSpy.mockRestore()
227
- })
228
-
229
- it('should ignore null listeners', () => {
230
- // Should not throw
231
- target.addEventListener('test', null)
232
- target.removeEventListener('test', null)
233
- target.dispatchEvent(new Event('test'))
234
- })
235
-
236
- it('should handle composed path', () => {
237
- let composedPath: readonly EventTarget[] | null = null
238
-
239
- const listener = (event: Event) => {
240
- composedPath = event.composedPath()
241
- }
242
-
243
- target.addEventListener('test', listener)
244
- target.dispatchEvent(new Event('test'))
245
-
246
- expect(composedPath).toEqual([target])
247
- })
248
-
249
- it('should prevent duplicate listeners', () => {
250
- const listener = jest.fn()
251
-
252
- target.addEventListener('test', listener)
253
- target.addEventListener('test', listener) // Same listener
254
-
255
- target.dispatchEvent(new Event('test'))
256
- expect(listener).toHaveBeenCalledTimes(1) // Only called once
257
- })
258
- })
259
-
260
- describe('Event flow integration', () => {
261
- it('should work with CustomEvent dispatch', () => {
262
- const target = new EventTarget()
263
- const listener = jest.fn()
264
- const detail = { message: 'hello' }
265
-
266
- target.addEventListener('custom', listener)
267
-
268
- const event = new CustomEvent('custom', {
269
- detail,
270
- bubbles: true,
271
- cancelable: true,
272
- })
273
-
274
- const result = target.dispatchEvent(event)
275
-
276
- expect(listener).toHaveBeenCalledWith(event)
277
- expect(listener.mock.calls[0][0].detail).toEqual(detail)
278
- expect(result).toBe(true)
279
- })
280
-
281
- it('should handle stopImmediatePropagation', () => {
282
- const target = new EventTarget()
283
- const listener1 = jest.fn((event: Event) => {
284
- event.stopImmediatePropagation()
285
- })
286
- const listener2 = jest.fn()
287
-
288
- target.addEventListener('test', listener1)
289
- target.addEventListener('test', listener2)
290
-
291
- target.dispatchEvent(new Event('test'))
292
-
293
- expect(listener1).toHaveBeenCalledTimes(1)
294
- expect(listener2).toHaveBeenCalledTimes(0) // Stopped
295
- })
296
- })
297
-
298
- describe('Global polyfill installation', () => {
299
- it('should make Event available globally', () => {
300
- // This tests that our polyfill setup works
301
- expect(typeof (global as any).Event).toBe('function')
302
- expect(typeof (global as any).CustomEvent).toBe('function')
303
-
304
- const globalEvent = new (global as any).Event('test')
305
- expect(globalEvent.type).toBe('test')
306
-
307
- const globalCustomEvent = new (global as any).CustomEvent('custom', {
308
- detail: 'test',
309
- })
310
- expect(globalCustomEvent.detail).toBe('test')
311
- })
312
- })
313
- })
@@ -1,5 +0,0 @@
1
- describe('Chat', () => {
2
- it('should do maths', () => {
3
- expect(1 + 1).toBe(2)
4
- })
5
- })
@@ -1,11 +0,0 @@
1
- import { jestTransformPackages } from '../jest'
2
-
3
- describe('jestTransformPackages', () => {
4
- it('exports an array of package patterns', () => {
5
- expect(jestTransformPackages).toEqual([
6
- '@planningcenter/chat-react-native',
7
- '@planningcenter/emoji-keyboard',
8
- '@fortawesome',
9
- ])
10
- })
11
- })
@@ -1,65 +0,0 @@
1
- import { Session, Uri } from '../../utils'
2
-
3
- describe('URI', () => {
4
- it('should be defined', () => {
5
- expect(Uri).toBeDefined()
6
- })
7
-
8
- it('should create a new instance', () => {
9
- const uri = new Uri({
10
- session: new Session({ env: 'production', type: 'OAuth' }),
11
- })
12
- expect(uri).toBeDefined()
13
- })
14
-
15
- describe('baseUrl', () => {
16
- describe('planning center', () => {
17
- it('should return the correct base URL for production', () => {
18
- const uri = new Uri({
19
- session: new Session({ env: 'production', type: 'OAuth' }),
20
- })
21
- expect(uri.baseUrl).toBe('https://api.planningcenteronline.com')
22
- })
23
-
24
- it('should return the correct base URL for staging', () => {
25
- const uri = new Uri({
26
- session: new Session({ env: 'staging', type: 'OAuth' }),
27
- })
28
- expect(uri.baseUrl).toBe('https://api-staging.planningcenteronline.com')
29
- })
30
-
31
- it('should return the correct base URL for development', () => {
32
- const uri = new Uri({
33
- session: new Session({ env: 'development', type: 'OAuth' }),
34
- })
35
- expect(uri.baseUrl).toBe('https://api.pco.test')
36
- })
37
- })
38
-
39
- describe('church center', () => {
40
- it('should return the correct base URL for production', () => {
41
- const uri = new Uri({
42
- session: new Session({ env: 'production', type: 'ChurchCenterOauth' }),
43
- graph: 'churchcenter',
44
- })
45
- expect(uri.baseUrl).toBe('https://api.churchcenter.com')
46
- })
47
-
48
- it('should return the correct base URL for staging', () => {
49
- const uri = new Uri({
50
- session: new Session({ env: 'staging', type: 'ChurchCenterOauth' }),
51
- graph: 'churchcenter',
52
- })
53
- expect(uri.baseUrl).toBe('https://api.staging.churchcenter.com')
54
- })
55
-
56
- it('should return the correct base URL for development', () => {
57
- const uri = new Uri({
58
- session: new Session({ env: 'development', type: 'ChurchCenterOauth' }),
59
- graph: 'churchcenter',
60
- })
61
- expect(uri.baseUrl).toBe('https://api.churchcenter.test')
62
- })
63
- })
64
- })
65
- })