diff --git a/src/dpid-reader/DpidReader.ts b/src/dpid-reader/DpidReader.ts index 6f7273d..63296b6 100644 --- a/src/dpid-reader/DpidReader.ts +++ b/src/dpid-reader/DpidReader.ts @@ -138,14 +138,24 @@ export class DpidReader { private static transformWeb = async (result: DpidResult, request: DpidRequest) => { const { prefix, suffix, version, domain } = request; const uuid = result.id64; + // debugger; const output = { msg: `beta.dpid.org resolver`, params: request, uuid }; // TODO: support version=v1 syntax in Nodes and we can get rid of cleanVersion logic - const cleanVersion: string | undefined = !version + let cleanVersion: string | undefined = !version ? undefined : version?.substring(0, 1) == "v" ? version : `v${parseInt(version || "0") + 1}`; + + if (cleanVersion === "vNaN") { + /** + ** Not a valid version, so pass along the original string the user entered, it may route to other + ** codex entities or the DPID may be an alias to another external non research object entity. + */ + cleanVersion = version; + } + let environment = prefix === "beta-dev" || domain === "dev-beta.dpid.org" ? "-dev" : ""; if (domain === "staging-beta.dpid.org") { environment = "-staging"; diff --git a/src/index.ts b/src/index.ts index 943b0fe..947e13b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,13 +61,13 @@ app.get("/*", async (req: Request, res: Response) => { extra: dpidRequest, eventType: LogEventType.DPID_GET, }); - const dpidResult = await DpidReader.read(dpidRequest); if (dpidResult.id16 == "0x0") { logger.error("dpid not found"); throw new Error("dpid not found"); } const redir = await DpidReader.transform(dpidResult, dpidRequest); + // debugger; // res.send({ output, redir }); if (dpidRequest.jsonld) { res.setHeader("Content-Type", "application/ld+json").send(redir); diff --git a/test/basics.spec.ts b/test/basics.spec.ts index a884b15..22ddc11 100644 --- a/test/basics.spec.ts +++ b/test/basics.spec.ts @@ -125,5 +125,101 @@ describe("dPID resolution", function () { assert.equal(value, expected, "incorrect resolution"); }); }); + it("should handle a generic attestations route", async () => { + await request(app) + .get("/46/attestations") + .expect(302) + .then((res) => { + const value = res.header["location"]; + + const expected = "https://nodes.desci.com/dpid/46/attestations"; + assert.equal(value, expected, "incorrect resolution"); + }) + .catch((err) => { + if (err) { + assert.fail(err); + } + }); + }); + it("should handle a versioned(V) generic attestations route", async () => { + await request(app) + .get("/46/v2/attestations") + .expect(302) + .then((res) => { + const value = res.header["location"]; + + const expected = "https://nodes.desci.com/dpid/46/v2/attestations"; + assert.equal(value, expected, "incorrect resolution"); + }) + .catch((err) => { + if (err) { + assert.fail(err); + } + }); + }); + it("should handle a versioned(I) generic attestations route", async () => { + await request(app) + .get("/46/2/attestations") + .expect(302) + .then((res) => { + const value = res.header["location"]; + + const expected = "https://nodes.desci.com/dpid/46/v3/attestations"; + assert.equal(value, expected, "incorrect resolution"); + }) + .catch((err) => { + if (err) { + assert.fail(err); + } + }); + }); + it("should handle a specific attestations route with an attestation slug", async () => { + await request(app) + .get("/46/attestations/scientific-manuscript") + .expect(302) + .then((res) => { + const value = res.header["location"]; + + const expected = "https://nodes.desci.com/dpid/46/attestations/scientific-manuscript"; + assert.equal(value, expected, "incorrect resolution"); + }) + .catch((err) => { + if (err) { + assert.fail(err); + } + }); + }); + it("should handle a versioned(V) attestations route with an attestation slug", async () => { + await request(app) + .get("/46/v2/attestations/scientific-manuscript") + .expect(302) + .then((res) => { + const value = res.header["location"]; + + const expected = "https://nodes.desci.com/dpid/46/v2/attestations/scientific-manuscript"; + assert.equal(value, expected, "incorrect resolution"); + }) + .catch((err) => { + if (err) { + assert.fail(err); + } + }); + }); + it("should handle a versioned(I) attestations route with an attestation slug", async () => { + await request(app) + .get("/46/2/attestations/scientific-manuscript") + .expect(302) + .then((res) => { + const value = res.header["location"]; + + const expected = "https://nodes.desci.com/dpid/46/v3/attestations/scientific-manuscript"; + assert.equal(value, expected, "incorrect resolution"); + }) + .catch((err) => { + if (err) { + assert.fail(err); + } + }); + }); }); }); diff --git a/tsconfig.json b/tsconfig.json index 6d6eca0..b4e20c8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,8 +10,8 @@ "strict": true, "skipLibCheck": true, "baseUrl": "./src", + "inlineSources": true, + "inlineSourceMap": true }, - "include": [ - "src/**/*" - ], -} \ No newline at end of file + "include": ["src/**/*"] +}