@coxwave/tap-kit-types 0.0.34

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 ADDED
@@ -0,0 +1,84 @@
1
+ # @coxwave/tap-kit-types
2
+
3
+ Shared TypeScript types for TapKit SDK packages.
4
+
5
+ ## Purpose
6
+
7
+ This package serves as the **single source of truth** for all TapKit type definitions, eliminating duplication between:
8
+
9
+ - `@coxwave/tap-sdk` - npm wrapper package
10
+ - `@coxwave/tap-kit-core` - CDN implementation
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @coxwave/tap-kit-types
16
+ # or
17
+ pnpm add @coxwave/tap-kit-types
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```typescript
23
+ import type {
24
+ TapKitConfig,
25
+ TapKitInitParams,
26
+ Course,
27
+ ContainerStyle,
28
+ } from "@coxwave/tap-kit-types";
29
+
30
+ const config: TapKitConfig = {
31
+ apiKey: "your-api-key",
32
+ };
33
+
34
+ const params: TapKitInitParams = {
35
+ buttonId: "tap-button",
36
+ course: {
37
+ userId: "user-1",
38
+ courseId: "course-1",
39
+ clipId: "clip-1",
40
+ },
41
+ };
42
+ ```
43
+
44
+ ## Exported Types
45
+
46
+ ### Core Configuration
47
+
48
+ - `TapKitConfig` - SDK configuration
49
+ - `TapKitInitParams` - Initialization parameters
50
+ - `Course` - Course information
51
+
52
+ ### Styling
53
+
54
+ - `ContainerStyle` - Container styling options
55
+ - `PositionType` - Position configuration
56
+ - `CustomStyles` - Backward compatibility alias
57
+
58
+ ### Events
59
+
60
+ - `SeekTimelineParamsType` - Timeline seek parameters
61
+ - `ShortcutKeyPropertiesType` - Keyboard shortcut configuration
62
+ - `ContainerVisibility` - Visibility state
63
+
64
+ ### Errors
65
+
66
+ - `TapKitError` - Base error class
67
+ - `TapKitInitializationError` - Initialization errors
68
+ - `TapKitMessageError` - Message communication errors
69
+ - `TapKitConfigurationError` - Configuration errors
70
+ - `TapKitLoaderError` - Loader errors
71
+ - `TapKitIframeError` - iframe operation errors
72
+
73
+ ### Re-exports from @coxwave/tap-messages
74
+
75
+ - `AlarmMessageInstanceType`
76
+ - `AlarmType`
77
+
78
+ ## Version
79
+
80
+ Current version: 0.1.0
81
+
82
+ ## License
83
+
84
+ MIT
@@ -0,0 +1,176 @@
1
+ import { AlarmMessageInstanceType } from '@coxwave/tap-messages';
2
+ export { AlarmMessageInstanceType, AlarmType } from '@coxwave/tap-messages';
3
+
4
+ /**
5
+ * @coxwave/tap-kit-types
6
+ * Shared TypeScript types for TapKit SDK packages
7
+ *
8
+ * This package serves as the single source of truth for all TapKit types,
9
+ * used by both @coxwave/tap-sdk (npm wrapper) and @coxwave/tap-kit-core (CDN implementation).
10
+ */
11
+
12
+ /**
13
+ * SDK Configuration
14
+ */
15
+ type TapKitConfig = {
16
+ apiKey: string;
17
+ };
18
+ /**
19
+ * SDK Initialization Parameters
20
+ */
21
+ type TapKitInitParams = {
22
+ buttonId: string;
23
+ course: Course;
24
+ container?: ContainerStyle;
25
+ };
26
+ /**
27
+ * Course Information
28
+ */
29
+ type Course = {
30
+ userId: string;
31
+ courseId: string;
32
+ clipId: string;
33
+ clipPlayHead?: number;
34
+ };
35
+ /**
36
+ * Container Styling
37
+ */
38
+ type ContainerStyle = {
39
+ position?: PositionType;
40
+ width?: string;
41
+ height?: string;
42
+ borderRadius?: string;
43
+ };
44
+ type PositionType = {
45
+ top?: string;
46
+ left?: string;
47
+ right?: string;
48
+ bottom?: string;
49
+ };
50
+ /**
51
+ * Flattened container styles (backward compatibility)
52
+ */
53
+ type CustomStyles = ContainerStyle;
54
+ /**
55
+ * Timeline seek parameters
56
+ */
57
+ type SeekTimelineParamsType = {
58
+ clipId: string;
59
+ clipPlayHead: number;
60
+ };
61
+ /**
62
+ * Shortcut Key Configuration
63
+ */
64
+ type ShortcutKeyPropertiesType = {
65
+ key: string;
66
+ modifier: "ctrlKey" | "altKey" | "shiftKey" | "metaKey" | "";
67
+ };
68
+ /**
69
+ * Container Visibility State
70
+ */
71
+ type ContainerVisibility = "open" | "closed";
72
+ /**
73
+ * Pop-up information passed to onPopUpOpen event handler
74
+ */
75
+ interface PopUpInfo {
76
+ html: string;
77
+ [key: string]: unknown;
78
+ }
79
+ /**
80
+ * Base TapKit instance interface
81
+ * Shared properties and methods between core and wrapper
82
+ */
83
+ interface TapKitBaseInstance {
84
+ events: {
85
+ seekTimeline: (params: SeekTimelineParamsType) => Promise<void>;
86
+ onTimelineSeek: (callback: (clipPlayHead: number, clipId: string) => void) => () => void;
87
+ onChatInitiated: (handler: () => void) => () => void;
88
+ onChatOpened: (handler: () => void) => () => void;
89
+ onChatClosed: (handler: () => void) => () => void;
90
+ onAlarmFadeIn: (handler: (messageInfo: AlarmMessageInstanceType) => void) => () => void;
91
+ onPopUpOpen: (handler: (popUpInfo: PopUpInfo) => void) => () => void;
92
+ onPdfOpen: (handler: () => void) => () => void;
93
+ onPdfClose: (handler: () => void) => () => void;
94
+ };
95
+ isOpen: boolean;
96
+ isInitialized: boolean;
97
+ ready: Promise<void>;
98
+ init(params: TapKitInitParams): Promise<void>;
99
+ destroy(): void;
100
+ }
101
+ /**
102
+ * TapKit instance type from tap-kit-core
103
+ * This matches the actual TapKit class exported from @coxwave/tap-kit-core
104
+ * Exported for advanced use cases (e.g., when using window.TapKit directly)
105
+ *
106
+ * Currently identical to TapKitBaseInstance, but kept as separate type
107
+ * for future extensibility and semantic clarity
108
+ */
109
+ interface TapKitCoreInstance extends TapKitBaseInstance {
110
+ }
111
+ /**
112
+ * Public TapKit instance interface
113
+ * This is what users interact with when using the SDK
114
+ */
115
+ interface TapKitInstance extends TapKitBaseInstance {
116
+ getVersion(): string;
117
+ }
118
+ /**
119
+ * TapKit constructor type
120
+ */
121
+ type TapKitConstructor = new (config: TapKitConfig) => TapKitCoreInstance;
122
+ declare const TAP_ERROR_MARKER = "__tap_sdk_error__";
123
+ interface TapErrorOptions {
124
+ code?: string;
125
+ cause?: Error;
126
+ }
127
+ /**
128
+ * Base error class for all TapKit errors
129
+ * Supports serialization across iframe boundaries
130
+ */
131
+ declare class TapKitError extends Error {
132
+ cause: Error | undefined;
133
+ code: string | undefined;
134
+ constructor(message: string, options?: TapErrorOptions);
135
+ /**
136
+ * Restore error from postMessage serialization
137
+ */
138
+ static fromPossibleFrameSafeError(error: any): TapKitError | null;
139
+ }
140
+ /**
141
+ * Error thrown when SDK initialization fails
142
+ */
143
+ declare class TapKitInitializationError extends TapKitError {
144
+ constructor(message: string, options?: TapErrorOptions);
145
+ static fromPossibleFrameSafeError(error: any): TapKitInitializationError | null;
146
+ }
147
+ /**
148
+ * Error thrown when message communication fails
149
+ */
150
+ declare class TapKitMessageError extends TapKitError {
151
+ constructor(message: string, options?: TapErrorOptions);
152
+ static fromPossibleFrameSafeError(error: any): TapKitMessageError | null;
153
+ }
154
+ /**
155
+ * Error thrown when configuration is invalid
156
+ */
157
+ declare class TapKitConfigurationError extends TapKitError {
158
+ constructor(message: string, options?: TapErrorOptions);
159
+ static fromPossibleFrameSafeError(error: any): TapKitConfigurationError | null;
160
+ }
161
+ /**
162
+ * Error thrown when loader fails to fetch or load resources
163
+ */
164
+ declare class TapKitLoaderError extends TapKitError {
165
+ constructor(message: string, options?: TapErrorOptions);
166
+ static fromPossibleFrameSafeError(error: any): TapKitLoaderError | null;
167
+ }
168
+ /**
169
+ * Error thrown when iframe operations fail
170
+ */
171
+ declare class TapKitIframeError extends TapKitError {
172
+ constructor(message: string, options?: TapErrorOptions);
173
+ static fromPossibleFrameSafeError(error: any): TapKitIframeError | null;
174
+ }
175
+
176
+ export { type ContainerStyle, type ContainerVisibility, type Course, type CustomStyles, TapKitInitializationError as InitializationError, type PopUpInfo, type PositionType, type SeekTimelineParamsType, type ShortcutKeyPropertiesType, TAP_ERROR_MARKER, type TapErrorOptions, type TapKitBaseInstance, type TapKitConfig, TapKitConfigurationError, type TapKitConstructor, type TapKitCoreInstance, TapKitError, TapKitIframeError, type TapKitInitParams, TapKitInitializationError, type TapKitInstance, TapKitLoaderError, TapKitMessageError };
package/dist/index.js ADDED
@@ -0,0 +1,136 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
5
+ // index.ts
6
+ var TAP_ERROR_MARKER = "__tap_sdk_error__";
7
+ var TapKitError = class _TapKitError extends Error {
8
+ constructor(message, options) {
9
+ super(message);
10
+ __publicField(this, "cause");
11
+ __publicField(this, "code");
12
+ this.name = "TapKitError";
13
+ this.code = options?.code;
14
+ this.cause = options?.cause;
15
+ }
16
+ /**
17
+ * Restore error from postMessage serialization
18
+ */
19
+ static fromPossibleFrameSafeError(error) {
20
+ if (error instanceof _TapKitError) {
21
+ return error;
22
+ }
23
+ if (error && typeof error === "object" && TAP_ERROR_MARKER in error && error[TAP_ERROR_MARKER] === "TapKitError") {
24
+ const err = new _TapKitError(error.message, {
25
+ code: error.code
26
+ });
27
+ err.stack = error.stack;
28
+ return err;
29
+ }
30
+ return null;
31
+ }
32
+ };
33
+ var TapKitInitializationError = class _TapKitInitializationError extends TapKitError {
34
+ constructor(message, options) {
35
+ super(message, options);
36
+ this.name = "TapKitInitializationError";
37
+ this.code = options?.code ?? "ERR_INITIALIZATION";
38
+ }
39
+ static fromPossibleFrameSafeError(error) {
40
+ if (error instanceof _TapKitInitializationError) {
41
+ return error;
42
+ }
43
+ if (error && typeof error === "object" && TAP_ERROR_MARKER in error && error[TAP_ERROR_MARKER] === "TapKitInitializationError") {
44
+ const err = new _TapKitInitializationError(error.message, {
45
+ code: error.code
46
+ });
47
+ err.stack = error.stack;
48
+ return err;
49
+ }
50
+ return null;
51
+ }
52
+ };
53
+ var TapKitMessageError = class _TapKitMessageError extends TapKitError {
54
+ constructor(message, options) {
55
+ super(message, options);
56
+ this.name = "TapKitMessageError";
57
+ this.code = options?.code ?? "ERR_MESSAGE";
58
+ }
59
+ static fromPossibleFrameSafeError(error) {
60
+ if (error instanceof _TapKitMessageError) {
61
+ return error;
62
+ }
63
+ if (error && typeof error === "object" && TAP_ERROR_MARKER in error && error[TAP_ERROR_MARKER] === "TapKitMessageError") {
64
+ const err = new _TapKitMessageError(error.message, {
65
+ code: error.code
66
+ });
67
+ err.stack = error.stack;
68
+ return err;
69
+ }
70
+ return null;
71
+ }
72
+ };
73
+ var TapKitConfigurationError = class _TapKitConfigurationError extends TapKitError {
74
+ constructor(message, options) {
75
+ super(message, options);
76
+ this.name = "TapKitConfigurationError";
77
+ this.code = options?.code ?? "ERR_CONFIGURATION";
78
+ }
79
+ static fromPossibleFrameSafeError(error) {
80
+ if (error instanceof _TapKitConfigurationError) {
81
+ return error;
82
+ }
83
+ if (error && typeof error === "object" && TAP_ERROR_MARKER in error && error[TAP_ERROR_MARKER] === "TapKitConfigurationError") {
84
+ const err = new _TapKitConfigurationError(error.message, {
85
+ code: error.code
86
+ });
87
+ err.stack = error.stack;
88
+ return err;
89
+ }
90
+ return null;
91
+ }
92
+ };
93
+ var TapKitLoaderError = class _TapKitLoaderError extends TapKitError {
94
+ constructor(message, options) {
95
+ super(message, options);
96
+ this.name = "TapKitLoaderError";
97
+ this.code = options?.code ?? "ERR_LOADER";
98
+ }
99
+ static fromPossibleFrameSafeError(error) {
100
+ if (error instanceof _TapKitLoaderError) {
101
+ return error;
102
+ }
103
+ if (error && typeof error === "object" && TAP_ERROR_MARKER in error && error[TAP_ERROR_MARKER] === "TapKitLoaderError") {
104
+ const err = new _TapKitLoaderError(error.message, {
105
+ code: error.code
106
+ });
107
+ err.stack = error.stack;
108
+ return err;
109
+ }
110
+ return null;
111
+ }
112
+ };
113
+ var TapKitIframeError = class _TapKitIframeError extends TapKitError {
114
+ constructor(message, options) {
115
+ super(message, options);
116
+ this.name = "TapKitIframeError";
117
+ this.code = options?.code ?? "ERR_IFRAME";
118
+ }
119
+ static fromPossibleFrameSafeError(error) {
120
+ if (error instanceof _TapKitIframeError) {
121
+ return error;
122
+ }
123
+ if (error && typeof error === "object" && TAP_ERROR_MARKER in error && error[TAP_ERROR_MARKER] === "TapKitIframeError") {
124
+ const err = new _TapKitIframeError(error.message, {
125
+ code: error.code
126
+ });
127
+ err.stack = error.stack;
128
+ return err;
129
+ }
130
+ return null;
131
+ }
132
+ };
133
+
134
+ export { TapKitInitializationError as InitializationError, TAP_ERROR_MARKER, TapKitConfigurationError, TapKitError, TapKitIframeError, TapKitInitializationError, TapKitLoaderError, TapKitMessageError };
135
+ //# sourceMappingURL=index.js.map
136
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../index.ts"],"names":[],"mappings":";;;;;AA4JO,IAAM,gBAAA,GAAmB;AAWzB,IAAM,WAAA,GAAN,MAAM,YAAA,SAAoB,KAAA,CAAM;AAAA,EAIrC,WAAA,CAAY,SAAiB,OAAA,EAA2B;AACtD,IAAA,KAAA,CAAM,OAAO,CAAA;AAJf,IAAA,aAAA,CAAA,IAAA,EAAS,OAAA,CAAA;AACT,IAAA,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAIE,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,OAAO,OAAA,EAAS,IAAA;AACrB,IAAA,IAAA,CAAK,QAAQ,OAAA,EAAS,KAAA;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,2BAA2B,KAAA,EAAgC;AAChE,IAAA,IAAI,iBAAiB,YAAA,EAAa;AAChC,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,IACE,KAAA,IACA,OAAO,KAAA,KAAU,QAAA,IACjB,oBAAoB,KAAA,IACpB,KAAA,CAAM,gBAAgB,CAAA,KAAM,aAAA,EAC5B;AACA,MAAA,MAAM,GAAA,GAAM,IAAI,YAAA,CAAY,KAAA,CAAM,OAAA,EAAS;AAAA,QACzC,MAAM,KAAA,CAA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,QAC/C,MAAM,KAAA,CAAM;AAAA,OACb,CAAA;AACD,MAAA,GAAA,CAAI,QAAQ,KAAA,CAAM,KAAA;AAClB,MAAA,OAAO,GAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"index.js","sourcesContent":["/**\n * @coxwave/tap-kit-types\n * Shared TypeScript types for TapKit SDK packages\n *\n * This package serves as the single source of truth for all TapKit types,\n * used by both @coxwave/tap-sdk (npm wrapper) and @coxwave/tap-kit-core (CDN implementation).\n */\n\n// ==================== Re-exports from tap-messages ====================\nimport type {\n AlarmMessageInstanceType,\n AlarmType,\n} from \"@coxwave/tap-messages\";\n\nexport type { AlarmMessageInstanceType, AlarmType };\n\n// ==================== Core Configuration Types ====================\n\n/**\n * SDK Configuration\n */\nexport type TapKitConfig = {\n apiKey: string;\n};\n\n/**\n * SDK Initialization Parameters\n */\nexport type TapKitInitParams = {\n buttonId: string;\n course: Course;\n container?: ContainerStyle;\n};\n\n/**\n * Course Information\n */\nexport type Course = {\n userId: string;\n courseId: string;\n clipId: string;\n clipPlayHead?: number;\n};\n\n// ==================== Styling Types ====================\n\n/**\n * Container Styling\n */\nexport type ContainerStyle = {\n position?: PositionType;\n width?: string;\n height?: string;\n borderRadius?: string;\n};\n\nexport type PositionType = {\n top?: string;\n left?: string;\n right?: string;\n bottom?: string;\n};\n\n/**\n * Flattened container styles (backward compatibility)\n */\nexport type CustomStyles = ContainerStyle;\n\n// ==================== Event Types ====================\n\n/**\n * Timeline seek parameters\n */\nexport type SeekTimelineParamsType = {\n clipId: string;\n clipPlayHead: number;\n};\n\n/**\n * Shortcut Key Configuration\n */\nexport type ShortcutKeyPropertiesType = {\n key: string;\n modifier: \"ctrlKey\" | \"altKey\" | \"shiftKey\" | \"metaKey\" | \"\";\n};\n\n/**\n * Container Visibility State\n */\nexport type ContainerVisibility = \"open\" | \"closed\";\n\n// ==================== SDK Instance Interfaces ====================\n\n/**\n * Pop-up information passed to onPopUpOpen event handler\n */\nexport interface PopUpInfo {\n html: string;\n [key: string]: unknown;\n}\n\n/**\n * Base TapKit instance interface\n * Shared properties and methods between core and wrapper\n */\nexport interface TapKitBaseInstance {\n events: {\n seekTimeline: (params: SeekTimelineParamsType) => Promise<void>;\n onTimelineSeek: (\n callback: (clipPlayHead: number, clipId: string) => void,\n ) => () => void;\n onChatInitiated: (handler: () => void) => () => void;\n onChatOpened: (handler: () => void) => () => void;\n onChatClosed: (handler: () => void) => () => void;\n onAlarmFadeIn: (\n handler: (messageInfo: AlarmMessageInstanceType) => void,\n ) => () => void;\n onPopUpOpen: (handler: (popUpInfo: PopUpInfo) => void) => () => void;\n onPdfOpen: (handler: () => void) => () => void;\n onPdfClose: (handler: () => void) => () => void;\n };\n isOpen: boolean;\n isInitialized: boolean;\n ready: Promise<void>;\n init(params: TapKitInitParams): Promise<void>;\n destroy(): void;\n}\n\n/**\n * TapKit instance type from tap-kit-core\n * This matches the actual TapKit class exported from @coxwave/tap-kit-core\n * Exported for advanced use cases (e.g., when using window.TapKit directly)\n *\n * Currently identical to TapKitBaseInstance, but kept as separate type\n * for future extensibility and semantic clarity\n */\nexport interface TapKitCoreInstance extends TapKitBaseInstance {}\n\n/**\n * Public TapKit instance interface\n * This is what users interact with when using the SDK\n */\nexport interface TapKitInstance extends TapKitBaseInstance {\n // Wrapper-specific method\n getVersion(): string;\n}\n\n/**\n * TapKit constructor type\n */\nexport type TapKitConstructor = new (\n config: TapKitConfig,\n) => TapKitCoreInstance;\n\n// ==================== Error Classes ====================\n\nexport const TAP_ERROR_MARKER = \"__tap_sdk_error__\";\n\nexport interface TapErrorOptions {\n code?: string;\n cause?: Error;\n}\n\n/**\n * Base error class for all TapKit errors\n * Supports serialization across iframe boundaries\n */\nexport class TapKitError extends Error {\n override cause: Error | undefined;\n code: string | undefined;\n\n constructor(message: string, options?: TapErrorOptions) {\n super(message);\n this.name = \"TapKitError\";\n this.code = options?.code;\n this.cause = options?.cause;\n }\n\n /**\n * Restore error from postMessage serialization\n */\n static fromPossibleFrameSafeError(error: any): TapKitError | null {\n if (error instanceof TapKitError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitError\"\n ) {\n const err = new TapKitError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when SDK initialization fails\n */\nexport class TapKitInitializationError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitInitializationError\";\n this.code = options?.code ?? \"ERR_INITIALIZATION\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitInitializationError | null {\n if (error instanceof TapKitInitializationError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitInitializationError\"\n ) {\n const err = new TapKitInitializationError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when message communication fails\n */\nexport class TapKitMessageError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitMessageError\";\n this.code = options?.code ?? \"ERR_MESSAGE\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitMessageError | null {\n if (error instanceof TapKitMessageError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitMessageError\"\n ) {\n const err = new TapKitMessageError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when configuration is invalid\n */\nexport class TapKitConfigurationError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitConfigurationError\";\n this.code = options?.code ?? \"ERR_CONFIGURATION\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitConfigurationError | null {\n if (error instanceof TapKitConfigurationError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitConfigurationError\"\n ) {\n const err = new TapKitConfigurationError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when loader fails to fetch or load resources\n */\nexport class TapKitLoaderError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitLoaderError\";\n this.code = options?.code ?? \"ERR_LOADER\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitLoaderError | null {\n if (error instanceof TapKitLoaderError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitLoaderError\"\n ) {\n const err = new TapKitLoaderError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n/**\n * Error thrown when iframe operations fail\n */\nexport class TapKitIframeError extends TapKitError {\n constructor(message: string, options?: TapErrorOptions) {\n super(message, options);\n this.name = \"TapKitIframeError\";\n this.code = options?.code ?? \"ERR_IFRAME\";\n }\n\n static override fromPossibleFrameSafeError(\n error: any\n ): TapKitIframeError | null {\n if (error instanceof TapKitIframeError) {\n return error;\n }\n if (\n error &&\n typeof error === \"object\" &&\n TAP_ERROR_MARKER in error &&\n error[TAP_ERROR_MARKER] === \"TapKitIframeError\"\n ) {\n const err = new TapKitIframeError(error.message, {\n code: error.code,\n });\n err.stack = error.stack;\n return err;\n }\n return null;\n }\n}\n\n// Backward compatibility alias\nexport { TapKitInitializationError as InitializationError };\n"]}
package/index.ts ADDED
@@ -0,0 +1,363 @@
1
+ /**
2
+ * @coxwave/tap-kit-types
3
+ * Shared TypeScript types for TapKit SDK packages
4
+ *
5
+ * This package serves as the single source of truth for all TapKit types,
6
+ * used by both @coxwave/tap-sdk (npm wrapper) and @coxwave/tap-kit-core (CDN implementation).
7
+ */
8
+
9
+ // ==================== Re-exports from tap-messages ====================
10
+ import type {
11
+ AlarmMessageInstanceType,
12
+ AlarmType,
13
+ } from "@coxwave/tap-messages";
14
+
15
+ export type { AlarmMessageInstanceType, AlarmType };
16
+
17
+ // ==================== Core Configuration Types ====================
18
+
19
+ /**
20
+ * SDK Configuration
21
+ */
22
+ export type TapKitConfig = {
23
+ apiKey: string;
24
+ };
25
+
26
+ /**
27
+ * SDK Initialization Parameters
28
+ */
29
+ export type TapKitInitParams = {
30
+ buttonId: string;
31
+ course: Course;
32
+ container?: ContainerStyle;
33
+ };
34
+
35
+ /**
36
+ * Course Information
37
+ */
38
+ export type Course = {
39
+ userId: string;
40
+ courseId: string;
41
+ clipId: string;
42
+ clipPlayHead?: number;
43
+ };
44
+
45
+ // ==================== Styling Types ====================
46
+
47
+ /**
48
+ * Container Styling
49
+ */
50
+ export type ContainerStyle = {
51
+ position?: PositionType;
52
+ width?: string;
53
+ height?: string;
54
+ borderRadius?: string;
55
+ };
56
+
57
+ export type PositionType = {
58
+ top?: string;
59
+ left?: string;
60
+ right?: string;
61
+ bottom?: string;
62
+ };
63
+
64
+ /**
65
+ * Flattened container styles (backward compatibility)
66
+ */
67
+ export type CustomStyles = ContainerStyle;
68
+
69
+ // ==================== Event Types ====================
70
+
71
+ /**
72
+ * Timeline seek parameters
73
+ */
74
+ export type SeekTimelineParamsType = {
75
+ clipId: string;
76
+ clipPlayHead: number;
77
+ };
78
+
79
+ /**
80
+ * Shortcut Key Configuration
81
+ */
82
+ export type ShortcutKeyPropertiesType = {
83
+ key: string;
84
+ modifier: "ctrlKey" | "altKey" | "shiftKey" | "metaKey" | "";
85
+ };
86
+
87
+ /**
88
+ * Container Visibility State
89
+ */
90
+ export type ContainerVisibility = "open" | "closed";
91
+
92
+ // ==================== SDK Instance Interfaces ====================
93
+
94
+ /**
95
+ * Pop-up information passed to onPopUpOpen event handler
96
+ */
97
+ export interface PopUpInfo {
98
+ html: string;
99
+ [key: string]: unknown;
100
+ }
101
+
102
+ /**
103
+ * Base TapKit instance interface
104
+ * Shared properties and methods between core and wrapper
105
+ */
106
+ export interface TapKitBaseInstance {
107
+ events: {
108
+ seekTimeline: (params: SeekTimelineParamsType) => Promise<void>;
109
+ onTimelineSeek: (
110
+ callback: (clipPlayHead: number, clipId: string) => void,
111
+ ) => () => void;
112
+ onChatInitiated: (handler: () => void) => () => void;
113
+ onChatOpened: (handler: () => void) => () => void;
114
+ onChatClosed: (handler: () => void) => () => void;
115
+ onAlarmFadeIn: (
116
+ handler: (messageInfo: AlarmMessageInstanceType) => void,
117
+ ) => () => void;
118
+ onPopUpOpen: (handler: (popUpInfo: PopUpInfo) => void) => () => void;
119
+ onPdfOpen: (handler: () => void) => () => void;
120
+ onPdfClose: (handler: () => void) => () => void;
121
+ };
122
+ isOpen: boolean;
123
+ isInitialized: boolean;
124
+ ready: Promise<void>;
125
+ init(params: TapKitInitParams): Promise<void>;
126
+ destroy(): void;
127
+ }
128
+
129
+ /**
130
+ * TapKit instance type from tap-kit-core
131
+ * This matches the actual TapKit class exported from @coxwave/tap-kit-core
132
+ * Exported for advanced use cases (e.g., when using window.TapKit directly)
133
+ *
134
+ * Currently identical to TapKitBaseInstance, but kept as separate type
135
+ * for future extensibility and semantic clarity
136
+ */
137
+ export interface TapKitCoreInstance extends TapKitBaseInstance {}
138
+
139
+ /**
140
+ * Public TapKit instance interface
141
+ * This is what users interact with when using the SDK
142
+ */
143
+ export interface TapKitInstance extends TapKitBaseInstance {
144
+ // Wrapper-specific method
145
+ getVersion(): string;
146
+ }
147
+
148
+ /**
149
+ * TapKit constructor type
150
+ */
151
+ export type TapKitConstructor = new (
152
+ config: TapKitConfig,
153
+ ) => TapKitCoreInstance;
154
+
155
+ // ==================== Error Classes ====================
156
+
157
+ export const TAP_ERROR_MARKER = "__tap_sdk_error__";
158
+
159
+ export interface TapErrorOptions {
160
+ code?: string;
161
+ cause?: Error;
162
+ }
163
+
164
+ /**
165
+ * Base error class for all TapKit errors
166
+ * Supports serialization across iframe boundaries
167
+ */
168
+ export class TapKitError extends Error {
169
+ override cause: Error | undefined;
170
+ code: string | undefined;
171
+
172
+ constructor(message: string, options?: TapErrorOptions) {
173
+ super(message);
174
+ this.name = "TapKitError";
175
+ this.code = options?.code;
176
+ this.cause = options?.cause;
177
+ }
178
+
179
+ /**
180
+ * Restore error from postMessage serialization
181
+ */
182
+ static fromPossibleFrameSafeError(error: any): TapKitError | null {
183
+ if (error instanceof TapKitError) {
184
+ return error;
185
+ }
186
+ if (
187
+ error &&
188
+ typeof error === "object" &&
189
+ TAP_ERROR_MARKER in error &&
190
+ error[TAP_ERROR_MARKER] === "TapKitError"
191
+ ) {
192
+ const err = new TapKitError(error.message, {
193
+ code: error.code,
194
+ });
195
+ err.stack = error.stack;
196
+ return err;
197
+ }
198
+ return null;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Error thrown when SDK initialization fails
204
+ */
205
+ export class TapKitInitializationError extends TapKitError {
206
+ constructor(message: string, options?: TapErrorOptions) {
207
+ super(message, options);
208
+ this.name = "TapKitInitializationError";
209
+ this.code = options?.code ?? "ERR_INITIALIZATION";
210
+ }
211
+
212
+ static override fromPossibleFrameSafeError(
213
+ error: any
214
+ ): TapKitInitializationError | null {
215
+ if (error instanceof TapKitInitializationError) {
216
+ return error;
217
+ }
218
+ if (
219
+ error &&
220
+ typeof error === "object" &&
221
+ TAP_ERROR_MARKER in error &&
222
+ error[TAP_ERROR_MARKER] === "TapKitInitializationError"
223
+ ) {
224
+ const err = new TapKitInitializationError(error.message, {
225
+ code: error.code,
226
+ });
227
+ err.stack = error.stack;
228
+ return err;
229
+ }
230
+ return null;
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Error thrown when message communication fails
236
+ */
237
+ export class TapKitMessageError extends TapKitError {
238
+ constructor(message: string, options?: TapErrorOptions) {
239
+ super(message, options);
240
+ this.name = "TapKitMessageError";
241
+ this.code = options?.code ?? "ERR_MESSAGE";
242
+ }
243
+
244
+ static override fromPossibleFrameSafeError(
245
+ error: any
246
+ ): TapKitMessageError | null {
247
+ if (error instanceof TapKitMessageError) {
248
+ return error;
249
+ }
250
+ if (
251
+ error &&
252
+ typeof error === "object" &&
253
+ TAP_ERROR_MARKER in error &&
254
+ error[TAP_ERROR_MARKER] === "TapKitMessageError"
255
+ ) {
256
+ const err = new TapKitMessageError(error.message, {
257
+ code: error.code,
258
+ });
259
+ err.stack = error.stack;
260
+ return err;
261
+ }
262
+ return null;
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Error thrown when configuration is invalid
268
+ */
269
+ export class TapKitConfigurationError extends TapKitError {
270
+ constructor(message: string, options?: TapErrorOptions) {
271
+ super(message, options);
272
+ this.name = "TapKitConfigurationError";
273
+ this.code = options?.code ?? "ERR_CONFIGURATION";
274
+ }
275
+
276
+ static override fromPossibleFrameSafeError(
277
+ error: any
278
+ ): TapKitConfigurationError | null {
279
+ if (error instanceof TapKitConfigurationError) {
280
+ return error;
281
+ }
282
+ if (
283
+ error &&
284
+ typeof error === "object" &&
285
+ TAP_ERROR_MARKER in error &&
286
+ error[TAP_ERROR_MARKER] === "TapKitConfigurationError"
287
+ ) {
288
+ const err = new TapKitConfigurationError(error.message, {
289
+ code: error.code,
290
+ });
291
+ err.stack = error.stack;
292
+ return err;
293
+ }
294
+ return null;
295
+ }
296
+ }
297
+
298
+ /**
299
+ * Error thrown when loader fails to fetch or load resources
300
+ */
301
+ export class TapKitLoaderError extends TapKitError {
302
+ constructor(message: string, options?: TapErrorOptions) {
303
+ super(message, options);
304
+ this.name = "TapKitLoaderError";
305
+ this.code = options?.code ?? "ERR_LOADER";
306
+ }
307
+
308
+ static override fromPossibleFrameSafeError(
309
+ error: any
310
+ ): TapKitLoaderError | null {
311
+ if (error instanceof TapKitLoaderError) {
312
+ return error;
313
+ }
314
+ if (
315
+ error &&
316
+ typeof error === "object" &&
317
+ TAP_ERROR_MARKER in error &&
318
+ error[TAP_ERROR_MARKER] === "TapKitLoaderError"
319
+ ) {
320
+ const err = new TapKitLoaderError(error.message, {
321
+ code: error.code,
322
+ });
323
+ err.stack = error.stack;
324
+ return err;
325
+ }
326
+ return null;
327
+ }
328
+ }
329
+
330
+ /**
331
+ * Error thrown when iframe operations fail
332
+ */
333
+ export class TapKitIframeError extends TapKitError {
334
+ constructor(message: string, options?: TapErrorOptions) {
335
+ super(message, options);
336
+ this.name = "TapKitIframeError";
337
+ this.code = options?.code ?? "ERR_IFRAME";
338
+ }
339
+
340
+ static override fromPossibleFrameSafeError(
341
+ error: any
342
+ ): TapKitIframeError | null {
343
+ if (error instanceof TapKitIframeError) {
344
+ return error;
345
+ }
346
+ if (
347
+ error &&
348
+ typeof error === "object" &&
349
+ TAP_ERROR_MARKER in error &&
350
+ error[TAP_ERROR_MARKER] === "TapKitIframeError"
351
+ ) {
352
+ const err = new TapKitIframeError(error.message, {
353
+ code: error.code,
354
+ });
355
+ err.stack = error.stack;
356
+ return err;
357
+ }
358
+ return null;
359
+ }
360
+ }
361
+
362
+ // Backward compatibility alias
363
+ export { TapKitInitializationError as InitializationError };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@coxwave/tap-kit-types",
3
+ "version": "0.0.34",
4
+ "type": "module",
5
+ "description": "Shared TypeScript types for TapKit SDK packages",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "dev": "tsup --watch",
17
+ "lint": "eslint .",
18
+ "publish:npm": "./scripts/publish.sh"
19
+ },
20
+ "keywords": [
21
+ "tapkit",
22
+ "types",
23
+ "typescript"
24
+ ],
25
+ "author": "",
26
+ "license": "MIT",
27
+ "files": [
28
+ "dist",
29
+ "index.ts"
30
+ ],
31
+ "peerDependencies": {
32
+ "@coxwave/tap-messages": "^0.0.1"
33
+ },
34
+ "devDependencies": {
35
+ "@coxwave/config-eslint": "workspace:*",
36
+ "@coxwave/config-typescript": "workspace:*",
37
+ "@coxwave/tap-messages": "workspace:*",
38
+ "tsup": "^8.5.0"
39
+ }
40
+ }