@smcrm-sdk2/smcrm-sdk 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/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # SMCRM SDK
2
+
3
+ Official JavaScript SDK for SMCRM API integration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install smcrm-sdk
package/index.js ADDED
@@ -0,0 +1,230 @@
1
+ /**
2
+ * SMCRM SDK - Main Entry Point
3
+ * @version 1.0.0
4
+ * @author SMCRM
5
+ */
6
+
7
+ const axios = require('axios');
8
+
9
+ class SMCRMSDK {
10
+ constructor(config = {}) {
11
+ this.apiKey = config.apiKey || null;
12
+ this.baseURL = config.baseURL || 'https://smcrm.in/api';
13
+ this.timeout = config.timeout || 30000;
14
+ this.retryCount = config.retryCount || 3;
15
+ this.module = config.module || null;
16
+
17
+ this.axiosInstance = axios.create({
18
+ baseURL: this.baseURL,
19
+ timeout: this.timeout,
20
+ headers: {
21
+ 'Content-Type': 'application/json',
22
+ 'Accept': 'application/json'
23
+ }
24
+ });
25
+
26
+ // Add request interceptor for API key
27
+ this.axiosInstance.interceptors.request.use((config) => {
28
+ if (this.apiKey) {
29
+ config.headers['X-API-KEY'] = this.apiKey;
30
+ config.headers['Authorization'] = `Bearer ${this.apiKey}`;
31
+ }
32
+ return config;
33
+ });
34
+
35
+ // Add response interceptor for error handling
36
+ this.axiosInstance.interceptors.response.use(
37
+ (response) => response,
38
+ (error) => {
39
+ return Promise.reject(this.handleError(error));
40
+ }
41
+ );
42
+ }
43
+
44
+ // Initialize SDK
45
+ init(config = {}) {
46
+ if (config.apiKey) this.apiKey = config.apiKey;
47
+ if (config.baseURL) this.baseURL = config.baseURL;
48
+ if (config.module) this.module = config.module;
49
+
50
+ // Auto-detect module if not specified
51
+ if (!this.module) {
52
+ return this.detectModule();
53
+ }
54
+
55
+ return Promise.resolve({ status: true, module: this.module });
56
+ }
57
+
58
+ // Detect module automatically
59
+ async detectModule() {
60
+ try {
61
+ const response = await this.axiosInstance.get('/detect-module');
62
+ this.module = response.data.module || 'repair';
63
+ return { status: true, module: this.module };
64
+ } catch (error) {
65
+ this.module = 'repair';
66
+ return { status: true, module: 'repair', message: 'Using default module' };
67
+ }
68
+ }
69
+
70
+ // Error handler
71
+ handleError(error) {
72
+ if (error.response) {
73
+ // Server responded with error status
74
+ return {
75
+ status: false,
76
+ statusCode: error.response.status,
77
+ message: error.response.data?.message || 'Server error occurred',
78
+ data: error.response.data
79
+ };
80
+ } else if (error.request) {
81
+ // Request was made but no response
82
+ return {
83
+ status: false,
84
+ message: 'Network error - Unable to connect to server',
85
+ error: error.message
86
+ };
87
+ } else {
88
+ // Something else happened
89
+ return {
90
+ status: false,
91
+ message: error.message || 'An error occurred',
92
+ error: error
93
+ };
94
+ }
95
+ }
96
+
97
+ // Generic request method
98
+ async request(endpoint, method = 'GET', data = null) {
99
+ try {
100
+ const response = await this.axiosInstance({
101
+ url: endpoint,
102
+ method: method,
103
+ data: data,
104
+ params: method === 'GET' ? data : undefined
105
+ });
106
+
107
+ return {
108
+ status: true,
109
+ data: response.data,
110
+ message: 'Success'
111
+ };
112
+ } catch (error) {
113
+ return this.handleError(error);
114
+ }
115
+ }
116
+
117
+ // ============ SERVICES API ============
118
+
119
+ // Get all services
120
+ async getServices() {
121
+ if (this.module === 'repair') {
122
+ return this.request('/repair/services');
123
+ } else if (this.module === 'clinic') {
124
+ return this.request('/clinic/doctors');
125
+ } else if (this.module === 'gym') {
126
+ return this.request('/gym/plans');
127
+ } else if (this.module === 'hostel') {
128
+ return this.request('/hostel/rooms');
129
+ }
130
+ return this.request('/services');
131
+ }
132
+
133
+ // Get sub-services (repair module)
134
+ async getSubServices(serviceId) {
135
+ if (this.module === 'repair') {
136
+ return this.request(`/repair/sub-services/${serviceId}`);
137
+ }
138
+ return { status: false, message: 'Sub-services not available for this module' };
139
+ }
140
+
141
+ // ============ BOOKING API ============
142
+
143
+ // Create booking
144
+ async createBooking(bookingData) {
145
+ const endpoint = `/${this.module}/booking`;
146
+ return this.request(endpoint, 'POST', bookingData);
147
+ }
148
+
149
+ // Get bookings
150
+ async getBookings(bookingId = null) {
151
+ const endpoint = bookingId ? `/${this.module}/booking/${bookingId}` : `/${this.module}/bookings`;
152
+ return this.request(endpoint);
153
+ }
154
+
155
+ // Cancel booking
156
+ async cancelBooking(bookingId) {
157
+ return this.request(`/${this.module}/booking/${bookingId}/cancel`, 'POST');
158
+ }
159
+
160
+ // ============ BUSINESS API ============
161
+
162
+ // Get business info
163
+ async getBusiness() {
164
+ return this.request(`/${this.module}/business-info`);
165
+ }
166
+
167
+ // ============ VENDOR API ============
168
+
169
+ // Get vendors
170
+ async getVendors() {
171
+ return this.request('/admin/vendors');
172
+ }
173
+
174
+ // Get vendor by ID
175
+ async getVendor(vendorId) {
176
+ return this.request(`/admin/vendors/${vendorId}`);
177
+ }
178
+
179
+ // ============ ATTENDANCE API ============
180
+
181
+ // Mark attendance
182
+ async markAttendance(attendanceData) {
183
+ return this.request('/attendance/mark', 'POST', attendanceData);
184
+ }
185
+
186
+ // Get recent attendance
187
+ async getRecentAttendance() {
188
+ return this.request('/attendance/recent');
189
+ }
190
+
191
+ // ============ UTILITY METHODS ============
192
+
193
+ // Set API key
194
+ setApiKey(apiKey) {
195
+ this.apiKey = apiKey;
196
+ this.axiosInstance.defaults.headers['X-API-KEY'] = apiKey;
197
+ this.axiosInstance.defaults.headers['Authorization'] = `Bearer ${apiKey}`;
198
+ return { status: true, message: 'API Key set successfully' };
199
+ }
200
+
201
+ // Get API key
202
+ getApiKey() {
203
+ return this.apiKey;
204
+ }
205
+
206
+ // Set module
207
+ setModule(module) {
208
+ const validModules = ['repair', 'clinic', 'gym', 'hostel'];
209
+ if (validModules.includes(module)) {
210
+ this.module = module;
211
+ return { status: true, message: `Module set to ${module}` };
212
+ }
213
+ return { status: false, message: 'Invalid module' };
214
+ }
215
+ }
216
+
217
+ // Create and export instance
218
+ const SMCRM = new SMCRMSDK();
219
+
220
+ // Export for different module systems
221
+ if (typeof module !== 'undefined' && module.exports) {
222
+ module.exports = SMCRM;
223
+ module.exports.default = SMCRM;
224
+ module.exports.SMCRMSDK = SMCRMSDK;
225
+ }
226
+
227
+ // Make global for browser
228
+ if (typeof window !== 'undefined') {
229
+ window.SMCRM = SMCRM;
230
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@smcrm-sdk2/smcrm-sdk",
3
+ "version": "1.0.0",
4
+ "description": "SMCRM JavaScript SDK for seamless API integration",
5
+ "main": "index.js",
6
+ "module": "src/index.js",
7
+ "types": "types/index.d.ts",
8
+ "scripts": {
9
+ "test": "jest",
10
+ "build": "webpack --mode production",
11
+ "dev": "webpack --mode development --watch"
12
+ },
13
+ "keywords": [
14
+ "smcrm",
15
+ "api",
16
+ "sdk",
17
+ "repair-service",
18
+ "clinic",
19
+ "gym",
20
+ "hostel",
21
+ "booking"
22
+ ],
23
+ "author": "SMCRM",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/smcrm/smcrm-sdk.git"
28
+ },
29
+ "dependencies": {
30
+ "axios": "^1.6.0"
31
+ },
32
+ "devDependencies": {
33
+ "@babel/core": "^7.23.0",
34
+ "@babel/preset-env": "^7.23.0",
35
+ "babel-loader": "^9.1.0",
36
+ "jest": "^29.7.0",
37
+ "webpack": "^5.88.0",
38
+ "webpack-cli": "^5.1.0"
39
+ }
40
+ }
File without changes