@youversion/platform-react-hooks 0.4.2 → 0.4.3
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +8 -0
- package/README.md +138 -0
- package/dist/context/BibleSDKContext.d.ts +1 -1
- package/dist/context/BibleSDKContext.d.ts.map +1 -1
- package/dist/context/BibleSDKProvider.d.ts +2 -2
- package/dist/context/BibleSDKProvider.d.ts.map +1 -1
- package/dist/context/BibleSDKProvider.js +2 -2
- package/dist/context/BibleSDKProvider.js.map +1 -1
- package/dist/useBibleClient.js +3 -3
- package/dist/useBibleClient.js.map +1 -1
- package/dist/useHighlights.js +3 -3
- package/dist/useHighlights.js.map +1 -1
- package/dist/useLanguages.js +3 -3
- package/dist/useLanguages.js.map +1 -1
- package/package.json +4 -4
- package/src/context/BibleSDKContext.tsx +1 -1
- package/src/context/BibleSDKProvider.tsx +3 -3
- package/src/useBibleClient.test.tsx +14 -14
- package/src/useBibleClient.ts +3 -3
- package/src/useHighlights.test.tsx +23 -23
- package/src/useHighlights.ts +3 -3
- package/src/useLanguages.test.tsx +16 -16
- package/src/useLanguages.ts +3 -3
- package/src/useVOTD.test.tsx +17 -17
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @youversion/platform-react-hooks@0.4.
|
|
2
|
+
> @youversion/platform-react-hooks@0.4.3 build /home/runner/work/platform-sdk-react/platform-sdk-react/packages/hooks
|
|
3
3
|
> tsc -p tsconfig.build.json
|
|
4
4
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @youversion/platform-react-hooks
|
|
2
2
|
|
|
3
|
+
## 0.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7b652f7: chore(docs): update documentation and readmes, and env var usage
|
|
8
|
+
- Updated dependencies [7b652f7]
|
|
9
|
+
- @youversion/platform-core@0.4.3
|
|
10
|
+
|
|
3
11
|
## 0.4.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
# @youversion/platform-react-hooks
|
|
6
|
+
|
|
7
|
+
A comprehensive collection of React hooks for accessing the YouVersion Platform APIs. Build Bible-based applications with type-safe hooks that handle loading states, error handling, and data fetching automatically.
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
`@youversion/platform-react-hooks` provides React hooks that wrap the [@youversion/platform-core](../core/README.md) SDK, offering a declarative way to access Bible data in your React applications. Features automatic loading and error state management, type-safe hooks with TypeScript support, and memoized data fetching.
|
|
12
|
+
|
|
13
|
+
> **📚 Full Documentation:** [developers.youversion.com/sdks/react](https://developers.youversion.com/sdks/react)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @youversion/platform-react-hooks
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Peer Dependencies
|
|
22
|
+
|
|
23
|
+
Requires React 19.0.0 or higher:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm install react@19.0.0
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## When to Use This Package
|
|
30
|
+
|
|
31
|
+
Use `@youversion/platform-react-hooks` when you need:
|
|
32
|
+
- ✅ Building custom React components with Bible features
|
|
33
|
+
- ✅ Declarative data fetching with automatic loading/error states
|
|
34
|
+
- ✅ Control over component UI while using reusable hooks
|
|
35
|
+
- ✅ Server-side rendering compatible hooks
|
|
36
|
+
|
|
37
|
+
**Use other packages instead if:**
|
|
38
|
+
- ❌ Need direct API access → Use [@youversion/platform-core](../core/README.md) for low-level client
|
|
39
|
+
- ❌ Want ready-made UI → Use [@youversion/platform-react-ui](../ui/README.md) for production components
|
|
40
|
+
|
|
41
|
+
## Related Packages
|
|
42
|
+
|
|
43
|
+
- **[@youversion/platform-core](../core/README.md)** - Core TypeScript SDK for direct API access
|
|
44
|
+
- **[@youversion/platform-react-ui](../ui/README.md)** - Pre-built React components
|
|
45
|
+
|
|
46
|
+
## Setup
|
|
47
|
+
|
|
48
|
+
All hooks require the `BibleSDKProvider` to be wrapped around your application:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { BibleSDKProvider } from '@youversion/platform-react-hooks';
|
|
52
|
+
|
|
53
|
+
function App() {
|
|
54
|
+
return (
|
|
55
|
+
<BibleSDKProvider appKey="YOUR_APP_KEY">
|
|
56
|
+
{/* All hooks work here */}
|
|
57
|
+
</BibleSDKProvider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
> **⚠️ Missing Provider Error:** If you use a hook without wrapping it in `BibleSDKProvider`, you'll get: `Error: useBibleClient must be used within a BibleSDKProvider`.
|
|
63
|
+
|
|
64
|
+
## Quick Start
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { BibleSDKProvider, useVersion, usePassage } from '@youversion/platform-react-hooks';
|
|
68
|
+
|
|
69
|
+
function BibleVerse() {
|
|
70
|
+
const { version, loading: versionLoading } = useVersion(111);
|
|
71
|
+
const { passage, loading: passageLoading } = usePassage(111, 'JHN.3.16');
|
|
72
|
+
|
|
73
|
+
if (versionLoading || passageLoading) return <div>Loading...</div>;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div>
|
|
77
|
+
<h1>{passage?.human_reference}</h1>
|
|
78
|
+
<p>Version: {version?.abbreviation}</p>
|
|
79
|
+
<div dangerouslySetInnerHTML={{ __html: passage?.content || '' }} />
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function App() {
|
|
85
|
+
return (
|
|
86
|
+
<BibleSDKProvider appKey="YOUR_APP_KEY">
|
|
87
|
+
<BibleVerse />
|
|
88
|
+
</BibleSDKProvider>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Features
|
|
94
|
+
|
|
95
|
+
- Fetch Bible versions, books, chapters, and verses
|
|
96
|
+
- Get formatted passages with HTML or text output
|
|
97
|
+
- Access Verse of the Day content
|
|
98
|
+
- Navigate between chapters and verses
|
|
99
|
+
- Query available languages and metadata
|
|
100
|
+
- Automatic loading/error state management
|
|
101
|
+
|
|
102
|
+
## Troubleshooting
|
|
103
|
+
|
|
104
|
+
### Provider Not Found Error
|
|
105
|
+
|
|
106
|
+
**Error:** `Error: useBibleClient must be used within a BibleSDKProvider`
|
|
107
|
+
|
|
108
|
+
**Solution:** Ensure `BibleSDKProvider` wraps your component tree:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
// ✅ Correct
|
|
112
|
+
function App() {
|
|
113
|
+
return (
|
|
114
|
+
<BibleSDKProvider appKey="YOUR_APP_KEY">
|
|
115
|
+
<MyComponent />
|
|
116
|
+
</BibleSDKProvider>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Invalid App Key Error
|
|
122
|
+
|
|
123
|
+
**Solution:** Get your App Key from [platform.youversion.com](https://platform.youversion.com/) and verify it's passed correctly.
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for development instructions.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
See [LICENSE](../../LICENSE)
|
|
132
|
+
|
|
133
|
+
## Support
|
|
134
|
+
|
|
135
|
+
- GitHub Issues: [Create an issue](https://github.com/youversion/platform-sdk-react/issues)
|
|
136
|
+
- Platform Docs: [platform.youversion.com](https://platform.youversion.com/)
|
|
137
|
+
- Core SDK: [@youversion/platform-core documentation](../core/README.md)
|
|
138
|
+
- Monorepo: [YouVersion Platform SDK](../../README.md)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BibleSDKContext.d.ts","sourceRoot":"","sources":["../../src/context/BibleSDKContext.tsx"],"names":[],"mappings":"AAIA,KAAK,mBAAmB,GAAG;IACzB,
|
|
1
|
+
{"version":3,"file":"BibleSDKContext.d.ts","sourceRoot":"","sources":["../../src/context/BibleSDKContext.tsx"],"names":[],"mappings":"AAIA,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,eAAe,qDAAkD,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { PropsWithChildren, ReactNode } from 'react';
|
|
2
2
|
type BibleSDKProviderProps = {
|
|
3
3
|
children: ReactNode;
|
|
4
|
-
|
|
4
|
+
appKey: string;
|
|
5
5
|
};
|
|
6
|
-
export declare function BibleSDKProvider({
|
|
6
|
+
export declare function BibleSDKProvider({ appKey, children, }: PropsWithChildren<BibleSDKProviderProps>): React.ReactElement;
|
|
7
7
|
export {};
|
|
8
8
|
//# sourceMappingURL=BibleSDKProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BibleSDKProvider.d.ts","sourceRoot":"","sources":["../../src/context/BibleSDKProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG1D,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,SAAS,CAAC;IACpB,
|
|
1
|
+
{"version":3,"file":"BibleSDKProvider.d.ts","sourceRoot":"","sources":["../../src/context/BibleSDKProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG1D,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,QAAQ,GACT,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,GAAG,KAAK,CAAC,YAAY,CAE/D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { BibleSDKContext } from './BibleSDKContext';
|
|
4
|
-
export function BibleSDKProvider({
|
|
5
|
-
return _jsx(BibleSDKContext.Provider, { value: {
|
|
4
|
+
export function BibleSDKProvider({ appKey, children, }) {
|
|
5
|
+
return _jsx(BibleSDKContext.Provider, { value: { appKey }, children: children });
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=BibleSDKProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BibleSDKProvider.js","sourceRoot":"","sources":["../../src/context/BibleSDKProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAOpD,MAAM,UAAU,gBAAgB,CAAC,EAC/B,
|
|
1
|
+
{"version":3,"file":"BibleSDKProvider.js","sourceRoot":"","sources":["../../src/context/BibleSDKProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAOpD,MAAM,UAAU,gBAAgB,CAAC,EAC/B,MAAM,EACN,QAAQ,GACiC;IACzC,OAAO,KAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,YAAG,QAAQ,GAA4B,CAAC;AAC5F,CAAC"}
|
package/dist/useBibleClient.js
CHANGED
|
@@ -5,13 +5,13 @@ import { BibleClient, ApiClient, YouVersionPlatformConfiguration } from '@youver
|
|
|
5
5
|
export function useBibleClient() {
|
|
6
6
|
const context = useContext(BibleSDKContext);
|
|
7
7
|
return useMemo(() => {
|
|
8
|
-
if (!context?.
|
|
8
|
+
if (!context?.appKey) {
|
|
9
9
|
throw new Error('BibleSDK context not found. Make sure your component is wrapped with BibleSDKProvider and an API key is provided.');
|
|
10
10
|
}
|
|
11
11
|
return new BibleClient(new ApiClient({
|
|
12
|
-
|
|
12
|
+
appKey: context.appKey,
|
|
13
13
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
14
14
|
}));
|
|
15
|
-
}, [context?.
|
|
15
|
+
}, [context?.appKey]);
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=useBibleClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBibleClient.js","sourceRoot":"","sources":["../src/useBibleClient.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAEpG,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,CAAC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useBibleClient.js","sourceRoot":"","sources":["../src/useBibleClient.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAEpG,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,mHAAmH,CACpH,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,WAAW,CACpB,IAAI,SAAS,CAAC;YACZ,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,cAAc,EAAE,+BAA+B,CAAC,cAAc;SAC/D,CAAC,CACH,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AACxB,CAAC"}
|
package/dist/useHighlights.js
CHANGED
|
@@ -8,14 +8,14 @@ import {} from '@youversion/platform-core';
|
|
|
8
8
|
export function useHighlights(options, apiOptions) {
|
|
9
9
|
const context = useContext(BibleSDKContext);
|
|
10
10
|
const highlightsClient = useMemo(() => {
|
|
11
|
-
if (!context?.
|
|
11
|
+
if (!context?.appKey) {
|
|
12
12
|
throw new Error('BibleSDK context not found. Make sure your component is wrapped with BibleSDKProvider and an API key is provided.');
|
|
13
13
|
}
|
|
14
14
|
return new HighlightsClient(new ApiClient({
|
|
15
|
-
|
|
15
|
+
appKey: context.appKey,
|
|
16
16
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
17
17
|
}));
|
|
18
|
-
}, [context?.
|
|
18
|
+
}, [context?.appKey]);
|
|
19
19
|
const { data, loading, error, refetch } = useApiData(() => highlightsClient.getHighlights(options), [highlightsClient, options?.version_id, options?.passage_id], {
|
|
20
20
|
enabled: apiOptions?.enabled !== false,
|
|
21
21
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHighlights.js","sourceRoot":"","sources":["../src/useHighlights.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,+BAA+B,GAChC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AAClE,OAAO,EAMN,MAAM,2BAA2B,CAAC;AAEnC,MAAM,UAAU,aAAa,CAC3B,OAA8B,EAC9B,UAA8B;IAS9B,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAE5C,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,EAAE;QACpC,IAAI,CAAC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useHighlights.js","sourceRoot":"","sources":["../src/useHighlights.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,+BAA+B,GAChC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AAClE,OAAO,EAMN,MAAM,2BAA2B,CAAC;AAEnC,MAAM,UAAU,aAAa,CAC3B,OAA8B,EAC9B,UAA8B;IAS9B,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAE5C,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,EAAE;QACpC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,mHAAmH,CACpH,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,gBAAgB,CACzB,IAAI,SAAS,CAAC;YACZ,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,cAAc,EAAE,+BAA+B,CAAC,cAAc;SAC/D,CAAC,CACH,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAEtB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,UAAU,CAClD,GAAG,EAAE,CAAC,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,EAC7C,CAAC,gBAAgB,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,EAC5D;QACE,OAAO,EAAE,UAAU,EAAE,OAAO,KAAK,KAAK;KACvC,CACF,CAAC;IAEF,MAAM,eAAe,GAAG,WAAW,CACjC,KAAK,EAAE,IAAqB,EAAsB,EAAE;QAClD,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC;QACV,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAC5B,CAAC;IAEF,MAAM,eAAe,GAAG,WAAW,CACjC,KAAK,EAAE,SAAiB,EAAE,aAAsC,EAAiB,EAAE;QACjF,MAAM,gBAAgB,CAAC,eAAe,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QACjE,OAAO,EAAE,CAAC;IACZ,CAAC,EACD,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAC5B,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,IAAI;QAChB,OAAO;QACP,KAAK;QACL,OAAO;QACP,eAAe;QACf,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
package/dist/useLanguages.js
CHANGED
|
@@ -8,14 +8,14 @@ import {} from '@youversion/platform-core';
|
|
|
8
8
|
export function useLanguages(options, apiOptions) {
|
|
9
9
|
const context = useContext(BibleSDKContext);
|
|
10
10
|
const languagesClient = useMemo(() => {
|
|
11
|
-
if (!context?.
|
|
11
|
+
if (!context?.appKey) {
|
|
12
12
|
throw new Error('BibleSDK context not found. Make sure your component is wrapped with BibleSDKProvider and an API key is provided.');
|
|
13
13
|
}
|
|
14
14
|
return new LanguagesClient(new ApiClient({
|
|
15
|
-
|
|
15
|
+
appKey: context.appKey,
|
|
16
16
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
17
17
|
}));
|
|
18
|
-
}, [context?.
|
|
18
|
+
}, [context?.appKey]);
|
|
19
19
|
const { data, loading, error, refetch } = useApiData(() => languagesClient.getLanguages(options), [languagesClient, options?.country, options?.page_size, options?.page_token], {
|
|
20
20
|
enabled: apiOptions?.enabled !== false,
|
|
21
21
|
});
|
package/dist/useLanguages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLanguages.js","sourceRoot":"","sources":["../src/useLanguages.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,eAAe,EACf,SAAS,EACT,+BAA+B,GAChC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AAClE,OAAO,EAIN,MAAM,2BAA2B,CAAC;AAEnC,MAAM,UAAU,YAAY,CAC1B,OAA4B,EAC5B,UAA8B;IAO9B,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAE5C,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,EAAE;QACnC,IAAI,CAAC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useLanguages.js","sourceRoot":"","sources":["../src/useLanguages.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACL,eAAe,EACf,SAAS,EACT,+BAA+B,GAChC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AAClE,OAAO,EAIN,MAAM,2BAA2B,CAAC;AAEnC,MAAM,UAAU,YAAY,CAC1B,OAA4B,EAC5B,UAA8B;IAO9B,MAAM,OAAO,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAE5C,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,EAAE;QACnC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,mHAAmH,CACpH,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,eAAe,CACxB,IAAI,SAAS,CAAC;YACZ,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,cAAc,EAAE,+BAA+B,CAAC,cAAc;SAC/D,CAAC,CACH,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAEtB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,UAAU,CAClD,GAAG,EAAE,CAAC,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC,EAC3C,CAAC,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,EAC5E;QACE,OAAO,EAAE,UAAU,EAAE,OAAO,KAAK,KAAK;KACvC,CACF,CAAC;IAEF,OAAO;QACL,SAAS,EAAE,IAAI;QACf,OAAO;QACP,KAAK;QACL,OAAO;KACR,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@youversion/platform-react-hooks",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@youversion/platform-core": "0.4.
|
|
24
|
+
"@youversion/platform-core": "0.4.3"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=19.1.0 <20.0.0"
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"eslint": "9.38.0",
|
|
36
36
|
"typescript": "5.9.3",
|
|
37
37
|
"vitest": "4.0.4",
|
|
38
|
-
"@internal/
|
|
39
|
-
"@internal/
|
|
38
|
+
"@internal/tsconfig": "0.0.0",
|
|
39
|
+
"@internal/eslint-config": "0.0.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "tsc --watch",
|
|
@@ -5,12 +5,12 @@ import { BibleSDKContext } from './BibleSDKContext';
|
|
|
5
5
|
|
|
6
6
|
type BibleSDKProviderProps = {
|
|
7
7
|
children: ReactNode;
|
|
8
|
-
|
|
8
|
+
appKey: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export function BibleSDKProvider({
|
|
12
|
-
|
|
12
|
+
appKey,
|
|
13
13
|
children,
|
|
14
14
|
}: PropsWithChildren<BibleSDKProviderProps>): React.ReactElement {
|
|
15
|
-
return <BibleSDKContext.Provider value={{
|
|
15
|
+
return <BibleSDKContext.Provider value={{ appKey }}>{children}</BibleSDKContext.Provider>;
|
|
16
16
|
}
|
|
@@ -28,7 +28,7 @@ vi.mock('@youversion/platform-core', async () => {
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
describe('useBibleClient', () => {
|
|
31
|
-
const
|
|
31
|
+
const mockAppKey = 'test-app-key';
|
|
32
32
|
|
|
33
33
|
beforeEach(() => {
|
|
34
34
|
vi.clearAllMocks();
|
|
@@ -38,7 +38,7 @@ describe('useBibleClient', () => {
|
|
|
38
38
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
39
39
|
<BibleSDKContext.Provider
|
|
40
40
|
value={{
|
|
41
|
-
|
|
41
|
+
appKey: mockAppKey,
|
|
42
42
|
}}
|
|
43
43
|
>
|
|
44
44
|
{children}
|
|
@@ -48,7 +48,7 @@ describe('useBibleClient', () => {
|
|
|
48
48
|
const { result } = renderHook(() => useBibleClient(), { wrapper });
|
|
49
49
|
|
|
50
50
|
expect(ApiClient).toHaveBeenCalledWith({
|
|
51
|
-
|
|
51
|
+
appKey: mockAppKey,
|
|
52
52
|
installationId: 'auto-generated-uuid',
|
|
53
53
|
});
|
|
54
54
|
expect(BibleClient).toHaveBeenCalledWith(expect.objectContaining({ isApiClient: true }));
|
|
@@ -61,11 +61,11 @@ describe('useBibleClient', () => {
|
|
|
61
61
|
);
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
it('should throw error when
|
|
64
|
+
it('should throw error when appKey is missing', () => {
|
|
65
65
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
66
66
|
<BibleSDKContext.Provider
|
|
67
67
|
value={{
|
|
68
|
-
|
|
68
|
+
appKey: '',
|
|
69
69
|
}}
|
|
70
70
|
>
|
|
71
71
|
{children}
|
|
@@ -81,7 +81,7 @@ describe('useBibleClient', () => {
|
|
|
81
81
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
82
82
|
<BibleSDKContext.Provider
|
|
83
83
|
value={{
|
|
84
|
-
|
|
84
|
+
appKey: mockAppKey,
|
|
85
85
|
}}
|
|
86
86
|
>
|
|
87
87
|
{children}
|
|
@@ -98,13 +98,13 @@ describe('useBibleClient', () => {
|
|
|
98
98
|
expect(BibleClient).toHaveBeenCalledTimes(1);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
it('should create new BibleClient when
|
|
102
|
-
let
|
|
101
|
+
it('should create new BibleClient when appKey changes', () => {
|
|
102
|
+
let currentAppKey = mockAppKey;
|
|
103
103
|
|
|
104
104
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
105
105
|
<BibleSDKContext.Provider
|
|
106
106
|
value={{
|
|
107
|
-
|
|
107
|
+
appKey: currentAppKey,
|
|
108
108
|
}}
|
|
109
109
|
>
|
|
110
110
|
{children}
|
|
@@ -116,11 +116,11 @@ describe('useBibleClient', () => {
|
|
|
116
116
|
const firstClient = result.current;
|
|
117
117
|
expect(BibleClient).toHaveBeenCalledTimes(1);
|
|
118
118
|
expect(ApiClient).toHaveBeenCalledWith({
|
|
119
|
-
|
|
119
|
+
appKey: mockAppKey,
|
|
120
120
|
installationId: 'auto-generated-uuid',
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
currentAppKey = 'new-app-key';
|
|
124
124
|
rerender();
|
|
125
125
|
|
|
126
126
|
const secondClient = result.current;
|
|
@@ -128,16 +128,16 @@ describe('useBibleClient', () => {
|
|
|
128
128
|
expect(firstClient).not.toBe(secondClient);
|
|
129
129
|
|
|
130
130
|
expect(ApiClient).toHaveBeenLastCalledWith({
|
|
131
|
-
|
|
131
|
+
appKey: 'new-app-key',
|
|
132
132
|
installationId: 'auto-generated-uuid',
|
|
133
133
|
});
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
-
it('should throw error when
|
|
136
|
+
it('should throw error when appKey is null', () => {
|
|
137
137
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
138
138
|
<BibleSDKContext.Provider
|
|
139
139
|
value={{
|
|
140
|
-
|
|
140
|
+
appKey: null as unknown as string,
|
|
141
141
|
}}
|
|
142
142
|
>
|
|
143
143
|
{children}
|
package/src/useBibleClient.ts
CHANGED
|
@@ -7,16 +7,16 @@ import { BibleClient, ApiClient, YouVersionPlatformConfiguration } from '@youver
|
|
|
7
7
|
export function useBibleClient(): BibleClient {
|
|
8
8
|
const context = useContext(BibleSDKContext);
|
|
9
9
|
return useMemo(() => {
|
|
10
|
-
if (!context?.
|
|
10
|
+
if (!context?.appKey) {
|
|
11
11
|
throw new Error(
|
|
12
12
|
'BibleSDK context not found. Make sure your component is wrapped with BibleSDKProvider and an API key is provided.',
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
15
|
return new BibleClient(
|
|
16
16
|
new ApiClient({
|
|
17
|
-
|
|
17
|
+
appKey: context.appKey,
|
|
18
18
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
19
19
|
}),
|
|
20
20
|
);
|
|
21
|
-
}, [context?.
|
|
21
|
+
}, [context?.appKey]);
|
|
22
22
|
}
|
|
@@ -31,7 +31,7 @@ vi.mock('@youversion/platform-core', async () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
describe('useHighlights', () => {
|
|
34
|
-
const
|
|
34
|
+
const mockAppKey = 'test-app-key';
|
|
35
35
|
|
|
36
36
|
const mockHighlights: Collection<Highlight> = {
|
|
37
37
|
data: [
|
|
@@ -59,7 +59,7 @@ describe('useHighlights', () => {
|
|
|
59
59
|
let mockCreateHighlight: Mock;
|
|
60
60
|
let mockDeleteHighlight: Mock;
|
|
61
61
|
|
|
62
|
-
const createWrapper = (contextValue: {
|
|
62
|
+
const createWrapper = (contextValue: { appKey: string }) => {
|
|
63
63
|
return ({ children }: { children: ReactNode }) => (
|
|
64
64
|
<BibleSDKContext.Provider value={contextValue}>{children}</BibleSDKContext.Provider>
|
|
65
65
|
);
|
|
@@ -94,9 +94,9 @@ describe('useHighlights', () => {
|
|
|
94
94
|
);
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
-
it('should throw error when
|
|
97
|
+
it('should throw error when appKey is missing', () => {
|
|
98
98
|
const wrapper = createWrapper({
|
|
99
|
-
|
|
99
|
+
appKey: '',
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
expect(() => renderHook(() => useHighlights(), { wrapper })).toThrow(
|
|
@@ -108,13 +108,13 @@ describe('useHighlights', () => {
|
|
|
108
108
|
describe('client creation', () => {
|
|
109
109
|
it('should create HighlightsClient with correct ApiClient config', () => {
|
|
110
110
|
const wrapper = createWrapper({
|
|
111
|
-
|
|
111
|
+
appKey: mockAppKey,
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
renderHook(() => useHighlights(), { wrapper });
|
|
115
115
|
|
|
116
116
|
expect(ApiClient).toHaveBeenCalledWith({
|
|
117
|
-
|
|
117
|
+
appKey: mockAppKey,
|
|
118
118
|
installationId: 'auto-generated-uuid',
|
|
119
119
|
});
|
|
120
120
|
expect(HighlightsClient).toHaveBeenCalledWith(expect.objectContaining({ isApiClient: true }));
|
|
@@ -122,7 +122,7 @@ describe('useHighlights', () => {
|
|
|
122
122
|
|
|
123
123
|
it('should memoize HighlightsClient instance', () => {
|
|
124
124
|
const wrapper = createWrapper({
|
|
125
|
-
|
|
125
|
+
appKey: mockAppKey,
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
const { rerender } = renderHook(() => useHighlights(), { wrapper });
|
|
@@ -134,12 +134,12 @@ describe('useHighlights', () => {
|
|
|
134
134
|
});
|
|
135
135
|
|
|
136
136
|
it('should create new HighlightsClient when context values change', () => {
|
|
137
|
-
let
|
|
137
|
+
let currentAppKey = mockAppKey;
|
|
138
138
|
|
|
139
139
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
140
140
|
<BibleSDKContext.Provider
|
|
141
141
|
value={{
|
|
142
|
-
|
|
142
|
+
appKey: currentAppKey,
|
|
143
143
|
}}
|
|
144
144
|
>
|
|
145
145
|
{children}
|
|
@@ -150,7 +150,7 @@ describe('useHighlights', () => {
|
|
|
150
150
|
|
|
151
151
|
expect(HighlightsClient).toHaveBeenCalledTimes(1);
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
currentAppKey = 'new-app-key';
|
|
154
154
|
|
|
155
155
|
rerender();
|
|
156
156
|
|
|
@@ -161,7 +161,7 @@ describe('useHighlights', () => {
|
|
|
161
161
|
describe('fetching highlights', () => {
|
|
162
162
|
it('should fetch highlights with no options', async () => {
|
|
163
163
|
const wrapper = createWrapper({
|
|
164
|
-
|
|
164
|
+
appKey: mockAppKey,
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
const { result } = renderHook(() => useHighlights(), { wrapper });
|
|
@@ -179,7 +179,7 @@ describe('useHighlights', () => {
|
|
|
179
179
|
|
|
180
180
|
it('should fetch highlights with version_id option', async () => {
|
|
181
181
|
const wrapper = createWrapper({
|
|
182
|
-
|
|
182
|
+
appKey: mockAppKey,
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
const { result } = renderHook(() => useHighlights({ version_id: 111 }), { wrapper });
|
|
@@ -194,7 +194,7 @@ describe('useHighlights', () => {
|
|
|
194
194
|
|
|
195
195
|
it('should fetch highlights with passage_id option', async () => {
|
|
196
196
|
const wrapper = createWrapper({
|
|
197
|
-
|
|
197
|
+
appKey: mockAppKey,
|
|
198
198
|
});
|
|
199
199
|
|
|
200
200
|
const { result } = renderHook(() => useHighlights({ passage_id: 'MAT.1.1' }), { wrapper });
|
|
@@ -209,7 +209,7 @@ describe('useHighlights', () => {
|
|
|
209
209
|
|
|
210
210
|
it('should fetch highlights with both options', async () => {
|
|
211
211
|
const wrapper = createWrapper({
|
|
212
|
-
|
|
212
|
+
appKey: mockAppKey,
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
const { result } = renderHook(
|
|
@@ -232,7 +232,7 @@ describe('useHighlights', () => {
|
|
|
232
232
|
|
|
233
233
|
it('should refetch when options change', async () => {
|
|
234
234
|
const wrapper = createWrapper({
|
|
235
|
-
|
|
235
|
+
appKey: mockAppKey,
|
|
236
236
|
});
|
|
237
237
|
|
|
238
238
|
const { result, rerender } = renderHook(({ options }) => useHighlights(options), {
|
|
@@ -258,7 +258,7 @@ describe('useHighlights', () => {
|
|
|
258
258
|
|
|
259
259
|
it('should not fetch when enabled is false', async () => {
|
|
260
260
|
const wrapper = createWrapper({
|
|
261
|
-
|
|
261
|
+
appKey: mockAppKey,
|
|
262
262
|
});
|
|
263
263
|
|
|
264
264
|
const { result } = renderHook(() => useHighlights(undefined, { enabled: false }), {
|
|
@@ -278,7 +278,7 @@ describe('useHighlights', () => {
|
|
|
278
278
|
mockGetHighlights.mockRejectedValueOnce(error);
|
|
279
279
|
|
|
280
280
|
const wrapper = createWrapper({
|
|
281
|
-
|
|
281
|
+
appKey: mockAppKey,
|
|
282
282
|
});
|
|
283
283
|
|
|
284
284
|
const { result } = renderHook(() => useHighlights(), { wrapper });
|
|
@@ -293,7 +293,7 @@ describe('useHighlights', () => {
|
|
|
293
293
|
|
|
294
294
|
it('should support manual refetch', async () => {
|
|
295
295
|
const wrapper = createWrapper({
|
|
296
|
-
|
|
296
|
+
appKey: mockAppKey,
|
|
297
297
|
});
|
|
298
298
|
|
|
299
299
|
const { result } = renderHook(() => useHighlights(), { wrapper });
|
|
@@ -315,7 +315,7 @@ describe('useHighlights', () => {
|
|
|
315
315
|
describe('createHighlight mutation', () => {
|
|
316
316
|
it('should create highlight and refetch', async () => {
|
|
317
317
|
const wrapper = createWrapper({
|
|
318
|
-
|
|
318
|
+
appKey: mockAppKey,
|
|
319
319
|
});
|
|
320
320
|
|
|
321
321
|
const { result } = renderHook(() => useHighlights(), { wrapper });
|
|
@@ -350,7 +350,7 @@ describe('useHighlights', () => {
|
|
|
350
350
|
mockCreateHighlight.mockRejectedValueOnce(error);
|
|
351
351
|
|
|
352
352
|
const wrapper = createWrapper({
|
|
353
|
-
|
|
353
|
+
appKey: mockAppKey,
|
|
354
354
|
});
|
|
355
355
|
|
|
356
356
|
const { result } = renderHook(() => useHighlights(), { wrapper });
|
|
@@ -377,7 +377,7 @@ describe('useHighlights', () => {
|
|
|
377
377
|
describe('deleteHighlight mutation', () => {
|
|
378
378
|
it('should delete highlight and refetch', async () => {
|
|
379
379
|
const wrapper = createWrapper({
|
|
380
|
-
|
|
380
|
+
appKey: mockAppKey,
|
|
381
381
|
});
|
|
382
382
|
|
|
383
383
|
const { result } = renderHook(() => useHighlights(), { wrapper });
|
|
@@ -402,7 +402,7 @@ describe('useHighlights', () => {
|
|
|
402
402
|
|
|
403
403
|
it('should delete highlight with options', async () => {
|
|
404
404
|
const wrapper = createWrapper({
|
|
405
|
-
|
|
405
|
+
appKey: mockAppKey,
|
|
406
406
|
});
|
|
407
407
|
|
|
408
408
|
const { result } = renderHook(() => useHighlights(), { wrapper });
|
|
@@ -428,7 +428,7 @@ describe('useHighlights', () => {
|
|
|
428
428
|
mockDeleteHighlight.mockRejectedValueOnce(error);
|
|
429
429
|
|
|
430
430
|
const wrapper = createWrapper({
|
|
431
|
-
|
|
431
|
+
appKey: mockAppKey,
|
|
432
432
|
});
|
|
433
433
|
|
|
434
434
|
const { result } = renderHook(() => useHighlights(), { wrapper });
|
package/src/useHighlights.ts
CHANGED
|
@@ -31,18 +31,18 @@ export function useHighlights(
|
|
|
31
31
|
const context = useContext(BibleSDKContext);
|
|
32
32
|
|
|
33
33
|
const highlightsClient = useMemo(() => {
|
|
34
|
-
if (!context?.
|
|
34
|
+
if (!context?.appKey) {
|
|
35
35
|
throw new Error(
|
|
36
36
|
'BibleSDK context not found. Make sure your component is wrapped with BibleSDKProvider and an API key is provided.',
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
return new HighlightsClient(
|
|
40
40
|
new ApiClient({
|
|
41
|
-
|
|
41
|
+
appKey: context.appKey,
|
|
42
42
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
43
43
|
}),
|
|
44
44
|
);
|
|
45
|
-
}, [context?.
|
|
45
|
+
}, [context?.appKey]);
|
|
46
46
|
|
|
47
47
|
const { data, loading, error, refetch } = useApiData<Collection<Highlight>>(
|
|
48
48
|
() => highlightsClient.getHighlights(options),
|
|
@@ -31,7 +31,7 @@ vi.mock('@youversion/platform-core', async () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
describe('useLanguages', () => {
|
|
34
|
-
const
|
|
34
|
+
const mockAppKey = 'test-app-key';
|
|
35
35
|
|
|
36
36
|
const mockLanguages: Collection<Language> = {
|
|
37
37
|
data: [
|
|
@@ -77,7 +77,7 @@ describe('useLanguages', () => {
|
|
|
77
77
|
|
|
78
78
|
let mockGetLanguages: Mock;
|
|
79
79
|
|
|
80
|
-
const createWrapper = (contextValue: {
|
|
80
|
+
const createWrapper = (contextValue: { appKey: string }) => {
|
|
81
81
|
return ({ children }: { children: ReactNode }) => (
|
|
82
82
|
<BibleSDKContext.Provider value={contextValue}>{children}</BibleSDKContext.Provider>
|
|
83
83
|
);
|
|
@@ -108,9 +108,9 @@ describe('useLanguages', () => {
|
|
|
108
108
|
);
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
it('should throw error when
|
|
111
|
+
it('should throw error when appKey is missing', () => {
|
|
112
112
|
const wrapper = createWrapper({
|
|
113
|
-
|
|
113
|
+
appKey: '',
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
expect(() => renderHook(() => useLanguages({ country: 'US' }), { wrapper })).toThrow(
|
|
@@ -122,13 +122,13 @@ describe('useLanguages', () => {
|
|
|
122
122
|
describe('client creation', () => {
|
|
123
123
|
it('should create LanguagesClient with correct ApiClient config', () => {
|
|
124
124
|
const wrapper = createWrapper({
|
|
125
|
-
|
|
125
|
+
appKey: mockAppKey,
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
renderHook(() => useLanguages({ country: 'US' }), { wrapper });
|
|
129
129
|
|
|
130
130
|
expect(ApiClient).toHaveBeenCalledWith({
|
|
131
|
-
|
|
131
|
+
appKey: mockAppKey,
|
|
132
132
|
installationId: 'auto-generated-uuid',
|
|
133
133
|
});
|
|
134
134
|
expect(LanguagesClient).toHaveBeenCalledWith(expect.objectContaining({ isApiClient: true }));
|
|
@@ -136,7 +136,7 @@ describe('useLanguages', () => {
|
|
|
136
136
|
|
|
137
137
|
it('should memoize LanguagesClient instance', () => {
|
|
138
138
|
const wrapper = createWrapper({
|
|
139
|
-
|
|
139
|
+
appKey: mockAppKey,
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
const { result, rerender } = renderHook(() => useLanguages({ country: 'US' }), { wrapper });
|
|
@@ -149,12 +149,12 @@ describe('useLanguages', () => {
|
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
it('should create new LanguagesClient when context values change', () => {
|
|
152
|
-
let
|
|
152
|
+
let currentAppKey = mockAppKey;
|
|
153
153
|
|
|
154
154
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
155
155
|
<BibleSDKContext.Provider
|
|
156
156
|
value={{
|
|
157
|
-
|
|
157
|
+
appKey: currentAppKey,
|
|
158
158
|
}}
|
|
159
159
|
>
|
|
160
160
|
{children}
|
|
@@ -165,7 +165,7 @@ describe('useLanguages', () => {
|
|
|
165
165
|
|
|
166
166
|
expect(LanguagesClient).toHaveBeenCalledTimes(1);
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
currentAppKey = 'new-app-key';
|
|
169
169
|
rerender();
|
|
170
170
|
|
|
171
171
|
expect(LanguagesClient).toHaveBeenCalledTimes(2);
|
|
@@ -175,7 +175,7 @@ describe('useLanguages', () => {
|
|
|
175
175
|
describe('fetching languages', () => {
|
|
176
176
|
it('should fetch languages with required country', async () => {
|
|
177
177
|
const wrapper = createWrapper({
|
|
178
|
-
|
|
178
|
+
appKey: mockAppKey,
|
|
179
179
|
});
|
|
180
180
|
|
|
181
181
|
const { result } = renderHook(() => useLanguages({ country: 'US' }), { wrapper });
|
|
@@ -193,7 +193,7 @@ describe('useLanguages', () => {
|
|
|
193
193
|
|
|
194
194
|
it('should fetch languages with all options', async () => {
|
|
195
195
|
const wrapper = createWrapper({
|
|
196
|
-
|
|
196
|
+
appKey: mockAppKey,
|
|
197
197
|
});
|
|
198
198
|
|
|
199
199
|
const options: GetLanguagesOptions = {
|
|
@@ -214,7 +214,7 @@ describe('useLanguages', () => {
|
|
|
214
214
|
|
|
215
215
|
it('should refetch when options change', async () => {
|
|
216
216
|
const wrapper = createWrapper({
|
|
217
|
-
|
|
217
|
+
appKey: mockAppKey,
|
|
218
218
|
});
|
|
219
219
|
|
|
220
220
|
const { result, rerender } = renderHook(({ options }) => useLanguages(options), {
|
|
@@ -240,7 +240,7 @@ describe('useLanguages', () => {
|
|
|
240
240
|
|
|
241
241
|
it('should not fetch when enabled is false', async () => {
|
|
242
242
|
const wrapper = createWrapper({
|
|
243
|
-
|
|
243
|
+
appKey: mockAppKey,
|
|
244
244
|
});
|
|
245
245
|
|
|
246
246
|
const { result } = renderHook(() => useLanguages({ country: 'US' }, { enabled: false }), {
|
|
@@ -260,7 +260,7 @@ describe('useLanguages', () => {
|
|
|
260
260
|
mockGetLanguages.mockRejectedValueOnce(error);
|
|
261
261
|
|
|
262
262
|
const wrapper = createWrapper({
|
|
263
|
-
|
|
263
|
+
appKey: mockAppKey,
|
|
264
264
|
});
|
|
265
265
|
|
|
266
266
|
const { result } = renderHook(() => useLanguages({ country: 'US' }), { wrapper });
|
|
@@ -275,7 +275,7 @@ describe('useLanguages', () => {
|
|
|
275
275
|
|
|
276
276
|
it('should support manual refetch', async () => {
|
|
277
277
|
const wrapper = createWrapper({
|
|
278
|
-
|
|
278
|
+
appKey: mockAppKey,
|
|
279
279
|
});
|
|
280
280
|
|
|
281
281
|
const { result } = renderHook(() => useLanguages({ country: 'US' }), { wrapper });
|
package/src/useLanguages.ts
CHANGED
|
@@ -27,18 +27,18 @@ export function useLanguages(
|
|
|
27
27
|
const context = useContext(BibleSDKContext);
|
|
28
28
|
|
|
29
29
|
const languagesClient = useMemo(() => {
|
|
30
|
-
if (!context?.
|
|
30
|
+
if (!context?.appKey) {
|
|
31
31
|
throw new Error(
|
|
32
32
|
'BibleSDK context not found. Make sure your component is wrapped with BibleSDKProvider and an API key is provided.',
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
return new LanguagesClient(
|
|
36
36
|
new ApiClient({
|
|
37
|
-
|
|
37
|
+
appKey: context.appKey,
|
|
38
38
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
39
39
|
}),
|
|
40
40
|
);
|
|
41
|
-
}, [context?.
|
|
41
|
+
}, [context?.appKey]);
|
|
42
42
|
|
|
43
43
|
const { data, loading, error, refetch } = useApiData<Collection<Language>>(
|
|
44
44
|
() => languagesClient.getLanguages(options),
|
package/src/useVOTD.test.tsx
CHANGED
|
@@ -27,7 +27,7 @@ vi.mock('@youversion/platform-core', async () => {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
describe('useVerseOfTheDay', () => {
|
|
30
|
-
const
|
|
30
|
+
const mockAppKey = 'test-app-key';
|
|
31
31
|
|
|
32
32
|
const mockVOTD: VOTD = {
|
|
33
33
|
day: 1,
|
|
@@ -36,7 +36,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
36
36
|
|
|
37
37
|
let mockGetVOTD: Mock;
|
|
38
38
|
|
|
39
|
-
const createWrapper = (contextValue: {
|
|
39
|
+
const createWrapper = (contextValue: { appKey: string }) => {
|
|
40
40
|
return ({ children }: { children: ReactNode }) => (
|
|
41
41
|
<BibleSDKContext.Provider value={contextValue}>{children}</BibleSDKContext.Provider>
|
|
42
42
|
);
|
|
@@ -67,9 +67,9 @@ describe('useVerseOfTheDay', () => {
|
|
|
67
67
|
);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
it('should throw error when
|
|
70
|
+
it('should throw error when appKey is missing', () => {
|
|
71
71
|
const wrapper = createWrapper({
|
|
72
|
-
|
|
72
|
+
appKey: '',
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
expect(() => renderHook(() => useVerseOfTheDay(1), { wrapper })).toThrow(
|
|
@@ -81,13 +81,13 @@ describe('useVerseOfTheDay', () => {
|
|
|
81
81
|
describe('client creation', () => {
|
|
82
82
|
it('should create BibleClient with correct ApiClient config', () => {
|
|
83
83
|
const wrapper = createWrapper({
|
|
84
|
-
|
|
84
|
+
appKey: mockAppKey,
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
renderHook(() => useVerseOfTheDay(1), { wrapper });
|
|
88
88
|
|
|
89
89
|
expect(ApiClient).toHaveBeenCalledWith({
|
|
90
|
-
|
|
90
|
+
appKey: mockAppKey,
|
|
91
91
|
installationId: MOCK_INSTALLATION_ID,
|
|
92
92
|
});
|
|
93
93
|
expect(BibleClient).toHaveBeenCalledWith(expect.objectContaining({ isApiClient: true }));
|
|
@@ -95,7 +95,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
95
95
|
|
|
96
96
|
it('should memoize BibleClient instance', () => {
|
|
97
97
|
const wrapper = createWrapper({
|
|
98
|
-
|
|
98
|
+
appKey: mockAppKey,
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
const { result, rerender } = renderHook(() => useVerseOfTheDay(1), { wrapper });
|
|
@@ -108,12 +108,12 @@ describe('useVerseOfTheDay', () => {
|
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
it('should create new BibleClient when context values change', () => {
|
|
111
|
-
let
|
|
111
|
+
let currentAppKey = mockAppKey;
|
|
112
112
|
|
|
113
113
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
114
114
|
<BibleSDKContext.Provider
|
|
115
115
|
value={{
|
|
116
|
-
|
|
116
|
+
appKey: currentAppKey,
|
|
117
117
|
}}
|
|
118
118
|
>
|
|
119
119
|
{children}
|
|
@@ -124,7 +124,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
124
124
|
|
|
125
125
|
expect(BibleClient).toHaveBeenCalledTimes(1);
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
currentAppKey = 'new-app-key';
|
|
128
128
|
rerender();
|
|
129
129
|
|
|
130
130
|
expect(BibleClient).toHaveBeenCalledTimes(2);
|
|
@@ -134,7 +134,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
134
134
|
describe('fetching VOTD', () => {
|
|
135
135
|
it('should fetch VOTD for day 1', async () => {
|
|
136
136
|
const wrapper = createWrapper({
|
|
137
|
-
|
|
137
|
+
appKey: mockAppKey,
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
const { result } = renderHook(() => useVerseOfTheDay(1), { wrapper });
|
|
@@ -155,7 +155,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
155
155
|
mockGetVOTD.mockResolvedValueOnce(mockVOTD100);
|
|
156
156
|
|
|
157
157
|
const wrapper = createWrapper({
|
|
158
|
-
|
|
158
|
+
appKey: mockAppKey,
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
const { result } = renderHook(() => useVerseOfTheDay(100), { wrapper });
|
|
@@ -173,7 +173,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
173
173
|
mockGetVOTD.mockResolvedValueOnce(mockVOTD366);
|
|
174
174
|
|
|
175
175
|
const wrapper = createWrapper({
|
|
176
|
-
|
|
176
|
+
appKey: mockAppKey,
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
const { result } = renderHook(() => useVerseOfTheDay(366), { wrapper });
|
|
@@ -188,7 +188,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
188
188
|
|
|
189
189
|
it('should refetch when day changes', async () => {
|
|
190
190
|
const wrapper = createWrapper({
|
|
191
|
-
|
|
191
|
+
appKey: mockAppKey,
|
|
192
192
|
});
|
|
193
193
|
|
|
194
194
|
const { result, rerender } = renderHook(({ day }) => useVerseOfTheDay(day), {
|
|
@@ -215,7 +215,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
215
215
|
|
|
216
216
|
it('should not fetch when enabled is false', async () => {
|
|
217
217
|
const wrapper = createWrapper({
|
|
218
|
-
|
|
218
|
+
appKey: mockAppKey,
|
|
219
219
|
});
|
|
220
220
|
|
|
221
221
|
const { result } = renderHook(() => useVerseOfTheDay(1, { enabled: false }), { wrapper });
|
|
@@ -233,7 +233,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
233
233
|
mockGetVOTD.mockRejectedValueOnce(error);
|
|
234
234
|
|
|
235
235
|
const wrapper = createWrapper({
|
|
236
|
-
|
|
236
|
+
appKey: mockAppKey,
|
|
237
237
|
});
|
|
238
238
|
|
|
239
239
|
const { result } = renderHook(() => useVerseOfTheDay(1), { wrapper });
|
|
@@ -248,7 +248,7 @@ describe('useVerseOfTheDay', () => {
|
|
|
248
248
|
|
|
249
249
|
it('should support manual refetch', async () => {
|
|
250
250
|
const wrapper = createWrapper({
|
|
251
|
-
|
|
251
|
+
appKey: mockAppKey,
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
const { result } = renderHook(() => useVerseOfTheDay(1), { wrapper });
|