action-lens 1.0.102 → 1.0.103

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