@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
package/dist/errors.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
export class BiabApiError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
body;
|
|
4
|
+
path;
|
|
5
|
+
constructor(input) {
|
|
6
|
+
super(input.message);
|
|
7
|
+
this.name = "BiabApiError";
|
|
8
|
+
this.status = input.status;
|
|
9
|
+
this.body = input.body;
|
|
10
|
+
this.path = input.path;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function isBiabPlanGateBody(value) {
|
|
14
|
+
if (!value || typeof value !== "object")
|
|
15
|
+
return false;
|
|
16
|
+
const v = value;
|
|
17
|
+
if (v["available"] !== false)
|
|
18
|
+
return false;
|
|
19
|
+
if (v["reason"] !== "plan_required" &&
|
|
20
|
+
v["reason"] !== "payment_required" &&
|
|
21
|
+
v["reason"] !== "service_suspended") {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return (typeof v["upgradeUrl"] === "string" && typeof v["message"] === "string");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Base class for every billing/entitlement rejection. Catch this to
|
|
28
|
+
* handle "the SDK refused to serve" uniformly; catch one of the three
|
|
29
|
+
* subclasses (or `instanceof`-narrow on this class) to branch on the
|
|
30
|
+
* specific reason.
|
|
31
|
+
*/
|
|
32
|
+
export class BiabAccessRejectedError extends Error {
|
|
33
|
+
reason;
|
|
34
|
+
upgradeUrl;
|
|
35
|
+
featureMessage;
|
|
36
|
+
path;
|
|
37
|
+
status;
|
|
38
|
+
constructor(input) {
|
|
39
|
+
super(input.body.message);
|
|
40
|
+
this.name = "BiabAccessRejectedError";
|
|
41
|
+
this.reason = input.body.reason;
|
|
42
|
+
this.upgradeUrl = input.body.upgradeUrl;
|
|
43
|
+
this.featureMessage = input.body.message;
|
|
44
|
+
this.path = input.path;
|
|
45
|
+
this.status = input.status;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Thrown when the org's plan doesn't include the feature the call
|
|
50
|
+
* needs. The org can resolve this by upgrading (or by adding the
|
|
51
|
+
* specific feature à la carte once that surface ships).
|
|
52
|
+
*/
|
|
53
|
+
export class BiabFeatureNotEntitledError extends BiabAccessRejectedError {
|
|
54
|
+
feature;
|
|
55
|
+
requiredPlan;
|
|
56
|
+
planDisplayName;
|
|
57
|
+
constructor(input) {
|
|
58
|
+
super(input);
|
|
59
|
+
this.name = "BiabFeatureNotEntitledError";
|
|
60
|
+
this.feature = input.body.requiredFeature;
|
|
61
|
+
this.requiredPlan = input.body.requiredPlan;
|
|
62
|
+
this.planDisplayName = input.body.planDisplayName;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Thrown when the org's billing is 0-60 days past-due. Static-data
|
|
67
|
+
* routes (marketing bundle, sitemap, robots, parallel-page reads,
|
|
68
|
+
* gallery/blog reads) continue serving normally — interactive ones
|
|
69
|
+
* (forms, cart, scheduling bookings, chatbot writes) throw this.
|
|
70
|
+
*/
|
|
71
|
+
export class BiabPaymentLapsedError extends BiabAccessRejectedError {
|
|
72
|
+
daysLapsed;
|
|
73
|
+
daysUntilSuspension;
|
|
74
|
+
constructor(input) {
|
|
75
|
+
super(input);
|
|
76
|
+
this.name = "BiabPaymentLapsedError";
|
|
77
|
+
this.daysLapsed = input.body.daysLapsed;
|
|
78
|
+
this.daysUntilSuspension = input.body.daysUntilSuspension;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Thrown when the org's billing has been past-due for more than 60
|
|
83
|
+
* days. Every SDK call throws this; the consumer's framework-level
|
|
84
|
+
* page handler should catch it and return HTTP 503 with a "site
|
|
85
|
+
* temporarily unavailable" page so search engines treat the outage
|
|
86
|
+
* as temporary. `robots.txt` and `sitemap.xml` separately switch to
|
|
87
|
+
* suspended-mode bodies (`Disallow: /` / empty) for the same reason.
|
|
88
|
+
*/
|
|
89
|
+
export class BiabServiceSuspendedError extends BiabAccessRejectedError {
|
|
90
|
+
daysLapsed;
|
|
91
|
+
constructor(input) {
|
|
92
|
+
super(input);
|
|
93
|
+
this.name = "BiabServiceSuspendedError";
|
|
94
|
+
this.daysLapsed = input.body.daysLapsed;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Factory the transport uses to throw the right subclass.
|
|
99
|
+
*/
|
|
100
|
+
export function accessRejectionFromBody(input) {
|
|
101
|
+
switch (input.body.reason) {
|
|
102
|
+
case "plan_required":
|
|
103
|
+
return new BiabFeatureNotEntitledError({
|
|
104
|
+
body: input.body,
|
|
105
|
+
path: input.path,
|
|
106
|
+
status: input.status,
|
|
107
|
+
});
|
|
108
|
+
case "payment_required":
|
|
109
|
+
return new BiabPaymentLapsedError({
|
|
110
|
+
body: input.body,
|
|
111
|
+
path: input.path,
|
|
112
|
+
status: input.status,
|
|
113
|
+
});
|
|
114
|
+
case "service_suspended":
|
|
115
|
+
return new BiabServiceSuspendedError({
|
|
116
|
+
body: input.body,
|
|
117
|
+
path: input.path,
|
|
118
|
+
status: input.status,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export async function unwrapAccess(fn) {
|
|
123
|
+
try {
|
|
124
|
+
const data = await fn();
|
|
125
|
+
return { data, rejected: null };
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
if (err instanceof BiabFeatureNotEntitledError) {
|
|
129
|
+
return {
|
|
130
|
+
data: null,
|
|
131
|
+
rejected: {
|
|
132
|
+
reason: "plan_required",
|
|
133
|
+
feature: err.feature,
|
|
134
|
+
requiredPlan: err.requiredPlan,
|
|
135
|
+
planDisplayName: err.planDisplayName,
|
|
136
|
+
upgradeUrl: err.upgradeUrl,
|
|
137
|
+
message: err.featureMessage,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (err instanceof BiabPaymentLapsedError) {
|
|
142
|
+
return {
|
|
143
|
+
data: null,
|
|
144
|
+
rejected: {
|
|
145
|
+
reason: "payment_required",
|
|
146
|
+
daysLapsed: err.daysLapsed,
|
|
147
|
+
daysUntilSuspension: err.daysUntilSuspension,
|
|
148
|
+
upgradeUrl: err.upgradeUrl,
|
|
149
|
+
message: err.featureMessage,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (err instanceof BiabServiceSuspendedError) {
|
|
154
|
+
return {
|
|
155
|
+
data: null,
|
|
156
|
+
rejected: {
|
|
157
|
+
reason: "service_suspended",
|
|
158
|
+
daysLapsed: err.daysLapsed,
|
|
159
|
+
upgradeUrl: err.upgradeUrl,
|
|
160
|
+
message: err.featureMessage,
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export async function unwrapEntitlement(fn) {
|
|
168
|
+
try {
|
|
169
|
+
const data = await fn();
|
|
170
|
+
return { data, notEntitled: null };
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
if (err instanceof BiabFeatureNotEntitledError) {
|
|
174
|
+
return {
|
|
175
|
+
data: null,
|
|
176
|
+
notEntitled: {
|
|
177
|
+
feature: err.feature,
|
|
178
|
+
requiredPlan: err.requiredPlan,
|
|
179
|
+
planDisplayName: err.planDisplayName,
|
|
180
|
+
upgradeUrl: err.upgradeUrl,
|
|
181
|
+
featureMessage: err.featureMessage,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC7B,MAAM,CAAS;IACf,IAAI,CAAU;IACd,IAAI,CAAS;IAEtB,YAAY,KAKX;QACA,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACxB,CAAC;CACD;AA8CD,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAChD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,IAAI,CAAC,CAAC,WAAW,CAAC,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAC3C,IACC,CAAC,CAAC,QAAQ,CAAC,KAAK,eAAe;QAC/B,CAAC,CAAC,QAAQ,CAAC,KAAK,kBAAkB;QAClC,CAAC,CAAC,QAAQ,CAAC,KAAK,mBAAmB,EAClC,CAAC;QACF,OAAO,KAAK,CAA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,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,MAAM,EAAE,EAAE,CAAC;QACxB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IACpC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,IAAI,GAAG,YAAY,2BAA2B,EAAE,CAAC;YAChD,OAAO;gBACN,IAAI,EAAE,IAAI;gBACV,WAAW,EAAE;oBACZ,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,YAAY,EAAE,GAAG,CAAC,YAAY;oBAC9B,eAAe,EAAE,GAAG,CAAC,eAAe;oBACpC,UAAU,EAAE,GAAG,CAAC,UAAU;oBAC1B,cAAc,EAAE,GAAG,CAAC,cAAc;iBAClC;aACD,CAAC;QACH,CAAC;QACD,MAAM,GAAG,CAAC;IACX,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML autofill (`autocomplete`) resolution for `<BiabForm>` inputs.
|
|
3
|
+
*
|
|
4
|
+
* Browsers autofill an input when it carries a recognized `autocomplete` token
|
|
5
|
+
* (https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
|
|
6
|
+
* The SDK infers a sensible token per field (so a "Full name" text field gets
|
|
7
|
+
* `name`, an email field gets `email`, etc.), and lets the consumer:
|
|
8
|
+
*
|
|
9
|
+
* - turn it off globally (`<BiabForm autoComplete={false}>` → every input
|
|
10
|
+
* gets `autocomplete="off"`), and
|
|
11
|
+
* - override per field (`fieldAutoComplete={{ [fieldId]: "off" | true | token }}`),
|
|
12
|
+
*
|
|
13
|
+
* Precedence (highest first): per-field override → schema token (`field.autocomplete`)
|
|
14
|
+
* → global off → inferred token.
|
|
15
|
+
*/
|
|
16
|
+
import type { FormCoreField } from "./validation.js";
|
|
17
|
+
/** Global + per-field autofill configuration, threaded from `<BiabForm>`. */
|
|
18
|
+
export type AutocompleteConfig = {
|
|
19
|
+
/** Global default. `false` emits `autocomplete="off"` on every input.
|
|
20
|
+
* Defaults to `true` (infer tokens). */
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
/** Per-field overrides keyed by field id: a literal token, `true` (infer),
|
|
23
|
+
* or `false` (off). Wins over everything else. */
|
|
24
|
+
overrides?: Record<string, string | boolean>;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Best-guess `autocomplete` token for a field from its type, then its key/label.
|
|
28
|
+
* Returns `undefined` when nothing sensible applies (e.g. a freeform number) so
|
|
29
|
+
* the attribute can be omitted entirely.
|
|
30
|
+
*/
|
|
31
|
+
export declare function inferAutocompleteToken(field: FormCoreField): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the final `autocomplete` attribute value for a field, or `undefined`
|
|
34
|
+
* to omit it. Applies the precedence documented above.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveFieldAutocomplete(field: FormCoreField, config: AutocompleteConfig): string | undefined;
|
|
37
|
+
//# sourceMappingURL=autocomplete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../src/forms-core/autocomplete.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,6EAA6E;AAC7E,MAAM,MAAM,kBAAkB,GAAG;IAChC;6CACyC;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;uDACmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;CAC7C,CAAC;AA6BF;;;;GAIG;AACH,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,aAAa,GAClB,MAAM,GAAG,SAAS,CAcpB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACvC,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,kBAAkB,GACxB,MAAM,GAAG,SAAS,CAWpB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML autofill (`autocomplete`) resolution for `<BiabForm>` inputs.
|
|
3
|
+
*
|
|
4
|
+
* Browsers autofill an input when it carries a recognized `autocomplete` token
|
|
5
|
+
* (https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
|
|
6
|
+
* The SDK infers a sensible token per field (so a "Full name" text field gets
|
|
7
|
+
* `name`, an email field gets `email`, etc.), and lets the consumer:
|
|
8
|
+
*
|
|
9
|
+
* - turn it off globally (`<BiabForm autoComplete={false}>` → every input
|
|
10
|
+
* gets `autocomplete="off"`), and
|
|
11
|
+
* - override per field (`fieldAutoComplete={{ [fieldId]: "off" | true | token }}`),
|
|
12
|
+
*
|
|
13
|
+
* Precedence (highest first): per-field override → schema token (`field.autocomplete`)
|
|
14
|
+
* → global off → inferred token.
|
|
15
|
+
*/
|
|
16
|
+
/** Label/key → token heuristics, in priority order (first match wins). */
|
|
17
|
+
const KEY_TOKEN_MAP = [
|
|
18
|
+
[/first[\s_-]?name|given[\s_-]?name/i, "given-name"],
|
|
19
|
+
[/last[\s_-]?name|family[\s_-]?name|surname/i, "family-name"],
|
|
20
|
+
[/full[\s_-]?name|your[\s_-]?name|^name$|contact[\s_-]?name/i, "name"],
|
|
21
|
+
[/company|organi[sz]ation|business[\s_-]?name|employer/i, "organization"],
|
|
22
|
+
[/job[\s_-]?title|position|occupation/i, "organization-title"],
|
|
23
|
+
[/web[\s_-]?site|homepage|\burl\b/i, "url"],
|
|
24
|
+
[
|
|
25
|
+
/address[\s_-]?line[\s_-]?2|apartment|\bapt\b|\bsuite\b|\bunit\b/i,
|
|
26
|
+
"address-line2",
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
/street|address[\s_-]?line[\s_-]?1|^address1?$|street[\s_-]?address/i,
|
|
30
|
+
"street-address",
|
|
31
|
+
],
|
|
32
|
+
[/\bcity\b|\btown\b/i, "address-level2"],
|
|
33
|
+
[/\bstate\b|province|region/i, "address-level1"],
|
|
34
|
+
[/\bzip\b|postal|post[\s_-]?code/i, "postal-code"],
|
|
35
|
+
[/\bcountry\b/i, "country-name"],
|
|
36
|
+
[/birth|\bdob\b/i, "bday"],
|
|
37
|
+
[
|
|
38
|
+
/work[\s_-]?phone|office[\s_-]?phone|company[\s_-]?phone|mobile|cell/i,
|
|
39
|
+
"tel",
|
|
40
|
+
],
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* Best-guess `autocomplete` token for a field from its type, then its key/label.
|
|
44
|
+
* Returns `undefined` when nothing sensible applies (e.g. a freeform number) so
|
|
45
|
+
* the attribute can be omitted entirely.
|
|
46
|
+
*/
|
|
47
|
+
export function inferAutocompleteToken(field) {
|
|
48
|
+
switch (field.type) {
|
|
49
|
+
case "email":
|
|
50
|
+
return "email";
|
|
51
|
+
case "phone":
|
|
52
|
+
return "tel";
|
|
53
|
+
case "url":
|
|
54
|
+
return "url";
|
|
55
|
+
}
|
|
56
|
+
const haystack = `${field.key ?? ""} ${field.label ?? ""}`;
|
|
57
|
+
for (const [pattern, token] of KEY_TOKEN_MAP) {
|
|
58
|
+
if (pattern.test(haystack))
|
|
59
|
+
return token;
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve the final `autocomplete` attribute value for a field, or `undefined`
|
|
65
|
+
* to omit it. Applies the precedence documented above.
|
|
66
|
+
*/
|
|
67
|
+
export function resolveFieldAutocomplete(field, config) {
|
|
68
|
+
const override = config.overrides?.[field.id];
|
|
69
|
+
if (typeof override === "string")
|
|
70
|
+
return override;
|
|
71
|
+
if (override === false)
|
|
72
|
+
return "off";
|
|
73
|
+
if (override === true)
|
|
74
|
+
return inferAutocompleteToken(field) ?? "on";
|
|
75
|
+
if (typeof field.autocomplete === "string" && field.autocomplete) {
|
|
76
|
+
return field.autocomplete;
|
|
77
|
+
}
|
|
78
|
+
if (config.enabled === false)
|
|
79
|
+
return "off";
|
|
80
|
+
return inferAutocompleteToken(field);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=autocomplete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.js","sourceRoot":"","sources":["../../src/forms-core/autocomplete.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAcH,0EAA0E;AAC1E,MAAM,aAAa,GAA6C;IAC/D,CAAC,oCAAoC,EAAE,YAAY,CAAC;IACpD,CAAC,4CAA4C,EAAE,aAAa,CAAC;IAC7D,CAAC,4DAA4D,EAAE,MAAM,CAAC;IACtE,CAAC,uDAAuD,EAAE,cAAc,CAAC;IACzE,CAAC,sCAAsC,EAAE,oBAAoB,CAAC;IAC9D,CAAC,kCAAkC,EAAE,KAAK,CAAC;IAC3C;QACC,kEAAkE;QAClE,eAAe;KACf;IACD;QACC,qEAAqE;QACrE,gBAAgB;KAChB;IACD,CAAC,oBAAoB,EAAE,gBAAgB,CAAC;IACxC,CAAC,4BAA4B,EAAE,gBAAgB,CAAC;IAChD,CAAC,iCAAiC,EAAE,aAAa,CAAC;IAClD,CAAC,cAAc,EAAE,cAAc,CAAC;IAChC,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC1B;QACC,sEAAsE;QACtE,KAAK;KACL;CACD,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACrC,KAAoB;IAEpB,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,OAAO;YACX,OAAO,OAAO,CAAC;QAChB,KAAK,OAAO;YACX,OAAO,KAAK,CAAC;QACd,KAAK,KAAK;YACT,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC;IAC3D,KAAK,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,aAAa,EAAE,CAAC;QAC9C,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAC;IAC1C,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACvC,KAAoB,EACpB,MAA0B;IAE1B,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC9C,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAClD,IAAI,QAAQ,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACrC,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,sBAAsB,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IAEpE,IAAI,OAAO,KAAK,CAAC,YAAY,KAAK,QAAQ,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;QAClE,OAAO,KAAK,CAAC,YAAY,CAAC;IAC3B,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAC3C,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business-function runtime — the typed layer over the formula engine.
|
|
3
|
+
*
|
|
4
|
+
* A business function has typed **inputs** (with required/default) and one or
|
|
5
|
+
* more typed **outputs** ("exported variables"), each its own expression. This
|
|
6
|
+
* module runs a function definition end-to-end and *self-corrects*: a missing
|
|
7
|
+
* optional input falls back to its default; a missing required input or a
|
|
8
|
+
* bad/null/wrong-type output is flagged per-output (with an optional fallback)
|
|
9
|
+
* while the other outputs still resolve — it never throws out. Outputs may
|
|
10
|
+
* reference inputs, prior outputs (declaration order = a mini-pipeline), and
|
|
11
|
+
* other business functions (composition).
|
|
12
|
+
*
|
|
13
|
+
* Pure + isomorphic (no DB, no React). The registry/UI and the form runner build
|
|
14
|
+
* on this; the SDK mirrors it.
|
|
15
|
+
*/
|
|
16
|
+
import { type EvalOptions, type FormulaObject, type FormulaValue } from "./formula.js";
|
|
17
|
+
export type FnValueType = "number" | "text" | "boolean" | "date" | "object" | "any";
|
|
18
|
+
export interface FnInput {
|
|
19
|
+
key: string;
|
|
20
|
+
label?: string;
|
|
21
|
+
type: FnValueType;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
default?: FormulaValue;
|
|
24
|
+
}
|
|
25
|
+
export interface FnOutput {
|
|
26
|
+
key: string;
|
|
27
|
+
label?: string;
|
|
28
|
+
type: FnValueType;
|
|
29
|
+
/** Expression over inputs / prior outputs / other functions. */
|
|
30
|
+
formula: string;
|
|
31
|
+
/** Used when the computed value is missing/invalid for the declared type. */
|
|
32
|
+
fallback?: FormulaValue;
|
|
33
|
+
}
|
|
34
|
+
export interface BusinessFunctionDef {
|
|
35
|
+
slug?: string;
|
|
36
|
+
inputs: FnInput[];
|
|
37
|
+
outputs: FnOutput[];
|
|
38
|
+
}
|
|
39
|
+
export interface FnIssue {
|
|
40
|
+
scope: "input" | "output";
|
|
41
|
+
key: string;
|
|
42
|
+
reason: string;
|
|
43
|
+
}
|
|
44
|
+
export interface FnRunResult {
|
|
45
|
+
ok: boolean;
|
|
46
|
+
/** The exported object — successfully computed outputs (incl. applied fallbacks). */
|
|
47
|
+
outputs: FormulaObject;
|
|
48
|
+
issues: FnIssue[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Run a business function. `rawInputs` is keyed by input `key`. `options.functions`
|
|
52
|
+
* supplies other business functions for composition. Never throws.
|
|
53
|
+
*/
|
|
54
|
+
export declare function runBusinessFunction(def: BusinessFunctionDef, rawInputs: Record<string, unknown>, options?: EvalOptions): FnRunResult;
|
|
55
|
+
/** Build the {@link EvalOptions} function map from a set of business functions,
|
|
56
|
+
* so formulas can call them by name. Params are the function's input keys (in
|
|
57
|
+
* order); a call resolves to the function's FIRST output (single-output
|
|
58
|
+
* convenience) — multi-output composition is wired via input bindings, not
|
|
59
|
+
* in-formula calls. */
|
|
60
|
+
export declare function functionsToEvalOptions(defs: Record<string, BusinessFunctionDef>): EvalOptions;
|
|
61
|
+
//# sourceMappingURL=business-function.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business-function.d.ts","sourceRoot":"","sources":["../../src/forms-core/business-function.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,YAAY,EAKjB,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,WAAW,GACpB,QAAQ,GACR,MAAM,GACN,SAAS,GACT,MAAM,GACN,QAAQ,GACR,KAAK,CAAC;AAET,MAAM,WAAW,OAAO;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,WAAW,QAAQ;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;IAClB,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,OAAO,EAAE,QAAQ,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACvB,KAAK,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,qFAAqF;IACrF,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,OAAO,EAAE,CAAC;CAClB;AAuDD;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,mBAAmB,EACxB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,OAAO,CAAC,EAAE,WAAW,GACnB,WAAW,CAwDb;AAED;;;;wBAIwB;AACxB,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,GACvC,WAAW,CAWb"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business-function runtime — the typed layer over the formula engine.
|
|
3
|
+
*
|
|
4
|
+
* A business function has typed **inputs** (with required/default) and one or
|
|
5
|
+
* more typed **outputs** ("exported variables"), each its own expression. This
|
|
6
|
+
* module runs a function definition end-to-end and *self-corrects*: a missing
|
|
7
|
+
* optional input falls back to its default; a missing required input or a
|
|
8
|
+
* bad/null/wrong-type output is flagged per-output (with an optional fallback)
|
|
9
|
+
* while the other outputs still resolve — it never throws out. Outputs may
|
|
10
|
+
* reference inputs, prior outputs (declaration order = a mini-pipeline), and
|
|
11
|
+
* other business functions (composition).
|
|
12
|
+
*
|
|
13
|
+
* Pure + isomorphic (no DB, no React). The registry/UI and the form runner build
|
|
14
|
+
* on this; the SDK mirrors it.
|
|
15
|
+
*/
|
|
16
|
+
import { isFormulaObjectValue, parseFormula, runFormula, } from "./formula.js";
|
|
17
|
+
const ISO_DATE = /^\d{4}-\d{2}-\d{2}([T ].*)?$/;
|
|
18
|
+
/** Coerce a raw value to a declared type, or return an error reason. */
|
|
19
|
+
function coerce(value, type) {
|
|
20
|
+
if (type === "any")
|
|
21
|
+
return { ok: true, value: value };
|
|
22
|
+
if (type === "object") {
|
|
23
|
+
if (value && typeof value === "object" && !Array.isArray(value))
|
|
24
|
+
return { ok: true, value: value };
|
|
25
|
+
return { ok: false, reason: "expected an object" };
|
|
26
|
+
}
|
|
27
|
+
if (type === "number") {
|
|
28
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
29
|
+
return Number.isNaN(n)
|
|
30
|
+
? { ok: false, reason: "not a number" }
|
|
31
|
+
: { ok: true, value: n };
|
|
32
|
+
}
|
|
33
|
+
if (type === "boolean") {
|
|
34
|
+
if (typeof value === "boolean")
|
|
35
|
+
return { ok: true, value };
|
|
36
|
+
if (value === "true" || value === 1)
|
|
37
|
+
return { ok: true, value: true };
|
|
38
|
+
if (value === "false" || value === 0)
|
|
39
|
+
return { ok: true, value: false };
|
|
40
|
+
return { ok: false, reason: "not a boolean" };
|
|
41
|
+
}
|
|
42
|
+
if (type === "date") {
|
|
43
|
+
const s = String(value);
|
|
44
|
+
if (ISO_DATE.test(s) && !Number.isNaN(new Date(s).getTime()))
|
|
45
|
+
return { ok: true, value: s };
|
|
46
|
+
return { ok: false, reason: "not a date" };
|
|
47
|
+
}
|
|
48
|
+
// text
|
|
49
|
+
return { ok: true, value: typeof value === "string" ? value : String(value) };
|
|
50
|
+
}
|
|
51
|
+
/** Validate an already-computed value against a declared output type. */
|
|
52
|
+
function matchesType(value, type) {
|
|
53
|
+
switch (type) {
|
|
54
|
+
case "any":
|
|
55
|
+
return true;
|
|
56
|
+
case "number":
|
|
57
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
58
|
+
case "text":
|
|
59
|
+
return typeof value === "string";
|
|
60
|
+
case "boolean":
|
|
61
|
+
return typeof value === "boolean";
|
|
62
|
+
case "object":
|
|
63
|
+
return isFormulaObjectValue(value);
|
|
64
|
+
case "date":
|
|
65
|
+
return typeof value === "string" && ISO_DATE.test(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Run a business function. `rawInputs` is keyed by input `key`. `options.functions`
|
|
70
|
+
* supplies other business functions for composition. Never throws.
|
|
71
|
+
*/
|
|
72
|
+
export function runBusinessFunction(def, rawInputs, options) {
|
|
73
|
+
const issues = [];
|
|
74
|
+
const vars = {};
|
|
75
|
+
// 1. Coerce inputs (missing optional → default; missing required → issue).
|
|
76
|
+
for (const input of def.inputs) {
|
|
77
|
+
const raw = rawInputs[input.key];
|
|
78
|
+
const missing = raw === undefined || raw === null || raw === "";
|
|
79
|
+
if (missing) {
|
|
80
|
+
if (input.default !== undefined) {
|
|
81
|
+
vars[input.key] = input.default;
|
|
82
|
+
}
|
|
83
|
+
else if (input.required) {
|
|
84
|
+
issues.push({
|
|
85
|
+
scope: "input",
|
|
86
|
+
key: input.key,
|
|
87
|
+
reason: "required value is missing",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const c = coerce(raw, input.type);
|
|
93
|
+
if (c.ok)
|
|
94
|
+
vars[input.key] = c.value;
|
|
95
|
+
else
|
|
96
|
+
issues.push({ scope: "input", key: input.key, reason: c.reason });
|
|
97
|
+
}
|
|
98
|
+
// 2. Evaluate each output in order; later outputs can read earlier ones.
|
|
99
|
+
const outputs = {};
|
|
100
|
+
for (const out of def.outputs) {
|
|
101
|
+
const r = runFormula(out.formula, vars, options);
|
|
102
|
+
if (!r.ok) {
|
|
103
|
+
if (out.fallback !== undefined) {
|
|
104
|
+
outputs[out.key] = out.fallback;
|
|
105
|
+
vars[out.key] = out.fallback;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
issues.push({ scope: "output", key: out.key, reason: r.error });
|
|
109
|
+
}
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!matchesType(r.value, out.type)) {
|
|
113
|
+
if (out.fallback !== undefined) {
|
|
114
|
+
outputs[out.key] = out.fallback;
|
|
115
|
+
vars[out.key] = out.fallback;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
issues.push({
|
|
119
|
+
scope: "output",
|
|
120
|
+
key: out.key,
|
|
121
|
+
reason: `expected ${out.type}`,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
outputs[out.key] = r.value;
|
|
127
|
+
vars[out.key] = r.value;
|
|
128
|
+
}
|
|
129
|
+
return { ok: issues.length === 0, outputs, issues };
|
|
130
|
+
}
|
|
131
|
+
/** Build the {@link EvalOptions} function map from a set of business functions,
|
|
132
|
+
* so formulas can call them by name. Params are the function's input keys (in
|
|
133
|
+
* order); a call resolves to the function's FIRST output (single-output
|
|
134
|
+
* convenience) — multi-output composition is wired via input bindings, not
|
|
135
|
+
* in-formula calls. */
|
|
136
|
+
export function functionsToEvalOptions(defs) {
|
|
137
|
+
const functions = {};
|
|
138
|
+
for (const [name, def] of Object.entries(defs)) {
|
|
139
|
+
const first = def.outputs[0];
|
|
140
|
+
if (!first)
|
|
141
|
+
continue;
|
|
142
|
+
functions[name] = {
|
|
143
|
+
params: def.inputs.map((i) => i.key),
|
|
144
|
+
formula: parseFormula(first.formula),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return { functions };
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=business-function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business-function.js","sourceRoot":"","sources":["../../src/forms-core/business-function.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAKN,oBAAoB,EACpB,YAAY,EACZ,UAAU,GACV,MAAM,cAAc,CAAC;AA+CtB,MAAM,QAAQ,GAAG,8BAA8B,CAAC;AAEhD,wEAAwE;AACxE,SAAS,MAAM,CACd,KAAc,EACd,IAAiB;IAEjB,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAqB,EAAE,CAAC;IACtE,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACvB,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAC9D,OAAO,EAAE,EAAE,EAAE,IAAI,E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AAI,CAAC,KAAK;YAAE,SAAS;QACrB,SAAS,CAAC,IAAI,CAAC,GAAG;YACjB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;YACpC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC;SACpC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
import { type BusinessFunctionDef } from "./business-function.js";
|
|
21
|
+
import { type EvalOptions, type FormulaObject, type FormulaValue } from "./formula.js";
|
|
22
|
+
export interface CalcInputBinding {
|
|
23
|
+
/** The variable name (formula) or function input key this binding feeds. */
|
|
24
|
+
variable: string;
|
|
25
|
+
/** The source field id whose value supplies it. */
|
|
26
|
+
fieldId: string;
|
|
27
|
+
}
|
|
28
|
+
export interface CalcDisplay {
|
|
29
|
+
/** Show the computed value live in the rendered form. */
|
|
30
|
+
show?: boolean;
|
|
31
|
+
prefix?: string;
|
|
32
|
+
suffix?: string;
|
|
33
|
+
/** Fixed decimal places for a numeric result (omit = as-is). */
|
|
34
|
+
decimals?: number;
|
|
35
|
+
}
|
|
36
|
+
export interface CalculationConfig {
|
|
37
|
+
mode?: "formula" | "function";
|
|
38
|
+
/** Inline expression (mode "formula"). Non-sensitive only. */
|
|
39
|
+
formula?: string;
|
|
40
|
+
/** Referenced business function id (mode "function"). */
|
|
41
|
+
functionId?: string;
|
|
42
|
+
/** Which function output to surface as the value (default: first output). */
|
|
43
|
+
outputKey?: string;
|
|
44
|
+
/** Binds variables / function input keys to source field ids. */
|
|
45
|
+
inputMap?: CalcInputBinding[];
|
|
46
|
+
display?: CalcDisplay;
|
|
47
|
+
/** True when it references a sensitive function → compute server-only. */
|
|
48
|
+
sensitive?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface CalcResult {
|
|
51
|
+
ok: boolean;
|
|
52
|
+
/** The surfaced value (the chosen output, or the formula result). */
|
|
53
|
+
value: FormulaValue | null;
|
|
54
|
+
/** For a function calc, the full exported object. */
|
|
55
|
+
outputs?: FormulaObject;
|
|
56
|
+
error?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface CalcContext {
|
|
59
|
+
/** Saved business functions keyed by id (for mode "function"). */
|
|
60
|
+
functionsById?: Record<string, BusinessFunctionDef>;
|
|
61
|
+
/** Eval options exposing other functions for composition (by UPPERCASE slug). */
|
|
62
|
+
evalOptions?: EvalOptions;
|
|
63
|
+
}
|
|
64
|
+
/** Apply display formatting (prefix/suffix/decimals) for rendering. Pure. */
|
|
65
|
+
export declare function formatCalcValue(value: FormulaValue | null, display?: CalcDisplay): string;
|
|
66
|
+
/**
|
|
67
|
+
* Compute a calculation field. `resolveField(fieldId)` returns the current
|
|
68
|
+
* value of a source field. Never throws — returns `{ ok:false, error }` on a
|
|
69
|
+
* bad config or evaluation error.
|
|
70
|
+
*/
|
|
71
|
+
export declare function computeCalculation(config: CalculationConfig, resolveField: (fieldId: string) => unknown, ctx?: CalcContext): CalcResult;
|
|
72
|
+
//# sourceMappingURL=calculation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculation.d.ts","sourceRoot":"","sources":["../../src/forms-core/calculation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACN,KAAK,mBAAmB,EAExB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,YAAY,EAGjB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,gBAAgB;IAChC,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC3B,yDAAyD;IACzD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IACjC,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;IAC9B,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,qEAAqE;IACrE,KAAK,EAAE,YAAY,GAAG,IAAI,C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