@vvedantb/native-ui 0.30.0 → 0.32.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.
@@ -0,0 +1,450 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { useRef, useState } from "react";
3
+ import { useUser } from "@clerk/expo";
4
+ import { useRouter } from "expo-router";
5
+ import { Button } from "../Button";
6
+ import { Input } from "../Input";
7
+ import { PasswordInput } from "../PasswordInput";
8
+ import { AuthScreen, FieldError } from "./AuthScreen";
9
+ import { authErrorMessage, DEFAULT_STAGE_TIMEOUT_MS, logAuthFailure, withAuthTimeout } from "./authErrors";
10
+
11
+ /** The messages the account screens can show. Generic: none names a provider. */
12
+ export const ACCOUNT_MESSAGES = {
13
+ changePasswordTitle: "Change password",
14
+ changePasswordSubtitle: "Enter your current password, then a new one.",
15
+ setPasswordTitle: "Set a password",
16
+ setPasswordSubtitle: "Your account has no password yet. Choose one.",
17
+ currentPasswordLabel: "Current password",
18
+ newPasswordLabel: "New password",
19
+ confirmPasswordLabel: "Confirm new password",
20
+ missingCurrentPassword: "Enter your current password",
21
+ missingNewPassword: "Enter a new password",
22
+ passwordMismatch: "The passwords do not match",
23
+ changePasswordFailed: "Could not change the password",
24
+ changePassword: "Change password",
25
+ setPassword: "Set password",
26
+ deleteTitle: "Delete account",
27
+ deleteSubtitle: "This deletes your account and its data. It cannot be undone.",
28
+ deleteConfirmMismatch: "Type the word exactly to confirm",
29
+ deleteFailed: "Could not delete the account",
30
+ deleteAccount: "Delete account",
31
+ cancel: "Cancel",
32
+ notReady: "Your account is not ready yet. Try again in a moment."
33
+ };
34
+ /**
35
+ * Changes the signed-in user's password with `user.updatePassword`: the
36
+ * current password, then the new one typed twice. An account with no password
37
+ * (Google only) gets no current-password field and the "Set a password" copy.
38
+ * Errors show under the fields. Render it under `ClerkProvider`, signed in.
39
+ */
40
+ export function ChangePasswordScreen(t0) {
41
+ const $ = _c(55);
42
+ const {
43
+ title,
44
+ subtitle,
45
+ header,
46
+ footer,
47
+ onCancel,
48
+ stageTimeoutMs: t1,
49
+ minPasswordLength,
50
+ signOutOfOtherSessions: t2,
51
+ onSuccess,
52
+ testIDPrefix: t3
53
+ } = t0;
54
+ const stageTimeoutMs = t1 === undefined ? DEFAULT_STAGE_TIMEOUT_MS : t1;
55
+ const signOutOfOtherSessions = t2 === undefined ? true : t2;
56
+ const testIDPrefix = t3 === undefined ? "change-password" : t3;
57
+ const {
58
+ isLoaded,
59
+ user
60
+ } = useUser();
61
+ const router = useRouter();
62
+ const [current, setCurrent] = useState("");
63
+ const [next, setNext] = useState("");
64
+ const [confirm, setConfirm] = useState("");
65
+ const [error, setError] = useState("");
66
+ const [submitting, setSubmitting] = useState(false);
67
+ const nextField = useRef(null);
68
+ const confirmField = useRef(null);
69
+ let t4;
70
+ if ($[0] !== testIDPrefix) {
71
+ t4 = name => `${testIDPrefix}-${name}`;
72
+ $[0] = testIDPrefix;
73
+ $[1] = t4;
74
+ } else {
75
+ t4 = $[1];
76
+ }
77
+ const id = t4;
78
+ const hasPassword = user ? user.passwordEnabled : true;
79
+ let t5;
80
+ if ($[2] !== confirm || $[3] !== current || $[4] !== hasPassword || $[5] !== isLoaded || $[6] !== minPasswordLength || $[7] !== next || $[8] !== onSuccess || $[9] !== router || $[10] !== signOutOfOtherSessions || $[11] !== stageTimeoutMs || $[12] !== submitting || $[13] !== user) {
81
+ t5 = async () => {
82
+ if (submitting) {
83
+ return;
84
+ }
85
+ if (!isLoaded || !user) {
86
+ return setError(ACCOUNT_MESSAGES.notReady);
87
+ }
88
+ if (hasPassword && !current) {
89
+ return setError(ACCOUNT_MESSAGES.missingCurrentPassword);
90
+ }
91
+ if (!next) {
92
+ return setError(ACCOUNT_MESSAGES.missingNewPassword);
93
+ }
94
+ if (minPasswordLength && next.length < minPasswordLength) {
95
+ return setError(`Use at least ${minPasswordLength} characters for the password`);
96
+ }
97
+ if (next !== confirm) {
98
+ return setError(ACCOUNT_MESSAGES.passwordMismatch);
99
+ }
100
+ setSubmitting(true);
101
+ setError("");
102
+ const params = hasPassword ? {
103
+ newPassword: next,
104
+ signOutOfOtherSessions,
105
+ currentPassword: current
106
+ } : {
107
+ newPassword: next,
108
+ signOutOfOtherSessions
109
+ };
110
+ let failed = false;
111
+ let failure;
112
+ ;
113
+ try {
114
+ await withAuthTimeout(user.updatePassword(params), "update-password", stageTimeoutMs);
115
+ } catch (t6) {
116
+ const caught = t6;
117
+ failed = true;
118
+ failure = caught;
119
+ }
120
+ setSubmitting(false);
121
+ if (failed) {
122
+ logAuthFailure("update-password", failure);
123
+ return setError(authErrorMessage(failure, ACCOUNT_MESSAGES.changePasswordFailed));
124
+ }
125
+ setCurrent("");
126
+ setNext("");
127
+ setConfirm("");
128
+ if (onSuccess) {
129
+ onSuccess();
130
+ } else {
131
+ router.back();
132
+ }
133
+ };
134
+ $[2] = confirm;
135
+ $[3] = current;
136
+ $[4] = hasPassword;
137
+ $[5] = isLoaded;
138
+ $[6] = minPasswordLength;
139
+ $[7] = next;
140
+ $[8] = onSuccess;
141
+ $[9] = router;
142
+ $[10] = signOutOfOtherSessions;
143
+ $[11] = stageTimeoutMs;
144
+ $[12] = submitting;
145
+ $[13] = user;
146
+ $[14] = t5;
147
+ } else {
148
+ t5 = $[14];
149
+ }
150
+ const submit = t5;
151
+ const t6 = id("screen");
152
+ const t7 = title ?? (hasPassword ? ACCOUNT_MESSAGES.changePasswordTitle : ACCOUNT_MESSAGES.setPasswordTitle);
153
+ const t8 = subtitle ?? (hasPassword ? ACCOUNT_MESSAGES.changePasswordSubtitle : ACCOUNT_MESSAGES.setPasswordSubtitle);
154
+ let t9;
155
+ if ($[15] !== current || $[16] !== hasPassword || $[17] !== id) {
156
+ t9 = hasPassword ? <PasswordInput testID={id("current")} accessibilityLabel={ACCOUNT_MESSAGES.currentPasswordLabel} autoCapitalize="none" autoComplete="password" textContentType="password" returnKeyType="next" submitBehavior="submit" onSubmitEditing={() => nextField.current?.focus()} value={current} placeholder={ACCOUNT_MESSAGES.currentPasswordLabel} onChangeText={setCurrent} /> : null;
157
+ $[15] = current;
158
+ $[16] = hasPassword;
159
+ $[17] = id;
160
+ $[18] = t9;
161
+ } else {
162
+ t9 = $[18];
163
+ }
164
+ const t10 = id("new");
165
+ let t11;
166
+ if ($[19] === Symbol.for("react.memo_cache_sentinel")) {
167
+ t11 = () => confirmField.current?.focus();
168
+ $[19] = t11;
169
+ } else {
170
+ t11 = $[19];
171
+ }
172
+ let t12;
173
+ if ($[20] !== next || $[21] !== t10) {
174
+ t12 = <PasswordInput testID={t10} ref={nextField} accessibilityLabel={ACCOUNT_MESSAGES.newPasswordLabel} autoCapitalize="none" autoComplete="new-password" textContentType="newPassword" returnKeyType="next" submitBehavior="submit" onSubmitEditing={t11} value={next} placeholder={ACCOUNT_MESSAGES.newPasswordLabel} onChangeText={setNext} />;
175
+ $[20] = next;
176
+ $[21] = t10;
177
+ $[22] = t12;
178
+ } else {
179
+ t12 = $[22];
180
+ }
181
+ const t13 = id("confirm");
182
+ let t14;
183
+ if ($[23] !== submit) {
184
+ t14 = () => void submit();
185
+ $[23] = submit;
186
+ $[24] = t14;
187
+ } else {
188
+ t14 = $[24];
189
+ }
190
+ let t15;
191
+ if ($[25] !== confirm || $[26] !== t13 || $[27] !== t14) {
192
+ t15 = <PasswordInput testID={t13} ref={confirmField} accessibilityLabel={ACCOUNT_MESSAGES.confirmPasswordLabel} autoCapitalize="none" autoComplete="new-password" textContentType="newPassword" returnKeyType="go" value={confirm} placeholder={ACCOUNT_MESSAGES.confirmPasswordLabel} onChangeText={setConfirm} onSubmitEditing={t14} />;
193
+ $[25] = confirm;
194
+ $[26] = t13;
195
+ $[27] = t14;
196
+ $[28] = t15;
197
+ } else {
198
+ t15 = $[28];
199
+ }
200
+ const t16 = id("error");
201
+ let t17;
202
+ if ($[29] !== error || $[30] !== t16) {
203
+ t17 = <FieldError testID={t16} message={error} />;
204
+ $[29] = error;
205
+ $[30] = t16;
206
+ $[31] = t17;
207
+ } else {
208
+ t17 = $[31];
209
+ }
210
+ const t18 = id("submit");
211
+ let t19;
212
+ if ($[32] !== submit) {
213
+ t19 = () => void submit();
214
+ $[32] = submit;
215
+ $[33] = t19;
216
+ } else {
217
+ t19 = $[33];
218
+ }
219
+ const t20 = hasPassword ? ACCOUNT_MESSAGES.changePassword : ACCOUNT_MESSAGES.setPassword;
220
+ let t21;
221
+ if ($[34] !== submitting || $[35] !== t18 || $[36] !== t19 || $[37] !== t20) {
222
+ t21 = <Button testID={t18} loading={submitting} onPress={t19}>{t20}</Button>;
223
+ $[34] = submitting;
224
+ $[35] = t18;
225
+ $[36] = t19;
226
+ $[37] = t20;
227
+ $[38] = t21;
228
+ } else {
229
+ t21 = $[38];
230
+ }
231
+ let t22;
232
+ if ($[39] !== id || $[40] !== onCancel || $[41] !== submitting) {
233
+ t22 = onCancel ? <Button testID={id("cancel")} variant="ghost" disabled={submitting} onPress={onCancel}>{ACCOUNT_MESSAGES.cancel}</Button> : null;
234
+ $[39] = id;
235
+ $[40] = onCancel;
236
+ $[41] = submitting;
237
+ $[42] = t22;
238
+ } else {
239
+ t22 = $[42];
240
+ }
241
+ let t23;
242
+ if ($[43] !== footer || $[44] !== header || $[45] !== t12 || $[46] !== t15 || $[47] !== t17 || $[48] !== t21 || $[49] !== t22 || $[50] !== t6 || $[51] !== t7 || $[52] !== t8 || $[53] !== t9) {
243
+ t23 = <AuthScreen testID={t6} title={t7} subtitle={t8} header={header} footer={footer}>{t9}{t12}{t15}{t17}{t21}{t22}</AuthScreen>;
244
+ $[43] = footer;
245
+ $[44] = header;
246
+ $[45] = t12;
247
+ $[46] = t15;
248
+ $[47] = t17;
249
+ $[48] = t21;
250
+ $[49] = t22;
251
+ $[50] = t6;
252
+ $[51] = t7;
253
+ $[52] = t8;
254
+ $[53] = t9;
255
+ $[54] = t23;
256
+ } else {
257
+ t23 = $[54];
258
+ }
259
+ return t23;
260
+ }
261
+ /**
262
+ * Deletes the signed-in user's account with `user.delete()`. The user types
263
+ * `confirmWord` first; the delete button stays off until it matches. Needs
264
+ * "Allow users to delete their accounts" turned on for the instance. Errors
265
+ * show under the field. Render it under `ClerkProvider`, signed in.
266
+ */
267
+ export function DeleteAccountScreen(t0) {
268
+ const $ = _c(44);
269
+ const {
270
+ title,
271
+ subtitle,
272
+ header,
273
+ footer,
274
+ onCancel,
275
+ stageTimeoutMs: t1,
276
+ confirmWord: t2,
277
+ onDeleted,
278
+ afterDeleteHref: t3,
279
+ testIDPrefix: t4
280
+ } = t0;
281
+ const stageTimeoutMs = t1 === undefined ? DEFAULT_STAGE_TIMEOUT_MS : t1;
282
+ const confirmWord = t2 === undefined ? "DELETE" : t2;
283
+ const afterDeleteHref = t3 === undefined ? "/" : t3;
284
+ const testIDPrefix = t4 === undefined ? "delete-account" : t4;
285
+ const {
286
+ isLoaded,
287
+ user
288
+ } = useUser();
289
+ const router = useRouter();
290
+ const [typed, setTyped] = useState("");
291
+ const [error, setError] = useState("");
292
+ const [submitting, setSubmitting] = useState(false);
293
+ let t5;
294
+ if ($[0] !== testIDPrefix) {
295
+ t5 = name => `${testIDPrefix}-${name}`;
296
+ $[0] = testIDPrefix;
297
+ $[1] = t5;
298
+ } else {
299
+ t5 = $[1];
300
+ }
301
+ const id = t5;
302
+ let t6;
303
+ if ($[2] !== typed) {
304
+ t6 = typed.trim().toLowerCase();
305
+ $[2] = typed;
306
+ $[3] = t6;
307
+ } else {
308
+ t6 = $[3];
309
+ }
310
+ let t7;
311
+ if ($[4] !== confirmWord) {
312
+ t7 = confirmWord.toLowerCase();
313
+ $[4] = confirmWord;
314
+ $[5] = t7;
315
+ } else {
316
+ t7 = $[5];
317
+ }
318
+ const matches = t6 === t7;
319
+ let t8;
320
+ if ($[6] !== afterDeleteHref || $[7] !== isLoaded || $[8] !== matches || $[9] !== onDeleted || $[10] !== router || $[11] !== stageTimeoutMs || $[12] !== submitting || $[13] !== user) {
321
+ t8 = async () => {
322
+ if (submitting) {
323
+ return;
324
+ }
325
+ if (!matches) {
326
+ return setError(ACCOUNT_MESSAGES.deleteConfirmMismatch);
327
+ }
328
+ if (!isLoaded || !user) {
329
+ return setError(ACCOUNT_MESSAGES.notReady);
330
+ }
331
+ setSubmitting(true);
332
+ setError("");
333
+ let failed = false;
334
+ let failure;
335
+ ;
336
+ try {
337
+ await withAuthTimeout(user.delete(), "delete-account", stageTimeoutMs);
338
+ } catch (t9) {
339
+ const caught = t9;
340
+ failed = true;
341
+ failure = caught;
342
+ }
343
+ setSubmitting(false);
344
+ if (failed) {
345
+ logAuthFailure("delete-account", failure);
346
+ return setError(authErrorMessage(failure, ACCOUNT_MESSAGES.deleteFailed));
347
+ }
348
+ if (onDeleted) {
349
+ onDeleted();
350
+ } else {
351
+ router.replace(afterDeleteHref);
352
+ }
353
+ };
354
+ $[6] = afterDeleteHref;
355
+ $[7] = isLoaded;
356
+ $[8] = matches;
357
+ $[9] = onDeleted;
358
+ $[10] = router;
359
+ $[11] = stageTimeoutMs;
360
+ $[12] = submitting;
361
+ $[13] = user;
362
+ $[14] = t8;
363
+ } else {
364
+ t8 = $[14];
365
+ }
366
+ const submit = t8;
367
+ const label = `Type ${confirmWord} to confirm`;
368
+ const t9 = id("screen");
369
+ const t10 = title ?? ACCOUNT_MESSAGES.deleteTitle;
370
+ const t11 = subtitle ?? ACCOUNT_MESSAGES.deleteSubtitle;
371
+ const t12 = id("confirm");
372
+ let t13;
373
+ if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
374
+ t13 = text => {
375
+ setTyped(text);
376
+ setError("");
377
+ };
378
+ $[15] = t13;
379
+ } else {
380
+ t13 = $[15];
381
+ }
382
+ let t14;
383
+ if ($[16] !== label || $[17] !== t12 || $[18] !== typed) {
384
+ t14 = <Input testID={t12} accessibilityLabel={label} autoCapitalize="characters" autoCorrect={false} returnKeyType="done" value={typed} placeholder={label} onChangeText={t13} />;
385
+ $[16] = label;
386
+ $[17] = t12;
387
+ $[18] = typed;
388
+ $[19] = t14;
389
+ } else {
390
+ t14 = $[19];
391
+ }
392
+ const t15 = id("error");
393
+ let t16;
394
+ if ($[20] !== error || $[21] !== t15) {
395
+ t16 = <FieldError testID={t15} message={error} />;
396
+ $[20] = error;
397
+ $[21] = t15;
398
+ $[22] = t16;
399
+ } else {
400
+ t16 = $[22];
401
+ }
402
+ const t17 = id("submit");
403
+ const t18 = !matches;
404
+ let t19;
405
+ if ($[23] !== submit) {
406
+ t19 = () => void submit();
407
+ $[23] = submit;
408
+ $[24] = t19;
409
+ } else {
410
+ t19 = $[24];
411
+ }
412
+ let t20;
413
+ if ($[25] !== submitting || $[26] !== t17 || $[27] !== t18 || $[28] !== t19) {
414
+ t20 = <Button testID={t17} variant="destructive" loading={submitting} disabled={t18} onPress={t19}>{ACCOUNT_MESSAGES.deleteAccount}</Button>;
415
+ $[25] = submitting;
416
+ $[26] = t17;
417
+ $[27] = t18;
418
+ $[28] = t19;
419
+ $[29] = t20;
420
+ } else {
421
+ t20 = $[29];
422
+ }
423
+ let t21;
424
+ if ($[30] !== id || $[31] !== onCancel || $[32] !== submitting) {
425
+ t21 = onCancel ? <Button testID={id("cancel")} variant="ghost" disabled={submitting} onPress={onCancel}>{ACCOUNT_MESSAGES.cancel}</Button> : null;
426
+ $[30] = id;
427
+ $[31] = onCancel;
428
+ $[32] = submitting;
429
+ $[33] = t21;
430
+ } else {
431
+ t21 = $[33];
432
+ }
433
+ let t22;
434
+ if ($[34] !== footer || $[35] !== header || $[36] !== t10 || $[37] !== t11 || $[38] !== t14 || $[39] !== t16 || $[40] !== t20 || $[41] !== t21 || $[42] !== t9) {
435
+ t22 = <AuthScreen testID={t9} title={t10} subtitle={t11} header={header} footer={footer}>{t14}{t16}{t20}{t21}</AuthScreen>;
436
+ $[34] = footer;
437
+ $[35] = header;
438
+ $[36] = t10;
439
+ $[37] = t11;
440
+ $[38] = t14;
441
+ $[39] = t16;
442
+ $[40] = t20;
443
+ $[41] = t21;
444
+ $[42] = t9;
445
+ $[43] = t22;
446
+ } else {
447
+ t22 = $[43];
448
+ }
449
+ return t22;
450
+ }
@@ -1,4 +1,4 @@
1
- import { ClerkLoaded, ClerkProvider, useAuth as useClerkAuth } from "@clerk/clerk-expo";
1
+ import { ClerkLoaded, ClerkProvider, useAuth as useClerkAuth } from "@clerk/expo";
2
2
  import { ConvexProvider } from "convex/react";
