@formancy/server-core 0.3.0 → 0.5.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/README.md +13 -2
- package/dist/index.d.mts +562 -157
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +531 -144
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -27,19 +27,30 @@ server gets argon2id and a CSPRNG.
|
|
|
27
27
|
## Use
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
|
-
import { publishForm, createSubmission, can } from '@formancy/server-core'
|
|
30
|
+
import { publishForm, formToFill, createSubmission, can } from '@formancy/server-core'
|
|
31
31
|
|
|
32
32
|
const published = await publishForm(deps, { path: 'contact-us', schema })
|
|
33
33
|
// publishForm is the save gate: structural validation, then the engine's own
|
|
34
34
|
// compile — a form that could loop is refused here and never persisted.
|
|
35
35
|
|
|
36
|
+
// What a respondent is handed: the current version, and the token its response is
|
|
37
|
+
// sent back with, so that a response sent twice is stored once.
|
|
38
|
+
const form = await formToFill(deps, 'contact-us')
|
|
39
|
+
|
|
36
40
|
const outcome = await createSubmission(deps, {
|
|
37
41
|
path: 'contact-us',
|
|
38
|
-
declaredSchemaHash:
|
|
42
|
+
declaredSchemaHash: form.schemaHash,
|
|
43
|
+
token: form.submissionToken,
|
|
39
44
|
data: payload,
|
|
40
45
|
})
|
|
46
|
+
// The same token again: { ok: false, kind: 'token_spent', id }, and nothing stored.
|
|
41
47
|
```
|
|
42
48
|
|
|
49
|
+
`publishForm`, `keepExamples` and `createSubmission` write their audit row inside
|
|
50
|
+
the transaction of what they record. Give them a `requestId` and the row names
|
|
51
|
+
that request, so it can be read beside a request log — `@formancy/server` passes
|
|
52
|
+
Fastify's request id. Without one, the row names none.
|
|
53
|
+
|
|
43
54
|
Authorization is one readable table (`can(actor, action)`), deliberately not
|
|
44
55
|
Postgres row-level security: RLS couples the application to per-request database
|
|
45
56
|
roles and hides authorization from the test suite.
|