@explita/cloud-auth-client 0.0.2 → 0.1.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,4 @@
1
+ import React from "react";
2
+ export declare function LockIcon({ size }: {
3
+ size?: number;
4
+ }): React.JSX.Element;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LockIcon = LockIcon;
7
+ const react_1 = __importDefault(require("react"));
8
+ function LockIcon({ size = 24 }) {
9
+ return (react_1.default.createElement("svg", { stroke: "currentColor", fill: "none", strokeWidth: "2", viewBox: "0 0 24 24", strokeLinecap: "round", strokeLinejoin: "round", height: `${size}px`, width: `${size}px`, xmlns: "http://www.w3.org/2000/svg" },
10
+ react_1.default.createElement("path", { d: "M15 21h-8a2 2 0 0 1 -2 -2v-6a2 2 0 0 1 2 -2h10c.265 0 .518 .052 .75 .145" }),
11
+ react_1.default.createElement("path", { d: "M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0" }),
12
+ react_1.default.createElement("path", { d: "M8 11v-4a4 4 0 1 1 8 0v4" }),
13
+ react_1.default.createElement("path", { d: "M19 22v.01" }),
14
+ react_1.default.createElement("path", { d: "M19 19a2.003 2.003 0 0 0 .914 -3.782a1.98 1.98 0 0 0 -2.414 .483" })));
15
+ }
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ export declare function LogoutIcon({ size }: {
3
+ size?: number;
4
+ }): React.JSX.Element;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LogoutIcon = LogoutIcon;
7
+ const react_1 = __importDefault(require("react"));
8
+ function LogoutIcon({ size = 24 }) {
9
+ return (react_1.default.createElement("svg", { stroke: "currentColor", fill: "currentColor", strokeWidth: "0", viewBox: "0 0 20 20", "aria-hidden": "true", height: `${size}px`, width: `${size}px`, xmlns: "http://www.w3.org/2000/svg" },
10
+ react_1.default.createElement("path", { fillRule: "evenodd", d: "M3 3a1 1 0 00-1 1v12a1 1 0 102 0V4a1 1 0 00-1-1zm10.293 9.293a1 1 0 001.414 1.414l3-3a1 1 0 000-1.414l-3-3a1 1 0 10-1.414 1.414L14.586 9H7a1 1 0 100 2h7.586l-1.293 1.293z", clipRule: "evenodd" })));
11
+ }
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ export declare function SettingIcon({ size }: {
3
+ size?: number;
4
+ }): React.JSX.Element;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SettingIcon = SettingIcon;
7
+ const react_1 = __importDefault(require("react"));
8
+ function SettingIcon({ size = 24 }) {
9
+ return (react_1.default.createElement("svg", { stroke: "currentColor", fill: "currentColor", strokeWidth: "0", viewBox: "0 0 24 24", height: `${size}px`, width: `${size}px`, xmlns: "http://www.w3.org/2000/svg" },
10
+ react_1.default.createElement("path", { fill: "none", d: "M0 0h24v24H0z" }),
11
+ react_1.default.createElement("path", { d: "M17.41 6.59 15 5.5l2.41-1.09L18.5 2l1.09 2.41L22 5.5l-2.41 1.09L18.5 9l-1.09-2.41zm3.87 6.13L20.5 11l-.78 1.72-1.72.78 1.72.78.78 1.72.78-1.72L23 13.5l-1.72-.78zm-5.04 1.65 1.94 1.47-2.5 4.33-2.24-.94c-.2.13-.42.26-.64.37l-.3 2.4h-5l-.3-2.41c-.22-.11-.43-.23-.64-.37l-2.24.94-2.5-4.33 1.94-1.47c-.01-.11-.01-.24-.01-.36s0-.25.01-.37l-1.94-1.47 2.5-4.33 2.24.94c.2-.13.42-.26.64-.37L7.5 6h5l.3 2.41c.22.11.43.23.64.37l2.24-.94 2.5 4.33-1.94 1.47c.01.12.01.24.01.37s0 .24-.01.36zM13 14c0-1.66-1.34-3-3-3s-3 1.34-3 3 1.34 3 3 3 3-1.34 3-3z" })));
12
+ }
@@ -74,19 +74,19 @@ function ResetPassword({ className, onChangePassword, ...props }) {
74
74
  console.log(error);
75
75
  }
76
76
  }, undefined);
