@veriforms/webapp-sdk 0.1.0 → 0.1.2
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 +26 -4
- package/config.schema.json +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/serverClient.d.ts +28 -3
- package/dist/serverClient.js +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,10 +129,13 @@ save entries`). Real data and real writes are on the test version.
|
|
|
129
129
|
|
|
130
130
|
## Server functions — PILOT, PLATFORM ADMINISTRATORS ONLY
|
|
131
131
|
|
|
132
|
-
>
|
|
133
|
-
>
|
|
134
|
-
>
|
|
135
|
-
> (
|
|
132
|
+
> Only a **platform administrator** may push and release server functions — for a web app in any
|
|
133
|
+
> account, customer accounts included (owner decision 2026-12-03: VeriForms builds customer solutions
|
|
134
|
+
> as a consulting offer). A version runs its functions only when an administrator released it, and
|
|
135
|
+
> only while the platform has them switched on (it is **off in production**). For everyone else — the
|
|
136
|
+
> app's owner included — a build with `server/` is refused (`bundle_server_code_not_enabled`), and so
|
|
137
|
+
> is publishing, restoring or promoting a version that carries one (`server_functions_not_enabled`):
|
|
138
|
+
> push a build without `server/`, or ask the VeriForms team to release it. Not part of the public docs. Concept:
|
|
136
139
|
> `docs/webapp-builder/CWA-CODE-BACKEND-CONCEPT.md`; decisions: `CWA-DECISIONS.md`
|
|
137
140
|
> ("Server functions, the developer side").
|
|
138
141
|
|
|
@@ -176,6 +179,8 @@ try {
|
|
|
176
179
|
}
|
|
177
180
|
```
|
|
178
181
|
|
|
182
|
+
- **No input:** a function defined without `input` is called with no argument — `await server.listMyQuotes()`
|
|
183
|
+
(sent as `null`; since 0.1.1). A function with an `input` schema still needs its input.
|
|
179
184
|
- **Routes:** the export name in camelCase is served in kebab-case — `placeOrder` → `/fn/place-order`
|
|
180
185
|
(the build writes `export { placeOrder as "place-order" }`).
|
|
181
186
|
- **The gateway reads the definition statically:** an object literal, `sources` as quoted names, `input`
|
|
@@ -194,6 +199,23 @@ try {
|
|
|
194
199
|
Every refusal rejects with `ServerFunctionError` (`code`, `status`, `message` / `messageDe` /
|
|
195
200
|
`messageEn`, `runId`; `kind === 'server_function_refused'` for `ctx.refuse`); no answer at all is
|
|
196
201
|
`code: 'network'` with `outcome: 'unknown'` — resend with the same `idempotencyKey`.
|
|
202
|
+
- **"No access" is not "failed" (since 0.1.2):** `e.accessRefused` (or `isServerFunctionAccessRefusal(e)`)
|
|
203
|
+
is true when the VISITOR may not do this — not signed in (`server_function_sign_in_required`), or a data
|
|
204
|
+
source refused them by access (`server_function_source_refused` with `access: true`: 401/403, e.g.
|
|
205
|
+
`sourceCode: 'row_rule_missing'` — the source has row rules only for roles the visitor does not hold).
|
|
206
|
+
Then `e.source`, `e.sourceStatus`, `e.sourceCode` and `e.sourceMessageDe` / `e.sourceMessageEn` say which
|
|
207
|
+
source and why; show "no access" (or a sign-in) there, never a calculation error. Every other code is a
|
|
208
|
+
fault of the function or a source. Every answer of the route — its own gates too (wrong host, JSON only,
|
|
209
|
+
link password, app misconfigured) — has the same shape: `code`, `message`, `messageDe`, `messageEn`.
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
try { setQuotes(await server.listMyQuotes()); }
|
|
213
|
+
catch (e) {
|
|
214
|
+
if (isServerFunctionAccessRefusal(e)) showNoAccess(lang === 'en' ? e.sourceMessageEn ?? e.messageEn : e.sourceMessageDe ?? e.messageDe);
|
|
215
|
+
else if (isServerFunctionError(e)) showFailure(e.message, e.runId);
|
|
216
|
+
else throw e;
|
|
217
|
+
}
|
|
218
|
+
```
|
|
197
219
|
- **A newer release (X9):** `409 server_function_version_changed` reloads the page (once per build) and
|
|
198
220
|
rejects with `ServerFunctionVersionChangedError`; the old code never runs.
|
|
199
221
|
- **Types:** the plugin writes `vf-server.d.ts` (input and answer of every function, from its
|
package/config.schema.json
CHANGED
|
@@ -323,7 +323,7 @@
|
|
|
323
323
|
"callableFrom": {
|
|
324
324
|
"type": "string",
|
|
325
325
|
"enum": ["server"],
|
|
326
|
-
"description": "\"server\": only the app's server functions may call this source, not the page directly (server functions are in a pilot
|
|
326
|
+
"description": "\"server\": only the app's server functions may call this source, not the page directly (server functions are in a pilot: only platform administrators push and release them). Absent = page and server functions."
|
|
327
327
|
},
|
|
328
328
|
"anyoneMayRun": {
|
|
329
329
|
"type": "string",
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/serverClient.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export declare const INPUT_SCHEMA_TYPES: readonly ["object", "array", "string",
|
|
|
33
33
|
* the two lists equal). An author's own refusal (`ctx.refuse`) keeps the author's code and has
|
|
34
34
|
* `kind === 'server_function_refused'`.
|
|
35
35
|
*/
|
|
36
|
-
export declare const SERVER_FUNCTION_CODES: readonly ["server_functions_off", "server_functions_not_enabled", "server_function_unavailable", "server_function_not_found", "server_function_version_changed", "server_function_sign_in_required", "server_function_input_too_large", "server_function_input_invalid", "server_function_nesting_limit", "server_function_budget_exhausted", "server_function_busy", "server_function_breaker_open", "server_function_time_limit", "server_function_statement_limit", "server_function_allocation_limit", "server_function_stack_limit", "server_function_regex_limit", "server_function_forbidden", "server_function_too_many_data_calls", "server_function_source_undeclared", "server_function_source_unsupported", "server_function_source_timeout", "server_function_source_refused", "server_function_module_unknown", "server_function_output_too_large", "server_function_output_invalid", "server_function_failed", "server_function_refused", "server_function_partial", "server_manifest_mismatch"];
|
|
36
|
+
export declare const SERVER_FUNCTION_CODES: readonly ["server_functions_off", "server_functions_not_enabled", "server_function_unavailable", "server_function_not_found", "server_function_version_changed", "server_function_sign_in_required", "server_function_input_too_large", "server_function_input_invalid", "server_function_nesting_limit", "server_function_budget_exhausted", "server_function_busy", "server_function_breaker_open", "server_function_time_limit", "server_function_statement_limit", "server_function_allocation_limit", "server_function_stack_limit", "server_function_regex_limit", "server_function_forbidden", "server_function_too_many_data_calls", "server_function_source_undeclared", "server_function_source_unsupported", "server_function_source_timeout", "server_function_source_refused", "server_function_module_unknown", "server_function_output_too_large", "server_function_output_invalid", "server_function_failed", "server_function_refused", "server_function_partial", "server_manifest_mismatch", "server_function_cross_site", "server_function_json_only", "server_function_wrong_host", "server_function_instance_mismatch", "server_function_link_ended", "server_function_link_password_required", "server_function_app_misconfigured"];
|
|
37
37
|
export type ServerFunctionCode = typeof SERVER_FUNCTION_CODES[number];
|
|
38
38
|
/** The stub's own codes: the request never got an answer (`network`), or one that is not the gateway's JSON (`http_error`). */
|
|
39
39
|
export type ServerFunctionClientCode = 'network' | 'http_error';
|
|
@@ -57,6 +57,20 @@ export declare class ServerFunctionError extends Error {
|
|
|
57
57
|
readonly idempotencyKey: string;
|
|
58
58
|
/** The whole answer body (e.g. `completed` / `pending` of `server_function_partial`). */
|
|
59
59
|
readonly data: Record<string, unknown> | undefined;
|
|
60
|
+
/** `server_function_source_refused`: the data source that refused the function's call (its config key). */
|
|
61
|
+
readonly source: string | undefined;
|
|
62
|
+
/** `server_function_source_refused`: the source's own status (403) and code (`row_rule_missing`). */
|
|
63
|
+
readonly sourceStatus: number | undefined;
|
|
64
|
+
readonly sourceCode: string | undefined;
|
|
65
|
+
/** `server_function_source_refused` for an ACCESS refusal: what the source said, in both languages. */
|
|
66
|
+
readonly sourceMessageDe: string | undefined;
|
|
67
|
+
readonly sourceMessageEn: string | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* True when the visitor may not do this — not signed in (`server_function_sign_in_required`) or a source
|
|
70
|
+
* refused them by access (401/403: no role with a row rule, too low a level). Show "no access" / offer
|
|
71
|
+
* sign-in, never "the calculation failed". False for a fault of the function or a source.
|
|
72
|
+
*/
|
|
73
|
+
readonly accessRefused: boolean;
|
|
60
74
|
constructor(init: {
|
|
61
75
|
code: string;
|
|
62
76
|
message: string;
|
|
@@ -77,6 +91,11 @@ export declare class ServerFunctionVersionChangedError extends ServerFunctionErr
|
|
|
77
91
|
readonly reloading: boolean;
|
|
78
92
|
constructor(init: ConstructorParameters<typeof ServerFunctionError>[0], reloading: boolean);
|
|
79
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* True for a refusal of the VISITOR (not signed in, or a source refused them by access — e.g. a row rule only for
|
|
96
|
+
* roles they do not hold): show "no access" or offer sign-in, not "failed". See {@link ServerFunctionError.accessRefused}.
|
|
97
|
+
*/
|
|
98
|
+
export declare function isServerFunctionAccessRefusal(e: unknown): e is ServerFunctionError;
|
|
80
99
|
/** True for a {@link ServerFunctionError}, optionally of one code. */
|
|
81
100
|
export declare function isServerFunctionError(e: unknown, code?: ServerFunctionCode | ServerFunctionClientCode | string): e is ServerFunctionError;
|
|
82
101
|
/**
|
|
@@ -103,9 +122,15 @@ export interface CallOptions {
|
|
|
103
122
|
* error body.
|
|
104
123
|
*/
|
|
105
124
|
export declare function callServerFunction<N extends ServerFunctionName>(name: N, input?: InputOf<N>, opts?: CallOptions): Promise<OutputOf<N>>;
|
|
106
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* One function of the stub. A function WITHOUT an input schema takes no input (its input type is `unknown`),
|
|
127
|
+
* so the argument is optional: `server.listMyQuotes()` — sent as `null`, exactly like `callServerFunction(name)`.
|
|
128
|
+
* A function with a schema keeps its input required (unless the schema's type itself admits `undefined`).
|
|
129
|
+
*/
|
|
130
|
+
export type ServerStubFunction<I, O> = unknown extends I ? (input?: I, opts?: CallOptions) => Promise<O> : undefined extends I ? (input?: I, opts?: CallOptions) => Promise<O> : (input: I, opts?: CallOptions) => Promise<O>;
|
|
131
|
+
/** The typed stub: `server.placeOrder(input)` is `callServerFunction('placeOrder', input)`; `server.ping()` needs no input. */
|
|
107
132
|
export type ServerStub = {
|
|
108
|
-
[N in keyof ServerFunctionRegistry & string]:
|
|
133
|
+
[N in keyof ServerFunctionRegistry & string]: ServerStubFunction<InputOf<N>, OutputOf<N>>;
|
|
109
134
|
} & (Registered extends true ? unknown : Record<string, (input?: unknown, opts?: CallOptions) => Promise<unknown>>);
|
|
110
135
|
export declare const server: ServerStub;
|
|
111
136
|
export {};
|
package/dist/serverClient.js
CHANGED
|
@@ -65,6 +65,13 @@ export const SERVER_FUNCTION_CODES = [
|
|
|
65
65
|
'server_function_refused',
|
|
66
66
|
'server_function_partial',
|
|
67
67
|
'server_manifest_mismatch',
|
|
68
|
+
'server_function_cross_site',
|
|
69
|
+
'server_function_json_only',
|
|
70
|
+
'server_function_wrong_host',
|
|
71
|
+
'server_function_instance_mismatch',
|
|
72
|
+
'server_function_link_ended',
|
|
73
|
+
'server_function_link_password_required',
|
|
74
|
+
'server_function_app_misconfigured',
|
|
68
75
|
];
|
|
69
76
|
/**
|
|
70
77
|
* A refused or failed server-function call. `message` is the gateway's sentence in the visitor's language;
|
|
@@ -85,6 +92,15 @@ export class ServerFunctionError extends Error {
|
|
|
85
92
|
this.outcome = init.outcome;
|
|
86
93
|
this.idempotencyKey = init.idempotencyKey;
|
|
87
94
|
this.data = init.data;
|
|
95
|
+
const d = init.data ?? {};
|
|
96
|
+
const str = (k) => (typeof d[k] === 'string' ? d[k] : undefined);
|
|
97
|
+
this.source = str('source');
|
|
98
|
+
this.sourceStatus = typeof d.sourceStatus === 'number' ? d.sourceStatus : undefined;
|
|
99
|
+
this.sourceCode = str('sourceCode');
|
|
100
|
+
this.sourceMessageDe = str('sourceMessageDe');
|
|
101
|
+
this.sourceMessageEn = str('sourceMessageEn');
|
|
102
|
+
this.accessRefused = init.code === 'server_function_sign_in_required'
|
|
103
|
+
|| (init.code === 'server_function_source_refused' && d.access === true);
|
|
88
104
|
}
|
|
89
105
|
}
|
|
90
106
|
/** 409 `server_function_version_changed`: the page is out of date; the stub has started a reload (unless it already did for this build). */
|
|
@@ -95,6 +111,13 @@ export class ServerFunctionVersionChangedError extends ServerFunctionError {
|
|
|
95
111
|
this.reloading = reloading;
|
|
96
112
|
}
|
|
97
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* True for a refusal of the VISITOR (not signed in, or a source refused them by access — e.g. a row rule only for
|
|
116
|
+
* roles they do not hold): show "no access" or offer sign-in, not "failed". See {@link ServerFunctionError.accessRefused}.
|
|
117
|
+
*/
|
|
118
|
+
export function isServerFunctionAccessRefusal(e) {
|
|
119
|
+
return e instanceof ServerFunctionError && e.accessRefused;
|
|
120
|
+
}
|
|
98
121
|
/** True for a {@link ServerFunctionError}, optionally of one code. */
|
|
99
122
|
export function isServerFunctionError(e, code) {
|
|
100
123
|
return e instanceof ServerFunctionError && (code === undefined || e.code === code);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veriforms/webapp-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Typed access to the VeriForms web app runtime (window.VF) for web apps built in code: data sources, tables, submissions, actions, payments, sign-in and pages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veriforms",
|