web3bio-profile-kit 0.1.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/README.md ADDED
@@ -0,0 +1,256 @@
1
+ # Web3.bio Profile Kit
2
+
3
+ A lightweight React hooks library for easily integrating Web3.bio profile data into your applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install web3bio-profile-kit
9
+ # or
10
+ yarn add web3bio-profile-kit
11
+ # or
12
+ pnpm add web3bio-profile-kit
13
+ ```
14
+
15
+ ## Overview
16
+
17
+ Web3.bio Profile Kit provides React hooks for querying the [Web3.bio Profile API](https://api.web3.bio/), which offers unified profile data across multiple Web3 platforms. This library makes it easy to fetch user profiles, name service information, and domain data.
18
+
19
+ More information about the Web3.bio Profile API can be found in the [document](https://api.web3.bio/).
20
+
21
+ ## API Key
22
+
23
+ The Profile API is free, but usage without API keys includes rate limiting mechanisms to ensure fair usage and prevent abuse. If you need an API Key, you can obtain one by contacting Web3.bio via [Twitter (X)](https://x.com/web3bio) or [Telegram group](https://t.me/web3dotbio).
24
+
25
+ You can set your API key using environment variables:
26
+
27
+ ```
28
+ WEB3BIO_API_KEY=your_api_key
29
+ # or
30
+ REACT_APP_WEB3BIO_API_KEY=your_api_key
31
+ # or
32
+ NEXT_PUBLIC_WEB3BIO_API_KEY=your_api_key
33
+ # or
34
+ VITE_WEB3BIO_API_KEY=your_api_key
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ### Query Profile Data
40
+
41
+ #### Platform-Specific Profile Queries
42
+
43
+ ```jsx
44
+ import { useProfile } from 'web3bio-profile-kit';
45
+
46
+ function ProfileComponent() {
47
+ // Query with explicit platform format
48
+ const { data, isLoading, error } = useProfile("ens,vitalik.eth");
49
+
50
+ // Or simplified format without the platform prefix
51
+ // const { data, isLoading, error } = useProfile("vitalik.eth");
52
+ // Or with Ethereum address
53
+ // const { data, isLoading, error } = useProfile("ethereum,0x123...");
54
+ // Or Farcaster, Lens, Basenames, Linea names and more
55
+
56
+ if (isLoading) return <div>Loading...</div>;
57
+ if (error) return <div>Error: {error.message}</div>;
58
+
59
+ return (
60
+ <div>
61
+ <h1>{data?.displayName || data?.identity}</h1>
62
+ {data?.avatar && <img src={data.avatar} alt="Profile" />}
63
+ <p>{data?.description}</p>
64
+ </div>
65
+ );
66
+ }
67
+ ```
68
+
69
+ #### Universal Profile Queries
70
+
71
+ ```jsx
72
+ import { useUniversalProfile } from 'web3bio-profile-kit';
73
+
74
+ function UniversalProfileComponent() {
75
+ // Query by any identity format - ENS domain, Farcaster handle, etc.
76
+ const { data, isLoading, error } = useUniversalProfile("vitalik.eth");
77
+
78
+ // Or with any other identity
79
+ // const { data, isLoading, error } = useUniversalProfile("dwr.eth.farcaster");
80
+ // const { data, isLoading, error } = useUniversalProfile("0x123...");
81
+
82
+ if (isLoading) return <div>Loading...</div>;
83
+ if (error) return <div>Error: {error.message}</div>;
84
+
85
+ return (
86
+ <div>
87
+ <h1>{data?.displayName || data?.identity}</h1>
88
+ {data?.avatar && <img src={data.avatar} alt="Profile" />}
89
+ <p>{data?.description}</p>
90
+ </div>
91
+ );
92
+ }
93
+ ```
94
+
95
+ ### Query Name Service Data
96
+
97
+ #### Platform-Specific Name Service Queries
98
+
99
+ ```jsx
100
+ import { useNS } from 'web3bio-profile-kit';
101
+
102
+ function NameServiceComponent() {
103
+ const { data, isLoading } = useNS("ens,vitalik.eth");
104
+
105
+ if (isLoading) return <div>Loading...</div>;
106
+
107
+ return (
108
+ <div>
109
+ <h2>{data?.displayName}</h2>
110
+ <p>Address: {data?.address}</p>
111
+ </div>
112
+ );
113
+ }
114
+ ```
115
+
116
+ #### Universal Name Service Queries
117
+
118
+ ```jsx
119
+ import { useUniversalNS } from 'web3bio-profile-kit';
120
+
121
+ function UniversalNameServiceComponent() {
122
+ // Works with any identity format
123
+ const { data, isLoading } = useUniversalNS("vitalik.eth");
124
+
125
+ if (isLoading) return <div>Loading...</div>;
126
+
127
+ return (
128
+ <div>
129
+ <h2>{data?.displayName}</h2>
130
+ <p>Address: {data?.address}</p>
131
+ </div>
132
+ );
133
+ }
134
+ ```
135
+
136
+ ### Query Domain Data
137
+
138
+ ```jsx
139
+ import { useDomain } from 'web3bio-profile-kit';
140
+
141
+ function DomainComponent() {
142
+ const { data, isLoading } = useDomain("vitalik.eth");
143
+
144
+ if (isLoading) return <div>Loading...</div>;
145
+
146
+ return (
147
+ <div>
148
+ <h2>{data?.identity}</h2>
149
+ <p>Resolved address: {data?.resolvedAddress}</p>
150
+ <p>Owner address: {data?.ownerAddress}</p>
151
+ </div>
152
+ );
153
+ }
154
+ ```
155
+
156
+ ### Batch Profile Query
157
+
158
+ ```jsx
159
+ import { useProfile } from 'web3bio-profile-kit';
160
+
161
+ function BatchProfileComponent() {
162
+ const { data, isLoading } = useProfile([
163
+ "vitalik.eth",
164
+ "lens,stani"
165
+ ]);
166
+
167
+ // You can also use useNS for batch queries
168
+ // const { data, isLoading } = useNS([
169
+ // "vitalik.eth",
170
+ // "lens,stani"
171
+ // ]);
172
+
173
+ if (isLoading) return <div>Loading...</div>;
174
+
175
+ return (
176
+ <div>
177
+ {Array.isArray(data) && data.map(profile => (
178
+ <div key={profile.identity}>
179
+ <h3>{profile.displayName}</h3>
180
+ <p>{profile.description}</p>
181
+ </div>
182
+ ))}
183
+ </div>
184
+ );
185
+ }
186
+ ```
187
+
188
+ ### Advanced Usage: Controlling Query Execution
189
+
190
+ You can control when the query executes using the `enabled` option:
191
+
192
+ ```jsx
193
+ const [searchTerm, setSearchTerm] = useState("");
194
+ const { data, isLoading } = useProfile(searchTerm, {
195
+ enabled: searchTerm.length > 0
196
+ });
197
+ ```
198
+
199
+ ## Supported Identity Formats
200
+
201
+ - ENS domains: `name.eth`
202
+ - Ethereum addresses: `0x123...`
203
+ - Farcaster: `username.farcaster`
204
+ - Lens profiles: `username.lens`
205
+ - And many more!
206
+
207
+ You can also use the explicit format `platform,identity` for clarity:
208
+ - `ens,vitalik.eth`
209
+ - `ethereum,0x123...`
210
+ - `farcaster,dwr.eth`
211
+ - `lens,stani.lens`
212
+
213
+ ## API Reference
214
+
215
+ ### Hooks
216
+
217
+ #### `useProfile(identity, options?)`
218
+
219
+ Fetches comprehensive profile data including social links and avatar.
220
+
221
+ #### `useUniversalProfile(identity, options?)`
222
+
223
+ Fetches comprehensive universal profile data including social links and avatar across multiple platforms.
224
+
225
+ #### `useNS(identity, options?)`
226
+
227
+ Fetches basic name service data (similar to ENS lookups).
228
+
229
+ #### `useUniversalNS(identity, options?)`
230
+
231
+ Fetches basic universal name service data across multiple platforms.
232
+
233
+ #### `useDomain(identity, options?)`
234
+
235
+ Fetches detailed domain information including resolution data.
236
+
237
+ ### Arguments
238
+
239
+ | Parameter | Type | Description |
240
+ |-----------|------|-------------|
241
+ | `identity` | `string` or `string[]` | Identity to query or array of identities for batch queries |
242
+ | `options` | `object` | Optional configuration with `apiKey` and `enabled` |
243
+
244
+ ### Return Values
245
+
246
+ All hooks return an object with:
247
+
248
+ | Property | Type | Description |
249
+ |-----------|------|-------------|
250
+ | `data` | `object` or `null` | The profile data when successful |
251
+ | `isLoading` | `boolean` | `true` during the fetch operation |
252
+ | `error` | `Error` or `null` | Error object if the request failed |
253
+
254
+ ## License
255
+
256
+ MIT
@@ -0,0 +1,6 @@
1
+ export { useProfile } from "./useProfile";
2
+ export { useNS } from "./useNS";
3
+ export { useDomain } from "./useDomain";
4
+ export { useUniversalProfile } from "./useUniversalProfile";
5
+ export { useUniversalNS } from "./useUniversalNS";
6
+ export { useBaseQuery } from "./useBaseQuery";
@@ -0,0 +1,6 @@
1
+ import { QueryEndpoint } from "../utils/constants";
2
+ import { Identity, QueryOptions, QueryResult } from "../utils/types";
3
+ /**
4
+ * Core hook for querying Web3.bio Profile API
5
+ */
6
+ export declare function useBaseQuery<T>(identity: Identity, endpoint: QueryEndpoint, universal?: boolean, options?: QueryOptions): QueryResult<T>;
@@ -0,0 +1,16 @@
1
+ import { DomainQueryResult, Identity, QueryOptions } from "../utils/types";
2
+ /**
3
+ * Hook to query Web3.bio domain data by identity
4
+ *
5
+ * @param identity - Identity string or array of identities to query
6
+ * @param options - Optional configuration options
7
+ * @returns Object containing domain data, loading state, and any errors
8
+ *
9
+ * @example
10
+ * // Query by ENS name
11
+ * const { data, isLoading, error } = useDomain("vitalik.eth");
12
+ *
13
+ * // Query by domain name with platform
14
+ * const { data } = useDomain("ens,vitalik.eth");
15
+ */
16
+ export declare function useDomain(identity: Identity, options?: QueryOptions): DomainQueryResult;
@@ -0,0 +1,16 @@
1
+ import { Identity, NSQueryResult, QueryOptions } from "../utils/types";
2
+ /**
3
+ * Hook to query Web3.bio name service (NS) data by identity
4
+ *
5
+ * @param identity - Identity string or array of identities to query
6
+ * @param options - Optional configuration options
7
+ * @returns Object containing NS data, loading state, and any errors
8
+ *
9
+ * @example
10
+ * // Query by ENS name
11
+ * const { data, isLoading, error } = useNS("vitalik.eth");
12
+ *
13
+ * // Query by Ethereum address
14
+ * const { data } = useNS("0x123...");
15
+ */
16
+ export declare function useNS(identity: Identity, options?: QueryOptions): NSQueryResult;
@@ -0,0 +1,16 @@
1
+ import { Identity, ProfileQueryResult, QueryOptions } from "../utils/types";
2
+ /**
3
+ * Hook to query Web3.bio profile data by identity
4
+ *
5
+ * @param identity - Identity string or array of identities to query
6
+ * @param options - Optional configuration options
7
+ * @returns Object containing profile data, loading state, and any errors
8
+ *
9
+ * @example
10
+ * // Query by ENS name
11
+ * const { data, isLoading, error } = useProfile("vitalik.eth");
12
+ *
13
+ * // Query with platform specification
14
+ * const { data } = useProfile("farcaster,dwr");
15
+ */
16
+ export declare function useProfile(identity: Identity, options?: QueryOptions): ProfileQueryResult;
@@ -0,0 +1,16 @@
1
+ import { Identity, NSQueryResult, QueryOptions } from "../utils/types";
2
+ /**
3
+ * Hook to query Web3.bio name service (NS) data using universal identity lookup
4
+ *
5
+ * @param identity - Identity string or array of identities to query
6
+ * @param options - Optional configuration options
7
+ * @returns Object containing NS data, loading state, and any errors
8
+ *
9
+ * @example
10
+ * // Query by ENS name with universal lookup
11
+ * const { data, isLoading, error } = useUniversalNS("vitalik.eth");
12
+ *
13
+ * // Query by any identity type with universal lookup
14
+ * const { data } = useUniversalNS("dwr.farcaster");
15
+ */
16
+ export declare function useUniversalNS(identity: Identity, options?: QueryOptions): NSQueryResult;
@@ -0,0 +1,16 @@
1
+ import { Identity, ProfileQueryResult, QueryOptions } from "../utils/types";
2
+ /**
3
+ * Hook to query Web3.bio profile data using universal identity lookup
4
+ *
5
+ * @param identity - Identity string or array of identities to query
6
+ * @param options - Optional configuration options
7
+ * @returns Object containing profile data, loading state, and any errors
8
+ *
9
+ * @example
10
+ * // Query by ENS name with universal lookup
11
+ * const { data, isLoading, error } = useUniversalProfile("vitalik.eth");
12
+ *
13
+ * // Query by any identity type with universal lookup
14
+ * const { data } = useUniversalProfile("dwr.farcaster");
15
+ */
16
+ export declare function useUniversalProfile(identity: Identity, options?: QueryOptions): ProfileQueryResult;
@@ -0,0 +1,216 @@
1
+ declare enum PlatformType {
2
+ ens = "ens",
3
+ farcaster = "farcaster",
4
+ lens = "lens",
5
+ ethereum = "ethereum",
6
+ twitter = "twitter",
7
+ github = "github",
8
+ bitcoin = "bitcoin",
9
+ unstoppableDomains = "unstoppabledomains",
10
+ basenames = "basenames",
11
+ linea = "linea",
12
+ space_id = "space_id",
13
+ solana = "solana",
14
+ sns = "sns",
15
+ nextid = "nextid",
16
+ dotbit = "dotbit"
17
+ }
18
+ declare enum SourceType {
19
+ ethereum = "ethereum",
20
+ ens = "ens",
21
+ twitter = "twitter",
22
+ nextid = "nextid",
23
+ dotbit = "dotbit",
24
+ unstoppabledomains = "unstoppabledomains",
25
+ lens = "lens",
26
+ farcaster = "farcaster",
27
+ space_id = "space_id",
28
+ solana = "solana",
29
+ sns = "sns"
30
+ }
31
+ type SocialLinksItem = {
32
+ link: string | null;
33
+ handle: string | null;
34
+ sources: SourceType[];
35
+ };
36
+ type SocialLinks = Record<string, SocialLinksItem>;
37
+ interface ProfileResponse {
38
+ identity: string;
39
+ address: string | null;
40
+ avatar: string | null;
41
+ description: string | null;
42
+ platform: string;
43
+ displayName: string | null;
44
+ email: string | null;
45
+ contenthash: string | null;
46
+ header: string | null;
47
+ location: string | null;
48
+ createdAt: string | null;
49
+ status: string | null;
50
+ error?: string;
51
+ links: SocialLinks;
52
+ social: {
53
+ uid: number | null;
54
+ follower: number;
55
+ following: number;
56
+ } | {};
57
+ }
58
+ interface NSResponse {
59
+ identity: string;
60
+ address: string | null;
61
+ avatar: string | null;
62
+ description: string | null;
63
+ platform: string;
64
+ displayName: string | null;
65
+ }
66
+ interface DomainResponse {
67
+ identity: string;
68
+ platform: PlatformType;
69
+ resolvedAddress: string | null;
70
+ ownerAddress: string | null;
71
+ managerAddress: string | null;
72
+ displayName: string | null;
73
+ isPrimary: boolean;
74
+ status: string;
75
+ createdAt: string | null;
76
+ updatedAt: string | null;
77
+ expiredAt: string | null;
78
+ contenthash: string | null;
79
+ texts: Record<string, string>;
80
+ addresses: Record<string, string>;
81
+ }
82
+ type QueryOptions = {
83
+ /** API Key for authentication */
84
+ apiKey?: string;
85
+ /** Whether the query should execute */
86
+ enabled?: boolean;
87
+ };
88
+ type IdentityString = string | `${PlatformType},${string}`;
89
+ type Identity = IdentityString | IdentityString[];
90
+ type QueryResult<T> = {
91
+ data: T | null;
92
+ isLoading: boolean;
93
+ error: Error | null;
94
+ };
95
+ type ProfileQueryResult = QueryResult<ProfileResponse>;
96
+ type NSQueryResult = QueryResult<NSResponse>;
97
+ type DomainQueryResult = QueryResult<DomainResponse>;
98
+
99
+ /**
100
+ * Hook to query Web3.bio profile data by identity
101
+ *
102
+ * @param identity - Identity string or array of identities to query
103
+ * @param options - Optional configuration options
104
+ * @returns Object containing profile data, loading state, and any errors
105
+ *
106
+ * @example
107
+ * // Query by ENS name
108
+ * const { data, isLoading, error } = useProfile("vitalik.eth");
109
+ *
110
+ * // Query with platform specification
111
+ * const { data } = useProfile("farcaster,dwr");
112
+ */
113
+ declare function useProfile(identity: Identity, options?: QueryOptions): ProfileQueryResult;
114
+
115
+ /**
116
+ * Hook to query Web3.bio name service (NS) data by identity
117
+ *
118
+ * @param identity - Identity string or array of identities to query
119
+ * @param options - Optional configuration options
120
+ * @returns Object containing NS data, loading state, and any errors
121
+ *
122
+ * @example
123
+ * // Query by ENS name
124
+ * const { data, isLoading, error } = useNS("vitalik.eth");
125
+ *
126
+ * // Query by Ethereum address
127
+ * const { data } = useNS("0x123...");
128
+ */
129
+ declare function useNS(identity: Identity, options?: QueryOptions): NSQueryResult;
130
+
131
+ /**
132
+ * Hook to query Web3.bio domain data by identity
133
+ *
134
+ * @param identity - Identity string or array of identities to query
135
+ * @param options - Optional configuration options
136
+ * @returns Object containing domain data, loading state, and any errors
137
+ *
138
+ * @example
139
+ * // Query by ENS name
140
+ * const { data, isLoading, error } = useDomain("vitalik.eth");
141
+ *
142
+ * // Query by domain name with platform
143
+ * const { data } = useDomain("ens,vitalik.eth");
144
+ */
145
+ declare function useDomain(identity: Identity, options?: QueryOptions): DomainQueryResult;
146
+
147
+ /**
148
+ * Hook to query Web3.bio profile data using universal identity lookup
149
+ *
150
+ * @param identity - Identity string or array of identities to query
151
+ * @param options - Optional configuration options
152
+ * @returns Object containing profile data, loading state, and any errors
153
+ *
154
+ * @example
155
+ * // Query by ENS name with universal lookup
156
+ * const { data, isLoading, error } = useUniversalProfile("vitalik.eth");
157
+ *
158
+ * // Query by any identity type with universal lookup
159
+ * const { data } = useUniversalProfile("dwr.farcaster");
160
+ */
161
+ declare function useUniversalProfile(identity: Identity, options?: QueryOptions): ProfileQueryResult;
162
+
163
+ /**
164
+ * Hook to query Web3.bio name service (NS) data using universal identity lookup
165
+ *
166
+ * @param identity - Identity string or array of identities to query
167
+ * @param options - Optional configuration options
168
+ * @returns Object containing NS data, loading state, and any errors
169
+ *
170
+ * @example
171
+ * // Query by ENS name with universal lookup
172
+ * const { data, isLoading, error } = useUniversalNS("vitalik.eth");
173
+ *
174
+ * // Query by any identity type with universal lookup
175
+ * const { data } = useUniversalNS("dwr.farcaster");
176
+ */
177
+ declare function useUniversalNS(identity: Identity, options?: QueryOptions): NSQueryResult;
178
+
179
+ declare const API_ENDPOINT = "https://api.web3.bio";
180
+ declare enum ErrorMessages {
181
+ NOT_FOUND = "Not Found",
182
+ INVALID_RESOLVER = "Invalid Resolver Address",
183
+ INVALID_RESOLVED = "Invalid Resolved Address",
184
+ NOT_EXIST = "Does Not Exist",
185
+ INVALID_IDENTITY = "Invalid Identity or Domain",
186
+ INVALID_ADDRESS = "Invalid Address",
187
+ UNKNOWN_ERROR = "Unknown Error Occurred",
188
+ NETWORK_ERROR = "Network Error"
189
+ }
190
+ declare enum QueryEndpoint {
191
+ NS = "ns",
192
+ PROFILE = "profile",
193
+ DOMAIN = "domain"
194
+ }
195
+ declare const REGEX: {
196
+ ENS: RegExp;
197
+ BASENAMES: RegExp;
198
+ LINEA: RegExp;
199
+ FARCASTER: RegExp;
200
+ LENS: RegExp;
201
+ CLUSTER: RegExp;
202
+ SPACE_ID: RegExp;
203
+ GENOME: RegExp;
204
+ UNSTOPPABLE_DOMAINS: RegExp;
205
+ CROSSBELL: RegExp;
206
+ DOTBIT: RegExp;
207
+ SNS: RegExp;
208
+ ETH_ADDRESS: RegExp;
209
+ BTC_ADDRESS: RegExp;
210
+ SOLANA_ADDRESS: RegExp;
211
+ LOWERCASE_EXEMPT: RegExp;
212
+ TWITTER: RegExp;
213
+ NEXT_ID: RegExp;
214
+ };
215
+
216
+ export { API_ENDPOINT, DomainQueryResult, DomainResponse, ErrorMessages, Identity, IdentityString, NSQueryResult, NSResponse, PlatformType, ProfileQueryResult, ProfileResponse, QueryEndpoint, QueryOptions, QueryResult, REGEX, SocialLinks, SocialLinksItem, SourceType, useDomain, useNS, useProfile, useUniversalNS, useUniversalProfile };