@usertour/helpers 0.0.43 → 0.0.45
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/__tests__/get-attribute-type.test.cjs +147 -52
- package/dist/__tests__/get-attribute-type.test.js +133 -25
- package/dist/__tests__/url.test.cjs +6 -0
- package/dist/__tests__/url.test.js +6 -0
- package/dist/attribute.cjs +21 -31
- package/dist/attribute.d.cts +17 -1
- package/dist/attribute.d.ts +17 -1
- package/dist/attribute.js +5 -3
- package/dist/chunk-MU3AHQEC.js +141 -0
- package/dist/{chunk-EEYZG4JJ.js → chunk-R4R6MDTW.js} +19 -30
- package/dist/content.cjs +86 -2
- package/dist/content.d.cts +4 -2
- package/dist/content.d.ts +4 -2
- package/dist/content.js +8 -3
- package/dist/index.cjs +94 -29
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -4
- package/package.json +2 -2
- package/dist/chunk-VWNWWZCH.js +0 -63
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isUndefined
|
|
3
|
+
} from "./chunk-GFH3VWOC.js";
|
|
4
|
+
|
|
5
|
+
// src/content.ts
|
|
6
|
+
import {
|
|
7
|
+
ContentEditorElementType,
|
|
8
|
+
ContentPriority
|
|
9
|
+
} from "@usertour/types";
|
|
10
|
+
import { deepmerge } from "deepmerge-ts";
|
|
11
|
+
var isPublishedInAllEnvironments = (content, environmentList, version) => {
|
|
12
|
+
var _a;
|
|
13
|
+
if (!((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) || !(environmentList == null ? void 0 : environmentList.length) || !(version == null ? void 0 : version.id)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return environmentList.every(
|
|
17
|
+
(env) => {
|
|
18
|
+
var _a2;
|
|
19
|
+
return (_a2 = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a2.some(
|
|
20
|
+
(item) => item.published && item.publishedVersionId === version.id && item.environment.id === env.id
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
var isPublishedAtLeastOneEnvironment = (content) => {
|
|
26
|
+
var _a;
|
|
27
|
+
if ((content == null ? void 0 : content.contentOnEnvironments) && ((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) > 0) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
var rulesSetting = {
|
|
33
|
+
// frequency: {
|
|
34
|
+
// frequency: Frequency.ONCE,
|
|
35
|
+
// every: { duration: 0, times: 1, unit: FrequencyUnits.MINUTES },
|
|
36
|
+
// atLeast: { duration: 0, unit: FrequencyUnits.MINUTES },
|
|
37
|
+
// },
|
|
38
|
+
startIfNotComplete: false,
|
|
39
|
+
priority: ContentPriority.MEDIUM,
|
|
40
|
+
wait: 0
|
|
41
|
+
};
|
|
42
|
+
var hideRulesSetting = {};
|
|
43
|
+
var defaultContentConfig = {
|
|
44
|
+
enabledAutoStartRules: false,
|
|
45
|
+
enabledHideRules: false,
|
|
46
|
+
autoStartRules: [],
|
|
47
|
+
hideRules: [],
|
|
48
|
+
autoStartRulesSetting: rulesSetting,
|
|
49
|
+
hideRulesSetting
|
|
50
|
+
};
|
|
51
|
+
var buildConfig = (config) => {
|
|
52
|
+
return {
|
|
53
|
+
...defaultContentConfig,
|
|
54
|
+
...config,
|
|
55
|
+
autoStartRulesSetting: deepmerge(
|
|
56
|
+
defaultContentConfig.autoStartRulesSetting,
|
|
57
|
+
(config == null ? void 0 : config.autoStartRulesSetting) || {}
|
|
58
|
+
),
|
|
59
|
+
hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
var extractLinkUrl = (value, userAttributes) => {
|
|
63
|
+
let url = "";
|
|
64
|
+
try {
|
|
65
|
+
for (const v of value) {
|
|
66
|
+
if ("children" in v && Array.isArray(v.children)) {
|
|
67
|
+
for (const vc of v.children) {
|
|
68
|
+
if ("type" in vc && vc.type === "user-attribute") {
|
|
69
|
+
if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
|
|
70
|
+
const attrValue = userAttributes[vc.attrCode];
|
|
71
|
+
const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
|
|
72
|
+
url += attrValue != null ? attrValue : fallback;
|
|
73
|
+
} else if ("fallback" in vc && typeof vc.fallback === "string") {
|
|
74
|
+
url += vc.fallback;
|
|
75
|
+
}
|
|
76
|
+
} else if ("text" in vc && typeof vc.text === "string") {
|
|
77
|
+
url += vc.text;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (_) {
|
|
83
|
+
}
|
|
84
|
+
return url;
|
|
85
|
+
};
|
|
86
|
+
var replaceUserAttrForElement = (data, userAttributes) => {
|
|
87
|
+
return data.map((v) => {
|
|
88
|
+
if (v.children) {
|
|
89
|
+
v.children = replaceUserAttrForElement(v.children, userAttributes);
|
|
90
|
+
}
|
|
91
|
+
if (v.type === "user-attribute" && userAttributes) {
|
|
92
|
+
const value = userAttributes[v.attrCode] || v.fallback;
|
|
93
|
+
if (!isUndefined(value)) {
|
|
94
|
+
v.value = String(value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (v.type === "link" && userAttributes) {
|
|
98
|
+
v.url = v.data ? extractLinkUrl(v.data, userAttributes) : "";
|
|
99
|
+
}
|
|
100
|
+
return v;
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
var replaceUserAttr = (editorContents, userAttributes) => {
|
|
104
|
+
return editorContents.map((editorContent) => {
|
|
105
|
+
if (!editorContent.children) {
|
|
106
|
+
return editorContent;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...editorContent,
|
|
110
|
+
children: editorContent.children.map((column) => {
|
|
111
|
+
if (!column.children) {
|
|
112
|
+
return column;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
...column,
|
|
116
|
+
children: column.children.map((element) => {
|
|
117
|
+
if (element.element.type === ContentEditorElementType.TEXT) {
|
|
118
|
+
return {
|
|
119
|
+
...element,
|
|
120
|
+
element: {
|
|
121
|
+
...element.element,
|
|
122
|
+
data: replaceUserAttrForElement(element.element.data, userAttributes)
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return { ...element };
|
|
127
|
+
})
|
|
128
|
+
};
|
|
129
|
+
})
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
isPublishedInAllEnvironments,
|
|
136
|
+
isPublishedAtLeastOneEnvironment,
|
|
137
|
+
defaultContentConfig,
|
|
138
|
+
buildConfig,
|
|
139
|
+
extractLinkUrl,
|
|
140
|
+
replaceUserAttr
|
|
141
|
+
};
|
|
@@ -4,47 +4,35 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/attribute.ts
|
|
6
6
|
import { BizAttributeTypes } from "@usertour/types";
|
|
7
|
-
import { isValid, parseISO
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
return year >= 1900 && year <= 2100;
|
|
11
|
-
};
|
|
12
|
-
var tryParseDate = (parser) => {
|
|
13
|
-
try {
|
|
14
|
-
const date = parser();
|
|
15
|
-
return isValid(date) && isValidYear(date);
|
|
16
|
-
} catch {
|
|
7
|
+
import { isValid, parseISO } from "date-fns";
|
|
8
|
+
var isValidISO8601 = (value) => {
|
|
9
|
+
if (typeof value !== "string") {
|
|
17
10
|
return false;
|
|
18
11
|
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (!Number.isNaN(Number(dateStr)) || dateStr.length < 10) {
|
|
12
|
+
const iso8601Pattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/;
|
|
13
|
+
if (!iso8601Pattern.test(value)) {
|
|
22
14
|
return false;
|
|
23
15
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
];
|
|
36
|
-
if (tryParseDate(() => parseISO(dateStr))) {
|
|
37
|
-
return true;
|
|
16
|
+
try {
|
|
17
|
+
const date = parseISO(value);
|
|
18
|
+
if (!isValid(date)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const isoString = date.toISOString();
|
|
22
|
+
const normalizedInput = value.replace(/\.\d{3}Z$/, "Z");
|
|
23
|
+
const normalizedIso = isoString.replace(/\.\d{3}Z$/, "Z");
|
|
24
|
+
return normalizedInput === normalizedIso || value === isoString;
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
38
27
|
}
|
|
39
|
-
|
|
40
|
-
}
|
|
28
|
+
};
|
|
41
29
|
var getAttributeType = (attribute) => {
|
|
42
30
|
const t = typeof attribute;
|
|
43
31
|
if (t === "number") {
|
|
44
32
|
return BizAttributeTypes.Number;
|
|
45
33
|
}
|
|
46
34
|
if (t === "string") {
|
|
47
|
-
if (
|
|
35
|
+
if (isValidISO8601(attribute)) {
|
|
48
36
|
return BizAttributeTypes.DateTime;
|
|
49
37
|
}
|
|
50
38
|
return BizAttributeTypes.String;
|
|
@@ -72,6 +60,7 @@ var filterNullAttributes = (attributes) => {
|
|
|
72
60
|
};
|
|
73
61
|
|
|
74
62
|
export {
|
|
63
|
+
isValidISO8601,
|
|
75
64
|
getAttributeType,
|
|
76
65
|
capitalizeFirstLetter,
|
|
77
66
|
filterNullAttributes
|
package/dist/content.cjs
CHANGED
|
@@ -22,12 +22,23 @@ var content_exports = {};
|
|
|
22
22
|
__export(content_exports, {
|
|
23
23
|
buildConfig: () => buildConfig,
|
|
24
24
|
defaultContentConfig: () => defaultContentConfig,
|
|
25
|
+
extractLinkUrl: () => extractLinkUrl,
|
|
25
26
|
isPublishedAtLeastOneEnvironment: () => isPublishedAtLeastOneEnvironment,
|
|
26
|
-
isPublishedInAllEnvironments: () => isPublishedInAllEnvironments
|
|
27
|
+
isPublishedInAllEnvironments: () => isPublishedInAllEnvironments,
|
|
28
|
+
replaceUserAttr: () => replaceUserAttr
|
|
27
29
|
});
|
|
28
30
|
module.exports = __toCommonJS(content_exports);
|
|
29
31
|
var import_types = require("@usertour/types");
|
|
30
32
|
var import_deepmerge_ts = require("deepmerge-ts");
|
|
33
|
+
|
|
34
|
+
// src/type-utils.ts
|
|
35
|
+
var nativeIsArray = Array.isArray;
|
|
36
|
+
var ObjProto = Object.prototype;
|
|
37
|
+
var objToString = ObjProto.toString;
|
|
38
|
+
var objHasOwn = ObjProto.hasOwnProperty;
|
|
39
|
+
var isUndefined = (x) => x === void 0;
|
|
40
|
+
|
|
41
|
+
// src/content.ts
|
|
31
42
|
var isPublishedInAllEnvironments = (content, environmentList, version) => {
|
|
32
43
|
var _a;
|
|
33
44
|
if (!((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) || !(environmentList == null ? void 0 : environmentList.length) || !(version == null ? void 0 : version.id)) {
|
|
@@ -79,10 +90,83 @@ var buildConfig = (config) => {
|
|
|
79
90
|
hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
|
|
80
91
|
};
|
|
81
92
|
};
|
|
93
|
+
var extractLinkUrl = (value, userAttributes) => {
|
|
94
|
+
let url = "";
|
|
95
|
+
try {
|
|
96
|
+
for (const v of value) {
|
|
97
|
+
if ("children" in v && Array.isArray(v.children)) {
|
|
98
|
+
for (const vc of v.children) {
|
|
99
|
+
if ("type" in vc && vc.type === "user-attribute") {
|
|
100
|
+
if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
|
|
101
|
+
const attrValue = userAttributes[vc.attrCode];
|
|
102
|
+
const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
|
|
103
|
+
url += attrValue != null ? attrValue : fallback;
|
|
104
|
+
} else if ("fallback" in vc && typeof vc.fallback === "string") {
|
|
105
|
+
url += vc.fallback;
|
|
106
|
+
}
|
|
107
|
+
} else if ("text" in vc && typeof vc.text === "string") {
|
|
108
|
+
url += vc.text;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} catch (_) {
|
|
114
|
+
}
|
|
115
|
+
return url;
|
|
116
|
+
};
|
|
117
|
+
var replaceUserAttrForElement = (data, userAttributes) => {
|
|
118
|
+
return data.map((v) => {
|
|
119
|
+
if (v.children) {
|
|
120
|
+
v.children = replaceUserAttrForElement(v.children, userAttributes);
|
|
121
|
+
}
|
|
122
|
+
if (v.type === "user-attribute" && userAttributes) {
|
|
123
|
+
const value = userAttributes[v.attrCode] || v.fallback;
|
|
124
|
+
if (!isUndefined(value)) {
|
|
125
|
+
v.value = String(value);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (v.type === "link" && userAttributes) {
|
|
129
|
+
v.url = v.data ? extractLinkUrl(v.data, userAttributes) : "";
|
|
130
|
+
}
|
|
131
|
+
return v;
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
var replaceUserAttr = (editorContents, userAttributes) => {
|
|
135
|
+
return editorContents.map((editorContent) => {
|
|
136
|
+
if (!editorContent.children) {
|
|
137
|
+
return editorContent;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
...editorContent,
|
|
141
|
+
children: editorContent.children.map((column) => {
|
|
142
|
+
if (!column.children) {
|
|
143
|
+
return column;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
...column,
|
|
147
|
+
children: column.children.map((element) => {
|
|
148
|
+
if (element.element.type === import_types.ContentEditorElementType.TEXT) {
|
|
149
|
+
return {
|
|
150
|
+
...element,
|
|
151
|
+
element: {
|
|
152
|
+
...element.element,
|
|
153
|
+
data: replaceUserAttrForElement(element.element.data, userAttributes)
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return { ...element };
|
|
158
|
+
})
|
|
159
|
+
};
|
|
160
|
+
})
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
};
|
|
82
164
|
// Annotate the CommonJS export names for ESM import in node:
|
|
83
165
|
0 && (module.exports = {
|
|
84
166
|
buildConfig,
|
|
85
167
|
defaultContentConfig,
|
|
168
|
+
extractLinkUrl,
|
|
86
169
|
isPublishedAtLeastOneEnvironment,
|
|
87
|
-
isPublishedInAllEnvironments
|
|
170
|
+
isPublishedInAllEnvironments,
|
|
171
|
+
replaceUserAttr
|
|
88
172
|
});
|
package/dist/content.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Content, Environment, ContentVersion, ContentConfigObject } from '@usertour/types';
|
|
1
|
+
import { Content, Environment, ContentVersion, ContentConfigObject, UserTourTypes, ContentEditorRoot } from '@usertour/types';
|
|
2
2
|
|
|
3
3
|
declare const isPublishedInAllEnvironments: (content: Content | null, environmentList: Environment[] | null, version: ContentVersion | null) => boolean;
|
|
4
4
|
declare const isPublishedAtLeastOneEnvironment: (content: Content | null) => boolean;
|
|
5
5
|
declare const defaultContentConfig: ContentConfigObject;
|
|
6
6
|
declare const buildConfig: (config: ContentConfigObject | undefined) => ContentConfigObject;
|
|
7
|
+
declare const extractLinkUrl: (value: any[], userAttributes: UserTourTypes.Attributes) => string;
|
|
8
|
+
declare const replaceUserAttr: (editorContents: ContentEditorRoot[], userAttributes: UserTourTypes.Attributes) => ContentEditorRoot[];
|
|
7
9
|
|
|
8
|
-
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments };
|
|
10
|
+
export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr };
|
package/dist/content.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Content, Environment, ContentVersion, ContentConfigObject } from '@usertour/types';
|
|
1
|
+
import { Content, Environment, ContentVersion, ContentConfigObject, UserTourTypes, ContentEditorRoot } from '@usertour/types';
|
|
2
2
|
|
|
3
3
|
declare const isPublishedInAllEnvironments: (content: Content | null, environmentList: Environment[] | null, version: ContentVersion | null) => boolean;
|
|
4
4
|
declare const isPublishedAtLeastOneEnvironment: (content: Content | null) => boolean;
|
|
5
5
|
declare const defaultContentConfig: ContentConfigObject;
|
|
6
6
|
declare const buildConfig: (config: ContentConfigObject | undefined) => ContentConfigObject;
|
|
7
|
+
declare const extractLinkUrl: (value: any[], userAttributes: UserTourTypes.Attributes) => string;
|
|
8
|
+
declare const replaceUserAttr: (editorContents: ContentEditorRoot[], userAttributes: UserTourTypes.Attributes) => ContentEditorRoot[];
|
|
7
9
|
|
|
8
|
-
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments };
|
|
10
|
+
export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr };
|
package/dist/content.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildConfig,
|
|
3
3
|
defaultContentConfig,
|
|
4
|
+
extractLinkUrl,
|
|
4
5
|
isPublishedAtLeastOneEnvironment,
|
|
5
|
-
isPublishedInAllEnvironments
|
|
6
|
-
|
|
6
|
+
isPublishedInAllEnvironments,
|
|
7
|
+
replaceUserAttr
|
|
8
|
+
} from "./chunk-MU3AHQEC.js";
|
|
9
|
+
import "./chunk-GFH3VWOC.js";
|
|
7
10
|
import "./chunk-XEO3YXBM.js";
|
|
8
11
|
export {
|
|
9
12
|
buildConfig,
|
|
10
13
|
defaultContentConfig,
|
|
14
|
+
extractLinkUrl,
|
|
11
15
|
isPublishedAtLeastOneEnvironment,
|
|
12
|
-
isPublishedInAllEnvironments
|
|
16
|
+
isPublishedInAllEnvironments,
|
|
17
|
+
replaceUserAttr
|
|
13
18
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -60,6 +60,7 @@ __export(src_exports, {
|
|
|
60
60
|
evaluateRulesConditions: () => evaluateRulesConditions,
|
|
61
61
|
evaluateTimeCondition: () => evaluateTimeCondition,
|
|
62
62
|
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
63
|
+
extractLinkUrl: () => extractLinkUrl,
|
|
63
64
|
fetch: () => fetch,
|
|
64
65
|
filterConditionsByType: () => filterConditionsByType,
|
|
65
66
|
filterNullAttributes: () => filterNullAttributes,
|
|
@@ -111,6 +112,7 @@ __export(src_exports, {
|
|
|
111
112
|
isUint8Array: () => isUint8Array,
|
|
112
113
|
isUndefined: () => isUndefined,
|
|
113
114
|
isUrl: () => isUrl,
|
|
115
|
+
isValidISO8601: () => isValidISO8601,
|
|
114
116
|
isValidSelector: () => isValidSelector,
|
|
115
117
|
location: () => location,
|
|
116
118
|
mergeThemeDefaultSettings: () => mergeThemeDefaultSettings,
|
|
@@ -121,6 +123,7 @@ __export(src_exports, {
|
|
|
121
123
|
parseUrlParams: () => parseUrlParams,
|
|
122
124
|
regenerateConditionIds: () => regenerateConditionIds,
|
|
123
125
|
removeAuthToken: () => removeAuthToken,
|
|
126
|
+
replaceUserAttr: () => replaceUserAttr,
|
|
124
127
|
setAuthToken: () => setAuthToken,
|
|
125
128
|
storage: () => storage,
|
|
126
129
|
userAgent: () => userAgent,
|
|
@@ -1050,6 +1053,77 @@ var buildConfig = (config) => {
|
|
|
1050
1053
|
hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
|
|
1051
1054
|
};
|
|
1052
1055
|
};
|
|
1056
|
+
var extractLinkUrl = (value, userAttributes) => {
|
|
1057
|
+
let url = "";
|
|
1058
|
+
try {
|
|
1059
|
+
for (const v of value) {
|
|
1060
|
+
if ("children" in v && Array.isArray(v.children)) {
|
|
1061
|
+
for (const vc of v.children) {
|
|
1062
|
+
if ("type" in vc && vc.type === "user-attribute") {
|
|
1063
|
+
if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
|
|
1064
|
+
const attrValue = userAttributes[vc.attrCode];
|
|
1065
|
+
const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
|
|
1066
|
+
url += attrValue != null ? attrValue : fallback;
|
|
1067
|
+
} else if ("fallback" in vc && typeof vc.fallback === "string") {
|
|
1068
|
+
url += vc.fallback;
|
|
1069
|
+
}
|
|
1070
|
+
} else if ("text" in vc && typeof vc.text === "string") {
|
|
1071
|
+
url += vc.text;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
} catch (_) {
|
|
1077
|
+
}
|
|
1078
|
+
return url;
|
|
1079
|
+
};
|
|
1080
|
+
var replaceUserAttrForElement = (data, userAttributes) => {
|
|
1081
|
+
return data.map((v) => {
|
|
1082
|
+
if (v.children) {
|
|
1083
|
+
v.children = replaceUserAttrForElement(v.children, userAttributes);
|
|
1084
|
+
}
|
|
1085
|
+
if (v.type === "user-attribute" && userAttributes) {
|
|
1086
|
+
const value = userAttributes[v.attrCode] || v.fallback;
|
|
1087
|
+
if (!isUndefined(value)) {
|
|
1088
|
+
v.value = String(value);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
if (v.type === "link" && userAttributes) {
|
|
1092
|
+
v.url = v.data ? extractLinkUrl(v.data, userAttributes) : "";
|
|
1093
|
+
}
|
|
1094
|
+
return v;
|
|
1095
|
+
});
|
|
1096
|
+
};
|
|
1097
|
+
var replaceUserAttr = (editorContents, userAttributes) => {
|
|
1098
|
+
return editorContents.map((editorContent) => {
|
|
1099
|
+
if (!editorContent.children) {
|
|
1100
|
+
return editorContent;
|
|
1101
|
+
}
|
|
1102
|
+
return {
|
|
1103
|
+
...editorContent,
|
|
1104
|
+
children: editorContent.children.map((column) => {
|
|
1105
|
+
if (!column.children) {
|
|
1106
|
+
return column;
|
|
1107
|
+
}
|
|
1108
|
+
return {
|
|
1109
|
+
...column,
|
|
1110
|
+
children: column.children.map((element) => {
|
|
1111
|
+
if (element.element.type === import_types3.ContentEditorElementType.TEXT) {
|
|
1112
|
+
return {
|
|
1113
|
+
...element,
|
|
1114
|
+
element: {
|
|
1115
|
+
...element.element,
|
|
1116
|
+
data: replaceUserAttrForElement(element.element.data, userAttributes)
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
return { ...element };
|
|
1121
|
+
})
|
|
1122
|
+
};
|
|
1123
|
+
})
|
|
1124
|
+
};
|
|
1125
|
+
});
|
|
1126
|
+
};
|
|
1053
1127
|
|
|
1054
1128
|
// src/utils.ts
|
|
1055
1129
|
var deepClone = (obj) => {
|
|
@@ -1561,46 +1635,34 @@ var allConditionsHaveIds = (conditions) => {
|
|
|
1561
1635
|
// src/attribute.ts
|
|
1562
1636
|
var import_types6 = require("@usertour/types");
|
|
1563
1637
|
var import_date_fns3 = require("date-fns");
|
|
1564
|
-
var
|
|
1565
|
-
|
|
1566
|
-
return year >= 1900 && year <= 2100;
|
|
1567
|
-
};
|
|
1568
|
-
var tryParseDate = (parser) => {
|
|
1569
|
-
try {
|
|
1570
|
-
const date = parser();
|
|
1571
|
-
return (0, import_date_fns3.isValid)(date) && isValidYear(date);
|
|
1572
|
-
} catch {
|
|
1638
|
+
var isValidISO8601 = (value) => {
|
|
1639
|
+
if (typeof value !== "string") {
|
|
1573
1640
|
return false;
|
|
1574
1641
|
}
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
if (!Number.isNaN(Number(dateStr)) || dateStr.length < 10) {
|
|
1642
|
+
const iso8601Pattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/;
|
|
1643
|
+
if (!iso8601Pattern.test(value)) {
|
|
1578
1644
|
return false;
|
|
1579
1645
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
"
|
|
1587
|
-
"
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
];
|
|
1592
|
-
if (tryParseDate(() => (0, import_date_fns3.parseISO)(dateStr))) {
|
|
1593
|
-
return true;
|
|
1646
|
+
try {
|
|
1647
|
+
const date = (0, import_date_fns3.parseISO)(value);
|
|
1648
|
+
if (!(0, import_date_fns3.isValid)(date)) {
|
|
1649
|
+
return false;
|
|
1650
|
+
}
|
|
1651
|
+
const isoString = date.toISOString();
|
|
1652
|
+
const normalizedInput = value.replace(/\.\d{3}Z$/, "Z");
|
|
1653
|
+
const normalizedIso = isoString.replace(/\.\d{3}Z$/, "Z");
|
|
1654
|
+
return normalizedInput === normalizedIso || value === isoString;
|
|
1655
|
+
} catch {
|
|
1656
|
+
return false;
|
|
1594
1657
|
}
|
|
1595
|
-
|
|
1596
|
-
}
|
|
1658
|
+
};
|
|
1597
1659
|
var getAttributeType = (attribute) => {
|
|
1598
1660
|
const t = typeof attribute;
|
|
1599
1661
|
if (t === "number") {
|
|
1600
1662
|
return import_types6.BizAttributeTypes.Number;
|
|
1601
1663
|
}
|
|
1602
1664
|
if (t === "string") {
|
|
1603
|
-
if (
|
|
1665
|
+
if (isValidISO8601(attribute)) {
|
|
1604
1666
|
return import_types6.BizAttributeTypes.DateTime;
|
|
1605
1667
|
}
|
|
1606
1668
|
return import_types6.BizAttributeTypes.String;
|
|
@@ -1653,6 +1715,7 @@ var filterNullAttributes = (attributes) => {
|
|
|
1653
1715
|
evaluateRulesConditions,
|
|
1654
1716
|
evaluateTimeCondition,
|
|
1655
1717
|
evaluateUrlCondition,
|
|
1718
|
+
extractLinkUrl,
|
|
1656
1719
|
fetch,
|
|
1657
1720
|
filterConditionsByType,
|
|
1658
1721
|
filterNullAttributes,
|
|
@@ -1704,6 +1767,7 @@ var filterNullAttributes = (attributes) => {
|
|
|
1704
1767
|
isUint8Array,
|
|
1705
1768
|
isUndefined,
|
|
1706
1769
|
isUrl,
|
|
1770
|
+
isValidISO8601,
|
|
1707
1771
|
isValidSelector,
|
|
1708
1772
|
location,
|
|
1709
1773
|
mergeThemeDefaultSettings,
|
|
@@ -1714,6 +1778,7 @@ var filterNullAttributes = (attributes) => {
|
|
|
1714
1778
|
parseUrlParams,
|
|
1715
1779
|
regenerateConditionIds,
|
|
1716
1780
|
removeAuthToken,
|
|
1781
|
+
replaceUserAttr,
|
|
1717
1782
|
setAuthToken,
|
|
1718
1783
|
storage,
|
|
1719
1784
|
userAgent,
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ export { getAuthToken, removeAuthToken, setAuthToken, storage } from './auth.cjs
|
|
|
5
5
|
export { defaultStep } from './settings.cjs';
|
|
6
6
|
export { isUrl } from './is-url.cjs';
|
|
7
7
|
export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.cjs';
|
|
8
|
-
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.cjs';
|
|
8
|
+
export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr } from './content.cjs';
|
|
9
9
|
export { deepClone, parseUrlParams, wait } from './utils.cjs';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
|
|
@@ -13,7 +13,7 @@ export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRul
|
|
|
13
13
|
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.cjs';
|
|
14
14
|
export { convertTimeConditionLegacyToV2, evaluateTimeCondition, isTimeConditionDataLegacy, isTimeConditionDataV2, normalizeTimeConditionData } from './conditions/time.cjs';
|
|
15
15
|
export { evaluateAttributeCondition } from './conditions/attribute.cjs';
|
|
16
|
-
export { capitalizeFirstLetter, filterNullAttributes, getAttributeType } from './attribute.cjs';
|
|
16
|
+
export { capitalizeFirstLetter, filterNullAttributes, getAttributeType, isValidISO8601 } from './attribute.cjs';
|
|
17
17
|
export { default as isEqual } from 'fast-deep-equal';
|
|
18
18
|
import '@usertour/types';
|
|
19
19
|
import './storage.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { getAuthToken, removeAuthToken, setAuthToken, storage } from './auth.js'
|
|
|
5
5
|
export { defaultStep } from './settings.js';
|
|
6
6
|
export { isUrl } from './is-url.js';
|
|
7
7
|
export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.js';
|
|
8
|
-
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.js';
|
|
8
|
+
export { buildConfig, defaultContentConfig, extractLinkUrl, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments, replaceUserAttr } from './content.js';
|
|
9
9
|
export { deepClone, parseUrlParams, wait } from './utils.js';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.js';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
|
|
@@ -13,7 +13,7 @@ export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRul
|
|
|
13
13
|
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.js';
|
|
14
14
|
export { convertTimeConditionLegacyToV2, evaluateTimeCondition, isTimeConditionDataLegacy, isTimeConditionDataV2, normalizeTimeConditionData } from './conditions/time.js';
|
|
15
15
|
export { evaluateAttributeCondition } from './conditions/attribute.js';
|
|
16
|
-
export { capitalizeFirstLetter, filterNullAttributes, getAttributeType } from './attribute.js';
|
|
16
|
+
export { capitalizeFirstLetter, filterNullAttributes, getAttributeType, isValidISO8601 } from './attribute.js';
|
|
17
17
|
export { default as isEqual } from 'fast-deep-equal';
|
|
18
18
|
import '@usertour/types';
|
|
19
19
|
import './storage.js';
|
package/dist/index.js
CHANGED
|
@@ -12,8 +12,9 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
capitalizeFirstLetter,
|
|
14
14
|
filterNullAttributes,
|
|
15
|
-
getAttributeType
|
|
16
|
-
|
|
15
|
+
getAttributeType,
|
|
16
|
+
isValidISO8601
|
|
17
|
+
} from "./chunk-R4R6MDTW.js";
|
|
17
18
|
import {
|
|
18
19
|
getAuthToken,
|
|
19
20
|
removeAuthToken,
|
|
@@ -55,9 +56,11 @@ import {
|
|
|
55
56
|
import {
|
|
56
57
|
buildConfig,
|
|
57
58
|
defaultContentConfig,
|
|
59
|
+
extractLinkUrl,
|
|
58
60
|
isPublishedAtLeastOneEnvironment,
|
|
59
|
-
isPublishedInAllEnvironments
|
|
60
|
-
|
|
61
|
+
isPublishedInAllEnvironments,
|
|
62
|
+
replaceUserAttr
|
|
63
|
+
} from "./chunk-MU3AHQEC.js";
|
|
61
64
|
import {
|
|
62
65
|
convertSettings,
|
|
63
66
|
convertToCssVars,
|
|
@@ -152,6 +155,7 @@ export {
|
|
|
152
155
|
evaluateRulesConditions,
|
|
153
156
|
evaluateTimeCondition,
|
|
154
157
|
evaluateUrlCondition,
|
|
158
|
+
extractLinkUrl,
|
|
155
159
|
fetch,
|
|
156
160
|
filterConditionsByType,
|
|
157
161
|
filterNullAttributes,
|
|
@@ -203,6 +207,7 @@ export {
|
|
|
203
207
|
isUint8Array,
|
|
204
208
|
isUndefined,
|
|
205
209
|
isUrl,
|
|
210
|
+
isValidISO8601,
|
|
206
211
|
isValidSelector,
|
|
207
212
|
location,
|
|
208
213
|
mergeThemeDefaultSettings,
|
|
@@ -213,6 +218,7 @@ export {
|
|
|
213
218
|
parseUrlParams,
|
|
214
219
|
regenerateConditionIds,
|
|
215
220
|
removeAuthToken,
|
|
221
|
+
replaceUserAttr,
|
|
216
222
|
setAuthToken,
|
|
217
223
|
storage,
|
|
218
224
|
userAgent,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usertour/helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.45",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Utility functions and helpers shared across the UserTour project",
|
|
6
6
|
"homepage": "https://www.usertour.io",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
32
|
-
"@usertour/types": "^0.0.
|
|
32
|
+
"@usertour/types": "^0.0.31",
|
|
33
33
|
"chroma-js": "^3.1.2",
|
|
34
34
|
"class-variance-authority": "^0.4.0",
|
|
35
35
|
"clsx": "^1.2.1",
|