kryptheon 0.1.54 → 0.1.56
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/README.md +79 -0
- package/bin/kryptheon.js +143 -1
- package/kryptheon-api.js +896 -0
- package/kryptheon-dashboard-page.js +1 -1
- package/kryptheon-dashboard.js +61 -6
- package/kryptheon-look.js +8 -0
- package/kryptheon-map.js +2910 -0
- package/kryptheon-payments-run.js +42 -0
- package/kryptheon-payments.js +39 -1
- package/kryptheon-roles.js +85 -10
- package/package.json +8 -4
|
@@ -128,6 +128,26 @@ function fixPrompt(result, f) {
|
|
|
128
128
|
'Keep the signature check first. Do not change anything else. Afterwards I will run: npx kryptheon payments',
|
|
129
129
|
]).join('\n');
|
|
130
130
|
}
|
|
131
|
+
if (f.kind === 'paid-nothing') {
|
|
132
|
+
return [
|
|
133
|
+
'A customer can pay in my app and get nothing for it.',
|
|
134
|
+
'',
|
|
135
|
+
'I tested it with a real ' + ADJ(result.provider) + ' test payment: the ' + f.events.join(' / ') + ' webhook reached ' + where +
|
|
136
|
+
', which answered ' + f.status + (f.said ? ' (' + f.said.slice(0, 120) + ')' : '') +
|
|
137
|
+
(f.logged ? ' and changed nothing in my database but its log.' : ' and changed nothing in my database.'),
|
|
138
|
+
f.before ? 'Nothing before it (checkout, the payment page) gave anything either, so the plan, credits or order this payment buys was never given.'
|
|
139
|
+
: 'So the plan, credits or order this payment buys was not given by the webhook.',
|
|
140
|
+
'',
|
|
141
|
+
'First tell me where this app is meant to give what a payment buys. Then:',
|
|
142
|
+
'- make ' + where + ' act on the event ' + who + ' really sends for a finished payment (' +
|
|
143
|
+
(result.provider === 'razorpay' ? 'payment.captured / order.paid' : result.provider === 'stripe' ? 'checkout.session.completed / invoice.paid' : f.events.join(' / ')) +
|
|
144
|
+
') - check the event names my handler listens for against ' + who + '\'s dashboard;',
|
|
145
|
+
'- find the customer from the payment (the notes, order id or customer id my checkout passes) and give the plan, credits or order;',
|
|
146
|
+
'- save the payment id with a UNIQUE rule first, so the same webhook sent again gives nothing twice;',
|
|
147
|
+
'- answer 200 once it is saved.',
|
|
148
|
+
'Keep the signature check first. Do not change anything else. Afterwards I will run: npx kryptheon payments',
|
|
149
|
+
].join('\n');
|
|
150
|
+
}
|
|
131
151
|
if (f.kind === 'refund-nothing') {
|
|
132
152
|
return [
|
|
133
153
|
'When ' + who + ' tells my app a payment was refunded, my app changes nothing.',
|
|
@@ -220,6 +240,18 @@ function findingLines(result, f) {
|
|
|
220
240
|
' Your database changed again:',
|
|
221
241
|
].concat(f.changes.map((c) => ' ' + c), f.noise.length ? [' Also changed, which is normal:'].concat(f.noise.map((c) => ' ' + c)) : []);
|
|
222
242
|
}
|
|
243
|
+
if (f.kind === 'paid-nothing') {
|
|
244
|
+
return [
|
|
245
|
+
'HIGH A payment went through, and your app gave nothing - to check.',
|
|
246
|
+
'',
|
|
247
|
+
' ' + f.events.join(' / ') + ' reached ' + result.path + ', which answered ' + f.status +
|
|
248
|
+
(f.said ? ' (' + f.said.slice(0, 80) + ')' : '') + (f.logged ? ' and wrote nothing but its log.' : ' and wrote nothing.'),
|
|
249
|
+
f.before ? ' Nothing before it gave anything either (no plan, credits or payment saved at checkout).'
|
|
250
|
+
: ' What the app saved before this webhook was not read.',
|
|
251
|
+
' The customer paid and has nothing to show for it. Fine if your app gives it some',
|
|
252
|
+
' other way (by hand, from another service); a hole if it is meant to give it here.',
|
|
253
|
+
];
|
|
254
|
+
}
|
|
223
255
|
if (f.kind === 'refund-nothing') {
|
|
224
256
|
return [
|
|
225
257
|
'MEDIUM A refund took nothing back - to check.',
|
|
@@ -385,6 +417,12 @@ async function run(root, options) {
|
|
|
385
417
|
// being checked - what that check sends would be in it.
|
|
386
418
|
let beforeRead = null;
|
|
387
419
|
let checking = false;
|
|
420
|
+
// The database when nothing is being paid: now, and again after each
|
|
421
|
+
// payment is checked. What changed from it to a payment's first webhook is
|
|
422
|
+
// what checkout gave, so a payment the webhook gives nothing for is not
|
|
423
|
+
// called empty when the page already gave it.
|
|
424
|
+
const readQuiet = () => payments.snapshot(client, schema, tables).catch(() => null);
|
|
425
|
+
let quiet = await readQuiet();
|
|
388
426
|
const readBefore = () => {
|
|
389
427
|
if (checking) return Promise.resolve(null);
|
|
390
428
|
return (beforeRead = beforeRead || (async () => {
|
|
@@ -436,6 +474,8 @@ async function run(root, options) {
|
|
|
436
474
|
const hooks = capture.captured.slice(next);
|
|
437
475
|
next = capture.captured.length;
|
|
438
476
|
const before = beforeRead ? await beforeRead.catch(() => null) : null;
|
|
477
|
+
const since = quiet && before && !before.late ? payments.writesOf(payments.diff(quiet, before.snap)) : null;
|
|
478
|
+
const groupTypes = hooks.map((h) => payments.eventOf(h).type);
|
|
439
479
|
checking = true;
|
|
440
480
|
for (const [i, hook] of hooks.entries()) {
|
|
441
481
|
const mode = payments.modeOf(hook.provider, hook.body, env);
|
|
@@ -453,6 +493,7 @@ async function run(root, options) {
|
|
|
453
493
|
const options_ = { client: client, schema: schema, target: app, hook: hook, say: (l) => say(' ' + l),
|
|
454
494
|
quietMs: options.quietMs, minMs: options.minMs, maxMs: options.maxMs,
|
|
455
495
|
before: i === 0 && before && !before.late ? { snap: before.snap, shared: hooks.length > 1 } : null,
|
|
496
|
+
sinceWrites: i === 0 ? since : null, groupTypes: i === 0 ? groupTypes : null,
|
|
456
497
|
beforeWhy: i > 0 ? 'what it wrote is counted with the first webhook of this payment, which arrived with it'
|
|
457
498
|
: before && before.late ? 'reading the database first took too long, so the webhook went on before it finished' : '' };
|
|
458
499
|
say('');
|
|
@@ -476,6 +517,7 @@ async function run(root, options) {
|
|
|
476
517
|
}
|
|
477
518
|
checking = false;
|
|
478
519
|
beforeRead = null;
|
|
520
|
+
quiet = await readQuiet();
|
|
479
521
|
save(root, report);
|
|
480
522
|
say('');
|
|
481
523
|
say('Ready for the next payment - make it now, or press ' + (options.stopWith ? 'Stop' : 'Ctrl-C') + ' when you are done.');
|
package/kryptheon-payments.js
CHANGED
|
@@ -422,6 +422,32 @@ const ok = (status) => status !== null && status >= 200 && status < 300;
|
|
|
422
422
|
// Events that say a payment was refunded, on either provider.
|
|
423
423
|
const REFUND_EVENT = /^(refund\.(created|processed)|payment\.refunded|charge\.refunded)$/;
|
|
424
424
|
|
|
425
|
+
// Events that say a payment went through: payment.captured, order.paid,
|
|
426
|
+
// subscription.charged, checkout.session.completed, invoice.paid,
|
|
427
|
+
// payment_intent.succeeded - and an app's own "payment.succeeded". Not
|
|
428
|
+
// payment.authorized (not taken yet) or Razorpay's subscription.completed
|
|
429
|
+
// (its last cycle ended).
|
|
430
|
+
const PAID_EVENT = /(^|[._])(paid|captured|succeeded|completed|charged|activated)$/i;
|
|
431
|
+
const NOT_PAID_EVENT = /^subscription\.completed$/;
|
|
432
|
+
const isPaidEvent = (type) => PAID_EVENT.test(String(type || '')) && !NOT_PAID_EVENT.test(String(type || ''));
|
|
433
|
+
|
|
434
|
+
// What a payment gives, by column or by table: written before its webhook
|
|
435
|
+
// (at checkout, from the page), it was given there.
|
|
436
|
+
const GRANT_COLUMN = /plan|tier|premium|(^|_)pro($|_)|credit|balance|quota|access|role|status|paid|active|subscri|expir|period|valid_until|wallet|seats/i;
|
|
437
|
+
const GRANT_TABLE = /subscri|entitle|purchase|payment|credit|licen|wallet|transaction/i;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Whether what changed between the start of the check and a payment's first
|
|
441
|
+
* webhook gave the customer something: the app may grant at checkout, from
|
|
442
|
+
* the page, and use the webhook only as a back-up. An order row made when
|
|
443
|
+
* checkout began is not that.
|
|
444
|
+
*/
|
|
445
|
+
function givenElsewhere(writes) {
|
|
446
|
+
return (writes || []).some((w) => (w.class || 'business') === 'business' && (
|
|
447
|
+
(w.kind === 'changed' && (w.columns || []).some((c) => GRANT_COLUMN.test(c.name))) ||
|
|
448
|
+
((w.kind === 'added' || w.kind === 'count') && GRANT_TABLE.test(w.table))));
|
|
449
|
+
}
|
|
450
|
+
|
|
425
451
|
// Columns whose values are never written into a trace, whatever the table.
|
|
426
452
|
const SECRET_COLUMN = /pass(word|wd)?|secret|token|api_?key|access_?key|private|signature|card|cvv|otp|(^|_)(pan|pin|ssn|aadhaar)(_|$)|(^|_)keys?$/i;
|
|
427
453
|
const SHORT = 200;
|
|
@@ -568,9 +594,19 @@ async function check(options) {
|
|
|
568
594
|
!firstDelivery.writes.some((w) => w.class === 'business')) {
|
|
569
595
|
result.findings.push({ kind: 'refund-nothing', severity: 'MEDIUM', toCheck: true, status: hook.status, said: hook.said || '' });
|
|
570
596
|
}
|
|
597
|
+
// A payment that gave nothing: the customer paid, and neither its webhooks
|
|
598
|
+
// nor anything before them (checkout, the page) gave a plan, credits or an
|
|
599
|
+
// order. Seen, not proven wrong: an app may give it by hand or elsewhere.
|
|
600
|
+
const types = options.groupTypes && options.groupTypes.length ? options.groupTypes : [event.type];
|
|
601
|
+
const paid = types.filter(isPaidEvent);
|
|
602
|
+
if (paid.length && firstDelivery.writes && !firstDelivery.writes.some((w) => w.class === 'business') &&
|
|
603
|
+
!givenElsewhere(options.sinceWrites)) {
|
|
604
|
+
result.findings.push({ kind: 'paid-nothing', severity: 'HIGH', toCheck: true, status: hook.status, said: hook.said || '',
|
|
605
|
+
events: paid, logged: firstDelivery.writes.length > 0, before: Array.isArray(options.sinceWrites) });
|
|
606
|
+
}
|
|
571
607
|
|
|
572
608
|
// 1. The same webhook again.
|
|
573
|
-
say('Sending the same webhook again, exactly as ' + (hook.provider === 'razorpay' ? 'Razorpay' : 'Stripe') + ' would on a retry ...');
|
|
609
|
+
say('Sending the same webhook again, exactly as ' + (hook.provider === 'razorpay' ? 'Razorpay' : hook.provider === 'stripe' ? 'Stripe' : 'your provider') + ' would on a retry ...');
|
|
574
610
|
const again = await send(target, hook);
|
|
575
611
|
const second = await settle(client, schema, tables, options);
|
|
576
612
|
const related = relatedTo(firstDelivery.writes, idsOf(hook));
|
|
@@ -678,6 +714,8 @@ function lifecycle(result, earlier) {
|
|
|
678
714
|
module.exports = {
|
|
679
715
|
signatureHeaderOf: signatureHeaderOf,
|
|
680
716
|
lifecycle: lifecycle,
|
|
717
|
+
isPaidEvent: isPaidEvent,
|
|
718
|
+
givenElsewhere: givenElsewhere,
|
|
681
719
|
isLocalAddress: isLocalAddress,
|
|
682
720
|
providerOf: providerOf,
|
|
683
721
|
modeOf: modeOf,
|
package/kryptheon-roles.js
CHANGED
|
@@ -85,6 +85,8 @@ function loadPolicy(root) {
|
|
|
85
85
|
function checkPolicy(json) {
|
|
86
86
|
const problems = [];
|
|
87
87
|
if (!json || typeof json !== 'object' || Array.isArray(json)) return { ok: false, problems: ['it must be a JSON object with a "roles" section.'] };
|
|
88
|
+
// A draft Kryptheon wrote from the code says what the code does today, not what the owner wants.
|
|
89
|
+
if (json.draft !== undefined) return { ok: false, problems: ['it is still marked "draft": it lists what your code does today, not what you want. Edit each role to what you want, then delete the "draft" line.'] };
|
|
88
90
|
const roles = {};
|
|
89
91
|
if (!json.roles || typeof json.roles !== 'object' || Array.isArray(json.roles)) problems.push('"roles" must say, for each role, the list of permissions it has.');
|
|
90
92
|
else {
|
|
@@ -106,6 +108,8 @@ function checkPolicy(json) {
|
|
|
106
108
|
|
|
107
109
|
/** Whether `role` has `permission` ("*" and "resource.*" are allowed in the file). */
|
|
108
110
|
function holds(policy, role, permission) {
|
|
111
|
+
// The API check's organization-only run: who may do what is not judged, every signed-in account may.
|
|
112
|
+
if (policy.anyRole) return true;
|
|
109
113
|
const key = Object.keys(policy.roles).find((r) => r.toLowerCase() === String(role || '').toLowerCase());
|
|
110
114
|
if (!key) return false;
|
|
111
115
|
return policy.roles[key].some((p) => p === permission || p === '*' || (p.endsWith('.*') && permission.startsWith(p.slice(0, -1))));
|
|
@@ -437,6 +441,13 @@ function findUser(json) {
|
|
|
437
441
|
return pools.find(looks) || null;
|
|
438
442
|
}
|
|
439
443
|
|
|
444
|
+
/** Who the app says is signed in when it names no role: an object with an id and an email. */
|
|
445
|
+
function findAnyUser(json) {
|
|
446
|
+
const looks = (o) => o && typeof o === 'object' && !Array.isArray(o) && o.id !== undefined && typeof o.email === 'string';
|
|
447
|
+
const pools = [json, json && json.user, json && json.data, json && json.data && json.data.user, json && json.me, json && json.account, json && json.profile];
|
|
448
|
+
return pools.find(looks) || null;
|
|
449
|
+
}
|
|
450
|
+
|
|
440
451
|
function orgOf(user, extra) {
|
|
441
452
|
const idPath = extra && extra.identity && extra.identity.orgPath;
|
|
442
453
|
const namePath = extra && extra.identity && extra.identity.orgNamePath;
|
|
@@ -509,7 +520,7 @@ async function checkAccess(input) {
|
|
|
509
520
|
for (const p of candidates) {
|
|
510
521
|
const me = await s.send('GET', p);
|
|
511
522
|
if (me.status === 200 && me.json) {
|
|
512
|
-
user = findUser(me.json);
|
|
523
|
+
user = findUser(me.json) || (policy.anyRole ? findAnyUser(me.json) : null);
|
|
513
524
|
if (user) break;
|
|
514
525
|
}
|
|
515
526
|
}
|
|
@@ -517,8 +528,8 @@ async function checkAccess(input) {
|
|
|
517
528
|
skipped.push({ what: a.email, why: 'signed in, but the app did not say who it is (looked at ' + candidates.slice(0, 3).join(', ') + '...). Name the address in ' + POLICY_FILE + ' under kryptheon.identity.path' });
|
|
518
529
|
continue;
|
|
519
530
|
}
|
|
520
|
-
const roleName = typeof user.role === 'string' ? user.role : user.role.name;
|
|
521
|
-
const known = Object.keys(policy.roles).find((r) => r.toLowerCase() === roleName.toLowerCase());
|
|
531
|
+
const roleName = typeof user.role === 'string' ? user.role : user.role ? user.role.name : 'signed in';
|
|
532
|
+
const known = policy.anyRole ? roleName : Object.keys(policy.roles).find((r) => r.toLowerCase() === roleName.toLowerCase());
|
|
522
533
|
if (!known) {
|
|
523
534
|
skipped.push({ what: a.email, why: 'the app says its role is "' + roleName + '", which ' + POLICY_FILE + ' does not list' });
|
|
524
535
|
continue;
|
|
@@ -601,7 +612,7 @@ async function checkAccess(input) {
|
|
|
601
612
|
for (const t of Object.keys(after)) if (before[t] !== undefined) lines.push.apply(lines, diffLines(t, before[t], after[t]));
|
|
602
613
|
return lines;
|
|
603
614
|
};
|
|
604
|
-
for (const key of orgs.keys()) {
|
|
615
|
+
for (const key of orgs.size ? Array.from(orgs.keys()) : [null]) {
|
|
605
616
|
const one = await snapshot(key);
|
|
606
617
|
const two = await snapshot(key);
|
|
607
618
|
for (const t of Object.keys(one)) if (JSON.stringify(one[t]) !== JSON.stringify(two[t])) {
|
|
@@ -641,12 +652,53 @@ async function checkAccess(input) {
|
|
|
641
652
|
fieldCache.set(k, field);
|
|
642
653
|
return field;
|
|
643
654
|
};
|
|
655
|
+
// A route whose address names a record, with no list of those records but a POST at the same address: the POST is sent once
|
|
656
|
+
// per organization (by an account that may) and the id in its answer is the record to aim at. Test data, listed.
|
|
657
|
+
const seeded = new Map();
|
|
658
|
+
out.seeded = [];
|
|
659
|
+
const idIn = (json) => {
|
|
660
|
+
const find = (v, depth) => {
|
|
661
|
+
if (v == null || typeof v !== 'object' || depth > 2) return undefined;
|
|
662
|
+
if (!Array.isArray(v) && ['string', 'number'].includes(typeof v.id)) return v.id;
|
|
663
|
+
for (const k of Object.keys(v)) {
|
|
664
|
+
const f = find(v[k], depth + 1);
|
|
665
|
+
if (f !== undefined) return f;
|
|
666
|
+
}
|
|
667
|
+
return undefined;
|
|
668
|
+
};
|
|
669
|
+
return find(json, 0);
|
|
670
|
+
};
|
|
671
|
+
if (input.seed) {
|
|
672
|
+
for (const action of journey.actions) {
|
|
673
|
+
if (action.params.length !== 1) continue;
|
|
674
|
+
const listing = '/' + action.segs.slice(0, action.params[0].index).join('/');
|
|
675
|
+
if (getTemplates.has(listing) || seeded.has(listing)) continue;
|
|
676
|
+
const maker = journey.actions.find((a) => a.method === 'POST' && a.template === listing && !a.params.length);
|
|
677
|
+
if (!maker) continue;
|
|
678
|
+
const perm = (mapped.find((m) => m.method === 'POST' && m.template === listing) || {}).permission || null;
|
|
679
|
+
const made = [];
|
|
680
|
+
for (const org of orgs.size ? Array.from(orgs.keys()) : [null]) {
|
|
681
|
+
const who = accountsOf(org).find((ss) => !perm || holds(policy, ss.role, perm)) || accountsOf(org)[0];
|
|
682
|
+
if (!who) continue;
|
|
683
|
+
const body = sampleBody(maker);
|
|
684
|
+
const res = await who.send('POST', listing, maker.encoding === 'form' ? { form: body } : { json: body });
|
|
685
|
+
const id = res.status >= 200 && res.status < 300 ? idIn(res.json) : undefined;
|
|
686
|
+
if (id === undefined) continue;
|
|
687
|
+
made.push({ org: org, value: id, item: res.json, listing: listing, field: 'id' });
|
|
688
|
+
out.seeded.push('POST ' + listing + ' -> ' + id + (org !== null ? ' (' + (orgs.get(org) ? orgs.get(org).name : org) + ')' : '') + ': made to have a record to aim at');
|
|
689
|
+
}
|
|
690
|
+
seeded.set(listing, made);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
644
693
|
/** The records of one organization an action's address can be aimed at: [{ value, item }]. */
|
|
645
694
|
const targetsFor = async (action, orgKey) => {
|
|
646
695
|
if (!action.params.length) return [{ value: null, item: null }];
|
|
647
696
|
if (action.params.length > 1) return null;
|
|
648
697
|
const listing = '/' + action.segs.slice(0, action.params[0].index).join('/');
|
|
649
|
-
if (!getTemplates.has(listing))
|
|
698
|
+
if (!getTemplates.has(listing)) {
|
|
699
|
+
const mine = (seeded.get(listing) || []).filter((r) => r.org === orgKey);
|
|
700
|
+
return mine.length ? mine : null;
|
|
701
|
+
}
|
|
650
702
|
const items = await itemsOf(orgKey, listing);
|
|
651
703
|
if (!items) return null;
|
|
652
704
|
const field = await fieldFor(action, listing);
|
|
@@ -693,6 +745,15 @@ async function checkAccess(input) {
|
|
|
693
745
|
}
|
|
694
746
|
}
|
|
695
747
|
}
|
|
748
|
+
// Asked for (the API check): every action once with no session at all, aimed at
|
|
749
|
+
// the first organization's records and judged by its lists before and after.
|
|
750
|
+
if (input.anonymous) {
|
|
751
|
+
const anon = authz.makeSession(ctx, null, '(not signed in)', null);
|
|
752
|
+
anon.role = 'not signed in';
|
|
753
|
+
anon.org = null;
|
|
754
|
+
const first = sessions.find((s) => s.org);
|
|
755
|
+
for (const action of mapped) plan.push({ action: action, actor: anon, kind: 'signin', expected: 'deny', org: first ? first.org.key : null });
|
|
756
|
+
}
|
|
696
757
|
// Refusals first, so a control that changes things (an archive, a job) cannot make a later refusal look kept.
|
|
697
758
|
const rank = (p) => (p.expected === 'deny' ? 0 : 1);
|
|
698
759
|
plan.sort((a, b) => rank(a) - rank(b));
|
|
@@ -736,7 +797,8 @@ async function checkAccess(input) {
|
|
|
736
797
|
groups.get(k).push(a);
|
|
737
798
|
}
|
|
738
799
|
for (const [k, list] of groups) {
|
|
739
|
-
|
|
800
|
+
const signedIn = list.filter((a) => a.kind !== 'signin');
|
|
801
|
+
if (signedIn.length && signedIn.every((a) => !a.notTried && a.response.status === 401)) {
|
|
740
802
|
out.attempts = out.attempts.filter((a) => !list.includes(a));
|
|
741
803
|
skipped.push({ what: k, why: 'every account was answered 401 (not signed in): it does not take the session, probably its own key, so it was not judged' });
|
|
742
804
|
}
|
|
@@ -832,7 +894,14 @@ async function tryOnce(x) {
|
|
|
832
894
|
}
|
|
833
895
|
if (/^(PATCH|PUT)$/.test(a.method) && !Object.keys(body).some((k) => nameOf(body[k]))) {
|
|
834
896
|
const field = Object.keys(body).find((k) => typeof body[k] === 'string' && body[k].length > 2 && !/status|state|type|role|kind|currency|country|id$/i.test(k));
|
|
835
|
-
if (field)
|
|
897
|
+
if (field) {
|
|
898
|
+
// the same value as the record already holds (a try of an earlier run, kept) would change nothing and look like a refusal
|
|
899
|
+
let v = body[field] + ' kx-roles';
|
|
900
|
+
const flat = (k) => String(k).split('_').join('').toLowerCase();
|
|
901
|
+
const held = target.item && typeof target.item === 'object' ? Object.keys(target.item).find((k) => flat(k) === flat(field)) : undefined;
|
|
902
|
+
if (held !== undefined && String(target.item[held]) === v) v = v + ' ' + Math.random().toString(36).slice(2, 5);
|
|
903
|
+
body[field] = v;
|
|
904
|
+
}
|
|
836
905
|
}
|
|
837
906
|
}
|
|
838
907
|
const request = { method: a.method, path: pathNow };
|
|
@@ -840,7 +909,7 @@ async function tryOnce(x) {
|
|
|
840
909
|
const requestText = pathNow + ' ' + JSON.stringify(body || {});
|
|
841
910
|
|
|
842
911
|
// what the app holds now
|
|
843
|
-
const reader = targetOrg !== null;
|
|
912
|
+
const reader = targetOrg !== null || p.kind === 'signin' || x.orgs.size === 0;
|
|
844
913
|
const before = reader ? await x.snapshot(targetOrg) : {};
|
|
845
914
|
const known = await x.knownTo(actor);
|
|
846
915
|
|
|
@@ -893,9 +962,15 @@ async function tryOnce(x) {
|
|
|
893
962
|
const original = target.item && /^(PATCH|PUT)$/.test(a.method) ? target.item : null;
|
|
894
963
|
if (original) {
|
|
895
964
|
const back = {};
|
|
896
|
-
|
|
965
|
+
// The body says recipientName where the record says recipient_name: the same field.
|
|
966
|
+
const plain = (k) => String(k).replace(/[^A-Za-z0-9]/g, '').toLowerCase();
|
|
967
|
+
const held = new Map(Object.keys(original).map((k) => [plain(k), k]));
|
|
968
|
+
for (const k of Object.keys(body || {})) {
|
|
969
|
+
const at = original[k] !== undefined ? k : held.get(plain(k));
|
|
970
|
+
if (at !== undefined && original[at] !== undefined) back[k] = original[at];
|
|
971
|
+
}
|
|
897
972
|
if (Object.keys(back).length) {
|
|
898
|
-
const writers = x.orgs.get(targetOrg).sessions.filter((s) => holds(policy, s.role, a.permission)).concat([actor]);
|
|
973
|
+
const writers = (x.orgs.get(targetOrg) ? x.orgs.get(targetOrg).sessions : x.sessions).filter((s) => holds(policy, s.role, a.permission)).concat([actor]);
|
|
899
974
|
for (const who of writers) {
|
|
900
975
|
await who.send(a.method, pathNow, a.encoding === 'form' ? { form: back } : { json: back });
|
|
901
976
|
const again = await x.snapshot(targetOrg);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kryptheon",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.56",
|
|
4
4
|
"description": "Record what you do in your app and get plain-language reports when it breaks.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -54,7 +54,9 @@
|
|
|
54
54
|
"kryptheon-payments.js",
|
|
55
55
|
"kryptheon-payments-run.js",
|
|
56
56
|
"kryptheon-authz.js",
|
|
57
|
-
"kryptheon-roles.js"
|
|
57
|
+
"kryptheon-roles.js",
|
|
58
|
+
"kryptheon-map.js",
|
|
59
|
+
"kryptheon-api.js"
|
|
58
60
|
],
|
|
59
61
|
"engines": {
|
|
60
62
|
"node": ">=20.6.0"
|
|
@@ -64,7 +66,7 @@
|
|
|
64
66
|
"pg": "^8.23.0"
|
|
65
67
|
},
|
|
66
68
|
"scripts": {
|
|
67
|
-
"check": "node kryptheon-store.check.js && node kryptheon-code.check.js && node kryptheon-constdata.check.js && node kryptheon-listitems.check.js && node kryptheon-accept.check.js && node kryptheon-keys.check.js && node kryptheon-dashboard.check.js && node kryptheon-edge.check.js && node kryptheon-reliability.check.js && node kryptheon-fresh.check.js && node kryptheon-payments-dash.check.js && node kryptheon-embedded.check.js && node kryptheon-autostart.check.js && node kryptheon-changes.check.js && node kryptheon-look.check.js && node kryptheon-verify.check.js && node kryptheon-recheck.check.js && node kryptheon-reporter.check.js && node kryptheon-signature.check.js && node kryptheon-signature.stream.check.js && node kryptheon-signature.baseline.check.js && node kryptheon-signature.settle.check.js && node kryptheon-signature.number.check.js && node kryptheon-signature.rows.check.js && node kryptheon-env.check.js && node kryptheon-watchdog.check.js && node kryptheon-phone.check.js && node kryptheon-homedash.check.js && node kryptheon-record.check.js && node kryptheon-selectors.check.js && node kryptheon-recordings.check.js && node kryptheon-testfiles.check.js && node kryptheon-cleanup.check.js && node kryptheon-orphan.check.js && node kryptheon-project.check.js && node kryptheon-setup.check.js && node kryptheon-browser.check.js && node kryptheon-heal.check.js && node kryptheon-load.check.js && node kryptheon-authz.check.js && node kryptheon-roles.check.js && node kryptheon-package.check.js",
|
|
69
|
+
"check": "node kryptheon-store.check.js && node kryptheon-code.check.js && node kryptheon-constdata.check.js && node kryptheon-listitems.check.js && node kryptheon-accept.check.js && node kryptheon-keys.check.js && node kryptheon-dashboard.check.js && node kryptheon-edge.check.js && node kryptheon-reliability.check.js && node kryptheon-fresh.check.js && node kryptheon-payments-dash.check.js && node kryptheon-embedded.check.js && node kryptheon-autostart.check.js && node kryptheon-changes.check.js && node kryptheon-look.check.js && node kryptheon-verify.check.js && node kryptheon-recheck.check.js && node kryptheon-reporter.check.js && node kryptheon-signature.check.js && node kryptheon-signature.stream.check.js && node kryptheon-signature.baseline.check.js && node kryptheon-signature.settle.check.js && node kryptheon-signature.number.check.js && node kryptheon-signature.rows.check.js && node kryptheon-env.check.js && node kryptheon-watchdog.check.js && node kryptheon-phone.check.js && node kryptheon-homedash.check.js && node kryptheon-record.check.js && node kryptheon-selectors.check.js && node kryptheon-recordings.check.js && node kryptheon-testfiles.check.js && node kryptheon-cleanup.check.js && node kryptheon-orphan.check.js && node kryptheon-project.check.js && node kryptheon-setup.check.js && node kryptheon-browser.check.js && node kryptheon-heal.check.js && node kryptheon-load.check.js && node kryptheon-authz.check.js && node kryptheon-roles.check.js && node kryptheon-map.check.js && node kryptheon-api.check.js && node kryptheon-package.check.js",
|
|
68
70
|
"check:store": "node kryptheon-store.check.js",
|
|
69
71
|
"check:code": "node kryptheon-code.check.js",
|
|
70
72
|
"check:constdata": "node kryptheon-constdata.check.js",
|
|
@@ -105,7 +107,9 @@
|
|
|
105
107
|
"check:fresh": "node kryptheon-fresh.check.js",
|
|
106
108
|
"check:authz": "node kryptheon-authz.check.js",
|
|
107
109
|
"check:roles": "node kryptheon-roles.check.js",
|
|
108
|
-
"check:roles-mutants": "node kryptheon-roles.mutants.js"
|
|
110
|
+
"check:roles-mutants": "node kryptheon-roles.mutants.js",
|
|
111
|
+
"check:map": "node kryptheon-map.check.js",
|
|
112
|
+
"check:api": "node kryptheon-api.check.js"
|
|
109
113
|
},
|
|
110
114
|
"keywords": [
|
|
111
115
|
"playwright",
|