Upgrade to v8
The purpose of this note is to help developers to upgrade their liana from v7 to v8. Please read carefully and integrate the following breaking changes to ensure a smooth upgrade.​
This upgrade unlocks the following features:

Upgrading to v8

Before upgrading to v8, consider the below breaking changes.
As for any dependency upgrade, it's very important to test this upgrade in your testing environments. Not doing so could result in your admin panel being unusable.
To upgrade to v8, run the following and then update your project as shown in the Breaking Changes section below.
SQL
MongoDB
1
npm install "[email protected]^8.0.0"
Copied!
1
npm install "[email protected]^8.0.0"
Copied!
In case of a regression introduced in Production after the upgrade, a rollback to your previous liana is the fastest way to restore your admin panel.

Breaking changes

CORS allowed headers

Every collection calls (CRUD operations) to your agent will now be performed with a new header called Forest-Context-Url . This header contains the current URL of the user performing requests. This can be handy if you need information on the context this user is working on.
If you don't have any restriction on headers within your CORS configuration, nothing needs to be changed, you can move on to the next section.
If you have configured a header whitelist (allowedHeaders in express for instance) in your CORS configuration, you need to add this new header to the whitelist, otherwise browsers won't trigger request anymore due to CORS policy:
Before
1
const corsConfig = {
2
origin: ...,
3
allowedHeaders: ['Authorization', 'X-Requested-With', 'Content-Type', ...],
4
maxAge: ...,
5
credentials: ...,
6
};
Copied!
After
1
const corsConfig = {
2
origin: ...,
3
allowedHeaders: ['Forest-Context-Url', 'Authorization', 'X-Requested-With', 'Content-Type', ...],
4
maxAge: ...,
5
credentials: ...,
6
};
Copied!

File Upload

