@jetthai/cuora 1.1.463 → 1.1.464

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.
@@ -309,7 +309,6 @@ io(`${socketURL}/frontend`, {
309
309
 
310
310
  - **siteConfig decoding**: the response is an encoded string; the `setConfig` action base64-decodes it to obtain the actual configuration (`loginMethods`, `paymentMethods`, `csChat`, etc.). **The downstream frontends' stores do not decode it a second time.**
311
311
  - **Broadcast rotation**: `picking` (5s) → `display` (5s) → `picking`, selecting `type === '0'` entries from `broadcastList`; already-shown items are added to `sentNormalBroadcastList` and not repeated
312
- - **Cocos native app detection**: when `window.CC_JSB === true`, **all agent/channel/cookie setup is skipped** (native apps don't need browser tracking)
313
312
  - **Mailbox filtering**: if `customerMessageEnable === false`, the count of CUSTOMER-type messages is deducted from the mailbox total
314
313
 
315
314
  ### 2.8 API Request Lifecycle
package/AGENTS.md CHANGED
@@ -309,7 +309,6 @@ io(`${socketURL}/frontend`, {
309
309
 
310
310
  - **siteConfig decoding**: the response is an encoded string; the `setConfig` action base64-decodes it to obtain the actual configuration (`loginMethods`, `paymentMethods`, `csChat`, etc.). **The downstream frontends' stores do not decode it a second time.**
311
311
  - **Broadcast rotation**: `picking` (5s) → `display` (5s) → `picking`, selecting `type === '0'` entries from `broadcastList`; already-shown items are added to `sentNormalBroadcastList` and not repeated
312
- - **Cocos native app detection**: when `window.CC_JSB === true`, **all agent/channel/cookie setup is skipped** (native apps don't need browser tracking)
313
312
  - **Mailbox filtering**: if `customerMessageEnable === false`, the count of CUSTOMER-type messages is deducted from the mailbox total
314
313
 
315
314
  ### 2.8 API Request Lifecycle
@@ -307,7 +307,6 @@ io(`${socketURL}/frontend`, {
307
307
 
308
308
  - **siteConfig 解碼**:回應為編碼字串,`setConfig` action 中 base64 解碼才得到實際設定(`loginMethods`、`paymentMethods`、`csChat` 等)。**下游前端的 store 不再解碼一次。**
309
309
  - **廣播輪播機制**:`picking`(5s)→ `display`(5s)→ `picking`,從 `broadcastList` 選 `type === '0'`,已顯示的加入 `sentNormalBroadcastList` 不再重複
310
- - **Cocos 原生 App 偵測**:`window.CC_JSB === true` 時**跳過所有 agent/channel/cookie 設定**(原生 App 不需瀏覽器追蹤)
311
310
  - **信箱過濾**:若 `customerMessageEnable === false`,從信箱總數中扣除 CUSTOMER 類型訊息數
312
311
 
313
312
  ### 2.8 API 請求生命週期
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.1.464](https://github.com/jetthai/cuora-module/compare/v1.1.463...v1.1.464) (2026-08-16)
6
+
7
+ ### Bug Fixes
8
+
9
+ - **deposit:** 切換存款活動不再重設使用者已選的通道 ([b9c1de2](https://github.com/jetthai/cuora-module/commit/b9c1de2f3665c56f52d7b074e892837e836d02fa))
10
+ - **user_sign_up:** 明確輸入判定改用 !== undefined,修復三層解析成為死碼 ([770450e](https://github.com/jetthai/cuora-module/commit/770450e6065d42d497504d2f8630c6740ec1e7c4))
11
+
5
12
  ### [1.1.463](https://github.com/jetthai/cuora-module/compare/v1.1.462...v1.1.463) (2026-08-12)
6
13
 
7
14
  ### [1.1.462](https://github.com/jetthai/cuora-module/compare/v1.1.461...v1.1.462) (2026-08-10)
package/CLAUDE.md CHANGED
@@ -309,7 +309,6 @@ io(`${socketURL}/frontend`, {
309
309
 
310
310
  - **siteConfig decoding**: the response is an encoded string; the `setConfig` action base64-decodes it to obtain the actual configuration (`loginMethods`, `paymentMethods`, `csChat`, etc.). **The downstream frontends' stores do not decode it a second time.**
311
311
  - **Broadcast rotation**: `picking` (5s) → `display` (5s) → `picking`, selecting `type === '0'` entries from `broadcastList`; already-shown items are added to `sentNormalBroadcastList` and not repeated
312
- - **Cocos native app detection**: when `window.CC_JSB === true`, **all agent/channel/cookie setup is skipped** (native apps don't need browser tracking)
313
312
  - **Mailbox filtering**: if `customerMessageEnable === false`, the count of CUSTOMER-type messages is deducted from the mailbox total
314
313
 
315
314
  ### 2.8 API Request Lifecycle
package/GEMINI.md CHANGED
@@ -309,7 +309,6 @@ io(`${socketURL}/frontend`, {
309
309
 
310
310
  - **siteConfig decoding**: the response is an encoded string; the `setConfig` action base64-decodes it to obtain the actual configuration (`loginMethods`, `paymentMethods`, `csChat`, etc.). **The downstream frontends' stores do not decode it a second time.**
311
311
  - **Broadcast rotation**: `picking` (5s) → `display` (5s) → `picking`, selecting `type === '0'` entries from `broadcastList`; already-shown items are added to `sentNormalBroadcastList` and not repeated
312
- - **Cocos native app detection**: when `window.CC_JSB === true`, **all agent/channel/cookie setup is skipped** (native apps don't need browser tracking)
313
312
  - **Mailbox filtering**: if `customerMessageEnable === false`, the count of CUSTOMER-type messages is deducted from the mailbox total
314
313
 
315
314
  ### 2.8 API Request Lifecycle
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.463",
3
+ "version": "1.1.464",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -2,6 +2,6 @@ import api from './api/index.js'
2
2
  import machine from './machine/index.js'
3
3
  import Request from './request/request.js'
4
4
  import Config from './request/config.js'
5
- import util, { constant, storage } from './util/index.js'
5
+ import util, { constant, storage, paramStore } from './util/index.js'
6
6
 
7
- export { api, machine, Request, Config, util, constant, storage }
7
+ export { api, machine, Request, Config, util, constant, storage, paramStore }
@@ -5,6 +5,7 @@ import user from '../api/user.js'
5
5
  import storage from '../util/storage.js'
6
6
  import common from '../api/common.js'
7
7
  import pickBy from 'lodash/pickBy.js'
8
+ import { readParamFromLocation, writeParam, normalize, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
8
9
 
9
10
  export default function (request) {
10
11
  const { appSecret, clientId, sentry } = request.config
@@ -469,7 +470,18 @@ export default function (request) {
469
470
 
470
471
  const dt = deviceTokenEnable ? await request.config.getDt?.() : undefined
471
472
 
472
- const affiliateCode = storage.get('ac')
473
+ // 宿主若明確帶了 ac(使用者在補資料頁/代理碼彈窗按下確認,含刻意留白)以它為準:
474
+ // 網址層仍留著進站時的 ?ac=,不讓步的話使用者剛清掉的值會被網址撿回來又寫回兩個媒介
475
+ const hasExplicitAc = !!event.data && Object.prototype.hasOwnProperty.call(event.data, 'ac')
476
+ const acRead = readParamFromLocation(AC_KEYS)
477
+ const affiliateCode = hasExplicitAc ? normalize(event.data.ac) : acRead.value
478
+ // 宿主可能傳進字面 'undefined',先 normalize 才不會蓋掉網址/儲存層的真值
479
+ const friendCode = normalize(fc) || readParamFromLocation(FC_KEYS).value
480
+
481
+ // 本段結尾以 window.location.href 離站,離站後 SPA 記憶體全丟;導頁前先落地雙寫
482
+ writeParam('ac', affiliateCode, { sentry })
483
+ writeParam('fc', friendCode, { sentry })
484
+
473
485
  const nickname = storage.get('nk')
474
486
  const phone = storage.get('tp_phone')
475
487
  const countryCode = storage.get('tp_countryCode')
@@ -478,35 +490,30 @@ export default function (request) {
478
490
  const messages = {
479
491
  url: window.location.href,
480
492
  affiliateCode,
493
+ acSource: hasExplicitAc ? 'event' : acRead.from,
481
494
  nickname,
482
495
  }
483
496
 
484
497
  sentry?.captureMessage(`[Auth] RedirectTo3Party Data: ${JSON.stringify(messages)}`, { level: 'info' })
485
498
 
486
- const referralObj = {}
487
- if (![undefined, 'undefined', null, 'null'].includes(affiliateCode)) {
488
- referralObj.ac = affiliateCode
489
- }
490
-
491
- if (![undefined, 'undefined', null, 'null'].includes(nickname)) {
492
- referralObj.nick_name = nickname
493
- }
494
-
495
- if (![undefined, 'undefined', null, 'null'].includes(phone)) {
496
- referralObj.phone = phone
497
- }
498
-
499
- if (![undefined, 'undefined', null, 'null'].includes(countryCode)) {
500
- referralObj.countryCode = countryCode
501
- }
502
-
503
- if (![undefined, 'undefined', null, 'null'].includes(email)) {
504
- referralObj.email = email
505
- }
506
-
507
- if (![undefined, 'undefined', null, 'null'].includes(birthday)) {
508
- referralObj.birthday = birthday
509
- }
499
+ // 空值一律不進 query。dt 與 fc 原本裸展開進 URLSearchParams,兩者為 undefined 時會被
500
+ // 序列化成字面字串 dt=undefined / fc=undefined,後端收到的是 "undefined" 而非缺省
501
+ const query = pickBy(
502
+ {
503
+ provider,
504
+ redirectURI: `${window.location.protocol}//${window.location.host}${context.base}`,
505
+ ac: affiliateCode,
506
+ nick_name: nickname,
507
+ phone,
508
+ countryCode,
509
+ email,
510
+ birthday,
511
+ dt,
512
+ platform: 'pwa',
513
+ fc: friendCode,
514
+ },
515
+ (value) => normalize(value) !== null
516
+ )
510
517
 
511
518
  storage.remove('tp_phone')
512
519
  storage.remove('tp_countryCode')
@@ -515,18 +522,7 @@ export default function (request) {
515
522
 
516
523
  const fullURL = request.config.fullURL
517
524
 
518
- const redirectURL = urljoin(
519
- fullURL,
520
- 'login?' +
521
- new URLSearchParams({
522
- provider,
523
- redirectURI: `${window.location.protocol}//${window.location.host}${context.base}`,
524
- ...referralObj,
525
- dt,
526
- platform: 'pwa',
527
- fc,
528
- }).toString()
529
- )
525
+ const redirectURL = urljoin(fullURL, 'login?' + new URLSearchParams(query).toString())
530
526
 
531
527
  window.location.href = redirectURL
532
528
  },
@@ -3,9 +3,10 @@ import { assign, createMachine } from 'xstate'
3
3
  import pickBy from 'lodash/pickBy.js'
4
4
  import api from '../api/common.js'
5
5
  import storage from '../util/storage.js'
6
+ import { readParam, writeParam, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
6
7
 
7
8
  export default function (request) {
8
- const { appSecret } = request.config
9
+ const { appSecret, sentry } = request.config
9
10
  return createMachine(
10
11
  {
11
12
  id: 'common',
@@ -276,28 +277,17 @@ export default function (request) {
276
277
  kpix,
277
278
  }
278
279
  }),
279
- setAgent: assign((context, event) => {
280
- if (window.CC_JSB === true) {
281
- // is cocos native app
282
- return
283
- } else {
284
- let urlParams = new URLSearchParams(window.location.search)
285
- const affiliateCode = urlParams.get('ac') || urlParams.get('referralCode') || storage.get('ac') || storage.get('referralCode')
286
- const friendCode = urlParams.get('fc') || urlParams.get('affiliate') || storage.get('fc') || storage.get('affiliate')
280
+ setAgent: assign(() => {
281
+ const urlParams = new URLSearchParams(window.location.search)
282
+ const ac = readParam(urlParams, AC_KEYS)
283
+ const fc = readParam(urlParams, FC_KEYS)
287
284
 
288
- storage.set('ac', affiliateCode, {
289
- path: '/',
290
- maxAge: 60 * 60 * 24 * 7,
291
- })
292
- storage.set('fc', friendCode, {
293
- path: '/',
294
- maxAge: 60 * 60 * 24 * 7,
295
- })
285
+ writeParam('ac', ac.value, { sentry })
286
+ writeParam('fc', fc.value, { sentry })
296
287
 
297
- return {
298
- affiliateCode,
299
- friendCode,
300
- }
288
+ return {
289
+ affiliateCode: ac.value,
290
+ friendCode: fc.value,
301
291
  }
302
292
  }),
303
293
  clearAnnouncements: assign((context, event) => {
@@ -1,5 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
+ import { isAmountInRange } from '../../util/amount.js'
3
4
 
4
5
  export default function (request, context) {
5
6
  const { paymentDetail = [], promotion, selectedAmount } = context || {}
@@ -177,13 +178,7 @@ export default function (request, context) {
177
178
  isPromotionChanged: (context, event) => {
178
179
  return event.data?.promotionsNo !== context.promotion?.promotionsNo
179
180
  },
180
- isCalculable: (context, event) => {
181
- const {
182
- selectedAmount,
183
- selectedDirect: { maximum, minimum },
184
- } = context
185
- return selectedAmount && minimum <= +selectedAmount && +selectedAmount <= maximum
186
- },
181
+ isCalculable: ({ selectedDirect, selectedAmount }) => isAmountInRange(selectedAmount, selectedDirect),
187
182
  isSubmittable: (context, event) => {
188
183
  const { selectedAmount, selectedDirect, selectedUserBank } = context
189
184
  return selectedAmount && selectedDirect && selectedUserBank
@@ -1,5 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
+ import { isAmountInRange } from '../../util/amount.js'
3
4
 
4
5
  export default function (request, context) {
5
6
  const { paymentDetail = [], promotion, selectedAmount } = context || {}
@@ -33,22 +34,7 @@ export default function (request, context) {
33
34
  debouncing: {
34
35
  entry: 'clearCalculation',
35
36
  after: {
36
- 1000: [
37
- {
38
- target: 'calculating',
39
- cond: (context, event) => {
40
- const { selectedLoadcard, selectedAmount } = context
41
- if (selectedLoadcard && selectedAmount) {
42
- return selectedLoadcard.minimum <= selectedAmount && selectedAmount <= selectedLoadcard.maximum
43
- } else {
44
- return false
45
- }
46
- },
47
- },
48
- {
49
- target: 'loaded',
50
- },
51
- ],
37
+ 1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'loaded' }],
52
38
  },
53
39
  },
54
40
  calculating: {
@@ -123,14 +109,11 @@ export default function (request, context) {
123
109
  }
124
110
  }),
125
111
  setPromotion: assign((context, event) => {
126
- const promotion = event.data
127
- const loadcards = context.loadcards
128
- const selectedLoadcard = loadcards[0]
112
+ // 通道清單不隨活動改變(loadcards 由 setInitData 從 paymentDetail 產生),
113
+ // 因此切換活動只清計算結果、保留使用者已選的通道;重設成 loadcards[0] 會讓
114
+ // 使用者選的通道被打回第一個,且重算的是錯誤通道的獎金
129
115
  return {
130
- promotion,
131
- loadcards,
132
- selectedLoadcard,
133
- options: selectedLoadcard?.optional,
116
+ promotion: event.data,
134
117
  calculation: null,
135
118
  }
136
119
  }),
@@ -183,6 +166,7 @@ export default function (request, context) {
183
166
  isPromotionChanged: (context, event) => {
184
167
  return event.data?.promotionsNo !== context.promotion?.promotionsNo
185
168
  },
169
+ isCalculable: ({ selectedLoadcard, selectedAmount }) => isAmountInRange(selectedAmount, selectedLoadcard),
186
170
  },
187
171
  services: {
188
172
  fetchCalculation: async (context, event) => {
@@ -1,5 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
+ import { isAmountInRange } from '../../util/amount.js'
3
4
 
4
5
  export default function (request, context) {
5
6
  const { paymentDetail = [], promotion, selectedAmount } = context || {}
@@ -45,22 +46,7 @@ export default function (request, context) {
45
46
  debouncing: {
46
47
  entry: 'clearCalculation',
47
48
  after: {
48
- 1000: [
49
- {
50
- target: 'calculating',
51
- cond: (context, event) => {
52
- const { selectedQrcode, selectedAmount } = context
53
- if (selectedQrcode && selectedAmount) {
54
- return selectedQrcode.minimum <= selectedAmount && selectedAmount <= selectedQrcode.maximum
55
- } else {
56
- return false
57
- }
58
- },
59
- },
60
- {
61
- target: 'loaded',
62
- },
63
- ],
49
+ 1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'loaded' }],
64
50
  },
65
51
  },
66
52
  calculating: {
@@ -79,6 +65,7 @@ export default function (request, context) {
79
65
  on: {
80
66
  SUBMIT: {
81
67
  target: 'submitting',
68
+ cond: 'isSubmittable',
82
69
  },
83
70
  },
84
71
  },
@@ -134,14 +121,11 @@ export default function (request, context) {
134
121
  }
135
122
  }),
136
123
  setPromotion: assign((context, event) => {
137
- const promotion = event.data
138
- const qrcodes = context.qrcodes
139
- const selectedQrcode = qrcodes[0]
124
+ // 通道清單不隨活動改變(qrcodes 由 setInitData 從 paymentDetail 產生),
125
+ // 因此切換活動只清計算結果、保留使用者已選的通道;重設成 qrcodes[0] 會讓
126
+ // 使用者選的通道被打回第一個,且重算的是錯誤通道的獎金
140
127
  return {
141
- promotion,
142
- qrcodes,
143
- selectedQrcode,
144
- options: selectedQrcode?.optional,
128
+ promotion: event.data,
145
129
  calculation: null,
146
130
  }
147
131
  }),
@@ -195,6 +179,8 @@ export default function (request, context) {
195
179
  hasQrcodeMethods: (context, event) => {
196
180
  return context.paymentDetail?.filter((element) => element.category === context.currentCategory).length > 0
197
181
  },
182
+ isCalculable: ({ selectedQrcode, selectedAmount }) => isAmountInRange(selectedAmount, selectedQrcode),
183
+ isSubmittable: ({ selectedQrcode, selectedAmount }) => isAmountInRange(selectedAmount, selectedQrcode),
198
184
  },
199
185
  services: {
200
186
  fetchCalculation: async (context, event) => {
@@ -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 = [
@@ -83,7 +84,8 @@ export default function (request) {
83
84
  }),
84
85
  setFriendCode: assign((context, event) => {
85
86
  const { fc } = event.data
86
- return { fc }
87
+ // api/auth.js 的 register 只濾 undefined/null,字面 'undefined' 會直送 query string
88
+ return { fc: normalize(fc) }
87
89
  }),
88
90
  setSignUpId: assign((context, event) => {
89
91
  const {
@@ -188,10 +190,19 @@ export default function (request) {
188
190
  const { signUpData, deviceTokenEnable } = context
189
191
  const dt = deviceTokenEnable ? await request.config.getDt?.() : undefined
190
192
 
191
- const affiliateCode = storage.get('ac') || signUpData?.affiliateCode
193
+ // 宿主明確帶入的 affiliateCode(註冊表單的代理碼欄位)優先於網址/儲存這類環境值。
194
+ // 判定用 `!== undefined` 而非 hasOwnProperty:上面的 setSignUpId/Phone/Email 是以解構寫入
195
+ // signUpData,宿主沒帶時 key 仍然存在(值為 undefined),hasOwnProperty 會恆為 true、
196
+ // 讓三層解析變成死碼。也不能用 `||`,否則使用者刻意清空送出的空字串會被吃掉、
197
+ // 退回三層解析把剛清掉的舊代理碼從網址撿回來。
198
+ const { affiliateCode: explicitAffiliateCode, ...signUpRest } = signUpData || {}
199
+ const hasExplicitAc = explicitAffiliateCode !== undefined
200
+ const acRead = readParamFromLocation(AC_KEYS)
201
+ const affiliateCode = hasExplicitAc ? normalize(explicitAffiliateCode) : acRead.value
192
202
  const messages = {
193
203
  url: window.location.href,
194
204
  affiliateCode,
205
+ acSource: hasExplicitAc ? 'signUpData' : acRead.from,
195
206
  }
196
207
 
197
208
  // 因 client-pwa-cash PR #805 的問題,暫時註解此 Sentry 上報
@@ -205,11 +216,11 @@ export default function (request) {
205
216
 
206
217
  return await request.send(
207
218
  auth.register({
208
- ...signUpData,
219
+ ...signUpRest,
209
220
  ...referralObj,
210
221
  dt,
211
222
  reCaptchaToken: context.reCaptchaToken,
212
- fc: context.fc,
223
+ fc: context.fc || readParamFromLocation(FC_KEYS).value,
213
224
  })
214
225
  )
215
226
  },
@@ -0,0 +1,8 @@
1
+ export function isAmountInRange(raw, payment) {
2
+ if (!payment) return false
3
+ const amount = Number(raw)
4
+ if (!Number.isFinite(amount) || amount <= 0) return false
5
+ const minimum = payment.minimum ?? 0
6
+ const maximum = payment.maximum ?? Infinity
7
+ return amount >= minimum && amount <= maximum
8
+ }
package/src/util/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import storage from './storage.js'
2
+ import paramStore from './paramStore.js'
2
3
  import * as constant from './constant.js'
3
4
  import { max } from './math.js'
5
+ import { isAmountInRange } from './amount.js'
4
6
 
5
7
  export default {}
6
- export { constant, storage, max }
8
+ export { constant, storage, paramStore, max, isAmountInRange }
@@ -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 }
@@ -1,142 +0,0 @@
1
- # Create Branch
2
-
3
- 從目前 HEAD 建立新分支(feat / fix / hotfix),**建立後切換到該分支**。
4
-
5
- - 分支命名:
6
- - `feat` → `feat/well/{子名稱}`
7
- - `fix` → `fix/well/{子名稱}`
8
- - `hotfix` → `hotfix/{版號}`(例如 `hotfix/1.1.562`)
9
-
10
- 請依序執行每個步驟,每步執行前先告知使用者當前進度。
11
-
12
- ---
13
-
14
- ## Step 1 — 檢查工作區是否乾淨(忽略 submodule)
15
-
16
- 若有未提交的變更(staged、unstaged、untracked),立即終止並提醒使用者先處理(commit 或 stash)。**忽略 submodule 變更。**
17
-
18
- ```bash
19
- git status --porcelain --ignore-submodules=all
20
- ```
21
-
22
- 若輸出非空,停止後續步驟並回報:
23
-
24
- - 工作區目前有未提交的變更,為避免遺失,已中止操作
25
- - 列出 `git status --short --ignore-submodules=all` 的結果
26
- - 建議使用者先 `git commit` 或 `git stash` 後再重新執行
27
-
28
- ---
29
-
30
- ## Step 2 — 詢問 branch 類型
31
-
32
- 使用 `AskUserQuestion` 工具,讓使用者選擇 branch 類型:
33
-
34
- - 問題:`請選擇要建立的 branch 類型?`
35
- - header:`Branch 類型`
36
- - 選項:
37
- - `feat` — 新功能開發
38
- - `fix` — Bug 修正
39
- - `hotfix` — 緊急修復
40
-
41
- 將使用者選擇的答案儲存為 `<BRANCH_TYPE>`。
42
-
43
- ---
44
-
45
- ## Step 3 — 決定最終 branch 名稱
46
-
47
- 依 `<BRANCH_TYPE>` 分支處理:
48
-
49
- ### 若 `<BRANCH_TYPE>` 為 `hotfix`
50
-
51
- 使用 `AskUserQuestion` 工具,請使用者透過「Other」選項輸入版號:
52
-
53
- - 問題:`請輸入 hotfix 版號(例如:1.1.562)?`
54
- - header:`Hotfix 版號`
55
- - 選項:
56
- - 提供 1~2 個範例選項讓使用者參考(例如 `1.0.0`、`1.1.562`)
57
- - 明確提示使用者應該選「Other」自行輸入
58
-
59
- 將使用者輸入的值儲存為 `<HOTFIX_VERSION>`。
60
-
61
- **驗證規則**:
62
-
63
- - 不可為空
64
- - 必須符合 `^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$` 格式(不含 `v` 前綴)
65
- - 若不符合規則,請使用者重新輸入
66
-
67
- 組合:
68
-
69
- ```
70
- <FINAL_BRANCH_NAME> = hotfix/<HOTFIX_VERSION>
71
- ```
72
-
73
- 例如 `hotfix/1.1.562`。跳到 Step 4。
74
-
75
- ### 若 `<BRANCH_TYPE>` 為 `feat` 或 `fix`
76
-
77
- 使用 `AskUserQuestion` 工具,請使用者透過「Other」選項自行輸入 branch 子名稱:
78
-
79
- - 問題:`請輸入 branch 子名稱(例如:login-fix、header-refactor)?`
80
- - header:`子名稱`
81
- - 選項:
82
- - 提供 2 個範例選項讓使用者參考(例如 `example-feature`、`example-bug`)
83
- - 明確提示使用者應該選「Other」自行輸入
84
-
85
- 將使用者輸入的值儲存為 `<BRANCH_SUBNAME>`。
86
-
87
- **驗證規則**:
88
-
89
- - 不可為空
90
- - 只允許英文字母、數字、連字號(`-`)、底線(`_`)、斜線(`/`)
91
- - 若不符合規則,請使用者重新輸入
92
-
93
- 組合:
94
-
95
- ```
96
- <FINAL_BRANCH_NAME> = <BRANCH_TYPE>/well/<BRANCH_SUBNAME>
97
- ```
98
-
99
- 範例:
100
-
101
- - `feat/well/login-page`
102
- - `fix/well/header-layout`
103
-
104
- ---
105
-
106
- ## Step 4 — 檢查 branch 是否已存在
107
-
108
- 檢查 `<FINAL_BRANCH_NAME>` 是否已存在(本地或遠端):
109
-
110
- ```bash
111
- git rev-parse --verify <FINAL_BRANCH_NAME> 2>/dev/null
112
- git ls-remote --exit-code --heads origin <FINAL_BRANCH_NAME> 2>/dev/null
113
- ```
114
-
115
- 若已存在,停止並告知使用者:
116
-
117
- - hotfix 場景:該版號的 hotfix 分支已存在,建議改用其他版號或先處理舊分支再重試
118
- - feat / fix 場景:建議改用其他子名稱
119
-
120
- ---
121
-
122
- ## Step 5 — 建立新 branch 並切換
123
-
124
- 從目前 HEAD 建立新分支,**並切換到該分支**:
125
-
126
- ```bash
127
- git checkout -b <FINAL_BRANCH_NAME>
128
- ```
129
-
130
- 若失敗則停止並回報原因。
131
-
132
- ---
133
-
134
- ## Step 6 — 回報結果
135
-
136
- 顯示完成摘要:
137
-
138
- - 新 branch 名稱:`<FINAL_BRANCH_NAME>`
139
- - 基於的 commit SHA(短版,`git log -1 --pretty=format:'%h'`)與訊息首行(`git log -1 --pretty=format:'%s'`)
140
- - 已切換到新分支
141
- - 提示使用者:
142
- - 若要推送到遠端,可執行 `git push -u origin <FINAL_BRANCH_NAME>`