@vritti/quantum-ui 0.1.21 → 0.1.23

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.
Files changed (69) hide show
  1. package/dist/Checkbox.js +2 -253
  2. package/dist/Checkbox.js.map +1 -1
  3. package/dist/Combination.js +3869 -0
  4. package/dist/Combination.js.map +1 -0
  5. package/dist/DataTable.d.ts +31 -0
  6. package/dist/DataTable.js +4989 -0
  7. package/dist/DataTable.js.map +1 -0
  8. package/dist/DatePicker.d.ts +68 -0
  9. package/dist/DatePicker.js +8229 -0
  10. package/dist/DatePicker.js.map +1 -0
  11. package/dist/Input.js +22 -0
  12. package/dist/Input.js.map +1 -0
  13. package/dist/Label.js +40 -0
  14. package/dist/Label.js.map +1 -0
  15. package/dist/PhoneField.js +2 -2
  16. package/dist/PhoneField.js.map +1 -1
  17. package/dist/Skeleton.d.ts +6 -0
  18. package/dist/Skeleton.js +18 -0
  19. package/dist/Skeleton.js.map +1 -0
  20. package/dist/TextField.js +2 -18
  21. package/dist/TextField.js.map +1 -1
  22. package/dist/ThemeToggle.js +15 -3
  23. package/dist/ThemeToggle.js.map +1 -1
  24. package/dist/assets/quantum-ui.css +186 -108
  25. package/dist/axios.d.ts +11 -6
  26. package/dist/axios.js +191 -147
  27. package/dist/axios.js.map +1 -1
  28. package/dist/check.js +15 -0
  29. package/dist/check.js.map +1 -0
  30. package/dist/components/Button.d.ts +7 -0
  31. package/dist/components/Card.d.ts +7 -0
  32. package/dist/components/Checkbox.d.ts +7 -0
  33. package/dist/components/DataTable.d.ts +9 -0
  34. package/dist/components/DataTable.js +2 -0
  35. package/dist/components/DataTable.js.map +1 -0
  36. package/dist/components/DatePicker.d.ts +9 -0
  37. package/dist/components/DatePicker.js +2 -0
  38. package/dist/components/DatePicker.js.map +1 -0
  39. package/dist/components/Form.d.ts +7 -0
  40. package/dist/components/OTPField.d.ts +7 -0
  41. package/dist/components/PasswordField.d.ts +7 -0
  42. package/dist/components/PhoneField.d.ts +7 -0
  43. package/dist/components/Progress.d.ts +7 -0
  44. package/dist/components/Skeleton.d.ts +9 -0
  45. package/dist/components/Skeleton.js +2 -0
  46. package/dist/components/Skeleton.js.map +1 -0
  47. package/dist/components/TextArea.d.ts +7 -0
  48. package/dist/components/TextField.d.ts +7 -0
  49. package/dist/components/ThemeToggle.d.ts +7 -0
  50. package/dist/components/Typography.d.ts +7 -0
  51. package/dist/field.js +1 -34
  52. package/dist/field.js.map +1 -1
  53. package/dist/index.d.ts +69 -38
  54. package/dist/index.js +8 -6
  55. package/dist/index.js.map +1 -1
  56. package/dist/index5.js +5 -2
  57. package/dist/index5.js.map +1 -1
  58. package/dist/index6.js +246 -0
  59. package/dist/index6.js.map +1 -0
  60. package/dist/shadcn/shadcnField.d.ts +7 -0
  61. package/dist/utils/axios.d.ts +21 -6
  62. package/dist/utils/axios.js +1 -1
  63. package/package.json +27 -13
  64. package/dist/AuthProvider.d.ts +0 -34
  65. package/dist/OnboardingProvider.js +0 -113
  66. package/dist/OnboardingProvider.js.map +0 -1
  67. package/dist/context/AuthProvider.d.ts +0 -2
  68. package/dist/context/AuthProvider.js +0 -2
  69. package/dist/context/AuthProvider.js.map +0 -1
