@coxwave/tap-kit-types 2.10.2 → 2.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -179,74 +179,36 @@ type ContainerConfig = {
179
179
  };
180
180
 
181
181
  /**
182
- * Feature Flags Type Definitions
183
- *
184
- * Extensible feature flag system using dot notation for namespacing.
185
- * Flags are optional booleans - undefined means "use default behavior".
186
- *
187
- * Naming convention: "domain.subdomain.feature"
188
- * Examples:
189
- * - "material.pdf.download" - PDF download in material viewer
190
- * - "quiz.enabled" - Quiz feature availability
191
- * - "chat.attachment" - File attachment in chat
192
- *
193
- * @example
194
- * const flags: FeatureFlags = {
195
- * "material.pdf.download": false, // Disable PDF download
196
- * };
197
- */
198
- /**
199
- * Known feature flag keys (for type safety and autocomplete)
200
- *
201
- * When adding new flags:
202
- * 1. Add the key to this union type
203
- * 2. Document the flag's purpose in JSDoc
204
- */
205
- type FeatureFlagKey =
206
- /**
207
- * Enable/disable PDF download button in material viewer
208
- * @default true (download enabled)
209
- */
210
- "material.pdf.download"
211
- /**
212
- * Enable/disable streak widget on home page
213
- * @default false (disabled, feature in development)
214
- */
215
- | "home.streak.enabled"
216
- /**
217
- * Enable/disable flashcard widget on home page
218
- * @default false (disabled, feature in development)
219
- */
220
- | "home.flashcard.enabled"
221
- /**
222
- * Enable/disable activity buttons on home page
223
- * @default true (enabled by default)
224
- */
225
- | "home.activity.enabled";
226
- /**
227
- * Feature flags object type
228
- *
229
- * All flags are optional - undefined means "use default behavior"
230
- * false = explicitly disabled
231
- * true = explicitly enabled
232
- */
182
+ * Feature Flags Single Source of Truth
183
+ *
184
+ * FLAG_DEFAULTS is the sole authority.
185
+ * FeatureFlagKey is derived never define keys separately.
186
+ * Server values always override: { ...FLAG_DEFAULTS, ...serverFlags }
187
+ *
188
+ * Naming: LaunchDarkly-style {action}.{subject}
189
+ * - show.* — UI visibility toggle
190
+ * - allow.* capability/permission gate
191
+ */
192
+ /** Every flag and its default. Add new flags here — types update automatically. */
193
+ declare const FLAG_DEFAULTS: {
194
+ readonly "show.tutor-profile": true;
195
+ readonly "show.streak": false;
196
+ readonly "show.activity": true;
197
+ readonly "show.quicktaps": true;
198
+ readonly "show.flashcard": false;
199
+ readonly "show.exam-activity": false;
200
+ readonly "show.chat-mode-chip": false;
201
+ readonly "allow.pdf-download": true;
202
+ };
203
+ /** Derived union of all known flag keys. */
204
+ type FeatureFlagKey = keyof typeof FLAG_DEFAULTS;
205
+ /** Partial flags — API boundary type (server may omit keys). */
233
206
  type FeatureFlags = Partial<Record<FeatureFlagKey, boolean>>;
234
- /**
235
- * Helper to check if a feature is enabled
236
- *
237
- * @param flags - Feature flags object
238
- * @param key - Feature flag key to check
239
- * @param defaultValue - Default value if flag is undefined (default: true)
240
- * @returns Whether the feature is enabled
241
- *
242
- * @example
243
- * const canDownload = isFeatureEnabled(flags, "material.pdf.download"); // default true
244
- * const quizEnabled = isFeatureEnabled(flags, "quiz.enabled", false); // default false
245
- */
246
- declare function isFeatureEnabled(flags: FeatureFlags | undefined, key: FeatureFlagKey, defaultValue?: boolean): boolean;
207
+ /** Check if a feature is enabled. Falls back to FLAG_DEFAULTS. */
208
+ declare function isFeatureEnabled(flags: FeatureFlags | undefined, key: FeatureFlagKey): boolean;
247
209
 
