@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.
@@ -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,48 @@ var ConfigManager;
148
158
  return { safe: true };
149
159
  }
150
160
  function safeCompileRegex(pattern, maxLength = 200) {
161
+ const isDevelopment = typeof process !== "undefined" && process.env?.NODE_ENV === "development";
151
162
  try {
152
163
  if (!pattern) {
153
- console.warn(`[SDK] DMCA pattern rejected: empty pattern`);
164
+ if (isDevelopment) {
165
+ console.warn(`[SDK] DMCA pattern rejected: empty pattern`);
166
+ }
154
167
  return null;
155
168
  }
156
169
  if (pattern.length > maxLength) {
157
- console.warn(`[SDK] DMCA pattern rejected: length ${pattern.length} exceeds max ${maxLength} - pattern: ${pattern.substring(0, 50)}...`);
170
+ if (isDevelopment) {
171
+ console.warn(`[SDK] DMCA pattern rejected: length ${pattern.length} exceeds max ${maxLength} - pattern: ${pattern.substring(0, 50)}...`);
172
+ }
158
173
  return null;
159
174
  }
160
175
  const staticAnalysis = analyzeRedosRisk(pattern);
161
176
  if (!staticAnalysis.safe) {
162
- console.warn(`[SDK] DMCA pattern rejected: static analysis failed (${staticAnalysis.reason}) - pattern: ${pattern.substring(0, 50)}...`);
177
+ if (isDevelopment) {
178
+ console.warn(`[SDK] DMCA pattern rejected: static analysis failed (${staticAnalysis.reason}) - pattern: ${pattern.substring(0, 50)}...`);
179
+ }
163
180
  return null;
164
181
  }
165
182
  let regex;
166
183
  try {
167
184
  regex = new RegExp(pattern);
168
185
  } catch (compileErr) {
169
- console.warn(`[SDK] DMCA pattern rejected: compilation failed - pattern: ${pattern.substring(0, 50)}...`, compileErr);
186
+ if (isDevelopment) {
187
+ console.warn(`[SDK] DMCA pattern rejected: compilation failed - pattern: ${pattern.substring(0, 50)}...`, compileErr);
188
+ }
170
189
  return null;
171
190
  }
172
191
  const runtimeTest = testRegexPerformance(regex);
173
192
  if (!runtimeTest.safe) {
174
- console.warn(`[SDK] DMCA pattern rejected: runtime test failed (${runtimeTest.reason}) - pattern: ${pattern.substring(0, 50)}...`);
193
+ if (isDevelopment) {
194
+ console.warn(`[SDK] DMCA pattern rejected: runtime test failed (${runtimeTest.reason}) - pattern: ${pattern.substring(0, 50)}...`);
195
+ }
175
196
  return null;
176
197
  }
177
198
  return regex;
178
199
  } catch (err) {
179
- console.warn(`[SDK] DMCA pattern rejected: unexpected error - pattern: ${pattern.substring(0, 50)}...`, err);
200
+ if (isDevelopment) {
201
+ console.warn(`[SDK] DMCA pattern rejected: unexpected error - pattern: ${pattern.substring(0, 50)}...`, err);
202
+ }
180
203
  return null;
181
204
  }
182
205
  }
@@ -187,7 +210,8 @@ var ConfigManager;
187
210
  CONFIG.dmcaTagRegexes = tags.map((pattern) => safeCompileRegex(pattern)).filter((r) => r !== null);
188
211
  CONFIG.dmcaPatternRegexes = [];
189
212
  const rejectedTagCount = tags.length - CONFIG.dmcaTagRegexes.length;
190
- if (!CONFIG._dmcaInitialized) {
213
+ const isDevelopment = typeof process !== "undefined" && process.env?.NODE_ENV === "development";
214
+ if (!CONFIG._dmcaInitialized && isDevelopment) {
191
215
  console.log(`[SDK] DMCA configuration loaded:`);
192
216
  console.log(` - Accounts: ${accounts.length}`);
193
217
  console.log(` - Tag patterns: ${CONFIG.dmcaTagRegexes.length}/${tags.length} compiled (${rejectedTagCount} rejected)`);
@@ -195,8 +219,8 @@ var ConfigManager;
195
219
  if (rejectedTagCount > 0) {
196
220
  console.warn(`[SDK] ${rejectedTagCount} DMCA tag patterns were rejected due to security validation. Check warnings above for details.`);
197
221
  }
198
- CONFIG._dmcaInitialized = true;
199
222
  }
223
+ CONFIG._dmcaInitialized = true;
200
224
  }
201
225
  ConfigManager2.setDmcaLists = setDmcaLists;
202
226
  })(ConfigManager || (ConfigManager = {}));
