@atlaskit/collab-provider 8.8.2 → 8.9.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/analytics/analytics-helper.js +21 -12
  3. package/dist/cjs/channel.js +5 -3
  4. package/dist/cjs/document/document-service.js +1 -1
  5. package/dist/cjs/errors/error-code-mapper.js +9 -2
  6. package/dist/cjs/namespace/namespace-service.js +77 -0
  7. package/dist/cjs/participants/participants-helper.js +2 -0
  8. package/dist/cjs/participants/participants-service.js +94 -30
  9. package/dist/cjs/provider/index.js +91 -173
  10. package/dist/cjs/version-wrapper.js +1 -1
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/analytics/analytics-helper.js +21 -12
  13. package/dist/es2019/channel.js +5 -3
  14. package/dist/es2019/document/document-service.js +1 -1
  15. package/dist/es2019/errors/error-code-mapper.js +9 -2
  16. package/dist/es2019/namespace/namespace-service.js +48 -0
  17. package/dist/es2019/participants/participants-helper.js +2 -0
  18. package/dist/es2019/participants/participants-service.js +88 -30
  19. package/dist/es2019/provider/index.js +82 -145
  20. package/dist/es2019/version-wrapper.js +1 -1
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/analytics/analytics-helper.js +21 -12
  23. package/dist/esm/channel.js +5 -3
  24. package/dist/esm/document/document-service.js +1 -1
  25. package/dist/esm/errors/error-code-mapper.js +9 -2
  26. package/dist/esm/namespace/namespace-service.js +69 -0
  27. package/dist/esm/participants/participants-helper.js +2 -0
  28. package/dist/esm/participants/participants-service.js +94 -30
  29. package/dist/esm/provider/index.js +91 -173
  30. package/dist/esm/version-wrapper.js +1 -1
  31. package/dist/esm/version.json +1 -1
  32. package/dist/types/namespace/namespace-service.d.ts +14 -0
  33. package/dist/types/participants/participants-helper.d.ts +2 -4
  34. package/dist/types/participants/participants-service.d.ts +40 -16
  35. package/dist/types/provider/index.d.ts +20 -36
  36. package/dist/types/types.d.ts +1 -1
  37. package/dist/types-ts4.5/analytics/analytics-helper.d.ts +11 -0
  38. package/dist/types-ts4.5/analytics/performance.d.ts +15 -0
  39. package/dist/types-ts4.5/analytics/ufo.d.ts +3 -0
  40. package/dist/types-ts4.5/channel.d.ts +47 -0
  41. package/dist/types-ts4.5/config.d.ts +5 -0
  42. package/dist/types-ts4.5/connectivity/network.d.ts +17 -0
  43. package/dist/types-ts4.5/connectivity/reconnect-helper.d.ts +8 -0
  44. package/dist/types-ts4.5/connectivity/singleton.d.ts +3 -0
  45. package/dist/types-ts4.5/disconnected-reason-mapper.d.ts +16 -0
  46. package/dist/types-ts4.5/document/catchup.d.ts +9 -0
  47. package/dist/types-ts4.5/document/document-service.d.ts +86 -0
  48. package/dist/types-ts4.5/document/step-queue-state.d.ts +16 -0
  49. package/dist/types-ts4.5/emitter.d.ts +19 -0
  50. package/dist/types-ts4.5/errors/error-code-mapper.d.ts +2 -0
  51. package/dist/types-ts4.5/errors/error-types.d.ts +443 -0
  52. package/dist/types-ts4.5/feature-flags/__test__/index.unit.d.ts +1 -0
  53. package/dist/types-ts4.5/feature-flags/index.d.ts +9 -0
  54. package/dist/types-ts4.5/feature-flags/types.d.ts +13 -0
  55. package/dist/types-ts4.5/helpers/const.d.ts +183 -0
  56. package/dist/types-ts4.5/helpers/utils.d.ts +5 -0
  57. package/dist/types-ts4.5/index.d.ts +4 -0
  58. package/dist/types-ts4.5/metadata/metadata-service.d.ts +25 -0
  59. package/dist/types-ts4.5/namespace/namespace-service.d.ts +14 -0
  60. package/dist/types-ts4.5/participants/participants-helper.d.ts +12 -0
  61. package/dist/types-ts4.5/participants/participants-service.d.ts +94 -0
  62. package/dist/types-ts4.5/participants/participants-state.d.ts +13 -0
  63. package/dist/types-ts4.5/participants/telepointers-helper.d.ts +4 -0
  64. package/dist/types-ts4.5/provider/commit-step.d.ts +25 -0
  65. package/dist/types-ts4.5/provider/index.d.ts +146 -0
  66. package/dist/types-ts4.5/socket-io-provider.d.ts +5 -0
  67. package/dist/types-ts4.5/types.d.ts +265 -0
  68. package/dist/types-ts4.5/version-wrapper.d.ts +3 -0
  69. package/package.json +3 -3
  70. package/report.api.md +4 -2
