@jetthai/cuora 1.0.66-sabai-2 → 1.0.67

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 (92) hide show
  1. package/CHANGELOG.md +0 -638
  2. package/README.md +0 -6
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.LICENSE.txt +30 -0
  5. package/package.json +11 -13
  6. package/src/api/activity.js +3 -10
  7. package/src/api/auth.js +5 -47
  8. package/src/api/game.js +2 -64
  9. package/src/api/index.js +8 -8
  10. package/src/api/payment.js +7 -86
  11. package/src/api/user.js +0 -18
  12. package/src/index.js +5 -7
  13. package/src/machine/activity/activity.js +10 -97
  14. package/src/machine/activity/continue_deposit_activity.js +1 -1
  15. package/src/machine/activity/deposit_activity.js +1 -1
  16. package/src/machine/activity/{diamond_shop_activity_fc.js → diamond_shop_activity.js} +5 -33
  17. package/src/machine/activity/{diamond_shop_activity_vn.js → diamond_shop_activity_single_exchange.js} +21 -66
  18. package/src/machine/activity/fafafa_activity.js +2 -4
  19. package/src/machine/activity/index.js +10 -24
  20. package/src/machine/activity/invite_friends_activity.js +8 -3
  21. package/src/machine/activity/ranking_activity.js +46 -40
  22. package/src/machine/activity/return_bonus_activity.js +3 -5
  23. package/src/machine/activity/specify_bets_activity.js +1 -1
  24. package/src/machine/auth.js +79 -234
  25. package/src/machine/{auth_otp_v3.js → auth_otp.js} +17 -80
  26. package/src/machine/bank_binding.js +14 -15
  27. package/src/machine/common.js +17 -80
  28. package/src/machine/{deposit/deposit_fc.js → deposit.js} +15 -27
  29. package/src/machine/error.js +1 -1
  30. package/src/machine/game.js +10 -17
  31. package/src/machine/game_favorite.js +2 -2
  32. package/src/machine/game_hot_new.js +1 -1
  33. package/src/machine/game_search.js +7 -3
  34. package/src/machine/inbox.js +6 -5
  35. package/src/machine/index.js +25 -56
  36. package/src/machine/merge.js +2 -2
  37. package/src/machine/payment_data.js +5 -6
  38. package/src/machine/reward.js +3 -84
  39. package/src/machine/setting.js +2 -5
  40. package/src/machine/side.js +27 -34
  41. package/src/machine/user_info.js +1 -1
  42. package/src/machine/user_reset_password.js +2 -2
  43. package/src/machine/user_sign_up.js +56 -111
  44. package/src/machine/welcome.js +8 -6
  45. package/src/machine/withdraw.js +380 -0
  46. package/src/machine/withdraw_vn.js +65 -248
  47. package/src/request/config.js +1 -7
  48. package/src/request/cookie.js +52 -0
  49. package/src/request/request.js +15 -11
  50. package/webpack.config.js +33 -0
  51. package/.husky/pre-commit +0 -4
  52. package/.prettierignore +0 -1
  53. package/dist/bundle.mjs +0 -27623
  54. package/rollup.config.js +0 -12
  55. package/src/lib/fingerprint.js +0 -5779
  56. package/src/machine/activity/affiliate_invite_friends_activity.js +0 -216
  57. package/src/machine/activity/mini_game_activity.js +0 -68
  58. package/src/machine/activity/roulette_activity_v2.js +0 -81
  59. package/src/machine/activity/sign_in_activity.js +0 -149
  60. package/src/machine/activity/specify_turnover_activity.js +0 -113
  61. package/src/machine/activity/time_bomb_activity.js +0 -80
  62. package/src/machine/auth_otp_v2.js +0 -177
  63. package/src/machine/bank_binding_amb.js +0 -140
  64. package/src/machine/bonus.js +0 -75
  65. package/src/machine/deposit/amb.js +0 -90
  66. package/src/machine/deposit/crypto.js +0 -267
  67. package/src/machine/deposit/crypto_button.js +0 -449
  68. package/src/machine/deposit/direct.js +0 -246
  69. package/src/machine/deposit/float.js +0 -295
  70. package/src/machine/deposit/index.js +0 -25
  71. package/src/machine/deposit/loadcard_vn.js +0 -390
  72. package/src/machine/deposit/manual_vn.js +0 -382
  73. package/src/machine/deposit/qrcode_v2.js +0 -451
  74. package/src/machine/deposit/usdt.js +0 -144
  75. package/src/machine/deposit/vpay.js +0 -292
  76. package/src/machine/game_favorite_v2.js +0 -119
  77. package/src/machine/game_search_v2.js +0 -379
  78. package/src/machine/game_v2.js +0 -381
  79. package/src/machine/game_v2_1.js +0 -442
  80. package/src/machine/leaderboard.js +0 -108
  81. package/src/machine/promotions.js +0 -170
  82. package/src/machine/reward_fc.js +0 -97
  83. package/src/machine/roulette_v2.js +0 -271
  84. package/src/machine/side_v2.js +0 -200
  85. package/src/machine/vip_table.js +0 -50
  86. package/src/machine/withdraw_amb.js +0 -373
  87. package/src/machine/withdraw_crypto.js +0 -560
  88. package/src/machine/withdraw_fc.js +0 -251
  89. package/src/util/constant.js +0 -2
  90. package/src/util/deviceToken.js +0 -33
  91. package/src/util/index.js +0 -6
  92. package/src/util/storage.js +0 -28