@@ -1024,7 +1048,8 @@ function getReferralsInfiniteQueryOptions(username) {
1024
1048
  initialPageParam: { maxId: void 0 },
1025
1049
  queryFn: async ({ pageParam }) => {
1026
1050
  const { maxId } = pageParam ?? {};
1027
- const url = new URL(CONFIG.privateApiHost + `/private-api/referrals/${username}`);
1051
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
1052
+ const url = new URL(`/private-api/referrals/${username}`, baseUrl);
1028
1053
  if (maxId !== void 0) {
1029
1054
  url.searchParams.set("max_id", maxId.toString());
1030
1055
  }
@@ -1187,9 +1212,8 @@ function getPromotedPostsQuery(type = "feed") {
1187
1212
  return queryOptions({
1188
1213
  queryKey: ["posts", "promoted", type],
1189
1214
  queryFn: async () => {
1190
- const url = new URL(
1191
- CONFIG.privateApiHost + "/private-api/promoted-entries"
1192
- );
1215
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
1216
+ const url = new URL("/private-api/promoted-entries", baseUrl);
1193
1217
  if (type === "waves") {
1194
1218
  url.searchParams.append("short_content", "1");
1195
1219
  }
@@ -2114,7 +2138,8 @@ function getWavesByTagQueryOptions(host, tag, limit = DEFAULT_TAG_FEED_LIMIT) {
2114
2138
  initialPageParam: void 0,
2115
2139
  queryFn: async ({ signal }) => {
2116
2140
  try {
2117
- const url = new URL(CONFIG.privateApiHost + "/private-api/waves/tags");
2141
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
2142
+ const url = new URL("/private-api/waves/tags", baseUrl);
2118
2143
  url.searchParams.set("container", host);
2119
2144
  url.searchParams.set("tag", tag);
2120
2145
  const response = await fetch(url.toString(), {
@@ -2151,7 +2176,8 @@ function getWavesFollowingQueryOptions(host, username) {
2151
2176
  return [];
2152
2177
  }
2153
2178
  try {
2154
- const url = new URL(CONFIG.privateApiHost + "/private-api/waves/following");
2179
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
2180
+ const url = new URL("/private-api/waves/following", baseUrl);
2155
2181
  url.searchParams.set("container", host);
2156
2182
  url.searchParams.set("username", normalizedUsername);
2157
2183
  const response = await fetch(url.toString(), {
@@ -2188,7 +2214,8 @@ function getWavesTrendingTagsQueryOptions(host, hours = 24) {
2188
2214
  queryKey: ["posts", "waves", "trending-tags", host, hours],
2189
2215
  queryFn: async ({ signal }) => {
2190
2216
  try {
2191
- const url = new URL(CONFIG.privateApiHost + "/private-api/waves/trending/tags");
2217
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
2218
+ const url = new URL("/private-api/waves/trending/tags", baseUrl);
2192
2219
  url.searchParams.set("container", host);
2193
2220
  url.searchParams.set("hours", hours.toString());
2194
2221
  const response = await fetch(url.toString(), {
@@ -4828,7 +4855,8 @@ async function hsTokenRenew(code) {
4828
4855
  var ENGINE_RPC_HEADERS = { "Content-type": "application/json" };
4829
4856
  async function engineRpc(payload) {
4830
4857
  const fetchApi = getBoundFetch();
4831
- const response = await fetchApi(`${CONFIG.privateApiHost}/private-api/engine-api`, {
4858
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
4859
+ const response = await fetchApi(`${baseUrl}/private-api/engine-api`, {
4832
4860
  method: "POST",
4833
4861
  body: JSON.stringify(payload),
4834
4862
  headers: ENGINE_RPC_HEADERS
@@ -5033,9 +5061,8 @@ async function getHiveEngineTokensMetadata(tokens) {
5033
5061
  }
5034
5062
  async function getHiveEngineTokenTransactions(username, symbol, limit, offset) {
5035
5063
  const fetchApi = getBoundFetch();
5036
- const url = new URL(
5037
- `${CONFIG.privateApiHost}/private-api/engine-account-history`
5038
- );
5064
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
5065
+ const url = new URL("/private-api/engine-account-history", baseUrl);
5039
5066
  url.searchParams.set("account", username);
5040
5067
  url.searchParams.set("symbol", symbol);
5041
5068
  url.searchParams.set("limit", limit.toString());
@@ -5053,7 +5080,8 @@ async function getHiveEngineTokenTransactions(username, symbol, limit, offset) {
5053
5080
  }
5054
5081
  async function getHiveEngineTokenMetrics(symbol, interval = "daily") {
5055
5082
  const fetchApi = getBoundFetch();
5056
- const url = new URL(`${CONFIG.privateApiHost}/private-api/engine-chart-api`);
5083
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
5084
+ const url = new URL("/private-api/engine-chart-api", baseUrl);
5057
5085
  url.searchParams.set("symbol", symbol);
5058
5086
  url.searchParams.set("interval", interval);
5059
5087
  const response = await fetchApi(url.toString(), {
@@ -5068,8 +5096,9 @@ async function getHiveEngineTokenMetrics(symbol, interval = "daily") {
5068
5096
  }
5069
5097
  async function getHiveEngineUnclaimedRewards(username) {
5070
5098
  const fetchApi = getBoundFetch();
5099
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
5071
5100
  const response = await fetchApi(
5072
- `${CONFIG.privateApiHost}/private-api/engine-reward-api/${username}?hive=1`
5101
+ `${baseUrl}/private-api/engine-reward-api/${username}?hive=1`
5073
5102
  );
5074
5103
  if (!response.ok) {
5075
5104
  throw new Error(