@jetthai/cuora 1.1.455-dev.9 → 1.1.455
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/.claude/commands/auto-git-flow.md +12 -5
- package/.claude/commands/commit-push.md +4 -15
- package/.claude/commands/sync-ai-prompts.md +1 -88
- package/.claude/settings.local.json +1 -3
- package/.github/copilot-instructions.md +394 -552
- package/.husky/post-checkout +3 -3
- package/.husky/pre-push +1 -1
- package/.prettierignore +1 -2
- package/AGENTS.md +394 -552
- package/AI_PROMPT_SOURCE.md +127 -663
- package/CHANGELOG.md +22 -325
- package/CLAUDE.md +394 -552
- package/GEMINI.md +394 -552
- package/README.md +137 -40
- package/package.json +1 -1
- package/scripts/auto-version.js +0 -1
- package/src/api/activity.js +2 -2
- package/src/api/user.js +0 -12
- package/src/index.js +2 -2
- package/src/machine/auth.js +2 -15
- package/src/machine/common.js +21 -11
- package/src/machine/deposit/crypto_bank_cash.js +5 -4
- package/src/machine/deposit/crypto_qrcode_cash.js +40 -25
- package/src/machine/deposit/crypto_way_cash.js +5 -4
- package/src/machine/deposit/direct_cash.js +3 -7
- package/src/machine/deposit/loadcard_cash.js +8 -7
- package/src/machine/deposit/manual_cash.js +2 -8
- package/src/machine/deposit/qrcode_cash.js +7 -5
- package/src/machine/deposit/virtual_bank_cash.js +2 -5
- package/src/machine/side_cash.js +2 -3
- package/src/machine/side_v2.js +4 -6
- package/src/machine/user_sign_up.js +3 -16
- package/src/util/index.js +1 -2
- package/src/util/paramStore.js +0 -139
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import payment from '../../api/payment.js'
|
|
3
|
+
import { max } from '../../util'
|
|
3
4
|
|
|
4
5
|
export default function (request, context) {
|
|
5
6
|
const { paymentDetail = [], promotion, selectedAmount } = context || {}
|
|
@@ -95,7 +96,6 @@ export default function (request, context) {
|
|
|
95
96
|
target: '.debouncing',
|
|
96
97
|
actions: 'setPromotion',
|
|
97
98
|
internal: false,
|
|
98
|
-
cond: 'isPromotionChanged',
|
|
99
99
|
},
|
|
100
100
|
SELECT_LOADCARD: {
|
|
101
101
|
target: '.debouncing',
|
|
@@ -112,7 +112,7 @@ export default function (request, context) {
|
|
|
112
112
|
{
|
|
113
113
|
actions: {
|
|
114
114
|
setInitData: assign((context, event) => {
|
|
115
|
-
const { paymentDetail } = context
|
|
115
|
+
const { paymentDetail, selectedAmount, promotion } = context
|
|
116
116
|
const loadcards = paymentDetail.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
|
|
117
117
|
const selectedLoadcard = loadcards[0]
|
|
118
118
|
return {
|
|
@@ -120,9 +120,11 @@ export default function (request, context) {
|
|
|
120
120
|
loadcards,
|
|
121
121
|
selectedLoadcard,
|
|
122
122
|
options: selectedLoadcard?.optional,
|
|
123
|
+
selectedAmount: max(promotion?.minimumAmount, selectedLoadcard?.minimum, selectedAmount, 0),
|
|
123
124
|
}
|
|
124
125
|
}),
|
|
125
126
|
setPromotion: assign((context, event) => {
|
|
127
|
+
const { selectedAmount } = context
|
|
126
128
|
const promotion = event.data
|
|
127
129
|
const loadcards = context.loadcards
|
|
128
130
|
const selectedLoadcard = loadcards[0]
|
|
@@ -131,14 +133,17 @@ export default function (request, context) {
|
|
|
131
133
|
loadcards,
|
|
132
134
|
selectedLoadcard,
|
|
133
135
|
options: selectedLoadcard?.optional,
|
|
136
|
+
selectedAmount: max(promotion.minimumAmount, selectedLoadcard?.minimum, selectedAmount, 0),
|
|
134
137
|
calculation: null,
|
|
135
138
|
}
|
|
136
139
|
}),
|
|
137
140
|
setLoadcard: assign((context, event) => {
|
|
141
|
+
const { promotion, selectedAmount } = context
|
|
138
142
|
const selectedLoadcard = event.data
|
|
139
143
|
return {
|
|
140
144
|
selectedLoadcard,
|
|
141
145
|
options: selectedLoadcard.optional,
|
|
146
|
+
selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
|
|
142
147
|
calculation: null,
|
|
143
148
|
}
|
|
144
149
|
}),
|
|
@@ -179,11 +184,7 @@ export default function (request, context) {
|
|
|
179
184
|
}
|
|
180
185
|
}),
|
|
181
186
|
},
|
|
182
|
-
guards: {
|
|
183
|
-
isPromotionChanged: (context, event) => {
|
|
184
|
-
return event.data?.promotionsNo !== context.promotion?.promotionsNo
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
+
guards: {},
|
|
187
188
|
services: {
|
|
188
189
|
fetchCalculation: async (context, event) => {
|
|
189
190
|
const { selectedLoadcard, selectedAmount, promotion } = context
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import payment from '../../api/payment.js'
|
|
3
|
+
import { max } from '../../util/index.js'
|
|
3
4
|
|
|
4
5
|
export default function (request, context) {
|
|
5
6
|
const { appSecret } = request.config
|
|
@@ -133,7 +134,6 @@ export default function (request, context) {
|
|
|
133
134
|
target: 'debouncing',
|
|
134
135
|
actions: 'setPromotion',
|
|
135
136
|
internal: false,
|
|
136
|
-
cond: 'isPromotionChanged',
|
|
137
137
|
},
|
|
138
138
|
INPUT_AMOUNT: {
|
|
139
139
|
target: 'debouncing',
|
|
@@ -141,9 +141,7 @@ export default function (request, context) {
|
|
|
141
141
|
internal: false,
|
|
142
142
|
},
|
|
143
143
|
SELECT_HOUSE_BANK: {
|
|
144
|
-
target: 'debouncing',
|
|
145
144
|
actions: 'setHouseBank',
|
|
146
|
-
internal: false,
|
|
147
145
|
},
|
|
148
146
|
},
|
|
149
147
|
},
|
|
@@ -182,6 +180,7 @@ export default function (request, context) {
|
|
|
182
180
|
method: currentPayment.method,
|
|
183
181
|
processing,
|
|
184
182
|
houseBanks,
|
|
183
|
+
selectedAmount: max(promotion?.minimumAmount, currentPayment?.minimum, selectedAmount, 0),
|
|
185
184
|
selectedHouseBank: houseBanks[0],
|
|
186
185
|
userBanks,
|
|
187
186
|
selectedUserBank: userBanks[0],
|
|
@@ -195,7 +194,6 @@ export default function (request, context) {
|
|
|
195
194
|
setHouseBank: assign((context, event) => {
|
|
196
195
|
return {
|
|
197
196
|
selectedHouseBank: event.data,
|
|
198
|
-
calculation: null,
|
|
199
197
|
}
|
|
200
198
|
}),
|
|
201
199
|
inputAmount: assign((context, event) => {
|
|
@@ -278,14 +276,10 @@ export default function (request, context) {
|
|
|
278
276
|
setPromotion: assign((context, event) => {
|
|
279
277
|
return {
|
|
280
278
|
promotion: event.data,
|
|
281
|
-
calculation: null,
|
|
282
279
|
}
|
|
283
280
|
}),
|
|
284
281
|
},
|
|
285
282
|
guards: {
|
|
286
|
-
isPromotionChanged: (context, event) => {
|
|
287
|
-
return event.data?.promotionsNo !== context.promotion?.promotionsNo
|
|
288
|
-
},
|
|
289
283
|
isCalculable: (context, event) => {
|
|
290
284
|
const {
|
|
291
285
|
selectedAmount,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import payment from '../../api/payment.js'
|
|
3
|
+
import { max } from '../../util'
|
|
3
4
|
|
|
4
5
|
export default function (request, context) {
|
|
5
6
|
const { paymentDetail = [], promotion, selectedAmount } = context || {}
|
|
@@ -101,7 +102,6 @@ export default function (request, context) {
|
|
|
101
102
|
target: '.debouncing',
|
|
102
103
|
actions: 'setPromotion',
|
|
103
104
|
internal: false,
|
|
104
|
-
cond: 'isPromotionChanged',
|
|
105
105
|
},
|
|
106
106
|
SELECT_QRCODE: {
|
|
107
107
|
target: '.debouncing',
|
|
@@ -123,7 +123,7 @@ export default function (request, context) {
|
|
|
123
123
|
{
|
|
124
124
|
actions: {
|
|
125
125
|
setInitData: assign((context, event) => {
|
|
126
|
-
const { paymentDetail } = context
|
|
126
|
+
const { paymentDetail, selectedAmount, promotion } = context
|
|
127
127
|
const qrcodes = paymentDetail.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
|
|
128
128
|
const selectedQrcode = qrcodes[0]
|
|
129
129
|
return {
|
|
@@ -131,9 +131,11 @@ export default function (request, context) {
|
|
|
131
131
|
qrcodes,
|
|
132
132
|
selectedQrcode,
|
|
133
133
|
options: selectedQrcode?.optional,
|
|
134
|
+
selectedAmount: max(promotion?.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
|
|
134
135
|
}
|
|
135
136
|
}),
|
|
136
137
|
setPromotion: assign((context, event) => {
|
|
138
|
+
const { selectedAmount } = context
|
|
137
139
|
const promotion = event.data
|
|
138
140
|
const qrcodes = context.qrcodes
|
|
139
141
|
const selectedQrcode = qrcodes[0]
|
|
@@ -142,14 +144,17 @@ export default function (request, context) {
|
|
|
142
144
|
qrcodes,
|
|
143
145
|
selectedQrcode,
|
|
144
146
|
options: selectedQrcode?.optional,
|
|
147
|
+
selectedAmount: max(promotion.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
|
|
145
148
|
calculation: null,
|
|
146
149
|
}
|
|
147
150
|
}),
|
|
148
151
|
setQrcode: assign((context, event) => {
|
|
152
|
+
const { promotion, selectedAmount } = context
|
|
149
153
|
const selectedQrcode = event.data
|
|
150
154
|
return {
|
|
151
155
|
selectedQrcode,
|
|
152
156
|
options: selectedQrcode.optional,
|
|
157
|
+
selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
|
|
153
158
|
calculation: null,
|
|
154
159
|
}
|
|
155
160
|
}),
|
|
@@ -189,9 +194,6 @@ export default function (request, context) {
|
|
|
189
194
|
}),
|
|
190
195
|
},
|
|
191
196
|
guards: {
|
|
192
|
-
isPromotionChanged: (context, event) => {
|
|
193
|
-
return event.data?.promotionsNo !== context.promotion?.promotionsNo
|
|
194
|
-
},
|
|
195
197
|
hasQrcodeMethods: (context, event) => {
|
|
196
198
|
return context.paymentDetail?.filter((element) => element.category === context.currentCategory).length > 0
|
|
197
199
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import payment from '@jetthai/cuora/src/api/payment.js'
|
|
3
|
+
import { max } from '@jetthai/cuora/src/util/index.js'
|
|
3
4
|
|
|
4
5
|
export default function (request, context) {
|
|
5
6
|
const { appSecret } = request.config
|
|
@@ -98,7 +99,6 @@ export default function (request, context) {
|
|
|
98
99
|
target: 'debouncing',
|
|
99
100
|
actions: 'setPromotion',
|
|
100
101
|
internal: false,
|
|
101
|
-
cond: 'isPromotionChanged',
|
|
102
102
|
},
|
|
103
103
|
INPUT_AMOUNT: {
|
|
104
104
|
target: 'debouncing',
|
|
@@ -120,6 +120,7 @@ export default function (request, context) {
|
|
|
120
120
|
currentPayment,
|
|
121
121
|
method: currentPayment.method,
|
|
122
122
|
processing,
|
|
123
|
+
selectedAmount: max(promotion?.minimumAmount, currentPayment?.minimum, selectedAmount, 0),
|
|
123
124
|
virtualBanks,
|
|
124
125
|
}
|
|
125
126
|
}),
|
|
@@ -157,14 +158,10 @@ export default function (request, context) {
|
|
|
157
158
|
setPromotion: assign((context, event) => {
|
|
158
159
|
return {
|
|
159
160
|
promotion: event.data,
|
|
160
|
-
calculation: null,
|
|
161
161
|
}
|
|
162
162
|
}),
|
|
163
163
|
},
|
|
164
164
|
guards: {
|
|
165
|
-
isPromotionChanged: (context, event) => {
|
|
166
|
-
return event.data?.promotionsNo !== context.promotion?.promotionsNo
|
|
167
|
-
},
|
|
168
165
|
isCalculable: (context, event) => {
|
|
169
166
|
const {
|
|
170
167
|
selectedAmount,
|
package/src/machine/side_cash.js
CHANGED
|
@@ -66,13 +66,12 @@ export default function (request) {
|
|
|
66
66
|
actions: {
|
|
67
67
|
setMenu: assign((context, event) => {
|
|
68
68
|
const menu = event.data
|
|
69
|
-
if (!Array.isArray(menu?.data)) return
|
|
70
69
|
addLevelProperty(menu.data, 0)
|
|
71
70
|
return { menu }
|
|
72
71
|
}),
|
|
73
72
|
updateMenu: assign((context, event) => {
|
|
74
73
|
const menu = event.data
|
|
75
|
-
if (menu
|
|
74
|
+
if (menu.data.length) {
|
|
76
75
|
addLevelProperty(menu.data, 0)
|
|
77
76
|
return { menu, defaultMenuItemStack: getDefaultItem(menu.data[0]) }
|
|
78
77
|
}
|
|
@@ -83,7 +82,7 @@ export default function (request) {
|
|
|
83
82
|
return await request.send(game.getListRoot({ appSecret }))
|
|
84
83
|
},
|
|
85
84
|
fetchUpdateMenu: async (context, event) => {
|
|
86
|
-
return await request.send(game.getListRoot({ timestamp: context.menu
|
|
85
|
+
return await request.send(game.getListRoot({ timestamp: context.menu.timestamp, appSecret }))
|
|
87
86
|
},
|
|
88
87
|
},
|
|
89
88
|
}
|
package/src/machine/side_v2.js
CHANGED
|
@@ -81,13 +81,12 @@ export default function (request) {
|
|
|
81
81
|
actions: {
|
|
82
82
|
setMenu: assign((context, event) => {
|
|
83
83
|
const menu = event.data
|
|
84
|
-
if (!Array.isArray(menu?.data)) return
|
|
85
84
|
addLevelProperty(menu.data, 0)
|
|
86
85
|
return { menu }
|
|
87
86
|
}),
|
|
88
87
|
setDefaultMenuItemStack: assign((context, event) => {
|
|
89
88
|
const menu = event.data
|
|
90
|
-
if (menu
|
|
89
|
+
if (menu.data.length > 0) {
|
|
91
90
|
const menuItemStack = getDefaultItem(menu.data[0])
|
|
92
91
|
return { menuItemStack, defaultMenuItemStack: menuItemStack }
|
|
93
92
|
}
|
|
@@ -128,7 +127,7 @@ export default function (request) {
|
|
|
128
127
|
}),
|
|
129
128
|
updateMenu: assign((context, event) => {
|
|
130
129
|
const menu = event.data
|
|
131
|
-
if (menu
|
|
130
|
+
if (menu.data.length) {
|
|
132
131
|
addLevelProperty(menu.data, 0)
|
|
133
132
|
return { menu, defaultMenuItemStack: getDefaultItem(menu.data[0]) }
|
|
134
133
|
}
|
|
@@ -157,7 +156,7 @@ export default function (request) {
|
|
|
157
156
|
isInMenu: (context, event) => {
|
|
158
157
|
const { menuItemStack, menu } = context
|
|
159
158
|
const menuItem = menuItemStack.slice(-1)[0]
|
|
160
|
-
return isItemInMenu(menuItem, menu
|
|
159
|
+
return isItemInMenu(menuItem, menu.data)
|
|
161
160
|
},
|
|
162
161
|
},
|
|
163
162
|
services: {
|
|
@@ -165,7 +164,7 @@ export default function (request) {
|
|
|
165
164
|
return await request.send(game.getListRoot({ appSecret }))
|
|
166
165
|
},
|
|
167
166
|
fetchUpdateMenu: async (context, event) => {
|
|
168
|
-
return await request.send(game.getListRoot({ timestamp: context.menu
|
|
167
|
+
return await request.send(game.getListRoot({ timestamp: context.menu.timestamp, appSecret }))
|
|
169
168
|
},
|
|
170
169
|
},
|
|
171
170
|
}
|
|
@@ -173,7 +172,6 @@ export default function (request) {
|
|
|
173
172
|
}
|
|
174
173
|
|
|
175
174
|
function isItemInMenu(targetItem, menuList) {
|
|
176
|
-
if (!Array.isArray(menuList)) return false
|
|
177
175
|
return menuList.reduce((result, currentItem) => {
|
|
178
176
|
if (result) {
|
|
179
177
|
return true
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import auth from '../api/auth.js'
|
|
3
3
|
import storage from '../util/storage.js'
|
|
4
|
-
import { readParamFromLocation, normalize, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
|
|
5
4
|
|
|
6
5
|
// 註冊強制綁定多型出款:轉發各綁定型別欄位(BANK / CRYPTO / EWALLET),只帶有值的欄位
|
|
7
6
|
const BIND_FIELDS = [
|
|
@@ -105,7 +104,6 @@ export default function (request) {
|
|
|
105
104
|
return {
|
|
106
105
|
signUpData: {
|
|
107
106
|
provider: 'local',
|
|
108
|
-
birthday,
|
|
109
107
|
...pickBindData(event.data),
|
|
110
108
|
birthday,
|
|
111
109
|
email,
|
|
@@ -129,7 +127,6 @@ export default function (request) {
|
|
|
129
127
|
return {
|
|
130
128
|
signUpData: {
|
|
131
129
|
provider: 'phone',
|
|
132
|
-
birthday,
|
|
133
130
|
...pickBindData(event.data),
|
|
134
131
|
birthday,
|
|
135
132
|
email,
|
|
@@ -152,7 +149,6 @@ export default function (request) {
|
|
|
152
149
|
return {
|
|
153
150
|
signUpData: {
|
|
154
151
|
provider: 'email',
|
|
155
|
-
birthday,
|
|
156
152
|
...pickBindData(event.data),
|
|
157
153
|
birthday,
|
|
158
154
|
email,
|
|
@@ -192,19 +188,10 @@ export default function (request) {
|
|
|
192
188
|
const { signUpData, deviceTokenEnable } = context
|
|
193
189
|
const dt = deviceTokenEnable ? await request.config.getDt?.() : undefined
|
|
194
190
|
|
|
195
|
-
|
|
196
|
-
// 判定用 `!== undefined` 而非 hasOwnProperty:上面的 setSignUpId/Phone/Email 是以解構寫入
|
|
197
|
-
// signUpData,宿主沒帶時 key 仍然存在(值為 undefined),hasOwnProperty 會恆為 true、
|
|
198
|
-
// 讓三層解析變成死碼。也不能用 `||`,否則使用者刻意清空送出的空字串會被吃掉、
|
|
199
|
-
// 退回三層解析把剛清掉的舊代理碼從網址撿回來。
|
|
200
|
-
const { affiliateCode: explicitAffiliateCode, ...signUpRest } = signUpData || {}
|
|
201
|
-
const hasExplicitAc = explicitAffiliateCode !== undefined
|
|
202
|
-
const acRead = readParamFromLocation(AC_KEYS)
|
|
203
|
-
const affiliateCode = hasExplicitAc ? normalize(explicitAffiliateCode) : acRead.value
|
|
191
|
+
const affiliateCode = storage.get('ac') || signUpData?.affiliateCode
|
|
204
192
|
const messages = {
|
|
205
193
|
url: window.location.href,
|
|
206
194
|
affiliateCode,
|
|
207
|
-
acSource: hasExplicitAc ? 'signUpData' : acRead.from,
|
|
208
195
|
}
|
|
209
196
|
|
|
210
197
|
// 因 client-pwa-cash PR #805 的問題,暫時註解此 Sentry 上報
|
|
@@ -218,11 +205,11 @@ export default function (request) {
|
|
|
218
205
|
|
|
219
206
|
return await request.send(
|
|
220
207
|
auth.register({
|
|
221
|
-
...
|
|
208
|
+
...signUpData,
|
|
222
209
|
...referralObj,
|
|
223
210
|
dt,
|
|
224
211
|
reCaptchaToken: context.reCaptchaToken,
|
|
225
|
-
fc: context.fc
|
|
212
|
+
fc: context.fc,
|
|
226
213
|
})
|
|
227
214
|
)
|
|
228
215
|
},
|
package/src/util/index.js
CHANGED
package/src/util/paramStore.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import Cookies from 'universal-cookie'
|
|
2
|
-
import storage from './storage.js'
|
|
3
|
-
|
|
4
|
-
export const PARAM_MAX_AGE = 60 * 60 * 24 * 7
|
|
5
|
-
export const AC_KEYS = ['ac', 'referralCode']
|
|
6
|
-
export const FC_KEYS = ['fc', 'affiliate']
|
|
7
|
-
|
|
8
|
-
const DIRTY_VALUES = ['undefined', 'null', 'NaN']
|
|
9
|
-
|
|
10
|
-
const reportedOnce = new Set()
|
|
11
|
-
|
|
12
|
-
function cookieJar() {
|
|
13
|
-
return typeof document === 'undefined' ? null : new Cookies()
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function normalize(value) {
|
|
17
|
-
if (value === undefined || value === null) return null
|
|
18
|
-
const trimmed = String(value).trim()
|
|
19
|
-
if (trimmed === '' || DIRTY_VALUES.includes(trimmed)) return null
|
|
20
|
-
return trimmed
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// storage.js 的 JSON.parse 未包在 try/catch 內,localStorage 若存有同名裸字串會 throw,
|
|
24
|
-
// 未攔截會沿 xstate entry chain 往上炸掉整條 setUA→setAgent→setPixel→setKPixel→setFbclid
|
|
25
|
-
function readLocal(name) {
|
|
26
|
-
try {
|
|
27
|
-
return normalize(storage.get(name))
|
|
28
|
-
} catch (error) {
|
|
29
|
-
return null
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function readCookie(name) {
|
|
34
|
-
const jar = cookieJar()
|
|
35
|
-
if (!jar) return null
|
|
36
|
-
try {
|
|
37
|
-
return normalize(jar.get(name, { doNotParse: true }))
|
|
38
|
-
} catch (error) {
|
|
39
|
-
return null
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function readParam(urlParams, keys) {
|
|
44
|
-
for (const key of keys) {
|
|
45
|
-
const value = normalize(urlParams?.get?.(key))
|
|
46
|
-
if (value) return { value, from: `url:${key}` }
|
|
47
|
-
}
|
|
48
|
-
for (const key of keys) {
|
|
49
|
-
const value = readLocal(key)
|
|
50
|
-
if (value) return { value, from: `local:${key}` }
|
|
51
|
-
}
|
|
52
|
-
for (const key of keys) {
|
|
53
|
-
const value = readCookie(key)
|
|
54
|
-
if (value) return { value, from: `cookie:${key}` }
|
|
55
|
-
}
|
|
56
|
-
return { value: null, from: 'none' }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function readParamFromLocation(keys) {
|
|
60
|
-
const search = typeof window === 'undefined' ? '' : window.location.search
|
|
61
|
-
return readParam(new URLSearchParams(search), keys)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function report(sentry, name, medium, reason) {
|
|
65
|
-
// 去重必須在確定送得出去之後才登錄,否則早於 sentry 注入的那次失敗會把 fingerprint 佔走,
|
|
66
|
-
// 導致之後真正有 sentry 時被自己的去重擋掉、永遠不上報
|
|
67
|
-
if (!sentry?.captureMessage) return
|
|
68
|
-
const fingerprint = `${name}:${medium}:${reason}`
|
|
69
|
-
if (reportedOnce.has(fingerprint)) return
|
|
70
|
-
reportedOnce.add(fingerprint)
|
|
71
|
-
sentry?.captureMessage?.(`[ParamStore] ${medium} persist ${reason}: ${name}`, {
|
|
72
|
-
level: 'warning',
|
|
73
|
-
tags: { feature: 'url-param-fallback', param_key: name, storage_medium: medium, failure_reason: reason },
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function clearParam(name) {
|
|
78
|
-
const result = { local: 'ok', cookie: 'ok', cleared: true }
|
|
79
|
-
try {
|
|
80
|
-
storage.remove(name)
|
|
81
|
-
} catch (error) {
|
|
82
|
-
result.local = 'throw'
|
|
83
|
-
}
|
|
84
|
-
const jar = cookieJar()
|
|
85
|
-
if (jar) {
|
|
86
|
-
try {
|
|
87
|
-
jar.remove(name, { path: '/' })
|
|
88
|
-
} catch (error) {
|
|
89
|
-
result.cookie = 'throw'
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return result
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function writeParam(name, value, options = {}) {
|
|
96
|
-
const { sentry, allowClear = false } = options
|
|
97
|
-
const normalized = normalize(value)
|
|
98
|
-
|
|
99
|
-
if (normalized === null) {
|
|
100
|
-
return allowClear ? clearParam(name) : { local: 'skipped', cookie: 'skipped', skipped: true }
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const result = { local: 'ok', cookie: 'ok' }
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
storage.set(name, normalized, { path: '/', maxAge: PARAM_MAX_AGE })
|
|
107
|
-
} catch (error) {
|
|
108
|
-
result.local = 'throw'
|
|
109
|
-
}
|
|
110
|
-
if (result.local === 'ok' && readLocal(name) !== normalized) {
|
|
111
|
-
result.local = 'mismatch'
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const jar = cookieJar()
|
|
115
|
-
if (!jar) {
|
|
116
|
-
result.cookie = 'unavailable'
|
|
117
|
-
} else {
|
|
118
|
-
try {
|
|
119
|
-
jar.set(name, normalized, {
|
|
120
|
-
path: '/',
|
|
121
|
-
maxAge: PARAM_MAX_AGE,
|
|
122
|
-
sameSite: 'lax',
|
|
123
|
-
secure: typeof window !== 'undefined' && window.location.protocol === 'https:',
|
|
124
|
-
})
|
|
125
|
-
} catch (error) {
|
|
126
|
-
result.cookie = 'throw'
|
|
127
|
-
}
|
|
128
|
-
if (result.cookie === 'ok' && readCookie(name) !== normalized) {
|
|
129
|
-
result.cookie = 'mismatch'
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (result.local !== 'ok') report(sentry, name, 'localStorage', result.local)
|
|
134
|
-
if (result.cookie !== 'ok') report(sentry, name, 'cookie', result.cookie)
|
|
135
|
-
|
|
136
|
-
return result
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export default { PARAM_MAX_AGE, AC_KEYS, FC_KEYS, normalize, readParam, readParamFromLocation, writeParam }
|