@kivacore/api-client 0.0.0 → 0.3.8
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/README.md +792 -1
- package/REVIEW.md +292 -0
- package/dist/index.d.ts +597 -0
- package/dist/index.js +1486 -0
- package/dist/index.js.map +1 -0
- package/dist/react-native/index.d.ts +75 -0
- package/dist/react-native/index.js +1534 -0
- package/dist/react-native/index.js.map +1 -0
- package/docyrus-api-query-guide.md +2057 -0
- package/package.json +40 -3
- package/src/clients/base-client.ts +570 -0
- package/src/clients/cf-client.ts +82 -0
- package/src/clients/edge-client.ts +34 -0
- package/src/clients/rest-client.ts +58 -0
- package/src/core/crypto.ts +63 -0
- package/src/core/errors.ts +183 -0
- package/src/core/token-manager.ts +59 -0
- package/src/core/types.ts +96 -0
- package/src/core/utils.ts +138 -0
- package/src/index.ts +112 -0
- package/src/oauth2/index.ts +37 -0
- package/src/oauth2/oauth2-client.ts +668 -0
- package/src/oauth2/oauth2-token-manager.ts +128 -0
- package/src/oauth2/oauth2-types.ts +234 -0
- package/src/oauth2/pkce.ts +121 -0
- package/src/react-native/index.ts +112 -0
- package/src/react-native/rn-crypto.ts +115 -0
- package/src/react-native/rn-helpers.ts +89 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +13 -0
- package/vitest.config.mts +13 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native helpers for @kivacore/api-client.
|
|
3
|
+
*
|
|
4
|
+
* Provides a factory function to create OAuth2TokenStorage from any
|
|
5
|
+
* key-value storage adapter (AsyncStorage, SecureStore, MMKV, SQLite, etc.)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { type OAuth2TokenStorage, type OAuth2Tokens, type PKCEState } from '../oauth2/oauth2-types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generic async key-value storage adapter interface.
|
|
12
|
+
* Compatible with most React Native storage libraries out of the box.
|
|
13
|
+
*/
|
|
14
|
+
export interface StorageAdapter {
|
|
15
|
+
getItem(key: string): Promise<string | null>;
|
|
16
|
+
setItem(key: string, value: string): Promise<void>;
|
|
17
|
+
removeItem(key: string): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an OAuth2TokenStorage implementation from any key-value storage adapter.
|
|
22
|
+
*
|
|
23
|
+
* Usage with expo-secure-store:
|
|
24
|
+
* ```ts
|
|
25
|
+
* import * as SecureStore from 'expo-secure-store';
|
|
26
|
+
*
|
|
27
|
+
* const tokenStorage = createTokenStorage({
|
|
28
|
+
* getItem: (key) => SecureStore.getItemAsync(key),
|
|
29
|
+
* setItem: (key, value) => SecureStore.setItemAsync(key, value),
|
|
30
|
+
* removeItem: (key) => SecureStore.deleteItemAsync(key),
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Usage with @react-native-async-storage/async-storage:
|
|
35
|
+
* ```ts
|
|
36
|
+
* import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
37
|
+
*
|
|
38
|
+
* const tokenStorage = createTokenStorage(AsyncStorage);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function createTokenStorage(
|
|
42
|
+
adapter: StorageAdapter,
|
|
43
|
+
prefix: string = 'docyrus_oauth2'
|
|
44
|
+
): OAuth2TokenStorage {
|
|
45
|
+
const tokensKey = `${prefix}_tokens`;
|
|
46
|
+
const pkceKey = `${prefix}_pkce`;
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
async getTokens(): Promise<OAuth2Tokens | null> {
|
|
50
|
+
const raw = await adapter.getItem(tokensKey);
|
|
51
|
+
|
|
52
|
+
if (!raw) return null;
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(raw) as OAuth2Tokens;
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
async setTokens(tokens: OAuth2Tokens): Promise<void> {
|
|
62
|
+
await adapter.setItem(tokensKey, JSON.stringify(tokens));
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
async clearTokens(): Promise<void> {
|
|
66
|
+
await adapter.removeItem(tokensKey);
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
async getPKCEState(): Promise<PKCEState | null> {
|
|
70
|
+
const raw = await adapter.getItem(pkceKey);
|
|
71
|
+
|
|
72
|
+
if (!raw) return null;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
return JSON.parse(raw) as PKCEState;
|
|
76
|
+
} catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
async setPKCEState(state: PKCEState): Promise<void> {
|
|
82
|
+
await adapter.setItem(pkceKey, JSON.stringify(state));
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
async clearPKCEState(): Promise<void> {
|
|
86
|
+
await adapter.removeItem(pkceKey);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ['src/index.ts', 'src/react-native/index.ts'],
|
|
5
|
+
format: ['esm'],
|
|
6
|
+
dts: true,
|
|
7
|
+
splitting: false,
|
|
8
|
+
sourcemap: true,
|
|
9
|
+
clean: true,
|
|
10
|
+
treeshake: true,
|
|
11
|
+
minify: false,
|
|
12
|
+
external: ['expo-crypto']
|
|
13
|
+
});
|