@dloizides/auth-web 1.5.0 → 1.6.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/index.js CHANGED
@@ -1,12 +1,118 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
4
3
  var reactNative = require('react-native');
4
+ var react = require('react');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var reactQuery = require('@tanstack/react-query');
7
7
  var authClient = require('@dloizides/auth-client');
8
8
 
9
- // src/components/LoginForm.tsx
9
+ // src/components/AuthScreen.tsx
10
+ var FULL_WIDTH = "100%";
11
+ var CARD_BORDER_WIDTH = 1;
12
+ function useAuthScreenStyles(theme) {
13
+ return react.useMemo(() => {
14
+ const { colors, radii, spacing, typography } = theme;
15
+ return reactNative.StyleSheet.create({
16
+ screen: {
17
+ flex: 1,
18
+ justifyContent: "center",
19
+ alignItems: "center",
20
+ padding: spacing.md,
21
+ backgroundColor: colors.background
22
+ },
23
+ card: {
24
+ width: FULL_WIDTH,
25
+ borderRadius: radii.card,
26
+ borderWidth: CARD_BORDER_WIDTH,
27
+ borderColor: colors.border,
28
+ padding: spacing.xl,
29
+ backgroundColor: colors.surface
30
+ },
31
+ title: {
32
+ fontSize: typography.title,
33
+ fontWeight: "bold",
34
+ marginBottom: spacing.xs,
35
+ color: colors.text
36
+ },
37
+ subtitle: {
38
+ fontSize: typography.subtitle,
39
+ marginBottom: spacing.lg,
40
+ color: colors.textSecondary
41
+ },
42
+ footer: {
43
+ marginTop: spacing.lg,
44
+ width: FULL_WIDTH,
45
+ alignItems: "center"
46
+ }
47
+ });
48
+ }, [theme]);
49
+ }
50
+
51
+ // src/theme/AuthTheme.ts
52
+ var defaultAuthTheme = {
53
+ colors: {
54
+ background: "#f5f5f7",
55
+ surface: "#ffffff",
56
+ text: "#1a1a1a",
57
+ textSecondary: "#6b6b6b",
58
+ border: "#d0d0d5",
59
+ primary: "#2563eb",
60
+ onPrimary: "#ffffff",
61
+ danger: "#d33333",
62
+ success: "#1f7a3d"
63
+ },
64
+ radii: {
65
+ input: 8,
66
+ card: 12
67
+ },
68
+ spacing: {
69
+ xs: 8,
70
+ sm: 12,
71
+ md: 20,
72
+ lg: 32,
73
+ xl: 24
74
+ },
75
+ typography: {
76
+ title: 28,
77
+ subtitle: 16,
78
+ label: 14,
79
+ body: 16,
80
+ caption: 12
81
+ }
82
+ };
83
+ var AuthThemeContext = react.createContext(defaultAuthTheme);
84
+ function AuthThemeProvider({
85
+ theme,
86
+ children
87
+ }) {
88
+ return /* @__PURE__ */ jsxRuntime.jsx(AuthThemeContext.Provider, { value: theme, children });
89
+ }
90
+ function useAuthTheme(themeProp) {
91
+ const contextTheme = react.useContext(AuthThemeContext);
92
+ return react.useMemo(() => themeProp ?? contextTheme, [themeProp, contextTheme]);
93
+ }
94
+ var DEFAULT_AUTH_CARD_MAX_WIDTH = 420;
95
+ function AuthScreen({
96
+ children,
97
+ theme: themeProp,
98
+ testID,
99
+ cardTestID,
100
+ maxWidth = DEFAULT_AUTH_CARD_MAX_WIDTH,
101
+ title,
102
+ subtitle,
103
+ footer
104
+ }) {
105
+ const theme = useAuthTheme(themeProp);
106
+ const styles3 = useAuthScreenStyles(theme);
107
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles3.screen, testID, children: [
108
+ /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [styles3.card, { maxWidth }], testID: cardTestID, children: [
109
+ title !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles3.title, children: title }) : null,
110
+ subtitle !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles3.subtitle, children: subtitle }) : null,
111
+ children
112
+ ] }),
113
+ footer !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles3.footer, { maxWidth }], children: footer }) : null
114
+ ] });
115
+ }
10
116
 
11
117
  // src/components/labels.ts
