@ai4b-team/fsaos-gateway-sdk 3.26.0 → 3.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/iife/ui.js CHANGED
@@ -1,3 +1,3 @@
1
- /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-08-30T23:41:03.565Z */
1
+ /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-09-06T15:05:48.892Z */
2
2
  "use strict";var __FSAOS_UI__=(()=>{var m=Object.create;var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var y=(e,i)=>()=>(i||e((i={exports:{}}).exports,i),i.exports),N=(e,i)=>{for(var a in i)r(e,a,{get:i[a],enumerable:!0})},s=(e,i,a,l)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of u(i))!h.call(e,t)&&t!==a&&r(e,t,{get:()=>i[t],enumerable:!(l=g(i,t))||l.enumerable});return e};var x=(e,i,a)=>(a=e!=null?m(f(e)):{},s(i||!e||!e.__esModule?r(a,"default",{value:e,enumerable:!0}):a,e)),b=e=>s(r({},"__esModule",{value:!0}),e);var d=y((V,c)=>{c.exports=React});var P={};N(P,{Badge:()=>z,Breadcrumbs:()=>A,Button:()=>D,Card:()=>w,DataView:()=>R,Detail:()=>_,Empty:()=>I,FilePreview:()=>O,Form:()=>F,Grid:()=>k,Image:()=>G,Link:()=>E,Page:()=>v,Router:()=>T,Sidebar:()=>S,Spinner:()=>B,Stack:()=>C,Table:()=>j,Tabs:()=>W,Video:()=>H});var n=x(d(),1);function o(){return(typeof window<"u"&&window.__FSAOS_CONFIG__||{}).edgeBaseUrl||""}function v(e){return(0,n.createElement)("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column"},className:e.className||""},e.children)}function C(e){let i=e.direction||"vertical";return(0,n.createElement)("div",{style:{display:"flex",flexDirection:i==="horizontal"?"row":"column",gap:e.gap||"0.5rem",padding:e.padding||"0",alignItems:e.align||"stretch",justifyContent:e.justify||"flex-start",flex:e.flex||"initial"},className:e.className||""},e.children)}function k(e){return(0,n.createElement)("div",{style:{display:"grid",gridTemplateColumns:"repeat("+(e.columns||3)+", 1fr)",gap:e.gap||"1rem",padding:e.padding||"0"},className:e.className||""},e.children)}function S(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"row",minHeight:"100vh"},className:e.className||""},e.children)}function w(e){return(0,n.createElement)("div",{style:{border:"1px solid var(--color-border, #e5e7eb)",borderRadius:"var(--border-radius, 0.5rem)",padding:e.padding||"1rem",background:"var(--color-surface, #fff)"},className:e.className||"",onClick:e.onClick},e.children)}function z(e){return(0,n.createElement)("span",{style:{display:"inline-flex",alignItems:"center",padding:"0.125rem 0.5rem",fontSize:"0.75rem",fontWeight:"500",borderRadius:"9999px",background:e.color||"#e5e7eb",color:e.textColor||"#374151"},className:e.className||""},e.children||e.label)}function B(e){let i=e.size||"1.5rem";return(0,n.createElement)("div",{style:{width:i,height:i,border:"2px solid #e5e7eb",borderTopColor:"var(--color-primary, #3b82f6)",borderRadius:"50%",animation:"fsaos-spin 0.6s linear infinite"}})}function D(e){return(0,n.createElement)("button",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:"500",borderRadius:"var(--border-radius, 0.375rem)",border:e.variant==="outline"?"1px solid var(--color-border, #d1d5db)":"none",background:e.variant==="outline"||e.variant==="ghost"?"transparent":"var(--color-primary, #3b82f6)",color:e.variant==="outline"||e.variant==="ghost"?"var(--color-text, #1a1a1a)":"#fff",cursor:e.disabled?"not-allowed":"pointer",opacity:e.disabled?"0.5":"1",gap:"0.5rem"},className:e.className||"",onClick:e.onClick,disabled:e.disabled},e.children||e.label)}function I(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"3rem",color:"var(--color-text-secondary, #6b7280)",textAlign:"center"}},e.icon?(0,n.createElement)("div",{style:{fontSize:"2rem",marginBottom:"0.5rem"}},e.icon):null,(0,n.createElement)("div",{style:{fontWeight:500,marginBottom:"0.25rem"}},e.title||e.message||e.children||"No items"),e.description?(0,n.createElement)("div",{style:{fontSize:"0.875rem",opacity:.7}},e.description):null)}function R(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function j(e){return(0,n.createElement)("table",{className:e.className||""},e.children)}function F(e){return(0,n.createElement)("form",{className:e.className||"",onSubmit:e.onSubmit},e.children)}function _(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function T(e){return(0,n.createElement)("div",null,e.children)}function E(e){return(0,n.createElement)("a",{href:e.href||e.to,className:e.className||"",onClick:e.onClick},e.children)}function W(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function A(e){return(0,n.createElement)("nav",{className:e.className||""},e.children)}function G(e){return(0,n.createElement)("img",{src:e.src||(e.path?o()+e.path:""),alt:e.alt||"",className:e.className||"",style:e.style})}function H(e){return(0,n.createElement)("video",{src:e.src||(e.path?o()+e.path:""),controls:!0,className:e.className||""})}function O(e){return(0,n.createElement)("div",{className:e.className||""},e.children||"File preview")}return b(P);})();
3
3
  //# sourceMappingURL=ui.js.map
package/dist/index.cjs CHANGED
@@ -43,6 +43,7 @@ __export(src_exports, {
43
43
  ComponentRenderer: () => ComponentRenderer,
44
44
  EnforcementDeniedError: () => EnforcementDeniedError,
45
45
  FormSubmissionError: () => FormSubmissionError,
46
+ GatewayRequestError: () => GatewayRequestError,
46
47
  InteractionTrackingError: () => InteractionTrackingError,
47
48
  KernelProvider: () => KernelProvider,
48
49
  QueryClientProvider: () => reactQuery.QueryClientProvider,
@@ -679,6 +680,15 @@ function trackAction(actionId, properties = {}, options = {}) {
679
680
  const adapterProperties = adapter.id_property ? { [adapter.id_property]: actionId } : {};
680
681
  return trackEvent(adapter.observation, { ...properties, ...adapterProperties }, { ...options, source: source.id });
681
682
  }
683
+ function formAttribution() {
684
+ try {
685
+ const source = publicSource();
686
+ adapterFor("form_receipt", source);
687
+ return { visitor_id: visitorId(source), session_id: sessionId(source), source: source.id };
688
+ } catch {
689
+ return void 0;
690
+ }
691
+ }
682
692
  function trackFormReceipt(properties, options = {}) {
683
693
  const source = publicSource(options.source);
684
694
  const adapter = adapterFor("form_receipt", source);
@@ -793,6 +803,26 @@ var ANCHOR_INDEPENDENT_METHODS = /* @__PURE__ */ new Set([
793
803
  "list-memberships",
794
804
  "init"
795
805
  ]);
806
+ var GatewayRequestError = class extends Error {
807
+ name = "GatewayRequestError";
808
+ method;
809
+ status;
810
+ statusText;
811
+ payload;
812
+ responseBody;
813
+ constructor(options) {
814
+ const code = typeof options.payload?.error === "string" ? options.payload.error.trim() : "";
815
+ const detail = typeof options.payload?.message === "string" ? options.payload.message.trim() : "";
816
+ const fallback = options.responseBody.trim() || `Gateway HTTP error: ${options.status} ${options.statusText}`.trim();
817
+ const message = code && detail ? `${code}: ${detail}` : detail || code || fallback;
818
+ super(message);
819
+ this.method = options.method;
820
+ this.status = options.status;
821
+ this.statusText = options.statusText;
822
+ this.payload = options.payload;
823
+ this.responseBody = options.responseBody;
824
+ }
825
+ };
796
826
  async function gatewayCall(method, params = {}) {
797
827
  const hostname = getHostname();
798
828
  const url = `${GATEWAY_URL}/d/${hostname}`;
@@ -820,24 +850,52 @@ async function gatewayCall(method, params = {}) {
820
850
  headers,
821
851
  body: JSON.stringify({ method, params: enrichedParams })
822
852
  });
823
- if (!response.ok) {
824
- throw new Error(`Gateway HTTP error: ${response.status} ${response.statusText}`);
853
+ const responseBody = await response.text();
854
+ let json = null;
855
+ if (responseBody) {
856
+ try {
857
+ json = JSON.parse(responseBody);
858
+ } catch {
859
+ }
860
+ }
861
+ if (!response.ok || !json) {
862
+ throw new GatewayRequestError({
863
+ method,
864
+ status: response.status,
865
+ statusText: response.statusText,
866
+ payload: json,
867
+ responseBody
868
+ });
825
869
  }
826
- const json = await response.json();
827
870
  if (json.success === false) {
828
871
  const err = json.error || "";
829
872
  const deniedBy = json.denied_by || json.error_type || "";
830
873
  if (deniedBy === "rule" || deniedBy === "access" || deniedBy === "entitlement" || err === "RULE_DENIED" || err === "ACCESS_DENIED" || err === "PERMISSION_DENIED" || err === "ENTITLEMENT_REQUIRED") {
831
874
  throw new EnforcementDeniedError(json);
832
875
  }
833
- throw new Error(
834
- json.message || json.error || `Gateway call ${method} failed`
835
- );
876
+ throw new GatewayRequestError({
877
+ method,
878
+ status: response.status,
879
+ statusText: response.statusText,
880
+ payload: json,
881
+ responseBody
882
+ });
836
883
  }
837
884
  return json;
838
885
  }
839
886
 
840
887
  // src/execution-control.ts
888
+ async function executionControlCall(params) {
889
+ try {
890
+ return await gatewayCall("execution-control-transition", params);
891
+ } catch (error) {
892
+ if (!(error instanceof GatewayRequestError) || error.status < 500) {
893
+ throw error;
894
+ }
895
+ await new Promise((resolve) => setTimeout(resolve, 250));
896
+ return gatewayCall("execution-control-transition", params);
897
+ }
898
+ }
841
899
  function withConversationAnchor(response) {
842
900
  const anchor = response.conversation_anchor_item_id ?? response.conversation_root_id;
843
901
  if (!anchor) return response;
@@ -860,7 +918,7 @@ async function cancelTurn(requestMessageId, options = {}) {
860
918
  if (idempotencyKey.length > 128) {
861
919
  throw new TypeError("cancelTurn idempotency key must be 128 characters or fewer");
862
920
  }
863
- const response = await gatewayCall("execution-control-transition", {
921
+ const response = await executionControlCall({
864
922
  op: "request",
865
923
  command: "cancel",
866
924
  delivery: "immediate",
@@ -890,7 +948,7 @@ async function steerTurn(requestMessageId, selectedQueueEntryId, options = {}) {
890
948
  if (idempotencyKey.length > 128) {
891
949
  throw new TypeError("steerTurn idempotency key must be 128 characters or fewer");
892
950
  }
893
- const response = await gatewayCall("execution-control-transition", {
951
+ const response = await executionControlCall({
894
952
  op: "request",
895
953
  command: "steer",
896
954
  delivery: "immediate",
@@ -914,7 +972,7 @@ async function cancelQueuedTurn(queueEntryId, options = {}) {
914
972
  if (idempotencyKey.length > 128) {
915
973
  throw new TypeError("cancelQueuedTurn idempotency key must be 128 characters or fewer");
916
974
  }
917
- const response = await gatewayCall("execution-control-transition", {
975
+ const response = await executionControlCall({
918
976
  op: "cancel_queue_entry",
919
977
  queue_entry_id: target,
920
978
  idempotency_key: idempotencyKey,
@@ -959,6 +1017,8 @@ async function submitForm(capabilityId, fields, options = {}) {
959
1017
  throw new TypeError("pageUrl is required outside a browser");
960
1018
  }
961
1019
  const endpoint = `${GATEWAY_URL.replace(/\/+$/, "")}/d/${encodeURIComponent(hostname)}/actions/${encodeURIComponent(capabilityId)}`;
1020
+ const identity = formAttribution();
1021
+ const attribution = identity ? { visitor_id: identity.visitor_id, session_id: identity.session_id } : void 0;
962
1022
  let response;
963
1023
  try {
964
1024
  response = await fetch(endpoint, {
@@ -967,7 +1027,7 @@ async function submitForm(capabilityId, fields, options = {}) {
967
1027
  "Content-Type": "application/json",
968
1028
  "Accept": "application/json"
969
1029
  },
970
- body: JSON.stringify({ fill_id: fillId, page_url: pageUrl, fields }),
1030
+ body: JSON.stringify({ fill_id: fillId, page_url: pageUrl, fields, ...attribution ? { attribution } : {} }),
971
1031
  signal: options.signal,
972
1032
  credentials: "omit"
973
1033
  });
@@ -998,7 +1058,7 @@ async function submitForm(capabilityId, fields, options = {}) {
998
1058
  fill_id: fillId,
999
1059
  action_id: capabilityId,
1000
1060
  release_id: payload.release_id
1001
- }, { eventId: fillId, pageUrl, signal: options.signal, keepalive: true });
1061
+ }, { eventId: fillId, pageUrl, signal: options.signal, keepalive: true, ...identity ? { source: identity.source, visitorId: identity.visitor_id, sessionId: identity.session_id } : {} });
1002
1062
  } catch {
1003
1063
  }
1004
1064
  return payload;
@@ -4674,6 +4734,7 @@ Object.defineProperty(exports, "QueryClientProvider", {
4674
4734
  exports.ComponentRenderer = ComponentRenderer;
4675
4735
  exports.EnforcementDeniedError = EnforcementDeniedError;
4676
4736
  exports.FormSubmissionError = FormSubmissionError;
4737
+ exports.GatewayRequestError = GatewayRequestError;
4677
4738
  exports.InteractionTrackingError = InteractionTrackingError;
4678
4739
  exports.KernelProvider = KernelProvider;
4679
4740
  exports.auth = auth;