@skippr/live-agent-sdk 0.8.0 → 0.10.0

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 CHANGED
@@ -17,9 +17,14 @@ import { LiveAgent } from '@skippr/live-agent-sdk';
17
17
  import '@skippr/live-agent-sdk/styles';
18
18
 
19
19
  function App() {
20
- return <LiveAgent organizationId="your_org_id" agentId="your_agent_id" />;
20
+ return (
21
+ <LiveAgent
22
+ agentId="your_agent_id"
23
+ appKey="pk_live_your_key"
24
+ />
25
+ );
21
26
  }
22
- ```
27
+
23
28
 
24
29
  ## Custom Components
25
30
 
@@ -37,7 +42,7 @@ function ConnectionStatus() {
37
42
 
38
43
  function App() {
39
44
  return (
40
- <LiveAgent organizationId="your_org_id" agentId="your_agent_id">
45
+ <LiveAgent agentId="your_agent_id" appKey="pk_live_your_key">
41
46
  <ConnectionStatus />
42
47
  </LiveAgent>
43
48
  );
@@ -54,8 +59,9 @@ Self-contained widget component. Renders a floating button that opens a sidebar
54
59
 
55
60
  | Prop | Type | Default | Description |
56
61
  |------|------|---------|-------------|
57
- | `organizationId` | `string` | *required* | Organization ID provided by Skippr |
58
62
  | `agentId` | `string` | *required* | Agent ID provided by Skippr |
63
+ | `appKey` | `string` | — | Publishable App Key from the admin dashboard |
64
+ | `authToken` | `string` | — | Bearer token for authenticated users |
59
65
  | `defaultOpen` | `boolean` | `false` | Whether the panel starts open |
60
66
 
61
67
  ---
@@ -9,7 +9,14 @@ var LiveAgentContext = createContext(null);
9
9
  // src/hooks/useSession.ts
10
10
  import { useCallback, useState } from "react";
11
11
  var API_URL = "https://skipprapi-production.up.railway.app";
12
- function useSession({ organizationId, agentId }) {
12
+ function resolveAuthHeaders(authToken, appKey) {
13
+ if (authToken)
14
+ return { Authorization: `Bearer ${authToken}` };
15
+ if (appKey)
16
+ return { "X-App-Key": appKey };
17
+ return {};
18
+ }
19
+ function useSession({ agentId, authToken, appKey }) {
13
20
  const [connection, setConnection] = useState(null);
14
21
  const [shouldConnect, setShouldConnect] = useState(false);
15
22
  const [isStarting, setIsStarting] = useState(false);
@@ -19,17 +26,19 @@ function useSession({ organizationId, agentId }) {
19
26
  setIsStarting(true);
20
27
  setError("");
21
28
  try {
29
+ const authHeaders = resolveAuthHeaders(authToken, appKey);
22
30
  const createResp = await fetch(`${API_URL}/v1/sessions`, {
23
31
  method: "POST",
24
- headers: { "Content-Type": "application/json" },
25
- body: JSON.stringify({ organizationId, agentId })
32
+ headers: { "Content-Type": "application/json", ...authHeaders },
33
+ body: JSON.stringify({ agentId })
26
34
  });
27
35
  if (!createResp.ok) {
28
36
  throw new Error(`Failed to create session: ${createResp.status}`);
29
37
  }
30
38
  const { session } = await createResp.json();
31
39
  const startResp = await fetch(`${API_URL}/v1/sessions/${session.id}/start`, {
32
- method: "POST"
40
+ method: "POST",
41
+ headers: authHeaders
33
42
  });
34
43
  if (!startResp.ok) {
35
44
  throw new Error(`Failed to start session: ${startResp.status}`);
@@ -46,13 +55,14 @@ function useSession({ organizationId, agentId }) {
46
55
  } finally {
47
56
  setIsStarting(false);
48
57
  }
49
- }, [organizationId, agentId]);
58
+ }, [agentId, authToken, appKey]);
50
59
  const disconnect = useCallback(async () => {
51
60
  if (sessionId) {
61
+ const authHeaders = resolveAuthHeaders(authToken, appKey);
52
62
  try {
53
63
  await fetch(`${API_URL}/v1/sessions/${sessionId}/complete`, {
54
64
  method: "POST",
55
- headers: { "Content-Type": "application/json" },
65
+ headers: { "Content-Type": "application/json", ...authHeaders },
56
66
  body: JSON.stringify({})
57
67
  });
58
68
  } catch {}
@@ -61,7 +71,7 @@ function useSession({ organizationId, agentId }) {
61
71
  setShouldConnect(false);
62
72
  setConnection(null);
63
73
  setSessionId(null);
64
- }, [sessionId]);
74
+ }, [sessionId, authToken, appKey]);
65
75
  return { connection, shouldConnect, isStarting, error, startSession, disconnect };
66
76
  }
67
77
 
@@ -748,14 +758,16 @@ function SidebarTrigger() {
748
758
  // src/components/LiveAgent.tsx
749
759
  import { jsx as jsx12, jsxs as jsxs9, Fragment as Fragment2 } from "react/jsx-runtime";
750
760
  function LiveAgent({
751
- organizationId,
752
761
  agentId,
762
+ authToken,
763
+ appKey,
753
764
  defaultOpen = false,
754
765
  children
755
766
  }) {
756
767
  const { connection, shouldConnect, isStarting, error, startSession, disconnect } = useSession({
757
- organizationId,
758
- agentId
768
+ agentId,
769
+ authToken,
770
+ appKey
759
771
  });
760
772
  const [isPanelOpen, setIsPanelOpen] = useState5(defaultOpen);
761
773
  const openPanel = useCallback5(() => setIsPanelOpen(true), []);