@stacksjs/defaults 0.75.562 → 0.75.569
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/skills/stacks-buddy/SKILL.md +2 -0
- package/ai/skills/stacks-hq/SKILL.md +47 -1
- package/ai/skills/stacks-native/CATALOG.md +5 -5
- package/ai/skills/stacks-orm/SKILL.md +85 -10
- package/ai/skills/stacks-repl/SKILL.md +9 -5
- package/ai/skills/stacks-security/SKILL.md +7 -1
- package/app/Actions/Dashboard/Infrastructure/log-provider.ts +99 -2
- package/app/Actions/Dashboard/dashboard-provider.ts +88 -10
- package/app/Actions/Monitoring/error-provider.ts +124 -11
- package/app/Models/User.ts +6 -4
- package/ide/vscode/package.json +1 -1
- package/package.json +3 -3
|
@@ -671,6 +671,8 @@ buddy telemetry # telemetry management
|
|
|
671
671
|
buddy list # list all available commands
|
|
672
672
|
buddy version # display version (flags: --version, -v)
|
|
673
673
|
buddy saas # SaaS management
|
|
674
|
+
buddy hq:connect [services] # connect to HQ services, write keys to .env (--no-open, --no-verify)
|
|
675
|
+
buddy hq:status # usage against each connected HQ service's allowance
|
|
674
676
|
buddy sms # SMS commands
|
|
675
677
|
buddy phone # phone commands
|
|
676
678
|
buddy http # HTTP commands
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
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).
|
|
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, connecting an app with buddy hq:connect, or reading an HQ service from an app. Covers @stacksjs/hq (meter, service, client, testing), the HQ entries in config/services.ts and buddy hq:status.
|
|
4
4
|
license: MIT
|
|
5
5
|
compatibility: Bun >= 1.3.0, TypeScript
|
|
6
6
|
allowed-tools: Read Edit Write Bash Grep Glob
|
|
@@ -100,6 +100,14 @@ The adapter (`HqServiceAdapter`) is what the service implements: `approveUrl`,
|
|
|
100
100
|
page calls `describeConnect(code)` to show the app name and
|
|
101
101
|
`approveConnect(code, user)` once a signed-in user confirms.
|
|
102
102
|
|
|
103
|
+
An approve link can be minted by anyone for any app name, so approving on the
|
|
104
|
+
link alone would let a signed-in person be talked into handing over their keys.
|
|
105
|
+
`confirmationCode(code)` is a six-character code derived from the connect code.
|
|
106
|
+
Send it as `confirmCode` beside `code` and `approveUrl` (`buddy hq:connect`
|
|
107
|
+
prints it), ask for it on the approve page without rendering it, and call
|
|
108
|
+
`approveConnect` only once `confirmationMatches(code, typed)` holds. Limit the
|
|
109
|
+
attempts per person.
|
|
110
|
+
|
|
103
111
|
Codes are single-use and expire after ten minutes. A store holds only the
|
|
104
112
|
SHA-256 of a code, and the approved keys wait encrypted under a key derived from
|
|
105
113
|
the code, so the table never contains a pollable code or a readable key. Use
|
|
@@ -136,6 +144,44 @@ if (usage.ok)
|
|
|
136
144
|
- `AnalyticsReader`, `UptimeReader` and `CommsReader` are interfaces only; the
|
|
137
145
|
package README lists the endpoint each service must expose first.
|
|
138
146
|
|
|
147
|
+
## Connecting an app
|
|
148
|
+
|
|
149
|
+
An app connects with `buddy hq:connect [service...]` (BugHQ and LogHQ when none
|
|
150
|
+
is named). For each service the command starts a connect, prints the approve
|
|
151
|
+
link and any confirmation code, opens the browser, waits for the approval, and
|
|
152
|
+
writes that service's keys to `.env`: `BUGHQ_KEY`, `BUGHQ_READ_KEY`,
|
|
153
|
+
`BUGHQ_PROJECT_ID`, `LOGHQ_KEY`, `LOGHQ_READ_KEY`, `LOGHQ_PROJECT_ID`. A key is
|
|
154
|
+
never printed. It then sends one test error and one test log and reads each
|
|
155
|
+
back with the read key. `--no-open` and `--no-verify` skip those steps, and a
|
|
156
|
+
service that answers 404 on the connect route is reported as not available yet
|
|
157
|
+
without failing the others.
|
|
158
|
+
|
|
159
|
+
`config/services.ts` lists each service's URL, keys and project, as
|
|
160
|
+
`services.bughq`, `services.loghq` and so on. `config/logging.ts` and
|
|
161
|
+
`config/monitoring.ts` take their LogHQ and BugHQ settings from it.
|
|
162
|
+
`buddy hq:status` prints used, limit, period and state
|
|
163
|
+
for every connected service, with the upgrade link from 80% of an allowance.
|
|
164
|
+
|
|
165
|
+
ReportsHQ is the odd one out: it runs inside the app against the app's own
|
|
166
|
+
database, so it has no ingest or read key and meters nothing. Its entry is
|
|
167
|
+
`services.reportshq` with a `license` from `REPORTSHQ_LICENSE`, which
|
|
168
|
+
`buddy hq:status` checks offline (shape only) and never prints.
|
|
169
|
+
`buddy hq:connect reportshq` runs the same approval and writes the licence to
|
|
170
|
+
`REPORTSHQ_LICENSE`, with nothing to send or read back.
|
|
171
|
+
|
|
172
|
+
A licence-only service answers a `LicenseGrant` (`{ project, licenseKey,
|
|
173
|
+
dashboardUrl }`) from `provision` and leaves `authenticateReadKey` and `usage`
|
|
174
|
+
off its adapter. `createHqService` then mounts the two connect routes and no
|
|
175
|
+
usage route. `isLicenseGrant` tells the two kinds of approved answer apart.
|
|
176
|
+
|
|
177
|
+
The dashboard's Logs and Errors sections read LogHQ and BugHQ when
|
|
178
|
+
`config/dashboard.ts` sets `providers.logs` or `providers.errors` to
|
|
179
|
+
`{ driver: 'hq' }`.
|
|
180
|
+
|
|
181
|
+
In tests, `createFakeHqService()` and `fakeHqFetch()` from
|
|
182
|
+
`@stacksjs/testing/hq` stand in for a service: the contract routes, ingest and
|
|
183
|
+
the two project readers, with no port.
|
|
184
|
+
|
|
139
185
|
## Limits
|
|
140
186
|
|
|
141
187
|
- The counter is approximate by one flush interval per instance. Use a
|
|
@@ -21,7 +21,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
21
21
|
| `@stacksjs/auth` | [`stacks-auth`](../stacks-auth/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/index.ts) | 132 |
|
|
22
22
|
| `@stacksjs/browser` | [`stacks-browser`](../stacks-browser/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser/src/index.ts) | 10 |
|
|
23
23
|
| `@stacksjs/browser-extension` | [`stacks-browser-extension`](../stacks-browser-extension/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser-extension/src/index.ts) | 9 |
|
|
24
|
-
| `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) |
|
|
24
|
+
| `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) | 194 |
|
|
25
25
|
| `@stacksjs/build` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/build/src/index.ts) | 7 |
|
|
26
26
|
| `@stacksjs/cache` | [`stacks-cache`](../stacks-cache/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cache/src/index.ts) | 24 |
|
|
27
27
|
| `@stacksjs/calendar-api` | [`stacks-calendar`](../stacks-calendar/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/calendar-api/src/index.ts) | 5 |
|
|
@@ -55,7 +55,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
55
55
|
| `@stacksjs/git` | [`stacks-git`](../stacks-git/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/git/src/index.ts) | 2 |
|
|
56
56
|
| `@stacksjs/github` | [`stacks-git`](../stacks-git/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/github/src/index.ts) | 8 |
|
|
57
57
|
| `@stacksjs/health` | [`stacks-health`](../stacks-health/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/health/src/index.ts) | 2 |
|
|
58
|
-
| `@stacksjs/hq` | [`stacks-hq`](../stacks-hq/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/index.ts) |
|
|
58
|
+
| `@stacksjs/hq` | [`stacks-hq`](../stacks-hq/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/index.ts) | 8 |
|
|
59
59
|
| `@stacksjs/http` | [`stacks-http`](../stacks-http/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/http/src/index.ts) | 3 |
|
|
60
60
|
| `@stacksjs/i18n` | [`stacks-i18n`](../stacks-i18n/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/i18n/src/index.ts) | 5 |
|
|
61
61
|
| `@stacksjs/image` | [`stacks-image`](../stacks-image/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/image/src/index.ts) | 4 |
|
|
@@ -220,7 +220,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
|
|
|
220
220
|
|
|
221
221
|
Local source modules: [src/commands/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/commands/index.ts).
|
|
222
222
|
|
|
223
|
-
Evidence directory: [
|
|
223
|
+
Evidence directory: [194 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
224
224
|
|
|
225
225
|
### @stacksjs/build
|
|
226
226
|
|
|
@@ -466,7 +466,7 @@ Evidence directory: [10 retained tests](https://github.com/stacksjs/stacks/blob/
|
|
|
466
466
|
|
|
467
467
|
Guidance: [`stacks-events`](../stacks-events/SKILL.md). Source: [storage/framework/core/events/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/events/src/index.ts).
|
|
468
468
|
|
|
469
|
-
Declared runtime exports: `all`, `appListenersBooted`, `bootAppListeners`, `createEmitter`, `default`, `defineEvents`, `defineListener`, `discoverListeners`, `dispatch`, `dispatchAndCollect`, `dispatchAsync`, `emitter`, `events`, `listen`, `mitt`, `off`, `once`, `registerAppListeners`, `resetListenerRegistry`, `resetNameRegistries`, `scope`, `scopedEvents`, `useEvent`, `useEvents`, `useListen`.
|
|
469
|
+
Declared runtime exports: `all`, `appListenersBooted`, `bootAppListeners`, `createEmitter`, `default`, `defineEvents`, `defineListener`, `discoverListeners`, `dispatch`, `dispatchAndCollect`, `dispatchAndCollectInPlace`, `dispatchAsync`, `emitter`, `events`, `listen`, `mitt`, `off`, `once`, `registerAppListeners`, `resetListenerRegistry`, `resetNameRegistries`, `scope`, `scopedEvents`, `useEvent`, `useEvents`, `useListen`.
|
|
470
470
|
|
|
471
471
|
Local source modules: [src/discover.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/events/src/discover.ts).
|
|
472
472
|
|
|
@@ -548,7 +548,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
|
|
|
548
548
|
|
|
549
549
|
Local source modules: [src/client.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/client.ts), [src/meter.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/meter.ts), [src/service.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/src/service.ts).
|
|
550
550
|
|
|
551
|
-
Evidence directory: [
|
|
551
|
+
Evidence directory: [8 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/hq/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
552
552
|
|
|
553
553
|
### @stacksjs/http
|
|
554
554
|
|
|
@@ -34,9 +34,9 @@ const open = WorkItem.where('done', false).orderBy('id', 'desc').get()
|
|
|
34
34
|
load lazily; server boot waits for model initialization. A feature-disabled
|
|
35
35
|
model is not made usable merely by an ambient declaration.
|
|
36
36
|
|
|
37
|
-
##
|
|
37
|
+
## Model calls answer in place
|
|
38
38
|
|
|
39
|
-
A model
|
|
39
|
+
A model call returns its value where it is written, on SQLite, MySQL and
|
|
40
40
|
Postgres:
|
|
41
41
|
|
|
42
42
|
```ts
|
|
@@ -48,7 +48,7 @@ if (User.where('email', email).exists()) return response.badRequest('Taken')
|
|
|
48
48
|
for (const post of Post.where('published', true).get()) titles.push(post.title)
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
- **
|
|
51
|
+
- **Every read, on every model.** `find`, `findOrFail`, `findMany`, `first`,
|
|
52
52
|
`firstOrFail`, `last`, `all`, `get`, `count`, `exists`, `pluck`, `sum`,
|
|
53
53
|
`avg`, `min`, `max`, `paginate`, `simplePaginate`, `cursorPaginate`, eager
|
|
54
54
|
loading through `with()`, and reads of encrypted attributes.
|
|
@@ -59,18 +59,93 @@ for (const post of Post.where('published', true).get()) titles.push(post.title)
|
|
|
59
59
|
row throws; wrap it in `try`/`catch`. `.catch()` and `.then()` do not exist
|
|
60
60
|
on a row. In a test, `expect(() => User.findOrFail(0)).toThrow()`, not
|
|
61
61
|
`await expect(...).rejects`.
|
|
62
|
-
- **A write is a promise, on every model.** `create`, `createMany`,
|
|
63
|
-
`firstOrCreate`, `updateOrCreate`, `update`, `save`, `delete`, `forceDelete`
|
|
64
|
-
and a query's `delete()` run setters, validation, encryption and lifecycle
|
|
65
|
-
events, any of which may wait. Keep their `await`.
|
|
66
62
|
- **How.** SQLite runs a query in place. MySQL and Postgres run on Bun's
|
|
67
63
|
driver, held by a worker thread the caller waits on, so nothing else runs on
|
|
68
64
|
the calling thread while a query is in flight (the cost `bun:sqlite` always
|
|
69
|
-
had). `models: { execution: 'async' }` in
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
had). `models: { execution: 'async' }` in `config/qb.ts` makes MySQL and
|
|
66
|
+
Postgres calls promises again for an app that needs the event loop free
|
|
67
|
+
during queries; every call then has to be awaited.
|
|
72
68
|
- **Not covered.** The `db` query builder (`db.selectFrom(...)`) and
|
|
73
69
|
`transaction()` still return promises.
|
|
70
|
+
- **Inside `db.transaction()`, write through `tx`, not through a model.** A
|
|
71
|
+
model call runs on its own connection, and on MySQL and Postgres the thread
|
|
72
|
+
waits for it. One that needs a row the open transaction has locked can never
|
|
73
|
+
finish, because the transaction cannot commit while its thread is waiting.
|
|
74
|
+
It throws `StatementTimeoutError` after `models.timeoutMs` (30 seconds by
|
|
75
|
+
default, `0` for no limit) instead of stopping the process. Postgres cancels
|
|
76
|
+
the abandoned statement; MySQL cannot, so there it may still be applied once
|
|
77
|
+
the lock is gone.
|
|
78
|
+
|
|
79
|
+
### Writes: in place, with the work around them
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
// Lifecycle events, a search index, a broadcast: the write is still the row.
|
|
83
|
+
const order = Order.create({ total: 1200 })
|
|
84
|
+
order.update({ total: 1500 })
|
|
85
|
+
Order.delete(order.id)
|
|
86
|
+
|
|
87
|
+
// Declares `useSoftDeletes`: every write is a promise.
|
|
88
|
+
const note = await Note.create({ title: 'Draft' })
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
What a model declares around its writes happens like this:
|
|
92
|
+
|
|
93
|
+
| Declaration | When it runs |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `traits.observe` | listeners are called in place, in order; the row comes back after them |
|
|
96
|
+
| `traits.useSearch` | the index update starts with the write and finishes after it |
|
|
97
|
+
| `traits.broadcastOn` | the broadcast starts with the write and finishes after it |
|
|
98
|
+
| `set: { ... }`, `hooks: { ... }` written without `async` | in place, as part of the write |
|
|
99
|
+
|
|
100
|
+
A before-listener (`saving`, `creating`, `updating`, `deleting`) cancels the
|
|
101
|
+
write by returning `false` or throwing, and the write throws where it stands.
|
|
102
|
+
An after-listener that is `async` runs on after the row is back. A
|
|
103
|
+
before-listener that is `async` still has to be waited for, since it may
|
|
104
|
+
cancel: that one write becomes a promise, and the ORM warns once per event.
|
|
105
|
+
Keep before-listeners synchronous.
|
|
106
|
+
|
|
107
|
+
A model's writes wait, and are typed as promises, only when its definition
|
|
108
|
+
declares something a write cannot do in place:
|
|
109
|
+
|
|
110
|
+
| Declaration | What the write waits for |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `traits.useSoftDeletes` / `softDeletable` | the soft-delete transaction |
|
|
113
|
+
| `traits.useAudit`, `traits.useActivityLog` | the audit or activity row |
|
|
114
|
+
| a `set:` member written `async` | the setter |
|
|
115
|
+
| a `hooks:` member written `async` | the hook |
|
|
116
|
+
|
|
117
|
+
It is decided from the declaration, not from what happens to run: on such a
|
|
118
|
+
model `create`, `createMany`, `firstOrCreate`, `updateOrCreate`, `update`,
|
|
119
|
+
`save`, `delete`, `forceDelete` and a query's `delete()` are promises every
|
|
120
|
+
time, and a failure is a rejection. On any other model they return the value,
|
|
121
|
+
and a failure (a guarded column, a validation rule, a listener that refuses)
|
|
122
|
+
throws where the call stands. `modelWritesWait(definition)` answers it at
|
|
123
|
+
runtime and `ModelWritesWait<typeof Model>` in the types. Reads never wait on
|
|
124
|
+
either kind.
|
|
125
|
+
|
|
126
|
+
Write setters so they answer in place. A password setter uses `makeHashSync`
|
|
127
|
+
from `@stacksjs/security`, as the default `User` does: it holds the thread for
|
|
128
|
+
the length of the hash (about a quarter of a second for bcrypt at 12 rounds),
|
|
129
|
+
and `User.create(...)` is the row. Where that pause is the worse trade, make
|
|
130
|
+
the setter `async` with `makeHash` and `await` that model's writes. An
|
|
131
|
+
instance write on a model with an async setter goes through `saveAsync()` /
|
|
132
|
+
`updateAsync()`.
|
|
133
|
+
|
|
134
|
+
Work that finishes after the write (the index update, the broadcast, an
|
|
135
|
+
`async` after-listener) is logged if it fails and never fails the write. A
|
|
136
|
+
server needs nothing more. A script that ends with `process.exit()` waits
|
|
137
|
+
first:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { modelWorkSettled } from '@stacksjs/orm'
|
|
141
|
+
|
|
142
|
+
Product.create({ name: 'Widget' })
|
|
143
|
+
await modelWorkSettled() // index updates and broadcasts are done; rejects if one failed
|
|
144
|
+
process.exit(0)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Application seeders and tinker snippets already do this. When in doubt,
|
|
148
|
+
`await` the write: it is correct on every model.
|
|
74
149
|
|
|
75
150
|
## Write behavior
|
|
76
151
|
|
|
@@ -80,6 +80,9 @@ evaluates it at global scope:
|
|
|
80
80
|
- a query needs no `await` at the top level (see "No await at the top level");
|
|
81
81
|
top-level `await` still works;
|
|
82
82
|
- a relative `import('./x')` resolves against the session's directory;
|
|
83
|
+
- a snippet is done when the work its model writes left running is done: the
|
|
84
|
+
search-index update and the broadcast, for up to five seconds. What they
|
|
85
|
+
print lands in that snippet's frames, and `durationMs` does not count them;
|
|
83
86
|
- nothing is written to the project.
|
|
84
87
|
|
|
85
88
|
It resolves with `{ ok, value, thrown, frames, durationMs }` and never rejects
|
|
@@ -107,11 +110,12 @@ if (User.where('active', true).exists()) dump(User.count())
|
|
|
107
110
|
for (const post of Post.latest().limit(5).get()) dump(post.title)
|
|
108
111
|
```
|
|
109
112
|
|
|
110
|
-
A model read is a value everywhere, in app code as well as here
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
a
|
|
113
|
+
A model read is a value everywhere, in app code as well as here, and so is a
|
|
114
|
+
write on a model that declares nothing to wait for (see `stacks-orm`). What a
|
|
115
|
+
session adds is the rest: outside a function, a call that returns a promise is
|
|
116
|
+
waited for where it stands, and so is a promise a statement names (the value
|
|
117
|
+
of a line, of a declaration, of an assignment). So a write on a model with
|
|
118
|
+
events or a search index, a `fetch` or a job dispatch reads the same way a
|
|
115
119
|
query does. A rejection is thrown there.
|
|
116
120
|
|
|
117
121
|
- **Inside a function nothing changes.** `await` there is yours to write:
|
|
@@ -71,13 +71,18 @@ const decrypted = await decrypt(encrypted, 'custom-passphrase')
|
|
|
71
71
|
## Password Hashing
|
|
72
72
|
|
|
73
73
|
```typescript
|
|
74
|
-
import { make, check, needsRehash, info, detectAlgorithm } from '@stacksjs/security'
|
|
74
|
+
import { make, makeSync, check, needsRehash, info, detectAlgorithm } from '@stacksjs/security'
|
|
75
75
|
|
|
76
76
|
// Hash a password
|
|
77
77
|
const hash = await make('password123') // bcrypt (default)
|
|
78
78
|
const hash = await make('password123', { algorithm: 'argon2' })
|
|
79
79
|
const hash = await make('password123', { rounds: 14 }) // bcrypt rounds
|
|
80
80
|
|
|
81
|
+
// The same hash, answered in place. For a model `set:` hook, so the write it
|
|
82
|
+
// belongs to stays in place. It holds the thread for the length of the hash
|
|
83
|
+
// (about a quarter of a second for bcrypt at 12 rounds).
|
|
84
|
+
const hashedNow = makeSync('password123')
|
|
85
|
+
|
|
81
86
|
// Verify
|
|
82
87
|
const valid = await check('password123', hash) // true/false
|
|
83
88
|
|
|
@@ -95,6 +100,7 @@ const algo = detectAlgorithm(hash) // 'bcrypt' | 'argon2' | 'argon2id' | ...
|
|
|
95
100
|
- `hashNeedsRehash` = `needsRehash`
|
|
96
101
|
- `hashInfo` = `info`
|
|
97
102
|
- `makeHash` = `make`
|
|
103
|
+
- `hashMakeSync` = `makeHashSync` = `makeSync`
|
|
98
104
|
- `verifyHash` = `check`
|
|
99
105
|
|
|
100
106
|
### Algorithm-Specific Functions
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { HqClient } from '@stacksjs/hq/client'
|
|
1
2
|
import type { DashboardProviderUnavailable } from '../dashboard-provider'
|
|
2
3
|
import type { DashboardLogRecord, DashboardLogSummary } from './log-dashboard'
|
|
3
4
|
import { db } from '@stacksjs/database/runtime'
|
|
4
|
-
import {
|
|
5
|
+
import { dashboardHqClient, hqUnavailableReason, readThroughProvider, resolveDashboardDriver } from '../dashboard-provider'
|
|
5
6
|
import { DASHBOARD_LOG_TYPES, normalizeDashboardLog, summarizeDashboardLogTypes } from './log-dashboard'
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -173,6 +174,102 @@ export const localLogsProvider: DashboardLogsProvider = {
|
|
|
173
174
|
},
|
|
174
175
|
}
|
|
175
176
|
|
|
177
|
+
/**
|
|
178
|
+
* LogHQ's levels, as the four types this section filters and counts by.
|
|
179
|
+
*
|
|
180
|
+
* LogHQ has no `success`: the framework's logger sends one as `info`, so that
|
|
181
|
+
* filter matches nothing here rather than guessing.
|
|
182
|
+
*/
|
|
183
|
+
const HQ_LEVELS_BY_TYPE: Record<string, string[]> = {
|
|
184
|
+
error: ['error', 'critical', 'alert', 'emergency'],
|
|
185
|
+
warning: ['warning'],
|
|
186
|
+
info: ['info', 'notice', 'debug'],
|
|
187
|
+
success: [],
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function typeOfHqLevel(level: string): string {
|
|
191
|
+
const normalized = level.toLowerCase()
|
|
192
|
+
return Object.keys(HQ_LEVELS_BY_TYPE).find(type => HQ_LEVELS_BY_TYPE[type]!.includes(normalized)) ?? normalized
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** How many of LogHQ's pages a numbered page may walk to. It pages by cursor, not by number. */
|
|
196
|
+
const HQ_MAX_PAGE_WALK = 10
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* LogHQ, read with the project's read key.
|
|
200
|
+
*
|
|
201
|
+
* Two things differ from the local table and are answered honestly rather
|
|
202
|
+
* than faked. LogHQ pages by cursor and reports no total, so `total` is what
|
|
203
|
+
* has been seen so far plus one when there is more, which is enough for the
|
|
204
|
+
* pager to offer the next page. And the summary counts the page shown, not
|
|
205
|
+
* the whole stream.
|
|
206
|
+
*/
|
|
207
|
+
export function hqLogsProvider(client: Pick<HqClient, 'logs'>, now: () => number = Date.now): DashboardLogsProvider {
|
|
208
|
+
return {
|
|
209
|
+
async logs(query: DashboardLogQuery): Promise<DashboardLogPayload> {
|
|
210
|
+
const levels = query.type ? HQ_LEVELS_BY_TYPE[query.type] ?? [query.type] : undefined
|
|
211
|
+
if (levels && !levels.length)
|
|
212
|
+
return { ...emptyLogPayload('', query), unavailable: undefined }
|
|
213
|
+
|
|
214
|
+
const cutoff = query.range === 'all' ? 0 : now() - Number(query.range) * 86400000
|
|
215
|
+
let page = 1
|
|
216
|
+
let cursor: string | undefined
|
|
217
|
+
let entries: Awaited<ReturnType<HqClient['logs']['list']>> & { ok: true } | undefined
|
|
218
|
+
|
|
219
|
+
for (; page <= Math.min(query.page, HQ_MAX_PAGE_WALK); page++) {
|
|
220
|
+
const result = await client.logs.list({
|
|
221
|
+
level: levels,
|
|
222
|
+
channel: query.source || undefined,
|
|
223
|
+
search: query.search || undefined,
|
|
224
|
+
before: cursor,
|
|
225
|
+
limit: query.perPage,
|
|
226
|
+
})
|
|
227
|
+
if (!result.ok)
|
|
228
|
+
return emptyLogPayload(hqUnavailableReason(result), query)
|
|
229
|
+
entries = result
|
|
230
|
+
if (!result.data.nextCursor || page === Math.min(query.page, HQ_MAX_PAGE_WALK))
|
|
231
|
+
break
|
|
232
|
+
cursor = result.data.nextCursor
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const all = entries?.data.logs ?? []
|
|
236
|
+
// Newest first, so everything after the first entry older than the range is older too.
|
|
237
|
+
const inRange = cutoff ? all.filter(log => !(Date.parse(log.timestamp) < cutoff)) : all
|
|
238
|
+
const hasMore = Boolean(entries?.data.nextCursor) && inRange.length === all.length
|
|
239
|
+
const offset = (page - 1) * query.perPage
|
|
240
|
+
|
|
241
|
+
const logs = inRange.map((log, index) => normalizeDashboardLog({
|
|
242
|
+
// LogHQ's ids are strings and this section keys rows by number.
|
|
243
|
+
id: offset + index + 1,
|
|
244
|
+
timestamp: log.timestamp,
|
|
245
|
+
type: typeOfHqLevel(log.level),
|
|
246
|
+
source: log.channel ?? '',
|
|
247
|
+
message: log.message,
|
|
248
|
+
// LogHQ's project is the one the read key opens; an entry carries no other.
|
|
249
|
+
project: '',
|
|
250
|
+
created_at: log.createdAt ?? log.timestamp,
|
|
251
|
+
}))
|
|
252
|
+
const total = offset + logs.length + (hasMore ? 1 : 0)
|
|
253
|
+
const typeCounts = new Map<string, number>()
|
|
254
|
+
for (const log of logs)
|
|
255
|
+
typeCounts.set(log.type, (typeCounts.get(log.type) ?? 0) + 1)
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
logs,
|
|
259
|
+
summary: summarizeDashboardLogTypes([...typeCounts].map(([type, count]) => ({ type, count })), total),
|
|
260
|
+
pagination: { page, perPage: query.perPage, total, totalPages: page + (hasMore ? 1 : 0) },
|
|
261
|
+
options: {
|
|
262
|
+
sources: [...new Set(logs.map(log => log.source).filter(Boolean))].sort(),
|
|
263
|
+
projects: [],
|
|
264
|
+
types: [...DASHBOARD_LOG_TYPES],
|
|
265
|
+
ranges: [...DASHBOARD_LOG_RANGES],
|
|
266
|
+
},
|
|
267
|
+
generatedAt: new Date(now()).toISOString(),
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
176
273
|
/** Reads the Logs section through whichever provider config selects. */
|
|
177
274
|
export async function readDashboardLogs(query: DashboardLogQuery): Promise<DashboardLogPayload> {
|
|
178
275
|
const driver = await resolveDashboardDriver('logs')
|
|
@@ -183,7 +280,7 @@ export async function readDashboardLogs(query: DashboardLogQuery): Promise<Dashb
|
|
|
183
280
|
return readThroughProvider(
|
|
184
281
|
'logs',
|
|
185
282
|
reason => emptyLogPayload(reason, query),
|
|
186
|
-
async () =>
|
|
283
|
+
async () => hqLogsProvider(await dashboardHqClient('logs', driver.options)).logs(query),
|
|
187
284
|
isLogPayload,
|
|
188
285
|
)
|
|
189
286
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HqClient, HqUnavailable } from '@stacksjs/hq/client'
|
|
2
|
+
import type { DashboardHqDriverOptions, DashboardProviderName, DashboardProviderSelection, HqServiceName, HqServiceOptions } from '@stacksjs/types'
|
|
3
|
+
import { createHqClient } from '@stacksjs/hq/client'
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* The seam between a dashboard section and the data behind it.
|
|
@@ -155,16 +157,92 @@ export async function readThroughProvider<T>(
|
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
/**
|
|
158
|
-
* The reason
|
|
160
|
+
* The reason the Analytics section has no data from `hq` yet.
|
|
159
161
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* but they authenticate a person rather than a machine, so wiring one needs a
|
|
164
|
-
* product decision about service credentials before any code here can help.
|
|
165
|
-
*
|
|
166
|
-
* Selecting `hq` today therefore yields an empty section that says so, which
|
|
167
|
-
* is the honest answer and keeps the degrade path real rather than theoretical.
|
|
162
|
+
* Logs and Errors read from LogHQ and BugHQ with a project read key (see
|
|
163
|
+
* `dashboardHqClient` below). AnalyticsHQ has no read-key endpoint, so
|
|
164
|
+
* selecting `hq` for analytics still yields an empty section that says so.
|
|
168
165
|
*/
|
|
169
166
|
export const HQ_READ_UNAVAILABLE
|
|
170
167
|
= 'No data. The hosted provider has no read API yet, so this section cannot be filled from it.'
|
|
168
|
+
|
|
169
|
+
/** The hosted service behind each domain that can be read today. */
|
|
170
|
+
const HQ_DOMAIN_SERVICE = { logs: 'loghq', errors: 'bughq' } as const satisfies Partial<Record<DashboardProviderDomain, HqServiceName>>
|
|
171
|
+
|
|
172
|
+
const HQ_LABELS: Record<HqServiceName, string> = {
|
|
173
|
+
bughq: 'BugHQ',
|
|
174
|
+
loghq: 'LogHQ',
|
|
175
|
+
analyticshq: 'AnalyticsHQ',
|
|
176
|
+
statushq: 'StatusHQ',
|
|
177
|
+
commshq: 'CommsHQ',
|
|
178
|
+
reportshq: 'ReportsHQ',
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type DashboardHqDomain = keyof typeof HQ_DOMAIN_SERVICE
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* A hosted read that came back with nothing, and the sentence to show for it.
|
|
185
|
+
*
|
|
186
|
+
* Thrown by an `hq` provider so its methods keep the same signatures as the
|
|
187
|
+
* local one's; the section's reader turns it into an empty payload carrying
|
|
188
|
+
* `reason`.
|
|
189
|
+
*/
|
|
190
|
+
export class DashboardProviderUnavailableError extends Error {
|
|
191
|
+
constructor(public readonly reason: string) {
|
|
192
|
+
super(reason)
|
|
193
|
+
this.name = 'DashboardProviderUnavailableError'
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Why a hosted read has no data, for whoever is looking at the dashboard. */
|
|
198
|
+
export function hqUnavailableReason(result: HqUnavailable): string {
|
|
199
|
+
const label = HQ_LABELS[result.service]
|
|
200
|
+
const connect = `Run \`buddy hq:connect ${result.service}\``
|
|
201
|
+
switch (result.reason) {
|
|
202
|
+
case 'not_configured':
|
|
203
|
+
return `${label} is not connected. ${connect} to connect it.`
|
|
204
|
+
case 'unauthorized':
|
|
205
|
+
return `${label} refused the read key. ${connect} to get a new one.`
|
|
206
|
+
case 'timeout':
|
|
207
|
+
case 'network':
|
|
208
|
+
return `${label} could not be reached. This section will fill in once it answers again.`
|
|
209
|
+
case 'http':
|
|
210
|
+
// The services answer 404, not 401, for a key that does not open the project.
|
|
211
|
+
return result.status === 404
|
|
212
|
+
? `${label} has no project that this read key opens. ${connect} to connect it again.`
|
|
213
|
+
: `${label} could not be read (it answered ${result.status}).`
|
|
214
|
+
default:
|
|
215
|
+
return `${label} answered something this section cannot show.`
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The client a domain's `hq` provider reads with.
|
|
221
|
+
*
|
|
222
|
+
* Credentials come from `config/services.ts`, where `buddy hq:connect` put them.
|
|
223
|
+
* The domain's own `drivers.hq` settings win where set, so one section can
|
|
224
|
+
* point at another project or a self-hosted instance.
|
|
225
|
+
*/
|
|
226
|
+
export async function dashboardHqClient(domain: DashboardHqDomain, options: DashboardHqDriverOptions = {}): Promise<HqClient> {
|
|
227
|
+
const service = HQ_DOMAIN_SERVICE[domain]
|
|
228
|
+
let configured: HqServiceOptions | undefined
|
|
229
|
+
try {
|
|
230
|
+
const { config, overridesReady } = await import('@stacksjs/config')
|
|
231
|
+
await overridesReady.catch(() => {})
|
|
232
|
+
configured = config.services?.[service]
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
console.warn(`[dashboard/api] config.services could not be read for ${domain}:`, error)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return createHqClient({
|
|
239
|
+
services: {
|
|
240
|
+
[service]: {
|
|
241
|
+
url: options.baseUrl || configured?.url || '',
|
|
242
|
+
readKey: options.token || configured?.readKey || '',
|
|
243
|
+
project: options.project || configured?.project,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
timeoutMs: options.timeoutMs ?? 5000,
|
|
247
|
+
})
|
|
248
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { HqClient, Issue } from '@stacksjs/hq/client'
|
|
1
2
|
import type { DashboardProviderUnavailable } from '../Dashboard/dashboard-provider'
|
|
2
3
|
import { errors } from '@stacksjs/commerce'
|
|
3
4
|
import type { QueryReader } from '../Dashboard/Content/content-list'
|
|
4
5
|
import { LIST_PAGE_SIZES, queryText } from '../Dashboard/Content/content-list'
|
|
5
|
-
import {
|
|
6
|
+
import { dashboardHqClient, DashboardProviderUnavailableError, hqUnavailableReason, readThroughProvider, resolveDashboardDriver } from '../Dashboard/dashboard-provider'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Where the Errors section reads from.
|
|
@@ -230,9 +231,114 @@ const EMPTY_STATS: DashboardErrorStats = {
|
|
|
230
231
|
trend: 0,
|
|
231
232
|
}
|
|
232
233
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
/**
|
|
235
|
+
* BugHQ, read with the project's read key.
|
|
236
|
+
*
|
|
237
|
+
* BugHQ already groups occurrences into issues, so an issue is a group here.
|
|
238
|
+
* Its read API is the issue list (the hundred most recently seen), which is
|
|
239
|
+
* what every answer below is built from:
|
|
240
|
+
*
|
|
241
|
+
* - a group's `message` is the issue title and it has no stack, because the
|
|
242
|
+
* list carries none
|
|
243
|
+
* - `stats` counts occurrences across those issues; `last_24h` is the number
|
|
244
|
+
* of issues seen in the last day, since the list has no per-hour counts
|
|
245
|
+
* - there is no timeline to read, so that panel says so
|
|
246
|
+
*
|
|
247
|
+
* A read that comes back unavailable throws
|
|
248
|
+
* `DashboardProviderUnavailableError`, which `readErrors` turns into the empty
|
|
249
|
+
* value plus its reason.
|
|
250
|
+
*/
|
|
251
|
+
export function hqErrorsProvider(client: Pick<HqClient, 'issues'>, now: () => number = Date.now): DashboardErrorsProvider {
|
|
252
|
+
const issues = async (status?: string): Promise<Issue[]> => {
|
|
253
|
+
const result = await client.issues.list(status ? { status } : {})
|
|
254
|
+
if (!result.ok)
|
|
255
|
+
throw new DashboardProviderUnavailableError(hqUnavailableReason(result))
|
|
256
|
+
return result.data
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const typeOf = (issue: Issue): string => issue.errorType || 'Error'
|
|
260
|
+
// BugHQ titles an issue `Type: message`.
|
|
261
|
+
const messageOf = (issue: Issue): string =>
|
|
262
|
+
issue.title.startsWith(`${typeOf(issue)}: `) ? issue.title.slice(typeOf(issue).length + 2) : issue.title
|
|
263
|
+
|
|
264
|
+
const toGroup = (issue: Issue): DashboardGroupedError => ({
|
|
265
|
+
id: issue.id,
|
|
266
|
+
type: typeOf(issue),
|
|
267
|
+
message: messageOf(issue),
|
|
268
|
+
stack: null,
|
|
269
|
+
status: toErrorStatus(issue.status),
|
|
270
|
+
count: issue.count,
|
|
271
|
+
first_seen: issue.firstSeen ?? '',
|
|
272
|
+
last_seen: issue.lastSeen ?? '',
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
const toRecord = (issue: Issue): DashboardErrorRecord => ({
|
|
276
|
+
id: issue.id,
|
|
277
|
+
type: typeOf(issue),
|
|
278
|
+
message: messageOf(issue),
|
|
279
|
+
stack: null,
|
|
280
|
+
status: null,
|
|
281
|
+
resolution: toErrorStatus(issue.status),
|
|
282
|
+
additional_info: issue.culprit,
|
|
283
|
+
created_at: issue.firstSeen ?? '',
|
|
284
|
+
updated_at: issue.lastSeen,
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
async grouped(query) {
|
|
289
|
+
const all = await issues(query.status === 'all' ? undefined : query.status)
|
|
290
|
+
const search = query.search.toLowerCase()
|
|
291
|
+
const matching = all
|
|
292
|
+
.filter(issue => !query.type || typeOf(issue) === query.type)
|
|
293
|
+
.filter(issue => !search || `${issue.title} ${issue.culprit ?? ''}`.toLowerCase().includes(search))
|
|
294
|
+
.map(toGroup)
|
|
295
|
+
|
|
296
|
+
const direction = query.direction === 'asc' ? 1 : -1
|
|
297
|
+
const key = (group: DashboardGroupedError): string | number =>
|
|
298
|
+
query.sort === 'count' ? group.count : query.sort === 'type' ? group.type : query.sort === 'status' ? group.status : group.last_seen
|
|
299
|
+
matching.sort((a, b) => {
|
|
300
|
+
const left = key(a)
|
|
301
|
+
const right = key(b)
|
|
302
|
+
return (left < right ? -1 : left > right ? 1 : 0) * direction
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
const page = Math.min(query.page, Math.max(1, Math.ceil(matching.length / query.perPage)))
|
|
306
|
+
return {
|
|
307
|
+
groups: matching.slice((page - 1) * query.perPage, page * query.perPage),
|
|
308
|
+
total: matching.length,
|
|
309
|
+
page,
|
|
310
|
+
types: [...new Set(all.map(typeOf))].sort(),
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
|
|
314
|
+
async stats() {
|
|
315
|
+
const all = await issues()
|
|
316
|
+
const since = now() - 86400000
|
|
317
|
+
const sum = (status: DashboardErrorStatus): number =>
|
|
318
|
+
all.filter(issue => toErrorStatus(issue.status) === status).reduce((total, issue) => total + issue.count, 0)
|
|
319
|
+
return {
|
|
320
|
+
total: all.reduce((total, issue) => total + issue.count, 0),
|
|
321
|
+
unresolved: sum('unresolved'),
|
|
322
|
+
resolved: sum('resolved'),
|
|
323
|
+
ignored: sum('ignored'),
|
|
324
|
+
last_24h: all.filter(issue => issue.lastSeen && Date.parse(issue.lastSeen) >= since).length,
|
|
325
|
+
trend: 0,
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
async timeline() {
|
|
330
|
+
throw new DashboardProviderUnavailableError('BugHQ has no hourly timeline to read yet. Open BugHQ for the full history.')
|
|
331
|
+
},
|
|
332
|
+
|
|
333
|
+
async byGroup(type, message) {
|
|
334
|
+
return (await issues()).filter(issue => typeOf(issue) === type && messageOf(issue) === message).map(toRecord)
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
async byId(id) {
|
|
338
|
+
const issue = (await issues()).find(candidate => candidate.id === String(id))
|
|
339
|
+
return issue ? toRecord(issue) : undefined
|
|
340
|
+
},
|
|
341
|
+
}
|
|
236
342
|
}
|
|
237
343
|
|
|
238
344
|
/**
|
|
@@ -247,19 +353,26 @@ async function readErrors<T>(
|
|
|
247
353
|
read: (provider: DashboardErrorsProvider) => Promise<T>,
|
|
248
354
|
isValid: (payload: unknown) => boolean,
|
|
249
355
|
): Promise<DashboardErrorsEnvelope<T>> {
|
|
250
|
-
const
|
|
356
|
+
const driver = await resolveDashboardDriver('errors')
|
|
251
357
|
|
|
252
|
-
if (
|
|
253
|
-
return { data: await read(
|
|
358
|
+
if (driver.name === 'local')
|
|
359
|
+
return { data: await read(localErrorsProvider) }
|
|
254
360
|
|
|
255
|
-
|
|
361
|
+
return readThroughProvider<DashboardErrorsEnvelope<T>>(
|
|
256
362
|
'errors',
|
|
257
363
|
reason => ({ data: empty, unavailable: reason }),
|
|
258
|
-
async () =>
|
|
364
|
+
async () => {
|
|
365
|
+
try {
|
|
366
|
+
return { data: await read(hqErrorsProvider(await dashboardHqClient('errors', driver.options))) }
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
if (error instanceof DashboardProviderUnavailableError)
|
|
370
|
+
return { data: empty, unavailable: error.reason }
|
|
371
|
+
throw error
|
|
372
|
+
}
|
|
373
|
+
},
|
|
259
374
|
candidate => isValid((candidate as DashboardErrorsEnvelope<T>)?.data),
|
|
260
375
|
)
|
|
261
|
-
|
|
262
|
-
return payload
|
|
263
376
|
}
|
|
264
377
|
|
|
265
378
|
const EMPTY_GROUP_PAGE: DashboardGroupedErrorPage = { groups: [], total: 0, page: 1, types: [] }
|
package/app/Models/User.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Attributes } from '@stacksjs/types'
|
|
2
2
|
import { defineModel, selfOwnership } from '@stacksjs/orm'
|
|
3
|
-
import {
|
|
3
|
+
import { makeHashSync } from '@stacksjs/security'
|
|
4
4
|
// soon, these will be auto-imported
|
|
5
5
|
import { schema } from '@stacksjs/validation/runtime'
|
|
6
6
|
import { PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH } from '../password-policy'
|
|
@@ -154,9 +154,11 @@ export default defineModel({
|
|
|
154
154
|
},
|
|
155
155
|
|
|
156
156
|
set: {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
// Hashed in place, so `User.create(...)` is the row and not a promise of
|
|
158
|
+
// one. That holds the thread for the length of the hash (about a quarter
|
|
159
|
+
// of a second at 12 rounds). An app that would rather wait for it without
|
|
160
|
+
// blocking makes this `async` with `makeHash`, and awaits its User writes.
|
|
161
|
+
password: (attributes: Attributes) => makeHashSync(attributes.password, { algorithm: 'bcrypt' }),
|
|
160
162
|
},
|
|
161
163
|
dashboard: {
|
|
162
164
|
highlight: true,
|
package/ide/vscode/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"publisher": "Stacks",
|
|
3
3
|
"name": "vscode-stacks",
|
|
4
4
|
"displayName": "Stacks",
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.569",
|
|
6
6
|
"description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/defaults",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.569",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@iconify-json/f7": "^1.2.2",
|
|
47
47
|
"@iconify-json/hugeicons": "^1.2.35",
|
|
48
|
-
"@stacksjs/mobile": "0.75.
|
|
48
|
+
"@stacksjs/mobile": "0.75.569",
|
|
49
49
|
"@stacksjs/sanitizer": "^0.2.864",
|
|
50
50
|
"@stacksjs/stx": "^0.2.864",
|
|
51
|
-
"@stacksjs/strings": "0.75.
|
|
51
|
+
"@stacksjs/strings": "0.75.569",
|
|
52
52
|
"@xterm/addon-fit": "^0.11.0",
|
|
53
53
|
"@xterm/xterm": "^6.0.0",
|
|
54
54
|
"ts-qr-codes": "^0.1.8"
|