diff --git a/.babelrc b/.babelrc index 6f4f54a93f1..6e6720bbf11 100644 --- a/.babelrc +++ b/.babelrc @@ -1,12 +1,15 @@ { "sourceMaps": true, "presets": [ - ["@babel/preset-env", { - "targets": { - "node": 10 - }, - "modules": "commonjs" - }], + [ + "@babel/preset-env", + { + "targets": { + "node": 10 + }, + "modules": "commonjs" + } + ], "@babel/preset-typescript" ], "plugins": [ diff --git a/.eslintrc.js b/.eslintrc.js index 3059df17f4d..fd77e6c5e42 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,12 +1,6 @@ module.exports = { - plugins: [ - "matrix-org", - "import", - ], - extends: [ - "plugin:matrix-org/babel", - "plugin:import/typescript", - ], + plugins: ["matrix-org", "import", "jsdoc"], + extends: ["plugin:matrix-org/babel", "plugin:import/typescript"], env: { browser: true, node: true, @@ -27,72 +21,95 @@ module.exports = { "padded-blocks": ["error"], "no-extend-native": ["error"], "camelcase": ["error"], - "no-multi-spaces": ["error", { "ignoreEOLComments": true }], - "space-before-function-paren": ["error", { - "anonymous": "never", - "named": "never", - "asyncArrow": "always", - }], + "no-multi-spaces": ["error", { ignoreEOLComments: true }], + "space-before-function-paren": [ + "error", + { + anonymous: "never", + named: "never", + asyncArrow: "always", + }, + ], "arrow-parens": "off", "prefer-promise-reject-errors": "off", - "quotes": "off", - "indent": "off", "no-constant-condition": "off", "no-async-promise-executor": "off", // We use a `logger` intermediary module "no-console": "error", // restrict EventEmitters to force callers to use TypedEventEmitter - "no-restricted-imports": ["error", { - name: "events", - message: "Please use TypedEventEmitter instead" - }], - - "import/no-restricted-paths": ["error", { - "zones": [{ - "target": "./src/", - "from": "./src/index.ts", - "message": "The package index is dynamic between src and lib depending on " + - "whether release or development, target the specific module or matrix.ts instead", - }], - }], - }, - overrides: [{ - files: [ - "**/*.ts", + "no-restricted-imports": [ + "error", + { + name: "events", + message: "Please use TypedEventEmitter instead", + }, ], - extends: [ - "plugin:matrix-org/typescript", + + "import/no-restricted-paths": [ + "error", + { + zones: [ + { + target: "./src/", + from: "./src/index.ts", + message: + "The package index is dynamic between src and lib depending on " + + "whether release or development, target the specific module or matrix.ts instead", + }, + ], + }, ], - rules: { - // TypeScript has its own version of this - "@babel/no-invalid-this": "off", + }, + overrides: [ + { + files: ["**/*.ts"], + plugins: ["eslint-plugin-tsdoc"], + extends: ["plugin:matrix-org/typescript"], + rules: { + // TypeScript has its own version of this + "@babel/no-invalid-this": "off", - // We're okay being explicit at the moment - "@typescript-eslint/no-empty-interface": "off", - // We disable this while we're transitioning - "@typescript-eslint/no-explicit-any": "off", - // We'd rather not do this but we do - "@typescript-eslint/ban-ts-comment": "off", - // We're okay with assertion errors when we ask for them - "@typescript-eslint/no-non-null-assertion": "off", + // We're okay being explicit at the moment + "@typescript-eslint/no-empty-interface": "off", + // We disable this while we're transitioning + "@typescript-eslint/no-explicit-any": "off", + // We'd rather not do this but we do + "@typescript-eslint/ban-ts-comment": "off", + // We're okay with assertion errors when we ask for them + "@typescript-eslint/no-non-null-assertion": "off", - // The non-TypeScript rule produces false positives - "func-call-spacing": "off", - "@typescript-eslint/func-call-spacing": ["error"], + // The non-TypeScript rule produces false positives + "func-call-spacing": "off", + "@typescript-eslint/func-call-spacing": ["error"], - "quotes": "off", - // We use a `logger` intermediary module - "no-console": "error", + "quotes": "off", + // We use a `logger` intermediary module + "no-console": "error", + }, }, - }, { - files: [ - "spec/**/*.ts", - ], - rules: { - // We don't need super strict typing in test utilities - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/explicit-member-accessibility": "off", + { + // We don't need amazing docs in our spec files + files: ["src/**/*.ts"], + rules: { + "tsdoc/syntax": "error", + // We use some select jsdoc rules as the tsdoc linter has only one rule + "jsdoc/no-types": "error", + "jsdoc/empty-tags": "error", + "jsdoc/check-property-names": "error", + "jsdoc/check-values": "error", + // These need a bit more work before we can enable + // "jsdoc/check-param-names": "error", + // "jsdoc/check-indentation": "error", + }, }, - }], + { + files: ["spec/**/*.ts"], + rules: { + // We don't need super strict typing in test utilities + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/explicit-member-accessibility": "off", + }, + }, + ], }; diff --git a/.github/renovate.json b/.github/renovate.json index 91ed4799766..76320426d9e 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -1,6 +1,4 @@ { - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "github>matrix-org/renovate-config-element-web" - ] + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["github>matrix-org/renovate-config-element-web"] } diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 10bda8e205f..32deb2f2b57 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -1,30 +1,30 @@ name: Backport on: - pull_request_target: - types: - - closed - - labeled - branches: - - develop + pull_request_target: + types: + - closed + - labeled + branches: + - develop jobs: - backport: - name: Backport - runs-on: ubuntu-latest - # Only react to merged PRs for security reasons. - # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target. - if: > - github.event.pull_request.merged - && ( - github.event.action == 'closed' - || ( - github.event.action == 'labeled' - && contains(github.event.label.name, 'backport') - ) - ) - steps: - - uses: tibdex/backport@v2 - with: - labels_template: "<%= JSON.stringify([...labels, 'X-Release-Blocker']) %>" - # We can't use GITHUB_TOKEN here or CI won't run on the new PR - github_token: ${{ secrets.ELEMENT_BOT_TOKEN }} + backport: + name: Backport + runs-on: ubuntu-latest + # Only react to merged PRs for security reasons. + # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target. + if: > + github.event.pull_request.merged + && ( + github.event.action == 'closed' + || ( + github.event.action == 'labeled' + && contains(github.event.label.name, 'backport') + ) + ) + steps: + - uses: tibdex/backport@v2 + with: + labels_template: "<%= JSON.stringify([...labels, 'X-Release-Blocker']) %>" + # We can't use GITHUB_TOKEN here or CI won't run on the new PR + github_token: ${{ secrets.ELEMENT_BOT_TOKEN }} diff --git a/.github/workflows/docs-pr-netlify.yaml b/.github/workflows/docs-pr-netlify.yaml index 4e1b09c5b0f..c53f981b6ea 100644 --- a/.github/workflows/docs-pr-netlify.yaml +++ b/.github/workflows/docs-pr-netlify.yaml @@ -1,34 +1,34 @@ name: Deploy documentation PR preview on: - workflow_run: - workflows: [ "Static Analysis" ] - types: - - completed + workflow_run: + workflows: ["Static Analysis"] + types: + - completed jobs: - netlify: - if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' - runs-on: ubuntu-latest - steps: - # There's a 'download artifact' action, but it hasn't been updated for the workflow_run action - # (https://github.com/actions/download-artifact/issues/60) so instead we get this mess: - - name: 📥 Download artifact - uses: dawidd6/action-download-artifact@e6e25ac3a2b93187502a8be1ef9e9603afc34925 # v2.24.2 - with: - workflow: static_analysis.yml - run_id: ${{ github.event.workflow_run.id }} - name: docs - path: docs + netlify: + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' + runs-on: ubuntu-latest + steps: + # There's a 'download artifact' action, but it hasn't been updated for the workflow_run action + # (https://github.com/actions/download-artifact/issues/60) so instead we get this mess: + - name: 📥 Download artifact + uses: dawidd6/action-download-artifact@e6e25ac3a2b93187502a8be1ef9e9603afc34925 # v2.24.2 + with: + workflow: static_analysis.yml + run_id: ${{ github.event.workflow_run.id }} + name: docs + path: docs - - name: 📤 Deploy to Netlify - uses: matrix-org/netlify-pr-preview@v1 - with: - path: docs - owner: ${{ github.event.workflow_run.head_repository.owner.login }} - branch: ${{ github.event.workflow_run.head_branch }} - revision: ${{ github.event.workflow_run.head_sha }} - token: ${{ secrets.NETLIFY_AUTH_TOKEN }} - site_id: ${{ secrets.NETLIFY_SITE_ID }} - desc: Documentation preview - deployment_env: PR Documentation Preview + - name: 📤 Deploy to Netlify + uses: matrix-org/netlify-pr-preview@v1 + with: + path: docs + owner: ${{ github.event.workflow_run.head_repository.owner.login }} + branch: ${{ github.event.workflow_run.head_branch }} + revision: ${{ github.event.workflow_run.head_sha }} + token: ${{ secrets.NETLIFY_AUTH_TOKEN }} + site_id: ${{ secrets.NETLIFY_SITE_ID }} + desc: Documentation preview + deployment_env: PR Documentation Preview diff --git a/.github/workflows/release-npm.yml b/.github/workflows/release-npm.yml index 84d88ea5e5e..88f452faf5a 100644 --- a/.github/workflows/release-npm.yml +++ b/.github/workflows/release-npm.yml @@ -1,41 +1,41 @@ # Must only be called from `release#published` triggers name: Publish to npm on: - workflow_call: - secrets: - NPM_TOKEN: - required: true + workflow_call: + secrets: + NPM_TOKEN: + required: true jobs: - npm: - name: Publish to npm - runs-on: ubuntu-latest - steps: - - name: 🧮 Checkout code - uses: actions/checkout@v3 + npm: + name: Publish to npm + runs-on: ubuntu-latest + steps: + - name: 🧮 Checkout code + uses: actions/checkout@v3 - - name: 🔧 Yarn cache - uses: actions/setup-node@v3 - with: - cache: "yarn" - registry-url: 'https://registry.npmjs.org' + - name: 🔧 Yarn cache + uses: actions/setup-node@v3 + with: + cache: "yarn" + registry-url: "https://registry.npmjs.org" - - name: 🔨 Install dependencies - run: "yarn install --pure-lockfile" + - name: 🔨 Install dependencies + run: "yarn install --pure-lockfile" - - name: 🚀 Publish to npm - id: npm-publish - uses: JS-DevTools/npm-publish@v1 - with: - token: ${{ secrets.NPM_TOKEN }} - access: public - tag: next + - name: 🚀 Publish to npm + id: npm-publish + uses: JS-DevTools/npm-publish@v1 + with: + token: ${{ secrets.NPM_TOKEN }} + access: public + tag: next - - name: 🎖️ Add `latest` dist-tag to final releases - if: github.event.release.prerelease == false - run: | - package=$(cat package.json | jq -er .name) - npm dist-tag add "$package@$release" latest - env: - # JS-DevTools/npm-publish overrides `NODE_AUTH_TOKEN` with `INPUT_TOKEN` in .npmrc - INPUT_TOKEN: ${{ secrets.NPM_TOKEN }} - release: ${{ steps.npm-publish.outputs.version }} + - name: 🎖️ Add `latest` dist-tag to final releases + if: github.event.release.prerelease == false + run: | + package=$(cat package.json | jq -er .name) + npm dist-tag add "$package@$release" latest + env: + # JS-DevTools/npm-publish overrides `NODE_AUTH_TOKEN` with `INPUT_TOKEN` in .npmrc + INPUT_TOKEN: ${{ secrets.NPM_TOKEN }} + release: ${{ steps.npm-publish.outputs.version }} diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index 5f612727815..c66451559d3 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -1,109 +1,74 @@ name: Static Analysis on: - pull_request: { } - push: - branches: [ develop, master ] + pull_request: {} + push: + branches: [develop, master] concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: - ts_lint: - name: "Typescript Syntax Check" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - cache: 'yarn' - - - name: Install Deps - run: "yarn install" - - - name: Typecheck - run: "yarn run lint:types" - - - name: Switch js-sdk to release mode - run: | - scripts/switch_package_to_release.js - yarn install - yarn run build:compile - yarn run build:types - - - name: Typecheck (release mode) - run: "yarn run lint:types" - - js_lint: - name: "ESLint" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - cache: 'yarn' - - - name: Install Deps - run: "yarn install" - - - name: Run Linter - run: "yarn run lint:js" - - docs: - name: "JSDoc Checker" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - cache: 'yarn' - - - name: Install Deps - run: "yarn install" - - - name: Generate Docs - run: "yarn run gendoc" - - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: docs - path: _docs - # We'll only use this in a workflow_run, then we're done with it - retention-days: 1 - - tsc-strict: - name: Typescript Strict Error Checker - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - permissions: - pull-requests: read - checks: write - steps: - - uses: actions/checkout@v3 - - - name: Get diff lines - id: diff - uses: Equip-Collaboration/diff-line-numbers@v1.0.0 - with: - include: '["\\.tsx?$"]' - - - name: Detecting files changed - id: files - uses: futuratrepadeira/changed-files@v4.0.0 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - pattern: '^.*\.tsx?$' - - - uses: t3chguy/typescript-check-action@main - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - use-check: false - check-fail-mode: added - output-behaviour: annotate - ts-extra-args: '--noImplicitAny' - files-changed: ${{ steps.files.outputs.files_updated }} - files-added: ${{ steps.files.outputs.files_created }} - files-deleted: ${{ steps.files.outputs.files_deleted }} - line-numbers: ${{ steps.diff.outputs.lineNumbers }} + ts_lint: + name: "Typescript Syntax Check" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + cache: "yarn" + + - name: Install Deps + run: "yarn install" + + - name: Typecheck + run: "yarn run lint:types" + + - name: Switch js-sdk to release mode + run: | + scripts/switch_package_to_release.js + yarn install + yarn run build:compile + yarn run build:types + + - name: Typecheck (release mode) + run: "yarn run lint:types" + + js_lint: + name: "ESLint" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + cache: "yarn" + + - name: Install Deps + run: "yarn install" + + - name: Run Linter + run: "yarn run lint:js" + + docs: + name: "JSDoc Checker" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + cache: "yarn" + + - name: Install Deps + run: "yarn install" + + - name: Generate Docs + run: "yarn run gendoc" + + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: docs + path: _docs + # We'll only use this in a workflow_run, then we're done with it + retention-days: 1 diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000000..6d56d969f02 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,26 @@ +/_docs +.DS_Store + +/.npmrc +/*.log +package-lock.json +.lock-wscript +build/Release +coverage +lib-cov +out +/dist +/lib +/examples/browser/lib +/examples/crypto-browser/lib +/examples/voip/lib + +# version file and tarball created by `npm pack` / `yarn pack` +/git-revision.txt +/matrix-js-sdk-*.tgz + +.vscode +.vscode/ + +# This file is owned, parsed, and generated by allchange, which doesn't comply with prettier +/CHANGELOG.md diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000000..6a17910f1a0 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1 @@ +module.exports = require("eslint-plugin-matrix-org/.prettierrc.js"); diff --git a/CHANGELOG.md b/CHANGELOG.md index e5dd9237cf8..e05be659ebf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,33 @@ +Changes in [23.0.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v23.0.0) (2022-12-21) +================================================================================================== + +## 🚨 BREAKING CHANGES + * Process `m.room.encryption` events before emitting `RoomMember` events ([\#2914](https://github.com/matrix-org/matrix-js-sdk/pull/2914)). Fixes vector-im/element-web#23819. + * Don't expose `calls` on `GroupCall` ([\#2941](https://github.com/matrix-org/matrix-js-sdk/pull/2941)). + +## ✨ Features + * Support MSC3391: Account data deletion ([\#2967](https://github.com/matrix-org/matrix-js-sdk/pull/2967)). + * Add a message ID on each to-device message ([\#2938](https://github.com/matrix-org/matrix-js-sdk/pull/2938)). + * Enable multiple users' power levels to be set at once ([\#2892](https://github.com/matrix-org/matrix-js-sdk/pull/2892)). Contributed by @GoodGuyMarco. + * Include pending events in thread summary and count again ([\#2922](https://github.com/matrix-org/matrix-js-sdk/pull/2922)). Fixes vector-im/element-web#23642. + * Make GroupCall work better with widgets ([\#2935](https://github.com/matrix-org/matrix-js-sdk/pull/2935)). + * Add method to get outgoing room key requests for a given event ([\#2930](https://github.com/matrix-org/matrix-js-sdk/pull/2930)). + +## 🐛 Bug Fixes + * Fix messages loaded during initial fetch ending up out of order ([\#2971](https://github.com/matrix-org/matrix-js-sdk/pull/2971)). Fixes vector-im/element-web#23972. + * Fix #23919: Root message for new thread loaded from network ([\#2965](https://github.com/matrix-org/matrix-js-sdk/pull/2965)). Fixes vector-im/element-web#23919. + * Fix #23916: Prevent edits of the last message in a thread getting lost ([\#2951](https://github.com/matrix-org/matrix-js-sdk/pull/2951)). Fixes vector-im/element-web#23916 and vector-im/element-web#23942. + * Fix infinite loop when restoring cached read receipts ([\#2963](https://github.com/matrix-org/matrix-js-sdk/pull/2963)). Fixes vector-im/element-web#23951. + * Don't swallow errors coming from the shareSession call ([\#2962](https://github.com/matrix-org/matrix-js-sdk/pull/2962)). Fixes vector-im/element-web#23792. + * Make sure that MegolmEncryption.setupPromise always resolves ([\#2960](https://github.com/matrix-org/matrix-js-sdk/pull/2960)). + * Do not calculate highlight notifs for threads unknown to the room ([\#2957](https://github.com/matrix-org/matrix-js-sdk/pull/2957)). + * Cache read receipts for unknown threads ([\#2953](https://github.com/matrix-org/matrix-js-sdk/pull/2953)). + * bugfix: sliding sync initial room timelines shouldn't notify ([\#2933](https://github.com/matrix-org/matrix-js-sdk/pull/2933)). + * Redo key sharing after own device verification ([\#2921](https://github.com/matrix-org/matrix-js-sdk/pull/2921)). Fixes vector-im/element-web#23333. + * Move updated threads to the end of the thread list ([\#2923](https://github.com/matrix-org/matrix-js-sdk/pull/2923)). Fixes vector-im/element-web#23876. + * Fix highlight notifications increasing when total notification is zero ([\#2937](https://github.com/matrix-org/matrix-js-sdk/pull/2937)). Fixes vector-im/element-web#23885. + * Fix synthesizeReceipt ([\#2916](https://github.com/matrix-org/matrix-js-sdk/pull/2916)). Fixes vector-im/element-web#23827 vector-im/element-web#23754 and vector-im/element-web#23847. + Changes in [22.0.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v22.0.0) (2022-12-06) ================================================================================================== diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7405ed23fd5..a7fd0989fc6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,3 @@ -Contributing code to matrix-js-sdk -================================== +# Contributing code to matrix-js-sdk matrix-js-sdk follows the same pattern as https://github.com/vector-im/element-web/blob/develop/CONTRIBUTING.md - diff --git a/README.md b/README.md index da9368cee3d..9f0e191ac67 100644 --- a/README.md +++ b/README.md @@ -7,27 +7,25 @@ `-- matrix-js-sdk <-- this repo (Matrix client js sdk) -Matrix Javascript SDK -===================== +# Matrix JavaScript SDK This is the [Matrix](https://matrix.org) Client-Server SDK for JavaScript and TypeScript. This SDK can be run in a browser or in Node.js. The Matrix specification is constantly evolving - while this SDK aims for maximum backwards compatibility, it only guarantees that a feature will be supported for at least 4 spec releases. For example, if a feature the js-sdk supports -is removed in v1.4 then the feature is *eligible* for removal from the SDK when v1.8 is released. This SDK has no +is removed in v1.4 then the feature is _eligible_ for removal from the SDK when v1.8 is released. This SDK has no guarantee on implementing all features of any particular spec release, currently. This can mean that the SDK will call endpoints from before Matrix 1.1, for example. -Quickstart -========== +# Quickstart + +## In a browser -In a browser ------------- Download the browser version from https://github.com/matrix-org/matrix-js-sdk/releases/latest and add that as a -`` - - -
- Sanity Testing (check the console) : This example is here to make sure that - the SDK works inside a browser. It simply does a GET /publicRooms on - matrix.org -