@cxpinsight/survey-spec 0.5.0 → 0.5.1
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/dist/validate.d.ts +13 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +30 -2
- package/package.json +2 -2
package/dist/validate.d.ts
CHANGED
|
@@ -33,7 +33,19 @@ export declare function impliedChoices(question: ValidatableQuestion): string[];
|
|
|
33
33
|
* it records. One place, so "Activate discount" reads the same on a website,
|
|
34
34
|
* a link and a phone.
|
|
35
35
|
*/
|
|
36
|
-
export declare function impliedActions(question: ValidatableQuestion
|
|
36
|
+
export declare function impliedActions(question: ValidatableQuestion,
|
|
37
|
+
/**
|
|
38
|
+
* Resolves {{references}} in the destination. Optional only so existing
|
|
39
|
+
* callers keep working; every renderer should pass one.
|
|
40
|
+
*
|
|
41
|
+
* A destination is authored as a TEMPLATE — "https://shop.example/cart/
|
|
42
|
+
* {{eventData.orderId}}" is the entire point of an abandoned-cart nudge —
|
|
43
|
+
* and until this existed the href was handed to the renderers verbatim. So
|
|
44
|
+
* the button navigated to a literal `{{eventData.orderId}}`, on the link
|
|
45
|
+
* surface and on React Native, sending someone to a 404 in the one moment
|
|
46
|
+
* the interaction exists to convert.
|
|
47
|
+
*/
|
|
48
|
+
interpolate?: (s: string) => string): Array<{
|
|
37
49
|
value: string;
|
|
38
50
|
label: string;
|
|
39
51
|
href?: string;
|
package/dist/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAkDjE,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE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336
|
* it records. One place, so "Activate discount" reads the same on a website,
|
|
337
337
|
* a link and a phone.
|
|
338
338
|
*/
|
|
339
|
-
function impliedActions(question
|
|
339
|
+
function impliedActions(question,
|
|
340
|
+
/**
|
|
341
|
+
* Resolves {{references}} in the destination. Optional only so existing
|
|
342
|
+
* callers keep working; every renderer should pass one.
|
|
343
|
+
*
|
|
344
|
+
* A destination is authored as a TEMPLATE — "https://shop.example/cart/
|
|
345
|
+
* {{eventData.orderId}}" is the entire point of an abandoned-cart nudge —
|
|
346
|
+
* and until this existed the href was handed to the renderers verbatim. So
|
|
347
|
+
* the button navigated to a literal `{{eventData.orderId}}`, on the link
|
|
348
|
+
* surface and on React Native, sending someone to a 404 in the one moment
|
|
349
|
+
* the interaction exists to convert.
|
|
350
|
+
*/
|
|
351
|
+
interpolate = (s) => s) {
|
|
340
352
|
const raw = question.choices
|
|
341
353
|
|| question.options;
|
|
342
354
|
if (!Array.isArray(raw))
|
|
@@ -356,7 +368,23 @@ function impliedActions(question) {
|
|
|
356
368
|
// function returned only {value, label}, and so a "Resume" button on an
|
|
357
369
|
// abandoned-cart nudge recorded the answer and left the customer exactly
|
|
358
370
|
// where they were — which is the one thing that nudge exists to change.
|
|
359
|
-
|
|
371
|
+
// Interpolated BEFORE the scheme check, never after: a template that
|
|
372
|
+
// resolves to `javascript:` has to be caught on what it BECAME, not on
|
|
373
|
+
// the harmless-looking string it started as.
|
|
374
|
+
const rawHref = (o.action && typeof o.action === 'object')
|
|
375
|
+
? o.action.value
|
|
376
|
+
: undefined;
|
|
377
|
+
const resolved = typeof rawHref === 'string' && rawHref
|
|
378
|
+
? interpolate(rawHref)
|
|
379
|
+
: rawHref;
|
|
380
|
+
// A reference that resolved to nothing leaves the braces behind. Sending
|
|
381
|
+
// someone to a URL with `{{...}}` still in it is worse than not moving
|
|
382
|
+
// them: the answer is recorded either way, and a 404 reads as the
|
|
383
|
+
// product being broken rather than a destination being unset.
|
|
384
|
+
const usable = typeof resolved === 'string' && /\{\{.*\}\}/.test(resolved)
|
|
385
|
+
? undefined
|
|
386
|
+
: resolved;
|
|
387
|
+
const href = safeActionHref(usable === undefined ? undefined : { ...o.action, value: usable });
|
|
360
388
|
if (value !== '' || label !== '') {
|
|
361
389
|
const entry = href ? { value, label: label || value, href } : { value, label: label || value };
|
|
362
390
|
// "Remind me later" — see isDeferChoice. Carried through because a
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cxpinsight/survey-spec",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "The survey specification the renderers share
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "The survey specification the renderers share — expression evaluation first. Source of truth for behaviour that must be identical on web, links and mobile.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|