larapi 0.0.4 → 0.0.6

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/lib/index.d.ts CHANGED
@@ -19,6 +19,8 @@ declare class API extends Core {
19
19
  private init;
20
20
  setToken(token: string): void;
21
21
  getToken(): string;
22
+ getUid(): number;
23
+ getUser(): TUser;
22
24
  get uid(): number;
23
25
  get user(): TUser;
24
26
  setUser(user: TUser): void;
@@ -38,5 +40,10 @@ declare class API extends Core {
38
40
  static addListener: (event: import("./types").TListenerEvents, callback: (data: any) => void) => import("easy-event-emitter").Event;
39
41
  static setInitData: (data: import("./types").TGroupsData) => void;
40
42
  static deleteCacheGroup: (group: string) => void;
43
+ static getToken: () => string;
44
+ static getUid: () => number;
45
+ static getUser: () => TUser;
46
+ static user: TUser;
47
+ static uid: number;
41
48
  }
42
49
  export default API;
package/lib/index.js CHANGED
@@ -21,8 +21,11 @@ class API extends Core_1.default {
21
21
  this.setUser = this.setUser.bind(this);
22
22
  this.updateUser = this.updateUser.bind(this);
23
23
  this.logout = this.logout.bind(this);
24
+ this.getToken = this.getToken.bind(this);
24
25
  this.get = this.get.bind(this);
25
26
  this.post = this.post.bind(this);
27
+ this.getUid = this.getUid.bind(this);
28
+ this.getUser = this.getUser.bind(this);
26
29
  }
27
30
  get(params) {
28
31
  return this.request('GET', params);
@@ -52,12 +55,18 @@ class API extends Core_1.default {
52
55
  getToken() {
53
56
  return this.token;
54
57
  }
55
- get uid() {
58
+ getUid() {
56
59
  return 'id' in this._user ? Number(this._user.id) : 0;
57
60
  }
58
- get user() {
61
+ getUser() {
59
62
  return this._user;
60
63
  }
64
+ get uid() {
65
+ return this.getUid();
66
+ }
67
+ get user() {
68
+ return this.getUser();
69
+ }
61
70
  setUser(user) {
62
71
  if (typeof window === 'undefined')
63
72
  return;
@@ -148,5 +157,35 @@ Object.defineProperty(API, "deleteCacheGroup", {
148
157
  writable: true,
149
158
  value: _a.instance.deleteCacheGroup
150
159
  });
160
+ Object.defineProperty(API, "getToken", {
161
+ enumerable: true,
162
+ configurable: true,
163
+ writable: true,
164
+ value: _a.instance.getToken
165
+ });
166
+ Object.defineProperty(API, "getUid", {
167
+ enumerable: true,
168
+ configurable: true,
169
+ writable: true,
170
+ value: _a.instance.getUid
171
+ });
172
+ Object.defineProperty(API, "getUser", {
173
+ enumerable: true,
174
+ configurable: true,
175
+ writable: true,
176
+ value: _a.instance.getUser
177
+ });
178
+ Object.defineProperty(API, "user", {
179
+ enumerable: true,
180
+ configurable: true,
181
+ writable: true,
182
+ value: _a.instance.user
183
+ });
184
+ Object.defineProperty(API, "uid", {
185
+ enumerable: true,
186
+ configurable: true,
187
+ writable: true,
188
+ value: _a.instance.uid
189
+ });
151
190
  globalThis.apiSetInitData = API.setInitData;
152
191
  exports.default = API;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "larapi",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "API client for laravel",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/src/index.ts CHANGED
@@ -25,8 +25,11 @@ class API extends Core {
25
25
  this.setUser = this.setUser.bind(this);
26
26
  this.updateUser = this.updateUser.bind(this);
27
27
  this.logout = this.logout.bind(this);
28
+ this.getToken = this.getToken.bind(this);
28
29
  this.get = this.get.bind(this);
29
30
  this.post = this.post.bind(this);
31
+ this.getUid = this.getUid.bind(this);
32
+ this.getUser = this.getUser.bind(this);
30
33
  }
31
34
 
32
35
  public get(params: TParams) {
@@ -60,12 +63,20 @@ class API extends Core {
60
63
  return this.token;
61
64
  }
62
65
 
66
+ public getUid(): number {
67
+ return 'id' in this._user ? Number(this._user.id) : 0;
68
+ }
69
+
70
+ public getUser(): TUser {
71
+ return this._user;
72
+ }
73
+
63
74
  public get uid(): number {
64
- return 'id' in this._user ? Number(this._user.id) : 0;
75
+ return this.getUid();
65
76
  }
66
77
 
67
78
  public get user(): TUser {
68
- return this._user;
79
+ return this.getUser();
69
80
  }
70
81
 
71
82
  public setUser(user: TUser) {
@@ -99,6 +110,11 @@ class API extends Core {
99
110
  public static addListener = this.instance.addListener;
100
111
  public static setInitData = this.instance.setInitData;
101
112
  public static deleteCacheGroup = this.instance.deleteCacheGroup;
113
+ public static getToken = this.instance.getToken;
114
+ public static getUid = this.instance.getUid;
115
+ public static getUser = this.instance.getUser;
116
+ public static user = this.instance.user;
117
+ public static uid = this.instance.uid;
102
118
  }
103
119
 
104
120
  (globalThis as any).apiSetInitData = API.setInitData;