Skip to content

Commit 4cff39f

Browse files
committed
refactor: allow custom SMS provider names
1 parent 7c96378 commit 4cff39f

5 files changed

Lines changed: 13 additions & 16 deletions

File tree

graphql/env/__tests__/merge.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ describe('getEnvOptions', () => {
161161
});
162162
});
163163

164+
it('accepts custom SMS provider names', () => {
165+
const result = getGraphQLEnvVars({
166+
SMS_PROVIDER: 'custom-sms-gateway'
167+
});
168+
169+
expect(result.sms?.provider).toBe('custom-sms-gateway');
170+
});
171+
164172
it('honors defaults, config, env, and runtime override priority for SMS', () => {
165173
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'graphql-env-sms-'));
166174
writeConfig(tempDir, {

graphql/env/src/env.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ConstructiveOptions, SmsProviderName } from '@constructive-io/graphql-types';
1+
import type { ConstructiveOptions } from '@constructive-io/graphql-types';
22

33
/**
44
* Parse GraphQL-related environment variables.
@@ -22,14 +22,6 @@ const parseEnvInteger = (name: string, val?: string): number | undefined => {
2222
return parsed;
2323
};
2424

25-
const parseSmsProvider = (val?: string): SmsProviderName | undefined => {
26-
if (val === undefined) return undefined;
27-
if (val === 'devsms' || val === 'twilio' || val === 'sns') {
28-
return val;
29-
}
30-
throw new Error('SMS_PROVIDER must be one of: devsms, twilio, sns');
31-
};
32-
3325
/**
3426
* @param env - Environment object to read from (defaults to process.env for backwards compatibility)
3527
*/
@@ -105,7 +97,7 @@ export const getGraphQLEnvVars = (env: NodeJS.ProcessEnv = process.env): Partial
10597
}),
10698
...((SMS_PROVIDER || SMS_SENDER_ID || SMS_REQUEST_TIMEOUT_MS || SEND_SMS_DRY_RUN || DEVSMS_BASE_URL) && {
10799
sms: {
108-
...(SMS_PROVIDER && { provider: parseSmsProvider(SMS_PROVIDER) }),
100+
...(SMS_PROVIDER && { provider: SMS_PROVIDER }),
109101
...(SMS_SENDER_ID && { senderId: SMS_SENDER_ID }),
110102
...(SMS_REQUEST_TIMEOUT_MS && {
111103
requestTimeoutMs: parseEnvInteger('SMS_REQUEST_TIMEOUT_MS', SMS_REQUEST_TIMEOUT_MS)

graphql/env/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Export Constructive-specific env functions
22
export { getEnvOptions, getConstructiveEnvOptions } from './merge';
33
export { getGraphQLEnvVars } from './env';
4-
export type { DevSmsOptions, SmsOptions, SmsProviderName } from '@constructive-io/graphql-types';
4+
export type { DevSmsOptions, SmsOptions } from '@constructive-io/graphql-types';

graphql/types/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export {
3232

3333
// Export SMS types
3434
export {
35-
SmsProviderName,
3635
SmsOptions,
3736
DevSmsOptions,
3837
smsDefaults

graphql/types/src/sms.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
* packages decide which providers they implement and validate that required
66
* provider-specific values are present before sending.
77
*/
8-
export type SmsProviderName = 'devsms' | 'twilio' | 'sns';
9-
108
export interface DevSmsOptions {
119
/** Base URL for the local DevSms API, e.g. http://localhost:4000 */
1210
baseUrl?: string;
1311
}
1412

1513
export interface SmsOptions {
16-
/** SMS provider implementation to use. */
17-
provider?: SmsProviderName;
14+
/** SMS provider implementation to use; runtimes may register custom names. */
15+
provider?: string;
1816
/** Optional sender ID/default source address for providers that support it. */
1917
senderId?: string;
2018
/** Outbound provider HTTP timeout in milliseconds. */

0 commit comments

Comments
 (0)