@levo-so/core 0.1.35 → 0.1.36
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/client.d.ts +72 -0
- package/dist/constants/media.d.ts +1 -1
- package/dist/control/audience.d.ts +13 -0
- package/dist/control/audience.d.ts.map +1 -0
- package/dist/control/index.d.ts +23 -0
- package/dist/control/index.d.ts.map +1 -0
- package/dist/httpClient.d.ts +13 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1124 -70
- package/dist/logger/batch.d.ts +3 -10
- package/dist/logger/batch.d.ts.map +1 -1
- package/dist/logger/index.d.ts +22 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/modules/blog.d.ts +10 -0
- package/dist/modules/blog.d.ts.map +1 -0
- package/dist/modules/collection.d.ts +25 -0
- package/dist/modules/collection.d.ts.map +1 -0
- package/dist/{plugins/LevoMedia.d.ts → modules/media.d.ts} +6 -4
- package/dist/modules/media.d.ts.map +1 -0
- package/dist/modules/membership.d.ts +21 -0
- package/dist/modules/membership.d.ts.map +1 -0
- package/package.json +3 -1
- package/dist/LevoClient.d.ts +0 -38
- package/dist/chunk-OT564SO4.js +0 -69
- package/dist/chunk-QJSKNLTV.js +0 -9
- package/dist/chunk-ZLLCLSGE.js +0 -8
- package/dist/plugins/LevoAudience.d.ts +0 -32
- package/dist/plugins/LevoAudience.d.ts.map +0 -1
- package/dist/plugins/LevoAudience.js +0 -561
- package/dist/plugins/LevoBlog.d.ts +0 -8
- package/dist/plugins/LevoBlog.d.ts.map +0 -1
- package/dist/plugins/LevoBlog.js +0 -21
- package/dist/plugins/LevoCollection.d.ts +0 -23
- package/dist/plugins/LevoCollection.d.ts.map +0 -1
- package/dist/plugins/LevoCollection.js +0 -47
- package/dist/plugins/LevoLogger.d.ts +0 -32
- package/dist/plugins/LevoLogger.d.ts.map +0 -1
- package/dist/plugins/LevoLogger.js +0 -193
- package/dist/plugins/LevoMedia.d.ts.map +0 -1
- package/dist/plugins/LevoMedia.js +0 -13
- package/dist/plugins/LevoMembership.d.ts +0 -38
- package/dist/plugins/LevoMembership.d.ts.map +0 -1
- package/dist/plugins/LevoMembership.js +0 -104
- package/dist/plugins/LevoPlugin.d.ts +0 -6
- package/dist/plugins/LevoPlugin.d.ts.map +0 -1
- package/dist/plugins/LevoPlugin.js +0 -1
|
@@ -1,561 +0,0 @@
|
|
|
1
|
-
import { LocalStorageLock, getLevoError } from '../chunk-OT564SO4.js';
|
|
2
|
-
import { LevoPlugin } from '../chunk-QJSKNLTV.js';
|
|
3
|
-
import { onUserActivity } from '@analytics/activity-utils';
|
|
4
|
-
import { getVisitorSource } from '@analytics/visitor-source';
|
|
5
|
-
import { Analytics } from 'analytics';
|
|
6
|
-
import wretch from 'wretch';
|
|
7
|
-
import getUserLocale from 'get-user-locale';
|
|
8
|
-
|
|
9
|
-
// src/utils/isIncognito.ts
|
|
10
|
-
var isIncognito = () => new Promise((resolve, reject) => {
|
|
11
|
-
let browserName = "Unknown";
|
|
12
|
-
function __callback(isPrivate) {
|
|
13
|
-
resolve({
|
|
14
|
-
isPrivate,
|
|
15
|
-
browserName
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
function identifyChromium() {
|
|
19
|
-
const ua = navigator.userAgent;
|
|
20
|
-
if (ua.match(/Chrome/)) {
|
|
21
|
-
if (navigator.brave !== void 0) {
|
|
22
|
-
return "Brave";
|
|
23
|
-
}
|
|
24
|
-
if (ua.match(/Edg/)) {
|
|
25
|
-
return "Edge";
|
|
26
|
-
}
|
|
27
|
-
if (ua.match(/OPR/)) {
|
|
28
|
-
return "Opera";
|
|
29
|
-
}
|
|
30
|
-
return "Chrome";
|
|
31
|
-
}
|
|
32
|
-
return "Chromium";
|
|
33
|
-
}
|
|
34
|
-
function assertEvalToString(value) {
|
|
35
|
-
return value === eval.toString().length;
|
|
36
|
-
}
|
|
37
|
-
function isSafari() {
|
|
38
|
-
const v = navigator.vendor;
|
|
39
|
-
return v !== void 0 && v.indexOf("Apple") === 0 && assertEvalToString(37);
|
|
40
|
-
}
|
|
41
|
-
function isChrome() {
|
|
42
|
-
const v = navigator.vendor;
|
|
43
|
-
return v !== void 0 && v.indexOf("Google") === 0 && assertEvalToString(33);
|
|
44
|
-
}
|
|
45
|
-
function isFirefox() {
|
|
46
|
-
return document.documentElement !== void 0 && document.documentElement.style.MozAppearance !== void 0 && assertEvalToString(37);
|
|
47
|
-
}
|
|
48
|
-
function isMSIE() {
|
|
49
|
-
return navigator.msSaveBlob !== void 0 && assertEvalToString(39);
|
|
50
|
-
}
|
|
51
|
-
function newSafariTest() {
|
|
52
|
-
const tmp_name = String(Math.random());
|
|
53
|
-
try {
|
|
54
|
-
const db = window.indexedDB.open(tmp_name, 1);
|
|
55
|
-
db.onupgradeneeded = (i) => {
|
|
56
|
-
const res = i.target?.result;
|
|
57
|
-
try {
|
|
58
|
-
res.createObjectStore("test", {
|
|
59
|
-
autoIncrement: true
|
|
60
|
-
}).put(new Blob());
|
|
61
|
-
__callback(false);
|
|
62
|
-
} catch (e) {
|
|
63
|
-
let message = e;
|
|
64
|
-
if (e instanceof Error) {
|
|
65
|
-
message = e.message ?? e;
|
|
66
|
-
}
|
|
67
|
-
if (typeof message !== "string") {
|
|
68
|
-
return __callback(false);
|
|
69
|
-
}
|
|
70
|
-
const matchesExpectedError = /BlobURLs are not yet supported/.test(
|
|
71
|
-
message
|
|
72
|
-
);
|
|
73
|
-
return __callback(matchesExpectedError);
|
|
74
|
-
} finally {
|
|
75
|
-
res.close();
|
|
76
|
-
window.indexedDB.deleteDatabase(tmp_name);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
} catch (e) {
|
|
80
|
-
return __callback(false);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function oldSafariTest() {
|
|
84
|
-
const openDB = window.openDatabase;
|
|
85
|
-
const storage = window.localStorage;
|
|
86
|
-
try {
|
|
87
|
-
openDB(null, null, null, null);
|
|
88
|
-
} catch (e) {
|
|
89
|
-
return __callback(true);
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
storage.setItem("test", "1");
|
|
93
|
-
storage.removeItem("test");
|
|
94
|
-
} catch (e) {
|
|
95
|
-
return __callback(true);
|
|
96
|
-
}
|
|
97
|
-
return __callback(false);
|
|
98
|
-
}
|
|
99
|
-
function safariPrivateTest() {
|
|
100
|
-
if (navigator.maxTouchPoints !== void 0) {
|
|
101
|
-
newSafariTest();
|
|
102
|
-
} else {
|
|
103
|
-
oldSafariTest();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function getQuotaLimit() {
|
|
107
|
-
const w = window;
|
|
108
|
-
if (w.performance !== void 0 && w.performance.memory !== void 0 && w.performance.memory.jsHeapSizeLimit !== void 0) {
|
|
109
|
-
return performance.memory.jsHeapSizeLimit;
|
|
110
|
-
}
|
|
111
|
-
return 1073741824;
|
|
112
|
-
}
|
|
113
|
-
function storageQuotaChromePrivateTest() {
|
|
114
|
-
navigator.webkitTemporaryStorage.queryUsageAndQuota(
|
|
115
|
-
(_, quota) => {
|
|
116
|
-
const quotaInMib = Math.round(quota / (1024 * 1024));
|
|
117
|
-
const quotaLimitInMib = Math.round(getQuotaLimit() / (1024 * 1024)) * 2;
|
|
118
|
-
__callback(quotaInMib < quotaLimitInMib);
|
|
119
|
-
},
|
|
120
|
-
(e) => {
|
|
121
|
-
reject(
|
|
122
|
-
new Error(
|
|
123
|
-
`detectIncognito somehow failed to query storage quota: ${e.message}`
|
|
124
|
-
)
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
function oldChromePrivateTest() {
|
|
130
|
-
const fs = window.webkitRequestFileSystem;
|
|
131
|
-
const success = () => {
|
|
132
|
-
__callback(false);
|
|
133
|
-
};
|
|
134
|
-
const error = () => {
|
|
135
|
-
__callback(true);
|
|
136
|
-
};
|
|
137
|
-
fs(0, 1, success, error);
|
|
138
|
-
}
|
|
139
|
-
function chromePrivateTest() {
|
|
140
|
-
if (self.Promise !== void 0 && self.Promise.allSettled !== void 0) {
|
|
141
|
-
storageQuotaChromePrivateTest();
|
|
142
|
-
} else {
|
|
143
|
-
oldChromePrivateTest();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function firefoxPrivateTest() {
|
|
147
|
-
__callback(navigator.serviceWorker === void 0);
|
|
148
|
-
}
|
|
149
|
-
function msiePrivateTest() {
|
|
150
|
-
__callback(window.indexedDB === void 0);
|
|
151
|
-
}
|
|
152
|
-
function main() {
|
|
153
|
-
if (isSafari()) {
|
|
154
|
-
browserName = "Safari";
|
|
155
|
-
safariPrivateTest();
|
|
156
|
-
} else if (isChrome()) {
|
|
157
|
-
browserName = identifyChromium();
|
|
158
|
-
chromePrivateTest();
|
|
159
|
-
} else if (isFirefox()) {
|
|
160
|
-
browserName = "Firefox";
|
|
161
|
-
firefoxPrivateTest();
|
|
162
|
-
} else if (isMSIE()) {
|
|
163
|
-
browserName = "Internet Explorer";
|
|
164
|
-
msiePrivateTest();
|
|
165
|
-
} else {
|
|
166
|
-
reject(new Error("detectIncognito cannot determine the browser"));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
main();
|
|
170
|
-
});
|
|
171
|
-
var isIncognito_default = isIncognito;
|
|
172
|
-
|
|
173
|
-
// src/utils/getUserProperties.ts
|
|
174
|
-
var getGPUInfo = () => {
|
|
175
|
-
const canvas = document.createElement("canvas");
|
|
176
|
-
const gl = canvas?.getContext("webgl") || canvas?.getContext("experimental-webgl");
|
|
177
|
-
if (!gl) {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
const debugInfo = gl?.getExtension("WEBGL_debug_renderer_info");
|
|
181
|
-
return debugInfo ? gl?.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) : null;
|
|
182
|
-
};
|
|
183
|
-
var getUserProperties = async () => {
|
|
184
|
-
let locale = "";
|
|
185
|
-
let timezone = "";
|
|
186
|
-
let dark_mode = false;
|
|
187
|
-
let private_mode = false;
|
|
188
|
-
const properties = {};
|
|
189
|
-
if (!window) {
|
|
190
|
-
return {
|
|
191
|
-
locale,
|
|
192
|
-
timezone,
|
|
193
|
-
dark_mode,
|
|
194
|
-
private_mode,
|
|
195
|
-
properties
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
({ isPrivate: private_mode } = await isIncognito_default());
|
|
200
|
-
} catch (e) {
|
|
201
|
-
console.error(e);
|
|
202
|
-
}
|
|
203
|
-
try {
|
|
204
|
-
dark_mode = window.matchMedia?.("(prefers-color-scheme: dark)").matches;
|
|
205
|
-
} catch (e) {
|
|
206
|
-
console.error(e);
|
|
207
|
-
}
|
|
208
|
-
try {
|
|
209
|
-
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
210
|
-
} catch (e) {
|
|
211
|
-
console.error(e);
|
|
212
|
-
}
|
|
213
|
-
try {
|
|
214
|
-
locale = getUserLocale();
|
|
215
|
-
} catch (e) {
|
|
216
|
-
console.error(e);
|
|
217
|
-
}
|
|
218
|
-
if (navigator && "connection" in navigator) {
|
|
219
|
-
const connection = navigator.connection || navigator?.mozConnection || navigator.webkitConnection;
|
|
220
|
-
properties.network_type = connection.effectiveType;
|
|
221
|
-
}
|
|
222
|
-
properties.width = window?.innerWidth;
|
|
223
|
-
properties.height = window?.innerHeight;
|
|
224
|
-
properties.pixel_ratio = window?.devicePixelRatio;
|
|
225
|
-
if (screen) {
|
|
226
|
-
properties.screen_width = screen?.width;
|
|
227
|
-
properties.screen_height = screen?.height;
|
|
228
|
-
properties.color_depth = screen?.colorDepth;
|
|
229
|
-
properties.orientation = screen?.orientation?.type;
|
|
230
|
-
}
|
|
231
|
-
if (navigator && "getBattery" in navigator) {
|
|
232
|
-
const battery = await navigator?.getBattery();
|
|
233
|
-
if (battery) {
|
|
234
|
-
properties.battery_level = Number((battery?.level * 100).toFixed(0));
|
|
235
|
-
properties.battery_charging = battery?.charging;
|
|
236
|
-
properties.battery_discharging_time = battery?.dischargingTime;
|
|
237
|
-
properties.battery_full_charge_capacity = battery?.fullChargeCapacity;
|
|
238
|
-
properties.battery_charging_time = battery?.chargingTime;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (navigator && "deviceMemory" in navigator) {
|
|
242
|
-
properties.device_memory = navigator?.deviceMemory;
|
|
243
|
-
}
|
|
244
|
-
const supportsTouch = "ontouchstart" in window || typeof navigator?.maxTouchPoints !== "undefined" && navigator?.maxTouchPoints > 0;
|
|
245
|
-
properties.touch_supported = supportsTouch;
|
|
246
|
-
if ("hardwareConcurrency" in navigator) {
|
|
247
|
-
properties.hardware_concurrency = navigator?.hardwareConcurrency;
|
|
248
|
-
}
|
|
249
|
-
if (navigator && "mediaDevices" in navigator) {
|
|
250
|
-
const mediaDevices = navigator?.mediaDevices;
|
|
251
|
-
const devices = await mediaDevices?.enumerateDevices();
|
|
252
|
-
const hasCamera = devices.some((device) => device?.kind === "videoinput");
|
|
253
|
-
properties.camera_supported = hasCamera;
|
|
254
|
-
const hasMicrophone = devices.some(
|
|
255
|
-
(device) => device?.kind === "audioinput"
|
|
256
|
-
);
|
|
257
|
-
properties.microphone_supported = hasMicrophone;
|
|
258
|
-
}
|
|
259
|
-
properties.gpu = getGPUInfo();
|
|
260
|
-
return {
|
|
261
|
-
locale,
|
|
262
|
-
timezone,
|
|
263
|
-
dark_mode,
|
|
264
|
-
private_mode,
|
|
265
|
-
properties
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
// src/plugins/LevoAudience.ts
|
|
270
|
-
var LevoAudience = class extends LevoPlugin {
|
|
271
|
-
instance = null;
|
|
272
|
-
idle_listener = null;
|
|
273
|
-
#IDLE_THROTTLE = 1 * 1e3;
|
|
274
|
-
// every 1 second we check for idleness
|
|
275
|
-
#IDLE_TIMEOUT = 60 * 1e3;
|
|
276
|
-
// 60 seconds till we consider user idle
|
|
277
|
-
#session = "";
|
|
278
|
-
#device = "";
|
|
279
|
-
#is_identified = false;
|
|
280
|
-
#batch = [];
|
|
281
|
-
#events = [];
|
|
282
|
-
request(url, data) {
|
|
283
|
-
const headers = {
|
|
284
|
-
Accept: "application/json",
|
|
285
|
-
"Content-Type": "application/json"
|
|
286
|
-
};
|
|
287
|
-
if (this.client.workspace) {
|
|
288
|
-
headers["Levo-Workspace"] = this.client.workspace;
|
|
289
|
-
}
|
|
290
|
-
const pageContext = this.client.getPageContext();
|
|
291
|
-
if (pageContext) {
|
|
292
|
-
headers["Levo-Page-Context"] = encodeURIComponent(
|
|
293
|
-
JSON.stringify(pageContext)
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
return wretch(url, {
|
|
297
|
-
credentials: "include"
|
|
298
|
-
}).options({
|
|
299
|
-
keepAlive: true
|
|
300
|
-
}).headers(headers).post(data).json();
|
|
301
|
-
}
|
|
302
|
-
async initiate(properties) {
|
|
303
|
-
if (this.client.NODE_ENV === "development") {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const plugin = {
|
|
307
|
-
name: this.client.workspace,
|
|
308
|
-
track: ({ payload }) => {
|
|
309
|
-
if (!this?.client?.insightsUrl || !this.client.workspace) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
const payloadProperties = payload?.properties || {};
|
|
313
|
-
const collectInput = {
|
|
314
|
-
session_id: this.#session,
|
|
315
|
-
device_id: this.#device,
|
|
316
|
-
event: payload.event,
|
|
317
|
-
version: payload.version || 1,
|
|
318
|
-
workspace_id: this.client.workspace,
|
|
319
|
-
properties: {
|
|
320
|
-
...properties,
|
|
321
|
-
...payloadProperties,
|
|
322
|
-
version: void 0,
|
|
323
|
-
resource: void 0,
|
|
324
|
-
identifier: void 0,
|
|
325
|
-
hostname: void 0,
|
|
326
|
-
pathname: void 0,
|
|
327
|
-
url: void 0,
|
|
328
|
-
page_title: void 0,
|
|
329
|
-
created_at: void 0
|
|
330
|
-
},
|
|
331
|
-
hostname: payload?.hostname || window.location.hostname,
|
|
332
|
-
pathname: payload?.pathname || window.location.pathname,
|
|
333
|
-
url: payload?.url || window.location.href,
|
|
334
|
-
page_title: payload?.page_title || document.title,
|
|
335
|
-
resource: payloadProperties?.resource || "page",
|
|
336
|
-
identifier: payloadProperties?.identifier || properties?.id,
|
|
337
|
-
created_at: payload?.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
338
|
-
tab_id: this.getCurrentTabId(),
|
|
339
|
-
tab_count: this.getTabCount()
|
|
340
|
-
};
|
|
341
|
-
let isQueued = false;
|
|
342
|
-
try {
|
|
343
|
-
isQueued = navigator.sendBeacon(
|
|
344
|
-
`${this?.client?.insightsUrl}/v1/insights/event/collect`,
|
|
345
|
-
JSON.stringify(collectInput)
|
|
346
|
-
);
|
|
347
|
-
} catch (e) {
|
|
348
|
-
}
|
|
349
|
-
if (!isQueued) {
|
|
350
|
-
this.request("/v1/insights/event/collect", collectInput);
|
|
351
|
-
}
|
|
352
|
-
this.#events.push({
|
|
353
|
-
input: payload,
|
|
354
|
-
payload: collectInput,
|
|
355
|
-
queued: isQueued
|
|
356
|
-
});
|
|
357
|
-
},
|
|
358
|
-
page: ({ payload }) => {
|
|
359
|
-
if (!this?.client?.insightsUrl) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const payloadProperties = payload?.properties || {};
|
|
363
|
-
this.track("page.view", {
|
|
364
|
-
...properties,
|
|
365
|
-
...payloadProperties,
|
|
366
|
-
title: document.title,
|
|
367
|
-
identifier: properties.id,
|
|
368
|
-
resource: "page"
|
|
369
|
-
});
|
|
370
|
-
},
|
|
371
|
-
identify: ({ payload }) => {
|
|
372
|
-
if (!this?.client?.insightsUrl || !this.client.workspace) {
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const welcomeInput = {
|
|
376
|
-
private_mode: payload.traits.private_mode,
|
|
377
|
-
dark_mode: payload.traits.dark_mode,
|
|
378
|
-
timezone: payload.traits.timezone,
|
|
379
|
-
locale: payload.traits.locale,
|
|
380
|
-
referrer: payload.traits.referrer,
|
|
381
|
-
properties: payload.traits.properties,
|
|
382
|
-
workspace_id: this.client.workspace,
|
|
383
|
-
hostname: window.location.hostname,
|
|
384
|
-
pathname: window.location.pathname,
|
|
385
|
-
page_title: document.title,
|
|
386
|
-
url: window.location.href,
|
|
387
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
388
|
-
tab_id: this.getCurrentTabId(),
|
|
389
|
-
tab_count: this.getTabCount()
|
|
390
|
-
};
|
|
391
|
-
const identifyLock = new LocalStorageLock("lv_aud_identify");
|
|
392
|
-
if (identifyLock.acquireLock()) {
|
|
393
|
-
this.request(
|
|
394
|
-
`${this?.client?.insightsUrl}/v1/insights/event/welcome`,
|
|
395
|
-
welcomeInput
|
|
396
|
-
).then((data) => {
|
|
397
|
-
this.#is_identified = true;
|
|
398
|
-
this.#session = data.content.data.session;
|
|
399
|
-
this.#device = data.content.data.device;
|
|
400
|
-
let isQueued = false;
|
|
401
|
-
try {
|
|
402
|
-
isQueued = navigator.sendBeacon(
|
|
403
|
-
`${this?.client?.insightsUrl}/v1/insights/event/bulk?workspace=${this?.client?.workspace}`,
|
|
404
|
-
JSON.stringify(this.#batch)
|
|
405
|
-
);
|
|
406
|
-
} catch (e) {
|
|
407
|
-
}
|
|
408
|
-
if (!isQueued) {
|
|
409
|
-
this.request("/v1/insights/event/bulk", this.#batch);
|
|
410
|
-
}
|
|
411
|
-
this.#batch = [];
|
|
412
|
-
identifyLock.releaseLock();
|
|
413
|
-
}).catch((e) => {
|
|
414
|
-
identifyLock.releaseLock();
|
|
415
|
-
return getLevoError(e);
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
this.instance = Analytics({
|
|
421
|
-
app: this.client.workspace || "",
|
|
422
|
-
plugins: [plugin]
|
|
423
|
-
});
|
|
424
|
-
await this.identify();
|
|
425
|
-
this.startActivityListener();
|
|
426
|
-
return this.instance.page({
|
|
427
|
-
resource: "page",
|
|
428
|
-
identifier: properties.id
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
async identify() {
|
|
432
|
-
if (!this.instance) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
const referrer = this.getReferrer();
|
|
436
|
-
const traits = await getUserProperties();
|
|
437
|
-
await this.instance.identify("", {
|
|
438
|
-
...traits,
|
|
439
|
-
referrer
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
getReferrer() {
|
|
443
|
-
if (typeof document === "undefined") {
|
|
444
|
-
return {};
|
|
445
|
-
}
|
|
446
|
-
const {
|
|
447
|
-
type,
|
|
448
|
-
referrer,
|
|
449
|
-
data = {}
|
|
450
|
-
} = getVisitorSource({
|
|
451
|
-
referrer: document.referrer,
|
|
452
|
-
currentUrl: window.location.href,
|
|
453
|
-
mapper: null
|
|
454
|
-
});
|
|
455
|
-
const dataKeys = Object.keys(data);
|
|
456
|
-
for (const key of dataKeys) {
|
|
457
|
-
if (data[key] && Array.isArray(data[key]) && data[key].length > 0) {
|
|
458
|
-
data[key] = data[key]?.[0];
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
return { type, referrer, data, raw: document.referrer };
|
|
462
|
-
}
|
|
463
|
-
startActivityListener() {
|
|
464
|
-
if (typeof document !== "undefined" && !this.idle_listener) {
|
|
465
|
-
this.idle_listener = onUserActivity({
|
|
466
|
-
timeout: this.#IDLE_TIMEOUT,
|
|
467
|
-
throttle: this.#IDLE_THROTTLE,
|
|
468
|
-
onIdle: (activeForSeconds) => {
|
|
469
|
-
this.track("user.idle", {
|
|
470
|
-
seconds_active: activeForSeconds
|
|
471
|
-
});
|
|
472
|
-
},
|
|
473
|
-
onWakeUp: (idleForSeconds) => {
|
|
474
|
-
this.track("user.active", {
|
|
475
|
-
seconds_idle: idleForSeconds
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
|
-
getActivityStatus() {
|
|
483
|
-
const status = this?.idle_listener?.getStatus();
|
|
484
|
-
if (!status) {
|
|
485
|
-
return null;
|
|
486
|
-
}
|
|
487
|
-
return {
|
|
488
|
-
status: status.isIdle ? "idle" : "active",
|
|
489
|
-
seconds: status.isIdle ? status.idle : status.active
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
async bounce(properties) {
|
|
493
|
-
const activity_status = this.getActivityStatus();
|
|
494
|
-
if (activity_status) {
|
|
495
|
-
if (activity_status?.status === "idle") {
|
|
496
|
-
properties.seconds_idle = activity_status.seconds;
|
|
497
|
-
} else {
|
|
498
|
-
properties.seconds_active = activity_status.seconds;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
this.track("page.bounce", properties);
|
|
502
|
-
}
|
|
503
|
-
async track(event, properties) {
|
|
504
|
-
if (!this.client.workspace) {
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
console.log(event, properties);
|
|
508
|
-
if (this.instance && this.#is_identified) {
|
|
509
|
-
return this.instance.track(event, properties);
|
|
510
|
-
}
|
|
511
|
-
return this.#batch.push({
|
|
512
|
-
event,
|
|
513
|
-
version: properties?.version || 1,
|
|
514
|
-
properties: {
|
|
515
|
-
...properties,
|
|
516
|
-
version: void 0,
|
|
517
|
-
resource: void 0,
|
|
518
|
-
identifier: void 0,
|
|
519
|
-
hostname: void 0,
|
|
520
|
-
pathname: void 0,
|
|
521
|
-
url: void 0,
|
|
522
|
-
page_title: void 0,
|
|
523
|
-
created_at: void 0
|
|
524
|
-
},
|
|
525
|
-
hostname: window.location.hostname,
|
|
526
|
-
pathname: window.location.pathname,
|
|
527
|
-
url: window.location.href,
|
|
528
|
-
page_title: document.title,
|
|
529
|
-
resource: properties?.resource || "page",
|
|
530
|
-
identifier: properties?.identifier || properties?.id,
|
|
531
|
-
workspace_id: this.client.workspace,
|
|
532
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
533
|
-
tab_id: this.getCurrentTabId(),
|
|
534
|
-
tab_count: this.getTabCount()
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
getCurrentTabId() {
|
|
538
|
-
try {
|
|
539
|
-
if (typeof window === "undefined" || !("sessionStorage" in window)) {
|
|
540
|
-
return "";
|
|
541
|
-
}
|
|
542
|
-
const CURRENT_TAB_LOCAL_STORAGE_KEY = "lv_insights_ct";
|
|
543
|
-
return window.sessionStorage.getItem(CURRENT_TAB_LOCAL_STORAGE_KEY) || "";
|
|
544
|
-
} catch (_) {
|
|
545
|
-
return "";
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
getTabCount() {
|
|
549
|
-
try {
|
|
550
|
-
if (typeof window === "undefined" || !("localStorage" in window)) {
|
|
551
|
-
return 0;
|
|
552
|
-
}
|
|
553
|
-
const OT_LOCAL_STORAGE_KEY = "lv_insights_ot";
|
|
554
|
-
return Number(window.localStorage.getItem(OT_LOCAL_STORAGE_KEY)) || 0;
|
|
555
|
-
} catch (_) {
|
|
556
|
-
return 0;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
export { LevoAudience };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { BlogClient, IResponseMultiple, IResponseSingle } from "../types";
|
|
2
|
-
import type { LevoQuery } from "../types/levo-query";
|
|
3
|
-
import { LevoPlugin } from "./LevoPlugin";
|
|
4
|
-
export declare class LevoBlog extends LevoPlugin {
|
|
5
|
-
getAllBlogs(blog_key: string, data?: LevoQuery.FindQuery, options?: BlogClient.OptionParams): Promise<IResponseMultiple<import("../types").IPost>>;
|
|
6
|
-
getSingleBlog(blog_key: string, slug: string, options?: BlogClient.OptionParams): Promise<IResponseSingle<import("../types").IPost, any>>;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=LevoBlog.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LevoBlog.d.ts","sourceRoot":"","sources":["../../src/plugins/LevoBlog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,QAAS,SAAQ,UAAU;IACtC,WAAW,CACT,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,SAAS,CAAC,SAAc,EAC9B,OAAO,CAAC,EAAE,UAAU,CAAC,YAAY;IAcnC,aAAa,CACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,UAAU,CAAC,YAAY;CAapC"}
|
package/dist/plugins/LevoBlog.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { LevoPlugin } from '../chunk-QJSKNLTV.js';
|
|
2
|
-
|
|
3
|
-
// src/plugins/LevoBlog.ts
|
|
4
|
-
var LevoBlog = class extends LevoPlugin {
|
|
5
|
-
getAllBlogs(blog_key, data = {}, options) {
|
|
6
|
-
return this.client.fetch.url(`/v1/blog/${blog_key}/post/query`).query({ ...options?.params || {} }).options({
|
|
7
|
-
headers: {
|
|
8
|
-
"Levo-Workspace": options?.workspace_id || ""
|
|
9
|
-
}
|
|
10
|
-
}).post(data).json();
|
|
11
|
-
}
|
|
12
|
-
getSingleBlog(blog_key, slug, options) {
|
|
13
|
-
return this.client.fetch.url(`/v1/blog/${blog_key}/post/${slug}`).query({ ...options?.params || {} }).options({
|
|
14
|
-
headers: {
|
|
15
|
-
"Levo-Workspace": options?.workspace_id || ""
|
|
16
|
-
}
|
|
17
|
-
}).get().json();
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { LevoBlog };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { WretchOptions } from "wretch";
|
|
2
|
-
import type { IDraftEntry, ILemaCollection, IResponseMultiple, IResponseSingle, Prettify } from "../types";
|
|
3
|
-
import type { LevoQuery } from "../types/levo-query";
|
|
4
|
-
import { LevoPlugin } from "./LevoPlugin";
|
|
5
|
-
type ColumnKeys = Prettify<keyof ILemaCollection>;
|
|
6
|
-
export declare class LevoCollection extends LevoPlugin {
|
|
7
|
-
getAllCollections(data?: LevoQuery.FindQuery<ColumnKeys>, options?: WretchOptions): Promise<IResponseMultiple<ILemaCollection>>;
|
|
8
|
-
getCollectionByIDExpanded<T = ILemaCollection>(id: string, options?: WretchOptions): Promise<IResponseSingle<T, any>>;
|
|
9
|
-
createCollection(data: ILemaCollection): Promise<IResponseSingle<ILemaCollection, any>>;
|
|
10
|
-
saveCollectionData({ collection_id, data, options, }: {
|
|
11
|
-
collection_id: string;
|
|
12
|
-
data: any;
|
|
13
|
-
options?: WretchOptions;
|
|
14
|
-
}): Promise<IResponseSingle<any, any>>;
|
|
15
|
-
getCollectionContentList({ collection_key, page, search, limit, where, }: {
|
|
16
|
-
collection_key: string;
|
|
17
|
-
} & LevoQuery.FindQuery): Promise<IResponseMultiple<Record<string, unknown>>>;
|
|
18
|
-
saveDraftEntry(collection_key: string, data: any): Promise<IResponseSingle<IDraftEntry, any>>;
|
|
19
|
-
getDraftEntry(collection_key: string): Promise<IResponseSingle<IDraftEntry, any>>;
|
|
20
|
-
submitDraftEntry(collection_key: string, data: any): Promise<IResponseSingle<IDraftEntry, any>>;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=LevoCollection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LevoCollection.d.ts","sourceRoot":"","sources":["../../src/plugins/LevoCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,QAAQ,EACT,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,KAAK,UAAU,GAAG,QAAQ,CAAC,MAAM,eAAe,CAAC,CAAC;AAElD,qBAAa,cAAe,SAAQ,UAAU;IAC5C,iBAAiB,CACf,IAAI,GAAE,SAAS,CAAC,SAAS,CAAC,UAAU,CAAM,EAC1C,OAAO,GAAE,aAAkB;IAS7B,yBAAyB,CAAC,CAAC,GAAG,eAAe,EAC3C,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,aAAkB;IAS7B,gBAAgB,CAAC,IAAI,EAAE,eAAe;IAOtC,kBAAkB,CAAC,EACjB,aAAa,EACb,IAAI,EACJ,OAAY,GACb,EAAE;QACD,aAAa,EAAE,MAAM,CAAC;QACtB,IAAI,EAAE,GAAG,CAAC;QACV,OAAO,CAAC,EAAE,aAAa,CAAC;KACzB;IAQD,wBAAwB,CAAC,EACvB,cAAc,EACd,IAAI,EACJ,MAAM,EACN,KAAU,EACV,KAAK,GACN,EAAE;QACD,cAAc,EAAE,MAAM,CAAC;KACxB,GAAG,SAAS,CAAC,SAAS;IAavB,cAAc,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAOhD,aAAa,CAAC,cAAc,EAAE,MAAM;IAOpC,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;CAMnD"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { LevoPlugin } from '../chunk-QJSKNLTV.js';
|
|
2
|
-
|
|
3
|
-
// src/plugins/LevoCollection.ts
|
|
4
|
-
var LevoCollection = class extends LevoPlugin {
|
|
5
|
-
getAllCollections(data = {}, options = {}) {
|
|
6
|
-
return this.client.fetch.url("/v1/bevy/collection/query").options(options).post(data).json();
|
|
7
|
-
}
|
|
8
|
-
getCollectionByIDExpanded(id, options = {}) {
|
|
9
|
-
return this.client.fetch.url(`/v1/bevy/collection/${id}`).options(options).get().json();
|
|
10
|
-
}
|
|
11
|
-
createCollection(data) {
|
|
12
|
-
return this.client.fetch.url("/v1/bevy/collection").post(data).json();
|
|
13
|
-
}
|
|
14
|
-
saveCollectionData({
|
|
15
|
-
collection_id,
|
|
16
|
-
data,
|
|
17
|
-
options = {}
|
|
18
|
-
}) {
|
|
19
|
-
return this.client.fetch.url(`/v1/bevy/content/${collection_id}`).options(options).post(data).json();
|
|
20
|
-
}
|
|
21
|
-
getCollectionContentList({
|
|
22
|
-
collection_key,
|
|
23
|
-
page,
|
|
24
|
-
search,
|
|
25
|
-
limit = 10,
|
|
26
|
-
where
|
|
27
|
-
}) {
|
|
28
|
-
return this.client.fetch.url(`/v1/bevy/content/${collection_key}/query`).post({
|
|
29
|
-
page,
|
|
30
|
-
limit,
|
|
31
|
-
search,
|
|
32
|
-
where
|
|
33
|
-
}).json();
|
|
34
|
-
}
|
|
35
|
-
// Collection Draft APIs
|
|
36
|
-
saveDraftEntry(collection_key, data) {
|
|
37
|
-
return this.client.fetch.url(`/v1/bevy/content/${collection_key}/save-entry`).post(data).json();
|
|
38
|
-
}
|
|
39
|
-
getDraftEntry(collection_key) {
|
|
40
|
-
return this.client.fetch.url(`/v1/bevy/content/${collection_key}/list-entry`).get().json();
|
|
41
|
-
}
|
|
42
|
-
submitDraftEntry(collection_key, data) {
|
|
43
|
-
return this.client.fetch.url(`/v1/bevy/content/${collection_key}/submit-entry`).post(data).json();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export { LevoCollection };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type LevoClient from "../LevoClient";
|
|
2
|
-
import { BatchOptions, LogBatch } from "../logger/batch";
|
|
3
|
-
import { LevoPlugin } from "./LevoPlugin";
|
|
4
|
-
export declare const isBrowser: boolean;
|
|
5
|
-
export declare enum LogLevel {
|
|
6
|
-
debug = 0,
|
|
7
|
-
info = 1,
|
|
8
|
-
warn = 2,
|
|
9
|
-
error = 3,
|
|
10
|
-
off = 100
|
|
11
|
-
}
|
|
12
|
-
export interface LoggerOptions extends BatchOptions {
|
|
13
|
-
level?: LogLevel;
|
|
14
|
-
enableRemote?: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare class LevoLogger extends LevoPlugin {
|
|
17
|
-
logLevel: LogLevel;
|
|
18
|
-
enableRemote: boolean;
|
|
19
|
-
batch: LogBatch;
|
|
20
|
-
context: Record<string, any>;
|
|
21
|
-
constructor(client: LevoClient, batchOptions?: LoggerOptions, context?: Record<string, any>);
|
|
22
|
-
debug: (...args: any[]) => void;
|
|
23
|
-
info: (...args: any[]) => void;
|
|
24
|
-
warn: (...args: any[]) => void;
|
|
25
|
-
error: (...args: any[]) => void;
|
|
26
|
-
format(messages: any[]): {
|
|
27
|
-
message: string;
|
|
28
|
-
content?: Array<object> | object | string;
|
|
29
|
-
};
|
|
30
|
-
log: (level: LogLevel, args: any[]) => void;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=LevoLogger.d.ts.map
|