@machhub-dev/sdk-ts 1.0.8 → 1.0.10

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.
@@ -1,5 +1,5 @@
1
1
  import { HTTPService } from "../services/http.service.js";
2
- import { Action, ActionResponse, Feature, Group, LoginResponse, User, ValidateJWTResponse } from "../types/auth.models.js";
2
+ import { ActionResponse, Feature, Group, LoginResponse, PermissionResponse, User, ValidateJWTResponse } from "../types/auth.models.js";
3
3
  export declare class Auth {
4
4
  private httpService;
5
5
  private applicationID;
@@ -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, scope: string): Promise<ActionResponse>;
20
- checkPermission(feature: string, scope: string, action: Action): Promise<ActionResponse>;
19
+ checkAction(feature: string): Promise<ActionResponse>;
20
+ checkPermission(feature: string, action: 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>;
@@ -14,19 +14,19 @@ class Auth {
14
14
  : this.AUTH_TOKEN_KEY_PREFIX;
15
15
  }
16
16
  storageGet(key) {
17
- if (typeof localStorage !== 'undefined')
17
+ if (typeof localStorage !== 'undefined' && typeof localStorage.getItem === 'function')
18
18
  return localStorage.getItem(key);
19
19
  return Auth.memoryStore.get(key) ?? null;
20
20
  }
21
21
  storageSet(key, value) {
22
- if (typeof localStorage !== 'undefined') {
22
+ if (typeof localStorage !== 'undefined' && typeof localStorage.setItem === 'function') {
23
23
  localStorage.setItem(key, value);
24
24
  return;
25
25
  }
26
26
  Auth.memoryStore.set(key, value);
27
27
  }
28
28
  storageRemove(key) {
29
- if (typeof localStorage !== 'undefined') {
29
+ if (typeof localStorage !== 'undefined' && typeof localStorage.removeItem === 'function') {
30
30
  localStorage.removeItem(key);
31
31
  return;
32
32
  }
@@ -68,18 +68,18 @@ class Auth {
68
68
  }
69
69
  return await this.validateJWT(token);
70
70
  }
71
- async checkAction(feature, scope) {
71
+ async checkAction(feature) {
72
72
  try {
73
- const res = await this.httpService.request.get(`/auth/permission/action/feature/${feature}/scope/${scope}`);
73
+ const res = await this.httpService.request.get(`/auth/permission/action/feature/${feature}`);
74
74
  return res;
75
75
  }
76
76
  catch (e) {
77
77
  throw new Error("failed to checkAction : " + e.message);
78
78
  }
79
79
  }
80
- async checkPermission(feature, scope, action) {
80
+ async checkPermission(feature, action) {
81
81
  try {
82
- const res = await this.httpService.request.get(`/auth/permission/check/feature/${feature}/scope/${scope}/action/${action}`);
82
+ const res = await this.httpService.request.get(`/auth/permission/check/feature/${feature}/action/${action}`);
83
83
  return res;
84
84
  }
85
85
  catch (e) {
@@ -280,7 +280,7 @@ async function findConfigEndpoint() {
280
280
  'Accept': 'application/json',
281
281
  },
282
282
  signal: AbortSignal.timeout(2000)
283
- }).catch(() => { console.log("ERR"); return null; }); // Catch fetch errors silently
283
+ }).catch(() => null); // Catch fetch errors silently
284
284
  if (!testResponse || !testResponse.ok) {
285
285
  continue; // Skip to next candidate
286
286
  }
@@ -117,7 +117,7 @@ class RequestParameters {
117
117
  return this;
118
118
  }
119
119
  withAccessToken() {
120
- if (typeof localStorage === 'undefined')
120
+ if (typeof localStorage === 'undefined' || typeof localStorage.getItem !== 'function')
121
121
  return this;
122
122
  const rawAppID = this.applicationID.replace("domains:", "");
123
123
  const storageKey = rawAppID
@@ -49,4 +49,4 @@ export interface ActionResponse extends BaseResponse {
49
49
  action: "read" | "read-write" | "";
50
50
  }
51
51
  export type Action = "read" | "read-write";
52
- export type Scope = "self" | "domain" | "all" | "nil";
52
+ export type Scope = "self" | "domain" | "all" | "nil" | "user-defined";
@@ -1,5 +1,5 @@
1
1
  import { HTTPService } from "../services/http.service.js";
2
- import { Action, ActionResponse, Feature, Group, LoginResponse, User, ValidateJWTResponse } from "../types/auth.models.js";
2
+ import { ActionResponse, Feature, Group, LoginResponse, PermissionResponse, User, ValidateJWTResponse } from "../types/auth.models.js";
3
3
  export declare class Auth {
4
4
  private httpService;
5
5
  private applicationID;
@@ -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, scope: string): Promise<ActionResponse>;
20
- checkPermission(feature: string, scope: string, action: Action): Promise<ActionResponse>;
19
+ checkAction(feature: string): Promise<ActionResponse>;
20
+ checkPermission(feature: string, action: 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>;
@@ -11,19 +11,19 @@ export class Auth {
11
11
  : this.AUTH_TOKEN_KEY_PREFIX;
12
12
  }
13
13
  storageGet(key) {
14
- if (typeof localStorage !== 'undefined')
14
+ if (typeof localStorage !== 'undefined' && typeof localStorage.getItem === 'function')
15
15
  return localStorage.getItem(key);
16
16
  return Auth.memoryStore.get(key) ?? null;
17
17
  }
18
18
  storageSet(key, value) {
19
- if (typeof localStorage !== 'undefined') {
19
+ if (typeof localStorage !== 'undefined' && typeof localStorage.setItem === 'function') {
20
20
  localStorage.setItem(key, value);
21
21
  return;
22
22
  }
23
23
  Auth.memoryStore.set(key, value);
24
24
  }
25
25
  storageRemove(key) {
26
- if (typeof localStorage !== 'undefined') {
26
+ if (typeof localStorage !== 'undefined' && typeof localStorage.removeItem === 'function') {
27
27
  localStorage.removeItem(key);
28
28
  return;
29
29
  }
@@ -65,18 +65,18 @@ export class Auth {
65
65
  }
66
66
  return await this.validateJWT(token);
67
67
  }
68
- async checkAction(feature, scope) {
68
+ async checkAction(feature) {
69
69
  try {
70
- const res = await this.httpService.request.get(`/auth/permission/action/feature/${feature}/scope/${scope}`);
70
+ const res = await this.httpService.request.get(`/auth/permission/action/feature/${feature}`);
71
71
  return res;
72
72
  }
73
73
  catch (e) {
74
74
  throw new Error("failed to checkAction : " + e.message);
75
75
  }
76
76
  }
77
- async checkPermission(feature, scope, action) {
77
+ async checkPermission(feature, action) {
78
78
  try {
79
- const res = await this.httpService.request.get(`/auth/permission/check/feature/${feature}/scope/${scope}/action/${action}`);
79
+ const res = await this.httpService.request.get(`/auth/permission/check/feature/${feature}/action/${action}`);
80
80
  return res;
81
81
  }
82
82
  catch (e) {
package/dist/sdk-ts.js CHANGED
@@ -276,7 +276,7 @@ async function findConfigEndpoint() {
276
276
  'Accept': 'application/json',
277
277
  },
278
278
  signal: AbortSignal.timeout(2000)
279
- }).catch(() => { console.log("ERR"); return null; }); // Catch fetch errors silently
279
+ }).catch(() => null); // Catch fetch errors silently
280
280
  if (!testResponse || !testResponse.ok) {
281
281
  continue; // Skip to next candidate
282
282
  }
@@ -112,7 +112,7 @@ class RequestParameters {
112
112
  return this;
113
113
  }
114
114
  withAccessToken() {
115
- if (typeof localStorage === 'undefined')
115
+ if (typeof localStorage === 'undefined' || typeof localStorage.getItem !== 'function')
116
116
  return this;
117
117
  const rawAppID = this.applicationID.replace("domains:", "");
118
118
  const storageKey = rawAppID
@@ -49,4 +49,4 @@ export interface ActionResponse extends BaseResponse {
49
49
  action: "read" | "read-write" | "";
50
50
  }
51
51
  export type Action = "read" | "read-write";
52
- export type Scope = "self" | "domain" | "all" | "nil";
52
+ export type Scope = "self" | "domain" | "all" | "nil" | "user-defined";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "MACHHUB TYPESCRIPT SDK",
5
5
  "keywords": [
6
6
  "machhub",
@@ -1,6 +1,6 @@
1
1
  import { HTTPService } from "../services/http.service.js";
2
2
  import { jwtDecode } from "jwt-decode";
3
- import { Action, ActionResponse, Feature, Group, LoginResponse, User, ValidateJWTResponse } from "../types/auth.models.js";
3
+ import { Action, ActionResponse, Feature, Group, LoginResponse, PermissionResponse, User, ValidateJWTResponse } from "../types/auth.models.js";
4
4
 
5
5
  export class Auth {
6
6
  private httpService: HTTPService;
@@ -22,17 +22,17 @@ export class Auth {
22
22
  }
23
23
 
24
24
  private storageGet(key: string): string | null {
25
- if (typeof localStorage !== 'undefined') return localStorage.getItem(key);
25
+ if (typeof localStorage !== 'undefined' && typeof localStorage.getItem === 'function') return localStorage.getItem(key);
26
26
  return Auth.memoryStore.get(key) ?? null;
27
27
  }
28
28
 
29
29
  private storageSet(key: string, value: string): void {
30
- if (typeof localStorage !== 'undefined') { localStorage.setItem(key, value); return; }
30
+ if (typeof localStorage !== 'undefined' && typeof localStorage.setItem === 'function') { localStorage.setItem(key, value); return; }
31
31
  Auth.memoryStore.set(key, value);
32
32
  }
33
33
 
34
34
  private storageRemove(key: string): void {
35
- if (typeof localStorage !== 'undefined') { localStorage.removeItem(key); return; }
35
+ if (typeof localStorage !== 'undefined' && typeof localStorage.removeItem === 'function') { localStorage.removeItem(key); return; }
36
36
  Auth.memoryStore.delete(key);
37
37
  }
38
38
 
@@ -81,9 +81,9 @@ export class Auth {
81
81
  return await this.validateJWT(token);
82
82
  }
83
83
 
84
- public async checkAction(feature: string, scope: string): Promise<ActionResponse> {
84
+ public async checkAction(feature: string): Promise<ActionResponse> {
85
85
  try {
86
- const res: ActionResponse = await this.httpService.request.get(`/auth/permission/action/feature/${feature}/scope/${scope}`);
86
+ const res: ActionResponse = await this.httpService.request.get(`/auth/permission/action/feature/${feature}`);
87
87
  return res
88
88
  }
89
89
  catch (e: unknown) {
@@ -91,9 +91,9 @@ export class Auth {
91
91
  }
92
92
  }
93
93
 
94
- public async checkPermission(feature: string, scope: string, action: Action): Promise<ActionResponse> {
94
+ public async checkPermission(feature: string, action: string): Promise<PermissionResponse> {
95
95
  try {
96
- const res: ActionResponse = await this.httpService.request.get(`/auth/permission/check/feature/${feature}/scope/${scope}/action/${action}`);
96
+ const res: PermissionResponse = await this.httpService.request.get(`/auth/permission/check/feature/${feature}/action/${action}`);
97
97
  return res
98
98
  }
99
99
  catch (e: unknown) {
package/src/sdk-ts.ts CHANGED
@@ -324,7 +324,7 @@ async function findConfigEndpoint(): Promise<string> {
324
324
  'Accept': 'application/json',
325
325
  },
326
326
  signal: AbortSignal.timeout(2000)
327
- }).catch(() => { console.log("ERR"); return null }); // Catch fetch errors silently
327
+ }).catch(() => null); // Catch fetch errors silently
328
328
 
329
329
  if (!testResponse || !testResponse.ok) {
330
330
  continue; // Skip to next candidate
@@ -147,7 +147,7 @@ class RequestParameters {
147
147
  }
148
148
 
149
149
  public withAccessToken(): RequestParameters {
150
- if (typeof localStorage === 'undefined') return this;
150
+ if (typeof localStorage === 'undefined' || typeof localStorage.getItem !== 'function') return this;
151
151
  const rawAppID = this.applicationID.replace("domains:", "");
152
152
  const storageKey = rawAppID
153
153
  ? `x-machhub-auth-tkn-${rawAppID}`
@@ -154,4 +154,4 @@ export interface ActionResponse extends BaseResponse {
154
154
  }
155
155
 
156
156
  export type Action = "read" | "read-write"
157
- export type Scope = "self" | "domain" | "all"| "nil"
157
+ export type Scope = "self" | "domain" | "all" | "nil" | "user-defined"