@jetthai/cuora 1.1.485-dev.2 → 1.1.487-otp.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.
Files changed (112) hide show
  1. package/.claude/commands/sync-ai-prompts.md +1 -88
  2. package/.claude/settings.local.json +1 -3
  3. package/.github/copilot-instructions.md +5 -8
  4. package/.husky/post-checkout +3 -3
  5. package/.husky/pre-push +1 -1
  6. package/.prettierignore +1 -2
  7. package/AGENTS.md +5 -8
  8. package/AI_PROMPT_SOURCE.md +5 -8
  9. package/CHANGELOG.md +29 -374
  10. package/CLAUDE.md +5 -8
  11. package/GEMINI.md +5 -8
  12. package/e2e/feature-map.md +19 -0
  13. package/package.json +3 -3
  14. package/prepare-for-pr/JT-1776243420.md +85 -0
  15. package/prepare-for-pr/TI-16026/STATE.md +18 -0
  16. package/prepare-for-pr/TI-16026/after-prepare-authorization.md +3 -0
  17. package/prepare-for-pr/TI-16026/analysis.md +38 -0
  18. package/prepare-for-pr/TI-16026/answer-analyze-01.md +1 -0
  19. package/prepare-for-pr/TI-16026/answer-commit-01.md +2 -0
  20. package/prepare-for-pr/TI-16026/answer-commit-02.md +1 -0
  21. package/prepare-for-pr/TI-16026/bundle.json +18 -0
  22. package/prepare-for-pr/TI-16026/checklist.md +196 -0
  23. package/prepare-for-pr/TI-16026/checklist.unit-test-original.md +39 -0
  24. package/prepare-for-pr/TI-16026/claude-after-model +1 -0
  25. package/prepare-for-pr/TI-16026/claude-commit-session +1 -0
  26. package/prepare-for-pr/TI-16026/claude-harvest-session +1 -0
  27. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.err +1 -0
  28. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.out +2 -0
  29. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.err +1 -0
  30. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.out +4 -0
  31. package/prepare-for-pr/TI-16026/claude-hops/03-dev.err +1 -0
  32. package/prepare-for-pr/TI-16026/claude-hops/03-dev.out +4 -0
  33. package/prepare-for-pr/TI-16026/claude-hops/04-dev.err +1 -0
  34. package/prepare-for-pr/TI-16026/claude-hops/04-dev.out +4 -0
  35. package/prepare-for-pr/TI-16026/claude-hops/05-dev.err +1 -0
  36. package/prepare-for-pr/TI-16026/claude-hops/05-dev.out +3 -0
  37. package/prepare-for-pr/TI-16026/claude-hops/06-after.err +1 -0
  38. package/prepare-for-pr/TI-16026/claude-hops/06-after.out +2 -0
  39. package/prepare-for-pr/TI-16026/claude-hops/07-commit.err +1 -0
  40. package/prepare-for-pr/TI-16026/claude-hops/07-commit.out +2 -0
  41. package/prepare-for-pr/TI-16026/claude-hops/08-commit.err +1 -0
  42. package/prepare-for-pr/TI-16026/claude-hops/08-commit.out +2 -0
  43. package/prepare-for-pr/TI-16026/claude-hops/09-commit.err +1 -0
  44. package/prepare-for-pr/TI-16026/claude-hops/09-commit.out +8 -0
  45. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.err +1 -0
  46. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.out +3 -0
  47. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.err +1 -0
  48. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.out +3 -0
  49. package/prepare-for-pr/TI-16026/commit-note.md +5 -0
  50. package/prepare-for-pr/TI-16026/evidence-index.json +215 -0
  51. package/prepare-for-pr/TI-16026/feature-map.before.md +61 -0
  52. package/prepare-for-pr/TI-16026/harvest-redaction.json +34 -0
  53. package/prepare-for-pr/TI-16026/harvest-redaction.out +37 -0
  54. package/prepare-for-pr/TI-16026/harvest.md +46 -0
  55. package/prepare-for-pr/TI-16026/lessons.md +5 -0
  56. package/prepare-for-pr/TI-16026/note-harvest-redaction.md +1 -0
  57. package/prepare-for-pr/TI-16026/open-questions.md +6 -0
  58. package/prepare-for-pr/TI-16026/publish.md +32 -0
  59. package/prepare-for-pr/TI-16026/review-convergence-response.md +3 -0
  60. package/prepare-for-pr/TI-16026/review-input/scope.md +18 -0
  61. package/prepare-for-pr/TI-16026/review-log.md +57 -0
  62. package/prepare-for-pr/TI-16026/review-notes.md +97 -0
  63. package/prepare-for-pr/TI-16026/review-response-r1.md +7 -0
  64. package/prepare-for-pr/TI-16026/self-test-report.md +67 -0
  65. package/prepare-for-pr/TI-16026/spec-proposal.md +34 -0
  66. package/prepare-for-pr/TI-16026/spec-snapshot.md +291 -0
  67. package/prepare-for-pr/TI-16026/state-log.md +57 -0
  68. package/prepare-for-pr/TI-16026/user-messages/01.md +12 -0
  69. package/prepare-for-pr/TI-16026/user-messages/02.md +20 -0
  70. package/prepare-for-pr/TI-16026/user-messages/03.md +1 -0
  71. package/prepare-for-pr/TI-16026/user-messages/04.md +1 -0
  72. package/prepare-for-pr/TI-16026/user-messages/05.md +1 -0
  73. package/prepare-for-pr/TI-16026/user-messages/06.md +1 -0
  74. package/prepare-for-pr/TI-16026/user-messages/07.md +1 -0
  75. package/prepare-for-pr/TI-16026/user-messages/08.md +1 -0
  76. package/prepare-for-pr/TI-16026/user-messages/09.md +1 -0
  77. package/prepare-for-pr/TI-16026/user-messages/10.md +1 -0
  78. package/prepare-for-pr/TI-16026/user-messages/11.md +1 -0
  79. package/prepare-for-pr/TI-16026/user-messages/12.md +1 -0
  80. package/prepare-for-pr/TI-16026/user-messages/13.md +1 -0
  81. package/prepare-for-pr/TI-16026/user-messages/14.md +1 -0
  82. package/prepare-for-pr/TI-16026/user-messages/15.md +1 -0
  83. package/prepare-for-pr/TI-16026/user-messages/16.md +1 -0
  84. package/prepare-for-pr/TI-16026/user-messages/17.md +1 -0
  85. package/prepare-for-pr/TI-16026/user-messages/18.md +10 -0
  86. package/prepare-for-pr/TI-16026/user-messages/19.md +1 -0
  87. package/prepare-for-pr/TI-16026/user-messages/20.md +1 -0
  88. package/prepare-for-pr/TI-16026/user-messages/21.md +1 -0
  89. package/prepare-for-pr/TI-16026/user-messages/22.md +1 -0
  90. package/prepare-for-pr/TI-16026/user-messages/23.md +8 -0
  91. package/prepare-for-pr/TI-16026/user-messages/24.md +24 -0
  92. package/prepare-for-pr/TI-16026/user-question.md +24 -0
  93. package/prepare-for-pr/TI-16026/verify/metrics-check.json +13 -0
  94. package/prepare-for-pr/TI-16026/verify/redaction.json +38 -0
  95. package/prepare-for-pr/TI-16026/verify/row-closure.json +45 -0
  96. package/prepare-for-pr/TI-16026/verify/s04-ws-capture.md +23 -0
  97. package/prepare-for-pr/TI-16026/verify-after.md +23 -0
  98. package/prepare-for-pr/TI-16026/verify.json +80 -0
  99. package/prepare-for-pr/TI-16026.md +408 -0
  100. package/scripts/auto-version.js +0 -1
  101. package/scripts/branch-auto-npm-publish.js +2 -9
  102. package/src/api/payment.js +0 -1
  103. package/src/machine/auth.js +18 -5
  104. package/src/machine/game_v2_1.js +0 -15
  105. package/src/machine/reward_cash.js +2 -2
  106. package/src/machine/user_sign_up.js +0 -3
  107. package/src/machine/withdraw/withdraw_manual_cash.js +14 -10
  108. package/src/request/request.js +4 -44
  109. package/src/util/constant.js +0 -3
  110. package/src/util/tokenStore.js +0 -44
  111. package/test/withdraw_manual_cash.test.js +0 -149
  112. package/tests/session.test.mjs +0 -177
