@codyswann/lisa 2.169.0 → 2.171.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/package.json +1 -1
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/skills/harper-auth/SKILL.md +320 -0
- package/plugins/lisa-harper-fabric/skills/harper-auth/agents/openai.yaml +4 -0
- package/plugins/lisa-harper-fabric/skills/harper-caching/SKILL.md +265 -0
- package/plugins/lisa-harper-fabric/skills/harper-caching/agents/openai.yaml +4 -0
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/skills/harper-auth/SKILL.md +320 -0
- package/plugins/lisa-harper-fabric-agy/skills/harper-caching/SKILL.md +265 -0
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/skills/harper-auth/SKILL.md +320 -0
- package/plugins/lisa-harper-fabric-copilot/skills/harper-caching/SKILL.md +265 -0
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/skills/harper-auth/SKILL.md +320 -0
- package/plugins/lisa-harper-fabric-cursor/skills/harper-caching/SKILL.md +265 -0
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/src/harper-fabric/skills/harper-auth/SKILL.md +320 -0
- package/plugins/src/harper-fabric/skills/harper-caching/SKILL.md +265 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: harper-caching
|
|
3
|
+
description: This skill should be used when implementing Harper (HarperDB/Fabric) caching tables, external-source caches, TTL expiration, stale revalidation, invalidation, and cache verification. Use it when caching an upstream API, database, or expensive computation in Harper instead of hand-rolling in-memory maps. Pairs with harper-resources, harper-schema-graphql, harper-rest-queries, and harper-operations.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Harper Caching
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Harper can use a local table as a durable cache for an external source. The table
|
|
11
|
+
stores records, enforces schema/index behavior, exposes normal REST/GraphQL
|
|
12
|
+
routes, and calls the source Resource only when a record is missing, expired, or
|
|
13
|
+
explicitly invalidated.
|
|
14
|
+
|
|
15
|
+
Use a caching table when the cached data should survive process restarts,
|
|
16
|
+
participate in Harper queries, or stay coherent across Fabric nodes. Do not keep
|
|
17
|
+
API responses in a module-level `Map` unless the data is deliberately
|
|
18
|
+
process-local, disposable, and not part of the application data model.
|
|
19
|
+
|
|
20
|
+
Cross-check the table declaration in [[harper-schema-graphql]] and the Resource
|
|
21
|
+
method conventions in [[harper-resources]] before editing. If cached records are
|
|
22
|
+
queried by filters, sort keys, or relationships, also align indexes and query
|
|
23
|
+
shape with [[harper-rest-queries]].
|
|
24
|
+
|
|
25
|
+
## Declare the cache table
|
|
26
|
+
|
|
27
|
+
Declare a normal `@table` and expose it with `@export` when callers should reach
|
|
28
|
+
the cache over REST or GraphQL. Use the `expiration` argument on `@table` for the
|
|
29
|
+
default time-to-live, in seconds:
|
|
30
|
+
|
|
31
|
+
```graphql
|
|
32
|
+
type WeatherSnapshot @table(expiration: 300) @export(name: "weather") {
|
|
33
|
+
locationId: String @primaryKey
|
|
34
|
+
city: String @indexed
|
|
35
|
+
temperatureF: Float
|
|
36
|
+
conditions: String
|
|
37
|
+
sourceUpdatedAt: Long
|
|
38
|
+
fetchedAt: Long
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Guidance:
|
|
43
|
+
|
|
44
|
+
- Keep the primary key stable and derived from the upstream identity. For an
|
|
45
|
+
external REST API, a normalized URL slug, vendor id, or compound key string is
|
|
46
|
+
usually better than an auto-generated id.
|
|
47
|
+
- Index attributes used by cache reads (`city`, `tenantId`, `category`, `status`)
|
|
48
|
+
so callers do not fetch broad collections and filter in JavaScript.
|
|
49
|
+
- Store upstream freshness metadata such as `sourceUpdatedAt`, `etag`, or
|
|
50
|
+
`fetchedAt` when verification, debugging, or conditional revalidation needs it.
|
|
51
|
+
- Keep TTL at the table level unless the upstream response controls freshness per
|
|
52
|
+
record. Per-record expiration belongs in the source Resource context.
|
|
53
|
+
|
|
54
|
+
## Wire `sourcedFrom`
|
|
55
|
+
|
|
56
|
+
Implement a source Resource that fetches the upstream record, then attach it to
|
|
57
|
+
the table with `sourcedFrom`. In Lisa template projects, write TypeScript under
|
|
58
|
+
`src/` and rebuild the generated Harper assets; do not edit `resources.js` by
|
|
59
|
+
hand.
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
export class WeatherApiSource extends Resource {
|
|
63
|
+
static loadAsInstance = false;
|
|
64
|
+
|
|
65
|
+
async get(target) {
|
|
66
|
+
const id = target.id;
|
|
67
|
+
const response = await fetch(
|
|
68
|
+
`https://api.example.com/weather/${encodeURIComponent(id)}`,
|
|
69
|
+
{
|
|
70
|
+
headers: { Accept: 'application/json' },
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (response.status === 404) {
|
|
75
|
+
const error = new Error(`Weather location not found: ${id}`);
|
|
76
|
+
error.statusCode = 404;
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
const error = new Error(`Weather upstream failed: ${response.status}`);
|
|
82
|
+
error.statusCode = 502;
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const data = await response.json();
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
locationId: id,
|
|
90
|
+
city: data.city,
|
|
91
|
+
temperatureF: data.temperatureF,
|
|
92
|
+
conditions: data.conditions,
|
|
93
|
+
sourceUpdatedAt: Date.parse(data.updatedAt),
|
|
94
|
+
fetchedAt: Date.now(),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
tables.WeatherSnapshot.sourcedFrom(WeatherApiSource);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
When a requested record is missing or stale, Harper calls the source `get()` and
|
|
103
|
+
caches the returned record in the local table. Concurrent requests for the same
|
|
104
|
+
missing or stale record share the same upstream load, which avoids a cache
|
|
105
|
+
stampede for a single key.
|
|
106
|
+
|
|
107
|
+
## TTL and eviction
|
|
108
|
+
|
|
109
|
+
Use `expiration` for the TTL: after that many seconds, the cached entry is stale
|
|
110
|
+
and the next read reloads it from the source. If a project cannot express the
|
|
111
|
+
default in schema, `sourcedFrom` can also receive options:
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
tables.WeatherSnapshot.sourcedFrom(WeatherApiSource, {
|
|
115
|
+
expiration: 300,
|
|
116
|
+
eviction: 3600,
|
|
117
|
+
scanInterval: 60,
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Option meanings:
|
|
122
|
+
|
|
123
|
+
| Option | Use |
|
|
124
|
+
| --- | --- |
|
|
125
|
+
| `expiration` | Default TTL in seconds before the cached record is stale. |
|
|
126
|
+
| `eviction` | Seconds after expiration before Harper may physically remove the record. |
|
|
127
|
+
| `scanInterval` | Seconds between scans for expired records. |
|
|
128
|
+
|
|
129
|
+
Prefer schema directives for stable application behavior because the data model
|
|
130
|
+
and default freshness policy stay together. Use `sourcedFrom` options when the
|
|
131
|
+
cache attachment is intentionally dynamic or the downstream Harper version lacks
|
|
132
|
+
the needed schema directive.
|
|
133
|
+
|
|
134
|
+
## Conditional revalidation
|
|
135
|
+
|
|
136
|
+
When the upstream provides `ETag`, `Last-Modified`, or `Cache-Control`, pass that
|
|
137
|
+
freshness model through the source Resource instead of overwriting good cached
|
|
138
|
+
data with every revalidation.
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
export class WeatherApiSource extends Resource {
|
|
142
|
+
static loadAsInstance = false;
|
|
143
|
+
|
|
144
|
+
async get(target) {
|
|
145
|
+
const context = this.getContext();
|
|
146
|
+
const headers = new Headers({ Accept: 'application/json' });
|
|
147
|
+
|
|
148
|
+
if (context.replacingVersion) {
|
|
149
|
+
headers.set(
|
|
150
|
+
'If-Modified-Since',
|
|
151
|
+
new Date(context.replacingVersion).toUTCString(),
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const response = await fetch(
|
|
156
|
+
`https://api.example.com/weather/${encodeURIComponent(target.id)}`,
|
|
157
|
+
{ headers },
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
if (response.status === 304) {
|
|
161
|
+
return context.replacingRecord;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const maxAge = response.headers
|
|
165
|
+
.get('Cache-Control')
|
|
166
|
+
?.match(/max-age=(\d+)/)?.[1];
|
|
167
|
+
|
|
168
|
+
if (maxAge) {
|
|
169
|
+
context.expiresAt = Date.now() + Number(maxAge) * 1000;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
context.lastModified = response.headers.get('Last-Modified');
|
|
173
|
+
return response.json();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Use `allowStaleWhileRevalidate(entry, id)` on the cached table when stale data is
|
|
179
|
+
acceptable during refresh:
|
|
180
|
+
|
|
181
|
+
```javascript
|
|
182
|
+
export class WeatherSnapshot extends tables.WeatherSnapshot {
|
|
183
|
+
static loadAsInstance = false;
|
|
184
|
+
|
|
185
|
+
allowStaleWhileRevalidate(entry, id) {
|
|
186
|
+
return Date.now() - entry.expiresAt < 60_000;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Return `false` or omit the method when callers must wait for a fresh value.
|
|
192
|
+
|
|
193
|
+
## Explicit invalidation
|
|
194
|
+
|
|
195
|
+
Use invalidation when an admin action, webhook, scheduled refresh, or upstream
|
|
196
|
+
write makes the cached record stale before its TTL.
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
await tables.WeatherSnapshot.invalidate('nyc');
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
The next `get()` for that id reloads from the source. If the project Harper
|
|
203
|
+
version or resource shape does not expose `invalidate()`, use an explicit delete
|
|
204
|
+
or overwrite path and document the behavior:
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
await tables.WeatherSnapshot.delete('nyc');
|
|
208
|
+
await tables.WeatherSnapshot.get('nyc');
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
For write-through caches, implement `put`, `patch`, or `delete` on the source
|
|
212
|
+
Resource only when those operations should update the upstream system. Otherwise,
|
|
213
|
+
reject writes or keep cache mutation behind an operator-only Resource so clients
|
|
214
|
+
do not accidentally diverge from the source of truth.
|
|
215
|
+
|
|
216
|
+
## Fabric coherence
|
|
217
|
+
|
|
218
|
+
In a Fabric deployment, treat every node as capable of serving a read while cache
|
|
219
|
+
state is replicating:
|
|
220
|
+
|
|
221
|
+
- Keep `get()` deterministic and idempotent. A second node may reload the same
|
|
222
|
+
stale key.
|
|
223
|
+
- Do not store request-local data, credentials, or tenant state in module-level
|
|
224
|
+
variables. Read identity from Resource context and pass context through when
|
|
225
|
+
calling other resources.
|
|
226
|
+
- Pick TTLs that tolerate replication delay. Very short TTLs can turn a cache
|
|
227
|
+
into repeated upstream traffic across nodes.
|
|
228
|
+
- After invalidation, verify from the route or node that matters for the caller.
|
|
229
|
+
Cross-node visibility may lag until replication catches up.
|
|
230
|
+
- Use Harper storage reclamation settings for disk-pressure eviction tuning, not
|
|
231
|
+
as a substitute for application freshness rules.
|
|
232
|
+
|
|
233
|
+
## Local verification recipe
|
|
234
|
+
|
|
235
|
+
Prove both cache fill and cache hit behavior against a running Harper app:
|
|
236
|
+
|
|
237
|
+
1. Add a temporary upstream counter, fixture server log, or test-only header that
|
|
238
|
+
shows how many times the source Resource fetched the upstream id.
|
|
239
|
+
2. Build and boot the app (`bun run build`, then the project Harper dev command).
|
|
240
|
+
3. Request the same id twice:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
curl -sS http://localhost:9926/weather/nyc | jq .
|
|
244
|
+
curl -sS http://localhost:9926/weather/nyc | jq .
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
4. Confirm the upstream was called once, the second response came from the table,
|
|
248
|
+
and the record contains `fetchedAt` or equivalent freshness evidence.
|
|
249
|
+
5. Invalidate or delete the id, request it again, and confirm the upstream count
|
|
250
|
+
increments:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
curl -sS -X DELETE http://localhost:9926/weather/nyc
|
|
254
|
+
curl -sS http://localhost:9926/weather/nyc | jq .
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
6. If TTL behavior matters, lower `expiration` in a local-only test fixture,
|
|
258
|
+
wait past the TTL, and verify either blocking refresh or stale-while-revalidate
|
|
259
|
+
behavior matches the Resource implementation.
|
|
260
|
+
|
|
261
|
+
## Sources
|
|
262
|
+
|
|
263
|
+
- [Harper v4 Resource API](https://docs.harperdb.io/reference/v4/resources/resource-api)
|
|
264
|
+
- [Harper v5 Resources overview](https://docs.harperdb.io/reference/v5/resources/overview)
|
|
265
|
+
- [Harper storage tuning](https://docs.harperdb.io/reference/v5/database/storage-tuning)
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: harper-auth
|
|
3
|
+
description: This skill should be used when adding or debugging Harper (HarperDB/Fabric) authentication and authorization - roles.yaml, user and role Operations API calls, Basic auth, JWT operation tokens, exported-resource permissions, and Resource context.user checks. Pairs with harper-config-yaml, harper-resources, harper-rest-queries, and harper-operations.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Harper Auth
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Harper uses role-based access control. Every user has one role, and that role
|
|
11
|
+
decides which databases, tables, attributes, and operations the user can access.
|
|
12
|
+
Use declarative `roles.yaml` for application-owned roles and the Operations API
|
|
13
|
+
for environment-owned users, password changes, role audits, and token issuance.
|
|
14
|
+
|
|
15
|
+
Cross-check extension wiring in [[harper-config-yaml]] before editing roles:
|
|
16
|
+
custom `config.yaml` files replace Harper's default config, so `roles` must be
|
|
17
|
+
re-declared alongside `rest`, `graphqlSchema`, and `jsResource` when the app needs
|
|
18
|
+
all of them. Cross-check endpoint/resource behavior in [[harper-resources]] and
|
|
19
|
+
query filters in [[harper-rest-queries]].
|
|
20
|
+
|
|
21
|
+
## Role model
|
|
22
|
+
|
|
23
|
+
Harper has built-in roles and custom roles:
|
|
24
|
+
|
|
25
|
+
| Role type | Use it for | Notes |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| `super_user` | Operators, deploy automation, emergency admin work | Full access to operations and data. Do not use for app clients. |
|
|
28
|
+
| `structure_user` | Schema/database administration without full data access | Scope narrowly when used; normal app users usually should not need it. |
|
|
29
|
+
| Custom role | Application clients, readers, editors, service accounts | Permissions are explicit. Missing database/table entries mean no access. |
|
|
30
|
+
|
|
31
|
+
Prefer least-privilege custom roles for application traffic. A public read client,
|
|
32
|
+
an editor/admin client, and a deploy/operator client should normally be separate
|
|
33
|
+
users with separate roles.
|
|
34
|
+
|
|
35
|
+
## Enable role files
|
|
36
|
+
|
|
37
|
+
Keep roles in the component root, typically `harper-app/roles.yaml`, and enable
|
|
38
|
+
the built-in `roles` extension in `harper-app/config.yaml`:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
rest: true
|
|
42
|
+
graphqlSchema:
|
|
43
|
+
files: 'schema.graphql'
|
|
44
|
+
roles:
|
|
45
|
+
files: 'roles.yaml'
|
|
46
|
+
jsResource:
|
|
47
|
+
files: 'resources.js'
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Because `config.yaml` is not merged with Harper's defaults, keep every extension
|
|
51
|
+
the component needs in this file. Removing `roles` silently stops role-file
|
|
52
|
+
reconciliation; removing `rest` or `jsResource` can make the secured endpoint
|
|
53
|
+
disappear while the role still exists.
|
|
54
|
+
|
|
55
|
+
## Declare roles in `roles.yaml`
|
|
56
|
+
|
|
57
|
+
Use `roles.yaml` for roles that should be versioned with the app. On startup,
|
|
58
|
+
Harper creates missing declared roles and updates existing declared roles to match
|
|
59
|
+
the file.
|
|
60
|
+
|
|
61
|
+
Example: public readers can read orders, but only admins can write:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
public_reader:
|
|
65
|
+
super_user: false
|
|
66
|
+
app:
|
|
67
|
+
Orders:
|
|
68
|
+
read: true
|
|
69
|
+
insert: false
|
|
70
|
+
update: false
|
|
71
|
+
delete: false
|
|
72
|
+
attributes:
|
|
73
|
+
id:
|
|
74
|
+
read: true
|
|
75
|
+
status:
|
|
76
|
+
read: true
|
|
77
|
+
publicTotal:
|
|
78
|
+
read: true
|
|
79
|
+
|
|
80
|
+
order_admin:
|
|
81
|
+
super_user: false
|
|
82
|
+
app:
|
|
83
|
+
Orders:
|
|
84
|
+
read: true
|
|
85
|
+
insert: true
|
|
86
|
+
update: true
|
|
87
|
+
delete: false
|
|
88
|
+
attributes:
|
|
89
|
+
internalNotes:
|
|
90
|
+
read: true
|
|
91
|
+
insert: true
|
|
92
|
+
update: true
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Rules:
|
|
96
|
+
|
|
97
|
+
- Database keys such as `app` must match the database names in `schema.graphql`.
|
|
98
|
+
- Table keys such as `Orders` must match the table type names, not necessarily the
|
|
99
|
+
exported REST path.
|
|
100
|
+
- Table-level `read`, `insert`, `update`, and `delete` are the outer gate.
|
|
101
|
+
- Attribute permissions narrow field-level access. They cannot grant a capability
|
|
102
|
+
that the table-level permission denies.
|
|
103
|
+
- If a database or table is omitted from the role, that role has no access to it.
|
|
104
|
+
|
|
105
|
+
Use role files for stable app permissions. Use Operations API calls when changing
|
|
106
|
+
users, rotating credentials, or inspecting what the deployed system actually has.
|
|
107
|
+
|
|
108
|
+
## Manage users and roles with Operations API
|
|
109
|
+
|
|
110
|
+
User and role mutations require a `super_user` caller. Send JSON `POST` requests
|
|
111
|
+
to the Operations API, usually port `9925` locally:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
curl -sS http://localhost:9925/ \
|
|
115
|
+
-u "$HARPER_USERNAME:$HARPER_PASSWORD" \
|
|
116
|
+
-H 'Content-Type: application/json' \
|
|
117
|
+
--data '{"operation":"list_roles"}'
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Create a user for a declared role:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
curl -sS http://localhost:9925/ \
|
|
124
|
+
-u "$HARPER_USERNAME:$HARPER_PASSWORD" \
|
|
125
|
+
-H 'Content-Type: application/json' \
|
|
126
|
+
--data '{
|
|
127
|
+
"operation": "add_user",
|
|
128
|
+
"username": "public-client",
|
|
129
|
+
"password": "replace-with-generated-secret",
|
|
130
|
+
"role": "public_reader",
|
|
131
|
+
"active": true
|
|
132
|
+
}'
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Change a user's role or password:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
curl -sS http://localhost:9925/ \
|
|
139
|
+
-u "$HARPER_USERNAME:$HARPER_PASSWORD" \
|
|
140
|
+
-H 'Content-Type: application/json' \
|
|
141
|
+
--data '{
|
|
142
|
+
"operation": "alter_user",
|
|
143
|
+
"username": "public-client",
|
|
144
|
+
"role": "order_admin",
|
|
145
|
+
"active": true
|
|
146
|
+
}'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Remove a user before removing a role:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
curl -sS http://localhost:9925/ \
|
|
153
|
+
-u "$HARPER_USERNAME:$HARPER_PASSWORD" \
|
|
154
|
+
-H 'Content-Type: application/json' \
|
|
155
|
+
--data '{"operation":"drop_user","username":"public-client"}'
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Avoid committing real passwords, tokens, or generated secrets. For local examples,
|
|
159
|
+
use environment variables or throwaway development credentials.
|
|
160
|
+
|
|
161
|
+
## Basic auth and JWT operation tokens
|
|
162
|
+
|
|
163
|
+
Harper accepts Basic auth for Operations API and secured REST calls:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
curl -i http://localhost:9926/app/orders/ \
|
|
167
|
+
-u "$PUBLIC_USERNAME:$PUBLIC_PASSWORD"
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
For clients that should not send Basic auth on every request, create JWT tokens
|
|
171
|
+
with `create_authentication_tokens`. This operation is intentionally unauthenticated
|
|
172
|
+
but requires the target username and password:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
tokens="$(
|
|
176
|
+
curl -sS http://localhost:9925/ \
|
|
177
|
+
-H 'Content-Type: application/json' \
|
|
178
|
+
--data '{
|
|
179
|
+
"operation": "create_authentication_tokens",
|
|
180
|
+
"username": "'"$PUBLIC_USERNAME"'",
|
|
181
|
+
"password": "'"$PUBLIC_PASSWORD"'"
|
|
182
|
+
}'
|
|
183
|
+
)"
|
|
184
|
+
|
|
185
|
+
operation_token="$(jq -r '.operation_token' <<<"$tokens")"
|
|
186
|
+
refresh_token="$(jq -r '.refresh_token' <<<"$tokens")"
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Use the operation token as a bearer token:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
curl -i http://localhost:9926/app/orders/ \
|
|
193
|
+
-H "Authorization: Bearer $operation_token"
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Refresh an expired operation token with the refresh token:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
curl -sS http://localhost:9925/ \
|
|
200
|
+
-H 'Content-Type: application/json' \
|
|
201
|
+
-H "Authorization: Bearer $refresh_token" \
|
|
202
|
+
--data '{"operation": "refresh_operation_token"}'
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Treat operation tokens and refresh tokens as credentials. Never log them, commit
|
|
206
|
+
them, paste them into tickets, or store them in browser-accessible app config.
|
|
207
|
+
|
|
208
|
+
## Exported resources and `context.user`
|
|
209
|
+
|
|
210
|
+
Exported tables and custom Resources inherit the caller's role permissions.
|
|
211
|
+
If a role cannot read or write the underlying table, Harper should deny the REST
|
|
212
|
+
or GraphQL request before app logic treats it as successful.
|
|
213
|
+
|
|
214
|
+
Use custom Resource checks when the rule depends on request identity, tenant
|
|
215
|
+
ownership, or business state that is not expressible in `roles.yaml`:
|
|
216
|
+
|
|
217
|
+
```javascript
|
|
218
|
+
export class Orders extends tables.Orders {
|
|
219
|
+
static async post(target, data, context) {
|
|
220
|
+
const user = context.user;
|
|
221
|
+
if (!user) {
|
|
222
|
+
const error = new Error('Authentication required');
|
|
223
|
+
error.statusCode = 401;
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (user.role !== 'order_admin') {
|
|
228
|
+
const error = new Error('Forbidden');
|
|
229
|
+
error.statusCode = 403;
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return super.post(target, await data, context);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Pass `context` through when delegating to tables or other resources:
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
await tables.OrderEvents.post(
|
|
242
|
+
target,
|
|
243
|
+
{
|
|
244
|
+
orderId,
|
|
245
|
+
type: 'created',
|
|
246
|
+
createdBy: context.user?.username,
|
|
247
|
+
},
|
|
248
|
+
context,
|
|
249
|
+
);
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Guidance:
|
|
253
|
+
|
|
254
|
+
- Use `roles.yaml` for coarse table/attribute access and Resource logic for
|
|
255
|
+
request-specific policy.
|
|
256
|
+
- Do not trust client-provided role, user id, tenant id, or permission claims.
|
|
257
|
+
Read identity from `context.user`.
|
|
258
|
+
- Do not put `context` in module-level state; it belongs to one request.
|
|
259
|
+
- Do not use `requestWithoutAuthentication` for normal application routes. If a
|
|
260
|
+
webhook must bypass Harper auth, verify its signature first and keep its table
|
|
261
|
+
writes narrowly scoped.
|
|
262
|
+
|
|
263
|
+
## Verification matrix
|
|
264
|
+
|
|
265
|
+
Run the local app, create the test users, and check unauthenticated, reader, and
|
|
266
|
+
admin behavior against the same endpoint:
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
harper dev harper-app
|
|
270
|
+
|
|
271
|
+
# Unauthenticated request should be denied.
|
|
272
|
+
curl -i http://localhost:9926/app/orders/
|
|
273
|
+
|
|
274
|
+
# Reader can read.
|
|
275
|
+
curl -i http://localhost:9926/app/orders/ \
|
|
276
|
+
-u "$PUBLIC_USERNAME:$PUBLIC_PASSWORD"
|
|
277
|
+
|
|
278
|
+
# Reader cannot write.
|
|
279
|
+
curl -i -X POST http://localhost:9926/app/orders/ \
|
|
280
|
+
-u "$PUBLIC_USERNAME:$PUBLIC_PASSWORD" \
|
|
281
|
+
-H 'Content-Type: application/json' \
|
|
282
|
+
--data '{"id":"ord_1","status":"new"}'
|
|
283
|
+
|
|
284
|
+
# Admin can write.
|
|
285
|
+
curl -i -X POST http://localhost:9926/app/orders/ \
|
|
286
|
+
-u "$ADMIN_USERNAME:$ADMIN_PASSWORD" \
|
|
287
|
+
-H 'Content-Type: application/json' \
|
|
288
|
+
--data '{"id":"ord_1","status":"new"}'
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Expected results:
|
|
292
|
+
|
|
293
|
+
| Caller | Read | Write |
|
|
294
|
+
| --- | --- | --- |
|
|
295
|
+
| No credentials | `401` or auth denial | `401` or auth denial |
|
|
296
|
+
| `public_reader` | `200` | `403` or permission denial |
|
|
297
|
+
| `order_admin` | `200` | `200` or expected validation response |
|
|
298
|
+
|
|
299
|
+
Also verify metadata with a restricted user when debugging permissions:
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
curl -sS http://localhost:9925/ \
|
|
303
|
+
-u "$PUBLIC_USERNAME:$PUBLIC_PASSWORD" \
|
|
304
|
+
-H 'Content-Type: application/json' \
|
|
305
|
+
--data '{"operation":"user_info"}'
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
If the status code is unexpected, check in this order:
|
|
309
|
+
|
|
310
|
+
1. `config.yaml` still enables `roles`, `rest`, `graphqlSchema`, and `jsResource`.
|
|
311
|
+
2. `roles.yaml` database/table names match the schema.
|
|
312
|
+
3. The user is active and assigned to the intended role.
|
|
313
|
+
4. The route being tested is the exported table/resource path you meant to secure.
|
|
314
|
+
5. Resource code passes `context` through to `super` and nested table calls.
|
|
315
|
+
|
|
316
|
+
## Sources
|
|
317
|
+
|
|
318
|
+
- [Users & Roles Configuration](https://docs.harperdb.io/reference/v5/users-and-roles/configuration)
|
|
319
|
+
- [Operations Reference](https://docs.harperdb.io/reference/v5/operations-api/operations)
|
|
320
|
+
- [Components Overview](https://docs.harperdb.io/reference/v5/components/overview)
|