@atlaskit/collab-provider 8.2.0 → 8.4.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 (72) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/cjs/analytics/index.js +67 -9
  3. package/dist/cjs/analytics/performance.js +46 -35
  4. package/dist/cjs/analytics/ufo.js +33 -0
  5. package/dist/cjs/channel.js +307 -162
  6. package/dist/cjs/connectivity/network.js +53 -0
  7. package/dist/cjs/connectivity/reconnect-helper.js +48 -0
  8. package/dist/cjs/connectivity/singleton.js +15 -0
  9. package/dist/cjs/disconnected-reason-mapper.js +19 -2
  10. package/dist/cjs/{error-code-mapper.js → errors/error-code-mapper.js} +17 -2
  11. package/dist/cjs/errors/error-types.js +43 -0
  12. package/dist/cjs/helpers/const.js +4 -11
  13. package/dist/cjs/provider/catchup.js +8 -12
  14. package/dist/cjs/provider/commit-step.js +70 -0
  15. package/dist/cjs/provider/index.js +503 -566
  16. package/dist/cjs/provider/telepointers.js +78 -0
  17. package/dist/cjs/version-wrapper.js +1 -1
  18. package/dist/cjs/version.json +1 -1
  19. package/dist/es2019/analytics/index.js +58 -8
  20. package/dist/es2019/analytics/performance.js +47 -35
  21. package/dist/es2019/analytics/ufo.js +22 -0
  22. package/dist/es2019/channel.js +192 -93
  23. package/dist/es2019/connectivity/network.js +34 -0
  24. package/dist/es2019/connectivity/reconnect-helper.js +29 -0
  25. package/dist/es2019/connectivity/singleton.js +7 -0
  26. package/dist/es2019/disconnected-reason-mapper.js +17 -1
  27. package/dist/es2019/{error-code-mapper.js → errors/error-code-mapper.js} +17 -2
  28. package/dist/es2019/errors/error-types.js +13 -0
  29. package/dist/es2019/helpers/const.js +3 -8
  30. package/dist/es2019/provider/catchup.js +5 -12
  31. package/dist/es2019/provider/commit-step.js +57 -0
  32. package/dist/es2019/provider/index.js +428 -515
  33. package/dist/es2019/provider/telepointers.js +65 -0
  34. package/dist/es2019/version-wrapper.js +1 -1
  35. package/dist/es2019/version.json +1 -1
  36. package/dist/esm/analytics/index.js +68 -9
  37. package/dist/esm/analytics/performance.js +47 -35
  38. package/dist/esm/analytics/ufo.js +25 -0
  39. package/dist/esm/channel.js +308 -165
  40. package/dist/esm/connectivity/network.js +45 -0
  41. package/dist/esm/connectivity/reconnect-helper.js +42 -0
  42. package/dist/esm/connectivity/singleton.js +7 -0
  43. package/dist/esm/disconnected-reason-mapper.js +17 -1
  44. package/dist/esm/{error-code-mapper.js → errors/error-code-mapper.js} +17 -2
  45. package/dist/esm/errors/error-types.js +34 -0
  46. package/dist/esm/helpers/const.js +3 -8
  47. package/dist/esm/provider/catchup.js +8 -12
  48. package/dist/esm/provider/commit-step.js +62 -0
  49. package/dist/esm/provider/index.js +504 -567
  50. package/dist/esm/provider/telepointers.js +69 -0
  51. package/dist/esm/version-wrapper.js +1 -1
  52. package/dist/esm/version.json +1 -1
  53. package/dist/types/analytics/index.d.ts +8 -2
  54. package/dist/types/analytics/performance.d.ts +6 -5
  55. package/dist/types/analytics/ufo.d.ts +3 -0
  56. package/dist/types/channel.d.ts +16 -5
  57. package/dist/types/connectivity/network.d.ts +17 -0
  58. package/dist/types/connectivity/reconnect-helper.d.ts +8 -0
  59. package/dist/types/connectivity/singleton.d.ts +3 -0
  60. package/dist/types/disconnected-reason-mapper.d.ts +1 -0
  61. package/dist/types/{error-code-mapper.d.ts → errors/error-code-mapper.d.ts} +6 -2
  62. package/dist/types/errors/error-types.d.ts +8 -0
  63. package/dist/types/helpers/const.d.ts +133 -26
  64. package/dist/types/provider/commit-step.d.ts +14 -0
  65. package/dist/types/provider/index.d.ts +24 -6
  66. package/dist/types/provider/telepointers.d.ts +5 -0
  67. package/dist/types/socket-io-provider.d.ts +3 -2
  68. package/dist/types/types.d.ts +44 -12
  69. package/package.json +5 -6
  70. package/report.api.md +49 -3
  71. package/.vscode/settings.json +0 -3
  72. package/error-code-mapper/package.json +0 -15
