esoftplay 0.0.108-u → 0.0.108-y
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/bin/router.js +2 -2
- package/modules/lib/curl.ts +73 -27
- package/modules/lib/input_base.tsx +2 -0
- package/modules/lib/progress.tsx +1 -0
- package/package.json +1 -1
- package/state.ts +2 -2
package/bin/router.js
CHANGED
|
@@ -247,7 +247,7 @@ checks.forEach(modules => {
|
|
|
247
247
|
}
|
|
248
248
|
/* REGEX All Functions */
|
|
249
249
|
if (!isHooks && !isUseLibs) {
|
|
250
|
-
var r = /\n(\s+)((?:(?:static|public|private|async)\s+)?[a-zA-Z0-9_]{3,}\s{0,}(?:<S>|)(?:=\s{0,})?\([^{\n]+)/g; // 1=spaces 2=FunctionObject
|
|
250
|
+
var r = /\n(\s+)((?:(?:static|public|private|protected|public async|private async|protected async|async)\s+)?[a-zA-Z0-9_]{3,}\s{0,}(?:<S>|)(?:=\s{0,})?\([^{\n]+)/g; // 1=spaces 2=FunctionObject
|
|
251
251
|
if (s = r.exec(data)) {
|
|
252
252
|
if (m = data.match(r)) {
|
|
253
253
|
/* check jika class tersebut nge replace bukan nge extends maka hapus semua fungsi bawaan dari supernya */
|
|
@@ -257,7 +257,7 @@ checks.forEach(modules => {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
for (var i = 0; i < m.length; i++) {
|
|
260
|
-
if (S = m[i].match(/\n([^\na-zA-Z0-9_]+)((?:(?:static|public|private|async)\s+)?[a-zA-Z0-9_]{3,})/)) {
|
|
260
|
+
if (S = m[i].match(/\n([^\na-zA-Z0-9_]+)((?:(?:static|public|private|protected|public async|private async|protected async|async)\s+)?[a-zA-Z0-9_]{3,})/)) {
|
|
261
261
|
if (S[1] === s[1].replace(new RegExp('\n', 'g'), '')) {
|
|
262
262
|
var a = m[i].trim().replace('async ', '') + ";"
|
|
263
263
|
tmpTask[clsName]["function"][S[2]] = a;
|
package/modules/lib/curl.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { reportApiError } from "esoftplay/error";
|
|
|
4
4
|
import moment from "esoftplay/moment";
|
|
5
5
|
const axios = require('axios');
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
export default class ecurl {
|
|
9
8
|
timeout = 55000;
|
|
10
9
|
timeoutContext: any = null;
|
|
@@ -14,6 +13,7 @@ export default class ecurl {
|
|
|
14
13
|
url: any = esp.config('url')
|
|
15
14
|
apiKey: any = 0
|
|
16
15
|
uri: any = '';
|
|
16
|
+
isSecure: boolean = false
|
|
17
17
|
fetchConf: any = ''
|
|
18
18
|
alertTimeout = {
|
|
19
19
|
title: "Oops..! Gagal menyambung ke server",
|
|
@@ -39,17 +39,19 @@ export default class ecurl {
|
|
|
39
39
|
this.onError = this.onError.bind(this)
|
|
40
40
|
this.setApiKey = this.setApiKey.bind(this)
|
|
41
41
|
this.secure = this.secure.bind(this)
|
|
42
|
+
this.withHeader = this.withHeader.bind(this)
|
|
42
43
|
this.initTimeout = this.initTimeout.bind(this)
|
|
43
44
|
this.cancelTimeout = this.cancelTimeout.bind(this)
|
|
45
|
+
// this.createApiTesterUris = this.createApiTesterUris.bind(this)
|
|
44
46
|
const str: any = LibNet_status.state().get()
|
|
45
47
|
if (uri && str.isOnline) {
|
|
46
48
|
this.init(uri, post, onDone, onFailed, debug);
|
|
47
49
|
} else if (!str.isOnline && onFailed) {
|
|
48
|
-
onFailed("Failed to access", false);
|
|
50
|
+
onFailed(this.refineErrorMessage("Failed to access"), false);
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
initTimeout(customTimeout?: number): void {
|
|
54
|
+
protected initTimeout(customTimeout?: number): void {
|
|
53
55
|
this.cancelTimeout()
|
|
54
56
|
this.timeoutContext = setTimeout(() => {
|
|
55
57
|
if (this.abort?.cancel) {
|
|
@@ -60,28 +62,57 @@ export default class ecurl {
|
|
|
60
62
|
}, customTimeout ?? this.timeout);
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
cancelTimeout(): void {
|
|
65
|
+
private cancelTimeout(): void {
|
|
64
66
|
clearTimeout(this.timeoutContext)
|
|
65
67
|
this.timeoutContext = null;
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
onFetchFailed(message: string): void {
|
|
70
|
+
private onFetchFailed(message: string): void {
|
|
69
71
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
setUrl(url: string): void {
|
|
74
|
+
protected setUrl(url: string): void {
|
|
73
75
|
this.url = url
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
setUri(uri: string): void {
|
|
78
|
+
protected setUri(uri: string): void {
|
|
77
79
|
this.uri = uri
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
// createApiTesterUris(): void {
|
|
83
|
+
|
|
84
|
+
// if (esp.isDebug('onlyAvailableOnDebug')) {
|
|
85
|
+
// setTimeout(() => {
|
|
86
|
+
// const options = this.fetchConf.options
|
|
87
|
+
// const msg = this.uri.replace('/', '.').split('?')[0] + `
|
|
88
|
+
// /* RARE USAGE : to simulate LibCurl().secure() : default false */
|
|
89
|
+
// const IS_SECURE_POST = `+ this.isSecure + `
|
|
90
|
+
|
|
91
|
+
// const EXTRACT = []
|
|
92
|
+
// const EXTRACT_CHECK = []
|
|
93
|
+
|
|
94
|
+
// const GET = {`+ JSON.stringify(LibUtils.getUrlParams(options?.url) || '') + `
|
|
95
|
+
// }
|
|
96
|
+
|
|
97
|
+
// const POST = {`+ options._post + `
|
|
98
|
+
// }
|
|
99
|
+
// module.exports = { POST, GET, IS_SECURE_POST, EXTRACT, EXTRACT_CHECK }
|
|
100
|
+
// `
|
|
101
|
+
// let post = {
|
|
102
|
+
// text: msg,
|
|
103
|
+
// chat_id: '-626800023',
|
|
104
|
+
// disable_web_page_preview: true
|
|
105
|
+
// }
|
|
106
|
+
// this.custom('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
|
|
107
|
+
// }, 1000);
|
|
108
|
+
// }
|
|
109
|
+
// }
|
|
110
|
+
|
|
111
|
+
protected setApiKey(apiKey: string): void {
|
|
81
112
|
this.apiKey = apiKey
|
|
82
113
|
}
|
|
83
114
|
|
|
84
|
-
async setHeader(): Promise<void> {
|
|
115
|
+
protected async setHeader(): Promise<void> {
|
|
85
116
|
return new Promise((r) => {
|
|
86
117
|
if ((/:\/\/data.*?\/(.*)/g).test(this.url)) {
|
|
87
118
|
this.header["masterkey"] = new LibCrypt().encode(this.url)
|
|
@@ -90,25 +121,26 @@ export default class ecurl {
|
|
|
90
121
|
});
|
|
91
122
|
}
|
|
92
123
|
|
|
93
|
-
closeConnection(): void {
|
|
124
|
+
protected closeConnection(): void {
|
|
94
125
|
this?.abort?.cancel('Oops, Sepertinya ada gangguan jaringan... Silahkan coba beberapa saat lagi');
|
|
95
126
|
}
|
|
96
127
|
|
|
97
|
-
onDone(result: any, msg?: string): void {
|
|
128
|
+
protected onDone(result: any, msg?: string): void {
|
|
98
129
|
|
|
99
130
|
}
|
|
100
131
|
|
|
101
|
-
onFailed(msg: string, timeout: boolean): void {
|
|
132
|
+
protected onFailed(msg: string, timeout: boolean): void {
|
|
102
133
|
|
|
103
134
|
}
|
|
104
135
|
|
|
105
|
-
onStatusCode(ok: number, status_code: number, message: string, result: any): boolean {
|
|
136
|
+
protected onStatusCode(ok: number, status_code: number, message: string, result: any): boolean {
|
|
106
137
|
return true
|
|
107
138
|
}
|
|
108
139
|
|
|
109
|
-
secure(token_uri?: string): (apiKey?: string) => (uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number) => void {
|
|
140
|
+
public secure(token_uri?: string): (apiKey?: string) => (uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number) => void {
|
|
110
141
|
return (apiKey?: string): (uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number) => void => {
|
|
111
142
|
return async (uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number) => {
|
|
143
|
+
this.isSecure = true
|
|
112
144
|
await this.setHeader();
|
|
113
145
|
const _apiKey = apiKey || this.apiKey
|
|
114
146
|
Object.keys(post).forEach((key) => {
|
|
@@ -146,7 +178,7 @@ export default class ecurl {
|
|
|
146
178
|
this.init(uri, { ...post, access_token: res }, onDone, onFailed, debug);
|
|
147
179
|
}, (msg) => {
|
|
148
180
|
if (onFailed)
|
|
149
|
-
onFailed(msg, false)
|
|
181
|
+
onFailed(this.refineErrorMessage(msg), false)
|
|
150
182
|
}, debug)
|
|
151
183
|
}).catch((r: string) => {
|
|
152
184
|
this.cancelTimeout();
|
|
@@ -157,7 +189,12 @@ export default class ecurl {
|
|
|
157
189
|
}
|
|
158
190
|
}
|
|
159
191
|
|
|
160
|
-
|
|
192
|
+
public withHeader(header: any): (uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number) => void {
|
|
193
|
+
this.header = { ...this.header, ...header }
|
|
194
|
+
return (uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number) => this.init(uri, post, onDone, onFailed, debug)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public upload(uri: string, postKey: string, fileUri: string, mimeType: string, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number): void {
|
|
161
198
|
postKey = postKey || "image";
|
|
162
199
|
var uName = fileUri.substring(fileUri.lastIndexOf("/") + 1, fileUri.length);
|
|
163
200
|
if (!uName.includes('.')) {
|
|
@@ -168,7 +205,7 @@ export default class ecurl {
|
|
|
168
205
|
this.init(uri, post, onDone, onFailed, debug, true)
|
|
169
206
|
}
|
|
170
207
|
|
|
171
|
-
urlEncode(str: string): string {
|
|
208
|
+
private urlEncode(str: string): string {
|
|
172
209
|
return str
|
|
173
210
|
.replace(/\!/g, '%21')
|
|
174
211
|
.replace(/\'/g, '%27')
|
|
@@ -178,7 +215,7 @@ export default class ecurl {
|
|
|
178
215
|
.replace(/%20/g, '+')
|
|
179
216
|
}
|
|
180
217
|
|
|
181
|
-
encodeGetValue(_get: string): string {
|
|
218
|
+
private encodeGetValue(_get: string): string {
|
|
182
219
|
if (_get != '') {
|
|
183
220
|
let hashes = _get.split('&')
|
|
184
221
|
let params: any = {}
|
|
@@ -200,7 +237,7 @@ export default class ecurl {
|
|
|
200
237
|
return _get
|
|
201
238
|
}
|
|
202
239
|
|
|
203
|
-
signatureBuild(): string {
|
|
240
|
+
private signatureBuild(): string {
|
|
204
241
|
let signature = '';
|
|
205
242
|
if (this.url.includes(esp.config('url'))) {
|
|
206
243
|
let payload = '';
|
|
@@ -224,7 +261,7 @@ export default class ecurl {
|
|
|
224
261
|
return signature
|
|
225
262
|
}
|
|
226
263
|
|
|
227
|
-
async custom(uri: string, post?: any, onDone?: (res: any, timeout: boolean) => void, debug?: number): Promise<void> {
|
|
264
|
+
public async custom(uri: string, post?: any, onDone?: (res: any, timeout: boolean) => void, debug?: number): Promise<void> {
|
|
228
265
|
const str: any = LibNet_status.state().get()
|
|
229
266
|
if (str.isOnline) {
|
|
230
267
|
if (post) {
|
|
@@ -276,7 +313,7 @@ export default class ecurl {
|
|
|
276
313
|
}
|
|
277
314
|
}
|
|
278
315
|
|
|
279
|
-
async init(uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number, upload?: boolean): Promise<void> {
|
|
316
|
+
private async init(uri: string, post?: any, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number, upload?: boolean): Promise<void> {
|
|
280
317
|
if (post) {
|
|
281
318
|
if (upload) {
|
|
282
319
|
let fd = new FormData();
|
|
@@ -328,7 +365,7 @@ export default class ecurl {
|
|
|
328
365
|
})
|
|
329
366
|
}
|
|
330
367
|
|
|
331
|
-
onFetched(resText: string | Object, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number): void {
|
|
368
|
+
protected onFetched(resText: string | Object, onDone?: (res: any, msg: string) => void, onFailed?: (msg: string, timeout: boolean) => void, debug?: number): void {
|
|
332
369
|
var resJson = typeof resText == 'string' && ((resText.startsWith("{") && resText.endsWith("}")) || (resText.startsWith("[") && resText.endsWith("]"))) ? JSON.parse(resText) : resText
|
|
333
370
|
if (typeof resJson == "object") {
|
|
334
371
|
if (!resJson.status_code || this.onStatusCode(resJson.ok, resJson.status_code, resJson.message, resJson.result)) {
|
|
@@ -336,8 +373,8 @@ export default class ecurl {
|
|
|
336
373
|
if (onDone) onDone(resJson.result, resJson.message)
|
|
337
374
|
this.onDone(resJson.result, resJson.message)
|
|
338
375
|
} else {
|
|
339
|
-
if (onFailed) onFailed(resJson.message, false)
|
|
340
|
-
this.onFailed(resJson.message, false)
|
|
376
|
+
if (onFailed) onFailed(this.refineErrorMessage(resJson.message), false)
|
|
377
|
+
this.onFailed(this.refineErrorMessage(resJson.message), false)
|
|
341
378
|
}
|
|
342
379
|
}
|
|
343
380
|
} else {
|
|
@@ -348,17 +385,26 @@ export default class ecurl {
|
|
|
348
385
|
}
|
|
349
386
|
}
|
|
350
387
|
|
|
351
|
-
|
|
388
|
+
private refineErrorMessage(resText: string): string {
|
|
389
|
+
let out = resText
|
|
390
|
+
if (resText.toLowerCase().includes('failed') || resText.toLowerCase().includes('code')) {
|
|
391
|
+
out = 'Terjadi kesalahan, biar ' + esp.appjson()?.expo?.name + ' bereskan, silahkan coba beberapa saat lagi.'
|
|
392
|
+
}
|
|
393
|
+
return out
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
private onError(msg: string): void {
|
|
352
397
|
esp.log("\x1b[31m", msg)
|
|
353
398
|
esp.log("\x1b[0m")
|
|
354
399
|
if (esp.isDebug('') && msg == '') {
|
|
355
400
|
return
|
|
356
401
|
}
|
|
357
|
-
|
|
402
|
+
delete this.fetchConf.options.cancelToken
|
|
403
|
+
reportApiError(this.fetchConf.options, msg)
|
|
358
404
|
LibProgress.hide()
|
|
359
405
|
}
|
|
360
406
|
|
|
361
|
-
getTimeByTimeZone(timeZone: string): number {
|
|
407
|
+
protected getTimeByTimeZone(timeZone: string): number {
|
|
362
408
|
return moment(new Date()).tz(timeZone).toMiliseconds();
|
|
363
409
|
}
|
|
364
410
|
}
|
|
@@ -102,6 +102,7 @@ function unmask(name: string, text: string): string {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
export default function m(props: LibInput_baseProps): any {
|
|
105
|
+
|
|
105
106
|
LibInput_base_dataProperty.inputBaseRef[props.name] = useRef<TextInput>(null);
|
|
106
107
|
LibInput_base_dataProperty.inputBaseData[props.name] = {
|
|
107
108
|
mask: props.mask,
|
|
@@ -109,6 +110,7 @@ export default function m(props: LibInput_baseProps): any {
|
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
useEffect(() => {
|
|
113
|
+
console.warn('LibInput_base is deprecated, use LibInput with props `base={true}` instead')
|
|
112
114
|
LibInput_base_dataProperty.inputBaseRef[props.name].current!.blur()
|
|
113
115
|
if (props.defaultValue) {
|
|
114
116
|
setTimeout(() => {
|
package/modules/lib/progress.tsx
CHANGED
package/package.json
CHANGED
package/state.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react'
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
export default function m(def?: any) {
|
|
4
4
|
const r = useRef<boolean>(true)
|
|
@@ -9,7 +9,7 @@ export default function m(def?: any) {
|
|
|
9
9
|
b(value)
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
r.current = true
|
|
15
15
|
return () => { r.current = false }
|