@sleeperhq/mini-core 1.4.6 → 1.4.8
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.
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type SleeperEntitlement from "@sleeperhq/mini-core/declarations/sleeper_entitlement";
|
|
2
|
+
import type SleeperHeaderOptions from "@sleeperhq/mini-core/declarations/sleeper_header_options";
|
|
3
|
+
|
|
1
4
|
type SocketMessage = {
|
|
2
5
|
_ip?: string;
|
|
3
6
|
_name?: string;
|
|
4
7
|
_webpack?: string;
|
|
5
8
|
_contextGet?: string;
|
|
9
|
+
_entitlements?: SleeperEntitlement[];
|
|
10
|
+
_headerOptions?: SleeperHeaderOptions;
|
|
6
11
|
};
|
|
7
12
|
export default SocketMessage;
|
package/package.json
CHANGED
package/src/dev_server/index.tsx
CHANGED
|
@@ -98,11 +98,13 @@ const DevServer = props => {
|
|
|
98
98
|
|
|
99
99
|
if (messageType.current === 'context') {
|
|
100
100
|
// We should have a context object now
|
|
101
|
-
const context = new Proxy(json, handler);
|
|
102
|
-
props.onContextChanged(context);
|
|
101
|
+
const context = new Proxy(json._context, handler);
|
|
102
|
+
props.onContextChanged(context, json._entitlements);
|
|
103
103
|
} else if (messageType.current === `partialContext`) {
|
|
104
104
|
// We are updating a partial Context
|
|
105
|
-
props.onContextUpdated(json)
|
|
105
|
+
props.onContextUpdated(json._context);
|
|
106
|
+
} else if (messageType.current === 'entitlements') {
|
|
107
|
+
props.onEntitlementsUpdated(json._entitlements);
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
messageType.current = '';
|
|
@@ -196,10 +198,12 @@ const DevServer = props => {
|
|
|
196
198
|
localAddress: ipAddress,
|
|
197
199
|
reuseAddress: true,
|
|
198
200
|
}, () => {
|
|
199
|
-
// When we establish a connection, send
|
|
201
|
+
// When we establish a connection, send some data to the server
|
|
200
202
|
const message: SocketMessage = {
|
|
201
203
|
_ip: ipAddress,
|
|
202
|
-
_name: config.name,
|
|
204
|
+
_name: config.name,
|
|
205
|
+
_entitlements: config.entitlements,
|
|
206
|
+
_headerOptions: config.headerOptions,
|
|
203
207
|
};
|
|
204
208
|
const json = JSON.stringify(message);
|
|
205
209
|
console.log('[Sleeper] Send IP address: ', ipAddress, config.name);
|
package/src/types/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type SleeperEntitlement from '../../declarations/sleeper_entitlement.d';
|
|
2
|
+
import type SleeperHeaderOptions from '../../declarations/sleeper_header_options.d';
|
|
3
|
+
|
|
1
4
|
export * from '../../declarations/types/index.d';
|
|
2
|
-
export { default as Context } from '../../declarations/sleeper_context.d';
|
|
5
|
+
export type { default as Context } from '../../declarations/sleeper_context.d';
|
|
6
|
+
export type { default as Entitlements } from '../../declarations/sleeper_entitlement.d';
|
|
7
|
+
export type { default as HeaderOptions } from '../../declarations/sleeper_header_options.d';
|
|
3
8
|
export type { default as SocketMessage } from '../../declarations/sleeper_message.d';
|
|
4
9
|
|
|
5
10
|
export type Config = {
|
|
@@ -9,4 +14,6 @@ export type Config = {
|
|
|
9
14
|
remoteSocketPort?: number,
|
|
10
15
|
dev?: boolean,
|
|
11
16
|
logsEnabled?: boolean,
|
|
17
|
+
entitlements?: SleeperEntitlement[],
|
|
18
|
+
headerOptions?: SleeperHeaderOptions,
|
|
12
19
|
};
|
package/start.tsx
CHANGED
|
@@ -18,18 +18,20 @@ DevServer.init(config);
|
|
|
18
18
|
const Root = () => {
|
|
19
19
|
const [context, setContext] = useState<Types.Context>({} as Types.Context);
|
|
20
20
|
const [connected, setConnected] = useState<boolean>(false);
|
|
21
|
+
const [entitlements, setEntitlements] = useState<Types.Entitlements>({} as Types.Entitlements);
|
|
21
22
|
const [, updateState] = React.useState<any>();
|
|
22
23
|
const forceUpdate = React.useCallback(() => updateState({}), []);
|
|
23
24
|
|
|
24
|
-
const _onContextChanged = useCallback((
|
|
25
|
-
setContext(
|
|
25
|
+
const _onContextChanged = useCallback((context: Types.Context, entitlements: Types.Entitlements) => {
|
|
26
|
+
setContext(context);
|
|
27
|
+
setEntitlements(entitlements);
|
|
26
28
|
}, []);
|
|
27
29
|
|
|
28
30
|
const _onContextUpdated = useCallback(
|
|
29
|
-
(
|
|
31
|
+
(context: any) => {
|
|
30
32
|
setContext(existing => {
|
|
31
|
-
for (const key in
|
|
32
|
-
existing[key] =
|
|
33
|
+
for (const key in context) {
|
|
34
|
+
existing[key] = context[key];
|
|
33
35
|
}
|
|
34
36
|
return existing;
|
|
35
37
|
});
|
|
@@ -38,6 +40,14 @@ const Root = () => {
|
|
|
38
40
|
[forceUpdate],
|
|
39
41
|
);
|
|
40
42
|
|
|
43
|
+
const _onEntitlementsUpdated = useCallback(
|
|
44
|
+
(entitlements: any) => {
|
|
45
|
+
setEntitlements(entitlements);
|
|
46
|
+
forceUpdate();
|
|
47
|
+
},
|
|
48
|
+
[forceUpdate],
|
|
49
|
+
);
|
|
50
|
+
|
|
41
51
|
const _onConnected = useCallback((value: boolean) => {
|
|
42
52
|
setConnected(value);
|
|
43
53
|
}, []);
|
|
@@ -59,9 +69,10 @@ const Root = () => {
|
|
|
59
69
|
<DevServer
|
|
60
70
|
onContextChanged={_onContextChanged}
|
|
61
71
|
onContextUpdated={_onContextUpdated}
|
|
72
|
+
onEntitlementsUpdated={_onEntitlementsUpdated}
|
|
62
73
|
onConnected={_onConnected}
|
|
63
74
|
/>
|
|
64
|
-
{connected && <Project context={context} />}
|
|
75
|
+
{connected && <Project context={context} entitlements={entitlements} />}
|
|
65
76
|
{!connected && _renderWaitingForConnection()}
|
|
66
77
|
</SafeAreaView>
|
|
67
78
|
);
|