@@ -0,0 +1,69 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import { createLogger } from '../helpers/utils';
4
+ import { ExperiencePerformanceTypes, ExperienceTypes, UFOExperience } from '@atlaskit/ufo';
5
+ import { AcknowledgementResponseTypes } from '../types';
6
+ var logger = createLogger('Telepointer', 'green');
7
+ export var telepointersFromStep = function telepointersFromStep(participants, step) {
8
+ var _Array$from$filter = Array.from(participants.values()).filter(function (p) {
9
+ return p.clientId === step.clientId;
10
+ }),
11
+ _Array$from$filter2 = _slicedToArray(_Array$from$filter, 1),
12
+ participant = _Array$from$filter2[0];
13
+ if (participant) {
14
+ var _node$text;
15
+ var stepType = step.stepType,
16
+ to = step.to,
17
+ from = step.from,
18
+ _step$slice = step.slice,
19
+ slice = _step$slice === void 0 ? {
20
+ content: []
21
+ } : _step$slice;
22
+ var _slice$content = _slicedToArray(slice.content, 1),
23
+ node = _slice$content[0];
24
+ if (to && from && stepType === 'replace' && to === from && slice.content.length === 1 && (node === null || node === void 0 ? void 0 : node.type) === 'text' && (node === null || node === void 0 ? void 0 : (_node$text = node.text) === null || _node$text === void 0 ? void 0 : _node$text.length) === 1) {
25
+ return {
26
+ sessionId: participant.sessionId,
27
+ selection: {
28
+ type: 'textSelection',
29
+ anchor: from + 1,
30
+ head: to + 1
31
+ },
32
+ type: 'telepointer'
33
+ };
34
+ }
35
+ }
36
+ };
37
+ export var telepointerCallback = function telepointerCallback(documentAri) {
38
+ var telepointerExperience = new UFOExperience('collab-provider.telepointer', {
39
+ type: ExperienceTypes.Operation,
40
+ performanceType: ExperiencePerformanceTypes.Custom,
41
+ performanceConfig: {
42
+ histogram: _defineProperty({}, ExperiencePerformanceTypes.Custom, {
43
+ duration: '250_500_1000_1500_2000_3000_4000'
44
+ })
45
+ }
46
+ });
47
+ telepointerExperience.addMetadata({
48
+ documentAri: documentAri
49
+ });
50
+ telepointerExperience.start();
51
+ return function (response) {
52
+ if (response.type === AcknowledgementResponseTypes.SUCCESS) {
53
+ telepointerExperience.success();
54
+ } else if (response.type === AcknowledgementResponseTypes.ERROR) {
55
+ var errorMessage = response.error;
56
+ telepointerExperience.addMetadata({
57
+ error: errorMessage
58
+ });
59
+ logger('Error from collab service with telepointer broadcast', errorMessage);
60
+ telepointerExperience.failure();
61
+ } else {
62
+ logger('Invalid ACK from collab service with telepointer broadcast');
63
+ telepointerExperience.addMetadata({
64
+ error: 'Invalid ACK from collab service with telepointer broadcast'
65
+ });
66
+ telepointerExperience.failure();
67
+ }
68
+ };
69
+ };
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/collab-provider";
2
- export var version = "8.2.0";
2
+ export var version = "8.4.0";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "8.2.0",
3
+ "version": "8.4.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,3 +1,9 @@
1
1
  import type { AnalyticsWebClient } from '@atlaskit/analytics-listeners';
2
- import { AnalyticsEvent } from '../helpers/const';
3
- export declare const triggerAnalyticsEvent: (analyticsEvent: AnalyticsEvent, analyticsClient?: AnalyticsWebClient | undefined) => void;
2
+ import type { ActionAnalyticsEvent, EVENT_STATUS } from '../helpers/const';
3
+ export default class AnalyticsHelper {
4
+ analyticsClient: AnalyticsWebClient | undefined;
5
+ documentAri: string;
6
+ constructor(documentAri: string, analyticsClient?: AnalyticsWebClient);
7
+ sendErrorEvent(error: unknown, errorMessage: string): void;
8
+ sendActionEvent(action: ActionAnalyticsEvent['eventAction'], status: EVENT_STATUS, attributes?: Omit<ActionAnalyticsEvent['attributes'], 'documentAri' | 'eventStatus'>): void;
9
+ }
@@ -1,12 +1,13 @@
1
+ import AnalyticsHelper from '.';
1
2
  export declare enum MEASURE_NAME {
2
3
  SOCKET_CONNECT = "socketConnect",
3
4
  DOCUMENT_INIT = "documentInit",
4
- CONVERT_PM_TO_ADF = "convertPMToADF",
5
- COMMIT_UNCONFIRMED_STEPS = "commitUnconfirmedSteps"
5
+ COMMIT_UNCONFIRMED_STEPS = "commitUnconfirmedSteps",
6
+ PUBLISH_PAGE = "publishPage",
7
+ GET_CURRENT_STATE = "getCurrentState"
6
8
  }
