action-lens 1.0.102 → 1.0.104

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.d.mts CHANGED
@@ -81,16 +81,24 @@ declare class ActionLensRc {
81
81
  email?: string;
82
82
  };
83
83
  metaData: Record<string, any>;
84
+ isRecordingPaused: boolean;
85
+ isSessionInitialized: boolean;
86
+ areAuxRecordersStarted: boolean;
87
+ recordingPauseDepth: number;
84
88
  constructor();
85
89
  init(projectId: string | null, _db?: Firestore | null, prefix?: string): Promise<void>;
86
90
  setUser(_userId: string | null, userMeta: {
87
91
  name: string;
88
92
  email: string;
89
93
  }, metaData?: Record<string, any>): Promise<void>;
94
+ private shouldRecordCustomEvents;
90
95
  startConsoleRecording(): void;
91
96
  startTimelineRecording(): void;
92
97
  startNetworkRecording(): void;
93
98
  startRrwebRecordingForStore(): Promise<void>;
99
+ withRecordingPaused<T>(fn: () => Promise<T> | T): Promise<T>;
100
+ pauseRrwebRecordingForStore(): void;
101
+ resumeRrwebRecordingForStore(): Promise<void>;
94
102
  stopRrwebRecordingForStore(): void;
95
103
  updateActionRecordSession(): Promise<void>;
96
104
  }
package/dist/index.d.ts CHANGED
@@ -81,16 +81,24 @@ declare class ActionLensRc {
81
81
  email?: string;
82
82
  };
83
83
  metaData: Record<string, any>;
84
+ isRecordingPaused: boolean;
85
+ isSessionInitialized: boolean;
86
+ areAuxRecordersStarted: boolean;
87
+ recordingPauseDepth: number;
84
88
  constructor();
85
89
  init(projectId: string | null, _db?: Firestore | null, prefix?: string): Promise<void>;
86
90
  setUser(_userId: string | null, userMeta: {
87
91
  name: string;
88
92
  email: string;
89
93
  }, metaData?: Record<string, any>): Promise<void>;
94
+ private shouldRecordCustomEvents;
90
95
  startConsoleRecording(): void;
91
96
  startTimelineRecording(): void;
92
97
  startNetworkRecording(): void;
93
98
  startRrwebRecordingForStore(): Promise<void>;
99
+ withRecordingPaused<T>(fn: () => Promise<T> | T): Promise<T>;
100
+ pauseRrwebRecordingForStore(): void;
101
+ resumeRrwebRecordingForStore(): Promise<void>;
94
102
  stopRrwebRecordingForStore(): void;
95
103
  updateActionRecordSession(): Promise<void>;
96
104
  }
package/dist/index.js CHANGED
@@ -376,6 +376,10 @@ var ActionLensRc = class {
376
376
  // 元のユーザーID(外部システムのIDなど)
377
377
  userMeta = {};
378
378
  metaData = {};
379
+ isRecordingPaused = false;
380
+ isSessionInitialized = false;
381
+ areAuxRecordersStarted = false;
382
+ recordingPauseDepth = 0;
379
383
  constructor() {
380
384
  this.db = db;
381
385
  }
@@ -549,6 +553,9 @@ var ActionLensRc = class {
549
553
  );
550
554
  return;
551
555
  }
556
+ shouldRecordCustomEvents() {
557
+ return !this.isRecordingPaused && !!this.stopFnForStore;
558
+ }
552
559
  // コンソールログをキャプチャ
