@ecency/sdk 1.5.5 → 1.5.7
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/browser/index.d.ts +13 -0
- package/dist/browser/index.js +37 -21
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +50 -21
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +50 -21
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -1232,6 +1232,19 @@ declare namespace ConfigManager {
|
|
|
1232
1232
|
* @param host - The private API host URL (e.g., "https://ecency.com" or "" for relative URLs)
|
|
1233
1233
|
*/
|
|
1234
1234
|
function setPrivateApiHost(host: string): void;
|
|
1235
|
+
/**
|
|
1236
|
+
* Get a validated base URL for API requests
|
|
1237
|
+
* Returns a valid base URL that can be used with new URL(path, baseUrl)
|
|
1238
|
+
*
|
|
1239
|
+
* Priority:
|
|
1240
|
+
* 1. CONFIG.privateApiHost if set (dev/staging or explicit config)
|
|
1241
|
+
* 2. window.location.origin if in browser (production with relative URLs)
|
|
1242
|
+
* 3. 'https://ecency.com' as fallback for SSR (production default)
|
|
1243
|
+
*
|
|
1244
|
+
* @returns A valid base URL string
|
|
1245
|
+
* @throws Never throws - always returns a valid URL
|
|
1246
|
+
*/
|
|
1247
|
+
function getValidatedBaseUrl(): string;
|
|
1235
1248
|
/**
|
|
1236
1249
|
* Set the image host
|
|
1237
1250
|
* @param host - The image host URL (e.g., "https://images.ecency.com")
|
package/dist/browser/index.js
CHANGED
|
@@ -90,6 +90,16 @@ var ConfigManager;
|
|
|
90
90
|
CONFIG.privateApiHost = host;
|
|
91
91
|
}
|
|
92
92
|
ConfigManager2.setPrivateApiHost = setPrivateApiHost;
|
|
93
|
+
function getValidatedBaseUrl() {
|
|
94
|
+
if (CONFIG.privateApiHost) {
|
|
95
|
+
return CONFIG.privateApiHost;
|
|
96
|
+
}
|
|
97
|
+
if (typeof window !== "undefined" && window.location?.origin) {
|
|
98
|
+
return window.location.origin;
|
|
99
|
+
}
|
|
100
|
+
return "https://ecency.com";
|
|
101
|
+
}
|
|
102
|
+
ConfigManager2.getValidatedBaseUrl = getValidatedBaseUrl;
|
|
93
103
|
function setImageHost(host) {
|
|
94
104
|
CONFIG.imageHost = host;
|
|
95
105
|
}
|
|
@@ -148,35 +158,35 @@ var ConfigManager;
|
|
|
148
158
|
return { safe: true };
|
|
149
159
|
}
|
|
150
160
|
function safeCompileRegex(pattern, maxLength = 200) {
|
|
161
|
+
const isDevelopment = typeof process !== "undefined" && false;
|
|
151
162
|
try {
|
|
152
163
|
if (!pattern) {
|
|
153
|
-
|
|
164
|
+
if (isDevelopment) ;
|
|
154
165
|
return null;
|
|
155
166
|
}
|
|
156
167
|
if (pattern.length > maxLength) {
|
|
157
|
-
|
|
168
|
+
if (isDevelopment) ;
|
|
158
169
|
return null;
|
|
159
170
|
}
|
|
160
171
|
const staticAnalysis = analyzeRedosRisk(pattern);
|
|
161
172
|
if (!staticAnalysis.safe) {
|
|
162
|
-
|
|
173
|
+
if (isDevelopment) ;
|
|
163
174
|
return null;
|
|
164
175
|
}
|
|
165
176
|
let regex;
|
|
166
177
|
try {
|
|
167
178
|
regex = new RegExp(pattern);
|
|
168
179
|
} catch (compileErr) {
|
|
169
|
-
|
|
180
|
+
if (isDevelopment) ;
|
|
170
181
|
return null;
|
|
171
182
|
}
|
|
172
183
|
const runtimeTest = testRegexPerformance(regex);
|
|
173
184
|
if (!runtimeTest.safe) {
|
|
174
|
-
|
|
185
|
+
if (isDevelopment) ;
|
|
175
186
|
return null;
|
|
176
187
|
}
|
|
177
188
|
return regex;
|
|
178
189
|
} catch (err) {
|
|
179
|
-
console.warn(`[SDK] DMCA pattern rejected: unexpected error - pattern: ${pattern.substring(0, 50)}...`, err);
|
|
180
190
|
return null;
|
|
181
191
|
}
|
|
182
192
|
}
|
|
@@ -187,7 +197,8 @@ var ConfigManager;
|
|
|
187
197
|
CONFIG.dmcaTagRegexes = tags.map((pattern) => safeCompileRegex(pattern)).filter((r) => r !== null);
|
|
188
198
|
CONFIG.dmcaPatternRegexes = [];
|
|
189
199
|
const rejectedTagCount = tags.length - CONFIG.dmcaTagRegexes.length;
|
|
190
|
-
|
|
200
|
+
const isDevelopment = typeof process !== "undefined" && false;
|
|
201
|
+
if (!CONFIG._dmcaInitialized && isDevelopment) {
|
|
191
202
|
console.log(`[SDK] DMCA configuration loaded:`);
|
|
192
203
|
console.log(` - Accounts: ${accounts.length}`);
|
|
193
204
|
console.log(` - Tag patterns: ${CONFIG.dmcaTagRegexes.length}/${tags.length} compiled (${rejectedTagCount} rejected)`);
|
|
@@ -195,8 +206,8 @@ var ConfigManager;
|
|
|
195
206
|
if (rejectedTagCount > 0) {
|
|
196
207
|
console.warn(`[SDK] ${rejectedTagCount} DMCA tag patterns were rejected due to security validation. Check warnings above for details.`);
|
|
197
208
|
}
|
|
198
|
-
CONFIG._dmcaInitialized = true;
|
|
199
209
|
}
|
|
210
|
+
CONFIG._dmcaInitialized = true;
|
|
200
211
|
}
|
|
201
212
|
ConfigManager2.setDmcaLists = setDmcaLists;
|
|
202
213
|
})(ConfigManager || (ConfigManager = {}));
|
|
@@ -1024,7 +1035,8 @@ function getReferralsInfiniteQueryOptions(username) {
|
|
|
1024
1035
|
initialPageParam: { maxId: void 0 },
|
|
1025
1036
|
queryFn: async ({ pageParam }) => {
|
|
1026
1037
|
const { maxId } = pageParam ?? {};
|
|
1027
|
-
const
|
|
1038
|
+
const baseUrl = ConfigManager.getValidatedBaseUrl();
|
|
1039
|
+
const url = new URL(`/private-api/referrals/${username}`, baseUrl);
|
|
1028
1040
|
if (maxId !== void 0) {
|
|
1029
1041
|
url.searchParams.set("max_id", maxId.toString());
|
|
1030
1042
|
}
|
|
@@ -1187,9 +1199,8 @@ function getPromotedPostsQuery(type = "feed") {
|
|
|
1187
1199
|
return queryOptions({
|
|
1188
1200
|
queryKey: ["posts", "promoted", type],
|
|
1189
1201
|
queryFn: async () => {
|
|
1190
|
-
const
|
|
1191
|
-
|
|
1192
|
-
);
|
|
1202
|
+
const baseUrl = ConfigManager.getValidatedBaseUrl();
|
|
1203
|
+
const url = new URL("/private-api/promoted-entries", baseUrl);
|
|
1193
1204
|
if (type === "waves") {
|
|
1194
1205
|
url.searchParams.append("short_content", "1");
|
|
1195
1206
|
}
|
|
@@ -2114,7 +2125,8 @@ function getWavesByTagQueryOptions(host, tag, limit = DEFAULT_TAG_FEED_LIMIT) {
|
|
|
2114
2125
|
initialPageParam: void 0,
|
|
2115
2126
|
queryFn: async ({ signal }) => {
|
|
2116
2127
|
try {
|
|
2117
|
-
const
|
|
2128
|
+
const baseUrl = ConfigManager.getValidatedBaseUrl();
|
|
2129
|
+
const url = new URL("/private-api/waves/tags", baseUrl);
|
|
2118
2130
|
url.searchParams.set("container", host);
|
|
2119
2131
|
url.searchParams.set("tag", tag);
|
|
2120
2132
|
const response = await fetch(url.toString(), {
|
|
@@ -2151,7 +2163,8 @@ function getWavesFollowingQueryOptions(host, username) {
|
|
|
2151
2163
|
return [];
|
|
2152
2164
|
}
|
|
2153
2165
|
try {
|
|
2154
|
-
const
|
|
2166
|
+
const baseUrl = ConfigManager.getValidatedBaseUrl();
|
|
2167
|
+
const url = new URL("/private-api/waves/following", baseUrl);
|
|
2155
2168
|
url.searchParams.set("container", host);
|
|
2156
2169
|
url.searchParams.set("username", normalizedUsername);
|
|
2157
2170
|
const response = await fetch(url.toString(), {
|
|
@@ -2188,7 +2201,8 @@ function getWavesTrendingTagsQueryOptions(host, hours = 24) {
|
|
|
2188
2201
|
queryKey: ["posts", "waves", "trending-tags", host, hours],
|
|
2189
2202
|
queryFn: async ({ signal }) => {
|
|
2190
2203
|
try {
|
|
2191
|
-
const
|
|
2204
|
+
const baseUrl = ConfigManager.getValidatedBaseUrl();
|
|
2205
|
+
const url = new URL("/private-api/waves/trending/tags", baseUrl);
|
|
2192
2206
|
url.searchParams.set("container", host);
|
|
2193
2207
|
url.searchParams.set("hours", hours.toString());
|
|
2194
2208
|
const response = await fetch(url.toString(), {
|
|
@@ -4828,7 +4842,8 @@ async function hsTokenRenew(code) {
|
|
|
4828
4842
|
var ENGINE_RPC_HEADERS = { "Content-type": "application/json" };
|
|
4829
4843
|
async function engineRpc(payload) {
|
|
4830
4844
|
const fetchApi = getBoundFetch();
|
|
4831
|
-
const
|
|
4845
|
+
const baseUrl = ConfigManager.getValidatedBaseUrl();
|
|
4846
|
+
const response = await fetchApi(`${baseUrl}/private-api/engine-api`, {
|
|
4832
4847
|
method: "POST",
|
|
4833
4848
|
body: JSON.stringify(payload),
|
|
4834
4849
|
headers: ENGINE_RPC_HEADERS
|
|
@@ -5033,9 +5048,8 @@ async function getHiveEngineTokensMetadata(tokens) {
|
|
|
5033
5048
|
}
|
|
5034
5049
|
async function getHiveEngineTokenTransactions(username, symbol, limit, offset) {
|
|
5035
5050
|
const fetchApi = getBoundFetch();
|
|
5036
|
-
const
|
|
5037
|
-
|
|
5038
|
-
);
|
|
5051
|
+
const baseUrl = ConfigManager.getValidatedBaseUrl();
|
|
5052
|
+
const url = new URL("/private-api/engine-account-history", baseUrl);
|
|
5039
5053
|
url.searchParams.set("account", username);
|
|
5040
5054
|
url.searchParams.set("symbol", symbol);
|
|
5041
5055
|
url.searchParams.set("limit", limit.toString());
|
|
@@ -5053,7 +5067,8 @@ async function getHiveEngineTokenTransactions(username, symbol, limit, offset) {
|
|
|
5053
5067
|
}
|
|
5054
5068
|
async function getHiveEngineTokenMetrics(symbol, interval = "daily") {
|
|
5055
5069
|
const fetchApi = getBoundFetch();
|
|
5056
|
-
const
|
|
5070
|
+
const baseUrl = ConfigManager.getValidatedBaseUrl();
|
|
5071
|
+
const url = new URL("/private-api/engine-chart-api", baseUrl);
|
|
5057
5072
|
url.searchParams.set("symbol", symbol);
|
|
5058
5073
|
url.searchParams.set("interval", interval);
|
|
5059
5074
|
const response = await fetchApi(url.toString(), {
|
|
@@ -5068,8 +5083,9 @@ async function getHiveEngineTokenMetrics(symbol, interval = "daily") {
|
|
|
5068
5083
|
}
|
|
5069
5084
|
async function getHiveEngineUnclaimedRewards(username) {
|
|
5070
5085
|
const fetchApi = getBoundFetch();
|
|
5086
|
+
const baseUrl = ConfigManager.getValidatedBaseUrl();
|
|
5071
5087
|
const response = await fetchApi(
|
|
5072
|
-
`${
|
|
5088
|
+
`${baseUrl}/private-api/engine-reward-api/${username}?hive=1`
|
|
5073
5089
|
);
|
|
5074
5090
|
if (!response.ok) {
|
|
5075
5091
|
throw new Error(
|