@jetthai/cuora 1.1.483-dev.4 → 1.1.485-dev.0
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/CHANGELOG.md +42 -2
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +14 -0
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +40 -0
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +41 -0
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +87 -0
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +73 -0
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +309 -0
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +245 -0
- package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +9 -0
- package/e2e/feature-map.md +61 -0
- package/package.json +1 -1
- package/prepare-for-pr/JT-1776243420.md +85 -0
- package/prepare-for-pr/TI-16026/STATE.md +17 -0
- package/prepare-for-pr/TI-16026/after-prepare-authorization.md +3 -0
- package/prepare-for-pr/TI-16026/analysis.md +38 -0
- package/prepare-for-pr/TI-16026/answer-analyze-01.md +1 -0
- package/prepare-for-pr/TI-16026/answer-commit-01.md +2 -0
- package/prepare-for-pr/TI-16026/answer-commit-02.md +1 -0
- package/prepare-for-pr/TI-16026/bundle.json +18 -0
- package/prepare-for-pr/TI-16026/checklist.md +39 -0
- package/prepare-for-pr/TI-16026/claude-after-model +1 -0
- package/prepare-for-pr/TI-16026/claude-commit-session +1 -0
- package/prepare-for-pr/TI-16026/claude-harvest-session +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/01-analyze.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/01-analyze.out +2 -0
- package/prepare-for-pr/TI-16026/claude-hops/02-analyze.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/02-analyze.out +4 -0
- package/prepare-for-pr/TI-16026/claude-hops/03-dev.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/03-dev.out +4 -0
- package/prepare-for-pr/TI-16026/claude-hops/04-dev.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/04-dev.out +4 -0
- package/prepare-for-pr/TI-16026/claude-hops/05-dev.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/05-dev.out +3 -0
- package/prepare-for-pr/TI-16026/claude-hops/06-after.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/06-after.out +2 -0
- package/prepare-for-pr/TI-16026/claude-hops/07-commit.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/07-commit.out +2 -0
- package/prepare-for-pr/TI-16026/claude-hops/08-commit.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/08-commit.out +2 -0
- package/prepare-for-pr/TI-16026/claude-hops/09-commit.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/09-commit.out +8 -0
- package/prepare-for-pr/TI-16026/claude-hops/10-harvest.err +1 -0
- package/prepare-for-pr/TI-16026/claude-hops/10-harvest.out +3 -0
- package/prepare-for-pr/TI-16026/commit-note.md +5 -0
- package/prepare-for-pr/TI-16026/feature-map.before.md +61 -0
- package/prepare-for-pr/TI-16026/harvest-redaction.out +1 -0
- package/prepare-for-pr/TI-16026/harvest.md +37 -0
- package/prepare-for-pr/TI-16026/lessons.md +5 -0
- package/prepare-for-pr/TI-16026/open-questions.md +6 -0
- package/prepare-for-pr/TI-16026/publish.md +28 -0
- package/prepare-for-pr/TI-16026/review-convergence-response.md +3 -0
- package/prepare-for-pr/TI-16026/review-input/scope.md +18 -0
- package/prepare-for-pr/TI-16026/review-log.md +57 -0
- package/prepare-for-pr/TI-16026/review-notes.md +97 -0
- package/prepare-for-pr/TI-16026/review-response-r1.md +7 -0
- package/prepare-for-pr/TI-16026/spec-proposal.md +34 -0
- package/prepare-for-pr/TI-16026/spec-snapshot.md +291 -0
- package/prepare-for-pr/TI-16026/state-log.md +35 -0
- package/prepare-for-pr/TI-16026/user-messages/01.md +12 -0
- package/prepare-for-pr/TI-16026/user-messages/02.md +20 -0
- package/prepare-for-pr/TI-16026/user-messages/03.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/04.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/05.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/06.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/07.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/08.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/09.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/10.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/11.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/12.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/13.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/14.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/15.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/16.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/17.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/18.md +10 -0
- package/prepare-for-pr/TI-16026/user-messages/19.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/20.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/21.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/22.md +1 -0
- package/prepare-for-pr/TI-16026/user-messages/23.md +8 -0
- package/prepare-for-pr/TI-16026/user-question.md +24 -0
- package/prepare-for-pr/TI-16026/verify-after.md +15 -0
- package/prepare-for-pr/TI-16026.md +408 -0
- package/src/machine/websocket.js +380 -311
- package/src/machine/withdraw/withdraw_manual_cash.js +7 -4
- package/src/util/socketPolicy.js +57 -0
- package/test/withdraw_manual_cash.test.js +149 -0
- package/tests/websocket.test.mjs +779 -0
|
@@ -36,9 +36,8 @@ export default function (request, context) {
|
|
|
36
36
|
target: 'checking',
|
|
37
37
|
actions: 'setInitData',
|
|
38
38
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
39
|
+
// submitted 的 REFRESH 失敗時無法確認訂單已結束,保留原 Pending 畫面讓下次 REFRESH 可重試
|
|
40
|
+
onError: [{ target: 'submitted', cond: 'isProcessing' }, { target: 'loaded' }],
|
|
42
41
|
},
|
|
43
42
|
},
|
|
44
43
|
checking: {
|
|
@@ -96,7 +95,11 @@ export default function (request, context) {
|
|
|
96
95
|
},
|
|
97
96
|
},
|
|
98
97
|
},
|
|
99
|
-
submitted: {
|
|
98
|
+
submitted: {
|
|
99
|
+
on: {
|
|
100
|
+
REFRESH: { target: 'loading', internal: false },
|
|
101
|
+
},
|
|
102
|
+
},
|
|
100
103
|
otp: {
|
|
101
104
|
type: 'parallel',
|
|
102
105
|
states: {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function decideNextStep({ event, reason, err, active, ready, rejection } = {}) {
|
|
2
|
+
if (event === 'kicked') return 'kicked'
|
|
3
|
+
if (event === 'disconnect' && reason === 'io client disconnect') return 'none'
|
|
4
|
+
if ((event === 'disconnect' && reason !== 'io server disconnect') || (event === 'connect_error' && active)) return 'socketio'
|
|
5
|
+
const info = rejection || err?.data
|
|
6
|
+
if (info) {
|
|
7
|
+
if (info.code === 'MAX_CONNECTIONS') return 'kicked'
|
|
8
|
+
if (info.code === 'SESSION_TOKEN_INVALID') return 'renew'
|
|
9
|
+
if (info.retryable === false) return 'stop'
|
|
10
|
+
if (info.retryable === true) return 'retry'
|
|
11
|
+
}
|
|
12
|
+
if (event === 'disconnect') return ready ? 'kicked' : 'retry'
|
|
13
|
+
if (err?.message === 'session rejected') return 'renew'
|
|
14
|
+
return 'retry'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function canResume(state, currentToken, source = 'user', now = Date.now()) {
|
|
18
|
+
if (!currentToken) return false
|
|
19
|
+
if (currentToken !== state.lastToken) return true
|
|
20
|
+
if (!state.blocked) return true
|
|
21
|
+
if (state.blocked === 'stop') return false
|
|
22
|
+
if (state.blocked === 'kicked') return source === 'user'
|
|
23
|
+
if (state.blocked === 'exhausted') return source === 'user' || (source === 'auto' && now - state.lastAttemptAt >= 15000)
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function nextRetryDelay(attempt, retryAfterMs) {
|
|
28
|
+
const count = Number.isFinite(attempt) ? Math.max(1, Math.floor(attempt)) : 1
|
|
29
|
+
const base = Math.min(30000, 1000 * 2 ** Math.min(count - 1, 30))
|
|
30
|
+
const floor = Number.isFinite(retryAfterMs) ? Math.max(0, retryAfterMs) : 0
|
|
31
|
+
return Math.max(floor, Math.round(base * (0.5 + Math.random())))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createPushDedupe({ max = 500, ttlMs = 600000 } = {}) {
|
|
35
|
+
const capacity = Number.isFinite(max) ? Math.max(1, Math.floor(max)) : 500
|
|
36
|
+
const ttl = Number.isFinite(ttlMs) ? Math.max(0, ttlMs) : 600000
|
|
37
|
+
const seen = new Map()
|
|
38
|
+
return (eventName, data, now = Date.now()) => {
|
|
39
|
+
for (const [key, timestamp] of seen) {
|
|
40
|
+
if (now - timestamp >= ttl) seen.delete(key)
|
|
41
|
+
}
|
|
42
|
+
const messageId = data?._meta?.messageId
|
|
43
|
+
const orderId = [data?.data?.applyId, data?.applyId, data?.data?.transactionId, data?.transactionId].find(
|
|
44
|
+
(id) => id !== undefined && id !== null && id !== ''
|
|
45
|
+
)
|
|
46
|
+
const businessEvent = [data?.event, data?.data?.event].find((event) => event !== undefined && event !== null && event !== '')
|
|
47
|
+
let key
|
|
48
|
+
if (messageId !== undefined && messageId !== null && messageId !== '') key = JSON.stringify(['message', messageId])
|
|
49
|
+
else if (eventName === 'payment-info' && businessEvent && orderId !== undefined && orderId !== null && orderId !== '')
|
|
50
|
+
key = JSON.stringify(['payment', eventName, businessEvent, String(orderId)])
|
|
51
|
+
if (!key) return false
|
|
52
|
+
if (seen.has(key)) return true
|
|
53
|
+
seen.set(key, now)
|
|
54
|
+
while (seen.size > capacity) seen.delete(seen.keys().next().value)
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { interpret } from 'xstate'
|
|
4
|
+
import withdrawManualCash from '../src/machine/withdraw/withdraw_manual_cash.js'
|
|
5
|
+
|
|
6
|
+
function waitForState(service, matches) {
|
|
7
|
+
if (service.state.matches(matches)) return Promise.resolve(service.state)
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const timeout = setTimeout(() => reject(new Error(`Timed out waiting for ${matches}`)), 1000)
|
|
10
|
+
service.onTransition((state) => {
|
|
11
|
+
if (!state.matches(matches)) return
|
|
12
|
+
clearTimeout(timeout)
|
|
13
|
+
resolve(state)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const context = {
|
|
19
|
+
doubleWalletWithdrawLimitCheck: '0',
|
|
20
|
+
paymentDetail: [{ category: 'manual', transferType: 'withdraw', method: 'MANUAL', minimum: 100, maximum: 10000 }],
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const boundBank = { bankCode: 'BANK', accountNumber: '0001', holderName: 'holder' }
|
|
24
|
+
|
|
25
|
+
// pendingOrders[i] 為第 i+1 次 pendingOrder 的回應;Error 代表該次 reject
|
|
26
|
+
function stubRequest(pendingOrders) {
|
|
27
|
+
const calls = { pendingOrder: 0 }
|
|
28
|
+
return {
|
|
29
|
+
calls,
|
|
30
|
+
async send(descriptor) {
|
|
31
|
+
if (descriptor.url === 'payment/v2/getBindingPaymentInfo') return { bankList: [boundBank], ewalletList: [], cryptoList: [] }
|
|
32
|
+
if (descriptor.url === 'payment/v2/withdrawRule') return { enableWithdraw: true }
|
|
33
|
+
if (descriptor.url === 'payment/v2/pendingOrder') {
|
|
34
|
+
const response = pendingOrders[calls.pendingOrder++] ?? []
|
|
35
|
+
if (response instanceof Error) throw response
|
|
36
|
+
return response
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function waitForPendingOrderCalls(request, count) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const started = Date.now()
|
|
46
|
+
const poll = () => {
|
|
47
|
+
if (request.calls.pendingOrder >= count) return resolve()
|
|
48
|
+
if (Date.now() - started > 1000) return reject(new Error(`Timed out waiting for ${count} pendingOrder calls`))
|
|
49
|
+
setTimeout(poll, 5)
|
|
50
|
+
}
|
|
51
|
+
poll()
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const firstOrder = { applyId: 'W-1', amount: 500 }
|
|
56
|
+
const secondOrder = { applyId: 'W-2', amount: 800 }
|
|
57
|
+
|
|
58
|
+
test('REFRESH in submitted re-runs loading and fetches the pending order again', async () => {
|
|
59
|
+
const request = stubRequest([[firstOrder], []])
|
|
60
|
+
const service = interpret(withdrawManualCash(request, context)).start()
|
|
61
|
+
try {
|
|
62
|
+
await waitForState(service, 'submitted')
|
|
63
|
+
assert.equal(request.calls.pendingOrder, 1)
|
|
64
|
+
service.send({ type: 'REFRESH' })
|
|
65
|
+
assert.equal(service.state.matches('loading'), true)
|
|
66
|
+
await waitForPendingOrderCalls(request, 2)
|
|
67
|
+
} finally {
|
|
68
|
+
service.stop()
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('REFRESH in submitted returns to the form when no order is pending', async () => {
|
|
73
|
+
const request = stubRequest([[firstOrder], []])
|
|
74
|
+
const service = interpret(withdrawManualCash(request, context)).start()
|
|
75
|
+
try {
|
|
76
|
+
await waitForState(service, 'submitted')
|
|
77
|
+
service.send({ type: 'REFRESH' })
|
|
78
|
+
const state = await waitForState(service, 'loaded')
|
|
79
|
+
assert.equal(request.calls.pendingOrder, 2)
|
|
80
|
+
assert.equal(state.context.processing, undefined)
|
|
81
|
+
} finally {
|
|
82
|
+
service.stop()
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('REFRESH in submitted keeps submitted with the updated order when one is still pending', async () => {
|
|
87
|
+
const request = stubRequest([[firstOrder], [secondOrder]])
|
|
88
|
+
const service = interpret(withdrawManualCash(request, context)).start()
|
|
89
|
+
try {
|
|
90
|
+
await waitForState(service, 'submitted')
|
|
91
|
+
assert.equal(service.state.context.processing.applyId, 'W-1')
|
|
92
|
+
service.send({ type: 'REFRESH' })
|
|
93
|
+
await waitForPendingOrderCalls(request, 2)
|
|
94
|
+
const state = await waitForState(service, 'submitted')
|
|
95
|
+
assert.equal(request.calls.pendingOrder, 2)
|
|
96
|
+
assert.deepEqual(state.context.processing, secondOrder)
|
|
97
|
+
} finally {
|
|
98
|
+
service.stop()
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
function networkError() {
|
|
103
|
+
return Object.assign(new Error('Network Error'), { code: 'ERR_998' })
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
test('a failed refresh in submitted keeps the pending order and a later REFRESH retries', async () => {
|
|
107
|
+
const request = stubRequest([[firstOrder], networkError(), []])
|
|
108
|
+
const service = interpret(withdrawManualCash(request, context)).start()
|
|
109
|
+
try {
|
|
110
|
+
await waitForState(service, 'submitted')
|
|
111
|
+
service.send({ type: 'REFRESH' })
|
|
112
|
+
await waitForPendingOrderCalls(request, 2)
|
|
113
|
+
const state = await waitForState(service, 'submitted')
|
|
114
|
+
assert.deepEqual(state.context.processing, firstOrder)
|
|
115
|
+
service.send({ type: 'REFRESH' })
|
|
116
|
+
await waitForState(service, 'loaded')
|
|
117
|
+
assert.equal(request.calls.pendingOrder, 3)
|
|
118
|
+
} finally {
|
|
119
|
+
service.stop()
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('a failed first load without a pending order still shows the form', async () => {
|
|
124
|
+
const request = stubRequest([networkError()])
|
|
125
|
+
const service = interpret(withdrawManualCash(request, context)).start()
|
|
126
|
+
try {
|
|
127
|
+
await waitForState(service, 'loaded')
|
|
128
|
+
assert.equal(request.calls.pendingOrder, 1)
|
|
129
|
+
assert.equal(service.state.context.processing, null)
|
|
130
|
+
} finally {
|
|
131
|
+
service.stop()
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('REFRESH in loaded with a bound bank is still ignored', async () => {
|
|
136
|
+
const request = stubRequest([[]])
|
|
137
|
+
const service = interpret(withdrawManualCash(request, context)).start()
|
|
138
|
+
try {
|
|
139
|
+
await waitForState(service, 'loaded')
|
|
140
|
+
assert.equal(request.calls.pendingOrder, 1)
|
|
141
|
+
service.send({ type: 'REFRESH' })
|
|
142
|
+
assert.equal(service.state.matches('loaded'), true)
|
|
143
|
+
await new Promise((resolve) => setTimeout(resolve, 20))
|
|
144
|
+
assert.equal(request.calls.pendingOrder, 1)
|
|
145
|
+
assert.equal(service.state.matches('loaded'), true)
|
|
146
|
+
} finally {
|
|
147
|
+
service.stop()
|
|
148
|
+
}
|
|
149
|
+
})
|