3
3
  import { ConvexProviderWithClerk } from "convex/react-clerk";
4
4
  /**
@@ -19,7 +19,7 @@ export function AuthProviders({
19
19
  return convex ? <ConvexProvider client={convex}>{children}</ConvexProvider> : <>{children}</>;
20
20
  }
21
21
  const inner = loaded ? <ClerkLoaded>{children}</ClerkLoaded> : children;
22
- return <ClerkProvider publishableKey={publishableKey} tokenCache={tokenCache}>
22
+ return <ClerkProvider publishableKey={publishableKey ?? ""} tokenCache={tokenCache}>
23
23
  {convex ? <ConvexProviderWithClerk client={convex} useAuth={useAuth}>
24
24
  {inner}
25
25
  </ConvexProviderWithClerk> : inner}
@@ -1,7 +1,7 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import { useEffect, useState } from "react";
3
3
  import { Platform } from "react-native";
4
- import { useSSO } from "@clerk/clerk-expo";
4
+ import { useSSO } from "@clerk/expo";
5
5
  import * as AuthSession from "expo-auth-session";
6
6
  import * as WebBrowser from "expo-web-browser";
7
7
  import { useRouter } from "expo-router";
@@ -1,7 +1,7 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import { useRef, useState } from "react";
3
3
  import { Text, View } from "react-native";
4
- import { useSignIn, useSignUp } from "@clerk/clerk-expo";
4
+ import { useSignIn, useSignUp } from "@clerk/expo/legacy";
5
5
  import { useRouter } from "expo-router";
6
6
  import { Button } from "../Button";
7
7
  import { textStyle } from "../controlStyles";
@@ -1,4 +1,4 @@
1
- import { isClerkAPIResponseError } from "@clerk/clerk-expo";
1
+ import { isClerkAPIResponseError } from "@clerk/expo";
2
2
 
3
3
  /** Words that must not reach the user: the auth provider and stack names. */
