@planningcenter/chat-react-native 3.4.1-rc.10 → 3.4.1-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/page/error_boundary.d.ts.map +1 -1
- package/build/components/page/error_boundary.js +4 -3
- package/build/components/page/error_boundary.js.map +1 -1
- package/build/contexts/chat_context.d.ts +7 -6
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +2 -2
- package/build/contexts/chat_context.js.map +1 -1
- package/build/hooks/use_conversation.d.ts +4 -4
- package/build/hooks/use_suspense_api.d.ts +6 -5
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +16 -3
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/index.d.ts +6 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -4
- package/build/index.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/native_adapters/configuration.d.ts +8 -5
- package/build/utils/native_adapters/configuration.d.ts.map +1 -1
- package/build/utils/native_adapters/configuration.js +7 -5
- 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/log.d.ts +15 -0
- package/build/utils/native_adapters/log.d.ts.map +1 -0
- package/build/utils/native_adapters/log.js +21 -0
- package/build/utils/native_adapters/log.js.map +1 -0
- package/build/utils/response_error.d.ts +9 -0
- package/build/utils/response_error.d.ts.map +1 -0
- package/build/utils/response_error.js +15 -0
- package/build/utils/response_error.js.map +1 -0
- package/package.json +2 -2
- package/src/components/page/error_boundary.tsx +4 -3
- package/src/contexts/chat_context.tsx +12 -8
- package/src/hooks/use_suspense_api.ts +23 -7
- package/src/index.tsx +6 -12
- package/src/types/api_primitives.ts +1 -1
- package/src/utils/native_adapters/configuration.ts +8 -5
- package/src/utils/native_adapters/index.ts +1 -0
- package/src/utils/native_adapters/log.ts +29 -0
- package/src/utils/response_error.ts +17 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_boundary.d.ts","sourceRoot":"","sources":["../../../src/components/page/error_boundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAsB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"error_boundary.d.ts","sourceRoot":"","sources":["../../../src/components/page/error_boundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAsB,MAAM,OAAO,CAAA;AAOpE,KAAK,kBAAkB,GAAG;IACxB,KAAK,EAAE,QAAQ,GAAG,KAAK,GAAG,IAAI,CAAA;IAC9B,YAAY,EAAE,MAAM,IAAI,CAAA;CACzB,CAAA;AAED,cAAM,aAAc,SAAQ,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC,CAAC;IACtF,KAAK,EAAE,kBAAkB,CAGxB;IAED,iBAAiB,CAAC,KAAK,EAAE,GAAG;IAI5B,WAAW,CAAC,KAAK,EAAE,GAAG;IAItB,WAAW,aAGV;IAED,MAAM;CAOP;AA+FD,eAAe,aAAa,CAAA"}
|
|
@@ -5,6 +5,7 @@ import { StyleSheet, View } from 'react-native';
|
|
|
5
5
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
6
|
import { Button, Heading, Icon, Text } from '../display';
|
|
7
7
|
import { useTheme } from '../../hooks';
|
|
8
|
+
import { ResponseError } from '../../utils/response_error';
|
|
8
9
|
class ErrorBoundary extends React.Component {
|
|
9
10
|
state = {
|
|
10
11
|
error: null,
|
|
@@ -39,12 +40,12 @@ function ErrorView({ error, onReset }) {
|
|
|
39
40
|
reset();
|
|
40
41
|
};
|
|
41
42
|
}, [reset, onReset]);
|
|
42
|
-
if (error instanceof
|
|
43
|
-
return <ResponseErrorView
|
|
43
|
+
if (error instanceof ResponseError) {
|
|
44
|
+
return <ResponseErrorView response={error.response} onReset={onReset}/>;
|
|
44
45
|
}
|
|
45
46
|
return <ErrorContent heading={'Oops!'} body={'Something unexpected happened.'}/>;
|
|
46
47
|
}
|
|
47
|
-
function ResponseErrorView({
|
|
48
|
+
function ResponseErrorView({ response }) {
|
|
48
49
|
const { status } = response;
|
|
49
50
|
const heading = useMemo(() => {
|
|
50
51
|
switch (status) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_boundary.js","sourceRoot":"","sources":["../../../src/components/page/error_boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,KAAK,EAAE,EAAqB,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"error_boundary.js","sourceRoot":"","sources":["../../../src/components/page/error_boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,KAAK,EAAE,EAAqB,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM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;YACX,UAAU,EAAE,QAAQ;YACpB,GAAG,EAAE,CAAC;SACP;QACD,OAAO,EAAE;YACP,SAAS,EAAE,QAAQ;YACnB,UAAU,EAAE,EAAE;SACf;QACD,IAAI,EAAE;YACJ,SAAS,EAAE,QAAQ;YACnB,UAAU,EAAE,EAAE;SACf;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,wBAAwB;SAC7C;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,eAAe,aAAa,CAAA","sourcesContent":["import { useNavigation } from '@react-navigation/native'\nimport { useQueryErrorResetBoundary } from '@tanstack/react-query'\nimport React, { PropsWithChildren, useEffect, useMemo } from 'react'\nimport { StyleSheet, View } from 'react-native'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { Button, Heading, Icon, Text } from '../display'\nimport { useTheme } from '../../hooks'\nimport { ResponseError } from '../../utils/response_error'\n\ntype ErrorBoundaryState = {\n error: Response | Error | null\n unsubscriber: () => void\n}\n\nclass ErrorBoundary extends React.Component<PropsWithChildren<{ onReset?: () => void }>> {\n state: ErrorBoundaryState = {\n error: null,\n unsubscriber: () => {},\n }\n\n componentDidCatch(error: any) {\n this.handleError(error)\n }\n\n handleError(error: any) {\n this.setState({ error })\n }\n\n handleReset = () => {\n this.props.onReset?.()\n this.setState({ error: null })\n }\n\n render() {\n if (this.state.error) {\n return <ErrorView error={this.state.error} onReset={this.handleReset} />\n } else {\n return this.props.children\n }\n }\n}\n\nfunction ErrorView({ error, onReset }: { error: Error | Response; onReset: () => void }) {\n const { reset } = useQueryErrorResetBoundary()\n useEffect(() => {\n if (!reset) return\n\n return () => {\n onReset()\n reset()\n }\n }, [reset, onReset])\n\n if (error instanceof ResponseError) {\n return <ResponseErrorView response={error.response} onReset={onReset} />\n }\n\n return <ErrorContent heading={'Oops!'} body={'Something unexpected happened.'} />\n}\n\nfunction ResponseErrorView({ response }: { response: Response; onReset: () => void }) {\n const { status } = response\n const heading = useMemo(() => {\n switch (status) {\n case 403:\n return 'Permission required'\n case 404:\n return 'Content not found'\n default:\n return 'Oops!'\n }\n }, [status])\n\n const body = useMemo(() => {\n switch (status) {\n case 403:\n return 'Contact your administrator for access.'\n case 404:\n return 'If you believe something should be here, please reach out to your administrator.'\n default:\n return 'Something unexpected happened.'\n }\n }, [status])\n\n return <ErrorContent heading={heading} body={body} />\n}\n\nfunction ErrorContent({ heading, body }: { heading: string; body: string }) {\n const styles = useStyles()\n const navigation = useNavigation()\n\n return (\n <View style={styles.container}>\n <Icon name=\"general.outlinedTextMessage\" size={32} color={styles.icon.color} />\n <View style={styles.information}>\n <Heading variant=\"h3\" style={styles.heading}>\n {heading}\n </Heading>\n <Text style={styles.body}>{body}</Text>\n </View>\n <Button variant=\"outline\" onPress={navigation.goBack} title=\"Go back\" size=\"md\" />\n </View>\n )\n}\n\nconst useStyles = () => {\n const theme = useTheme()\n const { bottom } = useSafeAreaInsets()\n return StyleSheet.create({\n container: {\n flex: 1,\n justifyContent: 'center',\n alignItems: 'center',\n gap: 24,\n paddingHorizontal: 16,\n paddingBottom: bottom,\n },\n information: {\n alignItems: 'center',\n gap: 8,\n },\n heading: {\n textAlign: 'center',\n lineHeight: 20,\n },\n body: {\n textAlign: 'center',\n lineHeight: 20,\n },\n icon: {\n color: theme.colors.iconColorDefaultDisabled,\n },\n })\n}\n\nexport default ErrorBoundary\n"]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ColorSchemeName } from 'react-native';
|
|
3
3
|
import { DeepPartial } from '../types';
|
|
4
|
-
import { ENV, PartialToken, ResponseError, Session } from '../utils';
|
|
4
|
+
import { ENV, OauthType, PartialToken, ResponseError, Session } from '../utils';
|
|
5
5
|
import { ChatTheme, DefaultTheme } from '../utils/theme';
|
|
6
|
-
export
|
|
6
|
+
export interface ChatProviderProps {
|
|
7
7
|
env?: ENV;
|
|
8
8
|
giphyApiKey?: string;
|
|
9
9
|
onUnauthorizedResponse: (_response: ResponseError) => void;
|
|
10
|
-
session: Session;
|
|
11
|
-
theme: ChatTheme;
|
|
12
10
|
token?: PartialToken;
|
|
13
|
-
|
|
14
|
-
export interface ChatProviderProps extends Omit<ChatContextValue, 'client' | 'theme' | 'session'> {
|
|
11
|
+
tokenType?: OauthType;
|
|
15
12
|
theme: CreateChatThemeProps;
|
|
16
13
|
}
|
|
14
|
+
export interface ChatContextValue extends Omit<ChatProviderProps, 'theme'> {
|
|
15
|
+
session: Session;
|
|
16
|
+
theme: ChatTheme;
|
|
17
|
+
}
|
|
17
18
|
export declare const ChatContext: React.Context<ChatContextValue>;
|
|
18
19
|
export declare function ChatProvider({ children, value }: {
|
|
19
20
|
children: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_context.d.ts","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAiC,MAAM,OAAO,CAAA;AACrD,OAAO,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"chat_context.d.ts","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAiC,MAAM,OAAO,CAAA;AACrD,OAAO,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC/E,OAAO,EAAE,SAAS,EAAgB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEtE,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,GAAG,CAAA;IACT,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sBAAsB,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,IAAI,CAAA;IAC1D,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,KAAK,EAAE,oBAAoB,CAAA;CAC5B;AAED,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACxE,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,SAAS,CAAA;CACjB;AAED,eAAO,MAAM,WAAW,iCAOtB,CAAA;AAEF,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAE,qBAkB5F;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;IACjC,WAAW,CAAC,EAAE,eAAe,CAAA;CAC9B;AAED,eAAO,MAAM,cAAc,wBAE1B,CAAA;AAED,eAAO,MAAM,kBAAkB,yDAG5B,oBAAoB,KAAG,SAYzB,CAAA"}
|
|
@@ -12,9 +12,9 @@ export const ChatContext = createContext({
|
|
|
12
12
|
token: undefined,
|
|
13
13
|
});
|
|
14
14
|
export function ChatProvider({ children, value }) {
|
|
15
|
-
const { env, token, onUnauthorizedResponse, giphyApiKey } = value;
|
|
15
|
+
const { env, token, onUnauthorizedResponse, giphyApiKey, tokenType } = value;
|
|
16
16
|
const theme = useCreateChatTheme(value.theme || {});
|
|
17
|
-
const session = useMemo(() => new Session({ token, env }), [env, token]);
|
|
17
|
+
const session = useMemo(() => new Session({ token, env, type: tokenType }), [env, token, tokenType]);
|
|
18
18
|
const contextValue = {
|
|
19
19
|
env,
|
|
20
20
|
token,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_context.js","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"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AAE,SAAS,CAAC,CACxB,CAAA;IAED,MAAM,YAAY,GAAqB;QACrC,GAAG;QACH,KAAK;QACL,sBAAsB;QACtB,OAAO;QACP,KAAK;QACL,WAAW;KACZ,CAAA;IAED,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;AACrF,CAAC;AAOD,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,OAAO,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AACtC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EACjC,KAAK,EAAE,WAAW,GAAG,EAAE,EACvB,WAAW,EAAE,cAAc,GACN,EAAa,EAAE;IACpC,MAAM,mBAAmB,GAAG,cAAc,EAAE,IAAI,OAAO,CAAA;IACvD,MAAM,WAAW,GAAG,cAAc,IAAI,mBAAmB,CAAA;IAEzD,MAAM,KAAK,GAAG;QACZ,GAAG,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;QACpD,MAAM,EAAE;YACN,GAAG,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC;SACpE;KACF,CAAA;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { merge } from 'lodash'\nimport React, { createContext, useMemo } from 'react'\nimport { ColorSchemeName, useColorScheme } from 'react-native'\nimport { DeepPartial } from '../types'\nimport { ENV, OauthType, PartialToken, ResponseError, Session } from '../utils'\nimport { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'\n\nexport interface ChatProviderProps {\n env?: ENV\n giphyApiKey?: string\n onUnauthorizedResponse: (_response: ResponseError) => void\n token?: PartialToken\n tokenType?: OauthType\n theme: CreateChatThemeProps\n}\n\nexport interface ChatContextValue extends Omit<ChatProviderProps, 'theme'> {\n session: Session\n theme: ChatTheme\n}\n\nexport const ChatContext = createContext<ChatContextValue>({\n env: undefined,\n giphyApiKey: undefined,\n onUnauthorizedResponse: () => {},\n session: new Session(),\n theme: defaultTheme('light'),\n token: undefined,\n})\n\nexport function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {\n const { env, token, onUnauthorizedResponse, giphyApiKey, tokenType } = value\n const theme = useCreateChatTheme(value.theme || {})\n const session = useMemo(\n () => new Session({ token, env, type: tokenType }),\n [env, token, tokenType]\n )\n\n const contextValue: ChatContextValue = {\n env,\n token,\n onUnauthorizedResponse,\n session,\n theme,\n giphyApiKey,\n }\n\n return <ChatContext.Provider value={contextValue}>{children}</ChatContext.Provider>\n}\n\nexport interface CreateChatThemeProps {\n theme?: DeepPartial<DefaultTheme>\n colorScheme?: ColorSchemeName\n}\n\nexport const useChatContext = () => {\n return React.useContext(ChatContext)\n}\n\nexport const useCreateChatTheme = ({\n theme: customTheme = {},\n colorScheme: appColorScheme,\n}: CreateChatThemeProps): ChatTheme => {\n const internalColorScheme = useColorScheme() || 'light'\n const colorScheme = appColorScheme || internalColorScheme\n\n const theme = {\n ...merge({}, defaultTheme(colorScheme), customTheme),\n colors: {\n ...merge({}, defaultTheme(colorScheme).colors, customTheme?.colors),\n },\n }\n\n return theme\n}\n"]}
|
|
@@ -16,18 +16,18 @@ export declare const getConversationRequestArgs: ({ conversation_id }: {
|
|
|
16
16
|
export declare const useConversation: ({ conversation_id }: {
|
|
17
17
|
conversation_id: number;
|
|
18
18
|
}) => {
|
|
19
|
-
|
|
19
|
+
status: "error" | "success";
|
|
20
|
+
error: import("../types").ApiError | null;
|
|
20
21
|
isError: boolean;
|
|
21
22
|
isPending: false;
|
|
22
23
|
isLoading: false;
|
|
23
24
|
isLoadingError: false;
|
|
24
25
|
isRefetchError: boolean;
|
|
25
26
|
isSuccess: boolean;
|
|
26
|
-
status: "error" | "success";
|
|
27
27
|
dataUpdatedAt: number;
|
|
28
28
|
errorUpdatedAt: number;
|
|
29
29
|
failureCount: number;
|
|
30
|
-
failureReason:
|
|
30
|
+
failureReason: import("../types").ApiError | null;
|
|
31
31
|
errorUpdateCount: number;
|
|
32
32
|
isFetched: boolean;
|
|
33
33
|
isFetchedAfterMount: boolean;
|
|
@@ -36,7 +36,7 @@ export declare const useConversation: ({ conversation_id }: {
|
|
|
36
36
|
isPaused: boolean;
|
|
37
37
|
isRefetching: boolean;
|
|
38
38
|
isStale: boolean;
|
|
39
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<ConversationResource>,
|
|
39
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<ConversationResource>, import("../types").ApiError>>;
|
|
40
40
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
41
41
|
data: ConversationResource;
|
|
42
42
|
links: Record<string, string>;
|
|
@@ -2,22 +2,23 @@ import { AnyUseSuspenseInfiniteQueryOptions, InfiniteData } from '@tanstack/reac
|
|
|
2
2
|
import { ApiCollection, ApiResource, ResourceObject } from '../types';
|
|
3
3
|
import { GetRequest } from '../utils/client/types';
|
|
4
4
|
import { App } from './use_api_client';
|
|
5
|
+
import { ApiError } from '../types/api_primitives';
|
|
5
6
|
interface SuspenseGetOptions extends GetRequest {
|
|
6
7
|
app?: App;
|
|
7
8
|
}
|
|
8
9
|
export declare const useSuspenseGet: <T extends ResourceObject | ResourceObject[]>(args: SuspenseGetOptions) => {
|
|
9
|
-
|
|
10
|
+
status: "error" | "success";
|
|
11
|
+
error: ApiError | null;
|
|
10
12
|
isError: boolean;
|
|
11
13
|
isPending: false;
|
|
12
14
|
isLoading: false;
|
|
13
15
|
isLoadingError: false;
|
|
14
16
|
isRefetchError: boolean;
|
|
15
17
|
isSuccess: boolean;
|
|
16
|
-
status: "error" | "success";
|
|
17
18
|
dataUpdatedAt: number;
|
|
18
19
|
errorUpdatedAt: number;
|
|
19
20
|
failureCount: number;
|
|
20
|
-
failureReason:
|
|
21
|
+
failureReason: ApiError | null;
|
|
21
22
|
errorUpdateCount: number;
|
|
22
23
|
isFetched: boolean;
|
|
23
24
|
isFetchedAfterMount: boolean;
|
|
@@ -26,7 +27,7 @@ export declare const useSuspenseGet: <T extends ResourceObject | ResourceObject[
|
|
|
26
27
|
isPaused: boolean;
|
|
27
28
|
isRefetching: boolean;
|
|
28
29
|
isStale: boolean;
|
|
29
|
-
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<T>,
|
|
30
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<ApiResource<T>, ApiError>>;
|
|
30
31
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
31
32
|
data: T;
|
|
32
33
|
links: Record<string, string>;
|
|
@@ -35,6 +36,7 @@ export declare const useSuspenseGet: <T extends ResourceObject | ResourceObject[
|
|
|
35
36
|
export type SuspensePaginatorOptions = Omit<AnyUseSuspenseInfiniteQueryOptions, 'getNextPageParam' | 'initialPageParam' | 'queryFn' | 'queryKey'>;
|
|
36
37
|
export declare const useSuspensePaginator: <T extends ResourceObject>(args: SuspenseGetOptions, opts?: SuspensePaginatorOptions) => {
|
|
37
38
|
data: T[];
|
|
39
|
+
status: "error" | "success";
|
|
38
40
|
error: Response | null;
|
|
39
41
|
isError: boolean;
|
|
40
42
|
isPending: false;
|
|
@@ -42,7 +44,6 @@ export declare const useSuspensePaginator: <T extends ResourceObject>(args: Susp
|
|
|
42
44
|
isLoadingError: false;
|
|
43
45
|
isRefetchError: boolean;
|
|
44
46
|
isSuccess: boolean;
|
|
45
|
-
status: "error" | "success";
|
|
46
47
|
dataUpdatedAt: number;
|
|
47
48
|
errorUpdatedAt: number;
|
|
48
49
|
failureCount: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_suspense_api.d.ts","sourceRoot":"","sources":["../../src/hooks/use_suspense_api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,YAAY,EAGb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,UAAU,EAAe,MAAM,uBAAuB,CAAA;AAC/D,OAAO,EAAE,GAAG,EAAgB,MAAM,kBAAkB,CAAA;AAEpD,UAAU,kBAAmB,SAAQ,UAAU;IAC7C,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;AAED,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,cAAc,GAAG,cAAc,EAAE,QAClE,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"use_suspense_api.d.ts","sourceRoot":"","sources":["../../src/hooks/use_suspense_api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kCAAkC,EAClC,YAAY,EAGb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,UAAU,EAAe,MAAM,uBAAuB,CAAA;AAC/D,OAAO,EAAE,GAAG,EAAgB,MAAM,kBAAkB,CAAA;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAGlD,UAAU,kBAAmB,SAAQ,UAAU;IAC7C,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;AAED,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,cAAc,GAAG,cAAc,EAAE,QAClE,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBzB,CAAA;AAOD,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,kCAAkC,EAClC,kBAAkB,GAAG,kBAAkB,GAAG,SAAS,GAAG,UAAU,CACjE,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,cAAc,QACrD,kBAAkB,SACjB,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4ChC,CAAA;AAUD,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB,CAAC,KAAK,CAAC;IACzB,kBAAkB,CAAC,MAAM,CAAC;IAC1B,kBAAkB,CAAC,SAAS,CAAC;IAC7B,kBAAkB,CAAC,KAAK,CAAC;CAC1B,CAAA;AACD,eAAO,MAAM,kBAAkB,SAAU,kBAAkB,KAAG,eAK7D,CAAA"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { useSuspenseInfiniteQuery, useSuspenseQuery, } from '@tanstack/react-query';
|
|
2
2
|
import { useApiClient } from './use_api_client';
|
|
3
|
+
import { Log } from '../utils';
|
|
4
|
+
import { ResponseError } from '../utils/response_error';
|
|
3
5
|
export const useSuspenseGet = (args) => {
|
|
4
6
|
const apiClient = useApiClient();
|
|
5
7
|
const { data, ...query } = useSuspenseQuery({
|
|
6
8
|
queryKey: getRequestQueryKey(args),
|
|
7
9
|
queryFn: ({ queryKey }) => {
|
|
8
10
|
const [url, d, headers, app = 'chat'] = queryKey;
|
|
9
|
-
return apiClient[app]
|
|
11
|
+
return apiClient[app]
|
|
12
|
+
.get({ url, data: d, headers })
|
|
13
|
+
.catch(throwResponseError);
|
|
10
14
|
},
|
|
11
15
|
});
|
|
12
16
|
return { ...data, ...query };
|
|
@@ -16,16 +20,19 @@ export const useSuspensePaginator = (args, opts) => {
|
|
|
16
20
|
const query = useSuspenseInfiniteQuery({
|
|
17
21
|
queryKey: getRequestQueryKey(args),
|
|
18
22
|
queryFn: ({ pageParam }) => {
|
|
23
|
+
Log.info('useSuspenseGet', { pageParam });
|
|
19
24
|
const pageParmWhere = pageParam?.where || {};
|
|
20
25
|
const argsWhere = args.data.where || {};
|
|
21
26
|
const where = { ...argsWhere, ...pageParmWhere };
|
|
22
27
|
const app = args.app || 'chat';
|
|
23
28
|
const offset = pageParam?.offset || args.data.offset;
|
|
24
29
|
const data = { ...args.data, where, offset };
|
|
25
|
-
return apiClient[app]
|
|
30
|
+
return apiClient[app]
|
|
31
|
+
.get({
|
|
26
32
|
url: args.url,
|
|
27
33
|
data,
|
|
28
|
-
})
|
|
34
|
+
})
|
|
35
|
+
.catch(throwResponseError);
|
|
29
36
|
},
|
|
30
37
|
initialPageParam: {},
|
|
31
38
|
getNextPageParam: lastPage => {
|
|
@@ -42,6 +49,12 @@ export const useSuspensePaginator = (args, opts) => {
|
|
|
42
49
|
const data = query.data?.pages.flatMap(page => page.data) || [];
|
|
43
50
|
return { ...query, data };
|
|
44
51
|
};
|
|
52
|
+
const throwResponseError = (error) => {
|
|
53
|
+
if (error instanceof Response) {
|
|
54
|
+
throw new ResponseError(error);
|
|
55
|
+
}
|
|
56
|
+
return Promise.reject(error);
|
|
57
|
+
};
|
|
45
58
|
export const getRequestQueryKey = (args) => [
|
|
46
59
|
args.url,
|
|
47
60
|
args.data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_suspense_api.js","sourceRoot":"","sources":["../../src/hooks/use_suspense_api.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAO,YAAY,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"use_suspense_api.js","sourceRoot":"","sources":["../../src/hooks/use_suspense_api.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAO,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAMvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,IAAwB,EACxB,EAAE;IAEF,MAAM,SAAS,GAAG,Y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IAAwB,EAAmB,EAAE,CAAC;IAC/E,IAAI,CAAC,GAAG;IACR,IAAI,CAAC,IAAI;IACT,IAAI,CAAC,OAAO;IACZ,IAAI,CAAC,GAAG,IAAI,MAAM;CACnB,CAAA","sourcesContent":["import {\n AnyUseSuspenseInfiniteQueryOptions,\n InfiniteData,\n useSuspenseInfiniteQuery,\n useSuspenseQuery,\n} from '@tanstack/react-query'\nimport { ApiCollection, ApiResource, ResourceObject } from '../types'\nimport { GetRequest, RequestData } from '../utils/client/types'\nimport { App, useApiClient } from './use_api_client'\nimport { Log } from '../utils'\nimport { ApiError } from '../types/api_primitives'\nimport { ResponseError } from '../utils/response_error'\n\ninterface SuspenseGetOptions extends GetRequest {\n app?: App\n}\n\nexport const useSuspenseGet = <T extends ResourceObject | ResourceObject[]>(\n args: SuspenseGetOptions\n) => {\n type Resource = ApiResource<T>\n const apiClient = useApiClient()\n\n const { data, ...query } = useSuspenseQuery<Resource, ApiError>({\n queryKey: getRequestQueryKey(args),\n queryFn: ({ queryKey }) => {\n const [url, d, headers, app = 'chat'] = queryKey as RequestQueryKey\n return apiClient[app]\n .get({ url, data: d, headers })\n .catch(throwResponseError) as Promise<Resource>\n },\n })\n\n return { ...data, ...query }\n}\n\ntype NextMeta = Partial<{\n offset: string\n idLt: string\n}>\n\nexport type SuspensePaginatorOptions = Omit<\n AnyUseSuspenseInfiniteQueryOptions,\n 'getNextPageParam' | 'initialPageParam' | 'queryFn' | 'queryKey'\n>\n\nexport const useSuspensePaginator = <T extends ResourceObject>(\n args: SuspenseGetOptions,\n opts?: SuspensePaginatorOptions\n) => {\n const apiClient = useApiClient()\n const query = useSuspenseInfiniteQuery<\n ApiCollection<T>,\n Response,\n InfiniteData<ApiCollection<T>>,\n any,\n Partial<RequestData> | undefined\n >({\n queryKey: getRequestQueryKey(args),\n queryFn: ({ pageParam }) => {\n Log.info('useSuspenseGet', { pageParam })\n\n const pageParmWhere = pageParam?.where || {}\n const argsWhere = args.data.where || {}\n const where = { ...argsWhere, ...pageParmWhere }\n const app = args.app || 'chat'\n const offset = pageParam?.offset || args.data.offset\n const data = { ...args.data, where, offset }\n\n return apiClient[app]\n .get<ApiCollection<T>>({\n url: args.url,\n data,\n })\n .catch(throwResponseError)\n },\n initialPageParam: {} as Partial<RequestData>,\n getNextPageParam: lastPage => {\n const next: NextMeta = lastPage.meta?.next || {}\n const { offset, idLt } = next\n\n if (idLt) return { where: { id_lt: idLt } }\n if (offset) return { offset: Number(offset) }\n\n return undefined\n },\n ...(opts || {}),\n })\n\n const data: T[] = query.data?.pages.flatMap(page => page.data) || []\n\n return { ...query, data }\n}\n\nconst throwResponseError = (error: unknown) => {\n if (error instanceof Response) {\n throw new ResponseError(error as ApiError)\n }\n\n return Promise.reject(error)\n}\n\nexport type RequestQueryKey = [\n SuspenseGetOptions['url'],\n SuspenseGetOptions['data'],\n SuspenseGetOptions['headers'],\n SuspenseGetOptions['app'],\n]\nexport const getRequestQueryKey = (args: SuspenseGetOptions): RequestQueryKey => [\n args.url,\n args.data,\n args.headers,\n args.app || 'chat',\n]\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { GroupConversations } from './components';
|
|
2
2
|
export { ApiProvider, chatQueryClient } from './contexts/api_provider';
|
|
3
|
-
export
|
|
3
|
+
export * from './contexts/chat_context';
|
|
4
4
|
export * from './navigation';
|
|
5
|
+
export { ScreenLayout } from './navigation/screenLayout';
|
|
6
|
+
export { DesignSystemScreen } from './screens';
|
|
5
7
|
export * from './types';
|
|
8
|
+
export { platformFontWeightBold, Session, TemporaryDefaultColorsType, Uri } from './utils';
|
|
6
9
|
export * from './utils/client';
|
|
7
|
-
export
|
|
8
|
-
export { TemporaryDefaultColorsType, ChatAdapters, ClipboardAdapter, Session, Uri, platformFontWeightBold, } from './utils';
|
|
10
|
+
export * from './utils/native_adapters';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACtE,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC9C,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,0BAA0B,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAC1F,cAAc,gBAAgB,CAAA;AAC9B,cAAc,yBAAyB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { GroupConversations } from './components';
|
|
2
2
|
export { ApiProvider, chatQueryClient } from './contexts/api_provider';
|
|
3
|
-
export
|
|
3
|
+
export * from './contexts/chat_context';
|
|
4
4
|
export * from './navigation';
|
|
5
|
+
export { ScreenLayout } from './navigation/screenLayout';
|
|
6
|
+
export { DesignSystemScreen } from './screens';
|
|
5
7
|
export * from './types';
|
|
8
|
+
export { platformFontWeightBold, Session, Uri } from './utils';
|
|
6
9
|
export * from './utils/client';
|
|
7
|
-
export
|
|
8
|
-
export { ChatAdapters, ClipboardAdapter, Session, Uri, platformFontWeightBold, } from './utils';
|
|
10
|
+
export * from './utils/native_adapters';
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACtE,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC9C,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAA8B,GAAG,EAAE,MAAM,SAAS,CAAA;AAC1F,cAAc,gBAAgB,CAAA;AAC9B,cAAc,yBAAyB,CAAA","sourcesContent":["export { GroupConversations } from './components'\nexport { ApiProvider, chatQueryClient } from './contexts/api_provider'\nexport * from './contexts/chat_context'\nexport * from './navigation'\nexport { ScreenLayout } from './navigation/screenLayout'\nexport { DesignSystemScreen } from './screens'\nexport * from './types'\nexport { platformFontWeightBold, Session, TemporaryDefaultColorsType, Uri } from './utils'\nexport * from './utils/client'\nexport * from './utils/native_adapters'\n"]}
|
|
@@ -24,7 +24,7 @@ export type ApiCollection<Type = ResourceObject> = {
|
|
|
24
24
|
links: Record<string, string>;
|
|
25
25
|
meta: CollectionMeta;
|
|
26
26
|
};
|
|
27
|
-
export interface ApiError {
|
|
27
|
+
export interface ApiError extends Response {
|
|
28
28
|
errors: ErrorObject[];
|
|
29
29
|
}
|
|
30
30
|
export interface CollectionMeta {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_primitives.d.ts","sourceRoot":"","sources":["../../src/types/api_primitives.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,MA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AAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,aAAa,CAAC,IAAI,GAAG,cAAc,IAAI;IACjD,IAAI,EAAE,IAAI,EAAE,CAAA;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,IAAI,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,MAAM,WAAW,QAAS,SAAQ,QAAQ;IACxC,MAAM,EAAE,WAAW,EAAE,CAAA;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAA;CACjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_primitives.js","sourceRoot":"","sources":["../../src/types/api_primitives.ts"],"names":[],"mappings":"","sourcesContent":["export interface ResourceObject {\n id: string | number\n type: string\n}\n\nexport interface ErrorObject {\n source?: { parameter: string }\n detail: string\n meta?: { associated_resources: any[]; resource: string }\n title: string\n status: string\n}\n\nexport type ApiResource<Type = ResourceObject> = {\n data: Type\n links: Record<string, string>\n meta: Record<string, unknown>\n}\n\nexport type ApiCollection<Type = ResourceObject> = {\n data: Type[]\n links: Record<string, string>\n meta: CollectionMeta\n}\n\nexport interface ApiError {\n errors: ErrorObject[]\n}\n\nexport interface CollectionMeta {\n count: number\n totalCount: number\n next?: Record<string, unknown>\n parent?: ResourceObject\n [attributeName: string]: unknown\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api_primitives.js","sourceRoot":"","sources":["../../src/types/api_primitives.ts"],"names":[],"mappings":"","sourcesContent":["export interface ResourceObject {\n id: string | number\n type: string\n}\n\nexport interface ErrorObject {\n source?: { parameter: string }\n detail: string\n meta?: { associated_resources: any[]; resource: string }\n title: string\n status: string\n}\n\nexport type ApiResource<Type = ResourceObject> = {\n data: Type\n links: Record<string, string>\n meta: Record<string, unknown>\n}\n\nexport type ApiCollection<Type = ResourceObject> = {\n data: Type[]\n links: Record<string, string>\n meta: CollectionMeta\n}\n\nexport interface ApiError extends Response {\n errors: ErrorObject[]\n}\n\nexport interface CollectionMeta {\n count: number\n totalCount: number\n next?: Record<string, unknown>\n parent?: ResourceObject\n [attributeName: string]: unknown\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LogAdapter } from './log';
|
|
1
2
|
import { AudioAdapter } from './audio';
|
|
2
3
|
import { ClipboardAdapter } from './clipboard';
|
|
3
4
|
import { ImagePickerAdapter } from './image_picker';
|
|
@@ -7,13 +8,15 @@ type ChatConfigurations = {
|
|
|
7
8
|
audio: AudioAdapter;
|
|
8
9
|
video: VideoAdapter;
|
|
9
10
|
imagePicker: ImagePickerAdapter;
|
|
11
|
+
log?: LogAdapter;
|
|
10
12
|
};
|
|
11
13
|
export declare class ChatAdapters {
|
|
12
14
|
static configure(configurations: ChatConfigurations): void;
|
|
13
15
|
}
|
|
14
|
-
declare let Clipboard: ClipboardAdapter;
|
|
15
|
-
declare let Audio: AudioAdapter;
|
|
16
|
-
declare let Video: VideoAdapter;
|
|
17
|
-
declare let ImagePicker: ImagePickerAdapter;
|
|
18
|
-
export
|
|
16
|
+
export declare let Clipboard: ClipboardAdapter;
|
|
17
|
+
export declare let Audio: AudioAdapter;
|
|
18
|
+
export declare let Video: VideoAdapter;
|
|
19
|
+
export declare let ImagePicker: ImagePickerAdapter;
|
|
20
|
+
export declare let Log: LogAdapter;
|
|
21
|
+
export {};
|
|
19
22
|
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,KAAK,kBAAkB,GAAG;IACxB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,KAAK,EAAE,YAAY,CAAA;IACnB,KAAK,EAAE,YAAY,CAAA;IACnB,WAAW,EAAE,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,KAAK,kBAAkB,GAAG;IACxB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,KAAK,EAAE,YAAY,CAAA;IACnB,KAAK,EAAE,YAAY,CAAA;IACnB,WAAW,EAAE,kBAAkB,CAAA;IAC/B,GAAG,CAAC,EAAE,UAAU,CAAA;CACjB,CAAA;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB;CAOpD;AAMD,eAAO,IAAI,SAAS,EAAE,gBAMpB,CAAA;AAEF,eAAO,IAAI,KAAK,EAAE,YAKhB,CAAA;AAEF,eAAO,IAAI,KAAK,EAAE,YAQhB,CAAA;AAEF,eAAO,IAAI,WAAW,EAAE,kBAStB,CAAA;AAEF,eAAO,IAAI,GAAG,EAAE,UAA6B,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LogAdapter } from './log';
|
|
1
2
|
import { AudioAdapter } from './audio';
|
|
2
3
|
import { ClipboardAdapter } from './clipboard';
|
|
3
4
|
import { ImagePickerAdapter } from './image_picker';
|
|
@@ -8,31 +9,32 @@ export class ChatAdapters {
|
|
|
8
9
|
Audio = configurations.audio;
|
|
9
10
|
Video = configurations.video;
|
|
10
11
|
ImagePicker = configurations.imagePicker;
|
|
12
|
+
Log = configurations.log || new LogAdapter();
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
const methodMissing = () => {
|
|
14
16
|
console.warn('ChatAdapters.configure() must be called before using any adapters');
|
|
15
17
|
};
|
|
16
|
-
let Clipboard = new ClipboardAdapter({
|
|
18
|
+
export let Clipboard = new ClipboardAdapter({
|
|
17
19
|
getStringAsync: async () => {
|
|
18
20
|
methodMissing();
|
|
19
21
|
return '';
|
|
20
22
|
},
|
|
21
23
|
setStringAsync: async (_) => methodMissing(),
|
|
22
24
|
});
|
|
23
|
-
let Audio = new AudioAdapter({
|
|
25
|
+
export let Audio = new AudioAdapter({
|
|
24
26
|
useAudio: (_) => {
|
|
25
27
|
methodMissing();
|
|
26
28
|
return {};
|
|
27
29
|
},
|
|
28
30
|
});
|
|
29
|
-
let Video = new VideoAdapter({
|
|
31
|
+
export let Video = new VideoAdapter({
|
|
30
32
|
Player: Object.assign(() => {
|
|
31
33
|
methodMissing();
|
|
32
34
|
return null;
|
|
33
35
|
}, { $$typeof: Symbol.for('react.forward_ref') }),
|
|
34
36
|
});
|
|
35
|
-
let ImagePicker = new ImagePickerAdapter({
|
|
37
|
+
export let ImagePicker = new ImagePickerAdapter({
|
|
36
38
|
openCameraAsync: async () => {
|
|
37
39
|
methodMissing();
|
|
38
40
|
return { canceled: true, assets: null };
|
|
@@ -42,5 +44,5 @@ let ImagePicker = new ImagePickerAdapter({
|
|
|
42
44
|
return { canceled: true, assets: null };
|
|
43
45
|
},
|
|
44
46
|
});
|
|
45
|
-
export
|
|
47
|
+
export let Log = new LogAdapter();
|
|
46
48
|
//# sourceMappingURL=configuration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/utils/native_adapters/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/utils/native_adapters/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAUtC,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,SAAS,CAAC,cAAkC;QACjD,SAAS,GAAG,cAAc,CAAC,SAAS,CAAA;QACpC,KAAK,GAAG,cAAc,CAAC,KAAK,CAAA;QAC5B,KAAK,GAAG,cAAc,CAAC,KAAK,CAAA;QAC5B,WAAW,GAAG,cAAc,CAAC,WAAW,CAAA;QACxC,GAAG,GAAG,cAAc,CAAC,GAAG,IAAI,IAAI,UAAU,EAAE,CAAA;IAC9C,CAAC;CACF;AAED,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,OAAO,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAA;AACnF,CAAC,CAAA;AAED,MAAM,CAAC,IAAI,SAAS,GAAqB,IAAI,gBAAgB,CAAC;IAC5D,cAAc,EAAE,KAAK,IAAI,EAAE;QACzB,aAAa,EAAE,CAAA;QACf,OAAO,EAAE,CAAA;IACX,CAAC;IACD,cAAc,EAAE,KAAK,EAAE,CAAS,EAAE,EAAE,CAAC,aAAa,EAAE;CACrD,CAAC,CAAA;AAEF,MAAM,CAAC,IAAI,KAAK,GAAiB,IAAI,YAAY,CAAC;IAChD,QAAQ,EAAE,CAAC,CAAS,EAAE,EAAE;QACtB,aAAa,EAAE,CAAA;QACf,OAAO,EAAS,CAAA;IAClB,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,IAAI,KAAK,GAAiB,IAAI,YAAY,CAAC;IAChD,MAAM,EAAE,MAAM,CAAC,MAAM,CACnB,GAAG,EAAE;QACH,aAAa,EAAE,CAAA;QACf,OAAO,IAAI,CAAA;IACb,CAAC,EACD,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,CAC9C;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,IAAI,WAAW,GAAuB,IAAI,kBAAkB,CAAC;IAClE,eAAe,EAAE,KAAK,IAAI,EAAE;QAC1B,aAAa,EAAE,CAAA;QACf,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;IACzC,CAAC;IACD,qBAAqB,EAAE,KAAK,IAAI,EAAE;QAChC,aAAa,EAAE,CAAA;QACf,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;IACzC,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,IAAI,GAAG,GAAe,IAAI,UAAU,EAAE,CAAA","sourcesContent":["import { LogAdapter } from './log'\nimport { AudioAdapter } from './audio'\nimport { ClipboardAdapter } from './clipboard'\nimport { ImagePickerAdapter } from './image_picker'\nimport { VideoAdapter } from './video'\n\ntype ChatConfigurations = {\n clipboard: ClipboardAdapter\n audio: AudioAdapter\n video: VideoAdapter\n imagePicker: ImagePickerAdapter\n log?: LogAdapter\n}\n\nexport class ChatAdapters {\n static configure(configurations: ChatConfigurations) {\n Clipboard = configurations.clipboard\n Audio = configurations.audio\n Video = configurations.video\n ImagePicker = configurations.imagePicker\n Log = configurations.log || new LogAdapter()\n }\n}\n\nconst methodMissing = () => {\n console.warn('ChatAdapters.configure() must be called before using any adapters')\n}\n\nexport let Clipboard: ClipboardAdapter = new ClipboardAdapter({\n getStringAsync: async () => {\n methodMissing()\n return ''\n },\n setStringAsync: async (_: string) => methodMissing(),\n})\n\nexport let Audio: AudioAdapter = new AudioAdapter({\n useAudio: (_: string) => {\n methodMissing()\n return {} as any\n },\n})\n\nexport let Video: VideoAdapter = new VideoAdapter({\n Player: Object.assign(\n () => {\n methodMissing()\n return null\n },\n { $$typeof: Symbol.for('react.forward_ref') }\n ),\n})\n\nexport let ImagePicker: ImagePickerAdapter = new ImagePickerAdapter({\n openCameraAsync: async () => {\n methodMissing()\n return { canceled: true, assets: null }\n },\n openImageLibraryAsync: async () => {\n methodMissing()\n return { canceled: true, assets: null }\n },\n})\n\nexport let Log: LogAdapter = new LogAdapter()\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/native_adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA","sourcesContent":["export * from './clipboard'\nexport * from './configuration'\nexport * from './audio'\nexport * from './image_picker'\nexport * from './video'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/native_adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA","sourcesContent":["export * from './clipboard'\nexport * from './configuration'\nexport * from './audio'\nexport * from './image_picker'\nexport * from './video'\nexport * from './log'\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface LogAdapterConfig {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
error: (message: string, ...args: any[]) => void;
|
|
4
|
+
info: (message: string, ...args: any[]) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare class LogAdapter {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
onError?: LogAdapterConfig['error'];
|
|
9
|
+
onInfo?: LogAdapterConfig['info'];
|
|
10
|
+
constructor(config?: Partial<LogAdapterConfig>);
|
|
11
|
+
error(message: string, ...args: any[]): void;
|
|
12
|
+
info(message: string, ...args: any[]): void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/log.ts"],"names":[],"mappings":"AAAA,UAAU,gBAAgB;IACxB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAChD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;CAChD;AAED,qBAAa,UAAU;IACrB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACnC,MAAM,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAA;gBAErB,MAAM,GAAE,OAAO,CAAC,gBAAgB,CAAM;IAMlD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAMrC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;CAKrC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class LogAdapter {
|
|
2
|
+
enabled;
|
|
3
|
+
onError;
|
|
4
|
+
onInfo;
|
|
5
|
+
constructor(config = {}) {
|
|
6
|
+
this.enabled = config.enabled ?? false;
|
|
7
|
+
this.onError = config.error;
|
|
8
|
+
this.onInfo = config.info;
|
|
9
|
+
}
|
|
10
|
+
error(message, ...args) {
|
|
11
|
+
if (!this.enabled)
|
|
12
|
+
return;
|
|
13
|
+
this.onError?.(message, ...args);
|
|
14
|
+
}
|
|
15
|
+
info(message, ...args) {
|
|
16
|
+
if (!this.enabled)
|
|
17
|
+
return;
|
|
18
|
+
this.onInfo?.(message, ...args);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/utils/native_adapters/log.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,UAAU;IACrB,OAAO,CAAS;IAChB,OAAO,CAA4B;IACnC,MAAM,CAA2B;IAEjC,YAAY,SAAoC,EAAE;QAChD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK,CAAA;QACtC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAA;IAC3B,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAW;QACnC,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAM;QAEzB,IAAI,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;IAClC,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;QAClC,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAM;QAEzB,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;IACjC,CAAC;CACF","sourcesContent":["interface LogAdapterConfig {\n enabled: boolean\n error: (message: string, ...args: any[]) => void\n info: (message: string, ...args: any[]) => void\n}\n\nexport class LogAdapter {\n enabled: boolean\n onError?: LogAdapterConfig['error']\n onInfo?: LogAdapterConfig['info']\n\n constructor(config: Partial<LogAdapterConfig> = {}) {\n this.enabled = config.enabled ?? false\n this.onError = config.error\n this.onInfo = config.info\n }\n\n error(message: string, ...args: any[]) {\n if (!this.enabled) return\n\n this.onError?.(message, ...args)\n }\n\n info(message: string, ...args: any[]) {\n if (!this.enabled) return\n\n this.onInfo?.(message, ...args)\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ApiError } from '../types/api_primitives';
|
|
2
|
+
export declare class ResponseError extends Error {
|
|
3
|
+
status: number;
|
|
4
|
+
statusText: string;
|
|
5
|
+
errors: ApiError['errors'];
|
|
6
|
+
response: ApiError;
|
|
7
|
+
constructor(response: ApiError);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=response_error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response_error.d.ts","sourceRoot":"","sources":["../../src/utils/response_error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAElD,qBAAa,aAAc,SAAQ,KAAK;IACtC,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAC1B,QAAQ,EAAE,QAAQ,CAAA;gBAEN,QAAQ,EAAE,QAAQ;CAQ/B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class ResponseError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
statusText;
|
|
4
|
+
errors;
|
|
5
|
+
response;
|
|
6
|
+
constructor(response) {
|
|
7
|
+
super(`ResponseError: ${response?.status} ${response?.statusText}`);
|
|
8
|
+
this.name = 'ResponseError';
|
|
9
|
+
this.status = response?.status;
|
|
10
|
+
this.statusText = response?.statusText;
|
|
11
|
+
this.errors = response?.errors || [];
|
|
12
|
+
this.response = response;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=response_error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response_error.js","sourceRoot":"","sources":["../../src/utils/response_error.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,MAAM,CAAQ;IACd,UAAU,CAAQ;IAClB,MAAM,CAAoB;IAC1B,QAAQ,CAAU;IAElB,YAAY,QAAkB;QAC5B,KAAK,CAAC,kBAAkB,QAAQ,EAAE,MAAM,IAAI,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAA;QACnE,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,QAAQ,EAAE,MAAM,CAAA;QAC9B,IAAI,CAAC,UAAU,GAAG,QAAQ,EAAE,UAAU,CAAA;QACtC,IAAI,CAAC,MAAM,GAAG,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAA;QACpC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF","sourcesContent":["import { ApiError } from '../types/api_primitives'\n\nexport class ResponseError extends Error {\n status: number\n statusText: string\n errors: ApiError['errors']\n response: ApiError\n\n constructor(response: ApiError) {\n super(`ResponseError: ${response?.status} ${response?.statusText}`)\n this.name = 'ResponseError'\n this.status = response?.status\n this.statusText = response?.statusText\n this.errors = response?.errors || []\n this.response = response\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "3.4.1-rc.
|
|
3
|
+
"version": "3.4.1-rc.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"prettier": "^3.4.2",
|
|
55
55
|
"typescript": "<5.6.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "9492d1e28fdb3afa7a5296fe2bc01bdc7f6acec4"
|
|
58
58
|
}
|
|
@@ -5,6 +5,7 @@ import { StyleSheet, View } from 'react-native'
|
|
|
5
5
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
6
6
|
import { Button, Heading, Icon, Text } from '../display'
|
|
7
7
|
import { useTheme } from '../../hooks'
|
|
8
|
+
import { ResponseError } from '../../utils/response_error'
|
|
8
9
|
|
|
9
10
|
type ErrorBoundaryState = {
|
|
10
11
|
error: Response | Error | null
|
|
@@ -50,14 +51,14 @@ function ErrorView({ error, onReset }: { error: Error | Response; onReset: () =>
|
|
|
50
51
|
}
|
|
51
52
|
}, [reset, onReset])
|
|
52
53
|
|
|
53
|
-
if (error instanceof
|
|
54
|
-
return <ResponseErrorView
|
|
54
|
+
if (error instanceof ResponseError) {
|
|
55
|
+
return <ResponseErrorView response={error.response} onReset={onReset} />
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
return <ErrorContent heading={'Oops!'} body={'Something unexpected happened.'} />
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
function ResponseErrorView({
|
|
61
|
+
function ResponseErrorView({ response }: { response: Response; onReset: () => void }) {
|
|
61
62
|
const { status } = response
|
|
62
63
|
const heading = useMemo(() => {
|
|
63
64
|
switch (status) {
|
|
@@ -2,20 +2,21 @@ import { merge } from 'lodash'
|
|
|
2
2
|
import React, { createContext, useMemo } from 'react'
|
|
3
3
|
import { ColorSchemeName, useColorScheme } from 'react-native'
|
|
4
4
|
import { DeepPartial } from '../types'
|
|
5
|
-
import { ENV, PartialToken, ResponseError, Session } from '../utils'
|
|
5
|
+
import { ENV, OauthType, PartialToken, ResponseError, Session } from '../utils'
|
|
6
6
|
import { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export interface ChatProviderProps {
|
|
9
9
|
env?: ENV
|
|
10
10
|
giphyApiKey?: string
|
|
11
11
|
onUnauthorizedResponse: (_response: ResponseError) => void
|
|
12
|
-
session: Session
|
|
13
|
-
theme: ChatTheme
|
|
14
12
|
token?: PartialToken
|
|
13
|
+
tokenType?: OauthType
|
|
14
|
+
theme: CreateChatThemeProps
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export interface
|
|
18
|
-
|
|
17
|
+
export interface ChatContextValue extends Omit<ChatProviderProps, 'theme'> {
|
|
18
|
+
session: Session
|
|
19
|
+
theme: ChatTheme
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export const ChatContext = createContext<ChatContextValue>({
|
|
@@ -28,9 +29,12 @@ export const ChatContext = createContext<ChatContextValue>({
|
|
|
28
29
|
})
|
|
29
30
|
|
|
30
31
|
export function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {
|
|
31
|
-
const { env, token, onUnauthorizedResponse, giphyApiKey } = value
|
|
32
|
+
const { env, token, onUnauthorizedResponse, giphyApiKey, tokenType } = value
|
|
32
33
|
const theme = useCreateChatTheme(value.theme || {})
|
|
33
|
-
const session = useMemo(
|
|
34
|
+
const session = useMemo(
|
|
35
|
+
() => new Session({ token, env, type: tokenType }),
|
|
36
|
+
[env, token, tokenType]
|
|
37
|
+
)
|
|
34
38
|
|
|
35
39
|
const contextValue: ChatContextValue = {
|
|
36
40
|
env,
|
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
import { ApiCollection, ApiResource, ResourceObject } from '../types'
|
|
8
8
|
import { GetRequest, RequestData } from '../utils/client/types'
|
|
9
9
|
import { App, useApiClient } from './use_api_client'
|
|
10
|
+
import { Log } from '../utils'
|
|
11
|
+
import { ApiError } from '../types/api_primitives'
|
|
12
|
+
import { ResponseError } from '../utils/response_error'
|
|
10
13
|
|
|
11
14
|
interface SuspenseGetOptions extends GetRequest {
|
|
12
15
|
app?: App
|
|
@@ -18,12 +21,13 @@ export const useSuspenseGet = <T extends ResourceObject | ResourceObject[]>(
|
|
|
18
21
|
type Resource = ApiResource<T>
|
|
19
22
|
const apiClient = useApiClient()
|
|
20
23
|
|
|
21
|
-
const { data, ...query } = useSuspenseQuery<Resource,
|
|
24
|
+
const { data, ...query } = useSuspenseQuery<Resource, ApiError>({
|
|
22
25
|
queryKey: getRequestQueryKey(args),
|
|
23
26
|
queryFn: ({ queryKey }) => {
|
|
24
27
|
const [url, d, headers, app = 'chat'] = queryKey as RequestQueryKey
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
return apiClient[app]
|
|
29
|
+
.get({ url, data: d, headers })
|
|
30
|
+
.catch(throwResponseError) as Promise<Resource>
|
|
27
31
|
},
|
|
28
32
|
})
|
|
29
33
|
|
|
@@ -54,6 +58,8 @@ export const useSuspensePaginator = <T extends ResourceObject>(
|
|
|
54
58
|
>({
|
|
55
59
|
queryKey: getRequestQueryKey(args),
|
|
56
60
|
queryFn: ({ pageParam }) => {
|
|
61
|
+
Log.info('useSuspenseGet', { pageParam })
|
|
62
|
+
|
|
57
63
|
const pageParmWhere = pageParam?.where || {}
|
|
58
64
|
const argsWhere = args.data.where || {}
|
|
59
65
|
const where = { ...argsWhere, ...pageParmWhere }
|
|
@@ -61,10 +67,12 @@ export const useSuspensePaginator = <T extends ResourceObject>(
|
|
|
61
67
|
const offset = pageParam?.offset || args.data.offset
|
|
62
68
|
const data = { ...args.data, where, offset }
|
|
63
69
|
|
|
64
|
-
return apiClient[app]
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
return apiClient[app]
|
|
71
|
+
.get<ApiCollection<T>>({
|
|
72
|
+
url: args.url,
|
|
73
|
+
data,
|
|
74
|
+
})
|
|
75
|
+
.catch(throwResponseError)
|
|
68
76
|
},
|
|
69
77
|
initialPageParam: {} as Partial<RequestData>,
|
|
70
78
|
getNextPageParam: lastPage => {
|
|
@@ -84,6 +92,14 @@ export const useSuspensePaginator = <T extends ResourceObject>(
|
|
|
84
92
|
return { ...query, data }
|
|
85
93
|
}
|
|
86
94
|
|
|
95
|
+
const throwResponseError = (error: unknown) => {
|
|
96
|
+
if (error instanceof Response) {
|
|
97
|
+
throw new ResponseError(error as ApiError)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return Promise.reject(error)
|
|
101
|
+
}
|
|
102
|
+
|
|
87
103
|
export type RequestQueryKey = [
|
|
88
104
|
SuspenseGetOptions['url'],
|
|
89
105
|
SuspenseGetOptions['data'],
|
package/src/index.tsx
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { GroupConversations } from './components'
|
|
2
2
|
export { ApiProvider, chatQueryClient } from './contexts/api_provider'
|
|
3
|
-
export
|
|
3
|
+
export * from './contexts/chat_context'
|
|
4
4
|
export * from './navigation'
|
|
5
|
+
export { ScreenLayout } from './navigation/screenLayout'
|
|
6
|
+
export { DesignSystemScreen } from './screens'
|
|
5
7
|
export * from './types'
|
|
8
|
+
export { platformFontWeightBold, Session, TemporaryDefaultColorsType, Uri } from './utils'
|
|
6
9
|
export * from './utils/client'
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
TemporaryDefaultColorsType,
|
|
11
|
-
ChatAdapters,
|
|
12
|
-
ClipboardAdapter,
|
|
13
|
-
Session,
|
|
14
|
-
Uri,
|
|
15
|
-
platformFontWeightBold,
|
|
16
|
-
} from './utils'
|
|
10
|
+
export * from './utils/native_adapters'
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LogAdapter } from './log'
|
|
1
2
|
import { AudioAdapter } from './audio'
|
|
2
3
|
import { ClipboardAdapter } from './clipboard'
|
|
3
4
|
import { ImagePickerAdapter } from './image_picker'
|
|
@@ -8,6 +9,7 @@ type ChatConfigurations = {
|
|
|
8
9
|
audio: AudioAdapter
|
|
9
10
|
video: VideoAdapter
|
|
10
11
|
imagePicker: ImagePickerAdapter
|
|
12
|
+
log?: LogAdapter
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export class ChatAdapters {
|
|
@@ -16,6 +18,7 @@ export class ChatAdapters {
|
|
|
16
18
|
Audio = configurations.audio
|
|
17
19
|
Video = configurations.video
|
|
18
20
|
ImagePicker = configurations.imagePicker
|
|
21
|
+
Log = configurations.log || new LogAdapter()
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -23,7 +26,7 @@ const methodMissing = () => {
|
|
|
23
26
|
console.warn('ChatAdapters.configure() must be called before using any adapters')
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
let Clipboard: ClipboardAdapter = new ClipboardAdapter({
|
|
29
|
+
export let Clipboard: ClipboardAdapter = new ClipboardAdapter({
|
|
27
30
|
getStringAsync: async () => {
|
|
28
31
|
methodMissing()
|
|
29
32
|
return ''
|
|
@@ -31,14 +34,14 @@ let Clipboard: ClipboardAdapter = new ClipboardAdapter({
|
|
|
31
34
|
setStringAsync: async (_: string) => methodMissing(),
|
|
32
35
|
})
|
|
33
36
|
|
|
34
|
-
let Audio: AudioAdapter = new AudioAdapter({
|
|
37
|
+
export let Audio: AudioAdapter = new AudioAdapter({
|
|
35
38
|
useAudio: (_: string) => {
|
|
36
39
|
methodMissing()
|
|
37
40
|
return {} as any
|
|
38
41
|
},
|
|
39
42
|
})
|
|
40
43
|
|
|
41
|
-
let Video: VideoAdapter = new VideoAdapter({
|
|
44
|
+
export let Video: VideoAdapter = new VideoAdapter({
|
|
42
45
|
Player: Object.assign(
|
|
43
46
|
() => {
|
|
44
47
|
methodMissing()
|
|
@@ -48,7 +51,7 @@ let Video: VideoAdapter = new VideoAdapter({
|
|
|
48
51
|
),
|
|
49
52
|
})
|
|
50
53
|
|
|
51
|
-
let ImagePicker: ImagePickerAdapter = new ImagePickerAdapter({
|
|
54
|
+
export let ImagePicker: ImagePickerAdapter = new ImagePickerAdapter({
|
|
52
55
|
openCameraAsync: async () => {
|
|
53
56
|
methodMissing()
|
|
54
57
|
return { canceled: true, assets: null }
|
|
@@ -59,4 +62,4 @@ let ImagePicker: ImagePickerAdapter = new ImagePickerAdapter({
|
|
|
59
62
|
},
|
|
60
63
|
})
|
|
61
64
|
|
|
62
|
-
export
|
|
65
|
+
export let Log: LogAdapter = new LogAdapter()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface LogAdapterConfig {
|
|
2
|
+
enabled: boolean
|
|
3
|
+
error: (message: string, ...args: any[]) => void
|
|
4
|
+
info: (message: string, ...args: any[]) => void
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class LogAdapter {
|
|
8
|
+
enabled: boolean
|
|
9
|
+
onError?: LogAdapterConfig['error']
|
|
10
|
+
onInfo?: LogAdapterConfig['info']
|
|
11
|
+
|
|
12
|
+
constructor(config: Partial<LogAdapterConfig> = {}) {
|
|
13
|
+
this.enabled = config.enabled ?? false
|
|
14
|
+
this.onError = config.error
|
|
15
|
+
this.onInfo = config.info
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
error(message: string, ...args: any[]) {
|
|
19
|
+
if (!this.enabled) return
|
|
20
|
+
|
|
21
|
+
this.onError?.(message, ...args)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
info(message: string, ...args: any[]) {
|
|
25
|
+
if (!this.enabled) return
|
|
26
|
+
|
|
27
|
+
this.onInfo?.(message, ...args)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ApiError } from '../types/api_primitives'
|
|
2
|
+
|
|
3
|
+
export class ResponseError extends Error {
|
|
4
|
+
status: number
|
|
5
|
+
statusText: string
|
|
6
|
+
errors: ApiError['errors']
|
|
7
|
+
response: ApiError
|
|
8
|
+
|
|
9
|
+
constructor(response: ApiError) {
|
|
10
|
+
super(`ResponseError: ${response?.status} ${response?.statusText}`)
|
|
11
|
+
this.name = 'ResponseError'
|
|
12
|
+
this.status = response?.status
|
|
13
|
+
this.statusText = response?.statusText
|
|
14
|
+
this.errors = response?.errors || []
|
|
15
|
+
this.response = response
|
|
16
|
+
}
|
|
17
|
+
}
|