Skip to content

Commit 5ca7aab

Browse files
committed
test(runtime): the body doors stamp the caller and refuse what only the platform writes
Tests, generated artifacts, docs and the changeset for the two body doors: each door refuses an input naming a stamped value, refuses a record the caller cannot read, and holds its recipient and hourly limits; the outbox delivers a row the mail service did not write from the configured sender; an app's timeline entry may not use a platform-only type or key. Clause-②: yes (widening) Metadata-protocol: added Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwV8gsjrvCXCqKoaiG
1 parent ad159e0 commit 5ca7aab

56 files changed

Lines changed: 1000 additions & 56 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/core': patch
4+
'@objectstack/runtime': patch
5+
'@objectstack/cli': patch
6+
'@objectstack/rest': patch
7+
'@objectstack/plugin-email': patch
8+
'@objectstack/plugin-audit': patch
9+
'@objectstack/plugin-security': patch
10+
'@object-ui/app-shell': patch
11+
---
12+
13+
feat(runtime): a script body sends mail and adds a timeline entry through platform doors that stamp who sent it
14+
15+
Clause-②: yes (widening)
16+
Metadata-protocol: added
17+
18+
- **`@objectstack/spec`:** two new body capabilities, `email.send` and `activity.append`, and their inputs `BodyMailSendInputSchema` and `BodyActivityAppendInputSchema` (`@objectstack/spec/data`). The sender, the sending user, the organization, the actor and the origin are stamped by the platform and are not inputs: a key outside either shape is refused. `SYS_ACTIVITY_PLATFORM_TYPES` names the timeline types only the platform records.
19+
- **`@objectstack/runtime`:** a hook, action or job body that declares the capability calls `ctx.email.send({ to, subject, text })` or `ctx.activity.append({ object, recordId, type, summary })`. A message is sent from the configured sender, as the calling user, under the caller's organization; a timeline entry is written with the calling user as its actor and the package and body as its origin. A record the call points at must be one the caller can read. A message names at most 50 recipients, and an organization's mail is held to `OS_EMAIL_APP_SEND_HOURLY_LIMIT` messages an hour (default 200) before the door refuses another. A body with no calling user (a job) sends and writes with no user recorded.
20+
- **`@objectstack/cli`:** the build infers both capabilities from a handler's calls, under a renamed or destructured context too.
21+
- **`@objectstack/core`:** the bounds a caller-sent message is held to (the sending user, the organization, the configured sender) are one function, `boundCallerMail`, shared by the REST mail door and the body door.
22+
- **`@objectstack/rest`:** the REST mail door reads its bounds from `boundCallerMail`; its answers are unchanged.
23+
- **`@objectstack/plugin-email`:** a mail-log row the mail service did not write is delivered from the configured sender.
24+
- **`@objectstack/plugin-audit`:** the activity feed owns the door's writer, `appendAppActivity` on the `audit` service. An app's entry may not use a platform-only type or a platform metadata key, and may not be about an object the feed does not show or an append-only object. `sys_activity` gains a read-only `origin` column, empty on an entry the platform recorded.
25+
- **`@objectstack/plugin-security`:** inserting into an append-only object from app automation that runs as system is deprecated, and says so once per kind and object, naming the two doors.
26+
- **`@object-ui/app-shell`:** the script capability picker lists both capabilities with their calls.

‎content/docs/automation/hook-bodies.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ The script sees only what the surrounding `ctx` object exposes:
105105
| `ctx.title('<lookup field>')` | The related record's title, through a lookup / master_detail / user / tree column. Costs one `findOne` (plus the lookups that record's own title reads through). | `api.read` |
106106
| `ctx.crypto.randomUUID()` | UUID generation. | `crypto.uuid` |
107107
| `ctx.log.{info,warn,error}` | Structured logging. | `log` |
108+
| `ctx.email.send({ to, subject, text })` | Sends mail through the mail service, from the configured sender, as the calling user and under the caller's organization. See [Email service](/docs/kernel/runtime-services/email-service#from-a-script-body). | `email.send` |
109+
| `ctx.activity.append({ object, recordId, type, summary })` | Adds an entry to a record's activity timeline. The platform stamps the calling user as the actor and the package and body as the entry's `origin`. `type` may not be one only the platform records (`SYS_ACTIVITY_PLATFORM_TYPES`), and the record must be one the caller can read. | `activity.append` |
108110
| `ctx.connector(name).<method>(...)` _(planned)_ | Outbound HTTP / SaaS calls. **Not yet wired into the sandbox** — ships with the separate Connector spec. | (separate Connector spec) |
109111

