@hexclave/next 1.0.20 → 1.0.22
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/README.md +187 -7
- package/dist/components/elements/sidebar-layout.js +1 -1
- package/dist/components-page/oauth-callback.js +14 -19
- package/dist/components-page/oauth-callback.js.map +1 -1
- package/dist/components-page/oauth-callback.test.d.ts +1 -0
- package/dist/components-page/oauth-callback.test.js +90 -0
- package/dist/components-page/oauth-callback.test.js.map +1 -0
- package/dist/esm/components/elements/sidebar-layout.js +1 -1
- package/dist/esm/components-page/oauth-callback.js +14 -19
- package/dist/esm/components-page/oauth-callback.js.map +1 -1
- package/dist/esm/components-page/oauth-callback.test.d.ts +1 -0
- package/dist/esm/components-page/oauth-callback.test.js +89 -0
- package/dist/esm/components-page/oauth-callback.test.js.map +1 -0
- package/dist/esm/generated/quetzal-translations.d.ts +2 -2
- package/dist/esm/lib/auth.d.ts.map +1 -1
- package/dist/esm/lib/auth.js +32 -11
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/auth.test.js +25 -10
- package/dist/esm/lib/auth.test.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +1 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.js +1 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +54 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +4 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js +28 -4
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/common.js +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/event-tracker.d.ts +1 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/event-tracker.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/event-tracker.js +17 -13
- package/dist/esm/lib/hexclave-app/apps/implementations/event-tracker.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/event-tracker.test.js +4 -8
- package/dist/esm/lib/hexclave-app/apps/implementations/event-tracker.test.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.d.ts +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.d.ts +3 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.js +19 -13
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.test.js +4 -9
- package/dist/esm/lib/hexclave-app/apps/implementations/session-replay.test.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/interfaces/admin-app.d.ts +1 -0
- package/dist/esm/lib/hexclave-app/apps/interfaces/admin-app.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/generated/quetzal-translations.d.ts +2 -2
- package/dist/lib/auth.d.ts.map +1 -1
- package/dist/lib/auth.js +31 -10
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/auth.test.js +23 -8
- package/dist/lib/auth.test.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +1 -0
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.js +1 -0
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +54 -0
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +4 -1
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.d.ts.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js +27 -3
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/common.js +1 -1
- package/dist/lib/hexclave-app/apps/implementations/event-tracker.d.ts +1 -0
- package/dist/lib/hexclave-app/apps/implementations/event-tracker.d.ts.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/event-tracker.js +16 -12
- package/dist/lib/hexclave-app/apps/implementations/event-tracker.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/event-tracker.test.js +4 -8
- package/dist/lib/hexclave-app/apps/implementations/event-tracker.test.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/server-app-impl.d.ts +1 -1
- package/dist/lib/hexclave-app/apps/implementations/session-replay.d.ts +3 -1
- package/dist/lib/hexclave-app/apps/implementations/session-replay.d.ts.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/session-replay.js +19 -12
- package/dist/lib/hexclave-app/apps/implementations/session-replay.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/session-replay.test.js +4 -9
- package/dist/lib/hexclave-app/apps/implementations/session-replay.test.js.map +1 -1
- package/dist/lib/hexclave-app/apps/interfaces/admin-app.d.ts +1 -0
- package/dist/lib/hexclave-app/apps/interfaces/admin-app.d.ts.map +1 -1
- package/dist/lib/hexclave-app/apps/interfaces/admin-app.js.map +1 -1
- package/package.json +4 -4
- package/src/components-page/oauth-callback.test.tsx +109 -0
- package/src/components-page/oauth-callback.tsx +14 -19
- package/src/lib/auth.test.ts +32 -10
- package/src/lib/auth.ts +41 -7
- package/src/lib/hexclave-app/apps/implementations/admin-app-impl.ts +2 -1
- package/src/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.ts +66 -0
- package/src/lib/hexclave-app/apps/implementations/client-app-impl.ts +39 -3
- package/src/lib/hexclave-app/apps/implementations/event-tracker.test.ts +5 -13
- package/src/lib/hexclave-app/apps/implementations/event-tracker.ts +19 -14
- package/src/lib/hexclave-app/apps/implementations/session-replay.test.ts +4 -20
- package/src/lib/hexclave-app/apps/implementations/session-replay.ts +19 -12
- package/src/lib/hexclave-app/apps/interfaces/admin-app.ts +1 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template
|
|
4
4
|
//===========================================
|
|
5
5
|
import { WebAuthnError, startAuthentication, startRegistration } from "@simplewebauthn/browser";
|
|
6
|
-
import { KnownErrors, HexclaveClientInterface } from "@hexclave/shared";
|
|
6
|
+
import { KnownError, KnownErrors, HexclaveClientInterface } from "@hexclave/shared";
|
|
7
7
|
import type { RequestListener } from "@hexclave/shared/dist/interface/client-interface";
|
|
8
8
|
import { ContactChannelsCrud } from "@hexclave/shared/dist/interface/crud/contact-channels";
|
|
9
9
|
import { CurrentUserCrud } from "@hexclave/shared/dist/interface/crud/current-user";
|
|
@@ -714,11 +714,11 @@ export class _HexclaveClientAppImplIncomplete<HasTokenStore extends boolean, Pro
|
|
|
714
714
|
if (
|
|
715
715
|
isBrowserLike()
|
|
716
716
|
&& (this._isOAuthCallbackUrlHosted() || this._currentUrlLooksLikeNestedCrossDomainOAuthCallback())
|
|
717
|
-
&& this._currentUrlLooksLikeHexclaveOAuthCallback()
|
|
717
|
+
&& (this._currentUrlLooksLikeHexclaveOAuthCallback() || this._currentUrlLooksLikeOAuthCallbackError())
|
|
718
718
|
) {
|
|
719
719
|
this._trackPendingAuthResolution(async () => {
|
|
720
720
|
if (isBrowserLike()) {
|
|
721
|
-
await this.
|
|
721
|
+
await this._handleHostedOAuthCallbackDuringStartup();
|
|
722
722
|
}
|
|
723
723
|
});
|
|
724
724
|
}
|
|
@@ -818,6 +818,22 @@ export class _HexclaveClientAppImplIncomplete<HasTokenStore extends boolean, Pro
|
|
|
818
818
|
currentUrl.searchParams.has("code") && currentUrl.searchParams.has("state")
|
|
819
819
|
) || (
|
|
820
820
|
currentUrl.searchParams.has("errorCode") && currentUrl.searchParams.has("message")
|
|
821
|
+
) || (
|
|
822
|
+
this._currentUrlLooksLikeOAuthCallbackError()
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
protected _currentUrlLooksLikeOAuthCallbackError(): boolean {
|
|
827
|
+
if (typeof window === "undefined") {
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
830
|
+
const currentUrl = new URL(window.location.href);
|
|
831
|
+
if (currentUrl.searchParams.has("errorCode") && currentUrl.searchParams.has("message")) {
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
834
|
+
return (
|
|
835
|
+
(currentUrl.searchParams.has("error") || currentUrl.searchParams.has("error_description"))
|
|
836
|
+
&& !(currentUrl.searchParams.has("code") && currentUrl.searchParams.has("state"))
|
|
821
837
|
);
|
|
822
838
|
}
|
|
823
839
|
|
|
@@ -859,6 +875,26 @@ export class _HexclaveClientAppImplIncomplete<HasTokenStore extends boolean, Pro
|
|
|
859
875
|
return currentUrl.toString();
|
|
860
876
|
}
|
|
861
877
|
|
|
878
|
+
protected async _redirectToOAuthCallbackError(error: KnownError): Promise<void> {
|
|
879
|
+
const errorUrl = new URL(this._getUrls().error, window.location.href);
|
|
880
|
+
errorUrl.searchParams.set("errorCode", error.errorCode);
|
|
881
|
+
errorUrl.searchParams.set("message", error.message);
|
|
882
|
+
errorUrl.searchParams.set("details", JSON.stringify(error.details ?? {}));
|
|
883
|
+
await this._redirectIfTrusted(errorUrl.toString(), { replace: true });
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
protected async _handleHostedOAuthCallbackDuringStartup(): Promise<void> {
|
|
887
|
+
try {
|
|
888
|
+
await this.callOAuthCallback({ dontWarnAboutMissingQueryParams: true });
|
|
889
|
+
} catch (error) {
|
|
890
|
+
if (KnownError.isKnownError(error)) {
|
|
891
|
+
await this._redirectToOAuthCallbackError(error);
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
throw error;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
862
898
|
protected async _fetchCurrentRefreshTokenIdIfSignedIn(options?: {
|
|
863
899
|
awaitPendingAuthResolutions?: boolean,
|
|
864
900
|
overrideTokenStoreInit?: TokenStoreInit,
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
//===========================================
|
|
5
5
|
// @vitest-environment jsdom
|
|
6
6
|
|
|
7
|
+
import { KnownErrors } from "@hexclave/shared/dist/known-errors";
|
|
7
8
|
import { Result } from "@hexclave/shared/dist/utils/results";
|
|
8
9
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
9
10
|
import { EventTracker } from "./event-tracker";
|
|
@@ -390,7 +391,7 @@ describe("EventTracker", () => {
|
|
|
390
391
|
}
|
|
391
392
|
});
|
|
392
393
|
|
|
393
|
-
it("silently disables when
|
|
394
|
+
it("silently disables when client interface returns ANALYTICS_NOT_ENABLED as an error", async () => {
|
|
394
395
|
vi.useFakeTimers();
|
|
395
396
|
document.body.innerHTML = "<button>Click me</button>";
|
|
396
397
|
|
|
@@ -400,28 +401,19 @@ describe("EventTracker", () => {
|
|
|
400
401
|
projectId: "internal",
|
|
401
402
|
sendBatch: async (body) => {
|
|
402
403
|
sentBodies.push(body);
|
|
403
|
-
return Result.
|
|
404
|
-
JSON.stringify({ code: "ANALYTICS_NOT_ENABLED", error: "Analytics is not enabled for this project." }),
|
|
405
|
-
{
|
|
406
|
-
status: 400,
|
|
407
|
-
headers: { "x-stack-known-error": "ANALYTICS_NOT_ENABLED" },
|
|
408
|
-
},
|
|
409
|
-
));
|
|
404
|
+
return Result.error(new KnownErrors.AnalyticsNotEnabled());
|
|
410
405
|
},
|
|
411
406
|
});
|
|
412
407
|
|
|
413
408
|
try {
|
|
414
409
|
tracker.start();
|
|
415
410
|
|
|
416
|
-
// First flush sends the initial page-view event; server rejects it.
|
|
417
411
|
await advancePastFlush();
|
|
418
412
|
expect(sentBodies).toHaveLength(1);
|
|
419
|
-
|
|
420
|
-
// No console.warn should have been emitted.
|
|
421
413
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
414
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
415
|
+
expect((tracker as any)._flushTimer).toBeNull();
|
|
422
416
|
|
|
423
|
-
// After disabling, new events should not accumulate or trigger further
|
|
424
|
-
// flushes.
|
|
425
417
|
document.querySelector("button")?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
426
418
|
await advancePastFlush();
|
|
427
419
|
expect(sentBodies).toHaveLength(1);
|
|
@@ -8,7 +8,7 @@ import { cssEscapeIdent } from "@hexclave/shared/dist/utils/dom";
|
|
|
8
8
|
import { buildElementsChain, ELEMENTS_CHAIN_MAX_DEPTH } from "@hexclave/shared/dist/utils/elements-chain";
|
|
9
9
|
import { runAsynchronously } from "@hexclave/shared/dist/utils/promises";
|
|
10
10
|
import { Result } from "@hexclave/shared/dist/utils/results";
|
|
11
|
-
import { generateUuid } from "./session-replay";
|
|
11
|
+
import { generateUuid, isAnalyticsNotEnabledError } from "./session-replay";
|
|
12
12
|
|
|
13
13
|
const FLUSH_INTERVAL_MS = 10_000;
|
|
14
14
|
const MAX_EVENTS_PER_BATCH = 50;
|
|
@@ -34,6 +34,10 @@ function hasHistoryMethods(value: unknown): value is { pushState: History["pushS
|
|
|
34
34
|
return typeof value.pushState === "function" && typeof value.replaceState === "function";
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
function getTextSnippet(textContent: string | null): string {
|
|
38
|
+
return textContent == null ? "" : textContent.trim().substring(0, 200);
|
|
39
|
+
}
|
|
40
|
+
|
|
37
41
|
// Pixel quantization factor for x/y/viewport in stored click events. Matches the
|
|
38
42
|
// SCALE_FACTOR used by the ClickHouse clickmap_events MV — keep them in sync.
|
|
39
43
|
const CLICKMAP_SCALE_FACTOR = 16;
|
|
@@ -321,7 +325,7 @@ export class EventTracker {
|
|
|
321
325
|
event_at_ms: Date.now(),
|
|
322
326
|
data: {
|
|
323
327
|
tag_name: target.tagName.toLowerCase(),
|
|
324
|
-
text: target.textContent
|
|
328
|
+
text: getTextSnippet(target.textContent),
|
|
325
329
|
href: this._findNearestAnchorHref(target),
|
|
326
330
|
selector: this._buildSelector(target),
|
|
327
331
|
elements_chain: buildElementsChain(target),
|
|
@@ -503,27 +507,28 @@ export class EventTracker {
|
|
|
503
507
|
);
|
|
504
508
|
|
|
505
509
|
if (res.status === "error") {
|
|
510
|
+
if (isAnalyticsNotEnabledError(res.error)) {
|
|
511
|
+
this._disable();
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
506
514
|
console.warn("EventTracker flush failed:", res.error);
|
|
507
515
|
return;
|
|
508
516
|
}
|
|
509
517
|
|
|
510
518
|
if (!res.data.ok) {
|
|
511
|
-
// If the server tells us analytics is not enabled for this project,
|
|
512
|
-
// silently disable the tracker — no point retrying or warning the user.
|
|
513
|
-
const knownError = res.data.headers.get("x-hexclave-known-error") ?? res.data.headers.get("x-stack-known-error");
|
|
514
|
-
if (knownError === "ANALYTICS_NOT_ENABLED") {
|
|
515
|
-
this._disabled = true;
|
|
516
|
-
if (this._flushTimer !== null) {
|
|
517
|
-
clearInterval(this._flushTimer);
|
|
518
|
-
this._flushTimer = null;
|
|
519
|
-
}
|
|
520
|
-
this._teardown();
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
519
|
console.warn("EventTracker flush failed:", res.data.status, await res.data.text());
|
|
524
520
|
}
|
|
525
521
|
}
|
|
526
522
|
|
|
523
|
+
private _disable() {
|
|
524
|
+
this._disabled = true;
|
|
525
|
+
if (this._flushTimer !== null) {
|
|
526
|
+
clearInterval(this._flushTimer);
|
|
527
|
+
this._flushTimer = null;
|
|
528
|
+
}
|
|
529
|
+
this._teardown();
|
|
530
|
+
}
|
|
531
|
+
|
|
527
532
|
private _tick() {
|
|
528
533
|
if (this._cancelled) return;
|
|
529
534
|
if (this._events.length > 0) {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
//===========================================
|
|
5
5
|
// @vitest-environment jsdom
|
|
6
6
|
|
|
7
|
+
import { KnownErrors } from "@hexclave/shared/dist/known-errors";
|
|
7
8
|
import { describe, expect, it, vi } from "vitest";
|
|
8
9
|
import { Result } from "@hexclave/shared/dist/utils/results";
|
|
9
10
|
import { analyticsOptionsFromJson, analyticsOptionsToJson, getSessionReplayOptions, SessionRecorder } from "./session-replay";
|
|
@@ -48,10 +49,9 @@ describe("analytics option JSON conversion", () => {
|
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
describe("SessionRecorder flush", () => {
|
|
51
|
-
it("silently disables when
|
|
52
|
+
it("silently disables when client interface returns ANALYTICS_NOT_ENABLED as an error", async () => {
|
|
52
53
|
vi.useFakeTimers();
|
|
53
54
|
|
|
54
|
-
// Seed localStorage with a valid session so _flush doesn't fail on getOrRotateSession
|
|
55
55
|
const storageKey = `hexclave:session-replay:v1:test-project`;
|
|
56
56
|
localStorage.setItem(storageKey, JSON.stringify({
|
|
57
57
|
session_id: "test-session",
|
|
@@ -65,13 +65,7 @@ describe("SessionRecorder flush", () => {
|
|
|
65
65
|
projectId: "test-project",
|
|
66
66
|
sendBatch: async (body) => {
|
|
67
67
|
sentBodies.push(body);
|
|
68
|
-
return Result.
|
|
69
|
-
JSON.stringify({ code: "ANALYTICS_NOT_ENABLED", error: "Analytics is not enabled for this project." }),
|
|
70
|
-
{
|
|
71
|
-
status: 400,
|
|
72
|
-
headers: { "x-stack-known-error": "ANALYTICS_NOT_ENABLED" },
|
|
73
|
-
},
|
|
74
|
-
));
|
|
68
|
+
return Result.error(new KnownErrors.AnalyticsNotEnabled());
|
|
75
69
|
},
|
|
76
70
|
},
|
|
77
71
|
{},
|
|
@@ -80,26 +74,16 @@ describe("SessionRecorder flush", () => {
|
|
|
80
74
|
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
81
75
|
|
|
82
76
|
try {
|
|
83
|
-
// Inject an event directly into the recorder's buffer to test flush behavior
|
|
84
|
-
// without needing rrweb. We access private fields for testing purposes.
|
|
85
77
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
86
78
|
(recorder as any)._events = [{ type: 2, timestamp: Date.now(), data: {} }];
|
|
87
79
|
|
|
88
|
-
// Manually trigger a tick (which calls _flush)
|
|
89
80
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
90
81
|
(recorder as any)._tick();
|
|
91
82
|
await vi.advanceTimersByTimeAsync(0);
|
|
92
83
|
|
|
93
|
-
// One batch should have been sent
|
|
94
84
|
expect(sentBodies).toHaveLength(1);
|
|
85
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
95
86
|
|
|
96
|
-
// No console.warn about "SessionRecorder flush failed" should have been emitted
|
|
97
|
-
const flushWarnings = warnSpy.mock.calls.filter(
|
|
98
|
-
(args) => typeof args[0] === "string" && args[0].includes("SessionRecorder")
|
|
99
|
-
);
|
|
100
|
-
expect(flushWarnings).toHaveLength(0);
|
|
101
|
-
|
|
102
|
-
// After disabling, pushing new events and triggering another tick should not send
|
|
103
87
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
104
88
|
(recorder as any)._events = [{ type: 3, timestamp: Date.now(), data: {} }];
|
|
105
89
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
//===========================================
|
|
3
3
|
// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template
|
|
4
4
|
//===========================================
|
|
5
|
+
import { KnownErrors } from "@hexclave/shared/dist/known-errors";
|
|
5
6
|
import { isBrowserLike } from "@hexclave/shared/dist/utils/env";
|
|
6
7
|
import { captureWarning } from "@hexclave/shared/dist/utils/errors";
|
|
7
8
|
import { runAsynchronously } from "@hexclave/shared/dist/utils/promises";
|
|
@@ -165,6 +166,10 @@ export type SessionRecorderDeps = {
|
|
|
165
166
|
sendBatch: (body: string, options: { keepalive: boolean }) => Promise<Result<Response, Error>>,
|
|
166
167
|
};
|
|
167
168
|
|
|
169
|
+
export function isAnalyticsNotEnabledError(error: unknown): boolean {
|
|
170
|
+
return KnownErrors.AnalyticsNotEnabled.isInstance(error);
|
|
171
|
+
}
|
|
172
|
+
|
|
168
173
|
export class SessionRecorder {
|
|
169
174
|
private _started = false;
|
|
170
175
|
private _cancelled = false;
|
|
@@ -269,23 +274,15 @@ export class SessionRecorder {
|
|
|
269
274
|
);
|
|
270
275
|
|
|
271
276
|
if (res.status === "error") {
|
|
277
|
+
if (isAnalyticsNotEnabledError(res.error)) {
|
|
278
|
+
this._disable();
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
272
281
|
captureWarning("SessionRecorder.flush", res.error);
|
|
273
282
|
return;
|
|
274
283
|
}
|
|
275
284
|
|
|
276
285
|
if (!res.data.ok) {
|
|
277
|
-
// If the server tells us analytics is not enabled for this project,
|
|
278
|
-
// silently disable the recorder — no point retrying or warning the user.
|
|
279
|
-
const knownError = res.data.headers.get("x-hexclave-known-error") ?? res.data.headers.get("x-stack-known-error");
|
|
280
|
-
if (knownError === "ANALYTICS_NOT_ENABLED") {
|
|
281
|
-
this._disabled = true;
|
|
282
|
-
if (this._flushTimer !== null) {
|
|
283
|
-
clearInterval(this._flushTimer);
|
|
284
|
-
this._flushTimer = null;
|
|
285
|
-
}
|
|
286
|
-
this._stopCurrentRecording();
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
286
|
captureWarning("SessionRecorder.flush", new Error(`SessionRecorder flush failed: ${res.data.status} ${await res.data.text()}`));
|
|
290
287
|
}
|
|
291
288
|
} finally {
|
|
@@ -293,6 +290,16 @@ export class SessionRecorder {
|
|
|
293
290
|
}
|
|
294
291
|
}
|
|
295
292
|
|
|
293
|
+
private _disable() {
|
|
294
|
+
this._disabled = true;
|
|
295
|
+
this.clearBuffer();
|
|
296
|
+
if (this._flushTimer !== null) {
|
|
297
|
+
clearInterval(this._flushTimer);
|
|
298
|
+
this._flushTimer = null;
|
|
299
|
+
}
|
|
300
|
+
this._stopCurrentRecording();
|
|
301
|
+
}
|
|
302
|
+
|
|
296
303
|
private async _startRecording() {
|
|
297
304
|
if (this._recording || this._cancelled) return;
|
|
298
305
|
|