update devDependencies, fix lint issues
[squeep-authentication-module] / lib / template / settings-html.js
index 42bfdcda4fedae3e6c12a25177cb87943f41bfbc..aba75f921126dbb42682bd77adf5f43df2b976ed 100644 (file)
@@ -6,6 +6,27 @@ const { TemplateHelper: th } = require('@squeep/html-template-helper');
 const { sessionNavLinks } = require('./helpers');
 const { TOTP } = require('@squeep/totp');
 
+/**
+ * @typedef {object} Context
+ * @property {string=} otpConfirmBox encrypted otp state
+ * @property {string=} otpConfirmKey otp key to confirm adding to identifier
+ * @property {string=} authenticationId identifier
+ */
+
+/**
+ * @alias {object} HtmlOptions
+ */
+
+/**
+ * @typedef {import('../session-manager').AppTemplateCallback} AppTemplateCallback
+ */
+
+/**
+ * Render password update section.
+ * @param {Context} ctx context
+ * @param {HtmlOptions} htmlOptions options
+ * @returns {string} section
+ */
 function updatePasswordSection(ctx, htmlOptions) {
   return `\t\t\t<section class="settings-update-password">
 \t\t\t\t<h2>Password</h2>
@@ -28,6 +49,12 @@ function updatePasswordSection(ctx, htmlOptions) {
 }
 
 
+/**
+ *
+ * @param {Context} ctx context
+ * @param {HtmlOptions} htmlOptions options
+ * @returns {string} otp enable section
+ */
 function enableOTPSection(ctx, htmlOptions) {
   return `\t\t\t<section class="settings-otp">
 \t\t\t\t<h2>OTP 2FA</h2>
@@ -41,6 +68,12 @@ function enableOTPSection(ctx, htmlOptions) {
 }
 
 
+/**
+ *
+ * @param {Context} ctx context
+ * @param {htmlOptions} htmlOptions options
+ * @returns {string} otp confirm section
+ */
 function confirmOTPSection(ctx, htmlOptions) {
   const { secret, svg, uri } = TOTP.createKeySVG({
     accountname: ctx.authenticationId,
@@ -74,6 +107,12 @@ ${svg}
 }
 
 
+/**
+ *
+ * @param {Context} ctx context
+ * @param {HtmlOptions} htmlOptions options
+ * @returns {string} disable otp section
+ */
 function disableOTPSection(ctx, htmlOptions) {
   return `\t\t\t<section class="settings-otp">
 \t\t\t\t<h2>OTP 2FA</h2>
@@ -85,6 +124,12 @@ function disableOTPSection(ctx, htmlOptions) {
 }
 
 
+/**
+ *
+ * @param {Context} ctx context
+ * @param {HtmlOptions} htmlOptions options
+ * @returns {string} otp section
+ */
 function OTPSection(ctx, htmlOptions) {
   const OTPToggle = ctx.otpKey ? disableOTPSection : enableOTPSection;
   const OTPContent = ctx.otpConfirmBox ? confirmOTPSection : OTPToggle;
@@ -93,7 +138,13 @@ function OTPSection(ctx, htmlOptions) {
     '\t\t\t</section>';
 }
 
-
+/**
+ * Render settings form for managing credential and otp key.
+ * @param {Context} ctx context
+ * @param {object} options options
+ * @param {AppTemplateCallback} appCb function to mogrify htmlOptions
+ * @returns {string} page
+ */
 module.exports = (ctx, options, appCb = () => {}) => {
   const pagePathLevel = 1;
   const htmlOptions = {