Skip to content

Commit 316200f

Browse files
committed
target sms-dev API for send sms
1 parent 66da398 commit 316200f

2 files changed

Lines changed: 15 additions & 31 deletions

File tree

functions/send-sms/__tests__/handler.test.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('send-sms handler', () => {
1515
jest.restoreAllMocks();
1616
});
1717

18-
it('sends sms_otp_code messages to the configured capture API', async () => {
18+
it('sends sms_otp_code messages to the configured sms-dev API', async () => {
1919
const result = await handler(
2020
{
2121
sms_type: 'sms_otp_code',
@@ -24,25 +24,21 @@ describe('send-sms handler', () => {
2424
},
2525
createMockContext({
2626
env: {
27-
SMS_CAPTURE_API_URL: 'http://localhost:8091',
27+
SMS_DEV_API_URL: 'http://localhost:4001',
2828
SMS_FROM: 'Constructive Test',
2929
},
3030
})
3131
);
3232

3333
expect(result).toEqual({ complete: true });
3434
expect(fetchMock).toHaveBeenCalledWith(
35-
'http://localhost:8091/messages',
35+
'http://localhost:4001/v1/messages',
3636
expect.objectContaining({
3737
method: 'POST',
3838
body: JSON.stringify({
3939
to: '+15555550101',
4040
from: 'Constructive Test',
41-
text: 'Your verification code is 123456',
42-
type: 'sms_otp_code',
43-
metadata: {
44-
userId: null,
45-
},
41+
body: 'Your verification code is 123456',
4642
}),
4743
})
4844
);
@@ -61,16 +57,12 @@ describe('send-sms handler', () => {
6157
);
6258

6359
expect(fetchMock).toHaveBeenCalledWith(
64-
'http://localhost:8091/messages',
60+
'http://localhost:4001/v1/messages',
6561
expect.objectContaining({
6662
body: JSON.stringify({
6763
to: '+15555550102',
6864
from: 'Constructive',
69-
text: 'Your verification code is 234567',
70-
type: 'mfa_verification_code',
71-
metadata: {
72-
userId: 'user-1',
73-
},
65+
body: 'Your verification code is 234567',
7466
}),
7567
})
7668
);

functions/send-sms/handler.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ type SendSmsContext = {
1818
};
1919
};
2020

21-
type SmsCapturePayload = {
21+
type SmsDevMessagePayload = {
2222
to: string;
2323
from: string;
24-
text: string;
25-
type: SmsType;
26-
metadata: {
27-
userId: string | null;
28-
};
24+
body: string;
2925
};
3026

31-
const DEFAULT_CAPTURE_API_URL = 'http://localhost:8091';
27+
const DEFAULT_SMS_DEV_API_URL = 'http://localhost:4001';
3228
const DEFAULT_SMS_FROM = 'Constructive';
3329

3430
function parseBoolean(value: string | undefined): boolean | undefined {
@@ -57,7 +53,7 @@ function normalizePhone(params: SendSmsParams): string | null {
5753
return `${params.phone_cc ?? ''}${params.phone_number}`.replace(/[\s()-]/g, '');
5854
}
5955

60-
function buildCapturePayload(params: SendSmsParams, env: SendSmsContext['env']): SmsCapturePayload {
56+
function buildSmsDevPayload(params: SendSmsParams, env: SendSmsContext['env']): SmsDevMessagePayload {
6157
if (!params.sms_type) {
6258
throw new Error('Missing required field: sms_type');
6359
}
@@ -78,16 +74,12 @@ function buildCapturePayload(params: SendSmsParams, env: SendSmsContext['env']):
7874
return {
7975
to: phone,
8076
from: env.SMS_FROM || DEFAULT_SMS_FROM,
81-
text: `Your verification code is ${params.code}`,
82-
type: params.sms_type,
83-
metadata: {
84-
userId: params.user_id ?? null,
85-
},
77+
body: `Your verification code is ${params.code}`,
8678
};
8779
}
8880

8981
async function sendSms(params: SendSmsParams, context: SendSmsContext) {
90-
const payload = buildCapturePayload(params, context.env);
82+
const payload = buildSmsDevPayload(params, context.env);
9183
const isDryRun = parseBoolean(context.env.SMS_SEND_DRY_RUN) ?? false;
9284

9385
context.log.info('[send-sms] Processing request', {
@@ -103,8 +95,8 @@ async function sendSms(params: SendSmsParams, context: SendSmsContext) {
10395
};
10496
}
10597

106-
const captureApiUrl = context.env.SMS_CAPTURE_API_URL || DEFAULT_CAPTURE_API_URL;
107-
const response = await fetch(`${captureApiUrl}/messages`, {
98+
const smsDevApiUrl = context.env.SMS_DEV_API_URL || DEFAULT_SMS_DEV_API_URL;
99+
const response = await fetch(`${smsDevApiUrl}/v1/messages`, {
108100
method: 'POST',
109101
headers: {
110102
'content-type': 'application/json',
@@ -113,7 +105,7 @@ async function sendSms(params: SendSmsParams, context: SendSmsContext) {
113105
});
114106

115107
if (!response.ok) {
116-
throw new Error(`SMS capture API error: ${response.status}`);
108+
throw new Error(`SMS dev API error: ${response.status}`);
117109
}
118110

119111
return {

0 commit comments

Comments
 (0)