diff --git a/.eslintignore b/.eslintignore index f29a7999e..2e2504c69 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,23 +1,23 @@ landing/dist landing/flow-typed landing/node_modules lib/flow-typed lib/node_modules web/dist web/flow-typed web/node_modules -server/app_compiled -server/landing_compiled -server/dist -server/secrets -server/facts -server/fonts -server/flow-typed -server/node_modules -server/src/landing -server/src/lib -server/src/web +keyserver/app_compiled +keyserver/landing_compiled +keyserver/dist +keyserver/secrets +keyserver/facts +keyserver/fonts +keyserver/flow-typed +keyserver/node_modules +keyserver/src/landing +keyserver/src/lib +keyserver/src/web native/flow-typed native/node_modules native/codegen/dist native/android/app/build diff --git a/.eslintrc.json b/.eslintrc.json index 2e362fb54..9e044cf2d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,56 +1,56 @@ { "root": true, "env": { "es6": true }, "extends": [ "eslint:recommended", "plugin:react/recommended", "plugin:flowtype/recommended", "plugin:import/errors", "plugin:import/warnings", "plugin:prettier/recommended", "prettier" ], "parser": "babel-eslint", "plugins": ["react", "react-hooks", "flowtype", "monorepo", "import"], "rules": { "flowtype/require-valid-file-annotation": ["error", "always"], "flowtype/require-exact-type": ["error", "never"], "curly": "error", "linebreak-style": "error", "semi": "error", "react-hooks/rules-of-hooks": "error", "react-hooks/exhaustive-deps": "warn", "monorepo/no-relative-import": "error", "no-empty": ["error", { "allowEmptyCatch": true }], "import/no-unresolved": 0, "no-unused-vars": ["error", { "ignoreRestSiblings": true }], "react/prop-types": ["error", { "skipUndeclared": true }], "no-shadow": 1, "import/order": [ "warn", { "newlines-between": "always", "alphabetize": { "order": "asc", "caseInsensitive": true }, "groups": [["builtin", "external"], "internal"] } ], "prefer-const": "error", "react/jsx-curly-brace-presence": [ "error", { "props": "never", "children": "ignore" } ], "eqeqeq": ["error", "always"] }, "settings": { "react": { "version": "detect" }, "import/ignore": ["react-native"], - "import/internal-regex": "^(lib|native|server|web)/" + "import/internal-regex": "^(lib|native|keyserver|web)/" } } diff --git a/.github/workflows/android_ci.yml b/.github/workflows/android_ci.yml index 9573b88ee..458d491b7 100644 --- a/.github/workflows/android_ci.yml +++ b/.github/workflows/android_ci.yml @@ -1,50 +1,50 @@ name: Android Build CI on: push: branches: [master] paths-ignore: - 'landing/**' - 'web/**' - 'docs/**' - - 'server/**' + - 'keyserver/**' jobs: build: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: set up JDK 11 uses: actions/setup-java@v2 with: java-version: '11' distribution: 'adopt' - name: Install Yarn run: npm install -g yarn - name: yarn --frozen-lockfile run: yarn --frozen-lockfile - name: Save ANDROID_KEY_STORE_B64 to file env: ANDROID_KEY_STORE_B64: ${{secrets.ANDROID_KEY_STORE_B64}} run: echo "$ANDROID_KEY_STORE_B64" > ANDROID_KEY_STORE_B64.b64 - name: Save ANDROID_KEY_STORE to file run: base64 -d ANDROID_KEY_STORE_B64.b64 > android_key_store.keystore - name: Configure gradle.properties run: | mkdir ~/.gradle touch ~/.gradle/gradle.properties echo "COMM_UPLOAD_STORE_FILE=$(pwd)/android_key_store.keystore" >> ~/.gradle/gradle.properties echo "COMM_UPLOAD_KEY_ALIAS=AndroidSigningKey" >> ~/.gradle/gradle.properties - name: Build with Gradle working-directory: ./native/android env: ANDROID_SIGNING_PASSWORD: ${{secrets.ANDROID_SIGNING_PASSWORD}} run: ./gradlew bundleRelease diff --git a/.github/workflows/eslint_flow_jest.yml b/.github/workflows/eslint_flow_jest.yml index a06dee1d7..ed0fa90ae 100644 --- a/.github/workflows/eslint_flow_jest.yml +++ b/.github/workflows/eslint_flow_jest.yml @@ -1,53 +1,53 @@ name: ESLint & Flow & Jest on: push: branches: [master] jobs: build: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: npm install -g yarn run: npm install -g yarn - name: yarn --frozen-lockfile run: yarn --frozen-lockfile - name: yarn eslint --max-warnings=0 run: yarn eslint --max-warnings=0 - name: '[lib] flow' working-directory: ./lib run: ./node_modules/.bin/flow - - name: '[server] flow' - working-directory: ./server + - name: '[keyserver] flow' + working-directory: ./keyserver run: | mkdir secrets touch secrets/db_config.json touch secrets/olm_config.json mkdir facts touch facts/squadcal_url.json touch facts/commapp_url.json touch facts/landing_url.json touch facts/url.json ./node_modules/.bin/flow - name: '[web] flow' working-directory: ./web run: ./node_modules/.bin/flow - name: '[landing] flow' working-directory: ./landing run: ./node_modules/.bin/flow - name: '[native] flow' working-directory: ./native run: ./node_modules/.bin/flow - name: '[lib] test' working-directory: ./lib run: yarn test diff --git a/.github/workflows/ios_ci.yml b/.github/workflows/ios_ci.yml index eb0e55db3..3d353ce5a 100644 --- a/.github/workflows/ios_ci.yml +++ b/.github/workflows/ios_ci.yml @@ -1,73 +1,73 @@ name: iOS Build CI on: push: branches: [master] paths-ignore: - 'landing/**' - 'web/**' - 'docs/**' - - 'server/**' + - 'keyserver/**' jobs: build: name: Build and archive iOS app runs-on: macos-11 steps: - name: Checkout uses: actions/checkout@v2 - name: Install the Apple certificate and provisioning profile env: BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }} P12_PASSWORD: ${{ secrets.P12_PASSWORD }} BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }} KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} run: | # create variables CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db # import certificate and provisioning profile from secrets echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode --output $CERTIFICATE_PATH echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode --output $PP_PATH # create temporary keychain security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH security set-keychain-settings -lut 21600 $KEYCHAIN_PATH security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH # import certificate to keychain security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH security list-keychain -d user -s $KEYCHAIN_PATH # apply provisioning profile mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles - name: npm install -g yarn run: npm install -g yarn - name: yarn --frozen-lockfile run: yarn --frozen-lockfile - name: Save auth_key to file working-directory: ./native/ios env: AUTH_KEY: ${{secrets.AUTH_KEY}} run: echo "$AUTH_KEY" > AUTH_KEY.p8 - name: Archive working-directory: ./native/ios env: AUTH_KEY_ID: ${{secrets.AUTH_KEY_ID}} AUTH_KEY_ISSUER_ID: ${{secrets.AUTH_KEY_ISSUER_ID}} run: xcodebuild archive -workspace Comm.xcworkspace -scheme Comm -configuration Release -archivePath archives/Comm.xcarchive -destination generic/platform=iOS -allowProvisioningUpdates -authenticationKeyIssuerID "$AUTH_KEY_ISSUER_ID" -authenticationKeyID "$AUTH_KEY_ID" -authenticationKeyPath $PWD/AUTH_KEY.p8 - name: Clean up keychain and provisioning profile if: ${{ always() }} run: | rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision security delete-keychain $RUNNER_TEMP/app-signing.keychain-db diff --git a/.github/workflows/services_ci.yml b/.github/workflows/services_ci.yml index 267ed2469..c46c96ff3 100644 --- a/.github/workflows/services_ci.yml +++ b/.github/workflows/services_ci.yml @@ -1,27 +1,27 @@ name: Services CI on: push: branches: [master] paths-ignore: - 'landing/**' - 'web/**' - 'docs/**' - - 'server/**' + - 'keyserver/**' jobs: build: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: Install Yarn run: npm install -g yarn - name: yarn --frozen-lockfile run: yarn --frozen-lockfile - name: Build Services working-directory: ./services run: yarn build-all diff --git a/.gitignore b/.gitignore index 5f564e34e..3fa81169e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,16 @@ .DS_Store node_modules landing/node_modules landing/dist lib/node_modules native/cpp/CommonCpp/CryptoTools/opaque-ke-cxx/target web/node_modules web/dist -server/dist -server/node_modules -server/secrets -server/facts +keyserver/dist +keyserver/node_modules +keyserver/secrets +keyserver/facts services/identity/target .eslintcache .vscode !.vscode/extensions.json diff --git a/.lintstagedrc.js b/.lintstagedrc.js index 3c63454e8..c3f8f921c 100644 --- a/.lintstagedrc.js +++ b/.lintstagedrc.js @@ -1,45 +1,45 @@ const { CLIEngine } = require('eslint'); const { getClangPaths } = require('./scripts/get_clang_paths'); const cli = new CLIEngine({}); module.exports = { '*.{js,mjs}': function eslint(files) { return ( 'eslint --cache --fix --max-warnings=0 ' + files.filter(file => !cli.isPathIgnored(file)).join(' ') ); }, '*.{css,html,md,json}': function prettier(files) { return 'prettier --write ' + files.join(' '); }, 'lib/**/*.js': function libFlow(files) { return 'yarn workspace lib flow --quiet'; }, '{web,lib}/**/*.js': function webFlow(files) { return 'yarn workspace web flow --quiet'; }, '{native,lib}/**/*.js': function nativeFlow(files) { return 'yarn workspace native flow --quiet'; }, - '{server,web,lib}/**/*.js': function serverFlow(files) { - return 'yarn workspace server flow --quiet'; + '{keyserver,web,lib}/**/*.js': function keyServerFlow(files) { + return 'yarn workspace keyserver flow --quiet'; }, '{landing,lib}/**/*.js': function landingFlow(files) { return 'yarn workspace landing flow --quiet'; }, '{native,services}/**/*.{h,cpp,java,mm}': function clangFormat(files) { files = files.filter((path) => { if (path.indexOf('generated') !== -1) { return false; } for (const allowedPath of getClangPaths()) { if (path.indexOf(allowedPath) !== -1) { return true; } } return false; }); return 'clang-format -i ' + files.join(' '); }, }; diff --git a/.prettierignore b/.prettierignore index 07de876ae..471215508 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,19 +1,19 @@ landing/dist landing/flow-typed lib/flow-typed web/dist web/flow-typed -server/app_compiled -server/landing_compiled -server/dist -server/secrets -server/facts -server/images -server/fonts -server/flow-typed -server/src/landing -server/src/lib -server/src/web +keyserver/app_compiled +keyserver/landing_compiled +keyserver/dist +keyserver/secrets +keyserver/facts +keyserver/images +keyserver/fonts +keyserver/flow-typed +keyserver/src/landing +keyserver/src/lib +keyserver/src/web native/android native/flow-typed native/ios diff --git a/README.md b/README.md index 28814cbef..8943b7647 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ ## Comm Comm is the working name of this open source messaging project. ## Repo structure The whole project is written in Flow-typed Javascript. The code is organized in a monorepo structure using Yarn Workspaces. - `native` contains the code for the React Native app, which supports both iOS and Android. -- `server` contains the code for the Node/Express server. +- `keyserver` contains the code for the Node/Express server. - `web` contains the code for the React desktop website. - `landing` contains the code for the [Comm landing page](https://comm.app). - `lib` contains code that is shared across multiple other workspaces, including most of the Redux stack that is shared across native/web. ## Dev environment Note that it’s currently it’s only possible to contribute to this project from macOS. This is primarily due to iOS native development only being supported in macOS. Check out our [doc on how to set up our dev environment](docs/dev_environment.md). diff --git a/docs/dev_environment.md b/docs/dev_environment.md index 32244080f..1684afd32 100644 --- a/docs/dev_environment.md +++ b/docs/dev_environment.md @@ -1,865 +1,865 @@ # Requirements Please note that our dev environment currently only works on macOS and Linux. For the Linux instructions [head to the Linux configuration steps](linux_dev_environment.md).
Why not Windows? (click to expand)

-It’s primarily because Apple only supports iOS development using macOS. It’s true that we could support web, server, and Android development on other operating systems, but because of the Apple requirement, all of our active developers currently run macOS. We’d very much welcome a PR to build out support on Windows! +It’s primarily because Apple only supports iOS development using macOS. It’s true that we could support web, keyserver, and Android development on other operating systems, but because of the Apple requirement, all of our active developers currently run macOS. We’d very much welcome a PR to build out support on Windows!

