Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5.0.0 #1280

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open

v5.0.0 #1280

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bfd33ce
Remove depreacted Log hook
LoicPoullain Aug 19, 2024
e8bd827
[Blog] Remove the deprecated Log hook
LoicPoullain Aug 22, 2024
9f7773a
Merge pull request #1279 from FoalTS/remove-log-hook
LoicPoullain Aug 22, 2024
0aa5a80
Remove CLI run-script alias
LoicPoullain Aug 19, 2024
5c7864f
[Blog] Remove "npx foal run-script"
LoicPoullain Aug 22, 2024
8f0345c
Merge pull request #1281 from FoalTS/remove-run-alias
LoicPoullain Aug 22, 2024
cad951a
Drop support for Node 18 and add support for Node 20
LoicPoullain Aug 20, 2024
3c46ca7
Use latest version of npm
LoicPoullain Aug 22, 2024
06704a2
[Blog] Add support for Node 20 and 22
LoicPoullain Aug 22, 2024
9044f10
Merge pull request #1282 from FoalTS/use-node-20-22
LoicPoullain Aug 22, 2024
ed9541a
Remove node-fetch dependency
LoicPoullain Aug 19, 2024
5b2d9b0
Merge pull request #1283 from FoalTS/remove-node-fetch
LoicPoullain Aug 22, 2024
20e8a6d
Make Context.state type to "{}" by default
LoicPoullain Aug 22, 2024
ccabf9f
Merge pull request #1284 from FoalTS/context-unkwon
LoicPoullain Aug 22, 2024
4e80cb8
Upgrade to TS v5
LoicPoullain Aug 22, 2024
fd3683f
[Blog] Support TS v5
LoicPoullain Aug 22, 2024
cd0246a
Merge pull request #1285 from FoalTS/ts-v5
LoicPoullain Aug 22, 2024
c983483
Compile to ES2023
LoicPoullain Aug 22, 2024
3cb8f2c
Fix linting
LoicPoullain Aug 22, 2024
79e40c0
[Blog] Add note on ES2023
LoicPoullain Aug 22, 2024
aacc37a
Merge pull request #1286 from FoalTS/compile-to-es2023
LoicPoullain Aug 22, 2024
f22b313
Improve `AbstractProvider.getUserInfoFromTokens` return type
LoicPoullain Aug 22, 2024
39486bd
[Blog] The return value of `getUserInfoFromTokens` is typed
LoicPoullain Aug 22, 2024
b292a5f
[Docs] Fix typo
LoicPoullain Aug 22, 2024
e1941d1
Merge pull request #1287 from FoalTS/abstract-provider-type
LoicPoullain Aug 22, 2024
d9a79bd
Make addLogContext accept a record with multiple params
LoicPoullain Aug 22, 2024
a249f41
Use better param name
LoicPoullain Aug 22, 2024
c2c4c49
Merge pull request #1288 from FoalTS/log-context
LoicPoullain Aug 22, 2024
139e902
[Docs] Fix typo on error logging
LoicPoullain Aug 22, 2024
3e6fb8d
Replace loggerFormat with logger.logHttpRequests
LoicPoullain Aug 22, 2024
7218835
[Blog] Replace loggerFormat with logger.logHttpRequests
LoicPoullain Aug 22, 2024
7b994a9
Merge pull request #1289 from FoalTS/logger-format
LoicPoullain Aug 22, 2024
c61eca9
Merge branch 'master' into v5-0-0
LoicPoullain Aug 22, 2024
a6d98cd
Remove deprecated AbstractProvider.redirect method
LoicPoullain Aug 22, 2024
ed9cfa5
Merge pull request #1290 from FoalTS/remove-social-redirect
LoicPoullain Aug 22, 2024
62ebbd4
Upgrade TypeORM peer dependency to v0.3.20
LoicPoullain Aug 24, 2024
6c23242
Merge pull request #1291 from FoalTS/upgrade-typeorm-peer-dep
LoicPoullain Aug 24, 2024
d76a1f2
Provide a ServiceManager to shell scripts
LoicPoullain Aug 26, 2024
7692b0a
[Blog] Provide a ServiceManager to shell scripts
LoicPoullain Aug 26, 2024
bdf395c
Merge branch 'master' into v5-0-0
LoicPoullain Aug 26, 2024
56c0a81
Merge pull request #1292 from FoalTS/shell-script-services
LoicPoullain Aug 26, 2024
36190b9
Merge branch 'master' into v5-0-0
LoicPoullain Sep 2, 2024
ea4fa00
[Website] Use global authors
LoicPoullain Sep 2, 2024
de5d843
Merge branch 'master' into v5-0-0
LoicPoullain Sep 2, 2024
7968747
Merge branch 'master' into v5-0-0
LoicPoullain Sep 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ All of major releases are supported for at least 18 months.

