@adminiumjs/manifest 0.3.63 → 0.3.65

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.
@@ -32,6 +32,7 @@ import { kindOf, rulesOf } from './capacity.js';
32
32
  import { formulaColumns } from './formula.js';
33
33
  import { refSchema, scalarSchema, settingRefSchema, valueFits, } from './refs.js';
34
34
  import { FORMS_BECAME_TABLE_MAX } from './forms.js';
35
+ import { compareSemver } from './semver.js';
35
36
  import { momentIssues, momentOffsetSchema, plainMomentSchema, wallTimeSchema } from './refs.js';
36
37
  import { conditionIssues, linkedConditionSchema, reachedOnlyByUndo, stateConditionSchema } from './states.js';
37
38
  /** The fewest characters (its prefix apart) of a code that opens its own row (`unlockBy.self`). */
@@ -54,6 +55,35 @@ export const FORMS_KEY = 'forms';
54
55
  * left out: forms send their own.
55
56
  */
56
57
  export const FORMS_ENTRY_WORDS = ['table', 'methods', 'key', 'writable', 'writableValues', 'defaults', 'requires', 'agrees', 'anonymous', 'requireSetting', 'module', 'source'];
58
+ /**
59
+ * The reserved key name of the entries that open a table to a CHAT's
60
+ * question left outside hours: a visitor who leaves one with an e-mail adds
61
+ * a new row of the table, through this entry's `writable` columns, `defaults`
62
+ * and `anonymous` limits. As with `forms`, no browser key of this name is
63
+ * ever made and the public API never serves such an entry: the chat door
64
+ * alone reads it. A table may carry both a `forms` and a `chat` entry.
65
+ */
66
+ export const CHAT_KEY = 'chat';
67
+ /** What a chat entry may say: a forms entry's words, but a chat's row has no form, so no form's "Source". */
68
+ export const CHAT_ENTRY_WORDS = FORMS_ENTRY_WORDS.filter((word) => word !== 'source');
69
+ /** The reserved keys whose entries a door of Adminium's own writes through, and the public API never serves. */
70
+ export const DOOR_KEYS = [FORMS_KEY, CHAT_KEY];
71
+ /**
72
+ * The release that reserved `chat`. A manifest whose floor
73
+ * (`compatibility.minAdminiumVersion`) is older was written when `chat` was
74
+ * an ordinary key name: it keeps that meaning, so an app that named a key
75
+ * `chat` before still validates and its entries are still served.
76
+ */
77
+ export const CHAT_KEY_FLOOR = '0.3.64';
78
+ /** Whether a manifest's `chat` is the reserved key: its floor is {@link CHAT_KEY_FLOOR} or later. */
79
+ export function chatKeyReserved(m) {
80
+ const floor = m.compatibility?.minAdminiumVersion;
81
+ return floor !== undefined && compareSemver(floor, CHAT_KEY_FLOOR) >= 0;
82
+ }
83
+ /** The reserved door keys of one manifest: `forms` always, `chat` from its floor on. */
84
+ export function doorKeysOf(m) {
85
+ return chatKeyReserved(m) ? DOOR_KEYS : [FORMS_KEY];
86
+ }
57
87
  /** The longest a plain-text value may be unless its column says longer: a name. */
58
88
  export const PLAIN_TEXT_MAX = 80;
59
89
  /** The most digits a plain-text column may take in all: "table 12", "2 without onions", never a phone number. */
@@ -927,6 +957,44 @@ function formsEntryIssues(entry, i, entries, appKey, index) {
927
957
  }
928
958
  return out;
929
959
  }
