@planningcenter/chat-react-native 4.6.4-qa-staging.3 → 4.6.4-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/build/contexts/api_provider.d.ts +0 -1
  2. package/build/contexts/api_provider.d.ts.map +1 -1
  3. package/build/contexts/api_provider.js +38 -50
  4. package/build/contexts/api_provider.js.map +1 -1
  5. package/build/contexts/chat_context.d.ts +0 -1
  6. package/build/contexts/chat_context.d.ts.map +1 -1
  7. package/build/contexts/chat_context.js +25 -28
  8. package/build/contexts/chat_context.js.map +1 -1
  9. package/build/contexts/session_context.d.ts +1 -2
  10. package/build/contexts/session_context.d.ts.map +1 -1
  11. package/build/contexts/session_context.js +6 -10
  12. package/build/contexts/session_context.js.map +1 -1
  13. package/build/hooks/index.d.ts +0 -1
  14. package/build/hooks/index.d.ts.map +1 -1
  15. package/build/hooks/index.js +0 -1
  16. package/build/hooks/index.js.map +1 -1
  17. package/build/screens/system_message_people_screen.d.ts.map +1 -1
  18. package/build/screens/system_message_people_screen.js +96 -33
  19. package/build/screens/system_message_people_screen.js.map +1 -1
  20. package/build/utils/session.d.ts +1 -3
  21. package/build/utils/session.d.ts.map +1 -1
  22. package/build/utils/session.js +0 -3
  23. package/build/utils/session.js.map +1 -1
  24. package/build/utils/session_manager.d.ts +1 -1
  25. package/build/utils/session_manager.d.ts.map +1 -1
  26. package/build/utils/session_manager.js +1 -2
  27. package/build/utils/session_manager.js.map +1 -1
  28. package/build/utils/upload_uri.d.ts.map +1 -1
  29. package/build/utils/upload_uri.js +0 -3
  30. package/build/utils/upload_uri.js.map +1 -1
  31. package/build/utils/uri.d.ts.map +1 -1
  32. package/build/utils/uri.js +0 -4
  33. package/build/utils/uri.js.map +1 -1
  34. package/package.json +3 -3
  35. package/src/contexts/__tests__/api_provider.test.tsx +4 -17
  36. package/src/contexts/api_provider.tsx +11 -25
  37. package/src/contexts/chat_context.tsx +2 -4
  38. package/src/contexts/session_context.tsx +10 -18
  39. package/src/hooks/index.ts +0 -1
  40. package/src/screens/system_message_people_screen.tsx +20 -6
  41. package/src/utils/__tests__/session_manager.test.ts +0 -12
  42. package/src/utils/session.ts +3 -11
  43. package/src/utils/session_manager.ts +1 -2
  44. package/src/utils/upload_uri.ts +0 -4
  45. package/src/utils/uri.ts +0 -5
  46. package/build/hooks/use_system_message_people.d.ts +0 -14
  47. package/build/hooks/use_system_message_people.d.ts.map +0 -1
  48. package/build/hooks/use_system_message_people.js +0 -101
  49. package/build/hooks/use_system_message_people.js.map +0 -1
  50. package/src/contexts/__tests__/configured_retry.test.ts +0 -39
  51. package/src/hooks/__tests__/use_system_message_people.test.tsx +0 -79
  52. package/src/hooks/use_system_message_people.ts +0 -55
  53. package/src/utils/__tests__/uri.test.ts +0 -26
