@jetthai/cuora 1.1.480 → 1.1.481-api.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/AGENTS.md +1 -1
- package/AI_PROMPT_SOURCE.md +1 -1
- package/CHANGELOG.md +11 -0
- package/CLAUDE.md +1 -1
- package/GEMINI.md +1 -1
- package/package.json +1 -1
- package/src/machine/auth.js +38 -1
- package/src/request/request.js +76 -2
package/AGENTS.md
CHANGED
|
@@ -191,7 +191,7 @@ Token 5min TTL → fetchUserInfo success → extendToken resets TTL → poll aga
|
|
|
191
191
|
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
192
192
|
| `LOGIN_3PARTY` | Third-party redirect | **Does not switch state**; uses `window.location.href` directly |
|
|
193
193
|
|
|
194
|
-
**OTP flow**: after a successful login it enters `otpChecking`, and only proceeds to `loginSuccess`
|
|
194
|
+
**OTP / bind-bank flow**: after a successful login it enters `otpChecking`; `OTP_VERIFIED` or `OTP_SKIP` moves it to `bindBankChecking`, and only `BIND_BANK_DONE` or `BIND_BANK_SKIP` proceeds to `loginSuccess` (either gate accepts `LOGOUT` to abort). Whether binding is required is decided by the downstream frontend; the machine only waits — **downstream must send one of these events in `bindBankChecking`, or the session stalls there**. The `tokenAuthenticated` path skips both gates.
|
|
195
195
|
|
|
196
196
|
**Account persistence**: the most recently used login account is stored in localStorage (31-day TTL) for form auto-fill. **Token expiration does not affect the account record.** However, `pruneRememberedAccounts`, which runs after `fetchSiteConfig` succeeds, **compares against `siteConfig.loginMethods` and clears the leftover account for any disabled login method** (`phone` clears the country code along with it) — fetching configuration, an apparently read-only action, carries the side effect of deleting from localStorage. The purpose is to prevent downstream frontends from back-filling a stale value into an input whose type has since changed after the backend disables a login method. When `loginMethods` is missing entirely, nothing is cleared, to avoid wiping everything by mistake.
|
|
197
197
|
|
package/AI_PROMPT_SOURCE.md
CHANGED
|
@@ -189,7 +189,7 @@ Token 5min TTL → fetchUserInfo 成功 → extendToken 重設 TTL → 再次輪
|
|
|
189
189
|
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
190
190
|
| `LOGIN_3PARTY` | 第三方跳轉 | **不切換狀態**,直接 `window.location.href` |
|
|
191
191
|
|
|
192
|
-
**OTP
|
|
192
|
+
**OTP/綁銀行流程**:登入成功後進入 `otpChecking`,等待 `OTP_VERIFIED` 或 `OTP_SKIP` 後進入 `bindBankChecking`,再等待 `BIND_BANK_DONE` 或 `BIND_BANK_SKIP` 才進入 `loginSuccess`(兩關都可送 `LOGOUT` 中止)。是否需要綁定由下游前端判斷,machine 只負責等待;**下游必須在 `bindBankChecking` 送出其中一個事件,否則會停在這一關**。`tokenAuthenticated` 路徑不經過這兩關。
|
|
193
193
|
|
|
194
194
|
**帳號持久化**:最後使用的登入帳號存 localStorage(31 天 TTL)供表單自動填入。**Token 過期不影響帳號記錄。**但 `fetchSiteConfig` 成功後的 `pruneRememberedAccounts` 會**比對 `siteConfig.loginMethods` 清掉已停用登入方式的殘留帳號**(`phone` 連同國碼一起刪)——拉設定這個看似唯讀的動作帶有刪 localStorage 的副作用,目的是避免後台關掉某種登入方式後,下游把舊值回填進已改型別的輸入框。`loginMethods` 整包缺失時不清除,以免誤刪全部。
|
|
195
195
|
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
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.481](https://github.com/jetthai/cuora-module/compare/v1.1.480...v1.1.481) (2026-10-20)
|
|
6
|
+
|
|
7
|
+
### ⚠ BREAKING CHANGES
|
|
8
|
+
|
|
9
|
+
- 下游在 OTP 關卡送出 OTP_VERIFIED / OTP_SKIP 後,必須在 bindBankChecking 送出
|
|
10
|
+
BIND_BANK_DONE 或 BIND_BANK_SKIP,否則會停在此關卡。目前僅 client-pwa-cash 使用本套件。
|
|
11
|
+
|
|
12
|
+
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
13
|
+
|
|
14
|
+
- [JT-1784011020] feat(auth): 新增 bindBankChecking 關卡,綁銀行完成前不進入 loginSuccess ([c9b5210](https://github.com/jetthai/cuora-module/commit/c9b5210b8f1abb9adca7c79207e89d66191daf8f))
|
|
15
|
+
|
|
5
16
|
### [1.1.480](https://github.com/jetthai/cuora-module/compare/v1.1.479...v1.1.480) (2026-10-19)
|
|
6
17
|
|
|
7
18
|
### ⚠ BREAKING CHANGES
|
package/CLAUDE.md
CHANGED
|
@@ -191,7 +191,7 @@ Token 5min TTL → fetchUserInfo success → extendToken resets TTL → poll aga
|
|
|
191
191
|
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
192
192
|
| `LOGIN_3PARTY` | Third-party redirect | **Does not switch state**; uses `window.location.href` directly |
|
|
193
193
|
|
|
194
|
-
**OTP flow**: after a successful login it enters `otpChecking`, and only proceeds to `loginSuccess`
|
|
194
|
+
**OTP / bind-bank flow**: after a successful login it enters `otpChecking`; `OTP_VERIFIED` or `OTP_SKIP` moves it to `bindBankChecking`, and only `BIND_BANK_DONE` or `BIND_BANK_SKIP` proceeds to `loginSuccess` (either gate accepts `LOGOUT` to abort). Whether binding is required is decided by the downstream frontend; the machine only waits — **downstream must send one of these events in `bindBankChecking`, or the session stalls there**. The `tokenAuthenticated` path skips both gates.
|
|
195
195
|
|
|
196
196
|
**Account persistence**: the most recently used login account is stored in localStorage (31-day TTL) for form auto-fill. **Token expiration does not affect the account record.** However, `pruneRememberedAccounts`, which runs after `fetchSiteConfig` succeeds, **compares against `siteConfig.loginMethods` and clears the leftover account for any disabled login method** (`phone` clears the country code along with it) — fetching configuration, an apparently read-only action, carries the side effect of deleting from localStorage. The purpose is to prevent downstream frontends from back-filling a stale value into an input whose type has since changed after the backend disables a login method. When `loginMethods` is missing entirely, nothing is cleared, to avoid wiping everything by mistake.
|
|
197
197
|
|
package/GEMINI.md
CHANGED
|
@@ -191,7 +191,7 @@ Token 5min TTL → fetchUserInfo success → extendToken resets TTL → poll aga
|
|
|
191
191
|
| `LOGIN_TELEGRAM` | Telegram | additionalUserInfo |
|
|
192
192
|
| `LOGIN_3PARTY` | Third-party redirect | **Does not switch state**; uses `window.location.href` directly |
|
|
193
193
|
|
|
194
|
-
**OTP flow**: after a successful login it enters `otpChecking`, and only proceeds to `loginSuccess`
|
|
194
|
+
**OTP / bind-bank flow**: after a successful login it enters `otpChecking`; `OTP_VERIFIED` or `OTP_SKIP` moves it to `bindBankChecking`, and only `BIND_BANK_DONE` or `BIND_BANK_SKIP` proceeds to `loginSuccess` (either gate accepts `LOGOUT` to abort). Whether binding is required is decided by the downstream frontend; the machine only waits — **downstream must send one of these events in `bindBankChecking`, or the session stalls there**. The `tokenAuthenticated` path skips both gates.
|
|
195
195
|
|
|
196
196
|
**Account persistence**: the most recently used login account is stored in localStorage (31-day TTL) for form auto-fill. **Token expiration does not affect the account record.** However, `pruneRememberedAccounts`, which runs after `fetchSiteConfig` succeeds, **compares against `siteConfig.loginMethods` and clears the leftover account for any disabled login method** (`phone` clears the country code along with it) — fetching configuration, an apparently read-only action, carries the side effect of deleting from localStorage. The purpose is to prevent downstream frontends from back-filling a stale value into an input whose type has since changed after the backend disables a login method. When `loginMethods` is missing entirely, nothing is cleared, to avoid wiping everything by mistake.
|
|
197
197
|
|
package/package.json
CHANGED
package/src/machine/auth.js
CHANGED
|
@@ -115,9 +115,46 @@ export default function (request) {
|
|
|
115
115
|
},
|
|
116
116
|
on: {
|
|
117
117
|
OTP_VERIFIED: {
|
|
118
|
-
target: '
|
|
118
|
+
target: 'bindBankChecking',
|
|
119
119
|
},
|
|
120
120
|
OTP_SKIP: {
|
|
121
|
+
target: 'bindBankChecking',
|
|
122
|
+
},
|
|
123
|
+
LOGOUT: {
|
|
124
|
+
target: 'leaving',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
// 綁銀行與 OTP 同為登入完成前的關卡:放在 loginSuccess 之前,登入後的副作用(公告、活動彈窗等)
|
|
129
|
+
// 才不會在綁定窗開著時觸發。是否需要綁定由前端依 siteConfig 判斷,machine 只負責等待結果。
|
|
130
|
+
bindBankChecking: {
|
|
131
|
+
initial: 'pending',
|
|
132
|
+
states: {
|
|
133
|
+
pending: {
|
|
134
|
+
after: {
|
|
135
|
+
TIMEOUT: {
|
|
136
|
+
target: 'fetching',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
fetching: {
|
|
141
|
+
invoke: {
|
|
142
|
+
src: 'fetchUserInfo',
|
|
143
|
+
onDone: {
|
|
144
|
+
target: 'pending',
|
|
145
|
+
actions: ['setUserInfo', 'extendToken'],
|
|
146
|
+
},
|
|
147
|
+
onError: {
|
|
148
|
+
target: 'pending',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
on: {
|
|
154
|
+
BIND_BANK_DONE: {
|
|
155
|
+
target: 'loginSuccess',
|
|
156
|
+
},
|
|
157
|
+
BIND_BANK_SKIP: {
|
|
121
158
|
target: 'loginSuccess',
|
|
122
159
|
},
|
|
123
160
|
LOGOUT: {
|
package/src/request/request.js
CHANGED
|
@@ -5,6 +5,8 @@ import { getErr998SentryExtra } from '../util/err998SentryExtra.js'
|
|
|
5
5
|
// 暫停 ERR_998 上報:在組裝 Sentry 資料之前就中止,不建立事件;仍照常 reject ERR_998 給呼叫端。恢復時改回 false 即可
|
|
6
6
|
const IS_ERR_998_REPORT_PAUSED = true
|
|
7
7
|
|
|
8
|
+
const CANCELLED_MESSAGE = 'Requests Cancelled'
|
|
9
|
+
|
|
8
10
|
// const pickBy = require('lodash/pickBy')
|
|
9
11
|
const supportVersion2List = [
|
|
10
12
|
// 04-09 Update
|
|
@@ -160,6 +162,9 @@ export default class Request {
|
|
|
160
162
|
this.errorHandler = null
|
|
161
163
|
this.hosts = []
|
|
162
164
|
this.isBlocked = false
|
|
165
|
+
this.activeRequests = new Set() // { source, token }:僅追蹤非 public 且帶 token 的在途請求,供 revokeToken 取消
|
|
166
|
+
this.revokedToken = null
|
|
167
|
+
this.tokenGate = null
|
|
163
168
|
this.clientIp = '' // 由外部 plugin(如 clientIp.client.js)非同步寫入,用於 ERR_998 Sentry 回報
|
|
164
169
|
this.hostTester = null // 由外部 plugin(如 host.client.js)寫入,需提供 lastResults 陣列供 ERR_998 Sentry 回報使用
|
|
165
170
|
this.initialize()
|
|
@@ -237,15 +242,75 @@ export default class Request {
|
|
|
237
242
|
this.errorHandler = handler
|
|
238
243
|
}
|
|
239
244
|
|
|
245
|
+
// 作廢指定 token:取消同 token 的在途請求,並讓之後仍帶此 token 的 send() 直接 reject。
|
|
246
|
+
// 只在 token 仍是目前身分時作用,舊身分遲到的錯誤不得影響新身分;重新登入後 token 改變即自然恢復
|
|
247
|
+
revokeToken(token) {
|
|
248
|
+
if (!token || token !== this.getToken()) return
|
|
249
|
+
this.revokedToken = token
|
|
250
|
+
this.activeRequests.forEach((item) => {
|
|
251
|
+
if (item.token === token) item.source.cancel(CANCELLED_MESSAGE)
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// 回前景時先確認 token 仍有效:promise 結算(成功或失敗)或逾時即放行,之後的 send() 才會送出
|
|
256
|
+
beginTokenGate(promise, timeoutMs = 3000) {
|
|
257
|
+
let timer
|
|
258
|
+
const timeout = new Promise((resolve) => {
|
|
259
|
+
timer = setTimeout(resolve, timeoutMs)
|
|
260
|
+
})
|
|
261
|
+
const gate = Promise.race([Promise.resolve(promise).catch(() => {}), timeout]).then(() => {
|
|
262
|
+
clearTimeout(timer)
|
|
263
|
+
if (this.tokenGate === gate) this.tokenGate = null
|
|
264
|
+
})
|
|
265
|
+
this.tokenGate = gate
|
|
266
|
+
return gate
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// 帶 ERR_800 讓下游既有的 `if (!error.code)` 判斷(如 Sentry 上報)把取消視為預期錯誤
|
|
270
|
+
_cancelledError() {
|
|
271
|
+
return Object.assign(new Error(CANCELLED_MESSAGE), { code: 'ERR_800' })
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
_throwIfRevoked() {
|
|
275
|
+
if (this.revokedToken && this.getToken() === this.revokedToken) {
|
|
276
|
+
throw this._cancelledError()
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
_isCancelled(error) {
|
|
281
|
+
return !!this.axios.isCancel?.(error) || error?.message === CANCELLED_MESSAGE
|
|
282
|
+
}
|
|
283
|
+
|
|
240
284
|
async send(req, customToken) {
|
|
285
|
+
let tracked = null
|
|
286
|
+
let requestToken = null
|
|
241
287
|
try {
|
|
242
288
|
// 非 public 請求缺 token 直接 reject:reject → onError → leaving → 乾淨登出,且不送網路 → 洪水照止
|
|
243
289
|
if (!req.isPublic && !this.getToken()) return Promise.reject({ code: 'ERR_A103' })
|
|
244
290
|
|
|
291
|
+
// 公開請求不帶 token,作廢期間 token 仍留在 storage 也不可誤拒(如 autoLogin 前後的 getConfig)
|
|
292
|
+
if (!req.isPublic) this._throwIfRevoked()
|
|
293
|
+
|
|
294
|
+
// /self 是 gate 自己的探測請求,不可等待 gate,否則死鎖
|
|
295
|
+
if (this.tokenGate && !req.isPublic && req.url.split('?')[0] !== 'self') {
|
|
296
|
+
await this.tokenGate
|
|
297
|
+
this._throwIfRevoked()
|
|
298
|
+
if (!this.getToken()) return Promise.reject({ code: 'ERR_A103' })
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
requestToken = req.isPublic ? null : this.getToken()
|
|
302
|
+
|
|
245
303
|
// axios <0.22 對 cancelToken.promise 註冊的取消 handler 永不退訂(xhr.js 無 unsubscribe),
|
|
246
304
|
// 預設掛長壽命共用 token 會使 handler 隨請求數線性累積(掛機過夜 OOM,TI-15555)。
|
|
247
|
-
//
|
|
248
|
-
|
|
305
|
+
// 故不掛共用 token:呼叫端傳入 customToken 時自行管理其生命週期;否則帶 token 的請求用一次性 source,
|
|
306
|
+
// 結束即移出 activeRequests 隨請求回收
|
|
307
|
+
let cancelToken = customToken
|
|
308
|
+
if (!customToken && requestToken && this.axios.CancelToken) {
|
|
309
|
+
const source = this.axios.CancelToken.source()
|
|
310
|
+
tracked = { source, token: requestToken }
|
|
311
|
+
this.activeRequests.add(tracked)
|
|
312
|
+
cancelToken = source.token
|
|
313
|
+
}
|
|
249
314
|
|
|
250
315
|
const requestConfig = this._createConfig(req, cancelToken)
|
|
251
316
|
const configUrls = ['getConfig', 'get-config']
|
|
@@ -256,11 +321,18 @@ export default class Request {
|
|
|
256
321
|
return data
|
|
257
322
|
}
|
|
258
323
|
} catch (error) {
|
|
324
|
+
if (this._isCancelled(error)) throw this._cancelledError()
|
|
325
|
+
if (requestToken && error && typeof error === 'object') {
|
|
326
|
+
error.requestToken = requestToken
|
|
327
|
+
}
|
|
259
328
|
if (error.code === 'ERR_F108') {
|
|
260
329
|
this.isBlocked = true
|
|
261
330
|
this.errorHandler && this.errorHandler(error)
|
|
262
331
|
throw error
|
|
263
332
|
}
|
|
333
|
+
// 舊身分遲到的錯誤不進 errorHandler;目前沒 token(TTL 過期或已 CLEAR)時維持原路由,A204 等彈窗才不會被吞
|
|
334
|
+
const currentToken = this.getToken()
|
|
335
|
+
if (requestToken && currentToken && currentToken !== requestToken) throw error
|
|
264
336
|
if (error.code === 'ERR_998') {
|
|
265
337
|
throw error
|
|
266
338
|
}
|
|
@@ -270,6 +342,8 @@ export default class Request {
|
|
|
270
342
|
}
|
|
271
343
|
throw error
|
|
272
344
|
}
|
|
345
|
+
} finally {
|
|
346
|
+
if (tracked) this.activeRequests.delete(tracked)
|
|
273
347
|
}
|
|
274
348
|
}
|
|
275
349
|
|