Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: assign a UUID to all BaseProvider requests #399

Closed
wants to merge 3 commits into from
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
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const baseConfig = {
global: {
branches: 67.6,
functions: 69.91,
lines: 69.51,
statements: 69.52,
lines: 69.58,
statements: 69.59,
},
},

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"extension-port-stream": "^4.1.0",
"fast-deep-equal": "^3.1.3",
"is-stream": "^2.0.0",
"readable-stream": "^3.6.2"
"readable-stream": "^3.6.2",
"uuid": "^11.0.5"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^3.0.4",
Expand All @@ -124,7 +125,6 @@
"@types/chrome": "^0.0.233",
"@types/jest": "^28.1.6",
"@types/node": "^20.14.9",
"@types/uuid": "^9.0.1",
"@types/webextension-polyfill": "^0.10.0",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
Expand Down
3 changes: 3 additions & 0 deletions src/BaseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
Json,
} from '@metamask/utils';
import dequal from 'fast-deep-equal';
import { v4 as uuidV4 } from 'uuid';

import messages from './messages';
import type { ConsoleLike, Maybe } from './utils';
Expand Down Expand Up @@ -208,9 +209,11 @@ export abstract class BaseProvider extends SafeEventEmitter {
const payload =
params === undefined || params === null
? {
id: uuidV4(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Do we want to do this in _rpcRequest? I see that we already provide a default value for jsonrpc if it's not given so it seems like this check for id may belong there too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More importantly, can we add a test for this?

method,
}
: {
id: uuidV4(),
method,
params,
};
Expand Down
18 changes: 10 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@ __metadata:
"@types/chrome": ^0.0.233
"@types/jest": ^28.1.6
"@types/node": ^20.14.9
"@types/uuid": ^9.0.1
"@types/webextension-polyfill": ^0.10.0
"@typescript-eslint/eslint-plugin": ^5.43.0
"@typescript-eslint/parser": ^5.43.0
Expand Down Expand Up @@ -1148,6 +1147,7 @@ __metadata:
ts-node: ^10.7.0
typedoc: ^0.23.15
typescript: ~5.6.3
uuid: ^11.0.5
webextension-polyfill: ^0.12.0
peerDependencies:
webextension-polyfill: ^0.10.0 || ^0.11.0 || ^0.12.0
Expand Down Expand Up @@ -1732,13 +1732,6 @@ __metadata:
languageName: node
linkType: hard

"@types/uuid@npm:^9.0.1":
version: 9.0.1
resolution: "@types/uuid@npm:9.0.1"
checksum: c472b8a77cbeded4bc529220b8611afa39bd64677f507838f8083d8aac8033b1f88cb9ddaa2f8589e0dcd2317291d0f6e1379f82d5ceebd6f74f3b4825288e00
languageName: node
linkType: hard

"@types/webextension-polyfill@npm:^0.10.0":
version: 0.10.0
resolution: "@types/webextension-polyfill@npm:0.10.0"
Expand Down Expand Up @@ -7496,6 +7489,15 @@ __metadata:
languageName: node
linkType: hard

"uuid@npm:^11.0.5":
version: 11.0.5
resolution: "uuid@npm:11.0.5"
bin:
uuid: dist/esm/bin/uuid
checksum: 8a8ed824c77ccc9387eed3049e75268a862379f0d41222716020743c438f31e9acfbe6495bd4cb1a7727c91fcf5ae20be40b306826a62c96f9ff42db48e8ed93
languageName: node
linkType: hard

"uuid@npm:^9.0.1":
version: 9.0.1
resolution: "uuid@npm:9.0.1"
Expand Down
Loading