web3bio-profile-kit 0.1.33 → 0.1.35
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/hooks/useBaseQuery.cjs +4 -4
- package/dist/hooks/useBaseQuery.js +5 -5
- package/dist/types/platform.cjs +1 -0
- package/dist/types/platform.d.ts +1 -0
- package/dist/types/platform.js +1 -0
- package/dist/utils/helpers.cjs +48 -40
- package/dist/utils/helpers.d.ts +1 -2
- package/dist/utils/helpers.js +46 -38
- package/dist/utils/index.cjs +6 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/ipfs.cjs +65 -0
- package/dist/utils/ipfs.d.ts +3 -0
- package/dist/utils/ipfs.js +61 -0
- package/dist/utils/platform.cjs +9 -0
- package/dist/utils/platform.js +9 -0
- package/dist/utils/resolver.cjs +23 -0
- package/dist/utils/resolver.d.ts +1 -0
- package/dist/utils/resolver.js +21 -0
- package/package.json +1 -1
|
@@ -14,19 +14,19 @@ var helpers = require('../utils/helpers.cjs');
|
|
|
14
14
|
*/
|
|
15
15
|
const buildApiUrl = (identity, endpoint, universal) => {
|
|
16
16
|
if (Array.isArray(identity)) {
|
|
17
|
-
return `${helpers.
|
|
17
|
+
return `${helpers.PROFILE_API_ENDPOINT}/${endpoint}/batch/${encodeURIComponent(JSON.stringify(identity))}`;
|
|
18
18
|
}
|
|
19
19
|
if (universal) {
|
|
20
|
-
return `${helpers.
|
|
20
|
+
return `${helpers.PROFILE_API_ENDPOINT}/${endpoint}/${identity}`;
|
|
21
21
|
}
|
|
22
22
|
const resolvedId = helpers.resolveIdentity(identity);
|
|
23
23
|
if (!resolvedId)
|
|
24
24
|
return null;
|
|
25
25
|
if ([hook.QueryEndpoint.DOMAIN, hook.QueryEndpoint.CREDENTIAL].includes(endpoint)) {
|
|
26
|
-
return `${helpers.
|
|
26
|
+
return `${helpers.PROFILE_API_ENDPOINT}/${endpoint}/${resolvedId}`;
|
|
27
27
|
}
|
|
28
28
|
const [platform, handle] = resolvedId.split(",");
|
|
29
|
-
return `${helpers.
|
|
29
|
+
return `${helpers.PROFILE_API_ENDPOINT}/${endpoint}/${platform}/${handle}`;
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
32
|
* Core hook for querying Web3.bio Profile API with React Query
|
|
@@ -5,26 +5,26 @@ import '../types/source.js';
|
|
|
5
5
|
import '../types/cointype.js';
|
|
6
6
|
import '../types/credential.js';
|
|
7
7
|
import { useQuery } from '@tanstack/react-query';
|
|
8
|
-
import { getApiKey,
|
|
8
|
+
import { getApiKey, PROFILE_API_ENDPOINT, resolveIdentity } from '../utils/helpers.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Constructs the API URL based on query parameters
|
|
12
12
|
*/
|
|
13
13
|
const buildApiUrl = (identity, endpoint, universal) => {
|
|
14
14
|
if (Array.isArray(identity)) {
|
|
15
|
-
return `${
|
|
15
|
+
return `${PROFILE_API_ENDPOINT}/${endpoint}/batch/${encodeURIComponent(JSON.stringify(identity))}`;
|
|
16
16
|
}
|
|
17
17
|
if (universal) {
|
|
18
|
-
return `${
|
|
18
|
+
return `${PROFILE_API_ENDPOINT}/${endpoint}/${identity}`;
|
|
19
19
|
}
|
|
20
20
|
const resolvedId = resolveIdentity(identity);
|
|
21
21
|
if (!resolvedId)
|
|
22
22
|
return null;
|
|
23
23
|
if ([QueryEndpoint.DOMAIN, QueryEndpoint.CREDENTIAL].includes(endpoint)) {
|
|
24
|
-
return `${
|
|
24
|
+
return `${PROFILE_API_ENDPOINT}/${endpoint}/${resolvedId}`;
|
|
25
25
|
}
|
|
26
26
|
const [platform, handle] = resolvedId.split(",");
|
|
27
|
-
return `${
|
|
27
|
+
return `${PROFILE_API_ENDPOINT}/${endpoint}/${platform}/${handle}`;
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* Core hook for querying Web3.bio Profile API with React Query
|
package/dist/types/platform.cjs
CHANGED
|
@@ -73,6 +73,7 @@ exports.Platform = void 0;
|
|
|
73
73
|
Platform["nextid"] = "nextid";
|
|
74
74
|
Platform["nostr"] = "nostr";
|
|
75
75
|
Platform["opensea"] = "opensea";
|
|
76
|
+
Platform["opinion"] = "opinion";
|
|
76
77
|
Platform["paragraph"] = "paragraph";
|
|
77
78
|
Platform["philand"] = "philand";
|
|
78
79
|
Platform["poap"] = "poap";
|
package/dist/types/platform.d.ts
CHANGED
package/dist/types/platform.js
CHANGED
package/dist/utils/helpers.cjs
CHANGED
|
@@ -9,8 +9,8 @@ require('../types/credential.cjs');
|
|
|
9
9
|
var platform$1 = require('./platform.cjs');
|
|
10
10
|
var regex = require('./regex.cjs');
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
const WEB2_SUFFIXES = [
|
|
12
|
+
const PROFILE_API_ENDPOINT = "https://api.web3.bio";
|
|
13
|
+
const WEB2_SUFFIXES = new Set([
|
|
14
14
|
platform.Platform.twitter,
|
|
15
15
|
platform.Platform.nextid,
|
|
16
16
|
platform.Platform.keybase,
|
|
@@ -22,7 +22,7 @@ const WEB2_SUFFIXES = [
|
|
|
22
22
|
platform.Platform.nostr,
|
|
23
23
|
platform.Platform.bluesky,
|
|
24
24
|
platform.Platform.telegram,
|
|
25
|
-
];
|
|
25
|
+
]);
|
|
26
26
|
/**
|
|
27
27
|
* Resolves an identity string to a platform and identifier
|
|
28
28
|
* @param input The identity to resolve
|
|
@@ -69,12 +69,16 @@ const prettify = (input) => {
|
|
|
69
69
|
return input.replace(/(\.farcaster|\.fcast\.id|\.farcaster\.eth)$/, "");
|
|
70
70
|
}
|
|
71
71
|
if (input.endsWith(".base") || input.endsWith(".linea")) {
|
|
72
|
-
|
|
72
|
+
const parts = input.split(".");
|
|
73
|
+
return `${parts[0]}.${parts[parts.length - 1]}.eth`;
|
|
73
74
|
}
|
|
74
75
|
// for all web2 platform prettify format as "identity.platform"
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
|
|
76
|
+
const lastDotIndex = input.lastIndexOf(".");
|
|
77
|
+
if (lastDotIndex !== -1) {
|
|
78
|
+
const suffix = input.slice(lastDotIndex + 1);
|
|
79
|
+
if (WEB2_SUFFIXES.has(suffix)) {
|
|
80
|
+
return input.slice(0, lastDotIndex);
|
|
81
|
+
}
|
|
78
82
|
}
|
|
79
83
|
return input;
|
|
80
84
|
};
|
|
@@ -109,36 +113,37 @@ const uglify = (input, platform$1) => {
|
|
|
109
113
|
return input;
|
|
110
114
|
}
|
|
111
115
|
};
|
|
116
|
+
const SUPPORTED_PLATFORMS = new Set([
|
|
117
|
+
platform.Platform.ens,
|
|
118
|
+
platform.Platform.basenames,
|
|
119
|
+
platform.Platform.linea,
|
|
120
|
+
platform.Platform.ethereum,
|
|
121
|
+
platform.Platform.farcaster,
|
|
122
|
+
platform.Platform.lens,
|
|
123
|
+
platform.Platform.twitter,
|
|
124
|
+
platform.Platform.github,
|
|
125
|
+
platform.Platform.discord,
|
|
126
|
+
platform.Platform.linkedin,
|
|
127
|
+
platform.Platform.instagram,
|
|
128
|
+
platform.Platform.reddit,
|
|
129
|
+
platform.Platform.facebook,
|
|
130
|
+
platform.Platform.telegram,
|
|
131
|
+
platform.Platform.keybase,
|
|
132
|
+
platform.Platform.nostr,
|
|
133
|
+
platform.Platform.bluesky,
|
|
134
|
+
platform.Platform.unstoppableDomains,
|
|
135
|
+
platform.Platform.nextid,
|
|
136
|
+
platform.Platform.dotbit,
|
|
137
|
+
platform.Platform.solana,
|
|
138
|
+
platform.Platform.sns,
|
|
139
|
+
]);
|
|
112
140
|
/**
|
|
113
141
|
* Check if the platform is supported for API queries
|
|
114
142
|
*/
|
|
115
|
-
const isSupportedPlatform = (platform
|
|
116
|
-
if (!platform
|
|
143
|
+
const isSupportedPlatform = (platform) => {
|
|
144
|
+
if (!platform)
|
|
117
145
|
return false;
|
|
118
|
-
return
|
|
119
|
-
platform.Platform.ens,
|
|
120
|
-
platform.Platform.basenames,
|
|
121
|
-
platform.Platform.linea,
|
|
122
|
-
platform.Platform.ethereum,
|
|
123
|
-
platform.Platform.farcaster,
|
|
124
|
-
platform.Platform.lens,
|
|
125
|
-
platform.Platform.twitter,
|
|
126
|
-
platform.Platform.github,
|
|
127
|
-
platform.Platform.discord,
|
|
128
|
-
platform.Platform.linkedin,
|
|
129
|
-
platform.Platform.instagram,
|
|
130
|
-
platform.Platform.reddit,
|
|
131
|
-
platform.Platform.facebook,
|
|
132
|
-
platform.Platform.telegram,
|
|
133
|
-
platform.Platform.keybase,
|
|
134
|
-
platform.Platform.nostr,
|
|
135
|
-
platform.Platform.bluesky,
|
|
136
|
-
platform.Platform.unstoppableDomains,
|
|
137
|
-
platform.Platform.nextid,
|
|
138
|
-
platform.Platform.dotbit,
|
|
139
|
-
platform.Platform.solana,
|
|
140
|
-
platform.Platform.sns,
|
|
141
|
-
].includes(platform$1);
|
|
146
|
+
return SUPPORTED_PLATFORMS.has(platform);
|
|
142
147
|
};
|
|
143
148
|
const platformMap = new Map([
|
|
144
149
|
[regex.REGEX.BASENAMES, platform.Platform.basenames],
|
|
@@ -164,9 +169,12 @@ const platformMap = new Map([
|
|
|
164
169
|
*/
|
|
165
170
|
const detectPlatform = (term) => {
|
|
166
171
|
// support all web2 platform as identity.platform format
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
|
|
172
|
+
const lastDotIndex = term.lastIndexOf(".");
|
|
173
|
+
if (lastDotIndex !== -1) {
|
|
174
|
+
const suffix = term.slice(lastDotIndex + 1);
|
|
175
|
+
if (platform$1.PLATFORM_DATA.has(suffix))
|
|
176
|
+
return suffix;
|
|
177
|
+
}
|
|
170
178
|
if (/\.(farcaster\.eth|farcaster|fcast\.id)$/.test(term))
|
|
171
179
|
return platform.Platform.farcaster;
|
|
172
180
|
for (const [regex, Platform] of platformMap) {
|
|
@@ -228,7 +236,7 @@ const isWeb3Address = (address) => {
|
|
|
228
236
|
const isValidEthereumAddress = (address) => {
|
|
229
237
|
if (!regex.REGEX.ETH_ADDRESS.test(address))
|
|
230
238
|
return false; // invalid ethereum address
|
|
231
|
-
if (
|
|
239
|
+
if (/^0x0*.$|^0x[123468abef]*$|^0x0*dead$/i.test(address))
|
|
232
240
|
return false; // empty & burn address
|
|
233
241
|
return true;
|
|
234
242
|
};
|
|
@@ -256,14 +264,14 @@ const idToJson = (input) => {
|
|
|
256
264
|
const id = resolveIdentity(input);
|
|
257
265
|
if (!id)
|
|
258
266
|
return null;
|
|
259
|
-
const [_platform,
|
|
267
|
+
const [_platform, _identity] = id.split(",");
|
|
260
268
|
return {
|
|
261
269
|
platform: _platform,
|
|
262
|
-
identity:
|
|
270
|
+
identity: _identity,
|
|
263
271
|
};
|
|
264
272
|
};
|
|
265
273
|
|
|
266
|
-
exports.
|
|
274
|
+
exports.PROFILE_API_ENDPOINT = PROFILE_API_ENDPOINT;
|
|
267
275
|
exports.detectPlatform = detectPlatform;
|
|
268
276
|
exports.getApiKey = getApiKey;
|
|
269
277
|
exports.idToJson = idToJson;
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Platform } from "../types";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const STAGING_API_ENDPOINT = "https://api-staging.web3.bio";
|
|
2
|
+
export declare const PROFILE_API_ENDPOINT = "https://api.web3.bio";
|
|
4
3
|
/**
|
|
5
4
|
* Resolves an identity string to a platform and identifier
|
|
6
5
|
* @param input The identity to resolve
|
package/dist/utils/helpers.js
CHANGED
|
@@ -7,8 +7,8 @@ import '../types/credential.js';
|
|
|
7
7
|
import { PLATFORM_DATA } from './platform.js';
|
|
8
8
|
import { REGEX } from './regex.js';
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
const WEB2_SUFFIXES = [
|
|
10
|
+
const PROFILE_API_ENDPOINT = "https://api.web3.bio";
|
|
11
|
+
const WEB2_SUFFIXES = new Set([
|
|
12
12
|
Platform.twitter,
|
|
13
13
|
Platform.nextid,
|
|
14
14
|
Platform.keybase,
|
|
@@ -20,7 +20,7 @@ const WEB2_SUFFIXES = [
|
|
|
20
20
|
Platform.nostr,
|
|
21
21
|
Platform.bluesky,
|
|
22
22
|
Platform.telegram,
|
|
23
|
-
];
|
|
23
|
+
]);
|
|
24
24
|
/**
|
|
25
25
|
* Resolves an identity string to a platform and identifier
|
|
26
26
|
* @param input The identity to resolve
|
|
@@ -67,12 +67,16 @@ const prettify = (input) => {
|
|
|
67
67
|
return input.replace(/(\.farcaster|\.fcast\.id|\.farcaster\.eth)$/, "");
|
|
68
68
|
}
|
|
69
69
|
if (input.endsWith(".base") || input.endsWith(".linea")) {
|
|
70
|
-
|
|
70
|
+
const parts = input.split(".");
|
|
71
|
+
return `${parts[0]}.${parts[parts.length - 1]}.eth`;
|
|
71
72
|
}
|
|
72
73
|
// for all web2 platform prettify format as "identity.platform"
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
|
|
74
|
+
const lastDotIndex = input.lastIndexOf(".");
|
|
75
|
+
if (lastDotIndex !== -1) {
|
|
76
|
+
const suffix = input.slice(lastDotIndex + 1);
|
|
77
|
+
if (WEB2_SUFFIXES.has(suffix)) {
|
|
78
|
+
return input.slice(0, lastDotIndex);
|
|
79
|
+
}
|
|
76
80
|
}
|
|
77
81
|
return input;
|
|
78
82
|
};
|
|
@@ -107,36 +111,37 @@ const uglify = (input, platform) => {
|
|
|
107
111
|
return input;
|
|
108
112
|
}
|
|
109
113
|
};
|
|
114
|
+
const SUPPORTED_PLATFORMS = new Set([
|
|
115
|
+
Platform.ens,
|
|
116
|
+
Platform.basenames,
|
|
117
|
+
Platform.linea,
|
|
118
|
+
Platform.ethereum,
|
|
119
|
+
Platform.farcaster,
|
|
120
|
+
Platform.lens,
|
|
121
|
+
Platform.twitter,
|
|
122
|
+
Platform.github,
|
|
123
|
+
Platform.discord,
|
|
124
|
+
Platform.linkedin,
|
|
125
|
+
Platform.instagram,
|
|
126
|
+
Platform.reddit,
|
|
127
|
+
Platform.facebook,
|
|
128
|
+
Platform.telegram,
|
|
129
|
+
Platform.keybase,
|
|
130
|
+
Platform.nostr,
|
|
131
|
+
Platform.bluesky,
|
|
132
|
+
Platform.unstoppableDomains,
|
|
133
|
+
Platform.nextid,
|
|
134
|
+
Platform.dotbit,
|
|
135
|
+
Platform.solana,
|
|
136
|
+
Platform.sns,
|
|
137
|
+
]);
|
|
110
138
|
/**
|
|
111
139
|
* Check if the platform is supported for API queries
|
|
112
140
|
*/
|
|
113
141
|
const isSupportedPlatform = (platform) => {
|
|
114
142
|
if (!platform)
|
|
115
143
|
return false;
|
|
116
|
-
return
|
|
117
|
-
Platform.ens,
|
|
118
|
-
Platform.basenames,
|
|
119
|
-
Platform.linea,
|
|
120
|
-
Platform.ethereum,
|
|
121
|
-
Platform.farcaster,
|
|
122
|
-
Platform.lens,
|
|
123
|
-
Platform.twitter,
|
|
124
|
-
Platform.github,
|
|
125
|
-
Platform.discord,
|
|
126
|
-
Platform.linkedin,
|
|
127
|
-
Platform.instagram,
|
|
128
|
-
Platform.reddit,
|
|
129
|
-
Platform.facebook,
|
|
130
|
-
Platform.telegram,
|
|
131
|
-
Platform.keybase,
|
|
132
|
-
Platform.nostr,
|
|
133
|
-
Platform.bluesky,
|
|
134
|
-
Platform.unstoppableDomains,
|
|
135
|
-
Platform.nextid,
|
|
136
|
-
Platform.dotbit,
|
|
137
|
-
Platform.solana,
|
|
138
|
-
Platform.sns,
|
|
139
|
-
].includes(platform);
|
|
144
|
+
return SUPPORTED_PLATFORMS.has(platform);
|
|
140
145
|
};
|
|
141
146
|
const platformMap = new Map([
|
|
142
147
|
[REGEX.BASENAMES, Platform.basenames],
|
|
@@ -162,9 +167,12 @@ const platformMap = new Map([
|
|
|
162
167
|
*/
|
|
163
168
|
const detectPlatform = (term) => {
|
|
164
169
|
// support all web2 platform as identity.platform format
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
|
|
170
|
+
const lastDotIndex = term.lastIndexOf(".");
|
|
171
|
+
if (lastDotIndex !== -1) {
|
|
172
|
+
const suffix = term.slice(lastDotIndex + 1);
|
|
173
|
+
if (PLATFORM_DATA.has(suffix))
|
|
174
|
+
return suffix;
|
|
175
|
+
}
|
|
168
176
|
if (/\.(farcaster\.eth|farcaster|fcast\.id)$/.test(term))
|
|
169
177
|
return Platform.farcaster;
|
|
170
178
|
for (const [regex, Platform] of platformMap) {
|
|
@@ -226,7 +234,7 @@ const isWeb3Address = (address) => {
|
|
|
226
234
|
const isValidEthereumAddress = (address) => {
|
|
227
235
|
if (!REGEX.ETH_ADDRESS.test(address))
|
|
228
236
|
return false; // invalid ethereum address
|
|
229
|
-
if (
|
|
237
|
+
if (/^0x0*.$|^0x[123468abef]*$|^0x0*dead$/i.test(address))
|
|
230
238
|
return false; // empty & burn address
|
|
231
239
|
return true;
|
|
232
240
|
};
|
|
@@ -254,11 +262,11 @@ const idToJson = (input) => {
|
|
|
254
262
|
const id = resolveIdentity(input);
|
|
255
263
|
if (!id)
|
|
256
264
|
return null;
|
|
257
|
-
const [_platform,
|
|
265
|
+
const [_platform, _identity] = id.split(",");
|
|
258
266
|
return {
|
|
259
267
|
platform: _platform,
|
|
260
|
-
identity:
|
|
268
|
+
identity: _identity,
|
|
261
269
|
};
|
|
262
270
|
};
|
|
263
271
|
|
|
264
|
-
export {
|
|
272
|
+
export { PROFILE_API_ENDPOINT, detectPlatform, getApiKey, idToJson, isSameAddress, isSupportedPlatform, isValidEthereumAddress, isValidSolanaAddress, isWeb3Address, prettify, resolveIdentity, uglify };
|
package/dist/utils/index.cjs
CHANGED
|
@@ -6,6 +6,8 @@ var platform = require('./platform.cjs');
|
|
|
6
6
|
var network = require('./network.cjs');
|
|
7
7
|
var source = require('./source.cjs');
|
|
8
8
|
var helpers = require('./helpers.cjs');
|
|
9
|
+
var ipfs = require('./ipfs.cjs');
|
|
10
|
+
var resolver = require('./resolver.cjs');
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
|
|
@@ -31,3 +33,7 @@ exports.isWeb3Address = helpers.isWeb3Address;
|
|
|
31
33
|
exports.prettify = helpers.prettify;
|
|
32
34
|
exports.resolveIdentity = helpers.resolveIdentity;
|
|
33
35
|
exports.uglify = helpers.uglify;
|
|
36
|
+
exports.isIPFS = ipfs.isIPFS;
|
|
37
|
+
exports.resolveIPFS_CID = ipfs.resolveIPFS_CID;
|
|
38
|
+
exports.resolveIPFS_URL = ipfs.resolveIPFS_URL;
|
|
39
|
+
exports.resolveMediaURL = resolver.resolveMediaURL;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export { DEFAULT_PLATFORM, PLATFORM_DATA, getPlatform } from "./platform";
|
|
|
4
4
|
export { NETWORK_DATA, getNetwork } from "./network";
|
|
5
5
|
export { SOURCE_DATA, getSource } from "./source";
|
|
6
6
|
export { resolveIdentity, idToJson, prettify, uglify, isSupportedPlatform, detectPlatform, isSameAddress, isWeb3Address, isValidEthereumAddress, isValidSolanaAddress, } from "./helpers";
|
|
7
|
+
export { isIPFS, resolveIPFS_URL, resolveIPFS_CID } from "./ipfs";
|
|
8
|
+
export { resolveMediaURL } from "./resolver";
|
package/dist/utils/index.js
CHANGED
|
@@ -4,3 +4,5 @@ export { DEFAULT_PLATFORM, PLATFORM_DATA, getPlatform } from './platform.js';
|
|
|
4
4
|
export { NETWORK_DATA, getNetwork } from './network.js';
|
|
5
5
|
export { SOURCE_DATA, getSource } from './source.js';
|
|
6
6
|
export { detectPlatform, idToJson, isSameAddress, isSupportedPlatform, isValidEthereumAddress, isValidSolanaAddress, isWeb3Address, prettify, resolveIdentity, uglify } from './helpers.js';
|
|
7
|
+
export { isIPFS, resolveIPFS_CID, resolveIPFS_URL } from './ipfs.js';
|
|
8
|
+
export { resolveMediaURL } from './resolver.js';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const IPFS_CID_PATTERN = "Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[2-7A-Za-z]{58,}|B[2-7A-Z]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[\\dA-F]{50,}";
|
|
4
|
+
const CORS_HOST = "https://cors-next.r2d2.to";
|
|
5
|
+
const CF_IPFS_HOST = "https://cloudflare-ipfs.com";
|
|
6
|
+
const IPFS_GATEWAY_HOST = "https://ipfs.io";
|
|
7
|
+
const MATCH_IPFS_DATA_RE = /ipfs\/(data:.*)$/;
|
|
8
|
+
const MATCH_IPFS_CID_RE = new RegExp(IPFS_CID_PATTERN);
|
|
9
|
+
const MATCH_IPFS_CID_AT_STARTS_RE = new RegExp(`^https://(?:${IPFS_CID_PATTERN})`);
|
|
10
|
+
const MATCH_IPFS_CID_AND_PATHNAME_RE = new RegExp(`(?:${IPFS_CID_PATTERN})(?:/.*)?`);
|
|
11
|
+
const CORS_HOST_RE = new RegExp(`^(?:${CORS_HOST}|${CF_IPFS_HOST})\\??`);
|
|
12
|
+
const resolveIPFS_CID = (str) => { var _a; return (_a = str.match(MATCH_IPFS_CID_RE)) === null || _a === void 0 ? void 0 : _a[0]; };
|
|
13
|
+
const isIPFS = (str) => MATCH_IPFS_CID_RE.test(str);
|
|
14
|
+
function resolveIPFS_URL(cidOrURL) {
|
|
15
|
+
if (!cidOrURL)
|
|
16
|
+
return cidOrURL;
|
|
17
|
+
// Normalize input by trimming and decoding
|
|
18
|
+
const queryIndex = cidOrURL.indexOf("?");
|
|
19
|
+
let normalizedURL = decodeURIComponent(queryIndex !== -1 ? cidOrURL.slice(0, queryIndex) : cidOrURL);
|
|
20
|
+
// Handle CORS proxies first
|
|
21
|
+
if (normalizedURL.startsWith(CORS_HOST) ||
|
|
22
|
+
normalizedURL.startsWith(CF_IPFS_HOST)) {
|
|
23
|
+
normalizedURL = normalizedURL.replace(CORS_HOST_RE, "");
|
|
24
|
+
// Continue processing the URL without the proxy prefix
|
|
25
|
+
}
|
|
26
|
+
// Handle ipfs.io URLs
|
|
27
|
+
if (normalizedURL.startsWith("https://ipfs.io")) {
|
|
28
|
+
const dataMatch = normalizedURL.match(MATCH_IPFS_DATA_RE);
|
|
29
|
+
if (dataMatch === null || dataMatch === void 0 ? void 0 : dataMatch[1]) {
|
|
30
|
+
return decodeURIComponent(dataMatch[1]);
|
|
31
|
+
}
|
|
32
|
+
return normalizedURL;
|
|
33
|
+
}
|
|
34
|
+
// Handle ipfs protocol and CIDs
|
|
35
|
+
if (normalizedURL.includes("ipfs:") || isIPFS(normalizedURL)) {
|
|
36
|
+
// Convert ipfs:// protocol to CID format
|
|
37
|
+
if (normalizedURL.startsWith("ipfs://")) {
|
|
38
|
+
normalizedURL = normalizedURL.slice(7);
|
|
39
|
+
}
|
|
40
|
+
// Handle URLs that start with a CID
|
|
41
|
+
if (MATCH_IPFS_CID_AT_STARTS_RE.test(normalizedURL)) {
|
|
42
|
+
try {
|
|
43
|
+
const url = new URL(normalizedURL);
|
|
44
|
+
const cid = resolveIPFS_CID(normalizedURL);
|
|
45
|
+
if (cid) {
|
|
46
|
+
const path = url.pathname === "/" ? "" : url.pathname;
|
|
47
|
+
return `${IPFS_GATEWAY_HOST}/ipfs/${cid}${path}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.debug("Failed to parse URL with CID", { normalizedURL, error });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Handle bare CIDs or CIDs with paths
|
|
55
|
+
const pathMatch = normalizedURL.match(MATCH_IPFS_CID_AND_PATHNAME_RE);
|
|
56
|
+
if (pathMatch === null || pathMatch === void 0 ? void 0 : pathMatch[0]) {
|
|
57
|
+
return `${IPFS_GATEWAY_HOST}/ipfs/${pathMatch[0]}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return normalizedURL;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.isIPFS = isIPFS;
|
|
64
|
+
exports.resolveIPFS_CID = resolveIPFS_CID;
|
|
65
|
+
exports.resolveIPFS_URL = resolveIPFS_URL;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const IPFS_CID_PATTERN = "Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[2-7A-Za-z]{58,}|B[2-7A-Z]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[\\dA-F]{50,}";
|
|
2
|
+
const CORS_HOST = "https://cors-next.r2d2.to";
|
|
3
|
+
const CF_IPFS_HOST = "https://cloudflare-ipfs.com";
|
|
4
|
+
const IPFS_GATEWAY_HOST = "https://ipfs.io";
|
|
5
|
+
const MATCH_IPFS_DATA_RE = /ipfs\/(data:.*)$/;
|
|
6
|
+
const MATCH_IPFS_CID_RE = new RegExp(IPFS_CID_PATTERN);
|
|
7
|
+
const MATCH_IPFS_CID_AT_STARTS_RE = new RegExp(`^https://(?:${IPFS_CID_PATTERN})`);
|
|
8
|
+
const MATCH_IPFS_CID_AND_PATHNAME_RE = new RegExp(`(?:${IPFS_CID_PATTERN})(?:/.*)?`);
|
|
9
|
+
const CORS_HOST_RE = new RegExp(`^(?:${CORS_HOST}|${CF_IPFS_HOST})\\??`);
|
|
10
|
+
const resolveIPFS_CID = (str) => { var _a; return (_a = str.match(MATCH_IPFS_CID_RE)) === null || _a === void 0 ? void 0 : _a[0]; };
|
|
11
|
+
const isIPFS = (str) => MATCH_IPFS_CID_RE.test(str);
|
|
12
|
+
function resolveIPFS_URL(cidOrURL) {
|
|
13
|
+
if (!cidOrURL)
|
|
14
|
+
return cidOrURL;
|
|
15
|
+
// Normalize input by trimming and decoding
|
|
16
|
+
const queryIndex = cidOrURL.indexOf("?");
|
|
17
|
+
let normalizedURL = decodeURIComponent(queryIndex !== -1 ? cidOrURL.slice(0, queryIndex) : cidOrURL);
|
|
18
|
+
// Handle CORS proxies first
|
|
19
|
+
if (normalizedURL.startsWith(CORS_HOST) ||
|
|
20
|
+
normalizedURL.startsWith(CF_IPFS_HOST)) {
|
|
21
|
+
normalizedURL = normalizedURL.replace(CORS_HOST_RE, "");
|
|
22
|
+
// Continue processing the URL without the proxy prefix
|
|
23
|
+
}
|
|
24
|
+
// Handle ipfs.io URLs
|
|
25
|
+
if (normalizedURL.startsWith("https://ipfs.io")) {
|
|
26
|
+
const dataMatch = normalizedURL.match(MATCH_IPFS_DATA_RE);
|
|
27
|
+
if (dataMatch === null || dataMatch === void 0 ? void 0 : dataMatch[1]) {
|
|
28
|
+
return decodeURIComponent(dataMatch[1]);
|
|
29
|
+
}
|
|
30
|
+
return normalizedURL;
|
|
31
|
+
}
|
|
32
|
+
// Handle ipfs protocol and CIDs
|
|
33
|
+
if (normalizedURL.includes("ipfs:") || isIPFS(normalizedURL)) {
|
|
34
|
+
// Convert ipfs:// protocol to CID format
|
|
35
|
+
if (normalizedURL.startsWith("ipfs://")) {
|
|
36
|
+
normalizedURL = normalizedURL.slice(7);
|
|
37
|
+
}
|
|
38
|
+
// Handle URLs that start with a CID
|
|
39
|
+
if (MATCH_IPFS_CID_AT_STARTS_RE.test(normalizedURL)) {
|
|
40
|
+
try {
|
|
41
|
+
const url = new URL(normalizedURL);
|
|
42
|
+
const cid = resolveIPFS_CID(normalizedURL);
|
|
43
|
+
if (cid) {
|
|
44
|
+
const path = url.pathname === "/" ? "" : url.pathname;
|
|
45
|
+
return `${IPFS_GATEWAY_HOST}/ipfs/${cid}${path}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.debug("Failed to parse URL with CID", { normalizedURL, error });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Handle bare CIDs or CIDs with paths
|
|
53
|
+
const pathMatch = normalizedURL.match(MATCH_IPFS_CID_AND_PATHNAME_RE);
|
|
54
|
+
if (pathMatch === null || pathMatch === void 0 ? void 0 : pathMatch[0]) {
|
|
55
|
+
return `${IPFS_GATEWAY_HOST}/ipfs/${pathMatch[0]}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return normalizedURL;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { isIPFS, resolveIPFS_CID, resolveIPFS_URL };
|
package/dist/utils/platform.cjs
CHANGED
|
@@ -649,6 +649,15 @@ const PLATFORM_DATA = new Map([
|
|
|
649
649
|
urlPrefix: "https://opensea.io/",
|
|
650
650
|
},
|
|
651
651
|
],
|
|
652
|
+
[
|
|
653
|
+
platform.Platform.opinion,
|
|
654
|
+
{
|
|
655
|
+
color: "#ed6432",
|
|
656
|
+
icon: "icons/icon-opinion.svg",
|
|
657
|
+
label: "Opinion",
|
|
658
|
+
urlPrefix: "https://app.opinion.trade/",
|
|
659
|
+
},
|
|
660
|
+
],
|
|
652
661
|
[
|
|
653
662
|
platform.Platform.paragraph,
|
|
654
663
|
{
|
package/dist/utils/platform.js
CHANGED
|
@@ -647,6 +647,15 @@ const PLATFORM_DATA = new Map([
|
|
|
647
647
|
urlPrefix: "https://opensea.io/",
|
|
648
648
|
},
|
|
649
649
|
],
|
|
650
|
+
[
|
|
651
|
+
Platform.opinion,
|
|
652
|
+
{
|
|
653
|
+
color: "#ed6432",
|
|
654
|
+
icon: "icons/icon-opinion.svg",
|
|
655
|
+
label: "Opinion",
|
|
656
|
+
urlPrefix: "https://app.opinion.trade/",
|
|
657
|
+
},
|
|
658
|
+
],
|
|
650
659
|
[
|
|
651
660
|
Platform.paragraph,
|
|
652
661
|
{
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ipfs = require('./ipfs.cjs');
|
|
4
|
+
|
|
5
|
+
const resolveMediaURL = (url) => {
|
|
6
|
+
if (!url)
|
|
7
|
+
return "";
|
|
8
|
+
// Fast path for common protocols
|
|
9
|
+
if (url.startsWith("data:") || url.startsWith("https:")) {
|
|
10
|
+
return url;
|
|
11
|
+
}
|
|
12
|
+
// Handle Arweave
|
|
13
|
+
if (url.startsWith("ar://")) {
|
|
14
|
+
return url.replace("ar://", "https://arweave.net/");
|
|
15
|
+
}
|
|
16
|
+
// Handle IPFS
|
|
17
|
+
if (url.includes("ipfs:") || ipfs.isIPFS(url)) {
|
|
18
|
+
return ipfs.resolveIPFS_URL(url) || "";
|
|
19
|
+
}
|
|
20
|
+
return url;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.resolveMediaURL = resolveMediaURL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resolveMediaURL: (url: string) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isIPFS, resolveIPFS_URL } from './ipfs.js';
|
|
2
|
+
|
|
3
|
+
const resolveMediaURL = (url) => {
|
|
4
|
+
if (!url)
|
|
5
|
+
return "";
|
|
6
|
+
// Fast path for common protocols
|
|
7
|
+
if (url.startsWith("data:") || url.startsWith("https:")) {
|
|
8
|
+
return url;
|
|
9
|
+
}
|
|
10
|
+
// Handle Arweave
|
|
11
|
+
if (url.startsWith("ar://")) {
|
|
12
|
+
return url.replace("ar://", "https://arweave.net/");
|
|
13
|
+
}
|
|
14
|
+
// Handle IPFS
|
|
15
|
+
if (url.includes("ipfs:") || isIPFS(url)) {
|
|
16
|
+
return resolveIPFS_URL(url) || "";
|
|
17
|
+
}
|
|
18
|
+
return url;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { resolveMediaURL };
|