@jetthai/cuora 1.1.395-payment-1 → 1.1.396

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 (62) hide show
  1. package/CHANGELOG.md +93 -1
  2. package/package.json +1 -1
  3. package/resetGitBranch.sh +0 -10
  4. package/src/api/activity.js +6 -4
  5. package/src/api/auth.js +2 -2
  6. package/src/api/common.js +1 -1
  7. package/src/api/game.js +25 -13
  8. package/src/api/payment.js +9 -5
  9. package/src/api/ranking.js +6 -6
  10. package/src/api/user.js +15 -10
  11. package/src/lib/{fingerprint_v3_11_5.js → fingerprint_v3_11_12.js} +3749 -4212
  12. package/src/machine/activity/continue_deposit_activity.js +2 -1
  13. package/src/machine/activity/fafafa_activity.js +2 -1
  14. package/src/machine/activity/return_bonus_activity.js +2 -1
  15. package/src/machine/activity/sign_in_activity.js +2 -1
  16. package/src/machine/activity/specify_bets_activity.js +2 -1
  17. package/src/machine/activity/specify_turnover_activity.js +2 -1
  18. package/src/machine/auth.js +15 -7
  19. package/src/machine/bank_binding.js +68 -10
  20. package/src/machine/common.js +34 -8
  21. package/src/machine/deposit/amb.js +1 -1
  22. package/src/machine/deposit/crypto_bank.js +10 -2
  23. package/src/machine/deposit/crypto_bank_cash.js +10 -2
  24. package/src/machine/deposit/crypto_way.js +10 -2
  25. package/src/machine/deposit/crypto_way_cash.js +10 -2
  26. package/src/machine/deposit/deposit_fc.js +11 -3
  27. package/src/machine/deposit/direct.js +12 -4
  28. package/src/machine/deposit/direct_cash.js +12 -4
  29. package/src/machine/deposit/float.js +12 -4
  30. package/src/machine/deposit/loadcard_cash.js +11 -3
  31. package/src/machine/deposit/loadcard_vn.js +11 -3
  32. package/src/machine/deposit/manual_cash.js +12 -4
  33. package/src/machine/deposit/manual_vn.js +11 -3
  34. package/src/machine/deposit/qrcode_cash.js +11 -3
  35. package/src/machine/deposit/qrcode_v2.js +11 -3
  36. package/src/machine/deposit/virtual_bank_cash.js +11 -3
  37. package/src/machine/deposit/virtual_bank_vn.js +11 -3
  38. package/src/machine/deposit/vpay.js +12 -4
  39. package/src/machine/game_betslip.js +46 -0
  40. package/src/machine/game_replay.js +2 -2
  41. package/src/machine/game_search_cash.js +10 -7
  42. package/src/machine/game_search_v2.js +10 -10
  43. package/src/machine/game_v2_1.js +22 -9
  44. package/src/machine/honor_board_cash.js +1 -1
  45. package/src/machine/inbox.js +22 -8
  46. package/src/machine/index.js +2 -0
  47. package/src/machine/ranking.js +14 -11
  48. package/src/machine/reward.js +58 -5
  49. package/src/machine/reward_cash.js +60 -3
  50. package/src/machine/reward_fc.js +2 -1
  51. package/src/machine/side_cash.js +3 -2
  52. package/src/machine/side_v2.js +5 -4
  53. package/src/machine/user_reset_password.js +5 -4
  54. package/src/machine/user_sign_up.js +6 -2
  55. package/src/machine/vip_table.js +11 -4
  56. package/src/machine/withdraw/withdraw_crypto_cash.js +10 -2
  57. package/src/machine/withdraw/withdraw_manual.js +11 -96
  58. package/src/machine/withdraw/withdraw_manual_cash.js +1 -1
  59. package/src/request/request.js +245 -7
  60. package/src/util/deviceToken.js +26 -2
  61. package/src/util/index.js +2 -2
  62. package/src/util/storage.js +18 -4
@@ -73,88 +73,6 @@ export default function (request) {
73
73
  },
74
74
  },
75
75
  },