4
4
  const PRODUCT_NAMES = /\b(clerk|convex)\b/gi;
@@ -1,5 +1,5 @@
1
1
  // Clerk + Convex providers and the shared sign-in and sign-up screens. On
2
- // `@vvedantb/native-ui/auth` only: they import `@clerk/clerk-expo`, `convex`,
2
+ // `@vvedantb/native-ui/auth` only: they import `@clerk/expo`, `convex`,
3
3
  // `expo-auth-session`, `expo-web-browser` and `expo-router`, and Metro does not
4
4
  // tree-shake.
5
5
  export { AuthProviders } from "./AuthProviders";
@@ -7,5 +7,6 @@ export { AuthScreen, OrDivider, FieldError } from "./AuthScreen";
7
7
  export { authErrorMessage, logAuthFailure, withAuthTimeout, AuthTimeoutError, isAuthTimeoutError, AUTH_TIMEOUT_CODE, DEFAULT_STAGE_TIMEOUT_MS, CREDENTIAL_ERROR_CODES } from "./authErrors";
8
8
  export { GoogleSignInButton, useGoogleSignIn, useWarmUpBrowser, GOOGLE_ERROR_MESSAGE } from "./GoogleSignInButton";
9
9
  export { SignInScreen, SignUpScreen, ResetPasswordScreen, AUTH_MESSAGES } from "./SignInScreen";