@@ -0,0 +1,14 @@
1
+ import { NamespaceStatus } from '../types';
2
+ /**
3
+ * Allows us to keep track of any namespace changes from the server.
4
+ * @param isNamespaceLocked - whether the namespace is locked or not, defaults to false
5
+ */
6
+ export declare class NamespaceService {
7
+ private isNamespaceLocked;
8
+ constructor(isNamespaceLocked?: boolean);
9
+ getIsNamespaceLocked: () => boolean;
10
+ /**
11
+ * ESS-2916 namespace status event- lock/unlock
12
+ */
13
+ onNamespaceStatusChanged: ({ isLocked, waitTimeInMs, timestamp, }: NamespaceStatus) => Promise<void>;
14
+ }
@@ -0,0 +1,12 @@
1
+ import type { CollabParticipant } from '@atlaskit/editor-common/collab';
2
+ import type { PresencePayload } from '../types';
3
+ export declare const PARTICIPANT_UPDATE_INTERVAL: number;
4
+ export type ProviderParticipant = CollabParticipant & {
5
+ userId: string;
6
+ clientId: number | string;
7
+ };
8
+ export type ParticipantsMap = Map<string, ProviderParticipant>;
9
+ export type GetUserType = ((userId: string) => Promise<Pick<ProviderParticipant, 'name' | 'avatar' | 'userId'>>) | undefined;
10
+ export declare const createParticipantFromPayload: (payload: PresencePayload & {
11
+ userId: string;
12
+ }, getUser: GetUserType) => Promise<ProviderParticipant>;
@@ -0,0 +1,94 @@
1
+ import type { CollabEventPresenceData, CollabEventDisconnectedData } from '@atlaskit/editor-common/collab';
2
+ import AnalyticsHelper from '../analytics/analytics-helper';
3
+ import type { ChannelEvent, CollabEventTelepointerData, PresencePayload, StepJson, TelepointerPayload } from '../types';
4
+ import { GetUserType } from './participants-helper';
5
+ import { ParticipantsState } from './participants-state';
6
+ /**
7
+ * This service is responsible for handling presence and participant events, as well as sending them on to the editor or NCS.
8
+ * @param analyticsHelper Analytics helper instance
9
+ * @param participantsState Starts with no participants, only add this when testing
10
+ * @param emit Emit from the Provider class (to the editor)
11
+ * @param getUser Callback to get user data from the editor
12
+ * @param channelBroadcast Broadcast from the Channel class (to NCS)
13
+ * @param sendPresenceJoined Callback to Channel class
14
+ */
15
+ export declare class ParticipantsService {
16
+ private analyticsHelper;
17
+ private participantsState;
18
+ private emit;
19
+ private getUser;
20
+ private channelBroadcast;
21
+ private sendPresenceJoined;
22
+ private participantUpdateTimeout;
23
+ private presenceUpdateTimeout;
24
+ constructor(analyticsHelper: AnalyticsHelper | undefined, participantsState: ParticipantsState, emit: (evt: 'presence' | 'telepointer' | 'disconnected', data: CollabEventPresenceData | CollabEventTelepointerData | CollabEventDisconnectedData) => void, getUser: GetUserType, channelBroadcast: <K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], 'timestamp'>, callback?: Function) => void, sendPresenceJoined: () => void);
25
+ /**
26
+ * Carries out 3 things: 1) enriches the participant with user data, 2) updates the participantsState, 3) emits the presence event
27
+ * @param payload Payload from incoming socket event
28
+ * @returns Awaitable Promise, due to getUser
29
+ */
30
+ onParticipantUpdated: (payload: PresencePayload) => Promise<void>;
31
+ /**
32
+ * Called when a participant leaves the session.
33
+ * We emit the `presence` event to update the active avatars in the editor.
34
+ */
35
+ onParticipantLeft: ({ sessionId }: PresencePayload) => void;
36
+ disconnect: (reason: string, sessionId: string | undefined) => void;
37
+ /**
38
+ * Updates when users were last active
39
+ * @param userIds Users in most recent steps
40
+ */
41
+ updateLastActive: (userIds?: string[]) => void;
42
+ /**
43
+ * Called on receiving steps, emits each step's telepointer
44
+ * @param steps Steps to extract telepointers from
45
+ */
46
+ emitTelepointersFromSteps(steps: StepJson[]): void;
47
+ /**
48
+ * Called when we receive a telepointer update from another
49
+ * participant.
50
+ */
51
+ onParticipantTelepointer: (payload: TelepointerPayload, thisSessionId: string | undefined) => void;
52
+ /**
53
+ * Every 5 minutes (PARTICIPANT_UPDATE_INTERVAL), removes inactive participants and emits the update to other participants.
54
+ * Needs to be kicked off in the Provider.
55
+ * @param sessionId SessionId from provider's connection
56
+ */
57
+ startInactiveRemover: (sessionId: string | undefined) => void;
58
+ /**
59
+ * Keep list of participants up to date. Filter out inactive users etc.
60
+ */
61
+ private filterInactive;
62
+ /**
63
+ * Wrapper function to emit with error handling and analytics
64
+ * @param data Data to emit
65
+ * @param emit Emit function from Provider
66
+ */
67
+ private emitPresence;
68
+ /**
69
+ * Wrapper function to emit with error handling and analytics
70
+ * @param data Data to emit
71
+ * @param emit Emit function from Provider
72
+ */
73
+ private emitTelepointer;
74
+ /**
75
+ * Used when the provider is disconnected or destroyed to prevent perpetual timers from continuously running
76
+ */
77
+ clearTimers: () => void;
78
+ private sendPresence;
79
+ /**
80
+ * Called when a participant joins the session.
81
+ *
82
+ * We keep track of participants internally, and emit the `presence` event to update
83
+ * the active avatars in the editor.
84
+ * This method will be triggered from backend to notify all participants to exchange presence
85
+ */
86
+ onPresenceJoined: (payload: PresencePayload) => void;
87
+ /**
88
+ * Called when the current user joins the session.
89
+ *
90
+ * This will send both a 'presence' event and a 'participant:updated' event.
91
+ * This updates both the avatars and the participants list.
92
+ */
93
+ onPresence: (payload: PresencePayload) => void;
94
+ }
@@ -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) => 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) => 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,146 @@
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
+ 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 isPreinitializing;
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 namespaceService;
26
+ /**
27
+ * Wrapper for this.emit, it binds scope for callbacks and waits for initialising of the editor before emitting events.
28
+ * Waiting for the collab provider to become connected to the editor ensures the editor doesn't miss any events.
29
+ * @param evt - Event name to emit to subscribers
30
+ * @param data - Event data to emit to subscribers
31
+ */
32
+ private readonly emitCallback;
33
+ private getStatePromise;
34
+ getStatePromiseResolve: (value: void | PromiseLike<void>) => void;
35
+ constructor(config: Config);
36
+ private initializeChannel;
37
+ /**
38
+ * Initialisation logic, called by Jira with a dummy getState function, deprecated in favour of the setup method which allows more configuration
39
+ * @param {Function} getState Function that returns the editor state, used to retrieve collab-edit properties and to interact with prosemirror-collab
40
+ * @throws {ProviderInitialisationError} Something went wrong during provider initialisation
41
+ * @deprecated Use setup method instead
42
+ */
43
+ initialize(getState: () => EditorState): this;
44
+ /**
45
+ * Initialisation logic, called by the editor in the collab-edit plugin.
46
+ *
47
+ * When getState is nullish and a initialDraft is provided the collab provider is in a state of pre-initialization,
48
+ * the provider starts to enable the connection to NCS, but the provider will not emit any events until this function
49
+ * is called again with a getState function, indicating that the editor is loaded and ready to receive the emits.
50
+ *
51
+ * @param {Object} options ...
52
+ * @param {Function} options.getState Function that returns the editor state, used to retrieve collab-edit properties and to interact with prosemirror-collab
53
+ * @param {SyncUpErrorFunction} options.onSyncUpError (Optional) Function that gets called when the sync of steps fails after retrying 30 times, used by Editor to log to analytics
54
+ * @throws {ProviderInitialisationError} Something went wrong during provider initialisation
55
+ */
56
+ setup({ getState, onSyncUpError, }: {
57
+ getState?: () => EditorState;
58
+ onSyncUpError?: SyncUpErrorFunction;
59
+ }): this;
60
+ private checkForCookies;
61
+ /**
62
+ * Send steps from transaction to NCS (and as a consequence to other participants), called from the collab-edit plugin in the editor
63
+ * @param {Transaction} _tr Deprecated, included to keep API consistent with Synchrony provider
64
+ * @param {EditorState} _oldState Deprecated, included to keep API consistent with Synchrony provider
65
+ * @param {EditorState} newState The editor state after applying the transaction
66
+ * @throws {SendTransactionError} Something went wrong while sending the steps for this transaction
67
+ */
68
+ send(_tr: Transaction | null, _oldState: EditorState | null, newState: EditorState): void;
69
+ /**
70
+ * @param {InternalError} error The error to handle
71
+ */
72
+ private onErrorHandled;
73
+ /**
74
+ * 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.
75
+ * Silently fails if an error occurs, since Presence isn't a critical functionality and self-restores over time.
76
+ * @param {CollabEventTelepointerData} data Data you want to send to NCS / the other participants
77
+ * @param {string} data.type Can only be 'telepointer' for now, we don't support anything else yet
78
+ * @param {CollabSendableSelection} data.selection Object representing the selected element
79
+ * @param {string} data.sessionId Identifier identifying the session
80
+ */
81
+ sendMessage(data: CollabEventTelepointerData): void;
82
+ private onDisconnected;
83
+ /**
84
+ * "Destroy" the provider, disconnect it's connection to the back-end service and unsubscribe all event listeners on the provider.
85
+ * Used by Jira products (JWM, JPD) to disable the provider
86
+ * @throws {DestroyError} Something went wrong while shutting down the collab provider
87
+ */
88
+ destroy(): this;
89
+ /**
90
+ * Disconnect the provider, disconnect it's connection to the back-end service and unsubscribe all event listeners on the provider.
91
+ * Used by Confluence to disable the provider when a user doesn't have access to a resource.
92
+ * @deprecated use destroy instead, it does the same thing
93
+ * @throws {DestroyError} Something went wrong while shutting down the collab provider
94
+ */
95
+ disconnect(): this;
96
+ /**
97
+ * 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.
98
+ * @deprecated use destroy instead, it does the same thing
99
+ * @throws {DestroyError} Something went wrong while shutting down the collab provider
100
+ */
101
+ unsubscribeAll(): this;
102
+ /**
103
+ * Update the title of the document in the collab provider and optionally broadcast it to other participants and NCS
104
+ * @deprecated use setMetadata instead, it does the same thing
105
+ * @param {string} title Title you want to set on the document
106
+ * @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)
107
+ * @throws {SetTitleError} Something went wrong while setting the title
108
+ */
109
+ setTitle(title: string, broadcast?: boolean): void;
110
+ /**
111
+ * Set editor width, not used any more
112
+ * @deprecated use setMetadata instead, it does the same thing
113
+ * @param {string} editorWidth string? indicating the editor width
114
+ * @param {boolean} broadcast (Optional) Flag indicating whether you want to broadcast the editor width change
115
+ * @throws {SetEditorWidthError} Something went wrong while setting the editor width
116
+ */
117
+ setEditorWidth(editorWidth: string, broadcast?: boolean): void;
118
+ /**
119
+ * Set the editor width and title and distribute it to all participants. Used by Confluence
120
+ * @param {Metadata} metadata The metadata you want to update
121
+ * @throws {ExampleError} Something went wrong while setting the metadata
122
+ */
123
+ setMetadata(metadata: Metadata): void;
124
+ /**
125
+ * Returns the documents metadata
126
+ */
127
+ getMetadata: () => Metadata;
128
+ /**
129
+ * Return the ADF version of the current draft document, together with it's title and the current step version.
130
+ * 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.
131
+ * @throws {GetCurrentStateError} Something went wrong while returning the current state
132
+ */
133
+ getCurrentState: () => Promise<ResolvedEditorState>;
134
+ /**
135
+ * Return the final acknowledged (by NCS) ADF version of the current draft document, together with it's title and the current step version.
136
+ * Used when returning the document to Confluence on publish.
137
+ * @throws {GetFinalAcknowledgedStateError} Something went wrong while returning the acknowledged state
138
+ */
139
+ getFinalAcknowledgedState: () => Promise<ResolvedEditorState>;
140
+ getUnconfirmedSteps: () => readonly ProseMirrorStep[] | undefined;
141
+ /**
142
+ * Used when the provider is disconnected or destroyed to prevent perpetual timers from continuously running
143
+ */
144
+ private clearTimers;
145
+ }
146
+ 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 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 type LifecycleEvents = 'save' | 'restore';
68
+ export type EventHandler = () => void;
69
+ export interface Lifecycle {
70
+ on(event: LifecycleEvents, handler: EventHandler): void;
71
+ }
72
+ export type CollabConnectedPayload = CollabEventConnectionData;
73
+ export type CollabConnectingPayload = CollabEventConnectingData;
74
+ export interface CollabDisconnectedPayload {
75
+ reason: DisconnectReason;
76
+ sid: string;
77
+ }
78
+ /**
79
+ * @deprecated Use ProviderError type instead
80
+ */
81
+ export 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 type CollabTelepointerPayload = CollabEventTelepointerData;
94
+ export type CollabPresencePayload = CollabEventPresenceData;
95
+ export type CollabMetadataPayload = Metadata;
96
+ export 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 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 type BroadcastIncomingPayload = {
128
+ sessionId?: string;
129
+ timestamp?: number;
130
+ data: PresencePayload | TelepointerPayload | StepsPayload | any;
131
+ };
132
+ export type PresencePayload = {
133
+ sessionId: string;
134
+ userId: string | undefined;
135
+ clientId: number | string;
136
+ timestamp: number;
137
+ };
138
+ export type TelepointerPayload = PresencePayload & {
139
+ selection: CollabSendableSelection;
140
+ };
141
+ type MarkJson = {
142
+ type: string;
143
+ attrs: {
144
+ [key: string]: any;
145
+ };
146
+ };
147
+ type NodeJson = {
148
+ type: string;
149
+ attrs: {
150
+ [key: string]: any;
151
+ };
152
+ content: NodeJson[];
153
+ marks: MarkJson[];
154
+ text?: string;
155
+ };
156
+ type SliceJson = {
157
+ content: NodeJson[];
158
+ openStart: number;
159
+ openEnd: number;
160
+ };
161
+ export 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 type AcknowledgementSuccessPayload = {
176
+ type: AcknowledgementResponseTypes.SUCCESS;
177
+ };
178
+ export type AcknowledgementPayload = AcknowledgementSuccessPayload | AcknowledgementErrorPayload;
179
+ export type AddStepAcknowledgementSuccessPayload = {
180
+ type: AcknowledgementResponseTypes.SUCCESS;
181
+ version: number;
182
+ };
183
+ export type AcknowledgementErrorPayload = {
184
+ type: AcknowledgementResponseTypes.ERROR;
185
+ error: InternalError;
186
+ };
187
+ export type AddStepAcknowledgementPayload = AddStepAcknowledgementSuccessPayload | AcknowledgementErrorPayload;
188
+ export type StepsPayload = {
189
+ version: number;
190
+ steps: StepJson[];
191
+ };
192
+ export type NamespaceStatus = {
193
+ isLocked: boolean;
194
+ timestamp: number;
195
+ waitTimeInMs?: number;
196
+ };
197
+ export 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 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 {};
@@ -0,0 +1,3 @@
1
+ export declare const name: string;
2
+ export declare const version: string;
3
+ export declare const nextMajorVersion: () => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "8.8.2",
3
+ "version": "8.9.0",
4
4
  "description": "A provider for collaborative editing.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "@atlaskit/analytics-gas-types": "^5.1.0",
