@aria-framework/customer 0.0.0-stage → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,172 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 — 2026-12-05 (UTC, built; not yet published)
4
+
5
+ Part **visits**: working in one customer (slice 3 of the plan for the shared customer-driven piece, Platform D-0011,
6
+ D-0013, D-0030; "Customer-driven apps" v7, CD-14 to CD-25, CD-44, CD-45, CD-50, CD-60). Needs
7
+ `@aria-framework/tenancy` 0.5.0 or later (its session mode's `guardSave`), published before this one. Part access is
8
+ unchanged.
9
+
10
+ - `createVisits({ … })`: one factory with the app's lists and lookups (README, "Visits"), every required option refused
11
+ by name. → `loaded`, `track`, `gate(kind)`, `requirePermission(...)`, `routes(Router)` (POST `<mountPath>/:cus/work-in`,
12
+ POST `<mountPath>/leave`, GET `<mountPath>/visit`), `entry`, `end`, `endFirst`, `recordEnded`, `stampOf`, `forStream`,
13
+ `forget`, `current`, `classify`.
14
+ - The visit is one session key (`customerVisit`) in a session mode of tenancy 0.5.0 with `guardSave`, so a slow request
15
+ in flight while Leave, a sign-out or another start runs cannot write it back (CD-23). The first customer-driven app's
16
+ in-process tombstones are not needed.
17
+ - The way in: the partner in force; a house person not working in the customer's partner reads it under the house's own
18
+ pin (not found); working in the partner they get exactly the partner's allowance; fleet view on: refused (CD-60).
19
+ - The level per kind: the lowest of what was asked, the customer's allowance for that kind and the role's most, the
20
+ role judged at the person's HOME partner (CD-17, CD-19). The visit exists while at least one kind has a level.
21
+ - The reason: required, trimmed, at most 300; blank only at a customer whose managed mark is in force, and only for the
22
+ partner's own staff (CD-15).
23
+ - Four hours from `VISIT_HOURS`; a kind let in by the customer's grant (its setting alone gives less) bounds the visit by
24
+ the grant's end (CD-16). `VISIT_WORDS` is the only text of that length.
25
+ - Every request (`track`) and every live event (`forStream`) re-judges the visit: the app's session ending
26
+ (`signed_out`), its end (`expired`), the user, working in a partner and the partner in force, the work-in permission
27
+ at home, and the fit read under the pin (`refused`, with `because`). The fit's memo is bounded, at most `fitMemoMs`
28
+ (≤ 5000), and `forget(customerId)` drops it (CD-22).
29
+ - `gate(kind)`: outside a visit only the app's `outside` entries pass (a page goes to the Customers list); in a visit a
30
+ kind not open is refused (`closed`), look only refuses every state-changing method before any route (CD-18), the
31
+ customer a query or form names is the pin's (CD-25), `can()` and `requirePermission` are the visit's, and the rest of
32
+ the request runs in `tenancy.asCustomer` (CD-14). Every refusal carries `X-Work-In`.
33
+ - One visit at a time (CD-21); Leave needs only a session. Fleet view's switch is refused while a session holds a visit
34
+ ("Leave <customer> first"), and its button is not offered (CD-60): `createVisits` registers a start check with fleet
35
+ view (tenancy 0.5.0 `addStartCheck`), asked by fleet view's own start route, so no spelling of the target routes
36
+ around it. Security fix made before release: the first build compared the path in `track`, before the route, with its
37
+ own normalisation, and `POST /fleet-view/start#x` (url.parse cuts at `#`) switched fleet view on during a visit.
38
+ - The record: `customer.work_in_start` and `customer.work_in_stop` (the first app's names), in the visit's partner's
39
+ trail; the stop row only when the request's own write removed the visit, once per visit in a process; `stampOf(req)`
40
+ for the app's audit helper (CD-44, CD-45). No tier on either row (version 2 has none, D-0013). `tellPartner` when the
41
+ house came in as the partner (CD-50).
42
+ - The chrome: `views/customer-visit-banner.ejs` (CD-20), `views/customer-visit-ended.ejs` (CD-23), `res.locals.visit`
43
+ for the menu, `res.locals.visitLocked(perm)` and `visitLockedText` for CD-18's disabled buttons, and
44
+ `assets/visit.js` (CD-23: the typed work kept when a visit ends under a form). No inline script or style.
45
+ - Package: `files` gains `views/` and `assets/`; peers `@aria-framework/tenancy` ≥ 0.5.0 and, optional, `express` ≥ 5
46
+ (the app passes its Router and runs the package's middleware; Express 5.2 is what the suites run).
47
+ - Tests: `visitRules.js` (the rules as truth tables, the options, the two rows, no typed length), `visits.pglite.js`
48
+ (a real app over a real worker on PGlite with row-level security, tenancy's fleet view and acting routes, express-
49
+ session), `views.js` (the partials, the CSP scan, the asset), `visitRaces.js` (Leave, sign-out and another start
50
+ across a slow request, each beside the twin without the save guard); `tables.js` scans `views/` and `assets/` too.
51
+ - Not in 0.2: db-worker's kind locks (until then a closed kind is held by the gate and by `can()`); people and roles
52
+ and the portal session; the record read back (Who came in, Activity).
53
+
54
+ Review round 1 (before release):
55
+
56
+ - CD-22: a fit read in flight when `forget()` ran stored its answer from before the narrowing write, so the next click
57
+ was served it for up to `fitMemoMs` (a write after Never went through). A forget generation keeps such an answer out
58
+ of the memo. The README's order was wrong as well: `forget()` comes AFTER the narrowing write commits.
59
+ - CD-44: a visit could end with NO stop row in one process: the claim was taken before the write, so when the first
60
+ claimer's re-read lost the race to another request's write, neither wrote the row. The claim is now taken after the
61
+ request's own write saved. The burst checks run on stores that answer out of order (the old in-order store could not
62
+ show it); "exactly one" is asserted in one process, "at least one, at most one per process" across two.
63
+ - A gate the app forgot on a mount listed in `mounts`: `visits.requirePermission` fell back to the app's guard
64
+ (unpinned, the partner's role, Never ignored), silently. It now refuses (403, `X-Work-In: no-gate`) and logs at error.
65
+ `isGate(fn)` and `isVisitGuard(fn)` let an app's wiring test walk its route stacks.
66
+ - CD-23 and the record, with tenancy 0.5.0's corrected guard: the start from no visit is guarded (`mode.guard(req)`),
67
+ its notice is flashed BEFORE the write, and the write is a compare-and-write (only while the stored session holds no
68
+ visit). Before, a start saved the visit and then flashed, so a Leave in another tab in between was written back over
69
+ (from no visit, unguarded; from a visit, the guard's old baseline), and two starts at once left the visit started in
70
+ between wiped with no stop row. Now the losing start is refused 409 `busy` and its start row gets a stop row
71
+ (`refused`, because `busy`).
72
+ - A missing `visits.loaded` went unnoticed for a house person working in a partner (fleet view's `loaded` keeps the
73
+ shared copy for acting sessions, which is what the check read), leaving the save guard off. `visits.loaded` now marks
74
+ each request in the package's own set, and `track` refuses every request it did not mark (500,
75
+ `X-Work-In: not-loaded`), logged at error.
76
+ - The rows' `acting_as_partner` came from the session when the row was written: a visit made working in A that ended
77
+ after acting stopped lost it, and a house visit that ended after acting started gained A. Both rows now carry it from
78
+ the record, and the app's helper is given the request as the visit was made.
79
+ - `audit` must return the promise of its write ("a failed start row stops the start" held only then); an answer that
80
+ is not a promise is an error naming `audit`.
81
+ - The gated mounts are matched as Express dispatches (case-blind by default; `caseSensitive: true` for an app that set
82
+ case-sensitive routing): `POST /NOTES` reached the notes router and the gate answered a 500 with no `X-Work-In`.
83
+ - `platformOnly` (optional): a platform-only permission named in `permission`, `levels` or `notCapped` is refused at
84
+ construction (a role is judged at partner scope at the home partner, where none is held).
85
+ - The values of `messages` are checked at construction (a sentence or a function; `refusal` and `invalid` by reason).
86
+ - README: what the CD-25 rewrite does not reach (a body parsed after the gate, route params) and what still protects
87
+ it (the pin) or does not (any use of the customer outside the database); the standard's version (7, not 3).
88
+ - The wiring mistakes the package detects (a gate in front of the wrong mount; a gate or the status route with no
89
+ `track` before it) answered a bare 500 with no marker: they now answer 500 `X-Work-In: wiring`, logged at error.
90
+ `stats()` reports the fit memo's and the ended set's sizes and bounds.
91
+ - Checks for README claims nothing checked: `roleCan` answering a promise or throwing is a "no", logged; a session with
92
+ no staff user is passed on by the gate; `sessionEnding` or `decide` throwing ends the visit `refused`/`error`; the
93
+ wiring refusals' marker; the two bounds (5000 answers, 10000 ended visits, each ended visit kept at most four hours).
94
+
95
+ Review round 2:
96
+
97
+ - Two starts truly at once (no hold): when both compare-and-writes read the row before either save landed, both saved,
98
+ the later overwrote the earlier, and the earlier's start row had no stop row. The start now reads the row again once
99
+ its write has landed (a confirming read): another visit there → its stop row (`refused`, `busy`), its notice taken
100
+ back, 409 `busy`; gone → stop row `signed_out`, 409 `signed-out`. What is left: a confirming read that answers before
101
+ the other start's save lands still misses it (both answer "started", one start row stays without a stop row);
102
+ closing it needs an atomic compare-and-write in the session store. `track` cannot write that row: nothing the session
103
+ holds afterwards names the overwritten visit, and the package keeps no record of its own.
104
+ - The `busy` sentence was said whenever the first visit's end did not land, because the session in memory (put back as
105
+ loaded) still held the old visit, after a Leave or a sign-out in another tab too. The store now decides: another
106
+ visit → `busy`; signed out → 409 `signed-out` with its own sentence (`messages.signedOut`); no visit → the start
107
+ goes on; the store failing → an error (a start row already written gets `refused`, `error`).
108
+ - `visits.loaded` mounted BEFORE the session middleware marked the request anyway, so the visit ran with no save guard,
109
+ silently. It now marks only a request that has a session, and `track` also refuses a session holding a visit whose
110
+ save is not guarded (tenancy 0.5.0's `mode.isGuarded(req)`): 500 `X-Work-In: not-loaded`, logged at error.
111
+ - A start from no visit lost an earlier middleware's change of the same request (an activity stamp) to the row's
112
+ value: the copy of the session as loaded was taken at the start. Tenancy 0.5.0's guarded mode now keeps it for every
113
+ request (checked here with an app that stamps every request).
114
+ - The audit helper is given a VIEW of the request for a visit's own rows (a new object), so a lookup keyed by the
115
+ request missed it: a visit ended inside a pinned request wrote its stop row without `stampOf`'s stamp. `stampOf`
116
+ now finds the request behind the view, and `visits.requestOf(view)` gives it to an app's own lookups (README).
117
+ - `caseSensitive` disagreeing with the app's "case sensitive routing" is said once, at warn, by `track`.
118
+
119
+ Review round 3:
120
+
121
+ - CD-60, a regression of round 1: since the start wrote by merging into the row, a start racing fleet view's switch in
122
+ another tab (fleet view judged off at the way in, switched on before the write) kept fleet view's keys and added the
123
+ visit: both on, pages pinned, and Leave refused by fleet view's read-only guard. Now:
124
+ - `track` ends a visit whose session carries fleet view (fleet view's `inRow`): `refused`, because `fleet-view`, one
125
+ stop row, the request outside; the two are never on for a request, whatever the race;
126
+ - the start's compare-and-write and its confirming read refuse a row in fleet view, or whose place (working in a
127
+ partner, the partner) is not the one the way in judged: 409 `fleet-view` / `acting` / `partner`, the start row
128
+ paired (`refused`, because the same), the notice taken back, a visit already stored ended through the session mode;
129
+ - fleet view's start check reads the stored row again when the session as loaded holds no visit (refused when one
130
+ landed since; a row it cannot read refuses, logged) and guards fleet view's own save for the visit key, so a visit
131
+ landing in between is kept (and ended by the next request) instead of wiped with no stop row;
132
+ - CD-21: fleet view's `readOnlyExcept` must list `POST <mountPath>/leave`; `createVisits` asks fleet view's own
133
+ `classify` and refuses to build without it. `fleetView` must carry `inRow` (tenancy 0.5.0).
134
+ What is left (README): a start and the switch whose writes cross within one store round trip are stored together
135
+ until the next request ends the visit, or the switch is lost.
136
+ - Named, not closed (the owner's ruling): a request that loaded the session before a start and saves after it overwrites
137
+ the new visit, whose start row then has no stop row. "The trail never shows a visit that was not" now says "except as
138
+ below".
139
+ - `messages.signedOut` covers signing in again too ("You were signed out, or signed in again, in another tab…"); the
140
+ README tells the app's sign-in to end the visit before `regenerate()`. `messages.placeChanged` is new.
141
+
142
+ Review round 4:
143
+
144
+ - When the confirming read found the visit stored where it was not judged, the end left the start's own notice beside
145
+ the end's sentence. The notice keys are now taken to the row's first (another tab's notice kept), and the end's own
146
+ write removes what the start's notice added. Taking the keys to the row's alone does not do it: the row the start's
147
+ own write landed in holds its notice.
148
+ - README: the place check reads tenancy's `contextFor`, so while the set of active partners is unknown or stale an
149
+ acting row reads as not acting (fails safe through the confirming read and `track`); for a partner known to be
150
+ inactive it deletes the acting keys from the row the start writes.
151
+
152
+ ## 0.1.0 — 2026-12-01 (published)
153
+
154
+ New package, part **access** (step 2 of the plan for the shared customer-driven piece, Platform D-0013). Needs
155
+ `@aria-framework/db-worker` 0.31.0 or later.
156
+
157
+ - Rules, version 2 of the model: no helper tier (one helper per customer, its partner; the house is the partner of its
158
+ own direct customers); a setting per kind of data; a grant per customer opening every kind not set to Never; the
159
+ managed mark in force only while every kind not set to Never is May come in (D-0014 answer 9). Moved from the first
160
+ customer-driven app's rules with the tier list, its helper functions and the house's separate starting value removed.
161
+ - `defineKinds`: the app's kinds of data, every field required.
162
+ - `createAccessStore`: the reads and writes of the five tables as one worker model (the customer's people, a pinned
163
+ helper, the partner's staff, a platform read for one partner, the sweep), with `ACCESS_CUSTOMER_SAFE` for the app's
164
+ customer-safe list. Every query states its partner.
165
+ - The tables as a db-worker definition set, `customer_access` 1.0.0, with new names for version 2
166
+ (`customer_access_settings`, `_defaults`, `_grants`, `_requests`, `_managed`), the manifest fragment and the schema
167
+ check; the columns the package needs of the app's `customers` and `customer_contacts` stated as anchors.
168
+ - The audit action names and words, and `sweepAudit`.
169
+ - A stored row of a kind the app no longer has is an error with status 500 (a kind a caller names: 400). The README says
170
+ what such a row blocks, that the store cannot tell whether fleet view is on, and one known race (a grant and an
171
+ all-Never save at the same moment).
172
+ - Not yet: visits, the record read back, people and roles, the kind locks in db-worker.