@ecency/sdk 1.5.4 → 1.5.6

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.
@@ -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")
@@ -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
  }
@@ -1024,7 +1034,8 @@ function getReferralsInfiniteQueryOptions(username) {
1024
1034
  initialPageParam: { maxId: void 0 },
1025
1035
  queryFn: async ({ pageParam }) => {
1026
1036
  const { maxId } = pageParam ?? {};
1027
- const url = new URL(CONFIG.privateApiHost + `/private-api/referrals/${username}`);
1037
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
1038
+ const url = new URL(`/private-api/referrals/${username}`, baseUrl);
1028
1039
  if (maxId !== void 0) {
1029
1040
  url.searchParams.set("max_id", maxId.toString());
1030
1041
  }
@@ -1187,9 +1198,8 @@ function getPromotedPostsQuery(type = "feed") {
1187
1198
  return queryOptions({
1188
1199
  queryKey: ["posts", "promoted", type],
1189
1200
  queryFn: async () => {
1190
- const url = new URL(
1191
- CONFIG.privateApiHost + "/private-api/promoted-entries"
1192
- );
1201
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
1202
+ const url = new URL("/private-api/promoted-entries", baseUrl);
1193
1203
  if (type === "waves") {
1194
1204
  url.searchParams.append("short_content", "1");
1195
1205
  }
@@ -1260,7 +1270,7 @@ function filterDmcaEntry(entryOrEntries) {
1260
1270
  function applyFilter(entry) {
1261
1271
  if (!entry) return entry;
1262
1272
  const entryPath = `@${entry.author}/${entry.permlink}`;
1263
- const isDmca = CONFIG.dmcaPatternRegexes.some((regex) => regex.test(entryPath));
1273
+ const isDmca = CONFIG.dmcaPatterns.includes(entryPath) || CONFIG.dmcaPatternRegexes.some((regex) => regex.test(entryPath));
1264
1274
  if (isDmca) {
1265
1275
  return {
1266
1276
  ...entry,
@@ -2114,7 +2124,8 @@ function getWavesByTagQueryOptions(host, tag, limit = DEFAULT_TAG_FEED_LIMIT) {
2114
2124
  initialPageParam: void 0,
2115
2125
  queryFn: async ({ signal }) => {
2116
2126
  try {
2117
- const url = new URL(CONFIG.privateApiHost + "/private-api/waves/tags");
2127
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
2128
+ const url = new URL("/private-api/waves/tags", baseUrl);
2118
2129
  url.searchParams.set("container", host);
2119
2130
  url.searchParams.set("tag", tag);
2120
2131
  const response = await fetch(url.toString(), {
@@ -2151,7 +2162,8 @@ function getWavesFollowingQueryOptions(host, username) {
2151
2162
  return [];
2152
2163
  }
2153
2164
  try {
2154
- const url = new URL(CONFIG.privateApiHost + "/private-api/waves/following");
2165
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
2166
+ const url = new URL("/private-api/waves/following", baseUrl);
2155
2167
  url.searchParams.set("container", host);
2156
2168
  url.searchParams.set("username", normalizedUsername);
2157
2169
  const response = await fetch(url.toString(), {
@@ -2188,7 +2200,8 @@ function getWavesTrendingTagsQueryOptions(host, hours = 24) {
2188
2200
  queryKey: ["posts", "waves", "trending-tags", host, hours],
2189
2201
  queryFn: async ({ signal }) => {
2190
2202
  try {
2191
- const url = new URL(CONFIG.privateApiHost + "/private-api/waves/trending/tags");
2203
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
2204
+ const url = new URL("/private-api/waves/trending/tags", baseUrl);
2192
2205
  url.searchParams.set("container", host);
2193
2206
  url.searchParams.set("hours", hours.toString());
2194
2207
  const response = await fetch(url.toString(), {
@@ -4828,7 +4841,8 @@ async function hsTokenRenew(code) {
4828
4841
  var ENGINE_RPC_HEADERS = { "Content-type": "application/json" };
4829
4842
  async function engineRpc(payload) {
4830
4843
  const fetchApi = getBoundFetch();
4831
- const response = await fetchApi(`${CONFIG.privateApiHost}/private-api/engine-api`, {
4844
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
4845
+ const response = await fetchApi(`${baseUrl}/private-api/engine-api`, {
4832
4846
  method: "POST",
4833
4847
  body: JSON.stringify(payload),
4834
4848
  headers: ENGINE_RPC_HEADERS
@@ -5033,9 +5047,8 @@ async function getHiveEngineTokensMetadata(tokens) {
5033
5047
  }
5034
5048
  async function getHiveEngineTokenTransactions(username, symbol, limit, offset) {
5035
5049
  const fetchApi = getBoundFetch();
5036
- const url = new URL(
5037
- `${CONFIG.privateApiHost}/private-api/engine-account-history`
5038
- );
5050
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
5051
+ const url = new URL("/private-api/engine-account-history", baseUrl);
5039
5052
  url.searchParams.set("account", username);
5040
5053
  url.searchParams.set("symbol", symbol);
5041
5054
  url.searchParams.set("limit", limit.toString());
@@ -5053,7 +5066,8 @@ async function getHiveEngineTokenTransactions(username, symbol, limit, offset) {
5053
5066
  }
5054
5067
  async function getHiveEngineTokenMetrics(symbol, interval = "daily") {
5055
5068
  const fetchApi = getBoundFetch();
5056
- const url = new URL(`${CONFIG.privateApiHost}/private-api/engine-chart-api`);
5069
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
5070
+ const url = new URL("/private-api/engine-chart-api", baseUrl);
5057
5071
  url.searchParams.set("symbol", symbol);
5058
5072
  url.searchParams.set("interval", interval);
5059
5073
  const response = await fetchApi(url.toString(), {
@@ -5068,8 +5082,9 @@ async function getHiveEngineTokenMetrics(symbol, interval = "daily") {
5068
5082
  }
5069
5083
  async function getHiveEngineUnclaimedRewards(username) {
5070
5084
  const fetchApi = getBoundFetch();
5085
+ const baseUrl = ConfigManager.getValidatedBaseUrl();
5071
5086
  const response = await fetchApi(
5072
- `${CONFIG.privateApiHost}/private-api/engine-reward-api/${username}?hive=1`
5087
+ `${baseUrl}/private-api/engine-reward-api/${username}?hive=1`
5073
5088
  );
5074
5089
  if (!response.ok) {
5075
5090
  throw new Error(