@parsrun/sms 0.2.1

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/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # @parsrun/sms
2
+
3
+ Edge-compatible SMS sending for Pars applications.
4
+
5
+ ## Features
6
+
7
+ - ๐ŸŒ **Edge Compatible** - Works in Cloudflare Workers, Vercel Edge, Deno, Bun
8
+ - ๐Ÿ“ฑ **Multiple Providers** - NetGSM (Turkey), with Twilio coming soon
9
+ - ๐Ÿ”ง **TypeScript First** - Full type definitions included
10
+ - ๐Ÿงช **Dev Mode** - Console provider for local development
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @parsrun/sms
16
+ # or
17
+ bun add @parsrun/sms
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ```typescript
23
+ import { createSMSService } from '@parsrun/sms';
24
+
25
+ // Create SMS service with NetGSM
26
+ const sms = createSMSService({
27
+ provider: 'netgsm',
28
+ username: process.env.NETGSM_USERNAME,
29
+ password: process.env.NETGSM_PASSWORD,
30
+ from: 'MYSENDER', // Sender ID registered with NetGSM
31
+ });
32
+
33
+ // Send a single SMS
34
+ await sms.send({
35
+ to: '905551234567',
36
+ message: 'Hello from Pars!',
37
+ });
38
+
39
+ // Send OTP
40
+ await sms.sendOTP('905551234567', '123456', 10);
41
+
42
+ // Send welcome message
43
+ await sms.sendWelcome('905551234567', 'John');
44
+ ```
45
+
46
+ ## Providers
47
+
48
+ ### NetGSM (Turkey)
49
+
50
+ ```typescript
51
+ import { createSMSService } from '@parsrun/sms';
52
+
53
+ const sms = createSMSService({
54
+ provider: 'netgsm',
55
+ username: 'your-username',
56
+ password: 'your-password',
57
+ from: 'SENDER_ID',
58
+ // Optional custom API URL
59
+ providerUrl: 'https://api.netgsm.com.tr/sms/send/otp',
60
+ });
61
+ ```
62
+
63
+ ### Console (Development)
64
+
65
+ ```typescript
66
+ import { createSMSService } from '@parsrun/sms';
67
+
68
+ const sms = createSMSService({
69
+ provider: 'console',
70
+ from: 'TEST',
71
+ });
72
+
73
+ // SMS will be logged to console instead of being sent
74
+ await sms.send({
75
+ to: '905551234567',
76
+ message: 'Test message',
77
+ });
78
+ ```
79
+
80
+ ## Environment Variables
81
+
82
+ ```bash
83
+ # NetGSM
84
+ NETGSM_USERNAME=your-username
85
+ NETGSM_PASSWORD=your-password
86
+ NETGSM_SENDER=MYSENDER
87
+ NETGSM_URL=https://api.netgsm.com.tr/sms/send/otp
88
+ ```
89
+
90
+ ## API Reference
91
+
92
+ ### SMSService
93
+
94
+ ```typescript
95
+ class SMSService {
96
+ // Send a single SMS
97
+ send(options: SMSOptions): Promise<SMSResult>;
98
+
99
+ // Send multiple SMS messages
100
+ sendBatch(options: BatchSMSOptions): Promise<BatchSMSResult>;
101
+
102
+ // Verify provider configuration
103
+ verify(): Promise<boolean>;
104
+
105
+ // Send OTP verification SMS
106
+ sendOTP(phone: string, code: string, expiresInMinutes?: number): Promise<SMSResult>;
107
+
108
+ // Send welcome SMS
109
+ sendWelcome(phone: string, name?: string): Promise<SMSResult>;
110
+ }
111
+ ```
112
+
113
+ ### Types
114
+
115
+ ```typescript
116
+ interface SMSOptions {
117
+ to: string; // Recipient phone number
118
+ message: string; // SMS content
119
+ from?: string; // Sender ID override
120
+ tags?: Record<string, string>;
121
+ }
122
+
123
+ interface SMSResult {
124
+ success: boolean;
125
+ messageId?: string;
126
+ error?: string;
127
+ data?: unknown;
128
+ }
129
+ ```
130
+
131
+ ## License
132
+
133
+ MIT
@@ -0,0 +1,140 @@
1
+ import { SMSServiceConfig, SMSProviderType, SMSOptions, SMSResult, BatchSMSOptions, BatchSMSResult, SMSProviderConfig, SMSProvider } from './types.js';
2
+ export { SMSError, SMSErrorCode, SMSErrorCodes } from './types.js';
3
+ export { NetGSMProvider, createNetGSMProvider } from './providers/netgsm.js';
4
+ export { ConsoleProvider, createConsoleProvider } from './providers/console.js';
5
+
6
+ /**
7
+ * @module
8
+ * Edge-compatible SMS sending for Pars.
9
+ *
10
+ * Supports multiple providers:
11
+ * - NetGSM (Turkey)
12
+ * - Console (development)
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { createSMSService } from '@parsrun/sms';
17
+ *
18
+ * const sms = createSMSService({
19
+ * provider: 'netgsm',
20
+ * username: process.env.NETGSM_USERNAME,
21
+ * password: process.env.NETGSM_PASSWORD,
22
+ * from: 'MYSENDER',
23
+ * });
24
+ *
25
+ * await sms.send({
26
+ * to: '905551234567',
27
+ * message: 'Your verification code is: 123456',
28
+ * });
29
+ * ```
30
+ */
31
+
32
+ /**
33
+ * SMS Service
34
+ *
35
+ * High-level SMS service that provides a unified interface for sending SMS
36
+ * through various providers (NetGSM, Twilio, or Console for development).
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const service = new SMSService({
41
+ * provider: 'netgsm',
42
+ * username: 'your-username',
43
+ * password: 'your-password',
44
+ * from: 'MYSENDER',
45
+ * });
46
+ *
47
+ * await service.send({
48
+ * to: '905551234567',
49
+ * message: 'Hello!',
50
+ * });
51
+ * ```
52
+ */
53
+ declare class SMSService {
54
+ private provider;
55
+ private debug;
56
+ /**
57
+ * Creates a new SMSService instance.
58
+ *
59
+ * @param config - The SMS service configuration
60
+ */
61
+ constructor(config: SMSServiceConfig);
62
+ private createProvider;
63
+ /**
64
+ * Gets the type of SMS provider being used.
65
+ */
66
+ get providerType(): SMSProviderType;
67
+ /**
68
+ * Sends a single SMS message.
69
+ *
70
+ * @param options - The SMS options
71
+ * @returns A promise that resolves to the send result
72
+ */
73
+ send(options: SMSOptions): Promise<SMSResult>;
74
+ /**
75
+ * Sends multiple SMS messages in a batch.
76
+ *
77
+ * @param options - The batch SMS options
78
+ * @returns A promise that resolves to the batch result
79
+ */
80
+ sendBatch(options: BatchSMSOptions): Promise<BatchSMSResult>;
81
+ /**
82
+ * Verifies the provider configuration.
83
+ *
84
+ * @returns A promise that resolves to true if configuration is valid
85
+ */
86
+ verify(): Promise<boolean>;
87
+ /**
88
+ * Send OTP verification SMS
89
+ *
90
+ * @param phone - Recipient phone number
91
+ * @param code - OTP code
92
+ * @param expiresInMinutes - Code expiration time
93
+ */
94
+ sendOTP(phone: string, code: string, expiresInMinutes?: number): Promise<SMSResult>;
95
+ /**
96
+ * Send welcome SMS
97
+ *
98
+ * @param phone - Recipient phone number
99
+ * @param name - User's display name
100
+ */
101
+ sendWelcome(phone: string, name?: string): Promise<SMSResult>;
102
+ }
103
+ /**
104
+ * Create an SMS service
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * // With NetGSM
109
+ * const sms = createSMSService({
110
+ * provider: 'netgsm',
111
+ * username: process.env.NETGSM_USERNAME,
112
+ * password: process.env.NETGSM_PASSWORD,
113
+ * from: 'MYSENDER',
114
+ * });
115
+ *
116
+ * // For development
117
+ * const sms = createSMSService({
118
+ * provider: 'console',
119
+ * from: 'TEST',
120
+ * });
121
+ * ```
122
+ */
123
+ declare function createSMSService(config: SMSServiceConfig): SMSService;
124
+ /**
125
+ * Creates an SMS provider instance directly.
126
+ *
127
+ * @param type - The type of SMS provider to create
128
+ * @param config - The provider configuration
129
+ * @returns A new SMS provider instance
130
+ */
131
+ declare function createSMSProvider(type: SMSProviderType, config: SMSProviderConfig & {
132
+ providerUrl?: string;
133
+ }): SMSProvider;
134
+ declare const _default: {
135
+ SMSService: typeof SMSService;
136
+ createSMSService: typeof createSMSService;
137
+ createSMSProvider: typeof createSMSProvider;
138
+ };
139
+
140
+ export { BatchSMSOptions, BatchSMSResult, SMSOptions, SMSProvider, SMSProviderConfig, SMSProviderType, SMSResult, SMSService, SMSServiceConfig, createSMSProvider, createSMSService, _default as default };