38
38
  "@atlaskit/analytics-listeners": "^8.7.0",
39
- "@atlaskit/editor-common": "^74.0.0",
39
+ "@atlaskit/editor-common": "^74.1.0",
40
40
  "@atlaskit/editor-json-transformer": "^8.9.0",
41
41
  "@atlaskit/prosemirror-collab": "^0.2.0",
42
42
  "@atlaskit/ufo": "^0.2.0",
@@ -68,7 +68,7 @@
68
68
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
69
69
  "@types/prosemirror-model": "^1.11.0",
70
70
  "@types/prosemirror-state": "^1.2.0",
71
- "prosemirror-model": "1.14.3",
71
+ "prosemirror-model": "1.16.0",
72
72
  "prosemirror-state": "1.3.4",
73
73
  "typescript": "~4.9.5"
74
74
  },
package/report.api.md CHANGED
@@ -85,7 +85,7 @@ export interface CollabEditProvider<
85
85
  ): void;
86
86
  // (undocumented)
87
87
  setup(props: {
88
- getState: () => EditorState;
88
+ getState?: () => EditorState;
89
89
  onSyncUpError?: SyncUpErrorFunction;
90
90
  }): this;
91
91
  // (undocumented)
@@ -386,6 +386,8 @@ export class Provider extends Emitter<CollabEvents> implements BaseEvents {
386
386
  getFinalAcknowledgedState: () => Promise<ResolvedEditorState>;
387
387
  getMetadata: () => Metadata_2;
388
388
  // (undocumented)
389
+ getStatePromiseResolve: (value: PromiseLike<void> | void) => void;
390
+ // (undocumented)
389
391
  getUnconfirmedSteps: () => readonly Step[] | undefined;
390
392
  // @deprecated
391
393
  initialize(getState: () => EditorState): this;
@@ -404,7 +406,7 @@ export class Provider extends Emitter<CollabEvents> implements BaseEvents {
404
406
  getState,
405
407
  onSyncUpError,
406
408
  }: {
407
- getState: () => EditorState;
409
+ getState?: () => EditorState;
408
410
  onSyncUpError?: SyncUpErrorFunction;
409
411
  }): this;
410
412
  // @deprecated