@olenbetong/appframe-core 2.11.0 → 2.11.2

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.
Files changed (52) hide show
  1. package/dist/esm/af.common.js +123 -143
  2. package/dist/esm/af.common.legacy.js +129 -149
  3. package/dist/esm/af.common.legacy.min.js +1 -1
  4. package/dist/esm/af.common.legacy.min.js.map +4 -4
  5. package/dist/esm/af.common.min.js +2 -2
  6. package/dist/esm/af.common.min.js.map +4 -4
  7. package/dist/iife/af.common.js +123 -143
  8. package/dist/iife/af.common.legacy.js +129 -149
  9. package/dist/iife/af.common.legacy.min.js +1 -1
  10. package/dist/iife/af.common.legacy.min.js.map +4 -4
  11. package/dist/iife/af.common.min.js +2 -2
  12. package/dist/iife/af.common.min.js.map +4 -4
  13. package/es/SessionHandler.js +1 -3
  14. package/es/UserSession.js +33 -29
  15. package/es/date.js +3 -3
  16. package/es/date.test.d.ts +1 -0
  17. package/es/date.test.js +23 -0
  18. package/es/errorHandler.d.ts +1 -0
  19. package/es/errorHandler.js +5 -21
  20. package/es/expose.d.ts +1 -1
  21. package/es/expose.js +1 -2
  22. package/es/expose.test.d.ts +10 -0
  23. package/es/expose.test.js +36 -0
  24. package/es/getLocalizedString.js +1 -2
  25. package/es/getUserImage.test.d.ts +1 -0
  26. package/es/getUserImage.test.js +30 -0
  27. package/es/index.d.ts +0 -1
  28. package/es/index.js +1 -2
  29. package/es/invariant.d.ts +8 -0
  30. package/es/invariant.js +8 -0
  31. package/es/invariant.test.d.ts +1 -0
  32. package/es/invariant.test.js +19 -0
  33. package/es/localStorage.js +1 -3
  34. package/es/parseFunc.js +1 -1
  35. package/es/parseFunc.test.d.ts +1 -0
  36. package/es/parseFunc.test.js +14 -0
  37. package/package.json +5 -3
  38. package/src/date.test.ts +27 -0
  39. package/src/date.ts +3 -3
  40. package/src/errorHandler.ts +6 -21
  41. package/src/expose.test.ts +59 -0
  42. package/src/expose.ts +2 -3
  43. package/src/getLocalizedString.ts +1 -3
  44. package/src/getUserImage.test.ts +50 -0
  45. package/src/index.ts +0 -1
  46. package/src/invariant.test.ts +23 -0
  47. package/src/invariant.ts +8 -0
  48. package/src/parseFunc.test.ts +17 -0
  49. package/src/parseFunc.ts +1 -1
  50. package/es/has.d.ts +0 -1
  51. package/es/has.js +0 -3
  52. package/src/has.ts +0 -3
@@ -110,27 +110,125 @@ var UserSession = class extends SessionHandler {
110
110
  }
111
111
  };
112
112
 
