@dronedeploy/rocos-js-sdk 3.0.1-alpha.16 → 3.0.1-alpha.18
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/models/device-credentials/DeviceCredentials.d.ts +15 -0
- package/cjs/services/AuthService.d.ts +12 -1
- package/cjs/services/AuthService.js +19 -1
- package/esm/models/device-credentials/DeviceCredentials.d.ts +15 -0
- package/esm/services/AuthService.d.ts +12 -1
- package/esm/services/AuthService.js +19 -1
- package/package.json +1 -1
@@ -30,7 +30,22 @@ export interface DeviceCredentialCreate {
|
|
30
30
|
* The system the credentials are for e.g. mqtt, rtmp, etc.
|
31
31
|
*/
|
32
32
|
system: string;
|
33
|
+
/**
|
34
|
+
* Access control list for the credentials
|
35
|
+
*/
|
36
|
+
acl?: DeviceCredentialACLItem[];
|
37
|
+
}
|
38
|
+
export interface DeviceCredentialACLItem {
|
39
|
+
/**
|
40
|
+
* The resource the ACL item is for e.g. /sys/product/{device_sn}/*
|
41
|
+
*/
|
42
|
+
resource: string;
|
43
|
+
/**
|
44
|
+
* The action the ACL item is for e.g. allow, deny, ignore
|
45
|
+
*/
|
46
|
+
action: DeviceCredentialAuthAction;
|
33
47
|
}
|
48
|
+
export type DeviceCredentialAuthAction = 'allow' | 'deny' | 'ignore';
|
34
49
|
export interface DeviceCredentialAuth extends DeviceCredential {
|
35
50
|
/**
|
36
51
|
* The agent component the credentials are for e.g. dji, spot, etc.
|
@@ -1,10 +1,20 @@
|
|
1
1
|
import { IBaseService, IRocosSDKConfig, RocosError, Token } from '../models';
|
2
|
+
import { Observable } from 'rxjs';
|
2
3
|
import { BaseServiceAbstract } from './BaseServiceAbstract';
|
3
4
|
export declare class AuthService extends BaseServiceAbstract implements IBaseService {
|
4
5
|
protected config: IRocosSDKConfig;
|
5
6
|
private token?;
|
6
7
|
private tokenRefreshTimeoutId?;
|
8
|
+
private tokenSubject$;
|
7
9
|
constructor(config: IRocosSDKConfig);
|
10
|
+
/** Observable for token updates
|
11
|
+
*
|
12
|
+
* This is useful for getting notified when the token changes.
|
13
|
+
* i.e. when the token is refreshed from the token refresh checker.
|
14
|
+
*
|
15
|
+
* This will not emit until the token is set, either by `setToken` or by getting a new token.
|
16
|
+
*/
|
17
|
+
get tokenUpdates$(): Observable<Token>;
|
8
18
|
getStatus(): boolean;
|
9
19
|
teardown(): void;
|
10
20
|
protected getError(e: RocosError): RocosError;
|
@@ -62,9 +72,10 @@ export declare class AuthService extends BaseServiceAbstract implements IBaseSer
|
|
62
72
|
* If you want to refresh the token regardless of the expiry time, use `refreshToken`.
|
63
73
|
*
|
64
74
|
* @param minutes the number of minutes before the token expires to refresh the token
|
75
|
+
* @returns true if the token was refreshed
|
65
76
|
* @see refreshToken
|
66
77
|
*/
|
67
|
-
refreshTokenIfExpired(minutes: number): Promise<
|
78
|
+
refreshTokenIfExpired(minutes: number): Promise<boolean>;
|
68
79
|
/** Start a 5-minute loop to check if the token needs to be refreshed
|
69
80
|
*
|
70
81
|
* This is useful when you are using GRPC services (i.e. telemetry) which does not automatically refresh the token.
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthService = void 0;
|
4
4
|
const api_1 = require("../constants/api");
|
5
5
|
const models_1 = require("../models");
|
6
|
+
const rxjs_1 = require("rxjs");
|
6
7
|
const BaseServiceAbstract_1 = require("./BaseServiceAbstract");
|
7
8
|
const RocosLogger_1 = require("../logger/RocosLogger");
|
8
9
|
const RocosStore_1 = require("../store/RocosStore");
|
@@ -12,11 +13,25 @@ class AuthService extends BaseServiceAbstract_1.BaseServiceAbstract {
|
|
12
13
|
constructor(config) {
|
13
14
|
super(config);
|
14
15
|
this.config = config;
|
16
|
+
this.tokenSubject$ = new rxjs_1.Subject();
|
15
17
|
this.config = config;
|
16
18
|
this.logger = RocosLogger_1.RocosLogger.getInstance(`AuthService(${this.config.url})`);
|
17
19
|
if (this.config.token) {
|
18
20
|
this.setToken(this.config.token);
|
19
21
|
}
|
22
|
+
this.tokenUpdates$.subscribe((token) => {
|
23
|
+
RocosStore_1.RocosStore.getChangeSubject().next({ type: 'token', url: this.config.url, data: token.value });
|
24
|
+
});
|
25
|
+
}
|
26
|
+
/** Observable for token updates
|
27
|
+
*
|
28
|
+
* This is useful for getting notified when the token changes.
|
29
|
+
* i.e. when the token is refreshed from the token refresh checker.
|
30
|
+
*
|
31
|
+
* This will not emit until the token is set, either by `setToken` or by getting a new token.
|
32
|
+
*/
|
33
|
+
get tokenUpdates$() {
|
34
|
+
return this.tokenSubject$.asObservable();
|
20
35
|
}
|
21
36
|
getStatus() {
|
22
37
|
return true;
|
@@ -42,7 +57,7 @@ class AuthService extends BaseServiceAbstract_1.BaseServiceAbstract {
|
|
42
57
|
}
|
43
58
|
this.config.token = this.token.value;
|
44
59
|
// output a message for token change
|
45
|
-
|
60
|
+
this.tokenSubject$?.next(this.token);
|
46
61
|
}
|
47
62
|
/**
|
48
63
|
* Clear token
|
@@ -166,6 +181,7 @@ class AuthService extends BaseServiceAbstract_1.BaseServiceAbstract {
|
|
166
181
|
* If you want to refresh the token regardless of the expiry time, use `refreshToken`.
|
167
182
|
*
|
168
183
|
* @param minutes the number of minutes before the token expires to refresh the token
|
184
|
+
* @returns true if the token was refreshed
|
169
185
|
* @see refreshToken
|
170
186
|
*/
|
171
187
|
async refreshTokenIfExpired(minutes) {
|
@@ -173,7 +189,9 @@ class AuthService extends BaseServiceAbstract_1.BaseServiceAbstract {
|
|
173
189
|
this.logger.info('Token expires in 15 minutes. Refreshing.');
|
174
190
|
const newToken = await this.refreshToken();
|
175
191
|
this.setToken(newToken);
|
192
|
+
return true;
|
176
193
|
}
|
194
|
+
return false;
|
177
195
|
}
|
178
196
|
/** Start a 5-minute loop to check if the token needs to be refreshed
|
179
197
|
*
|
@@ -30,7 +30,22 @@ export interface DeviceCredentialCreate {
|
|
30
30
|
* The system the credentials are for e.g. mqtt, rtmp, etc.
|
31
31
|
*/
|
32
32
|
system: string;
|
33
|
+
/**
|
34
|
+
* Access control list for the credentials
|
35
|
+
*/
|
36
|
+
acl?: DeviceCredentialACLItem[];
|
37
|
+
}
|
38
|
+
export interface DeviceCredentialACLItem {
|
39
|
+
/**
|
40
|
+
* The resource the ACL item is for e.g. /sys/product/{device_sn}/*
|
41
|
+
*/
|
42
|
+
resource: string;
|
43
|
+
/**
|
44
|
+
* The action the ACL item is for e.g. allow, deny, ignore
|
45
|
+
*/
|
46
|
+
action: DeviceCredentialAuthAction;
|
33
47
|
}
|
48
|
+
export type DeviceCredentialAuthAction = 'allow' | 'deny' | 'ignore';
|
34
49
|
export interface DeviceCredentialAuth extends DeviceCredential {
|
35
50
|
/**
|
36
51
|
* The agent component the credentials are for e.g. dji, spot, etc.
|
@@ -1,10 +1,20 @@
|
|
1
1
|
import { IBaseService, IRocosSDKConfig, RocosError, Token } from '../models';
|
2
|
+
import { Observable } from 'rxjs';
|
2
3
|
import { BaseServiceAbstract } from './BaseServiceAbstract';
|
3
4
|
export declare class AuthService extends BaseServiceAbstract implements IBaseService {
|
4
5
|
protected config: IRocosSDKConfig;
|
5
6
|
private token?;
|
6
7
|
private tokenRefreshTimeoutId?;
|
8
|
+
private tokenSubject$;
|
7
9
|
constructor(config: IRocosSDKConfig);
|
10
|
+
/** Observable for token updates
|
11
|
+
*
|
12
|
+
* This is useful for getting notified when the token changes.
|
13
|
+
* i.e. when the token is refreshed from the token refresh checker.
|
14
|
+
*
|
15
|
+
* This will not emit until the token is set, either by `setToken` or by getting a new token.
|
16
|
+
*/
|
17
|
+
get tokenUpdates$(): Observable<Token>;
|
8
18
|
getStatus(): boolean;
|
9
19
|
teardown(): void;
|
10
20
|
protected getError(e: RocosError): RocosError;
|
@@ -62,9 +72,10 @@ export declare class AuthService extends BaseServiceAbstract implements IBaseSer
|
|
62
72
|
* If you want to refresh the token regardless of the expiry time, use `refreshToken`.
|
63
73
|
*
|
64
74
|
* @param minutes the number of minutes before the token expires to refresh the token
|
75
|
+
* @returns true if the token was refreshed
|
65
76
|
* @see refreshToken
|
66
77
|
*/
|
67
|
-
refreshTokenIfExpired(minutes: number): Promise<
|
78
|
+
refreshTokenIfExpired(minutes: number): Promise<boolean>;
|
68
79
|
/** Start a 5-minute loop to check if the token needs to be refreshed
|
69
80
|
*
|
70
81
|
* This is useful when you are using GRPC services (i.e. telemetry) which does not automatically refresh the token.
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { API_APPLICATION_AUTH_URL, API_OTP_AUTH_URL, API_OTP_URL, API_USER_TOKEN_URL } from '../constants/api';
|
2
2
|
import { RocosError, Token, errorCodes } from '../models';
|
3
|
+
import { Subject } from 'rxjs';
|
3
4
|
import { BaseServiceAbstract } from './BaseServiceAbstract';
|
4
5
|
import { RocosLogger } from '../logger/RocosLogger';
|
5
6
|
import { RocosStore } from '../store/RocosStore';
|
@@ -9,11 +10,25 @@ export class AuthService extends BaseServiceAbstract {
|
|
9
10
|
constructor(config) {
|
10
11
|
super(config);
|
11
12
|
this.config = config;
|
13
|
+
this.tokenSubject$ = new Subject();
|
12
14
|
this.config = config;
|
13
15
|
this.logger = RocosLogger.getInstance(`AuthService(${this.config.url})`);
|
14
16
|
if (this.config.token) {
|
15
17
|
this.setToken(this.config.token);
|
16
18
|
}
|
19
|
+
this.tokenUpdates$.subscribe((token) => {
|
20
|
+
RocosStore.getChangeSubject().next({ type: 'token', url: this.config.url, data: token.value });
|
21
|
+
});
|
22
|
+
}
|
23
|
+
/** Observable for token updates
|
24
|
+
*
|
25
|
+
* This is useful for getting notified when the token changes.
|
26
|
+
* i.e. when the token is refreshed from the token refresh checker.
|
27
|
+
*
|
28
|
+
* This will not emit until the token is set, either by `setToken` or by getting a new token.
|
29
|
+
*/
|
30
|
+
get tokenUpdates$() {
|
31
|
+
return this.tokenSubject$.asObservable();
|
17
32
|
}
|
18
33
|
getStatus() {
|
19
34
|
return true;
|
@@ -39,7 +54,7 @@ export class AuthService extends BaseServiceAbstract {
|
|
39
54
|
}
|
40
55
|
this.config.token = this.token.value;
|
41
56
|
// output a message for token change
|
42
|
-
|
57
|
+
this.tokenSubject$?.next(this.token);
|
43
58
|
}
|
44
59
|
/**
|
45
60
|
* Clear token
|
@@ -163,6 +178,7 @@ export class AuthService extends BaseServiceAbstract {
|
|
163
178
|
* If you want to refresh the token regardless of the expiry time, use `refreshToken`.
|
164
179
|
*
|
165
180
|
* @param minutes the number of minutes before the token expires to refresh the token
|
181
|
+
* @returns true if the token was refreshed
|
166
182
|
* @see refreshToken
|
167
183
|
*/
|
168
184
|
async refreshTokenIfExpired(minutes) {
|
@@ -170,7 +186,9 @@ export class AuthService extends BaseServiceAbstract {
|
|
170
186
|
this.logger.info('Token expires in 15 minutes. Refreshing.');
|
171
187
|
const newToken = await this.refreshToken();
|
172
188
|
this.setToken(newToken);
|
189
|
+
return true;
|
173
190
|
}
|
191
|
+
return false;
|
174
192
|
}
|
175
193
|
/** Start a 5-minute loop to check if the token needs to be refreshed
|
176
194
|
*
|