248
- type TapMessageType = "tap:ready" | "tap:close" | "timeline:seek" | "alarm:click" | "alarm:fadeIn" | "popUp:open" | "popUp:close" | "material:view:open" | "material:view:close" | "material:view:error" | "html:view:open" | "html:view:close" | "container:mode:change" | "container:mode:change:ack" | "container:layout:state:changed" | "viewport:resize" | "config:update" | "config:request" | "GA_EVENT" | "tutor:info" | "featureFlags:update";
249
- type TapMessage = TapReadyMessage | TapCloseMessage | TimelineSeekMessage | AlarmClickMessage | AlarmFadeInMessage | PopUpOpenMessage | PopUpCloseMessage | MaterialViewOpenMessage | MaterialViewCloseMessage | MaterialViewErrorMessage | HtmlViewOpenMessage | HtmlViewCloseMessage | ContainerModeChangeMessage | ContainerModeChangeAckMessage | ContainerLayoutStateChangedMessage | ViewportResizeMessage | ConfigUpdateMessage | ConfigRequestMessage | GAEventMessage | TutorInfoMessage | FeatureFlagsUpdateMessage;
210
+ type TapMessageType = "tap:ready" | "tap:close" | "timeline:seek" | "alarm:click" | "alarm:fadeIn" | "popUp:open" | "popUp:close" | "material:view:open" | "material:view:close" | "material:view:error" | "html:view:open" | "html:view:close" | "container:mode:change" | "container:mode:change:ack" | "container:layout:state:changed" | "viewport:resize" | "config:update" | "config:request" | "GA_EVENT" | "tutor:info" | "host:context";
211
+ type TapMessage = TapReadyMessage | TapCloseMessage | TimelineSeekMessage | AlarmClickMessage | AlarmFadeInMessage | PopUpOpenMessage | PopUpCloseMessage | MaterialViewOpenMessage | MaterialViewCloseMessage | MaterialViewErrorMessage | HtmlViewOpenMessage | HtmlViewCloseMessage | ContainerModeChangeMessage | ContainerModeChangeAckMessage | ContainerLayoutStateChangedMessage | ViewportResizeMessage | ConfigUpdateMessage | ConfigRequestMessage | GAEventMessage | TutorInfoMessage | HostContextMessage;
250
212
  interface TapReadyMessage {
251
213
  type: "tap:ready";
252
214
  gaId: string;
@@ -292,7 +254,7 @@ interface MaterialViewOpenMessage {
292
254
  title?: string;
293
255
  /** Text phrases to highlight in PDF (from reference_string parsing) */
294
256
  highlightPhrases?: string[];
295
- /** Feature flags for viewer behavior (e.g., "material.pdf.download": false) */
257
+ /** Feature flags for viewer behavior (e.g., "allow.pdf-download": false) */
296
258
  flags?: FeatureFlags;
297
259
  nonce?: string | number;
298
260
  }
@@ -404,7 +366,7 @@ interface ConfigUpdateMessage {
404
366
  tapUrl?: string;
405
367
  apiUrl?: string;
406
368
  environment?: "dev" | "prod" | "demo" | "staging";
407
- language?: "ko" | "en" | (string & {});
369
+ language?: "ko" | "en" | "ja" | (string & {});
408
370
  userId?: string;
409
371
  courseId?: string;
410
372
  clipId?: string;
@@ -477,13 +439,24 @@ interface TutorInfoMessage {
477
439
  tutorName: string;
478
440
  }
479
441
  /**
480
- * Feature Flags Update Message (iframeparent)
481
- * Sent from edutap after tutor_setting API response with feature flags
482
- * Used to update feature flags store in tap-kit-core
442
+ * Host Context Message (parentiframe)
443
+ * Generic channel for host application to send contextual data to the iframe.
444
+ * Uses contextType discriminator for different context kinds (quiz answers, reading progress, etc.)
445
+ *
446
+ * @example
447
+ * ```typescript
448
+ * // Passage answer submission
449
+ * messenger.post({
450
+ * type: "host:context",
451
+ * contextType: "passage:answer:submit",
452
+ * payload: { passageId, question, selectedOptionId, isCorrect }
453
+ * });
454
+ * ```
483
455
  */
484
- interface FeatureFlagsUpdateMessage {
485
- type: "featureFlags:update";
486
- flags: FeatureFlags;
456
+ interface HostContextMessage {
457
+ type: "host:context";
458
+ contextType: string;
459
+ payload: Record<string, unknown>;
487
460
  }
488
461
 
489
462
  /**
@@ -2326,6 +2299,11 @@ declare const TutorInfoSchema: ObjectSchema<{
2326
2299
  readonly type: LiteralSchema<"tutor:info", undefined>;
2327
2300
  readonly tutorName: StringSchema<undefined>;
2328
2301
  }, undefined>;
2302
+ declare const HostContextSchema: ObjectSchema<{
2303
+ readonly type: LiteralSchema<"host:context", undefined>;
2304
+ readonly contextType: StringSchema<undefined>;
2305
+ readonly payload: RecordSchema<StringSchema<undefined>, AnySchema, undefined>;
2306
+ }, undefined>;
2329
2307
  declare const TapMessageSchema: UnionSchema<[ObjectSchema<{
2330
2308
  readonly type: LiteralSchema<"tap:ready", undefined>;
2331
2309
  readonly gaId: StringSchema<undefined>;
@@ -2434,6 +2412,10 @@ declare const TapMessageSchema: UnionSchema<[ObjectSchema<{
2434
2412
  }, undefined>, ObjectSchema<{
2435
2413
  readonly type: LiteralSchema<"tutor:info", undefined>;
2436
2414
  readonly tutorName: StringSchema<undefined>;
2415
+ }, undefined>, ObjectSchema<{
2416
+ readonly type: LiteralSchema<"host:context", undefined>;
2417
+ readonly contextType: StringSchema<undefined>;
2418
+ readonly payload: RecordSchema<StringSchema<undefined>, AnySchema, undefined>;
2437
2419
  }, undefined>], undefined>;
2438
2420
 
2439
2421
  type TapMessageRecord = TapMessage;
@@ -2833,6 +2815,12 @@ interface TapKitInstance {
2833
2815
  setCourse(course: Partial<Course> & {
2834
2816
  courseId: string;
2835
2817
  }): void;
2818
+ /**
2819
+ * Send contextual data from host application to the iframe
2820
+ * @param contextType - Discriminator for context kind (e.g., "passage:answer:submit")
2821
+ * @param payload - Arbitrary data payload
2822
+ */
2823
+ sendContext(contextType: string, payload: Record<string, unknown>): void;
2836
2824
  }
2837
2825
  /** TapKit constructor type */
2838
2826
  type TapKitConstructor = new (config: TapKitConfig) => TapKitInstance;
@@ -3375,7 +3363,7 @@ interface TapKitElement extends HTMLElement {
3375
3363
  clipPlayHead?: number;
3376
3364
 
3377
3365
  /** Language (optional, default: "ko") */
3378
- language?: "ko" | "en";
3366
+ language?: "ko" | "en" | "ja";
3379
3367
 
3380
3368
  /** TAP Frontend URL (optional, for testing) */
3381
3369
  tapUrl?: string;
@@ -3472,6 +3460,27 @@ interface TapKitElement extends HTMLElement {
3472
3460
  */
3473
3461
  setCourse(course: Partial<Course> & { courseId: string }): void;
3474
3462
 
3463
+ /**
3464
+ * Send contextual data from host application to the iframe (AI tutor)
3465
+ *
3466
+ * Generic channel for passing host context (quiz answers, reading progress, etc.)
3467
+ * to the iframe. Uses contextType discriminator for different context kinds.
3468
+ *
3469
+ * @param contextType - Discriminator string (e.g., "passage:answer:submit")
3470
+ * @param payload - Arbitrary data payload
3471
+ *
3472
+ * @example
3473
+ * ```typescript
3474
+ * kit.sendContext("passage:answer:submit", {
3475
+ * passageId: "p1",
3476
+ * question: "What is...?",
3477
+ * selectedOptionId: "A",
3478
+ * isCorrect: true,
3479
+ * });
3480
+ * ```
3481
+ */
3482
+ sendContext(contextType: string, payload: Record<string, unknown>): void;
3483
+
3475
3484
  // ===== Delegate Properties (Read-only) =====
3476
3485
 
3477
3486
  /**
@@ -3587,7 +3596,7 @@ interface TapKitAttributes {
3587
3596
  "clip-play-head"?: number;
3588
3597
 
3589
3598
  /** Language setting */
3590
- language?: "ko" | "en";
3599
+ language?: "ko" | "en" | "ja";
3591
3600
 
3592
3601
  /** TAP Frontend URL (for testing) */
3593
3602
  "tap-url"?: string;
@@ -3738,7 +3747,7 @@ interface MaterialViewConfig {
3738
3747
 
3739
3748
  /**
3740
3749
  * Feature flags for viewer behavior
3741
- * @example { "material.pdf.download": false } // Disable download button
3750
+ * @example { "allow.pdf-download": false } // Disable download button
3742
3751
  */
3743
3752
  flags?: FeatureFlags;
3744
3753
  }
@@ -3921,7 +3930,7 @@ declare global {
3921
3930
  courseId?: string;
3922
3931
  clipId?: string;
3923
3932
  clipPlayHead?: number;
3924
- language?: "ko" | "en";
3933
+ language?: "ko" | "en" | "ja";
3925
3934
  buttonId?: string;
3926
3935
  mode?: "inline" | "floating" | "sidebar";
3927
3936
  chatMode?: "NORMAL" | "EXAM" | "STUDY";
@@ -3950,4 +3959,4 @@ declare global {
3950
3959
  function cancelIdleCallback(handle: number): void;
3951
3960
  }
3952
3961
 
3953
- export { ALARM_DURATION, type AlarmClickMessage, AlarmClickSchema, type AlarmElement, type AlarmElementProps, AlarmElementPropsSchema, AlarmElementSchema, type AlarmFadeInMessage, AlarmFadeInSchema, AlarmMessageInstanceSchema, type AlarmMessageInstanceType, type AlarmPayload, type AlarmType, type CSSStyle, CSSStyleSchema, type ChatMode, type ConfigRequestMessage, ConfigRequestSchema, type ConfigUpdateKey, type ConfigUpdateMessage, type ConfigUpdateOptions, type ConfigUpdatePayload, ConfigUpdateSchema, type ContainerConfig, type ContainerLayoutStateChangedMessage, ContainerLayoutStateChangedSchema, type ContainerModeChangeAckMessage, ContainerModeChangeAckSchema, type ContainerModeChangeMessage, ContainerModeChangeSchema, type ContainerVisibility, type Course, type DisplayMode, type EventManager, type FeatureFlagKey, type FeatureFlags, type FeatureFlagsUpdateMessage, type FloatingConfig, type GAEventMessage, GAEventSchema, type HtmlViewCloseMessage, HtmlViewCloseSchema, type HtmlViewConfig, type HtmlViewOpenMessage, HtmlViewOpenSchema, type ITapButtonElement, type ITapContainerElement, type ITapHtmlViewerElement, type ITapKitElement, type ITapMaterialViewerElement, TapKitInitializationError as InitializationError, type LayoutMode, type MaterialViewCloseMessage, MaterialViewCloseSchema, type MaterialViewConfig, type MaterialViewErrorMessage, MaterialViewErrorSchema, type MaterialViewOpenMessage, MaterialViewOpenSchema, MaterialViewerError, type PopUpCloseMessage, PopUpCloseSchema, type PopUpOpenMessage, PopUpOpenSchema, type PositionType, type SeekTimelineParamsType, type ShortcutKeyPropertiesType, type SidebarConfig, type SyncableConfigKey, TAP_BUTTON_CLICK_EVENT, TAP_ERROR_MARKER, type TapButtonAttributes, type TapButtonClickEventDetail, type TapCloseMessage, TapCloseSchema, type TapContainerAttributes, type TapErrorOptions, type TapHtmlViewerAttributes, type TapKitConfig, TapKitConfigurationError, type TapKitConstructor, type TapKitElement, type TapKitElementEventMap, TapKitError, TapKitIframeError, type TapKitInitParams, TapKitInitializationError, type TapKitInstance, TapKitLoaderError, TapKitMessageError, type TapMaterialViewerAttributes, type TapMessage, type TapMessageRecord, TapMessageSchema, type TapMessageType, type TapReadyMessage, TapReadySchema, type TimelineSeekMessage, TimelineSeekSchema, type TutorInfoMessage, TutorInfoSchema, type VideoController, type VideoPlayerAdapter, type VideoPlayerConfig, type ViewportResizeMessage, ViewportResizeSchema, isFeatureEnabled };
3962
+ export { ALARM_DURATION, type AlarmClickMessage, AlarmClickSchema, type AlarmElement, type AlarmElementProps, AlarmElementPropsSchema, AlarmElementSchema, type AlarmFadeInMessage, AlarmFadeInSchema, AlarmMessageInstanceSchema, type AlarmMessageInstanceType, type AlarmPayload, type AlarmType, type CSSStyle, CSSStyleSchema, type ChatMode, type ConfigRequestMessage, ConfigRequestSchema, type ConfigUpdateKey, type ConfigUpdateMessage, type ConfigUpdateOptions, type ConfigUpdatePayload, ConfigUpdateSchema, type ContainerConfig, type ContainerLayoutStateChangedMessage, ContainerLayoutStateChangedSchema, type ContainerModeChangeAckMessage, ContainerModeChangeAckSchema, type ContainerModeChangeMessage, ContainerModeChangeSchema, type ContainerVisibility, type Course, type DisplayMode, type EventManager, FLAG_DEFAULTS, type FeatureFlagKey, type FeatureFlags, type FloatingConfig, type GAEventMessage, GAEventSchema, type HostContextMessage, HostContextSchema, type HtmlViewCloseMessage, HtmlViewCloseSchema, type HtmlViewConfig, type HtmlViewOpenMessage, HtmlViewOpenSchema, type ITapButtonElement, type ITapContainerElement, type ITapHtmlViewerElement, type ITapKitElement, type ITapMaterialViewerElement, TapKitInitializationError as InitializationError, type LayoutMode, type MaterialViewCloseMessage, MaterialViewCloseSchema, type MaterialViewConfig, type MaterialViewErrorMessage, MaterialViewErrorSchema, type MaterialViewOpenMessage, MaterialViewOpenSchema, MaterialViewerError, type PopUpCloseMessage, PopUpCloseSchema, type PopUpOpenMessage, PopUpOpenSchema, type PositionType, type SeekTimelineParamsType, type ShortcutKeyPropertiesType, type SidebarConfig, type SyncableConfigKey, TAP_BUTTON_CLICK_EVENT, TAP_ERROR_MARKER, type TapButtonAttributes, type TapButtonClickEventDetail, type TapCloseMessage, TapCloseSchema, type TapContainerAttributes, type TapErrorOptions, type TapHtmlViewerAttributes, type TapKitConfig, TapKitConfigurationError, type TapKitConstructor, type TapKitElement, type TapKitElementEventMap, TapKitError, TapKitIframeError, type TapKitInitParams, TapKitInitializationError, type TapKitInstance, TapKitLoaderError, TapKitMessageError, type TapMaterialViewerAttributes, type TapMessage, type TapMessageRecord, TapMessageSchema, type TapMessageType, type TapReadyMessage, TapReadySchema, type TimelineSeekMessage, TimelineSeekSchema, type TutorInfoMessage, TutorInfoSchema, type VideoController, type VideoPlayerAdapter, type VideoPlayerConfig, type ViewportResizeMessage, ViewportResizeSchema, isFeatureEnabled };
package/dist/index.js CHANGED
@@ -3,9 +3,20 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
 
5
5
  // src/feature-flags.ts
6
- function isFeatureEnabled(flags, key, defaultValue = true) {
7
- if (!flags) return defaultValue;
8
- return flags[key] ?? defaultValue;
6
+ var FLAG_DEFAULTS = {
7
+ // Home screen (top bottom, matches preview order)
8
+ "show.tutor-profile": true,
9
+ "show.streak": false,
10
+ "show.activity": true,
11
+ "show.quicktaps": true,
12
+ "show.flashcard": false,
13
+ "show.exam-activity": false,
14
+ "show.chat-mode-chip": false,
15
+ // Capabilities (not in preview)
16
+ "allow.pdf-download": true
17
+ };
18
+ function isFeatureEnabled(flags, key) {
19
+ return flags?.[key] ?? FLAG_DEFAULTS[key];
9
20
  }
10
21
 
11
22
  // src/errors.ts
@@ -897,6 +908,11 @@ var TutorInfoSchema = object({
897
908
  type: literal("tutor:info"),
898
909
  tutorName: string()
899
910
  });
911
+ var HostContextSchema = object({
912
+ type: literal("host:context"),
913
+ contextType: string(),
914
+ payload: record(string(), any())
915
+ });
900
916
  var TapMessageSchema = union([
901
917
  TapReadySchema,
902
918
  TapCloseSchema,
@@ -917,12 +933,13 @@ var TapMessageSchema = union([
917
933
  ConfigUpdateSchema,
918
934
  ConfigRequestSchema,
919
935
  GAEventSchema,
920
- TutorInfoSchema
936
+ TutorInfoSchema,
937
+ HostContextSchema
921
938
  ]);
922
939
 
923
940
  // src/tap-button.d.ts
924
941
  var TAP_BUTTON_CLICK_EVENT = "tap-button:click";
925
942
 
926
- export { ALARM_DURATION, AlarmClickSchema, AlarmElementPropsSchema, AlarmElementSchema, AlarmFadeInSchema, AlarmMessageInstanceSchema, CSSStyleSchema, ConfigRequestSchema, ConfigUpdateSchema, ContainerLayoutStateChangedSchema, ContainerModeChangeAckSchema, ContainerModeChangeSchema, GAEventSchema, HtmlViewCloseSchema, HtmlViewOpenSchema, TapKitInitializationError as InitializationError, MaterialViewCloseSchema, MaterialViewErrorSchema, MaterialViewOpenSchema, MaterialViewerError, PopUpCloseSchema, PopUpOpenSchema, TAP_BUTTON_CLICK_EVENT, TAP_ERROR_MARKER, TapCloseSchema, TapKitConfigurationError, TapKitError, TapKitIframeError, TapKitInitializationError, TapKitLoaderError, TapKitMessageError, TapMessageSchema, TapReadySchema, TimelineSeekSchema, TutorInfoSchema, ViewportResizeSchema, isFeatureEnabled };
943
+ export { ALARM_DURATION, AlarmClickSchema, AlarmElementPropsSchema, AlarmElementSchema, AlarmFadeInSchema, AlarmMessageInstanceSchema, CSSStyleSchema, ConfigRequestSchema, ConfigUpdateSchema, ContainerLayoutStateChangedSchema, ContainerModeChangeAckSchema, ContainerModeChangeSchema, FLAG_DEFAULTS, GAEventSchema, HostContextSchema, HtmlViewCloseSchema, HtmlViewOpenSchema, TapKitInitializationError as InitializationError, MaterialViewCloseSchema, MaterialViewErrorSchema, MaterialViewOpenSchema, MaterialViewerError, PopUpCloseSchema, PopUpOpenSchema, TAP_BUTTON_CLICK_EVENT, TAP_ERROR_MARKER, TapCloseSchema, TapKitConfigurationError, TapKitError, TapKitIframeError, TapKitInitializationError, TapKitLoaderError, TapKitMessageError, TapMessageSchema, TapReadySchema, TimelineSeekSchema, TutorInfoSchema, ViewportResizeSchema, isFeatureEnabled };
927
944
  //# sourceMappingURL=index.js.map
928
945
  //# sourceMappingURL=index.js.map