113
+ // src/log.ts
114
+ async function logActivity(activity, parameters = {}, timeElapsed = 0) {
115
+ try {
116
+ let response = await fetch("/api/logging/log-activity", {
117
+ method: "POST",
118
+ body: JSON.stringify({
119
+ article: af.article.id,
120
+ timeElapsed,
121
+ action: activity,
122
+ parameters: {
123
+ ...parameters,
124
+ _session: getSessionData()
125
+ }
126
+ }),
127
+ headers: { "Content-Type": "application/json", Accept: "application/json" }
128
+ });
129
+ if (!response.ok) {
130
+ if (response.headers.get("Content-Type")?.includes("application/json")) {
131
+ let data = await response.json();
132
+ console.error(data.error);
133
+ } else {
134
+ console.error(`${response.status} ${response.statusText}`);
135
+ }
136
+ }
137
+ } catch (error) {
138
+ }
139
+ }
140
+ function startActivity(activity, startParameters = {}) {
141
+ let start = performance.now();
142
+ return (endParameters = {}) => logActivity(activity, { ...startParameters, ...endParameters }, performance.now() - start);
143
+ }
144
+ async function time(callback) {
145
+ let start = performance.now();
146
+ let returnValue = await callback();
147
+ return [returnValue, performance.now() - start];
148
+ }
149
+ async function logError(error) {
150
+ try {
151
+ if (!error)
152
+ return;
153
+ let data = typeof error === "string" ? { error } : typeof error === "object" ? "message" in error ? {
154
+ error: error.message,
155
+ stack: error.stack ?? null
156
+ } : { error: error.toString() } : { error: "Unspecified error" };
157
+ console.error(error);
158
+ let result = await fetch("/data/Logger/LogError", {
159
+ method: "POST",
160
+ body: JSON.stringify(data),
161
+ headers: {
162
+ "Content-Type": "application/json; charset=utf-8"
163
+ }
164
+ });
165
+ if (result.ok) {
166
+ return await result.json();
167
+ }
168
+ console.error(Error("Failed to log error"));
169
+ } catch {
170
+ }
171
+ }
172
+ function getSessionId() {
173
+ return crypto.randomUUID?.();
174
+ }
175
+ var sessionStart = Date.now();
176
+ var sessionId = getSessionId();
177
+ var deviceId = "";
178
+ var browserSessionId = "";
179
+ if ("document" in window) {
180
+ let startSession = () => logActivity("AfSessionInit", {
181
+ "appframe-core": af.common.version,
182
+ "appframe-data": af.data?.version,
183
+ "app-version": af.article.version
184
+ });
185
+ document.addEventListener("DOMContentLoaded", () => {
186
+ deviceId = localStorage.getItem("_afDeviceId");
187
+ browserSessionId = sessionStorage.getItem("_afSessionId");
188
+ if (!deviceId) {
189
+ deviceId = getSessionId();
190
+ localStorage.setItem("_afDeviceId", deviceId);
191
+ }
192
+ if (!browserSessionId) {
193
+ browserSessionId = sessionId;
194
+ sessionStorage.setItem("_afSessionId", browserSessionId);
195
+ }
196
+ startSession();
197
+ });
198
+ document.addEventListener("visibilitychange", function logData() {
199
+ if (document.visibilityState === "hidden") {
200
+ navigator.sendBeacon(
201
+ "/api/logging/log-activity",
202
+ JSON.stringify({
203
+ article: af.article.id,
204
+ action: "AfSessionEnd",
205
+ parameters: {
206
+ _session: getSessionData()
207
+ }
208
+ })
209
+ );
210
+ } else {
211
+ startSession();
212
+ }
213
+ });
214
+ }
215
+ function getSessionData() {
216
+ return {
217
+ browserSessionId,
218
+ sessionStart,
219
+ sessionLength: Date.now() - sessionStart,
220
+ sessionId,
221
+ deviceId
222
+ };
223
+ }
224
+
113
225
  // src/errorHandler.ts
