Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
Open
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
13 changes: 10 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.git
.github
# from .gitignore
.env
lerna-debug.json
yarn-error.log
node_modules
build

# extra ignores to help docker caching
monitoring
.git
.github
docker-compose.yml
README.md
*.md
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

# Logs
lerna-debug.json
yarn-error.log

# Dependencies
node_modules
package-lock.json

# builds
build
34 changes: 11 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
FROM node:12.14.0-alpine
FROM node:12.19.0-alpine
RUN apk add --no-cache git

WORKDIR /app

# copy root package and lerna json files
COPY ./package.json /app/package.json
COPY ./lerna.json /app/lerna.json

# copy app package json
RUN mkdir -p /packages/app
COPY ./packages/app/package.json /app/packages/app/package.json

# copy server package json
RUN mkdir -p /packages/server
COPY ./packages/server/package.json /app/packages/server/package.json

# copy services package json
RUN mkdir -p /packages/services
COPY ./packages/services/package.json /app/packages/services/package.json

# copy shared package json
RUN mkdir -p /packages/shared
COPY ./packages/shared/package.json /app/packages/shared/package.json
# copy all package json files
COPY ./package.json /app/package.json
COPY ./packages/app/package.json /app/packages/app/package.json
COPY ./packages/server/package.json /app/packages/server/package.json
COPY ./packages/services/package.json /app/packages/services/package.json
COPY ./packages/shared/package.json /app/packages/shared/package.json

# install dependencies
COPY ./yarn.lock /app/yarn.lock
RUN yarn install
RUN yarn lerna link
COPY ./yarn.lock /app/yarn.lock
RUN yarn install --frozen-lockfile

# try building the app
COPY . .
RUN yarn build