110112
### Write provenance — `ctx.provenance`

‎content/docs/deployment/environment-variables.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ Link previews read the same values. The console document served at `/_console/`
175175
| `OS_EMAIL_SMTP_SECURE` | boolean | `true` | Require TLS. On port `465` that means implicit TLS; on any other port a **required** STARTTLS upgrade (a server that will not upgrade fails the send instead of leaking credentials in the clear). `false` connects in the clear and upgrades only when STARTTLS is offered. |
176176
| `OS_EMAIL_SMTP_USER` | string | — | SMTP AUTH username. Omit for servers that accept unauthenticated relay. |
177177
| `OS_EMAIL_SMTP_PASSWORD` | string | — | SMTP AUTH password. |
178+
| `OS_EMAIL_APP_SEND_HOURLY_LIMIT` | number | `200` | The most messages an organization's mail log may record in one hour before a script body's `ctx.email.send` is refused with `429 RATE_LIMIT_EXCEEDED`. A whole number, `0` or more; any other value fails the call. See [Email service](/docs/kernel/runtime-services/email-service#from-a-script-body). |
178179

179180
> SMTP delivery ships in `@objectstack/plugin-email` (ADR-0012) and is
180181
> implemented with `nodemailer`, imported lazily so deployments that never

‎content/docs/kernel/runtime-services/email-service.mdx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ services.email.sendTemplate(input: SendTemplateInput): Promise<SendEmailResult>
3030

3131
`replyTo` is not bounded. It is the caller's choice of Reply-To address and makes no claim about the sender.
3232

33+
## From a script body
34+
35+
A hook, action or job body sends mail with `ctx.email.send(input)` when it declares the `email.send` capability (`os build` infers it from the call). The input is `BodyMailSendInputSchema` (`@objectstack/spec/data`): `to`, `cc`, `bcc`, `replyTo`, `subject`, `text` and/or `html`, and `related`, the record the message is about.
36+
37+
- The message is sent from the configured sender. Its display name names the calling user beside the organization, for example `Ann Lee via Acme`. Replies go to `replyTo`.
38+
- It is recorded as sent by the calling user and under the caller's organization, with the same bounds as the HTTP door. `from`, `sentBy`, `organizationId`, `headers` and `identityMail` are not inputs, and a call that names one is refused with `400 VALIDATION_ERROR`.
39+
- `related` must be a record the caller can read. Otherwise the call is refused with `404 RECORD_NOT_FOUND` and nothing is sent.
40+
- A message names at most 50 recipients across `to`, `cc` and `bcc`.
41+
- While the organization's mail log records `OS_EMAIL_APP_SEND_HOURLY_LIMIT` messages (default 200) in the last hour, the call is refused with `429 RATE_LIMIT_EXCEEDED`.
42+
- A job body has no calling user, so its message is recorded with no `sentBy`.
43+
44+
The call answers `{ id, status }`. A deployment with no mail service answers `501 NOT_IMPLEMENTED`.
45+
46+
A row written into the mail log (`sys_email`, `sys_identity_email`) by anything other than the mail service is delivered from the configured sender, whatever its `from_address` said.
47+
3348
## Returns
3449

3550
`SendEmailResult`:
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: Hook Body Doors — Data Protocol reference
3+
navTitle: Hook Body Doors
4+
description: "The two platform doors a sandboxed script body (a hook, action or job body) reaches for records it may not write itself: mail goes through the mail service."
5+
---
6+
7+
{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}
8+
9+
The two platform doors a sandboxed script body (a hook, action or job body)
10+
reaches for records it may not write itself: mail goes through the mail
11+
service, and a timeline entry goes through the activity door. A body asks for
12+
each with its own capability token (`email.send`, `activity.append`,
13+
`HookBodyCapability`), and calls it as `ctx.email.send(input)` /
14+
`ctx.activity.append(input)`.
15+
16+
Each input below is what the BODY may say. What the platform says about the
17+
message or the entry is stamped by the door and is not an input: the sender,
18+
the user the mail is sent by, the organization it belongs to, the actor of a
19+
timeline entry and the origin naming the body that wrote it. A key outside
20+
the shape is refused, never dropped, so a body that names one of those is
21+
told at the call.
22+
23+
<Callout type="info">
24+
**Source:** `packages/spec/src/data/hook-body-doors.zod.ts`
25+
</Callout>
26+
27+
## TypeScript Usage
28+
29+
```typescript
30+
import { BodyActivityAppendInputSchema, BodyDoorRecordRefSchema, BodyMailSendInputSchema } from '@objectstack/spec/data';
31+
import type { BodyActivityAppendInput, BodyDoorRecordRef, BodyMailSendInput } from '@objectstack/spec/data';
32+
33+
// Validate data
34+
const result = BodyActivityAppendInputSchema.parse(data);
35+
```
36+
37+
---
38+
39+
## BodyActivityAppendInput
40+
41+
ctx.activity.append input: one entry a script body adds to a record timeline
42+
43+
### Properties
44+
45+
| Property | Type | Required | Description |
46+
| :--- | :--- | :--- | :--- |
47+
| **object** | `string` | ✅ | Object name of the record the entry is about |
48+
| **recordId** | `string` | ✅ | Id of the record the entry is about |
49+
| **type** | `string` | ✅ | Activity kind, from the open vocabulary less the platform-only values |
50+
| **summary** | `string` | ✅ | One-line summary |
51+
| **recordLabel** | `string` | optional | Display label of the record, as of the entry |
52+
| **source** | `{ object: string; id: string }` | optional | The record the entry points at for its detail |
53+
| **metadata** | `Record<string, any>` | optional | Display hints stored beside the entry |
54+
55+
### Nested Shape: `BodyActivityAppendInput.source`
56+
57+
| Property | Type | Required | Description |
58+
| :--- | :--- | :--- | :--- |
59+
| **object** | `string` | ✅ | Object name of the record |
60+
| **id** | `string` | ✅ | Record id |
61+
62+
63+
---
64+
65+
## BodyDoorRecordRef
66+
67+
A record the door reads in the caller's scope before it acts
68+
69+
### Properties
70+
71+
| Property | Type | Required | Description |
72+
| :--- | :--- | :--- | :--- |
73+
| **object** | `string` | ✅ | Object name of the record |
74+
| **id** | `string` | ✅ | Record id |
75+
76+
77+
---
78+
79+
## BodyMailSendInput
80+
81+
ctx.email.send input: a message a script body hands to the mail service
82+
83+
### Properties
84+
85+
| Property | Type | Required | Description |
86+
| :--- | :--- | :--- | :--- |
87+
| **to** | `string \| { name?: string; address: string } \| (string \| { name?: string; address: string })[]` | ✅ | Recipient address, or a list of them |
88+
| **cc** | `string \| { name?: string; address: string } \| (string \| { name?: string; address: string })[]` | optional | Carbon-copy recipients |
89+
| **bcc** | `string \| { name?: string; address: string } \| (string \| { name?: string; address: string })[]` | optional | Blind carbon-copy recipients |
90+
| **replyTo** | `string \| { name?: string; address: string }` | optional | Reply-To address; the sender itself is the configured one |
91+
| **subject** | `string` | ✅ | Subject line |
92+
| **text** | `string` | optional | Plain-text body |
93+
| **html** | `string` | optional | HTML body |
94+
| **related** | `{ object: string; id: string }` | optional | The record the message is about |
95+
96+
### Nested Shape: `BodyMailSendInput.related`
97+
98+
| Property | Type | Required | Description |
99+
| :--- | :--- | :--- | :--- |
100+
| **object** | `string` | ✅ | Object name of the record |
101+
| **id** | `string` | ✅ | Record id |
102+
103+
104+
---
105+

‎content/docs/references/data/hook-body.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ L2 sandboxed JS body — runs inside an isolated VM with declared capabilities
6767
| :--- | :--- | :--- | :--- |
6868
| **language** | `'js'` | ✅ | |
6969
| **source** | `string` | ✅ | Function body source |
70-
| **capabilities** | `Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log'>[]` | optional (default: `[]`) | Granted capability tokens |
70+
| **capabilities** | `Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log' \| 'email.send' \| 'activity.append'>[]` | optional (default: `[]`) | Granted capability tokens |
7171
| **timeoutMs** | `integer` | optional | Per-invocation timeout (ms) |
7272
| **memoryMb** | `integer` | optional | Per-invocation memory cap (MB) |
7373

@@ -85,6 +85,8 @@ L2 sandboxed JS body — runs inside an isolated VM with declared capabilities
8585
* `api.transaction`
8686
* `crypto.uuid`
8787
* `log`
88+
* `email.send`
89+
* `activity.append`
8890

8991

9092
---
@@ -99,7 +101,7 @@ L2 sandboxed JS body — runs inside an isolated VM with declared capabilities
99101
| :--- | :--- | :--- | :--- |
100102
| **language** | `'js'` | ✅ | |
101103
| **source** | `string` | ✅ | Function body source |
102-
| **capabilities** | `Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log'>[]` | optional (default: `[]`) | Granted capability tokens |
104+
| **capabilities** | `Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log' \| 'email.send' \| 'activity.append'>[]` | optional (default: `[]`) | Granted capability tokens |
103105
| **timeoutMs** | `integer` | optional | Per-invocation timeout (ms) |
104106
| **memoryMb** | `integer` | optional | Per-invocation memory cap (MB) |
105107

‎content/docs/references/data/hook.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const result = HookSchema.parse(data);
3333
| **object** | `string \| string[]` | ✅ | Target object(s) |
3434
| **events** | `Enum<'beforeFind' \| 'afterFind' \| 'beforeInsert' \| 'afterInsert' \| 'beforeUpdate' \| 'afterUpdate' \| 'beforeDelete' \| 'afterDelete'>[]` | ✅ | Lifecycle events |
3535
| **handler** | `string` | optional | Handler function name (string, post-build) or inline function (pre-build) — DEPRECATED, prefer `body` |
36-
| **body** | `{ language: 'expression'; source: string } \| { language: 'js'; source: string; capabilities?: Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log'>[]; timeoutMs?: integer; … }` | optional | Hook body — expression (L1) or sandboxed JS (L2) |
36+
| **body** | `{ language: 'expression'; source: string } \| { language: 'js'; source: string; capabilities?: Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log' \| …>[]; timeoutMs?: integer; … }` | optional | Hook body — expression (L1) or sandboxed JS (L2) |
3737
| **priority** | `number` | optional (default: `100`) | Execution priority |
3838
| **async** | `boolean` | optional (default: `false`) | Run specifically as fire-and-forget |
3939
| **condition** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL); hook runs only when TRUE. e.g. P`record.status == "closed" && record.amount != null && record.amount > 1000` |
@@ -69,7 +69,7 @@ L2 sandboxed JS body — runs inside an isolated VM with declared capabilities
6969
| :--- | :--- | :--- | :--- |
7070
| **language** | `'js'` | ✅ | |
7171
| **source** | `string` | ✅ | Function body source |
72-
| **capabilities** | `Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log'>[]` | optional (default: `[]`) | Granted capability tokens |
72+
| **capabilities** | `Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log' \| …>[]` | optional (default: `[]`) | Granted capability tokens |
7373
| **timeoutMs** | `integer` | optional | Per-invocation timeout (ms) |
7474
| **memoryMb** | `integer` | optional | Per-invocation memory cap (MB) |
7575

