Skip to content

Commit 5c22fbf

Browse files
authored
Merge pull request #180 from StatelessStudio/v2.1.0
[3.0.0] Jun-20-2019
2 parents b503e1d + 1a7a9d8 commit 5c22fbf

108 files changed

Lines changed: 1083 additions & 1178 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22
node_js:
3-
- "10.13.0"
3+
- "10.15.3"
44
before_script:
55
- psql -c 'create database testdb;' -U postgres
66
- cp local.config.travis.json local.config.json

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# PointyApi Changelog
22

3+
## [3.0.0] Jun-20-2019
4+
5+
### Breaking Changes (See migration.md)
6+
- [Issue #179] Swap http expect & token param
7+
- Removed database error handler
8+
- Changed `refreshToken` to `__refreshToken` in post endpoints
9+
- Changed `CLIENT_URL` to `ALLOW_ORIGIN`
10+
11+
### Additions
12+
- Added jwtBearer::sign argument
13+
- Added pointy::testmode
14+
- Added new ipc message test
15+
- Added ExampleUser class
16+
- Added ready-check prior to starting server
17+
- Added BaseDb::conn
18+
- Moved Postgres members to BaseDB
19+
20+
### Fixes
21+
- Error handling
22+
- Fixed a bug which mixed up `JWT_TTL` and `JWT_REFRESH_TTL`
23+
- runHook should log error
24+
- patchEndpoint should merge payload after patch hook
25+
- Login endpoint should check validation
26+
- npm update
27+
- Simplified login endpoint
28+
- Fixed default entities bug
29+
- Moved "server-ready" ipc from listen() to pointy::start()
30+
331
## [2.0.0] Jun-06-2019
432

533
### Breaking Changes (See migration.md)

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ npm i pointyapi
157157
.setEntities(
158158
[
159159
/* TODO: We will set our models here */
160+
ExampleUser
160161
]
161162
)
162163
.connect(ROOT_PATH)
@@ -168,7 +169,7 @@ npm i pointyapi
168169
```
169170
3. **Create a user route**
170171

171-
By default, PointyAPI will use `BaseUser` as the user model. Let's create a route for this model, so that we can access this model through our API:
172+
By default, PointyAPI will use `ExampleUser` as the user model. Let's create a route for this model, so that we can access this model through our API:
172173
- Create a folder for routes, `src/routes/`
173174
- Create a new router file, `src/routes/user.ts`
174175
- Copy & paste router code:
@@ -178,7 +179,7 @@ npm i pointyapi
178179

179180
import { Router } from 'express';
180181
import { setModel } from 'pointyapi';
181-
import { BaseUser } from 'pointyapi/models';
182+
import { ExampleUser } from 'pointyapi/models';
182183
import { postFilter, getFilter, patchFilter } from 'pointyapi/filters';
183184
import { onlySelf } from 'pointyapi/guards';
184185
import {
@@ -190,9 +191,9 @@ npm i pointyapi
190191

191192
const router: Router = Router();
192193

193-
// Set the route model to BaseUser
194+
// Set the route model to ExampleUser
194195
async function loader(request, response, next) {
195-
if (await setModel(request, response, BaseUser)) {
196+
if (await setModel(request, response, ExampleUser)) {
196197
next();
197198
}
198199
}
@@ -211,7 +212,7 @@ npm i pointyapi
211212
Open `src/index.ts` up again, and let's import our new User route.
212213

213214
```typescript
214-
import { BaseUser } from 'pointyapi/models'; // Add import to our user model
215+
import { ExampleUser } from 'pointyapi/models'; // Add import to our user model
215216

216217
...
217218
// Routes
@@ -229,7 +230,7 @@ npm i pointyapi
229230
.setEntities(
230231
[
231232
/* TODO: We will set our models here */
232-
BaseUser // Add our BaseModel model to the database
233+
ExampleUser // Add our BaseModel model to the database
233234
]
234235
)
235236

@@ -304,14 +305,14 @@ npm i pointyapi
304305

305306
import { Router } from 'express';
306307
import { loginEndpoint, logoutEndpoint } from 'pointyapi/endpoints';
307-
import { BaseUser } from 'pointyapi/models';
308+
import { ExampleUser } from 'pointyapi/models';
308309
import { setModel } from 'pointyapi';
309310

310311
const router: Router = Router();
311312

312313
// Set our route model & activate auth route
313314
async function loader(request, response, next) {
314-
if (await setModel(request, response, BaseUser, true)) {
315+
if (await setModel(request, response, ExampleUser, true)) {
315316
next();
316317
}
317318
}
@@ -344,7 +345,7 @@ npm i pointyapi
344345
.setEntities(
345346
[
346347
/* TODO: We will set our models here */
347-
BaseUser
348+
ExampleUser
348349
]
349350
)
350351

@@ -379,7 +380,7 @@ npm i pointyapi
379380
To launch in production mode, please make sure the following variables are set (environment variables/.env)
380381

381382
- **SITE_TITLE** - Set the site title
382-
- **CLIENT_URL** - Set your client URL to add the client to the CORS policy
383+
- **ALLOW_ORIGIN** - Set your client URL to add the client to the CORS policy
383384
- **JWT_KEY** - Set your token key to make JWT cryptographically secure
384385
- **JWT_TTL** - Set your token time-to-live (seconds). Default is 15 minutes
385386
- **JWT_REFRESH_TTL** - Set your refresh token time-to-live (seconds). Default is 7 days.

migration.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Migration Guide
22

3+
## What version do you have?
4+
> Choose the version you have before upgrading, and follow the guide to the bottom from there.
5+
- [Version 0.x.x](#version-0.x.x-->-1.x.x)
6+
- [Version 1.x.x](#version-1.x.x-->-2.x.x)
7+
- [Version 2.x.x](#version-2.x.x-->-3.x.x)
8+
39
## Version 0.x.x -> 1.x.x
410

511
1. Remove `response` parameter from responders and handlers
@@ -31,7 +37,7 @@
3137
```typescript
3238
// Set model
3339
router.use((request, response, next) => {
34-
if (await setModel(request, response, BaseUser)) {
40+
if (await setModel(request, response, ExampleUser)) {
3541
// Note that this next() call is now in an if-statement around the setModel()
3642
next();
3743
}
@@ -51,7 +57,7 @@
5157
// Set model
5258
router.use((request, response, next) => {
5359
// vvv add this for auth routes
54-
if (await setModel(request, response, BaseUser, true)) {
60+
if (await setModel(request, response, ExampleUser, true)) {
5561
// Note that this next() call is now in an if-statement around the setModel()
5662
next();
5763
}
@@ -110,11 +116,24 @@
110116
1. Auth tokens are now completely stateless. Remove the `token` field from your User entity.
111117
2. Login now issues a refresh token.
112118
1. Make a POST endpoint in your auth router:
113-
`router.post('/refresh', refreshTokenEndpoint);`
114-
2. Update your front-end auth service to save the `refreshToken` and `refreshExpiration` from the `loginEndpoint`
115-
3. Set a timeout to call the `refreshTokenEndpoint` route when the access token expires. `refreshTokenEndpoint` will return an updated user object, including a new access token & expiration time.
119+
`router.post('/refresh', loader, refreshTokenEndpoint);`
120+
2. Update your front-end auth refreshTokenservice to save the `refreshToken` and `refreshExpiration` from the `loginEndpoint`
121+
3. Set a timeout to call the `refreshTokenEndpoint` route when the access token expires. Setup the body like this: `{ __refreshToken: myRefreshToken }`. This will return an updated user object, including a new access token & expiration time.
116122
3. **(Optional)** PointyAPI now supports `UUID`. Follow the steps in the Readme to enable UUID (strongly recommended for production).
117123

118124
**NOTE** If you are already in production and decide to migrate to UUID, you must make sure to update relations etc
119125

120126
4. **(Optional)** Guards will now issue a `401` only if a token is not present/valid, otherwise will issue a `403`. This may help determine if the user is authenticated/authorized on the front-end.
127+
128+
## Version 2.x.x -> 3.x.x
129+
130+
1. If you use the PointyAPI HTTP Client, the functions have swapped the `bearer` and `expect` parameters. You must swap these in your code.
131+
2. If your code uses a custom database error handler, this should be removed and the pointyapi error handler used instead.
132+
3. `CLIENT_URL` is no longer used for CORS policy. Now you should use `ALLOW_ORIGINS`. **However, `CLIENT_URL` is still used for links, etc - so don't remove it**.
133+
Example:
134+
135+
`/.env`
136+
```
137+
CLIENT_URL=http://example.com/
138+
ALLOW_ORIGINS=http://example.com/, http://cool-example.com/
139+
```

orm-cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ module.exports = {
88
user: dbSettings.user,
99
password: dbSettings.password,
1010
database: dbSettings.database,
11-
entities: [ 'lib/src/models/base-user.ts' ],
11+
entities: [],
1212
uuidExtension: 'pgcrypto'
1313
};

0 commit comments

Comments
 (0)