stackverify
Advanced tools
+82
| # StackVerify SDK | ||
| A simple Node.js SDK to interact with the StackVerify API for sending SMS and checking message status. | ||
| ## Installation | ||
| ```bash | ||
| npm install stackverify | ||
| ``` | ||
| # Usage | ||
| Get your apikey . | ||
| - [@stackverify](https://stackverify.site) | ||
| ``` | ||
| import StackVerify from "stackverify"; | ||
| // Initialize the SDK | ||
| const stack = new StackVerify({ apiKey: "YOUR_API_KEY" }); | ||
| // Send an SMS and check status | ||
| async function main() { | ||
| try { | ||
| const response = await stack.sendSMS({ | ||
| recipients: ["+1234567890"], // array of phone numbers | ||
| body: "Hello! This is a test message.", | ||
| sender_id: "SMS" | ||
| }); | ||
| console.log("SMS sent:", response); | ||
| const status = await stack.getSMSStatus(response.message_id); | ||
| console.log("SMS status:", status); | ||
| } catch (err) { | ||
| console.error("Error:", err.message); | ||
| } | ||
| } | ||
| main(); | ||
| ``` | ||
| # Api | ||
| new StackVerify({ apiKey, baseUrl }) | ||
| apiKey (string) — Your StackVerify API key (required) | ||
| baseUrl (string) — API base URL (default: https://stackverify.site/api/v1) | ||
| sendSMS({ recipients, body, sender_id }) | ||
| Send an SMS. | ||
| recipients — array of phone numbers (required) | ||
| body — SMS message text (required) | ||
| sender_id — your sender ID (required) | ||
| getSMSStatus(messageId) | ||
| Get the status of a sent message. | ||
| messageId — ID returned by sendSMS (required) | ||
| ## Badges | ||
| [](https://choosealicense.com/licenses/mit/) | ||
| [](https://opensource.org/licenses/) | ||
| [](http://www.gnu.org/licenses/agpl-3.0) | ||
| ## Authors | ||
| - [@morgan miller](https://www.github.com/Frost-bit-star) | ||
| - [@samwuel simiyu](https://github.com/Trojan-254) | ||
| ## 🔗 Links | ||
| [](https://www.linkedin.com/) | ||
| [](https://twitter.com/) | ||
+1
-1
| { | ||
| "name": "stackverify", | ||
| "version": "1.0.3", | ||
| "version": "2.0.0", | ||
| "description": "Node.js SDK for StackVerify API (SMS, Email, WhatsApp)", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+47
-8
@@ -6,4 +6,6 @@ import fetch from "node-fetch"; | ||
| if (!apiKey) throw new Error("API key is required"); | ||
| this.apiKey = apiKey; | ||
| this.baseUrl = baseUrl.replace(/\/+$/, ""); | ||
| this.mode = apiKey.startsWith("sk_test_") ? "test" : "live"; | ||
| } | ||
@@ -20,22 +22,59 @@ | ||
| const text = await res.text().catch(() => null); | ||
| let data; | ||
| try { | ||
| data = await res.json(); | ||
| } catch { | ||
| data = null; | ||
| } | ||
| if (!res.ok) throw new Error(`StackVerify SDK Error: ${text || res.status}`); | ||
| try { return JSON.parse(text); } catch { return text; } | ||
| if (!res.ok) { | ||
| const error = new Error(data?.message || "StackVerify API Error"); | ||
| error.status = res.status; | ||
| error.error = data?.error || null; | ||
| error.retry_after = data?.retry_after || null; | ||
| throw error; | ||
| } | ||
| return data; | ||
| } | ||
| async sendSMS({ recipients, body, sender_id }) { | ||
| if (!recipients || !Array.isArray(recipients) || recipients.length === 0) | ||
| /** | ||
| * Send SMS | ||
| * Required permission: sms:send | ||
| */ | ||
| async sendSMS({ | ||
| recipients, | ||
| body, | ||
| sender_id, | ||
| templateId, | ||
| scheduleAt, | ||
| }) { | ||
| if (!Array.isArray(recipients) || recipients.length === 0) | ||
| throw new Error("recipients must be a non-empty array"); | ||
| if (!body) throw new Error("body is required"); | ||
| if (!sender_id) throw new Error("sender_id is required"); | ||
| if (!body && !templateId) | ||
| throw new Error("Either body or templateId is required"); | ||
| if (!sender_id) | ||
| throw new Error("sender_id is required"); | ||
| return this._request("/sms/send", { | ||
| method: "POST", | ||
| body: JSON.stringify({ recipients, body, sender_id }), | ||
| body: JSON.stringify({ | ||
| recipients, | ||
| body, | ||
| sender_id, | ||
| templateId, | ||
| scheduleAt, | ||
| }), | ||
| }); | ||
| } | ||
| /** | ||
| * Get SMS Status | ||
| * Required permission: sms:read | ||
| */ | ||
| async getSMSStatus(messageId) { | ||
| if (!messageId) throw new Error("messageId is required"); | ||
| return this._request(`/sms/status/${encodeURIComponent(messageId)}`); | ||
@@ -42,0 +81,0 @@ } |
| # StackVerify SDK | ||
| A simple Node.js SDK to interact with the StackVerify API for sending SMS and checking message status. | ||
| ## Installation | ||
| ```bash | ||
| npm install stackverify | ||
| ``` | ||
| # Usage | ||
| ``` | ||
| import StackVerify from "stackverify"; | ||
| // Initialize the SDK | ||
| const stack = new StackVerify({ apiKey: "YOUR_API_KEY" }); | ||
| // Send an SMS and check status | ||
| async function main() { | ||
| try { | ||
| const response = await stack.sendSMS({ | ||
| recipients: ["+1234567890"], // array of phone numbers | ||
| body: "Hello! This is a test message.", | ||
| sender_id: "SMS" | ||
| }); | ||
| console.log("SMS sent:", response); | ||
| const status = await stack.getSMSStatus(response.message_id); | ||
| console.log("SMS status:", status); | ||
| } catch (err) { | ||
| console.error("Error:", err.message); | ||
| } | ||
| } | ||
| main(); | ||
| ``` | ||
| # Api | ||
| new StackVerify({ apiKey, baseUrl }) | ||
| apiKey (string) — Your StackVerify API key (required) | ||
| baseUrl (string) — API base URL (default: https://stackverify.site/api/v1) | ||
| sendSMS({ recipients, body, sender_id }) | ||
| Send an SMS. | ||
| recipients — array of phone numbers (required) | ||
| body — SMS message text (required) | ||
| sender_id — your sender ID (required) | ||
| getSMSStatus(messageId) | ||
| Get the status of a sent message. | ||
| messageId — ID returned by sendSMS (required) | ||
| ## Badges | ||
| [](https://choosealicense.com/licenses/mit/) | ||
| [](https://opensource.org/licenses/) | ||
| [](http://www.gnu.org/licenses/agpl-3.0) | ||
| ## Authors | ||
| - [@morgan miller](https://www.github.com/Frost-bit-star) | ||
| - [@samwuel simiyu](https://github.com/Trojan-254) | ||
| ## 🔗 Links | ||
| [](https://stackverify.site/) | ||
| [](https://www.linkedin.com/) | ||
| [](https://twitter.com/) | ||
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
5583
9.41%69
97.14%83
3.75%