@adminiumjs/manifest 0.3.85 → 0.3.86

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/dist/schema.js CHANGED
@@ -26,7 +26,7 @@ import { lookUpIssues, lookUpSchema } from './look-up.js';
26
26
  import { pageBoardIssues } from './page-board.js';
27
27
  import { pageCalendarIssues } from './page-calendar.js';
28
28
  import { pageConfigIssues } from './page-config.js';
29
- import { emailTemplateSchema, outboxIssues, outboxProducerSchema, outboxSchema } from './outbox.js';
29
+ import { emailTemplateSchema, mustCarryIssues, outboxIssues, outboxProducerSchema, outboxSchema } from './outbox.js';
30
30
  import { CHAT_KEY, FORMS_KEY, chatKeyReserved, codeWhereSchema, personalColumn, plainTextMax, plainTextRef, publicAccessIssues, publicAccessSchema, publicKeysSchema, shareCodeColumns, unlistedColumn } from './public-access.js';
31
31
  import { appGrantsIssues, appGrantsSchema, roleTableHold } from './app-grants.js';
32
32
  import { personImportIssues, personImportSchema } from './person-import.js';
@@ -49,6 +49,7 @@ import { tableNameIssue, tableSchemaIssue } from './table-names.js';
49
49
  import { mailClassFloorIssues } from './mail-class.js';
50
50
  import { keepSchema, peopleIssues, peopleSchema, publicConsentIssues, textConsentBoxes } from './people.js';
51
51
  import { shippingIssues, shippingSchema } from './shipping.js';
52
+ import { LEGAL_EDIT_GRANT, LEGAL_VERSION_ID_LENGTH, LEGAL_VERSION_WRITTEN_ALONE, legalIssues, legalSchema, legalVersionColumns, legalVersionEntryIssues, legalVersionRuleSchema } from './legal.js';
52
53
  import { fromTemplateIssues, fromTemplateSchema } from './from-template.js';
53
54
  import { expiryNoticeIssues, expiryNoticeSchema } from './expiry-notice.js';
54
55
  import { recordClassIssues, recordClassesSchema } from './record-classes.js';
@@ -863,6 +864,12 @@ export const columnRulesSchema = z
863
864
  * installed, connected to this app and switched on.
864
865
  */
865
866
  addOnLink: addOnTableSchema.optional(),
867
+ /**
868
+ * The legal texts a row (an order) was placed under: the browser writes
869
+ * the version it showed, Adminium keeps that version's id, once (see
870
+ * `legalVersionRuleSchema` in `legal.ts`).
871
+ */
872
+ legalVersion: legalVersionRuleSchema.optional(),
866
873
  /**
867
874
  * A text column that holds a table's stored name (`<maker>:<table>`, or
868
875
  * the table's own name when no app made it). Adminium rewrites it when
@@ -2515,6 +2522,40 @@ sink) {
2515
2522
  if (table.columns.some((other) => other !== column && other.rules?.retryKey === true))
2516
2523
  out.push({ path: here('retryKey'), message: `"${table.ref}" keeps its retry key in one column` });
2517
2524
  }
2525
+ const legalVersion = legalVersionColumns(rules.legalVersion);
2526
+ if (legalVersion !== null) {
2527
+ // The id of a version of the install's legal texts, kept once by Adminium from the number the customer was shown.
2528
+ if (column.type !== 'text')
2529
+ out.push({ path: here('legalVersion'), message: 'the legal texts an order was placed under are kept as a version\'s id, in text' });
2530
+ if (column.nullable !== true)
2531
+ out.push({ path: here('legalVersion'), message: 'an order placed while no legal texts are published keeps none, so the column is nullable' });
2532
+ if (typeof column.maxLength === 'number' && column.maxLength < LEGAL_VERSION_ID_LENGTH)
2533
+ out.push({ path: here('legalVersion'), message: `a version's id is ${String(LEGAL_VERSION_ID_LENGTH)} characters, so maxLength is at least ${String(LEGAL_VERSION_ID_LENGTH)}` });
2534
+ if (deciders.length > 0 || rules.addOnLink !== undefined || column.references !== undefined)
2535
+ out.push({ path: here('legalVersion'), message: `the legal texts an order was placed under are the customer's and Adminium's, never ${[...deciders, ...(rules.addOnLink === undefined ? [] : ['addOnLink']), ...(column.references === undefined ? [] : ['a foreign key'])].join(', ')}` });
2536
+ if (table.columns.some((other) => other !== column && other.rules?.legalVersion !== undefined))
2537
+ out.push({ path: here('legalVersion'), message: `"${table.ref}" keeps the legal texts it was placed under in one column` });
2538
+ const side = (ref, name, type, what) => {
2539
+ if (ref === undefined)
2540
+ return;
2541
+ const other = table.columns.find((candidate) => candidate.ref === ref);
2542
+ if (other === undefined) {
2543
+ out.push({ path: here('legalVersion', name), message: `"${table.ref}" has no column "${ref}"` });
2544
+ return;
2545
+ }
2546
+ if (other === column)
2547
+ out.push({ path: here('legalVersion', name), message: `"${ref}" is the version's own column` });
2548
+ if (other.type !== type || other.nullable !== true)
2549
+ out.push({ path: here('legalVersion', name), message: `"${table.ref}.${ref}" is ${what}: a nullable ${type} column` });
2550
+ if (other.rules !== undefined && Object.keys(other.rules).some((rule) => rule !== 'personal'))
2551
+ out.push({ path: here('legalVersion', name), message: `"${table.ref}.${ref}" is written by Adminium alone, so it has no rules of its own` });
2552
+ decide(table.ref, ref);
2553
+ };
2554
+ side(legalVersion.acceptedAt, 'acceptedAt', 'timestamptz', 'when the customer accepted the texts');
2555
+ side(legalVersion.assumed, 'assumed', 'bool', 'whether the version was taken for the customer');
2556
+ if (legalVersion.acceptedAt !== undefined && legalVersion.acceptedAt === legalVersion.assumed)
2557
+ out.push({ path: here('legalVersion', 'assumed'), message: 'the moment and the mark are two columns' });
2558
+ }
2518
2559
  if (rules.normalize !== undefined && column.type !== 'text') {
2519
2560
  out.push({ path: here('normalize'), message: 'only text is stored trimmed or in lower case' });
2520
2561
  }
@@ -4211,6 +4252,8 @@ export const appManifestSchema = z
4211
4252
  people: peopleSchema.optional(),
4212
4253
  /** Where the app keeps what a carrier needs of an order (see `shipping.ts`). Without it, no real carrier is called for this app. */
