@atlaskit/collab-provider 8.3.0 → 8.5.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 (86) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/cjs/analytics/{index.js → analytics-helper.js} +45 -5
  3. package/dist/cjs/analytics/performance.js +7 -5
  4. package/dist/cjs/channel.js +318 -210
  5. package/dist/cjs/{provider → document}/catchup.js +2 -2
  6. package/dist/cjs/document/document-service.js +617 -0
  7. package/dist/cjs/document/step-queue-state.js +51 -0
  8. package/dist/cjs/errors/error-code-mapper.js +107 -0
  9. package/dist/cjs/errors/error-types.js +273 -0
  10. package/dist/cjs/helpers/const.js +2 -4
  11. package/dist/cjs/helpers/utils.js +1 -12
  12. package/dist/cjs/participants/participants-helper.js +51 -0
  13. package/dist/cjs/participants/participants-service.js +217 -0
  14. package/dist/cjs/participants/participants-state.js +53 -0
  15. package/dist/cjs/{provider/telepointers.js → participants/telepointers-helper.js} +6 -6
  16. package/dist/cjs/provider/commit-step.js +40 -36
  17. package/dist/cjs/provider/index.js +215 -762
  18. package/dist/cjs/types.js +3 -0
  19. package/dist/cjs/version-wrapper.js +1 -1
  20. package/dist/cjs/version.json +1 -1
  21. package/dist/es2019/analytics/{index.js → analytics-helper.js} +17 -5
  22. package/dist/es2019/analytics/performance.js +6 -6
  23. package/dist/es2019/channel.js +204 -129
  24. package/dist/es2019/{provider → document}/catchup.js +2 -2
  25. package/dist/es2019/document/document-service.js +495 -0
  26. package/dist/es2019/document/step-queue-state.js +30 -0
  27. package/dist/es2019/errors/error-code-mapper.js +102 -0
  28. package/dist/es2019/errors/error-types.js +151 -0
  29. package/dist/es2019/helpers/const.js +2 -4
  30. package/dist/es2019/helpers/utils.js +0 -10
  31. package/dist/es2019/participants/participants-helper.js +25 -0
  32. package/dist/es2019/participants/participants-service.js +166 -0
  33. package/dist/es2019/participants/participants-state.js +28 -0
  34. package/dist/es2019/{provider/telepointers.js → participants/telepointers-helper.js} +2 -2
  35. package/dist/es2019/provider/commit-step.js +38 -34
  36. package/dist/es2019/provider/index.js +163 -626
  37. package/dist/es2019/types.js +4 -0
  38. package/dist/es2019/version-wrapper.js +1 -1
  39. package/dist/es2019/version.json +1 -1
  40. package/dist/esm/analytics/{index.js → analytics-helper.js} +45 -5
  41. package/dist/esm/analytics/performance.js +6 -6
  42. package/dist/esm/channel.js +318 -210
  43. package/dist/esm/{provider → document}/catchup.js +2 -2
  44. package/dist/esm/document/document-service.js +609 -0
  45. package/dist/esm/document/step-queue-state.js +43 -0
  46. package/dist/esm/errors/error-code-mapper.js +102 -0
  47. package/dist/esm/errors/error-types.js +259 -0
  48. package/dist/esm/helpers/const.js +2 -4
  49. package/dist/esm/helpers/utils.js +0 -10
  50. package/dist/esm/participants/participants-helper.js +43 -0
  51. package/dist/esm/participants/participants-service.js +209 -0
  52. package/dist/esm/participants/participants-state.js +45 -0
  53. package/dist/esm/{provider/telepointers.js → participants/telepointers-helper.js} +4 -4
  54. package/dist/esm/provider/commit-step.js +40 -36
  55. package/dist/esm/provider/index.js +214 -762
  56. package/dist/esm/types.js +4 -0
  57. package/dist/esm/version-wrapper.js +1 -1
  58. package/dist/esm/version.json +1 -1
  59. package/dist/types/analytics/{index.d.ts → analytics-helper.d.ts} +3 -1
  60. package/dist/types/analytics/performance.d.ts +5 -2
  61. package/dist/types/analytics/ufo.d.ts +1 -1
  62. package/dist/types/channel.d.ts +17 -5
  63. package/dist/types/document/document-service.d.ts +105 -0
  64. package/dist/types/document/step-queue-state.d.ts +16 -0
  65. package/dist/types/errors/error-code-mapper.d.ts +2 -0
  66. package/dist/types/errors/error-types.d.ts +443 -0
  67. package/dist/types/helpers/const.d.ts +31 -8
  68. package/dist/types/helpers/utils.d.ts +0 -6
  69. package/dist/types/index.d.ts +2 -1
  70. package/dist/types/participants/participants-helper.d.ts +15 -0
  71. package/dist/types/participants/participants-service.d.ts +70 -0
  72. package/dist/types/participants/participants-state.d.ts +13 -0
  73. package/dist/types/participants/telepointers-helper.d.ts +4 -0
  74. package/dist/types/provider/commit-step.d.ts +6 -6
  75. package/dist/types/provider/index.d.ts +86 -65
  76. package/dist/types/socket-io-provider.d.ts +2 -2
  77. package/dist/types/types.d.ts +65 -33
  78. package/package.json +4 -4
  79. package/report.api.md +193 -23
  80. package/dist/cjs/error-code-mapper.js +0 -88
  81. package/dist/es2019/error-code-mapper.js +0 -78
  82. package/dist/esm/error-code-mapper.js +0 -79
  83. package/dist/types/error-code-mapper.d.ts +0 -36
  84. package/dist/types/provider/telepointers.d.ts +0 -5
  85. package/error-code-mapper/package.json +0 -15
  86. /package/dist/types/{provider → document}/catchup.d.ts +0 -0