12
118
  var DEFAULT_LOGIN_LABELS = {
@@ -247,7 +353,7 @@ var AuthTestIds = {
247
353
  function withTestIdPrefix(baseId, prefix) {
248
354
  return prefix === void 0 || prefix === "" ? baseId : `${prefix}-${baseId}`;
249
355
  }
250
- var FULL_WIDTH = "100%";
356
+ var FULL_WIDTH2 = "100%";
251
357
  var CARD_MAX_WIDTH = 420;
252
358
  var BUTTON_VERTICAL_PADDING = 14;
253
359
  function useAuthStyles(theme) {
@@ -262,7 +368,7 @@ function useAuthStyles(theme) {
262
368
  backgroundColor: colors.background
263
369
  },
264
370
  card: {
265
- width: FULL_WIDTH,
371
+ width: FULL_WIDTH2,
266
372
  maxWidth: CARD_MAX_WIDTH,
267
373
  borderRadius: radii.card,
268
374
  padding: spacing.xl,
@@ -469,50 +575,6 @@ function useBffAuth(options) {
469
575
  [session.user, session.status, isSubmitting, error, login, logout, refresh]
470
576
  );
471
577
  }
472
-
473
- // src/theme/AuthTheme.ts
474
- var defaultAuthTheme = {
475
- colors: {
476
- background: "#f5f5f7",
477
- surface: "#ffffff",
478
- text: "#1a1a1a",
479
- textSecondary: "#6b6b6b",
480
- border: "#d0d0d5",
481
- primary: "#2563eb",
482
- onPrimary: "#ffffff",
483
- danger: "#d33333",
484
- success: "#1f7a3d"
485
- },
486
- radii: {
487
- input: 8,
488
- card: 12
489
- },
490
- spacing: {
491
- xs: 8,
492
- sm: 12,
493
- md: 20,
494
- lg: 32,
495
- xl: 24
496
- },
497
- typography: {
498
- title: 28,
499
- subtitle: 16,
500
- label: 14,
501
- body: 16,
502
- caption: 12
503
- }
504
- };
505
- var AuthThemeContext = react.createContext(defaultAuthTheme);
506
- function AuthThemeProvider({
507
- theme,
508
- children
509
- }) {
510
- return /* @__PURE__ */ jsxRuntime.jsx(AuthThemeContext.Provider, { value: theme, children });
511
- }
512
- function useAuthTheme(themeProp) {
513
- const contextTheme = react.useContext(AuthThemeContext);
514
- return react.useMemo(() => themeProp ?? contextTheme, [themeProp, contextTheme]);
515
- }
516
578
  function LoginForm({
517
579
  client,
518
580
  theme: themeProp,
@@ -520,7 +582,8 @@ function LoginForm({
520
582
  onSuccess,
521
583
  onForgotPassword,
522
584
  onSignUp,
523
- testIdPrefix
585
+ testIdPrefix,
586
+ chromeless = false
524
587
  }) {
525
588
  const theme = useAuthTheme(themeProp);
526
589
  const styles3 = useAuthStyles(theme);
@@ -551,7 +614,7 @@ function LoginForm({
551
614
  void runLogin();
552
615
  }, [runLogin]);
553
616
  const submitButtonStyle = isSubmitting ? [styles3.primaryButton, styles3.primaryButtonDisabled] : styles3.primaryButton;
554
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles3.screen, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles3.card, testID: withTestIdPrefix(AuthTestIds.loginForm, testIdPrefix), children: [
617
+ const content = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
555
618
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles3.title, children: labels.title }),
556
619
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles3.subtitle, children: labels.subtitle }),
557
620
  /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles3.fieldGroup, children: [
@@ -640,7 +703,16 @@ function LoginForm({
640
703
  children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles3.linkText, children: labels.signUp })
641
704
  }
642
705
  ) : null
643
- ] }) });
706
+ ] });
707
+ const card = /* @__PURE__ */ jsxRuntime.jsx(
708
+ reactNative.View,
709
+ {
710
+ style: chromeless ? void 0 : styles3.card,
711
+ testID: withTestIdPrefix(AuthTestIds.loginForm, testIdPrefix),
712
+ children: content
713
+ }
714
+ );
715
+ return chromeless ? card : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles3.screen, children: card });
644
716
  }