4213
4254
  shipping: shippingSchema.optional(),
4255
+ /** The legal texts the app shows, kept by Adminium per install, and where its settings name the business (see `legal.ts`). */
4256
+ legal: legalSchema.optional(),
4214
4257
  /** The table of the app's own staff, and which account each row is (see `staff-accounts.ts`). */
4215
4258
  staffAccounts: staffAccountsSchema.optional(),
4216
4259
  /** How one file builds each of those people's rows (see `person-import.ts`). */
@@ -4258,6 +4301,14 @@ export const appManifestSchema = z
4258
4301
  ctx.addIssue({ code: 'custom', message: issue.message, path: issue.path });
4259
4302
  for (const issue of shippingIssues(m, tableIndex(m.requiredSchema.tables)))
4260
4303
  ctx.addIssue({ code: 'custom', message: issue.message, path: issue.path });
4304
+ for (const issue of legalIssues(m, tableIndex(m.requiredSchema.tables)))
4305
+ ctx.addIssue({ code: 'custom', message: issue.message, path: issue.path });
4306
+ for (const issue of legalVersionEntryIssues(m))
4307
+ ctx.addIssue({ code: 'custom', message: issue.message, path: issue.path });
4308
+ (m.emailTemplates ?? []).forEach((template, t) => {
4309
+ for (const issue of mustCarryIssues(template, ['emailTemplates', t]))
4310
+ ctx.addIssue({ code: 'custom', message: issue.message, path: issue.path });
4311
+ });
4261
4312
  for (const issue of textTemplateIssues(m))
4262
4313
  ctx.addIssue({ code: 'custom', message: issue.message, path: issue.path });
4263
4314
  for (const issue of outboxTextIssues(m, tableIndex(m.requiredSchema.tables)))
@@ -4722,6 +4773,18 @@ function addOnInstallIssues(m) {
4722
4773
  const byRef = new Map(tables.map((table) => [table.ref, table]));
4723
4774
  // `addOn.ledgers` is typed loosely in the contracts package (it cannot see these words); it is checked in full here.
4724
4775
  const ledgers = m.addOn.ledgers === undefined ? [] : parsedLedgers(m.addOn.ledgers, out);
4776
+ // A posting writes inside another row's save, where an order's legal texts version cannot be judged.
4777
+ ledgers.forEach((ledger, l) => {
4778
+ const written = [
4779
+ { ref: ledger.receipts, path: ['addOn', 'ledgers', l, 'receipts'] },
4780
+ ...Object.keys(ledger.writes).map((name) => ({ ref: name, path: ['addOn', 'ledgers', l, 'writes', name] })),
4781
+ ];
4782
+ for (const { ref, path } of written) {
4783
+ if ((byRef.get(ref)?.columns ?? []).some((column) => column.rules?.legalVersion !== undefined)) {
4784
+ out.push({ path, message: `"${ref}" ${LEGAL_VERSION_WRITTEN_ALONE}: a ledger's postings cannot write it` });
4785
+ }
4786
+ }
4787
+ });
4725
4788
  out.push(...appReferenceIssues({ ...m, requiredSchema: m.requiredSchema ?? { tables: [] }, ledgers, codePages: (m.addOn.pages ?? []).map((page) => page.ref) }));
4726
4789
  if (m.pages !== undefined)
4727
4790
  out.push(...pageCalendarIssues(m.pages, tableIndex(tables)), ...pageBoardIssues(m.pages, tableIndex(tables)), ...pageConfigIssues(m.pages, tableIndex(tables)));
@@ -5042,6 +5105,8 @@ function addOnInstallIssues(m) {
5042
5105
  out.push({ path: ['roles', r, 'permissions'], message: `"${PEOPLE_MANAGE_GRANT}" is given by an app's role, never an add-on's` });
5043
5106
  if ((role.permissions ?? []).includes('leave:@:report'))
5044
5107
  out.push({ path: ['roles', r, 'permissions'], message: '"leave:@:report" is given by an app\'s role, never an add-on\'s' });
5108
+ if ((role.permissions ?? []).includes(LEGAL_EDIT_GRANT))
5109
+ out.push({ path: ['roles', r, 'permissions'], message: `"${LEGAL_EDIT_GRANT}" is given by an app's role, never an add-on's` });
5045
5110
  (role.permissions ?? []).forEach((grant, g) => {
5046
5111
  const at = ['roles', r, 'permissions', g];
5047
5112
  const [resource, ref, action] = grant.split(':');