@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 +7 -8
- package/dist/mobile_platform.js +5 -0
- package/dist/platform_interface.js +7 -2
- package/dist/web_platform.js +8 -3
- package/dist/windows_platform.js +5 -0
- package/index.ts +8 -8
- package/mobile_platform.ts +6 -0
- package/package.json +1 -1
- package/platform_interface.ts +7 -3
- package/web_platform.ts +8 -3
- package/windows_platform.ts +5 -0
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.
|
|
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
|
|
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.
|
|
254
|
+
this.platform.setToken("Bearer " + res.data.token);
|
|
256
255
|
}
|
|
257
256
|
else if (access_token.startsWith("Bearer ")) {
|
|
258
|
-
this.
|
|
257
|
+
this.platform.setToken(access_token);
|
|
259
258
|
}
|
|
260
|
-
localStorage.setItem("token", this.
|
|
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.
|
|
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.
|
|
288
|
+
this.platform.setToken("Bearer " + res.data.token);
|
|
290
289
|
}
|
|
291
290
|
this.resolveReady(this.axios);
|
|
292
291
|
})
|
package/dist/mobile_platform.js
CHANGED
|
@@ -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(
|
|
7
|
-
this.token = token;
|
|
12
|
+
constructor(appCode, baseURL) {
|
|
8
13
|
this.appCode = appCode;
|
|
9
14
|
this.baseURL = baseURL;
|
|
10
15
|
}
|
package/dist/web_platform.js
CHANGED
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WebPlatform = void 0;
|
|
4
4
|
class WebPlatform {
|
|
5
|
-
constructor(
|
|
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
|
}
|
package/dist/windows_platform.js
CHANGED
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.
|
|
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
|
|
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.
|
|
265
|
+
this.platform.setToken("Bearer " + res.data.token);
|
|
266
266
|
} else if (access_token.startsWith("Bearer ")) {
|
|
267
|
-
this.
|
|
267
|
+
this.platform.setToken(access_token);
|
|
268
268
|
}
|
|
269
|
-
localStorage.setItem("token", this.
|
|
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.
|
|
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.
|
|
295
|
+
this.platform.setToken("Bearer " + res.data.token);
|
|
296
296
|
}
|
|
297
297
|
this.resolveReady(this.axios);
|
|
298
298
|
})
|
package/mobile_platform.ts
CHANGED
|
@@ -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
package/platform_interface.ts
CHANGED
|
@@ -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(
|
|
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(
|
|
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
|
}
|
package/windows_platform.ts
CHANGED
|
@@ -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
|
}
|