‎content/docs/references/data/index.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Data Protocol — complete schema reference
33
navTitle: Data Protocol
4-
description: "The ObjectStack Data Protocol in 34 reference pages: every schema in @objectstack/spec with its properties, types, defaults and a TypeScript example."
4+
description: "The ObjectStack Data Protocol in 35 reference pages: every schema in @objectstack/spec with its properties, types, defaults and a TypeScript example."
55
---
66

77
{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}
@@ -34,6 +34,7 @@ This section contains all protocol schemas for the data layer of ObjectStack.
3434
<Card href="/docs/references/data/filter" title="Filter" description="Source: packages/spec/src/data/filter.zod.ts" />
3535
<Card href="/docs/references/data/hook" title="Hook" description="Source: packages/spec/src/data/hook.zod.ts" />
3636
<Card href="/docs/references/data/hook-body" title="Hook Body" description="Source: packages/spec/src/data/hook-body.zod.ts" />
37+
<Card href="/docs/references/data/hook-body-doors" title="Hook Body Doors" description="Source: packages/spec/src/data/hook-body-doors.zod.ts" />
3738
<Card href="/docs/references/data/mapping" title="Mapping" description="Source: packages/spec/src/data/mapping.zod.ts" />
3839
<Card href="/docs/references/data/object" title="Object" description="Source: packages/spec/src/data/object.zod.ts" />
3940
<Card href="/docs/references/data/picklist" title="Picklist" description="Source: packages/spec/src/data/picklist.zod.ts" />

‎content/docs/references/data/meta.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"driver-sqlite",
3838
"driver-turso",
3939
"field-value",
40+
"hook-body-doors",
4041
"picklist",
4142
"recycle-bin",
4243
"seed-file"

0 commit comments

Comments
 (0)