@planningcenter/chat-react-native 1.4.0 → 1.4.1-qa-72.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.
- package/build/components/index.d.ts +3 -0
- package/build/components/index.d.ts.map +1 -0
- package/build/components/index.js +3 -0
- package/build/components/index.js.map +1 -0
- package/build/contexts/api_provider.d.ts.map +1 -1
- package/build/contexts/api_provider.js +7 -8
- package/build/contexts/api_provider.js.map +1 -1
- package/build/contexts/chat_context.d.ts +8 -1
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +21 -2
- package/build/contexts/chat_context.js.map +1 -1
- package/build/contexts/index.d.ts +3 -0
- package/build/contexts/index.d.ts.map +1 -0
- package/build/contexts/index.js +3 -0
- package/build/contexts/index.js.map +1 -0
- package/build/hooks/index.d.ts +2 -2
- package/build/hooks/index.d.ts.map +1 -1
- package/build/hooks/index.js +2 -2
- package/build/hooks/index.js.map +1 -1
- package/build/index.d.ts +4 -7
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -5
- package/build/index.js.map +1 -1
- package/build/utils/api.d.ts +9 -0
- package/build/utils/api.d.ts.map +1 -0
- package/build/utils/api.js +36 -0
- package/build/utils/api.js.map +1 -0
- package/build/utils/index.d.ts +3 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +3 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/session.d.ts +2 -0
- package/build/utils/session.d.ts.map +1 -1
- package/build/utils/session.js +12 -0
- package/build/utils/session.js.map +1 -1
- package/package.json +7 -5
- package/src/__tests__/session.tsx +43 -8
- package/src/components/index.tsx +2 -0
- package/src/contexts/api_provider.tsx +9 -8
- package/src/contexts/chat_context.tsx +34 -3
- package/src/contexts/index.ts +2 -0
- package/src/hooks/index.ts +2 -2
- package/src/index.tsx +4 -17
- package/src/utils/api.ts +47 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/session.ts +13 -0
- package/build/hooks/use_create_chat_theme.d.ts +0 -10
- package/build/hooks/use_create_chat_theme.d.ts.map +0 -1
- package/build/hooks/use_create_chat_theme.js +0 -20
- package/build/hooks/use_create_chat_theme.js.map +0 -1
- package/src/hooks/use_create_chat_theme.tsx +0 -31
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.tsx"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.tsx"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA","sourcesContent":["export * from './conversations'\nexport * from './error_boundary'\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_provider.d.ts","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api_provider.d.ts","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAiC,MAAM,uBAAuB,CAAA;AAClF,OAAO,KAAoB,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO,EAAE,GAAG,EAAW,MAAM,kBAAkB,CAAA;AAqB/C,eAAO,MAAM,WAAW,aAMtB,CAAA;AAEF,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,GAAkB,EAClB,KAAK,EACL,cAAc,GACf,EAAE,SAAS,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAAC,cAAc,EAAE,MAAM,IAAI,CAAA;CAAE,qBAU3E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import apiRequest from '../utils/api';
|
|
3
4
|
import { session } from '../utils/session';
|
|
4
5
|
let handleTokenExpired;
|
|
5
6
|
const defaultQueryFn = ({ queryKey }) => {
|
|
@@ -7,13 +8,8 @@ const defaultQueryFn = ({ queryKey }) => {
|
|
|
7
8
|
throw new Error('No token present');
|
|
8
9
|
}
|
|
9
10
|
const url = `${session.baseUrl}${queryKey[0]}`;
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
Authorization: `Bearer ${session.token?.access_token}`,
|
|
13
|
-
},
|
|
14
|
-
})
|
|
15
|
-
.then(validateResponse)
|
|
16
|
-
.then(response => response.json())
|
|
11
|
+
return apiRequest(url)
|
|
12
|
+
.then(r => r.json)
|
|
17
13
|
.catch(error => {
|
|
18
14
|
if (error.message === 'Token expired') {
|
|
19
15
|
handleTokenExpired();
|
|
@@ -32,6 +28,9 @@ export function ApiProvider({ children, env = 'production', token, onTokenExpire
|
|
|
32
28
|
session.env = env;
|
|
33
29
|
session.token = token;
|
|
34
30
|
handleTokenExpired = onTokenExpired;
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
queryClient.invalidateQueries();
|
|
33
|
+
}, [env, token]);
|
|
35
34
|
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
|
|
36
35
|
}
|
|
37
36
|
const validateResponse = (response) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_provider.js","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api_provider.js","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAY,MAAM,uBAAuB,CAAA;AAClF,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA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C,QAAQ,CAAC,EAAE,mBAAmB,CAAC,CAAA;AACnF,CAAC;AAED,MAAM,gBAAgB,GAAG,CAAC,QAAkB,EAAE,EAAE;IAC9C,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAA;IAEzC,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;IAClC,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import { JSONAPIResponse } from '@planningcenter/chat-core'\nimport { QueryClient, QueryClientProvider, QueryKey } from '@tanstack/react-query'\nimport React, { useEffect } from 'react'\nimport { ViewProps } from 'react-native'\nimport { OAuthToken } from '../types'\nimport apiRequest from '../utils/api'\nimport { ENV, session } from '../utils/session'\n\nlet handleTokenExpired: () => void\n\nconst defaultQueryFn = ({ queryKey }: { queryKey: QueryKey }) => {\n if (!session.token) {\n throw new Error('No token present')\n }\n\n const url = `${session.baseUrl}${queryKey[0]}`\n\n return apiRequest<JSONAPIResponse>(url)\n .then(r => r.json)\n .catch(error => {\n if (error.message === 'Token expired') {\n handleTokenExpired()\n }\n return null\n })\n}\n\nexport const queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n queryFn: defaultQueryFn,\n },\n },\n})\n\nexport function ApiProvider({\n children,\n env = 'production',\n token,\n onTokenExpired,\n}: ViewProps & { env?: ENV; token?: OAuthToken; onTokenExpired: () => void }) {\n session.env = env\n session.token = token\n handleTokenExpired = onTokenExpired\n\n useEffect(() => {\n queryClient.invalidateQueries()\n }, [env, token])\n\n return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>\n}\n\nconst validateResponse = (response: Response) => {\n const isExpired = response.status === 401\n\n if (isExpired) {\n throw new Error('Token expired')\n }\n\n return response\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ColorSchemeName } from 'react-native';
|
|
3
|
+
import { DeepPartial, OAuthToken } from '../types';
|
|
4
|
+
import { DefaultTheme } from '../utils/theme';
|
|
3
5
|
type ContextValue = {
|
|
4
6
|
token?: OAuthToken;
|
|
5
7
|
onTokenExpired: () => void;
|
|
@@ -11,5 +13,10 @@ export declare function ChatProvider({ children, value }: {
|
|
|
11
13
|
children: any;
|
|
12
14
|
value: ContextValue;
|
|
13
15
|
}): React.JSX.Element | null;
|
|
16
|
+
interface CreateChatThemeProps {
|
|
17
|
+
theme?: DeepPartial<DefaultTheme>;
|
|
18
|
+
colorScheme?: ColorSchemeName;
|
|
19
|
+
}
|
|
20
|
+
export declare const useCreateChatTheme: ({ theme: customTheme, colorScheme: appColorScheme, }: CreateChatThemeProps) => any;
|
|
14
21
|
export {};
|
|
15
22
|
//# sourceMappingURL=chat_context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_context.d.ts","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"
|
|
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,UAAU,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAgB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAI3D,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,KAAK,EAAE,GAAG,CAAA;IACV,GAAG,CAAC,EAAE,YAAY,GAAG,SAAS,GAAG,aAAa,CAAA;CAC/C,CAAA;AAED,eAAO,MAAM,WAAW,6BAKtB,CAAA;AAEF,wBAAgB,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,4BAYvF;AAED,UAAU,oBAAoB;IAC5B,KAAK,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;IACjC,WAAW,CAAC,EAAE,eAAe,CAAA;CAC9B;AAED,eAAO,MAAM,kBAAkB,yDAG5B,oBAAoB,QAetB,CAAA"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { merge } from 'lodash';
|
|
2
|
+
import React, { createContext, useMemo } from 'react';
|
|
3
|
+
import { useColorScheme } from 'react-native';
|
|
4
|
+
import { defaultTheme } from '../utils/theme';
|
|
5
|
+
import { tapestryAliasTokensColorMap } from '../vendor/tapestry/tapestry_alias_tokens_color_map';
|
|
2
6
|
import { ApiProvider } from './api_provider';
|
|
3
7
|
export const ChatContext = createContext({
|
|
4
8
|
theme: undefined,
|
|
@@ -7,12 +11,27 @@ export const ChatContext = createContext({
|
|
|
7
11
|
onTokenExpired: () => { },
|
|
8
12
|
});
|
|
9
13
|
export function ChatProvider({ children, value }) {
|
|
14
|
+
const theme = useCreateChatTheme(value.theme);
|
|
10
15
|
if (!Object.keys(value.token || {}).length)
|
|
11
16
|
return null;
|
|
12
|
-
return (<ChatContext.Provider value={value}>
|
|
17
|
+
return (<ChatContext.Provider value={{ ...value, theme }}>
|
|
13
18
|
<ApiProvider env={value.env} token={value.token} onTokenExpired={value.onTokenExpired}>
|
|
14
19
|
{children}
|
|
15
20
|
</ApiProvider>
|
|
16
21
|
</ChatContext.Provider>);
|
|
17
22
|
}
|
|
23
|
+
export const useCreateChatTheme = ({ theme: customTheme = {}, colorScheme: appColorScheme, }) => {
|
|
24
|
+
const internalColorScheme = useColorScheme() || 'light';
|
|
25
|
+
const colorScheme = appColorScheme || internalColorScheme;
|
|
26
|
+
const memoizedTheme = useMemo(() => {
|
|
27
|
+
return {
|
|
28
|
+
...merge({}, defaultTheme(colorScheme), customTheme),
|
|
29
|
+
colors: {
|
|
30
|
+
...merge({}, defaultTheme(colorScheme).colors, customTheme?.colors),
|
|
31
|
+
...tapestryAliasTokensColorMap[colorScheme],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}, [colorScheme, customTheme]);
|
|
35
|
+
return memoizedTheme;
|
|
36
|
+
};
|
|
18
37
|
//# sourceMappingURL=chat_context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_context.js","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"chat_context.js","sourceRoot":"","sources":["../../src/contexts/chat_context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC9B,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACrD,OAAO,EAAmB,cAAc,EAAE,MAAM,cAAc,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAgB,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oDAAoD,CAAA;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAS5C,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAe;IACrD,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,SAAS;IAChB,GAAG,EAAE,SAAS;IACd,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;CACzB,CAAC,CAAA;AAEF,MAAM,UAAU,YAAY,CAAC,EAAE,QAAQ,EAAE,KAAK,EAA0C;IACtF,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAE7C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAEvD,OAAO,CACL,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC,CAC/C;MAAA,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CACpF;QAAA,CAAC,QAAQ,CACX;MAAA,EAAE,WAAW,CACf;IAAA,EAAE,WAAW,CAAC,QAAQ,CAAC,CACxB,CAAA;AACH,CAAC;AAOD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EACjC,KAAK,EAAE,WAAW,GAAG,EAAE,EACvB,WAAW,EAAE,cAAc,GACN,EAAE,EAAE;IACzB,MAAM,mBAAmB,GAAG,cAAc,EAAE,IAAI,OAAO,CAAA;IACvD,MAAM,WAAW,GAAG,cAAc,IAAI,mBAAmB,CAAA;IAEzD,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE;QACjC,OAAO;YACL,GAAG,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;YACpD,MAAM,EAAE;gBACN,GAAG,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC;gBACnE,GAAG,2BAA2B,CAAC,WAAW,CAAC;aAC5C;SACF,CAAA;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAA;IAE9B,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import { merge } from 'lodash'\nimport React, { createContext, useMemo } from 'react'\nimport { ColorSchemeName, useColorScheme } from 'react-native'\nimport { DeepPartial, OAuthToken } from '../types'\nimport { defaultTheme, DefaultTheme } from '../utils/theme'\nimport { tapestryAliasTokensColorMap } from '../vendor/tapestry/tapestry_alias_tokens_color_map'\nimport { ApiProvider } from './api_provider'\n\ntype ContextValue = {\n token?: OAuthToken\n onTokenExpired: () => void\n theme: any\n env?: 'production' | 'staging' | 'development'\n}\n\nexport const ChatContext = createContext<ContextValue>({\n theme: undefined,\n token: undefined,\n env: undefined,\n onTokenExpired: () => {},\n})\n\nexport function ChatProvider({ children, value }: { children: any; value: ContextValue }) {\n const theme = useCreateChatTheme(value.theme)\n\n if (!Object.keys(value.token || {}).length) return null\n\n return (\n <ChatContext.Provider value={{ ...value, theme }}>\n <ApiProvider env={value.env} token={value.token} onTokenExpired={value.onTokenExpired}>\n {children}\n </ApiProvider>\n </ChatContext.Provider>\n )\n}\n\ninterface CreateChatThemeProps {\n theme?: DeepPartial<DefaultTheme>\n colorScheme?: ColorSchemeName\n}\n\nexport const useCreateChatTheme = ({\n theme: customTheme = {},\n colorScheme: appColorScheme,\n}: CreateChatThemeProps) => {\n const internalColorScheme = useColorScheme() || 'light'\n const colorScheme = appColorScheme || internalColorScheme\n\n const memoizedTheme = useMemo(() => {\n return {\n ...merge({}, defaultTheme(colorScheme), customTheme),\n colors: {\n ...merge({}, defaultTheme(colorScheme).colors, customTheme?.colors),\n ...tapestryAliasTokensColorMap[colorScheme],\n },\n }\n }, [colorScheme, customTheme])\n\n return memoizedTheme\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA","sourcesContent":["export * from './api_provider'\nexport * from './chat_context'\n"]}
|
package/build/hooks/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './use_async_storage';
|
|
2
|
+
export * from './use_theme';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA"}
|
package/build/hooks/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './use_async_storage';
|
|
2
|
+
export * from './use_theme';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/build/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA","sourcesContent":["export * from './use_async_storage'\nexport * from './use_theme'\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { baseUrlMap, uploadUrlMap } from './utils/session';
|
|
6
|
-
import { TemporaryDefaultColorsType } from './utils/theme';
|
|
7
|
-
export { baseUrlMap, ChatContext, ChatProvider, Conversations, OAuthToken, TemporaryDefaultColorsType, uploadUrlMap, useCreateChatTheme, };
|
|
1
|
+
export * from './components';
|
|
2
|
+
export * from './contexts';
|
|
3
|
+
export * from './hooks';
|
|
4
|
+
export * from './utils';
|
|
8
5
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { baseUrlMap, ChatContext, ChatProvider, Conversations, uploadUrlMap, useCreateChatTheme, };
|
|
1
|
+
export * from './components';
|
|
2
|
+
export * from './contexts';
|
|
3
|
+
export * from './hooks';
|
|
4
|
+
export * from './utils';
|
|
6
5
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA","sourcesContent":["export * from './components'\nexport * from './contexts'\nexport * from './hooks'\nexport * from './utils'\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,GAAG,OAAO,EAC5C,GAAG,EAAE,MAAM,EACX,EAAE,MAAc,EAAE,IAAW,EAAE;;;CAAK,GACnC,OAAO,CAAC;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,CAuBvD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import DeviceInfo from 'react-native-device-info';
|
|
2
|
+
import { session } from './session';
|
|
3
|
+
const brand = DeviceInfo.getBrand();
|
|
4
|
+
const model = DeviceInfo.getModel();
|
|
5
|
+
const systemName = DeviceInfo.getSystemName();
|
|
6
|
+
const systemVersion = DeviceInfo.getSystemVersion();
|
|
7
|
+
const readableVersion = DeviceInfo.getReadableVersion();
|
|
8
|
+
const appName = DeviceInfo.getApplicationName();
|
|
9
|
+
export default function apiRequest(url, { method = 'GET', data = null } = {}) {
|
|
10
|
+
const options = {
|
|
11
|
+
headers: {
|
|
12
|
+
Accept: 'application/vnd.api+json',
|
|
13
|
+
'Content-Type': 'application/json',
|
|
14
|
+
'User-Agent': `${appName}/${readableVersion} (${brand}, ${model}, ${systemName}, ${systemVersion})`,
|
|
15
|
+
Authorization: `Bearer ${session.token?.access_token}`,
|
|
16
|
+
},
|
|
17
|
+
method,
|
|
18
|
+
};
|
|
19
|
+
if (data && method !== 'GET') {
|
|
20
|
+
options.body = JSON.stringify(data);
|
|
21
|
+
}
|
|
22
|
+
return fetch(url, options)
|
|
23
|
+
.then(validateResponse)
|
|
24
|
+
.then(response => response
|
|
25
|
+
.json()
|
|
26
|
+
.then(json => ({ json: json, ok: response.ok, response }))
|
|
27
|
+
.catch(() => ({ json: null, ok: response.ok, response })));
|
|
28
|
+
}
|
|
29
|
+
const validateResponse = (response) => {
|
|
30
|
+
const isExpired = response.status === 401;
|
|
31
|
+
if (isExpired) {
|
|
32
|
+
throw new Error('Token expired');
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/utils/api.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA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AAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,CACjE,CAAA;AACL,CAAC;AAED,MAAM,gBAAgB,GAAG,CAAC,QAAkB,EAAE,EAAE;IAC9C,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAA;IAEzC,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;IAClC,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA","sourcesContent":["import DeviceInfo from 'react-native-device-info'\nimport { session } from './session'\n\nconst brand = DeviceInfo.getBrand()\nconst model = DeviceInfo.getModel()\nconst systemName = DeviceInfo.getSystemName()\nconst systemVersion = DeviceInfo.getSystemVersion()\nconst readableVersion = DeviceInfo.getReadableVersion()\nconst appName = DeviceInfo.getApplicationName()\n\nexport default function apiRequest<T = unknown>(\n url: string,\n { method = 'GET', data = null } = {}\n): Promise<{ json: T; ok: boolean; response: Response }> {\n const options: RequestInit = {\n headers: {\n Accept: 'application/vnd.api+json',\n 'Content-Type': 'application/json',\n 'User-Agent': `${appName}/${readableVersion} (${brand}, ${model}, ${systemName}, ${systemVersion})`,\n Authorization: `Bearer ${session.token?.access_token}`,\n },\n method,\n }\n\n if (data && method !== 'GET') {\n options.body = JSON.stringify(data)\n }\n\n return fetch(url, options)\n .then(validateResponse)\n .then(response =>\n response\n .json()\n .then(json => ({ json: json as T, ok: response.ok, response }))\n .catch(() => ({ json: null as T, ok: response.ok, response }))\n )\n}\n\nconst validateResponse = (response: Response) => {\n const isExpired = response.status === 401\n\n if (isExpired) {\n throw new Error('Token expired')\n }\n\n return response\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA","sourcesContent":["export * from './session'\nexport * from './theme'\n"]}
|
package/build/utils/session.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/utils/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,MAAM,MAAM,GAAG,GAAG,YAAY,GAAG,SAAS,GAAG,aAAa,CAAA;AAE1D,eAAO,MAAM,UAAU;;;;CAItB,CAAA;AAED,eAAO,MAAM,YAAY;;;;CAIxB,CAAA;AAED,KAAK,YAAY,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,UAAU,CAAA;CAAE,GAAG,SAAS,CAAA;AAEjE;;;;GAIG;AACH,qBAAa,OAAO;IAClB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,UAAU,GAAG,SAAS,CAAA;gBAEjB,KAAK,CAAC,EAAE,YAAY;IAMhC,IAAI,eAAe,YAElB;IAED,IAAI,OAAO,WAEV;IAED,IAAI,SAAS,WAEZ;
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/utils/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,MAAM,MAAM,GAAG,GAAG,YAAY,GAAG,SAAS,GAAG,aAAa,CAAA;AAE1D,eAAO,MAAM,UAAU;;;;CAItB,CAAA;AAED,eAAO,MAAM,YAAY;;;;CAIxB,CAAA;AAED,KAAK,YAAY,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,UAAU,CAAA;CAAE,GAAG,SAAS,CAAA;AAEjE;;;;GAIG;AACH,qBAAa,OAAO;IAClB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,UAAU,GAAG,SAAS,CAAA;gBAEjB,KAAK,CAAC,EAAE,YAAY;IAMhC,IAAI,eAAe,YAElB;IAED,IAAI,OAAO,WAEV;IAED,IAAI,SAAS,WAEZ;IAED,QAAQ;IAIR,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM;CAQrC;AAED,eAAO,MAAM,OAAO,SAAsC,CAAA"}
|
package/build/utils/session.js
CHANGED
|
@@ -30,6 +30,18 @@ export class Session {
|
|
|
30
30
|
get uploadUrl() {
|
|
31
31
|
return uploadUrlMap[this.env];
|
|
32
32
|
}
|
|
33
|
+
toString() {
|
|
34
|
+
return JSON.stringify({ env: this.env, token: this.token });
|
|
35
|
+
}
|
|
36
|
+
static hydrate(sessionString) {
|
|
37
|
+
try {
|
|
38
|
+
const props = JSON.parse(sessionString);
|
|
39
|
+
return new Session(props);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return new Session();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
33
45
|
}
|
|
34
46
|
export const session = new Session({ env: 'development' });
|
|
35
47
|
//# sourceMappingURL=session.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/utils/session.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,UAAU,EAAE,sCAAsC;IAClD,OAAO,EAAE,8CAA8C;IACvD,WAAW,EAAE,qBAAqB;CACnC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,UAAU,EAAE,kDAAkD;IAC9D,OAAO,EAAE,0DAA0D;IACnE,WAAW,EAAE,kDAAkD;CAChE,CAAA;AAID;;;;GAIG;AACH,MAAM,OAAO,OAAO;IAClB,GAAG,CAAK;IACR,KAAK,CAAwB;IAE7B,YAAY,KAAoB;QAC9B,MAAM,EAAE,GAAG,GAAG,aAAa,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,EAAE,CAAA;QAClD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC7B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC/B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC,CAAA","sourcesContent":["import { OAuthToken } from '../types'\n\nexport type ENV = 'production' | 'staging' | 'development'\n\nexport const baseUrlMap = {\n production: 'https://api.planningcenteronline.com',\n staging: 'https://api-staging.planningcenteronline.com',\n development: 'http://api.pco.test',\n}\n\nexport const uploadUrlMap = {\n production: 'https://upload.planningcenteronline.com/v2/files',\n staging: 'https://upload-staging.planningcenteronline.com/v2/files',\n development: 'https://upload.planningcenteronline.com/v2/files',\n}\n\ntype SessionProps = { env?: ENV; token?: OAuthToken } | undefined\n\n/**\n * Session class to track the environment and token\n * Not intended to make network requests or handle authentication\n * - returns urls for convenience only\n */\nexport class Session {\n env: ENV\n token: OAuthToken | undefined\n\n constructor(props?: SessionProps) {\n const { env = 'development', token } = props || {}\n this.env = env\n this.token = token\n }\n\n get isAuthenticated() {\n return Boolean(this.token)\n }\n\n get baseUrl() {\n return baseUrlMap[this.env]\n }\n\n get uploadUrl() {\n return uploadUrlMap[this.env]\n }\n}\n\nexport const session = new Session({ env: 'development' })\n"]}
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/utils/session.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,UAAU,EAAE,sCAAs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,CAAA","sourcesContent":["import { OAuthToken } from '../types'\n\nexport type ENV = 'production' | 'staging' | 'development'\n\nexport const baseUrlMap = {\n production: 'https://api.planningcenteronline.com',\n staging: 'https://api-staging.planningcenteronline.com',\n development: 'http://api.pco.test',\n}\n\nexport const uploadUrlMap = {\n production: 'https://upload.planningcenteronline.com/v2/files',\n staging: 'https://upload-staging.planningcenteronline.com/v2/files',\n development: 'https://upload.planningcenteronline.com/v2/files',\n}\n\ntype SessionProps = { env?: ENV; token?: OAuthToken } | undefined\n\n/**\n * Session class to track the environment and token\n * Not intended to make network requests or handle authentication\n * - returns urls for convenience only\n */\nexport class Session {\n env: ENV\n token: OAuthToken | undefined\n\n constructor(props?: SessionProps) {\n const { env = 'development', token } = props || {}\n this.env = env\n this.token = token\n }\n\n get isAuthenticated() {\n return Boolean(this.token)\n }\n\n get baseUrl() {\n return baseUrlMap[this.env]\n }\n\n get uploadUrl() {\n return uploadUrlMap[this.env]\n }\n\n toString() {\n return JSON.stringify({ env: this.env, token: this.token })\n }\n\n static hydrate(sessionString: string) {\n try {\n const props = JSON.parse(sessionString)\n return new Session(props)\n } catch (error) {\n return new Session()\n }\n }\n}\n\nexport const session = new Session({ env: 'development' })\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "1.4.0",
|
|
3
|
+
"version": "1.4.1-qa-72.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"prepublishOnly": "expo-module prepublishOnly"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@planningcenter/chat-core": "^1.4.0"
|
|
20
|
+
"@planningcenter/chat-core": "^1.4.1-qa-72.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@react-navigation/elements": "*",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"@tanstack/react-query": "^5.0.0",
|
|
26
26
|
"lodash": "*",
|
|
27
27
|
"react": "*",
|
|
28
|
-
"react-native": "*"
|
|
28
|
+
"react-native": "*",
|
|
29
|
+
"react-native-device-info": "*"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@react-native/eslint-config": "^0.77.0",
|
|
@@ -36,7 +37,8 @@
|
|
|
36
37
|
"expo-module-scripts": "^4.0.3",
|
|
37
38
|
"lodash": "^4.17.21",
|
|
38
39
|
"prettier": "^3.4.2",
|
|
39
|
-
"react-native": "0.74.5"
|
|
40
|
+
"react-native": "0.74.5",
|
|
41
|
+
"react-native-device-info": "^14.0.4"
|
|
40
42
|
},
|
|
41
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "ffcbba154e5eebf8049142ffe9721c34fa90c625"
|
|
42
44
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { OAuthToken } from '../types'
|
|
2
2
|
import { Session } from '../utils/session'
|
|
3
3
|
|
|
4
|
+
const token: OAuthToken = {
|
|
5
|
+
access_token: 'access_token',
|
|
6
|
+
refresh_token: 'refresh_token',
|
|
7
|
+
token_type: undefined,
|
|
8
|
+
created_at: 0,
|
|
9
|
+
expires_in: undefined,
|
|
10
|
+
scope: '',
|
|
11
|
+
}
|
|
12
|
+
|
|
4
13
|
describe('Session', () => {
|
|
5
14
|
describe('constructor', () => {
|
|
6
15
|
it('should track the environment', () => {
|
|
@@ -10,14 +19,6 @@ describe('Session', () => {
|
|
|
10
19
|
})
|
|
11
20
|
|
|
12
21
|
it('should track the token', () => {
|
|
13
|
-
const token: OAuthToken = {
|
|
14
|
-
access_token: 'access_token',
|
|
15
|
-
refresh_token: 'refresh_token',
|
|
16
|
-
token_type: undefined,
|
|
17
|
-
created_at: 0,
|
|
18
|
-
expires_in: undefined,
|
|
19
|
-
scope: '',
|
|
20
|
-
}
|
|
21
22
|
const session = new Session({ token })
|
|
22
23
|
expect(session.token).toEqual(token)
|
|
23
24
|
expect(session.isAuthenticated).toEqual(true)
|
|
@@ -43,4 +44,38 @@ describe('Session', () => {
|
|
|
43
44
|
expect(session.uploadUrl).toBe('https://upload-staging.planningcenteronline.com/v2/files')
|
|
44
45
|
})
|
|
45
46
|
})
|
|
47
|
+
|
|
48
|
+
describe('hydrate', () => {
|
|
49
|
+
describe('success', () => {
|
|
50
|
+
it('should return a hydrated Session instance', () => {
|
|
51
|
+
const session = new Session({ token })
|
|
52
|
+
expect(session.token).toEqual(token)
|
|
53
|
+
expect(session.isAuthenticated).toEqual(true)
|
|
54
|
+
|
|
55
|
+
const sessionString = session.toString()
|
|
56
|
+
const hydratedSession = Session.hydrate(sessionString)
|
|
57
|
+
expect(hydratedSession.token).toEqual(token)
|
|
58
|
+
expect(hydratedSession.isAuthenticated).toEqual(true)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should store the environment of hydrated Session instance', () => {
|
|
62
|
+
const env = 'production'
|
|
63
|
+
const session = new Session({ token, env })
|
|
64
|
+
|
|
65
|
+
const sessionString = session.toString()
|
|
66
|
+
const hydratedSession = Session.hydrate(sessionString)
|
|
67
|
+
expect(hydratedSession.env).toEqual(env)
|
|
68
|
+
expect(hydratedSession.token).toEqual(token)
|
|
69
|
+
expect(hydratedSession.isAuthenticated).toEqual(true)
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('failure', () => {
|
|
74
|
+
it('should return a new Session instance', () => {
|
|
75
|
+
const session = Session.hydrate('')
|
|
76
|
+
expect(session.env).toBe('development')
|
|
77
|
+
expect(session.isAuthenticated).toBe(false)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
})
|
|
46
81
|
})
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { JSONAPIResponse } from '@planningcenter/chat-core'
|
|
1
2
|
import { QueryClient, QueryClientProvider, QueryKey } from '@tanstack/react-query'
|
|
2
|
-
import React from 'react'
|
|
3
|
+
import React, { useEffect } from 'react'
|
|
3
4
|
import { ViewProps } from 'react-native'
|
|
4
5
|
import { OAuthToken } from '../types'
|
|
6
|
+
import apiRequest from '../utils/api'
|
|
5
7
|
import { ENV, session } from '../utils/session'
|
|
6
8
|
|
|
7
9
|
let handleTokenExpired: () => void
|
|
@@ -13,13 +15,8 @@ const defaultQueryFn = ({ queryKey }: { queryKey: QueryKey }) => {
|
|
|
13
15
|
|
|
14
16
|
const url = `${session.baseUrl}${queryKey[0]}`
|
|
15
17
|
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
Authorization: `Bearer ${session.token?.access_token}`,
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
.then(validateResponse)
|
|
22
|
-
.then(response => response.json())
|
|
18
|
+
return apiRequest<JSONAPIResponse>(url)
|
|
19
|
+
.then(r => r.json)
|
|
23
20
|
.catch(error => {
|
|
24
21
|
if (error.message === 'Token expired') {
|
|
25
22
|
handleTokenExpired()
|
|
@@ -46,6 +43,10 @@ export function ApiProvider({
|
|
|
46
43
|
session.token = token
|
|
47
44
|
handleTokenExpired = onTokenExpired
|
|
48
45
|
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
queryClient.invalidateQueries()
|
|
48
|
+
}, [env, token])
|
|
49
|
+
|
|
49
50
|
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { merge } from 'lodash'
|
|
2
|
+
import React, { createContext, useMemo } from 'react'
|
|
3
|
+
import { ColorSchemeName, useColorScheme } from 'react-native'
|
|
4
|
+
import { DeepPartial, OAuthToken } from '../types'
|
|
5
|
+
import { defaultTheme, DefaultTheme } from '../utils/theme'
|
|
6
|
+
import { tapestryAliasTokensColorMap } from '../vendor/tapestry/tapestry_alias_tokens_color_map'
|
|
3
7
|
import { ApiProvider } from './api_provider'
|
|
4
8
|
|
|
5
9
|
type ContextValue = {
|
|
@@ -17,13 +21,40 @@ export const ChatContext = createContext<ContextValue>({
|
|
|
17
21
|
})
|
|
18
22
|
|
|
19
23
|
export function ChatProvider({ children, value }: { children: any; value: ContextValue }) {
|
|
24
|
+
const theme = useCreateChatTheme(value.theme)
|
|
25
|
+
|
|
20
26
|
if (!Object.keys(value.token || {}).length) return null
|
|
21
27
|
|
|
22
28
|
return (
|
|
23
|
-
<ChatContext.Provider value={value}>
|
|
29
|
+
<ChatContext.Provider value={{ ...value, theme }}>
|
|
24
30
|
<ApiProvider env={value.env} token={value.token} onTokenExpired={value.onTokenExpired}>
|
|
25
31
|
{children}
|
|
26
32
|
</ApiProvider>
|
|
27
33
|
</ChatContext.Provider>
|
|
28
34
|
)
|
|
29
35
|
}
|
|
36
|
+
|
|
37
|
+
interface CreateChatThemeProps {
|
|
38
|
+
theme?: DeepPartial<DefaultTheme>
|
|
39
|
+
colorScheme?: ColorSchemeName
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const useCreateChatTheme = ({
|
|
43
|
+
theme: customTheme = {},
|
|
44
|
+
colorScheme: appColorScheme,
|
|
45
|
+
}: CreateChatThemeProps) => {
|
|
46
|
+
const internalColorScheme = useColorScheme() || 'light'
|
|
47
|
+
const colorScheme = appColorScheme || internalColorScheme
|
|
48
|
+
|
|
49
|
+
const memoizedTheme = useMemo(() => {
|
|
50
|
+
return {
|
|
51
|
+
...merge({}, defaultTheme(colorScheme), customTheme),
|
|
52
|
+
colors: {
|
|
53
|
+
...merge({}, defaultTheme(colorScheme).colors, customTheme?.colors),
|
|
54
|
+
...tapestryAliasTokensColorMap[colorScheme],
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
}, [colorScheme, customTheme])
|
|
58
|
+
|
|
59
|
+
return memoizedTheme
|
|
60
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './use_async_storage'
|
|
2
|
+
export * from './use_theme'
|
package/src/index.tsx
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { baseUrlMap, uploadUrlMap } from './utils/session'
|
|
6
|
-
import { TemporaryDefaultColorsType } from './utils/theme'
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
baseUrlMap,
|
|
10
|
-
ChatContext,
|
|
11
|
-
ChatProvider,
|
|
12
|
-
Conversations,
|
|
13
|
-
OAuthToken,
|
|
14
|
-
TemporaryDefaultColorsType,
|
|
15
|
-
uploadUrlMap,
|
|
16
|
-
useCreateChatTheme,
|
|
17
|
-
}
|
|
1
|
+
export * from './components'
|
|
2
|
+
export * from './contexts'
|
|
3
|
+
export * from './hooks'
|
|
4
|
+
export * from './utils'
|
package/src/utils/api.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import DeviceInfo from 'react-native-device-info'
|
|
2
|
+
import { session } from './session'
|
|
3
|
+
|
|
4
|
+
const brand = DeviceInfo.getBrand()
|
|
5
|
+
const model = DeviceInfo.getModel()
|
|
6
|
+
const systemName = DeviceInfo.getSystemName()
|
|
7
|
+
const systemVersion = DeviceInfo.getSystemVersion()
|
|
8
|
+
const readableVersion = DeviceInfo.getReadableVersion()
|
|
9
|
+
const appName = DeviceInfo.getApplicationName()
|
|
10
|
+
|
|
11
|
+
export default function apiRequest<T = unknown>(
|
|
12
|
+
url: string,
|
|
13
|
+
{ method = 'GET', data = null } = {}
|
|
14
|
+
): Promise<{ json: T; ok: boolean; response: Response }> {
|
|
15
|
+
const options: RequestInit = {
|
|
16
|
+
headers: {
|
|
17
|
+
Accept: 'application/vnd.api+json',
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
'User-Agent': `${appName}/${readableVersion} (${brand}, ${model}, ${systemName}, ${systemVersion})`,
|
|
20
|
+
Authorization: `Bearer ${session.token?.access_token}`,
|
|
21
|
+
},
|
|
22
|
+
method,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (data && method !== 'GET') {
|
|
26
|
+
options.body = JSON.stringify(data)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return fetch(url, options)
|
|
30
|
+
.then(validateResponse)
|
|
31
|
+
.then(response =>
|
|
32
|
+
response
|
|
33
|
+
.json()
|
|
34
|
+
.then(json => ({ json: json as T, ok: response.ok, response }))
|
|
35
|
+
.catch(() => ({ json: null as T, ok: response.ok, response }))
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const validateResponse = (response: Response) => {
|
|
40
|
+
const isExpired = response.status === 401
|
|
41
|
+
|
|
42
|
+
if (isExpired) {
|
|
43
|
+
throw new Error('Token expired')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return response
|
|
47
|
+
}
|
package/src/utils/session.ts
CHANGED
|
@@ -42,6 +42,19 @@ export class Session {
|
|
|
42
42
|
get uploadUrl() {
|
|
43
43
|
return uploadUrlMap[this.env]
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
toString() {
|
|
47
|
+
return JSON.stringify({ env: this.env, token: this.token })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static hydrate(sessionString: string) {
|
|
51
|
+
try {
|
|
52
|
+
const props = JSON.parse(sessionString)
|
|
53
|
+
return new Session(props)
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return new Session()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
45
58
|
}
|
|
46
59
|
|
|
47
60
|
export const session = new Session({ env: 'development' })
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ColorSchemeName } from 'react-native';
|
|
2
|
-
import { DefaultTheme } from '../utils/theme';
|
|
3
|
-
import { DeepPartial } from '../types';
|
|
4
|
-
interface CreateChatThemeProps {
|
|
5
|
-
theme?: DeepPartial<DefaultTheme>;
|
|
6
|
-
colorScheme?: ColorSchemeName;
|
|
7
|
-
}
|
|
8
|
-
export declare const useCreateChatTheme: ({ theme: customTheme, colorScheme: appColorScheme, }: CreateChatThemeProps) => any;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=use_create_chat_theme.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use_create_chat_theme.d.ts","sourceRoot":"","sources":["../../src/hooks/use_create_chat_theme.tsx"],"names":[],"mappings":"AACA,OAAO,EAAkB,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAgB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAItC,UAAU,oBAAoB;IAC5B,KAAK,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;IACjC,WAAW,CAAC,EAAE,eAAe,CAAA;CAC9B;AAED,eAAO,MAAM,kBAAkB,yDAG5B,oBAAoB,QAetB,CAAA"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { useColorScheme } from 'react-native';
|
|
3
|
-
import { defaultTheme } from '../utils/theme';
|
|
4
|
-
import { tapestryAliasTokensColorMap } from '../vendor/tapestry/tapestry_alias_tokens_color_map';
|
|
5
|
-
import { merge } from 'lodash';
|
|
6
|
-
export const useCreateChatTheme = ({ theme: customTheme = {}, colorScheme: appColorScheme, }) => {
|
|
7
|
-
const internalColorScheme = useColorScheme() || 'light';
|
|
8
|
-
const colorScheme = appColorScheme || internalColorScheme;
|
|
9
|
-
const memoizedTheme = useMemo(() => {
|
|
10
|
-
return {
|
|
11
|
-
...merge({}, defaultTheme(colorScheme), customTheme),
|
|
12
|
-
colors: {
|
|
13
|
-
...merge({}, defaultTheme(colorScheme).colors, customTheme?.colors),
|
|
14
|
-
...tapestryAliasTokensColorMap[colorScheme],
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}, [colorScheme, customTheme]);
|
|
18
|
-
return memoizedTheme;
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=use_create_chat_theme.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use_create_chat_theme.js","sourceRoot":"","sources":["../../src/hooks/use_create_chat_theme.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,cAAc,EAAmB,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAgB,MAAM,gBAAgB,CAAA;AAE3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oDAAoD,CAAA;AAChG,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAO9B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EACjC,KAAK,EAAE,WAAW,GAAG,EAAE,EACvB,WAAW,EAAE,cAAc,GACN,EAAE,EAAE;IACzB,MAAM,mBAAmB,GAAG,cAAc,EAAE,IAAI,OAAO,CAAA;IACvD,MAAM,WAAW,GAAG,cAAc,IAAI,mBAAmB,CAAA;IAEzD,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE;QACjC,OAAO;YACL,GAAG,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;YACpD,MAAM,EAAE;gBACN,GAAG,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC;gBACnE,GAAG,2BAA2B,CAAC,WAAW,CAAC;aAC5C;SACF,CAAA;IACH,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAA;IAE9B,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import { useMemo } from 'react'\nimport { useColorScheme, ColorSchemeName } from 'react-native'\nimport { defaultTheme, DefaultTheme } from '../utils/theme'\nimport { DeepPartial } from '../types'\nimport { tapestryAliasTokensColorMap } from '../vendor/tapestry/tapestry_alias_tokens_color_map'\nimport { merge } from 'lodash'\n\ninterface CreateChatThemeProps {\n theme?: DeepPartial<DefaultTheme>\n colorScheme?: ColorSchemeName\n}\n\nexport const useCreateChatTheme = ({\n theme: customTheme = {},\n colorScheme: appColorScheme,\n}: CreateChatThemeProps) => {\n const internalColorScheme = useColorScheme() || 'light'\n const colorScheme = appColorScheme || internalColorScheme\n\n const memoizedTheme = useMemo(() => {\n return {\n ...merge({}, defaultTheme(colorScheme), customTheme),\n colors: {\n ...merge({}, defaultTheme(colorScheme).colors, customTheme?.colors),\n ...tapestryAliasTokensColorMap[colorScheme],\n },\n }\n }, [colorScheme, customTheme])\n\n return memoizedTheme\n}\n"]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
2
|
-
import { useColorScheme, ColorSchemeName } from 'react-native'
|
|
3
|
-
import { defaultTheme, DefaultTheme } from '../utils/theme'
|
|
4
|
-
import { DeepPartial } from '../types'
|
|
5
|
-
import { tapestryAliasTokensColorMap } from '../vendor/tapestry/tapestry_alias_tokens_color_map'
|
|
6
|
-
import { merge } from 'lodash'
|
|
7
|
-
|
|
8
|
-
interface CreateChatThemeProps {
|
|
9
|
-
theme?: DeepPartial<DefaultTheme>
|
|
10
|
-
colorScheme?: ColorSchemeName
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const useCreateChatTheme = ({
|
|
14
|
-
theme: customTheme = {},
|
|
15
|
-
colorScheme: appColorScheme,
|
|
16
|
-
}: CreateChatThemeProps) => {
|
|
17
|
-
const internalColorScheme = useColorScheme() || 'light'
|
|
18
|
-
const colorScheme = appColorScheme || internalColorScheme
|
|
19
|
-
|
|
20
|
-
const memoizedTheme = useMemo(() => {
|
|
21
|
-
return {
|
|
22
|
-
...merge({}, defaultTheme(colorScheme), customTheme),
|
|
23
|
-
colors: {
|
|
24
|
-
...merge({}, defaultTheme(colorScheme).colors, customTheme?.colors),
|
|
25
|
-
...tapestryAliasTokensColorMap[colorScheme],
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
}, [colorScheme, customTheme])
|
|
29
|
-
|
|
30
|
-
return memoizedTheme
|
|
31
|
-
}
|