Skip to content
This repository was archived by the owner on Nov 24, 2020. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"settings": {
"react": {
"version": "detect"
}
},
"extends": [
"eslint:recommended",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint",
"prettier/react"
],
"plugins": ["@typescript-eslint", "react", "import", "prettier"],
"rules": {
"eol-last": "warn",
"no-multiple-empty-lines": ["warn", { "max": 1 }],
"lines-between-class-members": [
"warn",
"always",
{ "exceptAfterSingleLine": true }
],
"no-unneeded-ternary": "error",
"no-nested-ternary": "warn",
"prefer-object-spread": "warn",
"react/react-in-jsx-scope": 0,
"import/no-default-export": "warn",
"import/newline-after-import": "warn",
"import/order": [
"warn",
{
"newlines-between": "always",
"groups": [
"builtin",
["internal", "external"],
"parent",
"sibling",
"index"
]
}
],
"no-void": [
"error",
{
"allowAsStatement": true
}
]
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"overrides": [
{
"files": ["*.tsx"],
"rules": {
"semi": ["error", "never"]
}
},
{
"files": ["*.tsx"],
"rules": {
"@typescript-eslint/explicit-member-accessibility": "warn",
"@typescript-eslint/no-use-before-define": "warn",
"@typescript-eslint/indent": ["error", 2],
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/promise-function-async": "warn",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/restrict-plus-operands": "warn",
"@typescript-eslint/no-unnecessary-type-assertion": "warn"
}
}
],
"env": {
"browser": true,
"node": true
}
}
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Docker CI

on:
push:
branches: [ master ]
branches: [master]
tags:
- '*'
- '*'
pull_request:
branches: [ master ]
branches: [master]

jobs:
build-and-push:
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
container-job:
runs-on: ubuntu-latest
container: node:10.18-jessie

strategy:
matrix:
node-version: [10.x, 12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint
- run: npm run build
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.next
out
node_modules
31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![](https://github.com/codius/codius-web/workflows/Docker%20CI/badge.svg)

Web-monetized Codius service deployment and loading pages.
Web-monetized Codius balance reload page.

### Run

Expand All @@ -14,32 +14,27 @@ PAYMENT_POINTER=$codius.example.com npm start

### Environment Variables

#### CODIUS_HOST_URI
* Type: String
* Description: Root URI the Codius host

#### PAYMENT_POINTER
* Type: String
* Description: Codius host's [payment pointer](https://paymentpointers.org/).

- Type: String
- Description: Codius host's [payment pointer](https://paymentpointers.org/).

#### RECEIPT_VERIFIER_URI
* Type: String
* Description: Root URI of the [receipt verifier](https://github.com/coilhq/receipt-verifier)'s `balances` API.

- Type: String
- Description: Root URI of the [receipt verifier](https://github.com/coilhq/receipt-verifier)'s `balances` API.

#### REQUEST_PRICE
* Type: Number
* Description: The amount required to have been paid to serve a request. Denominated in the host's asset (code and scale).

- Type: Number
- Description: The amount required to have been paid to serve a request. Denominated in the host's asset (code and scale).

### Routes

#### `/`
Codius host's service deployment page.

This page is web-monetized. Deployment instructions are displayed when payment is verified (by successfully crediting receipt(s) to the web monetization request id balance at the [receipt verifier](https://github.com/coilhq/receipt-verifier)).

The balance is expected to be debited by the Codius host's [authentication token webhook](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#webhook-token-authentication) ([implementation](https://github.com/wilsonianb/codius-token-auth-webhook)) when the CREATE request is made to the Kubernetes API server.
Balance reload page.

#### `/{ID}/402`
Codius service balance reload page.
This page is web-monetized, and receipts are credited to the balance at the [`RECEIPT_VERIFIER_URI`](#receipt_verifier_uri).

This page is web-monetized. The total paid amount and a link to the Codius service are displayed when payment is verified (by successfully crediting receipt(s) to the Codius service's balance at the [receipt verifier](https://github.com/coilhq/receipt-verifier)).
The page reloads when the balance exceeds the [`REQUEST_PRICE`](#request_price).
17 changes: 17 additions & 0 deletions components/Head.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FC } from 'react'
import NextHead from 'next/head'

interface HeadProps {
paymentPointer: string
}

export const Head: FC<HeadProps> = (props: HeadProps) => {
return (
<NextHead>
<title>Codius Host</title>
<meta charSet='utf-8' />
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
<meta name='monetization' content={props.paymentPointer} />
</NextHead>
)
}
42 changes: 0 additions & 42 deletions components/Instructions.tsx

This file was deleted.

27 changes: 0 additions & 27 deletions components/Loading.tsx

This file was deleted.

34 changes: 34 additions & 0 deletions components/ReceiptSubmitter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FC, useEffect } from 'react'
import { useMonetizationCounter } from 'react-web-monetization'

interface ReceiptSubmitterProps {
balanceId: string
receiptVerifierUri: string
requestPrice: number
}

export const ReceiptSubmitter: FC<ReceiptSubmitterProps> = (
props: ReceiptSubmitterProps
) => {
const { receipt } = useMonetizationCounter()

useEffect(() => {
if (receipt !== null && props.balanceId !== '') {
const submitReceipt = async (): Promise<void> => {
const res = await fetch(
`${props.receiptVerifierUri}/balances/${props.balanceId}:creditReceipt`,
{
method: 'POST',
body: receipt
}
)
if (res.ok && parseInt(await res.text()) >= props.requestPrice) {
window.location.reload(true)
}
}
void submitReceipt()
}
}, [receipt])

return null
}
11 changes: 0 additions & 11 deletions components/Reload.tsx

This file was deleted.

46 changes: 0 additions & 46 deletions components/WebMonetizationLoader.tsx

This file was deleted.

21 changes: 21 additions & 0 deletions components/WebMonetizationStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FC } from 'react'
import { useMonetizationCounter } from 'react-web-monetization'

export const WebMonetizationStatus: FC = () => {
const { state: monetizationState } = useMonetizationCounter()

if (monetizationState === 'pending' || monetizationState === 'started') {
return (
<pre>
Awaiting <a href='https://webmonetization.org'>Web Monetization</a>...
</pre>
)
} else {
return (
<pre>
Pay with <a href='https://webmonetization.org'>Web Monetization</a> to
access this Codius host.
</pre>
)
}
}
4 changes: 2 additions & 2 deletions config/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ spec:
app: codius-web
spec:
containers:
- name: codius-web
image: codius/codius-web
- name: codius-web
image: codius/codius-web
Loading