Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

feat(proxy): demo warp based REST API endpoints #250

Closed
wants to merge 81 commits into from
Closed
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
fd37997
Bump proxy dependencies
xla Mar 19, 2020
633ba40
Attempt first end-to-end draft
xla Mar 19, 2020
aa843ef
Move serialisation to http module
xla Mar 20, 2020
20f9943
Merge branch 'master' into xla/220-warp-implementation
xla Mar 21, 2020
7b45e45
Explore json response assertions
xla Mar 22, 2020
a195ce7
Pass state
xla Mar 22, 2020
ef919df
Add docs
xla Mar 22, 2020
da71cc0
Move project endpoints into own module
xla Mar 23, 2020
695b7c9
Flesh out error responses
xla Mar 24, 2020
b9ffe18
Clean up
xla Mar 24, 2020
1f78617
Show case create endpoint
xla Mar 24, 2020
ac73fe1
Implement project registration
xla Mar 24, 2020
dcad433
Merge branch 'master' into xla/220-warp-implementation
xla Mar 25, 2020
2546e50
Test register
xla Mar 25, 2020
41ec0fa
Implement list endpoint
xla Mar 25, 2020
b7e9d0d
Simplify test assertions
xla Mar 25, 2020
ee5fccf
Fix reference
xla Mar 25, 2020
7a02e2f
Merge branch 'master' into xla/220-warp-implementation
xla Mar 25, 2020
87ab5a7
Use String in error fields
xla Mar 25, 2020
02c8c22
Remove explicit path end
xla Mar 25, 2020
dc6a174
Strings are strings are stirngs
xla Mar 25, 2020
76b1737
Use stronger Url type in the core
xla Mar 26, 2020
e4f9a4c
Merge branch 'master' into xla/220-warp-implementation
xla Mar 26, 2020
b947b6a
Wire the api in main
xla Mar 26, 2020
c754fbf
Use 8080
xla Mar 26, 2020
6e21def
Implement notification endpoint
xla Mar 29, 2020
e0a14a8
Wire up some rudimental logging
xla Mar 30, 2020
6bc54c5
chore: document REST API
garbados Mar 31, 2020
db653de
Explore mildly how ts state management could look like
xla Mar 31, 2020
0b84ddb
Merge branch 'master' into xla/220-warp-implementation
xla Apr 1, 2020
1f398bb
Merge branch 'xla/220-warp-implementation' into xla/220-meditations-o…
xla Apr 1, 2020
52f45f7
projects store
sarahscott Apr 2, 2020
a6a6bf1
messages defined outside of event
sarahscott Apr 2, 2020
e667f13
remote data type
sarahscott Apr 3, 2020
238b611
simplify access to readable store
sarahscott Apr 6, 2020
fb9f3e9
modifications to RemoteDataStore
sarahscott Apr 7, 2020
fa8e53c
remove stray TODOs
sarahscott Apr 7, 2020
c7c205f
add another todo for myself
sarahscott Apr 7, 2020
11cd5f7
added more todos
sarahscott Apr 7, 2020
9322187
clean up RemoteDataStore
sarahscott Apr 7, 2020
bbd09ea
Merge branch 'master' into xla/220-warp-implementation
xla Apr 7, 2020
5ee5a4e
Enable identities
xla Apr 8, 2020
4b814ab
Clean up
xla Apr 8, 2020
2f24ac7
Add missing docs
xla Apr 8, 2020
ce15339
Add transaction listing
xla Apr 8, 2020
4ef7506
Add missing docs
xla Apr 8, 2020
a6703e1
Simplify API
xla Apr 8, 2020
d21b9a1
Merge branch 'master' into xla/220-warp-implementation
xla Apr 8, 2020
b437207
Set up linting for ts
xla Apr 9, 2020
e3d5ffe
Improve API access
xla Apr 9, 2020
ea0317b
Set cypress cache directory
xla Apr 9, 2020
be63d25
Attempt to fix CI
rudolfs Apr 9, 2020
53769de
Revert "Attempt to fix CI"
rudolfs Apr 9, 2020
9413bcd
Simplify event handling
xla Apr 10, 2020
cc5bbe4
Make event handling sound
xla Apr 10, 2020
daa7ccd
Pass through project stats
xla Apr 10, 2020
437fc4d
Integrate OpenAPI documentation
xla Apr 14, 2020
741d98e
Minimize docs clutter
xla Apr 14, 2020
fdb953a
Merge branch 'master' into xla/220-warp-implementation
xla Apr 15, 2020
1ec2631
Expose GraphQL and REST API together
xla Apr 15, 2020
54b4455
Merge branch 'master' into xla/220-warp-implementation
xla Apr 15, 2020
4330574
Fix tests
xla Apr 15, 2020
3948265
sourceBrowserStore & parameterized FileSource
sarahscott Apr 16, 2020
500052a
simplify RevisionSelector
sarahscott Apr 16, 2020
751e88e
update revision event
sarahscott Apr 16, 2020
9a97fa7
simplifies FileList
sarahscott Apr 16, 2020
351fc9a
update source path
sarahscott Apr 16, 2020
cf6c842
Implement first source browsing endpoint
xla Apr 16, 2020
ab3f0ed
Use string enum for object type documentation
xla Apr 16, 2020
ca4423f
Adjust types to match proxy
xla Apr 16, 2020
06991c6
Make prettier check happy
rudolfs Apr 16, 2020
cece03b
Correct tye missmatch
xla Apr 16, 2020
88e5854
Fix field
xla Apr 16, 2020
17d6009
Implement commit endpoint
xla Apr 16, 2020
9dd2b79
Implement tree endpoint
xla Apr 17, 2020
d381d07
Implement branches endpoint
xla Apr 17, 2020
63d64e9
Implement tags endpoint
xla Apr 17, 2020
df138a0
Fix docs
xla Apr 17, 2020
07c8538
Complete first circle of source browsing
xla Apr 17, 2020
ebcc13b
blob name and revision event fix
sarahscott Apr 18, 2020
f6c6fef
Merge branch 'master' into xla/220-warp-implementation
xla Apr 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .buildkite/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ else
echo "HOME=$HOME"
fi

