esoftplay 0.0.246 → 0.0.248

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.
Files changed (39) hide show
  1. package/error.ts +1 -170
  2. package/esp.ts +2 -292
  3. package/global.ts +2 -276
  4. package/lazy.ts +2 -31
  5. package/mmkv.ts +2 -48
  6. package/modules/lib/version.tsx +14 -2
  7. package/modules/sys/error.ts +171 -0
  8. package/modules/sys/esp.ts +295 -0
  9. package/modules/sys/global.ts +278 -0
  10. package/modules/sys/lazy.ts +33 -0
  11. package/modules/sys/mmkv.ts +49 -0
  12. package/{mmkv.web.ts → modules/sys/mmkv.web.ts} +2 -0
  13. package/modules/sys/moment.ts +180 -0
  14. package/{oneplusfixfont.ts → modules/sys/oneplusfixfont.ts} +1 -0
  15. package/modules/sys/persist.ts +47 -0
  16. package/modules/sys/state.ts +34 -0
  17. package/modules/sys/storage.ts +90 -0
  18. package/modules/sys/subscribe.ts +53 -0
  19. package/modules/sys/timeout.ts +98 -0
  20. package/moment.ts +2 -178
  21. package/package.json +1 -1
  22. package/persist.ts +2 -45
  23. package/render.ts +3 -0
  24. package/state.ts +2 -32
  25. package/storage.ts +2 -88
  26. package/subscribe.ts +2 -51
  27. package/timeout.ts +2 -96
  28. /package/{error.d.ts → modules/sys/error.d.ts} +0 -0
  29. /package/{esp.d.ts → modules/sys/esp.d.ts} +0 -0
  30. /package/{global.d.ts → modules/sys/global.d.ts} +0 -0
  31. /package/{lazy.d.ts → modules/sys/lazy.d.ts} +0 -0
  32. /package/{mmkv.d.ts → modules/sys/mmkv.d.ts} +0 -0
  33. /package/{moment.d.ts → modules/sys/moment.d.ts} +0 -0
  34. /package/{persist.d.ts → modules/sys/persist.d.ts} +0 -0
  35. /package/{render.tsx → modules/sys/render.tsx} +0 -0
  36. /package/{state.d.ts → modules/sys/state.d.ts} +0 -0
  37. /package/{storage.d.ts → modules/sys/storage.d.ts} +0 -0
  38. /package/{subscribe.d.ts → modules/sys/subscribe.d.ts} +0 -0
  39. /package/{timeout.d.ts → modules/sys/timeout.d.ts} +0 -0
