@rc-ex/auto-refresh 0.2.0 → 0.2.2
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/README.md +8 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.ts +43 -0
- package/package.json +5 -5
- package/src/index.d.ts +16 -0
- package/src/index.js +32 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +5 -3
- package/tsconfig.json +0 -3
package/README.md
CHANGED
|
@@ -21,8 +21,14 @@ autoRefreshExtension.start();
|
|
|
21
21
|
// autoRefreshExtension.stop();
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
For a working sample, please check this
|
|
24
|
+
For a working sample, please check this
|
|
25
|
+
[test case](../../../test/auto-refresh-extension.spec.ts).
|
|
25
26
|
|
|
26
27
|
## Disclaimer
|
|
27
28
|
|
|
28
|
-
[Token management](https://medium.com/ringcentral-developers/ringcentral-token-management-477578f00954)
|
|
29
|
+
[Token management](https://medium.com/ringcentral-developers/ringcentral-token-management-477578f00954)
|
|
30
|
+
is a complicated topic. There is no one-fit-all solution. This extension is an
|
|
31
|
+
quick-and-dirty out-of-box solution to refresh your token. It is by no means the
|
|
32
|
+
best practice. It simply starts a background timers to refresh your token
|
|
33
|
+
periodically. For serious production applications, you may need better token
|
|
34
|
+
management strategy.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type RingCentral from
|
|
2
|
-
import SdkExtension from
|
|
1
|
+
import type RingCentral from "@rc-ex/core";
|
|
2
|
+
import SdkExtension from "@rc-ex/core/src/SdkExtension";
|
|
3
3
|
export interface AutoRefreshOptions {
|
|
4
4
|
interval: number;
|
|
5
5
|
}
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const SdkExtension_1 = __importDefault(require("@rc-ex/core/
|
|
6
|
+
const SdkExtension_1 = __importDefault(require("@rc-ex/core/src/SdkExtension"));
|
|
7
7
|
class AutoRefreshExtension extends SdkExtension_1.default {
|
|
8
8
|
constructor(options = { interval: 1000 * 60 * 30 }) {
|
|
9
9
|
super();
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;AACA,gFAAwD;AAMxD,MAAM,oBAAqB,SAAQ,sBAAY;IAK7C,YACE,UAA8B,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE,EAAE;QAE1D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,EAAe;QAClC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,gBAAgB;QAC7B,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;YAC9B,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QACpB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAEM,IAAI;QACT,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QAC3B,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,MAAM;QACjB,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;CACF;AAED,kBAAe,oBAAoB,CAAC"}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type RingCentral from "@rc-ex/core";
|
|
2
|
+
import SdkExtension from "@rc-ex/core/src/SdkExtension";
|
|
3
|
+
|
|
4
|
+
export interface AutoRefreshOptions {
|
|
5
|
+
interval: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class AutoRefreshExtension extends SdkExtension {
|
|
9
|
+
public rc!: RingCentral;
|
|
10
|
+
public options: AutoRefreshOptions;
|
|
11
|
+
private timeout?: NodeJS.Timeout;
|
|
12
|
+
|
|
13
|
+
public constructor(
|
|
14
|
+
options: AutoRefreshOptions = { interval: 1000 * 60 * 30 },
|
|
15
|
+
) {
|
|
16
|
+
super();
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public async install(rc: RingCentral) {
|
|
21
|
+
this.rc = rc;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public start() {
|
|
25
|
+
this.stop(); // stop existing
|
|
26
|
+
this.timeout = setInterval(() => {
|
|
27
|
+
this.rc.refresh();
|
|
28
|
+
}, this.options.interval);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public stop() {
|
|
32
|
+
if (this.timeout) {
|
|
33
|
+
clearInterval(this.timeout);
|
|
34
|
+
this.timeout = undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public async revoke(): Promise<void> {
|
|
39
|
+
this.stop();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default AutoRefreshExtension;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rc-ex/auto-refresh",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Auto Refresh extension for ringcentral-extensible project",
|
|
5
5
|
"author": "Tyler Liu <tyler.liu@ringcentral.com>",
|
|
6
6
|
"homepage": "https://github.com/ringcentral/ringcentral-extensible/tree/master/packages/extensions/auto-refresh",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"main": "
|
|
9
|
-
"types": "
|
|
8
|
+
"main": "src/index.js",
|
|
9
|
+
"types": "src/index.d.ts",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "git+https://github.com/ringcentral/ringcentral-extensible.git"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@rc-ex/core": "^1.5.
|
|
21
|
+
"@rc-ex/core": "^1.5.2"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "a0e465fd1f5d4b0758e6c3641635d5d2ee6c9a3a"
|
|
24
24
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type RingCentral from "@rc-ex/core";
|
|
2
|
+
import SdkExtension from "@rc-ex/core/src/SdkExtension";
|
|
3
|
+
export interface AutoRefreshOptions {
|
|
4
|
+
interval: number;
|
|
5
|
+
}
|
|
6
|
+
declare class AutoRefreshExtension extends SdkExtension {
|
|
7
|
+
rc: RingCentral;
|
|
8
|
+
options: AutoRefreshOptions;
|
|
9
|
+
private timeout?;
|
|
10
|
+
constructor(options?: AutoRefreshOptions);
|
|
11
|
+
install(rc: RingCentral): Promise<void>;
|
|
12
|
+
start(): void;
|
|
13
|
+
stop(): void;
|
|
14
|
+
revoke(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export default AutoRefreshExtension;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const SdkExtension_1 = __importDefault(require("@rc-ex/core/src/SdkExtension"));
|
|
7
|
+
class AutoRefreshExtension extends SdkExtension_1.default {
|
|
8
|
+
constructor(options = { interval: 1000 * 60 * 30 }) {
|
|
9
|
+
super();
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
async install(rc) {
|
|
13
|
+
this.rc = rc;
|
|
14
|
+
}
|
|
15
|
+
start() {
|
|
16
|
+
this.stop(); // stop existing
|
|
17
|
+
this.timeout = setInterval(() => {
|
|
18
|
+
this.rc.refresh();
|
|
19
|
+
}, this.options.interval);
|
|
20
|
+
}
|
|
21
|
+
stop() {
|
|
22
|
+
if (this.timeout) {
|
|
23
|
+
clearInterval(this.timeout);
|
|
24
|
+
this.timeout = undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async revoke() {
|
|
28
|
+
this.stop();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = AutoRefreshExtension;
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;AACA,gFAAwD;AAMxD,MAAM,oBAAqB,SAAQ,sBAAY;IAK7C,YACE,UAA8B,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE,EAAE;QAE1D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,EAAe;QAClC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,gBAAgB;QAC7B,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;YAC9B,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QACpB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAEM,IAAI;QACT,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QAC3B,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,MAAM;QACjB,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;CACF;AAED,kBAAe,oBAAoB,CAAC"}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type RingCentral from
|
|
2
|
-
import SdkExtension from
|
|
1
|
+
import type RingCentral from "@rc-ex/core";
|
|
2
|
+
import SdkExtension from "@rc-ex/core/src/SdkExtension";
|
|
3
3
|
|
|
4
4
|
export interface AutoRefreshOptions {
|
|
5
5
|
interval: number;
|
|
@@ -10,7 +10,9 @@ class AutoRefreshExtension extends SdkExtension {
|
|
|
10
10
|
public options: AutoRefreshOptions;
|
|
11
11
|
private timeout?: NodeJS.Timeout;
|
|
12
12
|
|
|
13
|
-
public constructor(
|
|
13
|
+
public constructor(
|
|
14
|
+
options: AutoRefreshOptions = { interval: 1000 * 60 * 30 },
|
|
15
|
+
) {
|
|
14
16
|
super();
|
|
15
17
|
this.options = options;
|
|
16
18
|
}
|