From 8710760d804ced907c09ce4dffe2ee661cbfa7e7 Mon Sep 17 00:00:00 2001 From: Frank Hinek Date: Thu, 18 May 2023 08:38:42 -0400 Subject: [PATCH] Fix Browser Exports (#68) * Bump dwn-sdk-js to 0.0.32 * fix bundler browser directives in `package.json` * Bump Web5 JS package versions for 0.7.1 release Co-authored-by: Frank Hinek Co-authored-by: Moe Jangda --- package-lock.json | 72 ++++++++++++------------- packages/crypto/.mocharc.json | 3 ++ packages/crypto/package.json | 8 +-- packages/dids/.mocharc.json | 3 ++ packages/dids/package.json | 10 ++-- packages/web5-agent/.mocharc.json | 3 ++ packages/web5-agent/package.json | 8 +-- packages/web5-proxy-agent/.mocharc.json | 3 ++ packages/web5-proxy-agent/package.json | 8 +-- packages/web5-user-agent/package.json | 10 ++-- packages/web5/package.json | 18 +++---- packages/web5/src/dwn-api.ts | 10 +++- packages/web5/src/protocol.ts | 10 ++-- packages/web5/tests/record.spec.ts | 4 +- packages/web5/tests/web5-dwn.spec.ts | 9 ++-- 15 files changed, 100 insertions(+), 79 deletions(-) create mode 100644 packages/crypto/.mocharc.json create mode 100644 packages/dids/.mocharc.json create mode 100644 packages/web5-agent/.mocharc.json create mode 100644 packages/web5-proxy-agent/.mocharc.json diff --git a/package-lock.json b/package-lock.json index f7d7d3caf..adcde6ad2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -928,9 +928,9 @@ "link": true }, "node_modules/@tbd54566975/dwn-sdk-js": { - "version": "0.0.32-unstable-2023-05-15-1350300", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.0.32-unstable-2023-05-15-1350300.tgz", - "integrity": "sha512-ymPmSwfiXv+4G2nGet87RjBA1Xun7V7jIo6YZnNPIFqw+vbn9sMj1ikuydRrlvW1cE2eCznuE8fTzEoe4trcLQ==", + "version": "0.0.32", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.0.32.tgz", + "integrity": "sha512-SijEHpmJDa0I9hC7jn/8P7XeYeFAi9byMc+b36yuCPDiF+j/hLLYGMpZpnbylJ6+ldWqWWEunumeWjxU4zrc3g==", "dependencies": { "@ipld/dag-cbor": "9.0.0", "@js-temporal/polyfill": "0.4.3", @@ -7599,7 +7599,7 @@ }, "packages/crypto": { "name": "@tbd54566975/crypto", - "version": "0.1.0", + "version": "0.1.1", "license": "Apache-2.0", "dependencies": { "ed2curve": "0.3.0", @@ -7635,12 +7635,12 @@ }, "packages/dids": { "name": "@tbd54566975/dids", - "version": "0.1.0", + "version": "0.1.1", "license": "Apache-2.0", "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/crypto": "0.1.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", + "@tbd54566975/crypto": "0.1.1", + "@tbd54566975/dwn-sdk-js": "0.0.32", "cross-fetch": "3.1.5" }, "devDependencies": { @@ -7672,16 +7672,16 @@ }, "packages/web5": { "name": "@tbd54566975/web5", - "version": "0.7.0", + "version": "0.7.1", "license": "Apache-2.0", "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/crypto": "0.1.0", - "@tbd54566975/dids": "0.1.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", - "@tbd54566975/web5-agent": "0.1.0", - "@tbd54566975/web5-proxy-agent": "0.1.0", - "@tbd54566975/web5-user-agent": "0.1.0", + "@tbd54566975/crypto": "0.1.1", + "@tbd54566975/dids": "0.1.1", + "@tbd54566975/dwn-sdk-js": "0.0.32", + "@tbd54566975/web5-agent": "0.1.1", + "@tbd54566975/web5-proxy-agent": "0.1.1", + "@tbd54566975/web5-user-agent": "0.1.1", "cross-fetch": "3.1.5", "level": "8.0.0", "ms": "2.1.3", @@ -7719,10 +7719,10 @@ }, "packages/web5-agent": { "name": "@tbd54566975/web5-agent", - "version": "0.1.0", + "version": "0.1.1", "license": "Apache-2.0", "dependencies": { - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", + "@tbd54566975/dwn-sdk-js": "0.0.32", "readable-stream": "4.4.0" }, "devDependencies": { @@ -7768,10 +7768,10 @@ }, "packages/web5-proxy-agent": { "name": "@tbd54566975/web5-proxy-agent", - "version": "0.1.0", + "version": "0.1.1", "license": "Apache-2.0", "dependencies": { - "@tbd54566975/web5-agent": "0.1.0" + "@tbd54566975/web5-agent": "0.1.1" }, "devDependencies": { "@types/chai": "4.3.0", @@ -7805,12 +7805,12 @@ }, "packages/web5-user-agent": { "name": "@tbd54566975/web5-user-agent", - "version": "0.1.0", + "version": "0.1.1", "license": "Apache-2.0", "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/dids": "0.1.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", + "@tbd54566975/dids": "0.1.1", + "@tbd54566975/dwn-sdk-js": "0.0.32", "abstract-level": "1.0.3", "cross-fetch": "3.1.5", "flat": "5.0.2", @@ -9265,8 +9265,8 @@ "version": "file:packages/dids", "requires": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/crypto": "0.1.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", + "@tbd54566975/crypto": "0.1.1", + "@tbd54566975/dwn-sdk-js": "0.0.32", "@types/chai": "4.3.0", "@types/eslint": "8.37.0", "@types/mocha": "10.0.1", @@ -9292,9 +9292,9 @@ } }, "@tbd54566975/dwn-sdk-js": { - "version": "0.0.32-unstable-2023-05-15-1350300", - "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.0.32-unstable-2023-05-15-1350300.tgz", - "integrity": "sha512-ymPmSwfiXv+4G2nGet87RjBA1Xun7V7jIo6YZnNPIFqw+vbn9sMj1ikuydRrlvW1cE2eCznuE8fTzEoe4trcLQ==", + "version": "0.0.32", + "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.0.32.tgz", + "integrity": "sha512-SijEHpmJDa0I9hC7jn/8P7XeYeFAi9byMc+b36yuCPDiF+j/hLLYGMpZpnbylJ6+ldWqWWEunumeWjxU4zrc3g==", "requires": { "@ipld/dag-cbor": "9.0.0", "@js-temporal/polyfill": "0.4.3", @@ -9352,12 +9352,12 @@ "version": "file:packages/web5", "requires": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/crypto": "0.1.0", - "@tbd54566975/dids": "0.1.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", - "@tbd54566975/web5-agent": "0.1.0", - "@tbd54566975/web5-proxy-agent": "0.1.0", - "@tbd54566975/web5-user-agent": "0.1.0", + "@tbd54566975/crypto": "0.1.1", + "@tbd54566975/dids": "0.1.1", + "@tbd54566975/dwn-sdk-js": "0.0.32", + "@tbd54566975/web5-agent": "0.1.1", + "@tbd54566975/web5-proxy-agent": "0.1.1", + "@tbd54566975/web5-user-agent": "0.1.1", "@types/chai": "4.3.0", "@types/chai-as-promised": "7.1.5", "@types/ms": "0.7.31", @@ -9577,7 +9577,7 @@ "@tbd54566975/web5-agent": { "version": "file:packages/web5-agent", "requires": { - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", + "@tbd54566975/dwn-sdk-js": "0.0.32", "@types/chai": "4.3.0", "@types/eslint": "8.37.0", "@types/mocha": "10.0.1", @@ -9618,7 +9618,7 @@ "@tbd54566975/web5-proxy-agent": { "version": "file:packages/web5-proxy-agent", "requires": { - "@tbd54566975/web5-agent": "0.1.0", + "@tbd54566975/web5-agent": "0.1.1", "@types/chai": "4.3.0", "@types/ed2curve": "0.2.2", "@types/eslint": "8.37.0", @@ -9650,8 +9650,8 @@ "requires": { "@decentralized-identity/ion-tools": "1.0.7", "@playwright/test": "1.33.0", - "@tbd54566975/dids": "0.1.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", + "@tbd54566975/dids": "0.1.1", + "@tbd54566975/dwn-sdk-js": "0.0.32", "@types/flat": "5.0.2", "@typescript-eslint/eslint-plugin": "5.59.0", "@typescript-eslint/parser": "5.59.0", diff --git a/packages/crypto/.mocharc.json b/packages/crypto/.mocharc.json new file mode 100644 index 000000000..2e8b2e076 --- /dev/null +++ b/packages/crypto/.mocharc.json @@ -0,0 +1,3 @@ +{ + "enable-source-maps": true +} \ No newline at end of file diff --git a/packages/crypto/package.json b/packages/crypto/package.json index c67bd1697..6a6d72f53 100644 --- a/packages/crypto/package.json +++ b/packages/crypto/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/crypto", - "version": "0.1.0", + "version": "0.1.1", "description": "TBD crypto library", "type": "module", "main": "./dist/cjs/main.cjs", @@ -52,8 +52,8 @@ } }, "browser": { - "./dist/esm/index.js": "./dist/browser.mjs", - "./dist/cjs/index.js": "./dist/browser.js", + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", "types": "./dist/types/main.d.ts" }, "keywords": [ @@ -96,4 +96,4 @@ "rimraf": "4.4.0", "typescript": "5.0.4" } -} +} \ No newline at end of file diff --git a/packages/dids/.mocharc.json b/packages/dids/.mocharc.json new file mode 100644 index 000000000..2e8b2e076 --- /dev/null +++ b/packages/dids/.mocharc.json @@ -0,0 +1,3 @@ +{ + "enable-source-maps": true +} \ No newline at end of file diff --git a/packages/dids/package.json b/packages/dids/package.json index 8e197033a..12ad19fee 100644 --- a/packages/dids/package.json +++ b/packages/dids/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/dids", - "version": "0.1.0", + "version": "0.1.1", "description": "TBD DIDs library", "type": "module", "main": "./dist/cjs/main.cjs", @@ -52,8 +52,8 @@ } }, "browser": { - "./dist/esm/index.js": "./dist/browser.mjs", - "./dist/cjs/index.js": "./dist/browser.js", + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", "types": "./dist/types/main.d.ts" }, "keywords": [ @@ -74,8 +74,8 @@ }, "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/crypto": "0.1.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", + "@tbd54566975/crypto": "0.1.1", + "@tbd54566975/dwn-sdk-js": "0.0.32", "cross-fetch": "3.1.5" }, "devDependencies": { diff --git a/packages/web5-agent/.mocharc.json b/packages/web5-agent/.mocharc.json new file mode 100644 index 000000000..2e8b2e076 --- /dev/null +++ b/packages/web5-agent/.mocharc.json @@ -0,0 +1,3 @@ +{ + "enable-source-maps": true +} \ No newline at end of file diff --git a/packages/web5-agent/package.json b/packages/web5-agent/package.json index 3ef1d25d8..ea6c1b606 100644 --- a/packages/web5-agent/package.json +++ b/packages/web5-agent/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/web5-agent", - "version": "0.1.0", + "version": "0.1.1", "description": "Web5 Agent", "type": "module", "main": "./dist/cjs/main.cjs", @@ -52,8 +52,8 @@ } }, "browser": { - "./dist/esm/index.js": "./dist/browser.mjs", - "./dist/cjs/index.js": "./dist/browser.js", + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", "types": "./dist/types/main.d.ts" }, "keywords": [ @@ -71,7 +71,7 @@ }, "dependencies": { "readable-stream": "4.4.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300" + "@tbd54566975/dwn-sdk-js": "0.0.32" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "5.59.0", diff --git a/packages/web5-proxy-agent/.mocharc.json b/packages/web5-proxy-agent/.mocharc.json new file mode 100644 index 000000000..2e8b2e076 --- /dev/null +++ b/packages/web5-proxy-agent/.mocharc.json @@ -0,0 +1,3 @@ +{ + "enable-source-maps": true +} \ No newline at end of file diff --git a/packages/web5-proxy-agent/package.json b/packages/web5-proxy-agent/package.json index 4aefdadc7..3a7017c6f 100644 --- a/packages/web5-proxy-agent/package.json +++ b/packages/web5-proxy-agent/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/web5-proxy-agent", - "version": "0.1.0", + "version": "0.1.1", "description": "Web5 Proxy Agent", "type": "module", "main": "./dist/cjs/main.cjs", @@ -52,8 +52,8 @@ } }, "browser": { - "./dist/esm/index.js": "./dist/browser.mjs", - "./dist/cjs/index.js": "./dist/browser.js", + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", "types": "./dist/types/main.d.ts" }, "keywords": [ @@ -70,7 +70,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@tbd54566975/web5-agent": "0.1.0" + "@tbd54566975/web5-agent": "0.1.1" }, "devDependencies": { "@types/chai": "4.3.0", diff --git a/packages/web5-user-agent/package.json b/packages/web5-user-agent/package.json index 93e99617d..12e5d5855 100644 --- a/packages/web5-user-agent/package.json +++ b/packages/web5-user-agent/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/web5-user-agent", - "version": "0.1.0", + "version": "0.1.1", "description": "Web5 User Agent", "type": "module", "main": "./dist/cjs/main.cjs", @@ -52,8 +52,8 @@ } }, "browser": { - "./dist/esm/index.js": "./dist/browser.mjs", - "./dist/cjs/index.js": "./dist/browser.js", + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", "types": "./dist/types/main.d.ts" }, "keywords": [ @@ -71,8 +71,8 @@ }, "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/dids": "0.1.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", + "@tbd54566975/dids": "0.1.1", + "@tbd54566975/dwn-sdk-js": "0.0.32", "abstract-level": "1.0.3", "cross-fetch": "3.1.5", "flat": "5.0.2", diff --git a/packages/web5/package.json b/packages/web5/package.json index 1451a1135..71631e526 100644 --- a/packages/web5/package.json +++ b/packages/web5/package.json @@ -1,6 +1,6 @@ { "name": "@tbd54566975/web5", - "version": "0.7.0", + "version": "0.7.1", "description": "SDK for accessing the features and capabilities of Web5", "type": "module", "main": "./dist/cjs/main.cjs", @@ -52,8 +52,8 @@ } }, "browser": { - "./dist/esm/index.js": "./dist/browser.mjs", - "./dist/cjs/index.js": "./dist/browser.js", + "./dist/esm/main.mjs": "./dist/browser.mjs", + "./dist/cjs/main.cjs": "./dist/browser.js", "types": "./dist/types/main.d.ts" }, "keywords": [ @@ -75,12 +75,12 @@ }, "dependencies": { "@decentralized-identity/ion-tools": "1.0.7", - "@tbd54566975/crypto": "0.1.0", - "@tbd54566975/dids": "0.1.0", - "@tbd54566975/dwn-sdk-js": "0.0.32-unstable-2023-05-15-1350300", - "@tbd54566975/web5-agent": "0.1.0", - "@tbd54566975/web5-proxy-agent": "0.1.0", - "@tbd54566975/web5-user-agent": "0.1.0", + "@tbd54566975/crypto": "0.1.1", + "@tbd54566975/dids": "0.1.1", + "@tbd54566975/dwn-sdk-js": "0.0.32", + "@tbd54566975/web5-agent": "0.1.1", + "@tbd54566975/web5-proxy-agent": "0.1.1", + "@tbd54566975/web5-user-agent": "0.1.1", "cross-fetch": "3.1.5", "level": "8.0.0", "ms": "2.1.3", diff --git a/packages/web5/src/dwn-api.ts b/packages/web5/src/dwn-api.ts index 61f8e2269..5c89f2c68 100644 --- a/packages/web5/src/dwn-api.ts +++ b/packages/web5/src/dwn-api.ts @@ -47,7 +47,7 @@ export type ProtocolsQueryRequest = { } export type ProtocolsQueryResponse = { - protocols: ProtocolsQueryReplyEntry[]; + protocols: Protocol[]; status: MessageReply['status']; } @@ -158,7 +158,13 @@ export class DwnApi { }); const { reply: { entries, status } } = agentResponse; - const protocols = entries as ProtocolsQueryReplyEntry[]; + // const protocols = entries as ProtocolsQueryReplyEntry[]; + + const protocols = entries.map((entry: ProtocolsQueryReplyEntry) => { + const metadata = { author: this.connectedDid, }; + + return new Protocol(this.web5Agent, entry, metadata); + }); return { protocols, status }; } diff --git a/packages/web5/src/protocol.ts b/packages/web5/src/protocol.ts index 699b7453f..291230e17 100644 --- a/packages/web5/src/protocol.ts +++ b/packages/web5/src/protocol.ts @@ -5,7 +5,7 @@ import type { ProtocolsConfigure } from '@tbd54566975/dwn-sdk-js'; export type ProtocolsConfigureMessage = ProtocolsConfigure['message']; type ProtocolMetadata = { author: string; - messageCid: string; + messageCid?: string; }; export class Protocol { @@ -13,6 +13,10 @@ export class Protocol { #web5Agent: Web5Agent; #protocolsConfigureMessage: ProtocolsConfigureMessage; + get definition() { + return this.#protocolsConfigureMessage.descriptor.definition; + } + constructor(web5Agent: Web5Agent, protocolsConfigureMessage: ProtocolsConfigureMessage, metadata: ProtocolMetadata) { this.#metadata = metadata; this.#web5Agent = web5Agent; @@ -23,11 +27,11 @@ export class Protocol { return this.#protocolsConfigureMessage; } - async send() { + async send(target: string) { const { reply } = await this.#web5Agent.sendDwnRequest({ messageType : 'ProtocolsConfigure', author : this.#metadata.author, - target : this.#metadata.author, + target : target, messageCid : this.#metadata.messageCid }); diff --git a/packages/web5/tests/record.spec.ts b/packages/web5/tests/record.spec.ts index 2fed2a0b9..c512060d2 100644 --- a/packages/web5/tests/record.spec.ts +++ b/packages/web5/tests/record.spec.ts @@ -288,7 +288,7 @@ describe('Record', () => { expect(aliceStatus.code).to.equal(202); expect(aliceProtocol).to.exist; - const { status: alicePushStatus } = await aliceProtocol!.send(); + const { status: alicePushStatus } = await aliceProtocol!.send(didAllKeys); expect(alicePushStatus.code).to.equal(202); // install a protocol for bob @@ -305,7 +305,7 @@ describe('Record', () => { expect(bobStatus.code).to.equal(202); expect(bobProtocol).to.exist; - const { status: bobPushStatus } = await bobProtocol!.send(); + const { status: bobPushStatus } = await bobProtocol!.send(bobDid); expect(bobPushStatus.code).to.equal(202); // alice writes a message to her own dwn diff --git a/packages/web5/tests/web5-dwn.spec.ts b/packages/web5/tests/web5-dwn.spec.ts index 6bceeb22d..f178577d2 100644 --- a/packages/web5/tests/web5-dwn.spec.ts +++ b/packages/web5/tests/web5-dwn.spec.ts @@ -72,11 +72,10 @@ describe('web5.dwn', () => { expect(response.status.code).to.equal(200); expect(response.protocols.length).to.equal(1); - expect(response.protocols[0].descriptor).to.have.property('definition'); - expect(response.protocols[0].descriptor.definition).to.have.property('types'); - expect(response.protocols[0].descriptor.definition).to.have.property('protocol'); - expect(response.protocols[0].descriptor.definition.protocol).to.equal(emailProtocolDefinition.protocol); - expect(response.protocols[0].descriptor.definition).to.have.property('structure'); + expect(response.protocols[0].definition).to.have.property('types'); + expect(response.protocols[0].definition).to.have.property('protocol'); + expect(response.protocols[0].definition.protocol).to.equal(emailProtocolDefinition.protocol); + expect(response.protocols[0].definition).to.have.property('structure'); }); });