@embeddables/forms 0.0.1 → 0.0.3
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 +52 -1
- package/dist/form-CUYofmuL.js +1075 -0
- package/dist/form-CUYofmuL.js.map +1 -0
- package/dist/form-CwUR8-8T.d.ts +180 -0
- package/dist/form-CwUR8-8T.d.ts.map +1 -0
- package/dist/form-W_EyuKU4.cjs +1104 -0
- package/dist/form-W_EyuKU4.cjs.map +1 -0
- package/dist/index.cjs +6 -993
- package/dist/index.d.ts +10 -175
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -988
- package/dist/react.cjs +157 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +34 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +153 -0
- package/dist/react.js.map +1 -0
- package/package.json +16 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as FormSchema, a as SetResult, b as JsonValue, c as initForms, d as AnalyticsTrackResult, f as FieldConfig, g as FormFieldKey, h as FieldValidator, i as InitFormsOptions, l as AnalyticsInstance, m as FieldValidations, n as FormInstance, o as SubmitResult, p as FieldType, r as FormsClient, s as ValidateResult, t as FieldErrors, u as AnalyticsTrackEvent, v as FormValues, y as ProtocolFieldId } from "./form-CwUR8-8T.js";
|
|
2
2
|
//#region src/errors.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Typed error hierarchy. Every failure this SDK raises on its own behalf is an
|
|
@@ -22,49 +22,15 @@ declare class ValidatorError extends FormsError {
|
|
|
22
22
|
constructor(message: string, options?: ErrorOptions);
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
|
-
//#region
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* `trackEvent` is a method (not a function property) so parameter checking
|
|
33
|
-
* stays bivariant: a precise analytics-sdk client remains assignable here, and
|
|
34
|
-
* callers without those types can still pass their payloads.
|
|
35
|
-
*/
|
|
36
|
-
/** Loose event payload other SDKs pass to `trackEvent`. */
|
|
37
|
-
interface AnalyticsTrackEvent {
|
|
38
|
-
event_name: string;
|
|
39
|
-
[key: string]: unknown;
|
|
40
|
-
}
|
|
41
|
-
/** Body `trackEvent` resolves with — identity plus ingest outcome. */
|
|
42
|
-
interface AnalyticsTrackResult {
|
|
43
|
-
app_user_id: string;
|
|
44
|
-
accepted: number;
|
|
45
|
-
forwarded: boolean;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Structural stand-in for `ReturnType<typeof initAnalytics>`. Other SDKs type
|
|
49
|
-
* injected clients against this; analytics-sdk's `AnalyticsClient` must remain
|
|
50
|
-
* assignable to it.
|
|
51
|
-
*/
|
|
52
|
-
interface AnalyticsInstance<TEvent = AnalyticsTrackEvent> {
|
|
53
|
-
trackEvent(input: TEvent | readonly TEvent[]): Promise<AnalyticsTrackResult>;
|
|
54
|
-
/** Live identity: the composed core instance's current user. */
|
|
55
|
-
getAppUserId(): string | null;
|
|
56
|
-
getProjectId(): string;
|
|
25
|
+
//#region src/storage/storage.d.ts
|
|
26
|
+
/** Every form on the origin shares this one entry, indexed by form ID. */
|
|
27
|
+
declare const FORM_DATA_KEY = "EMBEDDABLES-FORM-DATA";
|
|
28
|
+
interface FormsStorage {
|
|
29
|
+
getItem(key: string): string | null;
|
|
30
|
+
setItem(key: string, value: string): void;
|
|
31
|
+
removeItem(key: string): void;
|
|
57
32
|
}
|
|
58
33
|
//#endregion
|
|
59
|
-
//#region ../shared-types/dist/json.types.d.ts
|
|
60
|
-
/**
|
|
61
|
-
* Recursive JSON value, compatible with JSONB column values and public
|
|
62
|
-
* portal entity payloads.
|
|
63
|
-
*/
|
|
64
|
-
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
65
|
-
[key: string]: JsonValue;
|
|
66
|
-
};
|
|
67
|
-
//#endregion
|
|
68
34
|
//#region ../shared-types/dist/analytics-ingest.types.d.ts
|
|
69
35
|
type FieldUpdatedType = 'text' | 'email' | 'number' | 'boolean' | 'select' | 'multiselect' | 'json';
|
|
70
36
|
/**
|
|
@@ -103,139 +69,8 @@ type FormSubmittedEvent = FunnelStepFields & {
|
|
|
103
69
|
form_key: string;
|
|
104
70
|
};
|
|
105
71
|
//#endregion
|
|
106
|
-
//#region src/
|
|
107
|
-
type FieldType = 'text' | 'email' | 'number' | 'boolean' | 'select' | 'multiselect' | 'json';
|
|
108
|
-
/** Runtime `type` literal → the TypeScript type of that field's value. */
|
|
109
|
-
interface ValueOfFieldType {
|
|
110
|
-
text: string;
|
|
111
|
-
email: string;
|
|
112
|
-
number: number;
|
|
113
|
-
boolean: boolean;
|
|
114
|
-
select: string;
|
|
115
|
-
multiselect: string[];
|
|
116
|
-
json: JsonValue;
|
|
117
|
-
}
|
|
118
|
-
type FieldValidator<TValue extends JsonValue = JsonValue> = (args: {
|
|
119
|
-
value: TValue;
|
|
120
|
-
values: Readonly<Record<string, JsonValue>>;
|
|
121
|
-
}) => string | readonly string[] | null;
|
|
122
|
-
interface FieldValidationsFor<TType extends FieldType> {
|
|
123
|
-
readonly required?: boolean;
|
|
124
|
-
readonly minLength?: number;
|
|
125
|
-
readonly maxLength?: number;
|
|
126
|
-
readonly min?: number;
|
|
127
|
-
readonly max?: number;
|
|
128
|
-
/** ECMAScript source without delimiters. */
|
|
129
|
-
readonly pattern?: string;
|
|
130
|
-
/** Flags for `pattern`. `g` and `y` are stripped before compilation. */
|
|
131
|
-
readonly patternFlags?: string;
|
|
132
|
-
readonly oneOf?: readonly JsonValue[];
|
|
133
|
-
/** `value` is bound to this field's declared `type`. */
|
|
134
|
-
readonly custom?: FieldValidator<ValueOfFieldType[TType]>;
|
|
135
|
-
}
|
|
136
|
-
interface FieldConfigFor<TType extends FieldType> {
|
|
137
|
-
readonly key: string;
|
|
138
|
-
readonly label: string;
|
|
139
|
-
readonly type: TType;
|
|
140
|
-
readonly validations?: FieldValidationsFor<TType>;
|
|
141
|
-
readonly registryFieldId?: string;
|
|
142
|
-
readonly protocolFieldId?: string;
|
|
143
|
-
}
|
|
144
|
-
type FieldConfig = { [T in FieldType]: FieldConfigFor<T>; }[FieldType];
|
|
145
|
-
type FieldValidations = { [T in FieldType]: FieldValidationsFor<T>; }[FieldType];
|
|
146
|
-
interface FormSchema {
|
|
147
|
-
readonly id: string;
|
|
148
|
-
readonly name?: string;
|
|
149
|
-
readonly fields: readonly FieldConfig[];
|
|
150
|
-
}
|
|
151
|
-
type FieldsOf<TSchema extends FormSchema> = TSchema['fields'][number];
|
|
152
|
-
type FormFieldKey<TSchema extends FormSchema> = FieldsOf<TSchema>['key'];
|
|
153
|
-
type FormValues<TSchema extends FormSchema> = { [F in FieldsOf<TSchema> as F['key']]: ValueOfFieldType[F['type']]; };
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/analytics.d.ts
|
|
72
|
+
//#region src/core/analytics.d.ts
|
|
156
73
|
type FormsAnalyticsEvent = DataUpdatedEvent | FieldUpdatedEvent | FormSubmittedEvent;
|
|
157
74
|
//#endregion
|
|
158
|
-
|
|
159
|
-
/** Every form on the origin shares this one entry, indexed by form key. */
|
|
160
|
-
declare const FORM_DATA_KEY = "EMBEDDABLES-FORM-DATA";
|
|
161
|
-
interface FormsStorage {
|
|
162
|
-
getItem(key: string): string | null;
|
|
163
|
-
setItem(key: string, value: string): void;
|
|
164
|
-
removeItem(key: string): void;
|
|
165
|
-
}
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region src/form.d.ts
|
|
168
|
-
/** Per-key validation errors. An empty object means the operation succeeded. */
|
|
169
|
-
type FieldErrors<TSchema extends FormSchema> = Readonly<Partial<Record<FormFieldKey<TSchema>, readonly string[]>>>;
|
|
170
|
-
interface SetResult<TSchema extends FormSchema> {
|
|
171
|
-
ok: boolean;
|
|
172
|
-
errors: FieldErrors<TSchema>;
|
|
173
|
-
/** Set when an `analyticsInstance` was configured and `trackEvent` rejected. Never thrown. */
|
|
174
|
-
trackError?: unknown;
|
|
175
|
-
}
|
|
176
|
-
interface SubmitResult<TSchema extends FormSchema> {
|
|
177
|
-
ok: boolean;
|
|
178
|
-
errors: FieldErrors<TSchema>;
|
|
179
|
-
values: Partial<FormValues<TSchema>>;
|
|
180
|
-
trackError?: unknown;
|
|
181
|
-
}
|
|
182
|
-
interface ValidateResult<TSchema extends FormSchema> {
|
|
183
|
-
ok: boolean;
|
|
184
|
-
errors: FieldErrors<TSchema>;
|
|
185
|
-
values: Partial<FormValues<TSchema>>;
|
|
186
|
-
}
|
|
187
|
-
interface FormInstance<TSchema extends FormSchema> {
|
|
188
|
-
readonly key: TSchema['id'];
|
|
189
|
-
/**
|
|
190
|
-
* Applies every key atomically: all or nothing, one write, one event.
|
|
191
|
-
* Validates and persists synchronously; the returned promise never rejects.
|
|
192
|
-
* Throws synchronously only if a custom validator throws or returns an
|
|
193
|
-
* illegal shape.
|
|
194
|
-
*/
|
|
195
|
-
set(patch: Partial<FormValues<TSchema>>): Promise<SetResult<TSchema>>;
|
|
196
|
-
/** Typed by the field's declared `type`. Nothing verifies the stored value against it. */
|
|
197
|
-
get<K extends FormFieldKey<TSchema>>(key: K): FormValues<TSchema>[K] | undefined;
|
|
198
|
-
getAll(): Partial<FormValues<TSchema>>;
|
|
199
|
-
/**
|
|
200
|
-
* Validates every declared field, then emits one `form:submitted` event.
|
|
201
|
-
*
|
|
202
|
-
* Not idempotent: every call emits another event. The caller owns dedupe —
|
|
203
|
-
* disable the button, or guard on a route transition.
|
|
204
|
-
*
|
|
205
|
-
* Same synchronous-throw and never-reject contract as `set`.
|
|
206
|
-
*/
|
|
207
|
-
submit(): Promise<SubmitResult<TSchema>>;
|
|
208
|
-
/**
|
|
209
|
-
* Runs validation without writing to storage or emitting analytics.
|
|
210
|
-
*
|
|
211
|
-
* With no argument, validates every declared field against stored values and
|
|
212
|
-
* replaces `errors()` wholesale. With a patch, validates only those keys
|
|
213
|
-
* against a merged snapshot and updates errors for those keys only.
|
|
214
|
-
*
|
|
215
|
-
* Same synchronous-throw and never-reject contract as `set` / `submit`.
|
|
216
|
-
*/
|
|
217
|
-
validate(patch?: Partial<FormValues<TSchema>>): Promise<ValidateResult<TSchema>>;
|
|
218
|
-
errors(): FieldErrors<TSchema>;
|
|
219
|
-
clear(): void;
|
|
220
|
-
}
|
|
221
|
-
interface InitFormsOptions {
|
|
222
|
-
core: EmbeddablesInstance;
|
|
223
|
-
analyticsInstance?: AnalyticsInstance;
|
|
224
|
-
/** Overrides the default production backend URL for R2 persistence writes. */
|
|
225
|
-
baseUrl?: string;
|
|
226
|
-
}
|
|
227
|
-
interface FormsClient {
|
|
228
|
-
initForm<const TSchema extends FormSchema>(options: {
|
|
229
|
-
schema: TSchema;
|
|
230
|
-
customValidations?: { readonly [K in FormFieldKey<TSchema>]?: FieldValidator; };
|
|
231
|
-
}): FormInstance<TSchema>;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Validates the core instance once, then returns a per-form `initForm`. Public
|
|
235
|
-
* API — the Miro signature. Consumers pass only `core` and, optionally, an
|
|
236
|
-
* analytics client.
|
|
237
|
-
*/
|
|
238
|
-
declare function initForms(options: InitFormsOptions): FormsClient;
|
|
239
|
-
//#endregion
|
|
240
|
-
export { type AnalyticsInstance, type AnalyticsTrackEvent, type AnalyticsTrackResult, type DataUpdatedEvent, FORM_DATA_KEY, type FieldConfig, type FieldErrors, type FieldType, type FieldUpdatedEvent, type FieldUpdatedType, type FieldValidations, type FieldValidator, type FormFieldKey, type FormInstance, type FormSchema, type FormSubmittedEvent, type FormValues, type FormsAnalyticsEvent, type FormsClient, FormsError, type FormsStorage, type InitFormsOptions, type JsonValue, SchemaError, type SetResult, type SubmitResult, type ValidateResult, ValidatorError, initForms };
|
|
75
|
+
export { type AnalyticsInstance, type AnalyticsTrackEvent, type AnalyticsTrackResult, type DataUpdatedEvent, FORM_DATA_KEY, type FieldConfig, type FieldErrors, type FieldType, type FieldUpdatedEvent, type FieldUpdatedType, type FieldValidations, type FieldValidator, type FormFieldKey, type FormInstance, type FormSchema, type FormSubmittedEvent, type FormValues, type FormsAnalyticsEvent, type FormsClient, FormsError, type FormsStorage, type InitFormsOptions, type JsonValue, type ProtocolFieldId, SchemaError, type SetResult, type SubmitResult, type ValidateResult, ValidatorError, initForms };
|
|
241
76
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/errors.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/errors.ts","../src/storage/storage.ts","../../shared-types/dist/analytics-ingest.types.d.ts","../src/core/analytics.ts"],"mappings":";;;;;;;;;;;;cAWa,mBAAmB;EAClB,YAAA,iBAAiB,UAAU;;;cAO5B,oBAAoB;EACnB,YAAA,iBAAiB,UAAU;;;cAO5B,uBAAuB;EACtB,YAAA,iBAAiB,UAAU;;;;;cCvB5B;UAEI;EACf,QAAQ;EACR,QAAQ,aAAa;EACrB,WAAW;;;;KCJD;;;;;;;;KAQA,oBAAoB;KACpB;EACR;EACA;;KAsBQ,oBAAoB;EAC5B;;EAEA;EACA,YAAY;EACZ,cAAc;;EAEd;;EAEA;;KAEQ;EACR;EACA;;KAEQ,mBAAmB;EAC3B;EACA,MAAM,eAAe;;KAMb,qBAAqB;EAC7B;EACA;;;;KCpCQ,sBAAsB,mBAAmB,oBAAoB"}
|