@levo-so/studio 0.3.20 → 0.3.22

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.
Files changed (69) hide show
  1. package/BillingStep-ioR7mSo5.js +249 -0
  2. package/BookingCard-DEkBXh7O.js +646 -0
  3. package/DateTimeWidget-B-dajfHj.js +253 -0
  4. package/{EntryCard-9yv0KJTB.js → EntryCard-CZfljZAY.js} +4 -4
  5. package/{KBChatWidget-D39Z3HIl.js → KBChatWidget-BXRRgelS.js} +1 -1
  6. package/{LoginCard-D9vEC_g0.js → LoginCard-BVjeN1J0.js} +3 -3
  7. package/{LoginForm-kI_b_7Tc.js → LoginForm-DQVwLQCx.js} +19 -19
  8. package/{LoginModal-C-9BhmoO.js → LoginModal-C6TdAh-0.js} +5 -6
  9. package/{MessageCard-Nsxr98n6.js → MessageCard-B5MbVDJ8.js} +2 -2
  10. package/{MessageFooter-K4Zd_eFO.js → MessageFooter-DrlKXE9a.js} +1 -2
  11. package/{PendingApprovalCard-CzoBgYNy.js → PendingApprovalCard-5iFAeE1s.js} +3 -3
  12. package/{PhoneWidget-BtMMfGLu.js → PhoneWidget-B4KHlFjT.js} +6 -7
  13. package/{Popover-Iis-qOn1.js → Popover-y8XkbYNh.js} +7 -7
  14. package/{PopupBody-BI-MJqmd-B3ltSYMP.js → PopupBody-DWM55Zh5-DuOPsCAn.js} +53 -55
  15. package/PopupDialog-DwAAJ8JS-9xm5jrXW.js +261 -0
  16. package/PopupRenderer-BVtV4b9I-BdPryfLY.js +208 -0
  17. package/{ProfileCard-Chg20HBa.js → ProfileCard-WgFT-T4U.js} +5 -5
  18. package/{RichTextWidget-C3Y-0pNy.js → RichTextWidget-DKYm1cSW.js} +120 -123
  19. package/{Spinner-D5spB_Mv.js → Spinner-LdYfm4S7.js} +1 -1
  20. package/{VerifyButton-BwTbzSwS.js → VerifyButton-CNq78zG4.js} +5 -7
  21. package/collection.d.ts +9 -1
  22. package/collection.js +1 -1
  23. package/dialog-CU5nHKc5.js +119 -0
  24. package/dist-IMRD6dob.js +3858 -0
  25. package/index.js +3280 -2848
  26. package/{inlineRteTheme-BOAno9MG.js → inlineRteTheme-DFg69bqP.js} +50 -37
  27. package/{kbChat-zXbn56Zb.js → kbChat-eFsau7hG.js} +2 -2
  28. package/package.json +42 -43
  29. package/{pillChrome-QDjBETmP.js → pillChrome-Dy3ApFI5.js} +5 -5
  30. package/price-BUDkN5Me.js +823 -0
  31. package/script.esm-uVCZU25S.js +62 -0
  32. package/studio.css +1 -1
  33. package/themeMapping-DH_NoXK8-H-EHXbBt.js +156 -0
  34. package/useCheckout-gscmzFLD.js +179 -0
  35. package/useLogin-BYVekOp9.js +237 -0
  36. package/AuthProvider-B5NfFwbG.js +0 -118
  37. package/BillingStep-BTDOMFHV.js +0 -181
  38. package/Button-DXLWW3dp.js +0 -504
  39. package/CollectionField-BZmxRB5D.js +0 -270
  40. package/CollectionInput-DyNbxIZ8.js +0 -147
  41. package/DateTimeWidget-Bt1UcCnx.js +0 -255
  42. package/Dialog-CPE8yUqK.js +0 -130
  43. package/ModalManager-CzH36UIk.js +0 -32
  44. package/PopupRenderer-D66Gx63H-ChI4WBer.js +0 -389
  45. package/RteThemeProvider-owl5oajj.js +0 -20
  46. package/ThemeProvider-CqPHzkW9.js +0 -116
  47. package/Tooltip-DHU1QD-n.js +0 -67
  48. package/authentication-BXQbxiPP.js +0 -36
  49. package/bookingCard-g0n3ksiC.js +0 -605
  50. package/createThemeExtension-C0PSYy0J.js +0 -15
  51. package/dialog-8LH_ihs4.js +0 -92
  52. package/dist-Dijjo-5m.js +0 -3794
  53. package/generateRadiusScale-RROt8ppa.js +0 -71
  54. package/inlineCollectionTheme-uhBXoF1F.js +0 -19
  55. package/popupState-JmpeKzgM-UECLsSbL.js +0 -100
  56. package/rteTheme.cssm-W4gTOijw.js +0 -4
  57. package/theme.cssm-Czj9sF4X.js +0 -4
  58. package/themeMapping-Bi9Rcr5G-C7UXWE6o.js +0 -61
  59. package/useCheckout-DFalmfEQ.js +0 -161
  60. package/useLogin-CfnGrLdO.js +0 -127
  61. package/usePopupRedirect-CAAdcpaW-DdME0F7f.js +0 -82
  62. /package/{Beams-WJN38XSv.js → Beams-KsU_ixpY.js} +0 -0
  63. /package/{Dots-DggLz5I7.js → Dots-C_ja_PPu.js} +0 -0
  64. /package/{Gradient-BSWJAu0a.js → Gradient-CDGFLaA-.js} +0 -0
  65. /package/{Grid-BFKl0MUt.js → Grid-C22rTkrs.js} +0 -0
  66. /package/{Waves-BPEgTYoO.js → Waves-Cl5rKcFJ.js} +0 -0
  67. /package/{card-5ooLmYSr.js → card-BIebVDA0.js} +0 -0
  68. /package/{cn-B6c1DjO_.js → cn-CzJDhklM.js} +0 -0
  69. /package/{fontSize-B-ba6pvx.js → fontSize-DowUyWe-.js} +0 -0
