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