@dialectlabs/blinks-core
Advanced tools
Comparing version 0.14.1 to 0.15.0
@@ -374,10 +374,9 @@ import { ActionGetResponse, SignMessageData as SignMessageData$1, NextActionLink, PostNextActionLink, MessageNextActionPostRequest, NextActionPostRequest, NextAction, LinkedActionType, TypedActionParameter, ActionPostRequest, ActionPostResponse, GeneralParameterType, SelectableParameterType } from '@solana/actions-spec'; | ||
type ProxifiedResult = { | ||
readonly url: URL; | ||
readonly headers: Record<string, string>; | ||
}; | ||
declare function setProxyUrl(url: string): void; | ||
declare function proxify(url: string): { | ||
url: URL; | ||
headers: Record<string, string>; | ||
}; | ||
declare function proxifyImage(url: string): { | ||
url: URL; | ||
}; | ||
declare function proxify(url: string): ProxifiedResult; | ||
declare function proxifyImage(url: string): ProxifiedResult; | ||
@@ -490,2 +489,41 @@ type SecurityLevel = 'only-trusted' | 'non-malicious' | 'all'; | ||
export { AbstractActionComponent, Action$1 as Action, type ActionAdapter, type ActionAdapterMetadata, type ActionCallbacksConfig, ActionConfig, type ActionContext, type ActionSupportStrategy, type ActionSupportability, type ActionsJsonConfig, ActionsRegistry, type ActionsRegistryConfig, ActionsURLMapper, BASELINE_ACTION_BLOCKCHAIN_IDS, BASELINE_ACTION_VERSION, BLINK_CLIENT_KEY_HEADER, type BaseBlinkLayoutProps, type BlinkCaption, BlinkContainer, type BlinkContainerProps, type BlinkSecurityState, BlockchainIds, ButtonActionComponent, DEFAULT_SUPPORTED_BLOCKCHAIN_IDS, type DialectExperimentalFeatures, type Disclaimer, DisclaimerType, type ExecutionState, type ExecutionStatus, ExecutionType, type ExtendedActionGetResponse, type ExtraExecutionData, FormActionComponent, type IncomingActionConfig, type IsInterstitialResult, type LookupType, MAX_SUPPORTED_ACTION_VERSION, MultiValueActionComponent, type RegisteredEntity, type SecurityActionState, type SecurityLevel, type SignMessageData, SignMessageVerificationErrorType, type SignMessageVerificationOptions, SingleValueActionComponent, type SolanaPaySpecGetResponse, type SolanaPaySpecPostRequestBody, type SolanaPaySpecPostResponse, checkSecurity, createSignMessageText, defaultActionSupportStrategy, getExtendedActionState, getExtendedInterstitialState, getExtendedWebsiteState, isBlockchainSupported, isInterstitial, isParameterSelectable, isPatternAllowed, isVersionSupported, mergeActionStates, parseSignMessageText, proxify, proxifyImage, setClientKey, setProxyUrl, unfurlUrlToActionApiUrl, useAction, useActionsRegistryInterval, verifySignMessageData }; | ||
interface BlinkList { | ||
entries: BlinkListEntry[]; | ||
} | ||
interface BlinkListEntry { | ||
id: string; | ||
title: string; | ||
description: string; | ||
blinkUrl: string; | ||
metadataUrl?: string; | ||
image: string; | ||
icon?: string; | ||
} | ||
declare const useBlinkList: () => { | ||
loading: boolean; | ||
refetch: () => () => void; | ||
data: BlinkListEntry[]; | ||
}; | ||
interface UseMetadataArgs { | ||
wallet?: string; | ||
url: string; | ||
} | ||
interface BlinkMetadata { | ||
rows: MetadataRow[]; | ||
extendedDescription?: string; | ||
} | ||
interface MetadataRow { | ||
key: string; | ||
title: string; | ||
value: string; | ||
icon?: string; | ||
url?: string; | ||
} | ||
declare const useMetadata: ({ url, wallet }: UseMetadataArgs) => { | ||
loading: boolean; | ||
refetch: () => () => void; | ||
data: BlinkMetadata | undefined; | ||
}; | ||
export { AbstractActionComponent, Action$1 as Action, type ActionAdapter, type ActionAdapterMetadata, type ActionCallbacksConfig, ActionConfig, type ActionContext, type ActionSupportStrategy, type ActionSupportability, type ActionsJsonConfig, ActionsRegistry, type ActionsRegistryConfig, ActionsURLMapper, BASELINE_ACTION_BLOCKCHAIN_IDS, BASELINE_ACTION_VERSION, BLINK_CLIENT_KEY_HEADER, type BaseBlinkLayoutProps, type BlinkCaption, BlinkContainer, type BlinkContainerProps, type BlinkList, type BlinkListEntry, type BlinkMetadata, type BlinkSecurityState, BlockchainIds, ButtonActionComponent, DEFAULT_SUPPORTED_BLOCKCHAIN_IDS, type DialectExperimentalFeatures, type Disclaimer, DisclaimerType, type ExecutionState, type ExecutionStatus, ExecutionType, type ExtendedActionGetResponse, type ExtraExecutionData, FormActionComponent, type IncomingActionConfig, type IsInterstitialResult, type LookupType, MAX_SUPPORTED_ACTION_VERSION, type MetadataRow, MultiValueActionComponent, type RegisteredEntity, type SecurityActionState, type SecurityLevel, type SignMessageData, SignMessageVerificationErrorType, type SignMessageVerificationOptions, SingleValueActionComponent, type SolanaPaySpecGetResponse, type SolanaPaySpecPostRequestBody, type SolanaPaySpecPostResponse, checkSecurity, createSignMessageText, defaultActionSupportStrategy, getExtendedActionState, getExtendedInterstitialState, getExtendedWebsiteState, isBlockchainSupported, isInterstitial, isParameterSelectable, isPatternAllowed, isVersionSupported, mergeActionStates, parseSignMessageText, proxify, proxifyImage, setClientKey, setProxyUrl, unfurlUrlToActionApiUrl, useAction, useActionsRegistryInterval, useBlinkList, useMetadata, verifySignMessageData }; |
@@ -94,10 +94,19 @@ // src/utils/caip-2.ts | ||
function proxify(url) { | ||
const baseUrl = new URL(url); | ||
if (shouldIgnoreProxy(baseUrl)) { | ||
return createProxifiedUrl(url); | ||
} | ||
function proxifyImage(url) { | ||
return createProxifiedUrl(url, "image"); | ||
} | ||
function proxifyMetadata(url) { | ||
return createProxifiedUrl(url, "metadata"); | ||
} | ||
function createProxifiedUrl(url, endpoint) { | ||
const incomingUrl = new URL(url); | ||
if (!proxyUrl || shouldIgnoreProxy(incomingUrl)) { | ||
return { | ||
url: baseUrl, | ||
url: incomingUrl, | ||
headers: {} | ||
}; | ||
} | ||
const proxifiedUrl = new URL(proxyUrl); | ||
const proxifiedUrl = endpoint ? new URL(endpoint, proxyUrl) : new URL(proxyUrl); | ||
proxifiedUrl.searchParams.set("url", url); | ||
@@ -109,15 +118,2 @@ return { | ||
} | ||
function proxifyImage(url) { | ||
const baseUrl = new URL(url); | ||
if (shouldIgnoreProxy(baseUrl)) { | ||
return { | ||
url: baseUrl | ||
}; | ||
} | ||
const proxifiedUrl = new URL(`${proxyUrl}/image`); | ||
proxifiedUrl.searchParams.set("url", url); | ||
return { | ||
url: proxifiedUrl | ||
}; | ||
} | ||
function getProxifiedHeaders() { | ||
@@ -129,9 +125,3 @@ return { | ||
function shouldIgnoreProxy(url) { | ||
if (url.hostname === "localhost" || url.hostname === "127.0.0.1") { | ||
return true; | ||
} | ||
if (!proxyUrl) { | ||
return true; | ||
} | ||
return false; | ||
return url.hostname === "localhost" || url.hostname === "127.0.0.1"; | ||
} | ||
@@ -235,3 +225,3 @@ | ||
name: "@dialectlabs/blinks-core", | ||
version: "0.14.1", | ||
version: "0.15.0", | ||
license: "Apache-2.0", | ||
@@ -1688,2 +1678,130 @@ private: false, | ||
} | ||
// src/hooks/useBlinkList.ts | ||
import { useCallback, useEffect as useEffect4, useState as useState4 } from "react"; | ||
var useBlinkList = () => { | ||
const [loading, setLoading] = useState4(false); | ||
const [data, setData] = useState4(); | ||
const refetch = useCallback(() => { | ||
let ignore = false; | ||
setLoading(true); | ||
fetchBlinkList().then((data2) => { | ||
if (!ignore) { | ||
setData(data2); | ||
} | ||
}).finally(() => { | ||
if (!ignore) { | ||
setLoading(false); | ||
} | ||
}); | ||
return () => { | ||
ignore = true; | ||
}; | ||
}, []); | ||
useEffect4(() => { | ||
const cancel = refetch(); | ||
return () => { | ||
cancel(); | ||
}; | ||
}, [refetch]); | ||
return { | ||
loading, | ||
refetch, | ||
data: data?.entries ?? [] | ||
}; | ||
}; | ||
async function fetchBlinkList() { | ||
try { | ||
const response = await fetch( | ||
"https://registry.dial.to/v1/private/blinks/list", | ||
{ | ||
method: "GET", | ||
headers: { | ||
Accept: "application/json", | ||
...clientKey && { [BLINK_CLIENT_KEY_HEADER]: clientKey } | ||
} | ||
} | ||
); | ||
if (!response.ok) { | ||
console.error( | ||
`[@dialectlabs/blinks] Failed to fetch blink list, response status: ${response.status}` | ||
); | ||
return { | ||
entries: [] | ||
}; | ||
} | ||
return await response.json(); | ||
} catch (e) { | ||
console.error(`[@dialectlabs/blinks] Failed to fetch blink list`, e); | ||
return { | ||
entries: [] | ||
}; | ||
} | ||
} | ||
// src/hooks/useMetadata.ts | ||
import { useCallback as useCallback2, useEffect as useEffect5, useState as useState5 } from "react"; | ||
var useMetadata = ({ url, wallet }) => { | ||
const [loading, setLoading] = useState5(false); | ||
const [data, setData] = useState5(); | ||
const refetch = useCallback2(() => { | ||
let ignore = false; | ||
setLoading(true); | ||
fetchMetadata(url, wallet).then((data2) => { | ||
if (!ignore) { | ||
setData(data2); | ||
} | ||
}).finally(() => { | ||
if (!ignore) { | ||
setLoading(false); | ||
} | ||
}); | ||
return () => { | ||
ignore = true; | ||
}; | ||
}, [url, wallet]); | ||
useEffect5(() => { | ||
const cancel = refetch(); | ||
return () => { | ||
cancel(); | ||
}; | ||
}, [refetch]); | ||
return { | ||
loading, | ||
refetch, | ||
data | ||
}; | ||
}; | ||
async function fetchMetadata(url, wallet) { | ||
try { | ||
const urlObj = new URL(url); | ||
if (wallet) { | ||
urlObj.searchParams.append("account", wallet); | ||
} | ||
const { url: proxyUrl2, headers: proxyHeaders } = proxifyMetadata( | ||
urlObj.toString() | ||
); | ||
const response = await fetch(proxyUrl2, { | ||
method: "GET", | ||
headers: { | ||
Accept: "application/json", | ||
...proxyHeaders | ||
} | ||
}); | ||
if (!response.ok) { | ||
console.error( | ||
`[@dialectlabs/blinks] Failed to fetch metadata, response status: ${response.status}` | ||
); | ||
return { | ||
rows: [] | ||
}; | ||
} | ||
return await response.json(); | ||
} catch (e) { | ||
console.error(`[@dialectlabs/blinks] Failed to fetch metadata`, e); | ||
return { | ||
rows: [] | ||
}; | ||
} | ||
} | ||
export { | ||
@@ -1729,3 +1847,5 @@ AbstractActionComponent, | ||
useActionsRegistryInterval, | ||
useBlinkList, | ||
useMetadata, | ||
verifySignMessageData | ||
}; |
{ | ||
"name": "@dialectlabs/blinks-core", | ||
"version": "0.14.1", | ||
"version": "0.15.0", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "private": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
152688
4089
14