@machhub-dev/sdk-ts 1.0.12 → 1.0.14

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.
@@ -16,8 +16,8 @@ export declare class Auth {
16
16
  getJWTData(): Promise<any>;
17
17
  getCurrentUser(): Promise<User>;
18
18
  validateCurrentUser(): Promise<ValidateJWTResponse>;
19
- checkAction(feature: string): Promise<ActionResponse>;
20
- checkPermission(feature: string, action: string): Promise<PermissionResponse>;
19
+ checkAction(feature: string, scope: string): Promise<ActionResponse>;
20
+ checkPermission(feature: string, action: string, scope: string): Promise<PermissionResponse>;
21
21
  getUsers(): Promise<User[]>;
22
22
  getUserById(userId: string): Promise<User>;
23
23
  createUser(firstName: string, lastName: string, username: string, email: string, password: string, number: string, userImage: string): Promise<User>;
@@ -25,4 +25,5 @@ export declare class Auth {
25
25
  createGroup(name: string, features: Feature[]): Promise<Group>;
26
26
  addUserToGroup(userId: string, groupId: string): Promise<ActionResponse>;
27
27
  addPermissionsToGroup(group_id: string, permissions: Feature[]): Promise<ActionResponse>;
28
+ getPermissions(): Promise<Feature[]>;
28
29
  }
@@ -68,22 +68,44 @@ class Auth {
68
68
  }
69
69
  return await this.validateJWT(token);
70
70
  }
71
- async checkAction(feature) {
71
+ async checkAction(feature, scope) {
72
72
  try {
73
- const res = await this.httpService.request.get(`/auth/permission/action/feature/${feature}`);
73
+ const encodedFeature = encodeURIComponent(feature);
74
+ const encodedScope = encodeURIComponent(scope);
75
+ const res = await this.httpService.request.get(`/auth/permission/action/feature/${encodedFeature}/scope/${encodedScope}`);
74
76
  return res;
75
77
  }
76
78
  catch (e) {
77
- throw new Error("failed to checkAction : " + e.message);
79
+ // Backward compatibility for older API versions.
80
+ try {
81
+ const encodedFeature = encodeURIComponent(feature);
82
+ const res = await this.httpService.request.get(`/auth/permission/action/feature/${encodedFeature}`);
83
+ return res;
84
+ }
85
+ catch {
86
+ throw new Error("failed to checkAction : " + e.message);
87
+ }
78
88
  }
79
89
  }
80
- async checkPermission(feature, action) {
90
+ async checkPermission(feature, action, scope) {
81
91
  try {
82
- const res = await this.httpService.request.get(`/auth/permission/check/feature/${feature}/action/${action}`);
92
+ const encodedFeature = encodeURIComponent(feature);
93
+ const encodedScope = encodeURIComponent(scope);
94
+ const encodedAction = encodeURIComponent(action);
95
+ const res = await this.httpService.request.get(`/auth/permission/check/feature/${encodedFeature}/scope/${encodedScope}/action/${encodedAction}`);
83
96
  return res;
84
97
  }
85
98
  catch (e) {
86
- throw new Error("failed to checkPermission : " + e.message);
99
+ // Backward compatibility for older API versions.
100
+ try {
101
+ const encodedFeature = encodeURIComponent(feature);
102
+ const encodedAction = encodeURIComponent(action);
103
+ const res = await this.httpService.request.get(`/auth/permission/check/feature/${encodedFeature}/action/${encodedAction}`);
104
+ return res;
105
+ }
106
+ catch {
107
+ throw new Error("failed to checkPermission : " + e.message);
108
+ }
87
109
  }
88
110
  }
89
111
  async getUsers() {
@@ -120,6 +142,10 @@ class Auth {
120
142
  group_id, permissions
121
143
  }).post("/auth/permission");
122
144
  }
145
+ async getPermissions() {
146
+ const res = await this.httpService.request.get("/auth/permission");
147
+ return res.permissions ?? [];
148
+ }
123
149
  }
124
150
  exports.Auth = Auth;
125
151
  // In-memory fallback for environments without localStorage (e.g. Node.js)
@@ -46,7 +46,7 @@ export interface Permission {
46
46
  }
47
47
  export declare function machhubPermissions(): Permission[];