10
+ export { ChangePasswordScreen, DeleteAccountScreen, ACCOUNT_MESSAGES } from "./AccountScreens";
10
11
  export { SecondFactorScreen } from "./SecondFactorScreen";
11
12
  export { submitTotpSecondFactor, submitSecondFactor, prepareSecondFactorIfNeeded, prepareFirstFactorIfNeeded, submitFirstFactor, pickFirstFactorStrategy, supportedFirstFactorStrategies, FIRST_FACTOR_PREFERENCE, pickSecondFactorStrategy, supportedSecondFactorStrategies, SECOND_FACTOR_PREFERENCE, useSecondFactor, TOTP_MESSAGES } from "./totp";
package/dist/auth/totp.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import { useState } from "react";
3
- import { useSignIn } from "@clerk/clerk-expo";
3
+ import { useSignIn } from "@clerk/expo/legacy";
4
4
  import { authErrorMessage, DEFAULT_STAGE_TIMEOUT_MS, isAuthTimeoutError, logAuthFailure, withAuthTimeout } from "./authErrors";
5
5
 
6
6
  /** Logs a timed-out stage. Other failures are not logged here. */
@@ -1,5 +1,5 @@
1
1
  // `@vvedantb/native-ui/auth`: `AuthProviders`, `SignInScreen`, `SignUpScreen`,
