{"id":24102766,"url":"https://github.com/alphagov/pay-js-commons","last_synced_at":"2025-05-08T17:02:00.416Z","repository":{"id":31536548,"uuid":"128039797","full_name":"alphagov/pay-js-commons","owner":"alphagov","description":"Reusable js scripts for GOV.UK Pay Node.js projects","archived":false,"fork":false,"pushed_at":"2025-04-01T15:29:41.000Z","size":15597,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-19T19:31:43.125Z","etag":null,"topics":["govuk-pay","portfolio"],"latest_commit_sha":null,"homepage":"","language":"SCSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alphagov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-04-04T09:29:09.000Z","updated_at":"2025-04-01T15:29:44.000Z","dependencies_parsed_at":"2023-10-19T11:28:13.920Z","dependency_job_id":"8b4dab8d-5620-414a-9661-3efd267f34d1","html_url":"https://github.com/alphagov/pay-js-commons","commit_stats":{"total_commits":1030,"total_committers":29,"mean_commits":35.51724137931034,"dds":0.6368932038834951,"last_synced_commit":"d9b016e203b33d9e1d6e68468e557fa6c3256b0a"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphagov%2Fpay-js-commons","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphagov%2Fpay-js-commons/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphagov%2Fpay-js-commons/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphagov%2Fpay-js-commons/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alphagov","download_url":"https://codeload.github.com/alphagov/pay-js-commons/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253112071,"owners_count":21856070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["govuk-pay","portfolio"],"created_at":"2025-01-10T18:29:16.831Z","updated_at":"2025-05-08T17:02:00.343Z","avatar_url":"https://github.com/alphagov.png","language":"SCSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GOV.UK Pay JS Commons\nReusable js scripts for GOV.UK Pay Node.js projects\n\n- [Browsered scripts](#browsered-scripts)\n- [Utilities](#utilities)\n- [Nunjucks filters](#nunjucks-filters)\n- [HTTPS base client](#https-base-client)\n- [Releasing a new version](#releasing-a-new-version)\n\n## Browsered scripts\nThis is a collection of client side scripts we use throughout GOV.UK \nPay in the browser. We call it `browsered` because they are written in \nNode.js and _browsered_ by Browserify to make them safe for all our \nbrowsers. We browserify [within the microservice when it’s compiled](https://github.com/alphagov/pay-selfservice/blob/master/Gruntfile.js#L128).\n\n#### List of scripts\n- [Field validation](#field-validation)\n\n### Field Validation\nThis is a collection of validators that can be applied to inputs that\nwill check the values and display errors using the [GOV.UK elements styling](https://govuk-elements.herokuapp.com/errors/#summarise-errors).\n\nValidators:\n- [required](#required)\n- [currency](#currency)\n- [email](#email)\n- [phone](#phone)\n- [https](#https)\n- [belowMaxAmount](#number-is-less-than-maximum-value)\n- [passwordLessThanTenChars](#password)\n- [isFieldGreaterThanMaxLengthChars](#maximum-character-limit)\n- [isNaxsiSafe](#naxsi)\n\n#### Required\nThis requires a value from a given input\n\n```html\n\u003cform data-validate\u003e\n  \u003cdiv class=\"govuk-form-group\"\u003e\n    \u003clabel for=\"name\"\u003eYour name\u003c/label\u003e\n    \u003cinput name=\"name\" data-validate=\"required\" value=\"\" /\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n#### Currency\nThis requires the value is a valid currency amount i.e. “10” or ”9.99”.\n\n```html\n\u003cform data-validate\u003e\n  \u003cdiv class=\"govuk-form-group\"\u003e\n    \u003clabel for=\"amount\"\u003eAmount\u003c/label\u003e\n    \u003cinput name=\"amount\" data-validate=\"required currency\" value=\"\" /\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n#### Email\nThis requires the value is a valid email address with a [TLD](https://en.wikipedia.org/wiki/Top-level_domain) on the end (as [technically](https://www.ietf.org/rfc/rfc822.txt) an email doesn’t need one).\n\n```html\n\u003cform data-validate\u003e\n  \u003cdiv class=\"govuk-form-group\"\u003e\n    \u003clabel for=\"email\"\u003eYour email address\u003c/label\u003e\n    \u003cinput name=\"email\" data-validate=\"email\" value=\"\" /\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n#### Phone\nThis requires the value is a 11 digit phone number, it isn’t concerned\nwith spacing, so `077 777 777 77` and `07777777777` are both valid.\n\n```html\n\u003cform data-validate\u003e\n  \u003cdiv class=\"govuk-form-group\"\u003e\n    \u003clabel for=\"phone\"\u003ePhone number\u003c/label\u003e\n    \u003cinput name=\"phone\" data-validate=\"phone\" value=\"\" /\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n#### HTTPS\nThis requires a link to begin with https://\n\n```html\n\u003cform data-validate\u003e\n  \u003cdiv class=\"govuk-form-group\"\u003e\n    \u003clabel for=\"url\"\u003eReturn URL\u003c/label\u003e\n    \u003cinput name=\"url\" data-validate=\"https\" value=\"\" /\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n#### Number is less than maximum value\nThis requires the value is less than £100,000 as that has been deemed sensible…\n\n```html\n\u003cform data-validate\u003e\n  \u003cdiv class=\"govuk-form-group\"\u003e\n    \u003clabel for=\"price\"\u003eAmount\u003c/label\u003e\n    \u003cinput name=\"price\" data-validate=\"belowMaxAmount\" value=\"\" /\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n#### Password\nThis requires a password be at least 10 chars\n\n```html\n\u003cform data-validate\u003e\n  \u003cdiv class=\"govuk-form-group\"\u003e\n    \u003clabel for=\"password\"\u003ePassword\u003c/label\u003e\n    \u003cinput name=\"password\" data-validate=\"passwordLessThanTenChars\" value=\"\" /\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n#### Maximum character limit\nThis requires a value be less than a certain number of characters. This limit\nis set within a `data-attribute`\n\n```html\n\u003cform data-validate\u003e\n  \u003cdiv class=\"govuk-form-group\"\u003e\n    \u003clabel for=\"title\"\u003eTitle\u003c/label\u003e\n    \u003cinput name=\"title\" data-validate=\"isFieldGreaterThanMaxLengthChars\" data-validate-max-length=\"255\" value=\"\" /\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n#### NAXSI\nThis checks whether a field contains characters than would cause NAXSI to get upset,\nmeaning characters that look like code injection\ni.e. ``\u003c \u003e ; : ` ( ) \" \\' = | , ~ [ ]``\n\n```html\n\u003cform data-validate\u003e\n  \u003cdiv class=\"govuk-form-group\"\u003e\n    \u003clabel for=\"title\"\u003eTitle\u003c/label\u003e\n    \u003cinput name=\"title\" data-validate=\"isNaxsiSafe\" value=\"\" /\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\n## Utilities\n\n### Nunjucks filters\n\nThese are small functions that power the nunjucks filters but can also be used for server side stuff too.\n\nThese get loaded in to the Nunjucks environment and then can apply changes to variables in templates.\n\nFor example if a country comes in as ISO code `EN` it can be converted to it’s name like so\n\n```html\n  \u003cp\u003e{{ countryCode | countryISOtoName }}\u003c/p\u003e\n```\n\nOr a pence value can be converted to GBP\n\n```html\n  \u003cdl\u003e\n    \u003cdt\u003eAmount:\u003c/dt\u003e\n    \u003cdd\u003e{{ amount | penceToPounds }}\u003c/dd\u003e\n  \u003c/dl\u003e\n```\n\n## Axios base client\n\nUsed in our Node.js apps to call APIs such as connector or ledger.\n\nUses the NPM [Axios](https://www.npmjs.com/package/axios) library.\n\nThe base client provides the following configuration options:\n* onRequestStart - Callback function before starting a API request.  Mainly used for logging.\n* onSuccessResponse - Callback function when request has completed successfully.\n* onFailureResponse - Callback function when request has failed.\n* acceptAllStatusCodes - `boolean`\n  * By default all non 2xx responses are considered failed requests.\n  * Set this to `true` and all status codes are considered a successful request.  You code will then need to handle the response appropriately.  Currently, only `pay-frontend` requires this to be set to `true`. \n\n### Built in in retry functionality\n\nIf a `GET` request provides a response with the error message `ECONNRESET` - the the Axios base client will automatically try that request another 2 times - 3 times in total.\n\nBy default, on each failed request, it will call the `onFailureResponse` callback.\n\nIf `acceptAllStatusCodes=true`, then it will call the `onSuccessResponse` callback.\n\n## Releasing\n\nAfter a pull request is merged, Concourse will automatically create a new release pull request that increments the package version.\n\nThis pull request must be reviewed and merged by a developer.\n\nOnce the release pull request is merged, GitHub Actions will publish the new versioned package to NPM.\n\n__IMPORTANT__: Other pull requests will be blocked from merging until the release pull request is merged or closed.\n\n## Licence\n\n[MIT License](https://github.com/alphagov/pay-js-commons/blob/master/LICENSE)\n\n## Vulnerability Disclosure\n\nGOV.UK Pay aims to stay secure for everyone.\nIf you are a security researcher and have discovered a security vulnerability in this code, we appreciate your help in disclosing it to us in a responsible manner.\nPlease refer to our [vulnerability disclosure policy](https://www.gov.uk/help/report-vulnerability) and our [security.txt](https://vdp.cabinetoffice.gov.uk/.well-known/security.txt) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphagov%2Fpay-js-commons","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falphagov%2Fpay-js-commons","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphagov%2Fpay-js-commons/lists"}