package/dist/esm/types.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @deprecated Use ProviderError type instead
3
+ */
4
+
1
5
  // Channel
2
6
 
3
7
  export var AcknowledgementResponseTypes;
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/collab-provider";
2
- export var version = "8.3.0";
2
+ export var version = "8.5.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.3.0",
3
+ "version": "8.5.0",
4
4
  "sideEffects": false
5
5
  }
@@ -2,8 +2,10 @@ import type { AnalyticsWebClient } from '@atlaskit/analytics-listeners';
2
2
  import type { ActionAnalyticsEvent, EVENT_STATUS } from '../helpers/const';
3
3
  export default class AnalyticsHelper {
4
4
  analyticsClient: AnalyticsWebClient | undefined;
5
+ getAnalyticsClient: Promise<AnalyticsWebClient> | undefined;
5
6
  documentAri: string;
6
- constructor(documentAri: string, analyticsClient?: AnalyticsWebClient);
7
+ constructor(documentAri: string, analyticsClient?: AnalyticsWebClient, getAnalyticsClient?: Promise<AnalyticsWebClient>);
7
8
  sendErrorEvent(error: unknown, errorMessage: string): void;
8
9
  sendActionEvent(action: ActionAnalyticsEvent['eventAction'], status: EVENT_STATUS, attributes?: Omit<ActionAnalyticsEvent['attributes'], 'documentAri' | 'eventStatus'>): void;
10
+ private sendEvent;
9
11
  }
@@ -1,10 +1,13 @@
1
- import AnalyticsHelper from '.';
1
+ import AnalyticsHelper from './analytics-helper';
2
2
  export declare enum MEASURE_NAME {
3
3
  SOCKET_CONNECT = "socketConnect",
4
4
  DOCUMENT_INIT = "documentInit",
5
5
  COMMIT_UNCONFIRMED_STEPS = "commitUnconfirmedSteps",
6
- PUBLISH_PAGE = "publishPage"
6
+ PUBLISH_PAGE = "publishPage",
7
+ GET_CURRENT_STATE = "getCurrentState"
7
8
  }
9
+ export declare const isPerformanceAPIAvailable: () => boolean;
10
+ export declare const measureMap: Map<string, number>;
8
11
  export declare function startMeasure(measureName: MEASURE_NAME, analyticsHelper: AnalyticsHelper | undefined): void;
