@guidelytech/shared 0.2.0 → 0.4.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/dist/chunk-QUKMOTT4.js +477 -0
- package/dist/chunk-QUKMOTT4.js.map +1 -0
- package/dist/index.cjs +267 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +352 -83
- package/dist/index.d.ts +352 -83
- package/dist/index.js +124 -7
- package/dist/index.js.map +1 -1
- package/dist/runtime.cjs +181 -4
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.cts +191 -2
- package/dist/runtime.d.ts +191 -2
- package/dist/runtime.js +47 -3
- package/package.json +1 -1
package/dist/runtime.d.ts
CHANGED
|
@@ -15,9 +15,70 @@ declare function stripOrigin(url: string): string;
|
|
|
15
15
|
/** Safe regexp construction with a length cap to limit ReDoS exposure. */
|
|
16
16
|
declare function safeRegExp(source: string, flags?: string): RegExp | null;
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Cross-platform helpers shared by the web SDK, the React Native SDK and (as a reference for) the
|
|
20
|
+
* native iOS/Android SDKs. Zod-free so it can ship in runtime bundles.
|
|
21
|
+
*/
|
|
22
|
+
/** Platforms a guide can be delivered to. */
|
|
23
|
+
declare const PLATFORMS: readonly ["web", "ios", "android"];
|
|
24
|
+
type Platform = (typeof PLATFORMS)[number];
|
|
25
|
+
/** Guides published before platforms existed have no `platforms` field and are web-only. */
|
|
26
|
+
declare const DEFAULT_PLATFORMS: Platform[];
|
|
27
|
+
/** Platforms a guide config targets (missing field → web only). */
|
|
28
|
+
declare function guidePlatforms(config: {
|
|
29
|
+
platforms?: readonly string[] | null;
|
|
30
|
+
}): string[];
|
|
31
|
+
declare function supportsPlatform(config: {
|
|
32
|
+
platforms?: readonly string[] | null;
|
|
33
|
+
}, platform: string): boolean;
|
|
34
|
+
/** Attribute web apps put on elements to share a target id with their mobile apps. */
|
|
35
|
+
declare const GUIDELY_ID_ATTRIBUTE = "data-guidely-id";
|
|
36
|
+
/**
|
|
37
|
+
* Extracts a Guidely target id from a trigger / advance / checklist value so the same guide works on
|
|
38
|
+
* web and mobile. Accepts a bare id (`new-deal`), `#new-deal`, or `[data-guidely-id="new-deal"]`
|
|
39
|
+
* (also `data-testid` / `data-tour`). Returns null for selectors that cannot name a single id.
|
|
40
|
+
*/
|
|
41
|
+
declare function guidelyIdFromSelector(value: string | null | undefined): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* Mobile SDKs have screens instead of URLs. URL-based features (URL patterns, `url_match` triggers,
|
|
44
|
+
* multi-page steps, `url_visited` checklist tasks) match against the screen path `/<ScreenName>`.
|
|
45
|
+
*/
|
|
46
|
+
declare function screenPath(screen: string | null | undefined): string;
|
|
47
|
+
/**
|
|
48
|
+
* Compares dotted version strings numerically (`2.10.0` > `2.9.3`). Non-numeric parts compare as
|
|
49
|
+
* strings; a missing part counts as 0 (`2.1` == `2.1.0`). Returns -1, 0 or 1, or null when either
|
|
50
|
+
* side is empty.
|
|
51
|
+
*/
|
|
52
|
+
declare function compareVersions(a: unknown, b: unknown): -1 | 0 | 1 | null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Pure checklist / survey logic shared by every renderer (web runtime, React Native, and the
|
|
56
|
+
* reference for the native SDKs). Zod-free; uses structural types so it stays in the runtime entry.
|
|
57
|
+
*/
|
|
58
|
+
type SurveyAnswer = string | number | boolean | string[];
|
|
59
|
+
type SurveyAnswers = Record<string, SurveyAnswer>;
|
|
60
|
+
interface ShowWhen {
|
|
61
|
+
questionId: string;
|
|
62
|
+
op: "equals" | "lte" | "gte" | "in";
|
|
63
|
+
value: string | number | string[];
|
|
64
|
+
}
|
|
65
|
+
/** Evaluates a question's `showWhen` condition against current answers. */
|
|
66
|
+
declare function isQuestionVisible(q: {
|
|
67
|
+
showWhen?: ShowWhen;
|
|
68
|
+
}, answers: SurveyAnswers): boolean;
|
|
69
|
+
/** Are all required tasks done? */
|
|
70
|
+
declare function isChecklistComplete(config: {
|
|
71
|
+
tasks: Array<{
|
|
72
|
+
id: string;
|
|
73
|
+
required: boolean;
|
|
74
|
+
}>;
|
|
75
|
+
}, progress: {
|
|
76
|
+
completedTaskIds: string[];
|
|
77
|
+
}): boolean;
|
|
78
|
+
|
|
18
79
|
declare const RULE_OPERATORS: readonly ["equals", "not_equals", "contains", "not_contains", "starts_with", "ends_with", "exists", "not_exists", "gt", "gte", "lt", "lte", "in", "not_in", "regex", "is_true", "is_false", "before", "after"];
|
|
19
80
|
type RuleOperator = (typeof RULE_OPERATORS)[number];
|
|
20
|
-
declare const RULE_FIELDS: readonly ["user.attribute", "account.attribute", "user.role", "user.plan", "url.path", "url.full", "url.query", "device.type", "device.browser", "device.os", "visitor.firstVisit", "visitor.returning", "event.seen", "guide.completed", "guide.dismissed", "guide.seen", "checklist.completed", "audience.member", "datetime.now", "datetime.dayOfWeek", "datetime.hour", "rollout.percentage", "environment", "locale"];
|
|
81
|
+
declare const RULE_FIELDS: readonly ["user.attribute", "account.attribute", "user.role", "user.plan", "url.path", "url.full", "url.query", "device.type", "device.browser", "device.os", "visitor.firstVisit", "visitor.returning", "event.seen", "guide.completed", "guide.dismissed", "guide.seen", "checklist.completed", "audience.member", "datetime.now", "datetime.dayOfWeek", "datetime.hour", "rollout.percentage", "environment", "locale", "app.platform", "app.screen", "app.version"];
|
|
21
82
|
type RuleField = (typeof RULE_FIELDS)[number];
|
|
22
83
|
interface Rule {
|
|
23
84
|
id: string;
|
|
@@ -61,6 +122,12 @@ interface TargetingContext {
|
|
|
61
122
|
now: Date;
|
|
62
123
|
environment: string;
|
|
63
124
|
locale?: string;
|
|
125
|
+
/** `web`, `ios` or `android`. Missing means web. */
|
|
126
|
+
platform?: string;
|
|
127
|
+
/** Current screen name (mobile SDKs; set via `screen()`). */
|
|
128
|
+
screen?: string;
|
|
129
|
+
/** Host app version (mobile SDKs), e.g. `2.4.1`. */
|
|
130
|
+
appVersion?: string;
|
|
64
131
|
/** Salt for rollout (guide id). Set per guide before evaluating. */
|
|
65
132
|
rolloutSalt?: string;
|
|
66
133
|
}
|
|
@@ -77,4 +144,126 @@ declare const SENSITIVE_PROPERTY_PATTERN: RegExp;
|
|
|
77
144
|
declare const MAX_PROPERTY_BYTES: number;
|
|
78
145
|
declare function sanitizeProperties(props: Record<string, unknown> | undefined): Record<string, unknown>;
|
|
79
146
|
|
|
80
|
-
|
|
147
|
+
/** One parsed stack frame. `file` is the script URL (or path) as the browser reported it. */
|
|
148
|
+
interface StackFrame {
|
|
149
|
+
fn?: string;
|
|
150
|
+
file?: string;
|
|
151
|
+
line?: number;
|
|
152
|
+
col?: number;
|
|
153
|
+
}
|
|
154
|
+
/** Properties carried by an `exception` event (see `docs/product-analytics.md`). */
|
|
155
|
+
interface ExceptionProperties {
|
|
156
|
+
type: string;
|
|
157
|
+
message: string;
|
|
158
|
+
frames: StackFrame[];
|
|
159
|
+
/** `onerror` | `unhandledrejection` | `manual` (captureException) | `console`. */
|
|
160
|
+
source?: string;
|
|
161
|
+
handled?: boolean;
|
|
162
|
+
/** App version or commit (SDK option `release`); selects the matching uploaded source maps. */
|
|
163
|
+
release?: string;
|
|
164
|
+
/** Set by the server at ingestion; groups occurrences into an issue. */
|
|
165
|
+
fingerprint?: string;
|
|
166
|
+
}
|
|
167
|
+
declare const MAX_STACK_FRAMES = 30;
|
|
168
|
+
/** Parses `Error.stack` from V8, SpiderMonkey and JavaScriptCore into frames (innermost first). */
|
|
169
|
+
declare function parseStack(stack: string | undefined | null, max?: number): StackFrame[];
|
|
170
|
+
/** Replaces volatile parts of a message (numbers, ids, quoted values) so repeats group together. */
|
|
171
|
+
declare function normalizeErrorMessage(message: string): string;
|
|
172
|
+
/** Strips origin, query, hash and build hashes (`main.3f2a1b9c.js` → `main.js`) from a script URL. */
|
|
173
|
+
declare function normalizeFrameFile(file: string | undefined): string;
|
|
174
|
+
/** Source map upload limits (`POST /api/v1/sourcemaps/upload`). */
|
|
175
|
+
declare const SOURCEMAP_MAX_FILE_BYTES: number;
|
|
176
|
+
declare const SOURCEMAP_MAX_FILES_PER_UPLOAD = 200;
|
|
177
|
+
/**
|
|
178
|
+
* Stable issue key for an exception: error type + normalised message + the innermost frame that
|
|
179
|
+
* has a file (path without build hash + function name, or its original source + name when a source
|
|
180
|
+
* map resolved it). Line/column numbers are left out because they change with every deploy of a
|
|
181
|
+
* minified bundle.
|
|
182
|
+
*/
|
|
183
|
+
declare function fingerprintError(input: {
|
|
184
|
+
type?: string;
|
|
185
|
+
message?: string;
|
|
186
|
+
frames?: StackFrame[];
|
|
187
|
+
original?: {
|
|
188
|
+
source: string;
|
|
189
|
+
name?: string | null;
|
|
190
|
+
} | null;
|
|
191
|
+
}): string;
|
|
192
|
+
|
|
193
|
+
/** rrweb plugin name for network events in recordings (event type 6, `data.plugin`). */
|
|
194
|
+
declare const NETWORK_PLUGIN = "guidely/network@1";
|
|
195
|
+
/** Request kinds, from `fetch`/`XMLHttpRequest` patching or `PerformanceResourceTiming.initiatorType`. */
|
|
196
|
+
type NetworkRequestType = "fetch" | "xhr" | "websocket" | "document" | "script" | "stylesheet" | "image" | "font" | "media" | "beacon" | "other";
|
|
197
|
+
/**
|
|
198
|
+
* One network request in a recording: the payload of an rrweb plugin event
|
|
199
|
+
* `{ type: 6, data: { plugin: NETWORK_PLUGIN, payload: NetworkPluginPayload } }`, batched.
|
|
200
|
+
* Times are epoch milliseconds (same clock as rrweb event timestamps).
|
|
201
|
+
*
|
|
202
|
+
* A WebSocket is a request with `type: "websocket"` and `method: "GET"`, emitted when it opens
|
|
203
|
+
* (`startTime`) and again, with the same `id`, when it closes (`endTime`, `closeCode`, `closeReason`,
|
|
204
|
+
* totals in `messages`). Its frames are `WebSocketMessage`s referencing that `id`.
|
|
205
|
+
*/
|
|
206
|
+
interface NetworkRequest {
|
|
207
|
+
/** Stable id within the recording. */
|
|
208
|
+
id: string;
|
|
209
|
+
type: NetworkRequestType;
|
|
210
|
+
method: string;
|
|
211
|
+
/** Absolute URL; values of sensitive-looking query parameters replaced with `[redacted]`. */
|
|
212
|
+
url: string;
|
|
213
|
+
startTime: number;
|
|
214
|
+
endTime?: number;
|
|
215
|
+
durationMs?: number;
|
|
216
|
+
/** HTTP status; 0 for network errors / blocked / aborted. Absent when the browser doesn't expose it. */
|
|
217
|
+
status?: number;
|
|
218
|
+
/** Set for failed requests: network error, abort or timeout message. */
|
|
219
|
+
error?: string;
|
|
220
|
+
/** Encoded bytes transferred / decoded response size, when known. */
|
|
221
|
+
transferSize?: number;
|
|
222
|
+
responseSize?: number;
|
|
223
|
+
/** Only when `recordNetworkPayloads` is on; sensitive headers are `[redacted]`. */
|
|
224
|
+
requestHeaders?: Record<string, string>;
|
|
225
|
+
responseHeaders?: Record<string, string>;
|
|
226
|
+
/** Text/JSON bodies, ≤10KB, sensitive JSON fields masked; `[binary]` / `[truncated]` markers otherwise. */
|
|
227
|
+
requestBody?: string;
|
|
228
|
+
responseBody?: string;
|
|
229
|
+
/** WebSocket only: negotiated subprotocol, close details, and frame totals (all frames, including ones not recorded). */
|
|
230
|
+
protocol?: string;
|
|
231
|
+
closeCode?: number;
|
|
232
|
+
closeReason?: string;
|
|
233
|
+
messages?: {
|
|
234
|
+
sent: number;
|
|
235
|
+
received: number;
|
|
236
|
+
sentBytes: number;
|
|
237
|
+
receivedBytes: number;
|
|
238
|
+
recorded: number;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** One WebSocket frame. At most `WS_MAX_MESSAGES_PER_SOCKET` are recorded per connection per page load. */
|
|
242
|
+
interface WebSocketMessage {
|
|
243
|
+
/** The `NetworkRequest.id` of the connection. */
|
|
244
|
+
socketId: string;
|
|
245
|
+
dir: "send" | "recv";
|
|
246
|
+
time: number;
|
|
247
|
+
/** Bytes (UTF-8 length for text frames). */
|
|
248
|
+
size: number;
|
|
249
|
+
binary?: boolean;
|
|
250
|
+
/** Only with `recordNetworkPayloads`: text ≤ 2KB (JSON with sensitive keys masked), else `[truncated]`; binary frames are `[binary <n> B]`. */
|
|
251
|
+
data?: string;
|
|
252
|
+
}
|
|
253
|
+
interface NetworkPluginPayload {
|
|
254
|
+
requests?: NetworkRequest[];
|
|
255
|
+
messages?: WebSocketMessage[];
|
|
256
|
+
/** Requests/frames dropped since the previous payload because a cap was reached. */
|
|
257
|
+
dropped?: {
|
|
258
|
+
requests?: number;
|
|
259
|
+
messages?: number;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
declare const WS_MAX_MESSAGES_PER_SOCKET = 200;
|
|
263
|
+
declare const WS_MAX_MESSAGE_BYTES = 2048;
|
|
264
|
+
/** Header names always replaced with `[redacted]` when payload capture is on. */
|
|
265
|
+
declare const SENSITIVE_HEADER_PATTERN: RegExp;
|
|
266
|
+
/** Query parameter and JSON field names whose values are redacted. */
|
|
267
|
+
declare const SENSITIVE_PARAM_PATTERN: RegExp;
|
|
268
|
+
|
|
269
|
+
export { DEFAULT_PLATFORMS, type ExceptionProperties, GUIDELY_ID_ATTRIBUTE, MAX_PROPERTY_BYTES, MAX_STACK_FRAMES, NETWORK_PLUGIN, type NetworkPluginPayload, type NetworkRequest, type NetworkRequestType, PLATFORMS, type Platform, RULE_FIELDS, RULE_OPERATORS, type Rule, type RuleField, type RuleGroup, type RuleOperator, SENSITIVE_HEADER_PATTERN, SENSITIVE_PARAM_PATTERN, SENSITIVE_PROPERTY_PATTERN, SERVER_ASSISTED_FIELDS, SOURCEMAP_MAX_FILES_PER_UPLOAD, SOURCEMAP_MAX_FILE_BYTES, type ShowWhen, type StackFrame, type SurveyAnswer, type SurveyAnswers, type TargetingContext, WS_MAX_MESSAGES_PER_SOCKET, WS_MAX_MESSAGE_BYTES, type WebSocketMessage, clamp, compare, compareVersions, describeRule, emptyRuleGroup, evaluateRule, evaluateRules, fingerprintError, fnv1a, getPath, guidePlatforms, guidelyIdFromSelector, isChecklistComplete, isPlainObject, isQuestionVisible, isRuleGroup, matchUrlPattern, normalizeErrorMessage, normalizeFrameFile, parseStack, randomId, rolloutBucket, safeRegExp, sanitizeProperties, screenPath, slugify, stripOrigin, supportsPlatform };
|
package/dist/runtime.js
CHANGED
|
@@ -1,49 +1,93 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_PLATFORMS,
|
|
3
|
+
GUIDELY_ID_ATTRIBUTE,
|
|
2
4
|
MAX_PROPERTY_BYTES,
|
|
5
|
+
MAX_STACK_FRAMES,
|
|
6
|
+
NETWORK_PLUGIN,
|
|
7
|
+
PLATFORMS,
|
|
3
8
|
RULE_FIELDS,
|
|
4
9
|
RULE_OPERATORS,
|
|
10
|
+
SENSITIVE_HEADER_PATTERN,
|
|
11
|
+
SENSITIVE_PARAM_PATTERN,
|
|
5
12
|
SENSITIVE_PROPERTY_PATTERN,
|
|
6
13
|
SERVER_ASSISTED_FIELDS,
|
|
14
|
+
SOURCEMAP_MAX_FILES_PER_UPLOAD,
|
|
15
|
+
SOURCEMAP_MAX_FILE_BYTES,
|
|
16
|
+
WS_MAX_MESSAGES_PER_SOCKET,
|
|
17
|
+
WS_MAX_MESSAGE_BYTES,
|
|
7
18
|
clamp,
|
|
8
19
|
compare,
|
|
20
|
+
compareVersions,
|
|
9
21
|
describeRule,
|
|
10
22
|
emptyRuleGroup,
|
|
11
23
|
evaluateRule,
|
|
12
24
|
evaluateRules,
|
|
25
|
+
fingerprintError,
|
|
13
26
|
fnv1a,
|
|
14
27
|
getPath,
|
|
28
|
+
guidePlatforms,
|
|
29
|
+
guidelyIdFromSelector,
|
|
30
|
+
isChecklistComplete,
|
|
15
31
|
isPlainObject,
|
|
32
|
+
isQuestionVisible,
|
|
16
33
|
isRuleGroup,
|
|
17
34
|
matchUrlPattern,
|
|
35
|
+
normalizeErrorMessage,
|
|
36
|
+
normalizeFrameFile,
|
|
37
|
+
parseStack,
|
|
18
38
|
randomId,
|
|
19
39
|
rolloutBucket,
|
|
20
40
|
safeRegExp,
|
|
21
41
|
sanitizeProperties,
|
|
42
|
+
screenPath,
|
|
22
43
|
slugify,
|
|
23
|
-
stripOrigin
|
|
24
|
-
|
|
44
|
+
stripOrigin,
|
|
45
|
+
supportsPlatform
|
|
46
|
+
} from "./chunk-QUKMOTT4.js";
|
|
25
47
|
export {
|
|
48
|
+
DEFAULT_PLATFORMS,
|
|
49
|
+
GUIDELY_ID_ATTRIBUTE,
|
|
26
50
|
MAX_PROPERTY_BYTES,
|
|
51
|
+
MAX_STACK_FRAMES,
|
|
52
|
+
NETWORK_PLUGIN,
|
|
53
|
+
PLATFORMS,
|
|
27
54
|
RULE_FIELDS,
|
|
28
55
|
RULE_OPERATORS,
|
|
56
|
+
SENSITIVE_HEADER_PATTERN,
|
|
57
|
+
SENSITIVE_PARAM_PATTERN,
|
|
29
58
|
SENSITIVE_PROPERTY_PATTERN,
|
|
30
59
|
SERVER_ASSISTED_FIELDS,
|
|
60
|
+
SOURCEMAP_MAX_FILES_PER_UPLOAD,
|
|
61
|
+
SOURCEMAP_MAX_FILE_BYTES,
|
|
62
|
+
WS_MAX_MESSAGES_PER_SOCKET,
|
|
63
|
+
WS_MAX_MESSAGE_BYTES,
|
|
31
64
|
clamp,
|
|
32
65
|
compare,
|
|
66
|
+
compareVersions,
|
|
33
67
|
describeRule,
|
|
34
68
|
emptyRuleGroup,
|
|
35
69
|
evaluateRule,
|
|
36
70
|
evaluateRules,
|
|
71
|
+
fingerprintError,
|
|
37
72
|
fnv1a,
|
|
38
73
|
getPath,
|
|
74
|
+
guidePlatforms,
|
|
75
|
+
guidelyIdFromSelector,
|
|
76
|
+
isChecklistComplete,
|
|
39
77
|
isPlainObject,
|
|
78
|
+
isQuestionVisible,
|
|
40
79
|
isRuleGroup,
|
|
41
80
|
matchUrlPattern,
|
|
81
|
+
normalizeErrorMessage,
|
|
82
|
+
normalizeFrameFile,
|
|
83
|
+
parseStack,
|
|
42
84
|
randomId,
|
|
43
85
|
rolloutBucket,
|
|
44
86
|
safeRegExp,
|
|
45
87
|
sanitizeProperties,
|
|
88
|
+
screenPath,
|
|
46
89
|
slugify,
|
|
47
|
-
stripOrigin
|
|
90
|
+
stripOrigin,
|
|
91
|
+
supportsPlatform
|
|
48
92
|
};
|
|
49
93
|
//# sourceMappingURL=runtime.js.map
|