114
226
  if (true) {
115
227
  window.window?.addEventListener("error", (event) => {
116
- try {
117
- const data = {
118
- error: event.error?.message ?? event.message ?? null,
119
- file: event.filename,
120
- line: event.lineno ?? 0,
121
- column: event.colno ?? 0,
122
- stack: event.error?.stack ?? null
123
- };
124
- fetch("/data/Logger/LogError", {
125
- body: JSON.stringify(data),
126
- headers: {
127
- Accept: "application/json",
128
- "Content-Type": "application/json; charset=utf-8",
129
- "X-Requested-With": "XMLHttpRequest"
130
- },
131
- method: "POST"
132
- });
133
- } catch (ex) {
228
+ if (typeof event === "object" && "error" in event) {
229
+ logError(event.error);
230
+ } else if (typeof event === "object" && "message" in event) {
231
+ logError(event);
134
232
  }
135
233
  });
136
234
  }
@@ -176,13 +274,13 @@ var localStorage_default = new LocalStorage();
176
274
  function toLocalISODate(date) {
177
275
  return date ? toLocalISODateTime(date).substring(0, 10) : null;
178
276
  }
179
- function pad(num) {
180
- return String(num).padStart(2, "0");
277
+ function pad(num, digits = 2) {
278
+ return String(num).padStart(digits, "0");
181
279
  }
182
280
  function toLocalISODateTime(date) {
183
281
  return date ? `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
184
282
  date.getMinutes()
185
- )}:${pad(date.getSeconds())}.${pad(date.getMilliseconds())}` : null;
283
+ )}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}` : null;
186
284
  }
187
285
  function toLocalDateTime(date) {
188
286
  return date ? date.toISOString().substring(0, 16) : "";
@@ -267,17 +365,12 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
267
365
  }
268
366
  }
269
367
 
270
- // src/has.ts
271
- function has(obj, key) {
272
- return Object.prototype.hasOwnProperty.call(obj, key);
273
- }
274
-
275
368
  // src/parseFunc.ts
276
369
  var funcRegex = /^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;
277
370
  function parseFunc(func) {
278
371
  var match = func.toString().match(funcRegex);
279
372
  invariant(match, "Unable to parse function!");
280
- return { name: match[1], args: match[2].split(","), body: match[3] };
373
+ return { name: func.name ?? match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
281
374
  }
282
375
 
283
376
  // src/Namespace.ts
@@ -331,7 +424,7 @@ function expose(name, value, options = {}) {
331
424
  } else {
332
425
  invariant(false, "Invalid typeof parameter 'name', or unable to parse pValue!");
333
426
  }
334
- if (has(namespace, keyName) && options?.overwrite !== true) {
427
+ if (Object.hasOwn(namespace, keyName) && options?.overwrite !== true) {
335
428
  console.warn([name, keyName].join(".") + " is already defined!");
336
429
  } else {
337
430
  namespace[keyName] = value;
@@ -385,7 +478,7 @@ function getLocalizedString(string, wait) {
385
478
  return;
386
479
  }
387
480
  if (window.af?.article?.i18n !== void 0) {
388
- if (!has(af.article.i18n, string)) {
481
+ if (!Object.hasOwn(af.article.i18n, string)) {
389
482
  af.article.i18n[string] = string;
390
483
  let promise = fetchLocalizedString(string).then((text) => {
391
484
  af.article.i18n[string] = text;
@@ -415,118 +508,6 @@ function localize(stringParts, ...args) {
415
508
  return localized;
416
509
  }
417
510
 
418
- // src/log.ts
419
- async function logActivity(activity, parameters = {}, timeElapsed = 0) {
420
- try {
421
- let response = await fetch("/api/logging/log-activity", {
422
- method: "POST",
423
- body: JSON.stringify({
424
- article: af.article.id,
425
- timeElapsed,
426
- action: activity,
427
- parameters: {
428
- ...parameters,
429
- _session: getSessionData()
430
- }
431
- }),
432
- headers: { "Content-Type": "application/json", Accept: "application/json" }
433
- });
434
- if (!response.ok) {
435
- if (response.headers.get("Content-Type")?.includes("application/json")) {
436
- let data = await response.json();
437
- console.error(data.error);
438
- } else {
439
- console.error(`${response.status} ${response.statusText}`);
440
- }
441
- }
442
- } catch (error) {
443
- }
444
- }
445
- function startActivity(activity, startParameters = {}) {
446
- let start = performance.now();
447
- return (endParameters = {}) => logActivity(activity, { ...startParameters, ...endParameters }, performance.now() - start);
448
- }
449
- async function time(callback) {
450
- let start = performance.now();
451
- let returnValue = await callback();
452
- return [returnValue, performance.now() - start];
453
- }
454
- async function logError(error) {
455
- try {
456
- if (!error)
457
- return;
458
- let data = typeof error === "string" ? { error } : typeof error === "object" ? "message" in error ? {
459
- error: error.message,
460
- stack: error.stack ?? null
461
- } : { error: error.toString() } : { error: "Unspecified error" };
462
- console.error(error);
463
- let result = await fetch("/data/Logger/LogError", {
464
- method: "POST",
465
- body: JSON.stringify(data),
466
- headers: {
467
- "Content-Type": "application/json; charset=utf-8"
468
- }
469
- });
470
- if (result.ok) {
471
- return await result.json();
472
- }
473
- console.error(Error("Failed to log error"));
474
- } catch {
475
- }
476
- }
477
- function getSessionId() {
478
- return crypto.randomUUID?.();
479
- }
480
- var sessionStart = Date.now();
481
- var sessionId = getSessionId();
482
- var deviceId = "";
483
- var browserSessionId = "";
484
- if ("document" in window) {
485
- let startSession = () => logActivity("AfSessionInit", {
486
- "appframe-core": af.common.version,
487
- "appframe-data": af.data?.version,
488
- "app-version": af.article.version
489
- });
490
- document.addEventListener("DOMContentLoaded", () => {
491
- deviceId = localStorage.getItem("_afDeviceId");
492
- browserSessionId = sessionStorage.getItem("_afSessionId");
493
- if (!deviceId) {
494
- deviceId = getSessionId();
495
- localStorage.setItem("_afDeviceId", deviceId);
496
- }
497
- if (!browserSessionId) {
498
- browserSessionId = sessionId;
499
- sessionStorage.setItem("_afSessionId", browserSessionId);
500
- }
501
- startSession();
502
- });
503
- document.addEventListener("visibilitychange", function logData() {
504
- if (document.visibilityState === "hidden") {
505
- navigator.sendBeacon(
506
- "/api/logging/log-activity",
507
- JSON.stringify({
508
- article: af.article.id,
509
- action: "AfSessionEnd",
510
- parameters: {
511
- _session: getSessionData()
512
- }
513
- })
514
- );
515
- } else {
516
- startSession();
517
- }
518
- });
519
- }
520
- function getSessionData() {
521
- return {
522
- browserSessionId,
523
- sessionStart,
524
- sessionLength: Date.now() - sessionStart,
525
- sessionId,
526
- deviceId
527
- };
528
- }
529
-
530
511
  // src/settings.ts
531
512
  function getKey(article) {
532
513
  const articleKey = article || af.article.id;
@@ -668,7 +649,7 @@ async function alert(prompt, options = {}) {
668
649
  }
669
650
 
670
651
  // src/index.ts
671
- var version = "2.11.0";
652
+ var version = "2.11.2";
672
653
  export {
673
654
  ConfirmButtons,
674
655
  SessionHandler,
@@ -682,7 +663,6 @@ export {
682
663
  getSessionData,
683
664
  getSettings,
684
665
  getUserImage,
685
- has,
686
666
  invariant,
687
667
  localStorage_default as localStorage,
688
668
  localize,
@@ -136,29 +136,131 @@ var UserSession = class extends SessionHandler {
136
136
  }
137
137
  };
138
138
 
139
+ // src/log.ts
140
+ async function logActivity(activity, parameters = {}, timeElapsed = 0) {
141
+ var _a2;
142
+ try {
143
+ let response = await fetch("/api/logging/log-activity", {
144
+ method: "POST",
145
+ body: JSON.stringify({
146
+ article: af.article.id,
147
+ timeElapsed,
148
+ action: activity,
149
+ parameters: __spreadProps(__spreadValues({}, parameters), {
150
+ _session: getSessionData()
151
+ })
152
+ }),
153
+ headers: { "Content-Type": "application/json", Accept: "application/json" }
154
+ });
155
+ if (!response.ok) {
156
+ if ((_a2 = response.headers.get("Content-Type")) == null ? void 0 : _a2.includes("application/json")) {
157
+ let data = await response.json();
158
+ console.error(data.error);
159
+ } else {
160
+ console.error("".concat(response.status, " ").concat(response.statusText));
161
+ }
162
+ }
163
+ } catch (error) {
164
+ }
165
+ }
166
+ function startActivity(activity, startParameters = {}) {
167
+ let start = performance.now();
168
+ return (endParameters = {}) => logActivity(activity, __spreadValues(__spreadValues({}, startParameters), endParameters), performance.now() - start);
169
+ }
170
+ async function time(callback) {
171
+ let start = performance.now();
172
+ let returnValue = await callback();
173
+ return [returnValue, performance.now() - start];
174
+ }
175
+ async function logError(error) {
176
+ var _a2;
177
+ try {
178
+ if (!error)
179
+ return;
180
+ let data = typeof error === "string" ? { error } : typeof error === "object" ? "message" in error ? {
181
+ error: error.message,
182
+ stack: (_a2 = error.stack) != null ? _a2 : null
183
+ } : { error: error.toString() } : { error: "Unspecified error" };
184
+ console.error(error);
185
+ let result = await fetch("/data/Logger/LogError", {
186
+ method: "POST",
187
+ body: JSON.stringify(data),
188
+ headers: {
189
+ "Content-Type": "application/json; charset=utf-8"
190
+ }
191
+ });
192
+ if (result.ok) {
193
+ return await result.json();
194
+ }
195
+ console.error(Error("Failed to log error"));
196
+ } catch (e) {
197
+ }
198
+ }
199
+ function getSessionId() {
200
+ var _a2;
201
+ return (_a2 = crypto.randomUUID) == null ? void 0 : _a2.call(crypto);
202
+ }
203
+ var sessionStart = Date.now();
204
+ var sessionId = getSessionId();
205
+ var deviceId = "";
206
+ var browserSessionId = "";
207
+ if ("document" in window) {
208
+ let startSession = () => {
209
+ var _a2;
210
+ return logActivity("AfSessionInit", {
211
+ "appframe-core": af.common.version,
212
+ "appframe-data": (_a2 = af.data) == null ? void 0 : _a2.version,
213
+ "app-version": af.article.version
214
+ });
215
+ };
216
+ document.addEventListener("DOMContentLoaded", () => {
217
+ deviceId = localStorage.getItem("_afDeviceId");
218
+ browserSessionId = sessionStorage.getItem("_afSessionId");
219
+ if (!deviceId) {
220
+ deviceId = getSessionId();
221
+ localStorage.setItem("_afDeviceId", deviceId);
222
+ }
223
+ if (!browserSessionId) {
224
+ browserSessionId = sessionId;
225
+ sessionStorage.setItem("_afSessionId", browserSessionId);
226
+ }
227
+ startSession();
228
+ });
229
+ document.addEventListener("visibilitychange", function logData() {
230
+ if (document.visibilityState === "hidden") {
231
+ navigator.sendBeacon(
232
+ "/api/logging/log-activity",
233
+ JSON.stringify({
234
+ article: af.article.id,
235
+ action: "AfSessionEnd",
236
+ parameters: {
237
+ _session: getSessionData()
238
+ }
239
+ })
240
+ );
241
+ } else {
242
+ startSession();
243
+ }
244
+ });
245
+ }
246
+ function getSessionData() {
247
+ return {
248
+ browserSessionId,
249
+ sessionStart,
250
+ sessionLength: Date.now() - sessionStart,
251
+ sessionId,
252
+ deviceId
253
+ };
254
+ }
255
+
139
256
  // src/errorHandler.ts
140
257
  var _a;
141
258
  if (true) {
142
259
  (_a = window.window) == null ? void 0 : _a.addEventListener("error", (event) => {
143
- var _a2, _b, _c, _d, _e, _f, _g;
144
- try {
145
- const data = {
146
- error: (_c = (_b = (_a2 = event.error) == null ? void 0 : _a2.message) != null ? _b : event.message) != null ? _c : null,
147
- file: event.filename,
148
- line: (_d = event.lineno) != null ? _d : 0,
149
- column: (_e = event.colno) != null ? _e : 0,
150
- stack: (_g = (_f = event.error) == null ? void 0 : _f.stack) != null ? _g : null
151
- };
152
- fetch("/data/Logger/LogError", {
153
- body: JSON.stringify(data),
154
- headers: {
155
- Accept: "application/json",
156
- "Content-Type": "application/json; charset=utf-8",
157
- "X-Requested-With": "XMLHttpRequest"
158
- },
159
- method: "POST"
160
- });
161
- } catch (ex) {
260
+ if (typeof event === "object" && "error" in event) {
261
+ logError(event.error);
262
+ } else if (typeof event === "object" && "message" in event) {
263
+ logError(event);
162
264
  }
163
265
  });
164
266
  }
@@ -207,13 +309,13 @@ var localStorage_default = new LocalStorage();
207
309
  function toLocalISODate(date) {
208
310
  return date ? toLocalISODateTime(date).substring(0, 10) : null;
209
311
  }
210
- function pad(num) {
211
- return String(num).padStart(2, "0");
312
+ function pad(num, digits = 2) {
313
+ return String(num).padStart(digits, "0");
212
314
  }
213
315
  function toLocalISODateTime(date) {
214
316
  return date ? "".concat(date.getFullYear(), "-").concat(pad(date.getMonth() + 1), "-").concat(pad(date.getDate()), "T").concat(pad(date.getHours()), ":").concat(pad(
215
317
  date.getMinutes()
216
- ), ":").concat(pad(date.getSeconds()), ".").concat(pad(date.getMilliseconds())) : null;
318
+ ), ":").concat(pad(date.getSeconds()), ".").concat(pad(date.getMilliseconds(), 3)) : null;
217
319
  }
218
320
  function toLocalDateTime(date) {
219
321
  return date ? date.toISOString().substring(0, 16) : "";
@@ -299,17 +401,13 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
299
401
  }
300
402
  }
301
403
 
302
- // src/has.ts
303
- function has(obj, key) {
304
- return Object.prototype.hasOwnProperty.call(obj, key);
305
- }
306
-
307
404
  // src/parseFunc.ts
308
405
  var funcRegex = /^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;
309
406
  function parseFunc(func) {
407
+ var _a2;
310
408
  var match = func.toString().match(funcRegex);
311
409
  invariant(match, "Unable to parse function!");
312
- return { name: match[1], args: match[2].split(","), body: match[3] };
410
+ return { name: (_a2 = func.name) != null ? _a2 : match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
313
411
  }
314
412
 
315
413
  // src/Namespace.ts
@@ -363,7 +461,7 @@ function expose(name, value, options = {}) {
363
461
  } else {
364
462
  invariant(false, "Invalid typeof parameter 'name', or unable to parse pValue!");
365
463
  }
366
- if (has(namespace, keyName) && (options == null ? void 0 : options.overwrite) !== true) {
464
+ if (Object.hasOwn(namespace, keyName) && (options == null ? void 0 : options.overwrite) !== true) {
367
465
  console.warn([name, keyName].join(".") + " is already defined!");
368
466
  } else {
369
467
  namespace[keyName] = value;
@@ -418,7 +516,7 @@ function getLocalizedString(string, wait) {
418
516
  return;
419
517
  }
420
518
  if (((_b = (_a2 = window.af) == null ? void 0 : _a2.article) == null ? void 0 : _b.i18n) !== void 0) {
421
- if (!has(af.article.i18n, string)) {
519
+ if (!Object.hasOwn(af.article.i18n, string)) {
422
520
  af.article.i18n[string] = string;
423
521
  let promise = fetchLocalizedString(string).then((text) => {
424
522
  af.article.i18n[string] = text;
@@ -448,123 +546,6 @@ function localize(stringParts, ...args) {
448
546
  return localized;
449
547
  }
450
548
 
451
- // src/log.ts
452
- async function logActivity(activity, parameters = {}, timeElapsed = 0) {
453
- var _a2;
454
- try {
455
- let response = await fetch("/api/logging/log-activity", {
456
- method: "POST",
457
- body: JSON.stringify({
458
- article: af.article.id,
459
- timeElapsed,
460
- action: activity,
461
- parameters: __spreadProps(__spreadValues({}, parameters), {
462
- _session: getSessionData()
463
- })
464
- }),
465
- headers: { "Content-Type": "application/json", Accept: "application/json" }
466
- });
467
- if (!response.ok) {
468
- if ((_a2 = response.headers.get("Content-Type")) == null ? void 0 : _a2.includes("application/json")) {
469
- let data = await response.json();
470
- console.error(data.error);
471
- } else {
472
- console.error("".concat(response.status, " ").concat(response.statusText));
473
- }
474
- }
475
- } catch (error) {
476
- }
477
- }
478
- function startActivity(activity, startParameters = {}) {
479
- let start = performance.now();
480
- return (endParameters = {}) => logActivity(activity, __spreadValues(__spreadValues({}, startParameters), endParameters), performance.now() - start);
481
- }
482
- async function time(callback) {
483
- let start = performance.now();
484
- let returnValue = await callback();
485
- return [returnValue, performance.now() - start];
486
- }
487
- async function logError(error) {
488
- var _a2;
489
- try {
490
- if (!error)
491
- return;
492
- let data = typeof error === "string" ? { error } : typeof error === "object" ? "message" in error ? {
493
- error: error.message,
494
- stack: (_a2 = error.stack) != null ? _a2 : null
495
- } : { error: error.toString() } : { error: "Unspecified error" };
496
- console.error(error);
497
- let result = await fetch("/data/Logger/LogError", {
498
- method: "POST",
499
- body: JSON.stringify(data),
500
- headers: {
501
- "Content-Type": "application/json; charset=utf-8"
502
- }
503
- });
504
- if (result.ok) {
505
- return await result.json();
506
- }
507
- console.error(Error("Failed to log error"));
508
- } catch (e) {
509
- }
510
- }
511
- function getSessionId() {
512
- var _a2;
513
- return (_a2 = crypto.randomUUID) == null ? void 0 : _a2.call(crypto);
514
- }
515
- var sessionStart = Date.now();
516
- var sessionId = getSessionId();
517
- var deviceId = "";
518
- var browserSessionId = "";
519
- if ("document" in window) {
520
- let startSession = () => {
521
- var _a2;
522
- return logActivity("AfSessionInit", {
523
- "appframe-core": af.common.version,
524
- "appframe-data": (_a2 = af.data) == null ? void 0 : _a2.version,
525
- "app-version": af.article.version
526
- });
527
- };
528
- document.addEventListener("DOMContentLoaded", () => {
529
- deviceId = localStorage.getItem("_afDeviceId");
530
- browserSessionId = sessionStorage.getItem("_afSessionId");
531
- if (!deviceId) {
532
- deviceId = getSessionId();
533
- localStorage.setItem("_afDeviceId", deviceId);
534
- }
535
- if (!browserSessionId) {
536
- browserSessionId = sessionId;
537
- sessionStorage.setItem("_afSessionId", browserSessionId);
538
- }
539
- startSession();
540
- });
541
- document.addEventListener("visibilitychange", function logData() {
542
- if (document.visibilityState === "hidden") {
543
- navigator.sendBeacon(
544
- "/api/logging/log-activity",
545
- JSON.stringify({
546
- article: af.article.id,
547
- action: "AfSessionEnd",
548
- parameters: {
549
- _session: getSessionData()
550
- }
551
- })
552
- );
553
- } else {
554
- startSession();
555
- }
556
- });
557
- }
558
- function getSessionData() {
559
- return {
560
- browserSessionId,
561
- sessionStart,
562
- sessionLength: Date.now() - sessionStart,
563
- sessionId,
564
- deviceId
565
- };
566
- }
567
-
568
549
  // src/settings.ts
569
550
  function getKey(article) {
570
551
  const articleKey = article || af.article.id;
@@ -697,7 +678,7 @@ async function alert(prompt, options = {}) {
697
678
  }
698
679
 
699
680
  // src/index.ts
700
- var version = "2.11.0";
681
+ var version = "2.11.2";
701
682
  export {
702
683
  ConfirmButtons,
703
684
  SessionHandler,
@@ -711,7 +692,6 @@ export {
711
692
  getSessionData,
712
693
  getSettings,
713
694
  getUserImage,
714
- has,
715
695
  invariant,
716
696
  localStorage_default as localStorage,
717
697
  localize,