diff --git a/package-lock.json b/package-lock.json index 245996f..d323bd6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@web5/dwn-server", - "version": "0.5.0", + "version": "0.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@web5/dwn-server", - "version": "0.5.0", + "version": "0.6.0", "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.4.7", - "@tbd54566975/dwn-sql-store": "0.6.7", + "@tbd54566975/dwn-sdk-js": "0.5.1", + "@tbd54566975/dwn-sql-store": "0.6.8", "@web5/common": "^1.0.2", "@web5/crypto": "^1.0.3", "@web5/dids": "^1.1.3", @@ -607,9 +607,9 @@ "dev": true }, "node_modules/@tbd54566975/dwn-sdk-js": { - "version": "0.4.7", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.4.7.tgz", - "integrity": "sha512-VYaLT4FKdHfVvUPZbicUpF77erkOSi1xBP/EVQIpnp0khPujp2lYcojbRcw4c4JR23CrRvLPy/iWXmEhdP8LqA==", + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.5.1.tgz", + "integrity": "sha512-4xfDttiXOzs7h3PHODflHxHP7Z1HlNod6BN+HX6elXKlqOlBueORrzB72BnzVBbv35eDRJR5w2upmGsUoq3dGg==", "dependencies": { "@ipld/dag-cbor": "9.0.3", "@js-temporal/polyfill": "0.4.4", @@ -710,12 +710,12 @@ } }, "node_modules/@tbd54566975/dwn-sql-store": { - "version": "0.6.7", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sql-store/-/dwn-sql-store-0.6.7.tgz", - "integrity": "sha512-5v/BudrItBx8UUMEIH42nMBwykpM9ZyBpMERmWwJn06Xe47wv+ojkDhVX000Npuv4q+bsLv0lQhCaIAmKcMlaQ==", + "version": "0.6.8", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sql-store/-/dwn-sql-store-0.6.8.tgz", + "integrity": "sha512-2F1ACH9GKUBQm8kEKzyLdWw36Dakhx+Z8HAbPsNqbj9w8qht/AEykTJNhvcAi07G2Un83PfqCYDJURs8tM92tA==", "dependencies": { "@ipld/dag-cbor": "9.0.5", - "@tbd54566975/dwn-sdk-js": "0.4.7", + "@tbd54566975/dwn-sdk-js": "0.5.1", "kysely": "0.26.3", "multiformats": "12.0.1", "readable-stream": "4.4.2" diff --git a/package.json b/package.json index e129d92..d58a537 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@web5/dwn-server", "type": "module", - "version": "0.5.0", + "version": "0.6.0", "files": [ "dist", "src" @@ -26,8 +26,8 @@ "url": "https://github.com/TBD54566975/dwn-server/issues" }, "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.4.7", - "@tbd54566975/dwn-sql-store": "0.6.7", + "@tbd54566975/dwn-sdk-js": "0.5.1", + "@tbd54566975/dwn-sql-store": "0.6.8", "@web5/common": "^1.0.2", "@web5/crypto": "^1.0.3", "@web5/dids": "^1.1.3", diff --git a/src/config.ts b/src/config.ts index 53a550a..f2a27fb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,6 +14,7 @@ export const config = { /** * The base external URL of this DWN. * This is used to construct URL paths such as the `Request URI` in the Web5 Connect flow. + * Should NOT be pointing to `localhost` for production use. */ baseUrl: process.env.DWN_BASE_URL || 'http://localhost:3000', diff --git a/src/http-api.ts b/src/http-api.ts index 4ee110c..d373028 100644 --- a/src/http-api.ts +++ b/src/http-api.ts @@ -1,3 +1,4 @@ +import type { RecordsReadReply } from '@tbd54566975/dwn-sdk-js'; import { type Dwn, DateSort, RecordsRead, RecordsQuery, ProtocolsQuery } from '@tbd54566975/dwn-sdk-js'; import cors from 'cors'; @@ -111,13 +112,12 @@ export class HttpApi { const leadTailSlashRegex = /^\/|\/$/; - function readReplyHandler(res, reply): any { + function readReplyHandler(res, reply: RecordsReadReply): any { if (reply.status.code === 200) { - if (reply?.record?.data) { - const stream = reply.record.data; - delete reply.record.data; + if (reply?.entry?.data) { + const stream = reply.entry.data; - res.setHeader('content-type', reply.record.descriptor.dataFormat); + res.setHeader('content-type', reply.entry.recordsWrite.descriptor.dataFormat); res.setHeader('dwn-response', JSON.stringify(reply)); return stream.pipe(res); @@ -292,9 +292,9 @@ export class HttpApi { }); this.#api.post('/', async (req: Request, res) => { - const dwnRequest = req.headers['dwn-request'] as any; + const dwnRpcRequestString = req.headers['dwn-request'] as string; - if (!dwnRequest) { + if (!dwnRpcRequestString) { const reply = createJsonRpcErrorResponse(uuidv4(), JsonRpcErrorCodes.BadRequest, 'request payload required.'); return res.status(400).json(reply); @@ -302,7 +302,7 @@ export class HttpApi { let dwnRpcRequest: JsonRpcRequest; try { - dwnRpcRequest = JSON.parse(dwnRequest); + dwnRpcRequest = JSON.parse(dwnRpcRequestString); } catch (e) { const reply = createJsonRpcErrorResponse(uuidv4(), JsonRpcErrorCodes.BadRequest, e.message); diff --git a/src/json-rpc-handlers/dwn/process-message.ts b/src/json-rpc-handlers/dwn/process-message.ts index 6d66c66..8ec31dc 100644 --- a/src/json-rpc-handlers/dwn/process-message.ts +++ b/src/json-rpc-handlers/dwn/process-message.ts @@ -80,14 +80,11 @@ export const handleDwnProcessMessage: JsonRpcHandler = async ( }); - const { record, entry } = reply; + const { entry } = reply; // RecordsRead or MessagesRead messages optionally return data as a stream to accommodate large amounts of data // we remove the data stream from the reply that will be serialized and return it as a separate property in the response payload. let recordDataStream: IsomorphicReadable; - if (record !== undefined && record.data !== undefined) { - recordDataStream = reply.record.data; - delete reply.record.data; // not serializable via JSON - } else if (entry !== undefined && entry.data !== undefined) { + if (entry !== undefined && entry.data !== undefined) { recordDataStream = entry.data; delete reply.entry.data; // not serializable via JSON } diff --git a/tests/common-scenario-validator.ts b/tests/common-scenario-validator.ts index 4d755b2..a302b0a 100644 --- a/tests/common-scenario-validator.ts +++ b/tests/common-scenario-validator.ts @@ -133,7 +133,7 @@ export default class CommonScenarioValidator { expect(recordsReadJsonRpcResponse.id).to.equal(recordsReadRequestId); expect(recordsReadJsonRpcResponse.error).to.not.exist; expect(recordsReadJsonRpcResponse.result.reply.status.code).to.equal(200); - expect(recordsReadJsonRpcResponse.result.reply.record).to.exist; + expect(recordsReadJsonRpcResponse.result.reply.entry.recordsWrite).to.exist; // can't get response as stream from supertest :( const cid = await Cid.computeDagPbCidFromStream(recordsReadResponse.body as Readable); diff --git a/tests/http-api.spec.ts b/tests/http-api.spec.ts index 6a6b6c0..35f81a7 100644 --- a/tests/http-api.spec.ts +++ b/tests/http-api.spec.ts @@ -770,10 +770,10 @@ describe('http api', function () { expect(blob.size).to.equal(size); // get dwn message response - const { status, record } = getDwnResponse(recordReadResponse); + const { status, entry } = getDwnResponse(recordReadResponse); expect(status.code).to.equal(200); - expect(record).to.exist; - expect(record.recordId).to.equal(recordsWrite.message.recordId); + expect(entry).to.exist; + expect(entry.recordsWrite.recordId).to.equal(recordsWrite.message.recordId); }); it('removes the trailing slash from the protocol path', async function () {