Compare commits

...
Sign in to create a new pull request.

135 commits

Author SHA1 Message Date
1a5ef88c55
basic tests 2025-08-28 22:57:20 +02:00
cd9c7678ee
add AGENTS.md 2025-08-28 22:49:07 +02:00
f444bd792f
remove tests 2025-08-28 22:45:36 +02:00
74263b1e1c
add migration command to package.json 2025-08-28 22:43:21 +02:00
d19c057937
offer service makes transaction for offer creation 2025-03-22 17:02:56 +01:00
3b995dfc70
services provider takes sequelize 2025-03-22 16:59:17 +01:00
Pablo Martin
369aa6a6ed split install into multiple steps 2025-03-19 18:51:26 +01:00
Pablo Martin
865b974f38 move price display 2025-03-17 17:52:15 +01:00
Pablo Martin
a3643ee9d0 premium and price connected 2025-03-17 17:49:03 +01:00
Pablo Martin
cca4402126 separate price setting behaviour 2025-03-17 17:21:43 +01:00
Pablo Martin
97847f503b price display can be seen 2025-03-17 16:45:20 +01:00
Pablo Martin
536408482b formatting 2025-03-17 16:23:12 +01:00
Pablo Martin
bc3ed21da4 a few small notes 2025-03-17 16:01:02 +01:00
b8579a5370
premium selector 2025-03-15 17:28:48 +01:00
1da3252061
missing export 2025-03-15 16:36:50 +01:00
ceba684d77
buy or sell button group 2025-03-15 16:36:31 +01:00
47c50ad078
move to different file 2025-03-15 15:28:44 +01:00
c82fc895b7
button extracted 2025-03-15 15:26:57 +01:00
4ee00edb04
extract out function 2025-03-15 14:56:51 +01:00
2b7b761737
styles and typo 2025-03-15 12:53:44 +01:00
4006523c8c
lots of stuff 2025-03-15 12:46:55 +01:00
add7891e94
login service 2025-03-14 18:52:00 +01:00
8ae4fddd12
refactor name 2025-03-14 18:28:53 +01:00
cb54bbe6b6
inline useless functions 2025-03-14 17:03:29 +01:00
29a4c0ca69
popup component 2025-03-14 16:57:55 +01:00
4c28cebdce
oportunistic linting stuff 2025-03-14 16:24:53 +01:00
983c9644bf
warnings and stuff 2025-03-14 16:14:01 +01:00
545c54bf81
stuff really 2025-03-13 15:36:00 +01:00
8131de0c96
use util 2025-03-13 11:48:40 +01:00
0b3e5e83a3
extract util 2025-03-13 11:45:28 +01:00
5a7c954982
ignore bundle files 2025-03-13 11:33:10 +01:00
faf8d61ef8
home 2025-03-13 11:28:13 +01:00
17517f798d
home 2025-03-13 11:28:07 +01:00
0f7ec6f521
inline utils 2025-03-13 11:16:58 +01:00
161135e315
offers 2025-03-13 11:16:01 +01:00
9dbe299a32
login page 2025-03-13 11:08:54 +01:00
eb1cfbb64c
next page 2025-03-13 11:05:12 +01:00
ae64424f54
refactor invite page to pickup webpacked code 2025-03-12 18:57:17 +01:00
5b6ab8779e
configure webpack 2025-03-12 18:56:53 +01:00
f034f29d94
install webpack 2025-03-12 18:56:36 +01:00
e81533db4c
move public 2025-03-12 16:28:44 +01:00
7fcf62e647
delete offer popup 2025-03-10 16:45:16 +01:00
56fa3e20e7
refactor into function 2025-03-10 16:11:57 +01:00
4f1d6b4cfb
deleting offer updates offer list 2025-03-10 16:04:27 +01:00
78509e657b
remove sync foreva 2025-03-10 15:52:15 +01:00
107edb70e7
move associations file 2025-03-10 15:51:47 +01:00
5b35bb603d
rename 2025-03-10 15:38:23 +01:00
9c4581d33d
now only active offers are shown 2025-03-10 15:37:37 +01:00
613ded0cf1
add signupchallengecompleted 2025-03-10 14:08:16 +01:00
3e0a4772aa
signupchallengecreated 2025-03-10 14:02:41 +01:00
78362f1067
session related to publickey 2025-03-10 13:57:35 +01:00
bccde12a04
session created 2025-03-10 13:56:00 +01:00
d3e419c98b
offerdetailsset 2025-03-10 13:54:08 +01:00
01c9fca093
offercreated offerdeleted 2025-03-10 13:51:13 +01:00
8c4c9dfe99
add nymset 2025-03-10 13:46:14 +01:00
317ca7ded2
split FKs into another file 2025-03-10 13:43:55 +01:00
3b2edb4ca9
relationship 2025-03-10 13:05:33 +01:00
afc8a6d04d
nostr challenges 2025-03-10 13:02:33 +01:00
9d4967a41d
first couple models working, now let's add more 2025-03-10 12:47:09 +01:00
f5ced9888e
first schema 2025-03-09 17:13:26 +01:00
8e86f72975
start 2025-03-09 17:09:40 +01:00
55a57444f8
move database into folder 2025-03-09 16:51:23 +01:00
12a0c7563e
add sequelize-cli 2025-03-09 16:49:51 +01:00
bb68c0585a
no more sync 2025-03-09 16:49:20 +01:00
e718626aad
now it works 2025-03-09 16:48:37 +01:00
9660e263d1
removed unwanted async 2025-03-08 02:51:11 +01:00
2d124a1ef4
associations and db stuff 2025-03-08 02:47:37 +01:00
bf478bbbe9
pull up 2025-03-08 00:29:52 +01:00
b4d698a989
move declarations inside provider 2025-03-08 00:26:14 +01:00
be7ec9b43f
mass refactor of models 2025-03-08 00:25:56 +01:00
b5c27c9b26
pass models from dependencies 2025-03-07 16:24:51 +01:00
b1ff3b8d75
remove unused require 2025-03-07 16:14:04 +01:00
ee590984b2
remove comments 2025-03-07 16:06:55 +01:00
bf0775ba31
offer service 2025-03-07 16:06:44 +01:00
ec725f8e4e
profile service 2025-03-07 16:03:10 +01:00
42fea55233
finished session service 2025-03-07 15:35:55 +01:00
a2e44553d6
wip sessionService 2025-03-07 15:35:42 +01:00
53219924ff
wip sessionService 2025-03-07 15:35:22 +01:00
097bed525e
wip sessionService 2025-03-07 15:31:46 +01:00
e85fae2f99
wip sessionService 2025-03-07 15:31:04 +01:00
49c3e970cb
wip sessionService 2025-03-07 15:30:30 +01:00
0f4ccf9847
wip sessionService 2025-03-07 15:29:58 +01:00
ba9b4d5ef3
login service 2025-03-07 15:11:34 +01:00
544a134eb3
invite service 2025-03-07 15:05:43 +01:00
0da67c6104
missing errors import 2025-03-07 13:28:00 +01:00
00670f051f
no more models 2025-03-07 13:27:28 +01:00
73a71d3ccb
pass constants to nostr service 2025-03-07 13:17:55 +01:00
9f4bc729e2
finish the cli stuff 2025-03-07 13:03:44 +01:00
5c294b89a1
just a silly error change 2025-03-07 12:53:37 +01:00
9246da2e84
cli now uses DI 2025-03-07 12:52:15 +01:00
b680ede093
finished all services 2025-03-07 12:31:07 +01:00
f8a185e879
nostr service and fix usage in invites 2025-03-06 02:19:23 +01:00
15217dc77a
invites 2025-03-06 01:59:23 +01:00
69290f4c7a
session service 2025-03-06 01:46:17 +01:00
a2939a7f2e
profile service 2025-03-06 01:28:47 +01:00
56aa416751
first service 2025-03-06 01:26:36 +01:00
cdc344c528
services thingy 2025-03-06 01:09:45 +01:00
1dca924b83
all middlewares provider 2025-03-06 01:01:12 +01:00
3623ff11cb
last one 2025-03-06 00:46:51 +01:00
c4131c82aa
another 2025-03-06 00:39:16 +01:00
6ba8eed427
another 2025-03-06 00:35:48 +01:00
1ec83c5e5d
another 2025-03-06 00:33:15 +01:00
72b68e772b
another 2025-03-06 00:30:28 +01:00
3c5aa812ab
refactor first middleware 2025-03-06 00:14:30 +01:00
d34e62070a
refactor model imports in all services 2025-03-05 16:49:03 +01:00
011a255d9e
root module def for models 2025-03-05 16:44:02 +01:00
1702f29987
typo 2025-03-05 16:40:54 +01:00
1a82b28745
pass in express 2025-03-05 16:29:51 +01:00
2f93e65862
pass errors 2025-03-05 16:23:36 +01:00
47b2821f90
passing services 2025-03-05 16:21:37 +01:00
1cf303c31d
require all services in one go 2025-03-05 16:18:09 +01:00
54cb13d1e5
revert the shit i did when i started the other way around 2025-03-05 16:13:39 +01:00
966d951490
pass in middlwares 2025-03-05 16:07:57 +01:00
c923493108
start api routes 2025-03-05 16:04:44 +01:00
db97f9fd80
web routes complete di-ized 2025-03-05 15:55:13 +01:00
7cb9144281
more refactor 2025-03-05 15:53:13 +01:00
b36f44ae35
refactor middlwares 2025-03-05 15:50:51 +01:00
76efca914a
refactor middlewares 2025-03-05 15:46:51 +01:00
efa855c60a
split 2025-03-05 15:39:31 +01:00
7db9e7f78c
going somewhere, kinda 2025-03-05 15:21:57 +01:00
ba9fa84407
provider-ize profile service 2025-03-05 15:04:27 +01:00
76e6bee411
put factor creation in function 2025-03-05 14:08:12 +01:00
26f549c928
button deletes 2025-03-05 11:29:20 +01:00
2b48c7f5e2
endpont 2025-03-05 11:13:10 +01:00
ab41f50142
export service function 2025-03-05 11:13:01 +01:00
5134982870
fix bug 2025-03-05 11:10:06 +01:00
a5e519f634
service entry 2025-03-05 00:48:33 +01:00
9f807a783d
new model 2025-03-05 00:40:34 +01:00
6930e0708c
remove old stuff, format 2025-03-05 00:28:56 +01:00
5e09802d5e
checkboxes now work properly 2025-03-05 00:26:30 +01:00
aea850c642
move button 2025-03-04 17:55:30 +01:00
98faeb2f1b
pretty modal hell yeah 2025-03-04 17:32:03 +01:00
0f889f6361
fix double rendering 2025-03-04 15:26:07 +01:00
a3f166089a
fix 2025-03-04 15:24:36 +01:00
8f762404cf
delete old stuff 2025-03-04 15:14:13 +01:00
125 changed files with 6258 additions and 2684 deletions

1
.eslintignore Normal file
View file

