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/dist/index.js ADDED
@@ -0,0 +1,354 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+
7
+ const API_ENDPOINT = "https://api.web3.bio";
8
+ exports.ErrorMessages = void 0;
9
+ (function (ErrorMessages) {
10
+ ErrorMessages["NOT_FOUND"] = "Not Found";
11
+ ErrorMessages["INVALID_RESOLVER"] = "Invalid Resolver Address";
12
+ ErrorMessages["INVALID_RESOLVED"] = "Invalid Resolved Address";
13
+ ErrorMessages["NOT_EXIST"] = "Does Not Exist";
14
+ ErrorMessages["INVALID_IDENTITY"] = "Invalid Identity or Domain";
15
+ ErrorMessages["INVALID_ADDRESS"] = "Invalid Address";
16
+ ErrorMessages["UNKNOWN_ERROR"] = "Unknown Error Occurred";
17
+ ErrorMessages["NETWORK_ERROR"] = "Network Error";
18
+ })(exports.ErrorMessages || (exports.ErrorMessages = {}));
19
+ exports.QueryEndpoint = void 0;
20
+ (function (QueryEndpoint) {
21
+ QueryEndpoint["NS"] = "ns";
22
+ QueryEndpoint["PROFILE"] = "profile";
23
+ QueryEndpoint["DOMAIN"] = "domain";
24
+ })(exports.QueryEndpoint || (exports.QueryEndpoint = {}));
25
+ // Regular expressions for identity detection
26
+ const REGEX = {
27
+ ENS: /^.+\.(eth|xyz|bio|app|luxe|kred|art|ceo|club|box)$/i,
28
+ BASENAMES: /^.+\.base(\.eth)?$/i,
29
+ LINEA: /^.+\.linea(\.eth)?$/i,
30
+ FARCASTER: /^(?:[A-Za-z0-9_-]{1,61}(?:(?:\.eth)?(?:\.farcaster|\.fcast\.id|\.farcaster\.eth)?)?|farcaster,#\d+)$/i,
31
+ LENS: /^(?:.+\.lens)$/i,
32
+ CLUSTER: /^[\w-]+\/[\w-]+$/,
33
+ SPACE_ID: /^.+\.(bnb|arb)$/i,
34
+ GENOME: /^.+\.gno$/i,
35
+ UNSTOPPABLE_DOMAINS: /^.+\.(crypto|888|nft|blockchain|bitcoin|dao|x|klever|hi|zil|kresus|polygon|wallet|binanceus|anime|go|manga|eth)$/i,
36
+ CROSSBELL: /^.+\.csb$/i,
37
+ DOTBIT: /^.+\.bit$/i,
38
+ SNS: /^.+\.sol$/i,
39
+ ETH_ADDRESS: /^0x[a-fA-F0-9]{40}$/i,
40
+ BTC_ADDRESS: /\b([13][a-km-zA-HJ-NP-Z1-9]{25,34}|bc1[qp][a-z0-9]{11,71})\b/,
41
+ SOLANA_ADDRESS: /^[1-9A-HJ-NP-Za-km-z]{32,44}$/,
42
+ LOWERCASE_EXEMPT: /\b(?:(?:[13][a-km-zA-HJ-NP-Z1-9]{25,34}|bc1[qp][a-z0-9]{11,71})|(?:[1-9A-HJ-NP-Za-km-z]{32,44}))\b/,
43
+ TWITTER: /^[A-Za-z0-9_]{1,15}(?:\.twitter)?$/i,
44
+ NEXT_ID: /^0x[a-f0-9]{66}(?:\.nextid)?$/i,
45
+ };
46
+
47
+ exports.PlatformType = void 0;
48
+ (function (PlatformType) {
49
+ PlatformType["ens"] = "ens";
50
+ PlatformType["farcaster"] = "farcaster";
51
+ PlatformType["lens"] = "lens";
52
+ PlatformType["ethereum"] = "ethereum";
53
+ PlatformType["twitter"] = "twitter";
54
+ PlatformType["github"] = "github";
55
+ PlatformType["bitcoin"] = "bitcoin";
56
+ PlatformType["unstoppableDomains"] = "unstoppabledomains";
57
+ PlatformType["basenames"] = "basenames";
58
+ PlatformType["linea"] = "linea";
59
+ PlatformType["space_id"] = "space_id";
60
+ PlatformType["solana"] = "solana";
61
+ PlatformType["sns"] = "sns";
62
+ PlatformType["nextid"] = "nextid";
63
+ PlatformType["dotbit"] = "dotbit";
64
+ })(exports.PlatformType || (exports.PlatformType = {}));
65
+ exports.SourceType = void 0;
66
+ (function (SourceType) {
67
+ SourceType["ethereum"] = "ethereum";
68
+ SourceType["ens"] = "ens";
69
+ SourceType["twitter"] = "twitter";
70
+ SourceType["nextid"] = "nextid";
71
+ SourceType["dotbit"] = "dotbit";
72
+ SourceType["unstoppabledomains"] = "unstoppabledomains";
73
+ SourceType["lens"] = "lens";
74
+ SourceType["farcaster"] = "farcaster";
75
+ SourceType["space_id"] = "space_id";
76
+ SourceType["solana"] = "solana";
77
+ SourceType["sns"] = "sns";
78
+ })(exports.SourceType || (exports.SourceType = {}));
79
+
80
+ /**
81
+ * Resolves an identity string to a platform and identifier
82
+ * @param input The identity to resolve
83
+ * @returns A formatted identity string or null if invalid
84
+ */
85
+ const resolveIdentity = (input) => {
86
+ if (!input)
87
+ return null;
88
+ const parts = input.split(",");
89
+ let platform;
90
+ let identity;
91
+ if (parts.length === 2) {
92
+ // Format is already "platform,identity"
93
+ platform = parts[0];
94
+ identity = prettify(parts[1]);
95
+ }
96
+ else if (parts.length === 1) {
97
+ // Auto-detect platform from the identity string
98
+ platform = detectPlatform(input);
99
+ identity = prettify(input);
100
+ }
101
+ else {
102
+ return null;
103
+ }
104
+ if (!isSupportedPlatform(platform) || !identity)
105
+ return null;
106
+ // Normalize case except for case-sensitive identities
107
+ const normalizedIdentity = REGEX.LOWERCASE_EXEMPT.test(identity)
108
+ ? identity
109
+ : identity.toLowerCase();
110
+ return `${platform},${normalizedIdentity}`;
111
+ };
112
+ /**
113
+ * Clean up and standardize identity format
114
+ */
115
+ const prettify = (input) => {
116
+ if (!input)
117
+ return "";
118
+ if (input.endsWith(".twitter"))
119
+ return input.replace(".twitter", "");
120
+ if (input.endsWith(".nextid"))
121
+ return input.replace(".nextid", "");
122
+ if (input.startsWith("farcaster,#"))
123
+ return input.replace(/^(farcaster),/, "");
124
+ if (input.endsWith(".farcaster") ||
125
+ input.endsWith(".fcast.id") ||
126
+ input.endsWith(".farcaster.eth")) {
127
+ return input.replace(/(\.farcaster|\.fcast\.id|\.farcaster\.eth)$/, "");
128
+ }
129
+ if (input.endsWith(".base") || input.endsWith(".linea")) {
130
+ return input.split(".")[0] + "." + input.split(".").pop() + ".eth";
131
+ }
132
+ return input;
133
+ };
134
+ /**
135
+ * Check if the platform is supported for API queries
136
+ */
137
+ const isSupportedPlatform = (platform) => {
138
+ if (!platform)
139
+ return false;
140
+ return Object.values(exports.PlatformType).includes(platform);
141
+ };
142
+ /**
143
+ * Detect platform from identity string based on regex patterns
144
+ */
145
+ const detectPlatform = (term) => {
146
+ if (term.endsWith(".farcaster.eth"))
147
+ return exports.PlatformType.farcaster;
148
+ const platformMap = [
149
+ [REGEX.BASENAMES, exports.PlatformType.basenames],
150
+ [REGEX.LINEA, exports.PlatformType.linea],
151
+ [REGEX.ENS, exports.PlatformType.ens],
152
+ [REGEX.ETH_ADDRESS, exports.PlatformType.ethereum],
153
+ [REGEX.LENS, exports.PlatformType.lens],
154
+ [REGEX.UNSTOPPABLE_DOMAINS, exports.PlatformType.unstoppableDomains],
155
+ [REGEX.SPACE_ID, exports.PlatformType.space_id],
156
+ [REGEX.DOTBIT, exports.PlatformType.dotbit],
157
+ [REGEX.SNS, exports.PlatformType.sns],
158
+ [REGEX.BTC_ADDRESS, exports.PlatformType.bitcoin],
159
+ [REGEX.SOLANA_ADDRESS, exports.PlatformType.solana],
160
+ [REGEX.FARCASTER, exports.PlatformType.farcaster],
161
+ [REGEX.TWITTER, exports.PlatformType.twitter],
162
+ [REGEX.NEXT_ID, exports.PlatformType.nextid],
163
+ ];
164
+ for (const [regex, platformType] of platformMap) {
165
+ if (regex.test(term)) {
166
+ return platformType;
167
+ }
168
+ }
169
+ // Default fallback
170
+ return term.includes(".") ? exports.PlatformType.ens : exports.PlatformType.farcaster;
171
+ };
172
+ /**
173
+ * Get API key from various environment sources or user provided value
174
+ */
175
+ const getApiKey = (userProvidedKey) => {
176
+ return (userProvidedKey ||
177
+ process.env.WEB3BIO_API_KEY ||
178
+ process.env.REACT_APP_WEB3BIO_API_KEY ||
179
+ process.env.NEXT_PUBLIC_WEB3BIO_API_KEY ||
180
+ process.env.VITE_WEB3BIO_API_KEY);
181
+ };
182
+
183
+ /**
184
+ * Constructs the API URL based on query parameters
185
+ */
186
+ const buildApiUrl = (identity, endpoint, universal) => {
187
+ // Handle batch queries (array of identities)
188
+ if (Array.isArray(identity)) {
189
+ return `${API_ENDPOINT}/${endpoint}/batch/${JSON.stringify(identity)}`;
190
+ }
191
+ // Handle single identity query
192
+ if (universal) {
193
+ return `${API_ENDPOINT}/${endpoint}/${identity}`;
194
+ }
195
+ else {
196
+ const resolvedId = resolveIdentity(identity);
197
+ if (!resolvedId)
198
+ return null;
199
+ const [platform, handle] = resolvedId.split(",");
200
+ return `${API_ENDPOINT}/${endpoint}/${platform}/${handle}`;
201
+ }
202
+ };
203
+ /**
204
+ * Core hook for querying Web3.bio Profile API
205
+ */
206
+ function useBaseQuery(identity, endpoint, universal = false, options = {}) {
207
+ const { apiKey: userApiKey, enabled = true } = options;
208
+ const apiKey = getApiKey(userApiKey);
209
+ const [data, setData] = react.useState(null);
210
+ const [isLoading, setIsLoading] = react.useState(false);
211
+ const [error, setError] = react.useState(null);
212
+ react.useEffect(() => {
213
+ // Don't run the query if disabled or no identity
214
+ if (!enabled || !identity)
215
+ return;
216
+ const controller = new AbortController();
217
+ setIsLoading(true);
218
+ setError(null);
219
+ const fetchData = async () => {
220
+ try {
221
+ const url = buildApiUrl(identity, endpoint, universal);
222
+ if (!url) {
223
+ throw new Error(exports.ErrorMessages.INVALID_IDENTITY);
224
+ }
225
+ const headers = apiKey ? { "x-api-key": apiKey } : {};
226
+ const response = await fetch(url, {
227
+ method: "GET",
228
+ headers,
229
+ signal: controller.signal,
230
+ });
231
+ if (!response.ok) {
232
+ throw new Error(`API error: ${response.status}`);
233
+ }
234
+ const responseData = await response.json();
235
+ if (responseData === null || responseData === void 0 ? void 0 : responseData.error) {
236
+ throw new Error(responseData.error);
237
+ }
238
+ setData(responseData);
239
+ }
240
+ catch (err) {
241
+ if (err instanceof Error && err.name === "AbortError")
242
+ return;
243
+ setError(err instanceof Error ? err : new Error(String(err)));
244
+ }
245
+ finally {
246
+ setIsLoading(false);
247
+ }
248
+ };
249
+ fetchData();
250
+ return () => {
251
+ controller.abort();
252
+ };
253
+ }, [identity, apiKey, enabled, endpoint, universal]);
254
+ return { data, isLoading, error };
255
+ }
256
+
257
+ /**
258
+ * Hook to query Web3.bio profile data by identity
259
+ *
260
+ * @param identity - Identity string or array of identities to query
261
+ * @param options - Optional configuration options
262
+ * @returns Object containing profile data, loading state, and any errors
263
+ *
264
+ * @example
265
+ * // Query by ENS name
266
+ * const { data, isLoading, error } = useProfile("vitalik.eth");
267
+ *
268
+ * // Query with platform specification
269
+ * const { data } = useProfile("farcaster,dwr");
270
+ */
271
+ function useProfile(identity, options = {}) {
272
+ return useBaseQuery(identity, exports.QueryEndpoint.PROFILE, false, options);
273
+ }
274
+
275
+ /**
276
+ * Hook to query Web3.bio name service (NS) data by identity
277
+ *
278
+ * @param identity - Identity string or array of identities to query
279
+ * @param options - Optional configuration options
280
+ * @returns Object containing NS data, loading state, and any errors
281
+ *
282
+ * @example
283
+ * // Query by ENS name
284
+ * const { data, isLoading, error } = useNS("vitalik.eth");
285
+ *
286
+ * // Query by Ethereum address
287
+ * const { data } = useNS("0x123...");
288
+ */
289
+ function useNS(identity, options = {}) {
290
+ return useBaseQuery(identity, exports.QueryEndpoint.NS, false, options);
291
+ }
292
+
293
+ /**
294
+ * Hook to query Web3.bio domain data by identity
295
+ *
296
+ * @param identity - Identity string or array of identities to query
297
+ * @param options - Optional configuration options
298
+ * @returns Object containing domain data, loading state, and any errors
299
+ *
300
+ * @example
301
+ * // Query by ENS name
302
+ * const { data, isLoading, error } = useDomain("vitalik.eth");
303
+ *
304
+ * // Query by domain name with platform
305
+ * const { data } = useDomain("ens,vitalik.eth");
306
+ */
307
+ function useDomain(identity, options = {}) {
308
+ return useBaseQuery(identity, exports.QueryEndpoint.DOMAIN, false, options);
309
+ }
310
+
311
+ /**
312
+ * Hook to query Web3.bio profile data using universal identity lookup
313
+ *
314
+ * @param identity - Identity string or array of identities to query
315
+ * @param options - Optional configuration options
316
+ * @returns Object containing profile data, loading state, and any errors
317
+ *
318
+ * @example
319
+ * // Query by ENS name with universal lookup
320
+ * const { data, isLoading, error } = useUniversalProfile("vitalik.eth");
321
+ *
322
+ * // Query by any identity type with universal lookup
323
+ * const { data } = useUniversalProfile("dwr.farcaster");
324
+ */
325
+ function useUniversalProfile(identity, options = {}) {
326
+ return useBaseQuery(identity, exports.QueryEndpoint.PROFILE, true, options);
327
+ }
328
+
329
+ /**
330
+ * Hook to query Web3.bio name service (NS) data using universal identity lookup
331
+ *
332
+ * @param identity - Identity string or array of identities to query
333
+ * @param options - Optional configuration options
334
+ * @returns Object containing NS data, loading state, and any errors
335
+ *
336
+ * @example
337
+ * // Query by ENS name with universal lookup
338
+ * const { data, isLoading, error } = useUniversalNS("vitalik.eth");
339
+ *
340
+ * // Query by any identity type with universal lookup
341
+ * const { data } = useUniversalNS("dwr.farcaster");
342
+ */
343
+ function useUniversalNS(identity, options = {}) {
344
+ return useBaseQuery(identity, exports.QueryEndpoint.NS, true, options);
345
+ }
346
+
347
+ exports.API_ENDPOINT = API_ENDPOINT;
348
+ exports.REGEX = REGEX;
349
+ exports.useDomain = useDomain;
350
+ exports.useNS = useNS;
351
+ exports.useProfile = useProfile;
352
+ exports.useUniversalNS = useUniversalNS;
353
+ exports.useUniversalProfile = useUniversalProfile;
354
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/utils/constants.ts","../src/utils/types.ts","../src/utils/helpers.ts","../src/hooks/useBaseQuery.ts","../src/hooks/useProfile.ts","../src/hooks/useNS.ts","../src/hooks/useDomain.ts","../src/hooks/useUniversalProfile.ts","../src/hooks/useUniversalNS.ts"],"sourcesContent":["export const API_ENDPOINT = \"https://api.web3.bio\";\n\nexport enum ErrorMessages {\n NOT_FOUND = \"Not Found\",\n INVALID_RESOLVER = \"Invalid Resolver Address\",\n INVALID_RESOLVED = \"Invalid Resolved Address\",\n NOT_EXIST = \"Does Not Exist\",\n INVALID_IDENTITY = \"Invalid Identity or Domain\",\n INVALID_ADDRESS = \"Invalid Address\",\n UNKNOWN_ERROR = \"Unknown Error Occurred\",\n NETWORK_ERROR = \"Network Error\",\n}\n\nexport enum QueryEndpoint {\n NS = \"ns\",\n PROFILE = \"profile\",\n DOMAIN = \"domain\",\n}\n\n// Regular expressions for identity detection\nexport const REGEX = {\n ENS: /^.+\\.(eth|xyz|bio|app|luxe|kred|art|ceo|club|box)$/i,\n BASENAMES: /^.+\\.base(\\.eth)?$/i,\n LINEA: /^.+\\.linea(\\.eth)?$/i,\n FARCASTER: /^(?:[A-Za-z0-9_-]{1,61}(?:(?:\\.eth)?(?:\\.farcaster|\\.fcast\\.id|\\.farcaster\\.eth)?)?|farcaster,#\\d+)$/i,\n LENS: /^(?:.+\\.lens)$/i,\n CLUSTER: /^[\\w-]+\\/[\\w-]+$/,\n SPACE_ID: /^.+\\.(bnb|arb)$/i,\n GENOME: /^.+\\.gno$/i,\n UNSTOPPABLE_DOMAINS: /^.+\\.(crypto|888|nft|blockchain|bitcoin|dao|x|klever|hi|zil|kresus|polygon|wallet|binanceus|anime|go|manga|eth)$/i,\n CROSSBELL: /^.+\\.csb$/i,\n DOTBIT: /^.+\\.bit$/i,\n SNS: /^.+\\.sol$/i,\n ETH_ADDRESS: /^0x[a-fA-F0-9]{40}$/i,\n BTC_ADDRESS: /\\b([13][a-km-zA-HJ-NP-Z1-9]{25,34}|bc1[qp][a-z0-9]{11,71})\\b/,\n SOLANA_ADDRESS: /^[1-9A-HJ-NP-Za-km-z]{32,44}$/,\n LOWERCASE_EXEMPT: /\\b(?:(?:[13][a-km-zA-HJ-NP-Z1-9]{25,34}|bc1[qp][a-z0-9]{11,71})|(?:[1-9A-HJ-NP-Za-km-z]{32,44}))\\b/,\n TWITTER: /^[A-Za-z0-9_]{1,15}(?:\\.twitter)?$/i,\n NEXT_ID: /^0x[a-f0-9]{66}(?:\\.nextid)?$/i,\n};","export enum PlatformType {\n ens = \"ens\",\n farcaster = \"farcaster\",\n lens = \"lens\",\n ethereum = \"ethereum\",\n twitter = \"twitter\",\n github = \"github\",\n bitcoin = \"bitcoin\",\n unstoppableDomains = \"unstoppabledomains\",\n basenames = \"basenames\",\n linea = \"linea\",\n space_id = \"space_id\",\n solana = \"solana\",\n sns = \"sns\",\n nextid = \"nextid\",\n dotbit = \"dotbit\",\n}\n\nexport enum SourceType {\n ethereum = \"ethereum\",\n ens = \"ens\",\n twitter = \"twitter\",\n nextid = \"nextid\",\n dotbit = \"dotbit\",\n unstoppabledomains = \"unstoppabledomains\",\n lens = \"lens\",\n farcaster = \"farcaster\",\n space_id = \"space_id\",\n solana = \"solana\",\n sns = \"sns\",\n}\n\nexport type SocialLinksItem = {\n link: string | null;\n handle: string | null;\n sources: SourceType[];\n};\n\nexport type SocialLinks = Record<string, SocialLinksItem>;\n\nexport interface ProfileResponse {\n identity: string;\n address: string | null;\n avatar: string | null;\n description: string | null;\n platform: string;\n displayName: string | null;\n email: string | null;\n contenthash: string | null;\n header: string | null;\n location: string | null;\n createdAt: string | null;\n status: string | null;\n error?: string;\n links: SocialLinks;\n social:\n | {\n uid: number | null;\n follower: number;\n following: number;\n }\n | {};\n}\n\nexport interface NSResponse {\n identity: string;\n address: string | null;\n avatar: string | null;\n description: string | null;\n platform: string;\n displayName: string | null;\n}\n\nexport interface DomainResponse {\n identity: string;\n platform: PlatformType;\n resolvedAddress: string | null;\n ownerAddress: string | null;\n managerAddress: string | null;\n displayName: string | null;\n isPrimary: boolean;\n status: string;\n createdAt: string | null;\n updatedAt: string | null;\n expiredAt: string | null;\n contenthash: string | null;\n texts: Record<string, string>;\n addresses: Record<string, string>;\n}\n\nexport type QueryOptions = {\n /** API Key for authentication */\n apiKey?: string;\n /** Whether the query should execute */\n enabled?: boolean;\n};\n\nexport type IdentityString = string | `${PlatformType},${string}`;\nexport type Identity = IdentityString | IdentityString[];\n\nexport type QueryResult<T> = {\n data: T | null;\n isLoading: boolean;\n error: Error | null;\n};\n\n// Query-specific result types for better type safety\nexport type ProfileQueryResult = QueryResult<ProfileResponse>;\nexport type NSQueryResult = QueryResult<NSResponse>;\nexport type DomainQueryResult = QueryResult<DomainResponse>;\n","import { REGEX } from \"./constants\";\nimport { PlatformType, Identity } from \"./types\";\n\n/**\n * Resolves an identity string to a platform and identifier\n * @param input The identity to resolve\n * @returns A formatted identity string or null if invalid\n */\nexport const resolveIdentity = (input: string): string | null => {\n if (!input) return null;\n\n const parts = input.split(\",\");\n\n let platform: PlatformType;\n let identity: string;\n\n if (parts.length === 2) {\n // Format is already \"platform,identity\"\n platform = parts[0] as PlatformType;\n identity = prettify(parts[1]);\n } else if (parts.length === 1) {\n // Auto-detect platform from the identity string\n platform = detectPlatform(input);\n identity = prettify(input);\n } else {\n return null;\n }\n\n if (!isSupportedPlatform(platform) || !identity) return null;\n\n // Normalize case except for case-sensitive identities\n const normalizedIdentity = REGEX.LOWERCASE_EXEMPT.test(identity)\n ? identity\n : identity.toLowerCase();\n\n return `${platform},${normalizedIdentity}`;\n};\n\n/**\n * Clean up and standardize identity format\n */\nexport const prettify = (input: string): string => {\n if (!input) return \"\";\n if (input.endsWith(\".twitter\")) return input.replace(\".twitter\", \"\");\n if (input.endsWith(\".nextid\")) return input.replace(\".nextid\", \"\");\n if (input.startsWith(\"farcaster,#\"))\n return input.replace(/^(farcaster),/, \"\");\n if (\n input.endsWith(\".farcaster\") ||\n input.endsWith(\".fcast.id\") ||\n input.endsWith(\".farcaster.eth\")\n ) {\n return input.replace(/(\\.farcaster|\\.fcast\\.id|\\.farcaster\\.eth)$/, \"\");\n }\n if (input.endsWith(\".base\") || input.endsWith(\".linea\")) {\n return input.split(\".\")[0] + \".\" + input.split(\".\").pop() + \".eth\";\n }\n return input;\n};\n\n/**\n * Check if the platform is supported for API queries\n */\nexport const isSupportedPlatform = (\n platform?: PlatformType | null,\n): boolean => {\n if (!platform) return false;\n return Object.values(PlatformType).includes(platform as PlatformType);\n};\n\n/**\n * Detect platform from identity string based on regex patterns\n */\nexport const detectPlatform = (term: string): PlatformType => {\n if (term.endsWith(\".farcaster.eth\")) return PlatformType.farcaster;\n\n const platformMap: [RegExp, PlatformType][] = [\n [REGEX.BASENAMES, PlatformType.basenames],\n [REGEX.LINEA, PlatformType.linea],\n [REGEX.ENS, PlatformType.ens],\n [REGEX.ETH_ADDRESS, PlatformType.ethereum],\n [REGEX.LENS, PlatformType.lens],\n [REGEX.UNSTOPPABLE_DOMAINS, PlatformType.unstoppableDomains],\n [REGEX.SPACE_ID, PlatformType.space_id],\n [REGEX.DOTBIT, PlatformType.dotbit],\n [REGEX.SNS, PlatformType.sns],\n [REGEX.BTC_ADDRESS, PlatformType.bitcoin],\n [REGEX.SOLANA_ADDRESS, PlatformType.solana],\n [REGEX.FARCASTER, PlatformType.farcaster],\n [REGEX.TWITTER, PlatformType.twitter],\n [REGEX.NEXT_ID, PlatformType.nextid],\n ];\n\n for (const [regex, platformType] of platformMap) {\n if (regex.test(term)) {\n return platformType;\n }\n }\n\n // Default fallback\n return term.includes(\".\") ? PlatformType.ens : PlatformType.farcaster;\n};\n\n/**\n * Get API key from various environment sources or user provided value\n */\nexport const getApiKey = (userProvidedKey?: string): string | undefined => {\n return (\n userProvidedKey ||\n process.env.WEB3BIO_API_KEY ||\n process.env.REACT_APP_WEB3BIO_API_KEY ||\n process.env.NEXT_PUBLIC_WEB3BIO_API_KEY ||\n process.env.VITE_WEB3BIO_API_KEY\n );\n};\n","import { useState, useEffect } from \"react\";\nimport { API_ENDPOINT, ErrorMessages, QueryEndpoint } from \"../utils/constants\";\nimport { getApiKey, resolveIdentity } from \"../utils/helpers\";\nimport { Identity, QueryOptions, QueryResult } from \"../utils/types\";\n\n/**\n * Constructs the API URL based on query parameters\n */\nconst buildApiUrl = (\n identity: Identity,\n endpoint: QueryEndpoint,\n universal: boolean,\n): string | null => {\n // Handle batch queries (array of identities)\n if (Array.isArray(identity)) {\n return `${API_ENDPOINT}/${endpoint}/batch/${JSON.stringify(identity)}`;\n }\n\n // Handle single identity query\n if (universal) {\n return `${API_ENDPOINT}/${endpoint}/${identity}`;\n } else {\n const resolvedId = resolveIdentity(identity);\n if (!resolvedId) return null;\n\n const [platform, handle] = resolvedId.split(\",\");\n return `${API_ENDPOINT}/${endpoint}/${platform}/${handle}`;\n }\n};\n\n/**\n * Core hook for querying Web3.bio Profile API\n */\nexport function useBaseQuery<T>(\n identity: Identity,\n endpoint: QueryEndpoint,\n universal: boolean = false,\n options: QueryOptions = {},\n): QueryResult<T> {\n const { apiKey: userApiKey, enabled = true } = options;\n const apiKey = getApiKey(userApiKey);\n\n const [data, setData] = useState<T | null>(null);\n const [isLoading, setIsLoading] = useState<boolean>(false);\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n // Don't run the query if disabled or no identity\n if (!enabled || !identity) return;\n\n const controller = new AbortController();\n setIsLoading(true);\n setError(null);\n\n const fetchData = async () => {\n try {\n const url = buildApiUrl(identity, endpoint, universal);\n\n if (!url) {\n throw new Error(ErrorMessages.INVALID_IDENTITY);\n }\n\n const headers: HeadersInit = apiKey ? { \"x-api-key\": apiKey } : {};\n\n const response = await fetch(url, {\n method: \"GET\",\n headers,\n signal: controller.signal,\n });\n\n if (!response.ok) {\n throw new Error(`API error: ${response.status}`);\n }\n\n const responseData = await response.json();\n\n if (responseData?.error) {\n throw new Error(responseData.error);\n }\n\n setData(responseData as T);\n } catch (err) {\n if (err instanceof Error && err.name === \"AbortError\") return;\n setError(err instanceof Error ? err : new Error(String(err)));\n } finally {\n setIsLoading(false);\n }\n };\n\n fetchData();\n\n return () => {\n controller.abort();\n };\n }, [identity, apiKey, enabled, endpoint, universal]);\n\n return { data, isLoading, error };\n}\n","import { QueryEndpoint } from \"../utils/constants\";\nimport { Identity, ProfileQueryResult, ProfileResponse, QueryOptions } from \"../utils/types\";\nimport { useBaseQuery } from \"./useBaseQuery\";\n\n/**\n * Hook to query Web3.bio profile data by identity\n * \n * @param identity - Identity string or array of identities to query\n * @param options - Optional configuration options\n * @returns Object containing profile data, loading state, and any errors\n * \n * @example\n * // Query by ENS name\n * const { data, isLoading, error } = useProfile(\"vitalik.eth\");\n * \n * // Query with platform specification\n * const { data } = useProfile(\"farcaster,dwr\");\n */\nexport function useProfile(\n identity: Identity,\n options: QueryOptions = {}\n): ProfileQueryResult {\n return useBaseQuery<ProfileResponse>(identity, QueryEndpoint.PROFILE, false, options);\n}","import { QueryEndpoint } from \"../utils/constants\";\nimport { Identity, NSResponse, NSQueryResult, QueryOptions } from \"../utils/types\";\nimport { useBaseQuery } from \"./useBaseQuery\";\n\n/**\n * Hook to query Web3.bio name service (NS) data by identity\n * \n * @param identity - Identity string or array of identities to query\n * @param options - Optional configuration options\n * @returns Object containing NS data, loading state, and any errors\n * \n * @example\n * // Query by ENS name\n * const { data, isLoading, error } = useNS(\"vitalik.eth\");\n * \n * // Query by Ethereum address\n * const { data } = useNS(\"0x123...\");\n */\nexport function useNS(\n identity: Identity,\n options: QueryOptions = {}\n): NSQueryResult {\n return useBaseQuery<NSResponse>(identity, QueryEndpoint.NS, false, options);\n}","import { QueryEndpoint } from \"../utils/constants\";\nimport { DomainQueryResult, DomainResponse, Identity, QueryOptions } from \"../utils/types\";\nimport { useBaseQuery } from \"./useBaseQuery\";\n\n/**\n * Hook to query Web3.bio domain data by identity\n * \n * @param identity - Identity string or array of identities to query\n * @param options - Optional configuration options\n * @returns Object containing domain data, loading state, and any errors\n * \n * @example\n * // Query by ENS name\n * const { data, isLoading, error } = useDomain(\"vitalik.eth\");\n * \n * // Query by domain name with platform\n * const { data } = useDomain(\"ens,vitalik.eth\");\n */\nexport function useDomain(\n identity: Identity,\n options: QueryOptions = {}\n): DomainQueryResult {\n return useBaseQuery<DomainResponse>(identity, QueryEndpoint.DOMAIN, false, options);\n}","import { QueryEndpoint } from \"../utils/constants\";\nimport { Identity, ProfileQueryResult, ProfileResponse, QueryOptions } from \"../utils/types\";\nimport { useBaseQuery } from \"./useBaseQuery\";\n\n/**\n * Hook to query Web3.bio profile data using universal identity lookup\n * \n * @param identity - Identity string or array of identities to query\n * @param options - Optional configuration options\n * @returns Object containing profile data, loading state, and any errors\n * \n * @example\n * // Query by ENS name with universal lookup\n * const { data, isLoading, error } = useUniversalProfile(\"vitalik.eth\");\n * \n * // Query by any identity type with universal lookup\n * const { data } = useUniversalProfile(\"dwr.farcaster\");\n */\nexport function useUniversalProfile(\n identity: Identity,\n options: QueryOptions = {}\n): ProfileQueryResult {\n return useBaseQuery<ProfileResponse>(identity, QueryEndpoint.PROFILE, true, options);\n}","import { QueryEndpoint } from \"../utils/constants\";\nimport { Identity, NSResponse, NSQueryResult, QueryOptions } from \"../utils/types\";\nimport { useBaseQuery } from \"./useBaseQuery\";\n\n/**\n * Hook to query Web3.bio name service (NS) data using universal identity lookup\n * \n * @param identity - Identity string or array of identities to query\n * @param options - Optional configuration options\n * @returns Object containing NS data, loading state, and any errors\n * \n * @example\n * // Query by ENS name with universal lookup\n * const { data, isLoading, error } = useUniversalNS(\"vitalik.eth\");\n * \n * // Query by any identity type with universal lookup\n * const { data } = useUniversalNS(\"dwr.farcaster\");\n */\nexport function useUniversalNS(\n identity: Identity,\n options: QueryOptions = {}\n): NSQueryResult {\n return useBaseQuery<NSResponse>(identity, QueryEndpoint.NS, true, options);\n}"],"names":["ErrorMessages","QueryEndpoint","PlatformType","SourceType","useState","useEffect"],"mappings":";;;;;;AAAO,MAAM,YAAY,GAAG,uBAAuB;AAEvCA,+BASX;AATD,CAAA,UAAY,aAAa,EAAA;AACvB,IAAA,aAAA,CAAA,WAAA,CAAA,GAAA,WAAuB,CAAA;AACvB,IAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,0BAA6C,CAAA;AAC7C,IAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,0BAA6C,CAAA;AAC7C,IAAA,aAAA,CAAA,WAAA,CAAA,GAAA,gBAA4B,CAAA;AAC5B,IAAA,aAAA,CAAA,kBAAA,CAAA,GA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AA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACpC;;AC7FA;;;;;;;;;;;;;AAaG;SACa,UAAU,CACxB,QAAkB,EAClB,UAAwB,EAAE,EAAA;AAE1B,IAAA,OAAO,YAAY,CAAkB,QAAQ,EAAEC,qBAAa,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACxF;;ACnBA;;;;;;;;;;;;;AAaG;SACa,KAAK,CACnB,QAAkB,EAClB,UAAwB,EAAE,EAAA;AAE1B,IAAA,OAAO,YAAY,CAAa,QAAQ,EAAEA,qBAAa,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAC9E;;ACnBA;;;;;;;;;;;;;AAaG;SACa,SAAS,CACvB,QAAkB,EAClB,UAAwB,EAAE,EAAA;AAE1B,IAAA,OAAO,YAAY,CAAiB,QAAQ,EAAEA,qBAAa,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACtF;;ACnBA;;;;;;;;;;;;;AAaG;SACa,mBAAmB,CACjC,QAAkB,EAClB,UAAwB,EAAE,EAAA;AAE1B,IAAA,OAAO,YAAY,CAAkB,QAAQ,EAAEA,qBAAa,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACvF;;ACnBA;;;;;;;;;;;;;AAaG;SACa,cAAc,CAC5B,QAAkB,EAClB,UAAwB,EAAE,EAAA;AAE1B,IAAA,OAAO,YAAY,CAAa,QAAQ,EAAEA,qBAAa,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7E;;;;;;;;;;"}
@@ -0,0 +1 @@
1
+ import "@testing-library/jest-dom";
@@ -0,0 +1,36 @@
1
+ export declare const API_ENDPOINT = "https://api.web3.bio";
2
+ export declare enum ErrorMessages {
3
+ NOT_FOUND = "Not Found",
4
+ INVALID_RESOLVER = "Invalid Resolver Address",
5
+ INVALID_RESOLVED = "Invalid Resolved Address",
6
+ NOT_EXIST = "Does Not Exist",
7
+ INVALID_IDENTITY = "Invalid Identity or Domain",
8
+ INVALID_ADDRESS = "Invalid Address",
9
+ UNKNOWN_ERROR = "Unknown Error Occurred",
10
+ NETWORK_ERROR = "Network Error"
11
+ }
12
+ export declare enum QueryEndpoint {
13
+ NS = "ns",
14
+ PROFILE = "profile",
15
+ DOMAIN = "domain"
16
+ }
17
+ export declare const REGEX: {
18
+ ENS: RegExp;
19
+ BASENAMES: RegExp;
20
+ LINEA: RegExp;
21
+ FARCASTER: RegExp;
22
+ LENS: RegExp;
23
+ CLUSTER: RegExp;
24
+ SPACE_ID: RegExp;
25
+ GENOME: RegExp;
26
+ UNSTOPPABLE_DOMAINS: RegExp;
27
+ CROSSBELL: RegExp;
28
+ DOTBIT: RegExp;
29
+ SNS: RegExp;
30
+ ETH_ADDRESS: RegExp;
31
+ BTC_ADDRESS: RegExp;
32
+ SOLANA_ADDRESS: RegExp;
33
+ LOWERCASE_EXEMPT: RegExp;
34
+ TWITTER: RegExp;
35
+ NEXT_ID: RegExp;
36
+ };
@@ -0,0 +1,23 @@
1
+ import { PlatformType } from "./types";
2
+ /**
3
+ * Resolves an identity string to a platform and identifier
4
+ * @param input The identity to resolve
5
+ * @returns A formatted identity string or null if invalid
6
+ */
7
+ export declare const resolveIdentity: (input: string) => string | null;
8
+ /**
9
+ * Clean up and standardize identity format
10
+ */
11
+ export declare const prettify: (input: string) => string;
12
+ /**
13
+ * Check if the platform is supported for API queries
14
+ */
15
+ export declare const isSupportedPlatform: (platform?: PlatformType | null) => boolean;
16
+ /**
17
+ * Detect platform from identity string based on regex patterns
18
+ */
19
+ export declare const detectPlatform: (term: string) => PlatformType;
20
+ /**
21
+ * Get API key from various environment sources or user provided value
22
+ */
23
+ export declare const getApiKey: (userProvidedKey?: string) => string | undefined;
@@ -0,0 +1,97 @@
1
+ export 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
+ export 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
+ export type SocialLinksItem = {
32
+ link: string | null;
33
+ handle: string | null;
34
+ sources: SourceType[];
35
+ };
36
+ export type SocialLinks = Record<string, SocialLinksItem>;
37
+ export 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
+ export 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
+ export 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
+ export type QueryOptions = {
83
+ /** API Key for authentication */
84
+ apiKey?: string;
85
+ /** Whether the query should execute */
86
+ enabled?: boolean;
87
+ };
88
+ export type IdentityString = string | `${PlatformType},${string}`;
89
+ export type Identity = IdentityString | IdentityString[];
90
+ export type QueryResult<T> = {
91
+ data: T | null;
92
+ isLoading: boolean;
93
+ error: Error | null;
94
+ };
95
+ export type ProfileQueryResult = QueryResult<ProfileResponse>;
96
+ export type NSQueryResult = QueryResult<NSResponse>;
97
+ export type DomainQueryResult = QueryResult<DomainResponse>;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "web3bio-profile-kit",
3
+ "version": "0.1.0",
4
+ "description": "React hooks for querying Web3.bio profiles",
5
+ "author": "web3bio",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.esm.js",
10
+ "types": "dist/index.d.ts",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "sideEffects": false,
15
+ "keywords": [
16
+ "web3",
17
+ "profile",
18
+ "react",
19
+ "hooks",
20
+ "web3bio",
21
+ "ens",
22
+ "farcaster",
23
+ "lens"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/web3bio/web3bio-profile-kit"
28
+ },
29
+ "homepage": "https://github.com/web3bio/web3bio-profile-kit#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/web3bio/web3bio-profile-kit/issues"
32
+ },
33
+ "scripts": {
34
+ "build": "rimraf dist && rollup -c",
35
+ "test": "react-scripts test",
36
+ "prepublishOnly": "npm run build"
37
+ },
38
+ "peerDependencies": {
39
+ "react": ">=16.8.0",
40
+ "react-dom": ">=16.8.0"
41
+ },
42
+ "devDependencies": {
43
+ "@rollup/plugin-commonjs": "^25.0.0",
44
+ "@rollup/plugin-node-resolve": "^15.0.0",
45
+ "@rollup/plugin-typescript": "^11.0.0",
46
+ "@testing-library/react": "^14.0.0",
47
+ "@types/react": "^18.0.0",
48
+ "react": "^18.2.0",
49
+ "react-dom": "^18.2.0",
50
+ "rimraf": "^5.0.5",
51
+ "rollup": "^3.25.0",
52
+ "rollup-plugin-dts": "^5.3.0",
53
+ "rollup-plugin-peer-deps-external": "^2.2.4",
54
+ "typescript": "^5.0.0"
55
+ }
56
+ }