@explita/cloud-auth-client 0.0.1 → 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.
Files changed (48) hide show
  1. package/README.md +25 -2
  2. package/dist/components/change-password.js +13 -11
  3. package/dist/components/icons/lock.d.ts +4 -0
  4. package/dist/components/icons/lock.js +15 -0
  5. package/dist/components/icons/logout.d.ts +4 -0
  6. package/dist/components/icons/logout.js +11 -0
  7. package/dist/components/icons/setting.d.ts +4 -0
  8. package/dist/components/icons/setting.js +12 -0
  9. package/dist/components/login-form.js +3 -4
  10. package/dist/components/optional-otp.js +2 -2
  11. package/dist/components/reset-password.js +15 -16
  12. package/dist/components/settings.js +4 -1
  13. package/dist/components/signup-form.d.ts +3 -3
  14. package/dist/components/signup-form.js +20 -21
  15. package/dist/components/toggle-2fa.js +3 -3
  16. package/dist/components/toggle-account-status.js +18 -11
  17. package/dist/components/ui/dialog.js +1 -1
  18. package/dist/components/user-card.js +22 -9
  19. package/dist/contexts/auth-provider.js +23 -18
  20. package/dist/hooks/use-token-refresher.js +11 -11
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +3 -1
  23. package/dist/lib/api-client.js +39 -24
  24. package/dist/lib/api-server.js +5 -4
  25. package/dist/lib/constants.d.ts +10 -0
  26. package/dist/lib/constants.js +13 -0
  27. package/dist/lib/error.js +1 -1
  28. package/dist/lib/refresh-helper.d.ts +0 -6
  29. package/dist/lib/refresh-helper.js +12 -22
  30. package/dist/lib/utils.d.ts +3 -1
  31. package/dist/lib/utils.js +19 -14
  32. package/dist/server/index.d.ts +3 -2
  33. package/dist/server/index.js +5 -2
  34. package/dist/server/{cookie.js → next-cookie-override.js} +3 -3
  35. package/dist/server/reset-password.js +7 -0
  36. package/dist/server/role.d.ts +2 -4
  37. package/dist/server/role.js +13 -1
  38. package/dist/server/server-session.js +5 -0
  39. package/dist/server/server-token.js +5 -5
  40. package/dist/server/toggle-2fa.js +4 -0
  41. package/dist/server/{users-accounts.d.ts → user.d.ts} +3 -5
  42. package/dist/server/{users-accounts.js → user.js} +16 -4
  43. package/dist/styles.css +7 -1
  44. package/dist/types.d.ts +21 -87
  45. package/package.json +9 -9
  46. /package/dist/components/{x-icon.d.ts → icons/x-icon.d.ts} +0 -0
  47. /package/dist/components/{x-icon.js → icons/x-icon.js} +0 -0
  48. /package/dist/server/{cookie.d.ts → next-cookie-override.d.ts} +0 -0
@@ -7,9 +7,12 @@ exports.updateRole = updateRole;
7
7
  exports.assignPermission = assignPermission;
8
8
  const api_1 = require("../lib/api");
9
9
  const error_1 = require("../lib/error");