7
- export declare function startMeasure(measureName: MEASURE_NAME): void;
8
- export declare function stopMeasure(measureName: MEASURE_NAME, onMeasureComplete?: (duration: number, startTime: number) => void): {
9
+ export declare function startMeasure(measureName: MEASURE_NAME, analyticsHelper: AnalyticsHelper | undefined): void;
10
+ export declare function stopMeasure(measureName: MEASURE_NAME, analyticsHelper: AnalyticsHelper | undefined, onMeasureComplete?: (duration: number, startTime: number) => void): {
9
11
  duration: number;
10
12
  startTime: number;
11
13
  } | undefined;
12
- export declare function clearMeasure(measureName: string): void;
@@ -0,0 +1,3 @@
1
+ import { UFOExperience } from '@atlaskit/ufo';
2
+ import AnalyticsHelper from '.';
3
+ export declare const createDocInitExp: (analyticsHelper: AnalyticsHelper | undefined) => UFOExperience | undefined;
@@ -1,21 +1,31 @@
1
1
  import { Emitter } from './emitter';
2
- import type { Config, Socket, ChannelEvent, CatchupResponse, Metadata } from './types';
2
+ import type { Config, ChannelEvent, CatchupResponse, Metadata } from './types';
3
+ import type { Socket } from 'socket.io-client';
4
+ import AnalyticsHelper from './analytics';
3
5
  export declare class Channel extends Emitter<ChannelEvent> {
4
6
  private connected;
5
7
  private config;
6
8
  private socket;
9
+ private reconnectHelper?;
7
10
  private initialized;
8
- private analyticsClient?;
9
- private initExperience;
10
- constructor(config: Config);
11
+ private analyticsHelper?;
12
+ private initExperience?;
13
+ private token?;
14
+ private network;
15
+ constructor(config: Config, analyticsHelper: AnalyticsHelper);
11
16
  getInitialized: () => boolean;
12
17
  getConnected: () => boolean;
13
- getSocket: () => Socket | null;
18
+ getSocket: () => Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap> | null;
19
+ getToken: () => string | undefined;
20
+ private setToken;
21
+ private unsetToken;
14
22
  /**
15
23
  * Connect to collab service using websockets
16
24
  */
17
25
  connect(): void;
26
+ private handlePermissionInvalidateToken;
18
27
  private onConnectError;
28
+ private onReconnectError;
19
29
  private onConnect;
20
30
  private onReceiveData;
21
31
  fetchCatchup(fromVersion: number): Promise<CatchupResponse>;
@@ -25,5 +35,6 @@ export declare class Channel extends Emitter<ChannelEvent> {
25
35
  broadcast<K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], 'timestamp'>, callback?: Function): void;
26
36
  sendMetadata(metadata: Metadata): void;
27
37
  sendPresenceJoined(): void;
38
+ onOnlineHandler: () => void;
28
39
  disconnect(): void;
29
40
  }
@@ -0,0 +1,17 @@
1
+ export declare enum NetworkStatus {
2
+ ONLINE = "ONLINE",
3
+ OFFLINE = "OFFLINE"
4
+ }
5
+ export interface NetworkProps {
6
+ initialStatus?: NetworkStatus;
7
+ onlineCallback?: () => void;
8
+ }
9
+ export default class Network {
10
+ status?: NetworkStatus;
11
+ onlineCallback?: () => void;
12
+ constructor(props?: NetworkProps);
13
+ private offlineHandler;
14
+ private onlineHandler;
15
+ getStatus(): NetworkStatus | null;
16
+ destroy(): void;
17
+ }
@@ -0,0 +1,8 @@
1
+ export default class ReconnectHelper {
2
+ failedReconnectCount: number;
3
+ constructor();
4
+ private onlineHandler;
5
+ countReconnectError(): void;
6
+ isLikelyNetworkIssue(): boolean;
7
+ destroy(): void;
8
+ }
@@ -0,0 +1,3 @@
1
+ import Network from './network';
2
+ declare const network: Network;
3
+ export { network };
@@ -13,3 +13,4 @@ export declare enum DisconnectReason {
13
13
  SOCKET_TIMEOUT = "SOCKET_TIMEOUT",
14
14
  UNKNOWN_DISCONNECT = "UNKNOWN_DISCONNECT"
15
15
  }
