kryptheon 0.1.49 → 0.1.51

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/bin/kryptheon.js CHANGED
@@ -107,6 +107,8 @@ function usage() {
107
107
  console.log(' npx kryptheon code read your frontend code for text inserted as HTML');
108
108
  console.log(' npx kryptheon edge try unusual values in your recorded forms (adds test data; asks first)');
109
109
  console.log(' npx kryptheon reliability replay each flow 3 times, double-click what saves (adds test data; asks first)');
110
+ console.log(' npx kryptheon payments one test payment, its webhook sent again: given twice? (asks first)');
111
+ console.log(' ... --app <url> --port <n> --schema <name> --test-mode (database: KRYPTHEON_DATABASE_URL)');
110
112
  console.log(' npx kryptheon dashboard the page above (also: npx kryptheon, in a terminal)');
111
113
  console.log('');
112
114
  console.log(' add --quiet to check for one line when everything passes');
@@ -1020,16 +1022,19 @@ function reportSecrets(replacements) {
1020
1022
  // order mark that makes the first line unreadable.
1021
1023
  const hasEnv = fs.existsSync(path.join(USER_DIR, '.env'));
1022
1024
  const example = hasEnv ? null : secrets.writeEnvExample(USER_DIR, names);
1025
+ // Each account has its own name, so the owner's and a member's recordings
1026
+ // can both sign in (blind round 19).
1027
+ const whose = (item) => (item.account ? ' (' + String(item.field).toLowerCase() + ' of ' + item.account + ')' : '');
1023
1028
  if (example) {
1024
1029
  console.log(' A file called .env.example has been written here:');
1025
- for (const name of names) console.log(' ' + name + '=yourpassword');
1030
+ for (const item of replacements) console.log(' ' + item.envName + '=yourpassword' + whose(item));
1026
1031
  console.log('');
1027
- console.log(' Put your real password in it and save it as .env, in this folder.');
1032
+ console.log(' Put the real password in it and save it as .env, in this folder.');
1028
1033
  } else {
1029
1034
  console.log(' Before this can be checked, put it in a file called .env next to');
1030
1035
  console.log(' your tests, like this:');
1031
1036
  for (const item of replacements) {
1032
- console.log(' ' + item.envName + '=your ' + String(item.field).toLowerCase() + ' here');
1037
+ console.log(' ' + item.envName + '=your ' + String(item.field).toLowerCase() + ' here' + whose(item));
1033
1038
  }
1034
1039
  }
1035
1040
  console.log('');
@@ -2135,6 +2140,83 @@ async function probeCommand(check, args) {
2135
2140
  return report.flows.some((f) => f.state === 'tested') ? 0 : 2;
2136
2141
  }
2137
2142
 
2143
+ // --- payments ---------------------------------------------------------------
2144
+ //
2145
+ // One real test-mode payment, its webhook sent again: does the customer get it
2146
+ // twice? The work is in kryptheon-payments.js; what is said is in
2147
+ // kryptheon-payments-run.js. The database address is only ever read from the
2148
+ // environment, never from the command line, where it would be kept in the
2149
+ // shell's history.
2150
+
2151
+ function flagValue(args, name) {
2152
+ const at = args.indexOf(name);
2153
+ return at !== -1 && args[at + 1] && !/^--/.test(args[at + 1]) ? args[at + 1] : null;
2154
+ }
2155
+
2156
+ async function paymentsCommand(args) {
2157
+ if (!openStore()) return 1;
2158
+ const runner = require(path.join(PACKAGE_DIR, 'kryptheon-payments-run.js'));
2159
+ const port = Number(flagValue(args, '--port')) || runner.DEFAULT_PORT;
2160
+ let stopped = false;
2161
+ const onSigint = () => { stopped = true; };
2162
+ process.once('SIGINT', onSigint);
2163
+ console.log('');
2164
+ const out = await runner.run(USER_DIR, {
2165
+ app: flagValue(args, '--app') || 'http://localhost:3000',
2166
+ schema: flagValue(args, '--schema') || 'public',
2167
+ port: port,
2168
+ database: process.env.KRYPTHEON_DATABASE_URL || null,
2169
+ yes: args.includes('--yes'),
2170
+ testMode: args.includes('--test-mode'),
2171
+ ask: (question) => (process.stdin.isTTY ? askLine(' ' + question) : Promise.resolve('')),
2172
+ say: (line) => console.log(line ? ' ' + line : ''),
2173
+ stopped: () => stopped,
2174
+ });
2175
+ process.removeListener('SIGINT', onSigint);
2176
+ console.log('');
2177
+ return out.code;
2178
+ }
2179
+
2180
+ /**
2181
+ * What a replay that did not all pass is called on the page: "broke" only
2182
+ * when a flow that passed before fails now. Round 18 said "a flow broke"
2183
+ * about a recording that had never passed, while the replay said 0 broken.
2184
+ */
2185
+ function regressionSummary() {
2186
+ try {
2187
+ const dash = require(path.join(PACKAGE_DIR, 'kryptheon-dashboard.js'));
2188
+ const open = dash.buildState(USER_DIR).findings.filter((f) => f.check === 'regression');
2189
+ if (open.length && open.every((f) => f.status !== 'confirmed')) return 'a recording has never passed - see Findings (the recording or the app?)';
2190
+ } catch (err) {
2191
+ /* said the usual way */
2192
+ }
2193
+ return 'a flow broke - see Findings';
2194
+ }
2195
+
2196
+ /**
2197
+ * The payment check from the dashboard's button. The page has shown its words
2198
+ * and the person said yes there; the server checked the address is local.
2199
+ * Stop ends the wait for a payment, or the run between webhooks.
2200
+ */
2201
+ async function paymentsFromDashboard(run, say, control) {
2202
+ const runner = require(path.join(PACKAGE_DIR, 'kryptheon-payments-run.js'));
2203
+ let stopped = false;
2204
+ if (control) control.onStop(() => { stopped = true; });
2205
+ const out = await runner.run(USER_DIR, {
2206
+ app: run.app, schema: run.schema, port: runner.DEFAULT_PORT, database: run.connection,
2207
+ yes: true, testMode: run.testMode, say: say, stopped: () => stopped, stopWith: 'Stop on this page',
2208
+ });
2209
+ const report = out.report || { results: [] };
2210
+ const found = report.results.reduce((n, r) => n + r.findings.length, 0);
2211
+ const tested = report.results.filter((r) => !r.notTested.length).length;
2212
+ if (out.code === 2) {
2213
+ const why = (report.results.find((r) => r.notTested.length) || { notTested: [] }).notTested[0];
2214
+ return { ok: false, why: stopped ? 'stopped before a payment was checked' : why || 'nothing was tested - see what it printed' };
2215
+ }
2216
+ return { ok: true, summary: found ? found + (found === 1 ? ' problem found' : ' problems found') + ' - see Findings'
2217
+ : tested + (tested === 1 ? ' webhook' : ' webhooks') + ' sent again, and nothing was given twice' };
2218
+ }
2219
+
2138
2220
  // --- setup-ai ---------------------------------------------------------------
2139
2221
  //
2140
2222
  // An assistant that only reads code will happily call a change finished. These
@@ -2546,6 +2628,7 @@ async function probeRecheckCommand(target, options) {
2546
2628
  : target.kind === 'phone' ? 'replays ' + name + ' once, then once more at phone size, clicking every button with saving blocked. Two runs.'
2547
2629
  : target.kind === 'race' ? 'replays ' + name + ' once, then once more with this save sent twice at the same moment. Two runs.'
2548
2630
  : target.kind === 'shown' ? 'replays ' + name + ' three times, looking for what the save added on the page right after it. It is fixed only if it shows right away.'
2631
+ : target.kind === 'kept' ? 'replays ' + name + ' three times, opening the form again after each save and reading back what was typed. It is fixed only if the form shows it.'
2549
2632
  : 'replays ' + name + ' once, then once more with this step double-clicked. Two runs.');
2550
2633
  const confirmed = await probeConsent(what, addresses, Boolean(options && options.yes), PROBE_CHECKS[target.check].words);
2551
2634
  if (!confirmed) return 2;
@@ -2799,7 +2882,7 @@ function runFromDashboard(id, opened, say) {
2799
2882
  // A run that found broken flows is a run that finished; its results are
2800
2883
  // in the history the page reads next.
2801
2884
  code === 0 ? { ok: true, summary: 'every flow held' }
2802
- : code === 1 ? { ok: true, summary: 'a flow broke - see Findings' }
2885
+ : code === 1 ? { ok: true, summary: regressionSummary() }
2803
2886
  : { ok: false, why: 'the replay stopped with exit ' + code });
2804
2887
  }
2805
2888
  return { ok: false, why: '"' + id + '" cannot be run from the dashboard' };
@@ -3236,6 +3319,7 @@ async function dashboardCommand() {
3236
3319
  probeRecheck: (id, say, control, confirmed) => probeRecheckFromDashboard(id, say, control, confirmed),
3237
3320
  record: (address, say, options) => recordFromDashboard(address, say, options),
3238
3321
  db: (action, connection, say) => databaseFromDashboard(action, connection, say),
3322
+ payments: (run, say, control) => paymentsFromDashboard(run, say, control),
3239
3323
  words: (connection) => nightWords(connection),
3240
3324
  chooseFolder: () => chooseFolder(),
3241
3325
  openFolder: (folder) => openFolderDashboard(folder),
@@ -3562,6 +3646,8 @@ async function main() {
3562
3646
  case 'edge':
3563
3647
  case 'reliability':
3564
3648
  return finishWith(await probeCommand(command, rest));
3649
+ case 'payments':
3650
+ return finishWith(await paymentsCommand(rest));
3565
3651
  case '-v':
3566
3652
  case '--version':
3567
3653
  case 'version':
package/kryptheon-code.js CHANGED
@@ -34,6 +34,11 @@ const SKIP_DIRS = new Set([
34
34
  ]);
35
35
  const CODE_EXT = /\.(js|mjs|cjs|jsx|ts|tsx)$/i;
36
36
  const PAGE_EXT = /\.(html|htm|vue|svelte)$/i;
37
+ // Pages the server fills in before it sends them: EJS, Handlebars, Pug,
38
+ // Nunjucks and the rest. Not JavaScript - read for the one thing that matters
39
+ // here, a value written out without escaping. Found on blind round 19: an
40
+ // app's pages were all .ejs, none was read, and <%- c.body %> was missed.
41
+ const TEMPLATE_EXT = /\.(ejs|eta|hbs|handlebars|mustache|pug|jade|njk|nunjucks|liquid|twig|erb)$/i;
37
42
  const MAX_BYTES = 800 * 1024;
38
43
 
39
44
  // A call whose name says it makes text safe for HTML. Matched on the called
@@ -67,7 +72,7 @@ function listFiles(root) {
67
72
  const full = path.join(dir, entry.name);
68
73
  if (entry.isDirectory()) {
69
74
  if (!SKIP_DIRS.has(entry.name)) walk(full);
70
- } else if ((CODE_EXT.test(entry.name) || PAGE_EXT.test(entry.name)) && !/\.min\.js$/i.test(entry.name)) {
75
+ } else if ((CODE_EXT.test(entry.name) || PAGE_EXT.test(entry.name) || TEMPLATE_EXT.test(entry.name)) && !/\.min\.js$/i.test(entry.name)) {
71
76
  out.push(full);
72
77
  }
73
78
  }
@@ -203,6 +208,48 @@ function vHtmlIn(source) {
203
208
  return found;
204
209
  }
205
210
 
211
+ // How each kind of server template writes a value out without escaping it,
212
+ // and the way that escapes it - for the fix.
213
+ const RAW_OUTPUT = [
214
+ { ext: /\.(ejs|eta)$/i, engine: 'EJS', re: /<%-\s*([\s\S]*?)\s*[-_]?%>/g, raw: '<%- %>', escaped: '<%= %>' },
215
+ { ext: /\.(hbs|handlebars|mustache)$/i, engine: 'Handlebars', re: /\{\{\{\s*([\s\S]*?)\s*\}\}\}|\{\{&\s*([\s\S]*?)\s*\}\}/g, raw: '{{{ }}}', escaped: '{{ }}' },
216
+ { ext: /\.(pug|jade)$/i, engine: 'Pug', re: /^[ \t]*[\w.#:-]*(?:\([^)\n]*\))?!=[ \t]*(.+)$|!\{([^}\n]+)\}/gm, raw: '!= or !{ }', escaped: '= or #{ }' },
217
+ { ext: /\.(njk|nunjucks|liquid|twig)$/i, engine: 'Nunjucks', re: /\{\{\s*([^}]*?)\s*\|\s*(?:safe|raw)\b[^}]*\}\}/g, raw: '| safe', escaped: 'the value without | safe' },
218
+ { ext: /\.erb$/i, engine: 'ERB', re: /<%==\s*([\s\S]*?)\s*-?%>|<%=\s*raw[\s(]+([\s\S]*?)\)?\s*-?%>|<%=\s*([\s\S]*?)\.html_safe\s*-?%>/g, raw: '<%== %>, raw or html_safe', escaped: '<%= %>' },
219
+ ];
220
+ // What a template writes out raw on purpose: another template, a layout's
221
+ // page body, a block of a layout.
222
+ const TEMPLATE_PLUMBING = /^(include|partial|render|block|yield|defineContent|contentFor)\b|^(body|locals\.body|script|style|layout)$/;
223
+ // A field whose name says it holds what someone typed: worth more than a guess.
224
+ const TYPED_FIELD = /(^|\.)(body|content|description|desc|comment|comments|text|message|msg|note|notes|bio|about|title|name|summary|html|markdown|reply|caption|subject|label)$/i;
225
+
226
+ /**
227
+ * Values a server template writes out without escaping them: { line,
228
+ * expression, engine, raw, escaped }. A literal, a number, another template
229
+ * and anything an escaping call made safe are left out.
230
+ */
231
+ function rawOutputsIn(file, source) {
232
+ const kind = RAW_OUTPUT.find((k) => k.ext.test(file));
233
+ if (!kind) return [];
234
+ const found = [];
235
+ kind.re.lastIndex = 0;
236
+ let m;
237
+ while ((m = kind.re.exec(source))) {
238
+ const expression = String(m.slice(1).find((g) => g !== undefined) || '').trim().replace(/;$/, '').trim();
239
+ if (!expression || TEMPLATE_PLUMBING.test(expression)) continue;
240
+ if (/^(['"`])[^'"`]*\1$/.test(expression) || /^-?\d+(\.\d+)?$/.test(expression)) continue;
241
+ const call = /^([\w$.]+)\s*\(/.exec(expression);
242
+ if (call && MAKES_SAFE.test(call[1].split('.').pop())) continue;
243
+ // JSON written into a page script: its own risk, said nowhere here.
244
+ if (call && /^JSON\.stringify$/.test(call[1])) continue;
245
+ const last = (/([\w$]+)\s*$/.exec(expression) || [])[1] || '';
246
+ if (/^[\w$.]+$/.test(expression) && (NUMERIC_PROPS.test(last) || NUMERIC_NAMES.test(last) || TAGLESS_COLUMNS.has(last))) continue;
247
+ found.push({ line: source.slice(0, m.index).split('\n').length + (/^\s*\n/.test(m[0]) ? 1 : 0), expression: expression.slice(0, 120),
248
+ engine: kind.engine, raw: kind.raw, escaped: kind.escaped, typed: TYPED_FIELD.test(expression) });
249
+ }
250
+ return found;
251
+ }
252
+
206
253
  function calleeName(node) {
207
254
  if (!node) return '';
208
255
  if (node.type === 'Identifier') return node.name;
@@ -1442,6 +1489,8 @@ function importResolver(parser, root) {
1442
1489
  const MUTATORS = /^(push|pop|shift|unshift|splice|sort|reverse|fill|copyWithin|set|add|delete|clear)$/;
1443
1490
  // Calls that only read what they are given.
1444
1491
  const READS_ONLY = /^(String|Number|Boolean|JSON\.stringify|console\.\w+|Array\.isArray|Object\.(keys|values|entries|freeze|isFrozen))$/;
1492
+ // Calls that only ask whether an object has a key.
1493
+ const HAS_KEY = /(^|\.)(hasOwnProperty|propertyIsEnumerable)\.call$|^Object\.hasOwn$|^Reflect\.has$/;
1445
1494
  // Methods that only read their argument: list.concat(demo.changes) builds a
1446
1495
  // new list and leaves demo alone. push() and the like are not here - they put
1447
1496
  // the value somewhere it can be written through.
@@ -1477,6 +1526,9 @@ function writtenThrough(ref, depth) {
1477
1526
  const full = callee.type === 'MemberExpression' && callee.object.type === 'Identifier'
1478
1527
  ? callee.object.name + '.' + calleeName(callee) : calleeName(callee);
1479
1528
  if (/MemberExpression$/.test(callee.type) && READS_ARGUMENT.test(calleeName(callee))) return false;
1529
+ // Asking whether it has a key reads it (blind round 20, DECOY-05:
1530
+ // Object.prototype.hasOwnProperty.call(styles, status)).
1531
+ if (HAS_KEY.test(memberPath(callee))) return false;
1480
1532
  return !(MAKES_SAFE.test(calleeName(callee)) || READS_ONLY.test(full));
1481
1533
  }
1482
1534
  }
@@ -1739,6 +1791,54 @@ function scanProject(root, options) {
1739
1791
  }
1740
1792
  return { ran: true, filesRead: filesRead, findings: secrets.concat(findings.map(describe)), unreadable: unreadable };
1741
1793
 
1794
+ /**
1795
+ * Whether a function the app declares under `name` (in its own JavaScript,
1796
+ * where a template's helpers live - server.js) returns only text that
1797
+ * cannot carry a tag: every return judged as any value put into a page is.
1798
+ * False when it is not found, or found more than once.
1799
+ */
1800
+ function helperIsSafe(name) {
1801
+ // Kept on the function: readAll runs before any const below its call.
1802
+ const helperSafety = (helperIsSafe.cache = helperIsSafe.cache || new Map());
1803
+ if (helperSafety.has(name)) return helperSafety.get(name);
1804
+ let verdict = false;
1805
+ const declared = new RegExp('(function\\s+' + name + '\\s*\\(|(const|let|var)\\s+' + name + '\\s*=)');
1806
+ const homes = files.filter((f) => CODE_EXT.test(f)).filter((f) => {
1807
+ try {
1808
+ return fs.statSync(f).size <= MAX_BYTES && declared.test(fs.readFileSync(f, 'utf8'));
1809
+ } catch (err) {
1810
+ return false;
1811
+ }
1812
+ });
1813
+ if (homes.length === 1) {
1814
+ try {
1815
+ const code = fs.readFileSync(homes[0], 'utf8');
1816
+ const ast = parser.babelParse(code, homes[0], true);
1817
+ PROGRAM_FILE.set(ast.program, homes[0]);
1818
+ const saved = FN_PATHS;
1819
+ FN_PATHS = new WeakMap();
1820
+ let fnPath = null;
1821
+ parser.traverse(ast, {
1822
+ Function(p) {
1823
+ FN_PATHS.set(p.node, p);
1824
+ },
1825
+ Program(p) {
1826
+ fnPath = localFunction(name, p.scope);
1827
+ },
1828
+ });
1829
+ if (fnPath) {
1830
+ const returns = returnsOf(fnPath);
1831
+ verdict = returns.length > 0 && worst(returns.map((r) => classify(r.node, r.scope, code, 0))) === 'safe';
1832
+ }
1833
+ FN_PATHS = saved;
1834
+ } catch (err) {
1835
+ verdict = false;
1836
+ }
1837
+ }
1838
+ helperSafety.set(name, verdict);
1839
+ return verdict;
1840
+ }
1841
+
1742
1842
  function readAll() {
1743
1843
  for (const full of files) {
1744
1844
  let size = 0;
@@ -1755,7 +1855,19 @@ function scanProject(root, options) {
1755
1855
  const source = fs.readFileSync(full, 'utf8');
1756
1856
  filesRead++;
1757
1857
  for (const k of keys.secretsIn(rel, source, loadedBy)) secrets.push(k);
1758
- const pieces = PAGE_EXT.test(full) ? scriptsIn(source) : [{ code: source, line: 1 }];
1858
+ // A template's own scripts are read as any page's are, unless the
1859
+ // template fills them in itself - then they are not JavaScript yet.
1860
+ const pieces = TEMPLATE_EXT.test(full) ? scriptsIn(source).filter((s) => !/<%|\{\{|[#!]\{/.test(s.code))
1861
+ : PAGE_EXT.test(full) ? scriptsIn(source) : [{ code: source, line: 1 }];
1862
+ if (TEMPLATE_EXT.test(full)) {
1863
+ for (const t of rawOutputsIn(full, source)) {
1864
+ // <%- statusPill(a.status) %>: a helper of the app's own whose every
1865
+ // return is fixed markup is not a way in (blind round 20, DECOY-05).
1866
+ const call = /^([A-Za-z_$][\w$]*)\s*\(/.exec(t.expression);
1867
+ if (call && helperIsSafe(call[1])) continue;
1868
+ findings.push({ file: rel, line: t.line, sink: t.engine + ' ' + t.raw, expression: t.expression, origin: t.typed ? 'template-typed' : 'template', template: t });
1869
+ }
1870
+ }
1759
1871
  for (const piece of pieces) {
1760
1872
  try {
1761
1873
  for (const f of sinksIn(parser, piece.code, full, piece.line, resolver)) findings.push(Object.assign({ file: rel }, f));
@@ -1776,6 +1888,8 @@ const ORIGIN_WORDS = {
1776
1888
  network: 'read from a server response',
1777
1889
  error: "an error's message, which often carries text a server sent",
1778
1890
  unknown: 'from somewhere the code alone cannot pin down',
1891
+ template: 'filled in by the server, from whatever it passes to the page - often a row from the database',
1892
+ 'template-typed': 'filled in by the server from a field whose name says it holds text someone typed',
1779
1893
  };
1780
1894
 
1781
1895
  // Wrapped here rather than by whoever prints it: this is pasted into a chat
@@ -1832,9 +1946,51 @@ function describeRedirect(f) {
1832
1946
  };
1833
1947
  }
1834
1948
 
1949
+ /** A server template writing a value out unescaped, in the same shape. */
1950
+ function describeTemplate(f) {
1951
+ const t = f.template;
1952
+ const typed = f.origin === 'template-typed';
1953
+ const fixPrompt = [
1954
+ 'My app may have a security problem - please check it rather than assume it.',
1955
+ '',
1956
+ 'In ' + f.file + ' at line ' + f.line + ', the page template writes this value into the page without escaping it (' + t.engine + ' ' + t.raw + '):',
1957
+ '',
1958
+ ' ' + f.expression,
1959
+ '',
1960
+ 'The value is ' + ORIGIN_WORDS[f.origin] + '. If it can ever contain text a user or another account typed, a "<" in it ' +
1961
+ 'becomes a real tag and can run script in the page of everyone who opens it, with their session.',
1962
+ '',
1963
+ 'Fix it so the value is shown as text: write it with ' + t.escaped + ' instead of ' + t.raw + ', which escapes it. If it is ' +
1964
+ 'meant to keep some formatting, clean it on the server with a sanitizer (sanitize-html, or DOMPurify) before it is ' +
1965
+ 'passed to the template, and keep ' + t.raw + ' only for that cleaned value.',
1966
+ '',
1967
+ 'Change only how this value is written, and look for the same pattern in the other templates. Afterwards, save a value ' +
1968
+ 'with < and & in it and open the page: both must show as typed.',
1969
+ ].map((p) => (p.startsWith(' ') ? p : wrap(p, 72))).join('\n');
1970
+ return {
1971
+ kind: 'unsafe-html',
1972
+ status: 'verification required',
1973
+ evidence: 'code analysis',
1974
+ severity: typed ? 'HIGH' : 'MEDIUM',
1975
+ confidence: typed ? 'medium' : 'low',
1976
+ file: f.file,
1977
+ line: f.line,
1978
+ sink: f.sink,
1979
+ expression: f.expression,
1980
+ origin: f.origin,
1981
+ parts: [],
1982
+ via: null,
1983
+ helper: null,
1984
+ headline: 'The template ' + f.file + ':' + f.line + ' writes ' + f.expression + ' into the page without escaping it (' + t.engine + ' ' + t.raw + ')' +
1985
+ (typed ? ' - a field that holds what someone typed.' : '.'),
1986
+ fixPrompt: fixPrompt,
1987
+ };
1988
+ }
1989
+
1835
1990
  /** One finding, in the shape every Kryptheon report uses. */
1836
1991
  function describe(f) {
1837
1992
  if (f.kind === 'redirect') return describeRedirect(f);
1993
+ if (f.template) return describeTemplate(f);
1838
1994
  const severity = f.origin === 'unknown' ? 'MEDIUM' : 'HIGH';
1839
1995
  const how = f.sink === 'v-html' ? 'v-html' : f.sink;
1840
1996
  // Where the helper builds it: its own file when it is another one.
@@ -302,8 +302,8 @@
302
302
  });
303
303
  }
304
304
 
305
- var CHECK_NAME = { regression: 'Recorded flows', frontend: 'Frontend code', data: 'Database', edge: 'Input and edge cases', reliability: 'Reliability' };
306
- var CHECK_TONE = { regression: 'sun', frontend: 'amber', data: 'dusk', edge: 'ember', reliability: 'ember' };
305
+ var CHECK_NAME = { regression: 'Recorded flows', frontend: 'Frontend code', data: 'Database', edge: 'Input and edge cases', reliability: 'Reliability', payments: 'Payments' };
306
+ var CHECK_TONE = { regression: 'sun', frontend: 'amber', data: 'dusk', edge: 'ember', reliability: 'ember', payments: 'ember' };
307
307
 
308
308
  function counts() {
309
309
  var confirmed = state.findings.filter(function (f) { return f.status === 'confirmed'; }).length;
@@ -867,7 +867,13 @@
867
867
  head.appendChild(icon(openRow === f.id ? 'change' : 'arrow', 18));
868
868
  head.addEventListener('click', function () { openRow = openRow === f.id ? null : f.id; renderFindings(); });
869
869
  card.appendChild(head);
870
- if (probeAsking && probeAsking.finding && probeAsking.finding.id === f.id) {
870
+ if (paymentsAsking && paymentsAsking.finding && paymentsAsking.finding.id === f.id) {
871
+ var askingPay = el('div', 'controls f-quick');
872
+ askingPay.appendChild(paymentsBox('Yes, wait for one more test payment', function (body) {
873
+ runJob('/api/payments', Object.assign({ id: f.id }, body)).then(function (done) { heard(f, (done && done.result) || {}); }, function () {});
874
+ }));
875
+ card.appendChild(askingPay);
876
+ } else if (probeAsking && probeAsking.finding && probeAsking.finding.id === f.id) {
871
877
  var askingProbe = el('div', 'controls f-quick');
872
878
  askingProbe.appendChild(probeConsentBox(probeAsking.check, 'Yes, try it again', function (body) {
873
879
  runJob('/api/recheck', Object.assign({ id: f.id }, body)).then(function (done) { heard(f, (done && done.result) || {}); }, function () {});
@@ -884,7 +890,7 @@
884
890
  var qre = button('sm', 'refresh', 'Re-check', function () { recheck(f); });
885
891
  qre.setAttribute('data-action', 'recheck');
886
892
  qre.disabled = busy;
887
- quick.appendChild(withCommand(qre, f.check === 'data' ? 'npx kryptheon-night' : 'npx kryptheon recheck ' + f.id));
893
+ quick.appendChild(withCommand(qre, f.check === 'data' ? 'npx kryptheon-night' : f.check === 'payments' ? 'npx kryptheon payments' : 'npx kryptheon recheck ' + f.id));
888
894
  quick.appendChild(whenTag('after every change'));
889
895
  card.appendChild(quick);
890
896
  }
@@ -998,6 +1004,46 @@
998
1004
  box.appendChild(row);
999
1005
  return box;
1000
1006
  }
1007
+ // The payment check's yes: its words, the app on this computer it sends to,
1008
+ // and - only when Razorpay's mode cannot be read from the app's .env - the
1009
+ // person's own word that it is test mode. For a re-check, the finding.
1010
+ var paymentsAsking = null;
1011
+ function paymentsBox(yesLabel, onYes) {
1012
+ var check = state.checks.filter(function (c) { return c.id === 'payments'; })[0];
1013
+ var ask = (check && check.payments) || { app: 'http://localhost:3000', lines: [] };
1014
+ var box = el('div', 'consent');
1015
+ box.appendChild(el('div', 'd-step', 'YOUR APP PROCESSES THE COPIES'));
1016
+ box.appendChild(linesBox('help', ask.lines));
1017
+ var appLabel = el('label', 'tick', 'Your app on this computer: ');
1018
+ var app = el('input', 'field');
1019
+ app.type = 'text';
1020
+ app.value = ask.app;
1021
+ app.setAttribute('aria-label', 'Your app\'s address on this computer');
1022
+ appLabel.appendChild(app);
1023
+ box.appendChild(appLabel);
1024
+ var label = el('label', 'tick');
1025
+ var tick = el('input');
1026
+ tick.type = 'checkbox';
1027
+ label.appendChild(tick);
1028
+ label.appendChild(document.createTextNode(' It is Razorpay\'s TEST mode (only needed when your .env has no rzp_test_ key)'));
1029
+ box.appendChild(label);
1030
+ var row = el('div', 'd-actions');
1031
+ var yes = button('sun sm', 'check', yesLabel, function () {
1032
+ var connection = dbInput.value.trim();
1033
+ if (!connection) { toast('Paste your DEVELOPMENT database\'s connection string in "Connect your database" first.'); dbInput.focus(); return; }
1034
+ var body = { consent: true, connection: connection, app: app.value.trim(), testMode: tick.checked };
1035
+ paymentsAsking = null;
1036
+ renderChecks();
1037
+ renderFindings();
1038
+ onYes(body);
1039
+ });
1040
+ yes.setAttribute('data-action', 'payments');
1041
+ yes.disabled = busy;
1042
+ row.appendChild(yes);
1043
+ row.appendChild(button('sm', null, 'Cancel', function () { paymentsAsking = null; renderChecks(); renderFindings(); }));
1044
+ box.appendChild(row);
1045
+ return box;
1046
+ }
1001
1047
  function checkSwitch(c) {
1002
1048
  var sw = el('label', 'switch');
1003
1049
  var input = el('input');
@@ -1045,7 +1091,21 @@
1045
1091
  (lr.stopped ? ' (stopped)' : '') + ', ' + lr.held + ' held, ' + lr.notTested + ' not tested, ' +
1046
1092
  plural(lr.testData, 'test write') + ' left in your app.'));
1047
1093
  }
1048
- if (c.asks && c.enabled) {
1094
+ if (c.id === 'payments' && c.enabled) {
1095
+ if (paymentsAsking && !paymentsAsking.finding) {
1096
+ card.appendChild(paymentsBox('Yes, start and wait for my test payment', function (body) {
1097
+ runJob('/api/payments', body).then(function (done) {
1098
+ var r = (done && done.result) || {};
1099
+ toast(r.ok ? 'Finished: ' + (r.summary || 'done') : 'It could not finish' + (r.why ? ' - ' + r.why : ''));
1100
+ }, function () {});
1101
+ }));
1102
+ } else {
1103
+ var pay = button('sm', 'play', 'Check payments - start, then pay', function () { paymentsAsking = {}; renderChecks(); });
1104
+ pay.setAttribute('data-action', 'payments');
1105
+ pay.disabled = busy;
1106
+ card.appendChild(withCommand(pay, 'npx kryptheon payments'));
1107
+ }
1108
+ } else if (c.asks && c.enabled) {
1049
1109
  if (probeAsking && probeAsking.check === c.id && !probeAsking.finding) {
1050
1110
  card.appendChild(probeConsentBox(c.id, 'Yes, add test data and run', function (body) {
1051
1111
  runJob('/api/probe', Object.assign({ id: c.id }, body)).then(function (done) {
@@ -1070,6 +1130,16 @@
1070
1130
  box.appendChild(card);
1071
1131
  });
1072
1132
  byId('naBadge').textContent = String(missing);
1133
+ var nc = byId('notCheckedList');
1134
+ clear(nc);
1135
+ (state.notChecked || []).forEach(function (n) {
1136
+ var row = el('div', 'nc-row');
1137
+ row.appendChild(el('div', 'c-name', n.what));
1138
+ row.appendChild(el('div', 'c-what', n.why));
1139
+ row.appendChild(el('div', 'c-what nc-yourself', 'Check it yourself: ' + n.yourself));
1140
+ nc.appendChild(row);
1141
+ });
1142
+ byId('notCheckedBadge').textContent = String((state.notChecked || []).length);
1073
1143
  }
1074
1144
 
1075
1145
  function renderRuns() {
@@ -1130,6 +1200,8 @@
1130
1200
  // An input finding is re-checked by typing its value again, which adds
1131
1201
  // test data to the app: the same yes as the check's own button, first.
1132
1202
  if (f.check === 'edge' || f.check === 'reliability') { probeAsking = { check: f.check, finding: f }; openRow = null; renderFindings(); return; }
1203
+ // A payment finding needs a new payment: the same yes, and one more test payment.
1204
+ if (f.check === 'payments') { paymentsAsking = { finding: f }; openRow = null; renderFindings(); return; }
1133
1205
  runJob('/api/recheck', { id: f.id }).then(function (done) { heard(f, (done && done.result) || {}); }, function () {});
1134
1206
  }
1135
1207
  function heard(f, r) {
@@ -1320,6 +1392,6 @@
1320
1392
  // while a yes is being asked for, and not while someone is typing.
1321
1393
  setInterval(function () {
1322
1394
  var typing = document.activeElement === dbInput || document.activeElement === recordInput;
1323
- if (!busy && !openRow && !pending && !probeAsking && !typing) load();
1395
+ if (!busy && !openRow && !pending && !probeAsking && !paymentsAsking && !typing) load();
1324
1396
  }, 5000);
1325
1397
  })();
@@ -239,6 +239,11 @@
239
239
  .check .c-name { font-weight: 800; font-stretch: 74%; font-size: 1.2rem; line-height: 1.05; text-transform: uppercase; }
240
240
  .check .c-what { font-size: 13.5px; line-height: 1.6; color: var(--muted); }
241
241
  .check .btn { align-self: flex-start; margin-top: auto; }
242
+ .not-checked { border-top: 1px solid var(--line); }
243
+ .nc-row { padding: 14px 4px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
244
+ .nc-row .c-name { font-weight: 700; }
245
+ .nc-row .c-what { font-size: 13.5px; line-height: 1.6; color: var(--muted); }
246
+ .nc-row .nc-yourself { color: var(--ink); }
242
247
  .na-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); border-top: 1px solid var(--line); }
243
248
  .na { display: flex; align-items: center; gap: 12px; padding: 14px 4px; font-weight: 700; font-stretch: 74%; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); }
244
249
  .na .na-lock { display: block; margin-top: 2px; font-size: 9px; font-weight: 400; color: rgba(18, 22, 29, 0.42); }
@@ -428,6 +433,10 @@
428
433
  <div class="card-head"><div><h3>Coming soon</h3><div class="c-sub">Being built, in this order - never shown as passed</div></div><span class="badge" id="naBadge">0</span></div>
429
434
  <div class="na-grid" id="naList"></div>
430
435
  </div>
436
+ <div class="card gap" id="notCheckedCard">
437
+ <div class="card-head"><div><h3>Not checked by Kryptheon</h3><div class="c-sub">No check here looks at these - a clean report says nothing about them. Check them yourself.</div></div><span class="badge" id="notCheckedBadge">0</span></div>
438
+ <div class="not-checked" id="notCheckedList"></div>
439
+ </div>
431
440
  </section>
432
441
 
433
442
  <section class="view" id="view-runs" hidden>