Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
|
|
|
{
|
|
|
|
|
"name": "notifications-admin",
|
|
|
|
|
"version": "0.0.1",
|
|
|
|
|
"description": "Admin front end for GOV.UK Notify",
|
2015-12-20 00:00:01 +00:00
|
|
|
"engines": {
|
2021-09-15 16:24:01 +01:00
|
|
|
"node": ">=10.15.3"
|
2015-12-20 00:00:01 +00:00
|
|
|
},
|
Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
|
|
|
"scripts": {
|
2019-05-21 10:56:38 +01:00
|
|
|
"test": "gulp lint && jest --config tests/javascripts/jest.config.js tests/javascripts",
|
2019-10-16 15:20:05 +01:00
|
|
|
"test-watch": "jest --watch --config tests/javascripts/jest.config.js tests/javascripts",
|
2016-01-12 13:37:50 +00:00
|
|
|
"build": "gulp",
|
|
|
|
|
"watch": "gulp watch"
|
Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
|
|
|
},
|
|
|
|
|
"repository": {
|
|
|
|
|
"type": "git",
|
|
|
|
|
"url": "git+https://github.com/alphagov/notifications-admin.git"
|
|
|
|
|
},
|
|
|
|
|
"author": "Government Digital Service",
|
|
|
|
|
"license": "MIT",
|
|
|
|
|
"homepage": "https://github.com/alphagov/notifications-admin#readme",
|
|
|
|
|
"dependencies": {
|
Support registering a new authenticator
This adds Yubico's FIDO2 library and two APIs for working with the
"navigator.credentials.create()" function in JavaScript. The GET
API uses the library to generate options for the "create()" function,
and the POST API decodes and verifies the resulting credential. While
the options and response are dict-like, CBOR is necessary to encode
some of the byte-level values, which can't be represented in JSON.
Much of the code here is based on the Yubico library example [1][2].
Implementation notes:
- There are definitely better ways to alert the user about failure, but
window.alert() will do for the time being. Using location.reload() is
also a bit jarring if the page scrolls, but not a major issue.
- Ideally we would use window.fetch() to do AJAX calls, but we don't
have a polyfill for this, and we use $.ajax() elsewhere [3]. We need
to do a few weird tricks [6] to stop jQuery trashing the data.
- The FIDO2 server doesn't serve web requests; it's just a "server" in
the sense of WebAuthn terminology. It lives in its own module, since it
needs to be initialised with the app / config.
- $.ajax returns a promise-like object. Although we've used ".fail()"
elsewhere [3], I couldn't find a stub object that supports it, so I've
gone for ".catch()", and used a Promise stub object in tests.
- WebAuthn only works over HTTPS, but there's an exception for "localhost"
[4]. However, the library is a bit too strict [5], so we have to disable
origin verification to avoid needing HTTPS for dev work.
[1]: https://github.com/Yubico/python-fido2/blob/c42d9628a4f33d20c4401096fa8d3fc466d5b77f/examples/server/server.py
[2]: https://github.com/Yubico/python-fido2/blob/c42d9628a4f33d20c4401096fa8d3fc466d5b77f/examples/server/static/register.html
[3]: https://github.com/alphagov/notifications-admin/blob/91453d36395b7a0cf2998dfb8a5f52cc9e96640f/app/assets/javascripts/updateContent.js#L33
[4]: https://stackoverflow.com/questions/55971593/navigator-credentials-is-null-on-local-server
[5]: https://github.com/Yubico/python-fido2/blob/c42d9628a4f33d20c4401096fa8d3fc466d5b77f/fido2/rpid.py#L69
[6]: https://stackoverflow.com/questions/12394622/does-jquery-ajax-or-load-allow-for-responsetype-arraybuffer
2021-05-07 18:10:07 +01:00
|
|
|
"cbor-js": "0.1.0",
|
2021-01-25 14:03:16 +00:00
|
|
|
"govuk_frontend_toolkit": "8.1.0",
|
2019-04-16 11:10:25 +01:00
|
|
|
"govuk-elements-sass": "3.1.2",
|
2019-10-03 12:59:26 +01:00
|
|
|
"govuk-frontend": "2.13.0",
|
2016-09-20 12:30:00 +01:00
|
|
|
"hogan": "1.0.2",
|
2020-04-29 22:56:45 +00:00
|
|
|
"jquery": "3.5.0",
|
2020-07-03 09:50:35 +01:00
|
|
|
"leaflet": "1.6.0",
|
2022-01-27 10:44:20 +00:00
|
|
|
"morphdom": "2.6.1",
|
2016-09-28 17:47:40 +01:00
|
|
|
"query-command-supported": "1.0.0",
|
2019-04-01 09:58:13 +01:00
|
|
|
"textarea-caret": "3.1.0",
|
2019-04-01 14:57:47 +01:00
|
|
|
"timeago": "1.6.5"
|
2016-02-08 11:05:07 +00:00
|
|
|
},
|
|
|
|
|
"devDependencies": {
|
2022-05-05 14:52:32 +01:00
|
|
|
"@babel/core": "7.4.0",
|
|
|
|
|
"@babel/preset-env": "7.4.2",
|
2022-05-06 15:34:54 +01:00
|
|
|
"better-npm-audit": "^3.7.3",
|
2022-05-05 14:52:32 +01:00
|
|
|
"gulp": "4.0.2",
|
|
|
|
|
"gulp-add-src": "1.0.0",
|
|
|
|
|
"gulp-babel": "8.0.0",
|
|
|
|
|
"gulp-better-rollup": "4.0.1",
|
|
|
|
|
"gulp-clean-css": "4.3.0",
|
|
|
|
|
"gulp-concat": "2.6.1",
|
2016-02-23 10:56:48 +00:00
|
|
|
"gulp-css-url-adjuster": "0.2.3",
|
2022-05-06 15:34:54 +01:00
|
|
|
"gulp-include": "2.4.1",
|
2018-01-17 16:50:39 +00:00
|
|
|
"gulp-jshint": "2.1.0",
|
2021-09-09 14:33:30 +01:00
|
|
|
"gulp-prettyerror": "2.0.0",
|
2022-05-06 15:34:54 +01:00
|
|
|
"gulp-sass": "5.0.0",
|
2019-04-01 09:58:13 +01:00
|
|
|
"gulp-sass-lint": "1.4.0",
|
2022-05-06 15:34:54 +01:00
|
|
|
"gulp-uglify": "3.0.2",
|
2019-04-12 11:51:51 +01:00
|
|
|
"jest": "24.7.1",
|
Delay AJAX calls if the server is slow to respond
By default our AJAX calls were 2 seconds. Then they were 5 seconds
because someone reckoned 2 seconds was putting too much load on the
system. Then we made them 10 seconds while we were having an incident.
Then we made them 20 seconds for the heaviest pages, but back to 5
seconds or 2 seconds for the rest of the pages.
This is not a good situation because:
- it slows all services down equally, no matter how much traffic they
have, or which features they have switched on
- it slows everything down by the same amount, no matter how much load
the platform is under
- the values are set based on our worst performance, until we manually
remember to switch them back
- we spend time during incidents deploying changes to slow down the
dashboard refresh time because it’s a nothing-to-lose change that
might relieve some symptoms, when we could be spending time digging
into the underlying cause
This pull request makes the Javascript smarter about how long it waits
until it makes another AJAX call. It bases the delay on how long the
server takes to respond (as a proxy for how much load the server is
under).
It’s based on the square root of the response time, so is more sensitive
to slow downs early on, and less sensitive to slow downs later on. This
helps us give a more pronounced difference in delay between an AJAX call
that is fast (for example the page for a single notification) and one
that is slow (for example a dashboard for a service with lots of
traffic).
*Some examples of what this would mean for various pages*
Page | Response time | Wait until next AJAX call
---|---|---
Check a reply to address | 130ms | 1,850ms
Brand new service dashboard | 229ms | 2,783ms
HM Passport Office dashboard | 634ms | 5,294ms
NHS Coronavirus Service dashboard | 779ms | 5,977ms
_Example of the kind of slowness we’ve seen during an incident_ | 6,000ms | 18,364ms
GOV.UK email dashboard | `HTTP 504` | 😬
2020-04-08 17:55:53 +01:00
|
|
|
"jest-date-mock": "^1.0.8",
|
|
|
|
|
"jest-each": "^25.3.0",
|
2019-04-01 16:41:23 +01:00
|
|
|
"jshint": "2.10.2",
|
2019-10-11 10:26:25 +01:00
|
|
|
"jshint-stylish": "2.2.1",
|
2022-05-05 14:52:32 +01:00
|
|
|
"rollup": "1.23.1",
|
2019-10-11 10:26:25 +01:00
|
|
|
"rollup-plugin-commonjs": "10.1.0",
|
2022-05-05 14:52:32 +01:00
|
|
|
"rollup-plugin-node-resolve": "5.2.0",
|
|
|
|
|
"sass": "1.32.7",
|
|
|
|
|
"streamqueue": "1.1.2"
|
Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
|
|
|
}
|
|
|
|
|
}
|