@planningcenter/chat-react-native 1.3.0-rc.6 → 1.3.0-rc.7
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/.babelrc.json +3 -0
- package/CHANGELOG.md +14 -0
- package/build/contexts/api_provider.d.ts +1 -2
- package/build/contexts/api_provider.d.ts.map +1 -1
- package/build/contexts/api_provider.js +6 -13
- package/build/contexts/api_provider.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/utils/session.d.ts +32 -0
- package/build/utils/session.d.ts.map +1 -0
- package/build/utils/session.js +35 -0
- package/build/utils/session.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/session.tsx +46 -0
- package/src/contexts/api_provider.tsx +6 -15
- package/src/index.tsx +3 -0
- package/src/utils/session.ts +47 -0
package/.babelrc.json
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.3.0-rc.7](https://github.com/planningcenter/chat-js/compare/v1.2.0...v1.3.0-rc.7) (2025-02-11)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add auth to the example app ([#50](https://github.com/planningcenter/chat-js/issues/50)) ([5e0ae00](https://github.com/planningcenter/chat-js/commit/5e0ae008345743f6bba388e982a3ad768265971a))
|
|
12
|
+
* allow environment switching ([#58](https://github.com/planningcenter/chat-js/issues/58)) ([2518d33](https://github.com/planningcenter/chat-js/commit/2518d33588a3eff1517b440cb0e493e97915d9b0))
|
|
13
|
+
* **Api:** teach app about enviroments and make fetching a snap ([#55](https://github.com/planningcenter/chat-js/issues/55)) ([bb7aa56](https://github.com/planningcenter/chat-js/commit/bb7aa567ea362b53faceed9c98ca3b315a0229f5))
|
|
14
|
+
* create higher fidelity components ([#54](https://github.com/planningcenter/chat-js/issues/54)) ([367b707](https://github.com/planningcenter/chat-js/commit/367b7076b6d3a81ede7852248e98a199adea9978))
|
|
15
|
+
* drop stream and set global dependencies ([#49](https://github.com/planningcenter/chat-js/issues/49)) ([1214b9f](https://github.com/planningcenter/chat-js/commit/1214b9fbc17f4ab67a1de1d39954604a28268f35))
|
|
16
|
+
* **StreamChat:** export core package ([#41](https://github.com/planningcenter/chat-js/issues/41)) ([e9afde0](https://github.com/planningcenter/chat-js/commit/e9afde0e2a11d9c7e13b84f8eee8a6cfa7aff795)), closes [#45](https://github.com/planningcenter/chat-js/issues/45)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
6
20
|
## [1.3.0-rc.6](https://github.com/planningcenter/chat-js/compare/v1.2.0...v1.3.0-rc.6) (2025-02-11)
|
|
7
21
|
|
|
8
22
|
|
|
@@ -2,12 +2,11 @@ import { QueryClient } from '@tanstack/react-query';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { ViewProps } from 'react-native';
|
|
4
4
|
import { OAuthToken } from '../types';
|
|
5
|
-
|
|
5
|
+
import { ENV } from '../utils/session';
|
|
6
6
|
export declare const queryClient: QueryClient;
|
|
7
7
|
export declare function ApiProvider({ children, env, token, onTokenExpired, }: ViewProps & {
|
|
8
8
|
env?: ENV;
|
|
9
9
|
token?: OAuthToken;
|
|
10
10
|
onTokenExpired: () => void;
|
|
11
11
|
}): React.JSX.Element;
|
|
12
|
-
export {};
|
|
13
12
|
//# sourceMappingURL=api_provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_provider.d.ts","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiC,MAAM,uBAAuB,CAAA;AAClF,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"api_provider.d.ts","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiC,MAAM,uBAAuB,CAAA;AAClF,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,GAAG,EAAW,MAAM,kBAAkB,CAAA;AA0B/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,qBAM3E"}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
|
|
4
|
-
let oauthToken;
|
|
3
|
+
import { session } from '../utils/session';
|
|
5
4
|
let handleTokenExpired;
|
|
6
|
-
const hostMap = {
|
|
7
|
-
production: 'https://api.planningcenteronline.com',
|
|
8
|
-
staging: 'https://api-staging.planningcenteronline.com',
|
|
9
|
-
development: 'https://api.pco.test',
|
|
10
|
-
};
|
|
11
5
|
const defaultQueryFn = ({ queryKey }) => {
|
|
12
|
-
if (!
|
|
13
|
-
console.error('No token present');
|
|
6
|
+
if (!session.token) {
|
|
14
7
|
throw new Error('No token present');
|
|
15
8
|
}
|
|
16
|
-
const url = `${
|
|
9
|
+
const url = `${session.baseUrl}${queryKey[0]}`;
|
|
17
10
|
return fetch(url, {
|
|
18
11
|
headers: {
|
|
19
|
-
Authorization: `Bearer ${
|
|
12
|
+
Authorization: `Bearer ${session.token?.access_token}`,
|
|
20
13
|
},
|
|
21
14
|
})
|
|
22
15
|
.then(validateResponse)
|
|
@@ -36,9 +29,9 @@ export const queryClient = new QueryClient({
|
|
|
36
29
|
},
|
|
37
30
|
});
|
|
38
31
|
export function ApiProvider({ children, env = 'production', token, onTokenExpired, }) {
|
|
39
|
-
|
|
32
|
+
session.env = env;
|
|
33
|
+
session.token = token;
|
|
40
34
|
handleTokenExpired = onTokenExpired;
|
|
41
|
-
environment = env;
|
|
42
35
|
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
|
|
43
36
|
}
|
|
44
37
|
const validateResponse = (response) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_provider.js","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAY,MAAM,uBAAuB,CAAA;AAClF,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"api_provider.js","sourceRoot":"","sources":["../../src/contexts/api_provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAY,MAAM,uBAAuB,CAAA;AAClF,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAO,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE/C,IAAI,kBAA8B,CAAA;AAElC,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAA0B,EAAE,EAAE;IAC9D,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;IACrC,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAA;IAE9C,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE;SACvD;KACF,CAAC;SACC,IAAI,CAAC,gBAAgB,CAAC;SACtB,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;SACjC,KAAK,CAAC,KAAK,CAAC,EAAE;QACb,IAAI,KAAK,CAAC,OAAO,KAAK,eAAe,EAAE,CAAC;YACtC,kBAAkB,EAAE,CAAA;QACtB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC;IACzC,cAAc,EAAE;QACd,OAAO,EAAE;YACP,OAAO,EAAE,cAAc;SACxB;KACF;CACF,CAAC,CAAA;AAEF,MAAM,UAAU,WAAW,CAAC,EAC1B,QAAQ,EACR,GAAG,GAAG,YAAY,EAClB,KAAK,EACL,cAAc,GAC4D;IAC1E,OAAO,CAAC,GAAG,GAAG,GAAG,CAAA;IACjB,OAAO,CAAC,KAAK,GAAG,KAAK,CAAA;IACrB,kBAAkB,GAAG,cAAc,CAAA;IAEnC,OAAO,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,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 { QueryClient, QueryClientProvider, QueryKey } from '@tanstack/react-query'\nimport React from 'react'\nimport { ViewProps } from 'react-native'\nimport { OAuthToken } from '../types'\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 fetch(url, {\n headers: {\n Authorization: `Bearer ${session.token?.access_token}`,\n },\n })\n .then(validateResponse)\n .then(response => response.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 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"]}
|
package/build/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Conversations } from './components/conversations';
|
|
|
2
2
|
import { ChatContext, ChatProvider } from './contexts/chat_context';
|
|
3
3
|
import { useCreateChatTheme } from './hooks/use_create_chat_theme';
|
|
4
4
|
import { OAuthToken } from './types';
|
|
5
|
+
import { baseUrlMap, uploadUrlMap } from './utils/session';
|
|
5
6
|
import { TemporaryDefaultColorsType } from './utils/theme';
|
|
6
|
-
export { ChatContext, ChatProvider, Conversations, OAuthToken, TemporaryDefaultColorsType, useCreateChatTheme, };
|
|
7
|
+
export { baseUrlMap, ChatContext, ChatProvider, Conversations, OAuthToken, TemporaryDefaultColorsType, uploadUrlMap, useCreateChatTheme, };
|
|
7
8
|
//# 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,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAA;AAE1D,OAAO,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,UAAU,EACV,0BAA0B,EAC1B,kBAAkB,GACnB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAA;AAE1D,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,UAAU,EACV,0BAA0B,EAC1B,YAAY,EACZ,kBAAkB,GACnB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Conversations } from './components/conversations';
|
|
2
2
|
import { ChatContext, ChatProvider } from './contexts/chat_context';
|
|
3
3
|
import { useCreateChatTheme } from './hooks/use_create_chat_theme';
|
|
4
|
-
|
|
4
|
+
import { baseUrlMap, uploadUrlMap } from './utils/session';
|
|
5
|
+
export { baseUrlMap, ChatContext, ChatProvider, Conversations, uploadUrlMap, useCreateChatTheme, };
|
|
5
6
|
//# 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,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAElE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG1D,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EAGb,YAAY,EACZ,kBAAkB,GACnB,CAAA","sourcesContent":["import { Conversations } from './components/conversations'\nimport { ChatContext, ChatProvider } from './contexts/chat_context'\nimport { useCreateChatTheme } from './hooks/use_create_chat_theme'\nimport { OAuthToken } from './types'\nimport { baseUrlMap, uploadUrlMap } from './utils/session'\nimport { TemporaryDefaultColorsType } from './utils/theme'\n\nexport {\n baseUrlMap,\n ChatContext,\n ChatProvider,\n Conversations,\n OAuthToken,\n TemporaryDefaultColorsType,\n uploadUrlMap,\n useCreateChatTheme,\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { OAuthToken } from '../types';
|
|
2
|
+
export type ENV = 'production' | 'staging' | 'development';
|
|
3
|
+
export declare const baseUrlMap: {
|
|
4
|
+
production: string;
|
|
5
|
+
staging: string;
|
|
6
|
+
development: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const uploadUrlMap: {
|
|
9
|
+
production: string;
|
|
10
|
+
staging: string;
|
|
11
|
+
development: string;
|
|
12
|
+
};
|
|
13
|
+
type SessionProps = {
|
|
14
|
+
env?: ENV;
|
|
15
|
+
token?: OAuthToken;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Session class to track the environment and token
|
|
19
|
+
* Not intended to make network requests or handle authentication
|
|
20
|
+
* - returns urls for convenience only
|
|
21
|
+
*/
|
|
22
|
+
export declare class Session {
|
|
23
|
+
env: ENV;
|
|
24
|
+
token: OAuthToken | undefined;
|
|
25
|
+
constructor(props?: SessionProps);
|
|
26
|
+
get isAuthenticated(): boolean;
|
|
27
|
+
get baseUrl(): string;
|
|
28
|
+
get uploadUrl(): string;
|
|
29
|
+
}
|
|
30
|
+
export declare const session: Session;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +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;CACF;AAED,eAAO,MAAM,OAAO,SAAsC,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const baseUrlMap = {
|
|
2
|
+
production: 'https://api.planningcenteronline.com',
|
|
3
|
+
staging: 'https://api-staging.planningcenteronline.com',
|
|
4
|
+
development: 'http://api.pco.test',
|
|
5
|
+
};
|
|
6
|
+
export const uploadUrlMap = {
|
|
7
|
+
production: 'https://upload.planningcenteronline.com/v2/files',
|
|
8
|
+
staging: 'https://upload-staging.planningcenteronline.com/v2/files',
|
|
9
|
+
development: 'https://upload.planningcenteronline.com/v2/files',
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Session class to track the environment and token
|
|
13
|
+
* Not intended to make network requests or handle authentication
|
|
14
|
+
* - returns urls for convenience only
|
|
15
|
+
*/
|
|
16
|
+
export class Session {
|
|
17
|
+
env;
|
|
18
|
+
token;
|
|
19
|
+
constructor(props) {
|
|
20
|
+
const { env = 'development', token } = props || {};
|
|
21
|
+
this.env = env;
|
|
22
|
+
this.token = token;
|
|
23
|
+
}
|
|
24
|
+
get isAuthenticated() {
|
|
25
|
+
return Boolean(this.token);
|
|
26
|
+
}
|
|
27
|
+
get baseUrl() {
|
|
28
|
+
return baseUrlMap[this.env];
|
|
29
|
+
}
|
|
30
|
+
get uploadUrl() {
|
|
31
|
+
return uploadUrlMap[this.env];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const session = new Session({ env: 'development' });
|
|
35
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "1.3.0-rc.
|
|
3
|
+
"version": "1.3.0-rc.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"prettier": "^3.4.2",
|
|
28
28
|
"react-native": "0.74.5"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "d523042ca47c1d2dd74744bf400ac3491a0a83ae"
|
|
31
31
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { OAuthToken } from '../types'
|
|
2
|
+
import { Session } from '../utils/session'
|
|
3
|
+
|
|
4
|
+
describe('Session', () => {
|
|
5
|
+
describe('constructor', () => {
|
|
6
|
+
it('should track the environment', () => {
|
|
7
|
+
const session = new Session()
|
|
8
|
+
expect(session.env).toBe('development')
|
|
9
|
+
expect(session.isAuthenticated).toBe(false)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
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
|
+
const session = new Session({ token })
|
|
22
|
+
expect(session.token).toEqual(token)
|
|
23
|
+
expect(session.isAuthenticated).toEqual(true)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('urls', () => {
|
|
28
|
+
it('should return the correct base url', () => {
|
|
29
|
+
const session = new Session({ env: 'production' })
|
|
30
|
+
expect(session.baseUrl).toBe('https://api.planningcenteronline.com')
|
|
31
|
+
session.env = 'development'
|
|
32
|
+
expect(session.baseUrl).toBe('http://api.pco.test')
|
|
33
|
+
session.env = 'staging'
|
|
34
|
+
expect(session.baseUrl).toBe('https://api-staging.planningcenteronline.com')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should return the correct upload url', () => {
|
|
38
|
+
const session = new Session({ env: 'production' })
|
|
39
|
+
expect(session.uploadUrl).toBe('https://upload.planningcenteronline.com/v2/files')
|
|
40
|
+
session.env = 'development'
|
|
41
|
+
expect(session.uploadUrl).toBe('https://upload.planningcenteronline.com/v2/files')
|
|
42
|
+
session.env = 'staging'
|
|
43
|
+
expect(session.uploadUrl).toBe('https://upload-staging.planningcenteronline.com/v2/files')
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -2,29 +2,20 @@ import { QueryClient, QueryClientProvider, QueryKey } from '@tanstack/react-quer
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import { ViewProps } from 'react-native'
|
|
4
4
|
import { OAuthToken } from '../types'
|
|
5
|
+
import { ENV, session } from '../utils/session'
|
|
5
6
|
|
|
6
|
-
type ENV = 'production' | 'staging' | 'development'
|
|
7
|
-
let environment: ENV = 'production'
|
|
8
|
-
let oauthToken: OAuthToken | undefined
|
|
9
7
|
let handleTokenExpired: () => void
|
|
10
8
|
|
|
11
|
-
const hostMap = {
|
|
12
|
-
production: 'https://api.planningcenteronline.com',
|
|
13
|
-
staging: 'https://api-staging.planningcenteronline.com',
|
|
14
|
-
development: 'https://api.pco.test',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
9
|
const defaultQueryFn = ({ queryKey }: { queryKey: QueryKey }) => {
|
|
18
|
-
if (!
|
|
19
|
-
console.error('No token present')
|
|
10
|
+
if (!session.token) {
|
|
20
11
|
throw new Error('No token present')
|
|
21
12
|
}
|
|
22
13
|
|
|
23
|
-
const url = `${
|
|
14
|
+
const url = `${session.baseUrl}${queryKey[0]}`
|
|
24
15
|
|
|
25
16
|
return fetch(url, {
|
|
26
17
|
headers: {
|
|
27
|
-
Authorization: `Bearer ${
|
|
18
|
+
Authorization: `Bearer ${session.token?.access_token}`,
|
|
28
19
|
},
|
|
29
20
|
})
|
|
30
21
|
.then(validateResponse)
|
|
@@ -51,9 +42,9 @@ export function ApiProvider({
|
|
|
51
42
|
token,
|
|
52
43
|
onTokenExpired,
|
|
53
44
|
}: ViewProps & { env?: ENV; token?: OAuthToken; onTokenExpired: () => void }) {
|
|
54
|
-
|
|
45
|
+
session.env = env
|
|
46
|
+
session.token = token
|
|
55
47
|
handleTokenExpired = onTokenExpired
|
|
56
|
-
environment = env
|
|
57
48
|
|
|
58
49
|
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
59
50
|
}
|
package/src/index.tsx
CHANGED
|
@@ -2,13 +2,16 @@ import { Conversations } from './components/conversations'
|
|
|
2
2
|
import { ChatContext, ChatProvider } from './contexts/chat_context'
|
|
3
3
|
import { useCreateChatTheme } from './hooks/use_create_chat_theme'
|
|
4
4
|
import { OAuthToken } from './types'
|
|
5
|
+
import { baseUrlMap, uploadUrlMap } from './utils/session'
|
|
5
6
|
import { TemporaryDefaultColorsType } from './utils/theme'
|
|
6
7
|
|
|
7
8
|
export {
|
|
9
|
+
baseUrlMap,
|
|
8
10
|
ChatContext,
|
|
9
11
|
ChatProvider,
|
|
10
12
|
Conversations,
|
|
11
13
|
OAuthToken,
|
|
12
14
|
TemporaryDefaultColorsType,
|
|
15
|
+
uploadUrlMap,
|
|
13
16
|
useCreateChatTheme,
|
|
14
17
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { OAuthToken } from '../types'
|
|
2
|
+
|
|
3
|
+
export type ENV = 'production' | 'staging' | 'development'
|
|
4
|
+
|
|
5
|
+
export const baseUrlMap = {
|
|
6
|
+
production: 'https://api.planningcenteronline.com',
|
|
7
|
+
staging: 'https://api-staging.planningcenteronline.com',
|
|
8
|
+
development: 'http://api.pco.test',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const uploadUrlMap = {
|
|
12
|
+
production: 'https://upload.planningcenteronline.com/v2/files',
|
|
13
|
+
staging: 'https://upload-staging.planningcenteronline.com/v2/files',
|
|
14
|
+
development: 'https://upload.planningcenteronline.com/v2/files',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type SessionProps = { env?: ENV; token?: OAuthToken } | undefined
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Session class to track the environment and token
|
|
21
|
+
* Not intended to make network requests or handle authentication
|
|
22
|
+
* - returns urls for convenience only
|
|
23
|
+
*/
|
|
24
|
+
export class Session {
|
|
25
|
+
env: ENV
|
|
26
|
+
token: OAuthToken | undefined
|
|
27
|
+
|
|
28
|
+
constructor(props?: SessionProps) {
|
|
29
|
+
const { env = 'development', token } = props || {}
|
|
30
|
+
this.env = env
|
|
31
|
+
this.token = token
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get isAuthenticated() {
|
|
35
|
+
return Boolean(this.token)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get baseUrl() {
|
|
39
|
+
return baseUrlMap[this.env]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get uploadUrl() {
|
|
43
|
+
return uploadUrlMap[this.env]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const session = new Session({ env: 'development' })
|