@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.
package/dist/index.mjs ADDED
@@ -0,0 +1,59 @@
1
+ import {
2
+ AggAuthProvider,
3
+ ConnectButton,
4
+ useAggAuthFlow
5
+ } from "./chunk-4RGHFPGG.mjs";
6
+ import {
7
+ createAppleAuthMethod,
8
+ createGoogleAuthMethod,
9
+ createTwitterAuthMethod
10
+ } from "./chunk-MEJEY2D2.mjs";
11
+ import {
12
+ createEmailAuthMethod
13
+ } from "./chunk-FGEWDEEE.mjs";
14
+ import {
15
+ toError
16
+ } from "./chunk-BVV6GEOL.mjs";
17
+ import "./chunk-AXBFBHS2.mjs";
18
+
19
+ // src/callback/index.tsx
20
+ import { useEffect, useRef, useState } from "react";
21
+ import { useAggAuthContext } from "@agg-build/hooks";
22
+ var useAggAuthCallback = (options = {}) => {
23
+ const { callbackUrl, enabled = true } = options;
24
+ const auth = useAggAuthContext();
25
+ const handledRef = useRef(false);
26
+ const [error, setError] = useState(null);
27
+ const [isHandled, setIsHandled] = useState(false);
28
+ const [isHandling, setIsHandling] = useState(false);
29
+ const [user, setUser] = useState(null);
30
+ useEffect(() => {
31
+ if (!enabled || handledRef.current) return;
32
+ handledRef.current = true;
33
+ setIsHandling(true);
34
+ void auth.handleAuthCallback(callbackUrl).then((resolvedUser) => {
35
+ setUser(resolvedUser);
36
+ setIsHandled(resolvedUser !== null);
37
+ }).catch((callbackError) => {
38
+ setError(toError(callbackError));
39
+ }).finally(() => {
40
+ setIsHandling(false);
41
+ });
42
+ }, [auth, callbackUrl, enabled]);
43
+ return {
44
+ error,
45
+ isHandled,
46
+ isHandling,
47
+ user
48
+ };
49
+ };
50
+ export {
51
+ AggAuthProvider,
52
+ ConnectButton,
53
+ createAppleAuthMethod,
54
+ createEmailAuthMethod,
55
+ createGoogleAuthMethod,
56
+ createTwitterAuthMethod,
57
+ useAggAuthCallback,
58
+ useAggAuthFlow
59
+ };
@@ -0,0 +1,17 @@
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 RedirectAuthMethodOptions = {
7
+ description?: string;
8
+ isAvailable?: boolean;
9
+ label?: string;
10
+ navigate?: (url: string) => void;
11
+ redirectUrl?: string;
12
+ };
13
+ declare const createGoogleAuthMethod: (options?: RedirectAuthMethodOptions) => AuthMethodAdapter;
14
+ declare const createTwitterAuthMethod: (options?: RedirectAuthMethodOptions) => AuthMethodAdapter;
15
+ declare const createAppleAuthMethod: (options?: RedirectAuthMethodOptions) => AuthMethodAdapter;
16
+
17
+ export { createAppleAuthMethod, createGoogleAuthMethod, createTwitterAuthMethod };
@@ -0,0 +1,17 @@
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 RedirectAuthMethodOptions = {
7
+ description?: string;
8
+ isAvailable?: boolean;
9
+ label?: string;
10
+ navigate?: (url: string) => void;
11
+ redirectUrl?: string;
12
+ };
13
+ declare const createGoogleAuthMethod: (options?: RedirectAuthMethodOptions) => AuthMethodAdapter;
14
+ declare const createTwitterAuthMethod: (options?: RedirectAuthMethodOptions) => AuthMethodAdapter;
15
+ declare const createAppleAuthMethod: (options?: RedirectAuthMethodOptions) => AuthMethodAdapter;
16
+
17
+ export { createAppleAuthMethod, createGoogleAuthMethod, createTwitterAuthMethod };
package/dist/oauth.js ADDED
@@ -0,0 +1,124 @@
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/oauth/index.ts
41
+ var oauth_exports = {};
42
+ __export(oauth_exports, {
43
+ createAppleAuthMethod: () => createAppleAuthMethod,
44
+ createGoogleAuthMethod: () => createGoogleAuthMethod,
45
+ createTwitterAuthMethod: () => createTwitterAuthMethod
46
+ });
47
+ module.exports = __toCommonJS(oauth_exports);
48
+
49
+ // src/shared/utils.ts
50
+ var resolveRedirectUrl = (redirectUrl) => {
51
+ if (redirectUrl) return redirectUrl;
52
+ if (typeof window === "undefined") return "http://localhost";
53
+ return `${window.location.origin}${window.location.pathname}${window.location.search}`;
54
+ };
55
+
56
+ // src/oauth/index.ts
57
+ var defaultNavigate = (url) => {
58
+ if (typeof window === "undefined") {
59
+ throw new Error("Redirect auth methods require a browser environment");
60
+ }
61
+ window.location.assign(url);
62
+ };
63
+ var createRedirectAuthMethod = (provider, defaults, options = {}) => {
64
+ var _a, _b, _c;
65
+ return {
66
+ id: provider,
67
+ kind: "social",
68
+ label: (_a = options.label) != null ? _a : defaults.label,
69
+ description: (_b = options.description) != null ? _b : defaults.description,
70
+ iconName: defaults.iconName,
71
+ isAvailable: (_c = options.isAvailable) != null ? _c : true,
72
+ start: (_0) => __async(null, [_0], function* ({ startAuth }) {
73
+ var _a2;
74
+ const response = yield startAuth({
75
+ provider,
76
+ redirectUrl: resolveRedirectUrl(options.redirectUrl)
77
+ });
78
+ if (response.type !== "redirect") {
79
+ throw new Error(`AGG auth start returned an unexpected "${response.type}" response`);
80
+ }
81
+ const navigate = (_a2 = options.navigate) != null ? _a2 : defaultNavigate;
82
+ navigate(response.url);
83
+ })
84
+ };
85
+ };
86
+ var createGoogleAuthMethod = (options = {}) => {
87
+ return createRedirectAuthMethod(
88
+ "google",
89
+ {
90
+ label: "Google",
91
+ description: "Continue with your Google account.",
92
+ iconName: "google"
93
+ },
94
+ options
95
+ );
96
+ };
97
+ var createTwitterAuthMethod = (options = {}) => {
98
+ return createRedirectAuthMethod(
99
+ "twitter",
100
+ {
101
+ label: "X",
102
+ description: "Continue with your X account.",
103
+ iconName: "twitter"
104
+ },
105
+ options
106
+ );
107
+ };
108
+ var createAppleAuthMethod = (options = {}) => {
109
+ return createRedirectAuthMethod(
110
+ "apple",
111
+ {
112
+ label: "Apple",
113
+ description: "Continue with Apple.",
114
+ iconName: "apple"
115
+ },
116
+ options
117
+ );
118
+ };
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ createAppleAuthMethod,
122
+ createGoogleAuthMethod,
123
+ createTwitterAuthMethod
124
+ });
package/dist/oauth.mjs ADDED
@@ -0,0 +1,12 @@
1
+ import {
2
+ createAppleAuthMethod,
3
+ createGoogleAuthMethod,
4
+ createTwitterAuthMethod
5
+ } from "./chunk-MEJEY2D2.mjs";
6
+ import "./chunk-BVV6GEOL.mjs";
7
+ import "./chunk-AXBFBHS2.mjs";
8
+ export {
9
+ createAppleAuthMethod,
10
+ createGoogleAuthMethod,
11
+ createTwitterAuthMethod
12
+ };
@@ -0,0 +1,16 @@
1
+ import { Connector } from 'wagmi';
2
+ import { b as AuthMethodAdapter } from './types-D-OXBxXn.mjs';
3
+ import '@agg-build/hooks';
4
+ import '@agg-build/ui';
5
+ import 'react';
6
+
7
+ type SiweAuthMethodOptions = {
8
+ connectorName?: string;
9
+ connectorPicker?: (connectors: readonly Connector[]) => Promise<Connector | null>;
10
+ description?: string;
11
+ label?: string;
12
+ statement?: string;
13
+ };
14
+ declare const useSiweAuthMethod: (options?: SiweAuthMethodOptions) => AuthMethodAdapter;
15
+
16
+ export { useSiweAuthMethod };
package/dist/siwe.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { Connector } from 'wagmi';
2
+ import { b as AuthMethodAdapter } from './types-D-OXBxXn.js';
3
+ import '@agg-build/hooks';
4
+ import '@agg-build/ui';
5
+ import 'react';
6
+
7
+ type SiweAuthMethodOptions = {
8
+ connectorName?: string;
9
+ connectorPicker?: (connectors: readonly Connector[]) => Promise<Connector | null>;
10
+ description?: string;
11
+ label?: string;
12
+ statement?: string;
13
+ };
14
+ declare const useSiweAuthMethod: (options?: SiweAuthMethodOptions) => AuthMethodAdapter;
15
+
16
+ export { useSiweAuthMethod };
package/dist/siwe.js ADDED
@@ -0,0 +1,129 @@
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/siwe/index.tsx
41
+ var siwe_exports = {};
42
+ __export(siwe_exports, {
43
+ useSiweAuthMethod: () => useSiweAuthMethod
44
+ });
45
+ module.exports = __toCommonJS(siwe_exports);
46
+ var import_react = require("react");
47
+ var import_wagmi = require("wagmi");
48
+ var useSiweAuthMethod = (options = {}) => {
49
+ const { address, chainId, isConnected } = (0, import_wagmi.useAccount)();
50
+ const { connectAsync, connectors } = (0, import_wagmi.useConnect)();
51
+ const { disconnectAsync } = (0, import_wagmi.useDisconnect)();
52
+ const { signMessageAsync } = (0, import_wagmi.useSignMessage)();
53
+ const { connectorName, connectorPicker, description, label, statement } = options;
54
+ return (0, import_react.useMemo)(() => {
55
+ return {
56
+ id: "siwe",
57
+ kind: "wallet",
58
+ chain: "ethereum",
59
+ label: label != null ? label : "Ethereum",
60
+ description: description != null ? description : "Connect and sign in with your Ethereum wallet.",
61
+ iconName: "ethereum",
62
+ isAvailable: isConnected || connectors.length > 0,
63
+ start: (_0) => __async(null, [_0], function* ({ signIn }) {
64
+ var _a, _b;
65
+ let resolvedAddress = address != null ? address : "";
66
+ let resolvedChainId = chainId;
67
+ const shouldDisconnectOnFailure = !resolvedAddress;
68
+ try {
69
+ if (!resolvedAddress) {
70
+ let connector;
71
+ if (connectorPicker) {
72
+ connector = yield connectorPicker(connectors);
73
+ } else if (connectorName) {
74
+ connector = (_a = connectors.find((candidate) => candidate.name === connectorName)) != null ? _a : connectors[0];
75
+ } else {
76
+ connector = connectors[0];
77
+ }
78
+ if (!connector) {
79
+ throw new Error("No Ethereum wallet connector selected");
80
+ }
81
+ const connection = yield connectAsync({ connector });
82
+ resolvedAddress = (_b = connection.accounts[0]) != null ? _b : "";
83
+ resolvedChainId = connection.chainId;
84
+ }
85
+ if (!resolvedAddress) {
86
+ throw new Error("Ethereum wallet address is unavailable");
87
+ }
88
+ yield signIn({
89
+ address: resolvedAddress,
90
+ chain: "ethereum",
91
+ chainId: resolvedChainId,
92
+ signMessage: (message) => __async(null, null, function* () {
93
+ return signMessageAsync({ message });
94
+ }),
95
+ statement
96
+ });
97
+ } catch (error) {
98
+ if (shouldDisconnectOnFailure) {
99
+ try {
100
+ yield disconnectAsync();
101
+ } catch (e) {
102
+ }
103
+ }
104
+ throw error;
105
+ }
106
+ }),
107
+ disconnect: () => __async(null, null, function* () {
108
+ yield disconnectAsync();
109
+ })
110
+ };
111
+ }, [
112
+ address,
113
+ chainId,
114
+ connectAsync,
115
+ connectors,
116
+ disconnectAsync,
117
+ isConnected,
118
+ connectorName,
119
+ connectorPicker,
120
+ description,
121
+ label,
122
+ statement,
123
+ signMessageAsync
124
+ ]);
125
+ };
126
+ // Annotate the CommonJS export names for ESM import in node:
127
+ 0 && (module.exports = {
128
+ useSiweAuthMethod
129
+ });
package/dist/siwe.mjs ADDED
@@ -0,0 +1,88 @@
1
+ import {
2
+ __async
3
+ } from "./chunk-AXBFBHS2.mjs";
4
+
5
+ // src/siwe/index.tsx
6
+ import { useMemo } from "react";
7
+ import { useAccount, useConnect, useDisconnect, useSignMessage } from "wagmi";
8
+ var useSiweAuthMethod = (options = {}) => {
9
+ const { address, chainId, isConnected } = useAccount();
10
+ const { connectAsync, connectors } = useConnect();
11
+ const { disconnectAsync } = useDisconnect();
12
+ const { signMessageAsync } = useSignMessage();
13
+ const { connectorName, connectorPicker, description, label, statement } = options;
14
+ return useMemo(() => {
15
+ return {
16
+ id: "siwe",
17
+ kind: "wallet",
18
+ chain: "ethereum",
19
+ label: label != null ? label : "Ethereum",
20
+ description: description != null ? description : "Connect and sign in with your Ethereum wallet.",
21
+ iconName: "ethereum",
22
+ isAvailable: isConnected || connectors.length > 0,
23
+ start: (_0) => __async(null, [_0], function* ({ signIn }) {
24
+ var _a, _b;
25
+ let resolvedAddress = address != null ? address : "";
26
+ let resolvedChainId = chainId;
27
+ const shouldDisconnectOnFailure = !resolvedAddress;
28
+ try {
29
+ if (!resolvedAddress) {
30
+ let connector;
31
+ if (connectorPicker) {
32
+ connector = yield connectorPicker(connectors);
33
+ } else if (connectorName) {
34
+ connector = (_a = connectors.find((candidate) => candidate.name === connectorName)) != null ? _a : connectors[0];
35
+ } else {
36
+ connector = connectors[0];
37
+ }
38
+ if (!connector) {
39
+ throw new Error("No Ethereum wallet connector selected");
40
+ }
41
+ const connection = yield connectAsync({ connector });
42
+ resolvedAddress = (_b = connection.accounts[0]) != null ? _b : "";
43
+ resolvedChainId = connection.chainId;
44
+ }
45
+ if (!resolvedAddress) {
46
+ throw new Error("Ethereum wallet address is unavailable");
47
+ }
48
+ yield signIn({
49
+ address: resolvedAddress,
50
+ chain: "ethereum",
51
+ chainId: resolvedChainId,
52
+ signMessage: (message) => __async(null, null, function* () {
53
+ return signMessageAsync({ message });
54
+ }),
55
+ statement
56
+ });
57
+ } catch (error) {
58
+ if (shouldDisconnectOnFailure) {
59
+ try {
60
+ yield disconnectAsync();
61
+ } catch (e) {
62
+ }
63
+ }
64
+ throw error;
65
+ }
66
+ }),
67
+ disconnect: () => __async(null, null, function* () {
68
+ yield disconnectAsync();
69
+ })
70
+ };
71
+ }, [
72
+ address,
73
+ chainId,
74
+ connectAsync,
75
+ connectors,
76
+ disconnectAsync,
77
+ isConnected,
78
+ connectorName,
79
+ connectorPicker,
80
+ description,
81
+ label,
82
+ statement,
83
+ signMessageAsync
84
+ ]);
85
+ };
86
+ export {
87
+ useSiweAuthMethod
88
+ };
@@ -0,0 +1,14 @@
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 SiwsAuthMethodOptions = {
7
+ cluster?: string;
8
+ description?: string;
9
+ label?: string;
10
+ statement?: string;
11
+ };
12
+ declare const useSiwsAuthMethod: (options?: SiwsAuthMethodOptions) => AuthMethodAdapter;
13
+
14
+ export { useSiwsAuthMethod };
package/dist/siws.d.ts ADDED
@@ -0,0 +1,14 @@
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 SiwsAuthMethodOptions = {
7
+ cluster?: string;
8
+ description?: string;
9
+ label?: string;
10
+ statement?: string;
11
+ };
12
+ declare const useSiwsAuthMethod: (options?: SiwsAuthMethodOptions) => AuthMethodAdapter;
13
+
14
+ export { useSiwsAuthMethod };