plexisms 1.0.0 → 1.0.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 PlexiSMS
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
17
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "plexisms",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Official Node.js SDK for PlexiSMS API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
7
12
  "scripts": {
8
13
  "build": "tsc",
9
14
  "lint": "eslint 'src/**/*.ts'",
@@ -44,4 +49,4 @@
44
49
  "dependencies": {
45
50
  "axios": "^1.6.0"
46
51
  }
47
- }
52
+ }
package/eslint.config.js DELETED
@@ -1,12 +0,0 @@
1
- const tseslint = require('typescript-eslint');
2
-
3
- module.exports = tseslint.config(
4
- {
5
- files: ['**/*.ts'],
6
- extends: [
7
- ...tseslint.configs.recommended,
8
- ],
9
- rules: {
10
- },
11
- },
12
- );
package/jest.config.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- };
package/src/client.ts DELETED
@@ -1,159 +0,0 @@
1
- import axios, { AxiosInstance } from 'axios';
2
- import {
3
- AuthenticationError,
4
- BalanceError,
5
- APIError,
6
- PlexismsError
7
- } from './exceptions';
8
- import {
9
- SendSMSOptions,
10
- SMSResponse,
11
- SendBulkSMSOptions,
12
- BulkSMSResponse,
13
- OTPRequestResponse,
14
- OTPVerifyResponse,
15
- BalanceResponse,
16
- MessageStatusResponse
17
- } from './types';
18
-
19
- export class Client {
20
- private client: AxiosInstance;
21
- private readonly DEFAULT_BASE_URL = "https://server.plexisms.com";
22
-
23
- public messages: Messages;
24
- public otp: OTP;
25
- public account: Account;
26
-
27
- /**
28
- * @param apiKey Your PlexiSMS API Key.
29
- * @param baseUrl Optional override for API URL.
30
- */
31
- constructor(apiKey?: string, baseUrl?: string) {
32
- const token = apiKey || process.env.PLEXISMS_API_KEY;
33
-
34
- if (!token) {
35
- throw new AuthenticationError("API Key is required. Pass it to the constructor or set PLEXISMS_API_KEY environment variable.");
36
- }
37
-
38
- this.client = axios.create({
39
- baseURL: (baseUrl || process.env.PLEXISMS_BASE_URL || this.DEFAULT_BASE_URL).replace(/\/$/, ""),
40
- headers: {
41
- 'Authorization': `Token ${token}`,
42
- 'Content-Type': 'application/json',
43
- 'User-Agent': 'plexisms-node/1.0.0'
44
- }
45
- });
46
-
47
- this.messages = new Messages(this.client);
48
- this.otp = new OTP(this.client);
49
- this.account = new Account(this.client);
50
- }
51
- }
52
-
53
- class Resource {
54
- protected client: AxiosInstance;
55
-
56
- constructor(client: AxiosInstance) {
57
- this.client = client;
58
- }
59
-
60
- protected async request<T>(method: 'get' | 'post', endpoint: string, data?: Record<string, unknown>, params?: Record<string, unknown>): Promise<T> {
61
- try {
62
- const response = await this.client.request<T>({
63
- method,
64
- url: endpoint,
65
- data,
66
- params
67
- });
68
- return response.data;
69
- } catch (error: unknown) {
70
- this.handleError(error);
71
- throw error; // Should be unreachable given handleError throws
72
- }
73
- }
74
-
75
- protected handleError(error: unknown): void {
76
- if (axios.isAxiosError(error)) {
77
- const status = error.response?.status;
78
- const data = error.response?.data as Record<string, unknown>;
79
- const message = (data?.error || data?.detail || error.message) as string;
80
-
81
- if (status === 401 || status === 403) {
82
- throw new AuthenticationError(`Unauthorized: ${message}`);
83
- } else if (status === 402) {
84
- throw new BalanceError(`Insufficient funds: ${message}`);
85
- } else if (status && status >= 500) {
86
- throw new APIError(`Server Error (${status}): ${message}`, status, data);
87
- } else if (status) {
88
- throw new APIError(`API Error (${status}): ${message}`, status, data);
89
- } else {
90
- throw new PlexismsError(`Network Error: ${error.message}`);
91
- }
92
- }
93
- throw new PlexismsError(`Unexpected Error: ${error}`);
94
- }
95
- }
96
-
97
- export class Messages extends Resource {
98
- /**
99
- * Send a single SMS
100
- */
101
- async create(options: SendSMSOptions): Promise<SMSResponse> {
102
- return this.request<SMSResponse>('post', '/api/sms/send/', {
103
- phone_number: options.to,
104
- message: options.body,
105
- sender_id: options.senderId,
106
- sms_type: options.smsType || 'transactional'
107
- });
108
- }
109
-
110
- /**
111
- * Send bulk SMS
112
- */
113
- async createBulk(options: SendBulkSMSOptions): Promise<BulkSMSResponse> {
114
- return this.request<BulkSMSResponse>('post', '/api/sms/send-bulk/', {
115
- phone_numbers: options.phoneNumbers,
116
- message: options.body,
117
- sender_id: options.senderId,
118
- sms_type: options.smsType || 'transactional'
119
- });
120
- }
121
-
122
- /**
123
- * Get SMS status
124
- */
125
- async get(messageId: string | number): Promise<MessageStatusResponse> {
126
- return this.request('get', `/api/sms/${messageId}/status/`);
127
- }
128
- }
129
-
130
- export class OTP extends Resource {
131
- /**
132
- * Send an OTP code
133
- */
134
- async send(to: string, brand: string = "PlexiSMS"): Promise<OTPRequestResponse> {
135
- return this.request<OTPRequestResponse>('post', '/api/sms/send-otp/', {
136
- phone_number: to,
137
- brand
138
- });
139
- }
140
-
141
- /**
142
- * Verify an OTP code
143
- */
144
- async verify(verificationId: string, code: string): Promise<OTPVerifyResponse> {
145
- return this.request<OTPVerifyResponse>('post', '/api/sms/verify-otp/', {
146
- verification_id: verificationId,
147
- otp_code: code
148
- });
149
- }
150
- }
151
-
152
- export class Account extends Resource {
153
- /**
154
- * Check account balance
155
- */
156
- async balance(): Promise<BalanceResponse> {
157
- return this.request<BalanceResponse>('get', '/api/sms/balance/');
158
- }
159
- }
package/src/exceptions.ts DELETED
@@ -1,32 +0,0 @@
1
- export class PlexismsError extends Error {
2
- constructor(message: string) {
3
- super(message);
4
- this.name = 'PlexismsError';
5
- }
6
- }
7
-
8
- export class AuthenticationError extends PlexismsError {
9
- constructor(message: string) {
10
- super(message);
11
- this.name = 'AuthenticationError';
12
- }
13
- }
14
-
15
- export class BalanceError extends PlexismsError {
16
- constructor(message: string) {
17
- super(message);
18
- this.name = 'BalanceError';
19
- }
20
- }
21
-
22
- export class APIError extends PlexismsError {
23
- statusCode?: number;
24
- responseBody?: Record<string, unknown>;
25
-
26
- constructor(message: string, statusCode?: number, responseBody?: Record<string, unknown>) {
27
- super(message);
28
- this.name = 'APIError';
29
- this.statusCode = statusCode;
30
- this.responseBody = responseBody;
31
- }
32
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './client';
2
- export * from './exceptions';
3
- export * from './types';
package/src/types.ts DELETED
@@ -1,63 +0,0 @@
1
- export interface SMSResponse {
2
- id: number;
3
- message_id: string;
4
- status: 'pending' | 'sent' | 'delivered' | 'failed';
5
- phone_number: string;
6
- parts: number;
7
- cost_usd: string;
8
- balance: {
9
- remaining_usd: string;
10
- remaining_sms: number;
11
- };
12
- }
13
-
14
- export interface BulkSMSResponse {
15
- total: number;
16
- queued: number;
17
- task_id: string;
18
- message: string;
19
- }
20
-
21
- export interface OTPRequestResponse {
22
- verification_id: string;
23
- status: string;
24
- phone_number: string;
25
- expires_in: number;
26
- }
27
-
28
- export interface OTPVerifyResponse {
29
- verified: boolean;
30
- phone_number?: string;
31
- error?: string;
32
- }
33
-
34
- export interface BalanceResponse {
35
- amount: string;
36
- currency: string;
37
- provider: string;
38
- }
39
-
40
- export interface SendSMSOptions {
41
- to: string;
42
- body: string;
43
- senderId?: string;
44
- smsType?: 'transactional' | 'promotional';
45
- }
46
-
47
- export interface SendBulkSMSOptions {
48
- phoneNumbers: string[];
49
- body: string;
50
- senderId?: string;
51
- smsType?: 'transactional' | 'promotional';
52
- }
53
-
54
- export interface MessageStatusResponse {
55
- id: number;
56
- message_id: string;
57
- status: 'pending' | 'sent' | 'delivered' | 'failed';
58
- phone_number: string;
59
- parts: number;
60
- cost_usd: string;
61
- created_at: string;
62
- updated_at: string;
63
- }
@@ -1,5 +0,0 @@
1
- describe('PlexiSMS Client', () => {
2
- it('should be true', () => {
3
- expect(true).toBe(true);
4
- });
5
- });
package/tsconfig.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2018",
4
- "module": "commonjs",
5
- "lib": [
6
- "es2018",
7
- "dom"
8
- ],
9
- "declaration": true,
10
- "strict": true,
11
- "esModuleInterop": true,
12
- "skipLibCheck": true,
13
- "forceConsistentCasingInFileNames": true,
14
- "outDir": "./dist",
15
- "rootDir": "./src"
16
- },
17
- "include": [
18
- "src/**/*"
19
- ],
20
- "exclude": [
21
- "node_modules",
22
- "**/*.spec.ts"
23
- ]
24
- }