feat(semi-auto): 客户链接按平台严格绑定,注入后统一由前端打开指定页
This commit is contained in:
@@ -503,7 +503,7 @@ export async function createSemiAutoMock(
|
||||
skuKey,
|
||||
connectorMode,
|
||||
connectorConfigured,
|
||||
customerPath: `/c/${encodeURIComponent(orderNo)}`,
|
||||
customerPath: buildMockCustomerPath(platform, orderNo),
|
||||
adminPath: `/admin/semi-auto-tasks?keyword=${encodeURIComponent(orderNo)}`,
|
||||
tips:
|
||||
platform === 'weibo'
|
||||
@@ -781,7 +781,7 @@ export async function createSemiAutoIntegrationMock(
|
||||
connectorMode,
|
||||
connectorConfigured,
|
||||
mappingId,
|
||||
customerPath: `/c/${encodeURIComponent(orderNo)}`,
|
||||
customerPath: buildMockCustomerPath(platform, orderNo),
|
||||
adminPath: `/admin/semi-auto-tasks?keyword=${encodeURIComponent(orderNo)}`,
|
||||
tips: [
|
||||
'订单通过正式 upsertOrderFromSource 入库。',
|
||||
@@ -802,6 +802,10 @@ function normalizeMockSemiAutoPlatform(value: unknown): 'huya' | 'weibo' {
|
||||
: 'huya'
|
||||
}
|
||||
|
||||
function buildMockCustomerPath(platform: 'huya' | 'weibo', orderNo: string): string {
|
||||
return `/${platform === 'weibo' ? 'd' : 'c'}/${encodeURIComponent(orderNo)}`
|
||||
}
|
||||
|
||||
function normalizeMockSemiAutoConnectorMode(value: unknown): SemiAutoConnectorMode {
|
||||
const mode = String(value || '')
|
||||
.trim()
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { describe, it } from 'node:test'
|
||||
|
||||
import { buildExtensionInjectionPayload } from './semi-auto-task-service.js'
|
||||
|
||||
const payload = {
|
||||
platform: 'weibo' as const,
|
||||
targetUrl: 'https://weibo.com/',
|
||||
expiresAt: '2026-11-17T00:00:00.000Z',
|
||||
cookies: [
|
||||
{
|
||||
name: 'SUB',
|
||||
value: 'weibo-sub',
|
||||
domain: '.weibo.com',
|
||||
path: '/',
|
||||
secure: true,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
describe('下发给扩展的注入载荷', () => {
|
||||
it('清空 targetUrl,避免扩展额外打开目标页', () => {
|
||||
const result = buildExtensionInjectionPayload(payload)
|
||||
assert.equal(result.targetUrl, '')
|
||||
assert.equal(result.platform, 'weibo')
|
||||
assert.equal(result.expiresAt, payload.expiresAt)
|
||||
assert.deepEqual(result.cookies, payload.cookies)
|
||||
})
|
||||
|
||||
it('不修改票据内的原始载荷(Cookie 序列化仍依赖原 targetUrl)', () => {
|
||||
buildExtensionInjectionPayload(payload)
|
||||
assert.equal(payload.targetUrl, 'https://weibo.com/')
|
||||
})
|
||||
})
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
consumeHuyaBrowserTicket,
|
||||
verifyHuyaSmsChallenge,
|
||||
type ConnectorBindingSession,
|
||||
type ConnectorInjectionPayload,
|
||||
type SemiAutoConnectorMode,
|
||||
type ConnectorLoginSession,
|
||||
} from './huya-connector-client.js'
|
||||
@@ -412,7 +413,7 @@ function assertHuyaTask(task: TaskRow) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 半自动订单没有工单,资料页 /c/<订单号> 是唯一入口。
|
||||
* 半自动订单没有工单,资料页 /c/<订单号>(虎牙)或 /d/<订单号>(微博)是唯一入口。
|
||||
* 未提交区服 / 游戏编号 / 角色名时,不允许开始登录,避免后续无法比对角色。
|
||||
*/
|
||||
function assertCustomerProfileReady(task: TaskRow) {
|
||||
@@ -713,7 +714,7 @@ export async function ensureSemiAutoTasksForOrderItems(input: unknown[]) {
|
||||
/**
|
||||
* 后台列表读取前的幂等回填。
|
||||
*
|
||||
* 客户不先打开 `/c/订单号` 时,任务也必须进入客服工作台;后备查询只插入缺失任务,
|
||||
* 客户不先打开 `/c/订单号` 或 `/d/订单号` 时,任务也必须进入客服工作台;后备查询只插入缺失任务,
|
||||
* 不修改已有任务状态,也不会重复写事件。
|
||||
*/
|
||||
export async function backfillSemiAutoTasks() {
|
||||
@@ -794,7 +795,7 @@ export function normalizeCustomerProfile(input: CustomerProfileInput = {}) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 半自动订单没有 work_orders,客户资料只能在授权页 /c/<订单号> 收集。
|
||||
* 半自动订单没有 work_orders,客户资料只能在授权页 /c/<订单号>(虎牙)或 /d/<订单号>(微博)收集。
|
||||
* 保存后立即参与“客户填写角色 vs 平台识别角色”的比对。
|
||||
*/
|
||||
export async function savePublicTaskProfile(
|
||||
@@ -2200,6 +2201,17 @@ export async function createAdminBrowserSession(
|
||||
return ticket
|
||||
}
|
||||
|
||||
/**
|
||||
* 票据内的 targetUrl 只服务于创建阶段的 Cookie 序列化与审计;
|
||||
* 下发给扩展时清空,指定平台页统一由前端占位页在注入成功后打开,
|
||||
* 这样扩展只写 Cookie,不会再额外打开一个目标页标签。
|
||||
*/
|
||||
export function buildExtensionInjectionPayload(
|
||||
payload: ConnectorInjectionPayload,
|
||||
): ConnectorInjectionPayload {
|
||||
return { ...payload, targetUrl: '' }
|
||||
}
|
||||
|
||||
export async function consumeSemiAutoInjectionTicket(ticketInput: unknown) {
|
||||
const ticket = String(ticketInput || '').trim()
|
||||
if (!ticket) {
|
||||
@@ -2208,10 +2220,10 @@ export async function consumeSemiAutoInjectionTicket(ticketInput: unknown) {
|
||||
errorCode: 'semi_auto_injection_ticket_invalid',
|
||||
})
|
||||
}
|
||||
if (ticket.startsWith(WEIBO_TICKET_PREFIX)) {
|
||||
return consumeWeiboBrowserTicket(ticket)
|
||||
}
|
||||
return consumeHuyaBrowserTicket(ticket)
|
||||
const payload = ticket.startsWith(WEIBO_TICKET_PREFIX)
|
||||
? await consumeWeiboBrowserTicket(ticket)
|
||||
: await consumeHuyaBrowserTicket(ticket)
|
||||
return buildExtensionInjectionPayload(payload)
|
||||
}
|
||||
|
||||
async function resolveCompletionEvidence(
|
||||
|
||||
@@ -91,7 +91,7 @@ test(
|
||||
[fulfillmentId, configId],
|
||||
)
|
||||
|
||||
// 客服工作台先打开时也必须看到任务,不能依赖客户先访问 `/c/订单号`。
|
||||
// 客服工作台先打开时也必须看到任务,不能依赖客户先访问 `/c/订单号` 或 `/d/订单号`。
|
||||
const adminList = await listAdminSemiAutoTasks({ keyword: orderNo })
|
||||
assert.equal(adminList.pagination.total, 1)
|
||||
assert.equal(adminList.items[0]?.orderNo, orderNo)
|
||||
|
||||
Reference in New Issue
Block a user