action-lens 1.0.6

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/index.mjs ADDED
@@ -0,0 +1,752 @@
1
+ // src/player.ts
2
+ import {
3
+ doc,
4
+ collection,
5
+ where,
6
+ query,
7
+ getDocs,
8
+ orderBy,
9
+ getDoc
10
+ } from "firebase/firestore";
11
+ import { Replayer } from "rrweb";
12
+
13
+ // src/utils/index.ts
14
+ import { initializeApp } from "firebase/app";
15
+ import { getFirestore } from "firebase/firestore";
16
+ var firebaseConfig = {
17
+ apiKey: "AIzaSyCxreoOZivnjFIh2mJ6WXjS3ieQ11wsDW8",
18
+ authDomain: "actionlens-b14ae.firebaseapp.com",
19
+ projectId: "actionlens-b14ae",
20
+ storageBucket: "actionlens-b14ae.firebasestorage.app",
21
+ messagingSenderId: "36086339210",
22
+ appId: "1:36086339210:web:36e16e8778aadd8c58ff73"
23
+ };
24
+ var app = initializeApp(firebaseConfig);
25
+ var db = getFirestore(app);
26
+
27
+ // src/player.ts
28
+ var ActionLensPlayer = class {
29
+ replayer = null;
30
+ overlayContainer = null;
31
+ playerStatus = "stopped";
32
+ targetDivId;
33
+ db;
34
+ prefix;
35
+ userId = null;
36
+ projectId = null;
37
+ currentTime = 0;
38
+ // 現在の再生時間
39
+ totalTime = 0;
40
+ // 再生中の時間を保持するための変数
41
+ setIntervalId = null;
42
+ // setTimeoutのIDを保持するための変数
43
+ constructor(userId, targetDivId, projectId, _db = db, prefix = "") {
44
+ this.userId = userId;
45
+ this.targetDivId = targetDivId;
46
+ this.db = _db;
47
+ this.prefix = prefix;
48
+ this.projectId = projectId;
49
+ }
50
+ async replayRrwebSession(sessionId) {
51
+ try {
52
+ const q = query(
53
+ collection(this.db, `${this.prefix}ActionRecord`),
54
+ where("sessionId", "==", sessionId),
55
+ orderBy("timeStamp", "asc")
56
+ );
57
+ const querySnapshot = await getDocs(q);
58
+ const events = querySnapshot.docs.map((doc3) => {
59
+ const data = doc3.data();
60
+ return JSON.parse(data.rrwebRecord);
61
+ });
62
+ console.log("events", events);
63
+ if (events.length === 0) {
64
+ console.warn(
65
+ `\u30BB\u30C3\u30B7\u30E7\u30F3ID ${sessionId} \u306E\u30C7\u30FC\u30BF\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F\u3002`
66
+ );
67
+ return;
68
+ }
69
+ const targetDiv = document.getElementById(this.targetDivId);
70
+ if (!targetDiv) {
71
+ throw new Error(
72
+ `ID ${this.targetDivId} \u306Ediv\u8981\u7D20\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F\u3002`
73
+ );
74
+ }
75
+ targetDiv.classList.add("replayer-container");
76
+ this.replayer = new Replayer(events, {
77
+ root: targetDiv,
78
+ UNSAFE_replayCanvas: false,
79
+ props: {
80
+ autoPlay: true,
81
+ speed: 1,
82
+ mouseTail: true
83
+ },
84
+ className: "_replayer-canvas"
85
+ });
86
+ this.replayer.on("custom-event", (event) => {
87
+ console.log("Custom event:", event);
88
+ this.handleCustomEvent(event);
89
+ });
90
+ this.replayer.on("finish", () => {
91
+ console.log("Replay finished");
92
+ this.replayer?.pause(0);
93
+ this.playerStatus = "stopped";
94
+ this.currentTime = this.replayer?.getCurrentTime() || 0;
95
+ this.endTimeoutTimeline();
96
+ });
97
+ const { totalTime } = this.replayer.getMetaData();
98
+ this.totalTime = totalTime;
99
+ const iframes = targetDiv.querySelectorAll("iframe");
100
+ iframes.forEach((iframe) => {
101
+ iframe.style.transform = "translate(-50%, -50%)";
102
+ iframe.style.position = "absolute";
103
+ iframe.style.left = "50%";
104
+ iframe.style.top = "50%";
105
+ });
106
+ const mouseTailElements = document.querySelectorAll(
107
+ ".replayer-mouse-tail"
108
+ );
109
+ mouseTailElements.forEach((element) => {
110
+ element.style.position = "absolute";
111
+ element.style.left = "50%";
112
+ element.style.top = "50%";
113
+ element.style.transform = "translate(-50%, -50%)";
114
+ element.style.zIndex = "1000";
115
+ });
116
+ this.replayer.play();
117
+ this.playerStatus = "playing";
118
+ console.log(`\u30BB\u30C3\u30B7\u30E7\u30F3ID ${sessionId} \u306E\u518D\u751F\u3092\u958B\u59CB\u3057\u307E\u3057\u305F\u3002`);
119
+ this.setTimeoutTimeline();
120
+ } catch (error) {
121
+ console.error("\u518D\u751F\u30A8\u30E9\u30FC:", error);
122
+ throw error;
123
+ }
124
+ }
125
+ // カスタムイベントを処理
126
+ handleCustomEvent(event) {
127
+ if (!event.data || !event.data.type) return;
128
+ const { timestamp } = event;
129
+ const timeString = new Date(timestamp).toISOString();
130
+ switch (event.data.type) {
131
+ case "console":
132
+ const { method, args } = event.data;
133
+ this.displayEvent(
134
+ `[${timeString}] Console ${method}: ${args.join(", ")}`,
135
+ "console"
136
+ );
137
+ break;
138
+ case "navigation":
139
+ const { url } = event.data;
140
+ this.displayEvent(`[${timeString}] Navigation to ${url}`, "navigation");
141
+ break;
142
+ case "performance":
143
+ const { name, entryType, duration } = event.data;
144
+ this.displayEvent(
145
+ `[${timeString}] Performance ${entryType}: ${name} (${duration}ms)`,
146
+ "performance"
147
+ );
148
+ break;
149
+ default:
150
+ console.warn("\u4E0D\u660E\u306A\u30AB\u30B9\u30BF\u30E0\u30A4\u30D9\u30F3\u30C8:", event.data.type);
151
+ }
152
+ }
153
+ // イベントをオーバーレイに表示
154
+ displayEvent(message, eventType) {
155
+ if (!this.overlayContainer) return;
156
+ const eventDiv = document.createElement("div");
157
+ eventDiv.style.padding = "5px";
158
+ eventDiv.style.borderBottom = "1px solid rgba(255, 255, 255, 0.2)";
159
+ const colors = {
160
+ console: "#00cc00",
161
+ navigation: "#3399ff",
162
+ performance: "#ff9900"
163
+ };
164
+ eventDiv.style.color = colors[eventType] || "white";
165
+ eventDiv.innerText = message;
166
+ this.overlayContainer.appendChild(eventDiv);
167
+ this.overlayContainer.scrollTop = this.overlayContainer.scrollHeight;
168
+ setTimeout(() => {
169
+ eventDiv.style.transition = "opacity 1s";
170
+ eventDiv.style.opacity = "0";
171
+ setTimeout(() => eventDiv.remove(), 1e3);
172
+ }, 5e3);
173
+ }
174
+ setReplayTime(time) {
175
+ if (this.replayer) {
176
+ this.replayer.pause(time);
177
+ this.currentTime = time;
178
+ this.playerStatus = "stopped";
179
+ }
180
+ }
181
+ setTimeoutTimeline() {
182
+ this.setIntervalId = setInterval(() => {
183
+ this.currentTime = this.replayer?.getCurrentTime() || 0;
184
+ }, 10);
185
+ }
186
+ endTimeoutTimeline() {
187
+ if (this.setIntervalId) {
188
+ clearTimeout(this.setIntervalId);
189
+ this.setIntervalId = null;
190
+ }
191
+ }
192
+ // 再生を停止
193
+ stopReplay() {
194
+ this.endTimeoutTimeline();
195
+ if (this.replayer) {
196
+ this.replayer.pause();
197
+ this.playerStatus = "stopped";
198
+ this.currentTime = this.replayer?.getCurrentTime() || 0;
199
+ }
200
+ }
201
+ restartReplay() {
202
+ this.setTimeoutTimeline();
203
+ if (this.replayer) {
204
+ const offset = this.replayer.getCurrentTime();
205
+ console.log("offset", offset);
206
+ this.replayer.play(offset);
207
+ this.playerStatus = "playing";
208
+ this.currentTime = this.replayer?.getCurrentTime() || 0;
209
+ }
210
+ }
211
+ getCurrentTime() {
212
+ if (this.replayer) {
213
+ return this.replayer.getCurrentTime();
214
+ }
215
+ return 0;
216
+ }
217
+ resetReplayer() {
218
+ this.endTimeoutTimeline();
219
+ this.playerStatus = "stopped";
220
+ this.currentTime = 0;
221
+ if (this.replayer) {
222
+ this.replayer.pause();
223
+ this.replayer.destroy();
224
+ this.replayer = null;
225
+ }
226
+ if (this.overlayContainer) {
227
+ this.overlayContainer.remove();
228
+ this.overlayContainer = null;
229
+ }
230
+ }
231
+ async fetchSessionList() {
232
+ try {
233
+ const q = query(
234
+ collection(this.db, `${this.prefix}ActionRecordSession`),
235
+ where("projectId", "==", this.projectId),
236
+ orderBy("startTime", "desc")
237
+ );
238
+ const usersStore = {};
239
+ const querySnapshot = await getDocs(q);
240
+ const promise = querySnapshot.docs.map(async (_doc) => {
241
+ const data = _doc.data();
242
+ if (!usersStore[data.userId]) {
243
+ usersStore[data.userId] = (await getDoc(doc(this.db, `${this.prefix}user`, data.userId))).data();
244
+ }
245
+ return { ...data, userData: usersStore[data.userId] };
246
+ });
247
+ const sessions = await Promise.all(promise);
248
+ console.log(sessions);
249
+ return sessions;
250
+ } catch (error) {
251
+ console.error("\u30BB\u30C3\u30B7\u30E7\u30F3\u30EA\u30B9\u30C8\u306E\u53D6\u5F97\u30A8\u30E9\u30FC:", error);
252
+ throw error;
253
+ }
254
+ }
255
+ };
256
+
257
+ // src/record.ts
258
+ import { v4 as uuidv4 } from "uuid";
259
+ import { record } from "rrweb";
260
+ import { doc as doc2, setDoc as setDoc2, collection as collection2, getDoc as getDoc2 } from "firebase/firestore";
261
+ var ActionLensRc = class {
262
+ sessionId = uuidv4();
263
+ stopFnForStore = null;
264
+ userId = null;
265
+ db = null;
266
+ prefix = "";
267
+ userData = null;
268
+ projectId = null;
269
+ projectData = null;
270
+ organizationId = null;
271
+ originalUserId = null;
272
+ // 元のユーザーID(外部システムのIDなど)
273
+ constructor(_userId, projectId, userMeta, metaData = {}, _db = null, prefix = "") {
274
+ try {
275
+ this.originalUserId = _userId;
276
+ console.log("ActionLensRc\u958B\u59CB");
277
+ if (!projectId) {
278
+ console.error("projectId\u304CNULL\u3067\u3059");
279
+ throw new Error("projectId\u304CNULL\u3067\u3059");
280
+ }
281
+ if (!_userId) {
282
+ console.error("userId\u304CNULL\u3067\u3059");
283
+ throw new Error("userId\u304CNULL\u3067\u3059");
284
+ }
285
+ if (!_db) {
286
+ this.db = db;
287
+ } else {
288
+ this.db = _db;
289
+ }
290
+ getDoc2(doc2(collection2(this.db, `${prefix}project`), projectId)).then(async (_doc) => {
291
+ this.projectData = _doc.data();
292
+ const projectData = this.projectData;
293
+ this.organizationId = projectData?.organizationId || null;
294
+ if (!_db) {
295
+ this.db = db;
296
+ } else {
297
+ this.db = _db;
298
+ }
299
+ if (!this.projectData) {
300
+ await setDoc2(
301
+ doc2(collection2(this.db, `${prefix}project`), projectId),
302
+ {
303
+ id: projectId,
304
+ name: projectId,
305
+ organizationId: "",
306
+ isActivate: false,
307
+ // デフォルトでアクティブに設定
308
+ createAt: /* @__PURE__ */ new Date(),
309
+ updateAt: /* @__PURE__ */ new Date(),
310
+ createdBy: _userId,
311
+ updatedBy: _userId
312
+ },
313
+ { merge: true }
314
+ );
315
+ throw new Error("\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u5B58\u5728\u3057\u307E\u305B\u3093");
316
+ }
317
+ if (!this.projectData.isActivate) {
318
+ console.warn(
319
+ "\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306F\u975E\u30A2\u30AF\u30C6\u30A3\u30D6\u3067\u3059\u3002\u9332\u753B\u3092\u958B\u59CB\u3067\u304D\u307E\u305B\u3093\u3002"
320
+ );
321
+ throw new Error(
322
+ "\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306F\u975E\u30A2\u30AF\u30C6\u30A3\u30D6\u3067\u3059\u3002\u9332\u753B\u3092\u958B\u59CB\u3067\u304D\u307E\u305B\u3093\u3002"
323
+ );
324
+ }
325
+ getDoc2(doc2(collection2(this.db, `${prefix}user`), _userId)).then(async (_doc2) => {
326
+ if (!this.db) {
327
+ console.error("Firestore\u304C\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
328
+ throw new Error("Firestore\u304C\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
329
+ }
330
+ this.userId = projectData.organizationId + "-" + _userId;
331
+ const userData = _doc2.data();
332
+ if (!_doc2.exists || !userData.organizationId || !userData.projectIds || !userData.type) {
333
+ await setDoc2(
334
+ doc2(
335
+ collection2(this.db, `${prefix}user`),
336
+ projectData.organizationId + "-" + _userId
337
+ ),
338
+ {
339
+ ...userMeta || {},
340
+ metaData,
341
+ id: projectData.organizationId + "-" + _userId,
342
+ originalUserId: _userId,
343
+ type: "customer",
344
+ organizationId: projectData.organizationId,
345
+ projectIds: [projectId],
346
+ createAt: /* @__PURE__ */ new Date(),
347
+ updateAt: /* @__PURE__ */ new Date(),
348
+ createdBy: _userId,
349
+ updatedBy: _userId,
350
+ hidden: false,
351
+ hiddenBy: ""
352
+ },
353
+ { merge: true }
354
+ ).catch((error) => {
355
+ console.error("Error creating document: ", error);
356
+ throw new Error("\u30E6\u30FC\u30B6\u30FC\u306E\u4F5C\u6210\u306B\u5931\u6557\u3057\u307E\u3057\u305F");
357
+ });
358
+ this.userData = _doc2.data();
359
+ } else {
360
+ this.userData = _doc2.data();
361
+ if (!this.userData?.projectIds?.includes(projectId)) {
362
+ await setDoc2(
363
+ doc2(
364
+ collection2(this.db, `${prefix}user`),
365
+ projectData.organizationId + "-" + _userId
366
+ ),
367
+ {
368
+ projectIds: [
369
+ ...this.userData?.projectIds || [],
370
+ projectId
371
+ ],
372
+ updateAt: /* @__PURE__ */ new Date(),
373
+ updatedBy: this.userId
374
+ },
375
+ { merge: true }
376
+ ).catch((error) => {
377
+ console.error("Error updating document: ", error);
378
+ throw new Error(
379
+ "\u30E6\u30FC\u30B6\u30FC\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8ID\u306E\u66F4\u65B0\u306B\u5931\u6557\u3057\u307E\u3057\u305F"
380
+ );
381
+ });
382
+ }
383
+ if (this.userData?.organizationId !== projectData.organizationId) {
384
+ await setDoc2(
385
+ doc2(
386
+ collection2(this.db, `${prefix}user`),
387
+ projectData.organizationId + "-" + _userId
388
+ ),
389
+ {
390
+ organizationId: this.userData?.organizationId ? this.userData?.organizationId : projectData.organizationId,
391
+ updateAt: /* @__PURE__ */ new Date(),
392
+ updatedBy: this.userId
393
+ },
394
+ { merge: true }
395
+ ).catch((error) => {
396
+ console.error("Error updating document: ", error);
397
+ throw new Error("\u30E6\u30FC\u30B6\u30FC\u306E\u7D44\u7E54ID\u306E\u66F4\u65B0\u306B\u5931\u6557\u3057\u307E\u3057\u305F");
398
+ });
399
+ }
400
+ }
401
+ this.prefix = prefix;
402
+ this.projectId = projectId;
403
+ this.startRrwebRecordingForStore();
404
+ this.startConsoleRecording();
405
+ }).catch((error) => {
406
+ console.error("\u30E6\u30FC\u30B6\u30FC\u30C7\u30FC\u30BF\u306E\u53D6\u5F97\u30A8\u30E9\u30FC:", error);
407
+ throw new Error("\u30E6\u30FC\u30B6\u30FC\u30C7\u30FC\u30BF\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F");
408
+ });
409
+ }).catch((error) => {
410
+ console.error("\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30C7\u30FC\u30BF\u306E\u53D6\u5F97\u30A8\u30E9\u30FC:", error);
411
+ throw new Error("\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30C7\u30FC\u30BF\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F");
412
+ });
413
+ } catch (error) {
414
+ console.error("\u521D\u671F\u5316\u30A8\u30E9\u30FC:", error);
415
+ throw error;
416
+ }
417
+ }
418
+ // コンソールログをキャプチャ
419
+ startConsoleRecording() {
420
+ try {
421
+ const originalConsole = { ...console };
422
+ const consoleMethods = [
423
+ "log",
424
+ "info",
425
+ "warn",
426
+ "error",
427
+ "debug",
428
+ "trace",
429
+ "assert",
430
+ "clear",
431
+ "context",
432
+ "count",
433
+ "countReset",
434
+ "createTask",
435
+ "debug",
436
+ "dir",
437
+ "dirxml",
438
+ "error",
439
+ "group",
440
+ "groupCollapsed",
441
+ "groupEnd",
442
+ "memory",
443
+ "profile",
444
+ "profileEnd",
445
+ "table",
446
+ "time",
447
+ "timeEnd",
448
+ "timeLog",
449
+ "timeStamp"
450
+ ];
451
+ const db2 = this.db;
452
+ const _updateActionRecordSession = () => this.updateActionRecordSession();
453
+ consoleMethods.forEach((method) => {
454
+ console[method] = (...args) => {
455
+ originalConsole[method](...args);
456
+ if (!db2) {
457
+ console.error("Firestore\u304C\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
458
+ return;
459
+ }
460
+ const consoleEvent = {
461
+ type: "custom-event",
462
+ data: {
463
+ type: "console",
464
+ method,
465
+ args: args.map(
466
+ (arg) => typeof arg === "object" ? JSON.stringify(arg) : arg
467
+ )
468
+ },
469
+ timestamp: Date.now()
470
+ };
471
+ record.addCustomEvent("console", { method: "log", args });
472
+ _updateActionRecordSession();
473
+ };
474
+ });
475
+ } catch (error) {
476
+ console.error("\u30B3\u30F3\u30BD\u30FC\u30EB\u9332\u753B\u30A8\u30E9\u30FC:", error);
477
+ throw error;
478
+ }
479
+ }
480
+ // タイムライン(ナビゲーションとパフォーマンス)をキャプチャ
481
+ startTimelineRecording() {
482
+ try {
483
+ const userId = this.userId || "unknown";
484
+ const sessionId = this.sessionId;
485
+ const db2 = this.db;
486
+ const prefix = this.prefix;
487
+ const _updateActionRecordSession = () => this.updateActionRecordSession();
488
+ window.addEventListener("popstate", (event) => {
489
+ if (!db2) {
490
+ console.error("Firestore\u304C\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
491
+ return;
492
+ }
493
+ const navigationEvent = {
494
+ type: "custom",
495
+ data: {
496
+ type: "navigation",
497
+ url: window.location.href,
498
+ state: event.state
499
+ },
500
+ timestamp: Date.now()
501
+ };
502
+ const newDocRef = doc2(collection2(db2, `${prefix}ActionRecord`));
503
+ const record2 = {
504
+ id: newDocRef.id,
505
+ timeStamp: /* @__PURE__ */ new Date(),
506
+ userId,
507
+ type: "navigation",
508
+ originalUserId: this.originalUserId ?? "",
509
+ sessionId,
510
+ rrwebRecord: JSON.stringify(navigationEvent),
511
+ createAt: /* @__PURE__ */ new Date(),
512
+ updateAt: /* @__PURE__ */ new Date(),
513
+ hidden: false,
514
+ createdBy: userId,
515
+ updatedBy: userId,
516
+ hiddenBy: ""
517
+ };
518
+ setDoc2(newDocRef, record2).catch((error) => {
519
+ console.error("Error saving navigation event: ", error);
520
+ });
521
+ _updateActionRecordSession();
522
+ });
523
+ if (window.performance) {
524
+ const observer = new PerformanceObserver((list) => {
525
+ if (!db2) {
526
+ console.error("Firestore\u304C\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
527
+ return;
528
+ }
529
+ for (const entry of list.getEntries()) {
530
+ const performanceEvent = {
531
+ type: "custom",
532
+ data: {
533
+ type: "performance",
534
+ name: entry.name,
535
+ entryType: entry.entryType,
536
+ startTime: entry.startTime,
537
+ duration: entry.duration
538
+ },
539
+ timestamp: Date.now()
540
+ };
541
+ const newDocRef = doc2(collection2(db2, `${prefix}ActionRecord`));
542
+ const record2 = {
543
+ id: newDocRef.id,
544
+ timeStamp: /* @__PURE__ */ new Date(),
545
+ userId,
546
+ originalUserId: this.originalUserId ?? "",
547
+ type: "performance",
548
+ sessionId,
549
+ rrwebRecord: JSON.stringify(performanceEvent),
550
+ createAt: /* @__PURE__ */ new Date(),
551
+ updateAt: /* @__PURE__ */ new Date(),
552
+ hidden: false,
553
+ createdBy: userId,
554
+ updatedBy: userId,
555
+ hiddenBy: ""
556
+ };
557
+ setDoc2(newDocRef, record2).catch((error) => {
558
+ console.error("Error saving performance event: ", error);
559
+ });
560
+ }
561
+ });
562
+ observer.observe({ entryTypes: ["resource", "navigation", "paint"] });
563
+ }
564
+ } catch (error) {
565
+ console.error("\u30BF\u30A4\u30E0\u30E9\u30A4\u30F3\u9332\u753B\u30A8\u30E9\u30FC:", error);
566
+ throw error;
567
+ }
568
+ }
569
+ startRrwebRecordingForStore() {
570
+ try {
571
+ if (this.stopFnForStore) return;
572
+ const _sessionId = this.sessionId;
573
+ const userId = this.userId || "unknown";
574
+ const originalUserId = this.originalUserId || "";
575
+ const db2 = this.db;
576
+ const prefix = this.prefix;
577
+ if (!db2) {
578
+ console.error("Firestore\u304C\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
579
+ return;
580
+ }
581
+ const ActionRecordSessionRef = doc2(
582
+ collection2(db2, `${prefix}ActionRecordSession`),
583
+ _sessionId
584
+ );
585
+ setDoc2(ActionRecordSessionRef, {
586
+ id: _sessionId,
587
+ startTime: /* @__PURE__ */ new Date(),
588
+ endTime: null,
589
+ userId,
590
+ projectId: this.projectId || null,
591
+ organizationId: this.projectData?.organizationId || null,
592
+ createAt: /* @__PURE__ */ new Date(),
593
+ updateAt: /* @__PURE__ */ new Date(),
594
+ createdBy: userId,
595
+ updatedBy: userId
596
+ });
597
+ const _updateActionRecordSession = () => this.updateActionRecordSession();
598
+ this.stopFnForStore = record({
599
+ collectFonts: true,
600
+ inlineImages: true,
601
+ sampling: {
602
+ canvas: 50,
603
+ mousemove: true
604
+ },
605
+ emit(event) {
606
+ const newDocRef = doc2(collection2(db2, `${prefix}ActionRecord`));
607
+ const record2 = {
608
+ id: newDocRef.id,
609
+ timeStamp: /* @__PURE__ */ new Date(),
610
+ userId,
611
+ originalUserId,
612
+ type: "rrweb",
613
+ sessionId: _sessionId,
614
+ rrwebRecord: JSON.stringify(event),
615
+ createAt: /* @__PURE__ */ new Date(),
616
+ updateAt: /* @__PURE__ */ new Date(),
617
+ hidden: false,
618
+ createdBy: userId,
619
+ updatedBy: userId,
620
+ hiddenBy: ""
621
+ };
622
+ setDoc2(newDocRef, record2).catch((error) => {
623
+ console.error("Error saving rrweb event: ", error);
624
+ });
625
+ _updateActionRecordSession();
626
+ },
627
+ recordCanvas: false
628
+ });
629
+ } catch (error) {
630
+ console.error("rrweb\u9332\u753B\u30A8\u30E9\u30FC:", error);
631
+ throw error;
632
+ }
633
+ }
634
+ stopRrwebRecordingForStore() {
635
+ try {
636
+ if (this.stopFnForStore) {
637
+ this.stopFnForStore();
638
+ this.stopFnForStore = null;
639
+ }
640
+ } catch (error) {
641
+ console.error("rrweb\u9332\u753B\u505C\u6B62\u30A8\u30E9\u30FC:", error);
642
+ throw error;
643
+ }
644
+ }
645
+ updateActionRecordSession() {
646
+ try {
647
+ if (!this.db || !this.sessionId || !this.userId) {
648
+ console.error(
649
+ "Firestore\u304C\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3001\u307E\u305F\u306FsessionId\u3001userId\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093"
650
+ );
651
+ return;
652
+ }
653
+ const ActionRecordSessionRef = doc2(
654
+ collection2(this.db, `${this.prefix}ActionRecordSession`),
655
+ this.sessionId
656
+ );
657
+ setDoc2(
658
+ ActionRecordSessionRef,
659
+ {
660
+ endTime: /* @__PURE__ */ new Date(),
661
+ updateAt: /* @__PURE__ */ new Date(),
662
+ updatedBy: this.userId
663
+ },
664
+ { merge: true }
665
+ ).catch((error) => {
666
+ console.error("Error updating ActionRecordSession: ", error);
667
+ });
668
+ } catch (error) {
669
+ console.error("ActionRecordSession\u66F4\u65B0\u30A8\u30E9\u30FC:", error);
670
+ throw error;
671
+ }
672
+ }
673
+ };
674
+
675
+ // src/utils/date.ts
676
+ import { Timestamp } from "firebase/firestore";
677
+ function convertTimestampToDate(timestamp) {
678
+ if (!timestamp) return null;
679
+ if (typeof timestamp === "string") {
680
+ const _string = new Date(timestamp);
681
+ if (isNaN(_string.getTime())) {
682
+ return null;
683
+ }
684
+ return _string;
685
+ }
686
+ if ("_seconds" in timestamp && timestamp?._seconds) {
687
+ return new Date(Number(timestamp._seconds) * 1e3);
688
+ }
689
+ if (timestamp instanceof Timestamp) {
690
+ const _timestamp = timestamp.toDate();
691
+ return _timestamp;
692
+ }
693
+ if (timestamp instanceof Date) {
694
+ const _date = timestamp;
695
+ return _date;
696
+ }
697
+ return timestamp;
698
+ }
699
+ var dateFormat = (payload, format = "YYYY/MM/DD") => {
700
+ let date = payload;
701
+ if (!date) return "";
702
+ if (typeof date === "string") {
703
+ if (date.length === 8 && /^\d{8}$/.test(date)) {
704
+ const strYear = Number(date.slice(0, 4));
705
+ const strMonth = Number(date.slice(4, 6)) - 1;
706
+ const strDate = Number(date.slice(6, 8));
707
+ date = new Date(strYear, strMonth, strDate);
708
+ } else if (!/^(\d{4}).([0-1]\d).([0-3]\d).*$/.test(date)) {
709
+ return "error";
710
+ } else {
711
+ const strYear = Number(date.slice(0, 4));
712
+ const strMonth = Number(date.slice(5, 7)) - 1;
713
+ const strDate = Number(date.slice(8, 10));
714
+ date = new Date(strYear, strMonth, strDate);
715
+ }
716
+ }
717
+ if (typeof date === "number") {
718
+ date = new Date(date);
719
+ }
720
+ if (isTimestamp(date)) {
721
+ date = date.toDate();
722
+ }
723
+ if (date.hasOwnProperty("_seconds") && date.hasOwnProperty("_nanoseconds")) {
724
+ date = new Date(
725
+ // @ts-ignore
726
+ date._seconds * 1e3 + Math.floor(date._nanoseconds / 1e6)
727
+ );
728
+ }
729
+ date = new Date(date);
730
+ format = format.replace(/YYYY/g, date.getFullYear().toString());
731
+ format = format.replace(/MM/g, ("0" + (date.getMonth() + 1)).slice(-2));
732
+ format = format.replace(/DD/g, ("0" + date.getDate()).slice(-2));
733
+ format = format.replace(/hh/g, ("0" + date.getHours()).slice(-2));
734
+ format = format.replace(/mm/g, ("0" + date.getMinutes()).slice(-2));
735
+ format = format.replace(/ss/g, ("0" + date.getSeconds()).slice(-2));
736
+ format = format.replace(/SSS/g, ("00" + date.getMilliseconds()).slice(-3));
737
+ format = format.replace(
738
+ /aaa/g,
739
+ ["\u65E5", "\u6708", "\u706B", "\u6C34", "\u6728", "\u91D1", "\u571F"][date.getDay()]
740
+ );
741
+ return format;
742
+ };
743
+ var isTimestamp = (payload) => {
744
+ return payload.toDate !== void 0;
745
+ };
746
+ export {
747
+ ActionLensPlayer,
748
+ ActionLensRc,
749
+ convertTimestampToDate,
750
+ dateFormat
751
+ };
752
+ //# sourceMappingURL=index.mjs.map