@unifold/core 0.1.14 → 0.1.16

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.d.mts CHANGED
@@ -285,24 +285,41 @@ interface ProjectConfigResponse {
285
285
  payment_networks: {
286
286
  networks: PaymentNetwork[];
287
287
  };
288
+ blocked_country_codes?: string[];
288
289
  }
289
290
  /**
290
291
  * Get project configuration
291
292
  * @param publishableKey - Optional publishable key, defaults to configured key
292
293
  */
293
294
  declare function getProjectConfig(publishableKey?: string): Promise<ProjectConfigResponse>;
295
+ interface IpAddressResponse {
296
+ alpha2: string;
297
+ alpha3: string;
298
+ country: string;
299
+ state: string | null;
300
+ ip_address: string;
301
+ }
302
+ /**
303
+ * Get IP address geolocation information
304
+ * Returns the user's IP address and associated country/state information
305
+ * This is a public endpoint that doesn't require authentication
306
+ */
307
+ declare function getIpAddress(): Promise<IpAddressResponse>;
294
308
 
295
309
  /**
296
310
  * User IP information interface
297
311
  */
298
312
  interface UserIpInfo {
299
313
  alpha2: string;
300
- state?: string;
314
+ alpha3?: string;
315
+ country?: string;
316
+ state?: string | null;
317
+ ipAddress?: string;
301
318
  }
302
319
  /**
303
320
  * Hook to fetch user's IP-based location information
304
321
  *
305
- * Uses ipapi.co to detect the user's country and state.
322
+ * Uses the Unifold API to detect the user's country and state.
306
323
  *
307
324
  * The result is cached in-memory using React Query:
308
325
  * - Data persists for the entire browser session
@@ -383,4 +400,4 @@ declare const i18n: {
383
400
  };
384
401
  type I18nStrings = typeof i18n;
385
402
 
386
- export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
403
+ export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
package/dist/index.d.ts CHANGED
@@ -285,24 +285,41 @@ interface ProjectConfigResponse {
285
285
  payment_networks: {
286
286
  networks: PaymentNetwork[];
287
287
  };
288
+ blocked_country_codes?: string[];
288
289
  }
289
290
  /**
290
291
  * Get project configuration
291
292
  * @param publishableKey - Optional publishable key, defaults to configured key
292
293
  */
293
294
  declare function getProjectConfig(publishableKey?: string): Promise<ProjectConfigResponse>;
295
+ interface IpAddressResponse {
296
+ alpha2: string;
297
+ alpha3: string;
298
+ country: string;
299
+ state: string | null;
300
+ ip_address: string;
301
+ }
302
+ /**
303
+ * Get IP address geolocation information
304
+ * Returns the user's IP address and associated country/state information
305
+ * This is a public endpoint that doesn't require authentication
306
+ */
307
+ declare function getIpAddress(): Promise<IpAddressResponse>;
294
308
 
295
309
  /**
296
310
  * User IP information interface
297
311
  */
298
312
  interface UserIpInfo {
299
313
  alpha2: string;
300
- state?: string;
314
+ alpha3?: string;
315
+ country?: string;
316
+ state?: string | null;
317
+ ipAddress?: string;
301
318
  }