960
+ /**
961
+ * A chat entry's own rules, those of a forms entry: it creates (POST) and
962
+ * nothing else, under anonymous limits, with the columns a left question may
963
+ * fill named; one per table, its table short enough for a conversation to
964
+ * keep whole; and no entry on any key lets anyone read the rows strangers
965
+ * add through it. A chat's row has no form, so it names no source.
966
+ */
967
+ function chatEntryIssues(entry, i, entries, appKey) {
968
+ const out = [];
969
+ const at = (...rest) => ['publicAccess', i, ...rest];
970
+ // Each conversation keeps the row it became by its table's stored name: it must fit a conversations table, whole.
971
+ const stored = appKey === undefined ? 0 : appKey.length + 1 + entry.table.length;
972
+ if (stored > FORMS_BECAME_TABLE_MAX) {
973
+ out.push({ path: at('table'), message: `a chat names the row it became by "<app>:<table>", at most ${String(FORMS_BECAME_TABLE_MAX)} characters: "${appKey ?? ''}:${entry.table}" is ${String(stored)}` });
974
+ }
975
+ const allowed = CHAT_ENTRY_WORDS;
976
+ for (const word of Object.keys(entry)) {
977
+ if (!allowed.includes(word))
978
+ out.push({ path: at(word), message: `a chat entry only lets a left question add a row: "${word}" is not said on it` });
979
+ }
980
+ if (entry.methods.length !== 1 || entry.methods[0] !== 'POST')
981
+ out.push({ path: at('methods'), message: 'a chat entry adds a row and does nothing else: its methods are ["POST"]' });
982
+ if (entry.anonymous === undefined)
983
+ out.push({ path: at('anonymous'), message: 'a question is left by strangers: a chat entry says its anonymous limits' });
984
+ if ((entry.writable ?? []).length === 0)
985
+ out.push({ path: at('writable'), message: 'a chat entry names the columns a left question may fill (writable)' });
986
+ if (entries.findIndex((other) => other.key === CHAT_KEY && other.table === entry.table) !== i) {
987
+ out.push({ path: at('table'), message: `"${entry.table}" is opened to chat by another entry already: one chat entry per table` });
988
+ }
989
+ const reader = entries.findIndex((other) => other !== entry && other.table === entry.table && readByAnyone(other));
990
+ if (reader !== -1) {
991
+ out.push({
992
+ path: at('table'),
993
+ message: `strangers add rows to "${entry.table}" through chat, and entry ${String(reader)} lets anyone read its rows: everyone could read the questions people left`,
994
+ });
995
+ }
996
+ return out;
997
+ }
930
998
  /**
931
999
  * An entry held to the app whose key serves it (`appColumn`): a text column
932
1000
  * of its table, never one a browser writes or a value the entry sets, and
@@ -961,6 +1029,10 @@ export function publicAccessIssues(entries, ctx) {
961
1029
  const { index } = ctx;
962
1030
  const has = index.has;
963
1031
  out.push(...appColumnIssues(entries, index));
1032
+ const doorKeys = ctx.chatReserved === false ? [FORMS_KEY] : DOOR_KEYS;
1033
+ if (doorKeys.includes(CHAT_KEY) && ctx.publicKeys?.[CHAT_KEY] !== undefined) {
1034
+ out.push({ path: ['publicKeys', CHAT_KEY], message: '"chat" is the name of the entries a chat\'s left questions write through, and no browser key: name the key otherwise' });
1035
+ }
964
1036
  for (const [name, key] of Object.entries(ctx.publicKeys ?? {})) {
965
1037
  const at = ['publicKeys', name];
966
1038
  // The app's own key, named only for its peak: nothing more to check.
@@ -1085,11 +1157,15 @@ export function publicAccessIssues(entries, ctx) {
1085
1157
  }
1086
1158
  const column = (ref) => index.column(entry.table, ref);
1087
1159
  const key = entry.key ?? CUSTOMER_KEY;
1088
- if (key !== CUSTOMER_KEY && key !== FORMS_KEY && ctx.publicKeys?.[key] === undefined) {
1089
- out.push({ path: at('key'), message: `"${key}" is not one of the app's publicKeys` });
1160
+ if (key !== CUSTOMER_KEY && !doorKeys.includes(key) && ctx.publicKeys?.[key] === undefined) {
1161
+ // Under an older floor `chat` is a key like any other: say so, for whoever meant a chat's left questions.
1162
+ const chat = key === CHAT_KEY ? ` (a chat's left questions are opened under "chat" from Adminium ${CHAT_KEY_FLOOR}: set compatibility.minAdminiumVersion to it or later)` : '';
1163
+ out.push({ path: at('key'), message: `"${key}" is not one of the app's publicKeys${chat}` });
1090
1164
  }
1091
1165
  if (key === FORMS_KEY)
1092
1166
  out.push(...formsEntryIssues(entry, i, entries, ctx.appKey, index));
1167
+ else if (key === CHAT_KEY && doorKeys.includes(CHAT_KEY))
1168
+ out.push(...chatEntryIssues(entry, i, entries, ctx.appKey));
1093
1169
  else if (entry.source !== undefined)
1094
1170
  out.push({ path: at('source'), message: 'a source is said only on a forms entry (key "forms"): the column a form\'s fixed "Source" value goes into' });
1095
1171
  for (const list of ['select', 'writable']) {
@@ -1101,8 +1177,8 @@ export function publicAccessIssues(entries, ctx) {
1101
1177
  // An entry anyone may call (no claim, no parent, no session asked) shows no personal data: the install refuses it too.
1102
1178
  const sessionOnly = entry.level !== undefined && entry.claim === undefined && entry.claimedBy === undefined && entry.visibleWith === undefined;
1103
1179
  const anyone = entry.claim === undefined && entry.visibleWith === undefined && (entry.claimedBy === undefined || entry.claimedBy.optional === true) && !sessionOnly;
1104
- // An availability entry shows no row, whatever it names; nor does a forms entry, which answers nobody with the row.
1105
- if (anyone && entry.kind !== 'availability' && key !== FORMS_KEY) {
1180
+ // An availability entry shows no row, whatever it names; nor does a forms or a chat entry, which answers nobody with the row.
1181
+ if (anyone && entry.kind !== 'availability' && !doorKeys.includes(key)) {
1106
1182
  // No select shows every column but a code Adminium makes and a secret, as the install reads it.
1107
1183
  const shown = entry.select ??
1108
1184
  table.columns.filter((c) => c.rules?.['code'] === undefined && c.rules?.['secret'] !== true).map((c) => c.ref);