@ -0,0 +1 @@
public/javascript/*

6
.gitignore vendored
View file

@ -136,10 +136,10 @@ dist
.pnp.*
test-results/*
# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
# webpack bundles
/public/javascript/*

6
.sequelizerc Normal file
View file

@ -0,0 +1,6 @@
const path = require('path');
module.exports = {
config: path.resolve('src', 'database', 'config.js'),
'migrations-path': path.resolve('src', 'database', 'migrations'),
};

10
AGENTS.md Normal file
View file

@ -0,0 +1,10 @@
# secajs
## Architecture
This repository contains a webapp. It covers the full stack which consists of:
- The client side code, in `src/front/`.
- The backend service in `src/`, except for `src/front/`.
- A Postgres database. Database connections and migrations are in `src/database/`.
- Besides, there is an admin CLI, with entrypoint in `src/cli.js` and commands in `src/commands/`.

View file

@ -1,10 +1,22 @@
FROM debian:latest
FROM debian:12
# Install dependencies
RUN apt-get update && apt-get install -y \
curl gnupg2 ca-certificates lsb-release apt-transport-https \
postgresql caddy nodejs npm && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update
RUN apt-get install -y \
curl gnupg2 ca-certificates lsb-release apt-transport-https
RUN apt-get install -y \
postgresql
RUN apt-get install -y \
caddy
RUN apt-get install -y \
nodejs npm
RUN rm -rf /var/lib/apt/lists/*
RUN echo "listen_addresses='*'" >> /etc/postgresql/15/main/postgresql.conf && \
echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/15/main/pg_hba.conf && \

View file

@ -2,12 +2,6 @@
laseca is a social bitcoin to cash exchange, implemented as a webapp.
## Upcoming stories
* [ ] Create offer
* [ ] Display existing offers
* [ ] Archive offer
## How to set up dev environment
* Pre-requisites
@ -16,11 +10,16 @@ laseca is a social bitcoin to cash exchange, implemented as a webapp.
* Installing
+ Run `npm install`
+ You can now start the app in a container by running `npm run start:container` (and shut it down with `npm run stop:container`).
* Building
+ The front-end code gets built with webpack. You can build it anytime with `npm run build`.
+ For development, it's useful to build continuously. You can run `npm run watch` and webpack will build every time you edit a monitored file.
* Running
+ Copy the `.env.dist` file into `.env` and set any values you like.
+ The app will run in a single container, with a Postgres database, a caddy webserver and the nodejs app.
+ Note that the container doesn't come with a volume for Postgres: default behaviour is to start from scratch every time you create the container, delete everything every time you delete the container.
+ You probably want to run migrations to get the database into proper state. You can do so with `npx sequelize-cli db:migrate`.
+ The docker image launches the nodejs app with nodemon, so changes to the code will be available immediately.
+ Furthermore, since the git repository gets mounted live into the docker container, the live changes made by webpack watch mode will also be available as you work on front end files.
+ The Postgres database is reachable from the host, so you can use your favourite SQL client to access it.
+ You can format with `npm run format` and lint with `npm run lint`.

1948
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -20,10 +20,13 @@
"start": "node src/app.js",
"start:container": "docker compose up -d --build",
"stop:container": "docker compose down",
"migrate": "npx sequelize-cli db:migrate",
"build": "webpack",
"watch": "webpack --watch",
"cli": "node src/cli.js",
"test": "playwright test",
"lint": "eslint . --fix",
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,html,ejs}\""
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,html,ejs}\"",
"test": "playwright test"
},
"keywords": [],
"author": "",
@ -36,6 +39,9 @@
"globals": "^15.15.0",
"playwright": "^1.50.1",
"prettier": "^3.5.1",
"prettier-plugin-ejs": "^1.0.3"
"prettier-plugin-ejs": "^1.0.3",
"sequelize-cli": "^6.6.2",
"webpack": "^5.98.0",
"webpack-cli": "^6.0.1"
}
}

13
playwright.config.js Normal file
View file

@ -0,0 +1,13 @@
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
testDir: './tests',
use: {
baseURL: 'http://localhost:3000',
},
webServer: {
command: 'npm start',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});

39
public/css/login.css Normal file
View file

@ -0,0 +1,39 @@
@media (max-width: 768px) {
#login-button {
width: 200px;
}
.logo {
width: 350px;
}
#login-card-content {
width: 100%;
}
}
@media (min-width: 769px) {
#login-button {
width: 300px;
}
.logo {
width: 500px;
}
#login-card-content {
width: 40%;
min-width: min-content;
}
}
#login-card-content {
margin-right: auto;
margin-left: auto;
padding: 20px;
}
#login-card-content > * {
margin: 1vh auto;
text-align: center;
}

View file

@ -20,7 +20,7 @@
}
.create-offer-step {
width: 100%;
width: 95%;
}
.checkbox-row {
@ -62,6 +62,8 @@
margin-left: auto;
margin-right: auto;
width: 70%;
min-width: 500px;
max-width: 95%;
}
.checkbox-row {
@ -80,15 +82,6 @@
margin: 10px 10px;
padding: 10px;
}
}
#create-offer-root {
display: none;
}
#view-my-offers-root {
display: none;
}
#view-my-offers-root {
@ -221,24 +214,29 @@
.offer-action-area {
cursor: pointer;
margin-right: 20px;
padding: 3px;
}
.offer-long-text {
font-size: 0.9em;
}
#create-offer-controls {
text-align: center;
overflow-y: auto;
max-height: 800px;
padding: 20px;
}
.create-offer-step {
text-align: center;
border-radius: 20px;
box-shadow: 0 0 13px #ccc;
padding: 20px 0;
margin-top: 20px;
margin-bottom: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: auto;
margin-right: auto;
}
.create-offer-step h3 {
@ -387,3 +385,8 @@
#button-submit-offer {
width: 33%;
}
#close-offer {
margin-left: auto;
margin-right: auto;
}

View file

@ -13,7 +13,6 @@
}
.button-medium {
height: 3em;
padding: 0.5em 1em;
border-radius: 10px;
}
@ -37,7 +36,6 @@
}
.button-medium {
height: 3em;
padding: 1em;
border-radius: 10px;
}
@ -118,6 +116,34 @@ h1 {
height: 50px;
}
.full-screen-modal-background {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.75);
transition: all 0.5s ease-in-out;
opacity: 0;
visibility: hidden;
pointer-events: none;
}
.full-screen-modal-background.shown {
opacity: 1;
visibility: visible;
pointer-events: all;
}
.full-screen-modal {
background-color: white;
border-radius: 20px;
padding: 10px;
width: fit-content;
max-width: 95%;
margin: 20px auto;
}
.button-group button {
border: 0;
padding: 1em;
@ -197,6 +223,19 @@ h1 {
cursor: default;
}
.button-secondary {
background: white;
border: 0;
color: #e1c300;
cursor: pointer;
border: 3px solid #e1c300;
transition: all 0.5 ease-in-out;
}
.button-secondary:hover {
font-weight: bold;
}
.button-large {
font-weight: bold;
font-size: 1.5em;

View file

Before

Width:  |  Height:  |  Size: 829 B

After

Width:  |  Height:  |  Size: 829 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 829 B

After

Width:  |  Height:  |  Size: 829 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 123 KiB

After

Width:  |  Height:  |  Size: 123 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 9 KiB

After

Width:  |  Height:  |  Size: 9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1 KiB

After

Width:  |  Height:  |  Size: 1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 650 B

After

Width:  |  Height:  |  Size: 650 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before After
Before After

View file

@ -1,31 +1,35 @@
const express = require('express');
const cookieParser = require('cookie-parser');
const path = require('path');
const { buildDependencies } = require('./dependencies');
const app = express();
const port = 3000;
function createApp(dependencies) {
const app = express();
const port = 3000;
app.use(cookieParser());
app.set('port', port);
app.use(express.json());
app.use(cookieParser());
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.json());
const createSessionMiddleware = require('./middlewares/sessionMiddleware');
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(createSessionMiddleware);
app.use(dependencies.middlewares.createSessionMiddleware);
const webRoutes = require('./routes/webRoutes');
const apiRoutes = require('./routes/apiRoutes');
app.use('/', dependencies.webRoutes);
app.use('/api', dependencies.apiRoutes);
app.use('/', webRoutes);
app.use('/api', apiRoutes);
app.use(express.static(path.join(__dirname, '../public')));
app.use(express.static(path.join(__dirname, 'public')));
app.disable('etag'); //avoids 304 responses
app.disable('etag'); //avoids 304 responses
return app;
}
app.listen(port, () => {
console.log(`Server started on port ${port}`);
const dependencies = buildDependencies();
const app = createApp(dependencies);
app.listen(app.get('port'), () => {
console.log(`Server started on port ${app.get('port')}`);
});

View file

@ -1,13 +1,31 @@
const { Command } = require('commander');
const program = new Command();
const { buildDependencies } = require('./dependencies');
const createAppInviteCommand = require('./commands/createAppInvite');
function buildCLIDependencies() {
const appDependencies = buildDependencies();
program.version('1.0.0').description('CLI for managing web app tasks');
const CreateAppInviteProvider = require('./commands/createAppInvite');
const createAppInvite = new CreateAppInviteProvider({
invitesService: appDependencies.services.invitesService,
}).provide();
program
return { createAppInviteCommand: createAppInvite };
}
function buildCLI({ createAppInviteCommand }) {
const wipCli = new Command();
wipCli.version('1.0.0').description('CLI for managing web app tasks');
wipCli
.command('createAppInvite <inviterNpub>')
.description('Create an invite')
.action(createAppInviteCommand);
program.parse(process.argv);
return wipCli;
}
const cliDependencies = buildCLIDependencies();
const cli = buildCLI(cliDependencies);
cli.parse(process.argv);

View file

@ -1,7 +1,17 @@
const invitesService = require('../services/invitesService');
class CreateAppInviteProvider {
constructor({ invitesService }) {
this.invitesService = invitesService;
}
module.exports = async function createAppInvite(inviterNpub) {
const appInvite = await invitesService.createAppInvite(inviterNpub);
provide() {
const createAppInvite = async (inviterNpub) => {
const appInvite = await this.invitesService.createAppInvite(inviterNpub);
console.log('Invite created');
console.log(`Check at http://localhost/invite/${appInvite.uuid}`);
};
};
return createAppInvite;
}
}
module.exports = CreateAppInviteProvider;

View file

@ -1,7 +1,15 @@
const DEFAULT_SESSION_DURATION_SECONDS = 60 * 60 * 24 * 30;
const DEFAULT_NOSTR_CHALLENGE_DURATION_SECONDS = 60 * 60 * 24 * 30;
const DEFAULT_REDIRECT_DELAY = 3 * 1000; // 3seconds times milliseconds;
const API_PATHS = {
createProfile: '/createProfile',
home: '/home',
};
module.exports = {
DEFAULT_SESSION_DURATION_SECONDS,
DEFAULT_NOSTR_CHALLENGE_DURATION_SECONDS,
API_PATHS,
DEFAULT_REDIRECT_DELAY,
};

View file

@ -0,0 +1,36 @@
class AssociationsDefiner {
constructor({ models, DataTypes }) {
this.models = models;
this.DataTypes = DataTypes;
}
define() {
this.models.NostrChallengeCreated.hasOne(
this.models.NostrChallengeCompleted,
{
foreignKey: 'challenge',
}
);
this.models.NostrChallengeCompleted.belongsTo(
this.models.NostrChallengeCreated,
{
foreignKey: {
name: 'challenge',
},
}
);
this.models.OfferCreated.hasOne(this.models.OfferDeleted, {
foreignKey: 'offer_uuid',
});
this.models.OfferDeleted.belongsTo(this.models.OfferCreated, {
foreignKey: {
name: 'offer_uuid',
type: this.DataTypes.UUID,
allowNull: false,
},
});
}
}
module.exports = AssociationsDefiner;

21
src/database/config.js Normal file
View file

@ -0,0 +1,21 @@
const dotenv = require('dotenv');
dotenv.config();
module.exports = {
development: {
dialect: 'postgres',
host: process.env.POSTGRES_HOST,
port: 5432,
database: process.env.POSTGRES_DB,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
logging: console.log,
define: {
timestamps: false,
freezeTableName: true,
underscored: true,
quoteIdentifiers: false,
},
},
};

View file

@ -10,11 +10,11 @@ const sequelize = new Sequelize({
database: process.env.POSTGRES_DB,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
logging: (msg) => {
/* logging: (msg) => {
if (msg && (msg.includes('ERROR') || msg.includes('error'))) {
console.error(msg);
}
},
}, */
define: {
timestamps: false,
freezeTableName: true,
@ -23,13 +23,4 @@ const sequelize = new Sequelize({
},
});
sequelize
.sync()
.then(() => {
console.log('Database synced');
})
.catch((err) => {
console.error('Error syncing the database:', err);
});
module.exports = sequelize;