302
319
  /**
303
320
  * Hook to fetch user's IP-based location information
304
321
  *
305
- * Uses ipapi.co to detect the user's country and state.
322
+ * Uses the Unifold API to detect the user's country and state.
306
323
  *
307
324
  * The result is cached in-memory using React Query:
308
325
  * - Data persists for the entire browser session
@@ -383,4 +400,4 @@ declare const i18n: {
383
400
  };
384
401
  type I18nStrings = typeof i18n;
385
402
 
386
- export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
403
+ export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  getFiatCurrencies: () => getFiatCurrencies,
30
30
  getIconUrl: () => getIconUrl,
31
31
  getIconUrlWithCdn: () => getIconUrlWithCdn,
32
+ getIpAddress: () => getIpAddress,
32
33
  getMeldQuotes: () => getMeldQuotes,
33
34
  getPreferredIconUrl: () => getPreferredIconUrl,
34
35
  getProjectConfig: () => getProjectConfig,
@@ -267,7 +268,9 @@ function getChainName(chains, chainType, chainId) {
267
268
  async function getProjectConfig(publishableKey) {
268
269
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
269
270
  validatePublishableKey(pk);
270
- const response = await fetch(`${API_BASE_URL}/v1/public/projects/config`, {
271
+ const url = `${API_BASE_URL}/v1/public/projects/config`;
272
+ console.log("[getProjectConfig] Fetching from:", url, "with key:", pk);
273
+ const response = await fetch(url, {
271
274
  method: "GET",
272
275
  headers: {
273
276
  accept: "application/json",
@@ -277,45 +280,47 @@ async function getProjectConfig(publishableKey) {
277
280
  if (!response.ok) {
278
281
  throw new Error(`Failed to fetch project config: ${response.statusText}`);
279
282
  }
283
+ const data = await response.json();
284
+ return data;
285
+ }
286
+ async function getIpAddress() {
287
+ const response = await fetch(`${API_BASE_URL}/v1/public/ip_address`, {
288
+ method: "GET",
289
+ headers: {
290
+ accept: "application/json"
291
+ }
292
+ });
293
+ if (!response.ok) {
294
+ throw new Error(
295
+ `Failed to fetch IP address information: ${response.statusText}`
296
+ );
297
+ }
280
298
  return response.json();
281
299
  }
282
300
 
283
301
  // src/hooks/use-user-ip.ts
284
302
  var import_react_query = require("@tanstack/react-query");
285
- async function getIpViaIpApi() {
286
- const url = "https://ipapi.co/json";
287
- const response = await fetch(url);
288
- if (!response.ok) {
289
- throw new Error(`ipapi.co failed: ${response.statusText}`);
290
- }
291
- const data = await response.json();
292
- return {
293
- alpha2: data.country_code.toLowerCase(),
294
- state: data.region_code?.toLowerCase()
295
- };
296
- }
297
303
  function useUserIp() {
298
304
  const {
299
305
  data: userIpInfo,
300
306
  isLoading,
301
307
  error
302
308
  } = (0, import_react_query.useQuery)({
303
- queryKey: ["getUserIpInfo"],
309
+ queryKey: ["unifold", "userIpInfo"],
304
310
  queryFn: async () => {
305
- try {
306
- const ipApiData = await getIpViaIpApi();
307
- console.log("IP detected via ipapi.co:", ipApiData);
308
- return ipApiData;
309
- } catch (ipApiError) {
310
- console.error("IP detection failed:", ipApiError);
311
- throw ipApiError;
312
- }
311
+ const data = await getIpAddress();
312
+ return {
313
+ alpha2: data.alpha2.toLowerCase(),
314
+ alpha3: data.alpha3?.toLowerCase(),
315
+ country: data.country,
316
+ state: data.state?.toLowerCase() ?? null,
317
+ ipAddress: data.ip_address
318
+ };
313
319
  },
314
320
  // Cache configuration to reduce API calls
315
321
  refetchOnMount: false,
316
322
  refetchOnReconnect: true,
317
323
  refetchOnWindowFocus: false,
318
- // Optional: Increase cache duration to 1 hour for even better rate limit protection
319
324
  staleTime: 1e3 * 60 * 60,
320
325
  // 1 hour - data considered fresh for 1 hour
321
326
  gcTime: 1e3 * 60 * 60 * 24
@@ -407,6 +412,7 @@ var i18n = en_default;
407
412
  getFiatCurrencies,
408
413
  getIconUrl,
409
414
  getIconUrlWithCdn,
415
+ getIpAddress,
410
416
  getMeldQuotes,
411
417
  getPreferredIconUrl,
412
418
  getProjectConfig,
package/dist/index.mjs CHANGED
@@ -223,7 +223,9 @@ function getChainName(chains, chainType, chainId) {
223
223
  async function getProjectConfig(publishableKey) {
224
224
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
225
225
  validatePublishableKey(pk);
226
- const response = await fetch(`${API_BASE_URL}/v1/public/projects/config`, {
226
+ const url = `${API_BASE_URL}/v1/public/projects/config`;
227
+ console.log("[getProjectConfig] Fetching from:", url, "with key:", pk);
228
+ const response = await fetch(url, {
227
229
  method: "GET",
228
230
  headers: {
229
231
  accept: "application/json",
@@ -233,45 +235,47 @@ async function getProjectConfig(publishableKey) {
233
235
  if (!response.ok) {
234
236
  throw new Error(`Failed to fetch project config: ${response.statusText}`);
235
237
  }
238
+ const data = await response.json();
239
+ return data;
240
+ }
241
+ async function getIpAddress() {
242
+ const response = await fetch(`${API_BASE_URL}/v1/public/ip_address`, {
243
+ method: "GET",
244
+ headers: {
245
+ accept: "application/json"
246
+ }
247
+ });
248
+ if (!response.ok) {
249
+ throw new Error(
250
+ `Failed to fetch IP address information: ${response.statusText}`
251
+ );
252
+ }
236
253
  return response.json();
237
254
  }
238
255
 
239
256
  // src/hooks/use-user-ip.ts
240
257
  import { useQuery } from "@tanstack/react-query";
241
- async function getIpViaIpApi() {
242
- const url = "https://ipapi.co/json";
243
- const response = await fetch(url);
244
- if (!response.ok) {
245
- throw new Error(`ipapi.co failed: ${response.statusText}`);
246
- }
247
- const data = await response.json();
248
- return {
249
- alpha2: data.country_code.toLowerCase(),
250
- state: data.region_code?.toLowerCase()
251
- };
252
- }
253
258
  function useUserIp() {
254
259
  const {
255
260
  data: userIpInfo,
256
261
  isLoading,
257
262
  error
258
263
  } = useQuery({
259
- queryKey: ["getUserIpInfo"],
264
+ queryKey: ["unifold", "userIpInfo"],
260
265
  queryFn: async () => {
261
- try {
262
- const ipApiData = await getIpViaIpApi();
263
- console.log("IP detected via ipapi.co:", ipApiData);
264
- return ipApiData;
265
- } catch (ipApiError) {
266
- console.error("IP detection failed:", ipApiError);
267
- throw ipApiError;
268
- }
266
+ const data = await getIpAddress();
267
+ return {
268
+ alpha2: data.alpha2.toLowerCase(),
269
+ alpha3: data.alpha3?.toLowerCase(),
270
+ country: data.country,
271
+ state: data.state?.toLowerCase() ?? null,
272
+ ipAddress: data.ip_address
273
+ };
269
274
  },
270
275
  // Cache configuration to reduce API calls
271
276
  refetchOnMount: false,
272
277
  refetchOnReconnect: true,
273
278
  refetchOnWindowFocus: false,
274
- // Optional: Increase cache duration to 1 hour for even better rate limit protection
275
279
  staleTime: 1e3 * 60 * 60,
276
280
  // 1 hour - data considered fresh for 1 hour
277
281
  gcTime: 1e3 * 60 * 60 * 24
@@ -362,6 +366,7 @@ export {
362
366
  getFiatCurrencies,
363
367
  getIconUrl,
364
368
  getIconUrlWithCdn,
369
+ getIpAddress,
365
370
  getMeldQuotes,
366
371
  getPreferredIconUrl,
367
372
  getProjectConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unifold/core",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "Unifold Core SDK - Core types, API client, and business logic",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",