package/dist/axios.js CHANGED
@@ -1,3 +1,54 @@
1
+ const defaultConfig = {
2
+ csrf: {
3
+ endpoint: "/csrf/token",
4
+ enabled: true,
5
+ headerName: "x-csrf-token"
6
+ },
7
+ axios: {
8
+ baseURL: "/api",
9
+ timeout: 3e4,
10
+ withCredentials: true,
11
+ headers: {
12
+ "Content-Type": "application/json",
13
+ Accept: "application/json"
14
+ }
15
+ },
16
+ auth: {
17
+ tokenHeaderName: "Authorization",
18
+ tokenPrefix: "Bearer"
19
+ }
20
+ };
21
+ let currentConfig = { ...defaultConfig };
22
+ function defineConfig(config) {
23
+ return config;
24
+ }
25
+ function configureQuantumUI(userConfig) {
26
+ currentConfig = {
27
+ csrf: {
28
+ ...defaultConfig.csrf,
29
+ ...userConfig.csrf || {}
30
+ },
31
+ axios: {
32
+ ...defaultConfig.axios,
33
+ ...userConfig.axios || {},
34
+ headers: {
35
+ ...defaultConfig.axios.headers,
36
+ ...userConfig.axios?.headers || {}
37
+ }
38
+ },
39
+ auth: {
40
+ ...defaultConfig.auth,
41
+ ...userConfig.auth || {}
42
+ }
43
+ };
44
+ }
45
+ function getConfig() {
46
+ return currentConfig;
47
+ }
48
+ function resetConfig() {
49
+ currentConfig = { ...defaultConfig };
50
+ }
51
+
1
52
  function bind(fn, thisArg) {
2
53
  return function wrap() {
3
54
  return fn.apply(thisArg, arguments);
@@ -3841,111 +3892,109 @@ const {
3841
3892
  mergeConfig
3842
3893
  } = axios$1;
3843
3894
 
3844
- const defaultConfig = {
3845
- csrf: {
3846
- endpoint: "/csrf/token",
3847
- enabled: true,
3848
- headerName: "x-csrf-token"
3849
- },
3850
- axios: {
3851
- baseURL: "/api",
3852
- timeout: 3e4,
3853
- withCredentials: true,
3854
- headers: {
3855
- "Content-Type": "application/json",
3856
- Accept: "application/json"
3857
- }
3858
- },
3859
- auth: {
3860
- tokenHeaderName: "Authorization",
3861
- tokenPrefix: "Bearer"
3862
- }
3863
- };
3864
- let currentConfig = { ...defaultConfig };
3865
- function defineConfig(config) {
3866
- return config;
3867
- }
3868
- function configureQuantumUI(userConfig) {
3869
- currentConfig = {
3870
- csrf: {
3871
- ...defaultConfig.csrf,
3872
- ...userConfig.csrf || {}
3873
- },
3874
- axios: {
3875
- ...defaultConfig.axios,
3876
- ...userConfig.axios || {},
3877
- headers: {
3878
- ...defaultConfig.axios.headers,
3879
- ...userConfig.axios?.headers || {}
3880
- }
3881
- },
3882
- auth: {
3883
- ...defaultConfig.auth,
3884
- ...userConfig.auth || {}
3885
- }
3886
- };
3887
- }
3888
- function getConfig() {
3889
- return currentConfig;
3890
- }
3891
- function resetConfig() {
3892
- currentConfig = { ...defaultConfig };
3893
- }
3894
-
3895
- const tokenStore = {};
3895
+ let accessToken = null;
3896
+ let refreshTimer = null;
3897
+ let sessionRecoveryPromise = null;
3896
3898
  let csrfToken = null;
3897
3899
  let csrfFetchPromise = null;
3898
- const setCsrfToken = (token) => {
3899
- if (!token || typeof token !== "string") {
3900
- console.warn("[axios] Invalid CSRF token provided");
3901
- return;
3900
+ const setToken = (token) => {
3901
+ if (token && typeof token === "string") {
3902
+ accessToken = token;
3902
3903
  }
3903
- csrfToken = token;
3904
3904
  };
3905
- const getCsrfToken = () => {
3906
- return csrfToken;
3905
+ const getToken = () => accessToken;
3906
+ const clearToken = () => {
3907
+ accessToken = null;
3908
+ cancelTokenRefresh();
3907
3909
  };
3910
+ const setCsrfToken = (token) => {
3911
+ if (token && typeof token === "string") {
3912
+ csrfToken = token;
3913
+ }
3914
+ };
3915
+ const getCsrfToken = () => csrfToken;
3908
3916
  const clearCsrfToken = () => {
3909
3917
  csrfToken = null;
3910
3918
  };
3911
- const TOKEN_PRIORITY = ["access", "refresh", "onboarding"];
3912
- const setToken = (type, token) => {
3913
- if (!token || typeof token !== "string") {
3914
- console.warn(`[axios] Invalid token provided for type: ${type}`);
3915
- return;
3919
+ async function recoverSession() {
3920
+ const config = getConfig();
3921
+ try {
3922
+ const response = await axios$1.get(
3923
+ "/auth/token",
3924
+ {
3925
+ baseURL: config.axios.baseURL,
3926
+ withCredentials: true,
3927
+ timeout: config.axios.timeout
3928
+ }
3929
+ );
3930
+ if (response.data.accessToken) {
3931
+ setToken(response.data.accessToken);
3932
+ return { success: true, expiresIn: response.data.expiresIn };
3933
+ }
3934
+ return { success: false, expiresIn: 0 };
3935
+ } catch {
3936
+ clearToken();
3937
+ return { success: false, expiresIn: 0 };
3916
3938
  }
3917
- tokenStore[type] = token;
3918
- };
3919
- const getToken = (type) => {
3920
- return tokenStore[type] || null;
3921
- };
3922
- const clearToken = (type) => {
3923
- delete tokenStore[type];
3924
- };
3925
- const clearAllTokens = () => {
3926
- Object.keys(tokenStore).forEach((key) => {
3927
- delete tokenStore[key];
3928
- });
3929
- };
3930
- const getActiveToken = () => {
3931
- for (const tokenType of TOKEN_PRIORITY) {
3932
- const token = tokenStore[tokenType];
3933
- if (token) {
3934
- return token;
3939
+ }
3940
+ async function recoverSessionIfNeeded() {
3941
+ if (accessToken) return true;
3942
+ if (sessionRecoveryPromise) {
3943
+ return sessionRecoveryPromise;
3944
+ }
3945
+ sessionRecoveryPromise = (async () => {
3946
+ try {
3947
+ const result = await recoverSession();
3948
+ if (result.success) {
3949
+ scheduleTokenRefresh(result.expiresIn);
3950
+ return true;
3951
+ }
3952
+ return false;
3953
+ } catch {
3954
+ return false;
3955
+ } finally {
3956
+ sessionRecoveryPromise = null;
3957
+ }
3958
+ })();
3959
+ return sessionRecoveryPromise;
3960
+ }
3961
+ function scheduleTokenRefresh(expiresIn) {
3962
+ cancelTokenRefresh();
3963
+ const refreshAt = expiresIn * 0.8 * 1e3;
3964
+ refreshTimer = setTimeout(async () => {
3965
+ const config = getConfig();
3966
+ try {
3967
+ const response = await axios$1.post(
3968
+ "/auth/refresh",
3969
+ {},
3970
+ {
3971
+ baseURL: config.axios.baseURL,
3972
+ withCredentials: true,
3973
+ timeout: config.axios.timeout
3974
+ }
3975
+ );
3976
+ if (response.data.accessToken) {
3977
+ setToken(response.data.accessToken);
3978
+ scheduleTokenRefresh(response.data.expiresIn);
3979
+ }
3980
+ } catch {
3981
+ clearToken();
3982
+ redirectToLogin();
3935
3983
  }
3984
+ }, refreshAt);
3985
+ }
3986
+ function cancelTokenRefresh() {
3987
+ if (refreshTimer) {
3988
+ clearTimeout(refreshTimer);
3989
+ refreshTimer = null;
3936
3990
  }
3937
- return null;
3938
- };
3991
+ }
3939
3992
  async function fetchCsrfToken() {
3940
- if (csrfFetchPromise) {
3941
- return csrfFetchPromise;
3942
- }
3993
+ if (csrfFetchPromise) return csrfFetchPromise;
3943
3994
  csrfFetchPromise = (async () => {
3944
3995
  try {
3945
3996
  const config = getConfig();
3946
- if (!config.csrf.enabled) {
3947
- return null;
3948
- }
3997
+ if (!config.csrf.enabled) return null;
3949
3998
  const response = await axios$1.get(config.csrf.endpoint, {
3950
3999
  baseURL: config.axios.baseURL,
3951
4000
  withCredentials: config.axios.withCredentials,
@@ -3956,10 +4005,8 @@ async function fetchCsrfToken() {
3956
4005
  setCsrfToken(token);
3957
4006
  return token;
3958
4007
  }
3959
- console.warn("[axios] CSRF endpoint did not return a csrfToken field");
3960
4008
  return null;
3961
- } catch (error) {
3962
- console.error("[axios] Failed to fetch CSRF token:", error);
4009
+ } catch {
3963
4010
  return null;
3964
4011
  } finally {
3965
4012
  csrfFetchPromise = null;
@@ -3967,6 +4014,22 @@ async function fetchCsrfToken() {
3967
4014
  })();
3968
4015
  return csrfFetchPromise;
3969
4016
  }
4017
+ function redirectToLogin() {
4018
+ if (typeof window !== "undefined") {
4019
+ window.location.href = "/login";
4020
+ }
4021
+ }
4022
+ function getSubdomain() {
4023
+ if (typeof window === "undefined") return null;
4024
+ const parts = window.location.hostname.split(".");
4025
+ if (parts.length >= 2 && parts[parts.length - 1] === "localhost") {
4026
+ return parts[0];
4027
+ }
4028
+ if (parts.length >= 3) {
4029
+ return parts[0];
4030
+ }
4031
+ return null;
4032
+ }
3970
4033
  function createAxiosInstance() {
3971
4034
  const config = getConfig();
3972
4035
  return axios$1.create({
@@ -3977,65 +4040,46 @@ function createAxiosInstance() {
3977
4040
  });
3978
4041
  }
3979
4042
  const axios = createAxiosInstance();
3980
- const getSubdomain = () => {
3981
- if (typeof window === "undefined") {
3982
- return null;
3983
- }
3984
- const hostname = window.location.hostname;
3985
- const parts = hostname.split(".");
3986
- if (parts.length >= 2 && parts[parts.length - 1] === "localhost") {
3987
- return parts[0];
3988
- }
3989
- if (parts.length >= 3) {
3990
- return parts[0];
3991
- }
3992
- return null;
3993
- };
3994
- axios.interceptors.request.use(
3995
- async (config) => {
3996
- const quantumConfig = getConfig();
3997
- const token = getActiveToken();
3998
- if (token) {
3999
- const authHeaderName = quantumConfig.auth.tokenHeaderName;
4000
- const tokenPrefix = quantumConfig.auth.tokenPrefix;
4001
- config.headers[authHeaderName] = `${tokenPrefix} ${token}`;
4002
- }
4003
- const subdomain = getSubdomain();
4004
- if (subdomain) {
4005
- config.headers["x-subdomain"] = subdomain;
4006
- }
4007
- const isStateChangingRequest = ["post", "put", "patch", "delete"].includes(
4008
- config.method?.toLowerCase() || ""
4009
- );
4010
- if (isStateChangingRequest && quantumConfig.csrf.enabled) {
4011
- let csrfTokenValue = getCsrfToken();
4012
- if (!csrfTokenValue) {
4013
- csrfTokenValue = await fetchCsrfToken();
4014
- }
4015
- if (csrfTokenValue) {
4016
- config.headers[quantumConfig.csrf.headerName] = csrfTokenValue;
4017
- } else {
4018
- console.warn("[axios] CSRF token not available for state-changing request");
4019
- }
4020
- }
4021
- return config;
4022
- },
4023
- (error) => {
4024
- return Promise.reject(error);
4043
+ axios.interceptors.request.use(async (config) => {
4044
+ const quantumConfig = getConfig();
4045
+ const isPublicRequest = config.public === true;
4046
+ if (!isPublicRequest) {
4047
+ const hasSession = await recoverSessionIfNeeded();
4048
+ if (!hasSession) {
4049
+ redirectToLogin();
4050
+ return Promise.reject(new Error("No valid session"));
4051
+ }
4052
+ }
4053
+ const token = getToken();
4054
+ if (token) {
4055
+ config.headers[quantumConfig.auth.tokenHeaderName] = `${quantumConfig.auth.tokenPrefix} ${token}`;
4056
+ }
4057
+ const subdomain = getSubdomain();
4058
+ if (subdomain) {
4059
+ config.headers["x-subdomain"] = subdomain;
4060
+ }
4061
+ const isStateChanging = ["post", "put", "patch", "delete"].includes(
4062
+ config.method?.toLowerCase() || ""
4063
+ );
4064
+ if (isStateChanging && quantumConfig.csrf.enabled) {
4065
+ let csrf = getCsrfToken();
4066
+ if (!csrf) csrf = await fetchCsrfToken();
4067
+ if (csrf) config.headers[quantumConfig.csrf.headerName] = csrf;
4025
4068
  }
4026
- );
4069
+ return config;
4070
+ });
4027
4071
  axios.interceptors.response.use(
4028
- (response) => {
4029
- return response;
4030
- },
4031
- async (error) => {
4032
- const originalRequest = error.config;
4033
- if (error.response?.status === 401 && !originalRequest._retry) {
4034
- originalRequest._retry = true;
4072
+ (response) => response,
4073
+ (error) => {
4074
+ const isPublicRequest = error.config?.public === true;
4075
+ if (error.response?.status === 401 && !isPublicRequest) {
4076
+ clearToken();
4077
+ cancelTokenRefresh();
4078
+ redirectToLogin();
4035
4079
  }
4036
4080
  return Promise.reject(error);
4037
4081
  }
4038
4082
  );
4039
4083
 
4040
- export { axios as a, getToken as b, configureQuantumUI as c, defineConfig as d, clearToken as e, clearAllTokens as f, getConfig as g, setCsrfToken as h, getCsrfToken as i, clearCsrfToken as j, resetConfig as r, setToken as s };
4084
+ export { axios as a, getToken as b, configureQuantumUI as c, defineConfig as d, clearToken as e, recoverSession as f, getConfig as g, scheduleTokenRefresh as h, cancelTokenRefresh as i, setCsrfToken as j, getCsrfToken as k, clearCsrfToken as l, resetConfig as r, setToken as s };
4041
4085
  //# sourceMappingURL=axios.js.map