Skip to content

Commit

Permalink
🏷️ [#445] Convert headers factory to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Mar 4, 2025
1 parent 43e5063 commit 10e03a8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/headers.js → src/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const CSPNonceHeaderName = 'X-CSP-Nonce';
const CSRFTokenHeaderName = 'X-CSRFToken';
const IsFormDesignerHeaderName = 'X-Is-Form-Designer';

const factoryHeader = (headerName, headerValue) => {
const factoryHeader = <T>(headerName: string, headerValue: T | null) => {
return {
headerName: headerName,
value: headerValue,
getValue() {
return headerValue;
},
setValue(value) {
setValue(value: T) {
headerValue = value;
},
};
Expand All @@ -26,7 +26,7 @@ const factoryHeader = (headerName, headerValue) => {
* The Open Forms SDK includes the value of the cspNonce as a header in fetch api calls
* so that any HTML can be post-processed to add the correct nonce.
*/
let CSPNonce = factoryHeader(CSPNonceHeaderName, null);
const CSPNonce = factoryHeader<string>(CSPNonceHeaderName, null);

/**
* Global module-scoped variable to track the value of the CSRF Token.
Expand All @@ -37,22 +37,22 @@ let CSPNonce = factoryHeader(CSPNonceHeaderName, null);
* The Open Forms SDK includes the value of the CSRF Token as a header in fetch api
* calls if it's set.
*/
let CSRFToken = factoryHeader(CSRFTokenHeaderName, null);
const CSRFToken = factoryHeader<string>(CSRFTokenHeaderName, null);

/**
* Global module-scoped variable to track whether the user is a Form Designer.
*
* Form designers are allowed to navigate between submission steps even if these are not completed.
*
*/
let IsFormDesigner = factoryHeader(IsFormDesignerHeaderName, false);
const IsFormDesigner = factoryHeader<boolean>(IsFormDesignerHeaderName, false);

/**
* Global module-scoped variable to track the current (UI) language.
*
* The backend interprets the HTTP Accept-Language (request) header and informs us of
* the activated language via the Content-Language response header.
*/
let ContentLanguage = factoryHeader('Content-Language', 'nl');
const ContentLanguage = factoryHeader<string>('Content-Language', 'nl');

export {CSPNonce, CSRFToken, IsFormDesigner, ContentLanguage};

0 comments on commit 10e03a8

Please sign in to comment.