@businessdash/sdk 0.9.60
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/LICENSE +21 -0
- package/README.md +899 -0
- package/dist/adapters-revalidate.d.ts +44 -0
- package/dist/adapters-revalidate.d.ts.map +1 -0
- package/dist/adapters-revalidate.js +68 -0
- package/dist/adapters-revalidate.js.map +1 -0
- package/dist/alpha.d.ts +21 -0
- package/dist/alpha.d.ts.map +1 -0
- package/dist/alpha.js +21 -0
- package/dist/alpha.js.map +1 -0
- package/dist/analytics-core.d.ts +34 -0
- package/dist/analytics-core.d.ts.map +1 -0
- package/dist/analytics-core.js +138 -0
- package/dist/analytics-core.js.map +1 -0
- package/dist/analytics-server.d.ts +54 -0
- package/dist/analytics-server.d.ts.map +1 -0
- package/dist/analytics-server.js +78 -0
- package/dist/analytics-server.js.map +1 -0
- package/dist/attribution-logo.d.ts +2 -0
- package/dist/attribution-logo.d.ts.map +1 -0
- package/dist/attribution-logo.js +5 -0
- package/dist/attribution-logo.js.map +1 -0
- package/dist/auth-handler.d.ts +92 -0
- package/dist/auth-handler.d.ts.map +1 -0
- package/dist/auth-handler.js +277 -0
- package/dist/auth-handler.js.map +1 -0
- package/dist/biab-forms.css +484 -0
- package/dist/cli.d.ts +46 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1824 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +1681 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +2845 -0
- package/dist/client.js.map +1 -0
- package/dist/collections.d.ts +13 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +13 -0
- package/dist/collections.js.map +1 -0
- package/dist/contracts.d.ts +14609 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +2428 -0
- package/dist/contracts.js.map +1 -0
- package/dist/data-model-schema.d.ts +962 -0
- package/dist/data-model-schema.d.ts.map +1 -0
- package/dist/data-model-schema.js +2295 -0
- package/dist/data-model-schema.js.map +1 -0
- package/dist/distribution.d.ts +38 -0
- package/dist/distribution.d.ts.map +1 -0
- package/dist/distribution.js +61 -0
- package/dist/distribution.js.map +1 -0
- package/dist/element.d.ts +121 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +276 -0
- package/dist/element.js.map +1 -0
- package/dist/enums.d.ts +25 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +38 -0
- package/dist/enums.js.map +1 -0
- package/dist/errors.d.ts +195 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +188 -0
- package/dist/errors.js.map +1 -0
- package/dist/forms-core/autocomplete.d.ts +37 -0
- package/dist/forms-core/autocomplete.d.ts.map +1 -0
- package/dist/forms-core/autocomplete.js +82 -0
- package/dist/forms-core/autocomplete.js.map +1 -0
- package/dist/forms-core/business-function.d.ts +61 -0
- package/dist/forms-core/business-function.d.ts.map +1 -0
- package/dist/forms-core/business-function.js +149 -0
- package/dist/forms-core/business-function.js.map +1 -0
- package/dist/forms-core/calculation.d.ts +72 -0
- package/dist/forms-core/calculation.d.ts.map +1 -0
- package/dist/forms-core/calculation.js +103 -0
- package/dist/forms-core/calculation.js.map +1 -0
- package/dist/forms-core/controller.d.ts +249 -0
- package/dist/forms-core/controller.d.ts.map +1 -0
- package/dist/forms-core/controller.js +590 -0
- package/dist/forms-core/controller.js.map +1 -0
- package/dist/forms-core/elements.d.ts +44 -0
- package/dist/forms-core/elements.d.ts.map +1 -0
- package/dist/forms-core/elements.js +68 -0
- package/dist/forms-core/elements.js.map +1 -0
- package/dist/forms-core/email-domains.d.ts +10 -0
- package/dist/forms-core/email-domains.d.ts.map +1 -0
- package/dist/forms-core/email-domains.js +69 -0
- package/dist/forms-core/email-domains.js.map +1 -0
- package/dist/forms-core/file-rules.d.ts +51 -0
- package/dist/forms-core/file-rules.d.ts.map +1 -0
- package/dist/forms-core/file-rules.js +105 -0
- package/dist/forms-core/file-rules.js.map +1 -0
- package/dist/forms-core/formula.d.ts +114 -0
- package/dist/forms-core/formula.d.ts.map +1 -0
- package/dist/forms-core/formula.js +1170 -0
- package/dist/forms-core/formula.js.map +1 -0
- package/dist/forms-core/index.d.ts +24 -0
- package/dist/forms-core/index.d.ts.map +1 -0
- package/dist/forms-core/index.js +28 -0
- package/dist/forms-core/index.js.map +1 -0
- package/dist/forms-core/units.d.ts +49 -0
- package/dist/forms-core/units.d.ts.map +1 -0
- package/dist/forms-core/units.js +255 -0
- package/dist/forms-core/units.js.map +1 -0
- package/dist/forms-core/us-states.d.ts +14 -0
- package/dist/forms-core/us-states.d.ts.map +1 -0
- package/dist/forms-core/us-states.js +66 -0
- package/dist/forms-core/us-states.js.map +1 -0
- package/dist/forms-core/validation.d.ts +266 -0
- package/dist/forms-core/validation.d.ts.map +1 -0
- package/dist/forms-core/validation.js +850 -0
- package/dist/forms-core/validation.js.map +1 -0
- package/dist/forms.d.ts +19 -0
- package/dist/forms.d.ts.map +1 -0
- package/dist/forms.js +29 -0
- package/dist/forms.js.map +1 -0
- package/dist/gallery-types.d.ts +32 -0
- package/dist/gallery-types.d.ts.map +1 -0
- package/dist/gallery-types.js +2 -0
- package/dist/gallery-types.js.map +1 -0
- package/dist/graphql.d.ts +97 -0
- package/dist/graphql.d.ts.map +1 -0
- package/dist/graphql.js +212 -0
- package/dist/graphql.js.map +1 -0
- package/dist/index.cjs +19448 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/marketing-schema.d.ts +216 -0
- package/dist/marketing-schema.d.ts.map +1 -0
- package/dist/marketing-schema.js +200 -0
- package/dist/marketing-schema.js.map +1 -0
- package/dist/mcp.d.ts +42 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +87 -0
- package/dist/mcp.js.map +1 -0
- package/dist/native.d.ts +45 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +43 -0
- package/dist/native.js.map +1 -0
- package/dist/next-revalidate.d.ts +43 -0
- package/dist/next-revalidate.d.ts.map +1 -0
- package/dist/next-revalidate.js +84 -0
- package/dist/next-revalidate.js.map +1 -0
- package/dist/parallel-pages.d.ts +102 -0
- package/dist/parallel-pages.d.ts.map +1 -0
- package/dist/parallel-pages.js +108 -0
- package/dist/parallel-pages.js.map +1 -0
- package/dist/payment-icons.d.ts +66 -0
- package/dist/payment-icons.d.ts.map +1 -0
- package/dist/payment-icons.js +160 -0
- package/dist/payment-icons.js.map +1 -0
- package/dist/proxy.d.ts +67 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +97 -0
- package/dist/proxy.js.map +1 -0
- package/dist/react-analytics.d.ts +39 -0
- package/dist/react-analytics.d.ts.map +1 -0
- package/dist/react-analytics.js +59 -0
- package/dist/react-analytics.js.map +1 -0
- package/dist/react-attribution.d.ts +99 -0
- package/dist/react-attribution.d.ts.map +1 -0
- package/dist/react-attribution.js +52 -0
- package/dist/react-attribution.js.map +1 -0
- package/dist/react-marketing.d.ts +181 -0
- package/dist/react-marketing.d.ts.map +1 -0
- package/dist/react-marketing.js +215 -0
- package/dist/react-marketing.js.map +1 -0
- package/dist/react.d.ts +727 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +2418 -0
- package/dist/react.js.map +1 -0
- package/dist/reserved-paths.d.ts +24 -0
- package/dist/reserved-paths.d.ts.map +1 -0
- package/dist/reserved-paths.js +60 -0
- package/dist/reserved-paths.js.map +1 -0
- package/dist/revalidate-verify.d.ts +30 -0
- package/dist/revalidate-verify.d.ts.map +1 -0
- package/dist/revalidate-verify.js +74 -0
- package/dist/revalidate-verify.js.map +1 -0
- package/dist/sdk.d.ts +678 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +801 -0
- package/dist/sdk.js.map +1 -0
- package/dist/seo.d.ts +218 -0
- package/dist/seo.d.ts.map +1 -0
- package/dist/seo.js +309 -0
- package/dist/seo.js.map +1 -0
- package/dist/socials.d.ts +47 -0
- package/dist/socials.d.ts.map +1 -0
- package/dist/socials.js +172 -0
- package/dist/socials.js.map +1 -0
- package/dist/static.d.ts +14 -0
- package/dist/static.d.ts.map +1 -0
- package/dist/static.js +14 -0
- package/dist/static.js.map +1 -0
- package/dist/url-pattern.d.ts +47 -0
- package/dist/url-pattern.d.ts.map +1 -0
- package/dist/url-pattern.js +124 -0
- package/dist/url-pattern.js.map +1 -0
- package/dist/vanilla.d.ts +77 -0
- package/dist/vanilla.d.ts.map +1 -0
- package/dist/vanilla.js +903 -0
- package/dist/vanilla.js.map +1 -0
- package/openapi.json +13779 -0
- package/package.json +204 -0
- package/src/adapters-revalidate.ts +88 -0
- package/src/alpha.ts +89 -0
- package/src/analytics-core.ts +175 -0
- package/src/analytics-server.ts +99 -0
- package/src/angular/biab-form.component.ts +1443 -0
- package/src/angular/index.ts +26 -0
- package/src/attribution-logo.ts +5 -0
- package/src/auth-handler.ts +352 -0
- package/src/cli.ts +2517 -0
- package/src/client.ts +3578 -0
- package/src/collections.ts +101 -0
- package/src/contracts.ts +3390 -0
- package/src/data-model-schema.ts +4042 -0
- package/src/distribution.ts +73 -0
- package/src/element.ts +321 -0
- package/src/enums.ts +65 -0
- package/src/errors.ts +338 -0
- package/src/forms-core/autocomplete.ts +97 -0
- package/src/forms-core/business-function.ts +209 -0
- package/src/forms-core/calculation.ts +167 -0
- package/src/forms-core/controller.ts +922 -0
- package/src/forms-core/elements.ts +86 -0
- package/src/forms-core/email-domains.ts +68 -0
- package/src/forms-core/file-rules.ts +123 -0
- package/src/forms-core/formula.ts +1339 -0
- package/src/forms-core/index.ts +122 -0
- package/src/forms-core/units.ts +308 -0
- package/src/forms-core/us-states.ts +68 -0
- package/src/forms-core/validation.ts +1037 -0
- package/src/forms.ts +63 -0
- package/src/gallery-types.ts +31 -0
- package/src/graphql.ts +295 -0
- package/src/index.ts +505 -0
- package/src/marketing-schema.ts +395 -0
- package/src/mcp.ts +108 -0
- package/src/native.ts +73 -0
- package/src/next-revalidate.ts +124 -0
- package/src/parallel-pages.ts +192 -0
- package/src/payment-icons.ts +205 -0
- package/src/proxy.ts +173 -0
- package/src/qwik.tsx +1234 -0
- package/src/react-analytics.tsx +76 -0
- package/src/react-attribution.tsx +192 -0
- package/src/react-marketing.tsx +338 -0
- package/src/react.tsx +5495 -0
- package/src/reserved-paths.ts +65 -0
- package/src/revalidate-verify.ts +98 -0
- package/src/sdk.ts +1671 -0
- package/src/seo.ts +488 -0
- package/src/socials.ts +230 -0
- package/src/solid.tsx +1466 -0
- package/src/static.ts +21 -0
- package/src/styles/biab-forms.css +484 -0
- package/src/svelte/BiabForm.svelte +1069 -0
- package/src/svelte/context.ts +57 -0
- package/src/svelte/index.ts +79 -0
- package/src/url-pattern.ts +153 -0
- package/src/vanilla.ts +1290 -0
- package/src/vue/BiabForm.vue +1538 -0
- package/src/vue/index.ts +119 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculation/Math form-element runtime — the bridge between a form's
|
|
3
|
+
* "calculation" field and the Business Functions engine.
|
|
4
|
+
*
|
|
5
|
+
* A calculation field computes a value from OTHER fields in the same form,
|
|
6
|
+
* either by an **inline formula** (mode "formula") or by referencing a saved
|
|
7
|
+
* **business function** (mode "function"). Input variables are bound to source
|
|
8
|
+
* fields via `inputMap` (variable name → source field id). The result is the
|
|
9
|
+
* field's submitted value; for a multi-output function, `outputKey` selects
|
|
10
|
+
* which exported variable to surface (default: the function's first output).
|
|
11
|
+
*
|
|
12
|
+
* Sensitivity: a calculation that references a `sensitive` function MUST run
|
|
13
|
+
* server-only (its formula/def is never published). This module is pure and
|
|
14
|
+
* environment-agnostic — the CALLER decides whether to run it (the client skips
|
|
15
|
+
* sensitive calcs and shows a placeholder; the server always computes the
|
|
16
|
+
* authoritative value on submit).
|
|
17
|
+
*
|
|
18
|
+
* Pure + isomorphic (no DB, no React). The SDK mirrors it.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
type BusinessFunctionDef,
|
|
23
|
+
runBusinessFunction,
|
|
24
|
+
} from "./business-function.js";
|
|
25
|
+
import {
|
|
26
|
+
type EvalOptions,
|
|
27
|
+
type FormulaObject,
|
|
28
|
+
type FormulaValue,
|
|
29
|
+
type FormulaVars,
|
|
30
|
+
runFormula,
|
|
31
|
+
} from "./formula.js";
|
|
32
|
+
|
|
33
|
+
export interface CalcInputBinding {
|
|
34
|
+
/** The variable name (formula) or function input key this binding feeds. */
|
|
35
|
+
variable: string;
|
|
36
|
+
/** The source field id whose value supplies it. */
|
|
37
|
+
fieldId: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface CalcDisplay {
|
|
41
|
+
/** Show the computed value live in the rendered form. */
|
|
42
|
+
show?: boolean;
|
|
43
|
+
prefix?: string;
|
|
44
|
+
suffix?: string;
|
|
45
|
+
/** Fixed decimal places for a numeric result (omit = as-is). */
|
|
46
|
+
decimals?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface CalculationConfig {
|
|
50
|
+
mode?: "formula" | "function";
|
|
51
|
+
/** Inline expression (mode "formula"). Non-sensitive only. */
|
|
52
|
+
formula?: string;
|
|
53
|
+
/** Referenced business function id (mode "function"). */
|
|
54
|
+
functionId?: string;
|
|
55
|
+
/** Which function output to surface as the value (default: first output). */
|
|
56
|
+
outputKey?: string;
|
|
57
|
+
/** Binds variables / function input keys to source field ids. */
|
|
58
|
+
inputMap?: CalcInputBinding[];
|
|
59
|
+
display?: CalcDisplay;
|
|
60
|
+
/** True when it references a sensitive function → compute server-only. */
|
|
61
|
+
sensitive?: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface CalcResult {
|
|
65
|
+
ok: boolean;
|
|
66
|
+
/** The surfaced value (the chosen output, or the formula result). */
|
|
67
|
+
value: FormulaValue | null;
|
|
68
|
+
/** For a function calc, the full exported object. */
|
|
69
|
+
outputs?: FormulaObject;
|
|
70
|
+
error?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface CalcContext {
|
|
74
|
+
/** Saved business functions keyed by id (for mode "function"). */
|
|
75
|
+
functionsById?: Record<string, BusinessFunctionDef>;
|
|
76
|
+
/** Eval options exposing other functions for composition (by UPPERCASE slug). */
|
|
77
|
+
evalOptions?: EvalOptions;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Coerce an arbitrary source-field value into something the engine accepts. */
|
|
81
|
+
function toFormulaValue(raw: unknown): FormulaValue | undefined {
|
|
82
|
+
if (raw === null || raw === undefined || raw === "") return undefined;
|
|
83
|
+
if (typeof raw === "number" || typeof raw === "boolean") return raw;
|
|
84
|
+
if (typeof raw === "string") return raw;
|
|
85
|
+
if (typeof raw === "object" && !Array.isArray(raw))
|
|
86
|
+
return raw as FormulaObject;
|
|
87
|
+
return String(raw);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Apply display formatting (prefix/suffix/decimals) for rendering. Pure. */
|
|
91
|
+
export function formatCalcValue(
|
|
92
|
+
value: FormulaValue | null,
|
|
93
|
+
display?: CalcDisplay,
|
|
94
|
+
): string {
|
|
95
|
+
if (value === null || value === undefined) return "";
|
|
96
|
+
let body: string;
|
|
97
|
+
if (
|
|
98
|
+
typeof value === "number" &&
|
|
99
|
+
display?.decimals !== undefined &&
|
|
100
|
+
Number.isFinite(value)
|
|
101
|
+
) {
|
|
102
|
+
body = value.toFixed(display.decimals);
|
|
103
|
+
} else if (typeof value === "object") {
|
|
104
|
+
body = JSON.stringify(value);
|
|
105
|
+
} else {
|
|
106
|
+
body = String(value);
|
|
107
|
+
}
|
|
108
|
+
return `${display?.prefix ?? ""}${body}${display?.suffix ?? ""}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Compute a calculation field. `resolveField(fieldId)` returns the current
|
|
113
|
+
* value of a source field. Never throws — returns `{ ok:false, error }` on a
|
|
114
|
+
* bad config or evaluation error.
|
|
115
|
+
*/
|
|
116
|
+
export function computeCalculation(
|
|
117
|
+
config: CalculationConfig,
|
|
118
|
+
resolveField: (fieldId: string) => unknown,
|
|
119
|
+
ctx: CalcContext = {},
|
|
120
|
+
): CalcResult {
|
|
121
|
+
const bindings = config.inputMap ?? [];
|
|
122
|
+
|
|
123
|
+
if (config.mode === "function") {
|
|
124
|
+
const def = config.functionId
|
|
125
|
+
? ctx.functionsById?.[config.functionId]
|
|
126
|
+
: undefined;
|
|
127
|
+
if (!def) {
|
|
128
|
+
return {
|
|
129
|
+
ok: false,
|
|
130
|
+
value: null,
|
|
131
|
+
error: "Referenced function not found.",
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const rawInputs: Record<string, unknown> = {};
|
|
135
|
+
for (const b of bindings) {
|
|
136
|
+
rawInputs[b.variable] = resolveField(b.fieldId);
|
|
137
|
+
}
|
|
138
|
+
const run = runBusinessFunction(def, rawInputs, ctx.evalOptions);
|
|
139
|
+
const key = config.outputKey ?? def.outputs[0]?.key;
|
|
140
|
+
const value =
|
|
141
|
+
key !== undefined && key in run.outputs ? run.outputs[key] : null;
|
|
142
|
+
const result: CalcResult = {
|
|
143
|
+
ok: run.ok,
|
|
144
|
+
value: value ?? null,
|
|
145
|
+
outputs: run.outputs,
|
|
146
|
+
};
|
|
147
|
+
if (!run.ok) {
|
|
148
|
+
result.error = run.issues
|
|
149
|
+
.map((i) => `${i.scope}/${i.key}: ${i.reason}`)
|
|
150
|
+
.join("; ");
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// mode "formula" (default)
|
|
156
|
+
const formula = config.formula?.trim();
|
|
157
|
+
if (!formula) {
|
|
158
|
+
return { ok: false, value: null, error: "No formula." };
|
|
159
|
+
}
|
|
160
|
+
const vars: FormulaVars = {};
|
|
161
|
+
for (const b of bindings) {
|
|
162
|
+
vars[b.variable] = toFormulaValue(resolveField(b.fieldId));
|
|
163
|
+
}
|
|
164
|
+
const r = runFormula(formula, vars, ctx.evalOptions);
|
|
165
|
+
if (!r.ok) return { ok: false, value: null, error: r.error };
|
|
166
|
+
return { ok: true, value: r.value };
|
|
167
|
+
}
|