farazsms 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FarazSMS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # farazsms
2
+
3
+ Official lightweight client for the [FarazSMS](https://api.iranpayamak.com) web services — send pattern/OTP, simple & bulk SMS, pull reports, manage your phonebook, and reach **all 63 endpoints** through a low-level `request()`.
4
+
5
+ Zero dependencies. Works on **Node.js 18+** (built-in `fetch`), ESM **and** CommonJS, with TypeScript types.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install farazsms
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```js
16
+ import FarazSMS from "farazsms"; // ESM
17
+ // const FarazSMS = require("farazsms"); // CommonJS
18
+
19
+ const sms = new FarazSMS("YOUR_API_KEY"); // key from the FarazSMS panel → Web Service / API Key
20
+
21
+ console.log(await sms.balance()); // verify the key — free
22
+ await sms.sendPattern("SJ3FgPrE0C", "09120000000", { code: "1234" }); // OTP (instant, never queued)
23
+ await sms.sendSimple("Hello!", ["09120000000", "09130000000"]); // bulk
24
+ console.log(await sms.inbox(1, 20)); // inbound replies
25
+ ```
26
+
27
+ > Recipients use the local format `09120000000` (no `+98`). The default sender line is `90008361`.
28
+
29
+ ## Error handling
30
+
31
+ The client throws a `FarazError` whenever the API returns `{ status: "error" }`, so you don't have to check manually:
32
+
33
+ ```js
34
+ import { FarazError } from "farazsms";
35
+ try {
36
+ await sms.sendPattern("BAD_CODE", "09120000000", { code: "1" });
37
+ } catch (e) {
38
+ if (e instanceof FarazError) console.error(e.status, e.body);
39
+ }
40
+ ```
41
+
42
+ ## Bundled helpers
43
+
44
+ | Area | Methods |
45
+ |------|---------|
46
+ | Account | `balance()` · `profile()` · `lines()` |
47
+ | Send | `sendPattern()` · `sendSimple()` · `sendVariable()` |
48
+ | Patterns | `createPattern()` · `patterns()` |
49
+ | Reports | `inbox()` · `sendRequests()` · `sendRequestItems()` |
50
+ | Phonebook | `phonebooks()` · `addContact()` |
51
+ | Reference | `provinces()` · `numberBanks()` |
52
+
53
+ **Anything else** (tickets, orders, voice, LBS, …) is reachable via the low-level call:
54
+
55
+ ```js
56
+ await sms.request("POST", "/ws/v1/ticket", { department: 1, subject: "Hi" });
57
+ ```
58
+
59
+ ## License
60
+
61
+ MIT
package/index.cjs ADDED
@@ -0,0 +1,73 @@
1
+ // FarazSMS — official lightweight client (CommonJS). Node 18+ (built-in fetch).
2
+ "use strict";
3
+ const BASE = "https://api.iranpayamak.com";
4
+
5
+ class FarazError extends Error {
6
+ constructor(status, body) {
7
+ super("[" + status + "] " + (typeof body === "string" ? body : JSON.stringify(body)));
8
+ this.name = "FarazError";
9
+ this.status = status;
10
+ this.body = body;
11
+ }
12
+ }
13
+
14
+ class FarazSMS {
15
+ constructor(apiKey, baseUrl = BASE) {
16
+ if (!apiKey) throw new Error("FarazSMS: apiKey is required");
17
+ this.base = String(baseUrl).replace(/\/$/, "");
18
+ this.key = apiKey;
19
+ }
20
+
21
+ // low-level — reaches every one of the 63 endpoints
22
+ async request(method, path, body = null, query = null) {
23
+ const url = new URL(this.base + path);
24
+ if (query) for (const k in query) if (query[k] != null) url.searchParams.set(k, query[k]);
25
+ const res = await fetch(url, {
26
+ method,
27
+ headers: {
28
+ "Api-Key": this.key,
29
+ "Accept": "application/json",
30
+ ...(body ? { "Content-Type": "application/json" } : {}),
31
+ },
32
+ body: body ? JSON.stringify(body) : undefined,
33
+ });
34
+ const data = await res.json().catch(() => ({}));
35
+ if (data && data.status === "error") throw new FarazError(res.status, data.message != null ? data.message : data);
36
+ return data;
37
+ }
38
+
39
+ balance() { return this.request("GET", "/ws/v1/account/balance"); }
40
+ profile() { return this.request("GET", "/ws/v1/account/profile"); }
41
+ lines() { return this.request("GET", "/ws/v1/lines/accessible"); }
42
+
43
+ sendPattern(code, recipient, attributes, line = "90008361") {
44
+ return this.request("POST", "/ws/v1/sms/pattern",
45
+ { code, recipient, attributes, line_number: line, number_format: "english" });
46
+ }
47
+ sendSimple(text, recipients, line = "90008361") {
48
+ return this.request("POST", "/ws/v1/sms/simple",
49
+ { text, recipients, line_number: line, number_format: "english" });
50
+ }
51
+ sendVariable(text, recipients, line = "90008361") {
52
+ return this.request("POST", "/ws/v1/sms/keywords",
53
+ { text, recipients, line_number: line, number_format: "english" });
54
+ }
55
+
56
+ createPattern(payload) { return this.request("POST", "/ws/v1/patterns", payload); }
57
+ patterns(query = {}) { return this.request("GET", "/ws/v1/patterns", null, query); }
58
+
59
+ inbox(page = 1, limit = 20) { return this.request("GET", "/ws/v1/inbox", null, { page, limit }); }
60
+ sendRequests(query = {}) { return this.request("GET", "/ws/v1/send_request", null, query); }
61
+ sendRequestItems(id, query = {}) { return this.request("GET", "/ws/v1/send_request/" + id + "/items", null, query); }
62
+
63
+ phonebooks() { return this.request("GET", "/ws/v1/phone_book"); }
64
+ addContact(payload) { return this.request("POST", "/ws/v1/phone_book_data", payload); }
65
+
66
+ provinces(query = {}) { return this.request("GET", "/provinces", null, query); }
67
+ numberBanks(query = {}) { return this.request("GET", "/ws/v1/number_bank", null, query); }
68
+ }
69
+
70
+ module.exports = FarazSMS;
71
+ module.exports.FarazSMS = FarazSMS;
72
+ module.exports.FarazError = FarazError;
73
+ module.exports.default = FarazSMS;
package/index.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ // Type definitions for the FarazSMS client.
2
+ export type Json = any;
3
+ export type Query = Record<string, string | number | boolean | null | undefined>;
4
+
5
+ export class FarazError extends Error {
6
+ status: number;
7
+ body: Json;
8
+ constructor(status: number, body: Json);
9
+ }
10
+
11
+ export class FarazSMS {
12
+ base: string;
13
+ key: string;
14
+ constructor(apiKey: string, baseUrl?: string);
15
+
16
+ /** Low-level call — reaches every one of the 63 endpoints. Throws FarazError on `status: "error"`. */
17
+ request(method: string, path: string, body?: Json, query?: Query | null): Promise<Json>;
18
+
19
+ balance(): Promise<Json>;
20
+ profile(): Promise<Json>;
21
+ lines(): Promise<Json>;
22
+
23
+ sendPattern(code: string, recipient: string, attributes: Record<string, string | number>, line?: string): Promise<Json>;
24
+ sendSimple(text: string, recipients: string[], line?: string): Promise<Json>;
25
+ sendVariable(text: string, recipients: Json[], line?: string): Promise<Json>;
26
+
27
+ createPattern(payload: Json): Promise<Json>;
28
+ patterns(query?: Query): Promise<Json>;
29
+
30
+ inbox(page?: number, limit?: number): Promise<Json>;
31
+ sendRequests(query?: Query): Promise<Json>;
32
+ sendRequestItems(id: string | number, query?: Query): Promise<Json>;
33
+
34
+ phonebooks(): Promise<Json>;
35
+ addContact(payload: Json): Promise<Json>;
36
+
37
+ provinces(query?: Query): Promise<Json>;
38
+ numberBanks(query?: Query): Promise<Json>;
39
+ }
40
+
41
+ export default FarazSMS;
package/index.mjs ADDED
@@ -0,0 +1,75 @@
1
+ // FarazSMS — official lightweight client (ESM). Node 18+ (built-in fetch).
2
+ const BASE = "https://api.iranpayamak.com";
3
+
4
+ export class FarazError extends Error {
5
+ constructor(status, body) {
6
+ super("[" + status + "] " + (typeof body === "string" ? body : JSON.stringify(body)));
7
+ this.name = "FarazError";
8
+ this.status = status;
9
+ this.body = body;
10
+ }
11
+ }
12
+
13
+ export class FarazSMS {
14
+ constructor(apiKey, baseUrl = BASE) {
15
+ if (!apiKey) throw new Error("FarazSMS: apiKey is required");
16
+ this.base = String(baseUrl).replace(/\/$/, "");
17
+ this.key = apiKey;
18
+ }
19
+
20
+ // low-level — reaches every one of the 63 endpoints
21
+ async request(method, path, body = null, query = null) {
22
+ const url = new URL(this.base + path);
23
+ if (query) for (const k in query) if (query[k] != null) url.searchParams.set(k, query[k]);
24
+ const res = await fetch(url, {
25
+ method,
26
+ headers: {
27
+ "Api-Key": this.key,
28
+ "Accept": "application/json",
29
+ ...(body ? { "Content-Type": "application/json" } : {}),
30
+ },
31
+ body: body ? JSON.stringify(body) : undefined,
32
+ });
33
+ const data = await res.json().catch(() => ({}));
34
+ if (data && data.status === "error") throw new FarazError(res.status, data.message ?? data);
35
+ return data;
36
+ }
37
+
38
+ // account
39
+ balance() { return this.request("GET", "/ws/v1/account/balance"); }
40
+ profile() { return this.request("GET", "/ws/v1/account/profile"); }
41
+ lines() { return this.request("GET", "/ws/v1/lines/accessible"); }
42
+
43
+ // send
44
+ sendPattern(code, recipient, attributes, line = "90008361") {
45
+ return this.request("POST", "/ws/v1/sms/pattern",
46
+ { code, recipient, attributes, line_number: line, number_format: "english" });
47
+ }
48
+ sendSimple(text, recipients, line = "90008361") {
49
+ return this.request("POST", "/ws/v1/sms/simple",
50
+ { text, recipients, line_number: line, number_format: "english" });
51
+ }
52
+ sendVariable(text, recipients, line = "90008361") {
53
+ return this.request("POST", "/ws/v1/sms/keywords",
54
+ { text, recipients, line_number: line, number_format: "english" });
55
+ }
56
+
57
+ // patterns
58
+ createPattern(payload) { return this.request("POST", "/ws/v1/patterns", payload); }
59
+ patterns(query = {}) { return this.request("GET", "/ws/v1/patterns", null, query); }
60
+
61
+ // reports
62
+ inbox(page = 1, limit = 20) { return this.request("GET", "/ws/v1/inbox", null, { page, limit }); }
63
+ sendRequests(query = {}) { return this.request("GET", "/ws/v1/send_request", null, query); }
64
+ sendRequestItems(id, query = {}) { return this.request("GET", "/ws/v1/send_request/" + id + "/items", null, query); }
65
+
66
+ // phonebook
67
+ phonebooks() { return this.request("GET", "/ws/v1/phone_book"); }
68
+ addContact(payload) { return this.request("POST", "/ws/v1/phone_book_data", payload); }
69
+
70
+ // reference
71
+ provinces(query = {}) { return this.request("GET", "/provinces", null, query); }
72
+ numberBanks(query = {}) { return this.request("GET", "/ws/v1/number_bank", null, query); }
73
+ }
74
+
75
+ export default FarazSMS;
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "farazsms",
3
+ "version": "1.0.0",
4
+ "description": "Official lightweight client for the FarazSMS web services — send pattern/OTP, simple & bulk SMS, reports, phonebook, and all 63 endpoints via a low-level request().",
5
+ "keywords": ["farazsms", "sms", "otp", "pattern", "iran", "iranpayamak", "پیامک", "اس ام اس"],
6
+ "license": "MIT",
7
+ "author": "FarazSMS",
8
+ "homepage": "https://gitlab.faraz.club/common-service-centres/api-docs",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://gitlab.faraz.club/common-service-centres/api-docs.git"
12
+ },
13
+ "type": "module",
14
+ "main": "./index.cjs",
15
+ "module": "./index.mjs",
16
+ "types": "./index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./index.d.ts",
20
+ "import": "./index.mjs",
21
+ "require": "./index.cjs"
22
+ }
23
+ },
24
+ "files": ["index.mjs", "index.cjs", "index.d.ts", "README.md"],
25
+ "engines": { "node": ">=18" }
26
+ }