48
48
  export interface ActionResponse extends BaseResponse {
49
- action: "read" | "read-write" | "";
49
+ actions: string[];
50
50
  }
51
- export type Action = "read" | "read-write";
52
- export type Scope = "self" | "domain" | "all" | "nil" | "user-defined";
51
+ export type Action = string;
52
+ export type Scope = "self" | "domain" | "all" | "nil" | string;
@@ -16,8 +16,8 @@ export declare class Auth {
16
16
  getJWTData(): Promise<any>;
17
17
  getCurrentUser(): Promise<User>;
18
18
  validateCurrentUser(): Promise<ValidateJWTResponse>;
19
- checkAction(feature: string): Promise<ActionResponse>;
20
- checkPermission(feature: string, action: string): Promise<PermissionResponse>;
19
+ checkAction(feature: string, scope: string): Promise<ActionResponse>;
20
+ checkPermission(feature: string, action: string, scope: string): Promise<PermissionResponse>;
21
21
  getUsers(): Promise<User[]>;
22
22
  getUserById(userId: string): Promise<User>;
23
23
  createUser(firstName: string, lastName: string, username: string, email: string, password: string, number: string, userImage: string): Promise<User>;
@@ -25,4 +25,5 @@ export declare class Auth {
25
25
  createGroup(name: string, features: Feature[]): Promise<Group>;
26
26
  addUserToGroup(userId: string, groupId: string): Promise<ActionResponse>;
27
27
  addPermissionsToGroup(group_id: string, permissions: Feature[]): Promise<ActionResponse>;
28
+ getPermissions(): Promise<Feature[]>;
28
29
  }
@@ -65,22 +65,44 @@ export class Auth {
65
65
  }
66
66
  return await this.validateJWT(token);
67
67
  }
68
- async checkAction(feature) {
68
+ async checkAction(feature, scope) {
69
69
  try {
70
- const res = await this.httpService.request.get(`/auth/permission/action/feature/${feature}`);
70
+ const encodedFeature = encodeURIComponent(feature);
71
+ const encodedScope = encodeURIComponent(scope);
72
+ const res = await this.httpService.request.get(`/auth/permission/action/feature/${encodedFeature}/scope/${encodedScope}`);
71
73
  return res;
72
74
  }
73
75
  catch (e) {
74
- throw new Error("failed to checkAction : " + e.message);
76
+ // Backward compatibility for older API versions.
77
+ try {
78
+ const encodedFeature = encodeURIComponent(feature);
79
+ const res = await this.httpService.request.get(`/auth/permission/action/feature/${encodedFeature}`);
80
+ return res;
81
+ }
82
+ catch {
83
+ throw new Error("failed to checkAction : " + e.message);
84
+ }
75
85
  }
76
86
  }
77
- async checkPermission(feature, action) {
87
+ async checkPermission(feature, action, scope) {
78
88
  try {
79
- const res = await this.httpService.request.get(`/auth/permission/check/feature/${feature}/action/${action}`);
89
+ const encodedFeature = encodeURIComponent(feature);
90
+ const encodedScope = encodeURIComponent(scope);
91
+ const encodedAction = encodeURIComponent(action);
92
+ const res = await this.httpService.request.get(`/auth/permission/check/feature/${encodedFeature}/scope/${encodedScope}/action/${encodedAction}`);
80
93
  return res;
81
94
  }
82
95
  catch (e) {
83
- throw new Error("failed to checkPermission : " + e.message);
96
+ // Backward compatibility for older API versions.
97
+ try {
98
+ const encodedFeature = encodeURIComponent(feature);
99
+ const encodedAction = encodeURIComponent(action);
100
+ const res = await this.httpService.request.get(`/auth/permission/check/feature/${encodedFeature}/action/${encodedAction}`);
101
+ return res;
102
+ }
103
+ catch {
104
+ throw new Error("failed to checkPermission : " + e.message);
105
+ }
84
106
  }
85
107
  }
86
108
  async getUsers() {
@@ -117,6 +139,10 @@ export class Auth {
117
139
  group_id, permissions
118
140
  }).post("/auth/permission");
119
141
  }
142
+ async getPermissions() {
143
+ const res = await this.httpService.request.get("/auth/permission");
144
+ return res.permissions ?? [];
145
+ }
120
146
  }
