@ones-editor/editor 2.2.6-beta.1 → 2.2.8-beta.1
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/@ones-editor/core/src/core/doc/doc.d.ts +1 -0
- package/@ones-editor/core/src/core/editor-doc/editor-doc.d.ts +1 -0
- package/@ones-editor/misc/src/index.d.ts +1 -0
- package/@ones-editor/misc/src/re-auth/index.d.ts +23 -0
- package/@ones-editor/sharedb-doc/src/doc/auth-connection.d.ts +31 -39
- package/@ones-editor/sharedb-doc/src/doc/sharedb-client.d.ts +13 -6
- package/@ones-editor/sharedb-doc/src/doc/sharedb-doc.d.ts +4 -4
- package/@ones-editor/sharedb-doc/src/types.d.ts +2 -15
- package/@ones-editor/tsconfig.tsbuildinfo +1 -1
- package/dist/index.js +1877 -1857
- package/dist/types.d.ts +1 -13
- package/package.json +1 -1
- package/@ones-editor/sharedb-doc/src/doc/auto-renew-token.d.ts +0 -15
- package/@ones-editor/sharedb-doc/src/doc/connection-status.d.ts +0 -19
- package/@ones-editor/sharedb-doc/src/doc/edit-status.d.ts +0 -13
- package/dist/error-handler/index.d.ts +0 -19
|
@@ -132,6 +132,7 @@ export interface OnesEditorDocCallbacks {
|
|
|
132
132
|
onCustomMessage?: (msg: unknown) => void;
|
|
133
133
|
onStatusChanged?: (status: OnesEditorDocStatus) => void;
|
|
134
134
|
onError?: (error: Error) => void;
|
|
135
|
+
onAuthRecover?: () => void;
|
|
135
136
|
}
|
|
136
137
|
export interface UploadResourceOptions {
|
|
137
138
|
onProgress?: (progress: number) => void;
|
|
@@ -34,6 +34,7 @@ export default class EditorDoc extends EventCallbacks<OnesEditorDocCallbacks> im
|
|
|
34
34
|
onCustomMessage(msg: unknown): void;
|
|
35
35
|
onStatusChanged(status: OnesEditorDocStatus): void;
|
|
36
36
|
onError(error: Error): void;
|
|
37
|
+
onAuthRecover(): void;
|
|
37
38
|
uploadResource(file: File, options?: UploadResourceOptions): Promise<UploadResourceResult>;
|
|
38
39
|
addResources(resourceIds: string[]): Promise<string[]>;
|
|
39
40
|
buildResourceUrl(resourceId: string, options?: BuildResourceUrlOptions): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
2
|
+
import { OnesEditor, OnesEditorCustom, OnesEditorDocCallbacks } from '../../../../@ones-editor/core';
|
|
3
|
+
import ReAuthToolbar from './ui/toolbar';
|
|
4
|
+
import './locale';
|
|
5
|
+
type EventCallback = (() => void) | undefined;
|
|
6
|
+
declare const DOC_RE_AUTH_KEYS = "doc-re-auth-event";
|
|
7
|
+
type ReAuthEvent = {
|
|
8
|
+
tokenExpired: () => void;
|
|
9
|
+
};
|
|
10
|
+
declare class DocReAuthCallbacks extends TypedEmitter<ReAuthEvent> implements OnesEditorCustom, OnesEditorDocCallbacks {
|
|
11
|
+
private editor;
|
|
12
|
+
private authErrorCallback;
|
|
13
|
+
private authRecoverCallback;
|
|
14
|
+
reAuthToolbar: ReAuthToolbar;
|
|
15
|
+
constructor(editor: OnesEditor);
|
|
16
|
+
handleReAuth: () => void;
|
|
17
|
+
addAuthListen(event: 'authError' | 'authRecover', callback: EventCallback): void;
|
|
18
|
+
removeListeners(): void;
|
|
19
|
+
destroy: () => void;
|
|
20
|
+
onError: (error: Error) => void;
|
|
21
|
+
onAuthRecover: () => void;
|
|
22
|
+
}
|
|
23
|
+
export { ReAuthToolbar, DocReAuthCallbacks, DOC_RE_AUTH_KEYS, };
|
|
@@ -1,58 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { Connection, Doc } from 'sharedb/lib/client';
|
|
4
|
+
import ReconnectingWebSocket, { Event } from 'reconnecting-websocket';
|
|
5
|
+
import { AuthMessage, ReauthFunc } from '../types';
|
|
4
6
|
import './sharedb-ext';
|
|
5
|
-
export
|
|
6
|
-
renewingToken: (count: number) => void;
|
|
7
|
-
renewedToken: (auth: AuthMessage) => void;
|
|
8
|
-
renewTokenError: (error: Error) => void;
|
|
9
|
-
reauthing: (count: number) => void;
|
|
10
|
-
authError: (error: Error) => void;
|
|
11
|
-
authRecover: (auth: AuthMessage) => void;
|
|
12
|
-
unknownError: (error: Error) => void;
|
|
13
|
-
connectionError: (error: Error) => void;
|
|
14
|
-
disconnected: (reason: string) => void;
|
|
15
|
-
writeConflictError: (error: Error) => void;
|
|
16
|
-
maxUsersError: () => void;
|
|
17
|
-
requestReloadError: (error: Error) => void;
|
|
18
|
-
}
|
|
19
|
-
export declare class AuthConnection extends TypedEmitter<AutoConnectionEvents> {
|
|
7
|
+
export declare class AuthConnection {
|
|
20
8
|
url: string;
|
|
21
|
-
private
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
private connectionStatus;
|
|
30
|
-
private reauthing;
|
|
9
|
+
private reauthFunc?;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
connection?: Connection;
|
|
12
|
+
ws?: ReconnectingWebSocket;
|
|
13
|
+
retryCount: number;
|
|
14
|
+
events: EventEmitter;
|
|
15
|
+
token: string | null;
|
|
16
|
+
resourceToken: string | null;
|
|
31
17
|
pingOptions: {
|
|
32
18
|
interval: number;
|
|
33
19
|
timeout: number;
|
|
34
20
|
};
|
|
35
|
-
constructor(
|
|
21
|
+
constructor(url: string, reauthFunc?: ReauthFunc | undefined);
|
|
36
22
|
getBaseURL(): string;
|
|
37
23
|
getBase64BaseURL(): string;
|
|
38
|
-
|
|
39
|
-
getResourceToken(): string;
|
|
40
|
-
getAuthMessage(): AuthMessage;
|
|
41
|
-
verifyAuth(authMessage: AuthMessage): Promise<{
|
|
24
|
+
auth(auth: AuthMessage): Promise<{
|
|
42
25
|
read: string;
|
|
43
26
|
user: string;
|
|
44
27
|
}>;
|
|
45
28
|
logout(): Promise<void>;
|
|
46
|
-
init(): Promise<void>;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
init(auth: AuthMessage): Promise<void>;
|
|
30
|
+
reConnect(token: string): Promise<void>;
|
|
31
|
+
_autoReAuth(): Promise<void>;
|
|
32
|
+
autoReAuth(): Promise<void>;
|
|
33
|
+
handleAuthError(): Promise<void>;
|
|
34
|
+
reAuth: () => Promise<void>;
|
|
51
35
|
private emitPermissionError;
|
|
36
|
+
private emitAuthRecover;
|
|
37
|
+
private emitAuthError;
|
|
52
38
|
private emitRequestReloadError;
|
|
53
39
|
private emitWriteConflictError;
|
|
54
40
|
private emitMaxUsersError;
|
|
55
|
-
|
|
41
|
+
handleMessage(message: object): void;
|
|
56
42
|
get(collectionName: string, documentID: string): Doc;
|
|
43
|
+
addEventListener(event: 'open' | 'close' | 'error', callback: (e: Event | Error) => void): void;
|
|
44
|
+
onAuthError(callback: (error: Error) => void): void;
|
|
45
|
+
onAuthRecover(callback: () => void): void;
|
|
46
|
+
onWriteConflictError(callback: (error: Error) => void): void;
|
|
47
|
+
onMaxUsersError(callback: () => void): void;
|
|
48
|
+
onRequestReloadError(callback: (error: Error) => void): void;
|
|
57
49
|
end(logout: boolean): void;
|
|
58
50
|
}
|
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
import { BuildResourceUrlOptions, DocVersion, OnesEditorDocVersionExtra } from '../../../../@ones-editor/core';
|
|
2
2
|
import { Doc } from 'sharedb/lib/client';
|
|
3
|
+
import { Event } from 'reconnecting-websocket';
|
|
3
4
|
import type { AxiosResponse } from 'axios';
|
|
4
5
|
import { AuthConnection } from './auth-connection';
|
|
5
|
-
import { EditorDoc,
|
|
6
|
+
import { EditorDoc, ReauthFunc, AuthMessage, OnProgress, EditorOp, LinkDetails } from '../types';
|
|
6
7
|
export default class ShareDBClient {
|
|
7
8
|
connection: AuthConnection;
|
|
9
|
+
auth: AuthMessage;
|
|
8
10
|
private doc;
|
|
9
11
|
private reauthFunc?;
|
|
10
|
-
|
|
11
|
-
constructor(auth: AuthMessage, serverUrl: string, reauthFunc?:
|
|
12
|
-
get clientId(): string;
|
|
12
|
+
clientId: string;
|
|
13
|
+
constructor(auth: AuthMessage, serverUrl: string, reauthFunc?: ReauthFunc);
|
|
13
14
|
token(): string;
|
|
14
15
|
resourceToken(): string;
|
|
15
|
-
authMessage(): AuthMessage;
|
|
16
16
|
docId(): string;
|
|
17
17
|
editorServer(): string;
|
|
18
18
|
close(logout: boolean): void;
|
|
19
|
+
on(event: 'open' | 'close' | 'error', callback: (event: Event | Error) => void): void;
|
|
20
|
+
onAuthError(callback: (error: Error) => void): void;
|
|
21
|
+
onAuthRecover(callback: () => void): void;
|
|
22
|
+
onWriteConflictError(callback: (error: Error) => void): void;
|
|
23
|
+
onMaxUsersError(callback: () => void): void;
|
|
24
|
+
onRequestReloadError(callback: (error: Error) => void): void;
|
|
19
25
|
/**
|
|
20
26
|
* 根据Id生成一个文档对象,如果文档不存在,则创建一个新的。
|
|
21
27
|
* @param id 待获取的containerId
|
|
22
28
|
*/
|
|
23
29
|
getDoc: () => Promise<Doc<any>>;
|
|
24
30
|
authOnly(): Promise<void>;
|
|
25
|
-
getResourceToken(): string;
|
|
31
|
+
getResourceToken(): string | null;
|
|
26
32
|
hasDocContainer(): boolean;
|
|
27
33
|
apiServer(): string;
|
|
28
34
|
getFileUrlByHash(uploadFileUrl: string, hash: string, name: string, size: number, headers: {
|
|
@@ -51,4 +57,5 @@ export default class ShareDBClient {
|
|
|
51
57
|
recognizeLink(url: string): Promise<LinkDetails>;
|
|
52
58
|
getResourceId(url: string): string;
|
|
53
59
|
buildResourceUrl(resourceId: string, options?: BuildResourceUrlOptions): string;
|
|
60
|
+
reAuth(auto?: boolean): void;
|
|
54
61
|
}
|
|
@@ -4,9 +4,7 @@ import { LocalPresence } from 'sharedb/lib/sharedb';
|
|
|
4
4
|
import RemoteCaretsHandler from './remote-caret-handler';
|
|
5
5
|
import { EditorDoc, ShareDBDocCallbacks, ShareDBDocOptions } from '../types';
|
|
6
6
|
import ShareDBClient from './sharedb-client';
|
|
7
|
-
import { EditStatus } from './edit-status';
|
|
8
7
|
export default class ShareDBDoc extends EventCallbacks<ShareDBDocCallbacks> implements OnesEditorDoc, OnesEditorDocVersionHelper {
|
|
9
|
-
private options;
|
|
10
8
|
doc: Doc;
|
|
11
9
|
client: ShareDBClient;
|
|
12
10
|
localPresence?: LocalPresence;
|
|
@@ -15,8 +13,8 @@ export default class ShareDBDoc extends EventCallbacks<ShareDBDocCallbacks> impl
|
|
|
15
13
|
status: OnesEditorDocStatus;
|
|
16
14
|
disableLogout: boolean;
|
|
17
15
|
destroyed: boolean;
|
|
18
|
-
|
|
19
|
-
constructor(
|
|
16
|
+
options: ShareDBDocOptions | null;
|
|
17
|
+
constructor(client: ShareDBClient, doc: Doc, disableLogout?: boolean);
|
|
20
18
|
beginBatchUpdate(): number;
|
|
21
19
|
endBatchUpdate(): number;
|
|
22
20
|
static load(options: ShareDBDocOptions): Promise<ShareDBDoc>;
|
|
@@ -78,6 +76,7 @@ export default class ShareDBDoc extends EventCallbacks<ShareDBDocCallbacks> impl
|
|
|
78
76
|
onCreateComment(commentId: string, local: boolean): void;
|
|
79
77
|
onUpdateComment(commentId: string, local: boolean): void;
|
|
80
78
|
onCustomMessage(msg: unknown): void;
|
|
79
|
+
onAuthRecover(): void;
|
|
81
80
|
addResources(resourceIds: string[]): Promise<string[]>;
|
|
82
81
|
uploadResource(file: File, options?: UploadResourceOptions): Promise<UploadResourceResult>;
|
|
83
82
|
buildResourceUrl(resourceId: string, options?: BuildResourceUrlOptions): string;
|
|
@@ -109,4 +108,5 @@ export default class ShareDBDoc extends EventCallbacks<ShareDBDocCallbacks> impl
|
|
|
109
108
|
recognizeLink(url: string): Promise<import("../types").LinkDetails>;
|
|
110
109
|
parseHistoryData(historyData: OnesEditorDocHistoryData, handler: OnesEditorHistoryDataParseHandler): void;
|
|
111
110
|
getServerMeta(): OnesEditorDocServerMeta;
|
|
111
|
+
triggerReAuth(auto?: boolean): void;
|
|
112
112
|
}
|
|
@@ -62,29 +62,16 @@ export declare const FileExtError: {
|
|
|
62
62
|
};
|
|
63
63
|
export declare const AuthHeader = "x-live-editor-token";
|
|
64
64
|
export declare const BaseURLHeader = "x-live-editor-base-url";
|
|
65
|
-
export type
|
|
65
|
+
export type ReauthFunc = () => Promise<AuthMessage>;
|
|
66
66
|
export type OnProgress = (percentage: number) => void;
|
|
67
67
|
export interface ShareDBDocOptions {
|
|
68
68
|
auth: AuthMessage;
|
|
69
69
|
serverUrl: string;
|
|
70
|
+
reauthFunc?: ReauthFunc;
|
|
70
71
|
autoCreateDoc?: boolean;
|
|
71
72
|
templateData?: EditorDoc;
|
|
72
73
|
disableLogout?: boolean;
|
|
73
|
-
dirtyTimeout?: number;
|
|
74
74
|
onMaxUsersError?: () => void;
|
|
75
|
-
onDirtyTimeoutError?: () => void;
|
|
76
|
-
onClean?: () => void;
|
|
77
|
-
onRenewingToken?: (count: number) => void;
|
|
78
|
-
onRenewedToken?: (auth: AuthMessage) => void;
|
|
79
|
-
onRenewTokenError?: (error: Error) => void;
|
|
80
|
-
onReauthing?: () => void;
|
|
81
|
-
onReauthError?: (error: Error) => void;
|
|
82
|
-
onReauthRecovered?: (auth: AuthMessage) => void;
|
|
83
|
-
onUnknownError?: (error: Error) => void;
|
|
84
|
-
onDisconnected?: (reason: string) => void;
|
|
85
|
-
onConnectionError?: (error: Error) => void;
|
|
86
|
-
onUploadResourceError?: (error: Error) => void;
|
|
87
|
-
renewTokenFunc?: RenewTokenFunc;
|
|
88
75
|
buildResourceUrl?: (resourceId: string, options?: BuildResourceUrlOptions) => string;
|
|
89
76
|
uploadResource?: (file: File, options?: UploadResourceOptions) => Promise<UploadResourceResult>;
|
|
90
77
|
}
|