@machhub-dev/sdk-ts 1.0.11 → 1.0.13

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>;
@@ -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() {
@@ -33,5 +33,5 @@ export declare class Collection {
33
33
  create(data: Record<string, any>): Promise<any>;
34
34
  update(id: string, data: Record<string, any>): Promise<any>;
35
35
  delete(id: string): Promise<any>;
36
- getFile(fileName: string, fieldName: string): Promise<Blob>;
36
+ getFile(fileName: string, fieldName: string, recordID: string): Promise<Blob>;
37
37
  }
@@ -146,12 +146,13 @@ class Collection {
146
146
  throw new CollectionError('delete', this.collectionName, error);
147
147
  }
148
148
  }
149
- async getFile(fileName, fieldName) {
149
+ async getFile(fileName, fieldName, recordID) {
150
150
  try {
151
151
  return await this.httpService.request.withJSON({
152
152
  fileName,
153
153
  collectionName: this.collectionName,
154
- fieldName
154
+ fieldName,
155
+ recordID
155
156
  }).patch("file");
156
157
  }
157
158
  catch (error) {
@@ -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>;
@@ -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() {
@@ -33,5 +33,5 @@ export declare class Collection {
33
33
  create(data: Record<string, any>): Promise<any>;
34
34
  update(id: string, data: Record<string, any>): Promise<any>;
35
35
  delete(id: string): Promise<any>;
36
- getFile(fileName: string, fieldName: string): Promise<Blob>;
36
+ getFile(fileName: string, fieldName: string, recordID: string): Promise<Blob>;
37
37
  }
@@ -142,12 +142,13 @@ export class Collection {
142
142
  throw new CollectionError('delete', this.collectionName, error);
143
143
  }
144
144
  }
145
- async getFile(fileName, fieldName) {
145
+ async getFile(fileName, fieldName, recordID) {
146
146
  try {
147
147
  return await this.httpService.request.withJSON({
148
148
  fileName,
149
149
  collectionName: this.collectionName,
150
- fieldName
150
+ fieldName,
151
+ recordID
151
152
  }).patch("file");
152
153
  }
153
154
  catch (error) {
@@ -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.11",
3
+ "version": "1.0.13",
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
 
@@ -170,12 +170,13 @@ export class Collection {
170
170
  }
171
171
  }
172
172
 
173
- async getFile(fileName: string, fieldName: string): Promise<Blob> {
173
+ async getFile(fileName: string, fieldName: string, recordID: string): Promise<Blob> {
174
174
  try {
175
175
  return await this.httpService.request.withJSON({
176
176
  fileName,
177
177
  collectionName: this.collectionName,
178
- fieldName
178
+ fieldName,
179
+ recordID
179
180
  }).patch("file");
180
181
  } catch (error) {
181
182
  throw new CollectionError('getFile', this.collectionName, error as Error);
@@ -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