10
+ const utils_1 = require("../lib/utils");
11
+ const constants_1 = require("../lib/constants");
10
12
  async function getRoles(options) {
11
13
  try {
12
- const res = await (0, api_1.apiFactory)(`/roles?groupId=${(options === null || options === void 0 ? void 0 : options.groupId) || ""}`, {
14
+ const query = (0, utils_1.parseGroupId)(options?.groupIds);
15
+ const res = await (0, api_1.apiFactory)(`/roles${query}`, {
13
16
  method: "GET",
14
17
  });
15
18
  return res.data;
@@ -21,6 +24,9 @@ async function getRoles(options) {
21
24
  }
22
25
  async function addRole(role) {
23
26
  try {
27
+ if (typeof window !== "undefined") {
28
+ throw new Error(constants_1.serverOnlyCall);
29
+ }
24
30
  const res = await (0, api_1.apiFactory)("/roles", { method: "POST", body: role });
25
31
  return res;
26
32
  }
@@ -33,6 +39,9 @@ async function addRole(role) {
33
39
  }
34
40
  async function updateRole(roleId, role) {
35
41
  try {
42
+ if (typeof window !== "undefined") {
43
+ throw new Error(constants_1.serverOnlyCall);
44
+ }
36
45
  const res = await (0, api_1.apiFactory)(`/roles/${roleId}`, {
37
46
  method: "PUT",
38
47
  body: role,
@@ -48,6 +57,9 @@ async function updateRole(roleId, role) {
48
57
  }
49
58
  async function assignPermission(roleId, permissions) {
50
59
  try {
60
+ if (typeof window !== "undefined") {
61
+ throw new Error(constants_1.serverOnlyCall);
62
+ }
51
63
  const res = await (0, api_1.apiFactory)(`/assign-permissions/${roleId}`, {
52
64
  method: "PUT",
53
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: {
@@ -2,16 +2,16 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.getServerToken = getServerToken;
5
+ const constants_1 = require("../lib/constants");
5
6
  async function getServerToken(source) {
6
- var _a, _b;
7
- const cookieName = "_ecp_auth_token";
7
+ const cookieName = constants_1.AUTH_TOKEN_KEY;
8
8
  // Case 1: No source, assume App Router (next/headers)
9
9
  if (!source) {
10
10
  try {
11
11
  // Dynamically import to avoid bundling next in non-Next environments
12
12
  const { cookies } = require("next/headers");
13
13
  const cookieStore = await cookies();
14
- return (_a = cookieStore.get(cookieName)) === null || _a === void 0 ? void 0 : _a.value;
14
+ return cookieStore.get(cookieName)?.value;
15
15
  }
16
16
  catch {
17
17
  return undefined;
@@ -28,8 +28,8 @@ async function getServerToken(source) {
28
28
  }
29
29
  // Case 3: API routes or custom cookie objects
30
30
  const cookieSource = source.cookies;
31
- if (typeof (cookieSource === null || cookieSource === void 0 ? void 0 : cookieSource.get) === "function") {
32
- return (_b = cookieSource.get(cookieName)) === null || _b === void 0 ? void 0 : _b.value; // next/headers-style
31
+ if (typeof cookieSource?.get === "function") {
32
+ return cookieSource.get(cookieName)?.value; // next/headers-style
33
33
  }
34
34
  if (typeof cookieSource === "object") {
35
35
  //@ts-ignore
@@ -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,11 +1,9 @@
1
- import { VerifyUser, VerifyUserResponse, Signup, UpdateUser, User, GeneralResponse, FormResponse } 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>>;
7
- export declare function getUsers(options?: {
8
- groupId: string;
9
- }): Promise<User[]>;
7
+ export declare function getUsers(options?: QueryOpts): Promise<User[]>;
10
8
  export declare function getUserById(userId: string): Promise<User | null>;
11
9
  export declare function toggleUserStatus(userId: string): Promise<GeneralResponse>;
@@ -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;
@@ -10,6 +10,8 @@ exports.toggleUserStatus = toggleUserStatus;
10
10
  const utils_1 = require("../lib/utils");
11
11
  const api_1 = require("../lib/api");
12
12
  const error_1 = require("../lib/error");
13
+ const utils_2 = require("../lib/utils");
14
+ const constants_1 = require("../lib/constants");
13
15
  async function verifyUser(data) {
14
16
  try {
15
17
  const res = await (0, api_1.apiFactory)("/users/verify", {
@@ -21,9 +23,12 @@ async function verifyUser(data) {
21
23
  return error;
22
24
  }
23
25
  }
24
- async function registerUser(data, options) {
26
+ async function createUser(data, options) {
25
27
  try {
26
- const res = await (0, api_1.apiFactory)(`/signup?isSuperAdmin=${(options === null || options === void 0 ? void 0 : options.isSuperAdmin) || false}`, {
28
+ if (typeof window !== "undefined") {
29
+ throw new Error(constants_1.serverOnlyCall);
30
+ }
31
+ const res = await (0, api_1.apiFactory)(`/signup?isSuperAdmin=${options?.isSuperAdmin || false}`, {
27
32
  body: { ...data },
28
33
  });
29
34
  return res;
@@ -40,6 +45,9 @@ async function registerUser(data, options) {
40
45
  }
41
46
  async function updateUser(userId, data) {
42
47
  try {
48
+ if (typeof window !== "undefined") {
49
+ throw new Error(constants_1.serverOnlyCall);
50
+ }
43
51
  const res = await (0, api_1.apiFactory)(`/update-user/${userId}`, {
44
52
  body: { ...data },
45
53
  method: "PUT",
@@ -55,7 +63,8 @@ async function updateUser(userId, data) {
55
63
  }
56
64
  async function getUsers(options) {
57
65
  try {
58
- const res = await (0, api_1.apiFactory)(`/users?groupId=${(options === null || options === void 0 ? void 0 : options.groupId) || ""}`, {
66
+ const query = (0, utils_2.parseGroupId)(options?.groupIds);
67
+ const res = await (0, api_1.apiFactory)(`/users${query}`, {
59
68
  method: "GET",
60
69
  });
61
70
  return res.data;
@@ -77,6 +86,9 @@ async function getUserById(userId) {
77
86
  }
78
87
  async function toggleUserStatus(userId) {
79
88
  try {
89
+ if (typeof window !== "undefined") {
90
+ throw new Error(constants_1.serverOnlyCall);
91
+ }
80
92
  const res = await (0, api_1.apiFactory)("/toggle-user-status", {
81
93
  method: "PUT",
82
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
@@ -66,7 +66,7 @@ type ComputedRouteContext = {
66
66
  excludedPaths: string[];
67
67
  isExcluded: boolean;
68
68
  };
69
- type CookieOverrideFn = (cookie: string | undefined) => Promise<void>;
69
+ type CookieOverrideFn = (cookie?: string) => Promise<void>;
70
70
  export type ApiOptions = {
71
71
  method?: "GET" | "POST" | "PUT" | "DELETE";
72
72
  body?: Record<string, any>;
@@ -74,9 +74,9 @@ export type ApiOptions = {
74
74
  [key: string]: any;
75
75
  };
76
76
  export type NewRole = {
77
- groupId?: string;
78
- name: string;
79
- description?: string;
77
+ groupId?: string | null;
78
+ label: 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;
@@ -149,65 +149,26 @@ export type AuthContextType = {
149
149
  logout: (params?: Record<string, string>) => void;
150
150
  hasPermission: (permission: string) => boolean;
151
151
  revalidate: () => void;
152
+ getToken: () => string | null;
152
153
  computedRouteContext: ComputedRouteContext;
153
154
  };
154
- export type OTPContextReturn = {
155
- processing: boolean;
156
- isOpen: boolean;
157
- open: () => void;
158
- close: () => void;
159
- onCanceled?: () => void;
160
- successMessage: string;
161
- errorMessage: string;
162
- otpValue: string;
163
- setOtpValue: (value: string) => void;
164
- sendOtp: () => Promise<void>;
165
- verifyOtp: () => Promise<void>;
166
- isVerified: boolean;
167
- id: string;
168
- sendOnMount?: boolean;
169
- hasSent: boolean;
170
- };
171
- export type OTPContextProps = {
172
- id?: string;
173
- userId: string;
174
- email?: string;
175
- sendOnMount?: boolean;
176
- onVerified: (authToken: string, tempRefreshToken?: string) => void;
177
- onCanceled?: () => void;
178
- onSend?: () => void;
179
- onError?: () => void;
180
- };
181
- export type Otp = {
182
- id: string;
183
- userId: string;
184
- createdAt: Date;
185
- serviceId: string | null;
186
- sentTo: string;
187
- code: string;
188
- channel: Channel;
189
- used: boolean;
190
- success: boolean;
191
- reason: Reason | null;
192
- expiresAt: Date;
193
- verifiedAt: Date | null;
194
- };
195
155
  export type User = {
196
156
  id: string;
197
- roleId: string | null;
198
- groupId: string | null;
157
+ roleId?: string | null;
158
+ groupId?: string | null;
199
159
  email: string;
200
160
  username: string | null;
201
- firstName: string | null;
202
- lastName: string | null;
203
- fullName: string | null;
161
+ firstName: string;
162
+ lastName: string;
163
+ fullName: string;
204
164
  avatar: string | null;
205
165
  with2fa: boolean;
206
- metaData: Record<string, any>;
166
+ metadata: Record<string, any>;
207
167
  role: Role;
208
168
  isSuperAdmin: boolean;
209
169
  isActive: boolean;
210
170
  isLive: boolean;
171
+ lastLogin: string | null;
211
172
  createdAt: string;
212
173
  updatedAt: string;
213
174
  };
@@ -219,7 +180,7 @@ export type NextAppCookies = {
219
180
  export type Role = {
220
181
  id: string;
221
182
  userId: string | null;
222
- groupId: string | null;
183
+ groupId?: string | null;
223
184
  label: string;
224
185
  description: string | null;
225
186
  permissions: string[];
@@ -229,33 +190,6 @@ export type Role = {
229
190
  updatedAt: Date;
230
191
  isSuperAdmin: boolean;
231
192
  };
232
- export type Project = {
233
- id: string;
234
- projectName: string;
235
- createdAt: string;
236
- updatedAt: string;
237
- isActive: boolean;
238
- slug: string;
239
- services: Service[];
240
- };
241
- export type Service = {
242
- id: string;
243
- label: string;
244
- type: ServiceType;
245
- publicKey: string;
246
- privateKey: string;
247
- isLive: boolean;
248
- isActive: boolean;
249
- lastUsed: string | null;
250
- createdAt: string;
251
- updatedAt: string;
252
- envs: {
253
- privateEnv: string;
254
- publicEnv: string;
255
- combined: string;
256
- };
257
- slug: string;
258
- };
259
193
  export type AuthError = {
260
194
  errors: Record<string, string>;
261
195
  message: string;
@@ -277,8 +211,8 @@ export type UseTokenRefresherOptions = {
277
211
  revalidateUserWhenOnline?: () => void;
278
212
  config?: AuthConfig;
279
213
  };
214
+ export type QueryOpts = {
215
+ groupIds?: (string | number | null)[];
216
+ };
280
217
  export type Status = "ACTIVE" | "INACTIVE";
281
- export type ServiceType = "auth" | "database" | "otp" | "storage";
282
- export type Channel = "email" | "sms" | "totp" | "whatsapp";
283
- export type Reason = "expired" | "invalid" | "success";
284
218
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explita/cloud-auth-client",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "author": "Explita",
5
5
  "license": "MIT",
6
6
  "description": "A simple authentication library for React",
@@ -34,20 +34,20 @@
34
34
  "otp"
35
35
  ],
36
36
  "devDependencies": {
37
- "@tailwindcss/cli": "^4.1.5",
38
- "@types/node": "^24",
39
- "@types/react": "^19",
40
- "@types/react-dom": "^19",
41
- "fs-extra": "^11.3.0",
37
+ "@tailwindcss/cli": "^4.1.12",
38
+ "@types/node": "^24.3.0",
39
+ "@types/react": "^19.1.10",
40
+ "@types/react-dom": "^19.1.7",
41
+ "fs-extra": "^11.3.1",
42
42
  "rimraf": "^6.0.1",
43
- "tailwindcss": "^4.1.5",
44
- "typescript": "^5.8.3"
43
+ "tailwindcss": "^4.1.12",
44
+ "typescript": "^5.9.2"
45
45
  },
46
46
  "dependencies": {
47
47
  "class-variance-authority": "^0.7.1"
48
48
  },
49
49
  "optionalDependencies": {
50
- "@explita/cloud-otp-client": "*"
50
+ "@explita/cloud-otp-client": "^0.0.1"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "@radix-ui/react-dialog": "^1",
File without changes