| Release | Status | Active Start | Maintenance Start | End-of-life | Node versions | TS min version |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| 4.x | *Active* | 2023-09-06 | | | 18, 20 | 4.9 |
| 5.x | *Active* | TODO | | | 20, 22 | 5.5 |
| 4.x | *Maintenance* | 2023-09-06 | TODO | TODO | 18, 20 | 4.9 |
| 3.x | *End-of-Life* | 2022-10-28 | 2023-09-06 | 2024-03-06 | 16, 18 | 4.7 |
| 2.x | *End-of-Life* | 2020-12-03 | 2022-10-28 | 2023-04-30 | 10, 12, 14 | 4.0 |
| 1.x | *End-of-Life* | 2019-07-11 | 2020-12-03 | 2021-05-31 | 8, 10 | 3.5 |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/daily-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [18, 20]
node-version: [20, 22]

services:
mongodb:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '18.x'
node-version: '20.x'
- name: Test Build
run: |
cd docs
Expand All @@ -33,7 +33,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '18.x'
node-version: '20.x'
- name: Add key to allow access to repository
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [18, 20]
node-version: [20, 22]

env:
SETTINGS_AWS_ACCESS_KEY_ID: ${{ secrets.SETTINGS_AWS_ACCESS_KEY_ID }}
Expand All @@ -29,8 +29,6 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Use npm version 9.6
run: npm install -g npm@9.6
- name: Install project and package dependencies
run: npm install
- name: Build packages
Expand Down
Binary file added docs/blog/assets/version-5.0-is-here/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions docs/blog/version-5.0-release-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
title: Version 5.0 release notes
authors: LoicPoullain
image: blog/twitter-banners/version-5.0-release-notes.png
tags: [release]
---

![Banner](./assets/version-5.0-is-here/banner.png)

