@planningcenter/chat-react-native 3.21.2-rc.0 → 3.21.2-rc.2
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/contexts/chat_context.d.ts +3 -2
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js.map +1 -1
- package/build/hooks/services/use_team_members_for_new_conversation.d.ts +14 -14
- package/build/hooks/use_api.d.ts +41 -41
- package/build/hooks/use_api.d.ts.map +1 -1
- package/build/hooks/use_api.js.map +1 -1
- package/build/hooks/use_chat_permissions.d.ts +14 -14
- package/build/hooks/use_conversation.d.ts +3 -3
- package/build/hooks/use_groups.d.ts +26 -26
- package/build/hooks/use_groups_groups.d.ts +26 -26
- package/build/hooks/use_organization.d.ts +3 -3
- package/build/hooks/use_suspense_api.d.ts +5 -5
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/hooks/use_teams.d.ts +26 -26
- package/build/screens/conversation_filter_recipients/hooks/use_service_types_with_teams.d.ts +14 -14
- package/build/screens/conversation_filters/hooks/filters.d.ts +40 -40
- package/build/screens/design_system_screen.js +1 -1
- package/build/screens/design_system_screen.js.map +1 -1
- package/build/types/api_primitives.d.ts +1 -1
- package/build/types/api_primitives.d.ts.map +1 -1
- package/build/types/api_primitives.js.map +1 -1
- package/build/utils/client/client.d.ts +3 -6
- package/build/utils/client/client.d.ts.map +1 -1
- package/build/utils/client/client.js +2 -2
- package/build/utils/client/client.js.map +1 -1
- package/build/utils/response_error.d.ts +4 -4
- package/build/utils/response_error.d.ts.map +1 -1
- package/build/utils/response_error.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/utils/client.ts +2 -2
- package/src/contexts/chat_context.tsx +3 -2
- package/src/hooks/use_api.ts +3 -3
- package/src/hooks/use_suspense_api.ts +4 -4
- package/src/screens/design_system_screen.tsx +1 -1
- package/src/types/api_primitives.ts +1 -1
- package/src/utils/client/client.ts +7 -11
- package/src/utils/response_error.ts +5 -5
|
@@ -2,7 +2,7 @@ import MockServer from '../../__utils__/server'
|
|
|
2
2
|
import Client from '../../utils/client/client'
|
|
3
3
|
import DefaultFixtures from '../../__utils__/fixtures/defaults'
|
|
4
4
|
import { BASE_URL } from '../../__utils__/handlers'
|
|
5
|
-
import {
|
|
5
|
+
import { FailedResponse } from '../../types'
|
|
6
6
|
|
|
7
7
|
const APP_BASE_URL = BASE_URL
|
|
8
8
|
let client: Client
|
|
@@ -349,7 +349,7 @@ describe('error handling', () => {
|
|
|
349
349
|
const test401 = async ({ secretWord }: { secretWord: string }) => {
|
|
350
350
|
const url = '/records'
|
|
351
351
|
|
|
352
|
-
const expiredTokenResource: Partial<
|
|
352
|
+
const expiredTokenResource: Partial<FailedResponse> = {
|
|
353
353
|
errors: [
|
|
354
354
|
{
|
|
355
355
|
detail: `Zoinks, your token is borked ( ${secretWord} )`,
|
|
@@ -3,7 +3,8 @@ import React, { createContext, useMemo } from 'react'
|
|
|
3
3
|
import { ColorSchemeName, useColorScheme } from 'react-native'
|
|
4
4
|
import { useQuery } from '@tanstack/react-query'
|
|
5
5
|
import { ApiResource, DeepPartial } from '../types'
|
|
6
|
-
import { Client, ENV, OauthType, PartialToken,
|
|
6
|
+
import { Client, ENV, OauthType, PartialToken, Session, Uri } from '../utils'
|
|
7
|
+
import { FailedResponse } from '../types'
|
|
7
8
|
import { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'
|
|
8
9
|
import { AgeCheckContactInfo } from '../screens/age_check/screen_props'
|
|
9
10
|
import { ProductAnalyticsConfig } from '../types/product_analytics'
|
|
@@ -12,7 +13,7 @@ export interface ChatProviderProps {
|
|
|
12
13
|
env?: ENV
|
|
13
14
|
giphyApiKey?: string
|
|
14
15
|
onAgeDisqualification?: (params: AgeCheckContactInfo) => void
|
|
15
|
-
onUnauthorizedResponse: (_response:
|
|
16
|
+
onUnauthorizedResponse: (_response: FailedResponse) => void
|
|
16
17
|
token?: PartialToken
|
|
17
18
|
tokenType?: OauthType
|
|
18
19
|
theme: CreateChatThemeProps
|
package/src/hooks/use_api.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
useInfiniteQuery,
|
|
5
5
|
useQuery,
|
|
6
6
|
} from '@tanstack/react-query'
|
|
7
|
-
import { ApiCollection,
|
|
7
|
+
import { ApiCollection, ApiResource, FailedResponse, ResourceObject } from '../types'
|
|
8
8
|
import { GetRequest, RequestData } from '../utils/client'
|
|
9
9
|
import { App, useApiClient } from './use_api_client'
|
|
10
10
|
import { getRequestQueryKey, RequestQueryKey } from './use_suspense_api'
|
|
@@ -18,7 +18,7 @@ export const useApiGet = <T extends ResourceObject | ResourceObject[]>(args: Api
|
|
|
18
18
|
type Resource = ApiResource<T>
|
|
19
19
|
const apiClient = useApiClient()
|
|
20
20
|
|
|
21
|
-
const { data, ...query } = useQuery<Resource,
|
|
21
|
+
const { data, ...query } = useQuery<Resource, FailedResponse>({
|
|
22
22
|
queryKey: getRequestQueryKey(args),
|
|
23
23
|
queryFn: ({ queryKey }) => {
|
|
24
24
|
const [url, d, headers, app = 'chat'] = queryKey as RequestQueryKey
|
|
@@ -48,7 +48,7 @@ export const useApiPaginator = <T extends ResourceObject>(
|
|
|
48
48
|
const apiClient = useApiClient()
|
|
49
49
|
const query = useInfiniteQuery<
|
|
50
50
|
ApiCollection<T>,
|
|
51
|
-
|
|
51
|
+
FailedResponse,
|
|
52
52
|
InfiniteData<ApiCollection<T>>,
|
|
53
53
|
any,
|
|
54
54
|
Partial<RequestData> | undefined
|
|
@@ -9,7 +9,7 @@ import { ApiCollection, ApiResource, ResourceObject } from '../types'
|
|
|
9
9
|
import { GetRequest, RequestData } from '../utils/client'
|
|
10
10
|
import { App, useApiClient } from './use_api_client'
|
|
11
11
|
import { Log } from '../utils'
|
|
12
|
-
import {
|
|
12
|
+
import { FailedResponse } from '../types/api_primitives'
|
|
13
13
|
import { ResponseError } from '../utils/response_error'
|
|
14
14
|
|
|
15
15
|
interface SuspenseGetOptions extends GetRequest {
|
|
@@ -18,7 +18,7 @@ interface SuspenseGetOptions extends GetRequest {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export type SuspenseGetQueryOptions<T extends ResourceObject | ResourceObject[]> = Omit<
|
|
21
|
-
UseSuspenseQueryOptions<ApiResource<T>,
|
|
21
|
+
UseSuspenseQueryOptions<ApiResource<T>, FailedResponse>,
|
|
22
22
|
'queryKey' | 'queryFn'
|
|
23
23
|
>
|
|
24
24
|
|
|
@@ -29,7 +29,7 @@ export const useSuspenseGet = <T extends ResourceObject | ResourceObject[]>(
|
|
|
29
29
|
type Resource = ApiResource<T>
|
|
30
30
|
const apiClient = useApiClient()
|
|
31
31
|
|
|
32
|
-
const { data, ...query } = useSuspenseQuery<Resource,
|
|
32
|
+
const { data, ...query } = useSuspenseQuery<Resource, FailedResponse>({
|
|
33
33
|
queryKey: getRequestQueryKey(args),
|
|
34
34
|
queryFn: ({ queryKey }) => {
|
|
35
35
|
const [url, d, headers, app = 'chat'] = queryKey as RequestQueryKey
|
|
@@ -104,7 +104,7 @@ export const useSuspensePaginator = <T extends ResourceObject>(
|
|
|
104
104
|
|
|
105
105
|
const throwResponseError = (error: unknown) => {
|
|
106
106
|
if (error instanceof Response) {
|
|
107
|
-
throw new ResponseError(error as
|
|
107
|
+
throw new ResponseError(error as FailedResponse)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
return Promise.reject(error)
|
|
@@ -137,7 +137,7 @@ function ThemeSection({ isLast }: SectionProps) {
|
|
|
137
137
|
`CreateChatThemeProps`.
|
|
138
138
|
</Text>
|
|
139
139
|
<Text variant="footnote">
|
|
140
|
-
Example setup: `apps/
|
|
140
|
+
Example setup: `apps/sandbox/src/context/chat_context_provider.tsx`
|
|
141
141
|
</Text>
|
|
142
142
|
</TextRow>
|
|
143
143
|
<TextRow>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiCollection,
|
|
1
|
+
import { ApiCollection, ApiResource, FailedResponse } from '../../types'
|
|
2
2
|
import {
|
|
3
3
|
concatRecords,
|
|
4
4
|
ensureNoQueryParamsInDev,
|
|
@@ -10,11 +10,7 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import { DeleteRequest, GetRequest, PatchRequest, PostRequest, WalkRequest } from './types'
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
errors: ApiError['errors']
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type OnUnauthorizedResponse = (_response: ResponseError) => void
|
|
13
|
+
export type OnUnauthorizedResponse = (_response: FailedResponse) => void
|
|
18
14
|
|
|
19
15
|
type ClientArgs = {
|
|
20
16
|
version: string
|
|
@@ -112,19 +108,19 @@ export class Client {
|
|
|
112
108
|
|
|
113
109
|
handleNotOk = async (response: Response) => {
|
|
114
110
|
if (response.status === 401) {
|
|
115
|
-
const
|
|
111
|
+
const errorData = await this.parseErrorResponse(response)
|
|
116
112
|
this.onUnauthorizedResponse?.({
|
|
117
113
|
...response,
|
|
118
|
-
errors: errors || [],
|
|
119
|
-
})
|
|
114
|
+
errors: errorData.errors || [],
|
|
115
|
+
} as FailedResponse)
|
|
120
116
|
}
|
|
121
117
|
|
|
122
118
|
return Promise.reject(response)
|
|
123
119
|
}
|
|
124
120
|
|
|
125
|
-
parseErrorResponse = async (response: Response): Promise<Partial<
|
|
121
|
+
parseErrorResponse = async (response: Response): Promise<Partial<FailedResponse>> => {
|
|
126
122
|
try {
|
|
127
|
-
return (await response.clone().json()) as
|
|
123
|
+
return (await response.clone().json()) as FailedResponse
|
|
128
124
|
} catch {
|
|
129
125
|
return {}
|
|
130
126
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FailedResponse } from '../types/api_primitives'
|
|
2
2
|
|
|
3
3
|
export class ResponseError extends Error {
|
|
4
4
|
status: number
|
|
5
5
|
statusText: string
|
|
6
|
-
errors:
|
|
7
|
-
response:
|
|
6
|
+
errors: FailedResponse['errors']
|
|
7
|
+
response: FailedResponse
|
|
8
8
|
|
|
9
|
-
constructor(response:
|
|
9
|
+
constructor(response: FailedResponse) {
|
|
10
10
|
super(`ResponseError: ${response?.status} ${response?.statusText}`)
|
|
11
11
|
this.name = 'ResponseError'
|
|
12
12
|
this.status = response?.status
|
|
@@ -18,7 +18,7 @@ export class ResponseError extends Error {
|
|
|
18
18
|
|
|
19
19
|
export const throwResponseError = (error: unknown) => {
|
|
20
20
|
if (error instanceof Response) {
|
|
21
|
-
throw new ResponseError(error as
|
|
21
|
+
throw new ResponseError(error as FailedResponse)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
return Promise.reject(error)
|