@@ -1,5 +1,5 @@
1
1
  import pickBy from 'lodash/pickBy.js'
2
- import createTokenStore from '../util/tokenStore.js'
2
+ import storage from '../util/storage.js'
3
3
  import { getErr998SentryExtra } from '../util/err998SentryExtra.js'
4
4
 
5
5
  // 暫停 ERR_998 上報:在組裝 Sentry 資料之前就中止,不建立事件;仍照常 reject ERR_998 給呼叫端。恢復時改回 false 即可
@@ -7,9 +7,6 @@ const IS_ERR_998_REPORT_PAUSED = true
7
7
 
8
8
  const CANCELLED_MESSAGE = 'Requests Cancelled'
9
9
 
10
- const SELF_URL = 'self'
11
- const TOKEN_EXPIRED_CODE = 'ERR_A108'
12
-
13
10
  // const pickBy = require('lodash/pickBy')
14
11
  const supportVersion2List = [
15
12
  // 04-09 Update
@@ -162,7 +159,6 @@ export default class Request {
162
159
  this.config = config
163
160
  this.sentry = config.sentry
164
161
  this.key = `cuora_${config.clientId}`
165
- this.tokenStore = createTokenStore(this.key)
166
162
  this.errorHandler = null
167
163
  this.hosts = []
168
164
  this.isBlocked = false
@@ -285,27 +281,7 @@ export default class Request {
285
281
  return !!this.axios.isCancel?.(error) || error?.message === CANCELLED_MESSAGE
286
282
  }
287
283
 
288
- send(req, customToken) {
289
- return this._send(req, customToken, false)
290
- }
291
-
292
- _isSelf(req) {
293
- return req.url.split('?')[0] === SELF_URL
294
- }
295
-
296
- // ERR_A108 多半是續期的短暫落差:先以 /self 確認 session 仍在,成功才把原請求重送一次。
297
- // /self 自己、已重送過的請求、送出後身分已變的請求都不重送
298
- async _renewSession(req, requestToken) {
299
- if (!requestToken || this._isSelf(req) || this.getToken() !== requestToken) return false
300
- try {
301
- await this._send({ url: SELF_URL, method: 'get', silent: true }, undefined, true)
302
- } catch (error) {
303
- return false
304
- }
305
- return this.getToken() === requestToken
306
- }
307
-
308
- async _send(req, customToken, isRetry) {
284
+ async send(req, customToken) {
309
285
  let tracked = null
310
286
  let requestToken = null
311
287
  try {
@@ -316,7 +292,7 @@ export default class Request {
316
292
  if (!req.isPublic) this._throwIfRevoked()
317
293
 
318
294
  // /self 是 gate 自己的探測請求,不可等待 gate,否則死鎖
319
- if (this.tokenGate && !req.isPublic && !this._isSelf(req)) {
295
+ if (this.tokenGate && !req.isPublic && req.url.split('?')[0] !== 'self') {
320
296
  await this.tokenGate
321
297
  this._throwIfRevoked()
322
298
  if (!this.getToken()) return Promise.reject({ code: 'ERR_A103' })
@@ -346,9 +322,6 @@ export default class Request {
346
322
  }
347
323
  } catch (error) {
348
324
  if (this._isCancelled(error)) throw this._cancelledError()
349
- if (error?.code === TOKEN_EXPIRED_CODE && !isRetry && (await this._renewSession(req, requestToken))) {
350
- return await this._send(req, customToken, true)
351
- }
352
325
  // 不可列舉:避免 Bearer token 隨 JSON.stringify/Sentry 序列化外洩,但 error.requestToken 仍可讀取
353
326
  if (requestToken && error && typeof error === 'object' && Object.isExtensible(error)) {
354
327
  Object.defineProperty(error, 'requestToken', { value: requestToken, enumerable: false, configurable: true })
@@ -448,19 +421,6 @@ export default class Request {
448
421
  }
449
422
 
450
423
  getToken() {
451
- return this.tokenStore.get()
452
- }
453
-
454
- setToken(token) {
455
- this.tokenStore.set(token)
456
- }
457
-
458
- // 回傳續期當下的 token;已不存在時回傳 null
459
- extendToken() {
460
- return this.tokenStore.extend()
461
- }
462
-
463
- removeToken() {
464
- this.tokenStore.clear()
424
+ return storage.get(this.key)
465
425
  }
466
426
  }
@@ -22,6 +22,3 @@ export const GAME_TYPE_LIST = [
22
22
  // OTP 自動驗證:主動打的 /self 未通過後,最多再等幾次 auth 例行輪詢的 /self、等待上限多久
23
23
  export const AUTO_VERIFY_MAX_USER_INFO_UPDATES = 2
24
24
  export const AUTO_VERIFY_WAIT_MS = 5000
25
-
26
- // 登入 token 的存活秒數:每次 /self 成功續期一次,逾時由瀏覽器自行移除 cookie
27
- export const TOKEN_MAX_AGE = 300
@@ -1,44 +0,0 @@
1
- import storage from './storage.js'
2
- import { TOKEN_MAX_AGE } from './constant.js'
3
-
4
- // document.cookie 在受限的環境(sandbox iframe、停用 cookie)會直接拋錯:讀不到視為沒有,寫不進去就算了
5
- function read(name) {
6
- const prefix = `${name}=`
7
- try {
8
- const pair = document.cookie.split('; ').find((item) => item.startsWith(prefix))
9
- return pair ? decodeURIComponent(pair.slice(prefix.length)) || null : null
10
- } catch (error) {
11
- return null
12
- }
13
- }
14
-
15
- // 不帶 Domain:cookie 只屬於寫入它的網域,不跨子網域
16
- function write(name, value, maxAge) {
17
- try {
18
- const secure = location.protocol === 'https:' ? '; Secure' : ''
19
- document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAge}; SameSite=Lax${secure}`
20
- } catch (error) {
21
- console.error(`Error writing cookie: ${error}`)
22
- }
23
- }
24
-
25
- export default function createTokenStore(key) {
26
- // token 原本存在 localStorage;改放 cookie 後不沿用舊值,殘留的一併清掉
27
- storage.remove(key)
28
-
29
- const store = {
30
- get: () => read(key),
31
- set(token) {
32
- if (token) write(key, token, TOKEN_MAX_AGE)
33
- else store.clear()
34
- },
35
- // 以現有的值重寫一次,讓存活時間重新起算
36
- extend() {
37
- const token = read(key)
38
- if (token) write(key, token, TOKEN_MAX_AGE)
39
- return token
40
- },
41
- clear: () => write(key, '', 0),
42
- }
43
- return store
44
- }
@@ -1,149 +0,0 @@
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
- })
@@ -1,177 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { interpret } from 'xstate'
4
- import Request from '../src/request/request.js'
5
- import createTokenStore from '../src/util/tokenStore.js'
6
- import { TOKEN_MAX_AGE } from '../src/util/constant.js'
7
- import game from '../src/machine/game_v2_1.js'
8
-
9
- globalThis.localStorage = { getItem: () => null, setItem() {}, removeItem() {} }
10
- globalThis.location = { protocol: 'http:' }
11
-
12
- // 只模擬 tokenStore 用到的行為:以 name 覆寫、Max-Age=0 即刪除
13
- function installDocument() {
14
- const jar = new Map()
15
- const writes = []
16
- globalThis.document = {
17
- get cookie() {
18
- return [...jar].map(([name, value]) => `${name}=${value}`).join('; ')
19
- },
20
- set cookie(text) {
21
- writes.push(text)
22
- const [pair, ...attributes] = text.split('; ')
23
- const index = pair.indexOf('=')
24
- const name = pair.slice(0, index)
25
- const maxAge = attributes.find((item) => item.startsWith('Max-Age='))
26
- if (maxAge && Number(maxAge.slice(8)) <= 0) jar.delete(name)
27
- else jar.set(name, pair.slice(index + 1))
28
- },
29
- }
30
- return { jar, writes }
31
- }
32
-
33
- function createRequest(respond) {
34
- const calls = []
35
- const axios = {
36
- defaults: {},
37
- interceptors: { request: { use() {} }, response: { use() {} } },
38
- isCancel: () => false,
39
- async request(config) {
40
- calls.push(config.url)
41
- return respond(config, calls.length)
42
- },
43
- }
44
- const request = new Request(axios, { clientId: 'SITE', fullURL: 'https://api.test/v1/SITE' })
45
- const handled = []
46
- request.setErrorHandler((error) => handled.push(error.code))
47
- return { request, calls, handled }
48
- }
49
-
50
- const expired = () => Promise.reject({ code: 'ERR_A108' })
51
- const ok = (data = {}) => Promise.resolve({ data })
52
-
53
- test('token lives in a host-only cookie with a 300 second lifetime', () => {
54
- const { jar, writes } = installDocument()
55
- const store = createTokenStore('cuora_SITE')
56
-
57
- assert.equal(store.get(), null)
58
- store.set('token.a')
59
- assert.equal(store.get(), 'token.a')
60
- assert.equal(writes.at(-1), `cuora_SITE=token.a; Path=/; Max-Age=${TOKEN_MAX_AGE}; SameSite=Lax`)
61
- assert.ok(!/Domain=/i.test(writes.at(-1)))
62
-
63
- jar.set('cuora_SITE-cred', 'sealed')
64
- assert.equal(store.get(), 'token.a')
65
-
66
- const before = writes.length
67
- assert.equal(store.extend(), 'token.a')
68
- assert.equal(writes.length, before + 1)
69
-
70
- store.clear()
71
- assert.equal(store.get(), null)
72
- assert.equal(store.extend(), null)
73
- })
74
-
75
- test('request reads and writes the token through the cookie', () => {
76
- installDocument()
77
- const { request } = createRequest(() => ok())
78
-
79
- request.setToken('token.a')
80
- assert.equal(request.getToken(), 'token.a')
81
- assert.equal(request.extendToken(), 'token.a')
82
- request.removeToken()
83
- assert.equal(request.getToken(), null)
84
- })
85
-
86
- test('ERR_A108 renews through /self and resends the request once', async () => {
87
- installDocument()
88
- const { request, calls, handled } = createRequest((config, count) => (count === 1 ? expired() : ok({ url: config.url })))
89
- request.setToken('token.a')
90
-
91
- const result = await request.send({ url: 'payment/v2/setting', method: 'get' })
92
-
93
- assert.deepEqual(calls, ['payment/v2/setting', 'self', 'payment/v2/setting'])
94
- assert.deepEqual(result, { url: 'payment/v2/setting' })
95
- assert.deepEqual(handled, [])
96
- })
97
-
98
- test('a resent request that still fails with ERR_A108 is routed as before', async () => {
99
- installDocument()
100
- const { request, calls, handled } = createRequest((config) => (config.url === 'self' ? ok() : expired()))
101
- request.setToken('token.a')
102
-
103
- await assert.rejects(request.send({ url: 'payment/v2/setting', method: 'get' }), { code: 'ERR_A108' })
104
-
105
- assert.deepEqual(calls, ['payment/v2/setting', 'self', 'payment/v2/setting'])
106
- assert.deepEqual(handled, ['ERR_A108'])
107
- })
108
-
109
- test('ERR_A108 is not resent when /self cannot renew the session', async () => {
110
- installDocument()
111
- const { request, calls, handled } = createRequest(() => expired())
112
- request.setToken('token.a')
113
-
114
- await assert.rejects(request.send({ url: 'payment/v2/setting', method: 'get' }), { code: 'ERR_A108' })
115
-
116
- assert.deepEqual(calls, ['payment/v2/setting', 'self'])
117
- assert.deepEqual(handled, ['ERR_A108'])
118
- })
119
-
120
- test('/self itself and public requests are never resent', async () => {
121
- installDocument()
122
- const { request, calls } = createRequest(() => expired())
123
- request.setToken('token.a')
124
-
125
- await assert.rejects(request.send({ url: 'self', method: 'get' }), { code: 'ERR_A108' })
126
- await assert.rejects(request.send({ url: 'getConfig', method: 'get', isPublic: true }), { code: 'ERR_A108' })
127
-
128
- assert.deepEqual(calls, ['self', 'get-config'])
129
- })
130
-
131
- test('a request whose identity changed while renewing is not resent', async () => {
132
- installDocument()
133
- let request
134
- const created = createRequest((config, count) => {
135
- if (count === 1) return expired()
136
- request.setToken('token.b')
137
- return ok()
138
- })
139
- request = created.request
140
- request.setToken('token.a')
141
-
142
- await assert.rejects(request.send({ url: 'payment/v2/setting', method: 'get' }), { code: 'ERR_A108' })
143
-
144
- assert.deepEqual(created.calls, ['payment/v2/setting', 'self'])
145
- assert.deepEqual(created.handled, [])
146
- })
147
-
148
- test('ABANDON_GAME leaves a game without calling game/logout', async () => {
149
- installDocument()
150
- const sent = []
151
- const request = {
152
- config: { appSecret: 'secret' },
153
- async send(descriptor) {
154
- sent.push(descriptor.url)
155
- return { type: 'url', redirect_url: 'https://game.test', wallet_type: 'CASH' }
156
- },
157
- }
158
- globalThis.window = { location: { origin: 'https://site.test', href: 'https://site.test/play', search: '' } }
159
- const service = interpret(game(request)).start()
160
-
161
- service.send({
162
- type: 'ENTER_GAME',
163
- data: { game: { providerId: 'P', gameId: 'G', gameTypeId: 'SLOT', mappingId: 1 }, locale: 'en-US' },
164
- })
165
- await new Promise((resolve) => setTimeout(resolve, 0))
166
- assert.ok(service.state.matches('flow.playing'))
167
- assert.equal(service.state.context.gameURL, 'https://game.test')
168
-
169
- service.send({ type: 'ABANDON_GAME' })
170
- assert.ok(service.state.matches('flow.idle'))
171
- assert.equal(service.state.context.gameURL, undefined)
172
-
173
- service.send({ type: 'EXIT_GAME', data: 'uid' })
174
- assert.ok(service.state.matches('flow.idle'))
175
- assert.ok(!sent.includes('game/logout'))
176
- service.stop()
177
- })