@planningcenter/chat-react-native 4.6.4-qa-staging.0 → 4.6.4-qa-staging.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/contexts/api_provider.js +39 -33
- package/build/contexts/api_provider.js.map +1 -1
- package/build/contexts/chat_context.d.ts +1 -0
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +28 -25
- package/build/contexts/chat_context.js.map +1 -1
- package/build/contexts/session_context.d.ts +2 -1
- package/build/contexts/session_context.d.ts.map +1 -1
- package/build/contexts/session_context.js +10 -6
- package/build/contexts/session_context.js.map +1 -1
- package/build/hooks/use_current_person.d.ts.map +1 -1
- package/build/hooks/use_current_person.js +1 -1
- package/build/hooks/use_current_person.js.map +1 -1
- package/build/hooks/use_person_settings.d.ts +1 -0
- package/build/hooks/use_person_settings.d.ts.map +1 -1
- package/build/hooks/use_person_settings.js +10 -7
- package/build/hooks/use_person_settings.js.map +1 -1
- package/build/screens/settings_screen.js +6 -6
- package/build/screens/settings_screen.js.map +1 -1
- package/build/types/resources/person.d.ts +1 -0
- package/build/types/resources/person.d.ts.map +1 -1
- package/build/types/resources/person.js.map +1 -1
- package/build/utils/session.d.ts +3 -1
- package/build/utils/session.d.ts.map +1 -1
- package/build/utils/session.js +3 -0
- package/build/utils/session.js.map +1 -1
- package/build/utils/session_manager.d.ts +1 -1
- package/build/utils/session_manager.d.ts.map +1 -1
- package/build/utils/session_manager.js +2 -1
- package/build/utils/session_manager.js.map +1 -1
- package/build/utils/upload_uri.d.ts.map +1 -1
- package/build/utils/upload_uri.js +3 -0
- package/build/utils/upload_uri.js.map +1 -1
- package/build/utils/uri.d.ts.map +1 -1
- package/build/utils/uri.js +4 -0
- package/build/utils/uri.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/hooks/use_person_settings.test.tsx +53 -0
- package/src/__tests__/screens/settings_screen.test.tsx +58 -0
- package/src/contexts/__tests__/api_provider.test.tsx +17 -4
- package/src/contexts/api_provider.tsx +13 -6
- package/src/contexts/chat_context.tsx +4 -2
- package/src/contexts/session_context.tsx +18 -10
- package/src/hooks/use_current_person.ts +1 -0
- package/src/hooks/use_person_settings.ts +3 -1
- package/src/screens/settings_screen.tsx +4 -4
- package/src/types/resources/person.ts +1 -0
- package/src/utils/__tests__/session_manager.test.ts +12 -0
- package/src/utils/__tests__/uri.test.ts +26 -0
- package/src/utils/session.ts +11 -3
- package/src/utils/session_manager.ts +2 -1
- package/src/utils/upload_uri.ts +4 -0
- package/src/utils/uri.ts +5 -0
|
@@ -56,8 +56,8 @@ export const chatQueryClient = new QueryClient({
|
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
export function ApiProvider({ children }: ViewProps) {
|
|
59
|
-
const { token, env, session } = useContext(ChatContext)
|
|
60
|
-
const sessionChanged = useSessionChanged({ token, env })
|
|
59
|
+
const { token, env, prototypeName, session } = useContext(ChatContext)
|
|
60
|
+
const sessionChanged = useSessionChanged({ token, env, prototypeName })
|
|
61
61
|
|
|
62
62
|
const client = useApiClient()
|
|
63
63
|
|
|
@@ -115,9 +115,15 @@ export function useFocusManager() {
|
|
|
115
115
|
return appState
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
function useSessionChanged(
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
function useSessionChanged(
|
|
119
|
+
value: Pick<ChatContextValue, 'token' | 'env' | 'prototypeName'>
|
|
120
|
+
): boolean {
|
|
121
|
+
const { token: newToken, env: newEnv, prototypeName: newPrototypeName } = value
|
|
122
|
+
const {
|
|
123
|
+
token: prevToken,
|
|
124
|
+
env: prevEnv,
|
|
125
|
+
prototypeName: prevPrototypeName,
|
|
126
|
+
} = usePrevious<typeof value>(value)
|
|
121
127
|
|
|
122
128
|
const isInitialLogin = !prevToken && !!newToken
|
|
123
129
|
if (isInitialLogin) return false
|
|
@@ -127,8 +133,9 @@ function useSessionChanged(value: Pick<ChatContextValue, 'token' | 'env'>): bool
|
|
|
127
133
|
)
|
|
128
134
|
|
|
129
135
|
const envChanged = Boolean(prevEnv && newEnv !== prevEnv)
|
|
136
|
+
const prototypeChanged = Boolean(prevEnv && newPrototypeName !== prevPrototypeName)
|
|
130
137
|
|
|
131
|
-
return tokenChanged || envChanged
|
|
138
|
+
return tokenChanged || envChanged || prototypeChanged
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
function usePrevious<T>(value: T): T {
|
|
@@ -12,6 +12,7 @@ import { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'
|
|
|
12
12
|
|
|
13
13
|
export interface ChatProviderProps {
|
|
14
14
|
env?: ENV
|
|
15
|
+
prototypeName?: string
|
|
15
16
|
giphyApiKey?: string
|
|
16
17
|
onAgeDisqualification?: (params: AgeCheckContactInfo) => void
|
|
17
18
|
onUnauthorizedResponse: (_response: FailedResponse) => void
|
|
@@ -45,6 +46,7 @@ export const ChatContext = createContext<ChatContextValue>({
|
|
|
45
46
|
export function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {
|
|
46
47
|
const {
|
|
47
48
|
env,
|
|
49
|
+
prototypeName,
|
|
48
50
|
token,
|
|
49
51
|
onAgeDisqualification = (_params: AgeCheckContactInfo) => {},
|
|
50
52
|
onUnauthorizedResponse,
|
|
@@ -58,8 +60,8 @@ export function ChatProvider({ children, value }: { children: any; value: ChatPr
|
|
|
58
60
|
setLiquidGlassCapability(liquidGlassEnabled)
|
|
59
61
|
const theme = useCreateChatTheme(value.theme || {})
|
|
60
62
|
const session = useMemo(
|
|
61
|
-
() => new Session({ token, env, type: tokenType }),
|
|
62
|
-
[env, token, tokenType]
|
|
63
|
+
() => new Session({ token, env, prototypeName, type: tokenType }),
|
|
64
|
+
[env, prototypeName, token, tokenType]
|
|
63
65
|
)
|
|
64
66
|
|
|
65
67
|
const productAnalyticsConfig = useProductAnalyticsConfig(session)
|
|
@@ -23,7 +23,7 @@ type Sessions = Record<string, string> // Key is session ID
|
|
|
23
23
|
|
|
24
24
|
export type SessionContextValue = {
|
|
25
25
|
env: ENV
|
|
26
|
-
setEnv: (_env: ENV) => void
|
|
26
|
+
setEnv: (_env: ENV, _prototypeName?: string) => void
|
|
27
27
|
session: Session
|
|
28
28
|
sessions: Sessions
|
|
29
29
|
token: OAuthToken | undefined
|
|
@@ -52,7 +52,11 @@ export type SessionContextConfig = {
|
|
|
52
52
|
secureStorage: StorageAdapter // For sensitive data (tokens/sessions)
|
|
53
53
|
|
|
54
54
|
// Functional callbacks
|
|
55
|
-
refreshTokenFn: (params: {
|
|
55
|
+
refreshTokenFn: (params: {
|
|
56
|
+
refresh_token: string
|
|
57
|
+
env: ENV
|
|
58
|
+
prototypeName?: string
|
|
59
|
+
}) => Promise<OAuthToken>
|
|
56
60
|
onLogout: () => void | Promise<void>
|
|
57
61
|
|
|
58
62
|
// Optional configuration
|
|
@@ -127,9 +131,11 @@ export function SessionContextProvider({
|
|
|
127
131
|
if (!token?.refresh_token) {
|
|
128
132
|
return Promise.reject(new Error('Refresh token is required'))
|
|
129
133
|
}
|
|
130
|
-
return refreshTokenFn({
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
return refreshTokenFn({
|
|
135
|
+
refresh_token: token.refresh_token,
|
|
136
|
+
env: currentSession.env,
|
|
137
|
+
prototypeName: currentSession.prototypeName,
|
|
138
|
+
}).then(handleTokenUpdate)
|
|
133
139
|
},
|
|
134
140
|
onError: (t: Partial<FailedResponse>) => {
|
|
135
141
|
handleRefreshFailed(t)
|
|
@@ -142,22 +148,24 @@ export function SessionContextProvider({
|
|
|
142
148
|
}, [queryClient])
|
|
143
149
|
|
|
144
150
|
const handleSetEnv = useCallback(
|
|
145
|
-
async (_env: ENV) => {
|
|
151
|
+
async (_env: ENV, _prototypeName?: string) => {
|
|
146
152
|
const updatedManager = SessionManager.hydrate(managerString)
|
|
147
153
|
const session = updatedManager.currentSession
|
|
148
|
-
|
|
154
|
+
const sameEnvironment = _env === session.env && _prototypeName === session.prototypeName
|
|
155
|
+
if (sameEnvironment) return
|
|
149
156
|
|
|
150
157
|
const productionEnvironments = ['production', 'staging']
|
|
151
158
|
const switchingToDevelopment =
|
|
152
159
|
_env === 'development' && productionEnvironments.includes(session.env)
|
|
153
160
|
const switchingToProduction = _env === 'production' && session.env === 'development'
|
|
161
|
+
const switchingPrototype = _env === 'prototype' || session.env === 'prototype'
|
|
154
162
|
|
|
155
|
-
if (switchingToDevelopment || switchingToProduction) {
|
|
156
|
-
const newSession = new Session({ env: _env })
|
|
163
|
+
if (switchingToDevelopment || switchingToProduction || switchingPrototype) {
|
|
164
|
+
const newSession = new Session({ env: _env, prototypeName: _prototypeName })
|
|
157
165
|
updatedManager.upsertSession(newSession)
|
|
158
166
|
}
|
|
159
167
|
|
|
160
|
-
updatedManager.setEnv(_env)
|
|
168
|
+
updatedManager.setEnv(_env, _prototypeName)
|
|
161
169
|
await setManagerString(updatedManager.toString())
|
|
162
170
|
},
|
|
163
171
|
[managerString, setManagerString]
|
|
@@ -9,6 +9,8 @@ export function usePersonSettings() {
|
|
|
9
9
|
const { update, invalidate } = useCurrentPersonCache()
|
|
10
10
|
|
|
11
11
|
const directMessagesDisabled = person?.directMessagesDisabled ?? false
|
|
12
|
+
const canManageDirectMessages =
|
|
13
|
+
person?.canManageDirectMessages ?? person?.directMessagesEligible ?? false
|
|
12
14
|
|
|
13
15
|
const { mutate: setDirectMessagesDisabled, isPending: isMutating } = useMutation({
|
|
14
16
|
mutationFn: (disabled: boolean) => {
|
|
@@ -25,5 +27,5 @@ export function usePersonSettings() {
|
|
|
25
27
|
},
|
|
26
28
|
})
|
|
27
29
|
|
|
28
|
-
return { directMessagesDisabled, setDirectMessagesDisabled, isMutating }
|
|
30
|
+
return { canManageDirectMessages, directMessagesDisabled, setDirectMessagesDisabled, isMutating }
|
|
29
31
|
}
|
|
@@ -5,7 +5,7 @@ import { Platform, ScrollView, StyleSheet, View } from 'react-native'
|
|
|
5
5
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
6
6
|
import { Heading, Icon, Text, VersionFooter } from '../components'
|
|
7
7
|
import { Switch } from '../components/display/switch'
|
|
8
|
-
import {
|
|
8
|
+
import { useTheme } from '../hooks'
|
|
9
9
|
import { useAppName } from '../hooks/use_app_name'
|
|
10
10
|
import { usePersonSettings } from '../hooks/use_person_settings'
|
|
11
11
|
|
|
@@ -13,8 +13,8 @@ export type SettingsScreenProps = StaticScreenProps<{}>
|
|
|
13
13
|
|
|
14
14
|
export function SettingsScreen({}: SettingsScreenProps) {
|
|
15
15
|
const styles = useStyles()
|
|
16
|
-
const { directMessagesDisabled, setDirectMessagesDisabled, isMutating } =
|
|
17
|
-
|
|
16
|
+
const { canManageDirectMessages, directMessagesDisabled, setDirectMessagesDisabled, isMutating } =
|
|
17
|
+
usePersonSettings()
|
|
18
18
|
const appName = useAppName()
|
|
19
19
|
const navigation = useNavigation()
|
|
20
20
|
|
|
@@ -33,7 +33,7 @@ export function SettingsScreen({}: SettingsScreenProps) {
|
|
|
33
33
|
<View style={styles.sectionHeader}>
|
|
34
34
|
<Heading variant="h2">Messages</Heading>
|
|
35
35
|
</View>
|
|
36
|
-
{
|
|
36
|
+
{canManageDirectMessages && (
|
|
37
37
|
<View style={styles.settingRow}>
|
|
38
38
|
<View style={styles.settingRowText}>
|
|
39
39
|
<Text>Allow direct messages</Text>
|
|
@@ -23,6 +23,7 @@ export interface CurrentPersonResource extends PersonResource {
|
|
|
23
23
|
ageQualificationStatus?: AgeQualificationStatus
|
|
24
24
|
directMessagesDisabled: boolean
|
|
25
25
|
directMessagesEligible: boolean
|
|
26
|
+
canManageDirectMessages?: boolean
|
|
26
27
|
canBrowseArchivedConversations?: boolean
|
|
27
28
|
under_18: boolean
|
|
28
29
|
}
|
|
@@ -110,6 +110,18 @@ describe('SessionManager', () => {
|
|
|
110
110
|
expect(manager.currentSession.id).toBe(UNAUTHENTICATED_SESSION_ID)
|
|
111
111
|
expect(manager.sessions).toHaveProperty(UNAUTHENTICATED_SESSION_ID)
|
|
112
112
|
})
|
|
113
|
+
|
|
114
|
+
it('keeps the Protonova environment name only while on Protonova', () => {
|
|
115
|
+
const manager = new SessionManager()
|
|
116
|
+
|
|
117
|
+
manager.setEnv('prototype', 'chat-812')
|
|
118
|
+
expect(SessionManager.hydrate(manager.toString()).currentSession.prototypeName).toBe(
|
|
119
|
+
'chat-812'
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
manager.setEnv('production', 'chat-812')
|
|
123
|
+
expect(manager.currentSession.prototypeName).toBeUndefined()
|
|
124
|
+
})
|
|
113
125
|
})
|
|
114
126
|
|
|
115
127
|
describe('upsertSession', () => {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Session } from '../session'
|
|
2
|
+
import { UploadUri } from '../upload_uri'
|
|
3
|
+
import { Uri } from '../uri'
|
|
4
|
+
|
|
5
|
+
const prototypeSession = (type?: 'OAuth' | 'ChurchCenterOauth') =>
|
|
6
|
+
new Session({ env: 'prototype', prototypeName: 'chat-812', type })
|
|
7
|
+
|
|
8
|
+
describe('on a Protonova environment', () => {
|
|
9
|
+
it('sends Planning Center requests to the environment', () => {
|
|
10
|
+
const uri = new Uri({ session: prototypeSession('OAuth'), app: 'chat' })
|
|
11
|
+
|
|
12
|
+
expect(uri.appUrl('/me')).toBe('https://chat-812.api.planningcenter.ninja/chat/v2/me')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('sends Church Center requests to the environment', () => {
|
|
16
|
+
const uri = new Uri({ session: prototypeSession('ChurchCenterOauth'), app: 'chat' })
|
|
17
|
+
|
|
18
|
+
expect(uri.appUrl('/me')).toBe('https://chat-812.api.churchcenter.ninja/chat/v2/me')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('uploads to the environment', () => {
|
|
22
|
+
expect(new UploadUri({ session: prototypeSession() }).baseUrl).toBe(
|
|
23
|
+
'https://chat-812.upload.planningcenter.ninja'
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
})
|
package/src/utils/session.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OAuthToken, OrganizationResource, PersonResource } from '../types'
|
|
2
2
|
|
|
3
|
-
export type ENV = 'production' | 'staging' | 'development'
|
|
3
|
+
export type ENV = 'production' | 'staging' | 'development' | 'prototype'
|
|
4
4
|
export type OauthType = 'OAuth' | 'ChurchCenterOauth'
|
|
5
5
|
export type PartialToken = Pick<OAuthToken, 'access_token'> & Partial<OAuthToken>
|
|
6
6
|
export type SessionMeta = {
|
|
@@ -11,6 +11,7 @@ export type SessionMeta = {
|
|
|
11
11
|
}
|
|
12
12
|
export type SessionProps<T extends PartialToken> = {
|
|
13
13
|
env?: ENV
|
|
14
|
+
prototypeName?: string
|
|
14
15
|
token?: T
|
|
15
16
|
type?: OauthType
|
|
16
17
|
meta?: SessionMeta
|
|
@@ -25,13 +26,15 @@ type SessionId = string | typeof UNAUTHENTICATED_SESSION_ID
|
|
|
25
26
|
*/
|
|
26
27
|
export class Session<T extends PartialToken = PartialToken> {
|
|
27
28
|
env: ENV
|
|
29
|
+
prototypeName: string | undefined
|
|
28
30
|
token: T | undefined
|
|
29
31
|
type: OauthType
|
|
30
32
|
meta: Record<string, any>
|
|
31
33
|
|
|
32
34
|
constructor(props?: SessionProps<T>) {
|
|
33
|
-
const { env = 'production', token, type, meta } = props || {}
|
|
35
|
+
const { env = 'production', prototypeName, token, type, meta } = props || {}
|
|
34
36
|
this.env = env
|
|
37
|
+
this.prototypeName = env === 'prototype' ? prototypeName : undefined
|
|
35
38
|
this.token = token
|
|
36
39
|
this.type = type || 'OAuth'
|
|
37
40
|
this.meta = meta || {}
|
|
@@ -54,7 +57,12 @@ export class Session<T extends PartialToken = PartialToken> {
|
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
toString() {
|
|
57
|
-
return JSON.stringify({
|
|
60
|
+
return JSON.stringify({
|
|
61
|
+
env: this.env,
|
|
62
|
+
prototypeName: this.prototypeName,
|
|
63
|
+
token: this.token,
|
|
64
|
+
meta: this.meta,
|
|
65
|
+
})
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
// Convenience methods to set the person and organization
|
|
@@ -32,10 +32,11 @@ export class SessionManager {
|
|
|
32
32
|
)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
setEnv(env: ENV) {
|
|
35
|
+
setEnv(env: ENV, prototypeName?: string) {
|
|
36
36
|
// Get the current session (handles case where it doesn't exist)
|
|
37
37
|
const session = this.currentSession
|
|
38
38
|
session.env = env
|
|
39
|
+
session.prototypeName = prototypeName
|
|
39
40
|
// Store the session with its ID
|
|
40
41
|
this.upsertSession(session)
|
|
41
42
|
}
|
package/src/utils/upload_uri.ts
CHANGED
package/src/utils/uri.ts
CHANGED
|
@@ -24,6 +24,11 @@ export class Uri {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
get host() {
|
|
27
|
+
if (this.env === 'prototype') {
|
|
28
|
+
const graphDomain = this.isChurchCenter ? 'churchcenter' : 'planningcenter'
|
|
29
|
+
return `${this.session.prototypeName}.api.${graphDomain}.ninja`
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
return `${this.subdomain}.${this.domain}.${this.tld}`
|
|
28
33
|
}
|
|
29
34
|
|