553
560
  startConsoleRecording() {
554
561
  try {
@@ -565,6 +572,7 @@ var ActionLensRc = class {
565
572
  consoleMethods.forEach((method) => {
566
573
  console[method] = (...args) => {
567
574
  originalConsole[method](...args);
575
+ if (!this.shouldRecordCustomEvents()) return;
568
576
  const fileName = new Error().stack?.split("\n")[2]?.trim() || "unknown";
569
577
  import_rrweb2.record.addCustomEvent("console", { method, args, fileName });
570
578
  };
@@ -586,6 +594,7 @@ var ActionLensRc = class {
586
594
  console.error("Firestore\u304C\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
587
595
  return;
588
596
  }
597
+ if (!this.shouldRecordCustomEvents()) return;
589
598
  import_rrweb2.record.addCustomEvent("navigation", {
590
599
  url: window.location.href,
591
600
  state: event.state
@@ -593,6 +602,7 @@ var ActionLensRc = class {
593
602
  });
594
603
  if (window.performance) {
595
604
  const observer = new PerformanceObserver((list) => {
605
+ if (!this.shouldRecordCustomEvents()) return;
596
606
  for (const entry of list.getEntries()) {
597
607
  if (entry.entryType === "resource") {
598
608
  const resourceEntry = entry;
@@ -645,6 +655,7 @@ var ActionLensRc = class {
645
655
  // ネットワークリクエストをキャプチャ(新規追加)
646
656
  startNetworkRecording() {
647
657
  try {
658
+ const shouldRecordCustomEvents = () => this.shouldRecordCustomEvents();
648
659
  const shouldIgnoreNetwork = (url) => {
649
660
  try {
650
661
  const parsed = new URL(url, window.location.href);
@@ -673,7 +684,7 @@ var ActionLensRc = class {
673
684
  method = init?.method || "GET";
674
685
  requestBody = init?.body;
675
686
  }
676
- if (shouldIgnoreNetwork(urlStr)) {
687
+ if (shouldIgnoreNetwork(urlStr) || !shouldRecordCustomEvents()) {
677
688
  return originalFetch(...args);
678
689
  }
679
690
  import_rrweb2.record.addCustomEvent("network_request", {
@@ -686,6 +697,9 @@ var ActionLensRc = class {
686
697
  // 初期状態は保留中
687
698
  });
688
699
  return originalFetch(...args).then((response) => {
700
+ if (!shouldRecordCustomEvents()) {
701
+ return response;
702
+ }
689
703
  const endTime = Date.now();
690
704
  const duration = endTime - startTime;
691
705
  const clonedResponse = response.clone();
@@ -707,6 +721,9 @@ var ActionLensRc = class {
707
721
  });
708
722
  return response;
709
723
  }).catch((error) => {
724
+ if (!shouldRecordCustomEvents()) {
725
+ throw error;
726
+ }
710
727
  const endTime = Date.now();
711
728
  const duration = endTime - startTime;
712
729
  import_rrweb2.record.addCustomEvent("network_error", {
@@ -734,7 +751,7 @@ var ActionLensRc = class {
734
751
  this._method = method;
735
752
  this._url = url.toString();
736
753
  this._startTime = Date.now();
737
- this._skipRecord = shouldIgnoreNetwork(this._url);
754
+ this._skipRecord = shouldIgnoreNetwork(this._url) || !shouldRecordCustomEvents();
738
755
  if (!this._skipRecord) {
739
756
  import_rrweb2.record.addCustomEvent("network_request", {
740
757
  type: "xhr",
@@ -752,6 +769,7 @@ var ActionLensRc = class {
752
769
  return super.send(body);
753
770
  }
754
771
  this.addEventListener("load", () => {
772
+ if (!shouldRecordCustomEvents()) return;
755
773
  const endTime = Date.now();
756
774
  const duration = endTime - (this._startTime || 0);
757
775
  import_rrweb2.record.addCustomEvent("network_response", {
@@ -765,6 +783,7 @@ var ActionLensRc = class {
765
783
  });
766
784
  });
767
785
  this.addEventListener("error", () => {
786
+ if (!shouldRecordCustomEvents()) return;
768
787
  const endTime = Date.now();
769
788
  const duration = endTime - (this._startTime || 0);
770
789
  import_rrweb2.record.addCustomEvent("network_error", {
@@ -786,48 +805,53 @@ var ActionLensRc = class {
786
805
  super(url, protocols);
787
806
  const wsUrl = url.toString();
788
807
  this._skipRecord = shouldIgnoreNetwork(wsUrl);
789
- if (!this._skipRecord) {
808
+ if (this._skipRecord) return;
809
+ if (shouldRecordCustomEvents()) {
790
810
  import_rrweb2.record.addCustomEvent("network_websocket_open", {
791
811
  type: "websocket",
792
812
  url: wsUrl,
793
813
  startTime: Date.now()
794
814
  });
795
- this.addEventListener("message", (event) => {
796
- import_rrweb2.record.addCustomEvent("network_websocket_message", {
797
- type: "websocket",
798
- url: wsUrl,
799
- data: event.data,
800
- time: Date.now()
801
- });
802
- });
803
- this.addEventListener("close", (event) => {
804
- import_rrweb2.record.addCustomEvent("network_websocket_close", {
805
- type: "websocket",
806
- url: wsUrl,
807
- code: event.code,
808
- reason: event.reason,
809
- endTime: Date.now()
810
- });
815
+ }
816
+ this.addEventListener("message", (event) => {
817
+ if (!shouldRecordCustomEvents()) return;
818
+ import_rrweb2.record.addCustomEvent("network_websocket_message", {
819
+ type: "websocket",
820
+ url: wsUrl,
821
+ data: event.data,
822
+ time: Date.now()
811
823
  });
812
- this.addEventListener("error", (event) => {
813
- import_rrweb2.record.addCustomEvent("network_websocket_error", {
814
- type: "websocket",
815
- url: wsUrl,
816
- error: "WebSocket error",
817
- time: Date.now()
818
- });
824
+ });
825
+ this.addEventListener("close", (event) => {
826
+ if (!shouldRecordCustomEvents()) return;
827
+ import_rrweb2.record.addCustomEvent("network_websocket_close", {
828
+ type: "websocket",
829
+ url: wsUrl,
830
+ code: event.code,
831
+ reason: event.reason,
832
+ endTime: Date.now()
819
833
  });
820
- }
821
- }
822
- send(data) {
823
- if (!this._skipRecord) {
824
- import_rrweb2.record.addCustomEvent("network_websocket_send", {
834
+ });
835
+ this.addEventListener("error", (event) => {
836
+ if (!shouldRecordCustomEvents()) return;
837
+ import_rrweb2.record.addCustomEvent("network_websocket_error", {
825
838
  type: "websocket",
826
- url: this.url,
827
- data,
839
+ url: wsUrl,
840
+ error: "WebSocket error",
828
841
  time: Date.now()
829
842
  });
843
+ });
844
+ }
845
+ send(data) {
846
+ if (this._skipRecord || !shouldRecordCustomEvents()) {
847
+ return super.send(data);
830
848
  }
849
+ import_rrweb2.record.addCustomEvent("network_websocket_send", {
850
+ type: "websocket",
851
+ url: this.url,
852
+ data,
853
+ time: Date.now()
854
+ });
831
855
  return super.send(data);
832
856
  }
833
857
  };
@@ -850,44 +874,47 @@ var ActionLensRc = class {
850
874
  console.error("Firestore\u304C\u521D\u671F\u5316\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
851
875
  return;
852
876
  }
853
- const ActionRecordSessionRef = (0, import_firestore3.doc)(
854
- (0, import_firestore3.collection)(this.db, `${prefix}ActionRecordSession`),
855
- _sessionId
856
- );
857
- await (0, import_firestore3.setDoc)(ActionRecordSessionRef, {
858
- id: _sessionId,
859
- startTime: /* @__PURE__ */ new Date(),
860
- endTime: /* @__PURE__ */ new Date(),
861
- recordTime: 0,
862
- // 初期値は0
863
- userId,
864
- projectId: this.projectId || "",
865
- organizationId: this.projectData?.organizationId || "",
866
- createAt: /* @__PURE__ */ new Date(),
867
- updateAt: /* @__PURE__ */ new Date(),
868
- createdBy: userId,
869
- updatedBy: userId
870
- });
871
- try {
872
- console.log("setSessionDetail\u95A2\u6570\u3092\u547C\u3073\u51FA\u3057\u307E\u3059", this.sessionId);
873
- await setSessionDetail({ sessionId: this.sessionId });
874
- } catch (error) {
875
- console.error("setSessionDetail\u95A2\u6570\u306E\u547C\u3073\u51FA\u3057\u306B\u5931\u6557:", error);
876
- }
877
- const docRef = (0, import_firestore3.doc)(
878
- (0, import_firestore3.collection)(this.db, "ActionRecordSession"),
879
- this.sessionId
880
- );
881
- await (0, import_firestore3.getDoc)(docRef).then(async (doc3) => {
882
- if (doc3.exists()) {
883
- const data = doc3.data();
884
- const ipAddress = data?.ipAddress || "";
885
- const placeData = await getPlaceFromIp(ipAddress);
886
- await (0, import_firestore3.updateDoc)(docRef, { place: placeData });
877
+ if (!this.isSessionInitialized) {
878
+ const ActionRecordSessionRef = (0, import_firestore3.doc)(
879
+ (0, import_firestore3.collection)(this.db, `${prefix}ActionRecordSession`),
880
+ _sessionId
881
+ );
882
+ await (0, import_firestore3.setDoc)(ActionRecordSessionRef, {
883
+ id: _sessionId,
884
+ startTime: /* @__PURE__ */ new Date(),
885
+ endTime: /* @__PURE__ */ new Date(),
886
+ recordTime: 0,
887
+ // 初期値は0
888
+ userId,
889
+ projectId: this.projectId || "",
890
+ organizationId: this.projectData?.organizationId || "",
891
+ createAt: /* @__PURE__ */ new Date(),
892
+ updateAt: /* @__PURE__ */ new Date(),
893
+ createdBy: userId,
894
+ updatedBy: userId
895
+ });
896
+ this.isSessionInitialized = true;
897
+ try {
898
+ console.log("setSessionDetail\u95A2\u6570\u3092\u547C\u3073\u51FA\u3057\u307E\u3059", this.sessionId);
899
+ await setSessionDetail({ sessionId: this.sessionId });
900
+ } catch (error) {
901
+ console.error("setSessionDetail\u95A2\u6570\u306E\u547C\u3073\u51FA\u3057\u306B\u5931\u6557:", error);
887
902
  }
888
- }).catch((error) => {
889
- console.error("IP\u30A2\u30C9\u30EC\u30B9\u306E\u53D6\u5F97\u306B\u5931\u6557:", error);
890
- });
903
+ const docRef = (0, import_firestore3.doc)(
904
+ (0, import_firestore3.collection)(this.db, "ActionRecordSession"),
905
+ this.sessionId
906
+ );
907
+ await (0, import_firestore3.getDoc)(docRef).then(async (doc3) => {
908
+ if (doc3.exists()) {
909
+ const data = doc3.data();
910
+ const ipAddress = data?.ipAddress || "";
911
+ const placeData = await getPlaceFromIp(ipAddress);
912
+ await (0, import_firestore3.updateDoc)(docRef, { place: placeData });
913
+ }
914
+ }).catch((error) => {
915
+ console.error("IP\u30A2\u30C9\u30EC\u30B9\u306E\u53D6\u5F97\u306B\u5931\u6557:", error);
916
+ });
917
+ }
891
918
  this.stopFnForStore = (0, import_rrweb2.record)({
892
919
  packFn: import_packer2.pack,
893
920
  collectFonts: false,
@@ -937,20 +964,65 @@ var ActionLensRc = class {
937
964
  },
938
965
  recordCanvas: false
939
966
  });
940
- this.startConsoleRecording();
941
- this.startTimelineRecording();
942
- this.startNetworkRecording();
967
+ this.isRecordingPaused = false;
968
+ if (!this.areAuxRecordersStarted) {
969
+ this.startConsoleRecording();
970
+ this.startTimelineRecording();
971
+ this.startNetworkRecording();
972
+ this.areAuxRecordersStarted = true;
973
+ }
943
974
  } catch (error) {
944
975
  console.error("rrweb\u9332\u753B\u30A8\u30E9\u30FC:", error);
945
976
  throw error;
946
977
  }
947
978
  }
979
+ async withRecordingPaused(fn) {
980
+ if (!this.stopFnForStore) {
981
+ return await fn();
982
+ }
983
+ const shouldPause = !this.isRecordingPaused && this.recordingPauseDepth === 0;
984
+ this.recordingPauseDepth += 1;
985
+ if (shouldPause) {
986
+ this.pauseRrwebRecordingForStore();
987
+ }
988
+ try {
989
+ return await fn();
990
+ } finally {
991
+ this.recordingPauseDepth = Math.max(0, this.recordingPauseDepth - 1);
992
+ if (shouldPause && this.recordingPauseDepth === 0) {
993
+ await this.resumeRrwebRecordingForStore();
994
+ }
995
+ }
996
+ }
997
+ pauseRrwebRecordingForStore() {
998
+ try {
999
+ this.isRecordingPaused = true;
1000
+ if (this.stopFnForStore) {
1001
+ this.stopFnForStore();
1002
+ this.stopFnForStore = null;
1003
+ }
1004
+ } catch (error) {
1005
+ console.error("rrweb\u9332\u753B\u4E00\u6642\u505C\u6B62\u30A8\u30E9\u30FC:", error);
1006
+ throw error;
1007
+ }
1008
+ }
1009
+ async resumeRrwebRecordingForStore() {
1010
+ try {
1011
+ if (this.stopFnForStore) return;
1012
+ this.isRecordingPaused = false;
1013
+ await this.startRrwebRecordingForStore();
1014
+ } catch (error) {
1015
+ console.error("rrweb\u9332\u753B\u518D\u958B\u30A8\u30E9\u30FC:", error);
1016
+ throw error;
1017
+ }
1018
+ }
948
1019
  stopRrwebRecordingForStore() {
949
1020
  try {
950
1021
  if (this.stopFnForStore) {
951
1022
  this.stopFnForStore();
952
1023
  this.stopFnForStore = null;
953
1024
  }
1025
+ this.isRecordingPaused = false;
954
1026
  } catch (error) {
955
1027
  console.error("rrweb\u9332\u753B\u505C\u6B62\u30A8\u30E9\u30FC:", error);
956
1028
  throw error;