@@ -1,8 +1,13 @@
1
1
  import { assign, createMachine } from 'xstate'
2
- import findLastIndex from 'lodash/findLastIndex.js'
3
- import payment from '../api/payment.js'
4
- import common from '../api/common.js'
5
- import user from '../api/user.js'
2
+ import findLastIndex from 'lodash/findLastIndex'
3
+ import payment from '../api/payment'
4
+ import common from '../api/common'
5
+ import user from '../api/user'
6
+
7
+ // todo - noBind -> unbound
8
+ // todo - withdrawLimit, targetWithdrawLimit 轉為正數
9
+ // todo - mod -> mode
10
+ // todo - adjust updateWithdrawCondition
6
11
 
7
12
  export default function (request) {
8
13
  const { appSecret } = request.config
@@ -23,11 +28,6 @@ export default function (request) {
23
28
  bankList: [],
24
29
  withdrawLimit: null,
25
30
  targetWithdrawLimit: null,
26
- attachmentType: null, // null | 'withdraw' | 'pool'
27
- maximumWithdrawAmount: 0,
28
- enableWithdrawAmount: 0,
29
- enableWithdraw: false,
30
- withdrawRules: [],
31
31
 
32
32
  amount: null,
33
33
  bank: null,
@@ -35,11 +35,8 @@ export default function (request) {
35
35
  accountNumber: null,
36
36
  holderName: null,
37
37
 
38
- // otp
39
- requestId: null,
40
- status: null,
41
- target: null,
42
- ttl: null,
38
+ withdrawDistance: null,
39
+ withdrawAmount: null,
43
40
  },
44
41
  states: {
45
42
  loading: {
@@ -47,7 +44,7 @@ export default function (request) {
47
44
  src: 'fetchInitData',
48
45
  onDone: {
49
46
  target: 'mode',
50
- actions: ['setInitData', 'preset', 'updateWithdrawCondition'],
47
+ actions: ['setSiteConfig', 'setUserInfo', 'setInitData', 'preset'],
51
48
  },
52
49
  onError: {
53
50
  target: 'fail',
@@ -58,69 +55,43 @@ export default function (request) {
58
55
  always: [{ target: 'free', cond: 'isFree' }, { target: 'cash' }],
59
56
  },
60
57
  free: {
61
- initial: 'checking',
58
+ initial: 'loading',
62
59
  states: {
63
- // loading: {
64
- // invoke: {
65
- // src: 'fetchWithdrawRules',
66
- // onDone: {
67
- // target: 'checking',
68
- // actions: 'updateWithdrawCondition',
69
- // },
70
- // onError: {
71
- // target: 'notConvertible',
72
- // },
73
- // },
74
- // },
75
- checking: {
76
- always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
77
- },
78
- notConvertible: {
79
- on: {
80
- GIVE_UP: {
81
- target: 'givingUp',
82
- },
83
- },
84
- },
85
- givingUp: {
60
+ loading: {
86
61
  invoke: {
87
- src: 'giveUp',
62
+ src: 'fetchWithdrawRules',
88
63
  onDone: {
89
- target: 'gaveUp',
64
+ target: 'checking',
65
+ actions: 'updateWithdrawCondition',
90
66
  },
91
67
  onError: {
92
- target: 'convertible',
68
+ target: 'notConvertible',
93
69
  },
94
70
  },
95
71
  },
96
- gaveUp: {},
72
+ checking: {
73
+ always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
74
+ },
75
+ notConvertible: {},
97
76
  convertible: {
98
77
  on: {
99
78
  SUBMIT: {
100
79
  target: 'converting',
101
- actions: 'setAttachmentType',
102
80
  },
103
81
  },
104
82
  },
105
83
  converting: {
106
84
  invoke: {
107
- src: 'convertFreeCredit',
108
- onDone: [
109
- {
110
- target: '#withdraw_vn.otp',
111
- actions: 'setOtp',
112
- cond: 'isOtpRequired',
113
- },
114
- { target: 'converted' },
115
- ],
85
+ src: 'submitWithdrawFree',
86
+ onDone: {
87
+ target: 'converted',
88
+ },
116
89
  onError: {
117
90
  target: 'convertible',
118
91
  },
119
92
  },
120
93
  },
121
- converted: {
122
- always: [{ target: '#withdraw_vn.cash.withdrawable', cond: 'hasAttachmentType' }],
123
- },
94
+ converted: {},
124
95
  },
125
96
  },
126
97
  cash: {
@@ -155,38 +126,18 @@ export default function (request) {
155
126
  }
156
127
  }),
157
128
  },
158
- SET_ATTACHMENT_TYPE: {
159
- actions: 'setAttachmentType',
160
- cond: 'isNewWalletMode',
129
+ SUBMIT: {
130
+ target: 'submitting',
131
+ cond: 'isSubmittable',
161
132
  },
162
- SUBMIT: [
163
- {
164
- target: 'pooling',
165
- cond: (context, event) => {
166
- const { amount, attachmentType } = context
167
- return attachmentType === 'pool' && amount > 0
168
- },
169
- },
170
- {
171
- target: 'submitting',
172
- cond: 'isSubmittable',
173
- },
174
- ],
175
133
  },
176
134
  },
177
135
  submitting: {
178
136
  invoke: {
179
137
  src: 'submitWithdraw',
180
- onDone: [
181
- {
182
- target: '#withdraw_vn.otp',
183
- actions: 'setOtp',
184
- cond: 'isOtpRequired',
185
- },
186
- {
187
- target: 'submitted',
188
- },
189
- ],
138
+ onDone: {
139
+ target: 'submitted',
140
+ },
190
141
  onError: {
191
142
  target: 'withdrawable',
192
143
  },
@@ -200,7 +151,6 @@ export default function (request) {
200
151
  invoke: {
201
152
  src: 'fetchPaymentData',
202
153
  onDone: {
203
- target: 'inProcessing',
204
154
  actions: 'setPaymentData',
205
155
  },
206
156
  onError: {
@@ -208,81 +158,6 @@ export default function (request) {
208
158
  },
209
159
  },
210
160
  },
211
- pooling: {
212
- invoke: {
213
- src: 'pool',
214
- onDone: { target: 'pooled' },
215
- onError: {
216
- target: 'withdrawable',
217
- },
218
- },
219
- },
220
- pooled: {},
221
- },
222
- },
223
- otp: {
224
- type: 'parallel',
225
- states: {
226
- countdown: {
227
- after: {
228
- 1000: {
229
- target: 'countdown',
230
- actions: 'decreaseTtl',
231
- cond: (context) => context.ttl > 0,
232
- },
233
- },
234
- },
235
- verification: {
236
- initial: 'idle',
237
- states: {
238
- idle: {
239
- on: {
240
- ACKNOWLEDGE: {
241
- target: 'acknowledging',
242
- },
243
- RESET_OTP: {
244
- target: 'reset',
245
- },
246
- BACK: [
247
- {
248
- target: '#withdraw_vn.free.convertible',
249
- cond: 'isFree',
250
- },
251
- {
252
- target: '#withdraw_vn.cash.withdrawable',
253
- },
254
- ],
255
- },
256
- },
257
- acknowledging: {
258
- invoke: {
259
- src: 'acknowledge',
260
- onDone: [
261
- {
262
- target: '#withdraw_vn.free.converted',
263
- cond: 'isFree',
264
- },
265
- {
266
- target: '#withdraw_vn.cash.submitted',
267
- },
268
- ],
269
- onError: {
270
- target: 'idle',
271
- },
272
- },
273
- },
274
- reset: {
275
- invoke: {
276
- src: 'resetOtp',
277
- onDone: {
278
- target: 'idle',
279
- actions: 'setVerificationData',
280
- },
281
- onError: { target: 'idle' },
282
- },
283
- },
284
- },
285
- },
286
161
  },
287
162
  },
288
163
  fail: {},
@@ -299,7 +174,6 @@ export default function (request) {
299
174
  return {
300
175
  paymentDetail: event.data.paymentDetail,
301
176
  bankInfo: event.data.bankInfo,
302
- bank: event.data.bankInfo[0],
303
177
  bonus: event.data.bonus,
304
178
  bankList: event.data.bankList,
305
179
  }
@@ -311,6 +185,16 @@ export default function (request) {
311
185
  paymentDetail: event.data.paymentDetail,
312
186
  }
313
187
  }),
188
+ setUserInfo: assign((context, event) => {
189
+ return {
190
+ userInfo: event.data.userInfo,
191
+ }
192
+ }),
193
+ setSiteConfig: assign((context, event) => {
194
+ return {
195
+ siteConfig: event.data.siteConfig,
196
+ }
197
+ }),
314
198
  preset: assign((context, event) => {
315
199
  const { userInfo, siteConfig } = event.data
316
200
  const { withdraw_limit, target_withdraw_limit } = userInfo || {}
@@ -321,26 +205,24 @@ export default function (request) {
321
205
  targetWithdrawLimit: Math.abs(target_withdraw_limit),
322
206
  methods,
323
207
  balance,
324
- siteConfig,
325
- userInfo,
326
- attachmentType: siteConfig.walletMode > 0 ? 'withdraw' : null,
327
208
  }
328
209
  }),
329
210
  updateWithdrawCondition: assign((context, event) => {
330
- const { differAmountLimit, enableWithdraw, enableWithdrawAmount, maxWithdrawStatus, maximumWithdrawAmount, minimumWithdrawAmount } =
331
- event.data?.withdrawRule
211
+ const rules = event.data.rules.filter((rule) => rule.maxWithdrawAmount > 0)
332
212
 
333
- const withdrawRules = event.data?.withdrawRule?.rules || []
334
- const rules = withdrawRules.filter((rule) => rule.maxWithdrawAmount > 0)
335
-
336
- const { balance } = context
213
+ const { balance, withdrawLimit } = context
337
214
  const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
338
215
 
339
- let maxWithdrawAmount = 0
216
+ let maxWithdrawAmount = 0,
217
+ availableWithdrawAmount = 0
340
218
 
341
219
  if (lastMatchedIndex > -1) {
342
220
  rules[lastMatchedIndex].match = true
343
221
  maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
222
+
223
+ if (withdrawLimit === 0) {
224
+ availableWithdrawAmount = Math.min(balance, maxWithdrawAmount)
225
+ }
344
226
  } else if (rules.length > 0) {
345
227
  maxWithdrawAmount = rules[0].maxWithdrawAmount
346
228
  } else {
@@ -349,37 +231,7 @@ export default function (request) {
349
231
 
350
232
  return {
351
233
  maxWithdrawAmount,
352
- enableWithdrawAmount: +enableWithdrawAmount,
353
- enableWithdraw,
354
- withdrawRules,
355
- }
356
- }),
357
- setOtp: assign((context, event) => {
358
- const { requestId, status, target, ttl } = event.data
359
- return {
360
- requestId,
361
- status,
362
- target,
363
- ttl,
364
- }
365
- }),
366
- decreaseTtl: assign((context, evnet) => {
367
- const second = context.ttl
368
- return {
369
- ttl: Math.max(second - 1, 0),
370
- }
371
- }),
372
- setVerificationData: assign((context, event) => {
373
- const { requestId, ttl, target } = event.data
374
- return {
375
- requestId,
376
- ttl,
377
- target,
378
- }
379
- }),
380
- setAttachmentType: assign((context, event) => {
381
- return {
382
- attachmentType: event.data,
234
+ availableWithdrawAmount,
383
235
  }
384
236
  }),
385
237
  },
@@ -387,11 +239,8 @@ export default function (request) {
387
239
  isFree: (context, event) => {
388
240
  return context.userInfo?.withdraw_rule !== 'DEFAULT'
389
241
  },
390
- hasAttachmentType: (context, event) => {
391
- return ['withdraw', 'pool'].includes(context.attachmentType)
392
- },
393
242
  haveProcessing: (context, event) => {
394
- return (context.paymentDetail?.[0]?.processing || []).length > 0
243
+ return context.paymentDetail[0] && context.paymentDetail[0].processing.length > 0
395
244
  },
396
245
  isWithdrawDisable: (context, event) => {
397
246
  const { siteConfig } = context
@@ -402,39 +251,31 @@ export default function (request) {
402
251
  return !context.bankInfo?.length
403
252
  },
404
253
  isSubmittable: (context, event) => {
405
- const { bank, amount } = context
406
- return bank && amount > 0
254
+ const { applyerBankCode, applyerAccountNumber, branch, holderName, amount } = event.data
255
+ return applyerBankCode, applyerAccountNumber, branch, holderName, amount
407
256
  },
408
257
  isConvertible: (context, event) => {
409
- const { balance, enableWithdraw } = context
410
- return balance > 0 && enableWithdraw
258
+ const { balance, withdrawLimit } = context
259
+ return balance > 0 && withdrawLimit === 0
411
260
  },
412
261
  isNotWithdrawable: (context, event) => {
413
- const { balance, enableWithdraw, paymentDetail } = context
262
+ const { balance, withdrawLimit, paymentDetail } = context
414
263
  const minWithdrawAmount = paymentDetail[0]?.minimum || 0
415
- return !enableWithdraw || balance < minWithdrawAmount
416
- },
417
- isOtpRequired: (context, event) => {
418
- return event.data?.status === 'otp-verifying'
264
+ return withdrawLimit !== 0 || balance < minWithdrawAmount
419
265
  },
420
- isNewWalletMode: (context, event) => context.siteConfig.walletMode > 0,
421
266
  },
422
267
  services: {
423
268
  fetchInitData: async (context, event) => {
424
- const [{ config }, userInfo, paymentDetail = [], { bonus, bankInfo }, withdrawRule] = await Promise.all([
269
+ const [{ config }, userInfo, paymentDetail = [], { bonus, bankInfo }] = await Promise.all([
425
270
  request.send(common.getConfig({ appSecret })),
426
271
  request.send(user.getUserInfo()),
427
272
  request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' })),
428
273
  request.send(payment.getPaymentInfo()),
429
- request.send(payment.getCurrentWithdrawRule()),
430
274
  ])
431
275
  const siteConfig = JSON.parse(window.atob(config))
432
- const method = paymentDetail.find((payment) => payment.category === 'manual').method
276
+ const method = paymentDetail.find((payment) => payment.methodType === 'manual').method
433
277
  const bankList = await request.send(payment.getBankList(method))
434
- const newBankInfo = bankInfo.map((item) => {
435
- return { ...item, ...bankList.find((bank) => bank.bankCode === item.bankCode) }
436
- })
437
- return { siteConfig, userInfo, paymentDetail, bonus, bankInfo: newBankInfo, bankList, withdrawRule }
278
+ return { siteConfig, userInfo, paymentDetail, bonus, bankInfo, bankList }
438
279
  },
439
280
  fetchPaymentData: async (context, event) => {
440
281
  const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
@@ -456,39 +297,15 @@ export default function (request) {
456
297
  return await request.send(payment.getCurrentWithdrawRule())
457
298
  },
458
299
  submitWithdraw: async (context, event) => {
459
- const { bank, amount } = context
300
+ const { amount, applyerBankCode, applyerAccountNumber, branch, holderName } = event.data
460
301
  const { method } = context.paymentDetail[0]
461
- const branchTemp = bank.bankCode === 'GCASH' ? '' : bank.branch
462
302
  return await request.send(
463
- payment.submitWithdrawTransactionVN({
464
- method,
465
- amount,
466
- applyerBankCode: bank.bankCode,
467
- applyerAccountNumber: bank.accountNumber,
468
- branch: branchTemp,
469
- holderName: bank.holderName,
470
- })
303
+ payment.submitWithdrawTransactionVN({ method, amount, applyerBankCode, applyerAccountNumber, branch, holderName })
471
304
  )
472
305
  },
473
- convertFreeCredit: async (context, event) => {
306
+ submitWithdrawFree: async (context, event) => {
474
307
  return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
475
308
  },
476
- resetOtp: async (context, event) => {
477
- const { requestId, target } = context
478
- return await request.send(user.otpReset({ requestId, target }))
479
- },
480
- acknowledge: async (context, event) => {
481
- const { requestId, target } = context
482
- const code = event.data
483
- return await request.send(user.otpAcknowledge({ requestId, target, code }))
484
- },
485
- pool: async (context, event) => {
486
- const { amount } = context
487
- return await request.send(payment.restore({ amount }))
488
- },
489
- giveUp: async (context, event) => {
490
- return await request.send(payment.giveUp())
491
- },
492
309
  },
493
310
  }
494
311
  )
@@ -1,9 +1,7 @@
1
1
  import urljoin from 'url-join'
2
2
 
3
- // const urljoin = require('url-join')
4
-
5
3
  export default class Config {
6
- constructor({ apiURL, apiVersion, clientId, appSecret, platform, version, fpToken, sentry, defaultChannel, defaultSubchannel }) {
4
+ constructor({ apiURL, apiVersion, clientId, appSecret, platform, version }) {
7
5
  this.apiURL = apiURL
8
6
  this.apiVersion = apiVersion
9
7
  this.clientId = clientId
@@ -11,10 +9,6 @@ export default class Config {
11
9
  this.platform = platform
12
10
  this.version = version
13
11
  this.fullURL = urljoin(this.apiURL, this.apiVersion, this.clientId)
14
- this.fpToken = fpToken // fingerprintjs token
15
- this.sentry = sentry
16
- this.defaultChannel = defaultChannel
17
- this.defaultSubchannel = defaultSubchannel
18
12
  }
19
13
 
20
14
  setApiURL(url) {
@@ -0,0 +1,52 @@
1
+ import Cookies from 'universal-cookie'
2
+
3
+ export default class Cookie {
4
+ constructor(tokenKey) {
5
+ this.cookies = new Cookies()
6
+ this.tokenKey = tokenKey
7
+ }
8
+
9
+ setToken(token) {
10
+ this.cookies.set(this.tokenKey, token, {
11
+ path: '/',
12
+ maxAge: 300,
13
+ })
14
+ }
15
+
16
+ prolongToken() {
17
+ const token = this.getToken()
18
+ if (token) {
19
+ this.setToken(token)
20
+ }
21
+ }
22
+
23
+ getToken() {
24
+ return this.cookies.get(this.tokenKey)
25
+ }
26
+
27
+ removeToken() {
28
+ this.cookies.remove(this.tokenKey, {
29
+ path: '/',
30
+ maxAge: 300,
31
+ })
32
+ }
33
+
34
+ setUser(user) {
35
+ this.cookies.set('cuora_tempuser', user, {
36
+ path: '/',
37
+ maxAge: 60 * 60 * 24,
38
+ })
39
+ }
40
+
41
+ getUser() {
42
+ return this.cookies.get('cuora_tempuser')
43
+ }
44
+
45
+ set(name, value, options) {
46
+ this.cookies.set(name, value, options)
47
+ }
48
+
49
+ get(name, options) {
50
+ return this.cookies.get(name, options)
51
+ }
52
+ }
@@ -1,7 +1,5 @@
1
- import pickBy from 'lodash/pickBy.js'
2
- import storage from '../util/storage.js'
3
-
4
- // const pickBy = require('lodash/pickBy')
1
+ import pickBy from 'lodash/pickBy'
2
+ import Cookie from './cookie'
5
3
 
6
4
  function isValid(value) {
7
5
  return value !== undefined && value !== null
@@ -12,9 +10,8 @@ export default class Request {
12
10
  this.axios = axios
13
11
  this.source = axios.CancelToken.source()
14
12
  this.config = config
15
- this.key = `cuora_${config.clientId}`
13
+ this.cookie = new Cookie(`cuora_${config.clientId}`)
16
14
  this.errorHandler = null
17
- this.hosts = []
18
15
  this.initialize()
19
16
  }
20
17
 
@@ -22,8 +19,8 @@ export default class Request {
22
19
  this.axios.interceptors.request.use((axiosConfig) => {
23
20
  axiosConfig.headers['X-TH1GAMES-VERSION'] = this.config.version
24
21
  axiosConfig.headers['X-TH1GAMES-PLATFORM'] = this.config.platform
25
- if (storage.get(this.key)) {
26
- axiosConfig.headers.Authorization = storage.get(this.key)
22
+ if (this.cookie.getToken()) {
23
+ axiosConfig.headers.Authorization = this.cookie.getToken()
27
24
  }
28
25
  return axiosConfig
29
26
  })
@@ -51,7 +48,7 @@ export default class Request {
51
48
  async send(req, customToken) {
52
49
  try {
53
50
  const cancelToken = customToken || this.source.token
54
- this._checkToken(req, storage.get(this.key))
51
+ this._checkToken(req, this.cookie.getToken())
55
52
  const requestConfig = this._createConfig(req, cancelToken)
56
53
  const { data } = await this.axios.request(requestConfig)
57
54
  return data
@@ -73,7 +70,15 @@ export default class Request {
73
70
  }
74
71
 
75
72
  _createConfig(req, cancelToken) {
76
- const { method, url, params, isPublic, isFormData, headers } = req
73
+ const { method, url, params, isPublic, isFormData } = req
74
+ // const config = { baseURL: this.config.fullURL, method, url, cancelToken, isPublic: req.isPublic }
75
+ // if (method.toUpperCase() === 'GET') {
76
+ // config.params = pickBy(params, isValid)
77
+ // } else {
78
+ // config.data = pickBy(params, isValid)
79
+ // }
80
+ // return config
81
+
77
82
  if (isFormData) {
78
83
  return {
79
84
  baseURL: this.config.fullURL,
@@ -91,7 +96,6 @@ export default class Request {
91
96
  url,
92
97
  cancelToken,
93
98
  isPublic,
94
- headers,
95
99
  [method.toUpperCase() === 'GET' ? 'params' : 'data']: pickBy(params, isValid),
96
100
  }
97
101
  }
@@ -0,0 +1,33 @@
1
+ const path = require('path')
2
+
3
+ module.exports = {
4
+ mode: 'production',
5
+ entry: {
6
+ main: './src/index.js',
7
+ },
8
+ output: {
9
+ filename: 'index.js',
10
+ path: path.resolve(__dirname, 'dist'),
11
+ clean: true,
12
+ library: {
13
+ type: 'module',
14
+ },
15
+ },
16
+ experiments: {
17
+ outputModule: true,
18
+ },
19
+ module: {
20
+ rules: [
21
+ {
22
+ test: /\.m?js$/,
23
+ exclude: /node_modules/,
24
+ use: {
25
+ loader: 'babel-loader',
26
+ options: {
27
+ presets: [['@babel/preset-env', { targets: 'defaults' }]],
28
+ },
29
+ },
30
+ },
31
+ ],
32
+ },
33
+ }
package/.husky/pre-commit DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname -- "$0")/_/husky.sh"
3
-
4
- npm run format && npm run build && git add .
package/.prettierignore DELETED
@@ -1 +0,0 @@
1
- dist/