@nexys/user-management-sdk 0.0.11 → 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.
package/dist/client.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- import { Locale, Permission, Profile, SSOService, UserAdmin } from "./type";
2
- export declare const redirectUrl: (ssoService: SSOService) => string;
1
+ import { type Locale, type Profile, type SSOService, type UserAdmin, Permission } from "./type";
3
2
  declare class AuthClient {
4
3
  apiBasename: string;
5
4
  constructor(apiBasename: string);
5
+ authSSOUrl2: (service: SSOService) => Promise<{
6
+ url: string;
7
+ }>;
6
8
  authSSOUrl: (service: SSOService, params?: Partial<{
7
9
  isSignup: boolean;
8
10
  redirectUrl: string;
@@ -26,15 +28,15 @@ declare class AuthClient {
26
28
  locale: Locale;
27
29
  }>;
28
30
  authLogout: () => Promise<any>;
31
+ adminUserList: () => Promise<UserAdmin[]>;
32
+ authRefresh: () => Promise<{
33
+ message: string;
34
+ }>;
29
35
  tenantExists: (data: {
30
36
  name: string;
31
37
  }) => Promise<{
32
38
  uuid: string;
33
39
  name: string;
34
40
  }>;
35
- adminUserList: () => Promise<UserAdmin[]>;
36
- authRefresh: () => Promise<{
37
- message: string;
38
- }>;
39
41
  }
40
42
  export default AuthClient;
package/dist/client.js CHANGED
@@ -1,14 +1,18 @@
1
1
  import { paramsToString } from "./utils";
2
2
  // auth stuff
3
3
  const headers = { "content-type": "application/json" };
4
- export const redirectUrl = (ssoService) => [window.location.origin, "auth", "sso", ssoService, "redirect"].join("/");
4
+ const redirectUrl = (ssoService) => [window.location.origin, "auth", "sso", ssoService, "redirect"].join("/");
5
5
  class AuthClient {
6
6
  apiBasename;
7
7
  constructor(apiBasename) {
8
8
  this.apiBasename = apiBasename;
9
9
  }
10
- authSSOUrl = async (service, params = {}) => {
11
- const url = `${this.apiBasename}/auth/${service}/url?${paramsToString(params)}`;
10
+ authSSOUrl2 = async (service) => {
11
+ const response = await fetch(`${this.apiBasename}/auth/oauth/${service}/url?redirectUrl=${encodeURIComponent(redirectUrl(service))}`);
12
+ return response.json();
13
+ };
14
+ authSSOUrl = async (service, params) => {
15
+ const url = `${this.apiBasename}/auth/oauth/${service}/url?${paramsToString(params)}`;
12
16
  const response = await fetch(url);
13
17
  if (response.ok) {
14
18
  return response.json();
@@ -17,14 +21,16 @@ class AuthClient {
17
21
  };
18
22
  authGoogleRedirect = async (ssoService, code, state) => {
19
23
  const response = await fetch(this.apiBasename +
20
- "/auth/" +
24
+ "/auth/oauth/" +
21
25
  ssoService +
22
- "/redirect?code=" +
26
+ "/callback?code=" +
23
27
  encodeURIComponent(code) +
24
28
  "&state=" +
25
29
  encodeURIComponent(state));
26
30
  const j = await response.json();
27
31
  if (response.ok) {
32
+ // here refresh to get access token
33
+ await this.authRefresh();
28
34
  return j;
29
35
  }
30
36
  return j;
@@ -41,21 +47,9 @@ class AuthClient {
41
47
  const response = await fetch(this.apiBasename + "/auth/logout");
42
48
  return response.json();
43
49
  };
44
- tenantExists = async (data) => {
45
- const response = await fetch("/napi/instance/exists", {
46
- method: "POST",
47
- headers,
48
- body: JSON.stringify(data),
49
- });
50
- if (response.ok) {
51
- return response.json();
52
- }
53
- return Promise.reject(response.json());
54
- };
55
50
  adminUserList = async () => {
56
51
  const response = await fetch(this.apiBasename + "/admin/user/list", {
57
52
  method: "POST",
58
- headers,
59
53
  });
60
54
  return response.json();
61
55
  };
@@ -63,5 +57,18 @@ class AuthClient {
63
57
  const response = await fetch(this.apiBasename + "/auth/refresh");
64
58
  return response.json();
65
59
  };
60
+ tenantExists = async (data) => {
61
+ {
62
+ const response = await fetch("/napi/instance/exists", {
63
+ method: "POST",
64
+ headers,
65
+ body: JSON.stringify(data),
66
+ });
67
+ if (response.ok) {
68
+ return response.json();
69
+ }
70
+ return Promise.reject(response.json());
71
+ }
72
+ };
66
73
  }
67
74
  export default AuthClient;
package/dist/context.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import React, { JSX, ReactNode } from "react";
2
- import AuthClient from "./client.js";
3
- import { Locale, Permission, Profile } from "./type.js";
1
+ import React, { type ReactNode } from "react";
2
+ import AuthClient from "./client";
3
+ import type { Locale, Permission, Profile } from "./type";
4
4
  export type AuthContextType = {
5
5
  profile: Profile;
6
6
  permissions: Permission[];
package/dist/context.js CHANGED
@@ -5,13 +5,11 @@ export const AdminContext = createContext(undefined);
5
5
  const REFRESH_INTERVAL = 5 * 60 * 1000; // 5 minutes in milliseconds
6
6
  export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children }) => {
7
7
  const navigate = useNavigate();
8
- const [profile, setProfile] = useState(null);
9
- const [permissions, setPermissions] = useState([]);
10
- const [locale, setLocale] = useState({ country: "US", lang: "en" });
8
+ const [fullProfile, setProfile] = useState(null);
11
9
  const refreshToken = useCallback(async () => {
12
10
  try {
13
11
  await authClient.authRefresh();
14
- const { profile: refreshedProfile } = await authClient.getProfile();
12
+ const refreshedProfile = await authClient.getProfile();
15
13
  setProfile(refreshedProfile);
16
14
  }
17
15
  catch (error) {
@@ -23,14 +21,12 @@ export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children
23
21
  try {
24
22
  authClient
25
23
  .getProfile()
26
- .then(({ profile }) => setProfile(profile))
24
+ .then((profile) => setProfile(profile))
27
25
  .catch(async () => {
28
26
  try {
29
27
  await authClient.authRefresh();
30
- const { profile, permissions, locale } = await authClient.getProfile();
31
- setProfile(profile);
32
- setPermissions(permissions);
33
- setLocale(locale);
28
+ const fullProfile = await authClient.getProfile();
29
+ setProfile(fullProfile);
34
30
  }
35
31
  catch (e) {
36
32
  console.log("e1", e);
@@ -51,18 +47,18 @@ export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children
51
47
  return navigate(loginPath, { state: navigationMessage });
52
48
  }
53
49
  }, []);
54
- // Set up refresh interval when profile exists
55
50
  React.useEffect(() => {
56
- if (!profile)
51
+ if (!fullProfile)
57
52
  return;
58
53
  const intervalId = setInterval(refreshToken, REFRESH_INTERVAL);
59
54
  return () => {
60
55
  clearInterval(intervalId);
61
56
  };
62
- }, [profile, refreshToken]);
63
- if (profile === null) {
57
+ }, [fullProfile, refreshToken]);
58
+ if (fullProfile === null) {
64
59
  return _jsx(Spinner, {});
65
60
  }
61
+ const { profile, permissions, locale } = fullProfile;
66
62
  const logout = () => {
67
63
  setProfile(null);
68
64
  authClient.authLogout();
@@ -1,5 +1,4 @@
1
- import { JSX } from "react";
2
- import AuthClient from "./client.js";
1
+ import AuthClient from "./client";
3
2
  declare const SsoResponse: ({ authClient, links, Banner, Spinner, }: {
4
3
  authClient: AuthClient;
5
4
  links: {
package/dist/type.js CHANGED
@@ -1,18 +1 @@
1
- export var UserStatus;
2
- (function (UserStatus) {
3
- UserStatus[UserStatus["active"] = 1] = "active";
4
- UserStatus[UserStatus["inactive"] = 2] = "inactive";
5
- UserStatus[UserStatus["pending"] = 3] = "pending";
6
- })(UserStatus || (UserStatus = {}));
7
- export const ssoAvailable = [
8
- "microsoft",
9
- "apple",
10
- "github",
11
- "google",
12
- ];
13
- export var Permission;
14
- (function (Permission) {
15
- Permission[Permission["app"] = 1] = "app";
16
- Permission[Permission["admin"] = 2] = "admin";
17
- Permission[Permission["superadmin"] = 3] = "superadmin";
18
- })(Permission || (Permission = {}));
1
+ export {};
@@ -1,9 +1,7 @@
1
- // utils.test.js
2
- import { describe, expect, it } from "bun:test";
3
- import { arrayBufferToBase64, base64UrlToUint8Array, getLoginInfoFromQuery, } from "./utils.js";
4
- // Mock browser's atob and btoa for Node.js/Bun environment
5
- global.atob = (base64) => Buffer.from(base64, "base64").toString("binary");
6
- global.btoa = (binary) => Buffer.from(binary, "binary").toString("base64");
1
+ // Import necessary modules
2
+ import { expect, describe, it } from "bun:test";
3
+ import { getLoginInfoFromQuery, base64UrlToUint8Array, arrayBufferToBase64, } from "./utils.js";
4
+ // Describe the test suite
7
5
  describe("getLoginInfoFromQuery", () => {
8
6
  it('should return null if the query does not contain the "q" parameter', () => {
9
7
  const result = getLoginInfoFromQuery("?someOtherParam=abc");
@@ -14,7 +12,8 @@ describe("getLoginInfoFromQuery", () => {
14
12
  expect(result).toBe(null);
15
13
  });
16
14
  it('should decode the "q" parameter and return the correct userId and instanceId', () => {
17
- const encodedParam = Buffer.from("user123:instance456").toString("base64");
15
+ // Bun has built-in atob/btoa so we don't need to use Buffer
16
+ const encodedParam = btoa("user123:instance456");
18
17
  const query = `?q=${encodedParam}`;
19
18
  const result = getLoginInfoFromQuery(query);
20
19
  expect(result).toEqual({
@@ -23,7 +22,7 @@ describe("getLoginInfoFromQuery", () => {
23
22
  });
24
23
  });
25
24
  it('should handle missing ":" in decoded string and return undefined values', () => {
26
- const encodedParam = Buffer.from("user123").toString("base64");
25
+ const encodedParam = btoa("user123");
27
26
  const query = `?q=${encodedParam}`;
28
27
  const result = getLoginInfoFromQuery(query);
29
28
  expect(result).toEqual({
@@ -32,6 +31,7 @@ describe("getLoginInfoFromQuery", () => {
32
31
  });
33
32
  });
34
33
  });
34
+ // Tests for base64UrlToUint8Array
35
35
  describe("base64UrlToUint8Array", () => {
36
36
  it("should correctly convert Base64URL string to Uint8Array", () => {
37
37
  const base64Url = "SGVsbG8td29ybGQ_"; // Base64URL for "Hello-world?"
@@ -50,6 +50,7 @@ describe("base64UrlToUint8Array", () => {
50
50
  expect(result).toEqual(expectedArray);
51
51
  });
52
52
  });
53
+ // Tests for arrayBufferToBase64
53
54
  describe("arrayBufferToBase64", () => {
54
55
  it("should correctly convert ArrayBuffer to Base64URL string", () => {
55
56
  const buffer = new Uint8Array([
package/package.json CHANGED
@@ -1,26 +1,20 @@
1
1
  {
2
2
  "name": "@nexys/user-management-sdk",
3
- "version": "0.0.11",
3
+ "version": "0.1.0",
4
4
  "private": false,
5
5
  "description": "react client/sdk that faciliates connecting to the user management",
6
6
  "main": "dist/index.js",
7
7
  "devDependencies": {
8
- "@types/bun": "^1.1.14",
9
- "@types/node": "^22.5.4",
10
- "@types/react": "^19.0.2",
11
- "@types/react-dom": "^19.0.2",
12
- "react": "^19.0.0",
13
- "react-router-dom": "^6.26.2",
14
- "typescript": "^5.6.2"
8
+ "@types/react": "^18.3.5",
9
+ "react": "^18.3.1",
10
+ "react-router-dom": "^6.26.2"
15
11
  },
16
12
  "type": "module",
17
13
  "files": [
18
14
  "dist"
19
15
  ],
20
16
  "scripts": {
21
- "build": "tsc",
22
- "test": "bun test",
23
- "buildPackage": "yarn build; rm dist/*.test.js; rm dist/*.test.d.ts"
17
+ "build": "tsc"
24
18
  },
25
19
  "repository": {
26
20
  "type": "git",
@@ -31,10 +25,5 @@
31
25
  "bugs": {
32
26
  "url": "https://github.com/nexys-system/user-management-client/issues"
33
27
  },
34
- "homepage": "https://github.com/nexys-system/user-management-client#readme",
35
- "dependencies": {
36
- "@nexys/user-management-aas": "^0.6.8",
37
- "@nexys/validation": "^2.1.8",
38
- "react-dom": "^19.0.0"
39
- }
28
+ "homepage": "https://github.com/nexys-system/user-management-client#readme"
40
29
  }