@clinchdate/api-client 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 +711 -0
- package/dist/client.d.ts +30 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +196 -0
- package/dist/client.js.map +1 -0
- package/dist/config/environments.d.ts +24 -0
- package/dist/config/environments.d.ts.map +1 -0
- package/dist/config/environments.js +24 -0
- package/dist/config/environments.js.map +1 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +44 -0
- package/dist/config.js.map +1 -0
- package/dist/hooks/useAuth.d.ts +13 -0
- package/dist/hooks/useAuth.d.ts.map +1 -0
- package/dist/hooks/useAuth.js +66 -0
- package/dist/hooks/useAuth.js.map +1 -0
- package/dist/hooks/useCall.d.ts +55 -0
- package/dist/hooks/useCall.d.ts.map +1 -0
- package/dist/hooks/useCall.js +148 -0
- package/dist/hooks/useCall.js.map +1 -0
- package/dist/hooks/useChat.d.ts +13 -0
- package/dist/hooks/useChat.d.ts.map +1 -0
- package/dist/hooks/useChat.js +76 -0
- package/dist/hooks/useChat.js.map +1 -0
- package/dist/hooks/useMatch.d.ts +15 -0
- package/dist/hooks/useMatch.d.ts.map +1 -0
- package/dist/hooks/useMatch.js +72 -0
- package/dist/hooks/useMatch.js.map +1 -0
- package/dist/hooks/useUser.d.ts +22 -0
- package/dist/hooks/useUser.d.ts.map +1 -0
- package/dist/hooks/useUser.js +170 -0
- package/dist/hooks/useUser.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/auth.interceptor.d.ts +14 -0
- package/dist/interceptors/auth.interceptor.d.ts.map +1 -0
- package/dist/interceptors/auth.interceptor.js +61 -0
- package/dist/interceptors/auth.interceptor.js.map +1 -0
- package/dist/interceptors/error.interceptor.d.ts +12 -0
- package/dist/interceptors/error.interceptor.d.ts.map +1 -0
- package/dist/interceptors/error.interceptor.js +50 -0
- package/dist/interceptors/error.interceptor.js.map +1 -0
- package/dist/interceptors/response.interceptor.d.ts +2 -0
- package/dist/interceptors/response.interceptor.d.ts.map +1 -0
- package/dist/interceptors/response.interceptor.js +2 -0
- package/dist/interceptors/response.interceptor.js.map +1 -0
- package/dist/services/auth.service.d.ts +12 -0
- package/dist/services/auth.service.d.ts.map +1 -0
- package/dist/services/auth.service.js +37 -0
- package/dist/services/auth.service.js.map +1 -0
- package/dist/services/base.service.d.ts +10 -0
- package/dist/services/base.service.d.ts.map +1 -0
- package/dist/services/base.service.js +22 -0
- package/dist/services/base.service.js.map +1 -0
- package/dist/services/call.service.d.ts +80 -0
- package/dist/services/call.service.d.ts.map +1 -0
- package/dist/services/call.service.js +57 -0
- package/dist/services/call.service.js.map +1 -0
- package/dist/services/chat.service.d.ts +16 -0
- package/dist/services/chat.service.d.ts.map +1 -0
- package/dist/services/chat.service.js +33 -0
- package/dist/services/chat.service.js.map +1 -0
- package/dist/services/index.d.ts +23 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +23 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/match.service.d.ts +14 -0
- package/dist/services/match.service.d.ts.map +1 -0
- package/dist/services/match.service.js +23 -0
- package/dist/services/match.service.js.map +1 -0
- package/dist/services/notification.service.d.ts +16 -0
- package/dist/services/notification.service.d.ts.map +1 -0
- package/dist/services/notification.service.js +31 -0
- package/dist/services/notification.service.js.map +1 -0
- package/dist/services/payment.service.d.ts +15 -0
- package/dist/services/payment.service.d.ts.map +1 -0
- package/dist/services/payment.service.js +32 -0
- package/dist/services/payment.service.js.map +1 -0
- package/dist/services/user.service.d.ts +16 -0
- package/dist/services/user.service.d.ts.map +1 -0
- package/dist/services/user.service.js +34 -0
- package/dist/services/user.service.js.map +1 -0
- package/dist/types/auth.types.d.ts +49 -0
- package/dist/types/auth.types.d.ts.map +1 -0
- package/dist/types/auth.types.js +2 -0
- package/dist/types/auth.types.js.map +1 -0
- package/dist/types/chat.types.d.ts +35 -0
- package/dist/types/chat.types.d.ts.map +1 -0
- package/dist/types/chat.types.js +2 -0
- package/dist/types/chat.types.js.map +1 -0
- package/dist/types/common.types.d.ts +39 -0
- package/dist/types/common.types.d.ts.map +1 -0
- package/dist/types/common.types.js +25 -0
- package/dist/types/common.types.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/match.types.d.ts +40 -0
- package/dist/types/match.types.d.ts.map +1 -0
- package/dist/types/match.types.js +2 -0
- package/dist/types/match.types.js.map +1 -0
- package/dist/types/notification.types.d.ts +26 -0
- package/dist/types/notification.types.d.ts.map +1 -0
- package/dist/types/notification.types.js +2 -0
- package/dist/types/notification.types.js.map +1 -0
- package/dist/types/payment.types.d.ts +47 -0
- package/dist/types/payment.types.d.ts.map +1 -0
- package/dist/types/payment.types.js +2 -0
- package/dist/types/payment.types.js.map +1 -0
- package/dist/types/user.types.d.ts +50 -0
- package/dist/types/user.types.d.ts.map +1 -0
- package/dist/types/user.types.js +2 -0
- package/dist/types/user.types.js.map +1 -0
- package/package.json +120 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosError, AxiosRequestConfig } from 'axios';
|
|
2
|
+
export interface ApiErrorResponse {
|
|
3
|
+
success: false;
|
|
4
|
+
message: string;
|
|
5
|
+
errors?: Record<string, string[]>;
|
|
6
|
+
statusCode: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class ApiError extends Error {
|
|
9
|
+
statusCode: number;
|
|
10
|
+
errors?: Record<string, string[]>;
|
|
11
|
+
isNetworkError: boolean;
|
|
12
|
+
isAuthError: boolean;
|
|
13
|
+
raw?: AxiosError;
|
|
14
|
+
constructor(message: string, statusCode: number, options?: {
|
|
15
|
+
errors?: Record<string, string[]>;
|
|
16
|
+
isNetworkError?: boolean;
|
|
17
|
+
raw?: AxiosError;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export declare const httpClient: {
|
|
21
|
+
get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
22
|
+
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
23
|
+
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
24
|
+
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
|
|
25
|
+
delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
26
|
+
upload<T = any>(url: string, formData: FormData, onProgress?: (percent: number) => void): Promise<T>;
|
|
27
|
+
readonly axios: AxiosInstance;
|
|
28
|
+
};
|
|
29
|
+
export declare function resetHttpClient(): void;
|
|
30
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EACZ,aAAa,EACb,UAAU,EACV,kBAAkB,EAGnB,MAAM,OAAO,CAAC;AAOf,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,QAAS,SAAQ,KAAK;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAClC,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,UAAU,CAAC;gBAGf,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAClC,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,GAAG,CAAC,EAAE,UAAU,CAAC;KAClB;CAUJ;AAiMD,eAAO,MAAM,UAAU;QACX,CAAC,aAAa,MAAM,WAAW,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;SAK7D,CAAC,aAAa,MAAM,SAAS,GAAG,WAAW,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;QAK3E,CAAC,aAAa,MAAM,SAAS,GAAG,WAAW,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;UAKxE,CAAC,aAAa,MAAM,SAAS,GAAG,WAAW,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;WAKzE,CAAC,aAAa,MAAM,WAAW,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;WAK9D,CAAC,aACP,MAAM,YACD,QAAQ,eACL,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GACrC,OAAO,CAAC,CAAC,CAAC;oBAaA,aAAa;CAG3B,CAAC;AAgBF,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getConfig } from './config';
|
|
3
|
+
export class ApiError extends Error {
|
|
4
|
+
statusCode;
|
|
5
|
+
errors;
|
|
6
|
+
isNetworkError;
|
|
7
|
+
isAuthError;
|
|
8
|
+
raw;
|
|
9
|
+
constructor(message, statusCode, options) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'ApiError';
|
|
12
|
+
this.statusCode = statusCode;
|
|
13
|
+
this.errors = options?.errors;
|
|
14
|
+
this.isNetworkError = options?.isNetworkError ?? false;
|
|
15
|
+
this.isAuthError = statusCode === 401 || statusCode === 403;
|
|
16
|
+
this.raw = options?.raw;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let isRefreshing = false;
|
|
20
|
+
let failedQueue = [];
|
|
21
|
+
function processQueue(error, token) {
|
|
22
|
+
failedQueue.forEach((promise) => {
|
|
23
|
+
if (error) {
|
|
24
|
+
promise.reject(error);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
promise.resolve(token);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
failedQueue = [];
|
|
31
|
+
}
|
|
32
|
+
let _axiosInstance = null;
|
|
33
|
+
function getAxiosInstance() {
|
|
34
|
+
if (_axiosInstance)
|
|
35
|
+
return _axiosInstance;
|
|
36
|
+
const config = getConfig();
|
|
37
|
+
_axiosInstance = axios.create({
|
|
38
|
+
baseURL: config.baseURL,
|
|
39
|
+
timeout: config.timeout,
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
Accept: 'application/json',
|
|
43
|
+
...config.defaultHeaders,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
_axiosInstance.interceptors.request.use(async (reqConfig) => {
|
|
47
|
+
const sdkConfig = getConfig();
|
|
48
|
+
const token = await sdkConfig.getToken();
|
|
49
|
+
if (token) {
|
|
50
|
+
reqConfig.headers = reqConfig.headers || {};
|
|
51
|
+
reqConfig.headers.Authorization = `Bearer ${token}`;
|
|
52
|
+
}
|
|
53
|
+
if (sdkConfig.platform) {
|
|
54
|
+
reqConfig.headers['X-Platform'] = sdkConfig.platform;
|
|
55
|
+
}
|
|
56
|
+
if (sdkConfig.debug) {
|
|
57
|
+
console.log(`[SDK] → ${reqConfig.method?.toUpperCase()} ${reqConfig.url}`);
|
|
58
|
+
}
|
|
59
|
+
return reqConfig;
|
|
60
|
+
}, (error) => Promise.reject(error));
|
|
61
|
+
_axiosInstance.interceptors.response.use((response) => {
|
|
62
|
+
const sdkConfig = getConfig();
|
|
63
|
+
if (sdkConfig.debug) {
|
|
64
|
+
console.log(`[SDK] ← ${response.status} ${response.config.url}`);
|
|
65
|
+
}
|
|
66
|
+
return response;
|
|
67
|
+
}, async (error) => {
|
|
68
|
+
const originalRequest = error.config;
|
|
69
|
+
if (!error.response) {
|
|
70
|
+
throw new ApiError('Network error — please check your connection.', 0, {
|
|
71
|
+
isNetworkError: true,
|
|
72
|
+
raw: error,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const { status, data } = error.response;
|
|
76
|
+
const sdkConfig = getConfig();
|
|
77
|
+
if (status === 401 && !originalRequest._retry) {
|
|
78
|
+
originalRequest._retry = true;
|
|
79
|
+
if (isRefreshing) {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
failedQueue.push({
|
|
82
|
+
resolve: (token) => {
|
|
83
|
+
originalRequest.headers.Authorization = `Bearer ${token}`;
|
|
84
|
+
resolve(_axiosInstance.request(originalRequest));
|
|
85
|
+
},
|
|
86
|
+
reject: (err) => reject(err),
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
isRefreshing = true;
|
|
91
|
+
try {
|
|
92
|
+
const refreshToken = await sdkConfig.getRefreshToken();
|
|
93
|
+
if (!refreshToken)
|
|
94
|
+
throw new Error('No refresh token');
|
|
95
|
+
const response = await axios.post(`${sdkConfig.baseURL}/auth/refresh-token`, { refreshToken }, { timeout: sdkConfig.timeout });
|
|
96
|
+
const newTokens = response.data.data;
|
|
97
|
+
await sdkConfig.onTokenRefreshed(newTokens);
|
|
98
|
+
processQueue(null, newTokens.accessToken);
|
|
99
|
+
originalRequest.headers.Authorization = `Bearer ${newTokens.accessToken}`;
|
|
100
|
+
return _axiosInstance.request(originalRequest);
|
|
101
|
+
}
|
|
102
|
+
catch (refreshError) {
|
|
103
|
+
processQueue(refreshError, null);
|
|
104
|
+
sdkConfig.onAuthFailure();
|
|
105
|
+
throw new ApiError('Session expired. Please log in again.', 401, {
|
|
106
|
+
raw: error,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
isRefreshing = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const retryableStatuses = [408, 429, 500, 502, 503, 504];
|
|
114
|
+
const maxRetries = sdkConfig.maxRetries ?? 2;
|
|
115
|
+
const retryCount = originalRequest._retryCount ?? 0;
|
|
116
|
+
if (retryableStatuses.includes(status) && retryCount < maxRetries) {
|
|
117
|
+
originalRequest._retryCount = retryCount + 1;
|
|
118
|
+
const delay = Math.pow(2, retryCount) * 1000;
|
|
119
|
+
if (sdkConfig.debug) {
|
|
120
|
+
console.log(`[SDK] ↻ Retry ${retryCount + 1}/${maxRetries} in ${delay}ms`);
|
|
121
|
+
}
|
|
122
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
123
|
+
return _axiosInstance.request(originalRequest);
|
|
124
|
+
}
|
|
125
|
+
const message = data?.message || getDefaultErrorMessage(status);
|
|
126
|
+
throw new ApiError(message, status, {
|
|
127
|
+
errors: data?.errors,
|
|
128
|
+
raw: error,
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
return _axiosInstance;
|
|
132
|
+
}
|
|
133
|
+
function getDefaultErrorMessage(status) {
|
|
134
|
+
const messages = {
|
|
135
|
+
400: 'Invalid request. Please check your input.',
|
|
136
|
+
401: 'Authentication required. Please log in.',
|
|
137
|
+
403: 'You do not have permission to perform this action.',
|
|
138
|
+
404: 'The requested resource was not found.',
|
|
139
|
+
409: 'This action conflicts with the current state.',
|
|
140
|
+
413: 'The uploaded file is too large.',
|
|
141
|
+
422: 'Validation failed. Please check your input.',
|
|
142
|
+
429: 'Too many requests. Please wait and try again.',
|
|
143
|
+
500: 'An unexpected server error occurred.',
|
|
144
|
+
502: 'The server is temporarily unavailable.',
|
|
145
|
+
503: 'The service is currently under maintenance.',
|
|
146
|
+
};
|
|
147
|
+
return messages[status] || 'An unexpected error occurred.';
|
|
148
|
+
}
|
|
149
|
+
export const httpClient = {
|
|
150
|
+
async get(url, config) {
|
|
151
|
+
const response = await getAxiosInstance().get(url, config);
|
|
152
|
+
return unwrapResponse(response);
|
|
153
|
+
},
|
|
154
|
+
async post(url, data, config) {
|
|
155
|
+
const response = await getAxiosInstance().post(url, data, config);
|
|
156
|
+
return unwrapResponse(response);
|
|
157
|
+
},
|
|
158
|
+
async put(url, data, config) {
|
|
159
|
+
const response = await getAxiosInstance().put(url, data, config);
|
|
160
|
+
return unwrapResponse(response);
|
|
161
|
+
},
|
|
162
|
+
async patch(url, data, config) {
|
|
163
|
+
const response = await getAxiosInstance().patch(url, data, config);
|
|
164
|
+
return unwrapResponse(response);
|
|
165
|
+
},
|
|
166
|
+
async delete(url, config) {
|
|
167
|
+
const response = await getAxiosInstance().delete(url, config);
|
|
168
|
+
return unwrapResponse(response);
|
|
169
|
+
},
|
|
170
|
+
async upload(url, formData, onProgress) {
|
|
171
|
+
const response = await getAxiosInstance().post(url, formData, {
|
|
172
|
+
headers: { 'Content-Type': 'multipart/form-data' },
|
|
173
|
+
onUploadProgress: onProgress
|
|
174
|
+
? (event) => {
|
|
175
|
+
const percent = Math.round(((event.loaded ?? 0) * 100) / (event.total ?? 1));
|
|
176
|
+
onProgress(percent);
|
|
177
|
+
}
|
|
178
|
+
: undefined,
|
|
179
|
+
});
|
|
180
|
+
return unwrapResponse(response);
|
|
181
|
+
},
|
|
182
|
+
get axios() {
|
|
183
|
+
return getAxiosInstance();
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
function unwrapResponse(response) {
|
|
187
|
+
const body = response.data;
|
|
188
|
+
if (body && typeof body === 'object' && 'success' in body && 'data' in body) {
|
|
189
|
+
return body.data;
|
|
190
|
+
}
|
|
191
|
+
return body;
|
|
192
|
+
}
|
|
193
|
+
export function resetHttpClient() {
|
|
194
|
+
_axiosInstance = null;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,S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,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;oBAC7E,UAAU,CAAC,OAAO,CAAC,CAAC;gBACtB,CAAC;gBACH,CAAC,CAAC,SAAS;SACd,CAAC,CAAC;QACH,OAAO,cAAc,CAAI,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,gBAAgB,EAAE,CAAC;IAC5B,CAAC;CACF,CAAC;AAOF,SAAS,cAAc,CAAI,QAAuB;IAChD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC3B,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,SAAS,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QAC5E,OAAO,IAAI,CAAC,IAAS,CAAC;IACxB,CAAC;IACD,OAAO,IAAS,CAAC;AACnB,CAAC;AAGD,MAAM,UAAU,eAAe;IAC7B,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const ENVIRONMENTS: {
|
|
2
|
+
development: {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
socketURL: string;
|
|
5
|
+
timeout: number;
|
|
6
|
+
retryAttempts: number;
|
|
7
|
+
retryDelay: number;
|
|
8
|
+
};
|
|
9
|
+
staging: {
|
|
10
|
+
baseURL: string;
|
|
11
|
+
socketURL: string;
|
|
12
|
+
timeout: number;
|
|
13
|
+
retryAttempts: number;
|
|
14
|
+
retryDelay: number;
|
|
15
|
+
};
|
|
16
|
+
production: {
|
|
17
|
+
baseURL: string;
|
|
18
|
+
socketURL: string;
|
|
19
|
+
timeout: number;
|
|
20
|
+
retryAttempts: number;
|
|
21
|
+
retryDelay: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=environments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environments.d.ts","sourceRoot":"","sources":["../../src/config/environments.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;CAsBxB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const ENVIRONMENTS = {
|
|
2
|
+
development: {
|
|
3
|
+
baseURL: 'http://localhost:5000/api',
|
|
4
|
+
socketURL: 'http://localhost:5000',
|
|
5
|
+
timeout: 30000,
|
|
6
|
+
retryAttempts: 3,
|
|
7
|
+
retryDelay: 1000,
|
|
8
|
+
},
|
|
9
|
+
staging: {
|
|
10
|
+
baseURL: 'https://staging-api.clinchdate.com/api',
|
|
11
|
+
socketURL: 'https://staging-api.clinchdate.com',
|
|
12
|
+
timeout: 30000,
|
|
13
|
+
retryAttempts: 3,
|
|
14
|
+
retryDelay: 1000,
|
|
15
|
+
},
|
|
16
|
+
production: {
|
|
17
|
+
baseURL: 'https://api.clinchdate.com/api',
|
|
18
|
+
socketURL: 'https://api.clinchdate.com',
|
|
19
|
+
timeout: 30000,
|
|
20
|
+
retryAttempts: 3,
|
|
21
|
+
retryDelay: 1000,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=environments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environments.js","sourceRoot":"","sources":["../../src/config/environments.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,WAAW,EAAE;QACX,OAAO,EAAE,2BAA2B;QACpC,SAAS,EAAE,uBAAuB;QAClC,OAAO,EAAE,KAAK;QACd,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,IAAI;KACjB;IACD,OAAO,EAAE;QACP,OAAO,EAAE,wCAAwC;QACjD,SAAS,EAAE,oCAAoC;QAC/C,OAAO,EAAE,KAAK;QACd,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,IAAI;KACjB;IACD,UAAU,EAAE;QACV,OAAO,EAAE,gCAAgC;QACzC,SAAS,EAAE,4BAA4B;QACvC,OAAO,EAAE,KAAK;QACd,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,IAAI;KACjB;CACF,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface TokenPair {
|
|
2
|
+
accessToken: string;
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ApiClientConfig {
|
|
6
|
+
baseURL: string;
|
|
7
|
+
getToken: () => Promise<string | null>;
|
|
8
|
+
getRefreshToken: () => Promise<string | null>;
|
|
9
|
+
onTokenRefreshed: (tokens: TokenPair) => Promise<void>;
|
|
10
|
+
onAuthFailure: () => void;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
defaultHeaders?: Record<string, string>;
|
|
15
|
+
platform?: 'web' | 'ios' | 'android' | 'admin';
|
|
16
|
+
}
|
|
17
|
+
export declare function configure(config: ApiClientConfig): void;
|
|
18
|
+
export declare function getConfig(): ApiClientConfig;
|
|
19
|
+
export declare function isConfigured(): boolean;
|
|
20
|
+
export declare function resetConfig(): void;
|
|
21
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAkCA,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAE9B,OAAO,EAAE,MAAM,CAAC;IAGhB,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAGvC,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAG9C,gBAAgB,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAGvD,aAAa,EAAE,MAAM,IAAI,CAAC;IAG1B,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAGhB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAGxC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,CAAC;CAChD;AAWD,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAuBvD;AAKD,wBAAgB,SAAS,IAAI,eAAe,CAU3C;AAGD,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAGD,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
let _config = null;
|
|
2
|
+
export function configure(config) {
|
|
3
|
+
if (!config.baseURL)
|
|
4
|
+
throw new Error('[ClinchDate SDK] baseURL is required');
|
|
5
|
+
if (!config.getToken)
|
|
6
|
+
throw new Error('[ClinchDate SDK] getToken is required');
|
|
7
|
+
if (!config.getRefreshToken)
|
|
8
|
+
throw new Error('[ClinchDate SDK] getRefreshToken is required');
|
|
9
|
+
if (!config.onTokenRefreshed)
|
|
10
|
+
throw new Error('[ClinchDate SDK] onTokenRefreshed is required');
|
|
11
|
+
if (!config.onAuthFailure)
|
|
12
|
+
throw new Error('[ClinchDate SDK] onAuthFailure is required');
|
|
13
|
+
_config = {
|
|
14
|
+
timeout: 15000,
|
|
15
|
+
maxRetries: 2,
|
|
16
|
+
debug: false,
|
|
17
|
+
defaultHeaders: {},
|
|
18
|
+
...config,
|
|
19
|
+
baseURL: config.baseURL.replace(/\/+$/, ''),
|
|
20
|
+
};
|
|
21
|
+
if (_config.debug) {
|
|
22
|
+
console.log('[ClinchDate SDK] Configured:', {
|
|
23
|
+
baseURL: _config.baseURL,
|
|
24
|
+
timeout: _config.timeout,
|
|
25
|
+
platform: _config.platform ?? 'auto',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function getConfig() {
|
|
30
|
+
if (!_config) {
|
|
31
|
+
throw new Error('[ClinchDate SDK] Not initialized. Call configure() at app startup.\n\n' +
|
|
32
|
+
'Example:\n' +
|
|
33
|
+
' import { configure } from "@clinchdate/api-client";\n' +
|
|
34
|
+
' configure({ baseURL: "...", getToken: ..., ... });\n');
|
|
35
|
+
}
|
|
36
|
+
return _config;
|
|
37
|
+
}
|
|
38
|
+
export function isConfigured() {
|
|
39
|
+
return _config !== null;
|
|
40
|
+
}
|
|
41
|
+
export function resetConfig() {
|
|
42
|
+
_config = null;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AA2EA,IAAI,OAAO,GAA2B,IAAI,CAAC;AAK3C,MAAM,UAAU,SAAS,CAAC,MAAuB;IAC/C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC7E,IAAI,CAAC,MAAM,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC/E,IAAI,CAAC,MAAM,CAAC,eAAe;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAC7F,IAAI,CAAC,MAAM,CAAC,gBAAgB;QAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IAC/F,IAAI,CAAC,MAAM,CAAC,aAAa;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAEzF,OAAO,GAAG;QACR,OAAO,EAAE,KAAK;QACd,UAAU,EAAE,CAAC;QACb,KAAK,EAAE,KAAK;QACZ,cAAc,EAAE,EAAE;QAClB,GAAG,MAAM;QACT,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;KAC5C,CAAC;IAEF,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE;YAC1C,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,MAAM;SACrC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAKD,MAAM,UAAU,SAAS;IACvB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,wEAAwE;YACtE,YAAY;YACZ,yDAAyD;YACzD,wDAAwD,CAC3D,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAGD,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,KAAK,IAAI,CAAC;AAC1B,CAAC;AAGD,MAAM,UAAU,WAAW;IACzB,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UserProfile, LoginRequest, RegisterRequest } from '../types/auth.types';
|
|
2
|
+
import { ApiClientError } from '../types/common.types';
|
|
3
|
+
export declare function useAuth(): {
|
|
4
|
+
user: UserProfile | null;
|
|
5
|
+
setUser: import("react").Dispatch<import("react").SetStateAction<UserProfile | null>>;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
error: ApiClientError | null;
|
|
8
|
+
login: (credentials: LoginRequest) => Promise<import("..").AuthResponse>;
|
|
9
|
+
register: (data: RegisterRequest) => Promise<import("..").AuthResponse>;
|
|
10
|
+
logout: () => Promise<void>;
|
|
11
|
+
clearError: () => void;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=useAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD,wBAAgB,OAAO;;;;;yBAKyB,YAAY;qBAmBhB,eAAe;;;EAsC1D"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { AuthService } from '../services/auth.service';
|
|
3
|
+
import { ApiClientError } from '../types/common.types';
|
|
4
|
+
const authService = new AuthService();
|
|
5
|
+
export function useAuth() {
|
|
6
|
+
const [user, setUser] = useState(null);
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
const [error, setError] = useState(null);
|
|
9
|
+
const login = useCallback(async (credentials) => {
|
|
10
|
+
setLoading(true);
|
|
11
|
+
setError(null);
|
|
12
|
+
try {
|
|
13
|
+
const response = await authService.login(credentials);
|
|
14
|
+
setUser(response.user);
|
|
15
|
+
return response;
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
const apiError = err instanceof ApiClientError
|
|
19
|
+
? err
|
|
20
|
+
: new ApiClientError('UNKNOWN', 'Login failed');
|
|
21
|
+
setError(apiError);
|
|
22
|
+
throw apiError;
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
setLoading(false);
|
|
26
|
+
}
|
|
27
|
+
}, []);
|
|
28
|
+
const register = useCallback(async (data) => {
|
|
29
|
+
setLoading(true);
|
|
30
|
+
setError(null);
|
|
31
|
+
try {
|
|
32
|
+
const response = await authService.register(data);
|
|
33
|
+
setUser(response.user);
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
const apiError = err instanceof ApiClientError
|
|
38
|
+
? err
|
|
39
|
+
: new ApiClientError('UNKNOWN', 'Registration failed');
|
|
40
|
+
setError(apiError);
|
|
41
|
+
throw apiError;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
setLoading(false);
|
|
45
|
+
}
|
|
46
|
+
}, []);
|
|
47
|
+
const logout = useCallback(async () => {
|
|
48
|
+
setLoading(true);
|
|
49
|
+
try {
|
|
50
|
+
await authService.logout();
|
|
51
|
+
setUser(null);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
const apiError = err instanceof ApiClientError
|
|
55
|
+
? err
|
|
56
|
+
: new ApiClientError('UNKNOWN', 'Logout failed');
|
|
57
|
+
setError(apiError);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
setLoading(false);
|
|
61
|
+
}
|
|
62
|
+
}, []);
|
|
63
|
+
const clearError = useCallback(() => setError(null), []);
|
|
64
|
+
return { user, setUser, loading, error, login, register, logout, clearError };
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=useAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuth.js","sourceRoot":"","sources":["../../src/hooks/useAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,MAAM,UAAU,OAAO;IACrB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAC;IAC3D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAwB,IAAI,CAAC,CAAC;IAEhE,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,WAAyB,EAAE,EAAE;QAC5D,UAAU,CAAC,IAAI,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MAAM,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACpC,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,CAAC;YACH,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;YAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,QAAQ,GACZ,GAAG,YAAY,cAAc;gBAC3B,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,IAAI,cAAc,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;YACrD,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAEzD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare function useCall(): {
|
|
2
|
+
loading: boolean;
|
|
3
|
+
error: string | null;
|
|
4
|
+
clearError: () => void;
|
|
5
|
+
createVideoRoom: (roomName: string, maxParticipants?: number) => Promise<{
|
|
6
|
+
roomSid: string;
|
|
7
|
+
roomName: string;
|
|
8
|
+
callType: string;
|
|
9
|
+
maxParticipants: number;
|
|
10
|
+
}>;
|
|
11
|
+
joinVideoCall: (roomName: string) => Promise<{
|
|
12
|
+
token: string;
|
|
13
|
+
roomName: string;
|
|
14
|
+
}>;
|
|
15
|
+
endVideoCall: (roomSid: string) => Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
message: string;
|
|
18
|
+
}>;
|
|
19
|
+
muteAudio: (roomSid: string) => Promise<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
message: string;
|
|
22
|
+
} | undefined>;
|
|
23
|
+
unmuteAudio: (roomSid: string) => Promise<{
|
|
24
|
+
success: boolean;
|
|
25
|
+
message: string;
|
|
26
|
+
} | undefined>;
|
|
27
|
+
initiateAudioCall: (recipientId: string) => Promise<{
|
|
28
|
+
callId: string;
|
|
29
|
+
status: string;
|
|
30
|
+
}>;
|
|
31
|
+
acceptAudioCall: (callId: string) => Promise<{
|
|
32
|
+
callId: string;
|
|
33
|
+
token: string;
|
|
34
|
+
status: string;
|
|
35
|
+
}>;
|
|
36
|
+
rejectAudioCall: (callId: string) => Promise<{
|
|
37
|
+
success: boolean;
|
|
38
|
+
message: string;
|
|
39
|
+
} | undefined>;
|
|
40
|
+
endAudioCall: (callId: string) => Promise<{
|
|
41
|
+
callId: string;
|
|
42
|
+
duration: number;
|
|
43
|
+
status: string;
|
|
44
|
+
}>;
|
|
45
|
+
getCallHistory: (limit?: number) => Promise<{
|
|
46
|
+
callId: string;
|
|
47
|
+
type: string;
|
|
48
|
+
status: string;
|
|
49
|
+
duration: number | null;
|
|
50
|
+
otherUserId: string;
|
|
51
|
+
startedAt: string;
|
|
52
|
+
endedAt: string | null;
|
|
53
|
+
}[]>;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=useCall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCall.d.ts","sourceRoot":"","sources":["../../src/hooks/useCall.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO;;;;gCASF,MAAM,oBAAmB,MAAM;;;;;;8BAeC,MAAM;;;;4BAaR,MAAM;;;;yBAaT,MAAM;;;;2BASJ,MAAM;;;;qCAWI,MAAM;;;;8BAab,MAAM;;;;;8BAaN,MAAM;;;;2BAST,MAAM;;;;;6BAaL,MAAM;;;;;;;;;EA8BxD"}
|