This commit is contained in:
2026-04-22 22:01:07 +08:00
parent d8716d70b0
commit b317c2a8ea
37 changed files with 1821 additions and 515 deletions

View File

@@ -51,3 +51,26 @@ test('createSmsVerificationService initializes aliyun sdk client under tsx esm r
assert.equal(typeof service.sendLoginCode, 'function');
assert.equal(typeof service.verifyLoginCode, 'function');
});
test('mock sms service reports delivered tracking metadata', async () => {
const config = createAliyunSmsConfig();
config.smsAuth.provider = 'mock';
config.smsAuth.accessKeyId = '';
config.smsAuth.accessKeySecret = '';
const service = createSmsVerificationService(
config,
pino({ enabled: false }),
);
const result = await service.sendLoginCode({
e164: '+8613800138000',
nationalNumber: '13800138000',
maskedNationalNumber: '138****8000',
});
assert.equal(result.provider, 'mock');
assert.equal(result.deliveryStatus, 'delivered');
assert.equal(result.providerRequestId, 'mock-request-id');
assert.equal(result.providerOutId, 'mock-out-id');
});

View File

@@ -19,6 +19,10 @@ export type SendLoginCodeResult = {
cooldownSeconds: number;
expiresInSeconds: number;
providerRequestId: string | null;
providerBizId: string | null;
providerOutId: string | null;
provider: 'aliyun' | 'mock';
deliveryStatus: 'pending' | 'delivered';
};
export type SmsVerificationService = {
@@ -131,6 +135,10 @@ class AliyunSmsVerificationService implements SmsVerificationService {
cooldownSeconds: this.config.intervalSeconds,
expiresInSeconds: this.config.validTimeSeconds,
providerRequestId: body.requestId ?? body.model?.requestId ?? null,
providerBizId: body.model?.bizId ?? null,
providerOutId: body.model?.outId ?? null,
provider: 'aliyun',
deliveryStatus: 'pending',
} satisfies SendLoginCodeResult;
} catch (error) {
if (error instanceof Error && error.name === 'HttpError') {
@@ -240,6 +248,10 @@ class MockSmsVerificationService implements SmsVerificationService {
cooldownSeconds: this.config.intervalSeconds,
expiresInSeconds: this.config.validTimeSeconds,
providerRequestId: 'mock-request-id',
providerBizId: null,
providerOutId: 'mock-out-id',
provider: 'mock',
deliveryStatus: 'delivered',
} satisfies SendLoginCodeResult;
}