@nexys/user-management-sdk 0.0.12 → 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 +8 -6
- package/dist/client.js +24 -17
- package/dist/context.d.ts +3 -3
- package/dist/context.js +5 -6
- package/dist/sso-response.d.ts +1 -2
- package/dist/type.js +1 -18
- package/dist/utils.test.js +9 -8
- package/package.json +6 -17
package/dist/client.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Locale,
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
const
|
|
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
|
-
"/
|
|
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, {
|
|
2
|
-
import AuthClient from "./client
|
|
3
|
-
import { Locale, Permission, Profile } from "./type
|
|
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
|
@@ -9,8 +9,8 @@ export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children
|
|
|
9
9
|
const refreshToken = useCallback(async () => {
|
|
10
10
|
try {
|
|
11
11
|
await authClient.authRefresh();
|
|
12
|
-
const
|
|
13
|
-
setProfile(
|
|
12
|
+
const refreshedProfile = await authClient.getProfile();
|
|
13
|
+
setProfile(refreshedProfile);
|
|
14
14
|
}
|
|
15
15
|
catch (error) {
|
|
16
16
|
console.error("Token refresh failed:", error);
|
|
@@ -21,12 +21,12 @@ export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children
|
|
|
21
21
|
try {
|
|
22
22
|
authClient
|
|
23
23
|
.getProfile()
|
|
24
|
-
.then(setProfile)
|
|
24
|
+
.then((profile) => setProfile(profile))
|
|
25
25
|
.catch(async () => {
|
|
26
26
|
try {
|
|
27
27
|
await authClient.authRefresh();
|
|
28
|
-
const
|
|
29
|
-
setProfile(
|
|
28
|
+
const fullProfile = await authClient.getProfile();
|
|
29
|
+
setProfile(fullProfile);
|
|
30
30
|
}
|
|
31
31
|
catch (e) {
|
|
32
32
|
console.log("e1", e);
|
|
@@ -47,7 +47,6 @@ export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children
|
|
|
47
47
|
return navigate(loginPath, { state: navigationMessage });
|
|
48
48
|
}
|
|
49
49
|
}, []);
|
|
50
|
-
// Set up refresh interval when profile exists
|
|
51
50
|
React.useEffect(() => {
|
|
52
51
|
if (!fullProfile)
|
|
53
52
|
return;
|
package/dist/sso-response.d.ts
CHANGED
package/dist/type.js
CHANGED
|
@@ -1,18 +1 @@
|
|
|
1
|
-
export
|
|
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 {};
|
package/dist/utils.test.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
//
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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/
|
|
9
|
-
"
|
|
10
|
-
"
|
|
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
|
}
|