@captello/ulc-webview-sdk 0.1.0
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 +424 -0
- package/dist/chunk-ETF52K7K.js +91 -0
- package/dist/chunk-ETF52K7K.js.map +1 -0
- package/dist/chunk-ZMYMZK2A.js +328 -0
- package/dist/chunk-ZMYMZK2A.js.map +1 -0
- package/dist/client-3IBxKbIE.d.cts +561 -0
- package/dist/client-3IBxKbIE.d.ts +561 -0
- package/dist/index.cjs +594 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +121 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -0
- package/dist/promises.cjs +366 -0
- package/dist/promises.cjs.map +1 -0
- package/dist/promises.d.cts +72 -0
- package/dist/promises.d.ts +72 -0
- package/dist/promises.js +51 -0
- package/dist/promises.js.map +1 -0
- package/dist/react.cjs +476 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +108 -0
- package/dist/react.d.ts +108 -0
- package/dist/react.js +112 -0
- package/dist/react.js.map +1 -0
- package/package.json +82 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/messages.ts
|
|
4
|
+
var OutboundMessageType = /* @__PURE__ */ ((OutboundMessageType2) => {
|
|
5
|
+
OutboundMessageType2["FormLoadComplete"] = "form_load_complete";
|
|
6
|
+
OutboundMessageType2["FormErrorMessage"] = "form_error_message";
|
|
7
|
+
OutboundMessageType2["SubmissionBody"] = "submission_body";
|
|
8
|
+
OutboundMessageType2["FormSubmitSuccess"] = "form_submit_success";
|
|
9
|
+
OutboundMessageType2["ConnexionsProfileRedirect"] = "connexions_profile_redirect";
|
|
10
|
+
OutboundMessageType2["ConnexionsDownloadVcard"] = "connexions_download_vcard";
|
|
11
|
+
return OutboundMessageType2;
|
|
12
|
+
})(OutboundMessageType || {});
|
|
13
|
+
var InboundMessageType = /* @__PURE__ */ ((InboundMessageType2) => {
|
|
14
|
+
InboundMessageType2["Submit"] = "submit_form";
|
|
15
|
+
InboundMessageType2["Reset"] = "reset_form";
|
|
16
|
+
InboundMessageType2["FormPrefill"] = "form_prefill";
|
|
17
|
+
InboundMessageType2["UpdateDraft"] = "update_draft";
|
|
18
|
+
InboundMessageType2["TriggerValidation"] = "trigger_validation";
|
|
19
|
+
return InboundMessageType2;
|
|
20
|
+
})(InboundMessageType || {});
|
|
21
|
+
var PrefillDataType = /* @__PURE__ */ ((PrefillDataType2) => {
|
|
22
|
+
PrefillDataType2["UlcSubmission"] = "ulc_submission";
|
|
23
|
+
PrefillDataType2["Info"] = "info";
|
|
24
|
+
PrefillDataType2["UlcSubmissionAndInfo"] = "ulc_submission_and_info";
|
|
25
|
+
return PrefillDataType2;
|
|
26
|
+
})(PrefillDataType || {});
|
|
27
|
+
var OUTBOUND_TYPES = new Set(Object.values(OutboundMessageType));
|
|
28
|
+
function isPlainObject(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
function parseOutboundMessage(data) {
|
|
32
|
+
let value = data;
|
|
33
|
+
if (typeof value === "string") {
|
|
34
|
+
try {
|
|
35
|
+
value = JSON.parse(value);
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!isPlainObject(value)) return null;
|
|
41
|
+
if (typeof value["type"] !== "string" || !OUTBOUND_TYPES.has(value["type"])) return null;
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/client.ts
|
|
46
|
+
var SubmissionError = class extends Error {
|
|
47
|
+
constructor(message) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.name = "SubmissionError";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var SubmissionTimeoutError = class extends Error {
|
|
53
|
+
constructor(timeoutMs) {
|
|
54
|
+
super(`Captello webview did not respond to submit within ${timeoutMs}ms.`);
|
|
55
|
+
this.timeoutMs = timeoutMs;
|
|
56
|
+
this.name = "SubmissionTimeoutError";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function devWarn(message) {
|
|
60
|
+
try {
|
|
61
|
+
if (typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production") {
|
|
62
|
+
console.warn(message);
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
var CaptelloWebview = class {
|
|
68
|
+
constructor(frame, options = {}) {
|
|
69
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
70
|
+
this.anyListeners = /* @__PURE__ */ new Set();
|
|
71
|
+
this.destroyed = false;
|
|
72
|
+
/** True once `form_load_complete` has been observed. */
|
|
73
|
+
this.ready = false;
|
|
74
|
+
/** Messages sent before ready, flushed in order on load. */
|
|
75
|
+
this.outbox = [];
|
|
76
|
+
if (!frame) {
|
|
77
|
+
throw new Error("CaptelloWebview: an iframe element (or { contentWindow }) is required.");
|
|
78
|
+
}
|
|
79
|
+
this.frame = frame;
|
|
80
|
+
this.targetOrigin = options.targetOrigin ?? "*";
|
|
81
|
+
this.matchSource = options.matchSource ?? true;
|
|
82
|
+
this.queueUntilReady = options.queueUntilReady ?? true;
|
|
83
|
+
const hostWindow = options.hostWindow ?? (typeof window !== "undefined" ? window : void 0);
|
|
84
|
+
if (!hostWindow) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
"CaptelloWebview: no host window available. Pass `hostWindow` when constructing outside a browser."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
this.hostWindow = hostWindow;
|
|
90
|
+
this.boundHandler = (event) => this.handleMessage(event);
|
|
91
|
+
this.hostWindow.addEventListener("message", this.boundHandler);
|
|
92
|
+
}
|
|
93
|
+
/** `true` once the webview has reported `form_load_complete`. */
|
|
94
|
+
get isReady() {
|
|
95
|
+
return this.ready;
|
|
96
|
+
}
|
|
97
|
+
/* -------------------------------------------------------------- *
|
|
98
|
+
* Receiving (webview → host)
|
|
99
|
+
* -------------------------------------------------------------- */
|
|
100
|
+
/**
|
|
101
|
+
* Subscribe to a single outbound message type. Returns an unsubscribe function.
|
|
102
|
+
*
|
|
103
|
+
* @example webview.on(OutboundMessageType.FormErrorMessage, (m) => toast(m.data));
|
|
104
|
+
*/
|
|
105
|
+
on(type, listener) {
|
|
106
|
+
let set = this.listeners.get(type);
|
|
107
|
+
if (!set) {
|
|
108
|
+
set = /* @__PURE__ */ new Set();
|
|
109
|
+
this.listeners.set(type, set);
|
|
110
|
+
}
|
|
111
|
+
set.add(listener);
|
|
112
|
+
return () => {
|
|
113
|
+
set?.delete(listener);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Subscribe once: the listener is removed automatically after it fires the first
|
|
118
|
+
* time for `type`. Returns an unsubscribe function for cancelling early.
|
|
119
|
+
*/
|
|
120
|
+
once(type, listener) {
|
|
121
|
+
const off = this.on(type, (message) => {
|
|
122
|
+
off();
|
|
123
|
+
listener(message);
|
|
124
|
+
});
|
|
125
|
+
return off;
|
|
126
|
+
}
|
|
127
|
+
/** Subscribe to every outbound message regardless of type. Returns an unsubscribe function. */
|
|
128
|
+
onAny(listener) {
|
|
129
|
+
this.anyListeners.add(listener);
|
|
130
|
+
return () => {
|
|
131
|
+
this.anyListeners.delete(listener);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/* -------------------------------------------------------------- *
|
|
135
|
+
* Sending (host → webview)
|
|
136
|
+
* -------------------------------------------------------------- */
|
|
137
|
+
/**
|
|
138
|
+
* Low-level send: posts any inbound message to the webview as a JSON string.
|
|
139
|
+
* Prefer the typed helpers below; use this only for forward-compatibility.
|
|
140
|
+
*
|
|
141
|
+
* When `queueUntilReady` is enabled (the default) and the form hasn't reported
|
|
142
|
+
* `form_load_complete` yet, the message is buffered and flushed on load instead of
|
|
143
|
+
* posted immediately.
|
|
144
|
+
*
|
|
145
|
+
* @throws if the iframe's `contentWindow` is not available (not yet loaded /
|
|
146
|
+
* detached) and the message can't be queued.
|
|
147
|
+
*/
|
|
148
|
+
send(message) {
|
|
149
|
+
if (this.destroyed) {
|
|
150
|
+
throw new Error("CaptelloWebview: cannot send after destroy().");
|
|
151
|
+
}
|
|
152
|
+
if (this.queueUntilReady && !this.ready) {
|
|
153
|
+
this.outbox.push(message);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this.postNow(message);
|
|
157
|
+
}
|
|
158
|
+
/** Posts a message immediately, bypassing the ready-queue. */
|
|
159
|
+
postNow(message) {
|
|
160
|
+
const target = this.frame.contentWindow;
|
|
161
|
+
if (!target) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
"CaptelloWebview: iframe.contentWindow is null. Wait for the iframe to load before sending."
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
target.postMessage(JSON.stringify(message), this.targetOrigin);
|
|
167
|
+
}
|
|
168
|
+
/** Marks the client ready and flushes any queued messages, in order. */
|
|
169
|
+
markReadyAndFlush() {
|
|
170
|
+
if (this.ready) return;
|
|
171
|
+
this.ready = true;
|
|
172
|
+
const queued = this.outbox.splice(0);
|
|
173
|
+
for (const message of queued) {
|
|
174
|
+
try {
|
|
175
|
+
this.postNow(message);
|
|
176
|
+
} catch {
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** Programmatically submit the form (fire-and-forget). */
|
|
181
|
+
submit() {
|
|
182
|
+
this.send({ type: "submit_form" /* Submit */ });
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Submit the form and await the outcome.
|
|
186
|
+
*
|
|
187
|
+
* Sends `submit_form`, then resolves with the {@link SubmissionBody} when the
|
|
188
|
+
* webview emits `submission_body`, or rejects with a {@link SubmissionError}
|
|
189
|
+
* (carrying the translated message) when it emits `form_error_message`. Rejects
|
|
190
|
+
* with a {@link SubmissionTimeoutError} if neither arrives within `timeoutMs`.
|
|
191
|
+
*
|
|
192
|
+
* This is the typed, leak-free version of the common "click submit, wait for the
|
|
193
|
+
* result" flow — listeners are always cleaned up, including on timeout.
|
|
194
|
+
*
|
|
195
|
+
* @param timeoutMs how long to wait before giving up. Defaults to 60_000.
|
|
196
|
+
* @example
|
|
197
|
+
* try {
|
|
198
|
+
* const body = await webview.submitAndWait();
|
|
199
|
+
* await persist(body);
|
|
200
|
+
* } catch (err) {
|
|
201
|
+
* if (err instanceof SubmissionError) showToast(err.message);
|
|
202
|
+
* }
|
|
203
|
+
*/
|
|
204
|
+
submitAndWait(timeoutMs = 6e4) {
|
|
205
|
+
return new Promise((resolve, reject) => {
|
|
206
|
+
let settled = false;
|
|
207
|
+
let timer;
|
|
208
|
+
const cleanup = () => {
|
|
209
|
+
settled = true;
|
|
210
|
+
offSuccess();
|
|
211
|
+
offError();
|
|
212
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
213
|
+
};
|
|
214
|
+
const offSuccess = this.on("submission_body" /* SubmissionBody */, (message) => {
|
|
215
|
+
if (settled) return;
|
|
216
|
+
cleanup();
|
|
217
|
+
resolve(message.data);
|
|
218
|
+
});
|
|
219
|
+
const offError = this.on("form_error_message" /* FormErrorMessage */, (message) => {
|
|
220
|
+
if (settled) return;
|
|
221
|
+
cleanup();
|
|
222
|
+
reject(new SubmissionError(message.data));
|
|
223
|
+
});
|
|
224
|
+
if (timeoutMs > 0 && timeoutMs !== Infinity) {
|
|
225
|
+
timer = setTimeout(() => {
|
|
226
|
+
if (settled) return;
|
|
227
|
+
cleanup();
|
|
228
|
+
reject(new SubmissionTimeoutError(timeoutMs));
|
|
229
|
+
}, timeoutMs);
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
this.send({ type: "submit_form" /* Submit */ });
|
|
233
|
+
} catch (err) {
|
|
234
|
+
if (!settled) {
|
|
235
|
+
cleanup();
|
|
236
|
+
reject(err);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/** Reset the form, clearing all entered values. */
|
|
242
|
+
reset() {
|
|
243
|
+
this.send({ type: "reset_form" /* Reset */ });
|
|
244
|
+
}
|
|
245
|
+
/** Switch the current submission into draft-update mode. */
|
|
246
|
+
updateDraft() {
|
|
247
|
+
this.send({ type: "update_draft" /* UpdateDraft */ });
|
|
248
|
+
}
|
|
249
|
+
/** Run validation against a target field, or `"all"` for the whole form. */
|
|
250
|
+
triggerValidation(target) {
|
|
251
|
+
this.send({ type: "trigger_validation" /* TriggerValidation */, target });
|
|
252
|
+
}
|
|
253
|
+
/** Pre-fill the form from a submission body (a received body or a partial). */
|
|
254
|
+
prefillSubmission(submission) {
|
|
255
|
+
this.send({
|
|
256
|
+
type: "form_prefill" /* FormPrefill */,
|
|
257
|
+
data_type: "ulc_submission" /* UlcSubmission */,
|
|
258
|
+
data: submission
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/** Pre-fill the form from a list of transcription field/value items. */
|
|
262
|
+
prefillInfo(info) {
|
|
263
|
+
this.send({
|
|
264
|
+
type: "form_prefill" /* FormPrefill */,
|
|
265
|
+
data_type: "info" /* Info */,
|
|
266
|
+
data: info
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/** Pre-fill the form from a submission plus transcription items. */
|
|
270
|
+
prefillSubmissionAndInfo(data) {
|
|
271
|
+
this.send({
|
|
272
|
+
type: "form_prefill" /* FormPrefill */,
|
|
273
|
+
data_type: "ulc_submission_and_info" /* UlcSubmissionAndInfo */,
|
|
274
|
+
data
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/* -------------------------------------------------------------- *
|
|
278
|
+
* Lifecycle
|
|
279
|
+
* -------------------------------------------------------------- */
|
|
280
|
+
/** Remove the `message` listener and drop all subscriptions. Idempotent. */
|
|
281
|
+
destroy() {
|
|
282
|
+
if (this.destroyed) return;
|
|
283
|
+
this.destroyed = true;
|
|
284
|
+
this.hostWindow.removeEventListener("message", this.boundHandler);
|
|
285
|
+
this.listeners.clear();
|
|
286
|
+
this.anyListeners.clear();
|
|
287
|
+
this.outbox.length = 0;
|
|
288
|
+
}
|
|
289
|
+
/* -------------------------------------------------------------- *
|
|
290
|
+
* Internals
|
|
291
|
+
* -------------------------------------------------------------- */
|
|
292
|
+
handleMessage(event) {
|
|
293
|
+
if (this.destroyed) return;
|
|
294
|
+
if (this.targetOrigin !== "*" && event.origin !== this.targetOrigin) {
|
|
295
|
+
if (parseOutboundMessage(event.data)) {
|
|
296
|
+
devWarn(
|
|
297
|
+
`[captello-sdk] Ignored a Captello message from origin "${event.origin}" (expected "${this.targetOrigin}"). Check the targetOrigin you passed.`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (this.matchSource) {
|
|
303
|
+
const expected = this.frame.contentWindow;
|
|
304
|
+
if (expected && event.source !== expected) {
|
|
305
|
+
if (parseOutboundMessage(event.data)) {
|
|
306
|
+
devWarn(
|
|
307
|
+
"[captello-sdk] Ignored a Captello message from an unexpected source window (not the bound iframe). If the webview relays through another window, set matchSource: false."
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const message = parseOutboundMessage(event.data);
|
|
314
|
+
if (!message) return;
|
|
315
|
+
if (message.type === "form_load_complete" /* FormLoadComplete */) {
|
|
316
|
+
this.markReadyAndFlush();
|
|
317
|
+
}
|
|
318
|
+
const set = this.listeners.get(message.type);
|
|
319
|
+
if (set) {
|
|
320
|
+
for (const listener of [...set]) listener(message);
|
|
321
|
+
}
|
|
322
|
+
if (this.anyListeners.size) {
|
|
323
|
+
for (const listener of [...this.anyListeners]) listener(message);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/embed-url.ts
|
|
329
|
+
var EmbedParam = /* @__PURE__ */ ((EmbedParam2) => {
|
|
330
|
+
EmbedParam2["FormId"] = "f";
|
|
331
|
+
EmbedParam2["SubmissionToken"] = "s";
|
|
332
|
+
EmbedParam2["StationId"] = "st";
|
|
333
|
+
EmbedParam2["Mode"] = "m";
|
|
334
|
+
EmbedParam2["EventWebAccessToken"] = "e";
|
|
335
|
+
EmbedParam2["ActivationId"] = "a";
|
|
336
|
+
EmbedParam2["Language"] = "l";
|
|
337
|
+
EmbedParam2["ActionButtonPosition"] = "b";
|
|
338
|
+
EmbedParam2["FormType"] = "form_type";
|
|
339
|
+
EmbedParam2["Launcher"] = "launcher";
|
|
340
|
+
EmbedParam2["SubmissionType"] = "t";
|
|
341
|
+
EmbedParam2["SubmitButtonBottomPadding"] = "sbbp";
|
|
342
|
+
EmbedParam2["Platform"] = "platform";
|
|
343
|
+
EmbedParam2["HideEmail"] = "he";
|
|
344
|
+
EmbedParam2["ConnexionsEmbedMode"] = "cem";
|
|
345
|
+
EmbedParam2["Emro"] = "emro";
|
|
346
|
+
EmbedParam2["UseIn"] = "useIn";
|
|
347
|
+
return EmbedParam2;
|
|
348
|
+
})(EmbedParam || {});
|
|
349
|
+
var FormMode = /* @__PURE__ */ ((FormMode2) => {
|
|
350
|
+
FormMode2["Preview"] = "preview";
|
|
351
|
+
FormMode2["Submit"] = "submit";
|
|
352
|
+
FormMode2["Edit"] = "edit";
|
|
353
|
+
FormMode2["View"] = "view";
|
|
354
|
+
return FormMode2;
|
|
355
|
+
})(FormMode || {});
|
|
356
|
+
var LauncherType = /* @__PURE__ */ ((LauncherType2) => {
|
|
357
|
+
LauncherType2["EventGenMobile"] = "event_gen_mobile";
|
|
358
|
+
LauncherType2["EventGenWeb"] = "event_gen_web";
|
|
359
|
+
LauncherType2["WebApp"] = "webapp";
|
|
360
|
+
LauncherType2["Mmp"] = "MMP";
|
|
361
|
+
return LauncherType2;
|
|
362
|
+
})(LauncherType || {});
|
|
363
|
+
var ActionButtonPosition = /* @__PURE__ */ ((ActionButtonPosition2) => {
|
|
364
|
+
ActionButtonPosition2["Fixed"] = "0";
|
|
365
|
+
ActionButtonPosition2["Bottom"] = "1";
|
|
366
|
+
ActionButtonPosition2["Hidden"] = "2";
|
|
367
|
+
return ActionButtonPosition2;
|
|
368
|
+
})(ActionButtonPosition || {});
|
|
369
|
+
var OPTION_TO_PARAM = [
|
|
370
|
+
["formId", "f" /* FormId */],
|
|
371
|
+
["submissionToken", "s" /* SubmissionToken */],
|
|
372
|
+
["stationId", "st" /* StationId */],
|
|
373
|
+
["mode", "m" /* Mode */],
|
|
374
|
+
["eventWebAccessToken", "e" /* EventWebAccessToken */],
|
|
375
|
+
["activationId", "a" /* ActivationId */],
|
|
376
|
+
["language", "l" /* Language */],
|
|
377
|
+
["actionButtonPosition", "b" /* ActionButtonPosition */],
|
|
378
|
+
["formType", "form_type" /* FormType */],
|
|
379
|
+
["launcher", "launcher" /* Launcher */],
|
|
380
|
+
["submissionType", "t" /* SubmissionType */],
|
|
381
|
+
["submitButtonBottomPadding", "sbbp" /* SubmitButtonBottomPadding */],
|
|
382
|
+
["useIn", "useIn" /* UseIn */],
|
|
383
|
+
["platform", "platform" /* Platform */]
|
|
384
|
+
];
|
|
385
|
+
var BOOLEAN_OPTION_TO_PARAM = [
|
|
386
|
+
["hideEmail", "he" /* HideEmail */],
|
|
387
|
+
["connexionsEmbedMode", "cem" /* ConnexionsEmbedMode */],
|
|
388
|
+
["emro", "emro" /* Emro */]
|
|
389
|
+
];
|
|
390
|
+
function buildEmbedUrl(baseUrl, options = {}) {
|
|
391
|
+
const url = new URL(baseUrl);
|
|
392
|
+
for (const [optionKey, paramKey] of OPTION_TO_PARAM) {
|
|
393
|
+
const value = options[optionKey];
|
|
394
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
395
|
+
url.searchParams.set(paramKey, String(value));
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
for (const [optionKey, paramKey] of BOOLEAN_OPTION_TO_PARAM) {
|
|
399
|
+
if (options[optionKey]) {
|
|
400
|
+
url.searchParams.set(paramKey, "1");
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (options.extraParams) {
|
|
404
|
+
for (const [key, value] of Object.entries(options.extraParams)) {
|
|
405
|
+
if (value !== void 0 && value !== null) {
|
|
406
|
+
url.searchParams.set(key, String(value));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return url.toString();
|
|
411
|
+
}
|
|
412
|
+
function targetOriginFromUrl(embedUrl) {
|
|
413
|
+
return new URL(embedUrl).origin;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// src/submission-data.ts
|
|
417
|
+
var FormElementType = /* @__PURE__ */ ((FormElementType2) => {
|
|
418
|
+
FormElementType2["email"] = "email";
|
|
419
|
+
FormElementType2["section"] = "section_block";
|
|
420
|
+
FormElementType2["html_block"] = "section";
|
|
421
|
+
FormElementType2["url"] = "url";
|
|
422
|
+
FormElementType2["text"] = "text";
|
|
423
|
+
FormElementType2["select"] = "select";
|
|
424
|
+
FormElementType2["radio"] = "radio";
|
|
425
|
+
FormElementType2["simple_name"] = "simple_name";
|
|
426
|
+
FormElementType2["textarea"] = "textarea";
|
|
427
|
+
FormElementType2["time"] = "time";
|
|
428
|
+
FormElementType2["address"] = "address";
|
|
429
|
+
FormElementType2["money"] = "money";
|
|
430
|
+
FormElementType2["number"] = "number";
|
|
431
|
+
FormElementType2["date"] = "date";
|
|
432
|
+
FormElementType2["phone"] = "phone";
|
|
433
|
+
FormElementType2["simple_phone"] = "simple_phone";
|
|
434
|
+
FormElementType2["checkbox"] = "checkbox";
|
|
435
|
+
FormElementType2["image"] = "image";
|
|
436
|
+
FormElementType2["business_card"] = "business_card";
|
|
437
|
+
FormElementType2["signature"] = "signature";
|
|
438
|
+
FormElementType2["barcode"] = "barcode";
|
|
439
|
+
FormElementType2["separator"] = "column_separator";
|
|
440
|
+
FormElementType2["activation"] = "activation";
|
|
441
|
+
FormElementType2["document"] = "documents";
|
|
442
|
+
FormElementType2["datetime"] = "datetime";
|
|
443
|
+
FormElementType2["meeting"] = "meeting";
|
|
444
|
+
FormElementType2["audio"] = "audio";
|
|
445
|
+
FormElementType2["rating"] = "rating";
|
|
446
|
+
FormElementType2["assign_owner"] = "assign_owner";
|
|
447
|
+
FormElementType2["boolean"] = "boolean";
|
|
448
|
+
FormElementType2["engagem_feeder"] = "engagem_feeder";
|
|
449
|
+
FormElementType2["speaker_section"] = "speaker_section_block";
|
|
450
|
+
FormElementType2["session_section"] = "session_section_block";
|
|
451
|
+
FormElementType2["image_placeholder"] = "image_placeholder";
|
|
452
|
+
FormElementType2["star_rating"] = "star_survey";
|
|
453
|
+
FormElementType2["attachments"] = "attachments";
|
|
454
|
+
return FormElementType2;
|
|
455
|
+
})(FormElementType || {});
|
|
456
|
+
var VALUED_ELEMENT_TYPES = /* @__PURE__ */ new Set([
|
|
457
|
+
"email" /* email */,
|
|
458
|
+
"url" /* url */,
|
|
459
|
+
"text" /* text */,
|
|
460
|
+
"textarea" /* textarea */,
|
|
461
|
+
"money" /* money */,
|
|
462
|
+
"number" /* number */,
|
|
463
|
+
"phone" /* phone */,
|
|
464
|
+
"simple_phone" /* simple_phone */,
|
|
465
|
+
"date" /* date */,
|
|
466
|
+
"time" /* time */,
|
|
467
|
+
"datetime" /* datetime */,
|
|
468
|
+
"audio" /* audio */,
|
|
469
|
+
"rating" /* rating */,
|
|
470
|
+
"star_survey" /* star_rating */,
|
|
471
|
+
"assign_owner" /* assign_owner */,
|
|
472
|
+
"signature" /* signature */,
|
|
473
|
+
"barcode" /* barcode */,
|
|
474
|
+
"meeting" /* meeting */,
|
|
475
|
+
"activation" /* activation */,
|
|
476
|
+
"checkbox" /* checkbox */,
|
|
477
|
+
"radio" /* radio */,
|
|
478
|
+
"select" /* select */,
|
|
479
|
+
"image" /* image */,
|
|
480
|
+
"documents" /* document */,
|
|
481
|
+
"engagem_feeder" /* engagem_feeder */,
|
|
482
|
+
"business_card" /* business_card */,
|
|
483
|
+
"boolean" /* boolean */,
|
|
484
|
+
"attachments" /* attachments */,
|
|
485
|
+
"simple_name" /* simple_name */,
|
|
486
|
+
"address" /* address */
|
|
487
|
+
]);
|
|
488
|
+
function isPlainObject2(value) {
|
|
489
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
490
|
+
}
|
|
491
|
+
function isVisibleItem(value) {
|
|
492
|
+
if (!isPlainObject2(value)) return false;
|
|
493
|
+
return typeof value["element_id"] === "string" && typeof value["element_title"] === "string" && typeof value["element_type"] === "string" && VALUED_ELEMENT_TYPES.has(value["element_type"]) && "element_value" in value;
|
|
494
|
+
}
|
|
495
|
+
function parseVisibleSubmissionsData(data) {
|
|
496
|
+
let list = data;
|
|
497
|
+
if (isPlainObject2(data) && "visible_submissions_data" in data) {
|
|
498
|
+
list = data["visible_submissions_data"];
|
|
499
|
+
}
|
|
500
|
+
if (!Array.isArray(list)) return [];
|
|
501
|
+
return list.filter(isVisibleItem);
|
|
502
|
+
}
|
|
503
|
+
var DEFAULT_OPTIONS = {
|
|
504
|
+
listSeparator: ", ",
|
|
505
|
+
booleanLabels: { true: "Yes", false: "No" },
|
|
506
|
+
emptyText: ""
|
|
507
|
+
};
|
|
508
|
+
function isOrderCheckbox(value) {
|
|
509
|
+
return isPlainObject2(value) && Array.isArray(value["values"]);
|
|
510
|
+
}
|
|
511
|
+
function isOrderRadio(value) {
|
|
512
|
+
return isPlainObject2(value) && typeof value["value"] === "string";
|
|
513
|
+
}
|
|
514
|
+
function withQuantity(value, quantity) {
|
|
515
|
+
return quantity > 1 ? `${value} (x${quantity})` : value;
|
|
516
|
+
}
|
|
517
|
+
function joinNonEmpty(parts, sep) {
|
|
518
|
+
return parts.map((p) => (p ?? "").toString().trim()).filter(Boolean).join(sep);
|
|
519
|
+
}
|
|
520
|
+
function toDisplayValue(item, options = {}) {
|
|
521
|
+
const opts = {
|
|
522
|
+
listSeparator: options.listSeparator ?? DEFAULT_OPTIONS.listSeparator,
|
|
523
|
+
booleanLabels: options.booleanLabels ?? DEFAULT_OPTIONS.booleanLabels,
|
|
524
|
+
emptyText: options.emptyText ?? DEFAULT_OPTIONS.emptyText
|
|
525
|
+
};
|
|
526
|
+
const sep = opts.listSeparator;
|
|
527
|
+
const value = item.element_value;
|
|
528
|
+
switch (item.element_type) {
|
|
529
|
+
case "simple_name" /* simple_name */:
|
|
530
|
+
return joinNonEmpty(Object.values(value), " ") || opts.emptyText;
|
|
531
|
+
case "address" /* address */:
|
|
532
|
+
return joinNonEmpty(Object.values(value), sep) || opts.emptyText;
|
|
533
|
+
case "boolean" /* boolean */:
|
|
534
|
+
return value ? opts.booleanLabels.true : opts.booleanLabels.false;
|
|
535
|
+
case "checkbox" /* checkbox */:
|
|
536
|
+
if (Array.isArray(value)) return joinNonEmpty(value, sep) || opts.emptyText;
|
|
537
|
+
if (isOrderCheckbox(value)) {
|
|
538
|
+
const items = value.values.map((v) => withQuantity(v.value, v.quantity));
|
|
539
|
+
return joinNonEmpty([...items, value.note], sep) || opts.emptyText;
|
|
540
|
+
}
|
|
541
|
+
return opts.emptyText;
|
|
542
|
+
case "radio" /* radio */:
|
|
543
|
+
case "select" /* select */:
|
|
544
|
+
if (typeof value === "string") return value || opts.emptyText;
|
|
545
|
+
if (isOrderRadio(value)) {
|
|
546
|
+
return joinNonEmpty([withQuantity(value.value, value.quantity), value.note], sep) || opts.emptyText;
|
|
547
|
+
}
|
|
548
|
+
return opts.emptyText;
|
|
549
|
+
case "image" /* image */:
|
|
550
|
+
return joinNonEmpty(value, sep) || opts.emptyText;
|
|
551
|
+
case "documents" /* document */:
|
|
552
|
+
return joinNonEmpty(value.map(String), sep) || opts.emptyText;
|
|
553
|
+
case "attachments" /* attachments */:
|
|
554
|
+
return joinNonEmpty(
|
|
555
|
+
value.map((a) => a.name),
|
|
556
|
+
sep
|
|
557
|
+
) || opts.emptyText;
|
|
558
|
+
case "engagem_feeder" /* engagem_feeder */:
|
|
559
|
+
return value.map((q) => joinNonEmpty([q.question, q.answers.join("/")], ": ")).filter(Boolean).join("; ") || opts.emptyText;
|
|
560
|
+
case "business_card" /* business_card */: {
|
|
561
|
+
const bc = value;
|
|
562
|
+
return joinNonEmpty([bc.front, bc.back], sep) || opts.emptyText;
|
|
563
|
+
}
|
|
564
|
+
default:
|
|
565
|
+
return typeof value === "string" ? value || opts.emptyText : opts.emptyText;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
function toDisplayPairs(data, options) {
|
|
569
|
+
return parseVisibleSubmissionsData(data).map((item) => ({
|
|
570
|
+
elementId: item.element_id,
|
|
571
|
+
label: item.element_title,
|
|
572
|
+
value: toDisplayValue(item, options)
|
|
573
|
+
}));
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
exports.ActionButtonPosition = ActionButtonPosition;
|
|
577
|
+
exports.CaptelloWebview = CaptelloWebview;
|
|
578
|
+
exports.EmbedParam = EmbedParam;
|
|
579
|
+
exports.FormElementType = FormElementType;
|
|
580
|
+
exports.FormMode = FormMode;
|
|
581
|
+
exports.InboundMessageType = InboundMessageType;
|
|
582
|
+
exports.LauncherType = LauncherType;
|
|
583
|
+
exports.OutboundMessageType = OutboundMessageType;
|
|
584
|
+
exports.PrefillDataType = PrefillDataType;
|
|
585
|
+
exports.SubmissionError = SubmissionError;
|
|
586
|
+
exports.SubmissionTimeoutError = SubmissionTimeoutError;
|
|
587
|
+
exports.buildEmbedUrl = buildEmbedUrl;
|
|
588
|
+
exports.parseOutboundMessage = parseOutboundMessage;
|
|
589
|
+
exports.parseVisibleSubmissionsData = parseVisibleSubmissionsData;
|
|
590
|
+
exports.targetOriginFromUrl = targetOriginFromUrl;
|
|
591
|
+
exports.toDisplayPairs = toDisplayPairs;
|
|
592
|
+
exports.toDisplayValue = toDisplayValue;
|
|
593
|
+
//# sourceMappingURL=index.cjs.map
|
|
594
|
+
//# sourceMappingURL=index.cjs.map
|