@smartcrab/react-native 0.1.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/LICENSE +202 -0
- package/app.plugin.js +9 -0
- package/dist/adapters/expo-crypto-port.d.ts +3 -0
- package/dist/adapters/expo-crypto-port.js +8 -0
- package/dist/adapters/expo-linking-port.d.ts +3 -0
- package/dist/adapters/expo-linking-port.js +21 -0
- package/dist/adapters/expo-secure-store-port.d.ts +11 -0
- package/dist/adapters/expo-secure-store-port.js +15 -0
- package/dist/adapters/expo-web-browser-port.d.ts +7 -0
- package/dist/adapters/expo-web-browser-port.js +9 -0
- package/dist/adapters/react-native-app-state-port.d.ts +8 -0
- package/dist/adapters/react-native-app-state-port.js +13 -0
- package/dist/adapters/react-native-passkeys-adapter.d.ts +2 -0
- package/dist/adapters/react-native-passkeys-adapter.js +112 -0
- package/dist/adapters/react-native-passkeys-adapter.test.d.ts +1 -0
- package/dist/adapters/react-native-passkeys-adapter.test.js +76 -0
- package/dist/base64url.d.ts +20 -0
- package/dist/base64url.js +89 -0
- package/dist/base64url.test.d.ts +1 -0
- package/dist/base64url.test.js +36 -0
- package/dist/browser-port.d.ts +17 -0
- package/dist/browser-port.js +1 -0
- package/dist/client.d.ts +43 -0
- package/dist/client.js +871 -0
- package/dist/client.test.d.ts +1 -0
- package/dist/client.test.js +995 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.js +17 -0
- package/dist/crypto-port.d.ts +16 -0
- package/dist/crypto-port.js +1 -0
- package/dist/errors.d.ts +113 -0
- package/dist/errors.js +82 -0
- package/dist/errors.test.d.ts +1 -0
- package/dist/errors.test.js +81 -0
- package/dist/hooks.d.ts +93 -0
- package/dist/hooks.js +191 -0
- package/dist/http.d.ts +41 -0
- package/dist/http.js +102 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +29 -0
- package/dist/jwt.d.ts +1 -0
- package/dist/jwt.js +23 -0
- package/dist/lifecycle-ports.d.ts +29 -0
- package/dist/lifecycle-ports.js +1 -0
- package/dist/linking-port.d.ts +15 -0
- package/dist/linking-port.js +1 -0
- package/dist/passkey-adapter.d.ts +20 -0
- package/dist/passkey-adapter.js +1 -0
- package/dist/pkce.d.ts +32 -0
- package/dist/pkce.js +41 -0
- package/dist/pkce.test.d.ts +1 -0
- package/dist/pkce.test.js +66 -0
- package/dist/plugin.d.ts +89 -0
- package/dist/plugin.js +242 -0
- package/dist/plugin.test.d.ts +1 -0
- package/dist/plugin.test.js +210 -0
- package/dist/provider.d.ts +14 -0
- package/dist/provider.js +5 -0
- package/dist/secure-store.d.ts +54 -0
- package/dist/secure-store.js +55 -0
- package/dist/secure-store.test.d.ts +1 -0
- package/dist/secure-store.test.js +69 -0
- package/dist/types.d.ts +177 -0
- package/dist/types.js +1 -0
- package/package.json +69 -0
- package/src/adapters/expo-crypto-port.ts +11 -0
- package/src/adapters/expo-linking-port.ts +23 -0
- package/src/adapters/expo-secure-store-port.ts +20 -0
- package/src/adapters/expo-web-browser-port.ts +16 -0
- package/src/adapters/react-native-app-state-port.ts +15 -0
- package/src/adapters/react-native-passkeys-adapter.test.ts +87 -0
- package/src/adapters/react-native-passkeys-adapter.ts +138 -0
- package/src/base64url.test.ts +47 -0
- package/src/base64url.ts +92 -0
- package/src/browser-port.ts +19 -0
- package/src/client.test.ts +1275 -0
- package/src/client.ts +1329 -0
- package/src/context.ts +20 -0
- package/src/crypto-port.ts +16 -0
- package/src/errors.test.ts +94 -0
- package/src/errors.ts +216 -0
- package/src/hooks.ts +374 -0
- package/src/http.ts +159 -0
- package/src/index.ts +101 -0
- package/src/jwt.ts +24 -0
- package/src/lifecycle-ports.ts +32 -0
- package/src/linking-port.ts +16 -0
- package/src/passkey-adapter.ts +20 -0
- package/src/pkce.test.ts +84 -0
- package/src/pkce.ts +62 -0
- package/src/plugin.test.ts +303 -0
- package/src/plugin.ts +387 -0
- package/src/provider.tsx +20 -0
- package/src/secure-store.test.ts +91 -0
- package/src/secure-store.ts +102 -0
- package/src/types.ts +181 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { ClientId, SocialProvider } from "@smartcrab/contracts-public";
|
|
2
|
+
import type { WebBrowserPort } from "./browser-port.js";
|
|
3
|
+
import type { CryptoPort } from "./crypto-port.js";
|
|
4
|
+
import type { FetchPort } from "./http.js";
|
|
5
|
+
import type { AppStatePort, NetworkStatusPort } from "./lifecycle-ports.js";
|
|
6
|
+
import type { LinkingPort } from "./linking-port.js";
|
|
7
|
+
import type { PasskeyNativeAdapter } from "./passkey-adapter.js";
|
|
8
|
+
import type { SecureStorePort } from "./secure-store.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Public types for `@smartcrab/react-native` (design.md §21.3, §21.8).
|
|
12
|
+
*
|
|
13
|
+
* `ReactNativeAuthConfig`'s required fields are exactly the ones design.md
|
|
14
|
+
* §21.8's sample supplies (`issuer`, `clientId`, `redirectUri`); every other
|
|
15
|
+
* field (scopes, resource, and every injectable port) is optional with a
|
|
16
|
+
* production default backed by the corresponding peer dependency, so tests
|
|
17
|
+
* can substitute fakes without loading any native module.
|
|
18
|
+
*/
|
|
19
|
+
export interface ReactNativeAuthConfig {
|
|
20
|
+
/** OIDC issuer, e.g. `https://id.example-auth.com/e/env_xxx` (design.md §21.8, §15.1). */
|
|
21
|
+
readonly issuer: string;
|
|
22
|
+
readonly clientId: ClientId;
|
|
23
|
+
/** Must be byte-for-byte registered on the client (design.md §15.9), e.g. `com.customer.app:/oauth/callback`. */
|
|
24
|
+
readonly redirectUri: string;
|
|
25
|
+
/** Defaults to `["openid", "profile", "email", "offline_access"]` (design.md §21.8 sample). */
|
|
26
|
+
readonly scopes?: readonly string[];
|
|
27
|
+
/** RFC 8707 resource indicator(s) (design.md §16.1); a single string is normalized to a one-element array. */
|
|
28
|
+
readonly resource?: string | readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* Overrides the environment id this client would otherwise parse from
|
|
31
|
+
* `issuer`'s `/e/<environmentId>` path segment (design.md §21.6's
|
|
32
|
+
* SecureStore key format). Only needed when `issuer` does not follow that
|
|
33
|
+
* shape.
|
|
34
|
+
*/
|
|
35
|
+
readonly environmentId?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The passkey RP domain this app binary is built for (the config plugin's
|
|
38
|
+
* `rpDomain`: iOS `webcredentials:` / Android `asset_statements`). When set,
|
|
39
|
+
* every passkey options request pins `rp_id` to it.
|
|
40
|
+
*/
|
|
41
|
+
readonly rpDomain?: string;
|
|
42
|
+
/** Defaults to the global `fetch`. */
|
|
43
|
+
readonly fetch?: FetchPort;
|
|
44
|
+
/** Clock override for tests (epoch ms). */
|
|
45
|
+
readonly now?: () => number;
|
|
46
|
+
/** Defaults to an `expo-secure-store`-backed port (design.md §21.6). */
|
|
47
|
+
readonly secureStore?: SecureStorePort;
|
|
48
|
+
/** Defaults to a `react-native-passkeys`-backed adapter (design.md §21.2). */
|
|
49
|
+
readonly passkeyAdapter?: PasskeyNativeAdapter;
|
|
50
|
+
/** Defaults to an `expo-web-browser`-backed port (design.md §20.6: system browser only). */
|
|
51
|
+
readonly browser?: WebBrowserPort;
|
|
52
|
+
/** Defaults to an `expo-linking`-backed port. */
|
|
53
|
+
readonly linking?: LinkingPort;
|
|
54
|
+
/** Defaults to an `expo-crypto`-backed port (design.md §21.1). */
|
|
55
|
+
readonly crypto?: CryptoPort;
|
|
56
|
+
/** Defaults to React Native's own `AppState` (design.md §21.7 foreground trigger). */
|
|
57
|
+
readonly appState?: AppStatePort;
|
|
58
|
+
/**
|
|
59
|
+
* OPTIONAL: no connectivity-detection peer dependency is declared
|
|
60
|
+
* (design.md §21.1), so there is no production default. Supply one (e.g.
|
|
61
|
+
* backed by `@react-native-community/netinfo`) to get the network-recovery
|
|
62
|
+
* refresh trigger described in design.md §21.7; omitted, only the
|
|
63
|
+
* foreground trigger runs.
|
|
64
|
+
*/
|
|
65
|
+
readonly networkStatus?: NetworkStatusPort;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Session metadata (design.md §21.3). The access token itself is never exposed here — use `getAccessToken()`. */
|
|
69
|
+
export interface AuthSession {
|
|
70
|
+
readonly userId: string;
|
|
71
|
+
readonly scope: string;
|
|
72
|
+
readonly hasRefreshToken: boolean;
|
|
73
|
+
/** `null` when no access token is currently held in memory (e.g. immediately after an app relaunch). */
|
|
74
|
+
readonly accessTokenExpiresAt: number | null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface AuthResult {
|
|
78
|
+
readonly session: AuthSession;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Public projection of a passkey (design.md §21.3; mirrors contracts-public's `PasskeySummary`, camelCased). */
|
|
82
|
+
export interface Passkey {
|
|
83
|
+
readonly passkeyId: string;
|
|
84
|
+
readonly name: string | null;
|
|
85
|
+
readonly createdAt: string;
|
|
86
|
+
readonly lastUsedAt: string | null;
|
|
87
|
+
readonly deviceType: "single_device" | "multi_device" | null;
|
|
88
|
+
readonly backedUp: boolean;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Public projection of another signed-in device/session (design.md §21.3; mirrors `MeSessionSummary`). */
|
|
92
|
+
export interface DeviceSession {
|
|
93
|
+
readonly sessionId: string;
|
|
94
|
+
readonly clientId: string;
|
|
95
|
+
readonly deviceName: string | null;
|
|
96
|
+
readonly createdAt: string;
|
|
97
|
+
readonly lastActiveAt: string;
|
|
98
|
+
readonly current: boolean;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface EmailCodeChallenge {
|
|
102
|
+
readonly challengeId: string;
|
|
103
|
+
readonly expiresAt: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface AccessTokenRequest {
|
|
107
|
+
/** Forces a refresh even if the in-memory access token is not yet within the expiry skew. */
|
|
108
|
+
readonly forceRefresh?: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface RegisterPasskeyInput {
|
|
112
|
+
readonly name?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface AuthStateSnapshot {
|
|
116
|
+
readonly status: "signed_out" | "signed_in";
|
|
117
|
+
/** Runtime WebAuthn capability (design.md §21.2): the prebuilt UI hides `<PasskeyButton/>` when false. */
|
|
118
|
+
readonly passkeySupported: boolean;
|
|
119
|
+
readonly hasRefreshToken: boolean;
|
|
120
|
+
readonly accessTokenExpiresAt?: number;
|
|
121
|
+
readonly scope?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type AuthStateListener = (snapshot: AuthStateSnapshot) => void;
|
|
125
|
+
|
|
126
|
+
/** Public profile (design.md §16.2 `GET/PATCH /v1/me`; mirrors contracts-public's `MeUser`, camelCased). */
|
|
127
|
+
export interface UserProfile {
|
|
128
|
+
readonly userId: string;
|
|
129
|
+
readonly email: string | null;
|
|
130
|
+
readonly emailVerified: boolean;
|
|
131
|
+
readonly name: string | null;
|
|
132
|
+
readonly avatarUrl: string | null;
|
|
133
|
+
readonly locale: string | null;
|
|
134
|
+
readonly timezone: string | null;
|
|
135
|
+
readonly status: "active" | "blocked" | "pending_deletion";
|
|
136
|
+
readonly createdAt: string;
|
|
137
|
+
readonly lastLoginAt: string | null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface UpdateUserProfileInput {
|
|
141
|
+
readonly name?: string;
|
|
142
|
+
readonly avatarUrl?: string;
|
|
143
|
+
readonly locale?: string;
|
|
144
|
+
readonly timezone?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* `ReactNativeAuthClient` (design.md §21.3, verbatim member-for-member — every
|
|
149
|
+
* method design.md §21.3 lists is present with an identical signature).
|
|
150
|
+
*
|
|
151
|
+
* Two categories of members go beyond that list, both additive/non-breaking:
|
|
152
|
+
* - `getSnapshot`: a `useSyncExternalStore`-compatible synchronous read used
|
|
153
|
+
* by the React bindings (design.md §21.4).
|
|
154
|
+
* - `getMe`/`updateMe`: design.md §21.4 lists a `useUser()` hook, and §16.2
|
|
155
|
+
* documents `GET/PATCH /v1/me`, but §21.3's client interface snippet has no
|
|
156
|
+
* corresponding method — these back that hook. Documented here as a
|
|
157
|
+
* deliberate gap-fill, not a deviation from any §21.3 member.
|
|
158
|
+
*/
|
|
159
|
+
export interface ReactNativeAuthClient {
|
|
160
|
+
configure(config: ReactNativeAuthConfig): void;
|
|
161
|
+
getSession(): Promise<AuthSession | null>;
|
|
162
|
+
getAccessToken(input?: AccessTokenRequest): Promise<string>;
|
|
163
|
+
signInWithPasskey(): Promise<AuthResult>;
|
|
164
|
+
registerPasskey(input?: RegisterPasskeyInput): Promise<Passkey>;
|
|
165
|
+
sendEmailCode(input: { email: string }): Promise<EmailCodeChallenge>;
|
|
166
|
+
verifyEmailCode(input: { challengeId: string; code: string }): Promise<AuthResult>;
|
|
167
|
+
signInWithSocial(input: { provider: SocialProvider }): Promise<AuthResult>;
|
|
168
|
+
linkSocialAccount(input: { provider: SocialProvider }): Promise<void>;
|
|
169
|
+
listPasskeys(): Promise<Passkey[]>;
|
|
170
|
+
deletePasskey(passkeyId: string): Promise<void>;
|
|
171
|
+
listSessions(): Promise<DeviceSession[]>;
|
|
172
|
+
revokeSession(sessionId: string): Promise<void>;
|
|
173
|
+
signOut(): Promise<void>;
|
|
174
|
+
signOutAll(): Promise<void>;
|
|
175
|
+
subscribe(listener: AuthStateListener): () => void;
|
|
176
|
+
/** Synchronous snapshot read for `useSyncExternalStore` (design.md §21.4). */
|
|
177
|
+
getSnapshot(): AuthStateSnapshot;
|
|
178
|
+
/** Backs `useUser()` (design.md §21.4); see the interface doc comment above. */
|
|
179
|
+
getMe(): Promise<UserProfile>;
|
|
180
|
+
updateMe(input: UpdateUserProfileInput): Promise<UserProfile>;
|
|
181
|
+
}
|