76
- // mode: {
77
- // always: [{ target: 'cash' }],
78
- // },
79
- // activity: {
80
- // initial: 'checking',
81
- // states: {
82
- // checking: {
83
- // always: [{ target: 'convertible', cond: 'isConvertible' }, { target: 'notConvertible' }],
84
- // },
85
- // notConvertible: {
86
- // on: {
87
- // GIVE_UP: {
88
- // target: 'fetchWithdrawRule',
89
- // },
90
- // },
91
- // },
92
- // fetchWithdrawRule: {
93
- // invoke: {
94
- // src: 'fetchWithdrawRulePreview',
95
- // onDone: {
96
- // target: 'giveUp',
97
- // actions: 'setWithdrawRulePreview',
98
- // },
99
- // onError: {
100
- // target: 'notConvertible',
101
- // },
102
- // },
103
- // },
104
- // giveUp: {
105
- // on: {
106
- // CONFIRM: {
107
- // target: 'givingUp',
108
- // },
109
- // BACK: {
110
- // target: 'notConvertible',
111
- // },
112
- // },
113
- // },
114
- // givingUp: {
115
- // invoke: {
116
- // src: 'giveUp',
117
- // onDone: {
118
- // target: 'gaveUp',
119
- // },
120
- // onError: {
121
- // target: 'convertible',
122
- // },
123
- // },
124
- // },
125
- // gaveUp: {},
126
- // convertible: {
127
- // on: {
128
- // SUBMIT: {
129
- // target: 'converting',
130
- // actions: 'setAttachmentType',
131
- // },
132
- // },
133
- // },
134
- // converting: {
135
- // invoke: {
136
- // src: 'convertFreeCredit',
137
- // onDone: [
138
- // // {
139
- // // target: '#withdraw_manual.otp',
140
- // // actions: 'setOtp',
141
- // // cond: 'isOtpRequired',
142
- // // },
143
- // { target: 'converted' },
144
- // ],
145
- // onError: {
146
- // target: 'convertible',
147
- // },
148
- // },
149
- // },
150
- // converted: {
151
- // // always: [
152
- // // { target: '#withdraw_manual.cash.unbound', cond: 'isBankNotBound' },
153
- // // { target: '#withdraw_manual.cash.withdrawable', cond: 'hasAttachmentType' },
154
- // // ],
155
- // },
156
- // },
157
- // },
158
76
  cash: {
159
77
  initial: 'checking',
160
78
  states: {
@@ -333,10 +251,6 @@ export default function (request) {
333
251
  target: 'reset',
334
252
  },
335
253
  BACK: [
336
- // {
337
- // target: '#withdraw_manual.activity.convertible',
338
- // cond: 'isActivity',
339
- // },
340
254
  {
341
255
  target: '#withdraw_manual.cash.withdrawable',
342
256
  },
@@ -347,10 +261,6 @@ export default function (request) {
347
261
  invoke: {
348
262
  src: 'acknowledge',
349
263
  onDone: [
350
- // {
351
- // target: '#withdraw_manual.activity.converted',
352
- // cond: 'isActivity',
353
- // },
354
264
  {
355
265
  target: '#withdraw_manual.cash.submitted',
356
266
  },
@@ -474,8 +384,16 @@ export default function (request) {
474
384
  }
475
385
  }),
476
386
  setCalculation: assign((context, event) => {
477
- return {
478
- calculation: event.data,
387
+ // V2接口轉換中回傳的資料結構不同
388
+ const { data } = event.data
389
+ if (data) {
390
+ return {
391
+ calculation: data,
392
+ }
393
+ } else {
394
+ return {
395
+ calculation: event.data,
396
+ }
479
397
  }
480
398
  }),
481
399
  clearCalculation: assign((context, event) => {
@@ -497,9 +415,6 @@ export default function (request) {
497
415
  const lastMax = Math.min(parseFloat(balance), maximum)
498
416
  return !!currentBank && amount > 0 && minimum <= amount && amount <= lastMax
499
417
  },
500
- // isActivity: (context, event) => {
501
- // return context.mode === 'ACTIVITY'
502
- // },
503
418
  hasAttachmentType: (context, event) => {
504
419
  return ['withdraw', 'pool'].includes(context.attachmentType)
505
420
  },
@@ -579,7 +494,7 @@ export default function (request) {
579
494
  payment.submitWithdrawTransactionManual({
580
495
  method,
581
496
  amount,
582
- applyerBankCode: currentBank.bankCode,
497
+ applyerBankCode: currentBank.bankCode || currentBank.walletCode,
583
498
  applyerAccountNumber: currentBank.accountNumber,
584
499
  applyerIfscCode: currentBank.ifscCode,
585
500
  branch: branchTemp,
@@ -266,7 +266,7 @@ export default function (request, context) {
266
266
  payment.submitWithdrawTransactionVN({
267
267
  method: currentPayment.method,
268
268
  amount: selectedAmount,
269
- applyerBankCode: selectedUserBank.bankCode,
269
+ applyerBankCode: selectedUserBank.bankCode || selectedUserBank.walletCode,
270
270
  applyerAccountNumber: selectedUserBank.accountNumber,
271
271
  applyerIfscCode: selectedUserBank.ifscCode,
272
272
  branch: branchTemp,
@@ -2,6 +2,145 @@ import pickBy from 'lodash/pickBy.js'
2
2
  import storage from '../util/storage.js'
3
3
 
4
4
  // const pickBy = require('lodash/pickBy')
5
+ const supportVersion2List = [
6
+ // 04-09 Update
7
+ 'game/play',
8
+ 'game/gameReplay',
9
+ 'game/logout',
10
+ 'game/list/v3/root',
11
+ 'game/list/v3/category',
12
+ 'game/list/v3/addition',
13
+ 'game/list/v3/categoryByRange',
14
+ 'game/list/v3/additionByRange',
15
+ 'game/list/v3/myFavorite',
16
+ 'game/list/v3/addMyFavorite',
17
+ 'game/list/v3/removeMyFavorite',
18
+ 'login',
19
+ 'callback/:strategy',
20
+ 'guestLogin',
21
+ 'appLogin',
22
+ 'logout',
23
+ 'self',
24
+ 'register',
25
+ 'settings/password',
26
+ 'verify',
27
+ 'reset',
28
+ 'acknowledge',
29
+ 'recovery',
30
+ 'recovery/abandon',
31
+ 'recovery/acknowledge',
32
+ 'checkDt',
33
+ 'updateDt',
34
+ 'checkAC',
35
+ 'checkAccount',
36
+ 'getAllAvatar',
37
+ 'updateUserAvatar',
38
+ 'getConfig',
39
+ 'getQuickLayout',
40
+ 'getNavbarSetting',
41
+ 'getAffiliateCode',
42
+ 'get-site-config',
43
+ 'mailbox/sendMessage',
44
+ 'mailbox/getMessageList',
45
+ 'mailbox/getMessage',
46
+ 'mailbox/updateMessage',
47
+ 'mailbox/getMessageTypes',
48
+ // 05-23 Update
49
+ 'game/info',
50
+ 'recovery/v2/initiate',
51
+ 'recovery/v2/acknowledge',
52
+ 'recovery/v2/abandon',
53
+ 'recovery/v2/reset',
54
+ 'recovery/v2/changePassword',
55
+ 'account-binding/status',
56
+ 'account-binding/bind',
57
+ 'account-binding/acknowledge',
58
+ 'account-binding/bind-third-party',
59
+ 'feeds',
60
+ 'broadcast',
61
+ 'upload',
62
+ 'game/search',
63
+ 'game/search/home',
64
+ 'game/search/list',
65
+ 'game/search/trace',
66
+ 'game/history',
67
+ 'game/history/detail',
68
+ 'payment/v2/bankWallet/promotion/apply',
69
+ 'payment/v2/bankWallet/promotion/giveUp',
70
+ 'payment/v2/bankWallet/promotion/preview',
71
+ 'payment/v2/bankWallet/promotions',
72
+ 'payment/v2/bankWallet/restore',
73
+ 'payment/v2/callback',
74
+ 'payment/v2/convertFreeCredit',
75
+ 'payment/v2/getBindingBankList',
76
+ 'payment/v2/getBindingPaymentList',
77
+ 'payment/v2/getWithdrawBankList',
78
+ 'payment/v2/getCurrentWithdrawRule',
79
+ 'payment/v2/withdrawCheck',
80
+ 'payment/v2/history',
81
+ 'payment/v2/mergeWallet',
82
+ 'payment/v2/paymentDetail',
83
+ 'payment/v2/category/options',
84
+ 'payment/v2/paymentInfo',
85
+ 'payment/v2/getBindingPaymentInfo',
86
+ 'payment/v2/pendingOrder',
87
+ 'payment/v2/promotions',
88
+ 'payment/v2/spotmarket',
89
+ 'payment/v2/transactionHistory',
90
+ 'payment/v2/updateUtr',
91
+ 'payment/v2/setting',
92
+ 'payment/v2/amb/setting',
93
+ 'payment/v2/updatePaymentInfo',
94
+ 'payment/v2/uploadSlip',
95
+ 'payment/v2/withdrawRule',
96
+ 'payment/v2/:paymentType/getBankList',
97
+ 'payment/v2/:paymentType/transaction',
98
+ 'payment/v2/:paymentType/checkTransaction',
99
+ 'payment/v2/:paymentType/bonus/preview',
100
+ 'payment/v2/:paymentType/expected/result',
101
+ 'payment/v2/:paymentType/crypto/expected/result',
102
+ // 05-28 Update
103
+ 'all-activities/list',
104
+ 'activities/list',
105
+ 'activities/rewards',
106
+ 'activities/rewardAmount',
107
+ 'activities/sentAward',
108
+ 'activities/exchange',
109
+ 'activities/collect',
110
+ 'activities',
111
+ 'activities/types',
112
+ 'activities/promo',
113
+ 'activities/viptable',
114
+ 'activities/level-bonus/info',
115
+ 'activities/numbers',
116
+ 'activities/honorBroadcast',
117
+ 'activities/exchange/diamond/max-amount',
118
+ 'activities/exchange/diamond/settle',
119
+ 'tournament/detail',
120
+ 'ranking/detail',
121
+ 'ranking/detail/option',
122
+ 'hot-game/ranking',
123
+ 'activities/getFreeGameReward',
124
+ 'activities/getFreeGameRewardList',
125
+ 'activities/rebate/estimate',
126
+ 'activities/rebate/collect',
127
+ 'activities/rebate/history',
128
+ 'activities/lose-rebate/history',
129
+ 'friends',
130
+ 'friends/home',
131
+ 'friends/reward-list',
132
+ 'friends/dashboard',
133
+ 'friends/dashboard/list',
134
+ 'activities/ranking',
135
+ 'activities/activity/ranking',
136
+ 'activities/cashRain',
137
+ 'activities/jackpot/list',
138
+ // 09/09
139
+ 'getAnnouncements',
140
+ 'game/list/v3/gameInfo',
141
+ 'payment/v2/uploadCommonSlip',
142
+ 'game/history/options',
143
+ ]
5
144
 
6
145
  function isValid(value) {
7
146
  return value !== undefined && value !== null
@@ -16,15 +155,41 @@ export default class Request {
16
155
  this.key = `cuora_${config.clientId}`
17
156
  this.errorHandler = null
18
157
  this.hosts = []
158
+ this.isBlocked = false
19
159
  this.initialize()
20
160
  }
21
161
 
22
162
  initialize() {
163
+ // 自定義參數序列化器 - 避免使用 URLSearchParams
164
+ this.axios.defaults.paramsSerializer = function (params) {
165
+ return Object.keys(params)
166
+ .map((key) => {
167
+ let value = params[key]
168
+ if (value === null || value === undefined) {
169
+ return null
170
+ }
171
+ // 針對key為q的參數進行手動編碼,避免雙重編碼
172
+ if (key === 'q' && typeof value === 'string') {
173
+ // 處理其他需要編碼的字符
174
+ value = encodeURIComponent(value).replace(/[!'()*]/g, function (c) {
175
+ return '%' + c.charCodeAt(0).toString(16).toUpperCase()
176
+ })
177
+ } else {
178
+ // 對其他參數使用標準編碼
179
+ value = encodeURIComponent(value)
180
+ }
181
+ return `${encodeURIComponent(key)}=${value}`
182
+ })
183
+ .filter(Boolean)
184
+ .join('&')
185
+ }
186
+
23
187
  this.axios.interceptors.request.use((axiosConfig) => {
24
188
  axiosConfig.headers['X-TH1GAMES-VERSION'] = this.config.version
25
189
  axiosConfig.headers['X-TH1GAMES-PLATFORM'] = this.config.platform
26
190
  if (this.getToken()) {
27
- axiosConfig.headers.Authorization = this.getToken()
191
+ // 為了支援V2版本的API接口新增Bearer來進行身份驗證
192
+ axiosConfig.headers.Authorization = `Bearer ${this.getToken()}`
28
193
  }
29
194
  return axiosConfig
30
195
  })
@@ -61,10 +226,25 @@ export default class Request {
61
226
  try {
62
227
  const cancelToken = customToken || this.source.token
63
228
  this._checkToken(req)
229
+
64
230
  const requestConfig = this._createConfig(req, cancelToken)
65
- const { data } = await this.axios.request(requestConfig)
66
- return data
231
+ // console.log('*請求資料Check', requestConfig)
232
+ const configUrls = ['getConfig', 'get-config']
233
+ if (this.isBlocked && !configUrls.includes(requestConfig.url)) {
234
+ // 狀態是維護中&請求非siteConfig,終止所有的請求,除了維護頁需要的資料(siteConfig)
235
+ // console.log('%c*禁止的請求目標', requestConfig)
236
+ } else {
237
+ // console.log('%c*允許的請求目標', requestConfig)
238
+ const { data } = await this.axios.request(requestConfig)
239
+ return data
240
+ }
67
241
  } catch (error) {
242
+ if (error.code === 'ERR_F108') {
243
+ console.log('%c*維護中', 'color: #00ff33ff; font-weight: bold;')
244
+ this.isBlocked = true
245
+ this.errorHandler && this.errorHandler(error)
246
+ throw error
247
+ }
68
248
  if (error.code !== 'ERR_800') {
69
249
  if (error.code) {
70
250
  this.errorHandler && this.errorHandler(error)
@@ -85,11 +265,37 @@ export default class Request {
85
265
 
86
266
  _createConfig(req, cancelToken) {
87
267
  const { method, url, params, isPublic, isFormData, headers } = req
268
+ let fullURL = this.config.fullURL
269
+ let urlName = url
270
+ // 有些API會將參數(/?)直接帶在URL上,所以要將參數排除
271
+ const cleanUrl = url.split('?')[0]
272
+
273
+ const isV2Supported = supportVersion2List.some((supportedUrl) => {
274
+ // 如果包含動態參數(:parameter),則使用模式匹配
275
+ if (supportedUrl.includes(':')) {
276
+ const pattern = supportedUrl.replace(/:[^/]+/g, '[^/]+')
277
+ const regex = new RegExp(`^${pattern}$`)
278
+ return regex.test(cleanUrl)
279
+ }
280
+ return supportedUrl === cleanUrl
281
+ })
282
+
283
+ // 目前全站都支援V2,若有需要限制為V1的站點可以填入,此段等轉換全部完成之後就可以移除了
284
+ const supportV2Toggle = [''].includes(this.config?.clientId)
285
+
286
+ if (isV2Supported && !supportV2Toggle) {
287
+ fullURL = fullURL.replace('/v1/', '/v2/')
288
+ urlName = this._convertUrlToKebabCase(url)
289
+ // console.log(`*[DEV_ONLY]V2`, 'url:', urlName)
290
+ } else {
291
+ // console.log(`*[DEV_ONLY]V2-不支援:`, 'url:', urlName)
292
+ }
293
+
88
294
  if (isFormData) {
89
295
  return {
90
- baseURL: this.config.fullURL,
296
+ baseURL: fullURL,
91
297
  method,
92
- url,
298
+ url: urlName,
93
299
  cancelToken,
94
300
  isPublic,
95
301
  headers: { 'Content-Type': 'multipart/form-data' },
@@ -97,9 +303,9 @@ export default class Request {
97
303
  }
98
304
  } else {
99
305
  return {
100
- baseURL: this.config.fullURL,
306
+ baseURL: fullURL,
101
307
  method,
102
- url,
308
+ url: urlName,
103
309
  cancelToken,
104
310
  isPublic,
105
311
  headers,
@@ -108,6 +314,38 @@ export default class Request {
108
314
  }
109
315
  }
110
316
 
317
+ // 調整API路徑與名稱
318
+ _convertUrlToKebabCase(url) {
319
+ const specifyingPath = {
320
+ 'all-activities/list': 'activities/all-activities-list',
321
+ friends: 'activities/friends',
322
+ 'friends/home': 'activities/friends/home',
323
+ 'friends/reward-list': 'activities/friends/reward-list',
324
+ 'friends/dashboard': 'activities/friends/dashboard',
325
+ 'friends/dashboard/list': 'activities/friends/dashboard/list',
326
+ 'activities/getFreeGameReward': 'activities/free-game/get-free-game-reward',
327
+ 'activities/getFreeGameRewardList': 'activities/free-game/get-free-game-reward-list',
328
+ 'activities/lose-rebate/history': 'activities/rebate/lose-rebate/history',
329
+ 'activities/ranking': 'activities/ranking/promotion-ranking',
330
+ 'activities/activity/ranking': 'activities/ranking/basic-ranking',
331
+ 'activities/cashRain': 'activities/cash-rain/exchange',
332
+ 'tournament/detail': 'activities/tournament/detail',
333
+ 'ranking/detail': 'activities/tournament/ranking/detail',
334
+ 'ranking/detail/option': 'activities/tournament/ranking/detail/option',
335
+ 'hot-game/ranking': 'activities/tournament/ranking/hot-game',
336
+ 'activities/rebate/estimate': 'activities/rebate/estimate',
337
+ 'activities/exchange/diamond/max-amount': 'activities/diamond/exchange/max-amount',
338
+ 'activities/exchange/diamond/settle': 'activities/diamond/exchange/settle',
339
+ }
340
+ if (specifyingPath[url]) {
341
+ // 和原有路徑不同有另外改路徑
342
+ return specifyingPath[url]
343
+ } else {
344
+ // 將API_URL的命名規則由駝峰調整為短橫線(-)
345
+ return url.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
346
+ }
347
+ }
348
+
111
349
  _checkToken(req) {
112
350
  if (!req.isPublic && !this.getToken()) {
113
351
  throw { code: 'ERR_A103', url: req.url }
@@ -1,5 +1,5 @@
1
1
  import uniqBy from 'lodash/uniqBy'
2
- import { load, defaultEndpoint } from '../lib/fingerprint_v3_11_5.js'
2
+ import { load, defaultEndpoint } from '../lib/fingerprint_v3_11_12.js'
3
3
 
4
4
  const reg = /fnapi\d*/
5
5
 
@@ -32,4 +32,28 @@ const getDeviceToken = async ({ fpToken, sentry, hosts, enable = true }) => {
32
32
  }
33
33
  }
34
34
 
35
- export { getDeviceToken }
35
+ // 重試機制,最多嘗試 maxRetries 次,每次間隔 intervalMs 毫秒
36
+ const getDeviceTokenWithRetry = async ({ fpToken, sentry, hosts, enable = true, maxRetries = 3, intervalMs = 1000 }) => {
37
+ if (!enable) {
38
+ return
39
+ }
40
+ // 設置幾秒後重試
41
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
42
+ // 設定重試次數
43
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
44
+ try {
45
+ const deviceToken = await getDeviceToken({ fpToken, sentry, hosts, enable })
46
+ if (deviceToken) return deviceToken
47
+ throw new Error('No device token received')
48
+ } catch (error) {
49
+ // 若失敗則等待intervalMs後重試,最多重試maxRetries次
50
+ if (attempt < maxRetries) {
51
+ await delay(intervalMs)
52
+ } else {
53
+ throw error
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ export { getDeviceToken, getDeviceTokenWithRetry }
package/src/util/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { getDeviceToken } from './deviceToken.js'
1
+ import { getDeviceToken, getDeviceTokenWithRetry } from './deviceToken.js'
2
2
  import storage from './storage.js'
3
3
  import * as constant from './constant.js'
4
4
  import { max } from './math.js'
5
5
 
6
- export default { getDeviceToken }
6
+ export default { getDeviceToken, getDeviceTokenWithRetry }
7
7
  export { constant, storage, max }
@@ -1,6 +1,12 @@
1
1
  export default {
2
2
  get(name, options) {
3
- const itemStr = localStorage.getItem(name)
3
+ let itemStr = null
4
+ try {
5
+ itemStr = localStorage.getItem(name)
6
+ } catch (error) {
7
+ console.error(`Error getting item from localStorage: ${error}`)
8
+ return null
9
+ }
4
10
 
5
11
  if (!itemStr) {
6
12
  return null
@@ -12,7 +18,7 @@ export default {
12
18
  return null
13
19
  }
14
20
 
15
- return item.value
21
+ return 'value' in item ? item.value : item
16
22
  },
17
23
  set(name, value, options) {
18
24
  const item = { value }
@@ -20,9 +26,17 @@ export default {
20
26
  if (options?.maxAge) {
21
27
  item.expiry = new Date().getTime() + options.maxAge * 1000
22
28
  }
23
- localStorage.setItem(name, JSON.stringify(item))
29
+ try {
30
+ localStorage.setItem(name, JSON.stringify(item))
31
+ } catch (error) {
32
+ console.error(`Error setting item in localStorage: ${error}`)
33
+ }
24
34
  },
25
35
  remove(name, options) {
26
- localStorage.removeItem(name)
36
+ try {
37
+ localStorage.removeItem(name)
38
+ } catch (error) {
39
+ console.error(`Error removing item from localStorage: ${error}`)
40
+ }
27
41
  },
28
42
  }