@census-ai/census-sdk 0.2.0 → 0.4.1

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.cts CHANGED
@@ -103,7 +103,7 @@ interface Article {
103
103
  read_time_minutes: number | null;
104
104
  published_at: string | null;
105
105
  sort_order: number;
106
- content?: unknown;
106
+ content?: string;
107
107
  content_html?: string;
108
108
  features?: {
109
109
  id: string;
@@ -111,6 +111,36 @@ interface Article {
111
111
  slug: string;
112
112
  };
113
113
  }
114
+ /**
115
+ * A feature within a feature group
116
+ */
117
+ interface Feature {
118
+ id: string;
119
+ name: string;
120
+ slug: string;
121
+ description: string | null;
122
+ status: string;
123
+ article_count: number;
124
+ }
125
+ /**
126
+ * A feature group containing features
127
+ */
128
+ interface FeatureGroup {
129
+ id: string;
130
+ name: string;
131
+ slug: string;
132
+ description: string | null;
133
+ color: string | null;
134
+ features: Feature[];
135
+ feature_count: number;
136
+ article_count: number;
137
+ }
138
+ /**
139
+ * Response from feature groups endpoint
140
+ */
141
+ interface FeatureGroupsResponse {
142
+ feature_groups: FeatureGroup[];
143
+ }
114
144
  /**
115
145
  * Options for fetching articles
116
146
  */
@@ -229,6 +259,272 @@ interface CensusError {
229
259
  error: string;
230
260
  status?: number;
231
261
  }
262
+ /**
263
+ * Step types for guides
264
+ */
265
+ type GuideStepType = 'tooltip' | 'modal' | 'slideout' | 'hotspot' | 'banner';
266
+ /**
267
+ * Tooltip position options
268
+ */
269
+ type TooltipPosition = 'auto' | 'top' | 'bottom' | 'left' | 'right';
270
+ /**
271
+ * Step advancement trigger types
272
+ */
273
+ type AdvanceTrigger = 'button' | 'click' | 'delay' | 'form-submit';
274
+ /**
275
+ * Form types for guide steps
276
+ */
277
+ type GuideFormType = 'nps' | 'rating' | 'text' | 'select' | 'multi-select';
278
+ /**
279
+ * Rich content for guide steps
280
+ */
281
+ interface GuideStepRichContent {
282
+ title?: string;
283
+ body?: string;
284
+ media?: {
285
+ type: 'image' | 'video';
286
+ url: string;
287
+ alt?: string;
288
+ };
289
+ buttons?: Array<{
290
+ label: string;
291
+ action: 'next' | 'prev' | 'dismiss' | 'url' | 'custom';
292
+ url?: string;
293
+ customAction?: string;
294
+ style?: 'primary' | 'secondary' | 'text';
295
+ }>;
296
+ form?: {
297
+ type: GuideFormType;
298
+ question: string;
299
+ options?: string[];
300
+ required?: boolean;
301
+ submitLabel?: string;
302
+ };
303
+ }
304
+ /**
305
+ * Display configuration for guide steps
306
+ */
307
+ interface GuideStepDisplayConfig {
308
+ position?: TooltipPosition | 'center';
309
+ offset?: {
310
+ x: number;
311
+ y: number;
312
+ };
313
+ width?: number;
314
+ backdrop?: boolean;
315
+ spotlightPadding?: number;
316
+ bannerPosition?: 'top' | 'bottom';
317
+ }
318
+ /**
319
+ * Advancement configuration for guide steps
320
+ */
321
+ interface GuideStepAdvanceConfig {
322
+ trigger: AdvanceTrigger;
323
+ delay?: number;
324
+ clickSelector?: string;
325
+ }
326
+ /**
327
+ * Style configuration for guide steps
328
+ */
329
+ interface GuideStepStyleConfig {
330
+ backgroundColor?: string;
331
+ textColor?: string;
332
+ accentColor?: string;
333
+ borderRadius?: number;
334
+ customCSS?: string;
335
+ }
336
+ /**
337
+ * Selector strategy for targeting elements
338
+ */
339
+ interface SelectorStrategy {
340
+ css?: string;
341
+ xpath?: string;
342
+ text?: string;
343
+ testId?: string;
344
+ }
345
+ /**
346
+ * Guide step definition
347
+ */
348
+ interface GuideStep {
349
+ id: string;
350
+ guide_id?: string;
351
+ sort_order: number;
352
+ step_type: GuideStepType;
353
+ selector_strategy: SelectorStrategy | null;
354
+ title: string | null;
355
+ content: string | null;
356
+ tooltip_position: TooltipPosition;
357
+ actions: Array<Record<string, unknown>>;
358
+ wait_for: 'click' | 'next_button' | 'delay' | 'custom';
359
+ wait_config: Record<string, unknown>;
360
+ rich_content: GuideStepRichContent;
361
+ display_config: GuideStepDisplayConfig;
362
+ advance_config: GuideStepAdvanceConfig;
363
+ style_config: GuideStepStyleConfig;
364
+ created_at?: string;
365
+ updated_at?: string;
366
+ }
367
+ /**
368
+ * Guide trigger types
369
+ */
370
+ type GuideTriggerType = 'manual' | 'url_match' | 'first_visit' | 'event';
371
+ /**
372
+ * Guide status
373
+ */
374
+ type GuideStatus = 'draft' | 'published' | 'archived';
375
+ /**
376
+ * Guide definition
377
+ */
378
+ interface Guide {
379
+ id: string;
380
+ name: string;
381
+ slug: string;
382
+ description: string | null;
383
+ trigger_type: GuideTriggerType;
384
+ trigger_config: Record<string, unknown>;
385
+ theme: Record<string, unknown>;
386
+ allow_skip: boolean;
387
+ show_progress: boolean;
388
+ status?: GuideStatus;
389
+ published_at?: string | null;
390
+ created_at?: string;
391
+ updated_at?: string;
392
+ guide_steps: GuideStep[];
393
+ }
394
+ /**
395
+ * Options for creating a guide
396
+ */
397
+ interface CreateGuideOptions {
398
+ /**
399
+ * Name of the guide
400
+ */
401
+ name: string;
402
+ /**
403
+ * URL-friendly slug (lowercase, hyphens only)
404
+ */
405
+ slug: string;
406
+ /**
407
+ * Description of the guide
408
+ */
409
+ description?: string;
410
+ /**
411
+ * Project ID to associate with
412
+ */
413
+ projectId?: string;
414
+ /**
415
+ * When to trigger the guide
416
+ * @default "manual"
417
+ */
418
+ triggerType?: GuideTriggerType;
419
+ /**
420
+ * Configuration for the trigger (e.g., url_pattern for url_match)
421
+ */
422
+ triggerConfig?: Record<string, unknown>;
423
+ /**
424
+ * Theme customization
425
+ */
426
+ theme?: Record<string, unknown>;
427
+ /**
428
+ * Allow users to skip the guide
429
+ * @default true
430
+ */
431
+ allowSkip?: boolean;
432
+ /**
433
+ * Show progress indicator
434
+ * @default true
435
+ */
436
+ showProgress?: boolean;
437
+ }
438
+ /**
439
+ * Options for updating a guide
440
+ */
441
+ interface UpdateGuideOptions {
442
+ name?: string;
443
+ slug?: string;
444
+ description?: string;
445
+ triggerType?: GuideTriggerType;
446
+ triggerConfig?: Record<string, unknown>;
447
+ theme?: Record<string, unknown>;
448
+ allowSkip?: boolean;
449
+ showProgress?: boolean;
450
+ status?: GuideStatus;
451
+ }
452
+ /**
453
+ * Options for creating a guide step
454
+ */
455
+ interface CreateGuideStepOptions {
456
+ /**
457
+ * Type of step
458
+ * @default "tooltip"
459
+ */
460
+ stepType?: GuideStepType;
461
+ /**
462
+ * Order position (auto-assigned if not provided)
463
+ */
464
+ sortOrder?: number;
465
+ /**
466
+ * Element selector strategy
467
+ */
468
+ selectorStrategy?: SelectorStrategy;
469
+ /**
470
+ * Simple title (legacy, use richContent.title instead)
471
+ */
472
+ title?: string;
473
+ /**
474
+ * Simple content (legacy, use richContent.body instead)
475
+ */
476
+ content?: string;
477
+ /**
478
+ * Tooltip position
479
+ * @default "auto"
480
+ */
481
+ tooltipPosition?: TooltipPosition;
482
+ /**
483
+ * Rich content configuration
484
+ */
485
+ richContent?: GuideStepRichContent;
486
+ /**
487
+ * Display configuration
488
+ */
489
+ displayConfig?: GuideStepDisplayConfig;
490
+ /**
491
+ * Advancement configuration
492
+ */
493
+ advanceConfig?: GuideStepAdvanceConfig;
494
+ /**
495
+ * Style overrides
496
+ */
497
+ styleConfig?: GuideStepStyleConfig;
498
+ }
499
+ /**
500
+ * Options for updating a guide step
501
+ */
502
+ interface UpdateGuideStepOptions extends Partial<CreateGuideStepOptions> {
503
+ }
504
+ /**
505
+ * Options for fetching guides
506
+ */
507
+ interface GuidesOptions {
508
+ /**
509
+ * Filter by project ID
510
+ */
511
+ projectId?: string;
512
+ /**
513
+ * Current page URL (for trigger matching)
514
+ */
515
+ url?: string;
516
+ /**
517
+ * User ID (to get completion status)
518
+ */
519
+ userId?: string;
520
+ }
521
+ /**
522
+ * Response from guides list endpoint
523
+ */
524
+ interface GuidesResponse {
525
+ guides: Guide[];
526
+ completedGuides: string[];
527
+ }
232
528
  /**
233
529
  * Position for floating UI elements
234
530
  */
@@ -394,58 +690,6 @@ interface CensusProviderProps {
394
690
  */
395
691
  children: React.ReactNode;
396
692
  }
397
- interface GuideStep {
398
- id: string;
399
- sort_order: number;
400
- selector_strategy: SelectorStrategy;
401
- title: string | null;
402
- content: string | null;
403
- tooltip_position: TooltipPosition;
404
- actions: GuideAction[];
405
- wait_for: WaitForType;
406
- wait_config: Record<string, unknown>;
407
- }
408
- interface SelectorStrategy {
409
- css?: string;
410
- xpath?: string;
411
- text?: string;
412
- testId?: string;
413
- }
414
- type TooltipPosition = 'auto' | 'top' | 'bottom' | 'left' | 'right';
415
- type WaitForType = 'click' | 'next_button' | 'delay' | 'custom';
416
- interface GuideAction {
417
- type: 'click' | 'input' | 'navigate' | 'custom';
418
- config: Record<string, unknown>;
419
- }
420
- interface Guide {
421
- id: string;
422
- name: string;
423
- slug: string;
424
- description: string | null;
425
- trigger_type: GuideTriggerType;
426
- trigger_config: TriggerConfig;
427
- theme: GuideTheme;
428
- allow_skip: boolean;
429
- show_progress: boolean;
430
- guide_steps: GuideStep[];
431
- }
432
- type GuideTriggerType = 'manual' | 'url_match' | 'first_visit' | 'event';
433
- interface TriggerConfig {
434
- url_pattern?: string;
435
- event_name?: string;
436
- delay_ms?: number;
437
- }
438
- interface GuideTheme {
439
- primaryColor?: string;
440
- backgroundColor?: string;
441
- textColor?: string;
442
- borderRadius?: string;
443
- fontFamily?: string;
444
- }
445
- interface GuidesResponse {
446
- guides: Guide[];
447
- completedGuides: string[];
448
- }
449
693
  type GuideEventType = 'started' | 'step_viewed' | 'step_completed' | 'completed' | 'skipped' | 'dismissed';
450
694
  interface GuideAnalyticsEvent {
451
695
  guideId: string;
@@ -457,15 +701,6 @@ interface GuideAnalyticsEvent {
457
701
  userId?: string;
458
702
  metadata?: Record<string, unknown>;
459
703
  }
460
- interface TooltipOptions {
461
- position?: TooltipPosition;
462
- showProgress?: boolean;
463
- showSkip?: boolean;
464
- onNext?: () => void;
465
- onPrev?: () => void;
466
- onSkip?: () => void;
467
- onClose?: () => void;
468
- }
469
704
 
470
705
  /**
471
706
  * Census SDK Client
@@ -577,6 +812,21 @@ declare class CensusClient {
577
812
  * ```
578
813
  */
579
814
  getArticle(slugOrId: string): Promise<Article | null>;
815
+ /**
816
+ * Fetch feature groups with their features.
817
+ * Used by the HelpCenter component for navigation.
818
+ *
819
+ * @returns Feature groups with features and article counts
820
+ *
821
+ * @example
822
+ * ```typescript
823
+ * const { feature_groups } = await census.getFeatureGroups();
824
+ * feature_groups.forEach(group => {
825
+ * console.log(group.name, group.features.length);
826
+ * });
827
+ * ```
828
+ */
829
+ getFeatureGroups(): Promise<FeatureGroupsResponse>;
580
830
  /**
581
831
  * Fetch the current user's submitted requests (feedback, bugs, feature requests).
582
832
  * Requires a user to be identified first.
@@ -631,33 +881,166 @@ declare class CensusClient {
631
881
  */
632
882
  trackBatch(options: BatchEventsOptions): Promise<void>;
633
883
  /**
634
- * Fetch available guides for the current user.
635
- * Returns guides that match the user's context and haven't been completed.
884
+ * Get published guides.
636
885
  *
637
- * @returns Guides and list of completed guide IDs
886
+ * @param options - Query options
887
+ * @returns Guides and completion status
638
888
  *
639
889
  * @example
640
890
  * ```typescript
641
- * const { guides, completedGuides } = await census.getGuides();
642
- * guides.forEach(guide => console.log(guide.name));
891
+ * const { guides, completedGuides } = await census.getGuides({
892
+ * url: window.location.href,
893
+ * userId: 'user_123',
894
+ * });
643
895
  * ```
644
896
  */
645
- getGuides(): Promise<GuidesResponse>;
897
+ getGuides(options?: GuidesOptions): Promise<GuidesResponse>;
646
898
  /**
647
- * Fetch a single guide by slug or ID.
899
+ * Get a single guide by ID.
648
900
  *
649
- * @param slugOrId - Guide slug or ID
650
- * @returns Guide or null if not found
901
+ * @param guideId - Guide ID
902
+ * @returns Guide with steps or null if not found
651
903
  *
652
904
  * @example
653
905
  * ```typescript
654
- * const guide = await census.getGuide('onboarding-tour');
906
+ * const guide = await census.getGuide('guide_123');
655
907
  * if (guide) {
656
908
  * console.log(guide.name, guide.guide_steps.length);
657
909
  * }
658
910
  * ```
659
911
  */
660
- getGuide(slugOrId: string): Promise<Guide | null>;
912
+ getGuide(guideId: string): Promise<Guide | null>;
913
+ /**
914
+ * Create a new guide.
915
+ * Requires guides:create or guides:admin scope.
916
+ *
917
+ * @param options - Guide creation options
918
+ * @returns Created guide
919
+ *
920
+ * @example
921
+ * ```typescript
922
+ * const guide = await census.createGuide({
923
+ * name: 'Welcome Tour',
924
+ * slug: 'welcome-tour',
925
+ * description: 'Introduction to the app',
926
+ * triggerType: 'first_visit',
927
+ * });
928
+ * ```
929
+ */
930
+ createGuide(options: CreateGuideOptions): Promise<Guide>;
931
+ /**
932
+ * Update an existing guide.
933
+ * Requires guides:create or guides:admin scope.
934
+ *
935
+ * @param guideId - Guide ID to update
936
+ * @param options - Update options
937
+ * @returns Updated guide
938
+ *
939
+ * @example
940
+ * ```typescript
941
+ * const guide = await census.updateGuide('guide_123', {
942
+ * name: 'Updated Tour Name',
943
+ * status: 'published',
944
+ * });
945
+ * ```
946
+ */
947
+ updateGuide(guideId: string, options: UpdateGuideOptions): Promise<Guide>;
948
+ /**
949
+ * Delete a guide.
950
+ * Requires guides:admin scope.
951
+ *
952
+ * @param guideId - Guide ID to delete
953
+ *
954
+ * @example
955
+ * ```typescript
956
+ * await census.deleteGuide('guide_123');
957
+ * ```
958
+ */
959
+ deleteGuide(guideId: string): Promise<void>;
960
+ /**
961
+ * Get steps for a guide.
962
+ *
963
+ * @param guideId - Guide ID
964
+ * @returns Array of steps
965
+ *
966
+ * @example
967
+ * ```typescript
968
+ * const steps = await census.getGuideSteps('guide_123');
969
+ * ```
970
+ */
971
+ getGuideSteps(guideId: string): Promise<GuideStep[]>;
972
+ /**
973
+ * Add a step to a guide.
974
+ * Requires guides:create or guides:admin scope.
975
+ *
976
+ * @param guideId - Guide ID
977
+ * @param options - Step creation options
978
+ * @returns Created step
979
+ *
980
+ * @example
981
+ * ```typescript
982
+ * const step = await census.addGuideStep('guide_123', {
983
+ * stepType: 'tooltip',
984
+ * selectorStrategy: { css: '.welcome-button' },
985
+ * richContent: {
986
+ * title: 'Welcome!',
987
+ * body: 'Click here to get started',
988
+ * },
989
+ * });
990
+ * ```
991
+ */
992
+ addGuideStep(guideId: string, options: CreateGuideStepOptions): Promise<GuideStep>;
993
+ /**
994
+ * Update a guide step.
995
+ * Requires guides:create or guides:admin scope.
996
+ *
997
+ * @param guideId - Guide ID
998
+ * @param stepId - Step ID
999
+ * @param options - Update options
1000
+ * @returns Updated step
1001
+ *
1002
+ * @example
1003
+ * ```typescript
1004
+ * const step = await census.updateGuideStep('guide_123', 'step_456', {
1005
+ * richContent: { title: 'Updated title' },
1006
+ * });
1007
+ * ```
1008
+ */
1009
+ updateGuideStep(guideId: string, stepId: string, options: UpdateGuideStepOptions): Promise<GuideStep>;
1010
+ /**
1011
+ * Delete a guide step.
1012
+ * Requires guides:create or guides:admin scope.
1013
+ *
1014
+ * @param guideId - Guide ID
1015
+ * @param stepId - Step ID
1016
+ *
1017
+ * @example
1018
+ * ```typescript
1019
+ * await census.deleteGuideStep('guide_123', 'step_456');
1020
+ * ```
1021
+ */
1022
+ deleteGuideStep(guideId: string, stepId: string): Promise<void>;
1023
+ /**
1024
+ * Reorder steps in a guide.
1025
+ * Requires guides:create or guides:admin scope.
1026
+ *
1027
+ * @param guideId - Guide ID
1028
+ * @param stepOrder - Array of { id, sort_order } to define new order
1029
+ * @returns Updated steps
1030
+ *
1031
+ * @example
1032
+ * ```typescript
1033
+ * const steps = await census.reorderGuideSteps('guide_123', [
1034
+ * { id: 'step_a', sort_order: 0 },
1035
+ * { id: 'step_b', sort_order: 1 },
1036
+ * { id: 'step_c', sort_order: 2 },
1037
+ * ]);
1038
+ * ```
1039
+ */
1040
+ reorderGuideSteps(guideId: string, stepOrder: Array<{
1041
+ id: string;
1042
+ sort_order: number;
1043
+ }>): Promise<GuideStep[]>;
661
1044
  /**
662
1045
  * Track a guide analytics event.
663
1046
  * Used to track user progress through guides.
@@ -723,4 +1106,4 @@ declare class CensusClient {
723
1106
  */
724
1107
  declare function createCensus(config: CensusConfig): CensusClient;
725
1108
 
726
- export { type Article, type ArticlesOptions, type ArticlesResponse, type BatchEventsOptions, CensusClient, type CensusConfig, type CensusError, type CensusProviderProps, type CensusTheme, type FeedbackButtonProps, type FeedbackOptions, type FeedbackType, type Guide, type GuideAction, type GuideAnalyticsEvent, type GuideEventType, type GuideStep, type GuideTheme, type GuideTriggerType, type GuidesResponse, type KnowledgeBaseProps, type Position, type Request, type RequestsOptions, type RequestsProps, type RequestsResponse, type SelectorStrategy, type TooltipOptions, type TooltipPosition, type TrackEventOptions, type TriggerConfig, type UserIdentity, type WaitForType, createCensus };
1109
+ export { type AdvanceTrigger, type Article, type ArticlesOptions, type ArticlesResponse, type BatchEventsOptions, CensusClient, type CensusConfig, type CensusError, type CensusProviderProps, type CensusTheme, type CreateGuideOptions, type CreateGuideStepOptions, type FeedbackButtonProps, type FeedbackOptions, type FeedbackType, type Guide, type GuideAnalyticsEvent, type GuideEventType, type GuideFormType, type GuideStatus, type GuideStep, type GuideStepAdvanceConfig, type GuideStepDisplayConfig, type GuideStepRichContent, type GuideStepStyleConfig, type GuideStepType, type GuideTriggerType, type GuidesOptions, type GuidesResponse, type KnowledgeBaseProps, type Position, type Request, type RequestsOptions, type RequestsProps, type RequestsResponse, type SelectorStrategy, type TooltipPosition, type TrackEventOptions, type UpdateGuideOptions, type UpdateGuideStepOptions, type UserIdentity, createCensus };