@olenbetong/appframe-core 2.11.0 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/af.common.js +121 -135
- package/dist/esm/af.common.legacy.js +127 -141
- package/dist/esm/af.common.legacy.min.js +1 -1
- package/dist/esm/af.common.legacy.min.js.map +4 -4
- package/dist/esm/af.common.min.js +2 -2
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +121 -135
- package/dist/iife/af.common.legacy.js +127 -141
- package/dist/iife/af.common.legacy.min.js +1 -1
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +2 -2
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/SessionHandler.js +1 -3
- package/es/UserSession.js +33 -29
- package/es/date.js +3 -3
- package/es/date.test.d.ts +1 -0
- package/es/date.test.js +23 -0
- package/es/errorHandler.d.ts +1 -0
- package/es/errorHandler.js +5 -21
- package/es/expose.d.ts +1 -1
- package/es/expose.test.d.ts +10 -0
- package/es/expose.test.js +36 -0
- package/es/getUserImage.test.d.ts +1 -0
- package/es/getUserImage.test.js +30 -0
- package/es/index.js +1 -1
- package/es/invariant.test.d.ts +1 -0
- package/es/invariant.test.js +19 -0
- package/es/localStorage.js +1 -3
- package/es/parseFunc.js +1 -1
- package/es/parseFunc.test.d.ts +1 -0
- package/es/parseFunc.test.js +14 -0
- package/package.json +5 -3
- package/src/date.test.ts +27 -0
- package/src/date.ts +3 -3
- package/src/errorHandler.ts +6 -21
- package/src/expose.test.ts +59 -0
- package/src/expose.ts +1 -1
- package/src/getUserImage.test.ts +50 -0
- package/src/invariant.test.ts +23 -0
- package/src/parseFunc.test.ts +17 -0
- package/src/parseFunc.ts +1 -1
package/dist/esm/af.common.js
CHANGED
|
@@ -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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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(
|
|
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) : "";
|
|
@@ -277,7 +375,7 @@ var funcRegex = /^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA
|
|
|
277
375
|
function parseFunc(func) {
|
|
278
376
|
var match = func.toString().match(funcRegex);
|
|
279
377
|
invariant(match, "Unable to parse function!");
|
|
280
|
-
return { name: match[1], args: match[2].split(","), body: match[3] };
|
|
378
|
+
return { name: func.name ?? match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
|
|
281
379
|
}
|
|
282
380
|
|
|
283
381
|
// src/Namespace.ts
|
|
@@ -415,118 +513,6 @@ function localize(stringParts, ...args) {
|
|
|
415
513
|
return localized;
|
|
416
514
|
}
|
|
417
515
|
|
|
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
516
|
// src/settings.ts
|
|
531
517
|
function getKey(article) {
|
|
532
518
|
const articleKey = article || af.article.id;
|
|
@@ -668,7 +654,7 @@ async function alert(prompt, options = {}) {
|
|
|
668
654
|
}
|
|
669
655
|
|
|
670
656
|
// src/index.ts
|
|
671
|
-
var version = "2.11.
|
|
657
|
+
var version = "2.11.1";
|
|
672
658
|
export {
|
|
673
659
|
ConfirmButtons,
|
|
674
660
|
SessionHandler,
|
|
@@ -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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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(
|
|
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) : "";
|
|
@@ -307,9 +409,10 @@ function has(obj, key) {
|
|
|
307
409
|
// src/parseFunc.ts
|
|
308
410
|
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
411
|
function parseFunc(func) {
|
|
412
|
+
var _a2;
|
|
310
413
|
var match = func.toString().match(funcRegex);
|
|
311
414
|
invariant(match, "Unable to parse function!");
|
|
312
|
-
return { name: match[1], args: match[2].split(","), body: match[3] };
|
|
415
|
+
return { name: (_a2 = func.name) != null ? _a2 : match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
|
|
313
416
|
}
|
|
314
417
|
|
|
315
418
|
// src/Namespace.ts
|
|
@@ -448,123 +551,6 @@ function localize(stringParts, ...args) {
|
|
|
448
551
|
return localized;
|
|
449
552
|
}
|
|
450
553
|
|
|
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
554
|
// src/settings.ts
|
|
569
555
|
function getKey(article) {
|
|
570
556
|
const articleKey = article || af.article.id;
|
|
@@ -697,7 +683,7 @@ async function alert(prompt, options = {}) {
|
|
|
697
683
|
}
|
|
698
684
|
|
|
699
685
|
// src/index.ts
|
|
700
|
-
var version = "2.11.
|
|
686
|
+
var version = "2.11.1";
|
|
701
687
|
export {
|
|
702
688
|
ConfirmButtons,
|
|
703
689
|
SessionHandler,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Q=Object.defineProperty,P=Object.defineProperties;var ee=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable;var D=(e,t,o)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,p=(e,t)=>{for(var o in t||(t={}))te.call(t,o)&&D(e,o,t[o]);if($)for(var o of $(t))ne.call(t,o)&&D(e,o,t[o]);return e},C=(e,t)=>P(e,ee(t));var l=(e,t,o)=>(D(e,typeof t!="symbol"?t+"":t,o),o);function I(e){return{all:e=e||new Map,on:function(t,o){var n=e.get(t);n?n.push(o):e.set(t,[o])},off:function(t,o){var n=e.get(t);n&&(o?n.splice(n.indexOf(o)>>>0,1):e.set(t,[]))},emit:function(t,o){var n=e.get(t);n&&n.slice().map(function(r){r(o)}),(n=e.get("*"))&&n.slice().map(function(r){r(t,o)})}}}var m=class{constructor(){l(this,"eventHandler",I())}authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(t,o){try{let n=new Promise(a=>{let i=()=>{this.eventHandler.off("onAuthenticated",i),t==null||t(),a()};this.eventHandler.on("onAuthenticated",i)}),r=document.querySelector("dialog.session-expired-dialog");if(r)await n;else{r=document.createElement("dialog"),r.className="session-expired-dialog",r.style.display="flex",r.style.padding="0",r.style.left="50%",r.style.transform="translateX(-50%)";let a="/login?ReturnUrl=%2fapi/sessionexpired/remove";o!=="RequireTwoFactor"?await fetch("/logout",{method:"POST"}):a="/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove",r.innerHTML='<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="'.concat(a,'" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>'),document.body.append(r),r.showModal(),await n,r.remove()}}catch(n){window.location.href="/login?ReturnUrl=".concat(encodeURIComponent(window.location.pathname)).concat(encodeURIComponent(window.location.search))}}attachEvent(t,o){return this.eventHandler.on(t,o)}detachEvent(t,o){return this.eventHandler.off(t,o)}};var L=class extends m{constructor(o){super();l(this,"amDesignator","a.m.");l(this,"dayNames",["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]);l(this,"dayNamesShort",["sun","mon","tue","wed","thu","fri","sat"]);l(this,"decimalSeparator",".");l(this,"domain","OB");l(this,"email");l(this,"formats");l(this,"groupSeparator",null);l(this,"integratedSecurity",!1);l(this,"isDeveloper",!1);l(this,"login","");l(this,"loginType");l(this,"monthNames",["january","february","march","april","may","june","july","august","september","october","november","december",""]);l(this,"monthNamesShort",["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""]);l(this,"name");l(this,"pmDesignator","p.m.");l(this,"shortDateFormat","dd.MM.yyyy");l(this,"culture","en-GB");l(this,"uiculture","en-GB");this.formats={},Object.assign(this,o)}};var U;(U=window.window)==null||U.addEventListener("error",e=>{var t,o,n,r,a,i,d;try{let c={error:(n=(o=(t=e.error)==null?void 0:t.message)!=null?o:e.message)!=null?n:null,file:e.filename,line:(r=e.lineno)!=null?r:0,column:(a=e.colno)!=null?a:0,stack:(d=(i=e.error)==null?void 0:i.stack)!=null?d:null};fetch("/data/Logger/LogError",{body:JSON.stringify(c),headers:{Accept:"application/json","Content-Type":"application/json; charset=utf-8","X-Requested-With":"XMLHttpRequest"},method:"POST"})}catch(c){}});function _(e){var t;return[((t=af==null?void 0:af.article)==null?void 0:t.id)||"","common",e].join(".")}var E=class{constructor(){l(this,"isPersisted",()=>!0)}getLocalStorageKey(t,o){return o?["common",t].join("."):_(t)}get(t,o,n){let r=this.getLocalStorageKey(t,n),a=localStorage.getItem(r);return a!==null?JSON.parse(a):o}set(t,o,n){localStorage.setItem(this.getLocalStorageKey(t,n),JSON.stringify(o))}remove(t,o){let n=this.getLocalStorageKey(t,o);return localStorage.getItem(n)!==null?(localStorage.removeItem(n),!0):!1}clear(){let t=_("");for(let o in localStorage)o.slice(0,t.length)===t&&localStorage.removeItem(o)}},oe=new E;function re(e){return e?H(e).substring(0,10):null}function g(e){return String(e).padStart(2,"0")}function H(e){return e?"".concat(e.getFullYear(),"-").concat(g(e.getMonth()+1),"-").concat(g(e.getDate()),"T").concat(g(e.getHours()),":").concat(g(e.getMinutes()),":").concat(g(e.getSeconds()),".").concat(g(e.getMilliseconds())):null}function ie(e){return e?e.toISOString().substring(0,16):""}function T(e,t){return new Promise(function(o,n){try{let r=URL.createObjectURL(e),a=document.body,i=document.createElement("a");i.setAttribute("download",t),i.href=r,a.append(i),i.click(),a.removeChild(i),setTimeout(function(){URL.revokeObjectURL(r),o()},250)}catch(r){n(r)}})}function u(e,t){if(e)return;let o=typeof t=="function"?t():t;throw new Error(o!=null?o:"Invariant failed")}async function ae(e,{fileName:t,signal:o,onProgress:n}){var a;let r=0;n==null||n({status:"requested"});try{let i=await fetch(e);if(!i.ok||!i.body){if((a=i.headers.get("content-type"))!=null&&a.includes("application/json")){let c=await i.json();u(!c.error,c.error)}throw new Error("".concat(i.status," ").concat(i.statusText))}try{let c=i.body.getReader(),A=new ReadableStream({start:function(y){function h(){return c.read().then(function(s){if(s.done){y.close();return}return r+=s.value.length,n==null||n({bytesReceived:r,status:"downloading"}),y.enqueue(s.value),h()})}return h()}});i=new Response(A)}catch(c){}let d=await i.blob();n==null||n({bytesReceived:r,status:"downloaded"}),await T(d,t),n==null||n({bytesReceived:r,status:"completed"})}catch(i){o!=null&&o.aborted?n==null||n({status:"cancelled"}):n==null||n({error:i.message,status:"error"})}}function x(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var le=/^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)*)\}$/;function z(e){var t=e.toString().match(le);return u(t,"Unable to parse function!"),{name:t[1],args:t[2].split(","),body:t[3]}}function M(){}M.prototype=Object.create(null);var q=M;function O(e,t){if(typeof e=="object"){if(typeof t=="string"){let o=t.split(".");return O(e,o)}else if(Array.isArray(t)){let o=e;for(let n=0;n<t.length;n++)o=o[t[n]]=o[t[n]]||new q;return o}}}function k(e,t,o={}){if(Array.isArray(t))for(let n of t){let{name:r}=z(n);u(r,"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."),k(e,n)}else{let n,r;if(typeof t=="function"&&(n=z(t).name),typeof e=="string"){let a=e.split(".");n||(n=a[a.length-1],a=a.slice(0,a.length-1)),r=O(window,a)}else n&&(typeof e=="object"||typeof e=="function")?r=e:u(!1,"Invalid typeof parameter 'name', or unable to parse pValue!");x(r,n)&&(o==null?void 0:o.overwrite)!==!0?console.warn([e,n].join(".")+" is already defined!"):r[n]=t}}var se={xs:64,sm:128,md:256,lg:512,xl:void 0};function B(e,t,o,n="xs"){if(e&&typeof e=="object")return B(e.primKey,e.login,e.hash,e.size);if(!e||!o)return"";let r=se[n];return"/api/data/blob/EmployeesLookup/".concat(e,"/Image/").concat(encodeURIComponent(t!=null?t:"")).concat(t?".":"").concat(encodeURIComponent(o),".jpg").concat(r?"?width=".concat(r):"")}async function ce(e){try{let t=await fetch("/api/user/localize/new/".concat(af.article.id),{body:JSON.stringify({text:e}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(t.ok)return await t.json()}catch(t){}return e}function f(e,t){var o,n;if(typeof e=="string"&&e.trim().length===0)return e;if(!(e===void 0||e===""||e===null))if(((n=(o=window.af)==null?void 0:o.article)==null?void 0:n.i18n)!==void 0){if(!x(af.article.i18n,e)){af.article.i18n[e]=e;let r=ce(e).then(a=>(af.article.i18n[e]=a,a));if(t)return r}return af.article.i18n[e]}else return e}function ue(e,...t){u(Array.isArray(e)&&e.length===t.length+1,"Method 'localize' must be used as a tag function");let o=e.map((r,a)=>a===e.length-1?r:"".concat(r,"$").concat(a)).join(""),n=f(o);return t.forEach((r,a)=>{n=n.replace("$"+a,r)}),n}async function j(e,t={},o=0){var n;try{let r=await fetch("/api/logging/log-activity",{method:"POST",body:JSON.stringify({article:af.article.id,timeElapsed:o,action:e,parameters:C(p({},t),{_session:N()})}),headers:{"Content-Type":"application/json",Accept:"application/json"}});if(!r.ok)if((n=r.headers.get("Content-Type"))!=null&&n.includes("application/json")){let a=await r.json();console.error(a.error)}else console.error("".concat(r.status," ").concat(r.statusText))}catch(r){}}function de(e,t={}){let o=performance.now();return(n={})=>j(e,p(p({},t),n),performance.now()-o)}async function fe(e){let t=performance.now();return[await e(),performance.now()-t]}async function pe(e){var t;try{if(!e)return;let o=typeof e=="string"?{error:e}:typeof e=="object"?"message"in e?{error:e.message,stack:(t=e.stack)!=null?t:null}:{error:e.toString()}:{error:"Unspecified error"};console.error(e);let n=await fetch("/data/Logger/LogError",{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json; charset=utf-8"}});if(n.ok)return await n.json();console.error(Error("Failed to log error"))}catch(o){}}function J(){var e;return(e=crypto.randomUUID)==null?void 0:e.call(crypto)}var F=Date.now(),K=J(),b="",v="";if("document"in window){let e=()=>{var t;return j("AfSessionInit",{"appframe-core":af.common.version,"appframe-data":(t=af.data)==null?void 0:t.version,"app-version":af.article.version})};document.addEventListener("DOMContentLoaded",()=>{b=localStorage.getItem("_afDeviceId"),v=sessionStorage.getItem("_afSessionId"),b||(b=J(),localStorage.setItem("_afDeviceId",b)),v||(v=K,sessionStorage.setItem("_afSessionId",v)),e()}),document.addEventListener("visibilitychange",function(){document.visibilityState==="hidden"?navigator.sendBeacon("/api/logging/log-activity",JSON.stringify({article:af.article.id,action:"AfSessionEnd",parameters:{_session:N()}})):e()})}function N(){return{browserSessionId:v,sessionStart:F,sessionLength:Date.now()-F,sessionId:K,deviceId:b}}function V(e){let t=e||af.article.id;return"".concat(t,".").concat(af.userSession.login)}function me(e,t){if(!(af!=null&&af.userSession))return null;let o=V(t),n=JSON.parse(localStorage.getItem(o)||"{}");return e?n[e]||null:n}function ge(e,t,o){if(!(af!=null&&af.userSession))return;let n=V(o),r=JSON.parse(localStorage.getItem(n)||"{}");typeof t<"u"?r[e]=t:r=e,localStorage.setItem(n,JSON.stringify(r))}var ye='\n <dialog class="alert-dialog">\n <form method="dialog">\n <article></article>\n <footer>\n <menu></menu>\n </footer>\n </form>\n </dialog>\n';if(window.document&&!document.querySelector("#AlertDialogTemplate")){let e=document.createElement("template");e.id="AlertDialogTemplate",e.innerHTML=ye,document.body.append(e)}function Z(e,t="No"){return new Promise(o=>{let n=new AbortController;e.addEventListener("close",()=>{o(e.returnValue),n.abort()},{signal:n.signal}),e.addEventListener("cancel",()=>{o(t),n.abort()},{signal:n.signal})})}var w=new Map;async function R({buttons:e,content:t,className:o,id:n,title:r}){var y,h;if(n&&w.has(n))return await w.get(n);let a=document.querySelector("#AlertDialogTemplate");if(!a)throw Error("No alert dialog template found");let i=(y=a.content.firstElementChild)==null?void 0:y.cloneNode(!0),d=i==null?void 0:i.querySelector("article"),c=i==null?void 0:i.querySelector("footer menu");if(!i||!d||!c)throw Error("Invalid alert dialog template");if(o&&o.split(/\s+/).forEach(s=>i==null?void 0:i.classList.add(s)),r){let s=document.createElement("header");s.append(r),(h=d.parentNode)==null||h.insertBefore(s,d)}d.appendChild(typeof t=="string"?document.createTextNode(t):t);for(let{label:s,value:Y,primary:W}of e){let G=document.createElement("li"),S=document.createElement("button");S.value=Y,W&&S.classList.add("primary"),S.textContent=s,G.appendChild(S),c.appendChild(S)}document.body.appendChild(i),i.showModal();let A=Z(i).then(s=>(n&&w.has(n)&&w.delete(n),i&&document.body.removeChild(i),s));return n&&w.set(n,A),await A}var X=(o=>(o[o.YesNo=0]="YesNo",o[o.OkCancel=1]="OkCancel",o))(X||{});async function he(e,t={}){let{buttons:o=0,title:n}=t,r=o===1?[{label:f("OK"),value:"yes",primary:!0},{label:f("Cancel"),value:"no"}]:[{label:f("Yes"),value:"yes",primary:!0},{label:f("No"),value:"no"}];return await R({content:e,buttons:r,className:"alert-dialog-confirm",title:n})==="yes"}async function Se(e,t={}){await R(p({content:e,className:"alert-dialog-alert",buttons:[{label:f("OK"),value:"ok",primary:!0}]},t))}var ct="2.11.0";export{X as ConfirmButtons,m as SessionHandler,L as UserSession,Se as alert,he as confirm,T as downloadBlob,ae as downloadRequest,k as expose,f as getLocalizedString,N as getSessionData,me as getSettings,B as getUserImage,x as has,u as invariant,oe as localStorage,ue as localize,j as logActivity,pe as logError,I as mitt,R as openAlertDialog,ge as saveSettings,de as startActivity,fe as time,ie as toLocalDateTime,re as toLocalISODate,H as toLocalISODateTime,ct as version,Z as waitForDialog};
|
|
1
|
+
var P=Object.defineProperty,ee=Object.defineProperties;var te=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var I=(e,t,o)=>t in e?P(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,m=(e,t)=>{for(var o in t||(t={}))ne.call(t,o)&&I(e,o,t[o]);if(C)for(var o of C(t))oe.call(t,o)&&I(e,o,t[o]);return e},U=(e,t)=>ee(e,te(t));var l=(e,t,o)=>(I(e,typeof t!="symbol"?t+"":t,o),o);function L(e){return{all:e=e||new Map,on:function(t,o){var n=e.get(t);n?n.push(o):e.set(t,[o])},off:function(t,o){var n=e.get(t);n&&(o?n.splice(n.indexOf(o)>>>0,1):e.set(t,[]))},emit:function(t,o){var n=e.get(t);n&&n.slice().map(function(r){r(o)}),(n=e.get("*"))&&n.slice().map(function(r){r(t,o)})}}}var p=class{constructor(){l(this,"eventHandler",L())}authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(t,o){try{let n=new Promise(a=>{let i=()=>{this.eventHandler.off("onAuthenticated",i),t==null||t(),a()};this.eventHandler.on("onAuthenticated",i)}),r=document.querySelector("dialog.session-expired-dialog");if(r)await n;else{r=document.createElement("dialog"),r.className="session-expired-dialog",r.style.display="flex",r.style.padding="0",r.style.left="50%",r.style.transform="translateX(-50%)";let a="/login?ReturnUrl=%2fapi/sessionexpired/remove";o!=="RequireTwoFactor"?await fetch("/logout",{method:"POST"}):a="/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove",r.innerHTML='<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="'.concat(a,'" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>'),document.body.append(r),r.showModal(),await n,r.remove()}}catch(n){window.location.href="/login?ReturnUrl=".concat(encodeURIComponent(window.location.pathname)).concat(encodeURIComponent(window.location.search))}}attachEvent(t,o){return this.eventHandler.on(t,o)}detachEvent(t,o){return this.eventHandler.off(t,o)}};var E=class extends p{constructor(o){super();l(this,"amDesignator","a.m.");l(this,"dayNames",["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]);l(this,"dayNamesShort",["sun","mon","tue","wed","thu","fri","sat"]);l(this,"decimalSeparator",".");l(this,"domain","OB");l(this,"email");l(this,"formats");l(this,"groupSeparator",null);l(this,"integratedSecurity",!1);l(this,"isDeveloper",!1);l(this,"login","");l(this,"loginType");l(this,"monthNames",["january","february","march","april","may","june","july","august","september","october","november","december",""]);l(this,"monthNamesShort",["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""]);l(this,"name");l(this,"pmDesignator","p.m.");l(this,"shortDateFormat","dd.MM.yyyy");l(this,"culture","en-GB");l(this,"uiculture","en-GB");this.formats={},Object.assign(this,o)}};async function T(e,t={},o=0){var n;try{let r=await fetch("/api/logging/log-activity",{method:"POST",body:JSON.stringify({article:af.article.id,timeElapsed:o,action:e,parameters:U(m({},t),{_session:z()})}),headers:{"Content-Type":"application/json",Accept:"application/json"}});if(!r.ok)if((n=r.headers.get("Content-Type"))!=null&&n.includes("application/json")){let a=await r.json();console.error(a.error)}else console.error("".concat(r.status," ").concat(r.statusText))}catch(r){}}function re(e,t={}){let o=performance.now();return(n={})=>T(e,m(m({},t),n),performance.now()-o)}async function ie(e){let t=performance.now();return[await e(),performance.now()-t]}async function A(e){var t;try{if(!e)return;let o=typeof e=="string"?{error:e}:typeof e=="object"?"message"in e?{error:e.message,stack:(t=e.stack)!=null?t:null}:{error:e.toString()}:{error:"Unspecified error"};console.error(e);let n=await fetch("/data/Logger/LogError",{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json; charset=utf-8"}});if(n.ok)return await n.json();console.error(Error("Failed to log error"))}catch(o){}}function H(){var e;return(e=crypto.randomUUID)==null?void 0:e.call(crypto)}var _=Date.now(),M=H(),b="",x="";if("document"in window){let e=()=>{var t;return T("AfSessionInit",{"appframe-core":af.common.version,"appframe-data":(t=af.data)==null?void 0:t.version,"app-version":af.article.version})};document.addEventListener("DOMContentLoaded",()=>{b=localStorage.getItem("_afDeviceId"),x=sessionStorage.getItem("_afSessionId"),b||(b=H(),localStorage.setItem("_afDeviceId",b)),x||(x=M,sessionStorage.setItem("_afSessionId",x)),e()}),document.addEventListener("visibilitychange",function(){document.visibilityState==="hidden"?navigator.sendBeacon("/api/logging/log-activity",JSON.stringify({article:af.article.id,action:"AfSessionEnd",parameters:{_session:z()}})):e()})}function z(){return{browserSessionId:x,sessionStart:_,sessionLength:Date.now()-_,sessionId:M,deviceId:b}}var q;(q=window.window)==null||q.addEventListener("error",e=>{typeof e=="object"&&"error"in e?A(e.error):typeof e=="object"&&"message"in e&&A(e)});function k(e){var t;return[((t=af==null?void 0:af.article)==null?void 0:t.id)||"","common",e].join(".")}var O=class{constructor(){l(this,"isPersisted",()=>!0)}getLocalStorageKey(t,o){return o?["common",t].join("."):k(t)}get(t,o,n){let r=this.getLocalStorageKey(t,n),a=localStorage.getItem(r);return a!==null?JSON.parse(a):o}set(t,o,n){localStorage.setItem(this.getLocalStorageKey(t,n),JSON.stringify(o))}remove(t,o){let n=this.getLocalStorageKey(t,o);return localStorage.getItem(n)!==null?(localStorage.removeItem(n),!0):!1}clear(){let t=k("");for(let o in localStorage)o.slice(0,t.length)===t&&localStorage.removeItem(o)}},ae=new O;function le(e){return e?B(e).substring(0,10):null}function g(e,t=2){return String(e).padStart(t,"0")}function B(e){return e?"".concat(e.getFullYear(),"-").concat(g(e.getMonth()+1),"-").concat(g(e.getDate()),"T").concat(g(e.getHours()),":").concat(g(e.getMinutes()),":").concat(g(e.getSeconds()),".").concat(g(e.getMilliseconds(),3)):null}function se(e){return e?e.toISOString().substring(0,16):""}function j(e,t){return new Promise(function(o,n){try{let r=URL.createObjectURL(e),a=document.body,i=document.createElement("a");i.setAttribute("download",t),i.href=r,a.append(i),i.click(),a.removeChild(i),setTimeout(function(){URL.revokeObjectURL(r),o()},250)}catch(r){n(r)}})}function c(e,t){if(e)return;let o=typeof t=="function"?t():t;throw new Error(o!=null?o:"Invariant failed")}async function ce(e,{fileName:t,signal:o,onProgress:n}){var a;let r=0;n==null||n({status:"requested"});try{let i=await fetch(e);if(!i.ok||!i.body){if((a=i.headers.get("content-type"))!=null&&a.includes("application/json")){let d=await i.json();c(!d.error,d.error)}throw new Error("".concat(i.status," ").concat(i.statusText))}try{let d=i.body.getReader(),D=new ReadableStream({start:function(y){function h(){return d.read().then(function(s){if(s.done){y.close();return}return r+=s.value.length,n==null||n({bytesReceived:r,status:"downloading"}),y.enqueue(s.value),h()})}return h()}});i=new Response(D)}catch(d){}let f=await i.blob();n==null||n({bytesReceived:r,status:"downloaded"}),await j(f,t),n==null||n({bytesReceived:r,status:"completed"})}catch(i){o!=null&&o.aborted?n==null||n({status:"cancelled"}):n==null||n({error:i.message,status:"error"})}}function v(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var ue=/^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)*)\}$/;function N(e){var o;var t=e.toString().match(ue);return c(t,"Unable to parse function!"),{name:(o=e.name)!=null?o:t[1],args:t[2].split(",").map(n=>n.trim()),body:t[3]}}function F(){}F.prototype=Object.create(null);var J=F;function R(e,t){if(typeof e=="object"){if(typeof t=="string"){let o=t.split(".");return R(e,o)}else if(Array.isArray(t)){let o=e;for(let n=0;n<t.length;n++)o=o[t[n]]=o[t[n]]||new J;return o}}}function K(e,t,o={}){if(Array.isArray(t))for(let n of t){let{name:r}=N(n);c(r,"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."),K(e,n)}else{let n,r;if(typeof t=="function"&&(n=N(t).name),typeof e=="string"){let a=e.split(".");n||(n=a[a.length-1],a=a.slice(0,a.length-1)),r=R(window,a)}else n&&(typeof e=="object"||typeof e=="function")?r=e:c(!1,"Invalid typeof parameter 'name', or unable to parse pValue!");v(r,n)&&(o==null?void 0:o.overwrite)!==!0?console.warn([e,n].join(".")+" is already defined!"):r[n]=t}}var de={xs:64,sm:128,md:256,lg:512,xl:void 0};function V(e,t,o,n="xs"){if(e&&typeof e=="object")return V(e.primKey,e.login,e.hash,e.size);if(!e||!o)return"";let r=de[n];return"/api/data/blob/EmployeesLookup/".concat(e,"/Image/").concat(encodeURIComponent(t!=null?t:"")).concat(t?".":"").concat(encodeURIComponent(o),".jpg").concat(r?"?width=".concat(r):"")}async function fe(e){try{let t=await fetch("/api/user/localize/new/".concat(af.article.id),{body:JSON.stringify({text:e}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(t.ok)return await t.json()}catch(t){}return e}function u(e,t){var o,n;if(typeof e=="string"&&e.trim().length===0)return e;if(!(e===void 0||e===""||e===null))if(((n=(o=window.af)==null?void 0:o.article)==null?void 0:n.i18n)!==void 0){if(!v(af.article.i18n,e)){af.article.i18n[e]=e;let r=fe(e).then(a=>(af.article.i18n[e]=a,a));if(t)return r}return af.article.i18n[e]}else return e}function me(e,...t){c(Array.isArray(e)&&e.length===t.length+1,"Method 'localize' must be used as a tag function");let o=e.map((r,a)=>a===e.length-1?r:"".concat(r,"$").concat(a)).join(""),n=u(o);return t.forEach((r,a)=>{n=n.replace("$"+a,r)}),n}function Z(e){let t=e||af.article.id;return"".concat(t,".").concat(af.userSession.login)}function pe(e,t){if(!(af!=null&&af.userSession))return null;let o=Z(t),n=JSON.parse(localStorage.getItem(o)||"{}");return e?n[e]||null:n}function ge(e,t,o){if(!(af!=null&&af.userSession))return;let n=Z(o),r=JSON.parse(localStorage.getItem(n)||"{}");typeof t<"u"?r[e]=t:r=e,localStorage.setItem(n,JSON.stringify(r))}var ye='\n <dialog class="alert-dialog">\n <form method="dialog">\n <article></article>\n <footer>\n <menu></menu>\n </footer>\n </form>\n </dialog>\n';if(window.document&&!document.querySelector("#AlertDialogTemplate")){let e=document.createElement("template");e.id="AlertDialogTemplate",e.innerHTML=ye,document.body.append(e)}function Y(e,t="No"){return new Promise(o=>{let n=new AbortController;e.addEventListener("close",()=>{o(e.returnValue),n.abort()},{signal:n.signal}),e.addEventListener("cancel",()=>{o(t),n.abort()},{signal:n.signal})})}var w=new Map;async function $({buttons:e,content:t,className:o,id:n,title:r}){var y,h;if(n&&w.has(n))return await w.get(n);let a=document.querySelector("#AlertDialogTemplate");if(!a)throw Error("No alert dialog template found");let i=(y=a.content.firstElementChild)==null?void 0:y.cloneNode(!0),f=i==null?void 0:i.querySelector("article"),d=i==null?void 0:i.querySelector("footer menu");if(!i||!f||!d)throw Error("Invalid alert dialog template");if(o&&o.split(/\s+/).forEach(s=>i==null?void 0:i.classList.add(s)),r){let s=document.createElement("header");s.append(r),(h=f.parentNode)==null||h.insertBefore(s,f)}f.appendChild(typeof t=="string"?document.createTextNode(t):t);for(let{label:s,value:G,primary:W}of e){let Q=document.createElement("li"),S=document.createElement("button");S.value=G,W&&S.classList.add("primary"),S.textContent=s,Q.appendChild(S),d.appendChild(S)}document.body.appendChild(i),i.showModal();let D=Y(i).then(s=>(n&&w.has(n)&&w.delete(n),i&&document.body.removeChild(i),s));return n&&w.set(n,D),await D}var X=(o=>(o[o.YesNo=0]="YesNo",o[o.OkCancel=1]="OkCancel",o))(X||{});async function he(e,t={}){let{buttons:o=0,title:n}=t,r=o===1?[{label:u("OK"),value:"yes",primary:!0},{label:u("Cancel"),value:"no"}]:[{label:u("Yes"),value:"yes",primary:!0},{label:u("No"),value:"no"}];return await $({content:e,buttons:r,className:"alert-dialog-confirm",title:n})==="yes"}async function Se(e,t={}){await $(m({content:e,className:"alert-dialog-alert",buttons:[{label:u("OK"),value:"ok",primary:!0}]},t))}var ut="2.11.1";export{X as ConfirmButtons,p as SessionHandler,E as UserSession,Se as alert,he as confirm,j as downloadBlob,ce as downloadRequest,K as expose,u as getLocalizedString,z as getSessionData,pe as getSettings,V as getUserImage,v as has,c as invariant,ae as localStorage,me as localize,T as logActivity,A as logError,L as mitt,$ as openAlertDialog,ge as saveSettings,re as startActivity,ie as time,se as toLocalDateTime,le as toLocalISODate,B as toLocalISODateTime,ut as version,Y as waitForDialog};
|
|
2
2
|
//# sourceMappingURL=af.common.legacy.min.js.map
|