mkdir -p "$CACHE_FOLDER/cypress"
mkdir -p "$CACHE_FOLDER/npm"
mkdir -p "$CACHE_FOLDER/yarn"
mkdir -p "$CACHE_FOLDER/cargo"
mkdir -p "$CACHE_FOLDER/rustup"


export CYPRESS_CACHE_FOLDER="$CACHE_FOLDER/cypress"
Copy link
Member

Choose a reason for hiding this comment

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

I think this and L24 didn't make any difference to the CI build stability and can be removed again.

export NPM_CONFIG_CACHE="$CACHE_FOLDER/npm"
export YARN_CACHE_FOLDER="$CACHE_FOLDER/yarn"
export CARGO_HOME="$CACHE_FOLDER/cargo"
Expand Down
36 changes: 29 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": ["eslint:recommended"],
"plugins": ["svelte3"],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
}
},
"overrides": [
{
"files": ["**/*.svelte"],
"processor": "svelte3/svelte3"
"plugins": ["svelte3"],
"processor": "svelte3/svelte3",
"parser": "babel-eslint"
},
{
"files": ["**/*.ts"],
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
}
}
],
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"rules": {
// Disallow Unused Variables
// https://eslint.org/docs/rules/no-unused-vars
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ cypress/fixtures/example.json
proxy/target
proxy/**/*.rs.bk
schema.gql
ui/src/*.js
ui/src/*.js.map
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"@babel/node": "^7.8.4",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.6",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"apollo": "^2.24.0",
"babel-eslint": "^10.1.0",
"chokidar": "^3.3.1",
Expand All @@ -67,15 +69,17 @@
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-svelte": "^5.1.1",
"rollup-plugin-terser": "^5.2.0",
"rollup-plugin-typescript2": "^0.27.0",
"sirv-cli": "^0.4.5",
"standard-version": "^7.1.0",
"svelte": "^3.20.1",
"svelte-click-outside": "https://github.com/radicle-dev/svelte-click-outside#10e47e6359f943d45b72c2f3fc7ccc8036b60fac",
"svelte-spa-router": "^2.1.0",
"typescript": "3.8.3",
"wait-on": "^4.0.1"
},
"scripts": {
"start": "run-p --race svelte:watch proxy:start graphiql:serve electron:start",
"start": "run-p --race svelte:watch proxy:start:test graphiql:serve electron:start",
Copy link
Member

Choose a reason for hiding this comment

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

I assume this will be reverted before merge?

"start:test": "run-p --race svelte:watch proxy:start:test electron:start",
"test": "TZ='UTC' run-p --race proxy:start:test test:run",
"test:debug": "TZ='UTC' run-p --race svelte:watch proxy:start:test cypress:open",
Expand All @@ -87,7 +91,7 @@
"svelte:watch": "yarn svelte:clean && rollup -c -w",
"proxy:build": "cd proxy && cargo build --all-features --all-targets",
"proxy:build:release": "cd proxy && cargo build --release --all-features --all-targets",
"proxy:start": "cd proxy && cargo run --release -- --registry=emulator",
"proxy:start": "cd proxy && cargo run -- --registry=emulator",
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

"proxy:start:test": "cd proxy && cargo run -- --registry=emulator --test",
"graphiql": "open http://localhost:5000",
"graphiql:serve": "yarn sirv ./graphiql",
Expand All @@ -101,7 +105,7 @@
"prettier": "prettier \"**/*.@(js|json|svelte|css|html)\" --ignore-path .gitignore",
"prettier:check": "yarn prettier --check",
"prettier:write": "yarn prettier --write",
"lint": "eslint . --ignore-path .gitignore --ext .js,.svelte"
"lint": "eslint . --ignore-path .gitignore --ext js,.svelte,.ts"
Copy link
Member

Choose a reason for hiding this comment

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

Is "js" vs ".js" a typo here?

},
"dependencies": {
"@babel/runtime": "^7.8.4",
Expand Down Expand Up @@ -132,6 +136,9 @@
"*.svelte": [
"prettier --plugin-search-dir=. --write",
"eslint --fix"
],
"*.ts": [
"eslint --fix"
]
}
}
193 changes: 193 additions & 0 deletions proxy/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Radicle Proxy REST API