9
12
  export declare function stopMeasure(measureName: MEASURE_NAME, analyticsHelper: AnalyticsHelper | undefined, onMeasureComplete?: (duration: number, startTime: number) => void): {
10
13
  duration: number;
@@ -1,3 +1,3 @@
1
1
  import { UFOExperience } from '@atlaskit/ufo';
2
- import AnalyticsHelper from '.';
2
+ import AnalyticsHelper from './analytics-helper';
3
3
  export declare const createDocInitExp: (analyticsHelper: AnalyticsHelper | undefined) => UFOExperience | undefined;
@@ -1,7 +1,7 @@
1
1
  import { Emitter } from './emitter';
2
2
  import type { Config, ChannelEvent, CatchupResponse, Metadata } from './types';
3
3
  import type { Socket } from 'socket.io-client';
4
- import AnalyticsHelper from './analytics';
4
+ import AnalyticsHelper from './analytics/analytics-helper';
5
5
  export declare class Channel extends Emitter<ChannelEvent> {
6
6
  private connected;
7
7
  private config;
@@ -10,25 +10,37 @@ export declare class Channel extends Emitter<ChannelEvent> {
10
10
  private initialized;
11
11
  private analyticsHelper?;
12
12
  private initExperience?;
13
+ private token?;
13
14
  private network;
14
15
  constructor(config: Config, analyticsHelper: AnalyticsHelper);
15
16
  getInitialized: () => boolean;
16
17
  getConnected: () => boolean;
17
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;
18
22
  /**
19
23
  * Connect to collab service using websockets
20
24
  */
21
25
  connect(): void;
26
+ private handlePermissionInvalidateToken;
22
27
  private onConnectError;
23
28
  private onReconnectError;
24
29
  private onConnect;
25
30
  private onReceiveData;
26
- fetchCatchup(fromVersion: number): Promise<CatchupResponse>;
31
+ fetchCatchup: (fromVersion: number) => Promise<CatchupResponse>;
27
32
  /**
28
- * Send message to service. Timestamp will be added server side.
33
+ * Send message to the back-end service over the channel. Timestamp will be added server side.
34
+ * @throws {NotInitializedError} Channel not initialized
35
+ * @throws {NotConnectedError} Channel not connected
29
36
  */
30
- broadcast<K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], 'timestamp'>, callback?: Function): void;
31
- sendMetadata(metadata: Metadata): void;
37
+ broadcast: <K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], "timestamp">, callback?: Function | undefined) => void;
38
+ /**
39
+ * Send metadata to to the back-end service over the channel
40
+ * @throws {NotInitializedError} Channel not initialized
41
+ * @throws {NotConnectedError} Channel not connected
42
+ */
43
+ sendMetadata: (metadata: Metadata) => void;
32
44
  sendPresenceJoined(): void;
33
45
  onOnlineHandler: () => void;
34
46
  disconnect(): void;
