@sleeperhq/mini-core 1.2.3 → 1.2.5

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/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as Sleeper from './src/components';
2
2
  import DevServer from './src/dev_server';
3
3
  import * as Types from './src/types';
4
- import './src/packages';
4
+ import * as Styles from './src/styles';
5
5
 
6
- export {Sleeper, DevServer, Types};
6
+ export {Sleeper, DevServer, Types, Styles};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleeperhq/mini-core",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Core library frameworks for developing Sleeper Mini Apps.",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "access": "public"
35
35
  },
36
36
  "peerDependencies": {
37
- "@callstack/repack": "blitzstudios/repack.git#callstack-repack-v2.6.1-gitpkg",
37
+ "@callstack/repack": "blitzstudios/repack.git#callstack-repack-v2.6.3-gitpkg",
38
38
  "@react-native-community/netinfo": "9.3.7",
39
39
  "axios": "0.15.3",
40
40
  "lodash": "4.17.21",
@@ -0,0 +1,174 @@
1
+ const SHARED = {
2
+ INTER_EXTRALIGHT: 'Inter-ExtraLight',
3
+ INTER_THIN: 'Inter-Thin',
4
+ INTER_LIGHT: 'Inter-Light',
5
+ INTER_REGULAR: 'Inter-Regular',
6
+ INTER_MEDIUM: 'Inter-Medium',
7
+ INTER_SEMIBOLD: 'Inter-SemiBold',
8
+ INTER_BOLD: 'Inter-Bold',
9
+ INTER_BLACK: 'Inter-Black',
10
+ INTER_EXTRABOLD: 'Inter-ExtraBold',
11
+
12
+ POPPINS_THIN: 'Poppins-Thin',
13
+ POPPINS_LIGHT: 'Poppins-Light',
14
+ POPPINS_REGULAR: 'Poppins-Regular',
15
+ POPPINS_MEDIUM: 'Poppins-Medium',
16
+ POPPINS_SEMIBOLD: 'Poppins-SemiBold',
17
+ POPPINS_BOLD: 'Poppins-Bold',
18
+ POPPINS_BLACK: 'Poppins-Black',
19
+ POPPINS_EXTRABOLD: 'Poppins-ExtraBold',
20
+ } as const;
21
+
22
+ const Fonts = {
23
+ THIN: 'Lato-Thin',
24
+ LIGHT: 'Lato-Light',
25
+ REGULAR: 'Lato-Regular',
26
+ MEDIUM: 'Lato-Medium',
27
+ BOLD: 'Lato-Bold',
28
+ HEAVY: 'Lato-Heavy',
29
+ BLACK: 'Lato-Black',
30
+
31
+ MULI_THIN: 'Muli-ExtraLight',
32
+ MULI_LIGHT: 'Muli-Light',
33
+ MULI_REGULAR: 'Muli-Regular',
34
+ MULI_MEDIUM: 'Muli-SemiBold',
35
+ MULI_BOLD: 'Muli-Bold',
36
+ MULI_BLACK: 'Muli-Black',
37
+ MULI_EXTRABOLD: 'Muli-ExtraBold',
38
+
39
+ OSWALD__EXTRA_LIGHT: 'Oswald-ExtraLight',
40
+ OSWALD_LIGHT: 'Oswald-Light',
41
+ OSWALD_REGULAR: 'Oswald-Regular',
42
+ OSWALD_MEDIUM: 'Oswald-Medium',
43
+ OSWALD_SEMIBOLD: 'Oswald-SemiBold',
44
+ OSWALD_BOLD: 'Oswald-Bold',
45
+
46
+ DRUK_SUPERITALIC: 'Druk-SuperItalic',
47
+ CHANEY_EXTENDED: 'Chaney-Extended',
48
+
49
+ ...SHARED,
50
+
51
+ Styles: {
52
+ H1: {
53
+ fontFamily: SHARED.POPPINS_EXTRABOLD,
54
+ fontSize: 32,
55
+ // lineHeight: 48,
56
+ },
57
+ H2: {
58
+ fontFamily: SHARED.POPPINS_EXTRABOLD,
59
+ fontSize: 28,
60
+ // lineHeight: 48,
61
+ },
62
+ H3: {
63
+ fontFamily: SHARED.POPPINS_BOLD,
64
+ fontSize: 24,
65
+ // lineHeight: 32,
66
+ },
67
+ H4: {
68
+ fontFamily: SHARED.POPPINS_BOLD,
69
+ fontSize: 20,
70
+ // lineHeight: 26,
71
+ },
72
+ Title: {
73
+ fontFamily: SHARED.POPPINS_SEMIBOLD,
74
+ fontSize: 18,
75
+ // lineHeight: 24,
76
+ },
77
+ Subhead: {
78
+ fontFamily: SHARED.POPPINS_SEMIBOLD,
79
+ fontSize: 16,
80
+ // lineHeight: 20,
81
+ },
82
+ Menu: {
83
+ fontFamily: SHARED.POPPINS_SEMIBOLD,
84
+ fontSize: 12,
85
+ // lineHeight: 16,
86
+ letterSpacing: 0.5,
87
+ },
88
+ ButtonLarge: {
89
+ fontFamily: SHARED.POPPINS_SEMIBOLD,
90
+ fontSize: 14,
91
+ // lineHeight: 16, // Cuts off the text at 14
92
+ letterSpacing: 1,
93
+ },
94
+ ButtonSmall: {
95
+ fontFamily: SHARED.POPPINS_SEMIBOLD,
96
+ fontSize: 12,
97
+ // lineHeight: 14, // Cuts off the text at 12
98
+ letterSpacing: 1,
99
+ },
100
+ TextCtaLarge: {
101
+ fontFamily: SHARED.POPPINS_SEMIBOLD,
102
+ fontSize: 14,
103
+ // lineHeight: 14,
104
+ letterSpacing: 1,
105
+ },
106
+ TextCtaSmall: {
107
+ fontFamily: SHARED.POPPINS_SEMIBOLD,
108
+ fontSize: 12,
109
+ // lineHeight: 12,
110
+ letterSpacing: 1,
111
+ },
112
+ Body1: {
113
+ fontFamily: SHARED.INTER_REGULAR,
114
+ fontSize: 16,
115
+ // lineHeight: 20,
116
+ letterSpacing: -0.15,
117
+ },
118
+ Body1Bold: {
119
+ fontFamily: SHARED.INTER_SEMIBOLD,
120
+ fontSize: 16,
121
+ // lineHeight: 20,
122
+ letterSpacing: -0.15,
123
+ },
124
+ Body2: {
125
+ fontFamily: SHARED.INTER_REGULAR,
126
+ fontSize: 14,
127
+ // lineHeight: 18,
128
+ letterSpacing: -0.25,
129
+ },
130
+ Body2Bold: {
131
+ fontFamily: SHARED.INTER_SEMIBOLD,
132
+ fontSize: 14,
133
+ // lineHeight: 18,
134
+ letterSpacing: -0.25,
135
+ },
136
+ Body3: {
137
+ fontFamily: SHARED.INTER_REGULAR,
138
+ fontSize: 12,
139
+ // lineHeight: 16,
140
+ letterSpacing: -0.15,
141
+ },
142
+ Body3Bold: {
143
+ fontFamily: SHARED.INTER_SEMIBOLD,
144
+ fontSize: 12,
145
+ // lineHeight: 16,
146
+ letterSpacing: -0.25,
147
+ },
148
+ Caption1: {
149
+ fontFamily: SHARED.INTER_REGULAR,
150
+ fontSize: 10,
151
+ // lineHeight: 12,
152
+ letterSpacing: -0.25,
153
+ },
154
+ Caption1Bold: {
155
+ fontFamily: SHARED.INTER_BOLD,
156
+ fontSize: 10,
157
+ // lineHeight: 12,
158
+ letterSpacing: -0.15,
159
+ },
160
+ Overline: {
161
+ fontFamily: SHARED.POPPINS_BOLD,
162
+ fontSize: 10,
163
+ letterSpacing: 0.25,
164
+ },
165
+ Footnote: {
166
+ fontFamily: SHARED.INTER_REGULAR,
167
+ fontSize: 9,
168
+ // lineHeight: 12,
169
+ letterSpacing: -0.25,
170
+ },
171
+ },
172
+ } as const;
173
+
174
+ export default Fonts;
@@ -0,0 +1,2 @@
1
+ export { default as Theme } from './theme';
2
+ export { default as Fonts } from './fonts';
@@ -0,0 +1,69 @@
1
+ const Theme = {
2
+ name: 'dark',
3
+
4
+ backgroundBase: '#030616',
5
+ backgroundDark: '#15182d',
6
+ backgroundCard: '#252942',
7
+ backgroundIce: '#fbfbfb',
8
+ backgroundWhite: '#ffffff',
9
+
10
+ primaryText: '#ffffff',
11
+ secondaryText: '#a3bbd3', // gray300
12
+
13
+ gray100: '#eef2f7',
14
+ gray200: '#d8e2ed',
15
+ gray300: '#a3bbd3',
16
+ gray400: '#606f8c',
17
+ gray500: '#4a5870',
18
+ gray600: '#344054',
19
+
20
+ aqua: '#00baff',
21
+ blue: '#046ae0',
22
+ cypress: '#019494',
23
+ green: '#45e8a7',
24
+ lavender: '#b8bfff',
25
+ lilac: '#bd66ff',
26
+ mint: '#00ceb8',
27
+ orange: '#ff5c00',
28
+ pink: '#ff7db6',
29
+ purple: '#6e7df5',
30
+ red: '#ff2b6d',
31
+ salmon: '#ff6086',
32
+ yam: '#8e66ff',
33
+ yellow: '#ffae58',
34
+ white: '#ffffff',
35
+ black: '#000000',
36
+ dark: '#022047',
37
+
38
+ gradients: {
39
+ // The `LinearGradient` component explicitly expects an array of color string, so casting in advance.
40
+ primary: ['#4ce2a7', '#00b7b3'] as string[],
41
+ success: ['#4ce2b8', '#07c5ff'] as string[],
42
+ cheer: ['#ffaa7f', '#ff3a6e'] as string[],
43
+ alert: ['#ffae58', '#ff4542'] as string[],
44
+ purple: ['#89a5fb', '#635ee4'] as string[],
45
+ lilac: ['#db84ff', '#9139ff'] as string[],
46
+ blue: ['#7cdaf9', '#5e73e4'] as string[],
47
+ gray: ['#e6effa', '#a3bbd3'] as string[],
48
+ darkgray: ['#a3bbd3', '#3a465b'] as string[],
49
+ background: ['#55609f', '#101c5a'] as string[],
50
+ },
51
+
52
+ getColorForSport(sport: string) {
53
+ if (sport === 'cbb') {
54
+ return Theme.orange;
55
+ }
56
+
57
+ if (sport === 'nba') {
58
+ return Theme.yellow;
59
+ }
60
+
61
+ if (sport === 'lcs' || sport === 'lol') {
62
+ return Theme.aqua;
63
+ }
64
+
65
+ return Theme.mint;
66
+ },
67
+ } as const;
68
+
69
+ export default Theme;
@@ -1,317 +0,0 @@
1
- import React, {useEffect, useRef, useState} from 'react';
2
- import {Platform} from 'react-native';
3
- import {Config, SocketMessage} from '../types';
4
- import { ScriptLocatorResolver, ScriptManager, Federated } from '@callstack/repack/client';
5
- import NetInfo from '@react-native-community/netinfo';
6
- import TcpSocket from 'react-native-tcp-socket';
7
- import { fetchMainVersionMap, getMainUrl } from './url_resolver';
8
-
9
- let config: Config;
10
- const RETRY_TIMER = 5000;
11
-
12
- const DevServer = props => {
13
- const connection = useRef<TcpSocket.Socket>();
14
- const partialMessage = useRef('');
15
- const messageLength = useRef(0);
16
- const messageType = useRef('');
17
- const _retryTimer = useRef<NodeJS.Timeout>();
18
-
19
- const [data, setData] = useState({
20
- platform: '',
21
- binaryVersion: '',
22
- dist: '',
23
- isStaging: false,
24
- });
25
- const _dataRef = useRef<typeof data>();
26
- const _versionMap = useRef<Record<string, string>>();
27
-
28
- const _onConnected = async (value: boolean) => {
29
- props.onConnected(value);
30
- };
31
-
32
- const onSocket = (handler) => msg => {
33
- let msgString: string = msg.toString();
34
- while (msgString.length > 0) {
35
- if (messageLength.current === 0) {
36
- const delimit = msgString.indexOf('\n');
37
- if (delimit === -1) {
38
- console.log("[Sleeper] Message header not found, throwing out message.");
39
- return;
40
- }
41
-
42
- const header = msgString.substring(0, delimit);
43
- try {
44
- const headerObject = JSON.parse(header);
45
- messageType.current = headerObject.type;
46
- messageLength.current = headerObject.size;
47
- } catch (e) {
48
- console.log("[Sleeper] Message header malformed, throwing out message.");
49
- messageLength.current = 0;
50
- messageType.current = '';
51
- return;
52
- }
53
-
54
- msgString = msgString.substring(delimit + 1);
55
- }
56
-
57
- const partialLength = messageLength.current - partialMessage.current.length;
58
- if (partialLength < 0) {
59
- // We need to wait for more data
60
- partialMessage.current += msgString;
61
- return;
62
- }
63
-
64
- const remainingLength = msgString.length - partialLength;
65
- if (remainingLength === 0) {
66
- // We have the full message
67
- partialMessage.current += msgString;
68
- msgString = '';
69
- if (config.logsEnabled) console.log("[Sleeper] Message built.", partialMessage.current.length);
70
-
71
- } else {
72
- // We have more than the full message
73
- partialMessage.current += msgString.substring(0, partialLength);
74
- msgString = msgString.substring(partialLength);
75
-
76
- if (remainingLength <= 0) {
77
- // We have less than the full message
78
- if (config.logsEnabled) console.log("[Sleeper] Building message: ", partialMessage.current.length, messageLength.current, remainingLength);
79
- return;
80
- }
81
- }
82
-
83
- try {
84
- const json = JSON.parse(partialMessage.current);
85
- partialMessage.current = '';
86
- messageLength.current = 0;
87
-
88
- // Set connection data
89
- if (json._platform || json._binaryVersion || json._dist || json._isStaging) {
90
- if (config.logsEnabled) console.log("[Sleeper] Processing context data:", json._platform, json._binaryVersion, json._dist, json._isStaging);
91
- setData({
92
- platform: json._platform,
93
- binaryVersion: json._binaryVersion,
94
- dist: json._dist,
95
- isStaging: json._isStaging,
96
- });
97
- }
98
-
99
- if (messageType.current === 'context') {
100
- // We should have a context object now
101
- const context = new Proxy(json, handler);
102
- props.onContextChanged(context);
103
- } else if (messageType.current === `partialContext`) {
104
- // We are updating a partial Context
105
- props.onContextUpdated(json)
106
- }
107
-
108
- messageType.current = '';
109
- } catch (e) {
110
- console.log("[Sleeper] Failed to parse message: ", e);
111
- return;
112
- }
113
- }
114
- };
115
-
116
- const sendContextRequest = (socket, propertyPath) => {
117
- const message: SocketMessage = {_contextGet: propertyPath};
118
- const json = JSON.stringify(message);
119
- try {
120
- socket?.write(json + '\n');
121
- } catch (e) {
122
- console.log("[Sleeper] Failed to send context request: ", e);
123
- }
124
- }
125
-
126
- const proxyHandler = (socket) => {
127
- return {
128
- get: (target, property) => {
129
- let value = Reflect.get(target, property);
130
-
131
- // Check if we need to add a proxy to this object
132
- if (!!value && typeof value === 'object' && !value._isProxy && value._isProxyInternal) {
133
- const isLeaf = !value._continueProxy;
134
- // Adding proxies to objects
135
- const handler = proxyHandlerChild(socket, property, isLeaf);
136
- const proxiedValue = new Proxy(value, handler);
137
- Reflect.set(target, property, proxiedValue);
138
- value = proxiedValue;
139
- }
140
-
141
- return value;
142
- }
143
- };
144
- }
145
-
146
- const proxyHandlerChild = (socket, path, isLeaf) => {
147
- return {
148
- get: (target, property) => {
149
- // Check if a proxy was already added to this object
150
- if (property === '_isProxy') {
151
- return true;
152
- }
153
-
154
- const value = Reflect.get(target, property);
155
- const fullPropertyPath = `${path}.${property}`;
156
-
157
- // If the value is undefined, we need to request it from the server
158
- if (value === undefined && isLeaf) {
159
- if (config.logsEnabled) console.log("[Sleeper] Requesting context value: ", fullPropertyPath);
160
- sendContextRequest(socket, fullPropertyPath);
161
- }
162
-
163
- // Check if we need to add a second layer proxy to this object
164
- if (!isLeaf && !value?._isProxy) {
165
- const nextLeaf = true; // Currently we only support 2 layers of proxies
166
- // Adding proxies to objects
167
- // These proxies aren't stored in the context object so we will regenerate them every time
168
- const handler = proxyHandlerChild(socket, fullPropertyPath, nextLeaf);
169
- if (value === undefined) {
170
- return new Proxy({}, handler);
171
- } else {
172
- return new Proxy(value, handler);
173
- }
174
- }
175
-
176
- return value;
177
- }
178
- };
179
- }
180
-
181
- const startSocket = async () => {
182
- const netInfo = await NetInfo.fetch();
183
- const netInfoDetails = netInfo?.details;
184
- const ipAddress = netInfoDetails?.ipAddress;
185
-
186
- if (!netInfoDetails || !('ipAddress' in netInfoDetails)) {
187
- console.error('[Sleeper] Failed to determine local IP address.');
188
- return stopSocket();
189
- }
190
-
191
- connection.current = TcpSocket.createConnection({
192
- port: config.remoteSocketPort || 9092,
193
- host: config.remoteIP,
194
- localAddress: ipAddress,
195
- reuseAddress: true,
196
- }, () => {
197
- // When we establish a connection, send the IP address to the server
198
- const message: SocketMessage = {
199
- _ip: ipAddress,
200
- _name: config.name,
201
- };
202
- const json = JSON.stringify(message);
203
- console.log('[Sleeper] Send IP address: ', ipAddress, config.name);
204
- try {
205
- connection.current?.write(json + '\n', "utf8", (error) => {
206
- if (error) {
207
- return stopSocket();
208
- }
209
- console.log('[Sleeper] Connected to the Sleeper App.');
210
- _onConnected(true);
211
- });
212
- } catch (e) {
213
- return stopSocket();
214
- }
215
- });
216
-
217
- connection.current.on('data', (data, ...args) => {
218
- const handler = proxyHandler(connection.current);
219
- const onSocketHandler = onSocket(handler);
220
- onSocketHandler(data);
221
- });
222
- connection.current.on('error', err => {
223
- return stopSocket();
224
- });
225
- connection.current.on('close', (hadError) => {
226
- return stopSocket();
227
- });
228
- }
229
-
230
- const stopSocket = (retry = true) => {
231
- _onConnected(false);
232
-
233
- if (connection.current) {
234
- connection.current.destroy();
235
- connection.current = undefined;
236
- }
237
-
238
- // Any time the socket is closed, attempt to connect again.
239
- if (retry) {
240
- clearTimeout(_retryTimer.current);
241
- _retryTimer.current = setTimeout(() => {
242
- console.log('[Sleeper] Unable to connect to sleeper, retrying...');
243
- startSocket();
244
- }, RETRY_TIMER);
245
- }
246
- }
247
-
248
- const _waitForInitialization = () => {
249
- return new Promise<void>((resolve) => {
250
- (function checkData() {
251
- let isInitialized = !!_dataRef.current?.dist;
252
-
253
- // Non-staging builds also require a version map to be defined.
254
- if (!_dataRef.current?.isStaging) {
255
- isInitialized = !!_versionMap.current;
256
- }
257
-
258
- if (isInitialized) return resolve();
259
- setTimeout(checkData, 1000);
260
- })();
261
- });
262
- };
263
-
264
- const _resolveRemoteChunk: ScriptLocatorResolver = async (scriptId: string, caller: string) => {
265
- await _waitForInitialization();
266
-
267
- const bundleName = !caller ? `${scriptId}.container.bundle` : `${scriptId}.chunk.bundle`;
268
-
269
- // Try to resolve URL based on scriptId and caller
270
- const url = getMainUrl(scriptId, caller, {
271
- platform: _dataRef.current?.platform,
272
- bundleVersion: _versionMap.current?.[bundleName],
273
- binaryVersion: _dataRef.current?.binaryVersion,
274
- dist: _dataRef.current?.dist,
275
- isStaging: _dataRef.current?.isStaging,
276
- remoteIP: config.remoteIP,
277
- dev: config.dev,
278
- });
279
- const query = config.dev ? {platform: Platform.OS} : undefined;
280
-
281
- if (config.logsEnabled) console.log('[Sleeper] load script:', scriptId, caller, url);
282
- return {url, query};
283
- }
284
-
285
- const _fetchVersionMap = async (platform, binaryVersion, dist) => {
286
- _versionMap.current = await fetchMainVersionMap(platform, binaryVersion, dist);
287
- }
288
-
289
- useEffect(() => {
290
- _dataRef.current = data;
291
- if (!data.platform || !data.binaryVersion || !data.dist) return;
292
-
293
- _fetchVersionMap(data.platform, data.binaryVersion, data.dist);
294
- }, [data.platform, data.binaryVersion, data.dist, data.isStaging]);
295
-
296
- useEffect(() => {
297
- if (!config) {
298
- console.error('[Sleeper] No config file specified. Please make sure you call DevServer.init() early in the app lifecycle.');
299
- return;
300
- }
301
-
302
- ScriptManager.shared.addResolver(_resolveRemoteChunk.bind(this));
303
- startSocket();
304
-
305
- return () => {
306
- stopSocket(false);
307
- };
308
- }, []);
309
-
310
- return <></>;
311
- };
312
-
313
- DevServer.init = (_config: Config) => {
314
- config = _config;
315
- }
316
-
317
- export default DevServer;
@@ -1,4 +0,0 @@
1
- // preload shared packages that require initialization during startup
2
- import 'lodash';
3
- import 'react-native-svg';
4
- import 'react-native-linear-gradient';