CMD echo specify one of the package.json scripts in command line
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
},
"scripts": {
"db:setup": "lerna run db:setup --scope '*/*-server' --stream",
"start:app": "lerna run --scope=@aragon/protocol-backend-app --concurrency=1 --stream start",
"start:server": "lerna run --scope=@aragon/protocol-backend-server --concurrency=1 --stream start",
"start:server:dev": "lerna run --scope=@aragon/protocol-backend-server --concurrency=1 --stream start:dev",
"start:services": "lerna run --scope=@aragon/protocol-backend-services --concurrency=1 --stream start",
"start:services:dev": "lerna run --scope=@aragon/protocol-backend-services --concurrency=1 --stream start:dev",
"test:server": "lerna run --scope=@aragon/protocol-backend-server --concurrency=1 --stream test",
"test:services": "lerna run --scope=@aragon/protocol-backend-services --concurrency=1 --stream test"
"build": "lerna run --stream build",
"build:shared": "yarn run --scope '*/*-shared' build",
"start:app": "lerna run --scope '*/*-app' --stream start",
"start:server": "lerna run --scope '*/*-server' --stream start",
"start:server:dev": "lerna run --scope '*/*-server' --stream start:dev",
"start:services": "lerna run --scope '*/*-services' --stream start",
"start:services:dev": "lerna run --scope '*/*-services' --stream start:dev",
"test:server": "lerna run --scope '*/*-server' --stream test",
"test:services": "lerna run --scope '*/*-services' --stream test"
},
"workspaces": {
"packages": [
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"web3-utils": "^1.2.4"
},
"scripts": {
"build:shared": "yarn workspace @aragon/protocol-backend-shared build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "Aragon One",
"license": "(GPL-3.0-or-later OR AGPL-3.0-or-later)",
"scripts": {
"build:shared": "yarn workspace @aragon/protocol-backend-shared build",
"mint": "node ./bin/index.js mint --verbose",
"stake": "node ./bin/index.js stake --verbose",
"unstake": "node ./bin/index.js unstake --verbose",
Expand Down
1 change: 1 addition & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"scripts": {
"build": "babel ./src --out-dir ./build --source-maps --copy-files",
"build:shared": "yarn workspace @aragon/protocol-backend-shared build",
"start": "yarn build && yarn db:setup && node ./build",
"start:dev": "yarn db:setup && nodemon --ignore ./build --exec babel-node ./src/index.js",
"knex": "npx babel-node ./node_modules/.bin/knex",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/helpers/session-middleware.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import expressSession from 'express-session'
import { Session } from '../models/objection'

import { HOURS, DAYS } from '@aragon/protocol-backend-shared/helpers/times'
import { HOURS, DAYS } from '@aragon/protocol-backend-shared/build/helpers/times'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may be a dumb question, but when we update these other helpers to be in TS, would we be able to import the source files?

It seems a bit weird to have to do this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One way to do it would be to define main and types in package.json like I did in ipfs pinner and then have all imports in a single index.ts file:
https://github.com/aragonone/ipfs-pinner/blob/development/packages/shared/src/index.ts

In this case we could import the same thing like this:

import { times } from '@aragon/protocol-backend-shared
const { HOURS, DAYS } = times

I find this more verbose however and you also have to think about multiple imports/exports not just the source file directly.

const SESSION_MAXAGE = 30 * DAYS
const SESSION_EXPIRE_INTERVAL = HOURS
const { SESSION_SECURE } = process.env
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/models/objection/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UserEmail from './UserEmail'
import emailClient from '@aragon/protocol-backend-shared/helpers/email-client'
import { generateToken } from '../../helpers/token-manager'

import { DAYS } from '@aragon/protocol-backend-shared/helpers/times'
import { DAYS } from '@aragon/protocol-backend-shared/build/helpers/times'
const EMAIL_TOKEN_EXPIRES = DAYS
const EMAIL_TOKEN_OLD = DAYS

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/models/objection/UserNotification.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BaseModel from './BaseModel'
import { HOURS } from '@aragon/protocol-backend-shared/helpers/times'
import { HOURS } from '@aragon/protocol-backend-shared/build/helpers/times'

export default class UserNotification extends BaseModel {
static get tableName() {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/validators/UserSessionsValidator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { utils } from 'ethers'
import BaseValidator from './BaseValidator'

import { MINUTES } from '@aragon/protocol-backend-shared/helpers/times'
import { MINUTES } from '@aragon/protocol-backend-shared/build/helpers/times'
const SESSION_SIGNATURE_EXPIRES = MINUTES * 10

class UserSessionsValidator extends BaseValidator {
Expand Down
3 changes: 2 additions & 1 deletion packages/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "(GPL-3.0-or-later OR AGPL-3.0-or-later)",
"main": "index.js",
"scripts": {
"build:server": "cd node_modules/@aragon/protocol-backend-server && npm run build",
"build:shared": "yarn workspace @aragon/protocol-backend-shared build",
"build:server": "yarn workspace @aragon/protocol-backend-server build",
"start": "npm run build:server && babel-node ./bin/main.js",
"start:dev": "npm run build:server && nodemon --ignore ./build --exec babel-node ./bin/main.js",
"test": "npx mocha test --recursive --exit --require @babel/register"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { env: { CLIENT_URL } } = process
import { MINUTES, HOURS, DAYS } from '@aragon/protocol-backend-shared/helpers/times'
import { MINUTES, HOURS, DAYS } from '@aragon/protocol-backend-shared/build/helpers/times'

export default class NotificationScannerBaseModel {
async shouldNotifyUser(user) {
Expand Down
2 changes: 1 addition & 1 deletion packages/services/src/workers/contract-monitor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Etherscan from '../models/Etherscan'
import { DAYS } from '@aragon/protocol-backend-shared/helpers/times'
import { DAYS } from '@aragon/protocol-backend-shared/build/helpers/times'
import getWalletFromPk from '@aragon/protocol-backend-shared/helpers/get-wallet-from-pk'
import abi from 'web3-eth-abi'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { env: { CLIENT_URL } } = process
const notificationTypeModel = 'SubscriptionReminder'
const TEST_ADDR = '0xfc3771B19123F1f0237C737e92645BA6d628e2cB'
const TEST_EMAIL = 'subscription@reminder.test'
import { DAYS } from '@aragon/protocol-backend-shared/helpers/times'
import { DAYS } from '@aragon/protocol-backend-shared/build/helpers/times'


describe('SubscriptionReminder notifications', () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/shared/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"root": true,
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
// allow using any and non null assertion for Objection models
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off"
}
}
13 changes: 12 additions & 1 deletion packages/shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,16 @@ It provides the following helper functions:
- [`logger`](./helpers/logger.js): Logger object that provides a friendly interface for fancy logging
- [`numbers`](./helpers/numbers.js): BigNumber-related helper functions
- [`sleep`](./helpers/sleep.js): Sleep function to wait a number of seconds
- [`times`](./helpers/times.js): Time constants for using with `Date()`
- [`times`](./helpers/times.ts): Time constants for using with `Date()`
- [`voting`](./helpers/voting.js): Utils related to the CR Voting module of Aragon Protocol


## TypeScript compilation

Shared modules need to be compiled first before importing in other packages:
```
yarn build

# from another package:
yarn build:shared
```
18 changes: 18 additions & 0 deletions packages/shared/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"presets": [
"@babel/preset-typescript",
[
"@babel/preset-env",
{
"targets": {
"node": "current"
},
"useBuiltIns": "usage",
"corejs": 3
}
]
],
"plugins": [
"@babel/plugin-proposal-export-namespace-from"
]
}
5 changes: 0 additions & 5 deletions packages/shared/helpers/times.js

This file was deleted.

20 changes: 19 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
"private": true,
"author": "Aragon One",
"license": "(GPL-3.0-or-later OR AGPL-3.0-or-later)",
"scripts": {
"lint": "eslint src/** --ext .ts",
"build": "yarn lint && yarn build:types && yarn build:js",
"build:types": "tsc",
"build:js": "babel ./src --out-dir ./build --extensions .ts",
"build:clean": "yarn clean && yarn build",
"clean": "rm -rf ./build"
},
"dependencies": {
"@aragon/protocol-evm": "1.0.0-beta.2",
"@aragon/contract-helpers-test": "^0.1.0",
"@aragon/protocol-evm": "1.0.0-beta.2",
"@aragon/truffle-config-v5": "^1.0.1",
"@aragonone/erc20-faucet": "^1.0.0",
"@truffle/config": "1.2.7",
Expand All @@ -17,5 +25,15 @@
"graphql-request": "^1.8.2",
"postmark": "^2.5.3",
"web3-utils": "^1.2.4"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"@typescript-eslint/eslint-plugin": "^4.6.1",
"@typescript-eslint/parser": "^4.6.1",
"eslint": "^7.12.1",
"typescript": "^4.0.5"
}
}
6 changes: 6 additions & 0 deletions packages/shared/src/helpers/times.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const SECONDS = 1000
const MINUTES = 60 * SECONDS
const HOURS = 60 * MINUTES
const DAYS = 24 * HOURS

export { SECONDS, MINUTES, HOURS, DAYS }
18 changes: 18 additions & 0 deletions packages/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"include": [
"src/**/*"
],
"compilerOptions": {
"strict": true,
"outDir": "./build",
"declaration": true,
"emitDeclarationOnly": true,
"moduleResolution": "Node",
// allow advanced js features, proper targeting is done using Babel
"target": "ESNext",
// allow non-ES modules with 'export =' syntax as default imports
"esModuleInterop": true,
// allow json import
"resolveJsonModule": true
}
}
Loading