2
2
  // `GoogleSignInButton` and the auth frame. Not on the root entry: it imports
3
- // `@clerk/clerk-expo`, `convex`, `expo-auth-session`, `expo-web-browser` and
3
+ // `@clerk/expo`, `convex`, `expo-auth-session`, `expo-web-browser` and
4
4
  // `expo-router`, and Metro does not tree-shake.
5
5
  export * from "../auth";
@@ -55,6 +55,8 @@ export { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader,
55
55
  export { ConfirmDialog } from "../ConfirmDialog";
56
56
  export { BulkActionBar, BULK_BAR_LABEL_MIN_WIDTH } from "../BulkActionBar";
57
57
  export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuItem, DropdownMenuRadioItem, DropdownMenuSeparator } from "../DropdownMenu";
58
+ export { UpdateChecker, UpdatePrompt, V_STORE_UPDATES_URL } from "../UpdateChecker";
59
+ export { fetchGitHubUpdate, isNewerVersion, newerGitHubRelease } from "../updateCheck";
58
60
  export { Sheet, SheetTrigger, SheetClose, SheetContent, SheetHandle, SheetHeader, SheetTitle, SheetDescription, SheetBody, SheetFooter } from "../Sheet";
59
61
  export { Toaster } from "../Toast";
60
62
  export { toast } from "../toastStore";
