@hexclave/js 1.0.19 → 1.0.21
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/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +34 -5
- 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 +1 -0
- 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 +24 -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.js +2 -2
- package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.js.map +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/client-app.d.ts +3 -2
- package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/hexclave-app/project-configs/index.d.ts +7 -0
- package/dist/esm/lib/hexclave-app/project-configs/index.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/projects/index.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/projects/index.js +1 -1
- package/dist/esm/lib/hexclave-app/projects/index.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +34 -5
- 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 +1 -0
- 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 +24 -4
- 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.js +2 -2
- package/dist/lib/hexclave-app/apps/implementations/server-app-impl.js.map +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/client-app.d.ts +3 -2
- package/dist/lib/hexclave-app/apps/interfaces/client-app.d.ts.map +1 -1
- package/dist/lib/hexclave-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/hexclave-app/project-configs/index.d.ts +7 -0
- package/dist/lib/hexclave-app/project-configs/index.d.ts.map +1 -1
- package/dist/lib/hexclave-app/projects/index.d.ts.map +1 -1
- package/dist/lib/hexclave-app/projects/index.js +1 -1
- package/dist/lib/hexclave-app/projects/index.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.ts +36 -0
- package/src/lib/hexclave-app/apps/implementations/client-app-impl.ts +43 -4
- 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/server-app-impl.ts +2 -2
- 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/client-app.ts +3 -2
- package/src/lib/hexclave-app/project-configs/index.ts +8 -0
- package/src/lib/hexclave-app/projects/index.ts +13 -11
|
@@ -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) {
|
|
@@ -356,7 +356,7 @@ export class _HexclaveServerAppImplIncomplete<HasTokenStore extends boolean, Pro
|
|
|
356
356
|
isPrimary: crud.is_primary,
|
|
357
357
|
usedForAuth: crud.used_for_auth,
|
|
358
358
|
async sendVerificationEmail(options?: { callbackUrl?: string }) {
|
|
359
|
-
await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? constructRedirectUrl(app.
|
|
359
|
+
await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, options?.callbackUrl ?? constructRedirectUrl(app._getUrls().emailVerification, "callbackUrl"));
|
|
360
360
|
},
|
|
361
361
|
async update(data: ServerContactChannelUpdateOptions) {
|
|
362
362
|
await app._interface.updateServerContactChannel(userId, crud.id, serverContactChannelUpdateOptionsToCrud(data));
|
|
@@ -922,7 +922,7 @@ export class _HexclaveServerAppImplIncomplete<HasTokenStore extends boolean, Pro
|
|
|
922
922
|
await app._interface.sendServerTeamInvitation({
|
|
923
923
|
teamId: crud.id,
|
|
924
924
|
email: options.email,
|
|
925
|
-
callbackUrl: options.callbackUrl ?? constructRedirectUrl(app.
|
|
925
|
+
callbackUrl: options.callbackUrl ?? constructRedirectUrl(app._getUrls().teamInvitation, "callbackUrl"),
|
|
926
926
|
});
|
|
927
927
|
await app._serverTeamInvitationsCache.refresh([crud.id]);
|
|
928
928
|
},
|
|
@@ -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
|
|
|
@@ -68,8 +68,9 @@ export type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId ex
|
|
|
68
68
|
readonly version: string,
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
* @deprecated `app.urls` is static and does not include runtime redirect-back
|
|
72
|
-
*
|
|
71
|
+
* @deprecated Do not use `app.urls` for navigation. It is static and does not include runtime redirect-back,
|
|
72
|
+
* cross-domain auth, or sign-out state. Use the matching `redirectToXyz()` method instead, for example
|
|
73
|
+
* `redirectToSignIn()`, `redirectToSignUp()`, `redirectToSignOut()`, or `redirectToAccountSettings()`.
|
|
73
74
|
*/
|
|
74
75
|
readonly urls: Readonly<ResolvedHandlerUrls>,
|
|
75
76
|
|
|
@@ -76,6 +76,14 @@ export type AdminOAuthProviderConfig = {
|
|
|
76
76
|
microsoftTenantId?: string,
|
|
77
77
|
appleBundleIds?: string[],
|
|
78
78
|
}
|
|
79
|
+
| {
|
|
80
|
+
type: 'custom_oidc',
|
|
81
|
+
clientId: string,
|
|
82
|
+
clientSecret: string,
|
|
83
|
+
issuerUrl: string,
|
|
84
|
+
scope?: string,
|
|
85
|
+
displayName?: string,
|
|
86
|
+
}
|
|
79
87
|
) & OAuthProviderConfig;
|
|
80
88
|
|
|
81
89
|
export type AdminProjectConfigUpdateOptions = {
|
|
@@ -176,17 +176,19 @@ export function adminProjectUpdateOptionsToCrud(options: AdminProjectUpdateOptio
|
|
|
176
176
|
domain: d.domain,
|
|
177
177
|
handler_path: d.handlerPath
|
|
178
178
|
})),
|
|
179
|
-
oauth_providers: options.config?.oauthProviders
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
179
|
+
oauth_providers: options.config?.oauthProviders
|
|
180
|
+
?.filter((p): p is Exclude<typeof p, { type: 'custom_oidc' }> => p.type !== 'custom_oidc')
|
|
181
|
+
.map((p) => ({
|
|
182
|
+
id: p.id as any,
|
|
183
|
+
type: p.type,
|
|
184
|
+
...(p.type === 'standard' && {
|
|
185
|
+
client_id: p.clientId,
|
|
186
|
+
client_secret: p.clientSecret,
|
|
187
|
+
facebook_config_id: p.facebookConfigId,
|
|
188
|
+
microsoft_tenant_id: p.microsoftTenantId,
|
|
189
|
+
apple_bundle_ids: p.appleBundleIds,
|
|
190
|
+
}),
|
|
191
|
+
})),
|
|
190
192
|
email_config: options.config?.emailConfig && (
|
|
191
193
|
options.config.emailConfig.type === 'shared' ? {
|
|
192
194
|
type: 'shared',
|