77
- (0, react_1.useEffect)(() => {
78
- let timer;
79
- if (state?.status === "success") {
80
- if (loginUrl) {
81
- timer = setTimeout(() => {
82
- window.location.href = loginUrl;
83
- }, 2000);
84
- }
85
- }
86
- return () => {
87
- clearTimeout(timer);
88
- };
89
- }, [state?.status]);
77
+ // useEffect(() => {
78
+ // let timer: NodeJS.Timeout;
79
+ // if (state?.status === "success") {
80
+ // if (loginUrl) {
81
+ // timer = setTimeout(() => {
82
+ // window.location.href = loginUrl;
83
+ // }, 2000);
84
+ // }
85
+ // }
86
+ // return () => {
87
+ // clearTimeout(timer);
88
+ // };
89
+ // }, [state?.status]);
90
90
  return (react_1.default.createElement("div", { className: (0, utils_1.cn)("ecpauth:flex ecpauth:flex-col ecpauth:gap-6 ecpauth:w-full ecpauth:max-w-sm", className), ...props },
91
91
  react_1.default.createElement(card_1.Card, null,
92
92
  react_1.default.createElement(card_1.CardHeader, null,
@@ -1,9 +1,9 @@
1
1
  import React from "react";
2
- import { Signup, FormResponse, User } from "../types";
2
+ import { CreateUser, FormResponse, User } from "../types";
3
3
  type Props = {
4
4
  className?: string;
5
- onSubmit: (data: Signup) => Promise<FormResponse<User>>;
6
- groupId?: string;
5
+ onSubmit: (data: CreateUser) => Promise<FormResponse<User>>;
6
+ groupId?: string | null;
7
7
  metaData?: Record<string, string>;
8
8
  acceptUsername?: boolean;
9
9
  };
@@ -47,7 +47,7 @@ exports.DialogTrigger = DialogTrigger;
47
47
  const React = __importStar(require("react"));
48
48
  const DialogPrimitive = __importStar(require("@radix-ui/react-dialog"));
49
49
  const utils_1 = require("../../lib/utils");
50
- const x_icon_1 = require("../x-icon");
50
+ const x_icon_1 = require("../icons/x-icon");
51
51
  function Dialog({ ...props }) {
52
52
  return React.createElement(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
53
53
  }
@@ -39,8 +39,11 @@ const dropdown_menu_1 = require("./ui/dropdown-menu");
39
39
  const change_password_1 = require("./change-password");
40
40
  const auth_provider_1 = require("../contexts/auth-provider");
41
41
  const settings_1 = require("./settings");
42
+ const setting_1 = require("./icons/setting");
43
+ const lock_1 = require("./icons/lock");
44
+ const logout_1 = require("./icons/logout");
42
45
  function UserCard({ align = "start", onChangePassword, onToggle2FA, trigger, }) {
43
- const { logout } = (0, auth_provider_1.useAuth)();
46
+ const { logout, user } = (0, auth_provider_1.useAuth)();
44
47
  const [passwordOpen, setPasswordOpen] = (0, react_1.useState)(false);
45
48
  const [settingsOpen, setSettingsOpen] = (0, react_1.useState)(false);
46
49
  return (react_1.default.createElement(react_1.default.Fragment, null,
@@ -49,10 +52,20 @@ function UserCard({ align = "start", onChangePassword, onToggle2FA, trigger, })
49
52
  react_1.default.createElement(dropdown_menu_1.DropdownMenu, null,
50
53
  trigger ? (react_1.default.createElement(dropdown_menu_1.DropdownMenuTrigger, null, trigger)) : (react_1.default.createElement(Trigger, null)),
51
54
  react_1.default.createElement(dropdown_menu_1.DropdownMenuContent, { className: "ecpauth:w-56 ecpauth:border-gray-200 ecpauth:dark:border-gray-800", align: align },
52
- react_1.default.createElement(dropdown_menu_1.DropdownMenuItem, { onClick: () => setSettingsOpen(true) }, "Settings"),
53
- react_1.default.createElement(dropdown_menu_1.DropdownMenuItem, { onClick: () => setPasswordOpen(true) }, "Change Password"),
55
+ react_1.default.createElement("div", { className: "ecpauth:flex ecpauth:flex-col ecpauth:items-center ecpauth:justify-center ecpauth:py-4" },
56
+ react_1.default.createElement("h2", { className: "ecpauth:text-lg ecpauth:font-semibold" }, `${user?.fullName}`),
57
+ react_1.default.createElement("p", { className: "ecpauth:text-sm ecpauth:text-muted-foreground" }, user?.role?.label ?? "-Global-")),
54
58
  react_1.default.createElement(dropdown_menu_1.DropdownMenuSeparator, null),
55
- react_1.default.createElement(dropdown_menu_1.DropdownMenuItem, { onClick: () => logout() }, "Logout")))));
59
+ react_1.default.createElement(dropdown_menu_1.DropdownMenuItem, { onClick: () => setSettingsOpen(true) },
60
+ react_1.default.createElement(setting_1.SettingIcon, null),
61
+ "Settings"),
62
+ react_1.default.createElement(dropdown_menu_1.DropdownMenuItem, { onClick: () => setPasswordOpen(true) },
63
+ react_1.default.createElement(lock_1.LockIcon, null),
64
+ "Change Password"),
65
+ react_1.default.createElement(dropdown_menu_1.DropdownMenuSeparator, null),
66
+ react_1.default.createElement(dropdown_menu_1.DropdownMenuItem, { onClick: () => logout() },
67
+ react_1.default.createElement(logout_1.LogoutIcon, null),
68
+ "Logout")))));
56
69
  }
57
70
  function Trigger() {
58
71
  const { user, authLoading } = (0, auth_provider_1.useAuth)();
@@ -88,7 +88,7 @@ function AuthProvider({ children, config }) {
88
88
  }
89
89
  catch (err) {
90
90
  console.warn("[ecp-auth] Failed to fetch user:", err);
91
- await logout("session_expired");
91
+ await logout("server_unavailable");
92
92
  }
93
93
  finally {
94
94
  setLoading(false);
@@ -153,7 +153,7 @@ function AuthProvider({ children, config }) {
153
153
  }
154
154
  console.error("Logout failed:", err);
155
155
  }
156
- const forceLogout = reason === "user_logout";
156
+ const forceLogout = ["user_logout", "server_unavailable"].includes(reason);
157
157
  if (logoutSucceeded || forceLogout) {
158
158
  localStorage.removeItem(constants_1.AUTH_TOKEN_KEY);
159
159
  localStorage.removeItem(constants_1.LEADING_TAB_KEY);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from "./contexts/auth-provider";
2
2
  export * from "./components/message";
3
- export { buildRouteContext, getClientToken as getToken } from "./lib/utils";
4
- export type { AuthConfig, User, Role, Status, NewRole, UpdateUser, GeneralResponse, FormResponse, VerifyUser, VerifyUserResponse, ResetPasswordWithToken, ResetPasswordWithUserId, Signup, Login, } from "./types";
3
+ export { buildRouteContext, getClientToken as getToken, hasPermission, } from "./lib/utils";
4
+ export type { AuthConfig, User, Role, Status, NewRole, UpdateUser, GeneralResponse, FormResponse, VerifyUser, VerifyUserResponse, ResetPasswordWithToken, ResetPasswordWithUserId, CreateUser, Login, } from "./types";
package/dist/index.js CHANGED
@@ -14,9 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getToken = exports.buildRouteContext = void 0;
17
+ exports.hasPermission = exports.getToken = exports.buildRouteContext = void 0;
18
18
  __exportStar(require("./contexts/auth-provider"), exports);
19
19
  __exportStar(require("./components/message"), exports);
20
20
  var utils_1 = require("./lib/utils");
21
21
  Object.defineProperty(exports, "buildRouteContext", { enumerable: true, get: function () { return utils_1.buildRouteContext; } });
22
22
  Object.defineProperty(exports, "getToken", { enumerable: true, get: function () { return utils_1.getClientToken; } });
23
+ Object.defineProperty(exports, "hasPermission", { enumerable: true, get: function () { return utils_1.hasPermission; } });
@@ -5,34 +5,49 @@ const error_1 = require("./error");
5
5
  const utils_1 = require("./utils");
6
6
  // CLIENT: browser-side calls using public token
7
7
  async function apiClient(path, options) {
8
- const [apiUrl, apiKey] = atob((0, utils_1.getPublicTokenEnv)()).split("$");
9
- if (!apiUrl || !apiKey) {
8
+ const [apiUrl, version, workspaceId, apiKey] = atob((0, utils_1.getPublicTokenEnv)()).split("$");
9
+ if (!apiUrl || !apiKey || !version || !workspaceId) {
10
10
  throw new Error("Invalid API URL or API key. Please set ECP_AUTH_PUBLIC_TOKEN (or the VITE_/NEXT_PUBLIC_ equivalent) in your .env file. Check admin dashboard for env variables.");
11
11
  }
12
12
  const token = (0, utils_1.getClientToken)(); // from localStorage
13
13
  const { method = "POST", body, headers, ...rest } = options ?? {};
14
- const res = await fetch(`${apiUrl}${path}`, {
15
- method,
16
- body: body ? JSON.stringify(body) : undefined,
17
- headers: {
18
- "Content-Type": "application/json",
19
- Authorization: `Bearer ${token}`,
20
- "x-api-key": apiKey,
21
- "x-is-global": process.env.NEXT_PUBLIC_ECP_GLOBAL === "true" ? "true" : "false",
22
- ...headers,
23
- },
24
- credentials: "include",
25
- ...rest,
26
- });
27
- if (!res.ok) {
28
- let errorData;
29
- try {
30
- errorData = await res.json();
14
+ try {
15
+ const res = await fetch(`${apiUrl}${path}`, {
16
+ method,
17
+ body: body ? JSON.stringify(body) : undefined,
18
+ headers: {
19
+ "Content-Type": "application/json",
20
+ Authorization: `Bearer ${token}`,
21
+ "x-api-key": apiKey,
22
+ "x-api-version": version,
23
+ "x-workspace-id": workspaceId,
24
+ "x-is-global": process.env.NEXT_PUBLIC_ECP_GLOBAL === "true" ? "true" : "false",
25
+ ...headers,
26
+ },
27
+ credentials: "include",
28
+ ...rest,
29
+ });
30
+ if (!res.ok) {
31
+ let errorData;
32
+ try {
33
+ errorData = await res.json();
34
+ }
35
+ catch {
36
+ errorData = { message: "Something went wrong." };
37
+ }
38
+ throw new error_1.APIError(errorData.message || "Unexpected error occurred.", errorData, res.status);
31
39
  }
32
- catch {
33
- errorData = { message: "Something went wrong." };
40
+ return (await res.json());
41
+ }
42
+ catch (err) {
43
+ // Handle network errors
44
+ if (err instanceof TypeError) {
45
+ // fetch throws TypeError for network errors
46
+ throw new error_1.APIError("Network error", {
47
+ message: "Network error: could not reach server. Please check your connection or try again later.",
48
+ }, 0);
34
49
  }
35
- throw new error_1.APIError(errorData.message || "Unexpected error occurred.", errorData, res.status);
50
+ // Re-throw other errors
51
+ throw err;
36
52
  }
37
- return (await res.json());
38
53
  }
@@ -6,8 +6,8 @@ const error_1 = require("./error");
6
6
  const server_token_1 = require("../server/server-token");
7
7
  // SERVER: secure-only calls using private key
8
8
  async function apiServer(apiPath, options) {
9
- let [apiUrl, apiKey] = atob(process.env.ECP_AUTH_PRIVATE_TOKEN ?? "").split("$");
10
- if ((!apiUrl || !apiKey) && !options?.adminCall) {
9
+ let [apiUrl, version, workspaceId, apiKey] = atob(process.env.ECP_AUTH_PRIVATE_TOKEN ?? "").split("$");
10
+ if ((!apiUrl || !apiKey || !version || !workspaceId) && !options?.adminCall) {
11
11
  throw new Error("Invalid API URL or API key, please set ECP_AUTH_PRIVATE_TOKEN in your .env file. Check admin dashboard for env variables.");
12
12
  }
13
13
  let token = await (0, server_token_1.getServerToken)();
@@ -19,6 +19,8 @@ async function apiServer(apiPath, options) {
19
19
  "Content-Type": "application/json",
20
20
  Authorization: `Bearer ${token}`,
21
21
  "x-api-key": apiKey,
22
+ "x-api-version": version,
23
+ "x-workspace-id": workspaceId,
22
24
  "x-is-global": process.env.NEXT_PUBLIC_ECP_GLOBAL === "true" ? "true" : "false",
23
25
  ...headers,
24
26
  },
@@ -7,3 +7,4 @@ export declare const intervalMs: number;
7
7
  export declare const retryDelayMs = 60000;
8
8
  export declare const maxRetries = 5;
9
9
  export declare const backoffFactor = 2;
10
+ export declare const serverOnlyCall = "This function can only be called on the server";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.backoffFactor = exports.maxRetries = exports.retryDelayMs = exports.intervalMs = exports.thresholdMs = exports.LEADER_TIMEOUT = exports.LEADING_TAB_KEY = exports.AUTH_RETRY_STATE_KEY = exports.AUTH_TOKEN_KEY = void 0;
3
+ exports.serverOnlyCall = exports.backoffFactor = exports.maxRetries = exports.retryDelayMs = exports.intervalMs = exports.thresholdMs = exports.LEADER_TIMEOUT = exports.LEADING_TAB_KEY = exports.AUTH_RETRY_STATE_KEY = exports.AUTH_TOKEN_KEY = void 0;
4
4
  exports.AUTH_TOKEN_KEY = "_ecp_auth_token";
5
5
  exports.AUTH_RETRY_STATE_KEY = "_ecp_auth_retry_state";
6
6
  exports.LEADING_TAB_KEY = "_ecp_leading_tab";
@@ -10,3 +10,4 @@ exports.intervalMs = 1 * 60_000;
10
10
  exports.retryDelayMs = 60_000;
11
11
  exports.maxRetries = 5;
12
12
  exports.backoffFactor = 2;
13
+ exports.serverOnlyCall = "This function can only be called on the server";
@@ -1,7 +1,8 @@
1
1
  export * from "./toggle-2fa";
2
2
  export * from "./reset-password";
3
- export * from "./users-accounts";
3
+ export * from "./user";
4
4
  export * from "./next-cookie-override";
5
5
  export * from "./server-session";
6
6
  export * from "./server-token";
7
7
  export * from "./role";
8
+ export { hasPermission } from "../lib/utils";
@@ -14,10 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.hasPermission = void 0;
17
18
  __exportStar(require("./toggle-2fa"), exports);
18
19
  __exportStar(require("./reset-password"), exports);
19
- __exportStar(require("./users-accounts"), exports);
20
+ __exportStar(require("./user"), exports);
20
21
  __exportStar(require("./next-cookie-override"), exports);
21
22
  __exportStar(require("./server-session"), exports);
22
23
  __exportStar(require("./server-token"), exports);
23
24
  __exportStar(require("./role"), exports);
25
+ var utils_1 = require("../lib/utils");
26
+ Object.defineProperty(exports, "hasPermission", { enumerable: true, get: function () { return utils_1.hasPermission; } });
@@ -6,8 +6,12 @@ exports.changePassword = changePassword;
6
6
  const utils_1 = require("../lib/utils");
7
7
  const api_1 = require("../lib/api");
8
8
  const error_1 = require("../lib/error");
9
+ const constants_1 = require("../lib/constants");
9
10
  async function resetPassword(data) {
10
11
  try {
12
+ if (typeof window !== "undefined") {
13
+ throw new Error(constants_1.serverOnlyCall);
14
+ }
11
15
  const res = await (0, api_1.apiFactory)("/reset-password", {
12
16
  body: { ...data },
13
17
  });
@@ -22,6 +26,9 @@ async function resetPassword(data) {
22
26
  }
23
27
  async function changePassword(data) {
24
28
  try {
29
+ if (typeof window !== "undefined") {
30
+ throw new Error(constants_1.serverOnlyCall);
31
+ }
25
32
  const res = await (0, api_1.apiFactory)("/change-password", {
26
33
  method: "PUT",
27
34
  body: {
@@ -8,6 +8,7 @@ exports.assignPermission = assignPermission;
8
8
  const api_1 = require("../lib/api");
9
9
  const error_1 = require("../lib/error");
10
10
  const utils_1 = require("../lib/utils");
11
+ const constants_1 = require("../lib/constants");
11
12
  async function getRoles(options) {
12
13
  try {
13
14
  const query = (0, utils_1.parseGroupId)(options?.groupIds);
@@ -23,6 +24,9 @@ async function getRoles(options) {
23
24
  }
24
25
  async function addRole(role) {
25
26
  try {
27
+ if (typeof window !== "undefined") {
28
+ throw new Error(constants_1.serverOnlyCall);
29
+ }
26
30
  const res = await (0, api_1.apiFactory)("/roles", { method: "POST", body: role });
27
31
  return res;
28
32
  }
@@ -35,6 +39,9 @@ async function addRole(role) {
35
39
  }
36
40
  async function updateRole(roleId, role) {
37
41
  try {
42
+ if (typeof window !== "undefined") {
43
+ throw new Error(constants_1.serverOnlyCall);
44
+ }
38
45
  const res = await (0, api_1.apiFactory)(`/roles/${roleId}`, {
39
46
  method: "PUT",
40
47
  body: role,
@@ -50,6 +57,9 @@ async function updateRole(roleId, role) {
50
57
  }
51
58
  async function assignPermission(roleId, permissions) {
52
59
  try {
60
+ if (typeof window !== "undefined") {
61
+ throw new Error(constants_1.serverOnlyCall);
62
+ }
53
63
  const res = await (0, api_1.apiFactory)(`/assign-permissions/${roleId}`, {
54
64
  method: "PUT",
55
65
  body: { permissions },
@@ -10,6 +10,11 @@ async function getServerSession() {
10
10
  if (!token)
11
11
  return null;
12
12
  const session = (0, utils_1.parseJwt)(token);
13
+ const expiresAt = session.exp * 1000;
14
+ const now = Date.now();
15
+ if (now > expiresAt) {
16
+ return null;
17
+ }
13
18
  return {
14
19
  ...session.user,
15
20
  meta: {
@@ -7,8 +7,12 @@ exports.disable2FA = disable2FA;
7
7
  const utils_1 = require("../lib/utils");
8
8
  const api_1 = require("../lib/api");
9
9
  const error_1 = require("../lib/error");
10
+ const constants_1 = require("../lib/constants");
10
11
  async function toggle2FA(userId) {
11
12
  try {
13
+ if (typeof window !== "undefined") {
14
+ throw new Error(constants_1.serverOnlyCall);
15
+ }
12
16
  const res = await (0, api_1.apiFactory)("/2fa", {
13
17
  method: "PUT",
14
18
  body: {
@@ -1,6 +1,6 @@
1
- import { VerifyUser, VerifyUserResponse, Signup, UpdateUser, User, GeneralResponse, FormResponse, QueryOpts } from "../types";
1
+ import { VerifyUser, VerifyUserResponse, CreateUser, UpdateUser, User, GeneralResponse, FormResponse, QueryOpts } from "../types";
2
2
  export declare function verifyUser(data: VerifyUser): Promise<VerifyUserResponse>;
3
- export declare function registerUser(data: Signup, options?: {
3
+ export declare function createUser(data: CreateUser, options?: {
4
4
  isSuperAdmin?: boolean;
5
5
  }): Promise<FormResponse<User>>;
6
6
  export declare function updateUser(userId: string, data: UpdateUser): Promise<FormResponse<User>>;
@@ -2,7 +2,7 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.verifyUser = verifyUser;
5
- exports.registerUser = registerUser;
5
+ exports.createUser = createUser;
6
6
  exports.updateUser = updateUser;
7
7
  exports.getUsers = getUsers;
8
8
  exports.getUserById = getUserById;
@@ -11,6 +11,7 @@ const utils_1 = require("../lib/utils");
11
11
  const api_1 = require("../lib/api");
12
12
  const error_1 = require("../lib/error");
13
13
  const utils_2 = require("../lib/utils");
14
+ const constants_1 = require("../lib/constants");
14
15
  async function verifyUser(data) {
15
16
  try {
16
17
  const res = await (0, api_1.apiFactory)("/users/verify", {
@@ -22,8 +23,11 @@ async function verifyUser(data) {
22
23
  return error;
23
24
  }
24
25
  }
25
- async function registerUser(data, options) {
26
+ async function createUser(data, options) {
26
27
  try {
28
+ if (typeof window !== "undefined") {
29
+ throw new Error(constants_1.serverOnlyCall);
30
+ }
27
31
  const res = await (0, api_1.apiFactory)(`/signup?isSuperAdmin=${options?.isSuperAdmin || false}`, {
28
32
  body: { ...data },
29
33
  });
@@ -41,6 +45,9 @@ async function registerUser(data, options) {
41
45
  }
42
46
  async function updateUser(userId, data) {
43
47
  try {
48
+ if (typeof window !== "undefined") {
49
+ throw new Error(constants_1.serverOnlyCall);
50
+ }
44
51
  const res = await (0, api_1.apiFactory)(`/update-user/${userId}`, {
45
52
  body: { ...data },
46
53
  method: "PUT",
@@ -79,6 +86,9 @@ async function getUserById(userId) {
79
86
  }
80
87
  async function toggleUserStatus(userId) {
81
88
  try {
89
+ if (typeof window !== "undefined") {
90
+ throw new Error(constants_1.serverOnlyCall);
91
+ }
82
92
  const res = await (0, api_1.apiFactory)("/toggle-user-status", {
83
93
  method: "PUT",
84
94
  body: {
package/dist/styles.css CHANGED
@@ -1,4 +1,4 @@
1
- /*! tailwindcss v4.1.11 | MIT License | https://tailwindcss.com */
1
+ /*! tailwindcss v4.1.12 | MIT License | https://tailwindcss.com */
2
2
  @layer properties;
3
3
  @layer theme, base, components, utilities;
4
4
  @layer theme {
@@ -181,6 +181,9 @@
181
181
  ::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {
182
182
  padding-block: 0;
183
183
  }
184
+ ::-webkit-calendar-picker-indicator {
185
+ line-height: 1;
186
+ }
184
187
  :-moz-ui-invalid {
185
188
  box-shadow: none;
186
189
  }
@@ -563,6 +566,9 @@
563
566
  .ecpauth\:py-3 {
564
567
  padding-block: calc(var(--ecpauth-spacing) * 3);
565
568
  }
569
+ .ecpauth\:py-4 {
570
+ padding-block: calc(var(--ecpauth-spacing) * 4);
571
+ }
566
572
  .ecpauth\:py-6 {
567
573
  padding-block: calc(var(--ecpauth-spacing) * 6);
568
574
  }
package/dist/types.d.ts CHANGED
@@ -74,9 +74,9 @@ export type ApiOptions = {
74
74
  [key: string]: any;
75
75
  };
76
76
  export type NewRole = {
77
- groupId?: string;
77
+ groupId?: string | null;
78
78
  label: string;
79
- description?: string;
79
+ description?: string | null;
80
80
  permissions?: string[];
81
81
  };
82
82
  export type Login = {
@@ -84,19 +84,19 @@ export type Login = {
84
84
  password: string;
85
85
  authToken?: string | null;
86
86
  };
87
- export type Signup = {
88
- roleId?: string;
87
+ export type CreateUser = {
88
+ roleId?: string | null;
89
89
  groupId?: string | null;
90
90
  firstName: string;
91
91
  lastName: string;
92
- username?: string;
92
+ username?: string | null;
93
93
  email: string;
94
94
  password: string;
95
95
  confirmPassword: string;
96
- metaData?: Record<string, any>;
96
+ metadata?: Record<string, any>;
97
97
  isSuperAdmin?: boolean;
98
98
  };
99
- export type UpdateUser = Omit<Signup, "password" | "confirmPassword">;
99
+ export type UpdateUser = Omit<CreateUser, "password" | "confirmPassword">;
100
100
  export type GeneralResponse = {
101
101
  status: "failure";
102
102
  message: string;
@@ -154,20 +154,21 @@ export type AuthContextType = {
154
154
  };
155
155
  export type User = {
156
156
  id: string;
157
- roleId: string | null;
158
- groupId: string | null;
157
+ roleId?: string | null;
158
+ groupId?: string | null;
159
159
  email: string;
160
160
  username: string | null;
161
- firstName: string | null;
162
- lastName: string | null;
163
- fullName: string | null;
161
+ firstName: string;
162
+ lastName: string;
163
+ fullName: string;
164
164
  avatar: string | null;
165
165
  with2fa: boolean;
166
- metaData: Record<string, any>;
166
+ metadata: Record<string, any>;
167
167
  role: Role;
168
168
  isSuperAdmin: boolean;
169
169
  isActive: boolean;
170
170
  isLive: boolean;
171
+ lastLogin: string | null;
171
172
  createdAt: string;
172
173
  updatedAt: string;
173
174
  };
@@ -179,7 +180,7 @@ export type NextAppCookies = {
179
180
  export type Role = {
180
181
  id: string;
181
182
  userId: string | null;
182
- groupId: string | null;
183
+ groupId?: string | null;
183
184
  label: string;
184
185
  description: string | null;
185
186
  permissions: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explita/cloud-auth-client",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "author": "Explita",
5
5
  "license": "MIT",
6
6
  "description": "A simple authentication library for React",
File without changes