@vvedantb/native-ui 0.32.0 → 0.34.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/dist/UpdateChecker.jsx +80 -61
- package/dist/auth/SignInScreen.jsx +28 -94
- package/dist/auth/clerkCore3.js +110 -0
- package/dist/auth/totp.js +49 -60
- package/dist/index.js +1 -1
- package/dist/updateCheck.js +32 -0
- package/package.json +2 -2
- package/src/UpdateChecker.tsx +30 -9
- package/src/auth/SignInScreen.tsx +25 -55
- package/src/auth/clerkCore3.ts +88 -0
- package/src/auth/totp.ts +5 -11
- package/src/index.ts +2 -2
- package/src/updateCheck.ts +45 -0
package/src/auth/totp.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import { useSignIn } from "@clerk/expo
|
|
2
|
+
import { useSignIn } from "@clerk/expo";
|
|
3
3
|
import {
|
|
4
4
|
authErrorMessage,
|
|
5
5
|
DEFAULT_STAGE_TIMEOUT_MS,
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
logAuthFailure,
|
|
8
8
|
withAuthTimeout,
|
|
9
9
|
} from "./authErrors";
|
|
10
|
+
import { signInCalls } from "./clerkCore3";
|
|
10
11
|
|
|
11
12
|
/** Logs a timed-out stage. Other failures are not logged here. */
|
|
12
13
|
const logTimeout = (stage: string, error: unknown) => {
|
|
@@ -329,7 +330,8 @@ export type UseSecondFactorResult = {
|
|
|
329
330
|
* `{ ok: true }` the session is active: navigate in the caller.
|
|
330
331
|
*/
|
|
331
332
|
export function useSecondFactor(options: UseSecondFactorOptions = {}): UseSecondFactorResult {
|
|
332
|
-
|
|
333
|
+
// Always defined: before Clerk loads, a call waits for it, inside the stage timeout.
|
|
334
|
+
const signIn = signInCalls(useSignIn().signIn);
|
|
333
335
|
const [chosen, setChosen] = useState<SecondFactorStrategy | null>(null);
|
|
334
336
|
const strategy = chosen ?? options.strategy ?? "totp";
|
|
335
337
|
const [loading, setLoading] = useState(false);
|
|
@@ -338,13 +340,9 @@ export function useSecondFactor(options: UseSecondFactorOptions = {}): UseSecond
|
|
|
338
340
|
|
|
339
341
|
const submit = async (code: string): Promise<TotpResult> => {
|
|
340
342
|
if (loading) return { ok: false, error };
|
|
341
|
-
if (!isLoaded || !signIn || !setActive) {
|
|
342
|
-
setError(TOTP_MESSAGES.notReady);
|
|
343
|
-
return { ok: false, error: TOTP_MESSAGES.notReady };
|
|
344
|
-
}
|
|
345
343
|
setLoading(true);
|
|
346
344
|
setError("");
|
|
347
|
-
const result = await submitSecondFactor({ signIn, setActive, code, strategy, timeoutMs });
|
|
345
|
+
const result = await submitSecondFactor({ signIn, setActive: signIn.setActive, code, strategy, timeoutMs });
|
|
348
346
|
if (!result.ok) setError(result.error);
|
|
349
347
|
setLoading(false);
|
|
350
348
|
return result;
|
|
@@ -354,10 +352,6 @@ export function useSecondFactor(options: UseSecondFactorOptions = {}): UseSecond
|
|
|
354
352
|
prepareStrategy: SecondFactorStrategy = strategy,
|
|
355
353
|
factor?: SecondFactor,
|
|
356
354
|
): Promise<TotpResult> => {
|
|
357
|
-
if (!isLoaded || !signIn) {
|
|
358
|
-
setError(TOTP_MESSAGES.notReady);
|
|
359
|
-
return { ok: false, error: TOTP_MESSAGES.notReady };
|
|
360
|
-
}
|
|
361
355
|
setLoading(true);
|
|
362
356
|
setError("");
|
|
363
357
|
const result = await prepareSecondFactorIfNeeded({ signIn, strategy: prepareStrategy, factor, timeoutMs });
|
package/src/index.ts
CHANGED
|
@@ -191,8 +191,8 @@ export type {
|
|
|
191
191
|
export type { ConfirmDialogProps } from "./ConfirmDialog";
|
|
192
192
|
export { UpdateChecker, UpdatePrompt, V_STORE_UPDATES_URL } from "./UpdateChecker";
|
|
193
193
|
export type { UpdateCheckerProps, UpdateDismissStorage, UpdatePromptProps } from "./UpdateChecker";
|
|
194
|
-
export { fetchGitHubUpdate, isNewerVersion, newerGitHubRelease } from "./updateCheck";
|
|
195
|
-
export type { AvailableUpdate, GitHubRelease, GitHubReleaseSource } from "./updateCheck";
|
|
194
|
+
export { fetchGitHubUpdate, fetchVStoreUpdate, isNewerVersion, newerGitHubRelease, V_STORE_SITE_URL } from "./updateCheck";
|
|
195
|
+
export type { AvailableUpdate, GitHubRelease, GitHubReleaseSource, VStoreSource } from "./updateCheck";
|
|
196
196
|
export {
|
|
197
197
|
Sheet,
|
|
198
198
|
SheetTrigger,
|
package/src/updateCheck.ts
CHANGED
|
@@ -101,3 +101,48 @@ export async function fetchGitHubUpdate(
|
|
|
101
101
|
if (!Array.isArray(body) || !body.every(isRelease)) return null;
|
|
102
102
|
return newerGitHubRelease(body, currentVersion, source.tagPrefix);
|
|
103
103
|
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The HTTP host of V Store, the Project V Android app store. Its
|
|
107
|
+
* `GET /latest-version?package=<Android package>` answers
|
|
108
|
+
* `{ packageName, versionName }` for an app in its catalogue.
|
|
109
|
+
*/
|
|
110
|
+
export const V_STORE_SITE_URL = "https://blessed-porcupine-303.eu-west-1.convex.site";
|
|
111
|
+
|
|
112
|
+
export type VStoreSource = {
|
|
113
|
+
/** The app's Android package, as V Store lists it. */
|
|
114
|
+
packageName: string;
|
|
115
|
+
/**
|
|
116
|
+
* What Download opens for a version: the APK, or its release page. Leave it
|
|
117
|
+
* out when the APK has no public link (a private repository). Download is
|
|
118
|
+
* then hidden, and "Install from V Store" is the one way to update.
|
|
119
|
+
*/
|
|
120
|
+
downloadUrl?: (version: string) => string;
|
|
121
|
+
/** Default `V_STORE_SITE_URL`. */
|
|
122
|
+
siteUrl?: string;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Asks V Store for the app's newest version and returns it when it is newer
|
|
127
|
+
* than `currentVersion`, else null. V Store knows the releases of private
|
|
128
|
+
* repositories too, so this works where `fetchGitHubUpdate` cannot. Null too
|
|
129
|
+
* when the app is not in the catalogue, the request fails, or the answer has
|
|
130
|
+
* another shape. A network error rejects. Without `downloadUrl`, `url` is
|
|
131
|
+
* `fallbackUrl`.
|
|
132
|
+
*/
|
|
133
|
+
export async function fetchVStoreUpdate(
|
|
134
|
+
source: VStoreSource,
|
|
135
|
+
currentVersion: string,
|
|
136
|
+
fallbackUrl: string,
|
|
137
|
+
): Promise<AvailableUpdate | null> {
|
|
138
|
+
const site = source.siteUrl ?? V_STORE_SITE_URL;
|
|
139
|
+
const response = await fetch(`${site}/latest-version?package=${encodeURIComponent(source.packageName)}`, {
|
|
140
|
+
headers: { Accept: "application/json" },
|
|
141
|
+
});
|
|
142
|
+
if (!response.ok) return null;
|
|
143
|
+
const body: unknown = await response.json();
|
|
144
|
+
if (!body || typeof body !== "object") return null;
|
|
145
|
+
const version = (body as Record<string, unknown>).versionName;
|
|
146
|
+
if (typeof version !== "string" || !isNewerVersion(version, currentVersion)) return null;
|
|
147
|
+
return { version, url: source.downloadUrl?.(version) ?? fallbackUrl };
|
|
148
|
+
}
|