package/error.ts CHANGED
@@ -1,170 +1 @@
1
- import * as Application from 'expo-application';
2
- import Constants from 'expo-constants';
3
- import * as FileSystem from 'expo-file-system';
4
- import { Platform } from 'react-native';
5
- import { LibCurl } from './cache/lib/curl/import';
6
- import { LibNavigationProperty } from './cache/lib/navigation/import';
7
- import { UserClass } from './cache/user/class/import';
8
- import esp from './esp';
9
- import FastStorage from './mmkv';
10
- import { default as UserRoutes } from './modules/user/routes';
11
- let pack = require('../../package.json');
12
- let app = require('../../app.json');
13
- const { expoConfig } = Constants;
14
-
15
- function getTime() {
16
- const adjustedDate = new Date().getTime() + 7 * 60 * 60000; // Add offset in milliseconds
17
- const isoStringWithGMTPlus7 = new Date(adjustedDate).toISOString();
18
- return isoStringWithGMTPlus7.replace('T', ' ').replace(/\.[0-9]+Z/g, "")
19
- }
20
- const defaultErrorHandler = ErrorUtils?.getGlobalHandler?.()
21
-
22
- const myErrorHandler = (e: any, isFatal: any) => {
23
- if (!__DEV__)
24
- setError(e)
25
- defaultErrorHandler?.(e, isFatal)
26
- }
27
-
28
- /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/error.md#setError) untuk melihat dokumentasi*/
29
- export function setError(error?: any) {
30
- const config = esp?.config?.();
31
- const routes = UserRoutes?.state()?.get?.();
32
- const user = UserClass?.state()?.get?.();
33
- const routesName = routes?.routes?.map((x) => x.name)
34
-
35
- const _e = {
36
- user,
37
- error: String(error),
38
- routes: routesName,
39
- args: LibNavigationProperty.lastArgs.get(),
40
- time: getTime()
41
- };
42
- try {
43
- FastStorage.setItem(`${config?.domain}error`, JSON.stringify(_e));
44
- cleanCache()
45
- } catch (e) {
46
- console.error(e);
47
- }
48
- }
49
-
50
-
51
- /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/error.md#reportApiError) untuk melihat dokumentasi*/
52
- export function reportApiError(fetch: any, error: any) {
53
- let routes = UserRoutes?.state?.()?.get?.()
54
- let lastIndex = routes?.routes?.length - 1 ?? 0
55
- const user = UserClass?.state?.()?.get?.()
56
- let config = esp?.config?.()
57
- let msg = [
58
- 'slug: ' + "#" + expoConfig?.slug,
59
- 'error: ' + error,
60
- '\n\n\ndev: ' + Platform.OS + ' - ' + Constants.deviceName,
61
- 'time: ' + getTime(),
62
- 'runtimeVersion:' + app.expo.runtimeVersion,
63
- 'app/pub_id: ' + Constants.appOwnership + '/' + (config?.publish_id || '-'),
64
- 'user_id: ' + user?.id || user?.user_id || '-',
65
- 'username: ' + user?.username || '-',
66
- 'module:' + routes?.routes?.[lastIndex]?.name,
67
- 'fetch: ' + String(JSON.stringify(fetch || {}, undefined, 2)).replace(/[\[\]\{\}\"]+/g, ''),
68
- ].join('\n')
69
-
70
- if (__DEV__) {
71
- let post = {
72
- text: msg,
73
- chat_id: '-1001737180019',
74
- disable_web_page_preview: true
75
- }
76
- new LibCurl()?.custom?.('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
77
- } else {
78
- const telegramIds = config?.errorReport?.telegramIds || {}
79
- Object.values(telegramIds).forEach?.(id => {
80
- let post = {
81
- text: msg,
82
- chat_id: id,
83
- disable_web_page_preview: true
84
- }
85
- new LibCurl()?.custom?.('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
86
- });
87
- }
88
- }
89
-
90
- /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/error.md#sendTm) untuk melihat dokumentasi*/
91
- export function sendTm(message: string, chat_id?: string, bot?: string, res?: (result: any) => void): void {
92
- let _chatids: string[] = []
93
- if (chat_id) {
94
- _chatids = [chat_id]
95
- } else {
96
- let config = esp?.config?.()
97
- _chatids = Object.values(config?.errorReport?.telegramIds)
98
- }
99
- _chatids.forEach((cid: string) => {
100
- let post = {
101
- text: message,
102
- chat_id: cid,
103
- disable_web_page_preview: true
104
- }
105
- const _bot = bot || "923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4"
106
- new LibCurl()?.custom?.(`https://api.telegram.org/bot${_bot}/sendMessage`, post, res)
107
- })
108
- }
109
-
110
- /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/error.md#getError) untuk melihat dokumentasi*/
111
- export function getError() {
112
- let config = esp?.config?.()
113
- FastStorage.getItem(config?.domain + 'error').then((e: any) => {
114
- if (e) {
115
- cleanCache()
116
- let _e = JSON.parse(e)
117
- let msg = [
118
- 'slug: ' + "#" + expoConfig?.slug,
119
- 'error: \n' + _e.error,
120
- '\n\nname: ' + expoConfig?.name + ' - sdk' + pack?.dependencies?.expo,
121
- 'time: \n' + _e?.time,
122
- 'domain: ' + config.domain + config.uri,
123
- 'runtimeVersion:' + app.expo.runtimeVersion,
124
- 'package: ' + (Application.nativeBuildVersion) + ' - v' + (Platform.OS == 'ios' ? app.expo.ios.buildNumber : app.expo.android.versionCode),
125
- 'device: ' + Platform.OS + ' | ' + Constants.deviceName,
126
- 'native/pub_id: ' + expoConfig?.sdkVersion + '/' + (config?.publish_id || '-'),
127
- 'user_id: ' + _e?.user?.id || _e?.user?.user_id || '-',
128
- 'username: ' + _e?.user?.username || '-',
129
- 'module: ' + _e.routes,
130
- ].join('\n')
131
- // config?.errorReport?.telegramIds?.forEach?.((id: string) => {
132
- if (msg.includes(`Invariant Violation: "main" has not been registered. This can happen if`)) {
133
- // remove error that unsolved
134
- } else if (msg.includes(`deleteAdsCache`)) {
135
- // remove error that unsolved
136
- } else if (msg.includes(`SyntaxError: JSON Parse error: Unexpected token:`)) {
137
- // remove error that unsolved
138
- } else if (msg.includes(`FirebaseError: [code=invalid-argument]`)) {
139
- let post = {
140
- text: msg,
141
- chat_id: '-1001737180019',
142
- disable_web_page_preview: true
143
- }
144
- new LibCurl()?.custom?.('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
145
- } else {
146
- const telegramIds = config?.errorReport?.telegramIds || {}
147
- Object.values(telegramIds).forEach?.(id => {
148
- let post = {
149
- text: msg,
150
- chat_id: id,
151
- disable_web_page_preview: true
152
- }
153
- new LibCurl()?.custom?.('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
154
- });
155
- }
156
-
157
- FastStorage.removeItem(config.domain + 'error')
158
- }
159
- })
160
- }
161
-
162
- function cleanCache() {
163
- try {
164
- // try remove cache after errors
165
- if (FileSystem.cacheDirectory) {
166
- FileSystem.deleteAsync(FileSystem.cacheDirectory, { idempotent: true });
167
- }
168
- } catch (error) { }
169
- }
170
- ErrorUtils.setGlobalHandler(myErrorHandler)
1
+ export * from '../../node_modules/esoftplay/modules/sys/error';
package/esp.ts CHANGED
@@ -1,293 +1,3 @@
1
- import { EspAssets } from 'esoftplay/cache/assets';
2
- import cacheConfig from 'esoftplay/cache/config.json';
3
- import { LibLocale } from 'esoftplay/cache/lib/locale/import';
4
- import { EspRouterPropertyInterface } from 'esoftplay/cache/properties';
5
- import { EspRouterInterface } from 'esoftplay/cache/routers';
6
- import * as Application from 'expo-application';
7
- import { LogBox, Platform } from 'react-native';
8
- import 'react-native-reanimated';
9
- import './oneplusfixfont';
1
+ export * from '../../node_modules/esoftplay/modules/sys/esp';
2
+ export { default } from '../../node_modules/esoftplay/modules/sys/esp';
10
3
 
11
- type ConfigType = typeof cacheConfig
12
-
13
- const ignoreWarns = [
14
- "Setting a timer for a long period of time",
15
- "VirtualizedLists should never be nested inside plain ScrollViews with the same orientation",
16
- "ViewPropTypes will be removed",
17
- "AsyncStorage has been extracted from react-native",
18
- "EventEmitter.removeListener",
19
- "Got a component with the name 'm'",
20
- "Did not receive response to shouldStartLoad in time",
21
- "startLoadWithResult invoked with invalid lockldentifier",
22
- ];
23
-
24
-
25
- const err = console.error;
26
- console.error = (...arg) => {
27
- for (let i = 0; i < ignoreWarns.length; i++) {
28
- if (arg?.[0]?.startsWith?.(ignoreWarns[i])) return;
29
- }
30
- err(...arg);
31
- };
32
-
33
- const warn = console.warn;
34
- console.warn = (...arg) => {
35
- for (let i = 0; i < ignoreWarns.length; i++) {
36
- if (arg?.[0]?.startsWith?.(ignoreWarns[i])) return;
37
- }
38
- warn(...arg);
39
- };
40
- LogBox.ignoreLogs(ignoreWarns);
41
-
42
- let app = require('../../app.json');
43
- let conf = require('../../config.json');
44
- if (!__DEV__) {
45
- if (Platform.OS == 'web') {
46
- conf.config.domain = window.location.hostname
47
- }
48
- }
49
- let lconf: any
50
- try {
51
- lconf = require('../../config.live.json');
52
- } catch (error) {
53
-
54
- }
55
- if (conf?.config?.isDebug == 0)
56
- LogBox.ignoreAllLogs();
57
- /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/esp.md) untuk melihat dokumentasi*/
58
- const esp = {
59
- mergeDeep(target, ...sources) {
60
- target = Object(target);
61
-
62
- for (const source of sources) {
63
- const sourceObj = Object(source);
64
-
65
- for (const [key, value] of Object.entries(sourceObj)) {
66
- if (value !== undefined && value !== null) {
67
- if (Array.isArray(value)) {
68
- // Overwrite arrays completely
69
- target[key] = value.slice(); // shallow copy
70
- } else if (typeof value === "object") {
71
- target[key] = esp.mergeDeep(target[key] ?? {}, value);
72
- } else {
73
- target[key] = value;
74
- }
75
- }
76
- }
77
- }
78
-
79
- return target;
80
- },
81
- appjson(): any {
82
- return esp.mergeDeep(app, conf)
83
- },
84
- assets(path: EspAssets): any {
85
- const _assets = require('./cache/assets')
86
- return _assets(path)
87
- },
88
- versionName(): string {
89
- return (Application.nativeBuildVersion) + '-' + esp.config('publish_id')
90
- },
91
- config<T = ConfigType>(param?: keyof ConfigType, ...params: string[]): T {
92
- let out: any = this._config();
93
- if (param) {
94
- const _params = [param, ...params];
95
- for (let i = 0; i < _params.length; i++) {
96
- const key = _params[i];
97
- if (out && typeof out === 'object' && out.hasOwnProperty(key)) {
98
- out = out[key];
99
- } else {
100
- return {} as T; // Return empty object if key doesn't exist
101
- }
102
- }
103
- }
104
-
105
- return out as T;
106
- },
107
- isDebug(message: string): boolean {
108
- if (!lconf) {
109
- return false
110
- }
111
- return conf.config.domain != lconf.config.domain
112
- },
113
- readDeepObj(obj: any) {
114
- return function (param?: string, ...params: string[]): any {
115
- let out: any = obj
116
- if (param) {
117
- var _params = [param, ...params]
118
- if (_params.length > 0)
119
- for (let i = 0; i < _params.length; i++) {
120
- out = out?.[_params[i]];
121
- if (out == undefined) {
122
- break;
123
- }
124
- }
125
- }
126
- return out;
127
- }
128
- },
129
- lang<T extends keyof EspRouterInterface>(moduleTask: T, langName: string, ...stringToBe: string[]): string {
130
- let string = LibLocale.stateLang().get()?.[esp.langId()]?.[moduleTask]?.[langName]
131
- if (!string) {
132
- string = esp.assets("locale/id.json")?.[moduleTask]?.[langName]
133
- }
134
- function sprintf(string: string, index: number): string {
135
- if (stringToBe[index] != undefined) {
136
- string = string?.replace?.("%s", stringToBe[index])
137
- if (string?.includes?.("%s")) {
138
- return sprintf(string, index + 1)
139
- }
140
- }
141
- return string
142
- }
143
- if (string.includes("%s")) {
144
- string = sprintf(string, 0)
145
- }
146
- return string
147
- },
148
- langId(): string {
149
- const LibLocale = esp.mod('lib/locale');
150
- return LibLocale.state().get()
151
- },
152
- mod<T extends keyof EspRouterInterface>(path: T): EspRouterInterface[T] {
153
- var modtast = path.split("/");
154
- if (modtast[1] == "") {
155
- modtast[1] = "index";
156
- }
157
- const routers = require('./cache/routers')
158
- return routers(modtast.join("/"));
159
- },
160
- modProp<T extends keyof EspRouterPropertyInterface>(path: T): EspRouterPropertyInterface[T] {
161
- var modtast = path.split("/");
162
- if (modtast[1] == "") {
163
- modtast[1] = "index";
164
- }
165
- const properties = require('./cache/properties')
166
- return properties(modtast.join("/"));
167
- },
168
- _config(): typeof cacheConfig {
169
- app = esp.mergeDeep(app, conf)
170
- var msg = ''
171
- if (!app.hasOwnProperty('config')) {
172
- msg = "tidak ada config"
173
- } else if (!app.config.hasOwnProperty('domain') || app.config.domain.length == 0) {
174
- msg = "config tidak ada domain"
175
- } else if (!app.config.hasOwnProperty('salt') || app.config.salt.length == 0) {
176
- msg = "config tidak ada salt"
177
- } else if (!app.config.hasOwnProperty("experienceId") || app.config.experienceId.length == 0) {
178
- msg = "config experienceId harus diisi dengan @esoftplay/[slug]"
179
- }
180
- if (msg != '') {
181
- let error = new Error(msg);
182
- throw error;
183
- }
184
-
185
- const config = {
186
- // default config
187
- timezone: "Asia/Jakarta",
188
- protocol: "http",
189
- uri: "/",
190
- api: "api",
191
- data: "data",
192
- home: {
193
- member: "content/index",
194
- public: "content/index"
195
- },
196
- group_id: 0,
197
- langIds: ["id", "en"],
198
- theme: ["light", "dark"],
199
- comment_login: 1,
200
- notification: 0,
201
- ...app.config
202
- }
203
-
204
- if (!config.hasOwnProperty('url') || config.url.length == 0) {
205
- config.url = config.protocol + "://" + config.api + "." + config.domain + config.uri;
206
- }
207
- if (!config.hasOwnProperty('content') || config.content.length == 0) {
208
- config.content = config.protocol + "://" + config.data + "." + config.domain + config.uri;
209
- }
210
- config.webviewOpen = '<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link href="' + config.content + 'user/editor_css" rel="stylesheet" /> <script type="text/javascript">var _ROOT="' + config.uri + '";var _URL="' + config.content + '";function _Bbc(a,b){var c="BS3load_func";if(!window[c+"i"]){window[c+"i"]=0};window[c+"i"]++;if(!b){b=c+"i"+window[c+"i"]};if(!window[c]){window[c]=b}else{window[c]+=","+b}window[b]=a;if(typeof BS3!="undefined"){window[b](BS3)}};</script> <style type="text/css">body {padding: 0 20px;}</style></head> <body>';
211
- config.webviewClose = '<script src="' + config.content + 'templates/admin/bootstrap/js/bootstrap.min.js"></script> </body> </html>';
212
- return config;
213
- },
214
- navigations(): string[] {
215
- const navs = require('./cache/navs').default
216
- return navs;
217
- },
218
- home(): any {
219
- return esp.mod('user/index');
220
- },
221
- routes(): any {
222
- const UserRoutes = esp.mod('user/routes');
223
- return UserRoutes.state().get();
224
- },
225
- log(message?: any, ...optionalParams: any[]) {
226
- if (esp.config("isDebug") == 1) {
227
- let out = [message]
228
- if (optionalParams)
229
- out.push(...optionalParams)
230
- out.forEach((x) => {
231
- if (x != undefined)
232
- console.log(JSON.stringify(x, undefined, 2), "\x1b[0m");
233
- else
234
- console.log(x, "\x1b[0m")
235
- })
236
- }
237
- },
238
- condition() {
239
- let result: any = undefined;
240
- function ifFunc(condition: boolean, value: any) {
241
- if (result === undefined && condition)
242
- result = value;
243
- return api;
244
- }
245
-
246
- function elseFunc(value: any) {
247
- if (result === undefined)
248
- result = value;
249
- return api;
250
- }
251
-
252
- function valueFunc() {
253
- return result;
254
- }
255
-
256
- const api = {
257
- if: ifFunc,
258
- elseif: ifFunc,
259
- else: elseFunc,
260
- getValue: valueFunc,
261
- };
262
-
263
- return api;
264
- },
265
- logColor: {
266
- reset: "\x1b[0m",
267
- black: "\x1b[30m",
268
- red: "\x1b[31m",
269
- green: "\x1b[32m",
270
- yellow: "\x1b[33m",
271
- blue: "\x1b[34m",
272
- magenta: "\x1b[35m",
273
- cyan: "\x1b[36m",
274
- white: "\x1b[37m",
275
- backgroundBlack: "\x1b[40m",
276
- backgroundRed: "\x1b[41m",
277
- backgroundGreen: "\x1b[42m",
278
- backgroundYellow: "\x1b[43m",
279
- backgroundBlue: "\x1b[44m",
280
- backgroundMagenta: "\x1b[45m",
281
- backgroundCyan: "\x1b[46m",
282
- backgroundWhite: "\x1b[47m",
283
- }
284
- }
285
-
286
- export default esp
287
-
288
- // var a = esp.assets("bacground") // mengambil file dari folder images
289
- // var b = esp.config("data", "name") // mengambil value dari config (bisa ditentukan di app.json)
290
- // var c = esp.mod("module/task") // mengeksekusi module/task
291
- // var e = esp.home() // mengkesekusi module/task untuk halaman pertama
292
- // var f = esp.log("pesan") // log yang tampil jika di app.json -> isDebug == 1
293
- // var g = esp.routes() // mengambil history status navigasi yang sedang berjalan