Until now, once you had submitted a file for upload, the file name wasn't persisted. We have now made so that it is possible to save and display it.
If you use a regex to parse data before sending it for upload (like we originally suggested in this Woodshop tutorial), there is a breaking change: you need to use the output of the parseDataUri method.
Before
1
function S3Helper() {
2
this.upload = (rawData, filename) => new P((resolve, reject) => {
3
...
4
const parsed = parseDataUri(rawData);
5
const base64Image = rawData.replace(/^data:([-\w.]+\/[-\w.]+);base64,/, '');
6
7
const data = {
8
Body: new Buffer(base64Image, 'base64'),
9
ContentEncoding: 'base64',
10
...
11
};
12
}
Copied!
After
1
function S3Helper() {
2
this.upload = (rawData, filename) => new P((resolve, reject) => {
3
...
4
const parsed = parseDataUri(rawData);
5
const data = {
6
Body: parsed.data,
7
...
8
};
9
}
Copied!

Scopes

Scopes have been revamped, from a convenient alternative to segments, to a security feature. They are now enforced by the agent (server-side).
This update comes with many breaking changes in the prototype of helpers which are provided to access and modify data.
All occurrences of calls to RecordsGetter, RecordCounter, RecordsExporter, RecordsRemover, RecordCreator, RecordGetter, RecordUpdater, RecordRemover , RecordsCounter, must be updated.
Note that RecordSerializer was not modified, and can be used to serialize and deserialize models.
Before
1
router.post(
2
'/actions/do-something',
3
permissionMiddlewareCreator.smartAction()
4
(req, res) => {
5
const { query } = req;
6
7
// List helpers
8
new RecordsGetter(MyModel).getAll(query);
9
new RecordsGetter(MyModel).getIdsFromRequest(req);
10
new RecordCounter(MyModel).count(query);
11
new RecordsExporter(MyModel).streamExport(res, query);
12
new RecordsRemover(MyModel).remove([1, 2, 3])
13
14
// Single item helpers
15
new RecordCreator(MyModel).create({title: 'One');
16
new RecordGetter(MyModel).get(37);
17
new RecordUpdater(MyModel).update({title: 'Two'}, 37);
18
new RecordRemover(MyModel).remove(37);
19
}
20
);
Copied!
After
1
router.post(
2
'/actions/do-something',
3
permissionMiddlewareCreator.smartAction()
4
(req, res) => {
5
const { query, user } = req;
6
7
// List helpers
8
new RecordsGetter(MyModel, user, query).getAll();
9
new RecordsGetter(MyModel, user, query).getIdsFromRequest(req);
10
new RecordCounter(MyModel, user, query).count();
11
new RecordsExporter(MyModel, user, query).streamExport(res);
12
new RecordsRemover(MyModel, user, query).remove([1, 2, 3])
13
14
// Single item helpers
15
new RecordCreator(MyModel, user, query).create({title: 'One');
16
new RecordGetter(MyModel, user, query).get(37);
17
new RecordUpdater(MyModel, user, query).update({title: Two'}, 37);
18
new RecordRemover(MyModel, user, query).remove(37);
19
}
20
);
Copied!

Smart actions

The values endpoint is no longer supported. Hooks now replaces the values endpoint since they are now available for single, bulk & global smart action types.
1st change:
The Smart action change hook method name is no longer the fieldName. You are now required to declare the hook name as a property inside the field.
Before
1
{
2
name: 'Test action',
3
type: 'single',
4
fields: [{
5
field: 'a field',
6
type: 'String',
7
}],
8
hooks: {
9
change: {
10
'a field': ({ fields, record }) => {
11
// Do something ...
12
return fields;
13
},
14
}
15
},
16
}
Copied!
After
1
{
2
name: 'Test action',
3
type: 'single',
4
fields: [{
5
field: 'a field',
6
type: 'String',
7
hook: 'onFieldChanged',
8
}],
9
hooks: {
10
change: {
11
onFieldChanged: ({ fields, record, changedField }) => {
12
// Do something ...
13
return fields;
14
},
15
}
16
},
17
}
Copied!
2nd change:
The signature of hooks functions has changed. fields is now an array. You must change the way you access fields.
Before
1
[...]
2
hooks: {
3
load: ({ fields, record }) => {
4
const field = fields['a field'];
5
field.value = 'init your field';
6
return fields;
7
},
8
change: {
9
onFieldChanged: ({ fields, record }) => {
10
const field = fields['a field'];
11
field.value = 'what you want';
12
return fields;
13
}
14
}
15
}
16
[...]
Copied!
After
1
[...]
2
hooks: {
3
load: ({ fields, record }) => {
4
const field = fields.find(field => field.field === 'a field');
5
field.value = 'init your field';
6
return fields;
7
},
8
change: {
9
onFieldChanged: ({ fields, record, changedField }) => {
10
const field = fields.find(field => field.field === 'a field');
11
field.value = 'what you want';
12
return fields;
13
}
14
}
15
}
16
[...]
Copied!
3nd change:
The signature of hooks functions has changed. In order to support hooks for global and bulk smart actions, record is no longer sent to the hook. You must change the way you get the record informations. This change also prevents unnecessary computation in case you don't need to access the record(s) inside the hooks.
Before
1
[...]
2
hooks: {
3
load: ({ fields, record }) => {
4
const field = fields['a field'];
5
field.value = record.aProps;
6
return fields;
7
},
8
}
9
[...]
Copied!
After
SQL
Mongodb
1
const { model } = require('../models');
2
[...]
3
hooks: {
4
load: async ({ fields, request }) => {
5
const [id] = await new RecordsGetter(model, request.user, request.query)
6
.getIdsFromRequest(request);
7
// or
8
const id = request.body.data.attributes.ids[0];
9
10
const record = await model.findByPk(id);
11
12
const field = fields.find(field => field.field === 'a field');
13
field.value = record.aProps;
14
15
return fields;
16
},
17
}
18
[...]
Copied!
1
const { model } = require('../models');
2
[...]
3
hooks: {
4
load: async ({ fields, request }) => {
5
const [id] = await new RecordsGetter(model, request.user, request.query)
6
.getIdsFromRequest(request);
7
// or
8
const id = request.body.data.attributes.ids[0];
9
10
const record = await model.findById(id);
11
12
const field = fields.find(field => field.field === 'a field');
13
field.value = record.aProps;
14
15
return fields;
16
},
17
}
18
[...]
Copied!
Last modified 12d ago