Version 5.0 of [Foal](https://foalts.org/) is out!

<!--truncate-->

## Supported versions of Node and TypeScript

- Support for Node 18 has been dropped and support for Node 22 has been added. Foal code is now compiled to ES2023.
- The supported version of TypeScript is version 5. Update your `package.json` file accordingly.

> If you're using the `GraphQLController` with the `resolvers` property, you need to add the `declare` keyword before the property name:
> ```typescript
>
> export class ApiController extends GraphQLController {
> schema = // ...
>
> @dependency
> declare resolvers: RootResolverService;
> }
> ```

## TypeORM upgrade

- The minimum required version of TypeORM is v0.3.20.

## Better typing

- The default type of `Context.state` is now `{}`. This way, you'll get a compilation error if you forget to specify a type for the state.

```typescript
// Version 4
class MyController {
@Get('/foobar')
foobar(ctx: Context) {
// Does not throw.
console.log(ctx.state.shoppingCart);
}
}

// Version 5
class MyController {
@Get('/foobar')
foobar(ctx: Context) {
// Throws a compilation error: Property 'shoppingCart' does not exist on type '{}'.ts(2339)
console.log(ctx.state.shoppingCart);
}
}

// Version 5 (without error)
class MyController {
@Get('/foobar')
foobar(ctx: Context<any, { shoppingCart: object }>) {
console.log(ctx.state.shoppingCart);
}
}

```

- The return value of the social services `getUserInfoFromTokens` method is now typed.

## Logging

- The `Logger.addLogContext(key, value)` method now accepts a record as parameter: `Logger.addLogContext(context)`. This makes the function's signature more consistent with other logging methods (`info`, `warn`, etc.) and allows multiple keys/values to be passed at once.
- The deprecated `settings.loggerFormat` configuration has been removed. If you want to disable HTTP logging, set `settings.logger.logHttpRequests` to false instead.

## Shell scripts

- The `main` function of shell scripts now receives an instance of `ServiceManager` as second argument:
```typescript
export async function main(args: any, services: ServiceManager) {
// ...
}
```


## Removal of deprecated components

- The deprecated hook `@Log` has been removed. Use the `Logger` service in a custom `@Hook` instead.
- The command alias `npx foal run-script` has been removed. Use `npx foal run` instead.
- The deprecated method `AbstractProvider.redirect` has been removed. Use `AbstractProvider.createHttpResponseWithConsentPageUrl({ isRedirection: true })` instead.
6 changes: 4 additions & 2 deletions docs/docs/architecture/architecture-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Controllers may have sub-controllers. Hooks can be attached to the controllers o
Here's an example of what a FoalTS application may look like.

```typescript
import { Context, controller, Get, HttpResponseNotFound, HttpResponseOK, Log } from '@foal/core';
import { Context, controller, Get, Hook, HttpResponseNotFound, HttpResponseOK } from '@foal/core';
import { JWTRequired } from '@foal/jwt';

@JWTRequired()
Expand Down Expand Up @@ -105,7 +105,9 @@ class ApiController {
}
}

@Log('Receiving a request...')
@Hook(() => {
console.log('Receiving a request...')
})
class AppController {
subControllers = [
controller('/api', ApiController)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/architecture/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ It has seven properties:
| Name | Type | Description |
| --- | --- | --- |
| `request` | `Request` | Gives information about the HTTP request. |
| `state` | `{ [key: string]: any }` | Object which can be used to forward data accross several hooks (see [Hooks](./hooks.md)). |
| `state` | `{ [key: string]: any } = {}` | Object which can be used to forward data accross several hooks (see [Hooks](./hooks.md)). |
| `user` | `{ [key: string]: any }`\|`null` | The current user (see [Authentication](../authentication/quick-start.md)). |
| `session`| `Session`\|`null` | The session object if you use sessions. |
| `files` | `FileList` | A list of file paths or buffers if you uploaded files (see [Upload and download files](../common/file-storage/upload-and-download-files.md)). |
Expand Down
7 changes: 3 additions & 4 deletions docs/docs/architecture/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ They improve code readability and make unit testing easier.
Foal provides a number of hooks to handle the most common scenarios.

- `ValidateBody`, `ValidateHeader`, `ValidatePathParam`, `ValidateCookie` and `ValidateQueryParam` validate the format of the incoming HTTP requests (see [Validation](../common/validation-and-sanitization.md)).
- `Log` displays information on the request (see [Logging](../common/logging.md)).
- `JWTRequired`, `JWTOptional`, `UseSessions` authenticate the user by filling the `ctx.user` property.
- `PermissionRequired` restricts the route access to certain users.

Expand Down Expand Up @@ -73,7 +72,7 @@ If the user makes a POST request to `/products` whereas she/he is not authentica
> If you need to apply a hook globally, you just have to make it decorate the root controller: `AppController`.
>
> ```typescript
> @Log('Request body:', { body: true })
> @UseSessions()
> export class AppController {
> // ...
> }
Expand Down Expand Up @@ -466,7 +465,7 @@ import { Context, Get, Hook, HttpResponseOK, UserRequired } from '@foal/core';
import { Org } from '../entities';

function AddOrgToContext() {
return Hook(async ctx => {
return Hook(async (ctx: Context<any, { org: Org }>) => {
if (ctx.user) {
ctx.state.org = await Org.findOneByOrFail({ id: ctx.user.orgId });
}
Expand All @@ -478,7 +477,7 @@ export class ApiController {
@Get('/org-name')
@UserRequired()
@AddOrgToContext()
readOrgName(ctx: Context) {
readOrgName(ctx: Context<any, { org: Org }>) {
return new HttpResponseOK(ctx.state.org.name);
}

Expand Down
14 changes: 7 additions & 7 deletions docs/docs/authentication/session-tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
#### TypeORMStore

```
npm install typeorm@0.3.17 @foal/typeorm
npm install typeorm@0.3.20 @foal/typeorm
```

This store uses the default TypeORM connection whose configuration is usually specified in `config/default.{json|yml|js}`.
Expand Down Expand Up @@ -641,7 +641,7 @@ npx foal g script revoke-session
Open `scripts/revoke-session.ts` and update its content.

```typescript
import { createService, readSession, Store } from '@foal/core';
import { readSession, ServiceManager, Store } from '@foal/core';

import { dataSource } from '../db';

Expand All @@ -653,10 +653,10 @@ export const schema = {
required: [ 'token' ]
}

export async function main({ token }: { token: string }) {
export async function main({ token }: { token: string }, services: ServiceManager) {
await dataSource.initialize();

const store = createService(Store);
const store = services.get(Store);
await store.boot();

const session = await readSession(store, token);
Expand Down Expand Up @@ -687,14 +687,14 @@ npx foal g script revoke-all-sessions
Open `scripts/revoke-all-sessions.ts` and update its content.

```typescript
import { createService, Store } from '@foal/core';
import { ServiceManager, Store } from '@foal/core';

import { dataSource } from '../db';

export async function main() {
export async function main(args: any, services: ServiceManager) {
await dataSource.initialize();

const store = createService(Store);
const store = services.get(Store);
await store.boot();
await store.clear();
}
Expand Down
8 changes: 6 additions & 2 deletions docs/docs/authentication/social-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ export interface GithubUserInfoParameter {
// ...
}

export class GithubProvider extends AbstractProvider<GithubAuthParameter, GithubUserInfoParameter> {
export interface GithubUserInfo {
// ...
}

export class GithubProvider extends AbstractProvider<GithubAuthParameter, GithubUserInfoParameter, GithubUserInfo> {

protected configPaths = {
clientId: 'social.github.clientId',
Expand All @@ -357,7 +361,7 @@ export class GithubProvider extends AbstractProvider<GithubAuthParameter, Github

protected defaultScopes: string[] = [ 'email' ]; // Optional

async getUserInfoFromTokens(tokens: SocialTokens, params?: GithubUserInfoParameter) {
getUserInfoFromTokens(tokens: SocialTokens, params?: GithubUserInfoParameter): GithubUserInfo | Promise<GithubUserInfo> {
// ...

// In case the server returns an error when requesting
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/cli/shell-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ Remove the content of `src/scripts/display-users.ts` and replace it with the cod

```typescript
// 3p
import { createService } from '@foal/core';
import { ServiceManager } from '@foal/core';

// App
import { dataSource } from '../db';
import { User } from '../app/entities';
import { Logger } from '../app/services';

export async function main() {
export async function main(args: any, services: ServiceManager) {
await dataSource.initialize();

try {
const users = await User.find();
const logger = createService(Logger);
const logger = services.get(Logger);
logger.log(users);
} finally {
dataSource.destroy();
Expand All @@ -55,7 +55,7 @@ npm run build
Then you can execute it with this command:

```shell
npx foal run my-script # or npx foal run-script my-script
npx foal run my-script
```

> You can also provide additionnal arguments to your script (for example: `npx foal run my-script foo=1 bar='[ 3, 4 ]'`). The default template in the generated scripts shows you how to handle such behavior.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/common/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class ApiController extends GraphQLController {
schema = // ...

@dependency
resolvers: RootResolverService;
declare resolvers: RootResolverService;
}
```

Expand Down
Loading
Loading