View file

@ -0,0 +1,379 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.createTable(
'app_invite_created',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
inviter_pub_key: {
type: Sequelize.STRING,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'contact_details_set',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
public_key: {
type: Sequelize.STRING,
allowNull: false,
},
encrypted_contact_details: {
type: Sequelize.TEXT,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'nostr_challenge_created',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
challenge: {
type: Sequelize.STRING,
allowNull: false,
unique: true,
},
expires_at: {
type: Sequelize.DATE,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'login_challenge_created',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
nostr_challenge_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'nostr_challenge_completed',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
challenge: {
type: Sequelize.STRING,
allowNull: false,
unique: true,
},
signed_event: {
type: Sequelize.JSONB,
allowNull: false,
},
public_key: {
type: Sequelize.STRING,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'login_challenge_completed',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
nostr_challenge_completed_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
public_key: {
type: Sequelize.STRING,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'nym_set',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
public_key: {
type: Sequelize.STRING,
allowNull: false,
},
nym: {
type: Sequelize.TEXT,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'offer_created',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
public_key: {
type: Sequelize.STRING,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'offer_deleted',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
offer_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'offer_details_set',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
offer_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
wants: {
type: Sequelize.STRING,
allowNull: false,
},
premium: {
type: Sequelize.DECIMAL(5, 2),
allowNull: false,
},
trade_amount_eur: {
type: Sequelize.INTEGER,
allowNull: false,
},
location_details: {
type: Sequelize.TEXT,
allowNull: false,
},
time_availability_details: {
type: Sequelize.TEXT,
allowNull: false,
},
show_offer_to_trusted: {
type: Sequelize.BOOLEAN,
allowNull: false,
},
show_offer_to_trusted_trusted: {
type: Sequelize.BOOLEAN,
allowNull: false,
},
show_offer_to_all_members: {
type: Sequelize.BOOLEAN,
allowNull: false,
},
is_onchain_accepted: {
type: Sequelize.BOOLEAN,
allowNull: false,
},
is_lightning_accepted: {
type: Sequelize.BOOLEAN,
allowNull: false,
},
are_big_notes_accepted: {
type: Sequelize.BOOLEAN,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'session_created',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
expires_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'session_related_to_public_key',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
session_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
public_key: {
type: Sequelize.STRING,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'sign_up_challenge_created',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
nostr_challenge_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
app_invite_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
queryInterface.createTable(
'sign_up_challenge_completed',
{
uuid: {
type: Sequelize.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
nostr_challenge_completed_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
app_invite_uuid: {
type: Sequelize.UUID,
allowNull: false,
},
public_key: {
type: Sequelize.STRING,
allowNull: false,
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
},
},
{ transaction: t }
),
]);
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Users');
},
};

View file

@ -0,0 +1,152 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.addConstraint(
'login_challenge_created',
{
fields: ['nostr_challenge_uuid'],
type: 'foreign key',
references: {
table: 'nostr_challenge_created',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
queryInterface.addConstraint(
'nostr_challenge_completed',
{
fields: ['challenge'],
type: 'foreign key',
references: {
table: 'nostr_challenge_created',
field: 'challenge',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
queryInterface.addConstraint(
'login_challenge_completed',
{
fields: ['nostr_challenge_completed_uuid'],
type: 'foreign key',
references: {
table: 'nostr_challenge_completed',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
queryInterface.addConstraint(
'offer_deleted',
{
fields: ['offer_uuid'],
type: 'foreign key',
references: {
table: 'offer_created',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
queryInterface.addConstraint(
'offer_details_set',
{
fields: ['offer_uuid'],
type: 'foreign key',
references: {
table: 'offer_created',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
queryInterface.addConstraint(
'session_related_to_public_key',
{
fields: ['session_uuid'],
type: 'foreign key',
references: {
table: 'session_created',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
queryInterface.addConstraint(
'sign_up_challenge_created',
{
fields: ['nostr_challenge_uuid'],
type: 'foreign key',
references: {
table: 'nostr_challenge_created',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
queryInterface.addConstraint(
'sign_up_challenge_created',
{
fields: ['app_invite_uuid'],
type: 'foreign key',
references: {
table: 'app_invite_created',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
queryInterface.addConstraint(
'sign_up_challenge_completed',
{
fields: ['nostr_challenge_completed_uuid'],
type: 'foreign key',
references: {
table: 'nostr_challenge_completed',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
queryInterface.addConstraint(
'sign_up_challenge_completed',
{
fields: ['app_invite_uuid'],
type: 'foreign key',
references: {
table: 'app_invite_created',
field: 'uuid',
},
onDelete: 'cascade',
onUpdate: 'cascade',
},
{ transaction: t }
),
]);
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Users');
},
};

52
src/dependencies.js Normal file
View file

@ -0,0 +1,52 @@
const express = require('express');
function buildDependencies() {
const dependencies = {};
const errors = require('./errors');
const constants = require('./constants');
const sequelize = require('./database/database');
const { DataTypes } = require('sequelize');
const ModelsProvider = require('./models');
const models = new ModelsProvider({ sequelize, DataTypes }).provide();
const AssociationsDefiner = require('./database/associations');
new AssociationsDefiner({ models, DataTypes }).define();
const ServicesProvider = require('./services');
const services = new ServicesProvider({
models,
constants,
errors,
sequelize,
}).provide();
dependencies.services = services;
const MiddlewaresProvider = require('./middlewares');
const middlewares = new MiddlewaresProvider({
constants,
sessionService: services.sessionService,
profileService: services.profileService,
}).provide();
dependencies.middlewares = middlewares;
const WebRoutesProvider = require('./routes/webRoutes');
const webRoutesProvider = new WebRoutesProvider({
express,
middlewares,
invitesService: services.invitesService,
});
dependencies.webRoutes = webRoutesProvider.provide();
const ApiRoutesProvider = require('./routes/apiRoutes');
const apiRoutesProvider = new ApiRoutesProvider({
express,
middlewares,
services,
errors,
});
dependencies.apiRoutes = apiRoutesProvider.provide();
return dependencies;
}
module.exports = { buildDependencies };

View file

@ -0,0 +1,58 @@
class BuyOrSellButtonGroup {
constructor({ parentElement, id }) {
this.element = null;
this.parentElement = parentElement;
this.id = id;
this.buyButton = null;
this.sellButton = null;
}
render() {
const groupDiv = document.createElement('div');
groupDiv.className = 'button-group';
groupDiv.id = this.id;
const buyButton = document.createElement('button');
buyButton.dataset.value = 'buy-bitcoin';
buyButton.id = 'button-buy-bitcoin';
buyButton.className = 'selected';
buyButton.textContent = 'Quiero comprar Bitcoin';
this.buyButton = buyButton;
const sellButton = document.createElement('button');
sellButton.dataset.value = 'sell-bitcoin';
sellButton.id = 'button-sell-bitcoin';
sellButton.textContent = 'Quiero vender Bitcoin';
this.sellButton = sellButton;
groupDiv.appendChild(this.buyButton);
groupDiv.appendChild(this.sellButton);
for (const button of [this.buyButton, this.sellButton]) {
button.addEventListener('click', () => {
[this.buyButton, this.sellButton].forEach((aButton) => {
if (aButton.classList.contains('selected')) {
aButton.classList.remove('selected');
} else {
aButton.classList.add('selected');
}
});
});
}
this.element = groupDiv;
this.parentElement.appendChild(this.element);
}
wants() {
if (this.buyButton.classList.contains('selected')) {
return 'BTC';
}
if (this.sellButton.classList.contains('selected')) {
return 'EUR';
}
}
}
module.exports = BuyOrSellButtonGroup;

View file

@ -0,0 +1,25 @@
class PopupNotification {
constructor({ parentElement, id, text }) {
this.element = null;
this.parentElement = parentElement;
this.id = id;
this.text = text;
}
render() {
const div = document.createElement('div');
div.id = this.id;
div.className = 'top-notification-good';
div.innerHTML = `<img src="/img/circle-check-white.svg" />
<p>${this.text}</p>`;
this.element = div;
this.parentElement.appendChild(div);
}
display() {
this.element.classList.add('revealed');
}
}
module.exports = PopupNotification;

View file

@ -0,0 +1,68 @@
class PremiumSelector {
constructor({ parentElement, id, eventSink }) {
this.element = null;
this.parentElement = parentElement;
this.id = id;
this.eventSink = eventSink;
this.premiumValue = null;
}
render() {
const premiumSelectorArea = document.createElement('div');
premiumSelectorArea.id = this.id;
const premiumValue = document.createElement('div');
premiumValue.id = 'premium-value';
premiumValue.textContent = '0%';
this.premiumValue = premiumValue;
const premiumButtonsContainer = document.createElement('div');
premiumButtonsContainer.id = 'premium-buttons-container';
const increaseButton = document.createElement('button');
increaseButton.classList.add('premium-button');
increaseButton.id = 'button-increase-premium';
increaseButton.textContent = '+';
const decreaseButton = document.createElement('button');
decreaseButton.classList.add('premium-button');
decreaseButton.id = 'button-decrease-premium';
decreaseButton.textContent = '-';
premiumButtonsContainer.appendChild(increaseButton);
premiumButtonsContainer.appendChild(decreaseButton);
premiumSelectorArea.appendChild(premiumValue);
premiumSelectorArea.appendChild(premiumButtonsContainer);
increaseButton.addEventListener('click', () => {
this.modifyPremiumValue(1);
});
decreaseButton.addEventListener('click', () => {
this.modifyPremiumValue(-1);
});
this.element = premiumSelectorArea;
this.parentElement.appendChild(this.element);
}
modifyPremiumValue(delta) {
const regexExpression = /-*\d+/;
const numValue = parseInt(
this.premiumValue.innerText.match(regexExpression)[0]
);
const newValue = `${numValue + delta}%`;
this.premiumValue.innerText = newValue;
this.eventSink.dispatchEvent(new Event('premium-changed'));
}
getPremium() {
return parseInt(this.premiumValue.textContent.match(/-?\d+/)[0]) / 100;
}
}
module.exports = PremiumSelector;

View file

@ -0,0 +1,64 @@
const formatNumberWithSpaces = require('../utils/formatNumbersWithSpaces');
class PriceDisplay {
constructor({
parentElement,
id,
premiumProvidingCallback,
priceProvidingCallback,
}) {
this.element = null;
this.parentElement = parentElement;
this.id = id;
this.premiumProvidingCallback = premiumProvidingCallback;
this.priceProvidingCallback = priceProvidingCallback;
}
render() {
const container = document.createElement('div');
container.id = 'premium-price-display-area';
const offerParagraph = document.createElement('p');
offerParagraph.id = 'offer-price-paragraph';
offerParagraph.textContent = 'Tu precio: ';
const offerSpan = document.createElement('span');
offerSpan.id = 'offer-price';
this.offerPriceSpan = offerSpan;
offerParagraph.appendChild(offerSpan);
offerParagraph.append('€/BTC');
const marketParagraph = document.createElement('p');
marketParagraph.id = 'market-price-paragraph';
marketParagraph.textContent = '(Precio mercado: ';
const marketSpan = document.createElement('span');
marketSpan.id = 'market-price';
this.marketPriceSpan = marketSpan;
marketParagraph.appendChild(marketSpan);
marketParagraph.append('€/BTC)');
container.appendChild(offerParagraph);
container.appendChild(marketParagraph);
this.updatePrices();
this.element = container;
this.parentElement.appendChild(this.element);
}
updatePrices() {
const marketPrice = this.priceProvidingCallback();
const marketPriceString = formatNumberWithSpaces(marketPrice);
const offerPriceString = formatNumberWithSpaces(
Math.round(marketPrice * (1 + this.premiumProvidingCallback()))
);
this.marketPriceSpan.innerText = marketPriceString;
this.offerPriceSpan.innerText = offerPriceString;
}
}
module.exports = PriceDisplay;

View file

@ -0,0 +1,21 @@
class PublishOfferButton {
constructor({ parentElement, id, onClickCallback }) {
this.element = null;
this.parentElement = parentElement;
this.id = id;
this.onClickCallback = onClickCallback;
}
render() {
const button = document.createElement('button');
button.id = this.id;
button.className = 'button-primary button-large';
button.innerText = 'Publicar oferta';
button.addEventListener('click', this.onClickCallback);
this.element = button;
this.parentElement.appendChild(this.element);
}
}
module.exports = PublishOfferButton;

View file

@ -0,0 +1,25 @@
class WarningDiv {
constructor({ parentElement, id, innerHTML }) {
this.element = null;
this.parentElement = parentElement;
this.id = id;
this.innerHTML = innerHTML;
}
render() {
const div = document.createElement('div');
div.id = this.id;
div.className = 'card-secondary';
div.style.display = 'none';
div.innerHTML = this.innerHTML;
this.element = div;
this.parentElement.appendChild(div);
}
display() {
this.element.style.display = 'block';
}
}
module.exports = WarningDiv;

View file

@ -0,0 +1,63 @@
class NostrButton {
constructor({ parentElement, id, onClickCallback, buttonText }) {
this.element = null;
this.parentElement = parentElement;
this.id = id;
this.onClickCallback = onClickCallback;
this.buttonText = buttonText;
}
render() {
const thisButton = document.createElement('button');
thisButton.id = this.id;
thisButton.type = 'submit';
thisButton.className = 'button-large button-nostr';
const figure = document.createElement('figure');
const img = document.createElement('img');
img.src = '/img/white_ostrich.svg';
img.style.width = '40%';
img.style.margin = '-5% -5%';
figure.appendChild(img);
const paragraph = document.createElement('p');
paragraph.textContent = this.buttonText;
thisButton.appendChild(figure);
thisButton.appendChild(paragraph);
thisButton.addEventListener('click', () => {
this.onClickCallback();
});
this.element = thisButton;
this.parentElement.appendChild(this.element);
}
disable() {
if (this.element) {
this.element.disabled = true;
}
}
}
class NostrSignupButton extends NostrButton {
constructor({ parentElement, id, onClickCallback }) {
super({ parentElement, id, onClickCallback, buttonText: 'Alta con Nostr' });
}
}
class NostrLoginButton extends NostrButton {
constructor({ parentElement, id, onClickCallback }) {
super({
parentElement,
id,
onClickCallback,
buttonText: 'Login con Nostr',
});
}
}
module.exports = { NostrSignupButton, NostrLoginButton };

View file

@ -0,0 +1,125 @@
const createProfilesFunction = () => {
const createProfileConfirmation = document.querySelector(
'#create-profile-success'
);
function debounce(func, wait) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
const validateNymInput = debounce(() => {
const nymValue = nymInput.value.trim();
const isValid = nymValue.length >= 3 && nymValue.length <= 128;
if (isValid) {
nymInputValidationWarning.style.display = 'none';
} else {
nymInputValidationWarning.style.display = 'block';
}
}, 500);
const checkIfSubmittable = debounce((allInputs) => {
const nymIsFilled = allInputs.nymInput.value !== '';
let atLeastOneContactIsFilled = false;
for (const contactInput of allInputs.contactInputs) {
if (contactInput.value !== '') {
atLeastOneContactIsFilled = true;
}
}
const buttonShouldBeDisabled = !(nymIsFilled && atLeastOneContactIsFilled);
submitProfileButton.disabled = buttonShouldBeDisabled;
}, 500);
async function createProfile(allInputs) {
const contactDetails = [];
for (const someInput of allInputs.contactInputs) {
contactDetails.push({
type: someInput.getAttribute('data-type'),
value: someInput.value,
});
}
const encryptedContactDetails = await window.nostr.nip04.encrypt(
await window.nostr.getPublicKey(),
JSON.stringify(contactDetails)
);
await fetch('/api/set-contact-details', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ encryptedContactDetails }),
});
const nym = allInputs.nymInput.value;
await fetch('/api/set-nym', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ nym }),
});
createProfileConfirmation.classList.add('revealed');
setTimeout(() => {
window.location.href = '/home';
}, 5000);
}
function onLoadErrands(allInputs, submitProfileButton) {
allInputs.nymInput.addEventListener('input', validateNymInput);
for (const someInput of allInputs.allInputs) {
someInput.addEventListener('input', () => {
checkIfSubmittable(allInputs);
});
}
checkIfSubmittable(allInputs);
submitProfileButton.addEventListener('click', () => {
createProfile(allInputs);
});
}
const nymInput = document.getElementById('nym-input');
const nymInputValidationWarning = document.getElementById(
'nym-input-validation-warning'
);
const phoneInput = document.getElementById('phone-input');
const whatsappInput = document.getElementById('whatsapp-input');
const telegramInput = document.getElementById('telegram-input');
const emailInput = document.getElementById('email-input');
const nostrInput = document.getElementById('nostr-input');
const signalInput = document.getElementById('signal-input');
const submitProfileButton = document.getElementById('submit-profile-button');
const allInputs = {
nymInput: nymInput,
contactInputs: [
phoneInput,
whatsappInput,
telegramInput,
emailInput,
nostrInput,
signalInput,
],
allInputs: [
nymInput,
phoneInput,
whatsappInput,
telegramInput,
emailInput,
nostrInput,
signalInput,
],
};
onLoadErrands(allInputs, submitProfileButton);
};
createProfilesFunction();

14
src/front/pages/home.js Normal file
View file

@ -0,0 +1,14 @@
const homeFunction = () => {
const navbuttonHome = document.getElementById('navbutton-home');
const navbuttonOffers = document.getElementById('navbutton-offers');
navbuttonHome.addEventListener('click', () => {
window.location.href = '/home';
});
navbuttonOffers.addEventListener('click', () => {
window.location.href = '/offers';
});
};
homeFunction();

110
src/front/pages/invite.js Normal file
View file

@ -0,0 +1,110 @@
const checkNostrExtension = require('../utils/checkNostrExtension');
const inviteService = require('../services/inviteService');
const constants = require('../../constants');
const { NostrSignupButton } = require('../components/nostrButtons');
const WarningDiv = require('../components/WarningDiv');
const PopupNotification = require('../components/PopupNotification');
const invitesFunction = () => {
const body = document.querySelector('body');
const warningsContainer = document.getElementById('warnings-container');
const nostrSignupArea = document.getElementById('nostr-signup-area');
const signupButton = new NostrSignupButton({
parentElement: nostrSignupArea,
id: 'nostr-signup-button',
onClickCallback: async () => {
const verifyResponse =
await inviteService.requestAndRespondSignUpChallenge({
onNostrErrorCallback: () => {
rejectedNostrWarning.display();
},
});
if (verifyResponse.ok) {
signUpSuccessPopup.display();
setTimeout(() => {
window.location.href = constants.API_PATHS.createProfile;
}, constants.DEFAULT_REDIRECT_DELAY);
}
},
});
signupButton.render();
const noExtensionWarning = new WarningDiv({
parentElement: warningsContainer,
id: 'no-extension-nudges',
innerHTML: `<p>
¡Atención! No se ha encontrado una extensión de Nostr en tu
navegador. Puedes usar:
</p>
<p><strong>Firefox</strong></p>
<p>
<a
href="https://addons.mozilla.org/en-US/firefox/addon/alby/"
target="_blank"
rel="noopener noreferrer"
>Alby</a
>
</p>
<p>
<a
href="https://addons.mozilla.org/en-US/firefox/addon/nos2x-fox/"
target="_blank"
rel="noopener noreferrer"
>nos2x-fox</a
>
</p>
<p><strong>Chrome</strong></p>
<p>
<a
href="https://chromewebstore.google.com/detail/alby-bitcoin-wallet-for-l/iokeahhehimjnekafflcihljlcjccdbe?pli=1"
target="_blank"
rel="noopener noreferrer"
>Alby</a
>
</p>
<p>
<a
href="https://chromewebstore.google.com/detail/nos2x/kpgefcfmnafjgpblomihpgmejjdanjjp"
target="_blank"
rel="noopener noreferrer"
>nos2x</a
>
</p>`,
});
noExtensionWarning.render();
const rejectedNostrWarning = new WarningDiv({
parentElement: warningsContainer,
id: 'rejected-nostr-nudges',
innerHTML: `<p>
Ups, parece que no has aceptado que usemos tus claves. Si te has
equivocado, puedes intentarlo de nuevo.
</p>`,
});
rejectedNostrWarning.render();
const signUpSuccessPopup = new PopupNotification({
parentElement: body,
id: 'sign-up-success',
text: '¡Bien! Hemos dado de alta tu clave de Nostr. Te vamos a redirigir a la seca, espera un momento.',
});
signUpSuccessPopup.render();
window.onload = () => {
checkNostrExtension({
window,
successCallback: () => {
console.log('Nostr extension present');
},
failureCallback: () => {
console.log('Nostr extension not present');
signupButton.disable();
noExtensionWarning.display();
},
});
};
};
invitesFunction();

127
src/front/pages/login.js Normal file
View file

@ -0,0 +1,127 @@
const checkNostrExtension = require('../utils/checkNostrExtension');
const loginService = require('../services/loginService');
const WarningDiv = require('../components/WarningDiv');
const { NostrLoginButton } = require('../components/nostrButtons');
const PopupNotification = require('../components/PopupNotification');
const constants = require('../../constants');
const loginFunction = () => {
const loginButtonArea = document.getElementById('login-button-area');
const warningsArea = document.getElementById('warnings-area');
const successPopup = new PopupNotification({
parentElement: document.querySelector('body'),
id: 'login-success-popup',
text: '¡Éxito! Te estamos llevando a la app...',
});
successPopup.render();
const nostrLoginButton = new NostrLoginButton({
parentElement: loginButtonArea,
id: 'login-button',
onClickCallback: async () => {
const verifyResponse = await loginService.requestAndRespondLoginChallenge(
{
onRejectedPubKeyCallback: () => {
nostrRejectedWarning.display();
},
onRejectedSignatureCallback: () => {
nostrRejectedWarning.display();
},
}
);
if (verifyResponse.status === 403) {
notRegisteredPubkeyWarning.display();
}
if (verifyResponse.ok) {
nostrLoginButton.disable();
successPopup.display();
setTimeout(() => {
window.location.href = constants.API_PATHS.home;
}, constants.DEFAULT_REDIRECT_DELAY);
}
},
});
nostrLoginButton.render();
const notRegisteredPubkeyWarning = new WarningDiv({
parentElement: warningsArea,
id: 'rejected-public-key',
innerHTML: `<p>
Ups, esa clave no está registrada en la seca. ¿Quizás estás usando un
perfil equivocado?
</p>`,
});
notRegisteredPubkeyWarning.render();
const noExtensionWarning = new WarningDiv({
parentElement: warningsArea,
id: 'no-extension-nudges',
innerHTML: `<p>
¡Atención! No se ha encontrado una extensión de Nostr en tu navegador.
Puedes usar:
</p>
<p><strong>Firefox</strong></p>
<p>
<a
href="https://addons.mozilla.org/en-US/firefox/addon/alby/"
target="_blank"
rel="noopener noreferrer"
>Alby</a
>
</p>
<p>
<a
href="https://addons.mozilla.org/en-US/firefox/addon/nos2x-fox/"
target="_blank"
rel="noopener noreferrer"
>nos2x-fox</a
>
</p>
<p><strong>Chrome</strong></p>
<p>
<a
href="https://chromewebstore.google.com/detail/alby-bitcoin-wallet-for-l/iokeahhehimjnekafflcihljlcjccdbe?pli=1"
target="_blank"
rel="noopener noreferrer"
>Alby</a
>
</p>
<p>
<a
href="https://chromewebstore.google.com/detail/nos2x/kpgefcfmnafjgpblomihpgmejjdanjjp"
target="_blank"
rel="noopener noreferrer"
>nos2x</a
>
</p>`,
});
noExtensionWarning.render();
const nostrRejectedWarning = new WarningDiv({
parentElement: warningsArea,
id: 'rejected-nostr-nudges',
innerHTML: `<p>
Ups, parece que no has aceptado que usemos tus claves. Si te has
equivocado, puedes intentarlo de nuevo.
</p>`,
});
nostrRejectedWarning.render();
window.onload = () => {
checkNostrExtension({
window,
successCallback: () => {
console.log('Nostr extension present');
},
failureCallback: () => {
console.log('Nostr extension not present');
nostrLoginButton.disable();
noExtensionWarning.display();
},
});
};
};
loginFunction();

694
src/front/pages/offers.js Normal file
View file

@ -0,0 +1,694 @@
const formatNumberWithSpaces = require('../utils/formatNumbersWithSpaces');
const PublishOfferButton = require('../components/PublishOfferButton');
const BuyOrSellButtonGroup = require('../components/BuyOrSellButtonGroup');
const PremiumSelector = require('../components/PremiumSelector');
const PriceDisplay = require('../components/PriceDisplay');
function offersPage() {
const createOfferEventBus = new EventTarget();
const publishOfferButton = new PublishOfferButton({
parentElement: document.getElementById('submit-button-area'),
id: 'button-submit-offer',
onClickCallback: async () => {
await publishOffer();
await myOffers.getOffersFromApi();
await myOffers.render();
},
});
publishOfferButton.render();
const buyOrSellButtonGroup = new BuyOrSellButtonGroup({
parentElement: document.getElementById('buy-or-sell-area'),
id: 'button-group-buy-or-sell',
});
buyOrSellButtonGroup.render();
const premiumSelector = new PremiumSelector({
parentElement: document.getElementById('premium-content-area'),
id: 'premium-selector-area',
eventSink: createOfferEventBus,
});
premiumSelector.render();
const priceDisplay = new PriceDisplay({
parentElement: document.getElementById('premium-content-area'),
id: 'premium-price-display-area',
premiumProvidingCallback: () => {
return premiumSelector.getPremium();
},
priceProvidingCallback: () => {
return Math.floor(Math.random() * (95000 - 70000 + 1) + 70000);
},
});
priceDisplay.render();
createOfferEventBus.addEventListener('premium-changed', () => {
priceDisplay.updatePrices();
});
// -----------
const navbuttonHome = document.getElementById('navbutton-home');
const navbuttonOffers = document.getElementById('navbutton-offers');
navbuttonHome.addEventListener('click', () => {
window.location.href = '/home';
});
navbuttonOffers.addEventListener('click', () => {
window.location.href = '/offers';
});
const buttonStartCreateOffer = document.getElementById(
'button-start-create-offer'
);
const buttonViewMyOffers = document.getElementById('button-view-my-offers');
const closeOffer = document.getElementById('close-offer');
const createOfferModalRoot = document.getElementById(
'create-offer-modal-root'
);
const viewMyOffersRoot = document.getElementById('view-my-offers-root');
const eurAmountInput = document.getElementById('input-eur-amount');
const btcAmountInput = document.getElementById('input-btc-amount');
const placeInput = document.getElementById('place-input');
const timeInput = document.getElementById('time-input');
const onchainCheckbox = document.getElementById('onchain-checkbox');
const lightningCheckbox = document.getElementById('lightning-checkbox');
const btcMethodCheckboxes = [onchainCheckbox, lightningCheckbox];
const myTrustedCheckbox = document.getElementById('my-trusted-checkbox');
const myTrustedTrustedCheckbox = document.getElementById(
'my-trusted-trusted-checkbox'
);
const allMembersCheckbox = document.getElementById('all-members-checkbox');
const bigNotesAcceptedCheckbox = document.getElementById(
'large-bills-checkbox'
);
const offerCreatedPopup = document.getElementById(
'offer-created-confirmation'
);
const offerDeletedPopup = document.getElementById(
'offer-deleted-confirmation'
);
const ownOffersContainer = document.getElementById('own-offers-container');
function toggleCreateOfferModal() {
createOfferModalRoot.classList.toggle('shown');
}
function toggleViewMyOffersPanel() {
viewMyOffersRoot.style.display =
viewMyOffersRoot.style.display === 'block' ? 'none' : 'block';
}
function readIntFromEurAmountInput() {
const eurAmountFieldValue = eurAmountInput.value;
const regularExpression = /([\d\s]+)/;
const matchResult = eurAmountFieldValue.match(regularExpression);
if (!matchResult) {
return null;
}
const numberString = matchResult[1];
const cleanInputNumber = parseInt(numberString.replace(/\s/gi, ''));
return cleanInputNumber;
}
function validateAndFormatEurAmountInput() {
const cleanInputNumber = readIntFromEurAmountInput();
eurAmountInput.classList.remove('input-is-valid', 'input-is-invalid');
if (cleanInputNumber) {
eurAmountInput.value = formatNumberWithSpaces(cleanInputNumber);
eurAmountInput.classList.add('input-is-valid');
return;
}
eurAmountInput.classList.add('input-is-invalid');
}
function updateBtcInput() {
const eurToSatRate = 1021;
const cleanEurAmount = readIntFromEurAmountInput();
const satsAmount = cleanEurAmount * eurToSatRate;
const formattedSatsAmount = formatNumberWithSpaces(satsAmount);
btcAmountInput.value = formattedSatsAmount;
}
function validateBitcoinMethodCheckboxes(clickedCheckbox) {
let checkedCount = btcMethodCheckboxes.filter((cb) => cb.checked).length;
if (checkedCount === 0) {
clickedCheckbox.checked = true;
}
}
function applyTrustCheckboxConstraints(pressedCheckbox) {
if (pressedCheckbox === myTrustedTrustedCheckbox) {
console.log('first case!');
if (!myTrustedTrustedCheckbox.checked && allMembersCheckbox.checked) {
allMembersCheckbox.checked = false;
}
}
if (pressedCheckbox === allMembersCheckbox) {
console.log('second case!');
if (!myTrustedTrustedCheckbox.checked && allMembersCheckbox.checked) {
myTrustedTrustedCheckbox.checked = true;
}
}
}
async function publishOffer() {
const wants = buyOrSellButtonGroup.wants();
const premium = premiumSelector.getPremium();
const trade_amount_eur = eurAmountInput.value;
const location_details = placeInput.value;
const time_availability_details = timeInput.value;
const is_onchain_accepted = onchainCheckbox.checked;
const is_lightning_accepted = lightningCheckbox.checked;
const show_offer_to_trusted = myTrustedCheckbox.checked;
const show_offer_to_trusted_trusted = myTrustedTrustedCheckbox.checked;
const show_offer_to_all_members = allMembersCheckbox.checked;
const are_big_notes_accepted = bigNotesAcceptedCheckbox.checked;
const offerDetails = {
wants,
premium,
trade_amount_eur,
location_details,
time_availability_details,
is_onchain_accepted,
is_lightning_accepted,
show_offer_to_trusted,
show_offer_to_trusted_trusted,
show_offer_to_all_members,
are_big_notes_accepted,
};
await fetch('/api/offer', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ offerDetails }),
});
toggleOfferCreatedAlert();
toggleCreateOfferModal();
}
function toggleOfferCreatedAlert() {
offerCreatedPopup.classList.remove('max-size-zero');
offerCreatedPopup.classList.add('revealed');
setTimeout(() => {
offerCreatedPopup.classList.remove('revealed');
}, 3000);
setTimeout(() => {
offerCreatedPopup.classList.add('max-size-zero');
}, 4000);
}
function toggleOfferDeletedAlert() {
offerDeletedPopup.classList.remove('max-size-zero');
offerDeletedPopup.classList.add('revealed');
setTimeout(() => {
offerDeletedPopup.classList.remove('revealed');
}, 3000);
setTimeout(() => {
offerDeletedPopup.classList.add('max-size-zero');
}, 4000);
}
class Offer {
constructor(offerData) {
this.uuid = offerData.uuid;
this.public_key = offerData.public_key;
this.wants = offerData.wants;
this.premium = offerData.premium;
this.trade_amount_eur = offerData.trade_amount_eur;
this.location_details = offerData.location_details;
this.time_availability_details = offerData.time_availability_details;
this.show_offer_to_trusted = offerData.show_offer_to_trusted;
this.show_offer_to_trusted_trusted =
offerData.show_offer_to_trusted_trusted;
this.show_offer_to_all_members = offerData.show_offer_to_all_members;
this.is_onchain_accepted = offerData.is_onchain_accepted;
this.is_lightning_accepted = offerData.is_lightning_accepted;
this.are_big_notes_accepted = offerData.are_big_notes_accepted;
this.created_at = offerData.created_at;
this.last_updated_at = offerData.last_updated_at;
}
buildHTML() {
const offerCard = document.createElement('div');
offerCard.classList.add('myoffer-card');
offerCard.classList.add('shadowed-round-area');
const tradeDescDiv = document.createElement('div');
tradeDescDiv.classList.add('trade-desc');
const youBuyText = document.createElement('p');
youBuyText.classList.add('offer-card-content-title');
youBuyText.innerText = 'Compras';
tradeDescDiv.append(youBuyText);
const youBuyData = document.createElement('p');
youBuyData.classList.add('offer-card-content-data');
if (this.wants === 'BTC') {
youBuyData.innerText = `${this.trade_amount_eur * 1021} sats`;
}
if (this.wants === 'EUR') {
youBuyData.innerText = `${this.trade_amount_eur}`;
}
tradeDescDiv.append(youBuyData);
const youSellText = document.createElement('p');
youSellText.id = 'you-sell-title';
youSellText.classList.add('offer-card-content-title');
youSellText.innerText = 'Vendes';
tradeDescDiv.append(youSellText);
const youSellData = document.createElement('p');
youSellData.classList.add('offer-card-content-data');
if (this.wants === 'BTC') {
youSellData.innerText = `${this.trade_amount_eur}`;
}
if (this.wants === 'EUR') {
youSellData.innerText = `${this.trade_amount_eur * 1021} sats`;
}
tradeDescDiv.append(youSellData);
const premiumDescDiv = document.createElement('div');
premiumDescDiv.classList.add('premium-desc');
const premiumTitle = document.createElement('p');
premiumTitle.classList.add('offer-card-content-title');
premiumTitle.innerText = 'Premium';
premiumDescDiv.append(premiumTitle);
const premiumData = document.createElement('p');
premiumData.classList.add('offer-card-content-data');
premiumData.innerText = `${this.premium * 100} %`;
premiumDescDiv.append(premiumData);
const offerPriceTitle = document.createElement('p');
offerPriceTitle.classList.add('offer-card-content-title');
offerPriceTitle.innerText = 'Precio oferta';
premiumDescDiv.append(offerPriceTitle);
const offerPriceData = document.createElement('p');
offerPriceData.classList.add('offer-card-content-data');
offerPriceData.innerText = `90000 €/BTC`;
premiumDescDiv.append(offerPriceData);
const marketPriceTitle = document.createElement('p');
marketPriceTitle.classList.add('offer-card-content-title');
marketPriceTitle.innerText = 'Precio mercado';
premiumDescDiv.append(marketPriceTitle);
const marketPriceData = document.createElement('p');
marketPriceData.innerText = `88000 €/BTC`;
premiumDescDiv.append(marketPriceData);
const whereDescDiv = document.createElement('div');
whereDescDiv.classList.add('where-desc');
const whereDescTitle = document.createElement('p');
whereDescTitle.classList.add('offer-card-content-title');
whereDescTitle.innerText = 'Dónde';
whereDescDiv.append(whereDescTitle);
const whereDescData = document.createElement('p');
whereDescData.classList.add('offer-long-text');
whereDescData.innerText = `${this.location_details}`;
whereDescDiv.append(whereDescData);
const whenDescDiv = document.createElement('div');
whenDescDiv.classList.add('when-desc');
const whenDescTitle = document.createElement('p');
whenDescTitle.classList.add('offer-card-content-title');
whenDescTitle.innerText = 'Cúando';
whenDescDiv.append(whenDescTitle);
const whenDescData = document.createElement('p');
whenDescData.classList.add('offer-long-text');
whenDescData.innerText = `${this.time_availability_details}`;
whenDescDiv.append(whenDescData);
const bitcoinMethodsDiv = document.createElement('div');
bitcoinMethodsDiv.classList.add('bitcoin-methods-desc');
const bitcoinMethodsTitle = document.createElement('p');
bitcoinMethodsTitle.classList.add('offer-card-content-title');
bitcoinMethodsTitle.innerText = 'Protocolos Bitcoin aceptados';
bitcoinMethodsDiv.append(bitcoinMethodsTitle);
const onchainAcceptedContainer = document.createElement('div');
onchainAcceptedContainer.classList.add('left-icon-checkboxed-field');
if (this.is_onchain_accepted) {
const onchainIcon = document.createElement('img');
onchainIcon.src = '/img/chains-lasecagold.svg';
const onchainText = document.createElement('p');
onchainText.innerText = 'Onchain';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-check-green.svg';
onchainAcceptedContainer.append(onchainIcon, onchainText, checkIcon);
} else {
const onchainIcon = document.createElement('img');
onchainIcon.src = '/img/chains-gray.svg';
const onchainText = document.createElement('p');
onchainText.innerText = 'Onchain';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-xmark-gray.svg';
onchainAcceptedContainer.append(onchainIcon, onchainText, checkIcon);
}
const lightningAcceptedContainer = document.createElement('div');
lightningAcceptedContainer.classList.add('left-icon-checkboxed-field');
if (this.is_lightning_accepted) {
const lightningIcon = document.createElement('img');
lightningIcon.src = '/img/bolt-lightning-lasecagold.svg';
const lightningText = document.createElement('p');
lightningText.innerText = 'Lightning';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-check-green.svg';
lightningAcceptedContainer.append(
lightningIcon,
lightningText,
checkIcon
);
} else {
const lightningIcon = document.createElement('img');
lightningIcon.src = '/img/bolt-lightning-gray.svg';
const lightningText = document.createElement('p');
lightningText.innerText = 'Lightning';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-xmark-gray.svg';
lightningAcceptedContainer.append(
lightningIcon,
lightningText,
checkIcon
);
}
bitcoinMethodsDiv.append(
onchainAcceptedContainer,
lightningAcceptedContainer
);
const visibilityDiv = document.createElement('div');
visibilityDiv.classList.add('visibility-desc');
const visibilityTitle = document.createElement('p');
visibilityTitle.classList.add('offer-card-content-title');
visibilityTitle.innerText = 'Visibilidad';
visibilityDiv.append(visibilityTitle);
const showOfferToTrustedContainer = document.createElement('div');
showOfferToTrustedContainer.classList.add('right-icon-checkboxed-field');
if (this.show_offer_to_trusted) {
const showOfferToTrustedIcon = document.createElement('img');
showOfferToTrustedIcon.src = '/img/user-lasecagold.svg';
const showOfferToTrustedText = document.createElement('p');
showOfferToTrustedText.innerText = 'Confiados';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-check-green.svg';
showOfferToTrustedContainer.append(
showOfferToTrustedIcon,
showOfferToTrustedText,
checkIcon
);
} else {
const showOfferToTrustedIcon = document.createElement('img');
showOfferToTrustedIcon.src = '/img/user-gray.svg';
const showOfferToTrustedText = document.createElement('p');
showOfferToTrustedText.innerText = 'Confiados';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-xmark-gray.svg';
showOfferToTrustedContainer.append(
showOfferToTrustedIcon,
showOfferToTrustedText,
checkIcon
);
}
const showOfferToTrustedTrustedContainer = document.createElement('div');
showOfferToTrustedTrustedContainer.classList.add(
'right-icon-checkboxed-field'
);
if (this.show_offer_to_trusted_trusted) {
const showOfferToTrustedTrustedIcon = document.createElement('img');
showOfferToTrustedTrustedIcon.src = '/img/user-group-lasecagold.svg';
const showOfferToTrustedTrustedText = document.createElement('p');
showOfferToTrustedTrustedText.innerText = 'Sus confiados';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-check-green.svg';
showOfferToTrustedTrustedContainer.append(
showOfferToTrustedTrustedIcon,
showOfferToTrustedTrustedText,
checkIcon
);
} else {
const showOfferToTrustedTrustedIcon = document.createElement('img');
showOfferToTrustedTrustedIcon.src = '/img/user-group-gray.svg';
const showOfferToTrustedTrustedText = document.createElement('p');
showOfferToTrustedTrustedText.innerText = 'Sus confiados';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-xmark-gray.svg';
showOfferToTrustedTrustedContainer.append(
showOfferToTrustedTrustedIcon,
showOfferToTrustedTrustedText,
checkIcon
);
}
const showOfferToAllMembersContainer = document.createElement('div');
showOfferToAllMembersContainer.classList.add(
'right-icon-checkboxed-field'
);
if (this.show_offer_to_all_members) {
const showOfferToAllMembersIcon = document.createElement('img');
showOfferToAllMembersIcon.src = '/img/many-users-lasecagold.svg';
const showOfferToAllMembersText = document.createElement('p');
showOfferToAllMembersText.innerText = 'Todos';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-check-green.svg';
showOfferToAllMembersContainer.append(
showOfferToAllMembersIcon,
showOfferToAllMembersText,
checkIcon
);
} else {
const showOfferToAllMembersIcon = document.createElement('img');
showOfferToAllMembersIcon.src = '/img/many-users-gray.svg';
const showOfferToAllMembersText = document.createElement('p');
showOfferToAllMembersText.innerText = 'Todos';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-xmark-gray.svg';
showOfferToAllMembersContainer.append(
showOfferToAllMembersIcon,
showOfferToAllMembersText,
checkIcon
);
}
visibilityDiv.append(
showOfferToTrustedContainer,
showOfferToTrustedTrustedContainer,
showOfferToAllMembersContainer
);
const otherOfferFeaturesDiv = document.createElement('div');
otherOfferFeaturesDiv.classList.add('other-desc');
const otherOfferFeaturesTitle = document.createElement('p');
otherOfferFeaturesTitle.classList.add('offer-card-content-title');
otherOfferFeaturesTitle.innerText = 'Otros';
otherOfferFeaturesDiv.append(otherOfferFeaturesTitle);
const areBigNotesAcceptedContainer = document.createElement('div');
areBigNotesAcceptedContainer.classList.add('left-icon-checkboxed-field');
if (this.are_big_notes_accepted) {
const areBigNotesAcceptedIcon = document.createElement('img');
areBigNotesAcceptedIcon.src = '/img/eur-bill-lasecagold.svg';
const areBigNotesAcceptedText = document.createElement('p');
areBigNotesAcceptedText.innerText = 'Billetes grandes';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-check-green.svg';
areBigNotesAcceptedContainer.append(
areBigNotesAcceptedIcon,
areBigNotesAcceptedText,
checkIcon
);
} else {
const areBigNotesAcceptedIcon = document.createElement('img');
areBigNotesAcceptedIcon.src = '/img/eur-bill-gray.svg';
const areBigNotesAcceptedText = document.createElement('p');
areBigNotesAcceptedText.innerText = 'Billetes grandes';
const checkIcon = document.createElement('img');
checkIcon.src = '/img/circle-xmark-gray.svg';
areBigNotesAcceptedContainer.append(
areBigNotesAcceptedIcon,
areBigNotesAcceptedText,
checkIcon
);
}
otherOfferFeaturesDiv.append(areBigNotesAcceptedContainer);
const actionButtonsArea = document.createElement('p');
actionButtonsArea.classList.add('offer-action-buttons-area');
const editActionArea = document.createElement('div');
editActionArea.classList.add('offer-action-area');
editActionArea.classList.add('subtle-box');
const editActionIcon = document.createElement('img');
editActionIcon.src = '/img/edit.svg';
const editActionText = document.createElement('p');
editActionText.innerText = 'Editar';
editActionArea.append(editActionIcon, editActionText);
const deleteActionArea = document.createElement('div');
deleteActionArea.classList.add('offer-action-area');
deleteActionArea.classList.add('subtle-box');
const deleteActionIcon = document.createElement('img');
deleteActionIcon.src = '/img/trash-can-darkred.svg';
const deleteActionText = document.createElement('p');
deleteActionText.innerText = 'Eliminar';
deleteActionArea.append(deleteActionIcon, deleteActionText);
deleteActionArea.addEventListener('click', async () => {
await deleteOfferByUuid(this.uuid);
await myOffers.getOffersFromApi();
await myOffers.render();
toggleOfferDeletedAlert();
});
actionButtonsArea.append(editActionArea, deleteActionArea);
offerCard.append(
tradeDescDiv,
premiumDescDiv,
whereDescDiv,
whenDescDiv,
bitcoinMethodsDiv,
visibilityDiv,
otherOfferFeaturesDiv,
actionButtonsArea
);
return offerCard;
}
}
class MyOffers {
constructor(ownOffersContainerElement) {
this.ownOffersContainerElement = ownOffersContainerElement;
this.offers = [];
}
async getOffersFromApi() {
const offersResponse = await fetch('/api/publickey-offers');
this.offers = [];
const offersData = (await offersResponse.json()).data;
if (offersResponse.ok) {
for (const record of offersData) {
this.offers.push(new Offer(record));
}
}
}
async render() {
if (this.offers.length === 0) {
this.ownOffersContainerElement.innerHTML =
'<p class="shadowed-round-area">Vaya, no hay nada por aquí...</p>';
return;
}
this.ownOffersContainerElement.innerHTML = '';
for (const someOffer of this.offers) {
this.ownOffersContainerElement.append(someOffer.buildHTML());
}
}
}
async function deleteOfferByUuid(offerUuid) {
await fetch(`/api/offer/${offerUuid}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
});
}
buttonStartCreateOffer.addEventListener('click', () => {
toggleCreateOfferModal();
});
buttonViewMyOffers.addEventListener('click', async () => {
await myOffers.getOffersFromApi();
await myOffers.render();
toggleViewMyOffersPanel();
});
closeOffer.addEventListener('click', () => {
toggleCreateOfferModal();
});
eurAmountInput.addEventListener('blur', () => {
validateAndFormatEurAmountInput();
updateBtcInput();
});
eurAmountInput.addEventListener('input', () => {
eurAmountInput.value = eurAmountInput.value.replace(/[^0-9]/g, '');
updateBtcInput();
});
for (const btcMethodCheckbox of btcMethodCheckboxes) {
btcMethodCheckbox.addEventListener('click', () => {
validateBitcoinMethodCheckboxes(btcMethodCheckbox);
});
}
myTrustedTrustedCheckbox.addEventListener('click', () => {
applyTrustCheckboxConstraints(myTrustedTrustedCheckbox);
});
allMembersCheckbox.addEventListener('click', () => {
applyTrustCheckboxConstraints(allMembersCheckbox);
});
updateBtcInput();
const myOffers = new MyOffers(ownOffersContainer);
}
offersPage();

View file

@ -1,23 +1,4 @@
window.onload = function () {
if (!window.nostr) {
console.log('Nostr extension not present');
document.querySelector('#nostr-signup-button').disabled = true;
document.querySelector('#no-extension-nudges').style.display = 'block';
} else {
console.log('Nostr extension present');
}
};
const signUpConfirmation = document.querySelector('#sign-up-success');
function showConfirmationAndRedirect() {
signUpConfirmation.classList.add('revealed');
setTimeout(() => {
window.location.href = '/createProfile';
}, 5000);
}
async function acceptInvite() {
const requestAndRespondSignUpChallenge = async ({ onNostrErrorCallback }) => {
let challengeResponse;
try {
challengeResponse = await fetch('/api/signup/nostr-challenge', {
@ -37,7 +18,7 @@ async function acceptInvite() {
try {
pubkey = await window.nostr.getPublicKey();
} catch (error) {
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
onNostrErrorCallback();
return;
}
const event = {
@ -52,7 +33,7 @@ async function acceptInvite() {
try {
signedEvent = await window.nostr.signEvent(event);
} catch (error) {
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
onNostrErrorCallback();
return;
}
@ -68,7 +49,9 @@ async function acceptInvite() {
return;
}
if (verifyResponse.ok) {
showConfirmationAndRedirect();
}
}
return verifyResponse;
};
module.exports = {
requestAndRespondSignUpChallenge,
};

View file

@ -1,14 +1,12 @@
window.onload = function () {
if (!window.nostr) {
console.log('Nostr extension not present');
document.querySelector('#login-button').disabled = true;
document.querySelector('#no-extension-nudges').style.display = 'block';
} else {
console.log('Nostr extension present');
}
};
const requestAndRespondLoginChallenge = async ({
onRejectedPubKeyCallback,
onRejectedSignatureCallback,
}) => {
onRejectedPubKeyCallback = () => {
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
};
onRejectedSignatureCallback = onRejectedPubKeyCallback;
async function login() {
let challengeResponse;
try {
challengeResponse = await fetch('/api/login/nostr-challenge', {
@ -28,7 +26,7 @@ async function login() {
try {
pubkey = await window.nostr.getPublicKey();
} catch (error) {
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
onRejectedPubKeyCallback();
return;
}
const event = {
@ -43,7 +41,7 @@ async function login() {
try {
signedEvent = await window.nostr.signEvent(event);
} catch (error) {
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
onRejectedSignatureCallback();
return;
}
@ -59,14 +57,9 @@ async function login() {
return;
}
if (verifyResponse.status === 403) {
document.querySelector('#rejected-public-key').style.display = 'block';
}
return verifyResponse;
};
if (verifyResponse.ok) {
document.querySelector('#sign-up-success').style.display = 'block';
setTimeout(() => {
window.location.href = '/home';
}, 1000);
}
}
module.exports = {
requestAndRespondLoginChallenge,
};

View file

@ -0,0 +1,9 @@
function checkNostrExtension({ window, successCallback, failureCallback }) {
if (!window.nostr) {
failureCallback();
} else {
successCallback();
}
}
module.exports = checkNostrExtension;

View file

@ -1,3 +1,5 @@
function formatNumberWithSpaces(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
}
module.exports = formatNumberWithSpaces;

View file

@ -1,7 +1,11 @@
const sessionService = require('../services/sessionService');
class AttachPublicKeyMiddlewareProvider {
constructor({ sessionService }) {
this.sessionService = sessionService;
}
async function attachPublicKeyMiddleware(req, res, next) {
const publicKey = await sessionService.getPublicKeyRelatedToSession(
provide() {
return async (req, res, next) => {
const publicKey = await this.sessionService.getPublicKeyRelatedToSession(
req.cookies.sessionUuid
);
@ -9,6 +13,8 @@ async function attachPublicKeyMiddleware(req, res, next) {
req.cookies.publicKey = publicKey;
}
next();
};
}
}
module.exports = attachPublicKeyMiddleware;
module.exports = AttachPublicKeyMiddlewareProvider;

View file

@ -0,0 +1,39 @@
const uuid = require('uuid');
class CreateSessionMiddlewareProvider {
constructor({ constants, sessionService }) {
this.constants = constants;
this.sessionService = sessionService;
}
provide() {
return async (req, res, next) => {
const sessionUuid = req.cookies.sessionUuid;
if (!sessionUuid) {
const newSession = await this.setAndPersistNewSession(res);
req.cookies.sessionUuid = newSession.uuid;
}
if (sessionUuid) {
if (!(await this.sessionService.isSessionValid(sessionUuid))) {
const newSession = await this.setAndPersistNewSession(res);
req.cookies.sessionUuid = newSession.uuid;
}
}
next();
};
}
async setAndPersistNewSession(res) {
const sessionUuid = uuid.v7();
res.cookie('sessionUuid', sessionUuid, {
httpOnly: true,
maxAge: this.constants.DEFAULT_SESSION_DURATION_SECONDS * 1000,
});
return await this.sessionService.createSession(sessionUuid);
}
}
module.exports = CreateSessionMiddlewareProvider;

55
src/middlewares/index.js Normal file
View file

@ -0,0 +1,55 @@
class MiddlewaresProvider {
constructor({ constants, sessionService, profileService }) {
this.constants = constants;
this.sessionService = sessionService;
this.profileService = profileService;
}
provide() {
const AttachPublicKeyMiddlewareProvider = require('./attachPublicKeyMiddleware');
const attachPublicKeyMiddleware = new AttachPublicKeyMiddlewareProvider({
sessionService: this.sessionService,
}).provide();
const CreateSessionMiddlewareProvider = require('./createSessionMiddleware');
const createSessionMiddleware = new CreateSessionMiddlewareProvider({
constants: this.constants,
sessionService: this.sessionService,
}).provide();
const RejectIfNotAuthorizedMiddleware = require('./rejectIfNotAuthorizedMiddleware');
const rejectIfNotAuthorizedMiddleware = new RejectIfNotAuthorizedMiddleware(
{
sessionService: this.sessionService,
}
).provide();
const RedirectHomeIfAuthorized = require('./redirectHomeIfAuthorized');
const redirectHomeIfAuthorized = new RedirectHomeIfAuthorized({
sessionService: this.sessionService,
}).provide();
const RedirectIfNotAuthorizedMiddleware = require('./redirectIfNotAuthorizedMiddleware');
const redirectIfNotAuthorizedMiddleware =
new RedirectIfNotAuthorizedMiddleware({
sessionService: this.sessionService,
}).provide();
const RedirectIfMissingProfileDetailsMiddleware = require('./redirectIfMissingProfileDetailsMiddleware');
const redirectIfMissingProfileDetailsMiddleware =
new RedirectIfMissingProfileDetailsMiddleware({
profileService: this.profileService,
}).provide();
return {
redirectIfNotAuthorizedMiddleware,
attachPublicKeyMiddleware,
redirectIfMissingProfileDetailsMiddleware,
redirectHomeIfAuthorized,
rejectIfNotAuthorizedMiddleware,
createSessionMiddleware,
};
}
}
module.exports = MiddlewaresProvider;

View file

@ -1,10 +1,18 @@
const sessionService = require('../services/sessionService');
class RedirectHomeIfAuthorized {
constructor({ sessionService }) {
this.sessionService = sessionService;
}
async function redirectHomeIfAuthorized(req, res, next) {
if (await sessionService.isSessionAuthorized(req.cookies.sessionUuid)) {
provide() {
return async (req, res, next) => {
if (
await this.sessionService.isSessionAuthorized(req.cookies.sessionUuid)
) {
return res.redirect('/home');
}
next();
};
}
}
module.exports = redirectHomeIfAuthorized;
module.exports = RedirectHomeIfAuthorized;

View file

@ -1,12 +1,17 @@
const profileService = require('../services/profileService');
class RedirectIfMissingProfileDetailsMiddleware {
constructor({ profileService }) {
this.profileService = profileService;
}
async function redirectIfMissingProfileDetailsMiddleware(req, res, next) {
provide() {
return async (req, res, next) => {
const publicKey = req.cookies.publicKey;
if (!(await profileService.areProfileDetailsComplete(publicKey))) {
if (!(await this.profileService.areProfileDetailsComplete(publicKey))) {
res.redirect('/createProfile');
}
next();
};
}
}
module.exports = redirectIfMissingProfileDetailsMiddleware;
module.exports = RedirectIfMissingProfileDetailsMiddleware;

View file

@ -1,10 +1,20 @@
const sessionService = require('../services/sessionService');
class RedirectIfNotAuthorizedMiddleware {
constructor({ sessionService }) {
this.sessionService = sessionService;
}
async function redirectIfNotAuthorizedMiddleware(req, res, next) {
if (!(await sessionService.isSessionAuthorized(req.cookies.sessionUuid))) {
provide() {
return async (req, res, next) => {
if (
!(await this.sessionService.isSessionAuthorized(
req.cookies.sessionUuid
))
) {
return res.redirect('/login');
}
next();
};
}
}
module.exports = redirectIfNotAuthorizedMiddleware;
module.exports = RedirectIfNotAuthorizedMiddleware;

View file

@ -1,13 +1,23 @@
const sessionService = require('../services/sessionService');
class RejectIfNotAuthorizedMiddleware {
constructor({ sessionService }) {
this.sessionService = sessionService;
}
async function rejectIfNotAuthorizedMiddleware(req, res, next) {
if (!(await sessionService.isSessionAuthorized(req.cookies.sessionUuid))) {
provide() {
return async (req, res, next) => {
if (
!(await this.sessionService.isSessionAuthorized(
req.cookies.sessionUuid
))
) {
return res.status(403).json({
success: false,
message: 'Your session is not authorized.',
});
}
next();
};
}
}
module.exports = rejectIfNotAuthorizedMiddleware;
module.exports = RejectIfNotAuthorizedMiddleware;

View file

@ -1,33 +0,0 @@
const uuid = require('uuid');
const sessionService = require('../services/sessionService');
const constants = require('../constants');
async function setAndPersistNewSession(res) {
const sessionUuid = uuid.v7();
res.cookie('sessionUuid', sessionUuid, {
httpOnly: true,
maxAge: constants.DEFAULT_SESSION_DURATION_SECONDS * 1000,
});
return await sessionService.createSession(sessionUuid);
}
async function createSessionMiddleware(req, res, next) {
const sessionUuid = req.cookies.sessionUuid;
if (!sessionUuid) {
const newSession = await setAndPersistNewSession(res);
req.cookies.sessionUuid = newSession.uuid;
}
if (sessionUuid) {
if (!(await sessionService.isSessionValid(sessionUuid))) {
const newSession = await setAndPersistNewSession(res);
req.cookies.sessionUuid = newSession.uuid;
}
}
next();
}
module.exports = createSessionMiddleware;

View file

@ -1,27 +1,34 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class AppInviteCreatedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const AppInviteCreated = sequelize.define(
provide() {
const AppInviteCreated = this.sequelize.define(
'AppInviteCreated',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
inviter_pub_key: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'app_invite_created',
}
);
);
return AppInviteCreated;
}
}
module.exports = AppInviteCreated;
module.exports = AppInviteCreatedProvider;

View file

@ -1,31 +1,38 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class ContactDetailsSetProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const ContactDetailsSet = sequelize.define(
provide() {
const ContactDetailsSet = this.sequelize.define(
'ContactDetailsSet',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
public_key: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
},
encrypted_contact_details: {
type: DataTypes.TEXT,
type: this.DataTypes.TEXT,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'contact_details_set',
}
);
);
return ContactDetailsSet;
}
}
module.exports = ContactDetailsSet;
module.exports = ContactDetailsSetProvider;

View file

@ -1,31 +1,38 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class LoginChallengeCompletedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const LoginChallengeCompleted = sequelize.define(
provide() {
const LoginChallengeCompleted = this.sequelize.define(
'LoginChallengeCompleted',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
nostr_challenge_completed_uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
},
public_key: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'login_challenge_completed',
}
);
);
return LoginChallengeCompleted;
}
}
module.exports = LoginChallengeCompleted;
module.exports = LoginChallengeCompletedProvider;

View file

@ -1,27 +1,34 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class LoginChallengeCreatedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const LoginChallengeCreated = sequelize.define(
provide() {
const LoginChallengeCreated = this.sequelize.define(
'LoginChallengeCreated',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
nostr_challenge_uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'login_challenge_created',
}
);
);
return LoginChallengeCreated;
}
}
module.exports = LoginChallengeCreated;
module.exports = LoginChallengeCreatedProvider;

View file

@ -1,35 +1,43 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class NostrChallengeCompletedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const NostrChallengeCompleted = sequelize.define(
provide() {
const NostrChallengeCompleted = this.sequelize.define(
'NostrChallengeCompleted',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
challenge: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
unique: true,
},
signed_event: {
type: DataTypes.JSONB,
type: this.DataTypes.JSONB,
allowNull: false,
},
public_key: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'nostr_challenge_completed',
}
);
);
return NostrChallengeCompleted;
}
}
module.exports = NostrChallengeCompleted;
module.exports = NostrChallengeCompletedProvider;

View file

@ -1,31 +1,39 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class NostrChallengeCreatedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const NostrChallengeCreated = sequelize.define(
provide() {
const NostrChallengeCreated = this.sequelize.define(
'NostrChallengeCreated',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
challenge: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
unique: true,
},
expires_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'nostr_challenge_created',
}
);
);
return NostrChallengeCreated;
}
}
module.exports = NostrChallengeCreated;
module.exports = NostrChallengeCreatedProvider;

View file

@ -1,31 +1,38 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class NymSetProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const NymSet = sequelize.define(
provide() {
const NymSet = this.sequelize.define(
'NymSet',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
public_key: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
},
nym: {
type: DataTypes.TEXT,
type: this.DataTypes.TEXT,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'nym_set',
}
);
);
return NymSet;
}
}
module.exports = NymSet;
module.exports = NymSetProvider;

View file

@ -1,27 +1,34 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class OfferCreatedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const OfferCreated = sequelize.define(
provide() {
const OfferCreated = this.sequelize.define(
'OfferCreated',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
public_key: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'offer_created',
}
);
);
return OfferCreated;
}
}
module.exports = OfferCreated;
module.exports = OfferCreatedProvider;

View file

@ -0,0 +1,34 @@
class OfferDeletedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
provide() {
const OfferDeleted = this.sequelize.define(
'OfferDeleted',
{
uuid: {
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
offer_uuid: {
type: this.DataTypes.UUID,
allowNull: false,
},
created_at: {
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'offer_deleted',
}
);
return OfferDeleted;
}
}
module.exports = OfferDeletedProvider;

View file

@ -1,71 +1,78 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class OfferDetailsSetProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const OfferDetailsSet = sequelize.define(
provide() {
const OfferDetailsSet = this.sequelize.define(
'OfferDetailsSet',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
offer_uuid: {
type: DataTypes.STRING,
type: this.DataTypes.UUID,
allowNull: false,
},
wants: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
},
premium: {
type: DataTypes.DECIMAL(5, 2),
type: this.DataTypes.DECIMAL(5, 2),
allowNull: false,
},
trade_amount_eur: {
type: DataTypes.INTEGER,
type: this.DataTypes.INTEGER,
allowNull: false,
},
location_details: {
type: DataTypes.TEXT,
type: this.DataTypes.TEXT,
allowNull: false,
},
time_availability_details: {
type: DataTypes.TEXT,
type: this.DataTypes.TEXT,
allowNull: false,
},
show_offer_to_trusted: {
type: DataTypes.BOOLEAN,
type: this.DataTypes.BOOLEAN,
allowNull: false,
},
show_offer_to_trusted_trusted: {
type: DataTypes.BOOLEAN,
type: this.DataTypes.BOOLEAN,
allowNull: false,
},
show_offer_to_all_members: {
type: DataTypes.BOOLEAN,
type: this.DataTypes.BOOLEAN,
allowNull: false,
},
is_onchain_accepted: {
type: DataTypes.BOOLEAN,
type: this.DataTypes.BOOLEAN,
allowNull: false,
},
is_lightning_accepted: {
type: DataTypes.BOOLEAN,
type: this.DataTypes.BOOLEAN,
allowNull: false,
},
are_big_notes_accepted: {
type: DataTypes.BOOLEAN,
type: this.DataTypes.BOOLEAN,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'offer_details_set',
}
);
);
return OfferDetailsSet;
}
}
module.exports = OfferDetailsSet;
module.exports = OfferDetailsSetProvider;

View file

@ -1,27 +1,34 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class SessionCreatedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const SessionCreated = sequelize.define(
provide() {
const SessionCreated = this.sequelize.define(
'SessionCreated',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
expires_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'session_created',
}
);
);
return SessionCreated;
}
}
module.exports = SessionCreated;
module.exports = SessionCreatedProvider;

View file

@ -1,31 +1,37 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class SessionRelatedToPublickeyProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const SessionRelatedToPublickey = sequelize.define(
provide() {
const SessionRelatedToPublickey = this.sequelize.define(
'SessionRelatedToPublickey',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
session_uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
},
public_key: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'session_related_to_public_key',
}
);
module.exports = SessionRelatedToPublickey;
);
return SessionRelatedToPublickey;
}
}
module.exports = SessionRelatedToPublickeyProvider;

View file

@ -1,35 +1,42 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class SignUpChallengeCompletedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const SignUpChallengeCompleted = sequelize.define(
provide() {
const SignUpChallengeCompleted = this.sequelize.define(
'SignUpChallengeCompleted',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
nostr_challenge_completed_uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
},
app_invite_uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
},
public_key: {
type: DataTypes.STRING,
type: this.DataTypes.STRING,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'sign_up_challenge_completed',
}
);
);
return SignUpChallengeCompleted;
}
}
module.exports = SignUpChallengeCompleted;
module.exports = SignUpChallengeCompletedProvider;

View file

@ -1,31 +1,39 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../database');
class SignUpChallengeCreatedProvider {
constructor({ sequelize, DataTypes }) {
this.sequelize = sequelize;
this.DataTypes = DataTypes;
}
const SignUpChallengeCreated = sequelize.define(
provide() {
const SignUpChallengeCreated = this.sequelize.define(
'SignUpChallengeCreated',
{
uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
unique: true,
primaryKey: true,
},
nostr_challenge_uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
},
app_invite_uuid: {
type: DataTypes.UUID,
type: this.DataTypes.UUID,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
type: this.DataTypes.DATE,
allowNull: false,
},
},
{
tableName: 'sign_up_challenge_created',
}
);
);
module.exports = SignUpChallengeCreated;
return SignUpChallengeCreated;
}
}
module.exports = SignUpChallengeCreatedProvider;

Some files were not shown because too many files have changed in this diff Show more