From ed3dbc765575ee8cf959037d38cb8fe3b98ae009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Thu, 18 Jan 2024 15:04:22 +0100 Subject: [PATCH] Migrating `realm-web` workflow to NPM workspaces & BaaSaaS (#6368) * Migrating realm-web workflow to NPM workspaces * Update pr-realm-web.yml * Refactored into a setup.ts file * Upgrading Mocha * Migrating from file-based app config to in-code * Fixed import from mocha-remote * Using makeRequestBodyIterable only on Node and React Native * Adding interop on cjs outputs * Upgrading webpack for realm-web-integration-tests * Fixed importing security of an app * Fixed serving realm-web from Webpack dev server * Renamed MDB_REALM_ to BAAS_ * Using test-server workflow in pr-realm-web workflow * Remove --ignore-scripts to help download a browser * Migrating realm-web workflow to baasaas --- .github/workflows/pr-realm-web.yml | 36 ++- package-lock.json | 257 ++++++++++++------ .../realm-app-importer/src/AdminApiClient.ts | 2 +- .../src/AppConfigBuilder.ts | 24 +- .../realm-network-transport/rollup.config.mjs | 2 + .../src/DefaultNetworkTransport.ts | 5 +- .../realm-network-transport/src/node/index.ts | 2 + .../src/react-native/index.ts | 2 + .../realm-network-transport/tsconfig.cjs.json | 7 + .../realm-web-integration-tests/README.md | 24 +- .../harness/import-realm-app.ts | 196 +++++++++++-- .../harness/index.ts | 7 +- .../auth_providers/anon-user.json | 5 - .../auth_providers/api-key.json | 5 - .../auth_providers/custom-function.json | 8 - .../auth_providers/custom-token.json | 22 -- .../auth_providers/local-userpass.json | 11 - .../my-test-app-template/config.json | 8 - .../customAuthentication/config.json | 6 - .../functions/customAuthentication/source.js | 45 --- .../functions/resetPassword/config.json | 6 - .../functions/resetPassword/source.js | 66 ----- .../functions/translate/config.json | 5 - .../functions/translate/source.js | 37 --- .../my-test-app-template/secrets.json | 4 - .../services/custom-http-service/config.json | 6 - .../rules/allow-everything.json | 12 - .../services/local-mongodb/config.json | 8 - .../local-mongodb/rules/defaultRole.json | 14 - .../realm-web-integration-tests/package.json | 7 +- packages/realm-web/.mocharc.json | 5 + packages/realm-web/package.json | 12 +- packages/realm-web/rollup.config.mjs | 6 + .../{test/env.js => src/tests/setup.ts} | 16 +- packages/realm-web/test/mocha.opts | 4 - 35 files changed, 431 insertions(+), 451 deletions(-) create mode 100644 packages/realm-network-transport/tsconfig.cjs.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/auth_providers/anon-user.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/auth_providers/api-key.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/auth_providers/custom-function.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/auth_providers/custom-token.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/auth_providers/local-userpass.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/config.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/functions/customAuthentication/config.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/functions/customAuthentication/source.js delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/functions/resetPassword/config.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/functions/resetPassword/source.js delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/functions/translate/config.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/functions/translate/source.js delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/secrets.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/services/custom-http-service/config.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/services/custom-http-service/rules/allow-everything.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/services/local-mongodb/config.json delete mode 100644 packages/realm-web-integration-tests/my-test-app-template/services/local-mongodb/rules/defaultRole.json create mode 100644 packages/realm-web/.mocharc.json rename packages/realm-web/{test/env.js => src/tests/setup.ts} (65%) delete mode 100644 packages/realm-web/test/mocha.opts diff --git a/.github/workflows/pr-realm-web.yml b/.github/workflows/pr-realm-web.yml index 90a4ba664c..587027e0dc 100644 --- a/.github/workflows/pr-realm-web.yml +++ b/.github/workflows/pr-realm-web.yml @@ -11,6 +11,8 @@ on: - "packages/realm-app-importer/**" # Changing types might also affect Realm Web - "types/**" + # Or the workflow itself + - ".github/workflows/pr-realm-web.yml" # No need to run when updating documentation - "!**.md" @@ -20,6 +22,7 @@ concurrency: env: REALM_DISABLE_ANALYTICS: 1 + BAAS_BRANCH: master jobs: job: @@ -32,27 +35,22 @@ jobs: with: node-version: 20 registry-url: https://registry.npmjs.org/ - # Install the root package (--ignore-scripts to avoid downloading or building the native module) - - run: npm ci --ignore-scripts - # Bootstrap lerna sub-packages - - run: npx lerna bootstrap --scope realm-web-integration-tests --include-dependencies + # Install the root package + - run: npm ci # Build and test the package - - run: npm run build - working-directory: packages/realm-web + - run: npm run bundle --workspace realm-web - name: Run unit tests - run: npm test - working-directory: packages/realm-web - # Login with the Docker CLI to enable the integration test harness to pull the mongodb-realm-test-server - - name: Docker Login - uses: azure/docker-login@v1 + run: npm test --workspace realm-web + + - name: Start BaaS test server + id: baas + uses: ./.github/actions/baas-test-server with: - login-server: ghcr.io - username: realm-ci - password: ${{ secrets.REALM_CI_GITHUB_API_KEY }} + branch: ${{ env.BAAS_BRANCH }} + env: + BAASAAS_KEY: ${{ secrets.BAASAAS_KEY }} + - name: Run integration tests - run: npm run test:github - working-directory: packages/realm-web-integration-tests + run: npm test --workspace realm-web-integration-tests env: - AWS_ACCESS_KEY_ID: ${{ secrets.BAAS_AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.BAAS_AWS_SECRET_ACCESS_KEY }} - MONGODB_REALM_TEST_SERVER: "2023-02-22" + BAAS_BASE_URL: ${{ steps.baas.outputs.baas-url }} diff --git a/package-lock.json b/package-lock.json index 883d96a091..a6117d4e7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24464,6 +24464,47 @@ "node": ">=0.10.0" } }, + "node_modules/source-map-js": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", + "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-loader": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/source-map-loader/-/source-map-loader-4.0.2.tgz", + "integrity": "sha512-oYwAqCuL0OZhBoSgmdrLa7mv9MjommVMiQIWgcztf+eS4+8BfcUee6nenFnDhKOhzAVnk5gpZdfnz1iiBv+5sg==", + "dev": true, + "dependencies": { + "iconv-lite": "^0.6.3", + "source-map-js": "^1.0.2" + }, + "engines": { + "node": ">= 14.15.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^5.72.1" + } + }, + "node_modules/source-map-loader/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/source-map-support": { "version": "0.5.21", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", @@ -29205,17 +29246,17 @@ "@types/chai": "^4.2.9", "@types/fs-extra": "^8.1.0", "@types/js-base64": "^3.3.1", - "@types/mocha": "^7.0.1", + "@types/mocha": "^10.0.6", "@types/node": "^18.15.10", "abort-controller": "^3.0.0", "chai": "4.3.6", "fs-extra": "^10.0.0", - "mocha": "^5.2.0", - "node-fetch": "^2.6.9" + "mocha": "^10.2.0", + "node-fetch": "^3.3.2" }, "optionalDependencies": { - "abort-controller": "^3.0.0", - "node-fetch": "^2.6.0" + "abort-controller": "^3", + "node-fetch": "^3" } }, "packages/realm-web-integration-tests": { @@ -29229,8 +29270,8 @@ "mocha-remote-server": "^1.8.0", "puppeteer": "^14.3.0", "realm-web": "*", - "webpack": "^5.73.0", - "webpack-dev-server": "^4.9.2" + "webpack": "^5.89.0", + "webpack-dev-server": "^4.15.1" }, "devDependencies": { "@types/chai": "^4.3.1", @@ -29244,6 +29285,7 @@ "html-webpack-plugin": "^5.5.0", "mongodb-realm-cli": "^1.3.2", "node-fetch": "^3.2.5", + "source-map-loader": "^4.0.2", "ts-loader": "^9.3.0", "webpack-cli": "^4.9.2" }, @@ -29480,15 +29522,9 @@ } }, "packages/realm-web/node_modules/@types/mocha": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz", - "integrity": "sha512-ZvO2tAcjmMi8V/5Z3JsyofMe3hasRcaw88cto5etSVMwVQfeivGAlEYmaQgceUSVYFofVjT+ioHsATjdWcFt1w==", - "dev": true - }, - "packages/realm-web/node_modules/commander": { - "version": "2.15.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", - "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", + "version": "10.0.6", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz", + "integrity": "sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==", "dev": true }, "packages/realm-web/node_modules/debug": { @@ -29496,26 +29532,26 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], "dependencies": { - "ms": "2.0.0" - } - }, - "packages/realm-web/node_modules/diff": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", - "dev": true, - "engines": { - "node": ">=0.3.1" - } - }, - "packages/realm-web/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "dev": true, + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, "engines": { - "node": ">=0.8.0" + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" } }, "packages/realm-web/node_modules/fs-extra": { @@ -29532,15 +29568,6 @@ "node": ">=12" } }, - "packages/realm-web/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "packages/realm-web/node_modules/he": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", @@ -29550,55 +29577,50 @@ "he": "bin/he" } }, - "packages/realm-web/node_modules/minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha512-miQKw5Hv4NS1Psg2517mV4e4dYNaO3++hjAvLOAzKqZ61rH8NS1SK+vbfBWZ5PY/Me/bEWhUwqMghEW5Fb9T7Q==", - "dev": true - }, - "packages/realm-web/node_modules/mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha512-SknJC52obPfGQPnjIkXbmA6+5H15E+fR+E4iR2oQ3zzCLbd7/ONua69R/Gw7AgkTLsRG+r5fzksYwWe1AgTyWA==", - "deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)", - "dev": true, - "dependencies": { - "minimist": "0.0.8" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, "packages/realm-web/node_modules/mocha": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", - "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.2.0.tgz", + "integrity": "sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==", "dev": true, "dependencies": { + "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", - "commander": "2.15.1", - "debug": "3.1.0", - "diff": "3.5.0", - "escape-string-regexp": "1.0.5", - "glob": "7.1.2", - "growl": "1.10.5", - "he": "1.1.1", - "minimatch": "3.0.4", - "mkdirp": "0.5.1", - "supports-color": "5.4.0" + "chokidar": "3.5.3", + "debug": "4.3.4", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "7.2.0", + "he": "1.2.0", + "js-yaml": "4.1.0", + "log-symbols": "4.1.0", + "minimatch": "5.0.1", + "ms": "2.1.3", + "nanoid": "3.3.3", + "serialize-javascript": "6.0.0", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "workerpool": "6.2.1", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" }, "bin": { "_mocha": "bin/_mocha", - "mocha": "bin/mocha" + "mocha": "bin/mocha.js" }, "engines": { - "node": ">= 4.0.0" + "node": ">= 14.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mochajs" } }, "packages/realm-web/node_modules/mocha/node_modules/glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", "dev": true, "dependencies": { "fs.realpath": "^1.0.0", @@ -29610,13 +29632,73 @@ }, "engines": { "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, - "packages/realm-web/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true + "packages/realm-web/node_modules/mocha/node_modules/glob/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "packages/realm-web/node_modules/mocha/node_modules/minimatch": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", + "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "packages/realm-web/node_modules/mocha/node_modules/minimatch/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "packages/realm-web/node_modules/nanoid": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", + "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", + "dev": true, + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "packages/realm-web/node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dev": true, + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } }, "packages/realm-web/node_modules/supports-color": { "version": "5.4.0", @@ -29624,10 +29706,7 @@ "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", "dev": true, "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" + "randombytes": "^2.1.0" } }, "packages/realm/bindgen": { diff --git a/packages/realm-app-importer/src/AdminApiClient.ts b/packages/realm-app-importer/src/AdminApiClient.ts index cebf3f23dc..0db54dd90e 100644 --- a/packages/realm-app-importer/src/AdminApiClient.ts +++ b/packages/realm-app-importer/src/AdminApiClient.ts @@ -343,7 +343,7 @@ export class AdminApiClient { public async applyAllowedRequestOrigins(appId: string, origins: string[]) { await this.fetch({ route: ["groups", await this.groupId, "apps", appId, "security", "allowed_request_origins"], - method: "PUT", + method: "POST", body: origins, }); } diff --git a/packages/realm-app-importer/src/AppConfigBuilder.ts b/packages/realm-app-importer/src/AppConfigBuilder.ts index a8792f2a3b..7752f1fc81 100644 --- a/packages/realm-app-importer/src/AppConfigBuilder.ts +++ b/packages/realm-app-importer/src/AppConfigBuilder.ts @@ -19,9 +19,7 @@ export type AppConfig = { name: string; sync?: SyncConfig; - security?: { - allowed_request_origins?: string[]; - }; + security?: SecurityConfig; // Additional config below secrets: Record; values: Record; @@ -34,6 +32,10 @@ export type SyncConfig = { development_mode_enabled: boolean; }; +export type SecurityConfig = { + allowed_request_origins?: string[]; +}; + export type ServiceConfig = { name: string; type: string; @@ -45,7 +47,7 @@ export type ServiceConfig = { | (FlexibleSyncConfig & WithAtlas) | WithAtlas; - secret_config: Record; + secret_config?: Record; version?: number; }; @@ -55,7 +57,7 @@ export type WithAtlas = { wireProtocolEnabled: boolean; }; -export type ServiceRule = { +export type MongoDBServiceRule = { roles: Array<{ name: string; apply_when: unknown; // {} @@ -70,6 +72,13 @@ export type ServiceRule = { }>; }; +export type HTTPServiceRule = { + name: string; + actions: string[]; +}; + +export type ServiceRule = HTTPServiceRule | MongoDBServiceRule; + export type AuthProviderConfig = { name: string; disabled: boolean; @@ -211,4 +220,9 @@ export class AppConfigBuilder { this.config.functions.push(config); return this; } + + security(config: SecurityConfig) { + this.config.security = config; + return this; + } } diff --git a/packages/realm-network-transport/rollup.config.mjs b/packages/realm-network-transport/rollup.config.mjs index 6a666e334e..cccaf1fee2 100644 --- a/packages/realm-network-transport/rollup.config.mjs +++ b/packages/realm-network-transport/rollup.config.mjs @@ -30,6 +30,7 @@ export default [ { file: pkg.main, format: "cjs", + interop: "auto", }, { file: pkg.module, @@ -51,6 +52,7 @@ export default [ { file: pkg.browser[pkg.main], format: "cjs", + interop: "auto", }, { file: pkg.browser[pkg.module], diff --git a/packages/realm-network-transport/src/DefaultNetworkTransport.ts b/packages/realm-network-transport/src/DefaultNetworkTransport.ts index 4fa7422563..a1f936669d 100644 --- a/packages/realm-network-transport/src/DefaultNetworkTransport.ts +++ b/packages/realm-network-transport/src/DefaultNetworkTransport.ts @@ -16,7 +16,6 @@ // //////////////////////////////////////////////////////////////////////////// -import { makeRequestBodyIterable } from "./IterableReadableStream"; import { deriveStatusText } from "./status-text"; import type { NetworkTransport, @@ -31,6 +30,8 @@ import type { export class DefaultNetworkTransport implements NetworkTransport { public static fetch: Fetch; public static AbortController: AbortController; + // A hook to transform responses before being returned from fetch + public static transformResponse: (response: FetchResponse) => FetchResponse = (response) => response; public static extraFetchOptions: Record | undefined; public static DEFAULT_HEADERS = { @@ -107,7 +108,7 @@ export class DefaultNetworkTransport implements NetworkTransport { response.statusText = statusText; } // Wraps the body of the request in an iterable interface - return makeRequestBodyIterable(response); + return DefaultNetworkTransport.transformResponse(response); } finally { // Whatever happens, cancel any timeout cancelTimeout(); diff --git a/packages/realm-network-transport/src/node/index.ts b/packages/realm-network-transport/src/node/index.ts index 2b9344df53..0b584e0db7 100644 --- a/packages/realm-network-transport/src/node/index.ts +++ b/packages/realm-network-transport/src/node/index.ts @@ -20,9 +20,11 @@ export * from "../index"; import { DefaultNetworkTransport } from "../DefaultNetworkTransport"; import { Fetch, AbortController } from "../types"; +import { makeRequestBodyIterable } from "../IterableReadableStream"; import fetch from "node-fetch"; import NodeAbortController from "abort-controller"; DefaultNetworkTransport.fetch = fetch as Fetch; DefaultNetworkTransport.AbortController = NodeAbortController as AbortController; +DefaultNetworkTransport.transformResponse = makeRequestBodyIterable; diff --git a/packages/realm-network-transport/src/react-native/index.ts b/packages/realm-network-transport/src/react-native/index.ts index 7bed897835..121d9ca362 100644 --- a/packages/realm-network-transport/src/react-native/index.ts +++ b/packages/realm-network-transport/src/react-native/index.ts @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////////////// import { safeGlobalThis } from "@realm/common"; +import { makeRequestBodyIterable } from "../IterableReadableStream"; export * from "../index"; @@ -25,6 +26,7 @@ import { AbortController, Fetch } from "../types"; DefaultNetworkTransport.fetch = safeGlobalThis.fetch.bind(safeGlobalThis) as Fetch; DefaultNetworkTransport.AbortController = safeGlobalThis.AbortController.bind(safeGlobalThis) as AbortController; +DefaultNetworkTransport.transformResponse = makeRequestBodyIterable; // Setting this non-standard option to enable text streaming // See https://github.com/react-native-community/fetch#enable-text-streaming diff --git a/packages/realm-network-transport/tsconfig.cjs.json b/packages/realm-network-transport/tsconfig.cjs.json new file mode 100644 index 0000000000..c5271d797b --- /dev/null +++ b/packages/realm-network-transport/tsconfig.cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "esModuleInterop": true + } +} \ No newline at end of file diff --git a/packages/realm-web-integration-tests/README.md b/packages/realm-web-integration-tests/README.md index 07c8b9a2e6..7bbfa91737 100644 --- a/packages/realm-web-integration-tests/README.md +++ b/packages/realm-web-integration-tests/README.md @@ -65,28 +65,16 @@ Make sure to toggle on "OpenID Connect". Start the integration tests dev server with dev tools enabled (to keep the browser opened) and provide both the app id and your Google client id: ``` -GOOGLE_CLIENT_ID=414565162824-bqn7utq2u2hue0qum7eu7lfpmmq8p4qg.apps.googleusercontent.com MDB_REALM_APP_ID=my-test-app-fwoue DEV_TOOLS=1 npm test +GOOGLE_CLIENT_ID=414565162824-bqn7utq2u2hue0qum7eu7lfpmmq8p4qg.apps.googleusercontent.com BAAS_APP_ID=my-test-app-fwoue DEV_TOOLS=1 npm test ``` After the tests have run, navigate the browser window to http://localhost:8080/google-login, click the button to "Sign in with Google" and complete the authentication flow. ## Additional environment variables -To skip importing the app or use a different server, specify one or more of the following environment variables: +To use a different server / credentials, specify one or more of the following environment variables: -- `MDB_REALM_APP_ID` -- `MDB_REALM_BASE_URL` -- `MDB_REALM_USERNAME` -- `MDB_REALM_PASSWORD` - -If you want to communicate with the server using the credentials created by the test harness, you can run the test with the following environment variable: - -``` -MDB_REALM_SKIP_CLEANUP=true -``` - -This will skip the clean-up, leaving the app derived from the `./my-test-app-template` and the `./realm-config` file containing access and refresh tokens. - -``` -npx realm-cli export --base-url http://localhost:9090 --config-path ./realm-config --app-id my-test-app-kuxuo -``` +- `BAAS_APP_ID` +- `BAAS_BASE_URL` +- `BAAS_USERNAME` +- `BAAS_PASSWORD` diff --git a/packages/realm-web-integration-tests/harness/import-realm-app.ts b/packages/realm-web-integration-tests/harness/import-realm-app.ts index a551b5ba96..4f0cebf71c 100644 --- a/packages/realm-web-integration-tests/harness/import-realm-app.ts +++ b/packages/realm-web-integration-tests/harness/import-realm-app.ts @@ -16,38 +16,192 @@ // //////////////////////////////////////////////////////////////////////////// -import path from "path"; +import { AppImporter, AppConfigBuilder } from "@realm/app-importer"; -import { AppImporter } from "@realm/app-importer"; - -const MDB_REALM_BASE_URL = process.env.MDB_REALM_BASE_URL || "http://localhost:9090"; -const MDB_REALM_USERNAME = process.env.MDB_REALM_USERNAME || "unique_user@domain.com"; -const MDB_REALM_PASSWORD = process.env.MDB_REALM_PASSWORD || "password"; - -const MDB_REALM_APP_ID = process.env.MDB_REALM_APP_ID; - -const MDB_REALM_SKIP_CLEANUP = process.env.MDB_REALM_SKIP_CLEANUP === "true"; +const { + BAAS_BASE_URL = "http://localhost:9090", + BAAS_USERNAME = "unique_user@domain.com", + BAAS_PASSWORD = "password", + BAAS_APP_ID, +} = process.env; export async function importRealmApp() { // Create a new MongoDBRealmService - const baseUrl = MDB_REALM_BASE_URL; - if (MDB_REALM_APP_ID) { - console.log(`Skipping import of the app (MDB_REALM_APP_ID = ${MDB_REALM_APP_ID})`); - return { appId: MDB_REALM_APP_ID, baseUrl }; + const baseUrl = BAAS_BASE_URL; + if (BAAS_APP_ID) { + console.log(`Skipping import of the app (BAAS_APP_ID = ${BAAS_APP_ID})`); + return { appId: BAAS_APP_ID, baseUrl }; } else { const importer = new AppImporter({ baseUrl, credentials: { kind: "username-password", - username: MDB_REALM_USERNAME, - password: MDB_REALM_PASSWORD, + username: BAAS_USERNAME, + password: BAAS_PASSWORD, }, - appsDirectoryPath: path.resolve(__dirname, "../imported-apps"), - realmConfigPath: path.resolve(__dirname, "../realm-config"), - cleanUp: !MDB_REALM_SKIP_CLEANUP, }); - const appTemplatePath = path.resolve(__dirname, "../my-test-app-template"); - const { appId } = await importer.importApp(appTemplatePath); + const builder = new AppConfigBuilder("my-test-app") + .security({ allowed_request_origins: ["http://localhost:8080"] }) + .secret("jwt-secret", "2k66QfKeTRk3MdZ5vpDYgZCu2k66QfKeTRk3MdZ5vpDYgZCu") + .secret("local-mongodb-uri", "mongodb://localhost:26000") + .function({ + name: "customAuthentication", + private: true, + run_as_system: true, + source: ` + exports = async function (loginPayload) { + // Get a handle for the app.users collection + const users = context.services.get("local-mongodb").db("app").collection("users"); + + // Parse out custom data from the FunctionCredential + + const { username, secret } = loginPayload; + + if (secret !== "v3ry-s3cret") { + throw new Error("Ah ah ah, you didn't say the magic word"); + } + // Query for an existing user document with the specified username + + const user = await users.findOne({ username }); + + if (user) { + // If the user document exists, return its unique ID + return user._id.toString(); + } else { + // If the user document does not exist, create it and then return its unique ID + const result = await users.insertOne({ username }); + return result.insertedId.toString(); + } + }; + `, + }) + .function({ + name: "resetPassword", + private: false, + can_evaluate: {}, + source: ` + exports = () => { + // will not reset the password + return { status: "fail" }; + }; + `, + }) + .function({ + name: "translate", + private: false, + source: ` + exports = function (sentence, languages) { + if (languages === "fr_en") { + if (sentence === "bonjour") { + return "hello"; + } else { + return "what?"; + } + } else if (languages === "en_fr") { + if (sentence === "hello") { + return "bonjour"; + } else { + return "que?"; + } + } else { + throw new Error("Watch your language!"); + } + }; + + `, + }) + .authProvider({ + name: "anon-user", + type: "anon-user", + disabled: false, + }) + .authProvider({ + name: "api-key", + type: "api-key", + disabled: false, + }) + .authProvider({ + name: "custom-function", + type: "custom-function", + config: { + authFunctionName: "customAuthentication", + }, + disabled: false, + }) + .authProvider({ + name: "custom-token", + type: "custom-token", + config: { + audience: "", + signingAlgorithm: "HS256", + useJWKURI: false, + }, + secret_config: { + signingKeys: ["jwt-secret"], + }, + disabled: false, + metadata_fields: [ + { + required: true, + name: "mySecretField", + field_name: "secret", + }, + ], + }) + .authProvider({ + name: "local-userpass", + type: "local-userpass", + config: { + autoConfirm: true, + resetFunctionName: "resetPassword", + runConfirmationFunction: false, + runResetFunction: true, + }, + disabled: false, + }) + .service( + { + name: "custom-http-service", + type: "http", + config: {}, + version: 1, + }, + [ + { + name: "allow-everything", + actions: ["get", "post", "put", "delete", "patch", "head"], + }, + ], + ) + .service( + { + name: "local-mongodb", + type: "mongodb", + config: {}, + secret_config: { + uri: "local-mongodb-uri", + }, + }, + [ + { + roles: [ + { + name: "defaultRole", + apply_when: {}, + document_filters: { + read: true, + write: true, + }, + write: true, + read: true, + insert: true, + delete: true, + }, + ], + }, + ], + ); + const { appId } = await importer.importApp(builder.config); return { appId, baseUrl }; } } diff --git a/packages/realm-web-integration-tests/harness/index.ts b/packages/realm-web-integration-tests/harness/index.ts index 9bec446dad..a7239dc49a 100644 --- a/packages/realm-web-integration-tests/harness/index.ts +++ b/packages/realm-web-integration-tests/harness/index.ts @@ -21,7 +21,7 @@ import puppeteer from "puppeteer"; import WebpackDevServer from "webpack-dev-server"; import webpack from "webpack"; -import MochaRemote from "mocha-remote"; +import { Server as MochaRemoteServer } from "mocha-remote-server"; import { importRealmApp } from "./import-realm-app"; @@ -30,6 +30,7 @@ import path = require("path"); // Default to testing only the credentials that does not require manual interactions. const testCredentials = process.env.TEST_CREDENTIALS || "anonymous,email-password,function,jwt"; +const realmWebPath = path.dirname(require.resolve("realm-web/package.json")); const { BASE_URL = "http://localhost:8080" } = process.env; @@ -95,7 +96,7 @@ export async function run(devtools = false) { proxy: { "/api": baseUrl }, historyApiFallback: true, static: { - directory: path.join(__dirname, "../node_modules/realm-web"), + directory: realmWebPath, publicPath: "/realm-web", }, }); @@ -115,7 +116,7 @@ export async function run(devtools = false) { }); // Start the mocha remote server - const mochaServer = new MochaRemote.Server({ + const mochaServer = new MochaRemoteServer({ autoRun: devtools, }); diff --git a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/anon-user.json b/packages/realm-web-integration-tests/my-test-app-template/auth_providers/anon-user.json deleted file mode 100644 index a1c4697446..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/anon-user.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "anon-user", - "type": "anon-user", - "disabled": false -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/api-key.json b/packages/realm-web-integration-tests/my-test-app-template/auth_providers/api-key.json deleted file mode 100644 index ea575d1ca2..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/api-key.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "api-key", - "type": "api-key", - "disabled": false -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/custom-function.json b/packages/realm-web-integration-tests/my-test-app-template/auth_providers/custom-function.json deleted file mode 100644 index dd68de4ba7..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/custom-function.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "custom-function", - "type": "custom-function", - "config": { - "authFunctionName": "customAuthentication" - }, - "disabled": false -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/custom-token.json b/packages/realm-web-integration-tests/my-test-app-template/auth_providers/custom-token.json deleted file mode 100644 index 8d32eb6bcb..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/custom-token.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "custom-token", - "type": "custom-token", - "config": { - "audience": "", - "signingAlgorithm": "HS256", - "useJWKURI": false - }, - "secret_config": { - "signingKeys": [ - "jwt-secret" - ] - }, - "disabled": false, - "metadata_fields": [ - { - "required": true, - "name": "mySecretField", - "field_name": "secret" - } - ] -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/local-userpass.json b/packages/realm-web-integration-tests/my-test-app-template/auth_providers/local-userpass.json deleted file mode 100644 index bdd34dca5d..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/auth_providers/local-userpass.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "local-userpass", - "type": "local-userpass", - "config": { - "autoConfirm": true, - "resetFunctionName": "resetPassword", - "runConfirmationFunction": false, - "runResetFunction": true - }, - "disabled": false -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/config.json b/packages/realm-web-integration-tests/my-test-app-template/config.json deleted file mode 100644 index ad65da1641..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "my-test-app", - "security": { - "allowed_request_origins": [ - "http://localhost:8080" - ] - } -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/functions/customAuthentication/config.json b/packages/realm-web-integration-tests/my-test-app-template/functions/customAuthentication/config.json deleted file mode 100644 index 77c9dd7e50..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/functions/customAuthentication/config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": "5e622d21b55fffe5d410ebe6", - "name": "customAuthentication", - "private": true, - "run_as_system": true -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/functions/customAuthentication/source.js b/packages/realm-web-integration-tests/my-test-app-template/functions/customAuthentication/source.js deleted file mode 100644 index 46e2e34fda..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/functions/customAuthentication/source.js +++ /dev/null @@ -1,45 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2020 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////// - -/* eslint-env node */ -/* global context */ - -exports = async function (loginPayload) { - // Get a handle for the app.users collection - const users = context.services.get("local-mongodb").db("app").collection("users"); - - // Parse out custom data from the FunctionCredential - - const { username, secret } = loginPayload; - - if (secret !== "v3ry-s3cret") { - throw new Error("Ah ah ah, you didn't say the magic word"); - } - // Query for an existing user document with the specified username - - const user = await users.findOne({ username }); - - if (user) { - // If the user document exists, return its unique ID - return user._id.toString(); - } else { - // If the user document does not exist, create it and then return its unique ID - const result = await users.insertOne({ username }); - return result.insertedId.toString(); - } -}; diff --git a/packages/realm-web-integration-tests/my-test-app-template/functions/resetPassword/config.json b/packages/realm-web-integration-tests/my-test-app-template/functions/resetPassword/config.json deleted file mode 100644 index e476d695a5..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/functions/resetPassword/config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": "5e622d21b55fffe5d410ebe7", - "name": "resetPassword", - "private": false, - "can_evaluate": {} -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/functions/resetPassword/source.js b/packages/realm-web-integration-tests/my-test-app-template/functions/resetPassword/source.js deleted file mode 100644 index 72e22305ad..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/functions/resetPassword/source.js +++ /dev/null @@ -1,66 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2020 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////// - -/* eslint-env node */ - -/* -This function will be run when the client SDK 'callResetPasswordFunction' and is called with an object parameter -which contains four keys: 'token', 'tokenId', 'username', and 'password', and additional parameters -for each parameter passed in as part of the argument list from the SDK. - -The return object must contain a 'status' key which can be empty or one of three string values: - 'success', 'pending', or 'fail' - -'success': the user's password is set to the passed in 'password' parameter. - -'pending': the user's password is not reset and the UserPasswordAuthProviderClient 'resetPassword' function would - need to be called with the token, tokenId, and new password via an SDK. (see below) - - const emailPassClient = Stitch.defaultAppClient.auth - .getProviderClient(UserPasswordAuthProviderClient.factory); - - emailPassClient.resetPassword(token, tokenId, newPassword) - -'fail': the user's password is not reset and will not be able to log in with that password. - -If an error is thrown within the function the result is the same as 'fail'. - -Example below: - -exports = ({ token, tokenId, username, password }, sendEmail, securityQuestionAnswer) => { - // process the reset token, tokenId, username and password - if (sendEmail) { - context.functions.execute('sendResetPasswordEmail', username, token, tokenId); - // will wait for SDK resetPassword to be called with the token and tokenId - return { status: 'pending' }; - } else if (context.functions.execute('validateSecurityQuestionAnswer', username, securityQuestionAnswer)) { - // will set the users password to the password parameter - return { status: 'success' }; - } - - // will not reset the password - return { status: 'fail' }; -}; - -The uncommented function below is just a placeholder and will result in failure. -*/ - -exports = () => { - // will not reset the password - return { status: "fail" }; -}; diff --git a/packages/realm-web-integration-tests/my-test-app-template/functions/translate/config.json b/packages/realm-web-integration-tests/my-test-app-template/functions/translate/config.json deleted file mode 100644 index 89a87281ca..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/functions/translate/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": "5e622d21b55fffe5d410ebe8", - "name": "translate", - "private": false -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/functions/translate/source.js b/packages/realm-web-integration-tests/my-test-app-template/functions/translate/source.js deleted file mode 100644 index f89558a6c4..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/functions/translate/source.js +++ /dev/null @@ -1,37 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// -// Copyright 2020 Realm Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////// - -/* eslint-env node */ - -exports = function (sentence, languages) { - if (languages === "fr_en") { - if (sentence === "bonjour") { - return "hello"; - } else { - return "what?"; - } - } else if (languages === "en_fr") { - if (sentence === "hello") { - return "bonjour"; - } else { - return "que?"; - } - } else { - throw new Error("Watch your language!"); - } -}; diff --git a/packages/realm-web-integration-tests/my-test-app-template/secrets.json b/packages/realm-web-integration-tests/my-test-app-template/secrets.json deleted file mode 100644 index 9b1946acb7..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/secrets.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "jwt-secret": "2k66QfKeTRk3MdZ5vpDYgZCu2k66QfKeTRk3MdZ5vpDYgZCu", - "local-mongodb-uri": "mongodb://localhost:26000" -} \ No newline at end of file diff --git a/packages/realm-web-integration-tests/my-test-app-template/services/custom-http-service/config.json b/packages/realm-web-integration-tests/my-test-app-template/services/custom-http-service/config.json deleted file mode 100644 index 7187224475..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/services/custom-http-service/config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "custom-http-service", - "type": "http", - "config": {}, - "version": 1 -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/services/custom-http-service/rules/allow-everything.json b/packages/realm-web-integration-tests/my-test-app-template/services/custom-http-service/rules/allow-everything.json deleted file mode 100644 index e300dde92f..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/services/custom-http-service/rules/allow-everything.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "id": "5e8683fdb739bee989c7ef8e", - "name": "allow-everything", - "actions": [ - "get", - "post", - "put", - "delete", - "patch", - "head" - ] -} diff --git a/packages/realm-web-integration-tests/my-test-app-template/services/local-mongodb/config.json b/packages/realm-web-integration-tests/my-test-app-template/services/local-mongodb/config.json deleted file mode 100644 index 302258890c..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/services/local-mongodb/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "local-mongodb", - "type": "mongodb", - "config": {}, - "secret_config": { - "uri": "local-mongodb-uri" - } -} \ No newline at end of file diff --git a/packages/realm-web-integration-tests/my-test-app-template/services/local-mongodb/rules/defaultRole.json b/packages/realm-web-integration-tests/my-test-app-template/services/local-mongodb/rules/defaultRole.json deleted file mode 100644 index fbcd2ef8d6..0000000000 --- a/packages/realm-web-integration-tests/my-test-app-template/services/local-mongodb/rules/defaultRole.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "roles": [{ - "name": "defaultRole", - "apply_when": {}, - "document_filters": { - "read": true, - "write": true - }, - "write": true, - "read": true, - "insert": true, - "delete": true - }] -} diff --git a/packages/realm-web-integration-tests/package.json b/packages/realm-web-integration-tests/package.json index afaa403e51..1416ad8c4c 100644 --- a/packages/realm-web-integration-tests/package.json +++ b/packages/realm-web-integration-tests/package.json @@ -30,16 +30,16 @@ } }, "dependencies": { + "@realm/app-importer": "^0.1.0", "chai": "4.3.6", "js-base64": "^3.7.2", "jwt-encode": "^1.0.1", "mocha-remote-cli": "^1.8.0", "mocha-remote-server": "^1.8.0", "puppeteer": "^14.3.0", - "@realm/app-importer": "^0.1.0", "realm-web": "*", - "webpack": "^5.73.0", - "webpack-dev-server": "^4.9.2" + "webpack": "^5.89.0", + "webpack-dev-server": "^4.15.1" }, "peerDependencies": { "mocha-remote-client": "^1.8.0" @@ -56,6 +56,7 @@ "html-webpack-plugin": "^5.5.0", "mongodb-realm-cli": "^1.3.2", "node-fetch": "^3.2.5", + "source-map-loader": "^4.0.2", "ts-loader": "^9.3.0", "webpack-cli": "^4.9.2" } diff --git a/packages/realm-web/.mocharc.json b/packages/realm-web/.mocharc.json new file mode 100644 index 0000000000..66beb5d25a --- /dev/null +++ b/packages/realm-web/.mocharc.json @@ -0,0 +1,5 @@ +{ + "import": "tsx", + "file": "src/tests/setup.ts", + "spec": "src/tests/**/*.test.ts" +} \ No newline at end of file diff --git a/packages/realm-web/package.json b/packages/realm-web/package.json index f64dfead5a..b1f7620683 100644 --- a/packages/realm-web/package.json +++ b/packages/realm-web/package.json @@ -15,7 +15,7 @@ "bundle": "wireit", "start": "npm run build -- --watch", "lint": "eslint --ext .js,.ts .", - "test": "mocha 'src/tests/**/*.test.ts'", + "test": "mocha", "postversion": "ts-node --project scripts/tsconfig.json scripts/postversion.ts", "docs": "wireit" }, @@ -89,20 +89,20 @@ "js-base64": "^3.7.2" }, "optionalDependencies": { - "abort-controller": "^3.0.0", - "node-fetch": "^2.6.0" + "abort-controller": "^3", + "node-fetch": "^3" }, "devDependencies": { "@types/chai": "^4.2.9", "@types/fs-extra": "^8.1.0", "@types/js-base64": "^3.3.1", - "@types/mocha": "^7.0.1", + "@types/mocha": "^10.0.6", "@types/node": "^18.15.10", "abort-controller": "^3.0.0", "chai": "4.3.6", "fs-extra": "^10.0.0", - "mocha": "^5.2.0", - "node-fetch": "^2.6.9", + "mocha": "^10.2.0", + "node-fetch": "^3.3.2", "@realm/network-transport": "^0.7.2" } } diff --git a/packages/realm-web/rollup.config.mjs b/packages/realm-web/rollup.config.mjs index 99ee295b30..67969c70d2 100644 --- a/packages/realm-web/rollup.config.mjs +++ b/packages/realm-web/rollup.config.mjs @@ -35,10 +35,13 @@ export default [ { file: pkg.main, format: "cjs", + interop: "auto", + sourcemap: true, }, { file: pkg.module, format: "es", + sourcemap: true, }, ], plugins: [ @@ -57,10 +60,13 @@ export default [ { file: pkg.browser[pkg.main], format: "cjs", + interop: "auto", + sourcemap: true, }, { file: pkg.browser[pkg.module], format: "es", + sourcemap: true, }, ], plugins: [ diff --git a/packages/realm-web/test/env.js b/packages/realm-web/src/tests/setup.ts similarity index 65% rename from packages/realm-web/test/env.js rename to packages/realm-web/src/tests/setup.ts index 03188bcd71..23b22ce952 100644 --- a/packages/realm-web/test/env.js +++ b/packages/realm-web/src/tests/setup.ts @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////// // -// Copyright 2020 Realm Inc. +// Copyright 2024 Realm Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,16 +15,8 @@ // limitations under the License. // //////////////////////////////////////////////////////////////////////////// - -/* eslint-env node */ -/* eslint-disable @typescript-eslint/no-var-requires */ - -const path = require("path"); - -const tsConfigPath = path.resolve(__dirname, "../src/tests/tsconfig.json"); -process.env.TS_NODE_PROJECT = tsConfigPath; -console.log(`Loading TypeScript configuration from ${tsConfigPath}`); +import "../node/index"; // We can disable no-restricted-globals, since we know this will run on node.js -// eslint-disable-next-line no-restricted-globals -global.__SDK_VERSION__ = "0.0.0-test"; +/* eslint-disable-next-line no-restricted-globals */ +Object.assign(globalThis, { __SDK_VERSION__: "0.0.0-test" }); diff --git a/packages/realm-web/test/mocha.opts b/packages/realm-web/test/mocha.opts deleted file mode 100644 index 77a9d0581b..0000000000 --- a/packages/realm-web/test/mocha.opts +++ /dev/null @@ -1,4 +0,0 @@ ---watch-extensions ts ---require ./test/env.js ---require ts-node/register ---file src/node/index.ts \ No newline at end of file