## Routes

All routes under the REST API respond with JSON and expect request bodies to be encoded as JSON with the header `content-type: application/json` set.

The examples provided use [curl](https://curl.haxx.se/) and the [window.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) function available in the JavaScript environments of modern browsers.

### GET /projects
Copy link
Member

Choose a reason for hiding this comment

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

We should probably add a yarn script to start up the swagger live doc server and explain here how to use it and remove all the examples from this file.


Retrieve a list of known projects. Returns a list of projects.

Returns a list of Projects. (See Entities)

Curl example:

```
$ curl http://localhost:8080/api/v1/projects

[
{
"id": "ccb86b0a6860e27d403a09f15ce444c9c6b262dc.git",
"metadata": {
"name": "wow",
"description": "hello",
"default_branch": "master",
"img_url": "https://bovid.space/icons/favicon.ico"
}
}
]
```

JavaScript example:

```
fetch("http://localhost:8080/api/v1/projects")
.then((response) => {
return response.json()
// [{ "id": "...", "metadata": {...} }]
})
```

### POST /projects

Add a new project from the filesystem, assigning a librad ID to it.

Request JSON object:

- `path`: Path to the project on the filesystem, relative to the proxy's working directory.
- `metadata`: An object containing metadata about the project.
- `metadata.name`: The given name of the project.
- `metadata.description`: The given description of the project.
- `metadata.default_branch`: The default branch of the git project, ex: `master`.
- `metadata.img_url`: A URL to the image icon used for the project.

Returns a Project. (See Entities).

Status codes:

- [201 Created](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.2): Project assigned a librad ID.
- [400 Bad Request](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1): The project is already known to the proxy.

Curl example:

```
$ curl -v -X POST -H 'content-type: application/json' http://localhost:8080/api/v1/projects -d '{"path":"..", "metadata":{"name":"radicle-upstream-proxy", "description":"hello world", "img_url":"http://bovid.space/favicon.ico", "default_branch": "master"}}'

{
"id": "1a7f9a6e1883fc5781f3b1f8dccf21df04e06f11.git",
"metadata": {
"name": "who",
"description": "hello",
"default_branch": "master",
"img_url": "http://bovid.space/favicon.ico"
}
}
```

JavaScript example:

```
fetch("http://localhost:8080/api/v1/projects", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
path: "/home/$USER/code/radicle-upstream",
metadata: {
name: "radicle-upstream",
description: "Upstream is a cross-platform desktop client for the radicle code collaboration and registry protocols.",
default_branch: "master",
img_url: "https://..."
}
})
})
.then((response) => {
return response.json()
// { "id": "...", "metadata": {...} }
})
```

### GET /projects/<id>

Retrieve information about a particular project by its librad ID.

Returns a Project. (See Entities).

Curl example:

```
$ curl http://localhost:8080/api/v1/projects/da465d3457cc48968d78f66aadd01f8504c363a2.git

{"id":"da465d3457cc48968d78f66aadd01f8504c363a2.git","metadata":{"name":"radicle-upstream-proxy","description":"hello world","default_branch":"master","img_url":"http://bovid.space/favicon.ico"}}
```

### POST /projects/register

Register a project on the Radicle Registry.

Request JSON object:

- `org_id`: ID of the organization under which the project will be registered.
- `project_name`: Name of the project to use in the registry.
- `maybe_coco_id`: Optional librad ID for the project, used for mutual attestation.

Response JSON object:

- `id`: Abridged hexadecimal ID of this transaction on the registry.
- `messages[]`: Array of messages from the registry.
- `messages[].ProjectRegistration`: Information about the project registration.
- `messages[].ProjectRegistration.org_id`: Name of the organization with which the project is registered.
- `messages[].ProjectRegistration.project_name`: Name of the registered project.
- `state`: Information about the state of the transaction.
- `state.type`: A string indicating the state of the transaction. Currently will only ever be `TransactionApplied`.
- `state.block_hash`: The hash of the block the transaction is included in.
- `timestamp`: An object indicating when this transaction was applied.
- `timestamp.secs_since_epoch`: Seconds since epoch to the moment this transaction was applied.
- `timestamp.nanos_since_epoch`: Nanoseconds since epoch to the second this transaction was applied.

Curl example:

```
$ curl -v -X POST -H 'content-type: application/json' http://localhost:8080/api/v1/projects/register -d '{"org_id": "radicle", "project_name": "radicle-upstream"}'

{
"id": "0x47d8…3fcb",
"messages": [
{
"ProjectRegistration": {
"org_id": "abcdef",
"project_name": "cool-kids-club"
}
}
],
"state": {
"type": "TransactionApplied",
"block_hash": "0x0000…0000"
},
"timestamp": {
"secs_since_epoch": 1585616602,
"nanos_since_epoch": 216308544
}
}
```

JavaScript example:

```
fetch("http://localhost:8080/v1/projects/register", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
org_id: "radicle",
project_name: "radicle-upstream"
})
})
```

## Entities

The API returns some common objects representing entities in the domain.

### Project

- `id`: Librad ID of the project.
- `metadata`: An object containing metadata about the project.
- `metadata.name`: The given name of the project.
- `metadata.description`: The given description of the project.
- `metadata.default_branch`: The default branch of the git project, ex: `master`.
- `metadata.img_url`: A URL to the image icon used for the project.
Loading