@agg-build/auth 1.0.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,76 @@
1
+ import {
2
+ resolveRedirectUrl
3
+ } from "./chunk-BVV6GEOL.mjs";
4
+ import {
5
+ __async
6
+ } from "./chunk-AXBFBHS2.mjs";
7
+
8
+ // src/oauth/index.ts
9
+ var defaultNavigate = (url) => {
10
+ if (typeof window === "undefined") {
11
+ throw new Error("Redirect auth methods require a browser environment");
12
+ }
13
+ window.location.assign(url);
14
+ };
15
+ var createRedirectAuthMethod = (provider, defaults, options = {}) => {
16
+ var _a, _b, _c;
17
+ return {
18
+ id: provider,
19
+ kind: "social",
20
+ label: (_a = options.label) != null ? _a : defaults.label,
21
+ description: (_b = options.description) != null ? _b : defaults.description,
22
+ iconName: defaults.iconName,
23
+ isAvailable: (_c = options.isAvailable) != null ? _c : true,
24
+ start: (_0) => __async(null, [_0], function* ({ startAuth }) {
25
+ var _a2;
26
+ const response = yield startAuth({
27
+ provider,
28
+ redirectUrl: resolveRedirectUrl(options.redirectUrl)
29
+ });
30
+ if (response.type !== "redirect") {
31
+ throw new Error(`AGG auth start returned an unexpected "${response.type}" response`);
32
+ }
33
+ const navigate = (_a2 = options.navigate) != null ? _a2 : defaultNavigate;
34
+ navigate(response.url);
35
+ })
36
+ };
37
+ };
38
+ var createGoogleAuthMethod = (options = {}) => {
39
+ return createRedirectAuthMethod(
40
+ "google",
41
+ {
42
+ label: "Google",
43
+ description: "Continue with your Google account.",
44
+ iconName: "google"
45
+ },
46
+ options
47
+ );
48
+ };
49
+ var createTwitterAuthMethod = (options = {}) => {
50
+ return createRedirectAuthMethod(
51
+ "twitter",
52
+ {
53
+ label: "X",
54
+ description: "Continue with your X account.",
55
+ iconName: "twitter"
56
+ },
57
+ options
58
+ );
59
+ };
60
+ var createAppleAuthMethod = (options = {}) => {
61
+ return createRedirectAuthMethod(
62
+ "apple",
63
+ {
64
+ label: "Apple",
65
+ description: "Continue with Apple.",
66
+ iconName: "apple"
67
+ },
68
+ options
69
+ );
70
+ };
71
+
72
+ export {
73
+ createGoogleAuthMethod,
74
+ createTwitterAuthMethod,
75
+ createAppleAuthMethod
76
+ };
@@ -0,0 +1,28 @@
1
+ import { JSX } from 'react';
2
+ import { AuthConnectButtonViewButtonProps, AuthConnectButtonViewClassNames } from '@agg-build/ui';
3
+ import { c as AuthMethodId } from './types-D-OXBxXn.mjs';
4
+ import '@agg-build/hooks';
5
+
6
+ type ConnectButtonActionHandler = () => Promise<void> | void;
7
+ type ConnectButtonClassNames = AuthConnectButtonViewClassNames;
8
+ type ConnectButtonButtonProps = AuthConnectButtonViewButtonProps;
9
+ type ConnectButtonProps = {
10
+ buttonProps?: ConnectButtonButtonProps;
11
+ classNames?: ConnectButtonClassNames;
12
+ disabled?: boolean;
13
+ onAuthMethodSelect?: (methodId: AuthMethodId) => Promise<void> | void;
14
+ onDepositClick?: ConnectButtonActionHandler;
15
+ onDisconnect?: ConnectButtonActionHandler;
16
+ onProfileCardClick?: ConnectButtonActionHandler;
17
+ onProfileClick?: ConnectButtonActionHandler;
18
+ onClaimWinningsClick?: ConnectButtonActionHandler;
19
+ claimReadyCount?: number;
20
+ onWithdrawClick?: ConnectButtonActionHandler;
21
+ };
22
+
23
+ declare const ConnectButton: {
24
+ ({ buttonProps, classNames, disabled, onAuthMethodSelect, onDepositClick, onDisconnect, onProfileCardClick, onProfileClick, onClaimWinningsClick, claimReadyCount, onWithdrawClick, }: ConnectButtonProps): JSX.Element;
25
+ displayName: string;
26
+ };
27
+
28
+ export { ConnectButton, type ConnectButtonButtonProps, type ConnectButtonClassNames, type ConnectButtonProps };
@@ -0,0 +1,28 @@
1
+ import { JSX } from 'react';
2
+ import { AuthConnectButtonViewButtonProps, AuthConnectButtonViewClassNames } from '@agg-build/ui';
3
+ import { c as AuthMethodId } from './types-D-OXBxXn.js';
4
+ import '@agg-build/hooks';
5
+
6
+ type ConnectButtonActionHandler = () => Promise<void> | void;
7
+ type ConnectButtonClassNames = AuthConnectButtonViewClassNames;
8
+ type ConnectButtonButtonProps = AuthConnectButtonViewButtonProps;
9
+ type ConnectButtonProps = {
10
+ buttonProps?: ConnectButtonButtonProps;
11
+ classNames?: ConnectButtonClassNames;
12
+ disabled?: boolean;
13
+ onAuthMethodSelect?: (methodId: AuthMethodId) => Promise<void> | void;
14
+ onDepositClick?: ConnectButtonActionHandler;
15
+ onDisconnect?: ConnectButtonActionHandler;
16
+ onProfileCardClick?: ConnectButtonActionHandler;
17
+ onProfileClick?: ConnectButtonActionHandler;
18
+ onClaimWinningsClick?: ConnectButtonActionHandler;
19
+ claimReadyCount?: number;
20
+ onWithdrawClick?: ConnectButtonActionHandler;
21
+ };
22
+
23
+ declare const ConnectButton: {
24
+ ({ buttonProps, classNames, disabled, onAuthMethodSelect, onDepositClick, onDisconnect, onProfileCardClick, onProfileClick, onClaimWinningsClick, claimReadyCount, onWithdrawClick, }: ConnectButtonProps): JSX.Element;
25
+ displayName: string;
26
+ };
27
+
28
+ export { ConnectButton, type ConnectButtonButtonProps, type ConnectButtonClassNames, type ConnectButtonProps };
@@ -0,0 +1,372 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
39
+
40
+ // src/connect-button/index.tsx
41
+ var connect_button_exports = {};
42
+ __export(connect_button_exports, {
43
+ ConnectButton: () => ConnectButton
44
+ });
45
+ module.exports = __toCommonJS(connect_button_exports);
46
+ var import_react3 = require("react");
47
+ var import_ui = require("@agg-build/ui");
48
+ var import_hooks3 = require("@agg-build/hooks");
49
+
50
+ // src/core/context.tsx
51
+ var import_react = require("react");
52
+ var import_hooks = require("@agg-build/hooks");
53
+
54
+ // src/shared/utils.ts
55
+ var shortenAddress = (value) => {
56
+ if (value.length < 10) return value;
57
+ if (value.startsWith("0x")) return `${value.slice(0, 6)}...${value.slice(-4)}`;
58
+ return `${value.slice(0, 4)}...${value.slice(-4)}`;
59
+ };
60
+ var shortenProfileLabel = (value) => {
61
+ if (!value) return value;
62
+ if (value.includes("@")) return value;
63
+ if (value.startsWith("0x")) return shortenAddress(value);
64
+ if (value.length <= 16) return value;
65
+ return `${value.slice(0, 8)}...${value.slice(-5)}`;
66
+ };
67
+
68
+ // src/core/context.tsx
69
+ var import_jsx_runtime = require("react/jsx-runtime");
70
+ var AggAuthFlowContext = (0, import_react.createContext)(null);
71
+ var useAggAuthFlow = () => {
72
+ const context = (0, import_react.useContext)(AggAuthFlowContext);
73
+ if (!context) {
74
+ throw new Error("useAggAuthFlow must be used within an <AggAuthProvider>");
75
+ }
76
+ return context;
77
+ };
78
+
79
+ // src/turnstile/index.tsx
80
+ var import_react2 = require("react");
81
+ var import_react_turnstile = require("@marsidev/react-turnstile");
82
+ var import_jsx_runtime2 = require("react/jsx-runtime");
83
+ var TurnstileErrorBoundary = class extends import_react2.Component {
84
+ constructor() {
85
+ super(...arguments);
86
+ this.state = { hasError: false };
87
+ }
88
+ static getDerivedStateFromError() {
89
+ return { hasError: true };
90
+ }
91
+ componentDidCatch(_error, _info) {
92
+ var _a, _b;
93
+ (_b = (_a = this.props).onError) == null ? void 0 : _b.call(_a);
94
+ }
95
+ render() {
96
+ if (this.state.hasError) return null;
97
+ return this.props.children;
98
+ }
99
+ };
100
+ var TurnstileWidget = ({
101
+ siteKey,
102
+ onVerify,
103
+ onError,
104
+ onExpire
105
+ }) => {
106
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TurnstileErrorBoundary, { onError, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
107
+ import_react_turnstile.Turnstile,
108
+ {
109
+ siteKey,
110
+ onSuccess: onVerify,
111
+ onError,
112
+ onExpire,
113
+ options: { appearance: "always", theme: "auto" }
114
+ }
115
+ ) });
116
+ };
117
+
118
+ // src/connect-button/connect-button.utils.ts
119
+ var import_hooks2 = require("@agg-build/hooks");
120
+ var getAuthProfileLabel = (user) => {
121
+ var _a, _b;
122
+ if (user == null ? void 0 : user.username) return user.username;
123
+ const walletAddress = (0, import_hooks2.getWalletAddressFromUserProfile)(user);
124
+ if (walletAddress) return shortenAddress(walletAddress);
125
+ const providerAccountId = (_b = (_a = user == null ? void 0 : user.accounts) == null ? void 0 : _a[0]) == null ? void 0 : _b.providerAccountId;
126
+ if (providerAccountId) return shortenProfileLabel(providerAccountId);
127
+ if (user == null ? void 0 : user.id) return shortenProfileLabel(user.id);
128
+ return "";
129
+ };
130
+ var socialOrder = {
131
+ google: 0,
132
+ apple: 1,
133
+ twitter: 2
134
+ };
135
+ var walletOrder = {
136
+ siws: 0,
137
+ siwe: 1
138
+ };
139
+ var toViewMethod = (method) => {
140
+ return {
141
+ chain: method.chain,
142
+ description: method.description,
143
+ iconName: method.iconName,
144
+ id: method.id,
145
+ input: method.input,
146
+ isAvailable: method.isAvailable,
147
+ kind: method.kind,
148
+ label: method.label
149
+ };
150
+ };
151
+ var groupConnectButtonMethods = (methods) => {
152
+ var _a;
153
+ const emailMethod = (_a = methods.find((method) => method.kind === "email")) != null ? _a : null;
154
+ const socialMethods = methods.filter((method) => method.kind === "social").slice().sort((left, right) => {
155
+ var _a2, _b;
156
+ return ((_a2 = socialOrder[left.id]) != null ? _a2 : 99) - ((_b = socialOrder[right.id]) != null ? _b : 99);
157
+ }).map(toViewMethod);
158
+ const walletMethods = methods.filter((method) => method.kind === "wallet").slice().sort((left, right) => {
159
+ var _a2, _b;
160
+ return ((_a2 = walletOrder[left.id]) != null ? _a2 : 99) - ((_b = walletOrder[right.id]) != null ? _b : 99);
161
+ }).map(toViewMethod);
162
+ return {
163
+ emailMethod: emailMethod ? toViewMethod(emailMethod) : null,
164
+ socialMethods,
165
+ walletMethods
166
+ };
167
+ };
168
+
169
+ // src/connect-button/index.tsx
170
+ var import_jsx_runtime3 = require("react/jsx-runtime");
171
+ var ConnectButton = ({
172
+ buttonProps,
173
+ classNames,
174
+ disabled,
175
+ onAuthMethodSelect,
176
+ onDepositClick,
177
+ onDisconnect,
178
+ onProfileCardClick,
179
+ onProfileClick,
180
+ onClaimWinningsClick,
181
+ claimReadyCount,
182
+ onWithdrawClick
183
+ }) => {
184
+ var _a, _b;
185
+ const [emailValue, setEmailValue] = (0, import_react3.useState)("");
186
+ const [emailError, setEmailError] = (0, import_react3.useState)(null);
187
+ const [isChooserOpen, setIsChooserOpen] = (0, import_react3.useState)(false);
188
+ const [isProfileMenuOpen, setIsProfileMenuOpen] = (0, import_react3.useState)(false);
189
+ const {
190
+ activeMethodId,
191
+ challengeSiteKey,
192
+ clearFeedback,
193
+ configuredMethods,
194
+ error,
195
+ isBusy,
196
+ notice,
197
+ onChallengeError,
198
+ onChallengeVerify,
199
+ signOut,
200
+ startMethod
201
+ } = useAggAuthFlow();
202
+ const { isAuthenticated, user } = (0, import_hooks3.useAggAuthContext)();
203
+ const {
204
+ totalBalance,
205
+ positionsBalanceTotal,
206
+ isLoading: isBalanceLoading,
207
+ error: balanceError
208
+ } = (0, import_hooks3.useAggBalanceState)();
209
+ const { isDepositBlocked } = (0, import_hooks3.useGeoBlock)();
210
+ const resolvedWalletAddress = (_a = (0, import_hooks3.getWalletAddressFromUserProfile)(user)) != null ? _a : "";
211
+ const resolvedAddressLabel = resolvedWalletAddress ? shortenAddress(resolvedWalletAddress) : void 0;
212
+ const resolvedProfileLabel = getAuthProfileLabel(user) || void 0;
213
+ const { emailMethod, socialMethods, walletMethods } = (0, import_react3.useMemo)(() => {
214
+ return groupConnectButtonMethods(configuredMethods);
215
+ }, [configuredMethods]);
216
+ (0, import_react3.useEffect)(() => {
217
+ if (!isAuthenticated) return;
218
+ setIsChooserOpen(false);
219
+ setEmailError(null);
220
+ }, [isAuthenticated]);
221
+ (0, import_react3.useEffect)(() => {
222
+ if (typeof window === "undefined") return;
223
+ const handleOpenChooserRequest = () => {
224
+ if (disabled || isAuthenticated) return;
225
+ setEmailError(null);
226
+ clearFeedback();
227
+ setIsChooserOpen(true);
228
+ };
229
+ window.addEventListener(import_hooks3.AUTH_CHOOSER_OPEN_EVENT, handleOpenChooserRequest);
230
+ return () => {
231
+ window.removeEventListener(import_hooks3.AUTH_CHOOSER_OPEN_EVENT, handleOpenChooserRequest);
232
+ };
233
+ }, [clearFeedback, disabled, isAuthenticated]);
234
+ const resolvedError = error != null ? error : balanceError;
235
+ const challengeContent = challengeSiteKey ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex flex-col items-center gap-3", children: [
236
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-agg-sm text-agg-muted-foreground text-center", children: "Please complete the verification below to continue." }),
237
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
238
+ TurnstileWidget,
239
+ {
240
+ siteKey: challengeSiteKey,
241
+ onVerify: onChallengeVerify,
242
+ onError: onChallengeError,
243
+ onExpire: onChallengeError
244
+ }
245
+ )
246
+ ] }) : null;
247
+ const handleMethodSelection = (method) => __async(null, null, function* () {
248
+ if (!method.isAvailable || disabled || isBusy) return;
249
+ setEmailError(null);
250
+ clearFeedback();
251
+ setIsChooserOpen(false);
252
+ let result;
253
+ try {
254
+ result = yield startMethod(method.id);
255
+ } catch (e) {
256
+ setIsChooserOpen(true);
257
+ return;
258
+ }
259
+ if (result == null ? void 0 : result.challengePending) return;
260
+ yield Promise.resolve(onAuthMethodSelect == null ? void 0 : onAuthMethodSelect(method.id));
261
+ setIsChooserOpen(false);
262
+ });
263
+ const handleEmailSubmit = () => __async(null, null, function* () {
264
+ var _a2, _b2, _c;
265
+ if (!emailMethod || !emailMethod.isAvailable || disabled || isBusy) return;
266
+ const parsedEmail = (0, import_hooks3.parseEmail)(emailValue);
267
+ if (!parsedEmail.success) {
268
+ setEmailError((_c = (_b2 = (_a2 = parsedEmail.error) == null ? void 0 : _a2.issues[0]) == null ? void 0 : _b2.message) != null ? _c : "Enter a valid email address.");
269
+ return;
270
+ }
271
+ setEmailError(null);
272
+ const result = yield startMethod(emailMethod.id, {
273
+ email: parsedEmail.data.email
274
+ });
275
+ if (result == null ? void 0 : result.challengePending) return;
276
+ yield Promise.resolve(onAuthMethodSelect == null ? void 0 : onAuthMethodSelect(emailMethod.id));
277
+ setEmailValue("");
278
+ setIsChooserOpen(false);
279
+ });
280
+ const handleDepositClick = () => {
281
+ if (disabled) return;
282
+ setIsProfileMenuOpen(false);
283
+ void Promise.resolve(onDepositClick == null ? void 0 : onDepositClick());
284
+ };
285
+ const handleProfileCardClick = () => {
286
+ if (disabled) return;
287
+ setIsProfileMenuOpen(false);
288
+ void Promise.resolve(onProfileCardClick == null ? void 0 : onProfileCardClick());
289
+ };
290
+ const handleProfileClick = () => {
291
+ if (disabled) return;
292
+ setIsProfileMenuOpen(false);
293
+ void Promise.resolve(onProfileClick == null ? void 0 : onProfileClick());
294
+ };
295
+ const handleClaimWinningsClick = () => {
296
+ if (disabled) return;
297
+ setIsProfileMenuOpen(false);
298
+ void Promise.resolve(onClaimWinningsClick == null ? void 0 : onClaimWinningsClick());
299
+ };
300
+ const handleWithdrawClick = () => {
301
+ if (disabled) return;
302
+ setIsProfileMenuOpen(false);
303
+ void Promise.resolve(onWithdrawClick == null ? void 0 : onWithdrawClick());
304
+ };
305
+ const handleDisconnectClick = () => __async(null, null, function* () {
306
+ if (disabled) return;
307
+ setIsProfileMenuOpen(false);
308
+ yield signOut();
309
+ yield Promise.resolve(onDisconnect == null ? void 0 : onDisconnect());
310
+ });
311
+ const handleChooserOpenChange = (open) => {
312
+ if (disabled) return;
313
+ setIsChooserOpen(open);
314
+ if (open) return;
315
+ setEmailError(null);
316
+ clearFeedback();
317
+ };
318
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
319
+ import_ui.AuthConnectButtonView,
320
+ {
321
+ activeMethodId,
322
+ addressLabel: resolvedAddressLabel,
323
+ buttonProps,
324
+ challengeContent,
325
+ classNames,
326
+ disabled,
327
+ emailMethod,
328
+ emailError,
329
+ emailValue,
330
+ errorMessage: (_b = resolvedError == null ? void 0 : resolvedError.message) != null ? _b : null,
331
+ isAuthenticated,
332
+ isBalanceLoading,
333
+ isBusy,
334
+ isChooserOpen,
335
+ isProfileMenuOpen,
336
+ notice,
337
+ onChooserOpenChange: handleChooserOpenChange,
338
+ onDepositClick: handleDepositClick,
339
+ onDisconnectClick: () => {
340
+ void handleDisconnectClick();
341
+ },
342
+ onEmailChange: setEmailValue,
343
+ onEmailSubmit: () => {
344
+ void handleEmailSubmit();
345
+ },
346
+ onMethodSelect: (methodId) => {
347
+ const selectedMethod = [...socialMethods, ...walletMethods].find(
348
+ (method) => method.id === methodId
349
+ );
350
+ if (!selectedMethod) return;
351
+ void handleMethodSelection(selectedMethod);
352
+ },
353
+ onProfileCardClick: handleProfileCardClick,
354
+ onProfileClick: handleProfileClick,
355
+ onProfileMenuOpenChange: setIsProfileMenuOpen,
356
+ socialMethods,
357
+ onWithdrawClick: handleWithdrawClick,
358
+ profileLabel: resolvedProfileLabel,
359
+ totalBalance,
360
+ positionsBalance: positionsBalanceTotal,
361
+ claimReadyCount,
362
+ onClaimWinningsClick: handleClaimWinningsClick,
363
+ walletMethods,
364
+ isDepositBlocked
365
+ }
366
+ );
367
+ };
368
+ ConnectButton.displayName = "ConnectButton";
369
+ // Annotate the CommonJS export names for ESM import in node:
370
+ 0 && (module.exports = {
371
+ ConnectButton
372
+ });
@@ -0,0 +1,8 @@
1
+ import {
2
+ ConnectButton
3
+ } from "./chunk-4RGHFPGG.mjs";
4
+ import "./chunk-BVV6GEOL.mjs";
5
+ import "./chunk-AXBFBHS2.mjs";
6
+ export {
7
+ ConnectButton
8
+ };
@@ -0,0 +1,18 @@
1
+ import { b as AuthMethodAdapter } from './types-D-OXBxXn.mjs';
2
+ import '@agg-build/hooks';
3
+ import '@agg-build/ui';
4
+ import 'react';
5
+
6
+ type EmailAuthMethodOptions = {
7
+ description?: string;
8
+ helperText?: string;
9
+ isAvailable?: boolean;
10
+ label?: string;
11
+ placeholder?: string;
12
+ redirectUrl?: string;
13
+ successNotice?: string;
14
+ submitLabel?: string;
15
+ };
16
+ declare const createEmailAuthMethod: (options?: EmailAuthMethodOptions) => AuthMethodAdapter;
17
+
18
+ export { createEmailAuthMethod };
@@ -0,0 +1,18 @@
1
+ import { b as AuthMethodAdapter } from './types-D-OXBxXn.js';
2
+ import '@agg-build/hooks';
3
+ import '@agg-build/ui';
4
+ import 'react';
5
+
6
+ type EmailAuthMethodOptions = {
7
+ description?: string;
8
+ helperText?: string;
9
+ isAvailable?: boolean;
10
+ label?: string;
11
+ placeholder?: string;
12
+ redirectUrl?: string;
13
+ successNotice?: string;
14
+ submitLabel?: string;
15
+ };
16
+ declare const createEmailAuthMethod: (options?: EmailAuthMethodOptions) => AuthMethodAdapter;
17
+
18
+ export { createEmailAuthMethod };
package/dist/email.js ADDED
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
39
+
40
+ // src/email/index.ts
41
+ var email_exports = {};
42
+ __export(email_exports, {
43
+ createEmailAuthMethod: () => createEmailAuthMethod
44
+ });
45
+ module.exports = __toCommonJS(email_exports);
46
+ var import_hooks = require("@agg-build/hooks");
47
+
48
+ // src/shared/utils.ts
49
+ var resolveRedirectUrl = (redirectUrl) => {
50
+ if (redirectUrl) return redirectUrl;
51
+ if (typeof window === "undefined") return "http://localhost";
52
+ return `${window.location.origin}${window.location.pathname}${window.location.search}`;
53
+ };
54
+
55
+ // src/email/index.ts
56
+ var createEmailAuthMethod = (options = {}) => {
57
+ var _a, _b, _c, _d, _e;
58
+ return {
59
+ id: "email",
60
+ kind: "email",
61
+ label: (_a = options.label) != null ? _a : "Email",
62
+ description: (_b = options.description) != null ? _b : "Get a magic link sent to your inbox.",
63
+ iconName: "email",
64
+ input: {
65
+ type: "email",
66
+ placeholder: (_c = options.placeholder) != null ? _c : "Email address",
67
+ submitLabel: (_d = options.submitLabel) != null ? _d : "Continue",
68
+ helperText: options.helperText
69
+ },
70
+ isAvailable: (_e = options.isAvailable) != null ? _e : true,
71
+ start: (_0, _1) => __async(null, [_0, _1], function* ({ startAuth }, input) {
72
+ var _a2, _b2;
73
+ const { email } = (0, import_hooks.parseEmailStrict)((_a2 = input == null ? void 0 : input.email) != null ? _a2 : "");
74
+ const response = yield startAuth({
75
+ provider: "email",
76
+ email,
77
+ redirectUrl: resolveRedirectUrl(options.redirectUrl)
78
+ });
79
+ if (response.type === "challenge_required") {
80
+ if (!response.siteKey) {
81
+ throw new Error("Server returned challenge_required but no siteKey was provided.");
82
+ }
83
+ throw new import_hooks.TurnstileChallengeError(response.siteKey);
84
+ }
85
+ if (response.type !== "magic_link") {
86
+ throw new Error(`AGG auth start returned an unexpected "${response.type}" response`);
87
+ }
88
+ return {
89
+ notice: (_b2 = options.successNotice) != null ? _b2 : "Check your email for a magic link to finish signing in."
90
+ };
91
+ })
92
+ };
93
+ };
94
+ // Annotate the CommonJS export names for ESM import in node:
95
+ 0 && (module.exports = {
96
+ createEmailAuthMethod
97
+ });
package/dist/email.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import {
2
+ createEmailAuthMethod
3
+ } from "./chunk-FGEWDEEE.mjs";
4
+ import "./chunk-BVV6GEOL.mjs";
5
+ import "./chunk-AXBFBHS2.mjs";
6
+ export {
7
+ createEmailAuthMethod
8
+ };
@@ -0,0 +1,26 @@
1
+ import { A as AggAuthProviderProps, a as AggAuthFlowContextValue } from './types-D-OXBxXn.mjs';
2
+ export { b as AuthMethodAdapter, c as AuthMethodId, d as AuthMethodInputDefinition, e as AuthMethodInputValue, f as AuthMethodStartContext, g as AuthMethodStartResult } from './types-D-OXBxXn.mjs';
3
+ import { useAggAuthContext } from '@agg-build/hooks';
4
+ export { ConnectButton, ConnectButtonButtonProps, ConnectButtonClassNames, ConnectButtonProps } from './connect-button.mjs';
5
+ export { createEmailAuthMethod } from './email.mjs';
6
+ export { createAppleAuthMethod, createGoogleAuthMethod, createTwitterAuthMethod } from './oauth.mjs';
7
+ import '@agg-build/ui';
8
+ import 'react';
9
+
10
+ declare const AggAuthProvider: ({ autoHandleAuthCallback, children, methods, }: AggAuthProviderProps) => JSX.Element;
11
+ declare const useAggAuthFlow: () => AggAuthFlowContextValue;
12
+
13
+ type CallbackUser = ReturnType<typeof useAggAuthContext>["user"];
14
+ interface UseAggAuthCallbackOptions {
15
+ callbackUrl?: string | URL;
16
+ enabled?: boolean;
17
+ }
18
+ interface UseAggAuthCallbackResult {
19
+ error: Error | null;
20
+ isHandled: boolean;
21
+ isHandling: boolean;
22
+ user: CallbackUser | null;
23
+ }
24
+ declare const useAggAuthCallback: (options?: UseAggAuthCallbackOptions) => UseAggAuthCallbackResult;
25
+
26
+ export { AggAuthFlowContextValue, AggAuthProvider, AggAuthProviderProps, type UseAggAuthCallbackOptions, type UseAggAuthCallbackResult, useAggAuthCallback, useAggAuthFlow };