@vritti/quantum-ui 0.1.22 → 0.2.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.
Files changed (91) hide show
  1. package/dist/Button.d.ts +10 -3
  2. package/dist/Button.js +21 -36
  3. package/dist/Button.js.map +1 -1
  4. package/dist/Button2.js +42 -0
  5. package/dist/Button2.js.map +1 -0
  6. package/dist/Card.d.ts +8 -8
  7. package/dist/Card.js.map +1 -1
  8. package/dist/Checkbox.d.ts +5 -8
  9. package/dist/Checkbox.js +38 -278
  10. package/dist/Checkbox.js.map +1 -1
  11. package/dist/DatePicker.d.ts +68 -0
  12. package/dist/DatePicker.js +12038 -0
  13. package/dist/DatePicker.js.map +1 -0
  14. package/dist/Form.d.ts +70 -88
  15. package/dist/Form.js +34 -30
  16. package/dist/Form.js.map +1 -1
  17. package/dist/Label.js +40 -0
  18. package/dist/Label.js.map +1 -0
  19. package/dist/OTPField.js +2 -12
  20. package/dist/OTPField.js.map +1 -1
  21. package/dist/PasswordField.js.map +1 -1
  22. package/dist/PhoneField.js +6 -12
  23. package/dist/PhoneField.js.map +1 -1
  24. package/dist/Skeleton.d.ts +6 -0
  25. package/dist/Skeleton.js +9 -0
  26. package/dist/Skeleton.js.map +1 -0
  27. package/dist/Spinner.d.ts +14 -0
  28. package/dist/Spinner.js +31 -0
  29. package/dist/Spinner.js.map +1 -0
  30. package/dist/TextArea.js +4 -10
  31. package/dist/TextArea.js.map +1 -1
  32. package/dist/TextField.js.map +1 -1
  33. package/dist/ThemeToggle.js.map +1 -1
  34. package/dist/Typography.js.map +1 -1
  35. package/dist/assets/quantum-ui.css +66 -44
  36. package/dist/axios.d.ts +11 -6
  37. package/dist/axios.js +186 -147
  38. package/dist/axios.js.map +1 -1
  39. package/dist/components/Button.d.ts +7 -0
  40. package/dist/components/Button.js +2 -1
  41. package/dist/components/Button.js.map +1 -1
  42. package/dist/components/Card.d.ts +7 -0
  43. package/dist/components/Checkbox.d.ts +7 -0
  44. package/dist/components/DatePicker.d.ts +9 -0
  45. package/dist/components/DatePicker.js +2 -0
  46. package/dist/components/DatePicker.js.map +1 -0
  47. package/dist/components/Form.d.ts +7 -0
  48. package/dist/components/Form.js +1 -1
  49. package/dist/components/OTPField.d.ts +7 -0
  50. package/dist/components/PasswordField.d.ts +7 -0
  51. package/dist/components/PhoneField.d.ts +7 -0
  52. package/dist/components/Progress.d.ts +7 -0
  53. package/dist/components/Progress.js +2 -5
  54. package/dist/components/Progress.js.map +1 -1
  55. package/dist/components/Skeleton.d.ts +9 -0
  56. package/dist/components/Skeleton.js +2 -0
  57. package/dist/components/Skeleton.js.map +1 -0
  58. package/dist/components/Spinner.d.ts +9 -0
  59. package/dist/components/Spinner.js +2 -0
  60. package/dist/components/Spinner.js.map +1 -0
  61. package/dist/components/TextArea.d.ts +7 -0
  62. package/dist/components/TextField.d.ts +7 -0
  63. package/dist/components/ThemeToggle.d.ts +7 -0
  64. package/dist/components/Typography.d.ts +7 -0
  65. package/dist/createLucideIcon.js.map +1 -1
  66. package/dist/field.js +26 -177
  67. package/dist/field.js.map +1 -1
  68. package/dist/index.d.ts +146 -142
  69. package/dist/index.js +10 -7
  70. package/dist/index.js.map +1 -1
  71. package/dist/index2.js +54 -116
  72. package/dist/index2.js.map +1 -1
  73. package/dist/index3.js +103 -1
  74. package/dist/index3.js.map +1 -1
  75. package/dist/index4.js +31 -55
  76. package/dist/index4.js.map +1 -1
  77. package/dist/index5.js +90 -3
  78. package/dist/index5.js.map +1 -1
  79. package/dist/index6.js +246 -0
  80. package/dist/index6.js.map +1 -0
  81. package/dist/shadcn/shadcnField.d.ts +7 -0
  82. package/dist/utils/axios.d.ts +21 -6
  83. package/dist/utils/axios.js +1 -1
  84. package/dist/utils.js.map +1 -1
  85. package/package.json +33 -17
  86. package/dist/AuthProvider.d.ts +0 -34
  87. package/dist/OnboardingProvider.js +0 -113
  88. package/dist/OnboardingProvider.js.map +0 -1
  89. package/dist/context/AuthProvider.d.ts +0 -2
  90. package/dist/context/AuthProvider.js +0 -2
  91. 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,106 @@ 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 recoverToken() {
3920
+ const config = getConfig();
3921
+ try {
3922
+ const response = await axios$1.get("/auth/token", {
3923
+ baseURL: config.axios.baseURL,
3924
+ withCredentials: true,
3925
+ timeout: config.axios.timeout
3926
+ });
3927
+ if (response.data.accessToken) {
3928
+ setToken(response.data.accessToken);
3929
+ return { success: true, expiresIn: response.data.expiresIn };
3930
+ }
3931
+ return { success: false, expiresIn: 0 };
3932
+ } catch {
3933
+ clearToken();
3934
+ return { success: false, expiresIn: 0 };
3916
3935
  }
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;
3936
+ }
3937
+ async function recoverTokenIfNeeded() {
3938
+ if (accessToken) return true;
3939
+ if (sessionRecoveryPromise) {
3940
+ return sessionRecoveryPromise;
3941
+ }
3942
+ sessionRecoveryPromise = (async () => {
3943
+ try {
3944
+ const result = await recoverToken();
3945
+ if (result.success) {
3946
+ scheduleTokenRefresh(result.expiresIn);
3947
+ return true;
3948
+ }
3949
+ return false;
3950
+ } catch {
3951
+ return false;
3952
+ } finally {
3953
+ sessionRecoveryPromise = null;
3954
+ }
3955
+ })();
3956
+ return sessionRecoveryPromise;
3957
+ }
3958
+ function scheduleTokenRefresh(expiresIn) {
3959
+ cancelTokenRefresh();
3960
+ const refreshAt = expiresIn * 0.8 * 1e3;
3961
+ refreshTimer = setTimeout(async () => {
3962
+ const config = getConfig();
3963
+ try {
3964
+ const response = await axios$1.post(
3965
+ "/auth/refresh",
3966
+ {},
3967
+ {
3968
+ baseURL: config.axios.baseURL,
3969
+ withCredentials: true,
3970
+ timeout: config.axios.timeout
3971
+ }
3972
+ );
3973
+ if (response.data.accessToken) {
3974
+ setToken(response.data.accessToken);
3975
+ scheduleTokenRefresh(response.data.expiresIn);
3976
+ }
3977
+ } catch {
3978
+ clearToken();
3979
+ redirectToLogin();
3935
3980
  }
3981
+ }, refreshAt);
3982
+ }
3983
+ function cancelTokenRefresh() {
3984
+ if (refreshTimer) {
3985
+ clearTimeout(refreshTimer);
3986
+ refreshTimer = null;
3936
3987
  }
3937
- return null;
3938
- };
3988
+ }
3939
3989
  async function fetchCsrfToken() {
3940
- if (csrfFetchPromise) {
3941
- return csrfFetchPromise;
3942
- }
3990
+ if (csrfFetchPromise) return csrfFetchPromise;
3943
3991
  csrfFetchPromise = (async () => {
3944
3992
  try {
3945
3993
  const config = getConfig();
3946
- if (!config.csrf.enabled) {
3947
- return null;
3948
- }
3994
+ if (!config.csrf.enabled) return null;
3949
3995
  const response = await axios$1.get(config.csrf.endpoint, {
3950
3996
  baseURL: config.axios.baseURL,
3951
3997
  withCredentials: config.axios.withCredentials,
@@ -3956,10 +4002,8 @@ async function fetchCsrfToken() {
3956
4002
  setCsrfToken(token);
3957
4003
  return token;
3958
4004
  }
3959
- console.warn("[axios] CSRF endpoint did not return a csrfToken field");
3960
4005
  return null;
3961
- } catch (error) {
3962
- console.error("[axios] Failed to fetch CSRF token:", error);
4006
+ } catch {
3963
4007
  return null;
3964
4008
  } finally {
3965
4009
  csrfFetchPromise = null;
@@ -3967,6 +4011,22 @@ async function fetchCsrfToken() {
3967
4011
  })();
3968
4012
  return csrfFetchPromise;
3969
4013
  }
4014
+ function redirectToLogin() {
4015
+ if (typeof window !== "undefined") {
4016
+ window.location.href = "/login";
4017
+ }
4018
+ }
4019
+ function getSubdomain() {
4020
+ if (typeof window === "undefined") return null;
4021
+ const parts = window.location.hostname.split(".");
4022
+ if (parts.length >= 2 && parts[parts.length - 1] === "localhost") {
4023
+ return parts[0];
4024
+ }
4025
+ if (parts.length >= 3) {
4026
+ return parts[0];
4027
+ }
4028
+ return null;
4029
+ }
3970
4030
  function createAxiosInstance() {
3971
4031
  const config = getConfig();
3972
4032
  return axios$1.create({
@@ -3977,65 +4037,44 @@ function createAxiosInstance() {
3977
4037
  });
3978
4038
  }
3979
4039
  const axios = createAxiosInstance();
3980
- const getSubdomain = () => {
3981
- if (typeof window === "undefined") {
3982
- return null;
4040
+ axios.interceptors.request.use(async (config) => {
4041
+ const quantumConfig = getConfig();
4042
+ const isPublicRequest = config.public === true;
4043
+ if (!isPublicRequest) {
4044
+ const hasSession = await recoverTokenIfNeeded();
4045
+ if (!hasSession) {
4046
+ redirectToLogin();
4047
+ return Promise.reject(new Error("No valid session"));
4048
+ }
4049
+ }
4050
+ const token = getToken();
4051
+ if (token) {
4052
+ config.headers[quantumConfig.auth.tokenHeaderName] = `${quantumConfig.auth.tokenPrefix} ${token}`;
4053
+ }
4054
+ const subdomain = getSubdomain();
4055
+ if (subdomain) {
4056
+ config.headers["x-subdomain"] = subdomain;
4057
+ }
4058
+ const isStateChanging = ["post", "put", "patch", "delete"].includes(config.method?.toLowerCase() || "");
4059
+ if (isStateChanging && quantumConfig.csrf.enabled) {
4060
+ let csrf = getCsrfToken();
4061
+ if (!csrf) csrf = await fetchCsrfToken();
4062
+ if (csrf) config.headers[quantumConfig.csrf.headerName] = csrf;
3983
4063
  }
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);
4025
- }
4026
- );
4064
+ return config;
4065
+ });
4027
4066
  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;
4067
+ (response) => response,
4068
+ (error) => {
4069
+ const isPublicRequest = error.config?.public === true;
4070
+ if (error.response?.status === 401 && !isPublicRequest) {
4071
+ clearToken();
4072
+ cancelTokenRefresh();
4073
+ redirectToLogin();
4035
4074
  }
4036
4075
  return Promise.reject(error);
4037
4076
  }
4038
4077
  );
4039
4078
 
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 };
4079
+ export { axios as a, cancelTokenRefresh as b, configureQuantumUI as c, defineConfig as d, clearCsrfToken as e, clearToken as f, getConfig as g, getCsrfToken as h, getToken as i, recoverToken as j, setCsrfToken as k, setToken as l, resetConfig as r, scheduleTokenRefresh as s };
4041
4080
  //# sourceMappingURL=axios.js.map