@jetthai/cuora 1.1.488 → 2.0.0-beta.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/.husky/pre-commit +3 -1
- package/BREAKING_CHANGES.md +9 -0
- package/CHANGELOG.md +3 -316
- package/README.md +15 -299
- package/package.json +5 -5
- package/resetGitBranch.sh +101 -0
- package/src/api/account.js +1 -0
- package/src/api/activity.js +39 -24
- package/src/api/auth.js +36 -5
- package/src/api/common.js +3 -5
- package/src/api/game.js +10 -0
- package/src/api/payment.js +55 -17
- package/src/api/user.js +16 -10
- package/src/index.js +2 -2
- package/src/lib/fingerprint_v3_11_12.js +11433 -0
- package/src/machine/activity/activity.js +213 -0
- package/src/machine/activity/activity_cash.js +36 -84
- package/src/machine/activity/cash_rain_activity.js +1 -0
- package/src/machine/activity/continue_deposit_activity.js +1 -0
- package/src/machine/activity/deposit_activity.js +1 -0
- package/src/machine/activity/diamond_shop_activity_cash.js +8 -0
- package/src/machine/activity/diamond_shop_activity_fc.js +197 -0
- package/src/machine/activity/diamond_shop_activity_vn.js +179 -0
- package/src/machine/activity/fafafa_activity.js +11 -0
- package/src/machine/activity/friend_invite_friends_activity.js +7 -8
- package/src/machine/activity/index.js +12 -0
- package/src/machine/activity/instant_rebate_activity.js +1 -0
- package/src/machine/activity/invite_friends_activity.js +115 -0
- package/src/machine/activity/jackpot.js +1 -0
- package/src/machine/activity/mini_game_activity.js +69 -0
- package/src/machine/activity/otp_verified_activity.js +1 -0
- package/src/machine/activity/ranking_activity.js +1 -0
- package/src/machine/activity/return_bonus_activity.js +155 -0
- package/src/machine/activity/roulette_activity_v2.js +1 -0
- package/src/machine/activity/sign_in_activity.js +1 -0
- package/src/machine/activity/sign_in_monthly_activity.js +2 -1
- package/src/machine/activity/specify_bets_activity.js +1 -0
- package/src/machine/activity/specify_turnover_activity.js +1 -0
- package/src/machine/activity/time_bomb_activity.js +1 -0
- package/src/machine/activity/vip_card_activity.js +1 -0
- package/src/machine/auth.js +112 -149
- package/src/machine/auth_otp_v2.js +178 -0
- package/src/machine/auth_otp_v3.js +22 -64
- package/src/machine/bank_binding.js +3 -2
- package/src/machine/bank_binding_amb.js +146 -0
- package/src/machine/bonus.js +76 -0
- package/src/machine/common.js +98 -14
- package/src/machine/deposit/amb.js +93 -0
- package/src/machine/deposit/crypto_bank.js +340 -0
- package/src/machine/deposit/crypto_bank_cash.js +35 -20
- package/src/machine/deposit/crypto_qrcode.js +158 -0
- package/src/machine/deposit/crypto_qrcode_cash.js +64 -26
- package/src/machine/deposit/crypto_way.js +253 -0
- package/src/machine/deposit/crypto_way_cash.js +37 -48
- package/src/machine/deposit/deposit_fc.js +272 -0
- package/src/machine/deposit/direct.js +311 -0
- package/src/machine/deposit/direct_cash.js +10 -8
- package/src/machine/deposit/float.js +375 -0
- package/src/machine/deposit/index.js +28 -0
- package/src/machine/deposit/krway.js +152 -0
- package/src/machine/deposit/loadcard_cash.js +32 -14
- package/src/machine/deposit/loadcard_vn.js +352 -0
- package/src/machine/deposit/manual_cash.js +11 -8
- package/src/machine/deposit/manual_vn.js +459 -0
- package/src/machine/deposit/qrcode_cash.js +32 -15
- package/src/machine/deposit/qrcode_v2.js +339 -0
- package/src/machine/deposit/usdt.js +163 -0
- package/src/machine/deposit/usdt_cash.js +15 -1
- package/src/machine/deposit/virtual_bank_cash.js +12 -13
- package/src/machine/deposit/virtual_bank_vn.js +270 -0
- package/src/machine/deposit/vpay.js +374 -0
- package/src/machine/error.js +1 -7
- package/src/machine/game_betslip.js +1 -0
- package/src/machine/game_favorite_v2.js +1 -0
- package/src/machine/game_hot_new.js +80 -0
- package/src/machine/game_info.js +13 -1
- package/src/machine/game_replay.js +47 -0
- package/src/machine/game_search_cash.js +1 -0
- package/src/machine/game_search_v2.js +402 -0
- package/src/machine/game_v2_1.js +126 -39
- package/src/machine/honor_board.js +133 -0
- package/src/machine/honor_board_cash.js +28 -22
- package/src/machine/inbox.js +105 -43
- package/src/machine/index.js +32 -0
- package/src/machine/leaderboard.js +12 -8
- package/src/machine/merge.js +58 -0
- package/src/machine/navbar.js +3 -1
- package/src/machine/payment_data.js +87 -0
- package/src/machine/promotions.js +163 -0
- package/src/machine/ranking.js +30 -45
- package/src/machine/reward.js +256 -0
- package/src/machine/reward_cash.js +42 -2
- package/src/machine/reward_fc.js +99 -0
- package/src/machine/roulette_v2.js +11 -14
- package/src/machine/setting.js +1 -0
- package/src/machine/side.js +160 -0
- package/src/machine/side_cash.js +3 -3
- package/src/machine/side_v2.js +223 -0
- package/src/machine/user_info.js +1 -0
- package/src/machine/user_photo.js +1 -0
- package/src/machine/user_reset_password.js +14 -0
- package/src/machine/user_sign_up.js +61 -46
- package/src/machine/vip_table.js +58 -0
- package/src/machine/websocket.js +349 -374
- package/src/machine/welcome.js +111 -0
- package/src/machine/withdraw/index.js +6 -0
- package/src/machine/withdraw/withdraw_crypto_cash.js +328 -0
- package/src/machine/withdraw/withdraw_krway.js +223 -0
- package/src/machine/withdraw/withdraw_manual.js +541 -0
- package/src/machine/withdraw/withdraw_manual_cash.js +39 -59
- package/src/request/config.js +0 -2
- package/src/request/request.js +60 -124
- package/src/util/constant.js +2 -6
- package/src/util/deviceToken.js +60 -0
- package/src/util/index.js +4 -2
- package/src/util/math.js +4 -0
- package/src/util/storage.js +4 -3
- package/test/api.behavior.test.js +69 -0
- package/test/api.contract.test.js +18 -0
- package/test/config.test.js +27 -0
- package/test/deviceToken.test.js +139 -0
- package/test/helpers.coverage.test.js +11 -0
- package/test/helpers.js +91 -0
- package/test/index.exports.test.js +14 -0
- package/test/machine.activity.core.coverage.test.js +337 -0
- package/test/machine.activity.gap.coverage.test.js +252 -0
- package/test/machine.activity.more.coverage.test.js +180 -0
- package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
- package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
- package/test/machine.activity_welcome.low.coverage.test.js +211 -0
- package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
- package/test/machine.auth.coverage.test.js +215 -0
- package/test/machine.bank_binding.test.js +143 -0
- package/test/machine.binding_otp_krway.coverage.test.js +223 -0
- package/test/machine.contract.test.js +50 -0
- package/test/machine.crypto_bank.coverage.test.js +270 -0
- package/test/machine.crypto_way.coverage.test.js +108 -0
- package/test/machine.crypto_way_cash.coverage.test.js +114 -0
- package/test/machine.definition.test.js +137 -0
- package/test/machine.deposit.manual.coverage.test.js +365 -0
- package/test/machine.deposit_fc.coverage.test.js +126 -0
- package/test/machine.direct.coverage.test.js +96 -0
- package/test/machine.direct_cash.coverage.test.js +108 -0
- package/test/machine.error.coverage.test.js +37 -0
- package/test/machine.events.test.js +126 -0
- package/test/machine.favorite_jackpot.coverage.test.js +82 -0
- package/test/machine.float.coverage.test.js +136 -0
- package/test/machine.flow.test.js +226 -0
- package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
- package/test/machine.game_search_cash.coverage.test.js +155 -0
- package/test/machine.game_search_v2.test.js +199 -0
- package/test/machine.game_user_profile.coverage.test.js +100 -0
- package/test/machine.honor_board.test.js +133 -0
- package/test/machine.inbox.common.coverage.test.js +304 -0
- package/test/machine.loadcard_cash.coverage.test.js +101 -0
- package/test/machine.loadcard_vn.coverage.test.js +122 -0
- package/test/machine.misc.coverage.test.js +361 -0
- package/test/machine.more2.coverage.test.js +261 -0
- package/test/machine.options.execution.test.js +272 -0
- package/test/machine.priority.coverage.test.js +603 -0
- package/test/machine.qrcode_cash.coverage.test.js +107 -0
- package/test/machine.qrcode_v2.coverage.test.js +121 -0
- package/test/machine.regression.test.js +82 -0
- package/test/machine.roulette_v2.test.js +142 -0
- package/test/machine.side_reward_reset.coverage.test.js +220 -0
- package/test/machine.targeted.coverage.test.js +313 -0
- package/test/machine.usdt.coverage.test.js +95 -0
- package/test/machine.usdt_cash.coverage.test.js +73 -0
- package/test/machine.vip_card_activity.test.js +114 -0
- package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
- package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
- package/test/machine.vpay.coverage.test.js +142 -0
- package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
- package/test/machine.withdraw_krway.coverage.test.js +123 -0
- package/test/machine.withdraw_manual.coverage.test.js +185 -0
- package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
- package/test/request.test.js +325 -0
- package/test/util.storage.errors.test.js +47 -0
- package/test/util.test.js +41 -0
- package/.claude/commands/sync-ai-prompts.md +0 -93
- package/.claude/settings.local.json +0 -23
- package/.github/copilot-instructions.md +0 -448
- package/.husky/post-checkout +0 -32
- package/.husky/pre-push +0 -36
- package/AGENTS.md +0 -448
- package/AI_PROMPT_SOURCE.md +0 -446
- package/CLAUDE.md +0 -448
- package/GEMINI.md +0 -448
- package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
- package/docs/kibana/play-providerId-error.md +0 -202
- package/docs/kibana/play-selectedWalletType.md +0 -1
- package/docs/kibana/play-selectedWalletType_2.md +0 -1
- package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
- package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
- package/scripts/auto-version.js +0 -68
- package/scripts/auto-version.sh +0 -33
- package/scripts/branch-auto-npm-publish.js +0 -29
- package/scripts/check-version.sh +0 -36
- package/scripts/clean-tags.sh +0 -84
- package/src/util/amount.js +0 -8
- package/src/util/err998SentryExtra.js +0 -26
- package/src/util/paramStore.js +0 -139
- package/src/util/socketPolicy.js +0 -57
- package/test/auth_otp_v3.test.js +0 -323
- package/tests/websocket.test.mjs +0 -779
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import api from '../src/api/index.js'
|
|
5
|
+
|
|
6
|
+
test('auth.register builds querystring and payload correctly', () => {
|
|
7
|
+
const req = api.auth.register({
|
|
8
|
+
channel: 'web',
|
|
9
|
+
subchannel: 'sub',
|
|
10
|
+
ac: 'ac1',
|
|
11
|
+
fc: null,
|
|
12
|
+
dt: 'dt1',
|
|
13
|
+
username: 'u1',
|
|
14
|
+
password: 'p1',
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
assert.equal(req.method, 'post')
|
|
18
|
+
assert.equal(req.url, 'register?channel=web&subchannel=sub&ac=ac1')
|
|
19
|
+
assert.equal(req.params.dt, 'dt1')
|
|
20
|
+
assert.equal(req.params.username, 'u1')
|
|
21
|
+
assert.equal(req.isPublic, true)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('common API endpoints keep expected paths', () => {
|
|
25
|
+
assert.equal(api.common.getConfig({ appSecret: 's' }).url, 'getConfig')
|
|
26
|
+
assert.equal(api.common.broadcast({ appSecret: 's' }).url, 'broadcast')
|
|
27
|
+
assert.equal(api.common.sendPixel({ appSecret: 's' }).method, 'post')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('game search trace and replay endpoints map params', () => {
|
|
31
|
+
const trace = api.game.setGameSearchTrace({
|
|
32
|
+
traceId: 't1',
|
|
33
|
+
tagId: 'tag',
|
|
34
|
+
gameCode: 'g1',
|
|
35
|
+
query: 'q',
|
|
36
|
+
})
|
|
37
|
+
assert.equal(trace.url, 'game/search/trace')
|
|
38
|
+
assert.equal(trace.method, 'post')
|
|
39
|
+
assert.equal(trace.params.traceId, 't1')
|
|
40
|
+
|
|
41
|
+
const replay = api.game.getGameReplayInfo({ providerId: 'P', seqNo: 'S', lang: 'en', appSecret: 'sec' })
|
|
42
|
+
assert.equal(replay.url, 'game/gameReplay')
|
|
43
|
+
assert.equal(replay.isPublic, true)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('payment APIs build dynamic method paths', () => {
|
|
47
|
+
assert.equal(api.payment.getBankList('crypto').url, 'payment/v2/crypto/getBankList')
|
|
48
|
+
assert.equal(api.payment.checkTransaction('manual').url, 'payment/v2/manual/checkTransaction')
|
|
49
|
+
assert.equal(api.payment.getDepositExpectedResult({ method: 'manual', amount: 10 }).url, 'payment/v2/manual/expected/result')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('user and otp APIs keep security-sensitive paths', () => {
|
|
53
|
+
assert.equal(api.user.passwordV2RecoveryInit({ provider: 'account', username: 'u', appSecret: 's' }).url, 'recovery/v2/initiate')
|
|
54
|
+
assert.equal(api.user.verifyV2Initiate({ strategy: 'phone' }).url, '/verify/v2/initiate')
|
|
55
|
+
|
|
56
|
+
const verify = api.otp.verification({ requestId: 'r1', code: '1234' })
|
|
57
|
+
assert.equal(verify.url, 'otp-verification-point/verify')
|
|
58
|
+
assert.equal(verify.method, 'POST')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('activity APIs retain public/private intent', () => {
|
|
62
|
+
const list = api.activity.getActivityList({ appSecret: 's' })
|
|
63
|
+
assert.equal(list.url, 'activities/list')
|
|
64
|
+
assert.equal(list.isPublic, true)
|
|
65
|
+
|
|
66
|
+
const detail = api.activity.getActivityDetail({ activityNo: 1, appSecret: 's' })
|
|
67
|
+
assert.equal(detail.url, 'activities')
|
|
68
|
+
assert.equal(detail.isPublic, undefined)
|
|
69
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import api from '../src/api/index.js'
|
|
5
|
+
import { callWithFallback } from './helpers.js'
|
|
6
|
+
|
|
7
|
+
for (const [moduleName, moduleApi] of Object.entries(api)) {
|
|
8
|
+
test(`api contract: ${moduleName} endpoints return request descriptor`, () => {
|
|
9
|
+
assert.equal(typeof moduleApi, 'object')
|
|
10
|
+
|
|
11
|
+
for (const [fnName, endpointFactory] of Object.entries(moduleApi)) {
|
|
12
|
+
assert.equal(typeof endpointFactory, 'function', `${moduleName}.${fnName} should be a function`)
|
|
13
|
+
const requestDescriptor = callWithFallback(endpointFactory)
|
|
14
|
+
assert.equal(typeof requestDescriptor.url, 'string', `${moduleName}.${fnName} should return url`)
|
|
15
|
+
assert.equal(typeof requestDescriptor.method, 'string', `${moduleName}.${fnName} should return method`)
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import Config from '../src/request/config.js'
|
|
5
|
+
|
|
6
|
+
test('config builds fullURL and supports setApiURL', () => {
|
|
7
|
+
const config = new Config({
|
|
8
|
+
apiURL: 'https://api.example.com',
|
|
9
|
+
apiVersion: 'v2',
|
|
10
|
+
clientId: 'cid',
|
|
11
|
+
appSecret: 'secret',
|
|
12
|
+
platform: 'web',
|
|
13
|
+
version: '1.0.0',
|
|
14
|
+
fpToken: 'fp-token',
|
|
15
|
+
sentry: null,
|
|
16
|
+
defaultChannel: 'ch',
|
|
17
|
+
defaultSubchannel: 'sub',
|
|
18
|
+
socketURL: 'wss://socket.example.com',
|
|
19
|
+
bucketName: 'bucket',
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
assert.equal(config.fullURL, 'https://api.example.com/v2/cid')
|
|
23
|
+
|
|
24
|
+
config.setApiURL('https://api2.example.com/root')
|
|
25
|
+
assert.equal(config.apiURL, 'https://api2.example.com/root')
|
|
26
|
+
assert.equal(config.fullURL, 'https://api2.example.com/root/v2/cid')
|
|
27
|
+
})
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { getDeviceToken, getDeviceTokenWithRetry } from '../src/util/deviceToken.js'
|
|
5
|
+
|
|
6
|
+
test('getDeviceToken returns undefined when disabled', async () => {
|
|
7
|
+
const result = await getDeviceToken({
|
|
8
|
+
enable: false,
|
|
9
|
+
fpToken: 'fp',
|
|
10
|
+
hosts: ['https://fnapi1.example.com'],
|
|
11
|
+
})
|
|
12
|
+
assert.equal(result, undefined)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('getDeviceToken handles host/input errors and reports to sentry', async () => {
|
|
16
|
+
const sentryCalls = []
|
|
17
|
+
const sentry = {
|
|
18
|
+
setTag: (...args) => sentryCalls.push(['setTag', ...args]),
|
|
19
|
+
captureException: (...args) => sentryCalls.push(['captureException', ...args]),
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const result = await getDeviceToken({
|
|
23
|
+
enable: true,
|
|
24
|
+
fpToken: 'fp',
|
|
25
|
+
hosts: null,
|
|
26
|
+
sentry,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
assert.equal(result, undefined)
|
|
30
|
+
assert.equal(
|
|
31
|
+
sentryCalls.some((entry) => entry[0] === 'captureException'),
|
|
32
|
+
true
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('getDeviceTokenWithRetry returns undefined when disabled', async () => {
|
|
37
|
+
const result = await getDeviceTokenWithRetry({
|
|
38
|
+
enable: false,
|
|
39
|
+
fpToken: 'fp',
|
|
40
|
+
hosts: ['https://fnapi1.example.com'],
|
|
41
|
+
maxRetries: 2,
|
|
42
|
+
intervalMs: 1,
|
|
43
|
+
})
|
|
44
|
+
assert.equal(result, undefined)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('getDeviceTokenWithRetry retries and throws after maxRetries', async () => {
|
|
48
|
+
await assert.rejects(
|
|
49
|
+
getDeviceTokenWithRetry({
|
|
50
|
+
enable: true,
|
|
51
|
+
fpToken: 'fp',
|
|
52
|
+
hosts: [],
|
|
53
|
+
maxRetries: 2,
|
|
54
|
+
intervalMs: 1,
|
|
55
|
+
})
|
|
56
|
+
)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('getDeviceToken returns visitorId when loader succeeds', async () => {
|
|
60
|
+
const sentryCalls = []
|
|
61
|
+
const sentry = {
|
|
62
|
+
setTag: (...args) => sentryCalls.push(['setTag', ...args]),
|
|
63
|
+
captureException: (...args) => sentryCalls.push(['captureException', ...args]),
|
|
64
|
+
}
|
|
65
|
+
const loader = async () => ({
|
|
66
|
+
get: async () => ({ visitorId: 'dt-ok' }),
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const result = await getDeviceToken({
|
|
70
|
+
enable: true,
|
|
71
|
+
fpToken: 'fp',
|
|
72
|
+
hosts: ['https://fnapi1.example.com'],
|
|
73
|
+
sentry,
|
|
74
|
+
loader,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
assert.equal(result, 'dt-ok')
|
|
78
|
+
assert.equal(
|
|
79
|
+
sentryCalls.some((entry) => entry[0] === 'setTag' && entry[1] === 'dt' && entry[2] === 'dt-ok'),
|
|
80
|
+
true
|
|
81
|
+
)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('getDeviceTokenWithRetry returns token when loader eventually succeeds', async () => {
|
|
85
|
+
let count = 0
|
|
86
|
+
const loader = async () => ({
|
|
87
|
+
get: async () => {
|
|
88
|
+
count += 1
|
|
89
|
+
return { visitorId: count >= 2 ? 'dt-retry' : null }
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const result = await getDeviceTokenWithRetry({
|
|
94
|
+
enable: true,
|
|
95
|
+
fpToken: 'fp',
|
|
96
|
+
hosts: ['https://fnapi1.example.com'],
|
|
97
|
+
maxRetries: 3,
|
|
98
|
+
intervalMs: 1,
|
|
99
|
+
loader,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
assert.equal(result, 'dt-retry')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('getDeviceToken normalizes and deduplicates hosts before loader', async () => {
|
|
106
|
+
let capturedEndpoints = null
|
|
107
|
+
const loader = async ({ endpoint }) => {
|
|
108
|
+
capturedEndpoints = endpoint
|
|
109
|
+
return { get: async () => ({ visitorId: 'dt-hosts' }) }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const result = await getDeviceToken({
|
|
113
|
+
enable: true,
|
|
114
|
+
fpToken: 'fp',
|
|
115
|
+
hosts: ['https://fnapi1.example.com', 'https://fnapi2.example.com'],
|
|
116
|
+
loader,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
assert.equal(result, 'dt-hosts')
|
|
120
|
+
assert.equal(Array.isArray(capturedEndpoints), true)
|
|
121
|
+
// fnapi* should be normalized to fp and then deduplicated into one host plus default endpoint
|
|
122
|
+
assert.equal(
|
|
123
|
+
capturedEndpoints.some((url) => String(url).includes('fp.example.com')),
|
|
124
|
+
true
|
|
125
|
+
)
|
|
126
|
+
assert.equal(capturedEndpoints.length >= 2, true)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('getDeviceTokenWithRetry returns undefined when maxRetries is zero', async () => {
|
|
130
|
+
const result = await getDeviceTokenWithRetry({
|
|
131
|
+
enable: true,
|
|
132
|
+
fpToken: 'fp',
|
|
133
|
+
hosts: ['https://fnapi1.example.com'],
|
|
134
|
+
maxRetries: 0,
|
|
135
|
+
intervalMs: 1,
|
|
136
|
+
loader: async () => ({ get: async () => ({ visitorId: 'never-used' }) }),
|
|
137
|
+
})
|
|
138
|
+
assert.equal(result, undefined)
|
|
139
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { callWithFallback } from './helpers.js'
|
|
5
|
+
|
|
6
|
+
test('callWithFallback throws default error when no candidate returns object', () => {
|
|
7
|
+
assert.throws(
|
|
8
|
+
() => callWithFallback(() => null),
|
|
9
|
+
(error) => error instanceof Error && error.message.includes('Function did not return an object')
|
|
10
|
+
)
|
|
11
|
+
})
|
package/test/helpers.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export function createLocalStorageMock() {
|
|
2
|
+
const store = new Map()
|
|
3
|
+
return {
|
|
4
|
+
getItem(key) {
|
|
5
|
+
return store.has(key) ? store.get(key) : null
|
|
6
|
+
},
|
|
7
|
+
setItem(key, value) {
|
|
8
|
+
store.set(key, String(value))
|
|
9
|
+
},
|
|
10
|
+
removeItem(key) {
|
|
11
|
+
store.delete(key)
|
|
12
|
+
},
|
|
13
|
+
clear() {
|
|
14
|
+
store.clear()
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function callWithFallback(fn) {
|
|
20
|
+
const candidates = [
|
|
21
|
+
[],
|
|
22
|
+
[{}],
|
|
23
|
+
[
|
|
24
|
+
{
|
|
25
|
+
appSecret: 'app-secret',
|
|
26
|
+
method: 'manual',
|
|
27
|
+
paymentMethod: 'manual',
|
|
28
|
+
provider: 'google',
|
|
29
|
+
username: 'user',
|
|
30
|
+
password: 'pwd',
|
|
31
|
+
channel: 'channel',
|
|
32
|
+
subchannel: 'subchannel',
|
|
33
|
+
payload: { amount: 1 },
|
|
34
|
+
type: 'DEPOSIT',
|
|
35
|
+
amount: 100,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
['manual'],
|
|
39
|
+
[1],
|
|
40
|
+
[undefined],
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
let lastError
|
|
44
|
+
for (const args of candidates) {
|
|
45
|
+
try {
|
|
46
|
+
const result = fn(...args)
|
|
47
|
+
if (result && typeof result === 'object') {
|
|
48
|
+
return result
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
lastError = error
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw lastError || new Error('Function did not return an object with fallback arguments')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createAxiosMock() {
|
|
59
|
+
const handlers = {
|
|
60
|
+
requestSuccess: null,
|
|
61
|
+
responseSuccess: null,
|
|
62
|
+
responseError: null,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
handlers,
|
|
67
|
+
axios: {
|
|
68
|
+
defaults: {},
|
|
69
|
+
CancelToken: {
|
|
70
|
+
source: () => ({
|
|
71
|
+
token: { id: Math.random().toString(16).slice(2) },
|
|
72
|
+
cancel: () => {},
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
interceptors: {
|
|
76
|
+
request: {
|
|
77
|
+
use: (success) => {
|
|
78
|
+
handlers.requestSuccess = success
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
response: {
|
|
82
|
+
use: (success, error) => {
|
|
83
|
+
handlers.responseSuccess = success
|
|
84
|
+
handlers.responseError = error
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
request: async (config) => ({ data: { ok: true }, config }),
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import * as cuora from '../src/index.js'
|
|
5
|
+
|
|
6
|
+
test('index exports core modules', () => {
|
|
7
|
+
assert.ok(cuora.api)
|
|
8
|
+
assert.ok(cuora.machine)
|
|
9
|
+
assert.ok(cuora.Request)
|
|
10
|
+
assert.ok(cuora.Config)
|
|
11
|
+
assert.ok(cuora.util)
|
|
12
|
+
assert.ok(cuora.constant)
|
|
13
|
+
assert.ok(cuora.storage)
|
|
14
|
+
})
|