medos-sdk 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/README.md CHANGED
@@ -1,15 +1,433 @@
1
- # How to test this package
1
+ # Medos SDK
2
2
 
3
- #### Go to your package directory (medos-sdk-js):
3
+ A JavaScript/TypeScript SDK for integrating healthcare appointment booking into your applications. Built for clinics, hospitals, and healthcare platforms.
4
4
 
5
- - `cd c:\harsh\projects\medos\medos-sdk-js`
6
- - `npm link`
5
+ ## Installation
7
6
 
8
- #### Go to your test project directory (where you want to use the package):
7
+ ```bash
8
+ npm install medos-sdk
9
+ ```
9
10
 
10
- - `cd path\to\your\test-project`
11
- - `npm link medos-sdk-js`
11
+ ## Getting Started
12
12
 
13
- ### If you still get errors, you can also use the folder path directly:
13
+ ### Authentication
14
14
 
15
- `npm install --save-dev c:\harsh\projects\medos\medos-sdk-js`
15
+ The SDK supports two authentication methods:
16
+
17
+ #### Server-Side (API Key)
18
+
19
+ Use this method for backend services and server-side rendering.
20
+
21
+ ```javascript
22
+ import { MedosClient } from 'medos-sdk';
23
+
24
+ await MedosClient.init({
25
+ apiKey: 'your-api-key',
26
+ baseURL: 'https://api-dev.medapi.in/v1'
27
+ });
28
+ ```
29
+
30
+ #### Client-Side (Session Token)
31
+
32
+ Use this method for frontend applications. Obtain the session token from your backend.
33
+
34
+ ```javascript
35
+ import { MedosClient } from 'medos-sdk';
36
+
37
+ await MedosClient.initWithSession({
38
+ sessionToken: 'user-session-token',
39
+ baseURL: 'https://api-dev.medapi.in/v1'
40
+ });
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ### Fetch Clinic Addresses and Doctors
46
+
47
+ Retrieve all available clinic locations with their associated doctors.
48
+
49
+ ```javascript
50
+ const result = await MedosClient.fetchAllAddressesAndDoctors();
51
+ ```
52
+
53
+ **Response:**
54
+
55
+ ```javascript
56
+ {
57
+ totalAddresses: 5,
58
+ totalDoctors: 12,
59
+ workspaceId: "workspace-123",
60
+ addresses: [
61
+ {
62
+ id: "addr-1",
63
+ completeAddress: "123 Medical Center, New York, NY 10001",
64
+ addressLine1: "123 Medical Center",
65
+ city: "New York",
66
+ state: "NY",
67
+ country: "USA",
68
+ zipcode: "10001",
69
+ doctors: [
70
+ {
71
+ id: "doc-1",
72
+ name: "Dr. John Smith",
73
+ email: "john.smith@example.com",
74
+ specialty: "Cardiology"
75
+ }
76
+ ]
77
+ }
78
+ ]
79
+ }
80
+ ```
81
+
82
+ ### Fetch Available Slots
83
+
84
+ Get available appointment time slots for a specific doctor.
85
+
86
+ ```javascript
87
+ const slots = await MedosClient.fetchAppointments(
88
+ 'workspace-123', // workspaceId
89
+ 'addr-1', // addressId
90
+ 'doc-1', // doctorId
91
+ '2025-11-16' // appointmentDate (YYYY-MM-DD)
92
+ );
93
+ ```
94
+
95
+ **Response:**
96
+
97
+ ```javascript
98
+ [
99
+ {
100
+ start: "2025-11-16T10:00:00",
101
+ end: "2025-11-16T10:30:00",
102
+ id: "slot-1"
103
+ },
104
+ {
105
+ start: "2025-11-16T11:00:00",
106
+ end: "2025-11-16T11:30:00",
107
+ id: "slot-2"
108
+ }
109
+ ]
110
+ ```
111
+
112
+ ### Book an Appointment
113
+
114
+ Create a new appointment booking.
115
+
116
+ ```javascript
117
+ import { AppointmentService } from 'medos-sdk';
118
+
119
+ const appointment = await AppointmentService.createAppointment({
120
+ workspaceAddressId: 'addr-1',
121
+ doctorId: 'doc-1',
122
+ mode: 'OFFLINE',
123
+ appointmentDate: '2025-11-16',
124
+ fromDateTimeTs: '10:00',
125
+ toDateTimeTs: '10:30',
126
+ consultationCharge: '100',
127
+ type: 'CONSULTATION',
128
+ source: 'SDK_POWERED_WEBSITE',
129
+ patientPayload: {
130
+ firstName: 'Jane',
131
+ lastName: 'Doe',
132
+ email: 'jane.doe@example.com',
133
+ countryCode: '+1',
134
+ phoneNumber: '5551234567',
135
+ age: 30,
136
+ gender: 'FEMALE'
137
+ },
138
+ patientAddress: {
139
+ addressLine1: '456 Patient Street',
140
+ city: 'New York',
141
+ state: 'NY',
142
+ country: 'USA',
143
+ zipcode: '10001',
144
+ landmark: 'Near Central Park'
145
+ }
146
+ });
147
+ ```
148
+
149
+ **Optional Fields:**
150
+
151
+ | Field | Default Value | Description |
152
+ |-------|---------------|-------------|
153
+ | `mode` | `"OFFLINE"` | Consultation mode: `"OFFLINE"` or `"ONLINE"` |
154
+ | `consultationCharge` | `"0"` | Consultation fee as string |
155
+ | `type` | `"CONSULTATION"` | Appointment type |
156
+ | `source` | `"SDK_POWERED_WEBSITE"` | Source identifier |
157
+
158
+ ### Phone Verification
159
+
160
+ Implement OTP-based phone number verification for patients.
161
+
162
+ #### Send OTP
163
+
164
+ ```javascript
165
+ await MedosClient.sendPhoneVerificationOtp({
166
+ countryCode: '+1',
167
+ phoneNumber: '5551234567'
168
+ });
169
+ ```
170
+
171
+ #### Verify OTP
172
+
173
+ ```javascript
174
+ const result = await MedosClient.verifyPhoneVerificationOtp({
175
+ countryCode: '+1',
176
+ phoneNumber: '5551234567',
177
+ otp: '123456'
178
+ });
179
+ ```
180
+
181
+ ## TypeScript
182
+
183
+ The SDK is written in TypeScript and provides comprehensive type definitions.
184
+
185
+ ```typescript
186
+ import {
187
+ MedosClient,
188
+ AppointmentService,
189
+ BookAppointmentPayload,
190
+ AddressesResponse,
191
+ PatientPayload,
192
+ PatientAddressPayload
193
+ } from 'medos-sdk';
194
+
195
+ const payload: BookAppointmentPayload = {
196
+ workspaceAddressId: 'addr-1',
197
+ doctorId: 'doc-1',
198
+ appointmentDate: '2025-11-16',
199
+ fromDateTimeTs: '10:00',
200
+ toDateTimeTs: '10:30',
201
+ patientPayload: {
202
+ firstName: 'John',
203
+ lastName: 'Doe',
204
+ countryCode: '+1',
205
+ phoneNumber: '5551234567'
206
+ },
207
+ patientAddress: {
208
+ addressLine1: '123 Main Street',
209
+ city: 'New York',
210
+ state: 'NY',
211
+ country: 'USA',
212
+ zipcode: '10001'
213
+ }
214
+ };
215
+
216
+ const appointment = await AppointmentService.createAppointment(payload);
217
+ ```
218
+
219
+ ### Type Definitions
220
+
221
+ #### `BookAppointmentPayload`
222
+
223
+ ```typescript
224
+ {
225
+ workspaceAddressId: string | number;
226
+ doctorId: string | number;
227
+ appointmentDate: string; // Format: "YYYY-MM-DD"
228
+ fromDateTimeTs: string; // Format: "HH:MM"
229
+ toDateTimeTs: string; // Format: "HH:MM"
230
+ mode?: "OFFLINE" | "ONLINE"; // Default: "OFFLINE"
231
+ consultationCharge?: string; // Default: "0"
232
+ type?: "CONSULTATION" | string; // Default: "CONSULTATION"
233
+ source?: string; // Default: "SDK_POWERED_WEBSITE"
234
+ patientPayload: PatientPayload;
235
+ patientAddress: PatientAddressPayload; // Required
236
+ }
237
+ ```
238
+
239
+ #### `PatientPayload`
240
+
241
+ ```typescript
242
+ {
243
+ firstName: string;
244
+ lastName: string;
245
+ countryCode: string;
246
+ phoneNumber: string;
247
+ email?: string;
248
+ age?: number;
249
+ gender?: "MALE" | "FEMALE" | "OTHER";
250
+ }
251
+ ```
252
+
253
+ #### `PatientAddressPayload`
254
+
255
+ ```typescript
256
+ {
257
+ addressLine1?: string;
258
+ city?: string;
259
+ state?: string;
260
+ country?: string;
261
+ zipcode?: string;
262
+ landmark?: string;
263
+ }
264
+ ```
265
+
266
+ ## React Integration
267
+
268
+ Pre-built appointment calendar component for React applications.
269
+
270
+ ```jsx
271
+ import { AppointmentCalender } from 'medos-sdk';
272
+
273
+ function BookingPage() {
274
+ return <AppointmentCalender />;
275
+ }
276
+ ```
277
+
278
+ The component automatically uses the initialized `MedosClient` instance.
279
+
280
+ ## API Reference
281
+
282
+ ### MedosClient
283
+
284
+ #### `init(config)`
285
+
286
+ Initialize the SDK with an API key (server-side).
287
+
288
+ **Parameters:**
289
+ - `config.apiKey` (string, required) - Your Medos API key
290
+ - `config.baseURL` (string, optional) - API base URL. Defaults to dev environment
291
+
292
+ **Returns:** `Promise<void>`
293
+
294
+ ---
295
+
296
+ #### `initWithSession(config)`
297
+
298
+ Initialize the SDK with a session token (client-side).
299
+
300
+ **Parameters:**
301
+ - `config.sessionToken` (string, required) - Session token
302
+ - `config.baseURL` (string, optional) - API base URL. Defaults to dev environment
303
+
304
+ **Returns:** `Promise<void>`
305
+
306
+ ---
307
+
308
+ #### `fetchAllAddressesAndDoctors()`
309
+
310
+ Fetch all clinic addresses and their associated doctors.
311
+
312
+ **Returns:** `Promise<AddressesResponse>`
313
+
314
+ **Response Type:**
315
+ ```typescript
316
+ {
317
+ totalAddresses?: number;
318
+ totalDoctors?: number;
319
+ workspaceId?: number | string;
320
+ addresses: Array<{
321
+ id: string;
322
+ completeAddress?: string;
323
+ addressLine1?: string;
324
+ city?: string;
325
+ state?: string;
326
+ country?: string;
327
+ zipcode?: string;
328
+ doctors?: Array<{
329
+ id: string;
330
+ name: string;
331
+ email?: string;
332
+ specialty?: string;
333
+ }>;
334
+ }>;
335
+ }
336
+ ```
337
+
338
+ ---
339
+
340
+ #### `fetchAppointments(workspaceId, addressId, doctorId, appointmentDate)`
341
+
342
+ Fetch available appointment slots for a specific doctor.
343
+
344
+ **Parameters:**
345
+ - `workspaceId` (string | number) - Workspace identifier
346
+ - `addressId` (string | number) - Address identifier
347
+ - `doctorId` (string | number) - Doctor identifier
348
+ - `appointmentDate` (string) - Date in YYYY-MM-DD format
349
+
350
+ **Returns:** `Promise<Slot[]>`
351
+
352
+ **Response Type:**
353
+ ```typescript
354
+ Array<{
355
+ start: string; // ISO datetime format
356
+ end: string; // ISO datetime format
357
+ id?: string;
358
+ }>
359
+ ```
360
+
361
+ ---
362
+
363
+ #### `sendPhoneVerificationOtp(payload)`
364
+
365
+ Send OTP to a phone number for verification.
366
+
367
+ **Parameters:**
368
+ - `payload.countryCode` (string) - Country code with + prefix (e.g., "+1")
369
+ - `payload.phoneNumber` (string) - Phone number without country code
370
+
371
+ **Returns:** `Promise<any>`
372
+
373
+ ---
374
+
375
+ #### `verifyPhoneVerificationOtp(payload)`
376
+
377
+ Verify OTP for a phone number.
378
+
379
+ **Parameters:**
380
+ - `payload.countryCode` (string) - Country code with + prefix
381
+ - `payload.phoneNumber` (string) - Phone number without country code
382
+ - `payload.otp` (string) - OTP code received
383
+
384
+ **Returns:** `Promise<any>`
385
+
386
+ ---
387
+
388
+ ### AppointmentService
389
+
390
+ #### `createAppointment(payload)`
391
+
392
+ Create a new appointment booking.
393
+
394
+ **Parameters:**
395
+ - `payload` (BookAppointmentPayload) - Appointment details
396
+
397
+ **Returns:** `Promise<any>`
398
+
399
+ ## Error Handling
400
+
401
+ All SDK methods return Promises and should be wrapped in try-catch blocks.
402
+
403
+ ```javascript
404
+ try {
405
+ await MedosClient.init({ apiKey: 'your-api-key' });
406
+ const addresses = await MedosClient.fetchAllAddressesAndDoctors();
407
+ } catch (error) {
408
+ console.error('Failed to fetch addresses:', error.message);
409
+ }
410
+ ```
411
+
412
+ ## Requirements
413
+
414
+ - **Node.js:** v14 or higher
415
+ - **Browsers:** Modern browsers with ES6+ support
416
+ - **React:** v19 or higher (for React components)
417
+ - **TypeScript:** v5 or higher (optional)
418
+
419
+ ## License
420
+
421
+ UNLICENSED
422
+
423
+ ## Support
424
+
425
+ For bug reports and feature requests, please visit our [GitHub Issues](https://github.com/MediLaunch/medos-sdk-react/issues).
426
+
427
+ ## Author
428
+
429
+ Pooranjoy Bhattacharya
430
+
431
+ ---
432
+
433
+ *Built for healthcare providers worldwide.*
@@ -300,7 +300,11 @@ export const AppointmentCalender = ({ onError, }) => {
300
300
  };
301
301
  const submitAppointment = async () => {
302
302
  setError(null);
303
- if (!selectedDoctor || !selectedSlot || !workspaceId || !selectedAddress) {
303
+ if (!selectedDoctor ||
304
+ !selectedSlot ||
305
+ !workspaceId ||
306
+ !selectedAddress ||
307
+ !patientAddress) {
304
308
  setError("Please ensure all selections are complete.");
305
309
  return;
306
310
  }
@@ -323,11 +327,9 @@ export const AppointmentCalender = ({ onError, }) => {
323
327
  };
324
328
  const fromDateTimeTs = formatTime(startDate);
325
329
  const toDateTimeTs = formatTime(endDate);
326
- const patientAddressPayload = patientAddress
327
- ? {
328
- addressLine1: patientAddress,
329
- }
330
- : undefined;
330
+ const patientAddressPayload = {
331
+ addressLine1: patientAddress,
332
+ };
331
333
  await AppointmentService.createAppointment({
332
334
  workspaceId: workspaceId,
333
335
  workspaceAddressId: selectedAddress,
@@ -39,7 +39,7 @@ type BookAppointmentPayload = {
39
39
  type?: "CONSULTATION" | string;
40
40
  source?: string;
41
41
  patientPayload: PatientPayload;
42
- patientAddress?: PatientAddressPayload;
42
+ patientAddress: PatientAddressPayload;
43
43
  attachments?: File[];
44
44
  };
45
45
  type AppointmentPayload = {
@@ -54,7 +54,7 @@ type AppointmentPayload = {
54
54
  type?: string;
55
55
  source?: string;
56
56
  patientPayload: PatientPayload;
57
- patientAddress?: PatientAddressPayload;
57
+ patientAddress: PatientAddressPayload;
58
58
  attachments?: File[];
59
59
  };
60
60
  type AddressItem = {
@@ -73,7 +73,6 @@ const AppointmentService = {
73
73
  },
74
74
  async createAppointment(payload) {
75
75
  const client = await MedosClient.ensureInitialized();
76
- const workspaceId = payload.workspaceId;
77
76
  const appointmentData = {
78
77
  workspaceAddressId: payload.workspaceAddressId,
79
78
  doctorId: payload.doctorId,
@@ -87,22 +86,24 @@ const AppointmentService = {
87
86
  patientPayload: payload.patientPayload,
88
87
  patientAddress: payload.patientAddress,
89
88
  };
90
- const formData = new FormData();
91
- const payloadString = JSON.stringify(appointmentData);
92
- formData.append("payload", payloadString);
93
89
  if (payload.attachments && payload.attachments.length > 0) {
90
+ const formData = new FormData();
91
+ const payloadString = JSON.stringify(appointmentData);
92
+ formData.append("payload", payloadString);
94
93
  payload.attachments.forEach((file) => {
95
94
  formData.append("attachments", file);
96
95
  });
96
+ const res = await client.post("/appointments/book-appointment", formData);
97
+ return res.data;
97
98
  }
98
- const config = {
99
- headers: {},
100
- };
101
- if (workspaceId) {
102
- config.headers["workspace-id"] = String(workspaceId);
99
+ else {
100
+ const res = await client.post("/appointments/book-appointment", appointmentData, {
101
+ headers: {
102
+ "Content-Type": "application/json",
103
+ },
104
+ });
105
+ return res.data;
103
106
  }
104
- const res = await client.post("/appointments/book-appointment", formData, config);
105
- return res.data;
106
107
  },
107
108
  };
108
109
  export { AppointmentService, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "medos-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Medos SDK for managing appointments, meetings, and calendars in apps",
5
5
  "homepage": "https://github.com/MediLaunch/medos-sdk-react#readme",
6
6
  "bugs": {
@@ -25,11 +25,17 @@
25
25
  "test": "echo \"Error: no test specified\" && exit 1"
26
26
  },
27
27
  "dependencies": {
28
- "axios": "^1.12.2",
29
- "react": "^19.2.0"
28
+ "axios": "^1.12.2"
29
+ },
30
+ "peerDependencies": {
31
+ "react": "^18.0.0 || ^19.0.0",
32
+ "react-dom": "^18.0.0 || ^19.0.0"
30
33
  },
31
34
  "devDependencies": {
32
- "@types/react": "^19.2.3",
35
+ "@types/react": "^18.0.0",
36
+ "@types/react-dom": "^18.0.0",
37
+ "react": "^19.2.0",
38
+ "react-dom": "^19.2.0",
33
39
  "typescript": "^5.9.3"
34
40
  },
35
41
  "keywords": [