@ckeditor/ckeditor5-cloud-services 40.0.0 → 40.2.0

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.
@@ -1,121 +1,121 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module cloud-services/cloudservicesconfig
7
- */
8
- /**
9
- * Endpoint address to download the token or a callback that provides the token.
10
- */
11
- export type TokenUrl = string | (() => Promise<string>);
12
- /**
13
- * The configuration for all plugins using CKEditor Cloud Services.
14
- *
15
- * ```ts
16
- * ClassicEditor
17
- * .create( document.querySelector( '#editor' ), {
18
- * cloudServices: {
19
- * tokenUrl: 'https://example.com/cs-token-endpoint',
20
- * uploadUrl: 'https://your-organization-id.cke-cs.com/easyimage/upload/'
21
- * }
22
- * } )
23
- * .then( ... )
24
- * .catch( ... );
25
- * ```
26
- *
27
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
28
- */
29
- export interface CloudServicesConfig {
30
- /**
31
- * A token URL or a token request function.
32
- *
33
- * As a string, it should be a URL to the security token endpoint in your application.
34
- * The role of this endpoint is to securely authorize
35
- * the end users of your application to use [CKEditor Cloud Services](https://ckeditor.com/ckeditor-cloud-services) only
36
- * if they should have access e.g. to upload files with {@glink @cs guides/easy-image/quick-start Easy Image} or to use the
37
- * {@glink @cs guides/collaboration/quick-start Collaboration} service.
38
- *
39
- * ```ts
40
- * ClassicEditor
41
- * .create( document.querySelector( '#editor' ), {
42
- * cloudServices: {
43
- * tokenUrl: 'https://example.com/cs-token-endpoint',
44
- * ...
45
- * }
46
- * } )
47
- * .then( ... )
48
- * .catch( ... );
49
- * ```
50
- *
51
- * As a function, it should provide a promise to the token value,
52
- * so you can highly customize the token and provide your token URL endpoint.
53
- * By using this approach you can set your own headers for the request.
54
- *
55
- * ```ts
56
- * ClassicEditor
57
- * .create( document.querySelector( '#editor' ), {
58
- * cloudServices: {
59
- * tokenUrl: () => new Promise( ( resolve, reject ) => {
60
- * const xhr = new XMLHttpRequest();
61
- *
62
- * xhr.open( 'GET', 'https://example.com/cs-token-endpoint' );
63
- *
64
- * xhr.addEventListener( 'load', () => {
65
- * const statusCode = xhr.status;
66
- * const xhrResponse = xhr.response;
67
- *
68
- * if ( statusCode < 200 || statusCode > 299 ) {
69
- * return reject( new Error( 'Cannot download new token!' ) );
70
- * }
71
- *
72
- * return resolve( xhrResponse );
73
- * } );
74
- *
75
- * xhr.addEventListener( 'error', () => reject( new Error( 'Network Error' ) ) );
76
- * xhr.addEventListener( 'abort', () => reject( new Error( 'Abort' ) ) );
77
- *
78
- * xhr.setRequestHeader( customHeader, customValue );
79
- *
80
- * xhr.send();
81
- * } ),
82
- * ...
83
- * }
84
- * } )
85
- * ```
86
- *
87
- * You can find more information about token endpoints in the
88
- * {@glink @cs guides/easy-image/quick-start#create-token-endpoint Cloud Services - Quick start}
89
- * and {@glink @cs developer-resources/security/token-endpoint Cloud Services - Token endpoint} documentation.
90
- *
91
- * Without a properly working token endpoint (token URL) CKEditor plugins will not be able to connect to CKEditor Cloud Services.
92
- */
93
- tokenUrl?: TokenUrl;
94
- /**
95
- * The endpoint URL for [CKEditor Cloud Services](https://ckeditor.com/ckeditor-cloud-services) uploads.
96
- * This option must be set for Easy Image to work correctly.
97
- *
98
- * The upload URL is unique for each customer and can be found in the
99
- * [CKEditor Ecosystem customer dashboard](https://dashboard.ckeditor.com) after subscribing to the Easy Image service.
100
- * To learn how to start using Easy Image, check the {@glink @cs guides/easy-image/quick-start Easy Image - Quick start} documentation.
101
- *
102
- * Note: Make sure to also set the {@link module:cloud-services/cloudservicesconfig~CloudServicesConfig#tokenUrl} configuration option.
103
- */
104
- uploadUrl?: string;
105
- /**
106
- * The URL for web socket communication, used by the `RealTimeCollaborativeEditing` plugin. Every customer (organization in the CKEditor
107
- * Ecosystem dashboard) has their own, unique URLs to communicate with CKEditor Cloud Services. The URL can be found in the
108
- * CKEditor Ecosystem customer dashboard.
109
- *
110
- * Note: Unlike most plugins, `RealTimeCollaborativeEditing` is not included in any CKEditor 5 build and needs to be installed manually.
111
- * Check [Collaboration overview](https://ckeditor.com/docs/ckeditor5/latest/features/collaboration/overview.html) for more details.
112
- */
113
- webSocketUrl?: string;
114
- /**
115
- * An optional parameter used for integration with CKEditor Cloud Services when uploading the editor build to cloud services.
116
- *
117
- * Whenever the editor build or the configuration changes, this parameter should be set to a new, unique value to differentiate
118
- * the new bundle (build + configuration) from the old ones.
119
- */
120
- bundleVersion?: string;
121
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module cloud-services/cloudservicesconfig
7
+ */
8
+ /**
9
+ * Endpoint address to download the token or a callback that provides the token.
10
+ */
11
+ export type TokenUrl = string | (() => Promise<string>);
12
+ /**
13
+ * The configuration for all plugins using CKEditor Cloud Services.
14
+ *
15
+ * ```ts
16
+ * ClassicEditor
17
+ * .create( document.querySelector( '#editor' ), {
18
+ * cloudServices: {
19
+ * tokenUrl: 'https://example.com/cs-token-endpoint',
20
+ * uploadUrl: 'https://your-organization-id.cke-cs.com/easyimage/upload/'
21
+ * }
22
+ * } )
23
+ * .then( ... )
24
+ * .catch( ... );
25
+ * ```
26
+ *
27
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
28
+ */
29
+ export interface CloudServicesConfig {
30
+ /**
31
+ * A token URL or a token request function.
32
+ *
33
+ * As a string, it should be a URL to the security token endpoint in your application.
34
+ * The role of this endpoint is to securely authorize
35
+ * the end users of your application to use [CKEditor Cloud Services](https://ckeditor.com/ckeditor-cloud-services) only
36
+ * if they should have access e.g. to upload files with {@glink features/file-management/ckbox CKBox} or to use the
37
+ * {@glink @cs guides/collaboration/quick-start Collaboration} service.
38
+ *
39
+ * ```ts
40
+ * ClassicEditor
41
+ * .create( document.querySelector( '#editor' ), {
42
+ * cloudServices: {
43
+ * tokenUrl: 'https://example.com/cs-token-endpoint',
44
+ * ...
45
+ * }
46
+ * } )
47
+ * .then( ... )
48
+ * .catch( ... );
49
+ * ```
50
+ *
51
+ * As a function, it should provide a promise to the token value,
52
+ * so you can highly customize the token and provide your token URL endpoint.
53
+ * By using this approach you can set your own headers for the request.
54
+ *
55
+ * ```ts
56
+ * ClassicEditor
57
+ * .create( document.querySelector( '#editor' ), {
58
+ * cloudServices: {
59
+ * tokenUrl: () => new Promise( ( resolve, reject ) => {
60
+ * const xhr = new XMLHttpRequest();
61
+ *
62
+ * xhr.open( 'GET', 'https://example.com/cs-token-endpoint' );
63
+ *
64
+ * xhr.addEventListener( 'load', () => {
65
+ * const statusCode = xhr.status;
66
+ * const xhrResponse = xhr.response;
67
+ *
68
+ * if ( statusCode < 200 || statusCode > 299 ) {
69
+ * return reject( new Error( 'Cannot download new token!' ) );
70
+ * }
71
+ *
72
+ * return resolve( xhrResponse );
73
+ * } );
74
+ *
75
+ * xhr.addEventListener( 'error', () => reject( new Error( 'Network Error' ) ) );
76
+ * xhr.addEventListener( 'abort', () => reject( new Error( 'Abort' ) ) );
77
+ *
78
+ * xhr.setRequestHeader( customHeader, customValue );
79
+ *
80
+ * xhr.send();
81
+ * } ),
82
+ * ...
83
+ * }
84
+ * } )
85
+ * ```
86
+ *
87
+ * You can find more information about token endpoints in the
88
+ * {@glink @cs guides/easy-image/quick-start#create-token-endpoint Cloud Services - Quick start}
89
+ * and {@glink @cs developer-resources/security/token-endpoint Cloud Services - Token endpoint} documentation.
90
+ *
91
+ * Without a properly working token endpoint (token URL) CKEditor plugins will not be able to connect to CKEditor Cloud Services.
92
+ */
93
+ tokenUrl?: TokenUrl;
94
+ /**
95
+ * The endpoint URL for [CKEditor Cloud Services](https://ckeditor.com/ckeditor-cloud-services) uploads.
96
+ * This option must be set for Easy Image to work correctly.
97
+ *
98
+ * The upload URL is unique for each customer and can be found in the
99
+ * [CKEditor Ecosystem customer dashboard](https://dashboard.ckeditor.com) after subscribing to the Easy Image service.
100
+ * To learn how to start using Easy Image, check the {@glink @cs guides/easy-image/quick-start Easy Image - Quick start} documentation.
101
+ *
102
+ * Note: Make sure to also set the {@link module:cloud-services/cloudservicesconfig~CloudServicesConfig#tokenUrl} configuration option.
103
+ */
104
+ uploadUrl?: string;
105
+ /**
106
+ * The URL for web socket communication, used by the `RealTimeCollaborativeEditing` plugin. Every customer (organization in the CKEditor
107
+ * Ecosystem dashboard) has their own, unique URLs to communicate with CKEditor Cloud Services. The URL can be found in the
108
+ * CKEditor Ecosystem customer dashboard.
109
+ *
110
+ * Note: Unlike most plugins, `RealTimeCollaborativeEditing` is not included in any CKEditor 5 build and needs to be installed manually.
111
+ * Check [Collaboration overview](https://ckeditor.com/docs/ckeditor5/latest/features/collaboration/overview.html) for more details.
112
+ */
113
+ webSocketUrl?: string;
114
+ /**
115
+ * An optional parameter used for integration with CKEditor Cloud Services when uploading the editor build to cloud services.
116
+ *
117
+ * Whenever the editor build or the configuration changes, this parameter should be set to a new, unique value to differentiate
118
+ * the new bundle (build + configuration) from the old ones.
119
+ */
120
+ bundleVersion?: string;
121
+ }
@@ -1,5 +1,5 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- export {};
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ export {};
@@ -1,36 +1,36 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module cloud-services/cloudservicescore
7
- */
8
- import { ContextPlugin } from 'ckeditor5/src/core';
9
- import type { TokenUrl } from './cloudservicesconfig';
10
- import Token, { type InitializedToken, type TokenOptions } from './token/token';
11
- import UploadGateway from './uploadgateway/uploadgateway';
12
- /**
13
- * The `CloudServicesCore` plugin exposes the base API for communication with CKEditor Cloud Services.
14
- */
15
- export default class CloudServicesCore extends ContextPlugin {
16
- /**
17
- * @inheritDoc
18
- */
19
- static get pluginName(): "CloudServicesCore";
20
- /**
21
- * Creates the {@link module:cloud-services/token/token~Token} instance.
22
- *
23
- * @param tokenUrlOrRefreshToken Endpoint address to download the token or a callback that provides the token. If the
24
- * value is a function it has to match the {@link module:cloud-services/token/token~Token#refreshToken} interface.
25
- * @param options.initValue Initial value of the token.
26
- * @param options.autoRefresh Specifies whether to start the refresh automatically.
27
- */
28
- createToken(tokenUrlOrRefreshToken: TokenUrl, options?: TokenOptions): Token;
29
- /**
30
- * Creates the {@link module:cloud-services/uploadgateway/uploadgateway~UploadGateway} instance.
31
- *
32
- * @param token Token used for authentication.
33
- * @param apiAddress API address.
34
- */
35
- createUploadGateway(token: InitializedToken, apiAddress: string): UploadGateway;
36
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module cloud-services/cloudservicescore
7
+ */
8
+ import { ContextPlugin } from 'ckeditor5/src/core';
9
+ import type { TokenUrl } from './cloudservicesconfig';
10
+ import Token, { type InitializedToken, type TokenOptions } from './token/token';
11
+ import UploadGateway from './uploadgateway/uploadgateway';
12
+ /**
13
+ * The `CloudServicesCore` plugin exposes the base API for communication with CKEditor Cloud Services.
14
+ */
15
+ export default class CloudServicesCore extends ContextPlugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName(): "CloudServicesCore";
20
+ /**
21
+ * Creates the {@link module:cloud-services/token/token~Token} instance.
22
+ *
23
+ * @param tokenUrlOrRefreshToken Endpoint address to download the token or a callback that provides the token. If the
24
+ * value is a function it has to match the {@link module:cloud-services/token/token~Token#refreshToken} interface.
25
+ * @param options.initValue Initial value of the token.
26
+ * @param options.autoRefresh Specifies whether to start the refresh automatically.
27
+ */
28
+ createToken(tokenUrlOrRefreshToken: TokenUrl, options?: TokenOptions): Token;
29
+ /**
30
+ * Creates the {@link module:cloud-services/uploadgateway/uploadgateway~UploadGateway} instance.
31
+ *
32
+ * @param token Token used for authentication.
33
+ * @param apiAddress API address.
34
+ */
35
+ createUploadGateway(token: InitializedToken, apiAddress: string): UploadGateway;
36
+ }
@@ -1,41 +1,41 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module cloud-services/cloudservicescore
7
- */
8
- import { ContextPlugin } from 'ckeditor5/src/core';
9
- import Token from './token/token';
10
- import UploadGateway from './uploadgateway/uploadgateway';
11
- /**
12
- * The `CloudServicesCore` plugin exposes the base API for communication with CKEditor Cloud Services.
13
- */
14
- export default class CloudServicesCore extends ContextPlugin {
15
- /**
16
- * @inheritDoc
17
- */
18
- static get pluginName() {
19
- return 'CloudServicesCore';
20
- }
21
- /**
22
- * Creates the {@link module:cloud-services/token/token~Token} instance.
23
- *
24
- * @param tokenUrlOrRefreshToken Endpoint address to download the token or a callback that provides the token. If the
25
- * value is a function it has to match the {@link module:cloud-services/token/token~Token#refreshToken} interface.
26
- * @param options.initValue Initial value of the token.
27
- * @param options.autoRefresh Specifies whether to start the refresh automatically.
28
- */
29
- createToken(tokenUrlOrRefreshToken, options) {
30
- return new Token(tokenUrlOrRefreshToken, options);
31
- }
32
- /**
33
- * Creates the {@link module:cloud-services/uploadgateway/uploadgateway~UploadGateway} instance.
34
- *
35
- * @param token Token used for authentication.
36
- * @param apiAddress API address.
37
- */
38
- createUploadGateway(token, apiAddress) {
39
- return new UploadGateway(token, apiAddress);
40
- }
41
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module cloud-services/cloudservicescore
7
+ */
8
+ import { ContextPlugin } from 'ckeditor5/src/core';
9
+ import Token from './token/token';
10
+ import UploadGateway from './uploadgateway/uploadgateway';
11
+ /**
12
+ * The `CloudServicesCore` plugin exposes the base API for communication with CKEditor Cloud Services.
13
+ */
14
+ export default class CloudServicesCore extends ContextPlugin {
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ static get pluginName() {
19
+ return 'CloudServicesCore';
20
+ }
21
+ /**
22
+ * Creates the {@link module:cloud-services/token/token~Token} instance.
23
+ *
24
+ * @param tokenUrlOrRefreshToken Endpoint address to download the token or a callback that provides the token. If the
25
+ * value is a function it has to match the {@link module:cloud-services/token/token~Token#refreshToken} interface.
26
+ * @param options.initValue Initial value of the token.
27
+ * @param options.autoRefresh Specifies whether to start the refresh automatically.
28
+ */
29
+ createToken(tokenUrlOrRefreshToken, options) {
30
+ return new Token(tokenUrlOrRefreshToken, options);
31
+ }
32
+ /**
33
+ * Creates the {@link module:cloud-services/uploadgateway/uploadgateway~UploadGateway} instance.
34
+ *
35
+ * @param token Token used for authentication.
36
+ * @param apiAddress API address.
37
+ */
38
+ createUploadGateway(token, apiAddress) {
39
+ return new UploadGateway(token, apiAddress);
40
+ }
41
+ }
package/src/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module cloud-services
7
- */
8
- export { default as CloudServices } from './cloudservices';
9
- export { default as CloudServicesCore } from './cloudservicescore';
10
- export { TokenUrl, type CloudServicesConfig } from './cloudservicesconfig';
11
- export type { default as Token, InitializedToken } from './token/token';
12
- export type { default as UploadGateway } from './uploadgateway/uploadgateway';
13
- export type { default as FileUploader } from './uploadgateway/fileuploader';
14
- import './augmentation';
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module cloud-services
7
+ */
8
+ export { default as CloudServices } from './cloudservices';
9
+ export { default as CloudServicesCore } from './cloudservicescore';
10
+ export { TokenUrl, type CloudServicesConfig } from './cloudservicesconfig';
11
+ export type { default as Token, InitializedToken } from './token/token';
12
+ export type { default as UploadGateway } from './uploadgateway/uploadgateway';
13
+ export type { default as FileUploader } from './uploadgateway/fileuploader';
14
+ import './augmentation';
package/src/index.js CHANGED
@@ -1,10 +1,10 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module cloud-services
7
- */
8
- export { default as CloudServices } from './cloudservices';
9
- export { default as CloudServicesCore } from './cloudservicescore';
10
- import './augmentation';
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module cloud-services
7
+ */
8
+ export { default as CloudServices } from './cloudservices';
9
+ export { default as CloudServicesCore } from './cloudservicescore';
10
+ import './augmentation';
@@ -1,96 +1,96 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import type { TokenUrl } from '../cloudservicesconfig';
6
- declare const Token_base: {
7
- new (): import("ckeditor5/src/utils").Observable;
8
- prototype: import("ckeditor5/src/utils").Observable;
9
- };
10
- /**
11
- * Class representing the token used for communication with CKEditor Cloud Services.
12
- * Value of the token is retrieving from the specified URL and is refreshed every 1 hour by default.
13
- */
14
- export default class Token extends Token_base {
15
- /**
16
- * Value of the token.
17
- * The value of the token is undefined if `initValue` is not provided or `init` method was not called.
18
- * `create` method creates token with initialized value from url.
19
- *
20
- * @see module:cloud-services/token/token~InitializedToken
21
- * @observable
22
- * @readonly
23
- */
24
- value: string | undefined;
25
- /**
26
- * Base refreshing function.
27
- */
28
- private _refresh;
29
- private _options;
30
- private _tokenRefreshTimeout?;
31
- /**
32
- * Creates `Token` instance.
33
- * Method `init` should be called after using the constructor or use `create` method instead.
34
- *
35
- * @param tokenUrlOrRefreshToken Endpoint address to download the token or a callback that provides the token. If the
36
- * value is a function it has to match the {@link module:cloud-services/token/token~Token#refreshToken} interface.
37
- */
38
- constructor(tokenUrlOrRefreshToken: TokenUrl, options?: TokenOptions);
39
- /**
40
- * Initializes the token.
41
- */
42
- init(): Promise<InitializedToken>;
43
- /**
44
- * Refresh token method. Useful in a method form as it can be override in tests.
45
- */
46
- refreshToken(): Promise<InitializedToken>;
47
- /**
48
- * Destroys token instance. Stops refreshing.
49
- */
50
- destroy(): void;
51
- /**
52
- * Checks whether the provided token follows the JSON Web Tokens (JWT) format.
53
- *
54
- * @param tokenValue The token to validate.
55
- */
56
- private _validateTokenValue;
57
- /**
58
- * Registers a refresh token timeout for the time taken from token.
59
- */
60
- private _registerRefreshTokenTimeout;
61
- /**
62
- * Returns token refresh timeout time calculated from expire time in the token payload.
63
- *
64
- * If the token parse fails or the token payload doesn't contain, the default DEFAULT_TOKEN_REFRESH_TIMEOUT_TIME is returned.
65
- */
66
- private _getTokenRefreshTimeoutTime;
67
- /**
68
- * Creates a initialized {@link module:cloud-services/token/token~Token} instance.
69
- *
70
- * @param tokenUrlOrRefreshToken Endpoint address to download the token or a callback that provides the token. If the
71
- * value is a function it has to match the {@link module:cloud-services/token/token~Token#refreshToken} interface.
72
- */
73
- static create(tokenUrlOrRefreshToken: TokenUrl, options?: TokenOptions): Promise<InitializedToken>;
74
- }
75
- /**
76
- * A {@link ~Token} instance that has been initialized.
77
- */
78
- export type InitializedToken = Token & {
79
- value: string;
80
- };
81
- /**
82
- * Options for creating tokens.
83
- */
84
- export interface TokenOptions {
85
- /**
86
- * Initial value of the token.
87
- */
88
- initValue?: string;
89
- /**
90
- * Specifies whether to start the refresh automatically.
91
- *
92
- * @default true
93
- */
94
- autoRefresh?: boolean;
95
- }
96
- export {};
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import type { TokenUrl } from '../cloudservicesconfig';
6
+ declare const Token_base: {
7
+ new (): import("ckeditor5/src/utils").Observable;
8
+ prototype: import("ckeditor5/src/utils").Observable;
9
+ };
10
+ /**
11
+ * Class representing the token used for communication with CKEditor Cloud Services.
12
+ * Value of the token is retrieving from the specified URL and is refreshed every 1 hour by default.
13
+ */
14
+ export default class Token extends Token_base {
15
+ /**
16
+ * Value of the token.
17
+ * The value of the token is undefined if `initValue` is not provided or `init` method was not called.
18
+ * `create` method creates token with initialized value from url.
19
+ *
20
+ * @see module:cloud-services/token/token~InitializedToken
21
+ * @observable
22
+ * @readonly
23
+ */
24
+ value: string | undefined;
25
+ /**
26
+ * Base refreshing function.
27
+ */
28
+ private _refresh;
29
+ private _options;
30
+ private _tokenRefreshTimeout?;
31
+ /**
32
+ * Creates `Token` instance.
33
+ * Method `init` should be called after using the constructor or use `create` method instead.
34
+ *
35
+ * @param tokenUrlOrRefreshToken Endpoint address to download the token or a callback that provides the token. If the
36
+ * value is a function it has to match the {@link module:cloud-services/token/token~Token#refreshToken} interface.
37
+ */
38
+ constructor(tokenUrlOrRefreshToken: TokenUrl, options?: TokenOptions);
39
+ /**
40
+ * Initializes the token.
41
+ */
42
+ init(): Promise<InitializedToken>;
43
+ /**
44
+ * Refresh token method. Useful in a method form as it can be override in tests.
45
+ */
46
+ refreshToken(): Promise<InitializedToken>;
47
+ /**
48
+ * Destroys token instance. Stops refreshing.
49
+ */
50
+ destroy(): void;
51
+ /**
52
+ * Checks whether the provided token follows the JSON Web Tokens (JWT) format.
53
+ *
54
+ * @param tokenValue The token to validate.
55
+ */
56
+ private _validateTokenValue;
57
+ /**
58
+ * Registers a refresh token timeout for the time taken from token.
59
+ */
60
+ private _registerRefreshTokenTimeout;
61
+ /**
62
+ * Returns token refresh timeout time calculated from expire time in the token payload.
63
+ *
64
+ * If the token parse fails or the token payload doesn't contain, the default DEFAULT_TOKEN_REFRESH_TIMEOUT_TIME is returned.
65
+ */
66
+ private _getTokenRefreshTimeoutTime;
67
+ /**
68
+ * Creates a initialized {@link module:cloud-services/token/token~Token} instance.
69
+ *
70
+ * @param tokenUrlOrRefreshToken Endpoint address to download the token or a callback that provides the token. If the
71
+ * value is a function it has to match the {@link module:cloud-services/token/token~Token#refreshToken} interface.
72
+ */
73
+ static create(tokenUrlOrRefreshToken: TokenUrl, options?: TokenOptions): Promise<InitializedToken>;
74
+ }
75
+ /**
76
+ * A {@link ~Token} instance that has been initialized.
77
+ */
78
+ export type InitializedToken = Token & {
79
+ value: string;
80
+ };
81
+ /**
82
+ * Options for creating tokens.
83
+ */
84
+ export interface TokenOptions {
85
+ /**
86
+ * Initial value of the token.
87
+ */
88
+ initValue?: string;
89
+ /**
90
+ * Specifies whether to start the refresh automatically.
91
+ *
92
+ * @default true
93
+ */
94
+ autoRefresh?: boolean;
95
+ }
96
+ export {};