@stacksjs/defaults 0.75.539 → 0.75.541
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/ai/AGENTS.md +2 -0
- package/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-auth/SKILL.md +8 -1
- package/ai/skills/stacks-dashboard/SKILL.md +196 -3
- package/ai/skills/stacks-dependencies/SKILL.md +46 -0
- package/ai/skills/stacks-development/SKILL.md +1 -1
- package/ai/skills/stacks-flow/SKILL.md +7 -0
- package/ai/skills/stacks-hq/SKILL.md +146 -0
- package/ai/skills/stacks-models/SKILL.md +21 -3
- package/ai/skills/stacks-native/CATALOG.md +22 -9
- package/ai/skills/stacks-new-app/SKILL.md +175 -0
- package/ai/skills/stacks-repl/SKILL.md +61 -43
- package/ai/skills/stacks-stx/SKILL.md +6 -2
- package/ai/skills/stacks-upstream/SKILL.md +188 -0
- package/ai/skills/stacks-writing-for-agents/SKILL.md +1 -1
- package/app/Actions/Dashboard/Data/UserIndexAction.ts +20 -2
- package/app/Actions/Dashboard/Models/ModelDestroyAction.ts +48 -12
- package/app/Actions/Dashboard/Models/ModelOptionsAction.ts +103 -0
- package/app/Actions/Dashboard/Models/ModelRelatedAction.ts +42 -0
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +75 -12
- package/app/Actions/Dashboard/Models/ModelStoreAction.ts +7 -1
- package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +16 -2
- package/app/Actions/Dashboard/Models/model-destroy.ts +75 -0
- package/app/Actions/Dashboard/Models/model-options.ts +56 -0
- package/app/Actions/Dashboard/Models/model-related.ts +202 -0
- package/app/Actions/Dashboard/Models/model-relations.ts +172 -0
- package/app/Actions/Dashboard/Models/model-write.ts +240 -51
- package/app/Actions/Dashboard/Users/UserInviteAction.ts +50 -0
- package/app/Actions/Dashboard/Users/user-invitation.ts +110 -0
- package/app/Models/Activity.ts +4 -0
- package/app/Models/AnalyticsEvent.ts +4 -0
- package/app/Models/Automation.ts +4 -0
- package/app/Models/AutomationRun.ts +4 -0
- package/app/Models/Board.ts +4 -1
- package/app/Models/BoardColumn.ts +4 -1
- package/app/Models/Campaign.ts +4 -0
- package/app/Models/CampaignSend.ts +4 -0
- package/app/Models/CampaignVariant.ts +4 -0
- package/app/Models/Card.ts +4 -1
- package/app/Models/CardAttachment.ts +4 -0
- package/app/Models/CommunicationSuppression.ts +4 -0
- package/app/Models/ConsentEvent.ts +4 -0
- package/app/Models/Deployment.ts +1 -0
- package/app/Models/EmailList.ts +4 -0
- package/app/Models/EmailListSubscriber.ts +4 -0
- package/app/Models/Error.ts +4 -0
- package/app/Models/FailedJob.ts +4 -0
- package/app/Models/FeedbackToken.ts +4 -0
- package/app/Models/GdprRequest.ts +4 -0
- package/app/Models/Job.ts +4 -0
- package/app/Models/Log.ts +4 -0
- package/app/Models/MagicLinkToken.ts +4 -0
- package/app/Models/MailPreference.ts +4 -0
- package/app/Models/Notification.ts +4 -0
- package/app/Models/NotificationDelivery.ts +4 -0
- package/app/Models/PersonalAccessToken.ts +4 -0
- package/app/Models/QueryLog.ts +4 -0
- package/app/Models/Referral.ts +4 -0
- package/app/Models/Release.ts +1 -0
- package/app/Models/Request.ts +4 -0
- package/app/Models/SenderDomain.ts +4 -0
- package/app/Models/Site.ts +1 -0
- package/app/Models/SiteDomain.ts +4 -0
- package/app/Models/SocialPost.ts +4 -0
- package/app/Models/StorageItemTask.ts +4 -1
- package/app/Models/Subscriber.ts +4 -0
- package/app/Models/Subscription.ts +4 -0
- package/app/Models/Team.ts +1 -0
- package/app/Models/TeamInvitation.ts +1 -0
- package/app/Models/TeamMember.ts +1 -0
- package/app/Models/UsageEvent.ts +4 -0
- package/app/Models/User.ts +15 -3
- package/functions/dashboard-model-record.test.ts +276 -18
- package/functions/dashboard-model-record.ts +412 -55
- package/functions/data.ts +2 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +5 -5
- package/resources/components/Dashboard/Analytics/AnalyticsHub.stx +1 -1
- package/resources/components/Dashboard/Analytics/CampaignAnalytics.stx +1 -1
- package/resources/components/Dashboard/Analytics/EventAnalytics.stx +1 -1
- package/resources/components/Dashboard/Analytics/SalesAnalytics.stx +1 -1
- package/resources/components/Dashboard/Analytics/WebAnalyticsBreakdown.stx +1 -1
- package/resources/components/Dashboard/App/RequestsOverview.stx +1 -1
- package/resources/components/Dashboard/App/SourceInventory.stx +1 -1
- package/resources/components/Dashboard/Auth/AccessTokens.stx +1 -1
- package/resources/components/Dashboard/Buddy/BuddyAssistant.stx +1 -1
- package/resources/components/Dashboard/Ci/CiDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryPagination.stx +1 -1
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +1 -1
- package/resources/components/Dashboard/Content/BlogDashboard.stx +1 -1
- package/resources/components/Dashboard/DashboardLayout.stx +1 -1
- package/resources/components/Dashboard/Data/DataRecords.stx +43 -22
- package/resources/components/Dashboard/Data/UserInvite.stx +107 -0
- package/resources/components/Dashboard/Email/CapturedMailDashboard.stx +1 -1
- package/resources/components/Dashboard/Email/EmailActivityDashboard.stx +1 -1
- package/resources/components/Dashboard/Email/InboxDashboard.stx +1 -1
- package/resources/components/Dashboard/Email/InboxMessageDetail.stx +2 -2
- package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Home/DashboardHome.stx +6 -1
- package/resources/components/Dashboard/Infrastructure/CloudDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/DnsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/HealthDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/InsightsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/LogsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/MailboxesDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/ServerDetailsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/ServerlessDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/ServersDashboard.stx +1 -1
- package/resources/components/Dashboard/Jobs/JobDetail.stx +1 -1
- package/resources/components/Dashboard/Jobs/JobTable.stx +2 -2
- package/resources/components/Dashboard/Kanban/KanbanBoardDashboard.stx +1 -1
- package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +1 -1
- package/resources/components/Dashboard/Management/PermissionsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/AbandonedCartsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/CampaignsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/SocialPostsDashboard.stx +1 -1
- package/resources/components/Dashboard/Models/ModelFieldInputs.stx +125 -0
- package/resources/components/Dashboard/Models/ModelRecordCreate.stx +24 -66
- package/resources/components/Dashboard/Models/ModelRecordDetail.stx +36 -8
- package/resources/components/Dashboard/Models/ModelRecordEdit.stx +36 -32
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +72 -28
- package/resources/components/Dashboard/Models/ModelRelatedPanels.stx +99 -0
- package/resources/components/Dashboard/Models/ModelRelationPicker.stx +247 -0
- package/resources/components/Dashboard/Models/ModelsOverview.stx +1 -1
- package/resources/components/Dashboard/Notifications/NotificationDeliveries.stx +1 -1
- package/resources/components/Dashboard/Notifications/NotificationDeliveryHistory.stx +1 -1
- package/resources/components/Dashboard/Notifications/NotificationDeliveryOverview.stx +1 -1
- package/resources/components/Dashboard/Queries/QueryDashboard.stx +1 -1
- package/resources/components/Dashboard/Queries/QueryDetail.stx +1 -1
- package/resources/components/Dashboard/Queue/QueueDashboard.stx +1 -1
- package/resources/components/Dashboard/Realtime/RealtimeDashboard.stx +1 -1
- package/resources/components/Dashboard/Releases/ReleaseDashboard.stx +1 -1
- package/resources/components/Dashboard/Search/SearchEngineDashboard.stx +1 -1
- package/resources/components/Dashboard/Settings/MailSettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Settings/SettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Teams/TeamPeopleDashboard.stx +1 -1
- package/resources/components/Dashboard/UI/Drawer.stx +1 -1
- package/resources/components/Dashboard/UI/Input.stx +3 -2
- package/resources/components/Dashboard/UI/Modal.stx +1 -1
- package/resources/components/Dashboard/UI/Select.stx +8 -4
- package/resources/components/Dashboard/UI/Textarea.stx +18 -12
- package/resources/emails/password-reset.stx +3 -1
- package/routes/dashboard-api.ts +9 -0
- package/scaffold/config/analytics.ts +5 -3
- package/scaffold/resources/components/NextStep.stx +13 -0
- package/scaffold/resources/partials/head.stx +31 -0
- package/scaffold/resources/views/index.stx +23 -47
- package/scaffold/resources/views/layouts/default.stx +23 -0
- package/views/dashboard/data/users/invite.stx +8 -0
- package/views/dashboard/layouts/default.stx +21 -2
package/ai/AGENTS.md
CHANGED
|
@@ -92,12 +92,14 @@ in their stated context. `buddy generate`, `buddy generate:auto-imports` and
|
|
|
92
92
|
| Situation | Skill |
|
|
93
93
|
|---|---|
|
|
94
94
|
| Which skill fits, and where to cut a session | `stacks-flow` |
|
|
95
|
+
| Start an app with `buddy new`, or give a fresh one its structure | `stacks-new-app` |
|
|
95
96
|
| Stress-test an idea before building it | `stacks-office-hours`, `stacks-grilling` |
|
|
96
97
|
| Answer a design question with throwaway code | `stacks-prototype` |
|
|
97
98
|
| Plan the change: scope, seams, test matrix | `stacks-plan-review`, `stacks-codebase-design` |
|
|
98
99
|
| Name things, keep `CONTEXT.md` and ADRs current | `stacks-domain-modeling` |
|
|
99
100
|
| Build it test-first, one tracer bullet at a time | `stacks-tdd`, `stacks-new-feature` |
|
|
100
101
|
| Something is broken, flaky or slow | `stacks-investigate` |
|
|
102
|
+
| The problem is in a dependency: fix it in the owning repository | `stacks-upstream` |
|
|
101
103
|
| Review the diff on standards and spec | `stacks-review` |
|
|
102
104
|
| A step only a human can take | `stacks-wizard` |
|
|
103
105
|
| Improve the environment for next time | `stacks-retro` |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-actions
|
|
3
|
-
description: Use when working with Stacks server actions - creating actions in app/Actions/, auto-generated API actions from the useApi model trait, the
|
|
3
|
+
description: Use when working with Stacks server actions - creating actions in app/Actions/, auto-generated API actions from the useApi model trait, the 736 default framework actions (auth, dashboard, commerce, content, deployment, jobs), action request/response handling, or action registration. Covers @stacksjs/actions and storage/framework/defaults/app/Actions/.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -450,7 +450,14 @@ const result = await actions.resetPassword(token, newPassword)
|
|
|
450
450
|
|
|
451
451
|
`deliver` runs after the token commits, instead of the framework mail; the
|
|
452
452
|
`token`/`url` are the live credential, never log them. `sendEmail` stays a
|
|
453
|
-
|
|
453
|
+
no-op for unknown or throttled addresses (anti-enumeration) and resolves
|
|
454
|
+
`false` for them, `true` when a link was issued and delivered. That result is
|
|
455
|
+
for the server: a public endpoint keeps answering every caller the same way,
|
|
456
|
+
while an operator-facing one (the dashboard's user invitation) has to know the
|
|
457
|
+
mail did not go. The mail states the link's lifetime in words ("7 days", "2
|
|
458
|
+
hours", "60 minutes") through the `expiresIn` template variable
|
|
459
|
+
(`describeLinkLifetime`); `expireMinutes` is still passed for templates an app
|
|
460
|
+
overrides.
|
|
454
461
|
|
|
455
462
|
### One credential sweep (password/credentials.ts)
|
|
456
463
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: stacks-dashboard
|
|
3
|
-
description: Use when building or customizing the Stacks admin dashboard, including dashboard pages, model management views, analytics widgets, commerce dashboards, content management, settings panels, deployment monitoring, job/queue management, or the
|
|
3
|
+
description: Use when building or customizing the Stacks admin dashboard, including dashboard pages, model management views, analytics widgets, commerce dashboards, content management, settings panels, deployment monitoring, job/queue management, or the 421 built-in dashboard components. Covers the dashboard system at storage/framework/defaults/.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -8,7 +8,7 @@ allowed-tools: Read Edit Write Bash Grep Glob
|
|
|
8
8
|
|
|
9
9
|
# Stacks Dashboard
|
|
10
10
|
|
|
11
|
-
The Stacks admin dashboard provides a full-featured admin panel with 100+ route views,
|
|
11
|
+
The Stacks admin dashboard provides a full-featured admin panel with 100+ route views, 421 components, and a multi-section layout.
|
|
12
12
|
|
|
13
13
|
## Key Paths
|
|
14
14
|
- Dashboard components: `storage/framework/defaults/resources/components/Dashboard/`
|
|
@@ -606,7 +606,14 @@ The desktop sidebar is fixed and publishes its current width through
|
|
|
606
606
|
`--stx-sidebar-width` on the dashboard content shell. Fixed dialogs and
|
|
607
607
|
drawers must use the shared `dashboard-modal-layer` class so their interactive
|
|
608
608
|
surface starts beside that sidebar and returns to `left: 0` on mobile and in
|
|
609
|
-
the Craft native-sidebar shell.
|
|
609
|
+
the Craft native-sidebar shell. The class owns the layer's whole horizontal
|
|
610
|
+
box (`left`, `right` and `width`), so a dialog is centred over the content and
|
|
611
|
+
a drawer ends at the window's edge. Do not put a width utility (`w-screen`,
|
|
612
|
+
`w-full`) on an element that carries it: beside `left: 250px` that runs the
|
|
613
|
+
layer a sidebar's width past the window. The rule's selector is
|
|
614
|
+
`html .dashboard-modal-layer`, so it outweighs `inset-0` whichever stylesheet
|
|
615
|
+
loads last; a bare class did not, and dialogs moved depending on how the page
|
|
616
|
+
was reached.
|
|
610
617
|
|
|
611
618
|
Use `Dashboard/UI/Modal`, `Dashboard/UI/Drawer`, and
|
|
612
619
|
`Dashboard/UI/ConfirmDialog` for page dialogs, inspectors, forms, and
|
|
@@ -685,6 +692,192 @@ or separate routes generated by `useApi`. Configure `security.api.models` or
|
|
|
685
692
|
new boundary does not provide row ownership or permission checks for models
|
|
686
693
|
that remain exposed.
|
|
687
694
|
|
|
695
|
+
## What the dashboard may write to a model
|
|
696
|
+
|
|
697
|
+
Every record has a page to view it (`/models/{slug}/{id}`), and where the
|
|
698
|
+
model allows, a page to edit it, a page to create one, and a delete behind a
|
|
699
|
+
confirmation. Table rows carry the same three as icons: eye, pencil, trash.
|
|
700
|
+
|
|
701
|
+
Which of those a model gets comes from one of two places:
|
|
702
|
+
|
|
703
|
+
- Left alone, the dashboard offers the writes the model's `useApi` routes
|
|
704
|
+
declare (`store`, `update`, `destroy`).
|
|
705
|
+
- `dashboard: { writes: [...] }` names them instead, wider or narrower. Use it
|
|
706
|
+
when an operator should be able to do what the API should not offer. `User`
|
|
707
|
+
declares `writes: ['store', 'update', 'destroy']` and keeps `update` and
|
|
708
|
+
`destroy` off its API, where a generated PATCH would let a caller change
|
|
709
|
+
their own email and password outside the flows that verify them.
|
|
710
|
+
`writes: []` makes a model read-only in the dashboard whatever its API
|
|
711
|
+
allows.
|
|
712
|
+
|
|
713
|
+
These writes go through the dashboard's own guarded endpoints
|
|
714
|
+
(`/api/dashboard/models/{slug}`), so naming one opens nothing on the public
|
|
715
|
+
API. Creating still needs a form that can supply every required field: a
|
|
716
|
+
model with a required hidden field, like `User.password`, is not creatable
|
|
717
|
+
here even when `store` is named.
|
|
718
|
+
|
|
719
|
+
### What the forms ask for, and how
|
|
720
|
+
|
|
721
|
+
The create and edit forms offer a model's `fillable` attributes, less the
|
|
722
|
+
`hidden` ones and the protected columns (`password`, tokens, secrets, `id`,
|
|
723
|
+
`uuid`, the timestamps), plus the foreign key of each `belongsTo`. The server
|
|
724
|
+
applies the same list, so a request naming anything else is ignored.
|
|
725
|
+
|
|
726
|
+
Each field's control follows its validation rule (`modelFieldType`), and both
|
|
727
|
+
forms draw them with one component, `Dashboard/Models/ModelFieldInputs`:
|
|
728
|
+
|
|
729
|
+
| Rule | Control | Stored as |
|
|
730
|
+
|---|---|---|
|
|
731
|
+
| `enum` | select of its allowed values | the value |
|
|
732
|
+
| `boolean` | checkbox | true or false |
|
|
733
|
+
| `number`, `integer`, `float`, `unix` | number box | a number |
|
|
734
|
+
| `date` | date picker | the calendar day |
|
|
735
|
+
| `timestamp`, `timestampTz`, `datetime` | date and time, in the visitor's zone | UTC `YYYY-MM-DD HH:MM:SS` (ISO for `timestampTz`) |
|
|
736
|
+
| a declared `belongsTo` | search for the related record by name | its id |
|
|
737
|
+
| `json` | tall fixed-width box, checked on save | JSON text |
|
|
738
|
+
| `string` with `type: 'text'` | tall box | text |
|
|
739
|
+
| any other `string` | one line (`email` when the name says so) | text |
|
|
740
|
+
|
|
741
|
+
An edit sends only the fields that were changed. Labels, and the
|
|
742
|
+
model's own name in titles, come from `humanizeIdentifier` ("Social Post",
|
|
743
|
+
"Image URL").
|
|
744
|
+
|
|
745
|
+
### Relations are picked by name
|
|
746
|
+
|
|
747
|
+
A `belongsTo` is stored as an id and asked for as the record: each one is a
|
|
748
|
+
`relation` field drawn by `Dashboard/Models/ModelRelationPicker`, a search box
|
|
749
|
+
that lists the related model's records and stores the chosen one's id. It is
|
|
750
|
+
one field whether the model leaves the key to the relation (`belongsTo:
|
|
751
|
+
['Team']`) or also spells it out as an attribute (`userId`). Both spellings of
|
|
752
|
+
a relation are read, the object form and its `foreignKey` included.
|
|
753
|
+
|
|
754
|
+
Only a declared `belongsTo` is a relation. Other fields ending in `Id`
|
|
755
|
+
(`externalId`, `providerMessageId`, a polymorphic `subjectId`) stay as they
|
|
756
|
+
are, and so does a relation to a model the dashboard cannot reach (its
|
|
757
|
+
feature is off, or `dashboard.access` is false).
|
|
758
|
+
|
|
759
|
+
`GET /api/dashboard/models/{slug}/options` backs the picker: `?q=` searches by
|
|
760
|
+
what a record is called and `?ids=3,7` names exactly those. A record is called
|
|
761
|
+
by the first of `name`, `title`, `label`, `subject`, `email`, `domain`, `code`,
|
|
762
|
+
`slug` the model has, with a person's email beside it, and by `Model #id` when
|
|
763
|
+
it has none of them (such a model is searchable by id only).
|
|
764
|
+
|
|
765
|
+
A record's page shows each relation as a link to the related record, by name.
|
|
766
|
+
A write naming a record that has since been deleted comes back on that field
|
|
767
|
+
("That team no longer exists. Choose another.").
|
|
768
|
+
|
|
769
|
+
### A model chooses its list columns
|
|
770
|
+
|
|
771
|
+
A model's list (`/models/{slug}`) shows every column its table has unless the
|
|
772
|
+
model names the ones it wants, in order:
|
|
773
|
+
|
|
774
|
+
```ts
|
|
775
|
+
dashboard: { columns: ['name', 'email', 'team', 'createdAt'] }
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
A name is an attribute (`createdAt`), its column (`created_at`), or a
|
|
779
|
+
`belongsTo` (`team` for `team_id`). The same choice shapes the model's panel
|
|
780
|
+
on another record's page. The record's own page still shows every field.
|
|
781
|
+
|
|
782
|
+
It narrows what is drawn, not what is reachable: every column can still be
|
|
783
|
+
sorted and filtered on, a `hidden` attribute stays hidden if it is named, and
|
|
784
|
+
a column the list is filtered on is drawn even when the model left it out, so
|
|
785
|
+
the filter can be seen and cleared. A name the table does not have is left
|
|
786
|
+
out and logged once (`[dashboard] User names 'nickname' in
|
|
787
|
+
dashboard.columns...`); a list of nothing but such names falls back to every
|
|
788
|
+
column.
|
|
789
|
+
|
|
790
|
+
The shipped models that people browse name theirs (43 of them, the widest
|
|
791
|
+
going from 34 columns to 6): what the record is called, the records it links
|
|
792
|
+
to, its status, and its most useful number or date. A model you add shows
|
|
793
|
+
every column until you choose. `tests/unit/dashboard-model-columns.test.ts`
|
|
794
|
+
checks that every shipped choice names real, showable columns.
|
|
795
|
+
|
|
796
|
+
In any list, a column that holds another model's id shows that record's name
|
|
797
|
+
as a link to it ("PrimeSoft Ltd", not `3`), under the model's name ("Team",
|
|
798
|
+
not "Team ID"). The list endpoint returns the names with the rows
|
|
799
|
+
(`relationNames`), one lookup per related model per page, and a record's page
|
|
800
|
+
uses the same ones.
|
|
801
|
+
|
|
802
|
+
### A record's page lists who points at it
|
|
803
|
+
|
|
804
|
+
For each `hasMany` and `hasOne` a model declares, its record page shows a
|
|
805
|
+
panel (`Dashboard/Models/ModelRelatedPanels`): a team's members and
|
|
806
|
+
invitations, a user's team memberships. Nothing is declared for the
|
|
807
|
+
dashboard; `GET /api/dashboard/models/{slug}/{id}/related` reads the model.
|
|
808
|
+
|
|
809
|
+
A panel is the newest five with the total. Its columns are the related
|
|
810
|
+
model's `dashboard.columns` when it names any. Otherwise they are chosen for
|
|
811
|
+
telling rows apart: what the related record is called, the other records it
|
|
812
|
+
points at (by name), its `enum` fields as badges, and when it was created.
|
|
813
|
+
Either way the link back to the page's own record is left out.
|
|
814
|
+
|
|
815
|
+
- The eye opens the related record.
|
|
816
|
+
- "View all" opens the related model's list narrowed to this record
|
|
817
|
+
(`/models/team-member?filters={"team_id":"3"}`); the list arrives with its
|
|
818
|
+
filter row open.
|
|
819
|
+
- "Add" opens the related model's create form with this record already
|
|
820
|
+
chosen (`?teamId=3`) and returns here. It is offered when that model can be
|
|
821
|
+
created from the dashboard, and for a `hasOne` only while there is none.
|
|
822
|
+
|
|
823
|
+
The link between the two models is the foreign key the declaration names,
|
|
824
|
+
else the related model's own `belongsTo`, else the conventional
|
|
825
|
+
`<model>_id` column. With none of those the relation gets no panel; so does a
|
|
826
|
+
related model the dashboard cannot reach.
|
|
827
|
+
|
|
828
|
+
The edit form never writes `password`, tokens, secrets, `id`, `uuid` or the
|
|
829
|
+
timestamps. A refused save comes back as a message under its field (a rule
|
|
830
|
+
the value breaks, or a `unique` value another row holds). A delete the
|
|
831
|
+
database refuses because other records point at the row is reported as that,
|
|
832
|
+
and an account cannot delete itself.
|
|
833
|
+
|
|
834
|
+
### A user other records refer to is anonymized, not refused
|
|
835
|
+
|
|
836
|
+
Many tables point at `users`, so anyone who has signed in, joined a team or
|
|
837
|
+
placed an order cannot be deleted, and deleting through all of those tables
|
|
838
|
+
from one trash icon would destroy far more than the operator sees. When the
|
|
839
|
+
database refuses to delete a `User`, the dashboard applies the app's erasure
|
|
840
|
+
rules instead (`eraseSubject`, the same thing `buddy gdpr:erase` runs): each
|
|
841
|
+
model's `gdpr` trait says whether that person's rows are deleted, anonymized
|
|
842
|
+
or kept, in one transaction with a `gdpr_requests` audit row recorded against
|
|
843
|
+
the admin who asked. With the shipped rules the account stays, its name,
|
|
844
|
+
email, avatar and password are replaced with placeholders, its tokens and
|
|
845
|
+
sessions are revoked, and the records that refer to it are kept.
|
|
846
|
+
|
|
847
|
+
The capability is `anonymize` (true for a deletable `User`), so the delete
|
|
848
|
+
confirmation says this before the button is pressed; the response carries
|
|
849
|
+
`anonymized: true` and the toast says "anonymized", not "deleted". A user
|
|
850
|
+
nothing refers to is still simply deleted. Every other model is still refused
|
|
851
|
+
with the reason.
|
|
852
|
+
|
|
853
|
+
An anonymized account is stored as `[erased]` / `erased-<id>`. The Users list
|
|
854
|
+
shows it as "Anonymized user" with an "Anonymized" badge, and its own page
|
|
855
|
+
carries a note, using `anonymizedRows('User', rows)` from `@stacksjs/orm`,
|
|
856
|
+
which asks the erasure plan whether a row's personal columns hold what
|
|
857
|
+
erasure writes. An anonymized account can be viewed and nothing else: its row
|
|
858
|
+
loses the pencil and trash (the table's per-row `when`), its page has no Edit
|
|
859
|
+
or Delete, and its edit address explains why there is no form. That is the
|
|
860
|
+
dashboard's choice of what to offer, not a rule of the endpoints: deleting
|
|
861
|
+
one again changes nothing, and a row given a real name and email again is an
|
|
862
|
+
account again.
|
|
863
|
+
|
|
864
|
+
### Users are invited, not typed in
|
|
865
|
+
|
|
866
|
+
`User.password` is required and hidden, so no form can supply it, and a
|
|
867
|
+
password typed by an operator would have to reach the person some other way.
|
|
868
|
+
When `User` allows `store`, its capability is `invite` instead of `create`:
|
|
869
|
+
the Users page and the model browser show "Invite user", which opens
|
|
870
|
+
`/data/users/invite` (name and email). `POST /api/dashboard/users/invitations`
|
|
871
|
+
creates the account with a random password nobody is shown and mails the
|
|
872
|
+
framework's account-setup link (`passwordResets(email).sendEmail({ purpose:
|
|
873
|
+
'setup' })`), valid for 7 days (`USER_INVITATION_DAYS`). The holder chooses
|
|
874
|
+
their password from that link; "Forgot password" works too if it expires.
|
|
875
|
+
|
|
876
|
+
An invitation whose mail could not be sent removes the account it created, so
|
|
877
|
+
a mail outage leaves no accounts whose holders were never told, and the retry
|
|
878
|
+
is not refused as a duplicate. An address that already has an account is
|
|
879
|
+
refused on the email field. Drop `store` from `dashboard.writes` to turn
|
|
880
|
+
inviting off.
|
|
688
881
|
|
|
689
882
|
## Application observability
|
|
690
883
|
|
|
@@ -84,6 +84,52 @@ Core packages use `workspace:*` references:
|
|
|
84
84
|
| `ts-mocker` | Fake data generation |
|
|
85
85
|
| `ts-slug` | URL slug generation |
|
|
86
86
|
|
|
87
|
+
## The STX packages: one version, declared by the app
|
|
88
|
+
|
|
89
|
+
STX is six packages released together at one version: `@stacksjs/stx` (the
|
|
90
|
+
runtime), `@stacksjs/components`, `bun-plugin-stx` (the compiler),
|
|
91
|
+
`stx-router`, `@stacksjs/desktop` and `@stacksjs/sanitizer`. They pin each
|
|
92
|
+
other exactly, so choosing a version of the runtime chooses all six. Two
|
|
93
|
+
versions in one app is two runtimes that do not share what they register:
|
|
94
|
+
pages render with no routes or components, and the install log says nothing.
|
|
95
|
+
|
|
96
|
+
An app picks its STX version in its own `package.json`, as ordinary
|
|
97
|
+
dependencies, all three on the same version:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"dependencies": { "stacks": "^0.75.540", "@stacksjs/stx": "0.2.851" },
|
|
102
|
+
"devDependencies": { "@stacksjs/components": "0.2.851", "bun-plugin-stx": "0.2.851" }
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The framework's packages ask for the release they were tested against or
|
|
107
|
+
newer (`^0.2.842`), so they resolve to the app's copy. **No `overrides` are
|
|
108
|
+
needed, and an app should not have any for these packages**: an override
|
|
109
|
+
only stops the app choosing a newer STX without editing it too. They used to
|
|
110
|
+
be necessary because the framework pinned STX exactly, which gave an app on a
|
|
111
|
+
newer patch two copies.
|
|
112
|
+
|
|
113
|
+
- Raise all three together. Raising one leaves the others behind, and that
|
|
114
|
+
is two versions again.
|
|
115
|
+
- `buddy doctor` reports it: `STX packages: one copy, 0.2.851`, or which
|
|
116
|
+
versions are installed and where.
|
|
117
|
+
- `buddy upgrade` raises the three to the release the framework was tested
|
|
118
|
+
against when the app is behind it, and leaves a newer one alone.
|
|
119
|
+
- An app that declares none of them gets the newest STX the range allows at
|
|
120
|
+
install time. `buddy new` declares them, so a new app is on a tested
|
|
121
|
+
release from the start.
|
|
122
|
+
|
|
123
|
+
In the framework repository itself, the root `package.json` names the
|
|
124
|
+
release exactly and holds every workspace package to it through `overrides`:
|
|
125
|
+
a workspace resolves each package's range on its own, and without the hold
|
|
126
|
+
the ones the root does not declare took a newer release than the runtime.
|
|
127
|
+
`buddy new` removes those overrides from the app it creates. To move the
|
|
128
|
+
framework to a new STX release, change the root's three declarations, its
|
|
129
|
+
five overrides, and the `^` floor in every `storage/framework/core/*`
|
|
130
|
+
manifest to the same version; `tests/declared-dependencies.test.ts` fails on
|
|
131
|
+
any that disagree.
|
|
132
|
+
|
|
87
133
|
## CLI Commands
|
|
88
134
|
|
|
89
135
|
```bash
|
|
@@ -72,6 +72,13 @@ A starting situation that generates work, then merges onto the main flow.
|
|
|
72
72
|
red on *this* bug, then fixes with a regression test. When the real finding is
|
|
73
73
|
that there is no good seam to lock the bug down, it hands off to
|
|
74
74
|
`stacks-codebase-design`.
|
|
75
|
+
- **There is no app yet, or a fresh one has no shape** goes to
|
|
76
|
+
**`/stacks-new-app`**: scaffold, ports, the layout, partial, component and
|
|
77
|
+
data structure, theme tokens, and the first verification loop. It merges onto
|
|
78
|
+
the main flow at `stacks-domain-modeling`.
|
|
79
|
+
- **The problem is in a dependency** goes to **`/stacks-upstream`**. Name the
|
|
80
|
+
owning repository, reproduce and fix it there, release, and prove the fix
|
|
81
|
+
from an installed version. The app carries a version bump, never a shim.
|
|
75
82
|
- **A visual surface needs to be built or lifted** goes to
|
|
76
83
|
**`/stacks-design-taste`**, or `/stacks-redesign` when the UI already exists
|
|
77
84
|
and needs auditing first. Those two carry their own flow, including the
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: stacks-hq
|
|
3
|
+
description: Use when metering usage against a plan allowance, answering the X-HQ-Usage header, mounting an HQ service's connect and usage endpoints, or reading an HQ service from an app. Covers @stacksjs/hq (meter, service, client, testing).
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
|
+
allowed-tools: Read Edit Write Bash Grep Glob
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# HQ services: metering, the service contract, readers
|
|
10
|
+
|
|
11
|
+
`@stacksjs/hq` holds what every Stacks HQ service (BugHQ, LogHQ, AnalyticsHQ,
|
|
12
|
+
StatusHQ, CommsHQ) must do the same way. The services stay separate: each keeps
|
|
13
|
+
its own accounts, keys, plans and billing. This package shares code, never
|
|
14
|
+
identity. It has no runtime dependencies; a database client or a store is
|
|
15
|
+
passed in.
|
|
16
|
+
|
|
17
|
+
Import from the subpath you need: `@stacksjs/hq/meter`, `@stacksjs/hq/service`,
|
|
18
|
+
`@stacksjs/hq/client`, `@stacksjs/hq/testing`.
|
|
19
|
+
|
|
20
|
+
## Meter
|
|
21
|
+
|
|
22
|
+
Two primitives, chosen by who is waiting on the answer.
|
|
23
|
+
|
|
24
|
+
**Counter, for ingest.** `createCounter({ store })` buffers deltas in memory and
|
|
25
|
+
folds them into `usage_counters` on a timer (ten seconds by default). `record`
|
|
26
|
+
and `admit` never await and never query, so metering adds no round-trip to an
|
|
27
|
+
ingest route. The fold is an additive upsert computed by the database, so
|
|
28
|
+
several app instances converge on one total. A crash loses at most one flush
|
|
29
|
+
interval.
|
|
30
|
+
|
|
31
|
+
- `sqlCounterStore(db, { dialect })` is the store over `usage_counters`, keyed by
|
|
32
|
+
(owner, meter, period). The period is `YYYY-MM` in UTC (`periodOf`).
|
|
33
|
+
- `usageCountersMigrationSql({ dialect })` returns the table's DDL for a
|
|
34
|
+
migration; `ensureUsageCountersTable(db)` provisions it explicitly. Nothing is
|
|
35
|
+
written implicitly.
|
|
36
|
+
- `counter.admit(owner, meter, limit)` decides one event and counts it. Kept
|
|
37
|
+
events count under `meter`, dropped ones under `droppedMeter(meter)`.
|
|
38
|
+
- `usageOf` answers `null` when nothing is known yet. Read that as "no reason to
|
|
39
|
+
act", not as zero.
|
|
40
|
+
|
|
41
|
+
**Reservation, for sends.** `reserveUsage(store, meter, quantity)` and
|
|
42
|
+
`releaseUsage` are a compare-and-set against a `UsageQuotaStore`. They fail
|
|
43
|
+
closed with `UsageQuotaError` (`unavailable`, `invalid`, `exceeded`,
|
|
44
|
+
`contention`). `@stacksjs/newsletter` re-exports them unchanged.
|
|
45
|
+
|
|
46
|
+
**Policy.** `evaluate(used, limit, policy)` is pure and returns
|
|
47
|
+
`{ state, allowed, used, limit, ceiling }`. `used` includes the unit being
|
|
48
|
+
decided. Thresholds are computed in integers.
|
|
49
|
+
|
|
50
|
+
| State | Meaning |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `ok` | under 80% of the allowance |
|
|
53
|
+
| `warn` | 80% or more, still inside it |
|
|
54
|
+
| `over` | allowance used up; the 20% grace is being spent, or a send is refused |
|
|
55
|
+
| `sampled` | an ingest meter past 120%, keeping one event in ten |
|
|
56
|
+
|
|
57
|
+
- `SOFT_INGEST` (`'soft-ingest'`): take everything to 120%, then keep every
|
|
58
|
+
tenth event. The choice is deterministic. Never answer non-2xx for quota: an
|
|
59
|
+
SDK would retry.
|
|
60
|
+
- `HARD_SEND` (`'hard-send'`): after the 20% grace `allowed` is false.
|
|
61
|
+
`enforceQuota(meter, used, limit)` throws the typed `QuotaExceededError`.
|
|
62
|
+
- A `null` limit is unlimited. A limit of `0` refuses the first send.
|
|
63
|
+
|
|
64
|
+
## The usage header
|
|
65
|
+
|
|
66
|
+
Every 2xx ingest response carries `X-HQ-Usage` (`USAGE_HEADER`):
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
X-HQ-Usage: errors;412;500;warn;upgrade=https%3A%2F%2Fbughq.example%2Fpricing
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The fields are `meter;used;limit;state;upgrade=<url>`. The limit is `unlimited`
|
|
73
|
+
for an unlimited meter, and the URL is percent-encoded. Build it with
|
|
74
|
+
`formatUsageHeader` and read it with `parseUsageHeader`, which answers `null`
|
|
75
|
+
for anything malformed instead of throwing.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const admission = counter.admit(project.owner_id, 'errors', limits.errors)
|
|
79
|
+
if (admission.accept)
|
|
80
|
+
await store(event)
|
|
81
|
+
return new Response(null, {
|
|
82
|
+
status: 202,
|
|
83
|
+
headers: { [USAGE_HEADER]: formatUsageHeader({ ...admission, upgradeUrl }) },
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Service contract
|
|
88
|
+
|
|
89
|
+
`createHqService(adapter)` returns handlers a service mounts in its own
|
|
90
|
+
`routes/hq.ts`. They take a Fetch-style request and return a `Response`.
|
|
91
|
+
|
|
92
|
+
| Route | Answer |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `POST /api/cli/connect` | `201 { code, approveUrl }` |
|
|
95
|
+
| `GET /api/cli/connect/{code}` | `{ status: 'pending' }`, or once approved `{ status: 'approved', project, ingestKey, readKey, dashboardUrl }`; `404 { status: 'expired' }` after that |
|
|
96
|
+
| `GET /api/v1/usage` | `{ meter, used, limit, period, state, upgradeUrl }[]`, authorised by `Authorization: Bearer <read key>` |
|
|
97
|
+
|
|
98
|
+
The adapter (`HqServiceAdapter`) is what the service implements: `approveUrl`,
|
|
99
|
+
`upgradeUrl`, `codes`, `provision`, `authenticateReadKey`, `usage`. The approve
|
|
100
|
+
page calls `describeConnect(code)` to show the app name and
|
|
101
|
+
`approveConnect(code, user)` once a signed-in user confirms.
|
|
102
|
+
|
|
103
|
+
Codes are single-use and expire after ten minutes. A store holds only the
|
|
104
|
+
SHA-256 of a code, and the approved keys wait encrypted under a key derived from
|
|
105
|
+
the code, so the table never contains a pollable code or a readable key. Use
|
|
106
|
+
`sqlConnectCodeStore(db)` with `connectCodesMigrationSql()`, or
|
|
107
|
+
`createMemoryConnectCodeStore()` in tests. Rate-limit `POST /api/cli/connect` in
|
|
108
|
+
the service's router.
|
|
109
|
+
|
|
110
|
+
Run the shared contract against the real adapter:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { hqServiceContract } from '@stacksjs/hq/testing'
|
|
114
|
+
|
|
115
|
+
hqServiceContract('bughq', async () => ({ adapter, user: await signedInUser() }))
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`createMemoryHqAdapter()` is a complete in-memory service for an app's own tests.
|
|
119
|
+
|
|
120
|
+
## Client
|
|
121
|
+
|
|
122
|
+
`createHqClient({ services })` takes each service's own `url`, `readKey` and
|
|
123
|
+
`project`. Readers never throw into the caller: every failure is an
|
|
124
|
+
`HqUnavailable` value with a `reason` (`not_configured`, `unauthorized`,
|
|
125
|
+
`timeout`, `network`, `http`, `bad_response`).
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const usage = await hq.getUsage('bughq')
|
|
129
|
+
if (usage.ok)
|
|
130
|
+
render(usage.data)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- `getUsage(service)` reads `GET /api/v1/usage`.
|
|
134
|
+
- `logs.list(query)` reads LogHQ's `GET /api/projects/{project}/logs`.
|
|
135
|
+
- `issues.list(query)` reads BugHQ's `GET /api/projects/{project}/issues`.
|
|
136
|
+
- `AnalyticsReader`, `UptimeReader` and `CommsReader` are interfaces only; the
|
|
137
|
+
package README lists the endpoint each service must expose first.
|
|
138
|
+
|
|
139
|
+
## Limits
|
|
140
|
+
|
|
141
|
+
- The counter is approximate by one flush interval per instance. Use a
|
|
142
|
+
reservation where an exact bound matters.
|
|
143
|
+
- After a restart the first event per owner is decided from zero while the
|
|
144
|
+
durable total loads behind it.
|
|
145
|
+
- This package does not create accounts, sign anyone in, or share keys between
|
|
146
|
+
services.
|
|
@@ -130,6 +130,18 @@ model-browser CRUD Actions before database work. Its default is `true`;
|
|
|
130
130
|
direct ORM calls, named domain Actions and generated `useApi` routes available.
|
|
131
131
|
Those APIs require their own route selection, middleware, ownership and policies.
|
|
132
132
|
|
|
133
|
+
`dashboard: { columns: ['name', 'email', 'team', 'createdAt'] }` names the
|
|
134
|
+
columns the model's dashboard list shows, in order, by attribute, column or
|
|
135
|
+
`belongsTo`. Left out, the list shows every column. See `stacks-dashboard`.
|
|
136
|
+
|
|
137
|
+
`dashboard: { writes: ['update', 'destroy'] }` names what an operator may do to
|
|
138
|
+
the model's rows from the dashboard (`store`, `update`, `destroy`). Left out,
|
|
139
|
+
the dashboard offers the writes the `useApi` routes declare. Name it when the
|
|
140
|
+
two should differ: `User` is editable and deletable in the dashboard while its
|
|
141
|
+
API offers neither, and `store` for it means an emailed invitation, since no
|
|
142
|
+
form can supply a password. It opens nothing on the generated API. See
|
|
143
|
+
`stacks-dashboard`.
|
|
144
|
+
|
|
133
145
|
`useApi` is an API capability, not a dashboard-view generator. Its generated
|
|
134
146
|
routes are registered from the merged model registry. Framework defaults are
|
|
135
147
|
loaded first, then recursive `app/Models/` definitions override matching model
|
|
@@ -334,13 +346,19 @@ attributes: {
|
|
|
334
346
|
- `subject` is derived when left out: `id` on `User`, the `belongsTo: ['User']`
|
|
335
347
|
foreign key elsewhere. A `via` parent must itself declare a subject.
|
|
336
348
|
- Anonymization writes NULL to nullable columns and a typed placeholder to
|
|
337
|
-
`NOT NULL` ones (`erased-<id>` when unique). A `NOT NULL`
|
|
338
|
-
|
|
349
|
+
`NOT NULL` ones (`erased-<id>` when unique). A column is `NOT NULL` when its
|
|
350
|
+
validation rule is `.required()`, which is what the migrations read, or
|
|
351
|
+
when it sets `required: true`; `nullable: true` overrides both. A `NOT NULL`
|
|
352
|
+
enum or timestamp needs `personal: { anonymize: <value> }`, or every
|
|
353
|
+
request refuses to run.
|
|
339
354
|
- A model that `belongsTo: ['User']` and declares nothing is **unclassified**:
|
|
340
355
|
erasure does not reach it and `buddy gdpr:register` lists it. Classify it, even
|
|
341
356
|
as `erasure: 'keep'`. `core/orm/tests/gdpr.test.ts` fails if a built-in one is.
|
|
342
357
|
- Engine: `exportSubjectData`, `eraseSubject({ dryRun })`, `pruneRetainedData`,
|
|
343
|
-
`resolveGdprPlan`, `renderProcessingRegister`,
|
|
358
|
+
`resolveGdprPlan`, `renderProcessingRegister`, and `anonymizedRows(model,
|
|
359
|
+
rows)` (which rows already hold what erasure writes, for labelling an erased
|
|
360
|
+
account in a list), all from `@stacksjs/orm`. The dashboard's delete runs
|
|
361
|
+
`eraseSubject` for a user the database will not delete: see `stacks-dashboard`.
|
|
344
362
|
Commands: `buddy gdpr:export|erase|prune|register|register:check`. Every
|
|
345
363
|
request writes a `gdpr_requests` row (the `GdprRequest` model).
|
|
346
364
|
|