@atlaskit/collab-provider 8.8.0 → 8.8.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/CHANGELOG.md +6 -0
- package/dist/cjs/channel.js +1 -2
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/channel.js +1 -2
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/channel.js +1 -2
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/helpers/const.d.ts +0 -1
- package/dist/types-ts4.0/analytics/analytics-helper.d.ts +11 -0
- package/dist/types-ts4.0/analytics/performance.d.ts +15 -0
- package/dist/types-ts4.0/analytics/ufo.d.ts +3 -0
- package/dist/types-ts4.0/channel.d.ts +47 -0
- package/dist/types-ts4.0/config.d.ts +5 -0
- package/dist/types-ts4.0/connectivity/network.d.ts +17 -0
- package/dist/types-ts4.0/connectivity/reconnect-helper.d.ts +8 -0
- package/dist/types-ts4.0/connectivity/singleton.d.ts +3 -0
- package/dist/types-ts4.0/disconnected-reason-mapper.d.ts +16 -0
- package/dist/types-ts4.0/document/catchup.d.ts +9 -0
- package/dist/types-ts4.0/document/document-service.d.ts +86 -0
- package/dist/types-ts4.0/document/step-queue-state.d.ts +16 -0
- package/dist/types-ts4.0/emitter.d.ts +19 -0
- package/dist/types-ts4.0/errors/error-code-mapper.d.ts +2 -0
- package/dist/types-ts4.0/errors/error-types.d.ts +443 -0
- package/dist/types-ts4.0/feature-flags/__test__/index.unit.d.ts +1 -0
- package/dist/types-ts4.0/feature-flags/index.d.ts +9 -0
- package/dist/types-ts4.0/feature-flags/types.d.ts +13 -0
- package/dist/types-ts4.0/helpers/const.d.ts +183 -0
- package/dist/types-ts4.0/helpers/utils.d.ts +5 -0
- package/dist/types-ts4.0/index.d.ts +4 -0
- package/dist/types-ts4.0/metadata/metadata-service.d.ts +25 -0
- package/dist/types-ts4.0/participants/participants-helper.d.ts +14 -0
- package/dist/types-ts4.0/participants/participants-service.d.ts +70 -0
- package/dist/types-ts4.0/participants/participants-state.d.ts +13 -0
- package/dist/types-ts4.0/participants/telepointers-helper.d.ts +4 -0
- package/dist/types-ts4.0/provider/commit-step.d.ts +25 -0
- package/dist/types-ts4.0/provider/index.d.ts +162 -0
- package/dist/types-ts4.0/socket-io-provider.d.ts +5 -0
- package/dist/types-ts4.0/types.d.ts +265 -0
- package/dist/types-ts4.0/version-wrapper.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CollabEventPresenceData, CollabParticipant } from '@atlaskit/editor-common/collab';
|
|
2
|
+
import type { CollabEventTelepointerData, PresencePayload } from '../types';
|
|
3
|
+
export declare const PARTICIPANT_UPDATE_INTERVAL: number;
|
|
4
|
+
export declare type ProviderParticipant = CollabParticipant & {
|
|
5
|
+
userId: string;
|
|
6
|
+
clientId: number | string;
|
|
7
|
+
};
|
|
8
|
+
export declare type ParticipantsMap = Map<string, ProviderParticipant>;
|
|
9
|
+
export declare type PresenceEmit = (evt: 'presence', data: CollabEventPresenceData) => void;
|
|
10
|
+
export declare type TelepointerEmit = (evt: 'telepointer', data: CollabEventTelepointerData) => void;
|
|
11
|
+
export declare type GetUserType = ((userId: string) => Promise<Pick<ProviderParticipant, 'name' | 'avatar' | 'userId'>>) | undefined;
|
|
12
|
+
export declare const createParticipantFromPayload: (payload: PresencePayload & {
|
|
13
|
+
userId: string;
|
|
14
|
+
}, getUser: GetUserType) => Promise<ProviderParticipant>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { CollabEventPresenceData, CollabEventDisconnectedData } from '@atlaskit/editor-common/collab';
|
|
2
|
+
import AnalyticsHelper from '../analytics/analytics-helper';
|
|
3
|
+
import type { CollabEventTelepointerData, PresencePayload, StepJson, TelepointerPayload } from '../types';
|
|
4
|
+
import { GetUserType, TelepointerEmit } from './participants-helper';
|
|
5
|
+
import type { PresenceEmit } from './participants-helper';
|
|
6
|
+
import { ParticipantsState } from './participants-state';
|
|
7
|
+
export declare class ParticipantsService {
|
|
8
|
+
private participantsState;
|
|
9
|
+
private participantUpdateTimeout;
|
|
10
|
+
private analyticsHelper;
|
|
11
|
+
constructor(analyticsHelper: AnalyticsHelper | undefined, participantsState?: ParticipantsState);
|
|
12
|
+
/**
|
|
13
|
+
* Carries out 3 things: 1) enriches the participant with user data, 2) updates the participantsState, 3) emits the presence event
|
|
14
|
+
* @param payload Payload from incoming socket event
|
|
15
|
+
* @param getUser Function to get user data from confluence
|
|
16
|
+
* @param emit Function to execute emit from provider socket
|
|
17
|
+
* @returns Awaitable Promise, due to getUser
|
|
18
|
+
*/
|
|
19
|
+
updateParticipant: (payload: PresencePayload, getUser: GetUserType, emit: PresenceEmit) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Called when a participant leaves the session.
|
|
22
|
+
*
|
|
23
|
+
* We emit the `presence` event to update the active avatars in the editor.
|
|
24
|
+
*/
|
|
25
|
+
participantLeft: ({ sessionId }: PresencePayload, emit: PresenceEmit) => void;
|
|
26
|
+
disconnect: (reason: string, sessionId: string | undefined, emit: (evt: 'presence' | 'disconnected', data: CollabEventPresenceData | CollabEventDisconnectedData) => void) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Updates when users were last active
|
|
29
|
+
* @param userIds Users in most recent steps
|
|
30
|
+
*/
|
|
31
|
+
updateLastActive: (userIds?: string[]) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Called on receiving steps, emits each step's telepointer
|
|
34
|
+
* @param steps Steps to extract telepointers from
|
|
35
|
+
* @param emit Provider emit function
|
|
36
|
+
*/
|
|
37
|
+
emitTelepointersFromSteps(steps: StepJson[], emit: TelepointerEmit): void;
|
|
38
|
+
/**
|
|
39
|
+
* Called when we receive a telepointer update from another
|
|
40
|
+
* participant.
|
|
41
|
+
*/
|
|
42
|
+
participantTelepointer: (payload: TelepointerPayload, thisSessionId: string | undefined, getUser: GetUserType, emit: (evt: 'telepointer' | 'presence', data: CollabEventTelepointerData | CollabEventPresenceData) => void) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Every 5 minutes (PARTICIPANT_UPDATE_INTERVAL), removes inactive participants and emits the update to other participants.
|
|
45
|
+
* Needs to be kicked off in the Provider.
|
|
46
|
+
* @param sessionId SessionId from provider's connection
|
|
47
|
+
* @param emit Function to execute emit from provider socket
|
|
48
|
+
*/
|
|
49
|
+
removeInactiveParticipants: (sessionId: string | undefined, emit: PresenceEmit) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Keep list of participants up to date. Filter out inactive users etc.
|
|
52
|
+
*/
|
|
53
|
+
private filterInactive;
|
|
54
|
+
/**
|
|
55
|
+
* Wrapper function to emit with error handling and analytics
|
|
56
|
+
* @param data Data to emit
|
|
57
|
+
* @param emit Emit function from Provider
|
|
58
|
+
*/
|
|
59
|
+
private emitPresence;
|
|
60
|
+
/**
|
|
61
|
+
* Wrapper function to emit with error handling and analytics
|
|
62
|
+
* @param data Data to emit
|
|
63
|
+
* @param emit Emit function from Provider
|
|
64
|
+
*/
|
|
65
|
+
private emitTelepointer;
|
|
66
|
+
/**
|
|
67
|
+
* Used when the provider is disconnected or destroyed to prevent perpetual timers from continuously running
|
|
68
|
+
*/
|
|
69
|
+
clearTimers: () => void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ParticipantsMap, ProviderParticipant } from './participants-helper';
|
|
2
|
+
export declare class ParticipantsState {
|
|
3
|
+
private participants;
|
|
4
|
+
constructor(baseParticipants?: ParticipantsMap);
|
|
5
|
+
getBySessionId: (sessionId: string) => ProviderParticipant | undefined;
|
|
6
|
+
setBySessionId: (sessionId: string, participant: ProviderParticipant) => void;
|
|
7
|
+
getParticipants: () => ProviderParticipant[];
|
|
8
|
+
removeBySessionId: (sessionId: string) => boolean;
|
|
9
|
+
clear: () => void;
|
|
10
|
+
doesntHave: (sessionId: string) => boolean;
|
|
11
|
+
size: () => number;
|
|
12
|
+
updateLastActive: (now: number, userIds: string[]) => void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AcknowledgementPayload, CollabEventTelepointerData, StepJson } from '../types';
|
|
2
|
+
import { ProviderParticipant } from './participants-helper';
|
|
3
|
+
export declare const telepointerFromStep: (participants: ProviderParticipant[], step: StepJson) => CollabEventTelepointerData | undefined;
|
|
4
|
+
export declare const telepointerCallback: (documentAri: string) => (response: AcknowledgementPayload) => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="lodash" />
|
|
2
|
+
import { ChannelEvent, StepsPayload } from '../types';
|
|
3
|
+
import type { Step as ProseMirrorStep } from 'prosemirror-transform';
|
|
4
|
+
import AnalyticsHelper from '../analytics/analytics-helper';
|
|
5
|
+
import type { InternalError } from '../errors/error-types';
|
|
6
|
+
export declare const commitStep: ({ broadcast, steps, version, userId, clientId, onStepsAdded, onErrorHandled, analyticsHelper, }: {
|
|
7
|
+
broadcast: <K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], "timestamp">, callback?: Function | undefined) => void;
|
|
8
|
+
steps: readonly ProseMirrorStep[];
|
|
9
|
+
version: number;
|
|
10
|
+
userId: string;
|
|
11
|
+
clientId: number | string;
|
|
12
|
+
onStepsAdded: (data: StepsPayload) => void;
|
|
13
|
+
onErrorHandled: (error: InternalError) => void;
|
|
14
|
+
analyticsHelper?: AnalyticsHelper | undefined;
|
|
15
|
+
}) => void;
|
|
16
|
+
export declare const throttledCommitStep: import("lodash").DebouncedFunc<({ broadcast, steps, version, userId, clientId, onStepsAdded, onErrorHandled, analyticsHelper, }: {
|
|
17
|
+
broadcast: <K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], "timestamp">, callback?: Function | undefined) => void;
|
|
18
|
+
steps: readonly ProseMirrorStep[];
|
|
19
|
+
version: number;
|
|
20
|
+
userId: string;
|
|
21
|
+
clientId: number | string;
|
|
22
|
+
onStepsAdded: (data: StepsPayload) => void;
|
|
23
|
+
onErrorHandled: (error: InternalError) => void;
|
|
24
|
+
analyticsHelper?: AnalyticsHelper | undefined;
|
|
25
|
+
}) => void>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { EditorState, Transaction } from 'prosemirror-state';
|
|
2
|
+
import type { Step as ProseMirrorStep } from 'prosemirror-transform';
|
|
3
|
+
import { Emitter } from '../emitter';
|
|
4
|
+
import type { ResolvedEditorState } from '@atlaskit/editor-common/collab';
|
|
5
|
+
import type { CollabEditProvider, CollabEvents, CollabEventTelepointerData, Config, Metadata } from '../types';
|
|
6
|
+
import type { SyncUpErrorFunction } from '@atlaskit/editor-common/types';
|
|
7
|
+
export declare const MAX_STEP_REJECTED_ERROR = 15;
|
|
8
|
+
declare type BaseEvents = Pick<CollabEditProvider<CollabEvents>, 'setup' | 'send' | 'sendMessage'>;
|
|
9
|
+
export declare class Provider extends Emitter<CollabEvents> implements BaseEvents {
|
|
10
|
+
private channel;
|
|
11
|
+
private config;
|
|
12
|
+
private analyticsHelper?;
|
|
13
|
+
private isChannelInitialized;
|
|
14
|
+
private initialDraft?;
|
|
15
|
+
private isProviderInitialized;
|
|
16
|
+
private isNamespaceLocked;
|
|
17
|
+
private sessionId?;
|
|
18
|
+
private clientId?;
|
|
19
|
+
private userId?;
|
|
20
|
+
private presenceUpdateTimeout?;
|
|
21
|
+
private disconnectedAt?;
|
|
22
|
+
private readonly participantsService;
|
|
23
|
+
private readonly metadataService;
|
|
24
|
+
private readonly documentService;
|
|
25
|
+
private readonly emitCallback;
|
|
26
|
+
constructor(config: Config);
|
|
27
|
+
private initializeChannel;
|
|
28
|
+
/**
|
|
29
|
+
* Initialisation logic, called by Jira with a dummy getState function, deprecated in favour of the setup method which allows more configuration
|
|
30
|
+
* @param {Function} getState Function that returns the editor state, used to retrieve collab-edit properties and to interact with prosemirror-collab
|
|
31
|
+
* @throws {ProviderInitialisationError} Something went wrong during provider initialisation
|
|
32
|
+
* @deprecated Use setup method instead
|
|
33
|
+
*/
|
|
34
|
+
initialize(getState: () => EditorState): this;
|
|
35
|
+
/**
|
|
36
|
+
* Initialisation logic, called by the editor in the collab-edit plugin
|
|
37
|
+
* @param {Object} parameters ...
|
|
38
|
+
* @param {Function} parameters.getState Function that returns the editor state, used to retrieve collab-edit properties and to interact with prosemirror-collab
|
|
39
|
+
* @param {SyncUpErrorFunction} parameters.onSyncUpError (Optional) Function that gets called when the sync of steps fails after retrying 30 times, used by Editor to log to analytics
|
|
40
|
+
* @throws {ProviderInitialisationError} Something went wrong during provider initialisation
|
|
41
|
+
*/
|
|
42
|
+
setup({ getState, onSyncUpError, }: {
|
|
43
|
+
getState: () => EditorState;
|
|
44
|
+
onSyncUpError?: SyncUpErrorFunction;
|
|
45
|
+
}): this;
|
|
46
|
+
private checkForCookies;
|
|
47
|
+
/**
|
|
48
|
+
* Send steps from transaction to NCS (and as a consequence to other participants), called from the collab-edit plugin in the editor
|
|
49
|
+
* @param {Transaction} _tr Deprecated, included to keep API consistent with Synchrony provider
|
|
50
|
+
* @param {EditorState} _oldState Deprecated, included to keep API consistent with Synchrony provider
|
|
51
|
+
* @param {EditorState} newState The editor state after applying the transaction
|
|
52
|
+
* @throws {SendTransactionError} Something went wrong while sending the steps for this transaction
|
|
53
|
+
*/
|
|
54
|
+
send(_tr: Transaction | null, _oldState: EditorState | null, newState: EditorState): void;
|
|
55
|
+
/**
|
|
56
|
+
* @param {InternalError} error The error to handle
|
|
57
|
+
*/
|
|
58
|
+
private onErrorHandled;
|
|
59
|
+
/**
|
|
60
|
+
* Send messages, such as telepointers, to NCS and other participants. Only used for telepointer data (text and node selections) in the editor and JWM. JWM does some weird serialisation stuff on the node selections.
|
|
61
|
+
* Silently fails if an error occurs, since Presence isn't a critical functionality and self-restores over time.
|
|
62
|
+
* @param {CollabEventTelepointerData} data Data you want to send to NCS / the other participants
|
|
63
|
+
* @param {string} data.type Can only be 'telepointer' for now, we don't support anything else yet
|
|
64
|
+
* @param {CollabSendableSelection} data.selection Object representing the selected element
|
|
65
|
+
* @param {string} data.sessionId Identifier identifying the session
|
|
66
|
+
*/
|
|
67
|
+
sendMessage(data: CollabEventTelepointerData): void;
|
|
68
|
+
private sendPresence;
|
|
69
|
+
/**
|
|
70
|
+
* Called when a participant joins the session.
|
|
71
|
+
*
|
|
72
|
+
* We keep track of participants internally in this class, and emit the `presence` event to update
|
|
73
|
+
* the active avatars in the editor.
|
|
74
|
+
* This method will be triggered from backend to notify all participants to exchange presence
|
|
75
|
+
*/
|
|
76
|
+
private onPresenceJoined;
|
|
77
|
+
private onPresence;
|
|
78
|
+
/**
|
|
79
|
+
* Called when a participant leaves the session.
|
|
80
|
+
*
|
|
81
|
+
* We emit the `presence` event to update the active avatars in the editor.
|
|
82
|
+
*/
|
|
83
|
+
private onParticipantLeft;
|
|
84
|
+
private startInactiveRemover;
|
|
85
|
+
/**
|
|
86
|
+
* Called when we receive an update event from another participant.
|
|
87
|
+
*/
|
|
88
|
+
private onParticipantUpdated;
|
|
89
|
+
/**
|
|
90
|
+
* Called when we receive a telepointer update from another
|
|
91
|
+
* participant.
|
|
92
|
+
*/
|
|
93
|
+
private onParticipantTelepointer;
|
|
94
|
+
private onDisconnected;
|
|
95
|
+
/**
|
|
96
|
+
* "Destroy" the provider, disconnect it's connection to the back-end service and unsubscribe all event listeners on the provider.
|
|
97
|
+
* Used by Jira products (JWM, JPD) to disable the provider
|
|
98
|
+
* @throws {DestroyError} Something went wrong while shutting down the collab provider
|
|
99
|
+
*/
|
|
100
|
+
destroy(): this;
|
|
101
|
+
/**
|
|
102
|
+
* Disconnect the provider, disconnect it's connection to the back-end service and unsubscribe all event listeners on the provider.
|
|
103
|
+
* Used by Confluence to disable the provider when a user doesn't have access to a resource.
|
|
104
|
+
* @deprecated use destroy instead, it does the same thing
|
|
105
|
+
* @throws {DestroyError} Something went wrong while shutting down the collab provider
|
|
106
|
+
*/
|
|
107
|
+
disconnect(): this;
|
|
108
|
+
/**
|
|
109
|
+
* Disconnect the provider's connection to the back-end service and unsubscribe from all events emitted by this provider. Kept to keep roughly aligned to Synchrony API, which you need to call for each event.
|
|
110
|
+
* @deprecated use destroy instead, it does the same thing
|
|
111
|
+
* @throws {DestroyError} Something went wrong while shutting down the collab provider
|
|
112
|
+
*/
|
|
113
|
+
unsubscribeAll(): this;
|
|
114
|
+
/**
|
|
115
|
+
* Update the title of the document in the collab provider and optionally broadcast it to other participants and NCS
|
|
116
|
+
* @deprecated use setMetadata instead, it does the same thing
|
|
117
|
+
* @param {string} title Title you want to set on the document
|
|
118
|
+
* @param {boolean} broadcast (Optional) Flag indicating whether you want to broadcast the title change to the other participants, always true for now (otherwise we would lose title changes)
|
|
119
|
+
* @throws {SetTitleError} Something went wrong while setting the title
|
|
120
|
+
*/
|
|
121
|
+
setTitle(title: string, broadcast?: boolean): void;
|
|
122
|
+
/**
|
|
123
|
+
* Set editor width, not used any more
|
|
124
|
+
* @deprecated use setMetadata instead, it does the same thing
|
|
125
|
+
* @param {string} editorWidth string? indicating the editor width
|
|
126
|
+
* @param {boolean} broadcast (Optional) Flag indicating whether you want to broadcast the editor width change
|
|
127
|
+
* @throws {SetEditorWidthError} Something went wrong while setting the editor width
|
|
128
|
+
*/
|
|
129
|
+
setEditorWidth(editorWidth: string, broadcast?: boolean): void;
|
|
130
|
+
/**
|
|
131
|
+
* Set the editor width and title and distribute it to all participants. Used by Confluence
|
|
132
|
+
* @param {Metadata} metadata The metadata you want to update
|
|
133
|
+
* @throws {ExampleError} Something went wrong while setting the metadata
|
|
134
|
+
*/
|
|
135
|
+
setMetadata(metadata: Metadata): void;
|
|
136
|
+
/**
|
|
137
|
+
* Returns the documents metadata
|
|
138
|
+
*/
|
|
139
|
+
getMetadata: () => Metadata;
|
|
140
|
+
/**
|
|
141
|
+
* Return the ADF version of the current draft document, together with it's title and the current step version.
|
|
142
|
+
* Used for draft sync, a process running every 5s for the first editor of a document to sync the document to the Confluence back-end.
|
|
143
|
+
* @throws {GetCurrentStateError} Something went wrong while returning the current state
|
|
144
|
+
*/
|
|
145
|
+
getCurrentState: () => Promise<ResolvedEditorState>;
|
|
146
|
+
/**
|
|
147
|
+
* Return the final acknowledged (by NCS) ADF version of the current draft document, together with it's title and the current step version.
|
|
148
|
+
* Used when returning the document to Confluence on publish.
|
|
149
|
+
* @throws {GetFinalAcknowledgedStateError} Something went wrong while returning the acknowledged state
|
|
150
|
+
*/
|
|
151
|
+
getFinalAcknowledgedState: () => Promise<ResolvedEditorState>;
|
|
152
|
+
getUnconfirmedSteps: () => readonly ProseMirrorStep[] | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* ESS-2916 namespace status event- lock/unlock
|
|
155
|
+
*/
|
|
156
|
+
private onNamespaceStatusChanged;
|
|
157
|
+
/**
|
|
158
|
+
* Used when the provider is disconnected or destroyed to prevent perpetual timers from continuously running
|
|
159
|
+
*/
|
|
160
|
+
private clearTimers;
|
|
161
|
+
}
|
|
162
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Provider } from './provider';
|
|
2
|
+
import { Socket } from 'socket.io-client';
|
|
3
|
+
import { Config, ProductInformation, InitAndAuthData, AuthCallback } from './types';
|
|
4
|
+
export declare function createSocketIOSocket(url: string, auth?: AuthCallback | InitAndAuthData, productInfo?: ProductInformation): Socket;
|
|
5
|
+
export declare function createSocketIOCollabProvider(config: Omit<Config, 'createSocket'>): Provider;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import type { Step } from 'prosemirror-transform';
|
|
2
|
+
import type { EditorState, Transaction } from 'prosemirror-state';
|
|
3
|
+
import type { CollabEventConnectionData, CollabEventInitData, CollabEventRemoteData, CollabEventPresenceData, CollabEventConnectingData, ResolvedEditorState } from '@atlaskit/editor-common/collab';
|
|
4
|
+
import type { AnalyticsWebClient } from '@atlaskit/analytics-listeners';
|
|
5
|
+
import type { Manager } from 'socket.io-client';
|
|
6
|
+
import type { DisconnectReason } from './disconnected-reason-mapper';
|
|
7
|
+
import type { InternalError } from './errors/error-types';
|
|
8
|
+
import type { ProviderError } from './errors/error-types';
|
|
9
|
+
import type { SyncUpErrorFunction } from '@atlaskit/editor-common/types';
|
|
10
|
+
import { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
11
|
+
import { ProviderParticipant } from './participants/participants-helper';
|
|
12
|
+
export interface Storage {
|
|
13
|
+
get(key: string): Promise<string>;
|
|
14
|
+
set(key: string, value: string): Promise<void>;
|
|
15
|
+
delete(key: string): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export interface InitialDraft {
|
|
18
|
+
document: JSONDocNode;
|
|
19
|
+
version: number;
|
|
20
|
+
metadata?: Metadata;
|
|
21
|
+
}
|
|
22
|
+
export interface Config {
|
|
23
|
+
url: string;
|
|
24
|
+
documentAri: string;
|
|
25
|
+
lifecycle?: Lifecycle;
|
|
26
|
+
storage?: Storage;
|
|
27
|
+
need404?: boolean;
|
|
28
|
+
createSocket: (path: string, auth?: AuthCallback | InitAndAuthData, productInfo?: ProductInformation) => Socket;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated: Use promise based getAnalyticsWebClient instead
|
|
31
|
+
*/
|
|
32
|
+
analyticsClient?: AnalyticsWebClient;
|
|
33
|
+
getAnalyticsWebClient?: Promise<AnalyticsWebClient>;
|
|
34
|
+
featureFlags?: {
|
|
35
|
+
[key: string]: boolean;
|
|
36
|
+
};
|
|
37
|
+
getUser?(userId: string): Promise<Pick<ProviderParticipant, 'avatar' | 'name' | 'userId'>>;
|
|
38
|
+
/**
|
|
39
|
+
* If provided, permissionTokenRefresh is called whenever a new JWT token is required.
|
|
40
|
+
*/
|
|
41
|
+
permissionTokenRefresh?: () => Promise<string | null>;
|
|
42
|
+
cacheToken?: boolean;
|
|
43
|
+
productInfo?: ProductInformation;
|
|
44
|
+
/**
|
|
45
|
+
* Throws errors when trying to send data to collab but the client is not offline.
|
|
46
|
+
* This can lead to potential dataloss and retrying should be considered. Without this flag the provider silently drops the requests.
|
|
47
|
+
*/
|
|
48
|
+
throwOnNotConnected?: boolean;
|
|
49
|
+
initialDraft?: InitialDraft;
|
|
50
|
+
}
|
|
51
|
+
export interface InitAndAuthData {
|
|
52
|
+
initialized: boolean;
|
|
53
|
+
need404?: boolean;
|
|
54
|
+
token?: string;
|
|
55
|
+
}
|
|
56
|
+
export declare type AuthCallback = (cb: (data: InitAndAuthData) => void) => void;
|
|
57
|
+
interface SimpleEventEmitter {
|
|
58
|
+
on(event: string, fn: Function): SimpleEventEmitter;
|
|
59
|
+
}
|
|
60
|
+
export interface Socket extends SimpleEventEmitter {
|
|
61
|
+
id: string;
|
|
62
|
+
connect(): Socket;
|
|
63
|
+
emit(event: string, ...args: any[]): Socket;
|
|
64
|
+
close(): Socket;
|
|
65
|
+
io?: Manager;
|
|
66
|
+
}
|
|
67
|
+
export declare type LifecycleEvents = 'save' | 'restore';
|
|
68
|
+
export declare type EventHandler = () => void;
|
|
69
|
+
export interface Lifecycle {
|
|
70
|
+
on(event: LifecycleEvents, handler: EventHandler): void;
|
|
71
|
+
}
|
|
72
|
+
export declare type CollabConnectedPayload = CollabEventConnectionData;
|
|
73
|
+
export declare type CollabConnectingPayload = CollabEventConnectingData;
|
|
74
|
+
export interface CollabDisconnectedPayload {
|
|
75
|
+
reason: DisconnectReason;
|
|
76
|
+
sid: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @deprecated Use ProviderError type instead
|
|
80
|
+
*/
|
|
81
|
+
export declare type CollabErrorPayload = ProviderError;
|
|
82
|
+
export interface CollabInitPayload extends CollabEventInitData {
|
|
83
|
+
doc: any;
|
|
84
|
+
version: number;
|
|
85
|
+
metadata?: Metadata;
|
|
86
|
+
reserveCursor?: boolean;
|
|
87
|
+
}
|
|
88
|
+
export interface CollabDataPayload extends CollabEventRemoteData {
|
|
89
|
+
version: number;
|
|
90
|
+
json: StepJson[];
|
|
91
|
+
userIds: (number | string)[];
|
|
92
|
+
}
|
|
93
|
+
export declare type CollabTelepointerPayload = CollabEventTelepointerData;
|
|
94
|
+
export declare type CollabPresencePayload = CollabEventPresenceData;
|
|
95
|
+
export declare type CollabMetadataPayload = Metadata;
|
|
96
|
+
export declare type CollabLocalStepsPayload = {
|
|
97
|
+
steps: readonly Step[];
|
|
98
|
+
};
|
|
99
|
+
export interface CollabEvents {
|
|
100
|
+
'metadata:changed': CollabMetadataPayload;
|
|
101
|
+
init: CollabInitPayload;
|
|
102
|
+
connected: CollabConnectedPayload;
|
|
103
|
+
disconnected: CollabDisconnectedPayload;
|
|
104
|
+
data: CollabDataPayload;
|
|
105
|
+
telepointer: CollabTelepointerPayload;
|
|
106
|
+
presence: CollabPresencePayload;
|
|
107
|
+
'local-steps': CollabLocalStepsPayload;
|
|
108
|
+
error: CollabErrorPayload;
|
|
109
|
+
entity: any;
|
|
110
|
+
connecting: CollabConnectingPayload;
|
|
111
|
+
}
|
|
112
|
+
export interface Metadata {
|
|
113
|
+
[key: string]: string | number | boolean;
|
|
114
|
+
}
|
|
115
|
+
export declare type InitPayload = {
|
|
116
|
+
doc: any;
|
|
117
|
+
version: number;
|
|
118
|
+
userId?: string;
|
|
119
|
+
metadata?: Metadata;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* @description Incoming payload type from the `broadcast` route in NCS
|
|
123
|
+
* @param {number} timestamp added in NCS
|
|
124
|
+
* @param {string} sessionId socket.id from NCS
|
|
125
|
+
* @param data event specific data from NCS
|
|
126
|
+
*/
|
|
127
|
+
export declare type BroadcastIncomingPayload = {
|
|
128
|
+
sessionId?: string;
|
|
129
|
+
timestamp?: number;
|
|
130
|
+
data: PresencePayload | TelepointerPayload | StepsPayload | any;
|
|
131
|
+
};
|
|
132
|
+
export declare type PresencePayload = {
|
|
133
|
+
sessionId: string;
|
|
134
|
+
userId: string | undefined;
|
|
135
|
+
clientId: number | string;
|
|
136
|
+
timestamp: number;
|
|
137
|
+
};
|
|
138
|
+
export declare type TelepointerPayload = PresencePayload & {
|
|
139
|
+
selection: CollabSendableSelection;
|
|
140
|
+
};
|
|
141
|
+
declare type MarkJson = {
|
|
142
|
+
type: string;
|
|
143
|
+
attrs: {
|
|
144
|
+
[key: string]: any;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
declare type NodeJson = {
|
|
148
|
+
type: string;
|
|
149
|
+
attrs: {
|
|
150
|
+
[key: string]: any;
|
|
151
|
+
};
|
|
152
|
+
content: NodeJson[];
|
|
153
|
+
marks: MarkJson[];
|
|
154
|
+
text?: string;
|
|
155
|
+
};
|
|
156
|
+
declare type SliceJson = {
|
|
157
|
+
content: NodeJson[];
|
|
158
|
+
openStart: number;
|
|
159
|
+
openEnd: number;
|
|
160
|
+
};
|
|
161
|
+
export declare type StepJson = {
|
|
162
|
+
stepType?: string;
|
|
163
|
+
from?: number;
|
|
164
|
+
to?: number;
|
|
165
|
+
slice?: SliceJson;
|
|
166
|
+
clientId: number | string;
|
|
167
|
+
userId: string;
|
|
168
|
+
createdAt?: number;
|
|
169
|
+
structure?: boolean;
|
|
170
|
+
};
|
|
171
|
+
export declare enum AcknowledgementResponseTypes {
|
|
172
|
+
SUCCESS = "SUCCESS",
|
|
173
|
+
ERROR = "ERROR"
|
|
174
|
+
}
|
|
175
|
+
export declare type AcknowledgementSuccessPayload = {
|
|
176
|
+
type: AcknowledgementResponseTypes.SUCCESS;
|
|
177
|
+
};
|
|
178
|
+
export declare type AcknowledgementPayload = AcknowledgementSuccessPayload | AcknowledgementErrorPayload;
|
|
179
|
+
export declare type AddStepAcknowledgementSuccessPayload = {
|
|
180
|
+
type: AcknowledgementResponseTypes.SUCCESS;
|
|
181
|
+
version: number;
|
|
182
|
+
};
|
|
183
|
+
export declare type AcknowledgementErrorPayload = {
|
|
184
|
+
type: AcknowledgementResponseTypes.ERROR;
|
|
185
|
+
error: InternalError;
|
|
186
|
+
};
|
|
187
|
+
export declare type AddStepAcknowledgementPayload = AddStepAcknowledgementSuccessPayload | AcknowledgementErrorPayload;
|
|
188
|
+
export declare type StepsPayload = {
|
|
189
|
+
version: number;
|
|
190
|
+
steps: StepJson[];
|
|
191
|
+
};
|
|
192
|
+
export declare type NamespaceStatus = {
|
|
193
|
+
isLocked: boolean;
|
|
194
|
+
timestamp: number;
|
|
195
|
+
waitTimeInMs?: number;
|
|
196
|
+
};
|
|
197
|
+
export declare type ChannelEvent = {
|
|
198
|
+
connected: {
|
|
199
|
+
sid: string;
|
|
200
|
+
initialized: boolean;
|
|
201
|
+
};
|
|
202
|
+
init: InitPayload;
|
|
203
|
+
restore: InitPayload;
|
|
204
|
+
reconnected: null;
|
|
205
|
+
'presence:joined': PresencePayload;
|
|
206
|
+
presence: PresencePayload;
|
|
207
|
+
'participant:left': PresencePayload;
|
|
208
|
+
'participant:telepointer': TelepointerPayload;
|
|
209
|
+
'participant:updated': PresencePayload;
|
|
210
|
+
'steps:commit': StepsPayload & {
|
|
211
|
+
userId: string;
|
|
212
|
+
};
|
|
213
|
+
'steps:added': StepsPayload;
|
|
214
|
+
'metadata:changed': Metadata;
|
|
215
|
+
error: InternalError;
|
|
216
|
+
disconnect: {
|
|
217
|
+
reason: string;
|
|
218
|
+
};
|
|
219
|
+
status: NamespaceStatus;
|
|
220
|
+
};
|
|
221
|
+
export interface CatchupResponse {
|
|
222
|
+
doc?: string;
|
|
223
|
+
version?: number;
|
|
224
|
+
stepMaps?: any[];
|
|
225
|
+
metadata?: Metadata;
|
|
226
|
+
}
|
|
227
|
+
export interface CatchupOptions {
|
|
228
|
+
getCurrentPmVersion: () => number;
|
|
229
|
+
fetchCatchup: (fromVersion: number) => Promise<CatchupResponse>;
|
|
230
|
+
filterQueue: (condition: (stepsPayload: StepsPayload) => boolean) => void;
|
|
231
|
+
getUnconfirmedSteps: () => readonly Step[] | undefined;
|
|
232
|
+
applyLocalSteps: (steps: Step[]) => void;
|
|
233
|
+
updateDocument: ({ doc, version, metadata, reserveCursor, }: CollabInitPayload) => void;
|
|
234
|
+
updateMetadata: (metadata: Metadata | undefined) => void;
|
|
235
|
+
}
|
|
236
|
+
export declare type ProductInformation = {
|
|
237
|
+
product: string;
|
|
238
|
+
subProduct?: string;
|
|
239
|
+
};
|
|
240
|
+
export interface CollabEventTelepointerData {
|
|
241
|
+
type: 'telepointer';
|
|
242
|
+
selection: CollabSendableSelection;
|
|
243
|
+
sessionId: string;
|
|
244
|
+
}
|
|
245
|
+
export interface CollabSendableSelection {
|
|
246
|
+
type: 'textSelection' | 'nodeSelection';
|
|
247
|
+
anchor?: number | string;
|
|
248
|
+
head?: number | string;
|
|
249
|
+
}
|
|
250
|
+
export interface CollabEditProvider<Events extends CollabEvents = CollabEvents> {
|
|
251
|
+
initialize(getState: () => any, createStep: (json: object) => Step): this;
|
|
252
|
+
setup(props: {
|
|
253
|
+
getState: () => EditorState;
|
|
254
|
+
onSyncUpError?: SyncUpErrorFunction;
|
|
255
|
+
}): this;
|
|
256
|
+
send(tr: Transaction, oldState: EditorState, newState: EditorState): void;
|
|
257
|
+
on(evt: keyof Events, handler: (...args: any) => void): this;
|
|
258
|
+
off(evt: keyof Events, handler: (...args: any) => void): this;
|
|
259
|
+
unsubscribeAll(evt: keyof Events): this;
|
|
260
|
+
sendMessage<K extends keyof Events>(data: {
|
|
261
|
+
type: K;
|
|
262
|
+
} & Events[K]): void;
|
|
263
|
+
getFinalAcknowledgedState(): Promise<ResolvedEditorState>;
|
|
264
|
+
}
|
|
265
|
+
export {};
|