@sleeperhq/mini-core 1.0.0 → 1.0.2

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,8 @@
1
+ ### Description
2
+
3
+
4
+ ### How To Test
5
+
6
+ 1.
7
+
8
+ ### Screenshots/Video
@@ -0,0 +1,37 @@
1
+ /// <reference types="react" />
2
+ import { GestureResponderEvent } from 'react-native';
3
+ export interface ButtonProps {
4
+ height?: number;
5
+ gradient?: (string | number)[];
6
+ start?: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ end?: {
11
+ x: number;
12
+ y: number;
13
+ };
14
+ disable?: boolean;
15
+ onPress?: (event: GestureResponderEvent) => void;
16
+ text?: string;
17
+ }
18
+ declare const Button: {
19
+ (props: ButtonProps): JSX.Element;
20
+ defaultProps: {
21
+ height: number;
22
+ shadowHeight: number;
23
+ gradient: string[];
24
+ type: string;
25
+ size: string;
26
+ isForSmallScreen: boolean;
27
+ start: {
28
+ x: number;
29
+ y: number;
30
+ };
31
+ end: {
32
+ x: number;
33
+ y: number;
34
+ };
35
+ };
36
+ };
37
+ export default Button;
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ declare const _default: any;
3
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import { ColorValue, ViewStyle } from 'react-native';
2
+ import SleeperJersey from 'components/ui/jersey';
3
+ export interface JerseyProps {
4
+ style: ViewStyle;
5
+ sport: 'nfl' | 'nba' | 'cbb' | 'cfb' | 'mlb';
6
+ number: string;
7
+ fill: ColorValue;
8
+ }
9
+ export default SleeperJersey;
@@ -0,0 +1,5 @@
1
+ import { NavigationType, NavigationTypeId } from './types';
2
+ declare class SleeperActions {
3
+ navigate: (navType: NavigationType, navTypeId: NavigationTypeId) => void;
4
+ }
5
+ export default SleeperActions;
@@ -0,0 +1,10 @@
1
+ import { User, Navigation, League } from './types';
2
+ import SleeperActions from './sleeper_actions';
3
+ declare class SleeperContext {
4
+ user: User;
5
+ navigation: Navigation;
6
+ league: League;
7
+ actions: SleeperActions;
8
+ constructor(user: User, navigation: Navigation, league: League);
9
+ }
10
+ export default SleeperContext;
@@ -0,0 +1,13 @@
1
+ import { PureComponent } from 'react';
2
+ import { TextProps } from 'react-native';
3
+ declare type Props = {
4
+ color?: string;
5
+ inheritStyles?: boolean;
6
+ screenShrink?: number;
7
+ } & TextProps;
8
+ export declare type AppTextProps = Props;
9
+ export default class AppText extends PureComponent<Props> {
10
+ private getStyles;
11
+ render(): JSX.Element;
12
+ }
13
+ export {};
@@ -0,0 +1,9 @@
1
+ import { NAVIGATION_ID, NAVIGATION_TYPE } from './redux/native_nav/constants.d';
2
+ export declare type NavigationType = typeof NAVIGATION_TYPE;
3
+ export declare type NavigationTypeId = typeof NAVIGATION_ID;
4
+ export * from './shared/graphql.d';
5
+ export declare type Navigation = {
6
+ selectedNavType: NavigationType;
7
+ selectedNavTypeId: NavigationTypeId;
8
+ selectedNavData: {};
9
+ };
@@ -0,0 +1,23 @@
1
+ export declare const NAVIGATION_TYPE: {
2
+ readonly DM: "DM";
3
+ readonly INBOX: "INBOX";
4
+ readonly MY_FEED: "MY_FEED";
5
+ readonly FRIENDS: "FRIENDS";
6
+ readonly LEAGUE: "LEAGUE";
7
+ readonly ASYNC_SPORT: "ASYNC_SPORT";
8
+ readonly CREATE_LEAGUE: "CREATE_LEAGUE";
9
+ readonly LEAGUE_SYNC: "LEAGUE_SYNC";
10
+ readonly DRAFTBOARDS: "DRAFTBOARDS";
11
+ readonly SOLO_OVER_UNDER: "SOLO_OVER_UNDER";
12
+ readonly CHANNEL: "CHANNEL";
13
+ readonly MANAGE_CHANNELS: "MANAGE_CHANNELS";
14
+ };
15
+ export declare const NAVIGATION_ID: {
16
+ readonly DRAFTBOARDS: 1;
17
+ readonly CREATE_DM: 2;
18
+ readonly DM_SCREEN: 3;
19
+ readonly CREATE_LEAGUE: 4;
20
+ readonly MY_FEED: 5;
21
+ readonly MENTIONS: 6;
22
+ readonly FRIENDS: 7;
23
+ };
@@ -0,0 +1,98 @@
1
+ export declare type Maybe<T> = T | null;
2
+ export declare type InputMaybe<T> = Maybe<T>;
3
+ export declare type Exact<T extends {
4
+ [key: string]: unknown;
5
+ }> = {
6
+ [K in keyof T]: T[K];
7
+ };
8
+ export declare type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
9
+ [SubKey in K]?: Maybe<T[SubKey]>;
10
+ };
11
+ export declare type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
12
+ [SubKey in K]: Maybe<T[SubKey]>;
13
+ };
14
+ /** All built-in and custom scalars, mapped to their actual values */
15
+ export declare type Scalars = {
16
+ ID: string;
17
+ String: string;
18
+ Boolean: boolean;
19
+ Int: number;
20
+ Float: number;
21
+ /** JSON */
22
+ Json: {
23
+ [key: string]: any;
24
+ };
25
+ /** Lists */
26
+ List: string[];
27
+ /** Map / Dictionary */
28
+ Map: {
29
+ [key: string]: any;
30
+ };
31
+ MapWithSnowflakeKey: {
32
+ [key: string]: any;
33
+ };
34
+ /** Sets */
35
+ Set: string[];
36
+ /** Snowflake ID */
37
+ Snowflake: string;
38
+ SnowflakeList: string[];
39
+ SnowflakeSet: string[];
40
+ };
41
+ export declare type League = {
42
+ __typename?: 'League';
43
+ avatar?: Maybe<Scalars['String']>;
44
+ company_id?: Maybe<Scalars['Snowflake']>;
45
+ display_order?: Maybe<Scalars['Int']>;
46
+ draft_id?: Maybe<Scalars['Snowflake']>;
47
+ group_id?: Maybe<Scalars['Snowflake']>;
48
+ last_author_avatar?: Maybe<Scalars['String']>;
49
+ last_author_display_name?: Maybe<Scalars['String']>;
50
+ last_author_id?: Maybe<Scalars['Snowflake']>;
51
+ last_author_is_bot?: Maybe<Scalars['Boolean']>;
52
+ last_message_attachment?: Maybe<Scalars['Json']>;
53
+ last_message_id?: Maybe<Scalars['Snowflake']>;
54
+ last_message_text?: Maybe<Scalars['String']>;
55
+ last_message_text_map?: Maybe<Scalars['Json']>;
56
+ last_message_time?: Maybe<Scalars['Int']>;
57
+ last_pinned_message_id?: Maybe<Scalars['Snowflake']>;
58
+ last_read_id?: Maybe<Scalars['Snowflake']>;
59
+ last_transaction_id?: Maybe<Scalars['Snowflake']>;
60
+ league_id?: Maybe<Scalars['Snowflake']>;
61
+ matchup_legs?: Maybe<Scalars['List']>;
62
+ metadata?: Maybe<Scalars['Map']>;
63
+ name?: Maybe<Scalars['String']>;
64
+ previous_league_id?: Maybe<Scalars['Snowflake']>;
65
+ roster_positions?: Maybe<Scalars['List']>;
66
+ scoring_settings?: Maybe<Scalars['Map']>;
67
+ season?: Maybe<Scalars['String']>;
68
+ season_type?: Maybe<Scalars['String']>;
69
+ settings?: Maybe<Scalars['Map']>;
70
+ sport?: Maybe<Scalars['String']>;
71
+ status?: Maybe<Scalars['String']>;
72
+ total_rosters?: Maybe<Scalars['Int']>;
73
+ };
74
+ export declare type User = {
75
+ __typename?: 'User';
76
+ async_bundles?: Maybe<Scalars['List']>;
77
+ avatar?: Maybe<Scalars['String']>;
78
+ cookies?: Maybe<Scalars['Int']>;
79
+ created?: Maybe<Scalars['Int']>;
80
+ currencies?: Maybe<Scalars['Map']>;
81
+ data_updated?: Maybe<Scalars['Map']>;
82
+ deleted?: Maybe<Scalars['Int']>;
83
+ display_name?: Maybe<Scalars['String']>;
84
+ email?: Maybe<Scalars['String']>;
85
+ is_bot?: Maybe<Scalars['Boolean']>;
86
+ metadata?: Maybe<Scalars['Json']>;
87
+ notifications?: Maybe<Scalars['Map']>;
88
+ pending?: Maybe<Scalars['Boolean']>;
89
+ phone?: Maybe<Scalars['String']>;
90
+ real_name?: Maybe<Scalars['String']>;
91
+ solicitable?: Maybe<Scalars['Boolean']>;
92
+ summoner_name?: Maybe<Scalars['String']>;
93
+ summoner_region?: Maybe<Scalars['String']>;
94
+ token?: Maybe<Scalars['String']>;
95
+ user_id?: Maybe<Scalars['Snowflake']>;
96
+ username?: Maybe<Scalars['String']>;
97
+ verification?: Maybe<Scalars['String']>;
98
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeperhq/mini-core",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Core library frameworks for developing Sleeper Mini Apps.",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
@@ -1,13 +1,8 @@
1
1
  import React from 'react';
2
- import {
3
- ColorValue,
4
- GestureResponderEvent,
5
- TextProps,
6
- View,
7
- ViewStyle,
8
- } from 'react-native';
2
+ import {TextProps, View} from 'react-native';
9
3
  import {Federated} from '@callstack/repack/client';
10
- import {Context} from '../types';
4
+ import type {ButtonProps} from '../../declarations/button';
5
+ import type {JerseyProps} from '../../declarations/jersey';
11
6
 
12
7
  const _SleeperModule = React.lazy(() =>
13
8
  Federated.importModule('sleeper', 'index').catch(() => ({
@@ -20,15 +15,6 @@ const _SleeperModule = React.lazy(() =>
20
15
  })),
21
16
  );
22
17
 
23
- type ButtonProps = {
24
- height?: number;
25
- gradient?: (string | number)[];
26
- start?: {x: number; y: number};
27
- end?: {x: number; y: number};
28
- disable?: boolean;
29
- onPress?: (event: GestureResponderEvent) => void;
30
- text?: string;
31
- };
32
18
  const Button = (props: ButtonProps) => {
33
19
  return (
34
20
  <React.Suspense fallback={<View />}>
@@ -45,12 +31,6 @@ const Text = (props: TextProps) => {
45
31
  );
46
32
  };
47
33
 
48
- type JerseyProps = {
49
- style: ViewStyle;
50
- sport: 'nfl' | 'nba' | 'cbb' | 'cfb' | 'mlb';
51
- number: string;
52
- fill: ColorValue;
53
- };
54
34
  const Jersey = (props: JerseyProps) => {
55
35
  return (
56
36
  <React.Suspense fallback={<View />}>
@@ -59,5 +39,5 @@ const Jersey = (props: JerseyProps) => {
59
39
  );
60
40
  };
61
41
 
62
- export type {ButtonProps, Context, TextProps, JerseyProps};
42
+ export type {ButtonProps, TextProps, JerseyProps};
63
43
  export {Button, Text, Jersey};
@@ -1,44 +1,12 @@
1
1
  import React, {useEffect} from 'react';
2
2
  import {Platform} from 'react-native';
3
+ import {Config} from '../types';
3
4
  import {ScriptManager, Federated} from '@callstack/repack/client';
4
5
  import NetInfo from '@react-native-community/netinfo';
5
6
  import dgram from 'react-native-udp';
6
- import {
7
- localSocketPort,
8
- remoteSocketPort,
9
- remoteBundlePort as _remoteBundlePort,
10
- release,
11
- remoteIP,
12
- } from '../../app.json';
13
7
  import axios from 'axios';
14
8
 
15
- const remoteBundleHost = release ? remoteIP : 'localhost';
16
- const remoteBundlePort = release ? _remoteBundlePort : 8081;
17
-
18
- ScriptManager.shared.addResolver(async (scriptId, caller) => {
19
- const extension =
20
- scriptId === 'sleeper' ? '.container.bundle' : '.chunk.bundle';
21
- const resolveURL = Federated.createURLResolver({
22
- containers: {
23
- sleeper: `http://${remoteBundleHost}:${remoteBundlePort}/[name]${extension}`,
24
- },
25
- });
26
-
27
- // Try to resolve URL based on scriptId and caller
28
- const url = resolveURL(scriptId, caller);
29
- const query = release ? undefined : {platform: Platform.OS};
30
-
31
- const response = await axios
32
- .get(url + '?' + new URLSearchParams(query), {method: 'HEAD'})
33
- .catch(() => ({
34
- status: 404,
35
- }));
36
-
37
- console.log('[Sleeper] load script:', scriptId, caller);
38
- if (response?.status === 200) {
39
- return {url, query};
40
- }
41
- });
9
+ let config: Config;
42
10
 
43
11
  const DevServer = props => {
44
12
  const onSocket = msg => {
@@ -63,7 +31,7 @@ const DevServer = props => {
63
31
  return;
64
32
  }
65
33
 
66
- socket.bind({port: localSocketPort, address: netInfoDetails.ipAddress});
34
+ socket.bind({port: config.localSocketPort, address: netInfoDetails.ipAddress});
67
35
  };
68
36
 
69
37
  const pingServer = socket => {
@@ -79,7 +47,7 @@ const DevServer = props => {
79
47
  const json = JSON.stringify({_ip: netInfoDetails.ipAddress});
80
48
 
81
49
  (async function ping() {
82
- socket.send(json, undefined, undefined, remoteSocketPort, remoteIP);
50
+ socket.send(json, undefined, undefined, config.remoteSocketPort, config.remoteIP);
83
51
  setTimeout(ping, 5000);
84
52
  })();
85
53
  });
@@ -87,6 +55,11 @@ const DevServer = props => {
87
55
  };
88
56
 
89
57
  useEffect(() => {
58
+ if (!config) {
59
+ console.error('[Sleeper] No config file specified. Please make sure you call DevServer.init() early in the app lifecycle.');
60
+ return;
61
+ }
62
+
90
63
  const socket = dgram.createSocket({type: 'udp4'});
91
64
  bindSocket(socket);
92
65
  pingServer(socket);
@@ -101,4 +74,36 @@ const DevServer = props => {
101
74
  return <></>;
102
75
  };
103
76
 
77
+ DevServer.init = (_config: Config) => {
78
+ config = _config;
79
+
80
+ const remoteBundleHost = config.release ? config.remoteIP : 'localhost';
81
+ const remoteBundlePort = config.release ? config.remoteBundlePort : 8081;
82
+
83
+ ScriptManager.shared.addResolver(async (scriptId, caller) => {
84
+ const extension =
85
+ scriptId === 'sleeper' ? '.container.bundle' : '.chunk.bundle';
86
+ const resolveURL = Federated.createURLResolver({
87
+ containers: {
88
+ sleeper: `http://${remoteBundleHost}:${remoteBundlePort}/[name]${extension}`,
89
+ },
90
+ });
91
+
92
+ // Try to resolve URL based on scriptId and caller
93
+ const url = resolveURL(scriptId, caller);
94
+ const query = config.release ? undefined : {platform: Platform.OS};
95
+
96
+ const response = await axios
97
+ .get(url + '?' + new URLSearchParams(query), {method: 'HEAD'})
98
+ .catch(() => ({
99
+ status: 404,
100
+ }));
101
+
102
+ console.log('[Sleeper] load script:', scriptId, caller);
103
+ if (response?.status === 200) {
104
+ return {url, query};
105
+ }
106
+ });
107
+ };
108
+
104
109
  export default DevServer;
@@ -1,116 +1,12 @@
1
- export type Maybe<T> = T | null;
2
- export type Scalars = {
3
- ID: string;
4
- String: string;
5
- Boolean: boolean;
6
- Int: number;
7
- Float: number;
8
- Json: {[key: string]: any};
9
- List: string[];
10
- Map: {[key: string]: any};
11
- MapWithSnowflakeKey: {[key: string]: any};
12
- Set: string[];
13
- Snowflake: string;
14
- SnowflakeList: string[];
15
- SnowflakeSet: string[];
16
- };
17
-
18
- export type User = {
19
- __typename?: 'User';
20
- async_bundles?: Maybe<Scalars['List']>;
21
- avatar?: Maybe<Scalars['String']>;
22
- cookies?: Maybe<Scalars['Int']>;
23
- created?: Maybe<Scalars['Int']>;
24
- currencies?: Maybe<Scalars['Map']>;
25
- data_updated?: Maybe<Scalars['Map']>;
26
- deleted?: Maybe<Scalars['Int']>;
27
- display_name?: Maybe<Scalars['String']>;
28
- email?: Maybe<Scalars['String']>;
29
- is_bot?: Maybe<Scalars['Boolean']>;
30
- metadata?: Maybe<Scalars['Json']>;
31
- notifications?: Maybe<Scalars['Map']>;
32
- pending?: Maybe<Scalars['Boolean']>;
33
- phone?: Maybe<Scalars['String']>;
34
- real_name?: Maybe<Scalars['String']>;
35
- solicitable?: Maybe<Scalars['Boolean']>;
36
- summoner_name?: Maybe<Scalars['String']>;
37
- summoner_region?: Maybe<Scalars['String']>;
38
- token?: Maybe<Scalars['String']>;
39
- user_id?: Maybe<Scalars['Snowflake']>;
40
- username?: Maybe<Scalars['String']>;
41
- verification?: Maybe<Scalars['String']>;
42
- };
43
-
44
- export type League = {
45
- __typename?: 'League';
46
- avatar?: Maybe<Scalars['String']>;
47
- company_id?: Maybe<Scalars['Snowflake']>;
48
- display_order?: Maybe<Scalars['Int']>;
49
- draft_id?: Maybe<Scalars['Snowflake']>;
50
- group_id?: Maybe<Scalars['Snowflake']>;
51
- last_author_avatar?: Maybe<Scalars['String']>;
52
- last_author_display_name?: Maybe<Scalars['String']>;
53
- last_author_id?: Maybe<Scalars['Snowflake']>;
54
- last_author_is_bot?: Maybe<Scalars['Boolean']>;
55
- last_message_attachment?: Maybe<Scalars['Json']>;
56
- last_message_id?: Maybe<Scalars['Snowflake']>;
57
- last_message_text?: Maybe<Scalars['String']>;
58
- last_message_text_map?: Maybe<Scalars['Json']>;
59
- last_message_time?: Maybe<Scalars['Int']>;
60
- last_pinned_message_id?: Maybe<Scalars['Snowflake']>;
61
- last_read_id?: Maybe<Scalars['Snowflake']>;
62
- last_transaction_id?: Maybe<Scalars['Snowflake']>;
63
- league_id?: Maybe<Scalars['Snowflake']>;
64
- matchup_legs?: Maybe<Scalars['List']>;
65
- metadata?: Maybe<Scalars['Map']>;
66
- name?: Maybe<Scalars['String']>;
67
- previous_league_id?: Maybe<Scalars['Snowflake']>;
68
- roster_positions?: Maybe<Scalars['List']>;
69
- scoring_settings?: Maybe<Scalars['Map']>;
70
- season?: Maybe<Scalars['String']>;
71
- season_type?: Maybe<Scalars['String']>;
72
- settings?: Maybe<Scalars['Map']>;
73
- sport?: Maybe<Scalars['String']>;
74
- status?: Maybe<Scalars['String']>;
75
- total_rosters?: Maybe<Scalars['Int']>;
76
- };
77
-
78
- export type NavigationType =
79
- | 'DM'
80
- | 'INBOX'
81
- | 'MY_FEED'
82
- | 'FRIENDS'
83
- | 'LEAGUE'
84
- | 'ASYNC_SPORT'
85
- | 'CREATE_LEAGUE'
86
- | 'LEAGUE_SYNC'
87
- | 'DRAFTBOARDS'
88
- | 'SOLO_OVER_UNDER'
89
- | 'CHANNEL'
90
- | 'MANAGE_CHANNELS';
91
-
92
- export type NavigationTypeId =
93
- | 1 // DRAFTBOARDS
94
- | 2 // CREATE_DM
95
- | 3 // DM_SCREEN
96
- | 4 // CREATE_LEAGUE
97
- | 5 // MY_FEED
98
- | 6 // MENTIONS
99
- | 7; // FRIENDS
100
-
101
- export type Navigation = {
102
- selectedNavType: NavigationType;
103
- selectedNavTypeId: NavigationTypeId;
104
- selectedNavData: {};
105
- };
106
-
107
- export type Actions = {
108
- navigate: (navType?: NavigationType, navTypeId?: NavigationTypeId) => void;
109
- };
110
-
111
- export type Context = {
112
- user?: User;
113
- league?: League;
114
- navigation?: Navigation;
115
- actions?: Actions;
1
+ export * from '../../declarations/types/index.d';
2
+ export { default as Context } from '../../declarations/sleeper_context.d';
3
+
4
+ export type Config = {
5
+ name: string,
6
+ displayName: string,
7
+ remoteIP: string,
8
+ localSocketPort: number,
9
+ remoteSocketPort: number,
10
+ remoteBundlePort: number,
11
+ release: boolean,
116
12
  };
package/app.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "name": "template",
3
- "displayName": "template",
4
- "remoteIP": "192.168.86.190",
5
- "localSocketPort": 8082,
6
- "remoteSocketPort": 9092,
7
- "remoteBundlePort": 9091,
8
- "release": true
9
- }