Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cmd/edgefetch-wasm/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,39 @@ func dispatchWasmRPC(rawReq []byte) (any, error) {
}
return map[string]any{"blocked": true, "message": msg}, nil

case "nostr_prepare_nip01":
var p struct {
URL string `json:"url"`
SelfHost string `json:"selfHost"`
SubID string `json:"subId"`
MaxEvents int `json:"maxEvents"`
}
if err := json.Unmarshal(env.Payload, &p); err != nil {
return nil, err
}
return extract.PrepareNostrNIP01(p.URL, p.SelfHost, p.SubID, p.MaxEvents), nil

case "nostr_format_nip01":
var p struct {
OrigURL string `json:"origUrl"`
RelayURL string `json:"relayUrl"`
SubID string `json:"subId"`
NIP11Raw string `json:"nip11Raw"`
Frames []string `json:"frames"`
MaxEvents int `json:"maxEvents"`
}
if err := json.Unmarshal(env.Payload, &p); err != nil {
return nil, err
}
if p.Frames != nil && len(p.NIP11Raw) == 0 && p.RelayURL == "" {
return map[string]any{"events": extract.ParseNostrNIP01Frames(p.SubID, p.Frames, p.MaxEvents)}, nil
}
doc, ok := extract.FormatNostrNIP01Frames(p.OrigURL, p.RelayURL, p.SubID, p.NIP11Raw, p.Frames, p.MaxEvents)
if !ok || doc == nil {
return map[string]any{"ok": false}, nil
}
return map[string]any{"ok": true, "doc": doc}, nil

