@machhub-dev/sdk-ts 1.0.9 → 1.0.11

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 { 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;
@@ -17,7 +17,7 @@ export declare class Auth {
17
17
  getCurrentUser(): Promise<User>;
18
18
  validateCurrentUser(): Promise<ValidateJWTResponse>;
19
19
  checkAction(feature: string): Promise<ActionResponse>;
20
- checkPermission(feature: string, action: 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
  }
@@ -100,7 +100,7 @@ class Collection {
100
100
  try {
101
101
  const formData = new FormData();
102
102
  for (const [key, value] of Object.entries(data)) {
103
- if (value instanceof File) {
103
+ if (typeof File !== 'undefined' && value instanceof File) {
104
104
  formData.append(key, value, value.name);
105
105
  data[key] = value.name;
106
106
  }
@@ -121,7 +121,7 @@ class Collection {
121
121
  try {
122
122
  const formData = new FormData();
123
123
  for (const [key, value] of Object.entries(data)) {
124
- if (value instanceof File) {
124
+ if (typeof File !== 'undefined' && value instanceof File) {
125
125
  formData.append(key, value, value.name);
126
126
  data[key] = value.name;
127
127
  }
@@ -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 { 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;
@@ -17,7 +17,7 @@ export declare class Auth {
17
17
  getCurrentUser(): Promise<User>;
18
18
  validateCurrentUser(): Promise<ValidateJWTResponse>;
19
19
  checkAction(feature: string): Promise<ActionResponse>;
20
- checkPermission(feature: string, action: 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
  }
@@ -96,7 +96,7 @@ export class Collection {
96
96
  try {
97
97
  const formData = new FormData();
98
98
  for (const [key, value] of Object.entries(data)) {
99
- if (value instanceof File) {
99
+ if (typeof File !== 'undefined' && value instanceof File) {
100
100
  formData.append(key, value, value.name);
101
101
  data[key] = value.name;
102
102
  }
@@ -117,7 +117,7 @@ export class Collection {
117
117
  try {
118
118
  const formData = new FormData();
119
119
  for (const [key, value] of Object.entries(data)) {
120
- if (value instanceof File) {
120
+ if (typeof File !== 'undefined' && value instanceof File) {
121
121
  formData.append(key, value, value.name);
122
122
  data[key] = value.name;
123
123
  }
@@ -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.9",
3
+ "version": "1.0.11",
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
 
@@ -91,9 +91,9 @@ export class Auth {
91
91
  }
92
92
  }
93
93
 
94
- public async checkPermission(feature: string, action: string): 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}/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) {
@@ -122,7 +122,7 @@ export class Collection {
122
122
  const formData = new FormData();
123
123
 
124
124
  for (const [key, value] of Object.entries(data)) {
125
- if (value instanceof File) {
125
+ if (typeof File !== 'undefined' && value instanceof File) {
126
126
  formData.append(key, value, value.name);
127
127
  data[key] = value.name
128
128
  }
@@ -144,7 +144,7 @@ export class Collection {
144
144
  const formData = new FormData();
145
145
 
146
146
  for (const [key, value] of Object.entries(data)) {
147
- if (value instanceof File) {
147
+ if (typeof File !== 'undefined' && value instanceof File) {
148
148
  formData.append(key, value, value.name);
149
149
  data[key] = value.name;
150
150
  }
@@ -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"