integrate-sdk 0.5.2 → 0.5.3

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/react.js CHANGED
@@ -859,15 +859,28 @@ var require_react = __commonJS((exports, module) => {
859
859
 
860
860
  // src/react/hooks.ts
861
861
  var import_react = __toESM(require_react(), 1);
862
+ function getSafeFallback() {
863
+ return {
864
+ tokens: {},
865
+ headers: {},
866
+ isLoading: false,
867
+ fetch: globalThis.fetch?.bind(globalThis) || (async () => new Response),
868
+ mergeHeaders: (existingHeaders) => new Headers(existingHeaders)
869
+ };
870
+ }
862
871
  function useIntegrateTokens(client) {
872
+ if (typeof window === "undefined") {
873
+ return getSafeFallback();
874
+ }
875
+ if (!client) {
876
+ return {
877
+ ...getSafeFallback(),
878
+ isLoading: true
879
+ };
880
+ }
863
881
  const [tokens, setTokens] = import_react.useState({});
864
882
  const [isLoading, setIsLoading] = import_react.useState(true);
865
883
  import_react.useEffect(() => {
866
- if (!client) {
867
- console.error("[useIntegrateTokens] Client parameter is required. " + "Pass your MCP client instance to this hook.");
868
- setIsLoading(false);
869
- return;
870
- }
871
884
  try {
872
885
  const updateTokens = () => {
873
886
  try {
@@ -39,8 +39,11 @@ export interface UseIntegrateTokensResult {
39
39
  * Automatically listens for authentication events and updates when tokens change.
40
40
  * Returns tokens and formatted headers ready to pass to API requests.
41
41
  *
42
- * @param client - MCP client instance created with createMCPClient()
43
- * @returns Object with tokens, headers, and loading state
42
+ * **Note:** This hook must be called inside a React component. It will return safe
43
+ * fallback values during SSR or if the client is not ready.
44
+ *
45
+ * @param client - MCP client instance created with createMCPClient() (optional)
46
+ * @returns Object with tokens, headers, loading state, fetch function, and mergeHeaders helper
44
47
  *
45
48
  * @example
46
49
  * ```tsx
@@ -53,11 +56,11 @@ export interface UseIntegrateTokensResult {
53
56
  * });
54
57
  *
55
58
  * function ChatComponent() {
56
- * const { tokens, headers, isLoading } = useIntegrateTokens(client);
59
+ * const { fetch: fetchWithTokens, isLoading } = useIntegrateTokens(client);
57
60
  *
58
61
  * const chat = useChat({
59
62
  * api: '/api/chat',
60
- * headers, // Automatically includes x-integrate-tokens
63
+ * fetch: fetchWithTokens, // Tokens automatically included
61
64
  * });
62
65
  *
63
66
  * return <div>Chat UI here</div>;
@@ -66,21 +69,18 @@ export interface UseIntegrateTokensResult {
66
69
  *
67
70
  * @example
68
71
  * ```tsx
69
- * // Manual fetch with tokens
72
+ * // With mergeHeaders helper
70
73
  * import { createMCPClient } from 'integrate-sdk';
71
74
  *
72
75
  * const client = createMCPClient({ plugins: [...] });
73
76
  *
74
77
  * function MyComponent() {
75
- * const { headers } = useIntegrateTokens(client);
78
+ * const { mergeHeaders } = useIntegrateTokens(client);
76
79
  *
77
80
  * const fetchData = async () => {
78
81
  * const response = await fetch('/api/data', {
79
82
  * method: 'POST',
80
- * headers: {
81
- * 'Content-Type': 'application/json',
82
- * ...headers, // Includes x-integrate-tokens
83
- * },
83
+ * headers: mergeHeaders({ 'Content-Type': 'application/json' }),
84
84
  * body: JSON.stringify({ query: 'example' }),
85
85
  * });
86
86
  * return response.json();
@@ -90,5 +90,5 @@ export interface UseIntegrateTokensResult {
90
90
  * }
91
91
  * ```
92
92
  */
93
- export declare function useIntegrateTokens(client: MCPClient<any>): UseIntegrateTokensResult;
93
+ export declare function useIntegrateTokens(client?: MCPClient<any> | null): UseIntegrateTokensResult;
94
94
  //# sourceMappingURL=hooks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/react/hooks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,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oH1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "integrate-sdk",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Type-safe TypeScript SDK for MCP Client with plugin-based OAuth provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",