@aerostack/sdk-react 0.6.7 → 0.6.10
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/package.json +2 -2
- package/src/context.tsx +20 -3
- package/test-realtime-import.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aerostack/sdk-react",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"author": "Aerostack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"typescript-eslint": "^8.26.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@aerostack/sdk-web": "^0.6.
|
|
44
|
+
"@aerostack/sdk-web": "^0.6.10"
|
|
45
45
|
},
|
|
46
46
|
"exports": {
|
|
47
47
|
".": {
|
package/src/context.tsx
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React, { createContext, useContext, useMemo } from 'react';
|
|
2
2
|
import { SDK } from '@aerostack/sdk-web';
|
|
3
|
+
import { RealtimeClient } from '@aerostack/sdk-web/sdk/realtime.js';
|
|
3
4
|
|
|
4
5
|
export interface AerostackContextType {
|
|
5
|
-
sdk: SDK;
|
|
6
|
+
sdk: SDK & { realtime?: RealtimeClient };
|
|
6
7
|
projectId: string;
|
|
7
8
|
}
|
|
8
9
|
|
|
@@ -10,12 +11,14 @@ const AerostackContext = createContext<AerostackContextType | null>(null);
|
|
|
10
11
|
|
|
11
12
|
export interface AerostackProviderProps {
|
|
12
13
|
projectId: string;
|
|
14
|
+
apiKey?: string;
|
|
13
15
|
baseUrl?: string;
|
|
14
16
|
children: React.ReactNode;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export const AerostackProvider: React.FC<AerostackProviderProps> = ({
|
|
18
20
|
projectId,
|
|
21
|
+
apiKey,
|
|
19
22
|
baseUrl = 'https://api.aerostack.ai/v1',
|
|
20
23
|
children,
|
|
21
24
|
}) => {
|
|
@@ -26,10 +29,24 @@ export const AerostackProvider: React.FC<AerostackProviderProps> = ({
|
|
|
26
29
|
if (mod.setProjectId) mod.setProjectId(projectId);
|
|
27
30
|
});
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
const client = new SDK({
|
|
30
33
|
serverURL: baseUrl,
|
|
34
|
+
apiKeyAuth: apiKey,
|
|
31
35
|
});
|
|
32
|
-
|
|
36
|
+
|
|
37
|
+
// Instantiate RealtimeClient and attach it to the SDK instance
|
|
38
|
+
// so that useSubscription and App code can access 'sdk.realtime'
|
|
39
|
+
const realtime = new RealtimeClient({
|
|
40
|
+
baseUrl,
|
|
41
|
+
projectId,
|
|
42
|
+
apiKey,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Expose realtime on the SDK instance
|
|
46
|
+
(client as any).realtime = realtime;
|
|
47
|
+
|
|
48
|
+
return client as SDK & { realtime: RealtimeClient };
|
|
49
|
+
}, [baseUrl, projectId, apiKey]);
|
|
33
50
|
|
|
34
51
|
const value = useMemo(() => ({
|
|
35
52
|
sdk,
|