@jetthai/cuora 1.1.454 → 1.1.455-dev.1
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 +5 -12
- package/.claude/commands/commit-push.md +15 -4
- package/.claude/commands/sync-ai-prompts.md +88 -1
- package/.claude/settings.local.json +3 -1
- package/.github/copilot-instructions.md +553 -395
- package/.husky/post-checkout +3 -3
- package/.husky/pre-push +1 -1
- package/.prettierignore +2 -1
- package/AGENTS.md +553 -395
- package/AI_PROMPT_SOURCE.md +664 -128
- package/CHANGELOG.md +317 -22
- package/CLAUDE.md +553 -395
- package/GEMINI.md +553 -395
- package/README.md +40 -137
- package/package.json +1 -1
- package/scripts/auto-version.js +1 -0
- package/src/api/user.js +12 -0
- package/src/index.js +2 -2
- package/src/machine/auth.js +15 -2
- package/src/machine/common.js +11 -21
- package/src/machine/deposit/crypto_bank_cash.js +4 -5
- package/src/machine/deposit/crypto_way_cash.js +4 -5
- package/src/machine/deposit/direct_cash.js +7 -3
- package/src/machine/deposit/loadcard_cash.js +7 -8
- package/src/machine/deposit/manual_cash.js +8 -2
- package/src/machine/deposit/qrcode_cash.js +5 -7
- package/src/machine/deposit/virtual_bank_cash.js +5 -2
- package/src/machine/user_sign_up.js +16 -3
- package/src/request/request.js +7 -3
- package/src/util/index.js +2 -1
- package/src/util/paramStore.js +139 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import payment from '../../api/payment.js'
|
|
3
|
-
import { max } from '../../util'
|
|
4
3
|
|
|
5
4
|
export default function (request, context) {
|
|
6
5
|
const { paymentDetail = [], promotion, selectedAmount } = context || {}
|
|
@@ -102,6 +101,7 @@ export default function (request, context) {
|
|
|
102
101
|
target: '.debouncing',
|
|
103
102
|
actions: 'setPromotion',
|
|
104
103
|
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
|
|
126
|
+
const { paymentDetail } = 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,11 +131,9 @@ 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),
|
|
135
134
|
}
|
|
136
135
|
}),
|
|
137
136
|
setPromotion: assign((context, event) => {
|
|
138
|
-
const { selectedAmount } = context
|
|
139
137
|
const promotion = event.data
|
|
140
138
|
const qrcodes = context.qrcodes
|
|
141
139
|
const selectedQrcode = qrcodes[0]
|
|
@@ -144,17 +142,14 @@ export default function (request, context) {
|
|
|
144
142
|
qrcodes,
|
|
145
143
|
selectedQrcode,
|
|
146
144
|
options: selectedQrcode?.optional,
|
|
147
|
-
selectedAmount: max(promotion.minimumAmount, selectedQrcode?.minimum, selectedAmount, 0),
|
|
148
145
|
calculation: null,
|
|
149
146
|
}
|
|
150
147
|
}),
|
|
151
148
|
setQrcode: assign((context, event) => {
|
|
152
|
-
const { promotion, selectedAmount } = context
|
|
153
149
|
const selectedQrcode = event.data
|
|
154
150
|
return {
|
|
155
151
|
selectedQrcode,
|
|
156
152
|
options: selectedQrcode.optional,
|
|
157
|
-
selectedAmount: max(promotion.minimumAmount, selectedAmount, 0),
|
|
158
153
|
calculation: null,
|
|
159
154
|
}
|
|
160
155
|
}),
|
|
@@ -194,6 +189,9 @@ export default function (request, context) {
|
|
|
194
189
|
}),
|
|
195
190
|
},
|
|
196
191
|
guards: {
|
|
192
|
+
isPromotionChanged: (context, event) => {
|
|
193
|
+
return event.data?.promotionsNo !== context.promotion?.promotionsNo
|
|
194
|
+
},
|
|
197
195
|
hasQrcodeMethods: (context, event) => {
|
|
198
196
|
return context.paymentDetail?.filter((element) => element.category === context.currentCategory).length > 0
|
|
199
197
|
},
|
|
@@ -1,6 +1,5 @@
|
|
|
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'
|
|
4
3
|
|
|
5
4
|
export default function (request, context) {
|
|
6
5
|
const { appSecret } = request.config
|
|
@@ -99,6 +98,7 @@ export default function (request, context) {
|
|
|
99
98
|
target: 'debouncing',
|
|
100
99
|
actions: 'setPromotion',
|
|
101
100
|
internal: false,
|
|
101
|
+
cond: 'isPromotionChanged',
|
|
102
102
|
},
|
|
103
103
|
INPUT_AMOUNT: {
|
|
104
104
|
target: 'debouncing',
|
|
@@ -120,7 +120,6 @@ 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),
|
|
124
123
|
virtualBanks,
|
|
125
124
|
}
|
|
126
125
|
}),
|
|
@@ -158,10 +157,14 @@ export default function (request, context) {
|
|
|
158
157
|
setPromotion: assign((context, event) => {
|
|
159
158
|
return {
|
|
160
159
|
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
|
+
},
|
|
165
168
|
isCalculable: (context, event) => {
|
|
166
169
|
const {
|
|
167
170
|
selectedAmount,
|
|
@@ -1,6 +1,7 @@
|
|
|
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'
|
|
4
5
|
|
|
5
6
|
// 註冊強制綁定多型出款:轉發各綁定型別欄位(BANK / CRYPTO / EWALLET),只帶有值的欄位
|
|
6
7
|
const BIND_FIELDS = [
|
|
@@ -104,6 +105,7 @@ export default function (request) {
|
|
|
104
105
|
return {
|
|
105
106
|
signUpData: {
|
|
106
107
|
provider: 'local',
|
|
108
|
+
birthday,
|
|
107
109
|
...pickBindData(event.data),
|
|
108
110
|
birthday,
|
|
109
111
|
email,
|
|
@@ -127,6 +129,7 @@ export default function (request) {
|
|
|
127
129
|
return {
|
|
128
130
|
signUpData: {
|
|
129
131
|
provider: 'phone',
|
|
132
|
+
birthday,
|
|
130
133
|
...pickBindData(event.data),
|
|
131
134
|
birthday,
|
|
132
135
|
email,
|
|
@@ -149,6 +152,7 @@ export default function (request) {
|
|
|
149
152
|
return {
|
|
150
153
|
signUpData: {
|
|
151
154
|
provider: 'email',
|
|
155
|
+
birthday,
|
|
152
156
|
...pickBindData(event.data),
|
|
153
157
|
birthday,
|
|
154
158
|
email,
|
|
@@ -188,10 +192,19 @@ export default function (request) {
|
|
|
188
192
|
const { signUpData, deviceTokenEnable } = context
|
|
189
193
|
const dt = deviceTokenEnable ? await request.config.getDt?.() : undefined
|
|
190
194
|
|
|
191
|
-
|
|
195
|
+
// 宿主明確帶入的 affiliateCode(註冊表單的代理碼欄位)優先於網址/儲存這類環境值。
|
|
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
|
|
192
204
|
const messages = {
|
|
193
205
|
url: window.location.href,
|
|
194
206
|
affiliateCode,
|
|
207
|
+
acSource: hasExplicitAc ? 'signUpData' : acRead.from,
|
|
195
208
|
}
|
|
196
209
|
|
|
197
210
|
// 因 client-pwa-cash PR #805 的問題,暫時註解此 Sentry 上報
|
|
@@ -205,11 +218,11 @@ export default function (request) {
|
|
|
205
218
|
|
|
206
219
|
return await request.send(
|
|
207
220
|
auth.register({
|
|
208
|
-
...
|
|
221
|
+
...signUpRest,
|
|
209
222
|
...referralObj,
|
|
210
223
|
dt,
|
|
211
224
|
reCaptchaToken: context.reCaptchaToken,
|
|
212
|
-
fc: context.fc,
|
|
225
|
+
fc: context.fc || readParamFromLocation(FC_KEYS).value || undefined,
|
|
213
226
|
})
|
|
214
227
|
)
|
|
215
228
|
},
|
package/src/request/request.js
CHANGED
|
@@ -251,12 +251,14 @@ export default class Request {
|
|
|
251
251
|
|
|
252
252
|
async send(req, customToken) {
|
|
253
253
|
try {
|
|
254
|
-
// reject → onError → leaving →
|
|
254
|
+
// 非 public 請求缺 token 直接 reject:reject → onError → leaving → 乾淨登出,且不送網路 → 洪水照止
|
|
255
255
|
if (!req.isPublic && !this.getToken()) return Promise.reject({ code: 'ERR_A103' })
|
|
256
256
|
|
|
257
|
-
|
|
257
|
+
// axios <0.22 對 cancelToken.promise 註冊的取消 handler 永不退訂(xhr.js 無 unsubscribe),
|
|
258
|
+
// 預設掛長壽命共用 token 會使 handler 隨請求數線性累積(掛機過夜 OOM,TI-15555)。
|
|
259
|
+
// 故預設不掛 cancelToken,僅呼叫端明確傳入 customToken(自行管理其生命週期)時才附加。
|
|
260
|
+
const cancelToken = customToken
|
|
258
261
|
|
|
259
|
-
// ERR_A103 No token provided 改由後端回傳:不再於送出前自行 throw,
|
|
260
262
|
const requestConfig = this._createConfig(req, cancelToken)
|
|
261
263
|
const configUrls = ['getConfig', 'get-config']
|
|
262
264
|
if (this.isBlocked && !configUrls.includes(requestConfig.url)) {
|
|
@@ -283,6 +285,8 @@ export default class Request {
|
|
|
283
285
|
}
|
|
284
286
|
}
|
|
285
287
|
|
|
288
|
+
// 注意:send() 已不再預設附加 this.source.token(見 send 內註解),
|
|
289
|
+
// sourceUpdate 僅對「呼叫端明確以 this.source.token 為 customToken」的請求有效;保留以維持 API 相容。
|
|
286
290
|
sourceUpdate() {
|
|
287
291
|
this.source.cancel('Requests Cancelled')
|
|
288
292
|
this.source = this.axios.CancelToken.source()
|
package/src/util/index.js
CHANGED
|
@@ -0,0 +1,139 @@
|
|
|
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 }
|