@aikaara/chat-sdk 0.7.2 → 0.7.6

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
@@ -407,6 +407,9 @@ export declare interface ChatEvents {
407
407
 
408
408
  export declare function clearPersistedConversationId(userId: string, projectId: string): void;
409
409
 
410
+ /** Read every credential listed in `spec`. Throws on missing required. */
411
+ export declare function collectSsoCredentials(opts: SsoCollectorOptions): Promise<Record<string, string>>;
412
+
410
413
  export declare interface ConnectionConfig {
411
414
  baseUrl: string;
412
415
  wsUrl?: string;
@@ -473,6 +476,8 @@ export declare function createPresigned3StepUploadAdapter(config: Presigned3Step
473
476
 
474
477
  export declare function createTiledeskHistoryAdapter(config: TiledeskHistoryAdapterConfig): ConversationHistoryAdapter;
475
478
 
479
+ export declare type CredentialProviders = Record<string, () => string | Promise<string>>;
480
+
476
481
  export declare interface EditEntityAction {
477
482
  action: 'edit_entity';
478
483
  entity_type: string;
@@ -506,6 +511,34 @@ export declare interface FieldUpdate {
506
511
  previousValue?: unknown;
507
512
  }
508
513
 
514
+ export declare interface FlowDescriptor {
515
+ /** Heading rendered above the step list (e.g. "ITR filing process"). */
516
+ title?: string;
517
+ steps: FlowStep[];
518
+ }
519
+
520
+ /**
521
+ * Static side-rail process taxonomy (e.g. bandhan's "ITR filing process").
522
+ * Fully descriptor-driven — dashboard owns the steps. The runtime state
523
+ * (which step is `done` / `active`) is calculated host-side from chat
524
+ * events (or overlaid from a backend status endpoint like
525
+ * `/itr/life-cycle-status`).
526
+ */
527
+ export declare interface FlowStep {
528
+ /** Stable id used by the host's reducer to address this step. */
529
+ id: string;
530
+ /** Display title. */
531
+ title: string;
532
+ /** Initial status. The host's `onMessage` reducer flips these as the
533
+ * conversation progresses. */
534
+ state?: 'done' | 'active' | 'pending';
535
+ /** Optional nested sub-steps (one level deep — bandhan style). */
536
+ sub?: FlowStep[];
537
+ /** Free-form metadata the host can use in its reducer (templateId
538
+ * patterns the bot uses to advance the step, copy text, hint, etc.). */
539
+ meta?: Record<string, unknown>;
540
+ }
541
+
509
542
  export declare class FormBridge extends EventEmitter<FormBridgeEvents> {
510
543
  private registration;
511
544
  private pendingEdits;
@@ -635,7 +668,7 @@ export declare function isTiledeskSelfEcho(message: TiledeskMessage, userId: str
635
668
  * Descriptor entry for intercepting link clicks. `match` is a glob pattern
636
669
  * (`*` = any, `?` = single char) tested against the full clicked URL.
637
670
  */
638
- declare interface LinkHandler {
671
+ export declare interface LinkHandler {
639
672
  /** Glob pattern matched against the clicked URL. */
640
673
  match: string;
641
674
  /** What to do on match. `tab` opens in new tab, `iframe` uses default modal,
@@ -763,7 +796,7 @@ export declare function parseTiledeskTemplate(message: TiledeskMessage): Tiledes
763
796
  * One HTTP call run by the SDK before auth. Failure of `soft: true` steps
764
797
  * is logged and ignored; failure of strict steps aborts the mount.
765
798
  */
766
- declare interface PreflightStep {
799
+ export declare interface PreflightStep {
767
800
  url: string;
768
801
  method?: 'GET' | 'POST' | 'PUT';
769
802
  body?: Record<string, unknown>;
@@ -823,6 +856,16 @@ export declare class SessionAuthAdapter {
823
856
  /** Force-refresh by clearing cache. Next `get()` call refetches. */
824
857
  reset(): void;
825
858
  get(): Promise<SessionAuthData>;
859
+ /**
860
+ * Backend often races on first signup — `/chatbuddy/auth?serviceType=ITR`
861
+ * returns 500 with `customerNew is null` for 5–30 seconds after the
862
+ * partner-user-onboard call resolves. The data does land eventually;
863
+ * retry with exponential backoff before bubbling the error up so the
864
+ * SDK doesn't need to wait by hand. Each retry burns through the
865
+ * preflight chain too (via the host's `runPreflight` re-invocation),
866
+ * but the cache makes that cheap.
867
+ */
868
+ private static readonly RETRY_DELAYS_MS;
826
869
  private fetchOnce;
827
870
  }
828
871
 
@@ -874,6 +917,9 @@ export declare type SessionTokenProvider = string | (() => string | Promise<stri
874
917
 
875
918
  export declare interface SlugMountedWidget extends MountedTenantWidget {
876
919
  fullName: string;
920
+ /** Resolved descriptor (fallback ⊕ fetched ⊕ overrides). Host reads
921
+ * `descriptor.itrFlow`, `descriptor.theme`, etc. */
922
+ descriptor: WidgetConfigDescriptor;
877
923
  /** Force a fresh /chatbuddy/auth-style refetch (clears cached requestId). */
878
924
  refreshAuth(): Promise<void>;
879
925
  }
@@ -888,6 +934,12 @@ export declare interface SlugMountOptions {
888
934
  /** Additional headers for the descriptor fetch. */
889
935
  configHeaders?: Record<string, string>;
890
936
  user: {
937
+ /**
938
+ * Initial identifier. When `descriptor.sso` is configured, the
939
+ * server-issued `ext_uid` from the SSO exchange overrides this
940
+ * value. For SSO-only flows you can pass an empty string and rely
941
+ * on the exchange to populate the identity.
942
+ */
891
943
  id: string;
892
944
  /** Display name fallback when descriptor.auth doesn't return one. */
893
945
  name?: string;
@@ -898,12 +950,31 @@ export declare interface SlugMountOptions {
898
950
  * or a getter that re-resolves on each refresh.
899
951
  */
900
952
  token: SessionTokenProvider;
953
+ /**
954
+ * Async getters for SSO credentials with `source: "callback"`. Each
955
+ * key matches a `descriptor.sso.collect[].name` entry. Lets the host
956
+ * app supply tokens that don't live in cookies / localStorage (e.g.
957
+ * an in-memory auth context, a parent-frame postMessage).
958
+ */
959
+ credentialProviders?: CredentialProviders;
960
+ /**
961
+ * Free-form identity bag forwarded to descriptor.preflight URL and
962
+ * body templates. Keys become `{name}` placeholders. Useful for
963
+ * tenant-specific fields the SDK doesn't know about (`pan`, `mobile`,
964
+ * `dob`, etc.) so the descriptor can drive the full warm-up chain
965
+ * without host code per call.
966
+ */
967
+ identity?: Record<string, string | undefined>;
901
968
  };
902
969
  /** Optional escape hatches; merge over descriptor-driven defaults. */
903
970
  hooks?: {
904
971
  upload?: UploadAdapter;
905
972
  history?: ConversationHistoryAdapter;
906
973
  onError?: (err: Error) => void;
974
+ /** Fired for every chat message (incoming + outgoing). Host apps can
975
+ * use this to advance UI state outside the widget — e.g. update an
976
+ * ITR-filing-process side rail when the bot moves the flow forward. */
977
+ onMessage?: (message: Message) => void;
907
978
  };
908
979
  /** Per-mount visual overrides. */
909
980
  overrides?: Partial<WidgetConfigDescriptor>;
@@ -916,6 +987,105 @@ export declare interface SlugMountOptions {
916
987
  fallbackConfig?: WidgetConfigDescriptor;
917
988
  }
918
989
 
990
+ export declare interface SsoCollectorOptions {
991
+ /** Spec from `descriptor.sso.collect`. */
992
+ spec: SsoCollectSpec[];
993
+ /** Async getters for `source: "callback"` entries (host-supplied). */
994
+ providers?: CredentialProviders;
995
+ }
996
+
997
+ export declare interface SsoCollectSpec {
998
+ /** Field name sent to aikaara-ai as `credentials[name]`. */
999
+ name: string;
1000
+ /** Where to read it from. */
1001
+ source: SsoSourceKind;
1002
+ /** Source-specific key (cookie name, storage key, query param, etc). */
1003
+ key?: string;
1004
+ /** When true, throw if the credential is absent / empty. */
1005
+ required?: boolean;
1006
+ /** Default value if the source doesn't provide one (and not required). */
1007
+ default?: string;
1008
+ }
1009
+
1010
+ export declare interface SsoDescriptor {
1011
+ /**
1012
+ * Aikaara-ai endpoint that runs the server-side SSO + provisioning chain.
1013
+ * Optional — when omitted the SDK derives it from the same `configBase`
1014
+ * it used to fetch `widget_configs/:slug`:
1015
+ * `${configBase}/api/v1/projects/by-slug/${slug}/sso_exchange`
1016
+ * Set this only when self-hosted aikaara-ai sits at a different host
1017
+ * than the widget-config endpoint.
1018
+ */
1019
+ exchangeEndpoint?: string;
1020
+ /** localStorage key for the cached identity. Null/empty → no cache. */
1021
+ cacheKey?: string;
1022
+ /** Cache TTL in seconds. Default 1800 (30 min). */
1023
+ cacheTtlSec?: number;
1024
+ /** Per-widget API key sent as `X-Api-Key` to aikaara-ai. */
1025
+ apiKey?: string;
1026
+ /** Extra static headers attached to the exchange POST. */
1027
+ headers?: Record<string, string>;
1028
+ /** Browser credential collection spec. */
1029
+ collect: SsoCollectSpec[];
1030
+ }
1031
+
1032
+ export declare class SsoExchangeAdapter {
1033
+ private readonly opts;
1034
+ private cache;
1035
+ private inflight;
1036
+ constructor(opts: SsoExchangeOptions);
1037
+ /** Drop any cached identity. Forces a fresh exchange on next `get()`. */
1038
+ reset(): void;
1039
+ /**
1040
+ * Resolve the SSO identity. Returns cached when fresh; otherwise runs the
1041
+ * collect → POST → response flow once and caches the result.
1042
+ */
1043
+ get(force?: boolean): Promise<SsoIdentity>;
1044
+ private exchange;
1045
+ private computeExpiry;
1046
+ private loadCache;
1047
+ private persistCache;
1048
+ private clearCache;
1049
+ }
1050
+
1051
+ export declare interface SsoExchangeOptions {
1052
+ descriptor: SsoDescriptor;
1053
+ /** Host-supplied async getters for `source: "callback"` entries. */
1054
+ providers?: CredentialProviders;
1055
+ /**
1056
+ * Resolved exchange URL. When `descriptor.exchangeEndpoint` is set it
1057
+ * wins; otherwise `mountFromSlug` builds this from
1058
+ * `${configBase}/api/v1/projects/by-slug/${slug}/sso_exchange`.
1059
+ */
1060
+ exchangeUrl?: string;
1061
+ }
1062
+
1063
+ export declare interface SsoIdentity {
1064
+ /** Aikaara `User.id` (UUID/int). Useful for support / audit. */
1065
+ id?: string | number;
1066
+ /** Partner system user id, mirrored as Aikaara `User.ext_uid`. */
1067
+ extUid: string;
1068
+ /** Aikaara user token (ActionCable / Aikaara REST bearer). */
1069
+ userToken: string;
1070
+ email?: string;
1071
+ displayName?: string;
1072
+ /** Free-form properties the provisioner wrote on the user row. */
1073
+ properties?: Record<string, unknown>;
1074
+ /** Unix-ms expiry for the cache row (not the token itself). */
1075
+ expiresAt?: number;
1076
+ }
1077
+
1078
+ /**
1079
+ * Browser-side credential collector for `descriptor.sso.collect`.
1080
+ *
1081
+ * Each entry tells the SDK where to read one credential from. The collected
1082
+ * map gets POSTed to aikaara-ai's `sso_exchange` endpoint, where the
1083
+ * server-side resolver swaps it for a partner identity + provisions an
1084
+ * Aikaara user. No secrets ever live in the public descriptor — this just
1085
+ * tells us "go look at cookie X" or "ask the host app for token Y".
1086
+ */
1087
+ export declare type SsoSourceKind = 'cookie' | 'localStorage' | 'sessionStorage' | 'url_param' | 'header_meta' | 'callback';
1088
+
919
1089
  declare type SubscriptionCallback = (data: unknown) => void;
920
1090
 
921
1091
  declare interface TemplateMessageEvent {
@@ -964,8 +1134,17 @@ export declare interface TenantMountOptions {
964
1134
  overrides?: Partial<WidgetConfigDescriptor>;
965
1135
  /** Surfaced from the SDK. */
966
1136
  onError?: (err: Error) => void;
1137
+ /** Forwarded to `WidgetConfig.onMessage` — fires for every message. */
1138
+ onMessage?: (message: Message) => void;
967
1139
  /** Bearer source for descriptor.linkHandlers fetches. */
968
1140
  getLinkBearer?: (source: 'session' | 'chat' | 'none') => Promise<string | null>;
1141
+ /**
1142
+ * Aikaara user token used by the ActionCable transport
1143
+ * (`?token=<userToken>` on the cable URL). Comes from the SSO exchange
1144
+ * when present. Tiledesk-only widgets ignore it; defaults to `userId`
1145
+ * for backwards compatibility.
1146
+ */
1147
+ userToken?: string;
969
1148
  }
970
1149
 
971
1150
  export declare interface TestToolAction {
@@ -1329,6 +1508,12 @@ export declare interface WidgetConfigDescriptor {
1329
1508
  };
1330
1509
  /** Defaults merged into every form-action postback */
1331
1510
  templateActionAttributes?: Record<string, unknown>;
1511
+ /**
1512
+ * Static side-rail flow (e.g. bandhan's "ITR filing process"). The
1513
+ * dashboard owns this — host renders it next to the chat. Live state
1514
+ * is overlaid by host code from chat events / status endpoints.
1515
+ */
1516
+ itrFlow?: FlowDescriptor;
1332
1517
  /** Adapter endpoints — SDK builds the actual fetch calls */
1333
1518
  uploadEndpoint?: string;
1334
1519
  uploadFieldName?: string;
@@ -1347,6 +1532,17 @@ export declare interface WidgetConfigDescriptor {
1347
1532
  * itself — the host app no longer needs a `tokenProvider` callback.
1348
1533
  */
1349
1534
  auth?: SessionAuthDescriptor;
1535
+ /**
1536
+ * Aikaara-ai-side SSO + provisioning. When present, the SDK collects the
1537
+ * partner credentials listed in `sso.collect`, POSTs them to
1538
+ * `sso.exchangeEndpoint`, and aikaara-ai resolves a partner identity +
1539
+ * provisions an Aikaara user. The returned `ext_uid` overrides
1540
+ * `opts.user.id` and the returned `userToken` populates
1541
+ * `widgetConfig.userToken` (used by the ActionCable transport). This
1542
+ * runs **before** `auth` — so partner SSO seeds the identity, then
1543
+ * `auth` mints chat-platform JWTs against that identity.
1544
+ */
1545
+ sso?: SsoDescriptor;
1350
1546
  /**
1351
1547
  * HTTP calls fired in order before `auth`. Use for backend warmups whose
1352
1548
  * side effects the auth call depends on (e.g. bandhan's bootstrap
@@ -1416,7 +1612,7 @@ export declare interface WidgetConfigDescriptor {
1416
1612
  * (`--aikaara-<kebab-cased-key>`), so renderers (built-in or
1417
1613
  * tenant-supplied) can style themselves consistently.
1418
1614
  */
1419
- declare interface WidgetTheme {
1615
+ export declare interface WidgetTheme {
1420
1616
  primary?: string;
1421
1617
  primaryHover?: string;
1422
1618
  primaryContrast?: string;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { r as o } from "./MountTenant-Bdm9wkBa.mjs";
2
- import { A as u, a as m, b as g, c as h, d as k, e as A, f as C, g as b, h as f, i as T, j as v, k as S, C as w, l as y, m as M, E, M as x, S as B, T as F, n as U, o as I, p as j, q, s as H, t as P, u as W, v as K, w as L, x as O } from "./MountTenant-Bdm9wkBa.mjs";
3
- import { FormBridge as z } from "./headless.mjs";
1
+ import { r as o } from "./MountTenant-DK039M0S.mjs";
2
+ import { A as u, a as m, b as g, c as h, d as k, e as A, f as C, g as b, h as f, i as S, j as T, k as v, C as y, l as w, m as M, E, M as x, S as B, n as F, T as U, o as I, p as j, q, s as H, t as P, u as W, v as z, w as K, x as L, y as O, z as R } from "./MountTenant-DK039M0S.mjs";
3
+ import { FormBridge as G } from "./headless.mjs";
4
4
  function l(e) {
5
5
  o();
6
6
  const a = document.createElement("aikaara-chat-widget"), r = {
@@ -38,28 +38,30 @@ export {
38
38
  C as AikaaraErrorBanner,
39
39
  b as AikaaraMessageBubble,
40
40
  f as AikaaraMessageList,
41
- T as AikaaraStreamingMessage,
42
- v as AikaaraTypingIndicator,
43
- S as ApiClient,
44
- w as ChannelSubscription,
45
- y as ConnectionManager,
41
+ S as AikaaraStreamingMessage,
42
+ T as AikaaraTypingIndicator,
43
+ v as ApiClient,
44
+ y as ChannelSubscription,
45
+ w as ConnectionManager,
46
46
  M as ConversationManager,
47
47
  E as EventEmitter,
48
- z as FormBridge,
48
+ G as FormBridge,
49
49
  x as MessageStore,
50
50
  B as SessionAuthAdapter,
51
- F as TiledeskTransport,
52
- U as clearPersistedConversationId,
53
- I as createFetchUploadAdapter,
54
- j as createPresigned3StepUploadAdapter,
55
- q as createTiledeskHistoryAdapter,
56
- H as extractTiledeskFileEnvelope,
57
- P as inferTiledeskRole,
58
- W as isTiledeskSelfEcho,
51
+ F as SsoExchangeAdapter,
52
+ U as TiledeskTransport,
53
+ I as clearPersistedConversationId,
54
+ j as collectSsoCredentials,
55
+ q as createFetchUploadAdapter,
56
+ H as createPresigned3StepUploadAdapter,
57
+ P as createTiledeskHistoryAdapter,
58
+ W as extractTiledeskFileEnvelope,
59
+ z as inferTiledeskRole,
60
+ K as isTiledeskSelfEcho,
59
61
  l as mount,
60
- K as mountFromSlug,
61
- L as mountTenantWidget,
62
- O as parseTiledeskTemplate,
62
+ L as mountFromSlug,
63
+ O as mountTenantWidget,
64
+ R as parseTiledeskTemplate,
63
65
  o as registerComponents,
64
66
  d as unmount
65
67
  };
package/dist/ui.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./MountTenant-BNpG6T7E.cjs");exports.AikaaraChat=a.AikaaraChat;exports.AikaaraChatBubble=a.AikaaraChatBubble;exports.AikaaraChatHeader=a.AikaaraChatHeader;exports.AikaaraChatInput=a.AikaaraChatInput;exports.AikaaraChatWidget=a.AikaaraChatWidget;exports.AikaaraComparePlans=a.AikaaraComparePlans;exports.AikaaraErrorBanner=a.AikaaraErrorBanner;exports.AikaaraLinkModal=a.AikaaraLinkModal;exports.AikaaraMessageBubble=a.AikaaraMessageBubble;exports.AikaaraMessageList=a.AikaaraMessageList;exports.AikaaraModalAction=a.AikaaraModalAction;exports.AikaaraOptionList=a.AikaaraOptionList;exports.AikaaraStreamingMessage=a.AikaaraStreamingMessage;exports.AikaaraSubmitAction=a.AikaaraSubmitAction;exports.AikaaraSystemPill=a.AikaaraSystemPill;exports.AikaaraTemplateRenderer=a.AikaaraTemplateRenderer;exports.AikaaraTypingIndicator=a.AikaaraTypingIndicator;exports.registerComponents=a.registerComponents;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./MountTenant-CTSUKHmw.cjs");exports.AikaaraChat=a.AikaaraChat;exports.AikaaraChatBubble=a.AikaaraChatBubble;exports.AikaaraChatHeader=a.AikaaraChatHeader;exports.AikaaraChatInput=a.AikaaraChatInput;exports.AikaaraChatWidget=a.AikaaraChatWidget;exports.AikaaraComparePlans=a.AikaaraComparePlans;exports.AikaaraErrorBanner=a.AikaaraErrorBanner;exports.AikaaraLinkModal=a.AikaaraLinkModal;exports.AikaaraMessageBubble=a.AikaaraMessageBubble;exports.AikaaraMessageList=a.AikaaraMessageList;exports.AikaaraModalAction=a.AikaaraModalAction;exports.AikaaraOptionList=a.AikaaraOptionList;exports.AikaaraStreamingMessage=a.AikaaraStreamingMessage;exports.AikaaraSubmitAction=a.AikaaraSubmitAction;exports.AikaaraSystemPill=a.AikaaraSystemPill;exports.AikaaraTemplateRenderer=a.AikaaraTemplateRenderer;exports.AikaaraTypingIndicator=a.AikaaraTypingIndicator;exports.registerComponents=a.registerComponents;
package/dist/ui.d.ts CHANGED
@@ -22,6 +22,19 @@ export declare class AikaaraChat extends HTMLElement {
22
22
  static get observedAttributes(): string[];
23
23
  /** Set programmatically when the session token must be refreshed dynamically. */
24
24
  tokenGetter?: () => string | Promise<string>;
25
+ /** Per-widget API key sent as `X-Api-Key` to aikaara-ai. Either set this
26
+ * property OR pass the `api-key` attribute. Required by hosted aikaara
27
+ * backends that gate `widget_configs/:slug`. */
28
+ apiKey?: string;
29
+ /** Extra headers attached to the descriptor fetch. Set via JS property
30
+ * for callers (Flutter / Vue / etc.) that prefer property-style config.
31
+ * Merged on top of the auto-added `X-Api-Key` from `apiKey` / `api-key`. */
32
+ configHeaders?: Record<string, string>;
33
+ /** Free-form identity bag forwarded to descriptor.preflight URL + body
34
+ * templates as `{name}` placeholders. */
35
+ identity?: Record<string, string | undefined>;
36
+ /** Async credential providers for `descriptor.sso.collect[].source = "callback"`. */
37
+ credentialProviders?: Record<string, () => string | Promise<string>>;
25
38
  private mounted;
26
39
  private mountInflight;
27
40
  connectedCallback(): void;
package/dist/ui.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { y as i, a as s, c as e, d as t, e as A, z as k, f as n, B as o, g, h as l, D as d, F as m, i as p, G as C, H as h, I as b, j as M, r as c } from "./MountTenant-Bdm9wkBa.mjs";
1
+ import { B as i, a as s, c as e, d as t, e as A, D as k, f as n, F as o, g, h as l, G as d, H as m, i as p, I as C, J as h, K as b, j as M, r as c } from "./MountTenant-DK039M0S.mjs";
2
2
  export {
3
3
  i as AikaaraChat,
4
4
  s as AikaaraChatBubble,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikaara/chat-sdk",
3
- "version": "0.7.2",
3
+ "version": "0.7.6",
4
4
  "type": "module",
5
5
  "description": "Aikaara Chat SDK — embeddable chat widget and headless client",
6
6
  "license": "MIT",