@poppykit/server 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +4 -0
- package/CHANGELOG.md +15 -15
- package/CONTRIBUTING.md +30 -42
- package/DELIVERY.md +6 -42
- package/README.md +55 -102
- package/RELEASING.md +91 -193
- package/SECURITY.md +3 -3
- package/STORAGE.md +75 -14
- package/dist/adapter-contract.d.ts +8 -0
- package/dist/adapter-contract.js +30 -0
- package/dist/postgres-runtime.d.ts +30 -0
- package/dist/postgres-runtime.js +172 -0
- package/dist/postgres.d.ts +31 -0
- package/dist/postgres.js +303 -0
- package/migrations/postgres/0001_poppy_server.sql +16 -0
- package/package.json +18 -3
package/RELEASING.md
CHANGED
|
@@ -1,193 +1,91 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
environment settings, npm ownership or OIDC exchange work.
|
|
93
|
-
|
|
94
|
-
Any documentation/package-metadata/source change after J6 creates a new candidate.
|
|
95
|
-
J6 evidence applies only to J6's recorded commits/digests. Re-run this complete
|
|
96
|
-
graph on final commits/tarballs and retain the new manifests/platform results.
|
|
97
|
-
Never label changed bytes publishable using old evidence. A passing Windows
|
|
98
|
-
local run does not substitute for actual hosted Linux/macOS jobs.
|
|
99
|
-
|
|
100
|
-
## Owner configuration — external, not performed by this repository
|
|
101
|
-
|
|
102
|
-
Rechecked against [npm trusted publishers](https://docs.npmjs.com/trusted-publishers/),
|
|
103
|
-
[GitHub secure use](https://docs.github.com/en/actions/reference/security/secure-use),
|
|
104
|
-
[OIDC](https://docs.github.com/en/actions/concepts/security/openid-connect), and
|
|
105
|
-
[deployment environments](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments)
|
|
106
|
-
on **2026-10-23**. Recheck those live requirements before first publication:
|
|
107
|
-
|
|
108
|
-
1. The owner confirmed the `@poppykit` scope and selected MIT/version 0.1.0.
|
|
109
|
-
Confirm the actual publishing account has package-name/maintainer rights and
|
|
110
|
-
the chosen version is unused. The complete LICENSE is in the package allowlist
|
|
111
|
-
and release notes describe this initial development candidate.
|
|
112
|
-
Confirm repository.url exactly matches the actual GitHub repository.
|
|
113
|
-
2. Protect main, release tags, Actions files/scripts and candidate pins with
|
|
114
|
-
repository rules and review/CODEOWNERS appropriate to the actual team. Require
|
|
115
|
-
the complete verification result for the exact commit. Prevent unreviewed
|
|
116
|
-
workflow changes or tag replacement. Read-only PR permissions and trusted
|
|
117
|
-
publishing cannot enforce these owner settings themselves.
|
|
118
|
-
3. Create environment `npm` in each package repository with required reviewers,
|
|
119
|
-
self-approval restrictions, protected release-tag rules and no admin bypass
|
|
120
|
-
where the repository plan supports them. Confirm feature availability; an
|
|
121
|
-
unprotected environment name alone provides no approval barrier. Add environment
|
|
122
|
-
variable `NPM_PUBLISH_ENABLED=true` only after setup/authorization. Missing
|
|
123
|
-
or false configuration fails the publisher's check.
|
|
124
|
-
4. Configure each npm package's trusted publisher for GitHub owner `LMol-4`,
|
|
125
|
-
the corresponding `poppykit-client`, `poppykit-server` or `poppykit-cli`
|
|
126
|
-
repository, workflow filename **release.yml**, and environment **npm**.
|
|
127
|
-
Match spelling/case and the initiating workflow identity. verify.yml is a
|
|
128
|
-
reusable verifier, not the publishing workflow. Reassess identity if introducing
|
|
129
|
-
a reusable publisher or changing callers; workflow_call/dispatch identity has
|
|
130
|
-
documented caller nuances. This setup authorizes a workflow identity, not its
|
|
131
|
-
test results. The gate supplies the independent verification condition.
|
|
132
|
-
5. npm currently requires npm >=11.5.1 and Node >=22.14.0 for trusted publishing;
|
|
133
|
-
this workflow uses Node24.12.0 and checks npm's version without upgrading it.
|
|
134
|
-
GitHub-hosted runners are supported; self-hosted runners are not supported for
|
|
135
|
-
this npm path. GitHub permissions must permit OIDC. No NODE_AUTH_TOKEN is set.
|
|
136
|
-
Do not silently fall back to a long-lived publish token when OIDC fails.
|
|
137
|
-
6. Verify provenance requirements, repository visibility and package visibility
|
|
138
|
-
in the current npm documentation. Trusted publishing generates provenance
|
|
139
|
-
automatically for supported public packages/public repositories; explicit
|
|
140
|
-
--provenance must not be treated as proof without checking the registry record.
|
|
141
|
-
A private-source repository may need an owner-approved alternative or visibility
|
|
142
|
-
decision; do not claim provenance supported where it is not.
|
|
143
|
-
7. Current npm publisher configurations require first successful use within two
|
|
144
|
-
days or expire; configure near the authorized release. npm supports up to ten
|
|
145
|
-
configurations, with separate direct-publish/staging/dist-tag permissions.
|
|
146
|
-
Grant only this workflow's required direct publication capability, review other
|
|
147
|
-
publishers/tokens and restrict alternative access according to owner policy.
|
|
148
|
-
Keep recovery access separate from the normal workflow.
|
|
149
|
-
|
|
150
|
-
## First publication and bootstrap
|
|
151
|
-
|
|
152
|
-
A new package may need first publication using authorized npm-owner authentication
|
|
153
|
-
before package settings/trusted publishing are available. npm name availability
|
|
154
|
-
has not been established by creating a GitHub repository. The owner must confirm
|
|
155
|
-
the current bootstrap flow and explicitly authorize it. Do not place bootstrap
|
|
156
|
-
tokens in PR workflows or temporarily make publication unconditional.
|
|
157
|
-
|
|
158
|
-
Prepare a license/version-ready candidate, run the exact full verification graph,
|
|
159
|
-
retain/download the unchanged manifest/tarball and verify its digest. If the first
|
|
160
|
-
publication must be manual, an authorized owner uses their own current npm login/
|
|
161
|
-
2FA or narrowly scoped supported bootstrap credential to publish those exact bytes,
|
|
162
|
-
then removes temporary credentials and configures the trusted publisher. Record
|
|
163
|
-
the resulting version/integrity/provenance. A dry run is not proof of bootstrap
|
|
164
|
-
permissions or production OIDC authentication. Current 0.1.0 candidates have public-ready metadata, but publication still
|
|
165
|
-
requires all exact-byte checks, owner settings and separate authorization.
|
|
166
|
-
|
|
167
|
-
## Package order, existing versions and partial recovery
|
|
168
|
-
|
|
169
|
-
Release by actual production dependencies: client and server are independent;
|
|
170
|
-
either SDK can publish first. Publish the client before a CLI version requiring
|
|
171
|
-
that exact client version. The CLI registry guard requires the published client's
|
|
172
|
-
dist.integrity to match its tested candidate tarball. If it differs, stop and
|
|
173
|
-
reconcile/retest the actual dependency; do not silently replace tested bytes.
|
|
174
|
-
|
|
175
|
-
Before publishing, npm view must confirm that this package version is absent.
|
|
176
|
-
Only a structured E404 is considered absent; auth/network/registry failures stop.
|
|
177
|
-
An existing version stops publication even after an uncertain earlier response.
|
|
178
|
-
Inspect npm's published version, integrity, provenance and intended dist-tag using
|
|
179
|
-
read-only registry commands. Never overwrite or blindly republish. If the exact
|
|
180
|
-
bytes already published, record that success and resume the remaining package's
|
|
181
|
-
separate verified release. Multi-repository releases are not atomic. Do not unpublish
|
|
182
|
-
a successful dependency as rollback. If correction is required, choose a new
|
|
183
|
-
version, update dependent pins/lockfiles/release notes and verify a new candidate.
|
|
184
|
-
|
|
185
|
-
This runbook does not authorize publication, tag pushes, package ownership changes,
|
|
186
|
-
external settings, deployment or demo implementation.
|
|
187
|
-
|
|
188
|
-
Candidate metadata is inspected with the archive basename and its directory as
|
|
189
|
-
`cwd`. This avoids GNU tar interpreting a Windows drive colon as a remote archive;
|
|
190
|
-
stderr is preserved in failure diagnostics. Negative checks exercise GNU tar on
|
|
191
|
-
Windows with space/Unicode candidate paths and retain wrong/missing/changed bytes
|
|
192
|
-
and fail-closed gate cases. Local success does not certify a future hosted run or
|
|
193
|
-
any newly packed bytes.
|
|
1
|
+
# Releasing
|
|
2
|
+
|
|
3
|
+
Use the tagged GitHub Actions workflow, not a local rebuild. Packages are MIT;
|
|
4
|
+
0.1.0 was manually bootstrapped. Version 0.1.1 refreshes documentation without
|
|
5
|
+
changing runtime APIs. Each new version needs its own source/artifact evidence.
|
|
6
|
+
|
|
7
|
+
## Before tagging
|
|
8
|
+
|
|
9
|
+
- Confirm npm ownership, unused versions, supported Node 24.12.0 and npm>=11.5.1.
|
|
10
|
+
Keep the pinned compiler/dependencies; do not upgrade tooling during a release.
|
|
11
|
+
- Update version, changelog and shipped docs. CLI's client dependency and both
|
|
12
|
+
candidate JSON files must match exact final SDK versions/full source SHAs.
|
|
13
|
+
- Review the full diff and run typecheck, build, tests and documentation checks.
|
|
14
|
+
Preserve the existing API/storage/security contracts and historical evidence.
|
|
15
|
+
- Protect source, workflow files, pins and release tags with repository review/rules.
|
|
16
|
+
All actions are commit-pinned; release verification never restores a PR cache.
|
|
17
|
+
- Verify GitHub environment **npm**: variable **NPM_PUBLISH_ENABLED=true**,
|
|
18
|
+
intended required reviewer, no admin bypass, and allowed deployment tags **v***.
|
|
19
|
+
Reviewers approve the real pending deployment; automation must not approve for them.
|
|
20
|
+
- Configure the npm package's GitHub trusted publisher: owner **LMol-4**, this
|
|
21
|
+
package repository, workflow **release.yml**, environment **npm**. Match case.
|
|
22
|
+
Enable **direct npm publish** permission; this workflow does not stage a publish.
|
|
23
|
+
Configure near the release: unused configurations expire after two days. Public
|
|
24
|
+
source/package visibility and supported GitHub-hosted runners are required for
|
|
25
|
+
this provenance path. Do not supply NODE_AUTH_TOKEN or fall back to a long-lived
|
|
26
|
+
token if OIDC fails. Confirm current [npm requirements](https://docs.npmjs.com/trusted-publishers/).
|
|
27
|
+
|
|
28
|
+
## Publish exact tagged source
|
|
29
|
+
|
|
30
|
+
Client and server are independent. Publish client before CLI: the CLI registry
|
|
31
|
+
guard requires its tested client tarball integrity to equal the published one.
|
|
32
|
+
|
|
33
|
+
1. Merge reviewed source to main. Record the full SHA and create/push an approved
|
|
34
|
+
immutable **vVERSION** tag at that exact commit. Never move or replace a tag.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
git tag vVERSION FULL_SHA
|
|
38
|
+
git push origin refs/tags/vVERSION
|
|
39
|
+
```
|
|
40
|
+
2. Dispatch **Release** from that tag, with matching version, tag and full commit.
|
|
41
|
+
Optional `publish=false` rehearses verification only. A later publishing dispatch
|
|
42
|
+
is a new run with newly identified artifacts; it does not reuse a rehearsal's bytes.
|
|
43
|
+
3. Dispatch with `publish=true` when authorized. Example (replace all placeholders):
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
gh workflow run release.yml --repo LMol-4/PACKAGE --ref vVERSION -f version=VERSION -f tag=vVERSION -f commit=FULL_SHA -f publish=true
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
4. Wait for candidate, fast, contracts, integration, packaged-linux/windows/macos,
|
|
50
|
+
validation and gate to succeed. Missing, failed, canceled or skipped prerequisites
|
|
51
|
+
fail closed. Then follow the Actions environment-approval link. Do not bypass it.
|
|
52
|
+
5. The publisher rechecks source/tag/ref/version, trusted manifest digest, unchanged
|
|
53
|
+
tarball metadata/bytes, owner enablement, registry absence and dependency integrity.
|
|
54
|
+
It publishes the same-run tested tarball with `--access public --provenance
|
|
55
|
+
--ignore-scripts`; it never installs, builds or packs again.
|
|
56
|
+
6. Save run URL, full source SHAs, manifest SHA256, filenames, versions, byte counts,
|
|
57
|
+
tarball SHA256/npm SHA512 and registry integrity/provenance. Download before the
|
|
58
|
+
14-day candidate retention expires. Verify registry bytes, a clean exact-version
|
|
59
|
+
registry install, exported modules and the real npm CLI shim.
|
|
60
|
+
|
|
61
|
+
Ordinary main/tag CI is useful evidence but is not a tagged Release/OIDC publishing
|
|
62
|
+
run. A dry run or green tests alone do not prove npm authentication or provenance.
|
|
63
|
+
The separate checked test-harness artifact is source/output-hash bound, used only
|
|
64
|
+
by unprivileged verification jobs, and never published in an npm package.
|
|
65
|
+
|
|
66
|
+
## Failure and partial release
|
|
67
|
+
|
|
68
|
+
Stop on tag/source/version/digest mismatch, unknown registry responses or changed
|
|
69
|
+
client integrity. Do not weaken gates, repack approved bytes, change pins silently,
|
|
70
|
+
force an overwrite or use a token fallback. Inspect the failed job and preserve logs.
|
|
71
|
+
For OIDC/auth failure check publisher spelling/case, workflow/environment identity,
|
|
72
|
+
expiry, reviewer approval, permissions and npm/toolchain support before a new run.
|
|
73
|
+
|
|
74
|
+
If a version already exists, compare its registry integrity and provenance with the
|
|
75
|
+
saved receipt. Matching successful publication is recorded, never republished.
|
|
76
|
+
For partial publication, finish only absent packages; verify the published client's
|
|
77
|
+
exact bytes before CLI. If bytes differ or a fix is needed, use a reviewed new
|
|
78
|
+
version and complete verification. A source checkout rollback cannot undo an npm
|
|
79
|
+
publication or external side effect. Deprecation, dist-tag changes, unpublish and
|
|
80
|
+
replacement versions need separate owner authorization; never delete evidence.
|
|
81
|
+
|
|
82
|
+
## Verification limits
|
|
83
|
+
|
|
84
|
+
Deterministic source suites run once per verification graph on Linux; exhaustive
|
|
85
|
+
file groups reject omissions/duplicates. Packaged jobs test actual installed JS,
|
|
86
|
+
exports/declarations/content/SQLite and representative platform behavior; CLI also
|
|
87
|
+
tests real shims, auth/retry processes and API/browser/feedback wiring. They do not
|
|
88
|
+
certify a production keyring, physical terminal, browser engine, KMS or TLS deployment.
|
|
89
|
+
Windows GNU tar is given archive basename plus directory cwd to avoid drive-colon
|
|
90
|
+
remote parsing. Failure logs retain seven days. Expired/missing artifacts require a
|
|
91
|
+
new full run, not relabeling old results. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
package/SECURITY.md
CHANGED
|
@@ -4,10 +4,10 @@ Do not put credentials, tokens, private keys, personal records or exploit detail
|
|
|
4
4
|
in a public issue. Use this repository's GitHub **Security → Report a vulnerability**
|
|
5
5
|
when private reporting is enabled. If it is unavailable, request a private contact
|
|
6
6
|
from the repository owner without disclosing the vulnerability publicly. The owner
|
|
7
|
-
must enable/confirm that route
|
|
7
|
+
must enable/confirm that route; no response SLA is promised.
|
|
8
8
|
|
|
9
9
|
Include affected commit/version, a minimal reproduction using synthetic data,
|
|
10
|
-
impact and the trust boundary involved. These
|
|
11
|
-
|
|
10
|
+
impact and the trust boundary involved. These draft packages have no promised
|
|
11
|
+
support window or response SLA. Custom vaults, issuers, browser controllers,
|
|
12
12
|
proxy routing and deployment policy remain operator responsibilities. Redaction
|
|
13
13
|
and scoped authority do not isolate an unrestricted same-user program.
|
package/STORAGE.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# Company persistence and authorization
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
breaking adapter change in an unpublished package. Node 24.12.0 or later is required.
|
|
3
|
+
Request paths use targeted domain selections, not whole-state rewrites. Node 24.12.0 or later is required.
|
|
5
4
|
The optional `@poppykit/server/sqlite` entry point exports `SqliteCompanyDatabase`.
|
|
6
5
|
The core and reference issuer entry points do not import SQLite. Consumers can
|
|
7
6
|
implement `ConversationStore`, `IssuerStore` and `AuthorityCoordinator` themselves.
|
|
@@ -46,10 +45,8 @@ still apply inside the SDK; a namespace name alone is not authentication.
|
|
|
46
45
|
Conversation selections resolve an ID, message receipt, work ID, or next eligible
|
|
47
46
|
claim. Reads include the related parent/Direct Conversation binding group, not
|
|
48
47
|
unrelated conversations. A worker query selects the oldest eligible message for a
|
|
49
|
-
conversation; publication rechecks lease and fence.
|
|
50
|
-
|
|
51
|
-
notification-backed waits, streaming and retention; this does not claim those jobs
|
|
52
|
-
are complete. `ConversationNotifications` defines subscribe/unsubscribe/publish:
|
|
48
|
+
conversation; publication rechecks lease and fence. Cursor-relative event selectors bound delivery reads without loading work/history
|
|
49
|
+
aggregates. `ConversationNotifications` defines subscribe/unsubscribe/publish:
|
|
53
50
|
subscribe before reading, treat wakes as hints, and always reconcile durable state
|
|
54
51
|
after a wake or bounded timeout. Publishing after commit is best-effort, not an outbox.
|
|
55
52
|
|
|
@@ -75,8 +72,8 @@ an uncertain result for reconciliation. Never claim universal exactly-once execu
|
|
|
75
72
|
|
|
76
73
|
`cleanup(namespace, now, limit)` bounds deletion to at most 1000 expired short-lived
|
|
77
74
|
codes, authorizations, access tokens or replay entries. It does not delete grants,
|
|
78
|
-
work intent, message receipts or conversation events.
|
|
79
|
-
|
|
75
|
+
work intent, message receipts or conversation events. Receipt identity remains
|
|
76
|
+
through retention for the conversation lifetime. Finished work pruning is
|
|
80
77
|
per selected conversation binding group; unrelated conversation growth cannot
|
|
81
78
|
force another conversation's receipts out of storage.
|
|
82
79
|
|
|
@@ -92,12 +89,8 @@ development reset, stop all processes, resolve uncertain external effects, and
|
|
|
92
89
|
explicitly move aside the database and WAL/SHM files. Reopen a fresh database to
|
|
93
90
|
obtain new generations. Never reset a live database behind active processes.
|
|
94
91
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
also checks publication fencing/deduplication, detached values, rollback, account
|
|
98
|
-
token rotation versus revocation, namespace isolation, and unchanged read counts
|
|
99
|
-
after adding unrelated conversations. These are local Windows/Node results;
|
|
100
|
-
other OS runner evidence belongs to J5/J6.
|
|
92
|
+
Contract tests cover real process contention/death, publication fences, rotation/
|
|
93
|
+
revocation, rollback, isolation and targeted read counts; see [contributing](CONTRIBUTING.md).
|
|
101
94
|
|
|
102
95
|
## Bounded conversation delivery and retention
|
|
103
96
|
|
|
@@ -117,3 +110,71 @@ state. Default payload retention is indefinite; operators should retain at least
|
|
|
117
110
|
30 days and explicitly choose any shorter policy. See [DELIVERY.md](DELIVERY.md)
|
|
118
111
|
for distinct lifetimes and client recovery behavior. No automatic destructive
|
|
119
112
|
reset or history deletion was added.
|
|
113
|
+
|
|
114
|
+
## Postgres
|
|
115
|
+
|
|
116
|
+
`@poppykit/server/postgres` ships `PostgresCompanyDatabase`, explicit migrations,
|
|
117
|
+
and `createPostgresPool` in this package. Install optional peer `pg@8.23.1` when
|
|
118
|
+
using that subpath. Core/reference-auth imports load neither database driver.
|
|
119
|
+
Supported baseline: Node 24.12+, PostgreSQL 17, including Supabase transaction pooling.
|
|
120
|
+
No application, Google login or Supabase Auth dependency is required.
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { createPostgresPool, migratePostgres,
|
|
124
|
+
PostgresCompanyDatabase } from '@poppykit/server/postgres';
|
|
125
|
+
const pool = createPostgresPool({ connectionString: process.env.DATABASE_URL });
|
|
126
|
+
// Explicit operator/deployment migration; do this before handling requests.
|
|
127
|
+
await migratePostgres(pool, 'poppy_server');
|
|
128
|
+
const database = new PostgresCompanyDatabase(pool);
|
|
129
|
+
const issuerStore = database.issuer('https://company.example/issuer');
|
|
130
|
+
const conversationStore = database.conversations('https://company.example/issuer');
|
|
131
|
+
// Reference issuer: store: issuerStore, coordinator: database.
|
|
132
|
+
// Conversation service: store: conversationStore, policy: issuer.authority.policy.
|
|
133
|
+
await database.close(); // after in-flight requests end; leaves caller pool open
|
|
134
|
+
await pool.end();
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Use one database object for issuer/coordinator/conversations. `withTransaction`
|
|
138
|
+
passes a generic query connection to host DB work inside that same transaction:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
await issuer.authority.policy.withCurrent(principal, ['records:write'], () =>
|
|
142
|
+
database.withTransaction(async connection => {
|
|
143
|
+
await connection.query('UPDATE application.records SET value=$1 WHERE owner=$2',
|
|
144
|
+
[validatedValue, trustedAccountId]);
|
|
145
|
+
}));
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The policy holds the issuer authority fence through commit; revocation waits or
|
|
149
|
+
wins before mutation. The host must still validate ownership, payload digests,
|
|
150
|
+
current business revisions and its own idempotency receipts. Issuer namespace
|
|
151
|
+
metadata and per-conversation binding/message locks use transaction-scoped advisory
|
|
152
|
+
locks, including absent keys; no process mutex or session lock substitutes for them.
|
|
153
|
+
Nested mutations use savepoints. Await nested mutations sequentially: overlapping
|
|
154
|
+
siblings reject explicitly, while recursion is supported. Escaped query handles
|
|
155
|
+
reject after their scope ends. External model/network/KMS calls belong outside this
|
|
156
|
+
boundary. Fences do not make arbitrary external effects exactly-once.
|
|
157
|
+
|
|
158
|
+
Pool defaults are max 2, acquisition 3s/idle 10s, verified TLS; configure a trusted
|
|
159
|
+
CA through `ssl`, never insecure TLS URL overrides. Explicit `ssl:false` is for a
|
|
160
|
+
trusted local test server. Caller-created pools remain their owner's responsibility.
|
|
161
|
+
Transactions/statements are bounded to 5s, lock waits 2s, with unnamed parameterized
|
|
162
|
+
queries and one checkout from BEGIN to COMMIT/ROLLBACK. No LISTEN, named prepares
|
|
163
|
+
or session state is required. `close` never closes a caller-supplied pool; callers
|
|
164
|
+
of `createPostgresPool` own and must end that pool.
|
|
165
|
+
|
|
166
|
+
Immutable SQL ships at `migrations/postgres/0001_poppy_server.sql`.
|
|
167
|
+
`postgresMigration('poppy_server')` returns reviewable SQL and
|
|
168
|
+
`migratePostgres(pool,'poppy_server')` is the explicit atomic apply/version check.
|
|
169
|
+
No constructor/request-time DDL or automatic SQLite import/reset exists. Unknown or
|
|
170
|
+
missing versions fail closed. Version 1 does not certify arbitrary manual table
|
|
171
|
+
edits: inspect migration history and reconcile drift before applying new versions.
|
|
172
|
+
Applied migrations are immutable, corrections require new versioned files. Back up,
|
|
173
|
+
review and rehearse live changes; roll application code back only to compatible
|
|
174
|
+
schemas, or restore a reviewed backup for destructive reversal. No populated-schema
|
|
175
|
+
drop/downgrade is automated. The disposable test runner is development tooling,
|
|
176
|
+
never a production migration command.
|
|
177
|
+
|
|
178
|
+
`runIssuerAdapterContract` joins the existing reusable conversation contract in
|
|
179
|
+
`@poppykit/server/adapter-contract`. Run both against two fresh shared handles;
|
|
180
|
+
process death, lock ordering and DB durability still require backend-specific tests.
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { ConversationOptions } from './conversation/service.js';
|
|
2
|
+
import type { IssuerStore } from './reference-auth/store.js';
|
|
3
|
+
export type IssuerAdapterFixture = () => Promise<{
|
|
4
|
+
store: IssuerStore;
|
|
5
|
+
second: IssuerStore;
|
|
6
|
+
close(): Promise<void>;
|
|
7
|
+
}>;
|
|
8
|
+
/** A fresh shared namespace, including absent-row serialization; no vendor-specific fixture is required. */
|
|
9
|
+
export declare function runIssuerAdapterContract(fixture: IssuerAdapterFixture): void;
|
|
2
10
|
type Store = ConversationOptions['store'] & {
|
|
3
11
|
inspect(): Promise<import('./conversation/service.js').ConversationStoreState>;
|
|
4
12
|
adminTransaction<T>(change: (draft: import('./conversation/service.js').ConversationStoreState) => T): Promise<T>;
|
package/dist/adapter-contract.js
CHANGED
|
@@ -5,6 +5,24 @@ import test from 'node:test';
|
|
|
5
5
|
import assert from 'node:assert/strict';
|
|
6
6
|
import { AuthorityError } from './auth/authority.js';
|
|
7
7
|
import { createConversationService, resetConversationState } from './conversation/service.js';
|
|
8
|
+
/** A fresh shared namespace, including absent-row serialization; no vendor-specific fixture is required. */
|
|
9
|
+
export function runIssuerAdapterContract(fixture) {
|
|
10
|
+
test('issuer adapter contract: replay updates serialize, snapshots detach and failed callbacks roll back', async () => {
|
|
11
|
+
const f = await fixture(), selection = { kind: 'browser', sessionId: 'absent', replayKey: 'counter' };
|
|
12
|
+
try {
|
|
13
|
+
await Promise.all(Array.from({ length: 10 }, (_, i) => (i % 2 ? f.store : f.second).transaction(selection, state => { state.replay.counter = (state.replay.counter ?? 0) + 1; })));
|
|
14
|
+
const state = await f.store.read(selection);
|
|
15
|
+
assert.equal(state.replay.counter, 10);
|
|
16
|
+
state.replay.counter = 999;
|
|
17
|
+
await assert.rejects(f.store.transaction(selection, draft => { draft.replay.counter = 0; throw new Error('rollback'); }), /rollback/);
|
|
18
|
+
await assert.rejects(f.store.transaction(selection, async (draft) => { draft.replay.counter = 0; }));
|
|
19
|
+
assert.equal((await f.second.read(selection)).replay.counter, 10);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
await f.close();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
8
26
|
const endpoint = 'https://contract.example.test/poppy/conversations';
|
|
9
27
|
const base = { issuer: 'https://auth.contract.test', clientId: 'https://agent.contract.test/client', sessionId: 's1', userId: 'u_1', scopes: [], tokenExpiresAt: 9e12, sessionVersion: 1 };
|
|
10
28
|
const principals = {
|
|
@@ -51,6 +69,18 @@ export function runConversationAdapterContract(fixture) {
|
|
|
51
69
|
await opened.close();
|
|
52
70
|
}
|
|
53
71
|
}
|
|
72
|
+
test('adapter contract: concurrent conflicting output retries publish one immutable result', () => withFixture(async ({ store, second }) => {
|
|
73
|
+
const a = serviceOn(store, clock), b = serviceOn(second, clock);
|
|
74
|
+
const id = (await call(a, '', 'signedOut', { message })).body.conversation_id;
|
|
75
|
+
const work = (await a.claim());
|
|
76
|
+
const results = await Promise.allSettled([a.reply(work, 'same-call', reply), b.reply(work, 'same-call', { ...reply, text: 'conflicting result' })]);
|
|
77
|
+
assert.equal(results.filter(result => result.status === 'fulfilled').length, 1);
|
|
78
|
+
const failed = results.find(result => result.status === 'rejected');
|
|
79
|
+
assert.ok(failed && failed.status === 'rejected');
|
|
80
|
+
assert.equal(failed.reason.code, 'output_conflict');
|
|
81
|
+
const events = (await call(a, `/${id}/events`, 'signedOut')).body.events;
|
|
82
|
+
assert.equal(events.filter(event => event.message?.id === reply.id).length, 1);
|
|
83
|
+
}));
|
|
54
84
|
test('adapter contract: reads and results are detached; failed, non-JSON and async changes roll back', () => withFixture(async ({ store, second }) => {
|
|
55
85
|
const snapshot = await store.inspect();
|
|
56
86
|
snapshot.bindings.leaked = {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Pool, PoolConfig, QueryResult, QueryResultRow } from 'pg';
|
|
2
|
+
export type PostgresSchema = 'poppy_client' | 'poppy_provider' | 'poppy_server';
|
|
3
|
+
export type PostgresConnection = {
|
|
4
|
+
query<R extends QueryResultRow = QueryResultRow>(sql: string, values?: unknown[]): Promise<QueryResult<R>>;
|
|
5
|
+
};
|
|
6
|
+
export declare function json(value: unknown): string;
|
|
7
|
+
export declare function synchronous<T>(value: T): T;
|
|
8
|
+
/** Remote defaults verify TLS; plaintext must be explicitly selected for a trusted local test server. */
|
|
9
|
+
export declare function createPostgresPool(config: PoolConfig): Pool;
|
|
10
|
+
export declare const postgresSchemaVersion = 1;
|
|
11
|
+
export declare function postgresMigration(schema: PostgresSchema): Promise<string>;
|
|
12
|
+
/** Explicit administration only. Constructors never execute DDL. */
|
|
13
|
+
export declare function migratePostgres(pool: Pool, schema: PostgresSchema): Promise<void>;
|
|
14
|
+
export declare class PostgresRuntime {
|
|
15
|
+
readonly pool: Pool;
|
|
16
|
+
readonly schema: PostgresSchema;
|
|
17
|
+
private readonly ownsPool;
|
|
18
|
+
private readonly context;
|
|
19
|
+
private closed;
|
|
20
|
+
readonly metrics: {
|
|
21
|
+
rowsRead: number;
|
|
22
|
+
rowsWritten: number;
|
|
23
|
+
};
|
|
24
|
+
constructor(pool: Pool, schema: PostgresSchema, ownsPool?: boolean);
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
run<T>(action: () => Promise<T>): Promise<T>;
|
|
27
|
+
connection(): PostgresConnection;
|
|
28
|
+
query<R extends QueryResultRow = QueryResultRow>(sql: string, values?: unknown[]): Promise<R[]>;
|
|
29
|
+
lock(key: string): Promise<void>;
|
|
30
|
+
}
|