16
+ export declare const disconnectedReasonMapper: (reason: string) => DisconnectReason;
@@ -1,4 +1,4 @@
1
- import type { CollabErrorPayload, ErrorPayload } from './types';
1
+ import type { CollabErrorPayload, ErrorPayload } from '../types';
2
2
  export declare const ErrorCodeMapper: {
3
3
  noPermissionError: {
4
4
  code: string;
@@ -24,9 +24,13 @@ export declare const ErrorCodeMapper: {
24
24
  code: string;
25
25
  message: string;
26
26
  };
27
+ restoreError: {
28
+ code: string;
29
+ message: string;
30
+ };
27
31
  internalError: {
28
32
  code: string;
29
33
  message: string;
30
34
  };
31
35
  };
32
- export declare const errorCodeMapper: (error: ErrorPayload) => CollabErrorPayload;
36
+ export declare const errorCodeMapper: (error: ErrorPayload) => CollabErrorPayload | undefined;
@@ -0,0 +1,8 @@
1
+ export declare class NotConnectedError extends Error {
2
+ name: string;
3
+ constructor(message: string);
4
+ }
5
+ export declare class NotInitializedError extends Error {
6
+ name: string;
7
+ constructor(message: string);
8
+ }
@@ -1,20 +1,16 @@
1
- import { CollabErrorPayload, ErrorPayload } from '../types';
2
- export declare const EVENT_SUBJECT = "collab";
3
- export declare enum COLLAB_SERVICE {
4
- NCS = "ncs",
5
- SYNCHRONY = "synchrony"
6
- }
1
+ import type { CollabErrorPayload } from '../types';
7
2
  export declare enum EVENT_ACTION {
8
3
  CONNECTION = "connection",
9
4
  CATCHUP = "catchup",
10
5
  DOCUMENT_INIT = "documentInit",
11
6
  ADD_STEPS = "addSteps",
12
- CONVERT_PM_TO_ADF = "convertPMToADF",
13
7
  UPDATE_PARTICIPANTS = "updateParticipants",
14
8
  COMMIT_UNCONFIRMED_STEPS = "commitUnconfirmedSteps",
15
9
  REINITIALISE_DOCUMENT = "reinitialiseDocument",
16
- INIT_PROVIDER = "initProvider",
17
- ERROR = "error"
10
+ ERROR = "error",
11
+ PUBLISH_PAGE = "publishPage",
12
+ GET_CURRENT_STATE = "getCurrentState",
13
+ INVALIDATE_TOKEN = "invalidateToken"
18
14
  }
19
15
  export declare enum EVENT_STATUS {
20
16
  SUCCESS = "SUCCESS",
@@ -25,12 +21,32 @@ export declare enum ADD_STEPS_TYPE {
25
21
  REJECTED = "REJECTED",
26
22
  ERROR = "ERROR"
27
23
  }
24
+ export declare type ErrorAnalyticsEvent = {
25
+ eventAction: EVENT_ACTION.ERROR;
26
+ attributes: {
27
+ errorMessage: string;
28
+ errorName?: string;
29
+ documentAri?: string;
30
+ mappedError?: CollabErrorPayload;
31
+ };
32
+ nonPrivacySafeAttributes: {
33
+ error: unknown;
34
+ };
35
+ };
36
+ declare type InvalidateTokenAnalyticsEvent = {
37
+ eventAction: EVENT_ACTION.INVALIDATE_TOKEN;
38
+ attributes: {
39
+ eventStatus: EVENT_STATUS.SUCCESS;
40
+ reason?: string;
41
+ usedCachedToken?: boolean;
42
+ };
43
+ };
28
44
  declare type AddStepsSuccessAnalyticsEvent = {
29
45
  eventAction: EVENT_ACTION.ADD_STEPS;
30
46
  attributes: {
47
+ documentAri: string;
31
48
  eventStatus: EVENT_STATUS.SUCCESS;
32
49
  type: ADD_STEPS_TYPE.ACCEPTED;
33
- documentAri: string;
34
50
  latency?: number;
35
51
  stepType?: {
36
52
  [key: string]: number;
@@ -40,38 +56,129 @@ declare type AddStepsSuccessAnalyticsEvent = {
40
56
  declare type AddStepsFailureAnalyticsEvent = {
41
57
  eventAction: EVENT_ACTION.ADD_STEPS;
42
58
  attributes: {
59
+ documentAri: string;
43
60
  eventStatus: EVENT_STATUS.FAILURE;
44
61
  type: ADD_STEPS_TYPE.REJECTED | ADD_STEPS_TYPE.ERROR;
62
+ latency?: number;
63
+ };
64
+ };
65
+ declare type ReInitDocFailAnalyticsEvent = {
66
+ eventAction: EVENT_ACTION.REINITIALISE_DOCUMENT;
67
+ attributes: {
45
68
  documentAri: string;
69
+ eventStatus: EVENT_STATUS.FAILURE;
70
+ numUnconfirmedSteps: number;
71
+ };
72
+ };
73
+ declare type ReInitDocSuccessAnalyticsEvent = {
74
+ eventAction: EVENT_ACTION.REINITIALISE_DOCUMENT;
75
+ attributes: {
76
+ documentAri: string;
77
+ eventStatus: EVENT_STATUS.SUCCESS;
78
+ numUnconfirmedSteps: number;
79
+ };
80
+ };
81
+ declare type ConnectionSuccessAnalyticsEvent = {
82
+ eventAction: EVENT_ACTION.CONNECTION;
83
+ attributes: {
84
+ documentAri: string;
85
+ eventStatus: EVENT_STATUS.SUCCESS;
46
86
  latency?: number;
47
- error: ErrorPayload;
48
87
  };
49
88
  };
50
- declare type ErrorAnalyticsEvent = {
51
- eventAction: EVENT_ACTION.ERROR;
89
+ declare type ConnectionFailureAnalyticsEvent = {
90
+ eventAction: EVENT_ACTION.CONNECTION;
52
91
  attributes: {
53
- attemptedAction?: EVENT_ACTION;
54
92
  documentAri: string;
55
- mappedError?: CollabErrorPayload;
93
+ eventStatus: EVENT_STATUS.FAILURE;
94
+ latency?: number;
56
95
  };
57
- nonPrivacySafeAttributes: {
58
- error: ErrorPayload;
96
+ };
97
+ declare type CatchUpSuccessAnalyticsEvent = {
98
+ eventAction: EVENT_ACTION.CATCHUP;
99
+ attributes: {
100
+ documentAri: string;
101
+ eventStatus: EVENT_STATUS.SUCCESS;
102
+ latency?: number;
103
+ };
104
+ };
105
+ declare type CatchUpFailureAnalyticsEvent = {
106
+ eventAction: EVENT_ACTION.CATCHUP;
107
+ attributes: {
108
+ documentAri: string;
109
+ eventStatus: EVENT_STATUS.FAILURE;
110
+ latency?: number;
59
111
  };
60
112
  };
61
- export declare type AnalyticsEvent = {
62
- eventAction: EVENT_ACTION.CONNECTION | EVENT_ACTION.CATCHUP | EVENT_ACTION.DOCUMENT_INIT | EVENT_ACTION.CONVERT_PM_TO_ADF | EVENT_ACTION.UPDATE_PARTICIPANTS | EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS | EVENT_ACTION.REINITIALISE_DOCUMENT;
113
+ declare type DocumentInitSuccessAnalyticsEvent = {
114
+ eventAction: EVENT_ACTION.DOCUMENT_INIT;
115
+ attributes: {
116
+ documentAri: string;
117
+ eventStatus: EVENT_STATUS.SUCCESS;
118
+ latency?: number;
119
+ resetReason?: string;
120
+ ttlEnabled?: boolean;
121
+ };
122
+ };
123
+ declare type UpdateParticipantsSuccessAnalyticsEvent = {
124
+ eventAction: EVENT_ACTION.UPDATE_PARTICIPANTS;
63
125
  attributes: {
64
126
  documentAri?: string;
65
- eventStatus?: EVENT_STATUS;
66
- meetsSLO?: boolean;
127
+ eventStatus: EVENT_STATUS.SUCCESS;
128
+ participants: number;
129
+ };
130
+ };
131
+ declare type CommitUnconfirmedStepsSuccessAnalyticsEvent = {
132
+ eventAction: EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS;
133
+ attributes: {
134
+ documentAri: string;
135
+ eventStatus: EVENT_STATUS.SUCCESS;
67
136
  latency?: number;
68
- error?: ErrorPayload;
69
- participants?: number;
70
137
  numUnconfirmedSteps?: number;
71
- requiredPageRecovery?: boolean;
72
- ttlEnabled?: boolean;
73
138
  };
74
- } | AddStepsSuccessAnalyticsEvent | AddStepsFailureAnalyticsEvent | ErrorAnalyticsEvent;
139
+ };
140
+ declare type CommitUnconfirmedStepsFailureAnalyticsEvent = {
141
+ eventAction: EVENT_ACTION.COMMIT_UNCONFIRMED_STEPS;
142
+ attributes: {
143
+ documentAri: string;
144
+ eventStatus: EVENT_STATUS.FAILURE;
145
+ latency?: number;
146
+ numUnconfirmedSteps?: number;
147
+ };
148
+ };
149
+ declare type PublishPageSuccessAnalyticsEvent = {
150
+ eventAction: EVENT_ACTION.PUBLISH_PAGE;
151
+ attributes: {
152
+ documentAri: string;
153
+ eventStatus: EVENT_STATUS.SUCCESS;
154
+ latency?: number;
155
+ };
156
+ };
157
+ declare type PublishPageFailureAnalyticsEvent = {
158
+ eventAction: EVENT_ACTION.PUBLISH_PAGE;
159
+ attributes: {
160
+ documentAri: string;
161
+ eventStatus: EVENT_STATUS.FAILURE;
162
+ latency?: number;
163
+ };
164
+ };
165
+ declare type GetCurrentStateSuccessAnalyticsEvent = {
166
+ eventAction: EVENT_ACTION.GET_CURRENT_STATE;
167
+ attributes: {
168
+ documentAri: string;
169
+ eventStatus: EVENT_STATUS.SUCCESS;
170
+ latency?: number;
171
+ };
172
+ };
173
+ declare type GetCurrentStateFailureAnalyticsEvent = {
174
+ eventAction: EVENT_ACTION.GET_CURRENT_STATE;
175
+ attributes: {
176
+ documentAri: string;
177
+ eventStatus: EVENT_STATUS.FAILURE;
178
+ latency?: number;
179
+ };
180
+ };
181
+ export declare type ActionAnalyticsEvent = AddStepsSuccessAnalyticsEvent | AddStepsFailureAnalyticsEvent | ReInitDocFailAnalyticsEvent | ReInitDocSuccessAnalyticsEvent | ConnectionSuccessAnalyticsEvent | ConnectionFailureAnalyticsEvent | CatchUpSuccessAnalyticsEvent | CatchUpFailureAnalyticsEvent | DocumentInitSuccessAnalyticsEvent | UpdateParticipantsSuccessAnalyticsEvent | CommitUnconfirmedStepsSuccessAnalyticsEvent | CommitUnconfirmedStepsFailureAnalyticsEvent | PublishPageSuccessAnalyticsEvent | PublishPageFailureAnalyticsEvent | GetCurrentStateSuccessAnalyticsEvent | GetCurrentStateFailureAnalyticsEvent | InvalidateTokenAnalyticsEvent;
75
182
  export declare const ACK_MAX_TRY = 30;
76
183
  export declare const CONFLUENCE = "confluence";
77
184
  export {};
@@ -0,0 +1,14 @@
1
+ import { ErrorPayload, StepsPayload } from '../types';
2
+ import type { Step as ProseMirrorStep } from 'prosemirror-transform';
3
+ import type { Channel } from '../channel';
4
+ import AnalyticsHelper from '../analytics';
5
+ export declare const commitStep: ({ channel, steps, version, userId, clientId, onStepsAdded, onErrorHandled, analyticsHelper, }: {
6
+ channel: Channel;
7
+ steps: readonly ProseMirrorStep[];
8
+ version: number;
9
+ userId: string;
10
+ clientId: number | string;
11
+ onStepsAdded: (data: StepsPayload) => void;
12
+ onErrorHandled: (error: ErrorPayload) => void;
13
+ analyticsHelper?: AnalyticsHelper | undefined;
14
+ }) => void;
@@ -1,11 +1,28 @@
1
+ /// <reference types="lodash" />
1
2
  import type { EditorState, Transaction } from 'prosemirror-state';
3
+ import type { Step as ProseMirrorStep } from 'prosemirror-transform';
2
4
  import { Emitter } from '../emitter';
3
- import type { CollabEditProvider, ResolvedEditorState } from '@atlaskit/editor-common/collab';
4
- import type { CollabEvents, Config, Metadata } from '../types';
5
+ import { Channel } from '../channel';
6
+ import type { CollabEditProvider, CollabParticipant, ResolvedEditorState } from '@atlaskit/editor-common/collab';
7
+ import type { CollabEvents, Config, ErrorPayload, Metadata, StepsPayload } from '../types';
8
+ import AnalyticsHelper from '../analytics';
5
9
  import type { SyncUpErrorFunction } from '@atlaskit/editor-common/types';
6
- export declare const CATCHUP_THROTTLE: number;
7
10
  export declare const MAX_STEP_REJECTED_ERROR = 15;
11
+ export declare const throttledCommitStep: import("lodash").DebouncedFunc<({ channel, steps, version, userId, clientId, onStepsAdded, onErrorHandled, analyticsHelper, }: {
12
+ channel: Channel;
13
+ steps: readonly ProseMirrorStep<any>[];
14
+ version: number;
15
+ userId: string;
16
+ clientId: string | number;
17
+ onStepsAdded: (data: StepsPayload) => void;
18
+ onErrorHandled: (error: ErrorPayload) => void;
19
+ analyticsHelper?: AnalyticsHelper | undefined;
20
+ }) => void>;
8
21
  declare type BaseEvents = Pick<CollabEditProvider<CollabEvents>, 'setup' | 'send' | 'sendMessage'>;
22
+ export declare type ParticipantsMap = Map<string, CollabParticipant & {
23
+ userId: string;
24
+ clientId: number | string;
25
+ }>;
9
26
  export declare class Provider extends Emitter<CollabEvents> implements BaseEvents {
10
27
  private participants;
11
28
  private channel;
@@ -13,7 +30,7 @@ export declare class Provider extends Emitter<CollabEvents> implements BaseEvent
13
30
  private getState;
14
31
  private metadata;
15
32
  private stepRejectCounter;
16
- private analyticsClient?;
33
+ private analyticsHelper?;
17
34
  private isChannelInitialized;
18
35
  private isNamespaceLocked;
19
36
  private onSyncUpError?;
@@ -58,6 +75,7 @@ export declare class Provider extends Emitter<CollabEvents> implements BaseEvent
58
75
  private applyLocalSteps;
59
76
  private getCurrentPmVersion;
60
77
  private getUnconfirmedSteps;
78
+ private getUnconfirmedStepsOrigins;
61
79
  /**
62
80
  * Called when:
63
81
  * * session established(offline -> online)
@@ -66,7 +84,6 @@ export declare class Provider extends Emitter<CollabEvents> implements BaseEvent
66
84
  private catchup;
67
85
  /**
68
86
  * @param error - The error to handle
69
- * @param disableAnalytics - If analytics is already dispatched for this error, re-sending it here can be disabled
70
87
  */
71
88
  private onErrorHandled;
72
89
  private pauseQueue?;
@@ -115,13 +132,14 @@ export declare class Provider extends Emitter<CollabEvents> implements BaseEvent
115
132
  */
116
133
  private updateParticipants;
117
134
  private emitTelepointersFromSteps;
118
- private disconnectedReasonMapper;
119
135
  private onDisconnected;
120
136
  destroy(): this;
121
137
  disconnect(): this;
122
138
  setTitle(title: string, broadcast?: boolean): void;
123
139
  setEditorWidth(editorWidth: string, broadcast?: boolean): void;
124
140
  setMetadata(metadata: Metadata): void;
141
+ getCurrentState: () => Promise<ResolvedEditorState>;
142
+ private commitUnconfirmedSteps;
125
143
  getFinalAcknowledgedState: () => Promise<ResolvedEditorState>;
126
144
  /**
127
145
  * Unsubscribe from all events emitted by this provider.
@@ -0,0 +1,5 @@
1
+ import type { CollabEventTelepointerData } from '@atlaskit/editor-common/collab';
2
+ import { AcknowledgementPayload, StepJson } from '../types';
3
+ import { ParticipantsMap } from './index';
4
+ export declare const telepointersFromStep: (participants: ParticipantsMap, step: StepJson) => CollabEventTelepointerData | undefined;
5
+ export declare const telepointerCallback: (documentAri: string) => (response: AcknowledgementPayload) => void;
@@ -1,4 +1,5 @@
1
1
  import { Provider } from './provider';
2
- import { Socket, Config, ProductInformation } from './types';
3
- export declare function createSocketIOSocket(url: string, auth?: (cb: (data: object) => void) => void, productInfo?: ProductInformation): Socket;
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;
4
5
  export declare function createSocketIOCollabProvider(config: Omit<Config, 'createSocket'>): Provider;
@@ -1,5 +1,5 @@
1
- import type { Transaction } from 'prosemirror-state';
2
- import type { Step } from 'prosemirror-transform';
1
+ import type { Step as ProseMirrorStep } from 'prosemirror-transform';
2
+ import type { Transaction as ProseMirrorTransaction } from 'prosemirror-state';
3
3
  import type { CollabParticipant, CollabEventTelepointerData, CollabEventConnectionData, CollabEventInitData, CollabEventRemoteData, CollabEventPresenceData, CollabEventConnectingData } from '@atlaskit/editor-common/collab';
4
4
  import type { AnalyticsWebClient } from '@atlaskit/analytics-listeners';
5
5
  import type { Manager } from 'socket.io-client';
@@ -15,7 +15,7 @@ export interface Config {
15
15
  lifecycle?: Lifecycle;
16
16
  storage?: Storage;
17
17
  need404?: boolean;
18
- createSocket: (path: string, auth?: (cb: (data: object) => void) => void, productInfo?: ProductInformation) => Socket;
18
+ createSocket: (path: string, auth?: AuthCallback | InitAndAuthData, productInfo?: ProductInformation) => Socket;
19
19
  analyticsClient?: AnalyticsWebClient;
20
20
  featureFlags?: {
21
21
  [key: string]: boolean;
@@ -23,9 +23,24 @@ export interface Config {
23
23
  getUser?(userId: string): Promise<Pick<CollabParticipant, 'avatar' | 'email' | 'name'> & {
24
24
  userId: string;
25
25
  }>;
26
+ /**
27
+ * If provided, permissionTokenRefresh is called whenever a new JWT token is required.
28
+ */
26
29
  permissionTokenRefresh?: () => Promise<string | null>;
30
+ cacheToken?: boolean;
27
31
  productInfo?: ProductInformation;
32
+ /**
33
+ * Throws errors when trying to send data to collab but the client is not offline.
34
+ * This can lead to potential dataloss and retrying should be considered. Without this flag the provider silently drops the requests.
35
+ */
36
+ throwOnNotConnected?: boolean;
28
37
  }
38
+ export interface InitAndAuthData {
39
+ initialized: boolean;
40
+ need404?: boolean;
41
+ token?: string;
42
+ }
43
+ export declare type AuthCallback = (cb: (data: InitAndAuthData) => void) => void;
29
44
  interface SimpleEventEmitter {
30
45
  on(event: string, fn: Function): SimpleEventEmitter;
31
46
  }
@@ -69,7 +84,7 @@ export declare type CollabTelepointerPayload = CollabEventTelepointerData;
69
84
  export declare type CollabPresencePayload = CollabEventPresenceData;
70
85
  export declare type CollabMetadataPayload = Metadata;
71
86
  export declare type CollabLocalStepsPayload = {
72
- steps: readonly Step[];
87
+ steps: readonly ProseMirrorStep[];
73
88
  };
74
89
  export interface CollabEvents {
75
90
  'metadata:changed': CollabMetadataPayload;
@@ -106,10 +121,31 @@ export declare type TelepointerPayload = PresencePayload & {
106
121
  head: number;
107
122
  };
108
123
  };
124
+ declare type MarkJson = {
125
+ type: string;
126
+ attrs: {
127
+ [key: string]: any;
128
+ };
129
+ };
130
+ declare type NodeJson = {
131
+ type: string;
132
+ attrs: {
133
+ [key: string]: any;
134
+ };
135
+ content: NodeJson[];
136
+ marks: MarkJson[];
137
+ text?: string;
138
+ };
139
+ declare type SliceJson = {
140
+ content: NodeJson[];
141
+ openStart: number;
142
+ openEnd: number;
143
+ };
109
144
  export declare type StepJson = {
145
+ stepType?: string;
110
146
  from?: number;
111
147
  to?: number;
112
- stepType?: string;
148
+ slice?: SliceJson;
113
149
  clientId: number | string;
114
150
  userId: string;
115
151
  createdAt?: number;
@@ -186,14 +222,10 @@ export interface CatchupOptions {
186
222
  getCurrentPmVersion: () => number;
187
223
  fetchCatchup: (fromVersion: number) => Promise<CatchupResponse>;
188
224
  filterQueue: (condition: (stepsPayload: StepsPayload) => boolean) => void;
189
- getUnconfirmedSteps: () => {
190
- version: number;
191
- steps: readonly Step<any>[];
192
- clientID: string | number;
193
- origins: readonly Transaction<any>[];
194
- } | null | undefined;
225
+ getUnconfirmedSteps: () => readonly ProseMirrorStep[] | undefined;
226
+ getUnconfirmedStepsOrigins: () => readonly ProseMirrorTransaction[] | undefined;
195
227
  updateDocumentWithMetadata: ({ doc, version, metadata, reserveCursor, }: CollabInitPayload) => void;
196
- applyLocalSteps: (steps: Step[]) => void;
228
+ applyLocalSteps: (steps: ProseMirrorStep[]) => void;
197
229
  }
198
230
  export declare type ProductInformation = {
199
231
  product: string;