@jrpool/kilotest 37.0.0 → 37.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/alerts.js CHANGED
@@ -19,7 +19,7 @@ const ALERT_FROM = process.env.ALERT_FROM;
19
19
  // FUNCTIONS
20
20
 
21
21
  // Sends an email alert to a manager.
22
- exports.sendAlert = (subject, body) => new Promise((resolve, reject) => {
22
+ exports.sendAlert = (subject, body) => new Promise(resolve => {
23
23
  // If the alert configuration is complete:
24
24
  if (MANAGER_EMAIL && ALERT_API_HOST && ALERT_API_PATH && ALERT_API_KEY && ALERT_FROM) {
25
25
  const payload = JSON.stringify({
package/eslint.config.mjs CHANGED
@@ -3,7 +3,7 @@ import globals from "globals";
3
3
  import json from "@eslint/json";
4
4
  import markdown from "@eslint/markdown";
5
5
  import css from "@eslint/css";
6
- import { defineConfig } from "eslint/config";
6
+ import {defineConfig} from "eslint/config";
7
7
 
8
8
  export default defineConfig([
9
9
  {
@@ -18,6 +18,9 @@ export default defineConfig([
18
18
  extends: ["js/recommended"],
19
19
  languageOptions: {
20
20
  globals: globals.node
21
+ },
22
+ rules: {
23
+ "no-control-regex": "off"
21
24
  }
22
25
  },
23
26
  {
package/index.js CHANGED
@@ -30,6 +30,7 @@ const {
30
30
  } = require('./util');
31
31
  const {handleMCP, mcpPath} = require('./mcp');
32
32
  const fs = require('fs/promises');
33
+ const {handleComment} = require('./tutorial/index');
33
34
  const http = require('http');
34
35
  const https = require('https');
35
36
  const path = require('path');
@@ -762,7 +763,7 @@ const requestHandler = async (request, response) => {
762
763
  else if (pageName === 'tutorialComment.html') {
763
764
  const {content} = postData;
764
765
  setHeaders('application/json', null, 'low');
765
- const answerData = await require(path.join(__dirname, 'tutorial', 'index')).saveComment(content);
766
+ const answerData = await handleComment(content);
766
767
  if (answerData.status === 'ok') {
767
768
  response.end(JSON.stringify({status: 'ok'}));
768
769
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jrpool/kilotest",
3
- "version": "37.0.0",
3
+ "version": "37.1.0",
4
4
  "description": "An ensemble testing service with a focus on accessibility",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tutorial/index.js CHANGED
@@ -5,7 +5,8 @@
5
5
 
6
6
  // IMPORTS
7
7
 
8
- const {getJSON} = require('../util');
8
+ const {sendAlert} = require('../alerts');
9
+ const {getJSON, getNowStamp} = require('../util');
9
10
  const fs = require('fs/promises');
10
11
  const path = require('path');
11
12
 
@@ -31,7 +32,7 @@ exports.answer = async () => {
31
32
  };
32
33
  };
33
34
  // Sanitizes and saves a tutorial comment to comments.json.
34
- exports.saveComment = async content => {
35
+ exports.handleComment = async content => {
35
36
  if (!content || typeof content !== 'string') {
36
37
  return {status: 'error', message: 'No content provided'};
37
38
  }
@@ -41,13 +42,22 @@ exports.saveComment = async content => {
41
42
  }
42
43
  let comments = [];
43
44
  try {
45
+ // Get the existing comments.
44
46
  const existing = await fs.readFile(commentsPath, 'utf8');
45
47
  comments = JSON.parse(existing);
46
48
  }
47
- catch (_) {
48
- // File absent or unparsable; start a fresh array.
49
+ // If there are none:
50
+ catch {
51
+ // Initialize a comments array.
49
52
  }
50
- comments.push({timeStamp: new Date().toISOString(), content: sanitized});
53
+ // Add the comment to the existing ones.
54
+ comments.push({
55
+ timeStamp: getNowStamp(),
56
+ content: sanitized
57
+ });
58
+ // Save the revised comments.
51
59
  await fs.writeFile(commentsPath, getJSON(comments));
60
+ // Send an alert to the manager.
61
+ await sendAlert('New tutorial comment received', 'A new tutorial comment has been received.');
52
62
  return {status: 'ok'};
53
63
  };