645
717
  function useBffForgotPassword(options) {
646
718
  const { client, ...rest } = options;
@@ -1490,7 +1562,8 @@ function OtpForm({
1490
1562
  theme: themeProp,
1491
1563
  labels: labelsProp,
1492
1564
  onSuccess,
1493
- testIdPrefix
1565
+ testIdPrefix,
1566
+ chromeless = false
1494
1567
  }) {
1495
1568
  const theme = useAuthTheme(themeProp);
1496
1569
  const styles3 = useAuthStyles(theme);
@@ -1511,7 +1584,7 @@ function OtpForm({
1511
1584
  otp.reset();
1512
1585
  }, [otp]);
1513
1586
  const errorText = localError ?? transportErrorFor(otp.step, otp.error, labels);
1514
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles3.screen, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles3.card, testID: withTestIdPrefix(AuthTestIds.otpForm, testIdPrefix), children: otp.step === "requestCode" /* RequestCode */ ? /* @__PURE__ */ jsxRuntime.jsx(
1587
+ const content = otp.step === "requestCode" /* RequestCode */ ? /* @__PURE__ */ jsxRuntime.jsx(
1515
1588
  OtpRequestStep,
1516
1589
  {
1517
1590
  errorText,
@@ -1536,7 +1609,16 @@ function OtpForm({
1536
1609
  onResend: handleResend,
1537
1610
  onSubmit: handleVerify
1538
1611
  }
1539
- ) }) });
1612
+ );
1613
+ const card = /* @__PURE__ */ jsxRuntime.jsx(
1614
+ reactNative.View,
1615
+ {
1616
+ style: chromeless ? void 0 : styles3.card,
1617
+ testID: withTestIdPrefix(AuthTestIds.otpForm, testIdPrefix),
1618
+ children: content
1619
+ }
1620
+ );
1621
+ return chromeless ? card : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles3.screen, children: card });
1540
1622
  }
1541
1623
  function toError3(value) {
1542
1624
  return value instanceof Error ? value : new Error(String(value));
@@ -1615,7 +1697,8 @@ function PinForm({
1615
1697
  theme: themeProp,
1616
1698
  labels: labelsProp,
1617
1699
  onSuccess,
1618
- testIdPrefix
1700
+ testIdPrefix,
1701
+ chromeless = false
1619
1702
  }) {
1620
1703
  const theme = useAuthTheme(themeProp);
1621
1704
  const styles3 = useAuthStyles(theme);
@@ -1629,7 +1712,7 @@ function PinForm({
1629
1712
  const handleSubmit = useSubmitHandler(pin, labels, setLocalError, onSuccess);
1630
1713
  const errorText = localError ?? transportErrorFor2(pin.error, labels);
1631
1714
  const buttonStyle = pin.isSubmitting ? [styles3.primaryButton, styles3.primaryButtonDisabled] : styles3.primaryButton;
1632
- return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles3.screen, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles3.card, testID: withTestIdPrefix(AuthTestIds.pinForm, testIdPrefix), children: [
1715
+ const content = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1633
1716
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles3.title, children: labels.title }),
1634
1717
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles3.subtitle, children: labels.description }),
1635
1718
  /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles3.fieldGroup, children: [
@@ -1674,7 +1757,16 @@ function PinForm({
1674
1757
  children: pin.isSubmitting ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.ActivityIndicator, { color: theme.colors.onPrimary, size: "small" }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: styles3.primaryButtonText, children: labels.submit })
1675
1758
  }
1676
1759
  )
1677
- ] }) });
1760
+ ] });
1761
+ const card = /* @__PURE__ */ jsxRuntime.jsx(
1762
+ reactNative.View,
1763
+ {
1764
+ style: chromeless ? void 0 : styles3.card,
1765
+ testID: withTestIdPrefix(AuthTestIds.pinForm, testIdPrefix),
1766
+ children: content
1767
+ }
1768
+ );
1769
+ return chromeless ? card : /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles3.screen, children: card });
1678
1770
  }
1679
1771
  var DOT_SIZE = 18;
1680
1772
  var DOT_BORDER_WIDTH = 2;
@@ -2916,9 +3008,11 @@ Object.defineProperty(exports, "createFetchHttpClient", {
2916
3008
  enumerable: true,
2917
3009
  get: function () { return authClient.createFetchHttpClient; }
2918
3010
  });
3011
+ exports.AuthScreen = AuthScreen;
2919
3012
  exports.AuthTestIds = AuthTestIds;
2920
3013
  exports.AuthThemeProvider = AuthThemeProvider;
2921
3014
  exports.BffAuthStatus = BffAuthStatus;
3015
+ exports.DEFAULT_AUTH_CARD_MAX_WIDTH = DEFAULT_AUTH_CARD_MAX_WIDTH;
2922
3016
  exports.DEFAULT_DEVICE_PIN_ENROLL_LABELS = DEFAULT_DEVICE_PIN_ENROLL_LABELS;
2923
3017
  exports.DEFAULT_DEVICE_PIN_SETTINGS_LABELS = DEFAULT_DEVICE_PIN_SETTINGS_LABELS;
2924
3018
  exports.DEFAULT_DEVICE_PIN_UNLOCK_LABELS = DEFAULT_DEVICE_PIN_UNLOCK_LABELS;