@touchcastllc/napster-companion-api-dev 1.5.0-alpha.1 → 1.6.0-alpha.2
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/lib/components/Avatar/index.d.ts +0 -1
- package/lib/index.css +1 -1
- package/lib/index.d.ts +13 -37
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/lib/index.standalone.js +1 -1
- package/lib/services/micGate.d.ts +30 -0
- package/lib/services/webrtc.d.ts +0 -5
- package/lib/stores/index.d.ts +2 -2
- package/lib/stores/selectors.d.ts +1 -4
- package/lib/stores/slices/appSlice.d.ts +2 -3
- package/lib/stores/slices/avatarSlice.d.ts +1 -7
- package/lib/stores/store.d.ts +0 -1
- package/lib/types/abstract-typing.d.ts +0 -22
- package/lib/types/errors.d.ts +0 -34
- package/lib/types/index.d.ts +21 -48
- package/lib/utils/debug.d.ts +0 -4
- package/lib/utils/mediaError.d.ts +0 -7
- package/package.json +1 -1
- package/lib/button/element.d.ts +0 -6
- package/lib/button/index.d.ts +0 -46
- package/lib/services/analytics.d.ts +0 -148
- package/lib/types/analytics.d.ts +0 -95
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handle returned by {@link gateOnMicrophone}. Lets the caller tear down an
|
|
3
|
+
* active recovery card (e.g. on session destroy) independent of whether the
|
|
4
|
+
* user ever retries.
|
|
5
|
+
*/
|
|
6
|
+
export interface MicGateController {
|
|
7
|
+
/** Force-hide the recovery card, if one is mounted. Safe to call unconditionally. */
|
|
8
|
+
dismiss(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface MicGateOptions {
|
|
11
|
+
/** Element the recovery card mounts into on denial. */
|
|
12
|
+
root: HTMLElement;
|
|
13
|
+
/**
|
|
14
|
+
* The microphone is available. Fires once for an immediate grant, and
|
|
15
|
+
* again after each successful "Check again" retry. May return a promise —
|
|
16
|
+
* {@link gateOnMicrophone}'s own promise waits for it, so a caller that
|
|
17
|
+
* awaits the gate call also waits for whatever `onGranted` kicks off.
|
|
18
|
+
*/
|
|
19
|
+
onGranted: () => void | Promise<void>;
|
|
20
|
+
/** Reported once, on the FIRST failure only — never on a refused retry. */
|
|
21
|
+
onError?: (error: Error) => void;
|
|
22
|
+
/** Fires immediately before the recovery card mounts. */
|
|
23
|
+
onBeforeRecovery?: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gate a session on microphone access (CA-622): try once, and on denial keep
|
|
27
|
+
* the widget mounted with a recovery card ("Check again", CA-774) instead of
|
|
28
|
+
* tearing it down.
|
|
29
|
+
*/
|
|
30
|
+
export declare function gateOnMicrophone(opts: MicGateOptions): Promise<MicGateController>;
|
package/lib/services/webrtc.d.ts
CHANGED
|
@@ -3,9 +3,7 @@ import type { MediaCapture } from "../utils/MediaCapture";
|
|
|
3
3
|
export interface WebRTCController {
|
|
4
4
|
startWithToken: (token: string) => Promise<void>;
|
|
5
5
|
close: () => void;
|
|
6
|
-
forceReconnect: () => Promise<void>;
|
|
7
6
|
getConnectionStatus: () => string;
|
|
8
|
-
getReconnectAttempts: () => number;
|
|
9
7
|
getError: () => Error | null;
|
|
10
8
|
updateAudioDevice: (deviceId: string) => Promise<void>;
|
|
11
9
|
}
|
|
@@ -19,9 +17,6 @@ interface WebRTCParams {
|
|
|
19
17
|
videoStream?: MediaStream | null;
|
|
20
18
|
audioStream?: MediaStream | null;
|
|
21
19
|
}) => void;
|
|
22
|
-
onDataChannel?: (dc: RTCDataChannel) => void;
|
|
23
|
-
maxReconnectAttempts?: number;
|
|
24
|
-
reconnectInterval?: number;
|
|
25
20
|
/**
|
|
26
21
|
* ICE servers for the peer connection. When omitted, servers from the
|
|
27
22
|
* connection token are used, else {@link DEFAULT_ICE_SERVERS}. Provide this to
|
package/lib/stores/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export { store } from "./store";
|
|
|
2
2
|
export type { RootState } from "./store";
|
|
3
3
|
export { setOnFeaturesUpdateCallback } from "./middleware/featuresUpdateMiddleware";
|
|
4
4
|
export * from "./selectors";
|
|
5
|
-
export { setSessionId,
|
|
6
|
-
export { setFeatures, resetFeatures,
|
|
5
|
+
export { setSessionId, setDataChannel, setStopInteraction, setMuted, setAutoMicActive, setVolume, setAvatarSpeaking, setScreenSharing, setUserTalking, setConnectionToken, setCloseConnectionHandler, setSessionTerminatedByServer, resetAvatar, } from "./slices/avatarSlice";
|
|
6
|
+
export { setFeatures, resetFeatures, setDebugMode } from "./slices/appSlice";
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { RootState } from "./index";
|
|
2
|
-
import { FeatureConfig
|
|
2
|
+
import { FeatureConfig } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* Avatar state selectors
|
|
5
5
|
*/
|
|
6
6
|
export declare const selectSessionId: (state: RootState) => string | undefined;
|
|
7
|
-
export declare const selectAvatarReady: (state: RootState) => boolean;
|
|
8
7
|
export declare const selectDataChannel: (state: RootState) => RTCDataChannel | null;
|
|
9
8
|
export declare const selectMuted: (state: RootState) => boolean;
|
|
10
9
|
export declare const selectAutoMicActive: (state: RootState) => boolean;
|
|
@@ -18,9 +17,7 @@ export declare const selectSessionTerminatedByServer: (state: RootState) => bool
|
|
|
18
17
|
* App state selectors
|
|
19
18
|
*/
|
|
20
19
|
export declare const selectFeatures: (state: RootState) => FeatureConfig;
|
|
21
|
-
export declare const selectPosition: (state: RootState) => Position | undefined;
|
|
22
20
|
/**
|
|
23
21
|
* Composite selectors
|
|
24
22
|
*/
|
|
25
23
|
export declare const selectIsConnected: (state: RootState) => boolean;
|
|
26
|
-
export declare const selectCanSendMessage: (state: RootState) => boolean;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FeatureConfig } from "../../types";
|
|
2
2
|
export interface AppState {
|
|
3
3
|
features: FeatureConfig;
|
|
4
|
-
position?: Position;
|
|
5
4
|
debugMode?: boolean;
|
|
6
5
|
}
|
|
7
6
|
export declare const setFeatures: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
8
7
|
feature: keyof FeatureConfig;
|
|
9
8
|
config: FeatureConfig[keyof FeatureConfig];
|
|
10
|
-
}, "app/setFeatures">, resetFeatures: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"app/resetFeatures">,
|
|
9
|
+
}, "app/setFeatures">, resetFeatures: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"app/resetFeatures">, setDebugMode: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<boolean | undefined, "app/setDebugMode">;
|
|
11
10
|
export declare const appReducer: import("redux").Reducer<AppState>;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
export interface WebRTCStatus {
|
|
2
|
-
blocked: boolean;
|
|
3
|
-
reason: string;
|
|
4
|
-
message: string;
|
|
5
|
-
}
|
|
6
1
|
export interface AvatarState {
|
|
7
2
|
sessionId?: string;
|
|
8
|
-
avatarReady: boolean;
|
|
9
3
|
dataChannel: RTCDataChannel | null;
|
|
10
4
|
stopInteraction: boolean;
|
|
11
5
|
muted: boolean;
|
|
@@ -18,5 +12,5 @@ export interface AvatarState {
|
|
|
18
12
|
closeConnectionHandler?: () => void;
|
|
19
13
|
sessionTerminatedByServer: boolean;
|
|
20
14
|
}
|
|
21
|
-
export declare const setSessionId: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setSessionId">,
|
|
15
|
+
export declare const setSessionId: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setSessionId">, setDataChannel: import("@reduxjs/toolkit").ActionCreatorWithPayload<RTCDataChannel | null, "avatar/setDataChannel">, setStopInteraction: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setStopInteraction">, setMuted: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMuted">, setAutoMicActive: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setAutoMicActive">, setVolume: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, "avatar/setVolume">, setAvatarSpeaking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setAvatarSpeaking">, setScreenSharing: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setScreenSharing">, setUserTalking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setUserTalking">, setConnectionToken: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setConnectionToken">, setCloseConnectionHandler: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<(() => void) | undefined, "avatar/setCloseConnectionHandler">, setSessionTerminatedByServer: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setSessionTerminatedByServer">, resetAvatar: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"avatar/resetAvatar">;
|
|
22
16
|
export declare const avatarReducer: import("redux").Reducer<AvatarState>;
|
package/lib/stores/store.d.ts
CHANGED
|
@@ -11,25 +11,3 @@ export interface BaseController<TOptions = unknown> {
|
|
|
11
11
|
*/
|
|
12
12
|
destroy(silent?: boolean): void;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Extended controller interface with lifecycle hooks
|
|
16
|
-
*/
|
|
17
|
-
export interface LifecycleController<TOptions = unknown> extends BaseController<TOptions> {
|
|
18
|
-
/**
|
|
19
|
-
* Initialize controller (called after construction)
|
|
20
|
-
*/
|
|
21
|
-
initialize?(): void;
|
|
22
|
-
/**
|
|
23
|
-
* Hook called before destroy
|
|
24
|
-
*/
|
|
25
|
-
beforeDestroy?(): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Controller with render capabilities
|
|
29
|
-
*/
|
|
30
|
-
export interface RenderController<TOptions = unknown> extends LifecycleController<TOptions> {
|
|
31
|
-
/**
|
|
32
|
-
* Render or re-render the component
|
|
33
|
-
*/
|
|
34
|
-
render(): void;
|
|
35
|
-
}
|
package/lib/types/errors.d.ts
CHANGED
|
@@ -30,12 +30,6 @@ export declare class InitializationError extends SDKError {
|
|
|
30
30
|
export declare class TokenError extends SDKError {
|
|
31
31
|
constructor(message: string, context?: Record<string, unknown>);
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* React version compatibility errors
|
|
35
|
-
*/
|
|
36
|
-
export declare class ReactVersionError extends SDKError {
|
|
37
|
-
constructor(message: string, context?: Record<string, unknown>);
|
|
38
|
-
}
|
|
39
33
|
/**
|
|
40
34
|
* Connection related errors
|
|
41
35
|
*/
|
|
@@ -48,30 +42,6 @@ export declare class ConnectionError extends SDKError {
|
|
|
48
42
|
export declare class WebRTCError extends SDKError {
|
|
49
43
|
constructor(message: string, context?: Record<string, unknown>);
|
|
50
44
|
}
|
|
51
|
-
/**
|
|
52
|
-
* API related errors
|
|
53
|
-
*/
|
|
54
|
-
export declare class APIError extends SDKError {
|
|
55
|
-
readonly status?: number;
|
|
56
|
-
readonly response?: unknown;
|
|
57
|
-
constructor(message: string, status?: number, response?: unknown, context?: Record<string, unknown>);
|
|
58
|
-
toJSON(): {
|
|
59
|
-
status: number | undefined;
|
|
60
|
-
response: unknown;
|
|
61
|
-
name: string;
|
|
62
|
-
message: string;
|
|
63
|
-
code: string;
|
|
64
|
-
timestamp: string;
|
|
65
|
-
context: Record<string, unknown> | undefined;
|
|
66
|
-
stack: string | undefined;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Configuration related errors
|
|
71
|
-
*/
|
|
72
|
-
export declare class ConfigurationError extends SDKError {
|
|
73
|
-
constructor(message: string, context?: Record<string, unknown>);
|
|
74
|
-
}
|
|
75
45
|
/**
|
|
76
46
|
* Feature related errors
|
|
77
47
|
*/
|
|
@@ -123,10 +93,6 @@ export declare enum ErrorCodes {
|
|
|
123
93
|
* Type guard to check if an error is an SDK error
|
|
124
94
|
*/
|
|
125
95
|
export declare function isSDKError(error: unknown): error is SDKError;
|
|
126
|
-
/**
|
|
127
|
-
* Helper function to create appropriate error based on context
|
|
128
|
-
*/
|
|
129
|
-
export declare function createError(type: "initialization" | "token" | "react" | "connection" | "webrtc" | "api" | "config" | "feature" | "media" | "faceTracking", message: string, context?: Record<string, unknown>): SDKError;
|
|
130
96
|
/**
|
|
131
97
|
* Error handler utility for consistent error processing
|
|
132
98
|
*/
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { AnalyticsConfig } from "./analytics";
|
|
2
1
|
import { DataChannelMessageType } from "../constants/events";
|
|
3
2
|
export * from "./errors";
|
|
4
|
-
export * from "./analytics";
|
|
5
3
|
export * from "./abstract-typing";
|
|
6
4
|
/**
|
|
7
5
|
* Placement positions used to anchor the UI on screen.
|
|
@@ -305,8 +303,7 @@ export interface NavigationProgressOptions {
|
|
|
305
303
|
height?: string;
|
|
306
304
|
}
|
|
307
305
|
/**
|
|
308
|
-
* Cross-page persistence options.
|
|
309
|
-
* `initWithButton` share the same persistence engine.
|
|
306
|
+
* Cross-page persistence options.
|
|
310
307
|
*/
|
|
311
308
|
export interface PersistenceOptions {
|
|
312
309
|
/** Turn persistence on. Required — there is no boolean shorthand. */
|
|
@@ -407,6 +404,19 @@ export interface PersistenceOptions {
|
|
|
407
404
|
* All fields are optional; sensible defaults are used by the SDK.
|
|
408
405
|
*/
|
|
409
406
|
export interface NapsterCompanionApiConfig {
|
|
407
|
+
/**
|
|
408
|
+
* Connection transport. Only `"webrtc"` exists today — any other value is a
|
|
409
|
+
* compile-time error. Reserved for future transports (e.g. WebSocket); until
|
|
410
|
+
* then the SDK defaults to `"webrtc"` and there is no reason to set this.
|
|
411
|
+
*/
|
|
412
|
+
transport?: "webrtc";
|
|
413
|
+
/**
|
|
414
|
+
* Connection modality. Only `"video"` exists today — any other value is a
|
|
415
|
+
* compile-time error. Reserved for future modalities (e.g. audio-only,
|
|
416
|
+
* text); until then the SDK defaults to `"video"` and there is no reason to
|
|
417
|
+
* set this.
|
|
418
|
+
*/
|
|
419
|
+
modality?: "video";
|
|
410
420
|
/** Position of the avatar on screen. See `Position` enum. */
|
|
411
421
|
position?: Position;
|
|
412
422
|
/** CSS class name(s) to add to the SDK root container. Useful for theming. */
|
|
@@ -463,22 +473,10 @@ export interface NapsterCompanionApiConfig {
|
|
|
463
473
|
/**
|
|
464
474
|
* Keep the session alive across page navigation. When enabled, the page is wrapped in
|
|
465
475
|
* a same-origin iframe so navigation happens inside it while the avatar stays in the
|
|
466
|
-
* top document, which never reloads.
|
|
476
|
+
* top document, which never reloads.
|
|
467
477
|
* When on, `mountContainer` is ignored — the avatar must live in the top document.
|
|
468
478
|
*/
|
|
469
479
|
persistence?: PersistenceOptions;
|
|
470
|
-
/**
|
|
471
|
-
* The click-to-start button's appearance. **Only used by `initWithButton()`** —
|
|
472
|
-
* passing it to `init()` (which connects immediately, with no button) throws.
|
|
473
|
-
*/
|
|
474
|
-
button?: {
|
|
475
|
-
/** Button text. Default: `"Talk to an agent"`. */
|
|
476
|
-
label?: string;
|
|
477
|
-
/** Optional companion picture shown on the button. */
|
|
478
|
-
avatarUrl?: string;
|
|
479
|
-
};
|
|
480
|
-
/** Analytics configuration controls analytics delivery and tracking. */
|
|
481
|
-
analytics?: AnalyticsConfig;
|
|
482
480
|
/** Lifecycle callbacks. All are optional. */
|
|
483
481
|
/** Called when the SDK has finished initialization and is ready to render. */
|
|
484
482
|
onReady?: () => void;
|
|
@@ -589,42 +587,17 @@ export interface NapsterCompanionApiInstance {
|
|
|
589
587
|
readonly isUserTalking: boolean;
|
|
590
588
|
}
|
|
591
589
|
/**
|
|
592
|
-
* Top-level SDK object exposed by the package. Call `init(
|
|
590
|
+
* Top-level SDK object exposed by the package. Call `init(getToken, config)` to
|
|
593
591
|
* bootstrap the SDK and receive a `NapsterCompanionApiInstance` for runtime control.
|
|
594
592
|
*/
|
|
595
593
|
export interface NapsterCompanionApiSDK {
|
|
596
594
|
/**
|
|
597
|
-
* Initialize the SDK
|
|
598
|
-
*
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* Render a button and connect on click (instead of connecting immediately like
|
|
603
|
-
* `init`). Returns a `NapsterCompanionApiController` synchronously — nothing connects
|
|
604
|
-
* until the user clicks. With `persistence`, the session survives navigation. No-op
|
|
605
|
-
* when run inside the persistence site frame.
|
|
606
|
-
*/
|
|
607
|
-
initWithButton(getToken: () => Promise<string>, config?: Partial<NapsterCompanionApiConfig>): import("../button").NapsterCompanionApiController;
|
|
608
|
-
/**
|
|
609
|
-
* Prompt for the microphone WITHOUT starting a session, so permission is settled
|
|
610
|
-
* before a connection token exists. A connection's lifetime starts the moment the
|
|
611
|
-
* backend creates it, and a prompt the user leaves open for seconds spends that
|
|
612
|
-
* budget before signaling runs — the session then fails to come up.
|
|
613
|
-
*
|
|
614
|
-
* `initWithButton` does this internally. Use it on the `init` path, where the host
|
|
615
|
-
* app owns when the token is minted:
|
|
616
|
-
*
|
|
617
|
-
* ```js
|
|
618
|
-
* await SDK.requestMicrophoneAccess();
|
|
619
|
-
* const token = await mintConnectionToken();
|
|
620
|
-
* await SDK.init(token, config);
|
|
621
|
-
* ```
|
|
622
|
-
*
|
|
623
|
-
* Rejects with a `ConnectionError` whose `context.name` is the underlying
|
|
624
|
-
* DOMException — `"NotAllowedError"` (refused) or `"NotFoundError"` (no device).
|
|
625
|
-
* Calling it is free once granted: the stream is cached and reused by the session.
|
|
595
|
+
* Initialize the SDK. `getToken` is called by the SDK itself once the microphone
|
|
596
|
+
* permission has settled, so the connection token is always fresh when signaling
|
|
597
|
+
* starts. A pre-minted token string is not accepted — minting it before the mic
|
|
598
|
+
* prompt lets it go stale while the user is deciding.
|
|
626
599
|
*/
|
|
627
|
-
|
|
600
|
+
init(getToken: () => Promise<string>, config?: Partial<NapsterCompanionApiConfig>): Promise<NapsterCompanionApiInstance>;
|
|
628
601
|
/** The SDK version string (useful for diagnostics). */
|
|
629
602
|
version: string;
|
|
630
603
|
}
|
package/lib/utils/debug.d.ts
CHANGED
|
@@ -5,10 +5,3 @@
|
|
|
5
5
|
* level down in `context.error`.
|
|
6
6
|
*/
|
|
7
7
|
export declare function rootCauseName(error: unknown): string | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* Whether a media failure leaves the user with a recoverable permission
|
|
10
|
-
* problem. Both flavors land on the same "access blocked" screen: a denied
|
|
11
|
-
* prompt is fixable in site settings, and a missing device is equally fatal to
|
|
12
|
-
* a voice session, so neither may negotiate a session the agent cannot hear.
|
|
13
|
-
*/
|
|
14
|
-
export declare function isMicUnavailable(error: unknown): boolean;
|
package/package.json
CHANGED
package/lib/button/element.d.ts
DELETED
package/lib/button/index.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import "./Button.css";
|
|
2
|
-
import type { NapsterCompanionApiConfig, NapsterCompanionApiInstance } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* Returned by {@link initWithButton}. A session controller: start/end the agent session,
|
|
5
|
-
* reach the live instance, or tear the button down. Created synchronously — nothing
|
|
6
|
-
* connects until `start()` (or a button click).
|
|
7
|
-
*
|
|
8
|
-
* Inside the SDK's own persistence frame (and during SSR) the call no-ops and every
|
|
9
|
-
* method here is a harmless no-op — `getInstance()` stays `null`. With
|
|
10
|
-
* `debug: true` the skip is logged.
|
|
11
|
-
*/
|
|
12
|
-
export interface NapsterCompanionApiController {
|
|
13
|
-
/** The live avatar instance once connected, else `null`. */
|
|
14
|
-
getInstance(): NapsterCompanionApiInstance | null;
|
|
15
|
-
/** Start the session (as if the button was clicked). */
|
|
16
|
-
start(): Promise<void>;
|
|
17
|
-
/** End the session (and, if persisted, unwrap back to the plain site). The button reappears. */
|
|
18
|
-
end(): void;
|
|
19
|
-
/** Remove the button and any active session/iframe. */
|
|
20
|
-
destroy(): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* What the button entry point needs from the SDK. Wired by the SDK's `initWithButton`
|
|
24
|
-
* method so this module never reaches into the singleton's internals.
|
|
25
|
-
*/
|
|
26
|
-
export interface ButtonDeps {
|
|
27
|
-
/** Connect a session; mounts the avatar into the button-owned root. */
|
|
28
|
-
init: (token: string, config?: Partial<NapsterCompanionApiConfig>) => Promise<NapsterCompanionApiInstance>;
|
|
29
|
-
/** Create + position the persistent, button-owned `#np_companion-sdk-root` and return it. */
|
|
30
|
-
mountRoot: (config: Partial<NapsterCompanionApiConfig>) => HTMLElement;
|
|
31
|
-
/** Remove the button-owned root and release SDK ownership (on destroy). */
|
|
32
|
-
unmountRoot: () => void;
|
|
33
|
-
/**
|
|
34
|
-
* Tear down any live session AND its persisted iframe WITHOUT navigating — reveal the
|
|
35
|
-
* page in place. Called when the whole widget is being removed (`destroy()`), where a
|
|
36
|
-
* page reload would be the wrong response. Private to the SDK↔button seam.
|
|
37
|
-
*/
|
|
38
|
-
disposeSession: () => void;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Build the button entry point. Returns a {@link NapsterCompanionApiController}.
|
|
42
|
-
*
|
|
43
|
-
* A no-op (returns an inert controller) when run inside the persistence site frame,
|
|
44
|
-
* so the same snippet is safe on every page.
|
|
45
|
-
*/
|
|
46
|
-
export declare function createButton(deps: ButtonDeps, getToken: () => Promise<string>, config?: Partial<NapsterCompanionApiConfig>): NapsterCompanionApiController;
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type { AnalyticsConfig } from "../types/analytics";
|
|
2
|
-
/**
|
|
3
|
-
* Analytics service class
|
|
4
|
-
*/
|
|
5
|
-
export declare class AnalyticsService {
|
|
6
|
-
private config;
|
|
7
|
-
private eventQueue;
|
|
8
|
-
private performanceQueue;
|
|
9
|
-
private errorQueue;
|
|
10
|
-
private flushTimer?;
|
|
11
|
-
private sessionId;
|
|
12
|
-
private providers;
|
|
13
|
-
constructor(config?: Partial<AnalyticsConfig>);
|
|
14
|
-
/**
|
|
15
|
-
* Setup analytics providers from configuration
|
|
16
|
-
*/
|
|
17
|
-
private setupProviders;
|
|
18
|
-
/**
|
|
19
|
-
* Generate a unique session ID
|
|
20
|
-
*/
|
|
21
|
-
private generateSessionId;
|
|
22
|
-
/**
|
|
23
|
-
* Start the flush timer for batched sending
|
|
24
|
-
*/
|
|
25
|
-
private startFlushTimer;
|
|
26
|
-
/**
|
|
27
|
-
* Setup automatic error tracking
|
|
28
|
-
*/
|
|
29
|
-
private setupErrorTracking;
|
|
30
|
-
/**
|
|
31
|
-
* Setup performance tracking
|
|
32
|
-
*/
|
|
33
|
-
private setupPerformanceTracking;
|
|
34
|
-
/**
|
|
35
|
-
* Track an analytics event
|
|
36
|
-
*/
|
|
37
|
-
trackEvent(name: string, properties?: Record<string, unknown>): void;
|
|
38
|
-
/**
|
|
39
|
-
* Track a performance metric
|
|
40
|
-
*/
|
|
41
|
-
trackPerformance(name: string, value: number, unit: "ms" | "bytes" | "count" | "percentage", context?: Record<string, unknown>): void;
|
|
42
|
-
/**
|
|
43
|
-
* Track an error
|
|
44
|
-
*/
|
|
45
|
-
trackError(error: Error, context?: Record<string, unknown>): void;
|
|
46
|
-
/**
|
|
47
|
-
* Track user interaction
|
|
48
|
-
*/
|
|
49
|
-
trackInteraction(action: string, target?: string, properties?: Record<string, unknown>): void;
|
|
50
|
-
/**
|
|
51
|
-
* Flush all queued data
|
|
52
|
-
*/
|
|
53
|
-
flush(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Flush events queue
|
|
56
|
-
*/
|
|
57
|
-
private flushEvents;
|
|
58
|
-
/**
|
|
59
|
-
* Flush performance queue
|
|
60
|
-
*/
|
|
61
|
-
private flushPerformance;
|
|
62
|
-
/**
|
|
63
|
-
* Flush errors queue
|
|
64
|
-
*/
|
|
65
|
-
private flushErrors;
|
|
66
|
-
/**
|
|
67
|
-
* Send data to analytics endpoint
|
|
68
|
-
*/
|
|
69
|
-
private sendData;
|
|
70
|
-
/**
|
|
71
|
-
* Send data to a specific analytics provider
|
|
72
|
-
*/
|
|
73
|
-
private sendToProvider;
|
|
74
|
-
/**
|
|
75
|
-
* Send to custom endpoint (backward compatible)
|
|
76
|
-
*/
|
|
77
|
-
private sendToCustomEndpoint;
|
|
78
|
-
/**
|
|
79
|
-
* Provider-specific send methods
|
|
80
|
-
*/
|
|
81
|
-
private sendToGA4;
|
|
82
|
-
private sendToMixpanel;
|
|
83
|
-
private sendToSegment;
|
|
84
|
-
private sendToAmplitude;
|
|
85
|
-
private sendToPostHog;
|
|
86
|
-
private sendToAzureInsights;
|
|
87
|
-
/**
|
|
88
|
-
* Update configuration
|
|
89
|
-
*/
|
|
90
|
-
updateConfig(newConfig: Partial<AnalyticsConfig>): void;
|
|
91
|
-
/**
|
|
92
|
-
* Destroy the analytics service
|
|
93
|
-
*/
|
|
94
|
-
destroy(): void;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Initialize analytics service
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* // Single provider configuration
|
|
101
|
-
* const analytics = initializeAnalytics({
|
|
102
|
-
* enabled: true,
|
|
103
|
-
* provider: {
|
|
104
|
-
* type: 'google-analytics-4',
|
|
105
|
-
* measurementId: 'G-XXXXXXXXXX',
|
|
106
|
-
* apiKey: 'your-api-secret'
|
|
107
|
-
* }
|
|
108
|
-
* });
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* // Multiple providers configuration
|
|
112
|
-
* const analytics = initializeAnalytics({
|
|
113
|
-
* enabled: true,
|
|
114
|
-
* providers: [
|
|
115
|
-
* {
|
|
116
|
-
* type: 'google-analytics-4',
|
|
117
|
-
* measurementId: 'G-XXXXXXXXXX',
|
|
118
|
-
* apiKey: 'your-api-secret'
|
|
119
|
-
* },
|
|
120
|
-
* {
|
|
121
|
-
* type: 'mixpanel',
|
|
122
|
-
* projectToken: 'your-mixpanel-token'
|
|
123
|
-
* }
|
|
124
|
-
* ]
|
|
125
|
-
* });
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* // Backward compatible legacy configuration
|
|
129
|
-
* const analytics = initializeAnalytics({
|
|
130
|
-
* enabled: true,
|
|
131
|
-
* endpoint: 'https://your-api.com/analytics',
|
|
132
|
-
* apiKey: 'your-api-key'
|
|
133
|
-
* });
|
|
134
|
-
*/
|
|
135
|
-
export declare function initializeAnalytics(config: Partial<AnalyticsConfig>): AnalyticsService;
|
|
136
|
-
/**
|
|
137
|
-
* Get the global analytics instance
|
|
138
|
-
*/
|
|
139
|
-
export declare function getAnalytics(): AnalyticsService | null;
|
|
140
|
-
/**
|
|
141
|
-
* Convenience functions for common tracking
|
|
142
|
-
*/
|
|
143
|
-
export declare const analytics: {
|
|
144
|
-
track: (name: string, properties?: Record<string, unknown>) => void;
|
|
145
|
-
performance: (name: string, value: number, unit: "ms" | "bytes" | "count" | "percentage", context?: Record<string, unknown>) => void;
|
|
146
|
-
error: (error: Error, context?: Record<string, unknown>) => void;
|
|
147
|
-
interaction: (action: string, target?: string, properties?: Record<string, unknown>) => void;
|
|
148
|
-
};
|
package/lib/types/analytics.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Analytics and monitoring service for SDK usage tracking
|
|
3
|
-
*/
|
|
4
|
-
export interface AnalyticsEvent {
|
|
5
|
-
/** Name of the analytics event */
|
|
6
|
-
name: string;
|
|
7
|
-
/** Properties associated with the event */
|
|
8
|
-
properties?: Record<string, unknown>;
|
|
9
|
-
/** Timestamp of the event */
|
|
10
|
-
timestamp?: number;
|
|
11
|
-
/** User identifier */
|
|
12
|
-
userId?: string;
|
|
13
|
-
/** Session identifier */
|
|
14
|
-
sessionId?: string;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Supported analytics providers
|
|
18
|
-
*/
|
|
19
|
-
export type AnalyticsProvider = "custom" | "google-analytics-4" | "mixpanel" | "segment" | "amplitude" | "posthog" | "azure-insights";
|
|
20
|
-
/**
|
|
21
|
-
* Analytics provider configuration
|
|
22
|
-
*/
|
|
23
|
-
export interface ProviderConfig {
|
|
24
|
-
/** Type of analytics provider */
|
|
25
|
-
type: AnalyticsProvider;
|
|
26
|
-
/** Measurement ID for Google Analytics 4 */
|
|
27
|
-
measurementId?: string;
|
|
28
|
-
/** Project token for Mixpanel */
|
|
29
|
-
projectToken?: string;
|
|
30
|
-
/** Write key for Segment */
|
|
31
|
-
writeKey?: string;
|
|
32
|
-
/** Generic API key */
|
|
33
|
-
apiKey?: string;
|
|
34
|
-
/** Custom endpoint */
|
|
35
|
-
endpoint?: string;
|
|
36
|
-
/** Regional endpoint */
|
|
37
|
-
region?: string;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Performance metric data structure
|
|
41
|
-
*/
|
|
42
|
-
export interface PerformanceMetric {
|
|
43
|
-
/** Name of the performance metric */
|
|
44
|
-
name: string;
|
|
45
|
-
/** Value of the metric */
|
|
46
|
-
value: number;
|
|
47
|
-
/** Unit of the metric value */
|
|
48
|
-
unit: "ms" | "bytes" | "count" | "percentage";
|
|
49
|
-
/** Timestamp of the metric */
|
|
50
|
-
timestamp?: number;
|
|
51
|
-
/** Additional context for the metric */
|
|
52
|
-
context?: Record<string, unknown>;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Error event data structure
|
|
56
|
-
*/
|
|
57
|
-
export interface ErrorEvent {
|
|
58
|
-
/** Error object */
|
|
59
|
-
error: Error;
|
|
60
|
-
/** Additional context for the error */
|
|
61
|
-
context?: Record<string, unknown>;
|
|
62
|
-
/** Timestamp of the error event */
|
|
63
|
-
timestamp?: number;
|
|
64
|
-
/** User identifier */
|
|
65
|
-
userId?: string;
|
|
66
|
-
/** Session identifier */
|
|
67
|
-
sessionId?: string;
|
|
68
|
-
/** Stack trace of the error */
|
|
69
|
-
stack?: string;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Analytics configuration options
|
|
73
|
-
*/
|
|
74
|
-
export interface AnalyticsConfig {
|
|
75
|
-
/** Enable or disable analytics tracking */
|
|
76
|
-
enabled: boolean;
|
|
77
|
-
/** Analytics service provider configuration */
|
|
78
|
-
provider?: ProviderConfig;
|
|
79
|
-
/** Support multiple analytics service providers */
|
|
80
|
-
providers?: ProviderConfig[];
|
|
81
|
-
/** Unique user identifier for tracking purposes */
|
|
82
|
-
userId?: string;
|
|
83
|
-
/** Unique session identifier for tracking purposes */
|
|
84
|
-
sessionId?: string;
|
|
85
|
-
/** Batch size for sending analytics events */
|
|
86
|
-
batchSize?: number;
|
|
87
|
-
/** Interval in milliseconds for flushing analytics data */
|
|
88
|
-
flushInterval?: number;
|
|
89
|
-
/** Enable or disable performance tracking */
|
|
90
|
-
enablePerformanceTracking?: boolean;
|
|
91
|
-
/** Enable or disable error tracking */
|
|
92
|
-
enableErrorTracking?: boolean;
|
|
93
|
-
/** Enable or disable user interaction tracking */
|
|
94
|
-
enableUserInteractionTracking?: boolean;
|
|
95
|
-
}
|