@veriforms/webapp-sdk 0.1.1 → 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 CHANGED
@@ -199,6 +199,23 @@ try {
199
199
  Every refusal rejects with `ServerFunctionError` (`code`, `status`, `message` / `messageDe` /
200
200
  `messageEn`, `runId`; `kind === 'server_function_refused'` for `ctx.refuse`); no answer at all is
201
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
+ ```
202
219
  - **A newer release (X9):** `409 server_function_version_changed` reloads the page (once per build) and
203
220
  rejects with `ServerFunctionVersionChangedError`; the old code never runs.
204
221
  - **Types:** the plugin writes `vf-server.d.ts` (input and answer of every function, from its
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@
15
15
  *
16
16
  * Concept: docs/webapp-builder/CWA-CODE-APPS-CONCEPT.md (§4.2).
17
17
  */
18
- export declare const SDK_VERSION = "0.1.1";
18
+ export declare const SDK_VERSION = "0.1.2";
19
19
  /**
20
20
  * Augmented by the `vf-app.d.ts` that `vf app types` generates:
21
21
  *
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@
15
15
  *
16
16
  * Concept: docs/webapp-builder/CWA-CODE-APPS-CONCEPT.md (§4.2).
17
17
  */
18
- export const SDK_VERSION = '0.1.1';
18
+ export const SDK_VERSION = '0.1.2';
19
19
  export function isVfRequestError(e) {
20
20
  return e instanceof Error;
21
21
  }
@@ -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
  /**
@@ -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.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",