Unfortunately the dev environment is overall pretty heavy. You’ll ideally want a machine with at least 32 GiB of RAM, although 16 GiB should suffice. # Prerequisites ## Xcode Go to the [Mac App Store](https://apps.apple.com/us/app/xcode/id497799835) to install Xcode, or if you already have it, to update it to the latest version. Once Xcode is installed, open it up. If you are prompted, follow the instructions to install any “Additional Required Components”. Finally, you need to make sure that the Xcode “Command Line Tools” are installed. You can do this by running: ``` xcode-select --install ``` ## Homebrew Install [Homebrew](https://brew.sh/), a package manager for macOS. ## Node Next, install [Node](https://nodejs.org/) using Homebrew. We’re going to use version 16 to avoid some possible issues that come up on Apple silicon when we install project dependencies. ``` brew install node@16; brew upgrade node@16 ``` The reason we use both `install` and `upgrade` is that there’s no single Homebrew command equivalent to “install if not installed, and upgrade if already installed”. ## PHP [PHP](https://www.php.net) is needed for Arcanist. As of macOS 12 (Monterey), PHP is no longer bundled with the OS and needs to be installed via Homebrew. ``` brew install php@7.4; brew upgrade php@7.4 ``` ## Rust We use a Rust [implementation](https://github.com/novifinancial/opaque-ke) of the OPAQUE password-authenticated key exchange protocol, so you will need to install Rust to compile the static library. The easiest way to do this is with `rustup`. ``` curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` ## Yarn We use the [Yarn](https://yarnpkg.com/) package manager for JavaScript in our repo. ``` brew install yarn; brew upgrade yarn ``` ## Watchman Watchman is a tool from Facebook used in the React Native dev environment to watch for changes to your filesystem. ``` brew install watchman; brew upgrade watchman ``` ## Node Version Manager -Node Version Manager (nvm) is a tool that ensures we use the same version of Node on our server between prod and dev environments. +Node Version Manager (nvm) is a tool that ensures we use the same version of Node on our keyserver between prod and dev environments. ``` brew install nvm; brew upgrade nvm ``` After installing, Homebrew will print out some instructions under the Caveats section of its output. It will ask you to do two things: `mkdir ~/.nvm`, and to add some lines to your `~/.bash_profile` (or desired shell configuration file). We recommend that you append `--no-use` to the line that loads nvm, so that you continue to use your Homebrew-sourced Node distribution by default: ``` export NVM_DIR="$HOME/.nvm" [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" --no-use # This loads nvm [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion ``` Now either close and reopen your terminal window or re-source your shell configuration file in order to load nvm: ``` source ~/.bash_profile ``` ## MySQL For now we’re using MySQL 5.7 as the primary server-side database. Hopefully we’ll change this soon, but for now, install MySQL 5.7 using Homebrew. ``` brew install mysql@5.7; brew upgrade mysql@5.7 ``` Next we’ll configure MySQL to start when your computer boots using `brew services`: ``` brew tap homebrew/services brew services start mysql@5.7 ``` We’ll also want to link MySQL so that you can run CLI commands: ``` brew link mysql@5.7 --force ``` Finally, you should set up a root password for your local MySQL instance: ``` mysqladmin -u root password ``` ## Redis -We use Redis on the server side as a message broker. +We use Redis on the keyserver side as a message broker. ``` brew install redis; brew upgrade redis ``` We’ll set it up to start on boot with `brew services`: ``` brew services start redis ``` ## CocoaPods CocoaPods is a dependency management system for iOS development. React Native uses it to manage native modules. ``` brew install cocoapods; brew upgrade cocoapods ``` ## Reactotron Reactotron is an event tracker and logger that can be used to aid in debugging on React Native. ``` brew install reactotron; brew upgrade reactotron ``` ## React Dev Tools Chrome extension The React Dev Tools Chrome extension lets you inspect the React component tree for web applications in Chrome. You can install it by navigating [here](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi) on Chrome. ## Redux Dev Tools Chrome extension The Redux Dev Tools Chrome extension lets you watch for Redux actions and inspect the Redux store state, both for web applications in Chrome, but also for our native applications using the “Remote DevTools” functionality. To install it, navigate [here](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd) on Chrome. ## JDK We’ll need the Java Development Kit (JDK) for Android development. We’re using [SDKMAN!](https://sdkman.io/) to manage our JDK installation. Run the following to install SDKMAN!: ``` curl -s "https://get.sdkman.io" | bash ``` Now either close and reopen your terminal window or re-source your `~/.bash_profile` (or desired shell configuration file) in order to load SDKMAN!: ``` source ~/.bash_profile ``` You can run `sdk version` to see if SDKMAN! was installed properly. Run the following to install Azul Zulu 11 with SDKMAN!: ``` sdk install java 11.0.13-zulu ``` SDKMAN! takes care of setting up the `$JAVA_HOME` environment variable to point to the newly installed JDK. You can verify this by running `echo $JAVA_HOME`. ## Android Studio Start by downloading and installing [Android Studio](https://developer.android.com/studio/index.html) for your platform. When prompted to choose an installation type, select “Custom”. You’ll be prompted to select a JDK installation. If your SDKMAN!-sourced JDK doesn’t appear in the dropdown, you can find the absolute path to your installed JDK with the following command: ``` sdk home java 11.0.13-zulu ``` Make sure you check the boxes for the following: #### Intel x86-64: - `Android SDK` - `Android SDK Platform` - `Performance (Intel ® HAXM)` - `Android Virtual Device` #### Apple silicon: - `Android SDK` - `Android SDK Platform` - `Android Virtual Device` ### Android SDK Android Studio installs the latest Android SDK by default, but since React Native uses the Android 11 SDK specifically, we’ll need to install it using Android Studio’s SDK Manager. You can access the SDK Manager from the “Welcome to Android Studio” screen that pops up when you first open the application, under “Configure”. If you already have a project open, you can access it from Tools → SDK Manager. Once you have the SDK Manager open, select the “SDK Platforms” tab, and then check the box for “Show Package Details”. Now expand the “Android 11 (R)” section, and make sure the following subsections are checked: - `Android SDK Platform 30` #### Intel x86-64: - `Intel x86 Atom_64 System Image` or `Google APIs Intel x86 Atom System Image` #### Apple silicon: - `Google Play ARM 64 v8a System Image` Next, select the “SDK Tools” tab, and check the box for “Show Package Details”. Refer to `native/android/build.gradle` for specific tool versions and install the following: - Android SDK Build-Tools - NDK - CMake version 3.10.2 To finish the SDK Manager step, click “Apply” to download and install everything you’ve selected. ### Enable Android CLI commands You’ll need to append the following lines to your `~/.bash_profile` (or desired shell configuration file) in order for React Native to be able to build your Android project. ``` export ANDROID_HOME=$HOME/Library/Android/sdk export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=$PATH:$ANDROID_HOME/platform-tools ``` Now either close and reopen your terminal window or re-source your shell configuration file in order to run the new commands: ``` source ~/.bash_profile ``` ## Flipper Flipper is a debugging tool for mobile applications from Facebook. We use it for JavaScript debugging using the Hermes runtime, and also use several plugins such as the React Dev Tools. You can download the latest version of Flipper for MacOS [here](https://www.facebook.com/fbflipper/public/mac). ### Flipper settings After opening Flipper, click the gear icon in the bottom left and navigate to “Settings”. Let’s set the Android SDK path. To find the path, open Android Studio and navigate to Preferences → Appearance & Behavior → System Settings → Android SDK. The explicit path of your Android SDK is defined in “Android SDK Location”. Use this path in Flipper Settings as the “Android SDK Location”. Also, enable the option for “React Native keyboard shortcuts” below. ### Flipper plugins Flipper has a plugin system that allows teams to integrate additional debugging tools into Flipper. We currently only use one plugin, which is for monitoring Redux state. To install it, open Flipper and go to View → Manage Plugins. Type in “redux-debugger“ and install the Flipper plugin with that name. ## idb Flipper relies on Facebook’s idb tool to debug iOS apps running on your device. We’ll need to install it: ``` brew tap facebook/fb brew install idb-companion pip3 install --user --upgrade fb-idb ``` Since we run `pip3 install` with `--user` instead of running it with `sudo`, the `idb` executable gets installed in your userdir. For me, running MacOS with Python 3.9, it got installed in `~/Library/Python/3.9/bin/idb`. For Flipper to be able to talk to `idb`, you’ll need to set the IDB Binary Location in the Flipper Settings. If you have trouble getting Flipper to work with a physical iOS device, it may be due to Python weirdness. The above steps have been tested with Python 3.9 sourced from Homebrew. Let @ashoat know if you have any trouble! ## Codegen for gRPC gRPC is a framework from Google for writing services. As a developer, you define your service’s API using Protobufs, and gRPC handles the networking and basic infrastructure for you. The codegen for gRPC takes files written in the [protocol buffers language](https://developers.google.com/protocol-buffers/docs/proto3) as input and outputs C++ code that enables a developer to create a client and a server that use gRPC for communication. Because of C++ build dependencies, this could not be bundled as an npm package. `brew` also fails to install the required version so if you want to generate files in your local environment, you have to manually install Protobuf. If you find yourself needing to modify the Protobuf schema files, you’ll need to set up the tools to run the codegen. Follow the steps below: - `brew install autoconf automake libtool curl make unzip` - `wget https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protobuf-cpp-3.15.8.tar.gz` - `tar xfzv protobuf-cpp-3.15.8.tar.gz` - `cd protobuf-3.15.8` - `./configure` - `make` - `make check` - `make install` After installing, you should be able to check the version of Protobuf like this: `protoc --version` After installing Protobuf, you will also need to install gRPC using `brew install grpc`. This will install the `grpc_cpp_plugin` for `protoc` (the Protobuf compiler), which is necessary for compiling gRPC schemas. Please note that the order is crucial here - you have to first install Protobuf and only then gRPC. This is because otherwise gRPC will install Protobuf automatically from its dependency list, but the version of Protobuf will be incorrect. ## Arcanist We use Phabricator for code review. To upload a “diff” to Phabricator, you’ll need to use a tool called Arcanist. To install Arcanist, we’ll need to clone its Git repository. Pick a place in your filesystem to store it, and then run this command: ``` git clone https://github.com/phacility/arcanist.git ``` Next, you’ll need to add the path `./arcanist/bin` to your `$PATH` in your `~/.bash_profile` (or desired shell configuration file): ``` export PATH=$PATH:~/src/arcanist/bin ``` Make sure to replace the `~/src` portion of the above with the location of the directory you installed Arcanist in. # Configuration ## Apache In both dev and prod environments we have Node configured to run on port 3000, with Apache proxying it across to port 80. The reason for Apache is so that we can use other tech stacks alongside Node. macOS comes with an Apache installation built in. We just need to configure it a little bit. First, we’ll edit the main Apache configuration file. ``` sudo vim /private/etc/apache2/httpd.conf ``` The following individual lines each need to be uncommented: ``` LoadModule proxy_module libexec/apache2/mod_proxy.so LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so LoadModule proxy_wstunnel_module libexec/apache2/mod_proxy_wstunnel.so LoadModule userdir_module libexec/apache2/mod_userdir.so Include /private/etc/apache2/extra/httpd-userdir.conf ``` Next, we’ll edit the `http-userdir.conf` file. ``` sudo vim /private/etc/apache2/extra/httpd-userdir.conf ``` The following line needs to be uncommented: ``` Include /private/etc/apache2/users/*.conf ``` Now for the main course. We need to set up a configuration file for the current user. ``` sudo vim /private/etc/apache2/users/$USER.conf ``` ``` ProxyRequests on ProxyPass /comm/ws ws://localhost:3000/ws ProxyPass /comm/ http://localhost:3000/ ProxyPass /commlanding/ http://localhost:3000/commlanding/ RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME} RequestHeader set "X-Forwarded-SSL" expr=%{HTTPS} ``` You’ll want to make sure that Apache can read your new file. ``` sudo chmod 644 /private/etc/apache2/users/$USER.conf ``` Finally, let’s restart Apache so it picks up the changes. ``` sudo apachectl restart ``` If you end up installing a macOS update you should go through the Apache configuration section again, as your Apache config in `httpd.conf` may have been restored to the default. ## MySQL Next we’ll set up a MySQL user and a fresh database. We’ll start by opening up a MySQL console. ``` mysql -u root -p ``` Type in the MySQL root password you set up previously when prompted. Then, we’ll go ahead and create an empty database. ``` CREATE DATABASE comm; ``` Now we need to create a user that can access this database. For the following command, replace “password” with a unique password. ``` CREATE USER comm@localhost IDENTIFIED BY 'password'; ``` Finally, we will give permissions to this user to access this database. ``` GRANT ALL ON comm.* TO comm@localhost; ``` You can now exit the MySQL console using Ctrl+D. ## TablePlus Feel free to use a MySQL administration platform that you’re comfortable with. PHP was deprecated in macOS 12 (Monterey), leading many of us to switch to [TablePlus](https://tableplus.com/). After installing TablePlus, you need to open a new connection. After opening TablePlus, click the “Create a new connection” text at the bottom of the window that appears. - Alternatively, you can navigate through Connection → New... in the menu at the top of the display. Choose MySQL from the database options that appear. You’ll be prompted for: - Name (Comm) - Host (localhost) - Port (3306 by default) - User (comm) - Password (the one you made when initializing the MySQL server in the previous step) ## Android Emulator In order to test the Android app on your computer you’ll need to set up an Android Emulator. To do this we’ll need to open up the AVD Manager in Android Studio. AVD stands for “Android Virtual Device”. You can access the AVD Manager from the “Welcome to Android Studio” screen that pops up when you first open the application, under “Configure”. If you already have a project open, you can access it from Tools → AVD Manager. With the AVD Manager open, select “Create Virtual Device” on the bottom row. Feel free to select any “device definition” that includes Play Store support. On the next screen you’ll be asked to select a system image. Go for the latest version of Android that’s been released. From there you can just hit Next and then Finish. You should then be able to start your new AVD from the AVD Manager. # Git repo ## Clone from GitHub Finally! It’s time to clone the repo from GitHub. ``` git clone git@github.com:CommE2E/comm.git ``` Once you have the repo cloned, you can run this command to pull in dependencies. ``` cd comm yarn cleaninstall ``` ## URLs -The server needs to know some info about paths in order to properly construct URLs. +The keyserver needs to know some info about paths in order to properly construct URLs. ``` -mkdir -p server/facts -vim server/facts/url.json +mkdir -p keyserver/facts +vim keyserver/facts/url.json ``` Your `url.json` file should look like this: ```json { "baseRoutePath": "/" } ``` Next, we’ll create files for constructing URLs for the main app. ``` -vim server/facts/squadcal_url.json +vim keyserver/facts/squadcal_url.json ``` Your `squadcal_url.json` file should look like this: ```json { "baseDomain": "http://localhost", "basePath": "/comm/", "baseRoutePath": "/", "https": false } ``` Copy the contents of `squadcal_url.json` to a file called `commapp_url.json`. ``` cp server/facts/squadcal_url.json server/facts/commapp_url.json ``` Finally, we’ll create a file for the URLs in the landing page. ``` -vim server/facts/landing_url.json +vim keyserver/facts/landing_url.json ``` Your `landing_url.json` file should look like this: ```json { "baseDomain": "http://localhost", "basePath": "/commlanding/", "baseRoutePath": "/commlanding/", "https": false } ``` ## MySQL -The server side needs to see some config files before things can work. The first is a config file with MySQL details. +The keyserver side needs to see some config files before things can work. The first is a config file with MySQL details. ``` -cd server +cd keyserver mkdir secrets vim secrets/db_config.json ``` The DB config file should look like this: ```json { "host": "localhost", "user": "comm", "password": "password", "database": "comm" } ``` Make sure to replace the password with the one you set up for your `comm` MySQL user earlier. New let’s run a script to setup the database. Before we can run the script, we’ll have to use Babel to transpile our source files into something Node can interpret. Babel will transpile the files in `src` into a new directory called `dist`. We also use `rsync` to copy over files that don’t need transpilation. ``` yarn babel-build yarn rsync yarn script dist/scripts/create-db.js ``` ## Olm The second config file contains some details that the keyserver needs in order to launch Olm sessions to provide E2E encryption. ``` -cd server +cd keyserver yarn script dist/scripts/generate-olm-config.json ``` -This script will create the `server/secrets/olm_config.json` config file. +This script will create the `keyserver/secrets/olm_config.json` config file. ## Phabricator The last configuration step is to set up an account on Phabricator, where we handle code review. Start by [logging in to Phabricator](https://phabricator.ashoat.com) using your GitHub account. Next, make sure you’re inside the directory containing the Comm Git repository, and run the following command: ``` arc install-certificate ``` This command will help you connect your Phabricator account with the local Arcanist instance, allowing you to run `arc diff` and `arc land` commands. # Development ## Flow typechecker It’s good to run the `flow` typechecker frequently to make sure you’re not introducing any type errors. Flow treats each Yarn Workspace as a separate environment, and as such runs a separate type-checking server for each. This server is started when you first run `node_modules/.bin/flow` in each of the four Yarn Workspace folders. To make sure Flow runs from the command-line, you can edit your `$PATH` environmental variable in your `~/.bash_profile` file (or desired shell configuration file) to always include `./node_modules/.bin`. ``` export PATH=$PATH:./node_modules/.bin ``` As always, make sure you reload the `~/.bash_profile` after editing it: ``` source ~/.bash_profile ``` You should now be able to run `flow` in any of the Yarn workspaces: ``` cd lib flow ``` ## Running web app Open a new terminal and run: ``` cd web yarn dev ``` This will start two processes. One is `webpack-dev-server`, which will serve the JS files. `webpack-dev-server` also makes sure the website automatically hot-reloads whenever any of the source files change. The other process is `webpack --watch`, which will build the `app.build.cjs` file, as well as rebuilding it whenever any of the source files change. The `app.build.cjs` file is consumed by the Node server in order to pre-render the initial HTML from the web source (“Server-Side Rendering”). ## Running landing page Open a new terminal and run: ``` cd landing yarn dev ``` This runs the same two processes as the web app, but for the landing page. Note that the `landing.build.cjs` file (similar to the web app’s `app.build.cjs` file) is consumed by the Node server. -## Running server +## Running keyserver Open a new terminal and run: ``` -cd server +cd keyserver yarn dev ``` You should now be able to load the web app in your web browser at http://localhost/comm/, and the landing page at http://localhost/commlanding/. This command runs three processes. The first two are to keep the `dist` folder updated whenever the `src` folder changes. They are “watch” versions of the same Babel and `rsync` commands we used to initially create the `dist` folder (before running the `create-db.js` script above). The final process is `nodemon`, which is similar to `node` except that it restarts whenever any of its source files (in the `dist` directory) changes. -Note that if you run `yarn dev` in `server` right after `yarn cleaninstall`, before Webpack is given a chance to build `app.build.cjs`/`landing.build.cjs` files, then Node will crash when it attempts to import those files. Just make sure to run `yarn dev` (or `yarn prod`) in `web` or `landing` before attempting to load the corresponding webpages. +Note that if you run `yarn dev` in `keyserver` right after `yarn cleaninstall`, before Webpack is given a chance to build `app.build.cjs`/`landing.build.cjs` files, then Node will crash when it attempts to import those files. Just make sure to run `yarn dev` (or `yarn prod`) in `web` or `landing` before attempting to load the corresponding webpages. ## Running mobile app on iOS Simulator First, make sure that the Metro bundler is running. If you haven’t already, open a new terminal and run: ``` cd native yarn dev ``` This command runs two processes. The first is the Metro bundler, which handles bundling our app’s JavaScript code and communicating with the debug build of the app running on either a physical or virtual device. The second is the `remotedev-server` for Redux, which is a proxy of sorts through which the Redux monitor (running in the Chrome extension) can communicate with the debug build of the app. Next, open `native/ios/Comm.xcworkspace` in Xcode. Select a Simulator from the Scheme menu in the Workspace Toolbar. Then hit the Run button to build and run the project. ## Running mobile app on Android Emulator First, make sure that the Metro bundler is running. If you haven’t already, open a new terminal and run: ``` cd native yarn dev ``` This command runs two processes (see previous section for details). Next, boot up an Android Emulator using Android Studio’s AVD Manager. You should have a single Android Emulator (or plugged-in device) running at one time. Finally, use this command to build and run the Android app: ``` cd native yarn react-native run-android ``` ## Running mobile app on physical iOS devices There are a few things you’ll need to do before you can deploy the app to a physical iOS device. ### Xcode settings First, in Xcode, open the Comm workspace `native/ios/Comm.xcworkspace`. Make sure that you’re signed into Xcode with an Apple Developer account (either the Comm developer team’s or your own). You can see any accounts currently associated with Xcode by navigating to Xcode → Preferences → Accounts. Next, you’ll want to ensure that the Comm project is configured with a valid Team, Bundle Identifier, and Provisioning Profile. To access these settings, navigate to View → Navigators → Project, and select the “Comm” project in the left sidebar. Then, select “Comm” from the “TARGETS” list, and navigate to the “Signing & Capabilities” tab. You should verify the following settings: #### Using a Comm development team Apple Developer account - Team - Comm Technologies, Inc. - Bundle Identifier - app.comm - Provisioning Profile - Make sure that the Provisioning Profile exists #### Using a Personal Apple Developer account - Team - Set this to a valid “Team”, which can just be your personal Apple Developer account. “Comm Technologies, Inc.” may be chosen by default, but it’s not valid if you’re using a personal Apple Developer account - Bundle Identifier - Pick a unique [Bundle Identifier](https://developer.apple.com/documentation/xcode/preparing-your-app-for-distribution) - Provisioning Profile - Make sure that the Provisioning Profile exists ### Building and deploying the app When you plug your iOS device into your machine for the first time, you’ll be prompted to enter your device passcode to enable debugging and deployment. Click the ”Register” button in the dialog that Xcode displays if your device needs to be added to your Provisioning Profile. Make sure to pull the latest changes and clean the build folder before trying to deploy a build to your device. In Xcode, run Product → Clean Build Folder. If you’re running a debug build, you’ll need to check that the Metro bundler is running. If you haven’t already, open a new terminal and run: ``` cd native yarn dev ``` This command runs the Metro bundler and `remotedev-server` for Redux (see the “Running mobile app on iOS simulator” section for more details). You should finally be ready to build and deploy the app in Xcode! Select your physical device from ”run destinations” in the Workspace Toolbar. Then hit the Run button to build and run the project. -If you’re connecting to a local server instance, you’ll want to “Allow Comm to Access” the “Local Network” in your device Settings. This toggle can be found from Settings → Comm. Note that this setting is not enabled by default, and you may have to re-enable it on subsequent build deployments. +If you’re connecting to a local keyserver instance, you’ll want to “Allow Comm to Access” the “Local Network” in your device Settings. This toggle can be found from Settings → Comm. Note that this setting is not enabled by default, and you may have to re-enable it on subsequent build deployments. -### Connecting to local server +### Connecting to local keyserver -If you want your custom build of the app to connect to your local instance of the Node.js server (the `server` subdirectory of the repo), you’ll need to do some additional work. First, confirm that your computer and physical iOS device are on the same network. If you’re running a local server instance, you’ll need to be able to reach it with your device. Local servers run on the local IP address at port 8043. +If you want your custom build of the app to connect to your local instance of the Node.js server (the `keyserver` subdirectory of the repo), you’ll need to do some additional work. First, confirm that your computer and physical iOS device are on the same network. If you’re running a local keyserver instance, you’ll need to be able to reach it with your device. Local keyservers run on the local IP address at port 8043. To find your machine’s local IP address, navigate to System Preferences → Network, and select the hardware interface you’re currently using to connect to the internet (Wi-Fi, or potentially a Thunderbolt port for ethernet connections). Next, click “Advanced” and go to the “TCP/IP” tab. Your local IP address is listed as the “IPv4 Address”. Try visiting this IP address using a browser on your device. It should display an “It works!” message if your iOS device can reach your machine. -Finally, we need to direct the mobile app to use your local server instance. There are a few different ways to do this, depending on your situation: +Finally, we need to direct the mobile app to use your local keyserver instance. There are a few different ways to do this, depending on your situation: - As long as you’re deploying a debug build, this strategy should work for you. You can create a `network.json` file in `native/facts` that will override the default. ``` mkdir -p native/facts vim native/facts/network.json ``` Your `network.json` file should look like the following, where `w.x.y.z` is the local IP address you found earlier: ```json { "natDevHostname": "w.x.y.z" } ``` You’ll need to delete and reinstall the app for changes to `native/facts/network.json` to take effect, as the default production URL is persisted in Redux. - If you’re deploying a release build, the above strategy won’t work. Your best bet to override the server URL is to get to the secret “Developer tools” menu option in the app. 1. You may need to use a real production account for this, since the server address will default to the production server if this is the first build you've deployed to the target device. 2. Next, in order for the “Developer tools” menu option to appear, you’ll need to add your user ID to [the list of user IDs in `staff.json`](https://github.com/CommE2E/comm/blob/master/lib/facts/staff.json). A good way to figure out your user ID is to use the Chrome Redux debugger to inspect the `currentUserInfo` property when logged into the web app. 3. Finally, you should be able to navigate to Profile → Developer tools in the app and set the address of the local server. It should look something like this: ``` http://w.x.y.z/comm ``` Where `w.x.y.z` is the local IP address you found earlier. - Alternately, if you’re on a release build and option 2 above seems like too much of a hassle, you should be able to simply change the value of [`productionNodeServerURL` in the code](https://github.com/CommE2E/comm/blob/9e6a13f1569787b498a72c890b12ce0dd8323804/native/utils/url-utils.js#L12). Note that you’ll need to delete and reinstall the app for this change to take effect, as the default production URL is persisted in Redux. ## Running Node scripts -To run one of the scripts in `server/src/scripts`, you should start by making sure that the Node server is running. If you haven’t already, open a new terminal and run: +To run one of the scripts in `keyserver/src/scripts`, you should start by making sure that the Node server is running. If you haven’t already, open a new terminal and run: ``` cd native yarn dev ``` -Then, from the `server` directory, run `yarn script dist/scripts/name.js`, where `name.js` is the file containing the script. +Then, from the `keyserver` directory, run `yarn script dist/scripts/name.js`, where `name.js` is the file containing the script. ## Codegen We use a couple of tools that automatically generate code. There is always a source of truth – usually some file(s) with schemas. ### Codegen for JSI JSI is a framework in React Native that allows C++ and JS to communicate synchronously and directly. The codegen for JSI takes a Flow schema and generates C++ files that enable communication between JS and C++ in `react-native` apps. The script to generate this code is written in JavaScript and is included as a npm package so no additional software is needed to use it. The schema has to be defined in Flow as an interface, and that interface must inherit from react-native’s `TurboModule` interface. To run the JSI codegen, just run: ``` cd native yarn codegen-jsi ``` The input Flow schemas are located in `native/schema`. ### Codegen for gRPC In order to generate the codegen files for gRPC, you should run the following command: ``` cd native yarn codegen-grpc ``` # Debugging ## React Developer Tools - For web, you can access the React Developer Tools through the Chrome extension by opening the Chrome Developer Tools and selecting the “Components” or “Profiler” tabs. This should work in both our development environment and in production. - For iOS and Android, you can access the React Developer Tools through Flipper. First start a debug build of a React Native app. Next, just open up Flipper and you should be able to see an option for “React DevTools”. Flipper communicates with the app through the Metro bundler that gets started when you run `cd native && yarn dev`. ## Redux Developer Tools - For web, you can access the Redux Developer Tools through the Chrome extension by opening the Chrome Developer Tools and selecting the “Redux” tab. This should work in both our development environment and in production, although in production you won’t be able to see Redux actions from before you opened up the Redux dev tools. - For iOS and Android, you can access the Redux Developer Tools through the Chrome extension’s Remote DevTools functionality. First, to open the Remote DevTools, right click on any webpage, go into the “Redux DevTools” menu, and select “Open Remote DevTools”. Then hit “Settings”, select “Use custom (local) server”, and configure it to connect to `localhost` on port 8043. This will connect to the `remotedev-server` instance that you started when you ran `cd native && yarn dev`. ## Debugging JavaScript - For web, you can just use your browser of choice’s dev tools. - For iOS and Android, you should use Flipper. First start a debug build of a React Native app. Next, just open up Flipper and you should be able to see an option for “Hermes Debugger (RN)”. Flipper communicates with the app through the Metro bundler that gets started when you run `cd native && yarn dev`. # Working with Phabricator ## Creating a new diff The biggest difference between GitHub’s PR workflow and Phabricator’s “diff” workflow is that Phabricator lets you create a diff from any commit, or set of commits. In contrast, GitHub can only create PRs from branches. When you have a commit ready and want to submit a diff for code review, just run `arc diff` from within the Comm Git repo. Arcanist will attempt to determine the “base” for your diff automatically, but by default it will take the single most recent commit. You can see what base Arcanist thinks it should use by running `arc which`. You can also explicitly specify a base by using `arc diff --base`. For instance, `arc diff --base HEAD^` will create a diff from the most recent commit, which should be the default behavior. Keep in mind that `arc diff` always diffs the base against your current working copy. Though this nominally includes any unstashed changes you might have, `arc diff`’s interactive prompts will help you exclude unrelated changes in your working copy. It’s generally easiest to keep a 1:1 correspondence between diffs and commits. If you’re working with a stack of commits, you can use Git’s interactive rebase feature (`git rebase -i`) to run `arc diff` on each commit individually. ## Updating a diff Whereas with GitHub PRs, updates are usually created by adding on more commits, in Phabricator the easiest way to update a diff is by amending the existing commit. When you run `arc diff` on a commit for the first time, it amends the commit message to include a link to the Phabricator diff. If and when you want to update that diff, just run `arc diff` again. If you’re working with a stack of diffs, and want to update an earlier diff, you can use Git’s interactive rebase feature (`git rebase -i`) to open the stack to a particular point. Then you can amend that commit and run `arc diff` before continuing the rebase. ## Committing a diff After your diff has been accepted, you should be able to land it. To land a diff just run `arc land` from within the repository. If you’re dealing with a stack, `arc land` will make sure to only land the diffs that have been accepted, and shouldn’t land any diffs that depend on other diffs that haven’t been accepted yet. Note that you need commit rights to the repository in order to run `arc land`. If you don’t have commit rights, reach out to @ashoat for assistance. ## Creating a Herald rule Once you have access to Phabricator, you may want to set up a Herald rule so that you get CC’d on any new diffs. The way to do that in Phabricator is: 1. Go to “More Applications” on the left-hand sidebar. 2. Select “Herald” from the list. 3. Press the “Create Herald Rule” button in the upper-right corner of the screen. 4. Select “Differential Revisions” from the list. 5. Select “Personal Rule” from the list. 6. Set up your new rule to match [this one](https://phabricator.ashoat.com/H2). ## Final notes -When developing, I usually just pop up three terminal windows, one for `yarn dev` in each of server, web, and native. +When developing, I usually just pop up three terminal windows, one for `yarn dev` in each of keyserver, web, and native. Note that it’s currently only possible to create a user account using the iOS or Android apps. The website supports logging in, but does not support account creation. Good luck, and let @ashoat know if you have any questions! diff --git a/server/.eslintrc.json b/keyserver/.eslintrc.json similarity index 100% rename from server/.eslintrc.json rename to keyserver/.eslintrc.json diff --git a/server/.flowconfig b/keyserver/.flowconfig similarity index 100% rename from server/.flowconfig rename to keyserver/.flowconfig diff --git a/server/.npmrc b/keyserver/.npmrc similarity index 100% rename from server/.npmrc rename to keyserver/.npmrc diff --git a/server/.nvmrc b/keyserver/.nvmrc similarity index 100% rename from server/.nvmrc rename to keyserver/.nvmrc diff --git a/server/.well-known/apple-app-site-association b/keyserver/.well-known/apple-app-site-association similarity index 100% rename from server/.well-known/apple-app-site-association rename to keyserver/.well-known/apple-app-site-association diff --git a/server/.well-known/assetlinks.json b/keyserver/.well-known/assetlinks.json similarity index 100% rename from server/.well-known/assetlinks.json rename to keyserver/.well-known/assetlinks.json diff --git a/server/app_compiled b/keyserver/app_compiled similarity index 100% rename from server/app_compiled rename to keyserver/app_compiled diff --git a/server/babel.config.cjs b/keyserver/babel.config.cjs similarity index 100% rename from server/babel.config.cjs rename to keyserver/babel.config.cjs diff --git a/server/bash/backup_phabricator.sh b/keyserver/bash/backup_phabricator.sh similarity index 100% rename from server/bash/backup_phabricator.sh rename to keyserver/bash/backup_phabricator.sh diff --git a/server/bash/deploy.sh b/keyserver/bash/deploy.sh similarity index 82% rename from server/bash/deploy.sh rename to keyserver/bash/deploy.sh index add1210f4..4655cb146 100755 --- a/server/bash/deploy.sh +++ b/keyserver/bash/deploy.sh @@ -1,56 +1,56 @@ #!/bin/bash # run as: ssh user on root wheel # run from: wherever # param: path to link to # The maximum amount of space to spend on checkouts. By default we leave around # old deployments in case we want to roll back. The limit includes the current # prod checkout, but will never delete prod. MAX_DISK_USAGE_KB=3145728 # 3 GiB # The user that spawns the Node server DAEMON_USER=comm # Input to git clone GIT_CLONE_PARAMS=https://github.com/CommE2E/comm.git set -e [[ `whoami` = root ]] || exec sudo su -c "$0 $1" # STEP 1: clone source into new directory CHECKOUT_PATH=$1.$(date +%F-%H-%M) rm -rf "$CHECKOUT_PATH" # badass. risky mkdir -p "$CHECKOUT_PATH" chown $DAEMON_USER:$DAEMON_USER "$CHECKOUT_PATH" su $DAEMON_USER -c "git clone $GIT_CLONE_PARAMS '$CHECKOUT_PATH'" -su $DAEMON_USER -c "cp -r '$1'/server/secrets '$CHECKOUT_PATH'/server/secrets" -su $DAEMON_USER -c "cp -r '$1'/server/facts '$CHECKOUT_PATH'/server/facts" +su $DAEMON_USER -c "cp -r '$1'/keyserver/secrets '$CHECKOUT_PATH'/keyserver/secrets" +su $DAEMON_USER -c "cp -r '$1'/keyserver/facts '$CHECKOUT_PATH'/keyserver/facts" cd "$CHECKOUT_PATH" -su $DAEMON_USER -c "server/bash/setup.sh" +su $DAEMON_USER -c "keyserver/bash/setup.sh" # STEP 2: test if the binary crashes within 60 seconds set +e -su $DAEMON_USER -c "cd server && PORT=3001 timeout 60 bash/run-prod.sh" +su $DAEMON_USER -c "cd keyserver && PORT=3001 timeout 60 bash/run-prod.sh" [[ $? -eq 124 ]] || exit 1 set -e # STEP 3: flip it over systemctl stop comm || true rm "$1" ln -s "$CHECKOUT_PATH" "$1" chown -h $DAEMON_USER:$DAEMON_USER "$1" systemctl restart comm # STEP 4: clean out old checkouts checkouts=($(ls -dtr "$1".*)) for checkout in "${checkouts[@]}"; do if [[ "$checkout" = "$CHECKOUT_PATH" ]]; then break fi TOTAL_USAGE=$(sudo du -cs $1* | grep total | awk '{ print $1 }') if [[ $TOTAL_USAGE -le $MAX_DISK_USAGE_KB ]]; then break fi rm -rf "$checkout" done diff --git a/server/bash/run-prod.sh b/keyserver/bash/run-prod.sh similarity index 100% rename from server/bash/run-prod.sh rename to keyserver/bash/run-prod.sh diff --git a/server/bash/setup.sh b/keyserver/bash/setup.sh similarity index 74% rename from server/bash/setup.sh rename to keyserver/bash/setup.sh index 7a65725b9..20e6c57eb 100755 --- a/server/bash/setup.sh +++ b/keyserver/bash/setup.sh @@ -1,17 +1,17 @@ #!/bin/bash # run as: node user # run from: root of repo set -e . ~/.nvm/nvm.sh chmod -R u=rwX,g=rX,o=rX . -chmod -R u=rwX,g=,o= server/secrets +chmod -R u=rwX,g=,o= keyserver/secrets pushd server && nvm install && popd yarn cleaninstall yarn workspace web prod yarn workspace landing prod -yarn workspace server prod-build +yarn workspace keyserver prod-build diff --git a/server/bash/source-nvm.sh b/keyserver/bash/source-nvm.sh similarity index 100% rename from server/bash/source-nvm.sh rename to keyserver/bash/source-nvm.sh diff --git a/server/flow-typed/npm/@parse/node-apn_vx.x.x.js b/keyserver/flow-typed/npm/@parse/node-apn_vx.x.x.js similarity index 100% rename from server/flow-typed/npm/@parse/node-apn_vx.x.x.js rename to keyserver/flow-typed/npm/@parse/node-apn_vx.x.x.js diff --git a/server/flow-typed/npm/body-parser_v1.x.x.js b/keyserver/flow-typed/npm/body-parser_v1.x.x.js similarity index 100% rename from server/flow-typed/npm/body-parser_v1.x.x.js rename to keyserver/flow-typed/npm/body-parser_v1.x.x.js diff --git a/server/flow-typed/npm/buffer-image-size_vx.x.x.js b/keyserver/flow-typed/npm/buffer-image-size_vx.x.x.js similarity index 100% rename from server/flow-typed/npm/buffer-image-size_vx.x.x.js rename to keyserver/flow-typed/npm/buffer-image-size_vx.x.x.js diff --git a/server/flow-typed/npm/common-tags_v1.4.x.js b/keyserver/flow-typed/npm/common-tags_v1.4.x.js similarity index 100% rename from server/flow-typed/npm/common-tags_v1.4.x.js rename to keyserver/flow-typed/npm/common-tags_v1.4.x.js diff --git a/server/flow-typed/npm/cookie-parser_v1.x.x.js b/keyserver/flow-typed/npm/cookie-parser_v1.x.x.js similarity index 100% rename from server/flow-typed/npm/cookie-parser_v1.x.x.js rename to keyserver/flow-typed/npm/cookie-parser_v1.x.x.js diff --git a/server/flow-typed/npm/express_v4.17.x.js b/keyserver/flow-typed/npm/express_v4.17.x.js similarity index 100% rename from server/flow-typed/npm/express_v4.17.x.js rename to keyserver/flow-typed/npm/express_v4.17.x.js diff --git a/server/flow-typed/npm/firebase-admin_vx.x.x.js b/keyserver/flow-typed/npm/firebase-admin_vx.x.x.js similarity index 100% rename from server/flow-typed/npm/firebase-admin_vx.x.x.js rename to keyserver/flow-typed/npm/firebase-admin_vx.x.x.js diff --git a/server/flow-typed/npm/flow-bin_v0.x.x.js b/keyserver/flow-typed/npm/flow-bin_v0.x.x.js similarity index 100% rename from server/flow-typed/npm/flow-bin_v0.x.x.js rename to keyserver/flow-typed/npm/flow-bin_v0.x.x.js diff --git a/server/flow-typed/npm/history_v4.x.x.js b/keyserver/flow-typed/npm/history_v4.x.x.js similarity index 100% rename from server/flow-typed/npm/history_v4.x.x.js rename to keyserver/flow-typed/npm/history_v4.x.x.js diff --git a/server/flow-typed/npm/invariant_v2.x.x.js b/keyserver/flow-typed/npm/invariant_v2.x.x.js similarity index 100% rename from server/flow-typed/npm/invariant_v2.x.x.js rename to keyserver/flow-typed/npm/invariant_v2.x.x.js diff --git a/server/flow-typed/npm/jest_v26.x.x.js b/keyserver/flow-typed/npm/jest_v26.x.x.js similarity index 100% rename from server/flow-typed/npm/jest_v26.x.x.js rename to keyserver/flow-typed/npm/jest_v26.x.x.js diff --git a/server/flow-typed/npm/lodash_v4.x.x.js b/keyserver/flow-typed/npm/lodash_v4.x.x.js similarity index 100% rename from server/flow-typed/npm/lodash_v4.x.x.js rename to keyserver/flow-typed/npm/lodash_v4.x.x.js diff --git a/server/flow-typed/npm/mysql_v2.x.x.js b/keyserver/flow-typed/npm/mysql_v2.x.x.js similarity index 100% rename from server/flow-typed/npm/mysql_v2.x.x.js rename to keyserver/flow-typed/npm/mysql_v2.x.x.js diff --git a/server/flow-typed/npm/react-redux_v7.x.x.js b/keyserver/flow-typed/npm/react-redux_v7.x.x.js similarity index 100% rename from server/flow-typed/npm/react-redux_v7.x.x.js rename to keyserver/flow-typed/npm/react-redux_v7.x.x.js diff --git a/server/flow-typed/npm/react-router-dom_v5.x.x.js b/keyserver/flow-typed/npm/react-router-dom_v5.x.x.js similarity index 100% rename from server/flow-typed/npm/react-router-dom_v5.x.x.js rename to keyserver/flow-typed/npm/react-router-dom_v5.x.x.js diff --git a/server/flow-typed/npm/react-router_v5.x.x.js b/keyserver/flow-typed/npm/react-router_v5.x.x.js similarity index 100% rename from server/flow-typed/npm/react-router_v5.x.x.js rename to keyserver/flow-typed/npm/react-router_v5.x.x.js diff --git a/server/flow-typed/npm/redis_v2.x.x.js b/keyserver/flow-typed/npm/redis_v2.x.x.js similarity index 100% rename from server/flow-typed/npm/redis_v2.x.x.js rename to keyserver/flow-typed/npm/redis_v2.x.x.js diff --git a/server/flow-typed/npm/redux_v4.x.x.js b/keyserver/flow-typed/npm/redux_v4.x.x.js similarity index 100% rename from server/flow-typed/npm/redux_v4.x.x.js rename to keyserver/flow-typed/npm/redux_v4.x.x.js diff --git a/server/flow-typed/npm/rereadable-stream_vx.x.x.js b/keyserver/flow-typed/npm/rereadable-stream_vx.x.x.js similarity index 100% rename from server/flow-typed/npm/rereadable-stream_vx.x.x.js rename to keyserver/flow-typed/npm/rereadable-stream_vx.x.x.js diff --git a/server/flow-typed/npm/uuid_v3.x.x.js b/keyserver/flow-typed/npm/uuid_v3.x.x.js similarity index 100% rename from server/flow-typed/npm/uuid_v3.x.x.js rename to keyserver/flow-typed/npm/uuid_v3.x.x.js diff --git a/server/flow-typed/npm/ws_v7.x.x.js b/keyserver/flow-typed/npm/ws_v7.x.x.js similarity index 100% rename from server/flow-typed/npm/ws_v7.x.x.js rename to keyserver/flow-typed/npm/ws_v7.x.x.js diff --git a/server/fonts/IBMPlexMono-Medium.woff2 b/keyserver/fonts/IBMPlexMono-Medium.woff2 similarity index 100% rename from server/fonts/IBMPlexMono-Medium.woff2 rename to keyserver/fonts/IBMPlexMono-Medium.woff2 diff --git a/server/fonts/IBMPlexSans-Medium.woff2 b/keyserver/fonts/IBMPlexSans-Medium.woff2 similarity index 100% rename from server/fonts/IBMPlexSans-Medium.woff2 rename to keyserver/fonts/IBMPlexSans-Medium.woff2 diff --git a/server/fonts/IBMPlexSans-Regular.woff2 b/keyserver/fonts/IBMPlexSans-Regular.woff2 similarity index 100% rename from server/fonts/IBMPlexSans-Regular.woff2 rename to keyserver/fonts/IBMPlexSans-Regular.woff2 diff --git a/server/fonts/anaheim-latin-ext.woff2 b/keyserver/fonts/anaheim-latin-ext.woff2 similarity index 100% rename from server/fonts/anaheim-latin-ext.woff2 rename to keyserver/fonts/anaheim-latin-ext.woff2 diff --git a/server/fonts/anaheim-latin.woff2 b/keyserver/fonts/anaheim-latin.woff2 similarity index 100% rename from server/fonts/anaheim-latin.woff2 rename to keyserver/fonts/anaheim-latin.woff2 diff --git a/server/fonts/duo.css b/keyserver/fonts/duo.css similarity index 100% rename from server/fonts/duo.css rename to keyserver/fonts/duo.css diff --git a/server/fonts/iAWriterDuoS-Bold.woff2 b/keyserver/fonts/iAWriterDuoS-Bold.woff2 similarity index 100% rename from server/fonts/iAWriterDuoS-Bold.woff2 rename to keyserver/fonts/iAWriterDuoS-Bold.woff2 diff --git a/server/fonts/iAWriterDuoS-BoldItalic.woff2 b/keyserver/fonts/iAWriterDuoS-BoldItalic.woff2 similarity index 100% rename from server/fonts/iAWriterDuoS-BoldItalic.woff2 rename to keyserver/fonts/iAWriterDuoS-BoldItalic.woff2 diff --git a/server/fonts/iAWriterDuoS-Italic.woff2 b/keyserver/fonts/iAWriterDuoS-Italic.woff2 similarity index 100% rename from server/fonts/iAWriterDuoS-Italic.woff2 rename to keyserver/fonts/iAWriterDuoS-Italic.woff2 diff --git a/server/fonts/iAWriterDuoS-Regular.woff2 b/keyserver/fonts/iAWriterDuoS-Regular.woff2 similarity index 100% rename from server/fonts/iAWriterDuoS-Regular.woff2 rename to keyserver/fonts/iAWriterDuoS-Regular.woff2 diff --git a/server/fonts/iAWriterLICENSE.md b/keyserver/fonts/iAWriterLICENSE.md similarity index 100% rename from server/fonts/iAWriterLICENSE.md rename to keyserver/fonts/iAWriterLICENSE.md diff --git a/server/fonts/local-fonts.css b/keyserver/fonts/local-fonts.css similarity index 100% rename from server/fonts/local-fonts.css rename to keyserver/fonts/local-fonts.css diff --git a/server/icons/android-chrome-192x192.png b/keyserver/icons/android-chrome-192x192.png similarity index 100% rename from server/icons/android-chrome-192x192.png rename to keyserver/icons/android-chrome-192x192.png diff --git a/server/icons/android-chrome-512x512.png b/keyserver/icons/android-chrome-512x512.png similarity index 100% rename from server/icons/android-chrome-512x512.png rename to keyserver/icons/android-chrome-512x512.png diff --git a/server/icons/apple-touch-icon.png b/keyserver/icons/apple-touch-icon.png similarity index 100% rename from server/icons/apple-touch-icon.png rename to keyserver/icons/apple-touch-icon.png diff --git a/server/icons/browserconfig.xml b/keyserver/icons/browserconfig.xml similarity index 100% rename from server/icons/browserconfig.xml rename to keyserver/icons/browserconfig.xml diff --git a/server/icons/favicon-16x16.png b/keyserver/icons/favicon-16x16.png similarity index 100% rename from server/icons/favicon-16x16.png rename to keyserver/icons/favicon-16x16.png diff --git a/server/icons/favicon-32x32.png b/keyserver/icons/favicon-32x32.png similarity index 100% rename from server/icons/favicon-32x32.png rename to keyserver/icons/favicon-32x32.png diff --git a/server/icons/favicon.ico b/keyserver/icons/favicon.ico similarity index 100% rename from server/icons/favicon.ico rename to keyserver/icons/favicon.ico diff --git a/server/icons/mstile-150x150.png b/keyserver/icons/mstile-150x150.png similarity index 100% rename from server/icons/mstile-150x150.png rename to keyserver/icons/mstile-150x150.png diff --git a/server/icons/safari-pinned-tab.svg b/keyserver/icons/safari-pinned-tab.svg similarity index 100% rename from server/icons/safari-pinned-tab.svg rename to keyserver/icons/safari-pinned-tab.svg diff --git a/server/icons/site.webmanifest b/keyserver/icons/site.webmanifest similarity index 100% rename from server/icons/site.webmanifest rename to keyserver/icons/site.webmanifest diff --git a/server/images/animated_cloud.json b/keyserver/images/animated_cloud.json similarity index 100% rename from server/images/animated_cloud.json rename to keyserver/images/animated_cloud.json diff --git a/server/images/animated_eye.json b/keyserver/images/animated_eye.json similarity index 100% rename from server/images/animated_eye.json rename to keyserver/images/animated_eye.json diff --git a/server/images/corner_arrow.svg b/keyserver/images/corner_arrow.svg similarity index 100% rename from server/images/corner_arrow.svg rename to keyserver/images/corner_arrow.svg diff --git a/server/images/hero_illustration.svg b/keyserver/images/hero_illustration.svg similarity index 100% rename from server/images/hero_illustration.svg rename to keyserver/images/hero_illustration.svg diff --git a/server/images/placeholder.png b/keyserver/images/placeholder.png similarity index 100% rename from server/images/placeholder.png rename to keyserver/images/placeholder.png diff --git a/server/images/server_illustration.svg b/keyserver/images/server_illustration.svg similarity index 100% rename from server/images/server_illustration.svg rename to keyserver/images/server_illustration.svg diff --git a/server/images/server_illustration_small.svg b/keyserver/images/server_illustration_small.svg similarity index 100% rename from server/images/server_illustration_small.svg rename to keyserver/images/server_illustration_small.svg diff --git a/server/landing_compiled b/keyserver/landing_compiled similarity index 100% rename from server/landing_compiled rename to keyserver/landing_compiled diff --git a/server/landing_icons/apple-touch-icon.png b/keyserver/landing_icons/apple-touch-icon.png similarity index 100% rename from server/landing_icons/apple-touch-icon.png rename to keyserver/landing_icons/apple-touch-icon.png diff --git a/server/landing_icons/landing-favicon-16x16.png b/keyserver/landing_icons/landing-favicon-16x16.png similarity index 100% rename from server/landing_icons/landing-favicon-16x16.png rename to keyserver/landing_icons/landing-favicon-16x16.png diff --git a/server/landing_icons/landing-favicon-32x32.png b/keyserver/landing_icons/landing-favicon-32x32.png similarity index 100% rename from server/landing_icons/landing-favicon-32x32.png rename to keyserver/landing_icons/landing-favicon-32x32.png diff --git a/server/loader.mjs b/keyserver/loader.mjs similarity index 90% rename from server/loader.mjs rename to keyserver/loader.mjs index 418bbac0e..a9c11b451 100644 --- a/server/loader.mjs +++ b/keyserver/loader.mjs @@ -1,18 +1,19 @@ +// @flow const localPackages = ['landing', 'lib', 'web']; async function resolve(specifier, context, defaultResolve) { const defaultResult = defaultResolve(specifier, context, defaultResolve); // Special hack to use Babel-transpiled lib and web if (localPackages.some(pkg => specifier.startsWith(`${pkg}/`))) { const url = defaultResult.url.replace( specifier, - `server/dist/${specifier}`, + `keyserver/dist/${specifier}`, ); return { url }; } return defaultResult; } export { resolve }; diff --git a/server/misc/android_privacy_policy.html b/keyserver/misc/android_privacy_policy.html similarity index 100% rename from server/misc/android_privacy_policy.html rename to keyserver/misc/android_privacy_policy.html diff --git a/server/package.json b/keyserver/package.json similarity index 97% rename from server/package.json rename to keyserver/package.json index da8720ab2..1abc79efb 100644 --- a/server/package.json +++ b/keyserver/package.json @@ -1,98 +1,98 @@ { - "name": "server", + "name": "keyserver", "version": "0.0.1", "type": "module", "private": true, "license": "BSD-3-Clause", - "main": "dist/server", + "main": "dist/keyserver", "scripts": { "clean": "rm -rf dist/ && rm -rf node_modules/ && mkdir dist", "babel-build": "yarn --silent babel src/ --out-dir dist/ --config-file ./babel.config.cjs --verbose --ignore 'src/landing/flow-typed','src/landing/node_modules','src/landing/package.json','src/lib/flow-typed','src/lib/node_modules','src/lib/package.json','src/web/flow-typed','src/web/node_modules','src/web/package.json','src/web/dist','src/web/webpack.config.js','src/web/account-bar.react.js','src/web/app.react.js','src/web/calendar','src/web/chat','src/web/flow','src/web/loading-indicator.react.js','src/web/modals','src/web/root.js','src/web/router-history.js','src/web/script.js','src/web/selectors/chat-selectors.js','src/web/selectors/entry-selectors.js','src/web/splash','src/web/vector-utils.js','src/web/vectors.react.js'", "rsync": "rsync -rLpmuv --exclude '*/package.json' --exclude '*/node_modules/*' --include '*.json' --include '*.cjs' --exclude '*.*' src/ dist/", "prod-build": "yarn babel-build && yarn rsync && yarn update-geoip", "update-geoip": "yarn script dist/scripts/update-geoip.js", - "prod": "node --trace-warnings --experimental-json-modules --loader=./loader.mjs --experimental-specifier-resolution=node dist/server", + "prod": "node --trace-warnings --experimental-json-modules --loader=./loader.mjs --experimental-specifier-resolution=node dist/keyserver", "dev-rsync": "yarn --silent chokidar --initial --silent -s 'src/**/*.json' 'src/**/*.cjs' -c 'yarn rsync > /dev/null 2>&1'", - "dev": "yarn concurrently --names=\"BABEL,RSYNC,NODEM\" -c \"bgBlue.bold,bgMagenta.bold,bgGreen.bold\" \"yarn babel-build --watch\" \"yarn dev-rsync\" \". bash/source-nvm.sh && NODE_ENV=development nodemon -e js,json,cjs --watch dist --experimental-json-modules --loader=./loader.mjs --experimental-specifier-resolution=node dist/server\"", + "dev": "yarn concurrently --names=\"BABEL,RSYNC,NODEM\" -c \"bgBlue.bold,bgMagenta.bold,bgGreen.bold\" \"yarn babel-build --watch\" \"yarn dev-rsync\" \". bash/source-nvm.sh && NODE_ENV=development nodemon -e js,json,cjs --watch dist --experimental-json-modules --loader=./loader.mjs --experimental-specifier-resolution=node dist/keyserver\"", "script": ". bash/source-nvm.sh && NODE_ENV=development node --experimental-json-modules --loader=./loader.mjs --experimental-specifier-resolution=node", "test": "jest" }, "devDependencies": { "@babel/cli": "^7.13.14", "@babel/core": "^7.13.14", "@babel/node": "^7.13.13", "@babel/plugin-proposal-class-properties": "^7.13.0", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8", "@babel/plugin-proposal-object-rest-spread": "^7.13.8", "@babel/plugin-proposal-optional-chaining": "^7.13.12", "@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-transform-runtime": "^7.13.10", "@babel/preset-env": "^7.13.12", "@babel/preset-flow": "^7.13.13", "@babel/preset-react": "^7.13.13", "babel-jest": "^26.6.3", "chokidar-cli": "^2.1.0", "concurrently": "^5.3.0", "flow-bin": "^0.158.0", "flow-typed": "^3.2.1", "jest": "^26.6.3", "nodemon": "^2.0.4" }, "dependencies": { "@babel/runtime": "^7.13.10", "@grpc/grpc-js": "^1.4.6", "@matrix-org/olm": "3.2.4", "@parse/node-apn": "^3.2.0", "@vingle/bmp-js": "^0.2.5", "JSONStream": "^1.3.5", "common-tags": "^1.7.2", "cookie-parser": "^1.4.3", "dateformat": "^3.0.3", "express": "^4.17.1", "express-ws": "^4.0.0", "firebase-admin": "^10.0.1", "geoip-lite": "^1.4.0", "invariant": "^2.2.4", "landing": "0.0.1", "lib": "0.0.1", "lodash": "^4.17.21", "multer": "^1.4.1", "mysql2": "^1.5.1", "node-schedule": "^1.3.0", "nodemailer": "^6.6.1", "react": "17.0.2", "react-dom": "17.0.2", "react-html-email": "^3.0.0", "react-redux": "^7.1.1", "react-router": "^5.2.0", "redis": "^3.1.1", "redux": "^4.0.4", "replacestream": "^4.0.3", "rereadable-stream": "^1.4.5", "sharp": "^0.29.3", "sql-template-strings": "^2.2.2", "stream-combiner": "^0.2.2", "tcomb": "^3.2.29", "twin-bcrypt": "^2.1.1", "uuid": "^3.3.3", "web": "0.0.1" }, "optionalDependencies": { "bufferutil": "^4.0.5", "utf-8-validate": "^5.0.7" }, "nodemonConfig": { "delay": "200" }, "jest": { "roots": [ "/src" ], "transform": { "\\.js$": "babel-jest" }, "transformIgnorePatterns": [ "/node_modules/(?!@babel/runtime)" ] } } diff --git a/server/src/bots/commbot.js b/keyserver/src/bots/commbot.js similarity index 100% rename from server/src/bots/commbot.js rename to keyserver/src/bots/commbot.js diff --git a/server/src/creators/account-creator.js b/keyserver/src/creators/account-creator.js similarity index 100% rename from server/src/creators/account-creator.js rename to keyserver/src/creators/account-creator.js diff --git a/server/src/creators/day-creator.js b/keyserver/src/creators/day-creator.js similarity index 100% rename from server/src/creators/day-creator.js rename to keyserver/src/creators/day-creator.js diff --git a/server/src/creators/entry-creator.js b/keyserver/src/creators/entry-creator.js similarity index 100% rename from server/src/creators/entry-creator.js rename to keyserver/src/creators/entry-creator.js diff --git a/server/src/creators/id-creator.js b/keyserver/src/creators/id-creator.js similarity index 100% rename from server/src/creators/id-creator.js rename to keyserver/src/creators/id-creator.js diff --git a/server/src/creators/message-creator.js b/keyserver/src/creators/message-creator.js similarity index 100% rename from server/src/creators/message-creator.js rename to keyserver/src/creators/message-creator.js diff --git a/server/src/creators/one-time-keys-creator.js b/keyserver/src/creators/one-time-keys-creator.js similarity index 100% rename from server/src/creators/one-time-keys-creator.js rename to keyserver/src/creators/one-time-keys-creator.js diff --git a/server/src/creators/relationship-creators.js b/keyserver/src/creators/relationship-creators.js similarity index 100% rename from server/src/creators/relationship-creators.js rename to keyserver/src/creators/relationship-creators.js diff --git a/server/src/creators/report-creator.js b/keyserver/src/creators/report-creator.js similarity index 100% rename from server/src/creators/report-creator.js rename to keyserver/src/creators/report-creator.js diff --git a/server/src/creators/role-creator.js b/keyserver/src/creators/role-creator.js similarity index 100% rename from server/src/creators/role-creator.js rename to keyserver/src/creators/role-creator.js diff --git a/server/src/creators/session-creator.js b/keyserver/src/creators/session-creator.js similarity index 100% rename from server/src/creators/session-creator.js rename to keyserver/src/creators/session-creator.js diff --git a/server/src/creators/thread-creator.js b/keyserver/src/creators/thread-creator.js similarity index 100% rename from server/src/creators/thread-creator.js rename to keyserver/src/creators/thread-creator.js diff --git a/server/src/creators/update-creator.js b/keyserver/src/creators/update-creator.js similarity index 100% rename from server/src/creators/update-creator.js rename to keyserver/src/creators/update-creator.js diff --git a/server/src/creators/upload-creator.js b/keyserver/src/creators/upload-creator.js similarity index 100% rename from server/src/creators/upload-creator.js rename to keyserver/src/creators/upload-creator.js diff --git a/server/src/cron/backups.js b/keyserver/src/cron/backups.js similarity index 100% rename from server/src/cron/backups.js rename to keyserver/src/cron/backups.js diff --git a/server/src/cron/cron.js b/keyserver/src/cron/cron.js similarity index 100% rename from server/src/cron/cron.js rename to keyserver/src/cron/cron.js diff --git a/server/src/cron/update-geoip-db.js b/keyserver/src/cron/update-geoip-db.js similarity index 95% rename from server/src/cron/update-geoip-db.js rename to keyserver/src/cron/update-geoip-db.js index 125c38528..c261eafb1 100644 --- a/server/src/cron/update-geoip-db.js +++ b/keyserver/src/cron/update-geoip-db.js @@ -1,77 +1,77 @@ // @flow import childProcess from 'child_process'; import cluster from 'cluster'; import geoip from 'geoip-lite'; import { handleAsyncPromise } from '../responders/handlers'; let cachedGeoipLicense = undefined; async function getGeoipLicense() { if (cachedGeoipLicense !== undefined) { return cachedGeoipLicense; } try { // $FlowFixMe const geoipLicenseImport = await import('../../secrets/geoip_license'); if (cachedGeoipLicense === undefined) { cachedGeoipLicense = geoipLicenseImport.default; } } catch { if (cachedGeoipLicense === undefined) { cachedGeoipLicense = null; } } return cachedGeoipLicense; } async function updateGeoipDB(): Promise { const geoipLicense = await getGeoipLicense(); if (!geoipLicense) { - console.log('no server/secrets/geoip_license.json so skipping update'); + console.log('no keyserver/secrets/geoip_license.json so skipping update'); return; } await spawnUpdater(geoipLicense); } function spawnUpdater(geoipLicense: { key: string }): Promise { const spawned = childProcess.spawn(process.execPath, [ '../node_modules/geoip-lite/scripts/updatedb.js', `license_key=${geoipLicense.key}`, ]); return new Promise((resolve, reject) => { spawned.on('error', reject); spawned.on('exit', () => resolve()); }); } function reloadGeoipDB(): Promise { return new Promise(resolve => geoip.reloadData(resolve)); } type IPCMessage = { type: 'geoip_reload', }; const reloadMessage: IPCMessage = { type: 'geoip_reload' }; async function updateAndReloadGeoipDB(): Promise { await updateGeoipDB(); await reloadGeoipDB(); if (!cluster.isMaster) { return; } for (const id in cluster.workers) { cluster.workers[Number(id)].send(reloadMessage); } } if (!cluster.isMaster) { process.on('message', (ipcMessage: IPCMessage) => { if (ipcMessage.type === 'geoip_reload') { handleAsyncPromise(reloadGeoipDB()); } }); } export { updateGeoipDB, updateAndReloadGeoipDB }; diff --git a/server/src/database/consts.js b/keyserver/src/database/consts.js similarity index 100% rename from server/src/database/consts.js rename to keyserver/src/database/consts.js diff --git a/server/src/database/database.js b/keyserver/src/database/database.js similarity index 100% rename from server/src/database/database.js rename to keyserver/src/database/database.js diff --git a/server/src/database/migrations.js b/keyserver/src/database/migrations.js similarity index 100% rename from server/src/database/migrations.js rename to keyserver/src/database/migrations.js diff --git a/server/src/database/monitor.js b/keyserver/src/database/monitor.js similarity index 100% rename from server/src/database/monitor.js rename to keyserver/src/database/monitor.js diff --git a/server/src/database/types.js b/keyserver/src/database/types.js similarity index 100% rename from server/src/database/types.js rename to keyserver/src/database/types.js diff --git a/server/src/deleters/account-deleters.js b/keyserver/src/deleters/account-deleters.js similarity index 100% rename from server/src/deleters/account-deleters.js rename to keyserver/src/deleters/account-deleters.js diff --git a/server/src/deleters/activity-deleters.js b/keyserver/src/deleters/activity-deleters.js similarity index 100% rename from server/src/deleters/activity-deleters.js rename to keyserver/src/deleters/activity-deleters.js diff --git a/server/src/deleters/cookie-deleters.js b/keyserver/src/deleters/cookie-deleters.js similarity index 100% rename from server/src/deleters/cookie-deleters.js rename to keyserver/src/deleters/cookie-deleters.js diff --git a/server/src/deleters/day-deleters.js b/keyserver/src/deleters/day-deleters.js similarity index 100% rename from server/src/deleters/day-deleters.js rename to keyserver/src/deleters/day-deleters.js diff --git a/server/src/deleters/entry-deleters.js b/keyserver/src/deleters/entry-deleters.js similarity index 100% rename from server/src/deleters/entry-deleters.js rename to keyserver/src/deleters/entry-deleters.js diff --git a/server/src/deleters/membership-deleters.js b/keyserver/src/deleters/membership-deleters.js similarity index 100% rename from server/src/deleters/membership-deleters.js rename to keyserver/src/deleters/membership-deleters.js diff --git a/server/src/deleters/message-deleters.js b/keyserver/src/deleters/message-deleters.js similarity index 100% rename from server/src/deleters/message-deleters.js rename to keyserver/src/deleters/message-deleters.js diff --git a/server/src/deleters/notif-deleters.js b/keyserver/src/deleters/notif-deleters.js similarity index 100% rename from server/src/deleters/notif-deleters.js rename to keyserver/src/deleters/notif-deleters.js diff --git a/server/src/deleters/one-time-key-deleters.js b/keyserver/src/deleters/one-time-key-deleters.js similarity index 100% rename from server/src/deleters/one-time-key-deleters.js rename to keyserver/src/deleters/one-time-key-deleters.js diff --git a/server/src/deleters/revision-deleters.js b/keyserver/src/deleters/revision-deleters.js similarity index 100% rename from server/src/deleters/revision-deleters.js rename to keyserver/src/deleters/revision-deleters.js diff --git a/server/src/deleters/role-deleters.js b/keyserver/src/deleters/role-deleters.js similarity index 100% rename from server/src/deleters/role-deleters.js rename to keyserver/src/deleters/role-deleters.js diff --git a/server/src/deleters/session-deleters.js b/keyserver/src/deleters/session-deleters.js similarity index 100% rename from server/src/deleters/session-deleters.js rename to keyserver/src/deleters/session-deleters.js diff --git a/server/src/deleters/thread-deleters.js b/keyserver/src/deleters/thread-deleters.js similarity index 100% rename from server/src/deleters/thread-deleters.js rename to keyserver/src/deleters/thread-deleters.js diff --git a/server/src/deleters/update-deleters.js b/keyserver/src/deleters/update-deleters.js similarity index 100% rename from server/src/deleters/update-deleters.js rename to keyserver/src/deleters/update-deleters.js diff --git a/server/src/deleters/upload-deleters.js b/keyserver/src/deleters/upload-deleters.js similarity index 100% rename from server/src/deleters/upload-deleters.js rename to keyserver/src/deleters/upload-deleters.js diff --git a/server/src/emails/access-request.js b/keyserver/src/emails/access-request.js similarity index 100% rename from server/src/emails/access-request.js rename to keyserver/src/emails/access-request.js diff --git a/server/src/emails/sendmail.js b/keyserver/src/emails/sendmail.js similarity index 100% rename from server/src/emails/sendmail.js rename to keyserver/src/emails/sendmail.js diff --git a/server/src/emails/subscribe-email-updates.js b/keyserver/src/emails/subscribe-email-updates.js similarity index 100% rename from server/src/emails/subscribe-email-updates.js rename to keyserver/src/emails/subscribe-email-updates.js diff --git a/server/src/emails/template.react.js b/keyserver/src/emails/template.react.js similarity index 100% rename from server/src/emails/template.react.js rename to keyserver/src/emails/template.react.js diff --git a/server/src/endpoints.js b/keyserver/src/endpoints.js similarity index 100% rename from server/src/endpoints.js rename to keyserver/src/endpoints.js diff --git a/server/src/fetchers/entry-fetchers.js b/keyserver/src/fetchers/entry-fetchers.js similarity index 100% rename from server/src/fetchers/entry-fetchers.js rename to keyserver/src/fetchers/entry-fetchers.js diff --git a/server/src/fetchers/key-fetchers.js b/keyserver/src/fetchers/key-fetchers.js similarity index 100% rename from server/src/fetchers/key-fetchers.js rename to keyserver/src/fetchers/key-fetchers.js diff --git a/server/src/fetchers/message-fetchers.js b/keyserver/src/fetchers/message-fetchers.js similarity index 100% rename from server/src/fetchers/message-fetchers.js rename to keyserver/src/fetchers/message-fetchers.js diff --git a/server/src/fetchers/relationship-fetchers.js b/keyserver/src/fetchers/relationship-fetchers.js similarity index 100% rename from server/src/fetchers/relationship-fetchers.js rename to keyserver/src/fetchers/relationship-fetchers.js diff --git a/server/src/fetchers/report-fetchers.js b/keyserver/src/fetchers/report-fetchers.js similarity index 100% rename from server/src/fetchers/report-fetchers.js rename to keyserver/src/fetchers/report-fetchers.js diff --git a/server/src/fetchers/role-fetchers.js b/keyserver/src/fetchers/role-fetchers.js similarity index 100% rename from server/src/fetchers/role-fetchers.js rename to keyserver/src/fetchers/role-fetchers.js diff --git a/server/src/fetchers/session-fetchers.js b/keyserver/src/fetchers/session-fetchers.js similarity index 100% rename from server/src/fetchers/session-fetchers.js rename to keyserver/src/fetchers/session-fetchers.js diff --git a/server/src/fetchers/thread-fetchers.js b/keyserver/src/fetchers/thread-fetchers.js similarity index 100% rename from server/src/fetchers/thread-fetchers.js rename to keyserver/src/fetchers/thread-fetchers.js diff --git a/server/src/fetchers/thread-permission-fetchers.js b/keyserver/src/fetchers/thread-permission-fetchers.js similarity index 100% rename from server/src/fetchers/thread-permission-fetchers.js rename to keyserver/src/fetchers/thread-permission-fetchers.js diff --git a/server/src/fetchers/update-fetchers.js b/keyserver/src/fetchers/update-fetchers.js similarity index 100% rename from server/src/fetchers/update-fetchers.js rename to keyserver/src/fetchers/update-fetchers.js diff --git a/server/src/fetchers/upload-fetchers.js b/keyserver/src/fetchers/upload-fetchers.js similarity index 100% rename from server/src/fetchers/upload-fetchers.js rename to keyserver/src/fetchers/upload-fetchers.js diff --git a/server/src/fetchers/user-fetchers.js b/keyserver/src/fetchers/user-fetchers.js similarity index 100% rename from server/src/fetchers/user-fetchers.js rename to keyserver/src/fetchers/user-fetchers.js diff --git a/server/src/server.js b/keyserver/src/keyserver.js similarity index 100% rename from server/src/server.js rename to keyserver/src/keyserver.js diff --git a/server/src/landing b/keyserver/src/landing similarity index 100% rename from server/src/landing rename to keyserver/src/landing diff --git a/server/src/lib b/keyserver/src/lib similarity index 100% rename from server/src/lib rename to keyserver/src/lib diff --git a/server/src/push/providers.js b/keyserver/src/push/providers.js similarity index 100% rename from server/src/push/providers.js rename to keyserver/src/push/providers.js diff --git a/server/src/push/rescind.js b/keyserver/src/push/rescind.js similarity index 100% rename from server/src/push/rescind.js rename to keyserver/src/push/rescind.js diff --git a/server/src/push/send.js b/keyserver/src/push/send.js similarity index 100% rename from server/src/push/send.js rename to keyserver/src/push/send.js diff --git a/server/src/push/utils.js b/keyserver/src/push/utils.js similarity index 94% rename from server/src/push/utils.js rename to keyserver/src/push/utils.js index 638f2caa4..2f37ff5fe 100644 --- a/server/src/push/utils.js +++ b/keyserver/src/push/utils.js @@ -1,199 +1,199 @@ // @flow import apn from '@parse/node-apn'; import type { ResponseFailure } from '@parse/node-apn'; import type { FirebaseApp, FirebaseError } from 'firebase-admin'; import invariant from 'invariant'; import { threadSubscriptions } from 'lib/types/subscription-types'; import { threadPermissions } from 'lib/types/thread-types'; import { dbQuery, SQL } from '../database/database'; import { getAPNPushProfileForCodeVersion, getFCMPushProfileForCodeVersion, getAPNProvider, getFCMProvider, } from './providers'; const fcmTokenInvalidationErrors = new Set([ 'messaging/registration-token-not-registered', 'messaging/invalid-registration-token', ]); const apnTokenInvalidationErrorCode = 410; const apnBadRequestErrorCode = 400; const apnBadTokenErrorString = 'BadDeviceToken'; type APNPushResult = | { +success: true } | { +errors: $ReadOnlyArray, +invalidTokens?: $ReadOnlyArray, }; async function apnPush({ notification, deviceTokens, codeVersion, }: { +notification: apn.Notification, +deviceTokens: $ReadOnlyArray, +codeVersion: ?number, }): Promise { const pushProfile = getAPNPushProfileForCodeVersion(codeVersion); const apnProvider = await getAPNProvider(pushProfile); if (!apnProvider && process.env.NODE_ENV === 'development') { - console.log(`no server/secrets/${pushProfile}.json so ignoring notifs`); + console.log(`no keyserver/secrets/${pushProfile}.json so ignoring notifs`); return { success: true }; } - invariant(apnProvider, `server/secrets/${pushProfile}.json should exist`); + invariant(apnProvider, `keyserver/secrets/${pushProfile}.json should exist`); const result = await apnProvider.send(notification, deviceTokens); const errors = []; const invalidTokens = []; for (const error of result.failed) { errors.push(error); /* eslint-disable eqeqeq */ if ( error.status == apnTokenInvalidationErrorCode || (error.status == apnBadRequestErrorCode && error.response.reason === apnBadTokenErrorString) ) { invalidTokens.push(error.device); } /* eslint-enable eqeqeq */ } if (invalidTokens.length > 0) { return { errors, invalidTokens }; } else if (errors.length > 0) { return { errors }; } else { return { success: true }; } } type FCMPushResult = { +success?: true, +fcmIDs?: $ReadOnlyArray, +errors?: $ReadOnlyArray, +invalidTokens?: $ReadOnlyArray, }; async function fcmPush({ notification, deviceTokens, collapseKey, codeVersion, }: { +notification: Object, +deviceTokens: $ReadOnlyArray, +codeVersion: ?number, +collapseKey?: ?string, }): Promise { const pushProfile = getFCMPushProfileForCodeVersion(codeVersion); const fcmProvider = await getFCMProvider(pushProfile); if (!fcmProvider && process.env.NODE_ENV === 'development') { - console.log(`no server/secrets/${pushProfile}.json so ignoring notifs`); + console.log(`no keyserver/secrets/${pushProfile}.json so ignoring notifs`); return { success: true }; } - invariant(fcmProvider, `server/secrets/${pushProfile}.json should exist`); + invariant(fcmProvider, `keyserver/secrets/${pushProfile}.json should exist`); const options: Object = { priority: 'high', }; if (collapseKey) { options.collapseKey = collapseKey; } // firebase-admin is extremely barebones and has a lot of missing or poorly // thought-out functionality. One of the issues is that if you send a // multicast messages and one of the device tokens is invalid, the resultant // won't explain which of the device tokens is invalid. So we're forced to // avoid the multicast functionality and call it once per deviceToken. const promises = []; for (const deviceToken of deviceTokens) { promises.push( fcmSinglePush(fcmProvider, notification, deviceToken, options), ); } const pushResults = await Promise.all(promises); const errors = []; const ids = []; const invalidTokens = []; for (let i = 0; i < pushResults.length; i++) { const pushResult = pushResults[i]; for (const error of pushResult.errors) { errors.push(error); if (fcmTokenInvalidationErrors.has(error.errorInfo.code)) { invalidTokens.push(deviceTokens[i]); } } for (const id of pushResult.fcmIDs) { ids.push(id); } } const result = {}; if (ids.length > 0) { result.fcmIDs = ids; } if (errors.length > 0) { result.errors = errors; } else { result.success = true; } if (invalidTokens.length > 0) { result.invalidTokens = invalidTokens; } return { ...result }; } async function fcmSinglePush( provider: FirebaseApp, notification: Object, deviceToken: string, options: Object, ) { try { const deliveryResult = await provider .messaging() .sendToDevice(deviceToken, notification, options); const errors = []; const ids = []; for (const fcmResult of deliveryResult.results) { if (fcmResult.error) { errors.push(fcmResult.error); } else if (fcmResult.messageId) { ids.push(fcmResult.messageId); } } return { fcmIDs: ids, errors }; } catch (e) { return { fcmIDs: [], errors: [e] }; } } async function getUnreadCounts( userIDs: string[], ): Promise<{ [userID: string]: number }> { const visPermissionExtractString = `$.${threadPermissions.VISIBLE}.value`; const notificationExtractString = `$.${threadSubscriptions.home}`; const query = SQL` SELECT user, COUNT(thread) AS unread_count FROM memberships WHERE user IN (${userIDs}) AND last_message > last_read_message AND role > 0 AND JSON_EXTRACT(permissions, ${visPermissionExtractString}) AND JSON_EXTRACT(subscription, ${notificationExtractString}) GROUP BY user `; const [result] = await dbQuery(query); const usersToUnreadCounts = {}; for (const row of result) { usersToUnreadCounts[row.user.toString()] = row.unread_count; } for (const userID of userIDs) { if (usersToUnreadCounts[userID] === undefined) { usersToUnreadCounts[userID] = 0; } } return usersToUnreadCounts; } export { apnPush, fcmPush, getUnreadCounts }; diff --git a/server/src/responders/activity-responders.js b/keyserver/src/responders/activity-responders.js similarity index 100% rename from server/src/responders/activity-responders.js rename to keyserver/src/responders/activity-responders.js diff --git a/server/src/responders/comm-landing-responders.js b/keyserver/src/responders/comm-landing-responders.js similarity index 100% rename from server/src/responders/comm-landing-responders.js rename to keyserver/src/responders/comm-landing-responders.js diff --git a/server/src/responders/device-responders.js b/keyserver/src/responders/device-responders.js similarity index 100% rename from server/src/responders/device-responders.js rename to keyserver/src/responders/device-responders.js diff --git a/server/src/responders/entry-responders.js b/keyserver/src/responders/entry-responders.js similarity index 100% rename from server/src/responders/entry-responders.js rename to keyserver/src/responders/entry-responders.js diff --git a/server/src/responders/handlers.js b/keyserver/src/responders/handlers.js similarity index 100% rename from server/src/responders/handlers.js rename to keyserver/src/responders/handlers.js diff --git a/server/src/responders/keys-responders.js b/keyserver/src/responders/keys-responders.js similarity index 100% rename from server/src/responders/keys-responders.js rename to keyserver/src/responders/keys-responders.js diff --git a/server/src/responders/landing-handler.js b/keyserver/src/responders/landing-handler.js similarity index 100% rename from server/src/responders/landing-handler.js rename to keyserver/src/responders/landing-handler.js diff --git a/server/src/responders/message-responders.js b/keyserver/src/responders/message-responders.js similarity index 100% rename from server/src/responders/message-responders.js rename to keyserver/src/responders/message-responders.js diff --git a/server/src/responders/relationship-responders.js b/keyserver/src/responders/relationship-responders.js similarity index 100% rename from server/src/responders/relationship-responders.js rename to keyserver/src/responders/relationship-responders.js diff --git a/server/src/responders/report-responders.js b/keyserver/src/responders/report-responders.js similarity index 100% rename from server/src/responders/report-responders.js rename to keyserver/src/responders/report-responders.js diff --git a/server/src/responders/search-responders.js b/keyserver/src/responders/search-responders.js similarity index 100% rename from server/src/responders/search-responders.js rename to keyserver/src/responders/search-responders.js diff --git a/server/src/responders/thread-responders.js b/keyserver/src/responders/thread-responders.js similarity index 100% rename from server/src/responders/thread-responders.js rename to keyserver/src/responders/thread-responders.js diff --git a/server/src/responders/thread-responders.test.js b/keyserver/src/responders/thread-responders.test.js similarity index 100% rename from server/src/responders/thread-responders.test.js rename to keyserver/src/responders/thread-responders.test.js diff --git a/server/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js similarity index 100% rename from server/src/responders/user-responders.js rename to keyserver/src/responders/user-responders.js diff --git a/server/src/responders/utils.js b/keyserver/src/responders/utils.js similarity index 100% rename from server/src/responders/utils.js rename to keyserver/src/responders/utils.js diff --git a/server/src/responders/verification-responders.js b/keyserver/src/responders/verification-responders.js similarity index 100% rename from server/src/responders/verification-responders.js rename to keyserver/src/responders/verification-responders.js diff --git a/server/src/responders/version-responders.js b/keyserver/src/responders/version-responders.js similarity index 100% rename from server/src/responders/version-responders.js rename to keyserver/src/responders/version-responders.js diff --git a/server/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js similarity index 100% rename from server/src/responders/website-responders.js rename to keyserver/src/responders/website-responders.js diff --git a/server/src/scripts/add-edit-thread-detailed-permissions.js b/keyserver/src/scripts/add-edit-thread-detailed-permissions.js similarity index 100% rename from server/src/scripts/add-edit-thread-detailed-permissions.js rename to keyserver/src/scripts/add-edit-thread-detailed-permissions.js diff --git a/server/src/scripts/add-indexes-for-account-deletion.js b/keyserver/src/scripts/add-indexes-for-account-deletion.js similarity index 100% rename from server/src/scripts/add-indexes-for-account-deletion.js rename to keyserver/src/scripts/add-indexes-for-account-deletion.js diff --git a/server/src/scripts/add-key-column-for-sessions.js b/keyserver/src/scripts/add-key-column-for-sessions.js similarity index 100% rename from server/src/scripts/add-key-column-for-sessions.js rename to keyserver/src/scripts/add-key-column-for-sessions.js diff --git a/server/src/scripts/add-key-column-for-users.js b/keyserver/src/scripts/add-key-column-for-users.js similarity index 100% rename from server/src/scripts/add-key-column-for-users.js rename to keyserver/src/scripts/add-key-column-for-users.js diff --git a/server/src/scripts/add-leave-thread-permissions.js b/keyserver/src/scripts/add-leave-thread-permissions.js similarity index 100% rename from server/src/scripts/add-leave-thread-permissions.js rename to keyserver/src/scripts/add-leave-thread-permissions.js diff --git a/server/src/scripts/add-primary-column-for-cookies.js b/keyserver/src/scripts/add-primary-column-for-cookies.js similarity index 100% rename from server/src/scripts/add-primary-column-for-cookies.js rename to keyserver/src/scripts/add-primary-column-for-cookies.js diff --git a/server/src/scripts/add-source-message-column.js b/keyserver/src/scripts/add-source-message-column.js similarity index 100% rename from server/src/scripts/add-source-message-column.js rename to keyserver/src/scripts/add-source-message-column.js diff --git a/server/src/scripts/add-staff.js b/keyserver/src/scripts/add-staff.js similarity index 100% rename from server/src/scripts/add-staff.js rename to keyserver/src/scripts/add-staff.js diff --git a/server/src/scripts/add-target-time-index-to-updates-table.js b/keyserver/src/scripts/add-target-time-index-to-updates-table.js similarity index 100% rename from server/src/scripts/add-target-time-index-to-updates-table.js rename to keyserver/src/scripts/add-target-time-index-to-updates-table.js diff --git a/server/src/scripts/add-thread-ancestry.js b/keyserver/src/scripts/add-thread-ancestry.js similarity index 100% rename from server/src/scripts/add-thread-ancestry.js rename to keyserver/src/scripts/add-thread-ancestry.js diff --git a/server/src/scripts/create-db.js b/keyserver/src/scripts/create-db.js similarity index 100% rename from server/src/scripts/create-db.js rename to keyserver/src/scripts/create-db.js diff --git a/server/src/scripts/create-friend-relationships.js b/keyserver/src/scripts/create-friend-relationships.js similarity index 100% rename from server/src/scripts/create-friend-relationships.js rename to keyserver/src/scripts/create-friend-relationships.js diff --git a/server/src/scripts/create-metadata-table.js b/keyserver/src/scripts/create-metadata-table.js similarity index 100% rename from server/src/scripts/create-metadata-table.js rename to keyserver/src/scripts/create-metadata-table.js diff --git a/server/src/scripts/create-one-time-keys-table.js b/keyserver/src/scripts/create-one-time-keys-table.js similarity index 100% rename from server/src/scripts/create-one-time-keys-table.js rename to keyserver/src/scripts/create-one-time-keys-table.js diff --git a/server/src/scripts/create-one-time-settings-table.js b/keyserver/src/scripts/create-one-time-settings-table.js similarity index 100% rename from server/src/scripts/create-one-time-settings-table.js rename to keyserver/src/scripts/create-one-time-settings-table.js diff --git a/server/src/scripts/create-relationships.js b/keyserver/src/scripts/create-relationships.js similarity index 100% rename from server/src/scripts/create-relationships.js rename to keyserver/src/scripts/create-relationships.js diff --git a/server/src/scripts/create-sidebar-permissions.js b/keyserver/src/scripts/create-sidebar-permissions.js similarity index 100% rename from server/src/scripts/create-sidebar-permissions.js rename to keyserver/src/scripts/create-sidebar-permissions.js diff --git a/server/src/scripts/create-user-messages-table.js b/keyserver/src/scripts/create-user-messages-table.js similarity index 100% rename from server/src/scripts/create-user-messages-table.js rename to keyserver/src/scripts/create-user-messages-table.js diff --git a/server/src/scripts/delete-emails.js b/keyserver/src/scripts/delete-emails.js similarity index 100% rename from server/src/scripts/delete-emails.js rename to keyserver/src/scripts/delete-emails.js diff --git a/server/src/scripts/delete-memberships-of-deleted-users.js b/keyserver/src/scripts/delete-memberships-of-deleted-users.js similarity index 100% rename from server/src/scripts/delete-memberships-of-deleted-users.js rename to keyserver/src/scripts/delete-memberships-of-deleted-users.js diff --git a/server/src/scripts/delete-unread-column.js b/keyserver/src/scripts/delete-unread-column.js similarity index 100% rename from server/src/scripts/delete-unread-column.js rename to keyserver/src/scripts/delete-unread-column.js diff --git a/server/src/scripts/fix-new-thread-types.js b/keyserver/src/scripts/fix-new-thread-types.js similarity index 100% rename from server/src/scripts/fix-new-thread-types.js rename to keyserver/src/scripts/fix-new-thread-types.js diff --git a/server/src/scripts/generate-olm-config.js b/keyserver/src/scripts/generate-olm-config.js similarity index 82% rename from server/src/scripts/generate-olm-config.js rename to keyserver/src/scripts/generate-olm-config.js index 79bfabc8e..a1b1f3540 100644 --- a/server/src/scripts/generate-olm-config.js +++ b/keyserver/src/scripts/generate-olm-config.js @@ -1,37 +1,39 @@ // @flow import olm from '@matrix-org/olm'; import fs from 'fs'; import path from 'path'; import uuid from 'uuid'; import { main } from './utils'; const olmConfigRelativePath = './secrets/olm_config.json'; async function generateOlmConfig() { await olm.init(); const account = new olm.Account(); account.create(); const picklingKey = uuid.v4(); const pickledAccount = account.pickle(picklingKey); const olmConfig = { picklingKey: picklingKey, pickledAccount: pickledAccount, }; const scriptWorkingDirectory = path.resolve(); - if (!scriptWorkingDirectory.endsWith('comm/server')) { - throw new Error('Script must be run in server directory in comm project.'); + if (!scriptWorkingDirectory.endsWith('comm/keyserver')) { + throw new Error( + 'Script must be run in keyserver directory in comm project.', + ); } const olmConfigFilePath = path.join( scriptWorkingDirectory, olmConfigRelativePath, ); fs.writeFileSync(olmConfigFilePath, JSON.stringify(olmConfig)); } main([generateOlmConfig]); diff --git a/server/src/scripts/image-size.js b/keyserver/src/scripts/image-size.js similarity index 100% rename from server/src/scripts/image-size.js rename to keyserver/src/scripts/image-size.js diff --git a/server/src/scripts/make-notif-columns-optional.js b/keyserver/src/scripts/make-notif-columns-optional.js similarity index 100% rename from server/src/scripts/make-notif-columns-optional.js rename to keyserver/src/scripts/make-notif-columns-optional.js diff --git a/server/src/scripts/make-source-message-unique.js b/keyserver/src/scripts/make-source-message-unique.js similarity index 100% rename from server/src/scripts/make-source-message-unique.js rename to keyserver/src/scripts/make-source-message-unique.js diff --git a/server/src/scripts/merge-users.js b/keyserver/src/scripts/merge-users.js similarity index 100% rename from server/src/scripts/merge-users.js rename to keyserver/src/scripts/merge-users.js diff --git a/server/src/scripts/rename-sidebar-message-fields.js b/keyserver/src/scripts/rename-sidebar-message-fields.js similarity index 100% rename from server/src/scripts/rename-sidebar-message-fields.js rename to keyserver/src/scripts/rename-sidebar-message-fields.js diff --git a/server/src/scripts/rename-user-column-for-one-time-keys.js b/keyserver/src/scripts/rename-user-column-for-one-time-keys.js similarity index 100% rename from server/src/scripts/rename-user-column-for-one-time-keys.js rename to keyserver/src/scripts/rename-user-column-for-one-time-keys.js diff --git a/server/src/scripts/rename-user.js b/keyserver/src/scripts/rename-user.js similarity index 100% rename from server/src/scripts/rename-user.js rename to keyserver/src/scripts/rename-user.js diff --git a/server/src/scripts/rescind-notifs.js b/keyserver/src/scripts/rescind-notifs.js similarity index 100% rename from server/src/scripts/rescind-notifs.js rename to keyserver/src/scripts/rescind-notifs.js diff --git a/server/src/scripts/reset-password.js b/keyserver/src/scripts/reset-password.js similarity index 100% rename from server/src/scripts/reset-password.js rename to keyserver/src/scripts/reset-password.js diff --git a/server/src/scripts/script-context.js b/keyserver/src/scripts/script-context.js similarity index 100% rename from server/src/scripts/script-context.js rename to keyserver/src/scripts/script-context.js diff --git a/server/src/scripts/set-last-read-messages.js b/keyserver/src/scripts/set-last-read-messages.js similarity index 100% rename from server/src/scripts/set-last-read-messages.js rename to keyserver/src/scripts/set-last-read-messages.js diff --git a/server/src/scripts/setup-sidebars.js b/keyserver/src/scripts/setup-sidebars.js similarity index 100% rename from server/src/scripts/setup-sidebars.js rename to keyserver/src/scripts/setup-sidebars.js diff --git a/server/src/scripts/sidebar-know-of-migration.js b/keyserver/src/scripts/sidebar-know-of-migration.js similarity index 100% rename from server/src/scripts/sidebar-know-of-migration.js rename to keyserver/src/scripts/sidebar-know-of-migration.js diff --git a/server/src/scripts/soft-launch-migration.js b/keyserver/src/scripts/soft-launch-migration.js similarity index 100% rename from server/src/scripts/soft-launch-migration.js rename to keyserver/src/scripts/soft-launch-migration.js diff --git a/server/src/scripts/update-geoip.js b/keyserver/src/scripts/update-geoip.js similarity index 100% rename from server/src/scripts/update-geoip.js rename to keyserver/src/scripts/update-geoip.js diff --git a/server/src/scripts/utils.js b/keyserver/src/scripts/utils.js similarity index 100% rename from server/src/scripts/utils.js rename to keyserver/src/scripts/utils.js diff --git a/server/src/search/users.js b/keyserver/src/search/users.js similarity index 100% rename from server/src/search/users.js rename to keyserver/src/search/users.js diff --git a/server/src/session/bots.js b/keyserver/src/session/bots.js similarity index 100% rename from server/src/session/bots.js rename to keyserver/src/session/bots.js diff --git a/server/src/session/cookies.js b/keyserver/src/session/cookies.js similarity index 100% rename from server/src/session/cookies.js rename to keyserver/src/session/cookies.js diff --git a/server/src/session/scripts.js b/keyserver/src/session/scripts.js similarity index 100% rename from server/src/session/scripts.js rename to keyserver/src/session/scripts.js diff --git a/server/src/session/version.js b/keyserver/src/session/version.js similarity index 100% rename from server/src/session/version.js rename to keyserver/src/session/version.js diff --git a/server/src/session/viewer.js b/keyserver/src/session/viewer.js similarity index 100% rename from server/src/session/viewer.js rename to keyserver/src/session/viewer.js diff --git a/server/src/shared/focused-times.js b/keyserver/src/shared/focused-times.js similarity index 100% rename from server/src/shared/focused-times.js rename to keyserver/src/shared/focused-times.js diff --git a/server/src/socket/redis.js b/keyserver/src/socket/redis.js similarity index 100% rename from server/src/socket/redis.js rename to keyserver/src/socket/redis.js diff --git a/server/src/socket/session-utils.js b/keyserver/src/socket/session-utils.js similarity index 100% rename from server/src/socket/session-utils.js rename to keyserver/src/socket/session-utils.js diff --git a/server/src/socket/socket.js b/keyserver/src/socket/socket.js similarity index 100% rename from server/src/socket/socket.js rename to keyserver/src/socket/socket.js diff --git a/server/src/updaters/account-updaters.js b/keyserver/src/updaters/account-updaters.js similarity index 100% rename from server/src/updaters/account-updaters.js rename to keyserver/src/updaters/account-updaters.js diff --git a/server/src/updaters/activity-updaters.js b/keyserver/src/updaters/activity-updaters.js similarity index 100% rename from server/src/updaters/activity-updaters.js rename to keyserver/src/updaters/activity-updaters.js diff --git a/server/src/updaters/device-token-updaters.js b/keyserver/src/updaters/device-token-updaters.js similarity index 100% rename from server/src/updaters/device-token-updaters.js rename to keyserver/src/updaters/device-token-updaters.js diff --git a/server/src/updaters/entry-updaters.js b/keyserver/src/updaters/entry-updaters.js similarity index 100% rename from server/src/updaters/entry-updaters.js rename to keyserver/src/updaters/entry-updaters.js diff --git a/server/src/updaters/relationship-updaters.js b/keyserver/src/updaters/relationship-updaters.js similarity index 100% rename from server/src/updaters/relationship-updaters.js rename to keyserver/src/updaters/relationship-updaters.js diff --git a/server/src/updaters/role-updaters.js b/keyserver/src/updaters/role-updaters.js similarity index 100% rename from server/src/updaters/role-updaters.js rename to keyserver/src/updaters/role-updaters.js diff --git a/server/src/updaters/session-updaters.js b/keyserver/src/updaters/session-updaters.js similarity index 100% rename from server/src/updaters/session-updaters.js rename to keyserver/src/updaters/session-updaters.js diff --git a/server/src/updaters/thread-permission-updaters.js b/keyserver/src/updaters/thread-permission-updaters.js similarity index 100% rename from server/src/updaters/thread-permission-updaters.js rename to keyserver/src/updaters/thread-permission-updaters.js diff --git a/server/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js similarity index 100% rename from server/src/updaters/thread-updaters.js rename to keyserver/src/updaters/thread-updaters.js diff --git a/server/src/updaters/upload-updaters.js b/keyserver/src/updaters/upload-updaters.js similarity index 100% rename from server/src/updaters/upload-updaters.js rename to keyserver/src/updaters/upload-updaters.js diff --git a/server/src/updaters/user-subscription-updaters.js b/keyserver/src/updaters/user-subscription-updaters.js similarity index 100% rename from server/src/updaters/user-subscription-updaters.js rename to keyserver/src/updaters/user-subscription-updaters.js diff --git a/server/src/uploads/media-utils.js b/keyserver/src/uploads/media-utils.js similarity index 100% rename from server/src/uploads/media-utils.js rename to keyserver/src/uploads/media-utils.js diff --git a/server/src/uploads/uploads.js b/keyserver/src/uploads/uploads.js similarity index 100% rename from server/src/uploads/uploads.js rename to keyserver/src/uploads/uploads.js diff --git a/server/src/utils/depth-queue.js b/keyserver/src/utils/depth-queue.js similarity index 100% rename from server/src/utils/depth-queue.js rename to keyserver/src/utils/depth-queue.js diff --git a/server/src/utils/idempotent.js b/keyserver/src/utils/idempotent.js similarity index 100% rename from server/src/utils/idempotent.js rename to keyserver/src/utils/idempotent.js diff --git a/server/src/utils/json-stream.js b/keyserver/src/utils/json-stream.js similarity index 100% rename from server/src/utils/json-stream.js rename to keyserver/src/utils/json-stream.js diff --git a/server/src/utils/olm-utils.js b/keyserver/src/utils/olm-utils.js similarity index 100% rename from server/src/utils/olm-utils.js rename to keyserver/src/utils/olm-utils.js diff --git a/server/src/utils/relationship-changeset.js b/keyserver/src/utils/relationship-changeset.js similarity index 100% rename from server/src/utils/relationship-changeset.js rename to keyserver/src/utils/relationship-changeset.js diff --git a/server/src/utils/security-utils.js b/keyserver/src/utils/security-utils.js similarity index 100% rename from server/src/utils/security-utils.js rename to keyserver/src/utils/security-utils.js diff --git a/server/src/utils/urls.js b/keyserver/src/utils/urls.js similarity index 100% rename from server/src/utils/urls.js rename to keyserver/src/utils/urls.js diff --git a/server/src/utils/validation-utils.js b/keyserver/src/utils/validation-utils.js similarity index 100% rename from server/src/utils/validation-utils.js rename to keyserver/src/utils/validation-utils.js diff --git a/server/src/web b/keyserver/src/web similarity index 100% rename from server/src/web rename to keyserver/src/web diff --git a/landing/webpack.config.cjs b/landing/webpack.config.cjs index 850bb577a..a377e7aeb 100644 --- a/landing/webpack.config.cjs +++ b/landing/webpack.config.cjs @@ -1,79 +1,79 @@ const path = require('path'); const AssetsPlugin = require('assets-webpack-plugin'); const babelConfig = require('./babel.config.cjs'); const { createProdBrowserConfig, createDevBrowserConfig, createNodeServerRenderingConfig, } = require('lib/webpack/shared.cjs'); const baseBrowserConfig = { entry: { browser: ['./script.js'], }, output: { filename: 'prod.[hash:12].build.js', path: path.join(__dirname, 'dist'), }, resolve: { alias: { - '../images': path.resolve('../server/images'), + '../images': path.resolve('../keyserver/images'), }, }, }; const baseDevBrowserConfig = { ...baseBrowserConfig, output: { ...baseBrowserConfig.output, filename: 'dev.build.js', pathinfo: true, publicPath: 'http://localhost:8082/', }, devServer: { hot: true, port: 8082, contentBase: path.join(__dirname, 'dist'), headers: { 'Access-Control-Allow-Origin': '*' }, }, }; const baseProdBrowserConfig = { ...baseBrowserConfig, plugins: [ new AssetsPlugin({ filename: 'assets.json', path: path.join(__dirname, 'dist'), }), ], }; const baseNodeServerRenderingConfig = { externals: ['react', 'react-dom', 'react-redux'], entry: { server: ['./landing-ssr.react.js'], }, output: { filename: 'landing.build.cjs', library: 'landing', libraryTarget: 'commonjs2', path: path.join(__dirname, 'dist'), }, }; module.exports = function (env) { const browserConfig = env === 'prod' ? createProdBrowserConfig(baseProdBrowserConfig, babelConfig) : createDevBrowserConfig(baseDevBrowserConfig, babelConfig); const nodeConfig = createNodeServerRenderingConfig( baseNodeServerRenderingConfig, babelConfig, ); const nodeServerRenderingConfig = { ...nodeConfig, mode: env === 'prod' ? 'production' : 'development', }; return [browserConfig, nodeServerRenderingConfig]; }; diff --git a/native/.flowconfig b/native/.flowconfig index e17943f2f..135088a2a 100644 --- a/native/.flowconfig +++ b/native/.flowconfig @@ -1,76 +1,76 @@ [ignore] ; We fork some components by platform .*/*[.]android.js .*/node_modules/redux-persist/lib/index.js .*/node_modules/react-native-fast-image/src/index.js.flow .*/node_modules/react-native-fs/FS.common.js .*/node_modules/react-native-gesture-handler/Swipeable.js ; Flow doesn't support platforms .*/Libraries/Utilities/LoadingView.js .*/comm/web/.* -.*/comm/server/.* +.*/comm/keyserver/.* .*/android/app/build/.* [untyped] .*/node_modules/@react-native-community/cli/.*/.* [declarations] .*/node_modules/react-native-camera/* .*/node_modules/react-native-firebase/* [include] ../node_modules ../lib [libs] ../node_modules/react-native/interface.js ../node_modules/react-native/flow/ ../lib/flow-typed/ [options] emoji=true exact_by_default=true format.bracket_spacing=false module.file_ext=.js module.file_ext=.json module.file_ext=.ios.js munge_underscores=true module.name_mapper='^react-native/\(.*\)$' -> '/../node_modules/react-native/\1' module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' suppress_type=$FlowIssue suppress_type=$FlowFixMe suppress_type=$FlowFixMeProps suppress_type=$FlowFixMeState [lints] sketchy-null-number=warn sketchy-null-mixed=warn sketchy-number=warn untyped-type-import=warn nonstrict-import=warn deprecated-type=warn unsafe-getters-setters=warn unnecessary-invariant=warn signature-verification-failure=warn [strict] deprecated-type nonstrict-import sketchy-null unclear-type unsafe-getters-setters untyped-import untyped-type-import [version] ^0.158.0 diff --git a/package.json b/package.json index 7156b963a..c5a380ec6 100644 --- a/package.json +++ b/package.json @@ -1,37 +1,37 @@ { "private": true, "license": "BSD-3-Clause", "workspaces": [ "lib", "web", "native", - "server", + "keyserver", "landing" ], "scripts": { - "clean": "yarn workspace lib clean && yarn workspace web clean && yarn workspace native clean && yarn workspace server clean && yarn workspace landing clean && rm -rf node_modules/", + "clean": "yarn workspace lib clean && yarn workspace web clean && yarn workspace native clean && yarn workspace keyserver clean && yarn workspace landing clean && rm -rf node_modules/", "cleaninstall": "yarn clean && yarn", "eslint": "eslint .", "eslint:fix": "eslint --fix .", "clang-format-all": "eval `node scripts/get_clang_paths_cli.js` | xargs clang-format -i", "prepare": "husky install" }, "devDependencies": { "babel-eslint": "^10.1.0", "clang-format": "^1.5.0", "core-js": "^3.6.5", "eslint": "^7.22.0", "eslint-config-prettier": "^8.1.0", "eslint-plugin-flowtype": "^5.4.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-jest": "^24.2.2", "eslint-plugin-monorepo": "^0.3.2", "eslint-plugin-prettier": "^3.3.1", "eslint-plugin-react": "^7.22.0", "eslint-plugin-react-hooks": "^4.2.0", "eslint-plugin-react-native": "^3.10.0", "husky": "^7.0.0", "lint-staged": "^12.1.4", "prettier": "^2.1.2" } } diff --git a/web/webpack.config.cjs b/web/webpack.config.cjs index dfaf1d43a..06559de0f 100644 --- a/web/webpack.config.cjs +++ b/web/webpack.config.cjs @@ -1,79 +1,79 @@ const path = require('path'); const AssetsPlugin = require('assets-webpack-plugin'); const babelConfig = require('./babel.config.cjs'); const { createProdBrowserConfig, createDevBrowserConfig, createNodeServerRenderingConfig, } = require('lib/webpack/shared.cjs'); const baseBrowserConfig = { entry: { browser: ['./script.js'], }, output: { filename: 'prod.[hash:12].build.js', path: path.join(__dirname, 'dist'), }, resolve: { alias: { - '../images': path.resolve('../server/images'), + '../images': path.resolve('../keyserver/images'), }, }, }; const baseDevBrowserConfig = { ...baseBrowserConfig, output: { ...baseBrowserConfig.output, filename: 'dev.build.js', pathinfo: true, publicPath: 'http://localhost:8080/', }, devServer: { hot: true, port: 8080, contentBase: path.join(__dirname, 'dist'), headers: { 'Access-Control-Allow-Origin': '*' }, }, }; const baseProdBrowserConfig = { ...baseBrowserConfig, plugins: [ new AssetsPlugin({ filename: 'assets.json', path: path.join(__dirname, 'dist'), }), ], }; const baseNodeServerRenderingConfig = { externals: ['react', 'react-dom', 'react-redux'], entry: { - server: ['./app.react.js'], + keyserver: ['./app.react.js'], }, output: { filename: 'app.build.cjs', library: 'app', libraryTarget: 'commonjs2', path: path.join(__dirname, 'dist'), }, }; module.exports = function (env) { const browserConfig = env === 'prod' ? createProdBrowserConfig(baseProdBrowserConfig, babelConfig) : createDevBrowserConfig(baseDevBrowserConfig, babelConfig); const nodeConfig = createNodeServerRenderingConfig( baseNodeServerRenderingConfig, babelConfig, ); const nodeServerRenderingConfig = { ...nodeConfig, mode: env === 'prod' ? 'production' : 'development', }; return [browserConfig, nodeServerRenderingConfig]; };