@@ -0,0 +1,105 @@
1
+ /// <reference types="lodash" />
2
+ import AnalyticsHelper from '../analytics/analytics-helper';
3
+ import { CatchupResponse, ChannelEvent, CollabEvents, CollabInitPayload, Metadata, StepsPayload } from '../types';
4
+ import type { Step as ProseMirrorStep } from 'prosemirror-transform';
5
+ import { SyncUpErrorFunction } from '@atlaskit/editor-common/types';
6
+ import type { EditorState, Transaction } from 'prosemirror-state';
7
+ import { ResolvedEditorState } from '@atlaskit/editor-common/collab';
8
+ import { ParticipantsService } from '../participants/participants-service';
9
+ import type { InternalError } from '../errors/error-types';
10
+ export declare class DocumentService {
11
+ private participantsService;
12
+ private analyticsHelper;
13
+ private fetchCatchup;
14
+ private providerEmitCallback;
15
+ private broadcastMetadata;
16
+ private broadcast;
17
+ private getUserId;
18
+ private onErrorHandled;
19
+ private getState;
20
+ private onSyncUpError?;
21
+ private stepQueue;
22
+ private stepRejectCounter;
23
+ private metadata;
24
+ private clientId?;
25
+ /**
26
+ *
27
+ * @param participantsService - The participants service, used when users are detected active when making changes to the document
28
+ * and to emit their telepointers from steps they add
29
+ * @param analyticsHelper - Helper for analytics events
30
+ * @param fetchCatchup - Function to fetch "catchup" data, data required to rebase current steps to the latest version.
31
+ * @param providerEmitCallback - Callback for emitting events to listeners on the provider
32
+ * @param broadcastMetadata - Callback for broadcasting metadata changes to other clients
33
+ * @param broadcast - Callback for broadcasting events to other clients
34
+ * @param getUserId - Callback to fetch the current user's ID
35
+ * @param onErrorHandled - Callback to handle
36
+ */
37
+ constructor(participantsService: ParticipantsService, analyticsHelper: AnalyticsHelper | undefined, fetchCatchup: (fromVersion: number) => Promise<CatchupResponse>, providerEmitCallback: (evt: keyof CollabEvents, data: any) => void, broadcastMetadata: (metadata: Metadata) => void, broadcast: <K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], 'timestamp'>, callback?: Function) => void, getUserId: () => string | undefined, onErrorHandled: (error: InternalError) => void);
38
+ /**
39
+ * Called when a metadata is changed externally from other clients/backend.
40
+ */
41
+ onMetadataChanged: (metadata: Metadata) => void;
42
+ getMetaData: () => Metadata;
43
+ setTitle(title: string, broadcast?: boolean): void;
44
+ setEditorWidth(editorWidth: string, broadcast?: boolean): void;
45
+ /**
46
+ * Updates the local metadata and broadcasts the metadata to other clients/backend.
47
+ * @param metadata
48
+ */
49
+ setMetadata(metadata: Metadata): void;
50
+ /**
51
+ * To prevent calling catchup to often, use lodash throttle to reduce the frequency
52
+ */
53
+ throttledCatchup: import("lodash").DebouncedFunc<() => Promise<void>>;
54
+ /**
55
+ * Called when:
56
+ * * session established(offline -> online)
57
+ * * try to accept steps but version is behind.
58
+ */
59
+ private catchup;
60
+ getCurrentPmVersion: () => number;
61
+ private processQueue;
62
+ getCurrentState: () => Promise<ResolvedEditorState>;
63
+ private processSteps;
64
+ getUnconfirmedStepsOrigins: () => readonly Transaction<any>[] | undefined;
65
+ getUnconfirmedSteps: () => readonly ProseMirrorStep[] | undefined;
66
+ private applyLocalSteps;
67
+ /**
68
+ * Emits the initialisation data for a document
69
+ * @param doc
70
+ * @param version
71
+ * @param metadata
72
+ * @param reserveCursor
73
+ */
74
+ updateDocumentWithMetadata: ({ doc, version, metadata, reserveCursor, }: CollabInitPayload) => void;
75
+ /**
76
+ * Called when we receive steps from the service
77
+ */
78
+ onStepsAdded: (data: StepsPayload) => void;
79
+ onRestore: ({ doc, version, metadata }: CollabInitPayload) => void;
80
+ getFinalAcknowledgedState: () => Promise<ResolvedEditorState>;
81
+ /**
82
+ * Commit the unconfirmed local steps to the back-end service
83
+ * @throws {Error} Couldn't sync the steps after retrying 30 times
84
+ */
85
+ commitUnconfirmedSteps: () => Promise<void>;
86
+ setup({ getState, onSyncUpError, clientId, }: {
87
+ getState: () => EditorState;
88
+ onSyncUpError?: SyncUpErrorFunction;
89
+ clientId: number | string | undefined;
90
+ }): this;
91
+ /**
92
+ * We can use this function to throttle/delay
93
+ * Any send steps operation
94
+ *
95
+ * The getState function will return the current EditorState
96
+ * from the EditorView.
97
+ */
98
+ sendStepsFromCurrentState(): void;
99
+ onStepRejectedError: () => void;
100
+ /**
101
+ * Send steps from transaction to other participants
102
+ * It needs the superfluous arguments because we keep the interface of the send API the same as the Synchrony plugin
103
+ */
104
+ send(_tr: Transaction | null, _oldState: EditorState | null, newState: EditorState): void;
105
+ }
@@ -0,0 +1,16 @@
1
+ import { StepsPayload } from '../types';
2
+ export declare class StepQueueState {
3
+ private queuePaused;
4
+ private queue;
5
+ queueSteps(data: StepsPayload): void;
6
+ getQueue: () => StepsPayload[];
7
+ filterQueue: (condition: (stepsPayload: StepsPayload) => boolean) => void;
8
+ /**
9
+ * Get whether the document service has stopped processing new steps whilst it carries out processes such as catchup.
10
+ * Exposed for testing
11
+ */
12
+ isPaused: () => boolean;
13
+ pauseQueue: () => void;
14
+ resumeQueue: () => void;
15
+ shift: () => StepsPayload | undefined;
16
+ }
@@ -0,0 +1,2 @@
1
+ import { InternalError, ProviderError } from './error-types';
2
+ export declare const errorCodeMapper: (error: InternalError) => ProviderError | undefined;
@@ -0,0 +1,443 @@
1
+ export declare enum INTERNAL_ERROR_CODE {
2
+ TOKEN_PERMISSION_ERROR = "TOKEN_PERMISSION_ERROR",
3
+ RECONNECTION_NETWORK_ISSUE = "RECONNECTION_NETWORK_ISSUE",
4
+ CONNECTION_ERROR = "CONNECTION_ERROR",
5
+ RECONNECTION_ERROR = "RECONNECTION_ERROR",
6
+ DOCUMENT_NOT_FOUND = "DOCUMENT_NOT_FOUND",
7
+ CATCHUP_FAILED = "CATCHUP_FAILED",
8
+ DOCUMENT_RESTORE_ERROR = "DOCUMENT_RESTORE_ERROR",
9
+ ADD_STEPS_ERROR = "ADD_STEPS_ERROR"
10
+ }
11
+ export declare enum NCS_ERROR_CODE {
12
+ HEAD_VERSION_UPDATE_FAILED = "HEAD_VERSION_UPDATE_FAILED",
13
+ VERSION_NUMBER_ALREADY_EXISTS = "VERSION_NUMBER_ALREADY_EXISTS",
14
+ INSUFFICIENT_EDITING_PERMISSION = "INSUFFICIENT_EDITING_PERMISSION",
15
+ FORBIDDEN_USER_TOKEN = "FORBIDDEN_USER_TOKEN",
16
+ DOCUMENT_NOT_FOUND = "DOCUMENT_NOT_FOUND",
17
+ INIT_DATA_LOAD_FAILED = "INIT_DATA_LOAD_FAILED",
18
+ ERROR_MAPPING_ERROR = "ERROR_MAPPING_ERROR",
19
+ NAMESPACE_INVALID = "NAMESPACE_INVALID",
20
+ NAMESPACE_NOT_FOUND = "NAMESPACE_NOT_FOUND",
21
+ TENANT_INSTANCE_MAINTENANCE = "TENANT_INSTANCE_MAINTENANCE",
22
+ LOCKED_DOCUMENT = "LOCKED_DOCUMENT",
23
+ EMPTY_BROADCAST = "EMPTY_BROADCAST",
24
+ DYNAMO_ERROR = "DYNAMO_ERROR",
25
+ INVALID_ACTIVATION_ID = "INVALID_ACTIVATION_ID",
26
+ INVALID_DOCUMENT_ARI = "INVALID_DOCUMENT_ARI",
27
+ INVALID_CLOUD_ID = "INVALID_CLOUD_ID"
28
+ }
29
+ declare type HeadVersionUpdateFailedError = {
30
+ message: string;
31
+ data: {
32
+ code: NCS_ERROR_CODE.HEAD_VERSION_UPDATE_FAILED;
33
+ meta: {
34
+ currentVersion: any;
35
+ incomingVersion: number;
36
+ };
37
+ status: number;
38
+ };
39
+ };
40
+ declare type VersionAlreadyPresentInDynamoError = {
41
+ message: string;
42
+ data: {
43
+ code: NCS_ERROR_CODE.VERSION_NUMBER_ALREADY_EXISTS;
44
+ meta: string;
45
+ status: number;
46
+ };
47
+ };
48
+ declare type InsufficientEditingPermissionError = {
49
+ message: string;
50
+ data: {
51
+ code: NCS_ERROR_CODE.INSUFFICIENT_EDITING_PERMISSION;
52
+ meta: {
53
+ description: string;
54
+ reason?: string;
55
+ };
56
+ status: number;
57
+ };
58
+ };
59
+ declare type ForbiddenUserTokenError = {
60
+ message: string;
61
+ data: {
62
+ code: NCS_ERROR_CODE.FORBIDDEN_USER_TOKEN;
63
+ meta: string;
64
+ status: number;
65
+ };
66
+ };
67
+ declare type NCSDocumentNotFoundError = {
68
+ message: string;
69
+ data: {
70
+ code: NCS_ERROR_CODE.DOCUMENT_NOT_FOUND;
71
+ status: number;
72
+ };
73
+ };
74
+ declare type FailedToLoadInitDataError = {
75
+ message: string;
76
+ data: {
77
+ code: NCS_ERROR_CODE.INIT_DATA_LOAD_FAILED;
78
+ status: number;
79
+ };
80
+ };
81
+ declare type ErrorMappingError = {
82
+ message: string;
83
+ data: {
84
+ code: NCS_ERROR_CODE.ERROR_MAPPING_ERROR;
85
+ status: number;
86
+ };
87
+ };
88
+ declare type InvalidNamespaceDefinedError = {
89
+ message: string;
90
+ data: {
91
+ code: NCS_ERROR_CODE.NAMESPACE_INVALID;
92
+ meta: string;
93
+ status: number;
94
+ };
95
+ };
96
+ declare type SocketNamespaceNotFoundError = {
97
+ message: string;
98
+ data: {
99
+ code: NCS_ERROR_CODE.NAMESPACE_NOT_FOUND;
100
+ meta: string;
101
+ status: number;
102
+ };
103
+ };
104
+ declare type TenantInstanceMaintenanceError = {
105
+ message: string;
106
+ data: {
107
+ code: NCS_ERROR_CODE.TENANT_INSTANCE_MAINTENANCE;
108
+ meta: {
109
+ description: string;
110
+ reason: string;
111
+ };
112
+ status: number;
113
+ };
114
+ };
115
+ declare type NamespaceLockedError = {
116
+ message: string;
117
+ data: {
118
+ code: NCS_ERROR_CODE.LOCKED_DOCUMENT;
119
+ meta: string;
120
+ status: number;
121
+ };
122
+ };
123
+ declare type EmptyBroadcastError = {
124
+ message: string;
125
+ data: {
126
+ code: NCS_ERROR_CODE.EMPTY_BROADCAST;
127
+ meta: string;
128
+ status: number;
129
+ };
130
+ };
131
+ declare type DynamoError = {
132
+ message: string;
133
+ data: {
134
+ code: NCS_ERROR_CODE.DYNAMO_ERROR;
135
+ meta: string;
136
+ status: number;
137
+ };
138
+ };
139
+ declare type InvalidActivationIdError = {
140
+ message: string;
141
+ data: {
142
+ code: NCS_ERROR_CODE.INVALID_ACTIVATION_ID;
143
+ meta: string;
144
+ status: number;
145
+ };
146
+ };
147
+ declare type InvalidDocumentAriError = {
148
+ message: string;
149
+ data: {
150
+ code: NCS_ERROR_CODE.INVALID_DOCUMENT_ARI;
151
+ meta: string;
152
+ status: number;
153
+ };
154
+ };
155
+ declare type InvalidCloudIdError = {
156
+ message: string;
157
+ data: {
158
+ code: NCS_ERROR_CODE.INVALID_CLOUD_ID;
159
+ meta: string;
160
+ status: number;
161
+ };
162
+ };
163
+ declare type NCSErrors = HeadVersionUpdateFailedError | VersionAlreadyPresentInDynamoError | InsufficientEditingPermissionError | ForbiddenUserTokenError | NCSDocumentNotFoundError | FailedToLoadInitDataError | ErrorMappingError | InvalidNamespaceDefinedError | SocketNamespaceNotFoundError | TenantInstanceMaintenanceError | NamespaceLockedError | EmptyBroadcastError | DynamoError | InvalidActivationIdError | InvalidDocumentAriError | InvalidCloudIdError;
164
+ declare type DocumentRecoveryError = {
165
+ message: string;
166
+ data: {
167
+ code: INTERNAL_ERROR_CODE.DOCUMENT_RESTORE_ERROR;
168
+ status: number;
169
+ };
170
+ };
171
+ declare type AddStepsError = {
172
+ message: string;
173
+ data: {
174
+ code: INTERNAL_ERROR_CODE.ADD_STEPS_ERROR;
175
+ status: number;
176
+ };
177
+ };
178
+ export declare type CatchUpFailedError = {
179
+ message: string;
180
+ data: {
181
+ code: INTERNAL_ERROR_CODE.CATCHUP_FAILED;
182
+ status: number;
183
+ };
184
+ };
185
+ export declare type TokenPermissionError = {
186
+ message: string;
187
+ data: {
188
+ code: INTERNAL_ERROR_CODE.TOKEN_PERMISSION_ERROR;
189
+ status: number;
190
+ meta: {
191
+ originalError?: unknown;
192
+ reason?: string;
193
+ };
194
+ };
195
+ };
196
+ export declare type ReconnectionError = {
197
+ message: string;
198
+ data: {
199
+ code: INTERNAL_ERROR_CODE.RECONNECTION_ERROR;
200
+ status: number;
201
+ };
202
+ };
203
+ export declare type ConnectionError = {
204
+ message: string;
205
+ data: {
206
+ code: INTERNAL_ERROR_CODE.CONNECTION_ERROR;
207
+ };
208
+ };
209
+ export declare type ReconnectionNetworkError = {
210
+ message: string;
211
+ data: {
212
+ code: INTERNAL_ERROR_CODE.RECONNECTION_NETWORK_ISSUE;
213
+ };
214
+ };
215
+ export declare type DocumentNotFoundError = {
216
+ message: string;
217
+ data: {
218
+ code: INTERNAL_ERROR_CODE.DOCUMENT_NOT_FOUND;
219
+ status: number;
220
+ };
221
+ };
222
+ /**
223
+ * A union of all possible internal errors, that are mapped to another error if being emitted to the editor.
224
+ */
225
+ export declare type InternalError = NCSErrors | DocumentRecoveryError | AddStepsError | CatchUpFailedError | TokenPermissionError | ReconnectionError | ConnectionError | ReconnectionNetworkError | DocumentNotFoundError;
226
+ export declare enum PROVIDER_ERROR_CODE {
227
+ NO_PERMISSION_ERROR = "NO_PERMISSION_ERROR",
228
+ INVALID_USER_TOKEN = "INVALID_USER_TOKEN",
229
+ DOCUMENT_NOT_FOUND = "DOCUMENT_NOT_FOUND",
230
+ LOCKED = "LOCKED",
231
+ FAIL_TO_SAVE = "FAIL_TO_SAVE",
232
+ DOCUMENT_RESTORE_ERROR = "DOCUMENT_RESTORE_ERROR",
233
+ INITIALISATION_ERROR = "INITIALISATION_ERROR",
234
+ NETWORK_ISSUE = "NETWORK_ISSUE",
235
+ INVALID_PROVIDER_CONFIGURATION = "INVALID_PROVIDER_CONFIGURATION",
236
+ INTERNAL_SERVICE_ERROR = "INTERNAL_SERVICE_ERROR"
237
+ }
238
+ /**
239
+ * This occurs when the provided user token is considered invalid for the given document ARI.
240
+ * It happens during initialisation of the provider.
241
+ * It could mean the document has been deleted (hence not found).
242
+ * @message Message returned to editor, i.e User does not have permissions to access this document or document is not found
243
+ * @recoverable It is recoverable, as we will try to refresh the token.
244
+ */
245
+ declare type InsufficientEditingPermission = {
246
+ code: PROVIDER_ERROR_CODE.NO_PERMISSION_ERROR;
247
+ message: string;
248
+ recoverable: boolean;
249
+ reason?: string;
250
+ /**
251
+ * @deprecated switch to using either the error code or the recoverable flag
252
+ */
253
+ status?: number;
254
+ };
255
+ /**
256
+ * Similiar to InsufficientEditingPermission, but the user token is invalid because it has expired or been revoked.
257
+ * It may also be an invalid token format.
258
+ * This error is given to the provider by NCS.
259
+ * @message Message returned to editor, i.e. The user token was invalid
260
+ * @recoverable It is recoverable, as we will try to refresh the token.
261
+ */
262
+ declare type InvalidUserToken = {
263
+ code: PROVIDER_ERROR_CODE.INVALID_USER_TOKEN;
264
+ message: string;
265
+ recoverable: boolean;
266
+ /**
267
+ * @deprecated switch to using either the error code or the recoverable flag
268
+ */
269
+ status?: number;
270
+ };
271
+ /**
272
+ * Document not found error, thrown when the provider is unable to find a document with the given ARI and user token.
273
+ * It occurs during fetchCatchup, a function that fetches the latest document state during catchup.
274
+ * We need to recieve a 404 from the document service to throw this error.
275
+ * @message Message returned to editor, i.e. The requested document is not found
276
+ * @recoverable It is recoverable, as the provider can try again later.
277
+ */
278
+ declare type DocumentNotFound = {
279
+ code: PROVIDER_ERROR_CODE.DOCUMENT_NOT_FOUND;
280
+ message: string;
281
+ recoverable: boolean;
282
+ /**
283
+ * @deprecated switch to using either the error code or the recoverable flag
284
+ */
285
+ status?: number;
286
+ };
287
+ /**
288
+ * This error is thrown when the document is locked by another user.
289
+ * The error is passed to us by NCS.
290
+ * @message Message returned to editor, i.e. The document is currently not available, please try again later
291
+ * @recoverable It is recoverable, as the provider can try again later.
292
+ */
293
+ declare type Locked = {
294
+ code: PROVIDER_ERROR_CODE.LOCKED;
295
+ message: string;
296
+ recoverable: boolean;
297
+ status?: number;
298
+ };
299
+ /**
300
+ * This error is thrown when the provider is unable to save the document.
301
+ * This can happen when the connection to dynamoDB is lost, or when we do not have sufficient permissions (DYNAMO ERROR).
302
+ * This error is given to us by NCS.
303
+ * @message Message returned to editor, i.e. Collab service is not able to save changes
304
+ * @recoverable It is not recoverable, as we don't want the user to continue editing a document that is not being saved.
305
+ */
306
+ declare type FailToSave = {
307
+ code: PROVIDER_ERROR_CODE.FAIL_TO_SAVE;
308
+ message: string;
309
+ recoverable: boolean;
310
+ /**
311
+ * @deprecated switch to using either the error code or the recoverable flag
312
+ */
313
+ status?: number;
314
+ };
315
+ /**
316
+ * This error is thrown when the provider is unable to restore the document.
317
+ * It occurs during onRestore, a function that restores the document to a previous version and reapplies unconfirmed steps.
318
+ * onRestore is called when page recovery has emitted an 'init' event on a page client is currently connected to.
319
+ * It could mean we failed to update the page metadata, or we failed to reapply unconfirmed steps.
320
+ * @message Message returned to editor, i.e. Collab service unable to restore document
321
+ * @recoverable It is not recoverable, as the provider has no further options after this.
322
+ * The user will need to refresh the page to try again.
323
+ */
324
+ declare type DocumentNotRestore = {
325
+ code: PROVIDER_ERROR_CODE.DOCUMENT_RESTORE_ERROR;
326
+ message: string;
327
+ recoverable: boolean;
328
+ /**
329
+ * @deprecated switch to using either the error code or the recoverable flag
330
+ */
331
+ status?: number;
332
+ };
333
+ /**
334
+ * The initial document couldn't be loaded from the collab service.
335
+ * This error is given to us by NCS.
336
+ * It could indicate either a network issue, or an internal service error in NCS.
337
+ * @message Message returned to editor, i.e. The initial document couldn't be loaded from the collab service
338
+ * @recoverable It is not recoverable, as the provider cannot do anything to fix it.
339
+ * The user will need to refresh the page to try again.
340
+ */
341
+ declare type InitialisationError = {
342
+ code: PROVIDER_ERROR_CODE.INITIALISATION_ERROR;
343
+ message: string;
344
+ recoverable: boolean;
345
+ /**
346
+ * @deprecated switch to using either the error code or the recoverable flag
347
+ */
348
+ status?: number;
349
+ };
350
+ /**
351
+ * Couldn't reconnect to the collab service (NCS) due to network issues.
352
+ * NCS could be down, or the user could be offline. It's also possible the url is incorrect, or the user is behind a proxy blocking the connection.
353
+ * Fired upon a reconnection attempt error (from Socket.IO Manager)
354
+ * @message Message returned to editor, i.e. Couldn't reconnect to the collab service due to network issues
355
+ * @recoverable It is recoverable, as the provider will try to reconnect.
356
+ */
357
+ declare type NetworkIssue = {
358
+ code: PROVIDER_ERROR_CODE.NETWORK_ISSUE;
359
+ message: string;
360
+ recoverable: boolean;
361
+ /**
362
+ * @deprecated switch to using either the error code or the recoverable flag
363
+ */
364
+ status?: number;
365
+ };
366
+ /**
367
+ * This error is thrown when the provider has an invalid configuration.
368
+ * It could happen due to these errors from NCS:
369
+ * NAMESPACE_INVALID
370
+ INVALID_ACTIVATION_ID
371
+ INVALID_DOCUMENT_ARI
372
+ INVALID_CLOUD_ID
373
+ * @message Message returned to editor, i.e. Invalid provider configuration
374
+ * @recoverable It is not recoverable, as the provider cannot do anything to fix it.
375
+ * The service using the provider will need to fix the configuration.
376
+ */
377
+ declare type InvalidProviderConfiguration = {
378
+ code: PROVIDER_ERROR_CODE.INVALID_PROVIDER_CONFIGURATION;
379
+ message: string;
380
+ recoverable: boolean;
381
+ reason: string;
382
+ /**
383
+ * @deprecated switch to using either the error code or the recoverable flag
384
+ */
385
+ status?: number;
386
+ };
387
+ /**
388
+ * This error is thrown when the provider encounters an internal service error, not otherwise accounted for.
389
+ * @message Message returned to editor, i.e. Collab Provider experienced an unrecoverable error
390
+ * @recoverable It is not recoverable, as the provider cannot do anything to fix it.
391
+ */
392
+ declare type InternalServiceError = {
393
+ code: PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR;
394
+ message: string;
395
+ recoverable: boolean;
396
+ reason: string;
397
+ /**
398
+ * @deprecated switch to using either the error code or the recoverable flag
399
+ */
400
+ status?: number;
401
+ };
402
+ /**
403
+ * A union of all possible provider errors that can be emitted back to the editor.
404
+ */
405
+ export declare type ProviderError = InsufficientEditingPermission | InvalidUserToken | DocumentNotFound | Locked | FailToSave | DocumentNotRestore | InitialisationError | NetworkIssue | InvalidProviderConfiguration | InternalServiceError;
406
+ declare class CustomError extends Error {
407
+ constructor(message: string, error?: unknown);
408
+ toJSON(): {
409
+ name: string;
410
+ message: string;
411
+ };
412
+ }
413
+ export declare class NotConnectedError extends CustomError {
414
+ name: string;
415
+ }
416
+ export declare class NotInitializedError extends CustomError {
417
+ name: string;
418
+ }
419
+ export declare class ProviderInitialisationError extends CustomError {
420
+ name: string;
421
+ }
422
+ export declare class SendTransactionError extends CustomError {
423
+ name: string;
424
+ }
425
+ export declare class DestroyError extends CustomError {
426
+ name: string;
427
+ }
428
+ export declare class SetTitleError extends CustomError {
429
+ name: string;
430
+ }
431
+ export declare class SetEditorWidthError extends CustomError {
432
+ name: string;
433
+ }
434
+ export declare class SetMetadataError extends CustomError {
435
+ name: string;
436
+ }
437
+ export declare class GetCurrentStateError extends CustomError {
438
+ name: string;
439
+ }
440
+ export declare class GetFinalAcknowledgedStateError extends CustomError {
441
+ name: string;
442
+ }
443
+ export {};