package/dist/index.js CHANGED
@@ -63,6 +63,8 @@ export { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader,
63
63
  export { ConfirmDialog } from "./ConfirmDialog";
64
64
  export { BulkActionBar, BULK_BAR_LABEL_MIN_WIDTH } from "./BulkActionBar";
65
65
  export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuItem, DropdownMenuRadioItem, DropdownMenuSeparator } from "./DropdownMenu";
66
+ export { UpdateChecker, UpdatePrompt, V_STORE_UPDATES_URL } from "./UpdateChecker";
67
+ export { fetchGitHubUpdate, isNewerVersion, newerGitHubRelease } from "./updateCheck";
66
68
  export { Sheet, SheetTrigger, SheetClose, SheetContent, SheetHandle, SheetHeader, SheetTitle, SheetDescription, SheetBody, SheetFooter } from "./Sheet";
67
69
  export { Toaster } from "./Toast";
68
70
  export { toast } from "./toastStore";
@@ -0,0 +1,79 @@
1
+ // The update check behind `UpdateChecker`: for an app that ships its Android
2
+ // APK as GitHub releases tagged `<tagPrefix><version>`, with no store and no
3
+ // over-the-air updates. Plain functions, no React and no native module.
4
+
5
+ /** A newer version to offer. `url` is what Download opens: the APK itself, else its release page. */
6
+
7
+ /** The fields of a GitHub release the check reads (`GET /repos/{owner}/{repo}/releases`). */
8
+
9
+ /** `[major, minor, patch]` of "1.2.3", or null. */
10
+ function parseVersion(version) {
11
+ const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
12
+ return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
13
+ }
14
+
15
+ /** Positive when `a` is newer than `b`. */
16
+ function compareParts(a, b) {
17
+ return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
18
+ }
19
+
20
+ /** True when `candidate` ("1.2.3") is newer than `current`. False when either is not `major.minor.patch`. */
21
+ export function isNewerVersion(candidate, current) {
22
+ const a = parseVersion(candidate);
23
+ const b = parseVersion(current);
24
+ return a !== null && b !== null && compareParts(a, b) > 0;
25
+ }
26
+ function isRelease(value) {
27
+ if (!value || typeof value !== "object") return false;
28
+ const release = value;
29
+ return typeof release.tag_name === "string" && typeof release.html_url === "string" && typeof release.draft === "boolean" && typeof release.prerelease === "boolean" && Array.isArray(release.assets) && release.assets.every(asset => {
30
+ if (!asset || typeof asset !== "object") return false;
31
+ const item = asset;
32
+ return typeof item.name === "string" && typeof item.browser_download_url === "string";
33
+ });
34
+ }
35
+
36
+ /**
37
+ * The newest published release tagged `<tagPrefix><version>` that is newer
38
+ * than `currentVersion`, or null. Drafts, prereleases, other tags and versions
39
+ * that are not `major.minor.patch` are skipped. The download is the release's
40
+ * first `.apk` asset, else its release page.
41
+ */
42
+ export function newerGitHubRelease(releases, currentVersion, tagPrefix) {
43
+ const installed = parseVersion(currentVersion);
44
+ if (!installed) return null;
45
+ let best = null;
46
+ for (const release of releases) {
47
+ if (release.draft || release.prerelease || !release.tag_name.startsWith(tagPrefix)) continue;
48
+ const version = release.tag_name.slice(tagPrefix.length);
49
+ const parts = parseVersion(version);
50
+ if (!parts || compareParts(parts, installed) <= 0) continue;
51
+ if (best && compareParts(parts, best.parts) <= 0) continue;
52
+ const apk = release.assets.find(asset => asset.name.endsWith(".apk"));
53
+ best = {
54
+ parts,
55
+ update: {
56
+ version,
57
+ url: apk?.browser_download_url ?? release.html_url
58
+ }
59
+ };
60
+ }
61
+ return best?.update ?? null;
62
+ }
63
+
64
+ /**
65
+ * Reads the repository's 30 latest releases from the public GitHub API and
66
+ * returns the newer one, or null. Null too when the request fails, is rate
67
+ * limited, or the answer has another shape. A network error rejects.
68
+ */
69
+ export async function fetchGitHubUpdate(source, currentVersion) {
70
+ const response = await fetch(`https://api.github.com/repos/${source.repo}/releases?per_page=30`, {
71
+ headers: {
72
+ Accept: "application/vnd.github+json"
73
+ }
74
+ });
75
+ if (!response.ok) return null;
76
+ const body = await response.json();
77
+ if (!Array.isArray(body) || !body.every(isRelease)) return null;
78
+ return newerGitHubRelease(body, currentVersion, source.tagPrefix);
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/native-ui",
3
- "version": "0.30.0",
3
+ "version": "0.32.0",
4
4
  "license": "MIT",
5
5
  "description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root and Clerk + Convex auth screens.",
6
6
  "type": "module",
@@ -190,7 +190,7 @@
190
190
  "sideEffects": false,
191
191
  "peerDependencies": {
192
192
  "expo-paste-input": ">=0.2.0",
193
- "@clerk/clerk-expo": "*",
193
+ "@clerk/expo": ">=4.0.0",
194
194
  "@expo/vector-icons": "*",
195
195
  "@json-render/core": ">=0.21.0",
196
196
  "@json-render/react-native": ">=0.21.0",
@@ -234,7 +234,7 @@
234
234
  "expo-paste-input": {
235
235
  "optional": true
236
236
  },
237
- "@clerk/clerk-expo": {
237
+ "@clerk/expo": {
238
238
  "optional": true
239
239
  },
240
240
  "@swmansion/react-native-bottom-sheet": {
@@ -308,7 +308,7 @@
308
308
  }
309
309
  },
310
310
  "devDependencies": {
311
- "@clerk/clerk-expo": "2.20.2",
311
+ "@clerk/expo": "4.17.2",
312
312
  "@types/react": "^19.1.0",
313
313
  "react": "^19.1.0",
314
314
  "typescript": "^5.9.0",