diff --git a/src/Base64Binary.ts b/src/Base64Binary.ts index 126c996..3776b70 100644 --- a/src/Base64Binary.ts +++ b/src/Base64Binary.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ /* Copyright (c) 2011, Daniel Guerrero All rights reserved. @@ -69,7 +70,7 @@ const Base64Binary = { if (arrayBuffer) uarray = new Uint8Array(arrayBuffer); else uarray = new Uint8Array(bytes); - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + input = input.replace(/[^A-Za-z0-9+/=]/g, ""); for (i = 0; i < bytes; i += 3) { //get the 3 octects in 4 ascii chars diff --git a/src/analytics.ts b/src/analytics.ts index 9072f7d..bcc270e 100644 --- a/src/analytics.ts +++ b/src/analytics.ts @@ -12,10 +12,11 @@ export enum LogEventType { export interface LogRequest { dpid: number; version: number; - extra: any; + extra: unknown; eventType: LogEventType; } +/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ let supabase: SupabaseClient | undefined; if (process.env.SUPABASE_URL && process.env.SUPABASE_KEY) { supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY); diff --git a/src/api/v1/list.ts b/src/api/v1/list.ts index 958209b..88579cc 100644 --- a/src/api/v1/list.ts +++ b/src/api/v1/list.ts @@ -16,6 +16,7 @@ const transformGraphResult = id: r.id, recentCid: safeHexToCid(r.researchObject.versions[r.researchObject.versions.length - 1].cid), researchObject: { + owner: r.researchObject.owner, id: r.researchObject.id, versions: r.researchObject.versions.map((v, index) => ({ ...v, @@ -66,8 +67,9 @@ export const list = async (req: Request, res: Response) => { ).researchObjectVersions; res.json(graphResult.map(transformGraphResult(transactionHashToDpid))); - } catch (err: any) { - res.json({ ok: false, error: err.message, path: "/api/v1/dpid" }).status(500); - logger.error("ERROR", err.message); + } catch (err) { + const error = err as Error; + res.json({ ok: false, error: error.message, path: "/api/v1/dpid" }).status(500); + logger.error("ERROR", error.message); } }; diff --git a/src/dpid-reader/DpidReader.ts b/src/dpid-reader/DpidReader.ts index c9e5b91..6f7273d 100644 --- a/src/dpid-reader/DpidReader.ts +++ b/src/dpid-reader/DpidReader.ts @@ -1,25 +1,22 @@ +/* eslint-disable no-console */ +/* eslint-disable @typescript-eslint/no-explicit-any */ const RPC_URL = "https://eth-sepolia.g.alchemy.com/v2/Dg4eT90opKOFZ7w-YCxVwX9O-sriKn0N"; -//'https://goerli.infura.io/v3/'; -import { AlchemyEth, createAlchemyWeb3 } from "@alch/alchemy-web3"; -import goerliContract from "../deployments/goerli/config.json"; +import { createAlchemyWeb3 } from "@alch/alchemy-web3"; import sepoliaDevContract from "../deployments/sepoliaDev/config.json"; import sepoliaProdContract from "../deployments/sepoliaProd/config.json"; -import { encode, decode } from "url-safe-base64"; +import { encode } from "url-safe-base64"; import { getIndexedResearchObjects } from "./TheGraphResolver"; import { base16 } from "multiformats/bases/base16"; import { CID } from "multiformats/cid"; -import fs from "fs"; -import https from "https"; import axios from "axios"; import { DataBucketComponent, - ResearchObject, - ResearchObjectComponentType, ResearchObjectV1, ResearchObjectV1Component, RoCrateTransformer, } from "@desci-labs/desci-models"; import parentLogger from "../logger"; + const logger = parentLogger.child({ module: "DpidReader" }); export interface DpidRequest { dpid: string; @@ -50,7 +47,7 @@ export const convertHexTo64PID = (hex: string, hexToBytes: any) => { const bytes: number[] = hexToBytes(hex); const base64encoded = Buffer.from(bytes).toString("base64"); - const base64SafePID = encode(base64encoded).replace(/[\.=]$/, ""); + const base64SafePID = encode(base64encoded).replace(/[.=]$/, ""); return base64SafePID; }; @@ -81,11 +78,6 @@ logger.info({ DEFAULT_IPFS_GATEWAY, }); -interface ContractConfig { - address: string; - abi: any; -} - interface DpidResult { id16: string; id64: string; @@ -120,11 +112,8 @@ export const hexToCid = (hexCid: string) => { export interface DataResponse { data: object; } -// TODO: remove sealstorage specific cert, no longer needed -const caBundle = fs.readFileSync("ssl/sealstorage-bundle.crt"); -const agent = new https.Agent({ ca: caBundle, rejectUnauthorized: false }); export class DpidReader { - static read = async ({ dpid, version, suffix, prefix }: DpidRequest): Promise => { + static read = async ({ dpid }: DpidRequest): Promise => { const web3 = createAlchemyWeb3(RPC_URL); const dpidRegistryContract = @@ -172,7 +161,6 @@ export class DpidReader { private static transformRaw = async (result: DpidResult, request: DpidRequest): Promise => { const { prefix, suffix, version } = request; const hex = result.id16; - const output = { msg: `beta.dpid.org resolver`, params: request, hex }; const graphUrl = THE_GRAPH_RESOLVER_URL[prefix]; const graphResult: GraphResult = (await getIndexedResearchObjects(graphUrl, [hex])).researchObjects[0]; @@ -182,7 +170,7 @@ export class DpidReader { // TODO: support version=v1 syntax in Nodes and we can get rid of cleanVersion logic and can pass the version identifier straight through let cleanVersion: number | undefined = undefined; if (version) { - cleanVersion = version?.substring(0, 1) == "v" ? parseInt(version!.substring(1)) - 1 : parseInt(version); + cleanVersion = version?.substring(0, 1) == "v" ? parseInt(version.substring(1)) - 1 : parseInt(version); } logger.debug({ cleanVersion, version }, "CLEAN VER"); @@ -193,7 +181,7 @@ export class DpidReader { logger.debug({ cleanVersion }, "set clean ver"); } - const targetVersion = graphResult.versions[graphResult.versions.length - 1 - cleanVersion!]; + const targetVersion = graphResult.versions[graphResult.versions.length - 1 - cleanVersion]; logger.info({ targetVersion }, "got target"); @@ -217,8 +205,9 @@ export class DpidReader { ) { const res = await fetch(manifestLocation); const researchObject: ResearchObjectV1 = await res.json(); - const dataBucketCandidate: ResearchObjectV1Component = researchObject.components[0]; - if (dataBucketCandidate && dataBucketCandidate.type === ResearchObjectComponentType.DATA_BUCKET) { + const dataBucketCandidate: ResearchObjectV1Component = + researchObject.components.find((a) => a.name == "root") || researchObject.components[0]; + if (dataBucketCandidate) { const dataBucket: DataBucketComponent = dataBucketCandidate as DataBucketComponent; let dataSuffix; if (versionAsData) { @@ -249,11 +238,12 @@ export class DpidReader { }; const defaultGateway = DEFAULT_IPFS_GATEWAY; const selectedGateway = + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (dataSuffix!.length > 0 ? CID_MAP[dataBucket.payload.cid] : defaultGateway) || defaultGateway; const dagTestURl = `${selectedGateway.replace(/\/ipfs$/, "")}/api/v0/dag/get?arg=${arg}`; console.log(dagTestURl, "dagTestURl"); try { - const { data } = await axios({ method: "POST", url: dagTestURl }); // , httpsAgent: agent }); + const { data } = await axios({ method: "POST", url: dagTestURl }); console.log("posted"); if (!data.Data || data.Data["/"].bytes !== "CAE") { return `${selectedGateway}/${arg}`; diff --git a/src/dpid-reader/TheGraphResolver.ts b/src/dpid-reader/TheGraphResolver.ts index e84d229..9e52fe1 100644 --- a/src/dpid-reader/TheGraphResolver.ts +++ b/src/dpid-reader/TheGraphResolver.ts @@ -54,6 +54,7 @@ export const getAllResearchObjectsForDpidRegistrations = async (url: string, dpi cid researchObject { id + owner versions(orderBy: time) { id time diff --git a/src/index.ts b/src/index.ts index 7c5a5b4..943b0fe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,7 +57,7 @@ app.get("/*", async (req: Request, res: Response) => { analytics.log({ dpid: parseInt(dpid), - version: parseInt(version!), + version: parseInt(version ?? "0"), extra: dpidRequest, eventType: LogEventType.DPID_GET, }); @@ -84,9 +84,10 @@ app.get("/*", async (req: Request, res: Response) => { ) ); } catch (err) { + const error = err as Error; res.status(400).send({ - error: (err as any).message, - detail: err, + error: error.message, + detail: error, params: req.params, query: req.query, path: "/*", diff --git a/src/logger.ts b/src/logger.ts index 624c572..c4cc83f 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -41,9 +41,10 @@ const logger = pino({ }); export default logger; +/* eslint-disable @typescript-eslint/no-explicit-any */ function omitBuffer(array: any) { return array.map((obj: any) => { - const { buffer, ...rest } = obj; + const { ...rest } = obj; return rest; }); } diff --git a/ssl/sealstorage-bundle.crt b/ssl/sealstorage-bundle.crt deleted file mode 100644 index a7c381b..0000000 --- a/ssl/sealstorage-bundle.crt +++ /dev/null @@ -1,79 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIE0DCCA7igAwIBAgIBBzANBgkqhkiG9w0BAQsFADCBg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