@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.
@@ -0,0 +1,3 @@
1
+ declare type SleeperEntitlement = 'user:email' | 'user:phone' | 'user:real_name';
2
+
3
+ export default SleeperEntitlement;
@@ -0,0 +1,5 @@
1
+ declare class SleeperHeaderOptions {
2
+ useLeagueSelector?: boolean;
3
+ }
4
+
5
+ export default SleeperHeaderOptions;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeperhq/mini-core",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
4
4
  "description": "Core library frameworks for developing Sleeper Mini Apps.",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
@@ -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 the IP address to the server
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);
@@ -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((data: Types.Context) => {
25
- setContext(data);
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
- (data: any) => {
31
+ (context: any) => {
30
32
  setContext(existing => {
31
- for (const key in data) {
32
- existing[key] = data[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
  );