@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 +133 -0
- package/dist/index.d.ts +140 -0
- package/dist/index.js +457 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/console.d.ts +65 -0
- package/dist/providers/console.js +77 -0
- package/dist/providers/console.js.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.js +284 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/netgsm.d.ts +89 -0
- package/dist/providers/netgsm.js +210 -0
- package/dist/providers/netgsm.js.map +1 -0
- package/dist/types.d.ts +116 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/package.json +65 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @parsrun/sms - Type definitions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Supported SMS provider types
|
|
6
|
+
*/
|
|
7
|
+
type SMSProviderType = "netgsm" | "twilio" | "console";
|
|
8
|
+
/**
|
|
9
|
+
* SMS send options
|
|
10
|
+
*/
|
|
11
|
+
interface SMSOptions {
|
|
12
|
+
/** Recipient phone number (international format recommended, e.g., 905xxxxxxxxx) */
|
|
13
|
+
to: string;
|
|
14
|
+
/** SMS message content */
|
|
15
|
+
message: string;
|
|
16
|
+
/** Optional sender ID override */
|
|
17
|
+
from?: string;
|
|
18
|
+
/** Optional metadata/tags */
|
|
19
|
+
tags?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* SMS send result
|
|
23
|
+
*/
|
|
24
|
+
interface SMSResult {
|
|
25
|
+
/** Whether the SMS was sent successfully */
|
|
26
|
+
success: boolean;
|
|
27
|
+
/** Provider-specific message ID */
|
|
28
|
+
messageId?: string;
|
|
29
|
+
/** Error message if send failed */
|
|
30
|
+
error?: string;
|
|
31
|
+
/** Raw provider response data */
|
|
32
|
+
data?: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Batch SMS options
|
|
36
|
+
*/
|
|
37
|
+
interface BatchSMSOptions {
|
|
38
|
+
/** Array of SMS messages to send */
|
|
39
|
+
messages: SMSOptions[];
|
|
40
|
+
/** Stop sending if an error occurs */
|
|
41
|
+
stopOnError?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Batch SMS result
|
|
45
|
+
*/
|
|
46
|
+
interface BatchSMSResult {
|
|
47
|
+
/** Total number of messages attempted */
|
|
48
|
+
total: number;
|
|
49
|
+
/** Number of successfully sent messages */
|
|
50
|
+
successful: number;
|
|
51
|
+
/** Number of failed messages */
|
|
52
|
+
failed: number;
|
|
53
|
+
/** Individual results for each message */
|
|
54
|
+
results: SMSResult[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* SMS provider configuration
|
|
58
|
+
*/
|
|
59
|
+
interface SMSProviderConfig {
|
|
60
|
+
/** API key or authentication token */
|
|
61
|
+
apiKey?: string;
|
|
62
|
+
/** Provider username (for providers like NetGSM) */
|
|
63
|
+
username?: string;
|
|
64
|
+
/** Provider password (for providers like NetGSM) */
|
|
65
|
+
password?: string;
|
|
66
|
+
/** Default sender ID/header */
|
|
67
|
+
from?: string;
|
|
68
|
+
/** Provider-specific options */
|
|
69
|
+
options?: Record<string, unknown>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* SMS service configuration
|
|
73
|
+
*/
|
|
74
|
+
interface SMSServiceConfig extends SMSProviderConfig {
|
|
75
|
+
/** SMS provider type */
|
|
76
|
+
provider: SMSProviderType;
|
|
77
|
+
/** Provider API URL (for custom endpoints) */
|
|
78
|
+
providerUrl?: string;
|
|
79
|
+
/** Enable debug logging */
|
|
80
|
+
debug?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* SMS provider interface
|
|
84
|
+
*/
|
|
85
|
+
interface SMSProvider {
|
|
86
|
+
/** Provider type identifier */
|
|
87
|
+
readonly type: SMSProviderType;
|
|
88
|
+
/** Send a single SMS */
|
|
89
|
+
send(options: SMSOptions): Promise<SMSResult>;
|
|
90
|
+
/** Send multiple SMS messages (optional) */
|
|
91
|
+
sendBatch?(options: BatchSMSOptions): Promise<BatchSMSResult>;
|
|
92
|
+
/** Verify provider configuration (optional) */
|
|
93
|
+
verify?(): Promise<boolean>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* SMS error codes
|
|
97
|
+
*/
|
|
98
|
+
declare const SMSErrorCodes: {
|
|
99
|
+
readonly INVALID_CONFIG: "SMS_INVALID_CONFIG";
|
|
100
|
+
readonly SEND_FAILED: "SMS_SEND_FAILED";
|
|
101
|
+
readonly INVALID_PHONE: "SMS_INVALID_PHONE";
|
|
102
|
+
readonly RATE_LIMITED: "SMS_RATE_LIMITED";
|
|
103
|
+
readonly INSUFFICIENT_BALANCE: "SMS_INSUFFICIENT_BALANCE";
|
|
104
|
+
readonly PROVIDER_ERROR: "SMS_PROVIDER_ERROR";
|
|
105
|
+
};
|
|
106
|
+
type SMSErrorCode = (typeof SMSErrorCodes)[keyof typeof SMSErrorCodes];
|
|
107
|
+
/**
|
|
108
|
+
* SMS error class
|
|
109
|
+
*/
|
|
110
|
+
declare class SMSError extends Error {
|
|
111
|
+
code: SMSErrorCode;
|
|
112
|
+
cause?: unknown;
|
|
113
|
+
constructor(message: string, code: SMSErrorCode, cause?: unknown);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { type BatchSMSOptions, type BatchSMSResult, SMSError, type SMSErrorCode, SMSErrorCodes, type SMSOptions, type SMSProvider, type SMSProviderConfig, type SMSProviderType, type SMSResult, type SMSServiceConfig };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var SMSErrorCodes = {
|
|
3
|
+
INVALID_CONFIG: "SMS_INVALID_CONFIG",
|
|
4
|
+
SEND_FAILED: "SMS_SEND_FAILED",
|
|
5
|
+
INVALID_PHONE: "SMS_INVALID_PHONE",
|
|
6
|
+
RATE_LIMITED: "SMS_RATE_LIMITED",
|
|
7
|
+
INSUFFICIENT_BALANCE: "SMS_INSUFFICIENT_BALANCE",
|
|
8
|
+
PROVIDER_ERROR: "SMS_PROVIDER_ERROR"
|
|
9
|
+
};
|
|
10
|
+
var SMSError = class extends Error {
|
|
11
|
+
code;
|
|
12
|
+
cause;
|
|
13
|
+
constructor(message, code, cause) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "SMSError";
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.cause = cause;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { SMSError, SMSErrorCodes };
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
23
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"names":[],"mappings":";AA6GO,IAAM,aAAA,GAAgB;AAAA,EAC3B,cAAA,EAAgB,oBAAA;AAAA,EAChB,WAAA,EAAa,iBAAA;AAAA,EACb,aAAA,EAAe,mBAAA;AAAA,EACf,YAAA,EAAc,kBAAA;AAAA,EACd,oBAAA,EAAsB,0BAAA;AAAA,EACtB,cAAA,EAAgB;AAClB;AAOO,IAAM,QAAA,GAAN,cAAuB,KAAA,CAAM;AAAA,EAClC,IAAA;AAAA,EACA,KAAA;AAAA,EAEA,WAAA,CAAY,OAAA,EAAiB,IAAA,EAAoB,KAAA,EAAiB;AAChE,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,UAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AACF","file":"types.js","sourcesContent":["/**\n * @parsrun/sms - Type definitions\n */\n\n/**\n * Supported SMS provider types\n */\nexport type SMSProviderType = \"netgsm\" | \"twilio\" | \"console\";\n\n/**\n * SMS send options\n */\nexport interface SMSOptions {\n /** Recipient phone number (international format recommended, e.g., 905xxxxxxxxx) */\n to: string;\n /** SMS message content */\n message: string;\n /** Optional sender ID override */\n from?: string;\n /** Optional metadata/tags */\n tags?: Record<string, string>;\n}\n\n/**\n * SMS send result\n */\nexport interface SMSResult {\n /** Whether the SMS was sent successfully */\n success: boolean;\n /** Provider-specific message ID */\n messageId?: string;\n /** Error message if send failed */\n error?: string;\n /** Raw provider response data */\n data?: unknown;\n}\n\n/**\n * Batch SMS options\n */\nexport interface BatchSMSOptions {\n /** Array of SMS messages to send */\n messages: SMSOptions[];\n /** Stop sending if an error occurs */\n stopOnError?: boolean;\n}\n\n/**\n * Batch SMS result\n */\nexport interface BatchSMSResult {\n /** Total number of messages attempted */\n total: number;\n /** Number of successfully sent messages */\n successful: number;\n /** Number of failed messages */\n failed: number;\n /** Individual results for each message */\n results: SMSResult[];\n}\n\n/**\n * SMS provider configuration\n */\nexport interface SMSProviderConfig {\n /** API key or authentication token */\n apiKey?: string;\n /** Provider username (for providers like NetGSM) */\n username?: string;\n /** Provider password (for providers like NetGSM) */\n password?: string;\n /** Default sender ID/header */\n from?: string;\n /** Provider-specific options */\n options?: Record<string, unknown>;\n}\n\n/**\n * SMS service configuration\n */\nexport interface SMSServiceConfig extends SMSProviderConfig {\n /** SMS provider type */\n provider: SMSProviderType;\n /** Provider API URL (for custom endpoints) */\n providerUrl?: string;\n /** Enable debug logging */\n debug?: boolean;\n}\n\n/**\n * SMS provider interface\n */\nexport interface SMSProvider {\n /** Provider type identifier */\n readonly type: SMSProviderType;\n\n /** Send a single SMS */\n send(options: SMSOptions): Promise<SMSResult>;\n\n /** Send multiple SMS messages (optional) */\n sendBatch?(options: BatchSMSOptions): Promise<BatchSMSResult>;\n\n /** Verify provider configuration (optional) */\n verify?(): Promise<boolean>;\n}\n\n/**\n * SMS error codes\n */\nexport const SMSErrorCodes = {\n INVALID_CONFIG: \"SMS_INVALID_CONFIG\",\n SEND_FAILED: \"SMS_SEND_FAILED\",\n INVALID_PHONE: \"SMS_INVALID_PHONE\",\n RATE_LIMITED: \"SMS_RATE_LIMITED\",\n INSUFFICIENT_BALANCE: \"SMS_INSUFFICIENT_BALANCE\",\n PROVIDER_ERROR: \"SMS_PROVIDER_ERROR\",\n} as const;\n\nexport type SMSErrorCode = (typeof SMSErrorCodes)[keyof typeof SMSErrorCodes];\n\n/**\n * SMS error class\n */\nexport class SMSError extends Error {\n code: SMSErrorCode;\n cause?: unknown;\n\n constructor(message: string, code: SMSErrorCode, cause?: unknown) {\n super(message);\n this.name = \"SMSError\";\n this.code = code;\n this.cause = cause;\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@parsrun/sms",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Edge-compatible SMS sending for Pars - NetGSM, Twilio, and more",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./types": {
|
|
15
|
+
"types": "./dist/types.d.ts",
|
|
16
|
+
"import": "./dist/types.js"
|
|
17
|
+
},
|
|
18
|
+
"./providers": {
|
|
19
|
+
"types": "./dist/providers/index.d.ts",
|
|
20
|
+
"import": "./dist/providers/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./providers/netgsm": {
|
|
23
|
+
"types": "./dist/providers/netgsm.d.ts",
|
|
24
|
+
"import": "./dist/providers/netgsm.js"
|
|
25
|
+
},
|
|
26
|
+
"./providers/console": {
|
|
27
|
+
"types": "./dist/providers/console.d.ts",
|
|
28
|
+
"import": "./dist/providers/console.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"dev": "tsup --watch",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"typecheck": "tsc --noEmit"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"sms",
|
|
43
|
+
"netgsm",
|
|
44
|
+
"twilio",
|
|
45
|
+
"edge",
|
|
46
|
+
"pars"
|
|
47
|
+
],
|
|
48
|
+
"author": "EMS Tech Solutions",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"homepage": "https://pars.run",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/parsrun/pars",
|
|
54
|
+
"directory": "packages/sms"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@parsrun/core": "workspace:*",
|
|
58
|
+
"@parsrun/types": "workspace:*"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"tsup": "^8.3.5",
|
|
62
|
+
"typescript": "^5.7.2",
|
|
63
|
+
"vitest": "^2.1.8"
|
|
64
|
+
}
|
|
65
|
+
}
|