@cpzxrobot/sdk 1.2.95 → 1.2.97

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/dist/index.js CHANGED
@@ -58,7 +58,6 @@ class Cpzxrobot {
58
58
  this.hash = "shzx";
59
59
  this.mode = "dev";
60
60
  this.auth = "";
61
- this.token = "";
62
61
  this.car = new car_gateway_1.CarGateway(this);
63
62
  this.project = new project_gateway_1.ProjectGateway(this);
64
63
  this.product = new product_gateway_1.ProductGateway(this);
@@ -126,7 +125,7 @@ class Cpzxrobot {
126
125
  this.mode = "miniapp_in_web";
127
126
  baseURL = "https://www.cpzxrobot.com";
128
127
  }
129
- this.platform = new web_platform_1.WebPlatform(this.token, this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
128
+ this.platform = new web_platform_1.WebPlatform(this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
130
129
  }
131
130
  this.platformReady = this.platform.ready();
132
131
  this.axios = this.platform.getAxiosFromMiniApp();
@@ -187,7 +186,7 @@ class Cpzxrobot {
187
186
  const token = localStorage.getItem("token");
188
187
  if (token) {
189
188
  logger(`found token(${token}) in localstorage`, "debug");
190
- this.token = token;
189
+ this.platform.setToken(token);
191
190
  this.axios.get("/api/v1/user/auth").then((res) => {
192
191
  if (res.data.Error) {
193
192
  window.location.href = "/login.html?error=" + res.data.Error;
@@ -252,12 +251,12 @@ class Cpzxrobot {
252
251
  return;
253
252
  }
254
253
  if (res.data.token) {
255
- this.token = "Bearer " + res.data.token;
254
+ this.platform.setToken("Bearer " + res.data.token);
256
255
  }
257
256
  else if (access_token.startsWith("Bearer ")) {
258
- this.token = access_token;
257
+ this.platform.setToken(access_token);
259
258
  }
260
- localStorage.setItem("token", this.token);
259
+ localStorage.setItem("token", this.platform.getToken());
261
260
  this.resolveReady(this.axios);
262
261
  });
263
262
  return;
@@ -272,7 +271,7 @@ class Cpzxrobot {
272
271
  logger(`sdk under ${this.mode} mode`, "debug");
273
272
  this.auth = auth;
274
273
  if (this.auth.startsWith("Bearer ")) {
275
- this.token = auth;
274
+ this.platform.setToken(auth);
276
275
  this.resolveReady(this.axios);
277
276
  }
278
277
  else {
@@ -286,7 +285,7 @@ class Cpzxrobot {
286
285
  throw res.data.Error;
287
286
  }
288
287
  else {
289
- this.token = "Bearer " + res.data.token;
288
+ this.platform.setToken("Bearer " + res.data.token);
290
289
  }
291
290
  this.resolveReady(this.axios);
292
291
  })
@@ -23,6 +23,11 @@ class MobilePlatform {
23
23
  }
24
24
  }, false);
25
25
  }
26
+ getToken() {
27
+ return "";
28
+ }
29
+ setToken(token) {
30
+ }
26
31
  setSelectedFarm(farm) {
27
32
  throw new Error("Method not implemented.");
28
33
  }
@@ -2,9 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlatformInterface = void 0;
4
4
  class PlatformInterface {
5
+ getToken() {
6
+ throw new Error("Method not implemented.");
7
+ }
8
+ setToken(token) {
9
+ throw new Error("Method not implemented.");
10
+ }
5
11
  //define constructor(token: string, appCode: string) {
6
- constructor(token, appCode, baseURL) {
7
- this.token = token;
12
+ constructor(appCode, baseURL) {
8
13
  this.appCode = appCode;
9
14
  this.baseURL = baseURL;
10
15
  }
@@ -2,16 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebPlatform = void 0;
4
4
  class WebPlatform {
5
- constructor(token, appCode, baseURL, selectedFarm, selectedUnit) {
5
+ constructor(appCode, baseURL, selectedFarm, selectedUnit) {
6
6
  this.token = "";
7
7
  this.appCode = "";
8
8
  this.baseURL = "";
9
- this.token = token;
10
9
  this.appCode = appCode;
11
- this.baseURL = baseURL;
10
+ this.baseURL = baseURL !== null && baseURL !== void 0 ? baseURL : "";
12
11
  this._selectedFarm = selectedFarm;
13
12
  this._selectedUnit = selectedUnit;
14
13
  }
14
+ getToken() {
15
+ return this.token;
16
+ }
17
+ setToken(token) {
18
+ this.token = token;
19
+ }
15
20
  setSelectedFarm(farm) {
16
21
  this._selectedFarm = farm;
17
22
  }
@@ -21,6 +21,11 @@ class WindwosMiniAppPlatform {
21
21
  }
22
22
  }, false);
23
23
  }
24
+ getToken() {
25
+ return "";
26
+ }
27
+ setToken(token) {
28
+ }
24
29
  setSelectedFarm(farm) {
25
30
  throw new Error("Method not implemented.");
26
31
  }
package/index.ts CHANGED
@@ -38,7 +38,7 @@ export class Cpzxrobot {
38
38
  axios!: MyAxiosInstance;
39
39
  appCode: string;
40
40
  user: UserGateway;
41
- token: string = "";
41
+ // token: string = "";
42
42
  factory: FactoryGateway;
43
43
  ready: Promise<MyAxiosInstance>;
44
44
  resolveReady!: (
@@ -129,7 +129,7 @@ export class Cpzxrobot {
129
129
  this.mode = "miniapp_in_web";
130
130
  baseURL = "https://www.cpzxrobot.com"
131
131
  }
132
- this.platform = new WebPlatform(this.token, this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
132
+ this.platform = new WebPlatform(this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
133
133
  }
134
134
 
135
135
  this.platformReady = this.platform.ready();
@@ -199,7 +199,7 @@ export class Cpzxrobot {
199
199
  const token = localStorage.getItem("token");
200
200
  if (token) {
201
201
  logger(`found token(${token}) in localstorage`, "debug");
202
- this.token = token;
202
+ this.platform.setToken(token);
203
203
  this.axios.get("/api/v1/user/auth").then((res) => {
204
204
  if (res.data.Error) {
205
205
  window.location.href = "/login.html?error=" + res.data.Error;
@@ -262,11 +262,11 @@ export class Cpzxrobot {
262
262
  return;
263
263
  }
264
264
  if (res.data.token) {
265
- this.token = "Bearer " + res.data.token;
265
+ this.platform.setToken("Bearer " + res.data.token);
266
266
  } else if (access_token.startsWith("Bearer ")) {
267
- this.token = access_token;
267
+ this.platform.setToken(access_token);
268
268
  }
269
- localStorage.setItem("token", this.token);
269
+ localStorage.setItem("token", this.platform.getToken());
270
270
  this.resolveReady(this.axios);
271
271
  });
272
272
  return;
@@ -280,7 +280,7 @@ export class Cpzxrobot {
280
280
  logger(`sdk under ${this.mode} mode`, "debug");
281
281
  this.auth = auth;
282
282
  if (this.auth.startsWith("Bearer ")) {
283
- this.token = auth;
283
+ this.platform.setToken(auth);
284
284
  this.resolveReady(this.axios);
285
285
  } else {
286
286
  this.axios
@@ -292,7 +292,7 @@ export class Cpzxrobot {
292
292
  if (res.data.Error) {
293
293
  throw res.data.Error;
294
294
  } else {
295
- this.token = "Bearer " + res.data.token;
295
+ this.platform.setToken("Bearer " + res.data.token);
296
296
  }
297
297
  this.resolveReady(this.axios);
298
298
  })
@@ -28,6 +28,12 @@ export class MobilePlatform implements PlatformInterface {
28
28
  }
29
29
  }, false);
30
30
  }
31
+ getToken(): string {
32
+ return "";
33
+ }
34
+ setToken(token: string): void {
35
+ }
36
+
31
37
  setSelectedFarm(farm: Factory): void {
32
38
  throw new Error("Method not implemented.");
33
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.2.95",
3
+ "version": "1.2.97",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,14 +1,18 @@
1
1
  import { Factory, MyAxiosInstance, Unit } from "./types";
2
2
 
3
3
  export abstract class PlatformInterface {
4
+ getToken(): string {
5
+ throw new Error("Method not implemented.");
6
+ }
7
+ setToken(token: string) {
8
+ throw new Error("Method not implemented.");
9
+ }
4
10
 
5
- token: string;
6
11
  appCode: string;
7
12
  baseURL: string;
8
13
 
9
14
  //define constructor(token: string, appCode: string) {
10
- constructor(token: string, appCode: string, baseURL: string) {
11
- this.token = token;
15
+ constructor(appCode: string, baseURL: string) {
12
16
  this.appCode = appCode;
13
17
  this.baseURL = baseURL;
14
18
  }
package/web_platform.ts CHANGED
@@ -8,13 +8,18 @@ export class WebPlatform implements PlatformInterface {
8
8
  _selectedFarm: Factory | undefined;
9
9
  _selectedUnit: Unit | undefined;
10
10
 
11
- constructor(token: string, appCode: string, baseURL: string, selectedFarm: Factory | undefined, selectedUnit: Unit | undefined) {
12
- this.token = token;
11
+ constructor(appCode: string, baseURL: string, selectedFarm: Factory | undefined, selectedUnit: Unit | undefined) {
13
12
  this.appCode = appCode;
14
- this.baseURL = baseURL;
13
+ this.baseURL = baseURL ?? "";
15
14
  this._selectedFarm = selectedFarm;
16
15
  this._selectedUnit = selectedUnit;
17
16
  }
17
+ getToken(): string {
18
+ return this.token;
19
+ }
20
+ setToken(token: string): void {
21
+ this.token = token;
22
+ }
18
23
  setSelectedFarm(farm: Factory): void {
19
24
  this._selectedFarm = farm;
20
25
  }
@@ -23,6 +23,11 @@ export class WindwosMiniAppPlatform implements PlatformInterface {
23
23
  }
24
24
  }, false);
25
25
  }
26
+ getToken(): string {
27
+ return "";
28
+ }
29
+ setToken(token: string): void {
30
+ }
26
31
  setSelectedFarm(farm: Factory): void {
27
32
  throw new Error("Method not implemented.");
28
33
  }