medos-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.
@@ -0,0 +1,108 @@
1
+ import { MedosClient } from "../client/MedosClient";
2
+ const AppointmentService = {
3
+ async getAddresses() {
4
+ const client = await MedosClient.ensureInitialized();
5
+ const res = await client.get("/workspaces");
6
+ const data = res.data ?? res;
7
+ if (data && Array.isArray(data.addressDoctors)) {
8
+ const addresses = data.addressDoctors
9
+ .filter((ad) => ad.address)
10
+ .map((ad) => {
11
+ const addr = ad.address;
12
+ const doctors = (ad.doctors || []).map((d) => ({
13
+ id: String(d.id ?? ""),
14
+ name: `${d.firstName || ""} ${d.lastName || ""}`.trim() || "Doctor",
15
+ email: d.email,
16
+ gender: d.gender,
17
+ countryCode: d.countryCode,
18
+ phoneNumber: d.phoneNumber,
19
+ dob: d.dob,
20
+ platform: d.platform,
21
+ isKycCompleted: d.isKycCompleted,
22
+ }));
23
+ return {
24
+ id: String(addr.id ?? ""),
25
+ completeAddress: addr.completeAddress,
26
+ addressLine1: addr.addressLine1,
27
+ addressLine2: addr.addressLine2,
28
+ city: addr.city,
29
+ state: addr.state,
30
+ country: addr.country,
31
+ zipcode: addr.zipcode,
32
+ landmark: addr.landmark,
33
+ phoneNumber: addr.phoneNumber,
34
+ latitude: addr.latitude,
35
+ longitude: addr.longitude,
36
+ doctors,
37
+ };
38
+ });
39
+ return {
40
+ totalAddresses: data.totalAddresses,
41
+ totalDoctors: data.totalDoctors,
42
+ workspaceId: data.workspaceId,
43
+ addresses,
44
+ };
45
+ }
46
+ return { addresses: [] };
47
+ },
48
+ async fetchSlots(workspaceId, addressId, doctorId, appointmentDate) {
49
+ const client = await MedosClient.ensureInitialized();
50
+ const res = await client.get(`/appointments/available-slots`, {
51
+ params: {
52
+ workspaceId,
53
+ addressId,
54
+ doctorId,
55
+ appointmentDate,
56
+ },
57
+ });
58
+ const data = res.data ?? res;
59
+ if (Array.isArray(data)) {
60
+ return data.map((slot) => {
61
+ const { appointmentDate: date, fromDateTimeTs: fromTime, toDateTimeTs: toTime, } = slot;
62
+ const start = `${date}T${fromTime}:00`;
63
+ const end = `${date}T${toTime}:00`;
64
+ return {
65
+ start,
66
+ end,
67
+ id: slot.id,
68
+ ...slot,
69
+ };
70
+ });
71
+ }
72
+ return [];
73
+ },
74
+ async createAppointment(payload) {
75
+ const client = await MedosClient.ensureInitialized();
76
+ const workspaceId = payload.workspaceId;
77
+ const appointmentData = {
78
+ workspaceAddressId: payload.workspaceAddressId,
79
+ doctorId: payload.doctorId,
80
+ mode: payload.mode || "OFFLINE",
81
+ appointmentDate: payload.appointmentDate,
82
+ fromDateTimeTs: payload.fromDateTimeTs,
83
+ toDateTimeTs: payload.toDateTimeTs,
84
+ consultationCharge: payload.consultationCharge || "0",
85
+ type: payload.type || "CONSULTATION",
86
+ source: payload.source || "SDK_POWERED_WEBSITE",
87
+ patientPayload: payload.patientPayload,
88
+ patientAddress: payload.patientAddress,
89
+ };
90
+ const formData = new FormData();
91
+ const payloadString = JSON.stringify(appointmentData);
92
+ formData.append("payload", payloadString);
93
+ if (payload.attachments && payload.attachments.length > 0) {
94
+ payload.attachments.forEach((file) => {
95
+ formData.append("attachments", file);
96
+ });
97
+ }
98
+ const config = {
99
+ headers: {},
100
+ };
101
+ if (workspaceId) {
102
+ config.headers["workspace-id"] = String(workspaceId);
103
+ }
104
+ const res = await client.post("/appointments/book-appointment", formData, config);
105
+ return res.data;
106
+ },
107
+ };
108
+ export { AppointmentService, };
@@ -0,0 +1,6 @@
1
+ declare const AuthService: {
2
+ init(apiKey: string): Promise<string>;
3
+ getToken(): string | null;
4
+ clear(): void;
5
+ };
6
+ export { AuthService };
@@ -0,0 +1,25 @@
1
+ import axios from "axios";
2
+ let sessionToken = null;
3
+ const AuthService = {
4
+ async init(apiKey) {
5
+ try {
6
+ const res = await axios.post(`https://api-dev.medapi.in/v1/auth/session?api_key=${apiKey}`, {});
7
+ const token = res.data?.access_token;
8
+ if (!token || typeof token !== "string") {
9
+ throw new Error("Invalid session token response");
10
+ }
11
+ sessionToken = token;
12
+ return token;
13
+ }
14
+ catch (e) {
15
+ throw new Error(`Failed to initialize session: ${e.message}`);
16
+ }
17
+ },
18
+ getToken() {
19
+ return sessionToken;
20
+ },
21
+ clear() {
22
+ sessionToken = null;
23
+ },
24
+ };
25
+ export { AuthService };
@@ -0,0 +1,14 @@
1
+ type SendPhoneVerificationOtpPayload = {
2
+ countryCode: string;
3
+ phoneNumber: string;
4
+ };
5
+ type VerifyPhoneVerificationOtpPayload = {
6
+ countryCode: string;
7
+ phoneNumber: string;
8
+ otpCode: string;
9
+ };
10
+ declare const PatientService: {
11
+ sendPhoneVerificationOtp(payload: SendPhoneVerificationOtpPayload): Promise<any>;
12
+ verifyPhoneVerificationOtp(payload: VerifyPhoneVerificationOtpPayload): Promise<any>;
13
+ };
14
+ export { PatientService, SendPhoneVerificationOtpPayload, VerifyPhoneVerificationOtpPayload, };
@@ -0,0 +1,14 @@
1
+ import { MedosClient } from "../client/MedosClient";
2
+ const PatientService = {
3
+ async sendPhoneVerificationOtp(payload) {
4
+ const client = await MedosClient.ensureInitialized();
5
+ const res = await client.post("/patients/send-phone-verification-otp", payload);
6
+ return res.data;
7
+ },
8
+ async verifyPhoneVerificationOtp(payload) {
9
+ const client = await MedosClient.ensureInitialized();
10
+ const res = await client.post("/patients/verify-phone-verification-otp", payload);
11
+ return res.data;
12
+ },
13
+ };
14
+ export { PatientService, };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "medos-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Medos SDK for managing appointments, meetings, and calendars in apps",
5
+ "homepage": "https://github.com/MediLaunch/medos-sdk-react#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/MediLaunch/medos-sdk-react/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/MediLaunch/medos-sdk-react.git"
12
+ },
13
+ "license": "UNLICENSED",
14
+ "author": "Pooranjoy Bhattacharya",
15
+ "type": "module",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "build:clean": "tsc --build --clean && tsc",
24
+ "prepublishOnly": "npm run build:clean",
25
+ "test": "echo \"Error: no test specified\" && exit 1"
26
+ },
27
+ "dependencies": {
28
+ "axios": "^1.12.2",
29
+ "react": "^19.2.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/react": "^19.2.3",
33
+ "typescript": "^5.9.3"
34
+ },
35
+ "keywords": [
36
+ "medos"
37
+ ]
38
+ }