121
147
  // In-memory fallback for environments without localStorage (e.g. Node.js)
122
148
  Auth.memoryStore = new Map();
@@ -46,7 +46,7 @@ export interface Permission {
46
46
  }
47
47
  export declare function machhubPermissions(): Permission[];
48
48
  export interface ActionResponse extends BaseResponse {
49
- action: "read" | "read-write" | "";
49
+ actions: string[];
50
50
  }
51
- export type Action = "read" | "read-write";
52
- export type Scope = "self" | "domain" | "all" | "nil" | "user-defined";
51
+ export type Action = string;
52
+ export type Scope = "self" | "domain" | "all" | "nil" | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "MACHHUB TYPESCRIPT SDK",
5
5
  "keywords": [
6
6
  "machhub",
@@ -81,23 +81,43 @@ export class Auth {
81
81
  return await this.validateJWT(token);
82
82
  }
83
83
 
84
- public async checkAction(feature: string): Promise<ActionResponse> {
84
+ public async checkAction(feature: string, scope: string): Promise<ActionResponse> {
85
85
  try {
86
- const res: ActionResponse = await this.httpService.request.get(`/auth/permission/action/feature/${feature}`);
86
+ const encodedFeature = encodeURIComponent(feature);
87
+ const encodedScope = encodeURIComponent(scope);
88
+ const res: ActionResponse = await this.httpService.request.get(`/auth/permission/action/feature/${encodedFeature}/scope/${encodedScope}`);
87
89
  return res
88
90
  }
89
91
  catch (e: unknown) {
90
- throw new Error("failed to checkAction : " + (e as Error).message);
92
+ // Backward compatibility for older API versions.
93
+ try {
94
+ const encodedFeature = encodeURIComponent(feature);
95
+ const res: ActionResponse = await this.httpService.request.get(`/auth/permission/action/feature/${encodedFeature}`);
96
+ return res;
97
+ } catch {
98
+ throw new Error("failed to checkAction : " + (e as Error).message);
99
+ }
91
100
  }
92
101
  }
93
102
 
94
- public async checkPermission(feature: string, action: string): Promise<PermissionResponse> {
103
+ public async checkPermission(feature: string, action: string, scope: string): Promise<PermissionResponse> {
95
104
  try {
96
- const res: PermissionResponse = await this.httpService.request.get(`/auth/permission/check/feature/${feature}/action/${action}`);
105
+ const encodedFeature = encodeURIComponent(feature);
106
+ const encodedScope = encodeURIComponent(scope);
107
+ const encodedAction = encodeURIComponent(action);
108
+ const res: PermissionResponse = await this.httpService.request.get(`/auth/permission/check/feature/${encodedFeature}/scope/${encodedScope}/action/${encodedAction}`);
97
109
  return res
98
110
  }
99
111
  catch (e: unknown) {
100
- throw new Error("failed to checkPermission : " + (e as Error).message);
112
+ // Backward compatibility for older API versions.
113
+ try {
114
+ const encodedFeature = encodeURIComponent(feature);
115
+ const encodedAction = encodeURIComponent(action);
116
+ const res: PermissionResponse = await this.httpService.request.get(`/auth/permission/check/feature/${encodedFeature}/action/${encodedAction}`);
117
+ return res;
118
+ } catch {
119
+ throw new Error("failed to checkPermission : " + (e as Error).message);
120
+ }
101
121
  }
102
122
  }
103
123
 
@@ -141,4 +161,9 @@ export class Auth {
141
161
  group_id, permissions
142
162
  }).post("/auth/permission");
143
163
  }
164
+
165
+ public async getPermissions(): Promise<Feature[]> {
166
+ const res: {permissions: Feature[]} = await this.httpService.request.get("/auth/permission");
167
+ return res.permissions ?? [];
168
+ }
144
169
  }
@@ -150,8 +150,8 @@ export function machhubPermissions(): Permission[]{
150
150
  }
151
151
 
152
152
  export interface ActionResponse extends BaseResponse {
153
- action: "read" | "read-write" | ""
153
+ actions: string[]
154
154
  }
155
155
 
156
- export type Action = "read" | "read-write"
157
- export type Scope = "self" | "domain" | "all" | "nil" | "user-defined"
156
+ export type Action = string
157
+ export type Scope = "self" | "domain" | "all" | "nil" | string