Skip to content

Commit

Permalink
feat: add connect relay server
Browse files Browse the repository at this point in the history
  • Loading branch information
horsefacts committed Dec 6, 2023
0 parents commit d262479
Show file tree
Hide file tree
Showing 36 changed files with 7,603 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**/node_modules/
**/.git
**/README.md
**/LICENSE
**/.vscode
**/npm-debug.log
**/coverage
**/.env
**/.editorconfig
**/.aws
**/.github
**/build
**/.husky
**/dist
**/Dockerfile*
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**What is the bug?**
A concise, high level description of the bug and how it affects you

**How can it be reproduced? (optional)**
Include steps, code samples, replits, screenshots and anything else that would be helpful to reproduce the problem.

**Additional context (optional)**
Add any other context about the problem here.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Feature
about: "Opening new feature requests "
title: "feat: "
labels: ""
assignees: ""
---

**What is the feature you would like to implement?**
A concise, high level summary of the feature

**Why is this feature important?**
An argument for why this feature should be build and how it should be prioritized

**How should this feature be built? (optional)**
A design for the implementation of the feature

**Additional context**
Add any other context or screenshots about the feature request here.
21 changes: 21 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Motivation

Describe why this issue should be fixed and link to any relevant design docs, issues or other relevant items.

## Change Summary

Describe the changes being made in 1-2 concise sentences.

## Merge Checklist

_Choose all relevant options below by adding an `x` now or at any time before submitting for review_

- [ ] PR title adheres to the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) standard
- [ ] PR has a changeset
- [ ] PR has been tagged with a change label(s) (i.e. documentation, feature, bugfix, or chore)
- [ ] PR includes documentation if necessary
- [ ] All commits have been signed

## Additional Context

If this is a relatively large or complex change, provide more details here that will help reviewers
79 changes: 79 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CI
on:
# CI is run on main because new branches can only access caches from master, not previous branches.
# So building on master allows new PR's to get the cache from before.
push:
branches: [main]
pull_request:
branches: [main]

# prevent multiple simultaneous test runs
concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true

jobs:
analyze:
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: "20"

- name: Restore cached dependencies for Node modules.
id: module-cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}--node--${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install

- name: Run build
run: yarn build

- name: Run linter
run: yarn lint:ci

test:
timeout-minutes: 10
runs-on: "buildjet-4vcpu-ubuntu-2204"

strategy:
matrix:
node_version: [18, 20]

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}

- name: Restore cached dependencies for Node modules.
id: module-cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}--node--${{ matrix.node_version}}--${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install

- name: Run build
run: yarn build

- name: Start background services
shell: bash
run: docker compose -f ./apps/relay/docker-compose.yml up --build --detach redis

- name: Run tests
run: yarn test:ci

- name: Upload coverage results
uses: codecov/codecov-action@v3
21 changes: 21 additions & 0 deletions .github/workflows/label_issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Label Issues

on:
issues:
types: [opened]

jobs:
label_issues:
runs-on: ubuntu-latest
steps:
- name: Add label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['s-triage']
})
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Logs
yarn-debug.log*
yarn-error.log*

.DS_Store
**/.DS_Store

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
build
.history
.hub_history

# Dependency directories
node_modules/

# TypeScript cache
*.tsbuildinfo

# Environment variables
.env

.eslintcache
depot.json

.console-history

# Code Coverage Reports
coverage/

# Turborepo
.turbo
out

dist

# Editor Cache
.vscode
.idea
.fleet
**/.vitepress/cache/
**/.vitepress/dist/
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry: https://registry.npmjs.org/
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2020-2023 Merkle Manufactory and others

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Farcaster Connect Monorepo

This monorepo contains packages and applications related to [Farcaster Connect](https://www.notion.so/warpcast/Farcaster-Connect-Public-9b3e9fb7a4b74f158369796f3e77c1d3).

## Packages

| Package Name | Description |
| ----------------------------------------- | ------------------------------ |
| [@farcaster/connect-relay](./apps/hubble) | Farcaster Connect relay server |
1 change: 1 addition & 0 deletions apps/relay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
21 changes: 21 additions & 0 deletions apps/relay/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "../../node_modules/@biomejs/biome/configuration_schema.json",
"organizeImports": {
"enabled": false
},
"formatter": {
"enabled": true,
"indentSize": 2,
"indentStyle": "space",
"lineWidth": 120
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"useLiteralKeys": "off"
}
}
}
}
20 changes: 20 additions & 0 deletions apps/relay/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.9"

services:
redis:
image: "redis:7.2-alpine"
restart: unless-stopped
command: --save 1 1 --loglevel warning --maxmemory-policy noeviction
volumes:
- redis-data:/data
ports:
- "6379:6379"
healthcheck:
test: ["CMD-SHELL", "redis-cli", "ping"]
interval: 10s
timeout: 10s
retries: 3
start_period: 5s

volumes:
redis-data:
10 changes: 10 additions & 0 deletions apps/relay/fastify.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FastifyRequest as DefaultFastifyRequest } from "fastify";
import { RelaySession } from "./src/handlers";
import { ChannelStore } from "./src/channels";

declare module "fastify" {
export interface FastifyRequest extends DefaultFastifyRequest {
channelToken: string;
channels: ChannelStore<RelaySession>;
}
}
21 changes: 21 additions & 0 deletions apps/relay/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Config } from "jest";

const jestConfig: Config = {
testEnvironment: "node",
coveragePathIgnorePatterns: ["<rootDir>/build/", "<rootDir>/node_modules/"],
testPathIgnorePatterns: ["<rootDir>/build", "<rootDir>/node_modules"],
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
/**
* For high performance with minimal configuration transform with TS with swc.
* @see https://github.com/farcasterxyz/hub/issues/314
*/
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
maxWorkers: "50%",
};

export default jestConfig;
32 changes: 32 additions & 0 deletions apps/relay/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@farcaster/connect-relay",
"version": "0.0.1",
"description": "Farcaster Connect relay server",
"private": true,
"type": "commonjs",
"scripts": {
"build": "tsc --project ./tsconfig.json",
"lint": "biome format src/ --write && biome check src/ --apply",
"lint:ci": "biome ci src/",
"test": "yarn build && jest",
"test:ci": "yarn build && ENVIRONMENT=test NODE_OPTIONS=\"--experimental-vm-modules --max-old-space-size=4096\" jest --ci --forceExit --coverage",
"start": "yarn build && node build/app.js start"
},
"engines": {
"node": ">=18"
},
"dependencies": {
"@farcaster/hub-nodejs": "^0.10.19",
"@fastify/cors": "^8.4.2",
"dotenv": "^16.3.1",
"ethers": "^6.9.0",
"fastify": "^4.24.3",
"ioredis": "^5.3.2",
"neverthrow": "^6.1.0",
"siwe": "^2.1.4"
},
"devDependencies": {
"axios": "^1.6.2",
"jest": "^29.7.0"
}
}
Loading

0 comments on commit d262479

Please sign in to comment.