@nexys/user-management-sdk 0.1.3 → 0.1.5

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 { type Locale, type Profile, type SSOService, type UserAdmin, Permission } from "./type.js";
1
+ import * as R from "./request.js";
2
+ import { type Locale, type Profile, type SSOService, type UserAdmin, Permission, UserStatus } from "./type.js";
2
3
  export declare const redirectUrl: (ssoService: SSOService) => string;
3
4
  declare class AuthClient {
4
- apiBasename: string;
5
- constructor(apiBasename: string);
5
+ private apiBasename;
6
+ makeRequest: <A>(params: R.MakeRequestParams) => Promise<A>;
7
+ constructor(apiBasename: string, makeRequestOverride?: <A>(params: R.MakeRequestParams) => Promise<A>);
6
8
  authSSOUrl: (service: SSOService, params?: Partial<{
7
9
  isSignup: boolean;
8
10
  redirectUrl: string;
@@ -25,8 +27,46 @@ declare class AuthClient {
25
27
  permissions: Permission[];
26
28
  locale: Locale;
27
29
  }>;
28
- authLogout: () => Promise<any>;
30
+ authLogout: () => Promise<unknown>;
29
31
  adminUserList: () => Promise<UserAdmin[]>;
32
+ adminUserInsert: (data: {
33
+ profile: {
34
+ firstName: string;
35
+ lastName: string;
36
+ email: string;
37
+ };
38
+ locale?: Locale;
39
+ status?: UserStatus;
40
+ }) => Promise<{
41
+ uuid: string;
42
+ }>;
43
+ adminUserDelete: (uuid: string) => Promise<{
44
+ success: boolean;
45
+ }>;
46
+ superadminUserList: (params?: {
47
+ uuid?: string;
48
+ order?: {
49
+ by: "firstName" | "lastName" | "logDateAdded";
50
+ desc: boolean;
51
+ };
52
+ take?: number;
53
+ }) => Promise<UserAdmin[]>;
54
+ superadminUserInsert: (data: {
55
+ firstName: string;
56
+ lastName: string;
57
+ email: string;
58
+ instance: {
59
+ uuid: string;
60
+ };
61
+ status?: UserStatus;
62
+ localeCountry?: string;
63
+ localeLang?: string;
64
+ }) => Promise<{
65
+ uuid: string;
66
+ }>;
67
+ superadminUserDelete: (uuid: string) => Promise<{
68
+ success: boolean;
69
+ }>;
30
70
  authRefresh: () => Promise<{
31
71
  message: string;
32
72
  }>;
package/dist/client.js CHANGED
@@ -1,77 +1,103 @@
1
- import { paramsToString } from "./utils.js";
2
- // auth stuff
3
- const headers = { "content-type": "application/json" };
1
+ import * as R from "./request.js";
4
2
  export const redirectUrl = (ssoService) => [window.location.origin, "auth", "sso", ssoService, "redirect"].join("/");
5
3
  class AuthClient {
6
4
  apiBasename;
7
- constructor(apiBasename) {
5
+ makeRequest;
6
+ constructor(apiBasename, makeRequestOverride) {
8
7
  this.apiBasename = apiBasename;
8
+ this.makeRequest = makeRequestOverride || R.makeRequest(this.apiBasename);
9
+ console.log("api base name", this.apiBasename);
9
10
  }
10
11
  authSSOUrl = async (service, params) => {
11
- const url = `${this.apiBasename}/auth/oauth/${service}/url?${paramsToString(params)}`;
12
- const response = await fetch(url);
13
- if (response.ok) {
14
- return response.json();
15
- }
16
- return Promise.reject(response.json());
12
+ return this.makeRequest({
13
+ path: `/auth/oauth/${service}/url`,
14
+ method: "GET",
15
+ queryParams: params,
16
+ });
17
17
  };
18
18
  authGoogleRedirect = async (ssoService, code, state) => {
19
- const response = await fetch(this.apiBasename +
20
- "/auth/oauth/" +
21
- ssoService +
22
- "/callback?code=" +
23
- encodeURIComponent(code) +
24
- "&state=" +
25
- encodeURIComponent(state));
26
- const j = await response.json();
27
- if (response.ok) {
28
- // here refresh to get access token
29
- await this.authRefresh();
30
- return j;
31
- }
19
+ const j = await this.makeRequest({
20
+ path: `/auth/oauth/${ssoService}/callback`,
21
+ method: "GET",
22
+ queryParams: { code, state },
23
+ });
24
+ // here refresh to get access token
25
+ await this.authRefresh();
32
26
  return j;
33
27
  };
34
28
  getProfile = async () => {
35
- const response = await fetch(this.apiBasename + "/profile");
36
- const j = await response.json();
37
- if (!response.ok) {
38
- throw j;
39
- }
40
- return j;
29
+ return this.makeRequest({
30
+ path: "/profile",
31
+ method: "GET",
32
+ });
41
33
  };
42
34
  authLogout = async () => {
43
- const response = await fetch(this.apiBasename + "/auth/logout");
44
- return response.json();
35
+ return this.makeRequest({
36
+ path: "/auth/logout",
37
+ method: "GET",
38
+ });
45
39
  };
40
+ // Admin routes (tenant implicit from authenticated user context)
46
41
  adminUserList = async () => {
47
- const response = await fetch(this.apiBasename + "/admin/user/list", {
42
+ return this.makeRequest({
43
+ path: "/admin/user/list",
44
+ method: "POST",
45
+ });
46
+ };
47
+ adminUserInsert = async (data) => {
48
+ return this.makeRequest({
49
+ path: "/admin/user/insert",
50
+ method: "POST",
51
+ data,
52
+ });
53
+ };
54
+ adminUserDelete = async (uuid) => {
55
+ return this.makeRequest({
56
+ path: "/admin/user/delete",
57
+ method: "POST",
58
+ data: { uuid },
59
+ });
60
+ };
61
+ // Superadmin routes (tenant must be explicitly provided)
62
+ superadminUserList = async (params) => {
63
+ return this.makeRequest({
64
+ path: "/superadmin/user/list",
65
+ method: "POST",
66
+ data: params || {},
67
+ });
68
+ };
69
+ superadminUserInsert = async (data) => {
70
+ return this.makeRequest({
71
+ path: "/superadmin/user/",
72
+ method: "POST",
73
+ data,
74
+ });
75
+ };
76
+ superadminUserDelete = async (uuid) => {
77
+ return this.makeRequest({
78
+ path: "/superadmin/user/delete",
48
79
  method: "POST",
80
+ data: { uuid },
49
81
  });
50
- return response.json();
51
82
  };
52
83
  authRefresh = async () => {
53
- const response = await fetch(this.apiBasename + "/auth/refresh");
54
- return response.json();
84
+ return this.makeRequest({
85
+ path: "/auth/refresh",
86
+ method: "GET",
87
+ });
55
88
  };
56
89
  tenantExists = async (data) => {
57
- {
58
- const response = await fetch("/napi/instance/exists", {
59
- method: "POST",
60
- headers,
61
- body: JSON.stringify(data),
62
- });
63
- if (response.ok) {
64
- return response.json();
65
- }
66
- return Promise.reject(response.json());
67
- }
90
+ return this.makeRequest({
91
+ path: "/instance/exists",
92
+ method: "POST",
93
+ data,
94
+ });
68
95
  };
69
96
  loadAvailableProviders = async () => {
70
- const response = await fetch(this.apiBasename + "/napi/auth/oauth/providers");
71
- if (response.ok) {
72
- return response.json();
73
- }
74
- return Promise.reject(response.json());
97
+ return this.makeRequest({
98
+ path: "/auth/oauth/providers",
99
+ method: "GET",
100
+ });
75
101
  };
76
102
  }
77
103
  export default AuthClient;
package/dist/context.d.ts CHANGED
@@ -14,5 +14,5 @@ export declare const AuthProvider: ({ authClient, Spinner, loginPath, }: {
14
14
  loginPath: string;
15
15
  }) => ({ children }: {
16
16
  children: ReactNode;
17
- }) => import("react/jsx-runtime").JSX.Element;
17
+ }) => import("react/jsx-runtime.js").JSX.Element;
18
18
  export declare const useAuth: () => AuthContextType;
@@ -0,0 +1,9 @@
1
+ export interface MakeRequestParams {
2
+ path: string;
3
+ queryParams?: Record<string, any>;
4
+ data?: Record<string, any>;
5
+ method: "GET" | "POST" | "DELETE" | "PUT";
6
+ }
7
+ export declare const makeRequest: (apiBasename: string, headers?: {
8
+ "content-type": string;
9
+ }) => <Out = any>({ path, data, queryParams, method, }: MakeRequestParams) => Promise<Out>;
@@ -0,0 +1,17 @@
1
+ import { paramsToString } from "./utils";
2
+ export const makeRequest = (apiBasename, headers = { "content-type": "application/json" }) => async ({ path, data, queryParams, method = "GET", }) => {
3
+ const queryParamsString = queryParams
4
+ ? "?" + paramsToString(queryParams)
5
+ : "";
6
+ const body = data && JSON.stringify(data);
7
+ const url = apiBasename + path + queryParamsString;
8
+ const response = await fetch(url, {
9
+ headers,
10
+ method,
11
+ body,
12
+ });
13
+ if (response.ok) {
14
+ return response.json();
15
+ }
16
+ return Promise.reject(response.json());
17
+ };
package/dist/webauthn.js CHANGED
@@ -1,4 +1,4 @@
1
- import * as U from "./utils";
1
+ import * as U from "./utils.js";
2
2
  // webauthn client
3
3
  const getPreLogin = async (user, instance) => {
4
4
  const r = await fetch("/napi/auth/webauthn/prelogin", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexys/user-management-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "private": false,
5
5
  "description": "react client/sdk that faciliates connecting to the user management",
6
6
  "main": "dist/index.js",