case "refine_blocked_map":
var p classify.RefineBlockedMapInput
if err := json.Unmarshal(env.Payload, &p); err != nil {
Expand Down
36 changes: 36 additions & 0 deletions hub/scripts/compile-manifests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,40 @@ export const VALID_HTML_MODES = new Set([
'local_classifieds_html',
'creator_digital_stores_html',
'chairish_1stdibs_html',
// Wave 3 B6 Category Q (Product Identity & GTIN #368-#374 + fcc-id enrichment)
'gs1_us_html',
'open_icecat_html',
'upcitemdb_barcodelookup_html',
'open_product_wikidata_html',
'energy_star_html',
'fcc_test_report_html',
'fcc_id_html',
'prop65_warnings_html',
// Wave 3 B6 Category R (Media, Entertainment & Lyrics #375-#386)
'tmdb_html',
'imdb_datasets_html',
'tvmaze_html',
'musicbrainz_html',
'discogs_html',
'podcast_index_html',
'spotify_html',
'setlist_lastfm_html',
'steam_store_html',
'igdb_html',
'bandcamp_html',
'genius_lyrics_html',
// Wave 3 B6 Category S (Finance & Market Data #387-#392)
'fed_h15_html',
'msrb_emma_html',
'ffiec_cdr_html',
// Wave 3 B6 Category T (Open Social & Creator #393-#400)
'threads_html',
'tumblr_html',
'farcaster_html',
'nostr_njump_html',
'product_hunt_html',
'substack_notes_html',
'patreon_public_html',
]);

const pslDatPath = join(manifestsDir, 'public_suffix_list.dat');
Expand Down Expand Up @@ -621,6 +655,8 @@ const APPROVED_WILDCARD_DOMAIN_PATTERNS = new Set([
'*.craigslist.org',
'*.gumroad.com',
'*.lemonsqueezy.com',
// Wave 3 B6 Category R
'*.bandcamp.com',
]);

const RESERVED_CORE_ATS_DOMAINS = new Set([
Expand Down
1 change: 1 addition & 0 deletions hub/scripts/run-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const suiteSpecs = [
['test/wave3-b3-trade-regulators.test.ts', 'wave3-b3-trade-regulators.test.mjs'],
['test/wave3-b4-research-security-dev.test.ts', 'wave3-b4-research-security-dev.test.mjs'],
['test/wave3-b5-cycling-resale.test.ts', 'wave3-b5-cycling-resale.test.mjs'],
['test/wave3-b6-gtin-media-finance-social.test.ts', 'wave3-b6-gtin-media-finance-social.test.mjs'],
['test/mcp-part2-wave2e.test.ts', 'mcp-part2-wave2e.test.mjs'],
['test/wave2-security-fixes.test.ts', 'wave2-security-fixes.test.mjs'],
['test/hub-secrets-policy.test.ts', 'hub-secrets-policy.test.mjs'],
Expand Down
1 change: 1 addition & 0 deletions hub/src/adapter-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const USER_AGENT_PROFILES: Readonly<Record<string, string>> = {
openstreetmap: 'EdgeFetch/2.7 (bot@edgefetch.dev; osm-polite-client)',
'sec-edgar': 'EdgeFetch/2.7 (bot@edgefetch.dev; sec-edgar-client)',
usajobs: 'EdgeFetch/2.7 (bot@edgefetch.dev; usajobs-client)',
musicbrainz: 'EdgeFetch/2.7 (bot@edgefetch.dev; musicbrainz-client)',
};

export interface AdapterPolicy {
Expand Down
69 changes: 66 additions & 3 deletions hub/src/extractors/declarative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,37 @@ export type DeclarativeJsonMode =
| 'ifixit_json'
| 'cpsc_ebike_incidents_json'
| 'reverb_listing_json'
| 'reverb_search_json';
| 'reverb_search_json'
| 'gs1_us_json'
| 'open_icecat_json'
| 'upcitemdb_json'
| 'barcodelookup_json'
| 'wikidata_gtin_sparql_json'
| 'energy_star_json'
| 'fcc_test_report_json'
| 'tmdb_json'
| 'tvmaze_json'
| 'musicbrainz_json'
| 'coverart_archive_json'
| 'discogs_json'
| 'podcast_index_json'
| 'spotify_api_json'
| 'spotify_oembed_json'
| 'setlist_fm_json'
| 'lastfm_json'
| 'steam_store_json'
| 'igdb_json'
| 'nasdaq_data_link_json'
| 'market_quotes_json'
| 'sec_xbrl_frames_json'
| 'ffiec_cdr_json'
| 'youtube_data_api_json'
| 'threads_api_json'
| 'tumblr_api_json'
| 'farcaster_hub_json'
| 'nostr_relay_json'
| 'product_hunt_json'
| 'beehiiv_api_json';

export interface DeclarativeExtractSpec {
commerceMode?: DeclarativeCommerceMode;
Expand Down Expand Up @@ -708,7 +738,10 @@ export interface DeclarativeExtractSpec {
| 'exploit_db_csv'
| 'exploit_db_rss'
| 'gerrit_json'
| 'apis_guru_list_bounded';
| 'apis_guru_list_bounded'
| 'opengtindb_text'
| 'imdb_datasets_tsv'
| 'fed_h15_csv';
pathParam?: string;
codeByPath?: DeclarativeCodeByPathSpec;
xml?: DeclarativeXmlSpec;
Expand Down Expand Up @@ -1134,7 +1167,37 @@ export type DeclarativeHtmlMode =
| 'peer_resale_fashion_html'
| 'local_classifieds_html'
| 'creator_digital_stores_html'
| 'chairish_1stdibs_html';
| 'chairish_1stdibs_html'
| 'gs1_us_html'
| 'open_icecat_html'
| 'upcitemdb_barcodelookup_html'
| 'open_product_wikidata_html'
| 'energy_star_html'
| 'fcc_test_report_html'
| 'fcc_id_html'
| 'prop65_warnings_html'
| 'tmdb_html'
| 'imdb_datasets_html'
| 'tvmaze_html'
| 'musicbrainz_html'
| 'discogs_html'
| 'podcast_index_html'
| 'spotify_html'
| 'setlist_lastfm_html'
| 'steam_store_html'
| 'igdb_html'
| 'bandcamp_html'
| 'genius_lyrics_html'
| 'fed_h15_html'
| 'msrb_emma_html'
| 'ffiec_cdr_html'
| 'threads_html'
| 'tumblr_html'
| 'farcaster_html'
| 'nostr_njump_html'
| 'product_hunt_html'
| 'substack_notes_html'
| 'patreon_public_html';

export interface DeclarativeHtmlRouteSpec {
id?: string;
Expand Down
58 changes: 58 additions & 0 deletions hub/src/scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import {
decodeWireItemBodyText,
evaluateTwinResponseRedirect,
executeKeyedTwinOfficialFetch,
fetchNostrRelayNip01Events,
isTrustedTwinRedirectUrl,
isTwinRedirectedToErrorPage,
runNostrNip11AndNip01AfterHubFetch,
selectRawBodyForContentState,
sliceToPolicyMaxFetchBytes,
} from './twin-transport';
Expand Down Expand Up @@ -243,6 +245,7 @@ export { isSameApiEndpointOriginAndPath } from './api-keys';
export {
decodeBase64ArchiveMagicPrefix,
decodeBoundedGzipTsvFromBase64,
fetchNostrRelayNip01Events,
isTrustedTwinRedirectUrl,
isTwinRedirectedToErrorPage,
};
Expand Down Expand Up @@ -3400,6 +3403,7 @@ export async function executeScrapeCall(params: {
tracer?: RequestTracer | TraceContext;
apiKeyVaultStore?: ApiKeyVaultStore;
mcpVaultStore?: McpVaultStore;
webSocketFactory?: (wssUrl: string) => WebSocket;
}): Promise<{ status: number; body: Record<string, unknown>; via: string; retryAfter?: string }> {
const activeTracer = getActiveRequestTracer(params.tracer);
const runScrape = async (): Promise<{ status: number; body: Record<string, unknown>; via: string; retryAfter?: string }> => {
Expand Down Expand Up @@ -5197,6 +5201,60 @@ export async function executeScrapeCall(params: {
formatted = registryTwin.formatTwin(twinBody, normalizedUrl, htmlFragToMd);
}
}
} else if (
registryTwin.id === 'nostr-relays' &&
callCoreWasm<{ enabled?: boolean }>('nostr_prepare_nip01', { url: normalizedUrl, ...(selfHost ? { selfHost } : {}) }).enabled
) {
const nip11Url = `${parsedUrl.origin}/`;
activeFetchUrl = nip11Url;
const twinPolicy = resolveAdapterPolicyForUrl(nip11Url);
const twinMinIntervalMs = Math.max(registryTwin.minIntervalMs ?? 0, twinPolicy.minIntervalMs ?? 0);
const twinRes = await executeHubFetch(
target,
JSON.stringify({
maxSeconds: 30,
options: {
includeBody: true,
respectRobots: true,
maxBytes: registryTwin.maxBytes ?? MAX_WASM_INPUT_BYTES,
maxInlineBodyBytes: MAX_WASM_INPUT_BYTES,
},
requests: [
buildTwinHubRequestSpec({
requestId: `twin-${registryTwin.id}`,
twin: { ...registryTwin, fetchUrl: nip11Url },
fallbackUaProfile: hostAdapterPolicy.userAgentProfile,
}),
],
}),
site,
`${source}:extractor:${registryTwin.id}`,
retentionMode,
true,
collectionId,
);
twinVia = twinRes.via;
twinDispatchStatus = twinRes.status;
if (twinRes.status === 200) {
const twinParsed = JSON.parse(twinRes.bodyText) as { results?: Array<Record<string, unknown>> };
twinItem = twinParsed.results?.[0];
const nostrOut = await runNostrNip11AndNip01AfterHubFetch({
normalizedUrl,
nip11Url,
nostrHost: parsedUrl.hostname.toLowerCase().replace(/\.+$/, ''),
twinId: registryTwin.id,
twinItem,
twinMinIntervalMs,
selfHost,
sleepFn,
webSocketFactory: params.webSocketFactory,
});
if (nostrOut.trusted) {
formatted = nostrOut.formatted;
} else if (twinItem && twinItem.outcome !== 'ok') {
reusedTwinFetchRes = twinRes;
}
}
} else {
const twinRes = await executeHubFetch(
target,
Expand Down
Loading
Loading