@@ -0,0 +1,156 @@
1
+ import { F as e, N as t, P as n } from "./price-BUDkN5Me.js";
2
+ import { persistentAtom as r } from "@nanostores/persistent";
3
+ import { atom as i, computed as a } from "nanostores";
4
+ //#region ../../libraries/levocn/dist/styles/inlineBaseTheme.js
5
+ var o = n(e), s = (e) => e ? e.radius && !e.radiusScale ? o({
6
+ ...e,
7
+ radiusScale: t(e.radius)
8
+ }) : o(e) : {}, c = 6e4, l = "lv_popups_session", u = {
9
+ active_popup_id: null,
10
+ shown_popup_ids: [],
11
+ last_closed_at: null
12
+ }, d = r("lv_popups_state", {}, {
13
+ encode: JSON.stringify,
14
+ decode: JSON.parse
15
+ }), f = (e) => {
16
+ if (!e) return u;
17
+ try {
18
+ return {
19
+ ...JSON.parse(e),
20
+ active_popup_id: null
21
+ };
22
+ } catch {
23
+ return u;
24
+ }
25
+ }, p = i((() => {
26
+ if (typeof sessionStorage > "u") return u;
27
+ try {
28
+ return f(sessionStorage.getItem(l));
29
+ } catch {
30
+ return u;
31
+ }
32
+ })()), m = p.set;
33
+ p.set = (e) => {
34
+ m(e);
35
+ try {
36
+ sessionStorage.setItem(l, JSON.stringify(e));
37
+ } catch {}
38
+ };
39
+ var h = a([p, d], (e, t) => ({
40
+ active_popup_id: e.active_popup_id,
41
+ shown_popup_ids: e.shown_popup_ids,
42
+ last_closed_at: e.last_closed_at,
43
+ previous_popups: t
44
+ })), g = i([]), _ = (e) => {
45
+ g.set(e);
46
+ }, v = i(!0), y = (e) => {
47
+ v.set(e);
48
+ }, b = () => h.get(), x = (e, t) => e.includes(t) ? e : [...e, t], S = "manual", C = () => S, w = null, T = () => w, E = [], D = null, O = () => {
49
+ if (D) return;
50
+ let { last_closed_at: e } = p.get();
51
+ if (!e) return;
52
+ let t = c - (Date.now() - e);
53
+ if (t <= 0) {
54
+ k();
55
+ return;
56
+ }
57
+ D = setTimeout(() => {
58
+ D = null, k();
59
+ }, t);
60
+ }, k = () => {
61
+ let e = p.get();
62
+ if (!e.active_popup_id) {
63
+ if (e.last_closed_at && Date.now() - e.last_closed_at < 6e4) {
64
+ O();
65
+ return;
66
+ }
67
+ for (; E.length > 0;) {
68
+ let e = E.shift();
69
+ if (M(e.popup, { trigger_type: e.trigger_type })) return;
70
+ }
71
+ }
72
+ }, A = (e, t) => {
73
+ E.some((t) => t.popup.id === e.id) || (E.push({
74
+ popup: e,
75
+ trigger_type: t
76
+ }), O());
77
+ }, j = (e, t) => {
78
+ let n = b();
79
+ if (t?.type === "always") return !n.shown_popup_ids.includes(e);
80
+ let r = n.previous_popups[e];
81
+ return r ? !t || t.type === "once" ? !1 : t.type === "interval" && t.interval_ms ? Date.now() - r.triggered_at >= t.interval_ms : !0 : !0;
82
+ }, M = (e, t = {}) => {
83
+ let { force: n = !1, trigger_type: r = "manual" } = t, i = e.id, a = e.settings?.display_frequency, o = p.get();
84
+ return o.active_popup_id === i ? !0 : !n && (o.active_popup_id || o.last_closed_at && Date.now() - o.last_closed_at < 6e4 || !j(i, a)) ? !1 : (D &&= (clearTimeout(D), null), S = r, w = Date.now(), p.set({
85
+ active_popup_id: i,
86
+ shown_popup_ids: x(o.shown_popup_ids, i),
87
+ last_closed_at: o.last_closed_at
88
+ }), a?.type !== "always" && d.set({
89
+ ...d.get(),
90
+ [i]: { triggered_at: Date.now() }
91
+ }), !0);
92
+ }, N = (e, t = {}) => {
93
+ let { trigger_type: n = "manual" } = t;
94
+ return M(e, { trigger_type: n }) ? !0 : (j(e.id, e.settings?.display_frequency) && A(e, n), !1);
95
+ }, P = (e) => {
96
+ let t = p.get();
97
+ t.active_popup_id === e && (S = "manual", w = null, p.set({
98
+ ...t,
99
+ active_popup_id: null,
100
+ last_closed_at: Date.now()
101
+ }), setTimeout(k, 0));
102
+ }, F = (e) => {
103
+ if (e == null) return;
104
+ if (typeof e == "string") return e;
105
+ if (typeof e != "object") return;
106
+ let t = e;
107
+ if (typeof t.l != "number" || typeof t.c != "number" || typeof t.h != "number") return;
108
+ let n = (e) => Math.round(e * 1e4) / 1e4, r = n(t.l), i = n(t.c), a = n(t.h), o = typeof t.alpha == "number" ? n(t.alpha) : 1;
109
+ return o < 1 ? `oklch(${r} ${i} ${a} / ${o})` : `oklch(${r} ${i} ${a})`;
110
+ }, I = (e) => {
111
+ let t = e.colors;
112
+ return !t || typeof t != "object" ? !1 : Object.values(t).some((e) => e != null);
113
+ }, L = (e) => {
114
+ if (!e || !I(e)) return null;
115
+ let t = e.colors, n = t?.brand ?? {}, r = e.fonts, i = e.sizes;
116
+ return {
117
+ colors: {
118
+ brand: {
119
+ main: F(n.main) ?? "",
120
+ foreground: F(n.foreground) ?? ""
121
+ },
122
+ text1: F(t.text1) ?? "",
123
+ text2: F(t.text2) ?? "",
124
+ page: F(t.page) ?? "",
125
+ border: F(t.border) ?? ""
126
+ },
127
+ fonts: {
128
+ heading: r?.heading ?? "inherit",
129
+ body: r?.body ?? "inherit"
130
+ },
131
+ sizes: { radius: i?.radius ?? "4px" }
132
+ };
133
+ }, R = (e) => {
134
+ if (e) return {
135
+ colors: {
136
+ primary: e.colors?.brand?.main,
137
+ primaryForeground: e.colors?.brand?.foreground,
138
+ foreground: e.colors?.text1,
139
+ text: e.colors?.text1,
140
+ heading: e.colors?.text1,
141
+ mutedForeground: e.colors?.text2,
142
+ background: e.colors?.page,
143
+ card: e.colors?.page,
144
+ cardForeground: e.colors?.text1,
145
+ popover: e.colors?.page,
146
+ popoverForeground: e.colors?.text1,
147
+ border: e.colors?.border,
148
+ input: e.colors?.page,
149
+ inputForeground: e.colors?.text1
150
+ },
151
+ fonts: e.fonts,
152
+ radius: e.sizes?.radius
153
+ };
154
+ }, z = (e) => s(R(e));
155
+ //#endregion
156
+ export { h as a, y as c, v as d, _ as f, s as h, M as i, N as l, C as m, z as n, g as o, T as p, L as r, b as s, P as t, p as u };
@@ -0,0 +1,179 @@
1
+ "use client";
2
+ import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
3
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
4
+ import { XIcon as s } from "lucide-react";
5
+ import c from "clsx";
6
+ import { useRazorpay as l } from "react-razorpay";
7
+ import { EmbeddedCheckout as u, EmbeddedCheckoutProvider as d } from "@stripe/react-stripe-js";
8
+ import { createPortal as f } from "react-dom";
9
+ //#region ../../libraries/react-collection/dist/lib/CollectionFormRenderer/booking/checkout/openCashfreeCheckout.js
10
+ var p = async (e) => {
11
+ let { payment_session_id: t, order_id: n } = e;
12
+ if (!t || !n) throw Error("Cashfree payment session missing");
13
+ let { load: r } = await import("./script.esm-uVCZU25S.js"), i = await r({ mode: e.environment || "production" });
14
+ if (!i) throw Error("Cashfree checkout failed to load");
15
+ let a = await i.checkout({
16
+ paymentSessionId: t,
17
+ redirectTarget: "_modal"
18
+ });
19
+ return a.paymentDetails ? {
20
+ status: "completed",
21
+ confirmation: { order_id: n }
22
+ } : a.redirect ? { status: "redirect" } : {
23
+ status: "closed",
24
+ message: a.error?.message
25
+ };
26
+ }, m = () => typeof window < "u" && "Razorpay" in window, h = ({ order: e, onSettled: n, onError: i }) => {
27
+ let { Razorpay: a, isLoading: o, error: s } = l(), c = r({
28
+ onSettled: n,
29
+ onError: i
30
+ });
31
+ c.current = {
32
+ onSettled: n,
33
+ onError: i
34
+ };
35
+ let u = r(!1);
36
+ return t(() => {
37
+ if (u.current) return;
38
+ if (s) {
39
+ u.current = !0, c.current.onError(Error(s));
40
+ return;
41
+ }
42
+ if (!a || !m()) return;
43
+ u.current = !0;
44
+ let t;
45
+ try {
46
+ let n = new a({
47
+ key: e.key,
48
+ amount: e.amount,
49
+ currency: e.currency,
50
+ order_id: e.orderId,
51
+ name: e.merchantName,
52
+ description: e.description,
53
+ prefill: e.prefill,
54
+ theme: e.themeColor ? { color: e.themeColor } : void 0,
55
+ handler: (e) => c.current.onSettled({
56
+ status: "completed",
57
+ confirmation: {
58
+ order_id: e.razorpay_order_id,
59
+ payment_id: e.razorpay_payment_id,
60
+ signature: e.razorpay_signature
61
+ }
62
+ }),
63
+ modal: { ondismiss: () => c.current.onSettled({
64
+ status: "closed",
65
+ message: t
66
+ }) }
67
+ });
68
+ n.on("payment.failed", (e) => {
69
+ t = e?.error?.description;
70
+ }), n.open();
71
+ } catch (e) {
72
+ c.current.onError(e instanceof Error ? e : /* @__PURE__ */ Error("Razorpay checkout failed to open"));
73
+ }
74
+ }, [
75
+ a,
76
+ o,
77
+ s,
78
+ e
79
+ ]), null;
80
+ }, g = "_1fguior1", _ = "_1fguior2", v = "_1fguior3", y = "_1fguior4", b = "_1fguior5", x = ({ stripePromise: e, clientSecret: i, onClose: l, onComplete: p }) => {
81
+ let m = r(p);
82
+ m.current = p;
83
+ let h = n(() => ({
84
+ clientSecret: i,
85
+ onComplete: () => m.current()
86
+ }), [i]), x = r(null), S = r(null);
87
+ return t(() => {
88
+ let e = document.activeElement, t = x.current;
89
+ S.current?.focus();
90
+ let n = !1, r = (e) => {
91
+ e.key === "Tab" && (n = e.shiftKey);
92
+ }, i = (e) => {
93
+ if (!t || t.contains(e.target)) return;
94
+ let r = t.querySelector("iframe") ?? S.current;
95
+ (n ? r : S.current)?.focus(), n = !1;
96
+ };
97
+ return document.addEventListener("keydown", r, !0), document.addEventListener("focusin", i), () => {
98
+ document.removeEventListener("keydown", r, !0), document.removeEventListener("focusin", i), e?.focus?.();
99
+ };
100
+ }, []), f(/* @__PURE__ */ a("div", {
101
+ className: g,
102
+ children: /* @__PURE__ */ o("div", {
103
+ ref: x,
104
+ role: "dialog",
105
+ "aria-modal": "true",
106
+ "aria-label": "Payment",
107
+ className: _,
108
+ children: [/* @__PURE__ */ a("button", {
109
+ ref: S,
110
+ type: "button",
111
+ onClick: l,
112
+ "aria-label": "Close payment",
113
+ className: v,
114
+ children: /* @__PURE__ */ a(s, { size: 20 })
115
+ }), /* @__PURE__ */ a("div", {
116
+ className: y,
117
+ children: /* @__PURE__ */ a(d, {
118
+ stripe: e,
119
+ options: h,
120
+ children: /* @__PURE__ */ a(u, { className: c("stripe-embedded-checkout", b) })
121
+ })
122
+ })]
123
+ })
124
+ }), document.body);
125
+ }, S = () => {
126
+ let [t, n] = i(null), r = e(async (e, t) => {
127
+ if (e.provider === "cashfree") return p(e);
128
+ if (e.provider === "stripe") {
129
+ let { client_secret: t, session_id: r } = e;
130
+ if (!t || !r) throw Error("Stripe checkout session missing");
131
+ let { loadStripe: i } = await import("@stripe/stripe-js"), a = i(e.key);
132
+ return new Promise((e, i) => n({
133
+ provider: "stripe",
134
+ stripePromise: a,
135
+ clientSecret: t,
136
+ sessionId: r,
137
+ settle: {
138
+ resolve: e,
139
+ reject: i
140
+ }
141
+ }));
142
+ }
143
+ let { order_id: r } = e;
144
+ if (!r) throw Error("Razorpay order missing");
145
+ return new Promise((i, a) => n({
146
+ provider: "razorpay",
147
+ order: {
148
+ ...t,
149
+ key: e.key,
150
+ currency: e.currency || "INR",
151
+ orderId: r
152
+ },
153
+ settle: {
154
+ resolve: i,
155
+ reject: a
156
+ }
157
+ }));
158
+ }, []), o = (e, t) => {
159
+ n(null), t instanceof Error ? e.settle.reject(t) : e.settle.resolve(t);
160
+ }, s = null;
161
+ return t?.provider === "stripe" ? s = /* @__PURE__ */ a(x, {
162
+ stripePromise: t.stripePromise,
163
+ clientSecret: t.clientSecret,
164
+ onComplete: () => o(t, {
165
+ status: "completed",
166
+ confirmation: { session_id: t.sessionId }
167
+ }),
168
+ onClose: () => o(t, { status: "closed" })
169
+ }) : t?.provider === "razorpay" && (s = /* @__PURE__ */ a(h, {
170
+ order: t.order,
171
+ onSettled: (e) => o(t, e),
172
+ onError: (e) => o(t, e)
173
+ })), {
174
+ open: r,
175
+ element: s
176
+ };
177
+ };
178
+ //#endregion
179
+ export { S as t };
@@ -0,0 +1,237 @@
1
+ "use client";
2
+ import { useLevo as e } from "@levo-so/react";
3
+ import { createContext as t, useContext as n, useEffect as r, useState as i } from "react";
4
+ import { jsx as a } from "react/jsx-runtime";
5
+ import { LevoError as o, getLevoError as s } from "@levo-so/core";
6
+ //#region src/providers/AuthProvider.tsx
7
+ var c = t({
8
+ isLoggedIn: !1,
9
+ account: null,
10
+ workspace: null,
11
+ isAuthLoaded: !1,
12
+ isAuthLoading: !1,
13
+ isSignOutLoading: !1,
14
+ isVerifying: !1,
15
+ setAuthState: () => {},
16
+ resetAuth: () => {}
17
+ }), l = ({ children: t, workspace: n, authOverride: o }) => {
18
+ let [l, u] = i({
19
+ isAuthLoading: !1,
20
+ isSignOutLoading: !1,
21
+ isVerifying: !1,
22
+ isAuthLoaded: !1,
23
+ isLoggedIn: !1,
24
+ account: null,
25
+ workspace: n
26
+ }), d = e(), f = (e) => {
27
+ u((t) => ({
28
+ ...t,
29
+ ...e
30
+ }));
31
+ }, p = () => {
32
+ u({
33
+ isAuthLoading: !1,
34
+ isSignOutLoading: !1,
35
+ isVerifying: !1,
36
+ isAuthLoaded: !0,
37
+ isLoggedIn: !1,
38
+ account: null,
39
+ workspace: n
40
+ });
41
+ };
42
+ return r(() => {
43
+ if (o?.enabled) {
44
+ if (o.isLoggedIn && o.selectedAccount) f({
45
+ account: o.selectedAccount,
46
+ isAuthLoaded: !0,
47
+ isAuthLoading: !1,
48
+ isLoggedIn: !0
49
+ });
50
+ else {
51
+ let e = {
52
+ _id: "preview-user-id",
53
+ first_name: "John",
54
+ last_name: "Doe",
55
+ slug: "john-doe",
56
+ username: "johndoe",
57
+ email: "john.doe@example.com",
58
+ display_email: "john.doe@example.com",
59
+ reducted_email: "jo***@example.com",
60
+ email_verified: !0,
61
+ email_verified_at: (/* @__PURE__ */ new Date()).toISOString(),
62
+ verified_at: (/* @__PURE__ */ new Date()).toISOString(),
63
+ mobile: null,
64
+ reducted_mobile: null,
65
+ mobile_verified: !1,
66
+ mobile_verified_at: null,
67
+ profile_picture: null,
68
+ oauth_credentials: [],
69
+ account_locked_at: null,
70
+ credentials_expired_at: null,
71
+ deactivated_at: null,
72
+ last_access_at: (/* @__PURE__ */ new Date()).toISOString(),
73
+ flagged_at: null,
74
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
75
+ updated_at: (/* @__PURE__ */ new Date()).toISOString(),
76
+ deleted_at: null
77
+ };
78
+ f({
79
+ account: o.isLoggedIn ? e : null,
80
+ isAuthLoaded: !0,
81
+ isAuthLoading: !1,
82
+ isLoggedIn: o.isLoggedIn
83
+ });
84
+ }
85
+ return;
86
+ } else d?.apiUrl && !l.isAuthLoaded && !l.isAuthLoading && (f({ isAuthLoading: !0 }), d.membership?.getMe()?.then((e) => {
87
+ f({
88
+ account: e,
89
+ isAuthLoaded: !0,
90
+ isAuthLoading: !1,
91
+ isLoggedIn: !0
92
+ });
93
+ })?.catch((e) => {
94
+ let t = s(e);
95
+ console.error("Initial auth check failed", t.message), f({
96
+ account: null,
97
+ isAuthLoaded: !0,
98
+ isAuthLoading: !1,
99
+ isLoggedIn: !1
100
+ });
101
+ }));
102
+ }, [
103
+ d?.apiUrl,
104
+ l.isAuthLoaded,
105
+ o
106
+ ]), /* @__PURE__ */ a(c.Provider, {
107
+ value: {
108
+ ...l,
109
+ isLoggedIn: l.isLoggedIn && !!l.account,
110
+ workspace: n,
111
+ setAuthState: f,
112
+ resetAuth: p
113
+ },
114
+ children: t
115
+ });
116
+ }, u = () => n(c), d = () => {
117
+ let { membership: t, logger: n } = e(), { isLoggedIn: r, isAuthLoading: i, setAuthState: a } = u(), c = async (e, r) => {
118
+ let { email: i, phone: a, medium: c } = e, l = i || a;
119
+ if (!l) throw new o({
120
+ status: 400,
121
+ code: "VALIDATION_ERROR",
122
+ title: "Missing Content",
123
+ description: "Either email or phone must be provided"
124
+ });
125
+ if (!t) throw new o({
126
+ status: 500,
127
+ code: "SDK_ERROR",
128
+ title: "SDK Error",
129
+ description: "Membership client not initialized"
130
+ });
131
+ try {
132
+ await t.requestOtp({
133
+ content: l,
134
+ medium: c || (a ? "whatsapp" : void 0)
135
+ });
136
+ } catch (e) {
137
+ let t = s(e), i = c === "whatsapp" || a ? "WhatsApp OTP" : "OTP";
138
+ throw n?.error(`Failed to ${r} ${i}`, { exception: t }), t;
139
+ }
140
+ }, l = (e) => c(e, "send"), d = (e) => c(e, "resend"), f = async (e, r) => {
141
+ if (!t) throw new o({
142
+ status: 500,
143
+ code: "SDK_ERROR",
144
+ title: "SDK Error",
145
+ description: "Membership client not initialized"
146
+ });
147
+ a({
148
+ isAuthLoading: !0,
149
+ isVerifying: !0
150
+ });
151
+ try {
152
+ let n = await t.signInWithOtp({
153
+ content: e,
154
+ code: r
155
+ });
156
+ return a({
157
+ account: n,
158
+ isAuthLoading: !1,
159
+ isVerifying: !1,
160
+ isLoggedIn: !0
161
+ }), n;
162
+ } catch (e) {
163
+ let t = s(e);
164
+ throw n?.error("OTP verification failed", { exception: t }), a({
165
+ account: null,
166
+ isAuthLoading: !1,
167
+ isVerifying: !1,
168
+ isLoggedIn: !1
169
+ }), t;
170
+ }
171
+ }, p = async (e) => {
172
+ if (!t) throw new o({
173
+ status: 500,
174
+ code: "SDK_ERROR",
175
+ title: "SDK Error",
176
+ description: "Membership client not initialized"
177
+ });
178
+ try {
179
+ await t.requestMagicLink({ content: e });
180
+ } catch (e) {
181
+ let t = s(e);
182
+ throw n?.error("Failed to send magic link", { exception: t }), t;
183
+ }
184
+ }, m = (e) => {
185
+ if (!t) {
186
+ n?.error("Refetch login status failed", { reason: "Membership client not initialized" });
187
+ return;
188
+ }
189
+ a({ isAuthLoading: !0 }), t.getMe().then((t) => {
190
+ t ? (a({
191
+ account: t,
192
+ isAuthLoading: !1,
193
+ isLoggedIn: !0
194
+ }), e?.(t)) : a({
195
+ account: null,
196
+ isAuthLoading: !1,
197
+ isLoggedIn: !1
198
+ });
199
+ }).catch((e) => {
200
+ let t = s(e);
201
+ n?.error("Refetch login status failed", { exception: t }), a({
202
+ account: null,
203
+ isAuthLoading: !1,
204
+ isLoggedIn: !1
205
+ });
206
+ });
207
+ };
208
+ return {
209
+ sendOTP: l,
210
+ verifyOTP: f,
211
+ resendOTP: d,
212
+ sendMagicLink: p,
213
+ refetchLoginStatus: m,
214
+ signOut: (e, r) => {
215
+ if (!t) {
216
+ let e = new o({
217
+ status: 500,
218
+ code: "SDK_ERROR",
219
+ title: "SDK Error",
220
+ description: "Membership client not initialized"
221
+ });
222
+ n?.error("Sign out failed", { exception: e }), r?.(e);
223
+ return;
224
+ }
225
+ a({ isSignOutLoading: !0 }), t.signOut().then(() => {
226
+ e && e(), m(), a({ isSignOutLoading: !1 });
227
+ }).catch((e) => {
228
+ let t = s(e);
229
+ n?.error("Sign out failed", { exception: t }), a({ isSignOutLoading: !1 }), r && r(t);
230
+ });
231
+ },
232
+ isLoggedIn: r,
233
+ isAuthLoading: i
234
+ };
235
+ };
236
+ //#endregion
237
+ export { l as n, u as r, d as t };
@@ -1,118 +0,0 @@
1
- "use client";
2
- import { useLevo as e } from "@levo-so/react";
3
- import { createContext as t, useContext as n, useEffect as r, useState as i } from "react";
4
- import { jsx as a } from "react/jsx-runtime";
5
- import { getLevoError as o } from "@levo-so/core";
6
- //#region src/providers/AuthProvider.tsx
7
- var s = t({
8
- isLoggedIn: !1,
9
- account: null,
10
- workspace: null,
11
- isAuthLoaded: !1,
12
- isAuthLoading: !1,
13
- isSignOutLoading: !1,
14
- isVerifying: !1,
15
- setAuthState: () => {},
16
- resetAuth: () => {}
17
- }), c = ({ children: t, workspace: n, authOverride: c }) => {
18
- let [l, u] = i({
19
- isAuthLoading: !1,
20
- isSignOutLoading: !1,
21
- isVerifying: !1,
22
- isAuthLoaded: !1,
23
- isLoggedIn: !1,
24
- account: null,
25
- workspace: n
26
- }), d = e(), f = (e) => {
27
- u((t) => ({
28
- ...t,
29
- ...e
30
- }));
31
- }, p = () => {
32
- u({
33
- isAuthLoading: !1,
34
- isSignOutLoading: !1,
35
- isVerifying: !1,
36
- isAuthLoaded: !0,
37
- isLoggedIn: !1,
38
- account: null,
39
- workspace: n
40
- });
41
- };
42
- return r(() => {
43
- if (c?.enabled) {
44
- if (c.isLoggedIn && c.selectedAccount) f({
45
- account: c.selectedAccount,
46
- isAuthLoaded: !0,
47
- isAuthLoading: !1,
48
- isLoggedIn: !0
49
- });
50
- else {
51
- let e = {
52
- _id: "preview-user-id",
53
- first_name: "John",
54
- last_name: "Doe",
55
- slug: "john-doe",
56
- username: "johndoe",
57
- email: "john.doe@example.com",
58
- display_email: "john.doe@example.com",
59
- reducted_email: "jo***@example.com",
60
- email_verified: !0,
61
- email_verified_at: (/* @__PURE__ */ new Date()).toISOString(),
62
- verified_at: (/* @__PURE__ */ new Date()).toISOString(),
63
- mobile: null,
64
- reducted_mobile: null,
65
- mobile_verified: !1,
66
- mobile_verified_at: null,
67
- profile_picture: null,
68
- oauth_credentials: [],
69
- account_locked_at: null,
70
- credentials_expired_at: null,
71
- deactivated_at: null,
72
- last_access_at: (/* @__PURE__ */ new Date()).toISOString(),
73
- flagged_at: null,
74
- created_at: (/* @__PURE__ */ new Date()).toISOString(),
75
- updated_at: (/* @__PURE__ */ new Date()).toISOString(),
76
- deleted_at: null
77
- };
78
- f({
79
- account: c.isLoggedIn ? e : null,
80
- isAuthLoaded: !0,
81
- isAuthLoading: !1,
82
- isLoggedIn: c.isLoggedIn
83
- });
84
- }
85
- return;
86
- } else d?.apiUrl && !l.isAuthLoaded && !l.isAuthLoading && (f({ isAuthLoading: !0 }), d.membership?.getMe()?.then((e) => {
87
- f({
88
- account: e,
89
- isAuthLoaded: !0,
90
- isAuthLoading: !1,
91
- isLoggedIn: !0
92
- });
93
- })?.catch((e) => {
94
- let t = o(e);
95
- console.error("Initial auth check failed", t.message), f({
96
- account: null,
97
- isAuthLoaded: !0,
98
- isAuthLoading: !1,
99
- isLoggedIn: !1
100
- });
101
- }));
102
- }, [
103
- d?.apiUrl,
104
- l.isAuthLoaded,
105
- c
106
- ]), /* @__PURE__ */ a(s.Provider, {
107
- value: {
108
- ...l,
109
- isLoggedIn: l.isLoggedIn && !!l.account,
110
- workspace: n,
111
- setAuthState: f,
112
- resetAuth: p
113
- },
114
- children: t
115
- });
116
- }, l = () => n(s);
117
- //#endregion
118
- export { l as n, c as t };