@@ -12,7 +12,6 @@ import { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'
12
12
 
13
13
  export interface ChatProviderProps {
14
14
  env?: ENV
15
- prototypeName?: string
16
15
  giphyApiKey?: string
17
16
  onAgeDisqualification?: (params: AgeCheckContactInfo) => void
18
17
  onUnauthorizedResponse: (_response: FailedResponse) => void
@@ -46,7 +45,6 @@ export const ChatContext = createContext<ChatContextValue>({
46
45
  export function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {
47
46
  const {
48
47
  env,
49
- prototypeName,
50
48
  token,
51
49
  onAgeDisqualification = (_params: AgeCheckContactInfo) => {},
52
50
  onUnauthorizedResponse,
@@ -60,8 +58,8 @@ export function ChatProvider({ children, value }: { children: any; value: ChatPr
60
58
  setLiquidGlassCapability(liquidGlassEnabled)
61
59
  const theme = useCreateChatTheme(value.theme || {})
62
60
  const session = useMemo(
63
- () => new Session({ token, env, prototypeName, type: tokenType }),
64
- [env, prototypeName, token, tokenType]
61
+ () => new Session({ token, env, type: tokenType }),
62
+ [env, token, tokenType]
65
63
  )
66
64
 
67
65
  const productAnalyticsConfig = useProductAnalyticsConfig(session)
@@ -23,7 +23,7 @@ type Sessions = Record<string, string> // Key is session ID
23
23
 
24
24
  export type SessionContextValue = {
25
25
  env: ENV
26
- setEnv: (_env: ENV, _prototypeName?: string) => void
26
+ setEnv: (_env: ENV) => void
27
27
  session: Session
28
28
  sessions: Sessions
29
29
  token: OAuthToken | undefined
@@ -52,11 +52,7 @@ export type SessionContextConfig = {
52
52
  secureStorage: StorageAdapter // For sensitive data (tokens/sessions)
53
53
 
54
54
  // Functional callbacks
55
- refreshTokenFn: (params: {
56
- refresh_token: string
57
- env: ENV
58
- prototypeName?: string
59
- }) => Promise<OAuthToken>
55
+ refreshTokenFn: (params: { refresh_token: string; env: ENV }) => Promise<OAuthToken>
60
56
  onLogout: () => void | Promise<void>
61
57
 
62
58
  // Optional configuration
@@ -131,11 +127,9 @@ export function SessionContextProvider({
131
127
  if (!token?.refresh_token) {
132
128
  return Promise.reject(new Error('Refresh token is required'))
133
129
  }
134
- return refreshTokenFn({
135
- refresh_token: token.refresh_token,
136
- env: currentSession.env,
137
- prototypeName: currentSession.prototypeName,
138
- }).then(handleTokenUpdate)
130
+ return refreshTokenFn({ refresh_token: token.refresh_token, env: currentSession.env }).then(
131
+ handleTokenUpdate
132
+ )
139
133
  },
140
134
  onError: (t: Partial<FailedResponse>) => {
141
135
  handleRefreshFailed(t)
@@ -148,24 +142,22 @@ export function SessionContextProvider({
148
142
  }, [queryClient])
149
143
 
150
144
  const handleSetEnv = useCallback(
151
- async (_env: ENV, _prototypeName?: string) => {
145
+ async (_env: ENV) => {
152
146
  const updatedManager = SessionManager.hydrate(managerString)
153
147
  const session = updatedManager.currentSession
154
- const sameEnvironment = _env === session.env && _prototypeName === session.prototypeName
155
- if (sameEnvironment) return
148
+ if (_env === session.env) return
156
149
 
157
150
  const productionEnvironments = ['production', 'staging']
158
151
  const switchingToDevelopment =
159
152
  _env === 'development' && productionEnvironments.includes(session.env)
160
153
  const switchingToProduction = _env === 'production' && session.env === 'development'
161
- const switchingPrototype = _env === 'prototype' || session.env === 'prototype'
162
154
 
163
- if (switchingToDevelopment || switchingToProduction || switchingPrototype) {
164
- const newSession = new Session({ env: _env, prototypeName: _prototypeName })
155
+ if (switchingToDevelopment || switchingToProduction) {
156
+ const newSession = new Session({ env: _env })
165
157
  updatedManager.upsertSession(newSession)
166
158
  }
167
159
 
168
- updatedManager.setEnv(_env, _prototypeName)
160
+ updatedManager.setEnv(_env)
169
161
  await setManagerString(updatedManager.toString())
170
162
  },
171
163
  [managerString, setManagerString]
@@ -29,5 +29,4 @@ export * from './use_reduce_motion'
29
29
  export * from './use_scalable_number_of_lines'
30
30
  export * from './use_submit_age_check'
31
31
  export * from './use_suspense_api'
32
- export * from './use_system_message_people'
33
32
  export * from './use_theme'
@@ -5,7 +5,8 @@ import { FlatList } from 'react-native-gesture-handler'
5
5
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
6
6
  import { Avatar, Text } from '../components'
7
7
  import FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet'
8
- import { SystemMessagePerson, useSystemMessagePeople } from '../hooks/use_system_message_people'
8
+ import { useSuspenseGet } from '../hooks'
9
+ import { MemberResource } from '../types'
9
10
 
10
11
  export const SystemMessagePeopleScreenOptions = getFormSheetScreenOptions({
11
12
  sheetAllowedDetents: Platform.select({
@@ -24,15 +25,26 @@ export function SystemMessagePeopleScreen({ route }: SystemMessagePeopleScreenPr
24
25
  const { conversation_id, person_ids } = route.params
25
26
  const styles = useStyles()
26
27
 
27
- const { data: people } = useSystemMessagePeople({
28
- conversationId: conversation_id,
29
- personIds: person_ids,
28
+ const { data: members } = useSuspenseGet<MemberResource[]>({
29
+ url: `/me/conversations/${conversation_id}/members`,
30
+ data: {
31
+ fields: {
32
+ Member: ['id', 'name', 'avatar'],
33
+ },
34
+ where: {
35
+ id: person_ids,
36
+ },
37
+ limit: person_ids.length,
38
+ },
30
39
  })
31
40
 
41
+ const orderById = Object.fromEntries(person_ids.map((id, i) => [id, i]))
42
+ const sortedMembers = [...members].sort((a, b) => (orderById[a.id] ?? 0) - (orderById[b.id] ?? 0))
43
+
32
44
  return (
33
45
  <FormSheet.Root contentStyle={styles.formSheetContent}>
34
46
  <FlatList
35
- data={people}
47
+ data={sortedMembers}
36
48
  contentContainerStyle={styles.contentContainer}
37
49
  keyExtractor={item => item.id.toString()}
38
50
  renderItem={({ item }) => <Person person={item} />}
@@ -41,7 +53,9 @@ export function SystemMessagePeopleScreen({ route }: SystemMessagePeopleScreenPr
41
53
  )
42
54
  }
43
55
 
44
- const Person = memo(({ person }: { person: SystemMessagePerson }) => {
56
+ type PersonProps = Pick<MemberResource, 'id' | 'name' | 'avatar'>
57
+
58
+ const Person = memo(({ person }: { person: PersonProps }) => {
45
59
  const styles = useStyles()
46
60
 
47
61
  return (
@@ -110,18 +110,6 @@ describe('SessionManager', () => {
110
110
  expect(manager.currentSession.id).toBe(UNAUTHENTICATED_SESSION_ID)
111
111
  expect(manager.sessions).toHaveProperty(UNAUTHENTICATED_SESSION_ID)
112
112
  })
113
-
114
- it('keeps the Protonova environment name only while on Protonova', () => {
115
- const manager = new SessionManager()
116
-
117
- manager.setEnv('prototype', 'chat-812')
118
- expect(SessionManager.hydrate(manager.toString()).currentSession.prototypeName).toBe(
119
- 'chat-812'
120
- )
121
-
122
- manager.setEnv('production', 'chat-812')
123
- expect(manager.currentSession.prototypeName).toBeUndefined()
124
- })
125
113
  })
126
114
 
127
115
  describe('upsertSession', () => {
@@ -1,6 +1,6 @@
1
1
  import { OAuthToken, OrganizationResource, PersonResource } from '../types'
2
2
 
3
- export type ENV = 'production' | 'staging' | 'development' | 'prototype'
3
+ export type ENV = 'production' | 'staging' | 'development'
4
4
  export type OauthType = 'OAuth' | 'ChurchCenterOauth'
5
5
  export type PartialToken = Pick<OAuthToken, 'access_token'> & Partial<OAuthToken>
6
6
  export type SessionMeta = {
@@ -11,7 +11,6 @@ export type SessionMeta = {
11
11
  }
12
12
  export type SessionProps<T extends PartialToken> = {
13
13
  env?: ENV
14
- prototypeName?: string
15
14
  token?: T
16
15
  type?: OauthType
17
16
  meta?: SessionMeta
@@ -26,15 +25,13 @@ type SessionId = string | typeof UNAUTHENTICATED_SESSION_ID
26
25
  */
27
26
  export class Session<T extends PartialToken = PartialToken> {
28
27
  env: ENV
29
- prototypeName: string | undefined
30
28
  token: T | undefined
31
29
  type: OauthType
32
30
  meta: Record<string, any>
33
31
 
34
32
  constructor(props?: SessionProps<T>) {
35
- const { env = 'production', prototypeName, token, type, meta } = props || {}
33
+ const { env = 'production', token, type, meta } = props || {}
36
34
  this.env = env
37
- this.prototypeName = env === 'prototype' ? prototypeName : undefined
38
35
  this.token = token
39
36
  this.type = type || 'OAuth'
40
37
  this.meta = meta || {}
@@ -57,12 +54,7 @@ export class Session<T extends PartialToken = PartialToken> {
57
54
  }
58
55
 
59
56
  toString() {
60
- return JSON.stringify({
61
- env: this.env,
62
- prototypeName: this.prototypeName,
63
- token: this.token,
64
- meta: this.meta,
65
- })
57
+ return JSON.stringify({ env: this.env, token: this.token, meta: this.meta })
66
58
  }
67
59
 
68
60
  // Convenience methods to set the person and organization
@@ -32,11 +32,10 @@ export class SessionManager {
32
32
  )
33
33
  }
34
34
 
35
- setEnv(env: ENV, prototypeName?: string) {
35
+ setEnv(env: ENV) {
36
36
  // Get the current session (handles case where it doesn't exist)
37
37
  const session = this.currentSession
38
38
  session.env = env
39
- session.prototypeName = prototypeName
40
39
  // Store the session with its ID
41
40
  this.upsertSession(session)
42
41
  }
@@ -23,10 +23,6 @@ export class UploadUri {
23
23
  }
24
24
 
25
25
  get host() {
26
- if (this.env === 'prototype') {
27
- return `${this.session.prototypeName}.upload.planningcenter.ninja`
28
- }
29
-
30
26
  return `${this.subdomain}.${this.domain}.${this.tld}`
31
27
  }
32
28
 
package/src/utils/uri.ts CHANGED
@@ -24,11 +24,6 @@ export class Uri {
24
24
  }
25
25
 
26
26
  get host() {
27
- if (this.env === 'prototype') {
28
- const graphDomain = this.isChurchCenter ? 'churchcenter' : 'planningcenter'
29
- return `${this.session.prototypeName}.api.${graphDomain}.ninja`
30
- }
31
-
32
27
  return `${this.subdomain}.${this.domain}.${this.tld}`
33
28
  }
34
29
 
@@ -1,14 +0,0 @@
1
- import { MemberResource } from '../types';
2
- import { GetRequest } from '../utils/client';
3
- export declare const MEMBERS_PER_REQUEST = 100;
4
- type SystemMessagePeopleArgs = {
5
- conversationId: number;
6
- personIds: number[];
7
- };
8
- export type SystemMessagePerson = Pick<MemberResource, 'type' | 'id' | 'name' | 'avatar'>;
9
- export declare const systemMessagePeopleRequest: (conversationId: number, personIds: number[]) => GetRequest;
10
- export declare const useSystemMessagePeople: ({ conversationId, personIds }: SystemMessagePeopleArgs) => {
11
- data: SystemMessagePerson[];
12
- };
13
- export {};
14
- //# sourceMappingURL=use_system_message_people.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use_system_message_people.d.ts","sourceRoot":"","sources":["../../src/hooks/use_system_message_people.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,cAAc,EAAE,MAAM,UAAU,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAK5C,eAAO,MAAM,mBAAmB,MAAM,CAAA;AAEtC,KAAK,uBAAuB,GAAG;IAC7B,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAA;AAEzF,eAAO,MAAM,0BAA0B,GACrC,gBAAgB,MAAM,EACtB,WAAW,MAAM,EAAE,KAClB,UAWD,CAAA;AAEF,eAAO,MAAM,sBAAsB,GAAI,+BAA+B,uBAAuB;;CAqB5F,CAAA"}
@@ -1,101 +0,0 @@
1
- import { c as _c } from "react/compiler-runtime";
2
- import { useSuspenseQueries } from '@tanstack/react-query';
3
- import { chunk, sortBy } from 'lodash';
4
- import { throwResponseError } from '../utils/response_error';
5
- import { useApiClient } from './use_api_client';
6
- import { getRequestQueryKey } from './use_suspense_api';
7
- export const MEMBERS_PER_REQUEST = 100;
8
- export const systemMessagePeopleRequest = (conversationId, personIds) => ({
9
- url: `/me/conversations/${conversationId}/members`,
10
- data: {
11
- fields: {
12
- Member: ['id', 'name', 'avatar']
13
- },
14
- where: {
15
- id: personIds
16
- },
17
- perPage: MEMBERS_PER_REQUEST
18
- }
19
- });
20
- export const useSystemMessagePeople = t0 => {
21
- const $ = _c(16);
22
- const {
23
- conversationId,
24
- personIds
25
- } = t0;
26
- const apiClient = useApiClient();
27
- let t1;
28
- let t2;
29
- if ($[0] !== apiClient || $[1] !== conversationId || $[2] !== personIds) {
30
- let t3;
31
- if ($[5] !== conversationId) {
32
- t3 = ids => systemMessagePeopleRequest(conversationId, ids);
33
- $[5] = conversationId;
34
- $[6] = t3;
35
- } else {
36
- t3 = $[6];
37
- }
38
- const requests = chunk(personIds, MEMBERS_PER_REQUEST).map(t3);
39
- t2 = useSuspenseQueries;
40
- let t4;
41
- if ($[7] !== apiClient) {
42
- t4 = request => ({
43
- queryKey: getRequestQueryKey(request),
44
- queryFn: () => apiClient.chat.get(request).catch(throwResponseError)
45
- });
46
- $[7] = apiClient;
47
- $[8] = t4;
48
- } else {
49
- t4 = $[8];
50
- }
51
- t1 = requests.map(t4);
52
- $[0] = apiClient;
53
- $[1] = conversationId;
54
- $[2] = personIds;
55
- $[3] = t1;
56
- $[4] = t2;
57
- } else {
58
- t1 = $[3];
59
- t2 = $[4];
60
- }
61
- let t3;
62
- if ($[9] !== t1) {
63
- t3 = {
64
- queries: t1
65
- };
66
- $[9] = t1;
67
- $[10] = t3;
68
- } else {
69
- t3 = $[10];
70
- }
71
- const queries = t2(t3);
72
- let t4;
73
- if ($[11] !== personIds || $[12] !== queries) {
74
- const orderById = Object.fromEntries(personIds.map(_temp));
75
- t4 = sortBy(queries.flatMap(_temp2), person => orderById[person.id] ?? personIds.length);
76
- $[11] = personIds;
77
- $[12] = queries;
78
- $[13] = t4;
79
- } else {
80
- t4 = $[13];
81
- }
82
- const people = t4;
83
- let t5;
84
- if ($[14] !== people) {
85
- t5 = {
86
- data: people
87
- };
88
- $[14] = people;
89
- $[15] = t5;
90
- } else {
91
- t5 = $[15];
92
- }
93
- return t5;
94
- };
95
- function _temp(id, index) {
96
- return [id, index];
97
- }
98
- function _temp2(query) {
99
- return query.data.data;
100
- }
101
- //# sourceMappingURL=use_system_message_people.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use_system_message_people.js","names":["useSuspenseQueries","chunk","sortBy","throwResponseError","useApiClient","getRequestQueryKey","MEMBERS_PER_REQUEST","systemMessagePeopleRequest","conversationId","personIds","url","data","fields","Member","where","id","perPage","useSystemMessagePeople","t0","$","_c","apiClient","t1","t2","t3","ids","requests","map","t4","request","queryKey","queryFn","chat","get","catch","queries","orderById","Object","fromEntries","_temp","flatMap","_temp2","person","length","people","t5","index","query"],"sources":["../../src/hooks/use_system_message_people.ts"],"sourcesContent":["import { useSuspenseQueries } from '@tanstack/react-query'\nimport { chunk, sortBy } from 'lodash'\nimport { ApiCollection, MemberResource } from '../types'\nimport { GetRequest } from '../utils/client'\nimport { throwResponseError } from '../utils/response_error'\nimport { useApiClient } from './use_api_client'\nimport { getRequestQueryKey } from './use_suspense_api'\n\nexport const MEMBERS_PER_REQUEST = 100\n\ntype SystemMessagePeopleArgs = {\n conversationId: number\n personIds: number[]\n}\n\nexport type SystemMessagePerson = Pick<MemberResource, 'type' | 'id' | 'name' | 'avatar'>\n\nexport const systemMessagePeopleRequest = (\n conversationId: number,\n personIds: number[]\n): GetRequest => ({\n url: `/me/conversations/${conversationId}/members`,\n data: {\n fields: {\n Member: ['id', 'name', 'avatar'],\n },\n where: {\n id: personIds,\n },\n perPage: MEMBERS_PER_REQUEST,\n },\n})\n\nexport const useSystemMessagePeople = ({ conversationId, personIds }: SystemMessagePeopleArgs) => {\n const apiClient = useApiClient()\n const requests = chunk(personIds, MEMBERS_PER_REQUEST).map(ids =>\n systemMessagePeopleRequest(conversationId, ids)\n )\n\n const queries = useSuspenseQueries({\n queries: requests.map(request => ({\n queryKey: getRequestQueryKey(request),\n queryFn: (): Promise<ApiCollection<SystemMessagePerson>> =>\n apiClient.chat.get<ApiCollection<SystemMessagePerson>>(request).catch(throwResponseError),\n })),\n })\n\n const orderById = Object.fromEntries(personIds.map((id, index) => [id, index]))\n const people = sortBy(\n queries.flatMap(query => query.data.data),\n person => orderById[person.id] ?? personIds.length\n )\n\n return { data: people }\n}\n"],"mappings":";AAAA,SAASA,kBAAkB,QAAQ,uBAAuB;AAC1D,SAASC,KAAK,EAAEC,MAAM,QAAQ,QAAQ;AAGtC,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB;AAEvD,OAAO,MAAMC,mBAAmB,GAAG,GAAG;AAStC,OAAO,MAAMC,0BAA0B,GAAGA,CACxCC,cAAsB,EACtBC,SAAmB,MACH;EAChBC,GAAG,EAAE,qBAAqBF,cAAc,UAAU;EAClDG,IAAI,EAAE;IACJC,MAAM,EAAE;MACNC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ;IACjC,CAAC;IACDC,KAAK,EAAE;MACLC,EAAE,EAAEN;IACN,CAAC;IACDO,OAAO,EAAEV;EACX;AACF,CAAC,CAAC;AAEF,OAAO,MAAMW,sBAAsB,GAAGC,EAAA;EAAA,MAAAC,CAAA,GAAAC,EAAA;EAAC;IAAAZ,cAAA;IAAAC;EAAA,IAAAS,EAAsD;EAC3F,MAAAG,SAAA,GAAkBjB,YAAY,CAAC,CAAC;EAAA,IAAAkB,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAJ,CAAA,QAAAE,SAAA,IAAAF,CAAA,QAAAX,cAAA,IAAAW,CAAA,QAAAV,SAAA;IAAA,IAAAe,EAAA;IAAA,IAAAL,CAAA,QAAAX,cAAA;MAC2BgB,EAAA,GAAAC,GAAA,IACzDlB,0BAA0B,CAACC,cAAc,EAAEiB,GAAG,CAAC;MAAAN,CAAA,MAAAX,cAAA;MAAAW,CAAA,MAAAK,EAAA;IAAA;MAAAA,EAAA,GAAAL,CAAA;IAAA;IADjD,MAAAO,QAAA,GAAiBzB,KAAK,CAACQ,SAAS,EAAEH,mBAAmB,CAAC,CAAAqB,GAAI,CAACH,EAE3D,CAAC;IAEexB,EAAA,CAAAA,CAAA,CAAAA,kBAAkB;IAAA,IAAA4B,EAAA;IAAA,IAAAT,CAAA,QAAAE,SAAA;MACVO,EAAA,GAAAC,OAAA,KAAY;QAAAC,QAAA,EACtBzB,kBAAkB,CAACwB,OAAO,CAAC;QAAAE,OAAA,EAC5BA,CAAA,KACPV,SAAS,CAAAW,IAAK,CAAAC,GAAI,CAAqCJ,OAAO,CAAC,CAAAK,KAAM,CAAC/B,kBAAkB;MAC5F,CAAC,CAAC;MAAAgB,CAAA,MAAAE,SAAA;MAAAF,CAAA,MAAAS,EAAA;IAAA;MAAAA,EAAA,GAAAT,CAAA;IAAA;IAJOG,EAAA,GAAAI,QAAQ,CAAAC,GAAI,CAACC,EAIpB,CAAC;IAAAT,CAAA,MAAAE,SAAA;IAAAF,CAAA,MAAAX,cAAA;IAAAW,CAAA,MAAAV,SAAA;IAAAU,CAAA,MAAAG,EAAA;IAAAH,CAAA,MAAAI,EAAA;EAAA;IAAAD,EAAA,GAAAH,CAAA;IAAAI,EAAA,GAAAJ,CAAA;EAAA;EAAA,IAAAK,EAAA;EAAA,IAAAL,CAAA,QAAAG,EAAA;IAL8BE,EAAA;MAAAW,OAAA,EACxBb;IAKX,CAAC;IAAAH,CAAA,MAAAG,EAAA;IAAAH,CAAA,OAAAK,EAAA;EAAA;IAAAA,EAAA,GAAAL,CAAA;EAAA;EAND,MAAAgB,OAAA,GAAgBnC,EAAkB,CAACwB,EAMlC,CAAC;EAAA,IAAAI,EAAA;EAAA,IAAAT,CAAA,SAAAV,SAAA,IAAAU,CAAA,SAAAgB,OAAA;IAEF,MAAAC,SAAA,GAAkBC,MAAM,CAAAC,WAAY,CAAC7B,SAAS,CAAAkB,GAAI,CAACY,KAA0B,CAAC,CAAC;IAChEX,EAAA,GAAA1B,MAAM,CACnBiC,OAAO,CAAAK,OAAQ,CAACC,MAAwB,CAAC,EACzCC,MAAA,IAAUN,SAAS,CAACM,MAAM,CAAA3B,EAAG,CAAqB,IAAhBN,SAAS,CAAAkC,MAC7C,CAAC;IAAAxB,CAAA,OAAAV,SAAA;IAAAU,CAAA,OAAAgB,OAAA;IAAAhB,CAAA,OAAAS,EAAA;EAAA;IAAAA,EAAA,GAAAT,CAAA;EAAA;EAHD,MAAAyB,MAAA,GAAehB,EAGd;EAAA,IAAAiB,EAAA;EAAA,IAAA1B,CAAA,SAAAyB,MAAA;IAEMC,EAAA;MAAAlC,IAAA,EAAQiC;IAAO,CAAC;IAAAzB,CAAA,OAAAyB,MAAA;IAAAzB,CAAA,OAAA0B,EAAA;EAAA;IAAAA,EAAA,GAAA1B,CAAA;EAAA;EAAA,OAAhB0B,EAAgB;AAAA,CACxB;AArBqC,SAAAN,MAAAxB,EAAA,EAAA+B,KAAA;EAAA,OAc8B,CAAC/B,EAAE,EAAE+B,KAAK,CAAC;AAAA;AAdzC,SAAAL,OAAAM,KAAA;EAAA,OAgBTA,KAAK,CAAApC,IAAK,CAAAA,IAAK;AAAA","ignoreList":[]}
@@ -1,39 +0,0 @@
1
- import { ResponseError } from '../../utils/response_error'
2
- import { configuredRetry } from '../api_provider'
3
-
4
- jest.mock('../../hooks/use_api_client')
5
-
6
- const responseWithStatus = (status: number) =>
7
- ({
8
- status,
9
- statusText: 'Error',
10
- ok: false,
11
- url: 'https://api.pco.test/chat/v2/me',
12
- headers: {},
13
- clone: () => ({}),
14
- json: () => Promise.resolve({}),
15
- text: () => Promise.resolve(''),
16
- arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
17
- errors: [],
18
- }) as unknown as Response
19
-
20
- describe('configuredRetry', () => {
21
- it('does not retry client errors', () => {
22
- ;[400, 404, 414, 422, 429].forEach(status => {
23
- expect(configuredRetry(0, new ResponseError(responseWithStatus(status) as any))).toBe(false)
24
- expect(configuredRetry(0, responseWithStatus(status))).toBe(false)
25
- })
26
- })
27
-
28
- it('retries server errors up to three times', () => {
29
- const error = new ResponseError(responseWithStatus(503) as any)
30
-
31
- expect(configuredRetry(0, error)).toBe(true)
32
- expect(configuredRetry(2, error)).toBe(true)
33
- expect(configuredRetry(3, error)).toBe(false)
34
- })
35
-
36
- it('retries network failures', () => {
37
- expect(configuredRetry(0, new TypeError('Network request failed'))).toBe(true)
38
- })
39
- })
@@ -1,79 +0,0 @@
1
- import { notifyManager, QueryClient, QueryClientProvider } from '@tanstack/react-query'
2
- import { act, renderHook, waitFor } from '@testing-library/react-native'
3
- import React, { Suspense } from 'react'
4
- import { MEMBERS_PER_REQUEST, useSystemMessagePeople } from '../use_system_message_people'
5
-
6
- const mockGet = jest.fn()
7
- jest.mock('../use_api_client', () => ({
8
- useApiClient: () => ({ chat: { get: mockGet } }),
9
- }))
10
-
11
- notifyManager.setNotifyFunction(fn => act(fn))
12
-
13
- const conversationId = 7
14
-
15
- const member = (id: number) => ({ type: 'Member', id, name: `Person ${id}`, avatar: '' })
16
-
17
- const membersPage = (ids: number[]) => ({
18
- data: ids.map(member),
19
- links: {},
20
- meta: { count: ids.length, totalCount: ids.length },
21
- })
22
-
23
- const requestedIds = () => mockGet.mock.calls.map(([request]) => request.data.where.id as number[])
24
-
25
- const render = (personIds: number[]) => {
26
- const queryClient = new QueryClient({
27
- defaultOptions: { queries: { retry: false, gcTime: 0 } },
28
- })
29
- const wrapper = ({ children }: { children: React.ReactNode }) => (
30
- <QueryClientProvider client={queryClient}>
31
- <Suspense fallback={null}>{children}</Suspense>
32
- </QueryClientProvider>
33
- )
34
-
35
- return renderHook(() => useSystemMessagePeople({ conversationId, personIds }), { wrapper })
36
- }
37
-
38
- beforeEach(() => {
39
- mockGet.mockReset()
40
- mockGet.mockImplementation(({ data }) =>
41
- Promise.resolve(membersPage([...(data.where.id as number[])].reverse()))
42
- )
43
- })
44
-
45
- describe('useSystemMessagePeople', () => {
46
- it('requests members in batches no larger than a page', async () => {
47
- const personIds = Array.from({ length: 250 }, (_, i) => i + 1)
48
-
49
- render(personIds)
50
-
51
- await waitFor(() => expect(mockGet).toHaveBeenCalledTimes(3))
52
-
53
- expect(requestedIds().map(ids => ids.length)).toEqual([100, 100, 50])
54
- expect(requestedIds().flat()).toEqual(personIds)
55
- mockGet.mock.calls.forEach(([request]) => {
56
- expect(request.url).toEqual(`/me/conversations/${conversationId}/members`)
57
- expect(request.data.perPage).toEqual(MEMBERS_PER_REQUEST)
58
- })
59
- })
60
-
61
- it('returns everyone in the order of the system message', async () => {
62
- const personIds = Array.from({ length: 150 }, (_, i) => 1000 - i)
63
-
64
- const { result } = render(personIds)
65
-
66
- await waitFor(() => expect(result.current?.data).toHaveLength(150))
67
-
68
- expect(result.current.data.map(({ id }) => id)).toEqual(personIds)
69
- })
70
-
71
- it('makes a single request for a small list', async () => {
72
- const { result } = render([3, 1, 2])
73
-
74
- await waitFor(() => expect(result.current?.data).toHaveLength(3))
75
-
76
- expect(mockGet).toHaveBeenCalledTimes(1)
77
- expect(result.current.data.map(({ id }) => id)).toEqual([3, 1, 2])
78
- })
79
- })
@@ -1,55 +0,0 @@
1
- import { useSuspenseQueries } from '@tanstack/react-query'
2
- import { chunk, sortBy } from 'lodash'
3
- import { ApiCollection, MemberResource } from '../types'
4
- import { GetRequest } from '../utils/client'
5
- import { throwResponseError } from '../utils/response_error'
6
- import { useApiClient } from './use_api_client'
7
- import { getRequestQueryKey } from './use_suspense_api'
8
-
9
- export const MEMBERS_PER_REQUEST = 100
10
-
11
- type SystemMessagePeopleArgs = {
12
- conversationId: number
13
- personIds: number[]
14
- }
15
-
16
- export type SystemMessagePerson = Pick<MemberResource, 'type' | 'id' | 'name' | 'avatar'>
17
-
18
- export const systemMessagePeopleRequest = (
19
- conversationId: number,
20
- personIds: number[]
21
- ): GetRequest => ({
22
- url: `/me/conversations/${conversationId}/members`,
23
- data: {
24
- fields: {
25
- Member: ['id', 'name', 'avatar'],
26
- },
27
- where: {
28
- id: personIds,
29
- },
30
- perPage: MEMBERS_PER_REQUEST,
31
- },
32
- })
33
-
34
- export const useSystemMessagePeople = ({ conversationId, personIds }: SystemMessagePeopleArgs) => {
35
- const apiClient = useApiClient()
36
- const requests = chunk(personIds, MEMBERS_PER_REQUEST).map(ids =>
37
- systemMessagePeopleRequest(conversationId, ids)
38
- )
39
-
40
- const queries = useSuspenseQueries({
41
- queries: requests.map(request => ({
42
- queryKey: getRequestQueryKey(request),
43
- queryFn: (): Promise<ApiCollection<SystemMessagePerson>> =>
44
- apiClient.chat.get<ApiCollection<SystemMessagePerson>>(request).catch(throwResponseError),
45
- })),
46
- })
47
-
48
- const orderById = Object.fromEntries(personIds.map((id, index) => [id, index]))
49
- const people = sortBy(
50
- queries.flatMap(query => query.data.data),
51
- person => orderById[person.id] ?? personIds.length
52
- )
53
-
54
- return { data: people }
55
- }
@@ -1,26 +0,0 @@
1
- import { Session } from '../session'
2
- import { UploadUri } from '../upload_uri'
3
- import { Uri } from '../uri'
4
-
5
- const prototypeSession = (type?: 'OAuth' | 'ChurchCenterOauth') =>
6
- new Session({ env: 'prototype', prototypeName: 'chat-812', type })
7
-
8
- describe('on a Protonova environment', () => {
9
- it('sends Planning Center requests to the environment', () => {
10
- const uri = new Uri({ session: prototypeSession('OAuth'), app: 'chat' })
11
-
12
- expect(uri.appUrl('/me')).toBe('https://chat-812.api.planningcenter.ninja/chat/v2/me')
13
- })
14
-
15
- it('sends Church Center requests to the environment', () => {
16
- const uri = new Uri({ session: prototypeSession('ChurchCenterOauth'), app: 'chat' })
17
-
18
- expect(uri.appUrl('/me')).toBe('https://chat-812.api.churchcenter.ninja/chat/v2/me')
19
- })
20
-
21
- it('uploads to the environment', () => {
22
- expect(new UploadUri({ session: prototypeSession() }).baseUrl).toBe(
23
- 'https://chat-812.upload.planningcenter.ninja'
24
- )
25
- })
26
- })